@clearideas/agent-runtime-contracts 0.4.0 → 0.4.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/dist/index.js +50 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -363,7 +363,49 @@ const validateSiblingStepIds = (steps, context, path) => {
|
|
|
363
363
|
}
|
|
364
364
|
});
|
|
365
365
|
};
|
|
366
|
-
|
|
366
|
+
const MAXIMUM_AGENT_MANIFEST_STRUCTURE_DEPTH = 128;
|
|
367
|
+
const MAXIMUM_AGENT_MANIFEST_STRUCTURE_NODES = 100_000;
|
|
368
|
+
const agentManifestStructureIssue = (input) => {
|
|
369
|
+
const ancestors = new WeakSet();
|
|
370
|
+
const stack = [{ value: input, depth: 0, exiting: false }];
|
|
371
|
+
let nodes = 0;
|
|
372
|
+
while (stack.length > 0) {
|
|
373
|
+
const frame = stack.pop();
|
|
374
|
+
if (frame.exiting) {
|
|
375
|
+
ancestors.delete(frame.value);
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
nodes += 1;
|
|
379
|
+
if (nodes > MAXIMUM_AGENT_MANIFEST_STRUCTURE_NODES) {
|
|
380
|
+
return `Agent manifest exceeds the ${MAXIMUM_AGENT_MANIFEST_STRUCTURE_NODES}-node structure limit.`;
|
|
381
|
+
}
|
|
382
|
+
if (frame.depth > MAXIMUM_AGENT_MANIFEST_STRUCTURE_DEPTH) {
|
|
383
|
+
return `Agent manifest exceeds the ${MAXIMUM_AGENT_MANIFEST_STRUCTURE_DEPTH}-level manifest structure depth limit.`;
|
|
384
|
+
}
|
|
385
|
+
if (frame.value == null || typeof frame.value !== "object")
|
|
386
|
+
continue;
|
|
387
|
+
if (ancestors.has(frame.value)) {
|
|
388
|
+
return "Agent manifest cannot contain cyclic data.";
|
|
389
|
+
}
|
|
390
|
+
const children = Array.isArray(frame.value)
|
|
391
|
+
? frame.value
|
|
392
|
+
: Object.values(frame.value);
|
|
393
|
+
if (nodes + children.length > MAXIMUM_AGENT_MANIFEST_STRUCTURE_NODES) {
|
|
394
|
+
return `Agent manifest exceeds the ${MAXIMUM_AGENT_MANIFEST_STRUCTURE_NODES}-node structure limit.`;
|
|
395
|
+
}
|
|
396
|
+
ancestors.add(frame.value);
|
|
397
|
+
stack.push({ ...frame, exiting: true });
|
|
398
|
+
for (let index = children.length - 1; index >= 0; index -= 1) {
|
|
399
|
+
stack.push({
|
|
400
|
+
value: children[index],
|
|
401
|
+
depth: frame.depth + 1,
|
|
402
|
+
exiting: false,
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return undefined;
|
|
407
|
+
};
|
|
408
|
+
const agentManifestObjectSchema = z
|
|
367
409
|
.object({
|
|
368
410
|
schemaVersion: z.literal(AGENT_MANIFEST_SCHEMA_VERSION),
|
|
369
411
|
id: z.string().optional(),
|
|
@@ -415,6 +457,13 @@ export const agentManifestSchema = z
|
|
|
415
457
|
variableKeys.add(normalizedKey);
|
|
416
458
|
});
|
|
417
459
|
});
|
|
460
|
+
export const agentManifestSchema = z.preprocess((input, context) => {
|
|
461
|
+
const issue = agentManifestStructureIssue(input);
|
|
462
|
+
if (issue) {
|
|
463
|
+
context.addIssue({ code: "custom", message: issue, fatal: true });
|
|
464
|
+
}
|
|
465
|
+
return input;
|
|
466
|
+
}, agentManifestObjectSchema);
|
|
418
467
|
export const agentRunBudgetSchema = z.strictObject({
|
|
419
468
|
maxTotalTokens: z.number().int().positive().safe(),
|
|
420
469
|
});
|
package/package.json
CHANGED