@mastra/core 1.2.0 → 1.2.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/_types/@internal_ai-sdk-v4/dist/index.d.ts +30 -17
- package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +10 -7
- package/dist/agent/index.cjs +13 -13
- package/dist/agent/index.js +2 -2
- package/dist/agent/message-list/index.cjs +18 -18
- package/dist/agent/message-list/index.js +1 -1
- package/dist/{chunk-VBOO4F4D.cjs → chunk-2DMSFLJY.cjs} +5 -5
- package/dist/{chunk-VBOO4F4D.cjs.map → chunk-2DMSFLJY.cjs.map} +1 -1
- package/dist/{chunk-ARQG4ZSD.cjs → chunk-5SOS47PH.cjs} +37 -37
- package/dist/chunk-5SOS47PH.cjs.map +1 -0
- package/dist/{chunk-NRMSZFAU.js → chunk-5YVR7B4R.js} +5 -5
- package/dist/{chunk-NRMSZFAU.js.map → chunk-5YVR7B4R.js.map} +1 -1
- package/dist/{chunk-G5NRZOPO.cjs → chunk-7MDVYPWX.cjs} +4 -4
- package/dist/{chunk-G5NRZOPO.cjs.map → chunk-7MDVYPWX.cjs.map} +1 -1
- package/dist/{chunk-AP3Z4EAP.cjs → chunk-A5QFWX67.cjs} +53 -53
- package/dist/{chunk-AP3Z4EAP.cjs.map → chunk-A5QFWX67.cjs.map} +1 -1
- package/dist/{chunk-4XLGMCCQ.js → chunk-AUF6U2BL.js} +3 -3
- package/dist/{chunk-4XLGMCCQ.js.map → chunk-AUF6U2BL.js.map} +1 -1
- package/dist/{chunk-POKH6N2J.cjs → chunk-AXN5P2GE.cjs} +4 -4
- package/dist/{chunk-POKH6N2J.cjs.map → chunk-AXN5P2GE.cjs.map} +1 -1
- package/dist/{chunk-YL6ETQ5I.cjs → chunk-B4M33FCS.cjs} +9 -9
- package/dist/{chunk-YL6ETQ5I.cjs.map → chunk-B4M33FCS.cjs.map} +1 -1
- package/dist/{chunk-DG6C6ZTL.cjs → chunk-CC3OOESY.cjs} +44 -43
- package/dist/chunk-CC3OOESY.cjs.map +1 -0
- package/dist/{chunk-NYC6PYZF.js → chunk-E3VFKTIA.js} +36 -4
- package/dist/chunk-E3VFKTIA.js.map +1 -0
- package/dist/{chunk-3LRUJTH3.cjs → chunk-GVLPTDJA.cjs} +50 -13
- package/dist/chunk-GVLPTDJA.cjs.map +1 -0
- package/dist/{chunk-SS4AZHZW.cjs → chunk-HU2ONA2W.cjs} +9 -9
- package/dist/{chunk-SS4AZHZW.cjs.map → chunk-HU2ONA2W.cjs.map} +1 -1
- package/dist/chunk-HVG7MWNT.js +439 -0
- package/dist/chunk-HVG7MWNT.js.map +1 -0
- package/dist/chunk-JCEP2VPF.cjs +441 -0
- package/dist/chunk-JCEP2VPF.cjs.map +1 -0
- package/dist/{chunk-PPAJGWVW.js → chunk-MSWXEOZC.js} +3 -3
- package/dist/{chunk-PPAJGWVW.js.map → chunk-MSWXEOZC.js.map} +1 -1
- package/dist/{chunk-AQHO4OC2.cjs → chunk-QOFI2WBM.cjs} +6 -6
- package/dist/{chunk-AQHO4OC2.cjs.map → chunk-QOFI2WBM.cjs.map} +1 -1
- package/dist/{chunk-EY3WXGUD.js → chunk-RXD5EGQF.js} +43 -6
- package/dist/chunk-RXD5EGQF.js.map +1 -0
- package/dist/{chunk-XC7WIZBL.js → chunk-S6BH5HHY.js} +4 -3
- package/dist/chunk-S6BH5HHY.js.map +1 -0
- package/dist/{chunk-IPXNR6RQ.js → chunk-V2MLGA7T.js} +1884 -998
- package/dist/chunk-V2MLGA7T.js.map +1 -0
- package/dist/{chunk-Z4PGSIZ5.cjs → chunk-VTE2OBKS.cjs} +1890 -1004
- package/dist/chunk-VTE2OBKS.cjs.map +1 -0
- package/dist/{chunk-ZODRDMZ7.js → chunk-VX7UA3SO.js} +3 -3
- package/dist/{chunk-ZODRDMZ7.js.map → chunk-VX7UA3SO.js.map} +1 -1
- package/dist/{chunk-5HDIPOLV.js → chunk-WFUNLRQX.js} +6 -6
- package/dist/chunk-WFUNLRQX.js.map +1 -0
- package/dist/{chunk-V3LENMEW.js → chunk-X5ORARLG.js} +4 -4
- package/dist/{chunk-V3LENMEW.js.map → chunk-X5ORARLG.js.map} +1 -1
- package/dist/{chunk-Z2OKCLGV.cjs → chunk-XCPEEIHI.cjs} +41 -8
- package/dist/chunk-XCPEEIHI.cjs.map +1 -0
- package/dist/{chunk-57O4TPB3.js → chunk-Z6NRYYOH.js} +3 -3
- package/dist/{chunk-57O4TPB3.js.map → chunk-Z6NRYYOH.js.map} +1 -1
- package/dist/{chunk-RUMXBL6P.js → chunk-ZWM2CAIM.js} +5 -5
- package/dist/{chunk-RUMXBL6P.js.map → chunk-ZWM2CAIM.js.map} +1 -1
- package/dist/docs/SKILL.md +270 -64
- package/dist/docs/{SOURCE_MAP.json → assets/SOURCE_MAP.json} +156 -152
- package/dist/docs/{agents/10-adding-voice.md → references/docs-agents-adding-voice.md} +6 -5
- package/dist/docs/{agents/08-agent-approval.md → references/docs-agents-agent-approval.md} +19 -19
- package/dist/docs/{agents/03-agent-memory.md → references/docs-agents-agent-memory.md} +57 -55
- package/dist/docs/{agents/07-guardrails.md → references/docs-agents-guardrails.md} +21 -39
- package/dist/docs/{agents/09-network-approval.md → references/docs-agents-network-approval.md} +12 -11
- package/dist/docs/{agents/05-networks.md → references/docs-agents-networks.md} +7 -9
- package/dist/docs/{agents/01-overview.md → references/docs-agents-overview.md} +54 -72
- package/dist/docs/{agents/06-processors.md → references/docs-agents-processors.md} +29 -24
- package/dist/docs/{agents/04-structured-output.md → references/docs-agents-structured-output.md} +13 -22
- package/dist/docs/{agents/02-using-tools.md → references/docs-agents-using-tools.md} +12 -13
- package/dist/docs/{evals/02-custom-scorers.md → references/docs-evals-custom-scorers.md} +5 -7
- package/dist/docs/{evals/01-overview.md → references/docs-evals-overview.md} +26 -17
- package/dist/docs/{evals/03-running-in-ci.md → references/docs-evals-running-in-ci.md} +2 -4
- package/dist/docs/{mcp/01-overview.md → references/docs-mcp-overview.md} +135 -140
- package/dist/docs/references/docs-mcp-publishing-mcp-server.md +95 -0
- package/dist/docs/{memory/05-memory-processors.md → references/docs-memory-memory-processors.md} +6 -8
- package/dist/docs/references/docs-memory-observational-memory.md +166 -0
- package/dist/docs/{memory/01-overview.md → references/docs-memory-overview.md} +8 -8
- package/dist/docs/{memory/04-semantic-recall.md → references/docs-memory-semantic-recall.md} +33 -17
- package/dist/docs/{memory/02-storage.md → references/docs-memory-storage.md} +29 -39
- package/dist/docs/{memory/03-working-memory.md → references/docs-memory-working-memory.md} +16 -27
- package/dist/docs/{observability/02-logging.md → references/docs-observability-logging.md} +6 -10
- package/dist/docs/{observability/01-overview.md → references/docs-observability-overview.md} +4 -10
- package/dist/docs/{observability/04-otel.md → references/docs-observability-tracing-bridges-otel.md} +31 -14
- package/dist/docs/{observability/07-arize.md → references/docs-observability-tracing-exporters-arize.md} +38 -22
- package/dist/docs/{observability/08-braintrust.md → references/docs-observability-tracing-exporters-braintrust.md} +24 -6
- package/dist/docs/{observability/06-cloud.md → references/docs-observability-tracing-exporters-cloud.md} +7 -7
- package/dist/docs/{observability/09-datadog.md → references/docs-observability-tracing-exporters-datadog.md} +26 -8
- package/dist/docs/{observability/05-default.md → references/docs-observability-tracing-exporters-default.md} +11 -14
- package/dist/docs/{observability/10-laminar.md → references/docs-observability-tracing-exporters-laminar.md} +24 -6
- package/dist/docs/{observability/11-langfuse.md → references/docs-observability-tracing-exporters-langfuse.md} +31 -12
- package/dist/docs/{observability/12-langsmith.md → references/docs-observability-tracing-exporters-langsmith.md} +29 -11
- package/dist/docs/{observability/13-otel.md → references/docs-observability-tracing-exporters-otel.md} +107 -63
- package/dist/docs/{observability/14-posthog.md → references/docs-observability-tracing-exporters-posthog.md} +24 -6
- package/dist/docs/{observability/03-overview.md → references/docs-observability-tracing-overview.md} +45 -53
- package/dist/docs/{rag/02-chunking-and-embedding.md → references/docs-rag-chunking-and-embedding.md} +5 -11
- package/dist/docs/{rag/05-graph-rag.md → references/docs-rag-graph-rag.md} +0 -2
- package/dist/docs/{rag/01-overview.md → references/docs-rag-overview.md} +2 -7
- package/dist/docs/{rag/04-retrieval.md → references/docs-rag-retrieval.md} +26 -53
- package/dist/docs/{rag/03-vector-databases.md → references/docs-rag-vector-databases.md} +198 -202
- package/dist/docs/{server/13-auth0.md → references/docs-server-auth-auth0.md} +68 -79
- package/dist/docs/{server/09-clerk.md → references/docs-server-auth-clerk.md} +41 -52
- package/dist/docs/{server/14-composite-auth.md → references/docs-server-auth-composite-auth.md} +1 -3
- package/dist/docs/{server/15-custom-auth-provider.md → references/docs-server-auth-custom-auth-provider.md} +13 -15
- package/dist/docs/{server/11-firebase.md → references/docs-server-auth-firebase.md} +83 -97
- package/dist/docs/{server/08-jwt.md → references/docs-server-auth-jwt.md} +46 -35
- package/dist/docs/{server/07-simple-auth.md → references/docs-server-auth-simple-auth.md} +10 -11
- package/dist/docs/{server/10-supabase.md → references/docs-server-auth-supabase.md} +33 -44
- package/dist/docs/{server/12-workos.md → references/docs-server-auth-workos.md} +45 -56
- package/dist/docs/{server/02-custom-adapters.md → references/docs-server-custom-adapters.md} +25 -31
- package/dist/docs/{server/05-custom-api-routes.md → references/docs-server-custom-api-routes.md} +7 -7
- package/dist/docs/{server/06-mastra-client.md → references/docs-server-mastra-client.md} +32 -20
- package/dist/docs/{server/01-mastra-server.md → references/docs-server-mastra-server.md} +5 -11
- package/dist/docs/{server/03-middleware.md → references/docs-server-middleware.md} +8 -15
- package/dist/docs/{server/04-request-context.md → references/docs-server-request-context.md} +29 -43
- package/dist/docs/{streaming/01-events.md → references/docs-streaming-events.md} +9 -16
- package/dist/docs/{streaming/02-tool-streaming.md → references/docs-streaming-tool-streaming.md} +6 -11
- package/dist/docs/{streaming/03-workflow-streaming.md → references/docs-streaming-workflow-streaming.md} +2 -6
- package/dist/docs/{tools-mcp/03-advanced-usage.md → references/docs-tools-mcp-advanced-usage.md} +23 -5
- package/dist/docs/{tools-mcp/01-mcp-overview.md → references/docs-tools-mcp-mcp-overview.md} +141 -146
- package/dist/docs/{tools-mcp/02-overview.md → references/docs-tools-mcp-overview.md} +4 -12
- package/dist/docs/{voice/01-overview.md → references/docs-voice-overview.md} +37 -81
- package/dist/docs/{voice/04-speech-to-speech.md → references/docs-voice-speech-to-speech.md} +1 -4
- package/dist/docs/{voice/03-speech-to-text.md → references/docs-voice-speech-to-text.md} +8 -11
- package/dist/docs/{voice/02-text-to-speech.md → references/docs-voice-text-to-speech.md} +12 -15
- package/dist/docs/{workflows/04-agents-and-tools.md → references/docs-workflows-agents-and-tools.md} +11 -21
- package/dist/docs/{workflows/03-control-flow.md → references/docs-workflows-control-flow.md} +58 -56
- package/dist/docs/{workflows/09-error-handling.md → references/docs-workflows-error-handling.md} +13 -15
- package/dist/docs/{workflows/07-human-in-the-loop.md → references/docs-workflows-human-in-the-loop.md} +11 -12
- package/dist/docs/{workflows/10-input-data-mapping.md → references/docs-workflows-input-data-mapping.md} +12 -14
- package/dist/docs/{workflows/01-overview.md → references/docs-workflows-overview.md} +31 -52
- package/dist/docs/{workflows/05-snapshots.md → references/docs-workflows-snapshots.md} +3 -5
- package/dist/docs/{workflows/06-suspend-and-resume.md → references/docs-workflows-suspend-and-resume.md} +12 -12
- package/dist/docs/{workflows/08-time-travel.md → references/docs-workflows-time-travel.md} +2 -5
- package/dist/docs/{workflows/02-workflow-state.md → references/docs-workflows-workflow-state.md} +4 -6
- package/dist/docs/{workspace/02-filesystem.md → references/docs-workspace-filesystem.md} +3 -8
- package/dist/docs/{workspace/01-overview.md → references/docs-workspace-overview.md} +10 -16
- package/dist/docs/{workspace/03-sandbox.md → references/docs-workspace-sandbox.md} +2 -4
- package/dist/docs/{workspace/05-search.md → references/docs-workspace-search.md} +20 -22
- package/dist/docs/{workspace/04-skills.md → references/docs-workspace-skills.md} +6 -9
- package/dist/docs/{guides/01-ai-sdk.md → references/guides-agent-frameworks-ai-sdk.md} +25 -9
- package/dist/docs/references/reference-agents-agent.md +142 -0
- package/dist/docs/references/reference-agents-generate.md +174 -0
- package/dist/docs/references/reference-agents-generateLegacy.md +176 -0
- package/dist/docs/references/reference-agents-getDefaultGenerateOptions.md +36 -0
- package/dist/docs/references/reference-agents-getDefaultOptions.md +34 -0
- package/dist/docs/references/reference-agents-getDefaultStreamOptions.md +36 -0
- package/dist/docs/references/reference-agents-getDescription.md +21 -0
- package/dist/docs/references/reference-agents-getInstructions.md +34 -0
- package/dist/docs/references/reference-agents-getLLM.md +37 -0
- package/dist/docs/references/reference-agents-getMemory.md +34 -0
- package/dist/docs/references/reference-agents-getModel.md +34 -0
- package/dist/docs/references/reference-agents-getTools.md +34 -0
- package/dist/docs/references/reference-agents-getVoice.md +34 -0
- package/dist/docs/references/reference-agents-listAgents.md +35 -0
- package/dist/docs/references/reference-agents-listScorers.md +34 -0
- package/dist/docs/references/reference-agents-listTools.md +34 -0
- package/dist/docs/references/reference-agents-listWorkflows.md +34 -0
- package/dist/docs/references/reference-agents-network.md +136 -0
- package/dist/docs/references/reference-ai-sdk-chat-route.md +82 -0
- package/dist/docs/references/reference-ai-sdk-network-route.md +74 -0
- package/dist/docs/references/reference-ai-sdk-to-ai-sdk-stream.md +232 -0
- package/dist/docs/references/reference-ai-sdk-with-mastra.md +59 -0
- package/dist/docs/references/reference-ai-sdk-workflow-route.md +79 -0
- package/dist/docs/references/reference-auth-auth0.md +73 -0
- package/dist/docs/references/reference-auth-clerk.md +36 -0
- package/dist/docs/references/reference-auth-firebase.md +80 -0
- package/dist/docs/references/reference-auth-jwt.md +26 -0
- package/dist/docs/references/reference-auth-supabase.md +33 -0
- package/dist/docs/references/reference-auth-workos.md +84 -0
- package/dist/docs/{cli/01-reference.md → references/reference-cli-mastra.md} +14 -28
- package/dist/docs/{client-js/01-reference.md → references/reference-client-js-agents.md} +3 -12
- package/dist/docs/{configuration.mdx/01-reference.md → references/reference-configuration.md} +71 -91
- package/dist/docs/references/reference-core-addGateway.md +42 -0
- package/dist/docs/references/reference-core-getAgent.md +21 -0
- package/dist/docs/references/reference-core-getAgentById.md +21 -0
- package/dist/docs/references/reference-core-getDeployer.md +22 -0
- package/dist/docs/references/reference-core-getGateway.md +38 -0
- package/dist/docs/references/reference-core-getGatewayById.md +41 -0
- package/dist/docs/references/reference-core-getLogger.md +22 -0
- package/dist/docs/references/reference-core-getMCPServer.md +45 -0
- package/dist/docs/references/reference-core-getMCPServerById.md +53 -0
- package/dist/docs/references/reference-core-getMemory.md +50 -0
- package/dist/docs/references/reference-core-getScorer.md +54 -0
- package/dist/docs/references/reference-core-getScorerById.md +54 -0
- package/dist/docs/references/reference-core-getServer.md +22 -0
- package/dist/docs/references/reference-core-getStorage.md +22 -0
- package/dist/docs/references/reference-core-getStoredAgentById.md +89 -0
- package/dist/docs/references/reference-core-getTelemetry.md +22 -0
- package/dist/docs/references/reference-core-getVector.md +22 -0
- package/dist/docs/references/reference-core-getWorkflow.md +40 -0
- package/dist/docs/references/reference-core-listAgents.md +21 -0
- package/dist/docs/references/reference-core-listGateways.md +40 -0
- package/dist/docs/references/reference-core-listLogs.md +38 -0
- package/dist/docs/references/reference-core-listLogsByRunId.md +36 -0
- package/dist/docs/references/reference-core-listMCPServers.md +51 -0
- package/dist/docs/references/reference-core-listMemory.md +56 -0
- package/dist/docs/references/reference-core-listScorers.md +29 -0
- package/dist/docs/references/reference-core-listStoredAgents.md +93 -0
- package/dist/docs/references/reference-core-listVectors.md +22 -0
- package/dist/docs/references/reference-core-listWorkflows.md +21 -0
- package/dist/docs/references/reference-core-mastra-class.md +66 -0
- package/dist/docs/references/reference-core-mastra-model-gateway.md +153 -0
- package/dist/docs/references/reference-core-setLogger.md +26 -0
- package/dist/docs/references/reference-core-setStorage.md +27 -0
- package/dist/docs/references/reference-deployer-cloudflare.md +56 -0
- package/dist/docs/references/reference-deployer-netlify.md +14 -0
- package/dist/docs/references/reference-deployer-vercel.md +39 -0
- package/dist/docs/references/reference-evals-answer-relevancy.md +105 -0
- package/dist/docs/references/reference-evals-answer-similarity.md +99 -0
- package/dist/docs/references/reference-evals-bias.md +120 -0
- package/dist/docs/references/reference-evals-completeness.md +137 -0
- package/dist/docs/references/reference-evals-content-similarity.md +101 -0
- package/dist/docs/references/reference-evals-context-precision.md +196 -0
- package/dist/docs/references/reference-evals-create-scorer.md +270 -0
- package/dist/docs/references/reference-evals-faithfulness.md +114 -0
- package/dist/docs/references/reference-evals-hallucination.md +220 -0
- package/dist/docs/references/reference-evals-keyword-coverage.md +128 -0
- package/dist/docs/references/reference-evals-mastra-scorer.md +123 -0
- package/dist/docs/references/reference-evals-run-evals.md +138 -0
- package/dist/docs/references/reference-evals-scorer-utils.md +330 -0
- package/dist/docs/references/reference-evals-textual-difference.md +113 -0
- package/dist/docs/references/reference-evals-tone-consistency.md +119 -0
- package/dist/docs/references/reference-evals-toxicity.md +123 -0
- package/dist/docs/{logging/01-reference.md → references/reference-logging-pino-logger.md} +16 -15
- package/dist/docs/references/reference-memory-deleteMessages.md +40 -0
- package/dist/docs/{memory/06-reference.md → references/reference-memory-memory-class.md} +28 -55
- package/dist/docs/references/reference-memory-observational-memory.md +217 -0
- package/dist/docs/references/reference-observability-tracing-bridges-otel.md +131 -0
- package/dist/docs/references/reference-observability-tracing-configuration.md +178 -0
- package/dist/docs/references/reference-observability-tracing-exporters-console-exporter.md +138 -0
- package/dist/docs/references/reference-observability-tracing-exporters-datadog.md +116 -0
- package/dist/docs/references/reference-observability-tracing-instances.md +109 -0
- package/dist/docs/references/reference-observability-tracing-interfaces.md +749 -0
- package/dist/docs/references/reference-observability-tracing-processors-sensitive-data-filter.md +144 -0
- package/dist/docs/references/reference-observability-tracing-spans.md +224 -0
- package/dist/docs/references/reference-processors-batch-parts-processor.md +61 -0
- package/dist/docs/references/reference-processors-language-detector.md +81 -0
- package/dist/docs/references/reference-processors-message-history-processor.md +85 -0
- package/dist/docs/references/reference-processors-moderation-processor.md +104 -0
- package/dist/docs/references/reference-processors-pii-detector.md +107 -0
- package/dist/docs/references/reference-processors-processor-interface.md +521 -0
- package/dist/docs/references/reference-processors-prompt-injection-detector.md +71 -0
- package/dist/docs/references/reference-processors-semantic-recall-processor.md +123 -0
- package/dist/docs/references/reference-processors-system-prompt-scrubber.md +80 -0
- package/dist/docs/references/reference-processors-token-limiter-processor.md +113 -0
- package/dist/docs/references/reference-processors-tool-call-filter.md +85 -0
- package/dist/docs/references/reference-processors-tool-search-processor.md +113 -0
- package/dist/docs/references/reference-processors-unicode-normalizer.md +62 -0
- package/dist/docs/references/reference-processors-working-memory-processor.md +154 -0
- package/dist/docs/references/reference-rag-database-config.md +264 -0
- package/dist/docs/references/reference-rag-embeddings.md +92 -0
- package/dist/docs/references/reference-server-mastra-server.md +298 -0
- package/dist/docs/references/reference-server-register-api-route.md +249 -0
- package/dist/docs/references/reference-storage-cloudflare-d1.md +218 -0
- package/dist/docs/references/reference-storage-composite.md +235 -0
- package/dist/docs/references/reference-storage-lance.md +131 -0
- package/dist/docs/references/reference-storage-libsql.md +135 -0
- package/dist/docs/references/reference-storage-mongodb.md +262 -0
- package/dist/docs/references/reference-storage-mssql.md +155 -0
- package/dist/docs/references/reference-storage-overview.md +121 -0
- package/dist/docs/references/reference-storage-postgresql.md +529 -0
- package/dist/docs/references/reference-storage-upstash.md +160 -0
- package/dist/docs/references/reference-streaming-ChunkType.md +292 -0
- package/dist/docs/references/reference-streaming-agents-MastraModelOutput.md +182 -0
- package/dist/docs/references/reference-streaming-agents-streamLegacy.md +142 -0
- package/dist/docs/references/reference-streaming-workflows-observeStream.md +42 -0
- package/dist/docs/references/reference-streaming-workflows-resumeStream.md +61 -0
- package/dist/docs/references/reference-streaming-workflows-stream.md +87 -0
- package/dist/docs/references/reference-streaming-workflows-timeTravelStream.md +142 -0
- package/dist/docs/{templates/01-reference.md → references/reference-templates-overview.md} +8 -17
- package/dist/docs/references/reference-tools-client.md +228 -0
- package/dist/docs/references/reference-tools-create-tool.md +237 -0
- package/dist/docs/references/reference-tools-graph-rag-tool.md +185 -0
- package/dist/docs/references/reference-tools-mcp-client.md +964 -0
- package/dist/docs/references/reference-tools-mcp-server.md +1275 -0
- package/dist/docs/references/reference-tools-vector-query-tool.md +459 -0
- package/dist/docs/references/reference-vectors-libsql.md +305 -0
- package/dist/docs/references/reference-vectors-mongodb.md +295 -0
- package/dist/docs/references/reference-vectors-pg.md +408 -0
- package/dist/docs/references/reference-vectors-upstash.md +294 -0
- package/dist/docs/references/reference-voice-composite-voice.md +121 -0
- package/dist/docs/references/reference-voice-mastra-voice.md +313 -0
- package/dist/docs/references/reference-voice-voice.addInstructions.md +56 -0
- package/dist/docs/references/reference-voice-voice.addTools.md +67 -0
- package/dist/docs/references/reference-voice-voice.connect.md +94 -0
- package/dist/docs/references/reference-voice-voice.events.md +37 -0
- package/dist/docs/references/reference-voice-voice.listen.md +164 -0
- package/dist/docs/references/reference-voice-voice.on.md +111 -0
- package/dist/docs/references/reference-voice-voice.speak.md +157 -0
- package/dist/docs/references/reference-workflows-run-methods-cancel.md +86 -0
- package/dist/docs/references/reference-workflows-run-methods-restart.md +33 -0
- package/dist/docs/references/reference-workflows-run-methods-resume.md +59 -0
- package/dist/docs/references/reference-workflows-run-methods-start.md +58 -0
- package/dist/docs/references/reference-workflows-run-methods-startAsync.md +67 -0
- package/dist/docs/references/reference-workflows-run-methods-timeTravel.md +142 -0
- package/dist/docs/references/reference-workflows-run.md +59 -0
- package/dist/docs/references/reference-workflows-step.md +117 -0
- package/dist/docs/references/reference-workflows-workflow-methods-branch.md +25 -0
- package/dist/docs/references/reference-workflows-workflow-methods-commit.md +17 -0
- package/dist/docs/references/reference-workflows-workflow-methods-create-run.md +63 -0
- package/dist/docs/references/reference-workflows-workflow-methods-dountil.md +25 -0
- package/dist/docs/references/reference-workflows-workflow-methods-dowhile.md +25 -0
- package/dist/docs/references/reference-workflows-workflow-methods-foreach.md +88 -0
- package/dist/docs/references/reference-workflows-workflow-methods-map.md +93 -0
- package/dist/docs/references/reference-workflows-workflow-methods-parallel.md +21 -0
- package/dist/docs/references/reference-workflows-workflow-methods-sleep.md +35 -0
- package/dist/docs/references/reference-workflows-workflow-methods-sleepUntil.md +35 -0
- package/dist/docs/references/reference-workflows-workflow-methods-then.md +21 -0
- package/dist/docs/references/reference-workflows-workflow.md +157 -0
- package/dist/docs/references/reference-workspace-filesystem.md +200 -0
- package/dist/docs/references/reference-workspace-local-filesystem.md +300 -0
- package/dist/docs/references/reference-workspace-local-sandbox.md +283 -0
- package/dist/docs/references/reference-workspace-sandbox.md +79 -0
- package/dist/docs/references/reference-workspace-workspace-class.md +247 -0
- package/dist/docs/references/reference.md +243 -0
- package/dist/evals/index.cjs +5 -5
- package/dist/evals/index.js +2 -2
- package/dist/evals/scoreTraces/index.cjs +3 -3
- package/dist/evals/scoreTraces/index.js +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.js +2 -2
- package/dist/llm/index.cjs +9 -5
- package/dist/llm/index.d.ts +1 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +1 -1
- package/dist/llm/model/index.d.ts +1 -1
- package/dist/llm/model/index.d.ts.map +1 -1
- package/dist/loop/index.cjs +12 -12
- package/dist/loop/index.js +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.ts +17 -0
- package/dist/mastra/index.d.ts.map +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +14 -14
- package/dist/memory/index.js +1 -1
- package/dist/memory/types.d.ts +3 -2
- package/dist/memory/types.d.ts.map +1 -1
- package/dist/processors/index.cjs +41 -41
- package/dist/processors/index.js +1 -1
- package/dist/relevance/index.cjs +3 -3
- package/dist/relevance/index.js +1 -1
- package/dist/storage/index.cjs +33 -33
- package/dist/storage/index.js +1 -1
- package/dist/stream/index.cjs +11 -11
- package/dist/stream/index.js +2 -2
- package/dist/test-utils/llm-mock.cjs +12 -12
- package/dist/test-utils/llm-mock.js +3 -3
- package/dist/{token-6GSAFR2W-TOUJCAPY.js → token-APYSY3BW-QJCV2XQG.js} +11 -11
- package/dist/token-APYSY3BW-QJCV2XQG.js.map +1 -0
- package/dist/{token-6GSAFR2W-GERJXNN5.cjs → token-APYSY3BW-UBKUGJQP.cjs} +14 -14
- package/dist/token-APYSY3BW-UBKUGJQP.cjs.map +1 -0
- package/dist/token-util-RMHT2CPJ-S2YMG7N3.js +8 -0
- package/dist/token-util-RMHT2CPJ-S2YMG7N3.js.map +1 -0
- package/dist/token-util-RMHT2CPJ-WV2T74WQ.cjs +10 -0
- package/dist/token-util-RMHT2CPJ-WV2T74WQ.cjs.map +1 -0
- package/dist/tool-loop-agent/index.cjs +4 -4
- package/dist/tool-loop-agent/index.js +1 -1
- package/dist/vector/index.cjs +11 -11
- package/dist/vector/index.js +3 -3
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/index.cjs +25 -25
- package/dist/workflows/index.js +1 -1
- package/package.json +4 -5
- package/dist/chunk-3LRUJTH3.cjs.map +0 -1
- package/dist/chunk-5HDIPOLV.js.map +0 -1
- package/dist/chunk-ARQG4ZSD.cjs.map +0 -1
- package/dist/chunk-DG6C6ZTL.cjs.map +0 -1
- package/dist/chunk-EY3WXGUD.js.map +0 -1
- package/dist/chunk-IPXNR6RQ.js.map +0 -1
- package/dist/chunk-NYC6PYZF.js.map +0 -1
- package/dist/chunk-X5HU5YVN.js +0 -250
- package/dist/chunk-X5HU5YVN.js.map +0 -1
- package/dist/chunk-XC7WIZBL.js.map +0 -1
- package/dist/chunk-Z2OKCLGV.cjs.map +0 -1
- package/dist/chunk-Z4PGSIZ5.cjs.map +0 -1
- package/dist/chunk-ZZF2IKZJ.cjs +0 -252
- package/dist/chunk-ZZF2IKZJ.cjs.map +0 -1
- package/dist/docs/README.md +0 -57
- package/dist/docs/agents/11-reference.md +0 -854
- package/dist/docs/ai-sdk/01-reference.md +0 -490
- package/dist/docs/auth/01-reference.md +0 -308
- package/dist/docs/core/01-reference.md +0 -1283
- package/dist/docs/deployer/01-reference.md +0 -128
- package/dist/docs/evals/04-reference.md +0 -2137
- package/dist/docs/index.mdx/01-reference.md +0 -14
- package/dist/docs/mcp/02-publishing-mcp-server.md +0 -111
- package/dist/docs/observability/15-reference.md +0 -1831
- package/dist/docs/processors/01-reference.md +0 -1418
- package/dist/docs/rag/06-reference.md +0 -342
- package/dist/docs/server/16-reference.md +0 -513
- package/dist/docs/storage/01-reference.md +0 -2022
- package/dist/docs/streaming/04-reference.md +0 -724
- package/dist/docs/tools/01-reference.md +0 -3136
- package/dist/docs/vectors/01-reference.md +0 -942
- package/dist/docs/voice/05-reference.md +0 -1043
- package/dist/docs/workflows/11-reference.md +0 -1044
- package/dist/docs/workspace/06-reference.md +0 -946
- package/dist/token-6GSAFR2W-GERJXNN5.cjs.map +0 -1
- package/dist/token-6GSAFR2W-TOUJCAPY.js.map +0 -1
- package/dist/token-util-NEHG7TUY-R2XAU2MF.cjs +0 -10
- package/dist/token-util-NEHG7TUY-R2XAU2MF.cjs.map +0 -1
- package/dist/token-util-NEHG7TUY-TZ426VZB.js +0 -8
- package/dist/token-util-NEHG7TUY-TZ426VZB.js.map +0 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkAXN5P2GE_cjs = require('./chunk-AXN5P2GE.cjs');
|
|
4
4
|
var z4 = require('zod/v4');
|
|
5
5
|
var v3 = require('zod/v3');
|
|
6
|
+
var zod = require('zod');
|
|
6
7
|
|
|
7
8
|
function _interopNamespace(e) {
|
|
8
9
|
if (e && e.__esModule) return e;
|
|
@@ -38,13 +39,13 @@ var AISDKError = class _AISDKError extends (_b = Error, _a = symbol, _b) {
|
|
|
38
39
|
* @param {unknown} [params.cause] - The underlying cause of the error.
|
|
39
40
|
*/
|
|
40
41
|
constructor({
|
|
41
|
-
name:
|
|
42
|
+
name: name1422,
|
|
42
43
|
message,
|
|
43
44
|
cause
|
|
44
45
|
}) {
|
|
45
46
|
super(message);
|
|
46
47
|
this[_a] = true;
|
|
47
|
-
this.name =
|
|
48
|
+
this.name = name1422;
|
|
48
49
|
this.cause = cause;
|
|
49
50
|
}
|
|
50
51
|
/**
|
|
@@ -55,8 +56,8 @@ var AISDKError = class _AISDKError extends (_b = Error, _a = symbol, _b) {
|
|
|
55
56
|
static isInstance(error) {
|
|
56
57
|
return _AISDKError.hasMarker(error, marker);
|
|
57
58
|
}
|
|
58
|
-
static hasMarker(error,
|
|
59
|
-
const markerSymbol = Symbol.for(
|
|
59
|
+
static hasMarker(error, marker1522) {
|
|
60
|
+
const markerSymbol = Symbol.for(marker1522);
|
|
60
61
|
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
61
62
|
}
|
|
62
63
|
};
|
|
@@ -186,34 +187,79 @@ var symbol13 = Symbol.for(marker13);
|
|
|
186
187
|
var _a13;
|
|
187
188
|
var _b13;
|
|
188
189
|
var TypeValidationError = class _TypeValidationError extends (_b13 = AISDKError, _a13 = symbol13, _b13) {
|
|
189
|
-
constructor({
|
|
190
|
+
constructor({
|
|
191
|
+
value,
|
|
192
|
+
cause,
|
|
193
|
+
context: context2
|
|
194
|
+
}) {
|
|
195
|
+
let contextPrefix = "Type validation failed";
|
|
196
|
+
if (context2 == null ? void 0 : context2.field) {
|
|
197
|
+
contextPrefix += ` for ${context2.field}`;
|
|
198
|
+
}
|
|
199
|
+
if ((context2 == null ? void 0 : context2.entityName) || (context2 == null ? void 0 : context2.entityId)) {
|
|
200
|
+
contextPrefix += " (";
|
|
201
|
+
const parts = [];
|
|
202
|
+
if (context2.entityName) {
|
|
203
|
+
parts.push(context2.entityName);
|
|
204
|
+
}
|
|
205
|
+
if (context2.entityId) {
|
|
206
|
+
parts.push(`id: "${context2.entityId}"`);
|
|
207
|
+
}
|
|
208
|
+
contextPrefix += parts.join(", ");
|
|
209
|
+
contextPrefix += ")";
|
|
210
|
+
}
|
|
190
211
|
super({
|
|
191
212
|
name: name12,
|
|
192
|
-
message:
|
|
213
|
+
message: `${contextPrefix}: Value: ${JSON.stringify(value)}.
|
|
193
214
|
Error message: ${getErrorMessage(cause)}`,
|
|
194
215
|
cause
|
|
195
216
|
});
|
|
196
217
|
this[_a13] = true;
|
|
197
218
|
this.value = value;
|
|
219
|
+
this.context = context2;
|
|
198
220
|
}
|
|
199
221
|
static isInstance(error) {
|
|
200
222
|
return AISDKError.hasMarker(error, marker13);
|
|
201
223
|
}
|
|
202
224
|
/**
|
|
203
225
|
* Wraps an error into a TypeValidationError.
|
|
204
|
-
* If the cause is already a TypeValidationError with the same value, it returns the cause.
|
|
226
|
+
* If the cause is already a TypeValidationError with the same value and context, it returns the cause.
|
|
205
227
|
* Otherwise, it creates a new TypeValidationError.
|
|
206
228
|
*
|
|
207
229
|
* @param {Object} params - The parameters for wrapping the error.
|
|
208
230
|
* @param {unknown} params.value - The value that failed validation.
|
|
209
231
|
* @param {unknown} params.cause - The original error or cause of the validation failure.
|
|
232
|
+
* @param {TypeValidationContext} params.context - Optional context about what is being validated.
|
|
210
233
|
* @returns {TypeValidationError} A TypeValidationError instance.
|
|
211
234
|
*/
|
|
212
235
|
static wrap({
|
|
213
236
|
value,
|
|
214
|
-
cause
|
|
237
|
+
cause,
|
|
238
|
+
context: context2
|
|
239
|
+
}) {
|
|
240
|
+
var _a1522, _b152, _c;
|
|
241
|
+
if (_TypeValidationError.isInstance(cause) && cause.value === value && ((_a1522 = cause.context) == null ? void 0 : _a1522.field) === (context2 == null ? void 0 : context2.field) && ((_b152 = cause.context) == null ? void 0 : _b152.entityName) === (context2 == null ? void 0 : context2.entityName) && ((_c = cause.context) == null ? void 0 : _c.entityId) === (context2 == null ? void 0 : context2.entityId)) {
|
|
242
|
+
return cause;
|
|
243
|
+
}
|
|
244
|
+
return new _TypeValidationError({ value, cause, context: context2 });
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
var name13 = "AI_UnsupportedFunctionalityError";
|
|
248
|
+
var marker14 = `vercel.ai.error.${name13}`;
|
|
249
|
+
var symbol14 = Symbol.for(marker14);
|
|
250
|
+
var _a14;
|
|
251
|
+
var _b14;
|
|
252
|
+
var UnsupportedFunctionalityError = class extends (_b14 = AISDKError, _a14 = symbol14, _b14) {
|
|
253
|
+
constructor({
|
|
254
|
+
functionality,
|
|
255
|
+
message = `'${functionality}' functionality not supported.`
|
|
215
256
|
}) {
|
|
216
|
-
|
|
257
|
+
super({ name: name13, message });
|
|
258
|
+
this[_a14] = true;
|
|
259
|
+
this.functionality = functionality;
|
|
260
|
+
}
|
|
261
|
+
static isInstance(error) {
|
|
262
|
+
return AISDKError.hasMarker(error, marker14);
|
|
217
263
|
}
|
|
218
264
|
};
|
|
219
265
|
var ParseError = class extends Error {
|
|
@@ -503,6 +549,25 @@ function isAbortError(error) {
|
|
|
503
549
|
error.name === "TimeoutError");
|
|
504
550
|
}
|
|
505
551
|
var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
|
|
552
|
+
var BUN_ERROR_CODES = [
|
|
553
|
+
"ConnectionRefused",
|
|
554
|
+
"ConnectionClosed",
|
|
555
|
+
"FailedToOpenSocket",
|
|
556
|
+
"ECONNRESET",
|
|
557
|
+
"ECONNREFUSED",
|
|
558
|
+
"ETIMEDOUT",
|
|
559
|
+
"EPIPE"
|
|
560
|
+
];
|
|
561
|
+
function isBunNetworkError(error) {
|
|
562
|
+
if (!(error instanceof Error)) {
|
|
563
|
+
return false;
|
|
564
|
+
}
|
|
565
|
+
const code = error.code;
|
|
566
|
+
if (typeof code === "string" && BUN_ERROR_CODES.includes(code)) {
|
|
567
|
+
return true;
|
|
568
|
+
}
|
|
569
|
+
return false;
|
|
570
|
+
}
|
|
506
571
|
function handleFetchError({
|
|
507
572
|
error,
|
|
508
573
|
url,
|
|
@@ -524,6 +589,15 @@ function handleFetchError({
|
|
|
524
589
|
});
|
|
525
590
|
}
|
|
526
591
|
}
|
|
592
|
+
if (isBunNetworkError(error)) {
|
|
593
|
+
return new APICallError({
|
|
594
|
+
message: `Cannot connect to API: ${error.message}`,
|
|
595
|
+
cause: error,
|
|
596
|
+
url,
|
|
597
|
+
requestBodyValues,
|
|
598
|
+
isRetryable: true
|
|
599
|
+
});
|
|
600
|
+
}
|
|
527
601
|
return error;
|
|
528
602
|
}
|
|
529
603
|
function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
@@ -572,7 +646,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
572
646
|
);
|
|
573
647
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
574
648
|
}
|
|
575
|
-
var VERSION = "4.0.
|
|
649
|
+
var VERSION = "4.0.13";
|
|
576
650
|
var getOriginalFetch = () => globalThis.fetch;
|
|
577
651
|
var getFromApi = async ({
|
|
578
652
|
url,
|
|
@@ -717,30 +791,39 @@ function secureJsonParse(text2) {
|
|
|
717
791
|
}
|
|
718
792
|
}
|
|
719
793
|
function addAdditionalPropertiesToJsonSchema(jsonSchema2) {
|
|
720
|
-
if (jsonSchema2.type === "object") {
|
|
794
|
+
if (jsonSchema2.type === "object" || Array.isArray(jsonSchema2.type) && jsonSchema2.type.includes("object")) {
|
|
721
795
|
jsonSchema2.additionalProperties = false;
|
|
722
|
-
const properties = jsonSchema2
|
|
796
|
+
const { properties } = jsonSchema2;
|
|
723
797
|
if (properties != null) {
|
|
724
|
-
for (const
|
|
725
|
-
properties[
|
|
726
|
-
properties[property]
|
|
727
|
-
);
|
|
798
|
+
for (const key of Object.keys(properties)) {
|
|
799
|
+
properties[key] = visit(properties[key]);
|
|
728
800
|
}
|
|
729
801
|
}
|
|
730
802
|
}
|
|
731
|
-
if (jsonSchema2.
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
803
|
+
if (jsonSchema2.items != null) {
|
|
804
|
+
jsonSchema2.items = Array.isArray(jsonSchema2.items) ? jsonSchema2.items.map(visit) : visit(jsonSchema2.items);
|
|
805
|
+
}
|
|
806
|
+
if (jsonSchema2.anyOf != null) {
|
|
807
|
+
jsonSchema2.anyOf = jsonSchema2.anyOf.map(visit);
|
|
808
|
+
}
|
|
809
|
+
if (jsonSchema2.allOf != null) {
|
|
810
|
+
jsonSchema2.allOf = jsonSchema2.allOf.map(visit);
|
|
811
|
+
}
|
|
812
|
+
if (jsonSchema2.oneOf != null) {
|
|
813
|
+
jsonSchema2.oneOf = jsonSchema2.oneOf.map(visit);
|
|
814
|
+
}
|
|
815
|
+
const { definitions } = jsonSchema2;
|
|
816
|
+
if (definitions != null) {
|
|
817
|
+
for (const key of Object.keys(definitions)) {
|
|
818
|
+
definitions[key] = visit(definitions[key]);
|
|
740
819
|
}
|
|
741
820
|
}
|
|
742
821
|
return jsonSchema2;
|
|
743
822
|
}
|
|
823
|
+
function visit(def) {
|
|
824
|
+
if (typeof def === "boolean") return def;
|
|
825
|
+
return addAdditionalPropertiesToJsonSchema(def);
|
|
826
|
+
}
|
|
744
827
|
var ignoreOverride = /* @__PURE__ */ Symbol(
|
|
745
828
|
"Let zodToJsonSchema decide on which parser to use"
|
|
746
829
|
);
|
|
@@ -1857,9 +1940,11 @@ function asSchema(schema) {
|
|
|
1857
1940
|
}
|
|
1858
1941
|
function standardSchema(standardSchema2) {
|
|
1859
1942
|
return jsonSchema(
|
|
1860
|
-
() =>
|
|
1861
|
-
|
|
1862
|
-
|
|
1943
|
+
() => addAdditionalPropertiesToJsonSchema(
|
|
1944
|
+
standardSchema2["~standard"].jsonSchema.input({
|
|
1945
|
+
target: "draft-07"
|
|
1946
|
+
})
|
|
1947
|
+
),
|
|
1863
1948
|
{
|
|
1864
1949
|
validate: async (value) => {
|
|
1865
1950
|
const result = await standardSchema2["~standard"].validate(value);
|
|
@@ -1922,17 +2007,19 @@ function zodSchema(zodSchema2, options) {
|
|
|
1922
2007
|
}
|
|
1923
2008
|
async function validateTypes({
|
|
1924
2009
|
value,
|
|
1925
|
-
schema
|
|
2010
|
+
schema,
|
|
2011
|
+
context: context2
|
|
1926
2012
|
}) {
|
|
1927
|
-
const result = await safeValidateTypes({ value, schema });
|
|
2013
|
+
const result = await safeValidateTypes({ value, schema, context: context2 });
|
|
1928
2014
|
if (!result.success) {
|
|
1929
|
-
throw TypeValidationError.wrap({ value, cause: result.error });
|
|
2015
|
+
throw TypeValidationError.wrap({ value, cause: result.error, context: context2 });
|
|
1930
2016
|
}
|
|
1931
2017
|
return result.value;
|
|
1932
2018
|
}
|
|
1933
2019
|
async function safeValidateTypes({
|
|
1934
2020
|
value,
|
|
1935
|
-
schema
|
|
2021
|
+
schema,
|
|
2022
|
+
context: context2
|
|
1936
2023
|
}) {
|
|
1937
2024
|
const actualSchema = asSchema(schema);
|
|
1938
2025
|
try {
|
|
@@ -1945,13 +2032,13 @@ async function safeValidateTypes({
|
|
|
1945
2032
|
}
|
|
1946
2033
|
return {
|
|
1947
2034
|
success: false,
|
|
1948
|
-
error: TypeValidationError.wrap({ value, cause: result.error }),
|
|
2035
|
+
error: TypeValidationError.wrap({ value, cause: result.error, context: context2 }),
|
|
1949
2036
|
rawValue: value
|
|
1950
2037
|
};
|
|
1951
2038
|
} catch (error) {
|
|
1952
2039
|
return {
|
|
1953
2040
|
success: false,
|
|
1954
|
-
error: TypeValidationError.wrap({ value, cause: error }),
|
|
2041
|
+
error: TypeValidationError.wrap({ value, cause: error, context: context2 }),
|
|
1955
2042
|
rawValue: value
|
|
1956
2043
|
};
|
|
1957
2044
|
}
|
|
@@ -2099,6 +2186,38 @@ var postToApi = async ({
|
|
|
2099
2186
|
throw handleFetchError({ error, url, requestBodyValues: body.values });
|
|
2100
2187
|
}
|
|
2101
2188
|
};
|
|
2189
|
+
function tool(tool2) {
|
|
2190
|
+
return tool2;
|
|
2191
|
+
}
|
|
2192
|
+
function createProviderToolFactoryWithOutputSchema({
|
|
2193
|
+
id,
|
|
2194
|
+
inputSchema,
|
|
2195
|
+
outputSchema: outputSchema2,
|
|
2196
|
+
supportsDeferredResults
|
|
2197
|
+
}) {
|
|
2198
|
+
return ({
|
|
2199
|
+
execute,
|
|
2200
|
+
needsApproval,
|
|
2201
|
+
toModelOutput,
|
|
2202
|
+
onInputStart,
|
|
2203
|
+
onInputDelta,
|
|
2204
|
+
onInputAvailable,
|
|
2205
|
+
...args
|
|
2206
|
+
}) => tool({
|
|
2207
|
+
type: "provider",
|
|
2208
|
+
id,
|
|
2209
|
+
args,
|
|
2210
|
+
inputSchema,
|
|
2211
|
+
outputSchema: outputSchema2,
|
|
2212
|
+
execute,
|
|
2213
|
+
needsApproval,
|
|
2214
|
+
toModelOutput,
|
|
2215
|
+
onInputStart,
|
|
2216
|
+
onInputDelta,
|
|
2217
|
+
onInputAvailable,
|
|
2218
|
+
supportsDeferredResults
|
|
2219
|
+
});
|
|
2220
|
+
}
|
|
2102
2221
|
async function resolve(value) {
|
|
2103
2222
|
if (typeof value === "function") {
|
|
2104
2223
|
value = value();
|
|
@@ -2219,15 +2338,15 @@ async function* executeTool({
|
|
|
2219
2338
|
yield { type: "final", output: await result };
|
|
2220
2339
|
}
|
|
2221
2340
|
}
|
|
2222
|
-
var require_get_context =
|
|
2223
|
-
"../../../node_modules/.pnpm/@vercel+oidc@3.0
|
|
2341
|
+
var require_get_context = chunkAXN5P2GE_cjs.__commonJS({
|
|
2342
|
+
"../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/get-context.js"(exports$1, module) {
|
|
2224
2343
|
var __defProp2 = Object.defineProperty;
|
|
2225
2344
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
2226
2345
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2227
2346
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
2228
2347
|
var __export2 = (target, all) => {
|
|
2229
|
-
for (var
|
|
2230
|
-
__defProp2(target,
|
|
2348
|
+
for (var name21 in all)
|
|
2349
|
+
__defProp2(target, name21, { get: all[name21], enumerable: true });
|
|
2231
2350
|
};
|
|
2232
2351
|
var __copyProps = (to, from, except, desc) => {
|
|
2233
2352
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -2251,15 +2370,15 @@ var require_get_context = chunkPOKH6N2J_cjs.__commonJS({
|
|
|
2251
2370
|
}
|
|
2252
2371
|
}
|
|
2253
2372
|
});
|
|
2254
|
-
var require_get_vercel_oidc_token =
|
|
2255
|
-
"../../../node_modules/.pnpm/@vercel+oidc@3.0
|
|
2373
|
+
var require_get_vercel_oidc_token = chunkAXN5P2GE_cjs.__commonJS({
|
|
2374
|
+
"../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/get-vercel-oidc-token.js"(exports$1, module) {
|
|
2256
2375
|
var __defProp2 = Object.defineProperty;
|
|
2257
2376
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
2258
2377
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2259
2378
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
2260
2379
|
var __export2 = (target, all) => {
|
|
2261
|
-
for (var
|
|
2262
|
-
__defProp2(target,
|
|
2380
|
+
for (var name21 in all)
|
|
2381
|
+
__defProp2(target, name21, { get: all[name21], enumerable: true });
|
|
2263
2382
|
};
|
|
2264
2383
|
var __copyProps = (to, from, except, desc) => {
|
|
2265
2384
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -2277,7 +2396,7 @@ var require_get_vercel_oidc_token = chunkPOKH6N2J_cjs.__commonJS({
|
|
|
2277
2396
|
});
|
|
2278
2397
|
module.exports = __toCommonJS(get_vercel_oidc_token_exports);
|
|
2279
2398
|
var import_get_context = require_get_context();
|
|
2280
|
-
var import_token_error =
|
|
2399
|
+
var import_token_error = chunkAXN5P2GE_cjs.require_token_error();
|
|
2281
2400
|
async function getVercelOidcToken3() {
|
|
2282
2401
|
let token = "";
|
|
2283
2402
|
let err;
|
|
@@ -2288,19 +2407,23 @@ var require_get_vercel_oidc_token = chunkPOKH6N2J_cjs.__commonJS({
|
|
|
2288
2407
|
}
|
|
2289
2408
|
try {
|
|
2290
2409
|
const [{ getTokenPayload, isExpired }, { refreshToken }] = await Promise.all([
|
|
2291
|
-
await import('./token-util-
|
|
2292
|
-
await import('./token-
|
|
2410
|
+
await import('./token-util-RMHT2CPJ-WV2T74WQ.cjs'),
|
|
2411
|
+
await import('./token-APYSY3BW-UBKUGJQP.cjs')
|
|
2293
2412
|
]);
|
|
2294
2413
|
if (!token || isExpired(getTokenPayload(token))) {
|
|
2295
2414
|
await refreshToken();
|
|
2296
2415
|
token = getVercelOidcTokenSync2();
|
|
2297
2416
|
}
|
|
2298
2417
|
} catch (error) {
|
|
2299
|
-
|
|
2300
|
-
|
|
2418
|
+
let message = err instanceof Error ? err.message : "";
|
|
2419
|
+
if (error instanceof Error) {
|
|
2420
|
+
message = `${message}
|
|
2301
2421
|
${error.message}`;
|
|
2302
2422
|
}
|
|
2303
|
-
|
|
2423
|
+
if (message) {
|
|
2424
|
+
throw new import_token_error.VercelOidcTokenError(message);
|
|
2425
|
+
}
|
|
2426
|
+
throw error;
|
|
2304
2427
|
}
|
|
2305
2428
|
return token;
|
|
2306
2429
|
}
|
|
@@ -2315,15 +2438,15 @@ ${error.message}`;
|
|
|
2315
2438
|
}
|
|
2316
2439
|
}
|
|
2317
2440
|
});
|
|
2318
|
-
var require_dist =
|
|
2319
|
-
"../../../node_modules/.pnpm/@vercel+oidc@3.0
|
|
2441
|
+
var require_dist = chunkAXN5P2GE_cjs.__commonJS({
|
|
2442
|
+
"../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/index.js"(exports$1, module) {
|
|
2320
2443
|
var __defProp2 = Object.defineProperty;
|
|
2321
2444
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
2322
2445
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2323
2446
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
2324
2447
|
var __export2 = (target, all) => {
|
|
2325
|
-
for (var
|
|
2326
|
-
__defProp2(target,
|
|
2448
|
+
for (var name21 in all)
|
|
2449
|
+
__defProp2(target, name21, { get: all[name21], enumerable: true });
|
|
2327
2450
|
};
|
|
2328
2451
|
var __copyProps = (to, from, except, desc) => {
|
|
2329
2452
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -2345,8 +2468,8 @@ var require_dist = chunkPOKH6N2J_cjs.__commonJS({
|
|
|
2345
2468
|
var import_get_context = require_get_context();
|
|
2346
2469
|
}
|
|
2347
2470
|
});
|
|
2348
|
-
var import_oidc =
|
|
2349
|
-
var import_oidc2 =
|
|
2471
|
+
var import_oidc = chunkAXN5P2GE_cjs.__toESM(require_dist(), 1);
|
|
2472
|
+
var import_oidc2 = chunkAXN5P2GE_cjs.__toESM(require_dist(), 1);
|
|
2350
2473
|
var marker16 = "vercel.ai.gateway.error";
|
|
2351
2474
|
var symbol16 = Symbol.for(marker16);
|
|
2352
2475
|
var _a16;
|
|
@@ -2355,12 +2478,14 @@ var GatewayError = class _GatewayError extends (_b16 = Error, _a16 = symbol16, _
|
|
|
2355
2478
|
constructor({
|
|
2356
2479
|
message,
|
|
2357
2480
|
statusCode = 500,
|
|
2358
|
-
cause
|
|
2481
|
+
cause,
|
|
2482
|
+
generationId
|
|
2359
2483
|
}) {
|
|
2360
|
-
super(message);
|
|
2484
|
+
super(generationId ? `${message} [${generationId}]` : message);
|
|
2361
2485
|
this[_a16] = true;
|
|
2362
2486
|
this.statusCode = statusCode;
|
|
2363
2487
|
this.cause = cause;
|
|
2488
|
+
this.generationId = generationId;
|
|
2364
2489
|
}
|
|
2365
2490
|
/**
|
|
2366
2491
|
* Checks if the given error is a Gateway Error.
|
|
@@ -2383,9 +2508,10 @@ var GatewayAuthenticationError = class _GatewayAuthenticationError extends (_b22
|
|
|
2383
2508
|
constructor({
|
|
2384
2509
|
message = "Authentication failed",
|
|
2385
2510
|
statusCode = 401,
|
|
2386
|
-
cause
|
|
2511
|
+
cause,
|
|
2512
|
+
generationId
|
|
2387
2513
|
} = {}) {
|
|
2388
|
-
super({ message, statusCode, cause });
|
|
2514
|
+
super({ message, statusCode, cause, generationId });
|
|
2389
2515
|
this[_a22] = true;
|
|
2390
2516
|
this.name = name15;
|
|
2391
2517
|
this.type = "authentication_error";
|
|
@@ -2401,7 +2527,8 @@ var GatewayAuthenticationError = class _GatewayAuthenticationError extends (_b22
|
|
|
2401
2527
|
oidcTokenProvided,
|
|
2402
2528
|
message = "Authentication failed",
|
|
2403
2529
|
statusCode = 401,
|
|
2404
|
-
cause
|
|
2530
|
+
cause,
|
|
2531
|
+
generationId
|
|
2405
2532
|
}) {
|
|
2406
2533
|
let contextualMessage;
|
|
2407
2534
|
if (apiKeyProvided) {
|
|
@@ -2429,7 +2556,8 @@ Run 'npx vercel link' to link your project, then 'vc env pull' to fetch the toke
|
|
|
2429
2556
|
return new _GatewayAuthenticationError({
|
|
2430
2557
|
message: contextualMessage,
|
|
2431
2558
|
statusCode,
|
|
2432
|
-
cause
|
|
2559
|
+
cause,
|
|
2560
|
+
generationId
|
|
2433
2561
|
});
|
|
2434
2562
|
}
|
|
2435
2563
|
};
|
|
@@ -2442,9 +2570,10 @@ var GatewayInvalidRequestError = class extends (_b32 = GatewayError, _a32 = symb
|
|
|
2442
2570
|
constructor({
|
|
2443
2571
|
message = "Invalid request",
|
|
2444
2572
|
statusCode = 400,
|
|
2445
|
-
cause
|
|
2573
|
+
cause,
|
|
2574
|
+
generationId
|
|
2446
2575
|
} = {}) {
|
|
2447
|
-
super({ message, statusCode, cause });
|
|
2576
|
+
super({ message, statusCode, cause, generationId });
|
|
2448
2577
|
this[_a32] = true;
|
|
2449
2578
|
this.name = name22;
|
|
2450
2579
|
this.type = "invalid_request_error";
|
|
@@ -2462,9 +2591,10 @@ var GatewayRateLimitError = class extends (_b42 = GatewayError, _a42 = symbol42,
|
|
|
2462
2591
|
constructor({
|
|
2463
2592
|
message = "Rate limit exceeded",
|
|
2464
2593
|
statusCode = 429,
|
|
2465
|
-
cause
|
|
2594
|
+
cause,
|
|
2595
|
+
generationId
|
|
2466
2596
|
} = {}) {
|
|
2467
|
-
super({ message, statusCode, cause });
|
|
2597
|
+
super({ message, statusCode, cause, generationId });
|
|
2468
2598
|
this[_a42] = true;
|
|
2469
2599
|
this.name = name32;
|
|
2470
2600
|
this.type = "rate_limit_exceeded";
|
|
@@ -2490,9 +2620,10 @@ var GatewayModelNotFoundError = class extends (_b52 = GatewayError, _a52 = symbo
|
|
|
2490
2620
|
message = "Model not found",
|
|
2491
2621
|
statusCode = 404,
|
|
2492
2622
|
modelId,
|
|
2493
|
-
cause
|
|
2623
|
+
cause,
|
|
2624
|
+
generationId
|
|
2494
2625
|
} = {}) {
|
|
2495
|
-
super({ message, statusCode, cause });
|
|
2626
|
+
super({ message, statusCode, cause, generationId });
|
|
2496
2627
|
this[_a52] = true;
|
|
2497
2628
|
this.name = name42;
|
|
2498
2629
|
this.type = "model_not_found";
|
|
@@ -2511,9 +2642,10 @@ var GatewayInternalServerError = class extends (_b62 = GatewayError, _a62 = symb
|
|
|
2511
2642
|
constructor({
|
|
2512
2643
|
message = "Internal server error",
|
|
2513
2644
|
statusCode = 500,
|
|
2514
|
-
cause
|
|
2645
|
+
cause,
|
|
2646
|
+
generationId
|
|
2515
2647
|
} = {}) {
|
|
2516
|
-
super({ message, statusCode, cause });
|
|
2648
|
+
super({ message, statusCode, cause, generationId });
|
|
2517
2649
|
this[_a62] = true;
|
|
2518
2650
|
this.name = name52;
|
|
2519
2651
|
this.type = "internal_server_error";
|
|
@@ -2533,9 +2665,10 @@ var GatewayResponseError = class extends (_b72 = GatewayError, _a72 = symbol72,
|
|
|
2533
2665
|
statusCode = 502,
|
|
2534
2666
|
response,
|
|
2535
2667
|
validationError,
|
|
2536
|
-
cause
|
|
2668
|
+
cause,
|
|
2669
|
+
generationId
|
|
2537
2670
|
} = {}) {
|
|
2538
|
-
super({ message, statusCode, cause });
|
|
2671
|
+
super({ message, statusCode, cause, generationId });
|
|
2539
2672
|
this[_a72] = true;
|
|
2540
2673
|
this.name = name62;
|
|
2541
2674
|
this.type = "response_error";
|
|
@@ -2553,34 +2686,49 @@ async function createGatewayErrorFromResponse({
|
|
|
2553
2686
|
cause,
|
|
2554
2687
|
authMethod
|
|
2555
2688
|
}) {
|
|
2689
|
+
var _a83;
|
|
2556
2690
|
const parseResult = await safeValidateTypes({
|
|
2557
2691
|
value: response,
|
|
2558
2692
|
schema: gatewayErrorResponseSchema
|
|
2559
2693
|
});
|
|
2560
2694
|
if (!parseResult.success) {
|
|
2695
|
+
const rawGenerationId = typeof response === "object" && response !== null && "generationId" in response ? response.generationId : void 0;
|
|
2561
2696
|
return new GatewayResponseError({
|
|
2562
2697
|
message: `Invalid error response format: ${defaultMessage}`,
|
|
2563
2698
|
statusCode,
|
|
2564
2699
|
response,
|
|
2565
2700
|
validationError: parseResult.error,
|
|
2566
|
-
cause
|
|
2701
|
+
cause,
|
|
2702
|
+
generationId: rawGenerationId
|
|
2567
2703
|
});
|
|
2568
2704
|
}
|
|
2569
2705
|
const validatedResponse = parseResult.value;
|
|
2570
2706
|
const errorType = validatedResponse.error.type;
|
|
2571
2707
|
const message = validatedResponse.error.message;
|
|
2708
|
+
const generationId = (_a83 = validatedResponse.generationId) != null ? _a83 : void 0;
|
|
2572
2709
|
switch (errorType) {
|
|
2573
2710
|
case "authentication_error":
|
|
2574
2711
|
return GatewayAuthenticationError.createContextualError({
|
|
2575
2712
|
apiKeyProvided: authMethod === "api-key",
|
|
2576
2713
|
oidcTokenProvided: authMethod === "oidc",
|
|
2577
2714
|
statusCode,
|
|
2578
|
-
cause
|
|
2715
|
+
cause,
|
|
2716
|
+
generationId
|
|
2579
2717
|
});
|
|
2580
2718
|
case "invalid_request_error":
|
|
2581
|
-
return new GatewayInvalidRequestError({
|
|
2719
|
+
return new GatewayInvalidRequestError({
|
|
2720
|
+
message,
|
|
2721
|
+
statusCode,
|
|
2722
|
+
cause,
|
|
2723
|
+
generationId
|
|
2724
|
+
});
|
|
2582
2725
|
case "rate_limit_exceeded":
|
|
2583
|
-
return new GatewayRateLimitError({
|
|
2726
|
+
return new GatewayRateLimitError({
|
|
2727
|
+
message,
|
|
2728
|
+
statusCode,
|
|
2729
|
+
cause,
|
|
2730
|
+
generationId
|
|
2731
|
+
});
|
|
2584
2732
|
case "model_not_found": {
|
|
2585
2733
|
const modelResult = await safeValidateTypes({
|
|
2586
2734
|
value: validatedResponse.error.param,
|
|
@@ -2590,13 +2738,24 @@ async function createGatewayErrorFromResponse({
|
|
|
2590
2738
|
message,
|
|
2591
2739
|
statusCode,
|
|
2592
2740
|
modelId: modelResult.success ? modelResult.value.modelId : void 0,
|
|
2593
|
-
cause
|
|
2741
|
+
cause,
|
|
2742
|
+
generationId
|
|
2594
2743
|
});
|
|
2595
2744
|
}
|
|
2596
2745
|
case "internal_server_error":
|
|
2597
|
-
return new GatewayInternalServerError({
|
|
2746
|
+
return new GatewayInternalServerError({
|
|
2747
|
+
message,
|
|
2748
|
+
statusCode,
|
|
2749
|
+
cause,
|
|
2750
|
+
generationId
|
|
2751
|
+
});
|
|
2598
2752
|
default:
|
|
2599
|
-
return new GatewayInternalServerError({
|
|
2753
|
+
return new GatewayInternalServerError({
|
|
2754
|
+
message,
|
|
2755
|
+
statusCode,
|
|
2756
|
+
cause,
|
|
2757
|
+
generationId
|
|
2758
|
+
});
|
|
2600
2759
|
}
|
|
2601
2760
|
}
|
|
2602
2761
|
var gatewayErrorResponseSchema = lazySchema(
|
|
@@ -2607,7 +2766,8 @@ var gatewayErrorResponseSchema = lazySchema(
|
|
|
2607
2766
|
type: z4.z.string().nullish(),
|
|
2608
2767
|
param: z4.z.unknown().nullish(),
|
|
2609
2768
|
code: z4.z.union([z4.z.string(), z4.z.number()]).nullish()
|
|
2610
|
-
})
|
|
2769
|
+
}),
|
|
2770
|
+
generationId: z4.z.string().nullish()
|
|
2611
2771
|
})
|
|
2612
2772
|
)
|
|
2613
2773
|
);
|
|
@@ -2883,7 +3043,7 @@ var GatewayLanguageModel = class {
|
|
|
2883
3043
|
}
|
|
2884
3044
|
getModelConfigHeaders(modelId, streaming) {
|
|
2885
3045
|
return {
|
|
2886
|
-
"ai-language-model-specification-version": "
|
|
3046
|
+
"ai-language-model-specification-version": "3",
|
|
2887
3047
|
"ai-language-model-id": modelId,
|
|
2888
3048
|
"ai-language-model-streaming": String(streaming)
|
|
2889
3049
|
};
|
|
@@ -2951,7 +3111,7 @@ var GatewayEmbeddingModel = class {
|
|
|
2951
3111
|
}
|
|
2952
3112
|
getModelConfigHeaders() {
|
|
2953
3113
|
return {
|
|
2954
|
-
"ai-embedding-model-specification-version": "
|
|
3114
|
+
"ai-embedding-model-specification-version": "3",
|
|
2955
3115
|
"ai-model-id": this.modelId
|
|
2956
3116
|
};
|
|
2957
3117
|
}
|
|
@@ -2981,6 +3141,8 @@ var GatewayImageModel = class {
|
|
|
2981
3141
|
size,
|
|
2982
3142
|
aspectRatio,
|
|
2983
3143
|
seed,
|
|
3144
|
+
files,
|
|
3145
|
+
mask,
|
|
2984
3146
|
providerOptions,
|
|
2985
3147
|
headers,
|
|
2986
3148
|
abortSignal
|
|
@@ -3005,7 +3167,11 @@ var GatewayImageModel = class {
|
|
|
3005
3167
|
...size && { size },
|
|
3006
3168
|
...aspectRatio && { aspectRatio },
|
|
3007
3169
|
...seed && { seed },
|
|
3008
|
-
...providerOptions && { providerOptions }
|
|
3170
|
+
...providerOptions && { providerOptions },
|
|
3171
|
+
...files && {
|
|
3172
|
+
files: files.map((file) => maybeEncodeImageFile(file))
|
|
3173
|
+
},
|
|
3174
|
+
...mask && { mask: maybeEncodeImageFile(mask) }
|
|
3009
3175
|
},
|
|
3010
3176
|
successfulResponseHandler: createJsonResponseHandler(
|
|
3011
3177
|
gatewayImageResponseSchema
|
|
@@ -3037,11 +3203,20 @@ var GatewayImageModel = class {
|
|
|
3037
3203
|
}
|
|
3038
3204
|
getModelConfigHeaders() {
|
|
3039
3205
|
return {
|
|
3040
|
-
"ai-image-model-specification-version": "
|
|
3206
|
+
"ai-image-model-specification-version": "3",
|
|
3041
3207
|
"ai-model-id": this.modelId
|
|
3042
3208
|
};
|
|
3043
3209
|
}
|
|
3044
3210
|
};
|
|
3211
|
+
function maybeEncodeImageFile(file) {
|
|
3212
|
+
if (file.type === "file" && file.data instanceof Uint8Array) {
|
|
3213
|
+
return {
|
|
3214
|
+
...file,
|
|
3215
|
+
data: convertUint8ArrayToBase64(file.data)
|
|
3216
|
+
};
|
|
3217
|
+
}
|
|
3218
|
+
return file;
|
|
3219
|
+
}
|
|
3045
3220
|
var providerMetadataEntrySchema = z4.z.object({
|
|
3046
3221
|
images: z4.z.array(z4.z.unknown()).optional()
|
|
3047
3222
|
}).catchall(z4.z.unknown());
|
|
@@ -3056,11 +3231,183 @@ var gatewayImageResponseSchema = z4.z.object({
|
|
|
3056
3231
|
).optional(),
|
|
3057
3232
|
providerMetadata: z4.z.record(z4.z.string(), providerMetadataEntrySchema).optional()
|
|
3058
3233
|
});
|
|
3234
|
+
var parallelSearchInputSchema = lazySchema(
|
|
3235
|
+
() => zodSchema(
|
|
3236
|
+
zod.z.object({
|
|
3237
|
+
objective: zod.z.string().describe(
|
|
3238
|
+
"Natural-language description of the web research goal, including source or freshness guidance and broader context from the task. Maximum 5000 characters."
|
|
3239
|
+
),
|
|
3240
|
+
search_queries: zod.z.array(zod.z.string()).optional().describe(
|
|
3241
|
+
"Optional search queries to supplement the objective. Maximum 200 characters per query."
|
|
3242
|
+
),
|
|
3243
|
+
mode: zod.z.enum(["one-shot", "agentic"]).optional().describe(
|
|
3244
|
+
'Mode preset: "one-shot" for comprehensive results with longer excerpts (default), "agentic" for concise, token-efficient results for multi-step workflows.'
|
|
3245
|
+
),
|
|
3246
|
+
max_results: zod.z.number().optional().describe(
|
|
3247
|
+
"Maximum number of results to return (1-20). Defaults to 10 if not specified."
|
|
3248
|
+
),
|
|
3249
|
+
source_policy: zod.z.object({
|
|
3250
|
+
include_domains: zod.z.array(zod.z.string()).optional().describe("List of domains to include in search results."),
|
|
3251
|
+
exclude_domains: zod.z.array(zod.z.string()).optional().describe("List of domains to exclude from search results."),
|
|
3252
|
+
after_date: zod.z.string().optional().describe(
|
|
3253
|
+
"Only include results published after this date (ISO 8601 format)."
|
|
3254
|
+
)
|
|
3255
|
+
}).optional().describe(
|
|
3256
|
+
"Source policy for controlling which domains to include/exclude and freshness."
|
|
3257
|
+
),
|
|
3258
|
+
excerpts: zod.z.object({
|
|
3259
|
+
max_chars_per_result: zod.z.number().optional().describe("Maximum characters per result."),
|
|
3260
|
+
max_chars_total: zod.z.number().optional().describe("Maximum total characters across all results.")
|
|
3261
|
+
}).optional().describe("Excerpt configuration for controlling result length."),
|
|
3262
|
+
fetch_policy: zod.z.object({
|
|
3263
|
+
max_age_seconds: zod.z.number().optional().describe(
|
|
3264
|
+
"Maximum age in seconds for cached content. Set to 0 to always fetch fresh content."
|
|
3265
|
+
)
|
|
3266
|
+
}).optional().describe("Fetch policy for controlling content freshness.")
|
|
3267
|
+
})
|
|
3268
|
+
)
|
|
3269
|
+
);
|
|
3270
|
+
var parallelSearchOutputSchema = lazySchema(
|
|
3271
|
+
() => zodSchema(
|
|
3272
|
+
zod.z.union([
|
|
3273
|
+
// Success response
|
|
3274
|
+
zod.z.object({
|
|
3275
|
+
searchId: zod.z.string(),
|
|
3276
|
+
results: zod.z.array(
|
|
3277
|
+
zod.z.object({
|
|
3278
|
+
url: zod.z.string(),
|
|
3279
|
+
title: zod.z.string(),
|
|
3280
|
+
excerpt: zod.z.string(),
|
|
3281
|
+
publishDate: zod.z.string().nullable().optional(),
|
|
3282
|
+
relevanceScore: zod.z.number().optional()
|
|
3283
|
+
})
|
|
3284
|
+
)
|
|
3285
|
+
}),
|
|
3286
|
+
// Error response
|
|
3287
|
+
zod.z.object({
|
|
3288
|
+
error: zod.z.enum([
|
|
3289
|
+
"api_error",
|
|
3290
|
+
"rate_limit",
|
|
3291
|
+
"timeout",
|
|
3292
|
+
"invalid_input",
|
|
3293
|
+
"configuration_error",
|
|
3294
|
+
"unknown"
|
|
3295
|
+
]),
|
|
3296
|
+
statusCode: zod.z.number().optional(),
|
|
3297
|
+
message: zod.z.string()
|
|
3298
|
+
})
|
|
3299
|
+
])
|
|
3300
|
+
)
|
|
3301
|
+
);
|
|
3302
|
+
var parallelSearchToolFactory = createProviderToolFactoryWithOutputSchema({
|
|
3303
|
+
id: "gateway.parallel_search",
|
|
3304
|
+
inputSchema: parallelSearchInputSchema,
|
|
3305
|
+
outputSchema: parallelSearchOutputSchema
|
|
3306
|
+
});
|
|
3307
|
+
var parallelSearch = (config = {}) => parallelSearchToolFactory(config);
|
|
3308
|
+
var perplexitySearchInputSchema = lazySchema(
|
|
3309
|
+
() => zodSchema(
|
|
3310
|
+
zod.z.object({
|
|
3311
|
+
query: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]).describe(
|
|
3312
|
+
"Search query (string) or multiple queries (array of up to 5 strings). Multi-query searches return combined results from all queries."
|
|
3313
|
+
),
|
|
3314
|
+
max_results: zod.z.number().optional().describe(
|
|
3315
|
+
"Maximum number of search results to return (1-20, default: 10)"
|
|
3316
|
+
),
|
|
3317
|
+
max_tokens_per_page: zod.z.number().optional().describe(
|
|
3318
|
+
"Maximum number of tokens to extract per search result page (256-2048, default: 2048)"
|
|
3319
|
+
),
|
|
3320
|
+
max_tokens: zod.z.number().optional().describe(
|
|
3321
|
+
"Maximum total tokens across all search results (default: 25000, max: 1000000)"
|
|
3322
|
+
),
|
|
3323
|
+
country: zod.z.string().optional().describe(
|
|
3324
|
+
"Two-letter ISO 3166-1 alpha-2 country code for regional search results (e.g., 'US', 'GB', 'FR')"
|
|
3325
|
+
),
|
|
3326
|
+
search_domain_filter: zod.z.array(zod.z.string()).optional().describe(
|
|
3327
|
+
"List of domains to include or exclude from search results (max 20). To include: ['nature.com', 'science.org']. To exclude: ['-example.com', '-spam.net']"
|
|
3328
|
+
),
|
|
3329
|
+
search_language_filter: zod.z.array(zod.z.string()).optional().describe(
|
|
3330
|
+
"List of ISO 639-1 language codes to filter results (max 10, lowercase). Examples: ['en', 'fr', 'de']"
|
|
3331
|
+
),
|
|
3332
|
+
search_after_date: zod.z.string().optional().describe(
|
|
3333
|
+
"Include only results published after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
|
|
3334
|
+
),
|
|
3335
|
+
search_before_date: zod.z.string().optional().describe(
|
|
3336
|
+
"Include only results published before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
|
|
3337
|
+
),
|
|
3338
|
+
last_updated_after_filter: zod.z.string().optional().describe(
|
|
3339
|
+
"Include only results last updated after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
|
|
3340
|
+
),
|
|
3341
|
+
last_updated_before_filter: zod.z.string().optional().describe(
|
|
3342
|
+
"Include only results last updated before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
|
|
3343
|
+
),
|
|
3344
|
+
search_recency_filter: zod.z.enum(["day", "week", "month", "year"]).optional().describe(
|
|
3345
|
+
"Filter results by relative time period. Cannot be used with search_after_date or search_before_date."
|
|
3346
|
+
)
|
|
3347
|
+
})
|
|
3348
|
+
)
|
|
3349
|
+
);
|
|
3350
|
+
var perplexitySearchOutputSchema = lazySchema(
|
|
3351
|
+
() => zodSchema(
|
|
3352
|
+
zod.z.union([
|
|
3353
|
+
// Success response
|
|
3354
|
+
zod.z.object({
|
|
3355
|
+
results: zod.z.array(
|
|
3356
|
+
zod.z.object({
|
|
3357
|
+
title: zod.z.string(),
|
|
3358
|
+
url: zod.z.string(),
|
|
3359
|
+
snippet: zod.z.string(),
|
|
3360
|
+
date: zod.z.string().optional(),
|
|
3361
|
+
lastUpdated: zod.z.string().optional()
|
|
3362
|
+
})
|
|
3363
|
+
),
|
|
3364
|
+
id: zod.z.string()
|
|
3365
|
+
}),
|
|
3366
|
+
// Error response
|
|
3367
|
+
zod.z.object({
|
|
3368
|
+
error: zod.z.enum([
|
|
3369
|
+
"api_error",
|
|
3370
|
+
"rate_limit",
|
|
3371
|
+
"timeout",
|
|
3372
|
+
"invalid_input",
|
|
3373
|
+
"unknown"
|
|
3374
|
+
]),
|
|
3375
|
+
statusCode: zod.z.number().optional(),
|
|
3376
|
+
message: zod.z.string()
|
|
3377
|
+
})
|
|
3378
|
+
])
|
|
3379
|
+
)
|
|
3380
|
+
);
|
|
3381
|
+
var perplexitySearchToolFactory = createProviderToolFactoryWithOutputSchema({
|
|
3382
|
+
id: "gateway.perplexity_search",
|
|
3383
|
+
inputSchema: perplexitySearchInputSchema,
|
|
3384
|
+
outputSchema: perplexitySearchOutputSchema
|
|
3385
|
+
});
|
|
3386
|
+
var perplexitySearch = (config = {}) => perplexitySearchToolFactory(config);
|
|
3387
|
+
var gatewayTools = {
|
|
3388
|
+
/**
|
|
3389
|
+
* Search the web using Parallel AI's Search API for LLM-optimized excerpts.
|
|
3390
|
+
*
|
|
3391
|
+
* Takes a natural language objective and returns relevant excerpts,
|
|
3392
|
+
* replacing multiple keyword searches with a single call for broad
|
|
3393
|
+
* or complex queries. Supports different search types for depth vs
|
|
3394
|
+
* breadth tradeoffs.
|
|
3395
|
+
*/
|
|
3396
|
+
parallelSearch,
|
|
3397
|
+
/**
|
|
3398
|
+
* Search the web using Perplexity's Search API for real-time information,
|
|
3399
|
+
* news, research papers, and articles.
|
|
3400
|
+
*
|
|
3401
|
+
* Provides ranked search results with advanced filtering options including
|
|
3402
|
+
* domain, language, date range, and recency filters.
|
|
3403
|
+
*/
|
|
3404
|
+
perplexitySearch
|
|
3405
|
+
};
|
|
3059
3406
|
async function getVercelRequestId() {
|
|
3060
3407
|
var _a83;
|
|
3061
3408
|
return (_a83 = (0, import_oidc.getContext)().headers) == null ? void 0 : _a83["x-vercel-id"];
|
|
3062
3409
|
}
|
|
3063
|
-
var VERSION2 = "3.0.
|
|
3410
|
+
var VERSION2 = "3.0.32";
|
|
3064
3411
|
var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
|
|
3065
3412
|
function createGatewayProvider(options = {}) {
|
|
3066
3413
|
var _a83, _b82;
|
|
@@ -3070,8 +3417,8 @@ function createGatewayProvider(options = {}) {
|
|
|
3070
3417
|
let lastFetchTime = 0;
|
|
3071
3418
|
const baseURL = (_b82 = withoutTrailingSlash(options.baseURL)) != null ? _b82 : "https://ai-gateway.vercel.sh/v3/ai";
|
|
3072
3419
|
const getHeaders = async () => {
|
|
3073
|
-
|
|
3074
|
-
|
|
3420
|
+
try {
|
|
3421
|
+
const auth = await getGatewayAuthToken(options);
|
|
3075
3422
|
return withUserAgentSuffix(
|
|
3076
3423
|
{
|
|
3077
3424
|
Authorization: `Bearer ${auth.token}`,
|
|
@@ -3081,12 +3428,14 @@ function createGatewayProvider(options = {}) {
|
|
|
3081
3428
|
},
|
|
3082
3429
|
`ai-sdk/gateway/${VERSION2}`
|
|
3083
3430
|
);
|
|
3431
|
+
} catch (error) {
|
|
3432
|
+
throw GatewayAuthenticationError.createContextualError({
|
|
3433
|
+
apiKeyProvided: false,
|
|
3434
|
+
oidcTokenProvided: false,
|
|
3435
|
+
statusCode: 401,
|
|
3436
|
+
cause: error
|
|
3437
|
+
});
|
|
3084
3438
|
}
|
|
3085
|
-
throw GatewayAuthenticationError.createContextualError({
|
|
3086
|
-
apiKeyProvided: false,
|
|
3087
|
-
oidcTokenProvided: false,
|
|
3088
|
-
statusCode: 401
|
|
3089
|
-
});
|
|
3090
3439
|
};
|
|
3091
3440
|
const createO11yHeaders = () => {
|
|
3092
3441
|
const deploymentId = loadOptionalSetting({
|
|
@@ -3185,6 +3534,7 @@ function createGatewayProvider(options = {}) {
|
|
|
3185
3534
|
};
|
|
3186
3535
|
provider.embeddingModel = createEmbeddingModel;
|
|
3187
3536
|
provider.textEmbeddingModel = createEmbeddingModel;
|
|
3537
|
+
provider.tools = gatewayTools;
|
|
3188
3538
|
return provider;
|
|
3189
3539
|
}
|
|
3190
3540
|
var gateway = createGatewayProvider();
|
|
@@ -3199,15 +3549,11 @@ async function getGatewayAuthToken(options) {
|
|
|
3199
3549
|
authMethod: "api-key"
|
|
3200
3550
|
};
|
|
3201
3551
|
}
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
};
|
|
3208
|
-
} catch (e) {
|
|
3209
|
-
return null;
|
|
3210
|
-
}
|
|
3552
|
+
const oidcToken = await (0, import_oidc2.getVercelOidcToken)();
|
|
3553
|
+
return {
|
|
3554
|
+
token: oidcToken,
|
|
3555
|
+
authMethod: "oidc"
|
|
3556
|
+
};
|
|
3211
3557
|
}
|
|
3212
3558
|
var _globalThis = typeof globalThis === "object" ? globalThis : global;
|
|
3213
3559
|
var VERSION22 = "1.9.0";
|
|
@@ -3280,11 +3626,11 @@ var major = VERSION22.split(".")[0];
|
|
|
3280
3626
|
var GLOBAL_OPENTELEMETRY_API_KEY = /* @__PURE__ */ Symbol.for("opentelemetry.js.api." + major);
|
|
3281
3627
|
var _global = _globalThis;
|
|
3282
3628
|
function registerGlobal(type, instance, diag, allowOverride) {
|
|
3283
|
-
var
|
|
3629
|
+
var _a21;
|
|
3284
3630
|
if (allowOverride === void 0) {
|
|
3285
3631
|
allowOverride = false;
|
|
3286
3632
|
}
|
|
3287
|
-
var api = _global[GLOBAL_OPENTELEMETRY_API_KEY] = (
|
|
3633
|
+
var api = _global[GLOBAL_OPENTELEMETRY_API_KEY] = (_a21 = _global[GLOBAL_OPENTELEMETRY_API_KEY]) !== null && _a21 !== void 0 ? _a21 : {
|
|
3288
3634
|
version: VERSION22
|
|
3289
3635
|
};
|
|
3290
3636
|
if (!allowOverride && api[type]) {
|
|
@@ -3302,8 +3648,8 @@ function registerGlobal(type, instance, diag, allowOverride) {
|
|
|
3302
3648
|
return true;
|
|
3303
3649
|
}
|
|
3304
3650
|
function getGlobal(type) {
|
|
3305
|
-
var
|
|
3306
|
-
var globalVersion = (
|
|
3651
|
+
var _a21, _b82;
|
|
3652
|
+
var globalVersion = (_a21 = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _a21 === void 0 ? void 0 : _a21.version;
|
|
3307
3653
|
if (!globalVersion || !isCompatible(globalVersion)) {
|
|
3308
3654
|
return;
|
|
3309
3655
|
}
|
|
@@ -3472,13 +3818,13 @@ var DiagAPI = (
|
|
|
3472
3818
|
}
|
|
3473
3819
|
var self = this;
|
|
3474
3820
|
var setLogger = function(logger, optionsOrLogLevel) {
|
|
3475
|
-
var
|
|
3821
|
+
var _a21, _b82, _c;
|
|
3476
3822
|
if (optionsOrLogLevel === void 0) {
|
|
3477
3823
|
optionsOrLogLevel = { logLevel: DiagLogLevel.INFO };
|
|
3478
3824
|
}
|
|
3479
3825
|
if (logger === self) {
|
|
3480
3826
|
var err = new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");
|
|
3481
|
-
self.error((
|
|
3827
|
+
self.error((_a21 = err.stack) !== null && _a21 !== void 0 ? _a21 : err.message);
|
|
3482
3828
|
return false;
|
|
3483
3829
|
}
|
|
3484
3830
|
if (typeof optionsOrLogLevel === "number") {
|
|
@@ -3530,14 +3876,14 @@ var BaseContext = (
|
|
|
3530
3876
|
return self._currentContext.get(key);
|
|
3531
3877
|
};
|
|
3532
3878
|
self.setValue = function(key, value) {
|
|
3533
|
-
var
|
|
3534
|
-
|
|
3535
|
-
return
|
|
3879
|
+
var context2 = new BaseContext2(self._currentContext);
|
|
3880
|
+
context2._currentContext.set(key, value);
|
|
3881
|
+
return context2;
|
|
3536
3882
|
};
|
|
3537
3883
|
self.deleteValue = function(key) {
|
|
3538
|
-
var
|
|
3539
|
-
|
|
3540
|
-
return
|
|
3884
|
+
var context2 = new BaseContext2(self._currentContext);
|
|
3885
|
+
context2._currentContext.delete(key);
|
|
3886
|
+
return context2;
|
|
3541
3887
|
};
|
|
3542
3888
|
}
|
|
3543
3889
|
return BaseContext2;
|
|
@@ -3642,16 +3988,16 @@ var ContextAPI = (
|
|
|
3642
3988
|
ContextAPI2.prototype.active = function() {
|
|
3643
3989
|
return this._getContextManager().active();
|
|
3644
3990
|
};
|
|
3645
|
-
ContextAPI2.prototype.with = function(
|
|
3646
|
-
var
|
|
3991
|
+
ContextAPI2.prototype.with = function(context2, fn, thisArg) {
|
|
3992
|
+
var _a21;
|
|
3647
3993
|
var args = [];
|
|
3648
3994
|
for (var _i = 3; _i < arguments.length; _i++) {
|
|
3649
3995
|
args[_i - 3] = arguments[_i];
|
|
3650
3996
|
}
|
|
3651
|
-
return (
|
|
3997
|
+
return (_a21 = this._getContextManager()).with.apply(_a21, __spreadArray4([context2, fn, thisArg], __read4(args), false));
|
|
3652
3998
|
};
|
|
3653
|
-
ContextAPI2.prototype.bind = function(
|
|
3654
|
-
return this._getContextManager().bind(
|
|
3999
|
+
ContextAPI2.prototype.bind = function(context2, target) {
|
|
4000
|
+
return this._getContextManager().bind(context2, target);
|
|
3655
4001
|
};
|
|
3656
4002
|
ContextAPI2.prototype._getContextManager = function() {
|
|
3657
4003
|
return getGlobal(API_NAME2) || NOOP_CONTEXT_MANAGER;
|
|
@@ -3719,24 +4065,24 @@ var NonRecordingSpan = (
|
|
|
3719
4065
|
})()
|
|
3720
4066
|
);
|
|
3721
4067
|
var SPAN_KEY = createContextKey("OpenTelemetry Context Key SPAN");
|
|
3722
|
-
function getSpan(
|
|
3723
|
-
return
|
|
4068
|
+
function getSpan(context2) {
|
|
4069
|
+
return context2.getValue(SPAN_KEY) || void 0;
|
|
3724
4070
|
}
|
|
3725
4071
|
function getActiveSpan() {
|
|
3726
4072
|
return getSpan(ContextAPI.getInstance().active());
|
|
3727
4073
|
}
|
|
3728
|
-
function setSpan(
|
|
3729
|
-
return
|
|
4074
|
+
function setSpan(context2, span) {
|
|
4075
|
+
return context2.setValue(SPAN_KEY, span);
|
|
3730
4076
|
}
|
|
3731
|
-
function deleteSpan(
|
|
3732
|
-
return
|
|
4077
|
+
function deleteSpan(context2) {
|
|
4078
|
+
return context2.deleteValue(SPAN_KEY);
|
|
3733
4079
|
}
|
|
3734
|
-
function setSpanContext(
|
|
3735
|
-
return setSpan(
|
|
4080
|
+
function setSpanContext(context2, spanContext) {
|
|
4081
|
+
return setSpan(context2, new NonRecordingSpan(spanContext));
|
|
3736
4082
|
}
|
|
3737
|
-
function getSpanContext(
|
|
3738
|
-
var
|
|
3739
|
-
return (
|
|
4083
|
+
function getSpanContext(context2) {
|
|
4084
|
+
var _a21;
|
|
4085
|
+
return (_a21 = getSpan(context2)) === null || _a21 === void 0 ? void 0 : _a21.spanContext();
|
|
3740
4086
|
}
|
|
3741
4087
|
var VALID_TRACEID_REGEX = /^([0-9a-f]{32})$/i;
|
|
3742
4088
|
var VALID_SPANID_REGEX = /^[0-9a-f]{16}$/i;
|
|
@@ -3758,22 +4104,22 @@ var NoopTracer = (
|
|
|
3758
4104
|
(function() {
|
|
3759
4105
|
function NoopTracer2() {
|
|
3760
4106
|
}
|
|
3761
|
-
NoopTracer2.prototype.startSpan = function(
|
|
3762
|
-
if (
|
|
3763
|
-
|
|
4107
|
+
NoopTracer2.prototype.startSpan = function(name21, options, context2) {
|
|
4108
|
+
if (context2 === void 0) {
|
|
4109
|
+
context2 = contextApi.active();
|
|
3764
4110
|
}
|
|
3765
4111
|
var root = Boolean(options === null || options === void 0 ? void 0 : options.root);
|
|
3766
4112
|
if (root) {
|
|
3767
4113
|
return new NonRecordingSpan();
|
|
3768
4114
|
}
|
|
3769
|
-
var parentFromContext =
|
|
4115
|
+
var parentFromContext = context2 && getSpanContext(context2);
|
|
3770
4116
|
if (isSpanContext(parentFromContext) && isSpanContextValid(parentFromContext)) {
|
|
3771
4117
|
return new NonRecordingSpan(parentFromContext);
|
|
3772
4118
|
} else {
|
|
3773
4119
|
return new NonRecordingSpan();
|
|
3774
4120
|
}
|
|
3775
4121
|
};
|
|
3776
|
-
NoopTracer2.prototype.startActiveSpan = function(
|
|
4122
|
+
NoopTracer2.prototype.startActiveSpan = function(name21, arg2, arg3, arg4) {
|
|
3777
4123
|
var opts;
|
|
3778
4124
|
var ctx;
|
|
3779
4125
|
var fn;
|
|
@@ -3790,7 +4136,7 @@ var NoopTracer = (
|
|
|
3790
4136
|
fn = arg4;
|
|
3791
4137
|
}
|
|
3792
4138
|
var parentContext = ctx !== null && ctx !== void 0 ? ctx : contextApi.active();
|
|
3793
|
-
var span = this.startSpan(
|
|
4139
|
+
var span = this.startSpan(name21, opts, parentContext);
|
|
3794
4140
|
var contextWithSpanSet = setSpan(parentContext, span);
|
|
3795
4141
|
return contextApi.with(contextWithSpanSet, fn, void 0, span);
|
|
3796
4142
|
};
|
|
@@ -3804,14 +4150,14 @@ var NOOP_TRACER = new NoopTracer();
|
|
|
3804
4150
|
var ProxyTracer = (
|
|
3805
4151
|
/** @class */
|
|
3806
4152
|
(function() {
|
|
3807
|
-
function ProxyTracer2(_provider,
|
|
4153
|
+
function ProxyTracer2(_provider, name21, version, options) {
|
|
3808
4154
|
this._provider = _provider;
|
|
3809
|
-
this.name =
|
|
4155
|
+
this.name = name21;
|
|
3810
4156
|
this.version = version;
|
|
3811
4157
|
this.options = options;
|
|
3812
4158
|
}
|
|
3813
|
-
ProxyTracer2.prototype.startSpan = function(
|
|
3814
|
-
return this._getTracer().startSpan(
|
|
4159
|
+
ProxyTracer2.prototype.startSpan = function(name21, options, context2) {
|
|
4160
|
+
return this._getTracer().startSpan(name21, options, context2);
|
|
3815
4161
|
};
|
|
3816
4162
|
ProxyTracer2.prototype.startActiveSpan = function(_name, _options, _context, _fn) {
|
|
3817
4163
|
var tracer = this._getTracer();
|
|
@@ -3848,20 +4194,20 @@ var ProxyTracerProvider = (
|
|
|
3848
4194
|
(function() {
|
|
3849
4195
|
function ProxyTracerProvider2() {
|
|
3850
4196
|
}
|
|
3851
|
-
ProxyTracerProvider2.prototype.getTracer = function(
|
|
3852
|
-
var
|
|
3853
|
-
return (
|
|
4197
|
+
ProxyTracerProvider2.prototype.getTracer = function(name21, version, options) {
|
|
4198
|
+
var _a21;
|
|
4199
|
+
return (_a21 = this.getDelegateTracer(name21, version, options)) !== null && _a21 !== void 0 ? _a21 : new ProxyTracer(this, name21, version, options);
|
|
3854
4200
|
};
|
|
3855
4201
|
ProxyTracerProvider2.prototype.getDelegate = function() {
|
|
3856
|
-
var
|
|
3857
|
-
return (
|
|
4202
|
+
var _a21;
|
|
4203
|
+
return (_a21 = this._delegate) !== null && _a21 !== void 0 ? _a21 : NOOP_TRACER_PROVIDER;
|
|
3858
4204
|
};
|
|
3859
4205
|
ProxyTracerProvider2.prototype.setDelegate = function(delegate) {
|
|
3860
4206
|
this._delegate = delegate;
|
|
3861
4207
|
};
|
|
3862
|
-
ProxyTracerProvider2.prototype.getDelegateTracer = function(
|
|
3863
|
-
var
|
|
3864
|
-
return (
|
|
4208
|
+
ProxyTracerProvider2.prototype.getDelegateTracer = function(name21, version, options) {
|
|
4209
|
+
var _a21;
|
|
4210
|
+
return (_a21 = this._delegate) === null || _a21 === void 0 ? void 0 : _a21.getTracer(name21, version, options);
|
|
3865
4211
|
};
|
|
3866
4212
|
return ProxyTracerProvider2;
|
|
3867
4213
|
})()
|
|
@@ -3872,6 +4218,7 @@ var SpanStatusCode;
|
|
|
3872
4218
|
SpanStatusCode2[SpanStatusCode2["OK"] = 1] = "OK";
|
|
3873
4219
|
SpanStatusCode2[SpanStatusCode2["ERROR"] = 2] = "ERROR";
|
|
3874
4220
|
})(SpanStatusCode || (SpanStatusCode = {}));
|
|
4221
|
+
var context = ContextAPI.getInstance();
|
|
3875
4222
|
var API_NAME3 = "trace";
|
|
3876
4223
|
var TraceAPI = (
|
|
3877
4224
|
/** @class */
|
|
@@ -3903,8 +4250,8 @@ var TraceAPI = (
|
|
|
3903
4250
|
TraceAPI2.prototype.getTracerProvider = function() {
|
|
3904
4251
|
return getGlobal(API_NAME3) || this._proxyTracerProvider;
|
|
3905
4252
|
};
|
|
3906
|
-
TraceAPI2.prototype.getTracer = function(
|
|
3907
|
-
return this.getTracerProvider().getTracer(
|
|
4253
|
+
TraceAPI2.prototype.getTracer = function(name21, version) {
|
|
4254
|
+
return this.getTracerProvider().getTracer(name21, version);
|
|
3908
4255
|
};
|
|
3909
4256
|
TraceAPI2.prototype.disable = function() {
|
|
3910
4257
|
unregisterGlobal(API_NAME3, DiagAPI.instance());
|
|
@@ -3916,8 +4263,8 @@ var TraceAPI = (
|
|
|
3916
4263
|
var trace = TraceAPI.getInstance();
|
|
3917
4264
|
var __defProp = Object.defineProperty;
|
|
3918
4265
|
var __export = (target, all) => {
|
|
3919
|
-
for (var
|
|
3920
|
-
__defProp(target,
|
|
4266
|
+
for (var name21 in all)
|
|
4267
|
+
__defProp(target, name21, { get: all[name21], enumerable: true });
|
|
3921
4268
|
};
|
|
3922
4269
|
var name72 = "AI_InvalidArgumentError";
|
|
3923
4270
|
var marker82 = `vercel.ai.error.${name72}`;
|
|
@@ -3942,10 +4289,28 @@ var InvalidArgumentError2 = class extends AISDKError {
|
|
|
3942
4289
|
}
|
|
3943
4290
|
};
|
|
3944
4291
|
_a82 = symbol82;
|
|
3945
|
-
var name322 = "
|
|
4292
|
+
var name322 = "AI_InvalidToolApprovalError";
|
|
3946
4293
|
var marker322 = `vercel.ai.error.${name322}`;
|
|
3947
4294
|
var symbol322 = Symbol.for(marker322);
|
|
3948
4295
|
var _a322;
|
|
4296
|
+
var InvalidToolApprovalError = class extends AISDKError {
|
|
4297
|
+
constructor({ approvalId }) {
|
|
4298
|
+
super({
|
|
4299
|
+
name: name322,
|
|
4300
|
+
message: `Tool approval response references unknown approvalId: "${approvalId}". No matching tool-approval-request found in message history.`
|
|
4301
|
+
});
|
|
4302
|
+
this[_a322] = true;
|
|
4303
|
+
this.approvalId = approvalId;
|
|
4304
|
+
}
|
|
4305
|
+
static isInstance(error) {
|
|
4306
|
+
return AISDKError.hasMarker(error, marker322);
|
|
4307
|
+
}
|
|
4308
|
+
};
|
|
4309
|
+
_a322 = symbol322;
|
|
4310
|
+
var name422 = "AI_InvalidToolInputError";
|
|
4311
|
+
var marker422 = `vercel.ai.error.${name422}`;
|
|
4312
|
+
var symbol422 = Symbol.for(marker422);
|
|
4313
|
+
var _a422;
|
|
3949
4314
|
var InvalidToolInputError = class extends AISDKError {
|
|
3950
4315
|
constructor({
|
|
3951
4316
|
toolInput,
|
|
@@ -3953,20 +4318,62 @@ var InvalidToolInputError = class extends AISDKError {
|
|
|
3953
4318
|
cause,
|
|
3954
4319
|
message = `Invalid input for tool ${toolName}: ${getErrorMessage(cause)}`
|
|
3955
4320
|
}) {
|
|
3956
|
-
super({ name:
|
|
3957
|
-
this[
|
|
4321
|
+
super({ name: name422, message, cause });
|
|
4322
|
+
this[_a422] = true;
|
|
3958
4323
|
this.toolInput = toolInput;
|
|
3959
4324
|
this.toolName = toolName;
|
|
3960
4325
|
}
|
|
3961
4326
|
static isInstance(error) {
|
|
3962
|
-
return AISDKError.hasMarker(error,
|
|
4327
|
+
return AISDKError.hasMarker(error, marker422);
|
|
3963
4328
|
}
|
|
3964
4329
|
};
|
|
3965
|
-
|
|
3966
|
-
var name522 = "
|
|
4330
|
+
_a422 = symbol422;
|
|
4331
|
+
var name522 = "AI_ToolCallNotFoundForApprovalError";
|
|
3967
4332
|
var marker522 = `vercel.ai.error.${name522}`;
|
|
3968
4333
|
var symbol522 = Symbol.for(marker522);
|
|
3969
4334
|
var _a522;
|
|
4335
|
+
var ToolCallNotFoundForApprovalError = class extends AISDKError {
|
|
4336
|
+
constructor({
|
|
4337
|
+
toolCallId,
|
|
4338
|
+
approvalId
|
|
4339
|
+
}) {
|
|
4340
|
+
super({
|
|
4341
|
+
name: name522,
|
|
4342
|
+
message: `Tool call "${toolCallId}" not found for approval request "${approvalId}".`
|
|
4343
|
+
});
|
|
4344
|
+
this[_a522] = true;
|
|
4345
|
+
this.toolCallId = toolCallId;
|
|
4346
|
+
this.approvalId = approvalId;
|
|
4347
|
+
}
|
|
4348
|
+
static isInstance(error) {
|
|
4349
|
+
return AISDKError.hasMarker(error, marker522);
|
|
4350
|
+
}
|
|
4351
|
+
};
|
|
4352
|
+
_a522 = symbol522;
|
|
4353
|
+
var name622 = "AI_MissingToolResultsError";
|
|
4354
|
+
var marker622 = `vercel.ai.error.${name622}`;
|
|
4355
|
+
var symbol622 = Symbol.for(marker622);
|
|
4356
|
+
var _a622;
|
|
4357
|
+
var MissingToolResultsError = class extends AISDKError {
|
|
4358
|
+
constructor({ toolCallIds }) {
|
|
4359
|
+
super({
|
|
4360
|
+
name: name622,
|
|
4361
|
+
message: `Tool result${toolCallIds.length > 1 ? "s are" : " is"} missing for tool call${toolCallIds.length > 1 ? "s" : ""} ${toolCallIds.join(
|
|
4362
|
+
", "
|
|
4363
|
+
)}.`
|
|
4364
|
+
});
|
|
4365
|
+
this[_a622] = true;
|
|
4366
|
+
this.toolCallIds = toolCallIds;
|
|
4367
|
+
}
|
|
4368
|
+
static isInstance(error) {
|
|
4369
|
+
return AISDKError.hasMarker(error, marker622);
|
|
4370
|
+
}
|
|
4371
|
+
};
|
|
4372
|
+
_a622 = symbol622;
|
|
4373
|
+
var name82 = "AI_NoObjectGeneratedError";
|
|
4374
|
+
var marker822 = `vercel.ai.error.${name82}`;
|
|
4375
|
+
var symbol822 = Symbol.for(marker822);
|
|
4376
|
+
var _a822;
|
|
3970
4377
|
var NoObjectGeneratedError = class extends AISDKError {
|
|
3971
4378
|
constructor({
|
|
3972
4379
|
message = "No object generated.",
|
|
@@ -3976,75 +4383,75 @@ var NoObjectGeneratedError = class extends AISDKError {
|
|
|
3976
4383
|
usage,
|
|
3977
4384
|
finishReason
|
|
3978
4385
|
}) {
|
|
3979
|
-
super({ name:
|
|
3980
|
-
this[
|
|
4386
|
+
super({ name: name82, message, cause });
|
|
4387
|
+
this[_a822] = true;
|
|
3981
4388
|
this.text = text2;
|
|
3982
4389
|
this.response = response;
|
|
3983
4390
|
this.usage = usage;
|
|
3984
4391
|
this.finishReason = finishReason;
|
|
3985
4392
|
}
|
|
3986
4393
|
static isInstance(error) {
|
|
3987
|
-
return AISDKError.hasMarker(error,
|
|
4394
|
+
return AISDKError.hasMarker(error, marker822);
|
|
3988
4395
|
}
|
|
3989
4396
|
};
|
|
3990
|
-
|
|
3991
|
-
var
|
|
3992
|
-
var
|
|
3993
|
-
var
|
|
3994
|
-
var
|
|
4397
|
+
_a822 = symbol822;
|
|
4398
|
+
var name92 = "AI_NoOutputGeneratedError";
|
|
4399
|
+
var marker92 = `vercel.ai.error.${name92}`;
|
|
4400
|
+
var symbol92 = Symbol.for(marker92);
|
|
4401
|
+
var _a92;
|
|
3995
4402
|
var NoOutputGeneratedError = class extends AISDKError {
|
|
3996
4403
|
// used in isInstance
|
|
3997
4404
|
constructor({
|
|
3998
4405
|
message = "No output generated.",
|
|
3999
4406
|
cause
|
|
4000
4407
|
} = {}) {
|
|
4001
|
-
super({ name:
|
|
4002
|
-
this[
|
|
4408
|
+
super({ name: name92, message, cause });
|
|
4409
|
+
this[_a92] = true;
|
|
4003
4410
|
}
|
|
4004
4411
|
static isInstance(error) {
|
|
4005
|
-
return AISDKError.hasMarker(error,
|
|
4412
|
+
return AISDKError.hasMarker(error, marker92);
|
|
4006
4413
|
}
|
|
4007
4414
|
};
|
|
4008
|
-
|
|
4009
|
-
var
|
|
4010
|
-
var
|
|
4011
|
-
var
|
|
4012
|
-
var
|
|
4415
|
+
_a92 = symbol92;
|
|
4416
|
+
var name132 = "AI_NoSuchToolError";
|
|
4417
|
+
var marker132 = `vercel.ai.error.${name132}`;
|
|
4418
|
+
var symbol132 = Symbol.for(marker132);
|
|
4419
|
+
var _a132;
|
|
4013
4420
|
var NoSuchToolError = class extends AISDKError {
|
|
4014
4421
|
constructor({
|
|
4015
4422
|
toolName,
|
|
4016
4423
|
availableTools = void 0,
|
|
4017
4424
|
message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === void 0 ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
|
|
4018
4425
|
}) {
|
|
4019
|
-
super({ name:
|
|
4020
|
-
this[
|
|
4426
|
+
super({ name: name132, message });
|
|
4427
|
+
this[_a132] = true;
|
|
4021
4428
|
this.toolName = toolName;
|
|
4022
4429
|
this.availableTools = availableTools;
|
|
4023
4430
|
}
|
|
4024
4431
|
static isInstance(error) {
|
|
4025
|
-
return AISDKError.hasMarker(error,
|
|
4432
|
+
return AISDKError.hasMarker(error, marker132);
|
|
4026
4433
|
}
|
|
4027
4434
|
};
|
|
4028
|
-
|
|
4029
|
-
var
|
|
4030
|
-
var
|
|
4031
|
-
var
|
|
4032
|
-
var
|
|
4435
|
+
_a132 = symbol132;
|
|
4436
|
+
var name142 = "AI_ToolCallRepairError";
|
|
4437
|
+
var marker142 = `vercel.ai.error.${name142}`;
|
|
4438
|
+
var symbol142 = Symbol.for(marker142);
|
|
4439
|
+
var _a142;
|
|
4033
4440
|
var ToolCallRepairError = class extends AISDKError {
|
|
4034
4441
|
constructor({
|
|
4035
4442
|
cause,
|
|
4036
4443
|
originalError,
|
|
4037
4444
|
message = `Error repairing tool call: ${getErrorMessage(cause)}`
|
|
4038
4445
|
}) {
|
|
4039
|
-
super({ name:
|
|
4040
|
-
this[
|
|
4446
|
+
super({ name: name142, message, cause });
|
|
4447
|
+
this[_a142] = true;
|
|
4041
4448
|
this.originalError = originalError;
|
|
4042
4449
|
}
|
|
4043
4450
|
static isInstance(error) {
|
|
4044
|
-
return AISDKError.hasMarker(error,
|
|
4451
|
+
return AISDKError.hasMarker(error, marker142);
|
|
4045
4452
|
}
|
|
4046
4453
|
};
|
|
4047
|
-
|
|
4454
|
+
_a142 = symbol142;
|
|
4048
4455
|
var UnsupportedModelVersionError = class extends AISDKError {
|
|
4049
4456
|
constructor(options) {
|
|
4050
4457
|
super({
|
|
@@ -4056,45 +4463,65 @@ var UnsupportedModelVersionError = class extends AISDKError {
|
|
|
4056
4463
|
this.modelId = options.modelId;
|
|
4057
4464
|
}
|
|
4058
4465
|
};
|
|
4059
|
-
var
|
|
4060
|
-
var
|
|
4061
|
-
var
|
|
4062
|
-
var
|
|
4466
|
+
var name152 = "AI_UIMessageStreamError";
|
|
4467
|
+
var marker152 = `vercel.ai.error.${name152}`;
|
|
4468
|
+
var symbol152 = Symbol.for(marker152);
|
|
4469
|
+
var _a152;
|
|
4470
|
+
var UIMessageStreamError = class extends AISDKError {
|
|
4471
|
+
constructor({
|
|
4472
|
+
chunkType,
|
|
4473
|
+
chunkId,
|
|
4474
|
+
message
|
|
4475
|
+
}) {
|
|
4476
|
+
super({ name: name152, message });
|
|
4477
|
+
this[_a152] = true;
|
|
4478
|
+
this.chunkType = chunkType;
|
|
4479
|
+
this.chunkId = chunkId;
|
|
4480
|
+
}
|
|
4481
|
+
static isInstance(error) {
|
|
4482
|
+
return AISDKError.hasMarker(error, marker152);
|
|
4483
|
+
}
|
|
4484
|
+
};
|
|
4485
|
+
_a152 = symbol152;
|
|
4486
|
+
var name17 = "AI_InvalidMessageRoleError";
|
|
4487
|
+
var marker17 = `vercel.ai.error.${name17}`;
|
|
4488
|
+
var symbol17 = Symbol.for(marker17);
|
|
4489
|
+
var _a17;
|
|
4063
4490
|
var InvalidMessageRoleError = class extends AISDKError {
|
|
4064
4491
|
constructor({
|
|
4065
4492
|
role,
|
|
4066
4493
|
message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
|
|
4067
4494
|
}) {
|
|
4068
|
-
super({ name:
|
|
4069
|
-
this[
|
|
4495
|
+
super({ name: name17, message });
|
|
4496
|
+
this[_a17] = true;
|
|
4070
4497
|
this.role = role;
|
|
4071
4498
|
}
|
|
4072
4499
|
static isInstance(error) {
|
|
4073
|
-
return AISDKError.hasMarker(error,
|
|
4500
|
+
return AISDKError.hasMarker(error, marker17);
|
|
4074
4501
|
}
|
|
4075
4502
|
};
|
|
4076
|
-
|
|
4077
|
-
var
|
|
4078
|
-
var
|
|
4079
|
-
var
|
|
4080
|
-
var
|
|
4503
|
+
_a17 = symbol17;
|
|
4504
|
+
var name19 = "AI_RetryError";
|
|
4505
|
+
var marker19 = `vercel.ai.error.${name19}`;
|
|
4506
|
+
var symbol19 = Symbol.for(marker19);
|
|
4507
|
+
var _a19;
|
|
4081
4508
|
var RetryError = class extends AISDKError {
|
|
4082
4509
|
constructor({
|
|
4083
4510
|
message,
|
|
4084
4511
|
reason,
|
|
4085
4512
|
errors
|
|
4086
4513
|
}) {
|
|
4087
|
-
super({ name:
|
|
4088
|
-
this[
|
|
4514
|
+
super({ name: name19, message });
|
|
4515
|
+
this[_a19] = true;
|
|
4089
4516
|
this.reason = reason;
|
|
4090
4517
|
this.errors = errors;
|
|
4091
4518
|
this.lastError = errors[errors.length - 1];
|
|
4092
4519
|
}
|
|
4093
4520
|
static isInstance(error) {
|
|
4094
|
-
return AISDKError.hasMarker(error,
|
|
4521
|
+
return AISDKError.hasMarker(error, marker19);
|
|
4095
4522
|
}
|
|
4096
4523
|
};
|
|
4097
|
-
|
|
4524
|
+
_a19 = symbol19;
|
|
4098
4525
|
function formatWarning({
|
|
4099
4526
|
warning,
|
|
4100
4527
|
provider,
|
|
@@ -4290,8 +4717,29 @@ function resolveEmbeddingModel(model) {
|
|
|
4290
4717
|
return getGlobalProvider().embeddingModel(model);
|
|
4291
4718
|
}
|
|
4292
4719
|
function getGlobalProvider() {
|
|
4293
|
-
var
|
|
4294
|
-
return (
|
|
4720
|
+
var _a21;
|
|
4721
|
+
return (_a21 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a21 : gateway;
|
|
4722
|
+
}
|
|
4723
|
+
function getTotalTimeoutMs(timeout) {
|
|
4724
|
+
if (timeout == null) {
|
|
4725
|
+
return void 0;
|
|
4726
|
+
}
|
|
4727
|
+
if (typeof timeout === "number") {
|
|
4728
|
+
return timeout;
|
|
4729
|
+
}
|
|
4730
|
+
return timeout.totalMs;
|
|
4731
|
+
}
|
|
4732
|
+
function getStepTimeoutMs(timeout) {
|
|
4733
|
+
if (timeout == null || typeof timeout === "number") {
|
|
4734
|
+
return void 0;
|
|
4735
|
+
}
|
|
4736
|
+
return timeout.stepMs;
|
|
4737
|
+
}
|
|
4738
|
+
function getChunkTimeoutMs(timeout) {
|
|
4739
|
+
if (timeout == null || typeof timeout === "number") {
|
|
4740
|
+
return void 0;
|
|
4741
|
+
}
|
|
4742
|
+
return timeout.chunkMs;
|
|
4295
4743
|
}
|
|
4296
4744
|
var imageMediaTypeSignatures = [
|
|
4297
4745
|
{
|
|
@@ -4404,9 +4852,9 @@ function detectMediaType({
|
|
|
4404
4852
|
}
|
|
4405
4853
|
return void 0;
|
|
4406
4854
|
}
|
|
4407
|
-
var VERSION3 = "6.0.
|
|
4855
|
+
var VERSION3 = "6.0.69";
|
|
4408
4856
|
var download = async ({ url }) => {
|
|
4409
|
-
var
|
|
4857
|
+
var _a21;
|
|
4410
4858
|
const urlText = url.toString();
|
|
4411
4859
|
try {
|
|
4412
4860
|
const response = await fetch(urlText, {
|
|
@@ -4425,7 +4873,7 @@ var download = async ({ url }) => {
|
|
|
4425
4873
|
}
|
|
4426
4874
|
return {
|
|
4427
4875
|
data: new Uint8Array(await response.arrayBuffer()),
|
|
4428
|
-
mediaType: (
|
|
4876
|
+
mediaType: (_a21 = response.headers.get("content-type")) != null ? _a21 : void 0
|
|
4429
4877
|
};
|
|
4430
4878
|
} catch (error) {
|
|
4431
4879
|
if (DownloadError.isInstance(error)) {
|
|
@@ -4460,8 +4908,8 @@ var dataContentSchema = z4.z.union([
|
|
|
4460
4908
|
z4.z.custom(
|
|
4461
4909
|
// Buffer might not be available in some environments such as CloudFlare:
|
|
4462
4910
|
(value) => {
|
|
4463
|
-
var
|
|
4464
|
-
return (_b82 = (
|
|
4911
|
+
var _a21, _b82;
|
|
4912
|
+
return (_b82 = (_a21 = globalThis.Buffer) == null ? void 0 : _a21.isBuffer(value)) != null ? _b82 : false;
|
|
4465
4913
|
},
|
|
4466
4914
|
{ message: "Must be a Buffer" }
|
|
4467
4915
|
)
|
|
@@ -4515,6 +4963,32 @@ async function convertToLanguageModelPrompt({
|
|
|
4515
4963
|
download2,
|
|
4516
4964
|
supportedUrls
|
|
4517
4965
|
);
|
|
4966
|
+
const approvalIdToToolCallId = /* @__PURE__ */ new Map();
|
|
4967
|
+
for (const message of prompt.messages) {
|
|
4968
|
+
if (message.role === "assistant" && Array.isArray(message.content)) {
|
|
4969
|
+
for (const part of message.content) {
|
|
4970
|
+
if (part.type === "tool-approval-request" && "approvalId" in part && "toolCallId" in part) {
|
|
4971
|
+
approvalIdToToolCallId.set(
|
|
4972
|
+
part.approvalId,
|
|
4973
|
+
part.toolCallId
|
|
4974
|
+
);
|
|
4975
|
+
}
|
|
4976
|
+
}
|
|
4977
|
+
}
|
|
4978
|
+
}
|
|
4979
|
+
const approvedToolCallIds = /* @__PURE__ */ new Set();
|
|
4980
|
+
for (const message of prompt.messages) {
|
|
4981
|
+
if (message.role === "tool") {
|
|
4982
|
+
for (const part of message.content) {
|
|
4983
|
+
if (part.type === "tool-approval-response") {
|
|
4984
|
+
const toolCallId = approvalIdToToolCallId.get(part.approvalId);
|
|
4985
|
+
if (toolCallId) {
|
|
4986
|
+
approvedToolCallIds.add(toolCallId);
|
|
4987
|
+
}
|
|
4988
|
+
}
|
|
4989
|
+
}
|
|
4990
|
+
}
|
|
4991
|
+
}
|
|
4518
4992
|
const messages = [
|
|
4519
4993
|
...prompt.system != null ? typeof prompt.system === "string" ? [{ role: "system", content: prompt.system }] : asArray(prompt.system).map((message) => ({
|
|
4520
4994
|
role: "system",
|
|
@@ -4538,23 +5012,67 @@ async function convertToLanguageModelPrompt({
|
|
|
4538
5012
|
combinedMessages.push(message);
|
|
4539
5013
|
}
|
|
4540
5014
|
}
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
5015
|
+
const toolCallIds = /* @__PURE__ */ new Set();
|
|
5016
|
+
for (const message of combinedMessages) {
|
|
5017
|
+
switch (message.role) {
|
|
5018
|
+
case "assistant": {
|
|
5019
|
+
for (const content of message.content) {
|
|
5020
|
+
if (content.type === "tool-call" && !content.providerExecuted) {
|
|
5021
|
+
toolCallIds.add(content.toolCallId);
|
|
5022
|
+
}
|
|
5023
|
+
}
|
|
5024
|
+
break;
|
|
5025
|
+
}
|
|
5026
|
+
case "tool": {
|
|
5027
|
+
for (const content of message.content) {
|
|
5028
|
+
if (content.type === "tool-result") {
|
|
5029
|
+
toolCallIds.delete(content.toolCallId);
|
|
5030
|
+
}
|
|
5031
|
+
}
|
|
5032
|
+
break;
|
|
5033
|
+
}
|
|
5034
|
+
case "user":
|
|
5035
|
+
case "system":
|
|
5036
|
+
for (const id of approvedToolCallIds) {
|
|
5037
|
+
toolCallIds.delete(id);
|
|
5038
|
+
}
|
|
5039
|
+
if (toolCallIds.size > 0) {
|
|
5040
|
+
throw new MissingToolResultsError({
|
|
5041
|
+
toolCallIds: Array.from(toolCallIds)
|
|
5042
|
+
});
|
|
5043
|
+
}
|
|
5044
|
+
break;
|
|
5045
|
+
}
|
|
5046
|
+
}
|
|
5047
|
+
for (const id of approvedToolCallIds) {
|
|
5048
|
+
toolCallIds.delete(id);
|
|
5049
|
+
}
|
|
5050
|
+
if (toolCallIds.size > 0) {
|
|
5051
|
+
throw new MissingToolResultsError({ toolCallIds: Array.from(toolCallIds) });
|
|
5052
|
+
}
|
|
5053
|
+
return combinedMessages.filter(
|
|
5054
|
+
// Filter out empty tool messages (e.g. if they only contained
|
|
5055
|
+
// tool-approval-response parts that were removed).
|
|
5056
|
+
// This prevents sending invalid empty messages to the provider.
|
|
5057
|
+
// Note: provider-executed tool-approval-response parts are preserved.
|
|
5058
|
+
(message) => message.role !== "tool" || message.content.length > 0
|
|
5059
|
+
);
|
|
5060
|
+
}
|
|
5061
|
+
function convertToLanguageModelMessage({
|
|
5062
|
+
message,
|
|
5063
|
+
downloadedAssets
|
|
5064
|
+
}) {
|
|
5065
|
+
const role = message.role;
|
|
5066
|
+
switch (role) {
|
|
5067
|
+
case "system": {
|
|
5068
|
+
return {
|
|
5069
|
+
role: "system",
|
|
5070
|
+
content: message.content,
|
|
5071
|
+
providerOptions: message.providerOptions
|
|
5072
|
+
};
|
|
5073
|
+
}
|
|
5074
|
+
case "user": {
|
|
5075
|
+
if (typeof message.content === "string") {
|
|
4558
5076
|
return {
|
|
4559
5077
|
role: "user",
|
|
4560
5078
|
content: [{ type: "text", text: message.content }],
|
|
@@ -4638,13 +5156,30 @@ function convertToLanguageModelMessage({
|
|
|
4638
5156
|
case "tool": {
|
|
4639
5157
|
return {
|
|
4640
5158
|
role: "tool",
|
|
4641
|
-
content: message.content.filter(
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
5159
|
+
content: message.content.filter(
|
|
5160
|
+
// Only include tool-approval-response for provider-executed tools
|
|
5161
|
+
(part) => part.type !== "tool-approval-response" || part.providerExecuted
|
|
5162
|
+
).map((part) => {
|
|
5163
|
+
switch (part.type) {
|
|
5164
|
+
case "tool-result": {
|
|
5165
|
+
return {
|
|
5166
|
+
type: "tool-result",
|
|
5167
|
+
toolCallId: part.toolCallId,
|
|
5168
|
+
toolName: part.toolName,
|
|
5169
|
+
output: mapToolResultOutput(part.output),
|
|
5170
|
+
providerOptions: part.providerOptions
|
|
5171
|
+
};
|
|
5172
|
+
}
|
|
5173
|
+
case "tool-approval-response": {
|
|
5174
|
+
return {
|
|
5175
|
+
type: "tool-approval-response",
|
|
5176
|
+
approvalId: part.approvalId,
|
|
5177
|
+
approved: part.approved,
|
|
5178
|
+
reason: part.reason
|
|
5179
|
+
};
|
|
5180
|
+
}
|
|
5181
|
+
}
|
|
5182
|
+
}),
|
|
4648
5183
|
providerOptions: message.providerOptions
|
|
4649
5184
|
};
|
|
4650
5185
|
}
|
|
@@ -4660,8 +5195,8 @@ async function downloadAssets(messages, download2, supportedUrls) {
|
|
|
4660
5195
|
).flat().filter(
|
|
4661
5196
|
(part) => part.type === "image" || part.type === "file"
|
|
4662
5197
|
).map((part) => {
|
|
4663
|
-
var
|
|
4664
|
-
const mediaType = (
|
|
5198
|
+
var _a21;
|
|
5199
|
+
const mediaType = (_a21 = part.mediaType) != null ? _a21 : part.type === "image" ? "image/*" : void 0;
|
|
4665
5200
|
let data = part.type === "image" ? part.image : part.data;
|
|
4666
5201
|
if (typeof data === "string") {
|
|
4667
5202
|
try {
|
|
@@ -4691,7 +5226,7 @@ async function downloadAssets(messages, download2, supportedUrls) {
|
|
|
4691
5226
|
);
|
|
4692
5227
|
}
|
|
4693
5228
|
function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
4694
|
-
var
|
|
5229
|
+
var _a21;
|
|
4695
5230
|
if (part.type === "text") {
|
|
4696
5231
|
return {
|
|
4697
5232
|
type: "text",
|
|
@@ -4724,7 +5259,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
|
4724
5259
|
switch (type) {
|
|
4725
5260
|
case "image": {
|
|
4726
5261
|
if (data instanceof Uint8Array || typeof data === "string") {
|
|
4727
|
-
mediaType = (
|
|
5262
|
+
mediaType = (_a21 = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _a21 : mediaType;
|
|
4728
5263
|
}
|
|
4729
5264
|
return {
|
|
4730
5265
|
type: "file",
|
|
@@ -4900,10 +5435,10 @@ async function prepareToolsAndToolChoice({
|
|
|
4900
5435
|
};
|
|
4901
5436
|
}
|
|
4902
5437
|
const filteredTools = activeTools != null ? Object.entries(tools).filter(
|
|
4903
|
-
([
|
|
5438
|
+
([name21]) => activeTools.includes(name21)
|
|
4904
5439
|
) : Object.entries(tools);
|
|
4905
5440
|
const languageModelTools = [];
|
|
4906
|
-
for (const [
|
|
5441
|
+
for (const [name21, tool2] of filteredTools) {
|
|
4907
5442
|
const toolType = tool2.type;
|
|
4908
5443
|
switch (toolType) {
|
|
4909
5444
|
case void 0:
|
|
@@ -4911,7 +5446,7 @@ async function prepareToolsAndToolChoice({
|
|
|
4911
5446
|
case "function":
|
|
4912
5447
|
languageModelTools.push({
|
|
4913
5448
|
type: "function",
|
|
4914
|
-
name:
|
|
5449
|
+
name: name21,
|
|
4915
5450
|
description: tool2.description,
|
|
4916
5451
|
inputSchema: await asSchema(tool2.inputSchema).jsonSchema,
|
|
4917
5452
|
...tool2.inputExamples != null ? { inputExamples: tool2.inputExamples } : {},
|
|
@@ -4922,7 +5457,7 @@ async function prepareToolsAndToolChoice({
|
|
|
4922
5457
|
case "provider":
|
|
4923
5458
|
languageModelTools.push({
|
|
4924
5459
|
type: "provider",
|
|
4925
|
-
name:
|
|
5460
|
+
name: name21,
|
|
4926
5461
|
id: tool2.id,
|
|
4927
5462
|
args: tool2.args
|
|
4928
5463
|
});
|
|
@@ -5227,17 +5762,26 @@ function getBaseTelemetryAttributes({
|
|
|
5227
5762
|
telemetry,
|
|
5228
5763
|
headers
|
|
5229
5764
|
}) {
|
|
5230
|
-
var
|
|
5765
|
+
var _a21;
|
|
5231
5766
|
return {
|
|
5232
5767
|
"ai.model.provider": model.provider,
|
|
5233
5768
|
"ai.model.id": model.modelId,
|
|
5234
5769
|
// settings:
|
|
5235
5770
|
...Object.entries(settings).reduce((attributes, [key, value]) => {
|
|
5236
|
-
|
|
5771
|
+
if (key === "timeout") {
|
|
5772
|
+
const totalTimeoutMs = getTotalTimeoutMs(
|
|
5773
|
+
value
|
|
5774
|
+
);
|
|
5775
|
+
if (totalTimeoutMs != null) {
|
|
5776
|
+
attributes[`ai.settings.${key}`] = totalTimeoutMs;
|
|
5777
|
+
}
|
|
5778
|
+
} else {
|
|
5779
|
+
attributes[`ai.settings.${key}`] = value;
|
|
5780
|
+
}
|
|
5237
5781
|
return attributes;
|
|
5238
5782
|
}, {}),
|
|
5239
5783
|
// add metadata as attributes:
|
|
5240
|
-
...Object.entries((
|
|
5784
|
+
...Object.entries((_a21 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a21 : {}).reduce(
|
|
5241
5785
|
(attributes, [key, value]) => {
|
|
5242
5786
|
attributes[`ai.telemetry.metadata.${key}`] = value;
|
|
5243
5787
|
return attributes;
|
|
@@ -5257,7 +5801,7 @@ var noopTracer = {
|
|
|
5257
5801
|
startSpan() {
|
|
5258
5802
|
return noopSpan;
|
|
5259
5803
|
},
|
|
5260
|
-
startActiveSpan(
|
|
5804
|
+
startActiveSpan(name21, arg1, arg2, arg3) {
|
|
5261
5805
|
if (typeof arg1 === "function") {
|
|
5262
5806
|
return arg1(noopSpan);
|
|
5263
5807
|
}
|
|
@@ -5322,18 +5866,19 @@ function getTracer({
|
|
|
5322
5866
|
return trace.getTracer("ai");
|
|
5323
5867
|
}
|
|
5324
5868
|
async function recordSpan({
|
|
5325
|
-
name:
|
|
5869
|
+
name: name21,
|
|
5326
5870
|
tracer,
|
|
5327
5871
|
attributes,
|
|
5328
5872
|
fn,
|
|
5329
5873
|
endWhenDone = true
|
|
5330
5874
|
}) {
|
|
5331
5875
|
return tracer.startActiveSpan(
|
|
5332
|
-
|
|
5876
|
+
name21,
|
|
5333
5877
|
{ attributes: await attributes },
|
|
5334
5878
|
async (span) => {
|
|
5879
|
+
const ctx = context.active();
|
|
5335
5880
|
try {
|
|
5336
|
-
const result = await fn(span);
|
|
5881
|
+
const result = await context.with(ctx, () => fn(span));
|
|
5337
5882
|
if (endWhenDone) {
|
|
5338
5883
|
span.end();
|
|
5339
5884
|
}
|
|
@@ -5453,12 +5998,12 @@ function createNullLanguageModelUsage() {
|
|
|
5453
5998
|
};
|
|
5454
5999
|
}
|
|
5455
6000
|
function addLanguageModelUsage(usage1, usage2) {
|
|
5456
|
-
var
|
|
6001
|
+
var _a21, _b82, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
5457
6002
|
return {
|
|
5458
6003
|
inputTokens: addTokenCounts(usage1.inputTokens, usage2.inputTokens),
|
|
5459
6004
|
inputTokenDetails: {
|
|
5460
6005
|
noCacheTokens: addTokenCounts(
|
|
5461
|
-
(
|
|
6006
|
+
(_a21 = usage1.inputTokenDetails) == null ? void 0 : _a21.noCacheTokens,
|
|
5462
6007
|
(_b82 = usage2.inputTokenDetails) == null ? void 0 : _b82.noCacheTokens
|
|
5463
6008
|
),
|
|
5464
6009
|
cacheReadTokens: addTokenCounts(
|
|
@@ -5694,13 +6239,25 @@ function collectToolApprovals({
|
|
|
5694
6239
|
);
|
|
5695
6240
|
for (const approvalResponse of approvalResponses) {
|
|
5696
6241
|
const approvalRequest = toolApprovalRequestsByApprovalId[approvalResponse.approvalId];
|
|
6242
|
+
if (approvalRequest == null) {
|
|
6243
|
+
throw new InvalidToolApprovalError({
|
|
6244
|
+
approvalId: approvalResponse.approvalId
|
|
6245
|
+
});
|
|
6246
|
+
}
|
|
5697
6247
|
if (toolResults[approvalRequest.toolCallId] != null) {
|
|
5698
6248
|
continue;
|
|
5699
6249
|
}
|
|
6250
|
+
const toolCall = toolCallsByToolCallId[approvalRequest.toolCallId];
|
|
6251
|
+
if (toolCall == null) {
|
|
6252
|
+
throw new ToolCallNotFoundForApprovalError({
|
|
6253
|
+
toolCallId: approvalRequest.toolCallId,
|
|
6254
|
+
approvalId: approvalRequest.approvalId
|
|
6255
|
+
});
|
|
6256
|
+
}
|
|
5700
6257
|
const approval = {
|
|
5701
6258
|
approvalRequest,
|
|
5702
6259
|
approvalResponse,
|
|
5703
|
-
toolCall
|
|
6260
|
+
toolCall
|
|
5704
6261
|
};
|
|
5705
6262
|
if (approvalResponse.approved) {
|
|
5706
6263
|
approvedToolApprovals.push(approval);
|
|
@@ -6201,37 +6758,42 @@ async function parsePartialJson(jsonText) {
|
|
|
6201
6758
|
return { value: void 0, state: "failed-parse" };
|
|
6202
6759
|
}
|
|
6203
6760
|
var text = () => ({
|
|
6761
|
+
name: "text",
|
|
6204
6762
|
responseFormat: Promise.resolve({ type: "text" }),
|
|
6205
6763
|
async parseCompleteOutput({ text: text2 }) {
|
|
6206
6764
|
return text2;
|
|
6207
6765
|
},
|
|
6208
6766
|
async parsePartialOutput({ text: text2 }) {
|
|
6209
6767
|
return { partial: text2 };
|
|
6768
|
+
},
|
|
6769
|
+
createElementStreamTransform() {
|
|
6770
|
+
return void 0;
|
|
6210
6771
|
}
|
|
6211
6772
|
});
|
|
6212
6773
|
var object = ({
|
|
6213
6774
|
schema: inputSchema,
|
|
6214
|
-
name:
|
|
6775
|
+
name: name21,
|
|
6215
6776
|
description
|
|
6216
6777
|
}) => {
|
|
6217
6778
|
const schema = asSchema(inputSchema);
|
|
6218
6779
|
return {
|
|
6780
|
+
name: "object",
|
|
6219
6781
|
responseFormat: resolve(schema.jsonSchema).then((jsonSchema2) => ({
|
|
6220
6782
|
type: "json",
|
|
6221
6783
|
schema: jsonSchema2,
|
|
6222
|
-
...
|
|
6784
|
+
...name21 != null && { name: name21 },
|
|
6223
6785
|
...description != null && { description }
|
|
6224
6786
|
})),
|
|
6225
|
-
async parseCompleteOutput({ text: text2 },
|
|
6787
|
+
async parseCompleteOutput({ text: text2 }, context2) {
|
|
6226
6788
|
const parseResult = await safeParseJSON({ text: text2 });
|
|
6227
6789
|
if (!parseResult.success) {
|
|
6228
6790
|
throw new NoObjectGeneratedError({
|
|
6229
6791
|
message: "No object generated: could not parse the response.",
|
|
6230
6792
|
cause: parseResult.error,
|
|
6231
6793
|
text: text2,
|
|
6232
|
-
response:
|
|
6233
|
-
usage:
|
|
6234
|
-
finishReason:
|
|
6794
|
+
response: context2.response,
|
|
6795
|
+
usage: context2.usage,
|
|
6796
|
+
finishReason: context2.finishReason
|
|
6235
6797
|
});
|
|
6236
6798
|
}
|
|
6237
6799
|
const validationResult = await safeValidateTypes({
|
|
@@ -6243,9 +6805,9 @@ var object = ({
|
|
|
6243
6805
|
message: "No object generated: response did not match schema.",
|
|
6244
6806
|
cause: validationResult.error,
|
|
6245
6807
|
text: text2,
|
|
6246
|
-
response:
|
|
6247
|
-
usage:
|
|
6248
|
-
finishReason:
|
|
6808
|
+
response: context2.response,
|
|
6809
|
+
usage: context2.usage,
|
|
6810
|
+
finishReason: context2.finishReason
|
|
6249
6811
|
});
|
|
6250
6812
|
}
|
|
6251
6813
|
return validationResult.value;
|
|
@@ -6265,16 +6827,20 @@ var object = ({
|
|
|
6265
6827
|
};
|
|
6266
6828
|
}
|
|
6267
6829
|
}
|
|
6830
|
+
},
|
|
6831
|
+
createElementStreamTransform() {
|
|
6832
|
+
return void 0;
|
|
6268
6833
|
}
|
|
6269
6834
|
};
|
|
6270
6835
|
};
|
|
6271
6836
|
var array = ({
|
|
6272
6837
|
element: inputElementSchema,
|
|
6273
|
-
name:
|
|
6838
|
+
name: name21,
|
|
6274
6839
|
description
|
|
6275
6840
|
}) => {
|
|
6276
6841
|
const elementSchema = asSchema(inputElementSchema);
|
|
6277
6842
|
return {
|
|
6843
|
+
name: "array",
|
|
6278
6844
|
// JSON schema that describes an array of elements:
|
|
6279
6845
|
responseFormat: resolve(elementSchema.jsonSchema).then((jsonSchema2) => {
|
|
6280
6846
|
const { $schema, ...itemSchema } = jsonSchema2;
|
|
@@ -6289,20 +6855,20 @@ var array = ({
|
|
|
6289
6855
|
required: ["elements"],
|
|
6290
6856
|
additionalProperties: false
|
|
6291
6857
|
},
|
|
6292
|
-
...
|
|
6858
|
+
...name21 != null && { name: name21 },
|
|
6293
6859
|
...description != null && { description }
|
|
6294
6860
|
};
|
|
6295
6861
|
}),
|
|
6296
|
-
async parseCompleteOutput({ text: text2 },
|
|
6862
|
+
async parseCompleteOutput({ text: text2 }, context2) {
|
|
6297
6863
|
const parseResult = await safeParseJSON({ text: text2 });
|
|
6298
6864
|
if (!parseResult.success) {
|
|
6299
6865
|
throw new NoObjectGeneratedError({
|
|
6300
6866
|
message: "No object generated: could not parse the response.",
|
|
6301
6867
|
cause: parseResult.error,
|
|
6302
6868
|
text: text2,
|
|
6303
|
-
response:
|
|
6304
|
-
usage:
|
|
6305
|
-
finishReason:
|
|
6869
|
+
response: context2.response,
|
|
6870
|
+
usage: context2.usage,
|
|
6871
|
+
finishReason: context2.finishReason
|
|
6306
6872
|
});
|
|
6307
6873
|
}
|
|
6308
6874
|
const outerValue = parseResult.value;
|
|
@@ -6314,9 +6880,9 @@ var array = ({
|
|
|
6314
6880
|
cause: "response must be an object with an elements array"
|
|
6315
6881
|
}),
|
|
6316
6882
|
text: text2,
|
|
6317
|
-
response:
|
|
6318
|
-
usage:
|
|
6319
|
-
finishReason:
|
|
6883
|
+
response: context2.response,
|
|
6884
|
+
usage: context2.usage,
|
|
6885
|
+
finishReason: context2.finishReason
|
|
6320
6886
|
});
|
|
6321
6887
|
}
|
|
6322
6888
|
for (const element of outerValue.elements) {
|
|
@@ -6329,9 +6895,9 @@ var array = ({
|
|
|
6329
6895
|
message: "No object generated: response did not match schema.",
|
|
6330
6896
|
cause: validationResult.error,
|
|
6331
6897
|
text: text2,
|
|
6332
|
-
response:
|
|
6333
|
-
usage:
|
|
6334
|
-
finishReason:
|
|
6898
|
+
response: context2.response,
|
|
6899
|
+
usage: context2.usage,
|
|
6900
|
+
finishReason: context2.finishReason
|
|
6335
6901
|
});
|
|
6336
6902
|
}
|
|
6337
6903
|
}
|
|
@@ -6364,15 +6930,28 @@ var array = ({
|
|
|
6364
6930
|
return { partial: parsedElements };
|
|
6365
6931
|
}
|
|
6366
6932
|
}
|
|
6933
|
+
},
|
|
6934
|
+
createElementStreamTransform() {
|
|
6935
|
+
let publishedElements = 0;
|
|
6936
|
+
return new TransformStream({
|
|
6937
|
+
transform({ partialOutput }, controller) {
|
|
6938
|
+
if (partialOutput != null) {
|
|
6939
|
+
for (; publishedElements < partialOutput.length; publishedElements++) {
|
|
6940
|
+
controller.enqueue(partialOutput[publishedElements]);
|
|
6941
|
+
}
|
|
6942
|
+
}
|
|
6943
|
+
}
|
|
6944
|
+
});
|
|
6367
6945
|
}
|
|
6368
6946
|
};
|
|
6369
6947
|
};
|
|
6370
6948
|
var choice = ({
|
|
6371
6949
|
options: choiceOptions,
|
|
6372
|
-
name:
|
|
6950
|
+
name: name21,
|
|
6373
6951
|
description
|
|
6374
6952
|
}) => {
|
|
6375
6953
|
return {
|
|
6954
|
+
name: "choice",
|
|
6376
6955
|
// JSON schema that describes an enumeration:
|
|
6377
6956
|
responseFormat: Promise.resolve({
|
|
6378
6957
|
type: "json",
|
|
@@ -6385,19 +6964,19 @@ var choice = ({
|
|
|
6385
6964
|
required: ["result"],
|
|
6386
6965
|
additionalProperties: false
|
|
6387
6966
|
},
|
|
6388
|
-
...
|
|
6967
|
+
...name21 != null && { name: name21 },
|
|
6389
6968
|
...description != null && { description }
|
|
6390
6969
|
}),
|
|
6391
|
-
async parseCompleteOutput({ text: text2 },
|
|
6970
|
+
async parseCompleteOutput({ text: text2 }, context2) {
|
|
6392
6971
|
const parseResult = await safeParseJSON({ text: text2 });
|
|
6393
6972
|
if (!parseResult.success) {
|
|
6394
6973
|
throw new NoObjectGeneratedError({
|
|
6395
6974
|
message: "No object generated: could not parse the response.",
|
|
6396
6975
|
cause: parseResult.error,
|
|
6397
6976
|
text: text2,
|
|
6398
|
-
response:
|
|
6399
|
-
usage:
|
|
6400
|
-
finishReason:
|
|
6977
|
+
response: context2.response,
|
|
6978
|
+
usage: context2.usage,
|
|
6979
|
+
finishReason: context2.finishReason
|
|
6401
6980
|
});
|
|
6402
6981
|
}
|
|
6403
6982
|
const outerValue = parseResult.value;
|
|
@@ -6409,9 +6988,9 @@ var choice = ({
|
|
|
6409
6988
|
cause: "response must be an object that contains a choice value."
|
|
6410
6989
|
}),
|
|
6411
6990
|
text: text2,
|
|
6412
|
-
response:
|
|
6413
|
-
usage:
|
|
6414
|
-
finishReason:
|
|
6991
|
+
response: context2.response,
|
|
6992
|
+
usage: context2.usage,
|
|
6993
|
+
finishReason: context2.finishReason
|
|
6415
6994
|
});
|
|
6416
6995
|
}
|
|
6417
6996
|
return outerValue.result;
|
|
@@ -6439,29 +7018,33 @@ var choice = ({
|
|
|
6439
7018
|
}
|
|
6440
7019
|
}
|
|
6441
7020
|
}
|
|
7021
|
+
},
|
|
7022
|
+
createElementStreamTransform() {
|
|
7023
|
+
return void 0;
|
|
6442
7024
|
}
|
|
6443
7025
|
};
|
|
6444
7026
|
};
|
|
6445
7027
|
var json = ({
|
|
6446
|
-
name:
|
|
7028
|
+
name: name21,
|
|
6447
7029
|
description
|
|
6448
7030
|
} = {}) => {
|
|
6449
7031
|
return {
|
|
7032
|
+
name: "json",
|
|
6450
7033
|
responseFormat: Promise.resolve({
|
|
6451
7034
|
type: "json",
|
|
6452
|
-
...
|
|
7035
|
+
...name21 != null && { name: name21 },
|
|
6453
7036
|
...description != null && { description }
|
|
6454
7037
|
}),
|
|
6455
|
-
async parseCompleteOutput({ text: text2 },
|
|
7038
|
+
async parseCompleteOutput({ text: text2 }, context2) {
|
|
6456
7039
|
const parseResult = await safeParseJSON({ text: text2 });
|
|
6457
7040
|
if (!parseResult.success) {
|
|
6458
7041
|
throw new NoObjectGeneratedError({
|
|
6459
7042
|
message: "No object generated: could not parse the response.",
|
|
6460
7043
|
cause: parseResult.error,
|
|
6461
7044
|
text: text2,
|
|
6462
|
-
response:
|
|
6463
|
-
usage:
|
|
6464
|
-
finishReason:
|
|
7045
|
+
response: context2.response,
|
|
7046
|
+
usage: context2.usage,
|
|
7047
|
+
finishReason: context2.finishReason
|
|
6465
7048
|
});
|
|
6466
7049
|
}
|
|
6467
7050
|
return parseResult.value;
|
|
@@ -6478,6 +7061,9 @@ var json = ({
|
|
|
6478
7061
|
return result.value === void 0 ? void 0 : { partial: result.value };
|
|
6479
7062
|
}
|
|
6480
7063
|
}
|
|
7064
|
+
},
|
|
7065
|
+
createElementStreamTransform() {
|
|
7066
|
+
return void 0;
|
|
6481
7067
|
}
|
|
6482
7068
|
};
|
|
6483
7069
|
};
|
|
@@ -6488,7 +7074,7 @@ async function parseToolCall({
|
|
|
6488
7074
|
system,
|
|
6489
7075
|
messages
|
|
6490
7076
|
}) {
|
|
6491
|
-
var
|
|
7077
|
+
var _a21;
|
|
6492
7078
|
try {
|
|
6493
7079
|
if (tools == null) {
|
|
6494
7080
|
if (toolCall.providerExecuted && toolCall.dynamic) {
|
|
@@ -6537,7 +7123,7 @@ async function parseToolCall({
|
|
|
6537
7123
|
dynamic: true,
|
|
6538
7124
|
invalid: true,
|
|
6539
7125
|
error,
|
|
6540
|
-
title: (
|
|
7126
|
+
title: (_a21 = tools == null ? void 0 : tools[toolCall.toolName]) == null ? void 0 : _a21.title,
|
|
6541
7127
|
providerExecuted: toolCall.providerExecuted,
|
|
6542
7128
|
providerMetadata: toolCall.providerMetadata
|
|
6543
7129
|
};
|
|
@@ -6683,7 +7269,13 @@ async function toResponseMessages({
|
|
|
6683
7269
|
const responseMessages = [];
|
|
6684
7270
|
const content = [];
|
|
6685
7271
|
for (const part of inputContent) {
|
|
6686
|
-
if (part.type === "source"
|
|
7272
|
+
if (part.type === "source") {
|
|
7273
|
+
continue;
|
|
7274
|
+
}
|
|
7275
|
+
if ((part.type === "tool-result" || part.type === "tool-error") && !part.providerExecuted) {
|
|
7276
|
+
continue;
|
|
7277
|
+
}
|
|
7278
|
+
if (part.type === "text" && part.text.length === 0) {
|
|
6687
7279
|
continue;
|
|
6688
7280
|
}
|
|
6689
7281
|
switch (part.type) {
|
|
@@ -6796,6 +7388,32 @@ async function toResponseMessages({
|
|
|
6796
7388
|
}
|
|
6797
7389
|
return responseMessages;
|
|
6798
7390
|
}
|
|
7391
|
+
function mergeAbortSignals(...signals) {
|
|
7392
|
+
const validSignals = signals.filter(
|
|
7393
|
+
(signal) => signal != null
|
|
7394
|
+
);
|
|
7395
|
+
if (validSignals.length === 0) {
|
|
7396
|
+
return void 0;
|
|
7397
|
+
}
|
|
7398
|
+
if (validSignals.length === 1) {
|
|
7399
|
+
return validSignals[0];
|
|
7400
|
+
}
|
|
7401
|
+
const controller = new AbortController();
|
|
7402
|
+
for (const signal of validSignals) {
|
|
7403
|
+
if (signal.aborted) {
|
|
7404
|
+
controller.abort(signal.reason);
|
|
7405
|
+
return controller.signal;
|
|
7406
|
+
}
|
|
7407
|
+
signal.addEventListener(
|
|
7408
|
+
"abort",
|
|
7409
|
+
() => {
|
|
7410
|
+
controller.abort(signal.reason);
|
|
7411
|
+
},
|
|
7412
|
+
{ once: true }
|
|
7413
|
+
);
|
|
7414
|
+
}
|
|
7415
|
+
return controller.signal;
|
|
7416
|
+
}
|
|
6799
7417
|
var originalGenerateId = createIdGenerator({
|
|
6800
7418
|
prefix: "aitxt",
|
|
6801
7419
|
size: 24
|
|
@@ -6809,6 +7427,7 @@ async function generateText({
|
|
|
6809
7427
|
messages,
|
|
6810
7428
|
maxRetries: maxRetriesArg,
|
|
6811
7429
|
abortSignal,
|
|
7430
|
+
timeout,
|
|
6812
7431
|
headers,
|
|
6813
7432
|
stopWhen = stepCountIs(1),
|
|
6814
7433
|
experimental_output,
|
|
@@ -6822,19 +7441,25 @@ async function generateText({
|
|
|
6822
7441
|
experimental_repairToolCall: repairToolCall,
|
|
6823
7442
|
experimental_download: download2,
|
|
6824
7443
|
experimental_context,
|
|
6825
|
-
|
|
6826
|
-
|
|
6827
|
-
currentDate = () => /* @__PURE__ */ new Date()
|
|
6828
|
-
} = {},
|
|
7444
|
+
experimental_include: include,
|
|
7445
|
+
_internal: { generateId: generateId2 = originalGenerateId } = {},
|
|
6829
7446
|
onStepFinish,
|
|
6830
7447
|
onFinish,
|
|
6831
7448
|
...settings
|
|
6832
7449
|
}) {
|
|
6833
7450
|
const model = resolveLanguageModel(modelArg);
|
|
6834
7451
|
const stopConditions = asArray(stopWhen);
|
|
7452
|
+
const totalTimeoutMs = getTotalTimeoutMs(timeout);
|
|
7453
|
+
const stepTimeoutMs = getStepTimeoutMs(timeout);
|
|
7454
|
+
const stepAbortController = stepTimeoutMs != null ? new AbortController() : void 0;
|
|
7455
|
+
const mergedAbortSignal = mergeAbortSignals(
|
|
7456
|
+
abortSignal,
|
|
7457
|
+
totalTimeoutMs != null ? AbortSignal.timeout(totalTimeoutMs) : void 0,
|
|
7458
|
+
stepAbortController == null ? void 0 : stepAbortController.signal
|
|
7459
|
+
);
|
|
6835
7460
|
const { maxRetries, retry } = prepareRetries({
|
|
6836
7461
|
maxRetries: maxRetriesArg,
|
|
6837
|
-
abortSignal
|
|
7462
|
+
abortSignal: mergedAbortSignal
|
|
6838
7463
|
});
|
|
6839
7464
|
const callSettings = prepareCallSettings(settings);
|
|
6840
7465
|
const headersWithUserAgent = withUserAgentSuffix(
|
|
@@ -6875,20 +7500,23 @@ async function generateText({
|
|
|
6875
7500
|
}),
|
|
6876
7501
|
tracer,
|
|
6877
7502
|
fn: async (span) => {
|
|
6878
|
-
var
|
|
7503
|
+
var _a21, _b82, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
6879
7504
|
const initialMessages = initialPrompt.messages;
|
|
6880
7505
|
const responseMessages = [];
|
|
6881
7506
|
const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({ messages: initialMessages });
|
|
6882
|
-
|
|
7507
|
+
const localApprovedToolApprovals = approvedToolApprovals.filter(
|
|
7508
|
+
(toolApproval) => !toolApproval.toolCall.providerExecuted
|
|
7509
|
+
);
|
|
7510
|
+
if (deniedToolApprovals.length > 0 || localApprovedToolApprovals.length > 0) {
|
|
6883
7511
|
const toolOutputs = await executeTools({
|
|
6884
|
-
toolCalls:
|
|
7512
|
+
toolCalls: localApprovedToolApprovals.map(
|
|
6885
7513
|
(toolApproval) => toolApproval.toolCall
|
|
6886
7514
|
),
|
|
6887
7515
|
tools,
|
|
6888
7516
|
tracer,
|
|
6889
7517
|
telemetry,
|
|
6890
7518
|
messages: initialMessages,
|
|
6891
|
-
abortSignal,
|
|
7519
|
+
abortSignal: mergedAbortSignal,
|
|
6892
7520
|
experimental_context
|
|
6893
7521
|
});
|
|
6894
7522
|
const toolContent = [];
|
|
@@ -6914,7 +7542,15 @@ async function generateText({
|
|
|
6914
7542
|
toolName: toolApproval.toolCall.toolName,
|
|
6915
7543
|
output: {
|
|
6916
7544
|
type: "execution-denied",
|
|
6917
|
-
reason: toolApproval.approvalResponse.reason
|
|
7545
|
+
reason: toolApproval.approvalResponse.reason,
|
|
7546
|
+
// For provider-executed tools, include approvalId so provider can correlate
|
|
7547
|
+
...toolApproval.toolCall.providerExecuted && {
|
|
7548
|
+
providerOptions: {
|
|
7549
|
+
openai: {
|
|
7550
|
+
approvalId: toolApproval.approvalResponse.approvalId
|
|
7551
|
+
}
|
|
7552
|
+
}
|
|
7553
|
+
}
|
|
6918
7554
|
}
|
|
6919
7555
|
});
|
|
6920
7556
|
}
|
|
@@ -6923,6 +7559,24 @@ async function generateText({
|
|
|
6923
7559
|
content: toolContent
|
|
6924
7560
|
});
|
|
6925
7561
|
}
|
|
7562
|
+
const providerExecutedToolApprovals = [
|
|
7563
|
+
...approvedToolApprovals,
|
|
7564
|
+
...deniedToolApprovals
|
|
7565
|
+
].filter((toolApproval) => toolApproval.toolCall.providerExecuted);
|
|
7566
|
+
if (providerExecutedToolApprovals.length > 0) {
|
|
7567
|
+
responseMessages.push({
|
|
7568
|
+
role: "tool",
|
|
7569
|
+
content: providerExecutedToolApprovals.map(
|
|
7570
|
+
(toolApproval) => ({
|
|
7571
|
+
type: "tool-approval-response",
|
|
7572
|
+
approvalId: toolApproval.approvalResponse.approvalId,
|
|
7573
|
+
approved: toolApproval.approvalResponse.approved,
|
|
7574
|
+
reason: toolApproval.approvalResponse.reason,
|
|
7575
|
+
providerExecuted: true
|
|
7576
|
+
})
|
|
7577
|
+
)
|
|
7578
|
+
});
|
|
7579
|
+
}
|
|
6926
7580
|
const callSettings2 = prepareCallSettings(settings);
|
|
6927
7581
|
let currentModelResponse;
|
|
6928
7582
|
let clientToolCalls = [];
|
|
@@ -6930,263 +7584,274 @@ async function generateText({
|
|
|
6930
7584
|
const steps = [];
|
|
6931
7585
|
const pendingDeferredToolCalls = /* @__PURE__ */ new Map();
|
|
6932
7586
|
do {
|
|
6933
|
-
const
|
|
6934
|
-
|
|
6935
|
-
|
|
6936
|
-
|
|
6937
|
-
|
|
6938
|
-
|
|
6939
|
-
|
|
6940
|
-
|
|
6941
|
-
|
|
6942
|
-
|
|
6943
|
-
|
|
6944
|
-
|
|
6945
|
-
|
|
6946
|
-
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
|
|
6950
|
-
|
|
6951
|
-
|
|
6952
|
-
|
|
6953
|
-
|
|
6954
|
-
|
|
6955
|
-
toolChoice:
|
|
6956
|
-
|
|
6957
|
-
|
|
6958
|
-
|
|
6959
|
-
|
|
6960
|
-
|
|
6961
|
-
|
|
6962
|
-
|
|
6963
|
-
|
|
6964
|
-
|
|
6965
|
-
attributes: {
|
|
6966
|
-
|
|
6967
|
-
|
|
6968
|
-
|
|
6969
|
-
|
|
6970
|
-
|
|
6971
|
-
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
|
|
6975
|
-
|
|
6976
|
-
|
|
6977
|
-
|
|
6978
|
-
|
|
6979
|
-
|
|
6980
|
-
|
|
6981
|
-
|
|
6982
|
-
|
|
6983
|
-
|
|
6984
|
-
|
|
6985
|
-
|
|
6986
|
-
|
|
6987
|
-
|
|
6988
|
-
|
|
6989
|
-
|
|
6990
|
-
|
|
6991
|
-
|
|
6992
|
-
|
|
6993
|
-
|
|
6994
|
-
|
|
7587
|
+
const stepTimeoutId = stepTimeoutMs != null ? setTimeout(() => stepAbortController.abort(), stepTimeoutMs) : void 0;
|
|
7588
|
+
try {
|
|
7589
|
+
const stepInputMessages = [...initialMessages, ...responseMessages];
|
|
7590
|
+
const prepareStepResult = await (prepareStep == null ? void 0 : prepareStep({
|
|
7591
|
+
model,
|
|
7592
|
+
steps,
|
|
7593
|
+
stepNumber: steps.length,
|
|
7594
|
+
messages: stepInputMessages,
|
|
7595
|
+
experimental_context
|
|
7596
|
+
}));
|
|
7597
|
+
const stepModel = resolveLanguageModel(
|
|
7598
|
+
(_a21 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a21 : model
|
|
7599
|
+
);
|
|
7600
|
+
const promptMessages = await convertToLanguageModelPrompt({
|
|
7601
|
+
prompt: {
|
|
7602
|
+
system: (_b82 = prepareStepResult == null ? void 0 : prepareStepResult.system) != null ? _b82 : initialPrompt.system,
|
|
7603
|
+
messages: (_c = prepareStepResult == null ? void 0 : prepareStepResult.messages) != null ? _c : stepInputMessages
|
|
7604
|
+
},
|
|
7605
|
+
supportedUrls: await stepModel.supportedUrls,
|
|
7606
|
+
download: download2
|
|
7607
|
+
});
|
|
7608
|
+
experimental_context = (_d = prepareStepResult == null ? void 0 : prepareStepResult.experimental_context) != null ? _d : experimental_context;
|
|
7609
|
+
const { toolChoice: stepToolChoice, tools: stepTools } = await prepareToolsAndToolChoice({
|
|
7610
|
+
tools,
|
|
7611
|
+
toolChoice: (_e = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _e : toolChoice,
|
|
7612
|
+
activeTools: (_f = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _f : activeTools
|
|
7613
|
+
});
|
|
7614
|
+
currentModelResponse = await retry(
|
|
7615
|
+
() => {
|
|
7616
|
+
var _a2222;
|
|
7617
|
+
return recordSpan({
|
|
7618
|
+
name: "ai.generateText.doGenerate",
|
|
7619
|
+
attributes: selectTelemetryAttributes({
|
|
7620
|
+
telemetry,
|
|
7621
|
+
attributes: {
|
|
7622
|
+
...assembleOperationName({
|
|
7623
|
+
operationId: "ai.generateText.doGenerate",
|
|
7624
|
+
telemetry
|
|
7625
|
+
}),
|
|
7626
|
+
...baseTelemetryAttributes,
|
|
7627
|
+
// model:
|
|
7628
|
+
"ai.model.provider": stepModel.provider,
|
|
7629
|
+
"ai.model.id": stepModel.modelId,
|
|
7630
|
+
// prompt:
|
|
7631
|
+
"ai.prompt.messages": {
|
|
7632
|
+
input: () => stringifyForTelemetry(promptMessages)
|
|
7633
|
+
},
|
|
7634
|
+
"ai.prompt.tools": {
|
|
7635
|
+
// convert the language model level tools:
|
|
7636
|
+
input: () => stepTools == null ? void 0 : stepTools.map((tool2) => JSON.stringify(tool2))
|
|
7637
|
+
},
|
|
7638
|
+
"ai.prompt.toolChoice": {
|
|
7639
|
+
input: () => stepToolChoice != null ? JSON.stringify(stepToolChoice) : void 0
|
|
7640
|
+
},
|
|
7641
|
+
// standardized gen-ai llm span attributes:
|
|
7642
|
+
"gen_ai.system": stepModel.provider,
|
|
7643
|
+
"gen_ai.request.model": stepModel.modelId,
|
|
7644
|
+
"gen_ai.request.frequency_penalty": settings.frequencyPenalty,
|
|
7645
|
+
"gen_ai.request.max_tokens": settings.maxOutputTokens,
|
|
7646
|
+
"gen_ai.request.presence_penalty": settings.presencePenalty,
|
|
7647
|
+
"gen_ai.request.stop_sequences": settings.stopSequences,
|
|
7648
|
+
"gen_ai.request.temperature": (_a2222 = settings.temperature) != null ? _a2222 : void 0,
|
|
7649
|
+
"gen_ai.request.top_k": settings.topK,
|
|
7650
|
+
"gen_ai.request.top_p": settings.topP
|
|
7651
|
+
}
|
|
7652
|
+
}),
|
|
7653
|
+
tracer,
|
|
7654
|
+
fn: async (span2) => {
|
|
7655
|
+
var _a23, _b222, _c2, _d2, _e2, _f2, _g2, _h2;
|
|
7656
|
+
const stepProviderOptions = mergeObjects(
|
|
7657
|
+
providerOptions,
|
|
7658
|
+
prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
|
|
7659
|
+
);
|
|
7660
|
+
const result = await stepModel.doGenerate({
|
|
7661
|
+
...callSettings2,
|
|
7662
|
+
tools: stepTools,
|
|
7663
|
+
toolChoice: stepToolChoice,
|
|
7664
|
+
responseFormat: await (output == null ? void 0 : output.responseFormat),
|
|
7665
|
+
prompt: promptMessages,
|
|
7666
|
+
providerOptions: stepProviderOptions,
|
|
7667
|
+
abortSignal: mergedAbortSignal,
|
|
7668
|
+
headers: headersWithUserAgent
|
|
7669
|
+
});
|
|
7670
|
+
const responseData = {
|
|
7671
|
+
id: (_b222 = (_a23 = result.response) == null ? void 0 : _a23.id) != null ? _b222 : generateId2(),
|
|
7672
|
+
timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : /* @__PURE__ */ new Date(),
|
|
7673
|
+
modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : stepModel.modelId,
|
|
7674
|
+
headers: (_g2 = result.response) == null ? void 0 : _g2.headers,
|
|
7675
|
+
body: (_h2 = result.response) == null ? void 0 : _h2.body
|
|
7676
|
+
};
|
|
7677
|
+
span2.setAttributes(
|
|
7678
|
+
await selectTelemetryAttributes({
|
|
7679
|
+
telemetry,
|
|
7680
|
+
attributes: {
|
|
7681
|
+
"ai.response.finishReason": result.finishReason.unified,
|
|
7682
|
+
"ai.response.text": {
|
|
7683
|
+
output: () => extractTextContent(result.content)
|
|
7684
|
+
},
|
|
7685
|
+
"ai.response.toolCalls": {
|
|
7686
|
+
output: () => {
|
|
7687
|
+
const toolCalls = asToolCalls(result.content);
|
|
7688
|
+
return toolCalls == null ? void 0 : JSON.stringify(toolCalls);
|
|
7689
|
+
}
|
|
7690
|
+
},
|
|
7691
|
+
"ai.response.id": responseData.id,
|
|
7692
|
+
"ai.response.model": responseData.modelId,
|
|
7693
|
+
"ai.response.timestamp": responseData.timestamp.toISOString(),
|
|
7694
|
+
"ai.response.providerMetadata": JSON.stringify(
|
|
7695
|
+
result.providerMetadata
|
|
7696
|
+
),
|
|
7697
|
+
// TODO rename telemetry attributes to inputTokens and outputTokens
|
|
7698
|
+
"ai.usage.promptTokens": result.usage.inputTokens.total,
|
|
7699
|
+
"ai.usage.completionTokens": result.usage.outputTokens.total,
|
|
7700
|
+
// standardized gen-ai llm span attributes:
|
|
7701
|
+
"gen_ai.response.finish_reasons": [
|
|
7702
|
+
result.finishReason.unified
|
|
7703
|
+
],
|
|
7704
|
+
"gen_ai.response.id": responseData.id,
|
|
7705
|
+
"gen_ai.response.model": responseData.modelId,
|
|
7706
|
+
"gen_ai.usage.input_tokens": result.usage.inputTokens.total,
|
|
7707
|
+
"gen_ai.usage.output_tokens": result.usage.outputTokens.total
|
|
7708
|
+
}
|
|
7709
|
+
})
|
|
7710
|
+
);
|
|
7711
|
+
return { ...result, response: responseData };
|
|
6995
7712
|
}
|
|
6996
|
-
})
|
|
6997
|
-
|
|
6998
|
-
|
|
6999
|
-
|
|
7000
|
-
|
|
7001
|
-
|
|
7002
|
-
|
|
7003
|
-
|
|
7004
|
-
|
|
7005
|
-
|
|
7006
|
-
|
|
7007
|
-
|
|
7008
|
-
|
|
7009
|
-
|
|
7010
|
-
|
|
7011
|
-
|
|
7012
|
-
|
|
7013
|
-
|
|
7014
|
-
|
|
7015
|
-
|
|
7016
|
-
|
|
7017
|
-
|
|
7018
|
-
|
|
7019
|
-
|
|
7020
|
-
|
|
7021
|
-
|
|
7022
|
-
|
|
7023
|
-
|
|
7024
|
-
|
|
7025
|
-
|
|
7026
|
-
|
|
7027
|
-
|
|
7028
|
-
|
|
7029
|
-
|
|
7030
|
-
|
|
7031
|
-
|
|
7032
|
-
return toolCalls == null ? void 0 : JSON.stringify(toolCalls);
|
|
7033
|
-
}
|
|
7034
|
-
},
|
|
7035
|
-
"ai.response.id": responseData.id,
|
|
7036
|
-
"ai.response.model": responseData.modelId,
|
|
7037
|
-
"ai.response.timestamp": responseData.timestamp.toISOString(),
|
|
7038
|
-
"ai.response.providerMetadata": JSON.stringify(
|
|
7039
|
-
result.providerMetadata
|
|
7040
|
-
),
|
|
7041
|
-
// TODO rename telemetry attributes to inputTokens and outputTokens
|
|
7042
|
-
"ai.usage.promptTokens": result.usage.inputTokens.total,
|
|
7043
|
-
"ai.usage.completionTokens": result.usage.outputTokens.total,
|
|
7044
|
-
// standardized gen-ai llm span attributes:
|
|
7045
|
-
"gen_ai.response.finish_reasons": [
|
|
7046
|
-
result.finishReason.unified
|
|
7047
|
-
],
|
|
7048
|
-
"gen_ai.response.id": responseData.id,
|
|
7049
|
-
"gen_ai.response.model": responseData.modelId,
|
|
7050
|
-
"gen_ai.usage.input_tokens": result.usage.inputTokens.total,
|
|
7051
|
-
"gen_ai.usage.output_tokens": result.usage.outputTokens.total
|
|
7052
|
-
}
|
|
7053
|
-
})
|
|
7054
|
-
);
|
|
7055
|
-
return { ...result, response: responseData };
|
|
7056
|
-
}
|
|
7057
|
-
});
|
|
7058
|
-
}
|
|
7059
|
-
);
|
|
7060
|
-
const stepToolCalls = await Promise.all(
|
|
7061
|
-
currentModelResponse.content.filter(
|
|
7062
|
-
(part) => part.type === "tool-call"
|
|
7063
|
-
).map(
|
|
7064
|
-
(toolCall) => parseToolCall({
|
|
7713
|
+
});
|
|
7714
|
+
}
|
|
7715
|
+
);
|
|
7716
|
+
const stepToolCalls = await Promise.all(
|
|
7717
|
+
currentModelResponse.content.filter(
|
|
7718
|
+
(part) => part.type === "tool-call"
|
|
7719
|
+
).map(
|
|
7720
|
+
(toolCall) => parseToolCall({
|
|
7721
|
+
toolCall,
|
|
7722
|
+
tools,
|
|
7723
|
+
repairToolCall,
|
|
7724
|
+
system,
|
|
7725
|
+
messages: stepInputMessages
|
|
7726
|
+
})
|
|
7727
|
+
)
|
|
7728
|
+
);
|
|
7729
|
+
const toolApprovalRequests = {};
|
|
7730
|
+
for (const toolCall of stepToolCalls) {
|
|
7731
|
+
if (toolCall.invalid) {
|
|
7732
|
+
continue;
|
|
7733
|
+
}
|
|
7734
|
+
const tool2 = tools == null ? void 0 : tools[toolCall.toolName];
|
|
7735
|
+
if (tool2 == null) {
|
|
7736
|
+
continue;
|
|
7737
|
+
}
|
|
7738
|
+
if ((tool2 == null ? void 0 : tool2.onInputAvailable) != null) {
|
|
7739
|
+
await tool2.onInputAvailable({
|
|
7740
|
+
input: toolCall.input,
|
|
7741
|
+
toolCallId: toolCall.toolCallId,
|
|
7742
|
+
messages: stepInputMessages,
|
|
7743
|
+
abortSignal: mergedAbortSignal,
|
|
7744
|
+
experimental_context
|
|
7745
|
+
});
|
|
7746
|
+
}
|
|
7747
|
+
if (await isApprovalNeeded({
|
|
7748
|
+
tool: tool2,
|
|
7065
7749
|
toolCall,
|
|
7066
|
-
tools,
|
|
7067
|
-
repairToolCall,
|
|
7068
|
-
system,
|
|
7069
|
-
messages: stepInputMessages
|
|
7070
|
-
})
|
|
7071
|
-
)
|
|
7072
|
-
);
|
|
7073
|
-
const toolApprovalRequests = {};
|
|
7074
|
-
for (const toolCall of stepToolCalls) {
|
|
7075
|
-
if (toolCall.invalid) {
|
|
7076
|
-
continue;
|
|
7077
|
-
}
|
|
7078
|
-
const tool2 = tools == null ? void 0 : tools[toolCall.toolName];
|
|
7079
|
-
if (tool2 == null) {
|
|
7080
|
-
continue;
|
|
7081
|
-
}
|
|
7082
|
-
if ((tool2 == null ? void 0 : tool2.onInputAvailable) != null) {
|
|
7083
|
-
await tool2.onInputAvailable({
|
|
7084
|
-
input: toolCall.input,
|
|
7085
|
-
toolCallId: toolCall.toolCallId,
|
|
7086
7750
|
messages: stepInputMessages,
|
|
7087
|
-
abortSignal,
|
|
7088
7751
|
experimental_context
|
|
7089
|
-
})
|
|
7752
|
+
})) {
|
|
7753
|
+
toolApprovalRequests[toolCall.toolCallId] = {
|
|
7754
|
+
type: "tool-approval-request",
|
|
7755
|
+
approvalId: generateId2(),
|
|
7756
|
+
toolCall
|
|
7757
|
+
};
|
|
7758
|
+
}
|
|
7090
7759
|
}
|
|
7091
|
-
|
|
7092
|
-
|
|
7093
|
-
|
|
7094
|
-
|
|
7095
|
-
|
|
7096
|
-
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
|
|
7100
|
-
toolCall
|
|
7101
|
-
|
|
7760
|
+
const invalidToolCalls = stepToolCalls.filter(
|
|
7761
|
+
(toolCall) => toolCall.invalid && toolCall.dynamic
|
|
7762
|
+
);
|
|
7763
|
+
clientToolOutputs = [];
|
|
7764
|
+
for (const toolCall of invalidToolCalls) {
|
|
7765
|
+
clientToolOutputs.push({
|
|
7766
|
+
type: "tool-error",
|
|
7767
|
+
toolCallId: toolCall.toolCallId,
|
|
7768
|
+
toolName: toolCall.toolName,
|
|
7769
|
+
input: toolCall.input,
|
|
7770
|
+
error: getErrorMessage2(toolCall.error),
|
|
7771
|
+
dynamic: true
|
|
7772
|
+
});
|
|
7102
7773
|
}
|
|
7103
|
-
|
|
7104
|
-
|
|
7105
|
-
(toolCall) => toolCall.invalid && toolCall.dynamic
|
|
7106
|
-
);
|
|
7107
|
-
clientToolOutputs = [];
|
|
7108
|
-
for (const toolCall of invalidToolCalls) {
|
|
7109
|
-
clientToolOutputs.push({
|
|
7110
|
-
type: "tool-error",
|
|
7111
|
-
toolCallId: toolCall.toolCallId,
|
|
7112
|
-
toolName: toolCall.toolName,
|
|
7113
|
-
input: toolCall.input,
|
|
7114
|
-
error: getErrorMessage2(toolCall.error),
|
|
7115
|
-
dynamic: true
|
|
7116
|
-
});
|
|
7117
|
-
}
|
|
7118
|
-
clientToolCalls = stepToolCalls.filter(
|
|
7119
|
-
(toolCall) => !toolCall.providerExecuted
|
|
7120
|
-
);
|
|
7121
|
-
if (tools != null) {
|
|
7122
|
-
clientToolOutputs.push(
|
|
7123
|
-
...await executeTools({
|
|
7124
|
-
toolCalls: clientToolCalls.filter(
|
|
7125
|
-
(toolCall) => !toolCall.invalid && toolApprovalRequests[toolCall.toolCallId] == null
|
|
7126
|
-
),
|
|
7127
|
-
tools,
|
|
7128
|
-
tracer,
|
|
7129
|
-
telemetry,
|
|
7130
|
-
messages: stepInputMessages,
|
|
7131
|
-
abortSignal,
|
|
7132
|
-
experimental_context
|
|
7133
|
-
})
|
|
7774
|
+
clientToolCalls = stepToolCalls.filter(
|
|
7775
|
+
(toolCall) => !toolCall.providerExecuted
|
|
7134
7776
|
);
|
|
7135
|
-
|
|
7136
|
-
|
|
7137
|
-
|
|
7138
|
-
|
|
7139
|
-
|
|
7140
|
-
|
|
7141
|
-
|
|
7142
|
-
|
|
7777
|
+
if (tools != null) {
|
|
7778
|
+
clientToolOutputs.push(
|
|
7779
|
+
...await executeTools({
|
|
7780
|
+
toolCalls: clientToolCalls.filter(
|
|
7781
|
+
(toolCall) => !toolCall.invalid && toolApprovalRequests[toolCall.toolCallId] == null
|
|
7782
|
+
),
|
|
7783
|
+
tools,
|
|
7784
|
+
tracer,
|
|
7785
|
+
telemetry,
|
|
7786
|
+
messages: stepInputMessages,
|
|
7787
|
+
abortSignal: mergedAbortSignal,
|
|
7788
|
+
experimental_context
|
|
7789
|
+
})
|
|
7143
7790
|
);
|
|
7144
|
-
|
|
7145
|
-
|
|
7146
|
-
|
|
7147
|
-
|
|
7791
|
+
}
|
|
7792
|
+
for (const toolCall of stepToolCalls) {
|
|
7793
|
+
if (!toolCall.providerExecuted)
|
|
7794
|
+
continue;
|
|
7795
|
+
const tool2 = tools == null ? void 0 : tools[toolCall.toolName];
|
|
7796
|
+
if ((tool2 == null ? void 0 : tool2.type) === "provider" && tool2.supportsDeferredResults) {
|
|
7797
|
+
const hasResultInResponse = currentModelResponse.content.some(
|
|
7798
|
+
(part) => part.type === "tool-result" && part.toolCallId === toolCall.toolCallId
|
|
7799
|
+
);
|
|
7800
|
+
if (!hasResultInResponse) {
|
|
7801
|
+
pendingDeferredToolCalls.set(toolCall.toolCallId, {
|
|
7802
|
+
toolName: toolCall.toolName
|
|
7803
|
+
});
|
|
7804
|
+
}
|
|
7148
7805
|
}
|
|
7149
7806
|
}
|
|
7150
|
-
|
|
7151
|
-
|
|
7152
|
-
|
|
7153
|
-
|
|
7807
|
+
for (const part of currentModelResponse.content) {
|
|
7808
|
+
if (part.type === "tool-result") {
|
|
7809
|
+
pendingDeferredToolCalls.delete(part.toolCallId);
|
|
7810
|
+
}
|
|
7154
7811
|
}
|
|
7155
|
-
|
|
7156
|
-
|
|
7157
|
-
|
|
7158
|
-
|
|
7159
|
-
|
|
7160
|
-
toolApprovalRequests: Object.values(toolApprovalRequests),
|
|
7161
|
-
tools
|
|
7162
|
-
});
|
|
7163
|
-
responseMessages.push(
|
|
7164
|
-
...await toResponseMessages({
|
|
7165
|
-
content: stepContent,
|
|
7812
|
+
const stepContent = asContent({
|
|
7813
|
+
content: currentModelResponse.content,
|
|
7814
|
+
toolCalls: stepToolCalls,
|
|
7815
|
+
toolOutputs: clientToolOutputs,
|
|
7816
|
+
toolApprovalRequests: Object.values(toolApprovalRequests),
|
|
7166
7817
|
tools
|
|
7167
|
-
})
|
|
7168
|
-
|
|
7169
|
-
|
|
7170
|
-
|
|
7171
|
-
|
|
7172
|
-
|
|
7173
|
-
|
|
7174
|
-
|
|
7175
|
-
|
|
7176
|
-
request: (_g = currentModelResponse.request) != null ? _g : {},
|
|
7177
|
-
response: {
|
|
7818
|
+
});
|
|
7819
|
+
responseMessages.push(
|
|
7820
|
+
...await toResponseMessages({
|
|
7821
|
+
content: stepContent,
|
|
7822
|
+
tools
|
|
7823
|
+
})
|
|
7824
|
+
);
|
|
7825
|
+
const stepRequest = ((_g = include == null ? void 0 : include.requestBody) != null ? _g : true) ? (_h = currentModelResponse.request) != null ? _h : {} : { ...currentModelResponse.request, body: void 0 };
|
|
7826
|
+
const stepResponse = {
|
|
7178
7827
|
...currentModelResponse.response,
|
|
7179
7828
|
// deep clone msgs to avoid mutating past messages in multi-step:
|
|
7180
|
-
messages: structuredClone(responseMessages)
|
|
7181
|
-
|
|
7182
|
-
|
|
7183
|
-
|
|
7184
|
-
|
|
7185
|
-
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7829
|
+
messages: structuredClone(responseMessages),
|
|
7830
|
+
// Conditionally include response body:
|
|
7831
|
+
body: ((_i = include == null ? void 0 : include.responseBody) != null ? _i : true) ? (_j = currentModelResponse.response) == null ? void 0 : _j.body : void 0
|
|
7832
|
+
};
|
|
7833
|
+
const currentStepResult = new DefaultStepResult({
|
|
7834
|
+
content: stepContent,
|
|
7835
|
+
finishReason: currentModelResponse.finishReason.unified,
|
|
7836
|
+
rawFinishReason: currentModelResponse.finishReason.raw,
|
|
7837
|
+
usage: asLanguageModelUsage(currentModelResponse.usage),
|
|
7838
|
+
warnings: currentModelResponse.warnings,
|
|
7839
|
+
providerMetadata: currentModelResponse.providerMetadata,
|
|
7840
|
+
request: stepRequest,
|
|
7841
|
+
response: stepResponse
|
|
7842
|
+
});
|
|
7843
|
+
logWarnings({
|
|
7844
|
+
warnings: (_k = currentModelResponse.warnings) != null ? _k : [],
|
|
7845
|
+
provider: stepModel.provider,
|
|
7846
|
+
model: stepModel.modelId
|
|
7847
|
+
});
|
|
7848
|
+
steps.push(currentStepResult);
|
|
7849
|
+
await (onStepFinish == null ? void 0 : onStepFinish(currentStepResult));
|
|
7850
|
+
} finally {
|
|
7851
|
+
if (stepTimeoutId != null) {
|
|
7852
|
+
clearTimeout(stepTimeoutId);
|
|
7853
|
+
}
|
|
7854
|
+
}
|
|
7190
7855
|
} while (
|
|
7191
7856
|
// Continue if:
|
|
7192
7857
|
// 1. There are client tool calls that have all been executed, OR
|
|
@@ -7477,6 +8142,23 @@ function asContent({
|
|
|
7477
8142
|
}
|
|
7478
8143
|
break;
|
|
7479
8144
|
}
|
|
8145
|
+
case "tool-approval-request": {
|
|
8146
|
+
const toolCall = toolCalls.find(
|
|
8147
|
+
(toolCall2) => toolCall2.toolCallId === part.toolCallId
|
|
8148
|
+
);
|
|
8149
|
+
if (toolCall == null) {
|
|
8150
|
+
throw new ToolCallNotFoundForApprovalError({
|
|
8151
|
+
toolCallId: part.toolCallId,
|
|
8152
|
+
approvalId: part.approvalId
|
|
8153
|
+
});
|
|
8154
|
+
}
|
|
8155
|
+
contentParts.push({
|
|
8156
|
+
type: "tool-approval-request",
|
|
8157
|
+
approvalId: part.approvalId,
|
|
8158
|
+
toolCall
|
|
8159
|
+
});
|
|
8160
|
+
break;
|
|
8161
|
+
}
|
|
7480
8162
|
}
|
|
7481
8163
|
}
|
|
7482
8164
|
return [...contentParts, ...toolOutputs, ...toolApprovalRequests];
|
|
@@ -7653,21 +8335,23 @@ function processUIMessageStream({
|
|
|
7653
8335
|
new TransformStream({
|
|
7654
8336
|
async transform(chunk, controller) {
|
|
7655
8337
|
await runUpdateMessageJob(async ({ state, write }) => {
|
|
7656
|
-
var
|
|
8338
|
+
var _a21, _b82, _c, _d;
|
|
7657
8339
|
function getToolInvocation(toolCallId) {
|
|
7658
8340
|
const toolInvocations = state.message.parts.filter(isToolUIPart);
|
|
7659
8341
|
const toolInvocation = toolInvocations.find(
|
|
7660
8342
|
(invocation) => invocation.toolCallId === toolCallId
|
|
7661
8343
|
);
|
|
7662
8344
|
if (toolInvocation == null) {
|
|
7663
|
-
throw new
|
|
7664
|
-
|
|
7665
|
-
|
|
8345
|
+
throw new UIMessageStreamError({
|
|
8346
|
+
chunkType: "tool-invocation",
|
|
8347
|
+
chunkId: toolCallId,
|
|
8348
|
+
message: `No tool invocation found for tool call ID "${toolCallId}".`
|
|
8349
|
+
});
|
|
7666
8350
|
}
|
|
7667
8351
|
return toolInvocation;
|
|
7668
8352
|
}
|
|
7669
8353
|
function updateToolPart(options) {
|
|
7670
|
-
var
|
|
8354
|
+
var _a2222;
|
|
7671
8355
|
const part = state.message.parts.find(
|
|
7672
8356
|
(part2) => isStaticToolUIPart(part2) && part2.toolCallId === options.toolCallId
|
|
7673
8357
|
);
|
|
@@ -7683,8 +8367,8 @@ function processUIMessageStream({
|
|
|
7683
8367
|
if (options.title !== void 0) {
|
|
7684
8368
|
anyPart.title = options.title;
|
|
7685
8369
|
}
|
|
7686
|
-
anyPart.providerExecuted = (
|
|
7687
|
-
if (anyOptions.providerMetadata != null
|
|
8370
|
+
anyPart.providerExecuted = (_a2222 = anyOptions.providerExecuted) != null ? _a2222 : part.providerExecuted;
|
|
8371
|
+
if (anyOptions.providerMetadata != null) {
|
|
7688
8372
|
part.callProviderMetadata = anyOptions.providerMetadata;
|
|
7689
8373
|
}
|
|
7690
8374
|
} else {
|
|
@@ -7704,7 +8388,7 @@ function processUIMessageStream({
|
|
|
7704
8388
|
}
|
|
7705
8389
|
}
|
|
7706
8390
|
function updateDynamicToolPart(options) {
|
|
7707
|
-
var
|
|
8391
|
+
var _a2222, _b222;
|
|
7708
8392
|
const part = state.message.parts.find(
|
|
7709
8393
|
(part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
|
|
7710
8394
|
);
|
|
@@ -7716,13 +8400,13 @@ function processUIMessageStream({
|
|
|
7716
8400
|
anyPart.input = anyOptions.input;
|
|
7717
8401
|
anyPart.output = anyOptions.output;
|
|
7718
8402
|
anyPart.errorText = anyOptions.errorText;
|
|
7719
|
-
anyPart.rawInput = (
|
|
8403
|
+
anyPart.rawInput = (_a2222 = anyOptions.rawInput) != null ? _a2222 : anyPart.rawInput;
|
|
7720
8404
|
anyPart.preliminary = anyOptions.preliminary;
|
|
7721
8405
|
if (options.title !== void 0) {
|
|
7722
8406
|
anyPart.title = options.title;
|
|
7723
8407
|
}
|
|
7724
8408
|
anyPart.providerExecuted = (_b222 = anyOptions.providerExecuted) != null ? _b222 : part.providerExecuted;
|
|
7725
|
-
if (anyOptions.providerMetadata != null
|
|
8409
|
+
if (anyOptions.providerMetadata != null) {
|
|
7726
8410
|
part.callProviderMetadata = anyOptions.providerMetadata;
|
|
7727
8411
|
}
|
|
7728
8412
|
} else {
|
|
@@ -7747,7 +8431,11 @@ function processUIMessageStream({
|
|
|
7747
8431
|
if (messageMetadataSchema != null) {
|
|
7748
8432
|
await validateTypes({
|
|
7749
8433
|
value: mergedMetadata,
|
|
7750
|
-
schema: messageMetadataSchema
|
|
8434
|
+
schema: messageMetadataSchema,
|
|
8435
|
+
context: {
|
|
8436
|
+
field: "message.metadata",
|
|
8437
|
+
entityId: state.message.id
|
|
8438
|
+
}
|
|
7751
8439
|
});
|
|
7752
8440
|
}
|
|
7753
8441
|
state.message.metadata = mergedMetadata;
|
|
@@ -7768,13 +8456,27 @@ function processUIMessageStream({
|
|
|
7768
8456
|
}
|
|
7769
8457
|
case "text-delta": {
|
|
7770
8458
|
const textPart = state.activeTextParts[chunk.id];
|
|
8459
|
+
if (textPart == null) {
|
|
8460
|
+
throw new UIMessageStreamError({
|
|
8461
|
+
chunkType: "text-delta",
|
|
8462
|
+
chunkId: chunk.id,
|
|
8463
|
+
message: `Received text-delta for missing text part with ID "${chunk.id}". Ensure a "text-start" chunk is sent before any "text-delta" chunks.`
|
|
8464
|
+
});
|
|
8465
|
+
}
|
|
7771
8466
|
textPart.text += chunk.delta;
|
|
7772
|
-
textPart.providerMetadata = (
|
|
8467
|
+
textPart.providerMetadata = (_a21 = chunk.providerMetadata) != null ? _a21 : textPart.providerMetadata;
|
|
7773
8468
|
write();
|
|
7774
8469
|
break;
|
|
7775
8470
|
}
|
|
7776
8471
|
case "text-end": {
|
|
7777
8472
|
const textPart = state.activeTextParts[chunk.id];
|
|
8473
|
+
if (textPart == null) {
|
|
8474
|
+
throw new UIMessageStreamError({
|
|
8475
|
+
chunkType: "text-end",
|
|
8476
|
+
chunkId: chunk.id,
|
|
8477
|
+
message: `Received text-end for missing text part with ID "${chunk.id}". Ensure a "text-start" chunk is sent before any "text-end" chunks.`
|
|
8478
|
+
});
|
|
8479
|
+
}
|
|
7778
8480
|
textPart.state = "done";
|
|
7779
8481
|
textPart.providerMetadata = (_b82 = chunk.providerMetadata) != null ? _b82 : textPart.providerMetadata;
|
|
7780
8482
|
delete state.activeTextParts[chunk.id];
|
|
@@ -7795,6 +8497,13 @@ function processUIMessageStream({
|
|
|
7795
8497
|
}
|
|
7796
8498
|
case "reasoning-delta": {
|
|
7797
8499
|
const reasoningPart = state.activeReasoningParts[chunk.id];
|
|
8500
|
+
if (reasoningPart == null) {
|
|
8501
|
+
throw new UIMessageStreamError({
|
|
8502
|
+
chunkType: "reasoning-delta",
|
|
8503
|
+
chunkId: chunk.id,
|
|
8504
|
+
message: `Received reasoning-delta for missing reasoning part with ID "${chunk.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-delta" chunks.`
|
|
8505
|
+
});
|
|
8506
|
+
}
|
|
7798
8507
|
reasoningPart.text += chunk.delta;
|
|
7799
8508
|
reasoningPart.providerMetadata = (_c = chunk.providerMetadata) != null ? _c : reasoningPart.providerMetadata;
|
|
7800
8509
|
write();
|
|
@@ -7802,6 +8511,13 @@ function processUIMessageStream({
|
|
|
7802
8511
|
}
|
|
7803
8512
|
case "reasoning-end": {
|
|
7804
8513
|
const reasoningPart = state.activeReasoningParts[chunk.id];
|
|
8514
|
+
if (reasoningPart == null) {
|
|
8515
|
+
throw new UIMessageStreamError({
|
|
8516
|
+
chunkType: "reasoning-end",
|
|
8517
|
+
chunkId: chunk.id,
|
|
8518
|
+
message: `Received reasoning-end for missing reasoning part with ID "${chunk.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-end" chunks.`
|
|
8519
|
+
});
|
|
8520
|
+
}
|
|
7805
8521
|
reasoningPart.providerMetadata = (_d = chunk.providerMetadata) != null ? _d : reasoningPart.providerMetadata;
|
|
7806
8522
|
reasoningPart.state = "done";
|
|
7807
8523
|
delete state.activeReasoningParts[chunk.id];
|
|
@@ -7856,7 +8572,8 @@ function processUIMessageStream({
|
|
|
7856
8572
|
state: "input-streaming",
|
|
7857
8573
|
input: void 0,
|
|
7858
8574
|
providerExecuted: chunk.providerExecuted,
|
|
7859
|
-
title: chunk.title
|
|
8575
|
+
title: chunk.title,
|
|
8576
|
+
providerMetadata: chunk.providerMetadata
|
|
7860
8577
|
});
|
|
7861
8578
|
} else {
|
|
7862
8579
|
updateToolPart({
|
|
@@ -7865,7 +8582,8 @@ function processUIMessageStream({
|
|
|
7865
8582
|
state: "input-streaming",
|
|
7866
8583
|
input: void 0,
|
|
7867
8584
|
providerExecuted: chunk.providerExecuted,
|
|
7868
|
-
title: chunk.title
|
|
8585
|
+
title: chunk.title,
|
|
8586
|
+
providerMetadata: chunk.providerMetadata
|
|
7869
8587
|
});
|
|
7870
8588
|
}
|
|
7871
8589
|
write();
|
|
@@ -7873,6 +8591,13 @@ function processUIMessageStream({
|
|
|
7873
8591
|
}
|
|
7874
8592
|
case "tool-input-delta": {
|
|
7875
8593
|
const partialToolCall = state.partialToolCalls[chunk.toolCallId];
|
|
8594
|
+
if (partialToolCall == null) {
|
|
8595
|
+
throw new UIMessageStreamError({
|
|
8596
|
+
chunkType: "tool-input-delta",
|
|
8597
|
+
chunkId: chunk.toolCallId,
|
|
8598
|
+
message: `Received tool-input-delta for missing tool call with ID "${chunk.toolCallId}". Ensure a "tool-input-start" chunk is sent before any "tool-input-delta" chunks.`
|
|
8599
|
+
});
|
|
8600
|
+
}
|
|
7876
8601
|
partialToolCall.text += chunk.inputTextDelta;
|
|
7877
8602
|
const { value: partialArgs } = await parsePartialJson(
|
|
7878
8603
|
partialToolCall.text
|
|
@@ -8064,9 +8789,18 @@ function processUIMessageStream({
|
|
|
8064
8789
|
default: {
|
|
8065
8790
|
if (isDataUIMessageChunk(chunk)) {
|
|
8066
8791
|
if ((dataPartSchemas == null ? void 0 : dataPartSchemas[chunk.type]) != null) {
|
|
8792
|
+
const partIdx = state.message.parts.findIndex(
|
|
8793
|
+
(p) => "id" in p && "data" in p && p.id === chunk.id && p.type === chunk.type
|
|
8794
|
+
);
|
|
8795
|
+
const actualPartIdx = partIdx >= 0 ? partIdx : state.message.parts.length;
|
|
8067
8796
|
await validateTypes({
|
|
8068
8797
|
value: chunk.data,
|
|
8069
|
-
schema: dataPartSchemas[chunk.type]
|
|
8798
|
+
schema: dataPartSchemas[chunk.type],
|
|
8799
|
+
context: {
|
|
8800
|
+
field: `message.parts[${actualPartIdx}].data`,
|
|
8801
|
+
entityName: chunk.type,
|
|
8802
|
+
entityId: chunk.id
|
|
8803
|
+
}
|
|
8070
8804
|
});
|
|
8071
8805
|
}
|
|
8072
8806
|
const dataChunk = chunk;
|
|
@@ -8202,11 +8936,13 @@ function createAsyncIterableStream(source) {
|
|
|
8202
8936
|
const reader = this.getReader();
|
|
8203
8937
|
let finished = false;
|
|
8204
8938
|
async function cleanup(cancelStream) {
|
|
8205
|
-
var
|
|
8939
|
+
var _a21;
|
|
8940
|
+
if (finished)
|
|
8941
|
+
return;
|
|
8206
8942
|
finished = true;
|
|
8207
8943
|
try {
|
|
8208
8944
|
{
|
|
8209
|
-
await ((
|
|
8945
|
+
await ((_a21 = reader.cancel) == null ? void 0 : _a21.call(reader));
|
|
8210
8946
|
}
|
|
8211
8947
|
} finally {
|
|
8212
8948
|
try {
|
|
@@ -8232,7 +8968,7 @@ function createAsyncIterableStream(source) {
|
|
|
8232
8968
|
return { done: false, value };
|
|
8233
8969
|
},
|
|
8234
8970
|
/**
|
|
8235
|
-
*
|
|
8971
|
+
* May be called on early exit (e.g., break from for-await) or after completion.
|
|
8236
8972
|
* Ensures the stream is cancelled and resources are released.
|
|
8237
8973
|
* @returns A promise resolving to a completed IteratorResult.
|
|
8238
8974
|
*/
|
|
@@ -8364,8 +9100,8 @@ function createStitchableStream() {
|
|
|
8364
9100
|
};
|
|
8365
9101
|
}
|
|
8366
9102
|
function now() {
|
|
8367
|
-
var
|
|
8368
|
-
return (_b82 = (
|
|
9103
|
+
var _a21, _b82;
|
|
9104
|
+
return (_b82 = (_a21 = globalThis == null ? void 0 : globalThis.performance) == null ? void 0 : _a21.now()) != null ? _b82 : Date.now();
|
|
8369
9105
|
}
|
|
8370
9106
|
function runToolsTransformation({
|
|
8371
9107
|
tools,
|
|
@@ -8387,6 +9123,7 @@ function runToolsTransformation({
|
|
|
8387
9123
|
});
|
|
8388
9124
|
const outstandingToolResults = /* @__PURE__ */ new Set();
|
|
8389
9125
|
const toolInputs = /* @__PURE__ */ new Map();
|
|
9126
|
+
const toolCallsByToolCallId = /* @__PURE__ */ new Map();
|
|
8390
9127
|
let canClose = false;
|
|
8391
9128
|
let finishChunk = void 0;
|
|
8392
9129
|
function attemptClose() {
|
|
@@ -8438,6 +9175,25 @@ function runToolsTransformation({
|
|
|
8438
9175
|
};
|
|
8439
9176
|
break;
|
|
8440
9177
|
}
|
|
9178
|
+
case "tool-approval-request": {
|
|
9179
|
+
const toolCall = toolCallsByToolCallId.get(chunk.toolCallId);
|
|
9180
|
+
if (toolCall == null) {
|
|
9181
|
+
toolResultsStreamController.enqueue({
|
|
9182
|
+
type: "error",
|
|
9183
|
+
error: new ToolCallNotFoundForApprovalError({
|
|
9184
|
+
toolCallId: chunk.toolCallId,
|
|
9185
|
+
approvalId: chunk.approvalId
|
|
9186
|
+
})
|
|
9187
|
+
});
|
|
9188
|
+
break;
|
|
9189
|
+
}
|
|
9190
|
+
controller.enqueue({
|
|
9191
|
+
type: "tool-approval-request",
|
|
9192
|
+
approvalId: chunk.approvalId,
|
|
9193
|
+
toolCall
|
|
9194
|
+
});
|
|
9195
|
+
break;
|
|
9196
|
+
}
|
|
8441
9197
|
case "tool-call": {
|
|
8442
9198
|
try {
|
|
8443
9199
|
const toolCall = await parseToolCall({
|
|
@@ -8447,6 +9203,7 @@ function runToolsTransformation({
|
|
|
8447
9203
|
system,
|
|
8448
9204
|
messages
|
|
8449
9205
|
});
|
|
9206
|
+
toolCallsByToolCallId.set(toolCall.toolCallId, toolCall);
|
|
8450
9207
|
controller.enqueue(toolCall);
|
|
8451
9208
|
if (toolCall.invalid) {
|
|
8452
9209
|
toolResultsStreamController.enqueue({
|
|
@@ -8503,6 +9260,12 @@ function runToolsTransformation({
|
|
|
8503
9260
|
}
|
|
8504
9261
|
}).then((result) => {
|
|
8505
9262
|
toolResultsStreamController.enqueue(result);
|
|
9263
|
+
}).catch((error) => {
|
|
9264
|
+
toolResultsStreamController.enqueue({
|
|
9265
|
+
type: "error",
|
|
9266
|
+
error
|
|
9267
|
+
});
|
|
9268
|
+
}).finally(() => {
|
|
8506
9269
|
outstandingToolResults.delete(toolExecutionId);
|
|
8507
9270
|
attemptClose();
|
|
8508
9271
|
});
|
|
@@ -8537,9 +9300,6 @@ function runToolsTransformation({
|
|
|
8537
9300
|
}
|
|
8538
9301
|
break;
|
|
8539
9302
|
}
|
|
8540
|
-
case "tool-approval-request": {
|
|
8541
|
-
break;
|
|
8542
|
-
}
|
|
8543
9303
|
default: {
|
|
8544
9304
|
const _exhaustiveCheck = chunkType;
|
|
8545
9305
|
throw new Error(`Unhandled chunk type: ${_exhaustiveCheck}`);
|
|
@@ -8590,6 +9350,7 @@ function streamText({
|
|
|
8590
9350
|
messages,
|
|
8591
9351
|
maxRetries,
|
|
8592
9352
|
abortSignal,
|
|
9353
|
+
timeout,
|
|
8593
9354
|
headers,
|
|
8594
9355
|
stopWhen = stepCountIs(1),
|
|
8595
9356
|
experimental_output,
|
|
@@ -8611,20 +9372,31 @@ function streamText({
|
|
|
8611
9372
|
onAbort,
|
|
8612
9373
|
onStepFinish,
|
|
8613
9374
|
experimental_context,
|
|
8614
|
-
|
|
8615
|
-
|
|
8616
|
-
generateId: generateId2 = originalGenerateId2,
|
|
8617
|
-
currentDate = () => /* @__PURE__ */ new Date()
|
|
8618
|
-
} = {},
|
|
9375
|
+
experimental_include: include,
|
|
9376
|
+
_internal: { now: now2 = now, generateId: generateId2 = originalGenerateId2 } = {},
|
|
8619
9377
|
...settings
|
|
8620
9378
|
}) {
|
|
9379
|
+
const totalTimeoutMs = getTotalTimeoutMs(timeout);
|
|
9380
|
+
const stepTimeoutMs = getStepTimeoutMs(timeout);
|
|
9381
|
+
const chunkTimeoutMs = getChunkTimeoutMs(timeout);
|
|
9382
|
+
const stepAbortController = stepTimeoutMs != null ? new AbortController() : void 0;
|
|
9383
|
+
const chunkAbortController = chunkTimeoutMs != null ? new AbortController() : void 0;
|
|
8621
9384
|
return new DefaultStreamTextResult({
|
|
8622
9385
|
model: resolveLanguageModel(model),
|
|
8623
9386
|
telemetry,
|
|
8624
9387
|
headers,
|
|
8625
9388
|
settings,
|
|
8626
9389
|
maxRetries,
|
|
8627
|
-
abortSignal
|
|
9390
|
+
abortSignal: mergeAbortSignals(
|
|
9391
|
+
abortSignal,
|
|
9392
|
+
totalTimeoutMs != null ? AbortSignal.timeout(totalTimeoutMs) : void 0,
|
|
9393
|
+
stepAbortController == null ? void 0 : stepAbortController.signal,
|
|
9394
|
+
chunkAbortController == null ? void 0 : chunkAbortController.signal
|
|
9395
|
+
),
|
|
9396
|
+
stepTimeoutMs,
|
|
9397
|
+
stepAbortController,
|
|
9398
|
+
chunkTimeoutMs,
|
|
9399
|
+
chunkAbortController,
|
|
8628
9400
|
system,
|
|
8629
9401
|
prompt,
|
|
8630
9402
|
messages,
|
|
@@ -8644,10 +9416,10 @@ function streamText({
|
|
|
8644
9416
|
onAbort,
|
|
8645
9417
|
onStepFinish,
|
|
8646
9418
|
now: now2,
|
|
8647
|
-
currentDate,
|
|
8648
9419
|
generateId: generateId2,
|
|
8649
9420
|
experimental_context,
|
|
8650
|
-
download: download2
|
|
9421
|
+
download: download2,
|
|
9422
|
+
include
|
|
8651
9423
|
});
|
|
8652
9424
|
}
|
|
8653
9425
|
function createOutputTransformStream(output) {
|
|
@@ -8673,7 +9445,7 @@ function createOutputTransformStream(output) {
|
|
|
8673
9445
|
}
|
|
8674
9446
|
return new TransformStream({
|
|
8675
9447
|
async transform(chunk, controller) {
|
|
8676
|
-
var
|
|
9448
|
+
var _a21;
|
|
8677
9449
|
if (chunk.type === "finish-step" && textChunk.length > 0) {
|
|
8678
9450
|
publishTextChunk({ controller });
|
|
8679
9451
|
}
|
|
@@ -8700,7 +9472,7 @@ function createOutputTransformStream(output) {
|
|
|
8700
9472
|
}
|
|
8701
9473
|
text2 += chunk.text;
|
|
8702
9474
|
textChunk += chunk.text;
|
|
8703
|
-
textProviderMetadata = (
|
|
9475
|
+
textProviderMetadata = (_a21 = chunk.providerMetadata) != null ? _a21 : textProviderMetadata;
|
|
8704
9476
|
const result = await output.parsePartialOutput({ text: text2 });
|
|
8705
9477
|
if (result !== void 0) {
|
|
8706
9478
|
const currentJson = JSON.stringify(result.partial);
|
|
@@ -8720,6 +9492,10 @@ var DefaultStreamTextResult = class {
|
|
|
8720
9492
|
settings,
|
|
8721
9493
|
maxRetries: maxRetriesArg,
|
|
8722
9494
|
abortSignal,
|
|
9495
|
+
stepTimeoutMs,
|
|
9496
|
+
stepAbortController,
|
|
9497
|
+
chunkTimeoutMs,
|
|
9498
|
+
chunkAbortController,
|
|
8723
9499
|
system,
|
|
8724
9500
|
prompt,
|
|
8725
9501
|
messages,
|
|
@@ -8734,7 +9510,6 @@ var DefaultStreamTextResult = class {
|
|
|
8734
9510
|
prepareStep,
|
|
8735
9511
|
includeRawChunks,
|
|
8736
9512
|
now: now2,
|
|
8737
|
-
currentDate,
|
|
8738
9513
|
generateId: generateId2,
|
|
8739
9514
|
onChunk,
|
|
8740
9515
|
onError,
|
|
@@ -8742,7 +9517,8 @@ var DefaultStreamTextResult = class {
|
|
|
8742
9517
|
onAbort,
|
|
8743
9518
|
onStepFinish,
|
|
8744
9519
|
experimental_context,
|
|
8745
|
-
download: download2
|
|
9520
|
+
download: download2,
|
|
9521
|
+
include
|
|
8746
9522
|
}) {
|
|
8747
9523
|
this._totalUsage = new DelayedPromise();
|
|
8748
9524
|
this._finishReason = new DelayedPromise();
|
|
@@ -8766,7 +9542,7 @@ var DefaultStreamTextResult = class {
|
|
|
8766
9542
|
let activeReasoningContent = {};
|
|
8767
9543
|
const eventProcessor = new TransformStream({
|
|
8768
9544
|
async transform(chunk, controller) {
|
|
8769
|
-
var
|
|
9545
|
+
var _a21, _b82, _c, _d;
|
|
8770
9546
|
controller.enqueue(chunk);
|
|
8771
9547
|
const { part } = chunk;
|
|
8772
9548
|
if (part.type === "text-delta" || part.type === "reasoning-delta" || part.type === "source" || part.type === "tool-call" || part.type === "tool-result" || part.type === "tool-input-start" || part.type === "tool-input-delta" || part.type === "raw") {
|
|
@@ -8796,7 +9572,7 @@ var DefaultStreamTextResult = class {
|
|
|
8796
9572
|
return;
|
|
8797
9573
|
}
|
|
8798
9574
|
activeText.text += part.text;
|
|
8799
|
-
activeText.providerMetadata = (
|
|
9575
|
+
activeText.providerMetadata = (_a21 = part.providerMetadata) != null ? _a21 : activeText.providerMetadata;
|
|
8800
9576
|
}
|
|
8801
9577
|
if (part.type === "text-end") {
|
|
8802
9578
|
const activeText = activeTextContent[part.id];
|
|
@@ -8913,7 +9689,7 @@ var DefaultStreamTextResult = class {
|
|
|
8913
9689
|
async flush(controller) {
|
|
8914
9690
|
try {
|
|
8915
9691
|
if (recordedSteps.length === 0) {
|
|
8916
|
-
const error = new NoOutputGeneratedError({
|
|
9692
|
+
const error = (abortSignal == null ? void 0 : abortSignal.aborted) ? abortSignal.reason : new NoOutputGeneratedError({
|
|
8917
9693
|
message: "No output generated. Check the stream for errors."
|
|
8918
9694
|
});
|
|
8919
9695
|
self._finishReason.reject(error);
|
|
@@ -8961,8 +9737,8 @@ var DefaultStreamTextResult = class {
|
|
|
8961
9737
|
"ai.response.text": { output: () => finalStep.text },
|
|
8962
9738
|
"ai.response.toolCalls": {
|
|
8963
9739
|
output: () => {
|
|
8964
|
-
var
|
|
8965
|
-
return ((
|
|
9740
|
+
var _a21;
|
|
9741
|
+
return ((_a21 = finalStep.toolCalls) == null ? void 0 : _a21.length) ? JSON.stringify(finalStep.toolCalls) : void 0;
|
|
8966
9742
|
}
|
|
8967
9743
|
},
|
|
8968
9744
|
"ai.response.providerMetadata": JSON.stringify(
|
|
@@ -8994,7 +9770,13 @@ var DefaultStreamTextResult = class {
|
|
|
8994
9770
|
async pull(controller) {
|
|
8995
9771
|
function abort() {
|
|
8996
9772
|
onAbort == null ? void 0 : onAbort({ steps: recordedSteps });
|
|
8997
|
-
controller.enqueue({
|
|
9773
|
+
controller.enqueue({
|
|
9774
|
+
type: "abort",
|
|
9775
|
+
// The `reason` is usually of type DOMException, but it can also be of any type,
|
|
9776
|
+
// so we use getErrorMessage for serialization because it is already designed to accept values of the unknown type.
|
|
9777
|
+
// See: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/reason
|
|
9778
|
+
...(abortSignal == null ? void 0 : abortSignal.reason) !== void 0 ? { reason: getErrorMessage(abortSignal.reason) } : {}
|
|
9779
|
+
});
|
|
8998
9780
|
controller.close();
|
|
8999
9781
|
}
|
|
9000
9782
|
try {
|
|
@@ -9070,6 +9852,19 @@ var DefaultStreamTextResult = class {
|
|
|
9070
9852
|
const initialResponseMessages = [];
|
|
9071
9853
|
const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({ messages: initialMessages });
|
|
9072
9854
|
if (deniedToolApprovals.length > 0 || approvedToolApprovals.length > 0) {
|
|
9855
|
+
const providerExecutedToolApprovals = [
|
|
9856
|
+
...approvedToolApprovals,
|
|
9857
|
+
...deniedToolApprovals
|
|
9858
|
+
].filter((toolApproval) => toolApproval.toolCall.providerExecuted);
|
|
9859
|
+
const localApprovedToolApprovals = approvedToolApprovals.filter(
|
|
9860
|
+
(toolApproval) => !toolApproval.toolCall.providerExecuted
|
|
9861
|
+
);
|
|
9862
|
+
const localDeniedToolApprovals = deniedToolApprovals.filter(
|
|
9863
|
+
(toolApproval) => !toolApproval.toolCall.providerExecuted
|
|
9864
|
+
);
|
|
9865
|
+
const deniedProviderExecutedToolApprovals = deniedToolApprovals.filter(
|
|
9866
|
+
(toolApproval) => toolApproval.toolCall.providerExecuted
|
|
9867
|
+
);
|
|
9073
9868
|
let toolExecutionStepStreamController;
|
|
9074
9869
|
const toolExecutionStepStream = new ReadableStream({
|
|
9075
9870
|
start(controller) {
|
|
@@ -9078,7 +9873,10 @@ var DefaultStreamTextResult = class {
|
|
|
9078
9873
|
});
|
|
9079
9874
|
self.addStream(toolExecutionStepStream);
|
|
9080
9875
|
try {
|
|
9081
|
-
for (const toolApproval of
|
|
9876
|
+
for (const toolApproval of [
|
|
9877
|
+
...localDeniedToolApprovals,
|
|
9878
|
+
...deniedProviderExecutedToolApprovals
|
|
9879
|
+
]) {
|
|
9082
9880
|
toolExecutionStepStreamController == null ? void 0 : toolExecutionStepStreamController.enqueue({
|
|
9083
9881
|
type: "tool-output-denied",
|
|
9084
9882
|
toolCallId: toolApproval.toolCall.toolCallId,
|
|
@@ -9087,7 +9885,7 @@ var DefaultStreamTextResult = class {
|
|
|
9087
9885
|
}
|
|
9088
9886
|
const toolOutputs = [];
|
|
9089
9887
|
await Promise.all(
|
|
9090
|
-
|
|
9888
|
+
localApprovedToolApprovals.map(async (toolApproval) => {
|
|
9091
9889
|
const result = await executeToolCall({
|
|
9092
9890
|
toolCall: toolApproval.toolCall,
|
|
9093
9891
|
tools,
|
|
@@ -9106,36 +9904,52 @@ var DefaultStreamTextResult = class {
|
|
|
9106
9904
|
}
|
|
9107
9905
|
})
|
|
9108
9906
|
);
|
|
9109
|
-
|
|
9110
|
-
|
|
9111
|
-
|
|
9112
|
-
|
|
9113
|
-
|
|
9114
|
-
|
|
9115
|
-
|
|
9116
|
-
|
|
9117
|
-
|
|
9118
|
-
|
|
9119
|
-
|
|
9120
|
-
|
|
9121
|
-
})
|
|
9907
|
+
if (providerExecutedToolApprovals.length > 0) {
|
|
9908
|
+
initialResponseMessages.push({
|
|
9909
|
+
role: "tool",
|
|
9910
|
+
content: providerExecutedToolApprovals.map(
|
|
9911
|
+
(toolApproval) => ({
|
|
9912
|
+
type: "tool-approval-response",
|
|
9913
|
+
approvalId: toolApproval.approvalResponse.approvalId,
|
|
9914
|
+
approved: toolApproval.approvalResponse.approved,
|
|
9915
|
+
reason: toolApproval.approvalResponse.reason,
|
|
9916
|
+
providerExecuted: true
|
|
9917
|
+
})
|
|
9918
|
+
)
|
|
9122
9919
|
});
|
|
9123
9920
|
}
|
|
9124
|
-
|
|
9125
|
-
|
|
9126
|
-
|
|
9127
|
-
|
|
9128
|
-
|
|
9129
|
-
|
|
9130
|
-
|
|
9131
|
-
|
|
9132
|
-
|
|
9921
|
+
if (toolOutputs.length > 0 || localDeniedToolApprovals.length > 0) {
|
|
9922
|
+
const localToolContent = [];
|
|
9923
|
+
for (const output2 of toolOutputs) {
|
|
9924
|
+
localToolContent.push({
|
|
9925
|
+
type: "tool-result",
|
|
9926
|
+
toolCallId: output2.toolCallId,
|
|
9927
|
+
toolName: output2.toolName,
|
|
9928
|
+
output: await createToolModelOutput({
|
|
9929
|
+
toolCallId: output2.toolCallId,
|
|
9930
|
+
input: output2.input,
|
|
9931
|
+
tool: tools == null ? void 0 : tools[output2.toolName],
|
|
9932
|
+
output: output2.type === "tool-result" ? output2.output : output2.error,
|
|
9933
|
+
errorMode: output2.type === "tool-error" ? "json" : "none"
|
|
9934
|
+
})
|
|
9935
|
+
});
|
|
9936
|
+
}
|
|
9937
|
+
for (const toolApproval of localDeniedToolApprovals) {
|
|
9938
|
+
localToolContent.push({
|
|
9939
|
+
type: "tool-result",
|
|
9940
|
+
toolCallId: toolApproval.toolCall.toolCallId,
|
|
9941
|
+
toolName: toolApproval.toolCall.toolName,
|
|
9942
|
+
output: {
|
|
9943
|
+
type: "execution-denied",
|
|
9944
|
+
reason: toolApproval.approvalResponse.reason
|
|
9945
|
+
}
|
|
9946
|
+
});
|
|
9947
|
+
}
|
|
9948
|
+
initialResponseMessages.push({
|
|
9949
|
+
role: "tool",
|
|
9950
|
+
content: localToolContent
|
|
9133
9951
|
});
|
|
9134
9952
|
}
|
|
9135
|
-
initialResponseMessages.push({
|
|
9136
|
-
role: "tool",
|
|
9137
|
-
content
|
|
9138
|
-
});
|
|
9139
9953
|
} finally {
|
|
9140
9954
|
toolExecutionStepStreamController == null ? void 0 : toolExecutionStepStreamController.close();
|
|
9141
9955
|
}
|
|
@@ -9146,407 +9960,446 @@ var DefaultStreamTextResult = class {
|
|
|
9146
9960
|
responseMessages,
|
|
9147
9961
|
usage
|
|
9148
9962
|
}) {
|
|
9149
|
-
var
|
|
9963
|
+
var _a21, _b82, _c, _d, _e, _f, _g;
|
|
9150
9964
|
const includeRawChunks2 = self.includeRawChunks;
|
|
9151
|
-
|
|
9152
|
-
|
|
9153
|
-
|
|
9154
|
-
|
|
9155
|
-
|
|
9156
|
-
|
|
9157
|
-
|
|
9158
|
-
|
|
9159
|
-
|
|
9160
|
-
|
|
9161
|
-
|
|
9162
|
-
|
|
9163
|
-
|
|
9164
|
-
|
|
9165
|
-
|
|
9166
|
-
|
|
9167
|
-
|
|
9168
|
-
|
|
9169
|
-
|
|
9170
|
-
|
|
9171
|
-
|
|
9172
|
-
|
|
9173
|
-
|
|
9174
|
-
|
|
9175
|
-
|
|
9176
|
-
|
|
9177
|
-
|
|
9178
|
-
|
|
9179
|
-
|
|
9180
|
-
|
|
9181
|
-
|
|
9182
|
-
|
|
9183
|
-
|
|
9184
|
-
|
|
9185
|
-
|
|
9186
|
-
|
|
9187
|
-
|
|
9188
|
-
|
|
9189
|
-
|
|
9190
|
-
|
|
9191
|
-
|
|
9192
|
-
|
|
9193
|
-
|
|
9194
|
-
|
|
9195
|
-
|
|
9196
|
-
|
|
9197
|
-
|
|
9198
|
-
|
|
9199
|
-
|
|
9200
|
-
|
|
9201
|
-
|
|
9202
|
-
|
|
9203
|
-
|
|
9204
|
-
|
|
9205
|
-
|
|
9206
|
-
|
|
9207
|
-
|
|
9208
|
-
|
|
9209
|
-
|
|
9210
|
-
|
|
9211
|
-
|
|
9212
|
-
|
|
9213
|
-
|
|
9214
|
-
|
|
9215
|
-
|
|
9216
|
-
|
|
9217
|
-
|
|
9218
|
-
|
|
9219
|
-
|
|
9220
|
-
|
|
9221
|
-
|
|
9222
|
-
|
|
9223
|
-
|
|
9224
|
-
|
|
9225
|
-
|
|
9226
|
-
|
|
9227
|
-
|
|
9228
|
-
|
|
9229
|
-
|
|
9230
|
-
|
|
9231
|
-
|
|
9232
|
-
|
|
9233
|
-
|
|
9234
|
-
|
|
9235
|
-
|
|
9236
|
-
|
|
9237
|
-
|
|
9965
|
+
const stepTimeoutId = stepTimeoutMs != null ? setTimeout(() => stepAbortController.abort(), stepTimeoutMs) : void 0;
|
|
9966
|
+
let chunkTimeoutId = void 0;
|
|
9967
|
+
function resetChunkTimeout() {
|
|
9968
|
+
if (chunkTimeoutMs != null) {
|
|
9969
|
+
if (chunkTimeoutId != null) {
|
|
9970
|
+
clearTimeout(chunkTimeoutId);
|
|
9971
|
+
}
|
|
9972
|
+
chunkTimeoutId = setTimeout(
|
|
9973
|
+
() => chunkAbortController.abort(),
|
|
9974
|
+
chunkTimeoutMs
|
|
9975
|
+
);
|
|
9976
|
+
}
|
|
9977
|
+
}
|
|
9978
|
+
function clearChunkTimeout() {
|
|
9979
|
+
if (chunkTimeoutId != null) {
|
|
9980
|
+
clearTimeout(chunkTimeoutId);
|
|
9981
|
+
chunkTimeoutId = void 0;
|
|
9982
|
+
}
|
|
9983
|
+
}
|
|
9984
|
+
function clearStepTimeout() {
|
|
9985
|
+
if (stepTimeoutId != null) {
|
|
9986
|
+
clearTimeout(stepTimeoutId);
|
|
9987
|
+
}
|
|
9988
|
+
}
|
|
9989
|
+
try {
|
|
9990
|
+
stepFinish = new DelayedPromise();
|
|
9991
|
+
const stepInputMessages = [...initialMessages, ...responseMessages];
|
|
9992
|
+
const prepareStepResult = await (prepareStep == null ? void 0 : prepareStep({
|
|
9993
|
+
model,
|
|
9994
|
+
steps: recordedSteps,
|
|
9995
|
+
stepNumber: recordedSteps.length,
|
|
9996
|
+
messages: stepInputMessages,
|
|
9997
|
+
experimental_context
|
|
9998
|
+
}));
|
|
9999
|
+
const stepModel = resolveLanguageModel(
|
|
10000
|
+
(_a21 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a21 : model
|
|
10001
|
+
);
|
|
10002
|
+
const promptMessages = await convertToLanguageModelPrompt({
|
|
10003
|
+
prompt: {
|
|
10004
|
+
system: (_b82 = prepareStepResult == null ? void 0 : prepareStepResult.system) != null ? _b82 : initialPrompt.system,
|
|
10005
|
+
messages: (_c = prepareStepResult == null ? void 0 : prepareStepResult.messages) != null ? _c : stepInputMessages
|
|
10006
|
+
},
|
|
10007
|
+
supportedUrls: await stepModel.supportedUrls,
|
|
10008
|
+
download: download2
|
|
10009
|
+
});
|
|
10010
|
+
const { toolChoice: stepToolChoice, tools: stepTools } = await prepareToolsAndToolChoice({
|
|
10011
|
+
tools,
|
|
10012
|
+
toolChoice: (_d = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _d : toolChoice,
|
|
10013
|
+
activeTools: (_e = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _e : activeTools
|
|
10014
|
+
});
|
|
10015
|
+
experimental_context = (_f = prepareStepResult == null ? void 0 : prepareStepResult.experimental_context) != null ? _f : experimental_context;
|
|
10016
|
+
const stepProviderOptions = mergeObjects(
|
|
10017
|
+
providerOptions,
|
|
10018
|
+
prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
|
|
10019
|
+
);
|
|
10020
|
+
const {
|
|
10021
|
+
result: { stream: stream2, response, request },
|
|
10022
|
+
doStreamSpan,
|
|
10023
|
+
startTimestampMs
|
|
10024
|
+
} = await retry(
|
|
10025
|
+
() => recordSpan({
|
|
10026
|
+
name: "ai.streamText.doStream",
|
|
10027
|
+
attributes: selectTelemetryAttributes({
|
|
10028
|
+
telemetry,
|
|
10029
|
+
attributes: {
|
|
10030
|
+
...assembleOperationName({
|
|
10031
|
+
operationId: "ai.streamText.doStream",
|
|
10032
|
+
telemetry
|
|
10033
|
+
}),
|
|
10034
|
+
...baseTelemetryAttributes,
|
|
10035
|
+
// model:
|
|
10036
|
+
"ai.model.provider": stepModel.provider,
|
|
10037
|
+
"ai.model.id": stepModel.modelId,
|
|
10038
|
+
// prompt:
|
|
10039
|
+
"ai.prompt.messages": {
|
|
10040
|
+
input: () => stringifyForTelemetry(promptMessages)
|
|
10041
|
+
},
|
|
10042
|
+
"ai.prompt.tools": {
|
|
10043
|
+
// convert the language model level tools:
|
|
10044
|
+
input: () => stepTools == null ? void 0 : stepTools.map((tool2) => JSON.stringify(tool2))
|
|
10045
|
+
},
|
|
10046
|
+
"ai.prompt.toolChoice": {
|
|
10047
|
+
input: () => stepToolChoice != null ? JSON.stringify(stepToolChoice) : void 0
|
|
10048
|
+
},
|
|
10049
|
+
// standardized gen-ai llm span attributes:
|
|
10050
|
+
"gen_ai.system": stepModel.provider,
|
|
10051
|
+
"gen_ai.request.model": stepModel.modelId,
|
|
10052
|
+
"gen_ai.request.frequency_penalty": callSettings.frequencyPenalty,
|
|
10053
|
+
"gen_ai.request.max_tokens": callSettings.maxOutputTokens,
|
|
10054
|
+
"gen_ai.request.presence_penalty": callSettings.presencePenalty,
|
|
10055
|
+
"gen_ai.request.stop_sequences": callSettings.stopSequences,
|
|
10056
|
+
"gen_ai.request.temperature": callSettings.temperature,
|
|
10057
|
+
"gen_ai.request.top_k": callSettings.topK,
|
|
10058
|
+
"gen_ai.request.top_p": callSettings.topP
|
|
10059
|
+
}
|
|
10060
|
+
}),
|
|
10061
|
+
tracer,
|
|
10062
|
+
endWhenDone: false,
|
|
10063
|
+
fn: async (doStreamSpan2) => ({
|
|
10064
|
+
startTimestampMs: now2(),
|
|
10065
|
+
// get before the call
|
|
10066
|
+
doStreamSpan: doStreamSpan2,
|
|
10067
|
+
result: await stepModel.doStream({
|
|
10068
|
+
...callSettings,
|
|
10069
|
+
tools: stepTools,
|
|
10070
|
+
toolChoice: stepToolChoice,
|
|
10071
|
+
responseFormat: await (output == null ? void 0 : output.responseFormat),
|
|
10072
|
+
prompt: promptMessages,
|
|
10073
|
+
providerOptions: stepProviderOptions,
|
|
10074
|
+
abortSignal,
|
|
10075
|
+
headers,
|
|
10076
|
+
includeRawChunks: includeRawChunks2
|
|
10077
|
+
})
|
|
9238
10078
|
})
|
|
9239
10079
|
})
|
|
9240
|
-
|
|
9241
|
-
|
|
9242
|
-
|
|
9243
|
-
|
|
9244
|
-
|
|
9245
|
-
|
|
9246
|
-
|
|
9247
|
-
|
|
9248
|
-
|
|
9249
|
-
|
|
9250
|
-
|
|
9251
|
-
|
|
9252
|
-
|
|
9253
|
-
|
|
9254
|
-
|
|
9255
|
-
|
|
9256
|
-
|
|
9257
|
-
|
|
9258
|
-
|
|
9259
|
-
|
|
9260
|
-
|
|
9261
|
-
|
|
9262
|
-
|
|
9263
|
-
|
|
9264
|
-
|
|
9265
|
-
|
|
9266
|
-
|
|
9267
|
-
|
|
9268
|
-
|
|
9269
|
-
|
|
9270
|
-
|
|
9271
|
-
|
|
9272
|
-
|
|
9273
|
-
|
|
9274
|
-
|
|
9275
|
-
|
|
9276
|
-
|
|
9277
|
-
|
|
9278
|
-
|
|
9279
|
-
|
|
9280
|
-
|
|
9281
|
-
|
|
9282
|
-
|
|
9283
|
-
|
|
9284
|
-
|
|
9285
|
-
|
|
9286
|
-
|
|
9287
|
-
|
|
9288
|
-
|
|
9289
|
-
|
|
9290
|
-
|
|
9291
|
-
|
|
9292
|
-
|
|
9293
|
-
}
|
|
9294
|
-
const chunkType = chunk.type;
|
|
9295
|
-
switch (chunkType) {
|
|
9296
|
-
case "tool-approval-request":
|
|
9297
|
-
case "text-start":
|
|
9298
|
-
case "text-end": {
|
|
9299
|
-
controller.enqueue(chunk);
|
|
9300
|
-
break;
|
|
10080
|
+
);
|
|
10081
|
+
const streamWithToolResults = runToolsTransformation({
|
|
10082
|
+
tools,
|
|
10083
|
+
generatorStream: stream2,
|
|
10084
|
+
tracer,
|
|
10085
|
+
telemetry,
|
|
10086
|
+
system,
|
|
10087
|
+
messages: stepInputMessages,
|
|
10088
|
+
repairToolCall,
|
|
10089
|
+
abortSignal,
|
|
10090
|
+
experimental_context,
|
|
10091
|
+
generateId: generateId2
|
|
10092
|
+
});
|
|
10093
|
+
const stepRequest = ((_g = include == null ? void 0 : include.requestBody) != null ? _g : true) ? request != null ? request : {} : { ...request, body: void 0 };
|
|
10094
|
+
const stepToolCalls = [];
|
|
10095
|
+
const stepToolOutputs = [];
|
|
10096
|
+
let warnings;
|
|
10097
|
+
const activeToolCallToolNames = {};
|
|
10098
|
+
let stepFinishReason = "other";
|
|
10099
|
+
let stepRawFinishReason = void 0;
|
|
10100
|
+
let stepUsage = createNullLanguageModelUsage();
|
|
10101
|
+
let stepProviderMetadata;
|
|
10102
|
+
let stepFirstChunk = true;
|
|
10103
|
+
let stepResponse = {
|
|
10104
|
+
id: generateId2(),
|
|
10105
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
10106
|
+
modelId: model.modelId
|
|
10107
|
+
};
|
|
10108
|
+
let activeText = "";
|
|
10109
|
+
self.addStream(
|
|
10110
|
+
streamWithToolResults.pipeThrough(
|
|
10111
|
+
new TransformStream({
|
|
10112
|
+
async transform(chunk, controller) {
|
|
10113
|
+
var _a2222, _b222, _c2, _d2, _e2;
|
|
10114
|
+
resetChunkTimeout();
|
|
10115
|
+
if (chunk.type === "stream-start") {
|
|
10116
|
+
warnings = chunk.warnings;
|
|
10117
|
+
return;
|
|
10118
|
+
}
|
|
10119
|
+
if (stepFirstChunk) {
|
|
10120
|
+
const msToFirstChunk = now2() - startTimestampMs;
|
|
10121
|
+
stepFirstChunk = false;
|
|
10122
|
+
doStreamSpan.addEvent("ai.stream.firstChunk", {
|
|
10123
|
+
"ai.response.msToFirstChunk": msToFirstChunk
|
|
10124
|
+
});
|
|
10125
|
+
doStreamSpan.setAttributes({
|
|
10126
|
+
"ai.response.msToFirstChunk": msToFirstChunk
|
|
10127
|
+
});
|
|
10128
|
+
controller.enqueue({
|
|
10129
|
+
type: "start-step",
|
|
10130
|
+
request: stepRequest,
|
|
10131
|
+
warnings: warnings != null ? warnings : []
|
|
10132
|
+
});
|
|
9301
10133
|
}
|
|
9302
|
-
|
|
9303
|
-
|
|
10134
|
+
const chunkType = chunk.type;
|
|
10135
|
+
switch (chunkType) {
|
|
10136
|
+
case "tool-approval-request":
|
|
10137
|
+
case "text-start":
|
|
10138
|
+
case "text-end": {
|
|
10139
|
+
controller.enqueue(chunk);
|
|
10140
|
+
break;
|
|
10141
|
+
}
|
|
10142
|
+
case "text-delta": {
|
|
10143
|
+
if (chunk.delta.length > 0) {
|
|
10144
|
+
controller.enqueue({
|
|
10145
|
+
type: "text-delta",
|
|
10146
|
+
id: chunk.id,
|
|
10147
|
+
text: chunk.delta,
|
|
10148
|
+
providerMetadata: chunk.providerMetadata
|
|
10149
|
+
});
|
|
10150
|
+
activeText += chunk.delta;
|
|
10151
|
+
}
|
|
10152
|
+
break;
|
|
10153
|
+
}
|
|
10154
|
+
case "reasoning-start":
|
|
10155
|
+
case "reasoning-end": {
|
|
10156
|
+
controller.enqueue(chunk);
|
|
10157
|
+
break;
|
|
10158
|
+
}
|
|
10159
|
+
case "reasoning-delta": {
|
|
9304
10160
|
controller.enqueue({
|
|
9305
|
-
type: "
|
|
10161
|
+
type: "reasoning-delta",
|
|
9306
10162
|
id: chunk.id,
|
|
9307
10163
|
text: chunk.delta,
|
|
9308
10164
|
providerMetadata: chunk.providerMetadata
|
|
9309
10165
|
});
|
|
9310
|
-
|
|
10166
|
+
break;
|
|
9311
10167
|
}
|
|
9312
|
-
|
|
9313
|
-
|
|
9314
|
-
|
|
9315
|
-
|
|
9316
|
-
|
|
9317
|
-
|
|
9318
|
-
|
|
9319
|
-
|
|
9320
|
-
|
|
9321
|
-
|
|
9322
|
-
|
|
9323
|
-
|
|
9324
|
-
|
|
9325
|
-
|
|
9326
|
-
break;
|
|
9327
|
-
}
|
|
9328
|
-
case "tool-call": {
|
|
9329
|
-
controller.enqueue(chunk);
|
|
9330
|
-
stepToolCalls.push(chunk);
|
|
9331
|
-
break;
|
|
9332
|
-
}
|
|
9333
|
-
case "tool-result": {
|
|
9334
|
-
controller.enqueue(chunk);
|
|
9335
|
-
if (!chunk.preliminary) {
|
|
10168
|
+
case "tool-call": {
|
|
10169
|
+
controller.enqueue(chunk);
|
|
10170
|
+
stepToolCalls.push(chunk);
|
|
10171
|
+
break;
|
|
10172
|
+
}
|
|
10173
|
+
case "tool-result": {
|
|
10174
|
+
controller.enqueue(chunk);
|
|
10175
|
+
if (!chunk.preliminary) {
|
|
10176
|
+
stepToolOutputs.push(chunk);
|
|
10177
|
+
}
|
|
10178
|
+
break;
|
|
10179
|
+
}
|
|
10180
|
+
case "tool-error": {
|
|
10181
|
+
controller.enqueue(chunk);
|
|
9336
10182
|
stepToolOutputs.push(chunk);
|
|
10183
|
+
break;
|
|
9337
10184
|
}
|
|
9338
|
-
|
|
9339
|
-
|
|
9340
|
-
|
|
9341
|
-
|
|
9342
|
-
|
|
9343
|
-
|
|
9344
|
-
|
|
9345
|
-
|
|
9346
|
-
|
|
9347
|
-
|
|
9348
|
-
|
|
9349
|
-
|
|
9350
|
-
|
|
9351
|
-
|
|
9352
|
-
|
|
9353
|
-
|
|
9354
|
-
|
|
9355
|
-
|
|
9356
|
-
stepRawFinishReason = chunk.rawFinishReason;
|
|
9357
|
-
stepProviderMetadata = chunk.providerMetadata;
|
|
9358
|
-
const msToFinish = now2() - startTimestampMs;
|
|
9359
|
-
doStreamSpan.addEvent("ai.stream.finish");
|
|
9360
|
-
doStreamSpan.setAttributes({
|
|
9361
|
-
"ai.response.msToFinish": msToFinish,
|
|
9362
|
-
"ai.response.avgOutputTokensPerSecond": 1e3 * ((_d2 = stepUsage.outputTokens) != null ? _d2 : 0) / msToFinish
|
|
9363
|
-
});
|
|
9364
|
-
break;
|
|
9365
|
-
}
|
|
9366
|
-
case "file": {
|
|
9367
|
-
controller.enqueue(chunk);
|
|
9368
|
-
break;
|
|
9369
|
-
}
|
|
9370
|
-
case "source": {
|
|
9371
|
-
controller.enqueue(chunk);
|
|
9372
|
-
break;
|
|
9373
|
-
}
|
|
9374
|
-
case "tool-input-start": {
|
|
9375
|
-
activeToolCallToolNames[chunk.id] = chunk.toolName;
|
|
9376
|
-
const tool2 = tools == null ? void 0 : tools[chunk.toolName];
|
|
9377
|
-
if ((tool2 == null ? void 0 : tool2.onInputStart) != null) {
|
|
9378
|
-
await tool2.onInputStart({
|
|
9379
|
-
toolCallId: chunk.id,
|
|
9380
|
-
messages: stepInputMessages,
|
|
9381
|
-
abortSignal,
|
|
9382
|
-
experimental_context
|
|
10185
|
+
case "response-metadata": {
|
|
10186
|
+
stepResponse = {
|
|
10187
|
+
id: (_a2222 = chunk.id) != null ? _a2222 : stepResponse.id,
|
|
10188
|
+
timestamp: (_b222 = chunk.timestamp) != null ? _b222 : stepResponse.timestamp,
|
|
10189
|
+
modelId: (_c2 = chunk.modelId) != null ? _c2 : stepResponse.modelId
|
|
10190
|
+
};
|
|
10191
|
+
break;
|
|
10192
|
+
}
|
|
10193
|
+
case "finish": {
|
|
10194
|
+
stepUsage = chunk.usage;
|
|
10195
|
+
stepFinishReason = chunk.finishReason;
|
|
10196
|
+
stepRawFinishReason = chunk.rawFinishReason;
|
|
10197
|
+
stepProviderMetadata = chunk.providerMetadata;
|
|
10198
|
+
const msToFinish = now2() - startTimestampMs;
|
|
10199
|
+
doStreamSpan.addEvent("ai.stream.finish");
|
|
10200
|
+
doStreamSpan.setAttributes({
|
|
10201
|
+
"ai.response.msToFinish": msToFinish,
|
|
10202
|
+
"ai.response.avgOutputTokensPerSecond": 1e3 * ((_d2 = stepUsage.outputTokens) != null ? _d2 : 0) / msToFinish
|
|
9383
10203
|
});
|
|
10204
|
+
break;
|
|
9384
10205
|
}
|
|
9385
|
-
|
|
9386
|
-
|
|
9387
|
-
|
|
9388
|
-
|
|
9389
|
-
|
|
9390
|
-
|
|
9391
|
-
|
|
9392
|
-
|
|
9393
|
-
|
|
9394
|
-
|
|
9395
|
-
|
|
9396
|
-
|
|
9397
|
-
|
|
9398
|
-
|
|
9399
|
-
|
|
9400
|
-
|
|
9401
|
-
|
|
9402
|
-
|
|
9403
|
-
|
|
9404
|
-
|
|
9405
|
-
|
|
9406
|
-
|
|
10206
|
+
case "file": {
|
|
10207
|
+
controller.enqueue(chunk);
|
|
10208
|
+
break;
|
|
10209
|
+
}
|
|
10210
|
+
case "source": {
|
|
10211
|
+
controller.enqueue(chunk);
|
|
10212
|
+
break;
|
|
10213
|
+
}
|
|
10214
|
+
case "tool-input-start": {
|
|
10215
|
+
activeToolCallToolNames[chunk.id] = chunk.toolName;
|
|
10216
|
+
const tool2 = tools == null ? void 0 : tools[chunk.toolName];
|
|
10217
|
+
if ((tool2 == null ? void 0 : tool2.onInputStart) != null) {
|
|
10218
|
+
await tool2.onInputStart({
|
|
10219
|
+
toolCallId: chunk.id,
|
|
10220
|
+
messages: stepInputMessages,
|
|
10221
|
+
abortSignal,
|
|
10222
|
+
experimental_context
|
|
10223
|
+
});
|
|
10224
|
+
}
|
|
10225
|
+
controller.enqueue({
|
|
10226
|
+
...chunk,
|
|
10227
|
+
dynamic: (_e2 = chunk.dynamic) != null ? _e2 : (tool2 == null ? void 0 : tool2.type) === "dynamic",
|
|
10228
|
+
title: tool2 == null ? void 0 : tool2.title
|
|
9407
10229
|
});
|
|
10230
|
+
break;
|
|
9408
10231
|
}
|
|
9409
|
-
|
|
9410
|
-
|
|
9411
|
-
}
|
|
9412
|
-
case "error": {
|
|
9413
|
-
controller.enqueue(chunk);
|
|
9414
|
-
stepFinishReason = "error";
|
|
9415
|
-
break;
|
|
9416
|
-
}
|
|
9417
|
-
case "raw": {
|
|
9418
|
-
if (includeRawChunks2) {
|
|
10232
|
+
case "tool-input-end": {
|
|
10233
|
+
delete activeToolCallToolNames[chunk.id];
|
|
9419
10234
|
controller.enqueue(chunk);
|
|
10235
|
+
break;
|
|
9420
10236
|
}
|
|
9421
|
-
|
|
9422
|
-
|
|
9423
|
-
|
|
9424
|
-
|
|
9425
|
-
|
|
9426
|
-
|
|
9427
|
-
|
|
9428
|
-
|
|
9429
|
-
|
|
9430
|
-
|
|
9431
|
-
|
|
9432
|
-
try {
|
|
9433
|
-
doStreamSpan.setAttributes(
|
|
9434
|
-
await selectTelemetryAttributes({
|
|
9435
|
-
telemetry,
|
|
9436
|
-
attributes: {
|
|
9437
|
-
"ai.response.finishReason": stepFinishReason,
|
|
9438
|
-
"ai.response.text": {
|
|
9439
|
-
output: () => activeText
|
|
9440
|
-
},
|
|
9441
|
-
"ai.response.toolCalls": {
|
|
9442
|
-
output: () => stepToolCallsJson
|
|
9443
|
-
},
|
|
9444
|
-
"ai.response.id": stepResponse.id,
|
|
9445
|
-
"ai.response.model": stepResponse.modelId,
|
|
9446
|
-
"ai.response.timestamp": stepResponse.timestamp.toISOString(),
|
|
9447
|
-
"ai.response.providerMetadata": JSON.stringify(stepProviderMetadata),
|
|
9448
|
-
"ai.usage.inputTokens": stepUsage.inputTokens,
|
|
9449
|
-
"ai.usage.outputTokens": stepUsage.outputTokens,
|
|
9450
|
-
"ai.usage.totalTokens": stepUsage.totalTokens,
|
|
9451
|
-
"ai.usage.reasoningTokens": stepUsage.reasoningTokens,
|
|
9452
|
-
"ai.usage.cachedInputTokens": stepUsage.cachedInputTokens,
|
|
9453
|
-
// standardized gen-ai llm span attributes:
|
|
9454
|
-
"gen_ai.response.finish_reasons": [stepFinishReason],
|
|
9455
|
-
"gen_ai.response.id": stepResponse.id,
|
|
9456
|
-
"gen_ai.response.model": stepResponse.modelId,
|
|
9457
|
-
"gen_ai.usage.input_tokens": stepUsage.inputTokens,
|
|
9458
|
-
"gen_ai.usage.output_tokens": stepUsage.outputTokens
|
|
10237
|
+
case "tool-input-delta": {
|
|
10238
|
+
const toolName = activeToolCallToolNames[chunk.id];
|
|
10239
|
+
const tool2 = tools == null ? void 0 : tools[toolName];
|
|
10240
|
+
if ((tool2 == null ? void 0 : tool2.onInputDelta) != null) {
|
|
10241
|
+
await tool2.onInputDelta({
|
|
10242
|
+
inputTextDelta: chunk.delta,
|
|
10243
|
+
toolCallId: chunk.id,
|
|
10244
|
+
messages: stepInputMessages,
|
|
10245
|
+
abortSignal,
|
|
10246
|
+
experimental_context
|
|
10247
|
+
});
|
|
9459
10248
|
}
|
|
9460
|
-
|
|
9461
|
-
|
|
9462
|
-
|
|
9463
|
-
|
|
9464
|
-
|
|
9465
|
-
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
9471
|
-
|
|
9472
|
-
|
|
9473
|
-
|
|
9474
|
-
|
|
10249
|
+
controller.enqueue(chunk);
|
|
10250
|
+
break;
|
|
10251
|
+
}
|
|
10252
|
+
case "error": {
|
|
10253
|
+
controller.enqueue(chunk);
|
|
10254
|
+
stepFinishReason = "error";
|
|
10255
|
+
break;
|
|
10256
|
+
}
|
|
10257
|
+
case "raw": {
|
|
10258
|
+
if (includeRawChunks2) {
|
|
10259
|
+
controller.enqueue(chunk);
|
|
10260
|
+
}
|
|
10261
|
+
break;
|
|
10262
|
+
}
|
|
10263
|
+
default: {
|
|
10264
|
+
const exhaustiveCheck = chunkType;
|
|
10265
|
+
throw new Error(
|
|
10266
|
+
`Unknown chunk type: ${exhaustiveCheck}`
|
|
10267
|
+
);
|
|
10268
|
+
}
|
|
9475
10269
|
}
|
|
9476
|
-
}
|
|
9477
|
-
|
|
9478
|
-
|
|
9479
|
-
|
|
9480
|
-
|
|
9481
|
-
|
|
9482
|
-
|
|
9483
|
-
|
|
9484
|
-
|
|
9485
|
-
|
|
9486
|
-
|
|
9487
|
-
|
|
9488
|
-
|
|
9489
|
-
|
|
9490
|
-
|
|
9491
|
-
|
|
10270
|
+
},
|
|
10271
|
+
// invoke onFinish callback and resolve toolResults promise when the stream is about to close:
|
|
10272
|
+
async flush(controller) {
|
|
10273
|
+
const stepToolCallsJson = stepToolCalls.length > 0 ? JSON.stringify(stepToolCalls) : void 0;
|
|
10274
|
+
try {
|
|
10275
|
+
doStreamSpan.setAttributes(
|
|
10276
|
+
await selectTelemetryAttributes({
|
|
10277
|
+
telemetry,
|
|
10278
|
+
attributes: {
|
|
10279
|
+
"ai.response.finishReason": stepFinishReason,
|
|
10280
|
+
"ai.response.text": {
|
|
10281
|
+
output: () => activeText
|
|
10282
|
+
},
|
|
10283
|
+
"ai.response.toolCalls": {
|
|
10284
|
+
output: () => stepToolCallsJson
|
|
10285
|
+
},
|
|
10286
|
+
"ai.response.id": stepResponse.id,
|
|
10287
|
+
"ai.response.model": stepResponse.modelId,
|
|
10288
|
+
"ai.response.timestamp": stepResponse.timestamp.toISOString(),
|
|
10289
|
+
"ai.response.providerMetadata": JSON.stringify(stepProviderMetadata),
|
|
10290
|
+
"ai.usage.inputTokens": stepUsage.inputTokens,
|
|
10291
|
+
"ai.usage.outputTokens": stepUsage.outputTokens,
|
|
10292
|
+
"ai.usage.totalTokens": stepUsage.totalTokens,
|
|
10293
|
+
"ai.usage.reasoningTokens": stepUsage.reasoningTokens,
|
|
10294
|
+
"ai.usage.cachedInputTokens": stepUsage.cachedInputTokens,
|
|
10295
|
+
// standardized gen-ai llm span attributes:
|
|
10296
|
+
"gen_ai.response.finish_reasons": [
|
|
10297
|
+
stepFinishReason
|
|
10298
|
+
],
|
|
10299
|
+
"gen_ai.response.id": stepResponse.id,
|
|
10300
|
+
"gen_ai.response.model": stepResponse.modelId,
|
|
10301
|
+
"gen_ai.usage.input_tokens": stepUsage.inputTokens,
|
|
10302
|
+
"gen_ai.usage.output_tokens": stepUsage.outputTokens
|
|
10303
|
+
}
|
|
10304
|
+
})
|
|
9492
10305
|
);
|
|
9493
|
-
|
|
9494
|
-
|
|
9495
|
-
|
|
9496
|
-
|
|
10306
|
+
} catch (error) {
|
|
10307
|
+
} finally {
|
|
10308
|
+
doStreamSpan.end();
|
|
10309
|
+
}
|
|
10310
|
+
controller.enqueue({
|
|
10311
|
+
type: "finish-step",
|
|
10312
|
+
finishReason: stepFinishReason,
|
|
10313
|
+
rawFinishReason: stepRawFinishReason,
|
|
10314
|
+
usage: stepUsage,
|
|
10315
|
+
providerMetadata: stepProviderMetadata,
|
|
10316
|
+
response: {
|
|
10317
|
+
...stepResponse,
|
|
10318
|
+
headers: response == null ? void 0 : response.headers
|
|
10319
|
+
}
|
|
10320
|
+
});
|
|
10321
|
+
const combinedUsage = addLanguageModelUsage(
|
|
10322
|
+
usage,
|
|
10323
|
+
stepUsage
|
|
10324
|
+
);
|
|
10325
|
+
await stepFinish.promise;
|
|
10326
|
+
const clientToolCalls = stepToolCalls.filter(
|
|
10327
|
+
(toolCall) => toolCall.providerExecuted !== true
|
|
10328
|
+
);
|
|
10329
|
+
const clientToolOutputs = stepToolOutputs.filter(
|
|
10330
|
+
(toolOutput) => toolOutput.providerExecuted !== true
|
|
10331
|
+
);
|
|
10332
|
+
for (const toolCall of stepToolCalls) {
|
|
10333
|
+
if (toolCall.providerExecuted !== true)
|
|
10334
|
+
continue;
|
|
10335
|
+
const tool2 = tools == null ? void 0 : tools[toolCall.toolName];
|
|
10336
|
+
if ((tool2 == null ? void 0 : tool2.type) === "provider" && tool2.supportsDeferredResults) {
|
|
10337
|
+
const hasResultInStep = stepToolOutputs.some(
|
|
10338
|
+
(output2) => (output2.type === "tool-result" || output2.type === "tool-error") && output2.toolCallId === toolCall.toolCallId
|
|
10339
|
+
);
|
|
10340
|
+
if (!hasResultInStep) {
|
|
10341
|
+
pendingDeferredToolCalls.set(toolCall.toolCallId, {
|
|
10342
|
+
toolName: toolCall.toolName
|
|
10343
|
+
});
|
|
10344
|
+
}
|
|
9497
10345
|
}
|
|
9498
10346
|
}
|
|
9499
|
-
|
|
9500
|
-
|
|
9501
|
-
|
|
9502
|
-
|
|
10347
|
+
for (const output2 of stepToolOutputs) {
|
|
10348
|
+
if (output2.type === "tool-result" || output2.type === "tool-error") {
|
|
10349
|
+
pendingDeferredToolCalls.delete(output2.toolCallId);
|
|
10350
|
+
}
|
|
9503
10351
|
}
|
|
9504
|
-
|
|
9505
|
-
|
|
9506
|
-
|
|
9507
|
-
|
|
9508
|
-
|
|
9509
|
-
|
|
9510
|
-
|
|
9511
|
-
|
|
9512
|
-
|
|
9513
|
-
|
|
9514
|
-
) {
|
|
9515
|
-
responseMessages.push(
|
|
9516
|
-
...await toResponseMessages({
|
|
9517
|
-
content: (
|
|
9518
|
-
// use transformed content to create the messages for the next step:
|
|
9519
|
-
recordedSteps[recordedSteps.length - 1].content
|
|
9520
|
-
),
|
|
9521
|
-
tools
|
|
10352
|
+
clearStepTimeout();
|
|
10353
|
+
clearChunkTimeout();
|
|
10354
|
+
if (
|
|
10355
|
+
// Continue if:
|
|
10356
|
+
// 1. There are client tool calls that have all been executed, OR
|
|
10357
|
+
// 2. There are pending deferred results from provider-executed tools
|
|
10358
|
+
(clientToolCalls.length > 0 && clientToolOutputs.length === clientToolCalls.length || pendingDeferredToolCalls.size > 0) && // continue until a stop condition is met:
|
|
10359
|
+
!await isStopConditionMet({
|
|
10360
|
+
stopConditions,
|
|
10361
|
+
steps: recordedSteps
|
|
9522
10362
|
})
|
|
9523
|
-
)
|
|
9524
|
-
|
|
9525
|
-
|
|
9526
|
-
|
|
9527
|
-
|
|
9528
|
-
|
|
9529
|
-
|
|
9530
|
-
|
|
10363
|
+
) {
|
|
10364
|
+
responseMessages.push(
|
|
10365
|
+
...await toResponseMessages({
|
|
10366
|
+
content: (
|
|
10367
|
+
// use transformed content to create the messages for the next step:
|
|
10368
|
+
recordedSteps[recordedSteps.length - 1].content
|
|
10369
|
+
),
|
|
10370
|
+
tools
|
|
10371
|
+
})
|
|
10372
|
+
);
|
|
10373
|
+
try {
|
|
10374
|
+
await streamStep({
|
|
10375
|
+
currentStep: currentStep + 1,
|
|
10376
|
+
responseMessages,
|
|
10377
|
+
usage: combinedUsage
|
|
10378
|
+
});
|
|
10379
|
+
} catch (error) {
|
|
10380
|
+
controller.enqueue({
|
|
10381
|
+
type: "error",
|
|
10382
|
+
error
|
|
10383
|
+
});
|
|
10384
|
+
self.closeStream();
|
|
10385
|
+
}
|
|
10386
|
+
} else {
|
|
9531
10387
|
controller.enqueue({
|
|
9532
|
-
type: "
|
|
9533
|
-
|
|
10388
|
+
type: "finish",
|
|
10389
|
+
finishReason: stepFinishReason,
|
|
10390
|
+
rawFinishReason: stepRawFinishReason,
|
|
10391
|
+
totalUsage: combinedUsage
|
|
9534
10392
|
});
|
|
9535
10393
|
self.closeStream();
|
|
9536
10394
|
}
|
|
9537
|
-
} else {
|
|
9538
|
-
controller.enqueue({
|
|
9539
|
-
type: "finish",
|
|
9540
|
-
finishReason: stepFinishReason,
|
|
9541
|
-
rawFinishReason: stepRawFinishReason,
|
|
9542
|
-
totalUsage: combinedUsage
|
|
9543
|
-
});
|
|
9544
|
-
self.closeStream();
|
|
9545
10395
|
}
|
|
9546
|
-
}
|
|
9547
|
-
|
|
9548
|
-
)
|
|
9549
|
-
|
|
10396
|
+
})
|
|
10397
|
+
)
|
|
10398
|
+
);
|
|
10399
|
+
} finally {
|
|
10400
|
+
clearStepTimeout();
|
|
10401
|
+
clearChunkTimeout();
|
|
10402
|
+
}
|
|
9550
10403
|
}
|
|
9551
10404
|
await streamStep({
|
|
9552
10405
|
currentStep: 0,
|
|
@@ -9637,13 +10490,13 @@ var DefaultStreamTextResult = class {
|
|
|
9637
10490
|
return this._rawFinishReason.promise;
|
|
9638
10491
|
}
|
|
9639
10492
|
/**
|
|
9640
|
-
|
|
9641
|
-
|
|
9642
|
-
|
|
9643
|
-
|
|
9644
|
-
|
|
9645
|
-
|
|
9646
|
-
|
|
10493
|
+
* Split out a new stream from the original stream.
|
|
10494
|
+
* The original stream is replaced to allow for further splitting,
|
|
10495
|
+
* since we do not know how many times the stream will be split.
|
|
10496
|
+
*
|
|
10497
|
+
* Note: this leads to buffering the stream content on the server.
|
|
10498
|
+
* However, the LLM results are expected to be small enough to not cause issues.
|
|
10499
|
+
*/
|
|
9647
10500
|
teeStream() {
|
|
9648
10501
|
const [stream1, stream2] = this.baseStream.tee();
|
|
9649
10502
|
this.baseStream = stream2;
|
|
@@ -9674,14 +10527,14 @@ var DefaultStreamTextResult = class {
|
|
|
9674
10527
|
);
|
|
9675
10528
|
}
|
|
9676
10529
|
async consumeStream(options) {
|
|
9677
|
-
var
|
|
10530
|
+
var _a21;
|
|
9678
10531
|
try {
|
|
9679
10532
|
await consumeStream({
|
|
9680
10533
|
stream: this.fullStream,
|
|
9681
10534
|
onError: options == null ? void 0 : options.onError
|
|
9682
10535
|
});
|
|
9683
10536
|
} catch (error) {
|
|
9684
|
-
(
|
|
10537
|
+
(_a21 = options == null ? void 0 : options.onError) == null ? void 0 : _a21.call(options, error);
|
|
9685
10538
|
}
|
|
9686
10539
|
}
|
|
9687
10540
|
get experimental_partialOutputStream() {
|
|
@@ -9700,10 +10553,20 @@ var DefaultStreamTextResult = class {
|
|
|
9700
10553
|
)
|
|
9701
10554
|
);
|
|
9702
10555
|
}
|
|
10556
|
+
get elementStream() {
|
|
10557
|
+
var _a21, _b82, _c;
|
|
10558
|
+
const transform = (_a21 = this.outputSpecification) == null ? void 0 : _a21.createElementStreamTransform();
|
|
10559
|
+
if (transform == null) {
|
|
10560
|
+
throw new UnsupportedFunctionalityError({
|
|
10561
|
+
functionality: `element streams in ${(_c = (_b82 = this.outputSpecification) == null ? void 0 : _b82.name) != null ? _c : "text"} mode`
|
|
10562
|
+
});
|
|
10563
|
+
}
|
|
10564
|
+
return createAsyncIterableStream(this.teeStream().pipeThrough(transform));
|
|
10565
|
+
}
|
|
9703
10566
|
get output() {
|
|
9704
10567
|
return this.finalStep.then((step) => {
|
|
9705
|
-
var
|
|
9706
|
-
const output = (
|
|
10568
|
+
var _a21;
|
|
10569
|
+
const output = (_a21 = this.outputSpecification) != null ? _a21 : text();
|
|
9707
10570
|
return output.parseCompleteOutput(
|
|
9708
10571
|
{ text: step.text },
|
|
9709
10572
|
{
|
|
@@ -9730,8 +10593,8 @@ var DefaultStreamTextResult = class {
|
|
|
9730
10593
|
responseMessageId: generateMessageId
|
|
9731
10594
|
}) : void 0;
|
|
9732
10595
|
const isDynamic = (part) => {
|
|
9733
|
-
var
|
|
9734
|
-
const tool2 = (
|
|
10596
|
+
var _a21;
|
|
10597
|
+
const tool2 = (_a21 = this.tools) == null ? void 0 : _a21[part.toolName];
|
|
9735
10598
|
if (tool2 == null) {
|
|
9736
10599
|
return part.dynamic;
|
|
9737
10600
|
}
|
|
@@ -9832,6 +10695,7 @@ var DefaultStreamTextResult = class {
|
|
|
9832
10695
|
toolCallId: part.id,
|
|
9833
10696
|
toolName: part.toolName,
|
|
9834
10697
|
...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
|
|
10698
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
|
|
9835
10699
|
...dynamic != null ? { dynamic } : {},
|
|
9836
10700
|
...part.title != null ? { title: part.title } : {}
|
|
9837
10701
|
});
|
|
@@ -10067,13 +10931,17 @@ var ToolLoopAgent = class {
|
|
|
10067
10931
|
return this.settings.tools;
|
|
10068
10932
|
}
|
|
10069
10933
|
async prepareCall(options) {
|
|
10070
|
-
var
|
|
10934
|
+
var _a21, _b82, _c, _d;
|
|
10935
|
+
const { onStepFinish: _settingsOnStepFinish, ...settingsWithoutCallback } = this.settings;
|
|
10071
10936
|
const baseCallArgs = {
|
|
10072
|
-
...
|
|
10073
|
-
stopWhen: (
|
|
10937
|
+
...settingsWithoutCallback,
|
|
10938
|
+
stopWhen: (_a21 = this.settings.stopWhen) != null ? _a21 : stepCountIs(20),
|
|
10074
10939
|
...options
|
|
10075
10940
|
};
|
|
10076
|
-
const preparedCallArgs = (_d = await ((_c = (_b82 = this.settings).prepareCall) == null ? void 0 : _c.call(
|
|
10941
|
+
const preparedCallArgs = (_d = await ((_c = (_b82 = this.settings).prepareCall) == null ? void 0 : _c.call(
|
|
10942
|
+
_b82,
|
|
10943
|
+
baseCallArgs
|
|
10944
|
+
))) != null ? _d : baseCallArgs;
|
|
10077
10945
|
const { instructions, messages, prompt, ...callArgs } = preparedCallArgs;
|
|
10078
10946
|
return {
|
|
10079
10947
|
...callArgs,
|
|
@@ -10081,16 +10949,30 @@ var ToolLoopAgent = class {
|
|
|
10081
10949
|
...{ system: instructions, messages, prompt }
|
|
10082
10950
|
};
|
|
10083
10951
|
}
|
|
10952
|
+
mergeOnStepFinishCallbacks(methodCallback) {
|
|
10953
|
+
const constructorCallback = this.settings.onStepFinish;
|
|
10954
|
+
if (methodCallback && constructorCallback) {
|
|
10955
|
+
return async (stepResult) => {
|
|
10956
|
+
await constructorCallback(stepResult);
|
|
10957
|
+
await methodCallback(stepResult);
|
|
10958
|
+
};
|
|
10959
|
+
}
|
|
10960
|
+
return methodCallback != null ? methodCallback : constructorCallback;
|
|
10961
|
+
}
|
|
10084
10962
|
/**
|
|
10085
10963
|
* Generates an output from the agent (non-streaming).
|
|
10086
10964
|
*/
|
|
10087
10965
|
async generate({
|
|
10088
10966
|
abortSignal,
|
|
10967
|
+
timeout,
|
|
10968
|
+
onStepFinish,
|
|
10089
10969
|
...options
|
|
10090
10970
|
}) {
|
|
10091
10971
|
return generateText({
|
|
10092
10972
|
...await this.prepareCall(options),
|
|
10093
|
-
abortSignal
|
|
10973
|
+
abortSignal,
|
|
10974
|
+
timeout,
|
|
10975
|
+
onStepFinish: this.mergeOnStepFinishCallbacks(onStepFinish)
|
|
10094
10976
|
});
|
|
10095
10977
|
}
|
|
10096
10978
|
/**
|
|
@@ -10098,13 +10980,17 @@ var ToolLoopAgent = class {
|
|
|
10098
10980
|
*/
|
|
10099
10981
|
async stream({
|
|
10100
10982
|
abortSignal,
|
|
10983
|
+
timeout,
|
|
10101
10984
|
experimental_transform,
|
|
10985
|
+
onStepFinish,
|
|
10102
10986
|
...options
|
|
10103
10987
|
}) {
|
|
10104
10988
|
return streamText({
|
|
10105
10989
|
...await this.prepareCall(options),
|
|
10106
10990
|
abortSignal,
|
|
10107
|
-
|
|
10991
|
+
timeout,
|
|
10992
|
+
experimental_transform,
|
|
10993
|
+
onStepFinish: this.mergeOnStepFinishCallbacks(onStepFinish)
|
|
10108
10994
|
});
|
|
10109
10995
|
}
|
|
10110
10996
|
};
|
|
@@ -10164,7 +11050,7 @@ async function embed({
|
|
|
10164
11050
|
}),
|
|
10165
11051
|
tracer,
|
|
10166
11052
|
fn: async (doEmbedSpan) => {
|
|
10167
|
-
var
|
|
11053
|
+
var _a21;
|
|
10168
11054
|
const modelResponse = await model.doEmbed({
|
|
10169
11055
|
values: [value],
|
|
10170
11056
|
abortSignal,
|
|
@@ -10172,7 +11058,7 @@ async function embed({
|
|
|
10172
11058
|
providerOptions
|
|
10173
11059
|
});
|
|
10174
11060
|
const embedding2 = modelResponse.embeddings[0];
|
|
10175
|
-
const usage2 = (
|
|
11061
|
+
const usage2 = (_a21 = modelResponse.usage) != null ? _a21 : { tokens: NaN };
|
|
10176
11062
|
doEmbedSpan.setAttributes(
|
|
10177
11063
|
await selectTelemetryAttributes({
|
|
10178
11064
|
telemetry,
|
|
@@ -10233,5 +11119,5 @@ createIdGenerator({ prefix: "aiobj", size: 24 });
|
|
|
10233
11119
|
|
|
10234
11120
|
exports.ToolLoopAgent = ToolLoopAgent;
|
|
10235
11121
|
exports.embed = embed;
|
|
10236
|
-
//# sourceMappingURL=chunk-
|
|
10237
|
-
//# sourceMappingURL=chunk-
|
|
11122
|
+
//# sourceMappingURL=chunk-VTE2OBKS.cjs.map
|
|
11123
|
+
//# sourceMappingURL=chunk-VTE2OBKS.cjs.map
|