Skip to content

Commit 4c3a039

Browse files
committed
feat(sdk,core): drop legacy chat stream-ID constants
Final Phase F cleanup — `CHAT_STREAM_KEY`, `CHAT_MESSAGES_STREAM_ID`, and `CHAT_STOP_STREAM_ID` were meaningful only when chat.agent I/O lived on run-scoped Redis streams. The Session migration moved all chat I/O onto the backing Session's `.in` / `.out` channels, so these constants stopped describing how anything is addressed months ago and have been dead-weight re-exports since. Dropped from the public surface: - `@trigger.dev/core/v3/chat-client` no longer exports the three constants. The file keeps `ChatStoreChunk` + `applyChatStorePatch` (the chat.store primitive's shared types). - `@trigger.dev/sdk/ai` no longer re-exports them via the `CHAT_STREAM_KEY` / `CHAT_MESSAGES_STREAM_ID` / `CHAT_STOP_STREAM_ID` aliases introduced by the migration commit. - Deletes `packages/trigger-sdk/src/v3/chat-constants.ts` (the shim that bridged core's definitions to the SDK's public surface). What stayed the same: - `chat.stream.id` / `chat.messages.id` / `chat.stopSignal.id` still contain the literal strings `"chat"` / `"chat-messages"` / `"chat-stop"` — inlined as opaque breadcrumbs rather than user-consumable constants. Telemetry attrs keep the same values, so dashboards/spans don't shift. - All runtime behavior is untouched. The `chatStream` / `messagesInput` / `stopInput` facades still delegate through the Session handle exactly as before; only the constant symbols are gone. Migration note for external callers: Anyone still importing the old constants should migrate to the session primitives: - `streams.writer(CHAT_STREAM_KEY, …)` → `sessions.open(sessionId).out.writer(…)` - `streams.input(CHAT_MESSAGES_STREAM_ID)` → `sessions.open(sessionId).in.on(…)` (filtered by `chunk.kind === "message"`) - `streams.input(CHAT_STOP_STREAM_ID)` → `sessions.open(sessionId).in.on(…)` (filtered by `chunk.kind === "stop"`) Validated - 86/86 SDK tests green. - Webapp typecheck clean (core types used in SpanPresenter + AgentView are untouched). - ai-chat UI smoke passes end-to-end: new chat → send "Say hi in three words." → first assistant text in 4.9s → sessionId + runId + lastEventId all set.
1 parent 88c8f4d commit 4c3a039

5 files changed

Lines changed: 35 additions & 56 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@trigger.dev/sdk": patch
3+
"@trigger.dev/core": patch
4+
---
5+
6+
Drop the pre-Sessions chat stream-ID constants from the public surface:
7+
8+
- `CHAT_STREAM_KEY`, `CHAT_MESSAGES_STREAM_ID`, `CHAT_STOP_STREAM_ID` are no longer exported from `@trigger.dev/sdk/ai` or `@trigger.dev/core/v3/chat-client`. Deletes `packages/trigger-sdk/src/v3/chat-constants.ts`.
9+
- The `chat.stream.id` / `chat.messages.id` / `chat.stopSignal.id` labels still contain the same string values (`"chat"` / `"chat-messages"` / `"chat-stop"`) — now inlined as opaque breadcrumbs rather than user-consumable constants. Behavior and telemetry attrs are unchanged.
10+
11+
These constants only mattered before the chat.agent I/O moved onto the Session primitive — the SDK no longer writes to run-scoped `streams.writer(CHAT_STREAM_KEY, …)` / `streams.input(CHAT_*_STREAM_ID)` at all. Customers who still referenced them externally should migrate to `sessions.open(sessionId).out.writer(...)` / `sessions.open(sessionId).in.on(...)` — same primitives, now session-keyed.

packages/core/src/v3/chat-client.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
/**
2-
* Chat constants shared between backend (ai.ts) and frontend (chat.ts).
3-
* The ChatClient class lives in @trigger.dev/sdk/chat.
2+
* Chat shared types used by backend (ai.ts) and frontend (chat.ts)
3+
* code paths — primarily {@link ChatStoreChunk} + {@link applyChatStorePatch}
4+
* for the `chat.store` primitive. Pre-Session transport also exported
5+
* `CHAT_STREAM_KEY` / `CHAT_MESSAGES_STREAM_ID` / `CHAT_STOP_STREAM_ID`
6+
* from here; those are gone — chat output and input both live on the
7+
* backing Session now (see `@trigger.dev/sdk/sessions`).
48
*/
59

