Skip to content

feat: replace product-context prefix hack with SCRT2 session-context API - #3

Merged
chintandesai-cimulate merged 9 commits into
mainfrom
context-api
Oct 7, 2026
Merged

chintandesai-cimulate merged 9 commits into
mainfrom
context-api

Conversation

@chintandesai-cimulate

@chintandesai-cimulate chintandesai-cimulate commented Aug 28, 2026 •

Copy link
Copy Markdown
Collaborator

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 single commerce_agent_context variable (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 a SessionContextSet envelope on the /conversation/{id}/message endpoint.
  • buildPdpInlineContext(productId) replaces withProductContext() — builds a single commerce_agent_context variable as a StructuredValue containing:
    {
      "version": "1.0.0",
      "page_context_type": "pdp_inline",
      "page_context_data": { "id": "<productId>" }
    }
  • The agent declares commerce_agent_context as an Object type variable, parses page_context_type, and transitions to the appropriate topic accordingly.
  • Product ID is resolved fresh on every send (agent clears external context after each turn) via the same resolveProductId() strategies (query param, path pattern, PWA fallback, SFRA DOM).
  • SCRT2 warning responses (message accepted but context variables dropped) are logged.
  • Default capabilitiesVersion changed to "65" — the minimum that supports session-context variables.
  • New SDK types exported: SessionContextTextValue, SessionContextStructuredValue, SessionContextVariable, CommerceAgentContext.
  • demo/index.html updated with product-id-param="pid", capabilities-version="65", and a demo script to seed the pid query param.

Why StructuredValue instead of TextValue

The SCRT2 API silently drops Object-typed variables sent as TextValue (soft rejection — no error, the variable just disappears). Using StructuredValue ensures the BYON agent receives the context as a native object.

Test plan

  • npm run typecheck — clean
  • npm test — 195 passed (13 test files)
  • npm run build — ESM + UMD both succeed
  • End-to-end: sent a message on a PDP page, verified the StructuredValue context envelope in the network request, agent parsed page_context_type and transitioned to product_inline_pdp topic
  • Manual: send a message on a non-PDP page and verify no context field in the request body

@shilpi1998
shilpi1998 force-pushed the context-api branch 3 times, most recently from 0290c5a to e063c4e Compare September 30, 2026 23:57
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 shilpi1998 changed the title feat: PDP session-context API + default-on session persistence feat: replace product-context prefix hack with SCRT2 session-context API Oct 1, 2026
…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.
@chintandesai-cimulate
chintandesai-cimulate merged commit 9329d3d into main Oct 7, 2026
1 check passed
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.

2 participants