feat: add --context-variables-json for typed preview context variables - #483
Open
nico-pappagianis wants to merge 4 commits into
Open
feat: add --context-variables-json for typed preview context variables#483nico-pappagianis wants to merge 4 commits into
nico-pappagianis wants to merge 4 commits into
Conversation
--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
Add test/nuts/z3.agent.preview.context-variables.nut.ts covering the --context-variables-json flag end-to-end via trace inspection: all wire types (Text/Number/Boolean/Json/List) round-trip in one session, the JSON flag wins over --context-variables on a duplicate name, a comma-bearing value survives the JSON flag (with the old flag as a mangling control), the server rejects an Internal variable, and a type-mismatched value is rejected client-side. Augment the Willie_Resort_Manager fixture with five typed External probe variables (NutProbeText/Bool/Num/Obj/List) so the injected values can be observed in the session trace.
Reuse the Bot User pre-provisioned in shared setup by writing agentUser into the spec, instead of letting core auto-create one in the same transaction as the BotDefinition save. That auto-create intermittently races the pre-save validation trigger and fails with "User doesn't have access to agent". Mirrors #484.
|
|
||
| Typed session variables for the agent preview session, as a JSON array. | ||
|
|
||
| # flags.context-variables-json.description |
Collaborator
Author
There was a problem hiding this comment.
I went with context-variables-json instead of context-variables-object because object already means something in context variable land (a type of variable) so the name was a bit confusing. Plus, it is JSON.
| const contextVariables = mergeContextVariables( | ||
| parseContextVariables(flags['context-variables']), | ||
| parseContextVariablesJson(flags['context-variables-json']) | ||
| ); |
Collaborator
Author
There was a problem hiding this comment.
When merging context-variables and context-variables-json, context-variables-json wins out if there are duplicated variables.
| } | ||
|
|
||
| function toContextVariable(entry: unknown, index: number): ContextVariable { | ||
| if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) { |
Collaborator
Author
There was a problem hiding this comment.
Array.isArray is just checking the format is not an array since it must be a json object.
e.g. reject [["x"]] or [[{"name":"a"}]]
nico-pappagianis
marked this pull request as ready for review
August 28, 2026 22:23
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
Adds a new
--context-variables-jsonflag tosf agent previewandsf agent preview startso callers can send typed context variables (Boolean, Number, Object, List, Json) to the preview API, not justText.Why
--context-variables(the existingName=Valueflag) hard-codes every value as typeText. A boolean-gated route (for exampleavailable when @variables.probeGate == True) never opens, because the runtime compares the string"True"against the booleanTrue. See W-24014400.The new flag matches the preview API's own
Variableschema (a discriminated union keyed ontype), so a value is sent with the correct JSON type on the wire.How
contextVariablesJsonFlaginsrc/flags.ts, plusparseContextVariablesJson(validates JSON shape and that eachvaluematches its declaredtype) andmergeContextVariables(merges the text-form and JSON-form variables; on a duplicate name the JSON entry wins, keeping the text entry's position).agent:previewandagent:preview:startaccept both flags together.delimiteron the JSON flag, so commas inside a List/Object/JSON value are safe (unlike--context-variables, which splits on,).Notes
ContextVariablediscriminated union in@salesforce/agents(PR Feat/eval state injection @W-21514105@ #356). This branch currently builds against a localyarn linkof that SDK; once Feat/eval state injection @W-21514105@ #356 releases, bump the@salesforce/agentsversion here to drop the link.Tests
yarn testgreen (30 flags tests, includingparseContextVariablesJsonandmergeContextVariablescoverage).