Commit 7e91abb
committed
feat(sdk,playground,ai-chat): chat.agent on Sessions-as-run-manager
chat.agent now runs on top of the Session-as-run-manager primitive.
Public surface (`chat.agent({...})`, `useTriggerChatTransport`,
`chat.store` / `chat.defer` / `chat.history`, `AgentChat`) is unchanged;
the wiring underneath moves from per-run streams to the durable Session
row that owns its own runs.
Transport (TriggerChatTransport):
- Drop `getStartToken`. Replace with
`startSession({chatId, taskId, clientData}) => {publicAccessToken}` —
wraps a server action that calls `chat.createStartSessionAction`.
Idempotent on `(env, externalId)`.
- `clientData` (typed via `withClientData`) is threaded through
`startSession`'s params, so the first run's `basePayload.metadata`
matches per-turn `metadata`. Live-updated via `setClientData` when
the hook's `clientData` option changes.
- Drop transport-level `triggerConfig` / `triggerOptions` /
`idleTimeoutInSeconds`. All trigger config lives server-side in the
customer's `chat.createStartSessionAction(taskId, options)`.
- `transport.preload(chatId)` and lazy first `sendMessage` both route
through `startSession`, deduped via the in-flight pendingStarts map.
- `ChatSession` persistable shape drops `runId`; just `{lastEventId}`.
chat.agent runtime:
- New `chat.createStartSessionAction(taskId, options?)` — server-side
wrapper that calls `sessions.start` with `basePayload.{messages:[],
trigger: "preload"}` defaults plus the customer's overrides. Returns
`{sessionId, runId, publicAccessToken}`.
- `chat.requestUpgrade` calls `apiClient.endAndContinueSession` before
emitting the `trigger:upgrade-required` chunk. Server orchestrates
the swap; browser keeps streaming across the run handoff.
Webapp dashboard:
- Playground: `startSession` + `accessToken` both wired through the
Remix action (idempotent server-side start path). Preload button
now works. New session proxy routes for HEAD/GET on `/out` and POST
on `/in/append`; old run-stream proxies deleted.
- Run inspector Agent tab: SSE proxy now uses the canonical addressing
key (externalId if set, else friendlyId), matching what the agent
writes via `session.out`. Fixes the case where the Agent tab read
from a different S2 stream than the agent wrote to.
References (ai-chat):
- `chat-view` useEffect dance gone (just hydrates `initialSession`).
- `chat-app` `transport.preload(id)` routes through `startSession`.
- New `upgrade-test` agent + sidebar option for exercising
`chat.requestUpgrade` end-to-end.
- `ChatSession` schema simplified: drop `runId` / `sessionId`, keep
`publicAccessToken` + `lastEventId`.
- `chat-client-test` fixed for the new transport shape.
- Hello-world smoke stubs gutted to TODO placeholders — sessions
are now task-bound, so standalone-session smokes need rewriting.1 parent 31cec28 commit 7e91abb
29 files changed
Lines changed: 2053 additions & 4509 deletions
File tree
- apps/webapp/app/routes
- _app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.playground.$agentParam
- packages
- core/src/v3/apiClient
- trigger-sdk/src/v3
- test
- references
- ai-chat
- prisma
- migrations/20260427053743_simplify_chat_session_for_run_manager
- src
- app
- chats/[chatId]
- components
- trigger
- hello-world/src/trigger
Lines changed: 41 additions & 48 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
| |||
219 | 218 | | |
220 | 219 | | |
221 | 220 | | |
222 | | - | |
223 | | - | |
224 | | - | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
225 | 227 | | |
226 | | - | |
| 228 | + | |
227 | 229 | | |
228 | 230 | | |
229 | | - | |
230 | 231 | | |
231 | 232 | | |
232 | 233 | | |
| |||
243 | 244 | | |
244 | 245 | | |
245 | 246 | | |
246 | | - | |
247 | | - | |
| 247 | + | |
| 248 | + | |
248 | 249 | | |
249 | 250 | | |
250 | 251 | | |
251 | 252 | | |
252 | 253 | | |
253 | 254 | | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | 255 | | |
270 | 256 | | |
271 | | - | |
| 257 | + | |
272 | 258 | | |
273 | 259 | | |
274 | 260 | | |
| |||
280 | 266 | | |
281 | 267 | | |
282 | 268 | | |
283 | | - | |
284 | | - | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
285 | 279 | | |
286 | 280 | | |
287 | | - | |
| 281 | + | |
288 | 282 | | |
289 | 283 | | |
290 | 284 | | |
291 | | - | |
292 | 285 | | |
293 | 286 | | |
294 | 287 | | |
| |||
299 | 292 | | |
300 | 293 | | |
301 | 294 | | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | 295 | | |
312 | 296 | | |
313 | 297 | | |
| |||
382 | 366 | | |
383 | 367 | | |
384 | 368 | | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
| 369 | + | |
389 | 370 | | |
390 | 371 | | |
391 | 372 | | |
| |||
467 | 448 | | |
468 | 449 | | |
469 | 450 | | |
470 | | - | |
471 | | - | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
472 | 456 | | |
473 | 457 | | |
474 | 458 | | |
| |||
524 | 508 | | |
525 | 509 | | |
526 | 510 | | |
527 | | - | |
| 511 | + | |
528 | 512 | | |
529 | 513 | | |
530 | 514 | | |
| |||
646 | 630 | | |
647 | 631 | | |
648 | 632 | | |
| 633 | + | |
649 | 634 | | |
650 | 635 | | |
651 | 636 | | |
| |||
696 | 681 | | |
697 | 682 | | |
698 | 683 | | |
| 684 | + | |
699 | 685 | | |
700 | 686 | | |
701 | 687 | | |
| |||
722 | 708 | | |
723 | 709 | | |
724 | 710 | | |
725 | | - | |
726 | | - | |
727 | 711 | | |
728 | 712 | | |
729 | 713 | | |
730 | 714 | | |
731 | 715 | | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
732 | 723 | | |
733 | 724 | | |
734 | 725 | | |
| |||
971 | 962 | | |
972 | 963 | | |
973 | 964 | | |
974 | | - | |
| 965 | + | |
975 | 966 | | |
976 | | - | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
977 | 970 | | |
978 | 971 | | |
979 | 972 | | |
| |||
0 commit comments