@you-agent-factory/factory-emulator 0.0.0 → 0.0.2
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.md +19 -1
- package/README.md +305 -286
- package/dist/compatibility.d.ts +19 -0
- package/dist/compatibility.js +156 -0
- package/dist/event-sink.d.ts +29 -0
- package/dist/event-sink.js +58 -0
- package/dist/generated/scenario-schema.d.ts +268 -0
- package/dist/generated/scenario-schema.js +319 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/logical-move.d.ts +10 -0
- package/dist/logical-move.js +18 -0
- package/dist/recording-sink.d.ts +22 -0
- package/dist/recording-sink.js +122 -0
- package/dist/runtime-reference-conformance.d.ts +20 -0
- package/dist/runtime-reference-conformance.js +138 -0
- package/dist/runtime-reference-evidence.d.ts +9 -0
- package/dist/runtime-reference-evidence.js +193 -0
- package/dist/runtime-reference-fixtures.d.ts +7 -0
- package/dist/runtime-reference-fixtures.js +308 -0
- package/dist/runtime-reference.d.ts +48 -0
- package/dist/runtime-reference.js +143 -0
- package/dist/scenario-contracts.d.ts +81 -0
- package/dist/scenario-contracts.js +11 -0
- package/dist/scenario.d.ts +271 -0
- package/dist/scenario.js +333 -0
- package/dist/scheduler.d.ts +24 -0
- package/dist/scheduler.js +104 -0
- package/dist/session-contracts.d.ts +262 -0
- package/dist/session-contracts.js +74 -0
- package/dist/session.d.ts +4 -0
- package/dist/session.js +1490 -0
- package/dist/submission-replay.d.ts +14 -0
- package/dist/submission-replay.js +96 -0
- package/dist/submission-validation.d.ts +3 -0
- package/dist/submission-validation.js +113 -0
- package/examples/customer-support.scenario.v1.json +45 -0
- package/package.json +44 -22
- package/schema/scenario.schema.json +171 -0
- package/generated/factory-emulator-scenario.schema.json +0 -191
- package/generated/factory.schema.json +0 -2606
- package/src/contracts.ts +0 -41
- package/src/data-error.js +0 -21
- package/src/data-only.js +0 -208
- package/src/emulator.js +0 -195
- package/src/emulator.ts +0 -86
- package/src/examples.js +0 -86
- package/src/examples.ts +0 -11
- package/src/generated/factory-schema.d.ts +0 -3
- package/src/generated/factory-schema.js +0 -5
- package/src/generated/scenario-schema.d.ts +0 -4
- package/src/generated/scenario-schema.js +0 -6
- package/src/generated/scenario.ts +0 -103
- package/src/identity.js +0 -55
- package/src/index.js +0 -34
- package/src/index.ts +0 -102
- package/src/limits.js +0 -125
- package/src/parser.js +0 -113
- package/src/parser.ts +0 -56
- package/src/scheduler.js +0 -374
- package/src/semantics.js +0 -354
- package/src/semantics.ts +0 -38
- package/src/session.js +0 -1201
- package/src/session.ts +0 -324
- package/src/sinks.js +0 -118
- package/src/sinks.ts +0 -56
- package/src/support.js +0 -334
- package/src/support.ts +0 -15
- package/src/virtual-time.js +0 -36
package/src/support.js
DELETED
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The v1 browser-emulator support policy. Parsing consumes this policy directly,
|
|
3
|
-
* and inspection exposes it without requiring callers to reproduce parser rules.
|
|
4
|
-
*/
|
|
5
|
-
export const emulatorSupport = deepFreeze({
|
|
6
|
-
scenarioVersion: "you-agent-factory.emulator.scenario.v1",
|
|
7
|
-
factory: {
|
|
8
|
-
supported: {
|
|
9
|
-
orchestrator: { kind: "PETRI", allowOmitted: true },
|
|
10
|
-
workstations: { behavior: "STANDARD", allowOmitted: true },
|
|
11
|
-
},
|
|
12
|
-
unsupported: [
|
|
13
|
-
"JavaScript orchestration",
|
|
14
|
-
"configured Factory resources",
|
|
15
|
-
"Factory guards",
|
|
16
|
-
"cron workstation scheduling",
|
|
17
|
-
"non-STANDARD workstation behavior",
|
|
18
|
-
],
|
|
19
|
-
},
|
|
20
|
-
ruleMatchers: ["all", "workType", "submissionId"],
|
|
21
|
-
outcomeVariants: ["complete", "reject"],
|
|
22
|
-
outcomeDuration: {
|
|
23
|
-
field: "durationMs",
|
|
24
|
-
unit: "virtual milliseconds",
|
|
25
|
-
default: 0,
|
|
26
|
-
},
|
|
27
|
-
lineageCursors: {
|
|
28
|
-
initialSubmission: "one unique initial submission id",
|
|
29
|
-
scriptedOutcome: "one earlier complete scripted outcome",
|
|
30
|
-
},
|
|
31
|
-
exhaustionBehaviors: ["repeatLast", "useUnmatchedBehavior", "reject"],
|
|
32
|
-
unmatchedBehaviors: ["ignore", "reject"],
|
|
33
|
-
initialSubmissions: {
|
|
34
|
-
requiredFields: ["id", "workType"],
|
|
35
|
-
workTypeMustExistInFactory: true,
|
|
36
|
-
},
|
|
37
|
-
activityLabel: {
|
|
38
|
-
maximumLength: 120,
|
|
39
|
-
transient: true,
|
|
40
|
-
canonicalFactoryEventField: false,
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
/** Returns the stable, machine-readable v1 emulator support report. */
|
|
45
|
-
export function inspectEmulatorSupport() {
|
|
46
|
-
return emulatorSupport;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** Returns Factory-subset diagnostics used by the public parser. */
|
|
50
|
-
export function factorySupportDiagnostics(factory) {
|
|
51
|
-
if (!isRecord(factory)) {
|
|
52
|
-
return [
|
|
53
|
-
diagnostic(
|
|
54
|
-
"INVALID_FACTORY_DEFINITION",
|
|
55
|
-
"/",
|
|
56
|
-
"Factory definition must be an object.",
|
|
57
|
-
"a Factory definition object",
|
|
58
|
-
),
|
|
59
|
-
];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const diagnostics = [];
|
|
63
|
-
validateOrchestrator(factory, diagnostics);
|
|
64
|
-
validateWorkTypes(factory, diagnostics);
|
|
65
|
-
rejectConfiguredArray(
|
|
66
|
-
factory,
|
|
67
|
-
diagnostics,
|
|
68
|
-
"/",
|
|
69
|
-
"resources",
|
|
70
|
-
"resource capacity",
|
|
71
|
-
);
|
|
72
|
-
rejectConfiguredArray(factory, diagnostics, "/", "guards", "Factory guards");
|
|
73
|
-
validateWorkstations(factory, diagnostics);
|
|
74
|
-
return diagnostics;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function validateOrchestrator(factory, diagnostics) {
|
|
78
|
-
if (factory.orchestrator === undefined) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (!isRecord(factory.orchestrator)) {
|
|
82
|
-
diagnostics.push(
|
|
83
|
-
diagnostic(
|
|
84
|
-
"INVALID_FACTORY_DEFINITION",
|
|
85
|
-
"/orchestrator",
|
|
86
|
-
"Factory orchestrator must be an object when supplied.",
|
|
87
|
-
"a static PETRI orchestrator",
|
|
88
|
-
),
|
|
89
|
-
);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
if (
|
|
93
|
-
factory.orchestrator.kind !== undefined &&
|
|
94
|
-
factory.orchestrator.kind !==
|
|
95
|
-
emulatorSupport.factory.supported.orchestrator.kind
|
|
96
|
-
) {
|
|
97
|
-
diagnostics.push(
|
|
98
|
-
diagnostic(
|
|
99
|
-
"UNSUPPORTED_FACTORY_CAPABILITY",
|
|
100
|
-
"/orchestrator/kind",
|
|
101
|
-
`Factory orchestrator ${JSON.stringify(factory.orchestrator.kind)} is not supported by the emulator.`,
|
|
102
|
-
"a static PETRI orchestrator",
|
|
103
|
-
),
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function validateWorkTypes(factory, diagnostics) {
|
|
109
|
-
if (
|
|
110
|
-
!validateOptionalArray(
|
|
111
|
-
factory,
|
|
112
|
-
diagnostics,
|
|
113
|
-
"/",
|
|
114
|
-
"workTypes",
|
|
115
|
-
"Factory work types",
|
|
116
|
-
)
|
|
117
|
-
) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
for (const [index, workType] of (factory.workTypes ?? []).entries()) {
|
|
121
|
-
const path = `/workTypes/${index}`;
|
|
122
|
-
if (!isRecord(workType)) {
|
|
123
|
-
diagnostics.push(
|
|
124
|
-
diagnostic(
|
|
125
|
-
"INVALID_FACTORY_DEFINITION",
|
|
126
|
-
path,
|
|
127
|
-
"Factory work type must be an object.",
|
|
128
|
-
"a work type object with a non-empty name",
|
|
129
|
-
),
|
|
130
|
-
);
|
|
131
|
-
} else if (
|
|
132
|
-
typeof workType.name !== "string" ||
|
|
133
|
-
workType.name.length === 0
|
|
134
|
-
) {
|
|
135
|
-
diagnostics.push(
|
|
136
|
-
diagnostic(
|
|
137
|
-
"INVALID_FACTORY_DEFINITION",
|
|
138
|
-
`${path}/name`,
|
|
139
|
-
"Factory work type name must be a non-empty string.",
|
|
140
|
-
"a non-empty work type name",
|
|
141
|
-
),
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function rejectConfiguredArray(
|
|
148
|
-
owner,
|
|
149
|
-
diagnostics,
|
|
150
|
-
ownerPath,
|
|
151
|
-
property,
|
|
152
|
-
capability,
|
|
153
|
-
) {
|
|
154
|
-
if (
|
|
155
|
-
!validateOptionalArray(owner, diagnostics, ownerPath, property, capability)
|
|
156
|
-
) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
if (owner[property]?.length > 0) {
|
|
160
|
-
const path = childPath(ownerPath, property);
|
|
161
|
-
diagnostics.push(
|
|
162
|
-
diagnostic(
|
|
163
|
-
"UNSUPPORTED_FACTORY_CAPABILITY",
|
|
164
|
-
path,
|
|
165
|
-
`${capability} are not supported by the emulator.`,
|
|
166
|
-
`no configured ${capability}`,
|
|
167
|
-
),
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function validateOptionalArray(
|
|
173
|
-
owner,
|
|
174
|
-
diagnostics,
|
|
175
|
-
ownerPath,
|
|
176
|
-
property,
|
|
177
|
-
description,
|
|
178
|
-
) {
|
|
179
|
-
if (owner[property] === undefined || Array.isArray(owner[property])) {
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
diagnostics.push(
|
|
183
|
-
diagnostic(
|
|
184
|
-
"INVALID_FACTORY_DEFINITION",
|
|
185
|
-
childPath(ownerPath, property),
|
|
186
|
-
`${description} must be an array when supplied.`,
|
|
187
|
-
`an array of ${description}`,
|
|
188
|
-
),
|
|
189
|
-
);
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function validateWorkstations(factory, diagnostics) {
|
|
194
|
-
if (factory.workstations === undefined) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
if (!Array.isArray(factory.workstations)) {
|
|
198
|
-
diagnostics.push(
|
|
199
|
-
diagnostic(
|
|
200
|
-
"INVALID_FACTORY_DEFINITION",
|
|
201
|
-
"/workstations",
|
|
202
|
-
"Factory workstations must be an array when supplied.",
|
|
203
|
-
"an array of static standard workstations",
|
|
204
|
-
),
|
|
205
|
-
);
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
for (const [index, workstation] of factory.workstations.entries()) {
|
|
209
|
-
const path = `/workstations/${index}`;
|
|
210
|
-
if (!isRecord(workstation)) {
|
|
211
|
-
diagnostics.push(
|
|
212
|
-
diagnostic(
|
|
213
|
-
"INVALID_FACTORY_DEFINITION",
|
|
214
|
-
path,
|
|
215
|
-
"Factory workstation must be an object.",
|
|
216
|
-
"a static standard workstation object",
|
|
217
|
-
),
|
|
218
|
-
);
|
|
219
|
-
continue;
|
|
220
|
-
}
|
|
221
|
-
if (
|
|
222
|
-
workstation.behavior !== undefined &&
|
|
223
|
-
typeof workstation.behavior !== "string"
|
|
224
|
-
) {
|
|
225
|
-
diagnostics.push(
|
|
226
|
-
diagnostic(
|
|
227
|
-
"INVALID_FACTORY_DEFINITION",
|
|
228
|
-
`${path}/behavior`,
|
|
229
|
-
"Factory workstation behavior must be a string when supplied.",
|
|
230
|
-
"STANDARD workstation behavior",
|
|
231
|
-
),
|
|
232
|
-
);
|
|
233
|
-
} else if (
|
|
234
|
-
workstation.behavior !== undefined &&
|
|
235
|
-
workstation.behavior !==
|
|
236
|
-
emulatorSupport.factory.supported.workstations.behavior
|
|
237
|
-
) {
|
|
238
|
-
diagnostics.push(
|
|
239
|
-
diagnostic(
|
|
240
|
-
"UNSUPPORTED_FACTORY_CAPABILITY",
|
|
241
|
-
`${path}/behavior`,
|
|
242
|
-
`Factory workstation behavior ${JSON.stringify(workstation.behavior)} is not supported by the emulator.`,
|
|
243
|
-
"STANDARD workstation behavior",
|
|
244
|
-
),
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
if (workstation.cron !== undefined) {
|
|
248
|
-
diagnostics.push(
|
|
249
|
-
diagnostic(
|
|
250
|
-
"UNSUPPORTED_FACTORY_CAPABILITY",
|
|
251
|
-
`${path}/cron`,
|
|
252
|
-
"Factory cron scheduling is not supported by the emulator.",
|
|
253
|
-
"no cron scheduling",
|
|
254
|
-
),
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
rejectConfiguredArray(
|
|
258
|
-
workstation,
|
|
259
|
-
diagnostics,
|
|
260
|
-
path,
|
|
261
|
-
"resources",
|
|
262
|
-
"Workstation resource requirements",
|
|
263
|
-
);
|
|
264
|
-
rejectConfiguredArray(
|
|
265
|
-
workstation,
|
|
266
|
-
diagnostics,
|
|
267
|
-
path,
|
|
268
|
-
"guards",
|
|
269
|
-
"Workstation guards",
|
|
270
|
-
);
|
|
271
|
-
validateWorkstationInputs(workstation, diagnostics, path);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
function validateWorkstationInputs(workstation, diagnostics, workstationPath) {
|
|
276
|
-
if (
|
|
277
|
-
!validateOptionalArray(
|
|
278
|
-
workstation,
|
|
279
|
-
diagnostics,
|
|
280
|
-
workstationPath,
|
|
281
|
-
"inputs",
|
|
282
|
-
"Factory workstation inputs",
|
|
283
|
-
)
|
|
284
|
-
) {
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
for (const [index, input] of (workstation.inputs ?? []).entries()) {
|
|
288
|
-
const path = `${workstationPath}/inputs/${index}`;
|
|
289
|
-
if (!isRecord(input)) {
|
|
290
|
-
diagnostics.push(
|
|
291
|
-
diagnostic(
|
|
292
|
-
"INVALID_FACTORY_DEFINITION",
|
|
293
|
-
path,
|
|
294
|
-
"Factory workstation input must be an object.",
|
|
295
|
-
"a workstation input object",
|
|
296
|
-
),
|
|
297
|
-
);
|
|
298
|
-
continue;
|
|
299
|
-
}
|
|
300
|
-
rejectConfiguredArray(
|
|
301
|
-
input,
|
|
302
|
-
diagnostics,
|
|
303
|
-
path,
|
|
304
|
-
"guards",
|
|
305
|
-
"Workstation input guards",
|
|
306
|
-
);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
function childPath(ownerPath, property) {
|
|
311
|
-
return ownerPath === "/" ? `/${property}` : `${ownerPath}/${property}`;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
function diagnostic(code, path, message, expectation) {
|
|
315
|
-
return { code, path, message, expectation };
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
function isRecord(value) {
|
|
319
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
function deepFreeze(value) {
|
|
323
|
-
Object.freeze(value);
|
|
324
|
-
for (const child of Object.values(value)) {
|
|
325
|
-
if (
|
|
326
|
-
typeof child === "object" &&
|
|
327
|
-
child !== null &&
|
|
328
|
-
!Object.isFrozen(child)
|
|
329
|
-
) {
|
|
330
|
-
deepFreeze(child);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
return value;
|
|
334
|
-
}
|
package/src/support.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export interface EmulatorSupportInspection {
|
|
2
|
-
readonly scenarioVersion: string;
|
|
3
|
-
readonly factory: { readonly supported: { readonly orchestrator: { readonly kind: "PETRI"; readonly allowOmitted: true }; readonly workstations: { readonly behavior: "STANDARD"; readonly allowOmitted: true } }; readonly unsupported: readonly string[] };
|
|
4
|
-
readonly ruleMatchers: readonly ("all" | "workType" | "submissionId")[];
|
|
5
|
-
readonly outcomeVariants: readonly ("complete" | "reject")[];
|
|
6
|
-
readonly outcomeDuration: { readonly field: "durationMs"; readonly unit: "virtual milliseconds"; readonly default: 0 };
|
|
7
|
-
readonly lineageCursors: { readonly initialSubmission: string; readonly scriptedOutcome: string };
|
|
8
|
-
readonly exhaustionBehaviors: readonly ("repeatLast" | "useUnmatchedBehavior" | "reject")[];
|
|
9
|
-
readonly unmatchedBehaviors: readonly ("ignore" | "reject")[];
|
|
10
|
-
readonly initialSubmissions: { readonly requiredFields: readonly ("id" | "workType")[]; readonly workTypeMustExistInFactory: true };
|
|
11
|
-
readonly activityLabel: { readonly maximumLength: 120; readonly transient: true; readonly canonicalFactoryEventField: false };
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** Returns the stable, machine-readable v1 emulator support report. */
|
|
15
|
-
export declare function inspectEmulatorSupport(): EmulatorSupportInspection;
|
package/src/virtual-time.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { defineDataError } from "./data-error.js";
|
|
2
|
-
|
|
3
|
-
export const FactoryEmulatorDurationError = defineDataError(
|
|
4
|
-
"FactoryEmulatorDurationError",
|
|
5
|
-
"INVALID_DURATION",
|
|
6
|
-
{
|
|
7
|
-
message: () => "Factory emulator duration must be a non-negative safe integer",
|
|
8
|
-
details: (durationMs) => ({ durationMs }),
|
|
9
|
-
},
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
export function validateDuration(durationMs) {
|
|
13
|
-
if (!Number.isSafeInteger(durationMs) || durationMs < 0) {
|
|
14
|
-
throw new FactoryEmulatorDurationError(durationMs);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function stateAtElapsed(scenario, state, virtualElapsedMs) {
|
|
19
|
-
return {
|
|
20
|
-
...state,
|
|
21
|
-
virtualElapsedMs,
|
|
22
|
-
virtualTime: virtualTimeAt(scenario, virtualElapsedMs),
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function virtualTimeAt(scenario, virtualElapsedMs) {
|
|
27
|
-
const time = new Date(scenario.startAt).getTime() + virtualElapsedMs;
|
|
28
|
-
if (!Number.isFinite(time)) {
|
|
29
|
-
throw new FactoryEmulatorDurationError(virtualElapsedMs);
|
|
30
|
-
}
|
|
31
|
-
try {
|
|
32
|
-
return new Date(time).toISOString();
|
|
33
|
-
} catch {
|
|
34
|
-
throw new FactoryEmulatorDurationError(virtualElapsedMs);
|
|
35
|
-
}
|
|
36
|
-
}
|