feat: align preview ContextVariable with typed API schema - #356
Draft
nico-pappagianis wants to merge 1 commit into
Draft
feat: align preview ContextVariable with typed API schema#356nico-pappagianis wants to merge 1 commit into
nico-pappagianis wants to merge 1 commit into
Conversation
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
| name: string; | ||
| type: 'Object' | 'Boolean' | 'DateTime' | 'Money' | 'Number' | 'Text' | 'Ref' | 'List'; | ||
| value: string; | ||
| }; |
Collaborator
Author
There was a problem hiding this comment.
This old code was not in parity with the actual preview API contract.
| | { 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 }; |
Collaborator
Author
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Realign the preview
ContextVariabletype with the preview API's ownVariableschema (agent-api v1.1 OpenAPI), so callers can send correctly-typed context variables instead of everything beingText.Why
The preview API's
Variableis a discriminated union keyed ontype, where the JSON type ofvaluedepends ontype:typevalueBooleanNumberText/Date/DateTime/Money/RefObjectVariableListJsonOur
ContextVariabletypedvalueas alwaysstringand was missing theJsonandDatevariants. 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) againstTrue(Boolean), the types differ, the gate never opens, and the route tool is never offered to the router LLM.Changes
ContextVariableis now a discriminated union mirroring the API, including the previously-missingJsonandDatetypes.ContextVariableTypefor downstream (plugin-agent) flag validation against the canonical enum.{ type: 'Boolean', value: 'true' }) and add coverage proving nativetrue/3reach the request body as JSON, not strings.Note
This is a type-shape change to an exported type (
value: string-> a per-typeunion). Our own call sites usetype: 'Text'with string values and still compile. Downstream consumer sweep (plugin-agent, vscode-agents) pending before de-drafting.Follow-up
plugin-agentwill add a--context-variables-jsonflag that accepts this shape (separate PR).@W-24014400