Skip to content

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

Open
nico-pappagianis wants to merge 4 commits into
mainfrom
feat/preview-ctx-var-api-alignment
Open

feat: align preview ContextVariable with typed API schema @W-24014400@#356
nico-pappagianis wants to merge 4 commits into
mainfrom
feat/preview-ctx-var-api-alignment

Conversation

@nico-pappagianis

@nico-pappagianis nico-pappagianis commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

@W-24014400@

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).

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.

@nico-pappagianis nico-pappagianis changed the title feat: align preview ContextVariable with typed API schema feat: align preview ContextVariable with typed API schema @ W-24014400 Aug 28, 2026
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
nico-pappagianis force-pushed the feat/preview-ctx-var-api-alignment branch from 5d7a0b7 to 63097e9 Compare August 28, 2026 18:49
…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.
@nico-pappagianis nico-pappagianis changed the title feat: align preview ContextVariable with typed API schema @ W-24014400 feat: align preview ContextVariable with typed API schema @W-24014400 Aug 28, 2026
@nico-pappagianis nico-pappagianis changed the title feat: align preview ContextVariable with typed API schema @W-24014400 feat: align preview ContextVariable with typed API schema @W-24014400@ Aug 28, 2026
…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.
Comment thread test/nuts/agent.nut.ts
// 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,

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.

Should alleviate user provisioning race condition we are hitting on core for these e2e tests.

@nico-pappagianis
nico-pappagianis marked this pull request as ready for review August 28, 2026 22:09
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