@felspar/sdk 0.0.0-stage → 0.1.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 +202 -0
- package/README.md +133 -2
- package/dist/chunks/chunk-6EZBI7O6.js +583 -0
- package/dist/chunks/chunk-C2VMKF3S.js +4922 -0
- package/dist/draft-action-gate-claude.js +50 -0
- package/dist/draft-action-gate-eve.js +53 -0
- package/dist/draft-action-gate-openai.js +60 -0
- package/dist/draft-action-gate.js +35 -0
- package/dist/draft-hosted-client.js +8 -0
- package/dist/types/draft-action-gate-claude.d.ts +27 -0
- package/dist/types/draft-action-gate-decisions.d.ts +36 -0
- package/dist/types/draft-action-gate-domains.d.ts +2 -0
- package/dist/types/draft-action-gate-eve.d.ts +42 -0
- package/dist/types/draft-action-gate-openai.d.ts +36 -0
- package/dist/types/draft-action-gate-outputs.d.ts +35 -0
- package/dist/types/draft-action-gate-verifier.d.ts +7 -0
- package/dist/types/draft-action-gate.d.ts +65 -0
- package/dist/types/draft-hosted-client.d.ts +3384 -0
- package/package.json +68 -4
|
@@ -0,0 +1,4922 @@
|
|
|
1
|
+
// ../schemas/src/draft-content-parts.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var draftContentPartsFormat = "felspar.content-parts/v1";
|
|
4
|
+
var draftContentPartReferenceKey = "$part";
|
|
5
|
+
var digest = z.string().regex(/^sha256:[a-f0-9]{64}$/u);
|
|
6
|
+
var DraftContentPartsManifestSchema = z.strictObject({
|
|
7
|
+
schema: z.literal(draftContentPartsFormat),
|
|
8
|
+
root: z.unknown(),
|
|
9
|
+
parts: z.array(digest)
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
// ../runtime/src/canonical-json.ts
|
|
13
|
+
var canonicalJsonLimits = Object.freeze({
|
|
14
|
+
maxDepth: 64,
|
|
15
|
+
maxNodes: 1e5,
|
|
16
|
+
maxBytes: 1048576
|
|
17
|
+
});
|
|
18
|
+
var sealedEntries = /* @__PURE__ */ new WeakMap();
|
|
19
|
+
var sealedContainers = /* @__PURE__ */ new WeakSet();
|
|
20
|
+
var sealedEntryMinimumBytes = 1024;
|
|
21
|
+
var byteEncoder = new TextEncoder();
|
|
22
|
+
function utf8Bytes(token) {
|
|
23
|
+
if (token.length >= 64) {
|
|
24
|
+
return byteEncoder.encode(token).byteLength;
|
|
25
|
+
}
|
|
26
|
+
let bytes = 0;
|
|
27
|
+
for (let index = 0; index < token.length; index += 1) {
|
|
28
|
+
const code = token.codePointAt(index) ?? 0;
|
|
29
|
+
if (code < 128) {
|
|
30
|
+
bytes += 1;
|
|
31
|
+
} else if (code < 2048) {
|
|
32
|
+
bytes += 2;
|
|
33
|
+
} else if (code > 65535) {
|
|
34
|
+
bytes += 4;
|
|
35
|
+
index += 1;
|
|
36
|
+
} else {
|
|
37
|
+
bytes += 3;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return bytes;
|
|
41
|
+
}
|
|
42
|
+
function append(token, state, bytes = utf8Bytes(token)) {
|
|
43
|
+
state.bytes += bytes;
|
|
44
|
+
if (state.bytes > canonicalJsonLimits.maxBytes) {
|
|
45
|
+
throw new RangeError("Canonical JSON exceeds the byte limit");
|
|
46
|
+
}
|
|
47
|
+
state.buffer += token;
|
|
48
|
+
if (state.buffer.length < 4096) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
state.parts.push(state.buffer);
|
|
52
|
+
state.buffer = "";
|
|
53
|
+
}
|
|
54
|
+
function quoted(value) {
|
|
55
|
+
if (value.length > canonicalJsonLimits.maxBytes) {
|
|
56
|
+
throw new RangeError("Canonical JSON string exceeds the byte limit");
|
|
57
|
+
}
|
|
58
|
+
if (/[\uD800-\uDFFF]/u.test(value)) {
|
|
59
|
+
throw new TypeError("Canonical JSON requires valid Unicode strings");
|
|
60
|
+
}
|
|
61
|
+
return JSON.stringify(value);
|
|
62
|
+
}
|
|
63
|
+
function appendQuoted(value, state) {
|
|
64
|
+
let entry2 = state.strings.get(value);
|
|
65
|
+
if (!entry2) {
|
|
66
|
+
const token = quoted(value);
|
|
67
|
+
entry2 = { token, bytes: utf8Bytes(token) };
|
|
68
|
+
if (state.strings.size < 256 && state.stringBytes + entry2.bytes <= 65536) {
|
|
69
|
+
state.strings.set(value, entry2);
|
|
70
|
+
state.stringBytes += entry2.bytes;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
append(entry2.token, state, entry2.bytes);
|
|
74
|
+
}
|
|
75
|
+
function dataValue(input, key3) {
|
|
76
|
+
const descriptor = Object.getOwnPropertyDescriptor(input, key3);
|
|
77
|
+
if (descriptor?.enumerable !== true || !("value" in descriptor)) {
|
|
78
|
+
throw new TypeError("Canonical JSON requires enumerable data properties");
|
|
79
|
+
}
|
|
80
|
+
return descriptor.value;
|
|
81
|
+
}
|
|
82
|
+
function keysOf(input, nodes) {
|
|
83
|
+
const keys = Reflect.ownKeys(input);
|
|
84
|
+
if (keys.length > canonicalJsonLimits.maxNodes - nodes + 1) {
|
|
85
|
+
throw new RangeError("Canonical JSON exceeds the node limit");
|
|
86
|
+
}
|
|
87
|
+
return keys.map((key3) => {
|
|
88
|
+
if (typeof key3 !== "string") {
|
|
89
|
+
throw new TypeError("Canonical JSON does not support symbol keys");
|
|
90
|
+
}
|
|
91
|
+
return key3;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function writeArray(input, state, depth) {
|
|
95
|
+
const keys = keysOf(input, state.nodes);
|
|
96
|
+
if (Object.getPrototypeOf(input) !== Array.prototype || keys.length !== input.length + 1) {
|
|
97
|
+
throw new TypeError("Canonical JSON requires dense ordinary arrays without extra properties");
|
|
98
|
+
}
|
|
99
|
+
if (input.length > canonicalJsonLimits.maxNodes - state.nodes) {
|
|
100
|
+
throw new RangeError("Canonical JSON exceeds the node limit");
|
|
101
|
+
}
|
|
102
|
+
append("[", state);
|
|
103
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
104
|
+
if (index > 0) {
|
|
105
|
+
append(",", state);
|
|
106
|
+
}
|
|
107
|
+
writeValue(dataValue(input, String(index)), state, depth + 1);
|
|
108
|
+
}
|
|
109
|
+
append("]", state);
|
|
110
|
+
}
|
|
111
|
+
function compareKeys(left, right) {
|
|
112
|
+
if (left === right) {
|
|
113
|
+
return 0;
|
|
114
|
+
}
|
|
115
|
+
return left < right ? -1 : 1;
|
|
116
|
+
}
|
|
117
|
+
function writeObject(input, state, depth) {
|
|
118
|
+
const prototype = Object.getPrototypeOf(input);
|
|
119
|
+
if (prototype !== null && prototype !== Object.prototype) {
|
|
120
|
+
throw new TypeError("Canonical JSON requires ordinary objects");
|
|
121
|
+
}
|
|
122
|
+
const keys = keysOf(input, state.nodes).sort(compareKeys);
|
|
123
|
+
append("{", state);
|
|
124
|
+
for (const [index, key3] of keys.entries()) {
|
|
125
|
+
if (index > 0) {
|
|
126
|
+
append(",", state);
|
|
127
|
+
}
|
|
128
|
+
appendQuoted(key3, state);
|
|
129
|
+
append(":", state);
|
|
130
|
+
writeValue(dataValue(input, key3), state, depth + 1);
|
|
131
|
+
}
|
|
132
|
+
append("}", state);
|
|
133
|
+
}
|
|
134
|
+
function writeSealed(entry2, state, depth) {
|
|
135
|
+
state.nodes += entry2.nodes - 1;
|
|
136
|
+
if (depth + entry2.height > canonicalJsonLimits.maxDepth || state.nodes > canonicalJsonLimits.maxNodes) {
|
|
137
|
+
throw new RangeError("Canonical JSON exceeds the depth or node limit");
|
|
138
|
+
}
|
|
139
|
+
state.height = Math.max(state.height, depth + entry2.height);
|
|
140
|
+
append(entry2.json, state, entry2.bytes);
|
|
141
|
+
}
|
|
142
|
+
function writeContainer(input, state, depth) {
|
|
143
|
+
const sealed = sealedEntries.get(input);
|
|
144
|
+
if (sealed) {
|
|
145
|
+
writeSealed(sealed, state, depth);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (state.ancestors.has(input)) {
|
|
149
|
+
throw new TypeError("Canonical JSON does not support cycles");
|
|
150
|
+
}
|
|
151
|
+
state.ancestors.add(input);
|
|
152
|
+
if (Array.isArray(input)) {
|
|
153
|
+
writeArray(input, state, depth);
|
|
154
|
+
} else {
|
|
155
|
+
writeObject(input, state, depth);
|
|
156
|
+
}
|
|
157
|
+
state.ancestors.delete(input);
|
|
158
|
+
}
|
|
159
|
+
function writeValue(input, state, depth) {
|
|
160
|
+
state.nodes += 1;
|
|
161
|
+
if (depth > canonicalJsonLimits.maxDepth || state.nodes > canonicalJsonLimits.maxNodes) {
|
|
162
|
+
throw new RangeError("Canonical JSON exceeds the depth or node limit");
|
|
163
|
+
}
|
|
164
|
+
if (depth > state.height) {
|
|
165
|
+
state.height = depth;
|
|
166
|
+
}
|
|
167
|
+
if (input === null || typeof input === "boolean") {
|
|
168
|
+
append(JSON.stringify(input), state);
|
|
169
|
+
} else if (typeof input === "string") {
|
|
170
|
+
appendQuoted(input, state);
|
|
171
|
+
} else if (typeof input === "number" && Number.isFinite(input)) {
|
|
172
|
+
append(JSON.stringify(input), state);
|
|
173
|
+
} else if (typeof input === "object") {
|
|
174
|
+
writeContainer(input, state, depth);
|
|
175
|
+
} else {
|
|
176
|
+
throw new TypeError("Canonical JSON requires finite numbers and JSON-compatible values");
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function serialize(input) {
|
|
180
|
+
const state = {
|
|
181
|
+
parts: [],
|
|
182
|
+
buffer: "",
|
|
183
|
+
bytes: 0,
|
|
184
|
+
nodes: 0,
|
|
185
|
+
ancestors: /* @__PURE__ */ new Set(),
|
|
186
|
+
strings: /* @__PURE__ */ new Map(),
|
|
187
|
+
stringBytes: 0,
|
|
188
|
+
height: 0
|
|
189
|
+
};
|
|
190
|
+
writeValue(input, state, 0);
|
|
191
|
+
return { json: state.parts.join("") + state.buffer, state };
|
|
192
|
+
}
|
|
193
|
+
function canonicalizeJson(input) {
|
|
194
|
+
return serialize(input).json;
|
|
195
|
+
}
|
|
196
|
+
function sealedMembers(input) {
|
|
197
|
+
const keys = keysOf(input, 0);
|
|
198
|
+
const prototype = Object.getPrototypeOf(input);
|
|
199
|
+
if (Array.isArray(input)) {
|
|
200
|
+
if (prototype !== Array.prototype || keys.length !== input.length + 1) {
|
|
201
|
+
throw new TypeError("Canonical JSON requires dense ordinary arrays without extra properties");
|
|
202
|
+
}
|
|
203
|
+
return Array.from(input.keys(), String);
|
|
204
|
+
}
|
|
205
|
+
if (prototype !== null && prototype !== Object.prototype) {
|
|
206
|
+
throw new TypeError("Canonical JSON requires ordinary objects");
|
|
207
|
+
}
|
|
208
|
+
keys.sort(compareKeys);
|
|
209
|
+
return keys;
|
|
210
|
+
}
|
|
211
|
+
function consumeSource(token, source3) {
|
|
212
|
+
if (!source3) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (!source3.text.startsWith(token, source3.offset)) {
|
|
216
|
+
throw new TypeError("JSON text is not canonical");
|
|
217
|
+
}
|
|
218
|
+
source3.offset += token.length;
|
|
219
|
+
}
|
|
220
|
+
function sealValue(input, depth, state) {
|
|
221
|
+
const { ancestors, source: source3 } = state;
|
|
222
|
+
if (depth > canonicalJsonLimits.maxDepth) {
|
|
223
|
+
throw new RangeError("Canonical JSON exceeds the depth limit");
|
|
224
|
+
}
|
|
225
|
+
if (input === null || typeof input !== "object") {
|
|
226
|
+
const token = typeof input === "string" ? quoted(input) : canonicalizeJson(input);
|
|
227
|
+
consumeSource(token, source3);
|
|
228
|
+
return { json: token, bytes: utf8Bytes(token), nodes: 1, height: 0 };
|
|
229
|
+
}
|
|
230
|
+
const known = sealedEntries.get(input);
|
|
231
|
+
if (known) {
|
|
232
|
+
consumeSource(known.json, source3);
|
|
233
|
+
return known;
|
|
234
|
+
}
|
|
235
|
+
if (ancestors.has(input)) {
|
|
236
|
+
throw new TypeError("Canonical JSON does not support cycles");
|
|
237
|
+
}
|
|
238
|
+
ancestors.add(input);
|
|
239
|
+
const isArray = Array.isArray(input);
|
|
240
|
+
const members = sealedMembers(input);
|
|
241
|
+
const start = source3?.offset ?? 0;
|
|
242
|
+
let json = isArray ? "[" : "{";
|
|
243
|
+
consumeSource(json, source3);
|
|
244
|
+
let bytes = 2;
|
|
245
|
+
let nodes = 1;
|
|
246
|
+
let height = 0;
|
|
247
|
+
for (const [index, key3] of members.entries()) {
|
|
248
|
+
let prefix = index > 0 ? "," : "";
|
|
249
|
+
if (!isArray) {
|
|
250
|
+
prefix += `${quoted(key3)}:`;
|
|
251
|
+
}
|
|
252
|
+
consumeSource(prefix, source3);
|
|
253
|
+
const child = sealValue(dataValue(input, key3), depth + 1, state);
|
|
254
|
+
if (!source3) {
|
|
255
|
+
json += prefix + child.json;
|
|
256
|
+
}
|
|
257
|
+
bytes += utf8Bytes(prefix) + child.bytes;
|
|
258
|
+
nodes += child.nodes;
|
|
259
|
+
height = Math.max(height, child.height + 1);
|
|
260
|
+
}
|
|
261
|
+
const closing = isArray ? "]" : "}";
|
|
262
|
+
consumeSource(closing, source3);
|
|
263
|
+
json = source3 ? source3.text.slice(start, source3.offset) : json + closing;
|
|
264
|
+
ancestors.delete(input);
|
|
265
|
+
if (depth + height > canonicalJsonLimits.maxDepth || nodes > canonicalJsonLimits.maxNodes || bytes > canonicalJsonLimits.maxBytes) {
|
|
266
|
+
throw new RangeError("Canonical JSON exceeds the depth, node or byte limit");
|
|
267
|
+
}
|
|
268
|
+
Object.freeze(input);
|
|
269
|
+
const entry2 = { json, bytes, nodes, height };
|
|
270
|
+
sealedContainers.add(input);
|
|
271
|
+
if (bytes >= sealedEntryMinimumBytes) {
|
|
272
|
+
sealedEntries.set(input, entry2);
|
|
273
|
+
}
|
|
274
|
+
return entry2;
|
|
275
|
+
}
|
|
276
|
+
function sealCanonicalJson(input) {
|
|
277
|
+
sealValue(input, 0, { ancestors: /* @__PURE__ */ new Set() });
|
|
278
|
+
return input;
|
|
279
|
+
}
|
|
280
|
+
function isCanonicalJsonSealed(input) {
|
|
281
|
+
return input !== null && typeof input === "object" && sealedContainers.has(input);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// ../runtime/src/content-parts.ts
|
|
285
|
+
var mebibyte = 1048576;
|
|
286
|
+
var contentPartsLimits = Object.freeze({
|
|
287
|
+
minPartBytes: 4096,
|
|
288
|
+
maxParts: 512,
|
|
289
|
+
maxStoredBytes: 4 * mebibyte,
|
|
290
|
+
maxLogicalBytes: 32 * mebibyte,
|
|
291
|
+
maxLogicalNodes: 32e5,
|
|
292
|
+
maxLogicalDepth: canonicalJsonLimits.maxDepth
|
|
293
|
+
});
|
|
294
|
+
var encoder = new TextEncoder();
|
|
295
|
+
function utf8(text7) {
|
|
296
|
+
if (text7.length >= 64) {
|
|
297
|
+
return encoder.encode(text7).byteLength;
|
|
298
|
+
}
|
|
299
|
+
let bytes = 0;
|
|
300
|
+
for (let index = 0; index < text7.length; index += 1) {
|
|
301
|
+
const code = text7.codePointAt(index) ?? 0;
|
|
302
|
+
if (code < 128) {
|
|
303
|
+
bytes += 1;
|
|
304
|
+
} else if (code < 2048) {
|
|
305
|
+
bytes += 2;
|
|
306
|
+
} else if (code > 65535) {
|
|
307
|
+
bytes += 4;
|
|
308
|
+
index += 1;
|
|
309
|
+
} else {
|
|
310
|
+
bytes += 3;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return bytes;
|
|
314
|
+
}
|
|
315
|
+
async function sha256(text7) {
|
|
316
|
+
const hash = new Uint8Array(await crypto.subtle.digest("SHA-256", encoder.encode(text7)));
|
|
317
|
+
return `sha256:${Array.from(hash, (byte) => byte.toString(16).padStart(2, "0")).join("")}`;
|
|
318
|
+
}
|
|
319
|
+
function reference(digest28) {
|
|
320
|
+
return { [draftContentPartReferenceKey]: digest28 };
|
|
321
|
+
}
|
|
322
|
+
var referenceBytes = utf8(canonicalizeJson(reference(`sha256:${"0".repeat(64)}`)));
|
|
323
|
+
var logicalLimit = "Content parts exceed the logical byte, node or depth limit";
|
|
324
|
+
function admit(logical, depth) {
|
|
325
|
+
if (logical.bytes > contentPartsLimits.maxLogicalBytes || logical.nodes > contentPartsLimits.maxLogicalNodes || depth + logical.height > contentPartsLimits.maxLogicalDepth) {
|
|
326
|
+
throw new RangeError(logicalLimit);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function scalar(value) {
|
|
330
|
+
if (value === void 0 || typeof value === "function" || typeof value === "symbol") {
|
|
331
|
+
throw new TypeError("Content parts require JSON values");
|
|
332
|
+
}
|
|
333
|
+
const bytes = utf8(JSON.stringify(value));
|
|
334
|
+
return { value, tokenBytes: bytes, logical: { bytes, nodes: 1, height: 0 } };
|
|
335
|
+
}
|
|
336
|
+
function combine(keys, children) {
|
|
337
|
+
let tokenBytes = 2 + Math.max(children.length - 1, 0);
|
|
338
|
+
let bytes = tokenBytes;
|
|
339
|
+
let nodes = 1;
|
|
340
|
+
let height = 0;
|
|
341
|
+
for (const [index, child] of children.entries()) {
|
|
342
|
+
const key3 = keys?.[index];
|
|
343
|
+
const keyBytes = key3 === void 0 ? 0 : utf8(JSON.stringify(key3)) + 1;
|
|
344
|
+
tokenBytes += keyBytes + child.tokenBytes;
|
|
345
|
+
bytes += keyBytes + child.logical.bytes;
|
|
346
|
+
nodes += child.logical.nodes;
|
|
347
|
+
height = Math.max(height, child.logical.height + 1);
|
|
348
|
+
}
|
|
349
|
+
return { tokenBytes, logical: { bytes, nodes, height } };
|
|
350
|
+
}
|
|
351
|
+
var hydratedValues = /* @__PURE__ */ new WeakSet();
|
|
352
|
+
var knownSplits = /* @__PURE__ */ new WeakMap();
|
|
353
|
+
function isImmutable(value) {
|
|
354
|
+
return hydratedValues.has(value) || isCanonicalJsonSealed(value);
|
|
355
|
+
}
|
|
356
|
+
function entriesOf(input) {
|
|
357
|
+
const isArray = Array.isArray(input);
|
|
358
|
+
const prototype = Object.getPrototypeOf(input);
|
|
359
|
+
if (isArray ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) {
|
|
360
|
+
throw new TypeError("Content parts require plain JSON containers");
|
|
361
|
+
}
|
|
362
|
+
const keys = Reflect.ownKeys(input);
|
|
363
|
+
if (isArray && keys.length !== input.length + 1) {
|
|
364
|
+
throw new TypeError("Content parts require dense arrays");
|
|
365
|
+
}
|
|
366
|
+
const entries2 = [];
|
|
367
|
+
for (const key3 of keys) {
|
|
368
|
+
if (isArray && key3 === "length") {
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
const descriptor = Object.getOwnPropertyDescriptor(input, key3);
|
|
372
|
+
if (typeof key3 !== "string" || descriptor?.enumerable !== true || !("value" in descriptor)) {
|
|
373
|
+
throw new TypeError("Content parts require enumerable JSON data properties");
|
|
374
|
+
}
|
|
375
|
+
if (!isArray && key3 === draftContentPartReferenceKey) {
|
|
376
|
+
throw new TypeError("Content parts reserve the $part key");
|
|
377
|
+
}
|
|
378
|
+
entries2.push([key3, descriptor.value]);
|
|
379
|
+
}
|
|
380
|
+
return entries2;
|
|
381
|
+
}
|
|
382
|
+
function rebuild(input, entries2, values) {
|
|
383
|
+
return Array.isArray(input) ? values : Object.fromEntries(entries2.map(([key3], index) => [key3, values[index]]));
|
|
384
|
+
}
|
|
385
|
+
function measure(input, state, depth) {
|
|
386
|
+
if (input === null || typeof input !== "object") {
|
|
387
|
+
return scalar(input);
|
|
388
|
+
}
|
|
389
|
+
const known = state.isCollecting ? void 0 : knownSplits.get(input);
|
|
390
|
+
if (known) {
|
|
391
|
+
admit(known.logical, depth);
|
|
392
|
+
return known;
|
|
393
|
+
}
|
|
394
|
+
let node = state.measured.get(input);
|
|
395
|
+
if (!node) {
|
|
396
|
+
if (depth > contentPartsLimits.maxLogicalDepth) {
|
|
397
|
+
throw new RangeError(logicalLimit);
|
|
398
|
+
}
|
|
399
|
+
const entries2 = entriesOf(input);
|
|
400
|
+
const children = entries2.map(([, value]) => measure(value, state, depth + 1));
|
|
401
|
+
const keys = Array.isArray(input) ? null : entries2.map(([key3]) => key3);
|
|
402
|
+
const { tokenBytes: tokenBytes2, logical } = combine(keys, children);
|
|
403
|
+
const isPart = tokenBytes2 >= contentPartsLimits.minPartBytes;
|
|
404
|
+
node = { input, entries: entries2, tokenBytes: tokenBytes2, logical, isPart };
|
|
405
|
+
state.measured.set(input, node);
|
|
406
|
+
if (isPart) {
|
|
407
|
+
state.order.push(node);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
admit(node.logical, depth);
|
|
411
|
+
const tokenBytes = node.isPart ? referenceBytes : node.tokenBytes;
|
|
412
|
+
return { value: null, tokenBytes, logical: node.logical };
|
|
413
|
+
}
|
|
414
|
+
function storedForm(input, state) {
|
|
415
|
+
if (input === null || typeof input !== "object") {
|
|
416
|
+
return input;
|
|
417
|
+
}
|
|
418
|
+
const known = state.isCollecting ? void 0 : knownSplits.get(input);
|
|
419
|
+
if (known) {
|
|
420
|
+
return known.value;
|
|
421
|
+
}
|
|
422
|
+
const digest28 = state.digests.get(input);
|
|
423
|
+
if (digest28 !== void 0) {
|
|
424
|
+
return reference(digest28);
|
|
425
|
+
}
|
|
426
|
+
const node = state.measured.get(input);
|
|
427
|
+
if (!node) {
|
|
428
|
+
throw new Error("Content parts lost a measured container");
|
|
429
|
+
}
|
|
430
|
+
return rebuild(input, node.entries, node.entries.map(([, value]) => storedForm(value, state)));
|
|
431
|
+
}
|
|
432
|
+
function remember(node, value, tokenBytes) {
|
|
433
|
+
if (isImmutable(node.input)) {
|
|
434
|
+
knownSplits.set(node.input, { value, tokenBytes, logical: node.logical });
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
function isCanonicalDocumentSized(logical) {
|
|
438
|
+
return logical.bytes <= canonicalJsonLimits.maxBytes && logical.nodes <= canonicalJsonLimits.maxNodes && logical.height <= canonicalJsonLimits.maxDepth;
|
|
439
|
+
}
|
|
440
|
+
function freezeMeasured(state) {
|
|
441
|
+
for (const node of state.measured.values()) {
|
|
442
|
+
if (node.isPart && isCanonicalDocumentSized(node.logical)) {
|
|
443
|
+
sealCanonicalJson(node.input);
|
|
444
|
+
}
|
|
445
|
+
Object.freeze(node.input);
|
|
446
|
+
hydratedValues.add(node.input);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
async function splitRoot(value, isCollecting, isFreezing = false) {
|
|
450
|
+
const state = {
|
|
451
|
+
isCollecting,
|
|
452
|
+
measured: /* @__PURE__ */ new Map(),
|
|
453
|
+
order: [],
|
|
454
|
+
digests: /* @__PURE__ */ new Map(),
|
|
455
|
+
parts: /* @__PURE__ */ new Map()
|
|
456
|
+
};
|
|
457
|
+
const root = measure(value, state, 0);
|
|
458
|
+
if (isFreezing) {
|
|
459
|
+
freezeMeasured(state);
|
|
460
|
+
}
|
|
461
|
+
for (const node of state.order) {
|
|
462
|
+
const token = canonicalizeJson(storedForm(node.input, state));
|
|
463
|
+
const digest29 = await sha256(token);
|
|
464
|
+
state.digests.set(node.input, digest29);
|
|
465
|
+
state.parts.set(digest29, token);
|
|
466
|
+
remember(node, reference(digest29), referenceBytes);
|
|
467
|
+
}
|
|
468
|
+
const stored = storedForm(value, state);
|
|
469
|
+
if (value !== null && typeof value === "object") {
|
|
470
|
+
const node = state.measured.get(value);
|
|
471
|
+
if (node && !node.isPart) {
|
|
472
|
+
remember(node, stored, node.tokenBytes);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
const digest28 = await sha256(canonicalizeJson(stored));
|
|
476
|
+
return { state, root: { ...root, value: stored }, digest: digest28 };
|
|
477
|
+
}
|
|
478
|
+
function byDigest(left, right) {
|
|
479
|
+
return left < right ? -1 : 1;
|
|
480
|
+
}
|
|
481
|
+
function admitStored(parts, bytes) {
|
|
482
|
+
if (parts > contentPartsLimits.maxParts || bytes > contentPartsLimits.maxStoredBytes) {
|
|
483
|
+
throw new RangeError("Content parts exceed the stored part or byte limit");
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
async function packContentParts(value) {
|
|
487
|
+
const { state, root, digest: digest28 } = await splitRoot(value, true);
|
|
488
|
+
const parts = [];
|
|
489
|
+
for (const part of state.parts.keys()) {
|
|
490
|
+
parts.push(part);
|
|
491
|
+
}
|
|
492
|
+
parts.sort(byDigest);
|
|
493
|
+
const head = canonicalizeJson({ schema: draftContentPartsFormat, root: root.value, parts });
|
|
494
|
+
const text7 = [head, ...parts.map((part) => state.parts.get(part) ?? "")].join("\n");
|
|
495
|
+
const storedBytes = utf8(text7);
|
|
496
|
+
admitStored(parts.length, storedBytes);
|
|
497
|
+
return {
|
|
498
|
+
digest: digest28,
|
|
499
|
+
text: text7,
|
|
500
|
+
parts: parts.length,
|
|
501
|
+
storedBytes,
|
|
502
|
+
logicalBytes: root.logical.bytes,
|
|
503
|
+
logicalNodes: root.logical.nodes
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// ../schemas/src/draft-application-access.ts
|
|
508
|
+
import { z as z41 } from "zod";
|
|
509
|
+
|
|
510
|
+
// ../schemas/src/draft-job-handoff.ts
|
|
511
|
+
import { z as z40 } from "zod";
|
|
512
|
+
|
|
513
|
+
// ../schemas/src/draft-requirements.ts
|
|
514
|
+
import { z as z34 } from "zod";
|
|
515
|
+
|
|
516
|
+
// ../schemas/src/draft-required-origins.ts
|
|
517
|
+
import { z as z32 } from "zod";
|
|
518
|
+
|
|
519
|
+
// ../schemas/src/draft-required-decision.ts
|
|
520
|
+
import { z as z15 } from "zod";
|
|
521
|
+
|
|
522
|
+
// ../schemas/src/draft-relative-date.ts
|
|
523
|
+
import { z as z5 } from "zod";
|
|
524
|
+
|
|
525
|
+
// ../schemas/src/draft-calendar-date.ts
|
|
526
|
+
import { z as z2 } from "zod";
|
|
527
|
+
var CalendarDateSchema = z2.string().regex(/^(?!0000)\d{4}-\d{2}-\d{2}$/u).refine((value) => {
|
|
528
|
+
const instant2 = /* @__PURE__ */ new Date(`${value}T00:00:00.000Z`);
|
|
529
|
+
return Number.isFinite(instant2.getTime()) && instant2.toISOString().slice(0, 10) === value;
|
|
530
|
+
}, "Expected a real Gregorian calendar date in years 0001\u20139999");
|
|
531
|
+
function calendarDay(value) {
|
|
532
|
+
return Date.parse(`${value}T00:00:00.000Z`) / 864e5;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// ../schemas/src/draft-evidence-scope.ts
|
|
536
|
+
import { z as z3 } from "zod";
|
|
537
|
+
var identifier = z3.string().min(1).max(256).regex(/^[a-zA-Z0-9][a-zA-Z0-9._:/@-]*$/u);
|
|
538
|
+
var reference2 = z3.strictObject({
|
|
539
|
+
sourceId: identifier,
|
|
540
|
+
revision: identifier,
|
|
541
|
+
locator: z3.string().min(1).max(4096).regex(/\S/u),
|
|
542
|
+
contentDigest: z3.string().regex(/^sha256:[a-f0-9]{64}$/u)
|
|
543
|
+
});
|
|
544
|
+
function draftPassageKey(source3) {
|
|
545
|
+
return JSON.stringify([source3.sourceId, source3.revision, source3.locator]);
|
|
546
|
+
}
|
|
547
|
+
var DraftEvidenceScopeSchema = z3.strictObject({
|
|
548
|
+
schema: z3.literal("felspar.evidence-scope.draft/v0"),
|
|
549
|
+
entityId: identifier,
|
|
550
|
+
sources: z3.array(reference2.extend({ entityId: identifier })).max(64),
|
|
551
|
+
observations: z3.array(z3.strictObject({ id: identifier, evidence: reference2 })).max(64)
|
|
552
|
+
}).superRefine((input, context3) => {
|
|
553
|
+
const sources = /* @__PURE__ */ new Set();
|
|
554
|
+
for (const [index, source3] of input.sources.entries()) {
|
|
555
|
+
const key3 = draftPassageKey(source3);
|
|
556
|
+
if (sources.has(key3)) {
|
|
557
|
+
context3.addIssue({
|
|
558
|
+
code: "custom",
|
|
559
|
+
path: ["sources", index],
|
|
560
|
+
message: "Duplicate passage identity"
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
sources.add(key3);
|
|
564
|
+
}
|
|
565
|
+
const observations = /* @__PURE__ */ new Set();
|
|
566
|
+
for (const [index, observation2] of input.observations.entries()) {
|
|
567
|
+
if (observations.has(observation2.id)) {
|
|
568
|
+
context3.addIssue({
|
|
569
|
+
code: "custom",
|
|
570
|
+
path: ["observations", index],
|
|
571
|
+
message: "Duplicate observation identity"
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
observations.add(observation2.id);
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
// ../schemas/src/draft-evidence-values.ts
|
|
579
|
+
import { z as z4 } from "zod";
|
|
580
|
+
function hasUniqueValues(values) {
|
|
581
|
+
const unique4 = new Set(values);
|
|
582
|
+
return unique4.size === values.length;
|
|
583
|
+
}
|
|
584
|
+
var DraftEvidenceValueSchema = z4.union([z4.string().max(4096), z4.number(), z4.boolean()]);
|
|
585
|
+
var DraftValueRuleSchema = z4.discriminatedUnion("type", [
|
|
586
|
+
z4.strictObject({
|
|
587
|
+
type: z4.literal("enum"),
|
|
588
|
+
values: z4.array(z4.string().min(1).max(4096)).min(1).max(64).refine(hasUniqueValues, "Duplicate allowed value")
|
|
589
|
+
}),
|
|
590
|
+
z4.strictObject({
|
|
591
|
+
type: z4.literal("number"),
|
|
592
|
+
integer: z4.boolean(),
|
|
593
|
+
minimum: z4.number(),
|
|
594
|
+
maximum: z4.number()
|
|
595
|
+
}).refine((rule3) => rule3.minimum <= rule3.maximum, "Reversed number bounds"),
|
|
596
|
+
z4.strictObject({ type: z4.literal("boolean") }),
|
|
597
|
+
z4.strictObject({ type: z4.literal("date") })
|
|
598
|
+
]);
|
|
599
|
+
var DraftValueResultSchema = z4.discriminatedUnion("status", [
|
|
600
|
+
z4.strictObject({ status: z4.literal("supplied"), value: DraftEvidenceValueSchema }),
|
|
601
|
+
z4.strictObject({ status: z4.enum(["malformed", "timeout", "review_required"]) })
|
|
602
|
+
]);
|
|
603
|
+
|
|
604
|
+
// ../schemas/src/draft-relative-date.ts
|
|
605
|
+
var relativeDateResolutionPolicy = "relative-date-required-types/direct-overrides/v5";
|
|
606
|
+
var identifier2 = DraftEvidenceScopeSchema.shape.entityId;
|
|
607
|
+
var businessCalendar = z5.strictObject({
|
|
608
|
+
kind: z5.literal("business_days"),
|
|
609
|
+
id: identifier2,
|
|
610
|
+
version: identifier2,
|
|
611
|
+
validFrom: CalendarDateSchema,
|
|
612
|
+
validThrough: CalendarDateSchema,
|
|
613
|
+
workingWeekdays: z5.array(z5.number().int().min(0).max(6)).min(1).max(7).refine((values) => {
|
|
614
|
+
const unique4 = new Set(values);
|
|
615
|
+
return unique4.size === values.length;
|
|
616
|
+
}, "Duplicate working weekday"),
|
|
617
|
+
holidays: z5.array(CalendarDateSchema).max(3660).refine(hasUniqueValues, "Duplicate holiday")
|
|
618
|
+
}).superRefine((calendar, context3) => {
|
|
619
|
+
const span = calendarDay(calendar.validThrough) - calendarDay(calendar.validFrom);
|
|
620
|
+
if (span < 0 || span > 36600) {
|
|
621
|
+
context3.addIssue({
|
|
622
|
+
code: "custom",
|
|
623
|
+
message: "Calendar coverage must be ordered and at most 36600 days"
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
if (calendar.holidays.some((day) => {
|
|
627
|
+
const value = calendarDay(day);
|
|
628
|
+
return value < calendarDay(calendar.validFrom) || value > calendarDay(calendar.validThrough);
|
|
629
|
+
})) {
|
|
630
|
+
context3.addIssue({ code: "custom", message: "Holiday outside declared calendar coverage" });
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
var RelativeDateComparisonSchema = z5.strictObject({
|
|
634
|
+
operator: z5.enum(["eq", "lt", "lte", "gt", "gte"]),
|
|
635
|
+
anchorKey: identifier2,
|
|
636
|
+
offsetDays: z5.number().int().min(-3660).max(3660),
|
|
637
|
+
calendar: z5.union([z5.strictObject({ kind: z5.literal("calendar_days") }), businessCalendar])
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
// ../schemas/src/draft-authority.ts
|
|
641
|
+
import { z as z6 } from "zod";
|
|
642
|
+
var identifier3 = z6.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:/@-]*$/u);
|
|
643
|
+
var text = z6.string().regex(/\S/u);
|
|
644
|
+
var digest2 = z6.string().regex(/^sha256:[a-f0-9]{64}$/u);
|
|
645
|
+
var identifiers = z6.array(identifier3).min(1);
|
|
646
|
+
var unknownDefinition = "Unknown definition key";
|
|
647
|
+
var DraftSourceReferenceSchema = z6.strictObject({
|
|
648
|
+
sourceId: identifier3,
|
|
649
|
+
revision: identifier3,
|
|
650
|
+
contentDigest: digest2
|
|
651
|
+
});
|
|
652
|
+
var definition = z6.strictObject({
|
|
653
|
+
key: identifier3,
|
|
654
|
+
contentDigest: digest2,
|
|
655
|
+
sourceLocator: text,
|
|
656
|
+
allowedValues: identifiers
|
|
657
|
+
});
|
|
658
|
+
var rule = z6.strictObject({
|
|
659
|
+
id: identifier3,
|
|
660
|
+
sourceLocator: text,
|
|
661
|
+
contentDigest: digest2,
|
|
662
|
+
when: z6.strictObject({ key: identifier3, equals: identifier3 }),
|
|
663
|
+
outcome: identifier3
|
|
664
|
+
});
|
|
665
|
+
var authorityShape = z6.strictObject({
|
|
666
|
+
kind: z6.literal("proposal"),
|
|
667
|
+
job: identifier3,
|
|
668
|
+
source: DraftSourceReferenceSchema,
|
|
669
|
+
definition,
|
|
670
|
+
allowedOutcomes: identifiers,
|
|
671
|
+
rules: z6.array(rule).min(1)
|
|
672
|
+
});
|
|
673
|
+
function requireBinding(isValid, context3, issue) {
|
|
674
|
+
if (!isValid) {
|
|
675
|
+
context3.addIssue({ code: "custom", ...issue });
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
function unique(values, context3, path3) {
|
|
679
|
+
const distinct = new Set(values);
|
|
680
|
+
requireBinding(distinct.size === values.length, context3, {
|
|
681
|
+
path: path3,
|
|
682
|
+
message: "Duplicate identity/value"
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
function checkAuthority(authority, context3) {
|
|
686
|
+
unique(authority.definition.allowedValues, context3, ["definition", "allowedValues"]);
|
|
687
|
+
unique(authority.allowedOutcomes, context3, ["allowedOutcomes"]);
|
|
688
|
+
unique(authority.rules.map((entry2) => entry2.id), context3, ["rules"]);
|
|
689
|
+
const values = new Set(authority.definition.allowedValues);
|
|
690
|
+
const outcomes = new Set(authority.allowedOutcomes);
|
|
691
|
+
for (const [index, entry2] of authority.rules.entries()) {
|
|
692
|
+
const at = ["rules", index];
|
|
693
|
+
requireBinding(entry2.when.key === authority.definition.key, context3, {
|
|
694
|
+
path: [...at, "when", "key"],
|
|
695
|
+
message: unknownDefinition
|
|
696
|
+
});
|
|
697
|
+
requireBinding(values.has(entry2.when.equals), context3, {
|
|
698
|
+
path: [...at, "when", "equals"],
|
|
699
|
+
message: "Unknown definition value"
|
|
700
|
+
});
|
|
701
|
+
requireBinding(outcomes.has(entry2.outcome), context3, {
|
|
702
|
+
path: [...at, "outcome"],
|
|
703
|
+
message: "Unknown outcome"
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
var DraftAuthoritySchema = authorityShape.superRefine(checkAuthority);
|
|
708
|
+
|
|
709
|
+
// ../schemas/src/draft-decision-run.ts
|
|
710
|
+
import { z as z10 } from "zod";
|
|
711
|
+
|
|
712
|
+
// ../schemas/src/draft-evidence-validation.ts
|
|
713
|
+
import { z as z8 } from "zod";
|
|
714
|
+
|
|
715
|
+
// ../schemas/src/draft-observation-checks.ts
|
|
716
|
+
import { z as z7 } from "zod";
|
|
717
|
+
var identifier4 = DraftEvidenceScopeSchema.shape.observations.element.shape.id;
|
|
718
|
+
var digest3 = z7.string().regex(/^sha256:[a-f0-9]{64}$/u);
|
|
719
|
+
var timestamp = z7.iso.datetime().regex(/T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/u);
|
|
720
|
+
var DraftObservationChecksSchema = z7.strictObject({
|
|
721
|
+
schema: z7.literal("felspar.observation-checks.draft/v0"),
|
|
722
|
+
scope: DraftEvidenceScopeSchema,
|
|
723
|
+
evaluationTime: timestamp,
|
|
724
|
+
requirement: z7.strictObject({
|
|
725
|
+
key: identifier4,
|
|
726
|
+
definitionDigest: digest3,
|
|
727
|
+
maxAgeMs: z7.number().int().min(0).max(Number.MAX_SAFE_INTEGER)
|
|
728
|
+
}),
|
|
729
|
+
observations: z7.array(z7.strictObject({
|
|
730
|
+
id: identifier4,
|
|
731
|
+
key: identifier4,
|
|
732
|
+
definitionDigest: digest3,
|
|
733
|
+
observedAt: timestamp
|
|
734
|
+
})).max(64)
|
|
735
|
+
}).superRefine((input, context3) => {
|
|
736
|
+
const remaining = new Set(input.scope.observations.map((observation2) => observation2.id));
|
|
737
|
+
for (const [index, observation2] of input.observations.entries()) {
|
|
738
|
+
if (!remaining.delete(observation2.id)) {
|
|
739
|
+
context3.addIssue({
|
|
740
|
+
code: "custom",
|
|
741
|
+
path: ["observations", index, "id"],
|
|
742
|
+
message: "Unexpected or duplicate observation metadata"
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
if (remaining.size > 0) {
|
|
747
|
+
context3.addIssue({
|
|
748
|
+
code: "custom",
|
|
749
|
+
path: ["observations"],
|
|
750
|
+
message: "Missing observation metadata"
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
// ../schemas/src/draft-evidence-validation.ts
|
|
756
|
+
var identifier5 = DraftEvidenceScopeSchema.shape.entityId;
|
|
757
|
+
var reference3 = DraftEvidenceScopeSchema.shape.observations.element.shape.evidence;
|
|
758
|
+
var source = z8.strictObject({ reference: reference3, sourceClass: identifier5, sensitivity: identifier5 });
|
|
759
|
+
var admission = z8.strictObject({
|
|
760
|
+
reference: reference3,
|
|
761
|
+
purpose: identifier5,
|
|
762
|
+
sensitivity: identifier5,
|
|
763
|
+
trustDomain: identifier5,
|
|
764
|
+
status: z8.enum(["approved", "revoked"])
|
|
765
|
+
});
|
|
766
|
+
function draftEvidenceReferenceKey(value) {
|
|
767
|
+
return JSON.stringify([draftPassageKey(value), value.contentDigest]);
|
|
768
|
+
}
|
|
769
|
+
function draftAdmissionKey(value) {
|
|
770
|
+
return JSON.stringify([
|
|
771
|
+
draftEvidenceReferenceKey(value.reference),
|
|
772
|
+
value.purpose,
|
|
773
|
+
value.sensitivity,
|
|
774
|
+
value.trustDomain
|
|
775
|
+
]);
|
|
776
|
+
}
|
|
777
|
+
function requireCoverage({ expected: expected2, actual, path: path3 }, context3) {
|
|
778
|
+
const remaining = new Set(expected2);
|
|
779
|
+
for (const [index, key3] of actual.entries()) {
|
|
780
|
+
if (!remaining.delete(key3)) {
|
|
781
|
+
context3.addIssue({
|
|
782
|
+
code: "custom",
|
|
783
|
+
path: [path3, index],
|
|
784
|
+
message: "Unexpected or duplicate metadata"
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
if (remaining.size > 0) {
|
|
789
|
+
context3.addIssue({ code: "custom", path: [path3], message: "Missing metadata" });
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
var evidenceShape = z8.strictObject({
|
|
793
|
+
schema: z8.literal("felspar.evidence-validation.draft/v0"),
|
|
794
|
+
mode: z8.literal("new_run"),
|
|
795
|
+
job: identifier5,
|
|
796
|
+
trustDomain: identifier5,
|
|
797
|
+
observationChecks: DraftObservationChecksSchema,
|
|
798
|
+
allowedSourceClasses: z8.array(identifier5).min(1).max(64).refine(hasUniqueValues, "Duplicate source class"),
|
|
799
|
+
valueRule: DraftValueRuleSchema,
|
|
800
|
+
unit: identifier5.optional(),
|
|
801
|
+
collection: z8.enum([
|
|
802
|
+
"observed",
|
|
803
|
+
"not_found",
|
|
804
|
+
"blocked",
|
|
805
|
+
"error",
|
|
806
|
+
"not_applicable",
|
|
807
|
+
"unattempted"
|
|
808
|
+
]),
|
|
809
|
+
sources: z8.array(source).max(64),
|
|
810
|
+
admissions: z8.array(admission).max(128)
|
|
811
|
+
});
|
|
812
|
+
function checkMetadata(input, context3) {
|
|
813
|
+
if (input.unit !== void 0 && input.valueRule.type !== "number") {
|
|
814
|
+
context3.addIssue({
|
|
815
|
+
code: "custom",
|
|
816
|
+
path: ["unit"],
|
|
817
|
+
message: "Only numeric evidence may declare units"
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
requireCoverage({
|
|
821
|
+
expected: input.observationChecks.scope.sources.map(draftEvidenceReferenceKey),
|
|
822
|
+
actual: input.sources.map((item) => draftEvidenceReferenceKey(item.reference)),
|
|
823
|
+
path: "sources"
|
|
824
|
+
}, context3);
|
|
825
|
+
const seen = /* @__PURE__ */ new Set();
|
|
826
|
+
for (const [index, record] of input.admissions.entries()) {
|
|
827
|
+
const key3 = draftAdmissionKey(record);
|
|
828
|
+
if (seen.has(key3)) {
|
|
829
|
+
context3.addIssue({
|
|
830
|
+
code: "custom",
|
|
831
|
+
path: ["admissions", index],
|
|
832
|
+
message: "Duplicate admission scope"
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
seen.add(key3);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
var DraftEvidenceMetadataSchema = evidenceShape.superRefine(checkMetadata);
|
|
839
|
+
var DraftEvidenceValidationSchema = evidenceShape.extend({
|
|
840
|
+
normalization: z8.enum(["supplied", "malformed", "timeout", "review_required"]),
|
|
841
|
+
results: z8.array(z8.strictObject({ id: identifier5, result: DraftValueResultSchema })).max(64)
|
|
842
|
+
}).superRefine((input, context3) => {
|
|
843
|
+
checkMetadata(input, context3);
|
|
844
|
+
requireCoverage({
|
|
845
|
+
expected: input.observationChecks.scope.observations.map((item) => item.id),
|
|
846
|
+
actual: input.results.map((item) => item.id),
|
|
847
|
+
path: "results"
|
|
848
|
+
}, context3);
|
|
849
|
+
});
|
|
850
|
+
|
|
851
|
+
// ../schemas/src/draft-pack-candidate.ts
|
|
852
|
+
import { z as z9 } from "zod";
|
|
853
|
+
var DraftPackCandidateSchema = z9.strictObject({
|
|
854
|
+
schema: z9.literal("felspar.pack-candidate.draft/v0"),
|
|
855
|
+
candidateId: z9.string().max(200).regex(/^[a-zA-Z0-9][a-zA-Z0-9._:/@-]*$/u),
|
|
856
|
+
authority: DraftAuthoritySchema
|
|
857
|
+
}).superRefine(({ authority }, context3) => {
|
|
858
|
+
const collections = [
|
|
859
|
+
{ path: ["authority", "rules"], values: authority.rules },
|
|
860
|
+
{ path: ["authority", "allowedOutcomes"], values: authority.allowedOutcomes },
|
|
861
|
+
{
|
|
862
|
+
path: ["authority", "definition", "allowedValues"],
|
|
863
|
+
values: authority.definition.allowedValues
|
|
864
|
+
}
|
|
865
|
+
];
|
|
866
|
+
for (const { path: path3, values } of collections) {
|
|
867
|
+
if (values.length > 64) {
|
|
868
|
+
context3.addIssue({ code: "custom", path: path3, message: "Draft candidate limit is 64 entries" });
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
});
|
|
872
|
+
|
|
873
|
+
// ../schemas/src/draft-decision-run.ts
|
|
874
|
+
var DraftDecisionRunSchema = z10.strictObject({
|
|
875
|
+
schema: z10.literal("felspar.decision-run.draft/v0"),
|
|
876
|
+
proposal: z10.strictObject({
|
|
877
|
+
candidate: DraftPackCandidateSchema,
|
|
878
|
+
evidencePolicy: z10.strictObject({
|
|
879
|
+
maxAgeMs: DraftObservationChecksSchema.shape.requirement.shape.maxAgeMs,
|
|
880
|
+
allowedSourceClasses: DraftEvidenceValidationSchema.shape.allowedSourceClasses,
|
|
881
|
+
trustDomain: DraftEvidenceValidationSchema.shape.trustDomain
|
|
882
|
+
}),
|
|
883
|
+
resolutionPolicy: z10.literal("strict-single-value/v1")
|
|
884
|
+
}),
|
|
885
|
+
evidence: DraftEvidenceValidationSchema
|
|
886
|
+
}).superRefine(({ proposal }, context3) => {
|
|
887
|
+
const outcomes = /* @__PURE__ */ new Map();
|
|
888
|
+
for (const [index, rule3] of proposal.candidate.authority.rules.entries()) {
|
|
889
|
+
const prior = outcomes.get(rule3.when.equals);
|
|
890
|
+
if (prior !== void 0 && prior !== rule3.outcome) {
|
|
891
|
+
context3.addIssue({
|
|
892
|
+
code: "custom",
|
|
893
|
+
path: ["proposal", "candidate", "authority", "rules", index],
|
|
894
|
+
message: "Contradictory equality rules require resolved precedence before evaluation"
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
outcomes.set(rule3.when.equals, rule3.outcome);
|
|
898
|
+
}
|
|
899
|
+
});
|
|
900
|
+
|
|
901
|
+
// ../schemas/src/draft-required-predicates.ts
|
|
902
|
+
import { z as z12 } from "zod";
|
|
903
|
+
|
|
904
|
+
// ../schemas/src/draft-decision-date.ts
|
|
905
|
+
import { z as z11 } from "zod";
|
|
906
|
+
function isTimeZone(value) {
|
|
907
|
+
try {
|
|
908
|
+
const format = new Intl.DateTimeFormat("en-US", { timeZone: value });
|
|
909
|
+
const options = format.resolvedOptions();
|
|
910
|
+
return options.timeZone.length > 0;
|
|
911
|
+
} catch {
|
|
912
|
+
return false;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
var DecisionDateComparisonSchema = z11.strictObject({
|
|
916
|
+
operator: z11.enum(["eq", "lt", "lte", "gt", "gte"]),
|
|
917
|
+
offsetDays: z11.number().int().min(-3660).max(3660),
|
|
918
|
+
timeZone: z11.string().min(1).max(64).regex(/^[A-Za-z][A-Za-z0-9_+/-]*$/u).refine(isTimeZone, "Unknown IANA time zone")
|
|
919
|
+
});
|
|
920
|
+
|
|
921
|
+
// ../schemas/src/draft-required-predicates.ts
|
|
922
|
+
var base = DraftAuthoritySchema.shape.definition.omit({ allowedValues: true });
|
|
923
|
+
var identifier6 = DraftEvidenceScopeSchema.shape.entityId;
|
|
924
|
+
function isSupportedIntegerDomain(rule3) {
|
|
925
|
+
return !rule3.integer || rule3.minimum >= Number.MIN_SAFE_INTEGER && rule3.maximum <= Number.MAX_SAFE_INTEGER && Math.ceil(rule3.minimum) <= Math.floor(rule3.maximum);
|
|
926
|
+
}
|
|
927
|
+
var numeric = DraftValueRuleSchema.options[1].refine(isSupportedIntegerDomain, "Integer domain must contain safe integers only");
|
|
928
|
+
var RequiredDefinitionSchema = z12.union([
|
|
929
|
+
base.extend({
|
|
930
|
+
allowedValues: z12.array(identifier6).min(1).max(64).refine(hasUniqueValues, "Duplicate value")
|
|
931
|
+
}),
|
|
932
|
+
base.extend({ valueRule: DraftValueRuleSchema.options[2] }),
|
|
933
|
+
base.extend({ valueRule: numeric, unit: identifier6 }),
|
|
934
|
+
base.extend({ valueRule: DraftValueRuleSchema.options[3] })
|
|
935
|
+
]);
|
|
936
|
+
var RequiredConditionSchema = z12.union([
|
|
937
|
+
z12.strictObject({ key: identifier6, relativeDate: RelativeDateComparisonSchema }),
|
|
938
|
+
z12.strictObject({ key: identifier6, relativeToDecision: DecisionDateComparisonSchema }),
|
|
939
|
+
z12.strictObject({ key: identifier6, equals: z12.union([identifier6, z12.boolean()]) }),
|
|
940
|
+
z12.strictObject({
|
|
941
|
+
key: identifier6,
|
|
942
|
+
oneOf: z12.array(identifier6).min(2).max(64).refine(hasUniqueValues, "Duplicate value")
|
|
943
|
+
}),
|
|
944
|
+
z12.strictObject({
|
|
945
|
+
key: identifier6,
|
|
946
|
+
compare: z12.strictObject({
|
|
947
|
+
operator: z12.enum(["eq", "lt", "lte", "gt", "gte"]),
|
|
948
|
+
value: z12.number()
|
|
949
|
+
})
|
|
950
|
+
}),
|
|
951
|
+
z12.strictObject({
|
|
952
|
+
key: identifier6,
|
|
953
|
+
compareFact: z12.strictObject({
|
|
954
|
+
operator: z12.enum(["eq", "lt", "lte", "gt", "gte"]),
|
|
955
|
+
key: identifier6
|
|
956
|
+
})
|
|
957
|
+
}),
|
|
958
|
+
z12.strictObject({
|
|
959
|
+
key: identifier6,
|
|
960
|
+
compareDate: z12.strictObject({
|
|
961
|
+
operator: z12.enum(["eq", "lt", "lte", "gt", "gte"]),
|
|
962
|
+
value: CalendarDateSchema
|
|
963
|
+
})
|
|
964
|
+
})
|
|
965
|
+
]);
|
|
966
|
+
function comparisonBounds(clause, definition3) {
|
|
967
|
+
if (!("valueRule" in definition3)) {
|
|
968
|
+
return null;
|
|
969
|
+
}
|
|
970
|
+
const rule3 = definition3.valueRule;
|
|
971
|
+
if (rule3.type === "number" && "compare" in clause) {
|
|
972
|
+
return { ...rule3, ...clause.compare };
|
|
973
|
+
}
|
|
974
|
+
if (rule3.type === "date" && "compareDate" in clause) {
|
|
975
|
+
return {
|
|
976
|
+
minimum: calendarDay("0001-01-01"),
|
|
977
|
+
maximum: calendarDay("9999-12-31"),
|
|
978
|
+
operator: clause.compareDate.operator,
|
|
979
|
+
value: calendarDay(clause.compareDate.value)
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
return null;
|
|
983
|
+
}
|
|
984
|
+
function interval(clause, definition3) {
|
|
985
|
+
const bounds = comparisonBounds(clause, definition3);
|
|
986
|
+
if (!bounds) {
|
|
987
|
+
return null;
|
|
988
|
+
}
|
|
989
|
+
const { minimum, maximum, operator, value } = bounds;
|
|
990
|
+
return {
|
|
991
|
+
low: operator === "lt" || operator === "lte" ? minimum : Math.max(minimum, value),
|
|
992
|
+
high: operator === "gt" || operator === "gte" ? maximum : Math.min(maximum, value),
|
|
993
|
+
lowClosed: operator !== "gt" || minimum > value,
|
|
994
|
+
highClosed: operator !== "lt" || maximum < value
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
function nextNumber(value) {
|
|
998
|
+
if (value === 0) {
|
|
999
|
+
return Number.MIN_VALUE;
|
|
1000
|
+
}
|
|
1001
|
+
const view = new DataView(new ArrayBuffer(8));
|
|
1002
|
+
view.setFloat64(0, value);
|
|
1003
|
+
const bits = view.getBigUint64(0);
|
|
1004
|
+
view.setBigUint64(0, value > 0 ? bits + 1n : bits - 1n);
|
|
1005
|
+
return view.getFloat64(0);
|
|
1006
|
+
}
|
|
1007
|
+
function isNonempty(range2, isInteger) {
|
|
1008
|
+
if (isInteger) {
|
|
1009
|
+
const low = range2.lowClosed ? Math.ceil(range2.low) : Math.floor(range2.low) + 1;
|
|
1010
|
+
const high = range2.highClosed ? Math.floor(range2.high) : Math.ceil(range2.high) - 1;
|
|
1011
|
+
return low <= high;
|
|
1012
|
+
}
|
|
1013
|
+
const witness = range2.lowClosed ? range2.low : nextNumber(range2.low);
|
|
1014
|
+
return witness < range2.high || witness === range2.high && range2.highClosed;
|
|
1015
|
+
}
|
|
1016
|
+
function areCompatibleFacts(left, right) {
|
|
1017
|
+
if (!right || !("valueRule" in left) || !("valueRule" in right)) {
|
|
1018
|
+
return false;
|
|
1019
|
+
}
|
|
1020
|
+
if (left.valueRule.type === "date") {
|
|
1021
|
+
return right.valueRule.type === "date";
|
|
1022
|
+
}
|
|
1023
|
+
const areNumbers = left.valueRule.type === "number" && right.valueRule.type === "number";
|
|
1024
|
+
const haveSameUnit = "unit" in left && "unit" in right && left.unit === right.unit;
|
|
1025
|
+
return areNumbers && haveSameUnit;
|
|
1026
|
+
}
|
|
1027
|
+
function isConditionSupported(clause, definition3, definitions) {
|
|
1028
|
+
if (!definition3) {
|
|
1029
|
+
return false;
|
|
1030
|
+
}
|
|
1031
|
+
if ("relativeToDecision" in clause) {
|
|
1032
|
+
return "valueRule" in definition3 && definition3.valueRule.type === "date";
|
|
1033
|
+
}
|
|
1034
|
+
if ("relativeDate" in clause) {
|
|
1035
|
+
const anchor = definitions?.get(clause.relativeDate.anchorKey);
|
|
1036
|
+
const isDate = "valueRule" in definition3 && definition3.valueRule.type === "date";
|
|
1037
|
+
return clause.key !== clause.relativeDate.anchorKey && isDate && areCompatibleFacts(definition3, anchor);
|
|
1038
|
+
}
|
|
1039
|
+
if ("compareFact" in clause) {
|
|
1040
|
+
return clause.key !== clause.compareFact.key && areCompatibleFacts(definition3, definitions?.get(clause.compareFact.key));
|
|
1041
|
+
}
|
|
1042
|
+
if ("allowedValues" in definition3) {
|
|
1043
|
+
return "oneOf" in clause ? clause.oneOf.every((value) => definition3.allowedValues.includes(value)) : "equals" in clause && typeof clause.equals === "string" && definition3.allowedValues.includes(clause.equals);
|
|
1044
|
+
}
|
|
1045
|
+
if (definition3.valueRule.type === "boolean") {
|
|
1046
|
+
return "equals" in clause && typeof clause.equals === "boolean";
|
|
1047
|
+
}
|
|
1048
|
+
const range2 = interval(clause, definition3);
|
|
1049
|
+
return range2 !== null && isNonempty(range2, definition3.valueRule.type === "date" || definition3.valueRule.integer);
|
|
1050
|
+
}
|
|
1051
|
+
function optionsOf(clause) {
|
|
1052
|
+
if ("oneOf" in clause) {
|
|
1053
|
+
return clause.oneOf;
|
|
1054
|
+
}
|
|
1055
|
+
return "equals" in clause ? [clause.equals] : null;
|
|
1056
|
+
}
|
|
1057
|
+
function relativeConditionsOverlap(left, right) {
|
|
1058
|
+
if ("relativeDate" in left && "relativeDate" in right) {
|
|
1059
|
+
const { operator: a, ...leftOffset } = left.relativeDate;
|
|
1060
|
+
const { operator: b, ...rightOffset } = right.relativeDate;
|
|
1061
|
+
if (JSON.stringify(leftOffset) === JSON.stringify(rightOffset)) {
|
|
1062
|
+
const signs = { eq: [0], lt: [-1], lte: [-1, 0], gt: [1], gte: [0, 1] };
|
|
1063
|
+
return signs[a].some((value) => signs[b].includes(value));
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
return null;
|
|
1067
|
+
}
|
|
1068
|
+
function offsetSpace(clause) {
|
|
1069
|
+
if ("relativeDate" in clause && clause.relativeDate.calendar.kind === "calendar_days") {
|
|
1070
|
+
const { operator, anchorKey, offsetDays } = clause.relativeDate;
|
|
1071
|
+
return { reference: `anchor:${anchorKey}`, operator, offsetDays };
|
|
1072
|
+
}
|
|
1073
|
+
if ("relativeToDecision" in clause) {
|
|
1074
|
+
const { operator, timeZone, offsetDays } = clause.relativeToDecision;
|
|
1075
|
+
return { reference: `decision:${timeZone}`, operator, offsetDays };
|
|
1076
|
+
}
|
|
1077
|
+
return null;
|
|
1078
|
+
}
|
|
1079
|
+
function offsetInterval(space) {
|
|
1080
|
+
const { operator, offsetDays } = space;
|
|
1081
|
+
return {
|
|
1082
|
+
low: operator === "lt" || operator === "lte" ? -Infinity : offsetDays,
|
|
1083
|
+
high: operator === "gt" || operator === "gte" ? Infinity : offsetDays,
|
|
1084
|
+
lowClosed: operator !== "gt",
|
|
1085
|
+
highClosed: operator !== "lt"
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
function intersection(a, b) {
|
|
1089
|
+
const low = Math.max(a.low, b.low);
|
|
1090
|
+
const high = Math.min(a.high, b.high);
|
|
1091
|
+
return {
|
|
1092
|
+
low,
|
|
1093
|
+
high,
|
|
1094
|
+
lowClosed: (low !== a.low || a.lowClosed) && (low !== b.low || b.lowClosed),
|
|
1095
|
+
highClosed: (high !== a.high || a.highClosed) && (high !== b.high || b.highClosed)
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
function offsetConditionsOverlap(left, right) {
|
|
1099
|
+
const relativeOverlap = relativeConditionsOverlap(left, right);
|
|
1100
|
+
if (relativeOverlap !== null) {
|
|
1101
|
+
return relativeOverlap;
|
|
1102
|
+
}
|
|
1103
|
+
const a = offsetSpace(left);
|
|
1104
|
+
const b = offsetSpace(right);
|
|
1105
|
+
return a !== null && b !== null && a.reference === b.reference ? isNonempty(intersection(offsetInterval(a), offsetInterval(b)), true) : null;
|
|
1106
|
+
}
|
|
1107
|
+
function areIntervalsOverlapping(a, b, definition3) {
|
|
1108
|
+
if (a === null || b === null || !("valueRule" in definition3)) {
|
|
1109
|
+
return true;
|
|
1110
|
+
}
|
|
1111
|
+
const rule3 = definition3.valueRule;
|
|
1112
|
+
return rule3.type === "boolean" || isNonempty(intersection(a, b), rule3.type === "date" || rule3.integer);
|
|
1113
|
+
}
|
|
1114
|
+
function areConditionsOverlapping(left, right, definition3) {
|
|
1115
|
+
if (!definition3) {
|
|
1116
|
+
return true;
|
|
1117
|
+
}
|
|
1118
|
+
const offsetOverlap = offsetConditionsOverlap(left, right);
|
|
1119
|
+
if (offsetOverlap !== null) {
|
|
1120
|
+
return offsetOverlap;
|
|
1121
|
+
}
|
|
1122
|
+
if ("compareFact" in left && "compareFact" in right && left.compareFact.key === right.compareFact.key) {
|
|
1123
|
+
const signs = { eq: [0], lt: [-1], lte: [-1, 0], gt: [1], gte: [0, 1] };
|
|
1124
|
+
return signs[left.compareFact.operator].some((value) => signs[right.compareFact.operator].includes(value));
|
|
1125
|
+
}
|
|
1126
|
+
const leftValues = optionsOf(left);
|
|
1127
|
+
const rightValues = optionsOf(right);
|
|
1128
|
+
if (leftValues && rightValues) {
|
|
1129
|
+
return leftValues.some((value) => rightValues.includes(value));
|
|
1130
|
+
}
|
|
1131
|
+
const a = interval(left, definition3);
|
|
1132
|
+
const b = interval(right, definition3);
|
|
1133
|
+
return areIntervalsOverlapping(a, b, definition3);
|
|
1134
|
+
}
|
|
1135
|
+
function operatorOf(clause) {
|
|
1136
|
+
if ("compare" in clause) {
|
|
1137
|
+
return clause.compare.operator;
|
|
1138
|
+
}
|
|
1139
|
+
if ("compareDate" in clause) {
|
|
1140
|
+
return clause.compareDate.operator;
|
|
1141
|
+
}
|
|
1142
|
+
if ("relativeDate" in clause) {
|
|
1143
|
+
return clause.relativeDate.operator;
|
|
1144
|
+
}
|
|
1145
|
+
return "relativeToDecision" in clause ? clause.relativeToDecision.operator : null;
|
|
1146
|
+
}
|
|
1147
|
+
function boundSide(clause) {
|
|
1148
|
+
const sides = { gt: "lower", gte: "lower", lt: "upper", lte: "upper" };
|
|
1149
|
+
return sides[operatorOf(clause) ?? ""] ?? null;
|
|
1150
|
+
}
|
|
1151
|
+
function isRange(group2, definition3) {
|
|
1152
|
+
const [low, high] = group2;
|
|
1153
|
+
if (low === void 0 || high === void 0 || group2.length !== 2) {
|
|
1154
|
+
return false;
|
|
1155
|
+
}
|
|
1156
|
+
const sides = /* @__PURE__ */ new Set([boundSide(low), boundSide(high)]);
|
|
1157
|
+
return sides.has("lower") && sides.has("upper") && areConditionsOverlapping(low, high, definition3);
|
|
1158
|
+
}
|
|
1159
|
+
function areKeysBounded(clauses2, definitions, canHaveRanges) {
|
|
1160
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
1161
|
+
for (const clause of clauses2) {
|
|
1162
|
+
byKey.set(clause.key, [...byKey.get(clause.key) ?? [], clause]);
|
|
1163
|
+
}
|
|
1164
|
+
const isAllowed = ([key3, group2]) => group2.length === 1 || canHaveRanges && isRange(group2, definitions.get(key3));
|
|
1165
|
+
return [...byKey].every(isAllowed);
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
// ../schemas/src/draft-required-dependencies.ts
|
|
1169
|
+
var relationalResolutionPolicy = "relational-required-types/direct-overrides/v4";
|
|
1170
|
+
var scoredResolutionPolicy = "scored-required-types/mandatory-gates/v6";
|
|
1171
|
+
var windowedResolutionPolicy = "windowed-required-types/mandatory-gates/v7";
|
|
1172
|
+
function isWindowedPolicy(policy) {
|
|
1173
|
+
return policy === windowedResolutionPolicy;
|
|
1174
|
+
}
|
|
1175
|
+
function isScoringPolicy(policy) {
|
|
1176
|
+
return policy === scoredResolutionPolicy || isWindowedPolicy(policy);
|
|
1177
|
+
}
|
|
1178
|
+
function isRelativeDatePolicy(policy) {
|
|
1179
|
+
return policy === relativeDateResolutionPolicy || isScoringPolicy(policy);
|
|
1180
|
+
}
|
|
1181
|
+
function isLayeredResolutionPolicy(policy) {
|
|
1182
|
+
return policy === relationalResolutionPolicy || isRelativeDatePolicy(policy);
|
|
1183
|
+
}
|
|
1184
|
+
function conditionKeys(clause) {
|
|
1185
|
+
if ("relativeDate" in clause) {
|
|
1186
|
+
return [clause.key, clause.relativeDate.anchorKey];
|
|
1187
|
+
}
|
|
1188
|
+
return "compareFact" in clause ? [clause.key, clause.compareFact.key] : [clause.key];
|
|
1189
|
+
}
|
|
1190
|
+
function requirementLayers(requirements3) {
|
|
1191
|
+
const keys = new Set(requirements3.map((item) => item.definition.key));
|
|
1192
|
+
const done = /* @__PURE__ */ new Set();
|
|
1193
|
+
let pending = [...requirements3];
|
|
1194
|
+
const layers = [];
|
|
1195
|
+
while (pending.length > 0) {
|
|
1196
|
+
const layer = pending.filter((item) => {
|
|
1197
|
+
const dependencies = (item.requiredWhen ?? []).flatMap(conditionKeys);
|
|
1198
|
+
return dependencies.every((key3) => keys.has(key3) && done.has(key3));
|
|
1199
|
+
});
|
|
1200
|
+
if (layer.length === 0) {
|
|
1201
|
+
throw new Error("Unknown or cyclic requirement activation");
|
|
1202
|
+
}
|
|
1203
|
+
layer.sort((left, right) => left.definition.key < right.definition.key ? -1 : 1);
|
|
1204
|
+
layers.push(layer);
|
|
1205
|
+
for (const item of layer) {
|
|
1206
|
+
done.add(item.definition.key);
|
|
1207
|
+
}
|
|
1208
|
+
pending = pending.filter((item) => !done.has(item.definition.key));
|
|
1209
|
+
}
|
|
1210
|
+
return layers;
|
|
1211
|
+
}
|
|
1212
|
+
function activationGuards(key3, requirements3) {
|
|
1213
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1214
|
+
const guards = [];
|
|
1215
|
+
const visit = (current) => {
|
|
1216
|
+
if (visited.has(current)) {
|
|
1217
|
+
return;
|
|
1218
|
+
}
|
|
1219
|
+
visited.add(current);
|
|
1220
|
+
const clauses2 = requirements3.get(current)?.requiredWhen;
|
|
1221
|
+
if (!clauses2) {
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
for (const clause of clauses2) {
|
|
1225
|
+
guards.push(clause);
|
|
1226
|
+
for (const dependency of conditionKeys(clause)) {
|
|
1227
|
+
visit(dependency);
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
};
|
|
1231
|
+
visit(key3);
|
|
1232
|
+
return guards;
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
// ../schemas/src/draft-required-activation.ts
|
|
1236
|
+
var conditionalResolutionPolicy = "conditional-required-types/direct-overrides/v3";
|
|
1237
|
+
function clauseIdentity(clause) {
|
|
1238
|
+
if ("relativeToDecision" in clause) {
|
|
1239
|
+
return JSON.stringify([clause.key, "relativeToDecision", clause.relativeToDecision]);
|
|
1240
|
+
}
|
|
1241
|
+
if ("relativeDate" in clause) {
|
|
1242
|
+
return JSON.stringify([clause.key, "relativeDate", clause.relativeDate]);
|
|
1243
|
+
}
|
|
1244
|
+
if ("compareFact" in clause) {
|
|
1245
|
+
return JSON.stringify([
|
|
1246
|
+
clause.key,
|
|
1247
|
+
"fact",
|
|
1248
|
+
clause.compareFact.operator,
|
|
1249
|
+
clause.compareFact.key
|
|
1250
|
+
]);
|
|
1251
|
+
}
|
|
1252
|
+
if ("equals" in clause) {
|
|
1253
|
+
return JSON.stringify([clause.key, "equals", clause.equals]);
|
|
1254
|
+
}
|
|
1255
|
+
if ("oneOf" in clause) {
|
|
1256
|
+
return JSON.stringify([clause.key, "oneOf", clause.oneOf]);
|
|
1257
|
+
}
|
|
1258
|
+
const isNumeric = "compare" in clause;
|
|
1259
|
+
const comparison = isNumeric ? clause.compare : clause.compareDate;
|
|
1260
|
+
return JSON.stringify([
|
|
1261
|
+
clause.key,
|
|
1262
|
+
isNumeric ? "number" : "date",
|
|
1263
|
+
comparison.operator,
|
|
1264
|
+
comparison.value
|
|
1265
|
+
]);
|
|
1266
|
+
}
|
|
1267
|
+
function isSameClause(left, right) {
|
|
1268
|
+
return clauseIdentity(left) === clauseIdentity(right);
|
|
1269
|
+
}
|
|
1270
|
+
function isPolicyValid(proposal, context3) {
|
|
1271
|
+
const clauses2 = [
|
|
1272
|
+
...proposal.rules.flatMap((rule3) => rule3.when),
|
|
1273
|
+
...proposal.requirements.flatMap((item) => item.requiredWhen ?? [])
|
|
1274
|
+
];
|
|
1275
|
+
if (clauses2.some((clause) => "relativeToDecision" in clause) && !isWindowedPolicy(proposal.resolutionPolicy)) {
|
|
1276
|
+
context3.addIssue({
|
|
1277
|
+
code: "custom",
|
|
1278
|
+
message: "Decision-date windows require the v7 resolution policy"
|
|
1279
|
+
});
|
|
1280
|
+
return false;
|
|
1281
|
+
}
|
|
1282
|
+
const hasRelative = clauses2.some((clause) => "relativeDate" in clause);
|
|
1283
|
+
if (hasRelative && !isRelativeDatePolicy(proposal.resolutionPolicy)) {
|
|
1284
|
+
context3.addIssue({
|
|
1285
|
+
code: "custom",
|
|
1286
|
+
message: "Relative dates require a supporting resolution policy (v5 or v6)"
|
|
1287
|
+
});
|
|
1288
|
+
return false;
|
|
1289
|
+
}
|
|
1290
|
+
if (isLayeredResolutionPolicy(proposal.resolutionPolicy)) {
|
|
1291
|
+
try {
|
|
1292
|
+
requirementLayers(proposal.requirements);
|
|
1293
|
+
} catch {
|
|
1294
|
+
context3.addIssue({
|
|
1295
|
+
code: "custom",
|
|
1296
|
+
path: ["requirements"],
|
|
1297
|
+
message: "Unknown or cyclic requirement activation"
|
|
1298
|
+
});
|
|
1299
|
+
return false;
|
|
1300
|
+
}
|
|
1301
|
+
} else if ([
|
|
1302
|
+
...proposal.rules.flatMap((rule3) => rule3.when),
|
|
1303
|
+
...proposal.requirements.flatMap((item) => item.requiredWhen ?? [])
|
|
1304
|
+
].some((clause) => "compareFact" in clause)) {
|
|
1305
|
+
context3.addIssue({
|
|
1306
|
+
code: "custom",
|
|
1307
|
+
message: "Fact comparisons require the v4 resolution policy"
|
|
1308
|
+
});
|
|
1309
|
+
}
|
|
1310
|
+
if (!isLayeredResolutionPolicy(proposal.resolutionPolicy) && [
|
|
1311
|
+
...proposal.rules.flatMap((rule3) => rule3.when),
|
|
1312
|
+
...proposal.requirements.flatMap((item) => item.requiredWhen ?? [])
|
|
1313
|
+
].some((clause) => "oneOf" in clause)) {
|
|
1314
|
+
context3.addIssue({
|
|
1315
|
+
code: "custom",
|
|
1316
|
+
message: "Any-of conditions require a layered resolution policy (v4 or later)"
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
return true;
|
|
1320
|
+
}
|
|
1321
|
+
function inspectRuleGuards(proposal, context3) {
|
|
1322
|
+
const requirements3 = new Map(proposal.requirements.map((item) => [item.definition.key, item]));
|
|
1323
|
+
const isRelational = isLayeredResolutionPolicy(proposal.resolutionPolicy);
|
|
1324
|
+
for (const [index, rule3] of proposal.rules.entries()) {
|
|
1325
|
+
for (const clause of rule3.when) {
|
|
1326
|
+
const gates = isRelational ? conditionKeys(clause).flatMap((key3) => activationGuards(key3, requirements3)) : requirements3.get(clause.key)?.requiredWhen ?? [];
|
|
1327
|
+
if (gates.some((gate) => rule3.when.every((candidate2) => !isSameClause(gate, candidate2)))) {
|
|
1328
|
+
context3.addIssue({
|
|
1329
|
+
code: "custom",
|
|
1330
|
+
path: ["rules", index],
|
|
1331
|
+
message: "Conditional rule must include every exact activation predicate"
|
|
1332
|
+
});
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
function inspectActivation(proposal, context3) {
|
|
1338
|
+
const requirements3 = new Map(proposal.requirements.map((item) => [item.definition.key, item]));
|
|
1339
|
+
const isRelational = isLayeredResolutionPolicy(proposal.resolutionPolicy);
|
|
1340
|
+
const definitions = new Map(proposal.requirements.map((item) => [item.definition.key, item.definition]));
|
|
1341
|
+
if (!isPolicyValid(proposal, context3)) {
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1344
|
+
for (const [index, item] of proposal.requirements.entries()) {
|
|
1345
|
+
const isDate = "valueRule" in item.definition && item.definition.valueRule.type === "date";
|
|
1346
|
+
const fail = (message) => {
|
|
1347
|
+
context3.addIssue({ code: "custom", path: ["requirements", index], message });
|
|
1348
|
+
};
|
|
1349
|
+
if (!isRelational && proposal.resolutionPolicy !== conditionalResolutionPolicy && (isDate || item.requiredWhen)) {
|
|
1350
|
+
fail("Conditional requirements and dates require the v3 resolution policy");
|
|
1351
|
+
}
|
|
1352
|
+
if (!item.requiredWhen) {
|
|
1353
|
+
continue;
|
|
1354
|
+
}
|
|
1355
|
+
if (!areKeysBounded(item.requiredWhen, definitions, isWindowedPolicy(proposal.resolutionPolicy))) {
|
|
1356
|
+
fail("Duplicate activation key");
|
|
1357
|
+
}
|
|
1358
|
+
for (const clause of item.requiredWhen) {
|
|
1359
|
+
const gate = requirements3.get(clause.key);
|
|
1360
|
+
const isSupported = isConditionSupported(clause, gate?.definition, definitions);
|
|
1361
|
+
if (!isSupported || !isRelational && gate?.requiredWhen) {
|
|
1362
|
+
fail(isRelational ? "Activation requires supported predicates over declared, compatible requirements" : "Activation requires supported predicates over unconditional requirements");
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
inspectRuleGuards(proposal, context3);
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
// ../schemas/src/draft-scoring.ts
|
|
1370
|
+
import { z as z13 } from "zod";
|
|
1371
|
+
var identifier7 = DraftEvidenceScopeSchema.shape.entityId;
|
|
1372
|
+
var units = z13.number().int().min(0).max(1e9);
|
|
1373
|
+
var clauses = z13.array(RequiredConditionSchema).min(1).max(16);
|
|
1374
|
+
var source2 = {
|
|
1375
|
+
sourceLocator: z13.string().min(1).max(4096).regex(/\S/u),
|
|
1376
|
+
contentDigest: DraftSourceReferenceSchema.shape.contentDigest
|
|
1377
|
+
};
|
|
1378
|
+
var ScoringCriterionStatusSchema = z13.enum([
|
|
1379
|
+
"matched",
|
|
1380
|
+
"otherwise",
|
|
1381
|
+
"inactive",
|
|
1382
|
+
"unresolved"
|
|
1383
|
+
]);
|
|
1384
|
+
var contribution = z13.strictObject({
|
|
1385
|
+
id: identifier7,
|
|
1386
|
+
...source2,
|
|
1387
|
+
when: clauses,
|
|
1388
|
+
pointsUnits: units
|
|
1389
|
+
});
|
|
1390
|
+
var criterion = z13.strictObject({
|
|
1391
|
+
id: identifier7,
|
|
1392
|
+
...source2,
|
|
1393
|
+
maximumUnits: units,
|
|
1394
|
+
otherwiseUnits: units,
|
|
1395
|
+
activeWhen: clauses.optional(),
|
|
1396
|
+
cases: z13.array(contribution).min(1).max(16)
|
|
1397
|
+
});
|
|
1398
|
+
var DraftScoringPolicySchema = z13.strictObject({
|
|
1399
|
+
schema: z13.literal("felspar.scoring.draft/v0"),
|
|
1400
|
+
scale: z13.union([z13.literal(1), z13.literal(100), z13.literal(1e4)]),
|
|
1401
|
+
missingPolicy: z13.literal("withhold_total"),
|
|
1402
|
+
inactivePolicy: z13.literal("exclude_without_redistribution"),
|
|
1403
|
+
criteria: z13.array(criterion).min(1).max(16)
|
|
1404
|
+
}).superRefine((policy, context3) => {
|
|
1405
|
+
if (context3.issues.length > 0) {
|
|
1406
|
+
return;
|
|
1407
|
+
}
|
|
1408
|
+
if (!hasUniqueValues(policy.criteria.map((row2) => row2.id))) {
|
|
1409
|
+
context3.addIssue({ code: "custom", path: ["criteria"], message: "Duplicate criterion" });
|
|
1410
|
+
}
|
|
1411
|
+
for (const [index, row2] of policy.criteria.entries()) {
|
|
1412
|
+
if (!hasUniqueValues(row2.cases.map((item) => item.id))) {
|
|
1413
|
+
context3.addIssue({
|
|
1414
|
+
code: "custom",
|
|
1415
|
+
path: ["criteria", index, "cases"],
|
|
1416
|
+
message: "Duplicate contribution case"
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1419
|
+
const maximum = Math.max(row2.otherwiseUnits, ...row2.cases.map((item) => item.pointsUnits));
|
|
1420
|
+
if (maximum !== row2.maximumUnits) {
|
|
1421
|
+
context3.addIssue({
|
|
1422
|
+
code: "custom",
|
|
1423
|
+
path: ["criteria", index, "maximumUnits"],
|
|
1424
|
+
message: "Criterion maximum must equal its largest declared contribution"
|
|
1425
|
+
});
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
});
|
|
1429
|
+
|
|
1430
|
+
// ../schemas/src/draft-scored-policy.ts
|
|
1431
|
+
import { z as z14 } from "zod";
|
|
1432
|
+
|
|
1433
|
+
// ../schemas/src/draft-scoring-references.ts
|
|
1434
|
+
function hasClause(clauses2, expected2) {
|
|
1435
|
+
return clauses2.some((clause) => JSON.stringify(clause) === JSON.stringify(expected2));
|
|
1436
|
+
}
|
|
1437
|
+
function mayOverlap(left, right, definitions) {
|
|
1438
|
+
for (const clause of left) {
|
|
1439
|
+
for (const other of right) {
|
|
1440
|
+
if (clause.key === other.key && !areConditionsOverlapping(clause, other, definitions.get(clause.key))) {
|
|
1441
|
+
return false;
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
return true;
|
|
1446
|
+
}
|
|
1447
|
+
function clauseIssues(clause, scope2) {
|
|
1448
|
+
const { active, definitions, byKey } = scope2;
|
|
1449
|
+
const issues = [];
|
|
1450
|
+
if ("relativeToDecision" in clause) {
|
|
1451
|
+
issues.push("Scoring does not support decision-date windows");
|
|
1452
|
+
}
|
|
1453
|
+
if (!isConditionSupported(clause, definitions.get(clause.key), definitions)) {
|
|
1454
|
+
issues.push("Scoring requires declared, compatible typed predicates");
|
|
1455
|
+
}
|
|
1456
|
+
for (const key3 of conditionKeys(clause)) {
|
|
1457
|
+
if (activationGuards(key3, byKey).some((guard) => !hasClause(active, guard))) {
|
|
1458
|
+
issues.push("Scoring applicability must include every exact requirement activation guard");
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
return issues;
|
|
1462
|
+
}
|
|
1463
|
+
function inspectScoringReferences(scoring, requirements3, context3) {
|
|
1464
|
+
const definitions = new Map(requirements3.map((row2) => [row2.definition.key, row2.definition]));
|
|
1465
|
+
const byKey = new Map(requirements3.map((row2) => [row2.definition.key, row2]));
|
|
1466
|
+
for (const [index, criterion2] of scoring.criteria.entries()) {
|
|
1467
|
+
const active = criterion2.activeWhen ?? [];
|
|
1468
|
+
const fail = (message) => {
|
|
1469
|
+
context3.addIssue({ code: "custom", path: ["criteria", index], message });
|
|
1470
|
+
};
|
|
1471
|
+
for (const clause of active) {
|
|
1472
|
+
if (conditionKeys(clause).some((key3) => byKey.get(key3)?.requiredWhen)) {
|
|
1473
|
+
fail("Scoring applicability requires unconditional requirements");
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
const all = [...active, ...criterion2.cases.flatMap((item) => item.when)];
|
|
1477
|
+
for (const clause of all) {
|
|
1478
|
+
const messages = clauseIssues(clause, { active, definitions, byKey });
|
|
1479
|
+
for (const message of messages) {
|
|
1480
|
+
fail(message);
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
for (const [caseIndex, item] of criterion2.cases.entries()) {
|
|
1484
|
+
if (criterion2.cases.slice(caseIndex + 1).some((other) => mayOverlap(item.when, other.when, definitions))) {
|
|
1485
|
+
fail("Scoring contribution cases must be provably disjoint");
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
// ../schemas/src/draft-scored-policy.ts
|
|
1492
|
+
var ScoreRangeSchema = z14.strictObject({
|
|
1493
|
+
minimumUnits: z14.number().int().min(0).max(16e9),
|
|
1494
|
+
maximumUnits: z14.number().int().min(0).max(16e9)
|
|
1495
|
+
});
|
|
1496
|
+
function isScoredProposal(proposal) {
|
|
1497
|
+
return isWindowedPolicy(proposal.resolutionPolicy) ? proposal.scoring !== void 0 || proposal.mandatoryGateRuleIds !== void 0 : proposal.resolutionPolicy === scoredResolutionPolicy;
|
|
1498
|
+
}
|
|
1499
|
+
function inspectScoredPolicy(proposal, context3) {
|
|
1500
|
+
const { scoring, mandatoryGateRuleIds: gates, rules: rules2 } = proposal;
|
|
1501
|
+
const fail = (message) => {
|
|
1502
|
+
context3.addIssue({ code: "custom", message });
|
|
1503
|
+
};
|
|
1504
|
+
if (!isScoredProposal(proposal)) {
|
|
1505
|
+
if (Boolean(scoring) || Boolean(gates) || rules2.some((rule3) => Boolean(rule3.scoreRange) || rule3.when.length === 0)) {
|
|
1506
|
+
fail(isWindowedPolicy(proposal.resolutionPolicy) ? "Score-only rules require scoring" : "Scoring and score-only rules require the v6 resolution policy");
|
|
1507
|
+
}
|
|
1508
|
+
return;
|
|
1509
|
+
}
|
|
1510
|
+
if (!scoring || !gates) {
|
|
1511
|
+
fail("Scored policy requires scoring and explicit mandatory gate identities");
|
|
1512
|
+
return;
|
|
1513
|
+
}
|
|
1514
|
+
inspectScoringReferences(scoring, proposal.requirements, context3);
|
|
1515
|
+
const ids3 = new Set(rules2.map((rule3) => rule3.id));
|
|
1516
|
+
if (gates.some((id11) => !ids3.has(id11))) {
|
|
1517
|
+
fail("Unknown mandatory gate rule");
|
|
1518
|
+
}
|
|
1519
|
+
if (rules2.every((rule3) => gates.includes(rule3.id))) {
|
|
1520
|
+
fail("Scored policy requires at least one score-band rule");
|
|
1521
|
+
}
|
|
1522
|
+
const maximum = scoring.criteria.reduce((sum, row2) => sum + row2.maximumUnits, 0);
|
|
1523
|
+
for (const rule3 of rules2) {
|
|
1524
|
+
const isGate = gates.includes(rule3.id);
|
|
1525
|
+
const hasRange = rule3.scoreRange !== void 0;
|
|
1526
|
+
if (isGate ? hasRange || rule3.when.length === 0 : !hasRange) {
|
|
1527
|
+
fail("Mandatory gates require fact predicates only; other rules require score ranges");
|
|
1528
|
+
}
|
|
1529
|
+
if (rule3.overrides.some((id11) => gates.includes(id11) !== isGate)) {
|
|
1530
|
+
fail("Explicit overrides cannot cross mandatory-gate and score-band classes");
|
|
1531
|
+
}
|
|
1532
|
+
const range2 = rule3.scoreRange;
|
|
1533
|
+
if (range2 && (range2.minimumUnits > range2.maximumUnits || range2.maximumUnits > maximum)) {
|
|
1534
|
+
fail("Score range must be ordered within the fixed maximum units");
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
function areScoredRulesDisjoint(proposal, left, right) {
|
|
1539
|
+
if (!isScoredProposal(proposal)) {
|
|
1540
|
+
return false;
|
|
1541
|
+
}
|
|
1542
|
+
const gates = proposal.mandatoryGateRuleIds ?? [];
|
|
1543
|
+
if (gates.includes(left.id) !== gates.includes(right.id)) {
|
|
1544
|
+
return true;
|
|
1545
|
+
}
|
|
1546
|
+
return Boolean(left.scoreRange && right.scoreRange && (left.scoreRange.maximumUnits < right.scoreRange.minimumUnits || right.scoreRange.maximumUnits < left.scoreRange.minimumUnits));
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
// ../schemas/src/draft-required-decision.ts
|
|
1550
|
+
var typedResolutionPolicy = "strict-required-types/direct-overrides/v2";
|
|
1551
|
+
var identifier8 = DraftEvidenceScopeSchema.shape.entityId;
|
|
1552
|
+
var duplicateIdentity = "Duplicate identity";
|
|
1553
|
+
var uniqueIds = z15.array(identifier8).max(64).refine(hasUniqueValues, duplicateIdentity);
|
|
1554
|
+
var definition2 = RequiredDefinitionSchema;
|
|
1555
|
+
var rule2 = z15.strictObject({
|
|
1556
|
+
id: identifier8,
|
|
1557
|
+
sourceLocator: z15.string().min(1).max(4096).regex(/\S/u),
|
|
1558
|
+
contentDigest: DraftSourceReferenceSchema.shape.contentDigest,
|
|
1559
|
+
when: z15.array(RequiredConditionSchema).max(32),
|
|
1560
|
+
scoreRange: ScoreRangeSchema.optional(),
|
|
1561
|
+
outcome: identifier8,
|
|
1562
|
+
overrides: z15.array(identifier8).max(256).refine(hasUniqueValues, duplicateIdentity),
|
|
1563
|
+
priority: z15.number().int().min(0).max(1e6).optional()
|
|
1564
|
+
});
|
|
1565
|
+
var shape = z15.strictObject({
|
|
1566
|
+
schema: z15.literal("felspar.required-decision.draft/v0"),
|
|
1567
|
+
proposal: z15.strictObject({
|
|
1568
|
+
candidateId: identifier8,
|
|
1569
|
+
source: DraftSourceReferenceSchema,
|
|
1570
|
+
job: identifier8,
|
|
1571
|
+
trustDomain: identifier8,
|
|
1572
|
+
resolutionPolicy: z15.enum([
|
|
1573
|
+
"strict-required-values/direct-overrides/v1",
|
|
1574
|
+
typedResolutionPolicy,
|
|
1575
|
+
conditionalResolutionPolicy,
|
|
1576
|
+
relationalResolutionPolicy,
|
|
1577
|
+
relativeDateResolutionPolicy,
|
|
1578
|
+
scoredResolutionPolicy,
|
|
1579
|
+
windowedResolutionPolicy
|
|
1580
|
+
]),
|
|
1581
|
+
scoring: DraftScoringPolicySchema.optional(),
|
|
1582
|
+
mandatoryGateRuleIds: uniqueIds.optional(),
|
|
1583
|
+
requirements: z15.array(z15.strictObject({
|
|
1584
|
+
definition: definition2,
|
|
1585
|
+
requiredWhen: z15.array(RequiredConditionSchema).min(1).max(16).optional(),
|
|
1586
|
+
evidencePolicy: DraftDecisionRunSchema.shape.proposal.shape.evidencePolicy
|
|
1587
|
+
})).min(1).max(64),
|
|
1588
|
+
allowedOutcomes: uniqueIds.min(1),
|
|
1589
|
+
rules: z15.array(rule2).min(1).max(256)
|
|
1590
|
+
}),
|
|
1591
|
+
scope: z15.strictObject({
|
|
1592
|
+
entityId: identifier8,
|
|
1593
|
+
evaluationTime: DraftObservationChecksSchema.shape.evaluationTime
|
|
1594
|
+
}),
|
|
1595
|
+
evidence: z15.array(DraftEvidenceValidationSchema).max(64)
|
|
1596
|
+
});
|
|
1597
|
+
function hasOverlap(left, right, definitions) {
|
|
1598
|
+
for (const clause of left.when) {
|
|
1599
|
+
for (const other of right.when) {
|
|
1600
|
+
if (clause.key === other.key && !areConditionsOverlapping(clause, other, definitions.get(clause.key))) {
|
|
1601
|
+
return false;
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
return true;
|
|
1606
|
+
}
|
|
1607
|
+
function draftRulePriority(ranked) {
|
|
1608
|
+
return ranked.priority ?? 0;
|
|
1609
|
+
}
|
|
1610
|
+
function hasDraftRulePrecedence(winner, other) {
|
|
1611
|
+
return winner.overrides.includes(other.id) || draftRulePriority(winner) > draftRulePriority(other);
|
|
1612
|
+
}
|
|
1613
|
+
function hasCycle(rules2) {
|
|
1614
|
+
const graph = new Map(rules2.map((item) => [item.id, item.overrides]));
|
|
1615
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
1616
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1617
|
+
const hasPathCycle = (id11) => {
|
|
1618
|
+
if (visiting.has(id11)) {
|
|
1619
|
+
return true;
|
|
1620
|
+
}
|
|
1621
|
+
if (visited.has(id11)) {
|
|
1622
|
+
return false;
|
|
1623
|
+
}
|
|
1624
|
+
visiting.add(id11);
|
|
1625
|
+
if ((graph.get(id11) ?? []).some(hasPathCycle)) {
|
|
1626
|
+
return true;
|
|
1627
|
+
}
|
|
1628
|
+
visiting.delete(id11);
|
|
1629
|
+
visited.add(id11);
|
|
1630
|
+
return false;
|
|
1631
|
+
};
|
|
1632
|
+
return rules2.some((item) => hasPathCycle(item.id));
|
|
1633
|
+
}
|
|
1634
|
+
function inspectRules(proposal, context3) {
|
|
1635
|
+
const { rules: rules2, requirements: requirements3, allowedOutcomes } = proposal;
|
|
1636
|
+
const definitions = new Map(requirements3.map((item) => [item.definition.key, item.definition]));
|
|
1637
|
+
const ids3 = new Set(rules2.map((item) => item.id));
|
|
1638
|
+
const byId = new Map(rules2.map((entry2) => [entry2.id, entry2]));
|
|
1639
|
+
for (const [index, item] of rules2.entries()) {
|
|
1640
|
+
const fail = (message) => {
|
|
1641
|
+
context3.addIssue({
|
|
1642
|
+
code: "custom",
|
|
1643
|
+
path: ["rules", index],
|
|
1644
|
+
message
|
|
1645
|
+
});
|
|
1646
|
+
};
|
|
1647
|
+
if (!allowedOutcomes.includes(item.outcome)) {
|
|
1648
|
+
fail("Undeclared outcome");
|
|
1649
|
+
}
|
|
1650
|
+
if (!areKeysBounded(item.when, definitions, isWindowedPolicy(proposal.resolutionPolicy))) {
|
|
1651
|
+
fail("Duplicate condition key");
|
|
1652
|
+
}
|
|
1653
|
+
for (const clause of item.when) {
|
|
1654
|
+
if (!isConditionSupported(clause, definitions.get(clause.key), definitions)) {
|
|
1655
|
+
fail("Undeclared condition key or value");
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
if (item.overrides.some((id11) => id11 === item.id || !ids3.has(id11))) {
|
|
1659
|
+
fail("Unknown or self override");
|
|
1660
|
+
}
|
|
1661
|
+
if (item.overrides.some((id11) => {
|
|
1662
|
+
const target = byId.get(id11);
|
|
1663
|
+
return target !== void 0 && draftRulePriority(target) > draftRulePriority(item);
|
|
1664
|
+
})) {
|
|
1665
|
+
fail("Override points to a higher priority tier");
|
|
1666
|
+
}
|
|
1667
|
+
const laterRules = rules2.slice(index + 1);
|
|
1668
|
+
for (const other of laterRules) {
|
|
1669
|
+
const isContradictory = item.outcome !== other.outcome && !areScoredRulesDisjoint(proposal, item, other) && hasOverlap(item, other, definitions);
|
|
1670
|
+
if (isContradictory && !hasDraftRulePrecedence(item, other) && !hasDraftRulePrecedence(other, item)) {
|
|
1671
|
+
fail("Overlapping contradictory rules require a direct override");
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
if (hasCycle(rules2)) {
|
|
1676
|
+
context3.addIssue({ code: "custom", path: ["rules"], message: "Override cycle" });
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
var DraftRequiredProposalSchema = shape.shape.proposal.superRefine((proposal, context3) => {
|
|
1680
|
+
if (context3.issues.length > 0) {
|
|
1681
|
+
return;
|
|
1682
|
+
}
|
|
1683
|
+
const keys = proposal.requirements.map((item) => item.definition.key);
|
|
1684
|
+
const ids3 = proposal.rules.map((item) => item.id);
|
|
1685
|
+
for (const [values, path3] of [
|
|
1686
|
+
[keys, "requirements"],
|
|
1687
|
+
[ids3, "rules"]
|
|
1688
|
+
]) {
|
|
1689
|
+
if (!hasUniqueValues(values)) {
|
|
1690
|
+
context3.addIssue({ code: "custom", path: [path3], message: duplicateIdentity });
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
for (const [index, requirement] of proposal.requirements.entries()) {
|
|
1694
|
+
if (requirement.evidencePolicy.trustDomain !== proposal.trustDomain) {
|
|
1695
|
+
context3.addIssue({
|
|
1696
|
+
code: "custom",
|
|
1697
|
+
path: ["requirements", index],
|
|
1698
|
+
message: "Requirement trust domain differs from job"
|
|
1699
|
+
});
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
if (proposal.resolutionPolicy === "strict-required-values/direct-overrides/v1" && proposal.requirements.some((item) => !("allowedValues" in item.definition))) {
|
|
1703
|
+
context3.addIssue({
|
|
1704
|
+
code: "custom",
|
|
1705
|
+
message: "Typed requirements need the typed resolution policy"
|
|
1706
|
+
});
|
|
1707
|
+
}
|
|
1708
|
+
inspectScoredPolicy(proposal, context3);
|
|
1709
|
+
inspectActivation(proposal, context3);
|
|
1710
|
+
inspectRules(proposal, context3);
|
|
1711
|
+
});
|
|
1712
|
+
function requiredEvidenceBindingIssues(evidence, keys) {
|
|
1713
|
+
const supplied = evidence.map((item) => item.observationChecks.requirement.key);
|
|
1714
|
+
const issues = [];
|
|
1715
|
+
if (!hasUniqueValues(supplied)) {
|
|
1716
|
+
issues.push({ code: "custom", path: ["evidence"], message: duplicateIdentity });
|
|
1717
|
+
}
|
|
1718
|
+
if (supplied.some((key3) => !keys.has(key3))) {
|
|
1719
|
+
issues.push({ code: "custom", path: ["evidence"], message: "Unexpected requirement evidence" });
|
|
1720
|
+
}
|
|
1721
|
+
return issues;
|
|
1722
|
+
}
|
|
1723
|
+
var DraftRequiredDecisionSchema = shape.extend({
|
|
1724
|
+
proposal: DraftRequiredProposalSchema
|
|
1725
|
+
}).superRefine((input, context3) => {
|
|
1726
|
+
if (context3.issues.length > 0) {
|
|
1727
|
+
return;
|
|
1728
|
+
}
|
|
1729
|
+
const keys = new Set(input.proposal.requirements.map((item) => item.definition.key));
|
|
1730
|
+
for (const issue of requiredEvidenceBindingIssues(input.evidence, keys)) {
|
|
1731
|
+
context3.addIssue(issue);
|
|
1732
|
+
}
|
|
1733
|
+
});
|
|
1734
|
+
|
|
1735
|
+
// ../schemas/src/draft-authority-origins.ts
|
|
1736
|
+
import { z as z17 } from "zod";
|
|
1737
|
+
|
|
1738
|
+
// ../schemas/src/draft-decision-case.ts
|
|
1739
|
+
import { z as z16 } from "zod";
|
|
1740
|
+
var identifier9 = z16.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:/@-]*$/u);
|
|
1741
|
+
var text2 = z16.string().regex(/\S/u);
|
|
1742
|
+
var digest4 = z16.string().regex(/^sha256:[a-f0-9]{64}$/u);
|
|
1743
|
+
var timestamp2 = z16.iso.datetime().regex(/T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/u);
|
|
1744
|
+
var identifiers2 = z16.array(identifier9).min(1);
|
|
1745
|
+
var unknownDefinition2 = "Unknown definition key";
|
|
1746
|
+
var observation = z16.strictObject({
|
|
1747
|
+
id: identifier9,
|
|
1748
|
+
key: identifier9,
|
|
1749
|
+
value: identifier9,
|
|
1750
|
+
definitionDigest: digest4,
|
|
1751
|
+
observedAt: timestamp2,
|
|
1752
|
+
evidence: DraftSourceReferenceSchema.extend({ entityId: identifier9, locator: text2 }),
|
|
1753
|
+
interpretation: z16.strictObject({ method: z16.literal("manual"), actorId: identifier9 })
|
|
1754
|
+
});
|
|
1755
|
+
var expected = z16.discriminatedUnion("state", [
|
|
1756
|
+
z16.strictObject({
|
|
1757
|
+
state: z16.literal("ready"),
|
|
1758
|
+
outcome: identifier9,
|
|
1759
|
+
ruleId: identifier9,
|
|
1760
|
+
observationIds: identifiers2,
|
|
1761
|
+
reason: text2
|
|
1762
|
+
}),
|
|
1763
|
+
z16.strictObject({
|
|
1764
|
+
state: z16.literal("gap"),
|
|
1765
|
+
outcome: z16.null(),
|
|
1766
|
+
key: identifier9,
|
|
1767
|
+
reason: text2
|
|
1768
|
+
}),
|
|
1769
|
+
z16.strictObject({
|
|
1770
|
+
state: z16.literal("conflict"),
|
|
1771
|
+
outcome: z16.null(),
|
|
1772
|
+
observationIds: identifiers2.min(2),
|
|
1773
|
+
reason: text2
|
|
1774
|
+
})
|
|
1775
|
+
]);
|
|
1776
|
+
var shape2 = z16.strictObject({
|
|
1777
|
+
schema: z16.literal("felspar.decision-case.draft/v0"),
|
|
1778
|
+
caseId: identifier9,
|
|
1779
|
+
entityId: identifier9,
|
|
1780
|
+
evaluatedAt: timestamp2,
|
|
1781
|
+
authority: DraftAuthoritySchema,
|
|
1782
|
+
observations: z16.array(observation),
|
|
1783
|
+
expected
|
|
1784
|
+
});
|
|
1785
|
+
function requireBinding2(isValid, context3, issue) {
|
|
1786
|
+
if (!isValid) {
|
|
1787
|
+
context3.addIssue({ code: "custom", ...issue });
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
function unique2(values, context3, path3) {
|
|
1791
|
+
const distinct = new Set(values);
|
|
1792
|
+
requireBinding2(distinct.size === values.length, context3, {
|
|
1793
|
+
path: path3,
|
|
1794
|
+
message: "Duplicate identity/value"
|
|
1795
|
+
});
|
|
1796
|
+
}
|
|
1797
|
+
function checkObservations(candidate2, context3) {
|
|
1798
|
+
const { authority, observations } = candidate2;
|
|
1799
|
+
unique2(observations.map((entry2) => entry2.id), context3, ["observations"]);
|
|
1800
|
+
for (const [index, entry2] of observations.entries()) {
|
|
1801
|
+
const at = ["observations", index];
|
|
1802
|
+
requireBinding2(entry2.key === authority.definition.key, context3, {
|
|
1803
|
+
path: [...at, "key"],
|
|
1804
|
+
message: unknownDefinition2
|
|
1805
|
+
});
|
|
1806
|
+
requireBinding2(authority.definition.allowedValues.includes(entry2.value), context3, {
|
|
1807
|
+
path: [...at, "value"],
|
|
1808
|
+
message: "Unknown definition value"
|
|
1809
|
+
});
|
|
1810
|
+
requireBinding2(entry2.definitionDigest === authority.definition.contentDigest, context3, {
|
|
1811
|
+
path: [...at, "definitionDigest"],
|
|
1812
|
+
message: "Definition fingerprint mismatch"
|
|
1813
|
+
});
|
|
1814
|
+
requireBinding2(entry2.evidence.entityId === candidate2.entityId, context3, {
|
|
1815
|
+
path: [...at, "evidence", "entityId"],
|
|
1816
|
+
message: "Evidence belongs to a different entity"
|
|
1817
|
+
});
|
|
1818
|
+
requireBinding2(Date.parse(entry2.observedAt) <= Date.parse(candidate2.evaluatedAt), context3, {
|
|
1819
|
+
path: [...at, "observedAt"],
|
|
1820
|
+
message: "Observation is later than evaluation"
|
|
1821
|
+
});
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
function checkExpected(candidate2, context3) {
|
|
1825
|
+
const result = candidate2.expected;
|
|
1826
|
+
if (result.state === "gap") {
|
|
1827
|
+
requireBinding2(result.key === candidate2.authority.definition.key, context3, {
|
|
1828
|
+
path: ["expected", "key"],
|
|
1829
|
+
message: unknownDefinition2
|
|
1830
|
+
});
|
|
1831
|
+
return;
|
|
1832
|
+
}
|
|
1833
|
+
unique2(result.observationIds, context3, ["expected", "observationIds"]);
|
|
1834
|
+
const observationIds = new Set(candidate2.observations.map((entry2) => entry2.id));
|
|
1835
|
+
for (const [index, id11] of result.observationIds.entries()) {
|
|
1836
|
+
requireBinding2(observationIds.has(id11), context3, {
|
|
1837
|
+
path: ["expected", "observationIds", index],
|
|
1838
|
+
message: "Unknown observation"
|
|
1839
|
+
});
|
|
1840
|
+
}
|
|
1841
|
+
if (result.state !== "ready") {
|
|
1842
|
+
return;
|
|
1843
|
+
}
|
|
1844
|
+
requireBinding2(candidate2.authority.allowedOutcomes.includes(result.outcome), context3, {
|
|
1845
|
+
path: ["expected", "outcome"],
|
|
1846
|
+
message: "Unknown outcome"
|
|
1847
|
+
});
|
|
1848
|
+
requireBinding2(candidate2.authority.rules.some((entry2) => entry2.id === result.ruleId), context3, { path: ["expected", "ruleId"], message: "Unknown rule" });
|
|
1849
|
+
}
|
|
1850
|
+
var DraftDecisionCaseSchema = shape2.superRefine((candidate2, context3) => {
|
|
1851
|
+
checkObservations(candidate2, context3);
|
|
1852
|
+
checkExpected(candidate2, context3);
|
|
1853
|
+
});
|
|
1854
|
+
|
|
1855
|
+
// ../schemas/src/draft-authority-origins.ts
|
|
1856
|
+
var text3 = z17.string().max(4096).regex(/\S/u);
|
|
1857
|
+
var path = z17.string().max(512).regex(/^\/authority\//u);
|
|
1858
|
+
var digest5 = z17.string().regex(/^sha256:[a-f0-9]{64}$/u);
|
|
1859
|
+
var DraftAuthorityOriginSchema = z17.discriminatedUnion("kind", [
|
|
1860
|
+
z17.strictObject({
|
|
1861
|
+
kind: z17.literal("source_derived"),
|
|
1862
|
+
source: DraftSourceReferenceSchema,
|
|
1863
|
+
locator: text3,
|
|
1864
|
+
passageDigest: digest5,
|
|
1865
|
+
admissionRef: text3
|
|
1866
|
+
}),
|
|
1867
|
+
z17.strictObject({
|
|
1868
|
+
kind: z17.literal("owner_decision"),
|
|
1869
|
+
actorId: text3,
|
|
1870
|
+
decidedAt: z17.iso.datetime().regex(/T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/u),
|
|
1871
|
+
reviewRef: text3
|
|
1872
|
+
}),
|
|
1873
|
+
z17.strictObject({
|
|
1874
|
+
kind: z17.literal("deterministic_derivation"),
|
|
1875
|
+
transform: z17.strictObject({ id: text3, version: text3, contentDigest: digest5 }),
|
|
1876
|
+
inputs: z17.array(path).min(1).max(130)
|
|
1877
|
+
}),
|
|
1878
|
+
z17.strictObject({ kind: z17.literal("unsupported_suggestion"), reason: text3 })
|
|
1879
|
+
]);
|
|
1880
|
+
var entries = z17.array(z17.strictObject({ path, origin: DraftAuthorityOriginSchema })).max(130);
|
|
1881
|
+
var DraftAuthorityOriginsSchema = z17.strictObject({
|
|
1882
|
+
schema: z17.literal("felspar.authority-origins.draft/v0"),
|
|
1883
|
+
caseId: text3,
|
|
1884
|
+
entries
|
|
1885
|
+
});
|
|
1886
|
+
var DraftCandidateOriginsSchema = z17.strictObject({
|
|
1887
|
+
schema: z17.literal("felspar.candidate-origins.draft/v0"),
|
|
1888
|
+
candidateId: DraftPackCandidateSchema.shape.candidateId,
|
|
1889
|
+
candidateDigest: digest5,
|
|
1890
|
+
entries
|
|
1891
|
+
});
|
|
1892
|
+
|
|
1893
|
+
// ../schemas/src/draft-required-normalization.ts
|
|
1894
|
+
import { z as z25 } from "zod";
|
|
1895
|
+
|
|
1896
|
+
// ../schemas/src/draft-normalized-evidence.ts
|
|
1897
|
+
import { z as z24 } from "zod";
|
|
1898
|
+
|
|
1899
|
+
// ../schemas/src/draft-semantic-bundle.ts
|
|
1900
|
+
import { z as z23 } from "zod";
|
|
1901
|
+
|
|
1902
|
+
// ../schemas/src/draft-source-compositions.ts
|
|
1903
|
+
import { z as z22 } from "zod";
|
|
1904
|
+
|
|
1905
|
+
// ../schemas/src/draft-candidate-compilation.ts
|
|
1906
|
+
import { z as z20 } from "zod";
|
|
1907
|
+
|
|
1908
|
+
// ../schemas/src/draft-compiled-decision.ts
|
|
1909
|
+
import { z as z19 } from "zod";
|
|
1910
|
+
|
|
1911
|
+
// ../schemas/src/draft-scoring-expectations.ts
|
|
1912
|
+
import { z as z18 } from "zod";
|
|
1913
|
+
var identifier10 = DraftEvidenceScopeSchema.shape.entityId;
|
|
1914
|
+
var DraftScoringExpectationSchema = z18.strictObject({
|
|
1915
|
+
status: z18.enum(["ready", "unresolved"]),
|
|
1916
|
+
scale: z18.union([z18.literal(1), z18.literal(100), z18.literal(1e4)]),
|
|
1917
|
+
maximumUnits: z18.number().int().min(0).max(16e9),
|
|
1918
|
+
totalUnits: z18.number().int().min(0).max(16e9).nullable(),
|
|
1919
|
+
criteria: z18.array(z18.strictObject({
|
|
1920
|
+
criterionId: identifier10,
|
|
1921
|
+
status: ScoringCriterionStatusSchema,
|
|
1922
|
+
pointsUnits: z18.number().int().min(0).max(1e9).nullable(),
|
|
1923
|
+
matchedCaseId: identifier10.nullable()
|
|
1924
|
+
})).min(1).max(16).refine((rows) => hasUniqueValues(rows.map((row2) => row2.criterionId)), "Duplicate scoring expectation identity")
|
|
1925
|
+
});
|
|
1926
|
+
|
|
1927
|
+
// ../schemas/src/draft-compiled-decision.ts
|
|
1928
|
+
var identifier11 = DraftEvidenceScopeSchema.shape.entityId;
|
|
1929
|
+
var digest6 = DraftSourceReferenceSchema.shape.contentDigest;
|
|
1930
|
+
var draftCompilerContract = "felspar.local-draft-compiler/v1";
|
|
1931
|
+
var draftRequiredRuntimeContract = "felspar.required-decision-run/v1";
|
|
1932
|
+
var typedCompilerContract = "felspar.local-typed-draft-compiler/v1";
|
|
1933
|
+
var typedRuntimeContract = "felspar.required-typed-decision-run/v1";
|
|
1934
|
+
var conditionalCompilerContract = "felspar.local-conditional-draft-compiler/v1";
|
|
1935
|
+
var conditionalRuntimeContract = "felspar.required-conditional-decision-run/v1";
|
|
1936
|
+
var relationalCompilerContract = "felspar.local-relational-draft-compiler/v1";
|
|
1937
|
+
var relationalRuntimeContract = "felspar.required-relational-decision-run/v1";
|
|
1938
|
+
var relativeDateCompilerContract = "felspar.local-relative-date-draft-compiler/v1";
|
|
1939
|
+
var relativeDateRuntimeContract = "felspar.required-relative-date-decision-run/v1";
|
|
1940
|
+
var scoredCompilerContract = "felspar.local-scored-draft-compiler/v1";
|
|
1941
|
+
var scoredRuntimeContract = "felspar.required-scored-decision-run/v1";
|
|
1942
|
+
var windowedCompilerContract = "felspar.local-windowed-draft-compiler/v1";
|
|
1943
|
+
var windowedRuntimeContract = "felspar.required-windowed-decision-run/v1";
|
|
1944
|
+
function requiredContracts(policy) {
|
|
1945
|
+
if (policy === windowedResolutionPolicy) {
|
|
1946
|
+
return { compilerContract: windowedCompilerContract, runtimeContract: windowedRuntimeContract };
|
|
1947
|
+
}
|
|
1948
|
+
if (policy === scoredResolutionPolicy) {
|
|
1949
|
+
return { compilerContract: scoredCompilerContract, runtimeContract: scoredRuntimeContract };
|
|
1950
|
+
}
|
|
1951
|
+
if (policy === relativeDateResolutionPolicy) {
|
|
1952
|
+
return {
|
|
1953
|
+
compilerContract: relativeDateCompilerContract,
|
|
1954
|
+
runtimeContract: relativeDateRuntimeContract
|
|
1955
|
+
};
|
|
1956
|
+
}
|
|
1957
|
+
if (policy === relationalResolutionPolicy) {
|
|
1958
|
+
return {
|
|
1959
|
+
compilerContract: relationalCompilerContract,
|
|
1960
|
+
runtimeContract: relationalRuntimeContract
|
|
1961
|
+
};
|
|
1962
|
+
}
|
|
1963
|
+
if (policy === conditionalResolutionPolicy) {
|
|
1964
|
+
return {
|
|
1965
|
+
compilerContract: conditionalCompilerContract,
|
|
1966
|
+
runtimeContract: conditionalRuntimeContract
|
|
1967
|
+
};
|
|
1968
|
+
}
|
|
1969
|
+
return policy === typedResolutionPolicy ? { compilerContract: typedCompilerContract, runtimeContract: typedRuntimeContract } : { compilerContract: draftCompilerContract, runtimeContract: draftRequiredRuntimeContract };
|
|
1970
|
+
}
|
|
1971
|
+
var expectation = z19.strictObject({
|
|
1972
|
+
scoring: DraftScoringExpectationSchema.optional(),
|
|
1973
|
+
status: z19.enum(["ready", "blocked", "review_required", "stale", "conflict", "gap"]),
|
|
1974
|
+
outcome: identifier11.nullable(),
|
|
1975
|
+
selectedRuleIds: z19.array(identifier11).max(256).refine(hasUniqueValues, "Duplicate rule identity")
|
|
1976
|
+
}).superRefine((value, context3) => {
|
|
1977
|
+
const hasOutcome = value.outcome !== null;
|
|
1978
|
+
const hasRules = value.selectedRuleIds.length > 0;
|
|
1979
|
+
const isReady = value.status === "ready";
|
|
1980
|
+
if (isReady ? !hasOutcome || !hasRules : hasOutcome || hasRules) {
|
|
1981
|
+
context3.addIssue({
|
|
1982
|
+
code: "custom",
|
|
1983
|
+
message: "Outcome and selected rules require ready status"
|
|
1984
|
+
});
|
|
1985
|
+
}
|
|
1986
|
+
});
|
|
1987
|
+
var fixtureIdentity = {
|
|
1988
|
+
id: identifier11,
|
|
1989
|
+
scope: DraftRequiredDecisionSchema.shape.scope,
|
|
1990
|
+
expected: expectation
|
|
1991
|
+
};
|
|
1992
|
+
var DraftEvidenceFixtureSchema = z19.strictObject({
|
|
1993
|
+
...fixtureIdentity,
|
|
1994
|
+
evidence: DraftRequiredDecisionSchema.shape.evidence
|
|
1995
|
+
});
|
|
1996
|
+
var DraftFactFixtureSchema = z19.strictObject({
|
|
1997
|
+
...fixtureIdentity,
|
|
1998
|
+
facts: z19.array(z19.strictObject({ key: identifier11, value: DraftEvidenceValueSchema })).max(64).refine((facts) => hasUniqueValues(facts.map((fact) => fact.key)), "Duplicate fact key")
|
|
1999
|
+
});
|
|
2000
|
+
var DraftAnyCompilationFixtureSchema = z19.union([
|
|
2001
|
+
DraftEvidenceFixtureSchema,
|
|
2002
|
+
DraftFactFixtureSchema
|
|
2003
|
+
]);
|
|
2004
|
+
function fixtureList(fixtures) {
|
|
2005
|
+
return z19.array(fixtures).min(1).max(200).refine((rows) => hasUniqueValues(rows.map((item) => item.id)), "Duplicate fixture identity");
|
|
2006
|
+
}
|
|
2007
|
+
function checkCompilation(input, context3) {
|
|
2008
|
+
const isScored = isScoredProposal(input.proposal);
|
|
2009
|
+
const keys = new Set(input.proposal.requirements.map((item) => item.definition.key));
|
|
2010
|
+
for (const [index, fixture] of input.fixtures.entries()) {
|
|
2011
|
+
if ("facts" in fixture && fixture.facts.some((fact) => !keys.has(fact.key))) {
|
|
2012
|
+
context3.addIssue({
|
|
2013
|
+
code: "custom",
|
|
2014
|
+
path: ["fixtures", index, "facts"],
|
|
2015
|
+
message: "Every fixture fact must name a proposal requirement"
|
|
2016
|
+
});
|
|
2017
|
+
}
|
|
2018
|
+
if (Boolean(fixture.expected.scoring) !== isScored) {
|
|
2019
|
+
context3.addIssue({
|
|
2020
|
+
code: "custom",
|
|
2021
|
+
path: ["fixtures", index, "expected"],
|
|
2022
|
+
message: "Scoring expectations are required exactly for scored policies"
|
|
2023
|
+
});
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
var compilationVersion = z19.literal("felspar.compilation.draft/v0");
|
|
2028
|
+
var DraftCompilationSchema = z19.strictObject({
|
|
2029
|
+
schema: compilationVersion,
|
|
2030
|
+
proposal: DraftRequiredProposalSchema,
|
|
2031
|
+
fixtures: fixtureList(DraftEvidenceFixtureSchema)
|
|
2032
|
+
}).superRefine(checkCompilation);
|
|
2033
|
+
var DraftAnyCompilationSchema = z19.strictObject({
|
|
2034
|
+
schema: compilationVersion,
|
|
2035
|
+
proposal: DraftRequiredProposalSchema,
|
|
2036
|
+
fixtures: fixtureList(DraftAnyCompilationFixtureSchema)
|
|
2037
|
+
}).superRefine(checkCompilation);
|
|
2038
|
+
var DraftCompiledBodySchema = z19.strictObject({
|
|
2039
|
+
schema: z19.literal("felspar.compiled-decision.draft/v0"),
|
|
2040
|
+
authority: z19.literal("unapproved"),
|
|
2041
|
+
compilerContract: z19.enum([
|
|
2042
|
+
draftCompilerContract,
|
|
2043
|
+
typedCompilerContract,
|
|
2044
|
+
conditionalCompilerContract,
|
|
2045
|
+
relationalCompilerContract,
|
|
2046
|
+
relativeDateCompilerContract,
|
|
2047
|
+
scoredCompilerContract,
|
|
2048
|
+
windowedCompilerContract
|
|
2049
|
+
]),
|
|
2050
|
+
runtimeContract: z19.enum([
|
|
2051
|
+
draftRequiredRuntimeContract,
|
|
2052
|
+
typedRuntimeContract,
|
|
2053
|
+
conditionalRuntimeContract,
|
|
2054
|
+
relationalRuntimeContract,
|
|
2055
|
+
relativeDateRuntimeContract,
|
|
2056
|
+
scoredRuntimeContract,
|
|
2057
|
+
windowedRuntimeContract
|
|
2058
|
+
]),
|
|
2059
|
+
proposal: DraftRequiredProposalSchema,
|
|
2060
|
+
policyDigest: digest6,
|
|
2061
|
+
fixtureSuiteDigest: digest6
|
|
2062
|
+
}).superRefine((body, context3) => {
|
|
2063
|
+
const expected2 = requiredContracts(body.proposal.resolutionPolicy);
|
|
2064
|
+
if (body.compilerContract !== expected2.compilerContract || body.runtimeContract !== expected2.runtimeContract) {
|
|
2065
|
+
context3.addIssue({
|
|
2066
|
+
code: "custom",
|
|
2067
|
+
message: "Compiler/runtime identity differs from policy semantics"
|
|
2068
|
+
});
|
|
2069
|
+
}
|
|
2070
|
+
});
|
|
2071
|
+
var DraftCompiledArtifactSchema = z19.strictObject({
|
|
2072
|
+
format: z19.literal("felspar.json-content-identity/v1"),
|
|
2073
|
+
canonicalJson: z19.string().min(1).max(1048576),
|
|
2074
|
+
contentDigest: digest6
|
|
2075
|
+
});
|
|
2076
|
+
var DraftCompiledRequestSchema = z19.strictObject({
|
|
2077
|
+
schema: z19.literal("felspar.compiled-request.draft/v0"),
|
|
2078
|
+
expectedArtifactDigest: digest6,
|
|
2079
|
+
job: identifier11,
|
|
2080
|
+
trustDomain: identifier11,
|
|
2081
|
+
scope: DraftRequiredDecisionSchema.shape.scope,
|
|
2082
|
+
evidence: DraftRequiredDecisionSchema.shape.evidence
|
|
2083
|
+
});
|
|
2084
|
+
var DraftCompiledInvocationSchema = z19.strictObject({
|
|
2085
|
+
artifact: DraftCompiledArtifactSchema,
|
|
2086
|
+
request: DraftCompiledRequestSchema
|
|
2087
|
+
});
|
|
2088
|
+
var DraftVerifiedCompilationSchema = z19.strictObject({
|
|
2089
|
+
schema: z19.literal("felspar.verified-compilation.draft/v0"),
|
|
2090
|
+
engineVersion: digest6,
|
|
2091
|
+
policyDigest: digest6,
|
|
2092
|
+
fixtureSuiteDigest: digest6
|
|
2093
|
+
});
|
|
2094
|
+
|
|
2095
|
+
// ../schemas/src/draft-candidate-compilation.ts
|
|
2096
|
+
var draftCandidateTransform = "felspar.single-value-candidate-to-required/v1";
|
|
2097
|
+
var DraftCandidateCompilationSchema = z20.strictObject({
|
|
2098
|
+
schema: z20.literal("felspar.candidate-compilation.draft/v0"),
|
|
2099
|
+
proposal: DraftDecisionRunSchema.shape.proposal,
|
|
2100
|
+
fixtures: DraftCompilationSchema.shape.fixtures
|
|
2101
|
+
});
|
|
2102
|
+
var digest7 = DraftCompiledArtifactSchema.shape.contentDigest;
|
|
2103
|
+
var DraftCandidateCompilationBindingSchema = z20.strictObject({
|
|
2104
|
+
schema: z20.literal("felspar.candidate-compilation-binding.draft/v0"),
|
|
2105
|
+
authority: z20.literal("unapproved"),
|
|
2106
|
+
transformContract: z20.literal(draftCandidateTransform),
|
|
2107
|
+
candidateDigest: digest7,
|
|
2108
|
+
proposalDigest: digest7,
|
|
2109
|
+
policyDigest: digest7,
|
|
2110
|
+
fixtureSuiteDigest: digest7,
|
|
2111
|
+
artifactDigest: digest7
|
|
2112
|
+
});
|
|
2113
|
+
var DraftCandidateCompilationVerificationSchema = z20.strictObject({
|
|
2114
|
+
proposal: DraftDecisionRunSchema.shape.proposal,
|
|
2115
|
+
fixtures: DraftCompilationSchema.shape.fixtures,
|
|
2116
|
+
artifact: DraftCompiledArtifactSchema,
|
|
2117
|
+
binding: DraftCompiledArtifactSchema
|
|
2118
|
+
});
|
|
2119
|
+
|
|
2120
|
+
// ../schemas/src/draft-source-bindings.ts
|
|
2121
|
+
import { z as z21 } from "zod";
|
|
2122
|
+
var maxDepth = 8;
|
|
2123
|
+
var caseNodeLimit = 8192;
|
|
2124
|
+
var bundleNodeLimit = 65536;
|
|
2125
|
+
function boundedDraftInput(limits2) {
|
|
2126
|
+
return z21.unknown().transform((input, context3) => {
|
|
2127
|
+
let nodes = 0;
|
|
2128
|
+
let text7 = 0;
|
|
2129
|
+
const budgetError = new Error("Draft input budget exceeded or non-data input");
|
|
2130
|
+
function copy(value, depth) {
|
|
2131
|
+
nodes += 1;
|
|
2132
|
+
if (nodes > limits2.nodes || depth > maxDepth) {
|
|
2133
|
+
throw budgetError;
|
|
2134
|
+
}
|
|
2135
|
+
if (typeof value === "string") {
|
|
2136
|
+
text7 += value.length;
|
|
2137
|
+
if (value.length > limits2.stringLength || text7 > limits2.totalText) {
|
|
2138
|
+
throw budgetError;
|
|
2139
|
+
}
|
|
2140
|
+
return value;
|
|
2141
|
+
}
|
|
2142
|
+
if (value === null || typeof value !== "object") {
|
|
2143
|
+
return value;
|
|
2144
|
+
}
|
|
2145
|
+
const isArray = Array.isArray(value);
|
|
2146
|
+
const prototype = Object.getPrototypeOf(value);
|
|
2147
|
+
if (prototype !== null && prototype !== (isArray ? Array.prototype : Object.prototype)) {
|
|
2148
|
+
throw budgetError;
|
|
2149
|
+
}
|
|
2150
|
+
if (isArray && value.length > limits2.arrayLength) {
|
|
2151
|
+
throw budgetError;
|
|
2152
|
+
}
|
|
2153
|
+
const output = isArray ? Array.from({ length: value.length }) : {};
|
|
2154
|
+
let properties = 0;
|
|
2155
|
+
for (const key3 in value) {
|
|
2156
|
+
if (!Object.hasOwn(value, key3)) {
|
|
2157
|
+
continue;
|
|
2158
|
+
}
|
|
2159
|
+
properties += 1;
|
|
2160
|
+
if (properties > (isArray ? limits2.arrayLength : 32)) {
|
|
2161
|
+
throw budgetError;
|
|
2162
|
+
}
|
|
2163
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key3);
|
|
2164
|
+
if (!descriptor || !("value" in descriptor)) {
|
|
2165
|
+
throw budgetError;
|
|
2166
|
+
}
|
|
2167
|
+
copy(key3, depth + 1);
|
|
2168
|
+
Object.defineProperty(output, key3, {
|
|
2169
|
+
value: copy(descriptor.value, depth + 1),
|
|
2170
|
+
enumerable: true,
|
|
2171
|
+
configurable: true,
|
|
2172
|
+
writable: true
|
|
2173
|
+
});
|
|
2174
|
+
}
|
|
2175
|
+
return output;
|
|
2176
|
+
}
|
|
2177
|
+
try {
|
|
2178
|
+
return copy(input, 0);
|
|
2179
|
+
} catch (error) {
|
|
2180
|
+
if (error !== budgetError) {
|
|
2181
|
+
throw error;
|
|
2182
|
+
}
|
|
2183
|
+
context3.addIssue({ code: "custom", message: budgetError.message });
|
|
2184
|
+
return z21.NEVER;
|
|
2185
|
+
}
|
|
2186
|
+
});
|
|
2187
|
+
}
|
|
2188
|
+
var isUnicodeText = (value) => !/[\uD800-\uDFFF]/u.test(value);
|
|
2189
|
+
var isSplitCharacter = (text7, offset) => offset > 0 && offset < text7.length && /[\uDC00-\uDFFF]/u.test(text7.charAt(offset));
|
|
2190
|
+
var sourceText = DraftSourceReferenceSchema.omit({ contentDigest: true }).extend({
|
|
2191
|
+
text: z21.string().min(1).max(1048576).refine(isUnicodeText, "Lone Unicode surrogate"),
|
|
2192
|
+
offsetUnit: z21.literal("utf16_code_units"),
|
|
2193
|
+
passages: z21.array(z21.strictObject({
|
|
2194
|
+
locator: z21.string().regex(/\S/u),
|
|
2195
|
+
start: z21.number().int().nonnegative(),
|
|
2196
|
+
end: z21.number().int().positive()
|
|
2197
|
+
})).max(1024)
|
|
2198
|
+
});
|
|
2199
|
+
var sourceKey = (source3) => JSON.stringify([source3.sourceId, source3.revision]);
|
|
2200
|
+
var sourceBundle = z21.strictObject({
|
|
2201
|
+
schema: z21.literal("felspar.source-text-bundle.draft/v0"),
|
|
2202
|
+
sources: z21.array(sourceText).max(32)
|
|
2203
|
+
}).superRefine((bundle, context3) => {
|
|
2204
|
+
const identities = /* @__PURE__ */ new Set();
|
|
2205
|
+
for (const [sourceIndex, source3] of bundle.sources.entries()) {
|
|
2206
|
+
const at = ["sources", sourceIndex];
|
|
2207
|
+
const identity = sourceKey(source3);
|
|
2208
|
+
if (identities.has(identity)) {
|
|
2209
|
+
context3.addIssue({ code: "custom", path: at, message: "Duplicate source/revision" });
|
|
2210
|
+
}
|
|
2211
|
+
identities.add(identity);
|
|
2212
|
+
const locators2 = /* @__PURE__ */ new Set();
|
|
2213
|
+
for (const [index, passage4] of source3.passages.entries()) {
|
|
2214
|
+
const path3 = [...at, "passages", index];
|
|
2215
|
+
if (locators2.has(passage4.locator)) {
|
|
2216
|
+
context3.addIssue({ code: "custom", path: path3, message: "Duplicate passage locator" });
|
|
2217
|
+
}
|
|
2218
|
+
locators2.add(passage4.locator);
|
|
2219
|
+
if (passage4.start >= passage4.end || passage4.end > source3.text.length) {
|
|
2220
|
+
context3.addIssue({ code: "custom", path: path3, message: "Passage is outside source text" });
|
|
2221
|
+
} else if (isSplitCharacter(source3.text, passage4.start) || isSplitCharacter(source3.text, passage4.end)) {
|
|
2222
|
+
context3.addIssue({ code: "custom", path: path3, message: "Passage splits a Unicode character" });
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
});
|
|
2227
|
+
var DraftSourceTextBundleSchema = boundedDraftInput({
|
|
2228
|
+
arrayLength: 1024,
|
|
2229
|
+
stringLength: 1048576,
|
|
2230
|
+
totalText: 33554432,
|
|
2231
|
+
nodes: bundleNodeLimit
|
|
2232
|
+
}).pipe(sourceBundle);
|
|
2233
|
+
var boundedCase = boundedDraftInput({
|
|
2234
|
+
arrayLength: 64,
|
|
2235
|
+
stringLength: 4096,
|
|
2236
|
+
totalText: 262144,
|
|
2237
|
+
nodes: caseNodeLimit
|
|
2238
|
+
}).pipe(DraftDecisionCaseSchema);
|
|
2239
|
+
var inputBudgetMessage = "Draft input budget exceeded";
|
|
2240
|
+
var caseJson = z21.string().max(262144, inputBudgetMessage);
|
|
2241
|
+
var bundleJson = z21.string().max(33554432, inputBudgetMessage);
|
|
2242
|
+
|
|
2243
|
+
// ../schemas/src/draft-source-compositions.ts
|
|
2244
|
+
var locator = z22.string().min(1).max(200).regex(/\S/u);
|
|
2245
|
+
var draftSourceCompositionContract = "felspar.ordered-source-passage-join/v1";
|
|
2246
|
+
var DraftSourceCompositionsSchema = z22.strictObject({
|
|
2247
|
+
schema: z22.literal("felspar.source-compositions.draft/v0"),
|
|
2248
|
+
transformContract: z22.literal(draftSourceCompositionContract),
|
|
2249
|
+
candidateDigest: DraftSourceReferenceSchema.shape.contentDigest,
|
|
2250
|
+
entries: z22.array(z22.strictObject({
|
|
2251
|
+
source: DraftSourceReferenceSchema.omit({ contentDigest: true }),
|
|
2252
|
+
locator,
|
|
2253
|
+
parts: z22.array(locator).min(2).max(16),
|
|
2254
|
+
separator: z22.enum(["", "\n", "\n\n"])
|
|
2255
|
+
})).max(64)
|
|
2256
|
+
});
|
|
2257
|
+
var DraftComposedSourceVerificationSchema = z22.strictObject({
|
|
2258
|
+
candidate: DraftPackCandidateSchema,
|
|
2259
|
+
bundle: DraftSourceTextBundleSchema,
|
|
2260
|
+
compositions: DraftSourceCompositionsSchema
|
|
2261
|
+
});
|
|
2262
|
+
var DraftSourceBoundCompilationSchema = z22.strictObject({
|
|
2263
|
+
compilation: DraftCandidateCompilationSchema,
|
|
2264
|
+
bundle: DraftSourceTextBundleSchema,
|
|
2265
|
+
compositions: DraftSourceCompositionsSchema
|
|
2266
|
+
});
|
|
2267
|
+
|
|
2268
|
+
// ../schemas/src/draft-semantic-bundle.ts
|
|
2269
|
+
var text4 = z23.string().min(1).max(16384).regex(/\S/u);
|
|
2270
|
+
var identifier12 = z23.string().min(1).max(200).regex(/\S/u);
|
|
2271
|
+
var semanticGuidanceFields = [
|
|
2272
|
+
"inclusions",
|
|
2273
|
+
"exclusions",
|
|
2274
|
+
"examples",
|
|
2275
|
+
"edgeCases"
|
|
2276
|
+
];
|
|
2277
|
+
var locators = z23.array(identifier12).max(16).refine((items) => {
|
|
2278
|
+
const unique4 = new Set(items);
|
|
2279
|
+
return unique4.size === items.length;
|
|
2280
|
+
}, "Duplicate guidance locator");
|
|
2281
|
+
var DraftSemanticProposalSchema = z23.strictObject({
|
|
2282
|
+
values: z23.array(z23.strictObject({
|
|
2283
|
+
value: identifier12,
|
|
2284
|
+
definitionLocator: identifier12,
|
|
2285
|
+
inclusions: locators,
|
|
2286
|
+
exclusions: locators,
|
|
2287
|
+
examples: locators,
|
|
2288
|
+
edgeCases: locators
|
|
2289
|
+
})).min(1).max(64),
|
|
2290
|
+
normalization: z23.strictObject({
|
|
2291
|
+
id: identifier12,
|
|
2292
|
+
version: identifier12,
|
|
2293
|
+
instructions: text4
|
|
2294
|
+
})
|
|
2295
|
+
});
|
|
2296
|
+
var DraftSemanticBundleInputSchema = z23.strictObject({
|
|
2297
|
+
source: DraftComposedSourceVerificationSchema,
|
|
2298
|
+
proposal: DraftSemanticProposalSchema
|
|
2299
|
+
});
|
|
2300
|
+
var excerpt = z23.strictObject({ locator: identifier12, body: text4 });
|
|
2301
|
+
var excerpts = z23.array(excerpt).max(16);
|
|
2302
|
+
var digest8 = DraftSourceReferenceSchema.shape.contentDigest;
|
|
2303
|
+
var DraftSemanticBundleSchema = z23.strictObject({
|
|
2304
|
+
schema: z23.literal("felspar.semantic-bundle.draft/v0"),
|
|
2305
|
+
authority: z23.literal("unapproved"),
|
|
2306
|
+
candidateDigest: digest8,
|
|
2307
|
+
sourceBundleDigest: digest8,
|
|
2308
|
+
compositionsDigest: digest8,
|
|
2309
|
+
semanticDefinition: z23.strictObject({
|
|
2310
|
+
key: identifier12,
|
|
2311
|
+
source: DraftSourceReferenceSchema,
|
|
2312
|
+
sourceDefinitionDigest: digest8,
|
|
2313
|
+
sourceLocator: identifier12,
|
|
2314
|
+
body: z23.string().min(1).max(262144),
|
|
2315
|
+
values: z23.array(z23.strictObject({
|
|
2316
|
+
value: identifier12,
|
|
2317
|
+
definition: excerpt,
|
|
2318
|
+
inclusions: excerpts,
|
|
2319
|
+
exclusions: excerpts,
|
|
2320
|
+
examples: excerpts,
|
|
2321
|
+
edgeCases: excerpts
|
|
2322
|
+
})).min(1).max(64)
|
|
2323
|
+
}),
|
|
2324
|
+
semanticDefinitionDigest: digest8,
|
|
2325
|
+
normalizationProposal: z23.strictObject({
|
|
2326
|
+
id: identifier12,
|
|
2327
|
+
version: identifier12,
|
|
2328
|
+
instructions: text4,
|
|
2329
|
+
status: z23.literal("proposal_only"),
|
|
2330
|
+
targetSemanticDefinitionDigest: digest8
|
|
2331
|
+
}),
|
|
2332
|
+
normalizationProposalDigest: digest8,
|
|
2333
|
+
gaps: z23.array(z23.strictObject({
|
|
2334
|
+
value: identifier12,
|
|
2335
|
+
field: z23.enum(semanticGuidanceFields),
|
|
2336
|
+
reason: z23.literal("not_supplied")
|
|
2337
|
+
})).max(256),
|
|
2338
|
+
bundleDigest: digest8
|
|
2339
|
+
});
|
|
2340
|
+
|
|
2341
|
+
// ../schemas/src/draft-normalized-evidence.ts
|
|
2342
|
+
var identifier13 = DraftEvidenceScopeSchema.shape.entityId;
|
|
2343
|
+
var reference4 = DraftEvidenceScopeSchema.shape.observations.element.shape.evidence;
|
|
2344
|
+
var digest9 = reference4.shape.contentDigest;
|
|
2345
|
+
var evaluator = z24.strictObject({
|
|
2346
|
+
provider: identifier13,
|
|
2347
|
+
requestedModel: identifier13,
|
|
2348
|
+
resolvedModel: identifier13
|
|
2349
|
+
});
|
|
2350
|
+
var DraftEvaluatorContractSchema = z24.strictObject({
|
|
2351
|
+
schema: z24.literal("felspar.evaluator-contract.draft/v0"),
|
|
2352
|
+
authority: z24.literal("unapproved"),
|
|
2353
|
+
id: identifier13,
|
|
2354
|
+
version: identifier13,
|
|
2355
|
+
semanticDefinitionDigest: digest9,
|
|
2356
|
+
normalizationProposalDigest: digest9,
|
|
2357
|
+
evaluator,
|
|
2358
|
+
calibration: z24.strictObject({ id: identifier13, version: identifier13, contentDigest: digest9 }),
|
|
2359
|
+
minimumSelectedProbability: z24.number().gt(0).max(1),
|
|
2360
|
+
inputContextContract: z24.literal("job-entity-time/v1").optional(),
|
|
2361
|
+
probabilityContract: z24.enum([
|
|
2362
|
+
"closed-distribution-unique-maximum/v1",
|
|
2363
|
+
"closed-distribution-with-abstention/v1"
|
|
2364
|
+
])
|
|
2365
|
+
});
|
|
2366
|
+
var judgment = z24.discriminatedUnion("status", [
|
|
2367
|
+
z24.strictObject({
|
|
2368
|
+
status: z24.literal("evaluated"),
|
|
2369
|
+
abstentionProbability: z24.number().min(0).max(1).optional(),
|
|
2370
|
+
probabilities: z24.array(z24.strictObject({
|
|
2371
|
+
value: z24.string().min(1).max(200),
|
|
2372
|
+
probability: z24.number().min(0).max(1)
|
|
2373
|
+
})).min(1).max(64)
|
|
2374
|
+
}),
|
|
2375
|
+
z24.strictObject({ status: z24.enum(["abstained", "timeout", "malformed", "review_required"]) })
|
|
2376
|
+
]);
|
|
2377
|
+
var DraftNormalizedEvidenceSchema = z24.strictObject({
|
|
2378
|
+
schema: z24.literal("felspar.normalized-evidence.draft/v0"),
|
|
2379
|
+
attemptStatus: DraftEvidenceValidationSchema.shape.normalization.optional(),
|
|
2380
|
+
answerType: z24.literal("boolean").optional(),
|
|
2381
|
+
semantics: DraftSemanticBundleInputSchema,
|
|
2382
|
+
expectedSemanticBundleDigest: digest9,
|
|
2383
|
+
evaluatorContract: DraftEvaluatorContractSchema,
|
|
2384
|
+
expectedEvaluatorContractDigest: digest9,
|
|
2385
|
+
proposal: DraftDecisionRunSchema.shape.proposal,
|
|
2386
|
+
evidence: z24.strictObject({
|
|
2387
|
+
schema: DraftEvidenceValidationSchema.shape.schema,
|
|
2388
|
+
mode: DraftEvidenceValidationSchema.shape.mode,
|
|
2389
|
+
job: DraftEvidenceValidationSchema.shape.job,
|
|
2390
|
+
trustDomain: DraftEvidenceValidationSchema.shape.trustDomain,
|
|
2391
|
+
observationChecks: DraftEvidenceValidationSchema.shape.observationChecks,
|
|
2392
|
+
allowedSourceClasses: DraftEvidenceValidationSchema.shape.allowedSourceClasses,
|
|
2393
|
+
collection: DraftEvidenceValidationSchema.shape.collection,
|
|
2394
|
+
sources: DraftEvidenceValidationSchema.shape.sources,
|
|
2395
|
+
admissions: DraftEvidenceValidationSchema.shape.admissions
|
|
2396
|
+
}),
|
|
2397
|
+
normalizations: z24.array(z24.strictObject({
|
|
2398
|
+
observationId: identifier13,
|
|
2399
|
+
evidence: reference4,
|
|
2400
|
+
semanticBundleDigest: digest9,
|
|
2401
|
+
semanticDefinitionDigest: digest9,
|
|
2402
|
+
normalizationProposalDigest: digest9,
|
|
2403
|
+
evaluatorContractDigest: digest9,
|
|
2404
|
+
evaluator,
|
|
2405
|
+
calibrationDigest: digest9,
|
|
2406
|
+
inputScope: z24.strictObject({
|
|
2407
|
+
job: DraftEvidenceValidationSchema.shape.job,
|
|
2408
|
+
entityId: identifier13,
|
|
2409
|
+
evaluationTime: DraftEvidenceValidationSchema.shape.observationChecks.shape.evaluationTime
|
|
2410
|
+
}).optional(),
|
|
2411
|
+
judgment
|
|
2412
|
+
})).max(64)
|
|
2413
|
+
});
|
|
2414
|
+
|
|
2415
|
+
// ../schemas/src/draft-required-normalization.ts
|
|
2416
|
+
var { key } = DraftAuthoritySchema.shape.definition.shape;
|
|
2417
|
+
var digest10 = DraftNormalizedEvidenceSchema.shape.expectedSemanticBundleDigest;
|
|
2418
|
+
var conditionalNormalizationContract = "felspar.conditional-enum-normalization/v1";
|
|
2419
|
+
var DraftRequiredNormalizationSchema = z25.strictObject({
|
|
2420
|
+
schema: z25.enum([
|
|
2421
|
+
"felspar.required-normalization.draft/v0",
|
|
2422
|
+
"felspar.required-normalization.draft/v1"
|
|
2423
|
+
]),
|
|
2424
|
+
proposal: DraftRequiredProposalSchema,
|
|
2425
|
+
scope: DraftRequiredDecisionSchema.shape.scope,
|
|
2426
|
+
bindings: z25.array(z25.strictObject({
|
|
2427
|
+
key,
|
|
2428
|
+
semanticBundleDigest: digest10,
|
|
2429
|
+
evaluatorContractDigest: digest10
|
|
2430
|
+
})).min(1).max(16),
|
|
2431
|
+
normalizations: z25.array(z25.strictObject({ key, input: DraftNormalizedEvidenceSchema })).max(16)
|
|
2432
|
+
}).superRefine((input, context3) => {
|
|
2433
|
+
if (context3.issues.length > 0) {
|
|
2434
|
+
return;
|
|
2435
|
+
}
|
|
2436
|
+
if (isLayeredResolutionPolicy(input.proposal.resolutionPolicy)) {
|
|
2437
|
+
context3.addIssue({
|
|
2438
|
+
code: "custom",
|
|
2439
|
+
message: "The v4/v5 policies require the supplied route; dependency-layer normalization is unsupported"
|
|
2440
|
+
});
|
|
2441
|
+
return;
|
|
2442
|
+
}
|
|
2443
|
+
const isConditional = input.proposal.resolutionPolicy === conditionalResolutionPolicy;
|
|
2444
|
+
if (isConditional !== (input.schema === "felspar.required-normalization.draft/v1")) {
|
|
2445
|
+
context3.addIssue({
|
|
2446
|
+
code: "custom",
|
|
2447
|
+
message: "Conditional policy requires the supplied route or v1 normalization"
|
|
2448
|
+
});
|
|
2449
|
+
}
|
|
2450
|
+
if (input.proposal.requirements.some((item) => !("allowedValues" in item.definition))) {
|
|
2451
|
+
context3.addIssue({
|
|
2452
|
+
code: "custom",
|
|
2453
|
+
message: "This normalization route supports enum definitions only"
|
|
2454
|
+
});
|
|
2455
|
+
}
|
|
2456
|
+
const keys = new Set(input.proposal.requirements.map((item) => item.definition.key));
|
|
2457
|
+
for (const field of ["bindings", "normalizations"]) {
|
|
2458
|
+
const supplied = input[field].map((item) => item.key);
|
|
2459
|
+
const unique4 = new Set(supplied);
|
|
2460
|
+
if (unique4.size !== supplied.length || supplied.some((item) => !keys.has(item))) {
|
|
2461
|
+
context3.addIssue({
|
|
2462
|
+
code: "custom",
|
|
2463
|
+
path: [field],
|
|
2464
|
+
message: "Unknown or duplicate requirement key"
|
|
2465
|
+
});
|
|
2466
|
+
}
|
|
2467
|
+
if (field === "bindings" && supplied.length !== keys.size) {
|
|
2468
|
+
context3.addIssue({
|
|
2469
|
+
code: "custom",
|
|
2470
|
+
path: [field],
|
|
2471
|
+
message: "Every requirement needs a binding"
|
|
2472
|
+
});
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
});
|
|
2476
|
+
|
|
2477
|
+
// ../schemas/src/draft-required-context.ts
|
|
2478
|
+
import { z as z31 } from "zod";
|
|
2479
|
+
|
|
2480
|
+
// ../schemas/src/draft-context-selection.ts
|
|
2481
|
+
import { z as z28 } from "zod";
|
|
2482
|
+
|
|
2483
|
+
// ../schemas/src/draft-context.ts
|
|
2484
|
+
import { z as z27 } from "zod";
|
|
2485
|
+
|
|
2486
|
+
// ../schemas/src/draft-primitive-mapping.ts
|
|
2487
|
+
import { z as z26 } from "zod";
|
|
2488
|
+
var authorityPrimitives = [
|
|
2489
|
+
"actors",
|
|
2490
|
+
"decision_criteria",
|
|
2491
|
+
"source_signals",
|
|
2492
|
+
"needs_and_requirements",
|
|
2493
|
+
"evidence_and_proof",
|
|
2494
|
+
"boundaries",
|
|
2495
|
+
"output_contracts",
|
|
2496
|
+
"routing_jobs",
|
|
2497
|
+
"gaps",
|
|
2498
|
+
"evaluations"
|
|
2499
|
+
];
|
|
2500
|
+
var label = z26.string().trim().min(1).max(2e3);
|
|
2501
|
+
var id = z26.string().min(1).max(200);
|
|
2502
|
+
var reference5 = z26.discriminatedUnion("kind", [
|
|
2503
|
+
z26.strictObject({ kind: z26.literal("interpreter"), observationId: id }),
|
|
2504
|
+
z26.strictObject({ kind: z26.literal("rule"), ruleId: id }),
|
|
2505
|
+
z26.strictObject({ kind: z26.literal("observation"), observationId: id }),
|
|
2506
|
+
z26.strictObject({ kind: z26.literal("evidence"), observationId: id }),
|
|
2507
|
+
z26.strictObject({ kind: z26.literal("definition") }),
|
|
2508
|
+
z26.strictObject({ kind: z26.literal("outcomes") }),
|
|
2509
|
+
z26.strictObject({ kind: z26.literal("job") }),
|
|
2510
|
+
z26.strictObject({ kind: z26.literal("expectation") })
|
|
2511
|
+
]);
|
|
2512
|
+
var kinds = {
|
|
2513
|
+
actors: ["interpreter"],
|
|
2514
|
+
decision_criteria: ["rule"],
|
|
2515
|
+
source_signals: ["observation"],
|
|
2516
|
+
needs_and_requirements: ["definition"],
|
|
2517
|
+
evidence_and_proof: ["evidence"],
|
|
2518
|
+
boundaries: [],
|
|
2519
|
+
output_contracts: ["outcomes"],
|
|
2520
|
+
routing_jobs: ["job"],
|
|
2521
|
+
gaps: ["expectation"],
|
|
2522
|
+
evaluations: ["expectation"]
|
|
2523
|
+
};
|
|
2524
|
+
var category = z26.enum(authorityPrimitives);
|
|
2525
|
+
var row = z26.discriminatedUnion("status", [
|
|
2526
|
+
z26.strictObject({
|
|
2527
|
+
primitive: category,
|
|
2528
|
+
status: z26.literal("mapped"),
|
|
2529
|
+
explanation: label,
|
|
2530
|
+
references: z26.array(reference5).min(1).max(64),
|
|
2531
|
+
limitation: label
|
|
2532
|
+
}),
|
|
2533
|
+
z26.strictObject({ primitive: category, status: z26.literal("needs_decision"), reason: label })
|
|
2534
|
+
]);
|
|
2535
|
+
var DraftPrimitiveMappingSchema = z26.strictObject({
|
|
2536
|
+
schema: z26.literal("felspar.primitive-mapping.draft/v0"),
|
|
2537
|
+
caseId: id,
|
|
2538
|
+
rows: z26.array(row).length(authorityPrimitives.length)
|
|
2539
|
+
}).superRefine((mapping, context3) => {
|
|
2540
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2541
|
+
for (const [index, entry2] of mapping.rows.entries()) {
|
|
2542
|
+
const path3 = ["rows", index];
|
|
2543
|
+
if (seen.has(entry2.primitive)) {
|
|
2544
|
+
context3.addIssue({ code: "custom", path: path3, message: "Duplicate primitive" });
|
|
2545
|
+
}
|
|
2546
|
+
seen.add(entry2.primitive);
|
|
2547
|
+
if (entry2.status !== "mapped") {
|
|
2548
|
+
continue;
|
|
2549
|
+
}
|
|
2550
|
+
const references = /* @__PURE__ */ new Set();
|
|
2551
|
+
for (const [at, ref] of entry2.references.entries()) {
|
|
2552
|
+
if (!kinds[entry2.primitive].includes(ref.kind)) {
|
|
2553
|
+
context3.addIssue({
|
|
2554
|
+
code: "custom",
|
|
2555
|
+
path: [...path3, "references", at],
|
|
2556
|
+
message: "Reference kind does not belong to this primitive"
|
|
2557
|
+
});
|
|
2558
|
+
}
|
|
2559
|
+
const key3 = JSON.stringify(ref);
|
|
2560
|
+
if (references.has(key3)) {
|
|
2561
|
+
context3.addIssue({
|
|
2562
|
+
code: "custom",
|
|
2563
|
+
path: [...path3, "references", at],
|
|
2564
|
+
message: "Duplicate reference"
|
|
2565
|
+
});
|
|
2566
|
+
}
|
|
2567
|
+
references.add(key3);
|
|
2568
|
+
}
|
|
2569
|
+
}
|
|
2570
|
+
});
|
|
2571
|
+
function readObservation(input, ref) {
|
|
2572
|
+
const index = input.observations.findIndex((entry2) => entry2.id === ref.observationId);
|
|
2573
|
+
const observation2 = input.observations[index];
|
|
2574
|
+
if (!observation2) {
|
|
2575
|
+
return void 0;
|
|
2576
|
+
}
|
|
2577
|
+
const path3 = `observations.${index}`;
|
|
2578
|
+
if (ref.kind === "interpreter") {
|
|
2579
|
+
return { path: `${path3}.interpretation`, value: observation2.interpretation };
|
|
2580
|
+
}
|
|
2581
|
+
const { sourceId, revision, locator: locator2 } = observation2.evidence;
|
|
2582
|
+
return {
|
|
2583
|
+
path: ref.kind === "evidence" ? `${path3}.evidence` : path3,
|
|
2584
|
+
value: ref.kind === "evidence" ? observation2.evidence : observation2,
|
|
2585
|
+
source: { sourceId, revision, locator: locator2 }
|
|
2586
|
+
};
|
|
2587
|
+
}
|
|
2588
|
+
function readReference(input, ref) {
|
|
2589
|
+
const { authority } = input;
|
|
2590
|
+
switch (ref.kind) {
|
|
2591
|
+
case "definition": {
|
|
2592
|
+
return {
|
|
2593
|
+
path: "authority.definition",
|
|
2594
|
+
value: authority.definition,
|
|
2595
|
+
source: { ...authority.source, locator: authority.definition.sourceLocator }
|
|
2596
|
+
};
|
|
2597
|
+
}
|
|
2598
|
+
case "outcomes": {
|
|
2599
|
+
return { path: "authority.allowedOutcomes", value: authority.allowedOutcomes };
|
|
2600
|
+
}
|
|
2601
|
+
case "job": {
|
|
2602
|
+
return { path: "authority.job", value: authority.job };
|
|
2603
|
+
}
|
|
2604
|
+
case "expectation": {
|
|
2605
|
+
return { path: "expected", value: input.expected };
|
|
2606
|
+
}
|
|
2607
|
+
case "rule": {
|
|
2608
|
+
const index = authority.rules.findIndex((entry2) => entry2.id === ref.ruleId);
|
|
2609
|
+
const rule3 = authority.rules[index];
|
|
2610
|
+
return rule3 ? {
|
|
2611
|
+
path: `authority.rules.${index}`,
|
|
2612
|
+
value: rule3,
|
|
2613
|
+
source: { ...authority.source, locator: rule3.sourceLocator }
|
|
2614
|
+
} : void 0;
|
|
2615
|
+
}
|
|
2616
|
+
case "interpreter":
|
|
2617
|
+
case "observation":
|
|
2618
|
+
case "evidence": {
|
|
2619
|
+
return readObservation(input, ref);
|
|
2620
|
+
}
|
|
2621
|
+
default: {
|
|
2622
|
+
return void 0;
|
|
2623
|
+
}
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2626
|
+
var DraftMappedCaseSchema = z26.strictObject({
|
|
2627
|
+
input: DraftDecisionCaseSchema,
|
|
2628
|
+
mapping: DraftPrimitiveMappingSchema
|
|
2629
|
+
}).superRefine(({ input, mapping }, context3) => {
|
|
2630
|
+
if (input.caseId !== mapping.caseId) {
|
|
2631
|
+
context3.addIssue({
|
|
2632
|
+
code: "custom",
|
|
2633
|
+
path: ["mapping", "caseId"],
|
|
2634
|
+
message: "Mapping belongs to a different case"
|
|
2635
|
+
});
|
|
2636
|
+
}
|
|
2637
|
+
for (const [index, entry2] of mapping.rows.entries()) {
|
|
2638
|
+
if (entry2.status !== "mapped") {
|
|
2639
|
+
continue;
|
|
2640
|
+
}
|
|
2641
|
+
if (entry2.primitive === "gaps" && input.expected.state === "ready") {
|
|
2642
|
+
context3.addIssue({
|
|
2643
|
+
code: "custom",
|
|
2644
|
+
path: ["mapping", "rows", index],
|
|
2645
|
+
message: "Ready expectation cannot demonstrate an unresolved gap or conflict"
|
|
2646
|
+
});
|
|
2647
|
+
}
|
|
2648
|
+
for (const [at, ref] of entry2.references.entries()) {
|
|
2649
|
+
if (!readReference(input, ref)) {
|
|
2650
|
+
context3.addIssue({
|
|
2651
|
+
code: "custom",
|
|
2652
|
+
path: ["mapping", "rows", index, "references", at],
|
|
2653
|
+
message: "Referenced example field does not exist"
|
|
2654
|
+
});
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
}
|
|
2658
|
+
});
|
|
2659
|
+
|
|
2660
|
+
// ../schemas/src/draft-context.ts
|
|
2661
|
+
var identifier14 = DraftEvidenceScopeSchema.shape.entityId;
|
|
2662
|
+
var reference6 = DraftEvidenceScopeSchema.shape.observations.element.shape.evidence;
|
|
2663
|
+
var ids = z27.array(identifier14).max(64).refine(hasUniqueValues, "Duplicate entry ID");
|
|
2664
|
+
var entry = z27.strictObject({
|
|
2665
|
+
id: identifier14,
|
|
2666
|
+
primitive: z27.enum(authorityPrimitives),
|
|
2667
|
+
body: z27.string().min(1).max(8192).regex(/\S/u),
|
|
2668
|
+
source: reference6,
|
|
2669
|
+
dependencies: ids,
|
|
2670
|
+
conflictsWith: ids
|
|
2671
|
+
});
|
|
2672
|
+
var selection = z27.strictObject({
|
|
2673
|
+
outcome: identifier14,
|
|
2674
|
+
requiredIds: ids,
|
|
2675
|
+
optional: z27.array(z27.strictObject({ id: identifier14, priority: z27.number().int().min(0).max(65535) })).max(64)
|
|
2676
|
+
});
|
|
2677
|
+
var DraftContextPlanSchema = z27.strictObject({
|
|
2678
|
+
schema: z27.literal("felspar.context-plan.draft/v0"),
|
|
2679
|
+
authority: z27.literal("unapproved"),
|
|
2680
|
+
artifactDigest: reference6.shape.contentDigest,
|
|
2681
|
+
job: identifier14,
|
|
2682
|
+
trustDomain: identifier14,
|
|
2683
|
+
selectionBinding: z27.strictObject({
|
|
2684
|
+
selectionPlanDigest: reference6.shape.contentDigest,
|
|
2685
|
+
outputSurface: identifier14
|
|
2686
|
+
}).optional(),
|
|
2687
|
+
entries: z27.array(entry).min(1).max(64),
|
|
2688
|
+
requiredIds: ids,
|
|
2689
|
+
selections: z27.array(selection).min(1).max(64),
|
|
2690
|
+
budget: z27.strictObject({
|
|
2691
|
+
maxEntries: z27.number().int().min(0).max(64),
|
|
2692
|
+
maxBytes: z27.number().int().min(1).max(65536)
|
|
2693
|
+
})
|
|
2694
|
+
}).superRefine((plan, context3) => {
|
|
2695
|
+
if (context3.issues.length > 0) {
|
|
2696
|
+
return;
|
|
2697
|
+
}
|
|
2698
|
+
const collections = [
|
|
2699
|
+
plan.entries.map((item) => item.id),
|
|
2700
|
+
plan.selections.map((item) => item.outcome)
|
|
2701
|
+
];
|
|
2702
|
+
for (const item of plan.selections) {
|
|
2703
|
+
collections.push(item.optional.map((option2) => option2.id));
|
|
2704
|
+
const priorities = new Set(item.optional.map((option2) => option2.priority));
|
|
2705
|
+
if (priorities.size !== item.optional.length) {
|
|
2706
|
+
context3.addIssue({ code: "custom", message: "Optional priorities must be unique" });
|
|
2707
|
+
}
|
|
2708
|
+
}
|
|
2709
|
+
if (collections.some((values) => !hasUniqueValues(values))) {
|
|
2710
|
+
context3.addIssue({ code: "custom", message: "Duplicate entry, outcome or optional root" });
|
|
2711
|
+
}
|
|
2712
|
+
});
|
|
2713
|
+
var DraftContextInputSchema = z27.strictObject({
|
|
2714
|
+
artifact: DraftCompiledArtifactSchema,
|
|
2715
|
+
decision: DraftCompiledRequestSchema,
|
|
2716
|
+
plan: DraftContextPlanSchema,
|
|
2717
|
+
expectedPlanDigest: reference6.shape.contentDigest
|
|
2718
|
+
});
|
|
2719
|
+
|
|
2720
|
+
// ../schemas/src/draft-context-selection.ts
|
|
2721
|
+
var base2 = DraftContextPlanSchema.shape;
|
|
2722
|
+
var identifier15 = base2.job;
|
|
2723
|
+
var draftOutputPreparationContract = "felspar.structured-output-preparation/v1";
|
|
2724
|
+
var draftRequiredEvaluationContract = "felspar.required-evaluations/v1";
|
|
2725
|
+
var evaluationValidation = z28.strictObject({
|
|
2726
|
+
contract: z28.literal(draftRequiredEvaluationContract),
|
|
2727
|
+
recipes: z28.array(z28.strictObject({ entryId: identifier15, expectedRecipeDigest: base2.artifactDigest })).min(1).max(8).refine((items) => hasUniqueValues(items.map((item) => item.entryId)), "Duplicate required recipe"),
|
|
2728
|
+
maxRequests: z28.number().int().min(1).max(128),
|
|
2729
|
+
maxTotalBytes: z28.number().int().min(1).max(65536)
|
|
2730
|
+
});
|
|
2731
|
+
var hasUniqueIds = (values) => hasUniqueValues(values);
|
|
2732
|
+
var candidate = z28.strictObject({
|
|
2733
|
+
entryId: identifier15,
|
|
2734
|
+
outcomes: z28.array(identifier15).min(1).max(64).refine(hasUniqueIds, "Duplicate outcome"),
|
|
2735
|
+
when: z28.array(z28.strictObject({ key: identifier15, equals: identifier15 })).max(16).refine((clauses2) => hasUniqueIds(clauses2.map((clause) => clause.key)), "Duplicate condition key"),
|
|
2736
|
+
priority: z28.number().int().min(0).max(65535)
|
|
2737
|
+
});
|
|
2738
|
+
var group = z28.strictObject({
|
|
2739
|
+
id: identifier15,
|
|
2740
|
+
min: z28.number().int().min(0).max(64),
|
|
2741
|
+
max: z28.number().int().min(0).max(64),
|
|
2742
|
+
candidates: z28.array(candidate).max(64)
|
|
2743
|
+
}).refine((value) => value.min <= value.max, "Group minimum exceeds maximum");
|
|
2744
|
+
var DraftContextSelectionPlanSchema = z28.strictObject({
|
|
2745
|
+
schema: z28.enum([
|
|
2746
|
+
"felspar.context-selection.draft/v0",
|
|
2747
|
+
"felspar.context-selection.draft/v1",
|
|
2748
|
+
"felspar.context-selection.draft/v2"
|
|
2749
|
+
]),
|
|
2750
|
+
evaluationValidation: evaluationValidation.optional(),
|
|
2751
|
+
outputValidation: z28.strictObject({
|
|
2752
|
+
contract: z28.literal(draftOutputPreparationContract),
|
|
2753
|
+
entryId: identifier15,
|
|
2754
|
+
expectedContractDigest: base2.artifactDigest
|
|
2755
|
+
}).optional(),
|
|
2756
|
+
authority: base2.authority,
|
|
2757
|
+
artifactDigest: base2.artifactDigest,
|
|
2758
|
+
job: base2.job,
|
|
2759
|
+
trustDomain: base2.trustDomain,
|
|
2760
|
+
outputSurface: identifier15,
|
|
2761
|
+
unresolvedGuidanceEntryId: identifier15.optional(),
|
|
2762
|
+
attempts: z28.strictObject({
|
|
2763
|
+
max: z28.number().int().min(1).max(10),
|
|
2764
|
+
withProgress: z28.number().int().min(1).max(10)
|
|
2765
|
+
}).refine((value) => value.withProgress >= value.max, "withProgress below max").optional(),
|
|
2766
|
+
entries: base2.entries,
|
|
2767
|
+
requiredIds: base2.requiredIds,
|
|
2768
|
+
budget: base2.budget,
|
|
2769
|
+
groups: z28.array(group).min(1).max(8)
|
|
2770
|
+
}).superRefine((plan, context3) => {
|
|
2771
|
+
if (context3.issues.length > 0) {
|
|
2772
|
+
return;
|
|
2773
|
+
}
|
|
2774
|
+
if (plan.schema !== "felspar.context-selection.draft/v0" !== Boolean(plan.outputValidation)) {
|
|
2775
|
+
context3.addIssue({
|
|
2776
|
+
code: "custom",
|
|
2777
|
+
message: "Output validation requires selection-plan v1 or v2"
|
|
2778
|
+
});
|
|
2779
|
+
}
|
|
2780
|
+
if (plan.schema === "felspar.context-selection.draft/v2" !== Boolean(plan.evaluationValidation)) {
|
|
2781
|
+
context3.addIssue({
|
|
2782
|
+
code: "custom",
|
|
2783
|
+
message: "Required evaluations require selection-plan v2"
|
|
2784
|
+
});
|
|
2785
|
+
}
|
|
2786
|
+
const candidateIds = plan.groups.flatMap((item) => item.candidates.map((c) => c.entryId));
|
|
2787
|
+
if (candidateIds.length > 64 || !hasUniqueIds(candidateIds) || !hasUniqueIds(plan.groups.map((item) => item.id)) || !hasUniqueIds(plan.entries.map((item) => item.id))) {
|
|
2788
|
+
context3.addIssue({ code: "custom", message: "Duplicate identities or too many candidates" });
|
|
2789
|
+
}
|
|
2790
|
+
if (plan.requiredIds.some((id11) => candidateIds.includes(id11))) {
|
|
2791
|
+
context3.addIssue({ code: "custom", message: "Global required root cannot be a candidate" });
|
|
2792
|
+
}
|
|
2793
|
+
const guidanceId = plan.unresolvedGuidanceEntryId;
|
|
2794
|
+
if (guidanceId === void 0) {
|
|
2795
|
+
return;
|
|
2796
|
+
}
|
|
2797
|
+
const entry2 = plan.entries.find((row2) => row2.id === guidanceId);
|
|
2798
|
+
if ([
|
|
2799
|
+
!entry2,
|
|
2800
|
+
entry2?.primitive !== "gaps",
|
|
2801
|
+
entry2?.dependencies.length,
|
|
2802
|
+
entry2?.conflictsWith.length,
|
|
2803
|
+
plan.requiredIds.includes(guidanceId),
|
|
2804
|
+
candidateIds.includes(guidanceId),
|
|
2805
|
+
plan.entries.some((row2) => row2.dependencies.includes(guidanceId))
|
|
2806
|
+
].some(Boolean)) {
|
|
2807
|
+
context3.addIssue({
|
|
2808
|
+
code: "custom",
|
|
2809
|
+
message: "Unresolved guidance must be an isolated gaps entry outside ready context"
|
|
2810
|
+
});
|
|
2811
|
+
}
|
|
2812
|
+
});
|
|
2813
|
+
var DraftContextSelectionInputSchema = z28.strictObject({
|
|
2814
|
+
artifact: DraftContextInputSchema.shape.artifact,
|
|
2815
|
+
decision: DraftContextInputSchema.shape.decision,
|
|
2816
|
+
plan: DraftContextSelectionPlanSchema,
|
|
2817
|
+
expectedPlanDigest: DraftContextInputSchema.shape.expectedPlanDigest,
|
|
2818
|
+
requestedSurface: identifier15
|
|
2819
|
+
});
|
|
2820
|
+
|
|
2821
|
+
// ../schemas/src/draft-origin-gates.ts
|
|
2822
|
+
import { z as z30 } from "zod";
|
|
2823
|
+
|
|
2824
|
+
// ../schemas/src/draft-normalized-context.ts
|
|
2825
|
+
import { z as z29 } from "zod";
|
|
2826
|
+
var request = DraftCompiledRequestSchema.shape;
|
|
2827
|
+
var context = DraftContextSelectionInputSchema.shape;
|
|
2828
|
+
var compilation = DraftCandidateCompilationVerificationSchema.shape;
|
|
2829
|
+
var draftNormalizedContextContract = "felspar.normalized-context-run/v1";
|
|
2830
|
+
var DraftNormalizedContextInputSchema = z29.strictObject({
|
|
2831
|
+
normalization: DraftNormalizedEvidenceSchema,
|
|
2832
|
+
compilation: z29.strictObject({
|
|
2833
|
+
artifact: compilation.artifact,
|
|
2834
|
+
binding: compilation.binding,
|
|
2835
|
+
fixtures: compilation.fixtures
|
|
2836
|
+
}),
|
|
2837
|
+
request: z29.strictObject({
|
|
2838
|
+
expectedArtifactDigest: request.expectedArtifactDigest,
|
|
2839
|
+
job: request.job,
|
|
2840
|
+
trustDomain: request.trustDomain,
|
|
2841
|
+
scope: request.scope
|
|
2842
|
+
}),
|
|
2843
|
+
plan: context.plan,
|
|
2844
|
+
expectedPlanDigest: context.expectedPlanDigest,
|
|
2845
|
+
requestedSurface: context.requestedSurface
|
|
2846
|
+
});
|
|
2847
|
+
var digest11 = context.expectedPlanDigest;
|
|
2848
|
+
var DraftNormalizedContextReceiptBodySchema = z29.strictObject({
|
|
2849
|
+
schema: z29.literal("felspar.normalized-context-receipt.draft/v0"),
|
|
2850
|
+
authority: z29.literal("unapproved"),
|
|
2851
|
+
runtimeContract: z29.literal(draftNormalizedContextContract),
|
|
2852
|
+
inputDigest: digest11,
|
|
2853
|
+
resultDigest: digest11,
|
|
2854
|
+
artifactDigest: digest11,
|
|
2855
|
+
normalizationDigest: digest11,
|
|
2856
|
+
decisionRunDigest: digest11.nullable(),
|
|
2857
|
+
selectionPlanDigest: digest11,
|
|
2858
|
+
capsuleDigest: digest11.nullable(),
|
|
2859
|
+
status: z29.enum(["ready", "blocked"])
|
|
2860
|
+
});
|
|
2861
|
+
var DraftNormalizedContextReceiptSchema = DraftNormalizedContextReceiptBodySchema.extend({
|
|
2862
|
+
receiptDigest: digest11
|
|
2863
|
+
}).refine((receipt) => receipt.status === "ready" === (receipt.capsuleDigest !== null), "Only ready delivery may have a capsule digest");
|
|
2864
|
+
|
|
2865
|
+
// ../schemas/src/draft-origin-gates.ts
|
|
2866
|
+
var DraftOriginBoundCompilationSchema = DraftSourceBoundCompilationSchema.extend({
|
|
2867
|
+
origins: DraftCandidateOriginsSchema
|
|
2868
|
+
});
|
|
2869
|
+
var DraftContextOriginsSchema = z30.strictObject({
|
|
2870
|
+
schema: z30.literal("felspar.context-origins.draft/v0"),
|
|
2871
|
+
planDigest: DraftContextSelectionPlanSchema.shape.artifactDigest,
|
|
2872
|
+
entries: z30.array(z30.strictObject({
|
|
2873
|
+
entryId: DraftContextSelectionPlanSchema.shape.job,
|
|
2874
|
+
origin: DraftAuthorityOriginSchema
|
|
2875
|
+
})).max(64)
|
|
2876
|
+
});
|
|
2877
|
+
var DraftContextOriginInputSchema = z30.strictObject({
|
|
2878
|
+
plan: DraftContextSelectionPlanSchema,
|
|
2879
|
+
origins: DraftContextOriginsSchema,
|
|
2880
|
+
bundle: DraftSourceTextBundleSchema,
|
|
2881
|
+
compositions: DraftSourceCompositionsSchema
|
|
2882
|
+
});
|
|
2883
|
+
var DraftOriginBoundContextInputSchema = z30.strictObject({
|
|
2884
|
+
schema: z30.literal("felspar.origin-bound-context.draft/v0"),
|
|
2885
|
+
input: DraftNormalizedContextInputSchema,
|
|
2886
|
+
origins: DraftCandidateOriginsSchema,
|
|
2887
|
+
context: z30.strictObject({
|
|
2888
|
+
origins: DraftContextOriginsSchema,
|
|
2889
|
+
bundle: DraftSourceTextBundleSchema
|
|
2890
|
+
})
|
|
2891
|
+
});
|
|
2892
|
+
|
|
2893
|
+
// ../schemas/src/draft-required-context.ts
|
|
2894
|
+
var context2 = DraftContextSelectionInputSchema.shape;
|
|
2895
|
+
var draftRequiredContextContract = "felspar.required-context-run/v1";
|
|
2896
|
+
var DraftRequiredContextInputSchema = z31.strictObject({
|
|
2897
|
+
normalization: DraftRequiredNormalizationSchema,
|
|
2898
|
+
compilation: z31.strictObject({
|
|
2899
|
+
artifact: DraftCompiledArtifactSchema,
|
|
2900
|
+
fixtures: DraftAnyCompilationSchema.shape.fixtures
|
|
2901
|
+
}),
|
|
2902
|
+
request: DraftCompiledRequestSchema.omit({ schema: true, evidence: true }),
|
|
2903
|
+
plan: context2.plan,
|
|
2904
|
+
expectedPlanDigest: context2.expectedPlanDigest,
|
|
2905
|
+
requestedSurface: context2.requestedSurface,
|
|
2906
|
+
contextOrigins: DraftContextOriginInputSchema.omit({ plan: true })
|
|
2907
|
+
});
|
|
2908
|
+
var DraftRequiredContextReceiptBodySchema = DraftNormalizedContextReceiptBodySchema.extend({
|
|
2909
|
+
schema: z31.literal("felspar.required-context-receipt.draft/v0"),
|
|
2910
|
+
runtimeContract: z31.literal(draftRequiredContextContract),
|
|
2911
|
+
compilationDigest: context2.expectedPlanDigest,
|
|
2912
|
+
contextOriginsDigest: context2.expectedPlanDigest
|
|
2913
|
+
});
|
|
2914
|
+
var DraftRequiredContextReceiptSchema = DraftRequiredContextReceiptBodySchema.extend({
|
|
2915
|
+
receiptDigest: context2.expectedPlanDigest
|
|
2916
|
+
}).refine((receipt) => receipt.status === "ready" === (receipt.capsuleDigest !== null), "Only ready delivery may have a capsule digest");
|
|
2917
|
+
|
|
2918
|
+
// ../schemas/src/draft-required-origins.ts
|
|
2919
|
+
var normalization = DraftRequiredNormalizationSchema.shape;
|
|
2920
|
+
var packet = DraftNormalizedEvidenceSchema.shape;
|
|
2921
|
+
var digest12 = packet.expectedSemanticBundleDigest;
|
|
2922
|
+
var path2 = z32.string().max(512).regex(/^\/authority\//u);
|
|
2923
|
+
var DraftRequiredAuthoritySchema = z32.strictObject({
|
|
2924
|
+
proposal: normalization.proposal,
|
|
2925
|
+
normalizationContract: z32.literal(conditionalNormalizationContract).optional(),
|
|
2926
|
+
bindings: normalization.bindings,
|
|
2927
|
+
materials: z32.array(z32.strictObject({
|
|
2928
|
+
key: normalization.bindings.element.shape.key,
|
|
2929
|
+
semantics: packet.semantics,
|
|
2930
|
+
evaluatorContract: packet.evaluatorContract
|
|
2931
|
+
})).min(1).max(16)
|
|
2932
|
+
}).superRefine((catalog, context3) => {
|
|
2933
|
+
if (isLayeredResolutionPolicy(catalog.proposal.resolutionPolicy)) {
|
|
2934
|
+
context3.addIssue({
|
|
2935
|
+
code: "custom",
|
|
2936
|
+
message: "The v4/v5 policies require the supplied route; dependency-layer normalization is unsupported"
|
|
2937
|
+
});
|
|
2938
|
+
return;
|
|
2939
|
+
}
|
|
2940
|
+
const isConditional = catalog.proposal.resolutionPolicy === conditionalResolutionPolicy;
|
|
2941
|
+
if (isConditional !== (catalog.normalizationContract !== void 0)) {
|
|
2942
|
+
context3.addIssue({
|
|
2943
|
+
code: "custom",
|
|
2944
|
+
message: "Conditional policy requires the supplied route or an explicit normalization contract"
|
|
2945
|
+
});
|
|
2946
|
+
}
|
|
2947
|
+
if (isConditional && catalog.proposal.requirements.some((item) => !("allowedValues" in item.definition))) {
|
|
2948
|
+
context3.addIssue({
|
|
2949
|
+
code: "custom",
|
|
2950
|
+
message: "Conditional normalization supports enum definitions only"
|
|
2951
|
+
});
|
|
2952
|
+
}
|
|
2953
|
+
});
|
|
2954
|
+
var DraftRequiredOriginsSchema = z32.strictObject({
|
|
2955
|
+
schema: z32.literal("felspar.required-origins.draft/v0"),
|
|
2956
|
+
authorityDigest: digest12,
|
|
2957
|
+
entries: z32.array(z32.strictObject({ path: path2, origin: DraftAuthorityOriginSchema })).max(1024)
|
|
2958
|
+
});
|
|
2959
|
+
var DraftRequiredOriginInputSchema = z32.strictObject({
|
|
2960
|
+
catalog: DraftRequiredAuthoritySchema,
|
|
2961
|
+
origins: DraftRequiredOriginsSchema,
|
|
2962
|
+
expectedAuthorityDigest: digest12,
|
|
2963
|
+
expectedOriginsDigest: digest12,
|
|
2964
|
+
bundle: DraftSourceTextBundleSchema,
|
|
2965
|
+
compositions: DraftSourceCompositionsSchema
|
|
2966
|
+
});
|
|
2967
|
+
var DraftCoveredRequiredContextSchema = z32.strictObject({
|
|
2968
|
+
authority: DraftRequiredOriginInputSchema,
|
|
2969
|
+
input: DraftRequiredContextInputSchema
|
|
2970
|
+
});
|
|
2971
|
+
var DraftCoveredRequiredReceiptBodySchema = z32.strictObject({
|
|
2972
|
+
schema: z32.literal("felspar.covered-required-receipt.draft/v0"),
|
|
2973
|
+
authority: z32.literal("unapproved"),
|
|
2974
|
+
inputDigest: digest12,
|
|
2975
|
+
resultDigest: digest12,
|
|
2976
|
+
authorityDigest: digest12,
|
|
2977
|
+
originsDigest: digest12,
|
|
2978
|
+
capsuleDigest: digest12.nullable(),
|
|
2979
|
+
status: z32.enum(["ready", "blocked"])
|
|
2980
|
+
});
|
|
2981
|
+
var DraftCoveredRequiredReceiptSchema = DraftCoveredRequiredReceiptBodySchema.extend({
|
|
2982
|
+
receiptDigest: digest12
|
|
2983
|
+
}).refine((receipt) => receipt.status === "ready" === (receipt.capsuleDigest !== null), "Only ready delivery has a capsule digest");
|
|
2984
|
+
var DraftRequiredPreparationSchema = DraftRequiredContextInputSchema.omit({
|
|
2985
|
+
normalization: true,
|
|
2986
|
+
request: true
|
|
2987
|
+
}).extend({
|
|
2988
|
+
authority: DraftRequiredOriginInputSchema,
|
|
2989
|
+
expectedArtifactDigest: digest12
|
|
2990
|
+
});
|
|
2991
|
+
var DraftPreparedRequiredReadSchema = z32.strictObject({
|
|
2992
|
+
request: DraftRequiredContextInputSchema.shape.request,
|
|
2993
|
+
normalizations: normalization.normalizations
|
|
2994
|
+
});
|
|
2995
|
+
|
|
2996
|
+
// ../schemas/src/draft-supplied-context.ts
|
|
2997
|
+
import { z as z33 } from "zod";
|
|
2998
|
+
var draftSuppliedContextContract = "felspar.supplied-context-run/v1";
|
|
2999
|
+
var draftSuppliedContextPartsContract = "felspar.supplied-context-run/v2";
|
|
3000
|
+
var DraftSuppliedAuthoritySchema = z33.strictObject({
|
|
3001
|
+
proposal: DraftRequiredProposalSchema,
|
|
3002
|
+
route: z33.strictObject({
|
|
3003
|
+
kind: z33.literal("supplied_values"),
|
|
3004
|
+
contract: z33.literal("felspar.declared-scalar-observations/v1")
|
|
3005
|
+
})
|
|
3006
|
+
});
|
|
3007
|
+
var DraftSuppliedOriginInputSchema = DraftRequiredOriginInputSchema.extend({
|
|
3008
|
+
catalog: DraftSuppliedAuthoritySchema
|
|
3009
|
+
});
|
|
3010
|
+
var DraftSuppliedContextSchema = DraftRequiredContextInputSchema.omit({
|
|
3011
|
+
normalization: true
|
|
3012
|
+
}).extend({
|
|
3013
|
+
schema: z33.literal("felspar.supplied-context.draft/v0"),
|
|
3014
|
+
authority: DraftSuppliedOriginInputSchema,
|
|
3015
|
+
evidence: DraftRequiredDecisionSchema.shape.evidence
|
|
3016
|
+
});
|
|
3017
|
+
var DraftSuppliedPreparationSchema = DraftSuppliedContextSchema.omit({
|
|
3018
|
+
request: true,
|
|
3019
|
+
evidence: true
|
|
3020
|
+
}).extend({
|
|
3021
|
+
schema: z33.literal("felspar.supplied-preparation.draft/v0"),
|
|
3022
|
+
expectedArtifactDigest: DraftSuppliedContextSchema.shape.request.shape.expectedArtifactDigest
|
|
3023
|
+
});
|
|
3024
|
+
var DraftPreparedSuppliedRequestSchema = DraftSuppliedContextSchema.pick({
|
|
3025
|
+
request: true,
|
|
3026
|
+
evidence: true
|
|
3027
|
+
});
|
|
3028
|
+
var DraftSuppliedReceiptBodySchema = DraftCoveredRequiredReceiptBodySchema.extend({
|
|
3029
|
+
schema: z33.literal("felspar.supplied-context-receipt.draft/v0"),
|
|
3030
|
+
runtimeContract: z33.enum([draftSuppliedContextContract, draftSuppliedContextPartsContract])
|
|
3031
|
+
});
|
|
3032
|
+
var DraftSuppliedReceiptSchema = DraftSuppliedReceiptBodySchema.extend({
|
|
3033
|
+
receiptDigest: DraftCoveredRequiredReceiptBodySchema.shape.inputDigest
|
|
3034
|
+
}).refine((receipt) => receipt.status === "ready" === (receipt.capsuleDigest !== null), "Only ready delivery has a capsule digest");
|
|
3035
|
+
|
|
3036
|
+
// ../schemas/src/draft-requirements.ts
|
|
3037
|
+
var request2 = z34.strictObject({
|
|
3038
|
+
schema: z34.literal("felspar.requirements-request.draft/v0"),
|
|
3039
|
+
job: DraftRequiredProposalSchema.shape.job,
|
|
3040
|
+
trustDomain: DraftRequiredProposalSchema.shape.trustDomain,
|
|
3041
|
+
maxResponseBytes: z34.number().int().min(1).max(1048576)
|
|
3042
|
+
});
|
|
3043
|
+
var DraftRequirementsRequestSchema = z34.discriminatedUnion("route", [
|
|
3044
|
+
request2.extend({
|
|
3045
|
+
route: z34.literal("normalized"),
|
|
3046
|
+
authority: DraftRequiredOriginInputSchema
|
|
3047
|
+
}),
|
|
3048
|
+
request2.extend({
|
|
3049
|
+
route: z34.literal("supplied"),
|
|
3050
|
+
authority: DraftSuppliedOriginInputSchema
|
|
3051
|
+
})
|
|
3052
|
+
]);
|
|
3053
|
+
|
|
3054
|
+
// ../schemas/src/draft-typed-normalization.ts
|
|
3055
|
+
import { z as z37 } from "zod";
|
|
3056
|
+
|
|
3057
|
+
// ../schemas/src/draft-exact-reader.ts
|
|
3058
|
+
import { z as z35 } from "zod";
|
|
3059
|
+
var exactNumberReaderVersion = "felspar.exact-number/v2";
|
|
3060
|
+
var exactDateReaderVersion = "felspar.exact-date/v2";
|
|
3061
|
+
var numberStyles = ["1,234.56", "1.234,56", "1 234,56", "1'234.56"];
|
|
3062
|
+
var dateOrders = ["unstated", "month-first", "day-first"];
|
|
3063
|
+
var knownCurrencies = [
|
|
3064
|
+
"AED",
|
|
3065
|
+
"ARS",
|
|
3066
|
+
"AUD",
|
|
3067
|
+
"BRL",
|
|
3068
|
+
"CAD",
|
|
3069
|
+
"CHF",
|
|
3070
|
+
"CLP",
|
|
3071
|
+
"CNY",
|
|
3072
|
+
"COP",
|
|
3073
|
+
"CZK",
|
|
3074
|
+
"DKK",
|
|
3075
|
+
"EGP",
|
|
3076
|
+
"EUR",
|
|
3077
|
+
"GBP",
|
|
3078
|
+
"HKD",
|
|
3079
|
+
"HUF",
|
|
3080
|
+
"IDR",
|
|
3081
|
+
"ILS",
|
|
3082
|
+
"INR",
|
|
3083
|
+
"ISK",
|
|
3084
|
+
"JPY",
|
|
3085
|
+
"KES",
|
|
3086
|
+
"KRW",
|
|
3087
|
+
"MXN",
|
|
3088
|
+
"MYR",
|
|
3089
|
+
"NGN",
|
|
3090
|
+
"NOK",
|
|
3091
|
+
"NZD",
|
|
3092
|
+
"PEN",
|
|
3093
|
+
"PHP",
|
|
3094
|
+
"PKR",
|
|
3095
|
+
"PLN",
|
|
3096
|
+
"RON",
|
|
3097
|
+
"RUB",
|
|
3098
|
+
"SAR",
|
|
3099
|
+
"SEK",
|
|
3100
|
+
"SGD",
|
|
3101
|
+
"THB",
|
|
3102
|
+
"TRY",
|
|
3103
|
+
"TWD",
|
|
3104
|
+
"UAH",
|
|
3105
|
+
"USD",
|
|
3106
|
+
"VND",
|
|
3107
|
+
"ZAR"
|
|
3108
|
+
];
|
|
3109
|
+
var knownCurrencySet = new Set(knownCurrencies);
|
|
3110
|
+
function isKnownCurrency(code) {
|
|
3111
|
+
return knownCurrencySet.has(code);
|
|
3112
|
+
}
|
|
3113
|
+
var UnitWordSchema = z35.string().min(1).max(64).regex(/^\p{L}[\p{L}\p{N}'’ -]*\p{L}$|^\p{L}$/u, "Use a word or short phrase");
|
|
3114
|
+
var ExactNumberUnitSchema = z35.discriminatedUnion("kind", [
|
|
3115
|
+
z35.strictObject({
|
|
3116
|
+
kind: z35.literal("currency"),
|
|
3117
|
+
code: z35.string().regex(/^[A-Z]{3}$/u).refine(isKnownCurrency, "Not a currency code the reader recognises")
|
|
3118
|
+
}),
|
|
3119
|
+
z35.strictObject({ kind: z35.literal("percent") }),
|
|
3120
|
+
z35.strictObject({
|
|
3121
|
+
kind: z35.literal("count"),
|
|
3122
|
+
words: z35.array(UnitWordSchema).min(1).max(16).refine((words) => hasUniqueValues(words.map((word) => word.toLowerCase())), "Duplicate unit word")
|
|
3123
|
+
})
|
|
3124
|
+
]);
|
|
3125
|
+
var ExactReaderSchema = z35.discriminatedUnion("version", [
|
|
3126
|
+
z35.strictObject({
|
|
3127
|
+
version: z35.literal(exactNumberReaderVersion),
|
|
3128
|
+
unit: ExactNumberUnitSchema,
|
|
3129
|
+
numberStyle: z35.enum(numberStyles)
|
|
3130
|
+
}),
|
|
3131
|
+
z35.strictObject({
|
|
3132
|
+
version: z35.literal(exactDateReaderVersion),
|
|
3133
|
+
dateOrder: z35.enum(dateOrders)
|
|
3134
|
+
})
|
|
3135
|
+
]);
|
|
3136
|
+
|
|
3137
|
+
// ../schemas/src/draft-scalar-selection.ts
|
|
3138
|
+
import { z as z36 } from "zod";
|
|
3139
|
+
var scalarSelectionConfidence = "candidate-selected-probability/v1";
|
|
3140
|
+
var DraftScalarParserSchema = z36.discriminatedUnion("version", [
|
|
3141
|
+
z36.strictObject({
|
|
3142
|
+
version: z36.literal("iso-currency-decimal/v1"),
|
|
3143
|
+
currency: z36.string().regex(/^[A-Z]{3}$/u)
|
|
3144
|
+
}),
|
|
3145
|
+
z36.strictObject({ version: z36.literal("iso-calendar-date/v1") })
|
|
3146
|
+
]);
|
|
3147
|
+
var digest13 = z36.string().regex(/^sha256:[a-f0-9]{64}$/u);
|
|
3148
|
+
var candidateId = z36.string().regex(/^candidate_(?:\d|[1-5]\d|6[0-3])$/u);
|
|
3149
|
+
var DraftScalarSelectionSchema = z36.strictObject({
|
|
3150
|
+
schema: z36.literal("felspar.scalar-candidate-selection.draft/v0"),
|
|
3151
|
+
requestDigest: digest13,
|
|
3152
|
+
parser: DraftScalarParserSchema,
|
|
3153
|
+
sourceText: z36.string().min(1).max(262144),
|
|
3154
|
+
candidatesDigest: digest13,
|
|
3155
|
+
selectedCandidateId: candidateId.nullable(),
|
|
3156
|
+
probabilities: z36.array(z36.strictObject({ value: candidateId, probability: z36.number().min(0).max(1) })).min(1).max(64),
|
|
3157
|
+
abstentionProbability: z36.number().min(0).max(1),
|
|
3158
|
+
providerConfidence: z36.number().min(0).max(1)
|
|
3159
|
+
});
|
|
3160
|
+
|
|
3161
|
+
// ../schemas/src/draft-typed-normalization.ts
|
|
3162
|
+
var identifier16 = z37.string().min(1).max(200).regex(/\S/u);
|
|
3163
|
+
var digest14 = DraftNormalizedEvidenceSchema.shape.expectedSemanticBundleDigest;
|
|
3164
|
+
var { evaluator: evaluator2 } = DraftNormalizedEvidenceSchema.shape.evaluatorContract.shape;
|
|
3165
|
+
var reference7 = DraftEvidenceValidationSchema.shape.observationChecks.shape.scope.shape.observations.element.shape.evidence;
|
|
3166
|
+
var key2 = { key: identifier16 };
|
|
3167
|
+
var scalarRecipe = z37.strictObject({
|
|
3168
|
+
...key2,
|
|
3169
|
+
kind: z37.literal("scalar"),
|
|
3170
|
+
definitionDigest: digest14,
|
|
3171
|
+
id: identifier16,
|
|
3172
|
+
version: identifier16,
|
|
3173
|
+
instructions: z37.string().min(1).max(16384).regex(/\S/u),
|
|
3174
|
+
evaluator: evaluator2,
|
|
3175
|
+
calibration: DraftNormalizedEvidenceSchema.shape.evaluatorContract.shape.calibration,
|
|
3176
|
+
confidenceContract: z37.enum(["declared-scalar-confidence/v1", scalarSelectionConfidence]),
|
|
3177
|
+
parser: DraftScalarParserSchema.optional(),
|
|
3178
|
+
minimumConfidence: z37.number().gt(0).max(1),
|
|
3179
|
+
reader: ExactReaderSchema.optional()
|
|
3180
|
+
}).refine((recipe2) => recipe2.confidenceContract === scalarSelectionConfidence === Boolean(recipe2.parser), "A candidate-selection recipe requires its parser; legacy recipes cannot carry a parser");
|
|
3181
|
+
var DraftInterpretationManifestSchema = z37.strictObject({
|
|
3182
|
+
schema: z37.literal("felspar.typed-interpretation-manifest.draft/v0"),
|
|
3183
|
+
authority: z37.literal("unapproved"),
|
|
3184
|
+
authorityDigest: digest14,
|
|
3185
|
+
recipes: z37.array(z37.discriminatedUnion("kind", [
|
|
3186
|
+
scalarRecipe,
|
|
3187
|
+
z37.strictObject({
|
|
3188
|
+
...key2,
|
|
3189
|
+
kind: z37.literal("enum"),
|
|
3190
|
+
semanticBundleDigest: digest14,
|
|
3191
|
+
evaluatorContractDigest: digest14
|
|
3192
|
+
})
|
|
3193
|
+
])).min(1).max(64).refine((items) => hasUniqueValues(items.map((item) => item.key)), "Duplicate recipe key")
|
|
3194
|
+
});
|
|
3195
|
+
var judgment2 = z37.discriminatedUnion("status", [
|
|
3196
|
+
z37.strictObject({
|
|
3197
|
+
status: z37.literal("evaluated"),
|
|
3198
|
+
value: DraftEvidenceValueSchema,
|
|
3199
|
+
unit: identifier16.optional(),
|
|
3200
|
+
confidence: z37.number().min(0).max(1)
|
|
3201
|
+
}),
|
|
3202
|
+
z37.strictObject({ status: z37.enum(["abstained", "timeout", "malformed", "review_required"]) })
|
|
3203
|
+
]);
|
|
3204
|
+
var scalarPacket = z37.strictObject({
|
|
3205
|
+
...key2,
|
|
3206
|
+
kind: z37.literal("scalar"),
|
|
3207
|
+
evidence: z37.strictObject(DraftEvidenceValidationSchema.shape).omit({ results: true }),
|
|
3208
|
+
records: z37.array(z37.strictObject({
|
|
3209
|
+
observationId: identifier16,
|
|
3210
|
+
evidence: reference7,
|
|
3211
|
+
recipeDigest: digest14,
|
|
3212
|
+
evaluator: evaluator2,
|
|
3213
|
+
calibrationDigest: digest14,
|
|
3214
|
+
judgment: judgment2,
|
|
3215
|
+
selection: DraftScalarSelectionSchema.optional()
|
|
3216
|
+
})).max(64)
|
|
3217
|
+
});
|
|
3218
|
+
var DraftTypedNormalizationSchema = z37.strictObject({
|
|
3219
|
+
schema: z37.literal("felspar.typed-normalization.draft/v0"),
|
|
3220
|
+
invocation: DraftSuppliedContextSchema.omit({ evidence: true }),
|
|
3221
|
+
manifest: DraftInterpretationManifestSchema,
|
|
3222
|
+
expectedManifestDigest: digest14,
|
|
3223
|
+
packets: z37.array(z37.discriminatedUnion("kind", [
|
|
3224
|
+
scalarPacket,
|
|
3225
|
+
z37.strictObject({ ...key2, kind: z37.literal("enum"), input: DraftNormalizedEvidenceSchema })
|
|
3226
|
+
])).max(64).refine((items) => hasUniqueValues(items.map((item) => item.key)), "Duplicate packet key")
|
|
3227
|
+
});
|
|
3228
|
+
var DraftLayeredNormalizationSchema = DraftTypedNormalizationSchema.extend({
|
|
3229
|
+
schema: z37.literal("felspar.typed-normalization.draft/v1")
|
|
3230
|
+
});
|
|
3231
|
+
|
|
3232
|
+
// ../schemas/src/draft-context-receipt.ts
|
|
3233
|
+
import { z as z38 } from "zod";
|
|
3234
|
+
var digest15 = DraftContextSelectionInputSchema.shape.expectedPlanDigest;
|
|
3235
|
+
var { evaluationTime } = DraftContextSelectionInputSchema.shape.decision.shape.scope.shape;
|
|
3236
|
+
var draftContextRuntimeContract = "felspar.context-selection-run/v1";
|
|
3237
|
+
var DraftContextReceiptBodySchema = z38.strictObject({
|
|
3238
|
+
schema: z38.literal("felspar.context-receipt.draft/v0"),
|
|
3239
|
+
authority: z38.literal("unapproved"),
|
|
3240
|
+
stage: z38.literal("draft-context-selection"),
|
|
3241
|
+
runtimeContract: z38.literal(draftContextRuntimeContract),
|
|
3242
|
+
identityFormat: z38.literal("felspar.json-content-identity/v1"),
|
|
3243
|
+
evaluationTime,
|
|
3244
|
+
inputDigest: digest15,
|
|
3245
|
+
artifactDigest: digest15,
|
|
3246
|
+
selectionPlanDigest: digest15,
|
|
3247
|
+
decisionRunDigest: digest15,
|
|
3248
|
+
resultDigest: digest15,
|
|
3249
|
+
capsuleDigest: digest15.nullable(),
|
|
3250
|
+
status: z38.enum(["ready", "blocked"])
|
|
3251
|
+
});
|
|
3252
|
+
var DraftContextReceiptSchema = DraftContextReceiptBodySchema.extend({
|
|
3253
|
+
receiptDigest: digest15
|
|
3254
|
+
}).refine((receipt) => receipt.status === "ready" === (receipt.capsuleDigest !== null), "Only a ready context receipt has a capsule digest");
|
|
3255
|
+
var DraftContextVerificationOptionsSchema = z38.strictObject({
|
|
3256
|
+
expectedReceiptDigest: digest15,
|
|
3257
|
+
deliveredCapsule: z38.record(z38.string(), z38.unknown()).nullable()
|
|
3258
|
+
});
|
|
3259
|
+
|
|
3260
|
+
// ../schemas/src/draft-evaluation-requests.ts
|
|
3261
|
+
import { z as z39 } from "zod";
|
|
3262
|
+
var identifier17 = z39.string().min(1).max(200).regex(/\S/u);
|
|
3263
|
+
var digest16 = DraftTypedNormalizationSchema.shape.expectedManifestDigest;
|
|
3264
|
+
var [scalar2] = DraftTypedNormalizationSchema.shape.packets.element.options;
|
|
3265
|
+
var { reference: reference8 } = DraftEvidenceMetadataSchema.shape.sources.element.shape;
|
|
3266
|
+
var DraftEvaluationRequestsSchema = z39.strictObject({
|
|
3267
|
+
schema: z39.literal("felspar.evaluation-requests.draft/v0"),
|
|
3268
|
+
invocation: DraftTypedNormalizationSchema.shape.invocation,
|
|
3269
|
+
manifest: DraftTypedNormalizationSchema.shape.manifest,
|
|
3270
|
+
expectedManifestDigest: digest16,
|
|
3271
|
+
limits: z39.strictObject({
|
|
3272
|
+
maxQuestions: z39.number().int().min(1).max(64),
|
|
3273
|
+
maxRequestBytes: z39.number().int().min(1).max(1048576),
|
|
3274
|
+
maxResponseBytes: z39.number().int().min(1).max(1048576)
|
|
3275
|
+
}),
|
|
3276
|
+
packets: z39.array(z39.discriminatedUnion("kind", [
|
|
3277
|
+
z39.strictObject({
|
|
3278
|
+
key: identifier17,
|
|
3279
|
+
kind: z39.literal("scalar"),
|
|
3280
|
+
evidence: DraftEvidenceMetadataSchema
|
|
3281
|
+
}),
|
|
3282
|
+
z39.strictObject({
|
|
3283
|
+
key: identifier17,
|
|
3284
|
+
kind: z39.literal("enum"),
|
|
3285
|
+
input: DraftNormalizedEvidenceSchema.omit({ normalizations: true, attemptStatus: true })
|
|
3286
|
+
})
|
|
3287
|
+
])).max(64).refine((items) => hasUniqueValues(items.map((item) => item.key)), "Duplicate preparation key"),
|
|
3288
|
+
passages: z39.array(z39.strictObject({ reference: reference8, text: z39.string().min(1).max(262144) })).max(1024)
|
|
3289
|
+
});
|
|
3290
|
+
var DraftEvaluationResponseSchema = z39.strictObject({
|
|
3291
|
+
schema: z39.literal("felspar.evaluation-response.draft/v0"),
|
|
3292
|
+
requestDigest: digest16,
|
|
3293
|
+
answers: z39.array(z39.discriminatedUnion("kind", [
|
|
3294
|
+
z39.strictObject({
|
|
3295
|
+
key: identifier17,
|
|
3296
|
+
kind: z39.literal("scalar"),
|
|
3297
|
+
records: scalar2.shape.records
|
|
3298
|
+
}),
|
|
3299
|
+
z39.strictObject({
|
|
3300
|
+
key: identifier17,
|
|
3301
|
+
kind: z39.literal("enum"),
|
|
3302
|
+
records: DraftNormalizedEvidenceSchema.shape.normalizations
|
|
3303
|
+
})
|
|
3304
|
+
])).max(16).refine((items) => hasUniqueValues(items.map((item) => item.key)), "Duplicate answer key")
|
|
3305
|
+
});
|
|
3306
|
+
var DraftEvaluationResponsesSchema = z39.array(DraftEvaluationResponseSchema).max(2);
|
|
3307
|
+
var DraftLayeredEvaluationSchema = DraftEvaluationRequestsSchema.extend({
|
|
3308
|
+
schema: z39.literal("felspar.evaluation-requests.draft/v1"),
|
|
3309
|
+
limits: DraftEvaluationRequestsSchema.shape.limits.extend({
|
|
3310
|
+
maxRounds: z39.number().int().min(1).max(16),
|
|
3311
|
+
maxTotalQuestions: z39.number().int().min(1).max(64),
|
|
3312
|
+
maxTotalRequestBytes: z39.number().int().min(1).max(1048576),
|
|
3313
|
+
maxTotalResponseBytes: z39.number().int().min(1).max(1048576)
|
|
3314
|
+
})
|
|
3315
|
+
});
|
|
3316
|
+
var DraftLayeredResponsesSchema = z39.array(DraftEvaluationResponseSchema).max(16);
|
|
3317
|
+
|
|
3318
|
+
// ../schemas/src/draft-job-handoff.ts
|
|
3319
|
+
var digest17 = DraftContextVerificationOptionsSchema.shape.expectedReceiptDigest;
|
|
3320
|
+
var draftJobHandoffContract = "felspar.job-handoff/v1";
|
|
3321
|
+
var DraftJobDiscoverySchema = z40.strictObject({
|
|
3322
|
+
schema: z40.literal("felspar.job-discovery.draft/v0"),
|
|
3323
|
+
requirements: DraftRequirementsRequestSchema,
|
|
3324
|
+
compilation: DraftRequiredContextInputSchema.shape.compilation,
|
|
3325
|
+
expectedArtifactDigest: digest17
|
|
3326
|
+
});
|
|
3327
|
+
var executionVersion0 = "felspar.job-execution.draft/v0";
|
|
3328
|
+
var DraftJobExecutionSchema = z40.strictObject({
|
|
3329
|
+
schema: z40.literal(executionVersion0),
|
|
3330
|
+
discovery: DraftJobDiscoverySchema,
|
|
3331
|
+
expectedHandoffDigest: digest17,
|
|
3332
|
+
invocation: z40.discriminatedUnion("route", [
|
|
3333
|
+
z40.strictObject({ route: z40.literal("normalized"), input: DraftCoveredRequiredContextSchema }),
|
|
3334
|
+
z40.strictObject({ route: z40.literal("supplied"), input: DraftSuppliedContextSchema }),
|
|
3335
|
+
z40.strictObject({ route: z40.literal("typed"), input: DraftTypedNormalizationSchema }),
|
|
3336
|
+
z40.strictObject({ route: z40.literal("layered"), input: DraftLayeredNormalizationSchema }),
|
|
3337
|
+
z40.strictObject({
|
|
3338
|
+
route: z40.literal("evaluated"),
|
|
3339
|
+
input: DraftLayeredEvaluationSchema,
|
|
3340
|
+
responses: DraftLayeredResponsesSchema
|
|
3341
|
+
})
|
|
3342
|
+
])
|
|
3343
|
+
});
|
|
3344
|
+
var DraftJobDiscoveryReferenceSchema = z40.strictObject({
|
|
3345
|
+
schema: z40.literal("felspar.job-discovery-reference.draft/v1"),
|
|
3346
|
+
route: z40.enum(["normalized", "supplied"]),
|
|
3347
|
+
job: DraftRequirementsRequestSchema.options[0].shape.job,
|
|
3348
|
+
trustDomain: DraftRequirementsRequestSchema.options[0].shape.trustDomain,
|
|
3349
|
+
maxResponseBytes: DraftRequirementsRequestSchema.options[0].shape.maxResponseBytes,
|
|
3350
|
+
expectedArtifactDigest: digest17
|
|
3351
|
+
});
|
|
3352
|
+
var DraftJobExecutionV1Schema = z40.strictObject({
|
|
3353
|
+
schema: z40.literal("felspar.job-execution.draft/v1"),
|
|
3354
|
+
discovery: DraftJobDiscoveryReferenceSchema,
|
|
3355
|
+
expectedHandoffDigest: digest17,
|
|
3356
|
+
invocation: DraftJobExecutionSchema.shape.invocation
|
|
3357
|
+
});
|
|
3358
|
+
var DraftAnyJobExecutionSchema = z40.discriminatedUnion("schema", [
|
|
3359
|
+
DraftJobExecutionSchema,
|
|
3360
|
+
DraftJobExecutionV1Schema
|
|
3361
|
+
]);
|
|
3362
|
+
var DraftJobReceiptBodySchema = z40.strictObject({
|
|
3363
|
+
schema: z40.literal("felspar.job-handoff-receipt.draft/v0"),
|
|
3364
|
+
authority: z40.literal("unapproved"),
|
|
3365
|
+
runtimeContract: z40.literal(draftJobHandoffContract),
|
|
3366
|
+
route: z40.enum(["normalized", "supplied", "typed", "layered", "evaluated"]),
|
|
3367
|
+
inputDigest: digest17,
|
|
3368
|
+
handoffDigest: digest17,
|
|
3369
|
+
artifactDigest: digest17,
|
|
3370
|
+
downstreamRunDigest: digest17,
|
|
3371
|
+
capsuleDigest: digest17.nullable(),
|
|
3372
|
+
status: z40.enum(["ready", "blocked"])
|
|
3373
|
+
});
|
|
3374
|
+
var DraftJobReceiptSchema = DraftJobReceiptBodySchema.extend({
|
|
3375
|
+
receiptDigest: digest17
|
|
3376
|
+
}).refine((receipt) => receipt.status === "ready" === (receipt.capsuleDigest !== null), "Only ready delivery has a capsule digest");
|
|
3377
|
+
var DraftJobVerificationSchema = z40.strictObject({
|
|
3378
|
+
receipt: DraftJobReceiptSchema,
|
|
3379
|
+
retained: DraftAnyJobExecutionSchema,
|
|
3380
|
+
options: DraftContextVerificationOptionsSchema
|
|
3381
|
+
});
|
|
3382
|
+
|
|
3383
|
+
// ../schemas/src/draft-application-access.ts
|
|
3384
|
+
var identifier18 = z41.string().min(1).max(200).regex(/^[a-zA-Z0-9][a-zA-Z0-9._:/@-]*$/u);
|
|
3385
|
+
var digest18 = DraftJobExecutionSchema.shape.expectedHandoffDigest;
|
|
3386
|
+
var instant = z41.iso.datetime({ offset: true });
|
|
3387
|
+
var applicationActions = [
|
|
3388
|
+
"submit_source",
|
|
3389
|
+
"submit_proposal",
|
|
3390
|
+
"approve_proposal",
|
|
3391
|
+
"release_pack",
|
|
3392
|
+
"execute_job",
|
|
3393
|
+
"inspect_run"
|
|
3394
|
+
];
|
|
3395
|
+
var action = z41.enum(applicationActions);
|
|
3396
|
+
var DraftApplicationScopeSchema = z41.strictObject({
|
|
3397
|
+
organizationId: identifier18,
|
|
3398
|
+
environmentId: identifier18,
|
|
3399
|
+
authorityId: identifier18
|
|
3400
|
+
});
|
|
3401
|
+
var DraftApplicationTargetSchema = DraftApplicationScopeSchema.extend({
|
|
3402
|
+
action,
|
|
3403
|
+
resourceId: identifier18,
|
|
3404
|
+
jobId: identifier18.nullable()
|
|
3405
|
+
}).refine((target) => target.action === "execute_job" === (target.jobId !== null), "Only job execution carries a job ID");
|
|
3406
|
+
var DraftApplicationActorSchema = z41.strictObject({
|
|
3407
|
+
principalId: identifier18,
|
|
3408
|
+
organizationId: identifier18,
|
|
3409
|
+
principalType: z41.enum(["user", "delegated_agent", "autonomous_agent"]),
|
|
3410
|
+
actingUserId: identifier18.nullable(),
|
|
3411
|
+
authenticatedAt: instant,
|
|
3412
|
+
expiresAt: instant,
|
|
3413
|
+
permissionCeiling: z41.array(action).max(applicationActions.length)
|
|
3414
|
+
}).refine((actor) => actor.principalType === "delegated_agent" === (actor.actingUserId !== null), "Delegated agents preserve the acting user");
|
|
3415
|
+
var DraftApplicationPermissionSchema = z41.strictObject({
|
|
3416
|
+
target: DraftApplicationTargetSchema,
|
|
3417
|
+
principalId: identifier18,
|
|
3418
|
+
actingUserId: identifier18.nullable(),
|
|
3419
|
+
allowed: z41.boolean(),
|
|
3420
|
+
checkedAt: instant,
|
|
3421
|
+
expiresAt: instant
|
|
3422
|
+
});
|
|
3423
|
+
var DraftApplicationJobMaterialSchema = z41.strictObject({
|
|
3424
|
+
discovery: DraftJobExecutionSchema.shape.discovery,
|
|
3425
|
+
expectedHandoffDigest: digest18,
|
|
3426
|
+
input: DraftLayeredEvaluationSchema
|
|
3427
|
+
});
|
|
3428
|
+
var DraftApplicationJobMaterialV2Schema = z41.strictObject({
|
|
3429
|
+
schema: z41.literal("felspar.application-job-material.draft/v2"),
|
|
3430
|
+
discovery: DraftJobDiscoveryReferenceSchema,
|
|
3431
|
+
expectedHandoffDigest: digest18,
|
|
3432
|
+
input: DraftLayeredEvaluationSchema
|
|
3433
|
+
});
|
|
3434
|
+
var DraftAnyApplicationJobMaterialSchema = z41.union([
|
|
3435
|
+
DraftApplicationJobMaterialV2Schema,
|
|
3436
|
+
DraftApplicationJobMaterialSchema
|
|
3437
|
+
]);
|
|
3438
|
+
var DraftApplicationJobRequestSchema = z41.strictObject({
|
|
3439
|
+
schema: z41.literal("felspar.application-job-request.draft/v0"),
|
|
3440
|
+
scope: DraftApplicationScopeSchema,
|
|
3441
|
+
releaseId: identifier18,
|
|
3442
|
+
expectedReleaseDigest: digest18,
|
|
3443
|
+
jobId: identifier18,
|
|
3444
|
+
executionId: identifier18,
|
|
3445
|
+
material: DraftAnyApplicationJobMaterialSchema
|
|
3446
|
+
});
|
|
3447
|
+
var DraftApplicationReleaseSchema = z41.strictObject({
|
|
3448
|
+
schema: z41.literal("felspar.application-release.draft/v0"),
|
|
3449
|
+
scope: DraftApplicationScopeSchema,
|
|
3450
|
+
releaseId: identifier18,
|
|
3451
|
+
jobId: identifier18,
|
|
3452
|
+
trustDomain: identifier18,
|
|
3453
|
+
materialDigest: digest18,
|
|
3454
|
+
approvalId: identifier18,
|
|
3455
|
+
approvedMaterialDigest: digest18,
|
|
3456
|
+
releaseDigest: digest18,
|
|
3457
|
+
status: z41.enum(["draft", "released", "revoked"])
|
|
3458
|
+
});
|
|
3459
|
+
|
|
3460
|
+
// ../schemas/src/draft-hosted-application.ts
|
|
3461
|
+
import { z as z48 } from "zod";
|
|
3462
|
+
|
|
3463
|
+
// ../schemas/src/draft-hosted-output-checks.ts
|
|
3464
|
+
import { z as z47 } from "zod";
|
|
3465
|
+
|
|
3466
|
+
// ../schemas/src/draft-artifact-check-manifest.ts
|
|
3467
|
+
import { z as z45 } from "zod";
|
|
3468
|
+
|
|
3469
|
+
// ../schemas/src/draft-artifact-lint-semantic.ts
|
|
3470
|
+
import { z as z44 } from "zod";
|
|
3471
|
+
|
|
3472
|
+
// ../schemas/src/draft-claim-evaluation-recipe.ts
|
|
3473
|
+
import { z as z43 } from "zod";
|
|
3474
|
+
|
|
3475
|
+
// ../schemas/src/draft-output-check.ts
|
|
3476
|
+
import { z as z42 } from "zod";
|
|
3477
|
+
var identifier19 = DraftContextPlanSchema.shape.job;
|
|
3478
|
+
var digest19 = DraftJobReceiptBodySchema.shape.inputDigest;
|
|
3479
|
+
var byteLimit = z42.number().int().min(1).max(65536);
|
|
3480
|
+
var text5 = z42.string().max(16384);
|
|
3481
|
+
var sectionRule = z42.discriminatedUnion("check", [
|
|
3482
|
+
z42.strictObject({ id: identifier19, check: z42.literal("text"), maxBytes: byteLimit }),
|
|
3483
|
+
z42.strictObject({
|
|
3484
|
+
id: identifier19,
|
|
3485
|
+
check: z42.literal("exact"),
|
|
3486
|
+
maxBytes: byteLimit,
|
|
3487
|
+
alternatives: z42.array(text5.min(1).regex(/\S/u)).min(1).max(8).refine(hasUniqueValues)
|
|
3488
|
+
})
|
|
3489
|
+
]);
|
|
3490
|
+
var draftOutputCheckerContract = "felspar.structured-output-check/v1";
|
|
3491
|
+
var DraftOutputContractSchema = z42.strictObject({
|
|
3492
|
+
schema: z42.literal("felspar.output-contract.draft/v0"),
|
|
3493
|
+
id: identifier19,
|
|
3494
|
+
version: z42.number().int().min(1).max(65535),
|
|
3495
|
+
compiledArtifactDigest: digest19,
|
|
3496
|
+
job: identifier19,
|
|
3497
|
+
trustDomain: identifier19,
|
|
3498
|
+
outputSurface: identifier19,
|
|
3499
|
+
maxBytes: byteLimit,
|
|
3500
|
+
sections: z42.array(sectionRule).min(1).max(16)
|
|
3501
|
+
}).superRefine((contract, context3) => {
|
|
3502
|
+
if (!hasUniqueValues(contract.sections.map((section) => section.id))) {
|
|
3503
|
+
context3.addIssue({ code: "custom", message: "Duplicate output section rule" });
|
|
3504
|
+
}
|
|
3505
|
+
const encoder2 = new TextEncoder();
|
|
3506
|
+
for (const section of contract.sections) {
|
|
3507
|
+
if (section.check === "exact" && section.alternatives.some((value) => encoder2.encode(value).byteLength > section.maxBytes)) {
|
|
3508
|
+
context3.addIssue({ code: "custom", message: "Exact alternative exceeds section budget" });
|
|
3509
|
+
}
|
|
3510
|
+
}
|
|
3511
|
+
});
|
|
3512
|
+
var DraftStructuredOutputSchema = z42.strictObject({
|
|
3513
|
+
schema: z42.literal("felspar.structured-output.draft/v0"),
|
|
3514
|
+
id: identifier19,
|
|
3515
|
+
revision: identifier19,
|
|
3516
|
+
sections: z42.array(z42.strictObject({ id: identifier19, text: text5 })).max(32).refine((sections) => hasUniqueValues(sections.map((section) => section.id)))
|
|
3517
|
+
});
|
|
3518
|
+
var DraftOutputCheckSchema = z42.strictObject({
|
|
3519
|
+
schema: z42.literal("felspar.output-check.draft/v0"),
|
|
3520
|
+
execution: DraftJobExecutionSchema,
|
|
3521
|
+
expectedJobReceiptDigest: digest19,
|
|
3522
|
+
contractEntryId: identifier19,
|
|
3523
|
+
expectedContractDigest: digest19,
|
|
3524
|
+
output: DraftStructuredOutputSchema,
|
|
3525
|
+
expectedOutputDigest: digest19
|
|
3526
|
+
});
|
|
3527
|
+
var DraftOutputDiagnosticSchema = z42.strictObject({
|
|
3528
|
+
code: z42.enum([
|
|
3529
|
+
"upstream_blocked",
|
|
3530
|
+
"contract_coverage_incomplete",
|
|
3531
|
+
"contract_invalid",
|
|
3532
|
+
"output_too_large",
|
|
3533
|
+
"section_missing",
|
|
3534
|
+
"section_unknown",
|
|
3535
|
+
"section_empty",
|
|
3536
|
+
"section_too_large",
|
|
3537
|
+
"section_text_mismatch"
|
|
3538
|
+
]),
|
|
3539
|
+
sectionId: identifier19.nullable()
|
|
3540
|
+
});
|
|
3541
|
+
var DraftOutputReceiptBodySchema = z42.strictObject({
|
|
3542
|
+
schema: z42.literal("felspar.output-receipt.draft/v0"),
|
|
3543
|
+
authority: z42.literal("unapproved"),
|
|
3544
|
+
checkerContract: z42.literal(draftOutputCheckerContract),
|
|
3545
|
+
coverage: z42.literal("declared_structure_and_exact_text"),
|
|
3546
|
+
semanticEvaluation: z42.literal("not_performed"),
|
|
3547
|
+
actionAuthorized: z42.literal(false),
|
|
3548
|
+
inputDigest: digest19,
|
|
3549
|
+
jobReceiptDigest: digest19,
|
|
3550
|
+
compiledArtifactDigest: digest19,
|
|
3551
|
+
capsuleDigest: digest19.nullable(),
|
|
3552
|
+
contractDigest: digest19.nullable(),
|
|
3553
|
+
outputDigest: digest19,
|
|
3554
|
+
outputId: identifier19,
|
|
3555
|
+
outputRevision: identifier19,
|
|
3556
|
+
status: z42.enum(["checks_passed", "invalid", "blocked"]),
|
|
3557
|
+
structuralOnlySectionIds: z42.array(identifier19).max(16),
|
|
3558
|
+
diagnostics: z42.array(DraftOutputDiagnosticSchema).max(81)
|
|
3559
|
+
});
|
|
3560
|
+
var DraftOutputReceiptSchema = DraftOutputReceiptBodySchema.extend({
|
|
3561
|
+
receiptDigest: digest19
|
|
3562
|
+
});
|
|
3563
|
+
var DraftOutputVerificationOptionsSchema = z42.strictObject({
|
|
3564
|
+
expectedReceiptDigest: digest19
|
|
3565
|
+
});
|
|
3566
|
+
|
|
3567
|
+
// ../schemas/src/draft-claim-evaluation-recipe.ts
|
|
3568
|
+
var scope = DraftOutputContractSchema.shape;
|
|
3569
|
+
var identifier20 = scope.id;
|
|
3570
|
+
var text6 = z43.string().min(1).max(2048).regex(/\S/u);
|
|
3571
|
+
var ids2 = z43.array(identifier20).max(8).refine(hasUniqueValues, "Duplicate identifier");
|
|
3572
|
+
var { judgment: judgment3 } = DraftNormalizedEvidenceSchema.shape.normalizations.element.shape;
|
|
3573
|
+
var option = z43.strictObject({
|
|
3574
|
+
value: judgment3.options[0].shape.probabilities.element.shape.value,
|
|
3575
|
+
meaning: text6,
|
|
3576
|
+
effect: z43.enum(["satisfied", "violated", "unresolved"])
|
|
3577
|
+
});
|
|
3578
|
+
var question = z43.strictObject({
|
|
3579
|
+
id: identifier20,
|
|
3580
|
+
sectionIds: ids2.min(1),
|
|
3581
|
+
instructions: text6,
|
|
3582
|
+
authorityEntryIds: ids2.min(1),
|
|
3583
|
+
evidenceKeys: ids2,
|
|
3584
|
+
options: z43.array(option).min(2).max(8).refine((items) => hasUniqueValues(items.map((item) => item.value)), "Duplicate option").refine((items) => items.some((item) => item.effect === "unresolved"), "Explicit unresolved option required"),
|
|
3585
|
+
minimumSelectedProbability: z43.number().gt(0).max(1)
|
|
3586
|
+
});
|
|
3587
|
+
var DraftClaimEvaluationRecipeSchema = z43.strictObject({
|
|
3588
|
+
schema: z43.literal("felspar.claim-evaluation-recipe.draft/v0"),
|
|
3589
|
+
id: identifier20,
|
|
3590
|
+
version: identifier20,
|
|
3591
|
+
compiledArtifactDigest: scope.compiledArtifactDigest,
|
|
3592
|
+
job: scope.job,
|
|
3593
|
+
trustDomain: scope.trustDomain,
|
|
3594
|
+
outputSurface: scope.outputSurface,
|
|
3595
|
+
evaluator: DraftEvaluatorContractSchema.shape.evaluator,
|
|
3596
|
+
calibration: DraftEvaluatorContractSchema.shape.calibration,
|
|
3597
|
+
probabilityContract: DraftEvaluatorContractSchema.shape.probabilityContract,
|
|
3598
|
+
questions: z43.array(question).min(1).max(8).refine((items) => hasUniqueValues(items.map((item) => item.id)), "Duplicate question"),
|
|
3599
|
+
limits: z43.strictObject({
|
|
3600
|
+
maxRequests: z43.number().int().min(1).max(128),
|
|
3601
|
+
maxRequestBytes: z43.number().int().min(1).max(16384),
|
|
3602
|
+
maxTotalBytes: z43.number().int().min(1).max(65536)
|
|
3603
|
+
})
|
|
3604
|
+
});
|
|
3605
|
+
|
|
3606
|
+
// ../schemas/src/draft-artifact-lint-semantic.ts
|
|
3607
|
+
var id2 = DraftApplicationScopeSchema.shape.authorityId;
|
|
3608
|
+
var digest20 = DraftJobReceiptSchema.shape.receiptDigest;
|
|
3609
|
+
var recipe = DraftClaimEvaluationRecipeSchema.shape;
|
|
3610
|
+
var recipeQuestion = recipe.questions.element.shape;
|
|
3611
|
+
var { judgment: judgment4 } = DraftNormalizedEvidenceSchema.shape.normalizations.element.shape;
|
|
3612
|
+
var artifactSemanticLimits = {
|
|
3613
|
+
maxQuestions: 8,
|
|
3614
|
+
maxUnits: 64,
|
|
3615
|
+
maxEvaluations: 128,
|
|
3616
|
+
maxRequestBytes: 32768,
|
|
3617
|
+
maxTotalBytes: 1048576
|
|
3618
|
+
};
|
|
3619
|
+
var ArtifactSemanticQuestionSchema = z44.strictObject({
|
|
3620
|
+
id: id2,
|
|
3621
|
+
instructions: recipeQuestion.instructions,
|
|
3622
|
+
options: recipeQuestion.options,
|
|
3623
|
+
minimumSelectedProbability: recipeQuestion.minimumSelectedProbability,
|
|
3624
|
+
aggregation: z44.enum(["prohibit", "require", "match"])
|
|
3625
|
+
});
|
|
3626
|
+
var ArtifactSemanticRecipeSchema = z44.strictObject({
|
|
3627
|
+
evaluator: recipe.evaluator,
|
|
3628
|
+
calibration: recipe.calibration,
|
|
3629
|
+
probabilityContract: recipe.probabilityContract,
|
|
3630
|
+
questions: z44.array(ArtifactSemanticQuestionSchema).min(1).max(artifactSemanticLimits.maxQuestions),
|
|
3631
|
+
limits: z44.strictObject({
|
|
3632
|
+
maxEvaluations: z44.number().int().min(1).max(artifactSemanticLimits.maxEvaluations),
|
|
3633
|
+
maxRequestBytes: z44.number().int().min(1).max(artifactSemanticLimits.maxRequestBytes),
|
|
3634
|
+
maxTotalBytes: z44.number().int().min(1).max(artifactSemanticLimits.maxTotalBytes)
|
|
3635
|
+
})
|
|
3636
|
+
});
|
|
3637
|
+
var ArtifactSemanticRequestSchema = z44.strictObject({
|
|
3638
|
+
schema: z44.literal("felspar.artifact-question.draft/v1"),
|
|
3639
|
+
preparationDigest: digest20,
|
|
3640
|
+
unitId: id2,
|
|
3641
|
+
sectionId: id2,
|
|
3642
|
+
start: z44.number().int().min(0),
|
|
3643
|
+
end: z44.number().int().min(1),
|
|
3644
|
+
textDigest: digest20,
|
|
3645
|
+
text: z44.string().min(1),
|
|
3646
|
+
questionId: id2,
|
|
3647
|
+
instructions: recipeQuestion.instructions,
|
|
3648
|
+
options: z44.array(z44.strictObject({ value: z44.string(), meaning: z44.string() })).min(2).max(8),
|
|
3649
|
+
policy: z44.array(z44.strictObject({ sourceLocator: z44.string(), text: z44.string() })).min(1),
|
|
3650
|
+
evaluator: recipe.evaluator,
|
|
3651
|
+
calibration: recipe.calibration,
|
|
3652
|
+
requestDigest: digest20
|
|
3653
|
+
});
|
|
3654
|
+
var ArtifactSemanticResponseSchema = z44.strictObject({
|
|
3655
|
+
schema: z44.literal("felspar.artifact-question-response.draft/v1"),
|
|
3656
|
+
preparationDigest: digest20,
|
|
3657
|
+
evaluator: recipe.evaluator,
|
|
3658
|
+
calibrationDigest: digest20,
|
|
3659
|
+
answers: z44.array(z44.strictObject({ unitId: id2, questionId: id2, requestDigest: digest20, judgment: judgment4 })).max(artifactSemanticLimits.maxEvaluations)
|
|
3660
|
+
});
|
|
3661
|
+
var ArtifactSemanticJudgmentSchema = z44.strictObject({
|
|
3662
|
+
unitId: id2,
|
|
3663
|
+
sectionId: id2,
|
|
3664
|
+
start: z44.number().int().min(0),
|
|
3665
|
+
end: z44.number().int().min(1),
|
|
3666
|
+
textDigest: digest20,
|
|
3667
|
+
questionId: id2,
|
|
3668
|
+
requestDigest: digest20,
|
|
3669
|
+
judgment: judgment4.nullable(),
|
|
3670
|
+
value: z44.string().nullable(),
|
|
3671
|
+
effect: z44.enum(["satisfied", "violated", "unresolved", "unavailable", "not_stated"]),
|
|
3672
|
+
reasons: z44.array(z44.string().max(128)).max(8)
|
|
3673
|
+
});
|
|
3674
|
+
var ArtifactSemanticRecordSchema = z44.strictObject({
|
|
3675
|
+
state: z44.enum(["ready", "skipped", "over_budget", "not_evaluated"]),
|
|
3676
|
+
preparationDigest: digest20,
|
|
3677
|
+
evaluator: ArtifactSemanticRecipeSchema.shape.evaluator,
|
|
3678
|
+
calibrationDigest: digest20,
|
|
3679
|
+
probabilityContract: ArtifactSemanticRecipeSchema.shape.probabilityContract,
|
|
3680
|
+
questions: z44.array(ArtifactSemanticQuestionSchema.pick({
|
|
3681
|
+
id: true,
|
|
3682
|
+
minimumSelectedProbability: true,
|
|
3683
|
+
aggregation: true
|
|
3684
|
+
}).extend({
|
|
3685
|
+
checkId: id2,
|
|
3686
|
+
anchorSectionId: id2,
|
|
3687
|
+
sectionsAvailable: z44.boolean(),
|
|
3688
|
+
units: z44.number().int().min(0).max(artifactSemanticLimits.maxEvaluations),
|
|
3689
|
+
options: z44.array(z44.strictObject({
|
|
3690
|
+
value: ArtifactSemanticQuestionSchema.shape.options.element.shape.value,
|
|
3691
|
+
effect: z44.enum(["satisfied", "violated", "unresolved", "not_stated"])
|
|
3692
|
+
})).min(2).max(8)
|
|
3693
|
+
})).max(artifactSemanticLimits.maxQuestions),
|
|
3694
|
+
judgments: z44.array(ArtifactSemanticJudgmentSchema).max(artifactSemanticLimits.maxEvaluations)
|
|
3695
|
+
});
|
|
3696
|
+
var caseNotStated = "not_stated";
|
|
3697
|
+
var abstain = "cannot_determine";
|
|
3698
|
+
function isMatchOf(question2, check) {
|
|
3699
|
+
if (check?.kind !== "case_answer" || question2.aggregation !== "match") {
|
|
3700
|
+
return check?.kind === "semantic_question" && question2.aggregation !== "match";
|
|
3701
|
+
}
|
|
3702
|
+
const offered = new Set(question2.options.map((option2) => option2.value));
|
|
3703
|
+
const expected2 = [...(check.answers ?? []).map((row2) => row2.value), caseNotStated, abstain];
|
|
3704
|
+
return offered.size === question2.options.length && offered.size === expected2.length && expected2.every((value) => offered.has(value));
|
|
3705
|
+
}
|
|
3706
|
+
function isAsking(check) {
|
|
3707
|
+
const isAsker = check.kind === "semantic_question" || check.kind === "case_answer";
|
|
3708
|
+
return typeof check.questionId === "string" && isAsker;
|
|
3709
|
+
}
|
|
3710
|
+
function inspectSemantic(manifest2, issue) {
|
|
3711
|
+
const askers = manifest2.checks.filter(isAsking);
|
|
3712
|
+
const asked = askers.map((check) => check.questionId ?? "");
|
|
3713
|
+
const questions = manifest2.semantic?.questions ?? [];
|
|
3714
|
+
for (const question2 of questions) {
|
|
3715
|
+
const asker = askers.find((check) => check.questionId === question2.id);
|
|
3716
|
+
if (!isMatchOf(question2, asker)) {
|
|
3717
|
+
issue("A semantic question's aggregation differs from the check that asks it");
|
|
3718
|
+
}
|
|
3719
|
+
}
|
|
3720
|
+
const distinctAsked = new Set(asked);
|
|
3721
|
+
if (distinctAsked.size !== asked.length || asked.length !== questions.length || questions.some((question2) => !distinctAsked.has(question2.id))) {
|
|
3722
|
+
issue("Every released semantic question is asked by exactly one check");
|
|
3723
|
+
}
|
|
3724
|
+
for (const question2 of questions) {
|
|
3725
|
+
if (question2.aggregation === "match") {
|
|
3726
|
+
continue;
|
|
3727
|
+
}
|
|
3728
|
+
const effects = new Set(question2.options.map((option2) => option2.effect));
|
|
3729
|
+
const needed = question2.aggregation === "prohibit" ? "violated" : "satisfied";
|
|
3730
|
+
if (!effects.has(needed)) {
|
|
3731
|
+
issue("A semantic question needs an option that can decide its aggregation");
|
|
3732
|
+
}
|
|
3733
|
+
}
|
|
3734
|
+
}
|
|
3735
|
+
|
|
3736
|
+
// ../schemas/src/draft-artifact-check-manifest.ts
|
|
3737
|
+
var id3 = DraftApplicationScopeSchema.shape.authorityId;
|
|
3738
|
+
var digest21 = DraftJobReceiptSchema.shape.receiptDigest;
|
|
3739
|
+
var artifactLintLimits = {
|
|
3740
|
+
maxTotalBytes: 65536,
|
|
3741
|
+
maxSections: 16,
|
|
3742
|
+
maxSectionUnits: 16384,
|
|
3743
|
+
maxChecks: 64,
|
|
3744
|
+
maxAlternatives: 8,
|
|
3745
|
+
maxLiterals: 32,
|
|
3746
|
+
maxLiteralUnits: 512,
|
|
3747
|
+
maxOccurrencesPerCheck: 16
|
|
3748
|
+
};
|
|
3749
|
+
function isWellFormedText(value) {
|
|
3750
|
+
return !/\p{Cs}/u.test(value);
|
|
3751
|
+
}
|
|
3752
|
+
var literal = z45.string().min(1).max(artifactLintLimits.maxLiteralUnits).regex(/\S/u).refine(isWellFormedText);
|
|
3753
|
+
var passage = z45.strictObject({
|
|
3754
|
+
sourceLocator: z45.string().min(1).max(4096).regex(/\S/u),
|
|
3755
|
+
contentDigest: digest21
|
|
3756
|
+
});
|
|
3757
|
+
var common = { id: id3, required: z45.boolean(), specification: passage };
|
|
3758
|
+
var artifactCheckKinds = [
|
|
3759
|
+
"section",
|
|
3760
|
+
"required_wording",
|
|
3761
|
+
"prohibited_literal",
|
|
3762
|
+
"field_value",
|
|
3763
|
+
"semantic_question",
|
|
3764
|
+
"case_answer"
|
|
3765
|
+
];
|
|
3766
|
+
var artifactLintMediaTypes = [
|
|
3767
|
+
"text/plain",
|
|
3768
|
+
"application/vnd.felspar.structured-output+json"
|
|
3769
|
+
];
|
|
3770
|
+
var sectionTargets = z45.array(id3).min(1).max(artifactLintLimits.maxSections);
|
|
3771
|
+
var ArtifactCheckSchema = z45.discriminatedUnion("kind", [
|
|
3772
|
+
z45.strictObject({ ...common, kind: z45.literal("section"), sectionId: id3 }),
|
|
3773
|
+
z45.strictObject({
|
|
3774
|
+
...common,
|
|
3775
|
+
kind: z45.literal("required_wording"),
|
|
3776
|
+
sectionId: id3,
|
|
3777
|
+
alternatives: z45.array(literal).min(1).max(artifactLintLimits.maxAlternatives)
|
|
3778
|
+
}),
|
|
3779
|
+
z45.strictObject({
|
|
3780
|
+
...common,
|
|
3781
|
+
kind: z45.literal("prohibited_literal"),
|
|
3782
|
+
sectionIds: sectionTargets,
|
|
3783
|
+
literals: z45.array(literal).min(1).max(artifactLintLimits.maxLiterals)
|
|
3784
|
+
}),
|
|
3785
|
+
z45.strictObject({
|
|
3786
|
+
...common,
|
|
3787
|
+
kind: z45.literal("field_value"),
|
|
3788
|
+
sectionId: id3,
|
|
3789
|
+
label: z45.string().min(1).max(128).regex(/^[^\s:](?:[^\n\r:]*[^\s:])?$/u).refine(isWellFormedText),
|
|
3790
|
+
unit: z45.string().min(1).max(32).regex(/^\S+$/u).refine(isWellFormedText).nullable(),
|
|
3791
|
+
evidenceKey: id3,
|
|
3792
|
+
comparator: z45.enum(["eq", "lte", "gte"])
|
|
3793
|
+
}),
|
|
3794
|
+
z45.strictObject({
|
|
3795
|
+
...common,
|
|
3796
|
+
kind: z45.literal("case_answer"),
|
|
3797
|
+
sectionIds: sectionTargets,
|
|
3798
|
+
fact: z45.discriminatedUnion("comparison", [
|
|
3799
|
+
z45.strictObject({ key: id3, comparison: z45.literal("choice") }),
|
|
3800
|
+
z45.strictObject({
|
|
3801
|
+
key: id3,
|
|
3802
|
+
comparison: z45.literal("number"),
|
|
3803
|
+
reader: ExactReaderSchema.options[0]
|
|
3804
|
+
}),
|
|
3805
|
+
z45.strictObject({
|
|
3806
|
+
key: id3,
|
|
3807
|
+
comparison: z45.literal("date"),
|
|
3808
|
+
reader: ExactReaderSchema.options[1]
|
|
3809
|
+
})
|
|
3810
|
+
]),
|
|
3811
|
+
answers: z45.array(z45.strictObject({
|
|
3812
|
+
value: id3,
|
|
3813
|
+
wording: z45.array(literal).max(artifactLintLimits.maxAlternatives)
|
|
3814
|
+
})).max(artifactLintLimits.maxLiterals),
|
|
3815
|
+
questionId: id3.nullable()
|
|
3816
|
+
}),
|
|
3817
|
+
z45.strictObject({
|
|
3818
|
+
...common,
|
|
3819
|
+
kind: z45.literal("semantic_question"),
|
|
3820
|
+
sectionIds: sectionTargets,
|
|
3821
|
+
questionId: id3
|
|
3822
|
+
})
|
|
3823
|
+
]);
|
|
3824
|
+
var sectionDeclaration = z45.strictObject({
|
|
3825
|
+
id: id3,
|
|
3826
|
+
heading: z45.string().min(1).max(256).regex(/\S/u).refine((value) => !/[\n\r]/u.test(value) && isWellFormedText(value)).nullable(),
|
|
3827
|
+
maxUnits: z45.number().int().min(1).max(artifactLintLimits.maxSectionUnits)
|
|
3828
|
+
});
|
|
3829
|
+
function caseAnswerIssues(checks) {
|
|
3830
|
+
const issues = [];
|
|
3831
|
+
for (const check of checks) {
|
|
3832
|
+
if (check.kind !== "case_answer") {
|
|
3833
|
+
continue;
|
|
3834
|
+
}
|
|
3835
|
+
const values = check.answers.map((row2) => row2.value);
|
|
3836
|
+
const distinct = new Set(values);
|
|
3837
|
+
if (distinct.size !== values.length || distinct.has("not_stated")) {
|
|
3838
|
+
issues.push("A case answer check lists each answer once");
|
|
3839
|
+
}
|
|
3840
|
+
const isChoice = check.fact.comparison === "choice";
|
|
3841
|
+
if (isChoice ? values.length < 2 : values.length > 0 || check.questionId !== null) {
|
|
3842
|
+
issues.push("A choice fact lists its answers; a number or date fact has none and no question");
|
|
3843
|
+
}
|
|
3844
|
+
}
|
|
3845
|
+
return issues;
|
|
3846
|
+
}
|
|
3847
|
+
var ArtifactCheckManifestSchema = z45.strictObject({
|
|
3848
|
+
schema: z45.literal("felspar.artifact-check-manifest.draft/v1"),
|
|
3849
|
+
id: id3,
|
|
3850
|
+
version: z45.number().int().min(1).max(65535),
|
|
3851
|
+
jobId: id3,
|
|
3852
|
+
trustDomain: id3,
|
|
3853
|
+
contract: z45.strictObject({ id: id3, digest: digest21 }),
|
|
3854
|
+
parser: z45.enum(["body", "headings"]),
|
|
3855
|
+
maxBytes: z45.number().int().min(1).max(artifactLintLimits.maxTotalBytes),
|
|
3856
|
+
sections: z45.array(sectionDeclaration).min(1).max(artifactLintLimits.maxSections),
|
|
3857
|
+
caseContext: z45.enum(["required", "not_required"]),
|
|
3858
|
+
checks: z45.array(ArtifactCheckSchema).min(1).max(artifactLintLimits.maxChecks),
|
|
3859
|
+
semantic: ArtifactSemanticRecipeSchema.nullable()
|
|
3860
|
+
}).superRefine((manifest2, context3) => {
|
|
3861
|
+
const issue = (message) => {
|
|
3862
|
+
context3.addIssue({ code: "custom", message });
|
|
3863
|
+
};
|
|
3864
|
+
const sectionIds = manifest2.sections.map((section) => section.id);
|
|
3865
|
+
const sections = new Set(sectionIds);
|
|
3866
|
+
const checkIds = new Set(manifest2.checks.map((check) => check.id));
|
|
3867
|
+
if (sections.size !== sectionIds.length || checkIds.size !== manifest2.checks.length) {
|
|
3868
|
+
issue("Duplicate section or check identity");
|
|
3869
|
+
}
|
|
3870
|
+
const headings = manifest2.sections.map((section) => section.heading);
|
|
3871
|
+
const isBody = manifest2.parser === "body";
|
|
3872
|
+
if (isBody ? headings.length !== 1 || headings[0] !== null : headings.includes(null)) {
|
|
3873
|
+
issue("Body parser declares one unheaded section; heading parser heads every section");
|
|
3874
|
+
}
|
|
3875
|
+
const distinctHeadings = new Set(headings);
|
|
3876
|
+
if (distinctHeadings.size !== headings.length) {
|
|
3877
|
+
issue("Duplicate section heading");
|
|
3878
|
+
}
|
|
3879
|
+
for (const check of manifest2.checks) {
|
|
3880
|
+
const targets = "sectionIds" in check ? check.sectionIds : [check.sectionId];
|
|
3881
|
+
const distinctTargets = new Set(targets);
|
|
3882
|
+
if (distinctTargets.size !== targets.length || targets.some((t) => !sections.has(t))) {
|
|
3883
|
+
issue("Check targets an undeclared or repeated section");
|
|
3884
|
+
}
|
|
3885
|
+
}
|
|
3886
|
+
const structural = manifest2.checks.filter((check) => check.kind === "section");
|
|
3887
|
+
const covered = new Set(structural.map((check) => check.sectionId));
|
|
3888
|
+
if (structural.length !== sectionIds.length || covered.size !== sectionIds.length) {
|
|
3889
|
+
issue("Every declared section needs exactly one section check");
|
|
3890
|
+
}
|
|
3891
|
+
inspectSemantic(manifest2, issue);
|
|
3892
|
+
for (const message of caseAnswerIssues(manifest2.checks)) {
|
|
3893
|
+
issue(message);
|
|
3894
|
+
}
|
|
3895
|
+
const isCaseBound = manifest2.checks.some((check) => check.kind === "field_value" || check.kind === "case_answer");
|
|
3896
|
+
if (isCaseBound !== (manifest2.caseContext === "required")) {
|
|
3897
|
+
issue("Case context must be required exactly when a check reads case evidence");
|
|
3898
|
+
}
|
|
3899
|
+
});
|
|
3900
|
+
var ArtifactSpecificationSchema = passage;
|
|
3901
|
+
|
|
3902
|
+
// ../schemas/src/draft-job-obligations-manifest.ts
|
|
3903
|
+
import { z as z46 } from "zod";
|
|
3904
|
+
var id4 = DraftApplicationScopeSchema.shape.authorityId;
|
|
3905
|
+
var digest22 = DraftJobReceiptSchema.shape.receiptDigest;
|
|
3906
|
+
var passage2 = {
|
|
3907
|
+
sourceLocator: z46.string().min(1).max(4096).regex(/\S/u),
|
|
3908
|
+
contentDigest: digest22
|
|
3909
|
+
};
|
|
3910
|
+
var jobObligationsLimits = {
|
|
3911
|
+
maxOutcomes: 64,
|
|
3912
|
+
maxArtifacts: 16,
|
|
3913
|
+
maxApprovals: 16,
|
|
3914
|
+
maxContracts: 16,
|
|
3915
|
+
maxApprovalTargets: 16,
|
|
3916
|
+
maxManifestBytes: 65536
|
|
3917
|
+
};
|
|
3918
|
+
var DraftJobObligationsScopeSchema = z46.strictObject({
|
|
3919
|
+
purposeRef: id4,
|
|
3920
|
+
useRef: id4.nullable()
|
|
3921
|
+
});
|
|
3922
|
+
var artifact = z46.strictObject({
|
|
3923
|
+
id: id4,
|
|
3924
|
+
role: id4,
|
|
3925
|
+
contract: z46.strictObject({ id: id4, digest: digest22 }),
|
|
3926
|
+
...passage2
|
|
3927
|
+
});
|
|
3928
|
+
var approval = z46.strictObject({
|
|
3929
|
+
id: id4,
|
|
3930
|
+
policy: z46.strictObject({ id: id4, ...passage2 }),
|
|
3931
|
+
phase: z46.enum(["before_decision", "before_generation", "before_use"]),
|
|
3932
|
+
appliesTo: z46.array(z46.discriminatedUnion("kind", [
|
|
3933
|
+
z46.strictObject({ kind: z46.literal("decision") }),
|
|
3934
|
+
z46.strictObject({ kind: z46.literal("artifact"), id: id4 }),
|
|
3935
|
+
z46.strictObject({ kind: z46.literal("use") })
|
|
3936
|
+
])).min(1).max(jobObligationsLimits.maxApprovalTargets)
|
|
3937
|
+
});
|
|
3938
|
+
var outcome = z46.strictObject({
|
|
3939
|
+
outcomeId: id4,
|
|
3940
|
+
...passage2,
|
|
3941
|
+
contextRequired: z46.boolean(),
|
|
3942
|
+
artifacts: z46.array(artifact).max(jobObligationsLimits.maxArtifacts),
|
|
3943
|
+
approvals: z46.array(approval).max(jobObligationsLimits.maxApprovals)
|
|
3944
|
+
});
|
|
3945
|
+
var manifest = z46.strictObject({
|
|
3946
|
+
schema: z46.literal("felspar.job-obligations.draft/v0"),
|
|
3947
|
+
jobId: id4,
|
|
3948
|
+
trustDomain: id4,
|
|
3949
|
+
scope: DraftJobObligationsScopeSchema,
|
|
3950
|
+
source: DraftSourceReferenceSchema,
|
|
3951
|
+
contracts: z46.array(z46.strictObject({ id: id4, ...passage2 })).max(jobObligationsLimits.maxContracts),
|
|
3952
|
+
outcomes: z46.array(outcome).min(1).max(jobObligationsLimits.maxOutcomes)
|
|
3953
|
+
});
|
|
3954
|
+
function unique3(values, context3, path3) {
|
|
3955
|
+
const distinct = new Set(values);
|
|
3956
|
+
if (distinct.size !== values.length) {
|
|
3957
|
+
context3.addIssue({ code: "custom", path: path3, message: "Duplicate obligation identity or target" });
|
|
3958
|
+
}
|
|
3959
|
+
}
|
|
3960
|
+
function isApprovalTargetValid(item, target, useRef) {
|
|
3961
|
+
switch (item.phase) {
|
|
3962
|
+
case "before_decision": {
|
|
3963
|
+
return target.kind === "decision";
|
|
3964
|
+
}
|
|
3965
|
+
case "before_generation": {
|
|
3966
|
+
return target.kind === "artifact";
|
|
3967
|
+
}
|
|
3968
|
+
case "before_use": {
|
|
3969
|
+
return target.kind === "artifact" || target.kind === "use" && useRef !== null;
|
|
3970
|
+
}
|
|
3971
|
+
default: {
|
|
3972
|
+
return false;
|
|
3973
|
+
}
|
|
3974
|
+
}
|
|
3975
|
+
}
|
|
3976
|
+
function inspectApproval(item, binding, context3) {
|
|
3977
|
+
unique3(item.appliesTo.map((target) => JSON.stringify(target)), context3, ["approvals", item.id]);
|
|
3978
|
+
const artifacts = new Set(binding.selected.artifacts.map((entry2) => entry2.id));
|
|
3979
|
+
for (const target of item.appliesTo) {
|
|
3980
|
+
const isKnown = target.kind !== "artifact" || artifacts.has(target.id);
|
|
3981
|
+
const isValid = isApprovalTargetValid(item, target, binding.scope.useRef);
|
|
3982
|
+
if (!isKnown || !isValid) {
|
|
3983
|
+
context3.addIssue({
|
|
3984
|
+
code: "custom",
|
|
3985
|
+
path: ["approvals", item.id],
|
|
3986
|
+
message: "Unknown or incompatible approval target"
|
|
3987
|
+
});
|
|
3988
|
+
}
|
|
3989
|
+
}
|
|
3990
|
+
}
|
|
3991
|
+
function inspectManifest(value, context3) {
|
|
3992
|
+
if (context3.issues.length > 0) {
|
|
3993
|
+
return;
|
|
3994
|
+
}
|
|
3995
|
+
unique3(value.contracts.map((entry2) => entry2.id), context3, ["contracts"]);
|
|
3996
|
+
unique3(value.outcomes.map((entry2) => entry2.outcomeId), context3, ["outcomes"]);
|
|
3997
|
+
const contracts = new Map(value.contracts.map((entry2) => [entry2.id, entry2.contentDigest]));
|
|
3998
|
+
for (const selected of value.outcomes) {
|
|
3999
|
+
unique3(selected.artifacts.map((entry2) => entry2.id), context3, ["outcomes", selected.outcomeId, "artifacts"]);
|
|
4000
|
+
unique3(selected.approvals.map((entry2) => entry2.id), context3, ["outcomes", selected.outcomeId, "approvals"]);
|
|
4001
|
+
for (const entry2 of selected.artifacts) {
|
|
4002
|
+
if (contracts.get(entry2.contract.id) !== entry2.contract.digest) {
|
|
4003
|
+
context3.addIssue({
|
|
4004
|
+
code: "custom",
|
|
4005
|
+
message: "Dangling or mismatched specification reference"
|
|
4006
|
+
});
|
|
4007
|
+
}
|
|
4008
|
+
}
|
|
4009
|
+
for (const item of selected.approvals) {
|
|
4010
|
+
inspectApproval(item, { selected, scope: value.scope }, context3);
|
|
4011
|
+
}
|
|
4012
|
+
}
|
|
4013
|
+
const encoder2 = new TextEncoder();
|
|
4014
|
+
if (encoder2.encode(JSON.stringify(value)).length > jobObligationsLimits.maxManifestBytes) {
|
|
4015
|
+
context3.addIssue({ code: "custom", message: "Obligations manifest byte limit exceeded" });
|
|
4016
|
+
}
|
|
4017
|
+
}
|
|
4018
|
+
var DraftJobObligationsSchema = manifest.superRefine(inspectManifest);
|
|
4019
|
+
var DraftJobObligationsOutcomeSchema = outcome;
|
|
4020
|
+
|
|
4021
|
+
// ../schemas/src/draft-hosted-output-checks.ts
|
|
4022
|
+
var hostedOutputCheckLimits = { maxOutputs: 8 };
|
|
4023
|
+
var HostedOutputChecksSchema = z47.strictObject({
|
|
4024
|
+
schema: z47.literal("felspar.output-checks.draft/v0"),
|
|
4025
|
+
obligations: DraftJobObligationsSchema,
|
|
4026
|
+
manifests: z47.array(ArtifactCheckManifestSchema).min(1).max(hostedOutputCheckLimits.maxOutputs)
|
|
4027
|
+
}).superRefine((value, context3) => {
|
|
4028
|
+
if (context3.issues.length > 0) {
|
|
4029
|
+
return;
|
|
4030
|
+
}
|
|
4031
|
+
const issue = (message) => {
|
|
4032
|
+
context3.addIssue({ code: "custom", message });
|
|
4033
|
+
};
|
|
4034
|
+
const { obligations, manifests } = value;
|
|
4035
|
+
const contracts = new Map(obligations.contracts.map((entry2) => [entry2.id, entry2]));
|
|
4036
|
+
const checked = new Set(manifests.map((manifest2) => manifest2.contract.id));
|
|
4037
|
+
if (checked.size !== manifests.length) {
|
|
4038
|
+
issue("One manifest per output contract");
|
|
4039
|
+
}
|
|
4040
|
+
for (const manifest2 of manifests) {
|
|
4041
|
+
const contract = contracts.get(manifest2.contract.id);
|
|
4042
|
+
if (contract?.contentDigest !== manifest2.contract.digest || manifest2.jobId !== obligations.jobId || manifest2.trustDomain !== obligations.trustDomain) {
|
|
4043
|
+
issue("A manifest differs from its job or contract");
|
|
4044
|
+
}
|
|
4045
|
+
}
|
|
4046
|
+
const required = obligations.outcomes.flatMap((entry2) => entry2.artifacts.map((artifact2) => artifact2.contract.id));
|
|
4047
|
+
if (required.some((contractId) => !checked.has(contractId)) || checked.size > contracts.size) {
|
|
4048
|
+
issue("Every required output needs exactly one manifest");
|
|
4049
|
+
}
|
|
4050
|
+
});
|
|
4051
|
+
|
|
4052
|
+
// ../schemas/src/draft-hosted-application.ts
|
|
4053
|
+
var id5 = z48.string().min(1).max(200).regex(/^[a-zA-Z0-9][a-zA-Z0-9._:@-]*$/u);
|
|
4054
|
+
var digest23 = DraftApplicationReleaseSchema.shape.releaseDigest;
|
|
4055
|
+
var HostedSourceInputSchema = z48.strictObject({
|
|
4056
|
+
sourceId: id5,
|
|
4057
|
+
revision: id5,
|
|
4058
|
+
title: z48.string().min(1).max(200),
|
|
4059
|
+
text: z48.string().min(1).max(1048576)
|
|
4060
|
+
});
|
|
4061
|
+
var HostedProposalInputV0Schema = z48.strictObject({
|
|
4062
|
+
sourceObjectId: id5,
|
|
4063
|
+
expectedSourceDigest: digest23,
|
|
4064
|
+
material: DraftApplicationJobMaterialSchema,
|
|
4065
|
+
compilation: DraftCompilationSchema
|
|
4066
|
+
});
|
|
4067
|
+
var HostedProposalInputV2Schema = z48.strictObject({
|
|
4068
|
+
schema: z48.literal("felspar.hosted-proposal.draft/v2"),
|
|
4069
|
+
sourceObjectId: id5,
|
|
4070
|
+
expectedSourceDigest: digest23,
|
|
4071
|
+
material: DraftApplicationJobMaterialV2Schema,
|
|
4072
|
+
outputChecks: HostedOutputChecksSchema.optional()
|
|
4073
|
+
});
|
|
4074
|
+
var HostedProposalInputSchema = z48.union([
|
|
4075
|
+
HostedProposalInputV2Schema,
|
|
4076
|
+
HostedProposalInputV0Schema
|
|
4077
|
+
]);
|
|
4078
|
+
var HostedApprovalInputSchema = z48.strictObject({
|
|
4079
|
+
expectedProposalDigest: digest23,
|
|
4080
|
+
reviewedMeaning: z48.literal(true),
|
|
4081
|
+
reviewedFixtures: z48.literal(true),
|
|
4082
|
+
reviewNote: z48.string().min(1).max(2e3)
|
|
4083
|
+
});
|
|
4084
|
+
var HostedReleaseInputSchema = z48.strictObject({ expectedApprovalDigest: digest23 });
|
|
4085
|
+
var HostedReleaseBundleSchema = z48.strictObject({
|
|
4086
|
+
release: DraftApplicationReleaseSchema,
|
|
4087
|
+
material: DraftAnyApplicationJobMaterialSchema,
|
|
4088
|
+
approvalObjectId: id5,
|
|
4089
|
+
approvalDigest: digest23,
|
|
4090
|
+
proposalDigest: digest23,
|
|
4091
|
+
sourceDigest: digest23,
|
|
4092
|
+
verifiedCompilation: DraftVerifiedCompilationSchema.optional()
|
|
4093
|
+
});
|
|
4094
|
+
var HostedJobInputSchema = z48.strictObject({
|
|
4095
|
+
executionId: id5,
|
|
4096
|
+
expectedReleaseDigest: digest23,
|
|
4097
|
+
material: DraftAnyApplicationJobMaterialSchema
|
|
4098
|
+
});
|
|
4099
|
+
var HostedSuppliedJobInputSchema = z48.strictObject({
|
|
4100
|
+
mode: z48.literal("supplied"),
|
|
4101
|
+
executionId: id5,
|
|
4102
|
+
expectedReleaseDigest: digest23,
|
|
4103
|
+
expectedAuthorityDigest: digest23,
|
|
4104
|
+
jobId: id5,
|
|
4105
|
+
entityId: id5,
|
|
4106
|
+
evidence: DraftRequiredDecisionSchema.shape.evidence,
|
|
4107
|
+
passages: DraftLayeredEvaluationSchema.shape.passages.max(256)
|
|
4108
|
+
});
|
|
4109
|
+
var hostedFactsLimits = {
|
|
4110
|
+
maxExcerptCharacters: 2e3,
|
|
4111
|
+
maxExcerptsPerQuestion: 3,
|
|
4112
|
+
maxFactsBytes: 524288,
|
|
4113
|
+
maxQuestions: 64
|
|
4114
|
+
};
|
|
4115
|
+
var factSource = z48.strictObject({
|
|
4116
|
+
class: id5,
|
|
4117
|
+
id: DraftSourceReferenceSchema.shape.sourceId,
|
|
4118
|
+
revision: id5.optional(),
|
|
4119
|
+
locator: z48.string().min(1).max(4096).optional(),
|
|
4120
|
+
observedAt: DraftObservationChecksSchema.shape.evaluationTime,
|
|
4121
|
+
sensitivity: id5.optional()
|
|
4122
|
+
});
|
|
4123
|
+
var excerptText = z48.string().min(1).refine((text7) => text7.length <= hostedFactsLimits.maxExcerptCharacters, "text_too_long");
|
|
4124
|
+
var HostedExcerptSchema = z48.strictObject({ text: excerptText, source: factSource });
|
|
4125
|
+
var HostedValueFactSchema = z48.strictObject({
|
|
4126
|
+
value: z48.union([z48.string().min(1).max(200), z48.number(), z48.boolean()]),
|
|
4127
|
+
source: factSource.extend({ excerpt: excerptText.optional() })
|
|
4128
|
+
});
|
|
4129
|
+
var HostedFactSchema = z48.union([
|
|
4130
|
+
HostedValueFactSchema,
|
|
4131
|
+
HostedExcerptSchema,
|
|
4132
|
+
z48.array(HostedExcerptSchema).min(1).refine((excerpts2) => excerpts2.length <= hostedFactsLimits.maxExcerptsPerQuestion, "too_many_excerpts")
|
|
4133
|
+
]);
|
|
4134
|
+
function factsBytes(facts) {
|
|
4135
|
+
const encoder2 = new TextEncoder();
|
|
4136
|
+
return encoder2.encode(JSON.stringify(facts)).length;
|
|
4137
|
+
}
|
|
4138
|
+
var HostedFactsJobInputSchema = z48.strictObject({
|
|
4139
|
+
mode: z48.literal("facts"),
|
|
4140
|
+
executionId: id5,
|
|
4141
|
+
expectedReleaseDigest: digest23,
|
|
4142
|
+
jobId: id5,
|
|
4143
|
+
entityId: id5,
|
|
4144
|
+
facts: z48.record(id5, HostedFactSchema).refine((facts) => Object.keys(facts).length <= hostedFactsLimits.maxQuestions, "too_many_questions").refine((facts) => factsBytes(facts) <= hostedFactsLimits.maxFactsBytes, "request_too_large")
|
|
4145
|
+
});
|
|
4146
|
+
var HostedJobRequestSchema = z48.union([
|
|
4147
|
+
HostedJobInputSchema,
|
|
4148
|
+
HostedSuppliedJobInputSchema,
|
|
4149
|
+
HostedFactsJobInputSchema
|
|
4150
|
+
]);
|
|
4151
|
+
var HostedClassificationResultSchema = z48.strictObject({
|
|
4152
|
+
key: id5,
|
|
4153
|
+
observationId: id5,
|
|
4154
|
+
record: DraftNormalizedEvidenceSchema.shape.normalizations.element,
|
|
4155
|
+
reason: z48.string().regex(/^[a-z][a-z_]{2,63}$/u).nullable(),
|
|
4156
|
+
cached: z48.boolean()
|
|
4157
|
+
});
|
|
4158
|
+
function retainsFactsExactly(record) {
|
|
4159
|
+
const hasFacts = record.facts !== void 0 && record.judgments !== void 0 && record.judgmentsDigest !== void 0;
|
|
4160
|
+
return record.schema === "felspar.hosted-supplied-execution/v3" === hasFacts;
|
|
4161
|
+
}
|
|
4162
|
+
var HostedSuppliedExecutionRecordSchema = z48.strictObject({
|
|
4163
|
+
schema: z48.enum([
|
|
4164
|
+
"felspar.hosted-supplied-execution/v1",
|
|
4165
|
+
"felspar.hosted-supplied-execution/v2",
|
|
4166
|
+
"felspar.hosted-supplied-execution/v3"
|
|
4167
|
+
]),
|
|
4168
|
+
release: z48.strictObject({ releaseId: id5, releaseDigest: digest23, materialDigest: digest23 }),
|
|
4169
|
+
evaluationTime: z48.iso.datetime(),
|
|
4170
|
+
input: HostedSuppliedJobInputSchema,
|
|
4171
|
+
facts: HostedFactsJobInputSchema.optional(),
|
|
4172
|
+
judgments: z48.array(HostedClassificationResultSchema).max(192).optional(),
|
|
4173
|
+
judgmentsDigest: digest23.optional(),
|
|
4174
|
+
expansion: z48.literal("agreeing-excerpts").optional(),
|
|
4175
|
+
job: z48.record(z48.string(), z48.unknown())
|
|
4176
|
+
}).refine(retainsFactsExactly, "Version 3 records, and only they, retain facts with their judgments");
|
|
4177
|
+
var HostedObjectSchema = z48.strictObject({
|
|
4178
|
+
id: id5,
|
|
4179
|
+
kind: z48.enum(["source", "proposal", "approval", "release", "evidence", "result", "execution"]),
|
|
4180
|
+
payloadDigest: digest23,
|
|
4181
|
+
objectKey: z48.string().min(1).max(1e3),
|
|
4182
|
+
parentId: id5.nullable(),
|
|
4183
|
+
status: z48.enum(["active", "released", "revoked"]),
|
|
4184
|
+
metadata: z48.record(z48.string(), z48.unknown())
|
|
4185
|
+
});
|
|
4186
|
+
var HostedJobResultSchema = z48.object({
|
|
4187
|
+
status: z48.string(),
|
|
4188
|
+
reason: z48.string().nullable(),
|
|
4189
|
+
result: z48.object({
|
|
4190
|
+
executionId: z48.string(),
|
|
4191
|
+
releaseId: id5,
|
|
4192
|
+
releaseDigest: digest23,
|
|
4193
|
+
outcome: z48.string().nullable(),
|
|
4194
|
+
scoring: z48.unknown(),
|
|
4195
|
+
context: z48.unknown(),
|
|
4196
|
+
receipt: z48.unknown()
|
|
4197
|
+
}).loose().nullable()
|
|
4198
|
+
});
|
|
4199
|
+
|
|
4200
|
+
// ../schemas/src/draft-hosted-refusals.ts
|
|
4201
|
+
var limits = hostedFactsLimits;
|
|
4202
|
+
var formatFix = "The request does not match the facts request format at this path; follow input.jsonSchema from describe.";
|
|
4203
|
+
var fixes = {
|
|
4204
|
+
unknown_question: "This question is not in the released job. Use the question keys from describe.",
|
|
4205
|
+
source_class_not_accepted: "This question does not accept this source class. Send an excerpt from a source class the question's evidence policy in describe lists.",
|
|
4206
|
+
value_not_in_excerpt: "The quoted words do not state this value. Quote the exact words that state it, or send the text without a typed value.",
|
|
4207
|
+
duplicate_excerpt: "The same words from the same source were sent twice for this question. Send each excerpt once.",
|
|
4208
|
+
duplicate_source_locator: "Another excerpt in this request names the same source and locator with different words. Give each passage its own locator (for example the page URL with the section heading after #); the same words may answer several questions.",
|
|
4209
|
+
label_needs_mapping: "Felspar decides answer choices and yes/no questions from source text. Send the words the source says, not a label.",
|
|
4210
|
+
value_not_allowed: "A typed value must be a finite number for a number question or a YYYY-MM-DD date for a date question.",
|
|
4211
|
+
answer_choice_needs_excerpt: "Send this question in a facts request with the source text; Felspar classifies answer choices itself.",
|
|
4212
|
+
text_too_long: `An excerpt is at most ${limits.maxExcerptCharacters} characters. Send the shortest passage that states the fact.`,
|
|
4213
|
+
too_many_excerpts: `Send at most ${limits.maxExcerptsPerQuestion} excerpts per question.`,
|
|
4214
|
+
too_many_questions: `Send at most ${limits.maxQuestions} questions per request.`,
|
|
4215
|
+
request_too_large: `The facts in one request are at most ${limits.maxFactsBytes} bytes. Send shorter excerpts.`,
|
|
4216
|
+
release_changed: "The release changed. Describe the job again and resend with the current release digest.",
|
|
4217
|
+
job_mismatch: "This release serves a different job. Use the job and release from describe.",
|
|
4218
|
+
attempt_limit_reached: "This case has used its decision attempts. Don't ask again: escalate it with the next step from your last result.",
|
|
4219
|
+
rate_limited: "This caller or workspace sent more decision requests in the last minute than its plan allows. Wait retryAfterSeconds, then resend the same request with the same execution ID. Send every question you have evidence for in one facts request per entity instead of one request per question, and spread a large run over time; for runs of thousands of entities, ask Felspar about batch scoring.",
|
|
4220
|
+
execution_id_reused: "This execution ID was already used for a different request. Use a new execution ID, or resend the original request unchanged.",
|
|
4221
|
+
invalid_body: "The body must be JSON or content parts within the size limit.",
|
|
4222
|
+
forbidden: "This caller may not run this job on this release, or the release is not available. Check the release ID and the caller's access.",
|
|
4223
|
+
source_read_failed: "Felspar couldn't read the document's current version with your own connection. If access is not_connected or reconnect, connect or reconnect Google Drive on the Felspar Sources page; if no_access, ask the document's owner to share it with you; otherwise try again later.",
|
|
4224
|
+
source_text_not_allowed: "An MCP client can't submit text as a source. To use a document's newest text, call add_current_version with its sourceObjectId from list_sources.",
|
|
4225
|
+
source_not_connected: "This source was not added from a connected document. Use a sourceObjectId from list_sources.",
|
|
4226
|
+
decision_not_found: "Check the output against a decision this caller made: send the executionId from your get_job_decision result for this job.",
|
|
4227
|
+
decision_not_decided: "This decision has no outcome, so nothing is written for it. Follow its next step instead.",
|
|
4228
|
+
no_output_checks: "This job's release declares no output checks. Use the decision's next step; nothing is checked before sending.",
|
|
4229
|
+
output_not_required: "The decided outcome does not require this output. Send one of the outputs listed in required, or none when it is empty.",
|
|
4230
|
+
output_too_large: "The text is longer than this output allows. Shorten it and check again.",
|
|
4231
|
+
invalid_type: formatFix,
|
|
4232
|
+
invalid_union: formatFix,
|
|
4233
|
+
invalid_value: formatFix,
|
|
4234
|
+
invalid_format: formatFix,
|
|
4235
|
+
unrecognized_keys: formatFix,
|
|
4236
|
+
too_big: formatFix,
|
|
4237
|
+
too_small: formatFix
|
|
4238
|
+
};
|
|
4239
|
+
function hostedRefusalFix(code) {
|
|
4240
|
+
return Object.hasOwn(fixes, code) ? fixes[code] ?? null : null;
|
|
4241
|
+
}
|
|
4242
|
+
|
|
4243
|
+
// ../schemas/src/draft-hosted-job-description.ts
|
|
4244
|
+
import { z as z50 } from "zod";
|
|
4245
|
+
|
|
4246
|
+
// ../schemas/src/draft-hosted-output-guides.ts
|
|
4247
|
+
import { z as z49 } from "zod";
|
|
4248
|
+
var id6 = z49.string().min(1).max(200);
|
|
4249
|
+
var located = z49.strictObject({
|
|
4250
|
+
text: z49.string().min(1).max(262144),
|
|
4251
|
+
locator: z49.string().min(1).max(4096)
|
|
4252
|
+
});
|
|
4253
|
+
var hostedOutputGuideLimits = { maxOutputs: 8, maxContext: 8, maxChecks: 64 };
|
|
4254
|
+
var HostedOutputGuideSchema = z49.strictObject({
|
|
4255
|
+
id: id6,
|
|
4256
|
+
what: located,
|
|
4257
|
+
maxCharacters: z49.number().int().min(1),
|
|
4258
|
+
context: z49.array(located.extend({ id: id6 })).max(hostedOutputGuideLimits.maxContext).optional(),
|
|
4259
|
+
checks: z49.array(z49.strictObject({
|
|
4260
|
+
check: id6,
|
|
4261
|
+
rule: z49.string().nullable(),
|
|
4262
|
+
must: z49.string().min(1).max(8e3)
|
|
4263
|
+
})).max(hostedOutputGuideLimits.maxChecks)
|
|
4264
|
+
});
|
|
4265
|
+
var HostedOutputGuidesSchema = z49.array(HostedOutputGuideSchema).max(hostedOutputGuideLimits.maxOutputs);
|
|
4266
|
+
|
|
4267
|
+
// ../schemas/src/draft-hosted-job-description.ts
|
|
4268
|
+
var id7 = z50.string().min(1).max(200);
|
|
4269
|
+
var digest24 = DraftApplicationReleaseSchema.shape.releaseDigest;
|
|
4270
|
+
var { requirements, rules } = DraftRequiredProposalSchema.shape;
|
|
4271
|
+
var quotedText = z50.strictObject({
|
|
4272
|
+
text: z50.string().min(1).max(262144),
|
|
4273
|
+
source: DraftSourceReferenceSchema.omit({ contentDigest: true }).extend({
|
|
4274
|
+
locator: z50.string().min(1).max(4096),
|
|
4275
|
+
contentDigest: digest24
|
|
4276
|
+
}),
|
|
4277
|
+
parts: z50.array(z50.strictObject({ locator: z50.string().min(1).max(4096), text: z50.string() })).max(16)
|
|
4278
|
+
});
|
|
4279
|
+
var HostedJobDescriptionSchema = z50.strictObject({
|
|
4280
|
+
schema: z50.literal("felspar.hosted-job-description.draft/v0"),
|
|
4281
|
+
job: id7,
|
|
4282
|
+
trustDomain: id7,
|
|
4283
|
+
release: z50.strictObject({
|
|
4284
|
+
releaseId: id7,
|
|
4285
|
+
releaseDigest: digest24,
|
|
4286
|
+
materialDigest: digest24,
|
|
4287
|
+
expectedAuthorityDigest: digest24
|
|
4288
|
+
}),
|
|
4289
|
+
resolutionPolicy: DraftRequiredProposalSchema.shape.resolutionPolicy,
|
|
4290
|
+
questions: z50.array(requirements.element.extend({
|
|
4291
|
+
key: id7,
|
|
4292
|
+
type: z50.enum(["enum", "boolean", "number", "date"]),
|
|
4293
|
+
meaning: quotedText,
|
|
4294
|
+
answer: z50.strictObject({
|
|
4295
|
+
send: z50.enum(["text", "text_or_value"]),
|
|
4296
|
+
valueFormat: z50.enum(["number", "calendar-date"]).nullable(),
|
|
4297
|
+
interpretation: z50.enum(["classified", "exact_read", "unsupported"]),
|
|
4298
|
+
threshold: z50.number().gt(0).max(1).nullable(),
|
|
4299
|
+
applies: z50.enum(["always", "conditional"]),
|
|
4300
|
+
dependsOn: z50.array(id7).max(32),
|
|
4301
|
+
appliesWhen: z50.string().min(1).max(2e3).nullable(),
|
|
4302
|
+
reading: ExactReaderSchema.optional()
|
|
4303
|
+
}),
|
|
4304
|
+
answers: z50.array(z50.strictObject({
|
|
4305
|
+
value: id7,
|
|
4306
|
+
meaning: z50.string().nullable(),
|
|
4307
|
+
inclusions: z50.array(z50.string()).max(8),
|
|
4308
|
+
exclusions: z50.array(z50.string()).max(8),
|
|
4309
|
+
examples: z50.array(z50.string()).max(8),
|
|
4310
|
+
edgeCases: z50.array(z50.string()).max(8)
|
|
4311
|
+
})).max(64).optional(),
|
|
4312
|
+
whereToLook: z50.array(quotedText).max(8).optional()
|
|
4313
|
+
})).max(64),
|
|
4314
|
+
rules: z50.array(rules.element.extend({ text: quotedText })).max(256),
|
|
4315
|
+
outcomes: z50.array(z50.strictObject({
|
|
4316
|
+
id: id7,
|
|
4317
|
+
meaning: quotedText.nullable(),
|
|
4318
|
+
nextStep: quotedText.nullable().optional(),
|
|
4319
|
+
outputs: HostedOutputGuidesSchema.optional()
|
|
4320
|
+
})).max(64),
|
|
4321
|
+
whenUnresolved: quotedText.nullable().optional(),
|
|
4322
|
+
attempts: z50.strictObject({
|
|
4323
|
+
max: z50.number().int().min(1).max(10),
|
|
4324
|
+
withProgress: z50.number().int().min(1).max(10),
|
|
4325
|
+
rule: z50.string().min(1).max(1e3)
|
|
4326
|
+
}).optional(),
|
|
4327
|
+
guidance: z50.strictObject({ gather: z50.string().min(1).max(2e3) }),
|
|
4328
|
+
input: z50.strictObject({
|
|
4329
|
+
jsonSchema: z50.record(z50.string(), z50.unknown()),
|
|
4330
|
+
example: HostedFactsJobInputSchema.nullable(),
|
|
4331
|
+
exampleNote: z50.string().max(1e3)
|
|
4332
|
+
}),
|
|
4333
|
+
limits: z50.strictObject({
|
|
4334
|
+
maxEvidenceItems: z50.number().int().positive(),
|
|
4335
|
+
maxPassages: z50.number().int().positive(),
|
|
4336
|
+
facts: z50.strictObject({
|
|
4337
|
+
maxExcerptCharacters: z50.literal(hostedFactsLimits.maxExcerptCharacters),
|
|
4338
|
+
maxExcerptsPerQuestion: z50.literal(hostedFactsLimits.maxExcerptsPerQuestion),
|
|
4339
|
+
maxFactsBytes: z50.literal(hostedFactsLimits.maxFactsBytes),
|
|
4340
|
+
maxQuestions: z50.literal(hostedFactsLimits.maxQuestions)
|
|
4341
|
+
})
|
|
4342
|
+
})
|
|
4343
|
+
});
|
|
4344
|
+
var interpretedExcerpt = z50.strictObject({
|
|
4345
|
+
id: id7,
|
|
4346
|
+
method: z50.enum(["value", "exact_read", "classified"]),
|
|
4347
|
+
status: z50.enum(["accepted", "needs_evidence", "not_needed"]),
|
|
4348
|
+
value: z50.union([z50.string(), z50.number(), z50.boolean()]).optional(),
|
|
4349
|
+
reasons: z50.array(z50.string()),
|
|
4350
|
+
classification: z50.strictObject({
|
|
4351
|
+
candidate: z50.string().nullable(),
|
|
4352
|
+
probability: z50.number().min(0).max(1).nullable(),
|
|
4353
|
+
abstention: z50.number().min(0).max(1).nullable(),
|
|
4354
|
+
threshold: z50.number().min(0).max(1),
|
|
4355
|
+
alternatives: z50.array(z50.strictObject({ value: z50.string(), probability: z50.number() }))
|
|
4356
|
+
}).optional()
|
|
4357
|
+
});
|
|
4358
|
+
var ruleSummary = z50.strictObject({ id: id7, outcome: id7, text: quotedText });
|
|
4359
|
+
var HostedJobExplanationSchema = z50.strictObject({
|
|
4360
|
+
schema: z50.literal("felspar.hosted-job-explanation.draft/v0"),
|
|
4361
|
+
decision: z50.strictObject({ status: z50.string().nullable(), reasons: z50.array(z50.string()) }),
|
|
4362
|
+
needs: z50.array(z50.strictObject({
|
|
4363
|
+
key: id7,
|
|
4364
|
+
status: z50.string(),
|
|
4365
|
+
reasons: z50.array(z50.string()),
|
|
4366
|
+
acceptedSourceClasses: z50.array(z50.string()),
|
|
4367
|
+
maxAgeMs: z50.number().int().nonnegative(),
|
|
4368
|
+
requiredWhen: HostedJobDescriptionSchema.shape.questions.element.shape.requiredWhen,
|
|
4369
|
+
excerpts: z50.array(interpretedExcerpt).optional()
|
|
4370
|
+
})),
|
|
4371
|
+
why: z50.strictObject({
|
|
4372
|
+
rules: z50.array(ruleSummary),
|
|
4373
|
+
overrides: z50.array(z50.strictObject({ by: id7, target: id7 })),
|
|
4374
|
+
suppressedRuleIds: z50.array(id7),
|
|
4375
|
+
evidence: z50.array(z50.record(z50.string(), z50.unknown()))
|
|
4376
|
+
}).nullable(),
|
|
4377
|
+
context: z50.strictObject({ status: z50.string(), reason: z50.string().nullable() }).nullable(),
|
|
4378
|
+
reviewNeeds: z50.array(z50.string()),
|
|
4379
|
+
evidenceFreshUntil: z50.iso.datetime().nullable()
|
|
4380
|
+
});
|
|
4381
|
+
var HostedReceiptVerificationInputSchema = z50.strictObject({
|
|
4382
|
+
receipt: DraftJobReceiptSchema,
|
|
4383
|
+
expectedReceiptDigest: digest24,
|
|
4384
|
+
deliveredCapsule: DraftContextVerificationOptionsSchema.shape.deliveredCapsule
|
|
4385
|
+
});
|
|
4386
|
+
var HostedReceiptVerificationSchema = z50.strictObject({
|
|
4387
|
+
authority: z50.literal("unapproved"),
|
|
4388
|
+
status: z50.enum(["reproduced", "mismatch"]),
|
|
4389
|
+
mismatches: z50.array(z50.string()),
|
|
4390
|
+
decided: z50.strictObject({
|
|
4391
|
+
jobId: id7,
|
|
4392
|
+
entityId: id7,
|
|
4393
|
+
releaseId: id7,
|
|
4394
|
+
outcome: id7.nullable()
|
|
4395
|
+
}).optional()
|
|
4396
|
+
});
|
|
4397
|
+
|
|
4398
|
+
// ../schemas/src/draft-hosted-output-check-record.ts
|
|
4399
|
+
import { z as z53 } from "zod";
|
|
4400
|
+
|
|
4401
|
+
// ../schemas/src/draft-artifact-lint.ts
|
|
4402
|
+
import { z as z52 } from "zod";
|
|
4403
|
+
|
|
4404
|
+
// ../schemas/src/draft-job-obligations.ts
|
|
4405
|
+
import { z as z51 } from "zod";
|
|
4406
|
+
var id8 = DraftApplicationScopeSchema.shape.authorityId;
|
|
4407
|
+
var digest25 = DraftJobReceiptSchema.shape.receiptDigest;
|
|
4408
|
+
var outcome2 = DraftJobObligationsOutcomeSchema;
|
|
4409
|
+
var DraftApplicationJobMaterialV3Schema = DraftApplicationJobMaterialV2Schema.extend({
|
|
4410
|
+
schema: z51.literal("felspar.application-job-material.draft/v3"),
|
|
4411
|
+
obligations: DraftJobObligationsSchema
|
|
4412
|
+
}).superRefine((value, context3) => {
|
|
4413
|
+
if (context3.issues.length > 0) {
|
|
4414
|
+
return;
|
|
4415
|
+
}
|
|
4416
|
+
const { obligations, discovery } = value;
|
|
4417
|
+
const { proposal } = value.input.invocation.authority.catalog;
|
|
4418
|
+
const isSourceMatches = Object.entries(proposal.source).every(([key3, expected2]) => Reflect.get(obligations.source, key3) === expected2);
|
|
4419
|
+
const outcomes = new Set(obligations.outcomes.map((entry2) => entry2.outcomeId));
|
|
4420
|
+
const isComplete = outcomes.size === proposal.allowedOutcomes.length && proposal.allowedOutcomes.every((entry2) => outcomes.has(entry2));
|
|
4421
|
+
const matches = [
|
|
4422
|
+
isSourceMatches,
|
|
4423
|
+
isComplete,
|
|
4424
|
+
obligations.jobId === proposal.job,
|
|
4425
|
+
obligations.trustDomain === proposal.trustDomain,
|
|
4426
|
+
discovery.job === proposal.job,
|
|
4427
|
+
discovery.trustDomain === proposal.trustDomain
|
|
4428
|
+
];
|
|
4429
|
+
if (!matches.every(Boolean)) {
|
|
4430
|
+
context3.addIssue({
|
|
4431
|
+
code: "custom",
|
|
4432
|
+
path: ["obligations"],
|
|
4433
|
+
message: "Obligations differ from released job/source/outcomes"
|
|
4434
|
+
});
|
|
4435
|
+
}
|
|
4436
|
+
});
|
|
4437
|
+
var HostedProposalInputV3Schema = HostedProposalInputV2Schema.extend({
|
|
4438
|
+
schema: z51.literal("felspar.hosted-proposal.draft/v3"),
|
|
4439
|
+
material: DraftApplicationJobMaterialV3Schema
|
|
4440
|
+
});
|
|
4441
|
+
var jobObligationsReplayRoutes = ["supplied", "evaluated"];
|
|
4442
|
+
var replayRoutes = new Set(jobObligationsReplayRoutes);
|
|
4443
|
+
var DraftJobObligationsExecutionSchema = DraftAnyJobExecutionSchema.refine((execution) => replayRoutes.has(execution.invocation.route), "Obligations assessments support supplied and evaluated native executions");
|
|
4444
|
+
var DraftJobObligationsNativeResultSchema = z51.strictObject({
|
|
4445
|
+
authority: z51.literal("unapproved"),
|
|
4446
|
+
discovery: z51.record(z51.string(), z51.unknown()),
|
|
4447
|
+
executed: z51.record(z51.string(), z51.unknown()),
|
|
4448
|
+
receipt: DraftJobReceiptSchema
|
|
4449
|
+
});
|
|
4450
|
+
var DraftJobObligationsInputSchema = z51.strictObject({
|
|
4451
|
+
release: DraftApplicationReleaseSchema,
|
|
4452
|
+
material: z51.union([DraftApplicationJobMaterialV3Schema, DraftAnyApplicationJobMaterialSchema]),
|
|
4453
|
+
execution: DraftJobObligationsExecutionSchema,
|
|
4454
|
+
expectedReceiptDigest: digest25,
|
|
4455
|
+
job: DraftJobObligationsNativeResultSchema,
|
|
4456
|
+
explanation: HostedJobExplanationSchema,
|
|
4457
|
+
invocation: DraftJobObligationsScopeSchema.extend({ caseId: id8 })
|
|
4458
|
+
});
|
|
4459
|
+
var requirements2 = z51.strictObject({
|
|
4460
|
+
status: z51.enum(["established", "unresolved"]),
|
|
4461
|
+
scope: DraftJobObligationsScopeSchema,
|
|
4462
|
+
artifacts: outcome2.shape.artifacts,
|
|
4463
|
+
approvals: outcome2.shape.approvals,
|
|
4464
|
+
unresolved: z51.array(z51.strictObject({ scopeRef: id8, reasonCodes: z51.array(id8).min(1).max(64) })).max(64)
|
|
4465
|
+
});
|
|
4466
|
+
var nextReference = z51.discriminatedUnion("kind", [
|
|
4467
|
+
z51.strictObject({ kind: z51.literal("evidence_need"), id: id8 }),
|
|
4468
|
+
z51.strictObject({ kind: z51.literal("artifact_requirement"), id: id8 }),
|
|
4469
|
+
z51.strictObject({ kind: z51.literal("approval_requirement"), id: id8 }),
|
|
4470
|
+
z51.strictObject({ kind: z51.literal("unresolved_scope"), scopeRef: id8 })
|
|
4471
|
+
]);
|
|
4472
|
+
var DraftJobObligationsAssessmentBodySchema = z51.strictObject({
|
|
4473
|
+
schema: z51.literal("felspar.job-obligations-assessment.draft/v0"),
|
|
4474
|
+
binding: z51.strictObject({
|
|
4475
|
+
releaseDigest: digest25,
|
|
4476
|
+
materialDigest: digest25,
|
|
4477
|
+
nativeReceiptDigest: digest25,
|
|
4478
|
+
jobId: id8,
|
|
4479
|
+
applicationScope: DraftApplicationScopeSchema,
|
|
4480
|
+
caseId: id8,
|
|
4481
|
+
entityId: id8,
|
|
4482
|
+
evaluationTime: z51.iso.datetime({ offset: true }),
|
|
4483
|
+
purposeRef: id8,
|
|
4484
|
+
useRef: id8.nullable()
|
|
4485
|
+
}),
|
|
4486
|
+
requirements: requirements2,
|
|
4487
|
+
next: z51.strictObject({
|
|
4488
|
+
kind: z51.enum([
|
|
4489
|
+
"stop",
|
|
4490
|
+
"review_required",
|
|
4491
|
+
"gather_evidence",
|
|
4492
|
+
"prepare_artifact",
|
|
4493
|
+
"verify_before_action",
|
|
4494
|
+
"return_result"
|
|
4495
|
+
]),
|
|
4496
|
+
reasonCodes: z51.array(id8).max(64),
|
|
4497
|
+
refs: z51.array(nextReference).max(64)
|
|
4498
|
+
})
|
|
4499
|
+
});
|
|
4500
|
+
function isNextRefDeclared(ref, required) {
|
|
4501
|
+
switch (ref.kind) {
|
|
4502
|
+
case "artifact_requirement": {
|
|
4503
|
+
return required.artifacts.some((entry2) => entry2.id === ref.id);
|
|
4504
|
+
}
|
|
4505
|
+
case "approval_requirement": {
|
|
4506
|
+
return required.approvals.some((entry2) => entry2.id === ref.id);
|
|
4507
|
+
}
|
|
4508
|
+
case "unresolved_scope": {
|
|
4509
|
+
return required.unresolved.some((entry2) => entry2.scopeRef === ref.scopeRef);
|
|
4510
|
+
}
|
|
4511
|
+
case "evidence_need": {
|
|
4512
|
+
return true;
|
|
4513
|
+
}
|
|
4514
|
+
default: {
|
|
4515
|
+
return false;
|
|
4516
|
+
}
|
|
4517
|
+
}
|
|
4518
|
+
}
|
|
4519
|
+
var DraftJobObligationsAssessmentSchema = DraftJobObligationsAssessmentBodySchema.extend({
|
|
4520
|
+
assessmentDigest: digest25
|
|
4521
|
+
}).superRefine((value, context3) => {
|
|
4522
|
+
const { requirements: required } = value;
|
|
4523
|
+
if (required.status === "established" !== (required.unresolved.length === 0) || required.status === "unresolved" && (required.artifacts.length > 0 || required.approvals.length > 0)) {
|
|
4524
|
+
context3.addIssue({ code: "custom", message: "Requirements completeness differs" });
|
|
4525
|
+
}
|
|
4526
|
+
for (const ref of value.next.refs) {
|
|
4527
|
+
if (!isNextRefDeclared(ref, required)) {
|
|
4528
|
+
context3.addIssue({ code: "custom", message: "Dangling next reference" });
|
|
4529
|
+
}
|
|
4530
|
+
}
|
|
4531
|
+
});
|
|
4532
|
+
|
|
4533
|
+
// ../schemas/src/draft-artifact-lint.ts
|
|
4534
|
+
var id9 = DraftApplicationScopeSchema.shape.authorityId;
|
|
4535
|
+
var digest26 = DraftJobReceiptSchema.shape.receiptDigest;
|
|
4536
|
+
var passage3 = ArtifactSpecificationSchema;
|
|
4537
|
+
var plainArtifact = z52.strictObject({
|
|
4538
|
+
id: id9,
|
|
4539
|
+
revision: id9,
|
|
4540
|
+
mediaType: z52.literal("text/plain"),
|
|
4541
|
+
exportProfile: id9.nullable(),
|
|
4542
|
+
content: z52.string().max(artifactLintLimits.maxTotalBytes),
|
|
4543
|
+
expectedContentDigest: digest26
|
|
4544
|
+
});
|
|
4545
|
+
var structuredArtifact = z52.strictObject({
|
|
4546
|
+
id: id9,
|
|
4547
|
+
revision: id9,
|
|
4548
|
+
mediaType: z52.literal("application/vnd.felspar.structured-output+json"),
|
|
4549
|
+
exportProfile: id9.nullable(),
|
|
4550
|
+
content: DraftStructuredOutputSchema,
|
|
4551
|
+
expectedContentDigest: digest26
|
|
4552
|
+
});
|
|
4553
|
+
var ArtifactLintArtifactSchema = z52.discriminatedUnion("mediaType", [
|
|
4554
|
+
plainArtifact,
|
|
4555
|
+
structuredArtifact
|
|
4556
|
+
]);
|
|
4557
|
+
var ArtifactLintDecisionSchema = z52.strictObject({
|
|
4558
|
+
inputs: DraftJobObligationsInputSchema,
|
|
4559
|
+
assessment: DraftJobObligationsAssessmentSchema,
|
|
4560
|
+
expectedAssessmentDigest: digest26
|
|
4561
|
+
});
|
|
4562
|
+
var ArtifactLintInputSchema = z52.strictObject({
|
|
4563
|
+
schema: z52.literal("felspar.lint.draft/v1"),
|
|
4564
|
+
requestId: id9,
|
|
4565
|
+
release: DraftApplicationReleaseSchema,
|
|
4566
|
+
material: DraftApplicationJobMaterialV3Schema,
|
|
4567
|
+
manifest: ArtifactCheckManifestSchema,
|
|
4568
|
+
expectedManifestDigest: digest26,
|
|
4569
|
+
attachedObligations: z52.strictObject({ expectedObligationsDigest: digest26 }).optional(),
|
|
4570
|
+
attachedCase: z52.strictObject({
|
|
4571
|
+
decisionReceiptDigest: digest26,
|
|
4572
|
+
answers: z52.array(z52.strictObject({ key: id9, value: z52.union([z52.string().min(1).max(200), z52.null()]) })).max(256)
|
|
4573
|
+
}).optional(),
|
|
4574
|
+
case: z52.strictObject({ caseId: id9, purposeRef: id9, useRef: id9.nullable() }),
|
|
4575
|
+
artifactRequirementId: id9.nullable(),
|
|
4576
|
+
decision: ArtifactLintDecisionSchema.nullable(),
|
|
4577
|
+
artifact: ArtifactLintArtifactSchema
|
|
4578
|
+
});
|
|
4579
|
+
var artifactCheckStatuses = [
|
|
4580
|
+
"passed",
|
|
4581
|
+
"violated",
|
|
4582
|
+
"unresolved",
|
|
4583
|
+
"unsupported",
|
|
4584
|
+
"unavailable",
|
|
4585
|
+
"not_applicable",
|
|
4586
|
+
"skipped"
|
|
4587
|
+
];
|
|
4588
|
+
var range = z52.strictObject({
|
|
4589
|
+
sectionId: id9,
|
|
4590
|
+
start: z52.number().int().min(0).max(artifactLintLimits.maxSectionUnits),
|
|
4591
|
+
end: z52.number().int().min(1).max(artifactLintLimits.maxSectionUnits),
|
|
4592
|
+
offsetUnit: z52.literal("utf16_code_units")
|
|
4593
|
+
});
|
|
4594
|
+
var findingCodes = [
|
|
4595
|
+
"section_missing",
|
|
4596
|
+
"section_empty",
|
|
4597
|
+
"section_too_large",
|
|
4598
|
+
"section_duplicated",
|
|
4599
|
+
"required_wording_missing",
|
|
4600
|
+
"prohibited_literal",
|
|
4601
|
+
"field_missing",
|
|
4602
|
+
"field_ambiguous",
|
|
4603
|
+
"field_malformed",
|
|
4604
|
+
"field_mismatch",
|
|
4605
|
+
"case_value_unresolved",
|
|
4606
|
+
"text_unassigned",
|
|
4607
|
+
"hidden_formatting",
|
|
4608
|
+
"dependency_unmet",
|
|
4609
|
+
"check_unsupported",
|
|
4610
|
+
"semantic_violation",
|
|
4611
|
+
"semantic_missing",
|
|
4612
|
+
"semantic_unresolved",
|
|
4613
|
+
"case_answer_conflict",
|
|
4614
|
+
"case_answer_missing",
|
|
4615
|
+
"case_answer_unconfirmed",
|
|
4616
|
+
"evaluation_unavailable",
|
|
4617
|
+
"evaluation_budget_exceeded",
|
|
4618
|
+
"evaluation_skipped"
|
|
4619
|
+
];
|
|
4620
|
+
var ArtifactFindingSchema = z52.strictObject({
|
|
4621
|
+
code: z52.enum(findingCodes),
|
|
4622
|
+
checkId: id9.nullable(),
|
|
4623
|
+
severity: z52.enum(["error", "warning"]),
|
|
4624
|
+
specification: passage3.nullable(),
|
|
4625
|
+
location: range.nullable(),
|
|
4626
|
+
insertionAnchor: z52.strictObject({ sectionId: id9.nullable(), at: z52.number().int().min(0) }).nullable(),
|
|
4627
|
+
literalIndex: z52.number().int().min(0).max(artifactLintLimits.maxLiterals).nullable()
|
|
4628
|
+
});
|
|
4629
|
+
var ArtifactCheckObservationSchema = z52.strictObject({
|
|
4630
|
+
checkId: id9,
|
|
4631
|
+
kind: z52.enum(artifactCheckKinds),
|
|
4632
|
+
required: z52.boolean(),
|
|
4633
|
+
method: z52.enum(["deterministic", "semantic"]),
|
|
4634
|
+
status: z52.enum(artifactCheckStatuses),
|
|
4635
|
+
occurrences: z52.number().int().min(0),
|
|
4636
|
+
parsedValue: z52.number().nullable(),
|
|
4637
|
+
caseValue: z52.number().nullable()
|
|
4638
|
+
});
|
|
4639
|
+
var ArtifactLintRecordBodySchema = z52.strictObject({
|
|
4640
|
+
schema: z52.literal("felspar.lint-record.draft/v1"),
|
|
4641
|
+
requestId: id9,
|
|
4642
|
+
status: z52.enum(["pass", "revise", "unavailable", "review_required"]),
|
|
4643
|
+
caseContext: z52.enum(["bound", "not_required"]),
|
|
4644
|
+
binding: z52.strictObject({
|
|
4645
|
+
scope: DraftApplicationScopeSchema,
|
|
4646
|
+
releaseId: id9,
|
|
4647
|
+
releaseDigest: digest26,
|
|
4648
|
+
materialDigest: digest26,
|
|
4649
|
+
obligationsDigest: digest26.optional(),
|
|
4650
|
+
caseFactsDigest: digest26.optional(),
|
|
4651
|
+
jobId: id9,
|
|
4652
|
+
manifestId: id9,
|
|
4653
|
+
manifestDigest: digest26,
|
|
4654
|
+
contract: z52.strictObject({ id: id9, digest: digest26 }),
|
|
4655
|
+
caseId: id9,
|
|
4656
|
+
purposeRef: id9,
|
|
4657
|
+
useRef: id9.nullable(),
|
|
4658
|
+
artifactRequirementId: id9.nullable(),
|
|
4659
|
+
decisionReceiptDigest: digest26.nullable(),
|
|
4660
|
+
obligationsAssessmentDigest: digest26.nullable()
|
|
4661
|
+
}),
|
|
4662
|
+
artifact: z52.strictObject({
|
|
4663
|
+
id: id9,
|
|
4664
|
+
revision: id9,
|
|
4665
|
+
mediaType: z52.enum(artifactLintMediaTypes),
|
|
4666
|
+
exportProfile: id9.nullable(),
|
|
4667
|
+
contentDigest: digest26,
|
|
4668
|
+
sections: z52.array(z52.strictObject({
|
|
4669
|
+
id: id9,
|
|
4670
|
+
units: z52.number().int().min(0),
|
|
4671
|
+
contentDigest: digest26.nullable()
|
|
4672
|
+
})).max(artifactLintLimits.maxSections)
|
|
4673
|
+
}),
|
|
4674
|
+
checks: z52.array(ArtifactCheckObservationSchema).max(artifactLintLimits.maxChecks),
|
|
4675
|
+
findings: z52.array(ArtifactFindingSchema).max(2048),
|
|
4676
|
+
semantic: ArtifactSemanticRecordSchema.nullable(),
|
|
4677
|
+
coverage: z52.strictObject({
|
|
4678
|
+
scope: z52.literal("declared_checks_only"),
|
|
4679
|
+
declared: z52.number().int().min(0),
|
|
4680
|
+
applicable: z52.number().int().min(0),
|
|
4681
|
+
completed: z52.number().int().min(0),
|
|
4682
|
+
required: z52.number().int().min(0),
|
|
4683
|
+
requiredCompleted: z52.number().int().min(0),
|
|
4684
|
+
textAssigned: z52.enum(["complete", "incomplete"]),
|
|
4685
|
+
semantic: z52.enum(["not_declared", "complete", "incomplete"]),
|
|
4686
|
+
nativeDocumentLayout: z52.literal("not_checked")
|
|
4687
|
+
}),
|
|
4688
|
+
actionAuthorized: z52.literal(false)
|
|
4689
|
+
});
|
|
4690
|
+
var ArtifactLintRecordSchema = ArtifactLintRecordBodySchema.extend({
|
|
4691
|
+
recordDigest: digest26
|
|
4692
|
+
});
|
|
4693
|
+
var ArtifactLintReceiptSchema = z52.strictObject({
|
|
4694
|
+
schema: z52.literal("felspar.lint-receipt.draft/v1"),
|
|
4695
|
+
recordDigest: digest26,
|
|
4696
|
+
releaseDigest: digest26,
|
|
4697
|
+
manifestDigest: digest26,
|
|
4698
|
+
contractDigest: digest26,
|
|
4699
|
+
caseId: id9,
|
|
4700
|
+
caseContext: z52.enum(["bound", "not_required"]),
|
|
4701
|
+
decisionReceiptDigest: digest26.nullable(),
|
|
4702
|
+
obligationsAssessmentDigest: digest26.nullable(),
|
|
4703
|
+
artifactId: id9,
|
|
4704
|
+
artifactRevision: id9,
|
|
4705
|
+
artifactDigest: digest26,
|
|
4706
|
+
actionAuthorized: z52.literal(false),
|
|
4707
|
+
receiptDigest: digest26
|
|
4708
|
+
});
|
|
4709
|
+
|
|
4710
|
+
// ../schemas/src/draft-hosted-output-check-record.ts
|
|
4711
|
+
var id10 = DraftApplicationScopeSchema.shape.authorityId;
|
|
4712
|
+
var digest27 = DraftJobReceiptSchema.shape.receiptDigest;
|
|
4713
|
+
var HostedOutputCheckInputSchema = z53.strictObject({
|
|
4714
|
+
executionId: id10,
|
|
4715
|
+
output: id10.optional(),
|
|
4716
|
+
text: z53.string().min(1).max(artifactLintLimits.maxTotalBytes).refine(isWellFormedText, "text_not_well_formed"),
|
|
4717
|
+
revision: id10.optional()
|
|
4718
|
+
});
|
|
4719
|
+
var HostedOutputCheckRecordSchema = z53.strictObject({
|
|
4720
|
+
schema: z53.literal("felspar.hosted-output-check/v0"),
|
|
4721
|
+
checkId: id10,
|
|
4722
|
+
jobId: id10,
|
|
4723
|
+
output: id10,
|
|
4724
|
+
decision: z53.strictObject({ executionId: id10, outcome: id10, receiptDigest: digest27 }),
|
|
4725
|
+
release: z53.strictObject({ releaseId: id10, releaseDigest: digest27 }),
|
|
4726
|
+
record: ArtifactLintRecordSchema,
|
|
4727
|
+
receipt: ArtifactLintReceiptSchema.nullable(),
|
|
4728
|
+
evaluation: z53.strictObject({
|
|
4729
|
+
modelCalls: z53.number().int().min(0),
|
|
4730
|
+
reason: z53.string().regex(/^[a-z][a-z_]{2,63}$/u).nullable()
|
|
4731
|
+
})
|
|
4732
|
+
});
|
|
4733
|
+
|
|
4734
|
+
// src/draft-hosted-client.ts
|
|
4735
|
+
import { z as z54 } from "zod";
|
|
4736
|
+
var digestText = z54.string().regex(/^sha256:[a-f0-9]{64}$/u);
|
|
4737
|
+
var HostedOutputCheckReplySchema = z54.object({
|
|
4738
|
+
status: z54.enum(["pass", "revise", "review_required", "unavailable"]),
|
|
4739
|
+
checkId: z54.string(),
|
|
4740
|
+
output: z54.string(),
|
|
4741
|
+
findings: z54.array(z54.record(z54.string(), z54.unknown())),
|
|
4742
|
+
receipt: z54.object({ receiptDigest: digestText, artifactDigest: digestText }).loose().nullable(),
|
|
4743
|
+
decision: z54.object({ executionId: z54.string(), receiptDigest: digestText }),
|
|
4744
|
+
actionAuthorized: z54.literal(false)
|
|
4745
|
+
}).loose();
|
|
4746
|
+
var hostedPartsContentType = "application/x.felspar-content-parts";
|
|
4747
|
+
async function partsBody(value) {
|
|
4748
|
+
const packed = await packContentParts(value);
|
|
4749
|
+
return packed.text;
|
|
4750
|
+
}
|
|
4751
|
+
async function factsRequest(value, describeRelease) {
|
|
4752
|
+
if (typeof value.expectedReleaseDigest === "string") {
|
|
4753
|
+
return HostedFactsJobInputSchema.parse({ mode: "facts", ...value });
|
|
4754
|
+
}
|
|
4755
|
+
const described = await describeRelease(HostedObjectSchema.shape.id.parse(value.jobId));
|
|
4756
|
+
return HostedFactsJobInputSchema.parse({
|
|
4757
|
+
mode: "facts",
|
|
4758
|
+
...value,
|
|
4759
|
+
expectedReleaseDigest: described.release.releaseDigest
|
|
4760
|
+
});
|
|
4761
|
+
}
|
|
4762
|
+
function pinnedResult(response, releaseId, input) {
|
|
4763
|
+
if (response.result !== null && (response.result.releaseId !== releaseId || response.result.releaseDigest !== input.expectedReleaseDigest || response.result.executionId !== input.executionId)) {
|
|
4764
|
+
throw new Error("Felspar result pin differs");
|
|
4765
|
+
}
|
|
4766
|
+
return response;
|
|
4767
|
+
}
|
|
4768
|
+
function describePath(releaseId, jobId) {
|
|
4769
|
+
return `/v0/releases/${encodeURIComponent(releaseId)}/describe?job=${encodeURIComponent(jobId)}`;
|
|
4770
|
+
}
|
|
4771
|
+
function jobDescriber(fetchDescription) {
|
|
4772
|
+
const descriptions = /* @__PURE__ */ new Map();
|
|
4773
|
+
async function fetchOnce(key3, releaseId, jobId) {
|
|
4774
|
+
try {
|
|
4775
|
+
return await fetchDescription(releaseId, jobId);
|
|
4776
|
+
} catch (error) {
|
|
4777
|
+
descriptions.delete(key3);
|
|
4778
|
+
throw error;
|
|
4779
|
+
}
|
|
4780
|
+
}
|
|
4781
|
+
return async (releaseId, jobId) => {
|
|
4782
|
+
const key3 = `${releaseId}
|
|
4783
|
+
${jobId}`;
|
|
4784
|
+
let described = descriptions.get(key3);
|
|
4785
|
+
if (!described) {
|
|
4786
|
+
described = fetchOnce(key3, releaseId, jobId);
|
|
4787
|
+
descriptions.set(key3, described);
|
|
4788
|
+
}
|
|
4789
|
+
const result = await described;
|
|
4790
|
+
if (result.release.releaseId !== releaseId || result.job !== jobId) {
|
|
4791
|
+
throw new Error("Felspar description pin differs");
|
|
4792
|
+
}
|
|
4793
|
+
return result;
|
|
4794
|
+
};
|
|
4795
|
+
}
|
|
4796
|
+
var refusalCode = z54.string().regex(/^[a-z][a-z_]{2,63}$/u);
|
|
4797
|
+
var fieldPath = z54.array(z54.string().max(256)).max(32);
|
|
4798
|
+
var refusalSchema = z54.object({
|
|
4799
|
+
error: refusalCode,
|
|
4800
|
+
path: fieldPath.optional(),
|
|
4801
|
+
currentReleaseDigest: z54.string().regex(/^sha256:[a-f0-9]{64}$/u).optional(),
|
|
4802
|
+
retryAfterSeconds: z54.number().int().min(1).max(3600).optional(),
|
|
4803
|
+
issues: z54.array(z54.object({ code: refusalCode, path: fieldPath })).max(64).optional()
|
|
4804
|
+
}).transform((value) => {
|
|
4805
|
+
const fix = hostedRefusalFix(value.error);
|
|
4806
|
+
return {
|
|
4807
|
+
...value,
|
|
4808
|
+
...fix !== null && { fix },
|
|
4809
|
+
...value.issues && {
|
|
4810
|
+
issues: value.issues.map((issue) => {
|
|
4811
|
+
const issueFix = hostedRefusalFix(issue.code);
|
|
4812
|
+
return issueFix === null ? issue : { ...issue, fix: issueFix };
|
|
4813
|
+
})
|
|
4814
|
+
}
|
|
4815
|
+
};
|
|
4816
|
+
});
|
|
4817
|
+
var FelsparRequestError = class extends Error {
|
|
4818
|
+
status;
|
|
4819
|
+
refusal;
|
|
4820
|
+
constructor(options) {
|
|
4821
|
+
const code = options.refusal === null ? "" : `: ${options.refusal.error}`;
|
|
4822
|
+
super(`Felspar request failed (${options.status}${code})`, options);
|
|
4823
|
+
this.name = "FelsparRequestError";
|
|
4824
|
+
this.status = options.status;
|
|
4825
|
+
this.refusal = options.refusal;
|
|
4826
|
+
}
|
|
4827
|
+
};
|
|
4828
|
+
async function refusalOf(response) {
|
|
4829
|
+
const text7 = await response.text();
|
|
4830
|
+
const parsed = refusalSchema.safeParse(text7.length <= 65536 ? JSON.parse(text7) : null);
|
|
4831
|
+
return parsed.success ? parsed.data : null;
|
|
4832
|
+
}
|
|
4833
|
+
async function requestError(response) {
|
|
4834
|
+
let refusal = null;
|
|
4835
|
+
try {
|
|
4836
|
+
refusal = await refusalOf(response);
|
|
4837
|
+
} catch {
|
|
4838
|
+
}
|
|
4839
|
+
return new FelsparRequestError({ status: response.status, refusal });
|
|
4840
|
+
}
|
|
4841
|
+
function authorizationOf(configuration) {
|
|
4842
|
+
if (configuration.session !== void 0 && configuration.agentKey !== void 0) {
|
|
4843
|
+
throw new Error("Use a session or an agent key, not both");
|
|
4844
|
+
}
|
|
4845
|
+
if (configuration.session !== void 0) {
|
|
4846
|
+
return `FelsparSession ${configuration.session}`;
|
|
4847
|
+
}
|
|
4848
|
+
return configuration.agentKey === void 0 ? null : `Bearer ${configuration.agentKey}`;
|
|
4849
|
+
}
|
|
4850
|
+
function outputCheckCalls(call) {
|
|
4851
|
+
const objectId = HostedObjectSchema.shape.id;
|
|
4852
|
+
const checksOf = (job) => `/v0/jobs/${encodeURIComponent(objectId.parse(job))}/output-checks`;
|
|
4853
|
+
return {
|
|
4854
|
+
checkOutput: async (job, value) => await call(checksOf(job), HostedOutputCheckReplySchema, HostedOutputCheckInputSchema.parse(value)),
|
|
4855
|
+
readOutputCheck: async (job, checkId) => await call(`${checksOf(job)}/${encodeURIComponent(objectId.parse(checkId))}`, HostedOutputCheckReplySchema)
|
|
4856
|
+
};
|
|
4857
|
+
}
|
|
4858
|
+
function createHostedFelsparClient(configuration) {
|
|
4859
|
+
const origin = new URL(configuration.origin);
|
|
4860
|
+
const invalid = [
|
|
4861
|
+
origin.protocol !== "https:",
|
|
4862
|
+
origin.username !== "",
|
|
4863
|
+
origin.password !== "",
|
|
4864
|
+
origin.pathname !== "/",
|
|
4865
|
+
origin.search !== "",
|
|
4866
|
+
origin.hash !== ""
|
|
4867
|
+
];
|
|
4868
|
+
if (invalid.some(Boolean)) {
|
|
4869
|
+
throw new Error("HTTPS origin required");
|
|
4870
|
+
}
|
|
4871
|
+
const authorization = authorizationOf(configuration);
|
|
4872
|
+
const fetcher = configuration.fetcher ?? fetch;
|
|
4873
|
+
async function call(path3, schema, value) {
|
|
4874
|
+
const headers = new Headers(authorization === null ? {} : { Authorization: authorization });
|
|
4875
|
+
const body = value === void 0 ? void 0 : await partsBody(value);
|
|
4876
|
+
if (body !== void 0) {
|
|
4877
|
+
headers.set("Content-Type", hostedPartsContentType);
|
|
4878
|
+
}
|
|
4879
|
+
const response = await fetcher(`${origin.origin}${path3}`, {
|
|
4880
|
+
method: value === void 0 ? "GET" : "POST",
|
|
4881
|
+
headers,
|
|
4882
|
+
credentials: "include",
|
|
4883
|
+
redirect: "error",
|
|
4884
|
+
signal: AbortSignal.timeout(9e4),
|
|
4885
|
+
...body !== void 0 && { body }
|
|
4886
|
+
});
|
|
4887
|
+
if (!response.ok) {
|
|
4888
|
+
throw await requestError(response);
|
|
4889
|
+
}
|
|
4890
|
+
return schema.parse(await response.json());
|
|
4891
|
+
}
|
|
4892
|
+
const objectId = HostedObjectSchema.shape.id;
|
|
4893
|
+
const describe = jobDescriber(async (releaseId, jobId) => await call(describePath(releaseId, jobId), HostedJobDescriptionSchema));
|
|
4894
|
+
return {
|
|
4895
|
+
submitSource: async (value) => await call("/v0/sources", HostedObjectSchema, HostedSourceInputSchema.parse(value)),
|
|
4896
|
+
submitProposal: async (value) => await call("/v0/proposals", HostedObjectSchema, HostedProposalInputSchema.parse(value)),
|
|
4897
|
+
approveProposal: async (id11, value) => await call(`/v0/proposals/${encodeURIComponent(objectId.parse(id11))}/approve`, HostedObjectSchema, HostedApprovalInputSchema.parse(value)),
|
|
4898
|
+
releasePack: async (id11, value) => await call(`/v0/approvals/${encodeURIComponent(objectId.parse(id11))}/release`, DraftApplicationReleaseSchema, HostedReleaseInputSchema.parse(value)),
|
|
4899
|
+
loadRelease: async (id11) => await call(`/v0/releases/${encodeURIComponent(objectId.parse(id11))}`, HostedReleaseBundleSchema),
|
|
4900
|
+
describeJob: async (id11, job) => await describe(objectId.parse(id11), objectId.parse(job)),
|
|
4901
|
+
verifyReceipt: async (executionObjectId, value) => await call(`/v0/executions/${encodeURIComponent(objectId.parse(executionObjectId))}/verify`, HostedReceiptVerificationSchema, HostedReceiptVerificationInputSchema.parse(value)),
|
|
4902
|
+
...outputCheckCalls(call),
|
|
4903
|
+
executeJob: async (id11, value) => await call(`/v0/releases/${encodeURIComponent(objectId.parse(id11))}/jobs`, HostedJobResultSchema, HostedJobInputSchema.parse(value)),
|
|
4904
|
+
resolveFacts: async (id11, value) => {
|
|
4905
|
+
const releaseId = objectId.parse(id11);
|
|
4906
|
+
const input = await factsRequest(value, async (jobId) => await describe(releaseId, jobId));
|
|
4907
|
+
const path3 = `/v0/releases/${encodeURIComponent(releaseId)}/jobs`;
|
|
4908
|
+
return pinnedResult(await call(path3, HostedJobResultSchema, input), releaseId, input);
|
|
4909
|
+
},
|
|
4910
|
+
resolveJob: async (id11, value) => {
|
|
4911
|
+
const input = HostedSuppliedJobInputSchema.parse(value);
|
|
4912
|
+
const releaseId = objectId.parse(id11);
|
|
4913
|
+
const response = await call(`/v0/releases/${encodeURIComponent(releaseId)}/jobs`, HostedJobResultSchema, input);
|
|
4914
|
+
return pinnedResult(response, releaseId, input);
|
|
4915
|
+
}
|
|
4916
|
+
};
|
|
4917
|
+
}
|
|
4918
|
+
|
|
4919
|
+
export {
|
|
4920
|
+
FelsparRequestError,
|
|
4921
|
+
createHostedFelsparClient
|
|
4922
|
+
};
|