@tanstack/ai-client 0.12.0 → 0.14.0

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.
Files changed (59) hide show
  1. package/dist/esm/chat-client.d.ts +16 -2
  2. package/dist/esm/chat-client.js +197 -31
  3. package/dist/esm/chat-client.js.map +1 -1
  4. package/dist/esm/connection-adapters.d.ts +21 -1
  5. package/dist/esm/connection-adapters.js +262 -68
  6. package/dist/esm/connection-adapters.js.map +1 -1
  7. package/dist/esm/devtools-noop.d.ts +60 -0
  8. package/dist/esm/devtools-noop.js +135 -0
  9. package/dist/esm/devtools-noop.js.map +1 -0
  10. package/dist/esm/devtools.d.ts +276 -0
  11. package/dist/esm/devtools.js +1178 -0
  12. package/dist/esm/devtools.js.map +1 -0
  13. package/dist/esm/events.d.ts +51 -8
  14. package/dist/esm/events.js +65 -20
  15. package/dist/esm/events.js.map +1 -1
  16. package/dist/esm/generation-client.d.ts +14 -0
  17. package/dist/esm/generation-client.js +135 -5
  18. package/dist/esm/generation-client.js.map +1 -1
  19. package/dist/esm/generation-types.d.ts +16 -2
  20. package/dist/esm/generation-types.js.map +1 -1
  21. package/dist/esm/index.d.ts +6 -4
  22. package/dist/esm/index.js +9 -3
  23. package/dist/esm/index.js.map +1 -1
  24. package/dist/esm/realtime-client.d.ts +1 -1
  25. package/dist/esm/realtime-client.js +1 -1
  26. package/dist/esm/realtime-client.js.map +1 -1
  27. package/dist/esm/realtime-types.d.ts +1 -1
  28. package/dist/esm/response-stream.d.ts +7 -0
  29. package/dist/esm/response-stream.js +32 -0
  30. package/dist/esm/response-stream.js.map +1 -0
  31. package/dist/esm/sse-parser.d.ts +1 -1
  32. package/dist/esm/sse-parser.js +5 -6
  33. package/dist/esm/sse-parser.js.map +1 -1
  34. package/dist/esm/sse-utils.d.ts +1 -0
  35. package/dist/esm/sse-utils.js +11 -0
  36. package/dist/esm/sse-utils.js.map +1 -0
  37. package/dist/esm/tool-types.d.ts +1 -1
  38. package/dist/esm/types.d.ts +23 -5
  39. package/dist/esm/types.js.map +1 -1
  40. package/dist/esm/video-generation-client.d.ts +15 -0
  41. package/dist/esm/video-generation-client.js +147 -8
  42. package/dist/esm/video-generation-client.js.map +1 -1
  43. package/package.json +7 -3
  44. package/src/chat-client.ts +250 -33
  45. package/src/connection-adapters.ts +360 -68
  46. package/src/devtools-noop.ts +205 -0
  47. package/src/devtools.ts +1866 -0
  48. package/src/events.ts +143 -12
  49. package/src/generation-client.ts +177 -10
  50. package/src/generation-types.ts +24 -5
  51. package/src/index.ts +16 -3
  52. package/src/realtime-client.ts +2 -2
  53. package/src/realtime-types.ts +1 -1
  54. package/src/response-stream.ts +42 -0
  55. package/src/sse-parser.ts +9 -7
  56. package/src/sse-utils.ts +8 -0
  57. package/src/tool-types.ts +1 -1
  58. package/src/types.ts +31 -4
  59. package/src/video-generation-client.ts +187 -12
