@theoremjs/agents 0.3.4-next.600.gb15be9a → 0.3.4-next.602.gb5a7fab
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.
|
@@ -12,10 +12,6 @@ export declare function fillActivityLabel(template: LabelTemplate | undefined, v
|
|
|
12
12
|
input: unknown;
|
|
13
13
|
output?: unknown;
|
|
14
14
|
}): string | undefined;
|
|
15
|
-
/**
|
|
16
|
-
* Why a label can't be used with these JSON schemas, as a sentence for its author, or `undefined`
|
|
17
|
-
* when it can. Pass `output` for a Done label. A list must end on a line that always fits.
|
|
18
|
-
*/
|
|
19
15
|
export declare function activityLabelProblem(template: LabelTemplate, schemas: {
|
|
20
16
|
input: unknown;
|
|
21
17
|
output?: unknown;
|
|
@@ -428,7 +428,41 @@ function listProblem(entries) {
|
|
|
428
428
|
* Why a label can't be used with these JSON schemas, as a sentence for its author, or `undefined`
|
|
429
429
|
* when it can. Pass `output` for a Done label. A list must end on a line that always fits.
|
|
430
430
|
*/
|
|
431
|
+
/** The schemas' outputs, when a check names none. */
|
|
432
|
+
const NO_OUTPUT = {};
|
|
433
|
+
/** Answers by input schema, then output schema, then template: a schema object is read, never changed. */
|
|
434
|
+
const answered = new WeakMap();
|
|
435
|
+
/** The answers already given for these schemas, when both are objects that can key them. */
|
|
436
|
+
function answersFor(schemas) {
|
|
437
|
+
const { input } = schemas;
|
|
438
|
+
const output = 'output' in schemas ? schemas.output : NO_OUTPUT;
|
|
439
|
+
if (typeof input !== 'object' || input === null)
|
|
440
|
+
return undefined;
|
|
441
|
+
if (typeof output !== 'object' || output === null)
|
|
442
|
+
return undefined;
|
|
443
|
+
let byOutput = answered.get(input);
|
|
444
|
+
if (!byOutput) {
|
|
445
|
+
byOutput = new WeakMap();
|
|
446
|
+
answered.set(input, byOutput);
|
|
447
|
+
}
|
|
448
|
+
let byTemplate = byOutput.get(output);
|
|
449
|
+
if (!byTemplate) {
|
|
450
|
+
byTemplate = new Map();
|
|
451
|
+
byOutput.set(output, byTemplate);
|
|
452
|
+
}
|
|
453
|
+
return byTemplate;
|
|
454
|
+
}
|
|
455
|
+
// why: A studio compile checks every tool's labels for every agent that uses the tool, again on each edit that settles.
|
|
431
456
|
export function activityLabelProblem(template, schemas) {
|
|
457
|
+
const answers = answersFor(schemas);
|
|
458
|
+
const key = JSON.stringify(template);
|
|
459
|
+
if (answers?.has(key))
|
|
460
|
+
return answers.get(key);
|
|
461
|
+
const problem = templateProblem(template, schemas);
|
|
462
|
+
answers?.set(key, problem);
|
|
463
|
+
return problem;
|
|
464
|
+
}
|
|
465
|
+
function templateProblem(template, schemas) {
|
|
432
466
|
const sides = 'output' in schemas ? ['input', 'output'] : ['input'];
|
|
433
467
|
const listed = typeof template !== 'string';
|
|
434
468
|
const entries = entriesOf(template);
|
|
@@ -4,12 +4,30 @@ import { activityLabelProblem } from './activity-label.js';
|
|
|
4
4
|
import { agentToolInputFor, agentToolOutput, agentToolProfile, normalizeAgent } from './agent.js';
|
|
5
5
|
import { createMcpSessionCache } from './mcp-sessions.js';
|
|
6
6
|
import { pageAnswerHandler } from './page-answer.js';
|
|
7
|
-
import { assertFixedEndpointOrigin, jsonSchemaFromZod, validateToolSchema } from './schema.js';
|
|
7
|
+
import { assertFixedEndpointOrigin, jsonSchemaFromZod, validateToolSchema, } from './schema.js';
|
|
8
|
+
/** Each zod pair's JSON Schemas, as converted and checked: a zod schema is never changed. */
|
|
9
|
+
const converted = new WeakMap();
|
|
10
|
+
/** The pair's JSON Schemas, converted and checked once; registering the same schemas again reads them back. */
|
|
11
|
+
function checkedSchemas(input, output) {
|
|
12
|
+
let byOutput = converted.get(input);
|
|
13
|
+
if (!byOutput) {
|
|
14
|
+
byOutput = new WeakMap();
|
|
15
|
+
converted.set(input, byOutput);
|
|
16
|
+
}
|
|
17
|
+
let schemas = byOutput.get(output);
|
|
18
|
+
if (!schemas) {
|
|
19
|
+
const inputSchema = jsonSchemaFromZod(input, 'input');
|
|
20
|
+
validateToolSchema(inputSchema, 'input');
|
|
21
|
+
const outputSchema = jsonSchemaFromZod(output, 'output');
|
|
22
|
+
validateToolSchema(outputSchema, 'output');
|
|
23
|
+
schemas = { inputSchema, outputSchema };
|
|
24
|
+
byOutput.set(output, schemas);
|
|
25
|
+
}
|
|
26
|
+
return schemas;
|
|
27
|
+
}
|
|
8
28
|
function schemasFromZod(def) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const outputSchema = jsonSchemaFromZod(def.output, 'output');
|
|
12
|
-
validateToolSchema(outputSchema, 'output');
|
|
29
|
+
// why: A studio compile registers each tool once for every agent that uses it, again on each edit that settles.
|
|
30
|
+
const { inputSchema, outputSchema } = checkedSchemas(def.input, def.output);
|
|
13
31
|
const labels = {
|
|
14
32
|
activity: { input: inputSchema },
|
|
15
33
|
activityPast: { input: inputSchema, output: outputSchema },
|
|
@@ -23,7 +41,8 @@ function schemasFromZod(def) {
|
|
|
23
41
|
throw new TheoremError('config', `Tool "${def.name}" ${field} label: ${problem}`);
|
|
24
42
|
}
|
|
25
43
|
}
|
|
26
|
-
|
|
44
|
+
// invariant: Each registration gets its own copy, so nothing a tool does to its schemas reaches another.
|
|
45
|
+
return { inputSchema: structuredClone(inputSchema), outputSchema: structuredClone(outputSchema) };
|
|
27
46
|
}
|
|
28
47
|
/** The person is told which service they sign in to; the tool's builder names it, never the model or the server. */
|
|
29
48
|
function assertAuthService(name, auth) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theoremjs/agents",
|
|
3
|
-
"version": "0.3.4-next.
|
|
3
|
+
"version": "0.3.4-next.602.gb5a7fab",
|
|
4
4
|
"description": "A flat TypeScript agent kernel for typed profiles, deterministic turn execution, registered tools, provider adapters, guardrails, and host-injected traces.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|