Skip to content

Commit 46b1ec0

Browse files
Gustav-SimonssonTheGreatAxios
authored andcommitted
refactor(agent): compress verbose comments in the tool schema normalize module
1 parent f45628a commit 46b1ec0

1 file changed

Lines changed: 20 additions & 24 deletions

File tree

‎src/agent/tool-schema-normalize.ts‎

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ export interface NormalizeToolDefsContext {
1212
}
1313

1414
/**
15-
* Shared primitives / view guidance for `present`. Used by both the canonical
16-
* `presentDefinition.description` and the acyclic wire `view.description` so the
17-
* two never drift.
15+
* Shared by the canonical `presentDefinition.description` and the acyclic
16+
* wire `view.description` so the two never drift.
1817
*/
1918
export const PRESENT_VIEW_PRIMITIVES_GUIDANCE =
2019
"Primitives: text{text, tone?, bold?, dim?}; " +
@@ -35,7 +34,7 @@ const TONE_ENUM = [
3534
const ALIGN_ENUM = ["left", "right", "center"] as const;
3635
const GAP_ENUM = [0, 1] as const;
3736

38-
/** Fully-specified leaf text node (no children). */
37+
/** Leaf text node (no children). */
3938
const TEXT_NODE = {
4039
type: "object",
4140
properties: {
@@ -49,7 +48,7 @@ const TEXT_NODE = {
4948
additionalProperties: false,
5049
} as const;
5150

52-
/** Fully-specified leaf divider node. */
51+
/** Leaf divider node. */
5352
const DIVIDER_NODE = {
5453
type: "object",
5554
properties: { type: { type: "string", enum: ["divider"] } },
@@ -58,9 +57,8 @@ const DIVIDER_NODE = {
5857
} as const;
5958

6059
/**
61-
* Nested child: leafs fully typed, plus a depth-capped open object for deeper
62-
* containers, so type/children/text/rows are documented without recursive
63-
* `$ref`.
60+
* Leafs fully typed; deeper containers use a depth-capped open object so
61+
* type/children/text/rows stay documented without recursive `$ref`.
6462
*/
6563
const NESTED_CHILD = {
6664
oneOf: [
@@ -118,10 +116,10 @@ const COLUMNS_PROP = {
118116
} as const;
119117

120118
/**
121-
* Non-recursive `present` parameters: Moonshot/Kimi and Muse Spark reject
122-
* JSON Schema `$ref` cycles on `tools.function.parameters` and fail the turn
123-
* before inference. Depth-capped oneOf primitives keep the model's view of
124-
* type/children/text fields; runtime still validates full nested trees via
119+
* Non-recursive `present` schema. Moonshot/Kimi and Muse Spark reject
120+
* `$ref` cycles on `tools.function.parameters` and fail the turn
121+
* before inference. Depth-capped oneOf keeps type/children/text
122+
* visible to the model; runtime still validates full nested trees via
125123
* `validateView`.
126124
*/
127125
export const KIMI_PRESENT_INPUT_SCHEMA = {
@@ -187,7 +185,7 @@ export const KIMI_PRESENT_INPUT_SCHEMA = {
187185
function rewritePresentAcyclic(def: ToolDefinition): ToolDefinition {
188186
return {
189187
...def,
190-
// structuredClone so callers cannot mutate the shared const via the tool def.
188+
// structuredClone so callers cannot mutate the shared const via the def.
191189
inputSchema: structuredClone(
192190
KIMI_PRESENT_INPUT_SCHEMA,
193191
) as ToolDefinition["inputSchema"],
@@ -274,9 +272,9 @@ const SCHEMA_CHILD_KEYS = new Set([
274272
]);
275273

276274
/**
277-
* Grok's Responses proxy 400s the whole infer on one invalid tool schema.
275+
* Grok's Responses proxy 400s the whole infer on one invalid schema.
278276
* Untyped properties and `$schema` are the shapes MCP tools and
279-
* submit_result historically advertised.
277+
* submit_result advertise.
280278
*/
281279
function sanitizeSchemaForGrok(value: unknown): unknown {
282280
if (Array.isArray(value)) return value.map(sanitizeSchemaForGrok);
@@ -301,8 +299,8 @@ function sanitizeSchemaForGrok(value: unknown): unknown {
301299
next[key] = props;
302300
continue;
303301
}
304-
// Literal enum/const/default/example documents can themselves look like
305-
// schemas; only schema-valued keywords may interpret their children.
302+
// Literal enum/const/default/example values can look like schemas;
303+
// only schema-valued keywords interpret their children.
306304
next[key] = SCHEMA_CHILD_KEYS.has(key)
307305
? sanitizeSchemaForGrok(child)
308306
: child;
@@ -324,15 +322,13 @@ function needsAcyclicPresentSchema(ctx: NormalizeToolDefsContext): boolean {
324322
}
325323

326324
/**
327-
* Family-gated wire rewrite of tool definitions before they reach the
325+
* Family-gated wire rewrite of tool defs before they reach the
328326
* director / provider. Moonshot/kimi and Muse Spark get a non-recursive
329-
* `present` schema; Grok/xAI get schema sanitization so an untyped property
330-
* or `$schema` cannot 400 the infer; others pass through unchanged. Does not
331-
* alter runtime validation or the canonical `presentDefinition`.
327+
* `present` schema; Grok/xAI get schema sanitization; others pass through.
328+
* Does not alter runtime validation or the canonical `presentDefinition`.
332329
*
333-
* Call at every advertise path that may include `present` (main TUI/exec
334-
* sessions); sub-agent toolsets omit `present`, so rewriting is a no-op
335-
* unless one appears.
330+
* Call at every advertise path that may include `present`; sub-agent
331+
* toolsets omit it, so rewriting is a no-op unless one appears.
336332
*/
337333
export function normalizeToolDefinitionsForProvider(
338334
defs: readonly ToolDefinition[],

0 commit comments

Comments
 (0)