@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
@@ -0,0 +1,201 @@
1
+ import { type ContentHashV0, type NullReceiptSignatureV0, type ReceiptRecheckKindV0, type ReceiptV0 } from "../receipt";
2
+ import type { PolicyRecompileDecisionV0, PolicyRecompileExecutionV0, PolicyRollbackDecisionV0, PolicyTransitiveFreshnessFunctionV0 } from "../policy";
3
+ import { type ReactorExitBundleFailureV0, type ReactorExitBundleRegistrySnapshotV0, type ReactorExitBundleSafeStateV0, type ReactorExitBundleV0 } from "./exit-bundle";
4
+ export * from "./exit-bundle";
5
+ export interface ReactorClockAdapterV0 {
6
+ readonly now: () => string;
7
+ }
8
+ export interface ReactorStorageAdapterV0 {
9
+ readonly appendReceipt: (receipt: ReceiptV0) => void;
10
+ readonly listReceipts: () => readonly ReceiptV0[];
11
+ readonly readRegistry: () => ReactorRegistrySnapshotV0;
12
+ readonly writeRegistry?: (registry: ReactorRegistrySnapshotV0) => void;
13
+ }
14
+ export interface ReactorModelGatewayAdapterV0 {
15
+ readonly invoke: (request: ReactorModelGatewayRequestV0) => ReactorModelGatewayResponseV0;
16
+ }
17
+ export interface ReactorAgentSdkAdapterV0 {
18
+ readonly launch: (request: ReactorAgentRequestV0) => ReactorAgentResponseV0;
19
+ }
20
+ export interface ReactorSandboxAdapterV0 {
21
+ readonly run: (request: ReactorSandboxRequestV0) => ReactorSandboxResponseV0;
22
+ }
23
+ export type ReactorSignerAdapterV0 = NullReceiptSignatureV0;
24
+ export interface ReactorConnectorAdapterV0 {
25
+ readonly read: (request: ReactorConnectorRequestV0) => ReactorConnectorResponseV0;
26
+ }
27
+ export interface ReactorEventSinkAdapterV0 {
28
+ readonly emit: (event: ReactorSdkEventV0) => void;
29
+ }
30
+ export interface ReactorAdaptersV0 {
31
+ readonly clock: ReactorClockAdapterV0;
32
+ readonly storage: ReactorStorageAdapterV0;
33
+ readonly modelGateway: ReactorModelGatewayAdapterV0;
34
+ readonly agentSdk: ReactorAgentSdkAdapterV0;
35
+ readonly sandbox: ReactorSandboxAdapterV0;
36
+ readonly signer?: ReactorSignerAdapterV0;
37
+ readonly connectors: ReactorConnectorAdapterV0;
38
+ readonly eventSink: ReactorEventSinkAdapterV0;
39
+ }
40
+ export interface ReactorRegistrySnapshotV0 {
41
+ readonly [key: string]: unknown;
42
+ readonly contract_revision?: ContentHashV0;
43
+ readonly policy_artifact_id?: string;
44
+ readonly policy_artifact_identity?: string;
45
+ readonly policy_artifact_namespace: string;
46
+ readonly policy_artifact_revision: string;
47
+ readonly policy_artifact_validation_state?: ReactorExitBundleRegistrySnapshotV0["validation_state"];
48
+ readonly validation_state?: ReactorExitBundleRegistrySnapshotV0["validation_state"];
49
+ readonly policy_artifact_bytes?: string;
50
+ readonly policy_artifact_content_hash?: ContentHashV0;
51
+ readonly compiled_evidence_plan?: unknown;
52
+ readonly forecast_schedule?: unknown;
53
+ readonly contract_summary?: unknown;
54
+ readonly last_policy_revalidated_at?: string;
55
+ readonly last_recompile_at?: string;
56
+ readonly last_policy_recompile_at?: string;
57
+ readonly last_unforced_deep_at?: string;
58
+ readonly policy_rollback?: ReactorPolicyRollbackMetadataV0;
59
+ readonly transitive_freshness_function?: PolicyTransitiveFreshnessFunctionV0;
60
+ }
61
+ export interface ReactorPolicyRollbackMetadataV0 {
62
+ readonly schema: "openprose.reactor.policy-rollback.metadata";
63
+ readonly v: 0;
64
+ readonly fresh_policy_revision: string;
65
+ readonly fresh_policy_installed_at: string;
66
+ readonly last_known_good: {
67
+ readonly policy_artifact_revision: string;
68
+ readonly judged_activations_before_trip: number;
69
+ readonly registry: ReactorRegistrySnapshotV0;
70
+ };
71
+ }
72
+ export interface ReactorModelGatewayRequestV0 {
73
+ readonly kind: "judge" | "policy-compile" | "spike";
74
+ readonly payload: unknown;
75
+ }
76
+ export interface ReactorModelGatewayResponseV0 {
77
+ readonly payload: unknown;
78
+ readonly usage?: ReactorModelGatewayUsageV0;
79
+ }
80
+ export interface ReactorModelGatewayUsageV0 {
81
+ readonly provider: string;
82
+ readonly model: string;
83
+ readonly tokens: {
84
+ readonly fresh: number;
85
+ readonly reused: number;
86
+ };
87
+ readonly provider_norm?: {
88
+ readonly schema: string;
89
+ readonly [key: string]: unknown;
90
+ };
91
+ }
92
+ export interface ReactorAgentRequestV0 {
93
+ readonly kind: "bounded-activation" | "policy-author";
94
+ readonly payload: unknown;
95
+ }
96
+ export interface ReactorAgentResponseV0 {
97
+ readonly payload: unknown;
98
+ }
99
+ export interface ReactorSandboxRequestV0 {
100
+ readonly command: string;
101
+ readonly args: readonly string[];
102
+ }
103
+ export interface ReactorSandboxResponseV0 {
104
+ readonly exit_code: number;
105
+ readonly stdout: string;
106
+ readonly stderr: string;
107
+ }
108
+ export interface ReactorConnectorRequestV0 {
109
+ readonly source_id: string;
110
+ readonly as_of: string;
111
+ }
112
+ export interface ReactorConnectorResponseV0 {
113
+ readonly payload: unknown;
114
+ readonly content_hash?: ContentHashV0;
115
+ readonly payload_hash?: ContentHashV0;
116
+ readonly receipt?: ReceiptV0;
117
+ }
118
+ export interface ReactorSdkEventV0 {
119
+ readonly type: "ingest";
120
+ readonly responsibility_id: string;
121
+ readonly as_of: string;
122
+ readonly payload: unknown;
123
+ }
124
+ export interface ReactorCreateInputV0 {
125
+ readonly responsibility_id: string;
126
+ readonly adapters: ReactorAdaptersV0;
127
+ }
128
+ export interface ReactorIngestResultV0 {
129
+ readonly accepted: boolean;
130
+ readonly responsibility_id: string;
131
+ readonly as_of: string;
132
+ readonly receipt_hash?: ContentHashV0;
133
+ readonly outcome?: "fresh-judge-receipt" | "memo-hit-receipt" | "forecast-recheck-receipt" | "blocked-escalation-receipt" | "failed-before-write";
134
+ readonly next_due_at?: string;
135
+ readonly due_rechecks?: readonly ReceiptRecheckKindV0[];
136
+ readonly errors?: readonly string[];
137
+ }
138
+ export interface ReactorTickResultV0 {
139
+ readonly accepted: boolean;
140
+ readonly responsibility_id: string;
141
+ readonly as_of: string;
142
+ readonly outcome: "no-work" | "rechecks-completed" | "failed-before-write" | "policy-recompile-failed" | "policy-rollback-failed";
143
+ readonly receipts_appended: number;
144
+ readonly receipt_hashes: readonly ContentHashV0[];
145
+ readonly next_due_at?: string;
146
+ readonly due_rechecks?: readonly ReceiptRecheckKindV0[];
147
+ readonly recheck_results?: readonly ReactorIngestResultV0[];
148
+ readonly policy_recompile?: ReactorPolicyRecompileTickResultV0;
149
+ readonly policy_rollback?: ReactorPolicyRollbackTickResultV0;
150
+ readonly errors?: readonly string[];
151
+ }
152
+ export interface ReactorPolicyRecompileTickResultV0 {
153
+ readonly policy_artifact_revision_before: string;
154
+ readonly policy_artifact_revision_after?: string;
155
+ readonly compiled_evidence_plan_strategy?: "carried-forward";
156
+ readonly decision: PolicyRecompileDecisionV0;
157
+ readonly execution?: PolicyRecompileExecutionV0;
158
+ }
159
+ export interface ReactorPolicyRollbackTickResultV0 {
160
+ readonly policy_artifact_revision_before: string;
161
+ readonly policy_artifact_revision_after?: string;
162
+ readonly fresh_policy_installed_at: string;
163
+ readonly fresh_policy_judged_activations_before_trip: number;
164
+ readonly last_known_good_judged_activations_before_trip: number;
165
+ readonly receipt_hash?: ContentHashV0;
166
+ readonly decision: PolicyRollbackDecisionV0;
167
+ readonly self_trip: PolicyRecompileDecisionV0;
168
+ }
169
+ export type ReactorExportResultV0 = ReactorExitBundleV0 | ReactorExitBundleFailureV0;
170
+ export interface ReactorMemoNamespaceBindingV0 {
171
+ readonly policy_artifact_namespace: string;
172
+ readonly policy_artifact_revision: string;
173
+ }
174
+ export type ReactorImportExitBundleInputV0 = {
175
+ readonly adapters: ReactorAdaptersV0;
176
+ readonly bundle: unknown;
177
+ } | {
178
+ readonly reactor: Pick<ReactorSdkV0, "adapters">;
179
+ readonly bundle: unknown;
180
+ };
181
+ export type ReactorImportExitBundleResultV0 = ReactorImportExitBundleSuccessV0 | ReactorExitBundleFailureV0;
182
+ export interface ReactorImportExitBundleSuccessV0 {
183
+ readonly ok: true;
184
+ readonly imported: true;
185
+ readonly as_of: string;
186
+ readonly receipts_appended: number;
187
+ readonly memo_namespace: ReactorMemoNamespaceBindingV0;
188
+ readonly safe_state: ReactorExitBundleSafeStateV0;
189
+ }
190
+ export interface ReactorSdkV0 {
191
+ readonly adapters: ReactorAdaptersV0;
192
+ readonly ingest: (event: unknown) => ReactorIngestResultV0;
193
+ readonly tick: (as_of?: string) => ReactorTickResultV0;
194
+ readonly receipts: () => readonly ReceiptV0[];
195
+ readonly registry: () => ReactorRegistrySnapshotV0;
196
+ readonly export: () => ReactorExportResultV0;
197
+ }
198
+ export declare function createNullSignerAdapterV0(): ReactorSignerAdapterV0;
199
+ export declare function createReactor(input: ReactorCreateInputV0): ReactorSdkV0;
200
+ export declare function importReactorExitBundleV0(input: ReactorImportExitBundleInputV0): ReactorImportExitBundleResultV0;
201
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sdk/index.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,SAAS,EACf,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,yBAAyB,EACzB,0BAA0B,EAC1B,wBAAwB,EACxB,mCAAmC,EACpC,MAAM,WAAW,CAAC;AACnB,OAAO,EAGL,KAAK,0BAA0B,EAC/B,KAAK,mCAAmC,EACxC,KAAK,4BAA4B,EACjC,KAAK,mBAAmB,EAEzB,MAAM,eAAe,CAAC;AAEvB,cAAc,eAAe,CAAC;AAE9B,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,GAAG,EAAE,MAAM,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,aAAa,EAAE,CAAC,OAAO,EAAE,SAAS,KAAK,IAAI,CAAC;IACrD,QAAQ,CAAC,YAAY,EAAE,MAAM,SAAS,SAAS,EAAE,CAAC;IAClD,QAAQ,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AK,mBAAmB,CAAC;IACvD,QAAQ,CAAC,QAAQ,EAAE,MAAM,SAAS,SAAS,EAAE,CAAC;IAC9C,QAAQ,CAAC,QAAQ,EAAE,MAAM,yBAAyB,CAAC;IACnD,QAAQ,CAAC,MAAM,EAAE,MAAM,qBAAqB,CAAC;CAC9C;AAED,wBAAgB,yBAAyB,IAAI,sBAAsB,CAElE;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,oBAAoB,GAAG,YAAY,CA+GvE;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,8BAA8B,GACpC,+BAA+B,CA6CjC"}
@@ -0,0 +1,418 @@
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
+ exports.createNullSignerAdapterV0 = createNullSignerAdapterV0;
18
+ exports.createReactor = createReactor;
19
+ exports.importReactorExitBundleV0 = importReactorExitBundleV0;
20
+ const reactor_1 = require("../reactor");
21
+ const receipt_1 = require("../receipt");
22
+ const exit_bundle_1 = require("./exit-bundle");
23
+ __exportStar(require("./exit-bundle"), exports);
24
+ function createNullSignerAdapterV0() {
25
+ return (0, receipt_1.createNullSignerReceiptSignatureV0)();
26
+ }
27
+ function createReactor(input) {
28
+ if (input.responsibility_id.length === 0) {
29
+ throw new Error("responsibility_id must be non-empty");
30
+ }
31
+ assertAdapters(input.adapters);
32
+ const adapters = normalizeAdapters(input.adapters);
33
+ const runtime = (0, reactor_1.createRuntimeReactorV0)({ ...input, adapters });
34
+ return {
35
+ adapters,
36
+ ingest: runtime.ingest,
37
+ tick: runtime.tick,
38
+ receipts() {
39
+ return runtime.receipts();
40
+ },
41
+ registry() {
42
+ return runtime.registry();
43
+ },
44
+ export() {
45
+ const asOf = adapters.clock.now();
46
+ const receipts = adapters.storage.listReceipts();
47
+ const registry = adapters.storage.readRegistry();
48
+ const exportableRegistry = readExportableRegistry(registry);
49
+ if (!exportableRegistry.ok) {
50
+ return exportableRegistry.failure;
51
+ }
52
+ try {
53
+ return (0, exit_bundle_1.buildReactorExitBundleV0)({
54
+ contract_revision: exportableRegistry.registry.contract_revision,
55
+ active_policy_artifact: {
56
+ id: exportableRegistry.registry.policy_artifact_id,
57
+ identity: exportableRegistry.registry.policy_artifact_identity,
58
+ namespace: exportableRegistry.registry.policy_artifact_namespace,
59
+ revision: exportableRegistry.registry.policy_artifact_revision,
60
+ validation_state: exportableRegistry.registry.policy_artifact_validation_state,
61
+ ...(exportableRegistry.registry.policy_artifact_bytes === undefined
62
+ ? {}
63
+ : { bytes: exportableRegistry.registry.policy_artifact_bytes }),
64
+ ...(exportableRegistry.registry.policy_artifact_content_hash === undefined
65
+ ? {}
66
+ : {
67
+ content_hash: exportableRegistry.registry.policy_artifact_content_hash,
68
+ }),
69
+ },
70
+ receipts,
71
+ dependency_receipt_pins: collectDependencyReceiptPins(receipts),
72
+ runtime_registry: {
73
+ contract_revision: exportableRegistry.registry.contract_revision,
74
+ policy_artifact_id: exportableRegistry.registry.policy_artifact_id,
75
+ policy_artifact_identity: exportableRegistry.registry.policy_artifact_identity,
76
+ policy_artifact_namespace: exportableRegistry.registry.policy_artifact_namespace,
77
+ policy_artifact_revision: exportableRegistry.registry.policy_artifact_revision,
78
+ policy_artifact_validation_state: exportableRegistry.registry.policy_artifact_validation_state,
79
+ ...(exportableRegistry.registry.validation_state === undefined
80
+ ? {}
81
+ : { validation_state: exportableRegistry.registry.validation_state }),
82
+ ...(exportableRegistry.registry.policy_artifact_bytes === undefined
83
+ ? {}
84
+ : {
85
+ policy_artifact_bytes: exportableRegistry.registry.policy_artifact_bytes,
86
+ }),
87
+ ...(exportableRegistry.registry.policy_artifact_content_hash === undefined
88
+ ? {}
89
+ : {
90
+ policy_artifact_content_hash: exportableRegistry.registry.policy_artifact_content_hash,
91
+ }),
92
+ ...(exportableRegistry.registry.transitive_freshness_function === undefined
93
+ ? {}
94
+ : {
95
+ transitive_freshness_function: exportableRegistry.registry.transitive_freshness_function,
96
+ }),
97
+ ...(exportableRegistry.registry.compiled_evidence_plan === undefined
98
+ ? {}
99
+ : {
100
+ compiled_evidence_plan: exportableRegistry.registry.compiled_evidence_plan,
101
+ }),
102
+ ...(exportableRegistry.registry.forecast_schedule === undefined
103
+ ? {}
104
+ : {
105
+ forecast_schedule: exportableRegistry.registry.forecast_schedule,
106
+ }),
107
+ },
108
+ memo_namespace_binding: {
109
+ policy_artifact_namespace: exportableRegistry.registry.policy_artifact_namespace,
110
+ policy_artifact_revision: exportableRegistry.registry.policy_artifact_revision,
111
+ },
112
+ as_of: asOf,
113
+ });
114
+ }
115
+ catch (error) {
116
+ return (0, exit_bundle_1.createReactorExitBundleFailureV0)("malformed-bundle", [
117
+ error instanceof Error ? error.message : "exit bundle build failed",
118
+ ]);
119
+ }
120
+ },
121
+ };
122
+ }
123
+ function importReactorExitBundleV0(input) {
124
+ const rawAdapters = readImportAdapters(input);
125
+ assertAdapters(rawAdapters);
126
+ const adapters = normalizeAdapters(rawAdapters);
127
+ const verification = (0, exit_bundle_1.verifyReactorExitBundleV0)(input.bundle);
128
+ if (!verification.ok) {
129
+ return verification;
130
+ }
131
+ const bundle = verification.bundle;
132
+ const asOf = adapters.clock.now();
133
+ const registry = adapters.storage.readRegistry();
134
+ const compatibility = verifyLocalImportCompatibility(registry, bundle);
135
+ if (!compatibility.ok) {
136
+ return compatibility.failure;
137
+ }
138
+ const writeRegistry = adapters.storage.writeRegistry;
139
+ if (typeof writeRegistry !== "function") {
140
+ return (0, exit_bundle_1.createReactorExitBundleFailureV0)("invalid-policy-artifact", [
141
+ "storage.writeRegistry adapter is required before importing receipts",
142
+ ]);
143
+ }
144
+ try {
145
+ writeRegistry(hydrateRegistryFromExitBundle(bundle));
146
+ }
147
+ catch (error) {
148
+ return (0, exit_bundle_1.createReactorExitBundleFailureV0)("invalid-policy-artifact", [
149
+ error instanceof Error ? error.message : "registry hydration failed",
150
+ ]);
151
+ }
152
+ for (const receipt of bundle.receipt_log.entries) {
153
+ adapters.storage.appendReceipt(receipt);
154
+ }
155
+ return {
156
+ ok: true,
157
+ imported: true,
158
+ as_of: asOf,
159
+ receipts_appended: bundle.receipt_log.entries.length,
160
+ memo_namespace: bundle.memo_namespace,
161
+ safe_state: bundle.safe_state,
162
+ };
163
+ }
164
+ function assertAdapters(adapters) {
165
+ assertFunction(adapters.clock?.now, "clock.now");
166
+ assertFunction(adapters.storage?.appendReceipt, "storage.appendReceipt");
167
+ assertFunction(adapters.storage?.listReceipts, "storage.listReceipts");
168
+ assertFunction(adapters.storage?.readRegistry, "storage.readRegistry");
169
+ assertFunction(adapters.modelGateway?.invoke, "modelGateway.invoke");
170
+ assertFunction(adapters.agentSdk?.launch, "agentSdk.launch");
171
+ assertFunction(adapters.sandbox?.run, "sandbox.run");
172
+ const signer = adapters.signer;
173
+ if (signer !== undefined) {
174
+ assertNullSignerAdapter(signer);
175
+ }
176
+ assertFunction(adapters.connectors?.read, "connectors.read");
177
+ assertFunction(adapters.eventSink?.emit, "eventSink.emit");
178
+ }
179
+ function normalizeAdapters(adapters) {
180
+ return {
181
+ ...adapters,
182
+ signer: adapters.signer ?? createNullSignerAdapterV0(),
183
+ };
184
+ }
185
+ function assertNullSignerAdapter(value) {
186
+ if (!isRecord(value)) {
187
+ throw new Error("signer adapter must be the null signer state in receipt v0.1");
188
+ }
189
+ const keys = Object.keys(value).sort();
190
+ const expectedKeys = ["null_reason", "scheme"];
191
+ if (keys.length !== expectedKeys.length ||
192
+ keys.some((key, index) => key !== expectedKeys[index])) {
193
+ throw new Error("signer adapter support is honestly deferred in receipt v0.1; only {scheme:\"none\", null_reason:\"no-signer-adapter-configured\"} is supported");
194
+ }
195
+ if (value["scheme"] !== "none" ||
196
+ value["null_reason"] !== "no-signer-adapter-configured") {
197
+ throw new Error("signer adapter support is honestly deferred in receipt v0.1; only {scheme:\"none\", null_reason:\"no-signer-adapter-configured\"} is supported");
198
+ }
199
+ }
200
+ function assertFunction(value, name) {
201
+ if (typeof value !== "function") {
202
+ throw new Error(`${name} adapter is required`);
203
+ }
204
+ }
205
+ function readImportAdapters(input) {
206
+ return "adapters" in input ? input.adapters : input.reactor.adapters;
207
+ }
208
+ function verifyLocalImportCompatibility(registry, bundle) {
209
+ if (!registryHasActivePolicy(registry)) {
210
+ return { ok: true };
211
+ }
212
+ if (registry.contract_revision !== undefined &&
213
+ registry.contract_revision !== bundle.contract_revision) {
214
+ return {
215
+ ok: false,
216
+ failure: (0, exit_bundle_1.createReactorExitBundleFailureV0)("invalid-contract-revision", [
217
+ `local registry ${registry.contract_revision} does not match bundle ${bundle.contract_revision}`,
218
+ ]),
219
+ };
220
+ }
221
+ if (registry.policy_artifact_namespace !==
222
+ bundle.memo_namespace.policy_artifact_namespace ||
223
+ registry.policy_artifact_revision !==
224
+ bundle.memo_namespace.policy_artifact_revision) {
225
+ return {
226
+ ok: false,
227
+ failure: (0, exit_bundle_1.createReactorExitBundleFailureV0)("memo-namespace-mismatch", [
228
+ `local registry ${registry.policy_artifact_namespace}@${registry.policy_artifact_revision} does not match bundle ${bundle.memo_namespace.policy_artifact_namespace}@${bundle.memo_namespace.policy_artifact_revision}`,
229
+ ]),
230
+ };
231
+ }
232
+ if (registry.policy_artifact_identity !== undefined &&
233
+ registry.policy_artifact_identity !== bundle.policy_artifact.identity) {
234
+ return {
235
+ ok: false,
236
+ failure: (0, exit_bundle_1.createReactorExitBundleFailureV0)("invalid-policy-artifact", [
237
+ `local policy artifact ${registry.policy_artifact_identity} does not match bundle ${bundle.policy_artifact.identity}`,
238
+ ]),
239
+ };
240
+ }
241
+ if (registry.policy_artifact_content_hash !== undefined &&
242
+ bundle.policy_artifact.content_hash !== undefined &&
243
+ registry.policy_artifact_content_hash !== bundle.policy_artifact.content_hash) {
244
+ return {
245
+ ok: false,
246
+ failure: (0, exit_bundle_1.createReactorExitBundleFailureV0)("invalid-policy-artifact", [
247
+ `local policy artifact hash ${registry.policy_artifact_content_hash} does not match bundle ${bundle.policy_artifact.content_hash}`,
248
+ ]),
249
+ };
250
+ }
251
+ return { ok: true };
252
+ }
253
+ function registryHasActivePolicy(registry) {
254
+ const hasMaterialPolicyState = registry.contract_revision !== undefined ||
255
+ registry.policy_artifact_id !== undefined ||
256
+ registry.policy_artifact_identity !== undefined ||
257
+ registry.policy_artifact_validation_state !== undefined ||
258
+ registry.validation_state !== undefined ||
259
+ registry.policy_artifact_bytes !== undefined ||
260
+ registry.policy_artifact_content_hash !== undefined ||
261
+ registry.compiled_evidence_plan !== undefined ||
262
+ registry.forecast_schedule !== undefined;
263
+ if (hasMaterialPolicyState) {
264
+ return true;
265
+ }
266
+ return !(registry.policy_artifact_namespace === "policy.uninitialized" &&
267
+ registry.policy_artifact_revision === "0");
268
+ }
269
+ function hydrateRegistryFromExitBundle(bundle) {
270
+ const registry = bundle.runtime_registry;
271
+ return {
272
+ contract_revision: bundle.contract_revision,
273
+ policy_artifact_id: registry.policy_artifact_id,
274
+ policy_artifact_identity: registry.policy_artifact_identity,
275
+ policy_artifact_namespace: registry.policy_artifact_namespace,
276
+ policy_artifact_revision: registry.policy_artifact_revision,
277
+ policy_artifact_validation_state: registry.policy_artifact_validation_state,
278
+ ...(registry.validation_state === undefined
279
+ ? {}
280
+ : { validation_state: registry.validation_state }),
281
+ ...(registry.policy_artifact_bytes === undefined
282
+ ? {}
283
+ : { policy_artifact_bytes: registry.policy_artifact_bytes }),
284
+ ...(registry.policy_artifact_content_hash === undefined
285
+ ? {}
286
+ : {
287
+ policy_artifact_content_hash: registry.policy_artifact_content_hash,
288
+ }),
289
+ ...(registry.transitive_freshness_function === undefined
290
+ ? {}
291
+ : {
292
+ transitive_freshness_function: registry.transitive_freshness_function,
293
+ }),
294
+ ...(registry.compiled_evidence_plan === undefined
295
+ ? {}
296
+ : { compiled_evidence_plan: registry.compiled_evidence_plan }),
297
+ ...(registry.forecast_schedule === undefined
298
+ ? {}
299
+ : { forecast_schedule: registry.forecast_schedule }),
300
+ };
301
+ }
302
+ function readExportableRegistry(registry) {
303
+ const errors = [];
304
+ const contractRevision = registry.contract_revision;
305
+ const policyArtifactId = registry.policy_artifact_id ?? registry.policy_artifact_identity;
306
+ const policyArtifactIdentity = registry.policy_artifact_identity ?? registry.policy_artifact_id;
307
+ const validationState = registry.policy_artifact_validation_state ?? registry.validation_state;
308
+ const validationStateAlias = registry.validation_state;
309
+ const artifactContentHash = registry.policy_artifact_content_hash;
310
+ if (!isContentHash(contractRevision)) {
311
+ errors.push("registry.contract_revision must be a sha256 content address");
312
+ }
313
+ if (typeof policyArtifactId !== "string" || policyArtifactId.length === 0) {
314
+ errors.push("registry.policy_artifact_id must be non-empty");
315
+ }
316
+ if (typeof policyArtifactIdentity !== "string" ||
317
+ policyArtifactIdentity.length === 0) {
318
+ errors.push("registry.policy_artifact_identity must be non-empty");
319
+ }
320
+ if (registry.policy_artifact_namespace.length === 0) {
321
+ errors.push("registry.policy_artifact_namespace must be non-empty");
322
+ }
323
+ if (registry.policy_artifact_revision.length === 0) {
324
+ errors.push("registry.policy_artifact_revision must be non-empty");
325
+ }
326
+ if (!isPolicyArtifactValidationState(validationState)) {
327
+ errors.push("registry.policy_artifact_validation_state must be present");
328
+ }
329
+ if (validationStateAlias !== undefined &&
330
+ !isPolicyArtifactValidationState(validationStateAlias)) {
331
+ errors.push("registry.validation_state must be a valid policy artifact validation state");
332
+ }
333
+ if (registry.policy_artifact_bytes === undefined &&
334
+ !isContentHash(artifactContentHash)) {
335
+ errors.push("registry must include policy_artifact_bytes or policy_artifact_content_hash");
336
+ }
337
+ if (artifactContentHash !== undefined &&
338
+ !isContentHash(artifactContentHash)) {
339
+ errors.push("registry.policy_artifact_content_hash must be a sha256 content address");
340
+ }
341
+ if (errors.length > 0) {
342
+ return {
343
+ ok: false,
344
+ failure: (0, exit_bundle_1.createReactorExitBundleFailureV0)("malformed-bundle", errors),
345
+ };
346
+ }
347
+ return {
348
+ ok: true,
349
+ registry: {
350
+ contract_revision: contractRevision,
351
+ policy_artifact_id: policyArtifactId,
352
+ policy_artifact_identity: policyArtifactIdentity,
353
+ policy_artifact_namespace: registry.policy_artifact_namespace,
354
+ policy_artifact_revision: registry.policy_artifact_revision,
355
+ policy_artifact_validation_state: validationState,
356
+ ...(validationStateAlias === undefined
357
+ ? {}
358
+ : {
359
+ validation_state: validationStateAlias,
360
+ }),
361
+ ...(registry.policy_artifact_bytes === undefined
362
+ ? {}
363
+ : { policy_artifact_bytes: registry.policy_artifact_bytes }),
364
+ ...(artifactContentHash === undefined
365
+ ? {}
366
+ : {
367
+ policy_artifact_content_hash: artifactContentHash,
368
+ }),
369
+ ...(registry.transitive_freshness_function === undefined
370
+ ? {}
371
+ : {
372
+ transitive_freshness_function: registry.transitive_freshness_function,
373
+ }),
374
+ ...(registry.compiled_evidence_plan === undefined
375
+ ? {}
376
+ : { compiled_evidence_plan: registry.compiled_evidence_plan }),
377
+ ...(registry.forecast_schedule === undefined
378
+ ? {}
379
+ : { forecast_schedule: registry.forecast_schedule }),
380
+ },
381
+ };
382
+ }
383
+ function collectDependencyReceiptPins(receipts) {
384
+ const pins = new Map();
385
+ for (const receipt of receipts) {
386
+ for (const pin of receipt.composition.consumed_receipts) {
387
+ const acceptableSignerSet = [...pin.acceptable_signer_set].sort();
388
+ const key = [
389
+ pin.upstream_content_hash,
390
+ pin.contract_revision,
391
+ acceptableSignerSet.join("\0"),
392
+ ].join("\0");
393
+ pins.set(key, {
394
+ upstream_content_hash: pin.upstream_content_hash,
395
+ contract_revision: pin.contract_revision,
396
+ acceptable_signer_set: acceptableSignerSet,
397
+ });
398
+ }
399
+ }
400
+ return [...pins.values()].sort((left, right) => left.upstream_content_hash.localeCompare(right.upstream_content_hash));
401
+ }
402
+ function isPolicyArtifactValidationState(value) {
403
+ if (value === "validated" || value === "degraded" || value === "blocked") {
404
+ return true;
405
+ }
406
+ if (!isRecord(value)) {
407
+ return false;
408
+ }
409
+ return (value["status"] === "validated" ||
410
+ value["status"] === "degraded" ||
411
+ value["status"] === "blocked");
412
+ }
413
+ function isContentHash(value) {
414
+ return typeof value === "string" && /^sha256:[a-f0-9]{64}$/.test(value);
415
+ }
416
+ function isRecord(value) {
417
+ return typeof value === "object" && value !== null && !Array.isArray(value);
418
+ }