Skip to content

feat: add --context-variables-json for typed preview context variables - #483

Draft
nico-pappagianis wants to merge 2 commits into
mainfrom
feat/preview-ctx-var-agents-alignment
Draft

feat: add --context-variables-json for typed preview context variables#483
nico-pappagianis wants to merge 2 commits into
mainfrom
feat/preview-ctx-var-agents-alignment

Conversation

@nico-pappagianis

Copy link
Copy Markdown
Collaborator

What

Adds a new --context-variables-json flag to sf agent preview and sf agent preview start so callers can send typed context variables (Boolean, Number, Object, List, Json) to the preview API, not just Text.

Why

--context-variables (the existing Name=Value flag) hard-codes every value as type Text. A boolean-gated route (for example available when @variables.probeGate == True) never opens, because the runtime compares the string "True" against the boolean True. See W-24014400.

The new flag matches the preview API's own Variable schema (a discriminated union keyed on type), so a value is sent with the correct JSON type on the wire.

How

  • New contextVariablesJsonFlag in src/flags.ts, plus parseContextVariablesJson (validates JSON shape and that each value matches its declared type) and mergeContextVariables (merges the text-form and JSON-form variables; on a duplicate name the JSON entry wins, keeping the text entry's position).
  • Both agent:preview and agent:preview:start accept both flags together.
  • Deliberately no delimiter on the JSON flag, so commas inside a List/Object/JSON value are safe (unlike --context-variables, which splits on ,).
  • Help text and command snapshot updated.

Notes

Tests

yarn test green (30 flags tests, including parseContextVariablesJson and mergeContextVariables coverage).

--context-variables can only send Text, so a boolean-gated route
(available when @variables.x == True) never opens: the runtime compares
the string "True" against boolean True. Add --context-variables-json,
which takes a JSON array of typed variables ({ name, type, value })
matching the preview API's Variable schema, so Boolean/Number/Object/
List/Json values reach the wire with the correct type.

The JSON flag has no comma delimiter, so List/Object values (and any
comma-bearing value) are safe, unlike --context-variables. Both flags can
be combined; on a duplicate name the JSON entry wins. Each entry is
validated at parse time: name required, type in the enum, and value shape
checked against type.

Requires @salesforce/agents with the typed ContextVariable union.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant