Skip to content

defineTool({ parameters }) rejects the object returned by paramSchema().build() #184

Description

@hey-august

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions