operon-agents-core 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +55 -0
- package/README.md +7 -0
- package/dist/agent/agent.d.ts +65 -0
- package/dist/agent/agent.js +39 -0
- package/dist/agent/compose-hooks.d.ts +13 -0
- package/dist/agent/compose-hooks.js +197 -0
- package/dist/agent/concurrency.d.ts +22 -0
- package/dist/agent/concurrency.js +70 -0
- package/dist/agent/context-report.d.ts +60 -0
- package/dist/agent/context-report.js +45 -0
- package/dist/agent/graph.d.ts +48 -0
- package/dist/agent/graph.js +129 -0
- package/dist/agent/guardrail.d.ts +105 -0
- package/dist/agent/guardrail.js +314 -0
- package/dist/agent/handoff-executor.d.ts +21 -0
- package/dist/agent/handoff-executor.js +95 -0
- package/dist/agent/handoff.d.ts +42 -0
- package/dist/agent/handoff.js +70 -0
- package/dist/agent/index.d.ts +25 -0
- package/dist/agent/index.js +19 -0
- package/dist/agent/instruction-context.d.ts +33 -0
- package/dist/agent/instruction-context.js +100 -0
- package/dist/agent/pause.d.ts +12 -0
- package/dist/agent/pause.js +82 -0
- package/dist/agent/profile-builtins.d.ts +8 -0
- package/dist/agent/profile-builtins.js +130 -0
- package/dist/agent/profiles.d.ts +94 -0
- package/dist/agent/profiles.js +264 -0
- package/dist/agent/recovery.d.ts +10 -0
- package/dist/agent/recovery.js +151 -0
- package/dist/agent/run-support.d.ts +79 -0
- package/dist/agent/run-support.js +211 -0
- package/dist/agent/runner.d.ts +246 -0
- package/dist/agent/runner.js +786 -0
- package/dist/agent/session.d.ts +363 -0
- package/dist/agent/session.js +937 -0
- package/dist/agent/subagent-tools.d.ts +18 -0
- package/dist/agent/subagent-tools.js +650 -0
- package/dist/agent/subagent.d.ts +56 -0
- package/dist/agent/subagent.js +50 -0
- package/dist/agent/toolset.d.ts +24 -0
- package/dist/agent/toolset.js +112 -0
- package/dist/agent/workflow/index.d.ts +9 -0
- package/dist/agent/workflow/index.js +8 -0
- package/dist/agent/workflow/journal.d.ts +180 -0
- package/dist/agent/workflow/journal.js +224 -0
- package/dist/agent/workflow/manager.d.ts +27 -0
- package/dist/agent/workflow/manager.js +33 -0
- package/dist/agent/workflow/parse.d.ts +17 -0
- package/dist/agent/workflow/parse.js +174 -0
- package/dist/agent/workflow/prompt.d.ts +8 -0
- package/dist/agent/workflow/prompt.js +84 -0
- package/dist/agent/workflow/runtime.d.ts +64 -0
- package/dist/agent/workflow/runtime.js +380 -0
- package/dist/agent/workflow/sandbox.d.ts +35 -0
- package/dist/agent/workflow/sandbox.js +90 -0
- package/dist/agent/workflow/snapshot.d.ts +36 -0
- package/dist/agent/workflow/snapshot.js +9 -0
- package/dist/agent/workflow/structured.d.ts +35 -0
- package/dist/agent/workflow/structured.js +79 -0
- package/dist/agent/workflow/tool.d.ts +14 -0
- package/dist/agent/workflow/tool.js +569 -0
- package/dist/agent/workflow/types.d.ts +100 -0
- package/dist/agent/workflow/types.js +17 -0
- package/dist/agent/worktree.d.ts +38 -0
- package/dist/agent/worktree.js +56 -0
- package/dist/capabilities/assembler.d.ts +39 -0
- package/dist/capabilities/assembler.js +171 -0
- package/dist/capabilities/background/agent-task.d.ts +51 -0
- package/dist/capabilities/background/agent-task.js +101 -0
- package/dist/capabilities/background/command-task.d.ts +43 -0
- package/dist/capabilities/background/command-task.js +86 -0
- package/dist/capabilities/background/index.d.ts +20 -0
- package/dist/capabilities/background/index.js +57 -0
- package/dist/capabilities/background/manager.d.ts +194 -0
- package/dist/capabilities/background/manager.js +1131 -0
- package/dist/capabilities/background/persist-disk.d.ts +17 -0
- package/dist/capabilities/background/persist-disk.js +66 -0
- package/dist/capabilities/background/persist.d.ts +61 -0
- package/dist/capabilities/background/persist.js +117 -0
- package/dist/capabilities/background/question-task.d.ts +32 -0
- package/dist/capabilities/background/question-task.js +56 -0
- package/dist/capabilities/background/registrar.d.ts +12 -0
- package/dist/capabilities/background/registrar.js +9 -0
- package/dist/capabilities/background/swappable-sink.d.ts +20 -0
- package/dist/capabilities/background/swappable-sink.js +20 -0
- package/dist/capabilities/background/task.d.ts +114 -0
- package/dist/capabilities/background/task.js +20 -0
- package/dist/capabilities/background/tools.d.ts +6 -0
- package/dist/capabilities/background/tools.js +190 -0
- package/dist/capabilities/background/workflow-task.d.ts +48 -0
- package/dist/capabilities/background/workflow-task.js +91 -0
- package/dist/capabilities/capability-state.d.ts +13 -0
- package/dist/capabilities/capability-state.js +37 -0
- package/dist/capabilities/capability.d.ts +145 -0
- package/dist/capabilities/capability.js +2 -0
- package/dist/capabilities/compaction/full.d.ts +27 -0
- package/dist/capabilities/compaction/full.js +155 -0
- package/dist/capabilities/compaction/index.d.ts +17 -0
- package/dist/capabilities/compaction/index.js +145 -0
- package/dist/capabilities/compaction/instruction.d.ts +2 -0
- package/dist/capabilities/compaction/instruction.js +31 -0
- package/dist/capabilities/compaction/micro.d.ts +17 -0
- package/dist/capabilities/compaction/micro.js +57 -0
- package/dist/capabilities/compaction/service.d.ts +28 -0
- package/dist/capabilities/compaction/service.js +52 -0
- package/dist/capabilities/compaction/strategy.d.ts +43 -0
- package/dist/capabilities/compaction/strategy.js +116 -0
- package/dist/capabilities/compaction/tokens.d.ts +5 -0
- package/dist/capabilities/compaction/tokens.js +28 -0
- package/dist/capabilities/goal/goal-store.d.ts +69 -0
- package/dist/capabilities/goal/goal-store.js +172 -0
- package/dist/capabilities/goal/index.d.ts +6 -0
- package/dist/capabilities/goal/index.js +31 -0
- package/dist/capabilities/goal/injector.d.ts +9 -0
- package/dist/capabilities/goal/injector.js +79 -0
- package/dist/capabilities/goal/tools.d.ts +6 -0
- package/dist/capabilities/goal/tools.js +86 -0
- package/dist/capabilities/index.d.ts +25 -0
- package/dist/capabilities/index.js +22 -0
- package/dist/capabilities/injection.d.ts +44 -0
- package/dist/capabilities/injection.js +112 -0
- package/dist/capabilities/plan/index.d.ts +6 -0
- package/dist/capabilities/plan/index.js +25 -0
- package/dist/capabilities/plan/injector.d.ts +13 -0
- package/dist/capabilities/plan/injector.js +83 -0
- package/dist/capabilities/plan/plan-mode.d.ts +38 -0
- package/dist/capabilities/plan/plan-mode.js +113 -0
- package/dist/capabilities/plan/policies.d.ts +6 -0
- package/dist/capabilities/plan/policies.js +89 -0
- package/dist/capabilities/plan/tools.d.ts +15 -0
- package/dist/capabilities/plan/tools.js +87 -0
- package/dist/capabilities/skills/flow-provider.d.ts +6 -0
- package/dist/capabilities/skills/flow-provider.js +50 -0
- package/dist/capabilities/skills/index.d.ts +43 -0
- package/dist/capabilities/skills/index.js +48 -0
- package/dist/capabilities/skills/injector.d.ts +11 -0
- package/dist/capabilities/skills/injector.js +27 -0
- package/dist/capabilities/skills/parser.d.ts +36 -0
- package/dist/capabilities/skills/parser.js +334 -0
- package/dist/capabilities/skills/registry.d.ts +33 -0
- package/dist/capabilities/skills/registry.js +118 -0
- package/dist/capabilities/skills/scanner.d.ts +26 -0
- package/dist/capabilities/skills/scanner.js +154 -0
- package/dist/capabilities/skills/service.d.ts +39 -0
- package/dist/capabilities/skills/service.js +68 -0
- package/dist/capabilities/skills/skill-tool.d.ts +13 -0
- package/dist/capabilities/skills/skill-tool.js +72 -0
- package/dist/capabilities/skills/types.d.ts +62 -0
- package/dist/capabilities/skills/types.js +26 -0
- package/dist/capabilities/task/index.d.ts +23 -0
- package/dist/capabilities/task/index.js +38 -0
- package/dist/capabilities/task/injector.d.ts +9 -0
- package/dist/capabilities/task/injector.js +62 -0
- package/dist/capabilities/task/persist-disk.d.ts +19 -0
- package/dist/capabilities/task/persist-disk.js +84 -0
- package/dist/capabilities/task/persist.d.ts +52 -0
- package/dist/capabilities/task/persist.js +84 -0
- package/dist/capabilities/task/task-store.d.ts +44 -0
- package/dist/capabilities/task/task-store.js +106 -0
- package/dist/capabilities/task/tools.d.ts +12 -0
- package/dist/capabilities/task/tools.js +164 -0
- package/dist/capabilities/todo/index.d.ts +8 -0
- package/dist/capabilities/todo/index.js +21 -0
- package/dist/capabilities/todo/injector.d.ts +9 -0
- package/dist/capabilities/todo/injector.js +68 -0
- package/dist/capabilities/todo/todo-store.d.ts +19 -0
- package/dist/capabilities/todo/todo-store.js +36 -0
- package/dist/capabilities/todo/tools.d.ts +6 -0
- package/dist/capabilities/todo/tools.js +70 -0
- package/dist/capabilities/tool-provider.d.ts +12 -0
- package/dist/capabilities/tool-provider.js +20 -0
- package/dist/capabilities/user-hooks/engine.d.ts +22 -0
- package/dist/capabilities/user-hooks/engine.js +105 -0
- package/dist/capabilities/user-hooks/index.d.ts +13 -0
- package/dist/capabilities/user-hooks/index.js +126 -0
- package/dist/capabilities/user-hooks/types.d.ts +26 -0
- package/dist/capabilities/user-hooks/types.js +19 -0
- package/dist/capabilities/workflow/index.d.ts +16 -0
- package/dist/capabilities/workflow/index.js +15 -0
- package/dist/commands/index.d.ts +31 -0
- package/dist/commands/index.js +318 -0
- package/dist/config/config-store.d.ts +29 -0
- package/dist/config/config-store.js +103 -0
- package/dist/config/file-source.d.ts +40 -0
- package/dist/config/file-source.js +78 -0
- package/dist/config/flags.d.ts +13 -0
- package/dist/config/flags.js +25 -0
- package/dist/config/index.d.ts +17 -0
- package/dist/config/index.js +10 -0
- package/dist/config/merge.d.ts +5 -0
- package/dist/config/merge.js +57 -0
- package/dist/config/model-catalog.d.ts +17 -0
- package/dist/config/model-catalog.js +37 -0
- package/dist/config/paths.d.ts +31 -0
- package/dist/config/paths.js +28 -0
- package/dist/config/provider-manager.d.ts +57 -0
- package/dist/config/provider-manager.js +344 -0
- package/dist/config/resolver.d.ts +40 -0
- package/dist/config/resolver.js +52 -0
- package/dist/config/schema.d.ts +389 -0
- package/dist/config/schema.js +132 -0
- package/dist/events/events.d.ts +348 -0
- package/dist/events/events.js +146 -0
- package/dist/events/index.d.ts +10 -0
- package/dist/events/index.js +5 -0
- package/dist/events/projection.d.ts +207 -0
- package/dist/events/projection.js +438 -0
- package/dist/events/publisher.d.ts +48 -0
- package/dist/events/publisher.js +404 -0
- package/dist/events/redacting-sink.d.ts +11 -0
- package/dist/events/redacting-sink.js +31 -0
- package/dist/home.d.ts +16 -0
- package/dist/home.js +20 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +22 -0
- package/dist/internal.d.ts +33 -0
- package/dist/internal.js +29 -0
- package/dist/llm/auth.d.ts +22 -0
- package/dist/llm/auth.js +112 -0
- package/dist/llm/capability.d.ts +13 -0
- package/dist/llm/capability.js +45 -0
- package/dist/llm/define-model.d.ts +110 -0
- package/dist/llm/define-model.js +252 -0
- package/dist/llm/errors.d.ts +33 -0
- package/dist/llm/errors.js +154 -0
- package/dist/llm/index.d.ts +14 -0
- package/dist/llm/index.js +8 -0
- package/dist/llm/model.d.ts +43 -0
- package/dist/llm/model.js +9 -0
- package/dist/llm/retry.d.ts +35 -0
- package/dist/llm/retry.js +160 -0
- package/dist/llm/runtime.d.ts +25 -0
- package/dist/llm/runtime.js +38 -0
- package/dist/logging/diagnostics.d.ts +21 -0
- package/dist/logging/diagnostics.js +46 -0
- package/dist/logging/index.d.ts +11 -0
- package/dist/logging/index.js +7 -0
- package/dist/logging/logger.d.ts +25 -0
- package/dist/logging/logger.js +54 -0
- package/dist/logging/paths.d.ts +11 -0
- package/dist/logging/paths.js +20 -0
- package/dist/logging/policy.d.ts +5 -0
- package/dist/logging/policy.js +19 -0
- package/dist/logging/redact.d.ts +10 -0
- package/dist/logging/redact.js +95 -0
- package/dist/logging/sinks.d.ts +67 -0
- package/dist/logging/sinks.js +117 -0
- package/dist/loop/context.d.ts +69 -0
- package/dist/loop/context.js +129 -0
- package/dist/loop/errors.d.ts +8 -0
- package/dist/loop/errors.js +27 -0
- package/dist/loop/events.d.ts +14 -0
- package/dist/loop/events.js +2 -0
- package/dist/loop/index.d.ts +10 -0
- package/dist/loop/index.js +7 -0
- package/dist/loop/interruption.d.ts +118 -0
- package/dist/loop/interruption.js +191 -0
- package/dist/loop/run-turn.d.ts +54 -0
- package/dist/loop/run-turn.js +203 -0
- package/dist/loop/scheduler.d.ts +18 -0
- package/dist/loop/scheduler.js +71 -0
- package/dist/loop/steer.d.ts +122 -0
- package/dist/loop/steer.js +209 -0
- package/dist/loop/tool-call.d.ts +41 -0
- package/dist/loop/tool-call.js +326 -0
- package/dist/loop/turn-step.d.ts +57 -0
- package/dist/loop/turn-step.js +298 -0
- package/dist/loop/types.d.ts +217 -0
- package/dist/loop/types.js +2 -0
- package/dist/loop/usage.d.ts +6 -0
- package/dist/loop/usage.js +44 -0
- package/dist/mcp/auth-tool.d.ts +12 -0
- package/dist/mcp/auth-tool.js +92 -0
- package/dist/mcp/capability.d.ts +7 -0
- package/dist/mcp/capability.js +91 -0
- package/dist/mcp/config-loader.d.ts +28 -0
- package/dist/mcp/config-loader.js +115 -0
- package/dist/mcp/filter.d.ts +18 -0
- package/dist/mcp/filter.js +35 -0
- package/dist/mcp/index.d.ts +23 -0
- package/dist/mcp/index.js +13 -0
- package/dist/mcp/manager.d.ts +51 -0
- package/dist/mcp/manager.js +412 -0
- package/dist/mcp/mock-transport.d.ts +40 -0
- package/dist/mcp/mock-transport.js +68 -0
- package/dist/mcp/oauth/callback-server.d.ts +14 -0
- package/dist/mcp/oauth/callback-server.js +122 -0
- package/dist/mcp/oauth/index.d.ts +9 -0
- package/dist/mcp/oauth/index.js +5 -0
- package/dist/mcp/oauth/provider.d.ts +39 -0
- package/dist/mcp/oauth/provider.js +121 -0
- package/dist/mcp/oauth/service.d.ts +34 -0
- package/dist/mcp/oauth/service.js +130 -0
- package/dist/mcp/oauth/store.d.ts +40 -0
- package/dist/mcp/oauth/store.js +134 -0
- package/dist/mcp/output.d.ts +12 -0
- package/dist/mcp/output.js +110 -0
- package/dist/mcp/provider.d.ts +7 -0
- package/dist/mcp/provider.js +56 -0
- package/dist/mcp/sdk-transport.d.ts +25 -0
- package/dist/mcp/sdk-transport.js +228 -0
- package/dist/mcp/server.d.ts +77 -0
- package/dist/mcp/server.js +120 -0
- package/dist/mcp/tool-naming.d.ts +4 -0
- package/dist/mcp/tool-naming.js +26 -0
- package/dist/mcp/types.d.ts +75 -0
- package/dist/mcp/types.js +2 -0
- package/dist/net/index.d.ts +3 -0
- package/dist/net/index.js +2 -0
- package/dist/net/proxy.d.ts +16 -0
- package/dist/net/proxy.js +42 -0
- package/dist/permission/auto-approver/index.d.ts +3 -0
- package/dist/permission/auto-approver/index.js +3 -0
- package/dist/permission/auto-approver/llm-auto-approver.d.ts +53 -0
- package/dist/permission/auto-approver/llm-auto-approver.js +122 -0
- package/dist/permission/auto-approver/prompts-data.d.ts +9 -0
- package/dist/permission/auto-approver/prompts-data.js +155 -0
- package/dist/permission/auto-approver/prompts.d.ts +18 -0
- package/dist/permission/auto-approver/prompts.js +40 -0
- package/dist/permission/auto-approver/transcript.d.ts +22 -0
- package/dist/permission/auto-approver/transcript.js +75 -0
- package/dist/permission/auto-approver/xml.d.ts +5 -0
- package/dist/permission/auto-approver/xml.js +25 -0
- package/dist/permission/index.d.ts +7 -0
- package/dist/permission/index.js +5 -0
- package/dist/permission/manager.d.ts +74 -0
- package/dist/permission/manager.js +162 -0
- package/dist/permission/matches-rule.d.ts +27 -0
- package/dist/permission/matches-rule.js +54 -0
- package/dist/permission/policies.d.ts +14 -0
- package/dist/permission/policies.js +233 -0
- package/dist/permission/types.d.ts +84 -0
- package/dist/permission/types.js +2 -0
- package/dist/plugins/archive.d.ts +3 -0
- package/dist/plugins/archive.js +58 -0
- package/dist/plugins/github-resolver.d.ts +13 -0
- package/dist/plugins/github-resolver.js +20 -0
- package/dist/plugins/hooks.d.ts +28 -0
- package/dist/plugins/hooks.js +296 -0
- package/dist/plugins/index.d.ts +23 -0
- package/dist/plugins/index.js +23 -0
- package/dist/plugins/injector.d.ts +11 -0
- package/dist/plugins/injector.js +32 -0
- package/dist/plugins/manager.d.ts +37 -0
- package/dist/plugins/manager.js +330 -0
- package/dist/plugins/manifest.d.ts +9 -0
- package/dist/plugins/manifest.js +234 -0
- package/dist/plugins/marketplace.d.ts +85 -0
- package/dist/plugins/marketplace.js +205 -0
- package/dist/plugins/source.d.ts +23 -0
- package/dist/plugins/source.js +87 -0
- package/dist/plugins/store.d.ts +20 -0
- package/dist/plugins/store.js +30 -0
- package/dist/plugins/types.d.ts +118 -0
- package/dist/plugins/types.js +5 -0
- package/dist/protocol/index.d.ts +4 -0
- package/dist/protocol/index.js +2 -0
- package/dist/protocol/tool-schema.d.ts +6 -0
- package/dist/protocol/tool-schema.js +2 -0
- package/dist/store/blob-store.d.ts +45 -0
- package/dist/store/blob-store.js +120 -0
- package/dist/store/catalog-store.d.ts +32 -0
- package/dist/store/catalog-store.js +73 -0
- package/dist/store/disk-store.d.ts +58 -0
- package/dist/store/disk-store.js +369 -0
- package/dist/store/index.d.ts +23 -0
- package/dist/store/index.js +15 -0
- package/dist/store/lock.d.ts +86 -0
- package/dist/store/lock.js +104 -0
- package/dist/store/log-store.d.ts +89 -0
- package/dist/store/log-store.js +296 -0
- package/dist/store/migrate.d.ts +26 -0
- package/dist/store/migrate.js +32 -0
- package/dist/store/origin.d.ts +89 -0
- package/dist/store/origin.js +16 -0
- package/dist/store/pg.d.ts +90 -0
- package/dist/store/pg.js +344 -0
- package/dist/store/redacting-store.d.ts +21 -0
- package/dist/store/redacting-store.js +46 -0
- package/dist/store/redis.d.ts +89 -0
- package/dist/store/redis.js +370 -0
- package/dist/store/repository.d.ts +150 -0
- package/dist/store/repository.js +508 -0
- package/dist/store/session-catalog.d.ts +32 -0
- package/dist/store/session-catalog.js +117 -0
- package/dist/store/storage.d.ts +27 -0
- package/dist/store/storage.js +54 -0
- package/dist/store/store.d.ts +262 -0
- package/dist/store/store.js +129 -0
- package/dist/store/workdir-key.d.ts +4 -0
- package/dist/store/workdir-key.js +28 -0
- package/dist/tool/access.d.ts +37 -0
- package/dist/tool/access.js +79 -0
- package/dist/tool/ask.d.ts +22 -0
- package/dist/tool/ask.js +38 -0
- package/dist/tool/background.d.ts +109 -0
- package/dist/tool/background.js +39 -0
- package/dist/tool/builtin/ask-user-question.d.ts +2 -0
- package/dist/tool/builtin/ask-user-question.js +175 -0
- package/dist/tool/builtin/bash.d.ts +2 -0
- package/dist/tool/builtin/bash.js +407 -0
- package/dist/tool/builtin/edit.d.ts +2 -0
- package/dist/tool/builtin/edit.js +202 -0
- package/dist/tool/builtin/glob.d.ts +3 -0
- package/dist/tool/builtin/glob.js +260 -0
- package/dist/tool/builtin/grep.d.ts +2 -0
- package/dist/tool/builtin/grep.js +574 -0
- package/dist/tool/builtin/line-endings.d.ts +10 -0
- package/dist/tool/builtin/line-endings.js +41 -0
- package/dist/tool/builtin/read.d.ts +28 -0
- package/dist/tool/builtin/read.js +498 -0
- package/dist/tool/builtin/write.d.ts +2 -0
- package/dist/tool/builtin/write.js +179 -0
- package/dist/tool/define.d.ts +46 -0
- package/dist/tool/define.js +45 -0
- package/dist/tool/file-freshness.d.ts +81 -0
- package/dist/tool/file-freshness.js +67 -0
- package/dist/tool/filesystem-tools.d.ts +16 -0
- package/dist/tool/filesystem-tools.js +19 -0
- package/dist/tool/git-context.d.ts +20 -0
- package/dist/tool/git-context.js +114 -0
- package/dist/tool/index.d.ts +37 -0
- package/dist/tool/index.js +34 -0
- package/dist/tool/machine-base.d.ts +138 -0
- package/dist/tool/machine-base.js +388 -0
- package/dist/tool/machine-local.d.ts +35 -0
- package/dist/tool/machine-local.js +316 -0
- package/dist/tool/machine-null.d.ts +36 -0
- package/dist/tool/machine-null.js +64 -0
- package/dist/tool/machine-ssh.d.ts +86 -0
- package/dist/tool/machine-ssh.js +576 -0
- package/dist/tool/machine.d.ts +333 -0
- package/dist/tool/machine.js +15 -0
- package/dist/tool/policies/path-access.d.ts +48 -0
- package/dist/tool/policies/path-access.js +186 -0
- package/dist/tool/policies/sensitive.d.ts +3 -0
- package/dist/tool/policies/sensitive.js +60 -0
- package/dist/tool/questions.d.ts +40 -0
- package/dist/tool/questions.js +8 -0
- package/dist/tool/search/activation.d.ts +13 -0
- package/dist/tool/search/activation.js +31 -0
- package/dist/tool/search/deferral.d.ts +37 -0
- package/dist/tool/search/deferral.js +128 -0
- package/dist/tool/search/search-tool.d.ts +9 -0
- package/dist/tool/search/search-tool.js +62 -0
- package/dist/tool/shell-env.d.ts +9 -0
- package/dist/tool/shell-env.js +34 -0
- package/dist/tool/support/bash-destructive.d.ts +24 -0
- package/dist/tool/support/bash-destructive.js +63 -0
- package/dist/tool/support/bash-paths.d.ts +7 -0
- package/dist/tool/support/bash-paths.js +247 -0
- package/dist/tool/support/bash-read-only.d.ts +8 -0
- package/dist/tool/support/bash-read-only.js +165 -0
- package/dist/tool/support/bash-rule-match.d.ts +20 -0
- package/dist/tool/support/bash-rule-match.js +191 -0
- package/dist/tool/support/file-type.d.ts +10 -0
- package/dist/tool/support/file-type.js +149 -0
- package/dist/tool/support/git-worktree.d.ts +10 -0
- package/dist/tool/support/git-worktree.js +63 -0
- package/dist/tool/support/image-compress.d.ts +69 -0
- package/dist/tool/support/image-compress.js +265 -0
- package/dist/tool/support/machine-ops.d.ts +34 -0
- package/dist/tool/support/machine-ops.js +34 -0
- package/dist/tool/support/path-glob-match.d.ts +12 -0
- package/dist/tool/support/path-glob-match.js +84 -0
- package/dist/tool/support/result-builder.d.ts +27 -0
- package/dist/tool/support/result-builder.js +108 -0
- package/dist/tool/support/rg-locator.d.ts +20 -0
- package/dist/tool/support/rg-locator.js +42 -0
- package/dist/tool/support/ripgrep-run.d.ts +65 -0
- package/dist/tool/support/ripgrep-run.js +40 -0
- package/dist/tool/support/rule-match.d.ts +6 -0
- package/dist/tool/support/rule-match.js +23 -0
- package/dist/tool/support/tool-path.d.ts +8 -0
- package/dist/tool/support/tool-path.js +28 -0
- package/dist/tool/support/workspace.d.ts +5 -0
- package/dist/tool/support/workspace.js +2 -0
- package/dist/tool/types.d.ts +131 -0
- package/dist/tool/types.js +2 -0
- package/dist/tool/web/fetch-url.d.ts +4 -0
- package/dist/tool/web/fetch-url.js +61 -0
- package/dist/tool/web/index.d.ts +11 -0
- package/dist/tool/web/index.js +7 -0
- package/dist/tool/web/providers/direct-fetch.d.ts +33 -0
- package/dist/tool/web/providers/direct-fetch.js +198 -0
- package/dist/tool/web/providers/firecrawl.d.ts +16 -0
- package/dist/tool/web/providers/firecrawl.js +59 -0
- package/dist/tool/web/providers/tavily.d.ts +14 -0
- package/dist/tool/web/providers/tavily.js +43 -0
- package/dist/tool/web/types.d.ts +41 -0
- package/dist/tool/web/types.js +7 -0
- package/dist/tool/web/web-search.d.ts +4 -0
- package/dist/tool/web/web-search.js +68 -0
- package/dist/tool/workspace-spec.d.ts +74 -0
- package/dist/tool/workspace-spec.js +177 -0
- package/dist/tracing/bridge.d.ts +7 -0
- package/dist/tracing/bridge.js +171 -0
- package/dist/tracing/index.d.ts +9 -0
- package/dist/tracing/index.js +5 -0
- package/dist/tracing/otel.d.ts +38 -0
- package/dist/tracing/otel.js +221 -0
- package/dist/tracing/processor.d.ts +47 -0
- package/dist/tracing/processor.js +94 -0
- package/dist/tracing/spans.d.ts +94 -0
- package/dist/tracing/spans.js +56 -0
- package/dist/ui/ai-sdk.d.ts +114 -0
- package/dist/ui/ai-sdk.js +175 -0
- package/dist/ui/index.d.ts +2 -0
- package/dist/ui/index.js +2 -0
- package/package.json +101 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { InMemoryCredentialStore, type Credential, type CredentialInfo, type CredentialStore } from "@earendil-works/pi-ai";
|
|
2
|
+
export { InMemoryCredentialStore };
|
|
3
|
+
/** Backwards-compatible name for Operon callers; the implementation is pi's canonical store. */
|
|
4
|
+
export { InMemoryCredentialStore as MemoryCredentialStore };
|
|
5
|
+
export type { AuthInteraction, AuthPrompt, AuthResult, AuthType, Credential, CredentialInfo, CredentialStore, OAuthCredential, OAuthCredentials, } from "@earendil-works/pi-ai";
|
|
6
|
+
/**
|
|
7
|
+
* Persistent pi CredentialStore. The file is a provider-id keyed object and
|
|
8
|
+
* writes are atomic. Legacy Operon OAuth rows without `type` are upgraded to
|
|
9
|
+
* canonical `{ type: "oauth", ... }` credentials when read.
|
|
10
|
+
*/
|
|
11
|
+
export declare class FileCredentialStore implements CredentialStore {
|
|
12
|
+
private readonly filePath;
|
|
13
|
+
private writeChain;
|
|
14
|
+
constructor(filePath: string);
|
|
15
|
+
read(providerId: string): Promise<Credential | undefined>;
|
|
16
|
+
list(): Promise<readonly CredentialInfo[]>;
|
|
17
|
+
modify(providerId: string, fn: (current: Credential | undefined) => Promise<Credential | undefined>): Promise<Credential | undefined>;
|
|
18
|
+
delete(providerId: string): Promise<void>;
|
|
19
|
+
private readAll;
|
|
20
|
+
private writeAll;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=auth.d.ts.map
|
package/dist/llm/auth.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { randomBytes } from "node:crypto";
|
|
4
|
+
import { InMemoryCredentialStore, } from "@earendil-works/pi-ai";
|
|
5
|
+
export { InMemoryCredentialStore };
|
|
6
|
+
/** Backwards-compatible name for Operon callers; the implementation is pi's canonical store. */
|
|
7
|
+
export { InMemoryCredentialStore as MemoryCredentialStore };
|
|
8
|
+
/**
|
|
9
|
+
* Persistent pi CredentialStore. The file is a provider-id keyed object and
|
|
10
|
+
* writes are atomic. Legacy Operon OAuth rows without `type` are upgraded to
|
|
11
|
+
* canonical `{ type: "oauth", ... }` credentials when read.
|
|
12
|
+
*/
|
|
13
|
+
export class FileCredentialStore {
|
|
14
|
+
filePath;
|
|
15
|
+
writeChain = Promise.resolve();
|
|
16
|
+
constructor(filePath) {
|
|
17
|
+
this.filePath = filePath;
|
|
18
|
+
}
|
|
19
|
+
async read(providerId) {
|
|
20
|
+
return cloneCredential((await this.readAll())[providerId]);
|
|
21
|
+
}
|
|
22
|
+
async list() {
|
|
23
|
+
return Object.entries(await this.readAll()).map(([providerId, credential]) => ({
|
|
24
|
+
providerId,
|
|
25
|
+
type: credential.type,
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
modify(providerId, fn) {
|
|
29
|
+
let resolved;
|
|
30
|
+
const run = this.writeChain.then(async () => {
|
|
31
|
+
const all = await this.readAll();
|
|
32
|
+
const current = cloneCredential(all[providerId]);
|
|
33
|
+
const next = await fn(current);
|
|
34
|
+
if (next !== undefined) {
|
|
35
|
+
all[providerId] = cloneCredential(next);
|
|
36
|
+
await this.writeAll(all);
|
|
37
|
+
resolved = cloneCredential(next);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
resolved = current;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
this.writeChain = run.then(() => undefined, () => undefined);
|
|
44
|
+
return run.then(() => resolved);
|
|
45
|
+
}
|
|
46
|
+
delete(providerId) {
|
|
47
|
+
const run = this.writeChain.then(async () => {
|
|
48
|
+
const all = await this.readAll();
|
|
49
|
+
if (!(providerId in all))
|
|
50
|
+
return;
|
|
51
|
+
delete all[providerId];
|
|
52
|
+
await this.writeAll(all);
|
|
53
|
+
});
|
|
54
|
+
this.writeChain = run.then(() => undefined, () => undefined);
|
|
55
|
+
return run;
|
|
56
|
+
}
|
|
57
|
+
async readAll() {
|
|
58
|
+
let raw;
|
|
59
|
+
try {
|
|
60
|
+
raw = JSON.parse(await readFile(this.filePath, "utf-8"));
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (isMissingFile(error))
|
|
64
|
+
return {};
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw))
|
|
68
|
+
return {};
|
|
69
|
+
const credentials = {};
|
|
70
|
+
for (const [providerId, value] of Object.entries(raw)) {
|
|
71
|
+
const credential = normalizeCredential(value);
|
|
72
|
+
if (credential !== undefined)
|
|
73
|
+
credentials[providerId] = credential;
|
|
74
|
+
}
|
|
75
|
+
return credentials;
|
|
76
|
+
}
|
|
77
|
+
async writeAll(all) {
|
|
78
|
+
await mkdir(dirname(this.filePath), { recursive: true, mode: 0o700 });
|
|
79
|
+
const tmp = `${this.filePath}.tmp.${process.pid}.${randomBytes(4).toString("hex")}`;
|
|
80
|
+
await writeFile(tmp, `${JSON.stringify(all, null, 2)}\n`, {
|
|
81
|
+
encoding: "utf-8",
|
|
82
|
+
mode: 0o600,
|
|
83
|
+
});
|
|
84
|
+
await rename(tmp, this.filePath);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function normalizeCredential(value) {
|
|
88
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
const candidate = value;
|
|
92
|
+
if (candidate.type === "api_key") {
|
|
93
|
+
return { ...candidate, type: "api_key" };
|
|
94
|
+
}
|
|
95
|
+
if (candidate.type === "oauth" ||
|
|
96
|
+
(typeof candidate.access === "string" &&
|
|
97
|
+
typeof candidate.refresh === "string" &&
|
|
98
|
+
typeof candidate.expires === "number")) {
|
|
99
|
+
return { ...candidate, type: "oauth" };
|
|
100
|
+
}
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
function cloneCredential(credential) {
|
|
104
|
+
return credential === undefined ? undefined : structuredClone(credential);
|
|
105
|
+
}
|
|
106
|
+
function isMissingFile(error) {
|
|
107
|
+
return (typeof error === "object" &&
|
|
108
|
+
error !== null &&
|
|
109
|
+
"code" in error &&
|
|
110
|
+
error.code === "ENOENT");
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Api, Model } from "../protocol/index.ts";
|
|
2
|
+
export interface ModelCapability {
|
|
3
|
+
readonly image_in: boolean;
|
|
4
|
+
readonly video_in: boolean;
|
|
5
|
+
readonly audio_in: boolean;
|
|
6
|
+
readonly thinking: boolean;
|
|
7
|
+
readonly tool_use: boolean;
|
|
8
|
+
readonly max_context_tokens: number | undefined;
|
|
9
|
+
}
|
|
10
|
+
export declare const UNKNOWN_CAPABILITY: ModelCapability;
|
|
11
|
+
export declare function capabilityFromPiModel(model: Model<Api>): ModelCapability;
|
|
12
|
+
export declare function applyDeclaredCapability(base: ModelCapability, tags: readonly string[] | undefined, maxContextSize?: number): ModelCapability;
|
|
13
|
+
//# sourceMappingURL=capability.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export const UNKNOWN_CAPABILITY = Object.freeze({
|
|
2
|
+
image_in: false,
|
|
3
|
+
video_in: false,
|
|
4
|
+
audio_in: false,
|
|
5
|
+
thinking: false,
|
|
6
|
+
tool_use: true,
|
|
7
|
+
max_context_tokens: undefined,
|
|
8
|
+
});
|
|
9
|
+
export function capabilityFromPiModel(model) {
|
|
10
|
+
return {
|
|
11
|
+
image_in: model.input.includes("image"),
|
|
12
|
+
video_in: false, // pi's Model.input is only ("text" | "image")
|
|
13
|
+
audio_in: false,
|
|
14
|
+
thinking: model.reasoning,
|
|
15
|
+
tool_use: true,
|
|
16
|
+
max_context_tokens: model.contextWindow > 0 ? model.contextWindow : undefined,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const TAG_FLAGS = {
|
|
20
|
+
image_in: "image_in",
|
|
21
|
+
image: "image_in",
|
|
22
|
+
vision: "image_in",
|
|
23
|
+
video_in: "video_in",
|
|
24
|
+
video: "video_in",
|
|
25
|
+
audio_in: "audio_in",
|
|
26
|
+
audio: "audio_in",
|
|
27
|
+
thinking: "thinking",
|
|
28
|
+
reasoning: "thinking",
|
|
29
|
+
always_thinking: "thinking",
|
|
30
|
+
tool_use: "tool_use",
|
|
31
|
+
tools: "tool_use",
|
|
32
|
+
};
|
|
33
|
+
export function applyDeclaredCapability(base, tags, maxContextSize) {
|
|
34
|
+
const flags = { ...base };
|
|
35
|
+
for (const raw of tags ?? []) {
|
|
36
|
+
const key = TAG_FLAGS[raw.trim().toLowerCase()];
|
|
37
|
+
if (key !== undefined && key !== "max_context_tokens")
|
|
38
|
+
flags[key] = true;
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
...flags,
|
|
42
|
+
max_context_tokens: maxContextSize !== undefined && maxContextSize > 0 ? maxContextSize : base.max_context_tokens,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=capability.js.map
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { Api, AssistantMessage, AssistantMessageEventStream, Model, Provider, ProviderHeaders, Transport } from "../protocol/index.ts";
|
|
2
|
+
import { type ModelRuntime } from "./runtime.ts";
|
|
3
|
+
import type { CallOptions, LlmRequest, RetryHint } from "./model.ts";
|
|
4
|
+
/**
|
|
5
|
+
* How to reach the endpoint, as opposed to how the model should think. Fixed when the model is
|
|
6
|
+
* built, applied to every request it makes.
|
|
7
|
+
*
|
|
8
|
+
* The split from `ModelSettings` is the point: these describe the transport and never vary by
|
|
9
|
+
* agent or by turn, so keeping them here leaves `ModelSettings` free of knobs nobody wants to
|
|
10
|
+
* tune per call. `LlmRequest.providerOptions` still overrides any of them for a single request.
|
|
11
|
+
*
|
|
12
|
+
* Named fields rather than pi's whole `SimpleStreamOptions`: a bag of that shape used to sit on
|
|
13
|
+
* `ModelSpec`, which let `temperature` be configured both here and on an agent with only a
|
|
14
|
+
* silent precedence rule between them. Anything absent from this interface is deliberate — add
|
|
15
|
+
* a field when a knob earns one, instead of reopening the bag.
|
|
16
|
+
*
|
|
17
|
+
* The config-file path (`ProviderConfigSchema` → `ProviderManager`) reaches the same wire
|
|
18
|
+
* settings through provider and model descriptor headers; this is the programmatic equivalent
|
|
19
|
+
* for callers building a `ChatModel` directly.
|
|
20
|
+
*/
|
|
21
|
+
export interface ModelConnection {
|
|
22
|
+
/** Merged over provider and model defaults. A `null` value deletes a header pi would send. */
|
|
23
|
+
readonly headers?: ProviderHeaders;
|
|
24
|
+
/** HTTP request timeout, for providers/SDKs that support it. */
|
|
25
|
+
readonly timeoutMs?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Retries INSIDE the provider call, below `streamWithRetry`. Leave unset: pi defaults it to
|
|
28
|
+
* 0 and the loop's own retry is the one with the context to decide (it can tell a
|
|
29
|
+
* mid-stream failure from a clean one and fall back to non-streaming). Setting it here
|
|
30
|
+
* multiplies with that — 3 loop attempts × N here.
|
|
31
|
+
*/
|
|
32
|
+
readonly maxRetries?: number;
|
|
33
|
+
/** Cap on honoring a server-requested retry delay. pi defaults to 60s; 0 disables the cap. */
|
|
34
|
+
readonly maxRetryDelayMs?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Wire transport. Today only `openai-codex-responses` (the ChatGPT-subscription backend)
|
|
37
|
+
* reads it; every other API ignores it.
|
|
38
|
+
*
|
|
39
|
+
* The default `"auto"` is already the best setting there: a per-session pooled WebSocket
|
|
40
|
+
* that sends only the turn's NEW items, continuing from the connection-scoped
|
|
41
|
+
* `previous_response_id` instead of re-uploading the whole history each round. It falls
|
|
42
|
+
* back to SSE on its own if the socket fails before any content is emitted (after content,
|
|
43
|
+
* it errors rather than replaying), and remembers the fallback for the rest of the session.
|
|
44
|
+
*
|
|
45
|
+
* So the real reason to set this is diagnostic: pin `"sse"` to take the pooling, delta
|
|
46
|
+
* continuation, and sticky-fallback machinery out of the picture when investigating a
|
|
47
|
+
* suspected transport problem.
|
|
48
|
+
*/
|
|
49
|
+
readonly transport?: Transport;
|
|
50
|
+
/** WebSocket connect/open handshake budget; stream idleness still uses `timeoutMs`. */
|
|
51
|
+
readonly websocketConnectTimeoutMs?: number;
|
|
52
|
+
}
|
|
53
|
+
interface ModelSpecBase {
|
|
54
|
+
readonly runtime?: ModelRuntime;
|
|
55
|
+
/** Transport-tier settings applied to every request this model makes. */
|
|
56
|
+
readonly connection?: ModelConnection;
|
|
57
|
+
/**
|
|
58
|
+
* Credential for this model, for the common case of holding a key in code or config rather
|
|
59
|
+
* than in a `CredentialStore`.
|
|
60
|
+
*
|
|
61
|
+
* This OVERRIDES whatever the runtime's credential store resolves for the provider,
|
|
62
|
+
* including a freshly refreshed OAuth token — passing it opts out of `forceRefreshOAuth`
|
|
63
|
+
* recovery for this model. Leave it unset to use ambient credentials (`ANTHROPIC_API_KEY`
|
|
64
|
+
* and friends) or a stored credential, which is what OAuth-based providers want.
|
|
65
|
+
*
|
|
66
|
+
* Scope note: pi models auth per PROVIDER, one credential per provider id. This field is
|
|
67
|
+
* per model, so two `ChatModel`s on the same provider can legitimately carry different
|
|
68
|
+
* keys — useful, but it means this is not a way to configure the provider itself.
|
|
69
|
+
*/
|
|
70
|
+
readonly apiKey?: string;
|
|
71
|
+
}
|
|
72
|
+
export type ModelSpec = (ModelSpecBase & {
|
|
73
|
+
readonly provider: string;
|
|
74
|
+
readonly model: string;
|
|
75
|
+
readonly baseUrl?: string;
|
|
76
|
+
}) | (ModelSpecBase & {
|
|
77
|
+
readonly descriptor: Model<Api>;
|
|
78
|
+
/** A descriptor needs the Models collection that owns its provider. */
|
|
79
|
+
readonly runtime: ModelRuntime;
|
|
80
|
+
});
|
|
81
|
+
export declare class ChatModel {
|
|
82
|
+
readonly id: string;
|
|
83
|
+
readonly provider: Provider;
|
|
84
|
+
readonly api: Api;
|
|
85
|
+
readonly contextWindow: number;
|
|
86
|
+
/** Upper bound on tokens this model can emit in one response. Compaction sizes the room it
|
|
87
|
+
* holds back for the summary against this — a model that cannot emit 20k never needs 20k
|
|
88
|
+
* reserved. */
|
|
89
|
+
readonly maxOutputTokens: number;
|
|
90
|
+
readonly supportsDeferredTools: boolean;
|
|
91
|
+
private readonly piModel;
|
|
92
|
+
private readonly runtime;
|
|
93
|
+
/** Build-time settings (`apiKey` + `connection`) flattened once into pi's option shape.
|
|
94
|
+
* Every request starts from these; `params` and `providerOptions` layer on top. */
|
|
95
|
+
private readonly requestDefaults;
|
|
96
|
+
constructor(spec: ModelSpec);
|
|
97
|
+
stream(req: LlmRequest, call?: CallOptions): AssistantMessageEventStream;
|
|
98
|
+
complete(req: LlmRequest, call?: CallOptions): Promise<AssistantMessage>;
|
|
99
|
+
private streamWithAuthRetry;
|
|
100
|
+
/** Stream one attempt. Non-terminal events are relayed live; the terminal event is held so
|
|
101
|
+
* a clean pre-content failure can be retried instead of surfaced. */
|
|
102
|
+
private runAttempt;
|
|
103
|
+
classifyError(err: unknown): RetryHint;
|
|
104
|
+
private errorEvent;
|
|
105
|
+
private errorMessage;
|
|
106
|
+
}
|
|
107
|
+
export declare function defineModel(spec: ModelSpec): ChatModel;
|
|
108
|
+
export declare function tryGetPiModel(provider: string, model: string, runtime?: ModelRuntime): Model<Api> | undefined;
|
|
109
|
+
export {};
|
|
110
|
+
//# sourceMappingURL=define-model.d.ts.map
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { createAssistantMessageEventStream } from "@earendil-works/pi-ai";
|
|
2
|
+
import { emptyUsage } from "../loop/usage.js";
|
|
3
|
+
import { createModelRuntime, forceRefreshOAuth, } from "./runtime.js";
|
|
4
|
+
import { classifyError } from "./errors.js";
|
|
5
|
+
export class ChatModel {
|
|
6
|
+
id;
|
|
7
|
+
provider;
|
|
8
|
+
api;
|
|
9
|
+
contextWindow;
|
|
10
|
+
/** Upper bound on tokens this model can emit in one response. Compaction sizes the room it
|
|
11
|
+
* holds back for the summary against this — a model that cannot emit 20k never needs 20k
|
|
12
|
+
* reserved. */
|
|
13
|
+
maxOutputTokens;
|
|
14
|
+
supportsDeferredTools;
|
|
15
|
+
piModel;
|
|
16
|
+
runtime;
|
|
17
|
+
/** Build-time settings (`apiKey` + `connection`) flattened once into pi's option shape.
|
|
18
|
+
* Every request starts from these; `params` and `providerOptions` layer on top. */
|
|
19
|
+
requestDefaults;
|
|
20
|
+
constructor(spec) {
|
|
21
|
+
this.runtime = spec.runtime ?? createModelRuntime();
|
|
22
|
+
this.piModel = resolvePiModel(spec, this.runtime);
|
|
23
|
+
this.requestDefaults = {
|
|
24
|
+
...(spec.apiKey !== undefined ? { apiKey: spec.apiKey } : {}),
|
|
25
|
+
...spec.connection,
|
|
26
|
+
};
|
|
27
|
+
this.id = this.piModel.id;
|
|
28
|
+
this.provider = this.piModel.provider;
|
|
29
|
+
this.api = this.piModel.api;
|
|
30
|
+
this.contextWindow = this.piModel.contextWindow;
|
|
31
|
+
this.maxOutputTokens = this.piModel.maxTokens;
|
|
32
|
+
this.supportsDeferredTools = supportsNativeDeferredTools(this.piModel);
|
|
33
|
+
}
|
|
34
|
+
stream(req, call) {
|
|
35
|
+
const ctx = toContext(req);
|
|
36
|
+
// Models performs provider lookup, auth resolution, OAuth expiry refresh,
|
|
37
|
+
// credential-specific baseUrl/headers, and lazy API dispatch.
|
|
38
|
+
const out = createAssistantMessageEventStream();
|
|
39
|
+
void this.streamWithAuthRetry(req, call, ctx, out);
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
async complete(req, call) {
|
|
43
|
+
const ctx = toContext(req);
|
|
44
|
+
let first;
|
|
45
|
+
try {
|
|
46
|
+
first = await this.runtime.models.completeSimple(this.piModel, ctx, toOptions(req, call, this.requestDefaults));
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
first = this.errorMessage(messageOf(error));
|
|
50
|
+
}
|
|
51
|
+
if (first.stopReason !== "error" || !isAuthError(first.errorMessage ?? "")) {
|
|
52
|
+
return first;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
if (!(await forceRefreshOAuth(this.runtime, this.provider, call?.signal)))
|
|
56
|
+
return first;
|
|
57
|
+
return await this.runtime.models.completeSimple(this.piModel, ctx, toOptions(req, call, this.requestDefaults));
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
return this.errorMessage(messageOf(error));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async streamWithAuthRetry(req, call, ctx, out) {
|
|
64
|
+
const first = await this.runAttempt(req, call, ctx, out);
|
|
65
|
+
if (first.resolved)
|
|
66
|
+
return;
|
|
67
|
+
// pi refreshes expired OAuth credentials. Preserve Operon's additional
|
|
68
|
+
// revoked-token recovery: one forced refresh after a clean pre-content 401.
|
|
69
|
+
if (isAuthError(first.errorMessage)) {
|
|
70
|
+
try {
|
|
71
|
+
if (!(await forceRefreshOAuth(this.runtime, this.provider, call?.signal))) {
|
|
72
|
+
out.push(first.terminal);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
out.push(this.errorEvent(messageOf(error)));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const second = await this.runAttempt(req, call, ctx, out);
|
|
81
|
+
if (!second.resolved)
|
|
82
|
+
out.push(second.terminal); // retry also failed → machine
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
out.push(first.terminal); // not a refreshable auth error → machine
|
|
86
|
+
}
|
|
87
|
+
/** Stream one attempt. Non-terminal events are relayed live; the terminal event is held so
|
|
88
|
+
* a clean pre-content failure can be retried instead of surfaced. */
|
|
89
|
+
async runAttempt(req, call, ctx, out) {
|
|
90
|
+
let streamedContent = false;
|
|
91
|
+
let terminal;
|
|
92
|
+
try {
|
|
93
|
+
for await (const event of this.runtime.models.streamSimple(this.piModel, ctx, toOptions(req, call, this.requestDefaults))) {
|
|
94
|
+
if (event.type === "done" || event.type === "error") {
|
|
95
|
+
terminal = event;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
out.push(event);
|
|
99
|
+
if (isContentEvent(event))
|
|
100
|
+
streamedContent = true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
terminal = this.errorEvent(messageOf(error));
|
|
105
|
+
}
|
|
106
|
+
if (terminal === undefined)
|
|
107
|
+
return { resolved: true }; // (pi always emits a terminal)
|
|
108
|
+
const errorMessage = terminalErrorMessage(terminal);
|
|
109
|
+
if (errorMessage === undefined || streamedContent) {
|
|
110
|
+
out.push(terminal); // success, or a mid-stream error we must not retry → machine
|
|
111
|
+
return { resolved: true };
|
|
112
|
+
}
|
|
113
|
+
return { resolved: false, errorMessage, terminal };
|
|
114
|
+
}
|
|
115
|
+
classifyError(err) {
|
|
116
|
+
return classifyError(err);
|
|
117
|
+
}
|
|
118
|
+
errorEvent(text) {
|
|
119
|
+
return { type: "error", reason: "error", error: this.errorMessage(text) };
|
|
120
|
+
}
|
|
121
|
+
errorMessage(text) {
|
|
122
|
+
return {
|
|
123
|
+
role: "assistant",
|
|
124
|
+
content: [],
|
|
125
|
+
api: this.api,
|
|
126
|
+
provider: this.provider,
|
|
127
|
+
model: this.id,
|
|
128
|
+
usage: emptyUsage(),
|
|
129
|
+
stopReason: "error",
|
|
130
|
+
errorMessage: text,
|
|
131
|
+
timestamp: Date.now(),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function messageOf(error) {
|
|
136
|
+
return error instanceof Error ? error.message : String(error);
|
|
137
|
+
}
|
|
138
|
+
/** The error message of a terminal event, or undefined if it represents success.
|
|
139
|
+
* pi reports failures either as an `error` event or a `done` whose message stopped on error. */
|
|
140
|
+
function terminalErrorMessage(event) {
|
|
141
|
+
if (event.type === "error")
|
|
142
|
+
return event.error.errorMessage ?? "stream error";
|
|
143
|
+
if (event.type === "done" && event.message.stopReason === "error")
|
|
144
|
+
return event.message.errorMessage ?? "stream error";
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
/** Whether an event carries real model output — so a forced auth retry never duplicates
|
|
148
|
+
* streamed content. Empty start/end scaffolding does not count. */
|
|
149
|
+
function isContentEvent(event) {
|
|
150
|
+
switch (event.type) {
|
|
151
|
+
case "text_delta":
|
|
152
|
+
case "thinking_delta":
|
|
153
|
+
case "toolcall_delta":
|
|
154
|
+
return event.delta.length > 0;
|
|
155
|
+
case "toolcall_end":
|
|
156
|
+
return true;
|
|
157
|
+
default:
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const AUTH_ERROR_PATTERN = /\b401\b|unauthorized|invalid[\s_-]?api[\s_-]?key|authentication\s+(?:failed|error)|invalid[\s_-]?(?:token|credential)|token\s+(?:expired|revoked)/i;
|
|
162
|
+
/** Heuristic: does this provider error look like an auth failure worth a forced token refresh? */
|
|
163
|
+
function isAuthError(message) {
|
|
164
|
+
return AUTH_ERROR_PATTERN.test(message);
|
|
165
|
+
}
|
|
166
|
+
export function defineModel(spec) {
|
|
167
|
+
return new ChatModel(spec);
|
|
168
|
+
}
|
|
169
|
+
function resolvePiModel(spec, runtime) {
|
|
170
|
+
if ("descriptor" in spec)
|
|
171
|
+
return spec.descriptor;
|
|
172
|
+
const model = tryGetPiModel(spec.provider, spec.model, runtime);
|
|
173
|
+
if (!model)
|
|
174
|
+
throw new Error(`unknown model: ${spec.provider}/${spec.model}`);
|
|
175
|
+
return spec.baseUrl ? { ...model, baseUrl: spec.baseUrl } : model;
|
|
176
|
+
}
|
|
177
|
+
export function tryGetPiModel(provider, model, runtime = createModelRuntime()) {
|
|
178
|
+
return runtime.models.getModel(provider, model);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Mirror pi's public model-compat gates so Operon only hides capability tools
|
|
182
|
+
* when the selected wire can materialize `addedToolNames`. pi remains the
|
|
183
|
+
* authority for serialization; this gate only decides whether SearchTool mode
|
|
184
|
+
* is safe to enter.
|
|
185
|
+
*/
|
|
186
|
+
function supportsNativeDeferredTools(model) {
|
|
187
|
+
const compat = model.compat;
|
|
188
|
+
if (model.api === "openai-completions")
|
|
189
|
+
return compat?.deferredToolsMode === "kimi";
|
|
190
|
+
if (model.api === "openai-responses" || model.api === "openai-codex-responses") {
|
|
191
|
+
return compat?.supportsToolSearch === true;
|
|
192
|
+
}
|
|
193
|
+
if (model.api !== "anthropic-messages")
|
|
194
|
+
return false;
|
|
195
|
+
if (compat?.supportsToolReferences !== undefined)
|
|
196
|
+
return compat.supportsToolReferences;
|
|
197
|
+
// pi's Anthropic default: first-party Claude >= 4.5, excluding Haiku.
|
|
198
|
+
if (model.provider !== "anthropic" || model.id.includes("haiku"))
|
|
199
|
+
return false;
|
|
200
|
+
const version = model.id.match(/^claude-(?:opus|sonnet|fable)-(\d+)(?:-(\d+))?(?:-|$)/);
|
|
201
|
+
if (!version)
|
|
202
|
+
return false;
|
|
203
|
+
const major = Number(version[1]);
|
|
204
|
+
const minor = version[2] && version[2].length < 8 ? Number(version[2]) : 0;
|
|
205
|
+
return major > 4 || (major === 4 && minor >= 5);
|
|
206
|
+
}
|
|
207
|
+
function toContext(req) {
|
|
208
|
+
return {
|
|
209
|
+
systemPrompt: req.system,
|
|
210
|
+
messages: [...req.messages],
|
|
211
|
+
tools: req.tools?.map(toPiTool),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function toPiTool(tool) {
|
|
215
|
+
return {
|
|
216
|
+
name: tool.name,
|
|
217
|
+
description: tool.description,
|
|
218
|
+
// protocol-level params are a JSON Schema object; pi serializes it as the tool schema.
|
|
219
|
+
parameters: tool.parameters,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Map our request onto pi's simple stream options. Ordering IS the precedence rule, lowest
|
|
224
|
+
* first: the model's build-time defaults (`apiKey` + `connection`), then `params` (agent
|
|
225
|
+
* profile + session runtime, already folded by `resolveModelParams`), then the caller's
|
|
226
|
+
* signal, and `providerOptions` last so the extension escape hatch overrides anything above it.
|
|
227
|
+
*
|
|
228
|
+
* The two lower tiers do not overlap by construction — `ModelConnection` is transport, `params`
|
|
229
|
+
* is inference — so the order between them only matters if pi ever merges the two vocabularies.
|
|
230
|
+
*/
|
|
231
|
+
function toOptions(req, call, defaults) {
|
|
232
|
+
return {
|
|
233
|
+
...defaults,
|
|
234
|
+
...(req.params?.thinking !== undefined
|
|
235
|
+
? { reasoning: req.params.thinking }
|
|
236
|
+
: {}),
|
|
237
|
+
// Only meaningful alongside `reasoning`: pi reads it from `adjustMaxTokensForThinking`,
|
|
238
|
+
// which `streamSimple` skips entirely when no reasoning level was requested.
|
|
239
|
+
...(req.params?.thinkingBudgets !== undefined
|
|
240
|
+
? { thinkingBudgets: req.params.thinkingBudgets }
|
|
241
|
+
: {}),
|
|
242
|
+
...(req.params?.temperature !== undefined
|
|
243
|
+
? { temperature: req.params.temperature }
|
|
244
|
+
: {}),
|
|
245
|
+
...(req.params?.maxTokens !== undefined
|
|
246
|
+
? { maxTokens: req.params.maxTokens }
|
|
247
|
+
: {}),
|
|
248
|
+
...(call?.signal !== undefined ? { signal: call.signal } : {}),
|
|
249
|
+
...req.providerOptions,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=define-model.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { RetryHint } from "./model.ts";
|
|
2
|
+
export declare class ChatProviderError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class APIConnectionError extends ChatProviderError {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class APITimeoutError extends ChatProviderError {
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
|
11
|
+
export declare class APIStatusError extends ChatProviderError {
|
|
12
|
+
readonly statusCode: number;
|
|
13
|
+
readonly requestId: string | null;
|
|
14
|
+
constructor(statusCode: number, message: string, requestId?: string | null);
|
|
15
|
+
}
|
|
16
|
+
export declare class APIContextOverflowError extends APIStatusError {
|
|
17
|
+
constructor(statusCode: number, message: string, requestId?: string | null);
|
|
18
|
+
}
|
|
19
|
+
export declare class APIEmptyResponseError extends ChatProviderError {
|
|
20
|
+
constructor(message: string);
|
|
21
|
+
}
|
|
22
|
+
export declare function isRetryableGenerateError(error: unknown): boolean;
|
|
23
|
+
export declare function isContextOverflowErrorCode(code: string | null | undefined): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Message-text-only overflow detection, for the paths where the transport has already reduced
|
|
26
|
+
* the error to a string (model adapters fold thrown errors into `stopReason: "error"` messages,
|
|
27
|
+
* so class and status code are gone by the time the loop sees them).
|
|
28
|
+
*/
|
|
29
|
+
export declare function isContextOverflowMessage(message: string): boolean;
|
|
30
|
+
export declare function isContextOverflowStatusError(statusCode: number, message: string): boolean;
|
|
31
|
+
export declare function normalizeAPIStatusError(statusCode: number, message: string, requestId?: string | null): APIStatusError;
|
|
32
|
+
export declare function classifyError(error: unknown): RetryHint;
|
|
33
|
+
//# sourceMappingURL=errors.d.ts.map
|