import { z } from 'zod'; import type { AgentAttachmentType, AgentProcessStatus, AgentStatus, AgentToolCallStatus, AgentToolType, ChatType, MessageRole, StreamChunkType } from './enums'; export interface AgentAttachment { id: string; type: AgentAttachmentType; name: string; url?: string; mimeType?: string; metadata?: Record; size?: number; } export interface AgentToolCall { id: string; name: string; input: Record; status: AgentToolCallStatus; output?: Record; error?: string; subagentChatId?: string; /** Characters of tool input streamed so far — live progress for long * generations (e.g. a full page being written into a publish call). */ progressChars?: number; /** Human-readable stage of the streaming tool input, produced by the tool's * describeProgress hook (e.g. "features section"). */ progressLabel?: string; requiresConfirmation?: boolean; requiresUserAction?: boolean; approved?: boolean; approvalId?: string; userResponse?: string; } export type AgentMentionType = 'user' | 'agent'; export interface AgentMention { type: AgentMentionType; name: string; id?: string; } export type AgentMessageSenderType = 'user' | 'agent' | 'system'; export interface AgentMessageSender { id: string; type: AgentMessageSenderType; displayName?: string; avatarUrl?: string; } export type AgentMessagePartType = 'text' | 'reasoning' | 'tool-call'; /** * An ordered fragment of an assistant message. Unlike the flat `content` / * `reasoning` / `toolCalls` fields (which collapse each kind into a single * bucket), `parts` preserves the true chronological order the model produced * them in — e.g. reasoning → text → reasoning → tool-call → text. * * `text` / `reasoning` parts carry their own text; `tool-call` parts only hold * a reference (`toolCallId`) into `toolCalls`, which remains the canonical * store for tool status/input/output/approval. * * Optional and additive: messages without `parts` (all pre-existing rows) are * rendered from the legacy flat fields, so no backfill/migration is required. */ export type AgentMessagePart = { type: 'text'; text: string; } | { type: 'reasoning'; text: string; } | { type: 'tool-call'; toolCallId: string; }; export interface AgentMessage { id: string; chat: string; role: MessageRole; content: string; createdAt: string; reasoning?: string; toolCalls?: AgentToolCall[]; /** Ordered render blocks; preserves reasoning/text/tool-call interleaving. */ parts?: AgentMessagePart[]; attachments?: AgentAttachment[]; annotations?: Record; tokens?: number; agentName?: string; activity?: string; sender?: AgentMessageSender; mentions?: AgentMention[]; } export declare enum AgentSessionKind { ROOT = "ROOT", SUBAGENT = "SUBAGENT" } export interface AgentChat { id: string; title?: string; type?: ChatType; status?: AgentStatus; /** Primary owner user id when distinct from multi-user participants (subagents, legacy rows). */ userId?: string; tenants: Record; sessionKind?: AgentSessionKind; parentChatId?: string; parentMessageId?: string; parentToolCallId?: string; contextKey: string; model?: string; createdAt: string; updatedAt: string; metadata?: Record; participantIds?: string[]; } /** * Paginated messages response. Messages are in chronological order (oldest → newest). */ export interface MessagesPage { messages: AgentMessage[]; hasMore: boolean; } export interface ICurrentCursor { skip?: number; limit?: number; total: number; } export interface DataWithCursor { cursor: ICurrentCursor; data: Array; } export interface AgentProcessSummary { id: string; status: AgentProcessStatus; label: string; createdAt: string; updatedAt: string; sandboxed?: boolean; sandboxId?: string; } export interface SendMessagePayloadWithContent { chatId?: string; content: string; contextKey: string; metadata?: Record; attachments?: AgentAttachment[]; model?: string; userId?: string; participantIds?: string[]; mentions?: AgentMention[]; tenants?: Record; origin?: string; } export interface SendMessagePayloadWithApproval { chatId: string; messageId: string; approvalId: string; approved: boolean; userResponse?: string; metadata?: Record; attachments?: AgentAttachment[]; model?: string; userId?: string; tenants?: Record; origin?: string; } export interface AdditionalContext { headers?: Record; data?: Record; } export type SendMessagePayload = SendMessagePayloadWithContent | SendMessagePayloadWithApproval; export interface MultiUserMessagePayload { chatId?: string; content: string; contextKey: string; metadata?: Record; attachments?: AgentAttachment[]; model?: string; userId?: string; participantIds?: string[]; mentions?: AgentMention[]; senderDisplayName?: string; senderAvatarUrl?: string; tenants?: Record; origin?: string; } export interface MultiUserMessageResponse { chat: AgentChat; message: AgentMessage; agentTriggered: boolean; } export interface StreamChunk { type: StreamChunkType; /** * Optional chat identifier for clients that need to associate * streamed chunks with a new chat before messages arrive. */ chatId?: string; /** * Chat object sent when a new chat is created. * Used with StreamChunkType.Chat. */ chat?: AgentChat; message?: AgentMessage; reasoning?: string; toolCall?: AgentToolCall; artifactId?: string; error?: string; done?: boolean; } export interface AgentArtifact { id: string; label: string; mimeType: string; content: string; createdAt: string; metadata?: Record; } export interface ActivityMetadata { origin?: string; contextKey?: string; model?: string; modelId?: string; agentOptions?: { name?: string; } & Record; finishReason?: string; usage?: { inputTokens?: number; outputTokens?: number; totalTokens?: number; cost?: number; childCount?: number; [key: string]: unknown; }; responseTimestamp?: string | Date; messages?: unknown; providerMetadata?: Record; [key: string]: unknown; } export interface Activity { id: string; ownerId: string; groupId: string; name: string; description?: string; parentId?: string; hasChildren?: boolean; metadata: ActivityMetadata; tenants: Record; sourceId: string; sourceType: string; } export interface ActivitySummaryParams { period?: { from?: Date | string; to?: Date | string; }; timeBucket?: 'hour' | 'day' | 'week' | 'month'; model?: string; tenant?: Record; ownerId?: string; groupBy?: Array<'model' | 'userId' | string>; } export type ActivitySummary = { periodStart?: string; model?: string; tenant?: Record; userId?: string; totalRequests: number; totalTokens: number; totalCost: number; } & Record; export interface AIModel { id: string; provider: string; label: string; description?: string; } export interface ModelOption { id: string; label: string; provider?: string; reasoning?: 'disabled' | 'concise' | 'deep'; contexts?: string[]; description?: string; /** What the model produces. Defaults to 'language' when omitted. */ modality?: 'language' | 'image'; /** Request params the model accepts, for capability checks. */ supportedParameters?: string[]; /** Valid `reasoning_effort` values when reasoning is supported. */ supportedReasoningEfforts?: string[]; } export interface AgentConfigPreference { id: string; userId: string; agentName: string; tools: Record; createdAt: string; updatedAt: string; } export type AIProvider = 'openai' | 'anthropic' | 'google' | 'openrouter'; export interface TenantAICredential { id: string; tenantKey: string; tenants: Record; provider: AIProvider; encryptedApiKey: string; baseUrl?: string; createdAt: string; updatedAt: string; } export interface UpsertTenantAICredentialRequest { tenants: Record; provider: AIProvider; apiKey: string; baseUrl?: string; } /** Request body for POST /agents/:agentName/preferences */ export interface UpsertAgentPreferencesRequest { tools: Record; } /** Response for POST /agents/:agentName/preferences */ export type UpsertAgentPreferencesResponse = AgentConfigPreference; /** Request body for POST /agents/preferences (batch) */ export interface UpsertAgentPreferencesBatchRequest { preferences: Array<{ agentName: string; tools: Record; }>; } /** Response for POST /agents/preferences (batch) */ export interface UpsertAgentPreferencesBatchResponse { preferences: AgentConfigPreference[]; } export interface AgentToolConfiguration { title: string; description?: string; needsApproval?: boolean; disabledByDefault?: boolean; userConfigurable?: boolean; } export interface AgentConfiguration { name: string; description: string; defaultModel?: string; tools: AgentToolConfiguration[]; } export interface AgentApiTool { title: string; description: string; headersToPass: string[]; method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD'; url: string; body?: z.ZodSchema; queryParams?: z.ZodSchema; needsApproval: boolean; } export interface AgentCodeExecutionTool { title: string; description: string; filepath: string; params: z.ZodSchema; needsApproval: boolean; } export interface AgentWebSearchTool { title: string; } export type AgentLocalFunctionTool = T & { title: string; needsApproval: boolean; execute(input: Input, context?: AdditionalContext, options?: any): Promise; /** Optional live-progress narrator: receives the tool call's PARTIAL input * text as it streams and returns a short human-readable stage label * (e.g. "features section"). Runs server-side only; never serialized. */ describeProgress?: (partialInput: string) => string | undefined; }; export interface AgentImageGenerationTool { title?: string; description?: string; /** Image model id, e.g. 'gpt-image-1' or 'imagen-4.0-generate-001'. Falls back to config `ai.defaultImageModel`. */ model?: string; /** Provider to run image generation on. Inferred from the model id when omitted. */ provider?: AIProvider; needsApproval?: boolean; /** Upper bound for images per tool call (the model may ask for fewer). Defaults to 1. */ maxImagesPerCall?: number; } export interface AgentSubagentTool { subAgent: AgentConfig; title: string; description?: string; inputSchema?: z.ZodSchema; } export interface AgentToolAvailability { /** * If true, tool is not available unless explicitly enabled. */ disabledByDefault?: boolean; /** * If true, user can enable/disable this tool after agent creation. */ userConfigurable?: boolean; } export type AgentTool = ({ type: AgentToolType.API_TOOL; data: AgentApiTool; } | { type: AgentToolType.WEB_SEARCH; data?: AgentWebSearchTool; } | { type: AgentToolType.LOCAL_FUNCTION; data: AgentLocalFunctionTool; } | { type: AgentToolType.SUBAGENT; data: AgentSubagentTool; } | { type: AgentToolType.REQUEST_CLARIFICATION; data?: { description?: string; inputSchema?: z.ZodSchema; }; } | { type: AgentToolType.IMAGE_GENERATION; data?: AgentImageGenerationTool; }) & AgentToolAvailability; export type ToolChoice> = 'auto' | 'none' | 'required' | { type: 'tool'; toolName: Extract; }; /** * How a subagent run that ends on a tool-only step is reported back to the * parent. Each tool call's output is inlined verbatim when its JSON fits the * budget and elided otherwise, so the parent never receives whole files or * unbounded result sets it did not ask for. */ export interface AgentDelegationReportOptions { /** Per-tool-call output budget in JSON characters. Defaults to 500. */ maxInlineOutputChars?: number; } export interface AgentConfig = Record> { name: string; description: string; defaultModel?: string; systemPrompt: string; /** Report shaping for headless subagents whose value IS their tool output (data collection). */ delegationReport?: AgentDelegationReportOptions; temperature?: number; maxOutputTokens?: number; topP?: number; topK?: number; presencePenalty?: number; frequencyPenalty?: number; stopSequences?: string[]; seed?: number; outputSchema?: z.ZodSchema; tools: AgentTool[]; toolChoice?: ToolChoice; stopWhen?: any; prepareStep?: any; } export interface AgentAppConfig { [contextKey: string]: AgentConfig[]; } /** * Lifecycle of one agent run: a single user request → model steps → subagent * delegations → final assistant reply. The run is the first-class authority * for budgets, abort, and terminal state — never derived from message scans. */ export declare enum AgentRunStatus { /** A model step is streaming. */ Running = "running", /** Waiting on a subagent delegation. */ Delegating = "delegating", Completed = "completed", Failed = "failed", Aborted = "aborted" } export type AgentRunDelegationStatus = 'running' | 'succeeded' | 'failed' /** Refused before dispatch (budget exhausted). */ | 'rejected' | 'aborted'; export interface AgentRunDelegation { toolCallId: string; toolName: string; subagentChatId?: string; status: AgentRunDelegationStatus; startedAt: string; settledAt?: string; } export interface AgentRun { id: string; chatId: string; /** Assistant message this run produces — exactly one run per turn. */ messageId: string; status: AgentRunStatus; delegationLimit: number; delegationCount: number; delegations: AgentRunDelegation[]; /** The one extra step granted so a tool-only turn can write closing text. */ closingStepUsed: boolean; abortReason?: string; error?: string; createdAt: string; updatedAt: string; finishedAt?: string; } //# sourceMappingURL=models.d.ts.map