@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,1086 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-CkzbjWQW.mjs";
|
|
2
|
+
import { Et as rerank, Ft as tool, et as generateText, f as ToolLoopAgent, k as createMCPClient, s as Experimental_StdioMCPTransport, w as createAgentUIStreamResponse } from "./ai-runtime-CDzQztTt.mjs";
|
|
3
|
+
import { t as complianceSignalSchema } from "./schemas-CxQtxIga.mjs";
|
|
4
|
+
import { c as detectRiskFromMessages, i as resolveLoopPolicy, n as defaultTelemetry, o as applyDefaultGuardrails, r as mergeActiveTools } from "./telemetry-2eKMojIb.mjs";
|
|
5
|
+
import { n as FeedbackLoopConfigSchema, t as EvaluationResultSchema } from "./schema-CwFvuCnA.mjs";
|
|
6
|
+
import { randomUUID } from "node:crypto";
|
|
7
|
+
import { z } from "zod/v4";
|
|
8
|
+
import { logInfo } from "@od-oneapp/shared/logs";
|
|
9
|
+
|
|
10
|
+
//#region src/agents/tools/mcp.ts
|
|
11
|
+
/**
|
|
12
|
+
* @fileoverview Model Context Protocol (MCP) tool integration
|
|
13
|
+
*
|
|
14
|
+
* Provides utilities for connecting to MCP servers and integrating their tools
|
|
15
|
+
* into AI agents. Supports SSE, HTTP, and stdio transport types.
|
|
16
|
+
*
|
|
17
|
+
* @module @od-oneapp/ai-platform/agents/tools/mcp
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Connects to an MCP server and returns its tools.
|
|
21
|
+
* Uses createMCPClient from the AI SDK MCP package.
|
|
22
|
+
*
|
|
23
|
+
* @param options - MCP connection options.
|
|
24
|
+
* @returns Connected toolset with tools and close function.
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const toolset = await connectMcpToolset({
|
|
28
|
+
* transport: { type: 'sse', url: 'https://mcp.example.com/sse' },
|
|
29
|
+
* approval: true
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Use tools
|
|
33
|
+
* const result = await toolset.tools.myTool.execute({ input: 'data' });
|
|
34
|
+
*
|
|
35
|
+
* // Cleanup
|
|
36
|
+
* await toolset.close();
|
|
37
|
+
* ```
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const stdioToolset = await connectMcpToolset({
|
|
41
|
+
* transport: { type: 'stdio', command: 'mcp-server', args: ['--profile', 'prod'] },
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
const connectMcpToolset = async (options) => {
|
|
46
|
+
const baseEnv = Object.entries(process.env).reduce((acc, [key, value]) => {
|
|
47
|
+
if (typeof value === "string") acc[key] = value;
|
|
48
|
+
return acc;
|
|
49
|
+
}, {});
|
|
50
|
+
const client = await createMCPClient({ transport: options.transport.type === "stdio" ? new Experimental_StdioMCPTransport({
|
|
51
|
+
command: options.transport.command ?? "node",
|
|
52
|
+
args: options.transport.args ?? [],
|
|
53
|
+
env: options.transport.env ? {
|
|
54
|
+
...baseEnv,
|
|
55
|
+
...options.transport.env
|
|
56
|
+
} : baseEnv,
|
|
57
|
+
cwd: options.transport.cwd,
|
|
58
|
+
stderr: options.transport.stderr
|
|
59
|
+
}) : {
|
|
60
|
+
type: options.transport.type,
|
|
61
|
+
url: options.transport.url,
|
|
62
|
+
headers: options.transport.type === "http" && options.transport.sessionId ? {
|
|
63
|
+
...options.transport.headers,
|
|
64
|
+
"x-mcp-session-id": options.transport.sessionId
|
|
65
|
+
} : options.transport.headers,
|
|
66
|
+
authProvider: options.transport.authProvider
|
|
67
|
+
} });
|
|
68
|
+
let tools;
|
|
69
|
+
try {
|
|
70
|
+
tools = await client.tools();
|
|
71
|
+
} catch (error) {
|
|
72
|
+
await client.close();
|
|
73
|
+
throw new Error(`Failed to retrieve tools from MCP server: ${error instanceof Error ? error.message : String(error)}`);
|
|
74
|
+
}
|
|
75
|
+
const processedTools = {};
|
|
76
|
+
try {
|
|
77
|
+
for (const name of Object.keys(tools)) {
|
|
78
|
+
const toolDefinition = tools[name];
|
|
79
|
+
if (!toolDefinition) continue;
|
|
80
|
+
processedTools[name] = {
|
|
81
|
+
...toolDefinition,
|
|
82
|
+
needsApproval: options.approval ?? toolDefinition.needsApproval
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
} catch (error) {
|
|
86
|
+
await client.close();
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
tools: processedTools,
|
|
91
|
+
close: async () => {
|
|
92
|
+
await client.close();
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/agents/tools/index.ts
|
|
99
|
+
/**
|
|
100
|
+
* @fileoverview Default agent tools
|
|
101
|
+
*
|
|
102
|
+
* Provides default tools for AI agents including knowledge base search,
|
|
103
|
+
* escalation, and audit logging. Also includes utilities for creating
|
|
104
|
+
* execution signals.
|
|
105
|
+
*
|
|
106
|
+
* @module @od-oneapp/ai-platform/agents/tools
|
|
107
|
+
*/
|
|
108
|
+
/**
|
|
109
|
+
* Internal knowledge base for compliance and best practices.
|
|
110
|
+
* Used by the knowledgeBaseTool for searching compliance guidelines.
|
|
111
|
+
* @internal
|
|
112
|
+
*/
|
|
113
|
+
const KNOWLEDGE_BASE = [
|
|
114
|
+
{
|
|
115
|
+
id: "kb-guardrails",
|
|
116
|
+
title: "Guardrail Playbook",
|
|
117
|
+
snippet: "All high risk guardrail violations must be escalated to compliance within 1 hour."
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
id: "kb-telemetry",
|
|
121
|
+
title: "Telemetry Standards",
|
|
122
|
+
snippet: "Every AI call must include telemetry metadata including risk levels and tool names."
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
id: "kb-rag",
|
|
126
|
+
title: "RAG Quality Checks",
|
|
127
|
+
snippet: "Use rerank() with topN <= 5 to keep prompts small and latency predictable."
|
|
128
|
+
}
|
|
129
|
+
];
|
|
130
|
+
/**
|
|
131
|
+
* Schema for knowledge base search input.
|
|
132
|
+
*/
|
|
133
|
+
const knowledgeBaseInputSchema = z.object({
|
|
134
|
+
query: z.string().min(2),
|
|
135
|
+
topN: z.number().min(1).max(5).default(3)
|
|
136
|
+
});
|
|
137
|
+
/**
|
|
138
|
+
* Knowledge base search tool.
|
|
139
|
+
* Searches the internal compliance knowledge base using reranking.
|
|
140
|
+
* Falls back to simple text matching if reranking fails.
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* const result = await knowledgeBaseTool.execute({ query: 'guardrail', topN: 2 });
|
|
144
|
+
* console.log(result.results[0].text);
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
const knowledgeBaseTool = tool({
|
|
148
|
+
description: "Searches the internal compliance knowledge base and returns ranked snippets.",
|
|
149
|
+
inputSchema: knowledgeBaseInputSchema,
|
|
150
|
+
execute: async ({ query, topN }) => {
|
|
151
|
+
try {
|
|
152
|
+
return {
|
|
153
|
+
query,
|
|
154
|
+
results: (await rerank({
|
|
155
|
+
model: "openai:rerank-v1",
|
|
156
|
+
documents: KNOWLEDGE_BASE.map((document) => ({
|
|
157
|
+
id: document.id,
|
|
158
|
+
text: `${document.title}: ${document.snippet}`
|
|
159
|
+
})),
|
|
160
|
+
query,
|
|
161
|
+
topN,
|
|
162
|
+
experimental_telemetry: {
|
|
163
|
+
isEnabled: true,
|
|
164
|
+
functionId: "knowledge-base-rerank",
|
|
165
|
+
metadata: { queryLength: query.length }
|
|
166
|
+
}
|
|
167
|
+
})).rerankedDocuments.slice(0, topN).map((entry, index) => ({
|
|
168
|
+
id: entry.id ?? `kb-${index}`,
|
|
169
|
+
score: typeof entry.score === "number" ? entry.score : 0,
|
|
170
|
+
text: entry.text
|
|
171
|
+
}))
|
|
172
|
+
};
|
|
173
|
+
} catch (error) {
|
|
174
|
+
return {
|
|
175
|
+
query,
|
|
176
|
+
results: KNOWLEDGE_BASE.filter((document) => document.snippet.toLowerCase().includes(query.toLowerCase())).slice(0, topN).map((document, index) => ({
|
|
177
|
+
id: document.id ?? `fallback-${index}`,
|
|
178
|
+
score: 0,
|
|
179
|
+
text: `${document.title}: ${document.snippet}`
|
|
180
|
+
})),
|
|
181
|
+
warning: error instanceof Error ? error.message : String(error)
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
/**
|
|
187
|
+
* Schema for escalation ticket input.
|
|
188
|
+
*/
|
|
189
|
+
const escalateInputSchema = z.object({
|
|
190
|
+
summary: z.string().min(10),
|
|
191
|
+
ticketSystem: z.enum([
|
|
192
|
+
"jira",
|
|
193
|
+
"pagerduty",
|
|
194
|
+
"service-now"
|
|
195
|
+
]).default("jira"),
|
|
196
|
+
severity: z.enum([
|
|
197
|
+
"low",
|
|
198
|
+
"medium",
|
|
199
|
+
"high"
|
|
200
|
+
]).default("medium")
|
|
201
|
+
});
|
|
202
|
+
/**
|
|
203
|
+
* Escalation tool for creating compliance tickets.
|
|
204
|
+
* Requires human approval for medium and high severity tickets.
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* const ticket = await escalateTool.execute({
|
|
208
|
+
* summary: 'User requested PII export',
|
|
209
|
+
* ticketSystem: 'jira',
|
|
210
|
+
* severity: 'high',
|
|
211
|
+
* });
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
const escalateTool = tool({
|
|
215
|
+
description: "Creates a compliance escalation ticket that requires human approval.",
|
|
216
|
+
inputSchema: escalateInputSchema,
|
|
217
|
+
needsApproval: (input) => input.severity !== "low",
|
|
218
|
+
execute: async (input) => ({
|
|
219
|
+
ticketId: `${input.ticketSystem}-${randomUUID().slice(0, 8)}`,
|
|
220
|
+
...input,
|
|
221
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
222
|
+
})
|
|
223
|
+
});
|
|
224
|
+
/**
|
|
225
|
+
* Schema for audit log input.
|
|
226
|
+
*/
|
|
227
|
+
const auditLogInputSchema = z.object({
|
|
228
|
+
runId: z.string(),
|
|
229
|
+
toolCalls: z.array(z.object({
|
|
230
|
+
id: z.string(),
|
|
231
|
+
toolName: z.string(),
|
|
232
|
+
approved: z.boolean().optional(),
|
|
233
|
+
payload: z.record(z.string(), z.unknown()).optional()
|
|
234
|
+
}))
|
|
235
|
+
});
|
|
236
|
+
/**
|
|
237
|
+
* Audit logging tool for compliance tracking.
|
|
238
|
+
* Writes structured audit log entries and returns compliance receipts.
|
|
239
|
+
* @example
|
|
240
|
+
* ```ts
|
|
241
|
+
* const receipt = await auditLogTool.execute({
|
|
242
|
+
* runId: 'run-1',
|
|
243
|
+
* toolCalls: [{ id: 'call-1', toolName: 'knowledgeBase' }],
|
|
244
|
+
* });
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
const auditLogTool = tool({
|
|
248
|
+
description: "Writes a structured audit log entry and returns a compliance receipt.",
|
|
249
|
+
inputSchema: auditLogInputSchema,
|
|
250
|
+
execute: async ({ runId, toolCalls }) => ({
|
|
251
|
+
receiptId: randomUUID(),
|
|
252
|
+
runId,
|
|
253
|
+
totalTools: toolCalls.length,
|
|
254
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
255
|
+
})
|
|
256
|
+
});
|
|
257
|
+
/**
|
|
258
|
+
* Default tools available to all agents.
|
|
259
|
+
* Includes knowledge base search, escalation, and audit logging.
|
|
260
|
+
* @example
|
|
261
|
+
* ```ts
|
|
262
|
+
* const tools = Object.keys(defaultTools);
|
|
263
|
+
* // ['knowledgeBase', 'escalate', 'auditLog']
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
const defaultTools = {
|
|
267
|
+
knowledgeBase: knowledgeBaseTool,
|
|
268
|
+
escalate: escalateTool,
|
|
269
|
+
auditLog: auditLogTool
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* Creates a compliance signal for tool execution events.
|
|
273
|
+
* Used to track tool calls throughout agent execution for audit purposes.
|
|
274
|
+
*
|
|
275
|
+
* @param toolCall - Tool call information.
|
|
276
|
+
* @param type - Signal type (tool.executed, tool.awaiting-approval, or tool.denied).
|
|
277
|
+
* @param runId - Agent run identifier.
|
|
278
|
+
* @returns Compliance signal object.
|
|
279
|
+
* @example
|
|
280
|
+
* ```ts
|
|
281
|
+
* const signal = createExecutionSignal(
|
|
282
|
+
* { id: 'call-123', toolName: 'escalate', input: { summary: 'Issue' } },
|
|
283
|
+
* 'tool.executed',
|
|
284
|
+
* 'run-456'
|
|
285
|
+
* );
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
const createExecutionSignal = (toolCall, type, runId) => complianceSignalSchema.parse({
|
|
289
|
+
id: randomUUID(),
|
|
290
|
+
type,
|
|
291
|
+
message: `${toolCall.toolName} (${toolCall.id}) ${type.replace("tool.", "")}`,
|
|
292
|
+
runId,
|
|
293
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
//#endregion
|
|
297
|
+
//#region src/agents/default-agent.ts
|
|
298
|
+
/**
|
|
299
|
+
* @fileoverview Agent creation utilities
|
|
300
|
+
*
|
|
301
|
+
* Provides functions for creating AI agents with default configurations including
|
|
302
|
+
* guardrails, loop policies, telemetry, and structured output support.
|
|
303
|
+
*
|
|
304
|
+
* THIS FILE IMPLEMENTS THE STANDARD AGENT TRACK (Experimental_Agent).
|
|
305
|
+
*
|
|
306
|
+
* @module @od-oneapp/ai-platform/agents/default-agent
|
|
307
|
+
*/
|
|
308
|
+
/**
|
|
309
|
+
* Standard Agent type (Experimental_Agent instance).
|
|
310
|
+
* Wrapper class to maintain compatibility with legacy DefaultAgent interface
|
|
311
|
+
* while using Experimental_Agent internally.
|
|
312
|
+
*/
|
|
313
|
+
var StandardAgent = class {
|
|
314
|
+
agent;
|
|
315
|
+
options;
|
|
316
|
+
runId;
|
|
317
|
+
tools;
|
|
318
|
+
constructor(options) {
|
|
319
|
+
this.options = options;
|
|
320
|
+
this.runId = options.runId ?? randomUUID();
|
|
321
|
+
const wrappedModel = applyDefaultGuardrails(options.model);
|
|
322
|
+
const loopPolicy = resolveLoopPolicy({
|
|
323
|
+
riskLevel: options.riskLevel,
|
|
324
|
+
activeTools: options.activeTools
|
|
325
|
+
});
|
|
326
|
+
this.tools = {
|
|
327
|
+
...defaultTools,
|
|
328
|
+
...options.tools
|
|
329
|
+
};
|
|
330
|
+
const activeToolNames = mergeActiveTools(loopPolicy, options.activeTools);
|
|
331
|
+
this.agent = new ToolLoopAgent({
|
|
332
|
+
model: wrappedModel,
|
|
333
|
+
tools: activeToolNames ? Object.keys(this.tools).filter((key) => activeToolNames.includes(key)).reduce((obj, key) => {
|
|
334
|
+
const tool = this.tools[key];
|
|
335
|
+
if (tool) obj[key] = tool;
|
|
336
|
+
return obj;
|
|
337
|
+
}, {}) : this.tools,
|
|
338
|
+
instructions: "You are a compliance co-pilot. Obey guardrails, honour human approvals, and document every decision in the structured output.",
|
|
339
|
+
experimental_telemetry: options.telemetry ?? defaultTelemetry,
|
|
340
|
+
stopWhen: loopPolicy.stopCondition
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Generates a response using the agent.
|
|
345
|
+
* Wraps the internal generate call to provide signal emission and structured output handling.
|
|
346
|
+
*/
|
|
347
|
+
async generate(options) {
|
|
348
|
+
const result = await this.agent.generate(options);
|
|
349
|
+
if (this.options.onSignal && result.steps) {
|
|
350
|
+
for (const step of result.steps) if (step.toolCalls) for (const toolCall of step.toolCalls) this.options.onSignal(createExecutionSignal({
|
|
351
|
+
id: toolCall.toolCallId,
|
|
352
|
+
toolName: toolCall.toolName,
|
|
353
|
+
input: toolCall.input
|
|
354
|
+
}, "tool.executed", this.runId));
|
|
355
|
+
}
|
|
356
|
+
await this.options.onCleanup?.();
|
|
357
|
+
return result;
|
|
358
|
+
}
|
|
359
|
+
async stream(options) {
|
|
360
|
+
return this.agent.stream(options);
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Access the underlying ToolLoopAgent instance.
|
|
364
|
+
* Intended for SDK helpers that require the raw agent type.
|
|
365
|
+
*/
|
|
366
|
+
getToolLoopAgent() {
|
|
367
|
+
return this.agent;
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
/**
|
|
371
|
+
* Creates a default agent (Standard Track).
|
|
372
|
+
* Uses Experimental_Agent under the hood.
|
|
373
|
+
*/
|
|
374
|
+
const createDefaultAgent = (options) => {
|
|
375
|
+
return new StandardAgent(options);
|
|
376
|
+
};
|
|
377
|
+
const createDefaultAgentConfig = (options) => {
|
|
378
|
+
throw new Error("createDefaultAgentConfig is deprecated. Use createDefaultAgent directly.");
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region src/agents/governance-agent.ts
|
|
383
|
+
/**
|
|
384
|
+
* @fileoverview Governance Agent
|
|
385
|
+
*
|
|
386
|
+
* Implements the "Governance Track" agent strategy using the Ralph Wiggum autonomous retry loop.
|
|
387
|
+
* This agent prioritizes RELIABILITY and COMPLIANCE over raw speed.
|
|
388
|
+
*
|
|
389
|
+
* Features:
|
|
390
|
+
* - Autonomous Retry Loop (keeps trying until completion signal)
|
|
391
|
+
* - "Principal Skinner" Governance (fine-grained token budgets per iteration)
|
|
392
|
+
* - Audit Signals (loop.approval_required, loop.budget_exceeded)
|
|
393
|
+
* - Feedback Loops (feeds errors back into context)
|
|
394
|
+
*
|
|
395
|
+
* @module @od-oneapp/ai-platform/agents/governance-agent
|
|
396
|
+
*/
|
|
397
|
+
/**
|
|
398
|
+
* Creates a delay promise.
|
|
399
|
+
* @internal
|
|
400
|
+
*/
|
|
401
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
402
|
+
/**
|
|
403
|
+
* Filters tools based on blocked list.
|
|
404
|
+
* @internal
|
|
405
|
+
*/
|
|
406
|
+
const filterTools = (tools, blockedTools) => {
|
|
407
|
+
if (!tools) return void 0;
|
|
408
|
+
const filtered = {};
|
|
409
|
+
for (const [name, tool] of Object.entries(tools)) if (!blockedTools.includes(name)) filtered[name] = tool;
|
|
410
|
+
return Object.keys(filtered).length > 0 ? filtered : void 0;
|
|
411
|
+
};
|
|
412
|
+
/**
|
|
413
|
+
* Checks if output contains completion signal.
|
|
414
|
+
* Uses word boundary matching to avoid false positives.
|
|
415
|
+
* @internal
|
|
416
|
+
*/
|
|
417
|
+
const detectCompletion = (output, signal) => {
|
|
418
|
+
const escapedSignal = signal.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
419
|
+
return new RegExp(`\\b${escapedSignal}\\b`, "i").test(output);
|
|
420
|
+
};
|
|
421
|
+
/**
|
|
422
|
+
* Creates a compliance signal.
|
|
423
|
+
* @internal
|
|
424
|
+
*/
|
|
425
|
+
const createSignal = (type, message, runId, riskLevel, metadata) => {
|
|
426
|
+
return complianceSignalSchema.parse({
|
|
427
|
+
id: randomUUID(),
|
|
428
|
+
type,
|
|
429
|
+
message,
|
|
430
|
+
runId,
|
|
431
|
+
riskLevel,
|
|
432
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
433
|
+
metadata
|
|
434
|
+
});
|
|
435
|
+
};
|
|
436
|
+
/**
|
|
437
|
+
* Executes the Governance Loop.
|
|
438
|
+
* @internal
|
|
439
|
+
*/
|
|
440
|
+
async function executeGovernanceLoop(options) {
|
|
441
|
+
const { task, completionSignal, maxIterations = 10, feedbackErrors = true, iterationDelay = 0, governance, model, tools, onIteration, onSignal, systemPrompt, runId = randomUUID() } = options;
|
|
442
|
+
const signals = [];
|
|
443
|
+
const iterationHistory = [];
|
|
444
|
+
let iteration = 0;
|
|
445
|
+
const context = task;
|
|
446
|
+
let lastError;
|
|
447
|
+
let totalInputTokens = 0;
|
|
448
|
+
let totalOutputTokens = 0;
|
|
449
|
+
const startTime = Date.now();
|
|
450
|
+
const allowedTools = filterTools(tools, governance.blockedTools);
|
|
451
|
+
const startSignal = createSignal("loop.started", `Governance Agent started: ${task.slice(0, 50)}...`, runId, "low", {
|
|
452
|
+
maxIterations,
|
|
453
|
+
completionSignal
|
|
454
|
+
});
|
|
455
|
+
signals.push(startSignal);
|
|
456
|
+
onSignal?.(startSignal);
|
|
457
|
+
while (iteration < maxIterations) {
|
|
458
|
+
iteration++;
|
|
459
|
+
const iterationStart = Date.now();
|
|
460
|
+
if (governance.maxTotalTokens && totalInputTokens + totalOutputTokens >= governance.maxTotalTokens) {
|
|
461
|
+
const budgetSignal = createSignal("loop.budget_exceeded", `Total token budget exhausted after ${iteration - 1} iterations`, runId, "medium", {
|
|
462
|
+
totalInputTokens,
|
|
463
|
+
totalOutputTokens
|
|
464
|
+
});
|
|
465
|
+
signals.push(budgetSignal);
|
|
466
|
+
onSignal?.(budgetSignal);
|
|
467
|
+
return {
|
|
468
|
+
success: false,
|
|
469
|
+
iterations: iteration - 1,
|
|
470
|
+
iterationHistory,
|
|
471
|
+
error: `Token budget exceeded (${totalInputTokens + totalOutputTokens} / ${governance.maxTotalTokens})`,
|
|
472
|
+
totalTokens: {
|
|
473
|
+
input: totalInputTokens,
|
|
474
|
+
output: totalOutputTokens
|
|
475
|
+
},
|
|
476
|
+
totalDurationMs: Date.now() - startTime,
|
|
477
|
+
signals
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
const prompt = feedbackErrors && lastError ? `${context}\n\n[Previous attempt failed with error: ${lastError}]\n\nPlease try again and address the error.` : context;
|
|
481
|
+
try {
|
|
482
|
+
const result = await generateText({
|
|
483
|
+
model,
|
|
484
|
+
prompt,
|
|
485
|
+
system: systemPrompt,
|
|
486
|
+
tools: allowedTools,
|
|
487
|
+
maxOutputTokens: governance.maxTokensPerIteration,
|
|
488
|
+
abortSignal: governance.iterationTimeoutMs ? AbortSignal.timeout(governance.iterationTimeoutMs) : void 0
|
|
489
|
+
});
|
|
490
|
+
const iterationDuration = Date.now() - iterationStart;
|
|
491
|
+
const inputTokens = result.usage?.inputTokens ?? 0;
|
|
492
|
+
const outputTokens = result.usage?.outputTokens ?? 0;
|
|
493
|
+
totalInputTokens += inputTokens;
|
|
494
|
+
totalOutputTokens += outputTokens;
|
|
495
|
+
const toolCalls = result.toolCalls?.map((tc) => ({
|
|
496
|
+
name: tc.toolName,
|
|
497
|
+
args: tc.input ?? tc.args
|
|
498
|
+
}));
|
|
499
|
+
if (toolCalls) {
|
|
500
|
+
const approvalRequired = toolCalls.filter((tc) => governance.requireApproval.includes(tc.name));
|
|
501
|
+
if (approvalRequired.length > 0) {
|
|
502
|
+
const approvalSignal = createSignal("loop.approval_required", `Audit: Tools executed that require approval: ${approvalRequired.map((t) => t.name).join(", ")}`, runId, "medium", {
|
|
503
|
+
tools: approvalRequired,
|
|
504
|
+
note: "Post-execution audit signal"
|
|
505
|
+
});
|
|
506
|
+
signals.push(approvalSignal);
|
|
507
|
+
onSignal?.(approvalSignal);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
const iterationResult = {
|
|
511
|
+
index: iteration,
|
|
512
|
+
status: "running",
|
|
513
|
+
output: result.text,
|
|
514
|
+
tokenUsage: {
|
|
515
|
+
input: inputTokens,
|
|
516
|
+
output: outputTokens
|
|
517
|
+
},
|
|
518
|
+
durationMs: iterationDuration,
|
|
519
|
+
toolCalls
|
|
520
|
+
};
|
|
521
|
+
if (detectCompletion(result.text, completionSignal)) {
|
|
522
|
+
iterationResult.status = "success";
|
|
523
|
+
iterationHistory.push(iterationResult);
|
|
524
|
+
onIteration?.(iterationResult);
|
|
525
|
+
const successSignal = createSignal("loop.completed", `Governance Agent completed successfully after ${iteration} iterations`, runId, "low", {
|
|
526
|
+
iterations: iteration,
|
|
527
|
+
totalTokens: totalInputTokens + totalOutputTokens
|
|
528
|
+
});
|
|
529
|
+
signals.push(successSignal);
|
|
530
|
+
onSignal?.(successSignal);
|
|
531
|
+
return {
|
|
532
|
+
success: true,
|
|
533
|
+
iterations: iteration,
|
|
534
|
+
iterationHistory,
|
|
535
|
+
finalOutput: result.text,
|
|
536
|
+
totalTokens: {
|
|
537
|
+
input: totalInputTokens,
|
|
538
|
+
output: totalOutputTokens
|
|
539
|
+
},
|
|
540
|
+
totalDurationMs: Date.now() - startTime,
|
|
541
|
+
signals
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
iterationHistory.push(iterationResult);
|
|
545
|
+
onIteration?.(iterationResult);
|
|
546
|
+
lastError = void 0;
|
|
547
|
+
if (iterationDelay > 0 && iteration < maxIterations) await sleep(iterationDelay);
|
|
548
|
+
} catch (error) {
|
|
549
|
+
const iterationDuration = Date.now() - iterationStart;
|
|
550
|
+
lastError = error instanceof Error ? error.message : String(error);
|
|
551
|
+
const isTimeout = error instanceof Error && error.name === "TimeoutError";
|
|
552
|
+
const iterationResult = {
|
|
553
|
+
index: iteration,
|
|
554
|
+
status: isTimeout ? "timeout" : "error",
|
|
555
|
+
error: lastError,
|
|
556
|
+
tokenUsage: {
|
|
557
|
+
input: 0,
|
|
558
|
+
output: 0
|
|
559
|
+
},
|
|
560
|
+
durationMs: iterationDuration
|
|
561
|
+
};
|
|
562
|
+
iterationHistory.push(iterationResult);
|
|
563
|
+
onIteration?.(iterationResult);
|
|
564
|
+
const errorSignal = createSignal(isTimeout ? "loop.timeout" : "loop.error", `Iteration ${iteration} ${isTimeout ? "timed out" : "failed"}: ${lastError}`, runId, "medium", {
|
|
565
|
+
iteration,
|
|
566
|
+
error: lastError
|
|
567
|
+
});
|
|
568
|
+
signals.push(errorSignal);
|
|
569
|
+
onSignal?.(errorSignal);
|
|
570
|
+
if (!feedbackErrors) return {
|
|
571
|
+
success: false,
|
|
572
|
+
iterations: iteration,
|
|
573
|
+
iterationHistory,
|
|
574
|
+
error: `Iteration ${iteration} failed: ${lastError}`,
|
|
575
|
+
totalTokens: {
|
|
576
|
+
input: totalInputTokens,
|
|
577
|
+
output: totalOutputTokens
|
|
578
|
+
},
|
|
579
|
+
totalDurationMs: Date.now() - startTime,
|
|
580
|
+
signals
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
const exhaustedSignal = createSignal("loop.exhausted", `Max iterations (${maxIterations}) reached without completion signal`, runId, "high", {
|
|
585
|
+
iterations: maxIterations,
|
|
586
|
+
completionSignal
|
|
587
|
+
});
|
|
588
|
+
signals.push(exhaustedSignal);
|
|
589
|
+
onSignal?.(exhaustedSignal);
|
|
590
|
+
return {
|
|
591
|
+
success: false,
|
|
592
|
+
iterations: iteration,
|
|
593
|
+
iterationHistory,
|
|
594
|
+
error: `Max iterations (${maxIterations}) reached without completion signal "${completionSignal}"`,
|
|
595
|
+
totalTokens: {
|
|
596
|
+
input: totalInputTokens,
|
|
597
|
+
output: totalOutputTokens
|
|
598
|
+
},
|
|
599
|
+
totalDurationMs: Date.now() - startTime,
|
|
600
|
+
signals
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Governance Agent class.
|
|
605
|
+
* Wraps the autonomous retry loop in an interface compatible with StandardAgent.
|
|
606
|
+
*/
|
|
607
|
+
var GovernanceAgent = class GovernanceAgent {
|
|
608
|
+
options;
|
|
609
|
+
constructor(options) {
|
|
610
|
+
this.options = options;
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Generates a response using the governance retry loop.
|
|
614
|
+
* Maps the result to a format compatible with StandardAgent results where possible,
|
|
615
|
+
* or returns the specific GovernanceResult.
|
|
616
|
+
*/
|
|
617
|
+
async generate() {
|
|
618
|
+
return executeGovernanceLoop(this.options);
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Creates a new instance with merged options.
|
|
622
|
+
*/
|
|
623
|
+
static create(options) {
|
|
624
|
+
return new GovernanceAgent(options);
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
/**
|
|
628
|
+
* Factory for creating a Governance Agent with defaults.
|
|
629
|
+
*/
|
|
630
|
+
function createGovernanceAgent(options) {
|
|
631
|
+
return new GovernanceAgent(options);
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* Default governance rules.
|
|
635
|
+
*/
|
|
636
|
+
const DEFAULT_GOVERNANCE_RULES = {
|
|
637
|
+
maxTokensPerIteration: 4096,
|
|
638
|
+
blockedTools: [
|
|
639
|
+
"deleteFile",
|
|
640
|
+
"formatDisk",
|
|
641
|
+
"dropTable",
|
|
642
|
+
"truncateTable",
|
|
643
|
+
"deleteDatabase"
|
|
644
|
+
],
|
|
645
|
+
requireApproval: [
|
|
646
|
+
"executeShell",
|
|
647
|
+
"runCommand",
|
|
648
|
+
"modifyPermissions",
|
|
649
|
+
"deployProduction"
|
|
650
|
+
],
|
|
651
|
+
maxTotalTokens: 1e5,
|
|
652
|
+
iterationTimeoutMs: 6e4
|
|
653
|
+
};
|
|
654
|
+
const ralphLoop = executeGovernanceLoop;
|
|
655
|
+
const DEFAULT_RALPH_GOVERNANCE = DEFAULT_GOVERNANCE_RULES;
|
|
656
|
+
|
|
657
|
+
//#endregion
|
|
658
|
+
//#region src/agents/orchestrator.ts
|
|
659
|
+
/**
|
|
660
|
+
* @fileoverview Platform Orchestrator
|
|
661
|
+
*
|
|
662
|
+
* Provides risk-aware agent orchestration with intelligent caching and dynamic
|
|
663
|
+
* agent selection based on message risk analysis. Supports MCP toolset integration
|
|
664
|
+
* and compliance signal emission.
|
|
665
|
+
*
|
|
666
|
+
* @module @od-oneapp/ai-platform/agents/orchestrator
|
|
667
|
+
*/
|
|
668
|
+
/**
|
|
669
|
+
* Risk-aware agent orchestrator with intelligent caching and dynamic agent selection.
|
|
670
|
+
* Automatically selects the appropriate agent based on message risk analysis and
|
|
671
|
+
* caches agents per risk level for performance optimization.
|
|
672
|
+
*/
|
|
673
|
+
var PlatformOrchestrator = class {
|
|
674
|
+
/** Orchestrator version identifier. */
|
|
675
|
+
version = "agent-v1";
|
|
676
|
+
/** Orchestrator ID. */
|
|
677
|
+
id = "platform-orchestrator";
|
|
678
|
+
/** Orchestrator configuration options. */
|
|
679
|
+
options;
|
|
680
|
+
/** Cached agents per risk level. */
|
|
681
|
+
agents = {};
|
|
682
|
+
/**
|
|
683
|
+
* Constructs a new PlatformOrchestrator instance.
|
|
684
|
+
* @param options - Orchestrator configuration options.
|
|
685
|
+
*/
|
|
686
|
+
constructor(options) {
|
|
687
|
+
this.options = options;
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Gets the tools available to the orchestrator.
|
|
691
|
+
* Returns empty object as tools are managed per agent instance.
|
|
692
|
+
*/
|
|
693
|
+
get tools() {
|
|
694
|
+
return {};
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* Gets tools from a medium-risk agent (default).
|
|
698
|
+
*/
|
|
699
|
+
async getTools() {
|
|
700
|
+
return (await this.ensureAgent("medium")).tools;
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Generates a response using the appropriate agent based on message risk.
|
|
704
|
+
*/
|
|
705
|
+
async generate(options) {
|
|
706
|
+
return (await this.agentForMessages(options.messages ?? [])).generate(options);
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* Streams a response using the appropriate agent based on message risk.
|
|
710
|
+
*/
|
|
711
|
+
async stream(options) {
|
|
712
|
+
return (await this.agentForMessages(options.messages ?? [])).stream(options);
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* Creates a UI stream response for the given messages.
|
|
716
|
+
* Uses the StandardAgent (Experimental_Agent) interface.
|
|
717
|
+
*/
|
|
718
|
+
async respond({ messages }) {
|
|
719
|
+
return createAgentUIStreamResponse({
|
|
720
|
+
agent: (await this.agentForMessages(messages)).getToolLoopAgent(),
|
|
721
|
+
uiMessages: messages
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
extractTextContent(content) {
|
|
725
|
+
if (typeof content === "string") return content;
|
|
726
|
+
if (Array.isArray(content)) return content.filter((part) => typeof part === "object" && part !== null && "type" in part && part.type === "text" && "text" in part).map((part) => part.text).join(" ");
|
|
727
|
+
return "";
|
|
728
|
+
}
|
|
729
|
+
async agentForMessages(messages) {
|
|
730
|
+
const risk = detectRiskFromMessages(messages.map((message) => {
|
|
731
|
+
if (!message || typeof message !== "object") return null;
|
|
732
|
+
const record = message;
|
|
733
|
+
if (typeof record.role !== "string") return null;
|
|
734
|
+
const source = typeof record.content !== "undefined" ? record.content : record.parts;
|
|
735
|
+
return {
|
|
736
|
+
role: record.role,
|
|
737
|
+
content: this.extractTextContent(source)
|
|
738
|
+
};
|
|
739
|
+
}).filter((value) => value !== null));
|
|
740
|
+
return this.ensureAgent(risk);
|
|
741
|
+
}
|
|
742
|
+
async ensureAgent(riskLevel) {
|
|
743
|
+
const cachedAgent = this.agents[riskLevel];
|
|
744
|
+
if (cachedAgent) return cachedAgent;
|
|
745
|
+
if (!this.agents[riskLevel]) {
|
|
746
|
+
const model = this.options.modelFactory();
|
|
747
|
+
let cleanup;
|
|
748
|
+
let dynamicTools;
|
|
749
|
+
if (this.options.mcp) {
|
|
750
|
+
const connection = await connectMcpToolset(this.options.mcp);
|
|
751
|
+
dynamicTools = connection.tools;
|
|
752
|
+
cleanup = async () => {
|
|
753
|
+
await connection.close();
|
|
754
|
+
delete this.agents[riskLevel];
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
const agent = createDefaultAgent({
|
|
758
|
+
model,
|
|
759
|
+
riskLevel,
|
|
760
|
+
runId: randomUUID(),
|
|
761
|
+
onSignal: this.options.onSignal,
|
|
762
|
+
onStructuredOutput: this.options.onStructuredOutput,
|
|
763
|
+
tools: dynamicTools,
|
|
764
|
+
onCleanup: cleanup
|
|
765
|
+
});
|
|
766
|
+
this.agents[riskLevel] = agent;
|
|
767
|
+
}
|
|
768
|
+
return this.agents[riskLevel];
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
//#endregion
|
|
773
|
+
//#region src/agents/evaluator-optimizer/index.ts
|
|
774
|
+
/**
|
|
775
|
+
* @fileoverview Evaluator-Optimizer Feedback Loop.
|
|
776
|
+
* @module @od-oneapp/ai-platform/agents/evaluator-optimizer
|
|
777
|
+
*
|
|
778
|
+
* Main orchestration module implementing the 5-step workflow.
|
|
779
|
+
* Based on VERCEL_AI_SDK_V6_PATTERNS.md section 4.2
|
|
780
|
+
*
|
|
781
|
+
* WORKFLOW:
|
|
782
|
+
* 1. Generate initial content based on user request
|
|
783
|
+
* 2. Evaluate quality against criteria
|
|
784
|
+
* 3. If quality < threshold, optimize the content
|
|
785
|
+
* 4. Re-evaluate optimized content
|
|
786
|
+
* 5. Repeat steps 3-4 until threshold met or max iterations reached
|
|
787
|
+
*/
|
|
788
|
+
var evaluator_optimizer_exports = /* @__PURE__ */ __exportAll({
|
|
789
|
+
EvaluationResultSchema: () => EvaluationResultSchema,
|
|
790
|
+
EvaluatorOptimizer: () => EvaluatorOptimizer,
|
|
791
|
+
FeedbackLoopConfigSchema: () => FeedbackLoopConfigSchema,
|
|
792
|
+
createEvaluatorOptimizer: () => createEvaluatorOptimizer,
|
|
793
|
+
runFeedbackLoop: () => runFeedbackLoop
|
|
794
|
+
});
|
|
795
|
+
/** Default maximum iterations for feedback loop. */
|
|
796
|
+
const DEFAULT_MAX_ITERATIONS = 5;
|
|
797
|
+
/** Default target quality score. */
|
|
798
|
+
const DEFAULT_TARGET_SCORE = 8;
|
|
799
|
+
/** Default diminishing return threshold. */
|
|
800
|
+
const DEFAULT_DIMINISHING_RETURN_THRESHOLD = 2;
|
|
801
|
+
/** Minimum allowed iterations. */
|
|
802
|
+
const MIN_ITERATIONS = 1;
|
|
803
|
+
/** Maximum allowed iterations. */
|
|
804
|
+
const MAX_ITERATIONS = 10;
|
|
805
|
+
/** Minimum target score. */
|
|
806
|
+
const MIN_TARGET_SCORE = 1;
|
|
807
|
+
/** Maximum target score. */
|
|
808
|
+
const MAX_TARGET_SCORE = 10;
|
|
809
|
+
/**
|
|
810
|
+
* Validates OptimizerConfig bounds at runtime
|
|
811
|
+
* @throws Error if config values are out of valid ranges
|
|
812
|
+
*/
|
|
813
|
+
function validateOptimizerConfig(config) {
|
|
814
|
+
if (config.maxIterations < MIN_ITERATIONS || config.maxIterations > MAX_ITERATIONS) throw new Error(`maxIterations must be between ${MIN_ITERATIONS} and ${MAX_ITERATIONS}, got ${config.maxIterations}`);
|
|
815
|
+
if (config.targetScore < MIN_TARGET_SCORE || config.targetScore > MAX_TARGET_SCORE) throw new Error(`targetScore must be between ${MIN_TARGET_SCORE} and ${MAX_TARGET_SCORE}, got ${config.targetScore}`);
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* Main EvaluatorOptimizer class
|
|
819
|
+
* Orchestrates the iterative evaluation-optimization feedback loop
|
|
820
|
+
*/
|
|
821
|
+
var EvaluatorOptimizer = class {
|
|
822
|
+
config;
|
|
823
|
+
logger;
|
|
824
|
+
constructor(config) {
|
|
825
|
+
validateOptimizerConfig(config);
|
|
826
|
+
this.config = config;
|
|
827
|
+
this.logger = config.enableLogging ? logInfo : () => {};
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* Get the evaluator instance.
|
|
831
|
+
* @returns The configured evaluator.
|
|
832
|
+
*/
|
|
833
|
+
getEvaluator() {
|
|
834
|
+
return this.config.evaluator;
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* Get the optimizer instance.
|
|
838
|
+
* @returns The configured optimizer.
|
|
839
|
+
*/
|
|
840
|
+
getOptimizer() {
|
|
841
|
+
return this.config.optimizer;
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Execute 5-step feedback loop workflow
|
|
845
|
+
*
|
|
846
|
+
* STEP 1: Generate initial content (provided as input)
|
|
847
|
+
* STEP 2: Evaluate initial content
|
|
848
|
+
* STEP 3: If score < threshold, optimize
|
|
849
|
+
* STEP 4: Re-evaluate optimized content
|
|
850
|
+
* STEP 5: Repeat until threshold or max iterations
|
|
851
|
+
*
|
|
852
|
+
* @param initialContent - Initial content to optimize
|
|
853
|
+
* @param originalRequest - Original user request context
|
|
854
|
+
* @param config - Optional loop configuration overrides
|
|
855
|
+
* @returns Optimized result with full history and metadata
|
|
856
|
+
*
|
|
857
|
+
* @example
|
|
858
|
+
* ```typescript
|
|
859
|
+
* const optimizer = new EvaluatorOptimizer({
|
|
860
|
+
* maxIterations: 5,
|
|
861
|
+
* targetScore: 8,
|
|
862
|
+
* evaluator: createLLMEvaluator(),
|
|
863
|
+
* optimizer: createPromptOptimizer(),
|
|
864
|
+
* enableLogging: true
|
|
865
|
+
* });
|
|
866
|
+
*
|
|
867
|
+
* const result = await optimizer.runFeedbackLoop(
|
|
868
|
+
* "Generated content",
|
|
869
|
+
* "Original user request"
|
|
870
|
+
* );
|
|
871
|
+
*
|
|
872
|
+
* console.log(`Final score: ${result.finalEvaluation.qualityScore}/10`);
|
|
873
|
+
* console.log(`Cycles: ${result.cyclesCompleted}`);
|
|
874
|
+
* ```
|
|
875
|
+
*/
|
|
876
|
+
async runFeedbackLoop(initialContent, originalRequest, loopConfig) {
|
|
877
|
+
const startTime = (/* @__PURE__ */ new Date()).toISOString();
|
|
878
|
+
const config = {
|
|
879
|
+
maxIterations: this.config.maxIterations,
|
|
880
|
+
targetScore: this.config.targetScore,
|
|
881
|
+
enableLogging: this.config.enableLogging ?? false,
|
|
882
|
+
stopOnThreshold: this.config.stopOnThreshold ?? true,
|
|
883
|
+
diminishingReturnThreshold: this.config.diminishingReturnThreshold ?? 2,
|
|
884
|
+
...loopConfig
|
|
885
|
+
};
|
|
886
|
+
const scoreHistory = [];
|
|
887
|
+
const contentHistory = [initialContent];
|
|
888
|
+
let currentContent = initialContent;
|
|
889
|
+
let currentEvaluation = null;
|
|
890
|
+
let cyclesCompleted = 0;
|
|
891
|
+
let consecutiveNonImprovingCycles = 0;
|
|
892
|
+
this.logger(`\n${"=".repeat(60)}`);
|
|
893
|
+
this.logger("Evaluator-Optimizer Feedback Loop Started");
|
|
894
|
+
this.logger(`Target Score: ${config.targetScore}/10`);
|
|
895
|
+
this.logger(`Max Iterations: ${config.maxIterations}`);
|
|
896
|
+
this.logger(`${"=".repeat(60)}\n`);
|
|
897
|
+
try {
|
|
898
|
+
this.logger(`STEP 2: Initial Evaluation`);
|
|
899
|
+
currentEvaluation = await this.evaluateContent(currentContent, originalRequest, 1);
|
|
900
|
+
scoreHistory.push(currentEvaluation.qualityScore);
|
|
901
|
+
this.logger(`Quality Score: ${currentEvaluation.qualityScore}/10`);
|
|
902
|
+
this.logger(`Meets Threshold: ${currentEvaluation.meetsThreshold}\n`);
|
|
903
|
+
while (cyclesCompleted < config.maxIterations && !currentEvaluation.meetsThreshold) {
|
|
904
|
+
cyclesCompleted += 1;
|
|
905
|
+
this.logger(`${"─".repeat(60)}`);
|
|
906
|
+
this.logger(`STEP 3: Optimization (Cycle ${cyclesCompleted})`);
|
|
907
|
+
if (cyclesCompleted > 1 && scoreHistory.length >= 2) {
|
|
908
|
+
const previousScore = scoreHistory[scoreHistory.length - 2];
|
|
909
|
+
if (currentEvaluation.qualityScore === previousScore) {
|
|
910
|
+
consecutiveNonImprovingCycles += 1;
|
|
911
|
+
this.logger(`⚠ No improvement (${consecutiveNonImprovingCycles} consecutive)`);
|
|
912
|
+
if (consecutiveNonImprovingCycles >= config.diminishingReturnThreshold) {
|
|
913
|
+
this.logger(`Diminishing returns detected. Stopping optimization.`);
|
|
914
|
+
return this.buildResult(currentContent, currentEvaluation, cyclesCompleted, scoreHistory, contentHistory, "diminishing_returns", startTime, void 0);
|
|
915
|
+
}
|
|
916
|
+
} else consecutiveNonImprovingCycles = 0;
|
|
917
|
+
}
|
|
918
|
+
const optimizedContent = await this.optimizeContent(currentContent, currentEvaluation, originalRequest, cyclesCompleted);
|
|
919
|
+
currentContent = optimizedContent;
|
|
920
|
+
contentHistory.push(optimizedContent);
|
|
921
|
+
this.logger(`Content optimized`);
|
|
922
|
+
this.logger(`STEP 4: Re-evaluation`);
|
|
923
|
+
currentEvaluation = await this.evaluateContent(currentContent, originalRequest, cyclesCompleted + 1);
|
|
924
|
+
scoreHistory.push(currentEvaluation.qualityScore);
|
|
925
|
+
this.logger(`Quality Score: ${currentEvaluation.qualityScore}/10`);
|
|
926
|
+
this.logger(`Meets Threshold: ${currentEvaluation.meetsThreshold}`);
|
|
927
|
+
this.logger(`Issues: ${currentEvaluation.specificIssues.length}\n`);
|
|
928
|
+
if (currentEvaluation.meetsThreshold && config.stopOnThreshold) {
|
|
929
|
+
this.logger(`✓ Threshold reached! Quality: ${currentEvaluation.qualityScore}/10`);
|
|
930
|
+
return this.buildResult(currentContent, currentEvaluation, cyclesCompleted, scoreHistory, contentHistory, "threshold_met", startTime, void 0);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
if (currentEvaluation.meetsThreshold) {
|
|
934
|
+
this.logger(`✓ Threshold reached after ${cyclesCompleted} cycles`);
|
|
935
|
+
return this.buildResult(currentContent, currentEvaluation, cyclesCompleted, scoreHistory, contentHistory, "threshold_met", startTime, void 0);
|
|
936
|
+
} else {
|
|
937
|
+
this.logger(`⚠ Max iterations (${config.maxIterations}) reached without meeting threshold`);
|
|
938
|
+
return this.buildResult(currentContent, currentEvaluation, cyclesCompleted, scoreHistory, contentHistory, "max_iterations", startTime, void 0);
|
|
939
|
+
}
|
|
940
|
+
} catch (error) {
|
|
941
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
942
|
+
this.logger(`✗ Error in feedback loop: ${errorMessage}`);
|
|
943
|
+
const errorEvaluation = currentEvaluation || {
|
|
944
|
+
qualityScore: 0,
|
|
945
|
+
preservesTone: false,
|
|
946
|
+
preservesNuance: false,
|
|
947
|
+
culturallyAccurate: false,
|
|
948
|
+
technicallyCorrect: false,
|
|
949
|
+
specificIssues: [`Error during evaluation: ${errorMessage}`],
|
|
950
|
+
improvementSuggestions: [],
|
|
951
|
+
strengths: [],
|
|
952
|
+
overallAssessment: `Evaluation failed: ${errorMessage}`,
|
|
953
|
+
meetsThreshold: false
|
|
954
|
+
};
|
|
955
|
+
return this.buildResult(currentContent, errorEvaluation, cyclesCompleted, scoreHistory, contentHistory, "error", startTime, errorMessage);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* Evaluate content
|
|
960
|
+
*/
|
|
961
|
+
async evaluateContent(content, originalRequest, iterationNumber) {
|
|
962
|
+
const evaluatorInput = {
|
|
963
|
+
content,
|
|
964
|
+
originalRequest,
|
|
965
|
+
criteria: { threshold: this.config.targetScore },
|
|
966
|
+
iterationNumber
|
|
967
|
+
};
|
|
968
|
+
return this.config.evaluator.evaluate(evaluatorInput);
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* Optimize content
|
|
972
|
+
*/
|
|
973
|
+
async optimizeContent(content, evaluationFeedback, originalRequest, iterationNumber) {
|
|
974
|
+
return this.config.optimizer.optimize({
|
|
975
|
+
content,
|
|
976
|
+
evaluationFeedback,
|
|
977
|
+
originalRequest,
|
|
978
|
+
iterationNumber
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
/**
|
|
982
|
+
* Build final result object
|
|
983
|
+
*/
|
|
984
|
+
buildResult(finalContent, finalEvaluation, cyclesCompleted, scoreHistory, contentHistory, terminationReason, startTime, error) {
|
|
985
|
+
const endTime = (/* @__PURE__ */ new Date()).toISOString();
|
|
986
|
+
const startMs = new Date(startTime).getTime();
|
|
987
|
+
const endMs = new Date(endTime).getTime();
|
|
988
|
+
const firstScore = scoreHistory[0] ?? 0;
|
|
989
|
+
const lastScore = scoreHistory[scoreHistory.length - 1] ?? firstScore;
|
|
990
|
+
const averageScoreImprovement = scoreHistory.length > 1 ? (lastScore - firstScore) / (scoreHistory.length - 1) : 0;
|
|
991
|
+
this.logger(`\n${"=".repeat(60)}`);
|
|
992
|
+
this.logger("Feedback Loop Complete");
|
|
993
|
+
this.logger(`Cycles: ${cyclesCompleted}`);
|
|
994
|
+
this.logger(`Final Score: ${finalEvaluation.qualityScore}/10`);
|
|
995
|
+
this.logger(`Average Improvement: ${averageScoreImprovement.toFixed(2)}/cycle`);
|
|
996
|
+
this.logger(`Time: ${endMs - startMs}ms`);
|
|
997
|
+
this.logger(`Reason: ${terminationReason}`);
|
|
998
|
+
this.logger(`${"=".repeat(60)}\n`);
|
|
999
|
+
return {
|
|
1000
|
+
finalContent,
|
|
1001
|
+
finalEvaluation,
|
|
1002
|
+
cyclesCompleted,
|
|
1003
|
+
meetsThreshold: finalEvaluation.meetsThreshold,
|
|
1004
|
+
scoreHistory,
|
|
1005
|
+
contentHistory,
|
|
1006
|
+
terminationReason,
|
|
1007
|
+
error,
|
|
1008
|
+
metadata: {
|
|
1009
|
+
startTime,
|
|
1010
|
+
endTime,
|
|
1011
|
+
processingTimeMs: endMs - startMs,
|
|
1012
|
+
averageScoreImprovement
|
|
1013
|
+
}
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
/**
|
|
1018
|
+
* Factory function to create evaluator-optimizer
|
|
1019
|
+
*
|
|
1020
|
+
* @param config - Configuration object
|
|
1021
|
+
* @returns EvaluatorOptimizer instance
|
|
1022
|
+
*
|
|
1023
|
+
* @example
|
|
1024
|
+
* ```typescript
|
|
1025
|
+
* const loop = createEvaluatorOptimizer({
|
|
1026
|
+
* maxIterations: 5,
|
|
1027
|
+
* targetScore: 8,
|
|
1028
|
+
* evaluator: createLLMEvaluator(),
|
|
1029
|
+
* optimizer: createPromptOptimizer(),
|
|
1030
|
+
* enableLogging: true
|
|
1031
|
+
* });
|
|
1032
|
+
* ```
|
|
1033
|
+
*/
|
|
1034
|
+
function createEvaluatorOptimizer(config) {
|
|
1035
|
+
return new EvaluatorOptimizer(config);
|
|
1036
|
+
}
|
|
1037
|
+
/**
|
|
1038
|
+
* Helper function to run feedback loop with sensible defaults
|
|
1039
|
+
*
|
|
1040
|
+
* @param initialContent - Content to optimize
|
|
1041
|
+
* @param originalRequest - Original request context
|
|
1042
|
+
* @param config - Optional configuration
|
|
1043
|
+
* @returns Optimized result
|
|
1044
|
+
*
|
|
1045
|
+
* @example
|
|
1046
|
+
* ```typescript
|
|
1047
|
+
* const result = await runFeedbackLoop(
|
|
1048
|
+
* "Generated content",
|
|
1049
|
+
* "User request",
|
|
1050
|
+
* {
|
|
1051
|
+
* maxIterations: 5,
|
|
1052
|
+
* targetScore: 8,
|
|
1053
|
+
* enableLogging: true
|
|
1054
|
+
* }
|
|
1055
|
+
* );
|
|
1056
|
+
* ```
|
|
1057
|
+
*/
|
|
1058
|
+
async function runFeedbackLoop(initialContent, originalRequest, config) {
|
|
1059
|
+
let createLLMEvaluator;
|
|
1060
|
+
let createPromptOptimizer;
|
|
1061
|
+
try {
|
|
1062
|
+
const { createLLMEvaluator: importedEvaluator } = await import("./evaluator-Cs84qkr8.mjs");
|
|
1063
|
+
createLLMEvaluator = importedEvaluator;
|
|
1064
|
+
} catch (error) {
|
|
1065
|
+
throw new Error(`Failed to import evaluator module: ${error instanceof Error ? error.message : String(error)}`);
|
|
1066
|
+
}
|
|
1067
|
+
try {
|
|
1068
|
+
const { createPromptOptimizer: importedOptimizer } = await import("./optimizer-DhXXpci6.mjs");
|
|
1069
|
+
createPromptOptimizer = importedOptimizer;
|
|
1070
|
+
} catch (error) {
|
|
1071
|
+
throw new Error(`Failed to import optimizer module: ${error instanceof Error ? error.message : String(error)}`);
|
|
1072
|
+
}
|
|
1073
|
+
return createEvaluatorOptimizer({
|
|
1074
|
+
maxIterations: config?.maxIterations ?? DEFAULT_MAX_ITERATIONS,
|
|
1075
|
+
targetScore: config?.targetScore ?? DEFAULT_TARGET_SCORE,
|
|
1076
|
+
evaluator: config?.evaluator ?? createLLMEvaluator(),
|
|
1077
|
+
optimizer: config?.optimizer ?? createPromptOptimizer(),
|
|
1078
|
+
enableLogging: config?.enableLogging ?? false,
|
|
1079
|
+
stopOnThreshold: config?.stopOnThreshold ?? true,
|
|
1080
|
+
diminishingReturnThreshold: config?.diminishingReturnThreshold ?? DEFAULT_DIMINISHING_RETURN_THRESHOLD
|
|
1081
|
+
}).runFeedbackLoop(initialContent, originalRequest);
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
//#endregion
|
|
1085
|
+
export { GovernanceAgent as a, StandardAgent as c, DEFAULT_RALPH_GOVERNANCE as i, createDefaultAgent as l, PlatformOrchestrator as n, createGovernanceAgent as o, DEFAULT_GOVERNANCE_RULES as r, ralphLoop as s, evaluator_optimizer_exports as t, createDefaultAgentConfig as u };
|
|
1086
|
+
//# sourceMappingURL=evaluator-optimizer-De67_mJC.mjs.map
|