@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,7 +1,8 @@
|
|
|
1
|
-
import { __commonJS, require_token_error, __toESM } from './chunk-
|
|
1
|
+
import { __commonJS, require_token_error, __toESM } from './chunk-X5ORARLG.js';
|
|
2
2
|
import * as z4 from 'zod/v4';
|
|
3
3
|
import { z } from 'zod/v4';
|
|
4
4
|
import { ZodFirstPartyTypeKind } from 'zod/v3';
|
|
5
|
+
import { z as z$1 } from 'zod';
|
|
5
6
|
|
|
6
7
|
var marker = "vercel.ai.error";
|
|
7
8
|
var symbol = Symbol.for(marker);
|
|
@@ -17,13 +18,13 @@ var AISDKError = class _AISDKError extends (_b = Error, _a = symbol, _b) {
|
|
|
17
18
|
* @param {unknown} [params.cause] - The underlying cause of the error.
|
|
18
19
|
*/
|
|
19
20
|
constructor({
|
|
20
|
-
name:
|
|
21
|
+
name: name1422,
|
|
21
22
|
message,
|
|
22
23
|
cause
|
|
23
24
|
}) {
|
|
24
25
|
super(message);
|
|
25
26
|
this[_a] = true;
|
|
26
|
-
this.name =
|
|
27
|
+
this.name = name1422;
|
|
27
28
|
this.cause = cause;
|
|
28
29
|
}
|
|
29
30
|
/**
|
|
@@ -34,8 +35,8 @@ var AISDKError = class _AISDKError extends (_b = Error, _a = symbol, _b) {
|
|
|
34
35
|
static isInstance(error) {
|
|
35
36
|
return _AISDKError.hasMarker(error, marker);
|
|
36
37
|
}
|
|
37
|
-
static hasMarker(error,
|
|
38
|
-
const markerSymbol = Symbol.for(
|
|
38
|
+
static hasMarker(error, marker1522) {
|
|
39
|
+
const markerSymbol = Symbol.for(marker1522);
|
|
39
40
|
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
40
41
|
}
|
|
41
42
|
};
|
|
@@ -165,34 +166,79 @@ var symbol13 = Symbol.for(marker13);
|
|
|
165
166
|
var _a13;
|
|
166
167
|
var _b13;
|
|
167
168
|
var TypeValidationError = class _TypeValidationError extends (_b13 = AISDKError, _a13 = symbol13, _b13) {
|
|
168
|
-
constructor({
|
|
169
|
+
constructor({
|
|
170
|
+
value,
|
|
171
|
+
cause,
|
|
172
|
+
context: context2
|
|
173
|
+
}) {
|
|
174
|
+
let contextPrefix = "Type validation failed";
|
|
175
|
+
if (context2 == null ? void 0 : context2.field) {
|
|
176
|
+
contextPrefix += ` for ${context2.field}`;
|
|
177
|
+
}
|
|
178
|
+
if ((context2 == null ? void 0 : context2.entityName) || (context2 == null ? void 0 : context2.entityId)) {
|
|
179
|
+
contextPrefix += " (";
|
|
180
|
+
const parts = [];
|
|
181
|
+
if (context2.entityName) {
|
|
182
|
+
parts.push(context2.entityName);
|
|
183
|
+
}
|
|
184
|
+
if (context2.entityId) {
|
|
185
|
+
parts.push(`id: "${context2.entityId}"`);
|
|
186
|
+
}
|
|
187
|
+
contextPrefix += parts.join(", ");
|
|
188
|
+
contextPrefix += ")";
|
|
189
|
+
}
|
|
169
190
|
super({
|
|
170
191
|
name: name12,
|
|
171
|
-
message:
|
|
192
|
+
message: `${contextPrefix}: Value: ${JSON.stringify(value)}.
|
|
172
193
|
Error message: ${getErrorMessage(cause)}`,
|
|
173
194
|
cause
|
|
174
195
|
});
|
|
175
196
|
this[_a13] = true;
|
|
176
197
|
this.value = value;
|
|
198
|
+
this.context = context2;
|
|
177
199
|
}
|
|
178
200
|
static isInstance(error) {
|
|
179
201
|
return AISDKError.hasMarker(error, marker13);
|
|
180
202
|
}
|
|
181
203
|
/**
|
|
182
204
|
* Wraps an error into a TypeValidationError.
|
|
183
|
-
* If the cause is already a TypeValidationError with the same value, it returns the cause.
|
|
205
|
+
* If the cause is already a TypeValidationError with the same value and context, it returns the cause.
|
|
184
206
|
* Otherwise, it creates a new TypeValidationError.
|
|
185
207
|
*
|
|
186
208
|
* @param {Object} params - The parameters for wrapping the error.
|
|
187
209
|
* @param {unknown} params.value - The value that failed validation.
|
|
188
210
|
* @param {unknown} params.cause - The original error or cause of the validation failure.
|
|
211
|
+
* @param {TypeValidationContext} params.context - Optional context about what is being validated.
|
|
189
212
|
* @returns {TypeValidationError} A TypeValidationError instance.
|
|
190
213
|
*/
|
|
191
214
|
static wrap({
|
|
192
215
|
value,
|
|
193
|
-
cause
|
|
216
|
+
cause,
|
|
217
|
+
context: context2
|
|
218
|
+
}) {
|
|
219
|
+
var _a1522, _b152, _c;
|
|
220
|
+
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)) {
|
|
221
|
+
return cause;
|
|
222
|
+
}
|
|
223
|
+
return new _TypeValidationError({ value, cause, context: context2 });
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
var name13 = "AI_UnsupportedFunctionalityError";
|
|
227
|
+
var marker14 = `vercel.ai.error.${name13}`;
|
|
228
|
+
var symbol14 = Symbol.for(marker14);
|
|
229
|
+
var _a14;
|
|
230
|
+
var _b14;
|
|
231
|
+
var UnsupportedFunctionalityError = class extends (_b14 = AISDKError, _a14 = symbol14, _b14) {
|
|
232
|
+
constructor({
|
|
233
|
+
functionality,
|
|
234
|
+
message = `'${functionality}' functionality not supported.`
|
|
194
235
|
}) {
|
|
195
|
-
|
|
236
|
+
super({ name: name13, message });
|
|
237
|
+
this[_a14] = true;
|
|
238
|
+
this.functionality = functionality;
|
|
239
|
+
}
|
|
240
|
+
static isInstance(error) {
|
|
241
|
+
return AISDKError.hasMarker(error, marker14);
|
|
196
242
|
}
|
|
197
243
|
};
|
|
198
244
|
var ParseError = class extends Error {
|
|
@@ -482,6 +528,25 @@ function isAbortError(error) {
|
|
|
482
528
|
error.name === "TimeoutError");
|
|
483
529
|
}
|
|
484
530
|
var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
|
|
531
|
+
var BUN_ERROR_CODES = [
|
|
532
|
+
"ConnectionRefused",
|
|
533
|
+
"ConnectionClosed",
|
|
534
|
+
"FailedToOpenSocket",
|
|
535
|
+
"ECONNRESET",
|
|
536
|
+
"ECONNREFUSED",
|
|
537
|
+
"ETIMEDOUT",
|
|
538
|
+
"EPIPE"
|
|
539
|
+
];
|
|
540
|
+
function isBunNetworkError(error) {
|
|
541
|
+
if (!(error instanceof Error)) {
|
|
542
|
+
return false;
|
|
543
|
+
}
|
|
544
|
+
const code = error.code;
|
|
545
|
+
if (typeof code === "string" && BUN_ERROR_CODES.includes(code)) {
|
|
546
|
+
return true;
|
|
547
|
+
}
|
|
548
|
+
return false;
|
|
549
|
+
}
|
|
485
550
|
function handleFetchError({
|
|
486
551
|
error,
|
|
487
552
|
url,
|
|
@@ -503,6 +568,15 @@ function handleFetchError({
|
|
|
503
568
|
});
|
|
504
569
|
}
|
|
505
570
|
}
|
|
571
|
+
if (isBunNetworkError(error)) {
|
|
572
|
+
return new APICallError({
|
|
573
|
+
message: `Cannot connect to API: ${error.message}`,
|
|
574
|
+
cause: error,
|
|
575
|
+
url,
|
|
576
|
+
requestBodyValues,
|
|
577
|
+
isRetryable: true
|
|
578
|
+
});
|
|
579
|
+
}
|
|
506
580
|
return error;
|
|
507
581
|
}
|
|
508
582
|
function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
@@ -551,7 +625,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
551
625
|
);
|
|
552
626
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
553
627
|
}
|
|
554
|
-
var VERSION = "4.0.
|
|
628
|
+
var VERSION = "4.0.13";
|
|
555
629
|
var getOriginalFetch = () => globalThis.fetch;
|
|
556
630
|
var getFromApi = async ({
|
|
557
631
|
url,
|
|
@@ -696,30 +770,39 @@ function secureJsonParse(text2) {
|
|
|
696
770
|
}
|
|
697
771
|
}
|
|
698
772
|
function addAdditionalPropertiesToJsonSchema(jsonSchema2) {
|
|
699
|
-
if (jsonSchema2.type === "object") {
|
|
773
|
+
if (jsonSchema2.type === "object" || Array.isArray(jsonSchema2.type) && jsonSchema2.type.includes("object")) {
|
|
700
774
|
jsonSchema2.additionalProperties = false;
|
|
701
|
-
const properties = jsonSchema2
|
|
775
|
+
const { properties } = jsonSchema2;
|
|
702
776
|
if (properties != null) {
|
|
703
|
-
for (const
|
|
704
|
-
properties[
|
|
705
|
-
properties[property]
|
|
706
|
-
);
|
|
777
|
+
for (const key of Object.keys(properties)) {
|
|
778
|
+
properties[key] = visit(properties[key]);
|
|
707
779
|
}
|
|
708
780
|
}
|
|
709
781
|
}
|
|
710
|
-
if (jsonSchema2.
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
782
|
+
if (jsonSchema2.items != null) {
|
|
783
|
+
jsonSchema2.items = Array.isArray(jsonSchema2.items) ? jsonSchema2.items.map(visit) : visit(jsonSchema2.items);
|
|
784
|
+
}
|
|
785
|
+
if (jsonSchema2.anyOf != null) {
|
|
786
|
+
jsonSchema2.anyOf = jsonSchema2.anyOf.map(visit);
|
|
787
|
+
}
|
|
788
|
+
if (jsonSchema2.allOf != null) {
|
|
789
|
+
jsonSchema2.allOf = jsonSchema2.allOf.map(visit);
|
|
790
|
+
}
|
|
791
|
+
if (jsonSchema2.oneOf != null) {
|
|
792
|
+
jsonSchema2.oneOf = jsonSchema2.oneOf.map(visit);
|
|
793
|
+
}
|
|
794
|
+
const { definitions } = jsonSchema2;
|
|
795
|
+
if (definitions != null) {
|
|
796
|
+
for (const key of Object.keys(definitions)) {
|
|
797
|
+
definitions[key] = visit(definitions[key]);
|
|
719
798
|
}
|
|
720
799
|
}
|
|
721
800
|
return jsonSchema2;
|
|
722
801
|
}
|
|
802
|
+
function visit(def) {
|
|
803
|
+
if (typeof def === "boolean") return def;
|
|
804
|
+
return addAdditionalPropertiesToJsonSchema(def);
|
|
805
|
+
}
|
|
723
806
|
var ignoreOverride = /* @__PURE__ */ Symbol(
|
|
724
807
|
"Let zodToJsonSchema decide on which parser to use"
|
|
725
808
|
);
|
|
@@ -1836,9 +1919,11 @@ function asSchema(schema) {
|
|
|
1836
1919
|
}
|
|
1837
1920
|
function standardSchema(standardSchema2) {
|
|
1838
1921
|
return jsonSchema(
|
|
1839
|
-
() =>
|
|
1840
|
-
|
|
1841
|
-
|
|
1922
|
+
() => addAdditionalPropertiesToJsonSchema(
|
|
1923
|
+
standardSchema2["~standard"].jsonSchema.input({
|
|
1924
|
+
target: "draft-07"
|
|
1925
|
+
})
|
|
1926
|
+
),
|
|
1842
1927
|
{
|
|
1843
1928
|
validate: async (value) => {
|
|
1844
1929
|
const result = await standardSchema2["~standard"].validate(value);
|
|
@@ -1901,17 +1986,19 @@ function zodSchema(zodSchema2, options) {
|
|
|
1901
1986
|
}
|
|
1902
1987
|
async function validateTypes({
|
|
1903
1988
|
value,
|
|
1904
|
-
schema
|
|
1989
|
+
schema,
|
|
1990
|
+
context: context2
|
|
1905
1991
|
}) {
|
|
1906
|
-
const result = await safeValidateTypes({ value, schema });
|
|
1992
|
+
const result = await safeValidateTypes({ value, schema, context: context2 });
|
|
1907
1993
|
if (!result.success) {
|
|
1908
|
-
throw TypeValidationError.wrap({ value, cause: result.error });
|
|
1994
|
+
throw TypeValidationError.wrap({ value, cause: result.error, context: context2 });
|
|
1909
1995
|
}
|
|
1910
1996
|
return result.value;
|
|
1911
1997
|
}
|
|
1912
1998
|
async function safeValidateTypes({
|
|
1913
1999
|
value,
|
|
1914
|
-
schema
|
|
2000
|
+
schema,
|
|
2001
|
+
context: context2
|
|
1915
2002
|
}) {
|
|
1916
2003
|
const actualSchema = asSchema(schema);
|
|
1917
2004
|
try {
|
|
@@ -1924,13 +2011,13 @@ async function safeValidateTypes({
|
|
|
1924
2011
|
}
|
|
1925
2012
|
return {
|
|
1926
2013
|
success: false,
|
|
1927
|
-
error: TypeValidationError.wrap({ value, cause: result.error }),
|
|
2014
|
+
error: TypeValidationError.wrap({ value, cause: result.error, context: context2 }),
|
|
1928
2015
|
rawValue: value
|
|
1929
2016
|
};
|
|
1930
2017
|
} catch (error) {
|
|
1931
2018
|
return {
|
|
1932
2019
|
success: false,
|
|
1933
|
-
error: TypeValidationError.wrap({ value, cause: error }),
|
|
2020
|
+
error: TypeValidationError.wrap({ value, cause: error, context: context2 }),
|
|
1934
2021
|
rawValue: value
|
|
1935
2022
|
};
|
|
1936
2023
|
}
|
|
@@ -2078,6 +2165,38 @@ var postToApi = async ({
|
|
|
2078
2165
|
throw handleFetchError({ error, url, requestBodyValues: body.values });
|
|
2079
2166
|
}
|
|
2080
2167
|
};
|
|
2168
|
+
function tool(tool2) {
|
|
2169
|
+
return tool2;
|
|
2170
|
+
}
|
|
2171
|
+
function createProviderToolFactoryWithOutputSchema({
|
|
2172
|
+
id,
|
|
2173
|
+
inputSchema,
|
|
2174
|
+
outputSchema: outputSchema2,
|
|
2175
|
+
supportsDeferredResults
|
|
2176
|
+
}) {
|
|
2177
|
+
return ({
|
|
2178
|
+
execute,
|
|
2179
|
+
needsApproval,
|
|
2180
|
+
toModelOutput,
|
|
2181
|
+
onInputStart,
|
|
2182
|
+
onInputDelta,
|
|
2183
|
+
onInputAvailable,
|
|
2184
|
+
...args
|
|
2185
|
+
}) => tool({
|
|
2186
|
+
type: "provider",
|
|
2187
|
+
id,
|
|
2188
|
+
args,
|
|
2189
|
+
inputSchema,
|
|
2190
|
+
outputSchema: outputSchema2,
|
|
2191
|
+
execute,
|
|
2192
|
+
needsApproval,
|
|
2193
|
+
toModelOutput,
|
|
2194
|
+
onInputStart,
|
|
2195
|
+
onInputDelta,
|
|
2196
|
+
onInputAvailable,
|
|
2197
|
+
supportsDeferredResults
|
|
2198
|
+
});
|
|
2199
|
+
}
|
|
2081
2200
|
async function resolve(value) {
|
|
2082
2201
|
if (typeof value === "function") {
|
|
2083
2202
|
value = value();
|
|
@@ -2199,14 +2318,14 @@ async function* executeTool({
|
|
|
2199
2318
|
}
|
|
2200
2319
|
}
|
|
2201
2320
|
var require_get_context = __commonJS({
|
|
2202
|
-
"../../../node_modules/.pnpm/@vercel+oidc@3.0
|
|
2321
|
+
"../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/get-context.js"(exports$1, module) {
|
|
2203
2322
|
var __defProp2 = Object.defineProperty;
|
|
2204
2323
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
2205
2324
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2206
2325
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
2207
2326
|
var __export2 = (target, all) => {
|
|
2208
|
-
for (var
|
|
2209
|
-
__defProp2(target,
|
|
2327
|
+
for (var name21 in all)
|
|
2328
|
+
__defProp2(target, name21, { get: all[name21], enumerable: true });
|
|
2210
2329
|
};
|
|
2211
2330
|
var __copyProps = (to, from, except, desc) => {
|
|
2212
2331
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -2231,14 +2350,14 @@ var require_get_context = __commonJS({
|
|
|
2231
2350
|
}
|
|
2232
2351
|
});
|
|
2233
2352
|
var require_get_vercel_oidc_token = __commonJS({
|
|
2234
|
-
"../../../node_modules/.pnpm/@vercel+oidc@3.0
|
|
2353
|
+
"../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/get-vercel-oidc-token.js"(exports$1, module) {
|
|
2235
2354
|
var __defProp2 = Object.defineProperty;
|
|
2236
2355
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
2237
2356
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2238
2357
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
2239
2358
|
var __export2 = (target, all) => {
|
|
2240
|
-
for (var
|
|
2241
|
-
__defProp2(target,
|
|
2359
|
+
for (var name21 in all)
|
|
2360
|
+
__defProp2(target, name21, { get: all[name21], enumerable: true });
|
|
2242
2361
|
};
|
|
2243
2362
|
var __copyProps = (to, from, except, desc) => {
|
|
2244
2363
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -2267,19 +2386,23 @@ var require_get_vercel_oidc_token = __commonJS({
|
|
|
2267
2386
|
}
|
|
2268
2387
|
try {
|
|
2269
2388
|
const [{ getTokenPayload, isExpired }, { refreshToken }] = await Promise.all([
|
|
2270
|
-
await import('./token-util-
|
|
2271
|
-
await import('./token-
|
|
2389
|
+
await import('./token-util-RMHT2CPJ-S2YMG7N3.js'),
|
|
2390
|
+
await import('./token-APYSY3BW-QJCV2XQG.js')
|
|
2272
2391
|
]);
|
|
2273
2392
|
if (!token || isExpired(getTokenPayload(token))) {
|
|
2274
2393
|
await refreshToken();
|
|
2275
2394
|
token = getVercelOidcTokenSync2();
|
|
2276
2395
|
}
|
|
2277
2396
|
} catch (error) {
|
|
2278
|
-
|
|
2279
|
-
|
|
2397
|
+
let message = err instanceof Error ? err.message : "";
|
|
2398
|
+
if (error instanceof Error) {
|
|
2399
|
+
message = `${message}
|
|
2280
2400
|
${error.message}`;
|
|
2281
2401
|
}
|
|
2282
|
-
|
|
2402
|
+
if (message) {
|
|
2403
|
+
throw new import_token_error.VercelOidcTokenError(message);
|
|
2404
|
+
}
|
|
2405
|
+
throw error;
|
|
2283
2406
|
}
|
|
2284
2407
|
return token;
|
|
2285
2408
|
}
|
|
@@ -2295,14 +2418,14 @@ ${error.message}`;
|
|
|
2295
2418
|
}
|
|
2296
2419
|
});
|
|
2297
2420
|
var require_dist = __commonJS({
|
|
2298
|
-
"../../../node_modules/.pnpm/@vercel+oidc@3.0
|
|
2421
|
+
"../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/index.js"(exports$1, module) {
|
|
2299
2422
|
var __defProp2 = Object.defineProperty;
|
|
2300
2423
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
2301
2424
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2302
2425
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
2303
2426
|
var __export2 = (target, all) => {
|
|
2304
|
-
for (var
|
|
2305
|
-
__defProp2(target,
|
|
2427
|
+
for (var name21 in all)
|
|
2428
|
+
__defProp2(target, name21, { get: all[name21], enumerable: true });
|
|
2306
2429
|
};
|
|
2307
2430
|
var __copyProps = (to, from, except, desc) => {
|
|
2308
2431
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -2334,12 +2457,14 @@ var GatewayError = class _GatewayError extends (_b16 = Error, _a16 = symbol16, _
|
|
|
2334
2457
|
constructor({
|
|
2335
2458
|
message,
|
|
2336
2459
|
statusCode = 500,
|
|
2337
|
-
cause
|
|
2460
|
+
cause,
|
|
2461
|
+
generationId
|
|
2338
2462
|
}) {
|
|
2339
|
-
super(message);
|
|
2463
|
+
super(generationId ? `${message} [${generationId}]` : message);
|
|
2340
2464
|
this[_a16] = true;
|
|
2341
2465
|
this.statusCode = statusCode;
|
|
2342
2466
|
this.cause = cause;
|
|
2467
|
+
this.generationId = generationId;
|
|
2343
2468
|
}
|
|
2344
2469
|
/**
|
|
2345
2470
|
* Checks if the given error is a Gateway Error.
|
|
@@ -2362,9 +2487,10 @@ var GatewayAuthenticationError = class _GatewayAuthenticationError extends (_b22
|
|
|
2362
2487
|
constructor({
|
|
2363
2488
|
message = "Authentication failed",
|
|
2364
2489
|
statusCode = 401,
|
|
2365
|
-
cause
|
|
2490
|
+
cause,
|
|
2491
|
+
generationId
|
|
2366
2492
|
} = {}) {
|
|
2367
|
-
super({ message, statusCode, cause });
|
|
2493
|
+
super({ message, statusCode, cause, generationId });
|
|
2368
2494
|
this[_a22] = true;
|
|
2369
2495
|
this.name = name15;
|
|
2370
2496
|
this.type = "authentication_error";
|
|
@@ -2380,7 +2506,8 @@ var GatewayAuthenticationError = class _GatewayAuthenticationError extends (_b22
|
|
|
2380
2506
|
oidcTokenProvided,
|
|
2381
2507
|
message = "Authentication failed",
|
|
2382
2508
|
statusCode = 401,
|
|
2383
|
-
cause
|
|
2509
|
+
cause,
|
|
2510
|
+
generationId
|
|
2384
2511
|
}) {
|
|
2385
2512
|
let contextualMessage;
|
|
2386
2513
|
if (apiKeyProvided) {
|
|
@@ -2408,7 +2535,8 @@ Run 'npx vercel link' to link your project, then 'vc env pull' to fetch the toke
|
|
|
2408
2535
|
return new _GatewayAuthenticationError({
|
|
2409
2536
|
message: contextualMessage,
|
|
2410
2537
|
statusCode,
|
|
2411
|
-
cause
|
|
2538
|
+
cause,
|
|
2539
|
+
generationId
|
|
2412
2540
|
});
|
|
2413
2541
|
}
|
|
2414
2542
|
};
|
|
@@ -2421,9 +2549,10 @@ var GatewayInvalidRequestError = class extends (_b32 = GatewayError, _a32 = symb
|
|
|
2421
2549
|
constructor({
|
|
2422
2550
|
message = "Invalid request",
|
|
2423
2551
|
statusCode = 400,
|
|
2424
|
-
cause
|
|
2552
|
+
cause,
|
|
2553
|
+
generationId
|
|
2425
2554
|
} = {}) {
|
|
2426
|
-
super({ message, statusCode, cause });
|
|
2555
|
+
super({ message, statusCode, cause, generationId });
|
|
2427
2556
|
this[_a32] = true;
|
|
2428
2557
|
this.name = name22;
|
|
2429
2558
|
this.type = "invalid_request_error";
|
|
@@ -2441,9 +2570,10 @@ var GatewayRateLimitError = class extends (_b42 = GatewayError, _a42 = symbol42,
|
|
|
2441
2570
|
constructor({
|
|
2442
2571
|
message = "Rate limit exceeded",
|
|
2443
2572
|
statusCode = 429,
|
|
2444
|
-
cause
|
|
2573
|
+
cause,
|
|
2574
|
+
generationId
|
|
2445
2575
|
} = {}) {
|
|
2446
|
-
super({ message, statusCode, cause });
|
|
2576
|
+
super({ message, statusCode, cause, generationId });
|
|
2447
2577
|
this[_a42] = true;
|
|
2448
2578
|
this.name = name32;
|
|
2449
2579
|
this.type = "rate_limit_exceeded";
|
|
@@ -2469,9 +2599,10 @@ var GatewayModelNotFoundError = class extends (_b52 = GatewayError, _a52 = symbo
|
|
|
2469
2599
|
message = "Model not found",
|
|
2470
2600
|
statusCode = 404,
|
|
2471
2601
|
modelId,
|
|
2472
|
-
cause
|
|
2602
|
+
cause,
|
|
2603
|
+
generationId
|
|
2473
2604
|
} = {}) {
|
|
2474
|
-
super({ message, statusCode, cause });
|
|
2605
|
+
super({ message, statusCode, cause, generationId });
|
|
2475
2606
|
this[_a52] = true;
|
|
2476
2607
|
this.name = name42;
|
|
2477
2608
|
this.type = "model_not_found";
|
|
@@ -2490,9 +2621,10 @@ var GatewayInternalServerError = class extends (_b62 = GatewayError, _a62 = symb
|
|
|
2490
2621
|
constructor({
|
|
2491
2622
|
message = "Internal server error",
|
|
2492
2623
|
statusCode = 500,
|
|
2493
|
-
cause
|
|
2624
|
+
cause,
|
|
2625
|
+
generationId
|
|
2494
2626
|
} = {}) {
|
|
2495
|
-
super({ message, statusCode, cause });
|
|
2627
|
+
super({ message, statusCode, cause, generationId });
|
|
2496
2628
|
this[_a62] = true;
|
|
2497
2629
|
this.name = name52;
|
|
2498
2630
|
this.type = "internal_server_error";
|
|
@@ -2512,9 +2644,10 @@ var GatewayResponseError = class extends (_b72 = GatewayError, _a72 = symbol72,
|
|
|
2512
2644
|
statusCode = 502,
|
|
2513
2645
|
response,
|
|
2514
2646
|
validationError,
|
|
2515
|
-
cause
|
|
2647
|
+
cause,
|
|
2648
|
+
generationId
|
|
2516
2649
|
} = {}) {
|
|
2517
|
-
super({ message, statusCode, cause });
|
|
2650
|
+
super({ message, statusCode, cause, generationId });
|
|
2518
2651
|
this[_a72] = true;
|
|
2519
2652
|
this.name = name62;
|
|
2520
2653
|
this.type = "response_error";
|
|
@@ -2532,34 +2665,49 @@ async function createGatewayErrorFromResponse({
|
|
|
2532
2665
|
cause,
|
|
2533
2666
|
authMethod
|
|
2534
2667
|
}) {
|
|
2668
|
+
var _a83;
|
|
2535
2669
|
const parseResult = await safeValidateTypes({
|
|
2536
2670
|
value: response,
|
|
2537
2671
|
schema: gatewayErrorResponseSchema
|
|
2538
2672
|
});
|
|
2539
2673
|
if (!parseResult.success) {
|
|
2674
|
+
const rawGenerationId = typeof response === "object" && response !== null && "generationId" in response ? response.generationId : void 0;
|
|
2540
2675
|
return new GatewayResponseError({
|
|
2541
2676
|
message: `Invalid error response format: ${defaultMessage}`,
|
|
2542
2677
|
statusCode,
|
|
2543
2678
|
response,
|
|
2544
2679
|
validationError: parseResult.error,
|
|
2545
|
-
cause
|
|
2680
|
+
cause,
|
|
2681
|
+
generationId: rawGenerationId
|
|
2546
2682
|
});
|
|
2547
2683
|
}
|
|
2548
2684
|
const validatedResponse = parseResult.value;
|
|
2549
2685
|
const errorType = validatedResponse.error.type;
|
|
2550
2686
|
const message = validatedResponse.error.message;
|
|
2687
|
+
const generationId = (_a83 = validatedResponse.generationId) != null ? _a83 : void 0;
|
|
2551
2688
|
switch (errorType) {
|
|
2552
2689
|
case "authentication_error":
|
|
2553
2690
|
return GatewayAuthenticationError.createContextualError({
|
|
2554
2691
|
apiKeyProvided: authMethod === "api-key",
|
|
2555
2692
|
oidcTokenProvided: authMethod === "oidc",
|
|
2556
2693
|
statusCode,
|
|
2557
|
-
cause
|
|
2694
|
+
cause,
|
|
2695
|
+
generationId
|
|
2558
2696
|
});
|
|
2559
2697
|
case "invalid_request_error":
|
|
2560
|
-
return new GatewayInvalidRequestError({
|
|
2698
|
+
return new GatewayInvalidRequestError({
|
|
2699
|
+
message,
|
|
2700
|
+
statusCode,
|
|
2701
|
+
cause,
|
|
2702
|
+
generationId
|
|
2703
|
+
});
|
|
2561
2704
|
case "rate_limit_exceeded":
|
|
2562
|
-
return new GatewayRateLimitError({
|
|
2705
|
+
return new GatewayRateLimitError({
|
|
2706
|
+
message,
|
|
2707
|
+
statusCode,
|
|
2708
|
+
cause,
|
|
2709
|
+
generationId
|
|
2710
|
+
});
|
|
2563
2711
|
case "model_not_found": {
|
|
2564
2712
|
const modelResult = await safeValidateTypes({
|
|
2565
2713
|
value: validatedResponse.error.param,
|
|
@@ -2569,13 +2717,24 @@ async function createGatewayErrorFromResponse({
|
|
|
2569
2717
|
message,
|
|
2570
2718
|
statusCode,
|
|
2571
2719
|
modelId: modelResult.success ? modelResult.value.modelId : void 0,
|
|
2572
|
-
cause
|
|
2720
|
+
cause,
|
|
2721
|
+
generationId
|
|
2573
2722
|
});
|
|
2574
2723
|
}
|
|
2575
2724
|
case "internal_server_error":
|
|
2576
|
-
return new GatewayInternalServerError({
|
|
2725
|
+
return new GatewayInternalServerError({
|
|
2726
|
+
message,
|
|
2727
|
+
statusCode,
|
|
2728
|
+
cause,
|
|
2729
|
+
generationId
|
|
2730
|
+
});
|
|
2577
2731
|
default:
|
|
2578
|
-
return new GatewayInternalServerError({
|
|
2732
|
+
return new GatewayInternalServerError({
|
|
2733
|
+
message,
|
|
2734
|
+
statusCode,
|
|
2735
|
+
cause,
|
|
2736
|
+
generationId
|
|
2737
|
+
});
|
|
2579
2738
|
}
|
|
2580
2739
|
}
|
|
2581
2740
|
var gatewayErrorResponseSchema = lazySchema(
|
|
@@ -2586,7 +2745,8 @@ var gatewayErrorResponseSchema = lazySchema(
|
|
|
2586
2745
|
type: z.string().nullish(),
|
|
2587
2746
|
param: z.unknown().nullish(),
|
|
2588
2747
|
code: z.union([z.string(), z.number()]).nullish()
|
|
2589
|
-
})
|
|
2748
|
+
}),
|
|
2749
|
+
generationId: z.string().nullish()
|
|
2590
2750
|
})
|
|
2591
2751
|
)
|
|
2592
2752
|
);
|
|
@@ -2862,7 +3022,7 @@ var GatewayLanguageModel = class {
|
|
|
2862
3022
|
}
|
|
2863
3023
|
getModelConfigHeaders(modelId, streaming) {
|
|
2864
3024
|
return {
|
|
2865
|
-
"ai-language-model-specification-version": "
|
|
3025
|
+
"ai-language-model-specification-version": "3",
|
|
2866
3026
|
"ai-language-model-id": modelId,
|
|
2867
3027
|
"ai-language-model-streaming": String(streaming)
|
|
2868
3028
|
};
|
|
@@ -2930,7 +3090,7 @@ var GatewayEmbeddingModel = class {
|
|
|
2930
3090
|
}
|
|
2931
3091
|
getModelConfigHeaders() {
|
|
2932
3092
|
return {
|
|
2933
|
-
"ai-embedding-model-specification-version": "
|
|
3093
|
+
"ai-embedding-model-specification-version": "3",
|
|
2934
3094
|
"ai-model-id": this.modelId
|
|
2935
3095
|
};
|
|
2936
3096
|
}
|
|
@@ -2960,6 +3120,8 @@ var GatewayImageModel = class {
|
|
|
2960
3120
|
size,
|
|
2961
3121
|
aspectRatio,
|
|
2962
3122
|
seed,
|
|
3123
|
+
files,
|
|
3124
|
+
mask,
|
|
2963
3125
|
providerOptions,
|
|
2964
3126
|
headers,
|
|
2965
3127
|
abortSignal
|
|
@@ -2984,7 +3146,11 @@ var GatewayImageModel = class {
|
|
|
2984
3146
|
...size && { size },
|
|
2985
3147
|
...aspectRatio && { aspectRatio },
|
|
2986
3148
|
...seed && { seed },
|
|
2987
|
-
...providerOptions && { providerOptions }
|
|
3149
|
+
...providerOptions && { providerOptions },
|
|
3150
|
+
...files && {
|
|
3151
|
+
files: files.map((file) => maybeEncodeImageFile(file))
|
|
3152
|
+
},
|
|
3153
|
+
...mask && { mask: maybeEncodeImageFile(mask) }
|
|
2988
3154
|
},
|
|
2989
3155
|
successfulResponseHandler: createJsonResponseHandler(
|
|
2990
3156
|
gatewayImageResponseSchema
|
|
@@ -3016,11 +3182,20 @@ var GatewayImageModel = class {
|
|
|
3016
3182
|
}
|
|
3017
3183
|
getModelConfigHeaders() {
|
|
3018
3184
|
return {
|
|
3019
|
-
"ai-image-model-specification-version": "
|
|
3185
|
+
"ai-image-model-specification-version": "3",
|
|
3020
3186
|
"ai-model-id": this.modelId
|
|
3021
3187
|
};
|
|
3022
3188
|
}
|
|
3023
3189
|
};
|
|
3190
|
+
function maybeEncodeImageFile(file) {
|
|
3191
|
+
if (file.type === "file" && file.data instanceof Uint8Array) {
|
|
3192
|
+
return {
|
|
3193
|
+
...file,
|
|
3194
|
+
data: convertUint8ArrayToBase64(file.data)
|
|
3195
|
+
};
|
|
3196
|
+
}
|
|
3197
|
+
return file;
|
|
3198
|
+
}
|
|
3024
3199
|
var providerMetadataEntrySchema = z.object({
|
|
3025
3200
|
images: z.array(z.unknown()).optional()
|
|
3026
3201
|
}).catchall(z.unknown());
|
|
@@ -3035,11 +3210,183 @@ var gatewayImageResponseSchema = z.object({
|
|
|
3035
3210
|
).optional(),
|
|
3036
3211
|
providerMetadata: z.record(z.string(), providerMetadataEntrySchema).optional()
|
|
3037
3212
|
});
|
|
3213
|
+
var parallelSearchInputSchema = lazySchema(
|
|
3214
|
+
() => zodSchema(
|
|
3215
|
+
z$1.object({
|
|
3216
|
+
objective: z$1.string().describe(
|
|
3217
|
+
"Natural-language description of the web research goal, including source or freshness guidance and broader context from the task. Maximum 5000 characters."
|
|
3218
|
+
),
|
|
3219
|
+
search_queries: z$1.array(z$1.string()).optional().describe(
|
|
3220
|
+
"Optional search queries to supplement the objective. Maximum 200 characters per query."
|
|
3221
|
+
),
|
|
3222
|
+
mode: z$1.enum(["one-shot", "agentic"]).optional().describe(
|
|
3223
|
+
'Mode preset: "one-shot" for comprehensive results with longer excerpts (default), "agentic" for concise, token-efficient results for multi-step workflows.'
|
|
3224
|
+
),
|
|
3225
|
+
max_results: z$1.number().optional().describe(
|
|
3226
|
+
"Maximum number of results to return (1-20). Defaults to 10 if not specified."
|
|
3227
|
+
),
|
|
3228
|
+
source_policy: z$1.object({
|
|
3229
|
+
include_domains: z$1.array(z$1.string()).optional().describe("List of domains to include in search results."),
|
|
3230
|
+
exclude_domains: z$1.array(z$1.string()).optional().describe("List of domains to exclude from search results."),
|
|
3231
|
+
after_date: z$1.string().optional().describe(
|
|
3232
|
+
"Only include results published after this date (ISO 8601 format)."
|
|
3233
|
+
)
|
|
3234
|
+
}).optional().describe(
|
|
3235
|
+
"Source policy for controlling which domains to include/exclude and freshness."
|
|
3236
|
+
),
|
|
3237
|
+
excerpts: z$1.object({
|
|
3238
|
+
max_chars_per_result: z$1.number().optional().describe("Maximum characters per result."),
|
|
3239
|
+
max_chars_total: z$1.number().optional().describe("Maximum total characters across all results.")
|
|
3240
|
+
}).optional().describe("Excerpt configuration for controlling result length."),
|
|
3241
|
+
fetch_policy: z$1.object({
|
|
3242
|
+
max_age_seconds: z$1.number().optional().describe(
|
|
3243
|
+
"Maximum age in seconds for cached content. Set to 0 to always fetch fresh content."
|
|
3244
|
+
)
|
|
3245
|
+
}).optional().describe("Fetch policy for controlling content freshness.")
|
|
3246
|
+
})
|
|
3247
|
+
)
|
|
3248
|
+
);
|
|
3249
|
+
var parallelSearchOutputSchema = lazySchema(
|
|
3250
|
+
() => zodSchema(
|
|
3251
|
+
z$1.union([
|
|
3252
|
+
// Success response
|
|
3253
|
+
z$1.object({
|
|
3254
|
+
searchId: z$1.string(),
|
|
3255
|
+
results: z$1.array(
|
|
3256
|
+
z$1.object({
|
|
3257
|
+
url: z$1.string(),
|
|
3258
|
+
title: z$1.string(),
|
|
3259
|
+
excerpt: z$1.string(),
|
|
3260
|
+
publishDate: z$1.string().nullable().optional(),
|
|
3261
|
+
relevanceScore: z$1.number().optional()
|
|
3262
|
+
})
|
|
3263
|
+
)
|
|
3264
|
+
}),
|
|
3265
|
+
// Error response
|
|
3266
|
+
z$1.object({
|
|
3267
|
+
error: z$1.enum([
|
|
3268
|
+
"api_error",
|
|
3269
|
+
"rate_limit",
|
|
3270
|
+
"timeout",
|
|
3271
|
+
"invalid_input",
|
|
3272
|
+
"configuration_error",
|
|
3273
|
+
"unknown"
|
|
3274
|
+
]),
|
|
3275
|
+
statusCode: z$1.number().optional(),
|
|
3276
|
+
message: z$1.string()
|
|
3277
|
+
})
|
|
3278
|
+
])
|
|
3279
|
+
)
|
|
3280
|
+
);
|
|
3281
|
+
var parallelSearchToolFactory = createProviderToolFactoryWithOutputSchema({
|
|
3282
|
+
id: "gateway.parallel_search",
|
|
3283
|
+
inputSchema: parallelSearchInputSchema,
|
|
3284
|
+
outputSchema: parallelSearchOutputSchema
|
|
3285
|
+
});
|
|
3286
|
+
var parallelSearch = (config = {}) => parallelSearchToolFactory(config);
|
|
3287
|
+
var perplexitySearchInputSchema = lazySchema(
|
|
3288
|
+
() => zodSchema(
|
|
3289
|
+
z$1.object({
|
|
3290
|
+
query: z$1.union([z$1.string(), z$1.array(z$1.string())]).describe(
|
|
3291
|
+
"Search query (string) or multiple queries (array of up to 5 strings). Multi-query searches return combined results from all queries."
|
|
3292
|
+
),
|
|
3293
|
+
max_results: z$1.number().optional().describe(
|
|
3294
|
+
"Maximum number of search results to return (1-20, default: 10)"
|
|
3295
|
+
),
|
|
3296
|
+
max_tokens_per_page: z$1.number().optional().describe(
|
|
3297
|
+
"Maximum number of tokens to extract per search result page (256-2048, default: 2048)"
|
|
3298
|
+
),
|
|
3299
|
+
max_tokens: z$1.number().optional().describe(
|
|
3300
|
+
"Maximum total tokens across all search results (default: 25000, max: 1000000)"
|
|
3301
|
+
),
|
|
3302
|
+
country: z$1.string().optional().describe(
|
|
3303
|
+
"Two-letter ISO 3166-1 alpha-2 country code for regional search results (e.g., 'US', 'GB', 'FR')"
|
|
3304
|
+
),
|
|
3305
|
+
search_domain_filter: z$1.array(z$1.string()).optional().describe(
|
|
3306
|
+
"List of domains to include or exclude from search results (max 20). To include: ['nature.com', 'science.org']. To exclude: ['-example.com', '-spam.net']"
|
|
3307
|
+
),
|
|
3308
|
+
search_language_filter: z$1.array(z$1.string()).optional().describe(
|
|
3309
|
+
"List of ISO 639-1 language codes to filter results (max 10, lowercase). Examples: ['en', 'fr', 'de']"
|
|
3310
|
+
),
|
|
3311
|
+
search_after_date: z$1.string().optional().describe(
|
|
3312
|
+
"Include only results published after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
|
|
3313
|
+
),
|
|
3314
|
+
search_before_date: z$1.string().optional().describe(
|
|
3315
|
+
"Include only results published before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
|
|
3316
|
+
),
|
|
3317
|
+
last_updated_after_filter: z$1.string().optional().describe(
|
|
3318
|
+
"Include only results last updated after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
|
|
3319
|
+
),
|
|
3320
|
+
last_updated_before_filter: z$1.string().optional().describe(
|
|
3321
|
+
"Include only results last updated before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
|
|
3322
|
+
),
|
|
3323
|
+
search_recency_filter: z$1.enum(["day", "week", "month", "year"]).optional().describe(
|
|
3324
|
+
"Filter results by relative time period. Cannot be used with search_after_date or search_before_date."
|
|
3325
|
+
)
|
|
3326
|
+
})
|
|
3327
|
+
)
|
|
3328
|
+
);
|
|
3329
|
+
var perplexitySearchOutputSchema = lazySchema(
|
|
3330
|
+
() => zodSchema(
|
|
3331
|
+
z$1.union([
|
|
3332
|
+
// Success response
|
|
3333
|
+
z$1.object({
|
|
3334
|
+
results: z$1.array(
|
|
3335
|
+
z$1.object({
|
|
3336
|
+
title: z$1.string(),
|
|
3337
|
+
url: z$1.string(),
|
|
3338
|
+
snippet: z$1.string(),
|
|
3339
|
+
date: z$1.string().optional(),
|
|
3340
|
+
lastUpdated: z$1.string().optional()
|
|
3341
|
+
})
|
|
3342
|
+
),
|
|
3343
|
+
id: z$1.string()
|
|
3344
|
+
}),
|
|
3345
|
+
// Error response
|
|
3346
|
+
z$1.object({
|
|
3347
|
+
error: z$1.enum([
|
|
3348
|
+
"api_error",
|
|
3349
|
+
"rate_limit",
|
|
3350
|
+
"timeout",
|
|
3351
|
+
"invalid_input",
|
|
3352
|
+
"unknown"
|
|
3353
|
+
]),
|
|
3354
|
+
statusCode: z$1.number().optional(),
|
|
3355
|
+
message: z$1.string()
|
|
3356
|
+
})
|
|
3357
|
+
])
|
|
3358
|
+
)
|
|
3359
|
+
);
|
|
3360
|
+
var perplexitySearchToolFactory = createProviderToolFactoryWithOutputSchema({
|
|
3361
|
+
id: "gateway.perplexity_search",
|
|
3362
|
+
inputSchema: perplexitySearchInputSchema,
|
|
3363
|
+
outputSchema: perplexitySearchOutputSchema
|
|
3364
|
+
});
|
|
3365
|
+
var perplexitySearch = (config = {}) => perplexitySearchToolFactory(config);
|
|
3366
|
+
var gatewayTools = {
|
|
3367
|
+
/**
|
|
3368
|
+
* Search the web using Parallel AI's Search API for LLM-optimized excerpts.
|
|
3369
|
+
*
|
|
3370
|
+
* Takes a natural language objective and returns relevant excerpts,
|
|
3371
|
+
* replacing multiple keyword searches with a single call for broad
|
|
3372
|
+
* or complex queries. Supports different search types for depth vs
|
|
3373
|
+
* breadth tradeoffs.
|
|
3374
|
+
*/
|
|
3375
|
+
parallelSearch,
|
|
3376
|
+
/**
|
|
3377
|
+
* Search the web using Perplexity's Search API for real-time information,
|
|
3378
|
+
* news, research papers, and articles.
|
|
3379
|
+
*
|
|
3380
|
+
* Provides ranked search results with advanced filtering options including
|
|
3381
|
+
* domain, language, date range, and recency filters.
|
|
3382
|
+
*/
|
|
3383
|
+
perplexitySearch
|
|
3384
|
+
};
|
|
3038
3385
|
async function getVercelRequestId() {
|
|
3039
3386
|
var _a83;
|
|
3040
3387
|
return (_a83 = (0, import_oidc.getContext)().headers) == null ? void 0 : _a83["x-vercel-id"];
|
|
3041
3388
|
}
|
|
3042
|
-
var VERSION2 = "3.0.
|
|
3389
|
+
var VERSION2 = "3.0.32";
|
|
3043
3390
|
var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
|
|
3044
3391
|
function createGatewayProvider(options = {}) {
|
|
3045
3392
|
var _a83, _b82;
|
|
@@ -3049,8 +3396,8 @@ function createGatewayProvider(options = {}) {
|
|
|
3049
3396
|
let lastFetchTime = 0;
|
|
3050
3397
|
const baseURL = (_b82 = withoutTrailingSlash(options.baseURL)) != null ? _b82 : "https://ai-gateway.vercel.sh/v3/ai";
|
|
3051
3398
|
const getHeaders = async () => {
|
|
3052
|
-
|
|
3053
|
-
|
|
3399
|
+
try {
|
|
3400
|
+
const auth = await getGatewayAuthToken(options);
|
|
3054
3401
|
return withUserAgentSuffix(
|
|
3055
3402
|
{
|
|
3056
3403
|
Authorization: `Bearer ${auth.token}`,
|
|
@@ -3060,12 +3407,14 @@ function createGatewayProvider(options = {}) {
|
|
|
3060
3407
|
},
|
|
3061
3408
|
`ai-sdk/gateway/${VERSION2}`
|
|
3062
3409
|
);
|
|
3410
|
+
} catch (error) {
|
|
3411
|
+
throw GatewayAuthenticationError.createContextualError({
|
|
3412
|
+
apiKeyProvided: false,
|
|
3413
|
+
oidcTokenProvided: false,
|
|
3414
|
+
statusCode: 401,
|
|
3415
|
+
cause: error
|
|
3416
|
+
});
|
|
3063
3417
|
}
|
|
3064
|
-
throw GatewayAuthenticationError.createContextualError({
|
|
3065
|
-
apiKeyProvided: false,
|
|
3066
|
-
oidcTokenProvided: false,
|
|
3067
|
-
statusCode: 401
|
|
3068
|
-
});
|
|
3069
3418
|
};
|
|
3070
3419
|
const createO11yHeaders = () => {
|
|
3071
3420
|
const deploymentId = loadOptionalSetting({
|
|
@@ -3164,6 +3513,7 @@ function createGatewayProvider(options = {}) {
|
|
|
3164
3513
|
};
|
|
3165
3514
|
provider.embeddingModel = createEmbeddingModel;
|
|
3166
3515
|
provider.textEmbeddingModel = createEmbeddingModel;
|
|
3516
|
+
provider.tools = gatewayTools;
|
|
3167
3517
|
return provider;
|
|
3168
3518
|
}
|
|
3169
3519
|
var gateway = createGatewayProvider();
|
|
@@ -3178,15 +3528,11 @@ async function getGatewayAuthToken(options) {
|
|
|
3178
3528
|
authMethod: "api-key"
|
|
3179
3529
|
};
|
|
3180
3530
|
}
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
};
|
|
3187
|
-
} catch (e) {
|
|
3188
|
-
return null;
|
|
3189
|
-
}
|
|
3531
|
+
const oidcToken = await (0, import_oidc2.getVercelOidcToken)();
|
|
3532
|
+
return {
|
|
3533
|
+
token: oidcToken,
|
|
3534
|
+
authMethod: "oidc"
|
|
3535
|
+
};
|
|
3190
3536
|
}
|
|
3191
3537
|
var _globalThis = typeof globalThis === "object" ? globalThis : global;
|
|
3192
3538
|
var VERSION22 = "1.9.0";
|
|
@@ -3259,11 +3605,11 @@ var major = VERSION22.split(".")[0];
|
|
|
3259
3605
|
var GLOBAL_OPENTELEMETRY_API_KEY = /* @__PURE__ */ Symbol.for("opentelemetry.js.api." + major);
|
|
3260
3606
|
var _global = _globalThis;
|
|
3261
3607
|
function registerGlobal(type, instance, diag, allowOverride) {
|
|
3262
|
-
var
|
|
3608
|
+
var _a21;
|
|
3263
3609
|
if (allowOverride === void 0) {
|
|
3264
3610
|
allowOverride = false;
|
|
3265
3611
|
}
|
|
3266
|
-
var api = _global[GLOBAL_OPENTELEMETRY_API_KEY] = (
|
|
3612
|
+
var api = _global[GLOBAL_OPENTELEMETRY_API_KEY] = (_a21 = _global[GLOBAL_OPENTELEMETRY_API_KEY]) !== null && _a21 !== void 0 ? _a21 : {
|
|
3267
3613
|
version: VERSION22
|
|
3268
3614
|
};
|
|
3269
3615
|
if (!allowOverride && api[type]) {
|
|
@@ -3281,8 +3627,8 @@ function registerGlobal(type, instance, diag, allowOverride) {
|
|
|
3281
3627
|
return true;
|
|
3282
3628
|
}
|
|
3283
3629
|
function getGlobal(type) {
|
|
3284
|
-
var
|
|
3285
|
-
var globalVersion = (
|
|
3630
|
+
var _a21, _b82;
|
|
3631
|
+
var globalVersion = (_a21 = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _a21 === void 0 ? void 0 : _a21.version;
|
|
3286
3632
|
if (!globalVersion || !isCompatible(globalVersion)) {
|
|
3287
3633
|
return;
|
|
3288
3634
|
}
|
|
@@ -3451,13 +3797,13 @@ var DiagAPI = (
|
|
|
3451
3797
|
}
|
|
3452
3798
|
var self = this;
|
|
3453
3799
|
var setLogger = function(logger, optionsOrLogLevel) {
|
|
3454
|
-
var
|
|
3800
|
+
var _a21, _b82, _c;
|
|
3455
3801
|
if (optionsOrLogLevel === void 0) {
|
|
3456
3802
|
optionsOrLogLevel = { logLevel: DiagLogLevel.INFO };
|
|
3457
3803
|
}
|
|
3458
3804
|
if (logger === self) {
|
|
3459
3805
|
var err = new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");
|
|
3460
|
-
self.error((
|
|
3806
|
+
self.error((_a21 = err.stack) !== null && _a21 !== void 0 ? _a21 : err.message);
|
|
3461
3807
|
return false;
|
|
3462
3808
|
}
|
|
3463
3809
|
if (typeof optionsOrLogLevel === "number") {
|
|
@@ -3509,14 +3855,14 @@ var BaseContext = (
|
|
|
3509
3855
|
return self._currentContext.get(key);
|
|
3510
3856
|
};
|
|
3511
3857
|
self.setValue = function(key, value) {
|
|
3512
|
-
var
|
|
3513
|
-
|
|
3514
|
-
return
|
|
3858
|
+
var context2 = new BaseContext2(self._currentContext);
|
|
3859
|
+
context2._currentContext.set(key, value);
|
|
3860
|
+
return context2;
|
|
3515
3861
|
};
|
|
3516
3862
|
self.deleteValue = function(key) {
|
|
3517
|
-
var
|
|
3518
|
-
|
|
3519
|
-
return
|
|
3863
|
+
var context2 = new BaseContext2(self._currentContext);
|
|
3864
|
+
context2._currentContext.delete(key);
|
|
3865
|
+
return context2;
|
|
3520
3866
|
};
|
|
3521
3867
|
}
|
|
3522
3868
|
return BaseContext2;
|
|
@@ -3621,16 +3967,16 @@ var ContextAPI = (
|
|
|
3621
3967
|
ContextAPI2.prototype.active = function() {
|
|
3622
3968
|
return this._getContextManager().active();
|
|
3623
3969
|
};
|
|
3624
|
-
ContextAPI2.prototype.with = function(
|
|
3625
|
-
var
|
|
3970
|
+
ContextAPI2.prototype.with = function(context2, fn, thisArg) {
|
|
3971
|
+
var _a21;
|
|
3626
3972
|
var args = [];
|
|
3627
3973
|
for (var _i = 3; _i < arguments.length; _i++) {
|
|
3628
3974
|
args[_i - 3] = arguments[_i];
|
|
3629
3975
|
}
|
|
3630
|
-
return (
|
|
3976
|
+
return (_a21 = this._getContextManager()).with.apply(_a21, __spreadArray4([context2, fn, thisArg], __read4(args), false));
|
|
3631
3977
|
};
|
|
3632
|
-
ContextAPI2.prototype.bind = function(
|
|
3633
|
-
return this._getContextManager().bind(
|
|
3978
|
+
ContextAPI2.prototype.bind = function(context2, target) {
|
|
3979
|
+
return this._getContextManager().bind(context2, target);
|
|
3634
3980
|
};
|
|
3635
3981
|
ContextAPI2.prototype._getContextManager = function() {
|
|
3636
3982
|
return getGlobal(API_NAME2) || NOOP_CONTEXT_MANAGER;
|
|
@@ -3698,24 +4044,24 @@ var NonRecordingSpan = (
|
|
|
3698
4044
|
})()
|
|
3699
4045
|
);
|
|
3700
4046
|
var SPAN_KEY = createContextKey("OpenTelemetry Context Key SPAN");
|
|
3701
|
-
function getSpan(
|
|
3702
|
-
return
|
|
4047
|
+
function getSpan(context2) {
|
|
4048
|
+
return context2.getValue(SPAN_KEY) || void 0;
|
|
3703
4049
|
}
|
|
3704
4050
|
function getActiveSpan() {
|
|
3705
4051
|
return getSpan(ContextAPI.getInstance().active());
|
|
3706
4052
|
}
|
|
3707
|
-
function setSpan(
|
|
3708
|
-
return
|
|
4053
|
+
function setSpan(context2, span) {
|
|
4054
|
+
return context2.setValue(SPAN_KEY, span);
|
|
3709
4055
|
}
|
|
3710
|
-
function deleteSpan(
|
|
3711
|
-
return
|
|
4056
|
+
function deleteSpan(context2) {
|
|
4057
|
+
return context2.deleteValue(SPAN_KEY);
|
|
3712
4058
|
}
|
|
3713
|
-
function setSpanContext(
|
|
3714
|
-
return setSpan(
|
|
4059
|
+
function setSpanContext(context2, spanContext) {
|
|
4060
|
+
return setSpan(context2, new NonRecordingSpan(spanContext));
|
|
3715
4061
|
}
|
|
3716
|
-
function getSpanContext(
|
|
3717
|
-
var
|
|
3718
|
-
return (
|
|
4062
|
+
function getSpanContext(context2) {
|
|
4063
|
+
var _a21;
|
|
4064
|
+
return (_a21 = getSpan(context2)) === null || _a21 === void 0 ? void 0 : _a21.spanContext();
|
|
3719
4065
|
}
|
|
3720
4066
|
var VALID_TRACEID_REGEX = /^([0-9a-f]{32})$/i;
|
|
3721
4067
|
var VALID_SPANID_REGEX = /^[0-9a-f]{16}$/i;
|
|
@@ -3737,22 +4083,22 @@ var NoopTracer = (
|
|
|
3737
4083
|
(function() {
|
|
3738
4084
|
function NoopTracer2() {
|
|
3739
4085
|
}
|
|
3740
|
-
NoopTracer2.prototype.startSpan = function(
|
|
3741
|
-
if (
|
|
3742
|
-
|
|
4086
|
+
NoopTracer2.prototype.startSpan = function(name21, options, context2) {
|
|
4087
|
+
if (context2 === void 0) {
|
|
4088
|
+
context2 = contextApi.active();
|
|
3743
4089
|
}
|
|
3744
4090
|
var root = Boolean(options === null || options === void 0 ? void 0 : options.root);
|
|
3745
4091
|
if (root) {
|
|
3746
4092
|
return new NonRecordingSpan();
|
|
3747
4093
|
}
|
|
3748
|
-
var parentFromContext =
|
|
4094
|
+
var parentFromContext = context2 && getSpanContext(context2);
|
|
3749
4095
|
if (isSpanContext(parentFromContext) && isSpanContextValid(parentFromContext)) {
|
|
3750
4096
|
return new NonRecordingSpan(parentFromContext);
|
|
3751
4097
|
} else {
|
|
3752
4098
|
return new NonRecordingSpan();
|
|
3753
4099
|
}
|
|
3754
4100
|
};
|
|
3755
|
-
NoopTracer2.prototype.startActiveSpan = function(
|
|
4101
|
+
NoopTracer2.prototype.startActiveSpan = function(name21, arg2, arg3, arg4) {
|
|
3756
4102
|
var opts;
|
|
3757
4103
|
var ctx;
|
|
3758
4104
|
var fn;
|
|
@@ -3769,7 +4115,7 @@ var NoopTracer = (
|
|
|
3769
4115
|
fn = arg4;
|
|
3770
4116
|
}
|
|
3771
4117
|
var parentContext = ctx !== null && ctx !== void 0 ? ctx : contextApi.active();
|
|
3772
|
-
var span = this.startSpan(
|
|
4118
|
+
var span = this.startSpan(name21, opts, parentContext);
|
|
3773
4119
|
var contextWithSpanSet = setSpan(parentContext, span);
|
|
3774
4120
|
return contextApi.with(contextWithSpanSet, fn, void 0, span);
|
|
3775
4121
|
};
|
|
@@ -3783,14 +4129,14 @@ var NOOP_TRACER = new NoopTracer();
|
|
|
3783
4129
|
var ProxyTracer = (
|
|
3784
4130
|
/** @class */
|
|
3785
4131
|
(function() {
|
|
3786
|
-
function ProxyTracer2(_provider,
|
|
4132
|
+
function ProxyTracer2(_provider, name21, version, options) {
|
|
3787
4133
|
this._provider = _provider;
|
|
3788
|
-
this.name =
|
|
4134
|
+
this.name = name21;
|
|
3789
4135
|
this.version = version;
|
|
3790
4136
|
this.options = options;
|
|
3791
4137
|
}
|
|
3792
|
-
ProxyTracer2.prototype.startSpan = function(
|
|
3793
|
-
return this._getTracer().startSpan(
|
|
4138
|
+
ProxyTracer2.prototype.startSpan = function(name21, options, context2) {
|
|
4139
|
+
return this._getTracer().startSpan(name21, options, context2);
|
|
3794
4140
|
};
|
|
3795
4141
|
ProxyTracer2.prototype.startActiveSpan = function(_name, _options, _context, _fn) {
|
|
3796
4142
|
var tracer = this._getTracer();
|
|
@@ -3827,20 +4173,20 @@ var ProxyTracerProvider = (
|
|
|
3827
4173
|
(function() {
|
|
3828
4174
|
function ProxyTracerProvider2() {
|
|
3829
4175
|
}
|
|
3830
|
-
ProxyTracerProvider2.prototype.getTracer = function(
|
|
3831
|
-
var
|
|
3832
|
-
return (
|
|
4176
|
+
ProxyTracerProvider2.prototype.getTracer = function(name21, version, options) {
|
|
4177
|
+
var _a21;
|
|
4178
|
+
return (_a21 = this.getDelegateTracer(name21, version, options)) !== null && _a21 !== void 0 ? _a21 : new ProxyTracer(this, name21, version, options);
|
|
3833
4179
|
};
|
|
3834
4180
|
ProxyTracerProvider2.prototype.getDelegate = function() {
|
|
3835
|
-
var
|
|
3836
|
-
return (
|
|
4181
|
+
var _a21;
|
|
4182
|
+
return (_a21 = this._delegate) !== null && _a21 !== void 0 ? _a21 : NOOP_TRACER_PROVIDER;
|
|
3837
4183
|
};
|
|
3838
4184
|
ProxyTracerProvider2.prototype.setDelegate = function(delegate) {
|
|
3839
4185
|
this._delegate = delegate;
|
|
3840
4186
|
};
|
|
3841
|
-
ProxyTracerProvider2.prototype.getDelegateTracer = function(
|
|
3842
|
-
var
|
|
3843
|
-
return (
|
|
4187
|
+
ProxyTracerProvider2.prototype.getDelegateTracer = function(name21, version, options) {
|
|
4188
|
+
var _a21;
|
|
4189
|
+
return (_a21 = this._delegate) === null || _a21 === void 0 ? void 0 : _a21.getTracer(name21, version, options);
|
|
3844
4190
|
};
|
|
3845
4191
|
return ProxyTracerProvider2;
|
|
3846
4192
|
})()
|
|
@@ -3851,6 +4197,7 @@ var SpanStatusCode;
|
|
|
3851
4197
|
SpanStatusCode2[SpanStatusCode2["OK"] = 1] = "OK";
|
|
3852
4198
|
SpanStatusCode2[SpanStatusCode2["ERROR"] = 2] = "ERROR";
|
|
3853
4199
|
})(SpanStatusCode || (SpanStatusCode = {}));
|
|
4200
|
+
var context = ContextAPI.getInstance();
|
|
3854
4201
|
var API_NAME3 = "trace";
|
|
3855
4202
|
var TraceAPI = (
|
|
3856
4203
|
/** @class */
|
|
@@ -3882,8 +4229,8 @@ var TraceAPI = (
|
|
|
3882
4229
|
TraceAPI2.prototype.getTracerProvider = function() {
|
|
3883
4230
|
return getGlobal(API_NAME3) || this._proxyTracerProvider;
|
|
3884
4231
|
};
|
|
3885
|
-
TraceAPI2.prototype.getTracer = function(
|
|
3886
|
-
return this.getTracerProvider().getTracer(
|
|
4232
|
+
TraceAPI2.prototype.getTracer = function(name21, version) {
|
|
4233
|
+
return this.getTracerProvider().getTracer(name21, version);
|
|
3887
4234
|
};
|
|
3888
4235
|
TraceAPI2.prototype.disable = function() {
|
|
3889
4236
|
unregisterGlobal(API_NAME3, DiagAPI.instance());
|
|
@@ -3895,8 +4242,8 @@ var TraceAPI = (
|
|
|
3895
4242
|
var trace = TraceAPI.getInstance();
|
|
3896
4243
|
var __defProp = Object.defineProperty;
|
|
3897
4244
|
var __export = (target, all) => {
|
|
3898
|
-
for (var
|
|
3899
|
-
__defProp(target,
|
|
4245
|
+
for (var name21 in all)
|
|
4246
|
+
__defProp(target, name21, { get: all[name21], enumerable: true });
|
|
3900
4247
|
};
|
|
3901
4248
|
var name72 = "AI_InvalidArgumentError";
|
|
3902
4249
|
var marker82 = `vercel.ai.error.${name72}`;
|
|
@@ -3921,10 +4268,28 @@ var InvalidArgumentError2 = class extends AISDKError {
|
|
|
3921
4268
|
}
|
|
3922
4269
|
};
|
|
3923
4270
|
_a82 = symbol82;
|
|
3924
|
-
var name322 = "
|
|
4271
|
+
var name322 = "AI_InvalidToolApprovalError";
|
|
3925
4272
|
var marker322 = `vercel.ai.error.${name322}`;
|
|
3926
4273
|
var symbol322 = Symbol.for(marker322);
|
|
3927
4274
|
var _a322;
|
|
4275
|
+
var InvalidToolApprovalError = class extends AISDKError {
|
|
4276
|
+
constructor({ approvalId }) {
|
|
4277
|
+
super({
|
|
4278
|
+
name: name322,
|
|
4279
|
+
message: `Tool approval response references unknown approvalId: "${approvalId}". No matching tool-approval-request found in message history.`
|
|
4280
|
+
});
|
|
4281
|
+
this[_a322] = true;
|
|
4282
|
+
this.approvalId = approvalId;
|
|
4283
|
+
}
|
|
4284
|
+
static isInstance(error) {
|
|
4285
|
+
return AISDKError.hasMarker(error, marker322);
|
|
4286
|
+
}
|
|
4287
|
+
};
|
|
4288
|
+
_a322 = symbol322;
|
|
4289
|
+
var name422 = "AI_InvalidToolInputError";
|
|
4290
|
+
var marker422 = `vercel.ai.error.${name422}`;
|
|
4291
|
+
var symbol422 = Symbol.for(marker422);
|
|
4292
|
+
var _a422;
|
|
3928
4293
|
var InvalidToolInputError = class extends AISDKError {
|
|
3929
4294
|
constructor({
|
|
3930
4295
|
toolInput,
|
|
@@ -3932,20 +4297,62 @@ var InvalidToolInputError = class extends AISDKError {
|
|
|
3932
4297
|
cause,
|
|
3933
4298
|
message = `Invalid input for tool ${toolName}: ${getErrorMessage(cause)}`
|
|
3934
4299
|
}) {
|
|
3935
|
-
super({ name:
|
|
3936
|
-
this[
|
|
4300
|
+
super({ name: name422, message, cause });
|
|
4301
|
+
this[_a422] = true;
|
|
3937
4302
|
this.toolInput = toolInput;
|
|
3938
4303
|
this.toolName = toolName;
|
|
3939
4304
|
}
|
|
3940
4305
|
static isInstance(error) {
|
|
3941
|
-
return AISDKError.hasMarker(error,
|
|
4306
|
+
return AISDKError.hasMarker(error, marker422);
|
|
3942
4307
|
}
|
|
3943
4308
|
};
|
|
3944
|
-
|
|
3945
|
-
var name522 = "
|
|
4309
|
+
_a422 = symbol422;
|
|
4310
|
+
var name522 = "AI_ToolCallNotFoundForApprovalError";
|
|
3946
4311
|
var marker522 = `vercel.ai.error.${name522}`;
|
|
3947
4312
|
var symbol522 = Symbol.for(marker522);
|
|
3948
4313
|
var _a522;
|
|
4314
|
+
var ToolCallNotFoundForApprovalError = class extends AISDKError {
|
|
4315
|
+
constructor({
|
|
4316
|
+
toolCallId,
|
|
4317
|
+
approvalId
|
|
4318
|
+
}) {
|
|
4319
|
+
super({
|
|
4320
|
+
name: name522,
|
|
4321
|
+
message: `Tool call "${toolCallId}" not found for approval request "${approvalId}".`
|
|
4322
|
+
});
|
|
4323
|
+
this[_a522] = true;
|
|
4324
|
+
this.toolCallId = toolCallId;
|
|
4325
|
+
this.approvalId = approvalId;
|
|
4326
|
+
}
|
|
4327
|
+
static isInstance(error) {
|
|
4328
|
+
return AISDKError.hasMarker(error, marker522);
|
|
4329
|
+
}
|
|
4330
|
+
};
|
|
4331
|
+
_a522 = symbol522;
|
|
4332
|
+
var name622 = "AI_MissingToolResultsError";
|
|
4333
|
+
var marker622 = `vercel.ai.error.${name622}`;
|
|
4334
|
+
var symbol622 = Symbol.for(marker622);
|
|
4335
|
+
var _a622;
|
|
4336
|
+
var MissingToolResultsError = class extends AISDKError {
|
|
4337
|
+
constructor({ toolCallIds }) {
|
|
4338
|
+
super({
|
|
4339
|
+
name: name622,
|
|
4340
|
+
message: `Tool result${toolCallIds.length > 1 ? "s are" : " is"} missing for tool call${toolCallIds.length > 1 ? "s" : ""} ${toolCallIds.join(
|
|
4341
|
+
", "
|
|
4342
|
+
)}.`
|
|
4343
|
+
});
|
|
4344
|
+
this[_a622] = true;
|
|
4345
|
+
this.toolCallIds = toolCallIds;
|
|
4346
|
+
}
|
|
4347
|
+
static isInstance(error) {
|
|
4348
|
+
return AISDKError.hasMarker(error, marker622);
|
|
4349
|
+
}
|
|
4350
|
+
};
|
|
4351
|
+
_a622 = symbol622;
|
|
4352
|
+
var name82 = "AI_NoObjectGeneratedError";
|
|
4353
|
+
var marker822 = `vercel.ai.error.${name82}`;
|
|
4354
|
+
var symbol822 = Symbol.for(marker822);
|
|
4355
|
+
var _a822;
|
|
3949
4356
|
var NoObjectGeneratedError = class extends AISDKError {
|
|
3950
4357
|
constructor({
|
|
3951
4358
|
message = "No object generated.",
|
|
@@ -3955,75 +4362,75 @@ var NoObjectGeneratedError = class extends AISDKError {
|
|
|
3955
4362
|
usage,
|
|
3956
4363
|
finishReason
|
|
3957
4364
|
}) {
|
|
3958
|
-
super({ name:
|
|
3959
|
-
this[
|
|
4365
|
+
super({ name: name82, message, cause });
|
|
4366
|
+
this[_a822] = true;
|
|
3960
4367
|
this.text = text2;
|
|
3961
4368
|
this.response = response;
|
|
3962
4369
|
this.usage = usage;
|
|
3963
4370
|
this.finishReason = finishReason;
|
|
3964
4371
|
}
|
|
3965
4372
|
static isInstance(error) {
|
|
3966
|
-
return AISDKError.hasMarker(error,
|
|
4373
|
+
return AISDKError.hasMarker(error, marker822);
|
|
3967
4374
|
}
|
|
3968
4375
|
};
|
|
3969
|
-
|
|
3970
|
-
var
|
|
3971
|
-
var
|
|
3972
|
-
var
|
|
3973
|
-
var
|
|
4376
|
+
_a822 = symbol822;
|
|
4377
|
+
var name92 = "AI_NoOutputGeneratedError";
|
|
4378
|
+
var marker92 = `vercel.ai.error.${name92}`;
|
|
4379
|
+
var symbol92 = Symbol.for(marker92);
|
|
4380
|
+
var _a92;
|
|
3974
4381
|
var NoOutputGeneratedError = class extends AISDKError {
|
|
3975
4382
|
// used in isInstance
|
|
3976
4383
|
constructor({
|
|
3977
4384
|
message = "No output generated.",
|
|
3978
4385
|
cause
|
|
3979
4386
|
} = {}) {
|
|
3980
|
-
super({ name:
|
|
3981
|
-
this[
|
|
4387
|
+
super({ name: name92, message, cause });
|
|
4388
|
+
this[_a92] = true;
|
|
3982
4389
|
}
|
|
3983
4390
|
static isInstance(error) {
|
|
3984
|
-
return AISDKError.hasMarker(error,
|
|
4391
|
+
return AISDKError.hasMarker(error, marker92);
|
|
3985
4392
|
}
|
|
3986
4393
|
};
|
|
3987
|
-
|
|
3988
|
-
var
|
|
3989
|
-
var
|
|
3990
|
-
var
|
|
3991
|
-
var
|
|
4394
|
+
_a92 = symbol92;
|
|
4395
|
+
var name132 = "AI_NoSuchToolError";
|
|
4396
|
+
var marker132 = `vercel.ai.error.${name132}`;
|
|
4397
|
+
var symbol132 = Symbol.for(marker132);
|
|
4398
|
+
var _a132;
|
|
3992
4399
|
var NoSuchToolError = class extends AISDKError {
|
|
3993
4400
|
constructor({
|
|
3994
4401
|
toolName,
|
|
3995
4402
|
availableTools = void 0,
|
|
3996
4403
|
message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === void 0 ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
|
|
3997
4404
|
}) {
|
|
3998
|
-
super({ name:
|
|
3999
|
-
this[
|
|
4405
|
+
super({ name: name132, message });
|
|
4406
|
+
this[_a132] = true;
|
|
4000
4407
|
this.toolName = toolName;
|
|
4001
4408
|
this.availableTools = availableTools;
|
|
4002
4409
|
}
|
|
4003
4410
|
static isInstance(error) {
|
|
4004
|
-
return AISDKError.hasMarker(error,
|
|
4411
|
+
return AISDKError.hasMarker(error, marker132);
|
|
4005
4412
|
}
|
|
4006
4413
|
};
|
|
4007
|
-
|
|
4008
|
-
var
|
|
4009
|
-
var
|
|
4010
|
-
var
|
|
4011
|
-
var
|
|
4414
|
+
_a132 = symbol132;
|
|
4415
|
+
var name142 = "AI_ToolCallRepairError";
|
|
4416
|
+
var marker142 = `vercel.ai.error.${name142}`;
|
|
4417
|
+
var symbol142 = Symbol.for(marker142);
|
|
4418
|
+
var _a142;
|
|
4012
4419
|
var ToolCallRepairError = class extends AISDKError {
|
|
4013
4420
|
constructor({
|
|
4014
4421
|
cause,
|
|
4015
4422
|
originalError,
|
|
4016
4423
|
message = `Error repairing tool call: ${getErrorMessage(cause)}`
|
|
4017
4424
|
}) {
|
|
4018
|
-
super({ name:
|
|
4019
|
-
this[
|
|
4425
|
+
super({ name: name142, message, cause });
|
|
4426
|
+
this[_a142] = true;
|
|
4020
4427
|
this.originalError = originalError;
|
|
4021
4428
|
}
|
|
4022
4429
|
static isInstance(error) {
|
|
4023
|
-
return AISDKError.hasMarker(error,
|
|
4430
|
+
return AISDKError.hasMarker(error, marker142);
|
|
4024
4431
|
}
|
|
4025
4432
|
};
|
|
4026
|
-
|
|
4433
|
+
_a142 = symbol142;
|
|
4027
4434
|
var UnsupportedModelVersionError = class extends AISDKError {
|
|
4028
4435
|
constructor(options) {
|
|
4029
4436
|
super({
|
|
@@ -4035,45 +4442,65 @@ var UnsupportedModelVersionError = class extends AISDKError {
|
|
|
4035
4442
|
this.modelId = options.modelId;
|
|
4036
4443
|
}
|
|
4037
4444
|
};
|
|
4038
|
-
var
|
|
4039
|
-
var
|
|
4040
|
-
var
|
|
4041
|
-
var
|
|
4445
|
+
var name152 = "AI_UIMessageStreamError";
|
|
4446
|
+
var marker152 = `vercel.ai.error.${name152}`;
|
|
4447
|
+
var symbol152 = Symbol.for(marker152);
|
|
4448
|
+
var _a152;
|
|
4449
|
+
var UIMessageStreamError = class extends AISDKError {
|
|
4450
|
+
constructor({
|
|
4451
|
+
chunkType,
|
|
4452
|
+
chunkId,
|
|
4453
|
+
message
|
|
4454
|
+
}) {
|
|
4455
|
+
super({ name: name152, message });
|
|
4456
|
+
this[_a152] = true;
|
|
4457
|
+
this.chunkType = chunkType;
|
|
4458
|
+
this.chunkId = chunkId;
|
|
4459
|
+
}
|
|
4460
|
+
static isInstance(error) {
|
|
4461
|
+
return AISDKError.hasMarker(error, marker152);
|
|
4462
|
+
}
|
|
4463
|
+
};
|
|
4464
|
+
_a152 = symbol152;
|
|
4465
|
+
var name17 = "AI_InvalidMessageRoleError";
|
|
4466
|
+
var marker17 = `vercel.ai.error.${name17}`;
|
|
4467
|
+
var symbol17 = Symbol.for(marker17);
|
|
4468
|
+
var _a17;
|
|
4042
4469
|
var InvalidMessageRoleError = class extends AISDKError {
|
|
4043
4470
|
constructor({
|
|
4044
4471
|
role,
|
|
4045
4472
|
message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
|
|
4046
4473
|
}) {
|
|
4047
|
-
super({ name:
|
|
4048
|
-
this[
|
|
4474
|
+
super({ name: name17, message });
|
|
4475
|
+
this[_a17] = true;
|
|
4049
4476
|
this.role = role;
|
|
4050
4477
|
}
|
|
4051
4478
|
static isInstance(error) {
|
|
4052
|
-
return AISDKError.hasMarker(error,
|
|
4479
|
+
return AISDKError.hasMarker(error, marker17);
|
|
4053
4480
|
}
|
|
4054
4481
|
};
|
|
4055
|
-
|
|
4056
|
-
var
|
|
4057
|
-
var
|
|
4058
|
-
var
|
|
4059
|
-
var
|
|
4482
|
+
_a17 = symbol17;
|
|
4483
|
+
var name19 = "AI_RetryError";
|
|
4484
|
+
var marker19 = `vercel.ai.error.${name19}`;
|
|
4485
|
+
var symbol19 = Symbol.for(marker19);
|
|
4486
|
+
var _a19;
|
|
4060
4487
|
var RetryError = class extends AISDKError {
|
|
4061
4488
|
constructor({
|
|
4062
4489
|
message,
|
|
4063
4490
|
reason,
|
|
4064
4491
|
errors
|
|
4065
4492
|
}) {
|
|
4066
|
-
super({ name:
|
|
4067
|
-
this[
|
|
4493
|
+
super({ name: name19, message });
|
|
4494
|
+
this[_a19] = true;
|
|
4068
4495
|
this.reason = reason;
|
|
4069
4496
|
this.errors = errors;
|
|
4070
4497
|
this.lastError = errors[errors.length - 1];
|
|
4071
4498
|
}
|
|
4072
4499
|
static isInstance(error) {
|
|
4073
|
-
return AISDKError.hasMarker(error,
|
|
4500
|
+
return AISDKError.hasMarker(error, marker19);
|
|
4074
4501
|
}
|
|
4075
4502
|
};
|
|
4076
|
-
|
|
4503
|
+
_a19 = symbol19;
|
|
4077
4504
|
function formatWarning({
|
|
4078
4505
|
warning,
|
|
4079
4506
|
provider,
|
|
@@ -4269,8 +4696,29 @@ function resolveEmbeddingModel(model) {
|
|
|
4269
4696
|
return getGlobalProvider().embeddingModel(model);
|
|
4270
4697
|
}
|
|
4271
4698
|
function getGlobalProvider() {
|
|
4272
|
-
var
|
|
4273
|
-
return (
|
|
4699
|
+
var _a21;
|
|
4700
|
+
return (_a21 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a21 : gateway;
|
|
4701
|
+
}
|
|
4702
|
+
function getTotalTimeoutMs(timeout) {
|
|
4703
|
+
if (timeout == null) {
|
|
4704
|
+
return void 0;
|
|
4705
|
+
}
|
|
4706
|
+
if (typeof timeout === "number") {
|
|
4707
|
+
return timeout;
|
|
4708
|
+
}
|
|
4709
|
+
return timeout.totalMs;
|
|
4710
|
+
}
|
|
4711
|
+
function getStepTimeoutMs(timeout) {
|
|
4712
|
+
if (timeout == null || typeof timeout === "number") {
|
|
4713
|
+
return void 0;
|
|
4714
|
+
}
|
|
4715
|
+
return timeout.stepMs;
|
|
4716
|
+
}
|
|
4717
|
+
function getChunkTimeoutMs(timeout) {
|
|
4718
|
+
if (timeout == null || typeof timeout === "number") {
|
|
4719
|
+
return void 0;
|
|
4720
|
+
}
|
|
4721
|
+
return timeout.chunkMs;
|
|
4274
4722
|
}
|
|
4275
4723
|
var imageMediaTypeSignatures = [
|
|
4276
4724
|
{
|
|
@@ -4383,9 +4831,9 @@ function detectMediaType({
|
|
|
4383
4831
|
}
|
|
4384
4832
|
return void 0;
|
|
4385
4833
|
}
|
|
4386
|
-
var VERSION3 = "6.0.
|
|
4834
|
+
var VERSION3 = "6.0.69";
|
|
4387
4835
|
var download = async ({ url }) => {
|
|
4388
|
-
var
|
|
4836
|
+
var _a21;
|
|
4389
4837
|
const urlText = url.toString();
|
|
4390
4838
|
try {
|
|
4391
4839
|
const response = await fetch(urlText, {
|
|
@@ -4404,7 +4852,7 @@ var download = async ({ url }) => {
|
|
|
4404
4852
|
}
|
|
4405
4853
|
return {
|
|
4406
4854
|
data: new Uint8Array(await response.arrayBuffer()),
|
|
4407
|
-
mediaType: (
|
|
4855
|
+
mediaType: (_a21 = response.headers.get("content-type")) != null ? _a21 : void 0
|
|
4408
4856
|
};
|
|
4409
4857
|
} catch (error) {
|
|
4410
4858
|
if (DownloadError.isInstance(error)) {
|
|
@@ -4439,8 +4887,8 @@ var dataContentSchema = z.union([
|
|
|
4439
4887
|
z.custom(
|
|
4440
4888
|
// Buffer might not be available in some environments such as CloudFlare:
|
|
4441
4889
|
(value) => {
|
|
4442
|
-
var
|
|
4443
|
-
return (_b82 = (
|
|
4890
|
+
var _a21, _b82;
|
|
4891
|
+
return (_b82 = (_a21 = globalThis.Buffer) == null ? void 0 : _a21.isBuffer(value)) != null ? _b82 : false;
|
|
4444
4892
|
},
|
|
4445
4893
|
{ message: "Must be a Buffer" }
|
|
4446
4894
|
)
|
|
@@ -4494,6 +4942,32 @@ async function convertToLanguageModelPrompt({
|
|
|
4494
4942
|
download2,
|
|
4495
4943
|
supportedUrls
|
|
4496
4944
|
);
|
|
4945
|
+
const approvalIdToToolCallId = /* @__PURE__ */ new Map();
|
|
4946
|
+
for (const message of prompt.messages) {
|
|
4947
|
+
if (message.role === "assistant" && Array.isArray(message.content)) {
|
|
4948
|
+
for (const part of message.content) {
|
|
4949
|
+
if (part.type === "tool-approval-request" && "approvalId" in part && "toolCallId" in part) {
|
|
4950
|
+
approvalIdToToolCallId.set(
|
|
4951
|
+
part.approvalId,
|
|
4952
|
+
part.toolCallId
|
|
4953
|
+
);
|
|
4954
|
+
}
|
|
4955
|
+
}
|
|
4956
|
+
}
|
|
4957
|
+
}
|
|
4958
|
+
const approvedToolCallIds = /* @__PURE__ */ new Set();
|
|
4959
|
+
for (const message of prompt.messages) {
|
|
4960
|
+
if (message.role === "tool") {
|
|
4961
|
+
for (const part of message.content) {
|
|
4962
|
+
if (part.type === "tool-approval-response") {
|
|
4963
|
+
const toolCallId = approvalIdToToolCallId.get(part.approvalId);
|
|
4964
|
+
if (toolCallId) {
|
|
4965
|
+
approvedToolCallIds.add(toolCallId);
|
|
4966
|
+
}
|
|
4967
|
+
}
|
|
4968
|
+
}
|
|
4969
|
+
}
|
|
4970
|
+
}
|
|
4497
4971
|
const messages = [
|
|
4498
4972
|
...prompt.system != null ? typeof prompt.system === "string" ? [{ role: "system", content: prompt.system }] : asArray(prompt.system).map((message) => ({
|
|
4499
4973
|
role: "system",
|
|
@@ -4517,23 +4991,67 @@ async function convertToLanguageModelPrompt({
|
|
|
4517
4991
|
combinedMessages.push(message);
|
|
4518
4992
|
}
|
|
4519
4993
|
}
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4994
|
+
const toolCallIds = /* @__PURE__ */ new Set();
|
|
4995
|
+
for (const message of combinedMessages) {
|
|
4996
|
+
switch (message.role) {
|
|
4997
|
+
case "assistant": {
|
|
4998
|
+
for (const content of message.content) {
|
|
4999
|
+
if (content.type === "tool-call" && !content.providerExecuted) {
|
|
5000
|
+
toolCallIds.add(content.toolCallId);
|
|
5001
|
+
}
|
|
5002
|
+
}
|
|
5003
|
+
break;
|
|
5004
|
+
}
|
|
5005
|
+
case "tool": {
|
|
5006
|
+
for (const content of message.content) {
|
|
5007
|
+
if (content.type === "tool-result") {
|
|
5008
|
+
toolCallIds.delete(content.toolCallId);
|
|
5009
|
+
}
|
|
5010
|
+
}
|
|
5011
|
+
break;
|
|
5012
|
+
}
|
|
5013
|
+
case "user":
|
|
5014
|
+
case "system":
|
|
5015
|
+
for (const id of approvedToolCallIds) {
|
|
5016
|
+
toolCallIds.delete(id);
|
|
5017
|
+
}
|
|
5018
|
+
if (toolCallIds.size > 0) {
|
|
5019
|
+
throw new MissingToolResultsError({
|
|
5020
|
+
toolCallIds: Array.from(toolCallIds)
|
|
5021
|
+
});
|
|
5022
|
+
}
|
|
5023
|
+
break;
|
|
5024
|
+
}
|
|
5025
|
+
}
|
|
5026
|
+
for (const id of approvedToolCallIds) {
|
|
5027
|
+
toolCallIds.delete(id);
|
|
5028
|
+
}
|
|
5029
|
+
if (toolCallIds.size > 0) {
|
|
5030
|
+
throw new MissingToolResultsError({ toolCallIds: Array.from(toolCallIds) });
|
|
5031
|
+
}
|
|
5032
|
+
return combinedMessages.filter(
|
|
5033
|
+
// Filter out empty tool messages (e.g. if they only contained
|
|
5034
|
+
// tool-approval-response parts that were removed).
|
|
5035
|
+
// This prevents sending invalid empty messages to the provider.
|
|
5036
|
+
// Note: provider-executed tool-approval-response parts are preserved.
|
|
5037
|
+
(message) => message.role !== "tool" || message.content.length > 0
|
|
5038
|
+
);
|
|
5039
|
+
}
|
|
5040
|
+
function convertToLanguageModelMessage({
|
|
5041
|
+
message,
|
|
5042
|
+
downloadedAssets
|
|
5043
|
+
}) {
|
|
5044
|
+
const role = message.role;
|
|
5045
|
+
switch (role) {
|
|
5046
|
+
case "system": {
|
|
5047
|
+
return {
|
|
5048
|
+
role: "system",
|
|
5049
|
+
content: message.content,
|
|
5050
|
+
providerOptions: message.providerOptions
|
|
5051
|
+
};
|
|
5052
|
+
}
|
|
5053
|
+
case "user": {
|
|
5054
|
+
if (typeof message.content === "string") {
|
|
4537
5055
|
return {
|
|
4538
5056
|
role: "user",
|
|
4539
5057
|
content: [{ type: "text", text: message.content }],
|
|
@@ -4617,13 +5135,30 @@ function convertToLanguageModelMessage({
|
|
|
4617
5135
|
case "tool": {
|
|
4618
5136
|
return {
|
|
4619
5137
|
role: "tool",
|
|
4620
|
-
content: message.content.filter(
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
5138
|
+
content: message.content.filter(
|
|
5139
|
+
// Only include tool-approval-response for provider-executed tools
|
|
5140
|
+
(part) => part.type !== "tool-approval-response" || part.providerExecuted
|
|
5141
|
+
).map((part) => {
|
|
5142
|
+
switch (part.type) {
|
|
5143
|
+
case "tool-result": {
|
|
5144
|
+
return {
|
|
5145
|
+
type: "tool-result",
|
|
5146
|
+
toolCallId: part.toolCallId,
|
|
5147
|
+
toolName: part.toolName,
|
|
5148
|
+
output: mapToolResultOutput(part.output),
|
|
5149
|
+
providerOptions: part.providerOptions
|
|
5150
|
+
};
|
|
5151
|
+
}
|
|
5152
|
+
case "tool-approval-response": {
|
|
5153
|
+
return {
|
|
5154
|
+
type: "tool-approval-response",
|
|
5155
|
+
approvalId: part.approvalId,
|
|
5156
|
+
approved: part.approved,
|
|
5157
|
+
reason: part.reason
|
|
5158
|
+
};
|
|
5159
|
+
}
|
|
5160
|
+
}
|
|
5161
|
+
}),
|
|
4627
5162
|
providerOptions: message.providerOptions
|
|
4628
5163
|
};
|
|
4629
5164
|
}
|
|
@@ -4639,8 +5174,8 @@ async function downloadAssets(messages, download2, supportedUrls) {
|
|
|
4639
5174
|
).flat().filter(
|
|
4640
5175
|
(part) => part.type === "image" || part.type === "file"
|
|
4641
5176
|
).map((part) => {
|
|
4642
|
-
var
|
|
4643
|
-
const mediaType = (
|
|
5177
|
+
var _a21;
|
|
5178
|
+
const mediaType = (_a21 = part.mediaType) != null ? _a21 : part.type === "image" ? "image/*" : void 0;
|
|
4644
5179
|
let data = part.type === "image" ? part.image : part.data;
|
|
4645
5180
|
if (typeof data === "string") {
|
|
4646
5181
|
try {
|
|
@@ -4670,7 +5205,7 @@ async function downloadAssets(messages, download2, supportedUrls) {
|
|
|
4670
5205
|
);
|
|
4671
5206
|
}
|
|
4672
5207
|
function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
4673
|
-
var
|
|
5208
|
+
var _a21;
|
|
4674
5209
|
if (part.type === "text") {
|
|
4675
5210
|
return {
|
|
4676
5211
|
type: "text",
|
|
@@ -4703,7 +5238,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
|
4703
5238
|
switch (type) {
|
|
4704
5239
|
case "image": {
|
|
4705
5240
|
if (data instanceof Uint8Array || typeof data === "string") {
|
|
4706
|
-
mediaType = (
|
|
5241
|
+
mediaType = (_a21 = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _a21 : mediaType;
|
|
4707
5242
|
}
|
|
4708
5243
|
return {
|
|
4709
5244
|
type: "file",
|
|
@@ -4879,10 +5414,10 @@ async function prepareToolsAndToolChoice({
|
|
|
4879
5414
|
};
|
|
4880
5415
|
}
|
|
4881
5416
|
const filteredTools = activeTools != null ? Object.entries(tools).filter(
|
|
4882
|
-
([
|
|
5417
|
+
([name21]) => activeTools.includes(name21)
|
|
4883
5418
|
) : Object.entries(tools);
|
|
4884
5419
|
const languageModelTools = [];
|
|
4885
|
-
for (const [
|
|
5420
|
+
for (const [name21, tool2] of filteredTools) {
|
|
4886
5421
|
const toolType = tool2.type;
|
|
4887
5422
|
switch (toolType) {
|
|
4888
5423
|
case void 0:
|
|
@@ -4890,7 +5425,7 @@ async function prepareToolsAndToolChoice({
|
|
|
4890
5425
|
case "function":
|
|
4891
5426
|
languageModelTools.push({
|
|
4892
5427
|
type: "function",
|
|
4893
|
-
name:
|
|
5428
|
+
name: name21,
|
|
4894
5429
|
description: tool2.description,
|
|
4895
5430
|
inputSchema: await asSchema(tool2.inputSchema).jsonSchema,
|
|
4896
5431
|
...tool2.inputExamples != null ? { inputExamples: tool2.inputExamples } : {},
|
|
@@ -4901,7 +5436,7 @@ async function prepareToolsAndToolChoice({
|
|
|
4901
5436
|
case "provider":
|
|
4902
5437
|
languageModelTools.push({
|
|
4903
5438
|
type: "provider",
|
|
4904
|
-
name:
|
|
5439
|
+
name: name21,
|
|
4905
5440
|
id: tool2.id,
|
|
4906
5441
|
args: tool2.args
|
|
4907
5442
|
});
|
|
@@ -5206,17 +5741,26 @@ function getBaseTelemetryAttributes({
|
|
|
5206
5741
|
telemetry,
|
|
5207
5742
|
headers
|
|
5208
5743
|
}) {
|
|
5209
|
-
var
|
|
5744
|
+
var _a21;
|
|
5210
5745
|
return {
|
|
5211
5746
|
"ai.model.provider": model.provider,
|
|
5212
5747
|
"ai.model.id": model.modelId,
|
|
5213
5748
|
// settings:
|
|
5214
5749
|
...Object.entries(settings).reduce((attributes, [key, value]) => {
|
|
5215
|
-
|
|
5750
|
+
if (key === "timeout") {
|
|
5751
|
+
const totalTimeoutMs = getTotalTimeoutMs(
|
|
5752
|
+
value
|
|
5753
|
+
);
|
|
5754
|
+
if (totalTimeoutMs != null) {
|
|
5755
|
+
attributes[`ai.settings.${key}`] = totalTimeoutMs;
|
|
5756
|
+
}
|
|
5757
|
+
} else {
|
|
5758
|
+
attributes[`ai.settings.${key}`] = value;
|
|
5759
|
+
}
|
|
5216
5760
|
return attributes;
|
|
5217
5761
|
}, {}),
|
|
5218
5762
|
// add metadata as attributes:
|
|
5219
|
-
...Object.entries((
|
|
5763
|
+
...Object.entries((_a21 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a21 : {}).reduce(
|
|
5220
5764
|
(attributes, [key, value]) => {
|
|
5221
5765
|
attributes[`ai.telemetry.metadata.${key}`] = value;
|
|
5222
5766
|
return attributes;
|
|
@@ -5236,7 +5780,7 @@ var noopTracer = {
|
|
|
5236
5780
|
startSpan() {
|
|
5237
5781
|
return noopSpan;
|
|
5238
5782
|
},
|
|
5239
|
-
startActiveSpan(
|
|
5783
|
+
startActiveSpan(name21, arg1, arg2, arg3) {
|
|
5240
5784
|
if (typeof arg1 === "function") {
|
|
5241
5785
|
return arg1(noopSpan);
|
|
5242
5786
|
}
|
|
@@ -5301,18 +5845,19 @@ function getTracer({
|
|
|
5301
5845
|
return trace.getTracer("ai");
|
|
5302
5846
|
}
|
|
5303
5847
|
async function recordSpan({
|
|
5304
|
-
name:
|
|
5848
|
+
name: name21,
|
|
5305
5849
|
tracer,
|
|
5306
5850
|
attributes,
|
|
5307
5851
|
fn,
|
|
5308
5852
|
endWhenDone = true
|
|
5309
5853
|
}) {
|
|
5310
5854
|
return tracer.startActiveSpan(
|
|
5311
|
-
|
|
5855
|
+
name21,
|
|
5312
5856
|
{ attributes: await attributes },
|
|
5313
5857
|
async (span) => {
|
|
5858
|
+
const ctx = context.active();
|
|
5314
5859
|
try {
|
|
5315
|
-
const result = await fn(span);
|
|
5860
|
+
const result = await context.with(ctx, () => fn(span));
|
|
5316
5861
|
if (endWhenDone) {
|
|
5317
5862
|
span.end();
|
|
5318
5863
|
}
|
|
@@ -5432,12 +5977,12 @@ function createNullLanguageModelUsage() {
|
|
|
5432
5977
|
};
|
|
5433
5978
|
}
|
|
5434
5979
|
function addLanguageModelUsage(usage1, usage2) {
|
|
5435
|
-
var
|
|
5980
|
+
var _a21, _b82, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
5436
5981
|
return {
|
|
5437
5982
|
inputTokens: addTokenCounts(usage1.inputTokens, usage2.inputTokens),
|
|
5438
5983
|
inputTokenDetails: {
|
|
5439
5984
|
noCacheTokens: addTokenCounts(
|
|
5440
|
-
(
|
|
5985
|
+
(_a21 = usage1.inputTokenDetails) == null ? void 0 : _a21.noCacheTokens,
|
|
5441
5986
|
(_b82 = usage2.inputTokenDetails) == null ? void 0 : _b82.noCacheTokens
|
|
5442
5987
|
),
|
|
5443
5988
|
cacheReadTokens: addTokenCounts(
|
|
@@ -5673,13 +6218,25 @@ function collectToolApprovals({
|
|
|
5673
6218
|
);
|
|
5674
6219
|
for (const approvalResponse of approvalResponses) {
|
|
5675
6220
|
const approvalRequest = toolApprovalRequestsByApprovalId[approvalResponse.approvalId];
|
|
6221
|
+
if (approvalRequest == null) {
|
|
6222
|
+
throw new InvalidToolApprovalError({
|
|
6223
|
+
approvalId: approvalResponse.approvalId
|
|
6224
|
+
});
|
|
6225
|
+
}
|
|
5676
6226
|
if (toolResults[approvalRequest.toolCallId] != null) {
|
|
5677
6227
|
continue;
|
|
5678
6228
|
}
|
|
6229
|
+
const toolCall = toolCallsByToolCallId[approvalRequest.toolCallId];
|
|
6230
|
+
if (toolCall == null) {
|
|
6231
|
+
throw new ToolCallNotFoundForApprovalError({
|
|
6232
|
+
toolCallId: approvalRequest.toolCallId,
|
|
6233
|
+
approvalId: approvalRequest.approvalId
|
|
6234
|
+
});
|
|
6235
|
+
}
|
|
5679
6236
|
const approval = {
|
|
5680
6237
|
approvalRequest,
|
|
5681
6238
|
approvalResponse,
|
|
5682
|
-
toolCall
|
|
6239
|
+
toolCall
|
|
5683
6240
|
};
|
|
5684
6241
|
if (approvalResponse.approved) {
|
|
5685
6242
|
approvedToolApprovals.push(approval);
|
|
@@ -6180,37 +6737,42 @@ async function parsePartialJson(jsonText) {
|
|
|
6180
6737
|
return { value: void 0, state: "failed-parse" };
|
|
6181
6738
|
}
|
|
6182
6739
|
var text = () => ({
|
|
6740
|
+
name: "text",
|
|
6183
6741
|
responseFormat: Promise.resolve({ type: "text" }),
|
|
6184
6742
|
async parseCompleteOutput({ text: text2 }) {
|
|
6185
6743
|
return text2;
|
|
6186
6744
|
},
|
|
6187
6745
|
async parsePartialOutput({ text: text2 }) {
|
|
6188
6746
|
return { partial: text2 };
|
|
6747
|
+
},
|
|
6748
|
+
createElementStreamTransform() {
|
|
6749
|
+
return void 0;
|
|
6189
6750
|
}
|
|
6190
6751
|
});
|
|
6191
6752
|
var object = ({
|
|
6192
6753
|
schema: inputSchema,
|
|
6193
|
-
name:
|
|
6754
|
+
name: name21,
|
|
6194
6755
|
description
|
|
6195
6756
|
}) => {
|
|
6196
6757
|
const schema = asSchema(inputSchema);
|
|
6197
6758
|
return {
|
|
6759
|
+
name: "object",
|
|
6198
6760
|
responseFormat: resolve(schema.jsonSchema).then((jsonSchema2) => ({
|
|
6199
6761
|
type: "json",
|
|
6200
6762
|
schema: jsonSchema2,
|
|
6201
|
-
...
|
|
6763
|
+
...name21 != null && { name: name21 },
|
|
6202
6764
|
...description != null && { description }
|
|
6203
6765
|
})),
|
|
6204
|
-
async parseCompleteOutput({ text: text2 },
|
|
6766
|
+
async parseCompleteOutput({ text: text2 }, context2) {
|
|
6205
6767
|
const parseResult = await safeParseJSON({ text: text2 });
|
|
6206
6768
|
if (!parseResult.success) {
|
|
6207
6769
|
throw new NoObjectGeneratedError({
|
|
6208
6770
|
message: "No object generated: could not parse the response.",
|
|
6209
6771
|
cause: parseResult.error,
|
|
6210
6772
|
text: text2,
|
|
6211
|
-
response:
|
|
6212
|
-
usage:
|
|
6213
|
-
finishReason:
|
|
6773
|
+
response: context2.response,
|
|
6774
|
+
usage: context2.usage,
|
|
6775
|
+
finishReason: context2.finishReason
|
|
6214
6776
|
});
|
|
6215
6777
|
}
|
|
6216
6778
|
const validationResult = await safeValidateTypes({
|
|
@@ -6222,9 +6784,9 @@ var object = ({
|
|
|
6222
6784
|
message: "No object generated: response did not match schema.",
|
|
6223
6785
|
cause: validationResult.error,
|
|
6224
6786
|
text: text2,
|
|
6225
|
-
response:
|
|
6226
|
-
usage:
|
|
6227
|
-
finishReason:
|
|
6787
|
+
response: context2.response,
|
|
6788
|
+
usage: context2.usage,
|
|
6789
|
+
finishReason: context2.finishReason
|
|
6228
6790
|
});
|
|
6229
6791
|
}
|
|
6230
6792
|
return validationResult.value;
|
|
@@ -6244,16 +6806,20 @@ var object = ({
|
|
|
6244
6806
|
};
|
|
6245
6807
|
}
|
|
6246
6808
|
}
|
|
6809
|
+
},
|
|
6810
|
+
createElementStreamTransform() {
|
|
6811
|
+
return void 0;
|
|
6247
6812
|
}
|
|
6248
6813
|
};
|
|
6249
6814
|
};
|
|
6250
6815
|
var array = ({
|
|
6251
6816
|
element: inputElementSchema,
|
|
6252
|
-
name:
|
|
6817
|
+
name: name21,
|
|
6253
6818
|
description
|
|
6254
6819
|
}) => {
|
|
6255
6820
|
const elementSchema = asSchema(inputElementSchema);
|
|
6256
6821
|
return {
|
|
6822
|
+
name: "array",
|
|
6257
6823
|
// JSON schema that describes an array of elements:
|
|
6258
6824
|
responseFormat: resolve(elementSchema.jsonSchema).then((jsonSchema2) => {
|
|
6259
6825
|
const { $schema, ...itemSchema } = jsonSchema2;
|
|
@@ -6268,20 +6834,20 @@ var array = ({
|
|
|
6268
6834
|
required: ["elements"],
|
|
6269
6835
|
additionalProperties: false
|
|
6270
6836
|
},
|
|
6271
|
-
...
|
|
6837
|
+
...name21 != null && { name: name21 },
|
|
6272
6838
|
...description != null && { description }
|
|
6273
6839
|
};
|
|
6274
6840
|
}),
|
|
6275
|
-
async parseCompleteOutput({ text: text2 },
|
|
6841
|
+
async parseCompleteOutput({ text: text2 }, context2) {
|
|
6276
6842
|
const parseResult = await safeParseJSON({ text: text2 });
|
|
6277
6843
|
if (!parseResult.success) {
|
|
6278
6844
|
throw new NoObjectGeneratedError({
|
|
6279
6845
|
message: "No object generated: could not parse the response.",
|
|
6280
6846
|
cause: parseResult.error,
|
|
6281
6847
|
text: text2,
|
|
6282
|
-
response:
|
|
6283
|
-
usage:
|
|
6284
|
-
finishReason:
|
|
6848
|
+
response: context2.response,
|
|
6849
|
+
usage: context2.usage,
|
|
6850
|
+
finishReason: context2.finishReason
|
|
6285
6851
|
});
|
|
6286
6852
|
}
|
|
6287
6853
|
const outerValue = parseResult.value;
|
|
@@ -6293,9 +6859,9 @@ var array = ({
|
|
|
6293
6859
|
cause: "response must be an object with an elements array"
|
|
6294
6860
|
}),
|
|
6295
6861
|
text: text2,
|
|
6296
|
-
response:
|
|
6297
|
-
usage:
|
|
6298
|
-
finishReason:
|
|
6862
|
+
response: context2.response,
|
|
6863
|
+
usage: context2.usage,
|
|
6864
|
+
finishReason: context2.finishReason
|
|
6299
6865
|
});
|
|
6300
6866
|
}
|
|
6301
6867
|
for (const element of outerValue.elements) {
|
|
@@ -6308,9 +6874,9 @@ var array = ({
|
|
|
6308
6874
|
message: "No object generated: response did not match schema.",
|
|
6309
6875
|
cause: validationResult.error,
|
|
6310
6876
|
text: text2,
|
|
6311
|
-
response:
|
|
6312
|
-
usage:
|
|
6313
|
-
finishReason:
|
|
6877
|
+
response: context2.response,
|
|
6878
|
+
usage: context2.usage,
|
|
6879
|
+
finishReason: context2.finishReason
|
|
6314
6880
|
});
|
|
6315
6881
|
}
|
|
6316
6882
|
}
|
|
@@ -6343,15 +6909,28 @@ var array = ({
|
|
|
6343
6909
|
return { partial: parsedElements };
|
|
6344
6910
|
}
|
|
6345
6911
|
}
|
|
6912
|
+
},
|
|
6913
|
+
createElementStreamTransform() {
|
|
6914
|
+
let publishedElements = 0;
|
|
6915
|
+
return new TransformStream({
|
|
6916
|
+
transform({ partialOutput }, controller) {
|
|
6917
|
+
if (partialOutput != null) {
|
|
6918
|
+
for (; publishedElements < partialOutput.length; publishedElements++) {
|
|
6919
|
+
controller.enqueue(partialOutput[publishedElements]);
|
|
6920
|
+
}
|
|
6921
|
+
}
|
|
6922
|
+
}
|
|
6923
|
+
});
|
|
6346
6924
|
}
|
|
6347
6925
|
};
|
|
6348
6926
|
};
|
|
6349
6927
|
var choice = ({
|
|
6350
6928
|
options: choiceOptions,
|
|
6351
|
-
name:
|
|
6929
|
+
name: name21,
|
|
6352
6930
|
description
|
|
6353
6931
|
}) => {
|
|
6354
6932
|
return {
|
|
6933
|
+
name: "choice",
|
|
6355
6934
|
// JSON schema that describes an enumeration:
|
|
6356
6935
|
responseFormat: Promise.resolve({
|
|
6357
6936
|
type: "json",
|
|
@@ -6364,19 +6943,19 @@ var choice = ({
|
|
|
6364
6943
|
required: ["result"],
|
|
6365
6944
|
additionalProperties: false
|
|
6366
6945
|
},
|
|
6367
|
-
...
|
|
6946
|
+
...name21 != null && { name: name21 },
|
|
6368
6947
|
...description != null && { description }
|
|
6369
6948
|
}),
|
|
6370
|
-
async parseCompleteOutput({ text: text2 },
|
|
6949
|
+
async parseCompleteOutput({ text: text2 }, context2) {
|
|
6371
6950
|
const parseResult = await safeParseJSON({ text: text2 });
|
|
6372
6951
|
if (!parseResult.success) {
|
|
6373
6952
|
throw new NoObjectGeneratedError({
|
|
6374
6953
|
message: "No object generated: could not parse the response.",
|
|
6375
6954
|
cause: parseResult.error,
|
|
6376
6955
|
text: text2,
|
|
6377
|
-
response:
|
|
6378
|
-
usage:
|
|
6379
|
-
finishReason:
|
|
6956
|
+
response: context2.response,
|
|
6957
|
+
usage: context2.usage,
|
|
6958
|
+
finishReason: context2.finishReason
|
|
6380
6959
|
});
|
|
6381
6960
|
}
|
|
6382
6961
|
const outerValue = parseResult.value;
|
|
@@ -6388,9 +6967,9 @@ var choice = ({
|
|
|
6388
6967
|
cause: "response must be an object that contains a choice value."
|
|
6389
6968
|
}),
|
|
6390
6969
|
text: text2,
|
|
6391
|
-
response:
|
|
6392
|
-
usage:
|
|
6393
|
-
finishReason:
|
|
6970
|
+
response: context2.response,
|
|
6971
|
+
usage: context2.usage,
|
|
6972
|
+
finishReason: context2.finishReason
|
|
6394
6973
|
});
|
|
6395
6974
|
}
|
|
6396
6975
|
return outerValue.result;
|
|
@@ -6418,29 +6997,33 @@ var choice = ({
|
|
|
6418
6997
|
}
|
|
6419
6998
|
}
|
|
6420
6999
|
}
|
|
7000
|
+
},
|
|
7001
|
+
createElementStreamTransform() {
|
|
7002
|
+
return void 0;
|
|
6421
7003
|
}
|
|
6422
7004
|
};
|
|
6423
7005
|
};
|
|
6424
7006
|
var json = ({
|
|
6425
|
-
name:
|
|
7007
|
+
name: name21,
|
|
6426
7008
|
description
|
|
6427
7009
|
} = {}) => {
|
|
6428
7010
|
return {
|
|
7011
|
+
name: "json",
|
|
6429
7012
|
responseFormat: Promise.resolve({
|
|
6430
7013
|
type: "json",
|
|
6431
|
-
...
|
|
7014
|
+
...name21 != null && { name: name21 },
|
|
6432
7015
|
...description != null && { description }
|
|
6433
7016
|
}),
|
|
6434
|
-
async parseCompleteOutput({ text: text2 },
|
|
7017
|
+
async parseCompleteOutput({ text: text2 }, context2) {
|
|
6435
7018
|
const parseResult = await safeParseJSON({ text: text2 });
|
|
6436
7019
|
if (!parseResult.success) {
|
|
6437
7020
|
throw new NoObjectGeneratedError({
|
|
6438
7021
|
message: "No object generated: could not parse the response.",
|
|
6439
7022
|
cause: parseResult.error,
|
|
6440
7023
|
text: text2,
|
|
6441
|
-
response:
|
|
6442
|
-
usage:
|
|
6443
|
-
finishReason:
|
|
7024
|
+
response: context2.response,
|
|
7025
|
+
usage: context2.usage,
|
|
7026
|
+
finishReason: context2.finishReason
|
|
6444
7027
|
});
|
|
6445
7028
|
}
|
|
6446
7029
|
return parseResult.value;
|
|
@@ -6457,6 +7040,9 @@ var json = ({
|
|
|
6457
7040
|
return result.value === void 0 ? void 0 : { partial: result.value };
|
|
6458
7041
|
}
|
|
6459
7042
|
}
|
|
7043
|
+
},
|
|
7044
|
+
createElementStreamTransform() {
|
|
7045
|
+
return void 0;
|
|
6460
7046
|
}
|
|
6461
7047
|
};
|
|
6462
7048
|
};
|
|
@@ -6467,7 +7053,7 @@ async function parseToolCall({
|
|
|
6467
7053
|
system,
|
|
6468
7054
|
messages
|
|
6469
7055
|
}) {
|
|
6470
|
-
var
|
|
7056
|
+
var _a21;
|
|
6471
7057
|
try {
|
|
6472
7058
|
if (tools == null) {
|
|
6473
7059
|
if (toolCall.providerExecuted && toolCall.dynamic) {
|
|
@@ -6516,7 +7102,7 @@ async function parseToolCall({
|
|
|
6516
7102
|
dynamic: true,
|
|
6517
7103
|
invalid: true,
|
|
6518
7104
|
error,
|
|
6519
|
-
title: (
|
|
7105
|
+
title: (_a21 = tools == null ? void 0 : tools[toolCall.toolName]) == null ? void 0 : _a21.title,
|
|
6520
7106
|
providerExecuted: toolCall.providerExecuted,
|
|
6521
7107
|
providerMetadata: toolCall.providerMetadata
|
|
6522
7108
|
};
|
|
@@ -6662,7 +7248,13 @@ async function toResponseMessages({
|
|
|
6662
7248
|
const responseMessages = [];
|
|
6663
7249
|
const content = [];
|
|
6664
7250
|
for (const part of inputContent) {
|
|
6665
|
-
if (part.type === "source"
|
|
7251
|
+
if (part.type === "source") {
|
|
7252
|
+
continue;
|
|
7253
|
+
}
|
|
7254
|
+
if ((part.type === "tool-result" || part.type === "tool-error") && !part.providerExecuted) {
|
|
7255
|
+
continue;
|
|
7256
|
+
}
|
|
7257
|
+
if (part.type === "text" && part.text.length === 0) {
|
|
6666
7258
|
continue;
|
|
6667
7259
|
}
|
|
6668
7260
|
switch (part.type) {
|
|
@@ -6775,6 +7367,32 @@ async function toResponseMessages({
|
|
|
6775
7367
|
}
|
|
6776
7368
|
return responseMessages;
|
|
6777
7369
|
}
|
|
7370
|
+
function mergeAbortSignals(...signals) {
|
|
7371
|
+
const validSignals = signals.filter(
|
|
7372
|
+
(signal) => signal != null
|
|
7373
|
+
);
|
|
7374
|
+
if (validSignals.length === 0) {
|
|
7375
|
+
return void 0;
|
|
7376
|
+
}
|
|
7377
|
+
if (validSignals.length === 1) {
|
|
7378
|
+
return validSignals[0];
|
|
7379
|
+
}
|
|
7380
|
+
const controller = new AbortController();
|
|
7381
|
+
for (const signal of validSignals) {
|
|
7382
|
+
if (signal.aborted) {
|
|
7383
|
+
controller.abort(signal.reason);
|
|
7384
|
+
return controller.signal;
|
|
7385
|
+
}
|
|
7386
|
+
signal.addEventListener(
|
|
7387
|
+
"abort",
|
|
7388
|
+
() => {
|
|
7389
|
+
controller.abort(signal.reason);
|
|
7390
|
+
},
|
|
7391
|
+
{ once: true }
|
|
7392
|
+
);
|
|
7393
|
+
}
|
|
7394
|
+
return controller.signal;
|
|
7395
|
+
}
|
|
6778
7396
|
var originalGenerateId = createIdGenerator({
|
|
6779
7397
|
prefix: "aitxt",
|
|
6780
7398
|
size: 24
|
|
@@ -6788,6 +7406,7 @@ async function generateText({
|
|
|
6788
7406
|
messages,
|
|
6789
7407
|
maxRetries: maxRetriesArg,
|
|
6790
7408
|
abortSignal,
|
|
7409
|
+
timeout,
|
|
6791
7410
|
headers,
|
|
6792
7411
|
stopWhen = stepCountIs(1),
|
|
6793
7412
|
experimental_output,
|
|
@@ -6801,19 +7420,25 @@ async function generateText({
|
|
|
6801
7420
|
experimental_repairToolCall: repairToolCall,
|
|
6802
7421
|
experimental_download: download2,
|
|
6803
7422
|
experimental_context,
|
|
6804
|
-
|
|
6805
|
-
|
|
6806
|
-
currentDate = () => /* @__PURE__ */ new Date()
|
|
6807
|
-
} = {},
|
|
7423
|
+
experimental_include: include,
|
|
7424
|
+
_internal: { generateId: generateId2 = originalGenerateId } = {},
|
|
6808
7425
|
onStepFinish,
|
|
6809
7426
|
onFinish,
|
|
6810
7427
|
...settings
|
|
6811
7428
|
}) {
|
|
6812
7429
|
const model = resolveLanguageModel(modelArg);
|
|
6813
7430
|
const stopConditions = asArray(stopWhen);
|
|
7431
|
+
const totalTimeoutMs = getTotalTimeoutMs(timeout);
|
|
7432
|
+
const stepTimeoutMs = getStepTimeoutMs(timeout);
|
|
7433
|
+
const stepAbortController = stepTimeoutMs != null ? new AbortController() : void 0;
|
|
7434
|
+
const mergedAbortSignal = mergeAbortSignals(
|
|
7435
|
+
abortSignal,
|
|
7436
|
+
totalTimeoutMs != null ? AbortSignal.timeout(totalTimeoutMs) : void 0,
|
|
7437
|
+
stepAbortController == null ? void 0 : stepAbortController.signal
|
|
7438
|
+
);
|
|
6814
7439
|
const { maxRetries, retry } = prepareRetries({
|
|
6815
7440
|
maxRetries: maxRetriesArg,
|
|
6816
|
-
abortSignal
|
|
7441
|
+
abortSignal: mergedAbortSignal
|
|
6817
7442
|
});
|
|
6818
7443
|
const callSettings = prepareCallSettings(settings);
|
|
6819
7444
|
const headersWithUserAgent = withUserAgentSuffix(
|
|
@@ -6854,20 +7479,23 @@ async function generateText({
|
|
|
6854
7479
|
}),
|
|
6855
7480
|
tracer,
|
|
6856
7481
|
fn: async (span) => {
|
|
6857
|
-
var
|
|
7482
|
+
var _a21, _b82, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
6858
7483
|
const initialMessages = initialPrompt.messages;
|
|
6859
7484
|
const responseMessages = [];
|
|
6860
7485
|
const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({ messages: initialMessages });
|
|
6861
|
-
|
|
7486
|
+
const localApprovedToolApprovals = approvedToolApprovals.filter(
|
|
7487
|
+
(toolApproval) => !toolApproval.toolCall.providerExecuted
|
|
7488
|
+
);
|
|
7489
|
+
if (deniedToolApprovals.length > 0 || localApprovedToolApprovals.length > 0) {
|
|
6862
7490
|
const toolOutputs = await executeTools({
|
|
6863
|
-
toolCalls:
|
|
7491
|
+
toolCalls: localApprovedToolApprovals.map(
|
|
6864
7492
|
(toolApproval) => toolApproval.toolCall
|
|
6865
7493
|
),
|
|
6866
7494
|
tools,
|
|
6867
7495
|
tracer,
|
|
6868
7496
|
telemetry,
|
|
6869
7497
|
messages: initialMessages,
|
|
6870
|
-
abortSignal,
|
|
7498
|
+
abortSignal: mergedAbortSignal,
|
|
6871
7499
|
experimental_context
|
|
6872
7500
|
});
|
|
6873
7501
|
const toolContent = [];
|
|
@@ -6893,7 +7521,15 @@ async function generateText({
|
|
|
6893
7521
|
toolName: toolApproval.toolCall.toolName,
|
|
6894
7522
|
output: {
|
|
6895
7523
|
type: "execution-denied",
|
|
6896
|
-
reason: toolApproval.approvalResponse.reason
|
|
7524
|
+
reason: toolApproval.approvalResponse.reason,
|
|
7525
|
+
// For provider-executed tools, include approvalId so provider can correlate
|
|
7526
|
+
...toolApproval.toolCall.providerExecuted && {
|
|
7527
|
+
providerOptions: {
|
|
7528
|
+
openai: {
|
|
7529
|
+
approvalId: toolApproval.approvalResponse.approvalId
|
|
7530
|
+
}
|
|
7531
|
+
}
|
|
7532
|
+
}
|
|
6897
7533
|
}
|
|
6898
7534
|
});
|
|
6899
7535
|
}
|
|
@@ -6902,6 +7538,24 @@ async function generateText({
|
|
|
6902
7538
|
content: toolContent
|
|
6903
7539
|
});
|
|
6904
7540
|
}
|
|
7541
|
+
const providerExecutedToolApprovals = [
|
|
7542
|
+
...approvedToolApprovals,
|
|
7543
|
+
...deniedToolApprovals
|
|
7544
|
+
].filter((toolApproval) => toolApproval.toolCall.providerExecuted);
|
|
7545
|
+
if (providerExecutedToolApprovals.length > 0) {
|
|
7546
|
+
responseMessages.push({
|
|
7547
|
+
role: "tool",
|
|
7548
|
+
content: providerExecutedToolApprovals.map(
|
|
7549
|
+
(toolApproval) => ({
|
|
7550
|
+
type: "tool-approval-response",
|
|
7551
|
+
approvalId: toolApproval.approvalResponse.approvalId,
|
|
7552
|
+
approved: toolApproval.approvalResponse.approved,
|
|
7553
|
+
reason: toolApproval.approvalResponse.reason,
|
|
7554
|
+
providerExecuted: true
|
|
7555
|
+
})
|
|
7556
|
+
)
|
|
7557
|
+
});
|
|
7558
|
+
}
|
|
6905
7559
|
const callSettings2 = prepareCallSettings(settings);
|
|
6906
7560
|
let currentModelResponse;
|
|
6907
7561
|
let clientToolCalls = [];
|
|
@@ -6909,263 +7563,274 @@ async function generateText({
|
|
|
6909
7563
|
const steps = [];
|
|
6910
7564
|
const pendingDeferredToolCalls = /* @__PURE__ */ new Map();
|
|
6911
7565
|
do {
|
|
6912
|
-
const
|
|
6913
|
-
|
|
6914
|
-
|
|
6915
|
-
|
|
6916
|
-
|
|
6917
|
-
|
|
6918
|
-
|
|
6919
|
-
|
|
6920
|
-
|
|
6921
|
-
|
|
6922
|
-
|
|
6923
|
-
|
|
6924
|
-
|
|
6925
|
-
|
|
6926
|
-
|
|
6927
|
-
|
|
6928
|
-
|
|
6929
|
-
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
|
|
6933
|
-
|
|
6934
|
-
toolChoice:
|
|
6935
|
-
|
|
6936
|
-
|
|
6937
|
-
|
|
6938
|
-
|
|
6939
|
-
|
|
6940
|
-
|
|
6941
|
-
|
|
6942
|
-
|
|
6943
|
-
|
|
6944
|
-
attributes: {
|
|
6945
|
-
|
|
6946
|
-
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
|
|
6950
|
-
|
|
6951
|
-
|
|
6952
|
-
|
|
6953
|
-
|
|
6954
|
-
|
|
6955
|
-
|
|
6956
|
-
|
|
6957
|
-
|
|
6958
|
-
|
|
6959
|
-
|
|
6960
|
-
|
|
6961
|
-
|
|
6962
|
-
|
|
6963
|
-
|
|
6964
|
-
|
|
6965
|
-
|
|
6966
|
-
|
|
6967
|
-
|
|
6968
|
-
|
|
6969
|
-
|
|
6970
|
-
|
|
6971
|
-
|
|
6972
|
-
|
|
6973
|
-
|
|
7566
|
+
const stepTimeoutId = stepTimeoutMs != null ? setTimeout(() => stepAbortController.abort(), stepTimeoutMs) : void 0;
|
|
7567
|
+
try {
|
|
7568
|
+
const stepInputMessages = [...initialMessages, ...responseMessages];
|
|
7569
|
+
const prepareStepResult = await (prepareStep == null ? void 0 : prepareStep({
|
|
7570
|
+
model,
|
|
7571
|
+
steps,
|
|
7572
|
+
stepNumber: steps.length,
|
|
7573
|
+
messages: stepInputMessages,
|
|
7574
|
+
experimental_context
|
|
7575
|
+
}));
|
|
7576
|
+
const stepModel = resolveLanguageModel(
|
|
7577
|
+
(_a21 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a21 : model
|
|
7578
|
+
);
|
|
7579
|
+
const promptMessages = await convertToLanguageModelPrompt({
|
|
7580
|
+
prompt: {
|
|
7581
|
+
system: (_b82 = prepareStepResult == null ? void 0 : prepareStepResult.system) != null ? _b82 : initialPrompt.system,
|
|
7582
|
+
messages: (_c = prepareStepResult == null ? void 0 : prepareStepResult.messages) != null ? _c : stepInputMessages
|
|
7583
|
+
},
|
|
7584
|
+
supportedUrls: await stepModel.supportedUrls,
|
|
7585
|
+
download: download2
|
|
7586
|
+
});
|
|
7587
|
+
experimental_context = (_d = prepareStepResult == null ? void 0 : prepareStepResult.experimental_context) != null ? _d : experimental_context;
|
|
7588
|
+
const { toolChoice: stepToolChoice, tools: stepTools } = await prepareToolsAndToolChoice({
|
|
7589
|
+
tools,
|
|
7590
|
+
toolChoice: (_e = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _e : toolChoice,
|
|
7591
|
+
activeTools: (_f = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _f : activeTools
|
|
7592
|
+
});
|
|
7593
|
+
currentModelResponse = await retry(
|
|
7594
|
+
() => {
|
|
7595
|
+
var _a2222;
|
|
7596
|
+
return recordSpan({
|
|
7597
|
+
name: "ai.generateText.doGenerate",
|
|
7598
|
+
attributes: selectTelemetryAttributes({
|
|
7599
|
+
telemetry,
|
|
7600
|
+
attributes: {
|
|
7601
|
+
...assembleOperationName({
|
|
7602
|
+
operationId: "ai.generateText.doGenerate",
|
|
7603
|
+
telemetry
|
|
7604
|
+
}),
|
|
7605
|
+
...baseTelemetryAttributes,
|
|
7606
|
+
// model:
|
|
7607
|
+
"ai.model.provider": stepModel.provider,
|
|
7608
|
+
"ai.model.id": stepModel.modelId,
|
|
7609
|
+
// prompt:
|
|
7610
|
+
"ai.prompt.messages": {
|
|
7611
|
+
input: () => stringifyForTelemetry(promptMessages)
|
|
7612
|
+
},
|
|
7613
|
+
"ai.prompt.tools": {
|
|
7614
|
+
// convert the language model level tools:
|
|
7615
|
+
input: () => stepTools == null ? void 0 : stepTools.map((tool2) => JSON.stringify(tool2))
|
|
7616
|
+
},
|
|
7617
|
+
"ai.prompt.toolChoice": {
|
|
7618
|
+
input: () => stepToolChoice != null ? JSON.stringify(stepToolChoice) : void 0
|
|
7619
|
+
},
|
|
7620
|
+
// standardized gen-ai llm span attributes:
|
|
7621
|
+
"gen_ai.system": stepModel.provider,
|
|
7622
|
+
"gen_ai.request.model": stepModel.modelId,
|
|
7623
|
+
"gen_ai.request.frequency_penalty": settings.frequencyPenalty,
|
|
7624
|
+
"gen_ai.request.max_tokens": settings.maxOutputTokens,
|
|
7625
|
+
"gen_ai.request.presence_penalty": settings.presencePenalty,
|
|
7626
|
+
"gen_ai.request.stop_sequences": settings.stopSequences,
|
|
7627
|
+
"gen_ai.request.temperature": (_a2222 = settings.temperature) != null ? _a2222 : void 0,
|
|
7628
|
+
"gen_ai.request.top_k": settings.topK,
|
|
7629
|
+
"gen_ai.request.top_p": settings.topP
|
|
7630
|
+
}
|
|
7631
|
+
}),
|
|
7632
|
+
tracer,
|
|
7633
|
+
fn: async (span2) => {
|
|
7634
|
+
var _a23, _b222, _c2, _d2, _e2, _f2, _g2, _h2;
|
|
7635
|
+
const stepProviderOptions = mergeObjects(
|
|
7636
|
+
providerOptions,
|
|
7637
|
+
prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
|
|
7638
|
+
);
|
|
7639
|
+
const result = await stepModel.doGenerate({
|
|
7640
|
+
...callSettings2,
|
|
7641
|
+
tools: stepTools,
|
|
7642
|
+
toolChoice: stepToolChoice,
|
|
7643
|
+
responseFormat: await (output == null ? void 0 : output.responseFormat),
|
|
7644
|
+
prompt: promptMessages,
|
|
7645
|
+
providerOptions: stepProviderOptions,
|
|
7646
|
+
abortSignal: mergedAbortSignal,
|
|
7647
|
+
headers: headersWithUserAgent
|
|
7648
|
+
});
|
|
7649
|
+
const responseData = {
|
|
7650
|
+
id: (_b222 = (_a23 = result.response) == null ? void 0 : _a23.id) != null ? _b222 : generateId2(),
|
|
7651
|
+
timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : /* @__PURE__ */ new Date(),
|
|
7652
|
+
modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : stepModel.modelId,
|
|
7653
|
+
headers: (_g2 = result.response) == null ? void 0 : _g2.headers,
|
|
7654
|
+
body: (_h2 = result.response) == null ? void 0 : _h2.body
|
|
7655
|
+
};
|
|
7656
|
+
span2.setAttributes(
|
|
7657
|
+
await selectTelemetryAttributes({
|
|
7658
|
+
telemetry,
|
|
7659
|
+
attributes: {
|
|
7660
|
+
"ai.response.finishReason": result.finishReason.unified,
|
|
7661
|
+
"ai.response.text": {
|
|
7662
|
+
output: () => extractTextContent(result.content)
|
|
7663
|
+
},
|
|
7664
|
+
"ai.response.toolCalls": {
|
|
7665
|
+
output: () => {
|
|
7666
|
+
const toolCalls = asToolCalls(result.content);
|
|
7667
|
+
return toolCalls == null ? void 0 : JSON.stringify(toolCalls);
|
|
7668
|
+
}
|
|
7669
|
+
},
|
|
7670
|
+
"ai.response.id": responseData.id,
|
|
7671
|
+
"ai.response.model": responseData.modelId,
|
|
7672
|
+
"ai.response.timestamp": responseData.timestamp.toISOString(),
|
|
7673
|
+
"ai.response.providerMetadata": JSON.stringify(
|
|
7674
|
+
result.providerMetadata
|
|
7675
|
+
),
|
|
7676
|
+
// TODO rename telemetry attributes to inputTokens and outputTokens
|
|
7677
|
+
"ai.usage.promptTokens": result.usage.inputTokens.total,
|
|
7678
|
+
"ai.usage.completionTokens": result.usage.outputTokens.total,
|
|
7679
|
+
// standardized gen-ai llm span attributes:
|
|
7680
|
+
"gen_ai.response.finish_reasons": [
|
|
7681
|
+
result.finishReason.unified
|
|
7682
|
+
],
|
|
7683
|
+
"gen_ai.response.id": responseData.id,
|
|
7684
|
+
"gen_ai.response.model": responseData.modelId,
|
|
7685
|
+
"gen_ai.usage.input_tokens": result.usage.inputTokens.total,
|
|
7686
|
+
"gen_ai.usage.output_tokens": result.usage.outputTokens.total
|
|
7687
|
+
}
|
|
7688
|
+
})
|
|
7689
|
+
);
|
|
7690
|
+
return { ...result, response: responseData };
|
|
6974
7691
|
}
|
|
6975
|
-
})
|
|
6976
|
-
|
|
6977
|
-
|
|
6978
|
-
|
|
6979
|
-
|
|
6980
|
-
|
|
6981
|
-
|
|
6982
|
-
|
|
6983
|
-
|
|
6984
|
-
|
|
6985
|
-
|
|
6986
|
-
|
|
6987
|
-
|
|
6988
|
-
|
|
6989
|
-
|
|
6990
|
-
|
|
6991
|
-
|
|
6992
|
-
|
|
6993
|
-
|
|
6994
|
-
|
|
6995
|
-
|
|
6996
|
-
|
|
6997
|
-
|
|
6998
|
-
|
|
6999
|
-
|
|
7000
|
-
|
|
7001
|
-
|
|
7002
|
-
|
|
7003
|
-
|
|
7004
|
-
|
|
7005
|
-
|
|
7006
|
-
|
|
7007
|
-
|
|
7008
|
-
|
|
7009
|
-
|
|
7010
|
-
|
|
7011
|
-
return toolCalls == null ? void 0 : JSON.stringify(toolCalls);
|
|
7012
|
-
}
|
|
7013
|
-
},
|
|
7014
|
-
"ai.response.id": responseData.id,
|
|
7015
|
-
"ai.response.model": responseData.modelId,
|
|
7016
|
-
"ai.response.timestamp": responseData.timestamp.toISOString(),
|
|
7017
|
-
"ai.response.providerMetadata": JSON.stringify(
|
|
7018
|
-
result.providerMetadata
|
|
7019
|
-
),
|
|
7020
|
-
// TODO rename telemetry attributes to inputTokens and outputTokens
|
|
7021
|
-
"ai.usage.promptTokens": result.usage.inputTokens.total,
|
|
7022
|
-
"ai.usage.completionTokens": result.usage.outputTokens.total,
|
|
7023
|
-
// standardized gen-ai llm span attributes:
|
|
7024
|
-
"gen_ai.response.finish_reasons": [
|
|
7025
|
-
result.finishReason.unified
|
|
7026
|
-
],
|
|
7027
|
-
"gen_ai.response.id": responseData.id,
|
|
7028
|
-
"gen_ai.response.model": responseData.modelId,
|
|
7029
|
-
"gen_ai.usage.input_tokens": result.usage.inputTokens.total,
|
|
7030
|
-
"gen_ai.usage.output_tokens": result.usage.outputTokens.total
|
|
7031
|
-
}
|
|
7032
|
-
})
|
|
7033
|
-
);
|
|
7034
|
-
return { ...result, response: responseData };
|
|
7035
|
-
}
|
|
7036
|
-
});
|
|
7037
|
-
}
|
|
7038
|
-
);
|
|
7039
|
-
const stepToolCalls = await Promise.all(
|
|
7040
|
-
currentModelResponse.content.filter(
|
|
7041
|
-
(part) => part.type === "tool-call"
|
|
7042
|
-
).map(
|
|
7043
|
-
(toolCall) => parseToolCall({
|
|
7692
|
+
});
|
|
7693
|
+
}
|
|
7694
|
+
);
|
|
7695
|
+
const stepToolCalls = await Promise.all(
|
|
7696
|
+
currentModelResponse.content.filter(
|
|
7697
|
+
(part) => part.type === "tool-call"
|
|
7698
|
+
).map(
|
|
7699
|
+
(toolCall) => parseToolCall({
|
|
7700
|
+
toolCall,
|
|
7701
|
+
tools,
|
|
7702
|
+
repairToolCall,
|
|
7703
|
+
system,
|
|
7704
|
+
messages: stepInputMessages
|
|
7705
|
+
})
|
|
7706
|
+
)
|
|
7707
|
+
);
|
|
7708
|
+
const toolApprovalRequests = {};
|
|
7709
|
+
for (const toolCall of stepToolCalls) {
|
|
7710
|
+
if (toolCall.invalid) {
|
|
7711
|
+
continue;
|
|
7712
|
+
}
|
|
7713
|
+
const tool2 = tools == null ? void 0 : tools[toolCall.toolName];
|
|
7714
|
+
if (tool2 == null) {
|
|
7715
|
+
continue;
|
|
7716
|
+
}
|
|
7717
|
+
if ((tool2 == null ? void 0 : tool2.onInputAvailable) != null) {
|
|
7718
|
+
await tool2.onInputAvailable({
|
|
7719
|
+
input: toolCall.input,
|
|
7720
|
+
toolCallId: toolCall.toolCallId,
|
|
7721
|
+
messages: stepInputMessages,
|
|
7722
|
+
abortSignal: mergedAbortSignal,
|
|
7723
|
+
experimental_context
|
|
7724
|
+
});
|
|
7725
|
+
}
|
|
7726
|
+
if (await isApprovalNeeded({
|
|
7727
|
+
tool: tool2,
|
|
7044
7728
|
toolCall,
|
|
7045
|
-
tools,
|
|
7046
|
-
repairToolCall,
|
|
7047
|
-
system,
|
|
7048
|
-
messages: stepInputMessages
|
|
7049
|
-
})
|
|
7050
|
-
)
|
|
7051
|
-
);
|
|
7052
|
-
const toolApprovalRequests = {};
|
|
7053
|
-
for (const toolCall of stepToolCalls) {
|
|
7054
|
-
if (toolCall.invalid) {
|
|
7055
|
-
continue;
|
|
7056
|
-
}
|
|
7057
|
-
const tool2 = tools == null ? void 0 : tools[toolCall.toolName];
|
|
7058
|
-
if (tool2 == null) {
|
|
7059
|
-
continue;
|
|
7060
|
-
}
|
|
7061
|
-
if ((tool2 == null ? void 0 : tool2.onInputAvailable) != null) {
|
|
7062
|
-
await tool2.onInputAvailable({
|
|
7063
|
-
input: toolCall.input,
|
|
7064
|
-
toolCallId: toolCall.toolCallId,
|
|
7065
7729
|
messages: stepInputMessages,
|
|
7066
|
-
abortSignal,
|
|
7067
7730
|
experimental_context
|
|
7068
|
-
})
|
|
7731
|
+
})) {
|
|
7732
|
+
toolApprovalRequests[toolCall.toolCallId] = {
|
|
7733
|
+
type: "tool-approval-request",
|
|
7734
|
+
approvalId: generateId2(),
|
|
7735
|
+
toolCall
|
|
7736
|
+
};
|
|
7737
|
+
}
|
|
7069
7738
|
}
|
|
7070
|
-
|
|
7071
|
-
|
|
7072
|
-
|
|
7073
|
-
|
|
7074
|
-
|
|
7075
|
-
|
|
7076
|
-
|
|
7077
|
-
|
|
7078
|
-
|
|
7079
|
-
toolCall
|
|
7080
|
-
|
|
7739
|
+
const invalidToolCalls = stepToolCalls.filter(
|
|
7740
|
+
(toolCall) => toolCall.invalid && toolCall.dynamic
|
|
7741
|
+
);
|
|
7742
|
+
clientToolOutputs = [];
|
|
7743
|
+
for (const toolCall of invalidToolCalls) {
|
|
7744
|
+
clientToolOutputs.push({
|
|
7745
|
+
type: "tool-error",
|
|
7746
|
+
toolCallId: toolCall.toolCallId,
|
|
7747
|
+
toolName: toolCall.toolName,
|
|
7748
|
+
input: toolCall.input,
|
|
7749
|
+
error: getErrorMessage2(toolCall.error),
|
|
7750
|
+
dynamic: true
|
|
7751
|
+
});
|
|
7081
7752
|
}
|
|
7082
|
-
|
|
7083
|
-
|
|
7084
|
-
(toolCall) => toolCall.invalid && toolCall.dynamic
|
|
7085
|
-
);
|
|
7086
|
-
clientToolOutputs = [];
|
|
7087
|
-
for (const toolCall of invalidToolCalls) {
|
|
7088
|
-
clientToolOutputs.push({
|
|
7089
|
-
type: "tool-error",
|
|
7090
|
-
toolCallId: toolCall.toolCallId,
|
|
7091
|
-
toolName: toolCall.toolName,
|
|
7092
|
-
input: toolCall.input,
|
|
7093
|
-
error: getErrorMessage2(toolCall.error),
|
|
7094
|
-
dynamic: true
|
|
7095
|
-
});
|
|
7096
|
-
}
|
|
7097
|
-
clientToolCalls = stepToolCalls.filter(
|
|
7098
|
-
(toolCall) => !toolCall.providerExecuted
|
|
7099
|
-
);
|
|
7100
|
-
if (tools != null) {
|
|
7101
|
-
clientToolOutputs.push(
|
|
7102
|
-
...await executeTools({
|
|
7103
|
-
toolCalls: clientToolCalls.filter(
|
|
7104
|
-
(toolCall) => !toolCall.invalid && toolApprovalRequests[toolCall.toolCallId] == null
|
|
7105
|
-
),
|
|
7106
|
-
tools,
|
|
7107
|
-
tracer,
|
|
7108
|
-
telemetry,
|
|
7109
|
-
messages: stepInputMessages,
|
|
7110
|
-
abortSignal,
|
|
7111
|
-
experimental_context
|
|
7112
|
-
})
|
|
7753
|
+
clientToolCalls = stepToolCalls.filter(
|
|
7754
|
+
(toolCall) => !toolCall.providerExecuted
|
|
7113
7755
|
);
|
|
7114
|
-
|
|
7115
|
-
|
|
7116
|
-
|
|
7117
|
-
|
|
7118
|
-
|
|
7119
|
-
|
|
7120
|
-
|
|
7121
|
-
|
|
7756
|
+
if (tools != null) {
|
|
7757
|
+
clientToolOutputs.push(
|
|
7758
|
+
...await executeTools({
|
|
7759
|
+
toolCalls: clientToolCalls.filter(
|
|
7760
|
+
(toolCall) => !toolCall.invalid && toolApprovalRequests[toolCall.toolCallId] == null
|
|
7761
|
+
),
|
|
7762
|
+
tools,
|
|
7763
|
+
tracer,
|
|
7764
|
+
telemetry,
|
|
7765
|
+
messages: stepInputMessages,
|
|
7766
|
+
abortSignal: mergedAbortSignal,
|
|
7767
|
+
experimental_context
|
|
7768
|
+
})
|
|
7122
7769
|
);
|
|
7123
|
-
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
|
|
7770
|
+
}
|
|
7771
|
+
for (const toolCall of stepToolCalls) {
|
|
7772
|
+
if (!toolCall.providerExecuted)
|
|
7773
|
+
continue;
|
|
7774
|
+
const tool2 = tools == null ? void 0 : tools[toolCall.toolName];
|
|
7775
|
+
if ((tool2 == null ? void 0 : tool2.type) === "provider" && tool2.supportsDeferredResults) {
|
|
7776
|
+
const hasResultInResponse = currentModelResponse.content.some(
|
|
7777
|
+
(part) => part.type === "tool-result" && part.toolCallId === toolCall.toolCallId
|
|
7778
|
+
);
|
|
7779
|
+
if (!hasResultInResponse) {
|
|
7780
|
+
pendingDeferredToolCalls.set(toolCall.toolCallId, {
|
|
7781
|
+
toolName: toolCall.toolName
|
|
7782
|
+
});
|
|
7783
|
+
}
|
|
7127
7784
|
}
|
|
7128
7785
|
}
|
|
7129
|
-
|
|
7130
|
-
|
|
7131
|
-
|
|
7132
|
-
|
|
7786
|
+
for (const part of currentModelResponse.content) {
|
|
7787
|
+
if (part.type === "tool-result") {
|
|
7788
|
+
pendingDeferredToolCalls.delete(part.toolCallId);
|
|
7789
|
+
}
|
|
7133
7790
|
}
|
|
7134
|
-
|
|
7135
|
-
|
|
7136
|
-
|
|
7137
|
-
|
|
7138
|
-
|
|
7139
|
-
toolApprovalRequests: Object.values(toolApprovalRequests),
|
|
7140
|
-
tools
|
|
7141
|
-
});
|
|
7142
|
-
responseMessages.push(
|
|
7143
|
-
...await toResponseMessages({
|
|
7144
|
-
content: stepContent,
|
|
7791
|
+
const stepContent = asContent({
|
|
7792
|
+
content: currentModelResponse.content,
|
|
7793
|
+
toolCalls: stepToolCalls,
|
|
7794
|
+
toolOutputs: clientToolOutputs,
|
|
7795
|
+
toolApprovalRequests: Object.values(toolApprovalRequests),
|
|
7145
7796
|
tools
|
|
7146
|
-
})
|
|
7147
|
-
|
|
7148
|
-
|
|
7149
|
-
|
|
7150
|
-
|
|
7151
|
-
|
|
7152
|
-
|
|
7153
|
-
|
|
7154
|
-
|
|
7155
|
-
request: (_g = currentModelResponse.request) != null ? _g : {},
|
|
7156
|
-
response: {
|
|
7797
|
+
});
|
|
7798
|
+
responseMessages.push(
|
|
7799
|
+
...await toResponseMessages({
|
|
7800
|
+
content: stepContent,
|
|
7801
|
+
tools
|
|
7802
|
+
})
|
|
7803
|
+
);
|
|
7804
|
+
const stepRequest = ((_g = include == null ? void 0 : include.requestBody) != null ? _g : true) ? (_h = currentModelResponse.request) != null ? _h : {} : { ...currentModelResponse.request, body: void 0 };
|
|
7805
|
+
const stepResponse = {
|
|
7157
7806
|
...currentModelResponse.response,
|
|
7158
7807
|
// deep clone msgs to avoid mutating past messages in multi-step:
|
|
7159
|
-
messages: structuredClone(responseMessages)
|
|
7160
|
-
|
|
7161
|
-
|
|
7162
|
-
|
|
7163
|
-
|
|
7164
|
-
|
|
7165
|
-
|
|
7166
|
-
|
|
7167
|
-
|
|
7168
|
-
|
|
7808
|
+
messages: structuredClone(responseMessages),
|
|
7809
|
+
// Conditionally include response body:
|
|
7810
|
+
body: ((_i = include == null ? void 0 : include.responseBody) != null ? _i : true) ? (_j = currentModelResponse.response) == null ? void 0 : _j.body : void 0
|
|
7811
|
+
};
|
|
7812
|
+
const currentStepResult = new DefaultStepResult({
|
|
7813
|
+
content: stepContent,
|
|
7814
|
+
finishReason: currentModelResponse.finishReason.unified,
|
|
7815
|
+
rawFinishReason: currentModelResponse.finishReason.raw,
|
|
7816
|
+
usage: asLanguageModelUsage(currentModelResponse.usage),
|
|
7817
|
+
warnings: currentModelResponse.warnings,
|
|
7818
|
+
providerMetadata: currentModelResponse.providerMetadata,
|
|
7819
|
+
request: stepRequest,
|
|
7820
|
+
response: stepResponse
|
|
7821
|
+
});
|
|
7822
|
+
logWarnings({
|
|
7823
|
+
warnings: (_k = currentModelResponse.warnings) != null ? _k : [],
|
|
7824
|
+
provider: stepModel.provider,
|
|
7825
|
+
model: stepModel.modelId
|
|
7826
|
+
});
|
|
7827
|
+
steps.push(currentStepResult);
|
|
7828
|
+
await (onStepFinish == null ? void 0 : onStepFinish(currentStepResult));
|
|
7829
|
+
} finally {
|
|
7830
|
+
if (stepTimeoutId != null) {
|
|
7831
|
+
clearTimeout(stepTimeoutId);
|
|
7832
|
+
}
|
|
7833
|
+
}
|
|
7169
7834
|
} while (
|
|
7170
7835
|
// Continue if:
|
|
7171
7836
|
// 1. There are client tool calls that have all been executed, OR
|
|
@@ -7456,6 +8121,23 @@ function asContent({
|
|
|
7456
8121
|
}
|
|
7457
8122
|
break;
|
|
7458
8123
|
}
|
|
8124
|
+
case "tool-approval-request": {
|
|
8125
|
+
const toolCall = toolCalls.find(
|
|
8126
|
+
(toolCall2) => toolCall2.toolCallId === part.toolCallId
|
|
8127
|
+
);
|
|
8128
|
+
if (toolCall == null) {
|
|
8129
|
+
throw new ToolCallNotFoundForApprovalError({
|
|
8130
|
+
toolCallId: part.toolCallId,
|
|
8131
|
+
approvalId: part.approvalId
|
|
8132
|
+
});
|
|
8133
|
+
}
|
|
8134
|
+
contentParts.push({
|
|
8135
|
+
type: "tool-approval-request",
|
|
8136
|
+
approvalId: part.approvalId,
|
|
8137
|
+
toolCall
|
|
8138
|
+
});
|
|
8139
|
+
break;
|
|
8140
|
+
}
|
|
7459
8141
|
}
|
|
7460
8142
|
}
|
|
7461
8143
|
return [...contentParts, ...toolOutputs, ...toolApprovalRequests];
|
|
@@ -7632,21 +8314,23 @@ function processUIMessageStream({
|
|
|
7632
8314
|
new TransformStream({
|
|
7633
8315
|
async transform(chunk, controller) {
|
|
7634
8316
|
await runUpdateMessageJob(async ({ state, write }) => {
|
|
7635
|
-
var
|
|
8317
|
+
var _a21, _b82, _c, _d;
|
|
7636
8318
|
function getToolInvocation(toolCallId) {
|
|
7637
8319
|
const toolInvocations = state.message.parts.filter(isToolUIPart);
|
|
7638
8320
|
const toolInvocation = toolInvocations.find(
|
|
7639
8321
|
(invocation) => invocation.toolCallId === toolCallId
|
|
7640
8322
|
);
|
|
7641
8323
|
if (toolInvocation == null) {
|
|
7642
|
-
throw new
|
|
7643
|
-
|
|
7644
|
-
|
|
8324
|
+
throw new UIMessageStreamError({
|
|
8325
|
+
chunkType: "tool-invocation",
|
|
8326
|
+
chunkId: toolCallId,
|
|
8327
|
+
message: `No tool invocation found for tool call ID "${toolCallId}".`
|
|
8328
|
+
});
|
|
7645
8329
|
}
|
|
7646
8330
|
return toolInvocation;
|
|
7647
8331
|
}
|
|
7648
8332
|
function updateToolPart(options) {
|
|
7649
|
-
var
|
|
8333
|
+
var _a2222;
|
|
7650
8334
|
const part = state.message.parts.find(
|
|
7651
8335
|
(part2) => isStaticToolUIPart(part2) && part2.toolCallId === options.toolCallId
|
|
7652
8336
|
);
|
|
@@ -7662,8 +8346,8 @@ function processUIMessageStream({
|
|
|
7662
8346
|
if (options.title !== void 0) {
|
|
7663
8347
|
anyPart.title = options.title;
|
|
7664
8348
|
}
|
|
7665
|
-
anyPart.providerExecuted = (
|
|
7666
|
-
if (anyOptions.providerMetadata != null
|
|
8349
|
+
anyPart.providerExecuted = (_a2222 = anyOptions.providerExecuted) != null ? _a2222 : part.providerExecuted;
|
|
8350
|
+
if (anyOptions.providerMetadata != null) {
|
|
7667
8351
|
part.callProviderMetadata = anyOptions.providerMetadata;
|
|
7668
8352
|
}
|
|
7669
8353
|
} else {
|
|
@@ -7683,7 +8367,7 @@ function processUIMessageStream({
|
|
|
7683
8367
|
}
|
|
7684
8368
|
}
|
|
7685
8369
|
function updateDynamicToolPart(options) {
|
|
7686
|
-
var
|
|
8370
|
+
var _a2222, _b222;
|
|
7687
8371
|
const part = state.message.parts.find(
|
|
7688
8372
|
(part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
|
|
7689
8373
|
);
|
|
@@ -7695,13 +8379,13 @@ function processUIMessageStream({
|
|
|
7695
8379
|
anyPart.input = anyOptions.input;
|
|
7696
8380
|
anyPart.output = anyOptions.output;
|
|
7697
8381
|
anyPart.errorText = anyOptions.errorText;
|
|
7698
|
-
anyPart.rawInput = (
|
|
8382
|
+
anyPart.rawInput = (_a2222 = anyOptions.rawInput) != null ? _a2222 : anyPart.rawInput;
|
|
7699
8383
|
anyPart.preliminary = anyOptions.preliminary;
|
|
7700
8384
|
if (options.title !== void 0) {
|
|
7701
8385
|
anyPart.title = options.title;
|
|
7702
8386
|
}
|
|
7703
8387
|
anyPart.providerExecuted = (_b222 = anyOptions.providerExecuted) != null ? _b222 : part.providerExecuted;
|
|
7704
|
-
if (anyOptions.providerMetadata != null
|
|
8388
|
+
if (anyOptions.providerMetadata != null) {
|
|
7705
8389
|
part.callProviderMetadata = anyOptions.providerMetadata;
|
|
7706
8390
|
}
|
|
7707
8391
|
} else {
|
|
@@ -7726,7 +8410,11 @@ function processUIMessageStream({
|
|
|
7726
8410
|
if (messageMetadataSchema != null) {
|
|
7727
8411
|
await validateTypes({
|
|
7728
8412
|
value: mergedMetadata,
|
|
7729
|
-
schema: messageMetadataSchema
|
|
8413
|
+
schema: messageMetadataSchema,
|
|
8414
|
+
context: {
|
|
8415
|
+
field: "message.metadata",
|
|
8416
|
+
entityId: state.message.id
|
|
8417
|
+
}
|
|
7730
8418
|
});
|
|
7731
8419
|
}
|
|
7732
8420
|
state.message.metadata = mergedMetadata;
|
|
@@ -7747,13 +8435,27 @@ function processUIMessageStream({
|
|
|
7747
8435
|
}
|
|
7748
8436
|
case "text-delta": {
|
|
7749
8437
|
const textPart = state.activeTextParts[chunk.id];
|
|
8438
|
+
if (textPart == null) {
|
|
8439
|
+
throw new UIMessageStreamError({
|
|
8440
|
+
chunkType: "text-delta",
|
|
8441
|
+
chunkId: chunk.id,
|
|
8442
|
+
message: `Received text-delta for missing text part with ID "${chunk.id}". Ensure a "text-start" chunk is sent before any "text-delta" chunks.`
|
|
8443
|
+
});
|
|
8444
|
+
}
|
|
7750
8445
|
textPart.text += chunk.delta;
|
|
7751
|
-
textPart.providerMetadata = (
|
|
8446
|
+
textPart.providerMetadata = (_a21 = chunk.providerMetadata) != null ? _a21 : textPart.providerMetadata;
|
|
7752
8447
|
write();
|
|
7753
8448
|
break;
|
|
7754
8449
|
}
|
|
7755
8450
|
case "text-end": {
|
|
7756
8451
|
const textPart = state.activeTextParts[chunk.id];
|
|
8452
|
+
if (textPart == null) {
|
|
8453
|
+
throw new UIMessageStreamError({
|
|
8454
|
+
chunkType: "text-end",
|
|
8455
|
+
chunkId: chunk.id,
|
|
8456
|
+
message: `Received text-end for missing text part with ID "${chunk.id}". Ensure a "text-start" chunk is sent before any "text-end" chunks.`
|
|
8457
|
+
});
|
|
8458
|
+
}
|
|
7757
8459
|
textPart.state = "done";
|
|
7758
8460
|
textPart.providerMetadata = (_b82 = chunk.providerMetadata) != null ? _b82 : textPart.providerMetadata;
|
|
7759
8461
|
delete state.activeTextParts[chunk.id];
|
|
@@ -7774,6 +8476,13 @@ function processUIMessageStream({
|
|
|
7774
8476
|
}
|
|
7775
8477
|
case "reasoning-delta": {
|
|
7776
8478
|
const reasoningPart = state.activeReasoningParts[chunk.id];
|
|
8479
|
+
if (reasoningPart == null) {
|
|
8480
|
+
throw new UIMessageStreamError({
|
|
8481
|
+
chunkType: "reasoning-delta",
|
|
8482
|
+
chunkId: chunk.id,
|
|
8483
|
+
message: `Received reasoning-delta for missing reasoning part with ID "${chunk.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-delta" chunks.`
|
|
8484
|
+
});
|
|
8485
|
+
}
|
|
7777
8486
|
reasoningPart.text += chunk.delta;
|
|
7778
8487
|
reasoningPart.providerMetadata = (_c = chunk.providerMetadata) != null ? _c : reasoningPart.providerMetadata;
|
|
7779
8488
|
write();
|
|
@@ -7781,6 +8490,13 @@ function processUIMessageStream({
|
|
|
7781
8490
|
}
|
|
7782
8491
|
case "reasoning-end": {
|
|
7783
8492
|
const reasoningPart = state.activeReasoningParts[chunk.id];
|
|
8493
|
+
if (reasoningPart == null) {
|
|
8494
|
+
throw new UIMessageStreamError({
|
|
8495
|
+
chunkType: "reasoning-end",
|
|
8496
|
+
chunkId: chunk.id,
|
|
8497
|
+
message: `Received reasoning-end for missing reasoning part with ID "${chunk.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-end" chunks.`
|
|
8498
|
+
});
|
|
8499
|
+
}
|
|
7784
8500
|
reasoningPart.providerMetadata = (_d = chunk.providerMetadata) != null ? _d : reasoningPart.providerMetadata;
|
|
7785
8501
|
reasoningPart.state = "done";
|
|
7786
8502
|
delete state.activeReasoningParts[chunk.id];
|
|
@@ -7835,7 +8551,8 @@ function processUIMessageStream({
|
|
|
7835
8551
|
state: "input-streaming",
|
|
7836
8552
|
input: void 0,
|
|
7837
8553
|
providerExecuted: chunk.providerExecuted,
|
|
7838
|
-
title: chunk.title
|
|
8554
|
+
title: chunk.title,
|
|
8555
|
+
providerMetadata: chunk.providerMetadata
|
|
7839
8556
|
});
|
|
7840
8557
|
} else {
|
|
7841
8558
|
updateToolPart({
|
|
@@ -7844,7 +8561,8 @@ function processUIMessageStream({
|
|
|
7844
8561
|
state: "input-streaming",
|
|
7845
8562
|
input: void 0,
|
|
7846
8563
|
providerExecuted: chunk.providerExecuted,
|
|
7847
|
-
title: chunk.title
|
|
8564
|
+
title: chunk.title,
|
|
8565
|
+
providerMetadata: chunk.providerMetadata
|
|
7848
8566
|
});
|
|
7849
8567
|
}
|
|
7850
8568
|
write();
|
|
@@ -7852,6 +8570,13 @@ function processUIMessageStream({
|
|
|
7852
8570
|
}
|
|
7853
8571
|
case "tool-input-delta": {
|
|
7854
8572
|
const partialToolCall = state.partialToolCalls[chunk.toolCallId];
|
|
8573
|
+
if (partialToolCall == null) {
|
|
8574
|
+
throw new UIMessageStreamError({
|
|
8575
|
+
chunkType: "tool-input-delta",
|
|
8576
|
+
chunkId: chunk.toolCallId,
|
|
8577
|
+
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.`
|
|
8578
|
+
});
|
|
8579
|
+
}
|
|
7855
8580
|
partialToolCall.text += chunk.inputTextDelta;
|
|
7856
8581
|
const { value: partialArgs } = await parsePartialJson(
|
|
7857
8582
|
partialToolCall.text
|
|
@@ -8043,9 +8768,18 @@ function processUIMessageStream({
|
|
|
8043
8768
|
default: {
|
|
8044
8769
|
if (isDataUIMessageChunk(chunk)) {
|
|
8045
8770
|
if ((dataPartSchemas == null ? void 0 : dataPartSchemas[chunk.type]) != null) {
|
|
8771
|
+
const partIdx = state.message.parts.findIndex(
|
|
8772
|
+
(p) => "id" in p && "data" in p && p.id === chunk.id && p.type === chunk.type
|
|
8773
|
+
);
|
|
8774
|
+
const actualPartIdx = partIdx >= 0 ? partIdx : state.message.parts.length;
|
|
8046
8775
|
await validateTypes({
|
|
8047
8776
|
value: chunk.data,
|
|
8048
|
-
schema: dataPartSchemas[chunk.type]
|
|
8777
|
+
schema: dataPartSchemas[chunk.type],
|
|
8778
|
+
context: {
|
|
8779
|
+
field: `message.parts[${actualPartIdx}].data`,
|
|
8780
|
+
entityName: chunk.type,
|
|
8781
|
+
entityId: chunk.id
|
|
8782
|
+
}
|
|
8049
8783
|
});
|
|
8050
8784
|
}
|
|
8051
8785
|
const dataChunk = chunk;
|
|
@@ -8181,11 +8915,13 @@ function createAsyncIterableStream(source) {
|
|
|
8181
8915
|
const reader = this.getReader();
|
|
8182
8916
|
let finished = false;
|
|
8183
8917
|
async function cleanup(cancelStream) {
|
|
8184
|
-
var
|
|
8918
|
+
var _a21;
|
|
8919
|
+
if (finished)
|
|
8920
|
+
return;
|
|
8185
8921
|
finished = true;
|
|
8186
8922
|
try {
|
|
8187
8923
|
{
|
|
8188
|
-
await ((
|
|
8924
|
+
await ((_a21 = reader.cancel) == null ? void 0 : _a21.call(reader));
|
|
8189
8925
|
}
|
|
8190
8926
|
} finally {
|
|
8191
8927
|
try {
|
|
@@ -8211,7 +8947,7 @@ function createAsyncIterableStream(source) {
|
|
|
8211
8947
|
return { done: false, value };
|
|
8212
8948
|
},
|
|
8213
8949
|
/**
|
|
8214
|
-
*
|
|
8950
|
+
* May be called on early exit (e.g., break from for-await) or after completion.
|
|
8215
8951
|
* Ensures the stream is cancelled and resources are released.
|
|
8216
8952
|
* @returns A promise resolving to a completed IteratorResult.
|
|
8217
8953
|
*/
|
|
@@ -8343,8 +9079,8 @@ function createStitchableStream() {
|
|
|
8343
9079
|
};
|
|
8344
9080
|
}
|
|
8345
9081
|
function now() {
|
|
8346
|
-
var
|
|
8347
|
-
return (_b82 = (
|
|
9082
|
+
var _a21, _b82;
|
|
9083
|
+
return (_b82 = (_a21 = globalThis == null ? void 0 : globalThis.performance) == null ? void 0 : _a21.now()) != null ? _b82 : Date.now();
|
|
8348
9084
|
}
|
|
8349
9085
|
function runToolsTransformation({
|
|
8350
9086
|
tools,
|
|
@@ -8366,6 +9102,7 @@ function runToolsTransformation({
|
|
|
8366
9102
|
});
|
|
8367
9103
|
const outstandingToolResults = /* @__PURE__ */ new Set();
|
|
8368
9104
|
const toolInputs = /* @__PURE__ */ new Map();
|
|
9105
|
+
const toolCallsByToolCallId = /* @__PURE__ */ new Map();
|
|
8369
9106
|
let canClose = false;
|
|
8370
9107
|
let finishChunk = void 0;
|
|
8371
9108
|
function attemptClose() {
|
|
@@ -8417,6 +9154,25 @@ function runToolsTransformation({
|
|
|
8417
9154
|
};
|
|
8418
9155
|
break;
|
|
8419
9156
|
}
|
|
9157
|
+
case "tool-approval-request": {
|
|
9158
|
+
const toolCall = toolCallsByToolCallId.get(chunk.toolCallId);
|
|
9159
|
+
if (toolCall == null) {
|
|
9160
|
+
toolResultsStreamController.enqueue({
|
|
9161
|
+
type: "error",
|
|
9162
|
+
error: new ToolCallNotFoundForApprovalError({
|
|
9163
|
+
toolCallId: chunk.toolCallId,
|
|
9164
|
+
approvalId: chunk.approvalId
|
|
9165
|
+
})
|
|
9166
|
+
});
|
|
9167
|
+
break;
|
|
9168
|
+
}
|
|
9169
|
+
controller.enqueue({
|
|
9170
|
+
type: "tool-approval-request",
|
|
9171
|
+
approvalId: chunk.approvalId,
|
|
9172
|
+
toolCall
|
|
9173
|
+
});
|
|
9174
|
+
break;
|
|
9175
|
+
}
|
|
8420
9176
|
case "tool-call": {
|
|
8421
9177
|
try {
|
|
8422
9178
|
const toolCall = await parseToolCall({
|
|
@@ -8426,6 +9182,7 @@ function runToolsTransformation({
|
|
|
8426
9182
|
system,
|
|
8427
9183
|
messages
|
|
8428
9184
|
});
|
|
9185
|
+
toolCallsByToolCallId.set(toolCall.toolCallId, toolCall);
|
|
8429
9186
|
controller.enqueue(toolCall);
|
|
8430
9187
|
if (toolCall.invalid) {
|
|
8431
9188
|
toolResultsStreamController.enqueue({
|
|
@@ -8482,6 +9239,12 @@ function runToolsTransformation({
|
|
|
8482
9239
|
}
|
|
8483
9240
|
}).then((result) => {
|
|
8484
9241
|
toolResultsStreamController.enqueue(result);
|
|
9242
|
+
}).catch((error) => {
|
|
9243
|
+
toolResultsStreamController.enqueue({
|
|
9244
|
+
type: "error",
|
|
9245
|
+
error
|
|
9246
|
+
});
|
|
9247
|
+
}).finally(() => {
|
|
8485
9248
|
outstandingToolResults.delete(toolExecutionId);
|
|
8486
9249
|
attemptClose();
|
|
8487
9250
|
});
|
|
@@ -8516,9 +9279,6 @@ function runToolsTransformation({
|
|
|
8516
9279
|
}
|
|
8517
9280
|
break;
|
|
8518
9281
|
}
|
|
8519
|
-
case "tool-approval-request": {
|
|
8520
|
-
break;
|
|
8521
|
-
}
|
|
8522
9282
|
default: {
|
|
8523
9283
|
const _exhaustiveCheck = chunkType;
|
|
8524
9284
|
throw new Error(`Unhandled chunk type: ${_exhaustiveCheck}`);
|
|
@@ -8569,6 +9329,7 @@ function streamText({
|
|
|
8569
9329
|
messages,
|
|
8570
9330
|
maxRetries,
|
|
8571
9331
|
abortSignal,
|
|
9332
|
+
timeout,
|
|
8572
9333
|
headers,
|
|
8573
9334
|
stopWhen = stepCountIs(1),
|
|
8574
9335
|
experimental_output,
|
|
@@ -8590,20 +9351,31 @@ function streamText({
|
|
|
8590
9351
|
onAbort,
|
|
8591
9352
|
onStepFinish,
|
|
8592
9353
|
experimental_context,
|
|
8593
|
-
|
|
8594
|
-
|
|
8595
|
-
generateId: generateId2 = originalGenerateId2,
|
|
8596
|
-
currentDate = () => /* @__PURE__ */ new Date()
|
|
8597
|
-
} = {},
|
|
9354
|
+
experimental_include: include,
|
|
9355
|
+
_internal: { now: now2 = now, generateId: generateId2 = originalGenerateId2 } = {},
|
|
8598
9356
|
...settings
|
|
8599
9357
|
}) {
|
|
9358
|
+
const totalTimeoutMs = getTotalTimeoutMs(timeout);
|
|
9359
|
+
const stepTimeoutMs = getStepTimeoutMs(timeout);
|
|
9360
|
+
const chunkTimeoutMs = getChunkTimeoutMs(timeout);
|
|
9361
|
+
const stepAbortController = stepTimeoutMs != null ? new AbortController() : void 0;
|
|
9362
|
+
const chunkAbortController = chunkTimeoutMs != null ? new AbortController() : void 0;
|
|
8600
9363
|
return new DefaultStreamTextResult({
|
|
8601
9364
|
model: resolveLanguageModel(model),
|
|
8602
9365
|
telemetry,
|
|
8603
9366
|
headers,
|
|
8604
9367
|
settings,
|
|
8605
9368
|
maxRetries,
|
|
8606
|
-
abortSignal
|
|
9369
|
+
abortSignal: mergeAbortSignals(
|
|
9370
|
+
abortSignal,
|
|
9371
|
+
totalTimeoutMs != null ? AbortSignal.timeout(totalTimeoutMs) : void 0,
|
|
9372
|
+
stepAbortController == null ? void 0 : stepAbortController.signal,
|
|
9373
|
+
chunkAbortController == null ? void 0 : chunkAbortController.signal
|
|
9374
|
+
),
|
|
9375
|
+
stepTimeoutMs,
|
|
9376
|
+
stepAbortController,
|
|
9377
|
+
chunkTimeoutMs,
|
|
9378
|
+
chunkAbortController,
|
|
8607
9379
|
system,
|
|
8608
9380
|
prompt,
|
|
8609
9381
|
messages,
|
|
@@ -8623,10 +9395,10 @@ function streamText({
|
|
|
8623
9395
|
onAbort,
|
|
8624
9396
|
onStepFinish,
|
|
8625
9397
|
now: now2,
|
|
8626
|
-
currentDate,
|
|
8627
9398
|
generateId: generateId2,
|
|
8628
9399
|
experimental_context,
|
|
8629
|
-
download: download2
|
|
9400
|
+
download: download2,
|
|
9401
|
+
include
|
|
8630
9402
|
});
|
|
8631
9403
|
}
|
|
8632
9404
|
function createOutputTransformStream(output) {
|
|
@@ -8652,7 +9424,7 @@ function createOutputTransformStream(output) {
|
|
|
8652
9424
|
}
|
|
8653
9425
|
return new TransformStream({
|
|
8654
9426
|
async transform(chunk, controller) {
|
|
8655
|
-
var
|
|
9427
|
+
var _a21;
|
|
8656
9428
|
if (chunk.type === "finish-step" && textChunk.length > 0) {
|
|
8657
9429
|
publishTextChunk({ controller });
|
|
8658
9430
|
}
|
|
@@ -8679,7 +9451,7 @@ function createOutputTransformStream(output) {
|
|
|
8679
9451
|
}
|
|
8680
9452
|
text2 += chunk.text;
|
|
8681
9453
|
textChunk += chunk.text;
|
|
8682
|
-
textProviderMetadata = (
|
|
9454
|
+
textProviderMetadata = (_a21 = chunk.providerMetadata) != null ? _a21 : textProviderMetadata;
|
|
8683
9455
|
const result = await output.parsePartialOutput({ text: text2 });
|
|
8684
9456
|
if (result !== void 0) {
|
|
8685
9457
|
const currentJson = JSON.stringify(result.partial);
|
|
@@ -8699,6 +9471,10 @@ var DefaultStreamTextResult = class {
|
|
|
8699
9471
|
settings,
|
|
8700
9472
|
maxRetries: maxRetriesArg,
|
|
8701
9473
|
abortSignal,
|
|
9474
|
+
stepTimeoutMs,
|
|
9475
|
+
stepAbortController,
|
|
9476
|
+
chunkTimeoutMs,
|
|
9477
|
+
chunkAbortController,
|
|
8702
9478
|
system,
|
|
8703
9479
|
prompt,
|
|
8704
9480
|
messages,
|
|
@@ -8713,7 +9489,6 @@ var DefaultStreamTextResult = class {
|
|
|
8713
9489
|
prepareStep,
|
|
8714
9490
|
includeRawChunks,
|
|
8715
9491
|
now: now2,
|
|
8716
|
-
currentDate,
|
|
8717
9492
|
generateId: generateId2,
|
|
8718
9493
|
onChunk,
|
|
8719
9494
|
onError,
|
|
@@ -8721,7 +9496,8 @@ var DefaultStreamTextResult = class {
|
|
|
8721
9496
|
onAbort,
|
|
8722
9497
|
onStepFinish,
|
|
8723
9498
|
experimental_context,
|
|
8724
|
-
download: download2
|
|
9499
|
+
download: download2,
|
|
9500
|
+
include
|
|
8725
9501
|
}) {
|
|
8726
9502
|
this._totalUsage = new DelayedPromise();
|
|
8727
9503
|
this._finishReason = new DelayedPromise();
|
|
@@ -8745,7 +9521,7 @@ var DefaultStreamTextResult = class {
|
|
|
8745
9521
|
let activeReasoningContent = {};
|
|
8746
9522
|
const eventProcessor = new TransformStream({
|
|
8747
9523
|
async transform(chunk, controller) {
|
|
8748
|
-
var
|
|
9524
|
+
var _a21, _b82, _c, _d;
|
|
8749
9525
|
controller.enqueue(chunk);
|
|
8750
9526
|
const { part } = chunk;
|
|
8751
9527
|
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") {
|
|
@@ -8775,7 +9551,7 @@ var DefaultStreamTextResult = class {
|
|
|
8775
9551
|
return;
|
|
8776
9552
|
}
|
|
8777
9553
|
activeText.text += part.text;
|
|
8778
|
-
activeText.providerMetadata = (
|
|
9554
|
+
activeText.providerMetadata = (_a21 = part.providerMetadata) != null ? _a21 : activeText.providerMetadata;
|
|
8779
9555
|
}
|
|
8780
9556
|
if (part.type === "text-end") {
|
|
8781
9557
|
const activeText = activeTextContent[part.id];
|
|
@@ -8892,7 +9668,7 @@ var DefaultStreamTextResult = class {
|
|
|
8892
9668
|
async flush(controller) {
|
|
8893
9669
|
try {
|
|
8894
9670
|
if (recordedSteps.length === 0) {
|
|
8895
|
-
const error = new NoOutputGeneratedError({
|
|
9671
|
+
const error = (abortSignal == null ? void 0 : abortSignal.aborted) ? abortSignal.reason : new NoOutputGeneratedError({
|
|
8896
9672
|
message: "No output generated. Check the stream for errors."
|
|
8897
9673
|
});
|
|
8898
9674
|
self._finishReason.reject(error);
|
|
@@ -8940,8 +9716,8 @@ var DefaultStreamTextResult = class {
|
|
|
8940
9716
|
"ai.response.text": { output: () => finalStep.text },
|
|
8941
9717
|
"ai.response.toolCalls": {
|
|
8942
9718
|
output: () => {
|
|
8943
|
-
var
|
|
8944
|
-
return ((
|
|
9719
|
+
var _a21;
|
|
9720
|
+
return ((_a21 = finalStep.toolCalls) == null ? void 0 : _a21.length) ? JSON.stringify(finalStep.toolCalls) : void 0;
|
|
8945
9721
|
}
|
|
8946
9722
|
},
|
|
8947
9723
|
"ai.response.providerMetadata": JSON.stringify(
|
|
@@ -8973,7 +9749,13 @@ var DefaultStreamTextResult = class {
|
|
|
8973
9749
|
async pull(controller) {
|
|
8974
9750
|
function abort() {
|
|
8975
9751
|
onAbort == null ? void 0 : onAbort({ steps: recordedSteps });
|
|
8976
|
-
controller.enqueue({
|
|
9752
|
+
controller.enqueue({
|
|
9753
|
+
type: "abort",
|
|
9754
|
+
// The `reason` is usually of type DOMException, but it can also be of any type,
|
|
9755
|
+
// so we use getErrorMessage for serialization because it is already designed to accept values of the unknown type.
|
|
9756
|
+
// See: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/reason
|
|
9757
|
+
...(abortSignal == null ? void 0 : abortSignal.reason) !== void 0 ? { reason: getErrorMessage(abortSignal.reason) } : {}
|
|
9758
|
+
});
|
|
8977
9759
|
controller.close();
|
|
8978
9760
|
}
|
|
8979
9761
|
try {
|
|
@@ -9049,6 +9831,19 @@ var DefaultStreamTextResult = class {
|
|
|
9049
9831
|
const initialResponseMessages = [];
|
|
9050
9832
|
const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({ messages: initialMessages });
|
|
9051
9833
|
if (deniedToolApprovals.length > 0 || approvedToolApprovals.length > 0) {
|
|
9834
|
+
const providerExecutedToolApprovals = [
|
|
9835
|
+
...approvedToolApprovals,
|
|
9836
|
+
...deniedToolApprovals
|
|
9837
|
+
].filter((toolApproval) => toolApproval.toolCall.providerExecuted);
|
|
9838
|
+
const localApprovedToolApprovals = approvedToolApprovals.filter(
|
|
9839
|
+
(toolApproval) => !toolApproval.toolCall.providerExecuted
|
|
9840
|
+
);
|
|
9841
|
+
const localDeniedToolApprovals = deniedToolApprovals.filter(
|
|
9842
|
+
(toolApproval) => !toolApproval.toolCall.providerExecuted
|
|
9843
|
+
);
|
|
9844
|
+
const deniedProviderExecutedToolApprovals = deniedToolApprovals.filter(
|
|
9845
|
+
(toolApproval) => toolApproval.toolCall.providerExecuted
|
|
9846
|
+
);
|
|
9052
9847
|
let toolExecutionStepStreamController;
|
|
9053
9848
|
const toolExecutionStepStream = new ReadableStream({
|
|
9054
9849
|
start(controller) {
|
|
@@ -9057,7 +9852,10 @@ var DefaultStreamTextResult = class {
|
|
|
9057
9852
|
});
|
|
9058
9853
|
self.addStream(toolExecutionStepStream);
|
|
9059
9854
|
try {
|
|
9060
|
-
for (const toolApproval of
|
|
9855
|
+
for (const toolApproval of [
|
|
9856
|
+
...localDeniedToolApprovals,
|
|
9857
|
+
...deniedProviderExecutedToolApprovals
|
|
9858
|
+
]) {
|
|
9061
9859
|
toolExecutionStepStreamController == null ? void 0 : toolExecutionStepStreamController.enqueue({
|
|
9062
9860
|
type: "tool-output-denied",
|
|
9063
9861
|
toolCallId: toolApproval.toolCall.toolCallId,
|
|
@@ -9066,7 +9864,7 @@ var DefaultStreamTextResult = class {
|
|
|
9066
9864
|
}
|
|
9067
9865
|
const toolOutputs = [];
|
|
9068
9866
|
await Promise.all(
|
|
9069
|
-
|
|
9867
|
+
localApprovedToolApprovals.map(async (toolApproval) => {
|
|
9070
9868
|
const result = await executeToolCall({
|
|
9071
9869
|
toolCall: toolApproval.toolCall,
|
|
9072
9870
|
tools,
|
|
@@ -9085,36 +9883,52 @@ var DefaultStreamTextResult = class {
|
|
|
9085
9883
|
}
|
|
9086
9884
|
})
|
|
9087
9885
|
);
|
|
9088
|
-
|
|
9089
|
-
|
|
9090
|
-
|
|
9091
|
-
|
|
9092
|
-
|
|
9093
|
-
|
|
9094
|
-
|
|
9095
|
-
|
|
9096
|
-
|
|
9097
|
-
|
|
9098
|
-
|
|
9099
|
-
|
|
9100
|
-
})
|
|
9886
|
+
if (providerExecutedToolApprovals.length > 0) {
|
|
9887
|
+
initialResponseMessages.push({
|
|
9888
|
+
role: "tool",
|
|
9889
|
+
content: providerExecutedToolApprovals.map(
|
|
9890
|
+
(toolApproval) => ({
|
|
9891
|
+
type: "tool-approval-response",
|
|
9892
|
+
approvalId: toolApproval.approvalResponse.approvalId,
|
|
9893
|
+
approved: toolApproval.approvalResponse.approved,
|
|
9894
|
+
reason: toolApproval.approvalResponse.reason,
|
|
9895
|
+
providerExecuted: true
|
|
9896
|
+
})
|
|
9897
|
+
)
|
|
9101
9898
|
});
|
|
9102
9899
|
}
|
|
9103
|
-
|
|
9104
|
-
|
|
9105
|
-
|
|
9106
|
-
|
|
9107
|
-
|
|
9108
|
-
|
|
9109
|
-
|
|
9110
|
-
|
|
9111
|
-
|
|
9900
|
+
if (toolOutputs.length > 0 || localDeniedToolApprovals.length > 0) {
|
|
9901
|
+
const localToolContent = [];
|
|
9902
|
+
for (const output2 of toolOutputs) {
|
|
9903
|
+
localToolContent.push({
|
|
9904
|
+
type: "tool-result",
|
|
9905
|
+
toolCallId: output2.toolCallId,
|
|
9906
|
+
toolName: output2.toolName,
|
|
9907
|
+
output: await createToolModelOutput({
|
|
9908
|
+
toolCallId: output2.toolCallId,
|
|
9909
|
+
input: output2.input,
|
|
9910
|
+
tool: tools == null ? void 0 : tools[output2.toolName],
|
|
9911
|
+
output: output2.type === "tool-result" ? output2.output : output2.error,
|
|
9912
|
+
errorMode: output2.type === "tool-error" ? "json" : "none"
|
|
9913
|
+
})
|
|
9914
|
+
});
|
|
9915
|
+
}
|
|
9916
|
+
for (const toolApproval of localDeniedToolApprovals) {
|
|
9917
|
+
localToolContent.push({
|
|
9918
|
+
type: "tool-result",
|
|
9919
|
+
toolCallId: toolApproval.toolCall.toolCallId,
|
|
9920
|
+
toolName: toolApproval.toolCall.toolName,
|
|
9921
|
+
output: {
|
|
9922
|
+
type: "execution-denied",
|
|
9923
|
+
reason: toolApproval.approvalResponse.reason
|
|
9924
|
+
}
|
|
9925
|
+
});
|
|
9926
|
+
}
|
|
9927
|
+
initialResponseMessages.push({
|
|
9928
|
+
role: "tool",
|
|
9929
|
+
content: localToolContent
|
|
9112
9930
|
});
|
|
9113
9931
|
}
|
|
9114
|
-
initialResponseMessages.push({
|
|
9115
|
-
role: "tool",
|
|
9116
|
-
content
|
|
9117
|
-
});
|
|
9118
9932
|
} finally {
|
|
9119
9933
|
toolExecutionStepStreamController == null ? void 0 : toolExecutionStepStreamController.close();
|
|
9120
9934
|
}
|
|
@@ -9125,407 +9939,446 @@ var DefaultStreamTextResult = class {
|
|
|
9125
9939
|
responseMessages,
|
|
9126
9940
|
usage
|
|
9127
9941
|
}) {
|
|
9128
|
-
var
|
|
9942
|
+
var _a21, _b82, _c, _d, _e, _f, _g;
|
|
9129
9943
|
const includeRawChunks2 = self.includeRawChunks;
|
|
9130
|
-
|
|
9131
|
-
|
|
9132
|
-
|
|
9133
|
-
|
|
9134
|
-
|
|
9135
|
-
|
|
9136
|
-
|
|
9137
|
-
|
|
9138
|
-
|
|
9139
|
-
|
|
9140
|
-
|
|
9141
|
-
|
|
9142
|
-
|
|
9143
|
-
|
|
9144
|
-
|
|
9145
|
-
|
|
9146
|
-
|
|
9147
|
-
|
|
9148
|
-
|
|
9149
|
-
|
|
9150
|
-
|
|
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
|
-
|
|
9944
|
+
const stepTimeoutId = stepTimeoutMs != null ? setTimeout(() => stepAbortController.abort(), stepTimeoutMs) : void 0;
|
|
9945
|
+
let chunkTimeoutId = void 0;
|
|
9946
|
+
function resetChunkTimeout() {
|
|
9947
|
+
if (chunkTimeoutMs != null) {
|
|
9948
|
+
if (chunkTimeoutId != null) {
|
|
9949
|
+
clearTimeout(chunkTimeoutId);
|
|
9950
|
+
}
|
|
9951
|
+
chunkTimeoutId = setTimeout(
|
|
9952
|
+
() => chunkAbortController.abort(),
|
|
9953
|
+
chunkTimeoutMs
|
|
9954
|
+
);
|
|
9955
|
+
}
|
|
9956
|
+
}
|
|
9957
|
+
function clearChunkTimeout() {
|
|
9958
|
+
if (chunkTimeoutId != null) {
|
|
9959
|
+
clearTimeout(chunkTimeoutId);
|
|
9960
|
+
chunkTimeoutId = void 0;
|
|
9961
|
+
}
|
|
9962
|
+
}
|
|
9963
|
+
function clearStepTimeout() {
|
|
9964
|
+
if (stepTimeoutId != null) {
|
|
9965
|
+
clearTimeout(stepTimeoutId);
|
|
9966
|
+
}
|
|
9967
|
+
}
|
|
9968
|
+
try {
|
|
9969
|
+
stepFinish = new DelayedPromise();
|
|
9970
|
+
const stepInputMessages = [...initialMessages, ...responseMessages];
|
|
9971
|
+
const prepareStepResult = await (prepareStep == null ? void 0 : prepareStep({
|
|
9972
|
+
model,
|
|
9973
|
+
steps: recordedSteps,
|
|
9974
|
+
stepNumber: recordedSteps.length,
|
|
9975
|
+
messages: stepInputMessages,
|
|
9976
|
+
experimental_context
|
|
9977
|
+
}));
|
|
9978
|
+
const stepModel = resolveLanguageModel(
|
|
9979
|
+
(_a21 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a21 : model
|
|
9980
|
+
);
|
|
9981
|
+
const promptMessages = await convertToLanguageModelPrompt({
|
|
9982
|
+
prompt: {
|
|
9983
|
+
system: (_b82 = prepareStepResult == null ? void 0 : prepareStepResult.system) != null ? _b82 : initialPrompt.system,
|
|
9984
|
+
messages: (_c = prepareStepResult == null ? void 0 : prepareStepResult.messages) != null ? _c : stepInputMessages
|
|
9985
|
+
},
|
|
9986
|
+
supportedUrls: await stepModel.supportedUrls,
|
|
9987
|
+
download: download2
|
|
9988
|
+
});
|
|
9989
|
+
const { toolChoice: stepToolChoice, tools: stepTools } = await prepareToolsAndToolChoice({
|
|
9990
|
+
tools,
|
|
9991
|
+
toolChoice: (_d = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _d : toolChoice,
|
|
9992
|
+
activeTools: (_e = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _e : activeTools
|
|
9993
|
+
});
|
|
9994
|
+
experimental_context = (_f = prepareStepResult == null ? void 0 : prepareStepResult.experimental_context) != null ? _f : experimental_context;
|
|
9995
|
+
const stepProviderOptions = mergeObjects(
|
|
9996
|
+
providerOptions,
|
|
9997
|
+
prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
|
|
9998
|
+
);
|
|
9999
|
+
const {
|
|
10000
|
+
result: { stream: stream2, response, request },
|
|
10001
|
+
doStreamSpan,
|
|
10002
|
+
startTimestampMs
|
|
10003
|
+
} = await retry(
|
|
10004
|
+
() => recordSpan({
|
|
10005
|
+
name: "ai.streamText.doStream",
|
|
10006
|
+
attributes: selectTelemetryAttributes({
|
|
10007
|
+
telemetry,
|
|
10008
|
+
attributes: {
|
|
10009
|
+
...assembleOperationName({
|
|
10010
|
+
operationId: "ai.streamText.doStream",
|
|
10011
|
+
telemetry
|
|
10012
|
+
}),
|
|
10013
|
+
...baseTelemetryAttributes,
|
|
10014
|
+
// model:
|
|
10015
|
+
"ai.model.provider": stepModel.provider,
|
|
10016
|
+
"ai.model.id": stepModel.modelId,
|
|
10017
|
+
// prompt:
|
|
10018
|
+
"ai.prompt.messages": {
|
|
10019
|
+
input: () => stringifyForTelemetry(promptMessages)
|
|
10020
|
+
},
|
|
10021
|
+
"ai.prompt.tools": {
|
|
10022
|
+
// convert the language model level tools:
|
|
10023
|
+
input: () => stepTools == null ? void 0 : stepTools.map((tool2) => JSON.stringify(tool2))
|
|
10024
|
+
},
|
|
10025
|
+
"ai.prompt.toolChoice": {
|
|
10026
|
+
input: () => stepToolChoice != null ? JSON.stringify(stepToolChoice) : void 0
|
|
10027
|
+
},
|
|
10028
|
+
// standardized gen-ai llm span attributes:
|
|
10029
|
+
"gen_ai.system": stepModel.provider,
|
|
10030
|
+
"gen_ai.request.model": stepModel.modelId,
|
|
10031
|
+
"gen_ai.request.frequency_penalty": callSettings.frequencyPenalty,
|
|
10032
|
+
"gen_ai.request.max_tokens": callSettings.maxOutputTokens,
|
|
10033
|
+
"gen_ai.request.presence_penalty": callSettings.presencePenalty,
|
|
10034
|
+
"gen_ai.request.stop_sequences": callSettings.stopSequences,
|
|
10035
|
+
"gen_ai.request.temperature": callSettings.temperature,
|
|
10036
|
+
"gen_ai.request.top_k": callSettings.topK,
|
|
10037
|
+
"gen_ai.request.top_p": callSettings.topP
|
|
10038
|
+
}
|
|
10039
|
+
}),
|
|
10040
|
+
tracer,
|
|
10041
|
+
endWhenDone: false,
|
|
10042
|
+
fn: async (doStreamSpan2) => ({
|
|
10043
|
+
startTimestampMs: now2(),
|
|
10044
|
+
// get before the call
|
|
10045
|
+
doStreamSpan: doStreamSpan2,
|
|
10046
|
+
result: await stepModel.doStream({
|
|
10047
|
+
...callSettings,
|
|
10048
|
+
tools: stepTools,
|
|
10049
|
+
toolChoice: stepToolChoice,
|
|
10050
|
+
responseFormat: await (output == null ? void 0 : output.responseFormat),
|
|
10051
|
+
prompt: promptMessages,
|
|
10052
|
+
providerOptions: stepProviderOptions,
|
|
10053
|
+
abortSignal,
|
|
10054
|
+
headers,
|
|
10055
|
+
includeRawChunks: includeRawChunks2
|
|
10056
|
+
})
|
|
9217
10057
|
})
|
|
9218
10058
|
})
|
|
9219
|
-
|
|
9220
|
-
|
|
9221
|
-
|
|
9222
|
-
|
|
9223
|
-
|
|
9224
|
-
|
|
9225
|
-
|
|
9226
|
-
|
|
9227
|
-
|
|
9228
|
-
|
|
9229
|
-
|
|
9230
|
-
|
|
9231
|
-
|
|
9232
|
-
|
|
9233
|
-
|
|
9234
|
-
|
|
9235
|
-
|
|
9236
|
-
|
|
9237
|
-
|
|
9238
|
-
|
|
9239
|
-
|
|
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
|
-
const chunkType = chunk.type;
|
|
9274
|
-
switch (chunkType) {
|
|
9275
|
-
case "tool-approval-request":
|
|
9276
|
-
case "text-start":
|
|
9277
|
-
case "text-end": {
|
|
9278
|
-
controller.enqueue(chunk);
|
|
9279
|
-
break;
|
|
10059
|
+
);
|
|
10060
|
+
const streamWithToolResults = runToolsTransformation({
|
|
10061
|
+
tools,
|
|
10062
|
+
generatorStream: stream2,
|
|
10063
|
+
tracer,
|
|
10064
|
+
telemetry,
|
|
10065
|
+
system,
|
|
10066
|
+
messages: stepInputMessages,
|
|
10067
|
+
repairToolCall,
|
|
10068
|
+
abortSignal,
|
|
10069
|
+
experimental_context,
|
|
10070
|
+
generateId: generateId2
|
|
10071
|
+
});
|
|
10072
|
+
const stepRequest = ((_g = include == null ? void 0 : include.requestBody) != null ? _g : true) ? request != null ? request : {} : { ...request, body: void 0 };
|
|
10073
|
+
const stepToolCalls = [];
|
|
10074
|
+
const stepToolOutputs = [];
|
|
10075
|
+
let warnings;
|
|
10076
|
+
const activeToolCallToolNames = {};
|
|
10077
|
+
let stepFinishReason = "other";
|
|
10078
|
+
let stepRawFinishReason = void 0;
|
|
10079
|
+
let stepUsage = createNullLanguageModelUsage();
|
|
10080
|
+
let stepProviderMetadata;
|
|
10081
|
+
let stepFirstChunk = true;
|
|
10082
|
+
let stepResponse = {
|
|
10083
|
+
id: generateId2(),
|
|
10084
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
10085
|
+
modelId: model.modelId
|
|
10086
|
+
};
|
|
10087
|
+
let activeText = "";
|
|
10088
|
+
self.addStream(
|
|
10089
|
+
streamWithToolResults.pipeThrough(
|
|
10090
|
+
new TransformStream({
|
|
10091
|
+
async transform(chunk, controller) {
|
|
10092
|
+
var _a2222, _b222, _c2, _d2, _e2;
|
|
10093
|
+
resetChunkTimeout();
|
|
10094
|
+
if (chunk.type === "stream-start") {
|
|
10095
|
+
warnings = chunk.warnings;
|
|
10096
|
+
return;
|
|
10097
|
+
}
|
|
10098
|
+
if (stepFirstChunk) {
|
|
10099
|
+
const msToFirstChunk = now2() - startTimestampMs;
|
|
10100
|
+
stepFirstChunk = false;
|
|
10101
|
+
doStreamSpan.addEvent("ai.stream.firstChunk", {
|
|
10102
|
+
"ai.response.msToFirstChunk": msToFirstChunk
|
|
10103
|
+
});
|
|
10104
|
+
doStreamSpan.setAttributes({
|
|
10105
|
+
"ai.response.msToFirstChunk": msToFirstChunk
|
|
10106
|
+
});
|
|
10107
|
+
controller.enqueue({
|
|
10108
|
+
type: "start-step",
|
|
10109
|
+
request: stepRequest,
|
|
10110
|
+
warnings: warnings != null ? warnings : []
|
|
10111
|
+
});
|
|
9280
10112
|
}
|
|
9281
|
-
|
|
9282
|
-
|
|
10113
|
+
const chunkType = chunk.type;
|
|
10114
|
+
switch (chunkType) {
|
|
10115
|
+
case "tool-approval-request":
|
|
10116
|
+
case "text-start":
|
|
10117
|
+
case "text-end": {
|
|
10118
|
+
controller.enqueue(chunk);
|
|
10119
|
+
break;
|
|
10120
|
+
}
|
|
10121
|
+
case "text-delta": {
|
|
10122
|
+
if (chunk.delta.length > 0) {
|
|
10123
|
+
controller.enqueue({
|
|
10124
|
+
type: "text-delta",
|
|
10125
|
+
id: chunk.id,
|
|
10126
|
+
text: chunk.delta,
|
|
10127
|
+
providerMetadata: chunk.providerMetadata
|
|
10128
|
+
});
|
|
10129
|
+
activeText += chunk.delta;
|
|
10130
|
+
}
|
|
10131
|
+
break;
|
|
10132
|
+
}
|
|
10133
|
+
case "reasoning-start":
|
|
10134
|
+
case "reasoning-end": {
|
|
10135
|
+
controller.enqueue(chunk);
|
|
10136
|
+
break;
|
|
10137
|
+
}
|
|
10138
|
+
case "reasoning-delta": {
|
|
9283
10139
|
controller.enqueue({
|
|
9284
|
-
type: "
|
|
10140
|
+
type: "reasoning-delta",
|
|
9285
10141
|
id: chunk.id,
|
|
9286
10142
|
text: chunk.delta,
|
|
9287
10143
|
providerMetadata: chunk.providerMetadata
|
|
9288
10144
|
});
|
|
9289
|
-
|
|
10145
|
+
break;
|
|
9290
10146
|
}
|
|
9291
|
-
|
|
9292
|
-
|
|
9293
|
-
|
|
9294
|
-
|
|
9295
|
-
|
|
9296
|
-
|
|
9297
|
-
|
|
9298
|
-
|
|
9299
|
-
|
|
9300
|
-
|
|
9301
|
-
|
|
9302
|
-
|
|
9303
|
-
|
|
9304
|
-
|
|
9305
|
-
break;
|
|
9306
|
-
}
|
|
9307
|
-
case "tool-call": {
|
|
9308
|
-
controller.enqueue(chunk);
|
|
9309
|
-
stepToolCalls.push(chunk);
|
|
9310
|
-
break;
|
|
9311
|
-
}
|
|
9312
|
-
case "tool-result": {
|
|
9313
|
-
controller.enqueue(chunk);
|
|
9314
|
-
if (!chunk.preliminary) {
|
|
10147
|
+
case "tool-call": {
|
|
10148
|
+
controller.enqueue(chunk);
|
|
10149
|
+
stepToolCalls.push(chunk);
|
|
10150
|
+
break;
|
|
10151
|
+
}
|
|
10152
|
+
case "tool-result": {
|
|
10153
|
+
controller.enqueue(chunk);
|
|
10154
|
+
if (!chunk.preliminary) {
|
|
10155
|
+
stepToolOutputs.push(chunk);
|
|
10156
|
+
}
|
|
10157
|
+
break;
|
|
10158
|
+
}
|
|
10159
|
+
case "tool-error": {
|
|
10160
|
+
controller.enqueue(chunk);
|
|
9315
10161
|
stepToolOutputs.push(chunk);
|
|
10162
|
+
break;
|
|
9316
10163
|
}
|
|
9317
|
-
|
|
9318
|
-
|
|
9319
|
-
|
|
9320
|
-
|
|
9321
|
-
|
|
9322
|
-
|
|
9323
|
-
|
|
9324
|
-
|
|
9325
|
-
|
|
9326
|
-
|
|
9327
|
-
|
|
9328
|
-
|
|
9329
|
-
|
|
9330
|
-
|
|
9331
|
-
|
|
9332
|
-
|
|
9333
|
-
|
|
9334
|
-
|
|
9335
|
-
stepRawFinishReason = chunk.rawFinishReason;
|
|
9336
|
-
stepProviderMetadata = chunk.providerMetadata;
|
|
9337
|
-
const msToFinish = now2() - startTimestampMs;
|
|
9338
|
-
doStreamSpan.addEvent("ai.stream.finish");
|
|
9339
|
-
doStreamSpan.setAttributes({
|
|
9340
|
-
"ai.response.msToFinish": msToFinish,
|
|
9341
|
-
"ai.response.avgOutputTokensPerSecond": 1e3 * ((_d2 = stepUsage.outputTokens) != null ? _d2 : 0) / msToFinish
|
|
9342
|
-
});
|
|
9343
|
-
break;
|
|
9344
|
-
}
|
|
9345
|
-
case "file": {
|
|
9346
|
-
controller.enqueue(chunk);
|
|
9347
|
-
break;
|
|
9348
|
-
}
|
|
9349
|
-
case "source": {
|
|
9350
|
-
controller.enqueue(chunk);
|
|
9351
|
-
break;
|
|
9352
|
-
}
|
|
9353
|
-
case "tool-input-start": {
|
|
9354
|
-
activeToolCallToolNames[chunk.id] = chunk.toolName;
|
|
9355
|
-
const tool2 = tools == null ? void 0 : tools[chunk.toolName];
|
|
9356
|
-
if ((tool2 == null ? void 0 : tool2.onInputStart) != null) {
|
|
9357
|
-
await tool2.onInputStart({
|
|
9358
|
-
toolCallId: chunk.id,
|
|
9359
|
-
messages: stepInputMessages,
|
|
9360
|
-
abortSignal,
|
|
9361
|
-
experimental_context
|
|
10164
|
+
case "response-metadata": {
|
|
10165
|
+
stepResponse = {
|
|
10166
|
+
id: (_a2222 = chunk.id) != null ? _a2222 : stepResponse.id,
|
|
10167
|
+
timestamp: (_b222 = chunk.timestamp) != null ? _b222 : stepResponse.timestamp,
|
|
10168
|
+
modelId: (_c2 = chunk.modelId) != null ? _c2 : stepResponse.modelId
|
|
10169
|
+
};
|
|
10170
|
+
break;
|
|
10171
|
+
}
|
|
10172
|
+
case "finish": {
|
|
10173
|
+
stepUsage = chunk.usage;
|
|
10174
|
+
stepFinishReason = chunk.finishReason;
|
|
10175
|
+
stepRawFinishReason = chunk.rawFinishReason;
|
|
10176
|
+
stepProviderMetadata = chunk.providerMetadata;
|
|
10177
|
+
const msToFinish = now2() - startTimestampMs;
|
|
10178
|
+
doStreamSpan.addEvent("ai.stream.finish");
|
|
10179
|
+
doStreamSpan.setAttributes({
|
|
10180
|
+
"ai.response.msToFinish": msToFinish,
|
|
10181
|
+
"ai.response.avgOutputTokensPerSecond": 1e3 * ((_d2 = stepUsage.outputTokens) != null ? _d2 : 0) / msToFinish
|
|
9362
10182
|
});
|
|
10183
|
+
break;
|
|
9363
10184
|
}
|
|
9364
|
-
|
|
9365
|
-
|
|
9366
|
-
|
|
9367
|
-
|
|
9368
|
-
|
|
9369
|
-
|
|
9370
|
-
|
|
9371
|
-
|
|
9372
|
-
|
|
9373
|
-
|
|
9374
|
-
|
|
9375
|
-
|
|
9376
|
-
|
|
9377
|
-
|
|
9378
|
-
|
|
9379
|
-
|
|
9380
|
-
|
|
9381
|
-
|
|
9382
|
-
|
|
9383
|
-
|
|
9384
|
-
|
|
9385
|
-
|
|
10185
|
+
case "file": {
|
|
10186
|
+
controller.enqueue(chunk);
|
|
10187
|
+
break;
|
|
10188
|
+
}
|
|
10189
|
+
case "source": {
|
|
10190
|
+
controller.enqueue(chunk);
|
|
10191
|
+
break;
|
|
10192
|
+
}
|
|
10193
|
+
case "tool-input-start": {
|
|
10194
|
+
activeToolCallToolNames[chunk.id] = chunk.toolName;
|
|
10195
|
+
const tool2 = tools == null ? void 0 : tools[chunk.toolName];
|
|
10196
|
+
if ((tool2 == null ? void 0 : tool2.onInputStart) != null) {
|
|
10197
|
+
await tool2.onInputStart({
|
|
10198
|
+
toolCallId: chunk.id,
|
|
10199
|
+
messages: stepInputMessages,
|
|
10200
|
+
abortSignal,
|
|
10201
|
+
experimental_context
|
|
10202
|
+
});
|
|
10203
|
+
}
|
|
10204
|
+
controller.enqueue({
|
|
10205
|
+
...chunk,
|
|
10206
|
+
dynamic: (_e2 = chunk.dynamic) != null ? _e2 : (tool2 == null ? void 0 : tool2.type) === "dynamic",
|
|
10207
|
+
title: tool2 == null ? void 0 : tool2.title
|
|
9386
10208
|
});
|
|
10209
|
+
break;
|
|
9387
10210
|
}
|
|
9388
|
-
|
|
9389
|
-
|
|
9390
|
-
}
|
|
9391
|
-
case "error": {
|
|
9392
|
-
controller.enqueue(chunk);
|
|
9393
|
-
stepFinishReason = "error";
|
|
9394
|
-
break;
|
|
9395
|
-
}
|
|
9396
|
-
case "raw": {
|
|
9397
|
-
if (includeRawChunks2) {
|
|
10211
|
+
case "tool-input-end": {
|
|
10212
|
+
delete activeToolCallToolNames[chunk.id];
|
|
9398
10213
|
controller.enqueue(chunk);
|
|
10214
|
+
break;
|
|
9399
10215
|
}
|
|
9400
|
-
|
|
9401
|
-
|
|
9402
|
-
|
|
9403
|
-
|
|
9404
|
-
|
|
9405
|
-
|
|
9406
|
-
|
|
9407
|
-
|
|
9408
|
-
|
|
9409
|
-
|
|
9410
|
-
|
|
9411
|
-
try {
|
|
9412
|
-
doStreamSpan.setAttributes(
|
|
9413
|
-
await selectTelemetryAttributes({
|
|
9414
|
-
telemetry,
|
|
9415
|
-
attributes: {
|
|
9416
|
-
"ai.response.finishReason": stepFinishReason,
|
|
9417
|
-
"ai.response.text": {
|
|
9418
|
-
output: () => activeText
|
|
9419
|
-
},
|
|
9420
|
-
"ai.response.toolCalls": {
|
|
9421
|
-
output: () => stepToolCallsJson
|
|
9422
|
-
},
|
|
9423
|
-
"ai.response.id": stepResponse.id,
|
|
9424
|
-
"ai.response.model": stepResponse.modelId,
|
|
9425
|
-
"ai.response.timestamp": stepResponse.timestamp.toISOString(),
|
|
9426
|
-
"ai.response.providerMetadata": JSON.stringify(stepProviderMetadata),
|
|
9427
|
-
"ai.usage.inputTokens": stepUsage.inputTokens,
|
|
9428
|
-
"ai.usage.outputTokens": stepUsage.outputTokens,
|
|
9429
|
-
"ai.usage.totalTokens": stepUsage.totalTokens,
|
|
9430
|
-
"ai.usage.reasoningTokens": stepUsage.reasoningTokens,
|
|
9431
|
-
"ai.usage.cachedInputTokens": stepUsage.cachedInputTokens,
|
|
9432
|
-
// standardized gen-ai llm span attributes:
|
|
9433
|
-
"gen_ai.response.finish_reasons": [stepFinishReason],
|
|
9434
|
-
"gen_ai.response.id": stepResponse.id,
|
|
9435
|
-
"gen_ai.response.model": stepResponse.modelId,
|
|
9436
|
-
"gen_ai.usage.input_tokens": stepUsage.inputTokens,
|
|
9437
|
-
"gen_ai.usage.output_tokens": stepUsage.outputTokens
|
|
10216
|
+
case "tool-input-delta": {
|
|
10217
|
+
const toolName = activeToolCallToolNames[chunk.id];
|
|
10218
|
+
const tool2 = tools == null ? void 0 : tools[toolName];
|
|
10219
|
+
if ((tool2 == null ? void 0 : tool2.onInputDelta) != null) {
|
|
10220
|
+
await tool2.onInputDelta({
|
|
10221
|
+
inputTextDelta: chunk.delta,
|
|
10222
|
+
toolCallId: chunk.id,
|
|
10223
|
+
messages: stepInputMessages,
|
|
10224
|
+
abortSignal,
|
|
10225
|
+
experimental_context
|
|
10226
|
+
});
|
|
9438
10227
|
}
|
|
9439
|
-
|
|
9440
|
-
|
|
9441
|
-
|
|
9442
|
-
|
|
9443
|
-
|
|
9444
|
-
|
|
9445
|
-
|
|
9446
|
-
|
|
9447
|
-
|
|
9448
|
-
|
|
9449
|
-
|
|
9450
|
-
|
|
9451
|
-
|
|
9452
|
-
|
|
9453
|
-
|
|
10228
|
+
controller.enqueue(chunk);
|
|
10229
|
+
break;
|
|
10230
|
+
}
|
|
10231
|
+
case "error": {
|
|
10232
|
+
controller.enqueue(chunk);
|
|
10233
|
+
stepFinishReason = "error";
|
|
10234
|
+
break;
|
|
10235
|
+
}
|
|
10236
|
+
case "raw": {
|
|
10237
|
+
if (includeRawChunks2) {
|
|
10238
|
+
controller.enqueue(chunk);
|
|
10239
|
+
}
|
|
10240
|
+
break;
|
|
10241
|
+
}
|
|
10242
|
+
default: {
|
|
10243
|
+
const exhaustiveCheck = chunkType;
|
|
10244
|
+
throw new Error(
|
|
10245
|
+
`Unknown chunk type: ${exhaustiveCheck}`
|
|
10246
|
+
);
|
|
10247
|
+
}
|
|
9454
10248
|
}
|
|
9455
|
-
}
|
|
9456
|
-
|
|
9457
|
-
|
|
9458
|
-
|
|
9459
|
-
|
|
9460
|
-
|
|
9461
|
-
|
|
9462
|
-
|
|
9463
|
-
|
|
9464
|
-
|
|
9465
|
-
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
10249
|
+
},
|
|
10250
|
+
// invoke onFinish callback and resolve toolResults promise when the stream is about to close:
|
|
10251
|
+
async flush(controller) {
|
|
10252
|
+
const stepToolCallsJson = stepToolCalls.length > 0 ? JSON.stringify(stepToolCalls) : void 0;
|
|
10253
|
+
try {
|
|
10254
|
+
doStreamSpan.setAttributes(
|
|
10255
|
+
await selectTelemetryAttributes({
|
|
10256
|
+
telemetry,
|
|
10257
|
+
attributes: {
|
|
10258
|
+
"ai.response.finishReason": stepFinishReason,
|
|
10259
|
+
"ai.response.text": {
|
|
10260
|
+
output: () => activeText
|
|
10261
|
+
},
|
|
10262
|
+
"ai.response.toolCalls": {
|
|
10263
|
+
output: () => stepToolCallsJson
|
|
10264
|
+
},
|
|
10265
|
+
"ai.response.id": stepResponse.id,
|
|
10266
|
+
"ai.response.model": stepResponse.modelId,
|
|
10267
|
+
"ai.response.timestamp": stepResponse.timestamp.toISOString(),
|
|
10268
|
+
"ai.response.providerMetadata": JSON.stringify(stepProviderMetadata),
|
|
10269
|
+
"ai.usage.inputTokens": stepUsage.inputTokens,
|
|
10270
|
+
"ai.usage.outputTokens": stepUsage.outputTokens,
|
|
10271
|
+
"ai.usage.totalTokens": stepUsage.totalTokens,
|
|
10272
|
+
"ai.usage.reasoningTokens": stepUsage.reasoningTokens,
|
|
10273
|
+
"ai.usage.cachedInputTokens": stepUsage.cachedInputTokens,
|
|
10274
|
+
// standardized gen-ai llm span attributes:
|
|
10275
|
+
"gen_ai.response.finish_reasons": [
|
|
10276
|
+
stepFinishReason
|
|
10277
|
+
],
|
|
10278
|
+
"gen_ai.response.id": stepResponse.id,
|
|
10279
|
+
"gen_ai.response.model": stepResponse.modelId,
|
|
10280
|
+
"gen_ai.usage.input_tokens": stepUsage.inputTokens,
|
|
10281
|
+
"gen_ai.usage.output_tokens": stepUsage.outputTokens
|
|
10282
|
+
}
|
|
10283
|
+
})
|
|
9471
10284
|
);
|
|
9472
|
-
|
|
9473
|
-
|
|
9474
|
-
|
|
9475
|
-
|
|
10285
|
+
} catch (error) {
|
|
10286
|
+
} finally {
|
|
10287
|
+
doStreamSpan.end();
|
|
10288
|
+
}
|
|
10289
|
+
controller.enqueue({
|
|
10290
|
+
type: "finish-step",
|
|
10291
|
+
finishReason: stepFinishReason,
|
|
10292
|
+
rawFinishReason: stepRawFinishReason,
|
|
10293
|
+
usage: stepUsage,
|
|
10294
|
+
providerMetadata: stepProviderMetadata,
|
|
10295
|
+
response: {
|
|
10296
|
+
...stepResponse,
|
|
10297
|
+
headers: response == null ? void 0 : response.headers
|
|
10298
|
+
}
|
|
10299
|
+
});
|
|
10300
|
+
const combinedUsage = addLanguageModelUsage(
|
|
10301
|
+
usage,
|
|
10302
|
+
stepUsage
|
|
10303
|
+
);
|
|
10304
|
+
await stepFinish.promise;
|
|
10305
|
+
const clientToolCalls = stepToolCalls.filter(
|
|
10306
|
+
(toolCall) => toolCall.providerExecuted !== true
|
|
10307
|
+
);
|
|
10308
|
+
const clientToolOutputs = stepToolOutputs.filter(
|
|
10309
|
+
(toolOutput) => toolOutput.providerExecuted !== true
|
|
10310
|
+
);
|
|
10311
|
+
for (const toolCall of stepToolCalls) {
|
|
10312
|
+
if (toolCall.providerExecuted !== true)
|
|
10313
|
+
continue;
|
|
10314
|
+
const tool2 = tools == null ? void 0 : tools[toolCall.toolName];
|
|
10315
|
+
if ((tool2 == null ? void 0 : tool2.type) === "provider" && tool2.supportsDeferredResults) {
|
|
10316
|
+
const hasResultInStep = stepToolOutputs.some(
|
|
10317
|
+
(output2) => (output2.type === "tool-result" || output2.type === "tool-error") && output2.toolCallId === toolCall.toolCallId
|
|
10318
|
+
);
|
|
10319
|
+
if (!hasResultInStep) {
|
|
10320
|
+
pendingDeferredToolCalls.set(toolCall.toolCallId, {
|
|
10321
|
+
toolName: toolCall.toolName
|
|
10322
|
+
});
|
|
10323
|
+
}
|
|
9476
10324
|
}
|
|
9477
10325
|
}
|
|
9478
|
-
|
|
9479
|
-
|
|
9480
|
-
|
|
9481
|
-
|
|
10326
|
+
for (const output2 of stepToolOutputs) {
|
|
10327
|
+
if (output2.type === "tool-result" || output2.type === "tool-error") {
|
|
10328
|
+
pendingDeferredToolCalls.delete(output2.toolCallId);
|
|
10329
|
+
}
|
|
9482
10330
|
}
|
|
9483
|
-
|
|
9484
|
-
|
|
9485
|
-
|
|
9486
|
-
|
|
9487
|
-
|
|
9488
|
-
|
|
9489
|
-
|
|
9490
|
-
|
|
9491
|
-
|
|
9492
|
-
|
|
9493
|
-
) {
|
|
9494
|
-
responseMessages.push(
|
|
9495
|
-
...await toResponseMessages({
|
|
9496
|
-
content: (
|
|
9497
|
-
// use transformed content to create the messages for the next step:
|
|
9498
|
-
recordedSteps[recordedSteps.length - 1].content
|
|
9499
|
-
),
|
|
9500
|
-
tools
|
|
10331
|
+
clearStepTimeout();
|
|
10332
|
+
clearChunkTimeout();
|
|
10333
|
+
if (
|
|
10334
|
+
// Continue if:
|
|
10335
|
+
// 1. There are client tool calls that have all been executed, OR
|
|
10336
|
+
// 2. There are pending deferred results from provider-executed tools
|
|
10337
|
+
(clientToolCalls.length > 0 && clientToolOutputs.length === clientToolCalls.length || pendingDeferredToolCalls.size > 0) && // continue until a stop condition is met:
|
|
10338
|
+
!await isStopConditionMet({
|
|
10339
|
+
stopConditions,
|
|
10340
|
+
steps: recordedSteps
|
|
9501
10341
|
})
|
|
9502
|
-
)
|
|
9503
|
-
|
|
9504
|
-
|
|
9505
|
-
|
|
9506
|
-
|
|
9507
|
-
|
|
9508
|
-
|
|
9509
|
-
|
|
10342
|
+
) {
|
|
10343
|
+
responseMessages.push(
|
|
10344
|
+
...await toResponseMessages({
|
|
10345
|
+
content: (
|
|
10346
|
+
// use transformed content to create the messages for the next step:
|
|
10347
|
+
recordedSteps[recordedSteps.length - 1].content
|
|
10348
|
+
),
|
|
10349
|
+
tools
|
|
10350
|
+
})
|
|
10351
|
+
);
|
|
10352
|
+
try {
|
|
10353
|
+
await streamStep({
|
|
10354
|
+
currentStep: currentStep + 1,
|
|
10355
|
+
responseMessages,
|
|
10356
|
+
usage: combinedUsage
|
|
10357
|
+
});
|
|
10358
|
+
} catch (error) {
|
|
10359
|
+
controller.enqueue({
|
|
10360
|
+
type: "error",
|
|
10361
|
+
error
|
|
10362
|
+
});
|
|
10363
|
+
self.closeStream();
|
|
10364
|
+
}
|
|
10365
|
+
} else {
|
|
9510
10366
|
controller.enqueue({
|
|
9511
|
-
type: "
|
|
9512
|
-
|
|
10367
|
+
type: "finish",
|
|
10368
|
+
finishReason: stepFinishReason,
|
|
10369
|
+
rawFinishReason: stepRawFinishReason,
|
|
10370
|
+
totalUsage: combinedUsage
|
|
9513
10371
|
});
|
|
9514
10372
|
self.closeStream();
|
|
9515
10373
|
}
|
|
9516
|
-
} else {
|
|
9517
|
-
controller.enqueue({
|
|
9518
|
-
type: "finish",
|
|
9519
|
-
finishReason: stepFinishReason,
|
|
9520
|
-
rawFinishReason: stepRawFinishReason,
|
|
9521
|
-
totalUsage: combinedUsage
|
|
9522
|
-
});
|
|
9523
|
-
self.closeStream();
|
|
9524
10374
|
}
|
|
9525
|
-
}
|
|
9526
|
-
|
|
9527
|
-
)
|
|
9528
|
-
|
|
10375
|
+
})
|
|
10376
|
+
)
|
|
10377
|
+
);
|
|
10378
|
+
} finally {
|
|
10379
|
+
clearStepTimeout();
|
|
10380
|
+
clearChunkTimeout();
|
|
10381
|
+
}
|
|
9529
10382
|
}
|
|
9530
10383
|
await streamStep({
|
|
9531
10384
|
currentStep: 0,
|
|
@@ -9616,13 +10469,13 @@ var DefaultStreamTextResult = class {
|
|
|
9616
10469
|
return this._rawFinishReason.promise;
|
|
9617
10470
|
}
|
|
9618
10471
|
/**
|
|
9619
|
-
|
|
9620
|
-
|
|
9621
|
-
|
|
9622
|
-
|
|
9623
|
-
|
|
9624
|
-
|
|
9625
|
-
|
|
10472
|
+
* Split out a new stream from the original stream.
|
|
10473
|
+
* The original stream is replaced to allow for further splitting,
|
|
10474
|
+
* since we do not know how many times the stream will be split.
|
|
10475
|
+
*
|
|
10476
|
+
* Note: this leads to buffering the stream content on the server.
|
|
10477
|
+
* However, the LLM results are expected to be small enough to not cause issues.
|
|
10478
|
+
*/
|
|
9626
10479
|
teeStream() {
|
|
9627
10480
|
const [stream1, stream2] = this.baseStream.tee();
|
|
9628
10481
|
this.baseStream = stream2;
|
|
@@ -9653,14 +10506,14 @@ var DefaultStreamTextResult = class {
|
|
|
9653
10506
|
);
|
|
9654
10507
|
}
|
|
9655
10508
|
async consumeStream(options) {
|
|
9656
|
-
var
|
|
10509
|
+
var _a21;
|
|
9657
10510
|
try {
|
|
9658
10511
|
await consumeStream({
|
|
9659
10512
|
stream: this.fullStream,
|
|
9660
10513
|
onError: options == null ? void 0 : options.onError
|
|
9661
10514
|
});
|
|
9662
10515
|
} catch (error) {
|
|
9663
|
-
(
|
|
10516
|
+
(_a21 = options == null ? void 0 : options.onError) == null ? void 0 : _a21.call(options, error);
|
|
9664
10517
|
}
|
|
9665
10518
|
}
|
|
9666
10519
|
get experimental_partialOutputStream() {
|
|
@@ -9679,10 +10532,20 @@ var DefaultStreamTextResult = class {
|
|
|
9679
10532
|
)
|
|
9680
10533
|
);
|
|
9681
10534
|
}
|
|
10535
|
+
get elementStream() {
|
|
10536
|
+
var _a21, _b82, _c;
|
|
10537
|
+
const transform = (_a21 = this.outputSpecification) == null ? void 0 : _a21.createElementStreamTransform();
|
|
10538
|
+
if (transform == null) {
|
|
10539
|
+
throw new UnsupportedFunctionalityError({
|
|
10540
|
+
functionality: `element streams in ${(_c = (_b82 = this.outputSpecification) == null ? void 0 : _b82.name) != null ? _c : "text"} mode`
|
|
10541
|
+
});
|
|
10542
|
+
}
|
|
10543
|
+
return createAsyncIterableStream(this.teeStream().pipeThrough(transform));
|
|
10544
|
+
}
|
|
9682
10545
|
get output() {
|
|
9683
10546
|
return this.finalStep.then((step) => {
|
|
9684
|
-
var
|
|
9685
|
-
const output = (
|
|
10547
|
+
var _a21;
|
|
10548
|
+
const output = (_a21 = this.outputSpecification) != null ? _a21 : text();
|
|
9686
10549
|
return output.parseCompleteOutput(
|
|
9687
10550
|
{ text: step.text },
|
|
9688
10551
|
{
|
|
@@ -9709,8 +10572,8 @@ var DefaultStreamTextResult = class {
|
|
|
9709
10572
|
responseMessageId: generateMessageId
|
|
9710
10573
|
}) : void 0;
|
|
9711
10574
|
const isDynamic = (part) => {
|
|
9712
|
-
var
|
|
9713
|
-
const tool2 = (
|
|
10575
|
+
var _a21;
|
|
10576
|
+
const tool2 = (_a21 = this.tools) == null ? void 0 : _a21[part.toolName];
|
|
9714
10577
|
if (tool2 == null) {
|
|
9715
10578
|
return part.dynamic;
|
|
9716
10579
|
}
|
|
@@ -9811,6 +10674,7 @@ var DefaultStreamTextResult = class {
|
|
|
9811
10674
|
toolCallId: part.id,
|
|
9812
10675
|
toolName: part.toolName,
|
|
9813
10676
|
...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
|
|
10677
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
|
|
9814
10678
|
...dynamic != null ? { dynamic } : {},
|
|
9815
10679
|
...part.title != null ? { title: part.title } : {}
|
|
9816
10680
|
});
|
|
@@ -10046,13 +10910,17 @@ var ToolLoopAgent = class {
|
|
|
10046
10910
|
return this.settings.tools;
|
|
10047
10911
|
}
|
|
10048
10912
|
async prepareCall(options) {
|
|
10049
|
-
var
|
|
10913
|
+
var _a21, _b82, _c, _d;
|
|
10914
|
+
const { onStepFinish: _settingsOnStepFinish, ...settingsWithoutCallback } = this.settings;
|
|
10050
10915
|
const baseCallArgs = {
|
|
10051
|
-
...
|
|
10052
|
-
stopWhen: (
|
|
10916
|
+
...settingsWithoutCallback,
|
|
10917
|
+
stopWhen: (_a21 = this.settings.stopWhen) != null ? _a21 : stepCountIs(20),
|
|
10053
10918
|
...options
|
|
10054
10919
|
};
|
|
10055
|
-
const preparedCallArgs = (_d = await ((_c = (_b82 = this.settings).prepareCall) == null ? void 0 : _c.call(
|
|
10920
|
+
const preparedCallArgs = (_d = await ((_c = (_b82 = this.settings).prepareCall) == null ? void 0 : _c.call(
|
|
10921
|
+
_b82,
|
|
10922
|
+
baseCallArgs
|
|
10923
|
+
))) != null ? _d : baseCallArgs;
|
|
10056
10924
|
const { instructions, messages, prompt, ...callArgs } = preparedCallArgs;
|
|
10057
10925
|
return {
|
|
10058
10926
|
...callArgs,
|
|
@@ -10060,16 +10928,30 @@ var ToolLoopAgent = class {
|
|
|
10060
10928
|
...{ system: instructions, messages, prompt }
|
|
10061
10929
|
};
|
|
10062
10930
|
}
|
|
10931
|
+
mergeOnStepFinishCallbacks(methodCallback) {
|
|
10932
|
+
const constructorCallback = this.settings.onStepFinish;
|
|
10933
|
+
if (methodCallback && constructorCallback) {
|
|
10934
|
+
return async (stepResult) => {
|
|
10935
|
+
await constructorCallback(stepResult);
|
|
10936
|
+
await methodCallback(stepResult);
|
|
10937
|
+
};
|
|
10938
|
+
}
|
|
10939
|
+
return methodCallback != null ? methodCallback : constructorCallback;
|
|
10940
|
+
}
|
|
10063
10941
|
/**
|
|
10064
10942
|
* Generates an output from the agent (non-streaming).
|
|
10065
10943
|
*/
|
|
10066
10944
|
async generate({
|
|
10067
10945
|
abortSignal,
|
|
10946
|
+
timeout,
|
|
10947
|
+
onStepFinish,
|
|
10068
10948
|
...options
|
|
10069
10949
|
}) {
|
|
10070
10950
|
return generateText({
|
|
10071
10951
|
...await this.prepareCall(options),
|
|
10072
|
-
abortSignal
|
|
10952
|
+
abortSignal,
|
|
10953
|
+
timeout,
|
|
10954
|
+
onStepFinish: this.mergeOnStepFinishCallbacks(onStepFinish)
|
|
10073
10955
|
});
|
|
10074
10956
|
}
|
|
10075
10957
|
/**
|
|
@@ -10077,13 +10959,17 @@ var ToolLoopAgent = class {
|
|
|
10077
10959
|
*/
|
|
10078
10960
|
async stream({
|
|
10079
10961
|
abortSignal,
|
|
10962
|
+
timeout,
|
|
10080
10963
|
experimental_transform,
|
|
10964
|
+
onStepFinish,
|
|
10081
10965
|
...options
|
|
10082
10966
|
}) {
|
|
10083
10967
|
return streamText({
|
|
10084
10968
|
...await this.prepareCall(options),
|
|
10085
10969
|
abortSignal,
|
|
10086
|
-
|
|
10970
|
+
timeout,
|
|
10971
|
+
experimental_transform,
|
|
10972
|
+
onStepFinish: this.mergeOnStepFinishCallbacks(onStepFinish)
|
|
10087
10973
|
});
|
|
10088
10974
|
}
|
|
10089
10975
|
};
|
|
@@ -10143,7 +11029,7 @@ async function embed({
|
|
|
10143
11029
|
}),
|
|
10144
11030
|
tracer,
|
|
10145
11031
|
fn: async (doEmbedSpan) => {
|
|
10146
|
-
var
|
|
11032
|
+
var _a21;
|
|
10147
11033
|
const modelResponse = await model.doEmbed({
|
|
10148
11034
|
values: [value],
|
|
10149
11035
|
abortSignal,
|
|
@@ -10151,7 +11037,7 @@ async function embed({
|
|
|
10151
11037
|
providerOptions
|
|
10152
11038
|
});
|
|
10153
11039
|
const embedding2 = modelResponse.embeddings[0];
|
|
10154
|
-
const usage2 = (
|
|
11040
|
+
const usage2 = (_a21 = modelResponse.usage) != null ? _a21 : { tokens: NaN };
|
|
10155
11041
|
doEmbedSpan.setAttributes(
|
|
10156
11042
|
await selectTelemetryAttributes({
|
|
10157
11043
|
telemetry,
|
|
@@ -10211,5 +11097,5 @@ createIdGenerator({ prefix: "aiobj", size: 24 });
|
|
|
10211
11097
|
createIdGenerator({ prefix: "aiobj", size: 24 });
|
|
10212
11098
|
|
|
10213
11099
|
export { ToolLoopAgent, embed };
|
|
10214
|
-
//# sourceMappingURL=chunk-
|
|
10215
|
-
//# sourceMappingURL=chunk-
|
|
11100
|
+
//# sourceMappingURL=chunk-V2MLGA7T.js.map
|
|
11101
|
+
//# sourceMappingURL=chunk-V2MLGA7T.js.map
|