feat(sdk): add triggerConfig support to chat.headStart()#3933
feat(sdk): add triggerConfig support to chat.headStart()#3933saasjesus wants to merge 2 commits into
Conversation
Handover-prepare session runs now accept the same tags, queue, and
session trigger options as chat.createStartSessionAction(), with
chat:{chatId} auto-prepended to tags.
Co-authored-by: Cursor <cursoragent@cursor.com>
SessionTriggerConfig.tags allows at most 5 entries; align createChatStartSessionAction with chat.headStart and the Zod schema. Co-authored-by: Cursor <cursoragent@cursor.com>
🦋 Changeset detectedLatest commit: f40af00 The changes in this PR will be included in the next version bump. This PR includes changesets to release 25 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📜 Recent review details🧰 Additional context used📓 Path-based instructions (9)packages/trigger-sdk/**/*.{ts,tsx}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
**/*.{ts,tsx}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
**/*.{test,spec}.{ts,tsx}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
**/*.ts📄 CodeRabbit inference engine (.cursor/rules/otel-metrics.mdc)
Files:
**/*.test.{ts,tsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
packages/trigger-sdk/**/*.{js,ts,jsx,tsx}📄 CodeRabbit inference engine (packages/trigger-sdk/CLAUDE.md)
Files:
**/*.{js,ts,tsx,jsx,css,json,md}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.test.{js,ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (12)📚 Learning: 2026-03-22T13:26:12.060ZApplied to files:
📚 Learning: 2026-03-22T19:24:14.403ZApplied to files:
📚 Learning: 2026-05-18T08:21:27.694ZApplied to files:
📚 Learning: 2026-05-18T08:21:27.694ZApplied to files:
📚 Learning: 2026-03-31T21:37:27.212ZApplied to files:
📚 Learning: 2026-05-17T08:08:12.370ZApplied to files:
📚 Learning: 2026-05-18T14:19:56.437ZApplied to files:
📚 Learning: 2026-05-18T14:40:02.173ZApplied to files:
📚 Learning: 2026-05-18T14:40:02.173ZApplied to files:
📚 Learning: 2026-05-19T22:37:47.286ZApplied to files:
📚 Learning: 2026-06-04T18:16:35.386ZApplied to files:
📚 Learning: 2026-06-09T17:58:04.699ZApplied to files:
🔇 Additional comments (8)
WalkthroughThis PR extends the chat SDK to allow 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| const triggerConfig: SessionTriggerConfig = { | ||
| basePayload: { | ||
| ...(opts.triggerConfig?.basePayload ?? {}), | ||
| ...wirePayload, | ||
| chatId, | ||
| trigger: "handover-prepare", | ||
| idleTimeoutInSeconds, | ||
| }, | ||
| ...(opts.triggerConfig?.machine ? { machine: opts.triggerConfig.machine } : {}), | ||
| ...(opts.triggerConfig?.queue ? { queue: opts.triggerConfig.queue } : {}), | ||
| tags, | ||
| ...(opts.triggerConfig?.maxAttempts !== undefined | ||
| ? { maxAttempts: opts.triggerConfig.maxAttempts } | ||
| : {}), | ||
| ...(opts.triggerConfig?.maxDuration !== undefined | ||
| ? { maxDuration: opts.triggerConfig.maxDuration } | ||
| : {}), | ||
| ...(opts.triggerConfig?.region ? { region: opts.triggerConfig.region } : {}), | ||
| ...(opts.triggerConfig?.lockToVersion | ||
| ? { lockToVersion: opts.triggerConfig.lockToVersion } | ||
| : {}), | ||
| idleTimeoutInSeconds, | ||
| }; |
There was a problem hiding this comment.
🚩 headStart handles more triggerConfig fields than createStartSessionAction
The new openHandoverSession in chat-server.ts:342-364 forwards maxDuration, lockToVersion, and region from the user's triggerConfig, while the existing createChatStartSessionAction in ai.ts:9719-9750 does NOT handle these three fields. This means customers using chat.headStart can configure maxDuration/lockToVersion/region, but customers using chat.createStartSessionAction cannot. This is a pre-existing gap in createChatStartSessionAction, not introduced by this PR, but the two APIs are now inconsistent. Consider adding these fields to createChatStartSessionAction in a follow-up for parity.
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
triggerConfigtochat.headStart()andchat.openSession(), threading it throughopenHandoverSessionintocreateSession.chat.createStartSessionAction(), auto-prependingchat:{chatId}to tags.idleTimeoutInSecondsstill wins overtriggerConfig.idleTimeoutInSeconds;handover-preparetrigger andchatIdinbasePayloadcannot be overridden by customer config.createChatStartSessionAction:SessionTriggerConfig.tagsallows at most 5 (per schema), but the preload path was slicing to 10 — now both session entry points cap at 5.Why this matters
openHandoverSessionis the session-entry path on turn 0 for head-start chats. BecausecreateSessionis idempotent on(env, externalId = chatId), that first call fixes the session'striggerConfigfor its whole lifetime — a latercreateStartSessionActioncannot retroactively add tags to a session head-start already created.Test plan
cd packages/trigger-sdk && pnpm test src/v3/chat-server.test.ts src/v3/createStartSessionAction.test.ts --runchat-server.test.ts: merged tags (chat:chat-1first) and queue oncreateSessioncreateStartSessionAction.test.ts: tag prepend + cap at 5chat.headStart({ triggerConfig: { tags, queue } })and verify handover-prepare run tags/queue in dashboardMade with Cursor