Callback Definitions

Shared

Callback definitions shared between Services, Capabilities, and Clients.

intersect_sdk.shared_callback_definitions.INTERSECT_JSON_VALUE: TypeAlias = list['INTERSECT_JSON_VALUE'] | dict[str, 'INTERSECT_JSON_VALUE'] | str | bool | int | float | None

This is a simple type representation of JSON as a Python object. INTERSECT will automatically deserialize service payloads into one of these types.

(Pydantic has a similar type, “JsonValue”, which should be used if you desire functionality beyond type hinting. This is strictly a type hint.)

intersect_sdk.shared_callback_definitions.INTERSECT_RESPONSE_VALUE: TypeAlias = list['INTERSECT_JSON_VALUE'] | dict[str, 'INTERSECT_JSON_VALUE'] | str | bool | int | float | None | bytes

This is the actual response value you will get back from a Service. The type will already be serialized into Python for you, but will not be serialized into a precise value.

If you receive ‘bytes’, you should assume binary data. Other types imply JSON values.

class intersect_sdk.shared_callback_definitions.IntersectDirectMessageParams(*, destination: Annotated[str, _PydanticGeneralMetadata(pattern='^[a-z0-9][-a-z0-9.]*[-a-z0-9]$')], operation: str, payload: Any, content_type: Annotated[str, _PydanticGeneralMetadata(pattern='\\w+/[-+.\\w]+')] = 'application/json', data_handler: IntersectDataHandler = IntersectDataHandler.MESSAGE)

These are the public-facing properties of a message which can be sent to another Service.

This object can be used by Clients, and by Services if initiating a service-to-service request.

content_type: Annotated[str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(pattern='\\w+/[-+.\\w]+')])]

The IntersectMimeType of your message. You’ll want this to match with the ContentType of the function from the schema.

default: application/json

data_handler: IntersectDataHandler

The IntersectDataHandler you want to use (most people can just use IntersectDataHandler.MESSAGE here, unless your data is very large)

default: IntersectDataHandler.MESSAGE

destination: Annotated[str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(pattern='^[a-z0-9][-a-z0-9.]*[-a-z0-9]$')])]

The destination string. You’ll need to know the system-of-system representation of the Service.

Note that this should match what you would see in the schema.

operation: str

The name of the operation you want to call from the Service - this should be represented as it is in the Service’s schema.

payload: Any

The raw Python object you want to have serialized as the payload.

If you want to just use the service’s default value for a request (assuming it has a default value for a request), you may set this as None.

class intersect_sdk.shared_callback_definitions.IntersectEventMessageParams(*, hierarchy: Annotated[str, _PydanticGeneralMetadata(pattern='^[a-z0-9][-a-z0-9.]*[-a-z0-9]$')], capability_name: Annotated[str, _PydanticGeneralMetadata(pattern='^[a-zA-Z0-9]\\w*$')], event_name: str)

Public facing properties of events the Client/Service wants to listen to.

capability_name: Annotated[str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(pattern='^[a-zA-Z0-9]\\w*$')])]

Name of the capability you want to listen to events from

event_name: str

Name of the event the capability emits that you’re listening for

hierarchy: Annotated[str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(pattern='^[a-z0-9][-a-z0-9.]*[-a-z0-9]$')])]

The full hierarchy (org.facility.system.subsystem.service) that we want to listen to.

Client

Data types used in regard to client callbacks. Only relevant for Client authors.

See shared_callback_definitions for additional typings which are also shared by service authors.

intersect_sdk.client_callback_definitions.INTERSECT_CLIENT_EVENT_CALLBACK_TYPE

This is a callable function type which should be defined by the user.

Note: DO NOT handle serialization/deserialization yourself, the SDK will take care of this.

Params
The SDK will send the function four arguments:
  1. The message source (the SOS representation of the Service) - this is mostly useful for your own control flow loops you write in the function

  2. The name of the capability from the service that fired the event.

  3. The name of the event.

  4. The response, as a Python object - the type should be based on the corresponding Service’s event response. The Python object will already be deserialized for you (unless you are expecting binary data, then it will be base64). This will be either an integer, boolean, float, string, None, a List[T], or a Dict[str, T], where “T” represents any of the 7 aforementioned types.

Returns

If you want to send one or many messages in reaction to a message, or change which services you’re listening to for events, the function should return an IntersectClientCallback object.

If you are DONE listening to messages, raise a generic Exception from your function.

If you DON’T want to send another message or modify your events, but want to continue listening for messages, you can just return None.