@@ -0,0 +1,135 @@
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
+ setCurrentStreamId(_streamId) {
30
+ }
31
+ getCurrentStreamId() {
32
+ return null;
33
+ }
34
+ getLastStreamId() {
35
+ return null;
36
+ }
37
+ resolveStreamId() {
38
+ return "";
39
+ }
40
+ observeChunk(_chunk) {
41
+ }
42
+ beginRun(_runId, _threadId) {
43
+ }
44
+ getCurrentRunEventContext() {
45
+ return void 0;
46
+ }
47
+ getCurrentOrLastRunEventContext() {
48
+ return void 0;
49
+ }
50
+ findToolCallContext(toolCallId) {
51
+ return { toolCallId };
52
+ }
53
+ async applyFixture(_fixture) {
54
+ }
55
+ }
56
+ class NoOpGenerationDevtoolsBridge {
57
+ constructor(_options) {
58
+ }
59
+ // base bridge surface
60
+ emitRegistered() {
61
+ }
62
+ emitUpdated() {
63
+ }
64
+ emitSnapshot() {
65
+ }
66
+ emitToolsRegistered() {
67
+ }
68
+ emitRunLifecycle() {
69
+ }
70
+ deactivate() {
71
+ }
72
+ supersede() {
73
+ }
74
+ dispose() {
75
+ }
76
+ // generation-specific surface
77
+ beginRun(_input) {
78
+ return `noop-run-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
79
+ }
80
+ ensureRunStarted(_runId) {
81
+ }
82
+ finishRun(_runId, _eventType, _status, _error) {
83
+ }
84
+ getActiveRunId() {
85
+ return null;
86
+ }
87
+ resetRuns() {
88
+ }
89
+ recordResultChange() {
90
+ }
91
+ recordLoadingChange() {
92
+ }
93
+ recordErrorChange(_error) {
94
+ }
95
+ recordStatusChange() {
96
+ }
97
+ recordProgressChange() {
98
+ }
99
+ emitState() {
100
+ }
101
+ }
102
+ class NoOpVideoDevtoolsBridge extends NoOpGenerationDevtoolsBridge {
103
+ constructor(options) {
104
+ super(options);
105
+ }
106
+ recordJobIdChange() {
107
+ }
108
+ recordVideoStatusChange() {
109
+ }
110
+ }
111
+ const createNoOpChatDevtoolsBridge = (options) => (
112
+ // eslint-disable-next-line no-restricted-syntax -- see comment above
113
+ new NoOpChatDevtoolsBridge(options)
114
+ );
115
+ const createNoOpGenerationDevtoolsBridge = (options) => (
116
+ // eslint-disable-next-line no-restricted-syntax -- see comment above
117
+ new NoOpGenerationDevtoolsBridge(
118
+ options
119
+ )
120
+ );
121
+ const createNoOpVideoDevtoolsBridge = (options) => (
122
+ // eslint-disable-next-line no-restricted-syntax -- see comment above
123
+ new NoOpVideoDevtoolsBridge(
124
+ options
125
+ )
126
+ );
127
+ export {
128
+ NoOpChatDevtoolsBridge,
129
+ NoOpGenerationDevtoolsBridge,
130
+ NoOpVideoDevtoolsBridge,
131
+ createNoOpChatDevtoolsBridge,
132
+ createNoOpGenerationDevtoolsBridge,
133
+ createNoOpVideoDevtoolsBridge
134
+ };
135
+ //# sourceMappingURL=devtools-noop.js.map
@@ -0,0 +1 @@
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 setCurrentStreamId(_streamId: string | null): 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<...>` will resolve to a non-`never` union and the `as never`\n// assignment below will fail to typecheck — surfacing the drift at build\n// time instead of as a runtime TypeError later.\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 _chatBridgeParity: _ChatBridgeMissing = undefined as never\nconst _generationBridgeParity: _GenerationBridgeMissing = undefined as never\nconst _videoBridgeParity: _VideoBridgeMissing = undefined as never\nvoid _chatBridgeParity\nvoid _generationBridgeParity\nvoid _videoBridgeParity\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,mBAAmB,WAAgC;AAAA,EAAC;AAAA,EACpD,qBAAoC;AAClC,WAAO;AAAA,EACT;AAAA,EACA,kBAAiC;AAC/B,WAAO;AAAA,EACT;AAAA,EACA,kBAA0B;AACxB,WAAO;AAAA,EACT;AAAA,EACA,aAAa,QAA2B;AAAA,EAAC;AAAA,EACzC,SAAS,QAAgB,WAAyB;AAAA,EAAC;AAAA,EACnD,4BAAmE;AACjE,WAAO;AAAA,EACT;AAAA,EACA,kCAAyE;AACvE,WAAO;AAAA,EACT;AAAA,EACA,oBAAoB,YAA4C;AAC9D,WAAO,EAAE,WAAA;AAAA,EACX;AAAA,EACA,MAAM,aAAa,UAAgD;AAAA,EAEnE;AACF;AAEO,MAAM,6BAAsC;AAAA,EACjD,YAAY,UAAoD;AAAA,EAAC;AAAA;AAAA,EAGjE,iBAAuB;AAAA,EAAC;AAAA,EACxB,cAAoB;AAAA,EAAC;AAAA,EACrB,eAAqB;AAAA,EAAC;AAAA,EACtB,sBAA4B;AAAA,EAAC;AAAA,EAC7B,mBAAyB;AAAA,EAAC;AAAA,EAC1B,aAAmB;AAAA,EAAC;AAAA,EACpB,YAAkB;AAAA,EAAC;AAAA,EACnB,UAAgB;AAAA,EAAC;AAAA;AAAA,EAGjB,SAAS,QAAyB;AAIhC,WAAO,YAAY,KAAK,IAAA,CAAK,IAAI,KAAK,OAAA,EAAS,SAAS,EAAE,EAAE,MAAM,GAAG,CAAC,CAAC;AAAA,EACzE;AAAA,EACA,iBAAiB,QAAsB;AAAA,EAAC;AAAA,EACxC,UACE,QACA,YACA,SACA,QACM;AAAA,EAAC;AAAA,EACT,iBAAgC;AAC9B,WAAO;AAAA,EACT;AAAA,EACA,YAAkB;AAAA,EAAC;AAAA,EACnB,qBAA2B;AAAA,EAAC;AAAA,EAC5B,sBAA4B;AAAA,EAAC;AAAA,EAC7B,kBAAkB,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;AAmCO,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;"}
@@ -0,0 +1,276 @@
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 {};