6-
/** The output stream key where UIMessageChunks are written. */
7-
export const CHAT_STREAM_KEY = "chat";
8-
9-
/** Input stream ID for sending chat messages to the running task. */
10-
export const CHAT_MESSAGES_STREAM_ID = "chat-messages";
11-
12-
/** Input stream ID for sending stop signals to abort the current generation. */
13-
export const CHAT_STOP_STREAM_ID = "chat-stop";
14-
1510
// ─── chat.store chunk types ────────────────────────────────────────
1611
//
1712
// First-class chunk types for `chat.store` — bidirectional shared data

packages/trigger-sdk/src/v3/ai.ts

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,6 @@ import { tracer } from "./tracer.js";
9696

9797
/** Re-export for typing `ctx` in `chat.agent` hooks without importing `@trigger.dev/core`. */
9898
export type { TaskRunContext } from "@trigger.dev/core/v3";
99-
import {
100-
CHAT_STREAM_KEY as _CHAT_STREAM_KEY,
101-
CHAT_MESSAGES_STREAM_ID,
102-
CHAT_STOP_STREAM_ID,
103-
} from "./chat-constants.js";
10499
import {
105100
applyChatStorePatch,
106101
type ChatStoreChunk,
@@ -145,9 +140,8 @@ const chatTurnContextKey = locals.create<ChatTurnContext>("chat.turnContext");
145140
* Per-run slot holding the Session handle that backs this chat's `.in` /
146141
* `.out` channels. Populated at the top of `chatAgent`'s run function from
147142
* `payload.sessionId`; read by every module-level helper (`chatStream`,
148-
* `messagesInput`, `stopInput`, `streams.writer(CHAT_STREAM_KEY, …)`
149-
* callers) so the chat.agent internals can remain the same module-level
150-
* shape they were when the I/O was run-scoped.
143+
* `messagesInput`, `stopInput`) so the chat.agent internals can remain
144+
* the same module-level shape they were when the I/O was run-scoped.
151145
* @internal
152146
*/
153147
const chatSessionHandleKey = locals.create<SessionHandle>("chat.sessionHandle");
@@ -500,16 +494,6 @@ function createChatAccessToken<TTask extends AnyTask>(
500494
// Chat transport helpers — backend side
501495
// ---------------------------------------------------------------------------
502496

503-
/**
504-
* The default stream key used for chat transport communication.
505-
* Both `TriggerChatTransport` (frontend) and `pipeChat`/`chatAgent` (backend)
506-
* use this key by default.
507-
*/
508-
export const CHAT_STREAM_KEY = _CHAT_STREAM_KEY;
509-
510-
// Re-export input stream IDs for advanced usage
511-
export { CHAT_MESSAGES_STREAM_ID, CHAT_STOP_STREAM_ID };
512-
513497
/**
514498
* Typed chat output stream — `.writer()`, `.pipe()`, `.append()`, and
515499
* `.read()` methods pre-bound to this run's Session `.out` channel and
@@ -533,7 +517,12 @@ export { CHAT_MESSAGES_STREAM_ID, CHAT_STOP_STREAM_ID };
533517
* options on `.pipe()` are honoured as no-ops; the session is the target.
534518
*/
535519
const chatStream: RealtimeDefinedStream<UIMessageChunk> = {
536-
id: _CHAT_STREAM_KEY,
520+
// Stable opaque label for the run-scoped `RealtimeDefinedStream` shape.
521+
// `chatStream` is backed by the Session's `.out` channel — this id is
522+
// not the real addressing key (the session is). Kept as a literal so
523+
// the facade type stays satisfied without re-introducing a top-level
524+
// constant; dashboards/telemetry that already read "chat" keep working.
525+
id: "chat",
537526
pipe(value, options) {
538527
const { target: _target, ...sessionOptions } = (options ?? {}) as PipeStreamOptions;
539528
return getChatSession().out.pipe<UIMessageChunk>(
@@ -966,7 +955,7 @@ export type ChatTaskRunPayload<TClientData = unknown> = ChatTaskPayload<TClientD
966955
// lazily via `getChatSession()` so the module-level references stay
967956
// compatible with the pre-migration wiring.
968957
const messagesInput: RealtimeDefinedInputStream<ChatTaskWirePayload> = {
969-
id: CHAT_MESSAGES_STREAM_ID,
958+
id: "chat-messages",
970959
on(handler) {
971960
return getChatSession().in.on<ChatInputChunk>((chunk) => {
972961
if (chunk.kind === "message") {
@@ -1003,12 +992,12 @@ const messagesInput: RealtimeDefinedInputStream<ChatTaskWirePayload> = {
1003992
[SemanticInternalAttributes.ENTITY_TYPE]: "input-stream",
1004993
...(runId
1005994
? {
1006-
[SemanticInternalAttributes.ENTITY_ID]: `${runId}:${CHAT_MESSAGES_STREAM_ID}`,
995+
[SemanticInternalAttributes.ENTITY_ID]: `${runId}:chat-messages`,
1007996
}
1008997
: {}),
1009-
streamId: CHAT_MESSAGES_STREAM_ID,
998+
streamId: "chat-messages",
1010999
...accessoryAttributes({
1011-
items: [{ text: CHAT_MESSAGES_STREAM_ID, variant: "normal" }],
1000+
items: [{ text: "chat-messages", variant: "normal" }],
10121001
style: "codepath",
10131002
}),
10141003
},
@@ -1067,7 +1056,7 @@ const messagesInput: RealtimeDefinedInputStream<ChatTaskWirePayload> = {
10671056
};
10681057

10691058
const stopInput: RealtimeDefinedInputStream<{ stop: true; message?: string }> = {
1070-
id: CHAT_STOP_STREAM_ID,
1059+
id: "chat-stop",
10711060
on(handler) {
10721061
return getChatSession().in.on<ChatInputChunk>((chunk) => {
10731062
if (chunk.kind === "stop") {
@@ -1105,12 +1094,12 @@ const stopInput: RealtimeDefinedInputStream<{ stop: true; message?: string }> =
11051094
[SemanticInternalAttributes.ENTITY_TYPE]: "input-stream",
11061095
...(runId
11071096
? {
1108-
[SemanticInternalAttributes.ENTITY_ID]: `${runId}:${CHAT_STOP_STREAM_ID}`,
1097+
[SemanticInternalAttributes.ENTITY_ID]: `${runId}:chat-stop`,
11091098
}
11101099
: {}),
1111-
streamId: CHAT_STOP_STREAM_ID,
1100+
streamId: "chat-stop",
11121101
...accessoryAttributes({
1113-
items: [{ text: CHAT_STOP_STREAM_ID, variant: "normal" }],
1102+
items: [{ text: "chat-stop", variant: "normal" }],
11141103
style: "codepath",
11151104
}),
11161105
},
@@ -3686,8 +3675,8 @@ function chatAgent<
36863675
locals.set(chatAgentRunContextKey, ctx);
36873676

36883677
// Bind the run to its backing Session so every module-level helper
3689-
// (chat.stream, chat.messages, streams.writer(CHAT_STREAM_KEY, …))
3690-
// resolves to this chat's `.in` / `.out` channels.
3678+
// (chat.stream, chat.messages, chat.stopSignal) resolves to this
3679+
// chat's `.in` / `.out` channels.
36913680
//
36923681
// The transport opens/creates the session with `externalId = chatId`
36933682
// and threads its friendlyId through `payload.sessionId`. For legacy

packages/trigger-sdk/src/v3/chat-constants.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/trigger-sdk/src/v3/chat.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ function isRunPatAuthError(error: unknown): boolean {
3737
const e = error as { name?: string; status?: number };
3838
return e.name === "TriggerApiError" && (e.status === 401 || e.status === 403);
3939
}
40-
// Stream-ID constants are no longer used — the transport writes a tagged
41-
// ChatInputChunk to the session's `.in` channel (append route) and reads
42-
// UIMessageChunks from `.out` (SSE subscribe). Kept imported from
43-
// chat-constants.js only for callers that still import them directly; the
44-
// legacy constants will be deleted in a follow-up cleanup.
4540
import { ChatTabCoordinator } from "./chat-tab-coordinator.js";
4641

4742
const DEFAULT_STREAM_KEY = "chat";

0 commit comments

Comments
 (0)