Raises

Any uncaught or raised exceptions the callback function throws will terminate the INTERSECT lifecycle.

alias of Callable[[str, str, str, list[INTERSECT_JSON_VALUE] | dict[str, INTERSECT_JSON_VALUE] | str | bool | int | float | None | bytes], IntersectClientCallback | None]

intersect_sdk.client_callback_definitions.INTERSECT_CLIENT_RESPONSE_CALLBACK_TYPE

This is a callable function type which should be defined by the user.

Note: DO NOT handle serialization/deserialization yourself, the SDK will take care of this.

Params
The SDK will send the function four arguments:
  1. The message source - this is mostly useful for your own control flow loops you write in the function

  2. The name of the operation that triggered the response from your ORIGINAL message - needed for your own control flow loops if sending multiple messages.

  3. A boolean - if True, there was an error; if False, there was not.

  4. The response, as a Python object - the type should be based on the corresponding Service’s schema response. The Python object will already be deserialized for you (unless you are expecting binary data, then it will be a base64). If parameter 3 was “True”, then this will be the error message, as a string. If parameter 3 was “False”, then this will be either an integer, boolean, float, string, None, a List[T], or a Dict[str, T], where “T” represents any of the 7 aforementioned types.

Returns

If you want to send one or many messages in reaction to a message, or change which services you’re listening to for events, the function should return an IntersectClientCallback object.

If you are DONE listening to messages, raise a generic Exception from your function.

If you DON’T want to send another message or modify your events, but want to continue listening for messages, you can just return None.

Raises

Any uncaught or raised exceptions the callback function throws will terminate the INTERSECT lifecycle.

alias of Callable[[str, str, bool, list[INTERSECT_JSON_VALUE] | dict[str, INTERSECT_JSON_VALUE] | str | bool | int | float | None | bytes], IntersectClientCallback | None]

intersect_sdk.client_callback_definitions.INTERSECT_RESPONSE_VALUE: TypeAlias = list['INTERSECT_JSON_VALUE'] | dict[str, 'INTERSECT_JSON_VALUE'] | str | bool | int | float | None | bytes

This is the actual response value you will get back from a Service. The type will already be serialized into Python for you, but will not be serialized into a precise value.

final class intersect_sdk.client_callback_definitions.IntersectClientCallback(*, messages_to_send: list[IntersectDirectMessageParams] = [], services_to_start_listening_for_events: list[IntersectEventMessageParams] = [], services_to_stop_listening_for_events: list[IntersectEventMessageParams] = [])

The value a user should return from ALL client callback functions.

If you do not return a value of this type (or None), this will be treated as an Exception and will break the pub-sub loop.

messages_to_send: list[IntersectDirectMessageParams]

Messages to send as a result of an event or a response from a Service.

services_to_start_listening_for_events: list[IntersectEventMessageParams]

Start listening to events from these services as a result of an event or a response from a Service.

For each event in the list - if you are already listening to the event, the action will be a no-op.

services_to_stop_listening_for_events: list[IntersectEventMessageParams]

Stop listening to events from these services as a result of an event or a response from a Service.

For each event in the list - if you are not already listening to the event, the action will be a no-op.

Service

Callback definitions used by Services and Capabilities.

Please see shared_callback_definitions for definitions which are also used by Clients.

intersect_sdk.service_callback_definitions.INTERSECT_SERVICE_RESPONSE_CALLBACK_TYPE

Callback typing for the function which handles another Service’s response.

Params
The SDK will send the function four arguments:
  1. The message source - this is mostly useful for your own control flow loops you write in the function

  2. The name of the operation that triggered the response from your ORIGINAL message - needed for your own control flow loops if sending multiple messages.

  3. A boolean - if True, there was an error; if False, there was not.

  4. The response, as a Python object - the type should be based on the corresponding Service’s schema response. The Python object will already be deserialized for you. If parameter 3 was “True”, then this will be the error message, as a string. If parameter 3 was “False”, and you are expecting textual data, this will be either an integer, boolean, float, string, None, a List[T], or a Dict[str, T], where “T” represents any of the 7 aforementioned types. If parameter 3 was “False” but you are expecting binary data, this will be bytes.

This callback type should only be used on Capabilities - for client callback functions, use INTERSECT_CLIENT_RESPONSE_CALLBACK_TYPE .

alias of Callable[[str, str, bool, list[INTERSECT_JSON_VALUE] | dict[str, INTERSECT_JSON_VALUE] | str | bool | int | float | None | bytes], None]