@trigger.dev/sdk 4.4.6 → 4.5.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/dist/commonjs/v3/agentSkillsRuntime.d.ts +28 -0
  2. package/dist/commonjs/v3/agentSkillsRuntime.js +163 -0
  3. package/dist/commonjs/v3/agentSkillsRuntime.js.map +1 -0
  4. package/dist/commonjs/v3/ai-shared.d.ts +173 -0
  5. package/dist/commonjs/v3/ai-shared.js +25 -0
  6. package/dist/commonjs/v3/ai-shared.js.map +1 -0
  7. package/dist/commonjs/v3/ai.d.ts +2823 -5
  8. package/dist/commonjs/v3/ai.js +6197 -13
  9. package/dist/commonjs/v3/ai.js.map +1 -1
  10. package/dist/commonjs/v3/auth.d.ts +9 -0
  11. package/dist/commonjs/v3/auth.js.map +1 -1
  12. package/dist/commonjs/v3/chat-client.d.ts +301 -0
  13. package/dist/commonjs/v3/chat-client.js +624 -0
  14. package/dist/commonjs/v3/chat-client.js.map +1 -0
  15. package/dist/commonjs/v3/chat-react.d.ts +155 -0
  16. package/dist/commonjs/v3/chat-react.js +330 -0
  17. package/dist/commonjs/v3/chat-react.js.map +1 -0
  18. package/dist/commonjs/v3/chat-server.d.ts +206 -0
  19. package/dist/commonjs/v3/chat-server.js +737 -0
  20. package/dist/commonjs/v3/chat-server.js.map +1 -0
  21. package/dist/commonjs/v3/chat-server.test.d.ts +1 -0
  22. package/dist/commonjs/v3/chat-server.test.js +518 -0
  23. package/dist/commonjs/v3/chat-server.test.js.map +1 -0
  24. package/dist/commonjs/v3/chat-tab-coordinator.d.ts +65 -0
  25. package/dist/commonjs/v3/chat-tab-coordinator.js +235 -0
  26. package/dist/commonjs/v3/chat-tab-coordinator.js.map +1 -0
  27. package/dist/commonjs/v3/chat-tab-coordinator.test.d.ts +1 -0
  28. package/dist/commonjs/v3/chat-tab-coordinator.test.js +140 -0
  29. package/dist/commonjs/v3/chat-tab-coordinator.test.js.map +1 -0
  30. package/dist/commonjs/v3/chat.d.ts +437 -0
  31. package/dist/commonjs/v3/chat.js +968 -0
  32. package/dist/commonjs/v3/chat.js.map +1 -0
  33. package/dist/commonjs/v3/chat.test.d.ts +1 -0
  34. package/dist/commonjs/v3/chat.test.js +1180 -0
  35. package/dist/commonjs/v3/chat.test.js.map +1 -0
  36. package/dist/commonjs/v3/createStartSessionAction.test.d.ts +1 -0
  37. package/dist/commonjs/v3/createStartSessionAction.test.js +113 -0
  38. package/dist/commonjs/v3/createStartSessionAction.test.js.map +1 -0
  39. package/dist/commonjs/v3/deployments.d.ts +26 -0
  40. package/dist/commonjs/v3/deployments.js +37 -0
  41. package/dist/commonjs/v3/deployments.js.map +1 -0
  42. package/dist/commonjs/v3/index.d.ts +6 -3
  43. package/dist/commonjs/v3/index.js +7 -1
  44. package/dist/commonjs/v3/index.js.map +1 -1
  45. package/dist/commonjs/v3/runs.d.ts +22 -7
  46. package/dist/commonjs/v3/runs.js +1 -0
  47. package/dist/commonjs/v3/runs.js.map +1 -1
  48. package/dist/commonjs/v3/sessions.d.ts +228 -0
  49. package/dist/commonjs/v3/sessions.js +664 -0
  50. package/dist/commonjs/v3/sessions.js.map +1 -0
  51. package/dist/commonjs/v3/sessions.test.d.ts +1 -0
  52. package/dist/commonjs/v3/sessions.test.js +154 -0
  53. package/dist/commonjs/v3/sessions.test.js.map +1 -0
  54. package/dist/commonjs/v3/shared.d.ts +24 -2
  55. package/dist/commonjs/v3/shared.js +189 -1
  56. package/dist/commonjs/v3/shared.js.map +1 -1
  57. package/dist/commonjs/v3/skill.d.ts +99 -0
  58. package/dist/commonjs/v3/skill.js +155 -0
  59. package/dist/commonjs/v3/skill.js.map +1 -0
  60. package/dist/commonjs/v3/skills.d.ts +2 -0
  61. package/dist/commonjs/v3/skills.js +6 -0
  62. package/dist/commonjs/v3/skills.js.map +1 -0
  63. package/dist/commonjs/v3/streams.js +127 -19
  64. package/dist/commonjs/v3/streams.js.map +1 -1
  65. package/dist/commonjs/v3/tasks.d.ts +2 -1
  66. package/dist/commonjs/v3/tasks.js +1 -0
  67. package/dist/commonjs/v3/tasks.js.map +1 -1
  68. package/dist/commonjs/v3/test/index.d.ts +3 -0
  69. package/dist/commonjs/v3/test/index.js +18 -0
  70. package/dist/commonjs/v3/test/index.js.map +1 -0
  71. package/dist/commonjs/v3/test/mock-chat-agent.d.ts +259 -0
  72. package/dist/commonjs/v3/test/mock-chat-agent.js +468 -0
  73. package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -0
  74. package/dist/commonjs/v3/test/setup-catalog.d.ts +1 -0
  75. package/dist/commonjs/v3/test/setup-catalog.js +18 -0
  76. package/dist/commonjs/v3/test/setup-catalog.js.map +1 -0
  77. package/dist/commonjs/v3/test/test-session-handle.d.ts +53 -0
  78. package/dist/commonjs/v3/test/test-session-handle.js +256 -0
  79. package/dist/commonjs/v3/test/test-session-handle.js.map +1 -0
  80. package/dist/commonjs/version.js +1 -1
  81. package/dist/esm/v3/agentSkillsRuntime.d.ts +28 -0
  82. package/dist/esm/v3/agentSkillsRuntime.js +136 -0
  83. package/dist/esm/v3/agentSkillsRuntime.js.map +1 -0
  84. package/dist/esm/v3/ai-shared.d.ts +173 -0
  85. package/dist/esm/v3/ai-shared.js +22 -0
  86. package/dist/esm/v3/ai-shared.js.map +1 -0
  87. package/dist/esm/v3/ai.d.ts +2823 -5
  88. package/dist/esm/v3/ai.js +6187 -14
  89. package/dist/esm/v3/ai.js.map +1 -1
  90. package/dist/esm/v3/auth.d.ts +9 -0
  91. package/dist/esm/v3/auth.js.map +1 -1
  92. package/dist/esm/v3/chat-client.d.ts +301 -0
  93. package/dist/esm/v3/chat-client.js +619 -0
  94. package/dist/esm/v3/chat-client.js.map +1 -0
  95. package/dist/esm/v3/chat-react.d.ts +155 -0
  96. package/dist/esm/v3/chat-react.js +325 -0
  97. package/dist/esm/v3/chat-react.js.map +1 -0
  98. package/dist/esm/v3/chat-server.d.ts +206 -0
  99. package/dist/esm/v3/chat-server.js +734 -0
  100. package/dist/esm/v3/chat-server.js.map +1 -0
  101. package/dist/esm/v3/chat-server.test.d.ts +1 -0
  102. package/dist/esm/v3/chat-server.test.js +516 -0
  103. package/dist/esm/v3/chat-server.test.js.map +1 -0
  104. package/dist/esm/v3/chat-tab-coordinator.d.ts +65 -0
  105. package/dist/esm/v3/chat-tab-coordinator.js +231 -0
  106. package/dist/esm/v3/chat-tab-coordinator.js.map +1 -0
  107. package/dist/esm/v3/chat-tab-coordinator.test.d.ts +1 -0
  108. package/dist/esm/v3/chat-tab-coordinator.test.js +138 -0
  109. package/dist/esm/v3/chat-tab-coordinator.test.js.map +1 -0
  110. package/dist/esm/v3/chat.d.ts +437 -0
  111. package/dist/esm/v3/chat.js +961 -0
  112. package/dist/esm/v3/chat.js.map +1 -0
  113. package/dist/esm/v3/chat.test.d.ts +1 -0
  114. package/dist/esm/v3/chat.test.js +1178 -0
  115. package/dist/esm/v3/chat.test.js.map +1 -0
  116. package/dist/esm/v3/createStartSessionAction.test.d.ts +1 -0
  117. package/dist/esm/v3/createStartSessionAction.test.js +111 -0
  118. package/dist/esm/v3/createStartSessionAction.test.js.map +1 -0
  119. package/dist/esm/v3/deployments.d.ts +26 -0
  120. package/dist/esm/v3/deployments.js +34 -0
  121. package/dist/esm/v3/deployments.js.map +1 -0
  122. package/dist/esm/v3/index.d.ts +6 -3
  123. package/dist/esm/v3/index.js +4 -1
  124. package/dist/esm/v3/index.js.map +1 -1
  125. package/dist/esm/v3/runs.d.ts +15 -0
  126. package/dist/esm/v3/runs.js +1 -0
  127. package/dist/esm/v3/runs.js.map +1 -1
  128. package/dist/esm/v3/sessions.d.ts +228 -0
  129. package/dist/esm/v3/sessions.js +656 -0
  130. package/dist/esm/v3/sessions.js.map +1 -0
  131. package/dist/esm/v3/sessions.test.d.ts +1 -0
  132. package/dist/esm/v3/sessions.test.js +152 -0
  133. package/dist/esm/v3/sessions.test.js.map +1 -0
  134. package/dist/esm/v3/shared.d.ts +24 -2
  135. package/dist/esm/v3/shared.js +188 -1
  136. package/dist/esm/v3/shared.js.map +1 -1
  137. package/dist/esm/v3/skill.d.ts +99 -0
  138. package/dist/esm/v3/skill.js +128 -0
  139. package/dist/esm/v3/skill.js.map +1 -0
  140. package/dist/esm/v3/skills.d.ts +2 -0
  141. package/dist/esm/v3/skills.js +2 -0
  142. package/dist/esm/v3/skills.js.map +1 -0
  143. package/dist/esm/v3/streams.js +127 -20
  144. package/dist/esm/v3/streams.js.map +1 -1
  145. package/dist/esm/v3/tasks.d.ts +2 -1
  146. package/dist/esm/v3/tasks.js +2 -1
  147. package/dist/esm/v3/tasks.js.map +1 -1
  148. package/dist/esm/v3/test/index.d.ts +3 -0
  149. package/dist/esm/v3/test/index.js +13 -0
  150. package/dist/esm/v3/test/index.js.map +1 -0
  151. package/dist/esm/v3/test/mock-chat-agent.d.ts +259 -0
  152. package/dist/esm/v3/test/mock-chat-agent.js +465 -0
  153. package/dist/esm/v3/test/mock-chat-agent.js.map +1 -0
  154. package/dist/esm/v3/test/setup-catalog.d.ts +1 -0
  155. package/dist/esm/v3/test/setup-catalog.js +16 -0
  156. package/dist/esm/v3/test/setup-catalog.js.map +1 -0
  157. package/dist/esm/v3/test/test-session-handle.d.ts +53 -0
  158. package/dist/esm/v3/test/test-session-handle.js +251 -0
  159. package/dist/esm/v3/test/test-session-handle.js.map +1 -0
  160. package/dist/esm/version.js +1 -1
  161. package/package.json +87 -6
