@openprose/reactor-cradle 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.
- package/LICENSE +21 -0
- package/README.md +270 -0
- package/dist/assert/index.d.ts +35 -0
- package/dist/assert/index.d.ts.map +1 -0
- package/dist/assert/index.js +398 -0
- package/dist/baselines/cost-thesis/index.d.ts +103 -0
- package/dist/baselines/cost-thesis/index.d.ts.map +1 -0
- package/dist/baselines/cost-thesis/index.js +337 -0
- package/dist/baselines/naive-loop/index.d.ts +46 -0
- package/dist/baselines/naive-loop/index.d.ts.map +1 -0
- package/dist/baselines/naive-loop/index.js +188 -0
- package/dist/baselines/no-memo/index.d.ts +84 -0
- package/dist/baselines/no-memo/index.d.ts.map +1 -0
- package/dist/baselines/no-memo/index.js +226 -0
- package/dist/doubles/clock.d.ts +9 -0
- package/dist/doubles/clock.d.ts.map +1 -0
- package/dist/doubles/clock.js +42 -0
- package/dist/doubles/storage.d.ts +24 -0
- package/dist/doubles/storage.d.ts.map +1 -0
- package/dist/doubles/storage.js +191 -0
- package/dist/eval/index.d.ts +204 -0
- package/dist/eval/index.d.ts.map +1 -0
- package/dist/eval/index.js +596 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/policy-author/index.d.ts +103 -0
- package/dist/policy-author/index.d.ts.map +1 -0
- package/dist/policy-author/index.js +358 -0
- package/dist/policy-drift/index.d.ts +64 -0
- package/dist/policy-drift/index.d.ts.map +1 -0
- package/dist/policy-drift/index.js +495 -0
- package/dist/policy-replay/index.d.ts +106 -0
- package/dist/policy-replay/index.d.ts.map +1 -0
- package/dist/policy-replay/index.js +361 -0
- package/dist/provider-parity/index.d.ts +91 -0
- package/dist/provider-parity/index.d.ts.map +1 -0
- package/dist/provider-parity/index.js +439 -0
- package/dist/recompile/index.d.ts +161 -0
- package/dist/recompile/index.d.ts.map +1 -0
- package/dist/recompile/index.js +690 -0
- package/dist/release-candidate/index.d.ts +139 -0
- package/dist/release-candidate/index.d.ts.map +1 -0
- package/dist/release-candidate/index.js +553 -0
- package/dist/release-parity/index.d.ts +80 -0
- package/dist/release-parity/index.d.ts.map +1 -0
- package/dist/release-parity/index.js +1035 -0
- package/dist/replay/model-gateway.d.ts +25 -0
- package/dist/replay/model-gateway.d.ts.map +1 -0
- package/dist/replay/model-gateway.js +166 -0
- package/dist/replay/parity.d.ts +110 -0
- package/dist/replay/parity.d.ts.map +1 -0
- package/dist/replay/parity.js +232 -0
- package/dist/rollback/index.d.ts +106 -0
- package/dist/rollback/index.d.ts.map +1 -0
- package/dist/rollback/index.js +694 -0
- package/dist/scenario/parser.d.ts +11 -0
- package/dist/scenario/parser.d.ts.map +1 -0
- package/dist/scenario/parser.js +490 -0
- package/dist/scenario/runner.d.ts +12 -0
- package/dist/scenario/runner.d.ts.map +1 -0
- package/dist/scenario/runner.js +345 -0
- package/dist/scenario/synthetic-world-adapter.d.ts +4 -0
- package/dist/scenario/synthetic-world-adapter.d.ts.map +1 -0
- package/dist/scenario/synthetic-world-adapter.js +82 -0
- package/dist/scenario/time.d.ts +4 -0
- package/dist/scenario/time.d.ts.map +1 -0
- package/dist/scenario/time.js +45 -0
- package/dist/scenario/types.d.ts +149 -0
- package/dist/scenario/types.d.ts.map +1 -0
- package/dist/scenario/types.js +5 -0
- package/dist/spikes/index.d.ts +10 -0
- package/dist/spikes/index.d.ts.map +1 -0
- package/dist/spikes/index.js +29 -0
- package/dist/spikes/k1-ensemble-spread.d.ts +88 -0
- package/dist/spikes/k1-ensemble-spread.d.ts.map +1 -0
- package/dist/spikes/k1-ensemble-spread.js +396 -0
- package/dist/spikes/k2-policy-author.d.ts +25 -0
- package/dist/spikes/k2-policy-author.d.ts.map +1 -0
- package/dist/spikes/k2-policy-author.js +503 -0
- package/dist/spikes/live-refresh.d.ts +150 -0
- package/dist/spikes/live-refresh.d.ts.map +1 -0
- package/dist/spikes/live-refresh.js +511 -0
- package/dist/world/index.d.ts +2 -0
- package/dist/world/index.d.ts.map +1 -0
- package/dist/world/index.js +17 -0
- package/dist/world/synthetic-world.d.ts +104 -0
- package/dist/world/synthetic-world.d.ts.map +1 -0
- package/dist/world/synthetic-world.js +449 -0
- package/package.json +139 -0
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.POLICY_REPLAY_P5_SCENARIO_VERSION_V0 = exports.POLICY_REPLAY_P5_SCENARIO_SCHEMA_V0 = void 0;
|
|
4
|
+
exports.makeRecordedPolicyReplayP5ScenarioV0 = makeRecordedPolicyReplayP5ScenarioV0;
|
|
5
|
+
exports.assertRecordedPolicyReplayP5ScenarioV0 = assertRecordedPolicyReplayP5ScenarioV0;
|
|
6
|
+
exports.readRecordedPolicyArtifactFromRegistryV0 = readRecordedPolicyArtifactFromRegistryV0;
|
|
7
|
+
exports.createPolicyReplayP5WithheldGatewayProbeV0 = createPolicyReplayP5WithheldGatewayProbeV0;
|
|
8
|
+
exports.createRecordedArtifactPolicyRecompileReplayV0 = createRecordedArtifactPolicyRecompileReplayV0;
|
|
9
|
+
exports.runRecordedPolicyReplayP5ProofV0 = runRecordedPolicyReplayP5ProofV0;
|
|
10
|
+
const recompile_1 = require("../recompile");
|
|
11
|
+
const { validatePolicyArtifactV0 } = loadReactorPolicy();
|
|
12
|
+
exports.POLICY_REPLAY_P5_SCENARIO_SCHEMA_V0 = "openprose.reactor-cradle.policy-replay-p5-scenario";
|
|
13
|
+
exports.POLICY_REPLAY_P5_SCENARIO_VERSION_V0 = 0;
|
|
14
|
+
function makeRecordedPolicyReplayP5ScenarioV0() {
|
|
15
|
+
const recompileScenario = (0, recompile_1.makeRecordedPolicyRecompileD1ScenarioV0)();
|
|
16
|
+
const recordedRegistrySnapshot = recompileScenario.recompiled_registry_snapshot;
|
|
17
|
+
const authority = readRecordedPolicyArtifactFromRegistryV0(recordedRegistrySnapshot);
|
|
18
|
+
return {
|
|
19
|
+
schema: exports.POLICY_REPLAY_P5_SCENARIO_SCHEMA_V0,
|
|
20
|
+
v: exports.POLICY_REPLAY_P5_SCENARIO_VERSION_V0,
|
|
21
|
+
responsibility_id: recompileScenario.responsibility_id,
|
|
22
|
+
contract_revision: recompileScenario.contract_revision,
|
|
23
|
+
as_of: recompileScenario.as_of,
|
|
24
|
+
last_recompile_at: recompileScenario.last_recompile_at_blocked,
|
|
25
|
+
last_policy_revalidated_at: recompileScenario.last_recompile_at_blocked,
|
|
26
|
+
last_unforced_deep_at: recompileScenario.last_recompile_at_blocked,
|
|
27
|
+
source_policy_loop: "p3-recorded-recompile",
|
|
28
|
+
receipt_history: recompileScenario.receipt_history,
|
|
29
|
+
recorded_registry_snapshot: recordedRegistrySnapshot,
|
|
30
|
+
recorded_policy_artifact_bytes: authority.bytes,
|
|
31
|
+
recorded_policy_artifact_content_hash: authority.content_hash,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function assertRecordedPolicyReplayP5ScenarioV0(scenario) {
|
|
35
|
+
if (scenario.schema !== exports.POLICY_REPLAY_P5_SCENARIO_SCHEMA_V0) {
|
|
36
|
+
throw new Error("policy replay P5 scenario schema is malformed");
|
|
37
|
+
}
|
|
38
|
+
if (scenario.v !== exports.POLICY_REPLAY_P5_SCENARIO_VERSION_V0) {
|
|
39
|
+
throw new Error("policy replay P5 scenario version must be 0");
|
|
40
|
+
}
|
|
41
|
+
if (scenario.source_policy_loop !== "p3-recorded-recompile") {
|
|
42
|
+
throw new Error("policy replay P5 scenario must come from the recorded P3 recompile loop");
|
|
43
|
+
}
|
|
44
|
+
if (scenario.responsibility_id.length === 0) {
|
|
45
|
+
throw new Error("policy replay P5 scenario responsibility_id is required");
|
|
46
|
+
}
|
|
47
|
+
if (!isContentHash(scenario.contract_revision)) {
|
|
48
|
+
throw new Error("policy replay P5 scenario contract_revision must be a sha256 content hash");
|
|
49
|
+
}
|
|
50
|
+
parseReplayableInstantMs(scenario.as_of, "policy replay P5 scenario as_of");
|
|
51
|
+
parseReplayableInstantMs(scenario.last_recompile_at, "policy replay P5 scenario last_recompile_at");
|
|
52
|
+
parseReplayableInstantMs(scenario.last_policy_revalidated_at, "policy replay P5 scenario last_policy_revalidated_at");
|
|
53
|
+
parseReplayableInstantMs(scenario.last_unforced_deep_at, "policy replay P5 scenario last_unforced_deep_at");
|
|
54
|
+
if (scenario.receipt_history.length === 0) {
|
|
55
|
+
throw new Error("policy replay P5 scenario must include recorded receipt history");
|
|
56
|
+
}
|
|
57
|
+
const authority = readRecordedPolicyArtifactFromRegistryV0(scenario.recorded_registry_snapshot);
|
|
58
|
+
if (authority.bytes !== scenario.recorded_policy_artifact_bytes) {
|
|
59
|
+
throw new Error("policy replay P5 recorded artifact bytes must match the registry snapshot");
|
|
60
|
+
}
|
|
61
|
+
if (authority.content_hash !== scenario.recorded_policy_artifact_content_hash) {
|
|
62
|
+
throw new Error("policy replay P5 recorded artifact content hash must match the registry snapshot");
|
|
63
|
+
}
|
|
64
|
+
if (authority.artifact.responsibility_id !== scenario.responsibility_id) {
|
|
65
|
+
throw new Error("policy replay P5 artifact changed responsibility_id");
|
|
66
|
+
}
|
|
67
|
+
if (authority.artifact.provenance.contract_revision !== scenario.contract_revision) {
|
|
68
|
+
throw new Error("policy replay P5 artifact changed contract_revision");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function readRecordedPolicyArtifactFromRegistryV0(snapshot) {
|
|
72
|
+
const validationStatus = readRegistryValidationStatus(snapshot);
|
|
73
|
+
if (validationStatus !== "validated") {
|
|
74
|
+
throw new Error("policy replay P5 registry snapshot must be validated");
|
|
75
|
+
}
|
|
76
|
+
const namespace = readNonEmptyString(snapshot.policy_artifact_namespace, "policy replay P5 registry namespace");
|
|
77
|
+
const revision = readNonEmptyString(snapshot.policy_artifact_revision, "policy replay P5 registry revision");
|
|
78
|
+
const bytes = readNonEmptyString(snapshot.policy_artifact_bytes, "policy replay P5 registry must carry recorded policy artifact bytes");
|
|
79
|
+
const contentHash = readContentHash(snapshot.policy_artifact_content_hash, "policy replay P5 registry must carry recorded policy artifact content hash");
|
|
80
|
+
const parsed = parseCanonicalJson(bytes, "policy replay P5 artifact bytes");
|
|
81
|
+
const validation = validatePolicyArtifactV0(parsed);
|
|
82
|
+
if (!validation.ok) {
|
|
83
|
+
throw new Error(`policy replay P5 recorded artifact bytes are invalid: ${validation.errors.join("; ")}`);
|
|
84
|
+
}
|
|
85
|
+
if (validation.bytes !== bytes) {
|
|
86
|
+
throw new Error("policy replay P5 recorded artifact bytes are not canonical");
|
|
87
|
+
}
|
|
88
|
+
if (validation.content_hash !== contentHash) {
|
|
89
|
+
throw new Error(`policy replay P5 recorded artifact content hash is stale: expected ${validation.content_hash}, received ${contentHash}`);
|
|
90
|
+
}
|
|
91
|
+
if (validation.artifact.policy_revision !== revision) {
|
|
92
|
+
throw new Error("policy replay P5 registry revision does not match recorded artifact bytes");
|
|
93
|
+
}
|
|
94
|
+
if (namespace !== validation.artifact.registry_id) {
|
|
95
|
+
throw new Error("policy replay P5 registry namespace does not match recorded artifact bytes");
|
|
96
|
+
}
|
|
97
|
+
if (snapshot.contract_revision !== undefined &&
|
|
98
|
+
snapshot.contract_revision !== validation.artifact.provenance.contract_revision) {
|
|
99
|
+
throw new Error("policy replay P5 registry contract revision does not match recorded artifact bytes");
|
|
100
|
+
}
|
|
101
|
+
if (snapshot.policy_artifact_id !== undefined &&
|
|
102
|
+
snapshot.policy_artifact_id !== validation.artifact.registry_id) {
|
|
103
|
+
throw new Error("policy replay P5 registry artifact id does not match recorded artifact bytes");
|
|
104
|
+
}
|
|
105
|
+
if (snapshot.policy_artifact_identity !== undefined &&
|
|
106
|
+
snapshot.policy_artifact_identity !== validation.artifact.registry_id) {
|
|
107
|
+
throw new Error("policy replay P5 registry artifact identity does not match recorded artifact bytes");
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
source: "recorded-registry-snapshot-bytes",
|
|
111
|
+
artifact: validation.artifact,
|
|
112
|
+
bytes: validation.bytes,
|
|
113
|
+
content_hash: validation.content_hash,
|
|
114
|
+
byte_length: Buffer.byteLength(validation.bytes, "utf8"),
|
|
115
|
+
namespace,
|
|
116
|
+
registry_id: validation.artifact.registry_id,
|
|
117
|
+
revision,
|
|
118
|
+
validation_state: "validated",
|
|
119
|
+
artifact_bytes_canonical: true,
|
|
120
|
+
content_hash_verified: true,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function createPolicyReplayP5WithheldGatewayProbeV0() {
|
|
124
|
+
let agentLaunchCount = 0;
|
|
125
|
+
let modelGatewayInvocationCount = 0;
|
|
126
|
+
let policyAuthorInvocationCount = 0;
|
|
127
|
+
const agentSdk = {
|
|
128
|
+
launch(_request) {
|
|
129
|
+
agentLaunchCount += 1;
|
|
130
|
+
throw new Error("policy replay P5 proof must not launch agent SDK");
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
const modelGateway = {
|
|
134
|
+
invoke(_request) {
|
|
135
|
+
modelGatewayInvocationCount += 1;
|
|
136
|
+
throw new Error("policy replay P5 proof must not call model gateway");
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
const authorPolicyArtifactV0 = () => {
|
|
140
|
+
policyAuthorInvocationCount += 1;
|
|
141
|
+
throw new Error("policy replay P5 proof must not re-author policy artifacts");
|
|
142
|
+
};
|
|
143
|
+
return {
|
|
144
|
+
agentSdk,
|
|
145
|
+
agent_sdk: agentSdk,
|
|
146
|
+
modelGateway,
|
|
147
|
+
model_gateway: modelGateway,
|
|
148
|
+
authorPolicyArtifactV0,
|
|
149
|
+
author_policy_artifact_v0: authorPolicyArtifactV0,
|
|
150
|
+
get agent_launch_count() {
|
|
151
|
+
return agentLaunchCount;
|
|
152
|
+
},
|
|
153
|
+
get model_gateway_invocation_count() {
|
|
154
|
+
return modelGatewayInvocationCount;
|
|
155
|
+
},
|
|
156
|
+
get policy_author_invocation_count() {
|
|
157
|
+
return policyAuthorInvocationCount;
|
|
158
|
+
},
|
|
159
|
+
assertNoInvocations() {
|
|
160
|
+
if (agentLaunchCount !== 0 ||
|
|
161
|
+
modelGatewayInvocationCount !== 0 ||
|
|
162
|
+
policyAuthorInvocationCount !== 0) {
|
|
163
|
+
throw new Error(`policy replay P5 proof invoked forbidden replay dependencies: agent=${agentLaunchCount}, model=${modelGatewayInvocationCount}, author=${policyAuthorInvocationCount}`);
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function createRecordedArtifactPolicyRecompileReplayV0(planPolicyRecompileV0) {
|
|
169
|
+
return (input) => planPolicyRecompileV0({
|
|
170
|
+
artifact: input.artifact,
|
|
171
|
+
policy_artifact: input.artifact,
|
|
172
|
+
receipts: input.receipt_history,
|
|
173
|
+
receipt_history: input.receipt_history,
|
|
174
|
+
as_of: input.as_of,
|
|
175
|
+
last_recompile_at: input.last_recompile_at,
|
|
176
|
+
last_policy_recompile_at: input.last_policy_recompile_at,
|
|
177
|
+
last_policy_revalidated_at: input.last_policy_revalidated_at,
|
|
178
|
+
last_unforced_deep_at: input.last_unforced_deep_at,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
async function runRecordedPolicyReplayP5ProofV0(input) {
|
|
182
|
+
const scenario = input.scenario ?? makeRecordedPolicyReplayP5ScenarioV0();
|
|
183
|
+
assertRecordedPolicyReplayP5ScenarioV0(scenario);
|
|
184
|
+
const authority = readRecordedPolicyArtifactFromRegistryV0(scenario.recorded_registry_snapshot);
|
|
185
|
+
const probe = createPolicyReplayP5WithheldGatewayProbeV0();
|
|
186
|
+
const rawReplayResult = await input.replayRecordedPolicyV0(buildReplayRunInput(scenario, authority, probe));
|
|
187
|
+
const replayDecision = (0, recompile_1.normalizePolicyRecompileDecisionV0)(rawReplayResult);
|
|
188
|
+
assertReplayDecisionMatchesRecordedArtifact(replayDecision, authority, scenario);
|
|
189
|
+
probe.assertNoInvocations();
|
|
190
|
+
return {
|
|
191
|
+
scenario,
|
|
192
|
+
replay_authority: authority,
|
|
193
|
+
replay_decision: replayDecision,
|
|
194
|
+
raw_replay_result: rawReplayResult,
|
|
195
|
+
gateway_invocations: {
|
|
196
|
+
agent_launch_count: 0,
|
|
197
|
+
model_gateway_invocation_count: 0,
|
|
198
|
+
},
|
|
199
|
+
policy_author_invocation_count: 0,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function buildReplayRunInput(scenario, authority, probe) {
|
|
203
|
+
return {
|
|
204
|
+
artifact: authority.artifact,
|
|
205
|
+
policy_artifact: authority.artifact,
|
|
206
|
+
recorded_registry_snapshot: scenario.recorded_registry_snapshot,
|
|
207
|
+
recorded_artifact_bytes: authority.bytes,
|
|
208
|
+
recorded_policy_artifact_bytes: authority.bytes,
|
|
209
|
+
recorded_artifact_content_hash: authority.content_hash,
|
|
210
|
+
recorded_policy_artifact_content_hash: authority.content_hash,
|
|
211
|
+
receipt_history: scenario.receipt_history,
|
|
212
|
+
receipts: scenario.receipt_history,
|
|
213
|
+
as_of: scenario.as_of,
|
|
214
|
+
last_recompile_at: scenario.last_recompile_at,
|
|
215
|
+
last_policy_recompile_at: scenario.last_recompile_at,
|
|
216
|
+
last_policy_revalidated_at: scenario.last_policy_revalidated_at,
|
|
217
|
+
last_unforced_deep_at: scenario.last_unforced_deep_at,
|
|
218
|
+
responsibility_id: scenario.responsibility_id,
|
|
219
|
+
contract_revision: scenario.contract_revision,
|
|
220
|
+
policy_artifact_namespace: authority.namespace,
|
|
221
|
+
policy_artifact_revision: authority.revision,
|
|
222
|
+
author_input: {
|
|
223
|
+
responsibility_id: scenario.responsibility_id,
|
|
224
|
+
contract_revision: scenario.contract_revision,
|
|
225
|
+
receipt_history: scenario.receipt_history,
|
|
226
|
+
receipts: scenario.receipt_history,
|
|
227
|
+
as_of: scenario.as_of,
|
|
228
|
+
policy_artifact_namespace: authority.namespace,
|
|
229
|
+
agentSdk: probe.agentSdk,
|
|
230
|
+
},
|
|
231
|
+
agentSdk: probe.agentSdk,
|
|
232
|
+
agent_sdk: probe.agent_sdk,
|
|
233
|
+
modelGateway: probe.modelGateway,
|
|
234
|
+
model_gateway: probe.model_gateway,
|
|
235
|
+
authorPolicyArtifactV0: probe.authorPolicyArtifactV0,
|
|
236
|
+
author_policy_artifact_v0: probe.author_policy_artifact_v0,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function assertReplayDecisionMatchesRecordedArtifact(decision, authority, scenario) {
|
|
240
|
+
if (decision.outcome !== "recompile-delayed") {
|
|
241
|
+
throw new Error(`policy replay P5 expected recorded artifact to replay to recompile-delayed, received ${decision.outcome}`);
|
|
242
|
+
}
|
|
243
|
+
if (decision.drift_outcome !== undefined &&
|
|
244
|
+
decision.drift_outcome !== "tripped") {
|
|
245
|
+
throw new Error(`policy replay P5 must preserve tripped drift evidence, received ${decision.drift_outcome}`);
|
|
246
|
+
}
|
|
247
|
+
if (decision.evidence_receipt_hashes.length === 0) {
|
|
248
|
+
throw new Error("policy replay P5 decision must cite recorded receipt evidence");
|
|
249
|
+
}
|
|
250
|
+
const knownReceiptHashes = new Set(scenario.receipt_history.map((receipt) => receipt.content_hash));
|
|
251
|
+
const unknownHashes = decision.evidence_receipt_hashes.filter((hash) => !knownReceiptHashes.has(hash));
|
|
252
|
+
if (unknownHashes.length > 0) {
|
|
253
|
+
throw new Error(`policy replay P5 decision referenced receipts outside the recorded log: ${unknownHashes.join(", ")}`);
|
|
254
|
+
}
|
|
255
|
+
const raw = readOptionalRecord(decision.raw);
|
|
256
|
+
const rawHash = raw?.["policy_artifact_content_hash"];
|
|
257
|
+
if (rawHash !== undefined && rawHash !== authority.content_hash) {
|
|
258
|
+
throw new Error("policy replay P5 decision changed the artifact content hash");
|
|
259
|
+
}
|
|
260
|
+
const rawRevision = raw?.["policy_artifact_revision"];
|
|
261
|
+
if (rawRevision !== undefined && rawRevision !== authority.revision) {
|
|
262
|
+
throw new Error("policy replay P5 decision changed the artifact revision");
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function readRegistryValidationStatus(snapshot) {
|
|
266
|
+
const validationState = snapshot.policy_artifact_validation_state ?? snapshot.validation_state;
|
|
267
|
+
return typeof validationState === "string"
|
|
268
|
+
? validationState
|
|
269
|
+
: readOptionalRecord(validationState)?.["status"];
|
|
270
|
+
}
|
|
271
|
+
function parseCanonicalJson(value, label) {
|
|
272
|
+
try {
|
|
273
|
+
const parsed = JSON.parse(value);
|
|
274
|
+
const rendered = renderCanonical(parsed);
|
|
275
|
+
if (rendered !== value) {
|
|
276
|
+
throw new Error("payload is not canonical JSON");
|
|
277
|
+
}
|
|
278
|
+
return parsed;
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
const message = error instanceof Error ? error.message : "JSON parse failed";
|
|
282
|
+
throw new Error(`${label} must be canonical JSON: ${message}`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
function renderCanonical(value) {
|
|
286
|
+
if (value === null) {
|
|
287
|
+
return "null";
|
|
288
|
+
}
|
|
289
|
+
switch (typeof value) {
|
|
290
|
+
case "boolean":
|
|
291
|
+
return value ? "true" : "false";
|
|
292
|
+
case "number":
|
|
293
|
+
if (!Number.isFinite(value)) {
|
|
294
|
+
throw new TypeError("Cannot canonicalize non-finite numbers");
|
|
295
|
+
}
|
|
296
|
+
return JSON.stringify(value);
|
|
297
|
+
case "string":
|
|
298
|
+
return JSON.stringify(value);
|
|
299
|
+
case "object":
|
|
300
|
+
if (Array.isArray(value)) {
|
|
301
|
+
return `[${value.map((item) => renderCanonical(item)).join(",")}]`;
|
|
302
|
+
}
|
|
303
|
+
if (!isRecord(value)) {
|
|
304
|
+
throw new TypeError("Cannot canonicalize non-plain objects");
|
|
305
|
+
}
|
|
306
|
+
return `{${Object.keys(value)
|
|
307
|
+
.sort((left, right) => left.localeCompare(right))
|
|
308
|
+
.map((key) => `${JSON.stringify(key)}:${renderCanonical(value[key])}`)
|
|
309
|
+
.join(",")}}`;
|
|
310
|
+
default:
|
|
311
|
+
throw new TypeError(`Cannot canonicalize ${typeof value}`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function readNonEmptyString(value, label) {
|
|
315
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
316
|
+
throw new Error(`${label} must be a non-empty string`);
|
|
317
|
+
}
|
|
318
|
+
return value;
|
|
319
|
+
}
|
|
320
|
+
function readContentHash(value, label) {
|
|
321
|
+
if (typeof value !== "string" || !isContentHash(value)) {
|
|
322
|
+
throw new Error(`${label} must be a sha256 content hash`);
|
|
323
|
+
}
|
|
324
|
+
return value;
|
|
325
|
+
}
|
|
326
|
+
function parseReplayableInstantMs(value, label) {
|
|
327
|
+
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/.test(value)) {
|
|
328
|
+
throw new Error(`${label} must be a replayable UTC ISO instant`);
|
|
329
|
+
}
|
|
330
|
+
const ms = Date.parse(value);
|
|
331
|
+
if (!Number.isSafeInteger(ms)) {
|
|
332
|
+
throw new Error(`${label} must parse to a safe millisecond instant`);
|
|
333
|
+
}
|
|
334
|
+
return ms;
|
|
335
|
+
}
|
|
336
|
+
function isContentHash(value) {
|
|
337
|
+
return /^sha256:[a-f0-9]{64}$/.test(value);
|
|
338
|
+
}
|
|
339
|
+
function readOptionalRecord(value) {
|
|
340
|
+
return isRecord(value) ? value : undefined;
|
|
341
|
+
}
|
|
342
|
+
function isRecord(value) {
|
|
343
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
344
|
+
}
|
|
345
|
+
function loadReactorPolicy() {
|
|
346
|
+
try {
|
|
347
|
+
return require("@openprose/reactor/policy");
|
|
348
|
+
}
|
|
349
|
+
catch (error) {
|
|
350
|
+
if (isMissingReactorSubpath(error, "@openprose/reactor/policy")) {
|
|
351
|
+
return require("../../../reactor/dist/policy");
|
|
352
|
+
}
|
|
353
|
+
throw error;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
function isMissingReactorSubpath(error, subpath) {
|
|
357
|
+
return (isRecord(error) &&
|
|
358
|
+
error["code"] === "MODULE_NOT_FOUND" &&
|
|
359
|
+
typeof error["message"] === "string" &&
|
|
360
|
+
error["message"].includes(subpath));
|
|
361
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { ContentHashV0, ReceiptV0 } from "@openprose/reactor/receipt";
|
|
2
|
+
import type { AuthorPolicyArtifactV0Input, PolicyAuthorHistoryQueryV0, PolicyLiveObservableV0 } from "@openprose/reactor/policy";
|
|
3
|
+
import type { ReactorAgentRequestV0, ReactorAgentSdkAdapterV0, ReactorModelGatewayAdapterV0, ReactorModelGatewayRequestV0, ReactorModelGatewayResponseV0, ReactorModelGatewayUsageV0, ReactorRegistrySnapshotV0 } from "@openprose/reactor/sdk";
|
|
4
|
+
export declare const PROVIDER_PARITY_GATEWAY_REQUEST_SCHEMA_V0: "openprose.reactor-cradle.provider-parity.policy-author-gateway-request";
|
|
5
|
+
export declare const PROVIDER_PARITY_REPORT_SCHEMA_V0: "openprose.reactor-cradle.provider-parity.report";
|
|
6
|
+
export declare const PROVIDER_PARITY_REPORT_VERSION_V0: 0;
|
|
7
|
+
export declare const PROVIDER_PARITY_POLICY_AUTHOR_LAUNCH_REPRESENTATION_V0: "agent-sdk-backed-by-model-gateway";
|
|
8
|
+
export type ProviderParityPolicyAuthorStepV0 = "history-query" | "author-artifact";
|
|
9
|
+
export type ProviderParityAuthorPolicyArtifactV0 = (input: AuthorPolicyArtifactV0Input) => Promise<ReactorRegistrySnapshotV0> | ReactorRegistrySnapshotV0;
|
|
10
|
+
export interface ProviderParityRecordedProviderV0 {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly model: string;
|
|
13
|
+
readonly history_query: PolicyAuthorHistoryQueryV0;
|
|
14
|
+
readonly artifact: unknown;
|
|
15
|
+
readonly usage?: Partial<Record<ProviderParityPolicyAuthorStepV0, ReactorModelGatewayUsageV0>>;
|
|
16
|
+
}
|
|
17
|
+
export interface ProviderPolicyArtifactParityInputV0 {
|
|
18
|
+
readonly responsibility_id: string;
|
|
19
|
+
readonly contract_revision: ContentHashV0;
|
|
20
|
+
readonly contract_summary: string;
|
|
21
|
+
readonly no_anchor: boolean;
|
|
22
|
+
readonly live_observables: readonly PolicyLiveObservableV0[];
|
|
23
|
+
readonly receipt_history: readonly ReceiptV0[];
|
|
24
|
+
readonly providers: readonly ProviderParityRecordedProviderV0[];
|
|
25
|
+
readonly policy_artifact_namespace?: string;
|
|
26
|
+
readonly authorPolicyArtifactV0?: ProviderParityAuthorPolicyArtifactV0;
|
|
27
|
+
}
|
|
28
|
+
export interface ProviderParityGatewayRequestPayloadV0 {
|
|
29
|
+
readonly schema: typeof PROVIDER_PARITY_GATEWAY_REQUEST_SCHEMA_V0;
|
|
30
|
+
readonly v: typeof PROVIDER_PARITY_REPORT_VERSION_V0;
|
|
31
|
+
readonly provider_name: string;
|
|
32
|
+
readonly launch_representation: typeof PROVIDER_PARITY_POLICY_AUTHOR_LAUNCH_REPRESENTATION_V0;
|
|
33
|
+
readonly agent_request: ReactorAgentRequestV0;
|
|
34
|
+
}
|
|
35
|
+
export interface ProviderParityModelGatewayCallV0 {
|
|
36
|
+
readonly provider_name: string;
|
|
37
|
+
readonly model: string;
|
|
38
|
+
readonly step: ProviderParityPolicyAuthorStepV0;
|
|
39
|
+
readonly request: ReactorModelGatewayRequestV0;
|
|
40
|
+
readonly request_hash: ContentHashV0;
|
|
41
|
+
readonly response: ReactorModelGatewayResponseV0;
|
|
42
|
+
readonly response_hash: ContentHashV0;
|
|
43
|
+
readonly usage: ReactorModelGatewayUsageV0;
|
|
44
|
+
}
|
|
45
|
+
export interface RecordedProviderModelGatewayV0 extends ReactorModelGatewayAdapterV0 {
|
|
46
|
+
readonly provider_name: string;
|
|
47
|
+
readonly model: string;
|
|
48
|
+
readonly calls: () => readonly ProviderParityModelGatewayCallV0[];
|
|
49
|
+
}
|
|
50
|
+
export interface ModelGatewayBackedPolicyAuthorAgentSdkV0 {
|
|
51
|
+
readonly agentSdk: ReactorAgentSdkAdapterV0;
|
|
52
|
+
}
|
|
53
|
+
export interface ProviderParityProviderResultV0 {
|
|
54
|
+
readonly provider_name: string;
|
|
55
|
+
readonly model: string;
|
|
56
|
+
readonly policy_author_launch_representation: typeof PROVIDER_PARITY_POLICY_AUTHOR_LAUNCH_REPRESENTATION_V0;
|
|
57
|
+
readonly validation_state: "validated";
|
|
58
|
+
readonly artifact_hash: ContentHashV0;
|
|
59
|
+
readonly artifact_bytes: string;
|
|
60
|
+
readonly artifact_byte_length: number;
|
|
61
|
+
readonly artifact_bytes_canonical: true;
|
|
62
|
+
readonly policy_artifact_revision: string;
|
|
63
|
+
readonly model_gateway_call_count: number;
|
|
64
|
+
readonly model_gateway_request_hashes: readonly ContentHashV0[];
|
|
65
|
+
readonly model_gateway_response_hashes: readonly ContentHashV0[];
|
|
66
|
+
readonly model_gateway_usage: readonly ReactorModelGatewayUsageV0[];
|
|
67
|
+
}
|
|
68
|
+
export interface ProviderPolicyArtifactParityReportV0 {
|
|
69
|
+
readonly schema: typeof PROVIDER_PARITY_REPORT_SCHEMA_V0;
|
|
70
|
+
readonly v: typeof PROVIDER_PARITY_REPORT_VERSION_V0;
|
|
71
|
+
readonly provider_names: readonly string[];
|
|
72
|
+
readonly artifact_hashes: readonly ContentHashV0[];
|
|
73
|
+
readonly artifact_bytes: readonly string[];
|
|
74
|
+
readonly artifact_byte_lengths: readonly number[];
|
|
75
|
+
readonly byte_identical: boolean;
|
|
76
|
+
readonly validation_state: "validated";
|
|
77
|
+
readonly providers: readonly ProviderParityProviderResultV0[];
|
|
78
|
+
}
|
|
79
|
+
export declare function runProviderPolicyArtifactParityV0(input: ProviderPolicyArtifactParityInputV0): Promise<ProviderPolicyArtifactParityReportV0>;
|
|
80
|
+
export declare function assertProviderPolicyArtifactParityV0(input: ProviderPolicyArtifactParityInputV0): Promise<ProviderPolicyArtifactParityReportV0>;
|
|
81
|
+
export declare function assertProviderPolicyArtifactParityReportV0(report: ProviderPolicyArtifactParityReportV0): ProviderPolicyArtifactParityReportV0;
|
|
82
|
+
export declare function createRecordedProviderModelGatewayV0(provider: ProviderParityRecordedProviderV0): RecordedProviderModelGatewayV0;
|
|
83
|
+
export declare function createModelGatewayBackedPolicyAuthorAgentSdkV0(input: {
|
|
84
|
+
readonly provider_name: string;
|
|
85
|
+
readonly modelGateway: Pick<ReactorModelGatewayAdapterV0, "invoke">;
|
|
86
|
+
}): ModelGatewayBackedPolicyAuthorAgentSdkV0;
|
|
87
|
+
export declare function buildProviderParityModelGatewayRequestV0(input: {
|
|
88
|
+
readonly provider_name: string;
|
|
89
|
+
readonly agent_request: ReactorAgentRequestV0;
|
|
90
|
+
}): ReactorModelGatewayRequestV0;
|
|
91
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/provider-parity/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,KAAK,EACV,2BAA2B,EAC3B,0BAA0B,EAC1B,sBAAsB,EACvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EACV,qBAAqB,EAErB,wBAAwB,EACxB,4BAA4B,EAC5B,4BAA4B,EAC5B,6BAA6B,EAC7B,0BAA0B,EAC1B,yBAAyB,EAC1B,MAAM,wBAAwB,CAAC;AAEhC,eAAO,MAAM,yCAAyC,EACpD,wEAAiF,CAAC;AACpF,eAAO,MAAM,gCAAgC,EAC3C,iDAA0D,CAAC;AAC7D,eAAO,MAAM,iCAAiC,EAAG,CAAU,CAAC;AAC5D,eAAO,MAAM,sDAAsD,EACjE,mCAA4C,CAAC;AAS/C,MAAM,MAAM,gCAAgC,GACxC,eAAe,GACf,iBAAiB,CAAC;AAEtB,MAAM,MAAM,oCAAoC,GAAG,CACjD,KAAK,EAAE,2BAA2B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