Repository navigation
feat: replace product-context prefix hack with SCRT2 session-context API - #3
Merged
Merged
Conversation
shilpi1998
force-pushed
the
context-api
branch
3 times, most recently
from
September 30, 2026 23:57
0290c5a to
e063c4e
Compare
Replace the text-prefix approach ("Viewing product details for inline-widget:")
with structured SCRT2 v2 session-context variables (page_context_type,
page_context_message, page_context_data). The shopper's message text is now
sent unchanged; product context travels in the SessionContextSet envelope.
- client.sendMessage() accepts optional contextVariables param
- buildPdpInlineContext() replaces withProductContext()
- Default capabilitiesVersion bumped "1" → "66" (minimum for session context)
- New SDK types: SessionContextVariable, SessionContextEntry, SendMessageResponse
- Added tests for context envelope construction and omission
shilpi1998
force-pushed
the
context-api
branch
from
October 1, 2026 00:01
e063c4e to
451c899
Compare
…t object
Replace page_context_type, page_context_message, page_context_data with
a single page_context variable containing a JSON-encoded object
{ type, message, data }. BYON deserializes on its side — simpler
contract, easier to extend.
Keep data as a pre-serialized JSON string instead of a generic object — simpler contract, BYON parses it on its side.
… names Use embedded_agent_context as the SCRT2 variable name. Keep page_context_type, page_context_message, page_context_data as the JSON object keys for consistency with existing contexts.
# Conflicts: # src/provider/WidgetProvider.tsx # src/provider/types.ts
Rename agent_context → commerce_agent_context, add version field, make page_context_data a nested object, remove page_context_message.
The SCRT2 API silently drops Object-typed variables sent as TextValue. Use StructuredValue so the BYON agent receives the context as a native object instead of a JSON string it would need to parse.
shilpi1998
approved these changes
Oct 7, 2026
3 tasks
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.
Summary
Replace the text-prefix hack (
Viewing product details for: <id>) with the proper SCRT2 v2 session-context API. Product context is now sent as a singlecommerce_agent_contextvariable (Object /StructuredValue) alongside the message, leaving the shopper's message text untouched.What changed
AgentforceClient.sendMessage(text, contextVariables?)— accepts optional context variables and wraps them in aSessionContextSetenvelope on the/conversation/{id}/messageendpoint.buildPdpInlineContext(productId)replaceswithProductContext()— builds a singlecommerce_agent_contextvariable as aStructuredValuecontaining:{ "version": "1.0.0", "page_context_type": "pdp_inline", "page_context_data": { "id": "<productId>" } }commerce_agent_contextas an Object type variable, parsespage_context_type, and transitions to the appropriate topic accordingly.resolveProductId()strategies (query param, path pattern, PWA fallback, SFRA DOM).warningresponses (message accepted but context variables dropped) are logged.capabilitiesVersionchanged to"65"— the minimum that supports session-context variables.SessionContextTextValue,SessionContextStructuredValue,SessionContextVariable,CommerceAgentContext.demo/index.htmlupdated withproduct-id-param="pid",capabilities-version="65", and a demo script to seed thepidquery param.Why
StructuredValueinstead ofTextValueThe SCRT2 API silently drops Object-typed variables sent as
TextValue(soft rejection — no error, the variable just disappears). UsingStructuredValueensures the BYON agent receives the context as a native object.Test plan
npm run typecheck— cleannpm test— 195 passed (13 test files)npm run build— ESM + UMD both succeedStructuredValuecontext envelope in the network request, agent parsedpage_context_typeand transitioned toproduct_inline_pdptopiccontextfield in the request body