import type { ChatContextCompactionMeta } from "./chat-context-compaction.js"; import type { ChatContinuityMeta } from "./chat-continuity.js"; import type { ChatActor, ChatMessage, ChatScope, ChatThread, ChatWorkflowTimelineEvent } from "./types/chat.js"; export interface ChatApiMeta { requestId: string; idempotencyKey?: string; idempotentReplay?: boolean; nextCursor?: string; policyDecisionId?: string; context?: ChatContextCompactionMeta; continuity?: ChatContinuityMeta; } export interface ChatApiSuccess { data: T; meta: ChatApiMeta; } export interface ChatApiErrorBody { error: { code: string; message: string; requestId: string; retryable: boolean; }; } export interface CreateChatThreadInput { requestId?: string; scope: ChatScope; title: string; actor: ChatActor; } export interface ListChatInput { requestId?: string; scope: ChatScope; limit?: number; cursor?: string; } export interface ChatThreadInput { requestId?: string; scope: ChatScope; threadId: string; } export interface ChatMessagesInput extends ChatThreadInput { limit?: number; cursor?: string; expectedLastMessageId?: string; expectedLastSequence?: number; } export interface ChatMessageInput extends ChatThreadInput { idempotencyKey?: string; actor: ChatActor; text: string; format?: "plain_text" | "markdown"; } export interface ChatSendInput extends ChatMessageInput { stream?: boolean; contextBudgetTokens?: number; contextThresholdTokens?: number; contextRecentMessageCount?: number; } export type ChatStreamEventType = "message.created" | "message.delta" | "workflow.event" | "runtime.lifecycle" | "policy.blocked" | "error" | "complete"; export interface ChatStreamEvent { eventId: string; threadId: string; scope: ChatScope; createdAt: string; sequence: number; type: ChatStreamEventType; data: ChatStreamEventData; } export type ChatStreamEventData = { message: ChatMessage; } | { text: string; } | { workflowEvent: ChatWorkflowTimelineEvent; } | { lifecycleStatus: string; runtimeEvent?: ChatWorkflowTimelineEvent; } | { reasons: string[]; } | { code: string; message: string; } | { thread: ChatThread; } | { continuity: ChatContinuityMeta; }; export interface ChatSendResult { message?: ChatMessage; events: ChatStreamEvent[]; context?: ChatContextCompactionMeta; continuity?: ChatContinuityMeta; }