Summary
The parameter builder and defineTool() describe the same JSON Schema shape with two different TypeScript types, and they disagree on one field. As a result, passing a built schema straight into defineTool() fails to compile, even though the object is correct at runtime and the builder's doc comment says it produces "the exact shape defineTool({ parameters }) accepts".
The mismatch
An array property carries an items entry describing each element.
- The builder's output type (
ParameterProperty, src/ParameterSchema.ts:119) says items is any object.
- The type
defineTool() accepts (PropSchema, src/ParameterSchema.ts:159) says items must itself be a property with a type field.
"Any object" might lack type, so TypeScript rejects the whole schema. It does this even when no array property is present, because the check is on the declared type, not the actual values. Every other field in the two types is compatible.
Repro (SDK 6a2aa09, TS strict)
import { AgentBase, FunctionResult, paramSchema } from '@signalwire/sdk';
const agent = new AgentBase({ name: 'x', route: '/x' });
const params = paramSchema().string('pickup', 'addr').required('pickup').build();
agent.defineTool({
name: 't',
description: 'd',
parameters: params,
handler: async () => new FunctionResult('ok'),
});
Compiler output
error TS2322: Type 'ParameterSchemaObject' is not assignable to type 'ToolParameters | undefined'.
Type 'ParameterSchemaObject' is not assignable to type 'WrappedParametersSchema'.
Types of property 'properties' are incompatible.
Type 'Record<string, ParameterProperty>' is not assignable to type 'ParametersSchema'.
'string' index signatures are incompatible.
Type 'ParameterProperty' is not assignable to type 'PropSchema'.
Types of property 'items' are incompatible.
Type 'Record<string, unknown> | undefined' is not assignable to type 'PropSchema | undefined'.
Property 'type' is missing in type 'Record<string, unknown>' but required in type 'PropSchema'.
Suggested fix
Make the two types agree on items. Either tighten the builder side (ParameterProperty.items becomes ParameterProperty, and array() at line 299 takes the same type), or loosen the defineTool side (PropSchema.items becomes PropSchema | Record<string, unknown>). Tightening keeps InferArgs able to read array element types. Loosening is the smaller change.
Workaround (what the docs now show)
parameters: params.properties,
required: params.required,
Passing the two pieces separately avoids the items comparison. Related: signalwire/docs#668.
Summary
The parameter builder and
defineTool()describe the same JSON Schema shape with two different TypeScript types, and they disagree on one field. As a result, passing a built schema straight intodefineTool()fails to compile, even though the object is correct at runtime and the builder's doc comment says it produces "the exact shapedefineTool({ parameters })accepts".The mismatch
An array property carries an
itemsentry describing each element.ParameterProperty,src/ParameterSchema.ts:119) saysitemsis any object.defineTool()accepts (PropSchema,src/ParameterSchema.ts:159) saysitemsmust itself be a property with atypefield."Any object" might lack
type, so TypeScript rejects the whole schema. It does this even when no array property is present, because the check is on the declared type, not the actual values. Every other field in the two types is compatible.Repro (SDK
6a2aa09, TS strict)Compiler output
Suggested fix
Make the two types agree on
items. Either tighten the builder side (ParameterProperty.itemsbecomesParameterProperty, andarray()at line 299 takes the same type), or loosen thedefineToolside (PropSchema.itemsbecomesPropSchema | Record<string, unknown>). Tightening keepsInferArgsable to read array element types. Loosening is the smaller change.Workaround (what the docs now show)
Passing the two pieces separately avoids the
itemscomparison. Related: signalwire/docs#668.