@theoremjs/agents 0.3.5-next.944.ga2c173d → 0.3.5-next.945.g127cfdd

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.
@@ -5,8 +5,9 @@ export declare function withModelField<TIn>(name: string, input: z.ZodType<TIn>,
5
5
  /** `input` with the model's `after` field. */
6
6
  export declare function withCallOrder<TIn>(name: string, input: z.ZodType<TIn>): z.ZodType<TIn>;
7
7
  /**
8
- * A registered tool's input schema as the tool declared it, without the `after` field the kernel
9
- * added for the model. Registering the tool again from it adds the field once.
8
+ * A registered tool's input schema as the tool declared it: without the `after` field the kernel
9
+ * added for the model, and a union without the root `type` its JSON Schema was given. Registering
10
+ * the tool again from it adds the field once, to the same union.
10
11
  */
11
12
  export declare function declaredInputSchema(tool: {
12
13
  after?: boolean;
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import { TheoremError } from '../../guardrails/error.js';
3
3
  import { labelText } from '../../guardrails/labels.js';
4
+ import { zodJsonSchema } from './schema.js';
4
5
  const FIELD = 'after';
5
6
  function orderField() {
6
7
  return z.array(z.string()).optional().describe(labelText('tool.after_field'));
@@ -30,11 +31,13 @@ export function withCallOrder(name, input) {
30
31
  return withModelField(name, input, FIELD, orderField);
31
32
  }
32
33
  /**
33
- * A registered tool's input schema as the tool declared it, without the `after` field the kernel
34
- * added for the model. Registering the tool again from it adds the field once.
34
+ * A registered tool's input schema as the tool declared it: without the `after` field the kernel
35
+ * added for the model, and a union without the root `type` its JSON Schema was given. Registering
36
+ * the tool again from it adds the field once, to the same union.
35
37
  */
36
38
  export function declaredInputSchema(tool) {
37
- return tool.after ? withoutField(tool.inputSchema, FIELD) : tool.inputSchema;
39
+ const declared = zodJsonSchema(tool.inputSchema);
40
+ return tool.after ? withoutField(declared, FIELD) : declared;
38
41
  }
39
42
  function withoutField(schema, field) {
40
43
  const out = { ...schema };
@@ -3,7 +3,12 @@ export type JsonSchema = Record<string, unknown>;
3
3
  /** A structural check only: what a provider accepts is its own API's answer. */
4
4
  declare function validateToolSchema(schema: JsonSchema, label: 'input' | 'output'): void;
5
5
  declare function jsonSchemaFromZod(schema: ZodType, io?: 'input' | 'output'): JsonSchema;
6
- export { jsonSchemaFromZod, validateToolSchema };
6
+ /**
7
+ * `schema` as zod wrote it, without the root `type` `jsonSchemaFromZod` gives a union. Read back
8
+ * with that type beside its `oneOf` or `anyOf`, a union is an intersection with an object.
9
+ */
10
+ declare function zodJsonSchema(schema: JsonSchema): JsonSchema;
11
+ export { jsonSchemaFromZod, validateToolSchema, zodJsonSchema };
7
12
  /** Strips prototype-pollution keys before validation. */
8
13
  export declare function plainToolInput(input: unknown): unknown;
9
14
  /** A placeholder in the scheme or authority would let tool input choose where the credential goes. */
@@ -60,15 +60,28 @@ function validateToolSchema(schema, label) {
60
60
  throw new TheoremError('config', `Invalid tool ${label} schema: ${errors.join('; ')}`); // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
61
61
  }
62
62
  }
63
+ /** The root `type` a union's schema is given, which the union itself never states. */
64
+ const UNION_ROOT_TYPE = 'object';
63
65
  function jsonSchemaFromZod(schema, io = 'output') {
64
66
  const json = z.toJSONSchema(schema, { target: 'draft-7', io });
65
67
  delete json.$schema;
66
68
  if (!json.type) {
67
- json.type = 'object';
69
+ json.type = UNION_ROOT_TYPE;
68
70
  }
69
71
  return json;
70
72
  }
71
- export { jsonSchemaFromZod, validateToolSchema };
73
+ /**
74
+ * `schema` as zod wrote it, without the root `type` `jsonSchemaFromZod` gives a union. Read back
75
+ * with that type beside its `oneOf` or `anyOf`, a union is an intersection with an object.
76
+ */
77
+ function zodJsonSchema(schema) {
78
+ const isUnion = schema.oneOf !== undefined || schema.anyOf !== undefined;
79
+ if (!isUnion || schema.type !== UNION_ROOT_TYPE || schema.properties !== undefined)
80
+ return schema;
81
+ const { type: _added, ...union } = schema;
82
+ return union;
83
+ }
84
+ export { jsonSchemaFromZod, validateToolSchema, zodJsonSchema };
72
85
  /** Strips prototype-pollution keys before validation. */
73
86
  export function plainToolInput(input) {
74
87
  if (input === null || typeof input !== 'object') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theoremjs/agents",
3
- "version": "0.3.5-next.944.ga2c173d",
3
+ "version": "0.3.5-next.945.g127cfdd",
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",