@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,985 @@
|
|
|
1
|
+
import { $ as generateObject, Mt as streamObject, l as NoObjectGeneratedError, u as Output } from "./ai-runtime-CDzQztTt.mjs";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { logInfo, logWarn } from "@od-oneapp/shared/logs";
|
|
4
|
+
|
|
5
|
+
//#region src/output/factories.ts
|
|
6
|
+
/**
|
|
7
|
+
* @fileoverview Output API factories for structured output generation.
|
|
8
|
+
* @module @od-oneapp/ai-platform/output
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Creates a typed object output configuration.
|
|
12
|
+
*
|
|
13
|
+
* @param schema - Zod schema for the output
|
|
14
|
+
* @returns Output configuration for use with streamText/generateText
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const PersonOutput = createObjectOutput(z.object({
|
|
19
|
+
* name: z.string(),
|
|
20
|
+
* age: z.number(),
|
|
21
|
+
* }));
|
|
22
|
+
*
|
|
23
|
+
* const result = await streamText({
|
|
24
|
+
* model,
|
|
25
|
+
* prompt: 'Extract person info',
|
|
26
|
+
* output: PersonOutput,
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function createObjectOutput(schema) {
|
|
31
|
+
return Output.object({ schema });
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates a typed array output configuration with element streaming.
|
|
35
|
+
*
|
|
36
|
+
* @param schema - Zod schema for array elements
|
|
37
|
+
* @returns Output configuration for array streaming
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const TodosOutput = createArrayOutput(z.object({
|
|
42
|
+
* task: z.string(),
|
|
43
|
+
* done: z.boolean(),
|
|
44
|
+
* }));
|
|
45
|
+
*
|
|
46
|
+
* const result = await streamText({
|
|
47
|
+
* model,
|
|
48
|
+
* prompt: 'List todos',
|
|
49
|
+
* output: TodosOutput,
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* // Stream individual elements
|
|
53
|
+
* for await (const todo of result.output.elementStream) {
|
|
54
|
+
* console.log('Got todo:', todo);
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
function createArrayOutput(schema) {
|
|
59
|
+
return Output.array({ element: schema });
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Creates a choice output for classification tasks using Zod enum.
|
|
63
|
+
*
|
|
64
|
+
* @param values - Array of valid choices
|
|
65
|
+
* @returns Zod enum schema for use with generateObject
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* const SentimentSchema = createChoiceSchema(['positive', 'negative', 'neutral'] as const);
|
|
70
|
+
*
|
|
71
|
+
* const { object } = await generateObject({
|
|
72
|
+
* model,
|
|
73
|
+
* schema: z.object({ sentiment: SentimentSchema }),
|
|
74
|
+
* prompt: 'Classify sentiment: "I love this!"',
|
|
75
|
+
* });
|
|
76
|
+
* // object.sentiment === 'positive'
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
function createChoiceSchema(values) {
|
|
80
|
+
return z.enum(values);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Structured output helper that generates a single object.
|
|
84
|
+
*
|
|
85
|
+
* @param model - Language model to use
|
|
86
|
+
* @param schema - Zod schema for output
|
|
87
|
+
* @param prompt - Generation prompt
|
|
88
|
+
* @returns Generated object matching schema
|
|
89
|
+
*/
|
|
90
|
+
async function generateStructuredObject(model, schema, prompt) {
|
|
91
|
+
const { object } = await generateObject({
|
|
92
|
+
model,
|
|
93
|
+
schema,
|
|
94
|
+
prompt
|
|
95
|
+
});
|
|
96
|
+
return object;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Structured output helper that streams an object.
|
|
100
|
+
*
|
|
101
|
+
* @param model - Language model to use
|
|
102
|
+
* @param schema - Zod schema for output
|
|
103
|
+
* @param prompt - Generation prompt
|
|
104
|
+
* @returns Stream result with partial object stream
|
|
105
|
+
*/
|
|
106
|
+
function streamStructuredObject(model, schema, prompt) {
|
|
107
|
+
return streamObject({
|
|
108
|
+
model,
|
|
109
|
+
schema,
|
|
110
|
+
prompt
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Schema builder utilities for common patterns.
|
|
115
|
+
*/
|
|
116
|
+
const SchemaBuilders = {
|
|
117
|
+
listWithMeta(itemSchema) {
|
|
118
|
+
return z.object({
|
|
119
|
+
items: z.array(itemSchema),
|
|
120
|
+
total: z.number(),
|
|
121
|
+
hasMore: z.boolean().optional()
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
resultOrError(successSchema) {
|
|
125
|
+
return z.discriminatedUnion("success", [z.object({
|
|
126
|
+
success: z.literal(true),
|
|
127
|
+
data: successSchema
|
|
128
|
+
}), z.object({
|
|
129
|
+
success: z.literal(false),
|
|
130
|
+
error: z.string()
|
|
131
|
+
})]);
|
|
132
|
+
},
|
|
133
|
+
classificationWithConfidence(categories) {
|
|
134
|
+
return z.object({
|
|
135
|
+
category: z.enum(categories),
|
|
136
|
+
confidence: z.number().min(0).max(1),
|
|
137
|
+
reasoning: z.string().optional()
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
entities(entitySchemas) {
|
|
141
|
+
return z.object({
|
|
142
|
+
entities: z.object(entitySchemas),
|
|
143
|
+
raw: z.string().optional()
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
plan() {
|
|
147
|
+
return z.object({
|
|
148
|
+
steps: z.array(z.object({
|
|
149
|
+
step: z.number(),
|
|
150
|
+
action: z.string(),
|
|
151
|
+
reasoning: z.string().optional(),
|
|
152
|
+
dependencies: z.array(z.number()).optional()
|
|
153
|
+
})),
|
|
154
|
+
summary: z.string()
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* Safe structured object generation with NoObjectGeneratedError handling.
|
|
160
|
+
* Returns a result object instead of throwing.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const result = await safeGenerateObject({
|
|
165
|
+
* model,
|
|
166
|
+
* schema: z.object({ name: z.string() }),
|
|
167
|
+
* prompt: 'Extract name from: Hello!',
|
|
168
|
+
* });
|
|
169
|
+
*
|
|
170
|
+
* if (result.success) {
|
|
171
|
+
* console.log(result.object.name);
|
|
172
|
+
* } else {
|
|
173
|
+
* console.log('Failed:', result.error?.message);
|
|
174
|
+
* console.log('Raw text:', result.text);
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
async function safeGenerateObject(options) {
|
|
179
|
+
try {
|
|
180
|
+
const { object, usage } = await generateObject(options);
|
|
181
|
+
const usageRecord = usage ?? {};
|
|
182
|
+
return {
|
|
183
|
+
success: true,
|
|
184
|
+
object,
|
|
185
|
+
usage: {
|
|
186
|
+
promptTokens: usageRecord.promptTokens ?? 0,
|
|
187
|
+
completionTokens: usageRecord.completionTokens ?? 0,
|
|
188
|
+
totalTokens: usageRecord.totalTokens ?? 0
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
} catch (error) {
|
|
192
|
+
if (error instanceof NoObjectGeneratedError) {
|
|
193
|
+
logWarn(`[safeGenerateObject] No object generated: ${error.message}`);
|
|
194
|
+
const errorUsage = error.usage;
|
|
195
|
+
const possiblePartial = error.partialObject;
|
|
196
|
+
const partialObject = typeof possiblePartial === "object" && possiblePartial !== null ? possiblePartial : extractPartialFromError(error) ?? void 0;
|
|
197
|
+
return {
|
|
198
|
+
success: false,
|
|
199
|
+
error,
|
|
200
|
+
text: error.text,
|
|
201
|
+
partialObject,
|
|
202
|
+
usage: errorUsage ? {
|
|
203
|
+
promptTokens: errorUsage.promptTokens ?? 0,
|
|
204
|
+
completionTokens: errorUsage.completionTokens ?? 0,
|
|
205
|
+
totalTokens: errorUsage.totalTokens ?? 0
|
|
206
|
+
} : void 0
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
success: false,
|
|
211
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Generate object with fallback value on failure.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* const person = await generateObjectWithFallback({
|
|
221
|
+
* model,
|
|
222
|
+
* schema: z.object({ name: z.string(), age: z.number() }),
|
|
223
|
+
* prompt: 'Extract person info',
|
|
224
|
+
* fallback: { name: 'Unknown', age: 0 },
|
|
225
|
+
* });
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
async function generateObjectWithFallback(options) {
|
|
229
|
+
const { fallback, ...generateOptions } = options;
|
|
230
|
+
const result = await safeGenerateObject(generateOptions);
|
|
231
|
+
if (result.success && result.object !== void 0) return result.object;
|
|
232
|
+
logWarn(`[generateObjectWithFallback] Using fallback value`);
|
|
233
|
+
return fallback;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Generate object with retry on failure.
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```typescript
|
|
240
|
+
* const person = await generateObjectWithRetry({
|
|
241
|
+
* model,
|
|
242
|
+
* schema: z.object({ name: z.string() }),
|
|
243
|
+
* prompt: 'Extract name',
|
|
244
|
+
* maxRetries: 3,
|
|
245
|
+
* onRetry: (attempt, error) => console.log(`Retry ${attempt}:`, error.message),
|
|
246
|
+
* });
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
async function generateObjectWithRetry(options) {
|
|
250
|
+
const { maxRetries = 3, retryDelay = 1e3, onRetry, ...generateOptions } = options;
|
|
251
|
+
let lastError;
|
|
252
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
253
|
+
const result = await safeGenerateObject(generateOptions);
|
|
254
|
+
if (result.success && result.object !== void 0) return result.object;
|
|
255
|
+
lastError = result.error ?? /* @__PURE__ */ new Error("Unknown error");
|
|
256
|
+
if (attempt < maxRetries) {
|
|
257
|
+
onRetry?.(attempt + 1, lastError);
|
|
258
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay * (attempt + 1)));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
throw lastError ?? /* @__PURE__ */ new Error("Failed to generate object after retries");
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Extract partial data from NoObjectGeneratedError.
|
|
265
|
+
* Attempts to parse partial JSON from the raw text.
|
|
266
|
+
*/
|
|
267
|
+
function extractPartialFromError(error) {
|
|
268
|
+
const { text } = error;
|
|
269
|
+
if (!text) return null;
|
|
270
|
+
const jsonMatch = text.match(/\{[\s\S]*\}/);
|
|
271
|
+
if (!jsonMatch) return null;
|
|
272
|
+
try {
|
|
273
|
+
return JSON.parse(jsonMatch[0]);
|
|
274
|
+
} catch {
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/output/element-stream.ts
|
|
281
|
+
/**
|
|
282
|
+
* Element Stream Module
|
|
283
|
+
*
|
|
284
|
+
* SDK v6 pattern for streaming array elements in real-time.
|
|
285
|
+
* Uses streamObject with output: 'array' and elementStream for
|
|
286
|
+
* progressive rendering of list items.
|
|
287
|
+
*
|
|
288
|
+
* @module output/element-stream
|
|
289
|
+
*/
|
|
290
|
+
/**
|
|
291
|
+
* Stream array elements in real-time using SDK v6 elementStream pattern.
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```typescript
|
|
295
|
+
* const taskSchema = z.object({
|
|
296
|
+
* title: z.string(),
|
|
297
|
+
* priority: z.enum(['low', 'medium', 'high']),
|
|
298
|
+
* estimate: z.string(),
|
|
299
|
+
* });
|
|
300
|
+
*
|
|
301
|
+
* const { stream, elements } = streamElements({
|
|
302
|
+
* model: anthropic('claude-sonnet'),
|
|
303
|
+
* elementSchema: taskSchema,
|
|
304
|
+
* prompt: 'Break down building a web app into tasks',
|
|
305
|
+
* onElement: (task, index) => {
|
|
306
|
+
* console.log(`Task ${index + 1}: ${task.title}`);
|
|
307
|
+
* },
|
|
308
|
+
* });
|
|
309
|
+
*
|
|
310
|
+
* // Or iterate over the stream
|
|
311
|
+
* for await (const event of stream) {
|
|
312
|
+
* if (event.type === 'element' && event.isComplete) {
|
|
313
|
+
* renderTask(event.element);
|
|
314
|
+
* }
|
|
315
|
+
* }
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
function streamElements(options) {
|
|
319
|
+
const { model, elementSchema, system, prompt, abortSignal, maxTokens, temperature, onPartialElement, onElement, onError, onComplete } = options;
|
|
320
|
+
let resolveElements;
|
|
321
|
+
let rejectElements;
|
|
322
|
+
let resolveUsage;
|
|
323
|
+
let rejectUsage;
|
|
324
|
+
const elementsPromise = new Promise((resolve, reject) => {
|
|
325
|
+
resolveElements = resolve;
|
|
326
|
+
rejectElements = reject;
|
|
327
|
+
});
|
|
328
|
+
const usagePromise = new Promise((resolve, reject) => {
|
|
329
|
+
resolveUsage = resolve;
|
|
330
|
+
rejectUsage = reject;
|
|
331
|
+
});
|
|
332
|
+
async function* createStream() {
|
|
333
|
+
const allElements = [];
|
|
334
|
+
try {
|
|
335
|
+
const result = streamObject({
|
|
336
|
+
model,
|
|
337
|
+
output: "array",
|
|
338
|
+
schema: elementSchema,
|
|
339
|
+
system,
|
|
340
|
+
prompt,
|
|
341
|
+
abortSignal,
|
|
342
|
+
temperature
|
|
343
|
+
});
|
|
344
|
+
let currentIndex = 0;
|
|
345
|
+
for await (const element of result.elementStream) {
|
|
346
|
+
allElements.push(element);
|
|
347
|
+
onElement?.(element, currentIndex);
|
|
348
|
+
yield {
|
|
349
|
+
type: "element",
|
|
350
|
+
index: currentIndex,
|
|
351
|
+
element,
|
|
352
|
+
isComplete: true,
|
|
353
|
+
totalElements: allElements.length
|
|
354
|
+
};
|
|
355
|
+
currentIndex++;
|
|
356
|
+
}
|
|
357
|
+
const usageObj = await result.usage;
|
|
358
|
+
resolveUsage({
|
|
359
|
+
promptTokens: usageObj.promptTokens ?? 0,
|
|
360
|
+
completionTokens: usageObj.completionTokens ?? 0,
|
|
361
|
+
totalTokens: usageObj.totalTokens ?? 0
|
|
362
|
+
});
|
|
363
|
+
onComplete?.(allElements);
|
|
364
|
+
resolveElements(allElements);
|
|
365
|
+
yield {
|
|
366
|
+
type: "complete",
|
|
367
|
+
totalElements: allElements.length
|
|
368
|
+
};
|
|
369
|
+
} catch (error) {
|
|
370
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
371
|
+
onError?.(err);
|
|
372
|
+
rejectElements(err);
|
|
373
|
+
rejectUsage(err);
|
|
374
|
+
yield {
|
|
375
|
+
type: "error",
|
|
376
|
+
error: err,
|
|
377
|
+
totalElements: allElements.length
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return {
|
|
382
|
+
stream: createStream(),
|
|
383
|
+
elements: elementsPromise,
|
|
384
|
+
usage: usagePromise
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Stream array elements with partial progress updates.
|
|
389
|
+
* Useful for showing "typing" indicators for each element.
|
|
390
|
+
*
|
|
391
|
+
* @example
|
|
392
|
+
* ```typescript
|
|
393
|
+
* const { stream } = streamElementsWithProgress({
|
|
394
|
+
* model,
|
|
395
|
+
* elementSchema: taskSchema,
|
|
396
|
+
* prompt: 'Generate 5 tasks',
|
|
397
|
+
* updateInterval: 100,
|
|
398
|
+
* });
|
|
399
|
+
*
|
|
400
|
+
* for await (const event of stream) {
|
|
401
|
+
* if (event.type === 'partial') {
|
|
402
|
+
* // Show partial element with loading indicator
|
|
403
|
+
* updateUI(event.element, { loading: true });
|
|
404
|
+
* } else if (event.type === 'element') {
|
|
405
|
+
* // Show complete element
|
|
406
|
+
* updateUI(event.element, { loading: false });
|
|
407
|
+
* }
|
|
408
|
+
* }
|
|
409
|
+
* ```
|
|
410
|
+
*/
|
|
411
|
+
function streamElementsWithProgress(options) {
|
|
412
|
+
const { updateInterval = 50, onPartialElement, ...rest } = options;
|
|
413
|
+
const baseResult = streamElements(rest);
|
|
414
|
+
async function* createPartialStream() {
|
|
415
|
+
for await (const event of baseResult.stream) if (event.type === "element") yield {
|
|
416
|
+
type: "element",
|
|
417
|
+
index: event.index,
|
|
418
|
+
element: event.element,
|
|
419
|
+
isComplete: true,
|
|
420
|
+
totalElements: event.totalElements
|
|
421
|
+
};
|
|
422
|
+
else yield event;
|
|
423
|
+
}
|
|
424
|
+
return {
|
|
425
|
+
...baseResult,
|
|
426
|
+
partialStream: createPartialStream()
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Stream elements in batches for better performance.
|
|
431
|
+
*
|
|
432
|
+
* @example
|
|
433
|
+
* ```typescript
|
|
434
|
+
* const { batches } = streamElementsInBatches({
|
|
435
|
+
* model,
|
|
436
|
+
* elementSchema: taskSchema,
|
|
437
|
+
* prompt: 'Generate 20 tasks',
|
|
438
|
+
* batchSize: 5,
|
|
439
|
+
* batchTimeout: 1000,
|
|
440
|
+
* });
|
|
441
|
+
*
|
|
442
|
+
* for await (const batch of batches) {
|
|
443
|
+
* // Process 5 elements at once
|
|
444
|
+
* renderTaskBatch(batch);
|
|
445
|
+
* }
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
function streamElementsInBatches(options) {
|
|
449
|
+
const { batchSize, batchTimeout = 1e3, ...rest } = options;
|
|
450
|
+
const baseResult = streamElements(rest);
|
|
451
|
+
async function* createBatchStream() {
|
|
452
|
+
let batch = [];
|
|
453
|
+
let timeoutId = null;
|
|
454
|
+
const flushBatch = () => {
|
|
455
|
+
if (batch.length === 0) return null;
|
|
456
|
+
const result = [...batch];
|
|
457
|
+
batch = [];
|
|
458
|
+
if (timeoutId) {
|
|
459
|
+
clearTimeout(timeoutId);
|
|
460
|
+
timeoutId = null;
|
|
461
|
+
}
|
|
462
|
+
return result;
|
|
463
|
+
};
|
|
464
|
+
for await (const event of baseResult.stream) if (event.type === "element" && event.element) {
|
|
465
|
+
batch.push(event.element);
|
|
466
|
+
if (batch.length >= batchSize) {
|
|
467
|
+
const flushed = flushBatch();
|
|
468
|
+
if (flushed) yield flushed;
|
|
469
|
+
} else if (!timeoutId) timeoutId = setTimeout(() => {
|
|
470
|
+
timeoutId = null;
|
|
471
|
+
}, batchTimeout);
|
|
472
|
+
} else if (event.type === "complete") {
|
|
473
|
+
const flushed = flushBatch();
|
|
474
|
+
if (flushed) yield flushed;
|
|
475
|
+
}
|
|
476
|
+
const final = flushBatch();
|
|
477
|
+
if (final) yield final;
|
|
478
|
+
}
|
|
479
|
+
return {
|
|
480
|
+
...baseResult,
|
|
481
|
+
batches: createBatchStream()
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Create an element streamer for a specific schema.
|
|
486
|
+
* Useful for reusing the same schema across multiple prompts.
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
* ```typescript
|
|
490
|
+
* const streamTasks = createElementStreamer({
|
|
491
|
+
* model: anthropic('claude-sonnet'),
|
|
492
|
+
* elementSchema: taskSchema,
|
|
493
|
+
* });
|
|
494
|
+
*
|
|
495
|
+
* // Use multiple times
|
|
496
|
+
* const webAppTasks = await streamTasks('Break down building a web app');
|
|
497
|
+
* const apiTasks = await streamTasks('Break down building an API');
|
|
498
|
+
* ```
|
|
499
|
+
*/
|
|
500
|
+
function createElementStreamer(config) {
|
|
501
|
+
return async function stream(prompt, options) {
|
|
502
|
+
return collectElements({
|
|
503
|
+
...config,
|
|
504
|
+
prompt,
|
|
505
|
+
...options
|
|
506
|
+
});
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Create a collected element stream that returns all elements at once.
|
|
511
|
+
* Simpler API when you don't need real-time updates.
|
|
512
|
+
*
|
|
513
|
+
* @example
|
|
514
|
+
* ```typescript
|
|
515
|
+
* const tasks = await collectElements({
|
|
516
|
+
* model,
|
|
517
|
+
* elementSchema: taskSchema,
|
|
518
|
+
* prompt: 'Generate 5 tasks',
|
|
519
|
+
* });
|
|
520
|
+
*
|
|
521
|
+
* console.log(`Got ${tasks.length} tasks`);
|
|
522
|
+
* ```
|
|
523
|
+
*/
|
|
524
|
+
async function collectElements(options) {
|
|
525
|
+
const { stream, elements } = streamElements(options);
|
|
526
|
+
for await (const _ of stream);
|
|
527
|
+
return elements;
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Composable wrapper for streaming array elements from experimental_output.
|
|
531
|
+
*
|
|
532
|
+
* This wraps a streamText result that uses experimental_output with Output.array(),
|
|
533
|
+
* providing callbacks, transformations, and buffering capabilities.
|
|
534
|
+
*
|
|
535
|
+
* @param streamResult - Result from streamText with experimental_output
|
|
536
|
+
* @param config - Configuration for element streaming
|
|
537
|
+
* @returns Async generator yielding elements (potentially transformed/buffered)
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* ```typescript
|
|
541
|
+
* import { streamText, Output } from 'ai';
|
|
542
|
+
* import { withElementStream } from '@od-oneapp/ai-platform/output';
|
|
543
|
+
* import { z } from 'zod';
|
|
544
|
+
*
|
|
545
|
+
* const TodoSchema = z.object({
|
|
546
|
+
* task: z.string(),
|
|
547
|
+
* priority: z.enum(['low', 'medium', 'high']),
|
|
548
|
+
* });
|
|
549
|
+
*
|
|
550
|
+
* const result = streamText({
|
|
551
|
+
* model,
|
|
552
|
+
* prompt: 'List 10 todos',
|
|
553
|
+
* experimental_output: Output.array({ element: TodoSchema }),
|
|
554
|
+
* });
|
|
555
|
+
*
|
|
556
|
+
* // Basic iteration with callback
|
|
557
|
+
* const todos: z.infer<typeof TodoSchema>[] = [];
|
|
558
|
+
* for await (const todo of withElementStream(result, {
|
|
559
|
+
* onElement: (t, i) => console.log(`Got todo ${i}: ${t.task}`),
|
|
560
|
+
* })) {
|
|
561
|
+
* todos.push(todo);
|
|
562
|
+
* }
|
|
563
|
+
*
|
|
564
|
+
* // With transformation
|
|
565
|
+
* for await (const todo of withElementStream(result, {
|
|
566
|
+
* transform: (t) => ({ ...t, task: t.task.toUpperCase() }),
|
|
567
|
+
* })) {
|
|
568
|
+
* console.log(todo.task); // UPPERCASE
|
|
569
|
+
* }
|
|
570
|
+
*
|
|
571
|
+
* // With buffering (yields in batches)
|
|
572
|
+
* for await (const todoBatch of withElementStream(result, {
|
|
573
|
+
* bufferSize: 5,
|
|
574
|
+
* onElement: (t, i) => console.log(`Buffered todo ${i}`),
|
|
575
|
+
* })) {
|
|
576
|
+
* // todoBatch is an array of 5 todos (or fewer at the end)
|
|
577
|
+
* processBatch(todoBatch);
|
|
578
|
+
* }
|
|
579
|
+
* ```
|
|
580
|
+
*/
|
|
581
|
+
async function* withElementStream(streamResult, config) {
|
|
582
|
+
const { onElement, bufferSize, transform, onComplete, onError } = config ?? {};
|
|
583
|
+
const elementStream = streamResult.experimental_output?.elementStream;
|
|
584
|
+
if (!elementStream) {
|
|
585
|
+
const objectPromise = streamResult.experimental_output?.object;
|
|
586
|
+
if (objectPromise) try {
|
|
587
|
+
const elements = await objectPromise;
|
|
588
|
+
let index = 0;
|
|
589
|
+
if (bufferSize && bufferSize > 1) {
|
|
590
|
+
let buffer = [];
|
|
591
|
+
for (const element of elements) {
|
|
592
|
+
const transformed = transform ? transform(element) : element;
|
|
593
|
+
onElement?.(transformed, index);
|
|
594
|
+
buffer.push(transformed);
|
|
595
|
+
index++;
|
|
596
|
+
if (buffer.length >= bufferSize) {
|
|
597
|
+
yield buffer;
|
|
598
|
+
buffer = [];
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
if (buffer.length > 0) yield buffer;
|
|
602
|
+
} else for (const element of elements) {
|
|
603
|
+
const transformed = transform ? transform(element) : element;
|
|
604
|
+
onElement?.(transformed, index);
|
|
605
|
+
yield transformed;
|
|
606
|
+
index++;
|
|
607
|
+
}
|
|
608
|
+
const finalElements = transform ? elements.map(transform) : elements;
|
|
609
|
+
onComplete?.(finalElements, finalElements.length);
|
|
610
|
+
} catch (error) {
|
|
611
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
612
|
+
onError?.(err);
|
|
613
|
+
throw err;
|
|
614
|
+
}
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
try {
|
|
618
|
+
const allElements = [];
|
|
619
|
+
let index = 0;
|
|
620
|
+
let buffer = [];
|
|
621
|
+
for await (const element of elementStream) {
|
|
622
|
+
const transformed = transform ? transform(element) : element;
|
|
623
|
+
allElements.push(transformed);
|
|
624
|
+
onElement?.(transformed, index);
|
|
625
|
+
index++;
|
|
626
|
+
if (bufferSize && bufferSize > 1) {
|
|
627
|
+
buffer.push(transformed);
|
|
628
|
+
if (buffer.length >= bufferSize) {
|
|
629
|
+
yield buffer;
|
|
630
|
+
buffer = [];
|
|
631
|
+
}
|
|
632
|
+
} else yield transformed;
|
|
633
|
+
}
|
|
634
|
+
if (bufferSize && bufferSize > 1 && buffer.length > 0) yield buffer;
|
|
635
|
+
onComplete?.(allElements, allElements.length);
|
|
636
|
+
} catch (error) {
|
|
637
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
638
|
+
onError?.(err);
|
|
639
|
+
throw err;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Collect all elements from withElementStream into an array.
|
|
644
|
+
* Convenience function for when you want all elements at once.
|
|
645
|
+
*
|
|
646
|
+
* @param streamResult - Result from streamText with experimental_output
|
|
647
|
+
* @param config - Configuration for element streaming
|
|
648
|
+
* @returns Promise resolving to array of all elements
|
|
649
|
+
*
|
|
650
|
+
* @example
|
|
651
|
+
* ```typescript
|
|
652
|
+
* const todos = await collectFromElementStream(result, {
|
|
653
|
+
* onElement: (t, i) => console.log(`Processing ${i}`),
|
|
654
|
+
* transform: (t) => ({ ...t, processed: true }),
|
|
655
|
+
* });
|
|
656
|
+
* ```
|
|
657
|
+
*/
|
|
658
|
+
async function collectFromElementStream(streamResult, config) {
|
|
659
|
+
const elements = [];
|
|
660
|
+
for await (const element of withElementStream(streamResult, config)) elements.push(element);
|
|
661
|
+
return elements;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
//#endregion
|
|
665
|
+
//#region src/output/validator.ts
|
|
666
|
+
/**
|
|
667
|
+
* @fileoverview Output Validator Module
|
|
668
|
+
*
|
|
669
|
+
* Provides schema-based validation for AI model outputs with configurable
|
|
670
|
+
* error handling strategies including throw, partial recovery, and retry.
|
|
671
|
+
*
|
|
672
|
+
* @module @od-oneapp/ai-platform/output/validator
|
|
673
|
+
*
|
|
674
|
+
* @example
|
|
675
|
+
* ```typescript
|
|
676
|
+
* import { createOutputValidator } from '@od-oneapp/ai-platform/output';
|
|
677
|
+
* import { z } from 'zod';
|
|
678
|
+
*
|
|
679
|
+
* const PersonSchema = z.object({
|
|
680
|
+
* name: z.string(),
|
|
681
|
+
* age: z.number(),
|
|
682
|
+
* email: z.string().email(),
|
|
683
|
+
* });
|
|
684
|
+
*
|
|
685
|
+
* // Simple validation with throw strategy
|
|
686
|
+
* const strictValidator = createOutputValidator({
|
|
687
|
+
* schema: PersonSchema,
|
|
688
|
+
* onValidationError: 'throw',
|
|
689
|
+
* });
|
|
690
|
+
*
|
|
691
|
+
* try {
|
|
692
|
+
* const person = strictValidator.validate(rawOutput);
|
|
693
|
+
* } catch (error) {
|
|
694
|
+
* console.error('Validation failed:', error);
|
|
695
|
+
* }
|
|
696
|
+
*
|
|
697
|
+
* // Partial recovery strategy
|
|
698
|
+
* const lenientValidator = createOutputValidator({
|
|
699
|
+
* schema: PersonSchema,
|
|
700
|
+
* onValidationError: 'partial',
|
|
701
|
+
* });
|
|
702
|
+
*
|
|
703
|
+
* const result = lenientValidator.validate(rawOutput);
|
|
704
|
+
* if (result.success) {
|
|
705
|
+
* console.log('Valid:', result.data);
|
|
706
|
+
* } else {
|
|
707
|
+
* console.log('Partial:', result.partial, 'Errors:', result.errors);
|
|
708
|
+
* }
|
|
709
|
+
*
|
|
710
|
+
* // Retry strategy with model
|
|
711
|
+
* const retryValidator = createOutputValidator({
|
|
712
|
+
* schema: PersonSchema,
|
|
713
|
+
* onValidationError: 'retry',
|
|
714
|
+
* maxRetries: 2,
|
|
715
|
+
* });
|
|
716
|
+
*
|
|
717
|
+
* const validated = await retryValidator.validateAsync(rawOutput, {
|
|
718
|
+
* model: openai('gpt-4'),
|
|
719
|
+
* prompt: 'Extract person info from: John, 30 years old',
|
|
720
|
+
* });
|
|
721
|
+
* ```
|
|
722
|
+
*/
|
|
723
|
+
/**
|
|
724
|
+
* Custom error for validation failures with context.
|
|
725
|
+
*/
|
|
726
|
+
var OutputValidationError = class extends Error {
|
|
727
|
+
zodError;
|
|
728
|
+
strategy;
|
|
729
|
+
attempts;
|
|
730
|
+
constructor(message, zodError, strategy, attempts = 1) {
|
|
731
|
+
super(message);
|
|
732
|
+
this.name = "OutputValidationError";
|
|
733
|
+
this.zodError = zodError;
|
|
734
|
+
this.strategy = strategy;
|
|
735
|
+
this.attempts = attempts;
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
/**
|
|
739
|
+
* Extract partial data from validation errors.
|
|
740
|
+
* Attempts to keep valid fields while noting invalid ones.
|
|
741
|
+
*/
|
|
742
|
+
function extractPartialData(output, zodError) {
|
|
743
|
+
if (typeof output !== "object" || output === null) return;
|
|
744
|
+
const result = { ...output };
|
|
745
|
+
const invalidPaths = /* @__PURE__ */ new Set();
|
|
746
|
+
for (const issue of zodError.issues) if (issue.path.length > 0) invalidPaths.add(String(issue.path[0]));
|
|
747
|
+
for (const path of invalidPaths) delete result[path];
|
|
748
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Build error message with custom prefix if provided.
|
|
752
|
+
*/
|
|
753
|
+
function buildErrorMessage(zodError, customPrefix) {
|
|
754
|
+
const issueMessages = zodError.issues.map((issue) => {
|
|
755
|
+
return `${issue.path.length > 0 ? issue.path.join(".") : "root"}: ${issue.message}`;
|
|
756
|
+
}).join("; ");
|
|
757
|
+
return customPrefix ? `${customPrefix}: ${issueMessages}` : `Validation failed: ${issueMessages}`;
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Delay helper for retries.
|
|
761
|
+
*/
|
|
762
|
+
function delay(ms) {
|
|
763
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Create an output validator with configurable error handling.
|
|
767
|
+
*
|
|
768
|
+
* @param config - Validator configuration
|
|
769
|
+
* @returns Output validator instance
|
|
770
|
+
*
|
|
771
|
+
* @example
|
|
772
|
+
* ```typescript
|
|
773
|
+
* // Throw strategy (strict validation)
|
|
774
|
+
* const strictValidator = createOutputValidator({
|
|
775
|
+
* schema: UserSchema,
|
|
776
|
+
* onValidationError: 'throw',
|
|
777
|
+
* });
|
|
778
|
+
*
|
|
779
|
+
* // Partial strategy (lenient validation with error details)
|
|
780
|
+
* const lenientValidator = createOutputValidator({
|
|
781
|
+
* schema: UserSchema,
|
|
782
|
+
* onValidationError: 'partial',
|
|
783
|
+
* });
|
|
784
|
+
*
|
|
785
|
+
* // Retry strategy (regenerate with model on failure)
|
|
786
|
+
* const retryValidator = createOutputValidator({
|
|
787
|
+
* schema: UserSchema,
|
|
788
|
+
* onValidationError: 'retry',
|
|
789
|
+
* maxRetries: 3,
|
|
790
|
+
* retryDelay: 500,
|
|
791
|
+
* });
|
|
792
|
+
* ```
|
|
793
|
+
*/
|
|
794
|
+
function createOutputValidator(config) {
|
|
795
|
+
const { schema, onValidationError, maxRetries = 2, retryDelay = 1e3, errorMessage, onError } = config;
|
|
796
|
+
/**
|
|
797
|
+
* Synchronous validation.
|
|
798
|
+
*/
|
|
799
|
+
function validate(output) {
|
|
800
|
+
const result = schema.safeParse(output);
|
|
801
|
+
if (result.success) return result.data;
|
|
802
|
+
const zodError = result.error;
|
|
803
|
+
onError?.(zodError, 1);
|
|
804
|
+
switch (onValidationError) {
|
|
805
|
+
case "throw": throw new OutputValidationError(buildErrorMessage(zodError, errorMessage), zodError, "throw", 1);
|
|
806
|
+
case "partial": return {
|
|
807
|
+
success: false,
|
|
808
|
+
partial: extractPartialData(output, zodError),
|
|
809
|
+
errors: zodError.issues,
|
|
810
|
+
rawError: zodError
|
|
811
|
+
};
|
|
812
|
+
case "retry": throw new OutputValidationError(`${buildErrorMessage(zodError, errorMessage)} (use validateAsync for retry support)`, zodError, "retry", 1);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Asynchronous validation with retry support.
|
|
817
|
+
*/
|
|
818
|
+
async function validateAsync(output, retryContext) {
|
|
819
|
+
let currentOutput = output;
|
|
820
|
+
let lastError;
|
|
821
|
+
for (let attempt = 1; attempt <= maxRetries + 1; attempt++) {
|
|
822
|
+
const result = schema.safeParse(currentOutput);
|
|
823
|
+
if (result.success) {
|
|
824
|
+
if (attempt > 1) logInfo(`[OutputValidator] Validation succeeded on attempt ${attempt}`);
|
|
825
|
+
return result.data;
|
|
826
|
+
}
|
|
827
|
+
lastError = result.error;
|
|
828
|
+
onError?.(lastError, attempt);
|
|
829
|
+
if (onValidationError === "partial") return {
|
|
830
|
+
success: false,
|
|
831
|
+
partial: extractPartialData(currentOutput, lastError),
|
|
832
|
+
errors: lastError.issues,
|
|
833
|
+
rawError: lastError
|
|
834
|
+
};
|
|
835
|
+
if (onValidationError === "throw") throw new OutputValidationError(buildErrorMessage(lastError, errorMessage), lastError, "throw", attempt);
|
|
836
|
+
if (attempt <= maxRetries) {
|
|
837
|
+
if (!retryContext) throw new OutputValidationError("Retry strategy requires retryContext with model and prompt", lastError, "retry", attempt);
|
|
838
|
+
logWarn(`[OutputValidator] Validation failed on attempt ${attempt}/${maxRetries + 1}. Errors: ${lastError.issues.map((i) => i.message).join(", ")}. Retrying...`);
|
|
839
|
+
await delay(retryDelay * attempt);
|
|
840
|
+
try {
|
|
841
|
+
const { object } = await generateObject({
|
|
842
|
+
model: retryContext.model,
|
|
843
|
+
schema,
|
|
844
|
+
prompt: retryContext.prompt,
|
|
845
|
+
system: retryContext.system,
|
|
846
|
+
temperature: retryContext.temperature
|
|
847
|
+
});
|
|
848
|
+
currentOutput = object;
|
|
849
|
+
} catch (genError) {
|
|
850
|
+
logWarn(`[OutputValidator] Regeneration failed on attempt ${attempt}: ${genError instanceof Error ? genError.message : String(genError)}`);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
if (lastError) throw new OutputValidationError(`${buildErrorMessage(lastError, errorMessage)} (exhausted ${maxRetries + 1} attempts)`, lastError, "retry", maxRetries + 1);
|
|
855
|
+
throw new Error("Validation failed with unknown error");
|
|
856
|
+
}
|
|
857
|
+
return {
|
|
858
|
+
validate,
|
|
859
|
+
validateAsync,
|
|
860
|
+
getSchema: () => schema,
|
|
861
|
+
getStrategy: () => onValidationError
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* Check if an error is an OutputValidationError.
|
|
866
|
+
*
|
|
867
|
+
* @param error - Error to check
|
|
868
|
+
* @returns True if error is OutputValidationError
|
|
869
|
+
*/
|
|
870
|
+
function isOutputValidationError(error) {
|
|
871
|
+
return error instanceof OutputValidationError;
|
|
872
|
+
}
|
|
873
|
+
/**
|
|
874
|
+
* Create a simple validator that always throws on error.
|
|
875
|
+
* Shorthand for createOutputValidator with 'throw' strategy.
|
|
876
|
+
*
|
|
877
|
+
* @param schema - Zod schema for validation
|
|
878
|
+
* @returns Validator function
|
|
879
|
+
*
|
|
880
|
+
* @example
|
|
881
|
+
* ```typescript
|
|
882
|
+
* const validateUser = createStrictValidator(UserSchema);
|
|
883
|
+
* const user = validateUser(rawData); // throws if invalid
|
|
884
|
+
* ```
|
|
885
|
+
*/
|
|
886
|
+
function createStrictValidator(schema) {
|
|
887
|
+
const validator = createOutputValidator({
|
|
888
|
+
schema,
|
|
889
|
+
onValidationError: "throw"
|
|
890
|
+
});
|
|
891
|
+
return (output) => {
|
|
892
|
+
return validator.validate(output);
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* Create a validator that returns partial data on error.
|
|
897
|
+
* Shorthand for createOutputValidator with 'partial' strategy.
|
|
898
|
+
*
|
|
899
|
+
* @param schema - Zod schema for validation
|
|
900
|
+
* @returns Validator function returning PartialValidationResult
|
|
901
|
+
*
|
|
902
|
+
* @example
|
|
903
|
+
* ```typescript
|
|
904
|
+
* const validateUser = createPartialValidator(UserSchema);
|
|
905
|
+
* const result = validateUser(rawData);
|
|
906
|
+
* if (!result.success) {
|
|
907
|
+
* console.log('Partial data:', result.partial);
|
|
908
|
+
* }
|
|
909
|
+
* ```
|
|
910
|
+
*/
|
|
911
|
+
function createPartialValidator(schema) {
|
|
912
|
+
const validator = createOutputValidator({
|
|
913
|
+
schema,
|
|
914
|
+
onValidationError: "partial"
|
|
915
|
+
});
|
|
916
|
+
return (output) => {
|
|
917
|
+
const result = validator.validate(output);
|
|
918
|
+
if (!result || typeof result !== "object" || !("success" in result)) return {
|
|
919
|
+
success: true,
|
|
920
|
+
data: result
|
|
921
|
+
};
|
|
922
|
+
return result;
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
//#endregion
|
|
927
|
+
//#region src/output/errors.ts
|
|
928
|
+
/**
|
|
929
|
+
* NoObjectGeneratedError helpers and recovery strategies.
|
|
930
|
+
*/
|
|
931
|
+
const ErrorRecoveryStrategies = {
|
|
932
|
+
fallback: (fallback) => ({ fallback }),
|
|
933
|
+
ignore: () => ({})
|
|
934
|
+
};
|
|
935
|
+
function isNoObjectGeneratedError(error) {
|
|
936
|
+
return NoObjectGeneratedError.isInstance(error);
|
|
937
|
+
}
|
|
938
|
+
function handleNoObjectGenerated(error, options = {}) {
|
|
939
|
+
const info = {
|
|
940
|
+
cause: "no-object",
|
|
941
|
+
message: error.message,
|
|
942
|
+
text: error.text,
|
|
943
|
+
usage: error.usage
|
|
944
|
+
};
|
|
945
|
+
options.onError?.(info);
|
|
946
|
+
if (options.fallback !== void 0) return {
|
|
947
|
+
handled: true,
|
|
948
|
+
result: typeof options.fallback === "function" ? options.fallback(info) : options.fallback,
|
|
949
|
+
info
|
|
950
|
+
};
|
|
951
|
+
return {
|
|
952
|
+
handled: false,
|
|
953
|
+
error
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
function createNoObjectHandler(config = {}) {
|
|
957
|
+
return (error) => {
|
|
958
|
+
if (!isNoObjectGeneratedError(error)) return {
|
|
959
|
+
handled: false,
|
|
960
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
961
|
+
};
|
|
962
|
+
const result = handleNoObjectGenerated(error, config);
|
|
963
|
+
if (!result.handled && config.throwOnUnhandled) throw error;
|
|
964
|
+
return result;
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
function createStreamErrorHandler(options = {}) {
|
|
968
|
+
return (error) => {
|
|
969
|
+
if (isNoObjectGeneratedError(error)) {
|
|
970
|
+
const info = {
|
|
971
|
+
cause: "no-object",
|
|
972
|
+
message: error.message,
|
|
973
|
+
text: error.text,
|
|
974
|
+
usage: error.usage
|
|
975
|
+
};
|
|
976
|
+
options.onError?.(info);
|
|
977
|
+
return options.fallbackText ?? error.text ?? "";
|
|
978
|
+
}
|
|
979
|
+
return options.fallbackText ?? "";
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
//#endregion
|
|
984
|
+
export { generateObjectWithRetry as C, streamStructuredObject as E, generateObjectWithFallback as S, safeGenerateObject as T, withElementStream as _, isNoObjectGeneratedError as a, createChoiceSchema as b, createPartialValidator as c, collectElements as d, collectFromElementStream as f, streamElementsWithProgress as g, streamElementsInBatches as h, handleNoObjectGenerated as i, createStrictValidator as l, streamElements as m, createNoObjectHandler as n, OutputValidationError as o, createElementStreamer as p, createStreamErrorHandler as r, createOutputValidator as s, ErrorRecoveryStrategies as t, isOutputValidationError as u, SchemaBuilders as v, generateStructuredObject as w, createObjectOutput as x, createArrayOutput as y };
|
|
985
|
+
//# sourceMappingURL=errors-CQ8tF4dP.mjs.map
|