@@ -0,0 +1,228 @@
1
+ import type { ApiPromise, ApiRequestOptions, AsyncIterableStream, CloseSessionRequestBody, CreatedSessionResponseBody, CreateSessionRequestBody, InputStreamOnceOptions, InputStreamWaitOptions, InputStreamWaitWithIdleTimeoutOptions, ListSessionsOptions, ListedSessionItem, PipeStreamOptions, PipeStreamResult, RetrieveSessionResponseBody, UpdateSessionRequestBody, WriterStreamOptions } from "@trigger.dev/core/v3";
2
+ import { CursorPagePromise, InputStreamOncePromise, ManualWaitpointPromise } from "@trigger.dev/core/v3";
3
+ import type { ControlEvent, StreamWriteResult } from "@trigger.dev/core/v3";
4
+ export type { CreatedSessionResponseBody, CreateSessionRequestBody, CloseSessionRequestBody, ListSessionsOptions, ListedSessionItem, RetrieveSessionResponseBody, UpdateSessionRequestBody, };
5
+ export declare const sessions: {
6
+ start: typeof startSession;
7
+ retrieve: typeof retrieveSession;
8
+ update: typeof updateSession;
9
+ close: typeof closeSession;
10
+ list: typeof listSessions;
11
+ open: typeof open;
12
+ };
13
+ type SessionOpenImpl = (sessionIdOrExternalId: string) => SessionHandle;
14
+ export declare function __setSessionOpenImplForTests(impl: SessionOpenImpl | undefined): void;
15
+ type SessionStartImpl = (body: CreateSessionRequestBody) => Promise<CreatedSessionResponseBody> | CreatedSessionResponseBody;
16
+ export declare function __setSessionStartImplForTests(impl: SessionStartImpl | undefined): void;
17
+ /**
18
+ * Start a {@link Session} — a durable, task-bound, bidirectional I/O
19
+ * primitive. The server creates the row (idempotent on `externalId`)
20
+ * and triggers the first run from `triggerConfig` in one round-trip.
21
+ * Returns the new run's id and a session-scoped public access token
22
+ * for browser-side use against `.in/append`, `.out` SSE, and
23
+ * `end-and-continue`.
24
+ *
25
+ * If a session with the same `(env, externalId)` already exists,
26
+ * returns the existing row plus the live (or freshly re-triggered) run.
27
+ * Two browser tabs of the same chat converge to one session.
28
+ */
29
+ declare function startSession(body: CreateSessionRequestBody, requestOptions?: ApiRequestOptions): ApiPromise<CreatedSessionResponseBody>;
30
+ /**
31
+ * Retrieve a Session by `friendlyId` (`session_*`) or user-supplied
32
+ * `externalId`. The server disambiguates via the `session_` prefix.
33
+ */
34
+ declare function retrieveSession(sessionIdOrExternalId: string, requestOptions?: ApiRequestOptions): ApiPromise<RetrieveSessionResponseBody>;
35
+ /** Update mutable fields on a Session (tags, metadata, externalId). */
36
+ declare function updateSession(sessionIdOrExternalId: string, body: UpdateSessionRequestBody, requestOptions?: ApiRequestOptions): ApiPromise<RetrieveSessionResponseBody>;
37
+ /** Mark a Session as closed (terminal, idempotent). */
38
+ declare function closeSession(sessionIdOrExternalId: string, body?: CloseSessionRequestBody, requestOptions?: ApiRequestOptions): ApiPromise<RetrieveSessionResponseBody>;
39
+ /**
40
+ * List Sessions in the current environment with filters + cursor pagination.
41
+ * Returns a {@link CursorPagePromise} so callers can iterate pages with
42
+ * `for await`.
43
+ */
44
+ declare function listSessions(options?: ListSessionsOptions, requestOptions?: ApiRequestOptions): CursorPagePromise<typeof ListedSessionItem>;
45
+ /**
46
+ * Open a lightweight handle to a Session's realtime channels. Does not
47
+ * perform a network call on its own — each channel method hits the
48
+ * corresponding realtime endpoint.
49
+ */
50
+ declare function open(sessionIdOrExternalId: string): SessionHandle;
51
+ export declare class SessionHandle {
52
+ readonly id: string;
53
+ /**
54
+ * Producer-to-consumer channel: the task writes records; external
55
+ * clients read them. Mirrors `streams.define` — `append` / `pipe` /
56
+ * `writer` / `read`.
57
+ */
58
+ readonly out: SessionOutputChannel;
59
+ /**
60
+ * Consumer-to-producer channel: external clients call `.send()`; the
61
+ * task consumes via `.on` / `.once` / `.peek` / `.wait` /
62
+ * `.waitWithIdleTimeout`. Mirrors `streams.input` but keyed on the
63
+ * session so a conversation can survive across run boundaries.
64
+ */
65
+ readonly in: SessionInputChannel;
66
+ constructor(id: string, overrides?: {
67
+ in?: SessionInputChannel;
68
+ out?: SessionOutputChannel;
69
+ });
70
+ }
71
+ /**
72
+ * Options accepted by {@link SessionOutputChannel.pipe}. Session-scoped,
73
+ * so it omits the `target` field (self/parent/root/runId) that run-scoped
74
+ * {@link PipeStreamOptions} uses — the session is the target.
75
+ */
76
+ export type SessionPipeStreamOptions = Omit<PipeStreamOptions, "target">;
77
+ /**
78
+ * The `.out` side of a Session's bidirectional channel pair. Mirrors the
79
+ * consume-side of {@link streams.define}: `pipe` / `writer` / `append`
80
+ * for the task to produce records, `read` for external clients to
81
+ * consume via SSE. S2 credentials for direct writes are fetched
82
+ * internally by `pipe`/`writer` — there's no public `initialize()`.
83
+ */
84
+ export declare class SessionOutputChannel {
85
+ #private;
86
+ readonly sessionId: string;
87
+ constructor(sessionId: string);
88
+ /**
89
+ * Append a single record. Routes through {@link writer} internally so
90
+ * subscribers receive the same parsed-object shape as multi-record
91
+ * writes — the server-side append endpoint wraps the body in a string,
92
+ * which would give SSE consumers a JSON-string instead of an object.
93
+ * Mirrors how `streams.define.append` delegates to `streams.writer`.
94
+ */
95
+ append<T>(value: T, options?: SessionPipeStreamOptions): Promise<void>;
96
+ /**
97
+ * Pipe an `AsyncIterable` / `ReadableStream` directly to S2. Fetches
98
+ * session S2 credentials internally and streams through
99
+ * {@link SessionStreamInstance}. Parallel to {@link streams.pipe} but
100
+ * session-scoped — no `target` option because the session is the target.
101
+ */
102
+ pipe<T>(value: AsyncIterable<T> | ReadableStream<T>, options?: SessionPipeStreamOptions): PipeStreamResult<T>;
103
+ /**
104
+ * Mirror of {@link streams.writer}: runs `execute({ write, merge })`
105
+ * against an in-memory queue whose records are piped to S2. Returns
106
+ * `{ stream, waitUntilComplete }` so callers can observe the local
107
+ * stream and await completion. Span is collapsible via `options.spanName`
108
+ * / `options.collapsed`.
109
+ */
110
+ writer<T>(options: WriterStreamOptions<T>): PipeStreamResult<T>;
111
+ /**
112
+ * Subscribe to SSE records on `.out`. Returns an async-iterable stream —
113
+ * auto-retry, Last-Event-ID resume, and abort propagation come from the
114
+ * shared {@link SSEStreamSubscription} plumbing used by run-scoped
115
+ * realtime streams.
116
+ */
117
+ read<T = unknown>(options?: SessionSubscribeOptions<T>): Promise<AsyncIterableStream<T>>;
118
+ /**
119
+ * Write a single Trigger control record to `.out`. The record carries a
120
+ * `trigger-control` header valued with `subtype` plus any sibling
121
+ * `extraHeaders`; the body is empty. Control records are filtered out of
122
+ * the consumer-facing chunk stream by the SDK transport — readers route
123
+ * them via the `onControl` callback instead.
124
+ *
125
+ * The returned `lastEventId` is the S2 seq_num of the written record,
126
+ * useful for trim chains (e.g. trim back to the previous turn-complete).
127
+ */
128
+ writeControl(subtype: string, extraHeaders?: ReadonlyArray<readonly [string, string]>): Promise<StreamWriteResult>;
129
+ /**
130
+ * Append an S2 `trim` command record to `.out`. Records with seq_num
131
+ * less than `earliestSeqNum` are eventually removed from the stream.
132
+ *
133
+ * Idempotent and monotonic at S2's layer (`max(existing, min(provided,
134
+ * current_tail))`) — backward trims are silently no-ops for deletion
135
+ * but still consume a seq_num. Used by `chat.agent`'s turn loop to
136
+ * keep `session.out` bounded to roughly one turn at steady state.
137
+ */
138
+ trimTo(earliestSeqNum: number): Promise<void>;
139
+ }
140
+ /**
141
+ * The `.in` side of a Session's bidirectional channel pair. Mirrors
142
+ * {@link streams.input} — consumer-side primitives for the task
143
+ * (`on`/`once`/`peek`/`wait`/`waitWithIdleTimeout`) plus `send` for
144
+ * external clients. Keyed on the session rather than the run so a
145
+ * conversation can survive across run boundaries.
146
+ */
147
+ export declare class SessionInputChannel {
148
+ readonly sessionId: string;
149
+ constructor(sessionId: string);
150
+ /**
151
+ * Send a single record to the channel. Called by external clients
152
+ * (browser, server action, another task) producing input for the run.
153
+ * Matches {@link streams.input.send} but session-scoped — the session
154
+ * is the address, no `runId` required.
155
+ */
156
+ send(value: unknown, requestOptions?: ApiRequestOptions): Promise<void>;
157
+ /**
158
+ * Register a handler that fires for every record landing on `.in`.
159
+ * Handlers are flushed with any buffered records on attach and cleaned
160
+ * up automatically when the task run completes. Returns `{ off }` to
161
+ * unsubscribe early.
162
+ */
163
+ on<T = unknown>(handler: (data: T) => void | Promise<void>): {
164
+ off: () => void;
165
+ };
166
+ /**
167
+ * Wait for the next record on `.in` without suspending the run.
168
+ * Returns `{ ok: true, output }` on arrival or `{ ok: false, error }`
169
+ * when the timeout fires. Chain `.unwrap()` to get the data directly.
170
+ */
171
+ once<T = unknown>(options?: InputStreamOnceOptions): InputStreamOncePromise<T>;
172
+ /** Non-blocking peek at the head of the `.in` buffer. */
173
+ peek<T = unknown>(): T | undefined;
174
+ /**
175
+ * The highest S2 sequence number of any record this channel has
176
+ * delivered to a `once()` / `wait()` consumer (or had shifted off its
177
+ * buffer into one). Distinct from "last received" — buffered-but-not-
178
+ * yet-consumed records don't count.
179
+ *
180
+ * Used by `chat.agent` to persist the `.in` resume cursor on each
181
+ * `turn-complete` control record, so the next worker boot can subscribe
182
+ * past already-processed user messages.
183
+ */
184
+ lastDispatchedSeqNum(): number | undefined;
185
+ /**
186
+ * Suspend the current run until the next record arrives on `.in`.
187
+ * Unlike {@link once}, `wait()` frees compute while blocked — the
188
+ * run-engine waitpoint holds the run until the session append handler
189
+ * fires it. Only callable from inside `task.run()`.
190
+ */
191
+ wait<T = unknown>(options?: InputStreamWaitOptions): ManualWaitpointPromise<T>;
192
+ /**
193
+ * Wait for a record with an idle-then-suspend strategy. Keeps the run
194
+ * active (using compute) for `idleTimeoutInSeconds`, then suspends via
195
+ * {@link wait} if nothing arrives. If a record arrives during the idle
196
+ * phase the run responds without suspending.
197
+ */
198
+ waitWithIdleTimeout<T = unknown>(options: InputStreamWaitWithIdleTimeoutOptions): Promise<{
199
+ ok: true;
200
+ output: T;
201
+ } | {
202
+ ok: false;
203
+ error?: Error;
204
+ }>;
205
+ }
206
+ export type SessionSubscribeOptions<T = unknown> = {
207
+ signal?: AbortSignal;
208
+ lastEventId?: string | number;
209
+ /** Timeout in seconds for the underlying long-poll (max 600). */
210
+ timeoutInSeconds?: number;
211
+ /** Called for each SSE event with the full event metadata (id, timestamp). */
212
+ onPart?: (part: {
213
+ id: string;
214
+ chunk: T;
215
+ timestamp: number;
216
+ }) => void;
217
+ /**
218
+ * Called when a `trigger-control` record arrives on the stream (e.g.
219
+ * `turn-complete`, `upgrade-required`). Control records are filtered
220
+ * out of the consumer chunk stream — handle them here. See
221
+ * `docs/ai-chat/client-protocol.mdx` for the wire shape.
222
+ */
223
+ onControl?: (event: ControlEvent) => void;
224
+ /** Called when the server signals end-of-stream. */
225
+ onComplete?: () => void;
226
+ /** Called on unrecoverable errors after the retry budget is exhausted. */
227
+ onError?: (error: Error) => void;
228
+ };