Commit 7719150
committed
feat(cli): MCP agentChat tool → Sessions migration
Rewires the three MCP agent-chat tools onto the Session primitive so
they stay in sync with TriggerChatTransport and the server-side
AgentChat after the chat.agent -> Sessions migration.
Tools affected: start_agent_chat, send_agent_message, close_agent_chat.
All live in packages/cli-v3/src/mcp/tools/agentChat.ts.
Changes
- Drop imports of CHAT_STREAM_KEY / CHAT_MESSAGES_STREAM_ID /
CHAT_STOP_STREAM_ID from @trigger.dev/core/v3/chat-client. Add a
local ChatInputChunk type + serializeInputChunk helper that mirrors
the transport's wire format (JSON.stringify({ kind, payload })).
- start_agent_chat: call apiClient.createSession({ type:
"chat.agent", externalId: chatId }) before triggering. The call is
idempotent on externalId so two MCP clients targeting the same
chatId converge. Thread sessionId into the trigger payload so the
agent's sessions.open(payload.sessionId) finds the backing session.
- send_agent_message: replace
sendInputStream(runId, CHAT_MESSAGES_STREAM_ID, payload) with
appendToSessionStream(sessionId, "in",
serializeInputChunk({ kind: "message", payload })). Fall-back path
on send failure re-triggers on the same session (reuse sessionId,
swap runId) instead of creating a new chat.
- close_agent_chat: send { kind: "message", payload: { trigger:
"close", ... } } via appendToSessionStream so the agent's turn loop
exits cleanly — matches the transport's close semantics.
- collectAgentResponse: subscribe URL moves from
/realtime/v1/streams/{runId}/chat to
/realtime/v1/sessions/{sessionId}/out. Session SSE uses v2/batch
format which already delivers parsed UIMessageChunk objects via
record.body.data, so the chunk-switch logic is unchanged.
trigger:upgrade-required path keeps the same session and triggers
a new run — previously it reused the old /streams/{newRunId}/chat
URL, now the URL is stable across runs on the same session.
- Scopes: write:inputStreams -> read:sessions + write:sessions. The
former was the transport's old input-stream write capability; the
session endpoints are the new surface.
- ChatSession state grows a sessionId field (friendlyId session_*).
runId stays but is now a live-run hint rather than durable identity.
Known limitation: the MCP server binary was spawned by Claude Code
at session start from the pre-migration bundle and stays in memory
for the lifetime of the Claude session — runtime verification has to
wait for the next session restart. Build passes; dist bundle
contains the new createSession / appendToSessionStream /
realtime/v1/sessions / Session ID references.1 parent c2a851c commit 7719150
2 files changed
Lines changed: 80 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | 3 | | |
9 | 4 | | |
10 | 5 | | |
11 | | - | |
12 | 6 | | |
13 | 7 | | |
14 | 8 | | |
| |||
19 | 13 | | |
20 | 14 | | |
21 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
22 | 19 | | |
23 | 20 | | |
24 | 21 | | |
| |||
31 | 28 | | |
32 | 29 | | |
33 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
34 | 49 | | |
35 | 50 | | |
36 | 51 | | |
| |||
75 | 90 | | |
76 | 91 | | |
77 | 92 | | |
78 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
79 | 99 | | |
80 | 100 | | |
81 | 101 | | |
| |||
93 | 113 | | |
94 | 114 | | |
95 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
96 | 123 | | |
97 | | - | |
| 124 | + | |
| 125 | + | |
98 | 126 | | |
99 | 127 | | |
100 | 128 | | |
| 129 | + | |
101 | 130 | | |
102 | 131 | | |
103 | 132 | | |
| |||
111 | 140 | | |
112 | 141 | | |
113 | 142 | | |
| 143 | + | |
114 | 144 | | |
115 | 145 | | |
116 | 146 | | |
| |||
126 | 156 | | |
127 | 157 | | |
128 | 158 | | |
| 159 | + | |
129 | 160 | | |
130 | 161 | | |
131 | 162 | | |
| |||
136 | 167 | | |
137 | 168 | | |
138 | 169 | | |
139 | | - | |
| 170 | + | |
140 | 171 | | |
| 172 | + | |
141 | 173 | | |
142 | 174 | | |
143 | 175 | | |
| |||
153 | 185 | | |
154 | 186 | | |
155 | 187 | | |
| 188 | + | |
156 | 189 | | |
157 | 190 | | |
158 | 191 | | |
| |||
193 | 226 | | |
194 | 227 | | |
195 | 228 | | |
196 | | - | |
| 229 | + | |
197 | 230 | | |
198 | 231 | | |
199 | | - | |
| 232 | + | |
200 | 233 | | |
201 | 234 | | |
202 | 235 | | |
203 | | - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
204 | 239 | | |
205 | 240 | | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
210 | 245 | | |
211 | 246 | | |
212 | | - | |
213 | 247 | | |
214 | 248 | | |
215 | 249 | | |
216 | 250 | | |
| 251 | + | |
217 | 252 | | |
218 | 253 | | |
219 | 254 | | |
| |||
228 | 263 | | |
229 | 264 | | |
230 | 265 | | |
231 | | - | |
| 266 | + | |
232 | 267 | | |
233 | | - | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
234 | 272 | | |
235 | 273 | | |
236 | 274 | | |
| |||
277 | 315 | | |
278 | 316 | | |
279 | 317 | | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
288 | 329 | | |
289 | 330 | | |
290 | 331 | | |
| |||
310 | 351 | | |
311 | 352 | | |
312 | 353 | | |
313 | | - | |
| 354 | + | |
314 | 355 | | |
315 | 356 | | |
316 | 357 | | |
| |||
340 | 381 | | |
341 | 382 | | |
342 | 383 | | |
| 384 | + | |
| 385 | + | |
343 | 386 | | |
344 | 387 | | |
345 | 388 | | |
| |||
348 | 391 | | |
349 | 392 | | |
350 | 393 | | |
351 | | - | |
| 394 | + | |
| 395 | + | |
352 | 396 | | |
353 | 397 | | |
354 | 398 | | |
355 | 399 | | |
356 | 400 | | |
| 401 | + | |
357 | 402 | | |
358 | 403 | | |
359 | 404 | | |
| |||
367 | 412 | | |
368 | 413 | | |
369 | 414 | | |
370 | | - | |
| 415 | + | |
371 | 416 | | |
372 | 417 | | |
373 | 418 | | |
| |||
0 commit comments