@geminixiang/mikan 1.0.0-beta.53 → 1.0.0-beta.55
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/CHANGELOG.md +29 -0
- package/README.md +3 -2
- package/dist/adapters/commands/admin.d.ts.map +1 -0
- package/dist/{commands → adapters/commands}/admin.js +4 -8
- package/dist/adapters/commands/admin.js.map +1 -0
- package/dist/adapters/commands/login.d.ts.map +1 -0
- package/dist/adapters/commands/login.js +166 -0
- package/dist/adapters/commands/login.js.map +1 -0
- package/dist/adapters/commands/manifest.d.ts.map +1 -0
- package/dist/{commands → adapters/commands}/manifest.js +0 -7
- package/dist/adapters/commands/manifest.js.map +1 -0
- package/dist/{commands → adapters/commands}/model.d.ts +6 -0
- package/dist/adapters/commands/model.d.ts.map +1 -0
- package/dist/{commands → adapters/commands}/model.js +56 -44
- package/dist/adapters/commands/model.js.map +1 -0
- package/dist/adapters/commands/new.d.ts.map +1 -0
- package/dist/{commands → adapters/commands}/new.js +7 -8
- package/dist/adapters/commands/new.js.map +1 -0
- package/dist/adapters/commands/registry.d.ts.map +1 -0
- package/dist/{commands → adapters/commands}/registry.js +1 -3
- package/dist/adapters/commands/registry.js.map +1 -0
- package/dist/adapters/commands/sandbox.d.ts.map +1 -0
- package/dist/{commands → adapters/commands}/sandbox.js +22 -21
- package/dist/adapters/commands/sandbox.js.map +1 -0
- package/dist/adapters/commands/session-view.d.ts.map +1 -0
- package/dist/{commands → adapters/commands}/session-view.js +8 -11
- package/dist/adapters/commands/session-view.js.map +1 -0
- package/dist/{commands → adapters/commands}/types.d.ts +6 -6
- package/dist/adapters/commands/types.d.ts.map +1 -0
- package/dist/adapters/commands/types.js.map +1 -0
- package/dist/adapters/commands/utils.d.ts +14 -0
- package/dist/adapters/commands/utils.d.ts.map +1 -0
- package/dist/{commands → adapters/commands}/utils.js +18 -1
- package/dist/adapters/commands/utils.js.map +1 -0
- package/dist/adapters/discord/bot.d.ts.map +1 -1
- package/dist/adapters/discord/bot.js +4 -5
- package/dist/adapters/discord/bot.js.map +1 -1
- package/dist/adapters/github/bot.d.ts.map +1 -1
- package/dist/adapters/github/bot.js +3 -4
- package/dist/adapters/github/bot.js.map +1 -1
- package/dist/adapters/github/client.d.ts.map +1 -1
- package/dist/adapters/github/client.js +5 -18
- package/dist/adapters/github/client.js.map +1 -1
- package/dist/adapters/github/tool-pack.d.ts +1 -1
- package/dist/adapters/github/tool-pack.d.ts.map +1 -1
- package/dist/adapters/github/tool-pack.js.map +1 -1
- package/dist/adapters/github/tools/checks.js +1 -1
- package/dist/adapters/github/tools/checks.js.map +1 -1
- package/dist/adapters/github/tools/issue.js +1 -1
- package/dist/adapters/github/tools/issue.js.map +1 -1
- package/dist/adapters/github/tools/pr.js +1 -1
- package/dist/adapters/github/tools/pr.js.map +1 -1
- package/dist/adapters/github/tools/read.d.ts.map +1 -1
- package/dist/adapters/github/tools/read.js +53 -53
- package/dist/adapters/github/tools/read.js.map +1 -1
- package/dist/adapters/github/tools/review-reply.js +1 -1
- package/dist/adapters/github/tools/review-reply.js.map +1 -1
- package/dist/adapters/github/tools/sync.js +1 -1
- package/dist/adapters/github/tools/sync.js.map +1 -1
- package/dist/adapters/intake.d.ts +1 -1
- package/dist/adapters/intake.d.ts.map +1 -1
- package/dist/adapters/intake.js +2 -6
- package/dist/adapters/intake.js.map +1 -1
- package/dist/adapters/markdown-tables.d.ts +0 -13
- package/dist/adapters/markdown-tables.d.ts.map +1 -1
- package/dist/adapters/markdown-tables.js +26 -38
- package/dist/adapters/markdown-tables.js.map +1 -1
- package/dist/adapters/shared.js +1 -1
- package/dist/adapters/shared.js.map +1 -1
- package/dist/adapters/slack/bot.d.ts +7 -4
- package/dist/adapters/slack/bot.d.ts.map +1 -1
- package/dist/adapters/slack/bot.js +104 -122
- package/dist/adapters/slack/bot.js.map +1 -1
- package/dist/adapters/slack/response-lifecycle.d.ts.map +1 -1
- package/dist/adapters/slack/response-lifecycle.js +33 -25
- package/dist/adapters/slack/response-lifecycle.js.map +1 -1
- package/dist/adapters/slack/tool-pack.d.ts +1 -1
- package/dist/adapters/slack/tool-pack.d.ts.map +1 -1
- package/dist/adapters/slack/tool-pack.js.map +1 -1
- package/dist/adapters/slack/update-diagnostics.d.ts.map +1 -1
- package/dist/adapters/slack/update-diagnostics.js +8 -24
- package/dist/adapters/slack/update-diagnostics.js.map +1 -1
- package/dist/adapters/telegram/bot.d.ts.map +1 -1
- package/dist/adapters/telegram/bot.js +3 -4
- package/dist/adapters/telegram/bot.js.map +1 -1
- package/dist/adapters/types.d.ts +2 -4
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/adapters/types.js.map +1 -1
- package/dist/{web → adapters/web}/admin/portal.d.ts +3 -3
- package/dist/adapters/web/admin/portal.d.ts.map +1 -0
- package/dist/{web → adapters/web}/admin/portal.js +535 -709
- package/dist/adapters/web/admin/portal.js.map +1 -0
- package/dist/{web → adapters/web}/admin/provider-models.d.ts +1 -1
- package/dist/adapters/web/admin/provider-models.d.ts.map +1 -0
- package/dist/adapters/web/admin/provider-models.js.map +1 -0
- package/dist/{web → adapters/web}/admin/types.d.ts +5 -5
- package/dist/adapters/web/admin/types.d.ts.map +1 -0
- package/dist/adapters/web/admin/types.js.map +1 -0
- package/dist/adapters/web/login/oauth.d.ts.map +1 -0
- package/dist/{web → adapters/web}/login/oauth.js +50 -54
- package/dist/adapters/web/login/oauth.js.map +1 -0
- package/dist/{web → adapters/web}/login/portal.d.ts +2 -2
- package/dist/adapters/web/login/portal.d.ts.map +1 -0
- package/dist/{web → adapters/web}/login/portal.js +6 -6
- package/dist/adapters/web/login/portal.js.map +1 -0
- package/dist/{web → adapters/web}/login/types.d.ts +1 -1
- package/dist/adapters/web/login/types.d.ts.map +1 -0
- package/dist/adapters/web/login/types.js.map +1 -0
- package/dist/{web → adapters/web}/portal-shell.d.ts +2 -2
- package/dist/adapters/web/portal-shell.d.ts.map +1 -0
- package/dist/{web → adapters/web}/portal-shell.js +2 -2
- package/dist/adapters/web/portal-shell.js.map +1 -0
- package/dist/{web → adapters/web}/server.d.ts +5 -5
- package/dist/adapters/web/server.d.ts.map +1 -0
- package/dist/{web → adapters/web}/server.js +4 -7
- package/dist/adapters/web/server.js.map +1 -0
- package/dist/adapters/web/session-view/portal.d.ts.map +1 -0
- package/dist/{web → adapters/web}/session-view/portal.js +9 -9
- package/dist/adapters/web/session-view/portal.js.map +1 -0
- package/dist/{web → adapters/web}/session-view/types.d.ts +3 -3
- package/dist/adapters/web/session-view/types.d.ts.map +1 -0
- package/dist/adapters/web/session-view/types.js.map +1 -0
- package/dist/adapters/web/token-store.d.ts.map +1 -0
- package/dist/adapters/web/token-store.js.map +1 -0
- package/dist/adapters/web/types.d.ts.map +1 -0
- package/dist/adapters/web/types.js.map +1 -0
- package/dist/cli/arg-grammar.d.ts +24 -0
- package/dist/cli/arg-grammar.d.ts.map +1 -1
- package/dist/cli/arg-grammar.js +39 -8
- package/dist/cli/arg-grammar.js.map +1 -1
- package/dist/cli/boot.d.ts.map +1 -1
- package/dist/cli/boot.js +48 -62
- package/dist/cli/boot.js.map +1 -1
- package/dist/cli/download.d.ts.map +1 -1
- package/dist/cli/download.js +51 -54
- package/dist/cli/download.js.map +1 -1
- package/dist/cli/office.d.ts.map +1 -1
- package/dist/cli/office.js +9 -26
- package/dist/cli/office.js.map +1 -1
- package/dist/cli/onboard.d.ts.map +1 -1
- package/dist/cli/onboard.js +15 -11
- package/dist/cli/onboard.js.map +1 -1
- package/dist/cli/sessions.d.ts.map +1 -1
- package/dist/cli/sessions.js +49 -52
- package/dist/cli/sessions.js.map +1 -1
- package/dist/config.d.ts +4 -28
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +7 -112
- package/dist/config.js.map +1 -1
- package/dist/dream/index.d.ts.map +1 -1
- package/dist/dream/index.js +8 -2
- package/dist/dream/index.js.map +1 -1
- package/dist/dream/types.d.ts +1 -1
- package/dist/dream/types.d.ts.map +1 -1
- package/dist/dream/types.js.map +1 -1
- package/dist/env-manifest.d.ts +2 -0
- package/dist/env-manifest.d.ts.map +1 -1
- package/dist/env-manifest.js +29 -8
- package/dist/env-manifest.js.map +1 -1
- package/dist/events/index.d.ts +150 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/{harness/event-format.js → events/index.js} +80 -2
- package/dist/events/index.js.map +1 -0
- package/dist/{events.d.ts → events/watcher.d.ts} +4 -4
- package/dist/events/watcher.d.ts.map +1 -0
- package/dist/{events.js → events/watcher.js} +8 -8
- package/dist/events/watcher.js.map +1 -0
- package/dist/file-guards.d.ts.map +1 -0
- package/dist/file-guards.js.map +1 -0
- package/dist/harness/execution-env.d.ts +19 -0
- package/dist/harness/execution-env.d.ts.map +1 -0
- package/dist/harness/execution-env.js +262 -0
- package/dist/harness/execution-env.js.map +1 -0
- package/dist/harness/execution-resolver.d.ts +25 -0
- package/dist/harness/execution-resolver.d.ts.map +1 -0
- package/dist/{execution-resolver.js → harness/execution-resolver.js} +12 -21
- package/dist/harness/execution-resolver.js.map +1 -0
- package/dist/harness/index.d.ts +9 -9
- package/dist/harness/index.d.ts.map +1 -1
- package/dist/harness/index.js +8 -8
- package/dist/harness/index.js.map +1 -1
- package/dist/harness/mcp.d.ts +38 -0
- package/dist/harness/mcp.d.ts.map +1 -0
- package/dist/{mcp/loader.js → harness/mcp.js} +155 -6
- package/dist/harness/mcp.js.map +1 -0
- package/dist/harness/models.js +1 -1
- package/dist/harness/models.js.map +1 -1
- package/dist/harness/open-connector.d.ts.map +1 -0
- package/dist/{mcp → harness}/open-connector.js +1 -1
- package/dist/harness/open-connector.js.map +1 -0
- package/dist/{agent → harness}/presenter.d.ts +2 -9
- package/dist/harness/presenter.d.ts.map +1 -0
- package/dist/{agent → harness}/presenter.js +170 -146
- package/dist/harness/presenter.js.map +1 -0
- package/dist/{agent → harness}/prompt.d.ts +10 -3
- package/dist/harness/prompt.d.ts.map +1 -0
- package/dist/{agent → harness}/prompt.js +137 -41
- package/dist/harness/prompt.js.map +1 -0
- package/dist/harness/runner.d.ts +2 -109
- package/dist/harness/runner.d.ts.map +1 -1
- package/dist/harness/runner.js +499 -467
- package/dist/harness/runner.js.map +1 -1
- package/dist/harness/session.d.ts +119 -0
- package/dist/harness/session.d.ts.map +1 -0
- package/dist/harness/session.js +561 -0
- package/dist/harness/session.js.map +1 -0
- package/dist/harness/skills.d.ts +10 -2
- package/dist/harness/skills.d.ts.map +1 -1
- package/dist/harness/skills.js +62 -39
- package/dist/harness/skills.js.map +1 -1
- package/dist/harness/{subagent-runner.d.ts → subagent.d.ts} +25 -6
- package/dist/harness/subagent.d.ts.map +1 -0
- package/dist/harness/{subagent-runner.js → subagent.js} +106 -54
- package/dist/harness/subagent.js.map +1 -0
- package/dist/harness/tools/attach.d.ts.map +1 -0
- package/dist/harness/tools/attach.js.map +1 -0
- package/dist/{tools → harness/tools}/event.d.ts +3 -32
- package/dist/harness/tools/event.d.ts.map +1 -0
- package/dist/harness/tools/event.js +178 -0
- package/dist/harness/tools/event.js.map +1 -0
- package/dist/harness/tools/generate-image.d.ts.map +1 -0
- package/dist/harness/tools/generate-image.js.map +1 -0
- package/dist/harness/tools/host-fn-tool.d.ts.map +1 -0
- package/dist/harness/tools/host-fn-tool.js.map +1 -0
- package/dist/{tools → harness/tools}/index.d.ts +5 -6
- package/dist/harness/tools/index.d.ts.map +1 -0
- package/dist/{tools → harness/tools}/index.js +12 -16
- package/dist/harness/tools/index.js.map +1 -0
- package/dist/harness/tools/pi-tools.d.ts +18 -0
- package/dist/harness/tools/pi-tools.d.ts.map +1 -0
- package/dist/harness/tools/pi-tools.js +84 -0
- package/dist/harness/tools/pi-tools.js.map +1 -0
- package/dist/harness/tools/react.d.ts.map +1 -0
- package/dist/harness/tools/react.js.map +1 -0
- package/dist/{tools → harness/tools}/sandbox.d.ts +2 -2
- package/dist/harness/tools/sandbox.d.ts.map +1 -0
- package/dist/{tools → harness/tools}/sandbox.js +1 -1
- package/dist/harness/tools/sandbox.js.map +1 -0
- package/dist/{tools → harness/tools}/subagent.d.ts +28 -1
- package/dist/harness/tools/subagent.d.ts.map +1 -0
- package/dist/{tools → harness/tools}/subagent.js +218 -2
- package/dist/harness/tools/subagent.js.map +1 -0
- package/dist/{tools → harness/tools}/types.d.ts +0 -33
- package/dist/harness/tools/types.d.ts.map +1 -0
- package/dist/harness/tools/types.js.map +1 -0
- package/dist/harness/types.d.ts +180 -97
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js +1 -1
- package/dist/harness/types.js.map +1 -1
- package/dist/index.d.ts +12 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/main.js +10 -12
- package/dist/main.js.map +1 -1
- package/dist/observability/index.d.ts +33 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +256 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/instrument.js +7 -1
- package/dist/observability/instrument.js.map +1 -1
- package/dist/observability/otel.d.ts +10 -0
- package/dist/observability/otel.d.ts.map +1 -0
- package/dist/observability/otel.js +183 -0
- package/dist/observability/otel.js.map +1 -0
- package/dist/observability/sentry.d.ts +22 -5
- package/dist/observability/sentry.d.ts.map +1 -1
- package/dist/observability/sentry.js +68 -23
- package/dist/observability/sentry.js.map +1 -1
- package/dist/observability/types.d.ts +6 -2
- package/dist/observability/types.d.ts.map +1 -1
- package/dist/observability/types.js.map +1 -1
- package/dist/office/index.d.ts +2 -3
- package/dist/office/index.d.ts.map +1 -1
- package/dist/office/index.js +172 -140
- package/dist/office/index.js.map +1 -1
- package/dist/{workspace-projection/index.d.ts → office/projection.d.ts} +2 -2
- package/dist/office/projection.d.ts.map +1 -0
- package/dist/{workspace-projection/index.js → office/projection.js} +2 -2
- package/dist/office/projection.js.map +1 -0
- package/dist/office/types.d.ts +29 -2
- package/dist/office/types.d.ts.map +1 -1
- package/dist/office/types.js.map +1 -1
- package/dist/process-lifecycle.d.ts +1 -1
- package/dist/process-lifecycle.d.ts.map +1 -1
- package/dist/process-lifecycle.js +3 -3
- package/dist/process-lifecycle.js.map +1 -1
- package/dist/runtime/conversation-runtime.d.ts.map +1 -1
- package/dist/runtime/conversation-runtime.js +106 -107
- package/dist/runtime/conversation-runtime.js.map +1 -1
- package/dist/runtime/session-lifecycle.d.ts +10 -0
- package/dist/runtime/session-lifecycle.d.ts.map +1 -1
- package/dist/runtime/session-lifecycle.js +42 -24
- package/dist/runtime/session-lifecycle.js.map +1 -1
- package/dist/runtime/types.d.ts +3 -3
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/types.js.map +1 -1
- package/dist/sandbox/cloudflare.d.ts +1 -0
- package/dist/sandbox/cloudflare.d.ts.map +1 -1
- package/dist/sandbox/cloudflare.js +41 -50
- package/dist/sandbox/cloudflare.js.map +1 -1
- package/dist/sandbox/container.d.ts.map +1 -1
- package/dist/sandbox/container.js +7 -4
- package/dist/sandbox/container.js.map +1 -1
- package/dist/sandbox/host.d.ts.map +1 -1
- package/dist/sandbox/host.js +27 -35
- package/dist/sandbox/host.js.map +1 -1
- package/dist/sandbox/index.d.ts.map +1 -1
- package/dist/sandbox/index.js +8 -15
- package/dist/sandbox/index.js.map +1 -1
- package/dist/{provisioner.d.ts → sandbox/provisioner.d.ts} +2 -2
- package/dist/sandbox/provisioner.d.ts.map +1 -0
- package/dist/{provisioner.js → sandbox/provisioner.js} +3 -3
- package/dist/sandbox/provisioner.js.map +1 -0
- package/dist/sandbox/types.d.ts +2 -0
- package/dist/sandbox/types.d.ts.map +1 -1
- package/dist/sandbox/types.js.map +1 -1
- package/dist/sandbox/utils.d.ts +5 -0
- package/dist/sandbox/utils.d.ts.map +1 -1
- package/dist/sandbox/utils.js +14 -0
- package/dist/sandbox/utils.js.map +1 -1
- package/dist/sessions/chat-history-sync.d.ts.map +1 -1
- package/dist/sessions/chat-history-sync.js +72 -62
- package/dist/sessions/chat-history-sync.js.map +1 -1
- package/dist/sessions/migrate-common.d.ts +43 -0
- package/dist/sessions/migrate-common.d.ts.map +1 -0
- package/dist/sessions/migrate-common.js +99 -0
- package/dist/sessions/migrate-common.js.map +1 -0
- package/dist/sessions/migrate-pi-084.d.ts.map +1 -1
- package/dist/sessions/migrate-pi-084.js +152 -203
- package/dist/sessions/migrate-pi-084.js.map +1 -1
- package/dist/sessions/migrate-v3.d.ts +5 -0
- package/dist/sessions/migrate-v3.d.ts.map +1 -1
- package/dist/sessions/migrate-v3.js +161 -209
- package/dist/sessions/migrate-v3.js.map +1 -1
- package/dist/{harness → sessions}/session-store.d.ts +12 -1
- package/dist/sessions/session-store.d.ts.map +1 -0
- package/dist/{harness → sessions}/session-store.js +74 -35
- package/dist/sessions/session-store.js.map +1 -0
- package/dist/sessions/store.d.ts +1 -1
- package/dist/sessions/store.d.ts.map +1 -1
- package/dist/sessions/store.js +18 -17
- package/dist/sessions/store.js.map +1 -1
- package/dist/sessions/types.d.ts +40 -1
- package/dist/sessions/types.d.ts.map +1 -1
- package/dist/sessions/types.js +1 -1
- package/dist/sessions/types.js.map +1 -1
- package/dist/types.d.ts +7 -99
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/vault/index.d.ts.map +1 -1
- package/dist/vault/index.js +70 -53
- package/dist/vault/index.js.map +1 -1
- package/package.json +10 -4
- package/dist/adapters/slack/tools/attach.d.ts.map +0 -1
- package/dist/adapters/slack/tools/attach.js.map +0 -1
- package/dist/agent/catalog.d.ts +0 -22
- package/dist/agent/catalog.d.ts.map +0 -1
- package/dist/agent/catalog.js +0 -104
- package/dist/agent/catalog.js.map +0 -1
- package/dist/agent/execution.d.ts +0 -25
- package/dist/agent/execution.d.ts.map +0 -1
- package/dist/agent/execution.js +0 -171
- package/dist/agent/execution.js.map +0 -1
- package/dist/agent/presenter.d.ts.map +0 -1
- package/dist/agent/presenter.js.map +0 -1
- package/dist/agent/prompt.d.ts.map +0 -1
- package/dist/agent/prompt.js.map +0 -1
- package/dist/agent/runner.d.ts +0 -3
- package/dist/agent/runner.d.ts.map +0 -1
- package/dist/agent/runner.js +0 -452
- package/dist/agent/runner.js.map +0 -1
- package/dist/agent/types.d.ts +0 -101
- package/dist/agent/types.d.ts.map +0 -1
- package/dist/agent/types.js +0 -3
- package/dist/agent/types.js.map +0 -1
- package/dist/agent-events.d.ts +0 -6
- package/dist/agent-events.d.ts.map +0 -1
- package/dist/agent-events.js +0 -44
- package/dist/agent-events.js.map +0 -1
- package/dist/commands/admin.d.ts.map +0 -1
- package/dist/commands/admin.js.map +0 -1
- package/dist/commands/auto-reply.d.ts +0 -8
- package/dist/commands/auto-reply.d.ts.map +0 -1
- package/dist/commands/auto-reply.js +0 -65
- package/dist/commands/auto-reply.js.map +0 -1
- package/dist/commands/login.d.ts.map +0 -1
- package/dist/commands/login.js +0 -158
- package/dist/commands/login.js.map +0 -1
- package/dist/commands/manifest.d.ts.map +0 -1
- package/dist/commands/manifest.js.map +0 -1
- package/dist/commands/model.d.ts.map +0 -1
- package/dist/commands/model.js.map +0 -1
- package/dist/commands/new.d.ts.map +0 -1
- package/dist/commands/new.js.map +0 -1
- package/dist/commands/registry.d.ts.map +0 -1
- package/dist/commands/registry.js.map +0 -1
- package/dist/commands/sandbox.d.ts.map +0 -1
- package/dist/commands/sandbox.js.map +0 -1
- package/dist/commands/session-view.d.ts.map +0 -1
- package/dist/commands/session-view.js.map +0 -1
- package/dist/commands/types.d.ts.map +0 -1
- package/dist/commands/types.js.map +0 -1
- package/dist/commands/utils.d.ts +0 -11
- package/dist/commands/utils.d.ts.map +0 -1
- package/dist/commands/utils.js.map +0 -1
- package/dist/events.d.ts.map +0 -1
- package/dist/events.js.map +0 -1
- package/dist/execution-resolver.d.ts +0 -27
- package/dist/execution-resolver.d.ts.map +0 -1
- package/dist/execution-resolver.js.map +0 -1
- package/dist/harness/event-format.d.ts +0 -33
- package/dist/harness/event-format.d.ts.map +0 -1
- package/dist/harness/event-format.js.map +0 -1
- package/dist/harness/session-store.d.ts.map +0 -1
- package/dist/harness/session-store.js.map +0 -1
- package/dist/harness/settings.d.ts +0 -29
- package/dist/harness/settings.d.ts.map +0 -1
- package/dist/harness/settings.js +0 -40
- package/dist/harness/settings.js.map +0 -1
- package/dist/harness/subagent-runner.d.ts.map +0 -1
- package/dist/harness/subagent-runner.js.map +0 -1
- package/dist/harness/subagent-slots.d.ts +0 -28
- package/dist/harness/subagent-slots.d.ts.map +0 -1
- package/dist/harness/subagent-slots.js +0 -72
- package/dist/harness/subagent-slots.js.map +0 -1
- package/dist/harness/usage.d.ts +0 -11
- package/dist/harness/usage.d.ts.map +0 -1
- package/dist/harness/usage.js +0 -38
- package/dist/harness/usage.js.map +0 -1
- package/dist/mcp/catalog.d.ts +0 -5
- package/dist/mcp/catalog.d.ts.map +0 -1
- package/dist/mcp/catalog.js +0 -68
- package/dist/mcp/catalog.js.map +0 -1
- package/dist/mcp/loader.d.ts +0 -12
- package/dist/mcp/loader.d.ts.map +0 -1
- package/dist/mcp/loader.js.map +0 -1
- package/dist/mcp/open-connector.d.ts.map +0 -1
- package/dist/mcp/open-connector.js.map +0 -1
- package/dist/mcp/types.d.ts +0 -66
- package/dist/mcp/types.d.ts.map +0 -1
- package/dist/mcp/types.js.map +0 -1
- package/dist/packages/index.d.ts +0 -169
- package/dist/packages/index.d.ts.map +0 -1
- package/dist/packages/index.js +0 -721
- package/dist/packages/index.js.map +0 -1
- package/dist/packages/types.d.ts +0 -100
- package/dist/packages/types.d.ts.map +0 -1
- package/dist/packages/types.js.map +0 -1
- package/dist/provisioner.d.ts.map +0 -1
- package/dist/provisioner.js.map +0 -1
- package/dist/subagent-progress.d.ts +0 -39
- package/dist/subagent-progress.d.ts.map +0 -1
- package/dist/subagent-progress.js +0 -225
- package/dist/subagent-progress.js.map +0 -1
- package/dist/tools/bash.d.ts +0 -12
- package/dist/tools/bash.d.ts.map +0 -1
- package/dist/tools/bash.js +0 -80
- package/dist/tools/bash.js.map +0 -1
- package/dist/tools/edit.d.ts +0 -11
- package/dist/tools/edit.d.ts.map +0 -1
- package/dist/tools/edit.js +0 -132
- package/dist/tools/edit.js.map +0 -1
- package/dist/tools/event.d.ts.map +0 -1
- package/dist/tools/event.js +0 -255
- package/dist/tools/event.js.map +0 -1
- package/dist/tools/generate-image.d.ts.map +0 -1
- package/dist/tools/generate-image.js.map +0 -1
- package/dist/tools/host-fn-tool.d.ts.map +0 -1
- package/dist/tools/host-fn-tool.js.map +0 -1
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/react.d.ts.map +0 -1
- package/dist/tools/react.js.map +0 -1
- package/dist/tools/read.d.ts +0 -12
- package/dist/tools/read.d.ts.map +0 -1
- package/dist/tools/read.js +0 -140
- package/dist/tools/read.js.map +0 -1
- package/dist/tools/sandbox.d.ts.map +0 -1
- package/dist/tools/sandbox.js.map +0 -1
- package/dist/tools/subagent.d.ts.map +0 -1
- package/dist/tools/subagent.js.map +0 -1
- package/dist/tools/types.d.ts.map +0 -1
- package/dist/tools/types.js.map +0 -1
- package/dist/tools/write.d.ts +0 -10
- package/dist/tools/write.d.ts.map +0 -1
- package/dist/tools/write.js +0 -23
- package/dist/tools/write.js.map +0 -1
- package/dist/trigger.d.ts +0 -23
- package/dist/trigger.d.ts.map +0 -1
- package/dist/trigger.js +0 -97
- package/dist/trigger.js.map +0 -1
- package/dist/utils/file-guards.d.ts.map +0 -1
- package/dist/utils/file-guards.js.map +0 -1
- package/dist/web/admin/portal.d.ts.map +0 -1
- package/dist/web/admin/portal.js.map +0 -1
- package/dist/web/admin/provider-models.d.ts.map +0 -1
- package/dist/web/admin/provider-models.js.map +0 -1
- package/dist/web/admin/types.d.ts.map +0 -1
- package/dist/web/admin/types.js.map +0 -1
- package/dist/web/login/oauth.d.ts.map +0 -1
- package/dist/web/login/oauth.js.map +0 -1
- package/dist/web/login/portal.d.ts.map +0 -1
- package/dist/web/login/portal.js.map +0 -1
- package/dist/web/login/types.d.ts.map +0 -1
- package/dist/web/login/types.js.map +0 -1
- package/dist/web/portal-shell.d.ts.map +0 -1
- package/dist/web/portal-shell.js.map +0 -1
- package/dist/web/server.d.ts.map +0 -1
- package/dist/web/server.js.map +0 -1
- package/dist/web/session-view/portal.d.ts.map +0 -1
- package/dist/web/session-view/portal.js.map +0 -1
- package/dist/web/session-view/types.d.ts.map +0 -1
- package/dist/web/session-view/types.js +0 -2
- package/dist/web/session-view/types.js.map +0 -1
- package/dist/web/token-store.d.ts.map +0 -1
- package/dist/web/token-store.js.map +0 -1
- package/dist/web/types.d.ts.map +0 -1
- package/dist/web/types.js +0 -2
- package/dist/web/types.js.map +0 -1
- package/dist/workspace-projection/index.d.ts.map +0 -1
- package/dist/workspace-projection/index.js.map +0 -1
- package/dist/workspace-projection/types.d.ts +0 -29
- package/dist/workspace-projection/types.d.ts.map +0 -1
- package/dist/workspace-projection/types.js +0 -2
- package/dist/workspace-projection/types.js.map +0 -1
- /package/dist/{commands → adapters/commands}/admin.d.ts +0 -0
- /package/dist/{commands → adapters/commands}/login.d.ts +0 -0
- /package/dist/{commands → adapters/commands}/manifest.d.ts +0 -0
- /package/dist/{commands → adapters/commands}/new.d.ts +0 -0
- /package/dist/{commands → adapters/commands}/registry.d.ts +0 -0
- /package/dist/{commands → adapters/commands}/sandbox.d.ts +0 -0
- /package/dist/{commands → adapters/commands}/session-view.d.ts +0 -0
- /package/dist/{commands → adapters/commands}/types.js +0 -0
- /package/dist/{web → adapters/web}/admin/provider-models.js +0 -0
- /package/dist/{mcp → adapters/web/admin}/types.js +0 -0
- /package/dist/{web → adapters/web}/login/oauth.d.ts +0 -0
- /package/dist/{packages → adapters/web/login}/types.js +0 -0
- /package/dist/{web → adapters/web}/session-view/portal.d.ts +0 -0
- /package/dist/{tools → adapters/web/session-view}/types.js +0 -0
- /package/dist/{web → adapters/web}/token-store.d.ts +0 -0
- /package/dist/{web → adapters/web}/token-store.js +0 -0
- /package/dist/{web → adapters/web}/types.d.ts +0 -0
- /package/dist/{web/admin → adapters/web}/types.js +0 -0
- /package/dist/{utils/file-guards.d.ts → file-guards.d.ts} +0 -0
- /package/dist/{utils/file-guards.js → file-guards.js} +0 -0
- /package/dist/{mcp → harness}/open-connector.d.ts +0 -0
- /package/dist/{adapters/slack → harness}/tools/attach.d.ts +0 -0
- /package/dist/{adapters/slack → harness}/tools/attach.js +0 -0
- /package/dist/{tools → harness/tools}/generate-image.d.ts +0 -0
- /package/dist/{tools → harness/tools}/generate-image.js +0 -0
- /package/dist/{tools → harness/tools}/host-fn-tool.d.ts +0 -0
- /package/dist/{tools → harness/tools}/host-fn-tool.js +0 -0
- /package/dist/{tools → harness/tools}/react.d.ts +0 -0
- /package/dist/{tools → harness/tools}/react.js +0 -0
- /package/dist/{web/login → harness/tools}/types.js +0 -0
package/dist/harness/runner.js
CHANGED
|
@@ -1,491 +1,523 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
1
|
+
import { MikanModels } from "./models.js";
|
|
2
|
+
import { MikanAgentSession, DEFAULT_EVENT_BUDGET } from "./session.js";
|
|
3
|
+
import { runSubagent, DEFAULT_GLOBAL_SUBAGENT_SLOTS, SubagentSlotPool } from "./subagent.js";
|
|
4
|
+
import { loadSubagentProfiles } from "./subagent-profiles.js";
|
|
5
|
+
import { createMikanTools, createSubagentTool } from "./tools/index.js";
|
|
6
|
+
import { adaptAgentTool } from "./tools/pi-tools.js";
|
|
7
|
+
import { createSandboxExecutionEnv } from "./execution-env.js";
|
|
8
|
+
import { mkdir } from "node:fs/promises";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { ActorExecutionResolver } from "./execution-resolver.js";
|
|
11
|
+
import { assertSandboxSupportsWorkspacePolicy, createExecutor, getUnresolvedSandboxPathContext, } from "../sandbox/index.js";
|
|
12
|
+
import { resolveWorkspaceProjection } from "../office/projection.js";
|
|
13
|
+
import { createHash } from "node:crypto";
|
|
14
|
+
import { resolveConversationSettings } from "../config.js";
|
|
15
|
+
import { provisionOfficeOpenConnectorToken } from "./open-connector.js";
|
|
16
|
+
import { addLifecycleEvent, updateActiveSpanAttribution } from "../observability/index.js";
|
|
17
|
+
import { ChatHistorySync } from "../sessions/chat-history-sync.js";
|
|
18
|
+
import { conversationIdOf, isThreadSessionKey } from "../sessions/session-key.js";
|
|
19
|
+
import { extractSessionUuid, openManagedSession, } from "../sessions/store.js";
|
|
20
|
+
import { loadMikanSkills } from "./skills.js";
|
|
21
|
+
import { normalizeAttachRuntimePath, withStagedRuntimeFile, buildPromptPayload, buildSystemPrompt, buildTurnInstructions, getMemory, resolveTriggerAttribution, } from "./prompt.js";
|
|
22
|
+
import { attachSessionEventHandlers, activateRunPresentation, createRunState, finalizeRunResponse, isEventTriggerAttribution, reportUsageSummary, } from "./presenter.js";
|
|
18
23
|
import * as log from "../log.js";
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
24
|
+
// One process-wide fan-out account: per-conversation queues serialize runs,
|
|
25
|
+
// but each run can fan out up to the per-run cap — without this shared
|
|
26
|
+
// ceiling, N busy conversations hold N × cap live subagent sessions.
|
|
27
|
+
const globalSubagentSlots = new SubagentSlotPool(DEFAULT_GLOBAL_SUBAGENT_SLOTS);
|
|
28
|
+
async function createConfiguredAgentSession(params) {
|
|
29
|
+
const { workspaceDir, systemPrompt, model, thinkingLevel, tools, toolContext, sessionStore, models, } = params;
|
|
30
|
+
const loadedProfiles = loadSubagentProfiles(workspaceDir);
|
|
31
|
+
for (const diagnostic of loadedProfiles.diagnostics) {
|
|
32
|
+
log.logWarning(`Subagent profile ignored: ${diagnostic.path}`, diagnostic.message);
|
|
33
|
+
}
|
|
34
|
+
const availableToolNames = new Set(tools.map((tool) => tool.name));
|
|
35
|
+
const runnableProfiles = new Map([...loadedProfiles.profiles].filter(([, profile]) => profile.tools.every((tool) => availableToolNames.has(tool))));
|
|
36
|
+
let session;
|
|
37
|
+
const subagentTool = createSubagentTool((request, hooks) => runSubagent({
|
|
38
|
+
request,
|
|
39
|
+
...(hooks?.onActivity ? { onActivity: hooks.onActivity } : {}),
|
|
40
|
+
defaultModel: model,
|
|
41
|
+
thinkingLevel,
|
|
42
|
+
models,
|
|
43
|
+
workspaceDir,
|
|
44
|
+
availableTools: tools,
|
|
45
|
+
profiles: runnableProfiles,
|
|
46
|
+
slots: globalSubagentSlots,
|
|
47
|
+
toolContext,
|
|
48
|
+
parentMessages: [...session.messages],
|
|
49
|
+
onUsage: session.captureExternalUsageSink(),
|
|
50
|
+
}), runnableProfiles);
|
|
51
|
+
session = new MikanAgentSession({
|
|
52
|
+
systemPrompt,
|
|
53
|
+
model,
|
|
54
|
+
thinkingLevel,
|
|
55
|
+
tools: [...tools, adaptAgentTool(subagentTool)],
|
|
56
|
+
toolContext,
|
|
57
|
+
models,
|
|
58
|
+
sessionStore,
|
|
36
59
|
});
|
|
60
|
+
const reloaded = await session.reloadFromSession();
|
|
61
|
+
if (reloaded > 0)
|
|
62
|
+
log.logInfo(`Reloaded ${reloaded} messages from session context`);
|
|
63
|
+
return session;
|
|
37
64
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
/** Resource totals and terminal budget state from the most recent prompt. */
|
|
81
|
-
getLastRunStats() {
|
|
82
|
-
return {
|
|
83
|
-
usage: copyUsage(this.tally.usage),
|
|
84
|
-
tokens: this.tally.usage.totalTokens,
|
|
85
|
-
costUsd: this.tally.usage.cost.total,
|
|
86
|
-
llmCalls: this.tally.llmCalls,
|
|
87
|
-
toolCalls: this.tally.toolCalls,
|
|
88
|
-
toolCallCounts: { ...this.tally.toolCallCounts },
|
|
89
|
-
durationMs: this.tally.startedAt > 0 ? Date.now() - this.tally.startedAt : 0,
|
|
90
|
-
...(this.budgetExceededReason ? { budgetExceededReason: this.budgetExceededReason } : {}),
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Fold spend incurred outside this session's own LLM calls — e.g. subagent
|
|
95
|
-
* runs launched by a tool during the current prompt — into the run tally
|
|
96
|
-
* and enforce the run budget at the fold itself: a fold that lands over a
|
|
97
|
-
* resource ceiling aborts the run now instead of waiting for a next
|
|
98
|
-
* assistant message that may never come (and would be paid for). Complete
|
|
99
|
-
* usage is folded; external runs are not this session's turns.
|
|
100
|
-
*/
|
|
101
|
-
/** Capture a usage sink bound to the tally owned by the current prompt run. */
|
|
102
|
-
captureExternalUsageSink() {
|
|
103
|
-
const tally = this.tally;
|
|
104
|
-
return async (usage) => {
|
|
105
|
-
addUsage(tally.usage, usage);
|
|
106
|
-
if (this.tally !== tally || this.budgetExceededReason || !this.runActive)
|
|
107
|
-
return;
|
|
108
|
-
const reason = this.resourceOverBudgetReason();
|
|
109
|
-
if (reason)
|
|
110
|
-
await this.exceedBudget(reason);
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
async foldExternalUsage(usage) {
|
|
114
|
-
await this.captureExternalUsageSink()(usage);
|
|
115
|
-
}
|
|
116
|
-
subscribe(listener) {
|
|
117
|
-
this.listeners.add(listener);
|
|
118
|
-
return () => this.listeners.delete(listener);
|
|
119
|
-
}
|
|
120
|
-
/** Replace the agent transcript from the persisted session tree. */
|
|
121
|
-
async reloadFromSession() {
|
|
122
|
-
const context = await this.sessionStore.buildSessionContext();
|
|
123
|
-
if (context.messages.length > 0) {
|
|
124
|
-
this.agent.state.messages = context.messages;
|
|
125
|
-
}
|
|
126
|
-
return context.messages.length;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Send a user prompt and run the agent loop to completion, including
|
|
130
|
-
* automatic retries and compaction.
|
|
131
|
-
*
|
|
132
|
-
* @param options.budget Per-run resource ceilings that override the session
|
|
133
|
-
* defaults. Autonomous event runs should pass a budget so a runaway loop
|
|
134
|
-
* is stopped even with no human watching.
|
|
135
|
-
*/
|
|
136
|
-
async prompt(text, options) {
|
|
137
|
-
if (this.runActive)
|
|
138
|
-
throw new Error("Agent is already processing a prompt");
|
|
139
|
-
this.runActive = true;
|
|
140
|
-
const runSystemPrompt = this.agent.state.systemPrompt;
|
|
141
|
-
const runTools = this.agent.state.tools;
|
|
142
|
-
if (options?.tools)
|
|
143
|
-
this.agent.state.tools = options.tools;
|
|
144
|
-
try {
|
|
145
|
-
await this.runPrompt(text, options);
|
|
146
|
-
}
|
|
147
|
-
finally {
|
|
148
|
-
this.agent.state.systemPrompt = runSystemPrompt;
|
|
149
|
-
this.agent.state.tools = runTools;
|
|
150
|
-
this.runActive = false;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
async runPrompt(text, options) {
|
|
154
|
-
this.retryAttempt = 0;
|
|
155
|
-
this.overflowRecoveryAttempted = false;
|
|
156
|
-
this.runBudget = { ...this.settings.budget, ...options?.budget };
|
|
157
|
-
this.budgetExceededReason = undefined;
|
|
158
|
-
this.tally = {
|
|
159
|
-
usage: createEmptyUsage(),
|
|
160
|
-
llmCalls: 0,
|
|
161
|
-
toolCalls: 0,
|
|
162
|
-
toolCallCounts: {},
|
|
163
|
-
startedAt: Date.now(),
|
|
164
|
-
};
|
|
165
|
-
await this.ensureAuthConfigured(this.agent.state.model);
|
|
166
|
-
// A previous turn may have ended over the threshold (for example after an
|
|
167
|
-
// abort); compact before adding new context on top.
|
|
168
|
-
const lastAssistant = this.findLastAssistantMessage();
|
|
169
|
-
if (lastAssistant && lastAssistant.stopReason !== "error") {
|
|
170
|
-
await this.checkThresholdCompaction(lastAssistant);
|
|
171
|
-
}
|
|
172
|
-
const userMessage = {
|
|
173
|
-
role: "user",
|
|
174
|
-
content: [{ type: "text", text }, ...(options?.images ?? [])],
|
|
175
|
-
timestamp: Date.now(),
|
|
176
|
-
};
|
|
177
|
-
await this.agent.prompt([userMessage]);
|
|
178
|
-
while (await this.handlePostRun())
|
|
179
|
-
await this.agent.continue();
|
|
180
|
-
}
|
|
181
|
-
/** Abort the active run, pending retry backoff, and in-flight compaction. */
|
|
182
|
-
abort() {
|
|
183
|
-
this.retryAbortController?.abort();
|
|
184
|
-
this.compactionAbortController?.abort();
|
|
185
|
-
this.agent.abort();
|
|
186
|
-
}
|
|
187
|
-
async ensureAuthConfigured(model) {
|
|
188
|
-
const auth = await this.models.getAuth(model);
|
|
189
|
-
if (!auth) {
|
|
190
|
-
throw new Error(`No credentials for provider "${model.provider}". Set the provider API key environment variable.`);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
async emit(event) {
|
|
194
|
-
for (const listener of this.listeners) {
|
|
195
|
-
try {
|
|
196
|
-
await listener(event);
|
|
197
|
-
}
|
|
198
|
-
catch (err) {
|
|
199
|
-
log.logWarning("Harness event listener failed", err instanceof Error ? err.message : String(err));
|
|
65
|
+
function createRunnerExecutionContext(sandboxConfig, vaultManager, provisioner, workspace) {
|
|
66
|
+
const executionResolver = vaultManager && sandboxConfig.type !== "host"
|
|
67
|
+
? new ActorExecutionResolver(sandboxConfig, vaultManager, provisioner, workspace)
|
|
68
|
+
: undefined;
|
|
69
|
+
// activeExecutor is replaced at the start of each run() call when executionResolver
|
|
70
|
+
// is present, so the stable `executor` wrapper always delegates to the latest resolved value.
|
|
71
|
+
let activeExecutor = executionResolver !== undefined
|
|
72
|
+
? createExecutor({ type: "host" })
|
|
73
|
+
: createExecutor(sandboxConfig);
|
|
74
|
+
const executor = {
|
|
75
|
+
exec(command, options) {
|
|
76
|
+
return activeExecutor.exec(command, options);
|
|
77
|
+
},
|
|
78
|
+
readFile(path, options) {
|
|
79
|
+
return activeExecutor.readFile(path, options);
|
|
80
|
+
},
|
|
81
|
+
readFileBase64(path, options) {
|
|
82
|
+
return activeExecutor.readFileBase64(path, options);
|
|
83
|
+
},
|
|
84
|
+
writeFile(path, content, options) {
|
|
85
|
+
return activeExecutor.writeFile(path, content, options);
|
|
86
|
+
},
|
|
87
|
+
getWorkspacePath(hostPath) {
|
|
88
|
+
return activeExecutor.getWorkspacePath(hostPath);
|
|
89
|
+
},
|
|
90
|
+
getSandboxConfig() {
|
|
91
|
+
return activeExecutor.getSandboxConfig();
|
|
92
|
+
},
|
|
93
|
+
getPathContext(hostWorkspaceRoot) {
|
|
94
|
+
return activeExecutor.getPathContext(hostWorkspaceRoot);
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
executor,
|
|
99
|
+
async resolveForRun(context) {
|
|
100
|
+
if (executionResolver) {
|
|
101
|
+
const decision = await executionResolver.resolve(context);
|
|
102
|
+
activeExecutor = decision.executor;
|
|
103
|
+
return {
|
|
104
|
+
pathContext: decision.pathContext,
|
|
105
|
+
projection: decision.projection,
|
|
106
|
+
};
|
|
200
107
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
108
|
+
const office = workspace.office(context.address);
|
|
109
|
+
const projection = resolveWorkspaceProjection(office);
|
|
110
|
+
assertSandboxSupportsWorkspacePolicy(sandboxConfig, projection.doorPolicy, projection.promptSources.globalMemoryReadOnly === true);
|
|
111
|
+
return {
|
|
112
|
+
pathContext: executor.getPathContext(workspace.root),
|
|
113
|
+
projection,
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function buildThreadSessionName(message) {
|
|
119
|
+
const text = message?.text?.trim();
|
|
120
|
+
if (!text)
|
|
121
|
+
return undefined;
|
|
122
|
+
const userLabel = message?.userName || message?.user || "unknown";
|
|
123
|
+
return `[${userLabel}]: ${text}`;
|
|
124
|
+
}
|
|
125
|
+
async function resolveRunnerMcpServers(options) {
|
|
126
|
+
if (options.trustModel === "open-trigger")
|
|
127
|
+
return {};
|
|
128
|
+
return provisionOfficeOpenConnectorToken(options.office, options.platformWorkspaceId, options.servers, options.openConnector, options.signal);
|
|
129
|
+
}
|
|
130
|
+
async function preparePromptContext(params) {
|
|
131
|
+
const { message, platform, office, executor, resolveForRun, session } = params;
|
|
132
|
+
const conversationId = office.address.conversationId;
|
|
133
|
+
const decision = await resolveForRun({
|
|
134
|
+
address: message.address,
|
|
135
|
+
userId: message.userId,
|
|
136
|
+
trustModel: platform.trustModel,
|
|
137
|
+
});
|
|
138
|
+
const { pathContext, projection } = decision;
|
|
139
|
+
const reloaded = await session.reloadFromSession();
|
|
140
|
+
if (reloaded > 0) {
|
|
141
|
+
log.logInfo(`[${conversationId}] Reloaded ${reloaded} messages from context`);
|
|
233
142
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
143
|
+
const memory = await getMemory(projection);
|
|
144
|
+
const conversationSkillLoad = loadMikanSkills(office, pathContext.runtimeWorkspaceRoot, projection);
|
|
145
|
+
const triggerAttribution = resolveTriggerAttribution(message);
|
|
146
|
+
const systemPrompt = buildSystemPrompt({
|
|
147
|
+
workspacePath: pathContext.runtimeWorkspaceRoot,
|
|
148
|
+
office,
|
|
149
|
+
memory,
|
|
150
|
+
sandboxConfig: executor.getSandboxConfig(),
|
|
151
|
+
platform,
|
|
152
|
+
skills: conversationSkillLoad.skills,
|
|
153
|
+
projection,
|
|
154
|
+
skippedSkillLinks: conversationSkillLoad.skippedSkillLinks,
|
|
155
|
+
});
|
|
156
|
+
session.setSystemPrompt(systemPrompt);
|
|
157
|
+
// A stable hash across turns verifies that turn-specific data did not leak
|
|
158
|
+
// into the provider-cacheable system prompt.
|
|
159
|
+
const promptHash = createHash("sha256").update(systemPrompt).digest("hex").slice(0, 8);
|
|
160
|
+
log.logInfo(`[${conversationId}] System prompt (base): ${systemPrompt.length} chars, sha ${promptHash}`);
|
|
161
|
+
return { pathContext, memory, systemPrompt, triggerAttribution };
|
|
162
|
+
}
|
|
163
|
+
function bindRunCapabilities(params, pathContext) {
|
|
164
|
+
const { message, responder, platform, office, executor, setEventContext, setSandboxContext, setUploadFunction, setImageUploadFunction, setReactFunction, bindPlatformToolPacks, } = params;
|
|
165
|
+
setEventContext({
|
|
166
|
+
platform: platform.name,
|
|
167
|
+
conversationId: office.address.conversationId,
|
|
168
|
+
conversationKind: message.conversationKind,
|
|
169
|
+
userId: message.userId,
|
|
170
|
+
});
|
|
171
|
+
setSandboxContext({ address: message.address, userId: message.userId });
|
|
172
|
+
setUploadFunction(async (filePath, title) => {
|
|
173
|
+
const runtimePath = normalizeAttachRuntimePath(filePath, pathContext.runtimeWorkspaceRoot);
|
|
174
|
+
await withStagedRuntimeFile(executor, runtimePath, (stagedPath) => responder.uploadFile(stagedPath, title));
|
|
175
|
+
});
|
|
176
|
+
// Generated images already live host-side and must not be staged through a sandbox.
|
|
177
|
+
setImageUploadFunction(async (hostPath, title) => {
|
|
178
|
+
await responder.uploadFile(hostPath, title);
|
|
179
|
+
});
|
|
180
|
+
// Unset reaction support when the active responder cannot react.
|
|
181
|
+
setReactFunction(responder.react ? async (emoji) => responder.react(emoji) : null);
|
|
182
|
+
bindPlatformToolPacks({
|
|
183
|
+
conversationId: office.address.conversationId,
|
|
184
|
+
platformName: platform.name,
|
|
185
|
+
threadTs: message.threadTs,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
async function prepareRunContext(params) {
|
|
189
|
+
const { message, platform, office, executor } = params;
|
|
190
|
+
const sessionConversation = conversationIdOf(message.sessionKey);
|
|
191
|
+
await mkdir(join(office.dir, "scratch"), { recursive: true });
|
|
192
|
+
const { pathContext, memory, systemPrompt, triggerAttribution } = await preparePromptContext(params);
|
|
193
|
+
bindRunCapabilities(params, pathContext);
|
|
194
|
+
log.logInfo(`Context sizes - system: ${systemPrompt.length} chars, memory: ${memory.length} chars`);
|
|
195
|
+
log.logInfo(`Channels: ${platform.channels.length}, Users: ${platform.users.length}`);
|
|
196
|
+
const { userMessage, imageAttachments } = await buildPromptPayload(message, pathContext.runtimeWorkspaceRoot, pathContext, (runtimePath) => executor.readFileBase64(runtimePath));
|
|
197
|
+
const turnInstructions = buildTurnInstructions(message.id.startsWith("event:"), triggerAttribution, platform.name);
|
|
198
|
+
const finalUserMessage = turnInstructions ? `${turnInstructions}\n\n${userMessage}` : userMessage;
|
|
199
|
+
return {
|
|
200
|
+
sessionConversation,
|
|
201
|
+
userMessage: finalUserMessage,
|
|
202
|
+
imageAttachments,
|
|
203
|
+
triggerAttribution,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
async function buildInitialSystemPrompt(params) {
|
|
207
|
+
const { office, pathContext, projection, sandboxConfig } = params;
|
|
208
|
+
const memory = await getMemory(projection);
|
|
209
|
+
const { skills, skippedSkillLinks } = loadMikanSkills(office, pathContext.runtimeWorkspaceRoot, projection);
|
|
210
|
+
return buildSystemPrompt({
|
|
211
|
+
workspacePath: pathContext.runtimeWorkspaceRoot,
|
|
212
|
+
office,
|
|
213
|
+
memory,
|
|
214
|
+
sandboxConfig,
|
|
215
|
+
platform: {
|
|
216
|
+
name: "chat",
|
|
217
|
+
formattingGuide: "",
|
|
218
|
+
channels: [],
|
|
219
|
+
users: [],
|
|
220
|
+
trustModel: "membership",
|
|
221
|
+
},
|
|
222
|
+
skills,
|
|
223
|
+
projection,
|
|
224
|
+
skippedSkillLinks,
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
async function rollbackRunnerResource(label, cleanup) {
|
|
228
|
+
try {
|
|
229
|
+
await cleanup();
|
|
241
230
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
if (this.budgetExceededReason)
|
|
245
|
-
return;
|
|
246
|
-
const reason = this.overBudgetReason(message);
|
|
247
|
-
if (!reason)
|
|
248
|
-
return;
|
|
249
|
-
await this.exceedBudget(reason);
|
|
231
|
+
catch (error) {
|
|
232
|
+
log.logWarning(`Runner rollback failed to ${label}`, String(error));
|
|
250
233
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
llmCalls: this.tally.llmCalls,
|
|
262
|
-
durationMs: Date.now() - this.tally.startedAt,
|
|
263
|
-
});
|
|
264
|
-
log.logWarning("Run budget exceeded — aborting", reason);
|
|
265
|
-
this.agent.abort();
|
|
266
|
-
}
|
|
267
|
-
overBudgetReason(message) {
|
|
268
|
-
const { maxLlmCalls } = this.runBudget;
|
|
269
|
-
const needsAnotherCall = message.stopReason === "error" || message.content.some((part) => part.type === "toolCall");
|
|
270
|
-
if (needsAnotherCall && maxLlmCalls !== undefined && this.tally.llmCalls >= maxLlmCalls) {
|
|
271
|
-
return `${this.tally.llmCalls} LLM calls >= ${maxLlmCalls} limit`;
|
|
234
|
+
}
|
|
235
|
+
async function openRunnerSessionManager(params) {
|
|
236
|
+
const { contextFile, runtimeWorkspaceRoot, sessionKey, threadRootMessage } = params;
|
|
237
|
+
const sessionManager = await openManagedSession(contextFile, runtimeWorkspaceRoot);
|
|
238
|
+
try {
|
|
239
|
+
const threadSessionName = buildThreadSessionName(threadRootMessage);
|
|
240
|
+
if (isThreadSessionKey(sessionKey) &&
|
|
241
|
+
threadSessionName &&
|
|
242
|
+
(await sessionManager.getSessionName()) !== threadSessionName) {
|
|
243
|
+
await sessionManager.setSessionName(threadSessionName);
|
|
272
244
|
}
|
|
273
|
-
return
|
|
245
|
+
return sessionManager;
|
|
274
246
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
if (maxTokens !== undefined && this.tally.usage.totalTokens >= maxTokens) {
|
|
279
|
-
return `${this.tally.usage.totalTokens} tokens >= ${maxTokens} limit`;
|
|
280
|
-
}
|
|
281
|
-
if (maxCostUsd !== undefined && this.tally.usage.cost.total >= maxCostUsd) {
|
|
282
|
-
return `cost ${this.tally.usage.cost.total.toFixed(2)} USD >= ${maxCostUsd} USD limit`;
|
|
283
|
-
}
|
|
284
|
-
if (maxDurationMs !== undefined && Date.now() - this.tally.startedAt >= maxDurationMs) {
|
|
285
|
-
return `${Date.now() - this.tally.startedAt}ms >= ${maxDurationMs}ms limit`;
|
|
286
|
-
}
|
|
287
|
-
return undefined;
|
|
247
|
+
catch (error) {
|
|
248
|
+
await rollbackRunnerResource("close the session writer", () => sessionManager.close());
|
|
249
|
+
throw error;
|
|
288
250
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
251
|
+
}
|
|
252
|
+
async function createRunnerAgentSession(params) {
|
|
253
|
+
const { workspaceDir, systemPrompt, model, agentConfig, tools, toolContext, sessionManager, modelRegistry, signal, } = params;
|
|
254
|
+
const mcpTools = await sessionManager.connectMcp(agentConfig.mcpServers ?? {}, signal);
|
|
255
|
+
return createConfiguredAgentSession({
|
|
256
|
+
workspaceDir,
|
|
257
|
+
systemPrompt,
|
|
258
|
+
model,
|
|
259
|
+
thinkingLevel: agentConfig.thinkingLevel,
|
|
260
|
+
tools: [...tools, ...mcpTools.map(adaptAgentTool)],
|
|
261
|
+
toolContext,
|
|
262
|
+
sessionStore: sessionManager,
|
|
263
|
+
models: modelRegistry,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
async function runPreparedTurn(params) {
|
|
267
|
+
const { prepared, presentation, message, responder, platform, runState, session, model, agentConfig, sessionUuid, conversationId, contextFile, sessionView, } = params;
|
|
268
|
+
if (runState.logCtx) {
|
|
269
|
+
log.logAgentRunStart(runState.logCtx, model.provider, model.id, model.name);
|
|
297
270
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
271
|
+
updateActiveSpanAttribution({
|
|
272
|
+
provider: model.provider,
|
|
273
|
+
model: agentConfig.model,
|
|
274
|
+
channel_id: prepared.sessionConversation,
|
|
275
|
+
session_id: sessionUuid,
|
|
276
|
+
});
|
|
277
|
+
addLifecycleEvent("agent.prompt.sent", {
|
|
278
|
+
provider: model.provider,
|
|
279
|
+
model: agentConfig.model,
|
|
280
|
+
channel_id: prepared.sessionConversation,
|
|
281
|
+
session_id: sessionUuid,
|
|
282
|
+
attachment_count: message.attachments?.length ?? 0,
|
|
283
|
+
image_attachment_count: prepared.imageAttachments.length,
|
|
284
|
+
});
|
|
285
|
+
const isEventRun = message.id.startsWith("event:");
|
|
286
|
+
await session.prompt(prepared.userMessage, {
|
|
287
|
+
...(prepared.imageAttachments.length > 0 ? { images: prepared.imageAttachments } : {}),
|
|
288
|
+
...(isEventRun ? { budget: DEFAULT_EVENT_BUDGET } : {}),
|
|
289
|
+
});
|
|
290
|
+
await presentation.wait();
|
|
291
|
+
const sessionViewTokenStore = sessionView?.tokenStore;
|
|
292
|
+
const sessionViewPortalBaseUrl = sessionView?.portalBaseUrl;
|
|
293
|
+
let sessionViewLink;
|
|
294
|
+
const createSessionViewLink = sessionViewTokenStore && sessionViewPortalBaseUrl
|
|
295
|
+
? () => {
|
|
296
|
+
if (!sessionViewLink) {
|
|
297
|
+
const token = sessionViewTokenStore.create({
|
|
298
|
+
platform: platform.name,
|
|
299
|
+
platformUserId: message.userId,
|
|
300
|
+
conversationId,
|
|
301
|
+
sessionKey: message.sessionKey,
|
|
302
|
+
sessionFile: contextFile,
|
|
303
|
+
platformUserName: message.userName,
|
|
304
|
+
});
|
|
305
|
+
sessionViewLink = `${sessionViewPortalBaseUrl}/session?token=${token.token}`;
|
|
314
306
|
}
|
|
315
|
-
return
|
|
307
|
+
return sessionViewLink;
|
|
316
308
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
309
|
+
: undefined;
|
|
310
|
+
await finalizeRunResponse(responder, session, runState, {
|
|
311
|
+
triggerSessionLink: isEventTriggerAttribution(prepared.triggerAttribution)
|
|
312
|
+
? createSessionViewLink?.()
|
|
313
|
+
: undefined,
|
|
314
|
+
createOverflowLink: createSessionViewLink,
|
|
315
|
+
platform: platform.name,
|
|
316
|
+
model,
|
|
317
|
+
sessionConversation: prepared.sessionConversation,
|
|
318
|
+
sessionUuid,
|
|
319
|
+
});
|
|
320
|
+
await reportUsageSummary({
|
|
321
|
+
session,
|
|
322
|
+
runState,
|
|
323
|
+
responder,
|
|
324
|
+
platform,
|
|
325
|
+
model,
|
|
326
|
+
agentConfig,
|
|
327
|
+
sessionConversation: prepared.sessionConversation,
|
|
328
|
+
sessionUuid,
|
|
329
|
+
waitForQueue: presentation.wait,
|
|
330
|
+
});
|
|
331
|
+
return { stopReason: runState.stopReason, errorMessage: runState.errorMessage };
|
|
332
|
+
}
|
|
333
|
+
function createRunnerInterface(params) {
|
|
334
|
+
const { conversationId, conversationDir, sessionKey, office, sessionUuid, contextFile, sessionView, runState, executor, resolveForRun, session, model, agentConfig, sessionManager, chatSessionManager, toolBindings, } = params;
|
|
335
|
+
return {
|
|
336
|
+
async syncChatHistory(currentMessageId) {
|
|
337
|
+
await chatSessionManager.syncSessionManager({
|
|
338
|
+
conversationDir,
|
|
339
|
+
sessionKey,
|
|
340
|
+
sessionManager,
|
|
341
|
+
currentMessageId,
|
|
326
342
|
});
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
if (estimate.lastUsageIndex === null)
|
|
344
|
-
return false;
|
|
345
|
-
contextTokens = estimate.tokens;
|
|
346
|
-
}
|
|
347
|
-
if (!shouldCompact(contextTokens, contextWindow, settings))
|
|
348
|
-
return false;
|
|
349
|
-
return this.runCompaction("threshold", false);
|
|
350
|
-
}
|
|
351
|
-
async runCompaction(reason, willRetry) {
|
|
352
|
-
let started = false;
|
|
353
|
-
try {
|
|
354
|
-
const pathEntries = await this.sessionStore.getBranch();
|
|
355
|
-
const preparation = getOrThrow(prepareCompaction(pathEntries, this.settings.compaction));
|
|
356
|
-
if (!preparation)
|
|
357
|
-
return false;
|
|
358
|
-
await this.emit({ type: "compaction_start", reason });
|
|
359
|
-
started = true;
|
|
360
|
-
this.compactionAbortController = new AbortController();
|
|
361
|
-
const signal = this.compactionAbortController.signal;
|
|
362
|
-
const result = getOrThrow(await compact(preparation, this.createCompactionModels(), this.agent.state.model, undefined, this.agent.state.thinkingLevel, undefined, undefined, withAbortSignal(signal, TODO_CONTEXT)));
|
|
363
|
-
if (signal.aborted) {
|
|
364
|
-
await this.emit({ type: "compaction_end", reason, aborted: true });
|
|
365
|
-
return false;
|
|
366
|
-
}
|
|
367
|
-
await this.sessionStore.appendCompaction(result.summary, result.retainedTail, result.tokensBefore, result.details);
|
|
368
|
-
const context = await this.sessionStore.buildSessionContext();
|
|
369
|
-
this.agent.state.messages = context.messages;
|
|
370
|
-
await this.emit({
|
|
371
|
-
type: "compaction_end",
|
|
372
|
-
reason,
|
|
373
|
-
result: {
|
|
374
|
-
summary: result.summary,
|
|
375
|
-
retainedMessages: result.retainedTail.length,
|
|
376
|
-
tokensBefore: result.tokensBefore,
|
|
377
|
-
},
|
|
378
|
-
aborted: false,
|
|
343
|
+
},
|
|
344
|
+
async run(message, responder, platform) {
|
|
345
|
+
const prepared = await prepareRunContext({
|
|
346
|
+
message,
|
|
347
|
+
responder,
|
|
348
|
+
platform,
|
|
349
|
+
office,
|
|
350
|
+
executor,
|
|
351
|
+
resolveForRun,
|
|
352
|
+
session,
|
|
353
|
+
setEventContext: toolBindings.setEventContext,
|
|
354
|
+
setSandboxContext: toolBindings.setSandboxContext,
|
|
355
|
+
setUploadFunction: toolBindings.setUploadFunction,
|
|
356
|
+
setImageUploadFunction: toolBindings.setImageUploadFunction,
|
|
357
|
+
setReactFunction: toolBindings.setReactFunction,
|
|
358
|
+
bindPlatformToolPacks: toolBindings.bindPlatformToolPacks,
|
|
379
359
|
});
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
360
|
+
const presentation = activateRunPresentation(runState, {
|
|
361
|
+
responder,
|
|
362
|
+
sessionConversation: prepared.sessionConversation,
|
|
363
|
+
userName: message.userName,
|
|
364
|
+
sessionUuid,
|
|
365
|
+
triggerAttribution: prepared.triggerAttribution,
|
|
366
|
+
});
|
|
367
|
+
try {
|
|
368
|
+
return await runPreparedTurn({
|
|
369
|
+
prepared,
|
|
370
|
+
presentation,
|
|
371
|
+
message,
|
|
372
|
+
responder,
|
|
373
|
+
platform,
|
|
374
|
+
runState,
|
|
375
|
+
session,
|
|
376
|
+
model,
|
|
377
|
+
agentConfig,
|
|
378
|
+
sessionUuid,
|
|
379
|
+
conversationId,
|
|
380
|
+
contextFile,
|
|
381
|
+
sessionView,
|
|
398
382
|
});
|
|
399
383
|
}
|
|
400
|
-
|
|
401
|
-
|
|
384
|
+
finally {
|
|
385
|
+
presentation.dispose();
|
|
402
386
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
387
|
+
},
|
|
388
|
+
abort() {
|
|
389
|
+
session.abort();
|
|
390
|
+
},
|
|
391
|
+
async dispose() {
|
|
392
|
+
await sessionManager.close();
|
|
393
|
+
},
|
|
394
|
+
getCurrentStep() {
|
|
395
|
+
const first = runState.pendingTools.values().next().value;
|
|
396
|
+
if (!first)
|
|
397
|
+
return undefined;
|
|
398
|
+
return {
|
|
399
|
+
toolName: first.toolName,
|
|
400
|
+
label: first.args?.label,
|
|
401
|
+
};
|
|
402
|
+
},
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
async function finishRunnerCreation(params) {
|
|
406
|
+
const { options, conversationId, conversationDir, workspaceDir, executor, resolveForRun, model, modelRegistry, agentConfig, systemPrompt, sessionManager, toolBindings, toolContext, } = params;
|
|
407
|
+
const { sessionKey, office, sessionScope, sessionView } = options;
|
|
408
|
+
const { contextFile } = sessionScope;
|
|
409
|
+
try {
|
|
410
|
+
const sessionUuid = extractSessionUuid(contextFile);
|
|
411
|
+
const chatSessionManager = new ChatHistorySync();
|
|
412
|
+
const session = await createRunnerAgentSession({
|
|
413
|
+
workspaceDir,
|
|
414
|
+
systemPrompt,
|
|
415
|
+
model,
|
|
416
|
+
agentConfig,
|
|
417
|
+
tools: toolBindings.tools,
|
|
418
|
+
toolContext,
|
|
419
|
+
sessionManager,
|
|
420
|
+
modelRegistry,
|
|
421
|
+
conversationId,
|
|
422
|
+
signal: options.signal,
|
|
437
423
|
});
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
attempt: this.retryAttempt,
|
|
459
|
-
maxAttempts: settings.maxRetries,
|
|
460
|
-
delayMs,
|
|
461
|
-
errorMessage: message.errorMessage || "Unknown error",
|
|
424
|
+
options.signal?.throwIfAborted();
|
|
425
|
+
const runState = createRunState();
|
|
426
|
+
attachSessionEventHandlers({ session, runState, model, agentConfig });
|
|
427
|
+
return createRunnerInterface({
|
|
428
|
+
conversationId,
|
|
429
|
+
conversationDir,
|
|
430
|
+
sessionKey,
|
|
431
|
+
office,
|
|
432
|
+
sessionUuid,
|
|
433
|
+
contextFile,
|
|
434
|
+
sessionView,
|
|
435
|
+
runState,
|
|
436
|
+
executor,
|
|
437
|
+
resolveForRun,
|
|
438
|
+
session,
|
|
439
|
+
model,
|
|
440
|
+
agentConfig,
|
|
441
|
+
sessionManager,
|
|
442
|
+
chatSessionManager,
|
|
443
|
+
toolBindings,
|
|
462
444
|
});
|
|
463
|
-
this.dropTrailingErrorMessage();
|
|
464
|
-
this.retryAbortController = new AbortController();
|
|
465
|
-
try {
|
|
466
|
-
await sleep(delayMs, this.retryAbortController.signal);
|
|
467
|
-
}
|
|
468
|
-
catch {
|
|
469
|
-
const attempt = this.retryAttempt;
|
|
470
|
-
this.retryAttempt = 0;
|
|
471
|
-
await this.emit({
|
|
472
|
-
type: "auto_retry_end",
|
|
473
|
-
success: false,
|
|
474
|
-
attempt,
|
|
475
|
-
finalError: "Retry cancelled",
|
|
476
|
-
});
|
|
477
|
-
return false;
|
|
478
|
-
}
|
|
479
|
-
finally {
|
|
480
|
-
this.retryAbortController = undefined;
|
|
481
|
-
}
|
|
482
|
-
return true;
|
|
483
445
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
this.agent.state.messages = messages.slice(0, -1);
|
|
488
|
-
}
|
|
446
|
+
catch (error) {
|
|
447
|
+
await rollbackRunnerResource("close the session writer", () => sessionManager.close());
|
|
448
|
+
throw error;
|
|
489
449
|
}
|
|
490
450
|
}
|
|
451
|
+
export async function createRunner(options) {
|
|
452
|
+
options.signal?.throwIfAborted();
|
|
453
|
+
const { sandboxConfig, sessionKey, office, trustModel, sessionScope, vaultManager, provisioner, resourceController, platformToolPackFactories, } = options;
|
|
454
|
+
const conversationId = office.address.conversationId;
|
|
455
|
+
const conversationDir = office.dir;
|
|
456
|
+
const workspaceDir = office.workspace.root;
|
|
457
|
+
const resolvedAgentConfig = resolveConversationSettings(office);
|
|
458
|
+
const mcpServers = await resolveRunnerMcpServers({
|
|
459
|
+
office,
|
|
460
|
+
trustModel,
|
|
461
|
+
platformWorkspaceId: options.platformWorkspaceId,
|
|
462
|
+
servers: resolvedAgentConfig.mcpServers,
|
|
463
|
+
openConnector: options.openConnector,
|
|
464
|
+
signal: options.signal,
|
|
465
|
+
});
|
|
466
|
+
options.signal?.throwIfAborted();
|
|
467
|
+
const agentConfig = { ...resolvedAgentConfig, mcpServers };
|
|
468
|
+
const projection = resolveWorkspaceProjection(office);
|
|
469
|
+
// Bootstrap validation fails runner creation early. resolveForRun repeats
|
|
470
|
+
// the check against the actor-specific decision before any provider call.
|
|
471
|
+
assertSandboxSupportsWorkspacePolicy(sandboxConfig, projection.doorPolicy, projection.promptSources.globalMemoryReadOnly === true);
|
|
472
|
+
const { executor, resolveForRun } = createRunnerExecutionContext(sandboxConfig, vaultManager, provisioner, office.workspace);
|
|
473
|
+
const pathContext = getUnresolvedSandboxPathContext(sandboxConfig, workspaceDir);
|
|
474
|
+
// The env wraps the stable executor wrapper, which delegates to the
|
|
475
|
+
// actor-resolved executor per call, so one env serves every run.
|
|
476
|
+
const toolContext = {
|
|
477
|
+
env: createSandboxExecutionEnv(executor, sandboxConfig.type, pathContext.runtimeWorkspaceRoot),
|
|
478
|
+
};
|
|
479
|
+
const modelRegistry = options.models ?? MikanModels.create();
|
|
480
|
+
if (modelRegistry.getError()) {
|
|
481
|
+
log.logWarning("models.json load error", modelRegistry.getError());
|
|
482
|
+
}
|
|
483
|
+
const model = modelRegistry.resolve(agentConfig.provider, agentConfig.model);
|
|
484
|
+
// Create tools (per-runner, with per-runner upload function setter)
|
|
485
|
+
const toolBindings = createMikanTools(executor, workspaceDir, { sandbox: sandboxConfig, resourceController: resourceController ?? provisioner }, platformToolPackFactories ?? [], {
|
|
486
|
+
model,
|
|
487
|
+
getApiKey: () => modelRegistry.getApiKeyForProvider(model.provider),
|
|
488
|
+
// The conversation's own office dir: mounted into the sandbox, unlike
|
|
489
|
+
// the workspace base — generated images must land somewhere the agent
|
|
490
|
+
// (and a future run) can still reach.
|
|
491
|
+
outputDir: conversationDir,
|
|
492
|
+
});
|
|
493
|
+
const systemPrompt = await buildInitialSystemPrompt({
|
|
494
|
+
office,
|
|
495
|
+
pathContext,
|
|
496
|
+
projection,
|
|
497
|
+
sandboxConfig,
|
|
498
|
+
});
|
|
499
|
+
options.signal?.throwIfAborted();
|
|
500
|
+
const { contextFile, threadRootMessage } = sessionScope;
|
|
501
|
+
const sessionManager = await openRunnerSessionManager({
|
|
502
|
+
contextFile,
|
|
503
|
+
runtimeWorkspaceRoot: pathContext.runtimeWorkspaceRoot,
|
|
504
|
+
sessionKey,
|
|
505
|
+
threadRootMessage,
|
|
506
|
+
});
|
|
507
|
+
return finishRunnerCreation({
|
|
508
|
+
options,
|
|
509
|
+
conversationId,
|
|
510
|
+
conversationDir,
|
|
511
|
+
workspaceDir,
|
|
512
|
+
executor,
|
|
513
|
+
resolveForRun,
|
|
514
|
+
model,
|
|
515
|
+
modelRegistry,
|
|
516
|
+
agentConfig,
|
|
517
|
+
systemPrompt,
|
|
518
|
+
sessionManager,
|
|
519
|
+
toolBindings,
|
|
520
|
+
toolContext,
|
|
521
|
+
});
|
|
522
|
+
}
|
|
491
523
|
//# sourceMappingURL=runner.js.map
|