// events export type ExtendableMessageEvent = MessageEvent & { waitUntil: (promise: Promise) => void; waitForFinish: () => Promise; }; // agents export interface AgentObject extends EventTarget { id: string; name: string; description: string; bio: string; model: string; address: string; ctx: AppContextValue; getActionHistory: () => Promise; getMemory: (query: string, opts?: GetMemoryOpts) => Promise>; } // messages export type ChatMessage = { role: string; content: string; }; export type ChatMessages = Array; // actions export type ActionMessage = { userId: string; name: string; method: string; args: object; hidden: boolean; timestamp: number; }; export type PendingActionMessage = { method: string; args: object; timestamp: number; }; export type PerceptionMessage = { method: string; args: object; timestamp: number; }; export type ActionMessages = Array; export type AgentActionMessage = { agent: AgentObject; message: ActionMessage; }; export type AgentActionMessages = Array; // memory export type Memory = { text: string; embedding: Array; content: any; }; // active agents export type SubtleAiCompleteOpts = { model: string; }; export type SubtleAiImageOpts = { model: string; width: number; height: number; quality: string; }; export type SubtleAi = { context: AppContextValue; complete: ( messages: ChatMessages, opts?: SubtleAiCompleteOpts, ) => Promise; generateImage: ( prompt: string, opts?: SubtleAiImageOpts, ) => Promise; }; export type GetMemoryOpts = { matchThreshold?: number; matchCount?: number; }; export type AddMemoryOpts = GetMemoryOpts; export interface ActiveAgentObject extends AgentObject { wallets: any; addAction: (action: PendingActionMessage) => Promise; addMemory: ( text: string, content?: any, opts?: AddMemoryOpts, ) => Promise; say: (text: string, opts?: { timestamp?: number }) => Promise; monologue: (text: string) => Promise; think: () => Promise; } // action events export type ActionEventData = { agent: AgentObject; message: ActionMessage; }; export interface ActionEvent extends MessageEvent { data: ActionEventData; } export type PendingActionEventData = { agent: ActiveAgentObject; message: PendingActionMessage; }; export interface PendingActionEvent extends ExtendableMessageEvent { data: PendingActionEventData; commit: () => Promise; } export type AgentEventData = { agent: AgentObject; }; export interface AgentEvent extends MessageEvent { data: AgentEventData; } export type PerceptionEventData = { agent: ActiveAgentObject; message: PerceptionMessage; }; export interface PerceptionEvent extends ExtendableMessageEvent { data: PerceptionEventData; } // scenes export interface SceneObject extends EventTarget { description: string; } // inits export type ActionInit = { description: string; args: object; handler: (action: ActionEvent) => Promise; }; // props export type AgentAppProps = { children?: React.ReactNode; }; export type AgentProps = { children?: React.ReactNode; }; export type ActionProps = { name: string; description: string; example: string; handler: (e: PendingActionEvent) => Promise; }; export type PromptProps = { children: React.ReactNode; }; export type ParserProps = { parseFn: (s: string) => PendingActionMessage | Promise; }; export type PerceptionProps = { type: string; handler: (e: PerceptionEvent) => Promise; }; type ScheduleFnReturnType = number; type AgentConsole = { log: (args: Array) => void; warn: (args: Array) => void; }; export type SchedulerProps = { scheduleFn: () => ScheduleFnReturnType | Promise; }; export type ServerProps = { children: React.ReactNode | (() => void); }; export type SdkDefaultComponentArgs = { DefaultAgentComponents: React.FC; DefaultActions: React.FC; DefaultPrompts: React.FC; DefaultParsers: React.FC; DefaultPerceptions: React.FC; DefaultSchedulers: React.FC; DefaultServers: React.FC; }; // contexts type Compartment = { evaluate: (s: string) => any; }; export type AppContextValue = { // UserCompartment: new (...args: any[]) => Compartment; Agent: React.FC; Action: React.FC; Prompt: React.FC; Parser: React.FC; Perception: React.FC; Scheduler: React.FC; Server: React.FC; subtleAi: SubtleAi; useScene: () => SceneObject; useAgents: () => Array; useCurrentAgent: () => ActiveAgentObject; useActions: () => Array; useActionHistory: (agents: Array | AgentObject) => ActionMessages; useLoad: (p: Promise) => void; registerAgent: (key: symbol, props: AgentProps) => void; unregisterAgent: (key: symbol) => void; registerAction: (key: symbol, props: ActionProps) => void; unregisterAction: (key: symbol) => void; registerPrompt: (key: symbol, props: PromptProps) => void; unregisterPrompt: (key: symbol) => void; registerParser: (key: symbol, props: ParserProps) => void; unregisterParser: (key: symbol) => void; registerPerception: (key: symbol, props: PerceptionProps) => void; unregisterPerception: (key: symbol) => void; registerScheduler: (key: symbol, props: SchedulerProps) => void; unregisterScheduler: (key: symbol) => void; registerServer: (key: symbol, props: ServerProps) => void; unregisterServer: (key: symbol) => void; addAction: ( agent: ActiveAgentObject, action: PendingActionMessage, ) => Promise; think: (agent: ActiveAgentObject) => Promise; say: (agent: ActiveAgentObject, text: string) => Promise; monologue: (agent: ActiveAgentObject, text: string) => Promise; addMemory: ( agent: ActiveAgentObject, text: string, content?: any, opts?: AddMemoryOpts, ) => Promise; getMemory: ( agent: AgentObject, query: string, opts?: GetMemoryOpts, ) => Promise>; embed: (text: string) => Promise>; complete: ( messages: ChatMessages, opts?: SubtleAiCompleteOpts, ) => Promise; generateImage: ( text: string, opts?: SubtleAiImageOpts, ) => Promise; }; // user handler export type UserHandler = React.FC; // hooks export type useAgents = () => Array;