@mastra/react 0.0.0-studio-cli-20260504022012 → 0.0.0-sugared-octave-20261030170102
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/LICENSE.md +6 -4
- package/README.md +37 -0
- package/dist/accumulator-Bjfckb5t.cjs +1753 -0
- package/dist/accumulator-Bjfckb5t.cjs.map +1 -0
- package/dist/accumulator-DysrPe6U.js +1712 -0
- package/dist/accumulator-DysrPe6U.js.map +1 -0
- package/dist/agent/extract-tasks.d.ts +10 -0
- package/dist/agent/extract-tasks.d.ts.map +1 -0
- package/dist/agent/extractRunIdFromMessages.d.ts +9 -2
- package/dist/agent/extractRunIdFromMessages.d.ts.map +1 -1
- package/dist/agent/hooks.d.ts +77 -13
- package/dist/agent/hooks.d.ts.map +1 -1
- package/dist/agent/merge-history.d.ts +7 -0
- package/dist/agent/merge-history.d.ts.map +1 -0
- package/dist/agent/signal-data.d.ts +5 -0
- package/dist/agent/signal-data.d.ts.map +1 -0
- package/dist/agent/types.d.ts +15 -1
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/user-message.d.ts +4 -0
- package/dist/agent/user-message.d.ts.map +1 -0
- package/dist/chat/index.cjs +3 -0
- package/dist/chat/index.d.ts +3 -0
- package/dist/chat/index.d.ts.map +1 -0
- package/dist/chat/index.js +1 -0
- package/dist/combine-by-ids-C-0oe4eH.js +23 -0
- package/dist/combine-by-ids-C-0oe4eH.js.map +1 -0
- package/dist/combine-by-ids-ERVPXXBi.cjs +28 -0
- package/dist/combine-by-ids-ERVPXXBi.cjs.map +1 -0
- package/dist/experiments-Duv0RgkM.cjs +346 -0
- package/dist/experiments-Duv0RgkM.cjs.map +1 -0
- package/dist/experiments-DyecjEut.js +299 -0
- package/dist/experiments-DyecjEut.js.map +1 -0
- package/dist/feedback-refetch-interval-BBcT9r8s.cjs +16 -0
- package/dist/feedback-refetch-interval-BBcT9r8s.cjs.map +1 -0
- package/dist/feedback-refetch-interval-C12Nzb2r.js +11 -0
- package/dist/feedback-refetch-interval-C12Nzb2r.js.map +1 -0
- package/dist/hooks/agents/index.cjs +994 -0
- package/dist/hooks/agents/index.cjs.map +1 -0
- package/dist/hooks/agents/index.d.ts +19 -0
- package/dist/hooks/agents/index.d.ts.map +1 -0
- package/dist/hooks/agents/index.js +957 -0
- package/dist/hooks/agents/index.js.map +1 -0
- package/dist/hooks/agents/is-model-not-allowed.d.ts +15 -0
- package/dist/hooks/agents/is-model-not-allowed.d.ts.map +1 -0
- package/dist/hooks/agents/use-agent-messages.d.ts +18 -0
- package/dist/hooks/agents/use-agent-messages.d.ts.map +1 -0
- package/dist/hooks/agents/use-agent-plan.d.ts +14 -0
- package/dist/hooks/agents/use-agent-plan.d.ts.map +1 -0
- package/dist/hooks/agents/use-agent-skills.d.ts +2043 -0
- package/dist/hooks/agents/use-agent-skills.d.ts.map +1 -0
- package/dist/hooks/agents/use-agent-versions.d.ts +72 -0
- package/dist/hooks/agents/use-agent-versions.d.ts.map +1 -0
- package/dist/hooks/agents/use-agent-working-memory.d.ts +11 -0
- package/dist/hooks/agents/use-agent-working-memory.d.ts.map +1 -0
- package/dist/hooks/agents/use-agent-workspace.d.ts +2044 -0
- package/dist/hooks/agents/use-agent-workspace.d.ts.map +1 -0
- package/dist/hooks/agents/use-agent.d.ts +12 -0
- package/dist/hooks/agents/use-agent.d.ts.map +1 -0
- package/dist/hooks/agents/use-agents-model-providers.d.ts +9 -0
- package/dist/hooks/agents/use-agents-model-providers.d.ts.map +1 -0
- package/dist/hooks/agents/use-agents.d.ts +28 -0
- package/dist/hooks/agents/use-agents.d.ts.map +1 -0
- package/dist/hooks/agents/use-background-tasks.d.ts +51 -0
- package/dist/hooks/agents/use-background-tasks.d.ts.map +1 -0
- package/dist/hooks/agents/use-browser-session-probe.d.ts +34 -0
- package/dist/hooks/agents/use-browser-session-probe.d.ts.map +1 -0
- package/dist/hooks/agents/use-channels.d.ts +45 -0
- package/dist/hooks/agents/use-channels.d.ts.map +1 -0
- package/dist/hooks/agents/use-close-browser.d.ts +17 -0
- package/dist/hooks/agents/use-close-browser.d.ts.map +1 -0
- package/dist/hooks/agents/use-execute-agent-tool.d.ts +14 -0
- package/dist/hooks/agents/use-execute-agent-tool.d.ts.map +1 -0
- package/dist/hooks/agents/use-preview-instructions.d.ts +20 -0
- package/dist/hooks/agents/use-preview-instructions.d.ts.map +1 -0
- package/dist/hooks/agents/use-stored-agents.d.ts +8111 -0
- package/dist/hooks/agents/use-stored-agents.d.ts.map +1 -0
- package/dist/hooks/agents/use-stored-skills.d.ts +8 -0
- package/dist/hooks/agents/use-stored-skills.d.ts.map +1 -0
- package/dist/hooks/auth/fetch-with-refresh.d.ts +28 -0
- package/dist/hooks/auth/fetch-with-refresh.d.ts.map +1 -0
- package/dist/hooks/auth/get-client-query-key.d.ts +7 -0
- package/dist/hooks/auth/get-client-query-key.d.ts.map +1 -0
- package/dist/hooks/auth/index.cjs +482 -0
- package/dist/hooks/auth/index.cjs.map +1 -0
- package/dist/hooks/auth/index.d.ts +11 -0
- package/dist/hooks/auth/index.d.ts.map +1 -0
- package/dist/hooks/auth/index.js +464 -0
- package/dist/hooks/auth/index.js.map +1 -0
- package/dist/hooks/auth/sso-login.d.ts +8 -0
- package/dist/hooks/auth/sso-login.d.ts.map +1 -0
- package/dist/hooks/auth/types.d.ts +107 -0
- package/dist/hooks/auth/types.d.ts.map +1 -0
- package/dist/hooks/auth/use-auth-actions.d.ts +99 -0
- package/dist/hooks/auth/use-auth-actions.d.ts.map +1 -0
- package/dist/hooks/auth/use-auth-capabilities.d.ts +43 -0
- package/dist/hooks/auth/use-auth-capabilities.d.ts.map +1 -0
- package/dist/hooks/auth/use-credentials-login.d.ts +63 -0
- package/dist/hooks/auth/use-credentials-login.d.ts.map +1 -0
- package/dist/hooks/auth/use-credentials-signup.d.ts +66 -0
- package/dist/hooks/auth/use-credentials-signup.d.ts.map +1 -0
- package/dist/hooks/auth/use-current-user.d.ts +40 -0
- package/dist/hooks/auth/use-current-user.d.ts.map +1 -0
- package/dist/hooks/auth/use-permission-patterns.d.ts +24 -0
- package/dist/hooks/auth/use-permission-patterns.d.ts.map +1 -0
- package/dist/hooks/capabilities/index.cjs +139 -0
- package/dist/hooks/capabilities/index.cjs.map +1 -0
- package/dist/hooks/capabilities/index.d.ts +11 -0
- package/dist/hooks/capabilities/index.d.ts.map +1 -0
- package/dist/hooks/capabilities/index.js +129 -0
- package/dist/hooks/capabilities/index.js.map +1 -0
- package/dist/hooks/capabilities/use-feedback-available.d.ts +9 -0
- package/dist/hooks/capabilities/use-feedback-available.d.ts.map +1 -0
- package/dist/hooks/capabilities/use-observability-capabilities.d.ts +9 -0
- package/dist/hooks/capabilities/use-observability-capabilities.d.ts.map +1 -0
- package/dist/hooks/capabilities/use-span-aggregate-available.d.ts +9 -0
- package/dist/hooks/capabilities/use-span-aggregate-available.d.ts.map +1 -0
- package/dist/hooks/capabilities/use-span-query-available.d.ts +9 -0
- package/dist/hooks/capabilities/use-span-query-available.d.ts.map +1 -0
- package/dist/hooks/capabilities/use-thread-query-available.d.ts +9 -0
- package/dist/hooks/capabilities/use-thread-query-available.d.ts.map +1 -0
- package/dist/hooks/capabilities/use-trace-aggregate-available.d.ts +10 -0
- package/dist/hooks/capabilities/use-trace-aggregate-available.d.ts.map +1 -0
- package/dist/hooks/capabilities/use-trace-query-available.d.ts +9 -0
- package/dist/hooks/capabilities/use-trace-query-available.d.ts.map +1 -0
- package/dist/hooks/capabilities/use-trace-query-delta-polling-available.d.ts +10 -0
- package/dist/hooks/capabilities/use-trace-query-delta-polling-available.d.ts.map +1 -0
- package/dist/hooks/capabilities/use-trace-query-discovery-available.d.ts +10 -0
- package/dist/hooks/capabilities/use-trace-query-discovery-available.d.ts.map +1 -0
- package/dist/hooks/capabilities/use-trace-query-root-duration-available.d.ts +10 -0
- package/dist/hooks/capabilities/use-trace-query-root-duration-available.d.ts.map +1 -0
- package/dist/hooks/configuration/index.cjs +17 -0
- package/dist/hooks/configuration/index.cjs.map +1 -0
- package/dist/hooks/configuration/index.d.ts +2 -0
- package/dist/hooks/configuration/index.d.ts.map +1 -0
- package/dist/hooks/configuration/index.js +16 -0
- package/dist/hooks/configuration/index.js.map +1 -0
- package/dist/hooks/configuration/use-mastra-packages.d.ts +9 -0
- package/dist/hooks/configuration/use-mastra-packages.d.ts.map +1 -0
- package/dist/hooks/datasets/index.cjs +726 -0
- package/dist/hooks/datasets/index.cjs.map +1 -0
- package/dist/hooks/datasets/index.d.ts +10 -0
- package/dist/hooks/datasets/index.d.ts.map +1 -0
- package/dist/hooks/datasets/index.js +703 -0
- package/dist/hooks/datasets/index.js.map +1 -0
- package/dist/hooks/datasets/use-compare-experiments.d.ts +19 -0
- package/dist/hooks/datasets/use-compare-experiments.d.ts.map +1 -0
- package/dist/hooks/datasets/use-dataset-experiments.d.ts +92 -0
- package/dist/hooks/datasets/use-dataset-experiments.d.ts.map +1 -0
- package/dist/hooks/datasets/use-dataset-item-versions.d.ts +31 -0
- package/dist/hooks/datasets/use-dataset-item-versions.d.ts.map +1 -0
- package/dist/hooks/datasets/use-dataset-items.d.ts +38 -0
- package/dist/hooks/datasets/use-dataset-items.d.ts.map +1 -0
- package/dist/hooks/datasets/use-dataset-mutations.d.ts +315 -0
- package/dist/hooks/datasets/use-dataset-mutations.d.ts.map +1 -0
- package/dist/hooks/datasets/use-dataset-versions.d.ts +23 -0
- package/dist/hooks/datasets/use-dataset-versions.d.ts.map +1 -0
- package/dist/hooks/datasets/use-datasets.d.ts +51 -0
- package/dist/hooks/datasets/use-datasets.d.ts.map +1 -0
- package/dist/hooks/datasets/use-experiments.d.ts +24 -0
- package/dist/hooks/datasets/use-experiments.d.ts.map +1 -0
- package/dist/hooks/datasets/use-workflow-schema.d.ts +16 -0
- package/dist/hooks/datasets/use-workflow-schema.d.ts.map +1 -0
- package/dist/hooks/embedders/index.cjs +18 -0
- package/dist/hooks/embedders/index.cjs.map +1 -0
- package/dist/hooks/embedders/index.d.ts +2 -0
- package/dist/hooks/embedders/index.d.ts.map +1 -0
- package/dist/hooks/embedders/index.js +17 -0
- package/dist/hooks/embedders/index.js.map +1 -0
- package/dist/hooks/embedders/use-embedders.d.ts +17 -0
- package/dist/hooks/embedders/use-embedders.d.ts.map +1 -0
- package/dist/hooks/experiments/index.cjs +10 -0
- package/dist/hooks/experiments/index.d.ts +7 -0
- package/dist/hooks/experiments/index.d.ts.map +1 -0
- package/dist/hooks/experiments/index.js +1 -0
- package/dist/hooks/experiments/usage-accumulator.d.ts +25 -0
- package/dist/hooks/experiments/usage-accumulator.d.ts.map +1 -0
- package/dist/hooks/experiments/use-experiment-item-usage.d.ts +23 -0
- package/dist/hooks/experiments/use-experiment-item-usage.d.ts.map +1 -0
- package/dist/hooks/experiments/use-experiment-metrics.d.ts +30 -0
- package/dist/hooks/experiments/use-experiment-metrics.d.ts.map +1 -0
- package/dist/hooks/experiments/use-experiment-trace.d.ts +13 -0
- package/dist/hooks/experiments/use-experiment-trace.d.ts.map +1 -0
- package/dist/hooks/experiments/use-experiments-for-dataset-filter.d.ts +22 -0
- package/dist/hooks/experiments/use-experiments-for-dataset-filter.d.ts.map +1 -0
- package/dist/hooks/experiments/use-experiments-list-metrics.d.ts +19 -0
- package/dist/hooks/experiments/use-experiments-list-metrics.d.ts.map +1 -0
- package/dist/hooks/experiments/use-infinite-experiments.d.ts +22 -0
- package/dist/hooks/experiments/use-infinite-experiments.d.ts.map +1 -0
- package/dist/hooks/feedback/feedback-refetch-interval.d.ts +7 -0
- package/dist/hooks/feedback/feedback-refetch-interval.d.ts.map +1 -0
- package/dist/hooks/feedback/index.cjs +21 -0
- package/dist/hooks/feedback/index.cjs.map +1 -0
- package/dist/hooks/feedback/index.d.ts +3 -0
- package/dist/hooks/feedback/index.d.ts.map +1 -0
- package/dist/hooks/feedback/index.js +19 -0
- package/dist/hooks/feedback/index.js.map +1 -0
- package/dist/hooks/feedback/use-feedback.d.ts +56 -0
- package/dist/hooks/feedback/use-feedback.d.ts.map +1 -0
- package/dist/hooks/llm/index.cjs +16 -0
- package/dist/hooks/llm/index.cjs.map +1 -0
- package/dist/hooks/llm/index.d.ts +2 -0
- package/dist/hooks/llm/index.d.ts.map +1 -0
- package/dist/hooks/llm/index.js +15 -0
- package/dist/hooks/llm/index.js.map +1 -0
- package/dist/hooks/llm/use-llm-providers.d.ts +7 -0
- package/dist/hooks/llm/use-llm-providers.d.ts.map +1 -0
- package/dist/hooks/logs/index.cjs +83 -0
- package/dist/hooks/logs/index.cjs.map +1 -0
- package/dist/hooks/logs/index.d.ts +4 -0
- package/dist/hooks/logs/index.d.ts.map +1 -0
- package/dist/hooks/logs/index.js +81 -0
- package/dist/hooks/logs/index.js.map +1 -0
- package/dist/hooks/logs/types.d.ts +36 -0
- package/dist/hooks/logs/types.d.ts.map +1 -0
- package/dist/hooks/logs/use-logs.d.ts +79 -0
- package/dist/hooks/logs/use-logs.d.ts.map +1 -0
- package/dist/hooks/mcps/index.cjs +231 -0
- package/dist/hooks/mcps/index.cjs.map +1 -0
- package/dist/hooks/mcps/index.d.ts +8 -0
- package/dist/hooks/mcps/index.d.ts.map +1 -0
- package/dist/hooks/mcps/index.js +223 -0
- package/dist/hooks/mcps/index.js.map +1 -0
- package/dist/hooks/mcps/use-mcp-app-html.d.ts +17 -0
- package/dist/hooks/mcps/use-mcp-app-html.d.ts.map +1 -0
- package/dist/hooks/mcps/use-mcp-app-tools.d.ts +21 -0
- package/dist/hooks/mcps/use-mcp-app-tools.d.ts.map +1 -0
- package/dist/hooks/mcps/use-mcp-server-tool.d.ts +25 -0
- package/dist/hooks/mcps/use-mcp-server-tool.d.ts.map +1 -0
- package/dist/hooks/mcps/use-mcp-server-tools-by-id.d.ts +13 -0
- package/dist/hooks/mcps/use-mcp-server-tools-by-id.d.ts.map +1 -0
- package/dist/hooks/mcps/use-mcp-server-tools.d.ts +9 -0
- package/dist/hooks/mcps/use-mcp-server-tools.d.ts.map +1 -0
- package/dist/hooks/mcps/use-mcp-servers.d.ts +8 -0
- package/dist/hooks/mcps/use-mcp-servers.d.ts.map +1 -0
- package/dist/hooks/mcps/use-try-connect-mcp.d.ts +15 -0
- package/dist/hooks/mcps/use-try-connect-mcp.d.ts.map +1 -0
- package/dist/hooks/memory/index.cjs +324 -0
- package/dist/hooks/memory/index.cjs.map +1 -0
- package/dist/hooks/memory/index.d.ts +5 -0
- package/dist/hooks/memory/index.d.ts.map +1 -0
- package/dist/hooks/memory/index.js +308 -0
- package/dist/hooks/memory/index.js.map +1 -0
- package/dist/hooks/memory/use-memory-status.d.ts +12 -0
- package/dist/hooks/memory/use-memory-status.d.ts.map +1 -0
- package/dist/hooks/memory/use-memory-thread-messages.d.ts +13 -0
- package/dist/hooks/memory/use-memory-thread-messages.d.ts.map +1 -0
- package/dist/hooks/memory/use-memory.d.ts +159 -0
- package/dist/hooks/memory/use-memory.d.ts.map +1 -0
- package/dist/hooks/memory/use-observational-memory.d.ts +13 -0
- package/dist/hooks/memory/use-observational-memory.d.ts.map +1 -0
- package/dist/hooks/metrics/index.cjs +989 -0
- package/dist/hooks/metrics/index.cjs.map +1 -0
- package/dist/hooks/metrics/index.d.ts +16 -0
- package/dist/hooks/metrics/index.d.ts.map +1 -0
- package/dist/hooks/metrics/index.js +973 -0
- package/dist/hooks/metrics/index.js.map +1 -0
- package/dist/hooks/metrics/metrics-interval.d.ts +8 -0
- package/dist/hooks/metrics/metrics-interval.d.ts.map +1 -0
- package/dist/hooks/metrics/metrics-query-filters.d.ts +62 -0
- package/dist/hooks/metrics/metrics-query-filters.d.ts.map +1 -0
- package/dist/hooks/metrics/use-active-resources-kpi-metrics.d.ts +12 -0
- package/dist/hooks/metrics/use-active-resources-kpi-metrics.d.ts.map +1 -0
- package/dist/hooks/metrics/use-active-threads-kpi-metrics.d.ts +12 -0
- package/dist/hooks/metrics/use-active-threads-kpi-metrics.d.ts.map +1 -0
- package/dist/hooks/metrics/use-agent-runs-kpi-metrics.d.ts +9 -0
- package/dist/hooks/metrics/use-agent-runs-kpi-metrics.d.ts.map +1 -0
- package/dist/hooks/metrics/use-latency-metrics.d.ts +23 -0
- package/dist/hooks/metrics/use-latency-metrics.d.ts.map +1 -0
- package/dist/hooks/metrics/use-model-cost-kpi-metrics.d.ts +14 -0
- package/dist/hooks/metrics/use-model-cost-kpi-metrics.d.ts.map +1 -0
- package/dist/hooks/metrics/use-model-usage-cost-metrics.d.ts +17 -0
- package/dist/hooks/metrics/use-model-usage-cost-metrics.d.ts.map +1 -0
- package/dist/hooks/metrics/use-scores-metrics.d.ts +24 -0
- package/dist/hooks/metrics/use-scores-metrics.d.ts.map +1 -0
- package/dist/hooks/metrics/use-token-usage-by-agent-metrics.d.ts +15 -0
- package/dist/hooks/metrics/use-token-usage-by-agent-metrics.d.ts.map +1 -0
- package/dist/hooks/metrics/use-token-usage-timeseries.d.ts +22 -0
- package/dist/hooks/metrics/use-token-usage-timeseries.d.ts.map +1 -0
- package/dist/hooks/metrics/use-top-active-threads-metrics.d.ts +21 -0
- package/dist/hooks/metrics/use-top-active-threads-metrics.d.ts.map +1 -0
- package/dist/hooks/metrics/use-top-resources-by-threads-metrics.d.ts +20 -0
- package/dist/hooks/metrics/use-top-resources-by-threads-metrics.d.ts.map +1 -0
- package/dist/hooks/metrics/use-total-tokens-kpi-metrics.d.ts +13 -0
- package/dist/hooks/metrics/use-total-tokens-kpi-metrics.d.ts.map +1 -0
- package/dist/hooks/metrics/use-trace-volume-metrics.d.ts +17 -0
- package/dist/hooks/metrics/use-trace-volume-metrics.d.ts.map +1 -0
- package/dist/hooks/processors/index.cjs +42 -0
- package/dist/hooks/processors/index.cjs.map +1 -0
- package/dist/hooks/processors/index.d.ts +2 -0
- package/dist/hooks/processors/index.d.ts.map +1 -0
- package/dist/hooks/processors/index.js +39 -0
- package/dist/hooks/processors/index.js.map +1 -0
- package/dist/hooks/processors/use-processors.d.ts +64 -0
- package/dist/hooks/processors/use-processors.d.ts.map +1 -0
- package/dist/hooks/prompt-blocks/index.cjs +179 -0
- package/dist/hooks/prompt-blocks/index.cjs.map +1 -0
- package/dist/hooks/prompt-blocks/index.d.ts +3 -0
- package/dist/hooks/prompt-blocks/index.d.ts.map +1 -0
- package/dist/hooks/prompt-blocks/index.js +170 -0
- package/dist/hooks/prompt-blocks/index.js.map +1 -0
- package/dist/hooks/prompt-blocks/use-prompt-block-versions.d.ts +59 -0
- package/dist/hooks/prompt-blocks/use-prompt-block-versions.d.ts.map +1 -0
- package/dist/hooks/prompt-blocks/use-stored-prompt-blocks.d.ts +180 -0
- package/dist/hooks/prompt-blocks/use-stored-prompt-blocks.d.ts.map +1 -0
- package/dist/hooks/query/index.cjs +33 -0
- package/dist/hooks/query/index.cjs.map +1 -0
- package/dist/hooks/query/index.d.ts +4 -0
- package/dist/hooks/query/index.d.ts.map +1 -0
- package/dist/hooks/query/index.js +24 -0
- package/dist/hooks/query/index.js.map +1 -0
- package/dist/hooks/query/query-client-provider.d.ts +8 -0
- package/dist/hooks/query/query-client-provider.d.ts.map +1 -0
- package/dist/hooks/query/query-utils.d.ts +48 -0
- package/dist/hooks/query/query-utils.d.ts.map +1 -0
- package/dist/hooks/review/index.cjs +90 -0
- package/dist/hooks/review/index.cjs.map +1 -0
- package/dist/hooks/review/index.d.ts +4 -0
- package/dist/hooks/review/index.d.ts.map +1 -0
- package/dist/hooks/review/index.js +87 -0
- package/dist/hooks/review/index.js.map +1 -0
- package/dist/hooks/review/types.d.ts +24 -0
- package/dist/hooks/review/types.d.ts.map +1 -0
- package/dist/hooks/review/use-dataset-review-items.d.ts +19 -0
- package/dist/hooks/review/use-dataset-review-items.d.ts.map +1 -0
- package/dist/hooks/review/use-review-summary.d.ts +9 -0
- package/dist/hooks/review/use-review-summary.d.ts.map +1 -0
- package/dist/hooks/schedules/index.cjs +106 -0
- package/dist/hooks/schedules/index.cjs.map +1 -0
- package/dist/hooks/schedules/index.d.ts +5 -0
- package/dist/hooks/schedules/index.d.ts.map +1 -0
- package/dist/hooks/schedules/index.js +102 -0
- package/dist/hooks/schedules/index.js.map +1 -0
- package/dist/hooks/schedules/use-schedule-triggers.d.ts +18 -0
- package/dist/hooks/schedules/use-schedule-triggers.d.ts.map +1 -0
- package/dist/hooks/schedules/use-schedule.d.ts +11 -0
- package/dist/hooks/schedules/use-schedule.d.ts.map +1 -0
- package/dist/hooks/schedules/use-schedules.d.ts +7 -0
- package/dist/hooks/schedules/use-schedules.d.ts.map +1 -0
- package/dist/hooks/schedules/use-toggle-schedule.d.ts +13 -0
- package/dist/hooks/schedules/use-toggle-schedule.d.ts.map +1 -0
- package/dist/hooks/scores/index.cjs +334 -0
- package/dist/hooks/scores/index.cjs.map +1 -0
- package/dist/hooks/scores/index.d.ts +6 -0
- package/dist/hooks/scores/index.d.ts.map +1 -0
- package/dist/hooks/scores/index.js +318 -0
- package/dist/hooks/scores/index.js.map +1 -0
- package/dist/hooks/scores/use-scorer-versions.d.ts +71 -0
- package/dist/hooks/scores/use-scorer-versions.d.ts.map +1 -0
- package/dist/hooks/scores/use-scorers.d.ts +34 -0
- package/dist/hooks/scores/use-scorers.d.ts.map +1 -0
- package/dist/hooks/scores/use-stored-scorers.d.ts +151 -0
- package/dist/hooks/scores/use-stored-scorers.d.ts.map +1 -0
- package/dist/hooks/scores/use-trace-span-scores.d.ts +20 -0
- package/dist/hooks/scores/use-trace-span-scores.d.ts.map +1 -0
- package/dist/hooks/scores/use-trigger-scorer.d.ts +17 -0
- package/dist/hooks/scores/use-trigger-scorer.d.ts.map +1 -0
- package/dist/hooks/shared/combine-by-ids.d.ts +15 -0
- package/dist/hooks/shared/combine-by-ids.d.ts.map +1 -0
- package/dist/hooks/shared/cost.d.ts +7 -0
- package/dist/hooks/shared/cost.d.ts.map +1 -0
- package/dist/hooks/shared/date-format.d.ts +30 -0
- package/dist/hooks/shared/date-format.d.ts.map +1 -0
- package/dist/hooks/shared/map.d.ts +2 -0
- package/dist/hooks/shared/map.d.ts.map +1 -0
- package/dist/hooks/shared/query-options.d.ts +19 -0
- package/dist/hooks/shared/query-options.d.ts.map +1 -0
- package/dist/hooks/shared/use-in-view.d.ts +23 -0
- package/dist/hooks/shared/use-in-view.d.ts.map +1 -0
- package/dist/hooks/templates/index.cjs +465 -0
- package/dist/hooks/templates/index.cjs.map +1 -0
- package/dist/hooks/templates/index.d.ts +2 -0
- package/dist/hooks/templates/index.d.ts.map +1 -0
- package/dist/hooks/templates/index.js +457 -0
- package/dist/hooks/templates/index.js.map +1 -0
- package/dist/hooks/templates/use-templates.d.ts +139 -0
- package/dist/hooks/templates/use-templates.d.ts.map +1 -0
- package/dist/hooks/tool-providers/index.cjs +333 -0
- package/dist/hooks/tool-providers/index.cjs.map +1 -0
- package/dist/hooks/tool-providers/index.d.ts +10 -0
- package/dist/hooks/tool-providers/index.d.ts.map +1 -0
- package/dist/hooks/tool-providers/index.js +323 -0
- package/dist/hooks/tool-providers/index.js.map +1 -0
- package/dist/hooks/tool-providers/use-all-connections.d.ts +41 -0
- package/dist/hooks/tool-providers/use-all-connections.d.ts.map +1 -0
- package/dist/hooks/tool-providers/use-all-provider-tools.d.ts +25 -0
- package/dist/hooks/tool-providers/use-all-provider-tools.d.ts.map +1 -0
- package/dist/hooks/tool-providers/use-authorize.d.ts +45 -0
- package/dist/hooks/tool-providers/use-authorize.d.ts.map +1 -0
- package/dist/hooks/tool-providers/use-disconnect-connection.d.ts +24 -0
- package/dist/hooks/tool-providers/use-disconnect-connection.d.ts.map +1 -0
- package/dist/hooks/tool-providers/use-existing-connections.d.ts +33 -0
- package/dist/hooks/tool-providers/use-existing-connections.d.ts.map +1 -0
- package/dist/hooks/tool-providers/use-provider-tools.d.ts +17 -0
- package/dist/hooks/tool-providers/use-provider-tools.d.ts.map +1 -0
- package/dist/hooks/tool-providers/use-tool-providers.d.ts +23 -0
- package/dist/hooks/tool-providers/use-tool-providers.d.ts.map +1 -0
- package/dist/hooks/tool-providers/use-toolkits.d.ts +13 -0
- package/dist/hooks/tool-providers/use-toolkits.d.ts.map +1 -0
- package/dist/hooks/tool-providers/use-update-connection.d.ts +24 -0
- package/dist/hooks/tool-providers/use-update-connection.d.ts.map +1 -0
- package/dist/hooks/tools/index.cjs +47 -0
- package/dist/hooks/tools/index.cjs.map +1 -0
- package/dist/hooks/tools/index.d.ts +3 -0
- package/dist/hooks/tools/index.d.ts.map +1 -0
- package/dist/hooks/tools/index.js +44 -0
- package/dist/hooks/tools/index.js.map +1 -0
- package/dist/hooks/tools/use-all-tools.d.ts +16 -0
- package/dist/hooks/tools/use-all-tools.d.ts.map +1 -0
- package/dist/hooks/tools/use-execute-tool.d.ts +13 -0
- package/dist/hooks/tools/use-execute-tool.d.ts.map +1 -0
- package/dist/hooks/traces/discovery-cache.d.ts +12 -0
- package/dist/hooks/traces/discovery-cache.d.ts.map +1 -0
- package/dist/hooks/traces/index.cjs +1473 -0
- package/dist/hooks/traces/index.cjs.map +1 -0
- package/dist/hooks/traces/index.d.ts +26 -0
- package/dist/hooks/traces/index.d.ts.map +1 -0
- package/dist/hooks/traces/index.js +1424 -0
- package/dist/hooks/traces/index.js.map +1 -0
- package/dist/hooks/traces/types.d.ts +21 -0
- package/dist/hooks/traces/types.d.ts.map +1 -0
- package/dist/hooks/traces/use-branch.d.ts +18 -0
- package/dist/hooks/traces/use-branch.d.ts.map +1 -0
- package/dist/hooks/traces/use-create-feedback.d.ts +21 -0
- package/dist/hooks/traces/use-create-feedback.d.ts.map +1 -0
- package/dist/hooks/traces/use-delete-feedback.d.ts +21 -0
- package/dist/hooks/traces/use-delete-feedback.d.ts.map +1 -0
- package/dist/hooks/traces/use-entity-names.d.ts +14 -0
- package/dist/hooks/traces/use-entity-names.d.ts.map +1 -0
- package/dist/hooks/traces/use-environments.d.ts +10 -0
- package/dist/hooks/traces/use-environments.d.ts.map +1 -0
- package/dist/hooks/traces/use-query-spans.d.ts +27 -0
- package/dist/hooks/traces/use-query-spans.d.ts.map +1 -0
- package/dist/hooks/traces/use-query-threads.d.ts +30 -0
- package/dist/hooks/traces/use-query-threads.d.ts.map +1 -0
- package/dist/hooks/traces/use-service-names.d.ts +10 -0
- package/dist/hooks/traces/use-service-names.d.ts.map +1 -0
- package/dist/hooks/traces/use-span-aggregate.d.ts +16 -0
- package/dist/hooks/traces/use-span-aggregate.d.ts.map +1 -0
- package/dist/hooks/traces/use-span-detail.d.ts +14 -0
- package/dist/hooks/traces/use-span-detail.d.ts.map +1 -0
- package/dist/hooks/traces/use-span-feedback.d.ts +19 -0
- package/dist/hooks/traces/use-span-feedback.d.ts.map +1 -0
- package/dist/hooks/traces/use-tags.d.ts +10 -0
- package/dist/hooks/traces/use-tags.d.ts.map +1 -0
- package/dist/hooks/traces/use-thread-has-other-traces.d.ts +17 -0
- package/dist/hooks/traces/use-thread-has-other-traces.d.ts.map +1 -0
- package/dist/hooks/traces/use-trace-aggregate.d.ts +17 -0
- package/dist/hooks/traces/use-trace-aggregate.d.ts.map +1 -0
- package/dist/hooks/traces/use-trace-column-preferences-storage-key.d.ts +8 -0
- package/dist/hooks/traces/use-trace-column-preferences-storage-key.d.ts.map +1 -0
- package/dist/hooks/traces/use-trace-feedback.d.ts +16 -0
- package/dist/hooks/traces/use-trace-feedback.d.ts.map +1 -0
- package/dist/hooks/traces/use-trace-light-spans.d.ts +16 -0
- package/dist/hooks/traces/use-trace-light-spans.d.ts.map +1 -0
- package/dist/hooks/traces/use-trace-metadata-filter-fields.d.ts +42 -0
- package/dist/hooks/traces/use-trace-metadata-filter-fields.d.ts.map +1 -0
- package/dist/hooks/traces/use-trace-or-branch-spans.d.ts +39 -0
- package/dist/hooks/traces/use-trace-or-branch-spans.d.ts.map +1 -0
- package/dist/hooks/traces/use-trace-query.d.ts +106 -0
- package/dist/hooks/traces/use-trace-query.d.ts.map +1 -0
- package/dist/hooks/traces/use-trace-spans.d.ts +46 -0
- package/dist/hooks/traces/use-trace-spans.d.ts.map +1 -0
- package/dist/hooks/traces/use-trace-usage.d.ts +10 -0
- package/dist/hooks/traces/use-trace-usage.d.ts.map +1 -0
- package/dist/hooks/traces/use-traces.d.ts +244 -0
- package/dist/hooks/traces/use-traces.d.ts.map +1 -0
- package/dist/hooks/vectors/index.cjs +18 -0
- package/dist/hooks/vectors/index.cjs.map +1 -0
- package/dist/hooks/vectors/index.d.ts +2 -0
- package/dist/hooks/vectors/index.d.ts.map +1 -0
- package/dist/hooks/vectors/index.js +17 -0
- package/dist/hooks/vectors/index.js.map +1 -0
- package/dist/hooks/vectors/use-vectors.d.ts +14 -0
- package/dist/hooks/vectors/use-vectors.d.ts.map +1 -0
- package/dist/hooks/voice/index.cjs +86 -0
- package/dist/hooks/voice/index.cjs.map +1 -0
- package/dist/hooks/voice/index.d.ts +2 -0
- package/dist/hooks/voice/index.d.ts.map +1 -0
- package/dist/hooks/voice/index.js +85 -0
- package/dist/hooks/voice/index.js.map +1 -0
- package/dist/hooks/voice/use-read-aloud.d.ts +20 -0
- package/dist/hooks/voice/use-read-aloud.d.ts.map +1 -0
- package/dist/hooks/workflows/index.cjs +169 -0
- package/dist/hooks/workflows/index.cjs.map +1 -0
- package/dist/hooks/workflows/index.d.ts +7 -0
- package/dist/hooks/workflows/index.d.ts.map +1 -0
- package/dist/hooks/workflows/index.js +153 -0
- package/dist/hooks/workflows/index.js.map +1 -0
- package/dist/hooks/workflows/use-workflow-runs.d.ts +51 -0
- package/dist/hooks/workflows/use-workflow-runs.d.ts.map +1 -0
- package/dist/hooks/workflows/use-workflow.d.ts +14 -0
- package/dist/hooks/workflows/use-workflow.d.ts.map +1 -0
- package/dist/hooks/workflows/use-workflows-run-counts.d.ts +25 -0
- package/dist/hooks/workflows/use-workflows-run-counts.d.ts.map +1 -0
- package/dist/hooks/workflows/use-workflows.d.ts +10 -0
- package/dist/hooks/workflows/use-workflows.d.ts.map +1 -0
- package/dist/hooks/workspace/client-utils.d.ts +5 -0
- package/dist/hooks/workspace/client-utils.d.ts.map +1 -0
- package/dist/hooks/workspace/compatibility.d.ts +22 -0
- package/dist/hooks/workspace/compatibility.d.ts.map +1 -0
- package/dist/hooks/workspace/file-type.d.ts +7 -0
- package/dist/hooks/workspace/file-type.d.ts.map +1 -0
- package/dist/hooks/workspace/index.cjs +614 -0
- package/dist/hooks/workspace/index.cjs.map +1 -0
- package/dist/hooks/workspace/index.d.ts +11 -0
- package/dist/hooks/workspace/index.d.ts.map +1 -0
- package/dist/hooks/workspace/index.js +584 -0
- package/dist/hooks/workspace/index.js.map +1 -0
- package/dist/hooks/workspace/types.d.ts +199 -0
- package/dist/hooks/workspace/types.d.ts.map +1 -0
- package/dist/hooks/workspace/use-skills-sh.d.ts +104 -0
- package/dist/hooks/workspace/use-skills-sh.d.ts.map +1 -0
- package/dist/hooks/workspace/use-stored-workspaces.d.ts +12 -0
- package/dist/hooks/workspace/use-stored-workspaces.d.ts.map +1 -0
- package/dist/hooks/workspace/use-workspace-directory.d.ts +13 -0
- package/dist/hooks/workspace/use-workspace-directory.d.ts.map +1 -0
- package/dist/hooks/workspace/use-workspace-file-content.d.ts +15 -0
- package/dist/hooks/workspace/use-workspace-file-content.d.ts.map +1 -0
- package/dist/hooks/workspace/use-workspace-search.d.ts +20 -0
- package/dist/hooks/workspace/use-workspace-search.d.ts.map +1 -0
- package/dist/hooks/workspace/use-workspace-skills.d.ts +23 -0
- package/dist/hooks/workspace/use-workspace-skills.d.ts.map +1 -0
- package/dist/hooks/workspace/use-workspace.d.ts +56 -0
- package/dist/hooks/workspace/use-workspace.d.ts.map +1 -0
- package/dist/hooks-Bt15IwzP.cjs +266 -0
- package/dist/hooks-Bt15IwzP.cjs.map +1 -0
- package/dist/hooks-Btt7PyI-.js +249 -0
- package/dist/hooks-Btt7PyI-.js.map +1 -0
- package/dist/hooks-Czqwakn0.cjs +1347 -0
- package/dist/hooks-Czqwakn0.cjs.map +1 -0
- package/dist/hooks-MRtQ3GE8.js +1330 -0
- package/dist/hooks-MRtQ3GE8.js.map +1 -0
- package/dist/index.cjs +56 -3001
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -2936
- package/dist/index.js.map +1 -1
- package/dist/lib/mastra-db/accumulator.d.ts +42 -0
- package/dist/lib/mastra-db/accumulator.d.ts.map +1 -0
- package/dist/lib/mastra-db/formatCompletionFeedback.d.ts.map +1 -0
- package/dist/lib/mastra-db/fromCoreUserMessage.d.ts +13 -0
- package/dist/lib/mastra-db/fromCoreUserMessage.d.ts.map +1 -0
- package/dist/lib/mastra-db/index.d.ts +6 -0
- package/dist/lib/mastra-db/index.d.ts.map +1 -0
- package/dist/lib/mastra-db/types.d.ts +173 -0
- package/dist/lib/mastra-db/types.d.ts.map +1 -0
- package/dist/map-5-4U5rwA.js +11 -0
- package/dist/map-5-4U5rwA.js.map +1 -0
- package/dist/map-BGoWBTGy.cjs +16 -0
- package/dist/map-BGoWBTGy.cjs.map +1 -0
- package/dist/mastra-client-context-DQ5z_ze9.js +49 -0
- package/dist/mastra-client-context-DQ5z_ze9.js.map +1 -0
- package/dist/mastra-client-context-DX8wJM9p.cjs +60 -0
- package/dist/mastra-client-context-DX8wJM9p.cjs.map +1 -0
- package/dist/mastra-client-context.d.ts +1 -1
- package/dist/mastra-client-context.d.ts.map +1 -1
- package/dist/mastra-react-provider.d.ts +2 -2
- package/dist/mastra-react-provider.d.ts.map +1 -1
- package/dist/query-utils-BVgE_xxj.cjs +173 -0
- package/dist/query-utils-BVgE_xxj.cjs.map +1 -0
- package/dist/query-utils-DvMERIwf.js +126 -0
- package/dist/query-utils-DvMERIwf.js.map +1 -0
- package/dist/react.css +72 -127
- package/dist/ui/Code/Code.d.ts +3 -2
- package/dist/ui/Code/Code.d.ts.map +1 -1
- package/dist/ui/Entity/Entity.d.ts +4 -4
- package/dist/ui/Entity/Entity.d.ts.map +1 -1
- package/dist/ui/Entity/Entry.d.ts +2 -2
- package/dist/ui/Entity/Entry.d.ts.map +1 -1
- package/dist/ui/Entity/ToolApproval.d.ts +5 -5
- package/dist/ui/Entity/ToolApproval.d.ts.map +1 -1
- package/dist/ui/Icon/Icon.d.ts +1 -1
- package/dist/ui/Icon/Icon.d.ts.map +1 -1
- package/dist/ui/IconButton/IconButton.d.ts +1 -1
- package/dist/ui/IconButton/IconButton.d.ts.map +1 -1
- package/dist/ui/Icons/AgentIcon.d.ts +1 -1
- package/dist/ui/Icons/AgentIcon.d.ts.map +1 -1
- package/dist/ui/Icons/ToolsIcon.d.ts +1 -1
- package/dist/ui/Icons/ToolsIcon.d.ts.map +1 -1
- package/dist/ui/Icons/WorkflowIcon.d.ts +1 -1
- package/dist/ui/Icons/WorkflowIcon.d.ts.map +1 -1
- package/dist/ui/Message/Message.d.ts +9 -9
- package/dist/ui/Message/Message.d.ts.map +1 -1
- package/dist/ui/MessageFactory/MessageFactory.d.ts +24 -0
- package/dist/ui/MessageFactory/MessageFactory.d.ts.map +1 -0
- package/dist/ui/MessageFactory/index.d.ts +3 -0
- package/dist/ui/MessageFactory/index.d.ts.map +1 -0
- package/dist/ui/MessageFactory/types.d.ts +183 -0
- package/dist/ui/MessageFactory/types.d.ts.map +1 -0
- package/dist/ui/Tooltip/Tooltip.d.ts +3 -3
- package/dist/ui/Tooltip/Tooltip.d.ts.map +1 -1
- package/dist/ui/index.cjs +561 -0
- package/dist/ui/index.cjs.map +1 -0
- package/dist/ui/index.d.ts +1 -0
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +484 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/use-in-view-BxdrrnCw.cjs +36 -0
- package/dist/use-in-view-BxdrrnCw.cjs.map +1 -0
- package/dist/use-in-view-CyjKdplM.js +31 -0
- package/dist/use-in-view-CyjKdplM.js.map +1 -0
- package/dist/voice/index.d.ts +5 -0
- package/dist/voice/index.d.ts.map +1 -0
- package/dist/voice/play-stream-with-web-audio.d.ts +2 -0
- package/dist/voice/play-stream-with-web-audio.d.ts.map +1 -0
- package/dist/voice/record-mic-to-file.d.ts +2 -0
- package/dist/voice/record-mic-to-file.d.ts.map +1 -0
- package/dist/voice/use-speech-recognition.d.ts +20 -0
- package/dist/voice/use-speech-recognition.d.ts.map +1 -0
- package/dist/voice-Didej2E1.cjs +278 -0
- package/dist/voice-Didej2E1.cjs.map +1 -0
- package/dist/voice-ugGu7VyA.js +261 -0
- package/dist/voice-ugGu7VyA.js.map +1 -0
- package/dist/workflows/WorkflowStepFactory/WorkflowStepFactory.d.ts +8 -0
- package/dist/workflows/WorkflowStepFactory/WorkflowStepFactory.d.ts.map +1 -0
- package/dist/workflows/WorkflowStepFactory/index.d.ts +3 -0
- package/dist/workflows/WorkflowStepFactory/index.d.ts.map +1 -0
- package/dist/workflows/WorkflowStepFactory/types.d.ts +96 -0
- package/dist/workflows/WorkflowStepFactory/types.d.ts.map +1 -0
- package/dist/workflows/hooks.d.ts.map +1 -1
- package/dist/workflows/index.d.ts +1 -0
- package/dist/workflows/index.d.ts.map +1 -1
- package/dist/workflows/types.d.ts +4 -0
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/use-stream-workflow.d.ts +1 -29
- package/dist/workflows/use-stream-workflow.d.ts.map +1 -1
- package/package.json +70 -38
- package/CHANGELOG.md +0 -2495
- package/dist/lib/ai-sdk/index.d.ts +0 -5
- package/dist/lib/ai-sdk/index.d.ts.map +0 -1
- package/dist/lib/ai-sdk/memory/resolveInitialMessages.d.ts +0 -13
- package/dist/lib/ai-sdk/memory/resolveInitialMessages.d.ts.map +0 -1
- package/dist/lib/ai-sdk/transformers/AISdkNetworkTransformer.d.ts +0 -11
- package/dist/lib/ai-sdk/transformers/AISdkNetworkTransformer.d.ts.map +0 -1
- package/dist/lib/ai-sdk/transformers/types.d.ts +0 -11
- package/dist/lib/ai-sdk/transformers/types.d.ts.map +0 -1
- package/dist/lib/ai-sdk/types.d.ts +0 -143
- package/dist/lib/ai-sdk/types.d.ts.map +0 -1
- package/dist/lib/ai-sdk/utils/formatCompletionFeedback.d.ts.map +0 -1
- package/dist/lib/ai-sdk/utils/fromCoreUserMessageToUIMessage.d.ts +0 -11
- package/dist/lib/ai-sdk/utils/fromCoreUserMessageToUIMessage.d.ts.map +0 -1
- package/dist/lib/ai-sdk/utils/toAssistantUIMessage.d.ts +0 -15
- package/dist/lib/ai-sdk/utils/toAssistantUIMessage.d.ts.map +0 -1
- package/dist/lib/ai-sdk/utils/toUIMessage.d.ts +0 -18
- package/dist/lib/ai-sdk/utils/toUIMessage.d.ts.map +0 -1
- /package/dist/lib/{ai-sdk/utils → mastra-db}/formatCompletionFeedback.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,2938 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { n as useMastraClient, t as MastraClientProvider } from "./mastra-client-context-DQ5z_ze9.js";
|
|
2
|
+
import { a as CLIENT_MESSAGE_ID_KEY, i as mapWorkflowStreamChunkToWatchResult, n as accumulateNetworkChunk, r as finishStreamingAssistantMessage, t as accumulateChunk } from "./accumulator-DysrPe6U.js";
|
|
3
|
+
import { n as fromCoreUserMessageToMastraDBMessage, r as fromCoreUserMessagesToMastraDBMessage, t as useChat } from "./hooks-MRtQ3GE8.js";
|
|
4
|
+
import { n as useCreateWorkflowRun, r as useStreamWorkflow, t as useCancelWorkflowRun } from "./hooks-Btt7PyI-.js";
|
|
5
|
+
import { n as playStreamWithWebAudio, r as recordMicrophoneToFile, t as useSpeechRecognition } from "./voice-ugGu7VyA.js";
|
|
6
|
+
import { memo } from "react";
|
|
7
|
+
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
8
|
+
// src/mastra-react-provider.tsx
|
|
9
|
+
const MastraReactProvider = ({ children, baseUrl, headers, apiPrefix, credentials, customFetch }) => {
|
|
10
|
+
return /* @__PURE__ */ jsx(MastraClientProvider, {
|
|
11
|
+
baseUrl,
|
|
12
|
+
headers,
|
|
13
|
+
apiPrefix,
|
|
14
|
+
credentials,
|
|
15
|
+
customFetch,
|
|
16
|
+
children
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
// src/workflows/WorkflowStepFactory/WorkflowStepFactory.tsx
|
|
20
|
+
const renderUnknown = (step, UnknownStep) => UnknownStep?.(step) ?? null;
|
|
21
|
+
const WorkflowStepFactoryComponent = ({ step, Step, MapStep, AgentStep, ToolStep, ClassifierStep, ForEachStep, ParallelStep, Conditional, LoopStep, SleepStep, SleepUntilStep, NestedWorkflowStep, UnknownStep }) => {
|
|
22
|
+
switch (step.kind) {
|
|
23
|
+
case "step": return /* @__PURE__ */ jsx(Fragment$1, { children: Step?.(step) ?? renderUnknown(step, UnknownStep) });
|
|
24
|
+
case "map-step": return /* @__PURE__ */ jsx(Fragment$1, { children: MapStep?.(step) ?? renderUnknown(step, UnknownStep) });
|
|
25
|
+
case "agent-step": return /* @__PURE__ */ jsx(Fragment$1, { children: AgentStep?.(step) ?? renderUnknown(step, UnknownStep) });
|
|
26
|
+
case "tool-step": return /* @__PURE__ */ jsx(Fragment$1, { children: ToolStep?.(step) ?? renderUnknown(step, UnknownStep) });
|
|
27
|
+
case "classifier-step": return /* @__PURE__ */ jsx(Fragment$1, { children: ClassifierStep?.(step) ?? renderUnknown(step, UnknownStep) });
|
|
28
|
+
case "foreach-step": return /* @__PURE__ */ jsx(Fragment$1, { children: ForEachStep?.(step) ?? renderUnknown(step, UnknownStep) });
|
|
29
|
+
case "parallel-step": return /* @__PURE__ */ jsx(Fragment$1, { children: ParallelStep?.(step) ?? renderUnknown(step, UnknownStep) });
|
|
30
|
+
case "conditional": return /* @__PURE__ */ jsx(Fragment$1, { children: Conditional?.(step) ?? renderUnknown(step, UnknownStep) });
|
|
31
|
+
case "loop-step": return /* @__PURE__ */ jsx(Fragment$1, { children: LoopStep?.(step) ?? renderUnknown(step, UnknownStep) });
|
|
32
|
+
case "sleep-step": return /* @__PURE__ */ jsx(Fragment$1, { children: SleepStep?.(step) ?? renderUnknown(step, UnknownStep) });
|
|
33
|
+
case "sleep-until-step": return /* @__PURE__ */ jsx(Fragment$1, { children: SleepUntilStep?.(step) ?? renderUnknown(step, UnknownStep) });
|
|
34
|
+
case "nested-workflow-step": return /* @__PURE__ */ jsx(Fragment$1, { children: NestedWorkflowStep?.(step) ?? renderUnknown(step, UnknownStep) });
|
|
35
|
+
default: return /* @__PURE__ */ jsx(Fragment$1, { children: renderUnknown(step, UnknownStep) });
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const WorkflowStepFactory = memo(WorkflowStepFactoryComponent);
|
|
39
|
+
export { CLIENT_MESSAGE_ID_KEY, MastraReactProvider, WorkflowStepFactory, accumulateChunk, accumulateNetworkChunk, finishStreamingAssistantMessage, fromCoreUserMessageToMastraDBMessage, fromCoreUserMessagesToMastraDBMessage, mapWorkflowStreamChunkToWatchResult, playStreamWithWebAudio, recordMicrophoneToFile, useCancelWorkflowRun, useChat, useCreateWorkflowRun, useMastraClient, useSpeechRecognition, useStreamWorkflow };
|
|
10
40
|
|
|
11
|
-
// src/mastra-client-context.tsx
|
|
12
|
-
var MastraClientContext = createContext({});
|
|
13
|
-
var MastraClientProvider = ({
|
|
14
|
-
children,
|
|
15
|
-
baseUrl,
|
|
16
|
-
headers,
|
|
17
|
-
apiPrefix,
|
|
18
|
-
credentials = "include",
|
|
19
|
-
customFetch
|
|
20
|
-
}) => {
|
|
21
|
-
const client = createMastraClient(baseUrl, headers, apiPrefix, credentials, customFetch);
|
|
22
|
-
return /* @__PURE__ */ jsx(MastraClientContext.Provider, { value: client, children });
|
|
23
|
-
};
|
|
24
|
-
var useMastraClient = () => useContext(MastraClientContext);
|
|
25
|
-
var IPV4_LOOPBACK_RE = /^127\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
|
|
26
|
-
var isIPv4Loopback = (hostname) => {
|
|
27
|
-
const m = IPV4_LOOPBACK_RE.exec(hostname);
|
|
28
|
-
if (!m) return false;
|
|
29
|
-
return +m[1] <= 255 && +m[2] <= 255 && +m[3] <= 255;
|
|
30
|
-
};
|
|
31
|
-
var isLocalUrl = (url) => {
|
|
32
|
-
if (!url) return true;
|
|
33
|
-
try {
|
|
34
|
-
const { hostname } = new URL(url);
|
|
35
|
-
return hostname === "localhost" || hostname.endsWith(".localhost") || isIPv4Loopback(hostname) || hostname === "::1" || hostname === "[::1]";
|
|
36
|
-
} catch {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
var createMastraClient = (baseUrl, mastraClientHeaders = {}, apiPrefix, credentials = "include", customFetch) => {
|
|
41
|
-
return new MastraClient({
|
|
42
|
-
baseUrl: baseUrl || "",
|
|
43
|
-
headers: isLocalUrl(baseUrl) ? { ...mastraClientHeaders, "x-mastra-dev-playground": "true" } : mastraClientHeaders,
|
|
44
|
-
apiPrefix,
|
|
45
|
-
credentials,
|
|
46
|
-
fetch: customFetch
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
var MastraReactProvider = ({
|
|
50
|
-
children,
|
|
51
|
-
baseUrl,
|
|
52
|
-
headers,
|
|
53
|
-
apiPrefix,
|
|
54
|
-
credentials,
|
|
55
|
-
customFetch
|
|
56
|
-
}) => {
|
|
57
|
-
return /* @__PURE__ */ jsx(
|
|
58
|
-
MastraClientProvider,
|
|
59
|
-
{
|
|
60
|
-
baseUrl,
|
|
61
|
-
headers,
|
|
62
|
-
apiPrefix,
|
|
63
|
-
credentials,
|
|
64
|
-
customFetch,
|
|
65
|
-
children
|
|
66
|
-
}
|
|
67
|
-
);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// src/agent/extractRunIdFromMessages.ts
|
|
71
|
-
var extractRunIdFromMessages = (messages) => {
|
|
72
|
-
for (const message of messages) {
|
|
73
|
-
const metadataSources = [
|
|
74
|
-
message.metadata?.pendingToolApprovals,
|
|
75
|
-
message.metadata?.requireApprovalMetadata,
|
|
76
|
-
message.metadata?.suspendedTools
|
|
77
|
-
];
|
|
78
|
-
for (const source of metadataSources) {
|
|
79
|
-
if (!source || typeof source !== "object") continue;
|
|
80
|
-
for (const suspensionData of Object.values(source)) {
|
|
81
|
-
if (suspensionData && typeof suspensionData === "object" && typeof suspensionData.runId === "string" && suspensionData.runId.length > 0) {
|
|
82
|
-
return suspensionData.runId;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return void 0;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
// src/lib/ai-sdk/utils/formatCompletionFeedback.ts
|
|
91
|
-
var formatBaseCompletionFeedback = (result, maxIterationReached, formatScorerHeading, incompleteMessage) => {
|
|
92
|
-
const lines = [];
|
|
93
|
-
lines.push("#### Completion Check Results");
|
|
94
|
-
lines.push("");
|
|
95
|
-
lines.push(`Overall: ${result.complete ? "\u2705 COMPLETE" : "\u274C NOT COMPLETE"}`);
|
|
96
|
-
lines.push(`Duration: ${result.totalDuration}ms`);
|
|
97
|
-
if (result.timedOut) {
|
|
98
|
-
lines.push("\u26A0\uFE0F Scoring timed out");
|
|
99
|
-
}
|
|
100
|
-
lines.push("");
|
|
101
|
-
for (const scorer of result.scorers) {
|
|
102
|
-
lines.push(formatScorerHeading(scorer));
|
|
103
|
-
lines.push(`Score: ${scorer.score} ${scorer.passed ? "\u2705" : "\u274C"}`);
|
|
104
|
-
if (scorer.reason) {
|
|
105
|
-
lines.push(`Reason: ${scorer.reason}`);
|
|
106
|
-
}
|
|
107
|
-
lines.push("");
|
|
108
|
-
}
|
|
109
|
-
if (result.complete) {
|
|
110
|
-
lines.push("\u2705 The task is complete.");
|
|
111
|
-
} else if (maxIterationReached) {
|
|
112
|
-
lines.push("\u26A0\uFE0F Max iterations reached.");
|
|
113
|
-
} else {
|
|
114
|
-
lines.push(incompleteMessage);
|
|
115
|
-
}
|
|
116
|
-
return lines.join("\n");
|
|
117
|
-
};
|
|
118
|
-
var formatCompletionFeedback = (result, maxIterationReached) => {
|
|
119
|
-
return formatBaseCompletionFeedback(
|
|
120
|
-
result,
|
|
121
|
-
maxIterationReached,
|
|
122
|
-
(scorer) => `###### ${scorer.scorerName} (${scorer.scorerId})`,
|
|
123
|
-
"\u{1F504} Will continue working on the task."
|
|
124
|
-
);
|
|
125
|
-
};
|
|
126
|
-
var formatStreamCompletionFeedback = (result, maxIterationReached) => {
|
|
127
|
-
return formatBaseCompletionFeedback(
|
|
128
|
-
result,
|
|
129
|
-
maxIterationReached,
|
|
130
|
-
(scorer) => `**${scorer.scorerName}** (${scorer.scorerId})`,
|
|
131
|
-
"\u{1F504} The task is not yet complete. Please continue working based on the feedback above."
|
|
132
|
-
);
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
// src/lib/ai-sdk/utils/toUIMessage.ts
|
|
136
|
-
var mapWorkflowStreamChunkToWatchResult = (prev, chunk) => {
|
|
137
|
-
if (chunk.type === "workflow-start") {
|
|
138
|
-
return {
|
|
139
|
-
input: prev?.input,
|
|
140
|
-
status: "running",
|
|
141
|
-
steps: prev?.steps || {}
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
if (chunk.type === "workflow-canceled") {
|
|
145
|
-
return {
|
|
146
|
-
...prev,
|
|
147
|
-
status: "canceled"
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
if (chunk.type === "workflow-finish") {
|
|
151
|
-
const finalStatus = chunk.payload.workflowStatus;
|
|
152
|
-
const prevSteps = prev?.steps ?? {};
|
|
153
|
-
const lastStep = Object.values(prevSteps).pop();
|
|
154
|
-
return {
|
|
155
|
-
...prev,
|
|
156
|
-
status: chunk.payload.workflowStatus,
|
|
157
|
-
...finalStatus === "success" && lastStep?.status === "success" ? { result: lastStep?.output } : finalStatus === "failed" && lastStep?.status === "failed" ? { error: lastStep?.error } : finalStatus === "tripwire" && chunk.payload.tripwire ? { tripwire: chunk.payload.tripwire } : {}
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
const { stepCallId, stepName, ...newPayload } = chunk.payload ?? {};
|
|
161
|
-
const newSteps = {
|
|
162
|
-
...prev?.steps,
|
|
163
|
-
[chunk.payload.id]: {
|
|
164
|
-
...prev?.steps?.[chunk.payload.id],
|
|
165
|
-
...newPayload
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
if (chunk.type === "workflow-step-start") {
|
|
169
|
-
return {
|
|
170
|
-
...prev,
|
|
171
|
-
steps: newSteps
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
if (chunk.type === "workflow-step-suspended") {
|
|
175
|
-
const suspendedStepIds = Object.entries(newSteps).flatMap(
|
|
176
|
-
([stepId, stepResult]) => {
|
|
177
|
-
if (stepResult?.status === "suspended") {
|
|
178
|
-
const nestedPath = stepResult?.suspendPayload?.__workflow_meta?.path;
|
|
179
|
-
return nestedPath ? [[stepId, ...nestedPath]] : [[stepId]];
|
|
180
|
-
}
|
|
181
|
-
return [];
|
|
182
|
-
}
|
|
183
|
-
);
|
|
184
|
-
return {
|
|
185
|
-
...prev,
|
|
186
|
-
status: "suspended",
|
|
187
|
-
steps: newSteps,
|
|
188
|
-
suspendPayload: chunk.payload.suspendPayload,
|
|
189
|
-
suspended: suspendedStepIds
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
if (chunk.type === "workflow-step-waiting") {
|
|
193
|
-
return {
|
|
194
|
-
...prev,
|
|
195
|
-
status: "waiting",
|
|
196
|
-
steps: newSteps
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
if (chunk.type === "workflow-step-progress") {
|
|
200
|
-
const progressSteps = {
|
|
201
|
-
...prev?.steps,
|
|
202
|
-
[chunk.payload.id]: {
|
|
203
|
-
...prev?.steps?.[chunk.payload.id],
|
|
204
|
-
foreachProgress: {
|
|
205
|
-
completedCount: chunk.payload.completedCount,
|
|
206
|
-
totalCount: chunk.payload.totalCount,
|
|
207
|
-
currentIndex: chunk.payload.currentIndex,
|
|
208
|
-
iterationStatus: chunk.payload.iterationStatus,
|
|
209
|
-
iterationOutput: chunk.payload.iterationOutput
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
return {
|
|
214
|
-
...prev,
|
|
215
|
-
steps: progressSteps
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
if (chunk.type === "workflow-step-result") {
|
|
219
|
-
return {
|
|
220
|
-
...prev,
|
|
221
|
-
steps: newSteps
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
return prev;
|
|
225
|
-
};
|
|
226
|
-
var toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
227
|
-
const result = [...conversation];
|
|
228
|
-
if (chunk.type.startsWith("data-")) {
|
|
229
|
-
const dataPart = {
|
|
230
|
-
type: chunk.type,
|
|
231
|
-
data: "data" in chunk ? chunk.data : void 0,
|
|
232
|
-
..."id" in chunk && typeof chunk.id === "string" ? { id: chunk.id } : {}
|
|
233
|
-
};
|
|
234
|
-
const lastMessage = result[result.length - 1];
|
|
235
|
-
if (!lastMessage || lastMessage.role !== "assistant") {
|
|
236
|
-
const newMessage = {
|
|
237
|
-
id: `data-${chunk.runId}-${Date.now()}`,
|
|
238
|
-
role: "assistant",
|
|
239
|
-
parts: [dataPart],
|
|
240
|
-
metadata
|
|
241
|
-
};
|
|
242
|
-
return [...result, newMessage];
|
|
243
|
-
}
|
|
244
|
-
const updatedMessage = {
|
|
245
|
-
...lastMessage,
|
|
246
|
-
parts: [...lastMessage.parts, dataPart]
|
|
247
|
-
};
|
|
248
|
-
return [...result.slice(0, -1), updatedMessage];
|
|
249
|
-
}
|
|
250
|
-
switch (chunk.type) {
|
|
251
|
-
case "tripwire": {
|
|
252
|
-
const newMessage = {
|
|
253
|
-
id: `tripwire-${chunk.runId + Date.now()}`,
|
|
254
|
-
role: "assistant",
|
|
255
|
-
parts: [
|
|
256
|
-
{
|
|
257
|
-
type: "text",
|
|
258
|
-
text: chunk.payload.reason
|
|
259
|
-
}
|
|
260
|
-
],
|
|
261
|
-
metadata: {
|
|
262
|
-
...metadata,
|
|
263
|
-
status: "tripwire",
|
|
264
|
-
tripwire: {
|
|
265
|
-
retry: chunk.payload.retry,
|
|
266
|
-
tripwirePayload: chunk.payload.metadata,
|
|
267
|
-
processorId: chunk.payload.processorId
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
return [...result, newMessage];
|
|
272
|
-
}
|
|
273
|
-
case "start": {
|
|
274
|
-
const newMessage = {
|
|
275
|
-
id: typeof chunk.payload.messageId === "string" ? chunk.payload.messageId : `start-${chunk.runId + Date.now()}`,
|
|
276
|
-
role: "assistant",
|
|
277
|
-
parts: [],
|
|
278
|
-
metadata
|
|
279
|
-
};
|
|
280
|
-
return [...result, newMessage];
|
|
281
|
-
}
|
|
282
|
-
case "text-start": {
|
|
283
|
-
const lastMessage = result[result.length - 1];
|
|
284
|
-
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
285
|
-
const textId = chunk.payload.id || `text-${Date.now()}`;
|
|
286
|
-
const newTextPart = {
|
|
287
|
-
type: "text",
|
|
288
|
-
text: "",
|
|
289
|
-
state: "streaming",
|
|
290
|
-
textId,
|
|
291
|
-
providerMetadata: chunk.payload.providerMetadata
|
|
292
|
-
};
|
|
293
|
-
if (lastMessage.metadata?.completionResult) {
|
|
294
|
-
const newMessage = {
|
|
295
|
-
id: `start-${chunk.runId}-${Date.now()}`,
|
|
296
|
-
role: "assistant",
|
|
297
|
-
parts: [newTextPart],
|
|
298
|
-
metadata
|
|
299
|
-
};
|
|
300
|
-
return [...result, newMessage];
|
|
301
|
-
}
|
|
302
|
-
const parts = [...lastMessage.parts];
|
|
303
|
-
parts.push(newTextPart);
|
|
304
|
-
return [
|
|
305
|
-
...result.slice(0, -1),
|
|
306
|
-
{
|
|
307
|
-
...lastMessage,
|
|
308
|
-
parts
|
|
309
|
-
}
|
|
310
|
-
];
|
|
311
|
-
}
|
|
312
|
-
case "background-task-progress": {
|
|
313
|
-
const lastMessage = result[result.length - 1];
|
|
314
|
-
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
315
|
-
return [
|
|
316
|
-
...result.slice(0, -1),
|
|
317
|
-
{
|
|
318
|
-
...lastMessage,
|
|
319
|
-
metadata: {
|
|
320
|
-
mode: metadata.mode,
|
|
321
|
-
...lastMessage.metadata,
|
|
322
|
-
runningBackgroundTasksCount: chunk.payload.runningCount
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
];
|
|
326
|
-
}
|
|
327
|
-
case "text-delta": {
|
|
328
|
-
const lastMessage = result[result.length - 1];
|
|
329
|
-
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
330
|
-
const parts = [...lastMessage.parts];
|
|
331
|
-
const textId = chunk.payload.id;
|
|
332
|
-
let textPartIndex = textId ? parts.findLastIndex((part) => part.type === "text" && part.textId === textId) : -1;
|
|
333
|
-
if (textPartIndex === -1) {
|
|
334
|
-
textPartIndex = parts.findLastIndex(
|
|
335
|
-
(part) => part.type === "text" && part.state === "streaming"
|
|
336
|
-
);
|
|
337
|
-
}
|
|
338
|
-
if (textPartIndex === -1) {
|
|
339
|
-
const newTextPart = {
|
|
340
|
-
type: "text",
|
|
341
|
-
text: chunk.payload.text,
|
|
342
|
-
state: "streaming",
|
|
343
|
-
textId,
|
|
344
|
-
providerMetadata: chunk.payload.providerMetadata
|
|
345
|
-
};
|
|
346
|
-
parts.push(newTextPart);
|
|
347
|
-
} else {
|
|
348
|
-
const textPart = parts[textPartIndex];
|
|
349
|
-
if (textPart.type === "text") {
|
|
350
|
-
const extendedTextPart = textPart;
|
|
351
|
-
const updatedTextPart = {
|
|
352
|
-
...extendedTextPart,
|
|
353
|
-
text: extendedTextPart.text + chunk.payload.text,
|
|
354
|
-
state: "streaming"
|
|
355
|
-
};
|
|
356
|
-
parts[textPartIndex] = updatedTextPart;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
return [
|
|
360
|
-
...result.slice(0, -1),
|
|
361
|
-
{
|
|
362
|
-
...lastMessage,
|
|
363
|
-
parts
|
|
364
|
-
}
|
|
365
|
-
];
|
|
366
|
-
}
|
|
367
|
-
case "reasoning-delta": {
|
|
368
|
-
const lastMessage = result[result.length - 1];
|
|
369
|
-
if (!lastMessage || lastMessage.role !== "assistant") {
|
|
370
|
-
const newMessage = {
|
|
371
|
-
id: `reasoning-${chunk.runId + Date.now()}`,
|
|
372
|
-
role: "assistant",
|
|
373
|
-
parts: [
|
|
374
|
-
{
|
|
375
|
-
type: "reasoning",
|
|
376
|
-
text: chunk.payload.text,
|
|
377
|
-
state: "streaming",
|
|
378
|
-
providerMetadata: chunk.payload.providerMetadata
|
|
379
|
-
}
|
|
380
|
-
],
|
|
381
|
-
metadata
|
|
382
|
-
};
|
|
383
|
-
return [...result, newMessage];
|
|
384
|
-
}
|
|
385
|
-
const parts = [...lastMessage.parts];
|
|
386
|
-
let reasoningPartIndex = parts.findIndex((part) => part.type === "reasoning");
|
|
387
|
-
if (reasoningPartIndex === -1) {
|
|
388
|
-
parts.push({
|
|
389
|
-
type: "reasoning",
|
|
390
|
-
text: chunk.payload.text,
|
|
391
|
-
state: "streaming",
|
|
392
|
-
providerMetadata: chunk.payload.providerMetadata
|
|
393
|
-
});
|
|
394
|
-
} else {
|
|
395
|
-
const reasoningPart = parts[reasoningPartIndex];
|
|
396
|
-
if (reasoningPart.type === "reasoning") {
|
|
397
|
-
parts[reasoningPartIndex] = {
|
|
398
|
-
...reasoningPart,
|
|
399
|
-
text: reasoningPart.text + chunk.payload.text,
|
|
400
|
-
state: "streaming"
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
return [
|
|
405
|
-
...result.slice(0, -1),
|
|
406
|
-
{
|
|
407
|
-
...lastMessage,
|
|
408
|
-
parts
|
|
409
|
-
}
|
|
410
|
-
];
|
|
411
|
-
}
|
|
412
|
-
case "tool-call": {
|
|
413
|
-
const lastMessage = result[result.length - 1];
|
|
414
|
-
if (!lastMessage || lastMessage.role !== "assistant") {
|
|
415
|
-
const newMessage = {
|
|
416
|
-
id: `tool-call-${chunk.runId + Date.now()}`,
|
|
417
|
-
role: "assistant",
|
|
418
|
-
parts: [
|
|
419
|
-
{
|
|
420
|
-
type: "dynamic-tool",
|
|
421
|
-
toolName: chunk.payload.toolName,
|
|
422
|
-
toolCallId: chunk.payload.toolCallId,
|
|
423
|
-
state: "input-available",
|
|
424
|
-
input: chunk.payload.args,
|
|
425
|
-
callProviderMetadata: chunk.payload.providerMetadata
|
|
426
|
-
}
|
|
427
|
-
],
|
|
428
|
-
metadata
|
|
429
|
-
};
|
|
430
|
-
return [...result, newMessage];
|
|
431
|
-
}
|
|
432
|
-
const parts = [...lastMessage.parts];
|
|
433
|
-
parts.push({
|
|
434
|
-
type: "dynamic-tool",
|
|
435
|
-
toolName: chunk.payload.toolName,
|
|
436
|
-
toolCallId: chunk.payload.toolCallId,
|
|
437
|
-
state: "input-available",
|
|
438
|
-
input: chunk.payload.args,
|
|
439
|
-
callProviderMetadata: chunk.payload.providerMetadata
|
|
440
|
-
});
|
|
441
|
-
return [
|
|
442
|
-
...result.slice(0, -1),
|
|
443
|
-
{
|
|
444
|
-
...lastMessage,
|
|
445
|
-
parts
|
|
446
|
-
}
|
|
447
|
-
];
|
|
448
|
-
}
|
|
449
|
-
case "tool-error":
|
|
450
|
-
case "tool-result":
|
|
451
|
-
case "background-task-completed":
|
|
452
|
-
case "background-task-failed": {
|
|
453
|
-
const isBgTaskEvent = chunk.type === "background-task-completed" || chunk.type === "background-task-failed";
|
|
454
|
-
const location = locateToolPart(result, chunk.payload.toolCallId, isBgTaskEvent);
|
|
455
|
-
if (!location) return result;
|
|
456
|
-
const { messageIndex, toolPartIndex } = location;
|
|
457
|
-
const targetMessage = result[messageIndex];
|
|
458
|
-
if (!targetMessage || targetMessage.role !== "assistant") return result;
|
|
459
|
-
const parts = [...targetMessage.parts];
|
|
460
|
-
const toolPart = toolPartIndex >= 0 ? parts[toolPartIndex] : void 0;
|
|
461
|
-
if (toolPart && (toolPart.type === "dynamic-tool" || typeof toolPart.type === "string" && toolPart.type.startsWith("tool-"))) {
|
|
462
|
-
const toolName = "toolName" in toolPart && typeof toolPart.toolName === "string" ? toolPart.toolName : typeof toolPart.type === "string" && toolPart.type.startsWith("tool-") ? toolPart.type.substring(5) : "";
|
|
463
|
-
const toolCallId = toolPart.toolCallId;
|
|
464
|
-
if ((chunk.type === "tool-result" || chunk.type === "background-task-completed") && chunk.payload.isError || chunk.type === "tool-error" || chunk.type === "background-task-failed") {
|
|
465
|
-
const error = chunk.type === "tool-error" || chunk.type === "background-task-failed" ? chunk.payload.error : chunk.payload.result;
|
|
466
|
-
parts[toolPartIndex] = {
|
|
467
|
-
type: "dynamic-tool",
|
|
468
|
-
toolName,
|
|
469
|
-
toolCallId,
|
|
470
|
-
state: "output-error",
|
|
471
|
-
input: toolPart.input,
|
|
472
|
-
errorText: typeof error === "string" ? error : error instanceof Error ? error.message : error?.message ?? String(error),
|
|
473
|
-
callProviderMetadata: chunk.payload.providerMetadata
|
|
474
|
-
};
|
|
475
|
-
} else {
|
|
476
|
-
const isWorkflow = Boolean(chunk.payload.result?.result?.steps);
|
|
477
|
-
const isAgent = chunk?.from === "AGENT";
|
|
478
|
-
let output;
|
|
479
|
-
if (isWorkflow) {
|
|
480
|
-
output = chunk.payload.result?.result;
|
|
481
|
-
} else if (isAgent) {
|
|
482
|
-
const existingOutput = parts[toolPartIndex].output;
|
|
483
|
-
output = existingOutput ? {
|
|
484
|
-
...chunk.payload.result,
|
|
485
|
-
childMessages: existingOutput.childMessages?.length ? existingOutput.childMessages : chunk.payload.result?.childMessages
|
|
486
|
-
} : chunk.payload.result;
|
|
487
|
-
} else {
|
|
488
|
-
output = chunk.payload.result;
|
|
489
|
-
}
|
|
490
|
-
parts[toolPartIndex] = {
|
|
491
|
-
type: "dynamic-tool",
|
|
492
|
-
toolName,
|
|
493
|
-
toolCallId,
|
|
494
|
-
state: "output-available",
|
|
495
|
-
input: toolPart.input,
|
|
496
|
-
output,
|
|
497
|
-
callProviderMetadata: chunk.payload.providerMetadata
|
|
498
|
-
};
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
const nextMessage = {
|
|
502
|
-
...targetMessage,
|
|
503
|
-
parts,
|
|
504
|
-
metadata: mergeBgTaskMetadata(targetMessage.metadata, metadata.mode, {
|
|
505
|
-
resetRunningCount: isBgTaskEvent,
|
|
506
|
-
perTaskEntry: isBgTaskEvent ? {
|
|
507
|
-
toolCallId: chunk.payload.toolCallId,
|
|
508
|
-
completedAt: chunk.payload.completedAt,
|
|
509
|
-
taskId: chunk.payload.taskId
|
|
510
|
-
} : void 0
|
|
511
|
-
})
|
|
512
|
-
};
|
|
513
|
-
return [...result.slice(0, messageIndex), nextMessage, ...result.slice(messageIndex + 1)];
|
|
514
|
-
}
|
|
515
|
-
case "background-task-running": {
|
|
516
|
-
const location = locateToolPart(result, chunk.payload.toolCallId, true);
|
|
517
|
-
if (!location) return result;
|
|
518
|
-
const { messageIndex } = location;
|
|
519
|
-
const targetMessage = result[messageIndex];
|
|
520
|
-
if (!targetMessage || targetMessage.role !== "assistant") return result;
|
|
521
|
-
return [
|
|
522
|
-
...result.slice(0, messageIndex),
|
|
523
|
-
{
|
|
524
|
-
...targetMessage,
|
|
525
|
-
metadata: mergeBgTaskMetadata(targetMessage.metadata, metadata.mode, {
|
|
526
|
-
perTaskEntry: {
|
|
527
|
-
toolCallId: chunk.payload.toolCallId,
|
|
528
|
-
startedAt: chunk.payload.startedAt,
|
|
529
|
-
taskId: chunk.payload.taskId
|
|
530
|
-
}
|
|
531
|
-
})
|
|
532
|
-
},
|
|
533
|
-
...result.slice(messageIndex + 1)
|
|
534
|
-
];
|
|
535
|
-
}
|
|
536
|
-
case "tool-output":
|
|
537
|
-
case "background-task-output": {
|
|
538
|
-
const isBgTaskOutput = chunk.type === "background-task-output";
|
|
539
|
-
const location = locateToolPart(result, chunk.payload.toolCallId, isBgTaskOutput);
|
|
540
|
-
if (!location || location.toolPartIndex < 0) return result;
|
|
541
|
-
const { messageIndex, toolPartIndex } = location;
|
|
542
|
-
const targetMessage = result[messageIndex];
|
|
543
|
-
if (!targetMessage || targetMessage.role !== "assistant") return result;
|
|
544
|
-
const parts = [...targetMessage.parts];
|
|
545
|
-
const toolPart = parts[toolPartIndex];
|
|
546
|
-
if (toolPart.type === "dynamic-tool" || typeof toolPart.type === "string" && toolPart.type.startsWith("tool-")) {
|
|
547
|
-
const toolName = "toolName" in toolPart && typeof toolPart.toolName === "string" ? toolPart.toolName : typeof toolPart.type === "string" && toolPart.type.startsWith("tool-") ? toolPart.type.substring(5) : "";
|
|
548
|
-
const toolCallId = toolPart.toolCallId;
|
|
549
|
-
const input = toolPart.input;
|
|
550
|
-
const payloadOutput = chunk.type === "background-task-output" ? chunk.payload.payload.payload.output : chunk.payload.output;
|
|
551
|
-
if (payloadOutput?.type?.startsWith("workflow-")) {
|
|
552
|
-
const existingWorkflowState = toolPart.output || {};
|
|
553
|
-
const updatedWorkflowState = mapWorkflowStreamChunkToWatchResult(existingWorkflowState, payloadOutput);
|
|
554
|
-
parts[toolPartIndex] = {
|
|
555
|
-
type: "dynamic-tool",
|
|
556
|
-
toolName,
|
|
557
|
-
toolCallId,
|
|
558
|
-
state: "input-streaming",
|
|
559
|
-
input,
|
|
560
|
-
output: updatedWorkflowState
|
|
561
|
-
};
|
|
562
|
-
} else if (payloadOutput?.from === "AGENT" || payloadOutput?.from === "USER" && payloadOutput?.payload?.output?.type?.startsWith("workflow-")) {
|
|
563
|
-
return toUIMessageFromAgent(payloadOutput, conversation, metadata, toolCallId, toolName);
|
|
564
|
-
} else {
|
|
565
|
-
const currentOutput = toolPart.output || [];
|
|
566
|
-
const existingOutput = Array.isArray(currentOutput) ? currentOutput : [];
|
|
567
|
-
parts[toolPartIndex] = {
|
|
568
|
-
type: "dynamic-tool",
|
|
569
|
-
toolName,
|
|
570
|
-
toolCallId,
|
|
571
|
-
state: "input-streaming",
|
|
572
|
-
input,
|
|
573
|
-
output: [...existingOutput, payloadOutput]
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
return [
|
|
578
|
-
...result.slice(0, messageIndex),
|
|
579
|
-
{
|
|
580
|
-
...targetMessage,
|
|
581
|
-
parts
|
|
582
|
-
},
|
|
583
|
-
...result.slice(messageIndex + 1)
|
|
584
|
-
];
|
|
585
|
-
}
|
|
586
|
-
case "is-task-complete": {
|
|
587
|
-
if (chunk.payload.suppressFeedback) return result;
|
|
588
|
-
const feedback = formatStreamCompletionFeedback(
|
|
589
|
-
{
|
|
590
|
-
complete: chunk.payload.passed,
|
|
591
|
-
scorers: chunk.payload.results,
|
|
592
|
-
totalDuration: chunk.payload.duration,
|
|
593
|
-
timedOut: chunk.payload.timedOut},
|
|
594
|
-
chunk.payload.maxIterationReached
|
|
595
|
-
);
|
|
596
|
-
const newMessage = {
|
|
597
|
-
id: `is-task-complete-${chunk.runId + Date.now()}`,
|
|
598
|
-
role: "assistant",
|
|
599
|
-
parts: [
|
|
600
|
-
{
|
|
601
|
-
type: "text",
|
|
602
|
-
text: feedback
|
|
603
|
-
}
|
|
604
|
-
],
|
|
605
|
-
metadata: {
|
|
606
|
-
...metadata,
|
|
607
|
-
completionResult: {
|
|
608
|
-
passed: chunk.payload.passed
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
};
|
|
612
|
-
return [...result, newMessage];
|
|
613
|
-
}
|
|
614
|
-
case "source": {
|
|
615
|
-
const lastMessage = result[result.length - 1];
|
|
616
|
-
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
617
|
-
const parts = [...lastMessage.parts];
|
|
618
|
-
if (chunk.payload.sourceType === "url") {
|
|
619
|
-
parts.push({
|
|
620
|
-
type: "source-url",
|
|
621
|
-
sourceId: chunk.payload.id,
|
|
622
|
-
url: chunk.payload.url || "",
|
|
623
|
-
title: chunk.payload.title,
|
|
624
|
-
providerMetadata: chunk.payload.providerMetadata
|
|
625
|
-
});
|
|
626
|
-
} else if (chunk.payload.sourceType === "document") {
|
|
627
|
-
parts.push({
|
|
628
|
-
type: "source-document",
|
|
629
|
-
sourceId: chunk.payload.id,
|
|
630
|
-
mediaType: chunk.payload.mimeType || "application/octet-stream",
|
|
631
|
-
title: chunk.payload.title,
|
|
632
|
-
filename: chunk.payload.filename,
|
|
633
|
-
providerMetadata: chunk.payload.providerMetadata
|
|
634
|
-
});
|
|
635
|
-
}
|
|
636
|
-
return [
|
|
637
|
-
...result.slice(0, -1),
|
|
638
|
-
{
|
|
639
|
-
...lastMessage,
|
|
640
|
-
parts
|
|
641
|
-
}
|
|
642
|
-
];
|
|
643
|
-
}
|
|
644
|
-
case "file": {
|
|
645
|
-
const lastMessage = result[result.length - 1];
|
|
646
|
-
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
647
|
-
const parts = [...lastMessage.parts];
|
|
648
|
-
let url;
|
|
649
|
-
if (typeof chunk.payload.data === "string") {
|
|
650
|
-
url = chunk.payload.base64 ? `data:${chunk.payload.mimeType};base64,${chunk.payload.data}` : `data:${chunk.payload.mimeType},${encodeURIComponent(chunk.payload.data)}`;
|
|
651
|
-
} else {
|
|
652
|
-
const base64 = btoa(String.fromCharCode(...chunk.payload.data));
|
|
653
|
-
url = `data:${chunk.payload.mimeType};base64,${base64}`;
|
|
654
|
-
}
|
|
655
|
-
parts.push({
|
|
656
|
-
type: "file",
|
|
657
|
-
mediaType: chunk.payload.mimeType,
|
|
658
|
-
url,
|
|
659
|
-
providerMetadata: chunk.payload.providerMetadata
|
|
660
|
-
});
|
|
661
|
-
return [
|
|
662
|
-
...result.slice(0, -1),
|
|
663
|
-
{
|
|
664
|
-
...lastMessage,
|
|
665
|
-
parts
|
|
666
|
-
}
|
|
667
|
-
];
|
|
668
|
-
}
|
|
669
|
-
case "tool-call-approval": {
|
|
670
|
-
const lastMessage = result[result.length - 1];
|
|
671
|
-
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
672
|
-
const lastRequireApprovalMetadata = lastMessage.metadata?.mode === "stream" ? lastMessage.metadata?.requireApprovalMetadata : {};
|
|
673
|
-
return [
|
|
674
|
-
...result.slice(0, -1),
|
|
675
|
-
{
|
|
676
|
-
...lastMessage,
|
|
677
|
-
metadata: {
|
|
678
|
-
...lastMessage.metadata,
|
|
679
|
-
mode: "stream",
|
|
680
|
-
requireApprovalMetadata: {
|
|
681
|
-
...lastRequireApprovalMetadata,
|
|
682
|
-
[chunk.payload.toolName]: {
|
|
683
|
-
toolCallId: chunk.payload.toolCallId,
|
|
684
|
-
toolName: chunk.payload.toolName,
|
|
685
|
-
args: chunk.payload.args
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
];
|
|
691
|
-
}
|
|
692
|
-
case "tool-call-suspended": {
|
|
693
|
-
const lastMessage = result[result.length - 1];
|
|
694
|
-
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
695
|
-
const lastSuspendedTools = lastMessage.metadata?.mode === "stream" ? lastMessage.metadata?.suspendedTools : {};
|
|
696
|
-
return [
|
|
697
|
-
...result.slice(0, -1),
|
|
698
|
-
{
|
|
699
|
-
...lastMessage,
|
|
700
|
-
metadata: {
|
|
701
|
-
...lastMessage.metadata,
|
|
702
|
-
mode: "stream",
|
|
703
|
-
suspendedTools: {
|
|
704
|
-
...lastSuspendedTools,
|
|
705
|
-
[chunk.payload.toolName]: {
|
|
706
|
-
toolCallId: chunk.payload.toolCallId,
|
|
707
|
-
toolName: chunk.payload.toolName,
|
|
708
|
-
args: chunk.payload.args,
|
|
709
|
-
suspendPayload: chunk.payload.suspendPayload,
|
|
710
|
-
runId: chunk.runId
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
];
|
|
716
|
-
}
|
|
717
|
-
case "finish": {
|
|
718
|
-
const lastMessage = result[result.length - 1];
|
|
719
|
-
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
720
|
-
const parts = lastMessage.parts.map((part) => {
|
|
721
|
-
if (typeof part === "object" && part !== null && "type" in part && "state" in part && part.state === "streaming") {
|
|
722
|
-
if (part.type === "text" || part.type === "reasoning") {
|
|
723
|
-
return { ...part, state: "done" };
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
return part;
|
|
727
|
-
});
|
|
728
|
-
return [
|
|
729
|
-
...result.slice(0, -1),
|
|
730
|
-
{
|
|
731
|
-
...lastMessage,
|
|
732
|
-
parts
|
|
733
|
-
}
|
|
734
|
-
];
|
|
735
|
-
}
|
|
736
|
-
case "error": {
|
|
737
|
-
const newMessage = {
|
|
738
|
-
id: `error-${chunk.runId + Date.now()}`,
|
|
739
|
-
role: "assistant",
|
|
740
|
-
parts: [
|
|
741
|
-
{
|
|
742
|
-
type: "text",
|
|
743
|
-
text: typeof chunk.payload.error === "string" ? chunk.payload.error : JSON.stringify(chunk.payload.error)
|
|
744
|
-
}
|
|
745
|
-
],
|
|
746
|
-
metadata: {
|
|
747
|
-
...metadata,
|
|
748
|
-
status: "error"
|
|
749
|
-
}
|
|
750
|
-
};
|
|
751
|
-
return [...result, newMessage];
|
|
752
|
-
}
|
|
753
|
-
// For all other chunk types, return conversation unchanged
|
|
754
|
-
default:
|
|
755
|
-
return result;
|
|
756
|
-
}
|
|
757
|
-
};
|
|
758
|
-
var toUIMessageFromAgent = (chunk, conversation, metadata, parentToolCallId, parentToolName) => {
|
|
759
|
-
const lastMessage = conversation[conversation.length - 1];
|
|
760
|
-
if (!lastMessage || lastMessage.role !== "assistant") return conversation;
|
|
761
|
-
const parts = [...lastMessage.parts];
|
|
762
|
-
if (chunk.type === "text-delta") {
|
|
763
|
-
const agentChunk = chunk.payload;
|
|
764
|
-
const toolPartIndex = parts.findIndex(
|
|
765
|
-
(part) => part.type === "dynamic-tool" && (parentToolCallId && part.toolCallId === parentToolCallId || parentToolName && part.toolName === parentToolName)
|
|
766
|
-
);
|
|
767
|
-
if (toolPartIndex === -1) return conversation;
|
|
768
|
-
const toolPart = parts[toolPartIndex];
|
|
769
|
-
const childMessages = toolPart?.output?.childMessages || [];
|
|
770
|
-
const lastChildMessage = childMessages[childMessages.length - 1];
|
|
771
|
-
const textMessage = { type: "text", content: (lastChildMessage?.content || "") + agentChunk.text };
|
|
772
|
-
const nextMessages = lastChildMessage?.type === "text" ? [...childMessages.slice(0, -1), textMessage] : [...childMessages, textMessage];
|
|
773
|
-
parts[toolPartIndex] = {
|
|
774
|
-
...toolPart,
|
|
775
|
-
output: {
|
|
776
|
-
childMessages: nextMessages
|
|
777
|
-
}
|
|
778
|
-
};
|
|
779
|
-
} else if (chunk.type === "tool-call") {
|
|
780
|
-
const agentChunk = chunk.payload;
|
|
781
|
-
const toolPartIndex = parts.findIndex(
|
|
782
|
-
(part) => part.type === "dynamic-tool" && (parentToolCallId && part.toolCallId === parentToolCallId || parentToolName && part.toolName === parentToolName)
|
|
783
|
-
);
|
|
784
|
-
if (toolPartIndex === -1) return conversation;
|
|
785
|
-
const toolPart = parts[toolPartIndex];
|
|
786
|
-
const childMessages = toolPart?.output?.childMessages || [];
|
|
787
|
-
parts[toolPartIndex] = {
|
|
788
|
-
...toolPart,
|
|
789
|
-
output: {
|
|
790
|
-
...toolPart?.output,
|
|
791
|
-
childMessages: [
|
|
792
|
-
...childMessages,
|
|
793
|
-
{
|
|
794
|
-
type: "tool",
|
|
795
|
-
toolCallId: agentChunk.toolCallId,
|
|
796
|
-
toolName: agentChunk.toolName,
|
|
797
|
-
args: agentChunk.args
|
|
798
|
-
}
|
|
799
|
-
]
|
|
800
|
-
}
|
|
801
|
-
};
|
|
802
|
-
} else if (chunk.type === "tool-output") {
|
|
803
|
-
const agentChunk = chunk.payload;
|
|
804
|
-
const toolPartIndex = parts.findIndex(
|
|
805
|
-
(part) => part.type === "dynamic-tool" && (parentToolCallId && part.toolCallId === parentToolCallId || parentToolName && part.toolName === parentToolName)
|
|
806
|
-
);
|
|
807
|
-
if (toolPartIndex === -1) return conversation;
|
|
808
|
-
const toolPart = parts[toolPartIndex];
|
|
809
|
-
if (agentChunk?.output?.type?.startsWith("workflow-")) {
|
|
810
|
-
const childMessages = toolPart?.output?.childMessages || [];
|
|
811
|
-
const lastToolIndex = childMessages.length - 1;
|
|
812
|
-
const currentMessage = childMessages[lastToolIndex];
|
|
813
|
-
const actualExistingWorkflowState = currentMessage?.toolOutput || {};
|
|
814
|
-
const updatedWorkflowState = mapWorkflowStreamChunkToWatchResult(actualExistingWorkflowState, agentChunk.output);
|
|
815
|
-
if (lastToolIndex >= 0 && childMessages[lastToolIndex]?.type === "tool") {
|
|
816
|
-
parts[toolPartIndex] = {
|
|
817
|
-
...toolPart,
|
|
818
|
-
output: {
|
|
819
|
-
...toolPart?.output,
|
|
820
|
-
childMessages: [
|
|
821
|
-
...childMessages.slice(0, -1),
|
|
822
|
-
{
|
|
823
|
-
...currentMessage,
|
|
824
|
-
toolOutput: { ...updatedWorkflowState, runId: agentChunk.output.runId }
|
|
825
|
-
}
|
|
826
|
-
]
|
|
827
|
-
}
|
|
828
|
-
};
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
} else if (chunk.type === "tool-result") {
|
|
832
|
-
const agentChunk = chunk.payload;
|
|
833
|
-
const toolPartIndex = parts.findIndex(
|
|
834
|
-
(part) => part.type === "dynamic-tool" && (parentToolCallId && part.toolCallId === parentToolCallId || parentToolName && part.toolName === parentToolName)
|
|
835
|
-
);
|
|
836
|
-
if (toolPartIndex === -1) return conversation;
|
|
837
|
-
const toolPart = parts[toolPartIndex];
|
|
838
|
-
const childMessages = toolPart?.output?.childMessages || [];
|
|
839
|
-
const lastToolIndex = childMessages.length - 1;
|
|
840
|
-
const isWorkflow = agentChunk?.toolName?.startsWith("workflow-");
|
|
841
|
-
if (lastToolIndex >= 0 && childMessages[lastToolIndex]?.type === "tool") {
|
|
842
|
-
parts[toolPartIndex] = {
|
|
843
|
-
...toolPart,
|
|
844
|
-
output: {
|
|
845
|
-
...toolPart?.output,
|
|
846
|
-
childMessages: [
|
|
847
|
-
...childMessages.slice(0, -1),
|
|
848
|
-
{
|
|
849
|
-
...childMessages[lastToolIndex],
|
|
850
|
-
toolOutput: isWorkflow ? { ...agentChunk.result?.result, runId: agentChunk.result?.runId } : agentChunk.result
|
|
851
|
-
}
|
|
852
|
-
]
|
|
853
|
-
}
|
|
854
|
-
};
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
return [
|
|
858
|
-
...conversation.slice(0, -1),
|
|
859
|
-
{
|
|
860
|
-
...lastMessage,
|
|
861
|
-
parts
|
|
862
|
-
}
|
|
863
|
-
];
|
|
864
|
-
};
|
|
865
|
-
var findMessageIndexByToolCallId = (messages, toolCallId) => {
|
|
866
|
-
let count = 0;
|
|
867
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
868
|
-
const maxMessagesBack = 10;
|
|
869
|
-
if (count > maxMessagesBack) {
|
|
870
|
-
return -1;
|
|
871
|
-
}
|
|
872
|
-
const message = messages[i];
|
|
873
|
-
if (message.role !== "assistant") {
|
|
874
|
-
continue;
|
|
875
|
-
}
|
|
876
|
-
for (const part of message.parts) {
|
|
877
|
-
if (part.type === "dynamic-tool" && part.toolCallId === toolCallId) {
|
|
878
|
-
return i;
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
count++;
|
|
882
|
-
}
|
|
883
|
-
return -1;
|
|
884
|
-
};
|
|
885
|
-
var locateToolPart = (messages, toolCallId, allowMetadataOnlyMatch) => {
|
|
886
|
-
const lastMessage = messages[messages.length - 1];
|
|
887
|
-
if (lastMessage && lastMessage.role === "assistant") {
|
|
888
|
-
const toolPartIndex2 = lastMessage.parts.findIndex(
|
|
889
|
-
(part) => (part.type === "dynamic-tool" || typeof part.type === "string" && part.type.startsWith("tool-")) && "toolCallId" in part && part.toolCallId === toolCallId
|
|
890
|
-
);
|
|
891
|
-
if (toolPartIndex2 !== -1) {
|
|
892
|
-
return { messageIndex: messages.length - 1, toolPartIndex: toolPartIndex2 };
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
const messageIndex = findMessageIndexByToolCallId(messages, toolCallId);
|
|
896
|
-
if (messageIndex === -1) return null;
|
|
897
|
-
const message = messages[messageIndex];
|
|
898
|
-
if (!message || message.role !== "assistant") return null;
|
|
899
|
-
const toolPartIndex = message.parts.findIndex(
|
|
900
|
-
(part) => (part.type === "dynamic-tool" || typeof part.type === "string" && part.type.startsWith("tool-")) && "toolCallId" in part && part.toolCallId === toolCallId
|
|
901
|
-
);
|
|
902
|
-
if (toolPartIndex === -1) {
|
|
903
|
-
return allowMetadataOnlyMatch ? { messageIndex, toolPartIndex: -1 } : null;
|
|
904
|
-
}
|
|
905
|
-
return { messageIndex, toolPartIndex };
|
|
906
|
-
};
|
|
907
|
-
var mergeBgTaskMetadata = (existing, mode, args) => {
|
|
908
|
-
const existingAny = existing ?? {};
|
|
909
|
-
const existingBgTasks = existingAny.backgroundTasks ?? {};
|
|
910
|
-
const nextBgTasks = { ...existingBgTasks };
|
|
911
|
-
if (args.perTaskEntry) {
|
|
912
|
-
const { toolCallId, startedAt, completedAt, taskId } = args.perTaskEntry;
|
|
913
|
-
const prev = existingBgTasks[toolCallId] ?? { taskId };
|
|
914
|
-
nextBgTasks[toolCallId] = {
|
|
915
|
-
...prev,
|
|
916
|
-
taskId,
|
|
917
|
-
...startedAt !== void 0 ? { startedAt } : {},
|
|
918
|
-
...completedAt !== void 0 ? { completedAt } : {}
|
|
919
|
-
};
|
|
920
|
-
}
|
|
921
|
-
return {
|
|
922
|
-
...existingAny,
|
|
923
|
-
mode,
|
|
924
|
-
...args.resetRunningCount ? { runningBackgroundTasksCount: void 0 } : {},
|
|
925
|
-
backgroundTasks: nextBgTasks
|
|
926
|
-
};
|
|
927
|
-
};
|
|
928
|
-
|
|
929
|
-
// src/lib/ai-sdk/utils/toAssistantUIMessage.ts
|
|
930
|
-
var toAssistantUIMessage = (message) => {
|
|
931
|
-
const extendedMessage = message;
|
|
932
|
-
const content = message.parts.map((part) => {
|
|
933
|
-
if (part.type === "text") {
|
|
934
|
-
return {
|
|
935
|
-
type: "text",
|
|
936
|
-
text: part.text,
|
|
937
|
-
metadata: message.metadata
|
|
938
|
-
};
|
|
939
|
-
}
|
|
940
|
-
if (part.type === "reasoning") {
|
|
941
|
-
return {
|
|
942
|
-
type: "reasoning",
|
|
943
|
-
text: part.text,
|
|
944
|
-
metadata: message.metadata
|
|
945
|
-
};
|
|
946
|
-
}
|
|
947
|
-
if (part.type === "source-url") {
|
|
948
|
-
return {
|
|
949
|
-
type: "source",
|
|
950
|
-
sourceType: "url",
|
|
951
|
-
id: part.sourceId,
|
|
952
|
-
url: part.url,
|
|
953
|
-
title: part.title,
|
|
954
|
-
metadata: message.metadata
|
|
955
|
-
};
|
|
956
|
-
}
|
|
957
|
-
if (part.type === "source-document") {
|
|
958
|
-
return {
|
|
959
|
-
type: "file",
|
|
960
|
-
filename: part.filename,
|
|
961
|
-
mimeType: part.mediaType,
|
|
962
|
-
data: "",
|
|
963
|
-
// Source documents don't have inline data
|
|
964
|
-
metadata: message.metadata
|
|
965
|
-
};
|
|
966
|
-
}
|
|
967
|
-
if (part.type === "file") {
|
|
968
|
-
const type = part.mediaType.includes("image/") ? "image" : "file";
|
|
969
|
-
if (type === "file") {
|
|
970
|
-
return {
|
|
971
|
-
type,
|
|
972
|
-
mimeType: part.mediaType,
|
|
973
|
-
data: part.url,
|
|
974
|
-
// Use URL as data source
|
|
975
|
-
metadata: message.metadata
|
|
976
|
-
};
|
|
977
|
-
}
|
|
978
|
-
if (type === "image") {
|
|
979
|
-
return {
|
|
980
|
-
type,
|
|
981
|
-
image: part.url,
|
|
982
|
-
metadata: message.metadata
|
|
983
|
-
};
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
if (part.type === "dynamic-tool") {
|
|
987
|
-
const baseToolCall = {
|
|
988
|
-
type: "tool-call",
|
|
989
|
-
toolCallId: part.toolCallId,
|
|
990
|
-
toolName: part.toolName,
|
|
991
|
-
argsText: JSON.stringify(part.input),
|
|
992
|
-
args: part.input,
|
|
993
|
-
metadata: message.metadata
|
|
994
|
-
};
|
|
995
|
-
if (part.state === "output-error" && "errorText" in part) {
|
|
996
|
-
return { ...baseToolCall, result: part.errorText, isError: true };
|
|
997
|
-
}
|
|
998
|
-
if ("output" in part) {
|
|
999
|
-
return { ...baseToolCall, result: part.output };
|
|
1000
|
-
}
|
|
1001
|
-
return baseToolCall;
|
|
1002
|
-
}
|
|
1003
|
-
if (part.type.startsWith("tool-") && part.state !== "input-available") {
|
|
1004
|
-
const toolName2 = "toolName" in part && typeof part.toolName === "string" ? part.toolName : part.type.substring(5);
|
|
1005
|
-
const { suspendedToolRunId, ...cleanInput } = "input" in part ? part.input : {};
|
|
1006
|
-
const baseToolCall = {
|
|
1007
|
-
type: "tool-call",
|
|
1008
|
-
toolCallId: "toolCallId" in part && typeof part.toolCallId === "string" ? part.toolCallId : "",
|
|
1009
|
-
toolName: toolName2,
|
|
1010
|
-
argsText: JSON.stringify(cleanInput ?? {}),
|
|
1011
|
-
args: cleanInput ?? {},
|
|
1012
|
-
metadata: message.metadata
|
|
1013
|
-
};
|
|
1014
|
-
if ("output" in part) {
|
|
1015
|
-
return { ...baseToolCall, result: part.output };
|
|
1016
|
-
} else if ("error" in part) {
|
|
1017
|
-
return { ...baseToolCall, result: part.error, isError: true };
|
|
1018
|
-
}
|
|
1019
|
-
return baseToolCall;
|
|
1020
|
-
}
|
|
1021
|
-
const toolName = "toolName" in part && typeof part.toolName === "string" ? part.toolName : part.type.startsWith("tool-") ? part.type.substring(5) : "";
|
|
1022
|
-
const requireApprovalMetadata = extendedMessage.metadata?.requireApprovalMetadata;
|
|
1023
|
-
const suspendedTools = extendedMessage.metadata?.suspendedTools;
|
|
1024
|
-
const partToolCallId = "toolCallId" in part && typeof part.toolCallId === "string" ? part.toolCallId : void 0;
|
|
1025
|
-
const suspensionData = toolName ? requireApprovalMetadata?.[toolName] ?? suspendedTools?.[toolName] : void 0;
|
|
1026
|
-
if (suspensionData) {
|
|
1027
|
-
const { suspendedToolRunId, ...cleanInput } = "input" in part ? part.input : {};
|
|
1028
|
-
return {
|
|
1029
|
-
type: "tool-call",
|
|
1030
|
-
toolCallId: partToolCallId,
|
|
1031
|
-
toolName,
|
|
1032
|
-
argsText: JSON.stringify(cleanInput ?? {}),
|
|
1033
|
-
args: cleanInput,
|
|
1034
|
-
metadata: extendedMessage.metadata
|
|
1035
|
-
};
|
|
1036
|
-
}
|
|
1037
|
-
if (part.type.startsWith("data-")) {
|
|
1038
|
-
return {
|
|
1039
|
-
type: "data",
|
|
1040
|
-
name: part.type.substring(5),
|
|
1041
|
-
// Extract name from 'data-{name}'
|
|
1042
|
-
data: part.data,
|
|
1043
|
-
metadata: message.metadata
|
|
1044
|
-
};
|
|
1045
|
-
}
|
|
1046
|
-
return {
|
|
1047
|
-
type: "text",
|
|
1048
|
-
text: "",
|
|
1049
|
-
metadata: message.metadata
|
|
1050
|
-
};
|
|
1051
|
-
});
|
|
1052
|
-
let status;
|
|
1053
|
-
if (message.role === "assistant" && content.length > 0) {
|
|
1054
|
-
const hasStreamingParts = message.parts.some(
|
|
1055
|
-
(part) => part.type === "text" && "state" in part && part.state === "streaming" || part.type === "reasoning" && "state" in part && part.state === "streaming"
|
|
1056
|
-
);
|
|
1057
|
-
const hasToolCalls = message.parts.some((part) => part.type === "dynamic-tool" || part.type.startsWith("tool-"));
|
|
1058
|
-
const hasInputAvailableTools = message.parts.some(
|
|
1059
|
-
(part) => part.type === "dynamic-tool" && part.state === "input-available"
|
|
1060
|
-
);
|
|
1061
|
-
const hasErrorTools = message.parts.some(
|
|
1062
|
-
(part) => part.type === "dynamic-tool" && part.state === "output-error" || part.type.startsWith("tool-") && "error" in part
|
|
1063
|
-
);
|
|
1064
|
-
if (hasStreamingParts) {
|
|
1065
|
-
status = { type: "running" };
|
|
1066
|
-
} else if (hasInputAvailableTools && hasToolCalls) {
|
|
1067
|
-
status = { type: "requires-action", reason: "tool-calls" };
|
|
1068
|
-
} else if (hasErrorTools) {
|
|
1069
|
-
status = { type: "incomplete", reason: "error" };
|
|
1070
|
-
} else {
|
|
1071
|
-
status = { type: "complete", reason: "stop" };
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
const threadMessage = {
|
|
1075
|
-
role: message.role,
|
|
1076
|
-
content,
|
|
1077
|
-
id: message.id,
|
|
1078
|
-
createdAt: extendedMessage.createdAt,
|
|
1079
|
-
status,
|
|
1080
|
-
attachments: extendedMessage.experimental_attachments
|
|
1081
|
-
};
|
|
1082
|
-
return threadMessage;
|
|
1083
|
-
};
|
|
1084
|
-
|
|
1085
|
-
// src/lib/ai-sdk/memory/resolveInitialMessages.ts
|
|
1086
|
-
var resolveInitialMessages = (messages) => {
|
|
1087
|
-
const messagesLength = messages.length;
|
|
1088
|
-
return messages.map((message, index) => {
|
|
1089
|
-
const networkPart = message.parts.find(
|
|
1090
|
-
(part) => typeof part === "object" && part !== null && "type" in part && part.type === "text" && "text" in part && typeof part.text === "string" && part.text.includes('"isNetwork":true')
|
|
1091
|
-
);
|
|
1092
|
-
if (networkPart && networkPart.type === "text") {
|
|
1093
|
-
try {
|
|
1094
|
-
const json = JSON.parse(networkPart.text);
|
|
1095
|
-
if (json.isNetwork === true) {
|
|
1096
|
-
const selectionReason = json.selectionReason || "";
|
|
1097
|
-
const primitiveType = json.primitiveType || "";
|
|
1098
|
-
const primitiveId = json.primitiveId || "";
|
|
1099
|
-
const finalResult = json.finalResult;
|
|
1100
|
-
const messages2 = finalResult?.messages || [];
|
|
1101
|
-
const childMessages = [];
|
|
1102
|
-
const toolResultMap = /* @__PURE__ */ new Map();
|
|
1103
|
-
for (const msg of messages2) {
|
|
1104
|
-
if (Array.isArray(msg.content)) {
|
|
1105
|
-
for (const part of msg.content) {
|
|
1106
|
-
if (typeof part === "object" && part.type === "tool-result") {
|
|
1107
|
-
toolResultMap.set(part.toolCallId, part);
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
for (const msg of messages2) {
|
|
1113
|
-
if (msg.type === "tool-call" && Array.isArray(msg.content)) {
|
|
1114
|
-
for (const part of msg.content) {
|
|
1115
|
-
if (typeof part === "object" && part.type === "tool-call") {
|
|
1116
|
-
const toolCallContent = part;
|
|
1117
|
-
const toolResult = toolResultMap.get(toolCallContent.toolCallId);
|
|
1118
|
-
const isWorkflow = Boolean(toolResult?.result?.result?.steps);
|
|
1119
|
-
childMessages.push({
|
|
1120
|
-
type: "tool",
|
|
1121
|
-
toolCallId: toolCallContent.toolCallId,
|
|
1122
|
-
toolName: toolCallContent.toolName,
|
|
1123
|
-
args: toolCallContent.args,
|
|
1124
|
-
toolOutput: isWorkflow ? toolResult?.result?.result : toolResult?.result
|
|
1125
|
-
});
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
if (finalResult && finalResult.text) {
|
|
1131
|
-
childMessages.push({
|
|
1132
|
-
type: "text",
|
|
1133
|
-
content: finalResult.text
|
|
1134
|
-
});
|
|
1135
|
-
}
|
|
1136
|
-
const result = primitiveType === "tool" ? finalResult?.result : {
|
|
1137
|
-
childMessages,
|
|
1138
|
-
result: finalResult?.text || ""
|
|
1139
|
-
};
|
|
1140
|
-
const nextMessage = {
|
|
1141
|
-
role: "assistant",
|
|
1142
|
-
parts: [
|
|
1143
|
-
{
|
|
1144
|
-
type: "dynamic-tool",
|
|
1145
|
-
toolCallId: primitiveId,
|
|
1146
|
-
toolName: primitiveId,
|
|
1147
|
-
state: "output-available",
|
|
1148
|
-
input: json.input,
|
|
1149
|
-
output: result
|
|
1150
|
-
}
|
|
1151
|
-
],
|
|
1152
|
-
id: message.id,
|
|
1153
|
-
metadata: {
|
|
1154
|
-
...message.metadata,
|
|
1155
|
-
mode: "network",
|
|
1156
|
-
selectionReason,
|
|
1157
|
-
agentInput: json.input,
|
|
1158
|
-
hasMoreMessages: index < messagesLength - 1,
|
|
1159
|
-
from: primitiveType === "agent" ? "AGENT" : primitiveType === "tool" ? "TOOL" : "WORKFLOW"
|
|
1160
|
-
}
|
|
1161
|
-
};
|
|
1162
|
-
return nextMessage;
|
|
1163
|
-
}
|
|
1164
|
-
} catch {
|
|
1165
|
-
return message;
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
const extendedMessage = message;
|
|
1169
|
-
const pendingToolApprovals = extendedMessage.metadata?.pendingToolApprovals;
|
|
1170
|
-
if (pendingToolApprovals && typeof pendingToolApprovals === "object") {
|
|
1171
|
-
const stillPending = Object.fromEntries(
|
|
1172
|
-
Object.entries(pendingToolApprovals).filter(([_, approval]) => {
|
|
1173
|
-
if (!approval || typeof approval !== "object" || !("toolCallId" in approval)) {
|
|
1174
|
-
return false;
|
|
1175
|
-
}
|
|
1176
|
-
const toolCallId = approval.toolCallId;
|
|
1177
|
-
return !message.parts.some(
|
|
1178
|
-
(part) => part.toolCallId === toolCallId && (part.state === "output-available" || part.output != null)
|
|
1179
|
-
);
|
|
1180
|
-
})
|
|
1181
|
-
);
|
|
1182
|
-
return {
|
|
1183
|
-
...message,
|
|
1184
|
-
metadata: {
|
|
1185
|
-
...message.metadata,
|
|
1186
|
-
mode: "stream",
|
|
1187
|
-
...Object.keys(stillPending).length > 0 ? { requireApprovalMetadata: stillPending } : {}
|
|
1188
|
-
}
|
|
1189
|
-
};
|
|
1190
|
-
}
|
|
1191
|
-
const suspendedTools = extendedMessage.metadata?.suspendedTools;
|
|
1192
|
-
if (suspendedTools && typeof suspendedTools === "object") {
|
|
1193
|
-
return {
|
|
1194
|
-
...message,
|
|
1195
|
-
metadata: {
|
|
1196
|
-
...message.metadata,
|
|
1197
|
-
mode: "stream",
|
|
1198
|
-
suspendedTools
|
|
1199
|
-
}
|
|
1200
|
-
};
|
|
1201
|
-
}
|
|
1202
|
-
return message;
|
|
1203
|
-
})?.filter((message) => {
|
|
1204
|
-
const completionModes = ["generate", "stream", "network"];
|
|
1205
|
-
if (message.role === "assistant" && completionModes.includes(message?.metadata?.mode)) {
|
|
1206
|
-
const meta = message.metadata;
|
|
1207
|
-
if (meta?.isTaskCompleteResult?.suppressFeedback || meta?.completionResult?.suppressFeedback) {
|
|
1208
|
-
return false;
|
|
1209
|
-
}
|
|
1210
|
-
return true;
|
|
1211
|
-
}
|
|
1212
|
-
return true;
|
|
1213
|
-
});
|
|
1214
|
-
};
|
|
1215
|
-
var resolveToChildMessages = (messages) => {
|
|
1216
|
-
const assistantMessage = messages.find((message) => message.role === "assistant");
|
|
1217
|
-
if (!assistantMessage) return [];
|
|
1218
|
-
const parts = assistantMessage.parts;
|
|
1219
|
-
let childMessages = [];
|
|
1220
|
-
for (const part of parts) {
|
|
1221
|
-
const toolPart = part;
|
|
1222
|
-
if (part.type.startsWith("tool-")) {
|
|
1223
|
-
const toolName = part.type.substring("tool-".length);
|
|
1224
|
-
const isWorkflow = toolName.startsWith("workflow-");
|
|
1225
|
-
childMessages.push({
|
|
1226
|
-
type: "tool",
|
|
1227
|
-
toolCallId: toolPart.toolCallId,
|
|
1228
|
-
toolName,
|
|
1229
|
-
args: toolPart.input,
|
|
1230
|
-
toolOutput: isWorkflow ? { ...toolPart.output?.result, runId: toolPart.output?.runId } : toolPart.output
|
|
1231
|
-
});
|
|
1232
|
-
}
|
|
1233
|
-
if (part.type === "text") {
|
|
1234
|
-
childMessages.push({
|
|
1235
|
-
type: "text",
|
|
1236
|
-
content: toolPart.text
|
|
1237
|
-
});
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
return childMessages;
|
|
1241
|
-
};
|
|
1242
|
-
|
|
1243
|
-
// src/lib/ai-sdk/transformers/AISdkNetworkTransformer.ts
|
|
1244
|
-
var AISdkNetworkTransformer = class {
|
|
1245
|
-
transform({ chunk, conversation, metadata }) {
|
|
1246
|
-
const newConversation = [...conversation];
|
|
1247
|
-
if (chunk.type === "routing-agent-text-delta") {
|
|
1248
|
-
return this.handleRoutingAgentConversation(chunk, newConversation);
|
|
1249
|
-
}
|
|
1250
|
-
if (chunk.type.startsWith("agent-execution-")) {
|
|
1251
|
-
return this.handleAgentConversation(chunk, newConversation, metadata);
|
|
1252
|
-
}
|
|
1253
|
-
if (chunk.type.startsWith("workflow-execution-")) {
|
|
1254
|
-
return this.handleWorkflowConversation(chunk, newConversation, metadata);
|
|
1255
|
-
}
|
|
1256
|
-
if (chunk.type.startsWith("tool-execution-")) {
|
|
1257
|
-
return this.handleToolConversation(chunk, newConversation, metadata);
|
|
1258
|
-
}
|
|
1259
|
-
if (chunk.type === "network-validation-end") {
|
|
1260
|
-
if (chunk.payload.suppressFeedback) return newConversation;
|
|
1261
|
-
const feedback = formatCompletionFeedback(
|
|
1262
|
-
{
|
|
1263
|
-
complete: chunk.payload.passed,
|
|
1264
|
-
scorers: chunk.payload.results,
|
|
1265
|
-
totalDuration: chunk.payload.duration,
|
|
1266
|
-
timedOut: chunk.payload.timedOut},
|
|
1267
|
-
chunk.payload.maxIterationReached
|
|
1268
|
-
);
|
|
1269
|
-
const newMessage = {
|
|
1270
|
-
id: `network-validation-end-${chunk.payload.runId}-${Date.now()}`,
|
|
1271
|
-
role: "assistant",
|
|
1272
|
-
parts: [
|
|
1273
|
-
{
|
|
1274
|
-
type: "text",
|
|
1275
|
-
text: feedback
|
|
1276
|
-
}
|
|
1277
|
-
],
|
|
1278
|
-
metadata: {
|
|
1279
|
-
...metadata,
|
|
1280
|
-
mode: "network",
|
|
1281
|
-
completionResult: {
|
|
1282
|
-
passed: chunk.payload.passed
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
};
|
|
1286
|
-
return [...newConversation, newMessage];
|
|
1287
|
-
}
|
|
1288
|
-
if (chunk.type === "network-execution-event-step-finish") {
|
|
1289
|
-
const lastMessage = newConversation[newConversation.length - 1];
|
|
1290
|
-
if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
|
|
1291
|
-
const agentChunk = chunk.payload;
|
|
1292
|
-
const parts = [...lastMessage.parts];
|
|
1293
|
-
const textPartIndex = parts.findIndex((part) => part.type === "text");
|
|
1294
|
-
if (textPartIndex === -1) {
|
|
1295
|
-
parts.push({
|
|
1296
|
-
type: "text",
|
|
1297
|
-
text: agentChunk.result,
|
|
1298
|
-
state: "done"
|
|
1299
|
-
});
|
|
1300
|
-
return [
|
|
1301
|
-
...newConversation.slice(0, -1),
|
|
1302
|
-
{
|
|
1303
|
-
...lastMessage,
|
|
1304
|
-
parts
|
|
1305
|
-
}
|
|
1306
|
-
];
|
|
1307
|
-
}
|
|
1308
|
-
const textPart = parts[textPartIndex];
|
|
1309
|
-
if (textPart.type === "text") {
|
|
1310
|
-
parts[textPartIndex] = {
|
|
1311
|
-
...textPart,
|
|
1312
|
-
state: "done"
|
|
1313
|
-
};
|
|
1314
|
-
return [
|
|
1315
|
-
...newConversation.slice(0, -1),
|
|
1316
|
-
{
|
|
1317
|
-
...lastMessage,
|
|
1318
|
-
parts
|
|
1319
|
-
}
|
|
1320
|
-
];
|
|
1321
|
-
}
|
|
1322
|
-
return newConversation;
|
|
1323
|
-
}
|
|
1324
|
-
return newConversation;
|
|
1325
|
-
}
|
|
1326
|
-
handleRoutingAgentConversation = (chunk, newConversation) => {
|
|
1327
|
-
const lastMessage = newConversation[newConversation.length - 1];
|
|
1328
|
-
if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
|
|
1329
|
-
const agentChunk = chunk.payload;
|
|
1330
|
-
const parts = [...lastMessage.parts];
|
|
1331
|
-
const textPartIndex = parts.findIndex((part) => part.type === "text");
|
|
1332
|
-
if (textPartIndex === -1) {
|
|
1333
|
-
parts.push({
|
|
1334
|
-
type: "text",
|
|
1335
|
-
text: agentChunk.text,
|
|
1336
|
-
state: "streaming"
|
|
1337
|
-
});
|
|
1338
|
-
return [
|
|
1339
|
-
...newConversation.slice(0, -1),
|
|
1340
|
-
{
|
|
1341
|
-
...lastMessage,
|
|
1342
|
-
parts
|
|
1343
|
-
}
|
|
1344
|
-
];
|
|
1345
|
-
}
|
|
1346
|
-
const textPart = parts[textPartIndex];
|
|
1347
|
-
if (textPart.type === "text") {
|
|
1348
|
-
parts[textPartIndex] = {
|
|
1349
|
-
...textPart,
|
|
1350
|
-
text: textPart.text + agentChunk.text,
|
|
1351
|
-
state: "streaming"
|
|
1352
|
-
};
|
|
1353
|
-
return [
|
|
1354
|
-
...newConversation.slice(0, -1),
|
|
1355
|
-
{
|
|
1356
|
-
...lastMessage,
|
|
1357
|
-
parts
|
|
1358
|
-
}
|
|
1359
|
-
];
|
|
1360
|
-
}
|
|
1361
|
-
return newConversation;
|
|
1362
|
-
};
|
|
1363
|
-
handleAgentConversation = (chunk, newConversation, metadata) => {
|
|
1364
|
-
if (chunk.type === "agent-execution-start") {
|
|
1365
|
-
const primitiveId = chunk.payload?.args?.primitiveId;
|
|
1366
|
-
const runId = chunk.payload.runId;
|
|
1367
|
-
if (!primitiveId || !runId) return newConversation;
|
|
1368
|
-
const newMessage = {
|
|
1369
|
-
id: `agent-execution-start-${runId}-${Date.now()}`,
|
|
1370
|
-
role: "assistant",
|
|
1371
|
-
parts: [
|
|
1372
|
-
{
|
|
1373
|
-
type: "dynamic-tool",
|
|
1374
|
-
toolName: primitiveId,
|
|
1375
|
-
toolCallId: runId,
|
|
1376
|
-
state: "input-available",
|
|
1377
|
-
input: chunk.payload.args
|
|
1378
|
-
}
|
|
1379
|
-
],
|
|
1380
|
-
metadata: {
|
|
1381
|
-
...metadata,
|
|
1382
|
-
selectionReason: chunk.payload?.args?.selectionReason || "",
|
|
1383
|
-
agentInput: chunk.payload?.args?.task,
|
|
1384
|
-
mode: "network",
|
|
1385
|
-
from: "AGENT"
|
|
1386
|
-
}
|
|
1387
|
-
};
|
|
1388
|
-
return [...newConversation, newMessage];
|
|
1389
|
-
}
|
|
1390
|
-
if (chunk.type === "agent-execution-approval") {
|
|
1391
|
-
const lastMessage = newConversation[newConversation.length - 1];
|
|
1392
|
-
if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
|
|
1393
|
-
const lastRequireApprovalMetadata = lastMessage.metadata?.mode === "network" ? lastMessage.metadata?.requireApprovalMetadata : {};
|
|
1394
|
-
return [
|
|
1395
|
-
...newConversation.slice(0, -1),
|
|
1396
|
-
{
|
|
1397
|
-
...lastMessage,
|
|
1398
|
-
metadata: {
|
|
1399
|
-
...lastMessage.metadata,
|
|
1400
|
-
mode: "network",
|
|
1401
|
-
requireApprovalMetadata: {
|
|
1402
|
-
...lastRequireApprovalMetadata,
|
|
1403
|
-
[chunk.payload.toolName]: {
|
|
1404
|
-
toolCallId: chunk.payload.toolCallId,
|
|
1405
|
-
toolName: chunk.payload.toolName,
|
|
1406
|
-
args: chunk.payload.args,
|
|
1407
|
-
runId: chunk.payload.runId
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
];
|
|
1413
|
-
}
|
|
1414
|
-
if (chunk.type === "agent-execution-suspended") {
|
|
1415
|
-
const lastMessage = newConversation[newConversation.length - 1];
|
|
1416
|
-
if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
|
|
1417
|
-
const lastSuspendedTools = lastMessage.metadata?.mode === "network" ? lastMessage.metadata?.suspendedTools : {};
|
|
1418
|
-
return [
|
|
1419
|
-
...newConversation.slice(0, -1),
|
|
1420
|
-
{
|
|
1421
|
-
...lastMessage,
|
|
1422
|
-
metadata: {
|
|
1423
|
-
...lastMessage.metadata,
|
|
1424
|
-
mode: "network",
|
|
1425
|
-
suspendedTools: {
|
|
1426
|
-
...lastSuspendedTools,
|
|
1427
|
-
[chunk.payload.toolName]: {
|
|
1428
|
-
toolCallId: chunk.payload.toolCallId,
|
|
1429
|
-
toolName: chunk.payload.toolName,
|
|
1430
|
-
args: chunk.payload.args,
|
|
1431
|
-
suspendPayload: chunk.payload.suspendPayload,
|
|
1432
|
-
runId: chunk.payload.runId
|
|
1433
|
-
}
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1436
|
-
}
|
|
1437
|
-
];
|
|
1438
|
-
}
|
|
1439
|
-
if (chunk.type === "agent-execution-end") {
|
|
1440
|
-
const lastMessage = newConversation[newConversation.length - 1];
|
|
1441
|
-
if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
|
|
1442
|
-
const parts = [...lastMessage.parts];
|
|
1443
|
-
const toolPartIndex = parts.findIndex((part) => part.type === "dynamic-tool");
|
|
1444
|
-
if (toolPartIndex !== -1) {
|
|
1445
|
-
const toolPart = parts[toolPartIndex];
|
|
1446
|
-
if (toolPart.type === "dynamic-tool") {
|
|
1447
|
-
const currentOutput = toolPart.output;
|
|
1448
|
-
parts[toolPartIndex] = {
|
|
1449
|
-
type: "dynamic-tool",
|
|
1450
|
-
toolName: toolPart.toolName,
|
|
1451
|
-
toolCallId: toolPart.toolCallId,
|
|
1452
|
-
state: "output-available",
|
|
1453
|
-
input: toolPart.input,
|
|
1454
|
-
output: {
|
|
1455
|
-
...currentOutput,
|
|
1456
|
-
result: currentOutput?.result || chunk.payload?.result || ""
|
|
1457
|
-
}
|
|
1458
|
-
};
|
|
1459
|
-
}
|
|
1460
|
-
}
|
|
1461
|
-
return [
|
|
1462
|
-
...newConversation.slice(0, -1),
|
|
1463
|
-
{
|
|
1464
|
-
...lastMessage,
|
|
1465
|
-
parts
|
|
1466
|
-
}
|
|
1467
|
-
];
|
|
1468
|
-
}
|
|
1469
|
-
if (chunk.type.startsWith("agent-execution-event-")) {
|
|
1470
|
-
const lastMessage = newConversation[newConversation.length - 1];
|
|
1471
|
-
if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
|
|
1472
|
-
const agentChunk = chunk.payload;
|
|
1473
|
-
const parts = [...lastMessage.parts];
|
|
1474
|
-
const toolPartIndex = parts.findIndex((part) => part.type === "dynamic-tool");
|
|
1475
|
-
if (toolPartIndex === -1) return newConversation;
|
|
1476
|
-
const toolPart = parts[toolPartIndex];
|
|
1477
|
-
if (agentChunk.type === "text-delta") {
|
|
1478
|
-
const childMessages = toolPart?.output?.childMessages || [];
|
|
1479
|
-
const lastChildMessage = childMessages[childMessages.length - 1];
|
|
1480
|
-
const textMessage = { type: "text", content: (lastChildMessage?.content || "") + agentChunk.payload.text };
|
|
1481
|
-
const nextMessages = lastChildMessage?.type === "text" ? [...childMessages.slice(0, -1), textMessage] : [...childMessages, textMessage];
|
|
1482
|
-
parts[toolPartIndex] = {
|
|
1483
|
-
...toolPart,
|
|
1484
|
-
output: {
|
|
1485
|
-
childMessages: nextMessages
|
|
1486
|
-
}
|
|
1487
|
-
};
|
|
1488
|
-
} else if (agentChunk.type === "tool-call") {
|
|
1489
|
-
const childMessages = toolPart?.output?.childMessages || [];
|
|
1490
|
-
parts[toolPartIndex] = {
|
|
1491
|
-
...toolPart,
|
|
1492
|
-
output: {
|
|
1493
|
-
...toolPart?.output,
|
|
1494
|
-
childMessages: [
|
|
1495
|
-
...childMessages,
|
|
1496
|
-
{
|
|
1497
|
-
type: "tool",
|
|
1498
|
-
toolCallId: agentChunk.payload.toolCallId,
|
|
1499
|
-
toolName: agentChunk.payload.toolName,
|
|
1500
|
-
args: agentChunk.payload.args
|
|
1501
|
-
}
|
|
1502
|
-
]
|
|
1503
|
-
}
|
|
1504
|
-
};
|
|
1505
|
-
} else if (agentChunk.type === "tool-output") {
|
|
1506
|
-
if (agentChunk.payload?.output?.type?.startsWith("workflow-")) {
|
|
1507
|
-
const childMessages = toolPart?.output?.childMessages || [];
|
|
1508
|
-
const lastToolIndex = childMessages.length - 1;
|
|
1509
|
-
const currentMessage = childMessages[lastToolIndex];
|
|
1510
|
-
const actualExistingWorkflowState = currentMessage?.toolOutput || {};
|
|
1511
|
-
const updatedWorkflowState = mapWorkflowStreamChunkToWatchResult(
|
|
1512
|
-
actualExistingWorkflowState,
|
|
1513
|
-
agentChunk.payload.output
|
|
1514
|
-
);
|
|
1515
|
-
if (lastToolIndex >= 0 && childMessages[lastToolIndex]?.type === "tool") {
|
|
1516
|
-
parts[toolPartIndex] = {
|
|
1517
|
-
...toolPart,
|
|
1518
|
-
output: {
|
|
1519
|
-
...toolPart?.output,
|
|
1520
|
-
childMessages: [
|
|
1521
|
-
...childMessages.slice(0, -1),
|
|
1522
|
-
{
|
|
1523
|
-
...currentMessage,
|
|
1524
|
-
toolOutput: updatedWorkflowState
|
|
1525
|
-
}
|
|
1526
|
-
]
|
|
1527
|
-
}
|
|
1528
|
-
};
|
|
1529
|
-
}
|
|
1530
|
-
}
|
|
1531
|
-
} else if (agentChunk.type === "tool-result") {
|
|
1532
|
-
const childMessages = toolPart?.output?.childMessages || [];
|
|
1533
|
-
const lastToolIndex = childMessages.length - 1;
|
|
1534
|
-
const isWorkflow = Boolean(agentChunk.payload?.result?.result?.steps);
|
|
1535
|
-
if (lastToolIndex >= 0 && childMessages[lastToolIndex]?.type === "tool") {
|
|
1536
|
-
parts[toolPartIndex] = {
|
|
1537
|
-
...toolPart,
|
|
1538
|
-
output: {
|
|
1539
|
-
...toolPart?.output,
|
|
1540
|
-
childMessages: [
|
|
1541
|
-
...childMessages.slice(0, -1),
|
|
1542
|
-
{
|
|
1543
|
-
...childMessages[lastToolIndex],
|
|
1544
|
-
toolOutput: isWorkflow ? agentChunk.payload.result.result : agentChunk.payload.result
|
|
1545
|
-
}
|
|
1546
|
-
]
|
|
1547
|
-
}
|
|
1548
|
-
};
|
|
1549
|
-
}
|
|
1550
|
-
}
|
|
1551
|
-
return [
|
|
1552
|
-
...newConversation.slice(0, -1),
|
|
1553
|
-
{
|
|
1554
|
-
...lastMessage,
|
|
1555
|
-
parts
|
|
1556
|
-
}
|
|
1557
|
-
];
|
|
1558
|
-
}
|
|
1559
|
-
return newConversation;
|
|
1560
|
-
};
|
|
1561
|
-
handleWorkflowConversation = (chunk, newConversation, metadata) => {
|
|
1562
|
-
if (chunk.type === "workflow-execution-start") {
|
|
1563
|
-
const primitiveId = chunk.payload?.args?.primitiveId;
|
|
1564
|
-
const runId = chunk.payload.runId;
|
|
1565
|
-
if (!primitiveId || !runId) return newConversation;
|
|
1566
|
-
let agentInput;
|
|
1567
|
-
try {
|
|
1568
|
-
agentInput = JSON.parse(chunk?.payload?.args?.prompt);
|
|
1569
|
-
} catch {
|
|
1570
|
-
agentInput = chunk?.payload?.args?.prompt;
|
|
1571
|
-
}
|
|
1572
|
-
const newMessage = {
|
|
1573
|
-
id: `workflow-start-${runId}-${Date.now()}`,
|
|
1574
|
-
role: "assistant",
|
|
1575
|
-
parts: [
|
|
1576
|
-
{
|
|
1577
|
-
type: "dynamic-tool",
|
|
1578
|
-
toolName: primitiveId,
|
|
1579
|
-
toolCallId: runId,
|
|
1580
|
-
state: "input-available",
|
|
1581
|
-
input: chunk.payload.args
|
|
1582
|
-
}
|
|
1583
|
-
],
|
|
1584
|
-
metadata: {
|
|
1585
|
-
...metadata,
|
|
1586
|
-
selectionReason: chunk.payload?.args?.selectionReason || "",
|
|
1587
|
-
from: "WORKFLOW",
|
|
1588
|
-
mode: "network",
|
|
1589
|
-
agentInput
|
|
1590
|
-
}
|
|
1591
|
-
};
|
|
1592
|
-
return [...newConversation, newMessage];
|
|
1593
|
-
}
|
|
1594
|
-
if (chunk.type === "workflow-execution-suspended") {
|
|
1595
|
-
const lastMessage = newConversation[newConversation.length - 1];
|
|
1596
|
-
if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
|
|
1597
|
-
const lastSuspendedTools = lastMessage.metadata?.mode === "network" ? lastMessage.metadata?.suspendedTools : {};
|
|
1598
|
-
return [
|
|
1599
|
-
...newConversation.slice(0, -1),
|
|
1600
|
-
{
|
|
1601
|
-
...lastMessage,
|
|
1602
|
-
metadata: {
|
|
1603
|
-
...lastMessage.metadata,
|
|
1604
|
-
mode: "network",
|
|
1605
|
-
suspendedTools: {
|
|
1606
|
-
...lastSuspendedTools,
|
|
1607
|
-
[chunk.payload.toolName]: {
|
|
1608
|
-
toolCallId: chunk.payload.toolCallId,
|
|
1609
|
-
toolName: chunk.payload.toolName,
|
|
1610
|
-
args: chunk.payload.args,
|
|
1611
|
-
suspendPayload: chunk.payload.suspendPayload,
|
|
1612
|
-
runId: chunk.payload.runId
|
|
1613
|
-
}
|
|
1614
|
-
}
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
];
|
|
1618
|
-
}
|
|
1619
|
-
if (chunk.type.startsWith("workflow-execution-event-")) {
|
|
1620
|
-
const lastMessage = newConversation[newConversation.length - 1];
|
|
1621
|
-
if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
|
|
1622
|
-
const parts = [...lastMessage.parts];
|
|
1623
|
-
const toolPartIndex = parts.findIndex((part) => part.type === "dynamic-tool");
|
|
1624
|
-
if (toolPartIndex === -1) return newConversation;
|
|
1625
|
-
const toolPart = parts[toolPartIndex];
|
|
1626
|
-
if (toolPart.type !== "dynamic-tool") return newConversation;
|
|
1627
|
-
const existingWorkflowState = toolPart.output || {};
|
|
1628
|
-
const updatedWorkflowState = mapWorkflowStreamChunkToWatchResult(existingWorkflowState, chunk.payload);
|
|
1629
|
-
parts[toolPartIndex] = {
|
|
1630
|
-
...toolPart,
|
|
1631
|
-
output: updatedWorkflowState
|
|
1632
|
-
};
|
|
1633
|
-
return [
|
|
1634
|
-
...newConversation.slice(0, -1),
|
|
1635
|
-
{
|
|
1636
|
-
...lastMessage,
|
|
1637
|
-
parts
|
|
1638
|
-
}
|
|
1639
|
-
];
|
|
1640
|
-
}
|
|
1641
|
-
return newConversation;
|
|
1642
|
-
};
|
|
1643
|
-
handleToolConversation = (chunk, newConversation, metadata) => {
|
|
1644
|
-
if (chunk.type === "tool-execution-start") {
|
|
1645
|
-
const { args: argsData } = chunk.payload;
|
|
1646
|
-
const lastMessage = newConversation[newConversation.length - 1];
|
|
1647
|
-
const nestedArgs = argsData.args || {};
|
|
1648
|
-
if (!lastMessage || lastMessage.role !== "assistant") {
|
|
1649
|
-
const newMessage = {
|
|
1650
|
-
id: `tool-start-${chunk.runId}-${Date.now()}`,
|
|
1651
|
-
role: "assistant",
|
|
1652
|
-
parts: [
|
|
1653
|
-
{
|
|
1654
|
-
type: "dynamic-tool",
|
|
1655
|
-
toolName: argsData.toolName || "unknown",
|
|
1656
|
-
toolCallId: argsData.toolCallId || "unknown",
|
|
1657
|
-
state: "input-available",
|
|
1658
|
-
input: nestedArgs
|
|
1659
|
-
}
|
|
1660
|
-
],
|
|
1661
|
-
metadata: {
|
|
1662
|
-
...metadata,
|
|
1663
|
-
selectionReason: metadata?.mode === "network" ? metadata.selectionReason || argsData.selectionReason : "",
|
|
1664
|
-
mode: "network",
|
|
1665
|
-
agentInput: nestedArgs
|
|
1666
|
-
}
|
|
1667
|
-
};
|
|
1668
|
-
return [...newConversation, newMessage];
|
|
1669
|
-
}
|
|
1670
|
-
const parts = [...lastMessage.parts];
|
|
1671
|
-
parts.push({
|
|
1672
|
-
type: "dynamic-tool",
|
|
1673
|
-
toolName: argsData.toolName || "unknown",
|
|
1674
|
-
toolCallId: argsData.toolCallId || "unknown",
|
|
1675
|
-
state: "input-available",
|
|
1676
|
-
input: nestedArgs
|
|
1677
|
-
});
|
|
1678
|
-
return [
|
|
1679
|
-
...newConversation.slice(0, -1),
|
|
1680
|
-
{
|
|
1681
|
-
...lastMessage,
|
|
1682
|
-
parts
|
|
1683
|
-
}
|
|
1684
|
-
];
|
|
1685
|
-
}
|
|
1686
|
-
if (chunk.type === "tool-execution-approval") {
|
|
1687
|
-
const lastMessage = newConversation[newConversation.length - 1];
|
|
1688
|
-
if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
|
|
1689
|
-
const lastRequireApprovalMetadata = lastMessage.metadata?.mode === "network" ? lastMessage.metadata?.requireApprovalMetadata : {};
|
|
1690
|
-
return [
|
|
1691
|
-
...newConversation.slice(0, -1),
|
|
1692
|
-
{
|
|
1693
|
-
...lastMessage,
|
|
1694
|
-
metadata: {
|
|
1695
|
-
...lastMessage.metadata,
|
|
1696
|
-
mode: "network",
|
|
1697
|
-
requireApprovalMetadata: {
|
|
1698
|
-
...lastRequireApprovalMetadata,
|
|
1699
|
-
[chunk.payload.toolName]: {
|
|
1700
|
-
toolCallId: chunk.payload.toolCallId,
|
|
1701
|
-
toolName: chunk.payload.toolName,
|
|
1702
|
-
args: chunk.payload.args,
|
|
1703
|
-
runId: chunk.payload.runId
|
|
1704
|
-
}
|
|
1705
|
-
}
|
|
1706
|
-
}
|
|
1707
|
-
}
|
|
1708
|
-
];
|
|
1709
|
-
}
|
|
1710
|
-
if (chunk.type === "tool-execution-suspended") {
|
|
1711
|
-
const lastMessage = newConversation[newConversation.length - 1];
|
|
1712
|
-
if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
|
|
1713
|
-
const lastSuspendedTools = lastMessage.metadata?.mode === "network" ? lastMessage.metadata?.suspendedTools : {};
|
|
1714
|
-
return [
|
|
1715
|
-
...newConversation.slice(0, -1),
|
|
1716
|
-
{
|
|
1717
|
-
...lastMessage,
|
|
1718
|
-
metadata: {
|
|
1719
|
-
...lastMessage.metadata,
|
|
1720
|
-
mode: "network",
|
|
1721
|
-
suspendedTools: {
|
|
1722
|
-
...lastSuspendedTools,
|
|
1723
|
-
[chunk.payload.toolName]: {
|
|
1724
|
-
toolCallId: chunk.payload.toolCallId,
|
|
1725
|
-
toolName: chunk.payload.toolName,
|
|
1726
|
-
args: chunk.payload.args,
|
|
1727
|
-
suspendPayload: chunk.payload.suspendPayload,
|
|
1728
|
-
runId: chunk.payload.runId
|
|
1729
|
-
}
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1732
|
-
}
|
|
1733
|
-
];
|
|
1734
|
-
}
|
|
1735
|
-
if (chunk.type === "tool-execution-end") {
|
|
1736
|
-
const lastMessage = newConversation[newConversation.length - 1];
|
|
1737
|
-
if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
|
|
1738
|
-
const parts = [...lastMessage.parts];
|
|
1739
|
-
const toolPartIndex = parts.findIndex(
|
|
1740
|
-
(part) => part.type === "dynamic-tool" && "toolCallId" in part && part.toolCallId === chunk.payload.toolCallId
|
|
1741
|
-
);
|
|
1742
|
-
if (toolPartIndex !== -1) {
|
|
1743
|
-
const toolPart = parts[toolPartIndex];
|
|
1744
|
-
if (toolPart.type === "dynamic-tool") {
|
|
1745
|
-
const currentOutput = toolPart.output;
|
|
1746
|
-
parts[toolPartIndex] = {
|
|
1747
|
-
type: "dynamic-tool",
|
|
1748
|
-
toolName: toolPart.toolName,
|
|
1749
|
-
toolCallId: toolPart.toolCallId,
|
|
1750
|
-
state: "output-available",
|
|
1751
|
-
input: toolPart.input,
|
|
1752
|
-
output: currentOutput?.result || chunk.payload?.result || ""
|
|
1753
|
-
};
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
|
-
return [
|
|
1757
|
-
...newConversation.slice(0, -1),
|
|
1758
|
-
{
|
|
1759
|
-
...lastMessage,
|
|
1760
|
-
parts
|
|
1761
|
-
}
|
|
1762
|
-
];
|
|
1763
|
-
}
|
|
1764
|
-
return newConversation;
|
|
1765
|
-
};
|
|
1766
|
-
};
|
|
1767
|
-
|
|
1768
|
-
// src/lib/ai-sdk/utils/fromCoreUserMessageToUIMessage.tsx
|
|
1769
|
-
var fromCoreUserMessageToUIMessage = (coreUserMessage) => {
|
|
1770
|
-
const id = `user-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
1771
|
-
const parts = typeof coreUserMessage.content === "string" ? [
|
|
1772
|
-
{
|
|
1773
|
-
type: "text",
|
|
1774
|
-
text: coreUserMessage.content
|
|
1775
|
-
}
|
|
1776
|
-
] : coreUserMessage.content.map((part) => {
|
|
1777
|
-
switch (part.type) {
|
|
1778
|
-
case "text": {
|
|
1779
|
-
return {
|
|
1780
|
-
type: "text",
|
|
1781
|
-
text: part.text
|
|
1782
|
-
};
|
|
1783
|
-
}
|
|
1784
|
-
case "image": {
|
|
1785
|
-
const url = typeof part.image === "string" ? part.image : part.image instanceof URL ? part.image.toString() : "";
|
|
1786
|
-
return {
|
|
1787
|
-
type: "file",
|
|
1788
|
-
mediaType: part.mimeType ?? "image/*",
|
|
1789
|
-
url
|
|
1790
|
-
};
|
|
1791
|
-
}
|
|
1792
|
-
case "file": {
|
|
1793
|
-
const url = typeof part.data === "string" ? part.data : part.data instanceof URL ? part.data.toString() : "";
|
|
1794
|
-
return {
|
|
1795
|
-
type: "file",
|
|
1796
|
-
mediaType: part.mimeType,
|
|
1797
|
-
url,
|
|
1798
|
-
...part.filename !== void 0 ? { filename: part.filename } : {}
|
|
1799
|
-
};
|
|
1800
|
-
}
|
|
1801
|
-
default: {
|
|
1802
|
-
const exhaustiveCheck = part;
|
|
1803
|
-
throw new Error(`Unhandled content part type: ${exhaustiveCheck.type}`);
|
|
1804
|
-
}
|
|
1805
|
-
}
|
|
1806
|
-
});
|
|
1807
|
-
return {
|
|
1808
|
-
id,
|
|
1809
|
-
role: "user",
|
|
1810
|
-
parts
|
|
1811
|
-
};
|
|
1812
|
-
};
|
|
1813
|
-
|
|
1814
|
-
// src/agent/hooks.ts
|
|
1815
|
-
var useChat = ({
|
|
1816
|
-
agentId,
|
|
1817
|
-
resourceId,
|
|
1818
|
-
initialMessages,
|
|
1819
|
-
requestContext: propsRequestContext
|
|
1820
|
-
}) => {
|
|
1821
|
-
const _currentRunId = useRef(void 0);
|
|
1822
|
-
const _onChunk = useRef(void 0);
|
|
1823
|
-
const _networkRunId = useRef(void 0);
|
|
1824
|
-
const _onNetworkChunk = useRef(void 0);
|
|
1825
|
-
const _requestContext = useRef(propsRequestContext);
|
|
1826
|
-
const _streamAbortRef = useRef(null);
|
|
1827
|
-
const [messages, setMessages] = useState([]);
|
|
1828
|
-
const [toolCallApprovals, setToolCallApprovals] = useState({});
|
|
1829
|
-
const [networkToolCallApprovals, setNetworkToolCallApprovals] = useState({});
|
|
1830
|
-
const baseClient = useMastraClient();
|
|
1831
|
-
const [isRunning, setIsRunning] = useState(false);
|
|
1832
|
-
useEffect(() => {
|
|
1833
|
-
const formattedMessages = resolveInitialMessages(initialMessages || []);
|
|
1834
|
-
setMessages(formattedMessages);
|
|
1835
|
-
_currentRunId.current = extractRunIdFromMessages(formattedMessages);
|
|
1836
|
-
}, [initialMessages]);
|
|
1837
|
-
useEffect(() => {
|
|
1838
|
-
_requestContext.current = propsRequestContext;
|
|
1839
|
-
}, [propsRequestContext]);
|
|
1840
|
-
const generate = async ({
|
|
1841
|
-
coreUserMessages,
|
|
1842
|
-
requestContext,
|
|
1843
|
-
threadId,
|
|
1844
|
-
modelSettings,
|
|
1845
|
-
signal,
|
|
1846
|
-
onFinish,
|
|
1847
|
-
tracingOptions
|
|
1848
|
-
}) => {
|
|
1849
|
-
const {
|
|
1850
|
-
frequencyPenalty,
|
|
1851
|
-
presencePenalty,
|
|
1852
|
-
maxRetries,
|
|
1853
|
-
maxTokens,
|
|
1854
|
-
temperature,
|
|
1855
|
-
topK,
|
|
1856
|
-
topP,
|
|
1857
|
-
instructions,
|
|
1858
|
-
providerOptions,
|
|
1859
|
-
maxSteps,
|
|
1860
|
-
requireToolApproval
|
|
1861
|
-
} = modelSettings || {};
|
|
1862
|
-
const resolvedRequestContext = requestContext ?? propsRequestContext;
|
|
1863
|
-
_requestContext.current = resolvedRequestContext;
|
|
1864
|
-
setIsRunning(true);
|
|
1865
|
-
const clientWithAbort = new MastraClient({
|
|
1866
|
-
...baseClient.options,
|
|
1867
|
-
abortSignal: signal
|
|
1868
|
-
});
|
|
1869
|
-
const agent = clientWithAbort.getAgent(agentId);
|
|
1870
|
-
const runId = v4();
|
|
1871
|
-
_currentRunId.current = runId;
|
|
1872
|
-
const response = await agent.generate(coreUserMessages, {
|
|
1873
|
-
runId,
|
|
1874
|
-
maxSteps,
|
|
1875
|
-
modelSettings: {
|
|
1876
|
-
frequencyPenalty,
|
|
1877
|
-
presencePenalty,
|
|
1878
|
-
maxRetries,
|
|
1879
|
-
maxOutputTokens: maxTokens,
|
|
1880
|
-
temperature,
|
|
1881
|
-
topK,
|
|
1882
|
-
topP
|
|
1883
|
-
},
|
|
1884
|
-
instructions,
|
|
1885
|
-
requestContext: resolvedRequestContext,
|
|
1886
|
-
...threadId ? { memory: { thread: threadId, resource: resourceId || agentId } } : {},
|
|
1887
|
-
providerOptions,
|
|
1888
|
-
tracingOptions,
|
|
1889
|
-
requireToolApproval
|
|
1890
|
-
});
|
|
1891
|
-
if (response.finishReason === "suspended" && response.suspendPayload) {
|
|
1892
|
-
const { toolCallId, toolName, args } = response.suspendPayload;
|
|
1893
|
-
if (response.response?.uiMessages) {
|
|
1894
|
-
const mastraUIMessages = (response.response.uiMessages || []).map((message) => ({
|
|
1895
|
-
...message,
|
|
1896
|
-
metadata: {
|
|
1897
|
-
mode: "generate",
|
|
1898
|
-
requireApprovalMetadata: {
|
|
1899
|
-
[toolName]: {
|
|
1900
|
-
toolCallId,
|
|
1901
|
-
toolName,
|
|
1902
|
-
args
|
|
1903
|
-
}
|
|
1904
|
-
}
|
|
1905
|
-
}
|
|
1906
|
-
}));
|
|
1907
|
-
setMessages((prev) => [...prev, ...mastraUIMessages]);
|
|
1908
|
-
}
|
|
1909
|
-
setIsRunning(false);
|
|
1910
|
-
return;
|
|
1911
|
-
}
|
|
1912
|
-
setIsRunning(false);
|
|
1913
|
-
if (response && "uiMessages" in response.response && response.response.uiMessages) {
|
|
1914
|
-
void onFinish?.(response.response.uiMessages);
|
|
1915
|
-
const mastraUIMessages = (response.response.uiMessages || []).map((message) => ({
|
|
1916
|
-
...message,
|
|
1917
|
-
metadata: {
|
|
1918
|
-
mode: "generate"
|
|
1919
|
-
}
|
|
1920
|
-
}));
|
|
1921
|
-
setMessages((prev) => [...prev, ...mastraUIMessages]);
|
|
1922
|
-
}
|
|
1923
|
-
};
|
|
1924
|
-
const stream = async ({
|
|
1925
|
-
coreUserMessages,
|
|
1926
|
-
requestContext,
|
|
1927
|
-
threadId,
|
|
1928
|
-
onChunk,
|
|
1929
|
-
modelSettings,
|
|
1930
|
-
signal,
|
|
1931
|
-
tracingOptions
|
|
1932
|
-
}) => {
|
|
1933
|
-
const {
|
|
1934
|
-
frequencyPenalty,
|
|
1935
|
-
presencePenalty,
|
|
1936
|
-
maxRetries,
|
|
1937
|
-
maxTokens,
|
|
1938
|
-
temperature,
|
|
1939
|
-
topK,
|
|
1940
|
-
topP,
|
|
1941
|
-
instructions,
|
|
1942
|
-
providerOptions,
|
|
1943
|
-
maxSteps,
|
|
1944
|
-
requireToolApproval
|
|
1945
|
-
} = modelSettings || {};
|
|
1946
|
-
const resolvedRequestContext = requestContext ?? propsRequestContext;
|
|
1947
|
-
_requestContext.current = resolvedRequestContext;
|
|
1948
|
-
setIsRunning(true);
|
|
1949
|
-
_streamAbortRef.current?.abort();
|
|
1950
|
-
const internalAbort = new AbortController();
|
|
1951
|
-
_streamAbortRef.current = internalAbort;
|
|
1952
|
-
if (signal) {
|
|
1953
|
-
if (signal.aborted) internalAbort.abort();
|
|
1954
|
-
else signal.addEventListener("abort", () => internalAbort.abort(), { once: true });
|
|
1955
|
-
}
|
|
1956
|
-
const clientWithAbort = new MastraClient({
|
|
1957
|
-
...baseClient.options,
|
|
1958
|
-
abortSignal: internalAbort.signal
|
|
1959
|
-
});
|
|
1960
|
-
const agent = clientWithAbort.getAgent(agentId);
|
|
1961
|
-
const runId = v4();
|
|
1962
|
-
const response = await agent.streamUntilIdle(coreUserMessages, {
|
|
1963
|
-
runId,
|
|
1964
|
-
maxSteps,
|
|
1965
|
-
modelSettings: {
|
|
1966
|
-
frequencyPenalty,
|
|
1967
|
-
presencePenalty,
|
|
1968
|
-
maxRetries,
|
|
1969
|
-
maxOutputTokens: maxTokens,
|
|
1970
|
-
temperature,
|
|
1971
|
-
topK,
|
|
1972
|
-
topP
|
|
1973
|
-
},
|
|
1974
|
-
instructions,
|
|
1975
|
-
requestContext: resolvedRequestContext,
|
|
1976
|
-
...threadId ? { memory: { thread: threadId, resource: resourceId || agentId } } : {},
|
|
1977
|
-
providerOptions,
|
|
1978
|
-
requireToolApproval,
|
|
1979
|
-
tracingOptions
|
|
1980
|
-
});
|
|
1981
|
-
_onChunk.current = onChunk;
|
|
1982
|
-
_currentRunId.current = runId;
|
|
1983
|
-
await response.processDataStream({
|
|
1984
|
-
onChunk: async (chunk) => {
|
|
1985
|
-
setMessages((prev) => toUIMessage({ chunk, conversation: prev, metadata: { mode: "stream" } }));
|
|
1986
|
-
void onChunk?.(chunk);
|
|
1987
|
-
}
|
|
1988
|
-
});
|
|
1989
|
-
if (_streamAbortRef.current === internalAbort) {
|
|
1990
|
-
_streamAbortRef.current = null;
|
|
1991
|
-
}
|
|
1992
|
-
setIsRunning(false);
|
|
1993
|
-
};
|
|
1994
|
-
const network = async ({
|
|
1995
|
-
coreUserMessages,
|
|
1996
|
-
requestContext,
|
|
1997
|
-
threadId,
|
|
1998
|
-
onNetworkChunk,
|
|
1999
|
-
modelSettings,
|
|
2000
|
-
signal,
|
|
2001
|
-
tracingOptions
|
|
2002
|
-
}) => {
|
|
2003
|
-
const { frequencyPenalty, presencePenalty, maxRetries, maxTokens, temperature, topK, topP, maxSteps } = modelSettings || {};
|
|
2004
|
-
const resolvedRequestContext = requestContext ?? propsRequestContext;
|
|
2005
|
-
_requestContext.current = resolvedRequestContext;
|
|
2006
|
-
setIsRunning(true);
|
|
2007
|
-
const clientWithAbort = new MastraClient({
|
|
2008
|
-
...baseClient.options,
|
|
2009
|
-
abortSignal: signal
|
|
2010
|
-
});
|
|
2011
|
-
const agent = clientWithAbort.getAgent(agentId);
|
|
2012
|
-
const runId = v4();
|
|
2013
|
-
const response = await agent.network(coreUserMessages, {
|
|
2014
|
-
maxSteps,
|
|
2015
|
-
modelSettings: {
|
|
2016
|
-
frequencyPenalty,
|
|
2017
|
-
presencePenalty,
|
|
2018
|
-
maxRetries,
|
|
2019
|
-
maxOutputTokens: maxTokens,
|
|
2020
|
-
temperature,
|
|
2021
|
-
topK,
|
|
2022
|
-
topP
|
|
2023
|
-
},
|
|
2024
|
-
runId,
|
|
2025
|
-
requestContext: resolvedRequestContext,
|
|
2026
|
-
...threadId ? { memory: { thread: threadId, resource: resourceId || agentId } } : {},
|
|
2027
|
-
tracingOptions
|
|
2028
|
-
});
|
|
2029
|
-
_onNetworkChunk.current = onNetworkChunk;
|
|
2030
|
-
_networkRunId.current = runId;
|
|
2031
|
-
const transformer = new AISdkNetworkTransformer();
|
|
2032
|
-
await response.processDataStream({
|
|
2033
|
-
onChunk: async (chunk) => {
|
|
2034
|
-
setMessages((prev) => transformer.transform({ chunk, conversation: prev, metadata: { mode: "network" } }));
|
|
2035
|
-
void onNetworkChunk?.(chunk);
|
|
2036
|
-
}
|
|
2037
|
-
});
|
|
2038
|
-
setIsRunning(false);
|
|
2039
|
-
};
|
|
2040
|
-
const handleCancelRun = () => {
|
|
2041
|
-
setIsRunning(false);
|
|
2042
|
-
_currentRunId.current = void 0;
|
|
2043
|
-
_onChunk.current = void 0;
|
|
2044
|
-
_networkRunId.current = void 0;
|
|
2045
|
-
_onNetworkChunk.current = void 0;
|
|
2046
|
-
_requestContext.current = void 0;
|
|
2047
|
-
};
|
|
2048
|
-
const approveToolCall = async (toolCallId) => {
|
|
2049
|
-
const onChunk = _onChunk.current;
|
|
2050
|
-
const currentRunId = _currentRunId.current;
|
|
2051
|
-
if (!currentRunId)
|
|
2052
|
-
return console.info("[approveToolCall] approveToolCall can only be called after a stream has started");
|
|
2053
|
-
setIsRunning(true);
|
|
2054
|
-
setToolCallApprovals((prev) => ({ ...prev, [toolCallId]: { status: "approved" } }));
|
|
2055
|
-
const agent = baseClient.getAgent(agentId);
|
|
2056
|
-
const response = await agent.approveToolCall({
|
|
2057
|
-
runId: currentRunId,
|
|
2058
|
-
toolCallId,
|
|
2059
|
-
requestContext: _requestContext.current
|
|
2060
|
-
});
|
|
2061
|
-
await response.processDataStream({
|
|
2062
|
-
onChunk: async (chunk) => {
|
|
2063
|
-
setMessages((prev) => toUIMessage({ chunk, conversation: prev, metadata: { mode: "stream" } }));
|
|
2064
|
-
void onChunk?.(chunk);
|
|
2065
|
-
}
|
|
2066
|
-
});
|
|
2067
|
-
setIsRunning(false);
|
|
2068
|
-
};
|
|
2069
|
-
const declineToolCall = async (toolCallId) => {
|
|
2070
|
-
const onChunk = _onChunk.current;
|
|
2071
|
-
const currentRunId = _currentRunId.current;
|
|
2072
|
-
if (!currentRunId)
|
|
2073
|
-
return console.info("[declineToolCall] declineToolCall can only be called after a stream has started");
|
|
2074
|
-
setIsRunning(true);
|
|
2075
|
-
setToolCallApprovals((prev) => ({ ...prev, [toolCallId]: { status: "declined" } }));
|
|
2076
|
-
const agent = baseClient.getAgent(agentId);
|
|
2077
|
-
const response = await agent.declineToolCall({
|
|
2078
|
-
runId: currentRunId,
|
|
2079
|
-
toolCallId,
|
|
2080
|
-
requestContext: _requestContext.current
|
|
2081
|
-
});
|
|
2082
|
-
await response.processDataStream({
|
|
2083
|
-
onChunk: async (chunk) => {
|
|
2084
|
-
setMessages((prev) => toUIMessage({ chunk, conversation: prev, metadata: { mode: "stream" } }));
|
|
2085
|
-
void onChunk?.(chunk);
|
|
2086
|
-
}
|
|
2087
|
-
});
|
|
2088
|
-
setIsRunning(false);
|
|
2089
|
-
};
|
|
2090
|
-
const approveToolCallGenerate = async (toolCallId) => {
|
|
2091
|
-
const currentRunId = _currentRunId.current;
|
|
2092
|
-
if (!currentRunId)
|
|
2093
|
-
return console.info(
|
|
2094
|
-
"[approveToolCallGenerate] approveToolCallGenerate can only be called after a generate has started"
|
|
2095
|
-
);
|
|
2096
|
-
setIsRunning(true);
|
|
2097
|
-
setToolCallApprovals((prev) => ({ ...prev, [toolCallId]: { status: "approved" } }));
|
|
2098
|
-
const agent = baseClient.getAgent(agentId);
|
|
2099
|
-
const response = await agent.approveToolCallGenerate({
|
|
2100
|
-
runId: currentRunId,
|
|
2101
|
-
toolCallId,
|
|
2102
|
-
requestContext: _requestContext.current
|
|
2103
|
-
});
|
|
2104
|
-
if (response && "uiMessages" in response.response && response.response.uiMessages) {
|
|
2105
|
-
const mastraUIMessages = (response.response.uiMessages || []).map((message) => ({
|
|
2106
|
-
...message,
|
|
2107
|
-
metadata: {
|
|
2108
|
-
mode: "generate"
|
|
2109
|
-
}
|
|
2110
|
-
}));
|
|
2111
|
-
setMessages((prev) => [...prev, ...mastraUIMessages]);
|
|
2112
|
-
}
|
|
2113
|
-
setIsRunning(false);
|
|
2114
|
-
};
|
|
2115
|
-
const declineToolCallGenerate = async (toolCallId) => {
|
|
2116
|
-
const currentRunId = _currentRunId.current;
|
|
2117
|
-
if (!currentRunId)
|
|
2118
|
-
return console.info(
|
|
2119
|
-
"[declineToolCallGenerate] declineToolCallGenerate can only be called after a generate has started"
|
|
2120
|
-
);
|
|
2121
|
-
setIsRunning(true);
|
|
2122
|
-
setToolCallApprovals((prev) => ({ ...prev, [toolCallId]: { status: "declined" } }));
|
|
2123
|
-
const agent = baseClient.getAgent(agentId);
|
|
2124
|
-
const response = await agent.declineToolCallGenerate({
|
|
2125
|
-
runId: currentRunId,
|
|
2126
|
-
toolCallId,
|
|
2127
|
-
requestContext: _requestContext.current
|
|
2128
|
-
});
|
|
2129
|
-
if (response && "uiMessages" in response.response && response.response.uiMessages) {
|
|
2130
|
-
const mastraUIMessages = (response.response.uiMessages || []).map((message) => ({
|
|
2131
|
-
...message,
|
|
2132
|
-
metadata: {
|
|
2133
|
-
mode: "generate"
|
|
2134
|
-
}
|
|
2135
|
-
}));
|
|
2136
|
-
setMessages((prev) => [...prev, ...mastraUIMessages]);
|
|
2137
|
-
}
|
|
2138
|
-
setIsRunning(false);
|
|
2139
|
-
};
|
|
2140
|
-
const approveNetworkToolCall = async (toolName, runId) => {
|
|
2141
|
-
const onNetworkChunk = _onNetworkChunk.current;
|
|
2142
|
-
const networkRunId = runId || _networkRunId.current;
|
|
2143
|
-
if (!networkRunId)
|
|
2144
|
-
return console.info(
|
|
2145
|
-
"[approveNetworkToolCall] approveNetworkToolCall can only be called after a network stream has started"
|
|
2146
|
-
);
|
|
2147
|
-
setIsRunning(true);
|
|
2148
|
-
setNetworkToolCallApprovals((prev) => ({
|
|
2149
|
-
...prev,
|
|
2150
|
-
[runId ? `${runId}-${toolName}` : toolName]: { status: "approved" }
|
|
2151
|
-
}));
|
|
2152
|
-
const agent = baseClient.getAgent(agentId);
|
|
2153
|
-
const response = await agent.approveNetworkToolCall({
|
|
2154
|
-
runId: networkRunId,
|
|
2155
|
-
requestContext: _requestContext.current
|
|
2156
|
-
});
|
|
2157
|
-
const transformer = new AISdkNetworkTransformer();
|
|
2158
|
-
await response.processDataStream({
|
|
2159
|
-
onChunk: async (chunk) => {
|
|
2160
|
-
setMessages((prev) => transformer.transform({ chunk, conversation: prev, metadata: { mode: "network" } }));
|
|
2161
|
-
void onNetworkChunk?.(chunk);
|
|
2162
|
-
}
|
|
2163
|
-
});
|
|
2164
|
-
setIsRunning(false);
|
|
2165
|
-
};
|
|
2166
|
-
const declineNetworkToolCall = async (toolName, runId) => {
|
|
2167
|
-
const onNetworkChunk = _onNetworkChunk.current;
|
|
2168
|
-
const networkRunId = runId || _networkRunId.current;
|
|
2169
|
-
if (!networkRunId)
|
|
2170
|
-
return console.info(
|
|
2171
|
-
"[declineNetworkToolCall] declineNetworkToolCall can only be called after a network stream has started"
|
|
2172
|
-
);
|
|
2173
|
-
setIsRunning(true);
|
|
2174
|
-
setNetworkToolCallApprovals((prev) => ({
|
|
2175
|
-
...prev,
|
|
2176
|
-
[runId ? `${runId}-${toolName}` : toolName]: { status: "declined" }
|
|
2177
|
-
}));
|
|
2178
|
-
const agent = baseClient.getAgent(agentId);
|
|
2179
|
-
const response = await agent.declineNetworkToolCall({
|
|
2180
|
-
runId: networkRunId,
|
|
2181
|
-
requestContext: _requestContext.current
|
|
2182
|
-
});
|
|
2183
|
-
const transformer = new AISdkNetworkTransformer();
|
|
2184
|
-
await response.processDataStream({
|
|
2185
|
-
onChunk: async (chunk) => {
|
|
2186
|
-
setMessages((prev) => transformer.transform({ chunk, conversation: prev, metadata: { mode: "network" } }));
|
|
2187
|
-
void onNetworkChunk?.(chunk);
|
|
2188
|
-
}
|
|
2189
|
-
});
|
|
2190
|
-
setIsRunning(false);
|
|
2191
|
-
};
|
|
2192
|
-
const sendMessage = async ({ mode = "stream", ...args }) => {
|
|
2193
|
-
const nextMessage = { role: "user", content: [{ type: "text", text: args.message }] };
|
|
2194
|
-
const coreUserMessages = [nextMessage];
|
|
2195
|
-
if (args.coreUserMessages) {
|
|
2196
|
-
coreUserMessages.push(...args.coreUserMessages);
|
|
2197
|
-
}
|
|
2198
|
-
const uiMessages = coreUserMessages.map(fromCoreUserMessageToUIMessage);
|
|
2199
|
-
setMessages((s) => [...s, ...uiMessages]);
|
|
2200
|
-
if (mode === "generate") {
|
|
2201
|
-
await generate({ ...args, coreUserMessages });
|
|
2202
|
-
} else if (mode === "stream") {
|
|
2203
|
-
await stream({ ...args, coreUserMessages });
|
|
2204
|
-
} else if (mode === "network") {
|
|
2205
|
-
await network({ ...args, coreUserMessages });
|
|
2206
|
-
}
|
|
2207
|
-
};
|
|
2208
|
-
return {
|
|
2209
|
-
setMessages,
|
|
2210
|
-
sendMessage,
|
|
2211
|
-
isRunning,
|
|
2212
|
-
messages,
|
|
2213
|
-
approveToolCall,
|
|
2214
|
-
declineToolCall,
|
|
2215
|
-
approveToolCallGenerate,
|
|
2216
|
-
declineToolCallGenerate,
|
|
2217
|
-
cancelRun: handleCancelRun,
|
|
2218
|
-
toolCallApprovals,
|
|
2219
|
-
approveNetworkToolCall,
|
|
2220
|
-
declineNetworkToolCall,
|
|
2221
|
-
networkToolCallApprovals
|
|
2222
|
-
};
|
|
2223
|
-
};
|
|
2224
|
-
var IconSizes = {
|
|
2225
|
-
sm: "mastra:[&>svg]:size-3",
|
|
2226
|
-
md: "mastra:[&>svg]:size-4",
|
|
2227
|
-
lg: "mastra:[&>svg]:size-5"
|
|
2228
|
-
};
|
|
2229
|
-
var Icon = ({ children, className, size = "md", ...props }) => {
|
|
2230
|
-
return /* @__PURE__ */ jsx("div", { className: className || IconSizes[size], ...props, children });
|
|
2231
|
-
};
|
|
2232
|
-
var EntityContext = createContext({
|
|
2233
|
-
expanded: false,
|
|
2234
|
-
setExpanded: () => {
|
|
2235
|
-
},
|
|
2236
|
-
variant: "initial",
|
|
2237
|
-
disabled: false
|
|
2238
|
-
});
|
|
2239
|
-
var EntityProvider = EntityContext.Provider;
|
|
2240
|
-
var useEntity = () => useContext(EntityContext);
|
|
2241
|
-
var Entity = ({
|
|
2242
|
-
className,
|
|
2243
|
-
variant = "initial",
|
|
2244
|
-
initialExpanded = false,
|
|
2245
|
-
disabled = false,
|
|
2246
|
-
...props
|
|
2247
|
-
}) => {
|
|
2248
|
-
const [expanded, setExpanded] = useState(initialExpanded);
|
|
2249
|
-
return /* @__PURE__ */ jsx(EntityProvider, { value: { expanded, setExpanded, variant, disabled }, children: /* @__PURE__ */ jsx("div", { className, ...props }) });
|
|
2250
|
-
};
|
|
2251
|
-
var EntityTriggerClass = twMerge(
|
|
2252
|
-
"mastra:aria-disabled:cursor-not-allowed mastra:aria-disabled:bg-surface5 mastra:aria-disabled:text-text3",
|
|
2253
|
-
"mastra:aria-expanded:rounded-b-none mastra:aria-expanded:border-b-0",
|
|
2254
|
-
"mastra:bg-surface3 mastra:text-text6 mastra:hover:bg-surface4 mastra:active:bg-surface5",
|
|
2255
|
-
"mastra:rounded-lg mastra:py-2 mastra:px-4 mastra:border mastra:border-border1",
|
|
2256
|
-
"mastra:cursor-pointer mastra:inline-flex mastra:items-center mastra:gap-1 mastra:font-mono"
|
|
2257
|
-
);
|
|
2258
|
-
var EntityTriggerVariantClasses = {
|
|
2259
|
-
agent: "mastra:[&_svg.mastra-icon]:text-accent1",
|
|
2260
|
-
workflow: "mastra:[&_svg.mastra-icon]:text-accent3",
|
|
2261
|
-
tool: "mastra:[&_svg.mastra-icon]:text-accent6",
|
|
2262
|
-
memory: "mastra:[&_svg.mastra-icon]:text-accent2",
|
|
2263
|
-
initial: "mastra:[&_svg.mastra-icon]:text-text3"
|
|
2264
|
-
};
|
|
2265
|
-
var EntityTrigger = ({ className, children, ...props }) => {
|
|
2266
|
-
const { expanded, setExpanded, variant, disabled } = useEntity();
|
|
2267
|
-
const handleClick = (e) => {
|
|
2268
|
-
if (disabled) return;
|
|
2269
|
-
setExpanded(!expanded);
|
|
2270
|
-
props?.onClick?.(e);
|
|
2271
|
-
};
|
|
2272
|
-
return /* @__PURE__ */ jsx(
|
|
2273
|
-
"button",
|
|
2274
|
-
{
|
|
2275
|
-
className: className || twMerge(EntityTriggerClass, !disabled && EntityTriggerVariantClasses[variant]),
|
|
2276
|
-
...props,
|
|
2277
|
-
onClick: handleClick,
|
|
2278
|
-
"aria-expanded": expanded,
|
|
2279
|
-
"aria-disabled": disabled,
|
|
2280
|
-
children
|
|
2281
|
-
}
|
|
2282
|
-
);
|
|
2283
|
-
};
|
|
2284
|
-
var EntityContentClass = twMerge(
|
|
2285
|
-
"mastra:space-y-4",
|
|
2286
|
-
"mastra:rounded-lg mastra:rounded-tl-none mastra:p-4 mastra:border mastra:border-border1 mastra:-mt-[0.5px]",
|
|
2287
|
-
"mastra:bg-surface3 mastra:text-text6"
|
|
2288
|
-
);
|
|
2289
|
-
var EntityContent = ({ className, ...props }) => {
|
|
2290
|
-
const { expanded } = useEntity();
|
|
2291
|
-
if (!expanded) return null;
|
|
2292
|
-
return /* @__PURE__ */ jsx("div", { className: className || EntityContentClass, ...props });
|
|
2293
|
-
};
|
|
2294
|
-
var EntityCaret = ({ className, ...props }) => {
|
|
2295
|
-
const { expanded } = useEntity();
|
|
2296
|
-
return /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx(
|
|
2297
|
-
ChevronDownIcon,
|
|
2298
|
-
{
|
|
2299
|
-
className: twMerge(
|
|
2300
|
-
`mastra:text-text3 mastra:transition-transform mastra:duration-200 mastra:ease-in-out`,
|
|
2301
|
-
expanded ? "mastra:rotate-0" : "mastra:-rotate-90",
|
|
2302
|
-
className
|
|
2303
|
-
),
|
|
2304
|
-
...props
|
|
2305
|
-
}
|
|
2306
|
-
) });
|
|
2307
|
-
};
|
|
2308
|
-
var ToolApprovalClass = twMerge(
|
|
2309
|
-
"mastra:rounded-lg mastra:border mastra:border-border1 mastra:max-w-1/2 mastra:mt-2",
|
|
2310
|
-
"mastra:bg-surface3 mastra:text-text6"
|
|
2311
|
-
);
|
|
2312
|
-
var ToolApproval = ({ className, ...props }) => {
|
|
2313
|
-
return /* @__PURE__ */ jsx("div", { className: className || ToolApprovalClass, ...props });
|
|
2314
|
-
};
|
|
2315
|
-
var ToolApprovalTitleClass = twMerge("mastra:text-text6 mastra:inline-flex mastra:items-center mastra:gap-1");
|
|
2316
|
-
var ToolApprovalTitle = ({ className, ...props }) => {
|
|
2317
|
-
return /* @__PURE__ */ jsx("div", { className: className || ToolApprovalTitleClass, ...props });
|
|
2318
|
-
};
|
|
2319
|
-
var ToolApprovalHeaderClass = twMerge(
|
|
2320
|
-
"mastra:flex mastra:justify-between mastra:items-center mastra:gap-2",
|
|
2321
|
-
"mastra:border-b mastra:border-border1 mastra:px-4 mastra:py-2"
|
|
2322
|
-
);
|
|
2323
|
-
var ToolApprovalHeader = ({ className, ...props }) => {
|
|
2324
|
-
return /* @__PURE__ */ jsx("div", { className: className || ToolApprovalHeaderClass, ...props });
|
|
2325
|
-
};
|
|
2326
|
-
var ToolApprovalContentClass = twMerge("mastra:text-text6 mastra:p-4");
|
|
2327
|
-
var ToolApprovalContent = ({ className, ...props }) => {
|
|
2328
|
-
return /* @__PURE__ */ jsx("div", { className: className || ToolApprovalContentClass, ...props });
|
|
2329
|
-
};
|
|
2330
|
-
var ToolApprovalActionsClass = twMerge("mastra:flex mastra:gap-2 mastra:items-center");
|
|
2331
|
-
var ToolApprovalActions = ({ className, ...props }) => {
|
|
2332
|
-
return /* @__PURE__ */ jsx("div", { className: className || ToolApprovalActionsClass, ...props });
|
|
2333
|
-
};
|
|
2334
|
-
var EntryClass = "mastra:space-y-2";
|
|
2335
|
-
var Entry = ({ className, ...props }) => {
|
|
2336
|
-
return /* @__PURE__ */ jsx("div", { className: className || EntryClass, ...props });
|
|
2337
|
-
};
|
|
2338
|
-
var EntryTitleClass = "mastra:font-mono mastra:text-sm mastra:text-text3";
|
|
2339
|
-
var EntryTitle = ({ className, as: Root = "h3", ...props }) => {
|
|
2340
|
-
return /* @__PURE__ */ jsx(Root, { className: className || EntryTitleClass, ...props });
|
|
2341
|
-
};
|
|
2342
|
-
var Tooltip = ({ children }) => {
|
|
2343
|
-
return /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsx(Root, { children }) });
|
|
2344
|
-
};
|
|
2345
|
-
var TooltipContentClass = "mastra:bg-surface4 mastra:text-text6 mastra mastra:rounded-lg mastra:py-1 mastra:px-2 mastra:text-xs mastra:border mastra:border-border1 mastra-tooltip-enter";
|
|
2346
|
-
var TooltipContent = ({ children, className, ...props }) => {
|
|
2347
|
-
return /* @__PURE__ */ jsx(TooltipPortal, { children: /* @__PURE__ */ jsx(TooltipContent$1, { className: className || TooltipContentClass, ...props, children }) });
|
|
2348
|
-
};
|
|
2349
|
-
var TooltipTrigger = (props) => {
|
|
2350
|
-
return /* @__PURE__ */ jsx(TooltipTrigger$1, { ...props, asChild: true });
|
|
2351
|
-
};
|
|
2352
|
-
var IconButtonClass = "mastra:text-text3 mastra:hover:text-text6 mastra:active:text-text6 mastra:hover:bg-surface4 mastra:active:bg-surface5 mastra:rounded-md mastra:cursor-pointer";
|
|
2353
|
-
var IconButton = ({ children, tooltip, size = "md", className, ...props }) => {
|
|
2354
|
-
return /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
2355
|
-
/* @__PURE__ */ jsx(TooltipTrigger, { children: /* @__PURE__ */ jsx(
|
|
2356
|
-
"button",
|
|
2357
|
-
{
|
|
2358
|
-
...props,
|
|
2359
|
-
className: className || twMerge(IconButtonClass, size === "md" && "mastra:p-0.5", size === "lg" && "mastra:p-1"),
|
|
2360
|
-
children: /* @__PURE__ */ jsx(Icon, { size, children })
|
|
2361
|
-
}
|
|
2362
|
-
) }),
|
|
2363
|
-
/* @__PURE__ */ jsx(TooltipContent, { children: tooltip })
|
|
2364
|
-
] });
|
|
2365
|
-
};
|
|
2366
|
-
async function highlight(code, lang) {
|
|
2367
|
-
const out = await codeToHast(code, {
|
|
2368
|
-
lang,
|
|
2369
|
-
theme: "dracula-soft"
|
|
2370
|
-
});
|
|
2371
|
-
return toJsxRuntime(out, {
|
|
2372
|
-
Fragment,
|
|
2373
|
-
jsx: jsx,
|
|
2374
|
-
jsxs: jsxs
|
|
2375
|
-
});
|
|
2376
|
-
}
|
|
2377
|
-
var CodeBlockClass = "mastra:rounded-lg mastra:[&>pre]:p-4 mastra:overflow-hidden mastra:[&>pre]:!bg-surface4 mastra:[&>pre>code]:leading-5 mastra:relative";
|
|
2378
|
-
var CodeBlock = ({ code, language, className, cta }) => {
|
|
2379
|
-
const [nodes, setNodes] = useState(null);
|
|
2380
|
-
useLayoutEffect(() => {
|
|
2381
|
-
void highlight(code, language).then(setNodes);
|
|
2382
|
-
}, [language]);
|
|
2383
|
-
return /* @__PURE__ */ jsxs("div", { className: className || CodeBlockClass, children: [
|
|
2384
|
-
nodes ?? null,
|
|
2385
|
-
cta
|
|
2386
|
-
] });
|
|
2387
|
-
};
|
|
2388
|
-
var CodeCopyButton = ({ code }) => {
|
|
2389
|
-
const [isCopied, setIsCopied] = useState(false);
|
|
2390
|
-
const handleCopy = () => {
|
|
2391
|
-
void navigator.clipboard.writeText(code);
|
|
2392
|
-
setIsCopied(true);
|
|
2393
|
-
setTimeout(() => setIsCopied(false), 2e3);
|
|
2394
|
-
};
|
|
2395
|
-
return /* @__PURE__ */ jsx("div", { className: "mastra:absolute mastra:top-2 mastra:right-2", children: /* @__PURE__ */ jsx(IconButton, { tooltip: "Copy", onClick: handleCopy, children: isCopied ? /* @__PURE__ */ jsx(CheckIcon, {}) : /* @__PURE__ */ jsx(CopyIcon, {}) }) });
|
|
2396
|
-
};
|
|
2397
|
-
var AgentIcon = ({ className, ...props }) => /* @__PURE__ */ jsxs(
|
|
2398
|
-
"svg",
|
|
2399
|
-
{
|
|
2400
|
-
width: "17",
|
|
2401
|
-
height: "16",
|
|
2402
|
-
viewBox: "0 0 17 16",
|
|
2403
|
-
fill: "none",
|
|
2404
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2405
|
-
...props,
|
|
2406
|
-
className: twMerge("mastra-icon", className),
|
|
2407
|
-
children: [
|
|
2408
|
-
/* @__PURE__ */ jsx(
|
|
2409
|
-
"path",
|
|
2410
|
-
{
|
|
2411
|
-
fillRule: "evenodd",
|
|
2412
|
-
clipRule: "evenodd",
|
|
2413
|
-
d: "M8.5 15C10.3565 15 12.137 14.2625 13.4497 12.9497C14.7625 11.637 15.5 9.85652 15.5 8C15.5 6.14348 14.7625 4.36301 13.4497 3.05025C12.137 1.7375 10.3565 1 8.5 1C6.64348 1 4.86301 1.7375 3.55025 3.05025C2.2375 4.36301 1.5 6.14348 1.5 8C1.5 9.85652 2.2375 11.637 3.55025 12.9497C4.86301 14.2625 6.64348 15 8.5 15ZM5.621 10.879L4.611 11.889C3.84179 11.1198 3.31794 10.1398 3.1057 9.07291C2.89346 8.00601 3.00236 6.90013 3.41864 5.89512C3.83491 4.89012 4.53986 4.03112 5.44434 3.42676C6.34881 2.8224 7.41219 2.49983 8.5 2.49983C9.58781 2.49983 10.6512 2.8224 11.5557 3.42676C12.4601 4.03112 13.1651 4.89012 13.5814 5.89512C13.9976 6.90013 14.1065 8.00601 13.8943 9.07291C13.6821 10.1398 13.1582 11.1198 12.389 11.889L11.379 10.879C11.1004 10.6003 10.7696 10.3792 10.4055 10.2284C10.0414 10.0776 9.6511 9.99995 9.257 10H7.743C7.3489 9.99995 6.95865 10.0776 6.59455 10.2284C6.23045 10.3792 5.89963 10.6003 5.621 10.879Z",
|
|
2414
|
-
fill: "currentColor"
|
|
2415
|
-
}
|
|
2416
|
-
),
|
|
2417
|
-
/* @__PURE__ */ jsx(
|
|
2418
|
-
"path",
|
|
2419
|
-
{
|
|
2420
|
-
d: "M8.5 4C7.96957 4 7.46086 4.21071 7.08579 4.58579C6.71071 4.96086 6.5 5.46957 6.5 6V6.5C6.5 7.03043 6.71071 7.53914 7.08579 7.91421C7.46086 8.28929 7.96957 8.5 8.5 8.5C9.03043 8.5 9.53914 8.28929 9.91421 7.91421C10.2893 7.53914 10.5 7.03043 10.5 6.5V6C10.5 5.46957 10.2893 4.96086 9.91421 4.58579C9.53914 4.21071 9.03043 4 8.5 4Z",
|
|
2421
|
-
fill: "currentColor"
|
|
2422
|
-
}
|
|
2423
|
-
)
|
|
2424
|
-
]
|
|
2425
|
-
}
|
|
2426
|
-
);
|
|
2427
|
-
var ToolsIcon = ({ className, ...props }) => /* @__PURE__ */ jsx(
|
|
2428
|
-
"svg",
|
|
2429
|
-
{
|
|
2430
|
-
width: "17",
|
|
2431
|
-
height: "16",
|
|
2432
|
-
viewBox: "0 0 17 16",
|
|
2433
|
-
fill: "none",
|
|
2434
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2435
|
-
...props,
|
|
2436
|
-
className: twMerge("mastra-icon", className),
|
|
2437
|
-
children: /* @__PURE__ */ jsx(
|
|
2438
|
-
"path",
|
|
2439
|
-
{
|
|
2440
|
-
fillRule: "evenodd",
|
|
2441
|
-
clipRule: "evenodd",
|
|
2442
|
-
d: "M7.5605 1.42351C8.0791 0.904904 8.92215 0.906157 9.4395 1.42351L10.6922 2.67617C11.2108 3.19477 11.2095 4.03782 10.6922 4.55517L9.4395 5.80783C8.9209 6.32643 8.07785 6.32518 7.5605 5.80783L6.30784 4.55517C5.78923 4.03656 5.79049 3.19352 6.30784 2.67617L7.5605 1.42351ZM3.17618 5.80783C3.69478 5.28923 4.53782 5.29048 5.05517 5.80783L6.30784 7.0605C6.82644 7.5791 6.82519 8.42214 6.30784 8.93949L5.05517 10.1922C4.53657 10.7108 3.69353 10.7095 3.17618 10.1922L1.92351 8.93949C1.40491 8.42089 1.40616 7.57785 1.92351 7.0605L3.17618 5.80783ZM11.9448 5.80783C12.4634 5.28923 13.3065 5.29048 13.8238 5.80783L15.0765 7.0605C15.5951 7.5791 15.5938 8.42214 15.0765 8.93949L13.8238 10.1922C13.3052 10.7108 12.4622 10.7095 11.9448 10.1922L10.6922 8.93949C10.1736 8.42089 10.1748 7.57785 10.6922 7.0605L11.9448 5.80783ZM7.5605 10.1922C8.0791 9.67355 8.92215 9.67481 9.4395 10.1922L10.6922 11.4448C11.2108 11.9634 11.2095 12.8065 10.6922 13.3238L9.4395 14.5765C8.9209 15.0951 8.07785 15.0938 7.5605 14.5765L6.30784 13.3238C5.78923 12.8052 5.79049 11.9622 6.30784 11.4448L7.5605 10.1922Z",
|
|
2443
|
-
fill: "currentColor"
|
|
2444
|
-
}
|
|
2445
|
-
)
|
|
2446
|
-
}
|
|
2447
|
-
);
|
|
2448
|
-
var WorkflowIcon = ({ className, ...props }) => /* @__PURE__ */ jsx(
|
|
2449
|
-
"svg",
|
|
2450
|
-
{
|
|
2451
|
-
width: "17",
|
|
2452
|
-
height: "16",
|
|
2453
|
-
viewBox: "0 0 17 16",
|
|
2454
|
-
fill: "none",
|
|
2455
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
2456
|
-
...props,
|
|
2457
|
-
className: twMerge("mastra-icon", className),
|
|
2458
|
-
children: /* @__PURE__ */ jsx(
|
|
2459
|
-
"path",
|
|
2460
|
-
{
|
|
2461
|
-
fillRule: "evenodd",
|
|
2462
|
-
clipRule: "evenodd",
|
|
2463
|
-
d: "M6.24388 2.4018C6.24388 2.0394 6.53767 1.74561 6.90008 1.74561H10.0991C10.4614 1.74561 10.7553 2.0394 10.7553 2.4018V4.57546C10.7553 4.93787 10.4614 5.23166 10.0991 5.23166H9.31982V7.35469L10.0033 9.22664C9.90442 9.20146 9.80035 9.1761 9.6915 9.14986L9.62652 9.13422C9.30473 9.05687 8.92256 8.96501 8.61993 8.84491C8.5819 8.82981 8.54147 8.81292 8.49957 8.79391C8.45767 8.81292 8.41724 8.82981 8.3792 8.84491C8.07657 8.96501 7.6944 9.05687 7.37261 9.13422L7.30763 9.14986C7.19879 9.1761 7.09471 9.20146 6.99577 9.22664L7.67932 7.35469V5.23166H6.90008C6.53767 5.23166 6.24388 4.93787 6.24388 4.57546V2.4018ZM6.99577 9.22664C6.99577 9.22664 6.99578 9.22664 6.99577 9.22664L6.43283 10.7683H6.81806C7.18047 10.7683 7.47426 11.0622 7.47426 11.4245V13.5982C7.47426 13.9606 7.18047 14.2544 6.81806 14.2544H3.61909C3.25668 14.2544 2.96289 13.9606 2.96289 13.5982V11.4245C2.96289 11.0622 3.25668 10.7683 3.61909 10.7683H4.26617C4.2921 10.4663 4.32783 10.1494 4.37744 9.85171C4.43762 9.49063 4.52982 9.08135 4.68998 8.76102C4.93975 8.2615 5.44743 8.01751 5.7771 7.88788C6.14684 7.74249 6.57537 7.63889 6.92317 7.55505C7.24707 7.47696 7.49576 7.41679 7.67932 7.35469L6.99577 9.22664ZM6.43283 10.7683L6.99577 9.22664C6.75846 9.28705 6.55067 9.34646 6.37745 9.41458C6.22784 9.47341 6.1623 9.51712 6.14023 9.53254C6.09752 9.63631 6.04409 9.83055 5.99562 10.1214C5.96201 10.3231 5.93498 10.5439 5.91341 10.7683H6.43283ZM10.0033 9.22664L9.31982 7.35469C9.50338 7.41679 9.75206 7.47696 10.076 7.55505C10.4238 7.63889 10.8523 7.74249 11.2221 7.88788C11.5517 8.01751 12.0594 8.2615 12.3091 8.76102C12.4693 9.08135 12.5615 9.49063 12.6217 9.85171C12.6713 10.1494 12.707 10.4663 12.733 10.7683H13.38C13.7424 10.7683 14.0362 11.0622 14.0362 11.4245V13.5982C14.0362 13.9606 13.7424 14.2544 13.38 14.2544H10.1811C9.81867 14.2544 9.52488 13.9606 9.52488 13.5982V11.4245C9.52488 11.0622 9.81867 10.7683 10.1811 10.7683H10.5663L10.0033 9.22664ZM10.0033 9.22664L10.5663 10.7683H11.0857C11.0642 10.5439 11.0372 10.3231 11.0035 10.1214C10.9551 9.83055 10.9016 9.63631 10.8589 9.53254C10.8369 9.51712 10.7713 9.47341 10.6217 9.41458C10.4485 9.34646 10.2407 9.28705 10.0033 9.22664Z",
|
|
2464
|
-
fill: "currentColor"
|
|
2465
|
-
}
|
|
2466
|
-
)
|
|
2467
|
-
}
|
|
2468
|
-
);
|
|
2469
|
-
var MessageClass = "mastra:flex mastra:flex-col mastra:w-full mastra:py-4 mastra:gap-2 mastra:group";
|
|
2470
|
-
var Message = ({ position, className, children, ...props }) => {
|
|
2471
|
-
return /* @__PURE__ */ jsx(
|
|
2472
|
-
"div",
|
|
2473
|
-
{
|
|
2474
|
-
className: className || twMerge(
|
|
2475
|
-
MessageClass,
|
|
2476
|
-
position === "left" ? "" : "mastra:items-end mastra:[&_.mastra-message-content]:bg-surface4 mastra:[&_.mastra-message-content]:px-4"
|
|
2477
|
-
),
|
|
2478
|
-
...props,
|
|
2479
|
-
children
|
|
2480
|
-
}
|
|
2481
|
-
);
|
|
2482
|
-
};
|
|
2483
|
-
var MessageContentClass = "mastra:max-w-4/5 mastra:py-2 mastra:text-text6 mastra:rounded-lg mastra-message-content mastra:text-md";
|
|
2484
|
-
var MessageContent = ({ children, className, isStreaming, ...props }) => {
|
|
2485
|
-
return /* @__PURE__ */ jsxs("div", { className: className || MessageContentClass, ...props, children: [
|
|
2486
|
-
children,
|
|
2487
|
-
isStreaming && /* @__PURE__ */ jsx(MessageStreaming, {})
|
|
2488
|
-
] });
|
|
2489
|
-
};
|
|
2490
|
-
var MessageActionsClass = "mastra:gap-2 mastra:flex mastra:opacity-0 mastra:group-hover:opacity-100 mastra:group-focus-within:opacity-100 mastra:items-center";
|
|
2491
|
-
var MessageActions = ({ children, className, ...props }) => {
|
|
2492
|
-
return /* @__PURE__ */ jsx("div", { className: className || MessageActionsClass, ...props, children });
|
|
2493
|
-
};
|
|
2494
|
-
var MessageUsagesClass = "mastra:flex mastra:gap-2 mastra:items-center";
|
|
2495
|
-
var MessageUsages = ({ children, className, ...props }) => {
|
|
2496
|
-
return /* @__PURE__ */ jsx("div", { className: className || MessageUsagesClass, ...props, children });
|
|
2497
|
-
};
|
|
2498
|
-
var MessageUsageClass = "mastra:flex mastra:gap-2 mastra:items-center mastra:font-mono mastra:text-xs mastra:bg-surface3 mastra:rounded-lg mastra:px-2 mastra:py-1";
|
|
2499
|
-
var MessageUsage = ({ children, className, ...props }) => {
|
|
2500
|
-
return /* @__PURE__ */ jsx("dl", { className: className || MessageUsageClass, ...props, children });
|
|
2501
|
-
};
|
|
2502
|
-
var MessageUsageEntryClass = "mastra:text-text3 mastra:text-xs mastra:flex mastra:gap-1 mastra:items-center";
|
|
2503
|
-
var MessageUsageEntry = ({ children, className, ...props }) => {
|
|
2504
|
-
return /* @__PURE__ */ jsx("dt", { className: className || MessageUsageEntryClass, ...props, children });
|
|
2505
|
-
};
|
|
2506
|
-
var MessageUsageValueClass = "mastra:text-text6 mastra:text-xs";
|
|
2507
|
-
var MessageUsageValue = ({ children, className, ...props }) => {
|
|
2508
|
-
return /* @__PURE__ */ jsx("dd", { className: className || MessageUsageValueClass, ...props, children });
|
|
2509
|
-
};
|
|
2510
|
-
var MessageListClass = "mastra:overflow-y-auto mastra:h-full mastra-list";
|
|
2511
|
-
var MessageList = ({ children, className, ...props }) => {
|
|
2512
|
-
const listRef = useRef(null);
|
|
2513
|
-
useEffect(() => {
|
|
2514
|
-
const scrollToBottom = () => {
|
|
2515
|
-
if (!listRef.current) return;
|
|
2516
|
-
listRef.current.scrollTo({ top: listRef.current.scrollHeight, behavior: "smooth" });
|
|
2517
|
-
};
|
|
2518
|
-
requestAnimationFrame(scrollToBottom);
|
|
2519
|
-
});
|
|
2520
|
-
return /* @__PURE__ */ jsx("div", { className: className || MessageListClass, ...props, ref: listRef, children });
|
|
2521
|
-
};
|
|
2522
|
-
var MessageStreamingClass = "mastra:inline-block mastra:w-[2px] mastra:h-[1em] mastra:bg-text5 mastra:ml-0.5 mastra:align-text-bottom mastra:animate-pulse";
|
|
2523
|
-
var MessageStreaming = ({ className, ...props }) => {
|
|
2524
|
-
return /* @__PURE__ */ jsx("span", { className: className || MessageStreamingClass, ...props });
|
|
2525
|
-
};
|
|
2526
|
-
function useMutation(mutationFn) {
|
|
2527
|
-
const [isPending, setIsPending] = useState(false);
|
|
2528
|
-
const [isSuccess, setIsSuccess] = useState(false);
|
|
2529
|
-
const [isError, setIsError] = useState(false);
|
|
2530
|
-
const [error, setError] = useState(null);
|
|
2531
|
-
const [data, setData] = useState(void 0);
|
|
2532
|
-
const mutationFnRef = useRef(mutationFn);
|
|
2533
|
-
mutationFnRef.current = mutationFn;
|
|
2534
|
-
const reset = useCallback(() => {
|
|
2535
|
-
setIsPending(false);
|
|
2536
|
-
setIsSuccess(false);
|
|
2537
|
-
setIsError(false);
|
|
2538
|
-
setError(null);
|
|
2539
|
-
setData(void 0);
|
|
2540
|
-
}, []);
|
|
2541
|
-
const mutateAsync = useCallback(async (variables) => {
|
|
2542
|
-
setIsPending(true);
|
|
2543
|
-
setIsSuccess(false);
|
|
2544
|
-
setIsError(false);
|
|
2545
|
-
setError(null);
|
|
2546
|
-
try {
|
|
2547
|
-
const result = await mutationFnRef.current(variables);
|
|
2548
|
-
setData(result);
|
|
2549
|
-
setIsSuccess(true);
|
|
2550
|
-
return result;
|
|
2551
|
-
} catch (err) {
|
|
2552
|
-
const typedError = err;
|
|
2553
|
-
setError(typedError);
|
|
2554
|
-
setIsError(true);
|
|
2555
|
-
throw err;
|
|
2556
|
-
} finally {
|
|
2557
|
-
setIsPending(false);
|
|
2558
|
-
}
|
|
2559
|
-
}, []);
|
|
2560
|
-
const mutate = useCallback(
|
|
2561
|
-
(variables) => {
|
|
2562
|
-
mutateAsync(variables).catch(() => {
|
|
2563
|
-
});
|
|
2564
|
-
},
|
|
2565
|
-
[mutateAsync]
|
|
2566
|
-
);
|
|
2567
|
-
return {
|
|
2568
|
-
mutate,
|
|
2569
|
-
mutateAsync,
|
|
2570
|
-
isPending,
|
|
2571
|
-
isSuccess,
|
|
2572
|
-
isError,
|
|
2573
|
-
error,
|
|
2574
|
-
data,
|
|
2575
|
-
reset
|
|
2576
|
-
};
|
|
2577
|
-
}
|
|
2578
|
-
function useStreamWorkflow({ debugMode, tracingOptions, onError }) {
|
|
2579
|
-
const client = useMastraClient();
|
|
2580
|
-
const [streamResult, setStreamResult] = useState({});
|
|
2581
|
-
const [isStreaming, setIsStreaming] = useState(false);
|
|
2582
|
-
const readerRef = useRef(null);
|
|
2583
|
-
const observerRef = useRef(null);
|
|
2584
|
-
const resumeStreamRef = useRef(null);
|
|
2585
|
-
const timeTravelStreamRef = useRef(null);
|
|
2586
|
-
const isMountedRef = useRef(true);
|
|
2587
|
-
useEffect(() => {
|
|
2588
|
-
isMountedRef.current = true;
|
|
2589
|
-
return () => {
|
|
2590
|
-
isMountedRef.current = false;
|
|
2591
|
-
if (readerRef.current) {
|
|
2592
|
-
try {
|
|
2593
|
-
readerRef.current.releaseLock();
|
|
2594
|
-
} catch {
|
|
2595
|
-
}
|
|
2596
|
-
readerRef.current = null;
|
|
2597
|
-
}
|
|
2598
|
-
if (observerRef.current) {
|
|
2599
|
-
try {
|
|
2600
|
-
observerRef.current.releaseLock();
|
|
2601
|
-
} catch {
|
|
2602
|
-
}
|
|
2603
|
-
observerRef.current = null;
|
|
2604
|
-
}
|
|
2605
|
-
if (resumeStreamRef.current) {
|
|
2606
|
-
try {
|
|
2607
|
-
resumeStreamRef.current.releaseLock();
|
|
2608
|
-
} catch {
|
|
2609
|
-
}
|
|
2610
|
-
resumeStreamRef.current = null;
|
|
2611
|
-
}
|
|
2612
|
-
if (timeTravelStreamRef.current) {
|
|
2613
|
-
try {
|
|
2614
|
-
timeTravelStreamRef.current.releaseLock();
|
|
2615
|
-
} catch {
|
|
2616
|
-
}
|
|
2617
|
-
timeTravelStreamRef.current = null;
|
|
2618
|
-
}
|
|
2619
|
-
};
|
|
2620
|
-
}, []);
|
|
2621
|
-
const handleStreamError = useCallback(
|
|
2622
|
-
(err, defaultMessage, setStreamingState) => {
|
|
2623
|
-
if (err instanceof TypeError) {
|
|
2624
|
-
return;
|
|
2625
|
-
}
|
|
2626
|
-
const error = err instanceof Error ? err : new Error(defaultMessage);
|
|
2627
|
-
onError?.(error, defaultMessage);
|
|
2628
|
-
setStreamingState?.(false);
|
|
2629
|
-
},
|
|
2630
|
-
[onError]
|
|
2631
|
-
);
|
|
2632
|
-
const handleWorkflowFinish = useCallback((value) => {
|
|
2633
|
-
if (value.type === "workflow-finish") {
|
|
2634
|
-
const streamStatus = value.payload?.workflowStatus;
|
|
2635
|
-
const metadata = value.payload?.metadata;
|
|
2636
|
-
setStreamResult((prev) => ({
|
|
2637
|
-
...prev,
|
|
2638
|
-
status: streamStatus
|
|
2639
|
-
}));
|
|
2640
|
-
if (streamStatus === "failed") {
|
|
2641
|
-
throw new Error(metadata?.errorMessage || "Workflow execution failed");
|
|
2642
|
-
}
|
|
2643
|
-
}
|
|
2644
|
-
}, []);
|
|
2645
|
-
const streamWorkflow = useMutation(
|
|
2646
|
-
async ({ workflowId, runId, inputData, initialState, requestContext: playgroundRequestContext, perStep }) => {
|
|
2647
|
-
if (readerRef.current) {
|
|
2648
|
-
readerRef.current.releaseLock();
|
|
2649
|
-
}
|
|
2650
|
-
if (!isMountedRef.current) return;
|
|
2651
|
-
setIsStreaming(true);
|
|
2652
|
-
setStreamResult({ input: inputData });
|
|
2653
|
-
const workflow = client.getWorkflow(workflowId);
|
|
2654
|
-
const run = await workflow.createRun({ runId });
|
|
2655
|
-
const stream = await run.stream({
|
|
2656
|
-
inputData,
|
|
2657
|
-
initialState,
|
|
2658
|
-
requestContext: playgroundRequestContext,
|
|
2659
|
-
closeOnSuspend: true,
|
|
2660
|
-
tracingOptions,
|
|
2661
|
-
perStep: perStep ?? debugMode
|
|
2662
|
-
});
|
|
2663
|
-
if (!stream) {
|
|
2664
|
-
return handleStreamError(new Error("No stream returned"), "No stream returned", setIsStreaming);
|
|
2665
|
-
}
|
|
2666
|
-
const reader = stream.getReader();
|
|
2667
|
-
readerRef.current = reader;
|
|
2668
|
-
try {
|
|
2669
|
-
while (true) {
|
|
2670
|
-
if (!isMountedRef.current) break;
|
|
2671
|
-
const { done, value } = await reader.read();
|
|
2672
|
-
if (done) break;
|
|
2673
|
-
if (isMountedRef.current) {
|
|
2674
|
-
setStreamResult((prev) => {
|
|
2675
|
-
const newResult = mapWorkflowStreamChunkToWatchResult(prev, value);
|
|
2676
|
-
return newResult;
|
|
2677
|
-
});
|
|
2678
|
-
if (value.type === "workflow-step-start") {
|
|
2679
|
-
setIsStreaming(true);
|
|
2680
|
-
}
|
|
2681
|
-
if (value.type === "workflow-step-suspended") {
|
|
2682
|
-
setIsStreaming(false);
|
|
2683
|
-
}
|
|
2684
|
-
if (value.type === "workflow-finish") {
|
|
2685
|
-
handleWorkflowFinish(value);
|
|
2686
|
-
}
|
|
2687
|
-
}
|
|
2688
|
-
}
|
|
2689
|
-
} catch (err) {
|
|
2690
|
-
handleStreamError(err, "Error streaming workflow");
|
|
2691
|
-
} finally {
|
|
2692
|
-
if (isMountedRef.current) {
|
|
2693
|
-
setIsStreaming(false);
|
|
2694
|
-
}
|
|
2695
|
-
if (readerRef.current) {
|
|
2696
|
-
readerRef.current.releaseLock();
|
|
2697
|
-
readerRef.current = null;
|
|
2698
|
-
}
|
|
2699
|
-
}
|
|
2700
|
-
}
|
|
2701
|
-
);
|
|
2702
|
-
const observeWorkflowStream = useMutation(
|
|
2703
|
-
async ({ workflowId, runId, storeRunResult }) => {
|
|
2704
|
-
if (observerRef.current) {
|
|
2705
|
-
observerRef.current.releaseLock();
|
|
2706
|
-
}
|
|
2707
|
-
if (!isMountedRef.current) return;
|
|
2708
|
-
setIsStreaming(true);
|
|
2709
|
-
setStreamResult(storeRunResult || {});
|
|
2710
|
-
if (storeRunResult?.status === "suspended") {
|
|
2711
|
-
setIsStreaming(false);
|
|
2712
|
-
return;
|
|
2713
|
-
}
|
|
2714
|
-
const workflow = client.getWorkflow(workflowId);
|
|
2715
|
-
const run = await workflow.createRun({ runId });
|
|
2716
|
-
const stream = await run.observeStream();
|
|
2717
|
-
if (!stream) {
|
|
2718
|
-
return handleStreamError(new Error("No stream returned"), "No stream returned", setIsStreaming);
|
|
2719
|
-
}
|
|
2720
|
-
const reader = stream.getReader();
|
|
2721
|
-
observerRef.current = reader;
|
|
2722
|
-
try {
|
|
2723
|
-
while (true) {
|
|
2724
|
-
if (!isMountedRef.current) break;
|
|
2725
|
-
const { done, value } = await reader.read();
|
|
2726
|
-
if (done) break;
|
|
2727
|
-
if (isMountedRef.current) {
|
|
2728
|
-
setStreamResult((prev) => {
|
|
2729
|
-
const newResult = mapWorkflowStreamChunkToWatchResult(prev, value);
|
|
2730
|
-
return newResult;
|
|
2731
|
-
});
|
|
2732
|
-
if (value.type === "workflow-step-start") {
|
|
2733
|
-
setIsStreaming(true);
|
|
2734
|
-
}
|
|
2735
|
-
if (value.type === "workflow-step-suspended") {
|
|
2736
|
-
setIsStreaming(false);
|
|
2737
|
-
}
|
|
2738
|
-
if (value.type === "workflow-finish") {
|
|
2739
|
-
handleWorkflowFinish(value);
|
|
2740
|
-
}
|
|
2741
|
-
}
|
|
2742
|
-
}
|
|
2743
|
-
} catch (err) {
|
|
2744
|
-
handleStreamError(err, "Error observing workflow");
|
|
2745
|
-
} finally {
|
|
2746
|
-
if (isMountedRef.current) {
|
|
2747
|
-
setIsStreaming(false);
|
|
2748
|
-
}
|
|
2749
|
-
if (observerRef.current) {
|
|
2750
|
-
observerRef.current.releaseLock();
|
|
2751
|
-
observerRef.current = null;
|
|
2752
|
-
}
|
|
2753
|
-
}
|
|
2754
|
-
}
|
|
2755
|
-
);
|
|
2756
|
-
const resumeWorkflowStream = useMutation(
|
|
2757
|
-
async ({ workflowId, runId, step, resumeData, requestContext: playgroundRequestContext, perStep }) => {
|
|
2758
|
-
if (resumeStreamRef.current) {
|
|
2759
|
-
resumeStreamRef.current.releaseLock();
|
|
2760
|
-
}
|
|
2761
|
-
if (!isMountedRef.current) return;
|
|
2762
|
-
setIsStreaming(true);
|
|
2763
|
-
const workflow = client.getWorkflow(workflowId);
|
|
2764
|
-
const run = await workflow.createRun({ runId });
|
|
2765
|
-
const stream = await run.resumeStream({
|
|
2766
|
-
step,
|
|
2767
|
-
resumeData,
|
|
2768
|
-
requestContext: playgroundRequestContext,
|
|
2769
|
-
tracingOptions,
|
|
2770
|
-
perStep: perStep ?? debugMode
|
|
2771
|
-
});
|
|
2772
|
-
if (!stream) {
|
|
2773
|
-
return handleStreamError(new Error("No stream returned"), "No stream returned", setIsStreaming);
|
|
2774
|
-
}
|
|
2775
|
-
const reader = stream.getReader();
|
|
2776
|
-
resumeStreamRef.current = reader;
|
|
2777
|
-
try {
|
|
2778
|
-
while (true) {
|
|
2779
|
-
if (!isMountedRef.current) break;
|
|
2780
|
-
const { done, value } = await reader.read();
|
|
2781
|
-
if (done) break;
|
|
2782
|
-
if (isMountedRef.current) {
|
|
2783
|
-
setStreamResult((prev) => {
|
|
2784
|
-
const newResult = mapWorkflowStreamChunkToWatchResult(prev, value);
|
|
2785
|
-
return newResult;
|
|
2786
|
-
});
|
|
2787
|
-
if (value.type === "workflow-step-start") {
|
|
2788
|
-
setIsStreaming(true);
|
|
2789
|
-
}
|
|
2790
|
-
if (value.type === "workflow-step-suspended") {
|
|
2791
|
-
setIsStreaming(false);
|
|
2792
|
-
}
|
|
2793
|
-
if (value.type === "workflow-finish") {
|
|
2794
|
-
handleWorkflowFinish(value);
|
|
2795
|
-
}
|
|
2796
|
-
}
|
|
2797
|
-
}
|
|
2798
|
-
} catch (err) {
|
|
2799
|
-
handleStreamError(err, "Error resuming workflow stream");
|
|
2800
|
-
} finally {
|
|
2801
|
-
if (isMountedRef.current) {
|
|
2802
|
-
setIsStreaming(false);
|
|
2803
|
-
}
|
|
2804
|
-
if (resumeStreamRef.current) {
|
|
2805
|
-
resumeStreamRef.current.releaseLock();
|
|
2806
|
-
resumeStreamRef.current = null;
|
|
2807
|
-
}
|
|
2808
|
-
}
|
|
2809
|
-
}
|
|
2810
|
-
);
|
|
2811
|
-
const timeTravelWorkflowStream = useMutation(
|
|
2812
|
-
async ({ workflowId, requestContext: playgroundRequestContext, runId, perStep, ...params }) => {
|
|
2813
|
-
if (timeTravelStreamRef.current) {
|
|
2814
|
-
timeTravelStreamRef.current.releaseLock();
|
|
2815
|
-
}
|
|
2816
|
-
if (!isMountedRef.current) return;
|
|
2817
|
-
setIsStreaming(true);
|
|
2818
|
-
const workflow = client.getWorkflow(workflowId);
|
|
2819
|
-
const run = await workflow.createRun({ runId });
|
|
2820
|
-
const stream = await run.timeTravelStream({
|
|
2821
|
-
...params,
|
|
2822
|
-
perStep: perStep ?? debugMode,
|
|
2823
|
-
requestContext: playgroundRequestContext,
|
|
2824
|
-
tracingOptions
|
|
2825
|
-
});
|
|
2826
|
-
if (!stream) {
|
|
2827
|
-
return handleStreamError(new Error("No stream returned"), "No stream returned", setIsStreaming);
|
|
2828
|
-
}
|
|
2829
|
-
const reader = stream.getReader();
|
|
2830
|
-
timeTravelStreamRef.current = reader;
|
|
2831
|
-
try {
|
|
2832
|
-
while (true) {
|
|
2833
|
-
if (!isMountedRef.current) break;
|
|
2834
|
-
const { done, value } = await reader.read();
|
|
2835
|
-
if (done) break;
|
|
2836
|
-
if (isMountedRef.current) {
|
|
2837
|
-
setStreamResult((prev) => {
|
|
2838
|
-
const newResult = mapWorkflowStreamChunkToWatchResult(prev, value);
|
|
2839
|
-
return newResult;
|
|
2840
|
-
});
|
|
2841
|
-
if (value.type === "workflow-step-start") {
|
|
2842
|
-
setIsStreaming(true);
|
|
2843
|
-
}
|
|
2844
|
-
if (value.type === "workflow-step-suspended") {
|
|
2845
|
-
setIsStreaming(false);
|
|
2846
|
-
}
|
|
2847
|
-
if (value.type === "workflow-finish") {
|
|
2848
|
-
handleWorkflowFinish(value);
|
|
2849
|
-
}
|
|
2850
|
-
}
|
|
2851
|
-
}
|
|
2852
|
-
} catch (err) {
|
|
2853
|
-
handleStreamError(err, "Error time traveling workflow stream");
|
|
2854
|
-
} finally {
|
|
2855
|
-
if (isMountedRef.current) {
|
|
2856
|
-
setIsStreaming(false);
|
|
2857
|
-
}
|
|
2858
|
-
if (timeTravelStreamRef.current) {
|
|
2859
|
-
timeTravelStreamRef.current.releaseLock();
|
|
2860
|
-
timeTravelStreamRef.current = null;
|
|
2861
|
-
}
|
|
2862
|
-
}
|
|
2863
|
-
}
|
|
2864
|
-
);
|
|
2865
|
-
const closeStreamsAndReset = useCallback(() => {
|
|
2866
|
-
setIsStreaming(false);
|
|
2867
|
-
setStreamResult({});
|
|
2868
|
-
if (readerRef.current) {
|
|
2869
|
-
try {
|
|
2870
|
-
readerRef.current.releaseLock();
|
|
2871
|
-
} catch {
|
|
2872
|
-
}
|
|
2873
|
-
readerRef.current = null;
|
|
2874
|
-
}
|
|
2875
|
-
if (observerRef.current) {
|
|
2876
|
-
try {
|
|
2877
|
-
observerRef.current.releaseLock();
|
|
2878
|
-
} catch {
|
|
2879
|
-
}
|
|
2880
|
-
observerRef.current = null;
|
|
2881
|
-
}
|
|
2882
|
-
if (resumeStreamRef.current) {
|
|
2883
|
-
try {
|
|
2884
|
-
resumeStreamRef.current.releaseLock();
|
|
2885
|
-
} catch {
|
|
2886
|
-
}
|
|
2887
|
-
resumeStreamRef.current = null;
|
|
2888
|
-
}
|
|
2889
|
-
if (timeTravelStreamRef.current) {
|
|
2890
|
-
try {
|
|
2891
|
-
timeTravelStreamRef.current.releaseLock();
|
|
2892
|
-
} catch {
|
|
2893
|
-
}
|
|
2894
|
-
timeTravelStreamRef.current = null;
|
|
2895
|
-
}
|
|
2896
|
-
}, []);
|
|
2897
|
-
return {
|
|
2898
|
-
streamWorkflow,
|
|
2899
|
-
streamResult,
|
|
2900
|
-
isStreaming,
|
|
2901
|
-
observeWorkflowStream,
|
|
2902
|
-
closeStreamsAndReset,
|
|
2903
|
-
resumeWorkflowStream,
|
|
2904
|
-
timeTravelWorkflowStream
|
|
2905
|
-
};
|
|
2906
|
-
}
|
|
2907
|
-
|
|
2908
|
-
// src/workflows/hooks.ts
|
|
2909
|
-
function useCreateWorkflowRun() {
|
|
2910
|
-
const client = useMastraClient();
|
|
2911
|
-
return useMutation(async ({ workflowId, prevRunId }) => {
|
|
2912
|
-
try {
|
|
2913
|
-
const workflow = client.getWorkflow(workflowId);
|
|
2914
|
-
const { runId: newRunId } = await workflow.createRun({ runId: prevRunId });
|
|
2915
|
-
return { runId: newRunId };
|
|
2916
|
-
} catch (error) {
|
|
2917
|
-
console.error("Error creating workflow run:", error);
|
|
2918
|
-
throw error;
|
|
2919
|
-
}
|
|
2920
|
-
});
|
|
2921
|
-
}
|
|
2922
|
-
function useCancelWorkflowRun() {
|
|
2923
|
-
const client = useMastraClient();
|
|
2924
|
-
return useMutation(async ({ workflowId, runId }) => {
|
|
2925
|
-
try {
|
|
2926
|
-
const workflow = client.getWorkflow(workflowId);
|
|
2927
|
-
const run = await workflow.createRun({ runId });
|
|
2928
|
-
return run.cancelRun();
|
|
2929
|
-
} catch (error) {
|
|
2930
|
-
console.error("Error canceling workflow run:", error);
|
|
2931
|
-
throw error;
|
|
2932
|
-
}
|
|
2933
|
-
});
|
|
2934
|
-
}
|
|
2935
|
-
|
|
2936
|
-
export { AgentIcon, CodeBlock, CodeBlockClass, CodeCopyButton, Entity, EntityCaret, EntityContent, EntityContentClass, EntityTrigger, EntityTriggerClass, EntityTriggerVariantClasses, Entry, EntryClass, EntryTitle, EntryTitleClass, Icon, IconButton, IconButtonClass, IconSizes, MastraReactProvider, Message, MessageActions, MessageActionsClass, MessageClass, MessageContent, MessageContentClass, MessageList, MessageListClass, MessageStreaming, MessageStreamingClass, MessageUsage, MessageUsageClass, MessageUsageEntry, MessageUsageEntryClass, MessageUsageValue, MessageUsageValueClass, MessageUsages, MessageUsagesClass, ToolApproval, ToolApprovalActions, ToolApprovalActionsClass, ToolApprovalClass, ToolApprovalContent, ToolApprovalContentClass, ToolApprovalHeader, ToolApprovalHeaderClass, ToolApprovalTitle, ToolApprovalTitleClass, ToolsIcon, Tooltip, TooltipContent, TooltipContentClass, TooltipTrigger, WorkflowIcon, mapWorkflowStreamChunkToWatchResult, resolveToChildMessages, toAssistantUIMessage, toUIMessage, useCancelWorkflowRun, useChat, useCreateWorkflowRun, useEntity, useMastraClient, useStreamWorkflow };
|
|
2937
|
-
//# sourceMappingURL=index.js.map
|
|
2938
41
|
//# sourceMappingURL=index.js.map
|