@autumnsgrove/lyra 0.0.0-stage → 0.0.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/dist/adapters/cloudflare/index.d.ts +11 -0
- package/dist/adapters/cloudflare/index.d.ts.map +1 -0
- package/dist/adapters/cloudflare/index.js +11 -0
- package/dist/adapters/cloudflare/index.js.map +1 -0
- package/dist/adapters/cloudflare/secrets.d.ts +15 -0
- package/dist/adapters/cloudflare/secrets.d.ts.map +1 -0
- package/dist/adapters/cloudflare/secrets.js +24 -0
- package/dist/adapters/cloudflare/secrets.js.map +1 -0
- package/dist/adapters/cloudflare/storage.d.ts +43 -0
- package/dist/adapters/cloudflare/storage.d.ts.map +1 -0
- package/dist/adapters/cloudflare/storage.js +89 -0
- package/dist/adapters/cloudflare/storage.js.map +1 -0
- package/dist/adapters/cloudflare/waking.d.ts +34 -0
- package/dist/adapters/cloudflare/waking.d.ts.map +1 -0
- package/dist/adapters/cloudflare/waking.js +63 -0
- package/dist/adapters/cloudflare/waking.js.map +1 -0
- package/dist/adapters/memory/ids.d.ts +12 -0
- package/dist/adapters/memory/ids.d.ts.map +1 -0
- package/dist/adapters/memory/ids.js +20 -0
- package/dist/adapters/memory/ids.js.map +1 -0
- package/dist/adapters/memory/index.d.ts +13 -0
- package/dist/adapters/memory/index.d.ts.map +1 -0
- package/dist/adapters/memory/index.js +13 -0
- package/dist/adapters/memory/index.js.map +1 -0
- package/dist/adapters/memory/secrets.d.ts +14 -0
- package/dist/adapters/memory/secrets.d.ts.map +1 -0
- package/dist/adapters/memory/secrets.js +19 -0
- package/dist/adapters/memory/secrets.js.map +1 -0
- package/dist/adapters/memory/storage.d.ts +24 -0
- package/dist/adapters/memory/storage.d.ts.map +1 -0
- package/dist/adapters/memory/storage.js +40 -0
- package/dist/adapters/memory/storage.js.map +1 -0
- package/dist/adapters/memory/waking.d.ts +21 -0
- package/dist/adapters/memory/waking.d.ts.map +1 -0
- package/dist/adapters/memory/waking.js +29 -0
- package/dist/adapters/memory/waking.js.map +1 -0
- package/dist/core/clock.d.ts +22 -0
- package/dist/core/clock.d.ts.map +1 -0
- package/dist/core/clock.js +10 -0
- package/dist/core/clock.js.map +1 -0
- package/dist/core/conversation.d.ts +28 -0
- package/dist/core/conversation.d.ts.map +1 -0
- package/dist/core/conversation.js +9 -0
- package/dist/core/conversation.js.map +1 -0
- package/dist/core/decode-reply.d.ts +28 -0
- package/dist/core/decode-reply.d.ts.map +1 -0
- package/dist/core/decode-reply.js +158 -0
- package/dist/core/decode-reply.js.map +1 -0
- package/dist/core/define-recipe.d.ts +54 -0
- package/dist/core/define-recipe.d.ts.map +1 -0
- package/dist/core/define-recipe.js +96 -0
- package/dist/core/define-recipe.js.map +1 -0
- package/dist/core/events.d.ts +98 -0
- package/dist/core/events.d.ts.map +1 -0
- package/dist/core/events.js +14 -0
- package/dist/core/events.js.map +1 -0
- package/dist/core/execute-tools.d.ts +61 -0
- package/dist/core/execute-tools.d.ts.map +1 -0
- package/dist/core/execute-tools.js +147 -0
- package/dist/core/execute-tools.js.map +1 -0
- package/dist/core/finish.d.ts +53 -0
- package/dist/core/finish.d.ts.map +1 -0
- package/dist/core/finish.js +106 -0
- package/dist/core/finish.js.map +1 -0
- package/dist/core/handles.d.ts +34 -0
- package/dist/core/handles.d.ts.map +1 -0
- package/dist/core/handles.js +81 -0
- package/dist/core/handles.js.map +1 -0
- package/dist/core/json.d.ts +19 -0
- package/dist/core/json.d.ts.map +1 -0
- package/dist/core/json.js +41 -0
- package/dist/core/json.js.map +1 -0
- package/dist/core/limits.d.ts +53 -0
- package/dist/core/limits.d.ts.map +1 -0
- package/dist/core/limits.js +81 -0
- package/dist/core/limits.js.map +1 -0
- package/dist/core/model.d.ts +66 -0
- package/dist/core/model.d.ts.map +1 -0
- package/dist/core/model.js +10 -0
- package/dist/core/model.js.map +1 -0
- package/dist/core/recipe.d.ts +45 -0
- package/dist/core/recipe.d.ts.map +1 -0
- package/dist/core/recipe.js +102 -0
- package/dist/core/recipe.js.map +1 -0
- package/dist/core/result.d.ts +38 -0
- package/dist/core/result.d.ts.map +1 -0
- package/dist/core/result.js +35 -0
- package/dist/core/result.js.map +1 -0
- package/dist/core/resume.d.ts +71 -0
- package/dist/core/resume.d.ts.map +1 -0
- package/dist/core/resume.js +133 -0
- package/dist/core/resume.js.map +1 -0
- package/dist/core/run-handle.d.ts +39 -0
- package/dist/core/run-handle.d.ts.map +1 -0
- package/dist/core/run-handle.js +101 -0
- package/dist/core/run-handle.js.map +1 -0
- package/dist/core/run.d.ts +136 -0
- package/dist/core/run.d.ts.map +1 -0
- package/dist/core/run.js +1095 -0
- package/dist/core/run.js.map +1 -0
- package/dist/core/runtime.d.ts +81 -0
- package/dist/core/runtime.d.ts.map +1 -0
- package/dist/core/runtime.js +201 -0
- package/dist/core/runtime.js.map +1 -0
- package/dist/core/schema.d.ts +119 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js +469 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/slots.d.ts +32 -0
- package/dist/core/slots.d.ts.map +1 -0
- package/dist/core/slots.js +10 -0
- package/dist/core/slots.js.map +1 -0
- package/dist/core/state.d.ts +18 -0
- package/dist/core/state.d.ts.map +1 -0
- package/dist/core/state.js +53 -0
- package/dist/core/state.js.map +1 -0
- package/dist/core/system-clock.d.ts +17 -0
- package/dist/core/system-clock.d.ts.map +1 -0
- package/dist/core/system-clock.js +59 -0
- package/dist/core/system-clock.js.map +1 -0
- package/dist/core/tool.d.ts +74 -0
- package/dist/core/tool.d.ts.map +1 -0
- package/dist/core/tool.js +48 -0
- package/dist/core/tool.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/record/entries.d.ts +152 -0
- package/dist/record/entries.d.ts.map +1 -0
- package/dist/record/entries.js +497 -0
- package/dist/record/entries.js.map +1 -0
- package/dist/record/load.d.ts +29 -0
- package/dist/record/load.d.ts.map +1 -0
- package/dist/record/load.js +106 -0
- package/dist/record/load.js.map +1 -0
- package/dist/record/replay.d.ts +16 -0
- package/dist/record/replay.d.ts.map +1 -0
- package/dist/record/replay.js +63 -0
- package/dist/record/replay.js.map +1 -0
- package/dist/record/truncate.d.ts +25 -0
- package/dist/record/truncate.d.ts.map +1 -0
- package/dist/record/truncate.js +167 -0
- package/dist/record/truncate.js.map +1 -0
- package/dist/testkit/clock.d.ts +19 -0
- package/dist/testkit/clock.d.ts.map +1 -0
- package/dist/testkit/clock.js +77 -0
- package/dist/testkit/clock.js.map +1 -0
- package/dist/testkit/crashing-storage.d.ts +23 -0
- package/dist/testkit/crashing-storage.d.ts.map +1 -0
- package/dist/testkit/crashing-storage.js +39 -0
- package/dist/testkit/crashing-storage.js.map +1 -0
- package/dist/testkit/index.d.ts +15 -0
- package/dist/testkit/index.d.ts.map +1 -0
- package/dist/testkit/index.js +15 -0
- package/dist/testkit/index.js.map +1 -0
- package/dist/testkit/model.d.ts +53 -0
- package/dist/testkit/model.d.ts.map +1 -0
- package/dist/testkit/model.js +80 -0
- package/dist/testkit/model.js.map +1 -0
- package/dist/testkit/scenario.d.ts +55 -0
- package/dist/testkit/scenario.d.ts.map +1 -0
- package/dist/testkit/scenario.js +505 -0
- package/dist/testkit/scenario.js.map +1 -0
- package/dist/testkit/storage.d.ts +18 -0
- package/dist/testkit/storage.d.ts.map +1 -0
- package/dist/testkit/storage.js +27 -0
- package/dist/testkit/storage.js.map +1 -0
- package/dist/testkit/timeline-recipe.d.ts +59 -0
- package/dist/testkit/timeline-recipe.d.ts.map +1 -0
- package/dist/testkit/timeline-recipe.js +322 -0
- package/dist/testkit/timeline-recipe.js.map +1 -0
- package/dist/testkit/tools.d.ts +47 -0
- package/dist/testkit/tools.d.ts.map +1 -0
- package/dist/testkit/tools.js +82 -0
- package/dist/testkit/tools.js.map +1 -0
- package/package.json +42 -5
- package/README.md +0 -3
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The JSON Schema subset a tool's arguments are checked against
|
|
3
|
+
* (docs/recipes-and-tools.md, SCH01 to SCH20; decision 111).
|
|
4
|
+
*
|
|
5
|
+
* A tool's `parameters` is one piece of data doing three jobs: what the model is
|
|
6
|
+
* shown, what the tool-set hash covers, and what its arguments are checked against.
|
|
7
|
+
* Keeping it plain JSON Schema means there is one source of truth and no library
|
|
8
|
+
* holding a second copy to drift from it.
|
|
9
|
+
*
|
|
10
|
+
* The subset is deliberately small. There is no `pattern`, because a regular
|
|
11
|
+
* expression written by a tool author is a denial-of-service door on hostile
|
|
12
|
+
* input, and no `$ref` or `oneOf`, because a flat schema is enough for tool
|
|
13
|
+
* arguments. A keyword this build does not understand is refused when the schema is
|
|
14
|
+
* compiled, so a tool author hears about it on the first run rather than never.
|
|
15
|
+
*
|
|
16
|
+
* Everything here is a pure function over data. A hostile schema is refused with
|
|
17
|
+
* `SchemaDefinitionError` (a programming error, at definition time), and a hostile
|
|
18
|
+
* value is refused with errors, never an exception: the value comes from a model,
|
|
19
|
+
* so that path is a boundary (decision 21).
|
|
20
|
+
*/
|
|
21
|
+
import { isJsonValue, isPlainObject } from "./json.js";
|
|
22
|
+
import { canonicalJson } from "./recipe.js";
|
|
23
|
+
/** A schema nested deeper than this is a mistake or an attack, not a tool. */
|
|
24
|
+
export const MAX_SCHEMA_DEPTH = 32;
|
|
25
|
+
/** Arguments nested deeper than this are refused before anything looks at them. */
|
|
26
|
+
export const MAX_VALUE_DEPTH = 32;
|
|
27
|
+
/** The most errors one refusal lists, so a message stays a message. */
|
|
28
|
+
export const MAX_ERRORS = 10;
|
|
29
|
+
/** The most characters one formatted refusal may carry. */
|
|
30
|
+
export const MAX_MESSAGE_LENGTH = 2048;
|
|
31
|
+
export class SchemaDefinitionError extends Error {
|
|
32
|
+
name = "SchemaDefinitionError";
|
|
33
|
+
}
|
|
34
|
+
const SCHEMA_TYPES = [
|
|
35
|
+
"object",
|
|
36
|
+
"string",
|
|
37
|
+
"number",
|
|
38
|
+
"integer",
|
|
39
|
+
"boolean",
|
|
40
|
+
"array",
|
|
41
|
+
"null",
|
|
42
|
+
];
|
|
43
|
+
function isSchemaType(value) {
|
|
44
|
+
return SCHEMA_TYPES.some((known) => known === value);
|
|
45
|
+
}
|
|
46
|
+
/** Every keyword this build understands. Anything else is refused. */
|
|
47
|
+
const KNOWN_KEYWORDS = new Set([
|
|
48
|
+
"type",
|
|
49
|
+
"properties",
|
|
50
|
+
"required",
|
|
51
|
+
"additionalProperties",
|
|
52
|
+
"enum",
|
|
53
|
+
"items",
|
|
54
|
+
"minItems",
|
|
55
|
+
"maxItems",
|
|
56
|
+
"minLength",
|
|
57
|
+
"maxLength",
|
|
58
|
+
"minimum",
|
|
59
|
+
"maximum",
|
|
60
|
+
]);
|
|
61
|
+
function definitionError(message) {
|
|
62
|
+
throw new SchemaDefinitionError(message);
|
|
63
|
+
}
|
|
64
|
+
function hasOwn(value, key) {
|
|
65
|
+
return Object.prototype.hasOwnProperty.call(value, key);
|
|
66
|
+
}
|
|
67
|
+
function requireObject(value, where) {
|
|
68
|
+
if (!isPlainObject(value)) {
|
|
69
|
+
definitionError(`${where} is not an object`);
|
|
70
|
+
}
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
function optionalCount(schema, key, where) {
|
|
74
|
+
const value = schema[key];
|
|
75
|
+
if (value === undefined) {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
|
|
79
|
+
definitionError(`${where}.${key} must be a whole number of zero or more`);
|
|
80
|
+
}
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
function optionalNumber(schema, key, where) {
|
|
84
|
+
const value = schema[key];
|
|
85
|
+
if (value === undefined) {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
89
|
+
definitionError(`${where}.${key} must be a number`);
|
|
90
|
+
}
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
93
|
+
function enumValues(schema, where) {
|
|
94
|
+
const value = schema["enum"];
|
|
95
|
+
if (value === undefined) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
99
|
+
definitionError(`${where}.enum must be a non-empty list`);
|
|
100
|
+
}
|
|
101
|
+
for (const [index, member] of value.entries()) {
|
|
102
|
+
if (!isJsonValue(member)) {
|
|
103
|
+
definitionError(`${where}.enum[${index}] is not JSON`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
function checkBounds(lower, upper, where, what) {
|
|
109
|
+
if (lower !== undefined && upper !== undefined && lower > upper) {
|
|
110
|
+
definitionError(`${where}.${what} is a range that can never match`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** Every keyword a compiled kind may carry. A keyword on the wrong kind is a mistake. */
|
|
114
|
+
function rejectInapplicable(schema, where, allowed) {
|
|
115
|
+
for (const key of Object.keys(schema)) {
|
|
116
|
+
if (!allowed.includes(key)) {
|
|
117
|
+
definitionError(`${where}.${key} does not apply to a ${String(schema["type"])}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function compileAt(schema, where, depth) {
|
|
122
|
+
if (depth > MAX_SCHEMA_DEPTH) {
|
|
123
|
+
definitionError(`${where} is nested deeper than ${MAX_SCHEMA_DEPTH} levels`);
|
|
124
|
+
}
|
|
125
|
+
const object = requireObject(schema, where);
|
|
126
|
+
for (const key of Object.keys(object)) {
|
|
127
|
+
if (!KNOWN_KEYWORDS.has(key)) {
|
|
128
|
+
definitionError(`${where} uses the unsupported keyword "${key}"`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const type = object["type"];
|
|
132
|
+
const values = enumValues(object, where);
|
|
133
|
+
if (type === undefined) {
|
|
134
|
+
if (values === undefined) {
|
|
135
|
+
definitionError(`${where} needs a "type" or an "enum"`);
|
|
136
|
+
}
|
|
137
|
+
rejectInapplicable(object, where, ["enum"]);
|
|
138
|
+
return { kind: "enum", values };
|
|
139
|
+
}
|
|
140
|
+
if (!isSchemaType(type)) {
|
|
141
|
+
definitionError(`${where}.type must be one of ${SCHEMA_TYPES.join(", ")}`);
|
|
142
|
+
}
|
|
143
|
+
switch (type) {
|
|
144
|
+
case "string": {
|
|
145
|
+
rejectInapplicable(object, where, ["type", "enum", "minLength", "maxLength"]);
|
|
146
|
+
const minLength = optionalCount(object, "minLength", where);
|
|
147
|
+
const maxLength = optionalCount(object, "maxLength", where);
|
|
148
|
+
checkBounds(minLength, maxLength, where, "minLength/maxLength");
|
|
149
|
+
const allowed = values === undefined ? undefined : asStrings(values, where);
|
|
150
|
+
return { kind: "string", allowed, minLength, maxLength };
|
|
151
|
+
}
|
|
152
|
+
case "number":
|
|
153
|
+
case "integer": {
|
|
154
|
+
rejectInapplicable(object, where, ["type", "enum", "minimum", "maximum"]);
|
|
155
|
+
const minimum = optionalNumber(object, "minimum", where);
|
|
156
|
+
const maximum = optionalNumber(object, "maximum", where);
|
|
157
|
+
checkBounds(minimum, maximum, where, "minimum/maximum");
|
|
158
|
+
const integer = type === "integer";
|
|
159
|
+
const allowed = values === undefined ? undefined : asNumbers(values, integer, where);
|
|
160
|
+
return { kind: "number", integer, allowed, minimum, maximum };
|
|
161
|
+
}
|
|
162
|
+
case "boolean": {
|
|
163
|
+
rejectInapplicable(object, where, ["type", "enum"]);
|
|
164
|
+
const allowed = values === undefined ? undefined : asBooleans(values, where);
|
|
165
|
+
return { kind: "boolean", allowed };
|
|
166
|
+
}
|
|
167
|
+
case "null": {
|
|
168
|
+
rejectInapplicable(object, where, ["type"]);
|
|
169
|
+
return { kind: "null" };
|
|
170
|
+
}
|
|
171
|
+
case "array": {
|
|
172
|
+
rejectInapplicable(object, where, ["type", "enum", "items", "minItems", "maxItems"]);
|
|
173
|
+
const rawItems = object["items"];
|
|
174
|
+
const items = rawItems === undefined
|
|
175
|
+
? undefined
|
|
176
|
+
: compileAt(rawItems, `${where}.items`, depth + 1);
|
|
177
|
+
const minItems = optionalCount(object, "minItems", where);
|
|
178
|
+
const maxItems = optionalCount(object, "maxItems", where);
|
|
179
|
+
checkBounds(minItems, maxItems, where, "minItems/maxItems");
|
|
180
|
+
if (values !== undefined) {
|
|
181
|
+
for (const [index, member] of values.entries()) {
|
|
182
|
+
if (!Array.isArray(member)) {
|
|
183
|
+
definitionError(`${where}.enum[${index}] is not an array`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return { kind: "array", allowed: values, items, minItems, maxItems };
|
|
188
|
+
}
|
|
189
|
+
case "object": {
|
|
190
|
+
rejectInapplicable(object, where, [
|
|
191
|
+
"type",
|
|
192
|
+
"properties",
|
|
193
|
+
"required",
|
|
194
|
+
"additionalProperties",
|
|
195
|
+
]);
|
|
196
|
+
if (values !== undefined) {
|
|
197
|
+
definitionError(`${where}.enum is not supported on an object`);
|
|
198
|
+
}
|
|
199
|
+
const rawProperties = object["properties"];
|
|
200
|
+
const properties = new Map();
|
|
201
|
+
if (rawProperties !== undefined) {
|
|
202
|
+
const declared = requireObject(rawProperties, `${where}.properties`);
|
|
203
|
+
for (const [name, child] of Object.entries(declared)) {
|
|
204
|
+
properties.set(name, compileAt(child, `${where}.properties.${name}`, depth + 1));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const rawRequired = object["required"];
|
|
208
|
+
const required = [];
|
|
209
|
+
if (rawRequired !== undefined) {
|
|
210
|
+
if (!Array.isArray(rawRequired)) {
|
|
211
|
+
definitionError(`${where}.required must be a list of property names`);
|
|
212
|
+
}
|
|
213
|
+
for (const name of rawRequired) {
|
|
214
|
+
if (typeof name !== "string") {
|
|
215
|
+
definitionError(`${where}.required must be a list of property names`);
|
|
216
|
+
}
|
|
217
|
+
if (!properties.has(name)) {
|
|
218
|
+
definitionError(`${where}.required names "${name}", which ${where}.properties does not declare`);
|
|
219
|
+
}
|
|
220
|
+
if (!required.includes(name)) {
|
|
221
|
+
required.push(name);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const rawAdditional = object["additionalProperties"];
|
|
226
|
+
if (rawAdditional !== undefined && typeof rawAdditional !== "boolean") {
|
|
227
|
+
definitionError(`${where}.additionalProperties must be true or false`);
|
|
228
|
+
}
|
|
229
|
+
return {
|
|
230
|
+
kind: "object",
|
|
231
|
+
properties,
|
|
232
|
+
required,
|
|
233
|
+
additional: rawAdditional === true,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function asStrings(values, where) {
|
|
239
|
+
return values.map((value, index) => {
|
|
240
|
+
if (typeof value !== "string") {
|
|
241
|
+
definitionError(`${where}.enum[${index}] is not a string`);
|
|
242
|
+
}
|
|
243
|
+
return value;
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
function asNumbers(values, integer, where) {
|
|
247
|
+
return values.map((value, index) => {
|
|
248
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
249
|
+
definitionError(`${where}.enum[${index}] is not a number`);
|
|
250
|
+
}
|
|
251
|
+
if (integer && !Number.isInteger(value)) {
|
|
252
|
+
definitionError(`${where}.enum[${index}] is not a whole number`);
|
|
253
|
+
}
|
|
254
|
+
return value;
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function asBooleans(values, where) {
|
|
258
|
+
return values.map((value, index) => {
|
|
259
|
+
if (typeof value !== "boolean") {
|
|
260
|
+
definitionError(`${where}.enum[${index}] is not a boolean`);
|
|
261
|
+
}
|
|
262
|
+
return value;
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
/** Compile a tool's parameters, or throw the definition error that says what is wrong. */
|
|
266
|
+
export function compileSchema(schema, where = "parameters") {
|
|
267
|
+
return compileAt(schema, where, 0);
|
|
268
|
+
}
|
|
269
|
+
/** How a value is named in a message. A value of the wrong shape is never quoted back. */
|
|
270
|
+
function describe(value) {
|
|
271
|
+
if (value === null) {
|
|
272
|
+
return "null";
|
|
273
|
+
}
|
|
274
|
+
if (Array.isArray(value)) {
|
|
275
|
+
return "array";
|
|
276
|
+
}
|
|
277
|
+
return typeof value;
|
|
278
|
+
}
|
|
279
|
+
const MAX_QUOTED = 60;
|
|
280
|
+
function quote(value) {
|
|
281
|
+
const text = JSON.stringify(value) ?? "null";
|
|
282
|
+
return text.length <= MAX_QUOTED ? text : `${text.slice(0, MAX_QUOTED)}...`;
|
|
283
|
+
}
|
|
284
|
+
function childPath(path, key) {
|
|
285
|
+
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? `${path}.${key}` : `${path}[${quote(key)}]`;
|
|
286
|
+
}
|
|
287
|
+
function allowedList(names) {
|
|
288
|
+
const shown = names.slice(0, 20).join(", ");
|
|
289
|
+
return shown === names.join(", ") ? shown : `${shown}, ...`;
|
|
290
|
+
}
|
|
291
|
+
function push(errors, message) {
|
|
292
|
+
if (errors.length < MAX_ERRORS) {
|
|
293
|
+
errors.push(message);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
function wrongType(errors, path, expected, value) {
|
|
297
|
+
push(errors, `${path}: expected ${expected}, got ${describe(value)}`);
|
|
298
|
+
}
|
|
299
|
+
function validateAt(schema, value, path, errors) {
|
|
300
|
+
if (errors.length >= MAX_ERRORS) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
switch (schema.kind) {
|
|
304
|
+
case "enum": {
|
|
305
|
+
const match = isJsonValue(value)
|
|
306
|
+
? schema.values.some((member) => canonicalJson(member) === canonicalJson(value))
|
|
307
|
+
: false;
|
|
308
|
+
if (!match) {
|
|
309
|
+
const got = isJsonValue(value) ? quote(value) : describe(value);
|
|
310
|
+
push(errors, `${path}: expected one of ${schema.values.map(quote).join(", ")}, got ${got}`);
|
|
311
|
+
}
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
case "string": {
|
|
315
|
+
if (typeof value !== "string") {
|
|
316
|
+
return wrongType(errors, path, "string", value);
|
|
317
|
+
}
|
|
318
|
+
if (schema.allowed !== undefined && !schema.allowed.includes(value)) {
|
|
319
|
+
push(errors, `${path}: expected one of ${schema.allowed.map(quote).join(", ")}, got ${quote(value)}`);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (schema.minLength !== undefined && value.length < schema.minLength) {
|
|
323
|
+
push(errors, `${path}: expected at least ${schema.minLength} characters, got ${value.length}`);
|
|
324
|
+
}
|
|
325
|
+
if (schema.maxLength !== undefined && value.length > schema.maxLength) {
|
|
326
|
+
push(errors, `${path}: expected at most ${schema.maxLength} characters, got ${value.length}`);
|
|
327
|
+
}
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
case "number": {
|
|
331
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
332
|
+
return wrongType(errors, path, schema.integer ? "integer" : "number", value);
|
|
333
|
+
}
|
|
334
|
+
if (schema.integer && !Number.isInteger(value)) {
|
|
335
|
+
return wrongType(errors, path, "integer", value);
|
|
336
|
+
}
|
|
337
|
+
if (schema.allowed !== undefined && !schema.allowed.includes(value)) {
|
|
338
|
+
push(errors, `${path}: expected one of ${schema.allowed.join(", ")}, got ${value}`);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (schema.minimum !== undefined && value < schema.minimum) {
|
|
342
|
+
push(errors, `${path}: expected at least ${schema.minimum}, got ${value}`);
|
|
343
|
+
}
|
|
344
|
+
if (schema.maximum !== undefined && value > schema.maximum) {
|
|
345
|
+
push(errors, `${path}: expected at most ${schema.maximum}, got ${value}`);
|
|
346
|
+
}
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
case "boolean": {
|
|
350
|
+
if (typeof value !== "boolean") {
|
|
351
|
+
return wrongType(errors, path, "boolean", value);
|
|
352
|
+
}
|
|
353
|
+
if (schema.allowed !== undefined && !schema.allowed.includes(value)) {
|
|
354
|
+
push(errors, `${path}: expected one of ${schema.allowed.join(", ")}, got ${value}`);
|
|
355
|
+
}
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
case "null": {
|
|
359
|
+
if (value !== null) {
|
|
360
|
+
return wrongType(errors, path, "null", value);
|
|
361
|
+
}
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
case "array": {
|
|
365
|
+
if (!Array.isArray(value)) {
|
|
366
|
+
return wrongType(errors, path, "array", value);
|
|
367
|
+
}
|
|
368
|
+
if (schema.allowed !== undefined) {
|
|
369
|
+
const match = schema.allowed.some((member) => canonicalJson(member) === canonicalJson(value));
|
|
370
|
+
if (!match) {
|
|
371
|
+
push(errors, `${path}: not one of the allowed arrays`);
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (schema.minItems !== undefined && value.length < schema.minItems) {
|
|
376
|
+
push(errors, `${path}: expected at least ${schema.minItems} items, got ${value.length}`);
|
|
377
|
+
}
|
|
378
|
+
if (schema.maxItems !== undefined && value.length > schema.maxItems) {
|
|
379
|
+
push(errors, `${path}: expected at most ${schema.maxItems} items, got ${value.length}`);
|
|
380
|
+
}
|
|
381
|
+
const items = schema.items;
|
|
382
|
+
if (items === undefined) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
for (const [index, item] of value.entries()) {
|
|
386
|
+
if (errors.length >= MAX_ERRORS) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
validateAt(items, item, `${path}[${index}]`, errors);
|
|
390
|
+
}
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
case "object": {
|
|
394
|
+
if (!isPlainObject(value)) {
|
|
395
|
+
return wrongType(errors, path, "object", value);
|
|
396
|
+
}
|
|
397
|
+
for (const name of schema.required) {
|
|
398
|
+
if (!hasOwn(value, name)) {
|
|
399
|
+
push(errors, `${childPath(path, name)}: required`);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
for (const [name, child] of schema.properties) {
|
|
403
|
+
if (hasOwn(value, name)) {
|
|
404
|
+
validateAt(child, value[name], childPath(path, name), errors);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
if (!schema.additional) {
|
|
408
|
+
const names = [...schema.properties.keys()];
|
|
409
|
+
for (const name of Object.keys(value)) {
|
|
410
|
+
if (!schema.properties.has(name)) {
|
|
411
|
+
push(errors, `${childPath(path, name)}: not allowed (${names.length === 0
|
|
412
|
+
? "no arguments are expected"
|
|
413
|
+
: `allowed: ${allowedList(names)}`})`);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
/** Anything nested past the cap is refused outright, before a schema descends into it. */
|
|
421
|
+
function exceedsDepth(value) {
|
|
422
|
+
const stack = [{ value, depth: 1 }];
|
|
423
|
+
while (stack.length > 0) {
|
|
424
|
+
const item = stack.pop();
|
|
425
|
+
if (item === undefined) {
|
|
426
|
+
break;
|
|
427
|
+
}
|
|
428
|
+
if (item.depth > MAX_VALUE_DEPTH) {
|
|
429
|
+
return true;
|
|
430
|
+
}
|
|
431
|
+
if (Array.isArray(item.value)) {
|
|
432
|
+
for (const child of item.value) {
|
|
433
|
+
stack.push({ value: child, depth: item.depth + 1 });
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
else if (isPlainObject(item.value)) {
|
|
437
|
+
for (const child of Object.values(item.value)) {
|
|
438
|
+
stack.push({ value: child, depth: item.depth + 1 });
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
/** Check a value against a compiled schema. It never throws, whatever the value is. */
|
|
445
|
+
export function validateValue(schema, value, path = "arguments") {
|
|
446
|
+
if (exceedsDepth(value)) {
|
|
447
|
+
return {
|
|
448
|
+
ok: false,
|
|
449
|
+
errors: [`${path}: nested deeper than ${MAX_VALUE_DEPTH} levels`],
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
const errors = [];
|
|
453
|
+
validateAt(schema, value, path, errors);
|
|
454
|
+
if (errors.length > 0) {
|
|
455
|
+
return { ok: false, errors };
|
|
456
|
+
}
|
|
457
|
+
// The one cast in the validator: everything above has checked the value against
|
|
458
|
+
// the same subset the inferred type describes, so this is a claim, not a guess.
|
|
459
|
+
return { ok: true, value: value };
|
|
460
|
+
}
|
|
461
|
+
/** The message the model reads: stable, specific, and never longer than the cap. */
|
|
462
|
+
export function formatErrors(errors, prefix = "invalid arguments") {
|
|
463
|
+
const text = `${prefix}: ${errors.join("; ")}`;
|
|
464
|
+
if (text.length <= MAX_MESSAGE_LENGTH) {
|
|
465
|
+
return text;
|
|
466
|
+
}
|
|
467
|
+
return `${text.slice(0, MAX_MESSAGE_LENGTH - 3)}...`;
|
|
468
|
+
}
|
|
469
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/core/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,WAAW,EAAE,aAAa,EAAkB,MAAM,WAAW,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,8EAA8E;AAC9E,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAEnC,mFAAmF;AACnF,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAElC,uEAAuE;AACvE,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAC;AAE7B,2DAA2D;AAC3D,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEvC,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC7B,IAAI,GAAG,uBAAuB,CAAC;CACjD;AAID,MAAM,YAAY,GAA0B;IAC3C,QAAQ;IACR,QAAQ;IACR,QAAQ;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ACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,aAAa,CAC5B,MAAsB,EACtB,KAAc,EACd,IAAI,GAAG,WAAW;IAElB,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO;YACN,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,CAAC,GAAG,IAAI,wBAAwB,eAAe,SAAS,CAAC;SACjE,CAAC;IACH,CAAC;IACD,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACxC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAC9B,CAAC;IACD,gFAAgF;IAChF,gFAAgF;IAChF,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAU,EAAE,CAAC;AACxC,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,YAAY,CAAC,MAAyB,EAAE,MAAM,GAAG,mBAAmB;IACnF,MAAM,IAAI,GAAG,GAAG,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAC/C,IAAI,IAAI,CAAC,MAAM,IAAI,kBAAkB,EAAE,CAAC;QACvC,OAAO,IAAI,CAAC;IACb,CAAC;IACD,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage, secrets and waking: the three slots a host fills (decision 12).
|
|
3
|
+
*
|
|
4
|
+
* Storage deals in JSON lines rather than objects, so the core owns encoding
|
|
5
|
+
* and decoding and everything crossing the boundary is validated in one place
|
|
6
|
+
* (docs/implementation/01-core-with-fakes.md, "Storage deals in lines").
|
|
7
|
+
* Adapters stay dumb: save this line, read every line back.
|
|
8
|
+
*/
|
|
9
|
+
import type { Result } from "./result.js";
|
|
10
|
+
export interface StorageSlot {
|
|
11
|
+
/**
|
|
12
|
+
* The adapter's own limit for one saved line, in bytes, when it has one. The
|
|
13
|
+
* record's cap is always the smaller of this and its own (decision 90), so a
|
|
14
|
+
* truncation the core does is one the adapter will accept.
|
|
15
|
+
*/
|
|
16
|
+
readonly maxEntryBytes?: number;
|
|
17
|
+
/** Append one line. The returned `seq` is its zero-based position. */
|
|
18
|
+
append(line: string): Promise<Result<{
|
|
19
|
+
seq: number;
|
|
20
|
+
}>>;
|
|
21
|
+
/** Every line, in the order it was saved, exactly as saved. */
|
|
22
|
+
read(): Promise<Result<string[]>>;
|
|
23
|
+
}
|
|
24
|
+
export interface SecretsSlot {
|
|
25
|
+
/** A key by name, or nothing when it is not held. A tool never sees the rest. */
|
|
26
|
+
get(name: string): Promise<string | undefined>;
|
|
27
|
+
}
|
|
28
|
+
export interface WakingSlot {
|
|
29
|
+
schedule(runId: string, atMs: number): Promise<void>;
|
|
30
|
+
cancel(runId: string): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=slots.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slots.d.ts","sourceRoot":"","sources":["../../src/core/slots.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,WAAW,WAAW;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,sEAAsE;IACtE,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;IACvD,+DAA+D;IAC/D,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,WAAW;IAC3B,iFAAiF;IACjF,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CAC/C;AAED,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage, secrets and waking: the three slots a host fills (decision 12).
|
|
3
|
+
*
|
|
4
|
+
* Storage deals in JSON lines rather than objects, so the core owns encoding
|
|
5
|
+
* and decoding and everything crossing the boundary is validated in one place
|
|
6
|
+
* (docs/implementation/01-core-with-fakes.md, "Storage deals in lines").
|
|
7
|
+
* Adapters stay dumb: save this line, read every line back.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=slots.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slots.js","sourceRoot":"","sources":["../../src/core/slots.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rebuilding a recipe's state from the record (docs/recipes-and-tools.md, TOL07 to
|
|
3
|
+
* TOL11; decision 112).
|
|
4
|
+
*
|
|
5
|
+
* The record is the only place a run's progress lives (decision 32), and a run's
|
|
6
|
+
* state is what its tools build as it goes: the page, and the handle table that
|
|
7
|
+
* names real commits. A resume therefore runs the recipe's `setup` again and then
|
|
8
|
+
* walks the saved results in order, handing each one to its tool's `apply`. That is
|
|
9
|
+
* the same call a live run makes after a successful execute, so there is one code
|
|
10
|
+
* path and live and replayed state cannot drift.
|
|
11
|
+
*
|
|
12
|
+
* A result that is an error never changed anything, so it is skipped; so is a call
|
|
13
|
+
* whose arguments the tool's own schema refuses, because the live run never ran it.
|
|
14
|
+
*/
|
|
15
|
+
import type { RecordEntry } from "../record/entries.js";
|
|
16
|
+
import type { Tool } from "./tool.js";
|
|
17
|
+
export declare function replayState<S>(initial: S, entries: readonly RecordEntry[], tools: ReadonlyMap<string, Tool>): S;
|
|
18
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/core/state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,KAAK,EAAE,IAAI,EAAe,MAAM,WAAW,CAAC;AAEnD,wBAAgB,WAAW,CAAC,CAAC,EAC5B,OAAO,EAAE,CAAC,EACV,OAAO,EAAE,SAAS,WAAW,EAAE,EAC/B,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,GAC9B,CAAC,CAoCH"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rebuilding a recipe's state from the record (docs/recipes-and-tools.md, TOL07 to
|
|
3
|
+
* TOL11; decision 112).
|
|
4
|
+
*
|
|
5
|
+
* The record is the only place a run's progress lives (decision 32), and a run's
|
|
6
|
+
* state is what its tools build as it goes: the page, and the handle table that
|
|
7
|
+
* names real commits. A resume therefore runs the recipe's `setup` again and then
|
|
8
|
+
* walks the saved results in order, handing each one to its tool's `apply`. That is
|
|
9
|
+
* the same call a live run makes after a successful execute, so there is one code
|
|
10
|
+
* path and live and replayed state cannot drift.
|
|
11
|
+
*
|
|
12
|
+
* A result that is an error never changed anything, so it is skipped; so is a call
|
|
13
|
+
* whose arguments the tool's own schema refuses, because the live run never ran it.
|
|
14
|
+
*/
|
|
15
|
+
import { activePath } from "../record/replay.js";
|
|
16
|
+
import { usableArguments } from "./execute-tools.js";
|
|
17
|
+
export function replayState(initial, entries, tools) {
|
|
18
|
+
let state = initial;
|
|
19
|
+
/** The calls of the assistant turns seen so far, by id, so a result finds its own. */
|
|
20
|
+
const calls = new Map();
|
|
21
|
+
for (const entry of activePath(entries)) {
|
|
22
|
+
if (entry.type === "assistant_message") {
|
|
23
|
+
for (const call of entry.toolCalls) {
|
|
24
|
+
calls.set(call.id, { name: call.name, arguments: call.arguments });
|
|
25
|
+
}
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (entry.type !== "tool_message" || entry.isError) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const call = calls.get(entry.toolCallId);
|
|
32
|
+
if (call === undefined) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const tool = tools.get(call.name);
|
|
36
|
+
if (tool?.apply === undefined) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const args = usableArguments(tool, call.arguments);
|
|
40
|
+
if (!args.ok) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const outcome = { isError: false, content: entry.content };
|
|
44
|
+
if (entry.details !== undefined) {
|
|
45
|
+
outcome.details = entry.details;
|
|
46
|
+
}
|
|
47
|
+
// The recipe's own `apply` returns its own state type; this is the seam where
|
|
48
|
+
// the core, which does not know that type, carries it through.
|
|
49
|
+
state = tool.apply(state, args.value, outcome);
|
|
50
|
+
}
|
|
51
|
+
return state;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/core/state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,MAAM,UAAU,WAAW,CAC1B,OAAU,EACV,OAA+B,EAC/B,KAAgC;I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8E;QAC9E,+DAA+D;QAC/D,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,CAAM,CAAC;IACrD,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one file allowed to touch the real clock and real randomness.
|
|
3
|
+
*
|
|
4
|
+
* `scripts/importcheck.mjs` fails any other production file under `src/` that
|
|
5
|
+
* calls `Date.now`, `new Date(`, `setTimeout`, `setInterval`, `Math.random` or
|
|
6
|
+
* `console.`, so time and ids are injected everywhere else and a test can
|
|
7
|
+
* control them (docs/implementation/README.md, calls made in advance, 5).
|
|
8
|
+
*/
|
|
9
|
+
import type { Clock, Ids } from "./clock.js";
|
|
10
|
+
/** The host's clock. Use it only where nothing better exists: a test injects a fake. */
|
|
11
|
+
export declare function systemClock(): Clock;
|
|
12
|
+
/**
|
|
13
|
+
* Ids from the platform's cryptographic random source, as hex. A prefix such as
|
|
14
|
+
* `e` keeps a record readable; the random half is what cannot be guessed.
|
|
15
|
+
*/
|
|
16
|
+
export declare function systemIds(): Ids;
|
|
17
|
+
//# sourceMappingURL=system-clock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system-clock.d.ts","sourceRoot":"","sources":["../../src/core/system-clock.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAuC7C,wFAAwF;AACxF,wBAAgB,WAAW,IAAI,KAAK,CAMnC;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,GAAG,CAW/B"}
|