Skip to content

feat: align preview ContextVariable with typed API schema - #356

Draft
nico-pappagianis wants to merge 1 commit into
mainfrom
feat/preview-ctx-var-api-alignment
Draft

feat: align preview ContextVariable with typed API schema#356
nico-pappagianis wants to merge 1 commit into
mainfrom
feat/preview-ctx-var-api-alignment

Conversation

@nico-pappagianis

Copy link
Copy Markdown
Collaborator

What

Realign the preview ContextVariable type with the preview API's own Variable schema (agent-api v1.1 OpenAPI), so callers can send correctly-typed context variables instead of everything being Text.

Why

The preview API's Variable is a discriminated union keyed on type, where the JSON type of value depends on type:

type value
Boolean boolean
Number number
Text / Date / DateTime / Money / Ref string
Object array of Variable
List array of objects
Json any JSON object

Our ContextVariable typed value as always string and was missing the Json and Date variants. So a boolean could only be sent as the string "True", which leaves a boolean-gated route (available when @variables.x == True) permanently closed: the runtime compares "True" (Text) against True (Boolean), the types differ, the gate never opens, and the route tool is never offered to the router LLM.

Changes

  • ContextVariable is now a discriminated union mirroring the API, including the previously-missing Json and Date types.
  • Export ContextVariableType for downstream (plugin-agent) flag validation against the canonical enum.
  • Update a test that encoded the old bug ({ type: 'Boolean', value: 'true' }) and add coverage proving native true/3 reach the request body as JSON, not strings.

Note

This is a type-shape change to an exported type (value: string -> a per-type union). Our own call sites use type: 'Text' with string values and still compile. Downstream consumer sweep (plugin-agent, vscode-agents) pending before de-drafting.

Follow-up

plugin-agent will add a --context-variables-json flag that accepts this shape (separate PR).

@W-24014400

The preview API's Variable schema (agent-api v1.1) is a discriminated union
keyed on type, where the JSON type of value depends on type: Boolean is a
boolean, Number is a number, Object/List are arrays, Json is any JSON object.
Our ContextVariable typed value as always string and was missing the Json and
Date variants, so a boolean could only be sent as the string "True" - which
leaves a boolean-gated route (available when @variables.x == True) closed,
because the runtime compares "True" (Text) against True (Boolean).

Model ContextVariable as a discriminated union mirroring the API, export a
ContextVariableType helper for downstream validation, and cover native-typed
values reaching the request body as JSON rather than strings.

@W-24014400
Comment thread src/types.ts
name: string;
type: 'Object' | 'Boolean' | 'DateTime' | 'Money' | 'Number' | 'Text' | 'Ref' | 'List';
value: string;
};

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This old code was not in parity with the actual preview API contract.

Comment thread src/types.ts
| { name: string; type: 'Text' | 'Date' | 'DateTime' | 'Money' | 'Ref'; value?: string | null }
| { name: string; type: 'Object'; value?: ContextVariable[] | null }
| { name: string; type: 'List'; value?: Array<Record<string, unknown>> | null }
| { name: string; type: 'Json'; value?: Record<string, unknown> | null };

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have gone with a looser single value union but having the context variables clearly defined here is the better trade off. A bit more code but much clearer about what is supported.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant