> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ja/llms.txt # Run.timeTravelStream() `.timeTravelStream()` メソッドは、任意のステップから Workflow を再実行し、イベントをストリーミングします。各ステップの進捗を完全に把握しながら、タイムトラベル実行中の更新をリアルタイムで受け取れます。 ## 使用例 ```typescript const run = await workflow.createRun() const output = run.timeTravelStream({ step: 'step2', inputData: { value: 10 }, }) // Process events as they arrive for await (const event of output.fullStream) { console.log(event.type, event.payload) } // Get the final result const result = await output.result ``` ## パラメーター すべてのパラメーターは [`Run.timeTravel()`](https://mastra.zisheng.pro/ja/reference/workflows/run-methods/timeTravel) と同じです。パラメーターの詳細については、[timeTravel リファレンス](https://mastra.zisheng.pro/ja/reference/workflows/run-methods/timeTravel)を参照してください。 ## 戻り値 **output** (`WorkflowRunOutput>`): ストリームと結果の Promise の両方を含むオブジェクト **output.fullStream** (`ReadableStream`): 実行の進行に合わせて Workflow イベントを発行する読み取り可能なストリーム **output.result** (`Promise>`): Workflow 実行の最終結果に解決される Promise **output.traceId** (`string`): Tracing が有効な場合に、この実行に関連付けられる Trace ID ## ストリームイベント ストリームは、実行中に Workflow イベントを発行します。 - `workflow-step-start`: ステップの実行開始時に発行されます - `workflow-step-finish`: ステップが正常に完了したときに発行されます - `workflow-step-error`: ステップでエラーが発生したときに発行されます - `workflow-step-suspended`: ステップが中断したときに発行されます - ステップの種類(Agent、Tool など)に応じた追加イベント ## 詳細な使用例 ### タイムトラベル中のイベント処理 ```typescript const run = await workflow.createRun() const output = run.timeTravelStream({ step: 'step2', inputData: { value: 10 }, }) for await (const event of output.fullStream) { switch (event.type) { case 'workflow-step-start': console.log(`Starting step: ${event.payload.stepName}`) break case 'workflow-step-finish': console.log(`Completed step: ${event.payload.stepName}`) break case 'workflow-step-error': console.error(`Error in step: ${event.payload.stepName}`, event.payload.error) break } } const result = await output.result console.log('Time travel completed:', result) ``` ### コンテキストを使用するタイムトラベルストリーム ```typescript const output = run.timeTravelStream({ step: 'step2', context: { step1: { status: 'success', payload: { value: 0 }, output: { step1Result: 2 }, startedAt: Date.now(), endedAt: Date.now(), }, }, }) for await (const event of output.fullStream) { // Handle events console.log(event) } const result = await output.result ``` ### ネストされた Workflow を使用するタイムトラベルストリーム ```typescript const output = run.timeTravelStream({ step: ['nestedWorkflow', 'step3'], inputData: { value: 10 }, nestedStepsContext: { nestedWorkflow: { step2: { status: 'success', payload: { step1Result: 2 }, output: { step2Result: 3 }, startedAt: Date.now(), endedAt: Date.now(), }, }, }, }) for await (const event of output.fullStream) { console.log(event.type, event.payload) } const result = await output.result ``` ## 注意事項 - タイムトラベル実行が完了するかエラーが発生すると、ストリームは自動的に閉じられます - Workflow の実行中でも、ストリームのイベントを処理できます - `result` Promise は、すべてのステップが完了した後にのみ解決されます - ストリームイベントは、通常の Workflow ストリーミングと同じ形式です - タイムトラベルストリーミングは永続化された Workflow スナップショットを使用するため、storage を設定する必要があります ## 関連項目 - [Run.timeTravel()](https://mastra.zisheng.pro/ja/reference/workflows/run-methods/timeTravel) - [タイムトラベル](https://mastra.zisheng.pro/ja/docs/workflows/time-travel) - [Workflow ストリーミング](https://mastra.zisheng.pro/ja/docs/workflows/overview) - [Run.stream()](https://mastra.zisheng.pro/ja/reference/streaming/workflows/stream) - [Run.resumeStream()](https://mastra.zisheng.pro/ja/reference/streaming/workflows/resumeStream)