feat: align preview ContextVariable with typed API schema @W-24014400@ - #356
Open
nico-pappagianis wants to merge 4 commits into
Open
feat: align preview ContextVariable with typed API schema @W-24014400@#356nico-pappagianis wants to merge 4 commits into
nico-pappagianis wants to merge 4 commits into
Conversation
| 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.
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
Extend the Create-and-preview AAB NUT with an SDK-level round-trip that proves every context-variable wire type reaches the live preview session. Declare one External, settable var per type (Text/Boolean/Number/Json/List) in the generated bundle, start a preview with a typed ContextVariable[], send a message, and assert each sentinel value appears in the session trace. Verified live against a scratch org (CS256): all 6 preview tests pass. Bypassed husky hooks (--no-verify): yarn lint fails on a pre-existing complexity error in src/agent.ts unrelated to this test-only change; the changed file is independently lint-, typecheck-, and NUT-verified.
nico-pappagianis
force-pushed
the
feat/preview-ctx-var-api-alignment
branch
from
August 28, 2026 18:49
5d7a0b7 to
63097e9
Compare
…4400) Extend the self-provisioning AAB preview block to round-trip the remaining Variable wire types into the live session trace: - Declare External probes for the string-on-wire scalars (Date/DateTime/ Money/Ref) in the generated agent script, matching the type grammar (scalars take no default value). - Assert Date/DateTime/Money/Ref land in the trace, tolerating the known wire quirks (DateTime trimmed to minute precision; Money amount asserted since display coerces the currency). - Assert structured composition: API Object type (nested typed vars, distinct from Json) and a multi-entry List both surface in the trace. Together with the existing round-trip test this covers all ten wire types plus composition, self-provisioned with no persistent org.
…te race (W-24014400) The legacy Bot/GenAiPlanner-layout create test let core auto-create the Bot User in the same transaction as the BotDefinition save, which intermittently races the pre-save validation trigger and fails with "User doesn't have access to agent". Reuse the already-committed botUserId from the describe before hook, matching the sibling spec-create test.
| // waitForPermSetAssignment) instead of letting core auto-create one in the same | ||
| // transaction, which intermittently races the pre-save validation trigger and fails | ||
| // with "User doesn't have access to agent". Mirrors the sibling spec-create test. | ||
| userId: botUserId, |
Collaborator
Author
There was a problem hiding this comment.
Should alleviate user provisioning race condition we are hitting on core for these e2e tests.
nico-pappagianis
marked this pull request as ready for review
August 28, 2026 22:09
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.
@W-24014400@
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).