@qjp88995/agent-runtime 0.0.0-stage → 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/dist/agent-extensions.d.ts +30 -0
- package/dist/agent-extensions.d.ts.map +1 -0
- package/dist/agent-extensions.js +4 -0
- package/dist/agent-extensions.js.map +1 -0
- package/dist/builtins/ask-outcome.d.ts +49 -0
- package/dist/builtins/ask-outcome.d.ts.map +1 -0
- package/dist/builtins/ask-outcome.js +128 -0
- package/dist/builtins/ask-outcome.js.map +1 -0
- package/dist/builtins/ask-schema.d.ts +110 -0
- package/dist/builtins/ask-schema.d.ts.map +1 -0
- package/dist/builtins/ask-schema.js +124 -0
- package/dist/builtins/ask-schema.js.map +1 -0
- package/dist/builtins/ask.service.d.ts +210 -0
- package/dist/builtins/ask.service.d.ts.map +1 -0
- package/dist/builtins/ask.service.js +373 -0
- package/dist/builtins/ask.service.js.map +1 -0
- package/dist/builtins/ask.tool.d.ts +49 -0
- package/dist/builtins/ask.tool.d.ts.map +1 -0
- package/dist/builtins/ask.tool.js +109 -0
- package/dist/builtins/ask.tool.js.map +1 -0
- package/dist/builtins/index.d.ts +8 -0
- package/dist/builtins/index.d.ts.map +1 -0
- package/dist/builtins/index.js +8 -0
- package/dist/builtins/index.js.map +1 -0
- package/dist/builtins/todo-schema.d.ts +90 -0
- package/dist/builtins/todo-schema.d.ts.map +1 -0
- package/dist/builtins/todo-schema.js +97 -0
- package/dist/builtins/todo-schema.js.map +1 -0
- package/dist/builtins/todo-settle.hook.d.ts +110 -0
- package/dist/builtins/todo-settle.hook.d.ts.map +1 -0
- package/dist/builtins/todo-settle.hook.js +174 -0
- package/dist/builtins/todo-settle.hook.js.map +1 -0
- package/dist/builtins/todo.tool.d.ts +59 -0
- package/dist/builtins/todo.tool.d.ts.map +1 -0
- package/dist/builtins/todo.tool.js +107 -0
- package/dist/builtins/todo.tool.js.map +1 -0
- package/dist/context/context-budget-tracker.d.ts +185 -0
- package/dist/context/context-budget-tracker.d.ts.map +1 -0
- package/dist/context/context-budget-tracker.js +400 -0
- package/dist/context/context-budget-tracker.js.map +1 -0
- package/dist/context/context-budget.d.ts +48 -0
- package/dist/context/context-budget.d.ts.map +1 -0
- package/dist/context/context-budget.js +89 -0
- package/dist/context/context-budget.js.map +1 -0
- package/dist/context/index.d.ts +3 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +3 -0
- package/dist/context/index.js.map +1 -0
- package/dist/extensions/repeat-call.hook.d.ts +32 -0
- package/dist/extensions/repeat-call.hook.d.ts.map +1 -0
- package/dist/extensions/repeat-call.hook.js +54 -0
- package/dist/extensions/repeat-call.hook.js.map +1 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +3 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/turn-hook.registry.d.ts +51 -0
- package/dist/hooks/turn-hook.registry.d.ts.map +1 -0
- package/dist/hooks/turn-hook.registry.js +233 -0
- package/dist/hooks/turn-hook.registry.js.map +1 -0
- package/dist/hooks/turn-hook.types.d.ts +179 -0
- package/dist/hooks/turn-hook.types.d.ts.map +1 -0
- package/dist/hooks/turn-hook.types.js +48 -0
- package/dist/hooks/turn-hook.types.js.map +1 -0
- package/dist/images/byte-cache.d.ts +24 -0
- package/dist/images/byte-cache.d.ts.map +1 -0
- package/dist/images/byte-cache.js +51 -0
- package/dist/images/byte-cache.js.map +1 -0
- package/dist/images/delivery.d.ts +115 -0
- package/dist/images/delivery.d.ts.map +1 -0
- package/dist/images/delivery.js +321 -0
- package/dist/images/delivery.js.map +1 -0
- package/dist/images/index.d.ts +5 -0
- package/dist/images/index.d.ts.map +1 -0
- package/dist/images/index.js +5 -0
- package/dist/images/index.js.map +1 -0
- package/dist/images/prompt.d.ts +151 -0
- package/dist/images/prompt.d.ts.map +1 -0
- package/dist/images/prompt.js +172 -0
- package/dist/images/prompt.js.map +1 -0
- package/dist/images/vendor-files.d.ts +93 -0
- package/dist/images/vendor-files.d.ts.map +1 -0
- package/dist/images/vendor-files.js +156 -0
- package/dist/images/vendor-files.js.map +1 -0
- package/dist/in-process/conversation-store.d.ts +64 -0
- package/dist/in-process/conversation-store.d.ts.map +1 -0
- package/dist/in-process/conversation-store.js +222 -0
- package/dist/in-process/conversation-store.js.map +1 -0
- package/dist/in-process/coordination.d.ts +54 -0
- package/dist/in-process/coordination.d.ts.map +1 -0
- package/dist/in-process/coordination.js +137 -0
- package/dist/in-process/coordination.js.map +1 -0
- package/dist/in-process/image-source.d.ts +15 -0
- package/dist/in-process/image-source.d.ts.map +1 -0
- package/dist/in-process/image-source.js +27 -0
- package/dist/in-process/image-source.js.map +1 -0
- package/dist/in-process/index.d.ts +36 -0
- package/dist/in-process/index.d.ts.map +1 -0
- package/dist/in-process/index.js +37 -0
- package/dist/in-process/index.js.map +1 -0
- package/dist/in-process/question-store.d.ts +28 -0
- package/dist/in-process/question-store.d.ts.map +1 -0
- package/dist/in-process/question-store.js +122 -0
- package/dist/in-process/question-store.js.map +1 -0
- package/dist/in-process/run-store.d.ts +36 -0
- package/dist/in-process/run-store.d.ts.map +1 -0
- package/dist/in-process/run-store.js +81 -0
- package/dist/in-process/run-store.js.map +1 -0
- package/dist/in-process/session-store.d.ts +33 -0
- package/dist/in-process/session-store.d.ts.map +1 -0
- package/dist/in-process/session-store.js +93 -0
- package/dist/in-process/session-store.js.map +1 -0
- package/dist/in-process/stream-bus.d.ts +52 -0
- package/dist/in-process/stream-bus.d.ts.map +1 -0
- package/dist/in-process/stream-bus.js +200 -0
- package/dist/in-process/stream-bus.js.map +1 -0
- package/dist/in-process/vendor-file-cache.d.ts +11 -0
- package/dist/in-process/vendor-file-cache.d.ts.map +1 -0
- package/dist/in-process/vendor-file-cache.js +47 -0
- package/dist/in-process/vendor-file-cache.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/loop/active-tick.registry.d.ts +31 -0
- package/dist/loop/active-tick.registry.d.ts.map +1 -0
- package/dist/loop/active-tick.registry.js +45 -0
- package/dist/loop/active-tick.registry.js.map +1 -0
- package/dist/loop/index.d.ts +6 -0
- package/dist/loop/index.d.ts.map +1 -0
- package/dist/loop/index.js +6 -0
- package/dist/loop/index.js.map +1 -0
- package/dist/loop/loop-driver.d.ts +127 -0
- package/dist/loop/loop-driver.d.ts.map +1 -0
- package/dist/loop/loop-driver.js +199 -0
- package/dist/loop/loop-driver.js.map +1 -0
- package/dist/loop/message-hub.d.ts +236 -0
- package/dist/loop/message-hub.d.ts.map +1 -0
- package/dist/loop/message-hub.js +439 -0
- package/dist/loop/message-hub.js.map +1 -0
- package/dist/loop/orphan-run.sweeper.d.ts +79 -0
- package/dist/loop/orphan-run.sweeper.d.ts.map +1 -0
- package/dist/loop/orphan-run.sweeper.js +145 -0
- package/dist/loop/orphan-run.sweeper.js.map +1 -0
- package/dist/loop/root-host.d.ts +51 -0
- package/dist/loop/root-host.d.ts.map +1 -0
- package/dist/loop/root-host.js +65 -0
- package/dist/loop/root-host.js.map +1 -0
- package/dist/ports/context-store.d.ts +69 -0
- package/dist/ports/context-store.d.ts.map +1 -0
- package/dist/ports/context-store.js +2 -0
- package/dist/ports/context-store.js.map +1 -0
- package/dist/ports/conversation-store.d.ts +144 -0
- package/dist/ports/conversation-store.d.ts.map +1 -0
- package/dist/ports/conversation-store.js +2 -0
- package/dist/ports/conversation-store.js.map +1 -0
- package/dist/ports/coordination.d.ts +76 -0
- package/dist/ports/coordination.d.ts.map +1 -0
- package/dist/ports/coordination.js +12 -0
- package/dist/ports/coordination.js.map +1 -0
- package/dist/ports/image-source.d.ts +26 -0
- package/dist/ports/image-source.d.ts.map +1 -0
- package/dist/ports/image-source.js +2 -0
- package/dist/ports/image-source.js.map +1 -0
- package/dist/ports/index.d.ts +11 -0
- package/dist/ports/index.d.ts.map +1 -0
- package/dist/ports/index.js +4 -0
- package/dist/ports/index.js.map +1 -0
- package/dist/ports/logger.d.ts +14 -0
- package/dist/ports/logger.d.ts.map +1 -0
- package/dist/ports/logger.js +23 -0
- package/dist/ports/logger.js.map +1 -0
- package/dist/ports/question-store.d.ts +91 -0
- package/dist/ports/question-store.d.ts.map +1 -0
- package/dist/ports/question-store.js +8 -0
- package/dist/ports/question-store.js.map +1 -0
- package/dist/ports/run-store.d.ts +66 -0
- package/dist/ports/run-store.d.ts.map +1 -0
- package/dist/ports/run-store.js +2 -0
- package/dist/ports/run-store.js.map +1 -0
- package/dist/ports/session-store.d.ts +72 -0
- package/dist/ports/session-store.d.ts.map +1 -0
- package/dist/ports/session-store.js +9 -0
- package/dist/ports/session-store.js.map +1 -0
- package/dist/ports/stream-bus.d.ts +52 -0
- package/dist/ports/stream-bus.d.ts.map +1 -0
- package/dist/ports/stream-bus.js +2 -0
- package/dist/ports/stream-bus.js.map +1 -0
- package/dist/ports/vendor-file-cache.d.ts +46 -0
- package/dist/ports/vendor-file-cache.d.ts.map +1 -0
- package/dist/ports/vendor-file-cache.js +2 -0
- package/dist/ports/vendor-file-cache.js.map +1 -0
- package/dist/schema/agent-event.d.ts +35 -0
- package/dist/schema/agent-event.d.ts.map +1 -0
- package/dist/schema/agent-event.js +46 -0
- package/dist/schema/agent-event.js.map +1 -0
- package/dist/schema/agent-run.d.ts +23 -0
- package/dist/schema/agent-run.d.ts.map +1 -0
- package/dist/schema/agent-run.js +37 -0
- package/dist/schema/agent-run.js.map +1 -0
- package/dist/schema/index.d.ts +4 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +4 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/message-part.d.ts +73 -0
- package/dist/schema/message-part.d.ts.map +1 -0
- package/dist/schema/message-part.js +90 -0
- package/dist/schema/message-part.js.map +1 -0
- package/dist/subagent/delegate.tool.d.ts +145 -0
- package/dist/subagent/delegate.tool.d.ts.map +1 -0
- package/dist/subagent/delegate.tool.js +329 -0
- package/dist/subagent/delegate.tool.js.map +1 -0
- package/dist/subagent/index.d.ts +10 -0
- package/dist/subagent/index.d.ts.map +1 -0
- package/dist/subagent/index.js +10 -0
- package/dist/subagent/index.js.map +1 -0
- package/dist/subagent/milestone-body.d.ts +82 -0
- package/dist/subagent/milestone-body.d.ts.map +1 -0
- package/dist/subagent/milestone-body.js +112 -0
- package/dist/subagent/milestone-body.js.map +1 -0
- package/dist/subagent/output-scan.d.ts +14 -0
- package/dist/subagent/output-scan.d.ts.map +1 -0
- package/dist/subagent/output-scan.js +41 -0
- package/dist/subagent/output-scan.js.map +1 -0
- package/dist/subagent/registry-spawn-policy.d.ts +32 -0
- package/dist/subagent/registry-spawn-policy.d.ts.map +1 -0
- package/dist/subagent/registry-spawn-policy.js +48 -0
- package/dist/subagent/registry-spawn-policy.js.map +1 -0
- package/dist/subagent/roster-block.d.ts +45 -0
- package/dist/subagent/roster-block.d.ts.map +1 -0
- package/dist/subagent/roster-block.js +69 -0
- package/dist/subagent/roster-block.js.map +1 -0
- package/dist/subagent/situation-block.d.ts +16 -0
- package/dist/subagent/situation-block.d.ts.map +1 -0
- package/dist/subagent/situation-block.js +71 -0
- package/dist/subagent/situation-block.js.map +1 -0
- package/dist/subagent/spawn-guards.d.ts +32 -0
- package/dist/subagent/spawn-guards.d.ts.map +1 -0
- package/dist/subagent/spawn-guards.js +39 -0
- package/dist/subagent/spawn-guards.js.map +1 -0
- package/dist/subagent/subagent-registry.d.ts +150 -0
- package/dist/subagent/subagent-registry.d.ts.map +1 -0
- package/dist/subagent/subagent-registry.js +167 -0
- package/dist/subagent/subagent-registry.js.map +1 -0
- package/dist/subagent/subagent-sessions.d.ts +213 -0
- package/dist/subagent/subagent-sessions.d.ts.map +1 -0
- package/dist/subagent/subagent-sessions.js +295 -0
- package/dist/subagent/subagent-sessions.js.map +1 -0
- package/dist/testing/contracts.d.ts +37 -0
- package/dist/testing/contracts.d.ts.map +1 -0
- package/dist/testing/contracts.js +607 -0
- package/dist/testing/contracts.js.map +1 -0
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +5 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/stub.d.ts +28 -0
- package/dist/testing/stub.d.ts.map +1 -0
- package/dist/testing/stub.js +3 -0
- package/dist/testing/stub.js.map +1 -0
- package/dist/tools/agent-tool.base.d.ts +186 -0
- package/dist/tools/agent-tool.base.d.ts.map +1 -0
- package/dist/tools/agent-tool.base.js +243 -0
- package/dist/tools/agent-tool.base.js.map +1 -0
- package/dist/tools/agent-tool.interface.d.ts +95 -0
- package/dist/tools/agent-tool.interface.d.ts.map +1 -0
- package/dist/tools/agent-tool.interface.js +2 -0
- package/dist/tools/agent-tool.interface.js.map +1 -0
- package/dist/tools/builtin-names.d.ts +18 -0
- package/dist/tools/builtin-names.d.ts.map +1 -0
- package/dist/tools/builtin-names.js +20 -0
- package/dist/tools/builtin-names.js.map +1 -0
- package/dist/tools/index.d.ts +9 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +6 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/tool-definition.d.ts +18 -0
- package/dist/tools/tool-definition.d.ts.map +1 -0
- package/dist/tools/tool-definition.js +77 -0
- package/dist/tools/tool-definition.js.map +1 -0
- package/dist/tools/tool-meta.d.ts +55 -0
- package/dist/tools/tool-meta.d.ts.map +1 -0
- package/dist/tools/tool-meta.js +2 -0
- package/dist/tools/tool-meta.js.map +1 -0
- package/dist/tools/tool-registry.d.ts +190 -0
- package/dist/tools/tool-registry.d.ts.map +1 -0
- package/dist/tools/tool-registry.js +379 -0
- package/dist/tools/tool-registry.js.map +1 -0
- package/dist/tools/tool-result.d.ts +41 -0
- package/dist/tools/tool-result.d.ts.map +1 -0
- package/dist/tools/tool-result.js +19 -0
- package/dist/tools/tool-result.js.map +1 -0
- package/dist/tools/tool-wire.d.ts +24 -0
- package/dist/tools/tool-wire.d.ts.map +1 -0
- package/dist/tools/tool-wire.js +2 -0
- package/dist/tools/tool-wire.js.map +1 -0
- package/dist/turn/agent-runtime.d.ts +31 -0
- package/dist/turn/agent-runtime.d.ts.map +1 -0
- package/dist/turn/agent-runtime.js +30 -0
- package/dist/turn/agent-runtime.js.map +1 -0
- package/dist/turn/chunk-projection.d.ts +32 -0
- package/dist/turn/chunk-projection.d.ts.map +1 -0
- package/dist/turn/chunk-projection.js +62 -0
- package/dist/turn/chunk-projection.js.map +1 -0
- package/dist/turn/compaction.d.ts +48 -0
- package/dist/turn/compaction.d.ts.map +1 -0
- package/dist/turn/compaction.js +89 -0
- package/dist/turn/compaction.js.map +1 -0
- package/dist/turn/context-overflow.d.ts +11 -0
- package/dist/turn/context-overflow.d.ts.map +1 -0
- package/dist/turn/context-overflow.js +53 -0
- package/dist/turn/context-overflow.js.map +1 -0
- package/dist/turn/context-pressure.d.ts +100 -0
- package/dist/turn/context-pressure.d.ts.map +1 -0
- package/dist/turn/context-pressure.js +21 -0
- package/dist/turn/context-pressure.js.map +1 -0
- package/dist/turn/events-to-steps.d.ts +8 -0
- package/dist/turn/events-to-steps.d.ts.map +1 -0
- package/dist/turn/events-to-steps.js +64 -0
- package/dist/turn/events-to-steps.js.map +1 -0
- package/dist/turn/index.d.ts +17 -0
- package/dist/turn/index.d.ts.map +1 -0
- package/dist/turn/index.js +16 -0
- package/dist/turn/index.js.map +1 -0
- package/dist/turn/json-preview.d.ts +22 -0
- package/dist/turn/json-preview.d.ts.map +1 -0
- package/dist/turn/json-preview.js +34 -0
- package/dist/turn/json-preview.js.map +1 -0
- package/dist/turn/json-string-field.d.ts +30 -0
- package/dist/turn/json-string-field.d.ts.map +1 -0
- package/dist/turn/json-string-field.js +125 -0
- package/dist/turn/json-string-field.js.map +1 -0
- package/dist/turn/loop-reminder.d.ts +79 -0
- package/dist/turn/loop-reminder.d.ts.map +1 -0
- package/dist/turn/loop-reminder.js +0 -0
- package/dist/turn/loop-reminder.js.map +1 -0
- package/dist/turn/nul-safe.d.ts +21 -0
- package/dist/turn/nul-safe.d.ts.map +1 -0
- package/dist/turn/nul-safe.js +23 -0
- package/dist/turn/nul-safe.js.map +1 -0
- package/dist/turn/parts-from-events.d.ts +71 -0
- package/dist/turn/parts-from-events.d.ts.map +1 -0
- package/dist/turn/parts-from-events.js +217 -0
- package/dist/turn/parts-from-events.js.map +1 -0
- package/dist/turn/parts-to-model-messages.d.ts +158 -0
- package/dist/turn/parts-to-model-messages.d.ts.map +1 -0
- package/dist/turn/parts-to-model-messages.js +334 -0
- package/dist/turn/parts-to-model-messages.js.map +1 -0
- package/dist/turn/pending-work.d.ts +10 -0
- package/dist/turn/pending-work.d.ts.map +1 -0
- package/dist/turn/pending-work.js +14 -0
- package/dist/turn/pending-work.js.map +1 -0
- package/dist/turn/provider-error.d.ts +45 -0
- package/dist/turn/provider-error.d.ts.map +1 -0
- package/dist/turn/provider-error.js +154 -0
- package/dist/turn/provider-error.js.map +1 -0
- package/dist/turn/tool-input-preview.d.ts +94 -0
- package/dist/turn/tool-input-preview.d.ts.map +1 -0
- package/dist/turn/tool-input-preview.js +143 -0
- package/dist/turn/tool-input-preview.js.map +1 -0
- package/dist/turn/tool-input-progress.d.ts +47 -0
- package/dist/turn/tool-input-progress.d.ts.map +1 -0
- package/dist/turn/tool-input-progress.js +50 -0
- package/dist/turn/tool-input-progress.js.map +1 -0
- package/dist/turn/turn-envelope.d.ts +184 -0
- package/dist/turn/turn-envelope.d.ts.map +1 -0
- package/dist/turn/turn-envelope.js +2 -0
- package/dist/turn/turn-envelope.js.map +1 -0
- package/dist/turn/turn-journal.d.ts +49 -0
- package/dist/turn/turn-journal.d.ts.map +1 -0
- package/dist/turn/turn-journal.js +51 -0
- package/dist/turn/turn-journal.js.map +1 -0
- package/dist/turn/turn-run.d.ts +487 -0
- package/dist/turn/turn-run.d.ts.map +1 -0
- package/dist/turn/turn-run.js +1167 -0
- package/dist/turn/turn-run.js.map +1 -0
- package/dist/turn/usage.d.ts +27 -0
- package/dist/turn/usage.d.ts.map +1 -0
- package/dist/turn/usage.js +51 -0
- package/dist/turn/usage.js.map +1 -0
- package/package.json +55 -3
- package/src/agent-extensions.ts +33 -0
- package/src/builtins/ask-outcome.ts +168 -0
- package/src/builtins/ask-schema.ts +186 -0
- package/src/builtins/ask.service.ts +482 -0
- package/src/builtins/ask.tool.ts +138 -0
- package/src/builtins/index.ts +25 -0
- package/src/builtins/todo-schema.ts +108 -0
- package/src/builtins/todo-settle.hook.ts +221 -0
- package/src/builtins/todo.tool.ts +134 -0
- package/src/context/context-budget-tracker.ts +519 -0
- package/src/context/context-budget.ts +124 -0
- package/src/context/index.ts +17 -0
- package/src/extensions/repeat-call.hook.ts +77 -0
- package/src/hooks/index.ts +19 -0
- package/src/hooks/turn-hook.registry.ts +307 -0
- package/src/hooks/turn-hook.types.ts +210 -0
- package/src/images/byte-cache.ts +61 -0
- package/src/images/delivery.ts +508 -0
- package/src/images/index.ts +35 -0
- package/src/images/prompt.ts +289 -0
- package/src/images/vendor-files.ts +235 -0
- package/src/in-process/conversation-store.ts +304 -0
- package/src/in-process/coordination.ts +177 -0
- package/src/in-process/image-source.ts +29 -0
- package/src/in-process/index.ts +52 -0
- package/src/in-process/question-store.ts +155 -0
- package/src/in-process/run-store.ts +115 -0
- package/src/in-process/session-store.ts +118 -0
- package/src/in-process/stream-bus.ts +244 -0
- package/src/in-process/vendor-file-cache.ts +67 -0
- package/src/index.ts +28 -0
- package/src/loop/active-tick.registry.ts +49 -0
- package/src/loop/index.ts +25 -0
- package/src/loop/loop-driver.ts +275 -0
- package/src/loop/message-hub.ts +532 -0
- package/src/loop/orphan-run.sweeper.ts +204 -0
- package/src/loop/root-host.ts +119 -0
- package/src/ports/context-store.ts +71 -0
- package/src/ports/conversation-store.ts +165 -0
- package/src/ports/coordination.ts +81 -0
- package/src/ports/image-source.ts +26 -0
- package/src/ports/index.ts +56 -0
- package/src/ports/logger.ts +34 -0
- package/src/ports/question-store.ts +117 -0
- package/src/ports/run-store.ts +69 -0
- package/src/ports/session-store.ts +80 -0
- package/src/ports/stream-bus.ts +59 -0
- package/src/ports/vendor-file-cache.ts +54 -0
- package/src/schema/agent-event.ts +69 -0
- package/src/schema/agent-run.ts +44 -0
- package/src/schema/index.ts +25 -0
- package/src/schema/message-part.ts +100 -0
- package/src/subagent/delegate.tool.ts +476 -0
- package/src/subagent/index.ts +63 -0
- package/src/subagent/milestone-body.ts +144 -0
- package/src/subagent/output-scan.ts +56 -0
- package/src/subagent/registry-spawn-policy.ts +85 -0
- package/src/subagent/roster-block.ts +103 -0
- package/src/subagent/situation-block.ts +83 -0
- package/src/subagent/spawn-guards.ts +54 -0
- package/src/subagent/subagent-registry.ts +283 -0
- package/src/subagent/subagent-sessions.ts +496 -0
- package/src/testing/contracts.ts +882 -0
- package/src/testing/index.ts +14 -0
- package/src/testing/stub.ts +28 -0
- package/src/tools/agent-tool.base.ts +361 -0
- package/src/tools/agent-tool.interface.ts +101 -0
- package/src/tools/builtin-names.ts +26 -0
- package/src/tools/index.ts +39 -0
- package/src/tools/tool-definition.ts +93 -0
- package/src/tools/tool-meta.ts +60 -0
- package/src/tools/tool-registry.ts +513 -0
- package/src/tools/tool-result.ts +45 -0
- package/src/tools/tool-wire.ts +24 -0
- package/src/turn/agent-runtime.ts +43 -0
- package/src/turn/chunk-projection.ts +81 -0
- package/src/turn/compaction.ts +103 -0
- package/src/turn/context-overflow.ts +54 -0
- package/src/turn/context-pressure.ts +114 -0
- package/src/turn/events-to-steps.ts +73 -0
- package/src/turn/index.ts +71 -0
- package/src/turn/json-preview.ts +36 -0
- package/src/turn/json-string-field.ts +134 -0
- package/src/turn/loop-reminder.ts +0 -0
- package/src/turn/nul-safe.ts +22 -0
- package/src/turn/parts-from-events.ts +248 -0
- package/src/turn/parts-to-model-messages.ts +428 -0
- package/src/turn/pending-work.ts +14 -0
- package/src/turn/provider-error.ts +160 -0
- package/src/turn/tool-input-preview.ts +223 -0
- package/src/turn/tool-input-progress.ts +76 -0
- package/src/turn/turn-envelope.ts +185 -0
- package/src/turn/turn-journal.ts +102 -0
- package/src/turn/turn-run.ts +1479 -0
- package/src/turn/usage.ts +56 -0
- package/README.md +0 -3
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type LanguageModel,
|
|
3
|
+
type LanguageModelMiddleware,
|
|
4
|
+
wrapLanguageModel,
|
|
5
|
+
} from 'ai';
|
|
6
|
+
|
|
7
|
+
import { InMemoryVendorFileCache } from '../in-process/vendor-file-cache.js';
|
|
8
|
+
import type { ImageSource } from '../ports/image-source.js';
|
|
9
|
+
import { type Logger, silentLogger } from '../ports/logger.js';
|
|
10
|
+
import type {
|
|
11
|
+
VendorFileCache,
|
|
12
|
+
VendorFileRecord,
|
|
13
|
+
} from '../ports/vendor-file-cache.js';
|
|
14
|
+
import type { LlmHandles, LlmProviderOptions } from '../turn/turn-run.js';
|
|
15
|
+
import {
|
|
16
|
+
DEFAULT_BYTE_CACHE_LIMIT,
|
|
17
|
+
ImageByteCache,
|
|
18
|
+
type LoadedImage,
|
|
19
|
+
} from './byte-cache.js';
|
|
20
|
+
import {
|
|
21
|
+
collectPendingImages,
|
|
22
|
+
DEFAULT_DELIVERY_TEXTS,
|
|
23
|
+
type DeliveredImage,
|
|
24
|
+
deliverImages,
|
|
25
|
+
type DeliveryTexts,
|
|
26
|
+
isPinnedCredentialUnavailable,
|
|
27
|
+
type PendingImage,
|
|
28
|
+
rejectedVendorFiles,
|
|
29
|
+
urlSupported,
|
|
30
|
+
type V4Message,
|
|
31
|
+
} from './prompt.js';
|
|
32
|
+
import {
|
|
33
|
+
DIRECT_ACCOUNT,
|
|
34
|
+
VendorFiles,
|
|
35
|
+
type VendorFileStoreLike,
|
|
36
|
+
} from './vendor-files.js';
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 递送要的那一点模型句柄(provider-client `ModelHandle` 的结构子集;runtime 不依赖那个包,
|
|
40
|
+
* 兼容性由 `tools/live-images` 的类型检查钉住)。
|
|
41
|
+
*/
|
|
42
|
+
export interface ModelHandleLike {
|
|
43
|
+
model: LanguageModel;
|
|
44
|
+
providerOptions?: LlmProviderOptions | undefined;
|
|
45
|
+
replayedMetadataKeys?: readonly string[];
|
|
46
|
+
/** 厂商 Files API;没有为 null(只走公网 URL / base64)。 */
|
|
47
|
+
fileStore: VendorFileStoreLike | null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface ResolveModelOptions {
|
|
51
|
+
reasoningEffort?: string;
|
|
52
|
+
affinity?: string;
|
|
53
|
+
pin?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** provider-client `ModelResolver` 的结构子集(`ProviderClient` / `DirectModelResolver` 都满足)。 */
|
|
57
|
+
export interface ModelResolverLike<H extends ModelHandleLike> {
|
|
58
|
+
resolve(
|
|
59
|
+
ref: { vendor: string; modelId: string },
|
|
60
|
+
options?: ResolveModelOptions
|
|
61
|
+
): Promise<H>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface ImageDeliveryOptions {
|
|
65
|
+
/** 字节从哪来。 */
|
|
66
|
+
source: ImageSource;
|
|
67
|
+
/** Files API 的上传缓存。缺省进程内(`InMemoryVendorFileCache`),多实例换宿主的库实现。 */
|
|
68
|
+
cache?: VendorFileCache;
|
|
69
|
+
/** 上传时的 TTL(秒);省略 = 厂商默认。每次上传读一次,宿主可接系统参数。 */
|
|
70
|
+
ttlSeconds?: () => number | undefined;
|
|
71
|
+
/** 进程内字节缓存上限(缺省 256 MiB)。 */
|
|
72
|
+
byteCacheLimit?: number;
|
|
73
|
+
texts?: Partial<DeliveryTexts>;
|
|
74
|
+
logger?: Logger;
|
|
75
|
+
now?: () => number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** 一次请求的递送结果:改写好的 prompt、用的哪个句柄、哪个账号、交出去了哪些 file id。 */
|
|
79
|
+
interface Attempt {
|
|
80
|
+
prompt: V4Message[];
|
|
81
|
+
handle: ModelHandleLike;
|
|
82
|
+
/** 这次请求钉住的账号(只有中心模式的真 ref 才算;直连 / 未定为 undefined)。 */
|
|
83
|
+
pinned: string | undefined;
|
|
84
|
+
/** 交出去的 file id 落在哪个账号(直连是 `DIRECT_ACCOUNT`)。 */
|
|
85
|
+
account: string | undefined;
|
|
86
|
+
fileIds: string[];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
type CallParams = Parameters<
|
|
90
|
+
NonNullable<LanguageModelMiddleware['wrapStream']>
|
|
91
|
+
>[0]['params'];
|
|
92
|
+
interface CallableModel {
|
|
93
|
+
supportedUrls?:
|
|
94
|
+
PromiseLike<Record<string, RegExp[]>> | Record<string, RegExp[]>;
|
|
95
|
+
doGenerate(params: CallParams): PromiseLike<unknown>;
|
|
96
|
+
doStream(params: CallParams): PromiseLike<unknown>;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function callable(model: LanguageModel): CallableModel {
|
|
100
|
+
if (typeof model === 'string') {
|
|
101
|
+
throw new Error(
|
|
102
|
+
'image delivery needs a model object, not a gateway model id string'
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
return model as unknown as CallableModel;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function basenameOf(path: string): string {
|
|
109
|
+
const i = path.lastIndexOf('/');
|
|
110
|
+
return i >= 0 ? path.slice(i + 1) : path;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 图片递送(agent-base `llm/image-delivery` + `ImageDeliveryService`)。进程级单例:字节缓存与
|
|
115
|
+
* 上传合流跨会话共享;每一轮用 `wrap` 把那一轮的模型句柄包起来。
|
|
116
|
+
*
|
|
117
|
+
* ## 三档(用户拍板,2026-08-27)
|
|
118
|
+
*
|
|
119
|
+
* 1. **厂商 Files API**(句柄有 `fileStore` 时;按 `(厂商, 账号, 字节)` 缓存 file id);
|
|
120
|
+
* 2. **公网 URL**:`ImageSource.publicUrl` 给了、且承载包 `supportedUrls` 认这个地址与媒体类型;
|
|
121
|
+
* 3. **base64**——全线公约数。
|
|
122
|
+
*
|
|
123
|
+
* 每一档失败都退到下一档,**绝不抛**:一张图递不出去要变成一句给模型看的话,不能让这个会话从此
|
|
124
|
+
* 发不出请求。
|
|
125
|
+
*
|
|
126
|
+
* ## pin(中心模式,2026-11-11 定)
|
|
127
|
+
*
|
|
128
|
+
* 厂商文件绑账号,中心又会替我们换 key,所以引用旧文件的请求得 pin 到文件所在的那把。判据在
|
|
129
|
+
* **每次请求时**按这次 prompt 里的图定(prompt 就是完整历史):
|
|
130
|
+
*
|
|
131
|
+
* - 历史里的图在某个账号上有新鲜的 file id → 选覆盖张数最多的那个账号(平手取最近用过的),
|
|
132
|
+
* 用 `resolve(…, { pin })` 造一个钉住它的句柄发这次请求;缺的图也传到这个账号上(上传同样 pin)。
|
|
133
|
+
* - 一个都没有 → 先不 pin 地传第一张(落在中心按粘性选的那把上),拿到 `credentialRef` 后**再 pin
|
|
134
|
+
* 到它**发请求——这样上传与请求一定在同一个账号上,不靠粘性碰运气。
|
|
135
|
+
* - 直连模式(`credentialRef` 为 null)只有一把 key,不 pin。
|
|
136
|
+
*
|
|
137
|
+
* 两种失败各重做一次递送:厂商说 file id 不存在(错误里点名了这次的 id)→ 忘掉它们、重传;
|
|
138
|
+
* 中心说钉住的 key 不可用(409 `pinned_credential_unavailable`)→ 这次请求排除那个账号再挑
|
|
139
|
+
* (多半落到「一个都没有」,重传到新 key 上)。
|
|
140
|
+
*/
|
|
141
|
+
export class ImageDelivery {
|
|
142
|
+
readonly files: VendorFiles;
|
|
143
|
+
private readonly bytes: ImageByteCache;
|
|
144
|
+
private readonly texts: DeliveryTexts;
|
|
145
|
+
private readonly logger: Logger;
|
|
146
|
+
|
|
147
|
+
constructor(private readonly options: ImageDeliveryOptions) {
|
|
148
|
+
this.logger = options.logger ?? silentLogger('ImageDelivery');
|
|
149
|
+
this.files = new VendorFiles({
|
|
150
|
+
cache: options.cache ?? new InMemoryVendorFileCache(),
|
|
151
|
+
ttlSeconds: options.ttlSeconds,
|
|
152
|
+
logger: this.logger,
|
|
153
|
+
now: options.now,
|
|
154
|
+
});
|
|
155
|
+
this.bytes = new ImageByteCache(
|
|
156
|
+
options.source,
|
|
157
|
+
options.byteCacheLimit ?? DEFAULT_BYTE_CACHE_LIMIT
|
|
158
|
+
);
|
|
159
|
+
this.texts = { ...DEFAULT_DELIVERY_TEXTS, ...options.texts };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* 把一轮的模型句柄包成会递送图片的模型。
|
|
164
|
+
*
|
|
165
|
+
* @param vendor 厂商 slug(缓存键的一段)。
|
|
166
|
+
* @param base 不 pin 解析出的句柄(带会话粘性)。没有图的请求原样走它,一个对象都不重建。
|
|
167
|
+
* @param pinned 按 ref 造钉住的句柄(同一个 wrap 内按 ref 记忆)。缺席 = 不 pin(直连)。
|
|
168
|
+
*/
|
|
169
|
+
wrap(args: {
|
|
170
|
+
vendor: string;
|
|
171
|
+
base: ModelHandleLike;
|
|
172
|
+
pinned?: (credentialRef: string) => Promise<ModelHandleLike>;
|
|
173
|
+
}): LanguageModel {
|
|
174
|
+
const memo = new Map<string, Promise<ModelHandleLike>>();
|
|
175
|
+
const pinnedHandle = args.pinned
|
|
176
|
+
? (ref: string) => {
|
|
177
|
+
let p = memo.get(ref);
|
|
178
|
+
if (!p) {
|
|
179
|
+
p = args.pinned!(ref);
|
|
180
|
+
memo.set(ref, p);
|
|
181
|
+
p.catch(() => memo.delete(ref));
|
|
182
|
+
}
|
|
183
|
+
return p;
|
|
184
|
+
}
|
|
185
|
+
: undefined;
|
|
186
|
+
const run = <T>(
|
|
187
|
+
params: CallParams,
|
|
188
|
+
passthrough: () => PromiseLike<T>,
|
|
189
|
+
call: (model: CallableModel, params: CallParams) => PromiseLike<T>
|
|
190
|
+
) =>
|
|
191
|
+
this.run(args.vendor, args.base, pinnedHandle, params, passthrough, call);
|
|
192
|
+
|
|
193
|
+
const middleware: LanguageModelMiddleware = {
|
|
194
|
+
specificationVersion: 'v4',
|
|
195
|
+
wrapGenerate: ({ doGenerate, params }) =>
|
|
196
|
+
run(params, doGenerate, (m, p) => m.doGenerate(p)) as ReturnType<
|
|
197
|
+
typeof doGenerate
|
|
198
|
+
>,
|
|
199
|
+
wrapStream: ({ doStream, params }) =>
|
|
200
|
+
run(params, doStream, (m, p) => m.doStream(p)) as ReturnType<
|
|
201
|
+
typeof doStream
|
|
202
|
+
>,
|
|
203
|
+
};
|
|
204
|
+
return wrapLanguageModel({
|
|
205
|
+
model: callable(args.base.model) as unknown as Exclude<
|
|
206
|
+
LanguageModel,
|
|
207
|
+
string
|
|
208
|
+
>,
|
|
209
|
+
middleware,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
private async run<T>(
|
|
214
|
+
vendor: string,
|
|
215
|
+
base: ModelHandleLike,
|
|
216
|
+
pinnedHandle: ((ref: string) => Promise<ModelHandleLike>) | undefined,
|
|
217
|
+
params: CallParams,
|
|
218
|
+
passthrough: () => PromiseLike<T>,
|
|
219
|
+
call: (model: CallableModel, params: CallParams) => PromiseLike<T>
|
|
220
|
+
): Promise<T> {
|
|
221
|
+
const prompt = params.prompt as unknown as readonly V4Message[];
|
|
222
|
+
const pending = collectPendingImages(prompt);
|
|
223
|
+
// 快路径:一张我们的图都没有就原样放行。
|
|
224
|
+
if (pending.length === 0) return passthrough();
|
|
225
|
+
|
|
226
|
+
const excluded = new Set<string>();
|
|
227
|
+
let staleRetried = false;
|
|
228
|
+
let pinRetried = false;
|
|
229
|
+
for (;;) {
|
|
230
|
+
const attempt = await this.prepare(
|
|
231
|
+
vendor,
|
|
232
|
+
base,
|
|
233
|
+
pinnedHandle,
|
|
234
|
+
prompt,
|
|
235
|
+
pending,
|
|
236
|
+
excluded
|
|
237
|
+
);
|
|
238
|
+
try {
|
|
239
|
+
return await call(callable(attempt.handle.model), {
|
|
240
|
+
...params,
|
|
241
|
+
prompt: attempt.prompt as unknown as CallParams['prompt'],
|
|
242
|
+
});
|
|
243
|
+
} catch (err) {
|
|
244
|
+
const rejected = rejectedVendorFiles(err, attempt.fileIds);
|
|
245
|
+
if (
|
|
246
|
+
!staleRetried &&
|
|
247
|
+
attempt.account !== undefined &&
|
|
248
|
+
rejected.length > 0
|
|
249
|
+
) {
|
|
250
|
+
staleRetried = true;
|
|
251
|
+
await this.files.forget(vendor, attempt.account, rejected);
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
if (
|
|
255
|
+
!pinRetried &&
|
|
256
|
+
attempt.pinned !== undefined &&
|
|
257
|
+
isPinnedCredentialUnavailable(err)
|
|
258
|
+
) {
|
|
259
|
+
pinRetried = true;
|
|
260
|
+
this.logger.warn(
|
|
261
|
+
`pinned credential ${attempt.pinned} of ${vendor} unavailable; re-delivering without it`
|
|
262
|
+
);
|
|
263
|
+
excluded.add(attempt.pinned);
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
throw err;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
private async prepare(
|
|
272
|
+
vendor: string,
|
|
273
|
+
base: ModelHandleLike,
|
|
274
|
+
pinnedHandle: ((ref: string) => Promise<ModelHandleLike>) | undefined,
|
|
275
|
+
prompt: readonly V4Message[],
|
|
276
|
+
pending: readonly PendingImage[],
|
|
277
|
+
excluded: ReadonlySet<string>
|
|
278
|
+
): Promise<Attempt> {
|
|
279
|
+
const loaded = new Map<string, LoadedImage | null>();
|
|
280
|
+
for (const { src } of pending) {
|
|
281
|
+
if (loaded.has(src)) continue;
|
|
282
|
+
try {
|
|
283
|
+
loaded.set(src, await this.bytes.load(src));
|
|
284
|
+
} catch (err) {
|
|
285
|
+
// 对象被删 / 存储不可达:给模型一句话而不是抛——抛了这个会话每次发言都会死在这里。
|
|
286
|
+
this.logger.warn(
|
|
287
|
+
`image ${src} unavailable for delivery: ${String(err)}`
|
|
288
|
+
);
|
|
289
|
+
loaded.set(src, null);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const state: Attempt = {
|
|
294
|
+
prompt: [],
|
|
295
|
+
handle: base,
|
|
296
|
+
pinned: undefined,
|
|
297
|
+
account: undefined,
|
|
298
|
+
fileIds: [],
|
|
299
|
+
};
|
|
300
|
+
const usePin = async (account: string) => {
|
|
301
|
+
state.account = account;
|
|
302
|
+
if (account === DIRECT_ACCOUNT || !pinnedHandle) return;
|
|
303
|
+
try {
|
|
304
|
+
state.handle = await pinnedHandle(account);
|
|
305
|
+
state.pinned = account;
|
|
306
|
+
} catch (err) {
|
|
307
|
+
// 造不出钉住的句柄(目录刷新失败之类):这次不 pin,交给粘性。
|
|
308
|
+
this.logger.warn(`cannot pin ${vendor} to ${account}: ${String(err)}`);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
let records: VendorFileRecord[] = [];
|
|
313
|
+
if (base.fileStore) {
|
|
314
|
+
const hashes = [
|
|
315
|
+
...new Set(
|
|
316
|
+
[...loaded.values()].flatMap(l => (l ? [l.contentHash] : []))
|
|
317
|
+
),
|
|
318
|
+
];
|
|
319
|
+
records = (await this.files.lookup(vendor, hashes)).filter(
|
|
320
|
+
r => !excluded.has(r.account)
|
|
321
|
+
);
|
|
322
|
+
const account = pickAccount(records.filter(r => this.files.isFresh(r)));
|
|
323
|
+
if (account !== undefined) await usePin(account);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const resolve = async (img: PendingImage): Promise<DeliveredImage> => {
|
|
327
|
+
const bytes = loaded.get(img.src);
|
|
328
|
+
if (!bytes) {
|
|
329
|
+
return { kind: 'unavailable', reason: this.texts.unavailable };
|
|
330
|
+
}
|
|
331
|
+
const mediaType = img.mediaType || bytes.contentType;
|
|
332
|
+
|
|
333
|
+
// 1. 厂商 Files API
|
|
334
|
+
const store = state.handle.fileStore;
|
|
335
|
+
if (store) {
|
|
336
|
+
const fileId = await this.vendorFile(
|
|
337
|
+
vendor,
|
|
338
|
+
store,
|
|
339
|
+
img,
|
|
340
|
+
bytes,
|
|
341
|
+
mediaType,
|
|
342
|
+
records,
|
|
343
|
+
state,
|
|
344
|
+
usePin
|
|
345
|
+
);
|
|
346
|
+
if (fileId) {
|
|
347
|
+
state.fileIds.push(fileId);
|
|
348
|
+
return {
|
|
349
|
+
kind: 'file',
|
|
350
|
+
vendorFileId: fileId,
|
|
351
|
+
part: {
|
|
352
|
+
type: 'file',
|
|
353
|
+
mediaType,
|
|
354
|
+
data: {
|
|
355
|
+
type: 'reference',
|
|
356
|
+
reference: { [store.referenceKey]: fileId },
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// 2. 公网 URL
|
|
364
|
+
const url = this.options.source.publicUrl?.(img.src) ?? null;
|
|
365
|
+
if (url && /^https?:\/\//.test(url)) {
|
|
366
|
+
const supported =
|
|
367
|
+
(await callable(state.handle.model).supportedUrls) ?? {};
|
|
368
|
+
if (urlSupported(supported, mediaType, url)) {
|
|
369
|
+
return {
|
|
370
|
+
kind: 'file',
|
|
371
|
+
part: {
|
|
372
|
+
type: 'file',
|
|
373
|
+
mediaType,
|
|
374
|
+
data: { type: 'url', url: new URL(url) },
|
|
375
|
+
},
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// 3. base64
|
|
381
|
+
return {
|
|
382
|
+
kind: 'file',
|
|
383
|
+
part: {
|
|
384
|
+
type: 'file',
|
|
385
|
+
mediaType,
|
|
386
|
+
data: { type: 'data', data: bytes.data },
|
|
387
|
+
},
|
|
388
|
+
};
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
state.prompt = await deliverImages(prompt, resolve, this.texts);
|
|
392
|
+
return state;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/** 第一档:在本次请求的账号上取(或传)这张图,拿不到给 null。 */
|
|
396
|
+
private async vendorFile(
|
|
397
|
+
vendor: string,
|
|
398
|
+
store: VendorFileStoreLike,
|
|
399
|
+
img: PendingImage,
|
|
400
|
+
bytes: LoadedImage,
|
|
401
|
+
mediaType: string,
|
|
402
|
+
records: VendorFileRecord[],
|
|
403
|
+
state: Attempt,
|
|
404
|
+
usePin: (account: string) => Promise<void>
|
|
405
|
+
): Promise<string | null> {
|
|
406
|
+
const same = (r: VendorFileRecord) =>
|
|
407
|
+
r.account === state.account && r.contentHash === bytes.contentHash;
|
|
408
|
+
if (state.account !== undefined) {
|
|
409
|
+
const hit = records.find(r => same(r) && this.files.isFresh(r));
|
|
410
|
+
if (hit) {
|
|
411
|
+
this.files.touch(hit);
|
|
412
|
+
return hit.fileId;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
const uploaded = await this.files.upload(
|
|
416
|
+
{
|
|
417
|
+
vendor,
|
|
418
|
+
store,
|
|
419
|
+
contentHash: bytes.contentHash,
|
|
420
|
+
src: img.src,
|
|
421
|
+
data: bytes.data,
|
|
422
|
+
mediaType,
|
|
423
|
+
...(img.path ? { filename: basenameOf(img.path) } : {}),
|
|
424
|
+
previous: records.filter(r => r.contentHash === bytes.contentHash),
|
|
425
|
+
},
|
|
426
|
+
state.pinned
|
|
427
|
+
);
|
|
428
|
+
if (!uploaded) return null;
|
|
429
|
+
if (state.account === undefined) {
|
|
430
|
+
// 第一张上传定账号:之后的图与这次请求都钉到它上面。
|
|
431
|
+
await usePin(uploaded.account);
|
|
432
|
+
} else if (uploaded.account !== state.account) {
|
|
433
|
+
// 钉住了却落到别的账号(不该发生):这个 id 这次请求用不了,记下的账留给以后。
|
|
434
|
+
this.logger.warn(
|
|
435
|
+
`upload for ${vendor} landed on ${uploaded.account}, expected ${state.account}`
|
|
436
|
+
);
|
|
437
|
+
records.push(uploaded);
|
|
438
|
+
return null;
|
|
439
|
+
}
|
|
440
|
+
records.push(uploaded);
|
|
441
|
+
return uploaded.fileId;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/** 覆盖张数最多的账号;平手取最近用过的。 */
|
|
446
|
+
function pickAccount(records: readonly VendorFileRecord[]): string | undefined {
|
|
447
|
+
const score = new Map<string, { hashes: Set<string>; last: number }>();
|
|
448
|
+
for (const r of records) {
|
|
449
|
+
const s = score.get(r.account) ?? { hashes: new Set<string>(), last: 0 };
|
|
450
|
+
s.hashes.add(r.contentHash);
|
|
451
|
+
s.last = Math.max(s.last, r.lastUsedAt.getTime());
|
|
452
|
+
score.set(r.account, s);
|
|
453
|
+
}
|
|
454
|
+
let best: string | undefined;
|
|
455
|
+
let bestScore: { hashes: Set<string>; last: number } | undefined;
|
|
456
|
+
for (const [account, s] of score) {
|
|
457
|
+
if (
|
|
458
|
+
!bestScore ||
|
|
459
|
+
s.hashes.size > bestScore.hashes.size ||
|
|
460
|
+
(s.hashes.size === bestScore.hashes.size && s.last > bestScore.last)
|
|
461
|
+
) {
|
|
462
|
+
best = account;
|
|
463
|
+
bestScore = s;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
return best;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* 解析一轮要用的模型并接上图片递送。`affinity` 传**根会话 id**(子 Agent 与根共用一把 key:
|
|
471
|
+
* 前缀缓存与厂商文件都绑账号)。`images` 缺席 = 不递送(prompt 里出现图片引用时承载包会响亮地抛)。
|
|
472
|
+
*
|
|
473
|
+
* 返回解析出的完整句柄(宿主要它的能力、上限、单价)与交给 `runTurn` 的 `llm`。
|
|
474
|
+
*/
|
|
475
|
+
export async function resolveTurnModel<H extends ModelHandleLike>(args: {
|
|
476
|
+
resolver: ModelResolverLike<H>;
|
|
477
|
+
ref: { vendor: string; modelId: string };
|
|
478
|
+
reasoningEffort?: string;
|
|
479
|
+
affinity?: string;
|
|
480
|
+
images?: ImageDelivery | null;
|
|
481
|
+
}): Promise<{ handle: H; llm: LlmHandles }> {
|
|
482
|
+
const options: ResolveModelOptions = {
|
|
483
|
+
...(args.reasoningEffort !== undefined
|
|
484
|
+
? { reasoningEffort: args.reasoningEffort }
|
|
485
|
+
: {}),
|
|
486
|
+
...(args.affinity !== undefined ? { affinity: args.affinity } : {}),
|
|
487
|
+
};
|
|
488
|
+
const handle = await args.resolver.resolve(args.ref, options);
|
|
489
|
+
const model = args.images
|
|
490
|
+
? args.images.wrap({
|
|
491
|
+
vendor: args.ref.vendor,
|
|
492
|
+
base: handle,
|
|
493
|
+
pinned: pin => args.resolver.resolve(args.ref, { ...options, pin }),
|
|
494
|
+
})
|
|
495
|
+
: handle.model;
|
|
496
|
+
return {
|
|
497
|
+
handle,
|
|
498
|
+
llm: {
|
|
499
|
+
model,
|
|
500
|
+
...(handle.providerOptions !== undefined
|
|
501
|
+
? { providerOptions: handle.providerOptions }
|
|
502
|
+
: {}),
|
|
503
|
+
...(handle.replayedMetadataKeys !== undefined
|
|
504
|
+
? { replayedMetadataKeys: handle.replayedMetadataKeys }
|
|
505
|
+
: {}),
|
|
506
|
+
},
|
|
507
|
+
};
|
|
508
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export {
|
|
2
|
+
DEFAULT_BYTE_CACHE_LIMIT,
|
|
3
|
+
ImageByteCache,
|
|
4
|
+
type LoadedImage,
|
|
5
|
+
} from './byte-cache.js';
|
|
6
|
+
export {
|
|
7
|
+
ImageDelivery,
|
|
8
|
+
type ImageDeliveryOptions,
|
|
9
|
+
type ModelHandleLike,
|
|
10
|
+
type ModelResolverLike,
|
|
11
|
+
type ResolveModelOptions,
|
|
12
|
+
resolveTurnModel,
|
|
13
|
+
} from './delivery.js';
|
|
14
|
+
export {
|
|
15
|
+
collectPendingImages,
|
|
16
|
+
DEFAULT_DELIVERY_TEXTS,
|
|
17
|
+
type DeliveredImage,
|
|
18
|
+
deliverImages,
|
|
19
|
+
type DeliveryTexts,
|
|
20
|
+
errorText,
|
|
21
|
+
type ImageResolver,
|
|
22
|
+
isPinnedCredentialUnavailable,
|
|
23
|
+
mentionsVendorFile,
|
|
24
|
+
type PendingImage,
|
|
25
|
+
rejectedVendorFiles,
|
|
26
|
+
urlSupported,
|
|
27
|
+
} from './prompt.js';
|
|
28
|
+
export {
|
|
29
|
+
DIRECT_ACCOUNT,
|
|
30
|
+
MIN_VENDOR_FILE_TTL_SECONDS,
|
|
31
|
+
VENDOR_FILE_EXPIRY_MARGIN_MS,
|
|
32
|
+
VendorFiles,
|
|
33
|
+
type VendorFilesOptions,
|
|
34
|
+
type VendorFileStoreLike,
|
|
35
|
+
} from './vendor-files.js';
|