Skip to content

actions

ActionConfig

Bases: BaseModel

Configure a widget action and how the browser dispatches it.

Source code in chatkit/actions.py
12
13
14
15
16
17
18
19
class ActionConfig(BaseModel):
    """Configure a widget action and how the browser dispatches it."""

    type: str = Field(min_length=1)
    payload: Any = None
    handler: Handler = DEFAULT_HANDLER
    loadingBehavior: LoadingBehavior = DEFAULT_LOADING_BEHAVIOR
    streaming: bool = True

Action

Bases: BaseModel

Describe an action with a required name and an explicitly typed payload.

Source code in chatkit/actions.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class Action[TType: str, TPayload](BaseModel):
    """Describe an action with a required name and an explicitly typed payload."""

    type: TType = Field(frozen=True, min_length=1)
    payload: TPayload

    @classmethod
    def create(
        cls,
        payload: TPayload,
        handler: Handler = DEFAULT_HANDLER,
        loading_behavior: LoadingBehavior = DEFAULT_LOADING_BEHAVIOR,
        streaming: bool = True,
    ) -> ActionConfig:
        action_type = None
        anno = cls.model_fields["type"].annotation
        if get_origin(anno) is Literal:
            lits = get_args(anno)
            if len(lits) == 1 and isinstance(lits[0], str):
                action_type = lits[0]

        if action_type is None:
            raise TypeError(
                "Cannot infer 'type' for this Action[...]. Do not call create() on generic Action."
            )

        return ActionConfig(
            type=action_type,
            payload=payload,
            handler=handler,
            loadingBehavior=loading_behavior,
            streaming=streaming,
        )

IncomingAction

Bases: Action[str, Any]

An action from the browser, where an absent payload means no arguments.

Source code in chatkit/actions.py
57
58
59
60
class IncomingAction(Action[str, Any]):
    """An action from the browser, where an absent payload means no arguments."""

    payload: Any = None