MCPcopy Create free account
hub / github.com/TanStack/ai / createVideoConnection

Function createVideoConnection

examples/ts-react-chat/src/routes/generation-hooks.tsx:602–651  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

600}
601
602function createVideoConnection(): ConnectConnectionAdapter {
603 return {
604 async *connect(_messages, data, abortSignal, runContext) {
605 const runId = runContext?.runId ?? `video-run-${Date.now()}`
606 const threadId = runContext?.threadId ?? 'video-thread'
607 const jobId = `local-video-${Date.now()}`
608 const prompt = stringField(
609 toRecord(data),
610 'prompt',
611 'Local video fixture',
612 )
613
614 yield runStarted(runId, threadId)
615 await waitForFixtureStep(abortSignal)
616 if (abortSignal?.aborted) return
617
618 yield custom(GENERATION_EVENTS.VIDEO_JOB_CREATED, { jobId })
619 yield custom(GENERATION_EVENTS.VIDEO_STATUS, {
620 jobId,
621 status: 'pending',
622 progress: 10,
623 })
624 await waitForFixtureStep(abortSignal)
625 if (abortSignal?.aborted) return
626
627 yield custom(GENERATION_EVENTS.VIDEO_STATUS, {
628 jobId,
629 status: 'processing',
630 progress: 60,
631 })
632 await waitForFixtureStep(abortSignal)
633 if (abortSignal?.aborted) return
634
635 const finalResult: VideoGenerateResult = {
636 jobId,
637 status: 'completed',
638 url: SAMPLE_VIDEO_URL,
639 }
640 yield custom(GENERATION_EVENTS.VIDEO_STATUS, {
641 jobId,
642 status: 'completed',
643 progress: 100,
644 url: SAMPLE_VIDEO_URL,
645 prompt,
646 })
647 yield result(finalResult)
648 yield runFinished(runId, threadId)
649 },
650 }
651}
652
653async function waitForFixtureStep(abortSignal: AbortSignal | undefined) {
654 await new Promise<void>((resolve) => {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected