import type { Allocation, ApprovalPart, ApprovalQuestionAnswer, AttachmentRef, ChatModel, Conversation, ConversationSummary, GeneratingReply, ProviderInfo, ProviderIssue, ShareGroup, SharePermission, SharePermissionLevel, TodoItem, TokenUsage, ToolCall, ToolDecision, UnreachableSession } from '../types.js'; import type { CompletionMessage } from './openai/wire.js'; export declare class ChatAdapterError extends Error { status?: number | undefined; retryAt?: string | undefined; constructor(message: string, options?: { status?: number; cause?: unknown; retryAt?: string | undefined; }); } export interface ModelsList { models: ChatModel[]; unreachableSessions: UnreachableSession[]; providerIssues: ProviderIssue[]; } export interface StreamRequest { model: string; messages: CompletionMessage[]; conversationId: string; parentMessageId?: string | null; userMessageId: string; allocation?: string | null; useResponses?: boolean; tools?: string[]; resume?: ToolApprovalAnswer; } export interface ToolApprovalAnswer { messageId: string; toolCallId: string; allowed: boolean; feedback?: string; tool?: string; args?: string; } export interface StreamHandlers { onContent: (content: string) => void; onReasoning?: (reasoning: string) => void; onMessageId?: (messageId: string) => void; onPart?: (delta: PartDelta) => void; onUsage?: (usage: TokenUsage) => void; } export type PartDelta = { type: 'text' | 'reasoning'; text: string; } | { type: 'retract'; } | { type: 'tool_start'; id: string; name: string; args: string; startLine?: number; startedAt?: string; } | { type: 'tool_update'; id: string; args: string; } | { type: 'tool_wait'; id: string; } | { type: 'tool_end'; id: string; result: string; isError?: boolean; } | { type: 'tool_decision'; id: string; decision: ToolDecision; } | { type: 'subagent_start'; id: string; agentType?: string; color?: string; background?: boolean; description?: string; } | { type: 'subagent_action'; id: string; action: string; } /** How many of the subagent's calls a reviewer is deciding on; 0 once none are. */ | { type: 'subagent_reviewing'; id: string; count: number; } | { type: 'subagent_end'; id: string; ok: boolean; summary?: string; report?: string; /** A stop cut it off rather than it failing on its own. */ interrupted?: boolean; } | { type: 'approval_request'; approval: ApprovalPart; } | { type: 'approval_resolved'; id: string; answer?: string; answers?: ApprovalQuestionAnswer[]; chat?: boolean; } | { type: 'notice' | 'warning'; text: string; } | { type: 'todo_snapshot'; todos: TodoItem[]; }; export interface StreamResult { content: string; messageId: string; toolCalls: ToolCall[]; finishReason: string | null; model: string | null; reasoning: string; responsesOutput: unknown[]; } export type StreamCompletion = (req: StreamRequest, handlers: StreamHandlers, signal?: AbortSignal) => Promise; export interface ConversationsAdapter { list(): Promise; get(id: string): Promise; create(title?: string): Promise; rename(id: string, title: string): Promise; remove(id: string): Promise; stop?(id: string): Promise; generating?(id: string): Promise; } export interface ProvidersAdapter { list(): Promise; } export interface AttachmentPage { attachments: AttachmentRef[]; total: number; nextCursor?: string; hasMore: boolean; } export interface AttachmentsAdapter { list(opts: { limit: number; cursor?: string; }): Promise; upload(file: File, conversationId?: string): Promise; remove(id: string): Promise; downloadUrl(id: string): string; onOpen?(attachment: AttachmentRef): void; } export interface SharingAdapter { listPermissions(conversationId: string): Promise; listGroups(): Promise; addPermission(conversationId: string, permission: Omit): Promise; updatePermission(conversationId: string, permissionId: string, permission: SharePermissionLevel): Promise; removePermission(conversationId: string, permissionId: string): Promise; } export interface AllocationsAdapter { list(): Promise; } export interface ChatToolOption { id: string; label: string; description?: string; asksFirst?: boolean; } export interface ChatToolsAdapter { list(): Promise; } export interface ChatAdapter { conversations: ConversationsAdapter; models: { list(): Promise; }; streamCompletion: StreamCompletion; providers?: ProvidersAdapter; attachments?: AttachmentsAdapter; sharing?: SharingAdapter; allocations?: AllocationsAdapter; tools?: ChatToolsAdapter; }