UNPKG

@mariozechner/pi-agent

Version:

General-purpose agent with transport abstraction, state management, and attachment support

99 lines 2.63 kB
import type { AgentTool, AssistantMessage, AssistantMessageEvent, Message, Model, UserMessage } from "@mariozechner/pi-ai"; /** * Attachment type definition. * Processing is done by consumers (e.g., document extraction in web-ui). */ export interface Attachment { id: string; type: "image" | "document"; fileName: string; mimeType: string; size: number; content: string; extractedText?: string; preview?: string; } /** * Thinking/reasoning level for models that support it. */ export type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high"; /** * User message with optional attachments. */ export type UserMessageWithAttachments = UserMessage & { attachments?: Attachment[]; }; /** * Extensible interface for custom app messages. * Apps can extend via declaration merging: * * @example * ```typescript * declare module "@mariozechner/agent" { * interface CustomMessages { * artifact: ArtifactMessage; * notification: NotificationMessage; * } * } * ``` */ export interface CustomMessages { } /** * AppMessage: Union of LLM messages + attachments + custom messages. * This abstraction allows apps to add custom message types while maintaining * type safety and compatibility with the base LLM messages. */ export type AppMessage = AssistantMessage | UserMessageWithAttachments | Message | CustomMessages[keyof CustomMessages]; /** * Agent state containing all configuration and conversation data. */ export interface AgentState { systemPrompt: string; model: Model<any>; thinkingLevel: ThinkingLevel; tools: AgentTool<any>[]; messages: AppMessage[]; isStreaming: boolean; streamMessage: Message | null; pendingToolCalls: Set<string>; error?: string; } /** * Events emitted by the Agent for UI updates. * These events provide fine-grained lifecycle information for messages, turns, and tool executions. */ export type AgentEvent = { type: "agent_start"; } | { type: "agent_end"; messages: AppMessage[]; } | { type: "turn_start"; } | { type: "turn_end"; message: AppMessage; toolResults: AppMessage[]; } | { type: "message_start"; message: AppMessage; } | { type: "message_update"; message: AppMessage; assistantMessageEvent: AssistantMessageEvent; } | { type: "message_end"; message: AppMessage; } | { type: "tool_execution_start"; toolCallId: string; toolName: string; args: any; } | { type: "tool_execution_end"; toolCallId: string; toolName: string; result: any; isError: boolean; }; //# sourceMappingURL=types.d.ts.map