Skip to content

v0.4.0

Choose a tag to compare

@ggoodman ggoodman released this 29 Jul 12:57
f5291d2

Author discriminated tool and event schemas

Code mode now emits exact agent-facing TypeScript for discriminated JSON Schema
unions. anyOf and oneOf work when every branch is a closed object sharing a
required string const property with a distinct value:

const Event = Type.Union([
  Type.Object(
    {
      type: Type.Literal("research.requested"),
      payload: Type.Object(
        { query: Type.String() },
        { additionalProperties: false },
      ),
    },
    { additionalProperties: false },
  ),
  Type.Object(
    {
      type: Type.Literal("research.completed"),
      payload: Type.Object(
        { report: Type.String() },
        { additionalProperties: false },
      ),
    },
    { additionalProperties: false },
  ),
]);

Agent programs can construct, narrow, and forward these values between tools
without losing exact input checking. Other composition shapes remain rejected
instead of being emitted as looser TypeScript.

Install with:

npm install @torkbot/code-mode@0.4.0