Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

generation-devtools.test.ts

923 lines23.5 KB

1import { beforeEach, describe, expect, it, vi } from 'vitest'
2import { aiEventClient } from '@tanstack/ai-event-client'
3import { EventType } from '@tanstack/ai'
4import { createAIDevtoolsGenerationPreview } from '../src/devtools'
5import { GenerationClient } from '../src/generation-client'
6import { VideoGenerationClient } from '../src/video-generation-client'
7import type { StreamChunk } from '@tanstack/ai'
8import type { ConnectConnectionAdapter } from '../src/connection-adapters'
9​
10interface DevtoolsEvent<TPayload = unknown> {
11 type: string
12 payload: TPayload
13 pluginId?: string
15​
16type DevtoolsEventCallback = (event: DevtoolsEvent) => void
17​
18const eventClientMock = vi.hoisted(() => {
19 const listeners = new Map<string, Array<DevtoolsEventCallback>>()
20 const unsubscribe = vi.fn()
21​
22 return {
23 emit: vi.fn(),
24 emitAIDevtoolsEvent: vi.fn((eventName: string, payload: unknown) => {
25 eventClientMock.emit(eventName, payload)
26 }),
27 unsubscribe,
28 on: vi.fn((eventName: string, callback: DevtoolsEventCallback) => {
29 const currentListeners = listeners.get(eventName) ?? []
30 currentListeners.push(callback)
31 listeners.set(eventName, currentListeners)
32​
33 return () => {
34 unsubscribe()
35 const nextListeners = (listeners.get(eventName) ?? []).filter(
36 (listener) => listener !== callback,
37 )
38 listeners.set(eventName, nextListeners)
39 }
40 }),
41 dispatch(eventName: string, payload: unknown) {
42 for (const listener of listeners.get(eventName) ?? []) {
43 listener({
44 type: `tanstack-ai-devtools:${eventName}`,
45 payload,
46 pluginId: 'tanstack-ai-devtools',
47 })
48 }
49 },
50 emitted(eventName: string) {
51 return eventClientMock.emit.mock.calls.filter(
52 ([name]) => name === eventName,
53 )
54 },
55 reset() {
56 listeners.clear()
57 unsubscribe.mockClear()
58 },
59 }
60})
61​
62vi.mock('@tanstack/ai-event-client', () => ({
63 aiEventClient: {
64 emit: eventClientMock.emit,
65 on: eventClientMock.on,
66 },
67 emitAIDevtoolsEvent: eventClientMock.emitAIDevtoolsEvent,
68 createAIDevtoolsEventEnvelope: (input: {
69 eventType: string
70 timestamp: number
71 }) => ({
72 ...input,
73 eventId: `event:${input.eventType}:${input.timestamp}`,
74 }),
75}))
76​
77describe('generation client devtools bridge', () => {
78 beforeEach(() => {
79 vi.clearAllMocks()
80 eventClientMock.reset()
81 })
82​
83 function resultChunk(value: unknown) {
84 return {
85 type: EventType.CUSTOM,
86 name: 'generation:result',
87 value,
88 timestamp: Date.now(),
89 } satisfies StreamChunk
90 }
91​
92 function runStartedChunk(runId: string) {
93 return {
94 type: EventType.RUN_STARTED,
95 runId,
96 threadId: 'thread-1',
97 timestamp: Date.now(),
98 } satisfies StreamChunk
99 }
100​
101 function runFinishedChunk(runId: string) {
102 return {
103 type: EventType.RUN_FINISHED,
104 runId,
105 threadId: 'thread-1',
106 timestamp: Date.now(),
107 finishReason: 'stop',
108 } satisfies StreamChunk
109 }
110​
111 function createDeferred<T>() {
112 let resolve!: (value: T) => void
113 const promise = new Promise<T>((nextResolve) => {
114 resolve = nextResolve
115 })
116 return { promise, resolve }
117 }
118​
119 function latestSnapshotState() {
120 const snapshot = eventClientMock.emitted('hook:state-snapshot').at(-1)?.[1]
121 if (!isSnapshotStatePayload(snapshot)) {
122 throw new Error('Expected a hook state snapshot payload')
123 }
124 return snapshot.state
125 }
126​
127 function latestGenerationRuns() {
128 const runs = latestSnapshotState().runs
129 if (!Array.isArray(runs)) {
130 throw new Error('Expected generation snapshot runs')
131 }
132 return runs
133 }
134​
135 function isSnapshotStatePayload(
136 value: unknown,
137 ): value is { state: Record<string, unknown> } {
138 return Boolean(
139 value &&
140 typeof value === 'object' &&
141 'state' in value &&
142 value.state &&
143 typeof value.state === 'object' &&
144 !Array.isArray(value.state),
145 )
146 }
147​
148 it('normalizes generation results into renderable devtools previews', () => {
149 expect(
150 createAIDevtoolsGenerationPreview({
151 outputKind: 'image',
152 result: {
153 id: 'img-1',
154 model: 'image-model',
155 images: [
156 { url: 'https://example.com/image.png' },
157 { b64Json: 'iVBORw0KGgo=' },
158 ],
159 },
160 }),
161 ).toEqual({
162 kind: 'image',
163 items: [
164 {
165 src: 'https://example.com/image.png',
166 sourceType: 'url',
167 },
168 {
169 src: 'data:image/png;base64,iVBORw0KGgo=',
170 sourceType: 'base64',
171 mimeType: 'image/png',
172 },
173 ],
174 })
175​
176 expect(
177 createAIDevtoolsGenerationPreview({
178 outputKind: 'audio',
179 result: {
180 id: 'speech-1',
181 model: 'tts-model',
182 audio: 'UklGRg==',
183 format: 'wav',
184 contentType: 'audio/wav',
185 },
186 }),
187 ).toEqual({
188 kind: 'audio',
189 items: [
190 {
191 src: 'data:audio/wav;base64,UklGRg==',
192 sourceType: 'base64',
193 mimeType: 'audio/wav',
194 format: 'wav',
195 },
196 ],
197 })
198​
199 expect(
200 createAIDevtoolsGenerationPreview({
201 outputKind: 'text',
202 result: {
203 id: 'transcription-1',
204 model: 'whisper',
205 text: 'Hello world',
206 },
207 }),
208 ).toEqual({
209 kind: 'text',
210 text: 'Hello world',
211 })
212​
213 expect(
214 createAIDevtoolsGenerationPreview({
215 outputKind: 'video',
216 result: null,
217 videoStatus: {
218 jobId: 'job-1',
219 status: 'processing',
220 progress: 50,
221 url: 'https://example.com/video.mp4',
222 },
223 }),
224 ).toEqual({
225 kind: 'video',
226 items: [
227 {
228 src: 'https://example.com/video.mp4',
229 sourceType: 'url',
230 },
231 ],
232 job: {
233 jobId: 'job-1',
234 status: 'processing',
235 progress: 50,
236 },
237 })
238 })
239​
240 it('registers a generation hook and emits run lifecycle for fetcher mode', async () => {
241 const client = new GenerationClient({
242 id: 'gen-1',
243 fetcher: async () => ({ text: 'done' }),
244 devtools: {
245 framework: 'react',
246 hookName: 'useGenerateObject',
247 outputKind: 'structured',
248 },
249 })
250 vi.clearAllMocks()
251​
252 await client.generate({ prompt: 'make object' })
253​
254 expect(aiEventClient.emit).toHaveBeenCalledWith(
255 'run:started',
256 expect.objectContaining({
257 hookId: 'gen-1',
258 source: 'client',
259 visibility: 'client-state',
260 runId: expect.any(String),
261 status: 'started',
262 }),
263 )
264 expect(aiEventClient.emit).toHaveBeenCalledWith(
265 'run:completed',
266 expect.objectContaining({
267 hookId: 'gen-1',
268 source: 'client',
269 visibility: 'client-state',
270 runId: expect.any(String),
271 status: 'completed',
272 }),
273 )
274 expect(aiEventClient.emit).toHaveBeenCalledWith(
275 'hook:state-snapshot',
276 expect.objectContaining({
277 hookId: 'gen-1',
278 hookName: 'useGenerateObject',
279 framework: 'react',
280 outputKind: 'structured',
281 state: expect.objectContaining({
282 status: 'success',
283 isLoading: false,
284 result: { text: 'done' },
285 }),
286 }),
287 )
288​
289 client.dispose()
290 })
291​
292 it('includes input, progress, and renderable previews in generation snapshots', async () => {
293 const client = new GenerationClient({
294 id: 'image-hook',
295 fetcher: async () => ({
296 id: 'img-1',
297 model: 'image-model',
298 images: [
299 { url: 'https://example.com/image.png' },
300 { b64Json: 'iVBORw0KGgo=' },
301 ],
302 }),
303 devtools: {
304 framework: 'react',
305 hookName: 'useGenerateImage',
306 outputKind: 'image',
307 },
308 })
309 vi.clearAllMocks()
310​
311 await client.generate({ prompt: 'A quiet desk', numberOfImages: 2 })
312​
313 expect(latestSnapshotState()).toEqual(
314 expect.objectContaining({
315 input: { prompt: 'A quiet desk', numberOfImages: 2 },
316 progress: null,
317 preview: {
318 kind: 'image',
319 items: [
320 {
321 src: 'https://example.com/image.png',
322 sourceType: 'url',
323 },
324 {
325 src: 'data:image/png;base64,iVBORw0KGgo=',
326 sourceType: 'base64',
327 mimeType: 'image/png',
328 },
329 ],
330 },
331 }),
332 )
333​
334 client.dispose()
335 })
336​
337 it('tracks streamed progress in generation snapshots', async () => {
338 const connect: ConnectConnectionAdapter['connect'] = async function* () {
339 yield runStartedChunk('run-progress')
340 yield {
341 type: EventType.CUSTOM,
342 name: 'generation:progress',
343 value: { progress: 40, message: 'Rendering preview' },
344 timestamp: Date.now(),
345 } satisfies StreamChunk
346 yield resultChunk({ summary: 'short version' })
347 yield runFinishedChunk('run-progress')
348 }
349​
350 const client = new GenerationClient({
351 id: 'summary-hook',
352 connection: { connect },
353 devtools: {
354 hookName: 'useSummarize',
355 outputKind: 'text',
356 },
357 })
358 vi.clearAllMocks()
359​
360 await client.generate({ text: 'Long text' })
361​
362 expect(latestSnapshotState()).toEqual(
363 expect.objectContaining({
364 input: { text: 'Long text' },
365 progress: {
366 value: 100,
367 message: 'Rendering preview',
368 },
369 preview: {
370 kind: 'text',
371 text: 'short version',
372 },
373 }),
374 )
375​
376 client.dispose()
377 })
378​
379 it('retains grouped generation snapshots for previous runs', async () => {
380 const connect: ConnectConnectionAdapter['connect'] = async function* (
381 _messages,
382 data,
383 ) {
384 const prompt = typeof data?.prompt === 'string' ? data.prompt : 'unknown'
385 const runId = `run-${prompt}`
386 yield runStartedChunk(runId)
387 yield {
388 type: EventType.CUSTOM,
389 name: 'generation:progress',
390 value: { progress: 70, message: `Rendering ${prompt}` },
391 timestamp: Date.now(),
392 } satisfies StreamChunk
393 yield resultChunk({
394 id: `img-${prompt}`,
395 model: 'image-model',
396 images: [{ url: `https://example.com/${prompt}.png` }],
397 })
398 yield runFinishedChunk(runId)
399 }
400​
401 const client = new GenerationClient({
402 id: 'image-history',
403 connection: { connect },
404 devtools: {
405 hookName: 'useGenerateImage',
406 outputKind: 'image',
407 },
408 })
409 vi.clearAllMocks()
410​
411 await client.generate({ prompt: 'one' })
412 await client.generate({ prompt: 'two' })
413​
414 expect(latestGenerationRuns()).toEqual([
415 expect.objectContaining({
416 id: 'run-one',
417 input: { prompt: 'one' },
418 status: 'success',
419 isLoading: false,
420 progress: {
421 value: 100,
422 message: 'Rendering one',
423 },
424 result: expect.objectContaining({
425 id: 'img-one',
426 }),
427 preview: {
428 kind: 'image',
429 items: [
430 {
431 src: 'https://example.com/one.png',
432 sourceType: 'url',
433 },
434 ],
435 },
436 }),
437 expect.objectContaining({
438 id: 'run-two',
439 input: { prompt: 'two' },
440 status: 'success',
441 isLoading: false,
442 progress: {
443 value: 100,
444 message: 'Rendering two',
445 },
446 result: expect.objectContaining({
447 id: 'img-two',
448 }),
449 preview: {
450 kind: 'image',
451 items: [
452 {
453 src: 'https://example.com/two.png',
454 sourceType: 'url',
455 },
456 ],
457 },
458 }),
459 ])
460​
461 client.dispose()
462 })
463​
464 it('responds to devtools state requests for a generation hook', async () => {
465 const client = new GenerationClient({
466 id: 'gen-1',
467 fetcher: async () => ({ text: 'done' }),
468 devtools: {
469 framework: 'react',
470 hookName: 'useGenerateText',
471 outputKind: 'text',
472 },
473 })
474 client.mountDevtools()
475 vi.clearAllMocks()
476​
477 eventClientMock.dispatch('devtools:request-state', {
478 targetHookId: 'gen-1',
479 })
480​
481 expect(aiEventClient.emit).toHaveBeenCalledWith(
482 'hook:registered',
483 expect.objectContaining({
484 hookId: 'gen-1',
485 hookName: 'useGenerateText',
486 framework: 'react',
487 outputKind: 'text',
488 }),
489 )
490 expect(aiEventClient.emit).toHaveBeenCalledWith(
491 'hook:state-snapshot',
492 expect.objectContaining({
493 hookId: 'gen-1',
494 state: expect.objectContaining({
495 status: 'idle',
496 isLoading: false,
497 result: null,
498 activeRunId: null,
499 }),
500 }),
501 )
502​
503 client.dispose()
504 })
505​
506 it('emits errored run lifecycle for generation failures', async () => {
507 const client = new GenerationClient({
508 id: 'gen-1',
509 fetcher: async () => {
510 throw new Error('Generation failed')
511 },
512 devtools: {
513 hookName: 'useGenerateObject',
514 outputKind: 'structured',
515 },
516 })
517 vi.clearAllMocks()
518​
519 await client.generate({ prompt: 'fail' })
520​
521 expect(aiEventClient.emit).toHaveBeenCalledWith(
522 'run:errored',
523 expect.objectContaining({
524 hookId: 'gen-1',
525 runId: expect.any(String),
526 status: 'errored',
527 error: 'Generation failed',
528 }),
529 )
530 expect(aiEventClient.emit).toHaveBeenCalledWith(
531 'hook:state-snapshot',
532 expect.objectContaining({
533 hookId: 'gen-1',
534 state: expect.objectContaining({
535 status: 'error',
536 isLoading: false,
537 error: 'Generation failed',
538 }),
539 }),
540 )
541​
542 client.dispose()
543 })
544​
545 it('registers a generation hook for streaming connection mode', async () => {
546 const connect: ConnectConnectionAdapter['connect'] = async function* (
547 _messages,
548 _data,
549 _signal,
550 ) {
551 yield runStartedChunk('server-run-1')
552 yield resultChunk({ text: 'streamed' })
553 yield runFinishedChunk('server-run-1')
554 }
555 const connectSpy = vi.fn(connect)
556​
557 const client = new GenerationClient({
558 id: 'gen-stream',
559 connection: {
560 connect: connectSpy,
561 },
562 devtools: {
563 hookName: 'useGenerateText',
564 outputKind: 'text',
565 },
566 })
567 vi.clearAllMocks()
568​
569 await client.generate({ prompt: 'stream' })
570 const runContext = connectSpy.mock.calls[0]?.[3]
571​
572 expect(runContext).toEqual(
573 expect.objectContaining({
574 threadId: 'gen-stream',
575 runId: expect.any(String),
576 }),
577 )
578​
579 expect(aiEventClient.emit).toHaveBeenCalledWith(
580 'run:started',
581 expect.objectContaining({
582 hookId: 'gen-stream',
583 runId: 'server-run-1',
584 }),
585 )
586 expect(aiEventClient.emit).not.toHaveBeenCalledWith(
587 'run:started',
588 expect.objectContaining({
589 hookId: 'gen-stream',
590 runId: runContext?.runId,
591 }),
592 )
593 expect(eventClientMock.emitted('run:started')).toHaveLength(1)
594 expect(aiEventClient.emit).toHaveBeenCalledWith(
595 'run:completed',
596 expect.objectContaining({
597 hookId: 'gen-stream',
598 runId: 'server-run-1',
599 }),
600 )
601 expect(aiEventClient.emit).toHaveBeenCalledWith(
602 'hook:state-snapshot',
603 expect.objectContaining({
604 hookId: 'gen-stream',
605 state: expect.objectContaining({
606 status: 'success',
607 isLoading: false,
608 result: { text: 'streamed' },
609 }),
610 }),
611 )
612​
613 client.dispose()
614 })
615​
616 it('does not emit hook updates after disposal', async () => {
617 const deferred = createDeferred<{ text: string }>()
618 const client = new GenerationClient({
619 id: 'gen-1',
620 fetcher: async () => deferred.promise,
621 devtools: {
622 hookName: 'useGenerateText',
623 outputKind: 'text',
624 },
625 })
626 const generatePromise = client.generate({ prompt: 'slow' })
627 await Promise.resolve()
628​
629 client.dispose()
630 const unregisteredIndex = eventClientMock.emit.mock.calls.findIndex(
631 ([eventName]) => eventName === 'hook:unregistered',
632 )
633 deferred.resolve({ text: 'late' })
634 await generatePromise
635​
636 expect(unregisteredIndex).toBeGreaterThanOrEqual(0)
637 const emittedAfterDispose = eventClientMock.emit.mock.calls
638 .slice(unregisteredIndex + 1)
639 .map(([eventName]) => eventName)
640 expect(emittedAfterDispose).not.toContain('hook:updated')
641 expect(emittedAfterDispose).not.toContain('hook:state-snapshot')
642 })
643​
644 it('uses the stream run id for video connection lifecycle events', async () => {
645 const connect: ConnectConnectionAdapter['connect'] = async function* (
646 _messages,
647 _data,
648 _signal,
649 ) {
650 yield runStartedChunk('server-video-run-1')
651 yield {
652 type: EventType.CUSTOM,
653 name: 'generation:result',
654 value: {
655 jobId: 'job-1',
656 status: 'completed',
657 url: 'https://example.com/video.mp4',
658 },
659 timestamp: Date.now(),
660 } satisfies StreamChunk
661 yield runFinishedChunk('server-video-run-1')
662 }
663 const connectSpy = vi.fn(connect)
664​
665 const client = new VideoGenerationClient({
666 id: 'video-stream',
667 connection: {
668 connect: connectSpy,
669 },
670 devtools: {
671 hookName: 'useGenerateVideo',
672 outputKind: 'video',
673 },
674 })
675 vi.clearAllMocks()
676​
677 await client.generate({ prompt: 'stream video' })
678 const runId = connectSpy.mock.calls[0]?.[3]?.runId ?? 'missing-run'
679​
680 expect(aiEventClient.emit).not.toHaveBeenCalledWith(
681 'run:started',
682 expect.objectContaining({
683 hookId: 'video-stream',
684 runId,
685 }),
686 )
687 expect(eventClientMock.emitted('run:started')).toHaveLength(1)
688 expect(aiEventClient.emit).toHaveBeenCalledWith(
689 'run:completed',
690 expect.objectContaining({
691 hookId: 'video-stream',
692 runId: 'server-video-run-1',
693 }),
694 )
695​
696 client.dispose()
697 })
698​
699 it('registers a video hook and includes job state in snapshots', async () => {
700 const client = new VideoGenerationClient({
701 id: 'video-1',
702 fetcher: async () => ({
703 jobId: 'job-1',
704 status: 'completed',
705 url: 'https://example.com/video.mp4',
706 }),
707 devtools: {
708 framework: 'react',
709 hookName: 'useGenerateVideo',
710 outputKind: 'video',
711 },
712 })
713​
714 await client.generate({ prompt: 'make video' })
715​
716 expect(aiEventClient.emit).toHaveBeenCalledWith(
717 'hook:registered',
718 expect.objectContaining({
719 hookId: 'video-1',
720 hookName: 'useGenerateVideo',
721 framework: 'react',
722 outputKind: 'video',
723 }),
724 )
725 expect(aiEventClient.emit).toHaveBeenCalledWith(
726 'run:completed',
727 expect.objectContaining({
728 hookId: 'video-1',
729 status: 'completed',
730 }),
731 )
732 expect(aiEventClient.emit).toHaveBeenCalledWith(
733 'hook:state-snapshot',
734 expect.objectContaining({
735 hookId: 'video-1',
736 state: expect.objectContaining({
737 status: 'success',
738 isLoading: false,
739 jobId: 'job-1',
740 result: expect.objectContaining({
741 url: 'https://example.com/video.mp4',
742 }),
743 }),
744 }),
745 )
746​
747 client.dispose()
748 })
749​
750 it('includes input, progress, and renderable previews in video snapshots', async () => {
751 const connect: ConnectConnectionAdapter['connect'] = async function* () {
752 yield runStartedChunk('video-run')
753 yield {
754 type: EventType.CUSTOM,
755 name: 'video:job:created',
756 value: { jobId: 'job-1' },
757 timestamp: Date.now(),
758 } satisfies StreamChunk
759 yield {
760 type: EventType.CUSTOM,
761 name: 'video:status',
762 value: {
763 jobId: 'job-1',
764 status: 'processing',
765 progress: 60,
766 url: 'https://example.com/preview.mp4',
767 },
768 timestamp: Date.now(),
769 } satisfies StreamChunk
770 yield {
771 type: EventType.CUSTOM,
772 name: 'generation:result',
773 value: {
774 jobId: 'job-1',
775 status: 'completed',
776 url: 'https://example.com/final.mp4',
777 },
778 timestamp: Date.now(),
779 } satisfies StreamChunk
780 yield runFinishedChunk('video-run')
781 }
782​
783 const client = new VideoGenerationClient({
784 id: 'video-hook',
785 connection: { connect },
786 devtools: {
787 hookName: 'useGenerateVideo',
788 outputKind: 'video',
789 },
790 })
791 vi.clearAllMocks()
792​
793 await client.generate({ prompt: 'A flying car', duration: 4 })
794​
795 expect(latestSnapshotState()).toEqual(
796 expect.objectContaining({
797 input: { prompt: 'A flying car', duration: 4 },
798 progress: {
799 value: 100,
800 },
801 preview: {
802 kind: 'video',
803 items: [
804 {
805 src: 'https://example.com/final.mp4',
806 sourceType: 'url',
807 },
808 ],
809 job: {
810 jobId: 'job-1',
811 status: 'completed',
812 progress: 100,
813 },
814 },
815 }),
816 )
817​
818 client.dispose()
819 })
820​
821 it('retains grouped video generation snapshots for previous runs', async () => {
822 const connect: ConnectConnectionAdapter['connect'] = async function* (
823 _messages,
824 data,
825 ) {
826 const prompt = typeof data?.prompt === 'string' ? data.prompt : 'unknown'
827 const runId = `video-run-${prompt}`
828 const jobId = `job-${prompt}`
829 yield runStartedChunk(runId)
830 yield {
831 type: EventType.CUSTOM,
832 name: 'video:job:created',
833 value: { jobId },
834 timestamp: Date.now(),
835 } satisfies StreamChunk
836 yield {
837 type: EventType.CUSTOM,
838 name: 'video:status',
839 value: {
840 jobId,
841 status: 'processing',
842 progress: 70,
843 },
844 timestamp: Date.now(),
845 } satisfies StreamChunk
846 yield {
847 type: EventType.CUSTOM,
848 name: 'generation:result',
849 value: {
850 jobId,
851 status: 'completed',
852 url: `https://example.com/${prompt}.mp4`,
853 },
854 timestamp: Date.now(),
855 } satisfies StreamChunk
856 yield runFinishedChunk(runId)
857 }
858​
859 const client = new VideoGenerationClient({
860 id: 'video-history',
861 connection: { connect },
862 devtools: {
863 hookName: 'useGenerateVideo',
864 outputKind: 'video',
865 },
866 })
867 vi.clearAllMocks()
868​
869 await client.generate({ prompt: 'one' })
870 await client.generate({ prompt: 'two' })
871​
872 expect(latestGenerationRuns()).toEqual([
873 expect.objectContaining({
874 id: 'video-run-one',
875 input: { prompt: 'one' },
876 status: 'success',
877 isLoading: false,
878 progress: {
879 value: 100,
880 },
881 jobId: 'job-one',
882 videoStatus: expect.objectContaining({
883 jobId: 'job-one',
884 status: 'completed',
885 progress: 100,
886 url: 'https://example.com/one.mp4',
887 }),
888 preview: {
889 kind: 'video',
890 items: [
891 {
892 src: 'https://example.com/one.mp4',
893 sourceType: 'url',
894 },
895 ],
896 job: {
897 jobId: 'job-one',
898 status: 'completed',
899 progress: 100,
900 },
901 },
902 }),
903 expect.objectContaining({
904 id: 'video-run-two',
905 input: { prompt: 'two' },
906 status: 'success',
907 isLoading: false,
908 progress: {
909 value: 100,
910 },
911 jobId: 'job-two',
912 videoStatus: expect.objectContaining({
913 jobId: 'job-two',
914 status: 'completed',
915 progress: 100,
916 url: 'https://example.com/two.mp4',
917 }),
918 }),
919 ])
920​
921 client.dispose()
922 })
923})