e30e75b5d4
Changesets / Create Version PR (push) Waiting to run
Code Quality / Oxlint + Oxfmt (push) Waiting to run
Code Quality / Template Sync (push) Waiting to run
Code Quality / Build Changed Packages (push) Waiting to run
Code Quality / Test Changed Packages (push) Waiting to run
Deploy Expo Example / Deploy Production (push) Waiting to run
Deploy Ink Example / Deploy Production (push) Waiting to run
Python Tests / pytest (assistant-stream, 3.10) (push) Waiting to run
Python Tests / pytest (assistant-stream, 3.12) (push) Waiting to run
Python Tests / pytest (assistant-ui-sync-server-api, 3.10) (push) Waiting to run
Python Tests / pytest (assistant-ui-sync-server-api, 3.12) (push) Waiting to run
Deploy Shadcn Registry / Deploy Production (push) Waiting to run
Template Metrics / LOC + Bundle Size (push) Waiting to run
1940 lines
59 KiB
TypeScript
1940 lines
59 KiB
TypeScript
import { AssistantMessage, Event, FilePart, GlobalSession, Message as Message$1, Message as Message$2, Model, OpencodeClient, OpencodeClient as OpencodeClient$1, OpencodeClientConfig, Part, Part as Part$1, PermissionRequest, PermissionRequest as PermissionRequest$1, Provider, QuestionAnswer, QuestionAnswer as QuestionAnswer$1, QuestionRequest, QuestionRequest as QuestionRequest$1, ReasoningPart, Session, Session as Session$1, SessionStatus, SessionStatus as SessionStatus$1, SnapshotPart, StepFinishPart, StepStartPart, TextPart, ToolPart, ToolState, UserMessage, createOpencodeClient as createOpencodeClient$1 } from "@opencode-ai/sdk/v2/client";
|
|
|
|
import "@radix-ui/react-primitive";
|
|
|
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
|
|
import "radix-ui";
|
|
|
|
import "react-textarea-autosize";
|
|
|
|
import "zustand";
|
|
|
|
type AddToolResultOptions = {
|
|
messageId: string;
|
|
toolName: string;
|
|
toolCallId: string;
|
|
result: ReadonlyJSONValue;
|
|
isError: boolean;
|
|
artifact?: ReadonlyJSONValue | undefined;
|
|
modelContent?: readonly ToolModelContentPart[] | undefined;
|
|
};
|
|
|
|
type AncestorsOf<K extends ClientNames, Seen extends ClientNames = never> = K extends Seen ? never : ParentOf<K> extends never ? never : ParentOf<K> | AncestorsOf<ParentOf<K>, Seen | K>;
|
|
|
|
type AppendMessage = Omit<ThreadMessage, "id"> & {
|
|
parentId: string | null;
|
|
sourceId: string | null;
|
|
runConfig: RunConfig | undefined;
|
|
startRun?: boolean | undefined;
|
|
steer?: boolean | undefined;
|
|
};
|
|
|
|
type AsNumber<K> = K extends `${infer N extends number}` ? N | K : never;
|
|
|
|
type AssistantClient = {
|
|
[K in ClientNames]: AssistantClientAccessor<K>;
|
|
} & {
|
|
subscribe(listener: () => void): Unsubscribe$1;
|
|
on<TEvent extends AssistantEventName>(selector: AssistantEventSelector<TEvent>, callback: AssistantEventCallback<TEvent>): Unsubscribe$1;
|
|
};
|
|
|
|
type AssistantClientAccessor<K extends ClientNames> = (() => ClientSchemas[K]["methods"]) & (ClientMeta<K> | {
|
|
source: "root";
|
|
query: Record<string, never>;
|
|
} | {
|
|
source: null;
|
|
query: null;
|
|
}) & {
|
|
name: K;
|
|
};
|
|
|
|
type AssistantEventCallback<TEvent extends AssistantEventName> = (payload: AssistantEventPayload[TEvent]) => void;
|
|
|
|
type AssistantEventName = keyof AssistantEventPayload;
|
|
|
|
type AssistantEventPayload = ClientEventMap & {
|
|
"*": WildcardPayload;
|
|
};
|
|
|
|
type AssistantEventScope<TEvent extends AssistantEventName> = "*" | EventSource<TEvent> | (EventSource<TEvent> extends ClientNames ? AncestorsOf<EventSource<TEvent>> : never);
|
|
|
|
type AssistantEventSelector<TEvent extends AssistantEventName> = TEvent | {
|
|
scope: AssistantEventScope<TEvent>;
|
|
event: TEvent;
|
|
};
|
|
|
|
type AssistantRuntime = {
|
|
readonly threads: ThreadListRuntime;
|
|
readonly thread: ThreadRuntime;
|
|
registerModelContextProvider(provider: ModelContextProvider): Unsubscribe;
|
|
};
|
|
|
|
type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
|
|
|
|
type Attachment = PendingAttachment | CompleteAttachment;
|
|
|
|
type AttachmentAdapter = {
|
|
accept: string;
|
|
add(state: {
|
|
file: File;
|
|
}): Promise<PendingAttachment> | AsyncGenerator<PendingAttachment, void>;
|
|
remove(attachment: Attachment): Promise<void>;
|
|
send(attachment: PendingAttachment): Promise<CompleteAttachment>;
|
|
};
|
|
|
|
type AttachmentAddErrorEvent = {
|
|
readonly reason: AttachmentAddErrorReason;
|
|
readonly message: string;
|
|
readonly attachmentId?: string;
|
|
readonly error?: Error;
|
|
};
|
|
|
|
type AttachmentAddErrorReason = "adapter-error" | "no-adapter" | "not-accepted";
|
|
|
|
type AttachmentRuntime<TSource extends AttachmentRuntimeSource = AttachmentRuntimeSource> = {
|
|
readonly path: AttachmentRuntimePath & {
|
|
attachmentSource: TSource;
|
|
};
|
|
readonly source: TSource;
|
|
getState(): AttachmentState & {
|
|
source: TSource;
|
|
};
|
|
remove(): Promise<void>;
|
|
subscribe(callback: () => void): Unsubscribe;
|
|
};
|
|
|
|
type AttachmentRuntimePath = ((MessageRuntimePath & {
|
|
readonly attachmentSource: "edit-composer" | "message";
|
|
}) | (ThreadRuntimePath & {
|
|
readonly attachmentSource: "thread-composer";
|
|
})) & {
|
|
readonly attachmentSelector: {
|
|
readonly type: "index";
|
|
readonly index: number;
|
|
} | {
|
|
readonly type: "index";
|
|
readonly index: number;
|
|
} | {
|
|
readonly type: "index";
|
|
readonly index: number;
|
|
};
|
|
};
|
|
|
|
type AttachmentRuntimeSource = AttachmentState["source"];
|
|
|
|
type AttachmentState = ThreadComposerAttachmentState | EditComposerAttachmentState | MessageAttachmentState;
|
|
|
|
type BackendTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = ToolBase<TArgs, TResult> & {
|
|
type: "backend";
|
|
description?: undefined;
|
|
parameters?: undefined;
|
|
disabled?: undefined;
|
|
execute?: undefined;
|
|
toModelOutput?: undefined;
|
|
experimental_onSchemaValidationError?: undefined;
|
|
providerOptions?: undefined;
|
|
};
|
|
|
|
type BaseAttachment = {
|
|
id: string;
|
|
type: "image" | "document" | "file" | (string & {});
|
|
name: string;
|
|
contentType?: string | undefined;
|
|
file?: File;
|
|
content?: ThreadUserMessagePart[];
|
|
};
|
|
|
|
type BaseComposerState = {
|
|
readonly canCancel: boolean;
|
|
readonly canSend: boolean;
|
|
readonly isEditing: boolean;
|
|
readonly isEmpty: boolean;
|
|
readonly text: string;
|
|
readonly role: MessageRole;
|
|
readonly attachments: readonly Attachment[];
|
|
readonly runConfig: RunConfig;
|
|
readonly attachmentAccept: string;
|
|
readonly dictation: DictationState | undefined;
|
|
readonly quote: QuoteInfo | undefined;
|
|
readonly queue: readonly QueueItemState[];
|
|
};
|
|
|
|
type BaseThreadMessage = {
|
|
readonly status?: ThreadAssistantMessage["status"];
|
|
readonly metadata: {
|
|
readonly unstable_state?: ReadonlyJSONValue;
|
|
readonly unstable_annotations?: readonly ReadonlyJSONValue[];
|
|
readonly unstable_data?: readonly ReadonlyJSONValue[];
|
|
readonly steps?: readonly ThreadStep[];
|
|
readonly submittedFeedback?: {
|
|
readonly type: "negative" | "positive";
|
|
};
|
|
readonly timing?: MessageTiming;
|
|
readonly isOptimistic?: boolean;
|
|
readonly custom: Record<string, unknown>;
|
|
};
|
|
readonly attachments?: ThreadUserMessage["attachments"];
|
|
};
|
|
|
|
type ChatModelRunOptions = {
|
|
readonly messages: readonly ThreadMessage[];
|
|
readonly runConfig: RunConfig;
|
|
readonly abortSignal: AbortSignal;
|
|
readonly context: ModelContext;
|
|
readonly unstable_assistantMessageId?: string | undefined;
|
|
readonly unstable_threadId?: string | undefined;
|
|
readonly unstable_parentId?: string | null | undefined;
|
|
unstable_getMessage(): ThreadMessage;
|
|
};
|
|
|
|
type ChatModelRunResult = {
|
|
readonly content?: readonly ThreadAssistantMessagePart[] | undefined;
|
|
readonly status?: MessageStatus | undefined;
|
|
readonly metadata?: {
|
|
readonly unstable_state?: ReadonlyJSONValue;
|
|
readonly unstable_annotations?: readonly ReadonlyJSONValue[] | undefined;
|
|
readonly unstable_data?: readonly ReadonlyJSONValue[] | undefined;
|
|
readonly steps?: readonly ThreadStep[] | undefined;
|
|
readonly timing?: MessageTiming | undefined;
|
|
readonly custom?: Record<string, unknown> | undefined;
|
|
};
|
|
};
|
|
|
|
type ClientError<E extends string> = {
|
|
methods: Record<E, () => E>;
|
|
meta: {
|
|
source: ClientNames;
|
|
query: Record<E, E>;
|
|
};
|
|
events: Record<`${E}.`, E>;
|
|
};
|
|
|
|
type ClientEventMap = UnionToIntersection<{
|
|
[K in ClientNames]: ClientEvents<K>;
|
|
}[ClientNames]>;
|
|
|
|
type ClientEvents<K extends ClientNames> = "events" extends keyof ClientSchemas[K] ? ClientSchemas[K]["events"] extends ClientEventsType<K> ? ClientSchemas[K]["events"] : never : never;
|
|
|
|
type ClientEventsType<K extends ClientNames> = Record<`${K}.${string}`, unknown>;
|
|
|
|
type ClientMeta<K extends ClientNames> = "meta" extends keyof ClientSchemas[K] ? Pick<ClientSchemas[K]["meta"] extends ClientMetaType ? ClientSchemas[K]["meta"] : never, "query" | "source"> : never;
|
|
|
|
type ClientMetaType = {
|
|
source: ClientNames;
|
|
query: Record<string, unknown>;
|
|
};
|
|
|
|
interface ClientMethods {
|
|
[key: string | symbol]: (...args: any[]) => any;
|
|
}
|
|
|
|
type ClientNames = keyof ClientSchemas extends (infer U) ? U : never;
|
|
|
|
type ClientSchemas = keyof ScopeRegistry extends never ? {
|
|
"ERROR: No clients were defined": ClientError<"ERROR: No clients were defined">;
|
|
} : {
|
|
[K in keyof ScopeRegistry]: ValidateClient<K>;
|
|
};
|
|
|
|
type CompleteAttachment = BaseAttachment & {
|
|
status: CompleteAttachmentStatus;
|
|
content: ThreadUserMessagePart[];
|
|
};
|
|
|
|
type CompleteAttachmentStatus = {
|
|
type: "complete";
|
|
};
|
|
|
|
type ComposerRuntime = {
|
|
readonly path: ComposerRuntimePath;
|
|
readonly type: "edit" | "thread";
|
|
getState(): ComposerState;
|
|
addAttachment(fileOrAttachment: File | CreateAttachment): Promise<void>;
|
|
setText(text: string): void;
|
|
setRole(role: MessageRole): void;
|
|
setRunConfig(runConfig: RunConfig): void;
|
|
reset(): Promise<void>;
|
|
clearAttachments(): Promise<void>;
|
|
send(options?: SendOptions): void;
|
|
cancel(): void;
|
|
steerQueueItem(queueItemId: string): void;
|
|
removeQueueItem(queueItemId: string): void;
|
|
subscribe(callback: () => void): Unsubscribe;
|
|
getAttachmentByIndex(idx: number): AttachmentRuntime;
|
|
startDictation(): void;
|
|
stopDictation(): void;
|
|
setQuote(quote: QuoteInfo | undefined): void;
|
|
unstable_on<E extends ComposerRuntimeEventType>(event: E, callback: ComposerRuntimeEventCallback<E>): Unsubscribe;
|
|
};
|
|
|
|
type ComposerRuntimeEventCallback<E extends ComposerRuntimeEventType> = (payload: ComposerRuntimeEventPayload[E]) => void;
|
|
|
|
type ComposerRuntimeEventPayload = {
|
|
send: Record<string, never>;
|
|
attachmentAdd: Record<string, never>;
|
|
attachmentAddError: AttachmentAddErrorEvent;
|
|
};
|
|
|
|
type ComposerRuntimeEventType = keyof ComposerRuntimeEventPayload;
|
|
|
|
type ComposerRuntimePath = (ThreadRuntimePath & {
|
|
readonly composerSource: "thread";
|
|
}) | (MessageRuntimePath & {
|
|
readonly composerSource: "edit";
|
|
});
|
|
|
|
type ComposerState = ThreadComposerState | EditComposerState;
|
|
|
|
type CreateAppendMessage = string | {
|
|
parentId?: string | null | undefined;
|
|
sourceId?: string | null | undefined;
|
|
role?: AppendMessage["role"] | undefined;
|
|
content: AppendMessage["content"];
|
|
attachments?: AppendMessage["attachments"] | undefined;
|
|
metadata?: AppendMessage["metadata"] | undefined;
|
|
createdAt?: Date | undefined;
|
|
runConfig?: AppendMessage["runConfig"] | undefined;
|
|
startRun?: boolean | undefined;
|
|
};
|
|
|
|
type CreateAttachment = {
|
|
id?: string;
|
|
type?: "image" | "document" | "file" | (string & {});
|
|
name: string;
|
|
contentType?: string;
|
|
content: ThreadUserMessagePart[];
|
|
};
|
|
|
|
type CreateResumeRunConfig = CreateStartRunConfig & {
|
|
stream?: (options: ChatModelRunOptions) => AsyncGenerator<ChatModelRunResult, void, unknown>;
|
|
};
|
|
|
|
type CreateStartRunConfig = {
|
|
parentId: string | null;
|
|
sourceId?: string | null | undefined;
|
|
runConfig?: RunConfig | undefined;
|
|
};
|
|
|
|
type DataMessagePart<T = any> = {
|
|
readonly type: "data";
|
|
readonly name: string;
|
|
readonly data: T;
|
|
};
|
|
|
|
type DataPrefixedPart = {
|
|
readonly type: `data-${string}`;
|
|
readonly data: any;
|
|
};
|
|
|
|
type DeepPartial<T> = T extends readonly any[] ? readonly DeepPartial<T[number]>[] : T extends {
|
|
[key: string]: any;
|
|
} ? {
|
|
readonly [K in keyof T]?: DeepPartial<T[K]>;
|
|
} : T;
|
|
|
|
interface DevToolsApiEntry {
|
|
api: Partial<AssistantClient>;
|
|
logs: EventLog[];
|
|
}
|
|
|
|
interface DevToolsHook {
|
|
apis: Map<number, DevToolsApiEntry>;
|
|
nextId: number;
|
|
listeners: Set<(apiId: number) => void>;
|
|
}
|
|
|
|
declare namespace DictationAdapter {
|
|
type Status = {
|
|
type: "running" | "starting";
|
|
} | {
|
|
type: "ended";
|
|
reason: "cancelled" | "error" | "stopped";
|
|
};
|
|
type Result = {
|
|
transcript: string;
|
|
isFinal?: boolean;
|
|
};
|
|
type Session = {
|
|
status: Status;
|
|
stop: () => Promise<void>;
|
|
cancel: () => void;
|
|
onSpeechStart: (callback: () => void) => Unsubscribe;
|
|
onSpeechEnd: (callback: (result: Result) => void) => Unsubscribe;
|
|
onSpeech: (callback: (result: Result) => void) => Unsubscribe;
|
|
};
|
|
}
|
|
|
|
type DictationAdapter = {
|
|
listen: () => DictationAdapter.Session;
|
|
disableInputDuringDictation?: boolean;
|
|
};
|
|
|
|
type DictationState = {
|
|
readonly status: DictationAdapter.Status;
|
|
readonly transcript?: string;
|
|
readonly inputDisabled?: boolean;
|
|
};
|
|
|
|
type EditComposerAttachmentState = Attachment & {
|
|
readonly source: "edit-composer";
|
|
};
|
|
|
|
type EditComposerRuntime = Omit<ComposerRuntime, "getAttachmentByIndex" | "getState"> & {
|
|
readonly path: ComposerRuntimePath & {
|
|
composerSource: "edit";
|
|
};
|
|
readonly type: "edit";
|
|
getState(): EditComposerState;
|
|
beginEdit(): void;
|
|
getAttachmentByIndex(idx: number): AttachmentRuntime & {
|
|
source: "edit-composer";
|
|
};
|
|
};
|
|
|
|
type EditComposerState = BaseComposerState & {
|
|
readonly type: "edit";
|
|
readonly parentId: string | null;
|
|
readonly sourceId: string | null;
|
|
};
|
|
|
|
interface EventLog {
|
|
time: Date;
|
|
event: string;
|
|
data: unknown;
|
|
}
|
|
|
|
type EventSource<T extends AssistantEventName> = T extends `${infer Source}.${string}` ? Source : never;
|
|
|
|
type ExportedMessageRepository = {
|
|
headId?: string | null;
|
|
messages: Array<{
|
|
message: ThreadMessage;
|
|
parentId: string | null;
|
|
runConfig?: RunConfig;
|
|
}>;
|
|
};
|
|
|
|
declare const ExportedMessageRepository: {
|
|
fromArray: (messages: readonly ThreadMessageLike[]) => ExportedMessageRepository;
|
|
fromBranchableArray: (items: readonly {
|
|
message: ThreadMessageLike;
|
|
parentId: string | null;
|
|
}[], options?: {
|
|
headId?: string | null;
|
|
}) => ExportedMessageRepository;
|
|
};
|
|
|
|
type ExternalStoreAdapter<T = ThreadMessage> = ExternalStoreAdapterBase<T> & (T extends ThreadMessage ? object : ExternalStoreMessageConverterAdapter<T>);
|
|
|
|
type ExternalStoreAdapterBase<T> = {
|
|
isDisabled?: boolean | undefined;
|
|
isSendDisabled?: boolean | undefined;
|
|
isRunning?: boolean | undefined;
|
|
isLoading?: boolean | undefined;
|
|
messages?: readonly T[];
|
|
messageRepository?: ExportedMessageRepository;
|
|
suggestions?: readonly ThreadSuggestion[] | undefined;
|
|
state?: ReadonlyJSONValue | undefined;
|
|
extras?: unknown;
|
|
setMessages?: ((messages: readonly T[]) => void) | undefined;
|
|
unstable_onBranchChange?: ((event: ExternalStoreBranchChange) => void) | undefined;
|
|
onImport?: ((messages: readonly ThreadMessage[]) => void) | undefined;
|
|
onExportExternalState?: (() => any) | undefined;
|
|
onLoadExternalState?: ((state: any) => void) | undefined;
|
|
onNew: (message: AppendMessage) => Promise<void>;
|
|
queue?: ExternalThreadQueueAdapter | undefined;
|
|
onEdit?: ((message: AppendMessage) => Promise<void>) | undefined;
|
|
onDelete?: ((messageId: string) => Promise<void> | void) | undefined;
|
|
onReload?: ((parentId: string | null, config: StartRunConfig) => Promise<void>) | undefined;
|
|
onResume?: ((config: ResumeRunConfig) => Promise<void>) | undefined;
|
|
onCancel?: (() => Promise<void>) | undefined;
|
|
onAddToolResult?: ((options: AddToolResultOptions) => Promise<void> | void) | undefined;
|
|
onResumeToolCall?: ((options: {
|
|
toolCallId: string;
|
|
payload: unknown;
|
|
}) => void) | undefined;
|
|
onRespondToToolApproval?: ((options: RespondToToolApprovalOptions) => Promise<void> | void) | undefined;
|
|
convertMessage?: ExternalStoreMessageConverter<T> | undefined;
|
|
adapters?: {
|
|
attachments?: AttachmentAdapter | undefined;
|
|
speech?: SpeechSynthesisAdapter | undefined;
|
|
dictation?: DictationAdapter | undefined;
|
|
voice?: RealtimeVoiceAdapter | undefined;
|
|
feedback?: FeedbackAdapter | undefined;
|
|
threadList?: ExternalStoreThreadListAdapter | undefined;
|
|
} | undefined;
|
|
unstable_capabilities?: {
|
|
copy?: boolean | undefined;
|
|
} | undefined;
|
|
unstable_enableToolInvocations?: boolean | undefined;
|
|
setToolStatuses?: ((statuses: Record<string, ToolExecutionStatus>) => void) | undefined;
|
|
};
|
|
|
|
type ExternalStoreBranchChange = {
|
|
headId: string | null;
|
|
visibleMessageIds: readonly string[];
|
|
};
|
|
|
|
type ExternalStoreMessageConverter<T> = (message: T, idx: number) => ThreadMessageLike;
|
|
|
|
type ExternalStoreMessageConverterAdapter<T> = {
|
|
convertMessage: ExternalStoreMessageConverter<T>;
|
|
};
|
|
|
|
type ExternalStoreSharedOptions = Pick<ExternalStoreAdapter, "isDisabled" | "isSendDisabled" | "suggestions" | "unstable_capabilities">;
|
|
|
|
type ExternalStoreThreadData<TState extends "archived" | "regular"> = {
|
|
status: TState;
|
|
id: string;
|
|
remoteId?: string | undefined;
|
|
externalId?: string | undefined;
|
|
title?: string | undefined;
|
|
custom?: Record<string, unknown> | undefined;
|
|
};
|
|
|
|
type ExternalStoreThreadListAdapter = {
|
|
threadId?: string | undefined;
|
|
isLoading?: boolean | undefined;
|
|
threads?: readonly ExternalStoreThreadData<"regular">[] | undefined;
|
|
archivedThreads?: readonly ExternalStoreThreadData<"archived">[] | undefined;
|
|
onSwitchToNewThread?: (() => Promise<void> | void) | undefined;
|
|
onSwitchToThread?: ((threadId: string) => Promise<void> | void) | undefined;
|
|
onRename?: (threadId: string, newTitle: string) => (Promise<void> | void) | undefined;
|
|
onUpdateCustom?: ((threadId: string, custom: Record<string, unknown> | undefined) => Promise<void> | void) | undefined;
|
|
onArchive?: ((threadId: string) => Promise<void> | void) | undefined;
|
|
onUnarchive?: ((threadId: string) => Promise<void> | void) | undefined;
|
|
onDelete?: ((threadId: string) => Promise<void> | void) | undefined;
|
|
};
|
|
|
|
type ExternalThreadQueueAdapter = {
|
|
items: readonly QueueItemState[];
|
|
enqueue: (message: AppendMessage, options: {
|
|
steer: boolean;
|
|
}) => void;
|
|
steer: (queueItemId: string) => void;
|
|
remove: (queueItemId: string) => void;
|
|
clear: (reason: "cancel-run" | "edit" | "reload") => void;
|
|
};
|
|
|
|
type FeedbackAdapter = {
|
|
submit: (feedback: FeedbackAdapterFeedback) => void;
|
|
};
|
|
|
|
type FeedbackAdapterFeedback = {
|
|
message: ThreadMessage;
|
|
type: "negative" | "positive";
|
|
};
|
|
|
|
type FileMessagePart = {
|
|
readonly type: "file";
|
|
readonly filename?: string;
|
|
readonly data: string;
|
|
readonly mimeType: string;
|
|
readonly parentId?: string;
|
|
};
|
|
|
|
type FrontendTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = ToolBase<TArgs, TResult> & {
|
|
type: "frontend";
|
|
description?: string | undefined;
|
|
parameters: StandardSchemaV1<TArgs> | JSONSchema7;
|
|
disabled?: boolean;
|
|
execute?: ToolExecuteFunction<TArgs, TResult>;
|
|
toModelOutput?: ToolModelOutputFunction<TArgs, TResult>;
|
|
experimental_onSchemaValidationError?: OnSchemaValidationErrorFunction<TResult>;
|
|
providerOptions?: ProviderOptions;
|
|
};
|
|
|
|
type GenerativeUIMessagePart = {
|
|
readonly type: "generative-ui";
|
|
readonly spec: GenerativeUISpec;
|
|
readonly id?: string;
|
|
readonly parentId?: string;
|
|
};
|
|
|
|
type GenerativeUINode = string | {
|
|
readonly component: string;
|
|
readonly props?: Record<string, unknown>;
|
|
readonly children?: readonly GenerativeUINode[];
|
|
readonly key?: string;
|
|
};
|
|
|
|
type GenerativeUISpec = {
|
|
readonly root: GenerativeUINode | readonly GenerativeUINode[];
|
|
};
|
|
|
|
type HumanTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = ToolBase<TArgs, TResult> & {
|
|
type: "human";
|
|
description?: string | undefined;
|
|
parameters: StandardSchemaV1<TArgs> | JSONSchema7;
|
|
disabled?: boolean;
|
|
display?: "standalone";
|
|
execute?: undefined;
|
|
toModelOutput?: undefined;
|
|
experimental_onSchemaValidationError?: undefined;
|
|
providerOptions?: ProviderOptions;
|
|
};
|
|
|
|
type ImageMessagePart = {
|
|
readonly type: "image";
|
|
readonly image: string;
|
|
readonly filename?: string;
|
|
};
|
|
|
|
interface JSONSchema7 {
|
|
$id?: string | undefined;
|
|
$ref?: string | undefined;
|
|
$schema?: JSONSchema7Version | undefined;
|
|
$comment?: string | undefined;
|
|
$defs?: {
|
|
[key: string]: JSONSchema7Definition;
|
|
} | undefined;
|
|
type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
|
|
enum?: JSONSchema7Type[] | undefined;
|
|
const?: JSONSchema7Type | undefined;
|
|
multipleOf?: number | undefined;
|
|
maximum?: number | undefined;
|
|
exclusiveMaximum?: number | undefined;
|
|
minimum?: number | undefined;
|
|
exclusiveMinimum?: number | undefined;
|
|
maxLength?: number | undefined;
|
|
minLength?: number | undefined;
|
|
pattern?: string | undefined;
|
|
items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
|
|
additionalItems?: JSONSchema7Definition | undefined;
|
|
maxItems?: number | undefined;
|
|
minItems?: number | undefined;
|
|
uniqueItems?: boolean | undefined;
|
|
contains?: JSONSchema7Definition | undefined;
|
|
maxProperties?: number | undefined;
|
|
minProperties?: number | undefined;
|
|
required?: string[] | undefined;
|
|
properties?: {
|
|
[key: string]: JSONSchema7Definition;
|
|
} | undefined;
|
|
patternProperties?: {
|
|
[key: string]: JSONSchema7Definition;
|
|
} | undefined;
|
|
additionalProperties?: JSONSchema7Definition | undefined;
|
|
dependencies?: {
|
|
[key: string]: JSONSchema7Definition | string[];
|
|
} | undefined;
|
|
propertyNames?: JSONSchema7Definition | undefined;
|
|
if?: JSONSchema7Definition | undefined;
|
|
then?: JSONSchema7Definition | undefined;
|
|
else?: JSONSchema7Definition | undefined;
|
|
allOf?: JSONSchema7Definition[] | undefined;
|
|
anyOf?: JSONSchema7Definition[] | undefined;
|
|
oneOf?: JSONSchema7Definition[] | undefined;
|
|
not?: JSONSchema7Definition | undefined;
|
|
format?: string | undefined;
|
|
contentMediaType?: string | undefined;
|
|
contentEncoding?: string | undefined;
|
|
definitions?: {
|
|
[key: string]: JSONSchema7Definition;
|
|
} | undefined;
|
|
title?: string | undefined;
|
|
description?: string | undefined;
|
|
default?: JSONSchema7Type | undefined;
|
|
readOnly?: boolean | undefined;
|
|
writeOnly?: boolean | undefined;
|
|
examples?: JSONSchema7Type | undefined;
|
|
}
|
|
|
|
interface JSONSchema7Array extends Array<JSONSchema7Type> {
|
|
}
|
|
|
|
type JSONSchema7Definition = JSONSchema7 | boolean;
|
|
|
|
interface JSONSchema7Object {
|
|
[key: string]: JSONSchema7Type;
|
|
}
|
|
|
|
type JSONSchema7Type = string | number | boolean | JSONSchema7Object | JSONSchema7Array | null;
|
|
|
|
type JSONSchema7TypeName = "array" | "boolean" | "integer" | "null" | "number" | "object" | "string";
|
|
|
|
type JSONSchema7Version = string;
|
|
|
|
type LanguageModelConfig = {
|
|
apiKey?: string;
|
|
baseUrl?: string;
|
|
modelName?: string;
|
|
reasoningEffort?: string;
|
|
};
|
|
|
|
type LanguageModelV1CallSettings = {
|
|
maxTokens?: number;
|
|
temperature?: number;
|
|
topP?: number;
|
|
presencePenalty?: number;
|
|
frequencyPenalty?: number;
|
|
seed?: number;
|
|
headers?: Record<string, string | undefined>;
|
|
};
|
|
|
|
type Listener = (event: OpenCodeServerEvent) => void;
|
|
|
|
type McpAppMetadata = {
|
|
readonly resourceUri: string;
|
|
readonly mimeType?: string;
|
|
readonly visibility?: readonly ("app" | "model")[];
|
|
};
|
|
|
|
type McpServerConfig = {
|
|
type: "http" | "sse";
|
|
url: string;
|
|
headers?: Record<string, string>;
|
|
redirect?: "error" | "follow";
|
|
connectionTimeout?: number | undefined;
|
|
} | {
|
|
type: "stdio";
|
|
command: string;
|
|
args?: readonly string[];
|
|
env?: Record<string, string>;
|
|
cwd?: string;
|
|
connectionTimeout?: number | undefined;
|
|
};
|
|
|
|
type McpTool = ToolBase<Record<string, unknown>, unknown> & {
|
|
type: "mcp";
|
|
server: McpServerConfig;
|
|
description?: undefined;
|
|
parameters?: undefined;
|
|
disabled?: boolean;
|
|
execute?: undefined;
|
|
toModelOutput?: undefined;
|
|
experimental_onSchemaValidationError?: undefined;
|
|
providerOptions?: undefined;
|
|
};
|
|
|
|
type MessageAttachmentState = CompleteAttachment & {
|
|
readonly source: "message";
|
|
};
|
|
|
|
type MessageCommonProps = {
|
|
readonly id: string;
|
|
readonly createdAt: Date;
|
|
};
|
|
|
|
type MessagePartRuntime = {
|
|
addToolResult(result: any | ToolResponse<any>): void;
|
|
resumeToolCall(payload: unknown): void;
|
|
respondToToolApproval(response: ToolApprovalResponse): void;
|
|
readonly path: MessagePartRuntimePath;
|
|
getState(): MessagePartState;
|
|
subscribe(callback: () => void): Unsubscribe;
|
|
};
|
|
|
|
type MessagePartRuntimePath = MessageRuntimePath & {
|
|
readonly messagePartSelector: {
|
|
readonly type: "index";
|
|
readonly index: number;
|
|
} | {
|
|
readonly type: "toolCallId";
|
|
readonly toolCallId: string;
|
|
};
|
|
};
|
|
|
|
type MessagePartState = (ThreadUserMessagePart | ThreadAssistantMessagePart) & {
|
|
readonly status: MessagePartStatus | ToolCallMessagePartStatus;
|
|
};
|
|
|
|
type MessagePartStatus = {
|
|
readonly type: "running";
|
|
} | {
|
|
readonly type: "complete";
|
|
} | {
|
|
readonly type: "incomplete";
|
|
readonly reason: "cancelled" | "content-filter" | "error" | "length" | "other";
|
|
readonly error?: unknown;
|
|
};
|
|
|
|
type MessageRole = ThreadMessage["role"];
|
|
|
|
type MessageRuntime = {
|
|
readonly path: MessageRuntimePath;
|
|
readonly composer: EditComposerRuntime;
|
|
getState(): MessageState;
|
|
delete(): void | Promise<void>;
|
|
reload(config?: ReloadConfig): void;
|
|
speak(): void;
|
|
stopSpeaking(): void;
|
|
submitFeedback(_param0: {
|
|
type: "positive" | "negative";
|
|
}): void;
|
|
switchToBranch(_param1: {
|
|
position?: "previous" | "next" | undefined;
|
|
branchId?: string | undefined;
|
|
}): void;
|
|
unstable_getCopyText(): string;
|
|
subscribe(callback: () => void): Unsubscribe;
|
|
getMessagePartByIndex(idx: number): MessagePartRuntime;
|
|
getMessagePartByToolCallId(toolCallId: string): MessagePartRuntime;
|
|
getAttachmentByIndex(idx: number): AttachmentRuntime & {
|
|
source: "message";
|
|
};
|
|
};
|
|
|
|
type MessageRuntimePath = ThreadRuntimePath & {
|
|
readonly messageSelector: {
|
|
readonly type: "messageId";
|
|
readonly messageId: string;
|
|
} | {
|
|
readonly type: "index";
|
|
readonly index: number;
|
|
};
|
|
};
|
|
|
|
type MessageState = ThreadMessage & {
|
|
readonly parentId: string | null;
|
|
readonly index: number;
|
|
readonly isLast: boolean;
|
|
readonly branchNumber: number;
|
|
readonly branchCount: number;
|
|
readonly speech: SpeechState | undefined;
|
|
};
|
|
|
|
type MessageStatus = {
|
|
readonly type: "running";
|
|
} | {
|
|
readonly type: "requires-action";
|
|
readonly reason: "interrupt" | "tool-calls";
|
|
} | {
|
|
readonly type: "complete";
|
|
readonly reason: "stop" | "unknown";
|
|
} | {
|
|
readonly type: "incomplete";
|
|
readonly reason: "cancelled" | "content-filter" | "error" | "length" | "other" | "tool-calls";
|
|
readonly error?: ReadonlyJSONValue;
|
|
};
|
|
|
|
type MessageTiming = {
|
|
readonly streamStartTime: number;
|
|
readonly firstTokenTime?: number;
|
|
readonly totalStreamTime?: number;
|
|
readonly tokenCount?: number;
|
|
readonly tokensPerSecond?: number;
|
|
readonly totalChunks: number;
|
|
readonly toolCallCount: number;
|
|
};
|
|
|
|
type MessageWithParts = {
|
|
info: Message$1;
|
|
parts: Part[];
|
|
};
|
|
|
|
type ModelContext = {
|
|
priority?: number | undefined;
|
|
system?: string | undefined;
|
|
tools?: Record<string, Tool<any, any>> | undefined;
|
|
callSettings?: LanguageModelV1CallSettings | undefined;
|
|
config?: LanguageModelConfig | undefined;
|
|
unstable_composerMetadata?: Record<string, unknown> | undefined;
|
|
};
|
|
|
|
type ModelContextProvider = {
|
|
getModelContext: () => ModelContext;
|
|
subscribe?: (callback: () => void) => Unsubscribe;
|
|
};
|
|
|
|
type ObjectKey<T> = keyof T & (string | number);
|
|
|
|
type OnSchemaValidationErrorFunction<TResult> = ToolExecuteFunction<unknown, TResult>;
|
|
|
|
declare class OpenCodeEventSource {
|
|
private readonly client;
|
|
private readonly listeners;
|
|
private readonly reconnectDelayMs;
|
|
private readonly maxReconnectDelayMs;
|
|
private abortController;
|
|
private connectionPromise;
|
|
private stopped;
|
|
private nextReconnectDelayMs;
|
|
private hadConnection;
|
|
constructor(client: OpencodeClient);
|
|
subscribe(listener: Listener): () => void;
|
|
dispose(): void;
|
|
private emit;
|
|
private connect;
|
|
private disconnect;
|
|
private run;
|
|
}
|
|
|
|
type OpenCodeEventSourceProvider = () => Pick<OpenCodeEventSource, "subscribe">;
|
|
|
|
type OpenCodeLoadState = {
|
|
type: "idle";
|
|
} | {
|
|
type: "loading";
|
|
} | {
|
|
type: "ready";
|
|
} | {
|
|
type: "error";
|
|
error: unknown;
|
|
};
|
|
|
|
type OpenCodePartPayload = {
|
|
readonly name: string;
|
|
readonly data: Record<string, unknown>;
|
|
};
|
|
|
|
type OpenCodePermissionRequest = {
|
|
id: string;
|
|
sessionId: string;
|
|
permission: string;
|
|
patterns: readonly string[];
|
|
metadata: Record<string, unknown>;
|
|
always: readonly string[];
|
|
tool?: PermissionRequest["tool"] | undefined;
|
|
toolName?: string | undefined;
|
|
toolInput?: unknown;
|
|
title?: string | undefined;
|
|
askedAt: number;
|
|
raw: PermissionRequest;
|
|
};
|
|
|
|
type OpenCodePermissionResponse = "always" | "once" | "reject";
|
|
|
|
type OpenCodeProjectedThreadMessage = ThreadMessageLike;
|
|
|
|
type OpenCodeQuestionRequest = QuestionRequest & {
|
|
askedAt: number;
|
|
};
|
|
|
|
type OpenCodeRunState = {
|
|
type: "idle";
|
|
} | {
|
|
type: "streaming";
|
|
} | {
|
|
type: "cancelling";
|
|
} | {
|
|
type: "reverting";
|
|
} | {
|
|
type: "error";
|
|
error: unknown;
|
|
};
|
|
|
|
type OpenCodeRuntime = AssistantRuntime;
|
|
|
|
type OpenCodeRuntimeExtras = {
|
|
session: Session | null;
|
|
state: OpenCodeThreadState;
|
|
permissions: OpenCodeThreadState["interactions"]["permissions"]["pending"];
|
|
questions: OpenCodeThreadState["interactions"]["questions"]["pending"];
|
|
fork: (messageId: string) => Promise<string>;
|
|
revert: (messageId: string) => Promise<void>;
|
|
unrevert: () => Promise<void>;
|
|
cancel: () => Promise<void>;
|
|
refresh: () => Promise<void>;
|
|
replyToPermission: (permissionId: string, response: OpenCodePermissionResponse) => Promise<void>;
|
|
replyToQuestion: (questionId: string, answers: readonly QuestionAnswer[]) => Promise<void>;
|
|
rejectQuestion: (questionId: string) => Promise<void>;
|
|
};
|
|
|
|
type OpenCodeRuntimeOptions = ExternalStoreSharedOptions & {
|
|
onThreadIdChange?: ((threadId: string | undefined) => void) | undefined;
|
|
client?: OpencodeClient;
|
|
baseUrl?: string | undefined;
|
|
initialSessionId?: string | undefined;
|
|
defaultModel?: {
|
|
providerID: string;
|
|
modelID: string;
|
|
} | undefined;
|
|
defaultAgent?: string | undefined;
|
|
onError?: (error: unknown) => void;
|
|
adapters?: {
|
|
attachments?: AttachmentAdapter;
|
|
speech?: SpeechSynthesisAdapter;
|
|
dictation?: DictationAdapter;
|
|
voice?: RealtimeVoiceAdapter;
|
|
feedback?: FeedbackAdapter;
|
|
} | undefined;
|
|
};
|
|
|
|
type OpenCodeServerEvent = {
|
|
type: string;
|
|
sessionId: string | undefined;
|
|
raw: unknown;
|
|
properties: Record<string, unknown>;
|
|
};
|
|
|
|
type OpenCodeServerMessage = {
|
|
id: string;
|
|
info: Message$1 | undefined;
|
|
parts: readonly Part[];
|
|
shadowParts: readonly ThreadUserMessagePart[] | undefined;
|
|
};
|
|
|
|
type OpenCodeStateEvent = {
|
|
type: "history.loading";
|
|
} | {
|
|
type: "history.loaded";
|
|
session: Session | null;
|
|
messages: readonly MessageWithParts[];
|
|
} | {
|
|
type: "history.failed";
|
|
error: unknown;
|
|
} | {
|
|
type: "session.updated";
|
|
session: Session;
|
|
} | {
|
|
type: "session.status";
|
|
status: SessionStatus;
|
|
} | {
|
|
type: "session.idle";
|
|
sessionId: string;
|
|
} | {
|
|
type: "session.compacted";
|
|
sessionId: string;
|
|
} | {
|
|
type: "run.started";
|
|
} | {
|
|
type: "run.cancelling";
|
|
} | {
|
|
type: "run.reverting";
|
|
} | {
|
|
type: "run.failed";
|
|
error: unknown;
|
|
} | {
|
|
type: "message.updated";
|
|
info: Message$1;
|
|
} | {
|
|
type: "message.removed";
|
|
messageId: string;
|
|
} | {
|
|
type: "part.updated";
|
|
messageId: string;
|
|
part: Part;
|
|
} | {
|
|
type: "part.delta";
|
|
messageId: string;
|
|
partId: string;
|
|
field: string;
|
|
delta: string;
|
|
} | {
|
|
type: "part.removed";
|
|
messageId: string;
|
|
partId: string;
|
|
} | {
|
|
type: "permission.asked";
|
|
request: OpenCodePermissionRequest;
|
|
} | {
|
|
type: "permission.replied";
|
|
permissionId: string;
|
|
reply: OpenCodePermissionResponse;
|
|
} | {
|
|
type: "question.asked";
|
|
request: OpenCodeQuestionRequest;
|
|
} | {
|
|
type: "question.replied";
|
|
questionId: string;
|
|
answers: readonly QuestionAnswer[];
|
|
} | {
|
|
type: "question.rejected";
|
|
questionId: string;
|
|
} | {
|
|
type: "unhandled.event";
|
|
event: OpenCodeUnhandledEvent;
|
|
} | {
|
|
type: "local.message.queued";
|
|
pending: PendingUserMessage;
|
|
} | {
|
|
type: "local.message.reconciled";
|
|
clientId: string;
|
|
messageId: string;
|
|
} | {
|
|
type: "local.message.failed";
|
|
clientId: string;
|
|
error: unknown;
|
|
};
|
|
|
|
declare class OpenCodeThreadController implements OpenCodeThreadControllerLike {
|
|
private readonly client;
|
|
private readonly sessionId;
|
|
private state;
|
|
private readonly listeners;
|
|
private readonly getEventSource;
|
|
private unsubscribeFromEvents;
|
|
private loadPromise;
|
|
private reconnectSyncToken;
|
|
private readonly stagedMessages;
|
|
constructor(client: OpencodeClient, getEventSource: OpenCodeEventSourceProvider, sessionId: string);
|
|
private ensureEventSubscription;
|
|
private handleStreamReconnect;
|
|
dispose(): void;
|
|
getState: () => OpenCodeThreadState;
|
|
subscribe: (listener: () => void) => () => void;
|
|
load(force?: boolean): Promise<void>;
|
|
refresh(): Promise<void>;
|
|
private createPendingMessage;
|
|
private promptMessage;
|
|
sendMessage(message: AppendMessage, options?: OpenCodeUserMessageOptions): Promise<void>;
|
|
stageMessage(message: AppendMessage, options?: OpenCodeUserMessageOptions): Promise<void>;
|
|
sendStagedMessage(parentId: string, options?: OpenCodeUserMessageOptions): Promise<boolean>;
|
|
cancel(): Promise<void>;
|
|
revert(messageId: string): Promise<void>;
|
|
unrevert(): Promise<void>;
|
|
fork(messageId: string): Promise<string>;
|
|
replyToPermission(permissionId: string, response: OpenCodePermissionResponse): Promise<void>;
|
|
replyToQuestion(questionId: string, answers: readonly QuestionAnswer$1[]): Promise<void>;
|
|
rejectQuestion(questionId: string): Promise<void>;
|
|
private refreshInBackground;
|
|
private handleServerEvent;
|
|
private dispatch;
|
|
}
|
|
|
|
type OpenCodeThreadControllerLike = {
|
|
getState(): OpenCodeThreadControllerSnapshot;
|
|
subscribe(listener: () => void): () => void;
|
|
load(force?: boolean): Promise<void>;
|
|
refresh(): Promise<void>;
|
|
sendMessage(message: AppendMessage, options?: OpenCodeUserMessageOptions): Promise<void>;
|
|
stageMessage(message: AppendMessage, options?: OpenCodeUserMessageOptions): Promise<void>;
|
|
sendStagedMessage(parentId: string, options?: OpenCodeUserMessageOptions): Promise<boolean>;
|
|
cancel(): Promise<void>;
|
|
revert(messageId: string): Promise<void>;
|
|
unrevert(): Promise<void>;
|
|
fork(messageId: string): Promise<string>;
|
|
replyToPermission(permissionId: string, response: OpenCodePermissionResponse): Promise<void>;
|
|
replyToQuestion(questionId: string, answers: readonly QuestionAnswer[]): Promise<void>;
|
|
rejectQuestion(questionId: string): Promise<void>;
|
|
};
|
|
|
|
type OpenCodeThreadControllerSnapshot = OpenCodeThreadState;
|
|
|
|
type OpenCodeThreadState = {
|
|
sessionId: string;
|
|
session: Session | null;
|
|
sessionStatus: SessionStatus | null;
|
|
loadState: OpenCodeLoadState;
|
|
runState: OpenCodeRunState;
|
|
messageOrder: readonly string[];
|
|
messagesById: Readonly<Record<string, OpenCodeServerMessage>>;
|
|
pendingUserMessages: Readonly<Record<string, PendingUserMessage>>;
|
|
interactions: {
|
|
permissions: {
|
|
pending: Readonly<Record<string, OpenCodePermissionRequest>>;
|
|
resolved: Readonly<Record<string, {
|
|
request: OpenCodePermissionRequest;
|
|
reply: OpenCodePermissionResponse;
|
|
respondedAt: number;
|
|
}>>;
|
|
};
|
|
questions: {
|
|
pending: Readonly<Record<string, OpenCodeQuestionRequest>>;
|
|
answered: Readonly<Record<string, {
|
|
request: OpenCodeQuestionRequest;
|
|
answers: readonly QuestionAnswer[];
|
|
respondedAt: number;
|
|
}>>;
|
|
rejected: Readonly<Record<string, {
|
|
request: OpenCodeQuestionRequest;
|
|
rejectedAt: number;
|
|
}>>;
|
|
};
|
|
};
|
|
unhandledEvents: readonly OpenCodeUnhandledEvent[];
|
|
sync: {
|
|
lastHistoryLoadAt?: number;
|
|
lastEventAt?: number;
|
|
lastCompactionAt?: number;
|
|
};
|
|
};
|
|
|
|
type OpenCodeThreadStateSelector<T> = (state: OpenCodeThreadState) => T;
|
|
|
|
type OpenCodeUnhandledEvent = {
|
|
type: string;
|
|
sessionId: string | undefined;
|
|
properties: Record<string, unknown>;
|
|
seenAt: number;
|
|
};
|
|
|
|
type OpenCodeUserMessageOptions = {
|
|
model?: {
|
|
providerID: string;
|
|
modelID: string;
|
|
} | undefined;
|
|
agent?: string | undefined;
|
|
noReply?: boolean | undefined;
|
|
};
|
|
|
|
type ParentOf<K extends ClientNames> = AssistantClientAccessor<K> extends {
|
|
source: infer S;
|
|
} ? S extends ClientNames ? S : never : never;
|
|
|
|
type PartProviderMetadata = {
|
|
readonly [providerName: string]: ReadonlyJSONObject;
|
|
};
|
|
|
|
type PendingAttachment = BaseAttachment & {
|
|
status: PendingAttachmentStatus;
|
|
file: File;
|
|
};
|
|
|
|
type PendingAttachmentStatus = {
|
|
type: "running";
|
|
reason: "uploading";
|
|
progress: number;
|
|
} | {
|
|
type: "requires-action";
|
|
reason: "composer-send";
|
|
} | {
|
|
type: "incomplete";
|
|
reason: "error" | "upload-paused";
|
|
message?: string;
|
|
};
|
|
|
|
type PendingUserMessage = {
|
|
clientId: string;
|
|
sessionId: string;
|
|
createdAt: number;
|
|
parentId: string | null;
|
|
sourceId: string | null;
|
|
runConfig: unknown;
|
|
contentText: string;
|
|
parts: readonly ThreadUserMessagePart[];
|
|
status: "failed" | "pending";
|
|
error?: unknown;
|
|
};
|
|
|
|
type ProviderOptions = Record<string, Record<string, unknown>>;
|
|
|
|
type ProviderTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = ToolBase<TArgs, TResult> & {
|
|
type: "provider";
|
|
providerId: `${string}.${string}`;
|
|
parameters?: StandardSchemaV1<TArgs> | JSONSchema7 | undefined;
|
|
args: Record<string, unknown>;
|
|
supportsDeferredResults?: boolean;
|
|
description?: undefined;
|
|
disabled?: boolean;
|
|
execute?: undefined;
|
|
toModelOutput?: undefined;
|
|
experimental_onSchemaValidationError?: undefined;
|
|
providerOptions?: ProviderOptions;
|
|
};
|
|
|
|
type QueueItemState = {
|
|
readonly id: string;
|
|
readonly prompt: string;
|
|
};
|
|
|
|
type QuoteInfo = {
|
|
readonly text: string;
|
|
readonly messageId: string;
|
|
};
|
|
|
|
type ReadonlyJSONArray = readonly ReadonlyJSONValue[];
|
|
|
|
type ReadonlyJSONObject = {
|
|
readonly [key: string]: ReadonlyJSONValue;
|
|
};
|
|
|
|
type ReadonlyJSONValue = null | string | number | boolean | ReadonlyJSONObject | ReadonlyJSONArray;
|
|
|
|
declare namespace RealtimeVoiceAdapter {
|
|
type Status = {
|
|
type: "running" | "starting";
|
|
} | {
|
|
type: "ended";
|
|
reason: "cancelled" | "error" | "finished";
|
|
error?: unknown;
|
|
};
|
|
type Mode = "listening" | "speaking";
|
|
type TranscriptItem = {
|
|
role: "assistant" | "user";
|
|
text: string;
|
|
isFinal?: boolean;
|
|
};
|
|
type Session = {
|
|
status: Status;
|
|
isMuted: boolean;
|
|
disconnect: () => void;
|
|
mute: () => void;
|
|
unmute: () => void;
|
|
onStatusChange: (callback: (status: Status) => void) => Unsubscribe;
|
|
onTranscript: (callback: (transcript: TranscriptItem) => void) => Unsubscribe;
|
|
onModeChange: (callback: (mode: Mode) => void) => Unsubscribe;
|
|
onVolumeChange: (callback: (volume: number) => void) => Unsubscribe;
|
|
};
|
|
}
|
|
|
|
type RealtimeVoiceAdapter = {
|
|
connect: (options: {
|
|
abortSignal?: AbortSignal;
|
|
}) => RealtimeVoiceAdapter.Session;
|
|
};
|
|
|
|
type ReasoningMessagePart = {
|
|
readonly type: "reasoning";
|
|
readonly text: string;
|
|
readonly providerMetadata?: PartProviderMetadata;
|
|
readonly parentId?: string;
|
|
};
|
|
|
|
type ReloadConfig = {
|
|
runConfig?: RunConfig;
|
|
};
|
|
|
|
type RespondToToolApprovalOptions = {
|
|
approvalId: string;
|
|
approved: boolean;
|
|
optionId?: string;
|
|
reason?: string;
|
|
};
|
|
|
|
type ResumeRunConfig = StartRunConfig & {
|
|
stream?: (options: ChatModelRunOptions) => AsyncGenerator<ChatModelRunResult, void, unknown>;
|
|
};
|
|
|
|
type RunConfig = {
|
|
readonly custom?: Record<string, unknown>;
|
|
};
|
|
|
|
type RuntimeCapabilities = {
|
|
readonly switchToBranch: boolean;
|
|
readonly switchBranchDuringRun: boolean;
|
|
readonly edit: boolean;
|
|
readonly reload: boolean;
|
|
readonly delete: boolean;
|
|
readonly cancel: boolean;
|
|
readonly unstable_copy: boolean;
|
|
readonly speech: boolean;
|
|
readonly dictation: boolean;
|
|
readonly voice: boolean;
|
|
readonly attachments: boolean;
|
|
readonly feedback: boolean;
|
|
readonly queue: boolean;
|
|
};
|
|
|
|
declare const STREAM_RECONNECTED_EVENT_TYPE = "stream.reconnected";
|
|
|
|
interface ScopeRegistry {
|
|
[key: string]: { methods: any; meta?: any; events?: any };
|
|
}
|
|
|
|
type SendOptions = {
|
|
startRun?: boolean;
|
|
steer?: boolean;
|
|
};
|
|
|
|
type SourceMessagePart = {
|
|
readonly type: "source";
|
|
readonly sourceType: "url";
|
|
readonly id: string;
|
|
readonly url: string;
|
|
readonly title?: string;
|
|
readonly providerMetadata?: SourceProviderMetadata;
|
|
readonly parentId?: string;
|
|
} | {
|
|
readonly type: "source";
|
|
readonly sourceType: "document";
|
|
readonly id: string;
|
|
readonly url?: undefined;
|
|
readonly title: string;
|
|
readonly mediaType: string;
|
|
readonly filename?: string;
|
|
readonly providerMetadata?: SourceProviderMetadata;
|
|
readonly parentId?: string;
|
|
};
|
|
|
|
type SourceProviderMetadata = PartProviderMetadata;
|
|
|
|
interface SpeechRecognitionConstructor {
|
|
new (): SpeechRecognitionInstance;
|
|
}
|
|
|
|
interface SpeechRecognitionInstance extends EventTarget {
|
|
lang: string;
|
|
continuous: boolean;
|
|
interimResults: boolean;
|
|
start(): void;
|
|
stop(): void;
|
|
abort(): void;
|
|
}
|
|
|
|
type SpeechState = {
|
|
readonly messageId: string;
|
|
readonly status: SpeechSynthesisAdapter.Status;
|
|
};
|
|
|
|
declare namespace SpeechSynthesisAdapter {
|
|
type Status = {
|
|
type: "running" | "starting";
|
|
} | {
|
|
type: "ended";
|
|
reason: "cancelled" | "error" | "finished";
|
|
error?: unknown;
|
|
};
|
|
type Utterance = {
|
|
status: Status;
|
|
cancel: () => void;
|
|
subscribe: (callback: () => void) => Unsubscribe;
|
|
};
|
|
}
|
|
|
|
type SpeechSynthesisAdapter = {
|
|
speak: (text: string) => SpeechSynthesisAdapter.Utterance;
|
|
};
|
|
|
|
type StartRunConfig = {
|
|
parentId: string | null;
|
|
sourceId: string | null;
|
|
runConfig: RunConfig;
|
|
};
|
|
|
|
declare const TOOL_RESPONSE_SYMBOL: unique symbol;
|
|
|
|
type TextMessagePart = {
|
|
readonly type: "text";
|
|
readonly text: string;
|
|
readonly providerMetadata?: PartProviderMetadata;
|
|
readonly parentId?: string;
|
|
};
|
|
|
|
type ThreadAssistantMessage = MessageCommonProps & {
|
|
readonly role: "assistant";
|
|
readonly content: readonly ThreadAssistantMessagePart[];
|
|
readonly status: MessageStatus;
|
|
readonly metadata: {
|
|
readonly unstable_state: ReadonlyJSONValue;
|
|
readonly unstable_annotations: readonly ReadonlyJSONValue[];
|
|
readonly unstable_data: readonly ReadonlyJSONValue[];
|
|
readonly steps: readonly ThreadStep[];
|
|
readonly submittedFeedback?: {
|
|
readonly type: "negative" | "positive";
|
|
};
|
|
readonly timing?: MessageTiming;
|
|
readonly isOptimistic?: boolean;
|
|
readonly custom: Record<string, unknown>;
|
|
};
|
|
};
|
|
|
|
type ThreadAssistantMessagePart = TextMessagePart | ReasoningMessagePart | ToolCallMessagePart | SourceMessagePart | FileMessagePart | ImageMessagePart | DataMessagePart | GenerativeUIMessagePart;
|
|
|
|
type ThreadComposerAttachmentState = Attachment & {
|
|
readonly source: "thread-composer";
|
|
};
|
|
|
|
type ThreadComposerRuntime = Omit<ComposerRuntime, "getAttachmentByIndex" | "getState"> & {
|
|
readonly path: ComposerRuntimePath & {
|
|
composerSource: "thread";
|
|
};
|
|
readonly type: "thread";
|
|
getState(): ThreadComposerState;
|
|
getAttachmentByIndex(idx: number): AttachmentRuntime & {
|
|
source: "thread-composer";
|
|
};
|
|
};
|
|
|
|
type ThreadComposerState = BaseComposerState & {
|
|
readonly type: "thread";
|
|
};
|
|
|
|
type ThreadListItemEventCallback<E extends ThreadListItemEventType> = (payload: ThreadListItemEventPayload[E]) => void;
|
|
|
|
type ThreadListItemEventPayload = {
|
|
switchedTo: Record<string, never>;
|
|
switchedAway: Record<string, never>;
|
|
};
|
|
|
|
type ThreadListItemEventType = keyof ThreadListItemEventPayload;
|
|
|
|
type ThreadListItemRuntime = {
|
|
readonly path: ThreadListItemRuntimePath;
|
|
getState(): ThreadListItemState;
|
|
initialize(): Promise<{
|
|
remoteId: string;
|
|
externalId: string | undefined;
|
|
}>;
|
|
generateTitle(): Promise<void>;
|
|
switchTo(options?: {
|
|
unarchive?: boolean;
|
|
}): Promise<void>;
|
|
rename(newTitle: string): Promise<void>;
|
|
updateCustom(custom: Record<string, unknown> | undefined): Promise<void>;
|
|
archive(): Promise<void>;
|
|
unarchive(): Promise<void>;
|
|
delete(): Promise<void>;
|
|
detach(): void;
|
|
subscribe(callback: () => void): Unsubscribe;
|
|
unstable_on<E extends ThreadListItemEventType>(event: E, callback: ThreadListItemEventCallback<E>): Unsubscribe;
|
|
__internal_getRuntime(): ThreadListItemRuntime;
|
|
};
|
|
|
|
type ThreadListItemRuntimePath = {
|
|
readonly ref: string;
|
|
readonly threadSelector: {
|
|
readonly type: "main";
|
|
} | {
|
|
readonly type: "index";
|
|
readonly index: number;
|
|
} | {
|
|
readonly type: "archiveIndex";
|
|
readonly index: number;
|
|
} | {
|
|
readonly type: "threadId";
|
|
readonly threadId: string;
|
|
};
|
|
};
|
|
|
|
type ThreadListItemState = {
|
|
readonly isMain: boolean;
|
|
readonly id: string;
|
|
readonly remoteId: string | undefined;
|
|
readonly externalId: string | undefined;
|
|
readonly status: ThreadListItemStatus;
|
|
readonly title?: string | undefined;
|
|
readonly lastMessageAt?: Date | undefined;
|
|
readonly custom?: Record<string, unknown> | undefined;
|
|
};
|
|
|
|
type ThreadListItemStatus = "archived" | "deleted" | "new" | "regular";
|
|
|
|
type ThreadListRuntime = {
|
|
getState(): ThreadListState;
|
|
subscribe(callback: () => void): Unsubscribe;
|
|
readonly main: ThreadRuntime;
|
|
getById(threadId: string): ThreadRuntime;
|
|
readonly mainItem: ThreadListItemRuntime;
|
|
getItemById(threadId: string): ThreadListItemRuntime;
|
|
getItemByIndex(idx: number): ThreadListItemRuntime;
|
|
getArchivedItemByIndex(idx: number): ThreadListItemRuntime;
|
|
switchToThread(threadId: string, options?: {
|
|
unarchive?: boolean;
|
|
}): Promise<void>;
|
|
switchToNewThread(): Promise<void>;
|
|
getLoadThreadsPromise(): Promise<void>;
|
|
reload(): Promise<void>;
|
|
loadMore(): Promise<void>;
|
|
};
|
|
|
|
type ThreadListState = {
|
|
readonly mainThreadId: string;
|
|
readonly newThreadId: string | undefined;
|
|
readonly threadIds: readonly string[];
|
|
readonly archivedThreadIds: readonly string[];
|
|
readonly isLoading: boolean;
|
|
readonly isLoadingMore: boolean;
|
|
readonly hasMore: boolean;
|
|
readonly threadItems: Readonly<Record<string, Omit<ThreadListItemState, "isMain" | "threadId">>>;
|
|
};
|
|
|
|
type ThreadMessage = BaseThreadMessage & (ThreadSystemMessage | ThreadUserMessage | ThreadAssistantMessage);
|
|
|
|
type ThreadMessageLike = {
|
|
readonly role: "assistant" | "system" | "user";
|
|
readonly content: string | readonly (TextMessagePart | ReasoningMessagePart | SourceMessagePart | ImageMessagePart | FileMessagePart | DataMessagePart | GenerativeUIMessagePart | Unstable_AudioMessagePart | DataPrefixedPart | {
|
|
readonly type: "tool-call";
|
|
readonly toolCallId?: string;
|
|
readonly toolName: string;
|
|
readonly args?: ReadonlyJSONObject;
|
|
readonly argsText?: string;
|
|
readonly artifact?: any;
|
|
readonly result?: any | undefined;
|
|
readonly isError?: boolean | undefined;
|
|
readonly parentId?: string | undefined;
|
|
readonly messages?: readonly ThreadMessage[] | undefined;
|
|
readonly interrupt?: {
|
|
type: "human";
|
|
payload: unknown;
|
|
};
|
|
readonly timing?: ToolCallTiming;
|
|
readonly providerMetadata?: PartProviderMetadata;
|
|
readonly approval?: {
|
|
readonly id: string;
|
|
readonly approved?: boolean;
|
|
readonly reason?: string;
|
|
readonly isAutomatic?: boolean;
|
|
readonly options?: readonly ToolApprovalOption[];
|
|
readonly optionId?: string;
|
|
readonly resolution?: "cancelled" | "expired";
|
|
};
|
|
})[];
|
|
readonly id?: string | undefined;
|
|
readonly createdAt?: Date | undefined;
|
|
readonly status?: MessageStatus | undefined;
|
|
readonly attachments?: readonly (Omit<CompleteAttachment, "content"> & {
|
|
readonly content: readonly (ThreadUserMessagePart | DataPrefixedPart)[];
|
|
})[] | undefined;
|
|
readonly metadata?: {
|
|
readonly unstable_state?: ReadonlyJSONValue;
|
|
readonly unstable_annotations?: readonly ReadonlyJSONValue[] | undefined;
|
|
readonly unstable_data?: readonly ReadonlyJSONValue[] | undefined;
|
|
readonly steps?: readonly ThreadStep[] | undefined;
|
|
readonly timing?: MessageTiming | undefined;
|
|
readonly submittedFeedback?: {
|
|
readonly type: "negative" | "positive";
|
|
};
|
|
readonly isOptimistic?: boolean | undefined;
|
|
readonly custom?: Record<string, unknown> | undefined;
|
|
} | undefined;
|
|
};
|
|
|
|
type ThreadRuntime = {
|
|
readonly path: ThreadRuntimePath;
|
|
readonly composer: ThreadComposerRuntime;
|
|
getState(): ThreadState;
|
|
append(message: CreateAppendMessage): void;
|
|
deleteMessage(messageId: string): void | Promise<void>;
|
|
startRun(config: CreateStartRunConfig): void;
|
|
resumeRun(config: CreateResumeRunConfig): void;
|
|
exportExternalState(): any;
|
|
importExternalState(state: any): void;
|
|
subscribe(callback: () => void): Unsubscribe;
|
|
cancelRun(): void;
|
|
getModelContext(): ModelContext;
|
|
export(): ExportedMessageRepository;
|
|
import(repository: ExportedMessageRepository): void;
|
|
reset(initialMessages?: readonly ThreadMessageLike[]): void;
|
|
getMessageByIndex(idx: number): MessageRuntime;
|
|
getMessageById(messageId: string): MessageRuntime;
|
|
stopSpeaking(): void;
|
|
connectVoice(): void;
|
|
disconnectVoice(): void;
|
|
getVoiceVolume(): number;
|
|
subscribeVoiceVolume(callback: () => void): Unsubscribe;
|
|
muteVoice(): void;
|
|
unmuteVoice(): void;
|
|
unstable_on<E extends ThreadRuntimeEventType>(event: E, callback: ThreadRuntimeEventCallback<E>): Unsubscribe;
|
|
};
|
|
|
|
type ThreadRuntimeEventCallback<E extends ThreadRuntimeEventType> = (payload: ThreadRuntimeEventPayload[E]) => void;
|
|
|
|
type ThreadRuntimeEventPayload = {
|
|
runStart: Record<string, never>;
|
|
runEnd: Record<string, never>;
|
|
initialize: Record<string, never>;
|
|
modelContextUpdate: Record<string, never>;
|
|
};
|
|
|
|
type ThreadRuntimeEventType = keyof ThreadRuntimeEventPayload;
|
|
|
|
type ThreadRuntimePath = {
|
|
readonly ref: string;
|
|
readonly threadSelector: {
|
|
readonly type: "main";
|
|
} | {
|
|
readonly type: "threadId";
|
|
readonly threadId: string;
|
|
};
|
|
};
|
|
|
|
type ThreadState = {
|
|
readonly threadId: string;
|
|
readonly metadata: ThreadListItemState;
|
|
readonly isDisabled: boolean;
|
|
readonly isLoading: boolean;
|
|
readonly isRunning: boolean;
|
|
readonly capabilities: RuntimeCapabilities;
|
|
readonly messages: readonly ThreadMessage[];
|
|
readonly state: ReadonlyJSONValue;
|
|
readonly suggestions: readonly ThreadSuggestion[];
|
|
readonly extras: unknown;
|
|
readonly speech: SpeechState | undefined;
|
|
readonly voice: VoiceSessionState | undefined;
|
|
};
|
|
|
|
type ThreadStep = {
|
|
readonly messageId?: string;
|
|
readonly usage?: {
|
|
readonly inputTokens: number;
|
|
readonly outputTokens: number;
|
|
} | undefined;
|
|
};
|
|
|
|
type ThreadSuggestion = {
|
|
prompt: string;
|
|
};
|
|
|
|
type ThreadSystemMessage = MessageCommonProps & {
|
|
readonly role: "system";
|
|
readonly content: readonly [
|
|
TextMessagePart
|
|
];
|
|
readonly metadata: {
|
|
readonly unstable_state?: undefined;
|
|
readonly unstable_annotations?: undefined;
|
|
readonly unstable_data?: undefined;
|
|
readonly steps?: undefined;
|
|
readonly submittedFeedback?: undefined;
|
|
readonly timing?: undefined;
|
|
readonly custom: Record<string, unknown>;
|
|
};
|
|
};
|
|
|
|
type ThreadUserMessage = MessageCommonProps & {
|
|
readonly role: "user";
|
|
readonly content: readonly ThreadUserMessagePart[];
|
|
readonly attachments: readonly CompleteAttachment[];
|
|
readonly metadata: {
|
|
readonly unstable_state?: undefined;
|
|
readonly unstable_annotations?: undefined;
|
|
readonly unstable_data?: undefined;
|
|
readonly steps?: undefined;
|
|
readonly submittedFeedback?: undefined;
|
|
readonly timing?: undefined;
|
|
readonly custom: Record<string, unknown>;
|
|
};
|
|
};
|
|
|
|
type ThreadUserMessagePart = TextMessagePart | ImageMessagePart | FileMessagePart | DataMessagePart | Unstable_AudioMessagePart;
|
|
|
|
type Tool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = FrontendTool<TArgs, TResult> | BackendTool<TArgs, TResult> | HumanTool<TArgs, TResult> | ProviderTool<TArgs, TResult> | McpTool | ToolWithoutType<TArgs, TResult>;
|
|
|
|
type ToolApprovalOption = {
|
|
readonly id: string;
|
|
readonly kind: ToolApprovalOptionKind | (string & {});
|
|
readonly label?: string;
|
|
readonly description?: string;
|
|
readonly grants?: readonly string[];
|
|
readonly confirm?: boolean | {
|
|
title?: string;
|
|
description?: string;
|
|
};
|
|
};
|
|
|
|
type ToolApprovalOptionKind = "allow-always" | "allow-once" | "reject-always" | "reject-once";
|
|
|
|
type ToolApprovalResponse = {
|
|
readonly approved: boolean;
|
|
readonly reason?: string;
|
|
} | {
|
|
readonly optionId: string;
|
|
readonly reason?: string;
|
|
} | {
|
|
readonly approved: boolean;
|
|
readonly optionId: string;
|
|
readonly reason?: string;
|
|
};
|
|
|
|
type ToolBase<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = {
|
|
streamCall?: ToolStreamCallFunction<TArgs, TResult>;
|
|
display?: ToolDisplay;
|
|
};
|
|
|
|
interface ToolCallArgsReader<TArgs extends Record<string, unknown>> {
|
|
get<PathT extends TypePath<TArgs>>(...fieldPath: PathT): Promise<TypeAtPath<TArgs, PathT>>;
|
|
streamValues<PathT extends TypePath<TArgs>>(...fieldPath: PathT): AsyncIterableStream<DeepPartial<TypeAtPath<TArgs, PathT>>>;
|
|
streamText<PathT extends TypePath<TArgs>>(...fieldPath: PathT): TypeAtPath<TArgs, PathT> extends string & (infer U) ? AsyncIterableStream<U> : never;
|
|
forEach<PathT extends TypePath<TArgs>>(...fieldPath: PathT): NonNullable<TypeAtPath<TArgs, PathT>> extends Array<infer U> ? AsyncIterableStream<U> : never;
|
|
}
|
|
|
|
type ToolCallMessagePart<TArgs = ReadonlyJSONObject, TResult = unknown> = {
|
|
readonly type: "tool-call";
|
|
readonly toolCallId: string;
|
|
readonly toolName: string;
|
|
readonly args: TArgs;
|
|
readonly result?: TResult | undefined;
|
|
readonly isError?: boolean | undefined;
|
|
readonly argsText: string;
|
|
readonly artifact?: unknown;
|
|
readonly timing?: ToolCallTiming;
|
|
readonly mcp?: ToolCallMessagePartMcpMetadata;
|
|
readonly providerMetadata?: PartProviderMetadata;
|
|
readonly modelContent?: readonly ToolModelContentPart[] | undefined;
|
|
readonly interrupt?: {
|
|
type: "human";
|
|
payload: unknown;
|
|
};
|
|
readonly approval?: {
|
|
readonly id: string;
|
|
readonly approved?: boolean;
|
|
readonly reason?: string;
|
|
readonly isAutomatic?: boolean;
|
|
readonly options?: readonly ToolApprovalOption[];
|
|
readonly optionId?: string;
|
|
readonly resolution?: "cancelled" | "expired";
|
|
};
|
|
readonly parentId?: string;
|
|
readonly messages?: readonly ThreadMessage[];
|
|
};
|
|
|
|
type ToolCallMessagePartMcpMetadata = {
|
|
readonly app?: McpAppMetadata;
|
|
};
|
|
|
|
type ToolCallMessagePartStatus = {
|
|
readonly type: "requires-action";
|
|
readonly reason: "interrupt";
|
|
} | MessagePartStatus;
|
|
|
|
interface ToolCallReader<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> {
|
|
args: ToolCallArgsReader<TArgs>;
|
|
response: ToolCallResponseReader<TResult>;
|
|
result: {
|
|
get: () => Promise<TResult>;
|
|
};
|
|
}
|
|
|
|
interface ToolCallResponseReader<TResult> {
|
|
get: () => Promise<ToolResponse<TResult>>;
|
|
}
|
|
|
|
type ToolCallTiming = {
|
|
readonly startedAt: number;
|
|
readonly completedAt?: number;
|
|
};
|
|
|
|
type ToolDisplay = "inline" | "standalone";
|
|
|
|
type ToolExecuteFunction<TArgs, TResult> = (args: TArgs, context: ToolExecutionContext) => TResult | Promise<TResult>;
|
|
|
|
type ToolExecutionContext = {
|
|
toolCallId: string;
|
|
abortSignal: AbortSignal;
|
|
human: (payload: unknown) => Promise<unknown>;
|
|
};
|
|
|
|
type ToolExecutionStatus = {
|
|
type: "executing";
|
|
} | {
|
|
type: "interrupt";
|
|
payload: {
|
|
type: "human";
|
|
payload: unknown;
|
|
};
|
|
};
|
|
|
|
type ToolModelContentPart = {
|
|
readonly type: "text";
|
|
readonly text: string;
|
|
} | {
|
|
readonly type: "file";
|
|
readonly data: string;
|
|
readonly mediaType: string;
|
|
readonly filename?: string;
|
|
};
|
|
|
|
type ToolModelOutputFunction<TArgs, TResult> = (options: {
|
|
toolCallId: string;
|
|
input: TArgs;
|
|
output: TResult;
|
|
}) => readonly ToolModelContentPart[] | Promise<readonly ToolModelContentPart[]>;
|
|
|
|
declare class ToolResponse<TResult> {
|
|
get [TOOL_RESPONSE_SYMBOL](): boolean;
|
|
readonly artifact?: ReadonlyJSONValue;
|
|
readonly result: TResult;
|
|
readonly isError: boolean;
|
|
readonly modelContent?: readonly ToolModelContentPart[];
|
|
readonly messages?: ReadonlyJSONValue;
|
|
constructor(options: ToolResponseLike<TResult>);
|
|
static [Symbol.hasInstance](obj: unknown): obj is ToolResponse<ReadonlyJSONValue>;
|
|
static toResponse(result: any | ToolResponse<any>): ToolResponse<any>;
|
|
}
|
|
|
|
type ToolResponseLike<TResult> = {
|
|
result: TResult;
|
|
artifact?: ReadonlyJSONValue | undefined;
|
|
isError?: boolean | undefined;
|
|
modelContent?: readonly ToolModelContentPart[] | undefined;
|
|
messages?: ReadonlyJSONValue | undefined;
|
|
};
|
|
|
|
type ToolStreamCallFunction<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = (reader: ToolCallReader<TArgs, TResult>, context: ToolExecutionContext) => void;
|
|
|
|
type ToolWithoutType<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = (Omit<FrontendTool<TArgs, TResult>, "type"> | Omit<BackendTool<TArgs, TResult>, "type"> | Omit<HumanTool<TArgs, TResult>, "type"> | Omit<ProviderTool<TArgs, TResult>, "type">) & {
|
|
type?: undefined;
|
|
};
|
|
|
|
type TupleIndex<T extends readonly any[]> = Exclude<keyof T, keyof any[]>;
|
|
|
|
type TypeAtPath<T, P extends readonly any[]> = P extends [
|
|
infer Head,
|
|
...infer Rest
|
|
] ? Head extends keyof T ? TypeAtPath<T[Head], Rest> : never : T;
|
|
|
|
type TypePath<T> = [
|
|
] | (0 extends 1 & T ? any[] : T extends object ? T extends readonly any[] ? number extends T["length"] ? {
|
|
[K in TupleIndex<T>]: [
|
|
AsNumber<K>,
|
|
...TypePath<T[K]>
|
|
];
|
|
}[TupleIndex<T>] : [
|
|
number,
|
|
...TypePath<T[number]>
|
|
] : {
|
|
[K in ObjectKey<T>]: [
|
|
K,
|
|
...TypePath<T[K]>
|
|
];
|
|
}[ObjectKey<T>] : [
|
|
]);
|
|
|
|
type UnionToIntersection<U> = (U extends unknown ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
|
|
|
|
type Unstable_AudioMessagePart = {
|
|
readonly type: "audio";
|
|
readonly audio: {
|
|
readonly data: string;
|
|
readonly format: "mp3" | "wav";
|
|
};
|
|
};
|
|
|
|
type Unsubscribe = () => void;
|
|
|
|
type Unsubscribe$1 = () => void;
|
|
|
|
type ValidateClient<K extends keyof ScopeRegistry> = ScopeRegistry[K] extends {
|
|
methods: ClientMethods;
|
|
} ? "meta" extends keyof ScopeRegistry[K] ? ScopeRegistry[K]["meta"] extends ClientMetaType ? "events" extends keyof ScopeRegistry[K] ? ScopeRegistry[K]["events"] extends ClientEventsType<K> ? ScopeRegistry[K] : ClientError<`ERROR: ${K & string} has invalid events type`> : ScopeRegistry[K] : ClientError<`ERROR: ${K & string} has invalid meta type`> : "events" extends keyof ScopeRegistry[K] ? ScopeRegistry[K]["events"] extends ClientEventsType<K> ? ScopeRegistry[K] : ClientError<`ERROR: ${K & string} has invalid events type`> : ScopeRegistry[K] : ClientError<`ERROR: ${K & string} has invalid methods type`>;
|
|
|
|
type VoiceSessionState = {
|
|
readonly status: RealtimeVoiceAdapter.Status;
|
|
readonly isMuted: boolean;
|
|
readonly mode: RealtimeVoiceAdapter.Mode;
|
|
};
|
|
|
|
type WildcardPayload = {
|
|
[K in keyof ClientEventMap]: {
|
|
event: K;
|
|
payload: ClientEventMap[K];
|
|
};
|
|
}[Extract<keyof ClientEventMap, string>];
|
|
|
|
declare const createOpenCodeThreadState: (sessionId: string) => OpenCodeThreadState;
|
|
|
|
declare global {
|
|
interface Window {
|
|
SpeechRecognition?: SpeechRecognitionConstructor;
|
|
webkitSpeechRecognition?: SpeechRecognitionConstructor;
|
|
}
|
|
}
|
|
|
|
declare global {
|
|
interface Window {
|
|
__ASSISTANT_UI_DEVTOOLS_HOOK__?: any;
|
|
}
|
|
}
|
|
|
|
declare namespace entry_root_exports {
|
|
export { AssistantMessage, Event, FilePart, GlobalSession, Message$2 as Message, MessageWithParts, Model, OpenCodeEventSource, OpenCodeLoadState, OpenCodePartPayload, OpenCodePermissionRequest, OpenCodePermissionResponse, OpenCodeProjectedThreadMessage, OpenCodeQuestionRequest, OpenCodeRunState, OpenCodeRuntime, OpenCodeRuntimeExtras, OpenCodeRuntimeOptions, OpenCodeServerEvent, OpenCodeServerMessage, OpenCodeStateEvent, OpenCodeThreadController, OpenCodeThreadControllerLike, OpenCodeThreadControllerSnapshot, OpenCodeThreadState, OpenCodeThreadStateSelector, OpenCodeUnhandledEvent, OpenCodeUserMessageOptions, OpencodeClient$1 as OpencodeClient, OpencodeClientConfig, Part$1 as Part, PendingUserMessage, PermissionRequest$1 as PermissionRequest, Provider, QuestionAnswer$1 as QuestionAnswer, QuestionRequest$1 as QuestionRequest, ReasoningPart, STREAM_RECONNECTED_EVENT_TYPE, Session$1 as Session, SessionStatus$1 as SessionStatus, SnapshotPart, StepFinishPart, StepStartPart, TextPart, ToolPart, ToolState, UserMessage, createOpenCodeThreadState, createOpencodeClient$1 as createOpencodeClient, projectOpenCodeThreadMessages, reduceOpenCodeThreadState, useOpenCodePermissions, useOpenCodeQuestions, useOpenCodeRuntime, useOpenCodeRuntimeExtras, useOpenCodeSession, useOpenCodeStreamingTiming, useOpenCodeThreadState };
|
|
}
|
|
|
|
declare const projectOpenCodeThreadMessages: (state: OpenCodeThreadState, messageTiming?: Record<string, MessageTiming>) => OpenCodeProjectedThreadMessage[];
|
|
|
|
declare const reduceOpenCodeThreadState: (state: OpenCodeThreadState, event: OpenCodeStateEvent) => OpenCodeThreadState;
|
|
|
|
declare const useOpenCodePermissions: () => {
|
|
pending: OpenCodePermissionRequest[];
|
|
reply: (permissionId: string, response: OpenCodePermissionResponse) => Promise<void>;
|
|
};
|
|
|
|
declare const useOpenCodeQuestions: () => OpenCodeQuestionRequest[];
|
|
|
|
declare const useOpenCodeRuntime: (options?: OpenCodeRuntimeOptions) => AssistantRuntime;
|
|
|
|
declare const useOpenCodeRuntimeExtras: () => OpenCodeRuntimeExtras;
|
|
|
|
declare const useOpenCodeSession: () => import("@opencode-ai/sdk/v2/types").Session | null;
|
|
|
|
declare const useOpenCodeStreamingTiming: (state: OpenCodeThreadState, isRunning: boolean) => Record<string, MessageTiming>;
|
|
|
|
declare function useOpenCodeThreadState(): OpenCodeThreadState;
|
|
|
|
declare function useOpenCodeThreadState<T>(selector: (state: OpenCodeThreadState) => T): T;
|
|
|
|
export { entry_root_exports as entry_root };
|