@od-oneapp/ai-platform 0.1.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/README.md +235 -0
- package/dist/agents-base.d.mts +12 -0
- package/dist/agents-base.d.mts.map +1 -0
- package/dist/agents-base.mjs +20 -0
- package/dist/agents-base.mjs.map +1 -0
- package/dist/agents-control-flow.d.mts +115 -0
- package/dist/agents-control-flow.d.mts.map +1 -0
- package/dist/agents-control-flow.mjs +514 -0
- package/dist/agents-control-flow.mjs.map +1 -0
- package/dist/agents-coordinator.d.mts +11 -0
- package/dist/agents-coordinator.d.mts.map +1 -0
- package/dist/agents-coordinator.mjs +12 -0
- package/dist/agents-coordinator.mjs.map +1 -0
- package/dist/agents-experimental.d.mts +153 -0
- package/dist/agents-experimental.d.mts.map +1 -0
- package/dist/agents-experimental.mjs +580 -0
- package/dist/agents-experimental.mjs.map +1 -0
- package/dist/agents-fallback.d.mts +10 -0
- package/dist/agents-fallback.d.mts.map +1 -0
- package/dist/agents-fallback.mjs +15 -0
- package/dist/agents-fallback.mjs.map +1 -0
- package/dist/agents-multi-swarm.d.mts +9 -0
- package/dist/agents-multi-swarm.d.mts.map +1 -0
- package/dist/agents-multi-swarm.mjs +44 -0
- package/dist/agents-multi-swarm.mjs.map +1 -0
- package/dist/agents-multi.d.mts +10 -0
- package/dist/agents-multi.d.mts.map +1 -0
- package/dist/agents-multi.mjs +44 -0
- package/dist/agents-multi.mjs.map +1 -0
- package/dist/agents-observability.d.mts +161 -0
- package/dist/agents-observability.d.mts.map +1 -0
- package/dist/agents-observability.mjs +550 -0
- package/dist/agents-observability.mjs.map +1 -0
- package/dist/agents-patterns.d.mts +9 -0
- package/dist/agents-patterns.d.mts.map +1 -0
- package/dist/agents-patterns.mjs +18 -0
- package/dist/agents-patterns.mjs.map +1 -0
- package/dist/agents-persistence.d.mts +234 -0
- package/dist/agents-persistence.d.mts.map +1 -0
- package/dist/agents-persistence.mjs +447 -0
- package/dist/agents-persistence.mjs.map +1 -0
- package/dist/agents-triage.d.mts +11 -0
- package/dist/agents-triage.d.mts.map +1 -0
- package/dist/agents-triage.mjs +13 -0
- package/dist/agents-triage.mjs.map +1 -0
- package/dist/agents-workflows.d.mts +9 -0
- package/dist/agents-workflows.d.mts.map +1 -0
- package/dist/agents-workflows.mjs +9 -0
- package/dist/agents-workflows.mjs.map +1 -0
- package/dist/agents.d.mts +30 -0
- package/dist/agents.d.mts.map +1 -0
- package/dist/agents.mjs +50 -0
- package/dist/agents.mjs.map +1 -0
- package/dist/aggregation-8KJF1uzp.d.mts +276 -0
- package/dist/aggregation-8KJF1uzp.d.mts.map +1 -0
- package/dist/aggregation-BDop87kL.mjs +1180 -0
- package/dist/aggregation-BDop87kL.mjs.map +1 -0
- package/dist/ai-runtime-CDzQztTt.mjs +85 -0
- package/dist/ai-runtime-CDzQztTt.mjs.map +1 -0
- package/dist/ai-runtime-DIwOEc6g.d.mts +56 -0
- package/dist/ai-runtime-DIwOEc6g.d.mts.map +1 -0
- package/dist/ai-sdk-error-integration-D0GDqrM0.d.mts +553 -0
- package/dist/ai-sdk-error-integration-D0GDqrM0.d.mts.map +1 -0
- package/dist/approval-queue-BcDDQ4oQ.mjs +104 -0
- package/dist/approval-queue-BcDDQ4oQ.mjs.map +1 -0
- package/dist/approval-queue-CiKiFT9z.d.mts +21 -0
- package/dist/approval-queue-CiKiFT9z.d.mts.map +1 -0
- package/dist/audio-BzvN7r10.d.mts +79 -0
- package/dist/audio-BzvN7r10.d.mts.map +1 -0
- package/dist/audio-vBG_62ME.mjs +226 -0
- package/dist/audio-vBG_62ME.mjs.map +1 -0
- package/dist/audit-logger-Bb2JIcIk.d.mts +12 -0
- package/dist/audit-logger-Bb2JIcIk.d.mts.map +1 -0
- package/dist/audit-logger-CHIP8bRO.mjs +596 -0
- package/dist/audit-logger-CHIP8bRO.mjs.map +1 -0
- package/dist/auto-resume-BpUNbPtp.d.mts +160 -0
- package/dist/auto-resume-BpUNbPtp.d.mts.map +1 -0
- package/dist/auto-resume-BuFRNvAX.mjs +638 -0
- package/dist/auto-resume-BuFRNvAX.mjs.map +1 -0
- package/dist/budget-guard-C83KCH9V.d.mts +52 -0
- package/dist/budget-guard-C83KCH9V.d.mts.map +1 -0
- package/dist/budget-guard-d_b5rq4u.mjs +158 -0
- package/dist/budget-guard-d_b5rq4u.mjs.map +1 -0
- package/dist/budget-guard-gyhJS00s.mjs +234 -0
- package/dist/budget-guard-gyhJS00s.mjs.map +1 -0
- package/dist/buffer-BC8mvXHE.d.mts +98 -0
- package/dist/buffer-BC8mvXHE.d.mts.map +1 -0
- package/dist/buffer-CefJGbRy.mjs +289 -0
- package/dist/buffer-CefJGbRy.mjs.map +1 -0
- package/dist/caching-adapters.d.mts +5 -0
- package/dist/caching-adapters.mjs +3 -0
- package/dist/caching-strategies.d.mts +52 -0
- package/dist/caching-strategies.d.mts.map +1 -0
- package/dist/caching-strategies.mjs +703 -0
- package/dist/caching-strategies.mjs.map +1 -0
- package/dist/caching.d.mts +14 -0
- package/dist/caching.d.mts.map +1 -0
- package/dist/caching.mjs +15 -0
- package/dist/caching.mjs.map +1 -0
- package/dist/catalog.d.mts +19 -0
- package/dist/catalog.d.mts.map +1 -0
- package/dist/catalog.mjs +1114 -0
- package/dist/catalog.mjs.map +1 -0
- package/dist/chunk-CkzbjWQW.mjs +20 -0
- package/dist/circuit-breaker-DoKWPORd.mjs +262 -0
- package/dist/circuit-breaker-DoKWPORd.mjs.map +1 -0
- package/dist/circuit-breaker-Mey3E7tW.d.mts +64 -0
- package/dist/circuit-breaker-Mey3E7tW.d.mts.map +1 -0
- package/dist/citation-generator-C-9RpbHq.mjs +103 -0
- package/dist/citation-generator-C-9RpbHq.mjs.map +1 -0
- package/dist/citation-generator-CDSymDs_.d.mts +18 -0
- package/dist/citation-generator-CDSymDs_.d.mts.map +1 -0
- package/dist/client-CpacYDIE.mjs +882 -0
- package/dist/client-CpacYDIE.mjs.map +1 -0
- package/dist/client.d.mts +103 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +470 -0
- package/dist/client.mjs.map +1 -0
- package/dist/compliance-approval-queue-DQGLojAm.mjs +172 -0
- package/dist/compliance-approval-queue-DQGLojAm.mjs.map +1 -0
- package/dist/compliance-approval-queue-IrMxFfSJ.d.mts +99 -0
- package/dist/compliance-approval-queue-IrMxFfSJ.d.mts.map +1 -0
- package/dist/compliance-wrapper-CrOMHhHN.mjs +528 -0
- package/dist/compliance-wrapper-CrOMHhHN.mjs.map +1 -0
- package/dist/conditions-DmQ6Y1Wt.mjs +179 -0
- package/dist/conditions-DmQ6Y1Wt.mjs.map +1 -0
- package/dist/conditions-zDrKfrc3.d.mts +42 -0
- package/dist/conditions-zDrKfrc3.d.mts.map +1 -0
- package/dist/console-BGMxxPZN.mjs +181 -0
- package/dist/console-BGMxxPZN.mjs.map +1 -0
- package/dist/console-DqEqZd4A.d.mts +76 -0
- package/dist/console-DqEqZd4A.d.mts.map +1 -0
- package/dist/controller-BOy3-xbC.mjs +501 -0
- package/dist/controller-BOy3-xbC.mjs.map +1 -0
- package/dist/controller-Y0NGosbJ.d.mts +104 -0
- package/dist/controller-Y0NGosbJ.d.mts.map +1 -0
- package/dist/coordinator-agent-BglqZLwo.d.mts +54 -0
- package/dist/coordinator-agent-BglqZLwo.d.mts.map +1 -0
- package/dist/coordinator-agent-WFWBRL-G.mjs +236 -0
- package/dist/coordinator-agent-WFWBRL-G.mjs.map +1 -0
- package/dist/crypto-8ABhc3TD.mjs +40 -0
- package/dist/crypto-8ABhc3TD.mjs.map +1 -0
- package/dist/environment-CSoJb0SW.mjs +255 -0
- package/dist/environment-CSoJb0SW.mjs.map +1 -0
- package/dist/error-handling-DNVkm6RY.mjs +1334 -0
- package/dist/error-handling-DNVkm6RY.mjs.map +1 -0
- package/dist/errors-CQ8tF4dP.mjs +985 -0
- package/dist/errors-CQ8tF4dP.mjs.map +1 -0
- package/dist/errors-CfYdVeum.d.mts +212 -0
- package/dist/errors-CfYdVeum.d.mts.map +1 -0
- package/dist/errors-Dtn-UeRi.mjs +61 -0
- package/dist/errors-Dtn-UeRi.mjs.map +1 -0
- package/dist/evaluator-Cs84qkr8.mjs +91 -0
- package/dist/evaluator-Cs84qkr8.mjs.map +1 -0
- package/dist/evaluator-optimizer-De67_mJC.mjs +1086 -0
- package/dist/evaluator-optimizer-De67_mJC.mjs.map +1 -0
- package/dist/evaluator-optimizer-pattern-B5939s2Z.mjs +367 -0
- package/dist/evaluator-optimizer-pattern-B5939s2Z.mjs.map +1 -0
- package/dist/evaluator-optimizer-pattern-D1AJrzBD.d.mts +72 -0
- package/dist/evaluator-optimizer-pattern-D1AJrzBD.d.mts.map +1 -0
- package/dist/factory-DP6VSl8C.mjs +307 -0
- package/dist/factory-DP6VSl8C.mjs.map +1 -0
- package/dist/generative-ui-catalog.d.mts +8 -0
- package/dist/generative-ui-catalog.d.mts.map +1 -0
- package/dist/generative-ui-catalog.mjs +679 -0
- package/dist/generative-ui-catalog.mjs.map +1 -0
- package/dist/generative-ui-registry.d.mts +195 -0
- package/dist/generative-ui-registry.d.mts.map +1 -0
- package/dist/generative-ui-registry.mjs +250 -0
- package/dist/generative-ui-registry.mjs.map +1 -0
- package/dist/generative-ui-stream.d.mts +23 -0
- package/dist/generative-ui-stream.d.mts.map +1 -0
- package/dist/generative-ui-stream.mjs +219 -0
- package/dist/generative-ui-stream.mjs.map +1 -0
- package/dist/generative-ui-types.d.mts +123 -0
- package/dist/generative-ui-types.d.mts.map +1 -0
- package/dist/generative-ui-types.mjs +1 -0
- package/dist/generative-ui.d.mts +13 -0
- package/dist/generative-ui.d.mts.map +1 -0
- package/dist/generative-ui.mjs +21 -0
- package/dist/generative-ui.mjs.map +1 -0
- package/dist/governance-audit.d.mts +3 -0
- package/dist/governance-audit.mjs +3 -0
- package/dist/governance-compliance.d.mts +5 -0
- package/dist/governance-compliance.mjs +4 -0
- package/dist/governance-policies.d.mts +4 -0
- package/dist/governance-policies.mjs +4 -0
- package/dist/governance-tenancy.d.mts +3 -0
- package/dist/governance-tenancy.mjs +3 -0
- package/dist/governance.d.mts +88 -0
- package/dist/governance.d.mts.map +1 -0
- package/dist/governance.mjs +432 -0
- package/dist/governance.mjs.map +1 -0
- package/dist/grounding-attribution.d.mts +63 -0
- package/dist/grounding-attribution.d.mts.map +1 -0
- package/dist/grounding-attribution.mjs +259 -0
- package/dist/grounding-attribution.mjs.map +1 -0
- package/dist/grounding-citation.d.mts +2 -0
- package/dist/grounding-citation.mjs +3 -0
- package/dist/grounding-context.d.mts +9 -0
- package/dist/grounding-context.d.mts.map +1 -0
- package/dist/grounding-context.mjs +19 -0
- package/dist/grounding-context.mjs.map +1 -0
- package/dist/grounding-embed.d.mts +102 -0
- package/dist/grounding-embed.d.mts.map +1 -0
- package/dist/grounding-embed.mjs +417 -0
- package/dist/grounding-embed.mjs.map +1 -0
- package/dist/grounding-hallucination.d.mts +44 -0
- package/dist/grounding-hallucination.d.mts.map +1 -0
- package/dist/grounding-hallucination.mjs +115 -0
- package/dist/grounding-hallucination.mjs.map +1 -0
- package/dist/grounding-proof-map.d.mts +9 -0
- package/dist/grounding-proof-map.d.mts.map +1 -0
- package/dist/grounding-proof-map.mjs +26 -0
- package/dist/grounding-proof-map.mjs.map +1 -0
- package/dist/grounding-rag.d.mts +10 -0
- package/dist/grounding-rag.d.mts.map +1 -0
- package/dist/grounding-rag.mjs +27 -0
- package/dist/grounding-rag.mjs.map +1 -0
- package/dist/grounding-verification.d.mts +48 -0
- package/dist/grounding-verification.d.mts.map +1 -0
- package/dist/grounding-verification.mjs +224 -0
- package/dist/grounding-verification.mjs.map +1 -0
- package/dist/grounding.d.mts +24 -0
- package/dist/grounding.d.mts.map +1 -0
- package/dist/grounding.mjs +77 -0
- package/dist/grounding.mjs.map +1 -0
- package/dist/hitl-active-learning.d.mts +41 -0
- package/dist/hitl-active-learning.d.mts.map +1 -0
- package/dist/hitl-active-learning.mjs +178 -0
- package/dist/hitl-active-learning.mjs.map +1 -0
- package/dist/hitl-annotation.d.mts +74 -0
- package/dist/hitl-annotation.d.mts.map +1 -0
- package/dist/hitl-annotation.mjs +170 -0
- package/dist/hitl-annotation.mjs.map +1 -0
- package/dist/hitl-approval.d.mts +2 -0
- package/dist/hitl-approval.mjs +3 -0
- package/dist/hitl-feedback.d.mts +59 -0
- package/dist/hitl-feedback.d.mts.map +1 -0
- package/dist/hitl-feedback.mjs +137 -0
- package/dist/hitl-feedback.mjs.map +1 -0
- package/dist/hitl-review.d.mts +2 -0
- package/dist/hitl-review.mjs +3 -0
- package/dist/hitl.d.mts +14 -0
- package/dist/hitl.d.mts.map +1 -0
- package/dist/hitl.mjs +22 -0
- package/dist/hitl.mjs.map +1 -0
- package/dist/index-B17HT-VL.d.mts +285 -0
- package/dist/index-B17HT-VL.d.mts.map +1 -0
- package/dist/index-BDwgsK9B.d.mts +101 -0
- package/dist/index-BDwgsK9B.d.mts.map +1 -0
- package/dist/index-BGgMn_Ev.d.mts +2615 -0
- package/dist/index-BGgMn_Ev.d.mts.map +1 -0
- package/dist/index-DOqe5r9G.d.mts +318 -0
- package/dist/index-DOqe5r9G.d.mts.map +1 -0
- package/dist/index-DotINT7o.d.mts +1004 -0
- package/dist/index-DotINT7o.d.mts.map +1 -0
- package/dist/index-URlW7aD1.d.mts +67 -0
- package/dist/index-URlW7aD1.d.mts.map +1 -0
- package/dist/index.d.mts +64 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +46 -0
- package/dist/index.mjs.map +1 -0
- package/dist/integrations-blob-storage.d.mts +25 -0
- package/dist/integrations-blob-storage.d.mts.map +1 -0
- package/dist/integrations-blob-storage.mjs +3 -0
- package/dist/integrations-notifications.d.mts +2 -0
- package/dist/integrations-notifications.mjs +3 -0
- package/dist/integrations-rate-limit.d.mts +27 -0
- package/dist/integrations-rate-limit.d.mts.map +1 -0
- package/dist/integrations-rate-limit.mjs +30 -0
- package/dist/integrations-rate-limit.mjs.map +1 -0
- package/dist/integrations-redis.d.mts +3 -0
- package/dist/integrations-redis.mjs +3 -0
- package/dist/integrations-stream.d.mts +14 -0
- package/dist/integrations-stream.d.mts.map +1 -0
- package/dist/integrations-stream.mjs +3 -0
- package/dist/integrations.d.mts +7 -0
- package/dist/integrations.mjs +7 -0
- package/dist/log-adapter-BLegSZtz.d.mts +16 -0
- package/dist/log-adapter-BLegSZtz.d.mts.map +1 -0
- package/dist/log-adapter-PPe_2Pwv.mjs +28 -0
- package/dist/log-adapter-PPe_2Pwv.mjs.map +1 -0
- package/dist/loop-BOYEtr2g.mjs +520 -0
- package/dist/loop-BOYEtr2g.mjs.map +1 -0
- package/dist/loop-C-tBBOqi.d.mts +219 -0
- package/dist/loop-C-tBBOqi.d.mts.map +1 -0
- package/dist/middleware-5wQ9bANW.mjs +306 -0
- package/dist/middleware-5wQ9bANW.mjs.map +1 -0
- package/dist/middleware-C1apSrj0.mjs +613 -0
- package/dist/middleware-C1apSrj0.mjs.map +1 -0
- package/dist/middleware-C7k0uItW.d.mts +9 -0
- package/dist/middleware-C7k0uItW.d.mts.map +1 -0
- package/dist/middleware-CZQCTHfl.mjs +366 -0
- package/dist/middleware-CZQCTHfl.mjs.map +1 -0
- package/dist/models.d.mts +11 -0
- package/dist/models.d.mts.map +1 -0
- package/dist/models.mjs +32 -0
- package/dist/models.mjs.map +1 -0
- package/dist/observability-analytics.d.mts +107 -0
- package/dist/observability-analytics.d.mts.map +1 -0
- package/dist/observability-analytics.mjs +409 -0
- package/dist/observability-analytics.mjs.map +1 -0
- package/dist/observability-cost.d.mts +10 -0
- package/dist/observability-cost.d.mts.map +1 -0
- package/dist/observability-cost.mjs +15 -0
- package/dist/observability-cost.mjs.map +1 -0
- package/dist/observability-telemetry.d.mts +111 -0
- package/dist/observability-telemetry.d.mts.map +1 -0
- package/dist/observability-telemetry.mjs +343 -0
- package/dist/observability-telemetry.mjs.map +1 -0
- package/dist/observability-tracing.d.mts +10 -0
- package/dist/observability-tracing.d.mts.map +1 -0
- package/dist/observability-tracing.mjs +17 -0
- package/dist/observability-tracing.mjs.map +1 -0
- package/dist/observability.d.mts +15 -0
- package/dist/observability.d.mts.map +1 -0
- package/dist/observability.mjs +17 -0
- package/dist/observability.mjs.map +1 -0
- package/dist/optimizer-DhXXpci6.mjs +97 -0
- package/dist/optimizer-DhXXpci6.mjs.map +1 -0
- package/dist/output-multimodal.d.mts +9 -0
- package/dist/output-multimodal.d.mts.map +1 -0
- package/dist/output-multimodal.mjs +18 -0
- package/dist/output-multimodal.mjs.map +1 -0
- package/dist/output.d.mts +11 -0
- package/dist/output.d.mts.map +1 -0
- package/dist/output.mjs +40 -0
- package/dist/output.mjs.map +1 -0
- package/dist/pii-filter-3AxmYSiu.d.mts +23 -0
- package/dist/pii-filter-3AxmYSiu.d.mts.map +1 -0
- package/dist/pipelines.d.mts +448 -0
- package/dist/pipelines.d.mts.map +1 -0
- package/dist/pipelines.mjs +1534 -0
- package/dist/pipelines.mjs.map +1 -0
- package/dist/prompt-injection-DQXchzsV.d.mts +8 -0
- package/dist/prompt-injection-DQXchzsV.d.mts.map +1 -0
- package/dist/prompt-injection-RpoLPwSa.mjs +52 -0
- package/dist/prompt-injection-RpoLPwSa.mjs.map +1 -0
- package/dist/prompts.d.mts +192 -0
- package/dist/prompts.d.mts.map +1 -0
- package/dist/prompts.mjs +732 -0
- package/dist/prompts.mjs.map +1 -0
- package/dist/protocol-DfBiEsnl.d.mts +112 -0
- package/dist/protocol-DfBiEsnl.d.mts.map +1 -0
- package/dist/quota-manager-0iPMkQWN.d.mts +62 -0
- package/dist/quota-manager-0iPMkQWN.d.mts.map +1 -0
- package/dist/quota-manager-D_N7FuQ2.mjs +180 -0
- package/dist/quota-manager-D_N7FuQ2.mjs.map +1 -0
- package/dist/redaction-utils-DcQwsiNh.mjs +438 -0
- package/dist/redaction-utils-DcQwsiNh.mjs.map +1 -0
- package/dist/redis-CpsSrF8K.mjs +102 -0
- package/dist/redis-CpsSrF8K.mjs.map +1 -0
- package/dist/redis-CwguYFGh.d.mts +33 -0
- package/dist/redis-CwguYFGh.d.mts.map +1 -0
- package/dist/registry-CsD3iTIx.mjs +190 -0
- package/dist/registry-CsD3iTIx.mjs.map +1 -0
- package/dist/registry-DVPWzkXR.d.mts +36 -0
- package/dist/registry-DVPWzkXR.d.mts.map +1 -0
- package/dist/reranking-BpWYhYzl.d.mts +72 -0
- package/dist/reranking-BpWYhYzl.d.mts.map +1 -0
- package/dist/reranking-Ck8aKZW7.mjs +331 -0
- package/dist/reranking-Ck8aKZW7.mjs.map +1 -0
- package/dist/resumable-adapter-CO1HtsgJ.mjs +21 -0
- package/dist/resumable-adapter-CO1HtsgJ.mjs.map +1 -0
- package/dist/review-trigger-DmAsiQlM.d.mts +24 -0
- package/dist/review-trigger-DmAsiQlM.d.mts.map +1 -0
- package/dist/review-trigger-DwXfpww9.mjs +112 -0
- package/dist/review-trigger-DwXfpww9.mjs.map +1 -0
- package/dist/safe-context-BynhkTKR.d.mts +54 -0
- package/dist/safe-context-BynhkTKR.d.mts.map +1 -0
- package/dist/safe-context-C5A3Wv3b.mjs +143 -0
- package/dist/safe-context-C5A3Wv3b.mjs.map +1 -0
- package/dist/schema-Bu2noOZ4.mjs +27 -0
- package/dist/schema-Bu2noOZ4.mjs.map +1 -0
- package/dist/schema-CwFvuCnA.mjs +97 -0
- package/dist/schema-CwFvuCnA.mjs.map +1 -0
- package/dist/schema-Wz-1-ro9.d.mts +37 -0
- package/dist/schema-Wz-1-ro9.d.mts.map +1 -0
- package/dist/schemas-CxQtxIga.mjs +62 -0
- package/dist/schemas-CxQtxIga.mjs.map +1 -0
- package/dist/schemas-DBOhxgW7.d.mts +32 -0
- package/dist/schemas-DBOhxgW7.d.mts.map +1 -0
- package/dist/schemas-Dp_OCqBt.d.mts +63 -0
- package/dist/schemas-Dp_OCqBt.d.mts.map +1 -0
- package/dist/schemas-SwCsnT0z.mjs +83 -0
- package/dist/schemas-SwCsnT0z.mjs.map +1 -0
- package/dist/sdk-errors.d.mts +2 -0
- package/dist/sdk-errors.mjs +3 -0
- package/dist/sdk-experimental.d.mts +59 -0
- package/dist/sdk-experimental.d.mts.map +1 -0
- package/dist/sdk-experimental.mjs +193 -0
- package/dist/sdk-experimental.mjs.map +1 -0
- package/dist/sdk-stop-conditions.d.mts +3 -0
- package/dist/sdk-stop-conditions.mjs +3 -0
- package/dist/sdk.d.mts +15 -0
- package/dist/sdk.d.mts.map +1 -0
- package/dist/sdk.mjs +50 -0
- package/dist/sdk.mjs.map +1 -0
- package/dist/security-guardrails.d.mts +3 -0
- package/dist/security-guardrails.mjs +3 -0
- package/dist/security-injection.d.mts +2 -0
- package/dist/security-injection.mjs +3 -0
- package/dist/security.d.mts +12 -0
- package/dist/security.d.mts.map +1 -0
- package/dist/security.mjs +18 -0
- package/dist/security.mjs.map +1 -0
- package/dist/server.d.mts +420 -0
- package/dist/server.d.mts.map +1 -0
- package/dist/server.mjs +2225 -0
- package/dist/server.mjs.map +1 -0
- package/dist/shared.d.mts +2 -0
- package/dist/shared.mjs +3 -0
- package/dist/streaming-control.d.mts +2 -0
- package/dist/streaming-control.mjs +4 -0
- package/dist/streaming-core.d.mts +4 -0
- package/dist/streaming-core.mjs +3 -0
- package/dist/streaming-infra-resilience.d.mts +120 -0
- package/dist/streaming-infra-resilience.d.mts.map +1 -0
- package/dist/streaming-infra-resilience.mjs +358 -0
- package/dist/streaming-infra-resilience.mjs.map +1 -0
- package/dist/streaming-infra-transport.d.mts +57 -0
- package/dist/streaming-infra-transport.d.mts.map +1 -0
- package/dist/streaming-infra-transport.mjs +488 -0
- package/dist/streaming-infra-transport.mjs.map +1 -0
- package/dist/streaming-infra.d.mts +5 -0
- package/dist/streaming-infra.mjs +5 -0
- package/dist/streaming.d.mts +17 -0
- package/dist/streaming.d.mts.map +1 -0
- package/dist/streaming.mjs +71 -0
- package/dist/streaming.mjs.map +1 -0
- package/dist/telemetry-2eKMojIb.mjs +1046 -0
- package/dist/telemetry-2eKMojIb.mjs.map +1 -0
- package/dist/telemetry-C2t03dwD.d.mts +59 -0
- package/dist/telemetry-C2t03dwD.d.mts.map +1 -0
- package/dist/tool-Btbththq.d.mts +253 -0
- package/dist/tool-Btbththq.d.mts.map +1 -0
- package/dist/tool-JSf8JXZ8.mjs +1150 -0
- package/dist/tool-JSf8JXZ8.mjs.map +1 -0
- package/dist/tool-safety-CZO8a4D4.d.mts +60 -0
- package/dist/tool-safety-CZO8a4D4.d.mts.map +1 -0
- package/dist/tool-safety-DXtYDXod.mjs +319 -0
- package/dist/tool-safety-DXtYDXod.mjs.map +1 -0
- package/dist/tools-BuS2Uv0q.mjs +1708 -0
- package/dist/tools-BuS2Uv0q.mjs.map +1 -0
- package/dist/tools-approval.d.mts +99 -0
- package/dist/tools-approval.d.mts.map +1 -0
- package/dist/tools-approval.mjs +395 -0
- package/dist/tools-approval.mjs.map +1 -0
- package/dist/tools-compliance.d.mts +67 -0
- package/dist/tools-compliance.d.mts.map +1 -0
- package/dist/tools-compliance.mjs +330 -0
- package/dist/tools-compliance.mjs.map +1 -0
- package/dist/tools-computer.d.mts +25 -0
- package/dist/tools-computer.d.mts.map +1 -0
- package/dist/tools-computer.mjs +64 -0
- package/dist/tools-computer.mjs.map +1 -0
- package/dist/tools-core.d.mts +3 -0
- package/dist/tools-core.mjs +3 -0
- package/dist/tools-mcp.d.mts +3 -0
- package/dist/tools-mcp.mjs +5 -0
- package/dist/tools-superpowers.d.mts +2 -0
- package/dist/tools-superpowers.mjs +3 -0
- package/dist/tools.d.mts +401 -0
- package/dist/tools.d.mts.map +1 -0
- package/dist/tools.mjs +1921 -0
- package/dist/tools.mjs.map +1 -0
- package/dist/transport-selector-D-Ib05X1.mjs +1936 -0
- package/dist/transport-selector-D-Ib05X1.mjs.map +1 -0
- package/dist/triage-agent-BEsXg5sw.d.mts +63 -0
- package/dist/triage-agent-BEsXg5sw.d.mts.map +1 -0
- package/dist/triage-agent-CBsfX-HW.mjs +167 -0
- package/dist/triage-agent-CBsfX-HW.mjs.map +1 -0
- package/dist/types-BPnq3GQo.d.mts +23 -0
- package/dist/types-BPnq3GQo.d.mts.map +1 -0
- package/dist/types-BjWgimpY.d.mts +16 -0
- package/dist/types-BjWgimpY.d.mts.map +1 -0
- package/dist/types-BxD-5btB.d.mts +41 -0
- package/dist/types-BxD-5btB.d.mts.map +1 -0
- package/dist/types-By-r93bE.d.mts +36 -0
- package/dist/types-By-r93bE.d.mts.map +1 -0
- package/dist/types-CLBWFRZN.d.mts +69 -0
- package/dist/types-CLBWFRZN.d.mts.map +1 -0
- package/dist/types-CQ0HFd0u.d.mts +62 -0
- package/dist/types-CQ0HFd0u.d.mts.map +1 -0
- package/dist/types-D3zJb59_.d.mts +47 -0
- package/dist/types-D3zJb59_.d.mts.map +1 -0
- package/dist/types-DJnugQX0.d.mts +80 -0
- package/dist/types-DJnugQX0.d.mts.map +1 -0
- package/dist/types-DbUfMCnT.d.mts +70 -0
- package/dist/types-DbUfMCnT.d.mts.map +1 -0
- package/dist/upstash-adapter-D96Caq2O.mjs +22 -0
- package/dist/upstash-adapter-D96Caq2O.mjs.map +1 -0
- package/dist/upstash-adapter-DD4433dx.d.mts +8 -0
- package/dist/upstash-adapter-DD4433dx.d.mts.map +1 -0
- package/dist/utils-BlYhcD6M.mjs +319 -0
- package/dist/utils-BlYhcD6M.mjs.map +1 -0
- package/dist/utils-DpJGOb3y.d.mts +120 -0
- package/dist/utils-DpJGOb3y.d.mts.map +1 -0
- package/dist/vercel-blob-adapter-CkOXLT2D.mjs +25 -0
- package/dist/vercel-blob-adapter-CkOXLT2D.mjs.map +1 -0
- package/dist/xai-CbV_dCnP.mjs +1600 -0
- package/dist/xai-CbV_dCnP.mjs.map +1 -0
- package/package.json +479 -0
- package/src/agents/base/factory.ts +382 -0
- package/src/agents/base/index.ts +8 -0
- package/src/agents/base/schemas.ts +117 -0
- package/src/agents/base/types.ts +192 -0
- package/src/agents/control-flow/index.ts +683 -0
- package/src/agents/coordinator/coordinator-agent.ts +381 -0
- package/src/agents/coordinator/index.ts +6 -0
- package/src/agents/default-agent.ts +211 -0
- package/src/agents/evaluator-optimizer/README.md +612 -0
- package/src/agents/evaluator-optimizer/evaluator-optimizer.example.ts +437 -0
- package/src/agents/evaluator-optimizer/evaluator.ts +282 -0
- package/src/agents/evaluator-optimizer/index.test.ts +416 -0
- package/src/agents/evaluator-optimizer/index.ts +519 -0
- package/src/agents/evaluator-optimizer/optimizer.ts +322 -0
- package/src/agents/evaluator-optimizer/schema.ts +302 -0
- package/src/agents/evaluator-optimizer/utils.ts +42 -0
- package/src/agents/experimental/index.ts +1095 -0
- package/src/agents/experimental/types.ts +212 -0
- package/src/agents/fallback/index.ts +18 -0
- package/src/agents/fallback/recovery/circuit-breaker.ts +166 -0
- package/src/agents/fallback/strategies/model-fallback.ts +192 -0
- package/src/agents/fallback/types.ts +87 -0
- package/src/agents/governance-agent.ts +446 -0
- package/src/agents/index.ts +79 -0
- package/src/agents/multi/coordination/index.ts +6 -0
- package/src/agents/multi/coordination/message-bus.ts +144 -0
- package/src/agents/multi/index.ts +6 -0
- package/src/agents/multi/state/index.ts +162 -0
- package/src/agents/multi/supervisor/index.ts +7 -0
- package/src/agents/multi/supervisor/supervisor.ts +254 -0
- package/src/agents/multi/swarm/aggregation.ts +466 -0
- package/src/agents/multi/swarm/communication.ts +388 -0
- package/src/agents/multi/swarm/coordination.ts +380 -0
- package/src/agents/multi/swarm/index.ts +73 -0
- package/src/agents/multi/swarm/swarm-executor.ts +479 -0
- package/src/agents/multi/types.ts +181 -0
- package/src/agents/observability/index.ts +914 -0
- package/src/agents/orchestrator.ts +218 -0
- package/src/agents/patterns/README.md +512 -0
- package/src/agents/patterns/evaluator-optimizer-pattern.example.ts +455 -0
- package/src/agents/patterns/evaluator-optimizer-pattern.ts +653 -0
- package/src/agents/patterns/index.ts +26 -0
- package/src/agents/persistence/index.ts +726 -0
- package/src/agents/tools/index.ts +291 -0
- package/src/agents/tools/mcp.ts +188 -0
- package/src/agents/triage/index.ts +6 -0
- package/src/agents/triage/triage-agent.ts +280 -0
- package/src/agents/workflows/index.ts +6 -0
- package/src/agents/workflows/interfaces.ts +36 -0
- package/src/agents/workflows/schema.ts +20 -0
- package/src/caching/adapters/index.ts +7 -0
- package/src/caching/adapters/memory.ts +77 -0
- package/src/caching/adapters/redis.ts +60 -0
- package/src/caching/index.ts +17 -0
- package/src/caching/middleware.ts +452 -0
- package/src/caching/strategies/index.ts +1008 -0
- package/src/caching/types.ts +47 -0
- package/src/catalog.ts +921 -0
- package/src/client/chat-usage.ts +53 -0
- package/src/client/hooks.ts +343 -0
- package/src/client/index.ts +36 -0
- package/src/client/message-utils.ts +29 -0
- package/src/client/use-generative-ui.ts +174 -0
- package/src/client/utils.ts +66 -0
- package/src/generative-ui/catalog.ts +653 -0
- package/src/generative-ui/index.ts +82 -0
- package/src/generative-ui/registry.ts +273 -0
- package/src/generative-ui/stream.ts +324 -0
- package/src/generative-ui/types.ts +376 -0
- package/src/governance/audit/audit-logger.ts +239 -0
- package/src/governance/audit/audit-schema.ts +82 -0
- package/src/governance/audit/index.ts +6 -0
- package/src/governance/compliance/abac/policy-engine.ts +175 -0
- package/src/governance/compliance/abac/types.ts +40 -0
- package/src/governance/compliance/approval/compliance-approval-queue.ts +217 -0
- package/src/governance/compliance/index.ts +16 -0
- package/src/governance/compliance/schemas.ts +68 -0
- package/src/governance/compliance/types.ts +143 -0
- package/src/governance/compliance/validators/phi-detector.ts +145 -0
- package/src/governance/compliance/validators/redaction-utils.ts +176 -0
- package/src/governance/compliance/validators/safe-harbor.ts +135 -0
- package/src/governance/entitlements/index.ts +585 -0
- package/src/governance/entitlements/middleware.ts +651 -0
- package/src/governance/entitlements/rate-limiter.ts +711 -0
- package/src/governance/index.ts +32 -0
- package/src/governance/policies/guardrails.ts +1121 -0
- package/src/governance/policies/index.ts +42 -0
- package/src/governance/policies/loop-controls.ts +136 -0
- package/src/governance/policies/telemetry.ts +63 -0
- package/src/governance/tenancy/index.ts +30 -0
- package/src/governance/tenancy/isolation/context.ts +92 -0
- package/src/governance/tenancy/isolation/index.ts +13 -0
- package/src/governance/tenancy/quotas/index.ts +11 -0
- package/src/governance/tenancy/quotas/quota-manager.ts +180 -0
- package/src/governance/tenancy/types.ts +66 -0
- package/src/governance/types.ts +16 -0
- package/src/governance/versioning/index.ts +573 -0
- package/src/grounding/attribution/index.ts +424 -0
- package/src/grounding/citation/citation-generator.ts +174 -0
- package/src/grounding/citation/index.ts +12 -0
- package/src/grounding/context/index.ts +32 -0
- package/src/grounding/context/safe-context.ts +116 -0
- package/src/grounding/context/types.ts +62 -0
- package/src/grounding/context-engineering/error-handling.ts +359 -0
- package/src/grounding/context-engineering/index.ts +23 -0
- package/src/grounding/context-engineering/memory.ts +559 -0
- package/src/grounding/context-engineering/tool-masking.ts +338 -0
- package/src/grounding/embed/index.ts +704 -0
- package/src/grounding/embed/reranking.ts +604 -0
- package/src/grounding/hallucination/index.ts +223 -0
- package/src/grounding/index.ts +82 -0
- package/src/grounding/proof-map/applyPatch.ts +172 -0
- package/src/grounding/proof-map/index.ts +41 -0
- package/src/grounding/proof-map/loop.ts +275 -0
- package/src/grounding/proof-map/schema.ts +217 -0
- package/src/grounding/rag/__tests__/pipeline.test.ts +274 -0
- package/src/grounding/rag/__tests__/tool.test.ts +202 -0
- package/src/grounding/rag/__tests__/trace.test.ts +229 -0
- package/src/grounding/rag/circuit-breaker.ts +152 -0
- package/src/grounding/rag/index.ts +64 -0
- package/src/grounding/rag/pipeline.ts +602 -0
- package/src/grounding/rag/tool.ts +281 -0
- package/src/grounding/rag/trace.ts +503 -0
- package/src/grounding/rag/types.ts +284 -0
- package/src/grounding/retrieval/in-memory-store.ts +107 -0
- package/src/grounding/sources/index.ts +943 -0
- package/src/grounding/tests/applyPatch.test.ts +194 -0
- package/src/grounding/tests/loop.test.ts +141 -0
- package/src/grounding/tests/schema.test.ts +160 -0
- package/src/grounding/types.ts +100 -0
- package/src/grounding/verification/index.ts +419 -0
- package/src/hitl/active-learning/index.ts +332 -0
- package/src/hitl/annotation/index.ts +362 -0
- package/src/hitl/approval/approval-queue.ts +132 -0
- package/src/hitl/approval/index.ts +5 -0
- package/src/hitl/feedback/index.ts +284 -0
- package/src/hitl/index.ts +69 -0
- package/src/hitl/review/index.ts +6 -0
- package/src/hitl/review/review-trigger.ts +162 -0
- package/src/hitl/types.ts +126 -0
- package/src/index.ts +125 -0
- package/src/integrations/blob-storage/index.ts +7 -0
- package/src/integrations/blob-storage/types.ts +28 -0
- package/src/integrations/blob-storage/vercel-blob-adapter.ts +35 -0
- package/src/integrations/index.ts +15 -0
- package/src/integrations/notifications/index.ts +7 -0
- package/src/integrations/notifications/log-adapter.ts +30 -0
- package/src/integrations/notifications/types.ts +27 -0
- package/src/integrations/rate-limit/index.ts +7 -0
- package/src/integrations/rate-limit/types.ts +26 -0
- package/src/integrations/rate-limit/upstash-adapter.ts +45 -0
- package/src/integrations/redis/index.ts +7 -0
- package/src/integrations/redis/types.ts +67 -0
- package/src/integrations/redis/upstash-adapter.ts +18 -0
- package/src/integrations/stream/index.ts +7 -0
- package/src/integrations/stream/resumable-adapter.ts +20 -0
- package/src/integrations/stream/types.ts +21 -0
- package/src/internal/__tests__/hallucination.test.ts +162 -0
- package/src/internal/__tests__/models.test.ts +104 -0
- package/src/internal/__tests__/sdk-errors.test.ts +201 -0
- package/src/internal/__tests__/stop-conditions.test.ts +210 -0
- package/src/internal/shared/ai-types.ts +942 -0
- package/src/internal/testing/evaluators.ts +575 -0
- package/src/internal/testing/index.ts +960 -0
- package/src/internal/ui/data-parts.ts +511 -0
- package/src/internal/ui/type-guards.ts +344 -0
- package/src/internal/ui-factories/__tests__/ui-factories.test.ts +548 -0
- package/src/internal/ui-factories/artifact-factory.ts +667 -0
- package/src/internal/ui-factories/index.ts +82 -0
- package/src/internal/ui-factories/shimmer-manager.ts +220 -0
- package/src/internal/ui-factories/status-helpers.ts +149 -0
- package/src/internal/ui-factories/tool-renderer.ts +167 -0
- package/src/internal/ui-factories/types.ts +235 -0
- package/src/models/capabilities.ts +88 -0
- package/src/models/index.ts +16 -0
- package/src/models/provider-factory.ts +229 -0
- package/src/models/providers/anthropic.ts +539 -0
- package/src/models/providers/google.ts +354 -0
- package/src/models/providers/index.ts +21 -0
- package/src/models/providers/openai.ts +346 -0
- package/src/models/providers/perplexity.ts +276 -0
- package/src/models/providers/shared.ts +90 -0
- package/src/models/providers/xai.ts +269 -0
- package/src/models/registry.ts +208 -0
- package/src/models/routing/index.ts +45 -0
- package/src/models/routing/intent-router.ts +143 -0
- package/src/models/routing/model-router.ts +300 -0
- package/src/models/routing/types.ts +106 -0
- package/src/models/types.ts +23 -0
- package/src/observability/analytics/index.ts +593 -0
- package/src/observability/cost/index.ts +16 -0
- package/src/observability/cost/tracking/budget-guard.ts +110 -0
- package/src/observability/cost/tracking/usage-tracker.ts +120 -0
- package/src/observability/cost/types.ts +85 -0
- package/src/observability/index.ts +17 -0
- package/src/observability/telemetry/index.ts +508 -0
- package/src/observability/tracing/index.ts +30 -0
- package/src/observability/tracing/otel/ai-instrumentation.ts +193 -0
- package/src/observability/tracing/otel/exporters/console.ts +58 -0
- package/src/observability/tracing/otel/exporters/index.ts +6 -0
- package/src/observability/tracing/provenance.ts +769 -0
- package/src/observability/tracing/types.ts +92 -0
- package/src/output/__tests__/output.test.ts +737 -0
- package/src/output/element-stream.ts +678 -0
- package/src/output/errors.ts +108 -0
- package/src/output/factories.ts +392 -0
- package/src/output/index.ts +98 -0
- package/src/output/multimodal/EXPORTS.md +306 -0
- package/src/output/multimodal/IMPLEMENTATION_SUMMARY.md +421 -0
- package/src/output/multimodal/README.md +349 -0
- package/src/output/multimodal/SETUP_GUIDE.md +472 -0
- package/src/output/multimodal/audio.ts +650 -0
- package/src/output/multimodal/image.ts +22 -0
- package/src/output/multimodal/index.ts +32 -0
- package/src/output/multimodal/providers.example.ts +375 -0
- package/src/output/validator.ts +495 -0
- package/src/pipelines/adapters/trace-storage-blob.ts +458 -0
- package/src/pipelines/adapters/trace-storage-memory.ts +319 -0
- package/src/pipelines/defaults.ts +109 -0
- package/src/pipelines/index.ts +24 -0
- package/src/pipelines/message-transforms.ts +107 -0
- package/src/pipelines/multi-step-wrapper.ts +433 -0
- package/src/pipelines/pipeline-presets.ts +339 -0
- package/src/pipelines/step-executor.ts +257 -0
- package/src/pipelines/storage-factory.ts +85 -0
- package/src/pipelines/trace-storage-interface.ts +216 -0
- package/src/pipelines/types.ts +255 -0
- package/src/pipelines/validation.ts +323 -0
- package/src/prompts/index.ts +271 -0
- package/src/prompts/model-variants.ts +410 -0
- package/src/prompts/templates.ts +327 -0
- package/src/sdk/errors/base.ts +296 -0
- package/src/sdk/errors/index.ts +31 -0
- package/src/sdk/errors/utils.ts +148 -0
- package/src/sdk/experimental/index.ts +286 -0
- package/src/sdk/index.ts +25 -0
- package/src/sdk/middleware/ai-middleware.ts +95 -0
- package/src/sdk/middleware/cache.ts +154 -0
- package/src/sdk/middleware/circuit-breaker.ts +388 -0
- package/src/sdk/middleware/compose.ts +81 -0
- package/src/sdk/middleware/deduplication.ts +307 -0
- package/src/sdk/middleware/index.ts +660 -0
- package/src/sdk/middleware/model-middleware.ts +200 -0
- package/src/sdk/stop-conditions/conditions.ts +209 -0
- package/src/sdk/stop-conditions/index.ts +35 -0
- package/src/sdk/stop-conditions/types.ts +59 -0
- package/src/security/guardrails/index.ts +6 -0
- package/src/security/guardrails/middleware.ts +465 -0
- package/src/security/guardrails/pii-filter.ts +396 -0
- package/src/security/index.ts +33 -0
- package/src/security/injection/index.ts +5 -0
- package/src/security/injection/prompt-injection.ts +64 -0
- package/src/security/types.ts +85 -0
- package/src/server/cache/crypto.ts +47 -0
- package/src/server/cache/performance.ts +79 -0
- package/src/server/error-handler.ts +93 -0
- package/src/server/errors.ts +73 -0
- package/src/server/helpers.ts +944 -0
- package/src/server/http.ts +156 -0
- package/src/server/index.ts +12 -0
- package/src/server/messages/__tests__/messages.test.ts +720 -0
- package/src/server/messages/converter.ts +245 -0
- package/src/server/messages/data-parts.ts +338 -0
- package/src/server/messages/extraction.ts +328 -0
- package/src/server/messages/index.ts +126 -0
- package/src/server/messages/types.ts +355 -0
- package/src/server/messages/window.ts +450 -0
- package/src/server/rate-limit/env.ts +8 -0
- package/src/server/rate-limit/rate-limit.ts +165 -0
- package/src/server/routes/HEALTH_CHECK.md +502 -0
- package/src/server/routes/IMPLEMENTATION_SUMMARY.md +432 -0
- package/src/server/routes/QUICK_START.md +327 -0
- package/src/server/routes/README.md +357 -0
- package/src/server/routes/__tests__/routes.test.ts +628 -0
- package/src/server/routes/agent-route.ts +224 -0
- package/src/server/routes/agent-routes.ts +191 -0
- package/src/server/routes/embed-config.ts +181 -0
- package/src/server/routes/health-check.example.ts +507 -0
- package/src/server/routes/health-check.test.ts +533 -0
- package/src/server/routes/health-check.ts +639 -0
- package/src/server/routes/health-check.types.ts +217 -0
- package/src/server/routes/index.ts +32 -0
- package/src/server/routes/types.ts +274 -0
- package/src/shared/__tests__/schemas.test.ts +317 -0
- package/src/shared/ai-runtime.ts +139 -0
- package/src/shared/ai-types.ts +133 -0
- package/src/shared/index.ts +30 -0
- package/src/shared/sdk-runtime.ts +198 -0
- package/src/shared/sdk-types.ts +301 -0
- package/src/streaming/control/__tests__/streaming-control.test.ts +708 -0
- package/src/streaming/control/budget-guard.ts +264 -0
- package/src/streaming/control/controller.ts +255 -0
- package/src/streaming/control/index.ts +105 -0
- package/src/streaming/control/smoothing.ts +201 -0
- package/src/streaming/control/step-limit.ts +215 -0
- package/src/streaming/control/types.ts +234 -0
- package/src/streaming/core/auto-resume.ts +276 -0
- package/src/streaming/core/index.ts +85 -0
- package/src/streaming/core/multi-step.ts +471 -0
- package/src/streaming/core/protocol.ts +194 -0
- package/src/streaming/core/types.ts +182 -0
- package/src/streaming/index.ts +97 -0
- package/src/streaming/infra/backpressure/buffer.ts +210 -0
- package/src/streaming/infra/backpressure/index.ts +6 -0
- package/src/streaming/infra/index.ts +75 -0
- package/src/streaming/infra/multiplexing/index.ts +311 -0
- package/src/streaming/infra/resilience/index.ts +684 -0
- package/src/streaming/infra/transform/index.ts +15 -0
- package/src/streaming/infra/transform/stream-transforms.ts +166 -0
- package/src/streaming/infra/transport/index.ts +774 -0
- package/src/streaming/infra/types.ts +118 -0
- package/src/streaming/infra-extra/types.ts +118 -0
- package/src/tools/advanced/caching.ts +299 -0
- package/src/tools/advanced/generator.ts +267 -0
- package/src/tools/advanced/hitl.ts +251 -0
- package/src/tools/advanced/index.ts +9 -0
- package/src/tools/advanced/llm-tool.ts +208 -0
- package/src/tools/approval/FILES.md +449 -0
- package/src/tools/approval/IMPLEMENTATION_SUMMARY.md +567 -0
- package/src/tools/approval/QUICK_START.md +362 -0
- package/src/tools/approval/README.md +514 -0
- package/src/tools/approval/advanced-approval-queue.ts +7 -0
- package/src/tools/approval/approval.example.ts +571 -0
- package/src/tools/approval/in-memory-queue.ts +405 -0
- package/src/tools/approval/index.ts +737 -0
- package/src/tools/approval/middleware.ts +590 -0
- package/src/tools/approval/queue-factory.ts +162 -0
- package/src/tools/approval/redis-queue.ts +327 -0
- package/src/tools/approval/testing.ts +493 -0
- package/src/tools/approval/types.ts +221 -0
- package/src/tools/approval/with-approval.ts +366 -0
- package/src/tools/artifacts/artifact-tools.ts +273 -0
- package/src/tools/artifacts/index.ts +6 -0
- package/src/tools/compliance/compliance-wrapper.ts +789 -0
- package/src/tools/compliance/create-compliant-stream.ts +226 -0
- package/src/tools/compliance/index.ts +8 -0
- package/src/tools/compliance/phi-redaction.ts +406 -0
- package/src/tools/compliance/tool-wrapper.ts +306 -0
- package/src/tools/computer/index.ts +99 -0
- package/src/tools/computer/types.ts +41 -0
- package/src/tools/core/abort.ts +202 -0
- package/src/tools/core/factory.ts +197 -0
- package/src/tools/core/index.ts +8 -0
- package/src/tools/core/tool-safety.ts +112 -0
- package/src/tools/generic/index.ts +9 -0
- package/src/tools/generic/json-schema-tool.ts +301 -0
- package/src/tools/generic/tiptap-context.ts +619 -0
- package/src/tools/generic/web-search-tool.ts +82 -0
- package/src/tools/generic/web-search.ts +142 -0
- package/src/tools/index.ts +36 -0
- package/src/tools/mcp/ai-sdk-error-integration.ts +401 -0
- package/src/tools/mcp/client.ts +988 -0
- package/src/tools/mcp/connection-manager.ts +380 -0
- package/src/tools/mcp/connection-pool.ts +408 -0
- package/src/tools/mcp/edge-runtime.ts +318 -0
- package/src/tools/mcp/environment.ts +310 -0
- package/src/tools/mcp/index.ts +20 -0
- package/src/tools/mcp/next-pattern.ts +401 -0
- package/src/tools/mcp/stream-lifecycle-integration.ts +617 -0
- package/src/tools/mcp/tool-cache.ts +359 -0
- package/src/tools/mcp/transport-selector.ts +492 -0
- package/src/tools/mcp/transports.ts +99 -0
- package/src/tools/simple-factory.ts +55 -0
- package/src/tools/superpowers/index.ts +122 -0
- package/src/tools/superpowers/prompts/index.ts +533 -0
- package/src/tools/superpowers/schemas/index.ts +701 -0
- package/src/tools/superpowers/tools/index.ts +721 -0
- package/src/tools/validation-wrapper.ts +97 -0
|
@@ -0,0 +1,1095 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Experimental Agent Module
|
|
3
|
+
*
|
|
4
|
+
* AI SDK v6 Agent patterns with enhanced control:
|
|
5
|
+
* - prepareStep hook for dynamic model escalation and context trimming
|
|
6
|
+
* - toolChoice control (auto/required/none/specific)
|
|
7
|
+
* - InferAgentUIMessage for end-to-end type safety
|
|
8
|
+
* - Step-based execution with configurable stop conditions
|
|
9
|
+
*
|
|
10
|
+
* @module agents/experimental
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { logWarn } from '@repo/shared/logs';
|
|
14
|
+
|
|
15
|
+
import { generateText, tool } from '../../shared';
|
|
16
|
+
import {
|
|
17
|
+
convertFromSDKUsage,
|
|
18
|
+
generateId,
|
|
19
|
+
resolveModelId as getModelId,
|
|
20
|
+
type TokenUsage,
|
|
21
|
+
type ModelRef,
|
|
22
|
+
type SDKToolChoice,
|
|
23
|
+
type SDKTextPart,
|
|
24
|
+
type SDKFilePart,
|
|
25
|
+
type SDKToolCallPart,
|
|
26
|
+
type SDKToolResultPart,
|
|
27
|
+
type SDKToolApprovalResponse,
|
|
28
|
+
type SDKModelMessage,
|
|
29
|
+
type SDKUserMessage,
|
|
30
|
+
type SDKSystemMessage,
|
|
31
|
+
type SDKAssistantMessage,
|
|
32
|
+
type SDKToolMessage,
|
|
33
|
+
type SDKLanguageModel,
|
|
34
|
+
type SDKToolSet,
|
|
35
|
+
type SDKFlexibleSchema,
|
|
36
|
+
type MessageRole,
|
|
37
|
+
type CoreMessageRole,
|
|
38
|
+
type StepFinishReason,
|
|
39
|
+
type AgentFinishReason,
|
|
40
|
+
} from '../../shared';
|
|
41
|
+
|
|
42
|
+
import type { z } from 'zod';
|
|
43
|
+
|
|
44
|
+
// -----------------------------------------------------------------------------
|
|
45
|
+
// Types (SDK-Aligned)
|
|
46
|
+
// -----------------------------------------------------------------------------
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Model reference - LanguageModel instance from AI SDK.
|
|
50
|
+
* Re-exported from ai-types for convenience.
|
|
51
|
+
*/
|
|
52
|
+
export type { ModelRef };
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Tool choice options.
|
|
56
|
+
* Aligned with AI SDK v6's ToolChoice type.
|
|
57
|
+
* @see SDKToolChoice for the SDK's native type
|
|
58
|
+
*/
|
|
59
|
+
export type ToolChoice = SDKToolChoice<SDKToolSet>;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Token usage tracking.
|
|
63
|
+
* Re-exported from ai-types for convenience.
|
|
64
|
+
* @see TokenUsage in ai-types.ts
|
|
65
|
+
*/
|
|
66
|
+
export type { TokenUsage };
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Text part - SDK-aligned type for text content in messages.
|
|
70
|
+
*/
|
|
71
|
+
export type TextPart = SDKTextPart;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Tool call part - SDK-aligned type for tool invocations.
|
|
75
|
+
*/
|
|
76
|
+
export type ToolCallPart = SDKToolCallPart;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Tool result part - SDK-aligned type for tool execution results.
|
|
80
|
+
*/
|
|
81
|
+
export type ToolResultPart = SDKToolResultPart;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Message part types union.
|
|
85
|
+
* Directly uses AI SDK v6 part types for full compatibility.
|
|
86
|
+
*/
|
|
87
|
+
export type MessagePart =
|
|
88
|
+
| TextPart
|
|
89
|
+
| SDKFilePart
|
|
90
|
+
| ToolCallPart
|
|
91
|
+
| ToolResultPart
|
|
92
|
+
| SDKToolApprovalResponse;
|
|
93
|
+
|
|
94
|
+
type JsonValue = string | number | boolean | null | { [key: string]: JsonValue } | JsonValue[];
|
|
95
|
+
|
|
96
|
+
type AssistantPart = Exclude<MessagePart, SDKToolApprovalResponse>;
|
|
97
|
+
|
|
98
|
+
/** Tool definition */
|
|
99
|
+
export interface ToolDefinition<TInput = unknown, TOutput = unknown> {
|
|
100
|
+
readonly description: string;
|
|
101
|
+
readonly inputSchema: z.ZodSchema<TInput>;
|
|
102
|
+
readonly execute: (
|
|
103
|
+
input: TInput,
|
|
104
|
+
context: ToolExecutionContext,
|
|
105
|
+
) => Promise<TOutput> | AsyncIterable<TOutput>;
|
|
106
|
+
readonly strict?: boolean;
|
|
107
|
+
readonly inputExamples?: Array<{ input: TInput }>;
|
|
108
|
+
readonly needsApproval?: boolean | ((input: TInput) => Promise<boolean>);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Tool execution context */
|
|
112
|
+
export interface ToolExecutionContext {
|
|
113
|
+
readonly toolCallId: string;
|
|
114
|
+
readonly messages: AgentMessage[];
|
|
115
|
+
readonly abortSignal?: AbortSignal;
|
|
116
|
+
readonly context?: Record<string, unknown>;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Agent message (SDK-aligned).
|
|
121
|
+
* Uses SDK message part types for content and MessageRole type.
|
|
122
|
+
*/
|
|
123
|
+
export interface AgentMessage {
|
|
124
|
+
readonly id: string;
|
|
125
|
+
readonly role: MessageRole;
|
|
126
|
+
readonly content: string | MessagePart[];
|
|
127
|
+
readonly createdAt?: Date;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Step result from agent execution.
|
|
132
|
+
* Uses SDK-aligned StepFinishReason type.
|
|
133
|
+
*/
|
|
134
|
+
export interface AgentStepResult {
|
|
135
|
+
readonly stepNumber: number;
|
|
136
|
+
readonly message: AgentMessage;
|
|
137
|
+
readonly toolCalls?: Array<{
|
|
138
|
+
toolName: string;
|
|
139
|
+
toolCallId: string;
|
|
140
|
+
input: unknown;
|
|
141
|
+
output: ToolResultPart['output'];
|
|
142
|
+
duration?: number;
|
|
143
|
+
}>;
|
|
144
|
+
readonly usage?: TokenUsage;
|
|
145
|
+
readonly finishReason?: StepFinishReason;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Base agent configuration for experimental agent */
|
|
149
|
+
export interface ExperimentalAgentBaseConfig<
|
|
150
|
+
TTools extends Record<string, ToolDefinition> = Record<string, ToolDefinition>,
|
|
151
|
+
> {
|
|
152
|
+
/** Primary model for agent */
|
|
153
|
+
readonly model: ModelRef;
|
|
154
|
+
/** System prompt */
|
|
155
|
+
readonly system?: string;
|
|
156
|
+
/** Available tools */
|
|
157
|
+
readonly tools?: TTools;
|
|
158
|
+
/** Default tool choice behavior */
|
|
159
|
+
readonly toolChoice?: ToolChoice;
|
|
160
|
+
/** Maximum generation steps (default: 10) */
|
|
161
|
+
readonly maxSteps?: number;
|
|
162
|
+
/** Custom context passed to tools */
|
|
163
|
+
readonly context?: Record<string, unknown>;
|
|
164
|
+
/** Abort signal for cancellation */
|
|
165
|
+
readonly abortSignal?: AbortSignal;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** PrepareStep hook input */
|
|
169
|
+
export interface PrepareStepInput {
|
|
170
|
+
readonly stepNumber: number;
|
|
171
|
+
readonly messages: AgentMessage[];
|
|
172
|
+
readonly usage?: TokenUsage[];
|
|
173
|
+
readonly toolHistory?: Array<{ toolName: string; output: unknown }>;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** PrepareStep hook output */
|
|
177
|
+
export interface PrepareStepOutput {
|
|
178
|
+
/** Override model for this step */
|
|
179
|
+
readonly model?: ModelRef;
|
|
180
|
+
/** Trimmed/modified messages */
|
|
181
|
+
readonly messages?: AgentMessage[];
|
|
182
|
+
/** Override tool choice for this step */
|
|
183
|
+
readonly toolChoice?: ToolChoice;
|
|
184
|
+
/** Active tools (subset of available tools) */
|
|
185
|
+
readonly activeTools?: string[];
|
|
186
|
+
/** Additional system prompt */
|
|
187
|
+
readonly appendSystem?: string;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Agent with prepareStep hook */
|
|
191
|
+
export interface ExperimentalAgentConfig<
|
|
192
|
+
TTools extends Record<string, ToolDefinition> = Record<string, ToolDefinition>,
|
|
193
|
+
> extends ExperimentalAgentBaseConfig<TTools> {
|
|
194
|
+
/** Hook called before each generation step */
|
|
195
|
+
readonly prepareStep?: (
|
|
196
|
+
input: PrepareStepInput,
|
|
197
|
+
) => Promise<PrepareStepOutput> | PrepareStepOutput;
|
|
198
|
+
/** Callback after each step completes */
|
|
199
|
+
readonly onStepComplete?: (result: AgentStepResult) => Promise<void> | void;
|
|
200
|
+
/** Callback when tool needs approval */
|
|
201
|
+
readonly onToolApproval?: (
|
|
202
|
+
toolName: string,
|
|
203
|
+
input: unknown,
|
|
204
|
+
) => Promise<{ approved: boolean; reason?: string }>;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Agent execution result.
|
|
209
|
+
* Uses SDK-aligned AgentFinishReason type.
|
|
210
|
+
*/
|
|
211
|
+
export interface AgentResult {
|
|
212
|
+
readonly text: string;
|
|
213
|
+
readonly steps: AgentStepResult[];
|
|
214
|
+
readonly usage: TokenUsage;
|
|
215
|
+
readonly finishReason: AgentFinishReason;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// -----------------------------------------------------------------------------
|
|
219
|
+
// Experimental Agent Class
|
|
220
|
+
// -----------------------------------------------------------------------------
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Experimental Agent with enhanced control patterns.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```typescript
|
|
227
|
+
* const agent = new ExperimentalAgent({
|
|
228
|
+
* model: openai('gpt-4o'),
|
|
229
|
+
* system: 'You are a research assistant.',
|
|
230
|
+
* tools: { search, analyze, summarize },
|
|
231
|
+
* maxSteps: 15,
|
|
232
|
+
*
|
|
233
|
+
* prepareStep: async ({ stepNumber, messages, usage }) => {
|
|
234
|
+
* // Escalate to better model after step 5
|
|
235
|
+
* if (stepNumber >= 5) {
|
|
236
|
+
* return {
|
|
237
|
+
* model: openai('gpt-4-turbo'),
|
|
238
|
+
* messages: messages.slice(-10), // Trim history
|
|
239
|
+
* };
|
|
240
|
+
* }
|
|
241
|
+
* return {};
|
|
242
|
+
* },
|
|
243
|
+
* });
|
|
244
|
+
*
|
|
245
|
+
* const result = await agent.generate({ prompt: 'Research quantum computing' });
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
export class ExperimentalAgent<
|
|
249
|
+
TTools extends Record<string, ToolDefinition> = Record<string, ToolDefinition>,
|
|
250
|
+
> {
|
|
251
|
+
private readonly config: ExperimentalAgentConfig<TTools>;
|
|
252
|
+
private stepHistory: AgentStepResult[] = [];
|
|
253
|
+
private totalUsage: TokenUsage = { promptTokens: 0, completionTokens: 0, totalTokens: 0 };
|
|
254
|
+
private aborted = false;
|
|
255
|
+
|
|
256
|
+
constructor(config: ExperimentalAgentConfig<TTools>) {
|
|
257
|
+
this.config = {
|
|
258
|
+
maxSteps: 10,
|
|
259
|
+
toolChoice: 'auto',
|
|
260
|
+
...config,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Get all executed steps */
|
|
265
|
+
get steps(): AgentStepResult[] {
|
|
266
|
+
return [...this.stepHistory];
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** Get total token usage */
|
|
270
|
+
get usage(): TokenUsage {
|
|
271
|
+
return { ...this.totalUsage };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Generate a response for the given prompt.
|
|
276
|
+
*/
|
|
277
|
+
async generate(options: { prompt: string; messages?: AgentMessage[] }): Promise<AgentResult> {
|
|
278
|
+
this.stepHistory = [];
|
|
279
|
+
this.totalUsage = { promptTokens: 0, completionTokens: 0, totalTokens: 0 };
|
|
280
|
+
this.aborted = false;
|
|
281
|
+
|
|
282
|
+
const { prompt, messages: initialMessages = [] } = options;
|
|
283
|
+
|
|
284
|
+
// Build initial messages
|
|
285
|
+
let messages: AgentMessage[] = [
|
|
286
|
+
...initialMessages,
|
|
287
|
+
{
|
|
288
|
+
id: generateId(),
|
|
289
|
+
role: 'user',
|
|
290
|
+
content: prompt,
|
|
291
|
+
createdAt: new Date(),
|
|
292
|
+
},
|
|
293
|
+
];
|
|
294
|
+
|
|
295
|
+
const maxSteps = this.config.maxSteps ?? 10;
|
|
296
|
+
let stepNumber = 0;
|
|
297
|
+
let finishReason: AgentResult['finishReason'] = 'stop';
|
|
298
|
+
|
|
299
|
+
// Main agent loop
|
|
300
|
+
while (stepNumber < maxSteps && !this.aborted) {
|
|
301
|
+
// Check abort signal
|
|
302
|
+
if (this.config.abortSignal?.aborted) {
|
|
303
|
+
this.aborted = true;
|
|
304
|
+
finishReason = 'abort';
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
stepNumber++;
|
|
309
|
+
|
|
310
|
+
// Run prepareStep hook
|
|
311
|
+
let stepConfig: PrepareStepOutput = {};
|
|
312
|
+
if (this.config.prepareStep) {
|
|
313
|
+
stepConfig = await this.config.prepareStep({
|
|
314
|
+
stepNumber,
|
|
315
|
+
messages,
|
|
316
|
+
usage: this.stepHistory.map(s => s.usage).filter(Boolean) as TokenUsage[],
|
|
317
|
+
toolHistory: this.stepHistory.flatMap(s =>
|
|
318
|
+
(s.toolCalls ?? []).map(tc => ({ toolName: tc.toolName, output: tc.output })),
|
|
319
|
+
),
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
// Apply message trimming if provided
|
|
323
|
+
const { messages: preparedMessages } = stepConfig;
|
|
324
|
+
if (preparedMessages) {
|
|
325
|
+
messages = preparedMessages;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Determine active tools
|
|
330
|
+
const tools = this.getActiveTools(stepConfig.activeTools);
|
|
331
|
+
const toolChoice = stepConfig.toolChoice ?? this.config.toolChoice ?? 'auto';
|
|
332
|
+
const model = stepConfig.model ?? this.config.model;
|
|
333
|
+
|
|
334
|
+
// Execute step (simulated - in real implementation would call AI SDK)
|
|
335
|
+
const stepResult = await this.executeStep({
|
|
336
|
+
stepNumber,
|
|
337
|
+
messages,
|
|
338
|
+
tools,
|
|
339
|
+
toolChoice,
|
|
340
|
+
model,
|
|
341
|
+
appendSystem: stepConfig.appendSystem,
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
// Track step
|
|
345
|
+
this.stepHistory.push(stepResult);
|
|
346
|
+
this.updateUsage(stepResult.usage);
|
|
347
|
+
|
|
348
|
+
// Callback
|
|
349
|
+
if (this.config.onStepComplete) {
|
|
350
|
+
await this.config.onStepComplete(stepResult);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// Add assistant message to history
|
|
354
|
+
messages = [...messages, stepResult.message];
|
|
355
|
+
|
|
356
|
+
// Check if we should stop
|
|
357
|
+
if (stepResult.finishReason === 'stop') {
|
|
358
|
+
finishReason = 'stop';
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Process tool calls
|
|
363
|
+
if (stepResult.toolCalls && stepResult.toolCalls.length > 0) {
|
|
364
|
+
for (const toolCall of stepResult.toolCalls) {
|
|
365
|
+
// Add tool result to messages
|
|
366
|
+
messages = [
|
|
367
|
+
...messages,
|
|
368
|
+
{
|
|
369
|
+
id: generateId(),
|
|
370
|
+
role: 'tool',
|
|
371
|
+
content: [
|
|
372
|
+
{
|
|
373
|
+
type: 'tool-result',
|
|
374
|
+
toolCallId: toolCall.toolCallId,
|
|
375
|
+
toolName: toolCall.toolName,
|
|
376
|
+
output: toolCall.output,
|
|
377
|
+
},
|
|
378
|
+
],
|
|
379
|
+
},
|
|
380
|
+
];
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// If we hit max steps
|
|
386
|
+
if (stepNumber >= maxSteps && finishReason !== 'abort') {
|
|
387
|
+
finishReason = 'max-steps';
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Extract final text from last assistant message
|
|
391
|
+
const lastStep = this.stepHistory[this.stepHistory.length - 1];
|
|
392
|
+
const text = this.extractText(lastStep?.message);
|
|
393
|
+
|
|
394
|
+
return {
|
|
395
|
+
text,
|
|
396
|
+
steps: this.stepHistory,
|
|
397
|
+
usage: this.totalUsage,
|
|
398
|
+
finishReason,
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Stream a response (returns async generator).
|
|
404
|
+
*/
|
|
405
|
+
async *stream(options: {
|
|
406
|
+
prompt: string;
|
|
407
|
+
messages?: AgentMessage[];
|
|
408
|
+
}): AsyncGenerator<{ type: 'step' | 'text' | 'tool-call' | 'done'; data: unknown }> {
|
|
409
|
+
// Similar to generate but yields intermediate results
|
|
410
|
+
this.stepHistory = [];
|
|
411
|
+
this.totalUsage = { promptTokens: 0, completionTokens: 0, totalTokens: 0 };
|
|
412
|
+
this.aborted = false;
|
|
413
|
+
|
|
414
|
+
const { prompt, messages: initialMessages = [] } = options;
|
|
415
|
+
|
|
416
|
+
let messages: AgentMessage[] = [
|
|
417
|
+
...initialMessages,
|
|
418
|
+
{ id: generateId(), role: 'user', content: prompt, createdAt: new Date() },
|
|
419
|
+
];
|
|
420
|
+
|
|
421
|
+
const maxSteps = this.config.maxSteps ?? 10;
|
|
422
|
+
let stepNumber = 0;
|
|
423
|
+
|
|
424
|
+
while (stepNumber < maxSteps && !this.aborted) {
|
|
425
|
+
if (this.config.abortSignal?.aborted) {
|
|
426
|
+
this.aborted = true;
|
|
427
|
+
break;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
stepNumber++;
|
|
431
|
+
|
|
432
|
+
let stepConfig: PrepareStepOutput = {};
|
|
433
|
+
if (this.config.prepareStep) {
|
|
434
|
+
stepConfig = await this.config.prepareStep({
|
|
435
|
+
stepNumber,
|
|
436
|
+
messages,
|
|
437
|
+
usage: this.stepHistory.map(s => s.usage).filter(Boolean) as TokenUsage[],
|
|
438
|
+
toolHistory: this.stepHistory.flatMap(s =>
|
|
439
|
+
(s.toolCalls ?? []).map(tc => ({ toolName: tc.toolName, output: tc.output })),
|
|
440
|
+
),
|
|
441
|
+
});
|
|
442
|
+
const { messages: preparedMessages } = stepConfig;
|
|
443
|
+
if (preparedMessages) {
|
|
444
|
+
messages = preparedMessages;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
const tools = this.getActiveTools(stepConfig.activeTools);
|
|
449
|
+
const toolChoice = stepConfig.toolChoice ?? this.config.toolChoice ?? 'auto';
|
|
450
|
+
const model = stepConfig.model ?? this.config.model;
|
|
451
|
+
|
|
452
|
+
const stepResult = await this.executeStep({
|
|
453
|
+
stepNumber,
|
|
454
|
+
messages,
|
|
455
|
+
tools,
|
|
456
|
+
toolChoice,
|
|
457
|
+
model,
|
|
458
|
+
appendSystem: stepConfig.appendSystem,
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
this.stepHistory.push(stepResult);
|
|
462
|
+
this.updateUsage(stepResult.usage);
|
|
463
|
+
|
|
464
|
+
yield { type: 'step', data: stepResult };
|
|
465
|
+
|
|
466
|
+
if (stepResult.toolCalls) {
|
|
467
|
+
for (const tc of stepResult.toolCalls) {
|
|
468
|
+
yield { type: 'tool-call', data: tc };
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
const text = this.extractText(stepResult.message);
|
|
473
|
+
if (text) {
|
|
474
|
+
yield { type: 'text', data: text };
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
if (this.config.onStepComplete) {
|
|
478
|
+
await this.config.onStepComplete(stepResult);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
messages = [...messages, stepResult.message];
|
|
482
|
+
|
|
483
|
+
if (stepResult.finishReason === 'stop') break;
|
|
484
|
+
|
|
485
|
+
if (stepResult.toolCalls?.length) {
|
|
486
|
+
for (const tc of stepResult.toolCalls) {
|
|
487
|
+
messages = [
|
|
488
|
+
...messages,
|
|
489
|
+
{
|
|
490
|
+
id: generateId(),
|
|
491
|
+
role: 'tool',
|
|
492
|
+
content: [
|
|
493
|
+
{
|
|
494
|
+
type: 'tool-result',
|
|
495
|
+
toolCallId: tc.toolCallId,
|
|
496
|
+
toolName: tc.toolName,
|
|
497
|
+
output: tc.output,
|
|
498
|
+
},
|
|
499
|
+
],
|
|
500
|
+
},
|
|
501
|
+
];
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
yield {
|
|
507
|
+
type: 'done',
|
|
508
|
+
data: {
|
|
509
|
+
steps: this.stepHistory,
|
|
510
|
+
usage: this.totalUsage,
|
|
511
|
+
finishReason: this.aborted ? 'abort' : stepNumber >= maxSteps ? 'max-steps' : 'stop',
|
|
512
|
+
},
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* Abort the current execution.
|
|
518
|
+
*/
|
|
519
|
+
abort(): void {
|
|
520
|
+
this.aborted = true;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// ---------------------------------------------------------------------------
|
|
524
|
+
// Private Methods
|
|
525
|
+
// ---------------------------------------------------------------------------
|
|
526
|
+
|
|
527
|
+
private getActiveTools(activeToolNames?: string[]): Record<string, ToolDefinition> {
|
|
528
|
+
if (!this.config.tools) return {};
|
|
529
|
+
|
|
530
|
+
if (!activeToolNames) {
|
|
531
|
+
return this.config.tools as Record<string, ToolDefinition>;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
const result: Record<string, ToolDefinition> = {};
|
|
535
|
+
for (const name of activeToolNames) {
|
|
536
|
+
const tool = (this.config.tools as Record<string, ToolDefinition>)[name];
|
|
537
|
+
if (tool) {
|
|
538
|
+
result[name] = tool;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return result;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
private async executeStep(options: {
|
|
545
|
+
stepNumber: number;
|
|
546
|
+
messages: AgentMessage[];
|
|
547
|
+
tools: Record<string, ToolDefinition>;
|
|
548
|
+
toolChoice: ToolChoice;
|
|
549
|
+
model: ModelRef;
|
|
550
|
+
appendSystem?: string;
|
|
551
|
+
}): Promise<AgentStepResult> {
|
|
552
|
+
const { stepNumber, messages, tools, toolChoice, model, appendSystem } = options;
|
|
553
|
+
|
|
554
|
+
// Validate model is a proper LanguageModel instance
|
|
555
|
+
// ModelRef allows string | { modelId: string } but we need LanguageModel
|
|
556
|
+
if (
|
|
557
|
+
typeof model === 'string' ||
|
|
558
|
+
(typeof model === 'object' &&
|
|
559
|
+
model !== null &&
|
|
560
|
+
'modelId' in model &&
|
|
561
|
+
!('doGenerate' in model))
|
|
562
|
+
) {
|
|
563
|
+
throw new Error(
|
|
564
|
+
'Model must be a LanguageModel instance (e.g., from openai("gpt-4o")), not a plain string or object with modelId',
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
const languageModel = model as SDKLanguageModel;
|
|
568
|
+
|
|
569
|
+
// Convert AgentMessage[] to AI SDK format
|
|
570
|
+
const sdkMessages = this.convertMessagesToSDK(messages);
|
|
571
|
+
|
|
572
|
+
// Build system prompt
|
|
573
|
+
let systemPrompt = this.config.system;
|
|
574
|
+
if (appendSystem) {
|
|
575
|
+
systemPrompt = systemPrompt ? `${systemPrompt}\n\n${appendSystem}` : appendSystem;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// Convert tools to AI SDK format
|
|
579
|
+
const sdkTools = this.convertToolsToSDK(tools);
|
|
580
|
+
|
|
581
|
+
// Convert toolChoice to AI SDK format
|
|
582
|
+
const sdkToolChoice = this.convertToolChoiceToSDK(toolChoice);
|
|
583
|
+
|
|
584
|
+
// Call AI SDK generateText
|
|
585
|
+
const result = await generateText({
|
|
586
|
+
model: languageModel,
|
|
587
|
+
system: systemPrompt,
|
|
588
|
+
messages: sdkMessages,
|
|
589
|
+
tools: sdkTools,
|
|
590
|
+
toolChoice: sdkToolChoice,
|
|
591
|
+
abortSignal: this.config.abortSignal,
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
// Process tool calls
|
|
595
|
+
const toolCalls: AgentStepResult['toolCalls'] = [];
|
|
596
|
+
|
|
597
|
+
if (result.toolCalls && result.toolCalls.length > 0) {
|
|
598
|
+
for (const toolCall of result.toolCalls) {
|
|
599
|
+
const { toolName } = toolCall;
|
|
600
|
+
const tool = tools[toolName];
|
|
601
|
+
|
|
602
|
+
if (!tool) {
|
|
603
|
+
// Log warning for observability - tool name from model doesn't match registered tools
|
|
604
|
+
logWarn(`[ExperimentalAgent] Unknown tool "${toolName}" requested by model`);
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
const startTime = Date.now();
|
|
609
|
+
|
|
610
|
+
// Check approval if needed
|
|
611
|
+
let approved = true;
|
|
612
|
+
const input = toolCall.input ?? {};
|
|
613
|
+
let needsApprovalCheck = false;
|
|
614
|
+
if (tool.needsApproval) {
|
|
615
|
+
if (typeof tool.needsApproval === 'function') {
|
|
616
|
+
needsApprovalCheck = await tool.needsApproval(input);
|
|
617
|
+
} else {
|
|
618
|
+
needsApprovalCheck = tool.needsApproval;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
if (needsApprovalCheck) {
|
|
622
|
+
if (!this.config.onToolApproval) {
|
|
623
|
+
// HITL approval required but no handler configured - reject tool execution
|
|
624
|
+
throw new Error(
|
|
625
|
+
`Tool "${toolName}" requires approval but no onToolApproval handler is configured. ` +
|
|
626
|
+
`Either provide an onToolApproval callback or set needsApproval: false for this tool.`,
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
const approvalResult = await this.config.onToolApproval(toolName, input);
|
|
630
|
+
const { approved: approvedResult } = approvalResult;
|
|
631
|
+
approved = approvedResult;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
if (approved) {
|
|
635
|
+
const { toolCallId } = toolCall;
|
|
636
|
+
|
|
637
|
+
const toolResult = await this.executeToolCall(tool, input, {
|
|
638
|
+
toolCallId,
|
|
639
|
+
messages,
|
|
640
|
+
abortSignal: this.config.abortSignal,
|
|
641
|
+
context: this.config.context,
|
|
642
|
+
});
|
|
643
|
+
const output = this.toToolOutput(toolResult);
|
|
644
|
+
|
|
645
|
+
toolCalls.push({
|
|
646
|
+
toolName,
|
|
647
|
+
toolCallId,
|
|
648
|
+
input,
|
|
649
|
+
output,
|
|
650
|
+
duration: Date.now() - startTime,
|
|
651
|
+
});
|
|
652
|
+
} else {
|
|
653
|
+
// Add denied tool result to message history so model knows the call was rejected
|
|
654
|
+
const { toolCallId } = toolCall;
|
|
655
|
+
const output = this.toToolOutput('Tool call denied by approval handler');
|
|
656
|
+
toolCalls.push({
|
|
657
|
+
toolName,
|
|
658
|
+
toolCallId,
|
|
659
|
+
input,
|
|
660
|
+
output,
|
|
661
|
+
duration: Date.now() - startTime,
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
// Convert result to AgentMessage format
|
|
668
|
+
const message: AgentMessage = {
|
|
669
|
+
id: generateId(),
|
|
670
|
+
role: 'assistant',
|
|
671
|
+
content:
|
|
672
|
+
toolCalls.length > 0
|
|
673
|
+
? toolCalls.map(tc => ({
|
|
674
|
+
type: 'tool-call' as const,
|
|
675
|
+
toolCallId: tc.toolCallId,
|
|
676
|
+
toolName: tc.toolName,
|
|
677
|
+
input: tc.input,
|
|
678
|
+
}))
|
|
679
|
+
: result.text,
|
|
680
|
+
createdAt: new Date(),
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
// Convert usage
|
|
684
|
+
const usage = result.usage
|
|
685
|
+
? convertFromSDKUsage(result.usage)
|
|
686
|
+
: {
|
|
687
|
+
promptTokens: 0,
|
|
688
|
+
completionTokens: 0,
|
|
689
|
+
totalTokens: 0,
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
// Determine finish reason
|
|
693
|
+
let finishReason: AgentStepResult['finishReason'] = 'stop';
|
|
694
|
+
if (result.finishReason === 'tool-calls') {
|
|
695
|
+
finishReason = 'tool-calls';
|
|
696
|
+
} else if (result.finishReason === 'length') {
|
|
697
|
+
finishReason = 'length';
|
|
698
|
+
} else if (result.finishReason === 'content-filter') {
|
|
699
|
+
finishReason = 'content-filter';
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
return {
|
|
703
|
+
stepNumber,
|
|
704
|
+
message,
|
|
705
|
+
toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
706
|
+
usage,
|
|
707
|
+
finishReason,
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
private async executeToolCall(
|
|
712
|
+
tool: ToolDefinition,
|
|
713
|
+
input: unknown,
|
|
714
|
+
context: ToolExecutionContext,
|
|
715
|
+
): Promise<unknown> {
|
|
716
|
+
// Validate input against schema before execution
|
|
717
|
+
const parsedInput = tool.inputSchema.parse(input);
|
|
718
|
+
const result = tool.execute(parsedInput, context);
|
|
719
|
+
|
|
720
|
+
if (isAsyncIterable(result)) {
|
|
721
|
+
// Collect all yielded values - return all values for async iterables
|
|
722
|
+
const values: unknown[] = [];
|
|
723
|
+
for await (const value of result) {
|
|
724
|
+
values.push(value);
|
|
725
|
+
}
|
|
726
|
+
// Return single value if only one, otherwise return all values
|
|
727
|
+
return values.length === 1 ? values[0] : values;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
return result;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
private extractText(message?: AgentMessage): string {
|
|
734
|
+
if (!message) return '';
|
|
735
|
+
if (typeof message.content === 'string') return message.content;
|
|
736
|
+
const textParts = message.content.filter(
|
|
737
|
+
(p): p is { type: 'text'; text: string } => p.type === 'text',
|
|
738
|
+
);
|
|
739
|
+
return textParts.map(p => p.text).join('');
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
private updateUsage(usage?: TokenUsage): void {
|
|
743
|
+
if (!usage) return;
|
|
744
|
+
this.totalUsage = {
|
|
745
|
+
promptTokens: this.totalUsage.promptTokens + usage.promptTokens,
|
|
746
|
+
completionTokens: this.totalUsage.completionTokens + usage.completionTokens,
|
|
747
|
+
totalTokens: this.totalUsage.totalTokens + usage.totalTokens,
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
private isTextPart(part: MessagePart): part is TextPart {
|
|
752
|
+
return part.type === 'text';
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
private isFilePart(part: MessagePart): part is SDKFilePart {
|
|
756
|
+
return part.type === 'file';
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
private isAssistantPart(part: MessagePart): part is AssistantPart {
|
|
760
|
+
return part.type !== 'tool-approval-response';
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
private partsToText(parts: MessagePart[]): string {
|
|
764
|
+
return parts
|
|
765
|
+
.filter(part => this.isTextPart(part))
|
|
766
|
+
.map(part => part.text)
|
|
767
|
+
.join('\n');
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
private isJsonValue(value: unknown): value is JsonValue {
|
|
771
|
+
if (value === null) return true;
|
|
772
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
773
|
+
return true;
|
|
774
|
+
}
|
|
775
|
+
if (Array.isArray(value)) {
|
|
776
|
+
return value.every(item => this.isJsonValue(item));
|
|
777
|
+
}
|
|
778
|
+
if (typeof value === 'object') {
|
|
779
|
+
return Object.values(value).every(item => this.isJsonValue(item));
|
|
780
|
+
}
|
|
781
|
+
return false;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
private convertMessagesToSDK(messages: AgentMessage[]): SDKModelMessage[] {
|
|
785
|
+
return messages.map<SDKModelMessage>(msg => {
|
|
786
|
+
if (msg.role === 'tool') {
|
|
787
|
+
if (typeof msg.content === 'string') {
|
|
788
|
+
const toolMessage: SDKToolMessage = {
|
|
789
|
+
role: 'tool',
|
|
790
|
+
content: [
|
|
791
|
+
{
|
|
792
|
+
type: 'tool-result',
|
|
793
|
+
toolCallId: 'unknown',
|
|
794
|
+
toolName: 'unknown',
|
|
795
|
+
output: this.toToolOutput(msg.content),
|
|
796
|
+
},
|
|
797
|
+
],
|
|
798
|
+
};
|
|
799
|
+
return toolMessage;
|
|
800
|
+
}
|
|
801
|
+
const toolMessage: SDKToolMessage = {
|
|
802
|
+
role: 'tool',
|
|
803
|
+
content: this.normalizeToolContent(msg.content),
|
|
804
|
+
};
|
|
805
|
+
return toolMessage;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
if (msg.role === 'system') {
|
|
809
|
+
const systemMessage: SDKSystemMessage = {
|
|
810
|
+
role: 'system',
|
|
811
|
+
content: typeof msg.content === 'string' ? msg.content : this.partsToText(msg.content),
|
|
812
|
+
};
|
|
813
|
+
return systemMessage;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
if (msg.role === 'user') {
|
|
817
|
+
if (typeof msg.content === 'string') {
|
|
818
|
+
const userMessage: SDKUserMessage = { role: 'user', content: msg.content };
|
|
819
|
+
return userMessage;
|
|
820
|
+
}
|
|
821
|
+
const userParts = msg.content.filter(
|
|
822
|
+
part => this.isTextPart(part) || this.isFilePart(part),
|
|
823
|
+
);
|
|
824
|
+
if (userParts.length === msg.content.length) {
|
|
825
|
+
const userMessage: SDKUserMessage = { role: 'user', content: userParts };
|
|
826
|
+
return userMessage;
|
|
827
|
+
}
|
|
828
|
+
const userMessage: SDKUserMessage = {
|
|
829
|
+
role: 'user',
|
|
830
|
+
content: this.partsToText(msg.content),
|
|
831
|
+
};
|
|
832
|
+
return userMessage;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
if (typeof msg.content === 'string') {
|
|
836
|
+
const assistantMessage: SDKAssistantMessage = {
|
|
837
|
+
role: 'assistant',
|
|
838
|
+
content: msg.content,
|
|
839
|
+
};
|
|
840
|
+
return assistantMessage;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
const assistantParts = msg.content.filter(this.isAssistantPart).map(part => {
|
|
844
|
+
if (part.type === 'tool-call') {
|
|
845
|
+
return { ...part, input: part.input };
|
|
846
|
+
}
|
|
847
|
+
return part;
|
|
848
|
+
});
|
|
849
|
+
|
|
850
|
+
const assistantMessage: SDKAssistantMessage = {
|
|
851
|
+
role: 'assistant',
|
|
852
|
+
content: assistantParts.length > 0 ? assistantParts : '',
|
|
853
|
+
};
|
|
854
|
+
return assistantMessage;
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
private normalizeToolContent(
|
|
859
|
+
parts: MessagePart[],
|
|
860
|
+
): Array<ToolResultPart | SDKToolApprovalResponse> {
|
|
861
|
+
const toolContent = parts.filter(
|
|
862
|
+
(part): part is ToolResultPart | SDKToolApprovalResponse =>
|
|
863
|
+
part.type === 'tool-result' || part.type === 'tool-approval-response',
|
|
864
|
+
);
|
|
865
|
+
if (toolContent.length === parts.length && toolContent.length > 0) {
|
|
866
|
+
return toolContent.map(part => {
|
|
867
|
+
if (part.type !== 'tool-result') {
|
|
868
|
+
return part;
|
|
869
|
+
}
|
|
870
|
+
return {
|
|
871
|
+
...part,
|
|
872
|
+
output: this.toToolOutput(part.output),
|
|
873
|
+
};
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
const textValue = parts
|
|
878
|
+
.filter((part): part is TextPart => part.type === 'text')
|
|
879
|
+
.map(part => part.text)
|
|
880
|
+
.join('\n');
|
|
881
|
+
return [
|
|
882
|
+
{
|
|
883
|
+
type: 'tool-result',
|
|
884
|
+
toolCallId: 'unknown',
|
|
885
|
+
toolName: 'unknown',
|
|
886
|
+
output: this.toToolOutput(textValue || ''),
|
|
887
|
+
},
|
|
888
|
+
];
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
private toToolOutput(value: unknown): ToolResultPart['output'] {
|
|
892
|
+
if (value && typeof value === 'object' && 'type' in value) {
|
|
893
|
+
const output = value as ToolResultPart['output'];
|
|
894
|
+
if (typeof output.type === 'string') {
|
|
895
|
+
return output;
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
if (value instanceof Error) {
|
|
899
|
+
return { type: 'error-text', value: value.message };
|
|
900
|
+
}
|
|
901
|
+
if (typeof value === 'string') {
|
|
902
|
+
return { type: 'text', value };
|
|
903
|
+
}
|
|
904
|
+
if (value === undefined) {
|
|
905
|
+
return { type: 'json', value: null };
|
|
906
|
+
}
|
|
907
|
+
if (this.isJsonValue(value)) {
|
|
908
|
+
return { type: 'json', value };
|
|
909
|
+
}
|
|
910
|
+
const serialized = JSON.stringify(value);
|
|
911
|
+
return { type: 'text', value: serialized ?? String(value) };
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
private convertToolsToSDK(tools: Record<string, ToolDefinition>): SDKToolSet {
|
|
915
|
+
const sdkTools: SDKToolSet = {};
|
|
916
|
+
|
|
917
|
+
for (const [name, toolDef] of Object.entries(tools)) {
|
|
918
|
+
// Create placeholder tools for SDK - actual execution happens manually
|
|
919
|
+
// with proper ToolExecutionContext after we get toolCallId from result
|
|
920
|
+
const inputSchema = toolDef.inputSchema as SDKFlexibleSchema;
|
|
921
|
+
sdkTools[name] = tool<unknown, { placeholder: boolean }>({
|
|
922
|
+
description: toolDef.description,
|
|
923
|
+
inputSchema,
|
|
924
|
+
execute: async (input, options) => {
|
|
925
|
+
// Placeholder - actual execution happens manually in executeStep
|
|
926
|
+
// This allows SDK to decide which tools to call, but we control execution
|
|
927
|
+
void input;
|
|
928
|
+
void options;
|
|
929
|
+
return { placeholder: true };
|
|
930
|
+
},
|
|
931
|
+
});
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
return sdkTools;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
private convertToolChoiceToSDK(
|
|
938
|
+
toolChoice: ToolChoice,
|
|
939
|
+
): 'auto' | 'required' | 'none' | { type: 'tool'; toolName: string } {
|
|
940
|
+
if (toolChoice === 'auto' || toolChoice === 'required' || toolChoice === 'none') {
|
|
941
|
+
return toolChoice;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
if (typeof toolChoice === 'object' && toolChoice.type === 'tool') {
|
|
945
|
+
return { type: 'tool', toolName: toolChoice.toolName };
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
return 'auto';
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
// -----------------------------------------------------------------------------
|
|
953
|
+
// Type Inference Helpers
|
|
954
|
+
// -----------------------------------------------------------------------------
|
|
955
|
+
|
|
956
|
+
/**
|
|
957
|
+
* Infer UI message type from agent definition.
|
|
958
|
+
*
|
|
959
|
+
* @example
|
|
960
|
+
* ```typescript
|
|
961
|
+
* const agent = new ExperimentalAgent({
|
|
962
|
+
* model: openai('gpt-4o'),
|
|
963
|
+
* tools: { search, analyze },
|
|
964
|
+
* });
|
|
965
|
+
*
|
|
966
|
+
* type MyUIMessage = InferAgentUIMessage<typeof agent>;
|
|
967
|
+
* // MyUIMessage includes tool call types for 'search' and 'analyze'
|
|
968
|
+
* ```
|
|
969
|
+
*/
|
|
970
|
+
export type InferAgentUIMessage<TAgent extends ExperimentalAgent<Record<string, ToolDefinition>>> =
|
|
971
|
+
TAgent extends ExperimentalAgent<infer TTools>
|
|
972
|
+
? {
|
|
973
|
+
id: string;
|
|
974
|
+
role: CoreMessageRole;
|
|
975
|
+
content: string;
|
|
976
|
+
toolInvocations?: Array<{
|
|
977
|
+
toolCallId: string;
|
|
978
|
+
toolName: keyof TTools;
|
|
979
|
+
state: 'pending' | 'running' | 'completed' | 'failed';
|
|
980
|
+
input: unknown;
|
|
981
|
+
output?: unknown;
|
|
982
|
+
}>;
|
|
983
|
+
}
|
|
984
|
+
: never;
|
|
985
|
+
|
|
986
|
+
/**
|
|
987
|
+
* Infer tool types from agent.
|
|
988
|
+
*/
|
|
989
|
+
export type InferAgentTools<TAgent extends ExperimentalAgent<Record<string, ToolDefinition>>> =
|
|
990
|
+
TAgent extends ExperimentalAgent<infer TTools> ? TTools : never;
|
|
991
|
+
|
|
992
|
+
// -----------------------------------------------------------------------------
|
|
993
|
+
// Factory Functions
|
|
994
|
+
// -----------------------------------------------------------------------------
|
|
995
|
+
|
|
996
|
+
/**
|
|
997
|
+
* Create an experimental agent with simplified configuration.
|
|
998
|
+
*
|
|
999
|
+
* @example
|
|
1000
|
+
* ```typescript
|
|
1001
|
+
* const agent = createExperimentalAgent({
|
|
1002
|
+
* model: openai('gpt-4o'),
|
|
1003
|
+
* system: 'You are helpful.',
|
|
1004
|
+
* tools: { search, analyze },
|
|
1005
|
+
* });
|
|
1006
|
+
* ```
|
|
1007
|
+
*/
|
|
1008
|
+
export function createExperimentalAgent<TTools extends Record<string, ToolDefinition>>(
|
|
1009
|
+
config: ExperimentalAgentConfig<TTools>,
|
|
1010
|
+
): ExperimentalAgent<TTools> {
|
|
1011
|
+
return new ExperimentalAgent(config);
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
/**
|
|
1015
|
+
* Create a prepareStep hook for model escalation.
|
|
1016
|
+
*
|
|
1017
|
+
* @example
|
|
1018
|
+
* ```typescript
|
|
1019
|
+
* const prepareStep = createModelEscalation({
|
|
1020
|
+
* defaultModel: openai('gpt-4o-mini'),
|
|
1021
|
+
* escalateAfterStep: 5,
|
|
1022
|
+
* escalatedModel: openai('gpt-4o'),
|
|
1023
|
+
* trimMessagesTo: 10,
|
|
1024
|
+
* });
|
|
1025
|
+
* ```
|
|
1026
|
+
*/
|
|
1027
|
+
export function createModelEscalation(options: {
|
|
1028
|
+
defaultModel: ModelRef;
|
|
1029
|
+
escalateAfterStep: number;
|
|
1030
|
+
escalatedModel: ModelRef;
|
|
1031
|
+
trimMessagesTo?: number;
|
|
1032
|
+
}): (input: PrepareStepInput) => PrepareStepOutput {
|
|
1033
|
+
const { defaultModel, escalateAfterStep, escalatedModel, trimMessagesTo } = options;
|
|
1034
|
+
|
|
1035
|
+
return ({ stepNumber, messages }) => {
|
|
1036
|
+
const model = stepNumber >= escalateAfterStep ? escalatedModel : defaultModel;
|
|
1037
|
+
const trimmedMessages = trimMessagesTo ? messages.slice(-trimMessagesTo) : messages;
|
|
1038
|
+
|
|
1039
|
+
return {
|
|
1040
|
+
model,
|
|
1041
|
+
messages: trimmedMessages,
|
|
1042
|
+
};
|
|
1043
|
+
};
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
/**
|
|
1047
|
+
* Create a prepareStep hook for phased tool availability.
|
|
1048
|
+
*
|
|
1049
|
+
* @example
|
|
1050
|
+
* ```typescript
|
|
1051
|
+
* const prepareStep = createPhasedTools({
|
|
1052
|
+
* phases: [
|
|
1053
|
+
* { steps: [1, 2, 3], activeTools: ['search'], toolChoice: 'required' },
|
|
1054
|
+
* { steps: [4, 5, 6], activeTools: ['analyze'], toolChoice: 'required' },
|
|
1055
|
+
* { steps: [7, 8, 9, 10], activeTools: ['summarize', 'report'], toolChoice: 'auto' },
|
|
1056
|
+
* ],
|
|
1057
|
+
* });
|
|
1058
|
+
* ```
|
|
1059
|
+
*/
|
|
1060
|
+
export function createPhasedTools(options: {
|
|
1061
|
+
phases: Array<{
|
|
1062
|
+
steps: number[];
|
|
1063
|
+
activeTools: string[];
|
|
1064
|
+
toolChoice?: ToolChoice;
|
|
1065
|
+
}>;
|
|
1066
|
+
}): (input: PrepareStepInput) => PrepareStepOutput {
|
|
1067
|
+
return ({ stepNumber }) => {
|
|
1068
|
+
for (const phase of options.phases) {
|
|
1069
|
+
if (phase.steps.includes(stepNumber)) {
|
|
1070
|
+
return {
|
|
1071
|
+
activeTools: phase.activeTools,
|
|
1072
|
+
toolChoice: phase.toolChoice,
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
return {};
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
// -----------------------------------------------------------------------------
|
|
1081
|
+
// Utilities
|
|
1082
|
+
// -----------------------------------------------------------------------------
|
|
1083
|
+
|
|
1084
|
+
function isAsyncIterable(value: unknown): value is AsyncIterable<unknown> {
|
|
1085
|
+
return (
|
|
1086
|
+
value != null && typeof (value as AsyncIterable<unknown>)[Symbol.asyncIterator] === 'function'
|
|
1087
|
+
);
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
// -----------------------------------------------------------------------------
|
|
1091
|
+
// Re-exports
|
|
1092
|
+
// -----------------------------------------------------------------------------
|
|
1093
|
+
|
|
1094
|
+
export { generateId, getModelId };
|
|
1095
|
+
export type { MessageRole, CoreMessageRole, StepFinishReason, AgentFinishReason };
|