@soiljs/spi 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +110 -2
- package/dist/chunk-22LK3R2V.js +81 -0
- package/dist/chunk-22LK3R2V.js.map +1 -0
- package/dist/index.d.ts +137 -0
- package/dist/index.js +345 -0
- package/dist/index.js.map +1 -0
- package/dist/storage-DfHSUuQH.d.ts +619 -0
- package/dist/testing/index.d.ts +30 -0
- package/dist/testing/index.js +899 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +38 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { ToolValidationError } from './chunk-22LK3R2V.js';
|
|
2
|
+
export { AgentNotRegisteredError, COMMAND_REJECTION_REASONS, CommandRejectedError, ConcurrencyConflictError, IdempotencyConflictError, LeaseLostError, SOIL_ERROR_CODES, SessionBusyError, SoilError, ToolValidationError } from './chunk-22LK3R2V.js';
|
|
3
|
+
|
|
4
|
+
// src/primitives.ts
|
|
5
|
+
function aggregateUsageTotals(usages) {
|
|
6
|
+
const totals = {
|
|
7
|
+
inputTokens: 0,
|
|
8
|
+
outputTokens: 0,
|
|
9
|
+
cacheReadTokens: 0,
|
|
10
|
+
cacheWriteTokens: 0,
|
|
11
|
+
completeCount: 0,
|
|
12
|
+
incompleteCount: 0,
|
|
13
|
+
hasIncompleteUsage: false
|
|
14
|
+
};
|
|
15
|
+
for (const usage of usages) {
|
|
16
|
+
if (usage.completeness !== "complete") {
|
|
17
|
+
totals.incompleteCount++;
|
|
18
|
+
totals.hasIncompleteUsage = true;
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
totals.completeCount++;
|
|
22
|
+
totals.inputTokens += usage.inputTokens ?? 0;
|
|
23
|
+
totals.outputTokens += usage.outputTokens ?? 0;
|
|
24
|
+
totals.cacheReadTokens += usage.cacheReadTokens ?? 0;
|
|
25
|
+
totals.cacheWriteTokens += usage.cacheWriteTokens ?? 0;
|
|
26
|
+
}
|
|
27
|
+
return totals;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/states.ts
|
|
31
|
+
var TURN_STATUSES = [
|
|
32
|
+
"queued",
|
|
33
|
+
"running",
|
|
34
|
+
"waiting_approval",
|
|
35
|
+
"waiting_child",
|
|
36
|
+
"waiting_resolution",
|
|
37
|
+
"completed",
|
|
38
|
+
"failed",
|
|
39
|
+
"cancelled"
|
|
40
|
+
];
|
|
41
|
+
var TERMINAL_TURN_STATUSES = ["completed", "failed", "cancelled"];
|
|
42
|
+
var STEP_KINDS = [
|
|
43
|
+
"model_call",
|
|
44
|
+
"tool_exec",
|
|
45
|
+
"compaction",
|
|
46
|
+
"sub_turn",
|
|
47
|
+
"steering_input"
|
|
48
|
+
];
|
|
49
|
+
var STEP_STATUSES = [
|
|
50
|
+
"pending",
|
|
51
|
+
"awaiting_approval",
|
|
52
|
+
"running",
|
|
53
|
+
"waiting_child",
|
|
54
|
+
"unknown",
|
|
55
|
+
"completed",
|
|
56
|
+
"failed",
|
|
57
|
+
"rejected",
|
|
58
|
+
"skipped",
|
|
59
|
+
"cancelled"
|
|
60
|
+
];
|
|
61
|
+
var TERMINAL_STEP_STATUSES = [
|
|
62
|
+
"completed",
|
|
63
|
+
"failed",
|
|
64
|
+
"rejected",
|
|
65
|
+
"skipped",
|
|
66
|
+
"cancelled"
|
|
67
|
+
];
|
|
68
|
+
var ATTEMPT_KINDS = ["execute", "reconcile"];
|
|
69
|
+
var ATTEMPT_STATUSES = ["running", "succeeded", "failed", "cancelled", "unknown"];
|
|
70
|
+
var STEERING_STATUSES = ["pending", "consumed"];
|
|
71
|
+
var APPROVAL_STATUSES = ["pending", "approved", "rejected"];
|
|
72
|
+
var TOOL_EFFECTS = ["none", "external"];
|
|
73
|
+
var COMMAND_KINDS = ["approve", "resolve_unknown", "cancel", "steer", "resume"];
|
|
74
|
+
function includes(values, value) {
|
|
75
|
+
return typeof value === "string" && values.includes(value);
|
|
76
|
+
}
|
|
77
|
+
var isTurnStatus = (value) => includes(TURN_STATUSES, value);
|
|
78
|
+
var isTerminalTurnStatus = (value) => includes(TERMINAL_TURN_STATUSES, value);
|
|
79
|
+
var isStepKind = (value) => includes(STEP_KINDS, value);
|
|
80
|
+
var isStepStatus = (value) => includes(STEP_STATUSES, value);
|
|
81
|
+
var isTerminalStepStatus = (value) => includes(TERMINAL_STEP_STATUSES, value);
|
|
82
|
+
var isAttemptKind = (value) => includes(ATTEMPT_KINDS, value);
|
|
83
|
+
var isAttemptStatus = (value) => includes(ATTEMPT_STATUSES, value);
|
|
84
|
+
var isSteeringStatus = (value) => includes(STEERING_STATUSES, value);
|
|
85
|
+
var isApprovalStatus = (value) => includes(APPROVAL_STATUSES, value);
|
|
86
|
+
var isToolEffect = (value) => includes(TOOL_EFFECTS, value);
|
|
87
|
+
var isCommandKind = (value) => includes(COMMAND_KINDS, value);
|
|
88
|
+
|
|
89
|
+
// src/schema.ts
|
|
90
|
+
async function validateSchemaInput(schema, input) {
|
|
91
|
+
if ("~standard" in schema) {
|
|
92
|
+
const standard = schema["~standard"];
|
|
93
|
+
if (!standard || standard.version !== 1 || typeof standard.vendor !== "string" || typeof standard.validate !== "function") {
|
|
94
|
+
throw new ToolValidationError([{ message: "Invalid Standard Schema v1 interface." }]);
|
|
95
|
+
}
|
|
96
|
+
const result = await standard.validate(input);
|
|
97
|
+
if (result.issues !== void 0) throw new ToolValidationError(result.issues);
|
|
98
|
+
return result.value;
|
|
99
|
+
}
|
|
100
|
+
assertSchema(schema, 0);
|
|
101
|
+
const issues = check(schema, input, []);
|
|
102
|
+
if (issues.length > 0) throw new ToolValidationError(issues);
|
|
103
|
+
return input;
|
|
104
|
+
}
|
|
105
|
+
var annotations = /* @__PURE__ */ new Set([
|
|
106
|
+
"$schema",
|
|
107
|
+
"$id",
|
|
108
|
+
"$comment",
|
|
109
|
+
"title",
|
|
110
|
+
"description",
|
|
111
|
+
"default",
|
|
112
|
+
"examples",
|
|
113
|
+
"readOnly",
|
|
114
|
+
"writeOnly",
|
|
115
|
+
"deprecated"
|
|
116
|
+
]);
|
|
117
|
+
var numberKeys = /* @__PURE__ */ new Set([
|
|
118
|
+
"minimum",
|
|
119
|
+
"maximum",
|
|
120
|
+
"exclusiveMinimum",
|
|
121
|
+
"exclusiveMaximum",
|
|
122
|
+
"multipleOf"
|
|
123
|
+
]);
|
|
124
|
+
var countKeys = /* @__PURE__ */ new Set([
|
|
125
|
+
"minLength",
|
|
126
|
+
"maxLength",
|
|
127
|
+
"minItems",
|
|
128
|
+
"maxItems",
|
|
129
|
+
"minProperties",
|
|
130
|
+
"maxProperties"
|
|
131
|
+
]);
|
|
132
|
+
var types = /* @__PURE__ */ new Set(["null", "boolean", "object", "array", "number", "integer", "string"]);
|
|
133
|
+
function record(value) {
|
|
134
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
135
|
+
}
|
|
136
|
+
function invalid(message) {
|
|
137
|
+
throw new ToolValidationError([{ message }]);
|
|
138
|
+
}
|
|
139
|
+
function assertSchema(schema, depth) {
|
|
140
|
+
if (depth > 100) invalid("JSON Schema nesting exceeds 100 levels or is cyclic.");
|
|
141
|
+
if (typeof schema === "boolean") return;
|
|
142
|
+
if (!record(schema)) invalid("JSON Schema must be an object or boolean subschema.");
|
|
143
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
144
|
+
if (annotations.has(key) || key === "const") continue;
|
|
145
|
+
if (numberKeys.has(key) || countKeys.has(key)) {
|
|
146
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
147
|
+
invalid(`Invalid numeric keyword ${key}.`);
|
|
148
|
+
if (countKeys.has(key) && (!Number.isInteger(value) || value < 0))
|
|
149
|
+
invalid(`Invalid count keyword ${key}.`);
|
|
150
|
+
if (key === "multipleOf" && value <= 0) invalid("multipleOf must be positive.");
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
switch (key) {
|
|
154
|
+
case "type": {
|
|
155
|
+
const names = Array.isArray(value) ? value : [value];
|
|
156
|
+
if (names.length === 0 || names.some((name) => typeof name !== "string" || !types.has(name)))
|
|
157
|
+
invalid("Invalid JSON Schema type.");
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
case "enum":
|
|
161
|
+
if (!Array.isArray(value) || value.length === 0) invalid("enum must be a nonempty array.");
|
|
162
|
+
break;
|
|
163
|
+
case "required":
|
|
164
|
+
if (!Array.isArray(value) || value.some((name) => typeof name !== "string"))
|
|
165
|
+
invalid("required must be an array of property names.");
|
|
166
|
+
break;
|
|
167
|
+
case "properties":
|
|
168
|
+
if (!record(value)) invalid("properties must be an object.");
|
|
169
|
+
for (const child of Object.values(value)) assertSchema(child, depth + 1);
|
|
170
|
+
break;
|
|
171
|
+
case "items":
|
|
172
|
+
case "additionalProperties":
|
|
173
|
+
case "not":
|
|
174
|
+
assertSchema(value, depth + 1);
|
|
175
|
+
break;
|
|
176
|
+
case "allOf":
|
|
177
|
+
case "anyOf":
|
|
178
|
+
case "oneOf":
|
|
179
|
+
if (!Array.isArray(value) || value.length === 0)
|
|
180
|
+
invalid(`${key} must be a nonempty array.`);
|
|
181
|
+
for (const child of value) assertSchema(child, depth + 1);
|
|
182
|
+
break;
|
|
183
|
+
case "pattern":
|
|
184
|
+
if (typeof value !== "string") invalid("pattern must be a string.");
|
|
185
|
+
try {
|
|
186
|
+
new RegExp(value, "u");
|
|
187
|
+
} catch {
|
|
188
|
+
invalid("Invalid JSON Schema pattern.");
|
|
189
|
+
}
|
|
190
|
+
break;
|
|
191
|
+
case "uniqueItems":
|
|
192
|
+
if (typeof value !== "boolean") invalid("uniqueItems must be boolean.");
|
|
193
|
+
break;
|
|
194
|
+
default:
|
|
195
|
+
invalid(`Unsupported JSON Schema keyword: ${key}. Use Standard Schema for this dialect.`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function equal(left, right) {
|
|
200
|
+
if (left === right) return true;
|
|
201
|
+
if (Array.isArray(left) && Array.isArray(right))
|
|
202
|
+
return left.length === right.length && left.every((value, i) => equal(value, right[i]));
|
|
203
|
+
if (record(left) && record(right)) {
|
|
204
|
+
const keys = Object.keys(left);
|
|
205
|
+
return keys.length === Object.keys(right).length && keys.every((key) => Object.hasOwn(right, key) && equal(left[key], right[key]));
|
|
206
|
+
}
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
function matchesType(type, value) {
|
|
210
|
+
switch (type) {
|
|
211
|
+
case "null":
|
|
212
|
+
return value === null;
|
|
213
|
+
case "array":
|
|
214
|
+
return Array.isArray(value);
|
|
215
|
+
case "object":
|
|
216
|
+
return record(value);
|
|
217
|
+
case "number":
|
|
218
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
219
|
+
case "integer":
|
|
220
|
+
return typeof value === "number" && Number.isInteger(value);
|
|
221
|
+
default:
|
|
222
|
+
return typeof value === type;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
function check(schema, value, path) {
|
|
226
|
+
if (schema === true) return [];
|
|
227
|
+
if (schema === false) return [{ message: "Value is forbidden.", path }];
|
|
228
|
+
const issues = [];
|
|
229
|
+
const issue = (message) => {
|
|
230
|
+
issues.push({ message, path });
|
|
231
|
+
};
|
|
232
|
+
if (schema.type !== void 0) {
|
|
233
|
+
const names = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
234
|
+
if (!names.some((name) => matchesType(name, value))) issue("Value has an invalid type.");
|
|
235
|
+
}
|
|
236
|
+
if (Object.hasOwn(schema, "const") && !equal(schema.const, value))
|
|
237
|
+
issue("Value does not match const.");
|
|
238
|
+
if (Array.isArray(schema.enum) && !schema.enum.some((item) => equal(item, value)))
|
|
239
|
+
issue("Value is not in enum.");
|
|
240
|
+
for (const keyword of ["allOf", "anyOf", "oneOf"]) {
|
|
241
|
+
const children = schema[keyword];
|
|
242
|
+
if (children) {
|
|
243
|
+
const matches = children.filter((child) => check(child, value, path).length === 0).length;
|
|
244
|
+
if (keyword === "allOf" && matches !== children.length || keyword === "anyOf" && matches === 0 || keyword === "oneOf" && matches !== 1)
|
|
245
|
+
issue(`Value failed ${keyword}.`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (schema.not !== void 0 && check(schema.not, value, path).length === 0)
|
|
249
|
+
issue("Value matches forbidden schema.");
|
|
250
|
+
if (typeof value === "number") {
|
|
251
|
+
if (!Number.isFinite(value)) issue("Number must be finite.");
|
|
252
|
+
for (const [key, violates] of [
|
|
253
|
+
["minimum", value < schema.minimum],
|
|
254
|
+
["maximum", value > schema.maximum],
|
|
255
|
+
["exclusiveMinimum", value <= schema.exclusiveMinimum],
|
|
256
|
+
["exclusiveMaximum", value >= schema.exclusiveMaximum]
|
|
257
|
+
])
|
|
258
|
+
if (schema[key] !== void 0 && violates) issue(`Number failed ${key}.`);
|
|
259
|
+
if (typeof schema.multipleOf === "number") {
|
|
260
|
+
const quotient = value / schema.multipleOf;
|
|
261
|
+
if (Math.abs(quotient - Math.round(quotient)) > Number.EPSILON * Math.max(1, Math.abs(quotient)) * 4)
|
|
262
|
+
issue("Number failed multipleOf.");
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (typeof value === "string") {
|
|
266
|
+
const length = [...value].length;
|
|
267
|
+
if (typeof schema.minLength === "number" && length < schema.minLength)
|
|
268
|
+
issue("String is too short.");
|
|
269
|
+
if (typeof schema.maxLength === "number" && length > schema.maxLength)
|
|
270
|
+
issue("String is too long.");
|
|
271
|
+
if (typeof schema.pattern === "string" && !new RegExp(schema.pattern, "u").test(value))
|
|
272
|
+
issue("String failed pattern.");
|
|
273
|
+
}
|
|
274
|
+
if (Array.isArray(value)) {
|
|
275
|
+
if (typeof schema.minItems === "number" && value.length < schema.minItems)
|
|
276
|
+
issue("Array has too few items.");
|
|
277
|
+
if (typeof schema.maxItems === "number" && value.length > schema.maxItems)
|
|
278
|
+
issue("Array has too many items.");
|
|
279
|
+
if (schema.uniqueItems === true && value.some((item, i) => value.slice(0, i).some((other) => equal(item, other))))
|
|
280
|
+
issue("Array items are not unique.");
|
|
281
|
+
if (schema.items !== void 0)
|
|
282
|
+
value.forEach(
|
|
283
|
+
(item, index) => issues.push(...check(schema.items, item, [...path, index]))
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
if (record(value)) {
|
|
287
|
+
const keys = Object.keys(value);
|
|
288
|
+
if (typeof schema.minProperties === "number" && keys.length < schema.minProperties)
|
|
289
|
+
issue("Object has too few properties.");
|
|
290
|
+
if (typeof schema.maxProperties === "number" && keys.length > schema.maxProperties)
|
|
291
|
+
issue("Object has too many properties.");
|
|
292
|
+
for (const key of schema.required ?? [])
|
|
293
|
+
if (!Object.hasOwn(value, key))
|
|
294
|
+
issues.push({ message: "Required property is missing.", path: [...path, key] });
|
|
295
|
+
const properties = schema.properties ?? {};
|
|
296
|
+
for (const key of keys) {
|
|
297
|
+
if (Object.hasOwn(properties, key))
|
|
298
|
+
issues.push(...check(properties[key], value[key], [...path, key]));
|
|
299
|
+
else if (schema.additionalProperties !== void 0)
|
|
300
|
+
issues.push(
|
|
301
|
+
...check(schema.additionalProperties, value[key], [...path, key])
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return issues;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// src/events.ts
|
|
309
|
+
var DURABLE_EVENT_TYPES = [
|
|
310
|
+
"session.created",
|
|
311
|
+
"turn.queued",
|
|
312
|
+
"turn.started",
|
|
313
|
+
"turn.paused",
|
|
314
|
+
"turn.completed",
|
|
315
|
+
"turn.failed",
|
|
316
|
+
"turn.cancelled",
|
|
317
|
+
"steering.queued",
|
|
318
|
+
"steering.applied",
|
|
319
|
+
"step.dispatched",
|
|
320
|
+
"step.approval_requested",
|
|
321
|
+
"step.approval_resolved",
|
|
322
|
+
"step.completed",
|
|
323
|
+
"step.failed",
|
|
324
|
+
"step.unknown",
|
|
325
|
+
"step.resolved",
|
|
326
|
+
"compaction.committed",
|
|
327
|
+
"sub_turn.linked",
|
|
328
|
+
"command.applied"
|
|
329
|
+
];
|
|
330
|
+
var REALTIME_EVENT_TYPES = [
|
|
331
|
+
"text.delta",
|
|
332
|
+
"reasoning.delta",
|
|
333
|
+
"tool.call.delta",
|
|
334
|
+
"tool.progress"
|
|
335
|
+
];
|
|
336
|
+
function isDurableEventType(value) {
|
|
337
|
+
return typeof value === "string" && DURABLE_EVENT_TYPES.includes(value);
|
|
338
|
+
}
|
|
339
|
+
function isRealtimeEventType(value) {
|
|
340
|
+
return typeof value === "string" && REALTIME_EVENT_TYPES.includes(value);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export { APPROVAL_STATUSES, ATTEMPT_KINDS, ATTEMPT_STATUSES, COMMAND_KINDS, DURABLE_EVENT_TYPES, REALTIME_EVENT_TYPES, STEERING_STATUSES, STEP_KINDS, STEP_STATUSES, TERMINAL_STEP_STATUSES, TERMINAL_TURN_STATUSES, TOOL_EFFECTS, TURN_STATUSES, aggregateUsageTotals, isApprovalStatus, isAttemptKind, isAttemptStatus, isCommandKind, isDurableEventType, isRealtimeEventType, isSteeringStatus, isStepKind, isStepStatus, isTerminalStepStatus, isTerminalTurnStatus, isToolEffect, isTurnStatus, validateSchemaInput };
|
|
344
|
+
//# sourceMappingURL=index.js.map
|
|
345
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/primitives.ts","../src/states.ts","../src/schema.ts","../src/events.ts"],"names":[],"mappings":";;;;AAiCO,SAAS,qBAAqB,MAAA,EAA6C;AAChF,EAAA,MAAM,MAAA,GAAsB;AAAA,IAC1B,WAAA,EAAa,CAAA;AAAA,IACb,YAAA,EAAc,CAAA;AAAA,IACd,eAAA,EAAiB,CAAA;AAAA,IACjB,gBAAA,EAAkB,CAAA;AAAA,IAClB,aAAA,EAAe,CAAA;AAAA,IACf,eAAA,EAAiB,CAAA;AAAA,IACjB,kBAAA,EAAoB;AAAA,GAC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EAAM,GAAG,CAAC,CAAC,CAAA;AAAA,WAAA,IAC3D,OAAO,oBAAA,KAAyB,MAAA;AACvC,QAAA,MAAA,CAAO,IAAA;AAAA,UACL,GAAG,KAAA,CAAM,MAAA,CAAO,oBAAA,EAA8C,KAAA,CAAM,GAAG,CAAA,EAAG,CAAC,GAAG,IAAA,EAAM,GAAG,CAAC;AAAA,SAC1F;AAAA,IACJ;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT;;;AC5QO,IAAM,mBAAA,GAAsB;AAAA,EACjC,iBAAA;AAAA,EACA,aAAA;AAAA,EACA,cAAA;AAAA,EACA,aAAA;AAAA,EACA,gBAAA;AAAA,EACA,aAAA;AAAA,EACA,gBAAA;AAAA,EACA,iBAAA;AAAA,EACA,kBAAA;AAAA,EACA,iBAAA;AAAA,EACA,yBAAA;AAAA,EACA,wBAAA;AAAA,EACA,gBAAA;AAAA,EACA,aAAA;AAAA,EACA,cAAA;AAAA,EACA,eAAA;AAAA,EACA,sBAAA;AAAA,EACA,iBAAA;AAAA,EACA;AACF;AAEO,IAAM,oBAAA,GAAuB;AAAA,EAClC,YAAA;AAAA,EACA,iBAAA;AAAA,EACA,iBAAA;AAAA,EACA;AACF;AAEO,SAAS,mBAAmB,KAAA,EAA2C;AAC5E,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,mBAAA,CAAoB,SAAS,KAAyB,CAAA;AAC5F;AACO,SAAS,oBAAoB,KAAA,EAA4C;AAC9E,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,oBAAA,CAAqB,SAAS,KAA0B,CAAA;AAC9F","file":"index.js","sourcesContent":["export interface ScopeRef {\n tenantId?: string;\n projectId?: string;\n}\n\nexport interface ArtifactRef {\n uri: string;\n sha256: string;\n byteSize: number;\n contentType: string;\n}\n\nexport type UsageCompleteness = \"complete\" | \"partial\" | \"unknown\";\nexport interface UsageMetrics {\n inputTokens: number | null;\n outputTokens: number | null;\n cacheReadTokens: number | null;\n cacheWriteTokens: number | null;\n completeness: UsageCompleteness;\n costMicros?: number | null;\n}\n\nexport interface UsageTotals {\n inputTokens: number;\n outputTokens: number;\n cacheReadTokens: number;\n cacheWriteTokens: number;\n completeCount: number;\n incompleteCount: number;\n hasIncompleteUsage: boolean;\n}\n\n/** Unknown and partial observations never contribute invented token counts. */\nexport function aggregateUsageTotals(usages: Iterable<UsageMetrics>): UsageTotals {\n const totals: UsageTotals = {\n inputTokens: 0,\n outputTokens: 0,\n cacheReadTokens: 0,\n cacheWriteTokens: 0,\n completeCount: 0,\n incompleteCount: 0,\n hasIncompleteUsage: false,\n };\n for (const usage of usages) {\n if (usage.completeness !== \"complete\") {\n totals.incompleteCount++;\n totals.hasIncompleteUsage = true;\n continue;\n }\n totals.completeCount++;\n totals.inputTokens += usage.inputTokens ?? 0;\n totals.outputTokens += usage.outputTokens ?? 0;\n totals.cacheReadTokens += usage.cacheReadTokens ?? 0;\n totals.cacheWriteTokens += usage.cacheWriteTokens ?? 0;\n }\n return totals;\n}\n\nexport interface LeaseToken {\n holderId: string;\n epoch: number;\n expiresAt: string;\n}\n\nexport interface ErrorRecord {\n code: string;\n message: string;\n reason?: string;\n}\n","export const TURN_STATUSES = [\n \"queued\",\n \"running\",\n \"waiting_approval\",\n \"waiting_child\",\n \"waiting_resolution\",\n \"completed\",\n \"failed\",\n \"cancelled\",\n] as const;\nexport type TurnStatus = (typeof TURN_STATUSES)[number];\nexport const TERMINAL_TURN_STATUSES = [\"completed\", \"failed\", \"cancelled\"] as const;\nexport type TerminalTurnStatus = (typeof TERMINAL_TURN_STATUSES)[number];\nexport const STEP_KINDS = [\n \"model_call\",\n \"tool_exec\",\n \"compaction\",\n \"sub_turn\",\n \"steering_input\",\n] as const;\nexport type StepKind = (typeof STEP_KINDS)[number];\nexport const STEP_STATUSES = [\n \"pending\",\n \"awaiting_approval\",\n \"running\",\n \"waiting_child\",\n \"unknown\",\n \"completed\",\n \"failed\",\n \"rejected\",\n \"skipped\",\n \"cancelled\",\n] as const;\nexport type StepStatus = (typeof STEP_STATUSES)[number];\nexport const TERMINAL_STEP_STATUSES = [\n \"completed\",\n \"failed\",\n \"rejected\",\n \"skipped\",\n \"cancelled\",\n] as const;\nexport type TerminalStepStatus = (typeof TERMINAL_STEP_STATUSES)[number];\nexport const ATTEMPT_KINDS = [\"execute\", \"reconcile\"] as const;\nexport type AttemptKind = (typeof ATTEMPT_KINDS)[number];\nexport const ATTEMPT_STATUSES = [\"running\", \"succeeded\", \"failed\", \"cancelled\", \"unknown\"] as const;\nexport type AttemptStatus = (typeof ATTEMPT_STATUSES)[number];\nexport const STEERING_STATUSES = [\"pending\", \"consumed\"] as const;\nexport type SteeringStatus = (typeof STEERING_STATUSES)[number];\nexport const APPROVAL_STATUSES = [\"pending\", \"approved\", \"rejected\"] as const;\nexport type ApprovalStatus = (typeof APPROVAL_STATUSES)[number];\nexport const TOOL_EFFECTS = [\"none\", \"external\"] as const;\nexport type ToolEffect = (typeof TOOL_EFFECTS)[number];\nexport const COMMAND_KINDS = [\"approve\", \"resolve_unknown\", \"cancel\", \"steer\", \"resume\"] as const;\nexport type CommandKind = (typeof COMMAND_KINDS)[number];\n\nfunction includes<T extends string>(values: readonly T[], value: unknown): value is T {\n return typeof value === \"string\" && values.includes(value as T);\n}\nexport const isTurnStatus = (value: unknown): value is TurnStatus => includes(TURN_STATUSES, value);\nexport const isTerminalTurnStatus = (value: unknown): value is TerminalTurnStatus =>\n includes(TERMINAL_TURN_STATUSES, value);\nexport const isStepKind = (value: unknown): value is StepKind => includes(STEP_KINDS, value);\nexport const isStepStatus = (value: unknown): value is StepStatus => includes(STEP_STATUSES, value);\nexport const isTerminalStepStatus = (value: unknown): value is TerminalStepStatus =>\n includes(TERMINAL_STEP_STATUSES, value);\nexport const isAttemptKind = (value: unknown): value is AttemptKind =>\n includes(ATTEMPT_KINDS, value);\nexport const isAttemptStatus = (value: unknown): value is AttemptStatus =>\n includes(ATTEMPT_STATUSES, value);\nexport const isSteeringStatus = (value: unknown): value is SteeringStatus =>\n includes(STEERING_STATUSES, value);\nexport const isApprovalStatus = (value: unknown): value is ApprovalStatus =>\n includes(APPROVAL_STATUSES, value);\nexport const isToolEffect = (value: unknown): value is ToolEffect => includes(TOOL_EFFECTS, value);\nexport const isCommandKind = (value: unknown): value is CommandKind =>\n includes(COMMAND_KINDS, value);\n","import { ToolValidationError, type SchemaIssue } from \"./errors.js\";\n\n/** Structural Standard Schema v1; works without importing a validator library. */\nexport interface StandardSchemaV1<TOutput = unknown, TInput = unknown> {\n readonly \"~standard\": {\n readonly version: 1;\n readonly vendor: string;\n readonly validate: (\n value: unknown,\n ) => StandardSchemaResult<TOutput> | Promise<StandardSchemaResult<TOutput>>;\n readonly types?: { readonly input: TInput; readonly output: TOutput };\n };\n}\nexport type StandardSchemaResult<T> =\n { readonly value: T; readonly issues?: undefined } | { readonly issues: readonly SchemaIssue[] };\nexport type JsonSchema = Readonly<Record<string, unknown>>;\nexport type SchemaInput<T = unknown> = StandardSchemaV1<T> | JsonSchema;\n\n/**\n * Returns validated/transformed input or throws ToolValidationError.\n * JSON Schema supports the documented local assertion subset. Unsupported\n * keywords and malformed schemas fail closed; use Standard Schema for a full\n * dialect implementation. No defaults, coercion, network or filesystem access.\n */\nexport async function validateSchemaInput<T>(schema: SchemaInput<T>, input: unknown): Promise<T> {\n if (\"~standard\" in schema) {\n const standard = (schema as StandardSchemaV1<T>)[\"~standard\"];\n if (\n !standard ||\n standard.version !== 1 ||\n typeof standard.vendor !== \"string\" ||\n typeof standard.validate !== \"function\"\n ) {\n throw new ToolValidationError([{ message: \"Invalid Standard Schema v1 interface.\" }]);\n }\n const result = await standard.validate(input);\n if (result.issues !== undefined) throw new ToolValidationError(result.issues);\n return result.value;\n }\n assertSchema(schema, 0);\n const issues = check(schema, input, []);\n if (issues.length > 0) throw new ToolValidationError(issues);\n return input as T;\n}\n\nconst annotations = new Set([\n \"$schema\",\n \"$id\",\n \"$comment\",\n \"title\",\n \"description\",\n \"default\",\n \"examples\",\n \"readOnly\",\n \"writeOnly\",\n \"deprecated\",\n]);\nconst numberKeys = new Set([\n \"minimum\",\n \"maximum\",\n \"exclusiveMinimum\",\n \"exclusiveMaximum\",\n \"multipleOf\",\n]);\nconst countKeys = new Set([\n \"minLength\",\n \"maxLength\",\n \"minItems\",\n \"maxItems\",\n \"minProperties\",\n \"maxProperties\",\n]);\nconst types = new Set([\"null\", \"boolean\", \"object\", \"array\", \"number\", \"integer\", \"string\"]);\n\nfunction record(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\nfunction invalid(message: string): never {\n throw new ToolValidationError([{ message }]);\n}\nfunction assertSchema(schema: unknown, depth: number): asserts schema is JsonSchema | boolean {\n if (depth > 100) invalid(\"JSON Schema nesting exceeds 100 levels or is cyclic.\");\n if (typeof schema === \"boolean\") return;\n if (!record(schema)) invalid(\"JSON Schema must be an object or boolean subschema.\");\n for (const [key, value] of Object.entries(schema)) {\n if (annotations.has(key) || key === \"const\") continue;\n if (numberKeys.has(key) || countKeys.has(key)) {\n if (typeof value !== \"number\" || !Number.isFinite(value))\n invalid(`Invalid numeric keyword ${key}.`);\n if (countKeys.has(key) && (!Number.isInteger(value) || value < 0))\n invalid(`Invalid count keyword ${key}.`);\n if (key === \"multipleOf\" && value <= 0) invalid(\"multipleOf must be positive.\");\n continue;\n }\n switch (key) {\n case \"type\": {\n const names = Array.isArray(value) ? value : [value];\n if (\n names.length === 0 ||\n names.some((name: unknown) => typeof name !== \"string\" || !types.has(name))\n )\n invalid(\"Invalid JSON Schema type.\");\n break;\n }\n case \"enum\":\n if (!Array.isArray(value) || value.length === 0) invalid(\"enum must be a nonempty array.\");\n break;\n case \"required\":\n if (!Array.isArray(value) || value.some((name: unknown) => typeof name !== \"string\"))\n invalid(\"required must be an array of property names.\");\n break;\n case \"properties\":\n if (!record(value)) invalid(\"properties must be an object.\");\n for (const child of Object.values(value)) assertSchema(child, depth + 1);\n break;\n case \"items\":\n case \"additionalProperties\":\n case \"not\":\n assertSchema(value, depth + 1);\n break;\n case \"allOf\":\n case \"anyOf\":\n case \"oneOf\":\n if (!Array.isArray(value) || value.length === 0)\n invalid(`${key} must be a nonempty array.`);\n for (const child of value) assertSchema(child, depth + 1);\n break;\n case \"pattern\":\n if (typeof value !== \"string\") invalid(\"pattern must be a string.\");\n try {\n new RegExp(value, \"u\");\n } catch {\n invalid(\"Invalid JSON Schema pattern.\");\n }\n break;\n case \"uniqueItems\":\n if (typeof value !== \"boolean\") invalid(\"uniqueItems must be boolean.\");\n break;\n default:\n invalid(`Unsupported JSON Schema keyword: ${key}. Use Standard Schema for this dialect.`);\n }\n }\n}\nfunction equal(left: unknown, right: unknown): boolean {\n if (left === right) return true;\n if (Array.isArray(left) && Array.isArray(right))\n return left.length === right.length && left.every((value, i) => equal(value, right[i]));\n if (record(left) && record(right)) {\n const keys = Object.keys(left);\n return (\n keys.length === Object.keys(right).length &&\n keys.every((key) => Object.hasOwn(right, key) && equal(left[key], right[key]))\n );\n }\n return false;\n}\nfunction matchesType(type: unknown, value: unknown): boolean {\n switch (type) {\n case \"null\":\n return value === null;\n case \"array\":\n return Array.isArray(value);\n case \"object\":\n return record(value);\n case \"number\":\n return typeof value === \"number\" && Number.isFinite(value);\n case \"integer\":\n return typeof value === \"number\" && Number.isInteger(value);\n default:\n return typeof value === type;\n }\n}\nfunction check(\n schema: JsonSchema | boolean,\n value: unknown,\n path: readonly PropertyKey[],\n): SchemaIssue[] {\n if (schema === true) return [];\n if (schema === false) return [{ message: \"Value is forbidden.\", path }];\n const issues: SchemaIssue[] = [];\n const issue = (message: string) => {\n issues.push({ message, path });\n };\n if (schema.type !== undefined) {\n const names = Array.isArray(schema.type) ? schema.type : [schema.type];\n if (!names.some((name) => matchesType(name, value))) issue(\"Value has an invalid type.\");\n }\n if (Object.hasOwn(schema, \"const\") && !equal(schema.const, value))\n issue(\"Value does not match const.\");\n if (Array.isArray(schema.enum) && !schema.enum.some((item) => equal(item, value)))\n issue(\"Value is not in enum.\");\n for (const keyword of [\"allOf\", \"anyOf\", \"oneOf\"] as const) {\n const children = schema[keyword] as (JsonSchema | boolean)[] | undefined;\n if (children) {\n const matches = children.filter((child) => check(child, value, path).length === 0).length;\n if (\n (keyword === \"allOf\" && matches !== children.length) ||\n (keyword === \"anyOf\" && matches === 0) ||\n (keyword === \"oneOf\" && matches !== 1)\n )\n issue(`Value failed ${keyword}.`);\n }\n }\n if (\n schema.not !== undefined &&\n check(schema.not as JsonSchema | boolean, value, path).length === 0\n )\n issue(\"Value matches forbidden schema.\");\n if (typeof value === \"number\") {\n if (!Number.isFinite(value)) issue(\"Number must be finite.\");\n for (const [key, violates] of [\n [\"minimum\", value < (schema.minimum as number)],\n [\"maximum\", value > (schema.maximum as number)],\n [\"exclusiveMinimum\", value <= (schema.exclusiveMinimum as number)],\n [\"exclusiveMaximum\", value >= (schema.exclusiveMaximum as number)],\n ] as const)\n if (schema[key] !== undefined && violates) issue(`Number failed ${key}.`);\n if (typeof schema.multipleOf === \"number\") {\n const quotient = value / schema.multipleOf;\n if (\n Math.abs(quotient - Math.round(quotient)) >\n Number.EPSILON * Math.max(1, Math.abs(quotient)) * 4\n )\n issue(\"Number failed multipleOf.\");\n }\n }\n if (typeof value === \"string\") {\n const length = [...value].length;\n if (typeof schema.minLength === \"number\" && length < schema.minLength)\n issue(\"String is too short.\");\n if (typeof schema.maxLength === \"number\" && length > schema.maxLength)\n issue(\"String is too long.\");\n if (typeof schema.pattern === \"string\" && !new RegExp(schema.pattern, \"u\").test(value))\n issue(\"String failed pattern.\");\n }\n if (Array.isArray(value)) {\n if (typeof schema.minItems === \"number\" && value.length < schema.minItems)\n issue(\"Array has too few items.\");\n if (typeof schema.maxItems === \"number\" && value.length > schema.maxItems)\n issue(\"Array has too many items.\");\n if (\n schema.uniqueItems === true &&\n value.some((item, i) => value.slice(0, i).some((other) => equal(item, other)))\n )\n issue(\"Array items are not unique.\");\n if (schema.items !== undefined)\n value.forEach((item, index) =>\n issues.push(...check(schema.items as JsonSchema | boolean, item, [...path, index])),\n );\n }\n if (record(value)) {\n const keys = Object.keys(value);\n if (typeof schema.minProperties === \"number\" && keys.length < schema.minProperties)\n issue(\"Object has too few properties.\");\n if (typeof schema.maxProperties === \"number\" && keys.length > schema.maxProperties)\n issue(\"Object has too many properties.\");\n for (const key of (schema.required as string[] | undefined) ?? [])\n if (!Object.hasOwn(value, key))\n issues.push({ message: \"Required property is missing.\", path: [...path, key] });\n const properties = (schema.properties ?? {}) as Record<string, JsonSchema | boolean>;\n for (const key of keys) {\n if (Object.hasOwn(properties, key))\n issues.push(...check(properties[key]!, value[key], [...path, key]));\n else if (schema.additionalProperties !== undefined)\n issues.push(\n ...check(schema.additionalProperties as JsonSchema | boolean, value[key], [...path, key]),\n );\n }\n }\n return issues;\n}\n","import type { ErrorRecord, ScopeRef, UsageMetrics } from \"./primitives.js\";\n\nexport const DURABLE_EVENT_TYPES = [\n \"session.created\",\n \"turn.queued\",\n \"turn.started\",\n \"turn.paused\",\n \"turn.completed\",\n \"turn.failed\",\n \"turn.cancelled\",\n \"steering.queued\",\n \"steering.applied\",\n \"step.dispatched\",\n \"step.approval_requested\",\n \"step.approval_resolved\",\n \"step.completed\",\n \"step.failed\",\n \"step.unknown\",\n \"step.resolved\",\n \"compaction.committed\",\n \"sub_turn.linked\",\n \"command.applied\",\n] as const;\nexport type DurableEventType = (typeof DURABLE_EVENT_TYPES)[number];\nexport const REALTIME_EVENT_TYPES = [\n \"text.delta\",\n \"reasoning.delta\",\n \"tool.call.delta\",\n \"tool.progress\",\n] as const;\nexport type RealtimeEventType = (typeof REALTIME_EVENT_TYPES)[number];\nexport function isDurableEventType(value: unknown): value is DurableEventType {\n return typeof value === \"string\" && DURABLE_EVENT_TYPES.includes(value as DurableEventType);\n}\nexport function isRealtimeEventType(value: unknown): value is RealtimeEventType {\n return typeof value === \"string\" && REALTIME_EVENT_TYPES.includes(value as RealtimeEventType);\n}\nexport interface EventCorrelation {\n readonly scope?: ScopeRef;\n readonly sessionId: string;\n readonly rootTurnId: string;\n readonly parentTurnId?: string;\n readonly turnId: string;\n readonly stepId?: string;\n readonly attemptNo?: number;\n readonly traceId: string;\n readonly spanId: string;\n readonly parentSpanId?: string;\n}\n/** Transactional facts only. Credentials must be stripped before persistence. */\nexport interface DurableRuntimeEvent extends EventCorrelation {\n readonly type: DurableEventType;\n readonly seq: number;\n readonly eventId: string;\n readonly occurredAt: string;\n readonly data?: Readonly<Record<string, unknown>>;\n}\n/** Memory only: no durable sequence or event identity, delivery may be dropped. */\nexport interface RealtimeEvent extends EventCorrelation {\n readonly type: RealtimeEventType;\n readonly occurredAt: string;\n readonly delta?: string;\n readonly message?: string;\n readonly data?: Readonly<Record<string, unknown>>;\n}\nexport interface SpanRecord extends EventCorrelation {\n readonly name: string;\n readonly startedAt: string;\n readonly endedAt: string;\n readonly status: \"ok\" | \"error\" | \"cancelled\" | \"unknown\";\n readonly usage?: UsageMetrics;\n readonly error?: ErrorRecord;\n readonly attributes?: Readonly<Record<string, unknown>>;\n}\nexport interface ObservabilityHook {\n onDurableEvent(event: DurableRuntimeEvent): void | Promise<void>;\n onRealtimeEvent?(event: RealtimeEvent): void | Promise<void>;\n onSpanEnd?(span: SpanRecord): void | Promise<void>;\n}\n"]}
|