Files
chainlit--chainlit/backend/chainlit/action.py
T
wehub-resource-sync b7f52be4c9
CI / Run CI (push) Has been cancelled
CI / check-backend (push) Has been cancelled
CI / check-frontend (push) Has been cancelled
CI / tests (push) Has been cancelled
CI / e2e-tests (push) Has been cancelled
Copilot Setup Steps / copilot-setup-steps (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:48:47 +08:00

34 lines
1.1 KiB
Python

import uuid
from typing import Dict, Optional
from dataclasses_json import DataClassJsonMixin
from pydantic import Field
from pydantic.dataclasses import dataclass
from chainlit.context import context
@dataclass
class Action(DataClassJsonMixin):
# Name of the action, this should be used in the action_callback
name: str
# The parameters to call this action with.
payload: Dict
# The label of the action. This is what the user will see.
label: str = ""
# The tooltip of the action button. This is what the user will see when they hover the action.
tooltip: str = ""
# The lucid icon name for this action.
icon: Optional[str] = None
# This should not be set manually, only used internally.
forId: Optional[str] = None
# The ID of the action
id: str = Field(default_factory=lambda: str(uuid.uuid4()))
async def send(self, for_id: str):
self.forId = for_id
await context.emitter.emit("action", self.to_dict())
async def remove(self):
await context.emitter.emit("remove_action", self.to_dict())