@nylorun/runtime 0.26.0-beta → 0.28.0-beta
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 +171 -0
- package/README.md +18 -14
- package/dist/adapters/execution/restate.d.ts +15 -18
- package/dist/adapters/execution/restate.js +31 -27
- package/dist/adapters/replication/pgoutput.d.ts +1 -1
- package/dist/adapters/replication/pgoutput.js +3 -2
- package/dist/adapters/sandbox/local.js +8 -5
- package/dist/adapters/sandbox/virtual.js +2 -2
- package/dist/adapters/streams/s2.d.ts +1 -1
- package/dist/adapters/streams/s2.js +18 -14
- package/dist/api/a2a/card.d.ts +4 -3
- package/dist/api/a2a/card.js +4 -4
- package/dist/api/a2a/endpoint.js +3 -4
- package/dist/api/a2a/protocol.js +4 -0
- package/dist/api/a2a/routes.d.ts +2 -6
- package/dist/api/a2a/routes.js +30 -25
- package/dist/api/ag-ui/endpoint.js +2 -3
- package/dist/api/ag-ui/routes.js +8 -11
- package/dist/api/components.d.ts +6789 -3405
- package/dist/api/components.js +43 -30
- package/dist/api/gate/keys.js +7 -4
- package/dist/api/gate/routes.d.ts +6 -2
- package/dist/api/gate/routes.js +15 -11
- package/dist/api/http/app.js +9 -4
- package/dist/api/http/body.d.ts +17 -3
- package/dist/api/http/body.js +35 -7
- package/dist/api/http/respond.js +6 -2
- package/dist/api/http/routes/access.js +5 -4
- package/dist/api/http/routes/agent-manifests.d.ts +10 -0
- package/dist/api/http/routes/agent-manifests.js +135 -0
- package/dist/api/http/routes/agents.d.ts +11 -0
- package/dist/api/http/routes/agents.js +418 -0
- package/dist/api/http/routes/artifacts.js +21 -9
- package/dist/api/http/routes/coverage.d.ts +4 -4
- package/dist/api/http/routes/coverage.js +13 -7
- package/dist/api/http/routes/files.d.ts +2 -1
- package/dist/api/http/routes/files.js +31 -5
- package/dist/api/http/routes/mcp.js +3 -3
- package/dist/api/http/routes/me.d.ts +1 -1
- package/dist/api/http/routes/me.js +1 -2
- package/dist/api/http/routes/memories.d.ts +9 -0
- package/dist/api/http/routes/memories.js +152 -0
- package/dist/api/http/routes/reads.d.ts +10 -111
- package/dist/api/http/routes/reads.js +51 -29
- package/dist/api/http/routes/sessions.js +26 -54
- package/dist/api/http/routes/tenant.d.ts +2 -2
- package/dist/api/http/routes/tenant.js +77 -24
- package/dist/api/http/routes/triggers.d.ts +10 -0
- package/dist/api/http/routes/triggers.js +180 -0
- package/dist/api/inbound-files.d.ts +3 -9
- package/dist/api/inbound-files.js +18 -24
- package/dist/api/openapi.js +73 -47
- package/dist/artifacts/disk.d.ts +10 -14
- package/dist/artifacts/disk.js +99 -95
- package/dist/artifacts/files.d.ts +13 -4
- package/dist/artifacts/files.js +27 -9
- package/dist/artifacts/folder-upload.d.ts +75 -0
- package/dist/artifacts/folder-upload.js +263 -0
- package/dist/artifacts/folders.d.ts +14 -8
- package/dist/artifacts/folders.js +19 -11
- package/dist/artifacts/links.js +7 -6
- package/dist/artifacts/parts.d.ts +9 -14
- package/dist/artifacts/parts.js +11 -9
- package/dist/artifacts/pipe.d.ts +15 -0
- package/dist/artifacts/pipe.js +71 -0
- package/dist/artifacts/quota.d.ts +36 -0
- package/dist/artifacts/quota.js +44 -0
- package/dist/artifacts/service.d.ts +25 -1
- package/dist/artifacts/service.js +72 -27
- package/dist/blob/fs.js +2 -1
- package/dist/blob/s3.d.ts +6 -2
- package/dist/blob/s3.js +9 -7
- package/dist/blob/types.d.ts +1 -1
- package/dist/blob/types.js +1 -1
- package/dist/core/flow-host.d.ts +0 -1
- package/dist/core/limits.d.ts +11 -35
- package/dist/core/limits.js +5 -73
- package/dist/core/sandbox-routes.js +0 -1
- package/dist/core/turn-manifest.d.ts +1 -2
- package/dist/core/turn-manifest.js +4 -28
- package/dist/execution/memory.d.ts +8 -5
- package/dist/execution/memory.js +8 -6
- package/dist/execution/types.d.ts +1 -6
- package/dist/execution/types.js +0 -5
- package/dist/gates/contract.d.ts +3 -2
- package/dist/gates/contract.js +1 -1
- package/dist/gates/egress-credentials.js +5 -4
- package/dist/gates/egress.d.ts +13 -13
- package/dist/gates/egress.js +19 -21
- package/dist/gates/fixture-model.js +13 -2
- package/dist/gates/handler.d.ts +1 -3
- package/dist/gates/handler.js +4 -3
- package/dist/gates/http-client.d.ts +4 -3
- package/dist/gates/http-client.js +5 -7
- package/dist/gates/http-tool.d.ts +24 -4
- package/dist/gates/http-tool.js +41 -13
- package/dist/gates/in-process.d.ts +2 -1
- package/dist/gates/in-process.js +17 -9
- package/dist/gates/inflight.d.ts +2 -2
- package/dist/gates/inflight.js +3 -2
- package/dist/gates/journal.js +5 -7
- package/dist/gates/mcp-handler.d.ts +4 -3
- package/dist/gates/mcp-handler.js +15 -5
- package/dist/gates/meter.js +6 -5
- package/dist/gates/model-gate.d.ts +11 -2
- package/dist/gates/policy.d.ts +34 -6
- package/dist/gates/policy.js +66 -18
- package/dist/gates/provider-gate.d.ts +22 -0
- package/dist/gates/provider-gate.js +30 -0
- package/dist/gates/tool-calls.d.ts +1 -3
- package/dist/gates/tool-calls.js +2 -3
- package/dist/gates/tool-client.d.ts +1 -1
- package/dist/gates/tool-client.js +5 -6
- package/dist/gates/tool-contract.d.ts +8 -5
- package/dist/gates/tool-contract.js +1 -1
- package/dist/gates/tool-gate.d.ts +18 -7
- package/dist/gates/tool-gate.js +49 -7
- package/dist/harness/calls.d.ts +27 -25
- package/dist/harness/calls.js +40 -46
- package/dist/harness/executors.d.ts +10 -3
- package/dist/harness/executors.js +53 -23
- package/dist/harness/main.js +2 -2
- package/dist/harness/pod.d.ts +2 -2
- package/dist/harness/pod.js +7 -6
- package/dist/harness/run-tokens.d.ts +4 -1
- package/dist/harness/run-tokens.js +6 -2
- package/dist/harness/service.d.ts +17 -14
- package/dist/harness/service.js +21 -35
- package/dist/harness/setup.d.ts +0 -2
- package/dist/harness/setup.js +21 -15
- package/dist/harness/ws-client.d.ts +2 -2
- package/dist/harness/ws-client.js +7 -5
- package/dist/harness/ws-port.d.ts +3 -4
- package/dist/harness/ws-port.js +3 -4
- package/dist/harness-api/artifacts.d.ts +20 -0
- package/dist/harness-api/artifacts.js +478 -0
- package/dist/harness-api/in-process.d.ts +2 -2
- package/dist/harness-api/in-process.js +18 -16
- package/dist/harness-api/record.d.ts +10 -9
- package/dist/harness-api/record.js +113 -157
- package/dist/harness-api/renew.d.ts +1 -1
- package/dist/harness-api/renew.js +2 -2
- package/dist/harness-api/server.d.ts +1 -16
- package/dist/harness-api/server.js +86 -73
- package/dist/harness-api/start.d.ts +27 -5
- package/dist/harness-api/start.js +102 -19
- package/dist/harness-api/tool-journal.d.ts +15 -10
- package/dist/harness-api/tool-journal.js +26 -24
- package/dist/harness-api/workspace.d.ts +0 -4
- package/dist/harness-api/workspace.js +4 -47
- package/dist/harness-api/ws-server.js +10 -10
- package/dist/host/create-host.js +2 -3
- package/dist/host/execution.js +2 -3
- package/dist/host/gates.d.ts +2 -9
- package/dist/host/gates.js +15 -12
- package/dist/host/http.d.ts +2 -4
- package/dist/host/http.js +5 -29
- package/dist/host/main.js +10 -3
- package/dist/host/operate.js +12 -3
- package/dist/host/stack-config.d.ts +11 -0
- package/dist/host/stack-config.js +21 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/infra/index.js +2 -1
- package/dist/infra/readiness.d.ts +0 -2
- package/dist/infra/readiness.js +4 -3
- package/dist/keys/client.d.ts +1 -0
- package/dist/keys/client.js +2 -3
- package/dist/keys/contract.d.ts +0 -2
- package/dist/keys/contract.js +0 -2
- package/dist/keys/egress-ca.d.ts +0 -2
- package/dist/keys/egress-ca.js +2 -3
- package/dist/keys/keys.d.ts +15 -4
- package/dist/keys/keys.js +22 -1
- package/dist/keys/webhooks.d.ts +25 -0
- package/dist/keys/webhooks.js +62 -0
- package/dist/keys/x509.d.ts +8 -4
- package/dist/keys/x509.js +14 -5
- package/dist/management-openapi.json +3043 -1954
- package/dist/mcp/connect.d.ts +35 -26
- package/dist/mcp/connect.js +112 -141
- package/dist/mcp/pool.d.ts +27 -22
- package/dist/mcp/pool.js +34 -48
- package/dist/mcp/preview.d.ts +12 -5
- package/dist/mcp/preview.js +43 -26
- package/dist/mcp/snapshot.d.ts +35 -86
- package/dist/mcp/snapshot.js +93 -135
- package/dist/memory/service.d.ts +97 -0
- package/dist/memory/service.js +335 -0
- package/dist/memory/tool.d.ts +36 -0
- package/dist/memory/tool.js +84 -0
- package/dist/model/auth-store.js +5 -3
- package/dist/model/capabilities.d.ts +1 -1
- package/dist/model/catalog.d.ts +9 -36
- package/dist/model/catalog.js +6 -33
- package/dist/model/descriptor.d.ts +51 -0
- package/dist/model/descriptor.js +83 -0
- package/dist/model/models.d.ts +0 -3
- package/dist/model/models.js +3 -5
- package/dist/model/native-blocks.js +1 -1
- package/dist/model/pi-model.d.ts +16 -5
- package/dist/model/pi-model.js +86 -105
- package/dist/openapi.json +13653 -9986
- package/dist/reads/cursor.js +3 -1
- package/dist/reads/types.d.ts +3 -3
- package/dist/record/agent.d.ts +27 -0
- package/dist/record/agent.js +46 -0
- package/dist/record/append.d.ts +34 -2
- package/dist/record/append.js +50 -1
- package/dist/record/index.d.ts +2 -2
- package/dist/record/index.js +2 -2
- package/dist/redact.d.ts +1 -1
- package/dist/redact.js +3 -2
- package/dist/sandbox/egress-token.d.ts +3 -3
- package/dist/sandbox/egress-token.js +3 -3
- package/dist/sandbox/join.js +8 -7
- package/dist/sandbox/manager.d.ts +41 -41
- package/dist/sandbox/manager.js +112 -44
- package/dist/sandbox/placement.d.ts +2 -2
- package/dist/sandbox/placement.js +7 -10
- package/dist/sandbox/pods/client.d.ts +1 -10
- package/dist/sandbox/pods/client.js +8 -4
- package/dist/sandbox/pods/lifecycle.d.ts +25 -17
- package/dist/sandbox/pods/lifecycle.js +51 -29
- package/dist/sandbox/pods/network-gate.d.ts +4 -5
- package/dist/sandbox/pods/network-gate.js +7 -7
- package/dist/sandbox/pods/reconcile.js +14 -3
- package/dist/sandbox/pods/spec.js +8 -5
- package/dist/sandbox/policy.d.ts +7 -1
- package/dist/sandbox/policy.js +10 -3
- package/dist/sandbox/resolve.d.ts +11 -6
- package/dist/sandbox/resolve.js +19 -9
- package/dist/sandbox/setup.d.ts +6 -2
- package/dist/sandbox/setup.js +47 -14
- package/dist/sandbox/share.d.ts +5 -14
- package/dist/sandbox/share.js +5 -34
- package/dist/sandbox/skills.d.ts +7 -13
- package/dist/sandbox/skills.js +16 -31
- package/dist/sandbox/tenant-config.d.ts +2 -2
- package/dist/sandbox/tenant-config.js +4 -3
- package/dist/sandbox/tools.d.ts +7 -1
- package/dist/sandbox/tools.js +26 -26
- package/dist/sandbox/types.d.ts +10 -3
- package/dist/sandbox/types.js +9 -0
- package/dist/store/postgres/connect.d.ts +6 -5
- package/dist/store/postgres/connect.js +14 -11
- package/dist/store/postgres/control.js +13 -13
- package/dist/store/postgres/drizzle/0028_artifact_write_keys.sql +2 -0
- package/dist/store/postgres/drizzle/0029_protocol_15.sql +11 -0
- package/dist/store/postgres/drizzle/0030_protocol_15_runtime_block.sql +11 -0
- package/dist/store/postgres/drizzle/0031_protocol_15_mcp_snapshot.sql +8 -0
- package/dist/store/postgres/drizzle/0032_agents.sql +54 -0
- package/dist/store/postgres/drizzle/0033_agent_versions.sql +7 -0
- package/dist/store/postgres/drizzle/0034_protocol_17_session_queue.sql +13 -0
- package/dist/store/postgres/drizzle/0035_t4_triggers.sql +41 -0
- package/dist/store/postgres/drizzle/0036_t5_memories.sql +30 -0
- package/dist/store/postgres/drizzle/meta/_journal.json +63 -0
- package/dist/store/postgres/reads.js +17 -82
- package/dist/store/postgres/record-writer.d.ts +4 -4
- package/dist/store/postgres/record-writer.js +9 -9
- package/dist/store/postgres/schema.d.ts +1382 -151
- package/dist/store/postgres/schema.js +191 -37
- package/dist/store/postgres/store.js +384 -105
- package/dist/store/postgres/tenant.js +1 -2
- package/dist/store/types.d.ts +172 -57
- package/dist/store/types.js +0 -1
- package/dist/streams/relay/core.d.ts +3 -3
- package/dist/streams/relay/core.js +9 -10
- package/dist/tenant/advance.js +41 -39
- package/dist/tenant/agent-manifests.d.ts +72 -0
- package/dist/tenant/agent-manifests.js +359 -0
- package/dist/tenant/agent-versions.d.ts +126 -0
- package/dist/tenant/agent-versions.js +389 -0
- package/dist/tenant/agents.d.ts +230 -0
- package/dist/tenant/{environments.js → agents.js} +493 -328
- package/dist/tenant/auth.d.ts +1 -1
- package/dist/tenant/auth.js +3 -3
- package/dist/tenant/commands.d.ts +63 -2
- package/dist/tenant/commands.js +240 -90
- package/dist/tenant/context.d.ts +57 -33
- package/dist/tenant/context.js +6 -2
- package/dist/tenant/definition-files.d.ts +25 -4
- package/dist/tenant/definition-files.js +85 -47
- package/dist/tenant/effects.js +15 -51
- package/dist/tenant/ephemeral.js +2 -1
- package/dist/tenant/history.d.ts +1 -1
- package/dist/tenant/history.js +1 -1
- package/dist/tenant/host-token.d.ts +3 -3
- package/dist/tenant/host-token.js +11 -10
- package/dist/tenant/http.d.ts +5 -8
- package/dist/tenant/http.js +9 -0
- package/dist/tenant/identity-file.d.ts +29 -6
- package/dist/tenant/identity-file.js +45 -15
- package/dist/tenant/issuers.d.ts +5 -5
- package/dist/tenant/issuers.js +34 -26
- package/dist/tenant/jwt.d.ts +8 -2
- package/dist/tenant/jwt.js +10 -2
- package/dist/tenant/limits.d.ts +87 -0
- package/dist/tenant/limits.js +172 -0
- package/dist/tenant/memories.d.ts +38 -0
- package/dist/tenant/memories.js +119 -0
- package/dist/tenant/module.d.ts +4 -1
- package/dist/tenant/module.js +9 -8
- package/dist/tenant/outbound.d.ts +11 -14
- package/dist/tenant/outbound.js +10 -15
- package/dist/tenant/reset.js +2 -2
- package/dist/tenant/run-grants.d.ts +6 -0
- package/dist/tenant/run-grants.js +7 -2
- package/dist/tenant/run-token.d.ts +0 -4
- package/dist/tenant/run-token.js +6 -11
- package/dist/tenant/runtime-limits.d.ts +24 -0
- package/dist/tenant/runtime-limits.js +27 -0
- package/dist/tenant/runtime.d.ts +1 -1
- package/dist/tenant/runtime.js +38 -43
- package/dist/tenant/session-streams.js +7 -6
- package/dist/tenant/session.d.ts +1 -1
- package/dist/tenant/session.js +1 -1
- package/dist/tenant/sessions.d.ts +28 -45
- package/dist/tenant/sessions.js +89 -209
- package/dist/tenant/signing-keys.d.ts +1 -1
- package/dist/tenant/signing-keys.js +5 -6
- package/dist/tenant/status.js +10 -10
- package/dist/tenant/streams.js +18 -20
- package/dist/tenant/sweep.d.ts +1 -21
- package/dist/tenant/sweep.js +51 -51
- package/dist/tenant/transcript.d.ts +70 -23
- package/dist/tenant/transcript.js +28 -22
- package/dist/tenant/triggers.d.ts +143 -0
- package/dist/tenant/triggers.js +715 -0
- package/dist/tenant/turn-timing.d.ts +11 -1
- package/dist/tenant/turn-timing.js +3 -1
- package/dist/tenant/types.d.ts +9 -14
- package/dist/tenant/worker.d.ts +4 -10
- package/dist/tenant/worker.js +10 -14
- package/dist/traces/ids.js +5 -1
- package/dist/traces/map.d.ts +10 -7
- package/dist/traces/map.js +16 -12
- package/dist/traces/otlp.d.ts +3 -3
- package/dist/traces/otlp.js +5 -3
- package/dist/traces/projector.d.ts +9 -4
- package/dist/traces/projector.js +13 -7
- package/dist/traces/read.js +6 -1
- package/dist/tuning.d.ts +390 -0
- package/dist/tuning.js +677 -0
- package/dist/vault/headers.js +4 -2
- package/dist/vault/service.d.ts +13 -8
- package/dist/vault/service.js +61 -17
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +13 -12
- package/dist/api/http/routes/environment-manifests.d.ts +0 -9
- package/dist/api/http/routes/environment-manifests.js +0 -118
- package/dist/api/http/routes/environments.d.ts +0 -11
- package/dist/api/http/routes/environments.js +0 -332
- package/dist/artifacts/export.d.ts +0 -8
- package/dist/artifacts/export.js +0 -204
- package/dist/artifacts/media-types.d.ts +0 -30
- package/dist/artifacts/media-types.js +0 -137
- package/dist/artifacts/workspace.d.ts +0 -60
- package/dist/artifacts/workspace.js +0 -45
- package/dist/media.d.ts +0 -10
- package/dist/media.js +0 -58
- package/dist/record/environment.d.ts +0 -25
- package/dist/record/environment.js +0 -44
- package/dist/sandbox/runtime-tools.d.ts +0 -9
- package/dist/sandbox/runtime-tools.js +0 -16
- package/dist/sandbox/session-sandbox.d.ts +0 -16
- package/dist/sandbox/session-sandbox.js +0 -77
- package/dist/tenant/artifact-tool.d.ts +0 -13
- package/dist/tenant/artifact-tool.js +0 -243
- package/dist/tenant/environment-manifests.d.ts +0 -57
- package/dist/tenant/environment-manifests.js +0 -200
- package/dist/tenant/environments.d.ts +0 -174
- package/dist/tenant/skill-tool.d.ts +0 -20
- package/dist/tenant/skill-tool.js +0 -67
- package/dist/tenant/tool-results.d.ts +0 -57
- package/dist/tenant/tool-results.js +0 -298
- package/dist/tenant/tool-search.d.ts +0 -39
- package/dist/tenant/tool-search.js +0 -103
package/dist/tenant/sweep.js
CHANGED
|
@@ -8,19 +8,19 @@
|
|
|
8
8
|
* a delivery after commit that failed, or that a crash between the commit and the send cut
|
|
9
9
|
* off. The first pass on this process takes every row, so a previous process's are not
|
|
10
10
|
* left waiting; later passes take those whose delivery after commit failed and those older
|
|
11
|
-
* than `
|
|
12
|
-
* `
|
|
11
|
+
* than `sweep.outboxGraceMs` (Host tuning) (the database's clock), batch after batch within
|
|
12
|
+
* `sweep.drainBudgetMs`. Each row carries the idempotency key it was first sent with, so a
|
|
13
13
|
* request the execution did accept before the crash, or one still being sent after its
|
|
14
14
|
* commit, runs once. Rows are delivered one by one: a row that fails is retried with
|
|
15
|
-
* backoff and parked after `
|
|
15
|
+
* backoff and parked after `sweep.outboxAttempts` (`deliverOutbox`), and no delivery fails
|
|
16
16
|
* the step.
|
|
17
17
|
* 2. **Linked agents.** Pending workflow `agent` effects whose linked turn already settled
|
|
18
18
|
* are completed and the workflow is woken. A linked turn's settle does both in its own
|
|
19
19
|
* transaction; this is the backstop for one that settle left pending, such as an effect
|
|
20
20
|
* an older Runtime wrote.
|
|
21
21
|
* 3. **Orphaned sessions.** On this process's first pass for the Tenant, then at most every
|
|
22
|
-
* `
|
|
23
|
-
* expired, are woken with reason `recover`, page by page within `
|
|
22
|
+
* `sweep.orphanScanMs`: `running` or `runnable` sessions with no owner, or an owner whose lease
|
|
23
|
+
* expired, are woken with reason `recover`, page by page within `sweep.drainBudgetMs`; a scan
|
|
24
24
|
* the budget cut short goes on at the next pass. Neither a lost wake (step 1) nor a Worker
|
|
25
25
|
* that died mid-advance (the execution retries that advance, which takes over, §11.4)
|
|
26
26
|
* needs it: it is the backstop for what the execution itself lost or ended without an
|
|
@@ -33,8 +33,10 @@
|
|
|
33
33
|
* workspaces). Idle MCP connections of the in-process harness are closed. As often as the
|
|
34
34
|
* orphan scan, pod Environments whose change stalled get a reconcile (`reconcileStalePods`).
|
|
35
35
|
* Environments unused for their `lifecycle.deleteAfter` are deleted
|
|
36
|
-
* (`
|
|
37
|
-
*
|
|
36
|
+
* (`sweepUnusedAgents`).
|
|
37
|
+
* Triggers (track T4, `triggers.ts`): on this process's first pass every active trigger's
|
|
38
|
+
* timer is armed, later overdue ones only, and runs past `triggerRunRetentionMs` are deleted.
|
|
39
|
+
* 5. **Control signals.** Signals on the control bus older than `sweep.signalRetentionMs` are
|
|
38
40
|
* deleted: followers read back only the last two minutes (`store/postgres/control.ts`).
|
|
39
41
|
* 6. **Hooks.** Callbacks registered with `ctx.onSweep`.
|
|
40
42
|
*
|
|
@@ -43,30 +45,25 @@
|
|
|
43
45
|
* step does not stop the others; the first error is rethrown at the end so the execution
|
|
44
46
|
* reports it.
|
|
45
47
|
*/
|
|
46
|
-
import {
|
|
48
|
+
import { sweepUnusedAgents } from "./agents.js";
|
|
49
|
+
import { reconcileTriggers } from "./triggers.js";
|
|
47
50
|
import { sweepPendingSeeds } from "../artifacts/disk.js";
|
|
48
51
|
import { pendingAgentEffects, reconcilePendingAgentEffect, } from "../core/flow-host.js";
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
*
|
|
54
|
-
* already failed (then it is due at once): longer than that delivery can take with
|
|
55
|
-
* retries, so the sweep does not send again, and double the load on, an execution that is
|
|
56
|
-
*
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
*
|
|
61
|
-
* Tenant
|
|
62
|
-
|
|
63
|
-
export const ORPHAN_SCAN_MS = 60_000;
|
|
64
|
-
/**
|
|
65
|
-
* How long one pass may spend draining the outbox, and paging through orphaned sessions.
|
|
66
|
-
* A backlog is worked off over several passes rather than holding one (and with it the
|
|
67
|
-
* Tenant's sweep object in the execution) for long.
|
|
52
|
+
import { hostTuning } from "../tuning.js";
|
|
53
|
+
import { sweepStartChecks } from "./agent-versions.js";
|
|
54
|
+
/*
|
|
55
|
+
* The sweep's timings are the Host tuning's `sweep` group (`tuning.ts`):
|
|
56
|
+
* - `outboxGraceMs`: how old an outbox row is before the sweep delivers it, unless its delivery
|
|
57
|
+
* after commit already failed (then it is due at once): longer than that delivery can take with
|
|
58
|
+
* its retries, so the sweep does not send again, and double the load on, an execution that is
|
|
59
|
+
* only slow. Sending one twice is harmless either way (the idempotency key).
|
|
60
|
+
* - `orphanScanMs`: how often the orphan scan, and the stale pod sandbox check, run after the
|
|
61
|
+
* first pass of a Tenant opened on this process.
|
|
62
|
+
* - `drainBudgetMs`: how long one pass may spend draining the outbox, and paging through
|
|
63
|
+
* orphaned sessions. A backlog is worked off over several passes rather than holding one (and
|
|
64
|
+
* with it the Tenant's sweep object in the execution) for long.
|
|
65
|
+
* - `batchSize`, `signalRetentionMs`, `outboxAttempts`, `outboxRetry`, `stalePodMs`.
|
|
68
66
|
*/
|
|
69
|
-
export const DRAIN_BUDGET_MS = 2000;
|
|
70
67
|
/**
|
|
71
68
|
* Each open Tenant's sweep state on this process: when its last orphan scan finished, the
|
|
72
69
|
* last session id of one that ran out of budget, which the next pass goes on from, and when
|
|
@@ -82,10 +79,10 @@ export async function sweep(ctx) {
|
|
|
82
79
|
passes.set(ctx, pass);
|
|
83
80
|
const scanOrphans = pass.orphansAt === undefined ||
|
|
84
81
|
pass.orphansAfter !== undefined ||
|
|
85
|
-
now.getTime() - pass.orphansAt >=
|
|
86
|
-
const checkPods = pass.podsAt === undefined || now.getTime() - pass.podsAt >=
|
|
82
|
+
now.getTime() - pass.orphansAt >= hostTuning().sweep.orphanScanMs;
|
|
83
|
+
const checkPods = pass.podsAt === undefined || now.getTime() - pass.podsAt >= hostTuning().sweep.orphanScanMs;
|
|
87
84
|
const steps = [
|
|
88
|
-
["outbox", () => deliverOutbox(ctx, first ? 0 :
|
|
85
|
+
["outbox", () => deliverOutbox(ctx, first ? 0 : hostTuning().sweep.outboxGraceMs)],
|
|
89
86
|
["linked", () => reconcileLinkedAgents(ctx)],
|
|
90
87
|
...(scanOrphans
|
|
91
88
|
? [
|
|
@@ -120,14 +117,19 @@ export async function sweep(ctx) {
|
|
|
120
117
|
]
|
|
121
118
|
: []),
|
|
122
119
|
// Environments unused for their `lifecycle.deleteAfter`: one query when none is due.
|
|
123
|
-
["
|
|
120
|
+
["agents", () => sweepUnusedAgents(ctx, now.getTime())],
|
|
121
|
+
// Pods slower than `tenant.upgradeStartMs` to start on a new version go back (track T3).
|
|
122
|
+
["starts", () => sweepStartChecks(ctx, now.getTime())],
|
|
123
|
+
// Triggers (track T4): every active one armed on this process's first pass, overdue ones after;
|
|
124
|
+
// runs past their retention deleted.
|
|
125
|
+
["triggers", () => reconcileTriggers(ctx, first)],
|
|
124
126
|
// Seeds of new volumes whose engine is connected and no process copies (R2d step 3).
|
|
125
127
|
["seeds", () => sweepPendingSeeds(ctx)],
|
|
126
128
|
// A harness elsewhere closes its own idle MCP connections.
|
|
127
129
|
["mcp", async () => ctx.mcp?.sweep()],
|
|
128
130
|
[
|
|
129
131
|
"signals",
|
|
130
|
-
() => ctx.store.tx((t) => t.pruneSignals(new Date(now.getTime() -
|
|
132
|
+
() => ctx.store.tx((t) => t.pruneSignals(new Date(now.getTime() - hostTuning().sweep.signalRetentionMs))),
|
|
131
133
|
],
|
|
132
134
|
...[...ctx.sweepHooks].map((hook) => ["hook", hook]),
|
|
133
135
|
];
|
|
@@ -149,30 +151,26 @@ export async function sweep(ctx) {
|
|
|
149
151
|
if (failure)
|
|
150
152
|
throw failure.error;
|
|
151
153
|
}
|
|
152
|
-
/** Failed deliveries after which the sweep parks an outbox row (`Tx.failOutbox`). */
|
|
153
|
-
export const MAX_OUTBOX_ATTEMPTS = 10;
|
|
154
|
-
/** How long after its first failed delivery the sweep tries a row again; doubled each time. */
|
|
155
|
-
const RETRY_MS = 5000;
|
|
156
|
-
const RETRY_MAX_MS = 10 * 60_000;
|
|
157
154
|
/**
|
|
158
155
|
* Deliver the outbox rows that are due (`Tx.pendingOutbox`: older than `graceMs`, or whose
|
|
159
156
|
* delivery failed), oldest first, batch after batch until none is left or `budgetMs` is
|
|
160
157
|
* spent, and delete the delivered ones. Each row is delivered on its own: one that fails
|
|
161
158
|
* (Restate refuses it, or a Runtime that does not know a wake's reason) is tried again later,
|
|
162
|
-
* with backoff, so it never holds back the rows behind it, and after `
|
|
159
|
+
* with backoff, so it never holds back the rows behind it, and after `sweep.outboxAttempts`
|
|
163
160
|
* failures it is parked: logged once, at error, and kept in the outbox for an operator. A
|
|
164
161
|
* parked wake's session is still re-woken by the orphan scan while it is runnable, and a
|
|
165
162
|
* parked sandbox signal's pod by the stale pod check. A row the Tenant declines (it is
|
|
166
163
|
* closing) stays as it is, and ends the drain. Never throws for a delivery; returns the rows
|
|
167
164
|
* delivered.
|
|
168
165
|
*/
|
|
169
|
-
export async function deliverOutbox(ctx, graceMs = 0, budgetMs =
|
|
166
|
+
export async function deliverOutbox(ctx, graceMs = 0, budgetMs = hostTuning().sweep.drainBudgetMs) {
|
|
170
167
|
const deadline = Date.now() + budgetMs;
|
|
171
168
|
const delivered = [];
|
|
169
|
+
const batchSize = hostTuning().sweep.batchSize;
|
|
172
170
|
for (;;) {
|
|
173
|
-
const pending = await ctx.store.tx((t) => t.pendingOutbox(graceMs,
|
|
171
|
+
const pending = await ctx.store.tx((t) => t.pendingOutbox(graceMs, batchSize));
|
|
174
172
|
const batch = [];
|
|
175
|
-
let done = pending.length <
|
|
173
|
+
let done = pending.length < batchSize;
|
|
176
174
|
try {
|
|
177
175
|
for (const row of pending) {
|
|
178
176
|
if (Date.now() >= deadline) {
|
|
@@ -206,8 +204,11 @@ export async function deliverOutbox(ctx, graceMs = 0, budgetMs = DRAIN_BUDGET_MS
|
|
|
206
204
|
/** Records a failed delivery of `row`: retried with backoff, parked after the last attempt. */
|
|
207
205
|
async function failed(ctx, row, error) {
|
|
208
206
|
const attempts = row.attempts + 1;
|
|
209
|
-
|
|
210
|
-
|
|
207
|
+
// Parked after `sweep.outboxAttempts` failed deliveries (`Tx.failOutbox`); tried again after
|
|
208
|
+
// `outboxRetry.minMs`, doubled each time.
|
|
209
|
+
const { outboxAttempts, outboxRetry } = hostTuning().sweep;
|
|
210
|
+
const park = attempts >= outboxAttempts;
|
|
211
|
+
const retryInMs = Math.min(outboxRetry.minMs * 2 ** (attempts - 1), outboxRetry.maxMs);
|
|
211
212
|
await ctx.store.tx((t) => t.failOutbox(row, { retryInMs, park }));
|
|
212
213
|
const { request } = row;
|
|
213
214
|
const fields = {
|
|
@@ -235,29 +236,28 @@ export async function reconcileLinkedAgents(ctx) {
|
|
|
235
236
|
* after `after`, until none is left or `budgetMs` is spent. Returns the ids woken, and the last
|
|
236
237
|
* id when the budget ran out first (`next`, where the next scan goes on).
|
|
237
238
|
*/
|
|
238
|
-
export async function wakeOrphanedSessions(ctx, now = new Date(), after, budgetMs =
|
|
239
|
+
export async function wakeOrphanedSessions(ctx, now = new Date(), after, budgetMs = hostTuning().sweep.drainBudgetMs) {
|
|
239
240
|
const deadline = Date.now() + budgetMs;
|
|
240
241
|
const woken = [];
|
|
242
|
+
const batchSize = hostTuning().sweep.batchSize;
|
|
241
243
|
let cursor = after;
|
|
242
244
|
for (;;) {
|
|
243
|
-
const page = await ctx.store.tx((t) => t.orphanedSessions(now,
|
|
245
|
+
const page = await ctx.store.tx((t) => t.orphanedSessions(now, batchSize, cursor));
|
|
244
246
|
for (const session of page) {
|
|
245
247
|
await ctx.wake(session.id, { reason: "recover" });
|
|
246
248
|
woken.push(session.id);
|
|
247
249
|
cursor = session.id;
|
|
248
250
|
}
|
|
249
|
-
if (page.length <
|
|
251
|
+
if (page.length < batchSize)
|
|
250
252
|
return { woken };
|
|
251
253
|
if (Date.now() >= deadline)
|
|
252
254
|
return { woken, next: cursor };
|
|
253
255
|
}
|
|
254
256
|
}
|
|
255
|
-
/** A pod sandbox in a change this long without a reconcile gets one from the sweep. */
|
|
256
|
-
const STALE_POD_MS = 60_000;
|
|
257
257
|
/**
|
|
258
258
|
* Pod sandboxes (F7.2) whose change has not finished (creating, deleting, an old volume still
|
|
259
259
|
* to delete, an expiry not yet recorded), or that should run but whose engine is not connected,
|
|
260
|
-
* and whose row has not moved for a minute, get a reconcile: a pod or volume deleted outside
|
|
260
|
+
* and whose row has not moved for `sweep.stalePodMs` (a minute), get a reconcile: a pod or volume deleted outside
|
|
261
261
|
* the Runtime is found, and a change goes on whose reconcile the execution itself lost (its
|
|
262
262
|
* retry timer, an invocation an operator killed, Restate's state wiped) or whose outbox row
|
|
263
263
|
* was parked. A reconcile a commit asked for is never lost: it is in the outbox.
|
|
@@ -267,7 +267,7 @@ async function reconcileStalePods(ctx, now) {
|
|
|
267
267
|
return;
|
|
268
268
|
const stale = await ctx.store.tx(async (t) => (await t.listEnvironments()).filter((row) => {
|
|
269
269
|
const pod = row.pod;
|
|
270
|
-
if (!pod || now.getTime() - Date.parse(row.updatedAt) <
|
|
270
|
+
if (!pod || now.getTime() - Date.parse(row.updatedAt) < hostTuning().sweep.stalePodMs)
|
|
271
271
|
return false;
|
|
272
272
|
return (pod.desired === "deleted" ||
|
|
273
273
|
pod.retiring !== undefined ||
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
import type { HostEffect } from "@nylorun/harness/run";
|
|
7
7
|
import type { PluginLabel } from "@nylorun/core/define";
|
|
8
8
|
import type { TOOL_CALL_KINDS, TOOL_CALL_STATUSES } from "@nylorun/core/contracts";
|
|
9
|
+
import { type CompactionFacts } from "@nylorun/core/harness-api";
|
|
10
|
+
import type { Tx } from "../store/types.js";
|
|
9
11
|
export type ToolCallStatus = (typeof TOOL_CALL_STATUSES)[number];
|
|
10
12
|
export type ToolCallKind = (typeof TOOL_CALL_KINDS)[number];
|
|
11
13
|
/** The model's tool call id and the harness invocation, for tool effects. */
|
|
@@ -51,25 +53,52 @@ export declare function assistantMessage(request: HostEffect, value: unknown): {
|
|
|
51
53
|
usage?: object | undefined;
|
|
52
54
|
} | undefined;
|
|
53
55
|
/**
|
|
54
|
-
* `context.compacted` for a
|
|
55
|
-
*
|
|
56
|
-
*
|
|
56
|
+
* `context.compacted` for a compaction a harness reported with its transcript edit (Q4, protocol
|
|
57
|
+
* 15): its facts, the last summary call's step and model facts, and the agent. Every summary
|
|
58
|
+
* effect it names must be a completed, successful model call of turn `turnId` made for a summary
|
|
59
|
+
* (`purpose: "summary"`); otherwise the edit is refused (`invalid`).
|
|
57
60
|
*/
|
|
58
|
-
export declare function contextCompacted(
|
|
61
|
+
export declare function contextCompacted(t: Tx, sessionId: string, turnId: string | null, facts: CompactionFacts): Promise<{
|
|
59
62
|
agent: import("@nylorun/core/define").AgentRef;
|
|
60
63
|
invocationId?: string | undefined;
|
|
61
64
|
trigger: "overflow" | "threshold";
|
|
62
65
|
tokensBefore: number;
|
|
63
66
|
tokensAfter: number;
|
|
64
|
-
|
|
67
|
+
effectId: string;
|
|
68
|
+
durationMs?: number | undefined;
|
|
69
|
+
gate?: {
|
|
70
|
+
startedAt: string;
|
|
71
|
+
endedAt: string;
|
|
72
|
+
} | undefined;
|
|
73
|
+
firstTokenMs?: number | undefined;
|
|
74
|
+
meteredUsage?: {
|
|
75
|
+
inputTokens: number;
|
|
76
|
+
outputTokens: number;
|
|
77
|
+
totalTokens: number;
|
|
78
|
+
cachedTokens?: number | undefined;
|
|
79
|
+
costUsd?: number | undefined;
|
|
80
|
+
} | undefined;
|
|
65
81
|
} | {
|
|
66
82
|
agent?: undefined;
|
|
67
83
|
invocationId?: string | undefined;
|
|
68
84
|
trigger: "overflow" | "threshold";
|
|
69
85
|
tokensBefore: number;
|
|
70
86
|
tokensAfter: number;
|
|
71
|
-
|
|
72
|
-
|
|
87
|
+
effectId: string;
|
|
88
|
+
durationMs?: number | undefined;
|
|
89
|
+
gate?: {
|
|
90
|
+
startedAt: string;
|
|
91
|
+
endedAt: string;
|
|
92
|
+
} | undefined;
|
|
93
|
+
firstTokenMs?: number | undefined;
|
|
94
|
+
meteredUsage?: {
|
|
95
|
+
inputTokens: number;
|
|
96
|
+
outputTokens: number;
|
|
97
|
+
totalTokens: number;
|
|
98
|
+
cachedTokens?: number | undefined;
|
|
99
|
+
costUsd?: number | undefined;
|
|
100
|
+
} | undefined;
|
|
101
|
+
}>;
|
|
73
102
|
/** `model.failed` for a model effect that completed with a failure outcome (Model Calls §6.4). */
|
|
74
103
|
export declare function modelFailed(request: HostEffect, value: unknown): {
|
|
75
104
|
agent: import("@nylorun/core/define").AgentRef;
|
|
@@ -137,6 +166,8 @@ export interface ToolCallFacts {
|
|
|
137
166
|
readonly status: ToolCallStatus;
|
|
138
167
|
readonly kind?: ToolCallKind;
|
|
139
168
|
readonly server?: string;
|
|
169
|
+
/** The tool's identity: an MCP tool's name on `server`, an HTTP tool's declared name. */
|
|
170
|
+
readonly tool?: string;
|
|
140
171
|
readonly skill?: string;
|
|
141
172
|
readonly plugin?: PluginLabel;
|
|
142
173
|
readonly attempts?: number;
|
|
@@ -161,8 +192,9 @@ export declare function toolCompleted(request: HostEffect, value: unknown, facts
|
|
|
161
192
|
redacted: number;
|
|
162
193
|
toolName: string;
|
|
163
194
|
status?: "cancelled" | "completed" | "failed" | undefined;
|
|
164
|
-
kind?: "harness" | "http" | "mcp" | "
|
|
195
|
+
kind?: "harness" | "http" | "mcp" | "runtime" | "sandbox" | undefined;
|
|
165
196
|
server?: string | undefined;
|
|
197
|
+
tool?: string | undefined;
|
|
166
198
|
skill?: string | undefined;
|
|
167
199
|
plugin?: PluginLabel | undefined;
|
|
168
200
|
attempts?: number | undefined;
|
|
@@ -182,8 +214,9 @@ export declare function toolCompleted(request: HostEffect, value: unknown, facts
|
|
|
182
214
|
redacted: number;
|
|
183
215
|
toolName: string;
|
|
184
216
|
status?: "cancelled" | "completed" | "failed" | undefined;
|
|
185
|
-
kind?: "harness" | "http" | "mcp" | "
|
|
217
|
+
kind?: "harness" | "http" | "mcp" | "runtime" | "sandbox" | undefined;
|
|
186
218
|
server?: string | undefined;
|
|
219
|
+
tool?: string | undefined;
|
|
187
220
|
skill?: string | undefined;
|
|
188
221
|
plugin?: PluginLabel | undefined;
|
|
189
222
|
attempts?: number | undefined;
|
|
@@ -203,8 +236,9 @@ export declare function toolCompleted(request: HostEffect, value: unknown, facts
|
|
|
203
236
|
redacted?: undefined;
|
|
204
237
|
toolName: string;
|
|
205
238
|
status?: "cancelled" | "completed" | "failed" | undefined;
|
|
206
|
-
kind?: "harness" | "http" | "mcp" | "
|
|
239
|
+
kind?: "harness" | "http" | "mcp" | "runtime" | "sandbox" | undefined;
|
|
207
240
|
server?: string | undefined;
|
|
241
|
+
tool?: string | undefined;
|
|
208
242
|
skill?: string | undefined;
|
|
209
243
|
plugin?: PluginLabel | undefined;
|
|
210
244
|
attempts?: number | undefined;
|
|
@@ -224,8 +258,9 @@ export declare function toolCompleted(request: HostEffect, value: unknown, facts
|
|
|
224
258
|
redacted?: undefined;
|
|
225
259
|
toolName: string;
|
|
226
260
|
status?: "cancelled" | "completed" | "failed" | undefined;
|
|
227
|
-
kind?: "harness" | "http" | "mcp" | "
|
|
261
|
+
kind?: "harness" | "http" | "mcp" | "runtime" | "sandbox" | undefined;
|
|
228
262
|
server?: string | undefined;
|
|
263
|
+
tool?: string | undefined;
|
|
229
264
|
skill?: string | undefined;
|
|
230
265
|
plugin?: PluginLabel | undefined;
|
|
231
266
|
attempts?: number | undefined;
|
|
@@ -240,8 +275,9 @@ export declare function toolCompleted(request: HostEffect, value: unknown, facts
|
|
|
240
275
|
redacted: number;
|
|
241
276
|
toolName: string;
|
|
242
277
|
status?: "cancelled" | "completed" | "failed" | undefined;
|
|
243
|
-
kind?: "harness" | "http" | "mcp" | "
|
|
278
|
+
kind?: "harness" | "http" | "mcp" | "runtime" | "sandbox" | undefined;
|
|
244
279
|
server?: string | undefined;
|
|
280
|
+
tool?: string | undefined;
|
|
245
281
|
skill?: string | undefined;
|
|
246
282
|
plugin?: PluginLabel | undefined;
|
|
247
283
|
attempts?: number | undefined;
|
|
@@ -256,8 +292,9 @@ export declare function toolCompleted(request: HostEffect, value: unknown, facts
|
|
|
256
292
|
redacted: number;
|
|
257
293
|
toolName: string;
|
|
258
294
|
status?: "cancelled" | "completed" | "failed" | undefined;
|
|
259
|
-
kind?: "harness" | "http" | "mcp" | "
|
|
295
|
+
kind?: "harness" | "http" | "mcp" | "runtime" | "sandbox" | undefined;
|
|
260
296
|
server?: string | undefined;
|
|
297
|
+
tool?: string | undefined;
|
|
261
298
|
skill?: string | undefined;
|
|
262
299
|
plugin?: PluginLabel | undefined;
|
|
263
300
|
attempts?: number | undefined;
|
|
@@ -272,8 +309,9 @@ export declare function toolCompleted(request: HostEffect, value: unknown, facts
|
|
|
272
309
|
redacted?: undefined;
|
|
273
310
|
toolName: string;
|
|
274
311
|
status?: "cancelled" | "completed" | "failed" | undefined;
|
|
275
|
-
kind?: "harness" | "http" | "mcp" | "
|
|
312
|
+
kind?: "harness" | "http" | "mcp" | "runtime" | "sandbox" | undefined;
|
|
276
313
|
server?: string | undefined;
|
|
314
|
+
tool?: string | undefined;
|
|
277
315
|
skill?: string | undefined;
|
|
278
316
|
plugin?: PluginLabel | undefined;
|
|
279
317
|
attempts?: number | undefined;
|
|
@@ -288,8 +326,9 @@ export declare function toolCompleted(request: HostEffect, value: unknown, facts
|
|
|
288
326
|
redacted?: undefined;
|
|
289
327
|
toolName: string;
|
|
290
328
|
status?: "cancelled" | "completed" | "failed" | undefined;
|
|
291
|
-
kind?: "harness" | "http" | "mcp" | "
|
|
329
|
+
kind?: "harness" | "http" | "mcp" | "runtime" | "sandbox" | undefined;
|
|
292
330
|
server?: string | undefined;
|
|
331
|
+
tool?: string | undefined;
|
|
293
332
|
skill?: string | undefined;
|
|
294
333
|
plugin?: PluginLabel | undefined;
|
|
295
334
|
attempts?: number | undefined;
|
|
@@ -311,8 +350,9 @@ export declare function toolCompleted(request: HostEffect, value: unknown, facts
|
|
|
311
350
|
redacted: number;
|
|
312
351
|
toolName: string;
|
|
313
352
|
status?: "cancelled" | "completed" | "failed" | undefined;
|
|
314
|
-
kind?: "harness" | "http" | "mcp" | "
|
|
353
|
+
kind?: "harness" | "http" | "mcp" | "runtime" | "sandbox" | undefined;
|
|
315
354
|
server?: string | undefined;
|
|
355
|
+
tool?: string | undefined;
|
|
316
356
|
skill?: string | undefined;
|
|
317
357
|
plugin?: PluginLabel | undefined;
|
|
318
358
|
attempts?: number | undefined;
|
|
@@ -334,8 +374,9 @@ export declare function toolCompleted(request: HostEffect, value: unknown, facts
|
|
|
334
374
|
redacted: number;
|
|
335
375
|
toolName: string;
|
|
336
376
|
status?: "cancelled" | "completed" | "failed" | undefined;
|
|
337
|
-
kind?: "harness" | "http" | "mcp" | "
|
|
377
|
+
kind?: "harness" | "http" | "mcp" | "runtime" | "sandbox" | undefined;
|
|
338
378
|
server?: string | undefined;
|
|
379
|
+
tool?: string | undefined;
|
|
339
380
|
skill?: string | undefined;
|
|
340
381
|
plugin?: PluginLabel | undefined;
|
|
341
382
|
attempts?: number | undefined;
|
|
@@ -357,8 +398,9 @@ export declare function toolCompleted(request: HostEffect, value: unknown, facts
|
|
|
357
398
|
redacted?: undefined;
|
|
358
399
|
toolName: string;
|
|
359
400
|
status?: "cancelled" | "completed" | "failed" | undefined;
|
|
360
|
-
kind?: "harness" | "http" | "mcp" | "
|
|
401
|
+
kind?: "harness" | "http" | "mcp" | "runtime" | "sandbox" | undefined;
|
|
361
402
|
server?: string | undefined;
|
|
403
|
+
tool?: string | undefined;
|
|
362
404
|
skill?: string | undefined;
|
|
363
405
|
plugin?: PluginLabel | undefined;
|
|
364
406
|
attempts?: number | undefined;
|
|
@@ -380,8 +422,9 @@ export declare function toolCompleted(request: HostEffect, value: unknown, facts
|
|
|
380
422
|
redacted?: undefined;
|
|
381
423
|
toolName: string;
|
|
382
424
|
status?: "cancelled" | "completed" | "failed" | undefined;
|
|
383
|
-
kind?: "harness" | "http" | "mcp" | "
|
|
425
|
+
kind?: "harness" | "http" | "mcp" | "runtime" | "sandbox" | undefined;
|
|
384
426
|
server?: string | undefined;
|
|
427
|
+
tool?: string | undefined;
|
|
385
428
|
skill?: string | undefined;
|
|
386
429
|
plugin?: PluginLabel | undefined;
|
|
387
430
|
attempts?: number | undefined;
|
|
@@ -398,8 +441,9 @@ export declare function toolCompleted(request: HostEffect, value: unknown, facts
|
|
|
398
441
|
redacted: number;
|
|
399
442
|
toolName: string;
|
|
400
443
|
status?: "cancelled" | "completed" | "failed" | undefined;
|
|
401
|
-
kind?: "harness" | "http" | "mcp" | "
|
|
444
|
+
kind?: "harness" | "http" | "mcp" | "runtime" | "sandbox" | undefined;
|
|
402
445
|
server?: string | undefined;
|
|
446
|
+
tool?: string | undefined;
|
|
403
447
|
skill?: string | undefined;
|
|
404
448
|
plugin?: PluginLabel | undefined;
|
|
405
449
|
attempts?: number | undefined;
|
|
@@ -416,8 +460,9 @@ export declare function toolCompleted(request: HostEffect, value: unknown, facts
|
|
|
416
460
|
redacted: number;
|
|
417
461
|
toolName: string;
|
|
418
462
|
status?: "cancelled" | "completed" | "failed" | undefined;
|
|
419
|
-
kind?: "harness" | "http" | "mcp" | "
|
|
463
|
+
kind?: "harness" | "http" | "mcp" | "runtime" | "sandbox" | undefined;
|
|
420
464
|
server?: string | undefined;
|
|
465
|
+
tool?: string | undefined;
|
|
421
466
|
skill?: string | undefined;
|
|
422
467
|
plugin?: PluginLabel | undefined;
|
|
423
468
|
attempts?: number | undefined;
|
|
@@ -434,8 +479,9 @@ export declare function toolCompleted(request: HostEffect, value: unknown, facts
|
|
|
434
479
|
redacted?: undefined;
|
|
435
480
|
toolName: string;
|
|
436
481
|
status?: "cancelled" | "completed" | "failed" | undefined;
|
|
437
|
-
kind?: "harness" | "http" | "mcp" | "
|
|
482
|
+
kind?: "harness" | "http" | "mcp" | "runtime" | "sandbox" | undefined;
|
|
438
483
|
server?: string | undefined;
|
|
484
|
+
tool?: string | undefined;
|
|
439
485
|
skill?: string | undefined;
|
|
440
486
|
plugin?: PluginLabel | undefined;
|
|
441
487
|
attempts?: number | undefined;
|
|
@@ -452,8 +498,9 @@ export declare function toolCompleted(request: HostEffect, value: unknown, facts
|
|
|
452
498
|
redacted?: undefined;
|
|
453
499
|
toolName: string;
|
|
454
500
|
status?: "cancelled" | "completed" | "failed" | undefined;
|
|
455
|
-
kind?: "harness" | "http" | "mcp" | "
|
|
501
|
+
kind?: "harness" | "http" | "mcp" | "runtime" | "sandbox" | undefined;
|
|
456
502
|
server?: string | undefined;
|
|
503
|
+
tool?: string | undefined;
|
|
457
504
|
skill?: string | undefined;
|
|
458
505
|
plugin?: PluginLabel | undefined;
|
|
459
506
|
attempts?: number | undefined;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isModelFailureOutcome } from "@nylorun/core/define";
|
|
2
|
+
import { HarnessApiError } from "@nylorun/core/harness-api";
|
|
2
3
|
/** The model's tool call id and the harness invocation, for tool effects. */
|
|
3
4
|
export function toolIds(context) {
|
|
4
5
|
const c = context;
|
|
@@ -52,31 +53,35 @@ export function assistantMessage(request, value) {
|
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
55
|
/**
|
|
55
|
-
* `context.compacted` for a
|
|
56
|
-
*
|
|
57
|
-
*
|
|
56
|
+
* `context.compacted` for a compaction a harness reported with its transcript edit (Q4, protocol
|
|
57
|
+
* 15): its facts, the last summary call's step and model facts, and the agent. Every summary
|
|
58
|
+
* effect it names must be a completed, successful model call of turn `turnId` made for a summary
|
|
59
|
+
* (`purpose: "summary"`); otherwise the edit is refused (`invalid`).
|
|
58
60
|
*/
|
|
59
|
-
export function contextCompacted(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
61
|
+
export async function contextCompacted(t, sessionId, turnId, facts) {
|
|
62
|
+
let last;
|
|
63
|
+
for (const effectId of facts.summaryEffectIds) {
|
|
64
|
+
const row = await t.get("effects", effectId);
|
|
65
|
+
const request = row?.request;
|
|
66
|
+
if (!row ||
|
|
67
|
+
row.status !== "completed" ||
|
|
68
|
+
request?.kind !== "model" ||
|
|
69
|
+
request.sessionId !== sessionId ||
|
|
70
|
+
request.turnId !== turnId ||
|
|
71
|
+
request.purpose !== "summary" ||
|
|
72
|
+
isModelFailureOutcome(row.outcome?.value))
|
|
73
|
+
throw new HarnessApiError("invalid", `The compaction names ${effectId}, which is not a completed summary call of this turn`);
|
|
74
|
+
last = { effectId, row };
|
|
75
|
+
}
|
|
76
|
+
const { effectId, row } = last;
|
|
77
|
+
const invocationId = row.request.context?.invocationId;
|
|
73
78
|
return {
|
|
74
79
|
...(typeof invocationId === "string" ? { invocationId } : {}),
|
|
75
|
-
trigger:
|
|
76
|
-
tokensBefore,
|
|
77
|
-
tokensAfter:
|
|
78
|
-
...(
|
|
79
|
-
...agentOf(request),
|
|
80
|
+
trigger: facts.trigger,
|
|
81
|
+
tokensBefore: facts.tokensBefore,
|
|
82
|
+
tokensAfter: facts.tokensAfter,
|
|
83
|
+
...modelOutcomeFacts(effectId, row, await t.modelUsageOf(effectId)),
|
|
84
|
+
...agentOf(row.request),
|
|
80
85
|
};
|
|
81
86
|
}
|
|
82
87
|
/** `model.failed` for a model effect that completed with a failure outcome (Model Calls §6.4). */
|
|
@@ -164,6 +169,7 @@ export function toolCompleted(request, value, facts) {
|
|
|
164
169
|
status: facts.status,
|
|
165
170
|
...(facts.kind === undefined ? {} : { kind: facts.kind }),
|
|
166
171
|
...(facts.server === undefined ? {} : { server: facts.server }),
|
|
172
|
+
...(facts.tool === undefined ? {} : { tool: facts.tool }),
|
|
167
173
|
...(facts.skill === undefined ? {} : { skill: facts.skill }),
|
|
168
174
|
...(facts.plugin === undefined ? {} : { plugin: facts.plugin }),
|
|
169
175
|
...(facts.attempts === undefined ? {} : { attempts: facts.attempts }),
|