@openprose/reactor 0.1.0-rc.1

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.
Files changed (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +231 -0
  3. package/dist/adapters/agent-sdk-passthrough/index.d.ts +8 -0
  4. package/dist/adapters/agent-sdk-passthrough/index.d.ts.map +1 -0
  5. package/dist/adapters/agent-sdk-passthrough/index.js +25 -0
  6. package/dist/adapters/clock-system/index.d.ts +9 -0
  7. package/dist/adapters/clock-system/index.d.ts.map +1 -0
  8. package/dist/adapters/clock-system/index.js +39 -0
  9. package/dist/adapters/connector-static/index.d.ts +11 -0
  10. package/dist/adapters/connector-static/index.d.ts.map +1 -0
  11. package/dist/adapters/connector-static/index.js +35 -0
  12. package/dist/adapters/event-sink-memory/index.d.ts +10 -0
  13. package/dist/adapters/event-sink-memory/index.d.ts.map +1 -0
  14. package/dist/adapters/event-sink-memory/index.js +20 -0
  15. package/dist/adapters/index.d.ts +10 -0
  16. package/dist/adapters/index.d.ts.map +1 -0
  17. package/dist/adapters/index.js +25 -0
  18. package/dist/adapters/json.d.ts +3 -0
  19. package/dist/adapters/json.d.ts.map +1 -0
  20. package/dist/adapters/json.js +61 -0
  21. package/dist/adapters/model-gateway-record-replay/index.d.ts +24 -0
  22. package/dist/adapters/model-gateway-record-replay/index.d.ts.map +1 -0
  23. package/dist/adapters/model-gateway-record-replay/index.js +55 -0
  24. package/dist/adapters/sandbox-null/index.d.ts +3 -0
  25. package/dist/adapters/sandbox-null/index.d.ts.map +1 -0
  26. package/dist/adapters/sandbox-null/index.js +8 -0
  27. package/dist/adapters/storage-fs/index.d.ts +14 -0
  28. package/dist/adapters/storage-fs/index.d.ts.map +1 -0
  29. package/dist/adapters/storage-fs/index.js +65 -0
  30. package/dist/adapters/storage-memory/index.d.ts +11 -0
  31. package/dist/adapters/storage-memory/index.d.ts.map +1 -0
  32. package/dist/adapters/storage-memory/index.js +34 -0
  33. package/dist/adapters/types.d.ts +22 -0
  34. package/dist/adapters/types.d.ts.map +1 -0
  35. package/dist/adapters/types.js +97 -0
  36. package/dist/composition/index.d.ts +79 -0
  37. package/dist/composition/index.d.ts.map +1 -0
  38. package/dist/composition/index.js +280 -0
  39. package/dist/cost/index.d.ts +49 -0
  40. package/dist/cost/index.d.ts.map +1 -0
  41. package/dist/cost/index.js +206 -0
  42. package/dist/evidence-plan/index.d.ts +57 -0
  43. package/dist/evidence-plan/index.d.ts.map +1 -0
  44. package/dist/evidence-plan/index.js +164 -0
  45. package/dist/forecast/index.d.ts +39 -0
  46. package/dist/forecast/index.d.ts.map +1 -0
  47. package/dist/forecast/index.js +119 -0
  48. package/dist/index.d.ts +14 -0
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.js +29 -0
  51. package/dist/judge/index.d.ts +29 -0
  52. package/dist/judge/index.d.ts.map +1 -0
  53. package/dist/judge/index.js +138 -0
  54. package/dist/kernel/index.d.ts +170 -0
  55. package/dist/kernel/index.d.ts.map +1 -0
  56. package/dist/kernel/index.js +637 -0
  57. package/dist/memo/index.d.ts +59 -0
  58. package/dist/memo/index.d.ts.map +1 -0
  59. package/dist/memo/index.js +189 -0
  60. package/dist/policy/index.d.ts +249 -0
  61. package/dist/policy/index.d.ts.map +1 -0
  62. package/dist/policy/index.js +1463 -0
  63. package/dist/projection/index.d.ts +119 -0
  64. package/dist/projection/index.d.ts.map +1 -0
  65. package/dist/projection/index.js +506 -0
  66. package/dist/reactor/index.d.ts +54 -0
  67. package/dist/reactor/index.d.ts.map +1 -0
  68. package/dist/reactor/index.js +1861 -0
  69. package/dist/receipt/index.d.ts +190 -0
  70. package/dist/receipt/index.d.ts.map +1 -0
  71. package/dist/receipt/index.js +646 -0
  72. package/dist/sdk/exit-bundle.d.ts +144 -0
  73. package/dist/sdk/exit-bundle.d.ts.map +1 -0
  74. package/dist/sdk/exit-bundle.js +1034 -0
  75. package/dist/sdk/index.d.ts +201 -0
  76. package/dist/sdk/index.d.ts.map +1 -0
  77. package/dist/sdk/index.js +418 -0
  78. package/package.json +89 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 OpenProse
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.
package/README.md ADDED
@@ -0,0 +1,231 @@
1
+ # @openprose/reactor
2
+
3
+ `@openprose/reactor` is the local Reactor Harness runtime spine for OpenProse.
4
+ It models the parts of a responsibility loop that need to survive replay,
5
+ forking, evidence review, and package verification without changing OpenProse
6
+ source syntax.
7
+
8
+ This README describes the `0.1.0-rc.1` package surface. It is an OSS release
9
+ candidate; the stable `0.1.0` launch waits for provenance publication and
10
+ stranger-run verification.
11
+
12
+ ## v0.1 Status
13
+
14
+ What v0.1 demonstrates:
15
+
16
+ - The static-world cost thesis is visible in the package-backed
17
+ `skills/open-prose/examples/flat-tokens` run: four `createReactor().ingest()` turns
18
+ produce real Reactor receipts and print `tokens.fresh=46`,
19
+ `tokens.reused=46`, and `ratio=46:46`.
20
+ - Receipts, owner/subscriber/public projections, and SDK export/import are
21
+ implemented so the trail can be inspected, redacted for lower-trust readers,
22
+ and carried as exit material.
23
+ - Composition pins verify consumed receipts against contract revision and
24
+ acceptable signer posture; Cradle release parity exercises the same package
25
+ surface across memory and filesystem rows, with Postgres marked future.
26
+ - Local examples are runnable from the package/CLI release surface: the flat
27
+ tokens example runs from packed tarballs, and the companion OpenProse CLI
28
+ quickstart compiles, serves, triggers, and projects an incident-briefing
29
+ responsibility locally.
30
+
31
+ What is designed and partial:
32
+
33
+ - The CLI path is local and deterministic. It proves package/CLI integration,
34
+ receipt production, and projection, not production ingress or hosted
35
+ fulfillment quality.
36
+ - Provider parity is recorded, not a live runtime matrix. Cradle carries
37
+ deterministic provider parity doubles and one live-recorded K1 cassette, but
38
+ this package does not perform runtime variable-depth ensemble judging.
39
+ - The tagged publish gate is wired for provenance publication, but no npm
40
+ publication has been run for this worktree.
41
+
42
+ Deferred to v0.2 or external gates:
43
+
44
+ - Actual npm publication and provenance until a release tag and npm auth or
45
+ trusted publishing are available.
46
+ - The stranger run that verifies both local demos outside the authoring team.
47
+ - Production ingress, fulfillment, and oracle layers.
48
+ - Runtime variable-depth ensemble judging, Postgres parity, and a non-null
49
+ signer adapter.
50
+
51
+ The runtime package currently provides:
52
+
53
+ - `openprose.receipt v0` creation, verification, canonical hashing, and proof
54
+ inspection.
55
+ - Token-truth and surprise-attribution checks for flat-spend reasoning.
56
+ - Deterministic kernel policy evaluation, backstops, rollback comparison, and
57
+ safety receipts.
58
+ - Compiled evidence-plan, memo-key, forecast, policy recompile/rollback, and
59
+ graph-composition helpers.
60
+ - An adapter-injected SDK with receipt ingest, registry reads, and exit-bundle
61
+ export/import.
62
+ - Owner/subscriber/public receipt projections for privacy-preserving evidence
63
+ reports.
64
+
65
+ ## Public Subpaths
66
+
67
+ The packed artifact exposes these CommonJS entrypoints:
68
+
69
+ - `@openprose/reactor`
70
+ - `@openprose/reactor/receipt`
71
+ - `@openprose/reactor/cost`
72
+ - `@openprose/reactor/kernel`
73
+ - `@openprose/reactor/evidence-plan`
74
+ - `@openprose/reactor/memo`
75
+ - `@openprose/reactor/forecast`
76
+ - `@openprose/reactor/sdk`
77
+ - `@openprose/reactor/policy`
78
+ - `@openprose/reactor/composition`
79
+ - `@openprose/reactor/projection`
80
+
81
+ ## Quickstart
82
+
83
+ These TypeScript examples use the package's public subpaths. Verify a receipt
84
+ and derive a proof summary that avoids private payload fields:
85
+
86
+ ```ts
87
+ import {
88
+ inspectReceiptProofV0,
89
+ verifyReceiptV0,
90
+ type ReceiptV0,
91
+ } from "@openprose/reactor/receipt";
92
+
93
+ export function inspectStoredReceipt(receipt: ReceiptV0) {
94
+ const verification = verifyReceiptV0(receipt);
95
+ if (!verification.ok) {
96
+ throw new Error(verification.errors.join("; "));
97
+ }
98
+
99
+ return inspectReceiptProofV0(receipt);
100
+ }
101
+ ```
102
+
103
+ Project a proof for a lower-trust audience:
104
+
105
+ ```ts
106
+ import { projectReceiptProofV0 } from "@openprose/reactor/projection";
107
+ import type { ReceiptProofInspectionV0 } from "@openprose/reactor/receipt";
108
+
109
+ export function publicReceiptEvidence(proof: ReceiptProofInspectionV0) {
110
+ const result = projectReceiptProofV0({ tier: "public", proof });
111
+ if (!result.ok) {
112
+ throw new Error(result.errors.join("; "));
113
+ }
114
+
115
+ return result.projection;
116
+ }
117
+ ```
118
+
119
+ Create an SDK instance with explicit adapters. The SDK does not install hidden
120
+ network, model, agent, sandbox, or storage defaults. In v0.1, omitting `signer`
121
+ is represented explicitly as the null signer state
122
+ `{ scheme: "none", null_reason: "no-signer-adapter-configured" }`; real signing
123
+ adapters are deferred:
124
+
125
+ ```ts
126
+ import { createReactor, type ReactorAdaptersV0 } from "@openprose/reactor/sdk";
127
+
128
+ const adapters: ReactorAdaptersV0 = {
129
+ clock: { now: () => "2026-05-19T00:00:00Z" },
130
+ storage: {
131
+ appendReceipt: () => undefined,
132
+ listReceipts: () => [],
133
+ readRegistry: () => ({
134
+ contract_revision:
135
+ "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
136
+ policy_artifact_id: "policy.incident-briefing",
137
+ policy_artifact_identity: "incident-briefing",
138
+ policy_artifact_namespace: "policy.static",
139
+ policy_artifact_revision: "policy-revision-1",
140
+ policy_artifact_validation_state: "validated",
141
+ }),
142
+ },
143
+ modelGateway: { invoke: (request) => ({ payload: request.payload }) },
144
+ agentSdk: { launch: (request) => ({ payload: request.payload }) },
145
+ sandbox: { run: () => ({ exit_code: 0, stdout: "", stderr: "" }) },
146
+ connectors: { read: () => ({ payload: null }) },
147
+ eventSink: { emit: () => undefined },
148
+ };
149
+
150
+ const reactor = createReactor({
151
+ responsibility_id: "responsibility.incident-briefing",
152
+ adapters,
153
+ });
154
+
155
+ reactor.ingest({ kind: "tick" });
156
+ const exitBundle = reactor.export();
157
+ ```
158
+
159
+ Evaluate a validated policy artifact before running B3 backstops:
160
+
161
+ ```ts
162
+ import {
163
+ evaluateBackstops,
164
+ judgedActivations,
165
+ validateKernelPolicyArtifact,
166
+ } from "@openprose/reactor/kernel";
167
+
168
+ const validation = validateKernelPolicyArtifact({
169
+ no_anchor: true,
170
+ falsification_predicate: {
171
+ kind: "equals",
172
+ fact: "material_status",
173
+ value: "stale",
174
+ },
175
+ backstop_divergence_predicate: {
176
+ kind: "greater-than-or-equal",
177
+ fact: "observed_divergence_multiplier",
178
+ value: 2,
179
+ },
180
+ live_observables: ["material_status", "observed_divergence_multiplier"],
181
+ });
182
+
183
+ if (!validation.ok) {
184
+ throw new Error(validation.errors.join("; "));
185
+ }
186
+
187
+ const backstops = evaluateBackstops({
188
+ token: validation.token,
189
+ as_of: "2026-05-19T00:00:00Z",
190
+ last_policy_revalidated_at: "2026-05-01T00:00:00Z",
191
+ last_recompile_at: "2026-05-18T00:00:00Z",
192
+ recompile_requested: false,
193
+ policy_warmup_judged_activations: judgedActivations(1),
194
+ });
195
+ ```
196
+
197
+ ## Local Package Evidence
198
+
199
+ The current build has local evidence for the package shape:
200
+
201
+ ```sh
202
+ pnpm --filter @openprose/reactor test
203
+ pnpm --dir packages/reactor pack --pack-destination /tmp/openprose-reactor-pack
204
+ node .github/scripts/verify-reactor-pin.mjs \
205
+ --tarball /tmp/openprose-reactor-pack/openprose-reactor-0.1.0-rc.1.tgz
206
+ node .github/scripts/smoke-reactor-tarball-import.mjs \
207
+ --tarball /tmp/openprose-reactor-pack/openprose-reactor-0.1.0-rc.1.tgz
208
+ pnpm --dir packages/reactor-cradle pack --pack-destination /tmp/openprose-reactor-pack
209
+ node .github/scripts/smoke-reactor-flat-tokens-example.mjs \
210
+ --reactorTarball /tmp/openprose-reactor-pack/openprose-reactor-0.1.0-rc.1.tgz \
211
+ --cradleTarball /tmp/openprose-reactor-pack/openprose-reactor-cradle-0.1.0-rc.1.tgz \
212
+ --exampleDir skills/open-prose/examples/flat-tokens
213
+ ```
214
+
215
+ The verifier checks the packed tree against the Cradle pin, and the import
216
+ smoke imports every public Reactor entrypoint from the tarball in a temporary
217
+ offline consumer. The flat-tokens smoke installs packed Reactor and Cradle
218
+ artifacts into a temporary offline consumer and expects `tokens.fresh=46`,
219
+ `tokens.reused=46`, and `ratio=46:46`.
220
+
221
+ ## Current Boundaries
222
+
223
+ - This README describes the release-candidate package surface; the stable npm
224
+ release waits for registry-visible provenance and stranger-run evidence.
225
+ - GitHub Actions contain a tagged publish gate that relies on npm trusted
226
+ publishing/OIDC and rejects tag/package-version mismatches.
227
+ - The package does not include the CLI implementation; local CLI
228
+ `serve/status` evidence lives in the companion OpenProse CLI worktree.
229
+ - Postgres parity, production adapter release, live provider/model matrix, and
230
+ deployment checks are still outside this package surface.
231
+ - `cost.provider_norm` remains the deferred receipt v0 normalization field.
@@ -0,0 +1,8 @@
1
+ import type { ReactorAgentRequestV0, ReactorAgentResponseV0, ReactorAgentSdkAdapterV0 } from "../../sdk";
2
+ export type ReactorAgentSdkLaunchHandlerV0 = (request: ReactorAgentRequestV0) => ReactorAgentResponseV0;
3
+ export interface RecordingAgentSdkAdapterV0 extends ReactorAgentSdkAdapterV0 {
4
+ readonly launches: () => readonly ReactorAgentRequestV0[];
5
+ }
6
+ export declare function createPassthroughAgentSdkAdapterV0(handler?: ReactorAgentSdkLaunchHandlerV0): RecordingAgentSdkAdapterV0;
7
+ export declare function createNullAgentSdkAdapterV0(payload?: unknown): RecordingAgentSdkAdapterV0;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/agent-sdk-passthrough/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACzB,MAAM,WAAW,CAAC;AAGnB,MAAM,MAAM,8BAA8B,GAAG,CAC3C,OAAO,EAAE,qBAAqB,KAC3B,sBAAsB,CAAC;AAE5B,MAAM,WAAW,0BAA2B,SAAQ,wBAAwB;IAC1E,QAAQ,CAAC,QAAQ,EAAE,MAAM,SAAS,qBAAqB,EAAE,CAAC;CAC3D;AAED,wBAAgB,kCAAkC,CAChD,OAAO,GAAE,8BAEP,GACD,0BAA0B,CAa5B;AAED,wBAAgB,2BAA2B,CACzC,OAAO,GAAE,OAAc,GACtB,0BAA0B,CAI5B"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPassthroughAgentSdkAdapterV0 = createPassthroughAgentSdkAdapterV0;
4
+ exports.createNullAgentSdkAdapterV0 = createNullAgentSdkAdapterV0;
5
+ const json_1 = require("../json");
6
+ function createPassthroughAgentSdkAdapterV0(handler = (request) => ({
7
+ payload: request.payload,
8
+ })) {
9
+ const launches = [];
10
+ return {
11
+ launch(request) {
12
+ const requestCopy = (0, json_1.cloneAdapterJsonValueV0)(request);
13
+ launches.push(requestCopy);
14
+ return (0, json_1.cloneAdapterJsonValueV0)(handler(requestCopy));
15
+ },
16
+ launches() {
17
+ return launches.map((launch) => (0, json_1.cloneAdapterJsonValueV0)(launch));
18
+ },
19
+ };
20
+ }
21
+ function createNullAgentSdkAdapterV0(payload = null) {
22
+ return createPassthroughAgentSdkAdapterV0(() => ({
23
+ payload: (0, json_1.cloneAdapterJsonValueV0)(payload),
24
+ }));
25
+ }
@@ -0,0 +1,9 @@
1
+ import type { ReactorClockAdapterV0 } from "../../sdk";
2
+ export interface FixedClockAdapterV0 extends ReactorClockAdapterV0 {
3
+ readonly set: (instant: string) => void;
4
+ readonly advanceByMs: (milliseconds: number) => string;
5
+ readonly readings: () => readonly string[];
6
+ }
7
+ export declare function createSystemClockAdapterV0(): ReactorClockAdapterV0;
8
+ export declare function createFixedClockAdapterV0(initialInstant: string): FixedClockAdapterV0;
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/clock-system/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEvD,MAAM,WAAW,mBAAoB,SAAQ,qBAAqB;IAChE,QAAQ,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,QAAQ,CAAC,WAAW,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,CAAC;IACvD,QAAQ,CAAC,QAAQ,EAAE,MAAM,SAAS,MAAM,EAAE,CAAC;CAC5C;AAED,wBAAgB,0BAA0B,IAAI,qBAAqB,CAIlE;AAED,wBAAgB,yBAAyB,CAAC,cAAc,EAAE,MAAM,GAAG,mBAAmB,CA0BrF"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSystemClockAdapterV0 = createSystemClockAdapterV0;
4
+ exports.createFixedClockAdapterV0 = createFixedClockAdapterV0;
5
+ function createSystemClockAdapterV0() {
6
+ return {
7
+ now: () => new Date().toISOString(),
8
+ };
9
+ }
10
+ function createFixedClockAdapterV0(initialInstant) {
11
+ assertReplayableInstant(initialInstant, "initialInstant");
12
+ let current = initialInstant;
13
+ const emitted = [];
14
+ return {
15
+ now() {
16
+ emitted.push(current);
17
+ return current;
18
+ },
19
+ set(instant) {
20
+ assertReplayableInstant(instant, "instant");
21
+ current = instant;
22
+ },
23
+ advanceByMs(milliseconds) {
24
+ if (!Number.isFinite(milliseconds)) {
25
+ throw new Error("milliseconds must be finite");
26
+ }
27
+ current = new Date(Date.parse(current) + milliseconds).toISOString();
28
+ return current;
29
+ },
30
+ readings() {
31
+ return [...emitted];
32
+ },
33
+ };
34
+ }
35
+ function assertReplayableInstant(value, name) {
36
+ if (!Number.isFinite(Date.parse(value))) {
37
+ throw new Error(`${name} must be a replayable instant`);
38
+ }
39
+ }
@@ -0,0 +1,11 @@
1
+ import type { ReactorConnectorAdapterV0, ReactorConnectorRequestV0 } from "../../sdk";
2
+ export interface StaticConnectorSourceV0 {
3
+ readonly source_id: string;
4
+ readonly payload: unknown;
5
+ }
6
+ export interface StaticConnectorAdapterV0 extends ReactorConnectorAdapterV0 {
7
+ readonly writeSource: (source: StaticConnectorSourceV0) => void;
8
+ readonly reads: () => readonly ReactorConnectorRequestV0[];
9
+ }
10
+ export declare function createStaticConnectorAdapterV0(sources?: readonly StaticConnectorSourceV0[]): StaticConnectorAdapterV0;
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/connector-static/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,yBAAyB,EAE1B,MAAM,WAAW,CAAC;AAGnB,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,WAAW,wBAAyB,SAAQ,yBAAyB;IACzE,QAAQ,CAAC,WAAW,EAAE,CAAC,MAAM,EAAE,uBAAuB,KAAK,IAAI,CAAC;IAChE,QAAQ,CAAC,KAAK,EAAE,MAAM,SAAS,yBAAyB,EAAE,CAAC;CAC5D;AAED,wBAAgB,8BAA8B,CAC5C,OAAO,GAAE,SAAS,uBAAuB,EAAO,GAC/C,wBAAwB,CA2B1B"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createStaticConnectorAdapterV0 = createStaticConnectorAdapterV0;
4
+ const json_1 = require("../json");
5
+ function createStaticConnectorAdapterV0(sources = []) {
6
+ const records = new Map();
7
+ const reads = [];
8
+ for (const source of sources) {
9
+ writeSource(records, source);
10
+ }
11
+ return {
12
+ read(request) {
13
+ const requestCopy = (0, json_1.cloneAdapterJsonValueV0)(request);
14
+ reads.push(requestCopy);
15
+ if (!records.has(request.source_id)) {
16
+ throw new Error(`connector source not found: ${request.source_id}`);
17
+ }
18
+ return {
19
+ payload: (0, json_1.cloneAdapterJsonValueV0)(records.get(request.source_id)),
20
+ };
21
+ },
22
+ writeSource(source) {
23
+ writeSource(records, source);
24
+ },
25
+ reads() {
26
+ return reads.map((read) => (0, json_1.cloneAdapterJsonValueV0)(read));
27
+ },
28
+ };
29
+ }
30
+ function writeSource(records, source) {
31
+ if (source.source_id.length === 0) {
32
+ throw new Error("connector source_id must be non-empty");
33
+ }
34
+ records.set(source.source_id, (0, json_1.cloneAdapterJsonValueV0)(source.payload));
35
+ }
@@ -0,0 +1,10 @@
1
+ import type { ReactorEventSinkAdapterV0, ReactorSdkEventV0 } from "../../sdk";
2
+ export interface MemoryEventSinkAdapterV0 extends ReactorEventSinkAdapterV0 {
3
+ readonly events: () => readonly ReactorSdkEventV0[];
4
+ readonly clear: () => void;
5
+ }
6
+ export interface MemoryEventSinkAdapterInputV0 {
7
+ readonly onEmit?: (event: ReactorSdkEventV0) => void;
8
+ }
9
+ export declare function createMemoryEventSinkAdapterV0(input?: MemoryEventSinkAdapterInputV0): MemoryEventSinkAdapterV0;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/event-sink-memory/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAG9E,MAAM,WAAW,wBAAyB,SAAQ,yBAAyB;IACzE,QAAQ,CAAC,MAAM,EAAE,MAAM,SAAS,iBAAiB,EAAE,CAAC;IACpD,QAAQ,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;CACtD;AAED,wBAAgB,8BAA8B,CAC5C,KAAK,GAAE,6BAAkC,GACxC,wBAAwB,CAgB1B"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createMemoryEventSinkAdapterV0 = createMemoryEventSinkAdapterV0;
4
+ const json_1 = require("../json");
5
+ function createMemoryEventSinkAdapterV0(input = {}) {
6
+ const events = [];
7
+ return {
8
+ emit(event) {
9
+ const eventCopy = (0, json_1.cloneAdapterJsonValueV0)(event);
10
+ events.push(eventCopy);
11
+ input.onEmit?.(eventCopy);
12
+ },
13
+ events() {
14
+ return events.map((event) => (0, json_1.cloneAdapterJsonValueV0)(event));
15
+ },
16
+ clear() {
17
+ events.length = 0;
18
+ },
19
+ };
20
+ }
@@ -0,0 +1,10 @@
1
+ export * from "./agent-sdk-passthrough";
2
+ export * from "./clock-system";
3
+ export * from "./connector-static";
4
+ export * from "./event-sink-memory";
5
+ export * from "./model-gateway-record-replay";
6
+ export * from "./sandbox-null";
7
+ export * from "./storage-fs";
8
+ export * from "./storage-memory";
9
+ export * from "./types";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./agent-sdk-passthrough"), exports);
18
+ __exportStar(require("./clock-system"), exports);
19
+ __exportStar(require("./connector-static"), exports);
20
+ __exportStar(require("./event-sink-memory"), exports);
21
+ __exportStar(require("./model-gateway-record-replay"), exports);
22
+ __exportStar(require("./sandbox-null"), exports);
23
+ __exportStar(require("./storage-fs"), exports);
24
+ __exportStar(require("./storage-memory"), exports);
25
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,3 @@
1
+ export declare function renderAdapterJsonV0(value: unknown): string;
2
+ export declare function cloneAdapterJsonValueV0<T>(value: T): T;
3
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/adapters/json.ts"],"names":[],"mappings":"AAEA,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAE1D;AAED,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAEtD"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderAdapterJsonV0 = renderAdapterJsonV0;
4
+ exports.cloneAdapterJsonValueV0 = cloneAdapterJsonValueV0;
5
+ const receipt_1 = require("../receipt");
6
+ function renderAdapterJsonV0(value) {
7
+ return (0, receipt_1.canonicalizeForReceiptV0)(toAdapterJsonValue(value));
8
+ }
9
+ function cloneAdapterJsonValueV0(value) {
10
+ return JSON.parse(renderAdapterJsonV0(value));
11
+ }
12
+ function toAdapterJsonValue(value) {
13
+ if (value === null) {
14
+ return null;
15
+ }
16
+ switch (typeof value) {
17
+ case "boolean":
18
+ case "string":
19
+ return value;
20
+ case "number":
21
+ if (!Number.isFinite(value)) {
22
+ throw new TypeError("adapter JSON cannot contain non-finite numbers");
23
+ }
24
+ return value;
25
+ case "object":
26
+ if (Array.isArray(value)) {
27
+ return value.map((item) => {
28
+ if (item === undefined) {
29
+ throw new TypeError("adapter JSON arrays cannot contain undefined");
30
+ }
31
+ return toAdapterJsonValue(item);
32
+ });
33
+ }
34
+ if (!isPlainRecord(value)) {
35
+ throw new TypeError("adapter JSON cannot contain non-plain objects");
36
+ }
37
+ return normalizeRecord(value);
38
+ case "undefined":
39
+ case "bigint":
40
+ case "function":
41
+ case "symbol":
42
+ throw new TypeError(`adapter JSON cannot contain ${typeof value}`);
43
+ }
44
+ }
45
+ function normalizeRecord(value) {
46
+ const normalized = {};
47
+ for (const key of Object.keys(value)) {
48
+ const item = value[key];
49
+ if (item !== undefined) {
50
+ normalized[key] = toAdapterJsonValue(item);
51
+ }
52
+ }
53
+ return normalized;
54
+ }
55
+ function isPlainRecord(value) {
56
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
57
+ return false;
58
+ }
59
+ const prototype = Object.getPrototypeOf(value);
60
+ return prototype === Object.prototype || prototype === null;
61
+ }
@@ -0,0 +1,24 @@
1
+ import type { ReactorModelGatewayRequestV0, ReactorModelGatewayUsageV0 } from "../../sdk";
2
+ import { type ReactorModelGatewayRuntimeAdapterV0 } from "../types";
3
+ export interface RecordReplayModelGatewayRecordV0 {
4
+ readonly id: string;
5
+ readonly request: ReactorModelGatewayRequestV0;
6
+ readonly response: {
7
+ readonly payload: unknown;
8
+ readonly usage: ReactorModelGatewayUsageV0;
9
+ };
10
+ }
11
+ export interface RecordReplayModelGatewayCallV0 {
12
+ readonly record_id: string;
13
+ readonly request: ReactorModelGatewayRequestV0;
14
+ readonly usage: ReactorModelGatewayUsageV0;
15
+ }
16
+ export interface RecordReplayModelGatewayAdapterV0 extends ReactorModelGatewayRuntimeAdapterV0 {
17
+ readonly calls: () => readonly RecordReplayModelGatewayCallV0[];
18
+ readonly remaining: () => number;
19
+ }
20
+ export interface RecordReplayModelGatewayInputV0 {
21
+ readonly records: readonly RecordReplayModelGatewayRecordV0[];
22
+ }
23
+ export declare function createRecordReplayModelGatewayAdapterV0(input: RecordReplayModelGatewayInputV0): RecordReplayModelGatewayAdapterV0;
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/model-gateway-record-replay/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,0BAA0B,EAC3B,MAAM,WAAW,CAAC;AAEnB,OAAO,EAIL,KAAK,mCAAmC,EACzC,MAAM,UAAU,CAAC;AAElB,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,4BAA4B,CAAC;IAC/C,QAAQ,CAAC,QAAQ,EAAE;QACjB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;QAC1B,QAAQ,CAAC,KAAK,EAAE,0BAA0B,CAAC;KAC5C,CAAC;CACH;AAED,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,4BAA4B,CAAC;IAC/C,QAAQ,CAAC,KAAK,EAAE,0BAA0B,CAAC;CAC5C;AAED,MAAM,WAAW,iCACf,SAAQ,mCAAmC;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,SAAS,8BAA8B,EAAE,CAAC;IAChE,QAAQ,CAAC,SAAS,EAAE,MAAM,MAAM,CAAC;CAClC;AAED,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,CAAC,OAAO,EAAE,SAAS,gCAAgC,EAAE,CAAC;CAC/D;AAED,wBAAgB,uCAAuC,CACrD,KAAK,EAAE,+BAA+B,GACrC,iCAAiC,CAyCnC"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createRecordReplayModelGatewayAdapterV0 = createRecordReplayModelGatewayAdapterV0;
4
+ const json_1 = require("../json");
5
+ const types_1 = require("../types");
6
+ function createRecordReplayModelGatewayAdapterV0(input) {
7
+ const records = input.records.map((record) => normalizeRecord(record));
8
+ const calls = [];
9
+ let cursor = 0;
10
+ return {
11
+ invoke(request) {
12
+ const requestCopy = (0, json_1.cloneAdapterJsonValueV0)(request);
13
+ const record = records[cursor];
14
+ if (record === undefined) {
15
+ throw new Error("record-replay model gateway has no remaining records");
16
+ }
17
+ const expected = (0, json_1.renderAdapterJsonV0)(record.request);
18
+ const actual = (0, json_1.renderAdapterJsonV0)(requestCopy);
19
+ if (actual !== expected) {
20
+ throw new Error(`record-replay model gateway request mismatch at record ${record.id}`);
21
+ }
22
+ cursor += 1;
23
+ const usage = (0, types_1.cloneModelGatewayUsageV0)(record.response.usage);
24
+ calls.push({
25
+ record_id: record.id,
26
+ request: requestCopy,
27
+ usage,
28
+ });
29
+ return {
30
+ payload: (0, json_1.cloneAdapterJsonValueV0)(record.response.payload),
31
+ usage,
32
+ };
33
+ },
34
+ calls() {
35
+ return calls.map((call) => (0, json_1.cloneAdapterJsonValueV0)(call));
36
+ },
37
+ remaining() {
38
+ return records.length - cursor;
39
+ },
40
+ };
41
+ }
42
+ function normalizeRecord(record) {
43
+ if (record.id.length === 0) {
44
+ throw new Error("record-replay model gateway record id must be non-empty");
45
+ }
46
+ (0, types_1.assertModelGatewayUsageV0)(record.response.usage);
47
+ return {
48
+ id: record.id,
49
+ request: (0, json_1.cloneAdapterJsonValueV0)(record.request),
50
+ response: {
51
+ payload: (0, json_1.cloneAdapterJsonValueV0)(record.response.payload),
52
+ usage: (0, types_1.cloneModelGatewayUsageV0)(record.response.usage),
53
+ },
54
+ };
55
+ }
@@ -0,0 +1,3 @@
1
+ import type { ReactorSandboxAdapterV0, ReactorSandboxResponseV0 } from "../../sdk";
2
+ export declare function createNullSandboxAdapterV0(response?: ReactorSandboxResponseV0): ReactorSandboxAdapterV0;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/sandbox-null/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAEnF,wBAAgB,0BAA0B,CACxC,QAAQ,GAAE,wBAAmE,GAC5E,uBAAuB,CAIzB"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNullSandboxAdapterV0 = createNullSandboxAdapterV0;
4
+ function createNullSandboxAdapterV0(response = { exit_code: 0, stdout: "", stderr: "" }) {
5
+ return {
6
+ run: () => ({ ...response }),
7
+ };
8
+ }