@hold-rein/cli 0.0.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/cli.js +3 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.js +139 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime/api/app.d.ts +7 -0
- package/dist/runtime/api/app.d.ts.map +1 -0
- package/dist/runtime/api/app.js +41 -0
- package/dist/runtime/api/config/const.d.ts +8 -0
- package/dist/runtime/api/config/const.d.ts.map +1 -0
- package/dist/runtime/api/config/const.js +9 -0
- package/dist/runtime/api/config/env.d.ts +10 -0
- package/dist/runtime/api/config/env.d.ts.map +1 -0
- package/dist/runtime/api/config/env.js +32 -0
- package/dist/runtime/api/db/connection.d.ts +11 -0
- package/dist/runtime/api/db/connection.d.ts.map +1 -0
- package/dist/runtime/api/db/connection.js +21 -0
- package/dist/runtime/api/db/index.d.ts +4 -0
- package/dist/runtime/api/db/index.d.ts.map +1 -0
- package/dist/runtime/api/db/index.js +3 -0
- package/dist/runtime/api/db/migrate.d.ts +4 -0
- package/dist/runtime/api/db/migrate.d.ts.map +1 -0
- package/dist/runtime/api/db/migrate.js +308 -0
- package/dist/runtime/api/db/schema.d.ts +1610 -0
- package/dist/runtime/api/db/schema.d.ts.map +1 -0
- package/dist/runtime/api/db/schema.js +148 -0
- package/dist/runtime/api/middleware/error-middleware.d.ts +3 -0
- package/dist/runtime/api/middleware/error-middleware.d.ts.map +1 -0
- package/dist/runtime/api/middleware/error-middleware.js +5 -0
- package/dist/runtime/api/middleware/not-found-middleware.d.ts +3 -0
- package/dist/runtime/api/middleware/not-found-middleware.d.ts.map +1 -0
- package/dist/runtime/api/middleware/not-found-middleware.js +4 -0
- package/dist/runtime/api/modules/agents/active-task-run-registry.d.ts +10 -0
- package/dist/runtime/api/modules/agents/active-task-run-registry.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/active-task-run-registry.js +20 -0
- package/dist/runtime/api/modules/agents/agent-approval-store.d.ts +7 -0
- package/dist/runtime/api/modules/agents/agent-approval-store.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/agent-approval-store.js +23 -0
- package/dist/runtime/api/modules/agents/agent-event-bus.d.ts +8 -0
- package/dist/runtime/api/modules/agents/agent-event-bus.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/agent-event-bus.js +40 -0
- package/dist/runtime/api/modules/agents/agent-message-repository.d.ts +22 -0
- package/dist/runtime/api/modules/agents/agent-message-repository.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/agent-message-repository.js +60 -0
- package/dist/runtime/api/modules/agents/agent-message-storage.d.ts +4 -0
- package/dist/runtime/api/modules/agents/agent-message-storage.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/agent-message-storage.js +11 -0
- package/dist/runtime/api/modules/agents/agent-model-resolver.d.ts +4 -0
- package/dist/runtime/api/modules/agents/agent-model-resolver.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/agent-model-resolver.js +17 -0
- package/dist/runtime/api/modules/agents/agent-runtime-messages.d.ts +12 -0
- package/dist/runtime/api/modules/agents/agent-runtime-messages.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/agent-runtime-messages.js +19 -0
- package/dist/runtime/api/modules/agents/agent-runtime-support.d.ts +12 -0
- package/dist/runtime/api/modules/agents/agent-runtime-support.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/agent-runtime-support.js +38 -0
- package/dist/runtime/api/modules/agents/agent-runtime.d.ts +25 -0
- package/dist/runtime/api/modules/agents/agent-runtime.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/agent-runtime.js +371 -0
- package/dist/runtime/api/modules/agents/agent-subagents.d.ts +32 -0
- package/dist/runtime/api/modules/agents/agent-subagents.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/agent-subagents.js +65 -0
- package/dist/runtime/api/modules/agents/agent-task-actions.d.ts +9 -0
- package/dist/runtime/api/modules/agents/agent-task-actions.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/agent-task-actions.js +33 -0
- package/dist/runtime/api/modules/agents/agent-task-title-generator.d.ts +15 -0
- package/dist/runtime/api/modules/agents/agent-task-title-generator.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/agent-task-title-generator.js +61 -0
- package/dist/runtime/api/modules/agents/agent-tool-approval.d.ts +12 -0
- package/dist/runtime/api/modules/agents/agent-tool-approval.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/agent-tool-approval.js +40 -0
- package/dist/runtime/api/modules/agents/agent-types.d.ts +198 -0
- package/dist/runtime/api/modules/agents/agent-types.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/agent-types.js +1 -0
- package/dist/runtime/api/modules/agents/agents-router.d.ts +7 -0
- package/dist/runtime/api/modules/agents/agents-router.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/agents-router.js +210 -0
- package/dist/runtime/api/modules/agents/agents-service.d.ts +52 -0
- package/dist/runtime/api/modules/agents/agents-service.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/agents-service.js +282 -0
- package/dist/runtime/api/modules/agents/approval/store.d.ts +7 -0
- package/dist/runtime/api/modules/agents/approval/store.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/approval/store.js +23 -0
- package/dist/runtime/api/modules/agents/approval/tool-approval.d.ts +14 -0
- package/dist/runtime/api/modules/agents/approval/tool-approval.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/approval/tool-approval.js +43 -0
- package/dist/runtime/api/modules/agents/custom-agent-model.d.ts +16 -0
- package/dist/runtime/api/modules/agents/custom-agent-model.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/custom-agent-model.js +21 -0
- package/dist/runtime/api/modules/agents/default-agents-service.d.ts +3 -0
- package/dist/runtime/api/modules/agents/default-agents-service.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/default-agents-service.js +52 -0
- package/dist/runtime/api/modules/agents/event/event-bus.d.ts +8 -0
- package/dist/runtime/api/modules/agents/event/event-bus.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/event/event-bus.js +40 -0
- package/dist/runtime/api/modules/agents/index.d.ts +11 -0
- package/dist/runtime/api/modules/agents/index.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/index.js +9 -0
- package/dist/runtime/api/modules/agents/message/storage.d.ts +4 -0
- package/dist/runtime/api/modules/agents/message/storage.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/message/storage.js +11 -0
- package/dist/runtime/api/modules/agents/model/custom-model.d.ts +16 -0
- package/dist/runtime/api/modules/agents/model/custom-model.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/model/custom-model.js +21 -0
- package/dist/runtime/api/modules/agents/model/resolver.d.ts +4 -0
- package/dist/runtime/api/modules/agents/model/resolver.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/model/resolver.js +17 -0
- package/dist/runtime/api/modules/agents/router/browser-tool-result.d.ts +8 -0
- package/dist/runtime/api/modules/agents/router/browser-tool-result.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/router/browser-tool-result.js +35 -0
- package/dist/runtime/api/modules/agents/router/index.d.ts +10 -0
- package/dist/runtime/api/modules/agents/router/index.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/router/index.js +210 -0
- package/dist/runtime/api/modules/agents/router/request-parsing.d.ts +24 -0
- package/dist/runtime/api/modules/agents/router/request-parsing.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/router/request-parsing.js +78 -0
- package/dist/runtime/api/modules/agents/runtime/browser-runtime-contributions.d.ts +5 -0
- package/dist/runtime/api/modules/agents/runtime/browser-runtime-contributions.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/runtime/browser-runtime-contributions.js +115 -0
- package/dist/runtime/api/modules/agents/runtime/browser-runtime-tools.d.ts +13 -0
- package/dist/runtime/api/modules/agents/runtime/browser-runtime-tools.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/runtime/browser-runtime-tools.js +31 -0
- package/dist/runtime/api/modules/agents/runtime/browser-tool-call-store.d.ts +21 -0
- package/dist/runtime/api/modules/agents/runtime/browser-tool-call-store.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/runtime/browser-tool-call-store.js +69 -0
- package/dist/runtime/api/modules/agents/runtime/continuation-subagent.d.ts +26 -0
- package/dist/runtime/api/modules/agents/runtime/continuation-subagent.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/runtime/continuation-subagent.js +67 -0
- package/dist/runtime/api/modules/agents/runtime/index.d.ts +3 -0
- package/dist/runtime/api/modules/agents/runtime/index.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/runtime/index.js +432 -0
- package/dist/runtime/api/modules/agents/runtime/messages.d.ts +12 -0
- package/dist/runtime/api/modules/agents/runtime/messages.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/runtime/messages.js +19 -0
- package/dist/runtime/api/modules/agents/runtime/subagent-results.d.ts +22 -0
- package/dist/runtime/api/modules/agents/runtime/subagent-results.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/runtime/subagent-results.js +39 -0
- package/dist/runtime/api/modules/agents/runtime/subagent-tools.d.ts +49 -0
- package/dist/runtime/api/modules/agents/runtime/subagent-tools.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/runtime/subagent-tools.js +195 -0
- package/dist/runtime/api/modules/agents/runtime/support.d.ts +19 -0
- package/dist/runtime/api/modules/agents/runtime/support.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/runtime/support.js +106 -0
- package/dist/runtime/api/modules/agents/runtime/token-collection.d.ts +28 -0
- package/dist/runtime/api/modules/agents/runtime/token-collection.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/runtime/token-collection.js +131 -0
- package/dist/runtime/api/modules/agents/runtime/token-usage-sync.d.ts +15 -0
- package/dist/runtime/api/modules/agents/runtime/token-usage-sync.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/runtime/token-usage-sync.js +46 -0
- package/dist/runtime/api/modules/agents/runtime/type.d.ts +62 -0
- package/dist/runtime/api/modules/agents/runtime/type.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/runtime/type.js +1 -0
- package/dist/runtime/api/modules/agents/runtime/workspace-agent-instructions.d.ts +3 -0
- package/dist/runtime/api/modules/agents/runtime/workspace-agent-instructions.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/runtime/workspace-agent-instructions.js +31 -0
- package/dist/runtime/api/modules/agents/service/default.d.ts +3 -0
- package/dist/runtime/api/modules/agents/service/default.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/service/default.js +65 -0
- package/dist/runtime/api/modules/agents/service/index.d.ts +56 -0
- package/dist/runtime/api/modules/agents/service/index.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/service/index.js +296 -0
- package/dist/runtime/api/modules/agents/service/interrupt-task.d.ts +14 -0
- package/dist/runtime/api/modules/agents/service/interrupt-task.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/service/interrupt-task.js +34 -0
- package/dist/runtime/api/modules/agents/service/startup-recovery.d.ts +14 -0
- package/dist/runtime/api/modules/agents/service/startup-recovery.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/service/startup-recovery.js +15 -0
- package/dist/runtime/api/modules/agents/shell-command-risk.d.ts +3 -0
- package/dist/runtime/api/modules/agents/shell-command-risk.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/shell-command-risk.js +24 -0
- package/dist/runtime/api/modules/agents/shell-exec-tool.d.ts +4 -0
- package/dist/runtime/api/modules/agents/shell-exec-tool.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/shell-exec-tool.js +71 -0
- package/dist/runtime/api/modules/agents/subagent/index.d.ts +45 -0
- package/dist/runtime/api/modules/agents/subagent/index.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/subagent/index.js +143 -0
- package/dist/runtime/api/modules/agents/subagent/lifecycle.d.ts +13 -0
- package/dist/runtime/api/modules/agents/subagent/lifecycle.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/subagent/lifecycle.js +36 -0
- package/dist/runtime/api/modules/agents/subagent/repository.d.ts +12 -0
- package/dist/runtime/api/modules/agents/subagent/repository.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/subagent/repository.js +93 -0
- package/dist/runtime/api/modules/agents/subagent-repository.d.ts +11 -0
- package/dist/runtime/api/modules/agents/subagent-repository.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/subagent-repository.js +65 -0
- package/dist/runtime/api/modules/agents/task/actions.d.ts +10 -0
- package/dist/runtime/api/modules/agents/task/actions.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/task/actions.js +37 -0
- package/dist/runtime/api/modules/agents/task/active-run-registry.d.ts +10 -0
- package/dist/runtime/api/modules/agents/task/active-run-registry.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/task/active-run-registry.js +20 -0
- package/dist/runtime/api/modules/agents/task/run-monitor.d.ts +14 -0
- package/dist/runtime/api/modules/agents/task/run-monitor.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/task/run-monitor.js +42 -0
- package/dist/runtime/api/modules/agents/task/title-generator.d.ts +15 -0
- package/dist/runtime/api/modules/agents/task/title-generator.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/task/title-generator.js +61 -0
- package/dist/runtime/api/modules/agents/task-run-monitor.d.ts +14 -0
- package/dist/runtime/api/modules/agents/task-run-monitor.d.ts.map +1 -0
- package/dist/runtime/api/modules/agents/task-run-monitor.js +42 -0
- package/dist/runtime/api/modules/file-system/file-system-router.d.ts +6 -0
- package/dist/runtime/api/modules/file-system/file-system-router.d.ts.map +1 -0
- package/dist/runtime/api/modules/file-system/file-system-router.js +119 -0
- package/dist/runtime/api/modules/file-system/file-system-service.d.ts +30 -0
- package/dist/runtime/api/modules/file-system/file-system-service.d.ts.map +1 -0
- package/dist/runtime/api/modules/file-system/file-system-service.js +209 -0
- package/dist/runtime/api/modules/file-system/index.d.ts +4 -0
- package/dist/runtime/api/modules/file-system/index.d.ts.map +1 -0
- package/dist/runtime/api/modules/file-system/index.js +1 -0
- package/dist/runtime/api/modules/health/health-router.d.ts +3 -0
- package/dist/runtime/api/modules/health/health-router.d.ts.map +1 -0
- package/dist/runtime/api/modules/health/health-router.js +10 -0
- package/dist/runtime/api/modules/health/index.d.ts +2 -0
- package/dist/runtime/api/modules/health/index.d.ts.map +1 -0
- package/dist/runtime/api/modules/health/index.js +1 -0
- package/dist/runtime/api/modules/model-providers/default-model-provider-service.d.ts +3 -0
- package/dist/runtime/api/modules/model-providers/default-model-provider-service.d.ts.map +1 -0
- package/dist/runtime/api/modules/model-providers/default-model-provider-service.js +21 -0
- package/dist/runtime/api/modules/model-providers/index.d.ts +5 -0
- package/dist/runtime/api/modules/model-providers/index.d.ts.map +1 -0
- package/dist/runtime/api/modules/model-providers/index.js +4 -0
- package/dist/runtime/api/modules/model-providers/model-provider-api-key-crypto.d.ts +8 -0
- package/dist/runtime/api/modules/model-providers/model-provider-api-key-crypto.d.ts.map +1 -0
- package/dist/runtime/api/modules/model-providers/model-provider-api-key-crypto.js +35 -0
- package/dist/runtime/api/modules/model-providers/model-provider-repository.d.ts +51 -0
- package/dist/runtime/api/modules/model-providers/model-provider-repository.d.ts.map +1 -0
- package/dist/runtime/api/modules/model-providers/model-provider-repository.js +314 -0
- package/dist/runtime/api/modules/model-providers/model-providers-router.d.ts +9 -0
- package/dist/runtime/api/modules/model-providers/model-providers-router.d.ts.map +1 -0
- package/dist/runtime/api/modules/model-providers/model-providers-router.js +188 -0
- package/dist/runtime/api/modules/model-providers/model-providers-service.d.ts +52 -0
- package/dist/runtime/api/modules/model-providers/model-providers-service.d.ts.map +1 -0
- package/dist/runtime/api/modules/model-providers/model-providers-service.js +239 -0
- package/dist/runtime/api/modules/model-proxies/default-model-proxies-service.d.ts +3 -0
- package/dist/runtime/api/modules/model-proxies/default-model-proxies-service.d.ts.map +1 -0
- package/dist/runtime/api/modules/model-proxies/default-model-proxies-service.js +22 -0
- package/dist/runtime/api/modules/model-proxies/index.d.ts +5 -0
- package/dist/runtime/api/modules/model-proxies/index.d.ts.map +1 -0
- package/dist/runtime/api/modules/model-proxies/index.js +4 -0
- package/dist/runtime/api/modules/model-proxies/model-proxies-router.d.ts +7 -0
- package/dist/runtime/api/modules/model-proxies/model-proxies-router.d.ts.map +1 -0
- package/dist/runtime/api/modules/model-proxies/model-proxies-router.js +55 -0
- package/dist/runtime/api/modules/model-proxies/model-proxies-service.d.ts +26 -0
- package/dist/runtime/api/modules/model-proxies/model-proxies-service.d.ts.map +1 -0
- package/dist/runtime/api/modules/model-proxies/model-proxies-service.js +107 -0
- package/dist/runtime/api/modules/model-proxies/model-proxy-repository.d.ts +39 -0
- package/dist/runtime/api/modules/model-proxies/model-proxy-repository.d.ts.map +1 -0
- package/dist/runtime/api/modules/model-proxies/model-proxy-repository.js +146 -0
- package/dist/runtime/api/modules/model-proxies/model-proxy-runtime.d.ts +20 -0
- package/dist/runtime/api/modules/model-proxies/model-proxy-runtime.d.ts.map +1 -0
- package/dist/runtime/api/modules/model-proxies/model-proxy-runtime.js +45 -0
- package/dist/runtime/api/modules/plugins/plugins-router.d.ts +7 -0
- package/dist/runtime/api/modules/plugins/plugins-router.d.ts.map +1 -0
- package/dist/runtime/api/modules/plugins/plugins-router.js +11 -0
- package/dist/runtime/api/modules/skills/default-skills-service.d.ts +3 -0
- package/dist/runtime/api/modules/skills/default-skills-service.d.ts.map +1 -0
- package/dist/runtime/api/modules/skills/default-skills-service.js +9 -0
- package/dist/runtime/api/modules/skills/index.d.ts +5 -0
- package/dist/runtime/api/modules/skills/index.d.ts.map +1 -0
- package/dist/runtime/api/modules/skills/index.js +3 -0
- package/dist/runtime/api/modules/skills/skills-router.d.ts +7 -0
- package/dist/runtime/api/modules/skills/skills-router.d.ts.map +1 -0
- package/dist/runtime/api/modules/skills/skills-router.js +56 -0
- package/dist/runtime/api/modules/skills/skills-service.d.ts +7 -0
- package/dist/runtime/api/modules/skills/skills-service.d.ts.map +1 -0
- package/dist/runtime/api/modules/skills/skills-service.js +264 -0
- package/dist/runtime/api/modules/skills/skills-types.d.ts +22 -0
- package/dist/runtime/api/modules/skills/skills-types.d.ts.map +1 -0
- package/dist/runtime/api/modules/skills/skills-types.js +1 -0
- package/dist/runtime/api/modules/usage-stats/default-usage-stats-service.d.ts +3 -0
- package/dist/runtime/api/modules/usage-stats/default-usage-stats-service.d.ts.map +1 -0
- package/dist/runtime/api/modules/usage-stats/default-usage-stats-service.js +17 -0
- package/dist/runtime/api/modules/usage-stats/index.d.ts +4 -0
- package/dist/runtime/api/modules/usage-stats/index.d.ts.map +1 -0
- package/dist/runtime/api/modules/usage-stats/index.js +2 -0
- package/dist/runtime/api/modules/usage-stats/usage-stats-router.d.ts +7 -0
- package/dist/runtime/api/modules/usage-stats/usage-stats-router.d.ts.map +1 -0
- package/dist/runtime/api/modules/usage-stats/usage-stats-router.js +42 -0
- package/dist/runtime/api/modules/usage-stats/usage-stats-service.d.ts +40 -0
- package/dist/runtime/api/modules/usage-stats/usage-stats-service.d.ts.map +1 -0
- package/dist/runtime/api/modules/usage-stats/usage-stats-service.js +144 -0
- package/dist/runtime/api/modules/usage-stats/usage-stats-types.d.ts +39 -0
- package/dist/runtime/api/modules/usage-stats/usage-stats-types.d.ts.map +1 -0
- package/dist/runtime/api/modules/usage-stats/usage-stats-types.js +1 -0
- package/dist/runtime/api/modules/workspaces/default-workspaces-service.d.ts +3 -0
- package/dist/runtime/api/modules/workspaces/default-workspaces-service.d.ts.map +1 -0
- package/dist/runtime/api/modules/workspaces/default-workspaces-service.js +20 -0
- package/dist/runtime/api/modules/workspaces/index.d.ts +6 -0
- package/dist/runtime/api/modules/workspaces/index.d.ts.map +1 -0
- package/dist/runtime/api/modules/workspaces/index.js +5 -0
- package/dist/runtime/api/modules/workspaces/workspace-repository.d.ts +41 -0
- package/dist/runtime/api/modules/workspaces/workspace-repository.d.ts.map +1 -0
- package/dist/runtime/api/modules/workspaces/workspace-repository.js +326 -0
- package/dist/runtime/api/modules/workspaces/workspace-types.d.ts +33 -0
- package/dist/runtime/api/modules/workspaces/workspace-types.d.ts.map +1 -0
- package/dist/runtime/api/modules/workspaces/workspace-types.js +1 -0
- package/dist/runtime/api/modules/workspaces/workspaces-router.d.ts +7 -0
- package/dist/runtime/api/modules/workspaces/workspaces-router.d.ts.map +1 -0
- package/dist/runtime/api/modules/workspaces/workspaces-router.js +71 -0
- package/dist/runtime/api/modules/workspaces/workspaces-service.d.ts +24 -0
- package/dist/runtime/api/modules/workspaces/workspaces-service.d.ts.map +1 -0
- package/dist/runtime/api/modules/workspaces/workspaces-service.js +109 -0
- package/dist/runtime/api/plugin.d.ts +5 -0
- package/dist/runtime/api/plugin.d.ts.map +1 -0
- package/dist/runtime/api/plugin.js +48 -0
- package/dist/runtime/api/response/api-response.d.ts +11 -0
- package/dist/runtime/api/response/api-response.d.ts.map +1 -0
- package/dist/runtime/api/response/api-response.js +18 -0
- package/dist/runtime/api/response/index.d.ts +3 -0
- package/dist/runtime/api/response/index.d.ts.map +1 -0
- package/dist/runtime/api/response/index.js +2 -0
- package/dist/runtime/api/response/response-codes.d.ts +52 -0
- package/dist/runtime/api/response/response-codes.d.ts.map +1 -0
- package/dist/runtime/api/response/response-codes.js +44 -0
- package/dist/runtime/api/router/v1/index.d.ts +12 -0
- package/dist/runtime/api/router/v1/index.d.ts.map +1 -0
- package/dist/runtime/api/router/v1/index.js +26 -0
- package/dist/runtime/api/runtime.d.ts +15 -0
- package/dist/runtime/api/runtime.d.ts.map +1 -0
- package/dist/runtime/api/runtime.js +30 -0
- package/dist/runtime/api/server.d.ts +2 -0
- package/dist/runtime/api/server.d.ts.map +1 -0
- package/dist/runtime/api/server.js +14 -0
- package/dist/runtime/api/service/health-service.d.ts +7 -0
- package/dist/runtime/api/service/health-service.d.ts.map +1 -0
- package/dist/runtime/api/service/health-service.js +7 -0
- package/dist/runtime/web/assets/abap-DLDM7-KI.js +1 -0
- package/dist/runtime/web/assets/apex-DNDY2TF8.js +1 -0
- package/dist/runtime/web/assets/azcli-Y6nb8tq_.js +1 -0
- package/dist/runtime/web/assets/bat-BwHxbl9M.js +1 -0
- package/dist/runtime/web/assets/bicep-CFznDFnq.js +2 -0
- package/dist/runtime/web/assets/cameligo-Bf6VGUru.js +1 -0
- package/dist/runtime/web/assets/clojure-Dnu-v4kV.js +1 -0
- package/dist/runtime/web/assets/codicon-ngg6Pgfi.ttf +0 -0
- package/dist/runtime/web/assets/coffee-Bd8akH9Z.js +1 -0
- package/dist/runtime/web/assets/cpp-BbWJElDN.js +1 -0
- package/dist/runtime/web/assets/csharp-Co3qMtFm.js +1 -0
- package/dist/runtime/web/assets/csp-D-4FJmMZ.js +1 -0
- package/dist/runtime/web/assets/css-DdJfP1eB.js +3 -0
- package/dist/runtime/web/assets/css.worker-B4z49cGk.js +93 -0
- package/dist/runtime/web/assets/cssMode-w2xbbUEW.js +1 -0
- package/dist/runtime/web/assets/cypher-cTPe9QuQ.js +1 -0
- package/dist/runtime/web/assets/dart-BOtBlQCF.js +1 -0
- package/dist/runtime/web/assets/dockerfile-BG73LgW2.js +1 -0
- package/dist/runtime/web/assets/ecl-BEgZUVRK.js +1 -0
- package/dist/runtime/web/assets/elixir-BkW5O-1t.js +1 -0
- package/dist/runtime/web/assets/flow9-BeJ5waoc.js +1 -0
- package/dist/runtime/web/assets/freemarker2-mywz2bob.js +3 -0
- package/dist/runtime/web/assets/fsharp-PahG7c26.js +1 -0
- package/dist/runtime/web/assets/go-acbASCJo.js +1 -0
- package/dist/runtime/web/assets/graphql-BxJiqAUM.js +1 -0
- package/dist/runtime/web/assets/handlebars-Cy-2QN_R.js +1 -0
- package/dist/runtime/web/assets/hcl-DtV1sZF8.js +1 -0
- package/dist/runtime/web/assets/html-2WQMGvns.js +1 -0
- package/dist/runtime/web/assets/html.worker-DtiGdgqp.js +470 -0
- package/dist/runtime/web/assets/htmlMode-BznIdxOy.js +1 -0
- package/dist/runtime/web/assets/index-CQ_mZUpS.css +1 -0
- package/dist/runtime/web/assets/index-CtZcItCu.js +1512 -0
- package/dist/runtime/web/assets/ini-Kd9XrMLS.js +1 -0
- package/dist/runtime/web/assets/java-CXBNlu9o.js +1 -0
- package/dist/runtime/web/assets/javascript-BK6G_5BV.js +1 -0
- package/dist/runtime/web/assets/json.worker-leyajbqV.js +58 -0
- package/dist/runtime/web/assets/jsonMode-DI8_Cj0K.js +7 -0
- package/dist/runtime/web/assets/julia-cl7-CwDS.js +1 -0
- package/dist/runtime/web/assets/kotlin-s7OhZKlX.js +1 -0
- package/dist/runtime/web/assets/less-9HpZscsL.js +2 -0
- package/dist/runtime/web/assets/lexon-OrD6JF1K.js +1 -0
- package/dist/runtime/web/assets/liquid-CE7Qnc0w.js +1 -0
- package/dist/runtime/web/assets/lspLanguageFeatures-DKvGiYOU.js +4 -0
- package/dist/runtime/web/assets/lua-Cyyb5UIc.js +1 -0
- package/dist/runtime/web/assets/m3-B8OfTtLu.js +1 -0
- package/dist/runtime/web/assets/markdown-BFxVWTOG.js +1 -0
- package/dist/runtime/web/assets/mdx-Fk0ZjYeT.js +1 -0
- package/dist/runtime/web/assets/mips-CiqrrVzr.js +1 -0
- package/dist/runtime/web/assets/msdax-DmeGPVcC.js +1 -0
- package/dist/runtime/web/assets/mysql-C_tMU-Nz.js +1 -0
- package/dist/runtime/web/assets/objective-c-BDtDVThU.js +1 -0
- package/dist/runtime/web/assets/pascal-vHIfCaH5.js +1 -0
- package/dist/runtime/web/assets/pascaligo-DtZ0uQbO.js +1 -0
- package/dist/runtime/web/assets/perl-Ub6l9XKa.js +1 -0
- package/dist/runtime/web/assets/pgsql-BlNEE0v7.js +1 -0
- package/dist/runtime/web/assets/php-BBUBE1dy.js +1 -0
- package/dist/runtime/web/assets/pla-DSh2-awV.js +1 -0
- package/dist/runtime/web/assets/postiats-CocnycG-.js +1 -0
- package/dist/runtime/web/assets/powerquery-tScXyioY.js +1 -0
- package/dist/runtime/web/assets/powershell-COWaemsV.js +1 -0
- package/dist/runtime/web/assets/protobuf-Brw8urJB.js +2 -0
- package/dist/runtime/web/assets/pug-8SOpv6rk.js +1 -0
- package/dist/runtime/web/assets/python-xn7eKnQc.js +1 -0
- package/dist/runtime/web/assets/qsharp-Bw9ernYp.js +1 -0
- package/dist/runtime/web/assets/r-j7ic8hl3.js +1 -0
- package/dist/runtime/web/assets/razor-BjC5fot0.js +1 -0
- package/dist/runtime/web/assets/redis-Bu5POkcn.js +1 -0
- package/dist/runtime/web/assets/redshift-Bs9aos_-.js +1 -0
- package/dist/runtime/web/assets/restructuredtext-CqXO7rUv.js +1 -0
- package/dist/runtime/web/assets/ruby-zBfavPgS.js +1 -0
- package/dist/runtime/web/assets/rust-BzKRNQWT.js +1 -0
- package/dist/runtime/web/assets/sb-BBc9UKZt.js +1 -0
- package/dist/runtime/web/assets/scala-D9hQfWCl.js +1 -0
- package/dist/runtime/web/assets/scheme-BPhDTwHR.js +1 -0
- package/dist/runtime/web/assets/scss-CBJaRo0y.js +3 -0
- package/dist/runtime/web/assets/shell-DiJ1NA_G.js +1 -0
- package/dist/runtime/web/assets/solidity-Db0IVjzk.js +1 -0
- package/dist/runtime/web/assets/sophia-CnS9iZB_.js +1 -0
- package/dist/runtime/web/assets/sparql-CJmd_6j2.js +1 -0
- package/dist/runtime/web/assets/sql-ClhHkBeG.js +1 -0
- package/dist/runtime/web/assets/st-CHwy0fLd.js +1 -0
- package/dist/runtime/web/assets/swift-Bqt4WxQ4.js +3 -0
- package/dist/runtime/web/assets/systemverilog-Bs9z6M-B.js +1 -0
- package/dist/runtime/web/assets/tcl-Dm6ycUr_.js +1 -0
- package/dist/runtime/web/assets/ts.worker-59MjiAqk.js +67731 -0
- package/dist/runtime/web/assets/tsMode-8t6AIduV.js +11 -0
- package/dist/runtime/web/assets/twig-Csy3S7wG.js +1 -0
- package/dist/runtime/web/assets/typescript-DvPPogGC.js +1 -0
- package/dist/runtime/web/assets/typespec-Btyra-wh.js +1 -0
- package/dist/runtime/web/assets/vb-Db0cS2oM.js +1 -0
- package/dist/runtime/web/assets/wgsl-BTesnYfV.js +298 -0
- package/dist/runtime/web/assets/xml-CB8xdh8u.js +1 -0
- package/dist/runtime/web/assets/yaml-B4sXC4FA.js +1 -0
- package/dist/runtime/web/index.html +13 -0
- package/package.json +42 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subagent-results.d.ts","sourceRoot":"","sources":["../../../../src/modules/agents/runtime/subagent-results.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,EAAwB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAIrE,UAAU,2BAA2B;IACnC,wBAAwB,EAAE,CACxB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,OAAO,KACd,OAAO,CAAC,OAAO,CAAC,CAAC;CACvB;AAED,wBAAgB,wBAAwB,CACtC,sBAAsB,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,EAChD,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,IAAI,CAIN;AAED,wBAAsB,2BAA2B,CAC/C,OAAO,SAAS,2BAA2B,EAC3C,KAAK,EAAE;IACP,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,aAAa,CAAC;IACxB,sBAAsB,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IACjD,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;CAC9C,GAAG,OAAO,CAAC,IAAI,CAAC,CAWhB;AAED,wBAAsB,oBAAoB,CACxC,OAAO,SAAS,2BAA2B,EAC3C,KAAK,EAAE;IACP,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,aAAa,CAAC;IACxB,sBAAsB,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IACjD,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CAChC,GAAG,OAAO,CAAC,MAAM,CAAC,CAiBlB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { appendVisibleCustomMessage } from "./messages.js";
|
|
2
|
+
import { formatSubagentResult } from "../subagent/index.js";
|
|
3
|
+
const SUBAGENT_RESULT_CUSTOM_TYPE = "subagent_result";
|
|
4
|
+
export function addPendingSubagentResult(pendingSubagentResults, agentId, subagentId) {
|
|
5
|
+
const pending = pendingSubagentResults.get(agentId) ?? new Set();
|
|
6
|
+
pending.add(subagentId);
|
|
7
|
+
pendingSubagentResults.set(agentId, pending);
|
|
8
|
+
}
|
|
9
|
+
export async function flushPendingSubagentResults(input) {
|
|
10
|
+
const pending = input.pendingSubagentResults.get(input.agentId);
|
|
11
|
+
if (!pending)
|
|
12
|
+
return;
|
|
13
|
+
for (const subagentId of pending) {
|
|
14
|
+
const subagent = input.subagents.get(subagentId);
|
|
15
|
+
if (subagent && !subagent.consumed) {
|
|
16
|
+
await appendSubagentResult({ ...input, subagent });
|
|
17
|
+
input.subagents.delete(subagentId);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
input.pendingSubagentResults.delete(input.agentId);
|
|
21
|
+
}
|
|
22
|
+
export async function appendSubagentResult(input) {
|
|
23
|
+
const prompt = formatSubagentResult(input.subagent);
|
|
24
|
+
await appendVisibleCustomMessage({
|
|
25
|
+
agentId: input.agentId,
|
|
26
|
+
content: prompt,
|
|
27
|
+
customType: SUBAGENT_RESULT_CUSTOM_TYPE,
|
|
28
|
+
details: {
|
|
29
|
+
agentId: input.subagent.agentId,
|
|
30
|
+
agentName: input.subagent.agentName,
|
|
31
|
+
session: input.subagent.session
|
|
32
|
+
},
|
|
33
|
+
eventBus: input.eventBus,
|
|
34
|
+
session: input.session
|
|
35
|
+
});
|
|
36
|
+
input.subagent.consumed = true;
|
|
37
|
+
input.pendingSubagentResults.get(input.agentId)?.delete(input.subagent.agentId);
|
|
38
|
+
return prompt;
|
|
39
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ServerPlugin } from "@hold-rein/plugin-server";
|
|
2
|
+
import { type AppDatabase } from "../../../db";
|
|
3
|
+
import type { AgentEventBus } from "../event/event-bus";
|
|
4
|
+
import { type SubagentRun } from "../subagent";
|
|
5
|
+
import type { SubagentRepository } from "../subagent/repository";
|
|
6
|
+
import type { HarnessSession, PendingVisibleCustomMessage, StartHarnessOptions, StartHarnessResult } from "./type";
|
|
7
|
+
type StartHarness = (promptText: string, harnessOptions: StartHarnessOptions) => Promise<StartHarnessResult>;
|
|
8
|
+
interface CreateRuntimeSubagentToolsInput {
|
|
9
|
+
contributionTools: ServerPlugin.PluginTool[];
|
|
10
|
+
eventBus: AgentEventBus;
|
|
11
|
+
parentAgentId: string;
|
|
12
|
+
parentAgentName?: string;
|
|
13
|
+
parentSession: HarnessSession;
|
|
14
|
+
pendingVisibleMessages: Map<string, PendingVisibleCustomMessage[]>;
|
|
15
|
+
persistedSubagentRepository: SubagentRepository;
|
|
16
|
+
sessionRepo: SessionRepo;
|
|
17
|
+
startHarness: StartHarness;
|
|
18
|
+
subagentDatabase?: AppDatabase;
|
|
19
|
+
subagents: Map<string, SubagentRun<HarnessSession>>;
|
|
20
|
+
taskId: string;
|
|
21
|
+
workspacePath: string;
|
|
22
|
+
}
|
|
23
|
+
interface CreateRuntimeRevokeSubagentToolInput {
|
|
24
|
+
eventBus: AgentEventBus;
|
|
25
|
+
parentAgentId: string;
|
|
26
|
+
parentSession: HarnessSession;
|
|
27
|
+
persistedSubagentRepository: SubagentRepository;
|
|
28
|
+
sessionRepo: SessionRepo;
|
|
29
|
+
startHarness: StartHarness;
|
|
30
|
+
subagentDatabase?: AppDatabase;
|
|
31
|
+
subagents: Map<string, SubagentRun<HarnessSession>>;
|
|
32
|
+
taskId: string;
|
|
33
|
+
workspacePath: string;
|
|
34
|
+
}
|
|
35
|
+
interface SessionRepo {
|
|
36
|
+
create: (input: {
|
|
37
|
+
cwd: string;
|
|
38
|
+
}) => Promise<HarnessSession>;
|
|
39
|
+
open: (input: {
|
|
40
|
+
createdAt: string;
|
|
41
|
+
cwd: string;
|
|
42
|
+
id: string;
|
|
43
|
+
path: string;
|
|
44
|
+
}) => Promise<HarnessSession>;
|
|
45
|
+
}
|
|
46
|
+
export declare function createRuntimeSubagentTools(input: CreateRuntimeSubagentToolsInput): Promise<ServerPlugin.PluginTool[]>;
|
|
47
|
+
export declare function createRuntimeRevokeSubagentTool(input: CreateRuntimeRevokeSubagentToolInput): ServerPlugin.PluginTool;
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=subagent-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subagent-tools.d.ts","sourceRoot":"","sources":["../../../../src/modules/agents/runtime/subagent-tools.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,EAA+B,KAAK,WAAW,EAAoB,MAAM,aAAa,CAAC;AAC9F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAoD,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AACjG,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,KAAK,EAAE,cAAc,EAAE,2BAA2B,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAInH,KAAK,YAAY,GAAG,CAClB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,mBAAmB,KAChC,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAEjC,UAAU,+BAA+B;IACvC,iBAAiB,EAAE,YAAY,CAAC,UAAU,EAAE,CAAC;IAC7C,QAAQ,EAAE,aAAa,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,EAAE,cAAc,CAAC;IAC9B,sBAAsB,EAAE,GAAG,CAAC,MAAM,EAAE,2BAA2B,EAAE,CAAC,CAAC;IACnE,2BAA2B,EAAE,kBAAkB,CAAC;IAChD,WAAW,EAAE,WAAW,CAAC;IACzB,YAAY,EAAE,YAAY,CAAC;IAC3B,gBAAgB,CAAC,EAAE,WAAW,CAAC;IAC/B,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,UAAU,oCAAoC;IAC5C,QAAQ,EAAE,aAAa,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,cAAc,CAAC;IAC9B,2BAA2B,EAAE,kBAAkB,CAAC;IAChD,WAAW,EAAE,WAAW,CAAC;IACzB,YAAY,EAAE,YAAY,CAAC;IAC3B,gBAAgB,CAAC,EAAE,WAAW,CAAC;IAC/B,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,UAAU,WAAW;IACnB,MAAM,EAAE,CAAC,KAAK,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IAC5D,IAAI,EAAE,CAAC,KAAK,EAAE;QACZ,SAAS,EAAE,MAAM,CAAC;QAClB,GAAG,EAAE,MAAM,CAAC;QACZ,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;KACd,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;CAC/B;AAED,wBAAsB,0BAA0B,CAC9C,KAAK,EAAE,+BAA+B,GACrC,OAAO,CAAC,YAAY,CAAC,UAAU,EAAE,CAAC,CAUpC;AAED,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,oCAAoC,GAC1C,YAAY,CAAC,UAAU,CAmEzB"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { eq } from "drizzle-orm";
|
|
3
|
+
import { subagents as subagentsTable } from "../../../db/index.js";
|
|
4
|
+
import { createCallSubagentTool, createRevokeSubagentTool } from "../subagent/index.js";
|
|
5
|
+
import { toAgentSessionMetadata } from "./support.js";
|
|
6
|
+
const CALL_SUBAGENT_CUSTOM_TYPE = "callsubagent";
|
|
7
|
+
export async function createRuntimeSubagentTools(input) {
|
|
8
|
+
const hasCalledSubagent = await sessionHasCalledSubagent(input.parentSession);
|
|
9
|
+
return [
|
|
10
|
+
...input.contributionTools,
|
|
11
|
+
createCallSubagentTool({
|
|
12
|
+
startSubagent: (request) => startSubagent(input, request)
|
|
13
|
+
}),
|
|
14
|
+
...(hasCalledSubagent ? [createRuntimeRevokeSubagentTool(input)] : [])
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
export function createRuntimeRevokeSubagentTool(input) {
|
|
18
|
+
return createRevokeSubagentTool({
|
|
19
|
+
continueSubagent: async ({ agentId, prompt }) => {
|
|
20
|
+
const subagentRow = findSubagentRow(input.subagentDatabase, agentId);
|
|
21
|
+
if (!subagentRow ||
|
|
22
|
+
subagentRow.status !== "completed") {
|
|
23
|
+
throw new Error(`Unknown completed subagent: ${agentId}`);
|
|
24
|
+
}
|
|
25
|
+
const session = getPersistedSubagentSession(subagentRow);
|
|
26
|
+
if (!session) {
|
|
27
|
+
throw new Error(`Subagent session is missing: ${agentId}`);
|
|
28
|
+
}
|
|
29
|
+
const existingSubagent = input.subagents.get(agentId);
|
|
30
|
+
const agentName = existingSubagent?.agentName ?? subagentRow.agentName;
|
|
31
|
+
const agentSession = await input.sessionRepo.open({
|
|
32
|
+
...session,
|
|
33
|
+
cwd: input.workspacePath
|
|
34
|
+
});
|
|
35
|
+
updateSubagentStatus(input.subagentDatabase, agentId, "running");
|
|
36
|
+
input.subagents.set(agentId, {
|
|
37
|
+
agentId,
|
|
38
|
+
agentName,
|
|
39
|
+
agentSession,
|
|
40
|
+
consumed: false,
|
|
41
|
+
lastAssistantText: "",
|
|
42
|
+
parentAgentId: input.parentAgentId,
|
|
43
|
+
parentSession: input.parentSession,
|
|
44
|
+
session,
|
|
45
|
+
status: "running"
|
|
46
|
+
});
|
|
47
|
+
input.eventBus.emit({
|
|
48
|
+
agentId: input.parentAgentId,
|
|
49
|
+
payload: {
|
|
50
|
+
agentId,
|
|
51
|
+
agentName,
|
|
52
|
+
parentAgentId: input.parentAgentId,
|
|
53
|
+
session,
|
|
54
|
+
taskId: input.taskId
|
|
55
|
+
},
|
|
56
|
+
type: "subagent_resumed"
|
|
57
|
+
});
|
|
58
|
+
await input.startHarness(prompt, {
|
|
59
|
+
agentId,
|
|
60
|
+
agentName,
|
|
61
|
+
isContinue: true,
|
|
62
|
+
parentAgentId: input.parentAgentId,
|
|
63
|
+
pluginPrompt: prompt,
|
|
64
|
+
session: agentSession
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
content: [{
|
|
68
|
+
text: `Subagent "${agentName}" was revoked. agentId=${agentId}`,
|
|
69
|
+
type: "text"
|
|
70
|
+
}],
|
|
71
|
+
details: {
|
|
72
|
+
agentId,
|
|
73
|
+
agentName,
|
|
74
|
+
parentAgentId: input.parentAgentId,
|
|
75
|
+
session,
|
|
76
|
+
taskId: input.taskId
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function getPersistedSubagentSession(subagent) {
|
|
83
|
+
if (!subagent ||
|
|
84
|
+
!subagent.sessionCreatedAt ||
|
|
85
|
+
!subagent.sessionId ||
|
|
86
|
+
!subagent.sessionPath) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
createdAt: subagent.sessionCreatedAt,
|
|
91
|
+
id: subagent.sessionId,
|
|
92
|
+
path: subagent.sessionPath
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function findSubagentRow(database, agentId) {
|
|
96
|
+
if (!database) {
|
|
97
|
+
throw new Error("Subagent database is required to revoke a subagent");
|
|
98
|
+
}
|
|
99
|
+
return database.db
|
|
100
|
+
.select()
|
|
101
|
+
.from(subagentsTable)
|
|
102
|
+
.where(eq(subagentsTable.agentId, agentId))
|
|
103
|
+
.get();
|
|
104
|
+
}
|
|
105
|
+
function updateSubagentStatus(database, agentId, status) {
|
|
106
|
+
if (!database) {
|
|
107
|
+
throw new Error("Subagent database is required to update a subagent");
|
|
108
|
+
}
|
|
109
|
+
database.db
|
|
110
|
+
.update(subagentsTable)
|
|
111
|
+
.set({ status, updatedAt: new Date().toISOString() })
|
|
112
|
+
.where(eq(subagentsTable.agentId, agentId))
|
|
113
|
+
.run();
|
|
114
|
+
}
|
|
115
|
+
async function sessionHasCalledSubagent(session) {
|
|
116
|
+
const context = await session.buildContext();
|
|
117
|
+
return context.messages.some((message) => {
|
|
118
|
+
if (!message || typeof message !== "object")
|
|
119
|
+
return false;
|
|
120
|
+
const record = message;
|
|
121
|
+
return record.role === "custom" && record.customType === "callsubagent";
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
async function startSubagent(input, request) {
|
|
125
|
+
const agentId = `agent_${randomUUID()}`;
|
|
126
|
+
const createdAt = new Date().toISOString();
|
|
127
|
+
const childSession = await input.sessionRepo.create({
|
|
128
|
+
cwd: input.workspacePath
|
|
129
|
+
});
|
|
130
|
+
const childSessionMetadata = toAgentSessionMetadata(await childSession.getMetadata());
|
|
131
|
+
input.persistedSubagentRepository.create({
|
|
132
|
+
agentId,
|
|
133
|
+
agentName: request.agentName,
|
|
134
|
+
createdAt,
|
|
135
|
+
parentAgentId: input.parentAgentId,
|
|
136
|
+
sessionCreatedAt: childSessionMetadata.createdAt,
|
|
137
|
+
sessionId: childSessionMetadata.id,
|
|
138
|
+
sessionPath: childSessionMetadata.path,
|
|
139
|
+
status: "running",
|
|
140
|
+
taskId: input.taskId,
|
|
141
|
+
updatedAt: createdAt
|
|
142
|
+
});
|
|
143
|
+
let started;
|
|
144
|
+
try {
|
|
145
|
+
started = await input.startHarness(request.prompt, {
|
|
146
|
+
agentId,
|
|
147
|
+
agentName: request.agentName,
|
|
148
|
+
isContinue: false,
|
|
149
|
+
parentAgentId: input.parentAgentId,
|
|
150
|
+
pluginPrompt: request.prompt,
|
|
151
|
+
session: childSession
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
input.persistedSubagentRepository.delete(agentId);
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
const details = {
|
|
159
|
+
agentId: started.agentId,
|
|
160
|
+
agentName: request.agentName,
|
|
161
|
+
parentAgentId: input.parentAgentId,
|
|
162
|
+
session: started.session,
|
|
163
|
+
taskId: input.taskId
|
|
164
|
+
};
|
|
165
|
+
input.subagents.set(started.agentId, {
|
|
166
|
+
agentId: started.agentId,
|
|
167
|
+
agentName: request.agentName,
|
|
168
|
+
agentSession: started.harnessSession,
|
|
169
|
+
consumed: false,
|
|
170
|
+
lastAssistantText: "",
|
|
171
|
+
parentAgentId: input.parentAgentId,
|
|
172
|
+
...(input.parentAgentName === undefined
|
|
173
|
+
? {}
|
|
174
|
+
: { parentAgentName: input.parentAgentName }),
|
|
175
|
+
parentSession: input.parentSession,
|
|
176
|
+
session: started.session,
|
|
177
|
+
status: "running"
|
|
178
|
+
});
|
|
179
|
+
const pendingMessages = input.pendingVisibleMessages.get(request.toolCallId) ?? [];
|
|
180
|
+
pendingMessages.push({
|
|
181
|
+
content: `Subagent "${request.agentName}" is running.`,
|
|
182
|
+
customType: CALL_SUBAGENT_CUSTOM_TYPE,
|
|
183
|
+
details
|
|
184
|
+
});
|
|
185
|
+
input.pendingVisibleMessages.set(request.toolCallId, pendingMessages);
|
|
186
|
+
return {
|
|
187
|
+
content: [
|
|
188
|
+
{
|
|
189
|
+
text: `Subagent "${request.agentName}" is running. agentId=${started.agentId}`,
|
|
190
|
+
type: "text"
|
|
191
|
+
}
|
|
192
|
+
],
|
|
193
|
+
details
|
|
194
|
+
};
|
|
195
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type AgentHarness, type JsonlSessionRepoApi } from "@earendil-works/pi-agent-core/node";
|
|
2
|
+
import type { SkillsService } from "../../skills";
|
|
3
|
+
import type { AgentSessionMetadata } from "../agent-types";
|
|
4
|
+
export interface WorkspaceSkill {
|
|
5
|
+
name: string;
|
|
6
|
+
path: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function interruptHarness(harness: AgentHarness): Promise<void>;
|
|
9
|
+
export declare function createSessionRepo(): JsonlSessionRepoApi;
|
|
10
|
+
export declare function getSkillDirs(workspacePath: string, configuredSkillDirs?: string[]): string[];
|
|
11
|
+
export declare function getRuntimeSkillDirs(workspacePath: string, configuredSkillDirs?: string[], skillsService?: SkillsService): Promise<string[]>;
|
|
12
|
+
export declare function listWorkspaceSkills(workspacePath: string, configuredSkillDirs?: string[], skillsService?: SkillsService): Promise<WorkspaceSkill[]>;
|
|
13
|
+
export declare function getEnvApiKey(provider: string): string | undefined;
|
|
14
|
+
export declare function toAgentSessionMetadata(metadata: {
|
|
15
|
+
createdAt: string;
|
|
16
|
+
id: string;
|
|
17
|
+
path: string;
|
|
18
|
+
}): AgentSessionMetadata;
|
|
19
|
+
//# sourceMappingURL=support.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"support.d.ts","sourceRoot":"","sources":["../../../../src/modules/agents/runtime/support.ts"],"names":[],"mappings":"AAIA,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACzB,MAAM,oCAAoC,CAAC;AAG5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAO3D,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAc3E;AAED,wBAAgB,iBAAiB,IAAI,mBAAmB,CAKvD;AAED,wBAAgB,YAAY,CAC1B,aAAa,EAAE,MAAM,EACrB,mBAAmB,CAAC,EAAE,MAAM,EAAE,GAC7B,MAAM,EAAE,CAOV;AAED,wBAAsB,mBAAmB,CACvC,aAAa,EAAE,MAAM,EACrB,mBAAmB,CAAC,EAAE,MAAM,EAAE,EAC9B,aAAa,CAAC,EAAE,aAAa,GAC5B,OAAO,CAAC,MAAM,EAAE,CAAC,CAanB;AAED,wBAAsB,mBAAmB,CACvC,aAAa,EAAE,MAAM,EACrB,mBAAmB,CAAC,EAAE,MAAM,EAAE,EAC9B,aAAa,CAAC,EAAE,aAAa,GAC5B,OAAO,CAAC,cAAc,EAAE,CAAC,CAW3B;AAoED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEjE;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE;IAC/C,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,oBAAoB,CAMvB"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
2
|
+
import { basename, join } from "node:path";
|
|
3
|
+
import { JsonlSessionRepo, NodeExecutionEnv } from "@earendil-works/pi-agent-core/node";
|
|
4
|
+
import { SESSIONS_DIR, SKILL_DIR } from "../../../config/const.js";
|
|
5
|
+
export async function interruptHarness(harness) {
|
|
6
|
+
const interruptibleHarness = harness;
|
|
7
|
+
if (interruptibleHarness.interrupt) {
|
|
8
|
+
await interruptibleHarness.interrupt();
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (interruptibleHarness.abort) {
|
|
12
|
+
await interruptibleHarness.abort();
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
throw new Error("Agent runtime does not support interruption");
|
|
16
|
+
}
|
|
17
|
+
export function createSessionRepo() {
|
|
18
|
+
return new JsonlSessionRepo({
|
|
19
|
+
fs: new NodeExecutionEnv({ cwd: SESSIONS_DIR }),
|
|
20
|
+
sessionsRoot: SESSIONS_DIR
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export function getSkillDirs(workspacePath, configuredSkillDirs) {
|
|
24
|
+
return Array.from(new Set([
|
|
25
|
+
join(workspacePath, ".agents", "skills"),
|
|
26
|
+
join(workspacePath, ".hold-rein", "skills"),
|
|
27
|
+
SKILL_DIR,
|
|
28
|
+
...(configuredSkillDirs ?? [])
|
|
29
|
+
]));
|
|
30
|
+
}
|
|
31
|
+
export async function getRuntimeSkillDirs(workspacePath, configuredSkillDirs, skillsService) {
|
|
32
|
+
const enabledGlobalSkillDirs = await skillsService?.listEnabledSkillDirs();
|
|
33
|
+
if (!enabledGlobalSkillDirs) {
|
|
34
|
+
return getSkillDirs(workspacePath, configuredSkillDirs);
|
|
35
|
+
}
|
|
36
|
+
return Array.from(new Set([
|
|
37
|
+
join(workspacePath, ".agents", "skills"),
|
|
38
|
+
join(workspacePath, ".hold-rein", "skills"),
|
|
39
|
+
...enabledGlobalSkillDirs,
|
|
40
|
+
...(configuredSkillDirs ?? [])
|
|
41
|
+
]));
|
|
42
|
+
}
|
|
43
|
+
export async function listWorkspaceSkills(workspacePath, configuredSkillDirs, skillsService) {
|
|
44
|
+
const skillDirs = await getRuntimeSkillDirs(workspacePath, configuredSkillDirs, skillsService);
|
|
45
|
+
const skills = await Promise.all(skillDirs.map((skillDir) => listSkillsInDir(skillDir)));
|
|
46
|
+
return skills.flat();
|
|
47
|
+
}
|
|
48
|
+
async function listSkillsInDir(skillDir) {
|
|
49
|
+
let entries;
|
|
50
|
+
const directSkill = await readSkillPath(skillDir);
|
|
51
|
+
if (directSkill) {
|
|
52
|
+
return [directSkill];
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
entries = await readdir(skillDir, { withFileTypes: true });
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
const skillEntries = entries
|
|
61
|
+
.filter((entry) => entry.isDirectory())
|
|
62
|
+
.sort((leftEntry, rightEntry) => leftEntry.name.localeCompare(rightEntry.name));
|
|
63
|
+
const skills = await Promise.all(skillEntries.map((entry) => readSkill(skillDir, entry.name)));
|
|
64
|
+
return skills.filter((skill) => skill !== null);
|
|
65
|
+
}
|
|
66
|
+
async function readSkill(skillDir, skillFolderName) {
|
|
67
|
+
return readSkillPath(join(skillDir, skillFolderName));
|
|
68
|
+
}
|
|
69
|
+
async function readSkillPath(skillPath) {
|
|
70
|
+
const skillFilePath = join(skillPath, "SKILL.md");
|
|
71
|
+
try {
|
|
72
|
+
const content = await readFile(skillFilePath, "utf8");
|
|
73
|
+
return {
|
|
74
|
+
name: parseSkillName(content) ?? basename(skillPath),
|
|
75
|
+
path: skillPath
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function parseSkillName(content) {
|
|
83
|
+
const frontmatterMatch = /^---\n(?<frontmatter>[\s\S]*?)\n---/u.exec(content);
|
|
84
|
+
const frontmatter = frontmatterMatch?.groups?.frontmatter;
|
|
85
|
+
if (!frontmatter) {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
for (const line of frontmatter.split("\n")) {
|
|
89
|
+
const nameMatch = /^name:\s*(?<name>.+?)\s*$/u.exec(line);
|
|
90
|
+
const rawName = nameMatch?.groups?.name;
|
|
91
|
+
if (rawName) {
|
|
92
|
+
return rawName.replace(/^["']|["']$/gu, "");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
export function getEnvApiKey(provider) {
|
|
98
|
+
return process.env[`${provider.toUpperCase()}_API_KEY`];
|
|
99
|
+
}
|
|
100
|
+
export function toAgentSessionMetadata(metadata) {
|
|
101
|
+
return {
|
|
102
|
+
createdAt: metadata.createdAt,
|
|
103
|
+
id: metadata.id,
|
|
104
|
+
path: metadata.path
|
|
105
|
+
};
|
|
106
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AgentHarnessEvent } from "@earendil-works/pi-agent-core";
|
|
2
|
+
import type { NewModelTokenUsageHourlyRow, TaskRow } from "../../../db";
|
|
3
|
+
export interface TaskTokenUsageDelta {
|
|
4
|
+
inputToken: number;
|
|
5
|
+
outputToken: number;
|
|
6
|
+
}
|
|
7
|
+
export interface TokenUsageStorageTarget {
|
|
8
|
+
addModelTokenUsageHourly: (usage: NewModelTokenUsageHourlyRow) => unknown;
|
|
9
|
+
addTaskTokenUsage: (taskId: string, usage: Pick<TaskRow, "inputToken" | "outputToken">) => unknown;
|
|
10
|
+
}
|
|
11
|
+
export interface TokenCollection {
|
|
12
|
+
appendHarness: (harness: TokenCollectableHarness) => void;
|
|
13
|
+
flush: () => void;
|
|
14
|
+
}
|
|
15
|
+
interface TokenCollectableHarness {
|
|
16
|
+
subscribe: (listener: (event: AgentHarnessEvent, signal?: AbortSignal) => Promise<void> | void) => () => void;
|
|
17
|
+
}
|
|
18
|
+
export interface CreateTokenCollectionOptions {
|
|
19
|
+
flushIntervalMs?: number;
|
|
20
|
+
storageTarget?: TokenUsageStorageTarget;
|
|
21
|
+
}
|
|
22
|
+
export declare function createRuntimeTokenCollectionOptions(input: {
|
|
23
|
+
tokenFlushIntervalMs?: number | undefined;
|
|
24
|
+
tokenUsageStorageTarget?: TokenUsageStorageTarget | undefined;
|
|
25
|
+
}): CreateTokenCollectionOptions;
|
|
26
|
+
export declare function createTokenCollection(taskId: string, options?: CreateTokenCollectionOptions): TokenCollection;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=token-collection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-collection.d.ts","sourceRoot":"","sources":["../../../../src/modules/agents/runtime/token-collection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,KAAK,EAAE,2BAA2B,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAExE,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,uBAAuB;IACtC,wBAAwB,EAAE,CAAC,KAAK,EAAE,2BAA2B,KAAK,OAAO,CAAC;IAC1E,iBAAiB,EAAE,CACjB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,YAAY,GAAG,aAAa,CAAC,KAC/C,OAAO,CAAC;CACd;AAED,MAAM,WAAW,eAAe;IAC9B,aAAa,EAAE,CAAC,OAAO,EAAE,uBAAuB,KAAK,IAAI,CAAC;IAC1D,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,UAAU,uBAAuB;IAC/B,SAAS,EAAE,CACT,QAAQ,EAAE,CAAC,KAAK,EAAE,iBAAiB,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,KAC/E,MAAM,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,4BAA4B;IAC3C,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,uBAAuB,CAAC;CACzC;AAID,wBAAgB,mCAAmC,CAAC,KAAK,EAAE;IACzD,oBAAoB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,uBAAuB,CAAC,EAAE,uBAAuB,GAAG,SAAS,CAAC;CAC/D,GAAG,4BAA4B,CAS/B;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,4BAAiC,GACzC,eAAe,CAoIjB"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
const DEFAULT_TOKEN_FLUSH_INTERVAL_MS = 5000;
|
|
2
|
+
export function createRuntimeTokenCollectionOptions(input) {
|
|
3
|
+
if (!input.tokenUsageStorageTarget)
|
|
4
|
+
return {};
|
|
5
|
+
return {
|
|
6
|
+
...(input.tokenFlushIntervalMs === undefined
|
|
7
|
+
? {}
|
|
8
|
+
: { flushIntervalMs: input.tokenFlushIntervalMs }),
|
|
9
|
+
storageTarget: input.tokenUsageStorageTarget
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function createTokenCollection(taskId, options = {}) {
|
|
13
|
+
let pendingInputToken = 0;
|
|
14
|
+
let pendingOutputToken = 0;
|
|
15
|
+
let flushTimer;
|
|
16
|
+
const flushIntervalMs = options.flushIntervalMs ?? DEFAULT_TOKEN_FLUSH_INTERVAL_MS;
|
|
17
|
+
const subscriptions = new Map();
|
|
18
|
+
const pendingModelUsages = new Map();
|
|
19
|
+
const scheduleFlush = () => {
|
|
20
|
+
if (options.storageTarget === undefined || flushTimer !== undefined)
|
|
21
|
+
return;
|
|
22
|
+
flushTimer = setTimeout(() => {
|
|
23
|
+
flushTimer = undefined;
|
|
24
|
+
flush();
|
|
25
|
+
}, flushIntervalMs);
|
|
26
|
+
};
|
|
27
|
+
const record = (usage) => {
|
|
28
|
+
pendingInputToken += usage.inputToken;
|
|
29
|
+
pendingOutputToken += usage.outputToken;
|
|
30
|
+
const hour = toUsageHour(usage.hour);
|
|
31
|
+
const key = `${usage.provider}\0${usage.modelName}\0${hour}`;
|
|
32
|
+
const existingUsage = pendingModelUsages.get(key);
|
|
33
|
+
pendingModelUsages.set(key, {
|
|
34
|
+
hour,
|
|
35
|
+
inputToken: (existingUsage?.inputToken ?? 0) + usage.inputToken,
|
|
36
|
+
modelName: usage.modelName,
|
|
37
|
+
outputToken: (existingUsage?.outputToken ?? 0) + usage.outputToken,
|
|
38
|
+
provider: usage.provider
|
|
39
|
+
});
|
|
40
|
+
scheduleFlush();
|
|
41
|
+
};
|
|
42
|
+
const requeueModelUsage = (usage) => {
|
|
43
|
+
const key = `${usage.provider}\0${usage.modelName}\0${usage.hour}`;
|
|
44
|
+
const existingUsage = pendingModelUsages.get(key);
|
|
45
|
+
pendingModelUsages.set(key, {
|
|
46
|
+
...usage,
|
|
47
|
+
inputToken: (existingUsage?.inputToken ?? 0) + (usage.inputToken ?? 0),
|
|
48
|
+
outputToken: (existingUsage?.outputToken ?? 0) + (usage.outputToken ?? 0)
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
function flush() {
|
|
52
|
+
if (flushTimer !== undefined) {
|
|
53
|
+
clearTimeout(flushTimer);
|
|
54
|
+
flushTimer = undefined;
|
|
55
|
+
}
|
|
56
|
+
const storageTarget = options.storageTarget;
|
|
57
|
+
if (storageTarget === undefined)
|
|
58
|
+
return;
|
|
59
|
+
const taskUsage = {
|
|
60
|
+
inputToken: pendingInputToken,
|
|
61
|
+
outputToken: pendingOutputToken
|
|
62
|
+
};
|
|
63
|
+
const modelUsages = [...pendingModelUsages.values()];
|
|
64
|
+
pendingInputToken = 0;
|
|
65
|
+
pendingOutputToken = 0;
|
|
66
|
+
pendingModelUsages.clear();
|
|
67
|
+
if (taskUsage.inputToken > 0 || taskUsage.outputToken > 0) {
|
|
68
|
+
try {
|
|
69
|
+
storageTarget.addTaskTokenUsage(taskId, taskUsage);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
pendingInputToken += taskUsage.inputToken;
|
|
73
|
+
pendingOutputToken += taskUsage.outputToken;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
for (const modelUsage of modelUsages) {
|
|
77
|
+
try {
|
|
78
|
+
storageTarget.addModelTokenUsageHourly(modelUsage);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
requeueModelUsage(modelUsage);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (pendingInputToken > 0 ||
|
|
85
|
+
pendingOutputToken > 0 ||
|
|
86
|
+
pendingModelUsages.size > 0) {
|
|
87
|
+
scheduleFlush();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
appendHarness: (harness) => {
|
|
92
|
+
if (subscriptions.has(harness))
|
|
93
|
+
return;
|
|
94
|
+
const unsubscribe = harness.subscribe((event) => {
|
|
95
|
+
if (!subscriptions.has(harness))
|
|
96
|
+
return;
|
|
97
|
+
if (event.type === "message_end") {
|
|
98
|
+
if (event.message.role !== "assistant") {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const usage = event.message.usage;
|
|
102
|
+
const usageDelta = {
|
|
103
|
+
inputToken: usage?.input ?? 0,
|
|
104
|
+
outputToken: usage?.output ?? 0
|
|
105
|
+
};
|
|
106
|
+
if (usageDelta.inputToken > 0 || usageDelta.outputToken > 0) {
|
|
107
|
+
record({
|
|
108
|
+
...usageDelta,
|
|
109
|
+
hour: new Date(event.message.timestamp).toISOString(),
|
|
110
|
+
modelName: event.message.model,
|
|
111
|
+
provider: event.message.provider
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (event.type === "agent_end") {
|
|
117
|
+
subscriptions.get(harness)?.();
|
|
118
|
+
subscriptions.delete(harness);
|
|
119
|
+
flush();
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
subscriptions.set(harness, unsubscribe);
|
|
123
|
+
},
|
|
124
|
+
flush
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function toUsageHour(value) {
|
|
128
|
+
const date = new Date(value);
|
|
129
|
+
date.setUTCMinutes(0, 0, 0);
|
|
130
|
+
return date.toISOString();
|
|
131
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TaskTokenUsageDelta } from "./token-collection";
|
|
2
|
+
export interface TokenUsageSyncTarget {
|
|
3
|
+
addTaskTokenUsage: (taskId: string, usage: TaskTokenUsageDelta) => unknown;
|
|
4
|
+
}
|
|
5
|
+
export interface TokenUsageSync {
|
|
6
|
+
flush: () => void;
|
|
7
|
+
record: (usage: TaskTokenUsageDelta) => void;
|
|
8
|
+
}
|
|
9
|
+
export interface CreateTokenUsageSyncOptions {
|
|
10
|
+
flushIntervalMs?: number;
|
|
11
|
+
syncTarget: TokenUsageSyncTarget;
|
|
12
|
+
taskId: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function createTokenUsageSync(options: CreateTokenUsageSyncOptions): TokenUsageSync;
|
|
15
|
+
//# sourceMappingURL=token-usage-sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-usage-sync.d.ts","sourceRoot":"","sources":["../../../../src/modules/agents/runtime/token-usage-sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,MAAM,WAAW,oBAAoB;IACnC,iBAAiB,EAAE,CACjB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,mBAAmB,KACvB,OAAO,CAAC;CACd;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,MAAM,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,CAAC;CAC9C;AAED,MAAM,WAAW,2BAA2B;IAC1C,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,oBAAoB,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;CAChB;AAID,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,2BAA2B,GACnC,cAAc,CAkDhB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const DEFAULT_TOKEN_FLUSH_INTERVAL_MS = 5000;
|
|
2
|
+
export function createTokenUsageSync(options) {
|
|
3
|
+
let pendingInputToken = 0;
|
|
4
|
+
let pendingOutputToken = 0;
|
|
5
|
+
let flushTimer;
|
|
6
|
+
const flushIntervalMs = options.flushIntervalMs ?? DEFAULT_TOKEN_FLUSH_INTERVAL_MS;
|
|
7
|
+
const scheduleFlush = () => {
|
|
8
|
+
if (flushTimer !== undefined)
|
|
9
|
+
return;
|
|
10
|
+
flushTimer = setTimeout(() => {
|
|
11
|
+
flushTimer = undefined;
|
|
12
|
+
flush();
|
|
13
|
+
}, flushIntervalMs);
|
|
14
|
+
};
|
|
15
|
+
const flush = () => {
|
|
16
|
+
if (flushTimer !== undefined) {
|
|
17
|
+
clearTimeout(flushTimer);
|
|
18
|
+
flushTimer = undefined;
|
|
19
|
+
}
|
|
20
|
+
if (pendingInputToken === 0 && pendingOutputToken === 0) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const usage = {
|
|
24
|
+
inputToken: pendingInputToken,
|
|
25
|
+
outputToken: pendingOutputToken
|
|
26
|
+
};
|
|
27
|
+
pendingInputToken = 0;
|
|
28
|
+
pendingOutputToken = 0;
|
|
29
|
+
try {
|
|
30
|
+
options.syncTarget.addTaskTokenUsage(options.taskId, usage);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
pendingInputToken += usage.inputToken;
|
|
34
|
+
pendingOutputToken += usage.outputToken;
|
|
35
|
+
scheduleFlush();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
flush,
|
|
40
|
+
record: (usage) => {
|
|
41
|
+
pendingInputToken += usage.inputToken;
|
|
42
|
+
pendingOutputToken += usage.outputToken;
|
|
43
|
+
scheduleFlush();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|