@multiplayer-app/agent 0.1.19 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -7
- package/dist/agent/definition.d.ts +13 -0
- package/dist/agent/definition.d.ts.map +1 -1
- package/dist/agent/definition.test.js +8 -3
- package/dist/agent/definition.test.js.map +1 -1
- package/dist/agent/profiles/coding.d.ts +1 -1
- package/dist/agent/profiles/coding.d.ts.map +1 -1
- package/dist/agent/profiles/coding.js +21 -4
- package/dist/agent/profiles/coding.js.map +1 -1
- package/dist/agent/profiles/index.js +1 -1
- package/dist/agent/profiles/index.js.map +1 -1
- package/dist/agent/profiles/research.d.ts.map +1 -1
- package/dist/agent/profiles/research.js +23 -1
- package/dist/agent/profiles/research.js.map +1 -1
- package/dist/agent/turn-history.d.ts +40 -0
- package/dist/agent/turn-history.d.ts.map +1 -0
- package/dist/agent/turn-history.js +167 -0
- package/dist/agent/turn-history.js.map +1 -0
- package/dist/agent/turn-runner.d.ts +22 -1
- package/dist/agent/turn-runner.d.ts.map +1 -1
- package/dist/agent/turn-runner.js +162 -79
- package/dist/agent/turn-runner.js.map +1 -1
- package/dist/app/app-host.d.ts +57 -0
- package/dist/app/app-host.d.ts.map +1 -0
- package/dist/app/app-host.js +252 -0
- package/dist/app/app-host.js.map +1 -0
- package/dist/app/app-host.test.d.ts +2 -0
- package/dist/app/app-host.test.d.ts.map +1 -0
- package/dist/app/app-host.test.js +639 -0
- package/dist/app/app-host.test.js.map +1 -0
- package/dist/app/config.d.ts +196 -0
- package/dist/app/config.d.ts.map +1 -0
- package/dist/app/config.js +362 -0
- package/dist/app/config.js.map +1 -0
- package/dist/app/config.test.d.ts +2 -0
- package/dist/app/config.test.d.ts.map +1 -0
- package/dist/app/config.test.js +224 -0
- package/dist/app/config.test.js.map +1 -0
- package/dist/app/detect.d.ts +68 -0
- package/dist/app/detect.d.ts.map +1 -0
- package/dist/app/detect.js +449 -0
- package/dist/app/detect.js.map +1 -0
- package/dist/app/detect.test.d.ts +2 -0
- package/dist/app/detect.test.d.ts.map +1 -0
- package/dist/app/detect.test.js +267 -0
- package/dist/app/detect.test.js.map +1 -0
- package/dist/app/env.d.ts +5 -0
- package/dist/app/env.d.ts.map +1 -0
- package/dist/app/env.js +22 -0
- package/dist/app/env.js.map +1 -0
- package/dist/app/functions-cli.d.ts +3 -0
- package/dist/app/functions-cli.d.ts.map +1 -0
- package/dist/app/functions-cli.js +27 -0
- package/dist/app/functions-cli.js.map +1 -0
- package/dist/app/functions-host.d.ts +15 -0
- package/dist/app/functions-host.d.ts.map +1 -0
- package/dist/app/functions-host.js +276 -0
- package/dist/app/functions-host.js.map +1 -0
- package/dist/app/functions-host.test.d.ts +2 -0
- package/dist/app/functions-host.test.d.ts.map +1 -0
- package/dist/app/functions-host.test.js +117 -0
- package/dist/app/functions-host.test.js.map +1 -0
- package/dist/app/functions-routes.d.ts +23 -0
- package/dist/app/functions-routes.d.ts.map +1 -0
- package/dist/app/functions-routes.js +85 -0
- package/dist/app/functions-routes.js.map +1 -0
- package/dist/app/functions-routes.test.d.ts +2 -0
- package/dist/app/functions-routes.test.d.ts.map +1 -0
- package/dist/app/functions-routes.test.js +40 -0
- package/dist/app/functions-routes.test.js.map +1 -0
- package/dist/app/manifest.d.ts +17 -0
- package/dist/app/manifest.d.ts.map +1 -0
- package/dist/app/manifest.js +64 -0
- package/dist/app/manifest.js.map +1 -0
- package/dist/app/manifest.test.d.ts +2 -0
- package/dist/app/manifest.test.d.ts.map +1 -0
- package/dist/app/manifest.test.js +173 -0
- package/dist/app/manifest.test.js.map +1 -0
- package/dist/app/release-artifacts.d.ts +39 -0
- package/dist/app/release-artifacts.d.ts.map +1 -0
- package/dist/app/release-artifacts.js +229 -0
- package/dist/app/release-artifacts.js.map +1 -0
- package/dist/app/release-artifacts.test.d.ts +2 -0
- package/dist/app/release-artifacts.test.d.ts.map +1 -0
- package/dist/app/release-artifacts.test.js +295 -0
- package/dist/app/release-artifacts.test.js.map +1 -0
- package/dist/app/route-pattern.d.ts +23 -0
- package/dist/app/route-pattern.d.ts.map +1 -0
- package/dist/app/route-pattern.js +339 -0
- package/dist/app/route-pattern.js.map +1 -0
- package/dist/app/route-pattern.test.d.ts +2 -0
- package/dist/app/route-pattern.test.d.ts.map +1 -0
- package/dist/app/route-pattern.test.js +187 -0
- package/dist/app/route-pattern.test.js.map +1 -0
- package/dist/app/rules.d.ts +61 -0
- package/dist/app/rules.d.ts.map +1 -0
- package/dist/app/rules.js +90 -0
- package/dist/app/rules.js.map +1 -0
- package/dist/app/rules.test.d.ts +2 -0
- package/dist/app/rules.test.d.ts.map +1 -0
- package/dist/app/rules.test.js +69 -0
- package/dist/app/rules.test.js.map +1 -0
- package/dist/app/runner.d.ts +109 -0
- package/dist/app/runner.d.ts.map +1 -0
- package/dist/app/runner.js +429 -0
- package/dist/app/runner.js.map +1 -0
- package/dist/app/site.d.ts +73 -0
- package/dist/app/site.d.ts.map +1 -0
- package/dist/app/site.js +161 -0
- package/dist/app/site.js.map +1 -0
- package/dist/app/site.test.d.ts +2 -0
- package/dist/app/site.test.d.ts.map +1 -0
- package/dist/app/site.test.js +291 -0
- package/dist/app/site.test.js.map +1 -0
- package/dist/app/static-server.d.ts +20 -0
- package/dist/app/static-server.d.ts.map +1 -0
- package/dist/app/static-server.js +145 -0
- package/dist/app/static-server.js.map +1 -0
- package/dist/context-pruning.d.ts +2 -0
- package/dist/context-pruning.d.ts.map +1 -1
- package/dist/context-pruning.js +3 -2
- package/dist/context-pruning.js.map +1 -1
- package/dist/models/usage.d.ts +6 -0
- package/dist/models/usage.d.ts.map +1 -1
- package/dist/models/usage.js +13 -0
- package/dist/models/usage.js.map +1 -1
- package/dist/persistence/conversation-store.d.ts +21 -0
- package/dist/persistence/conversation-store.d.ts.map +1 -0
- package/dist/persistence/conversation-store.js +59 -0
- package/dist/persistence/conversation-store.js.map +1 -0
- package/dist/persistence/conversation-store.test.d.ts +2 -0
- package/dist/persistence/conversation-store.test.d.ts.map +1 -0
- package/dist/persistence/conversation-store.test.js +98 -0
- package/dist/persistence/conversation-store.test.js.map +1 -0
- package/dist/persistence/git-sync.d.ts +14 -1
- package/dist/persistence/git-sync.d.ts.map +1 -1
- package/dist/persistence/git-sync.js +73 -17
- package/dist/persistence/git-sync.js.map +1 -1
- package/dist/persistence/git-sync.test.js +155 -6
- package/dist/persistence/git-sync.test.js.map +1 -1
- package/dist/persistence/snapshot-sync.d.ts +19 -2
- package/dist/persistence/snapshot-sync.d.ts.map +1 -1
- package/dist/persistence/snapshot-sync.js +194 -83
- package/dist/persistence/snapshot-sync.js.map +1 -1
- package/dist/persistence/snapshot-sync.test.js +145 -27
- package/dist/persistence/snapshot-sync.test.js.map +1 -1
- package/dist/persistence/workspace.d.ts +3 -0
- package/dist/persistence/workspace.d.ts.map +1 -1
- package/dist/persistence/workspace.js +1 -0
- package/dist/persistence/workspace.js.map +1 -1
- package/dist/research/extract-texts.d.ts.map +1 -1
- package/dist/research/extract-texts.js +34 -16
- package/dist/research/extract-texts.js.map +1 -1
- package/dist/research/filingramp/attachment-tools.d.ts.map +1 -1
- package/dist/research/filingramp/attachment-tools.js +7 -4
- package/dist/research/filingramp/attachment-tools.js.map +1 -1
- package/dist/research/filingramp/shared.d.ts.map +1 -1
- package/dist/research/filingramp/shared.js +5 -5
- package/dist/research/filingramp/shared.js.map +1 -1
- package/dist/research/prompt.d.ts.map +1 -1
- package/dist/research/prompt.js +2 -1
- package/dist/research/prompt.js.map +1 -1
- package/dist/runtime/app-mode.d.ts +10 -0
- package/dist/runtime/app-mode.d.ts.map +1 -0
- package/dist/runtime/app-mode.js +172 -0
- package/dist/runtime/app-mode.js.map +1 -0
- package/dist/runtime/app-mode.test.d.ts +2 -0
- package/dist/runtime/app-mode.test.d.ts.map +1 -0
- package/dist/runtime/app-mode.test.js +130 -0
- package/dist/runtime/app-mode.test.js.map +1 -0
- package/dist/runtime/app-rehearsal.d.ts +2 -0
- package/dist/runtime/app-rehearsal.d.ts.map +1 -0
- package/dist/runtime/app-rehearsal.js +56 -0
- package/dist/runtime/app-rehearsal.js.map +1 -0
- package/dist/runtime/build-mode.d.ts +12 -0
- package/dist/runtime/build-mode.d.ts.map +1 -0
- package/dist/runtime/build-mode.js +116 -0
- package/dist/runtime/build-mode.js.map +1 -0
- package/dist/runtime/build-mode.test.d.ts +2 -0
- package/dist/runtime/build-mode.test.d.ts.map +1 -0
- package/dist/runtime/build-mode.test.js +121 -0
- package/dist/runtime/build-mode.test.js.map +1 -0
- package/dist/runtime/cli.js +7 -2
- package/dist/runtime/cli.js.map +1 -1
- package/dist/runtime/config.d.ts +4 -0
- package/dist/runtime/config.d.ts.map +1 -1
- package/dist/runtime/config.js +13 -2
- package/dist/runtime/config.js.map +1 -1
- package/dist/runtime/guest-server.d.ts +3 -0
- package/dist/runtime/guest-server.d.ts.map +1 -0
- package/dist/runtime/{lambda-microvm.js → guest-server.js} +49 -18
- package/dist/runtime/guest-server.js.map +1 -0
- package/dist/runtime/image-hooks.d.ts +5 -0
- package/dist/runtime/image-hooks.d.ts.map +1 -0
- package/dist/runtime/image-hooks.js +68 -0
- package/dist/runtime/image-hooks.js.map +1 -0
- package/dist/runtime/image-hooks.test.d.ts +2 -0
- package/dist/runtime/image-hooks.test.d.ts.map +1 -0
- package/dist/runtime/image-hooks.test.js +74 -0
- package/dist/runtime/image-hooks.test.js.map +1 -0
- package/dist/runtime/index.d.ts +8 -3
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +53 -35
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/listening-ports.d.ts +13 -0
- package/dist/runtime/listening-ports.d.ts.map +1 -0
- package/dist/runtime/listening-ports.js +78 -0
- package/dist/runtime/listening-ports.js.map +1 -0
- package/dist/runtime/listening-ports.test.d.ts +2 -0
- package/dist/runtime/listening-ports.test.d.ts.map +1 -0
- package/dist/runtime/listening-ports.test.js +39 -0
- package/dist/runtime/listening-ports.test.js.map +1 -0
- package/dist/runtime/preview-proxy.d.ts +56 -0
- package/dist/runtime/preview-proxy.d.ts.map +1 -0
- package/dist/runtime/preview-proxy.js +302 -0
- package/dist/runtime/preview-proxy.js.map +1 -0
- package/dist/runtime/preview-proxy.test.d.ts +2 -0
- package/dist/runtime/preview-proxy.test.d.ts.map +1 -0
- package/dist/runtime/preview-proxy.test.js +122 -0
- package/dist/runtime/preview-proxy.test.js.map +1 -0
- package/dist/runtime/session-mode.d.ts +3 -0
- package/dist/runtime/session-mode.d.ts.map +1 -0
- package/dist/runtime/session-mode.js +60 -0
- package/dist/runtime/session-mode.js.map +1 -0
- package/dist/runtime/workload.d.ts +44 -0
- package/dist/runtime/workload.d.ts.map +1 -0
- package/dist/runtime/workload.js +222 -0
- package/dist/runtime/workload.js.map +1 -0
- package/dist/runtime/workload.test.d.ts +2 -0
- package/dist/runtime/workload.test.d.ts.map +1 -0
- package/dist/runtime/workload.test.js +235 -0
- package/dist/runtime/workload.test.js.map +1 -0
- package/dist/session/conversation.d.ts +10 -2
- package/dist/session/conversation.d.ts.map +1 -1
- package/dist/session/conversation.js +40 -12
- package/dist/session/conversation.js.map +1 -1
- package/dist/session/conversation.test.js +2 -3
- package/dist/session/conversation.test.js.map +1 -1
- package/dist/session/index.d.ts +1 -1
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/index.js +2 -1
- package/dist/session/index.js.map +1 -1
- package/dist/session/runtime.d.ts +20 -3
- package/dist/session/runtime.d.ts.map +1 -1
- package/dist/session/runtime.js +97 -16
- package/dist/session/runtime.js.map +1 -1
- package/dist/session/runtime.test.js +18 -7
- package/dist/session/runtime.test.js.map +1 -1
- package/dist/session/tools.d.ts.map +1 -1
- package/dist/session/tools.js +5 -4
- package/dist/session/tools.js.map +1 -1
- package/dist/task/loop.d.ts.map +1 -1
- package/dist/task/loop.js +6 -4
- package/dist/task/loop.js.map +1 -1
- package/dist/tools/exec-tools.d.ts +12 -0
- package/dist/tools/exec-tools.d.ts.map +1 -1
- package/dist/tools/exec-tools.js +46 -3
- package/dist/tools/exec-tools.js.map +1 -1
- package/dist/tools/exec-tools.test.d.ts +2 -0
- package/dist/tools/exec-tools.test.d.ts.map +1 -0
- package/dist/tools/exec-tools.test.js +48 -0
- package/dist/tools/exec-tools.test.js.map +1 -0
- package/dist/tools/fs-tools.d.ts.map +1 -1
- package/dist/tools/fs-tools.js +5 -5
- package/dist/tools/fs-tools.js.map +1 -1
- package/dist/transport/link.d.ts.map +1 -1
- package/dist/transport/link.js +16 -5
- package/dist/transport/link.js.map +1 -1
- package/dist/transport/link.test.js +24 -0
- package/dist/transport/link.test.js.map +1 -1
- package/dist/transport/protocol.d.ts +190 -3
- package/dist/transport/protocol.d.ts.map +1 -1
- package/dist/transport/protocol.js +147 -7
- package/dist/transport/protocol.js.map +1 -1
- package/dist/transport/protocol.test.js +41 -0
- package/dist/transport/protocol.test.js.map +1 -1
- package/dist/workspace-sync/eligibility.d.ts +14 -0
- package/dist/workspace-sync/eligibility.d.ts.map +1 -0
- package/dist/workspace-sync/eligibility.js +53 -0
- package/dist/workspace-sync/eligibility.js.map +1 -0
- package/dist/workspace-sync/merge.d.ts +15 -0
- package/dist/workspace-sync/merge.d.ts.map +1 -0
- package/dist/workspace-sync/merge.js +66 -0
- package/dist/workspace-sync/merge.js.map +1 -0
- package/dist/workspace-sync/merge.test.d.ts +2 -0
- package/dist/workspace-sync/merge.test.d.ts.map +1 -0
- package/dist/workspace-sync/merge.test.js +28 -0
- package/dist/workspace-sync/merge.test.js.map +1 -0
- package/dist/workspace-sync/workspace-sync.d.ts +48 -0
- package/dist/workspace-sync/workspace-sync.d.ts.map +1 -0
- package/dist/workspace-sync/workspace-sync.js +308 -0
- package/dist/workspace-sync/workspace-sync.js.map +1 -0
- package/dist/workspace-sync/workspace-sync.test.d.ts +2 -0
- package/dist/workspace-sync/workspace-sync.test.d.ts.map +1 -0
- package/dist/workspace-sync/workspace-sync.test.js +111 -0
- package/dist/workspace-sync/workspace-sync.test.js.map +1 -0
- package/dist/workspace-sync/write-drafts.d.ts +24 -0
- package/dist/workspace-sync/write-drafts.d.ts.map +1 -0
- package/dist/workspace-sync/write-drafts.js +87 -0
- package/dist/workspace-sync/write-drafts.js.map +1 -0
- package/dist/workspace-sync/write-drafts.test.d.ts +2 -0
- package/dist/workspace-sync/write-drafts.test.d.ts.map +1 -0
- package/dist/workspace-sync/write-drafts.test.js +36 -0
- package/dist/workspace-sync/write-drafts.test.js.map +1 -0
- package/package.json +12 -2
- package/dist/runtime/lambda-microvm.d.ts +0 -3
- package/dist/runtime/lambda-microvm.d.ts.map +0 -1
- package/dist/runtime/lambda-microvm.js.map +0 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ configuration, chooses a mode, and connects the agent to the gateway.
|
|
|
7
7
|
|
|
8
8
|
| Area | Files | Responsibility |
|
|
9
9
|
| --- | --- | --- |
|
|
10
|
-
| Startup | `src/runtime/cli.ts`, `src/runtime/index.ts`, `src/runtime/
|
|
10
|
+
| Startup | `src/runtime/cli.ts`, `src/runtime/index.ts`, `src/runtime/guest-server.ts` | Process startup, shutdown, Lambda suspend/terminate hooks |
|
|
11
11
|
| Configuration and wire contract | `src/runtime/config.ts`, `src/transport/protocol.ts` | Environment variables, commands, events, secret keys |
|
|
12
12
|
| One-shot tasks | `src/task/loop.ts`, `src/transport/reporter.ts` | Run `AGENT_TASK`, report results, exit |
|
|
13
13
|
| Agent definitions | `src/agent/definition.ts`, `src/agent/profiles/` | Coding/research prompts, model selection, workspace directories, tool composition |
|
|
@@ -19,6 +19,9 @@ configuration, chooses a mode, and connects the agent to the gateway.
|
|
|
19
19
|
| Models and usage | `src/models/resolve-model.ts`, `src/models/usage.ts` | Resolve a definition's model and normalize token usage |
|
|
20
20
|
| Workspace persistence | `src/persistence/workspace.ts`, `src/persistence/git-sync.ts`, `src/persistence/snapshot-sync.ts` | Common restore/checkpoint interface backed by project Git or standalone session snapshots |
|
|
21
21
|
| Gateway connection | `src/transport/link.ts` | Send sequenced events and acknowledge commands |
|
|
22
|
+
| Workspace live sync | `src/workspace-sync/` | Mirror every workspace text file into the session as it changes (`file_*` events), stream `write_files` drafts while the model writes, merge people's edits (`file_state`) back into the files |
|
|
23
|
+
| Live preview | `src/runtime/preview-proxy.ts`, `src/runtime/listening-ports.ts` | Forward the gateway's `<vmId>-<port>.apps.<domain>` and session URL (`<sessionId>[-<port>].apps.<domain>`) traffic (HTTP and WebSocket) from the guest's port 8080 to the app on localhost; report listening ports (`ports` event) |
|
|
24
|
+
| App (builder.json) | `src/app/`, `src/runtime/app-mode.ts` | Run the workspace's app as `.builder/builder.json` says ([docs](../../docs/architecture/builder-json.md)): a session VM writes the file from the services it detects as Vercel does, with the routes between them, and the file then decides; installs, services on their own `$PORT`, daemons, restarts; after every turn and on boot; route the session URL to it (`app` event, `run_app` tool); in `AGENT_MODE=app` a deployment of it, built and served on port 8080 |
|
|
22
25
|
| Local and MCP tools | `src/tools/`, `src/mcp/` | Filesystem, shell, external tool discovery and execution |
|
|
23
26
|
| Research tools | `src/research/filingramp-tools.ts`, `src/research/filingramp/` | Register FilingRamp tools and implement searches, filing details, downloads |
|
|
24
27
|
| Research contracts | `src/research/filingramp-contract.ts`, `src/research/scope.ts` | Normalize API-specific filters and apply the session scope |
|
|
@@ -45,8 +48,8 @@ returned messages, and decides when completion can be announced. Its constructor
|
|
|
45
48
|
optional definition, runner, and persistence dependencies so these boundaries can be tested
|
|
46
49
|
without a model provider or storage server.
|
|
47
50
|
|
|
48
|
-
`WorkspacePersistence` adapts the existing Git
|
|
49
|
-
distinguishes a Git commit from a
|
|
51
|
+
`WorkspacePersistence` adapts the existing Git and session-folder sync classes. Its checkpoint
|
|
52
|
+
result distinguishes a Git commit from a folder hash; neither leaks into the other's wire contract.
|
|
50
53
|
A successful no-op is still durable. A failed restore or upload rejects the operation.
|
|
51
54
|
|
|
52
55
|
## Session flow and invariants
|
|
@@ -70,11 +73,15 @@ and an in-flight model/tool step are process-local; this is not an execution jou
|
|
|
70
73
|
replays interrupted tool calls. Client event replay is a separate platform concern handled
|
|
71
74
|
outside this runtime. The refactor does not change the persisted conversation format.
|
|
72
75
|
|
|
73
|
-
Standalone sessions
|
|
74
|
-
|
|
76
|
+
Standalone sessions keep their workspace as files in the session's folder,
|
|
77
|
+
`accounts/<accountId>/sessions/<sessionId>/`, through the authenticated storage service; they do
|
|
78
|
+
not create `.git`. A checkpoint uploads only what changed. A new VM downloads the folder.
|
|
75
79
|
Project sessions use Git under `accounts/<accountId>/projects/<projectId>/`.
|
|
76
|
-
|
|
77
|
-
|
|
80
|
+
Workspace live sync mirrors every text file of the workspace into the session while the agent
|
|
81
|
+
works, both ways (services/api's workspace-sync.service.ts holds the session's side); with it,
|
|
82
|
+
`publish_results` only makes the files it names current at once. Mirrored text belongs to live
|
|
83
|
+
sync, and a checkpoint uploads it only while the session has not confirmed that version; everything
|
|
84
|
+
else (binaries, large files, build output, the agent's conversation) is the checkpoint's.
|
|
78
85
|
|
|
79
86
|
## Adding a research tool
|
|
80
87
|
|
|
@@ -7,16 +7,29 @@ export interface AgentModel {
|
|
|
7
7
|
provider: ModelProviderConfig;
|
|
8
8
|
attribution: OpenRouterApp;
|
|
9
9
|
}
|
|
10
|
+
/** The agent's own running notes: what compaction carries forward in place of the steps it removes. */
|
|
11
|
+
export interface WorkingNotes {
|
|
12
|
+
/** Workspace-relative path, named to the agent in the compaction note. */
|
|
13
|
+
path: string;
|
|
14
|
+
(workspaceDir: string): Promise<string | undefined>;
|
|
15
|
+
}
|
|
10
16
|
/** Profile-specific behavior. Definitions have no queue, conversation, or checkpoint state. */
|
|
11
17
|
export interface AgentDefinition {
|
|
12
18
|
profile: AgentProfile;
|
|
13
19
|
model: AgentModel;
|
|
20
|
+
/** Steps per model loop. A turn ends here unless `maxTurnSteps` lets it continue in a new loop. */
|
|
14
21
|
maxSteps: number;
|
|
22
|
+
/**
|
|
23
|
+
* Steps a turn may take in all, continuing past `maxSteps` while the model still wants to work.
|
|
24
|
+
* Unset, a turn is one loop of `maxSteps`. The token budget bounds the spending either way.
|
|
25
|
+
*/
|
|
26
|
+
maxTurnSteps?: number;
|
|
15
27
|
workspaceDirectories: readonly string[];
|
|
16
28
|
instructions(context: {
|
|
17
29
|
restored: boolean;
|
|
18
30
|
tokenBudget?: number;
|
|
19
31
|
}): string;
|
|
20
32
|
createTools(context: SessionToolContext): Record<string, Tool>;
|
|
33
|
+
workingNotes?: WorkingNotes;
|
|
21
34
|
}
|
|
22
35
|
//# sourceMappingURL=definition.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../../src/agent/definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAEjE,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,mBAAmB,CAAA;IAC7B,WAAW,EAAE,aAAa,CAAA;CAC3B;AAED,+FAA+F;AAC/F,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,YAAY,CAAA;IACrB,KAAK,EAAE,UAAU,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,oBAAoB,EAAE,SAAS,MAAM,EAAE,CAAA;IACvC,YAAY,CAAC,OAAO,EAAE;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAA;IAC1E,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../../src/agent/definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAEjE,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,mBAAmB,CAAA;IAC7B,WAAW,EAAE,aAAa,CAAA;CAC3B;AAED,uGAAuG;AACvG,MAAM,WAAW,YAAY;IAC3B,0EAA0E;IAC1E,IAAI,EAAE,MAAM,CAAA;IACZ,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;CACpD;AAED,+FAA+F;AAC/F,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,YAAY,CAAA;IACrB,KAAK,EAAE,UAAU,CAAA;IACjB,mGAAmG;IACnG,QAAQ,EAAE,MAAM,CAAA;IAChB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,oBAAoB,EAAE,SAAS,MAAM,EAAE,CAAA;IACvC,YAAY,CAAC,OAAO,EAAE;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAA;IAC1E,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAC9D,YAAY,CAAC,EAAE,YAAY,CAAA;CAC5B"}
|
|
@@ -7,7 +7,7 @@ const strict_1 = __importDefault(require("node:assert/strict"));
|
|
|
7
7
|
const node_test_1 = require("node:test");
|
|
8
8
|
const profiles_1 = require("./profiles");
|
|
9
9
|
(0, node_test_1.it)('keeps profile instructions, workspace setup, models, and tools together', () => {
|
|
10
|
-
var _a;
|
|
10
|
+
var _a, _b;
|
|
11
11
|
const config = {
|
|
12
12
|
sessionId: 'test', mode: 'session', profile: 'coding', workspaceDir: '/unused',
|
|
13
13
|
model: 'main-model', extractionModel: 'extraction-model', provider: {}, mcpConnections: [],
|
|
@@ -23,8 +23,13 @@ const profiles_1 = require("./profiles");
|
|
|
23
23
|
strict_1.default.equal(coding.model.id, 'main-model');
|
|
24
24
|
strict_1.default.deepEqual(coding.workspaceDirectories, []);
|
|
25
25
|
strict_1.default.match(coding.instructions({ restored: false }), /coding agent/);
|
|
26
|
-
|
|
26
|
+
// An app can show the account's data: the FilingRamp tools, but not research's bulk extraction.
|
|
27
|
+
strict_1.default.match(coding.instructions({ restored: false }), /FilingRamp tools/);
|
|
28
|
+
strict_1.default.equal(typeof ((_a = coding.createTools(context).search_filings) === null || _a === void 0 ? void 0 : _a.execute), 'function');
|
|
27
29
|
strict_1.default.equal(coding.createTools(context).extract_from_texts, undefined);
|
|
30
|
+
const withoutFilingRamp = (0, profiles_1.createAgentDefinition)({ ...config, filingRamp: undefined }, context.workspaceDir);
|
|
31
|
+
strict_1.default.equal(withoutFilingRamp.createTools(context).search_filings, undefined);
|
|
32
|
+
strict_1.default.doesNotMatch(withoutFilingRamp.instructions({ restored: false }), /FilingRamp/);
|
|
28
33
|
const research = (0, profiles_1.createAgentDefinition)({ ...config, profile: 'research' }, context.workspaceDir);
|
|
29
34
|
strict_1.default.deepEqual(research.workspaceDirectories, ['research', 'data', 'data/text']);
|
|
30
35
|
strict_1.default.match(research.instructions({ restored: false }), /fresh session/);
|
|
@@ -33,7 +38,7 @@ const profiles_1 = require("./profiles");
|
|
|
33
38
|
strict_1.default.match(research.instructions({ restored: false }), /TX/);
|
|
34
39
|
const tools = research.createTools(context);
|
|
35
40
|
for (const name of ['search_filings', 'count_filings', 'summarize_filings', 'get_filing', 'search_documents', 'download_attachment', 'search_objections', 'read_text', 'extract_from_texts']) {
|
|
36
|
-
strict_1.default.equal(typeof ((
|
|
41
|
+
strict_1.default.equal(typeof ((_b = tools[name]) === null || _b === void 0 ? void 0 : _b.execute), 'function', name);
|
|
37
42
|
}
|
|
38
43
|
strict_1.default.equal(research.createTools(context).search_documents, tools.search_documents, 'scope lookup cache survives between turns');
|
|
39
44
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.test.js","sourceRoot":"","sources":["../../src/agent/definition.test.ts"],"names":[],"mappings":";;;;;AAAA,gEAAuC;AACvC,yCAA8B;AAE9B,yCAAkD;AAGlD,IAAA,cAAE,EAAC,yEAAyE,EAAE,GAAG,EAAE;;IACjF,MAAM,MAAM,GAAuB;QACjC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS;QAC9E,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,QAAQ,EAAE,EAAE,EAAE,cAAc,EAAE,EAAE;QAC1F,UAAU,EAAE,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE;QACvF,aAAa,EAAE,EAAE,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;KAClC,CAAA;IACD,MAAM,OAAO,GAAuB;QAClC,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,eAAe,EAAE,CAAC,MAAM;QAClE,cAAc,KAAI,CAAC,EAAE,oBAAoB,KAAI,CAAC,EAAE,YAAY,KAAI,CAAC,EAAE,WAAW,KAAI,CAAC;KACpF,CAAA;IACD,MAAM,MAAM,GAAG,IAAA,gCAAqB,EAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,CAAA;IAClE,gBAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;IACtC,gBAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,YAAY,CAAC,CAAA;IAC3C,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CAAC,CAAC,CAAA;IAClF,gBAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE,eAAe,CAAC,CAAA;IACzE,gBAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,EAAE,8BAA8B,CAAC,CAAA;IAC1G,gBAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,EAAE,cAAc,CAAC,CAAA;IAC1F,gBAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC,CAAA;IAC9D,MAAM,KAAK,GAAG,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;IAC3C,KAAK,MAAM,IAAI,IAAI,CAAC,gBAAgB,EAAE,eAAe,EAAE,mBAAmB,EAAE,YAAY,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,WAAW,EAAE,oBAAoB,CAAC,EAAE,CAAC;QAC7L,gBAAM,CAAC,KAAK,CAAC,OAAO,CAAA,MAAA,KAAK,CAAC,IAAI,CAAC,0CAAE,OAAO,CAAA,EAAE,UAAU,EAAE,IAAI,CAAC,CAAA;IAC7D,CAAC;IACD,gBAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,gBAAgB,EAAE,KAAK,CAAC,gBAAgB,EAAE,2CAA2C,CAAC,CAAA;AACnI,CAAC,CAAC,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { AgentDefinition } from '../definition';
|
|
2
2
|
import type { AgentRuntimeConfig } from '../../runtime/config';
|
|
3
|
-
export declare function createCodingAgent(config: AgentRuntimeConfig): AgentDefinition;
|
|
3
|
+
export declare function createCodingAgent(config: AgentRuntimeConfig, workspaceDir: string): AgentDefinition;
|
|
4
4
|
//# sourceMappingURL=coding.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coding.d.ts","sourceRoot":"","sources":["../../../src/agent/profiles/coding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAEpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"coding.d.ts","sourceRoot":"","sources":["../../../src/agent/profiles/coding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAEpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAW9D,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,GAAG,eAAe,CAuBnG"}
|
|
@@ -2,16 +2,33 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createCodingAgent = createCodingAgent;
|
|
4
4
|
const attribution_1 = require("../../models/attribution");
|
|
5
|
+
const filingramp_client_1 = require("../../research/filingramp-client");
|
|
6
|
+
const filingramp_tools_1 = require("../../research/filingramp-tools");
|
|
5
7
|
const tools_1 = require("../../session/tools");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
+
const exec_tools_1 = require("../../tools/exec-tools");
|
|
9
|
+
const SYSTEM_PROMPT = `You are a coding agent running inside an isolated session workspace VM with a persistent disk. You build what the user asks for — apps, dashboards, sites, APIs, scripts — as a real project in the workspace. You have direct tools to read/write files and run shell commands in the workspace, plus (if any MCP servers are configured) search_tools/get_tool_details/call_mcp_tool to use them. Every file you write appears in the user's session as you write it, so there is nothing to copy or publish. Work efficiently, verify with cheap commands (build, lint, a curl of the running app), report progress with report_progress, and finish each turn with a concise summary of what you built and how to use it. ${exec_tools_1.LIVE_PREVIEW_GUIDANCE}`;
|
|
10
|
+
const FILINGRAMP_DATA = ` Data from the user's FilingRamp account comes from the FilingRamp tools (count_filings, summarize_filings, search_filings, …): save what the app shows into the data/ folder of the service that shows it (packages/web/data/filings.json) with them and have the app load those files. Never put credentials in the app.`;
|
|
11
|
+
function createCodingAgent(config, workspaceDir) {
|
|
12
|
+
// Same FilingRamp access as the research profile, so an app can show the account's real data.
|
|
13
|
+
let reportProgress;
|
|
14
|
+
const filingTools = config.filingRamp
|
|
15
|
+
? (0, filingramp_tools_1.createFilingRampTools)({
|
|
16
|
+
client: new filingramp_client_1.FilingRampClient(config.filingRamp),
|
|
17
|
+
workspaceDir,
|
|
18
|
+
scope: config.researchScope,
|
|
19
|
+
onProgress: (toolCallId, done, total, label) => reportProgress === null || reportProgress === void 0 ? void 0 : reportProgress([{ key: 'bulk', label, status: done < total ? 'active' : 'done', detail: `${done}/${total}` }], toolCallId),
|
|
20
|
+
})
|
|
21
|
+
: {};
|
|
8
22
|
return {
|
|
9
23
|
profile: 'coding',
|
|
10
24
|
model: { id: config.model, provider: config.provider, attribution: attribution_1.OPENROUTER_APPS.SESSION_AGENT },
|
|
11
25
|
maxSteps: 80,
|
|
12
26
|
workspaceDirectories: [],
|
|
13
|
-
instructions: () => SYSTEM_PROMPT,
|
|
14
|
-
createTools: (context) =>
|
|
27
|
+
instructions: () => SYSTEM_PROMPT + (config.filingRamp ? FILINGRAMP_DATA : ''),
|
|
28
|
+
createTools: (context) => {
|
|
29
|
+
reportProgress = (steps, toolCallId) => context.reportProgress(steps, toolCallId);
|
|
30
|
+
return { ...(0, tools_1.createSessionTools)(context, config.mcpConnections), ...filingTools };
|
|
31
|
+
},
|
|
15
32
|
};
|
|
16
33
|
}
|
|
17
34
|
//# sourceMappingURL=coding.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coding.js","sourceRoot":"","sources":["../../../src/agent/profiles/coding.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AAU,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9E,WAAW,EAAE,CAAC,OAAO,EAAE,EAAE;YACvB,cAAc,GAAG,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;YACjF,OAAO,EAAE,GAAG,IAAA,0BAAkB,EAAC,OAAO,EAAE,MAAM,CAAC,cAAc,CAAC,EAAE,GAAG,WAAW,EAAE,CAAA;QAClF,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -4,6 +4,6 @@ exports.createAgentDefinition = createAgentDefinition;
|
|
|
4
4
|
const coding_1 = require("./coding");
|
|
5
5
|
const research_1 = require("./research");
|
|
6
6
|
function createAgentDefinition(config, workspaceDir) {
|
|
7
|
-
return config.profile === 'research' ? (0, research_1.createResearchAgent)(config, workspaceDir) : (0, coding_1.createCodingAgent)(config);
|
|
7
|
+
return config.profile === 'research' ? (0, research_1.createResearchAgent)(config, workspaceDir) : (0, coding_1.createCodingAgent)(config, workspaceDir);
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/agent/profiles/index.ts"],"names":[],"mappings":";;AAKA,sDAEC;AALD,qCAA4C;AAC5C,yCAAgD;AAEhD,SAAgB,qBAAqB,CAAC,MAA0B,EAAE,YAAoB;IACpF,OAAO,MAAM,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,IAAA,8BAAmB,EAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,IAAA,0BAAiB,EAAC,MAAM,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/agent/profiles/index.ts"],"names":[],"mappings":";;AAKA,sDAEC;AALD,qCAA4C;AAC5C,yCAAgD;AAEhD,SAAgB,qBAAqB,CAAC,MAA0B,EAAE,YAAoB;IACpF,OAAO,MAAM,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,IAAA,8BAAmB,EAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,IAAA,0BAAiB,EAAC,MAAM,EAAE,YAAY,CAAC,CAAA;AAC5H,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"research.d.ts","sourceRoot":"","sources":["../../../src/agent/profiles/research.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"research.d.ts","sourceRoot":"","sources":["../../../src/agent/profiles/research.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAgB,MAAM,eAAe,CAAA;AAElE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AA2B9D,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,GAAG,eAAe,CA2CrG"}
|
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.createResearchAgent = createResearchAgent;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
4
8
|
const attribution_1 = require("../../models/attribution");
|
|
9
|
+
const workload_1 = require("../../runtime/workload");
|
|
5
10
|
const extraction_tool_1 = require("../../research/extraction-tool");
|
|
6
11
|
const filingramp_client_1 = require("../../research/filingramp-client");
|
|
7
12
|
const filingramp_tools_1 = require("../../research/filingramp-tools");
|
|
8
13
|
const prompt_1 = require("../../research/prompt");
|
|
9
14
|
const tools_1 = require("../../session/tools");
|
|
15
|
+
/** Steps per model loop; past it the turn continues in a new loop (see AgentDefinition.maxTurnSteps). */
|
|
16
|
+
const STEPS_PER_LOOP = 80;
|
|
17
|
+
/** A research turn ends on its own or at the budget; this is the guard against a model that never does. */
|
|
18
|
+
const MAX_TURN_STEPS = 480;
|
|
19
|
+
/** The notes file the prompt tells the agent to keep; compaction carries it in place of removed steps. */
|
|
20
|
+
const workingNotes = Object.assign(async (workspaceDir) => {
|
|
21
|
+
try {
|
|
22
|
+
return (await (0, workload_1.readInside)(workspaceDir, node_path_1.default.join(workspaceDir, prompt_1.RESEARCH_OUTPUT_FILES.notes))).toString('utf8');
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (error.code === 'ENOENT')
|
|
26
|
+
return undefined;
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
}, { path: prompt_1.RESEARCH_OUTPUT_FILES.notes });
|
|
10
30
|
function createResearchAgent(config, workspaceDir) {
|
|
11
31
|
// Keep authentication and resolved scope labels across turns. These tools do not own turn state:
|
|
12
32
|
// bulk progress goes to whichever turn is running, through the slot createTools fills each turn.
|
|
@@ -25,8 +45,10 @@ function createResearchAgent(config, workspaceDir) {
|
|
|
25
45
|
return {
|
|
26
46
|
profile: 'research',
|
|
27
47
|
model: { id: config.model, provider: config.provider, attribution: attribution_1.OPENROUTER_APPS.DEEP_RESEARCH },
|
|
28
|
-
maxSteps:
|
|
48
|
+
maxSteps: STEPS_PER_LOOP,
|
|
49
|
+
maxTurnSteps: MAX_TURN_STEPS,
|
|
29
50
|
workspaceDirectories: prompt_1.RESEARCH_WORKSPACE_DIRS,
|
|
51
|
+
workingNotes,
|
|
30
52
|
instructions: ({ restored, tokenBudget }) => {
|
|
31
53
|
var _a;
|
|
32
54
|
return (0, prompt_1.buildResearchSystemPrompt)({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"research.js","sourceRoot":"","sources":["../../../src/agent/profiles/research.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"research.js","sourceRoot":"","sources":["../../../src/agent/profiles/research.ts"],"names":[],"mappings":";;;;;AA+B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AC3C,CAAC;aACH,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { AssistantModelMessage, ModelMessage, ToolModelMessage, UserModelMessage } from 'ai';
|
|
2
|
+
/** One model step: the assistant message and the tool results it produced, if any. */
|
|
3
|
+
export interface TurnStep {
|
|
4
|
+
assistant: AssistantModelMessage;
|
|
5
|
+
tool?: ToolModelMessage;
|
|
6
|
+
}
|
|
7
|
+
export declare function approxChars(message: ModelMessage): number;
|
|
8
|
+
/** Groups a turn's response messages into steps; anything that is not assistant or tool is dropped. */
|
|
9
|
+
export declare function splitSteps(messages: ModelMessage[]): TurnStep[];
|
|
10
|
+
export declare function flattenSteps(steps: TurnStep[]): ModelMessage[];
|
|
11
|
+
/** A deterministic one-paragraph account of steps: tool counts, questions asked, files touched. */
|
|
12
|
+
export declare function describeSteps(steps: TurnStep[]): string;
|
|
13
|
+
/** The text the turn ended with, when it ended on its own (a final step without tool calls). */
|
|
14
|
+
export declare function finalText(steps: TurnStep[]): string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* A finished (or interrupted) turn as one assistant message for the turns that follow. The final text is
|
|
17
|
+
* what the agent told the user; the account says what it did, so it can reuse its files instead of
|
|
18
|
+
* redoing the work. Tool calls and results are left out: they are paid for again on every later step
|
|
19
|
+
* and the workspace holds what they produced.
|
|
20
|
+
*/
|
|
21
|
+
export declare function collapseTurn(messages: ModelMessage[]): AssistantModelMessage;
|
|
22
|
+
export interface CompactionOptions {
|
|
23
|
+
/** Compact once the turn's messages (after result pruning) exceed this many characters. */
|
|
24
|
+
triggerChars: number;
|
|
25
|
+
/** Keep the most recent steps up to about this many characters; everything older is replaced by the note. */
|
|
26
|
+
keepChars: number;
|
|
27
|
+
}
|
|
28
|
+
/** chars ≈ tokens × 4: compact past ~80k tokens of turn, keep ~30k tokens of recent steps. */
|
|
29
|
+
export declare const DEFAULT_COMPACTION: CompactionOptions;
|
|
30
|
+
export interface CompactionState {
|
|
31
|
+
/** Leading steps of the turn replaced by `note`. */
|
|
32
|
+
droppedSteps: number;
|
|
33
|
+
note?: UserModelMessage;
|
|
34
|
+
}
|
|
35
|
+
/** Compaction is monotonic: once steps are dropped they stay dropped, so the cached prefix only changes when more are. */
|
|
36
|
+
export declare function stepsToDrop(steps: TurnStep[], state: CompactionState, options: CompactionOptions): number | undefined;
|
|
37
|
+
export declare function compactionNote(dropped: TurnStep[], notesPath: string | undefined, notes: string | undefined): UserModelMessage;
|
|
38
|
+
/** The turn as the model sees it: the compaction note (if any) followed by the steps not yet dropped. */
|
|
39
|
+
export declare function compactedView(steps: TurnStep[], state: CompactionState): ModelMessage[];
|
|
40
|
+
//# sourceMappingURL=turn-history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn-history.d.ts","sourceRoot":"","sources":["../../src/agent/turn-history.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,qBAAqB,EAAE,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,IAAI,CAAA;AAGjG,sFAAsF;AACtF,MAAM,WAAW,QAAQ;IACvB,SAAS,EAAE,qBAAqB,CAAA;IAChC,IAAI,CAAC,EAAE,gBAAgB,CAAA;CACxB;AAOD,wBAAgB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CAEzD;AAED,uGAAuG;AACvG,wBAAgB,UAAU,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,QAAQ,EAAE,CAO/D;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,YAAY,EAAE,CAE9D;AAuCD,mGAAmG;AACnG,wBAAgB,aAAa,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,MAAM,CAiBvD;AAED,gGAAgG;AAChG,wBAAgB,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,MAAM,GAAG,SAAS,CAK/D;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,qBAAqB,CAgB5E;AAID,MAAM,WAAW,iBAAiB;IAChC,2FAA2F;IAC3F,YAAY,EAAE,MAAM,CAAA;IACpB,6GAA6G;IAC7G,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,8FAA8F;AAC9F,eAAO,MAAM,kBAAkB,EAAE,iBAAiE,CAAA;AAKlG,MAAM,WAAW,eAAe;IAC9B,oDAAoD;IACpD,YAAY,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,gBAAgB,CAAA;CACxB;AAED,0HAA0H;AAC1H,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,iBAAiB,GAAG,MAAM,GAAG,SAAS,CAWrH;AAID,wBAAgB,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,gBAAgB,CAW9H;AAED,yGAAyG;AACzG,wBAAgB,aAAa,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,eAAe,GAAG,YAAY,EAAE,CAGvF"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_COMPACTION = void 0;
|
|
4
|
+
exports.approxChars = approxChars;
|
|
5
|
+
exports.splitSteps = splitSteps;
|
|
6
|
+
exports.flattenSteps = flattenSteps;
|
|
7
|
+
exports.describeSteps = describeSteps;
|
|
8
|
+
exports.finalText = finalText;
|
|
9
|
+
exports.collapseTurn = collapseTurn;
|
|
10
|
+
exports.stepsToDrop = stepsToDrop;
|
|
11
|
+
exports.compactionNote = compactionNote;
|
|
12
|
+
exports.compactedView = compactedView;
|
|
13
|
+
const context_pruning_1 = require("../context-pruning");
|
|
14
|
+
function approxChars(message) {
|
|
15
|
+
return JSON.stringify(message).length;
|
|
16
|
+
}
|
|
17
|
+
/** Groups a turn's response messages into steps; anything that is not assistant or tool is dropped. */
|
|
18
|
+
function splitSteps(messages) {
|
|
19
|
+
const steps = [];
|
|
20
|
+
for (const message of messages) {
|
|
21
|
+
if (message.role === 'assistant')
|
|
22
|
+
steps.push({ assistant: message });
|
|
23
|
+
else if (message.role === 'tool' && steps.length && !steps[steps.length - 1].tool)
|
|
24
|
+
steps[steps.length - 1].tool = message;
|
|
25
|
+
}
|
|
26
|
+
return steps;
|
|
27
|
+
}
|
|
28
|
+
function flattenSteps(steps) {
|
|
29
|
+
return steps.flatMap((step) => (step.tool ? [step.assistant, step.tool] : [step.assistant]));
|
|
30
|
+
}
|
|
31
|
+
function toolCallsOf(step) {
|
|
32
|
+
if (typeof step.assistant.content === 'string')
|
|
33
|
+
return [];
|
|
34
|
+
return step.assistant.content.flatMap((part) => (part.type === 'tool-call' ? [{ toolName: part.toolName, input: part.input }] : []));
|
|
35
|
+
}
|
|
36
|
+
function textOf(message) {
|
|
37
|
+
if (typeof message.content === 'string')
|
|
38
|
+
return message.content;
|
|
39
|
+
return message.content.flatMap((part) => (part.type === 'text' ? [part.text] : [])).join('');
|
|
40
|
+
}
|
|
41
|
+
/** Workspace files a step wrote or asked a tool to write (inputs) or that a tool reported writing (outputs). */
|
|
42
|
+
function filesOf(step) {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
const files = [];
|
|
45
|
+
for (const call of toolCallsOf(step)) {
|
|
46
|
+
const input = call.input;
|
|
47
|
+
if (!input || typeof input !== 'object')
|
|
48
|
+
continue;
|
|
49
|
+
if (Array.isArray(input.files)) {
|
|
50
|
+
for (const file of input.files)
|
|
51
|
+
if (file && typeof file.path === 'string')
|
|
52
|
+
files.push(file.path);
|
|
53
|
+
}
|
|
54
|
+
if (Array.isArray(input.paths))
|
|
55
|
+
for (const entry of input.paths)
|
|
56
|
+
if (typeof entry === 'string')
|
|
57
|
+
files.push(entry);
|
|
58
|
+
files.push(...(0, context_pruning_1.mentionedPaths)(input));
|
|
59
|
+
}
|
|
60
|
+
for (const part of (_b = (_a = step.tool) === null || _a === void 0 ? void 0 : _a.content) !== null && _b !== void 0 ? _b : [])
|
|
61
|
+
if (part.type === 'tool-result')
|
|
62
|
+
files.push(...(0, context_pruning_1.mentionedPaths)(part.output));
|
|
63
|
+
return files;
|
|
64
|
+
}
|
|
65
|
+
function questionsOf(step) {
|
|
66
|
+
return toolCallsOf(step).flatMap((call) => {
|
|
67
|
+
var _a;
|
|
68
|
+
if (call.toolName !== 'request_clarification')
|
|
69
|
+
return [];
|
|
70
|
+
const question = (_a = call.input) === null || _a === void 0 ? void 0 : _a.question;
|
|
71
|
+
return typeof question === 'string' ? [question] : [];
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
const MAX_LISTED_FILES = 40;
|
|
75
|
+
const MAX_QUESTION_CHARS = 1500;
|
|
76
|
+
/** A deterministic one-paragraph account of steps: tool counts, questions asked, files touched. */
|
|
77
|
+
function describeSteps(steps) {
|
|
78
|
+
var _a;
|
|
79
|
+
const counts = new Map();
|
|
80
|
+
const files = new Set();
|
|
81
|
+
const questions = [];
|
|
82
|
+
for (const step of steps) {
|
|
83
|
+
for (const call of toolCallsOf(step))
|
|
84
|
+
counts.set(call.toolName, ((_a = counts.get(call.toolName)) !== null && _a !== void 0 ? _a : 0) + 1);
|
|
85
|
+
for (const file of filesOf(step))
|
|
86
|
+
files.add(file);
|
|
87
|
+
questions.push(...questionsOf(step));
|
|
88
|
+
}
|
|
89
|
+
const parts = [`${steps.length} step${steps.length === 1 ? '' : 's'}`];
|
|
90
|
+
if (counts.size)
|
|
91
|
+
parts.push(`tool calls: ${[...counts].map(([name, count]) => `${name} ×${count}`).join(', ')}`);
|
|
92
|
+
if (files.size) {
|
|
93
|
+
const listed = [...files].slice(0, MAX_LISTED_FILES);
|
|
94
|
+
parts.push(`files written or saved: ${listed.join(', ')}${files.size > listed.length ? ` and ${files.size - listed.length} more` : ''}`);
|
|
95
|
+
}
|
|
96
|
+
for (const question of questions)
|
|
97
|
+
parts.push(`asked the user: "${question.length > MAX_QUESTION_CHARS ? `${question.slice(0, MAX_QUESTION_CHARS)}…` : question}"`);
|
|
98
|
+
return parts.join('; ');
|
|
99
|
+
}
|
|
100
|
+
/** The text the turn ended with, when it ended on its own (a final step without tool calls). */
|
|
101
|
+
function finalText(steps) {
|
|
102
|
+
const last = steps[steps.length - 1];
|
|
103
|
+
if (!last || last.tool || toolCallsOf(last).length)
|
|
104
|
+
return undefined;
|
|
105
|
+
const text = textOf(last.assistant).trim();
|
|
106
|
+
return text || undefined;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* A finished (or interrupted) turn as one assistant message for the turns that follow. The final text is
|
|
110
|
+
* what the agent told the user; the account says what it did, so it can reuse its files instead of
|
|
111
|
+
* redoing the work. Tool calls and results are left out: they are paid for again on every later step
|
|
112
|
+
* and the workspace holds what they produced.
|
|
113
|
+
*/
|
|
114
|
+
function collapseTurn(messages) {
|
|
115
|
+
const steps = splitSteps(messages);
|
|
116
|
+
const text = finalText(steps);
|
|
117
|
+
if (text === undefined) {
|
|
118
|
+
const narration = steps.map((step) => textOf(step.assistant).trim()).filter(Boolean).slice(-1)[0];
|
|
119
|
+
const lead = narration ? `${narration}\n\n` : '';
|
|
120
|
+
// A turn that ends on request_clarification ended on purpose: the next user message is the answer.
|
|
121
|
+
const last = steps[steps.length - 1];
|
|
122
|
+
if (last && toolCallsOf(last).some((call) => call.toolName === 'request_clarification')) {
|
|
123
|
+
return { role: 'assistant', content: `${lead}[This turn paused for the user's answer: ${describeSteps(steps)}.]` };
|
|
124
|
+
}
|
|
125
|
+
return { role: 'assistant', content: `${lead}[This turn was interrupted before it finished: ${describeSteps(steps)}. Its results are in the workspace files, not in this conversation.]` };
|
|
126
|
+
}
|
|
127
|
+
// The final step is the text itself; the account covers the work before it.
|
|
128
|
+
const work = steps.slice(0, -1);
|
|
129
|
+
return { role: 'assistant', content: work.length ? `${text}\n\n[Earlier in this turn: ${describeSteps(work)}.]` : text };
|
|
130
|
+
}
|
|
131
|
+
/** chars ≈ tokens × 4: compact past ~80k tokens of turn, keep ~30k tokens of recent steps. */
|
|
132
|
+
exports.DEFAULT_COMPACTION = { triggerChars: 320000, keepChars: 120000 };
|
|
133
|
+
/** Steps the model is working on right now are never compacted away, whatever their size. */
|
|
134
|
+
const MIN_KEPT_STEPS = 2;
|
|
135
|
+
/** Compaction is monotonic: once steps are dropped they stay dropped, so the cached prefix only changes when more are. */
|
|
136
|
+
function stepsToDrop(steps, state, options) {
|
|
137
|
+
const kept = steps.slice(state.droppedSteps);
|
|
138
|
+
const stepChars = kept.map((step) => approxChars(step.assistant) + (step.tool ? approxChars(step.tool) : 0));
|
|
139
|
+
let total = stepChars.reduce((sum, chars) => sum + chars, 0) + (state.note ? approxChars(state.note) : 0);
|
|
140
|
+
if (total <= options.triggerChars)
|
|
141
|
+
return undefined;
|
|
142
|
+
let drop = 0;
|
|
143
|
+
while (total > options.keepChars && kept.length - drop > MIN_KEPT_STEPS) {
|
|
144
|
+
total -= stepChars[drop];
|
|
145
|
+
drop += 1;
|
|
146
|
+
}
|
|
147
|
+
return drop ? state.droppedSteps + drop : undefined;
|
|
148
|
+
}
|
|
149
|
+
const MAX_NOTES_CHARS = 12000;
|
|
150
|
+
function compactionNote(dropped, notesPath, notes) {
|
|
151
|
+
const account = describeSteps(dropped);
|
|
152
|
+
const memory = (notes === null || notes === void 0 ? void 0 : notes.trim())
|
|
153
|
+
? `Your notes file (${notesPath}) as of now:\n\n${notes.length > MAX_NOTES_CHARS ? `[earlier part omitted]\n${notes.slice(-MAX_NOTES_CHARS)}` : notes}`
|
|
154
|
+
: notesPath
|
|
155
|
+
? `There is no notes file (${notesPath}) yet. Write one now with what is done, which files hold what, and what is next: the next compaction will carry it instead of the steps it removes.`
|
|
156
|
+
: 'Keep your own notes in a workspace file: the next compaction will carry it instead of the steps it removes.';
|
|
157
|
+
return {
|
|
158
|
+
role: 'user',
|
|
159
|
+
content: `(Automatic note, not from the user.) To stay within the context limit, the first ${dropped.length} steps of this turn were removed from the conversation: ${account}. Everything they produced is still in the workspace; the user's messages above and their answers stand. ${memory}\n\nContinue from the steps that follow. If you need something from the removed steps, read it from the workspace files instead of redoing the work.`,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/** The turn as the model sees it: the compaction note (if any) followed by the steps not yet dropped. */
|
|
163
|
+
function compactedView(steps, state) {
|
|
164
|
+
const kept = flattenSteps(steps.slice(state.droppedSteps));
|
|
165
|
+
return state.note ? [state.note, ...kept] : kept;
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=turn-history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn-history.js","sourceRoot":"","sources":["../../src/agent/turn-history.ts"],"names":[],"mappings":";;;AAoBA,kCAEC;AAGD,gCAOC;AAED,oCAEC;AAwCD,sCAiBC;AAGD,8BAKC;AAQD,oCAgBC;AAwBD,kCAWC;AAID,wCAWC;AAGD,sCAGC;AA9KD,wDAAmD;AAanD,SAAgB,WAAW,CAAC,OAAqB;IAC/C,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,MAAM,CAAA;AACvC,CAAC;AAED,uGAAuG;AACvG,SAAgB,UAAU,CAAC,QAAwB;IACjD,MAAM,KAAK,GAAe,EAAE,CAAA;IAC5B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW;YAAE,KAAK,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAA;aAC/D,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI;YAAE,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,C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OAAO,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;IACtC,MAAM,MAAM,GAAG,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,EAAE;QAC1B,CAAC,CAAC,oBAAoB,SAAS,mBAAmB,KAAK,CAAC,MAAM,GAAG,eAAe,CAAC,CAAC,CAAC,2BAA2B,KAAK,CAAC,KAAK,CAAC,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE;QACvJ,CAAC,CAAC,SAAS;YACT,CAAC,CAAC,2BAA2B,SAAS,qJAAqJ;YAC3L,CAAC,CAAC,6GAA6G,CAAA;IACnH,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,oFAAoF,OAAO,CAAC,MAAM,2DAA2D,OAAO,4GAA4G,MAAM,sJAAsJ;KACtb,CAAA;AACH,CAAC;AAED,yGAAyG;AACzG,SAAgB,aAAa,CAAC,KAAiB,EAAE,KAAsB;IACrE,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAA;IAC1D,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AAClD,CAAC"}
|
|
@@ -2,6 +2,7 @@ import { type ModelMessage } from 'ai';
|
|
|
2
2
|
import type { AgentDefinition } from './definition';
|
|
3
3
|
import type { OutboundEvent } from '../transport/link';
|
|
4
4
|
import { type TokenUsage } from '../models/usage';
|
|
5
|
+
import { type DraftSink } from '../workspace-sync/write-drafts';
|
|
5
6
|
/** Steps since the agent last called report_progress in this turn (all of them when it never did). */
|
|
6
7
|
export declare function stepsSinceProgress(steps: Array<{
|
|
7
8
|
toolCalls: Array<{
|
|
@@ -21,6 +22,18 @@ export interface TurnInput {
|
|
|
21
22
|
wrapUpOnly?: boolean;
|
|
22
23
|
recordUsage(usage: TokenUsage): void;
|
|
23
24
|
emit(event: OutboundEvent): void;
|
|
25
|
+
/**
|
|
26
|
+
* The turn's response messages so far, after every finished step. The runtime persists them, so a
|
|
27
|
+
* turn cut off by a lost VM resumes from its last step instead of from the user's message.
|
|
28
|
+
*/
|
|
29
|
+
onStep?(messages: ModelMessage[]): void;
|
|
30
|
+
/**
|
|
31
|
+
* Workspace live sync (workspace-sync/workspace-sync.ts): write_files drafts stream into it, and
|
|
32
|
+
* publish_results mirrors its files through it. Without it, publish_results sends a `files` event.
|
|
33
|
+
*/
|
|
34
|
+
files?: DraftSink & {
|
|
35
|
+
flush(paths: string[]): Promise<void>;
|
|
36
|
+
};
|
|
24
37
|
}
|
|
25
38
|
interface TurnOutput {
|
|
26
39
|
/** Messages to append to history, including a safe text-only fallback for an interrupted turn. */
|
|
@@ -44,7 +57,15 @@ export type TurnResult = TurnOutput & ({
|
|
|
44
57
|
error: string;
|
|
45
58
|
userMessage: string;
|
|
46
59
|
});
|
|
47
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* Executes one turn. It neither mutates conversation history nor checkpoints or schedules work.
|
|
62
|
+
*
|
|
63
|
+
* A turn runs as one or more model loops ("segments") of up to `maxSteps` steps each. A profile with
|
|
64
|
+
* `maxTurnSteps` keeps going in a new segment when a loop ends at the step cap while the model still
|
|
65
|
+
* wants to call tools, until the model stops on its own, asks the user, wraps up for the budget, or
|
|
66
|
+
* reaches `maxTurnSteps`. Across segments the turn is one conversation: long turns are compacted (the
|
|
67
|
+
* oldest steps replaced by a note and the agent's notes file) and bulky old results pruned.
|
|
68
|
+
*/
|
|
48
69
|
export declare class TurnRunner {
|
|
49
70
|
private readonly definition;
|
|
50
71
|
constructor(definition: AgentDefinition);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turn-runner.d.ts","sourceRoot":"","sources":["../../src/agent/turn-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,YAAY,EAAiC,MAAM,IAAI,CA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