@tanstack/ai-client 0.18.4 → 0.18.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/dist/esm/chat-client.d.ts +0 -264
- package/dist/esm/chat-client.js +0 -1097
- package/dist/esm/chat-client.js.map +0 -1
- package/dist/esm/client-persistor.d.ts +0 -86
- package/dist/esm/client-persistor.js +0 -243
- package/dist/esm/client-persistor.js.map +0 -1
- package/dist/esm/connection-adapters.d.ts +0 -203
- package/dist/esm/connection-adapters.js +0 -611
- package/dist/esm/connection-adapters.js.map +0 -1
- package/dist/esm/devtools-noop.d.ts +0 -63
- package/dist/esm/devtools-noop.js +0 -141
- package/dist/esm/devtools-noop.js.map +0 -1
- package/dist/esm/devtools.d.ts +0 -276
- package/dist/esm/devtools.js +0 -1178
- package/dist/esm/devtools.js.map +0 -1
- package/dist/esm/events.d.ts +0 -129
- package/dist/esm/events.js +0 -227
- package/dist/esm/events.js.map +0 -1
- package/dist/esm/generation-client.d.ts +0 -99
- package/dist/esm/generation-client.js +0 -325
- package/dist/esm/generation-client.js.map +0 -1
- package/dist/esm/generation-types.d.ts +0 -242
- package/dist/esm/generation-types.js +0 -14
- package/dist/esm/generation-types.js.map +0 -1
- package/dist/esm/index.d.ts +0 -16
- package/dist/esm/index.js +0 -44
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/realtime-client.d.ts +0 -98
- package/dist/esm/realtime-client.js +0 -403
- package/dist/esm/realtime-client.js.map +0 -1
- package/dist/esm/realtime-types.d.ts +0 -78
- package/dist/esm/response-stream.d.ts +0 -7
- package/dist/esm/response-stream.js +0 -32
- package/dist/esm/response-stream.js.map +0 -1
- package/dist/esm/sse-parser.d.ts +0 -8
- package/dist/esm/sse-parser.js +0 -52
- package/dist/esm/sse-parser.js.map +0 -1
- package/dist/esm/sse-utils.d.ts +0 -1
- package/dist/esm/sse-utils.js +0 -11
- package/dist/esm/sse-utils.js.map +0 -1
- package/dist/esm/tool-types.d.ts +0 -20
- package/dist/esm/types.d.ts +0 -419
- package/dist/esm/types.js +0 -11
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/video-generation-client.d.ts +0 -110
- package/dist/esm/video-generation-client.js +0 -382
- package/dist/esm/video-generation-client.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection-adapters.js","sources":["../../src/connection-adapters.ts"],"sourcesContent":["import { EventType, uiMessagesToWire } from '@tanstack/ai/client'\nimport {\n createResponseStreamTextDecoder,\n getResponseStreamReader,\n} from './response-stream'\nimport { parseSseDataLine } from './sse-utils'\nimport type {\n ModelMessage,\n RunErrorEvent,\n RunFinishedEvent,\n StreamChunk,\n UIMessage,\n} from '@tanstack/ai/client'\nimport type { ChatFetcher } from './types'\n\n/**\n * Associates connect-wrapped chunks with the run they were produced under.\n * Content events (TEXT_MESSAGE_CONTENT, TOOL_CALL_*, …) carry no `runId` of\n * their own, so the connect wrapper stamps the caller's run id here. Lets\n * run-scoped consumers (e.g. clear-during-stream suppression) attribute those\n * otherwise-runless chunks to their originating request.\n */\nconst chunkRunIds = new WeakMap<StreamChunk, string>()\n\n/**\n * Resolve a chunk's run id, preferring the value on the chunk itself\n * (RUN_STARTED / RUN_FINISHED / RUN_ERROR carry one) and falling back to the\n * run the connect wrapper stamped it with.\n */\nexport function getChunkRunId(chunk: StreamChunk): string | undefined {\n return 'runId' in chunk && typeof chunk.runId === 'string'\n ? chunk.runId\n : chunkRunIds.get(chunk)\n}\n\n/**\n * Thrown when an SSE/HTTP stream ends with a non-empty unterminated buffer.\n * Indicates the connection was cut mid-line (server crash, dropped TCP, proxy\n * timeout) so the partial content cannot be safely parsed.\n */\nexport class StreamTruncatedError extends Error {\n constructor() {\n super(\n 'Stream ended with unterminated trailing data — connection was likely cut short.',\n )\n this.name = 'StreamTruncatedError'\n }\n}\n\nfunction generateRunId(prefix: string): string {\n return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`\n}\n\n/**\n * Asserts an id is present when synthesizing a terminal event. The chat\n * client always supplies `runContext.threadId` / `runContext.runId`, so an\n * absent id at this layer indicates the adapter was wired up by a caller\n * that bypassed that contract — surface it rather than fabricating one.\n */\nfunction requireSyntheticId(\n value: string | undefined,\n field: 'threadId' | 'runId',\n): string {\n if (!value) {\n throw new Error(\n `Cannot synthesize terminal event: ${field} not supplied via runContext and not observed in the upstream stream.`,\n )\n }\n return value\n}\n\n/**\n * Merge custom headers into request headers\n */\nfunction mergeHeaders(\n customHeaders?: Record<string, string> | Headers,\n): Record<string, string> {\n if (!customHeaders) {\n return {}\n }\n if (customHeaders instanceof Headers) {\n const result: Record<string, string> = {}\n customHeaders.forEach((value, key) => {\n result[key] = value\n })\n return result\n }\n return customHeaders\n}\n\n/**\n * Read lines from a stream (newline-delimited)\n */\nasync function* readStreamLines(\n reader: ReadableStreamDefaultReader<Uint8Array>,\n abortSignal?: AbortSignal,\n): AsyncGenerator<string> {\n try {\n const decoder = createResponseStreamTextDecoder()\n let buffer = ''\n\n while (!abortSignal?.aborted) {\n const { done, value } = await reader.read()\n if (done) break\n\n buffer += decoder.decode(value, { stream: true })\n const lines = buffer.split('\\n')\n\n // Keep the last incomplete line in the buffer\n buffer = lines.pop() || ''\n\n for (const line of lines) {\n if (line.trim()) {\n yield line\n }\n }\n }\n\n // A non-empty trailing buffer means the connection was cut mid-line.\n // Surface this as an error so the chat client transitions to 'error'\n // state instead of silently presenting a partial stream as success.\n // Skip when the consumer aborted — a user-initiated stop() interrupting\n // mid-line is expected, not a truncation bug.\n if (buffer.trim() && !abortSignal?.aborted) {\n throw new StreamTruncatedError()\n }\n } finally {\n reader.releaseLock()\n }\n}\n\n/**\n * Yield StreamChunks parsed from an SSE Response body.\n *\n * Accepts either `data: {...}` lines or bare JSON lines. Skips comments\n * starting with `:` (proxies and CDNs inject these as keepalives) and the\n * `event:` / `id:` / `retry:` SSE control fields. A `[DONE]` sentinel is\n * treated as a terminal event: a synthesized RUN_FINISHED is yielded using\n * the most recent upstream `threadId` / `runId`, ensuring the consumer sees\n * a clean terminal event with real correlation ids.\n *\n * A JSON parse failure throws — the consumer surfaces it as an error.\n */\nasync function* responseToSSEChunks(\n response: Response,\n abortSignal?: AbortSignal,\n): AsyncGenerator<StreamChunk> {\n if (!response.ok) {\n throw new Error(\n `HTTP error! status: ${response.status} ${response.statusText}`,\n )\n }\n const reader = getResponseStreamReader(response)\n let lastThreadId: string | undefined\n let lastRunId: string | undefined\n let lastModel: string | undefined\n for await (const line of readStreamLines(reader, abortSignal)) {\n if (\n line.startsWith(':') ||\n line.startsWith('event:') ||\n line.startsWith('id:') ||\n line.startsWith('retry:')\n ) {\n continue\n }\n const data = parseSseDataLine(line)\n if (data === '[DONE]') {\n const synthetic: RunFinishedEvent = {\n type: EventType.RUN_FINISHED,\n threadId: lastThreadId ?? '',\n runId: lastRunId ?? '',\n model: lastModel ?? '',\n timestamp: Date.now(),\n finishReason: 'stop',\n }\n yield synthetic\n return\n }\n const chunk = JSON.parse(data) as StreamChunk\n if ('threadId' in chunk && typeof chunk.threadId === 'string') {\n lastThreadId = chunk.threadId\n }\n if ('runId' in chunk && typeof chunk.runId === 'string') {\n lastRunId = chunk.runId\n }\n if ('model' in chunk && typeof chunk.model === 'string') {\n lastModel = chunk.model\n }\n yield chunk\n }\n}\n\n/**\n * Per-send context provided by the chat client to the connection adapter.\n * The adapter combines this with serialized messages to build a full\n * AG-UI `RunAgentInput` payload.\n */\nexport interface RunAgentInputContext {\n threadId: string\n runId: string\n parentRunId?: string\n /** Client-declared tools to advertise in the request payload. */\n clientTools?: Array<{\n name: string\n description: string\n parameters: unknown\n }>\n /** Arbitrary user-controlled passthrough data. */\n forwardedProps?: Record<string, unknown>\n}\n\nexport interface ConnectConnectionAdapter {\n /**\n * Connect and return an async iterable of StreamChunks.\n */\n connect: (\n messages: Array<UIMessage> | Array<ModelMessage>,\n data?: Record<string, any>,\n abortSignal?: AbortSignal,\n runContext?: RunAgentInputContext,\n ) => AsyncIterable<StreamChunk>\n}\n\nexport interface SubscribeConnectionAdapter {\n /**\n * Subscribe to stream chunks.\n */\n subscribe: (abortSignal?: AbortSignal) => AsyncIterable<StreamChunk>\n /**\n * Send a request; chunks arrive through subscribe().\n */\n send: (\n messages: Array<UIMessage> | Array<ModelMessage>,\n data?: Record<string, any>,\n abortSignal?: AbortSignal,\n runContext?: RunAgentInputContext,\n ) => Promise<void>\n}\n\n/**\n * Connection adapter union.\n * Provide either `connect`, or `subscribe` + `send`.\n */\nexport type ConnectionAdapter =\n | ConnectConnectionAdapter\n | SubscribeConnectionAdapter\n\n/**\n * Normalize a ConnectionAdapter to subscribe/send operations.\n *\n * If a connection provides native subscribe/send, that mode is used.\n * Otherwise, connect() is wrapped using an async queue.\n */\nexport function normalizeConnectionAdapter(\n connection: ConnectionAdapter | undefined,\n): SubscribeConnectionAdapter {\n if (!connection) {\n throw new Error('Connection adapter is required')\n }\n\n const hasConnect = 'connect' in connection\n const hasSubscribe = 'subscribe' in connection\n const hasSend = 'send' in connection\n\n if (hasConnect && (hasSubscribe || hasSend)) {\n throw new Error(\n 'Connection adapter must provide either connect or both subscribe and send, not both modes',\n )\n }\n\n if (hasSubscribe && hasSend) {\n return {\n subscribe: connection.subscribe.bind(connection),\n send: connection.send.bind(connection),\n }\n }\n\n if (!hasConnect) {\n throw new Error(\n 'Connection adapter must provide either connect or both subscribe and send',\n )\n }\n\n // Legacy connect() wrapper\n let activeBuffer: Array<StreamChunk> = []\n let activeWaiters: Array<(chunk: StreamChunk | null) => void> = []\n\n function push(chunk: StreamChunk, runId?: string): void {\n if (runId) {\n chunkRunIds.set(chunk, runId)\n }\n const waiter = activeWaiters.shift()\n if (waiter) {\n waiter(chunk)\n } else {\n activeBuffer.push(chunk)\n }\n }\n\n return {\n subscribe(abortSignal?: AbortSignal): AsyncIterable<StreamChunk> {\n // Transfer ownership to the latest subscriber so only one active\n // subscribe() call receives chunks from the shared connect-wrapper queue.\n const myBuffer: Array<StreamChunk> = activeBuffer.splice(0)\n const myWaiters: Array<(chunk: StreamChunk | null) => void> = []\n activeBuffer = myBuffer\n activeWaiters = myWaiters\n\n return (async function* () {\n while (!abortSignal?.aborted) {\n let chunk: StreamChunk | null\n const buffered = myBuffer.shift()\n if (buffered !== undefined) {\n chunk = buffered\n } else {\n chunk = await new Promise<StreamChunk | null>((resolve) => {\n const onAbort = () => resolve(null)\n myWaiters.push((c) => {\n abortSignal?.removeEventListener('abort', onAbort)\n resolve(c)\n })\n abortSignal?.addEventListener('abort', onAbort, { once: true })\n })\n }\n if (chunk !== null) yield chunk\n }\n })()\n },\n async send(messages, data, abortSignal, runContext) {\n let hasTerminalEvent = false\n let upstreamThreadId: string | undefined\n let upstreamRunId: string | undefined\n try {\n const stream = connection.connect(\n messages,\n data,\n abortSignal,\n runContext,\n )\n for await (const chunk of stream) {\n if ('threadId' in chunk && typeof chunk.threadId === 'string') {\n upstreamThreadId = chunk.threadId\n }\n if ('runId' in chunk && typeof chunk.runId === 'string') {\n upstreamRunId = chunk.runId\n }\n if (chunk.type === 'RUN_FINISHED' || chunk.type === 'RUN_ERROR') {\n hasTerminalEvent = true\n }\n push(chunk, runContext?.runId)\n }\n\n // If the connect stream ended cleanly without a terminal event,\n // synthesize RUN_FINISHED so request-scoped consumers can complete.\n // Reuse the caller's threadId/runId so client-side activeRunIds tracking matches.\n if (!abortSignal?.aborted && !hasTerminalEvent) {\n const synthetic: RunFinishedEvent = {\n type: EventType.RUN_FINISHED,\n threadId: requireSyntheticId(\n upstreamThreadId ?? runContext?.threadId,\n 'threadId',\n ),\n runId: requireSyntheticId(\n upstreamRunId ?? runContext?.runId,\n 'runId',\n ),\n model: 'connect-wrapper',\n timestamp: Date.now(),\n finishReason: 'stop',\n }\n push(synthetic)\n }\n } catch (err) {\n if (!abortSignal?.aborted && !hasTerminalEvent) {\n const message =\n err instanceof Error ? err.message : 'Unknown error in connect()'\n const synthetic: RunErrorEvent = {\n type: EventType.RUN_ERROR,\n threadId: requireSyntheticId(\n upstreamThreadId ?? runContext?.threadId,\n 'threadId',\n ),\n runId: requireSyntheticId(\n upstreamRunId ?? runContext?.runId,\n 'runId',\n ),\n timestamp: Date.now(),\n message,\n }\n push(synthetic)\n }\n throw err\n }\n },\n }\n}\n\n/**\n * Options for fetch-based connection adapters\n */\nexport interface FetchConnectionOptions {\n headers?: Record<string, string> | Headers\n credentials?: RequestCredentials\n signal?: AbortSignal\n body?: Record<string, any>\n fetchClient?: typeof globalThis.fetch\n}\n\n/**\n * Options for XHR-based connection adapters.\n */\nexport interface XhrConnectionOptions {\n headers?: Record<string, string> | Headers\n withCredentials?: boolean\n signal?: AbortSignal\n body?: Record<string, any>\n xhrFactory?: () => XMLHttpRequest\n}\n\ntype ResolvedConnectionOptions = Pick<\n FetchConnectionOptions,\n 'body' | 'headers'\n>\n\nfunction buildRunAgentInputBody(\n messages: Array<UIMessage> | Array<ModelMessage>,\n data: Record<string, any> | undefined,\n runContext: RunAgentInputContext | undefined,\n options: ResolvedConnectionOptions,\n): Record<string, unknown> {\n // Precedence (later spreads win): static adapter `body` is the base,\n // overridden by `runContext.forwardedProps`, overridden by per-message `data`.\n const wireMessages = uiMessagesToWire(messages as Array<UIMessage>)\n const forwardedProps = {\n ...options.body,\n ...(runContext?.forwardedProps ?? {}),\n ...data,\n }\n\n return {\n threadId: runContext?.threadId ?? generateRunId('thread'),\n runId: runContext?.runId ?? generateRunId('run'),\n ...(runContext?.parentRunId !== undefined && {\n parentRunId: runContext.parentRunId,\n }),\n state: {},\n messages: wireMessages,\n tools: runContext?.clientTools ?? [],\n context: [],\n forwardedProps,\n // Backward-compat mirror of `forwardedProps` under the legacy field name.\n data: { ...forwardedProps },\n }\n}\n\n/**\n * Create a Server-Sent Events connection adapter\n *\n * @param url - The API endpoint URL (or a function that returns the URL)\n * @param options - Fetch options (headers, credentials, body, etc.) or a function that returns options (can be async)\n * @returns A connection adapter for SSE streams\n *\n * @example\n * ```typescript\n * // Static URL\n * const connection = fetchServerSentEvents('/api/chat');\n *\n * // Dynamic URL\n * const connection = fetchServerSentEvents(() => `/api/chat?user=${userId}`);\n *\n * // With options\n * const connection = fetchServerSentEvents('/api/chat', {\n * headers: { 'Authorization': 'Bearer token' }\n * });\n *\n * // With dynamic options\n * const connection = fetchServerSentEvents('/api/chat', () => ({\n * headers: { 'Authorization': `Bearer ${getToken()}` }\n * }));\n *\n * // With additional body data\n * const connection = fetchServerSentEvents('/api/chat', async () => ({\n * body: {\n * provider: 'openai',\n * model: 'gpt-4o',\n * }\n * }));\n * ```\n */\nexport function fetchServerSentEvents(\n url: string | (() => string),\n options:\n | FetchConnectionOptions\n | (() => FetchConnectionOptions | Promise<FetchConnectionOptions>) = {},\n): ConnectConnectionAdapter {\n return {\n async *connect(messages, data, abortSignal, runContext) {\n // Resolve URL and options if they are functions\n const resolvedUrl = typeof url === 'function' ? url() : url\n const resolvedOptions =\n typeof options === 'function' ? await options() : options\n\n const requestHeaders: Record<string, string> = {\n 'Content-Type': 'application/json',\n ...mergeHeaders(resolvedOptions.headers),\n }\n\n // Build AG-UI RunAgentInput payload.\n //\n // Precedence (later spreads win): static adapter `body` is the base,\n // overridden by `runContext.forwardedProps` (constructor body /\n // forwardedProps options), overridden by per-message `data` passed\n // to `connection.send`. Runtime values win over static config —\n // this matches the documented \"forwardedProps wins\" semantic.\n const requestBody = buildRunAgentInputBody(\n messages,\n data,\n runContext,\n resolvedOptions,\n )\n\n const fetchClient = resolvedOptions.fetchClient ?? fetch\n // `RequestInit.signal` is typed `AbortSignal | null` (no `undefined`\n // under `exactOptionalPropertyTypes`), so spread it conditionally\n // rather than passing `undefined` explicitly.\n const signal = abortSignal || resolvedOptions.signal\n const response = await fetchClient(resolvedUrl, {\n method: 'POST',\n headers: requestHeaders,\n body: JSON.stringify(requestBody),\n credentials: resolvedOptions.credentials || 'same-origin',\n ...(signal ? { signal } : {}),\n })\n\n yield* responseToSSEChunks(response, abortSignal)\n },\n }\n}\n\n/**\n * Create an HTTP streaming connection adapter (for raw streaming without SSE format)\n *\n * @param url - The API endpoint URL (or a function that returns the URL)\n * @param options - Fetch options (headers, credentials, body, etc.) or a function that returns options (can be async)\n * @returns A connection adapter for HTTP streams\n *\n * @example\n * ```typescript\n * // Static URL\n * const connection = fetchHttpStream('/api/chat');\n *\n * // Dynamic URL\n * const connection = fetchHttpStream(() => `/api/chat?user=${userId}`);\n *\n * // With options\n * const connection = fetchHttpStream('/api/chat', {\n * headers: { 'Authorization': 'Bearer token' }\n * });\n *\n * // With dynamic options\n * const connection = fetchHttpStream('/api/chat', () => ({\n * headers: { 'Authorization': `Bearer ${getToken()}` }\n * }));\n *\n * // With additional body data\n * const connection = fetchHttpStream('/api/chat', async () => ({\n * body: {\n * provider: 'openai',\n * model: 'gpt-4o',\n * }\n * }));\n * ```\n */\nexport function fetchHttpStream(\n url: string | (() => string),\n options:\n | FetchConnectionOptions\n | (() => FetchConnectionOptions | Promise<FetchConnectionOptions>) = {},\n): ConnectConnectionAdapter {\n return {\n async *connect(messages, data, abortSignal, runContext) {\n // Resolve URL and options if they are functions\n const resolvedUrl = typeof url === 'function' ? url() : url\n const resolvedOptions =\n typeof options === 'function' ? await options() : options\n\n const requestHeaders: Record<string, string> = {\n 'Content-Type': 'application/json',\n ...mergeHeaders(resolvedOptions.headers),\n }\n\n // Build AG-UI RunAgentInput payload.\n //\n // Precedence (later spreads win): static adapter `body` is the base,\n // overridden by `runContext.forwardedProps` (constructor body /\n // forwardedProps options), overridden by per-message `data` passed\n // to `connection.send`. Runtime values win over static config —\n // this matches the documented \"forwardedProps wins\" semantic.\n const requestBody = buildRunAgentInputBody(\n messages,\n data,\n runContext,\n resolvedOptions,\n )\n\n const fetchClient = resolvedOptions.fetchClient ?? fetch\n // `RequestInit.signal` is typed `AbortSignal | null` (no `undefined`\n // under `exactOptionalPropertyTypes`), so spread it conditionally\n // rather than passing `undefined` explicitly.\n const signal = abortSignal || resolvedOptions.signal\n const response = await fetchClient(resolvedUrl, {\n method: 'POST',\n headers: requestHeaders,\n body: JSON.stringify(requestBody),\n credentials: resolvedOptions.credentials || 'same-origin',\n ...(signal ? { signal } : {}),\n })\n\n if (!response.ok) {\n throw new Error(\n `HTTP error! status: ${response.status} ${response.statusText}`,\n )\n }\n\n // Parse raw HTTP stream (newline-delimited JSON)\n const reader = getResponseStreamReader(response)\n\n for await (const line of readStreamLines(reader, abortSignal)) {\n yield JSON.parse(line) as StreamChunk\n }\n },\n }\n}\n\ntype XhrConnectionOptionsResolver =\n | XhrConnectionOptions\n | (() => XhrConnectionOptions | Promise<XhrConnectionOptions>)\n\nfunction createDefaultXMLHttpRequest(): XMLHttpRequest {\n if (typeof globalThis.XMLHttpRequest !== 'function') {\n throw new Error('XMLHttpRequest is not available in this runtime')\n }\n\n return new globalThis.XMLHttpRequest()\n}\n\nfunction cleanupXhr(\n xhr: XMLHttpRequest,\n abortSignal: AbortSignal | undefined,\n onAbort: (() => void) | undefined,\n): void {\n xhr.onprogress = null\n xhr.onload = null\n xhr.onerror = null\n xhr.onabort = null\n xhr.onloadend = null\n\n if (abortSignal && onAbort) {\n abortSignal.removeEventListener('abort', onAbort)\n }\n}\n\nfunction readXhrLines(\n xhr: XMLHttpRequest,\n abortSignal?: AbortSignal,\n): AsyncGenerator<string> {\n let offset = 0\n let buffer = ''\n const lines: Array<string> = []\n const waiters: Array<() => void> = []\n let done = false\n let aborted = false\n let error: unknown\n let onAbort: (() => void) | undefined\n\n const wake = () => {\n const waiter = waiters.shift()\n waiter?.()\n }\n\n const enqueueDelta = () => {\n if (xhr.status !== 0 && (xhr.status < 200 || xhr.status >= 300)) {\n error = new Error(`XHR error! status: ${xhr.status} ${xhr.statusText}`)\n done = true\n return\n }\n\n const responseText = xhr.responseText\n if (responseText.length <= offset) {\n return\n }\n\n buffer += responseText.slice(offset)\n offset = responseText.length\n const splitLines = buffer.split('\\n')\n buffer = splitLines.pop() ?? ''\n\n for (const line of splitLines) {\n const normalized = line.endsWith('\\r') ? line.slice(0, -1) : line\n if (normalized.trim()) {\n lines.push(normalized)\n }\n }\n }\n\n const finish = () => {\n enqueueDelta()\n if (xhr.status < 200 || xhr.status >= 300) {\n error = new Error(`XHR error! status: ${xhr.status} ${xhr.statusText}`)\n } else if (buffer.trim() && !aborted) {\n error = new StreamTruncatedError()\n }\n done = true\n wake()\n }\n\n xhr.onprogress = () => {\n enqueueDelta()\n wake()\n }\n xhr.onload = finish\n xhr.onerror = () => {\n error = new Error('XHR request failed')\n done = true\n wake()\n }\n xhr.onabort = () => {\n aborted = true\n done = true\n wake()\n }\n xhr.onloadend = () => {\n if (!done) {\n finish()\n }\n }\n\n if (abortSignal) {\n onAbort = () => {\n aborted = true\n xhr.abort()\n }\n if (abortSignal.aborted) {\n onAbort()\n } else {\n abortSignal.addEventListener('abort', onAbort, { once: true })\n }\n }\n\n return (async function* () {\n try {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n while (true) {\n const line = lines.shift()\n if (line !== undefined) {\n yield line\n continue\n }\n\n if (error) {\n throw error\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (done || abortSignal?.aborted) {\n return\n }\n\n await new Promise<void>((resolve) => {\n waiters.push(resolve)\n })\n }\n } finally {\n cleanupXhr(xhr, abortSignal, onAbort)\n }\n })()\n}\n\ninterface ConfiguredXhrRequest {\n xhr: XMLHttpRequest\n body: string\n}\n\nfunction createConfiguredXhrRequest(\n url: string,\n options: XhrConnectionOptions,\n messages: Array<UIMessage> | Array<ModelMessage>,\n data: Record<string, any> | undefined,\n runContext: RunAgentInputContext | undefined,\n): ConfiguredXhrRequest {\n const xhr = options.xhrFactory?.() ?? createDefaultXMLHttpRequest()\n xhr.open('POST', url)\n if (options.withCredentials !== undefined) {\n xhr.withCredentials = options.withCredentials\n }\n\n const requestHeaders: Record<string, string> = {\n 'Content-Type': 'application/json',\n ...mergeHeaders(options.headers),\n }\n\n for (const [name, value] of Object.entries(requestHeaders)) {\n xhr.setRequestHeader(name, value)\n }\n\n const requestBody = buildRunAgentInputBody(\n messages,\n data,\n runContext,\n options,\n )\n\n return { xhr, body: JSON.stringify(requestBody) }\n}\n\nasync function resolveXhrConnectionOptions(\n options: XhrConnectionOptionsResolver,\n): Promise<XhrConnectionOptions> {\n return typeof options === 'function' ? await options() : options\n}\n\n/**\n * Create an XMLHttpRequest-backed Server-Sent Events connection adapter.\n */\nexport function xhrServerSentEvents(\n url: string | (() => string),\n options: XhrConnectionOptionsResolver = {},\n): ConnectConnectionAdapter {\n return {\n async *connect(messages, data, abortSignal, runContext) {\n const resolvedUrl = typeof url === 'function' ? url() : url\n const resolvedOptions = await resolveXhrConnectionOptions(options)\n const signal = abortSignal || resolvedOptions.signal\n const request = createConfiguredXhrRequest(\n resolvedUrl,\n resolvedOptions,\n messages,\n data,\n runContext,\n )\n const lines = readXhrLines(request.xhr, signal)\n if (signal?.aborted) {\n await lines.next()\n return\n }\n request.xhr.send(request.body)\n let lastThreadId: string | undefined\n let lastRunId: string | undefined\n let lastModel: string | undefined\n\n for await (const line of lines) {\n if (\n line.startsWith(':') ||\n line.startsWith('event:') ||\n line.startsWith('id:') ||\n line.startsWith('retry:')\n ) {\n continue\n }\n\n const chunkData = parseSseDataLine(line)\n if (chunkData === '[DONE]') {\n const synthetic: RunFinishedEvent = {\n type: EventType.RUN_FINISHED,\n threadId: lastThreadId ?? runContext?.threadId ?? '',\n runId: lastRunId ?? runContext?.runId ?? '',\n model: lastModel ?? '',\n timestamp: Date.now(),\n finishReason: 'stop',\n }\n request.xhr.abort()\n yield synthetic\n return\n }\n\n const chunk = JSON.parse(chunkData) as StreamChunk\n if ('threadId' in chunk && typeof chunk.threadId === 'string') {\n lastThreadId = chunk.threadId\n }\n if ('runId' in chunk && typeof chunk.runId === 'string') {\n lastRunId = chunk.runId\n }\n if ('model' in chunk && typeof chunk.model === 'string') {\n lastModel = chunk.model\n }\n yield chunk\n }\n },\n }\n}\n\n/**\n * Create an XMLHttpRequest-backed newline-delimited JSON stream adapter.\n */\nexport function xhrHttpStream(\n url: string | (() => string),\n options: XhrConnectionOptionsResolver = {},\n): ConnectConnectionAdapter {\n return {\n async *connect(messages, data, abortSignal, runContext) {\n const resolvedUrl = typeof url === 'function' ? url() : url\n const resolvedOptions = await resolveXhrConnectionOptions(options)\n const signal = abortSignal || resolvedOptions.signal\n const request = createConfiguredXhrRequest(\n resolvedUrl,\n resolvedOptions,\n messages,\n data,\n runContext,\n )\n const lines = readXhrLines(request.xhr, signal)\n if (signal?.aborted) {\n await lines.next()\n return\n }\n request.xhr.send(request.body)\n\n for await (const line of lines) {\n yield JSON.parse(line) as StreamChunk\n }\n },\n }\n}\n\n/**\n * Create a direct stream connection adapter (for server functions or direct streams)\n *\n * @param streamFactory - A function that returns an async iterable of StreamChunks\n * @returns A connection adapter for direct streams\n *\n * @example\n * ```typescript\n * // With TanStack Start server function\n * const connection = stream(() => serverFunction({ messages }));\n *\n * const client = new ChatClient({ connection });\n * ```\n */\nexport function stream(\n streamFactory: (\n messages: Array<UIMessage> | Array<ModelMessage>,\n data?: Record<string, any>,\n abortSignal?: AbortSignal,\n ) => AsyncIterable<StreamChunk>,\n): ConnectConnectionAdapter {\n return {\n async *connect(messages, data, abortSignal) {\n // Pass messages as-is (UIMessages with parts preserved)\n // Server-side chat() handles conversion to ModelMessages\n yield* streamFactory(messages, data, abortSignal)\n },\n }\n}\n\n/**\n * Wrap a `ChatFetcher` as a `ConnectConnectionAdapter` so the chat client can\n * consume it through the same `subscribe`/`send` plumbing used for SSE /\n * HTTP-stream / RPC connections. May return either a `Response` (parsed as\n * SSE) or an `AsyncIterable<StreamChunk>` (yielded directly).\n *\n * @internal\n */\nexport function fetcherToConnectionAdapter(\n fetcher: ChatFetcher,\n): ConnectConnectionAdapter {\n return {\n async *connect(messages, data, abortSignal, runContext) {\n if (!abortSignal) {\n throw new Error(\n 'fetcherToConnectionAdapter requires an AbortSignal — the chat client always supplies one.',\n )\n }\n if (!runContext) {\n throw new Error(\n 'fetcherToConnectionAdapter requires a RunAgentInputContext — the chat client always supplies one.',\n )\n }\n const uiMessages = messages as Array<UIMessage>\n const result = await fetcher(\n {\n messages: uiMessages,\n data,\n threadId: runContext.threadId,\n runId: runContext.runId,\n },\n { signal: abortSignal },\n )\n if (result instanceof Response) {\n yield* responseToSSEChunks(result, abortSignal)\n } else {\n yield* abortableIterable(result, abortSignal)\n }\n },\n }\n}\n\n/**\n * Wrap an AsyncIterable so iteration aborts when `signal` fires. Without\n * this, a fetcher that returns a generator ignoring its signal would leave\n * the for-await loop hanging until the iterable naturally ends.\n */\nasync function* abortableIterable<T>(\n iterable: AsyncIterable<T>,\n signal: AbortSignal,\n): AsyncGenerator<T> {\n if (signal.aborted) return\n const iterator = iterable[Symbol.asyncIterator]()\n const abortPromise = new Promise<{ done: true; value: undefined }>(\n (resolve) => {\n signal.addEventListener(\n 'abort',\n () => resolve({ done: true, value: undefined }),\n { once: true },\n )\n },\n )\n try {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n while (true) {\n const result = await Promise.race([iterator.next(), abortPromise])\n if (result.done) return\n yield result.value\n }\n } finally {\n await iterator.return?.()\n }\n}\n\n/**\n * Create an RPC stream connection adapter (for RPC-based streaming like Cap'n Web RPC)\n *\n * @param rpcCall - A function that accepts messages and returns an async iterable of StreamChunks\n * @returns A connection adapter for RPC streams\n *\n * @example\n * ```typescript\n * // With Cap'n Web RPC\n * const connection = rpcStream((messages, data) =>\n * api.streamMurfResponse(messages, data)\n * );\n *\n * const client = new ChatClient({ connection });\n * ```\n */\nexport function rpcStream(\n rpcCall: (\n messages: Array<UIMessage> | Array<ModelMessage>,\n data?: Record<string, any>,\n abortSignal?: AbortSignal,\n ) => AsyncIterable<StreamChunk>,\n): ConnectConnectionAdapter {\n return {\n async *connect(messages, data, abortSignal) {\n // Pass messages as-is (UIMessages with parts preserved)\n // Server-side chat() handles conversion to ModelMessages\n yield* rpcCall(messages, data, abortSignal)\n },\n }\n}\n"],"names":["stream"],"mappings":";;;AAsBA,MAAM,kCAAkB,QAAA;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,QAEpB,EAAE,QAAQ,YAAA;AAAA,MAAY;AAExB,UAAI,kBAAkB,UAAU;AAC9B,eAAO,oBAAoB,QAAQ,WAAW;AAAA,MAChD,OAAO;AACL,eAAO,kBAAkB,QAAQ,WAAW;AAAA,MAC9C;AAAA,IACF;AAAA,EAAA;AAEJ;AAOA,gBAAgB,kBACd,UACA,QACmB;AACnB,MAAI,OAAO,QAAS;AACpB,QAAM,WAAW,SAAS,OAAO,aAAa,EAAA;AAC9C,QAAM,eAAe,IAAI;AAAA,IACvB,CAAC,YAAY;AACX,aAAO;AAAA,QACL;AAAA,QACA,MAAM,QAAQ,EAAE,MAAM,MAAM,OAAO,QAAW;AAAA,QAC9C,EAAE,MAAM,KAAA;AAAA,MAAK;AAAA,IAEjB;AAAA,EAAA;AAEF,MAAI;AAEF,WAAO,MAAM;AACX,YAAM,SAAS,MAAM,QAAQ,KAAK,CAAC,SAAS,KAAA,GAAQ,YAAY,CAAC;AACjE,UAAI,OAAO,KAAM;AACjB,YAAM,OAAO;AAAA,IACf;AAAA,EACF,UAAA;AACE,UAAM,SAAS,SAAA;AAAA,EACjB;AACF;AAkBO,SAAS,UACd,SAK0B;AAC1B,SAAO;AAAA,IACL,OAAO,QAAQ,UAAU,MAAM,aAAa;AAG1C,aAAO,QAAQ,UAAU,MAAM,WAAW;AAAA,IAC5C;AAAA,EAAA;AAEJ;"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { ChatClientEventEmitter, ChatClientEventContext, ChatClientRunEventContext } from './events.js';
|
|
2
|
-
import { AIDevtoolsToolFixture, ChatDevtoolsBridge, ChatDevtoolsBridgeOptions, GenerationDevtoolsBridge, GenerationDevtoolsBridgeOptions, VideoDevtoolsBridge, VideoDevtoolsBridgeOptions } from './devtools.js';
|
|
3
|
-
import { StreamChunk } from '@tanstack/ai/client';
|
|
4
|
-
export type ChatDevtoolsBridgeFactory = (options: ChatDevtoolsBridgeOptions) => ChatDevtoolsBridge;
|
|
5
|
-
export type GenerationDevtoolsBridgeFactory = <TOutput>(options: GenerationDevtoolsBridgeOptions<TOutput>) => GenerationDevtoolsBridge<TOutput>;
|
|
6
|
-
export type VideoDevtoolsBridgeFactory = <TOutput>(options: VideoDevtoolsBridgeOptions<TOutput>) => VideoDevtoolsBridge<TOutput>;
|
|
7
|
-
export declare class NoOpChatDevtoolsBridge {
|
|
8
|
-
readonly events: ChatClientEventEmitter;
|
|
9
|
-
constructor(options: ChatDevtoolsBridgeOptions);
|
|
10
|
-
emitRegistered(): void;
|
|
11
|
-
emitUpdated(): void;
|
|
12
|
-
emitSnapshot(): void;
|
|
13
|
-
emitToolsRegistered(): void;
|
|
14
|
-
emitRunLifecycle(_eventType: unknown, _runId: string, _status: unknown, _options?: {
|
|
15
|
-
error?: string;
|
|
16
|
-
}): void;
|
|
17
|
-
deactivate(): void;
|
|
18
|
-
supersede(): void;
|
|
19
|
-
dispose(): void;
|
|
20
|
-
mountWithTools(_initialMessageCount: number): void;
|
|
21
|
-
notifyToolsChanged(): void;
|
|
22
|
-
setCurrentStreamId(_streamId: string | null): void;
|
|
23
|
-
recordStreamId(_streamId: string): void;
|
|
24
|
-
getCurrentStreamId(): string | null;
|
|
25
|
-
getLastStreamId(): string | null;
|
|
26
|
-
resolveStreamId(): string;
|
|
27
|
-
observeChunk(_chunk: StreamChunk): void;
|
|
28
|
-
beginRun(_runId: string, _threadId: string): void;
|
|
29
|
-
getCurrentRunEventContext(): ChatClientRunEventContext | undefined;
|
|
30
|
-
getCurrentOrLastRunEventContext(): ChatClientRunEventContext | undefined;
|
|
31
|
-
findToolCallContext(toolCallId: string): ChatClientEventContext;
|
|
32
|
-
applyFixture(_fixture: AIDevtoolsToolFixture): Promise<void>;
|
|
33
|
-
}
|
|
34
|
-
export declare class NoOpGenerationDevtoolsBridge<TOutput> {
|
|
35
|
-
constructor(_options: GenerationDevtoolsBridgeOptions<TOutput>);
|
|
36
|
-
emitRegistered(): void;
|
|
37
|
-
emitUpdated(): void;
|
|
38
|
-
emitSnapshot(): void;
|
|
39
|
-
emitToolsRegistered(): void;
|
|
40
|
-
emitRunLifecycle(): void;
|
|
41
|
-
deactivate(): void;
|
|
42
|
-
supersede(): void;
|
|
43
|
-
dispose(): void;
|
|
44
|
-
beginRun(_input: unknown): string;
|
|
45
|
-
ensureRunStarted(_runId: string): void;
|
|
46
|
-
finishRun(_runId: string, _eventType: 'run:completed' | 'run:errored' | 'run:cancelled', _status: 'completed' | 'errored' | 'cancelled', _error?: string): void;
|
|
47
|
-
getActiveRunId(): string | null;
|
|
48
|
-
resetRuns(): void;
|
|
49
|
-
recordResultChange(): void;
|
|
50
|
-
recordLoadingChange(): void;
|
|
51
|
-
recordErrorChange(_error: Error | undefined): void;
|
|
52
|
-
recordStatusChange(): void;
|
|
53
|
-
recordProgressChange(): void;
|
|
54
|
-
emitState(): void;
|
|
55
|
-
}
|
|
56
|
-
export declare class NoOpVideoDevtoolsBridge<TOutput> extends NoOpGenerationDevtoolsBridge<TOutput> {
|
|
57
|
-
constructor(options: VideoDevtoolsBridgeOptions<TOutput>);
|
|
58
|
-
recordJobIdChange(): void;
|
|
59
|
-
recordVideoStatusChange(): void;
|
|
60
|
-
}
|
|
61
|
-
export declare const createNoOpChatDevtoolsBridge: ChatDevtoolsBridgeFactory;
|
|
62
|
-
export declare const createNoOpGenerationDevtoolsBridge: GenerationDevtoolsBridgeFactory;
|
|
63
|
-
export declare const createNoOpVideoDevtoolsBridge: VideoDevtoolsBridgeFactory;
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { ChatClientEventEmitter } from "./events.js";
|
|
2
|
-
class NoOpChatClientEventEmitter extends ChatClientEventEmitter {
|
|
3
|
-
emitEvent() {
|
|
4
|
-
}
|
|
5
|
-
}
|
|
6
|
-
class NoOpChatDevtoolsBridge {
|
|
7
|
-
events;
|
|
8
|
-
constructor(options) {
|
|
9
|
-
this.events = new NoOpChatClientEventEmitter(options.clientId);
|
|
10
|
-
}
|
|
11
|
-
// base bridge surface
|
|
12
|
-
emitRegistered() {
|
|
13
|
-
}
|
|
14
|
-
emitUpdated() {
|
|
15
|
-
}
|
|
16
|
-
emitSnapshot() {
|
|
17
|
-
}
|
|
18
|
-
emitToolsRegistered() {
|
|
19
|
-
}
|
|
20
|
-
emitRunLifecycle(_eventType, _runId, _status, _options) {
|
|
21
|
-
}
|
|
22
|
-
deactivate() {
|
|
23
|
-
}
|
|
24
|
-
supersede() {
|
|
25
|
-
}
|
|
26
|
-
dispose() {
|
|
27
|
-
}
|
|
28
|
-
// chat-specific surface
|
|
29
|
-
mountWithTools(_initialMessageCount) {
|
|
30
|
-
}
|
|
31
|
-
notifyToolsChanged() {
|
|
32
|
-
}
|
|
33
|
-
setCurrentStreamId(_streamId) {
|
|
34
|
-
}
|
|
35
|
-
recordStreamId(_streamId) {
|
|
36
|
-
}
|
|
37
|
-
getCurrentStreamId() {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
getLastStreamId() {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
resolveStreamId() {
|
|
44
|
-
return "";
|
|
45
|
-
}
|
|
46
|
-
observeChunk(_chunk) {
|
|
47
|
-
}
|
|
48
|
-
beginRun(_runId, _threadId) {
|
|
49
|
-
}
|
|
50
|
-
getCurrentRunEventContext() {
|
|
51
|
-
return void 0;
|
|
52
|
-
}
|
|
53
|
-
getCurrentOrLastRunEventContext() {
|
|
54
|
-
return void 0;
|
|
55
|
-
}
|
|
56
|
-
findToolCallContext(toolCallId) {
|
|
57
|
-
return { toolCallId };
|
|
58
|
-
}
|
|
59
|
-
async applyFixture(_fixture) {
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
class NoOpGenerationDevtoolsBridge {
|
|
63
|
-
constructor(_options) {
|
|
64
|
-
}
|
|
65
|
-
// base bridge surface
|
|
66
|
-
emitRegistered() {
|
|
67
|
-
}
|
|
68
|
-
emitUpdated() {
|
|
69
|
-
}
|
|
70
|
-
emitSnapshot() {
|
|
71
|
-
}
|
|
72
|
-
emitToolsRegistered() {
|
|
73
|
-
}
|
|
74
|
-
emitRunLifecycle() {
|
|
75
|
-
}
|
|
76
|
-
deactivate() {
|
|
77
|
-
}
|
|
78
|
-
supersede() {
|
|
79
|
-
}
|
|
80
|
-
dispose() {
|
|
81
|
-
}
|
|
82
|
-
// generation-specific surface
|
|
83
|
-
beginRun(_input) {
|
|
84
|
-
return `noop-run-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
85
|
-
}
|
|
86
|
-
ensureRunStarted(_runId) {
|
|
87
|
-
}
|
|
88
|
-
finishRun(_runId, _eventType, _status, _error) {
|
|
89
|
-
}
|
|
90
|
-
getActiveRunId() {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
resetRuns() {
|
|
94
|
-
}
|
|
95
|
-
recordResultChange() {
|
|
96
|
-
}
|
|
97
|
-
recordLoadingChange() {
|
|
98
|
-
}
|
|
99
|
-
recordErrorChange(_error) {
|
|
100
|
-
}
|
|
101
|
-
recordStatusChange() {
|
|
102
|
-
}
|
|
103
|
-
recordProgressChange() {
|
|
104
|
-
}
|
|
105
|
-
emitState() {
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
class NoOpVideoDevtoolsBridge extends NoOpGenerationDevtoolsBridge {
|
|
109
|
-
constructor(options) {
|
|
110
|
-
super(options);
|
|
111
|
-
}
|
|
112
|
-
recordJobIdChange() {
|
|
113
|
-
}
|
|
114
|
-
recordVideoStatusChange() {
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
const createNoOpChatDevtoolsBridge = (options) => (
|
|
118
|
-
// eslint-disable-next-line no-restricted-syntax -- see comment above
|
|
119
|
-
new NoOpChatDevtoolsBridge(options)
|
|
120
|
-
);
|
|
121
|
-
const createNoOpGenerationDevtoolsBridge = (options) => (
|
|
122
|
-
// eslint-disable-next-line no-restricted-syntax -- see comment above
|
|
123
|
-
new NoOpGenerationDevtoolsBridge(
|
|
124
|
-
options
|
|
125
|
-
)
|
|
126
|
-
);
|
|
127
|
-
const createNoOpVideoDevtoolsBridge = (options) => (
|
|
128
|
-
// eslint-disable-next-line no-restricted-syntax -- see comment above
|
|
129
|
-
new NoOpVideoDevtoolsBridge(
|
|
130
|
-
options
|
|
131
|
-
)
|
|
132
|
-
);
|
|
133
|
-
export {
|
|
134
|
-
NoOpChatDevtoolsBridge,
|
|
135
|
-
NoOpGenerationDevtoolsBridge,
|
|
136
|
-
NoOpVideoDevtoolsBridge,
|
|
137
|
-
createNoOpChatDevtoolsBridge,
|
|
138
|
-
createNoOpGenerationDevtoolsBridge,
|
|
139
|
-
createNoOpVideoDevtoolsBridge
|
|
140
|
-
};
|
|
141
|
-
//# sourceMappingURL=devtools-noop.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"devtools-noop.js","sources":["../../src/devtools-noop.ts"],"sourcesContent":["// No-op devtools bridge implementations + factories. The chat / generation /\n// video clients import the real bridge classes as types only and accept a\n// factory in options; when no factory is supplied they fall back to the\n// no-op factories here, which never touch `aiEventClient` or any of the\n// heavy preview/fixture machinery in `./devtools`. This keeps `./devtools`\n// outside the main-entry import graph — consumers opt into functional\n// devtools via `@tanstack/ai-client/devtools` (see `package.json#exports`).\nimport { ChatClientEventEmitter } from './events'\nimport type {\n AIDevtoolsToolFixture,\n ChatDevtoolsBridge,\n ChatDevtoolsBridgeOptions,\n GenerationDevtoolsBridge,\n GenerationDevtoolsBridgeOptions,\n VideoDevtoolsBridge,\n VideoDevtoolsBridgeOptions,\n} from './devtools'\nimport type { StreamChunk } from '@tanstack/ai/client'\nimport type {\n ChatClientEventContext,\n ChatClientRunEventContext,\n} from './events'\n\nexport type ChatDevtoolsBridgeFactory = (\n options: ChatDevtoolsBridgeOptions,\n) => ChatDevtoolsBridge\n\nexport type GenerationDevtoolsBridgeFactory = <TOutput>(\n options: GenerationDevtoolsBridgeOptions<TOutput>,\n) => GenerationDevtoolsBridge<TOutput>\n\nexport type VideoDevtoolsBridgeFactory = <TOutput>(\n options: VideoDevtoolsBridgeOptions<TOutput>,\n) => VideoDevtoolsBridge<TOutput>\n\n// ===========================================================================\n// No-op event emitter — extends the abstract base so it satisfies the type\n// without dragging in any of the event-bus runtime cost.\n// ===========================================================================\n\nclass NoOpChatClientEventEmitter extends ChatClientEventEmitter {\n protected emitEvent(): void {\n // intentionally empty\n }\n}\n\n// ===========================================================================\n// No-op bridges. Methods exist to satisfy the structural shape of the real\n// classes; every emit/record call short-circuits.\n// ===========================================================================\n\nexport class NoOpChatDevtoolsBridge {\n readonly events: ChatClientEventEmitter\n\n constructor(options: ChatDevtoolsBridgeOptions) {\n this.events = new NoOpChatClientEventEmitter(options.clientId)\n }\n\n // base bridge surface\n emitRegistered(): void {}\n emitUpdated(): void {}\n emitSnapshot(): void {}\n emitToolsRegistered(): void {}\n emitRunLifecycle(\n _eventType: unknown,\n _runId: string,\n _status: unknown,\n _options?: { error?: string },\n ): void {}\n deactivate(): void {}\n supersede(): void {}\n dispose(): void {}\n\n // chat-specific surface\n mountWithTools(_initialMessageCount: number): void {}\n notifyToolsChanged(): void {}\n setCurrentStreamId(_streamId: string | null): void {}\n recordStreamId(_streamId: string): void {}\n getCurrentStreamId(): string | null {\n return null\n }\n getLastStreamId(): string | null {\n return null\n }\n resolveStreamId(): string {\n return ''\n }\n observeChunk(_chunk: StreamChunk): void {}\n beginRun(_runId: string, _threadId: string): void {}\n getCurrentRunEventContext(): ChatClientRunEventContext | undefined {\n return undefined\n }\n getCurrentOrLastRunEventContext(): ChatClientRunEventContext | undefined {\n return undefined\n }\n findToolCallContext(toolCallId: string): ChatClientEventContext {\n return { toolCallId }\n }\n async applyFixture(_fixture: AIDevtoolsToolFixture): Promise<void> {\n // intentionally empty\n }\n}\n\nexport class NoOpGenerationDevtoolsBridge<TOutput> {\n constructor(_options: GenerationDevtoolsBridgeOptions<TOutput>) {}\n\n // base bridge surface\n emitRegistered(): void {}\n emitUpdated(): void {}\n emitSnapshot(): void {}\n emitToolsRegistered(): void {}\n emitRunLifecycle(): void {}\n deactivate(): void {}\n supersede(): void {}\n dispose(): void {}\n\n // generation-specific surface\n beginRun(_input: unknown): string {\n // Real factories supply a stable id; the no-op still returns a\n // unique value because the generation client passes this run id to\n // the adapter's RunAgentInputContext.\n return `noop-run-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`\n }\n ensureRunStarted(_runId: string): void {}\n finishRun(\n _runId: string,\n _eventType: 'run:completed' | 'run:errored' | 'run:cancelled',\n _status: 'completed' | 'errored' | 'cancelled',\n _error?: string,\n ): void {}\n getActiveRunId(): string | null {\n return null\n }\n resetRuns(): void {}\n recordResultChange(): void {}\n recordLoadingChange(): void {}\n recordErrorChange(_error: Error | undefined): void {}\n recordStatusChange(): void {}\n recordProgressChange(): void {}\n emitState(): void {}\n}\n\nexport class NoOpVideoDevtoolsBridge<\n TOutput,\n> extends NoOpGenerationDevtoolsBridge<TOutput> {\n constructor(options: VideoDevtoolsBridgeOptions<TOutput>) {\n super(options)\n }\n\n recordJobIdChange(): void {}\n recordVideoStatusChange(): void {}\n}\n\n// Compile-time parity checks. If a public method is added to the real\n// bridge class without a matching stub on the no-op, the corresponding\n// `Exclude<...>` resolves to a non-`never` union, which violates the\n// `extends never` constraint below and fails the build — surfacing the\n// drift at build time instead of as a runtime TypeError later.\ntype AssertBridgeParity<TMissing extends never> = TMissing\ntype _ChatBridgeMissing = Exclude<\n keyof ChatDevtoolsBridge,\n keyof NoOpChatDevtoolsBridge\n>\ntype _GenerationBridgeMissing = Exclude<\n keyof GenerationDevtoolsBridge<unknown>,\n keyof NoOpGenerationDevtoolsBridge<unknown>\n>\ntype _VideoBridgeMissing = Exclude<\n keyof VideoDevtoolsBridge<unknown>,\n keyof NoOpVideoDevtoolsBridge<unknown>\n>\nconst _bridgeParity:\n | [\n AssertBridgeParity<_ChatBridgeMissing>,\n AssertBridgeParity<_GenerationBridgeMissing>,\n AssertBridgeParity<_VideoBridgeMissing>,\n ]\n | undefined = undefined\nvoid _bridgeParity\n\n// ===========================================================================\n// Factories — these are what the clients call when no real factory was\n// supplied in options.\n// ===========================================================================\n\n// Casts use `unknown` because the no-op classes don't `extend` the real bridge\n// (that would pull the real implementation into the main-entry import graph).\n// Structural parity is enforced by the `_*BridgeMissing` checks above.\n\nexport const createNoOpChatDevtoolsBridge: ChatDevtoolsBridgeFactory = (\n options,\n) =>\n // eslint-disable-next-line no-restricted-syntax -- see comment above\n new NoOpChatDevtoolsBridge(options) as unknown as ChatDevtoolsBridge\n\nexport const createNoOpGenerationDevtoolsBridge: GenerationDevtoolsBridgeFactory =\n <TOutput>(options: GenerationDevtoolsBridgeOptions<TOutput>) =>\n // eslint-disable-next-line no-restricted-syntax -- see comment above\n new NoOpGenerationDevtoolsBridge<TOutput>(\n options,\n ) as unknown as GenerationDevtoolsBridge<TOutput>\n\nexport const createNoOpVideoDevtoolsBridge: VideoDevtoolsBridgeFactory = <\n TOutput,\n>(\n options: VideoDevtoolsBridgeOptions<TOutput>,\n) =>\n // eslint-disable-next-line no-restricted-syntax -- see comment above\n new NoOpVideoDevtoolsBridge<TOutput>(\n options,\n ) as unknown as VideoDevtoolsBridge<TOutput>\n"],"names":[],"mappings":";AAwCA,MAAM,mCAAmC,uBAAuB;AAAA,EACpD,YAAkB;AAAA,EAE5B;AACF;AAOO,MAAM,uBAAuB;AAAA,EACzB;AAAA,EAET,YAAY,SAAoC;AAC9C,SAAK,SAAS,IAAI,2BAA2B,QAAQ,QAAQ;AAAA,EAC/D;AAAA;AAAA,EAGA,iBAAuB;AAAA,EAAC;AAAA,EACxB,cAAoB;AAAA,EAAC;AAAA,EACrB,eAAqB;AAAA,EAAC;AAAA,EACtB,sBAA4B;AAAA,EAAC;AAAA,EAC7B,iBACE,YACA,QACA,SACA,UACM;AAAA,EAAC;AAAA,EACT,aAAmB;AAAA,EAAC;AAAA,EACpB,YAAkB;AAAA,EAAC;AAAA,EACnB,UAAgB;AAAA,EAAC;AAAA;AAAA,EAGjB,eAAe,sBAAoC;AAAA,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BAAkB,QAAiC;AAAA,EAAC;AAAA,EACpD,qBAA2B;AAAA,EAAC;AAAA,EAC5B,uBAA6B;AAAA,EAAC;AAAA,EAC9B,YAAkB;AAAA,EAAC;AACrB;AAEO,MAAM,gCAEH,6BAAsC;AAAA,EAC9C,YAAY,SAA8C;AACxD,UAAM,OAAO;AAAA,EACf;AAAA,EAEA,oBAA0B;AAAA,EAAC;AAAA,EAC3B,0BAAgC;AAAA,EAAC;AACnC;AAsCO,MAAM,+BAA0D,CACrE;AAAA;AAAA,EAGA,IAAI,uBAAuB,OAAO;AAAA;AAE7B,MAAM,qCACX,CAAU;AAAA;AAAA,EAER,IAAI;AAAA,IACF;AAAA,EAAA;AAAA;AAGC,MAAM,gCAA4D,CAGvE;AAAA;AAAA,EAGA,IAAI;AAAA,IACF;AAAA,EAAA;AAAA;"}
|
package/dist/esm/devtools.d.ts
DELETED
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
import { AnyClientTool, StreamChunk } from '@tanstack/ai/client';
|
|
2
|
-
import { ChatClientEventContext, ChatClientEventEmitter, ChatClientRunEventContext } from './events.js';
|
|
3
|
-
import { ChatClientState, ConnectionStatus, UIMessage } from './types.js';
|
|
4
|
-
export interface AIDevtoolsDisplayOptions {
|
|
5
|
-
name?: string;
|
|
6
|
-
}
|
|
7
|
-
export interface AIDevtoolsClientMetadata extends AIDevtoolsDisplayOptions {
|
|
8
|
-
framework?: string;
|
|
9
|
-
hookName: string;
|
|
10
|
-
outputKind?: 'chat' | 'text' | 'structured' | 'image' | 'video' | 'audio';
|
|
11
|
-
}
|
|
12
|
-
export interface AIDevtoolsGenerationProgress {
|
|
13
|
-
value: number;
|
|
14
|
-
message?: string;
|
|
15
|
-
}
|
|
16
|
-
export interface AIDevtoolsGenerationMediaItem {
|
|
17
|
-
src: string;
|
|
18
|
-
sourceType: 'url' | 'base64';
|
|
19
|
-
mimeType?: string;
|
|
20
|
-
format?: string;
|
|
21
|
-
duration?: number;
|
|
22
|
-
}
|
|
23
|
-
export interface AIDevtoolsGenerationVideoJob {
|
|
24
|
-
jobId: string;
|
|
25
|
-
status?: string;
|
|
26
|
-
progress?: number;
|
|
27
|
-
error?: string;
|
|
28
|
-
}
|
|
29
|
-
export type AIDevtoolsGenerationPreview = {
|
|
30
|
-
kind: 'image';
|
|
31
|
-
items: Array<AIDevtoolsGenerationMediaItem>;
|
|
32
|
-
} | {
|
|
33
|
-
kind: 'audio';
|
|
34
|
-
items: Array<AIDevtoolsGenerationMediaItem>;
|
|
35
|
-
} | {
|
|
36
|
-
kind: 'video';
|
|
37
|
-
items: Array<AIDevtoolsGenerationMediaItem>;
|
|
38
|
-
job?: AIDevtoolsGenerationVideoJob;
|
|
39
|
-
} | {
|
|
40
|
-
kind: 'text';
|
|
41
|
-
text: string;
|
|
42
|
-
} | {
|
|
43
|
-
kind: 'structured';
|
|
44
|
-
value: unknown;
|
|
45
|
-
} | {
|
|
46
|
-
kind: 'empty';
|
|
47
|
-
};
|
|
48
|
-
export type AIDevtoolsGenerationRunStatus = 'idle' | 'generating' | 'success' | 'error' | 'cancelled';
|
|
49
|
-
export interface AIDevtoolsGenerationRunSnapshot<TOutput = unknown> {
|
|
50
|
-
id: string;
|
|
51
|
-
input: unknown;
|
|
52
|
-
result: TOutput | null;
|
|
53
|
-
preview: AIDevtoolsGenerationPreview;
|
|
54
|
-
progress: AIDevtoolsGenerationProgress | null;
|
|
55
|
-
status: AIDevtoolsGenerationRunStatus;
|
|
56
|
-
isLoading: boolean;
|
|
57
|
-
startedAt: number;
|
|
58
|
-
updatedAt: number;
|
|
59
|
-
completedAt?: number;
|
|
60
|
-
error?: string;
|
|
61
|
-
jobId?: string | null;
|
|
62
|
-
videoStatus?: unknown;
|
|
63
|
-
}
|
|
64
|
-
export interface AIDevtoolsGenerationPreviewInput {
|
|
65
|
-
outputKind?: AIDevtoolsClientMetadata['outputKind'];
|
|
66
|
-
result: unknown;
|
|
67
|
-
videoStatus?: unknown;
|
|
68
|
-
}
|
|
69
|
-
export interface AIDevtoolsChatSnapshot {
|
|
70
|
-
[key: string]: unknown;
|
|
71
|
-
messages: Array<UIMessage>;
|
|
72
|
-
status: ChatClientState;
|
|
73
|
-
isLoading: boolean;
|
|
74
|
-
isSubscribed: boolean;
|
|
75
|
-
connectionStatus: ConnectionStatus;
|
|
76
|
-
sessionGenerating: boolean;
|
|
77
|
-
activeRunIds: Array<string>;
|
|
78
|
-
error?: string;
|
|
79
|
-
}
|
|
80
|
-
export declare function createAIDevtoolsGenerationPreview(input: AIDevtoolsGenerationPreviewInput): AIDevtoolsGenerationPreview;
|
|
81
|
-
export interface AIDevtoolsToolFixture {
|
|
82
|
-
fixtureId?: string;
|
|
83
|
-
hookId?: string;
|
|
84
|
-
threadId?: string;
|
|
85
|
-
runId?: string;
|
|
86
|
-
toolName: string;
|
|
87
|
-
input: unknown;
|
|
88
|
-
output: unknown;
|
|
89
|
-
execute?: boolean;
|
|
90
|
-
message?: {
|
|
91
|
-
id: string;
|
|
92
|
-
role: UIMessage['role'];
|
|
93
|
-
parts: Array<unknown>;
|
|
94
|
-
createdAt?: number | string;
|
|
95
|
-
};
|
|
96
|
-
toolCallId?: string;
|
|
97
|
-
messageId?: string;
|
|
98
|
-
errorText?: string;
|
|
99
|
-
}
|
|
100
|
-
type AIDevtoolsRunEventType = 'run:created' | 'run:started' | 'run:updated' | 'run:completed' | 'run:errored' | 'run:cancelled';
|
|
101
|
-
type AIDevtoolsRunStatus = 'created' | 'started' | 'updated' | 'completed' | 'errored' | 'cancelled';
|
|
102
|
-
export interface AIDevtoolsBridgeOptions<TSnapshot extends object> {
|
|
103
|
-
hookId: string;
|
|
104
|
-
threadId?: string;
|
|
105
|
-
clientId: string;
|
|
106
|
-
metadata: AIDevtoolsClientMetadata;
|
|
107
|
-
getSnapshot: () => TSnapshot;
|
|
108
|
-
getTools?: () => Iterable<AnyClientTool>;
|
|
109
|
-
applyToolFixture?: (fixture: AIDevtoolsToolFixture) => void | Promise<void>;
|
|
110
|
-
}
|
|
111
|
-
export declare class ClientDevtoolsBridge<TSnapshot extends object> {
|
|
112
|
-
protected readonly options: AIDevtoolsBridgeOptions<TSnapshot>;
|
|
113
|
-
private readonly bridgeId;
|
|
114
|
-
private readonly unsubscribers;
|
|
115
|
-
private disposed;
|
|
116
|
-
private superseded;
|
|
117
|
-
private registered;
|
|
118
|
-
constructor(options: AIDevtoolsBridgeOptions<TSnapshot>);
|
|
119
|
-
emitRegistered(): void;
|
|
120
|
-
emitUpdated(): void;
|
|
121
|
-
emitSnapshot(): void;
|
|
122
|
-
emitToolsRegistered(): void;
|
|
123
|
-
emitRunLifecycle(eventType: AIDevtoolsRunEventType, runId: string, status: AIDevtoolsRunStatus, options?: {
|
|
124
|
-
error?: string;
|
|
125
|
-
}): void;
|
|
126
|
-
deactivate(): void;
|
|
127
|
-
supersede(): void;
|
|
128
|
-
dispose(): void;
|
|
129
|
-
private prepareForEmit;
|
|
130
|
-
private prepareForMountEmit;
|
|
131
|
-
private activate;
|
|
132
|
-
private handleRequestState;
|
|
133
|
-
private handleToolFixtureApply;
|
|
134
|
-
private matchesFixtureTarget;
|
|
135
|
-
private createEnvelope;
|
|
136
|
-
private createMetadataPayload;
|
|
137
|
-
}
|
|
138
|
-
export interface ChatDevtoolsBridgeOptions extends AIDevtoolsBridgeOptions<AIDevtoolsChatSnapshot> {
|
|
139
|
-
getMessages: () => Array<UIMessage>;
|
|
140
|
-
setMessages: (messages: Array<UIMessage>) => void;
|
|
141
|
-
addToolResult: (toolCallId: string, output: unknown, errorText?: string) => void;
|
|
142
|
-
generateId: (prefix: string) => string;
|
|
143
|
-
}
|
|
144
|
-
export declare class ChatDevtoolsBridge extends ClientDevtoolsBridge<AIDevtoolsChatSnapshot> {
|
|
145
|
-
readonly events: ChatClientEventEmitter;
|
|
146
|
-
private readonly chatOptions;
|
|
147
|
-
private currentRunId;
|
|
148
|
-
private currentRunThreadId;
|
|
149
|
-
private currentStreamId;
|
|
150
|
-
private lastStreamId;
|
|
151
|
-
private lastRunEventContext;
|
|
152
|
-
constructor(options: ChatDevtoolsBridgeOptions);
|
|
153
|
-
setCurrentStreamId(streamId: string | null): void;
|
|
154
|
-
/**
|
|
155
|
-
* Called by the auto-attaching emitter every time it sees a non-empty
|
|
156
|
-
* streamId pass through. Lets devtools track the latest stream id
|
|
157
|
-
* without the chat client wiring it up explicitly.
|
|
158
|
-
*/
|
|
159
|
-
recordStreamId(streamId: string): void;
|
|
160
|
-
mountWithTools(initialMessageCount: number): void;
|
|
161
|
-
notifyToolsChanged(): void;
|
|
162
|
-
getCurrentStreamId(): string | null;
|
|
163
|
-
getLastStreamId(): string | null;
|
|
164
|
-
resolveStreamId(): string;
|
|
165
|
-
beginRun(runId: string, threadId: string): void;
|
|
166
|
-
observeChunk(chunk: StreamChunk): void;
|
|
167
|
-
getCurrentRunEventContext(): ChatClientRunEventContext | undefined;
|
|
168
|
-
getCurrentOrLastRunEventContext(): ChatClientRunEventContext | undefined;
|
|
169
|
-
findToolCallContext(toolCallId: string): ChatClientEventContext;
|
|
170
|
-
/**
|
|
171
|
-
* Entry point invoked when the devtools panel emits
|
|
172
|
-
* `devtools:tool-fixture:apply`. The chat client never calls this
|
|
173
|
-
* directly; it is wired through the base bridge's fixture subscription.
|
|
174
|
-
*/
|
|
175
|
-
applyFixture(fixture: AIDevtoolsToolFixture): Promise<void>;
|
|
176
|
-
private executeFixture;
|
|
177
|
-
private addToolResultForFixture;
|
|
178
|
-
private createReplayMessageFromFixture;
|
|
179
|
-
private cloneFixtureSourceMessage;
|
|
180
|
-
private createFixtureToolCallIdMap;
|
|
181
|
-
private resolveFixtureMessageId;
|
|
182
|
-
private resolveFixtureToolCallId;
|
|
183
|
-
private findClientTool;
|
|
184
|
-
}
|
|
185
|
-
export interface AIDevtoolsGenerationSnapshotBase<TOutput> {
|
|
186
|
-
input: unknown;
|
|
187
|
-
result: TOutput | null;
|
|
188
|
-
preview: AIDevtoolsGenerationPreview;
|
|
189
|
-
progress: AIDevtoolsGenerationProgress | null;
|
|
190
|
-
status: AIDevtoolsGenerationRunStatus;
|
|
191
|
-
isLoading: boolean;
|
|
192
|
-
activeRunId: string | null;
|
|
193
|
-
runs: Array<AIDevtoolsGenerationRunSnapshot<TOutput>>;
|
|
194
|
-
error?: string;
|
|
195
|
-
}
|
|
196
|
-
export interface GenerationDevtoolsBridgeOptions<TOutput> extends Omit<AIDevtoolsBridgeOptions<AIDevtoolsGenerationSnapshotBase<TOutput>>, 'getSnapshot'> {
|
|
197
|
-
getCoreState: () => GenerationDevtoolsCoreState<TOutput>;
|
|
198
|
-
maxRuns?: number;
|
|
199
|
-
}
|
|
200
|
-
export interface GenerationDevtoolsCoreState<TOutput> {
|
|
201
|
-
input: unknown;
|
|
202
|
-
result: TOutput | null;
|
|
203
|
-
progress: AIDevtoolsGenerationProgress | null;
|
|
204
|
-
status: AIDevtoolsGenerationRunStatus;
|
|
205
|
-
isLoading: boolean;
|
|
206
|
-
error?: string;
|
|
207
|
-
}
|
|
208
|
-
export interface GenerationRunPatch<TOutput> {
|
|
209
|
-
input?: unknown;
|
|
210
|
-
result?: TOutput | null;
|
|
211
|
-
preview?: AIDevtoolsGenerationPreview;
|
|
212
|
-
progress?: AIDevtoolsGenerationProgress | null;
|
|
213
|
-
status?: AIDevtoolsGenerationRunStatus;
|
|
214
|
-
isLoading?: boolean;
|
|
215
|
-
completedAt?: number;
|
|
216
|
-
error?: string;
|
|
217
|
-
clearError?: boolean;
|
|
218
|
-
}
|
|
219
|
-
export declare class GenerationDevtoolsBridge<TOutput> extends ClientDevtoolsBridge<AIDevtoolsGenerationSnapshotBase<TOutput>> {
|
|
220
|
-
protected activeRunId: string | null;
|
|
221
|
-
protected activeRunStarted: boolean;
|
|
222
|
-
protected devtoolsRuns: Array<AIDevtoolsGenerationRunSnapshot<TOutput>>;
|
|
223
|
-
protected readonly maxRuns: number;
|
|
224
|
-
protected readonly getCoreState: () => GenerationDevtoolsCoreState<TOutput>;
|
|
225
|
-
constructor(options: GenerationDevtoolsBridgeOptions<TOutput>);
|
|
226
|
-
beginRun(input: unknown): string;
|
|
227
|
-
ensureRunStarted(runId: string): void;
|
|
228
|
-
finishRun(runId: string, eventType: 'run:completed' | 'run:errored' | 'run:cancelled', status: 'completed' | 'errored' | 'cancelled', error?: string): void;
|
|
229
|
-
getActiveRunId(): string | null;
|
|
230
|
-
/** Clear all per-run history. Called when the client `reset()`s. */
|
|
231
|
-
resetRuns(): void;
|
|
232
|
-
/** Record state changes from the client and emit the matching snapshot. */
|
|
233
|
-
recordResultChange(): void;
|
|
234
|
-
recordLoadingChange(): void;
|
|
235
|
-
recordErrorChange(error: Error | undefined): void;
|
|
236
|
-
recordStatusChange(status: AIDevtoolsGenerationRunStatus): void;
|
|
237
|
-
recordProgressChange(): void;
|
|
238
|
-
/** Emit the latest snapshot without touching run state. */
|
|
239
|
-
emitState(): void;
|
|
240
|
-
protected buildSnapshot(): AIDevtoolsGenerationSnapshotBase<TOutput>;
|
|
241
|
-
protected updateActiveRun(patch: GenerationRunPatch<TOutput>): void;
|
|
242
|
-
protected upsertRun(runId: string, patch: GenerationRunPatch<TOutput>): void;
|
|
243
|
-
protected renameRun(previousRunId: string, nextRunId: string): void;
|
|
244
|
-
protected getProgress(): AIDevtoolsGenerationProgress | null;
|
|
245
|
-
protected completeProgress(): AIDevtoolsGenerationProgress | null;
|
|
246
|
-
protected createPreview(result: TOutput | null): AIDevtoolsGenerationPreview;
|
|
247
|
-
protected generateRunId(): string;
|
|
248
|
-
}
|
|
249
|
-
export interface AIDevtoolsVideoSnapshotBase<TOutput> extends AIDevtoolsGenerationSnapshotBase<TOutput> {
|
|
250
|
-
jobId: string | null;
|
|
251
|
-
videoStatus: unknown;
|
|
252
|
-
}
|
|
253
|
-
export interface VideoDevtoolsCoreState<TOutput> extends GenerationDevtoolsCoreState<TOutput> {
|
|
254
|
-
jobId: string | null;
|
|
255
|
-
videoStatus: unknown;
|
|
256
|
-
}
|
|
257
|
-
export interface VideoDevtoolsBridgeOptions<TOutput> extends Omit<GenerationDevtoolsBridgeOptions<TOutput>, 'getCoreState'> {
|
|
258
|
-
getCoreState: () => VideoDevtoolsCoreState<TOutput>;
|
|
259
|
-
}
|
|
260
|
-
export interface VideoRunPatch<TOutput> extends GenerationRunPatch<TOutput> {
|
|
261
|
-
jobId?: string | null;
|
|
262
|
-
videoStatus?: unknown;
|
|
263
|
-
}
|
|
264
|
-
export declare class VideoDevtoolsBridge<TOutput> extends GenerationDevtoolsBridge<TOutput> {
|
|
265
|
-
constructor(options: VideoDevtoolsBridgeOptions<TOutput>);
|
|
266
|
-
recordJobIdChange(): void;
|
|
267
|
-
recordVideoStatusChange(): void;
|
|
268
|
-
protected buildSnapshot(): AIDevtoolsVideoSnapshotBase<TOutput>;
|
|
269
|
-
protected upsertRun(runId: string, patch: VideoRunPatch<TOutput>): void;
|
|
270
|
-
protected createPreview(result: TOutput | null): AIDevtoolsGenerationPreview;
|
|
271
|
-
private createVideoPreview;
|
|
272
|
-
}
|
|
273
|
-
export declare function createChatDevtoolsBridge(options: ChatDevtoolsBridgeOptions): ChatDevtoolsBridge;
|
|
274
|
-
export declare function createGenerationDevtoolsBridge<TOutput>(options: GenerationDevtoolsBridgeOptions<TOutput>): GenerationDevtoolsBridge<TOutput>;
|
|
275
|
-
export declare function createVideoDevtoolsBridge<TOutput>(options: VideoDevtoolsBridgeOptions<TOutput>): VideoDevtoolsBridge<TOutput>;
|
|
276
|
-
export {};
|