@agenticprimitives/service-host 0.0.0-alpha.0 → 0.0.0-stage

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 CHANGED
@@ -1,28 +1,3 @@
1
- # @agenticprimitives/service-host
1
+ # Temporary Holding Version
2
2
 
3
- **A service agent's run is a harness run, or it is not a run of that agent** ([spec 433](../../specs/433-service-apps-run-the-harness-service-host.md)).
4
-
5
- This package is the harness run pipeline a service built as its own app embeds, so it runs the same harness the
6
- Agentic Primitives runtime hosts: runs checkpointed in the agent's own DO, receipts and provenance in the agent's own
7
- vault, the `/harness/*` routes its Home reads. It is being promoted out of the runtime in the order the
8
- [census](../../docs/architecture/service-host-census.md) §8 sets.
9
-
10
- **W1 step 1 (this release): the run store.** `RunStore` is the port; the checkpoint shape, the listing rule (expiry,
11
- never the keyring), the turn merge, the progress lines and the canceled record are pure and shared; `./cloudflare`
12
- binds the port to Durable Object storage on the DO side and to a per-agent stub on the Worker side.
13
-
14
- ```ts
15
- import { mergeTurn, isExpired, liveRuns, progressLine } from '@agenticprimitives/service-host';
16
- import { durableObjectRunStorage, durableObjectRunStore } from '@agenticprimitives/service-host/cloudflare';
17
-
18
- // Inside the agent's DO: one handler for every `/internal/harness-run/<op>` call.
19
- const runs = durableObjectRunStorage(state.storage);
20
- return Response.json(await runs.handle(op, body));
21
-
22
- // In the Worker: the store over the agent's stub, in-Worker only (the marker is the app's).
23
- const store = durableObjectRunStore(env.A2A_TASKS, () => internalHeaders(env));
24
- await store.save(checkpoint);
25
- ```
26
-
27
- Nothing here grants authority: a checkpoint holds what a person already gave and decides nothing; every resume
28
- re-verifies every mandate (spec 350 W3).
3
+ This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
package/package.json CHANGED
@@ -1,68 +1,6 @@
1
1
  {
2
2
  "name": "@agenticprimitives/service-host",
3
- "version": "0.0.0-alpha.0",
4
- "description": "The Service Host (spec 433): the harness run pipeline a service agent embeds — run store, progress, routes, tools, provenance sink — so a service built as an app runs the same harness the runtime hosts. W1 step 1: the run store behind a port.",
5
- "homepage": "https://agenticprimitives.dev",
6
- "bugs": {
7
- "url": "https://github.com/agentictrustlabs/agenticprimitives/issues"
8
- },
9
- "author": {
10
- "name": "Agentic Trust Labs",
11
- "url": "https://agenticprimitives.dev"
12
- },
13
- "type": "module",
14
- "exports": {
15
- ".": {
16
- "types": "./dist/index.d.ts",
17
- "import": "./dist/index.js"
18
- },
19
- "./cloudflare": {
20
- "types": "./dist/cloudflare/index.d.ts",
21
- "import": "./dist/cloudflare/index.js"
22
- }
23
- },
24
- "files": [
25
- "LICENSE",
26
- "dist",
27
- "spec.md",
28
- "README.md"
29
- ],
30
- "dependencies": {
31
- "@agenticprimitives/types": "1.0.0-alpha.30",
32
- "@agenticprimitives/a2a": "0.0.0-alpha.28",
33
- "@agenticprimitives/orchestration": "0.0.0-alpha.9"
34
- },
35
- "devDependencies": {
36
- "@cloudflare/workers-types": "^4.20240117.0",
37
- "vitest": "^4.1.11"
38
- },
39
- "publishConfig": {
40
- "access": "public"
41
- },
42
- "repository": {
43
- "type": "git",
44
- "url": "git+https://github.com/agentictrustlabs/agenticprimitives.git",
45
- "directory": "packages/service-host"
46
- },
47
- "license": "MIT",
48
- "keywords": [
49
- "agentic",
50
- "primitives",
51
- "harness",
52
- "service-agent",
53
- "service-host",
54
- "agentic-primitives",
55
- "agenticprimitives",
56
- "ai-agents",
57
- "agent-authority",
58
- "agentic-trust"
59
- ],
60
- "scripts": {
61
- "build": "tsc -p tsconfig.build.json",
62
- "typecheck": "tsc -p tsconfig.json --noEmit",
63
- "test": "vitest run",
64
- "test:unit": "vitest run test/unit --passWithNoTests",
65
- "test:watch": "vitest",
66
- "clean": "rm -rf dist"
67
- }
3
+ "version": "0.0.0-stage",
4
+ "stub": true,
5
+ "description": "Temporary package placeholder for staged publishing"
68
6
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Agentic Trust Labs
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,14 +0,0 @@
1
- import { type RunStorage } from '../storage.js';
2
- import { type RunStore } from '../run-store.js';
3
- /** The path a DO answers the store on. The Worker-side client posts here; a DO's `fetch` routes it to `handle`. */
4
- export declare const RUN_STORE_PATH = "/internal/harness-run/";
5
- /** Inside the agent's Durable Object: the checkpoint + progress storage over `state.storage`. */
6
- export declare function durableObjectRunStorage(storage: DurableObjectStorage): RunStorage;
7
- /** The DO-side route: `fetch(request)` → `handleRunStoreRequest(request, runs)` for any `/internal/harness-run/<op>`.
8
- * Returns `null` when the request is not a run-store call, so the DO's own routing continues. The in-Worker marker that
9
- * gates this path is the app's (spec 341 §7) and is checked BEFORE this is called. */
10
- export declare function handleRunStoreRequest(request: Request, runs: RunStorage): Promise<Response | null>;
11
- /** In the Worker: the `RunStore` over the agent's own stub, one DO per agent (`idFromName(agent)`). `headers` supplies
12
- * the in-Worker marker the DO requires — the app's secret, read through a function so it is never captured here. */
13
- export declare function durableObjectRunStore(ns: DurableObjectNamespace, headers: () => Record<string, string>): RunStore;
14
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cloudflare/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAgB,KAAK,QAAQ,EAAmB,MAAM,iBAAiB,CAAC;AAG/E,mHAAmH;AACnH,eAAO,MAAM,cAAc,2BAA2B,CAAC;AAEvD,iGAAiG;AACjG,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,oBAAoB,GAAG,UAAU,CAEjF;AAED;;uFAEuF;AACvF,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAOxG;AAED;qHACqH;AACrH,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,QAAQ,CAUjH"}
@@ -1,39 +0,0 @@
1
- // THE CLOUDFLARE BINDING of the run store (census §2): the Durable Object's storage on the store's side, a per-agent stub
2
- // on the Worker's side. The core ships NO Cloudflare coupling (ADR-0034); this subpath takes the namespace as a VALUE —
3
- // the binding name (`A2A_TASKS`, `CATALOG_RUNS`, …) is the app's and is never named here.
4
- /// <reference types="@cloudflare/workers-types" />
5
- import { runStorage } from '../storage.js';
6
- import { runStoreOver } from '../run-store.js';
7
- /** The path a DO answers the store on. The Worker-side client posts here; a DO's `fetch` routes it to `handle`. */
8
- export const RUN_STORE_PATH = '/internal/harness-run/';
9
- /** Inside the agent's Durable Object: the checkpoint + progress storage over `state.storage`. */
10
- export function durableObjectRunStorage(storage) {
11
- return runStorage(storage);
12
- }
13
- /** The DO-side route: `fetch(request)` → `handleRunStoreRequest(request, runs)` for any `/internal/harness-run/<op>`.
14
- * Returns `null` when the request is not a run-store call, so the DO's own routing continues. The in-Worker marker that
15
- * gates this path is the app's (spec 341 §7) and is checked BEFORE this is called. */
16
- export async function handleRunStoreRequest(request, runs) {
17
- const url = new URL(request.url);
18
- if (!url.pathname.startsWith(RUN_STORE_PATH))
19
- return null;
20
- const op = url.pathname.slice(RUN_STORE_PATH.length);
21
- const body = (await request.json().catch(() => null));
22
- const r = await runs.handle(op, body);
23
- return r.ok ? Response.json(r) : Response.json({ ok: false, error: r.error }, { status: r.status });
24
- }
25
- /** In the Worker: the `RunStore` over the agent's own stub, one DO per agent (`idFromName(agent)`). `headers` supplies
26
- * the in-Worker marker the DO requires — the app's secret, read through a function so it is never captured here. */
27
- export function durableObjectRunStore(ns, headers) {
28
- return runStoreOver(async (agent, op, body) => {
29
- const stub = ns.get(ns.idFromName(agent.toLowerCase()));
30
- const res = await stub.fetch(new Request(`https://harness-run-do${RUN_STORE_PATH}${op}`, {
31
- method: 'POST', headers: { 'content-type': 'application/json', ...headers() }, body: JSON.stringify(body),
32
- }));
33
- const out = (await res.json().catch(() => ({})));
34
- if (!res.ok || out.ok === false)
35
- throw new Error(String(out.error ?? `harness-run/${op} failed (${res.status})`));
36
- return out;
37
- });
38
- }
39
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cloudflare/index.ts"],"names":[],"mappings":"AAAA,0HAA0H;AAC1H,wHAAwH;AACxH,0FAA0F;AAC1F,mDAAmD;AACnD,OAAO,EAAE,UAAU,EAAmB,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAkC,MAAM,iBAAiB,CAAC;AAG/E,mHAAmH;AACnH,MAAM,CAAC,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAEvD,iGAAiG;AACjG,MAAM,UAAU,uBAAuB,CAAC,OAA6B;IACnE,OAAO,UAAU,CAAC,OAAO,CAAC,CAA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AE,EAAE,cAAc,EAAE,kBAAkB,EAAE,GAAG,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC1G,CAAC,CAAC,CAAC;QACJ,MAAM,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAA+D,CAAC;QAC/G,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,KAAK,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,eAAe,EAAE,YAAY,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAClH,OAAO,GAAG,CAAC;IACb,CAAC,CAAC,CAAC;AACL,CAAC"}
package/dist/index.d.ts DELETED
@@ -1,10 +0,0 @@
1
- export declare const PACKAGE_NAME: "@agenticprimitives/service-host";
2
- export declare const PACKAGE_STATUS: "w1-run-store";
3
- export declare const SPEC_REF: "specs/433-service-apps-run-the-harness-service-host.md";
4
- export { mergeTurn, isExpired, expiryFor, liveRuns, completedStepsOf, canceledRecord, openRunOnThread, runStoreOver, AWAIT_WINDOW_MS, RUN_TTL_MS, } from './run-store.js';
5
- export type { HarnessRunCheckpointV1, SuspendedRunV1, SelectedOfferBindingV1, AwaitingKind, RunStore, RunStoreOp, RunStoreCall } from './run-store.js';
6
- export { toolWords, progressLine, PROGRESS_TTL_MS, PROGRESS_MAX_LINES } from './progress.js';
7
- export type { ProgressLineV1 } from './progress.js';
8
- export { runStorage, memoryRunKv, memoryRunStoreCall, RUN_KEY_PREFIX, PROGRESS_KEY_PREFIX } from './storage.js';
9
- export type { RunKv, RunStorage, RunStorageResult } from './storage.js';
10
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,EAAG,iCAA0C,CAAC;AACvE,eAAO,MAAM,cAAc,EAAG,cAAuB,CAAC;AACtD,eAAO,MAAM,QAAQ,EAAG,wDAAiE,CAAC;AAE1F,OAAO,EACL,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,gBAAgB,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAC1G,eAAe,EAAE,UAAU,GAC5B,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,sBAAsB,EAAE,cAAc,EAAE,sBAAsB,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEvJ,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC7F,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,kBAAkB,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAChH,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js DELETED
@@ -1,9 +0,0 @@
1
- // @agenticprimitives/service-host — spec 433. The harness run pipeline a service agent embeds, promoted out of the
2
- // ap-home runtime in the census order (docs/architecture/service-host-census.md §8). W1 step 1: the run store.
3
- export const PACKAGE_NAME = '@agenticprimitives/service-host';
4
- export const PACKAGE_STATUS = 'w1-run-store';
5
- export const SPEC_REF = 'specs/433-service-apps-run-the-harness-service-host.md';
6
- export { mergeTurn, isExpired, expiryFor, liveRuns, completedStepsOf, canceledRecord, openRunOnThread, runStoreOver, AWAIT_WINDOW_MS, RUN_TTL_MS, } from './run-store.js';
7
- export { toolWords, progressLine, PROGRESS_TTL_MS, PROGRESS_MAX_LINES } from './progress.js';
8
- export { runStorage, memoryRunKv, memoryRunStoreCall, RUN_KEY_PREFIX, PROGRESS_KEY_PREFIX } from './storage.js';
9
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,+GAA+G;AAC/G,MAAM,CAAC,MAAM,YAAY,GAAG,iCAA0C,CAAC;AACvE,MAAM,CAAC,MAAM,cAAc,GAAG,cAAuB,CAAC;AACtD,MAAM,CAAC,MAAM,QAAQ,GAAG,wDAAiE,CAAC;AAE1F,OAAO,EACL,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,gBAAgB,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAC1G,eAAe,EAAE,UAAU,GAC5B,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAG7F,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,kBAAkB,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC"}
@@ -1,33 +0,0 @@
1
- import type { RunEvent, ToolSpec } from '@agenticprimitives/orchestration';
2
- export interface ProgressLineV1 {
3
- /** Monotonic within the run, assigned by the store as lines arrive. */
4
- seq: number;
5
- at: number;
6
- type: RunEvent['type'] | 'ReplyReady' | 'Relayed' | 'AnswerDraft';
7
- /** Spec 418 A1 — the growing answer of a streamed step (`AnswerDraft`): a surface REPLACES the previous draft with it. */
8
- draft?: string;
9
- /** Spec 374 / appendix M8 — a line RELAYED from the subject agent's own run (a routed step): the words are the
10
- * receiver's, prefixed with its name; `from` says whose. */
11
- from?: {
12
- agent: string;
13
- name?: string;
14
- };
15
- stepRef?: string;
16
- toolId?: string;
17
- /** One sentence for a screen or a voice. */
18
- said: string;
19
- /** The run reached its reply; the surface may stop reading. */
20
- terminal?: boolean;
21
- }
22
- /** A run's progress is kept this long past its last line (a surface reads the tail after the reply). */
23
- export declare const PROGRESS_TTL_MS = 3600000;
24
- /** Lines per run, capped: a run is several turns and nothing a person needs is line 401. */
25
- export declare const PROGRESS_MAX_LINES = 400;
26
- /**
27
- * The words for a tool: the capability's plain phrase where one is published ("create organizations"), else the
28
- * tool's own description. Never the id — "organization.create" is not a thing a voice says.
29
- */
30
- export declare function toolWords(tool: ToolSpec | undefined, words: (capabilityId: string) => string | undefined): string;
31
- /** One sentence per loop event. `null` for events that say nothing a person needs mid-turn. */
32
- export declare function progressLine(e: RunEvent, tools: ReadonlyArray<ToolSpec>, words: (capabilityId: string) => string | undefined): Omit<ProgressLineV1, 'seq' | 'at'> | null;
33
- //# sourceMappingURL=progress.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../src/progress.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAE3E,MAAM,WAAW,cAAc;IAC7B,uEAAuE;IACvE,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,YAAY,GAAG,SAAS,GAAG,aAAa,CAAC;IAClE,0HAA0H;IAC1H,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;iEAC6D;IAC7D,IAAI,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wGAAwG;AACxG,eAAO,MAAM,eAAe,UAAW,CAAC;AACxC,4FAA4F;AAC5F,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAItC;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,EAAE,KAAK,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,GAAG,MAAM,CAUjH;AAED,+FAA+F;AAC/F,wBAAgB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC,cAAc,EAAE,KAAK,GAAG,IAAI,CAAC,GAAG,IAAI,CAuBxK"}
package/dist/progress.js DELETED
@@ -1,49 +0,0 @@
1
- /** A run's progress is kept this long past its last line (a surface reads the tail after the reply). */
2
- export const PROGRESS_TTL_MS = 3600_000;
3
- /** Lines per run, capped: a run is several turns and nothing a person needs is line 401. */
4
- export const PROGRESS_MAX_LINES = 400;
5
- const cap = (s) => (s ? s[0].toUpperCase() + s.slice(1) : s);
6
- /**
7
- * The words for a tool: the capability's plain phrase where one is published ("create organizations"), else the
8
- * tool's own description. Never the id — "organization.create" is not a thing a voice says.
9
- */
10
- export function toolWords(tool, words) {
11
- if (!tool)
12
- return 'the next step';
13
- const w = tool.capability?.id ? words(tool.capability.id) : undefined;
14
- if (w)
15
- return w;
16
- // A READ has no capability words. Its `answer`/`answers` say what it answers; failing that, the first clause of its
17
- // description — never the whole description, which once put a paragraph of planner guidance into a progress line.
18
- const q = tool.answer ?? tool.answers?.[0];
19
- if (q)
20
- return q.replace(/[?.]+$/, '').toLowerCase();
21
- const d = (tool.description ?? '').replace(/^ANSWERS A QUESTION:\s*/i, '').split(/\s[—–]\s|\.\s|:\s/)[0]?.trim() ?? '';
22
- return d ? (d.length > 72 ? `${d.slice(0, 69)}…` : d) : tool.id;
23
- }
24
- /** One sentence per loop event. `null` for events that say nothing a person needs mid-turn. */
25
- export function progressLine(e, tools, words) {
26
- const tool = (id) => tools.find((t) => t.id === id);
27
- const w = (id) => toolWords(tool(id), words);
28
- // A tool with no capability exercises no authority: reading, never acting (the loop's own rule).
29
- const informational = (id) => !tool(id)?.capability;
30
- switch (e.type) {
31
- case 'PlanCreated': return { type: e.type, said: e.steps === 1 ? 'Working out how — one step.' : `Working out how — ${e.steps} steps.` };
32
- case 'PlanRefused': return { type: e.type, said: e.replanning ? 'That plan did not fit — trying again.' : 'That plan did not fit.' };
33
- case 'StepProposed': return { type: e.type, stepRef: e.stepRef, toolId: e.toolId, said: e.risk === 'informational' || informational(e.toolId) ? `Reading ${w(e.toolId)}…` : `Checking your authority to ${w(e.toolId)}…` };
34
- case 'MandateChecked': return e.decision === 'allow' ? { type: e.type, stepRef: e.stepRef, said: e.afterApproval ? 'Approved and confirmed — going ahead.' : 'Authority confirmed — going ahead.' } : null;
35
- case 'MandateDenied': return { type: e.type, stepRef: e.stepRef, said: `Refused: ${e.reasons[0]?.message ?? 'the authority does not cover this'}.` };
36
- case 'ApprovalRequested': return { type: e.type, stepRef: e.stepRef, said: 'This needs an approval — asking.' };
37
- case 'ApprovalDischarged': return { type: e.type, stepRef: e.stepRef, said: 'Approved.' };
38
- case 'ApprovalRefused': return { type: e.type, stepRef: e.stepRef, said: `Approval refused${e.reason ? `: ${e.reason}` : ''}.` };
39
- case 'StepReplayed': return { type: e.type, stepRef: e.stepRef, toolId: e.toolId, said: `${cap(w(e.toolId))}: already done.` };
40
- case 'ToolInvoked': return { type: e.type, stepRef: e.stepRef, toolId: e.toolId, said: e.ok ? (informational(e.toolId) ? `Read ${w(e.toolId)}.` : `${cap(w(e.toolId))} — done.`) : `${cap(w(e.toolId))} failed.` };
41
- case 'RunSuspended': return { type: e.type, stepRef: e.stepRef, said: 'I need something from you.' };
42
- case 'EffectFailed': return { type: e.type, stepRef: e.stepRef, said: 'The act stood, but telling the other side failed.' };
43
- case 'RunCompleted': return { type: e.type, said: 'Done.', terminal: true };
44
- case 'RunFailed': return { type: e.type, said: `That did not go through: ${e.error.split(/[:\n]/)[0]}.`, terminal: true };
45
- case 'StepCompensated': return { type: e.type, stepRef: e.stepRef, said: e.ok ? 'Undone.' : 'Could not undo.' };
46
- default: return null;
47
- }
48
- }
49
- //# sourceMappingURL=progress.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"progress.js","sourceRoot":"","sources":["../src/progress.ts"],"names":[],"mappings":"AAuBA,wGAAwG;AACxG,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAC;AACxC,4FAA4F;AAC5F,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAEtC,MAAM,GAAG,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAE9E;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,IAA0B,EAAE,KAAmD;IACvG,IAAI,CAAC,IAAI;QAAE,OAAO,eAAe,CAAC;IAClC,MAAM,CAAC,GAAG,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACtE,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC;IAChB,oHAAoH;IACpH,kHAAkH;IAClH,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3C,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IACpD,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,0BAA0B,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC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EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QAC5E,KAAK,WAAW,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,4BAA4B,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QAC1H,KAAK,iBAAiB,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC;QAChH,OAAO,CAAC,CAAC,OAAO,IAAI,CAAC;IACvB,CAAC;AACH,CAAC"}
@@ -1,210 +0,0 @@
1
- import type { SuppliedInputV1, Plan, StepReceipt, CommitmentRefV1, RunRecordV1 } from '@agenticprimitives/orchestration';
2
- import type { DelegationWireV1 } from '@agenticprimitives/a2a';
3
- import type { Address, Hex } from '@agenticprimitives/types';
4
- import type { ProgressLineV1 } from './progress.js';
5
- /** Spec 384 W3 — a campaign's selection, carried on a run's origin: the provider the step is handed to and the offer the
6
- * mandate must name. Shapes the plan; no verifier reads it — the verifier reads the mandate. */
7
- export interface SelectedOfferBindingV1 {
8
- type: 'ap.selected-offer-binding.v1';
9
- campaignId: string;
10
- capability: string;
11
- provider: Address;
12
- providerName?: string | null;
13
- offerId: string;
14
- offerDigest: Hex;
15
- expiresAt: string;
16
- }
17
- export type AwaitingKind = 'data' | 'signature' | 'confirmation' | 'commitment' | 'authority';
18
- /** One unfinished ask. Small on purpose: what the person said, what they granted, what they answered. */
19
- export interface HarnessRunCheckpointV1 {
20
- runRef: string;
21
- /** The sentence. An ask is ONE thing — a different sentence is a different ask and a different intent digest, so it
22
- * may not inherit this run's mandate. */
23
- message: string;
24
- /** The FULL intent when the run was entered with one (a durable/supplied-plan run). The mandate binds the digest of
25
- * THIS object — rebuilding `{ goal }` from the message alone changes the digest and every mandate mismatches. */
26
- intent?: {
27
- goal: string;
28
- constraints?: Record<string, unknown>;
29
- context?: Record<string, unknown>;
30
- };
31
- /** The realm the ask was addressed to. */
32
- addressee: Address;
33
- /** WHO asked. Only they may resume: a run carries their session's authority and their answers. */
34
- asker: Address;
35
- /** THE KEYRING — every mandate this run has been granted, not just the last one (spec 350 W3). Holding a key is not
36
- * holding authority: every wire is re-verified on every turn, and the loop judges each step under exactly ONE
37
- * selected mandate (ADR-0013). A keyring makes the run rememberable, never more permitted. */
38
- presented: DelegationWireV1[];
39
- /** Everything answered so far, by stepRef. */
40
- supplied: SuppliedInputV1[];
41
- /** Spec 361 I4 — the caller-supplied plan, when the run was entered deterministically. */
42
- plan?: {
43
- steps: Array<{
44
- toolId: string;
45
- args: Record<string, unknown>;
46
- id?: string;
47
- }>;
48
- };
49
- /** What the run is waiting for. `expiresAt` (spec 370 P1) is when waiting stops being resumable. */
50
- awaiting?: {
51
- kind: AwaitingKind;
52
- prompt: string;
53
- stepRef: string;
54
- expiresAt?: number;
55
- /** Spec 374 — when `kind` is `commitment`: what another agent owes this run, and where it waits. */
56
- commitment?: CommitmentRefV1;
57
- /** Spec 385 — an AMBIGUITY choice's scope (word + capability + arg), so the resume that answers it can be
58
- * remembered as a scoped preference. Display/memory only. */
59
- scope?: {
60
- word: string;
61
- capability: string;
62
- arg: string;
63
- };
64
- };
65
- /** Spec 370 P1 — WHAT RAN: the admitted plan and the completed steps with their receipts. A resume REPLAYS them
66
- * (spec 362 §0.1 gate 4) and judges the remaining steps as if for the first time. Evidence, never permission. */
67
- executed?: {
68
- plan: Plan;
69
- completed: Array<{
70
- stepRef: string;
71
- result?: unknown;
72
- receipt?: StepReceipt;
73
- }>;
74
- };
75
- /** Spec 370 P5 — started by a TRIGGER of the agent's playbook, not by a person. Display and audit; no gate reads it. */
76
- trigger?: {
77
- id: string;
78
- playbookDigest: string;
79
- };
80
- /** Spec 372 N1 — started by an OUTSIDE runtime on the standard A2A surface, calling as the agent named. */
81
- outsider?: {
82
- agent: Address;
83
- surface: 'a2a-standard' | 'subject-ask';
84
- };
85
- /** Spec 374 — a ROUTED ACT another agent's run is waiting on; the correlation is the creditor's (spec 366 R2). */
86
- routedFrom?: {
87
- creditor: Address;
88
- correlation: {
89
- operationId: string;
90
- runRef: string;
91
- stepRef: string;
92
- };
93
- };
94
- /** Spec 374 W2 — where each ROUTED step of this run waits at the subject's agent. */
95
- routedAt?: Record<string, {
96
- agent: Address;
97
- name?: string;
98
- runRef: string;
99
- }>;
100
- /** Spec 370 P1 tail — when this run stops being resumable. Absent on older rows ⇒ `updatedAt`-based. */
101
- expiresAt?: number;
102
- /** A WORK ITEM nobody has picked up: `asker` is the principal, and any steward who can mint the mandate may claim it. */
103
- openToStewards?: boolean;
104
- /** The plan step this run exists to satisfy. When it completes, the step's evidence is its RECEIPT. */
105
- origin?: {
106
- endeavorId: string;
107
- stepId: string;
108
- principal: Address;
109
- commitmentRef?: string;
110
- planHash?: string;
111
- engagement?: SelectedOfferBindingV1;
112
- };
113
- /** Spec 362 — WHICH ENGINE advances this run. ONE executor per run, never a fallback pair. */
114
- executor?: 'client' | 'workflow';
115
- /** Spec 400 W2 (B3) — the THREAD this run belongs to, when a message on that thread opened it. */
116
- thread?: string;
117
- /** Spec 409 §5 — the SENDER whose message opened this run on its thread; only they continue it by words. */
118
- threadPeer?: string;
119
- createdAt: number;
120
- updatedAt: number;
121
- }
122
- /** One unfinished run as a LISTING shows it — everything but the keyring. A list says that something is waiting and
123
- * what it waits for; it never hands out the mandates, which only a resume does and only to whoever may resume. */
124
- export type SuspendedRunV1 = Omit<HarnessRunCheckpointV1, 'presented'>;
125
- /** THE PORT. What the harness turn and the `/harness/runs` route code against; nothing here names a binding. */
126
- export interface RunStore {
127
- save(checkpoint: HarnessRunCheckpointV1): Promise<void>;
128
- load(addressee: Address, runRef: string): Promise<HarnessRunCheckpointV1 | null>;
129
- /** The unfinished runs on this agent — ALL of them, keyring stripped. Who may see which is the caller's decision. */
130
- list(addressee: Address): Promise<SuspendedRunV1[]>;
131
- /** A run that reached a terminal outcome leaves nothing behind: done is done, and a denial is terminal (ADR-0013). */
132
- drop(addressee: Address, runRef: string): Promise<void>;
133
- /** Spec 370 P2 — the run's progress lines. `asker` is recorded with the first line and gates every read. */
134
- appendProgress(addressee: Address, runRef: string, asker: Address, line: Omit<ProgressLineV1, 'seq' | 'at'> & {
135
- at?: number;
136
- }): Promise<{
137
- seq: number;
138
- }>;
139
- readProgress(addressee: Address, runRef: string, asker: Address, after?: number): Promise<{
140
- known: boolean;
141
- lines: ProgressLineV1[];
142
- terminal: boolean;
143
- }>;
144
- }
145
- /** Spec 400 W2 (B3) — THE OPEN RUN ON A THREAD: the newest unexpired run on `thread` that waits for DATA. A run waiting
146
- * on a signature, a commitment or authority is not resumable by words, and a mention leaves it where it is. */
147
- export declare function openRunOnThread(runs: readonly SuspendedRunV1[], thread: string, now?: number): SuspendedRunV1 | null;
148
- /** Merge a turn's inputs over the checkpoint. The stored answers come FIRST so a resend of the same stepRef adds rather
149
- * than replaces. THE KEYRING GROWS, NEWEST FIRST: this turn's mandates go in front (a re-grant is reached first), the
150
- * older keys stay for the items they were granted for; a re-grant has a fresh salt and never dedups the one it
151
- * supersedes. */
152
- export declare function mergeTurn(stored: HarnessRunCheckpointV1 | null, turn: {
153
- message?: string;
154
- presented?: DelegationWireV1 | DelegationWireV1[] | null;
155
- supplied?: SuppliedInputV1[];
156
- }): {
157
- message: string;
158
- presented: DelegationWireV1[];
159
- supplied: SuppliedInputV1[];
160
- } | {
161
- error: string;
162
- };
163
- /** How long a wait stays resumable (spec 370 P1). A signature or a confirmation answers a mandate minted for the request
164
- * — minutes, not days; a data question may wait two hours; a commitment waits on ANOTHER agent's steward — a day. */
165
- export declare const AWAIT_WINDOW_MS: Record<AwaitingKind, number>;
166
- /** A day: well past the point of resumability for any run, whatever it waits for. */
167
- export declare const RUN_TTL_MS: number;
168
- /** Past its window: resumable no longer. Absent window ⇒ a data question keeps the day; anything else is stale after
169
- * the same half hour a new row would get. */
170
- export declare function isExpired(cp: Pick<HarnessRunCheckpointV1, 'awaiting' | 'expiresAt' | 'updatedAt'>, now?: number): boolean;
171
- /** The window a run keeps from the moment it stopped: the prompt's own, else the authority window. */
172
- export declare function expiryFor(awaiting: HarnessRunCheckpointV1['awaiting'] | undefined, now?: number): number;
173
- /**
174
- * THE LISTING RULE, shared by every store. An unfinished run expires: after `RUN_TTL_MS` regardless, or past its own
175
- * window (spec 370 P1 tail) — a run a person walked away from is gone from the list, not shown as unfinished (one estate
176
- * reached 167 of them). Mandates are bearer-shaped wires and enumeration is a LISTING, not a resume, so the keyring
177
- * never rides along. Returns what is live and which keys the store may delete.
178
- */
179
- export declare function liveRuns<K>(rows: ReadonlyArray<readonly [K, HarnessRunCheckpointV1]>, now?: number): {
180
- live: SuspendedRunV1[];
181
- expired: K[];
182
- };
183
- /** The completed steps of a run result, as a checkpoint records them — successful, named, with their receipt. A failed
184
- * or suspended step is not "done" and is not replayed. */
185
- export declare function completedStepsOf(result: {
186
- steps: ReadonlyArray<{
187
- ok: boolean;
188
- stepRef?: string;
189
- result?: unknown;
190
- }>;
191
- receipts: ReadonlyArray<StepReceipt>;
192
- }): NonNullable<HarnessRunCheckpointV1['executed']>['completed'];
193
- /**
194
- * Spec 398 §5.3 — THE RECORD OF A CANCELED RUN. The turn's record is kept and MARKED (never rewritten as failed: nothing
195
- * went wrong); a record that never landed is synthesised from the checkpoint — what ran, what it left, nothing invented.
196
- */
197
- export declare function canceledRecord(existing: RunRecordV1 | null, stored: Pick<HarnessRunCheckpointV1, 'runRef' | 'message' | 'intent' | 'executed'>, by: {
198
- at: number;
199
- by: Address;
200
- note?: string;
201
- }): RunRecordV1 & {
202
- canceled: NonNullable<RunRecordV1['canceled']>;
203
- };
204
- export type RunStoreOp = 'save' | 'load' | 'drop' | 'list' | 'progress-append' | 'progress-read';
205
- /** One call to the agent's own store: the Cloudflare adapter sends it to the agent's DO stub; a Node binding to its own
206
- * process. The core never names the transport. */
207
- export type RunStoreCall = (agent: Address, op: RunStoreOp, body: Record<string, unknown>) => Promise<Record<string, unknown>>;
208
- /** A `RunStore` over one `call`. The op names and bodies are the contract `runStorage` (the DO side) answers. */
209
- export declare function runStoreOver(call: RunStoreCall): RunStore;
210
- //# sourceMappingURL=run-store.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"run-store.d.ts","sourceRoot":"","sources":["../src/run-store.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AACzH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD;iGACiG;AACjG,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,8BAA8B,CAAC;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,GAAG,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,WAAW,GAAG,cAAc,GAAG,YAAY,GAAG,WAAW,CAAC;AAE9F,yGAAyG;AACzG,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf;8CAC0C;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB;sHACkH;IAClH,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,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AAC,sBAAsB,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,CAO1N;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,WAAW,GAAG,IAAI,EAC5B,MAAM,EAAE,IAAI,CAAC,sBAAsB,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,UAAU,CAAC,EAClF,EAAE,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7C,WAAW,GAAG;IAAE,QAAQ,EAAE,WAAW,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAA;CAAE,CAYlE;AAID,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,iBAAiB,GAAG,eAAe,CAAC;AAEjG;mDACmD;AACnD,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAE/H,iHAAiH;AACjH,wBAAgB,YAAY,CAAC,IAAI,EAAE,YAAY,GAAG,QAAQ,CAqBzD"}
package/dist/run-store.js DELETED
@@ -1,132 +0,0 @@
1
- /** Spec 400 W2 (B3) — THE OPEN RUN ON A THREAD: the newest unexpired run on `thread` that waits for DATA. A run waiting
2
- * on a signature, a commitment or authority is not resumable by words, and a mention leaves it where it is. */
3
- export function openRunOnThread(runs, thread, now = Date.now()) {
4
- return runs
5
- .filter((r) => r.thread === thread && r.awaiting?.kind === 'data' && !isExpired(r, now))
6
- .sort((a, b) => b.updatedAt - a.updatedAt)[0] ?? null;
7
- }
8
- /** A wire's identity WITHIN one run: delegator + delegate + salt. Not a security check — it dedups a list; every wire
9
- * is verified on chain regardless. */
10
- const wireKey = (w) => `${String(w.delegator).toLowerCase()}:${String(w.delegate).toLowerCase()}:${String(w.salt)}`;
11
- const asList = (p) => (p == null ? [] : Array.isArray(p) ? p : [p]);
12
- /** Merge a turn's inputs over the checkpoint. The stored answers come FIRST so a resend of the same stepRef adds rather
13
- * than replaces. THE KEYRING GROWS, NEWEST FIRST: this turn's mandates go in front (a re-grant is reached first), the
14
- * older keys stay for the items they were granted for; a re-grant has a fresh salt and never dedups the one it
15
- * supersedes. */
16
- export function mergeTurn(stored, turn) {
17
- const message = (turn.message ?? stored?.message ?? '').trim();
18
- if (!message)
19
- return { error: 'this run has no question and none was given' };
20
- if (stored && turn.message && turn.message.trim() !== stored.message) {
21
- // The mandate is bound to the intent digest, so a changed sentence would be denied a step later with
22
- // `intent-mismatch`. Saying it here names the actual mistake instead of a hash comparison.
23
- return { error: 'this run was started for a different question — ask it as a new one rather than changing this one mid-way' };
24
- }
25
- const keyring = [];
26
- const seen = new Set();
27
- for (const w of [...asList(turn.presented), ...asList(stored?.presented)]) {
28
- const k = wireKey(w);
29
- if (seen.has(k))
30
- continue;
31
- seen.add(k);
32
- keyring.push(w);
33
- }
34
- return { message, presented: keyring, supplied: [...(stored?.supplied ?? []), ...(turn.supplied ?? [])] };
35
- }
36
- /** How long a wait stays resumable (spec 370 P1). A signature or a confirmation answers a mandate minted for the request
37
- * — minutes, not days; a data question may wait two hours; a commitment waits on ANOTHER agent's steward — a day. */
38
- export const AWAIT_WINDOW_MS = {
39
- data: 2 * 3600_000, signature: 30 * 60_000, confirmation: 30 * 60_000, authority: 30 * 60_000, commitment: 24 * 3600_000,
40
- };
41
- /** A day: well past the point of resumability for any run, whatever it waits for. */
42
- export const RUN_TTL_MS = 24 * 60 * 60 * 1000;
43
- /** Past its window: resumable no longer. Absent window ⇒ a data question keeps the day; anything else is stale after
44
- * the same half hour a new row would get. */
45
- export function isExpired(cp, now = Date.now()) {
46
- if (typeof cp.awaiting?.expiresAt === 'number')
47
- return cp.awaiting.expiresAt < now;
48
- if (typeof cp.expiresAt === 'number')
49
- return cp.expiresAt < now;
50
- if (cp.awaiting?.kind === 'data')
51
- return false;
52
- return typeof cp.updatedAt === 'number' && now - cp.updatedAt > AWAIT_WINDOW_MS.signature;
53
- }
54
- /** The window a run keeps from the moment it stopped: the prompt's own, else the authority window. */
55
- export function expiryFor(awaiting, now = Date.now()) {
56
- return now + (awaiting ? AWAIT_WINDOW_MS[awaiting.kind] : AWAIT_WINDOW_MS.signature);
57
- }
58
- /**
59
- * THE LISTING RULE, shared by every store. An unfinished run expires: after `RUN_TTL_MS` regardless, or past its own
60
- * window (spec 370 P1 tail) — a run a person walked away from is gone from the list, not shown as unfinished (one estate
61
- * reached 167 of them). Mandates are bearer-shaped wires and enumeration is a LISTING, not a resume, so the keyring
62
- * never rides along. Returns what is live and which keys the store may delete.
63
- */
64
- export function liveRuns(rows, now = Date.now()) {
65
- const live = [];
66
- const expired = [];
67
- for (const [key, run] of rows) {
68
- const updatedAt = Number(run.updatedAt ?? 0);
69
- if (updatedAt && now - updatedAt > RUN_TTL_MS) {
70
- expired.push(key);
71
- continue;
72
- }
73
- if (isExpired(run, now)) {
74
- expired.push(key);
75
- continue;
76
- }
77
- const { presented: _presented, ...rest } = run;
78
- live.push(rest);
79
- }
80
- return { live, expired };
81
- }
82
- /** The completed steps of a run result, as a checkpoint records them — successful, named, with their receipt. A failed
83
- * or suspended step is not "done" and is not replayed. */
84
- export function completedStepsOf(result) {
85
- return result.steps
86
- .filter((o) => o.ok && o.stepRef)
87
- .map((o) => {
88
- const receipt = result.receipts.find((r) => r.stepRef === o.stepRef);
89
- return { stepRef: o.stepRef, ...(o.result !== undefined ? { result: o.result } : {}), ...(receipt ? { receipt } : {}) };
90
- });
91
- }
92
- /**
93
- * Spec 398 §5.3 — THE RECORD OF A CANCELED RUN. The turn's record is kept and MARKED (never rewritten as failed: nothing
94
- * went wrong); a record that never landed is synthesised from the checkpoint — what ran, what it left, nothing invented.
95
- */
96
- export function canceledRecord(existing, stored, by) {
97
- const completed = stored.executed?.completed ?? [];
98
- const base = existing ?? {
99
- type: 'ap.run-record.v1', runRef: stored.runRef, at: by.at,
100
- intent: stored.intent ?? { goal: stored.message },
101
- plan: stored.executed?.plan ?? { steps: [] },
102
- steps: completed.map((x) => ({ stepRef: x.stepRef, toolId: x.receipt?.toolId ?? '', args: {}, ok: true, ...(x.result !== undefined ? { result: x.result } : {}) })),
103
- receipts: completed.flatMap((x) => (x.receipt ? [x.receipt] : [])),
104
- events: [], outcome: 'suspended',
105
- };
106
- const note = by.note?.trim() ? by.note.trim().slice(0, 280) : undefined;
107
- return { ...base, canceled: { at: by.at, by: by.by, afterSteps: completed.length, ...(note ? { note } : {}) } };
108
- }
109
- /** A `RunStore` over one `call`. The op names and bodies are the contract `runStorage` (the DO side) answers. */
110
- export function runStoreOver(call) {
111
- return {
112
- async save(checkpoint) { await call(checkpoint.addressee, 'save', { checkpoint }); },
113
- async load(addressee, runRef) {
114
- const out = await call(addressee, 'load', { runRef });
115
- return out.checkpoint ?? null;
116
- },
117
- async list(addressee) {
118
- const out = await call(addressee, 'list', {});
119
- return out.runs ?? [];
120
- },
121
- async drop(addressee, runRef) { await call(addressee, 'drop', { runRef }); },
122
- async appendProgress(addressee, runRef, asker, line) {
123
- const out = await call(addressee, 'progress-append', { runRef, asker, line });
124
- return { seq: Number(out.seq ?? 0) };
125
- },
126
- async readProgress(addressee, runRef, asker, after = 0) {
127
- const out = await call(addressee, 'progress-read', { runRef, asker, after });
128
- return { known: out.known === true, lines: out.lines ?? [], terminal: out.terminal === true };
129
- },
130
- };
131
- }
132
- //# sourceMappingURL=run-store.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"run-store.js","sourceRoot":"","sources":["../src/run-store.ts"],"names":[],"mappings":"AA+GA;gHACgH;AAChH,MAAM,UAAU,eAAe,CAAC,IAA+B,EAAE,MAAc,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE;IAC/F,OAAO,IAAI;SACR,M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AE,KAAK,EAAG,GAAG,CAAC,KAAsC,IAAI,EAAE,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;QAClI,CAAC;KACF,CAAC;AACJ,CAAC"}
package/dist/storage.d.ts DELETED
@@ -1,54 +0,0 @@
1
- import { liveRuns, type HarnessRunCheckpointV1, type RunStoreOp } from './run-store.js';
2
- import { type ProgressLineV1 } from './progress.js';
3
- /** The slice of a key/value store the run storage needs. `DurableObjectStorage` satisfies it directly. */
4
- export interface RunKv {
5
- get<T = unknown>(key: string): Promise<T | undefined>;
6
- put<T = unknown>(key: string, value: T): Promise<void>;
7
- delete(key: string | string[]): Promise<unknown>;
8
- list<T = unknown>(opts: {
9
- prefix: string;
10
- }): Promise<Map<string, T>>;
11
- }
12
- export declare const RUN_KEY_PREFIX = "harness:run:";
13
- export declare const PROGRESS_KEY_PREFIX = "harness:progress:";
14
- export type RunStorageResult = {
15
- ok: true;
16
- } & Record<string, unknown> | {
17
- ok: false;
18
- error: string;
19
- status: number;
20
- };
21
- export interface RunStorage {
22
- /** One handler for every op; the Cloudflare DO routes `/internal/harness-run/<op>` here. */
23
- handle(op: RunStoreOp | string, body: Record<string, unknown> | null | undefined, now?: number): Promise<RunStorageResult>;
24
- /** The ops individually, for a binding that prefers typed calls. */
25
- save(checkpoint: HarnessRunCheckpointV1): Promise<void>;
26
- load(runRef: string): Promise<HarnessRunCheckpointV1 | null>;
27
- /** Live runs, newest first; `expired` counts the rows this call deleted. */
28
- list(now?: number): Promise<ReturnType<typeof liveRuns<string>>['live'] & {
29
- expired: number;
30
- }>;
31
- drop(runRef: string): Promise<void>;
32
- appendProgress(runRef: string, asker: string, line: Omit<ProgressLineV1, 'seq' | 'at'> & {
33
- at?: number;
34
- }, now?: number): Promise<{
35
- seq: number;
36
- } | {
37
- error: string;
38
- status: number;
39
- }>;
40
- readProgress(runRef: string, asker: string, after?: number): Promise<{
41
- known: boolean;
42
- lines: ProgressLineV1[];
43
- terminal: boolean;
44
- } | {
45
- error: string;
46
- status: number;
47
- }>;
48
- }
49
- export declare function runStorage(kv: RunKv): RunStorage;
50
- /** An in-memory `RunKv` — tests, and a single-process host. */
51
- export declare function memoryRunKv(): RunKv;
52
- /** A `RunStore` over an in-memory storage, one agent per key space — a single-process host or a test. */
53
- export declare function memoryRunStoreCall(): import('./run-store.js').RunStoreCall;
54
- //# sourceMappingURL=storage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,KAAK,sBAAsB,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACxF,OAAO,EAAuC,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAEzF,0GAA0G;AAC1G,MAAM,WAAW,KAAK;IACpB,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IACtD,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACjD,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;CACtE;AAED,eAAO,MAAM,cAAc,iBAAiB,CAAC;AAC7C,eAAO,MAAM,mBAAmB,sBAAsB,CAAC;AAMvD,MAAM,MAAM,gBAAgB,GAAG;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAAE,EAAE,EAAE,K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AE,OAAO,CAAC;QAAC,KAAK,EAAE,cAAc,EAAE,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAA;KAAE,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC1K;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,KAAK,GAAG,UAAU,CAoEhD;AAED,+DAA+D;AAC/D,wBAAgB,WAAW,IAAI,KAAK,CAQnC;AAED,yGAAyG;AACzG,wBAAgB,kBAAkB,IAAI,OAAO,gBAAgB,EAAE,YAAY,CAU1E"}
package/dist/storage.js DELETED
@@ -1,126 +0,0 @@
1
- // THE STORE'S OWN SIDE — what answers a `RunStoreCall`, over a minimal key/value storage (census §2: the checkpoint and
2
- // progress ops of the runtime's `A2aTaskDO`, carved out of the class). Pure over `RunKv`, so a Durable Object's storage
3
- // (`./cloudflare`), an in-memory map (tests) or a Node store bind it unchanged. The op names and bodies are the
4
- // contract `runStoreOver` sends.
5
- import { liveRuns } from './run-store.js';
6
- import { PROGRESS_MAX_LINES, PROGRESS_TTL_MS } from './progress.js';
7
- export const RUN_KEY_PREFIX = 'harness:run:';
8
- export const PROGRESS_KEY_PREFIX = 'harness:progress:';
9
- const runKey = (ref) => `${RUN_KEY_PREFIX}${ref}`;
10
- const progressKey = (ref) => `${PROGRESS_KEY_PREFIX}${ref}`;
11
- export function runStorage(kv) {
12
- const save = async (cp) => { await kv.put(runKey(cp.runRef), cp); };
13
- const load = async (runRef) => (await kv.get(runKey(runRef))) ?? null;
14
- const drop = async (runRef) => { await kv.delete(runKey(runRef)); };
15
- // ENUMERATE the unfinished runs. The store returns them all; WHOSE they are is decided by the caller's session at the
16
- // route (a person sees their own; a steward additionally sees the unclaimed work items). Expiry is applied here,
17
- // wherever the cost of a list is already being paid, rather than on a timer; and the progress lines a run left
18
- // behind outlive it by `PROGRESS_TTL_MS` at most.
19
- const list = async (now = Date.now()) => {
20
- const rows = [...(await kv.list({ prefix: RUN_KEY_PREFIX }))];
21
- const { live, expired } = liveRuns(rows, now);
22
- const stale = [...(await kv.list({ prefix: PROGRESS_KEY_PREFIX }))].filter(([, v]) => now - Number(v?.at ?? 0) > PROGRESS_TTL_MS).map(([k]) => k);
23
- const gone = [...expired, ...stale];
24
- if (gone.length)
25
- await kv.delete(gone);
26
- // Newest first — the order every listing surface shows, so a consumer never re-sorts.
27
- live.sort((a, b) => Number(b.updatedAt ?? 0) - Number(a.updatedAt ?? 0));
28
- return Object.assign(live, { expired: expired.length });
29
- };
30
- const appendProgress = async (runRef, asker, line, now = Date.now()) => {
31
- const cur = (await kv.get(progressKey(runRef))) ?? { asker, at: now, lines: [] };
32
- if (cur.asker !== asker)
33
- return { error: 'this run belongs to someone else', status: 403 };
34
- // ONE SEQUENCE PER RUN, assigned here: a reader keeps its cursor across turns. Spec 418 A1 — a streamed answer's
35
- // drafts REPLACE each other (same step): the list keeps the latest, under a new seq.
36
- const last = cur.lines[cur.lines.length - 1];
37
- const seq = (last?.seq ?? 0) + 1;
38
- const next = { ...line, at: line.at ?? now, seq };
39
- if (next.type === 'AnswerDraft' && last?.type === 'AnswerDraft' && last.stepRef === next.stepRef)
40
- cur.lines[cur.lines.length - 1] = next;
41
- else if (cur.lines.length < PROGRESS_MAX_LINES)
42
- cur.lines.push(next);
43
- cur.at = now;
44
- await kv.put(progressKey(runRef), cur);
45
- return { seq };
46
- };
47
- const readProgress = async (runRef, asker, after = 0) => {
48
- const cur = await kv.get(progressKey(runRef));
49
- if (!cur)
50
- return { known: false, lines: [], terminal: false };
51
- if (cur.asker !== asker)
52
- return { error: 'this run belongs to someone else', status: 403 };
53
- // Terminal = the LAST line says so: a new turn's lines after a reply make the run live again.
54
- const last = cur.lines[cur.lines.length - 1];
55
- return { known: true, lines: cur.lines.filter((l) => l.seq > after), terminal: !!last?.terminal };
56
- };
57
- const bad = (error, status = 400) => ({ ok: false, error, status });
58
- return {
59
- save, load, list, drop, appendProgress, readProgress,
60
- async handle(op, body, now = Date.now()) {
61
- const b = body ?? {};
62
- switch (op) {
63
- case 'save': {
64
- const cp = b.checkpoint;
65
- if (!cp?.runRef || !cp.addressee || !cp.asker)
66
- return bad('checkpoint with runRef, addressee and asker required');
67
- await save(cp);
68
- return { ok: true };
69
- }
70
- case 'load': {
71
- if (!b.runRef)
72
- return bad('runRef required');
73
- return { ok: true, checkpoint: await load(String(b.runRef)) };
74
- }
75
- case 'drop': {
76
- if (!b.runRef)
77
- return bad('runRef required');
78
- await drop(String(b.runRef));
79
- return { ok: true };
80
- }
81
- case 'list': {
82
- const runs = await list(now);
83
- return { ok: true, runs: [...runs], expired: runs.expired };
84
- }
85
- case 'progress-append': {
86
- if (!b.runRef || !b.line || !b.asker)
87
- return bad('runRef, asker and line required');
88
- const r = await appendProgress(String(b.runRef), String(b.asker), b.line, now);
89
- return 'error' in r ? bad(r.error, r.status) : { ok: true, seq: r.seq };
90
- }
91
- case 'progress-read': {
92
- if (!b.runRef || !b.asker)
93
- return bad('runRef and asker required');
94
- const r = await readProgress(String(b.runRef), String(b.asker), Number(b.after ?? 0));
95
- return 'error' in r ? bad(r.error, r.status) : { ok: true, ...r };
96
- }
97
- default: return bad(`unknown harness-run op "${op}"`, 404);
98
- }
99
- },
100
- };
101
- }
102
- /** An in-memory `RunKv` — tests, and a single-process host. */
103
- export function memoryRunKv() {
104
- const m = new Map();
105
- return {
106
- async get(key) { return m.get(key); },
107
- async put(key, value) { m.set(key, value); },
108
- async delete(key) { for (const k of Array.isArray(key) ? key : [key])
109
- m.delete(k); },
110
- async list({ prefix }) { return new Map([...m].filter(([k]) => k.startsWith(prefix))); },
111
- };
112
- }
113
- /** A `RunStore` over an in-memory storage, one agent per key space — a single-process host or a test. */
114
- export function memoryRunStoreCall() {
115
- const perAgent = new Map();
116
- return async (agent, op, body) => {
117
- const a = agent.toLowerCase();
118
- const s = perAgent.get(a) ?? runStorage(memoryRunKv());
119
- perAgent.set(a, s);
120
- const r = await s.handle(op, body);
121
- if (!r.ok)
122
- throw new Error(r.error);
123
- return r;
124
- };
125
- }
126
- //# sourceMappingURL=storage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,wHAAwH;AACxH,wHAAwH;AACxH,gHAAgH;AAChH,iCAAiC;AACjC,OAAO,EAAE,QAAQ,EAAgD,MAAM,gBAAgB,CAAC;AACxF,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAuB,MAAM,eAAe,CAAC;AAUzF,MAAM,CAAC,MAAM,cAAc,GAAG,cAAc,CAAC;AAC7C,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AACvD,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,cAAc,GAAG,GAAG,EAAE,CAAC;AAC1D,MAAM,WAAW,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,mBAAmB,GAAG,GAAG,EAAE,CAAC;AAmBpE,MAAM,UAAU,UAAU,CAAC,EAAS;IAClC,MAAM,IAAI,GAAG,KAAK,EAAE,EAA0B,EAAiB,EAAE,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3G,MAAM,IAAI,GAAG,KAAK,EAAE,MAAc,EAA0C,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAyB,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;IAC9I,MAAM,IAAI,GAAG,KAAK,EAAE,MAAc,EAAiB,EAAE,GAAG,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3F,sHAAsH;IACtH,iHAAiH;IACjH,+GAA+G;IAC/G,kDAAkD;IAClD,MAAM,IAAI,GAAG,KAAK,EAAE,GAAG,GAAG,IAAI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AAC,CAAC,CAAC;QAC5C,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;YAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACpF,KAAK,CAAC,IAAI,CAAI,EAAE,MAAM,EAAsB,IAAI,OAAO,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAuB,CAAC,CAAC,CAAC,CAAC;KACtI,CAAC;AACJ,CAAC;AAED,yGAAyG;AACzG,MAAM,UAAU,kBAAkB;IAChC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE;QAC/B,MAAM,CAAC,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;QAC9B,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;QACvD,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACnB,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QACnC,IAAI,CAAC,CAAC,CAAC,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACpC,OAAO,CAAC,CAAC;IACX,CAAC,CAAC;AACJ,CAAC"}
package/spec.md DELETED
@@ -1,4 +0,0 @@
1
- # service-host — the harness a service agent embeds
2
-
3
- **Status:** w1-run-store. **Spec of record:** [spec 433](../../specs/433-service-apps-run-the-harness-service-host.md).
4
- **Census (what moves here, from where):** [`docs/architecture/service-host-census.md`](../../docs/architecture/service-host-census.md).