@trigger.dev/sdk 0.0.0-prerelease-20251007140052 → 0.0.0-prerelease-20251113143926
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.
- package/dist/commonjs/v3/index.d.ts +1 -0
- package/dist/commonjs/v3/index.js +1 -0
- package/dist/commonjs/v3/index.js.map +1 -1
- package/dist/commonjs/v3/metadata.d.ts +3 -0
- package/dist/commonjs/v3/metadata.js +8 -1
- package/dist/commonjs/v3/metadata.js.map +1 -1
- package/dist/commonjs/v3/queues.d.ts +15 -0
- package/dist/commonjs/v3/queues.js +57 -0
- package/dist/commonjs/v3/queues.js.map +1 -1
- package/dist/commonjs/v3/shared.js +10 -10
- package/dist/commonjs/v3/shared.js.map +1 -1
- package/dist/commonjs/v3/streams.d.ts +266 -0
- package/dist/commonjs/v3/streams.js +322 -0
- package/dist/commonjs/v3/streams.js.map +1 -0
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/v3/index.d.ts +1 -0
- package/dist/esm/v3/index.js +1 -0
- package/dist/esm/v3/index.js.map +1 -1
- package/dist/esm/v3/metadata.d.ts +3 -0
- package/dist/esm/v3/metadata.js +8 -1
- package/dist/esm/v3/metadata.js.map +1 -1
- package/dist/esm/v3/queues.d.ts +15 -0
- package/dist/esm/v3/queues.js +55 -0
- package/dist/esm/v3/queues.js.map +1 -1
- package/dist/esm/v3/shared.js +10 -10
- package/dist/esm/v3/shared.js.map +1 -1
- package/dist/esm/v3/streams.d.ts +266 -0
- package/dist/esm/v3/streams.js +319 -0
- package/dist/esm/v3/streams.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { AsyncIterableStream, WriterStreamOptions, PipeStreamOptions, PipeStreamResult, ReadStreamOptions, AppendStreamOptions, RealtimeDefinedStream, InferStreamType } from "@trigger.dev/core/v3";
|
|
2
|
+
/**
|
|
3
|
+
* Pipes data to a realtime stream using the default stream key (`"default"`).
|
|
4
|
+
*
|
|
5
|
+
* This is a convenience overload that allows you to pipe data without specifying a stream key.
|
|
6
|
+
* The stream will be created/accessed with the key `"default"`.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of data chunks in the stream
|
|
9
|
+
* @param value - The stream of data to pipe from. Can be an `AsyncIterable<T>` or `ReadableStream<T>`.
|
|
10
|
+
* @param options - Optional configuration for the stream operation
|
|
11
|
+
* @returns A promise that resolves to an object containing:
|
|
12
|
+
* - `stream`: The original stream (can be consumed in your task)
|
|
13
|
+
* - `waitUntilComplete`: A function that returns a promise resolving when the stream is fully sent
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { streams } from "@trigger.dev/sdk";
|
|
18
|
+
*
|
|
19
|
+
* // Stream OpenAI completion chunks to the default stream
|
|
20
|
+
* const completion = await openai.chat.completions.create({
|
|
21
|
+
* model: "gpt-4",
|
|
22
|
+
* messages: [{ role: "user", content: "Hello" }],
|
|
23
|
+
* stream: true,
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* const { waitUntilComplete } = await streams.pipe(completion);
|
|
27
|
+
*
|
|
28
|
+
* // Process the stream locally
|
|
29
|
+
* for await (const chunk of completion) {
|
|
30
|
+
* console.log(chunk);
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* // Or alternatievely wait for all chunks to be sent to the realtime stream
|
|
34
|
+
* await waitUntilComplete();
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
declare function pipe<T>(value: AsyncIterable<T> | ReadableStream<T>, options?: PipeStreamOptions): PipeStreamResult<T>;
|
|
38
|
+
/**
|
|
39
|
+
* Pipes data to a realtime stream with a specific stream key.
|
|
40
|
+
*
|
|
41
|
+
* Use this overload when you want to use a custom stream key instead of the default.
|
|
42
|
+
*
|
|
43
|
+
* @template T - The type of data chunks in the stream
|
|
44
|
+
* @param key - The unique identifier for this stream. If multiple streams use the same key,
|
|
45
|
+
* they will be merged into a single stream. Defaults to `"default"` if not provided.
|
|
46
|
+
* @param value - The stream of data to pipe from. Can be an `AsyncIterable<T>` or `ReadableStream<T>`.
|
|
47
|
+
* @param options - Optional configuration for the stream operation
|
|
48
|
+
* @returns A promise that resolves to an object containing:
|
|
49
|
+
* - `stream`: The original stream (can be consumed in your task)
|
|
50
|
+
* - `waitUntilComplete`: A function that returns a promise resolving when the stream is fully sent
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { streams } from "@trigger.dev/sdk";
|
|
55
|
+
*
|
|
56
|
+
* // Stream data to a specific stream key
|
|
57
|
+
* const myStream = createAsyncGenerator();
|
|
58
|
+
* const { waitUntilComplete } = await streams.pipe("my-custom-stream", myStream);
|
|
59
|
+
*
|
|
60
|
+
* // Process the stream locally
|
|
61
|
+
* for await (const chunk of myStream) {
|
|
62
|
+
* console.log(chunk);
|
|
63
|
+
* }
|
|
64
|
+
*
|
|
65
|
+
* // Wait for all chunks to be sent
|
|
66
|
+
* await waitUntilComplete();
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* // Stream to a parent run
|
|
72
|
+
* await streams.pipe("output", myStream, {
|
|
73
|
+
* target: "parent",
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare function pipe<T>(key: string, value: AsyncIterable<T> | ReadableStream<T>, options?: PipeStreamOptions): PipeStreamResult<T>;
|
|
78
|
+
/**
|
|
79
|
+
* Reads data from a realtime stream using the default stream key (`"default"`).
|
|
80
|
+
*
|
|
81
|
+
* This is a convenience overload that allows you to read from the default stream without
|
|
82
|
+
* specifying a stream key. The stream will be accessed with the key `"default"`.
|
|
83
|
+
*
|
|
84
|
+
* @template T - The type of data chunks in the stream
|
|
85
|
+
* @param runId - The unique identifier of the run to read the stream from
|
|
86
|
+
* @param options - Optional configuration for reading the stream
|
|
87
|
+
* @returns A promise that resolves to an `AsyncIterableStream<T>` that can be consumed
|
|
88
|
+
* using `for await...of` or as a `ReadableStream`.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { streams } from "@trigger.dev/sdk/v3";
|
|
93
|
+
*
|
|
94
|
+
* // Read from the default stream
|
|
95
|
+
* const stream = await streams.read<string>(runId);
|
|
96
|
+
*
|
|
97
|
+
* for await (const chunk of stream) {
|
|
98
|
+
* console.log("Received chunk:", chunk);
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* // Read with custom timeout and starting position
|
|
105
|
+
* const stream = await streams.read<string>(runId, {
|
|
106
|
+
* timeoutInSeconds: 120,
|
|
107
|
+
* startIndex: 10, // Start from the 10th chunk
|
|
108
|
+
* });
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
declare function read<T>(runId: string, options?: ReadStreamOptions): Promise<AsyncIterableStream<T>>;
|
|
112
|
+
/**
|
|
113
|
+
* Reads data from a realtime stream with a specific stream key.
|
|
114
|
+
*
|
|
115
|
+
* Use this overload when you want to read from a stream with a custom key.
|
|
116
|
+
*
|
|
117
|
+
* @template T - The type of data chunks in the stream
|
|
118
|
+
* @param runId - The unique identifier of the run to read the stream from
|
|
119
|
+
* @param key - The unique identifier of the stream to read from. Defaults to `"default"` if not provided.
|
|
120
|
+
* @param options - Optional configuration for reading the stream
|
|
121
|
+
* @returns A promise that resolves to an `AsyncIterableStream<T>` that can be consumed
|
|
122
|
+
* using `for await...of` or as a `ReadableStream`.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* import { streams } from "@trigger.dev/sdk";
|
|
127
|
+
*
|
|
128
|
+
* // Read from a specific stream key
|
|
129
|
+
* const stream = await streams.read<string>(runId, "my-custom-stream");
|
|
130
|
+
*
|
|
131
|
+
* for await (const chunk of stream) {
|
|
132
|
+
* console.log("Received chunk:", chunk);
|
|
133
|
+
* }
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* // Read with signal for cancellation
|
|
139
|
+
* const controller = new AbortController();
|
|
140
|
+
* const stream = await streams.read<string>(runId, "my-stream", {
|
|
141
|
+
* signal: controller.signal,
|
|
142
|
+
* timeoutInSeconds: 30,
|
|
143
|
+
* });
|
|
144
|
+
*
|
|
145
|
+
* // Cancel after 5 seconds
|
|
146
|
+
* setTimeout(() => controller.abort(), 5000);
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
declare function read<T>(runId: string, key: string, options?: ReadStreamOptions): Promise<AsyncIterableStream<T>>;
|
|
150
|
+
declare function append<TPart extends BodyInit>(value: TPart, options?: AppendStreamOptions): Promise<void>;
|
|
151
|
+
declare function append<TPart extends BodyInit>(key: string, value: TPart, options?: AppendStreamOptions): Promise<void>;
|
|
152
|
+
/**
|
|
153
|
+
* Writes data to a realtime stream using the default stream key (`"default"`).
|
|
154
|
+
*
|
|
155
|
+
* This is a convenience overload that allows you to write to the default stream without
|
|
156
|
+
* specifying a stream key. The stream will be created/accessed with the key `"default"`.
|
|
157
|
+
*
|
|
158
|
+
* @template TPart - The type of data chunks in the stream
|
|
159
|
+
* @param options - The options for writing to the stream
|
|
160
|
+
* @returns A promise that resolves to an object containing:
|
|
161
|
+
* - `stream`: The original stream (can be consumed in your task)
|
|
162
|
+
* - `waitUntilComplete`: A function that returns a promise resolving when the stream is fully sent
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* import { streams } from "@trigger.dev/sdk";
|
|
167
|
+
*
|
|
168
|
+
* // Write to the default stream
|
|
169
|
+
* const { waitUntilComplete } = await streams.writer({
|
|
170
|
+
* execute: ({ write, merge }) => {
|
|
171
|
+
* write("chunk 1");
|
|
172
|
+
* write("chunk 2");
|
|
173
|
+
* write("chunk 3");
|
|
174
|
+
* },
|
|
175
|
+
* });
|
|
176
|
+
*
|
|
177
|
+
* // Wait for all chunks to be written
|
|
178
|
+
* await waitUntilComplete();
|
|
179
|
+
* ```
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* // Write to a specific stream key
|
|
184
|
+
* const { waitUntilComplete } = await streams.writer("my-custom-stream", {
|
|
185
|
+
* execute: ({ write, merge }) => {
|
|
186
|
+
* write("chunk 1");
|
|
187
|
+
* write("chunk 2");
|
|
188
|
+
* write("chunk 3");
|
|
189
|
+
* },
|
|
190
|
+
* });
|
|
191
|
+
*
|
|
192
|
+
* // Wait for all chunks to be written
|
|
193
|
+
* await waitUntilComplete();
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* // Write to a parent run
|
|
199
|
+
* await streams.writer("output", {
|
|
200
|
+
* execute: ({ write, merge }) => {
|
|
201
|
+
* write("chunk 1");
|
|
202
|
+
* write("chunk 2");
|
|
203
|
+
* write("chunk 3");
|
|
204
|
+
* },
|
|
205
|
+
* });
|
|
206
|
+
*
|
|
207
|
+
* // Wait for all chunks to be written
|
|
208
|
+
* await waitUntilComplete();
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts
|
|
213
|
+
* // Write to a specific stream key
|
|
214
|
+
* await streams.writer("my-custom-stream", {
|
|
215
|
+
* execute: ({ write, merge }) => {
|
|
216
|
+
* write("chunk 1");
|
|
217
|
+
* write("chunk 2");
|
|
218
|
+
* write("chunk 3");
|
|
219
|
+
* },
|
|
220
|
+
* });
|
|
221
|
+
*
|
|
222
|
+
* // Wait for all chunks to be written
|
|
223
|
+
* await waitUntilComplete();
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
declare function writer<TPart>(options: WriterStreamOptions<TPart>): PipeStreamResult<TPart>;
|
|
227
|
+
/**
|
|
228
|
+
* Writes data to a realtime stream with a specific stream key.
|
|
229
|
+
*
|
|
230
|
+
* @template TPart - The type of data chunks in the stream
|
|
231
|
+
* @param key - The unique identifier of the stream to write to. Defaults to `"default"` if not provided.
|
|
232
|
+
* @param options - The options for writing to the stream
|
|
233
|
+
* @returns A promise that resolves to an object containing:
|
|
234
|
+
* - `stream`: The original stream (can be consumed in your task)
|
|
235
|
+
* - `waitUntilComplete`: A function that returns a promise resolving when the stream is fully sent
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```ts
|
|
239
|
+
* import { streams } from "@trigger.dev/sdk";
|
|
240
|
+
*
|
|
241
|
+
* // Write to a specific stream key
|
|
242
|
+
* const { waitUntilComplete } = await streams.writer("my-custom-stream", {
|
|
243
|
+
* execute: ({ write, merge }) => {
|
|
244
|
+
* write("chunk 1");
|
|
245
|
+
* write("chunk 2");
|
|
246
|
+
* write("chunk 3");
|
|
247
|
+
* },
|
|
248
|
+
* });
|
|
249
|
+
*
|
|
250
|
+
* // Wait for all chunks to be written
|
|
251
|
+
* await waitUntilComplete();
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
declare function writer<TPart>(key: string, options: WriterStreamOptions<TPart>): PipeStreamResult<TPart>;
|
|
255
|
+
export type RealtimeDefineStreamOptions = {
|
|
256
|
+
id: string;
|
|
257
|
+
};
|
|
258
|
+
declare function define<TPart>(opts: RealtimeDefineStreamOptions): RealtimeDefinedStream<TPart>;
|
|
259
|
+
export type { InferStreamType };
|
|
260
|
+
export declare const streams: {
|
|
261
|
+
pipe: typeof pipe;
|
|
262
|
+
read: typeof read;
|
|
263
|
+
append: typeof append;
|
|
264
|
+
writer: typeof writer;
|
|
265
|
+
define: typeof define;
|
|
266
|
+
};
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.streams = void 0;
|
|
4
|
+
const v3_1 = require("@trigger.dev/core/v3");
|
|
5
|
+
const tracer_js_1 = require("./tracer.js");
|
|
6
|
+
const api_1 = require("@opentelemetry/api");
|
|
7
|
+
const DEFAULT_STREAM_KEY = "default";
|
|
8
|
+
function pipe(keyOrValue, valueOrOptions, options) {
|
|
9
|
+
// Handle overload: pipe(value, options?) or pipe(key, value, options?)
|
|
10
|
+
let key;
|
|
11
|
+
let value;
|
|
12
|
+
let opts;
|
|
13
|
+
if (typeof keyOrValue === "string") {
|
|
14
|
+
// pipe(key, value, options?)
|
|
15
|
+
key = keyOrValue;
|
|
16
|
+
value = valueOrOptions;
|
|
17
|
+
opts = options;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
// pipe(value, options?)
|
|
21
|
+
key = DEFAULT_STREAM_KEY;
|
|
22
|
+
value = keyOrValue;
|
|
23
|
+
opts = valueOrOptions;
|
|
24
|
+
}
|
|
25
|
+
return pipeInternal(key, value, opts, "streams.pipe()");
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Internal pipe implementation that allows customizing the span name.
|
|
29
|
+
* This is used by both the public `pipe` method and the `writer` method.
|
|
30
|
+
*/
|
|
31
|
+
function pipeInternal(key, value, opts, spanName) {
|
|
32
|
+
const runId = getRunIdForOptions(opts);
|
|
33
|
+
if (!runId) {
|
|
34
|
+
throw new Error("Could not determine the target run ID for the realtime stream. Please specify a target run ID using the `target` option or use this function from inside a task.");
|
|
35
|
+
}
|
|
36
|
+
const span = tracer_js_1.tracer.startSpan(spanName, {
|
|
37
|
+
attributes: {
|
|
38
|
+
key,
|
|
39
|
+
runId,
|
|
40
|
+
[v3_1.SemanticInternalAttributes.ENTITY_TYPE]: "realtime-stream",
|
|
41
|
+
[v3_1.SemanticInternalAttributes.ENTITY_ID]: `${runId}:${key}`,
|
|
42
|
+
[v3_1.SemanticInternalAttributes.STYLE_ICON]: "streams",
|
|
43
|
+
...(0, v3_1.accessoryAttributes)({
|
|
44
|
+
items: [
|
|
45
|
+
{
|
|
46
|
+
text: key,
|
|
47
|
+
variant: "normal",
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
style: "codepath",
|
|
51
|
+
}),
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
const requestOptions = (0, v3_1.mergeRequestOptions)({}, opts?.requestOptions);
|
|
55
|
+
try {
|
|
56
|
+
const instance = v3_1.realtimeStreams.pipe(key, value, {
|
|
57
|
+
signal: opts?.signal,
|
|
58
|
+
target: runId,
|
|
59
|
+
requestOptions,
|
|
60
|
+
});
|
|
61
|
+
instance.wait().finally(() => {
|
|
62
|
+
span.end();
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
stream: instance.stream,
|
|
66
|
+
waitUntilComplete: () => instance.wait(),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
// if the error is a signal abort error, we need to end the span but not record an exception
|
|
71
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
72
|
+
span.end();
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
if (error instanceof Error || typeof error === "string") {
|
|
76
|
+
span.recordException(error);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
span.recordException(String(error));
|
|
80
|
+
}
|
|
81
|
+
span.setStatus({ code: api_1.SpanStatusCode.ERROR });
|
|
82
|
+
span.end();
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function read(runId, keyOrOptions, options) {
|
|
87
|
+
// Handle overload: read(runId, options?) or read(runId, key, options?)
|
|
88
|
+
let key;
|
|
89
|
+
let opts;
|
|
90
|
+
if (typeof keyOrOptions === "string") {
|
|
91
|
+
// read(runId, key, options?)
|
|
92
|
+
key = keyOrOptions;
|
|
93
|
+
opts = options;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
// read(runId, options?)
|
|
97
|
+
key = DEFAULT_STREAM_KEY;
|
|
98
|
+
opts = keyOrOptions;
|
|
99
|
+
}
|
|
100
|
+
// Rename to readStream for consistency with existing code
|
|
101
|
+
return readStreamImpl(runId, key, opts);
|
|
102
|
+
}
|
|
103
|
+
async function readStreamImpl(runId, key, options) {
|
|
104
|
+
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
105
|
+
const span = tracer_js_1.tracer.startSpan("streams.read()", {
|
|
106
|
+
attributes: {
|
|
107
|
+
key,
|
|
108
|
+
runId,
|
|
109
|
+
[v3_1.SemanticInternalAttributes.ENTITY_TYPE]: "realtime-stream",
|
|
110
|
+
[v3_1.SemanticInternalAttributes.ENTITY_ID]: `${runId}:${key}`,
|
|
111
|
+
[v3_1.SemanticInternalAttributes.ENTITY_METADATA]: JSON.stringify({
|
|
112
|
+
startIndex: options?.startIndex,
|
|
113
|
+
}),
|
|
114
|
+
[v3_1.SemanticInternalAttributes.STYLE_ICON]: "streams",
|
|
115
|
+
...(0, v3_1.accessoryAttributes)({
|
|
116
|
+
items: [
|
|
117
|
+
{
|
|
118
|
+
text: key,
|
|
119
|
+
variant: "normal",
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
style: "codepath",
|
|
123
|
+
}),
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
return await apiClient.fetchStream(runId, key, {
|
|
127
|
+
signal: options?.signal,
|
|
128
|
+
timeoutInSeconds: options?.timeoutInSeconds ?? 60,
|
|
129
|
+
lastEventId: options?.startIndex ? (options.startIndex - 1).toString() : undefined,
|
|
130
|
+
onComplete: () => {
|
|
131
|
+
span.end();
|
|
132
|
+
},
|
|
133
|
+
onError: (error) => {
|
|
134
|
+
span.recordException(error);
|
|
135
|
+
span.setStatus({ code: api_1.SpanStatusCode.ERROR });
|
|
136
|
+
span.end();
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function append(keyOrValue, valueOrOptions, options) {
|
|
141
|
+
if (typeof keyOrValue === "string" && typeof valueOrOptions === "string") {
|
|
142
|
+
return appendInternal(keyOrValue, valueOrOptions, options);
|
|
143
|
+
}
|
|
144
|
+
if (typeof keyOrValue === "string") {
|
|
145
|
+
if (isAppendStreamOptions(valueOrOptions)) {
|
|
146
|
+
return appendInternal(DEFAULT_STREAM_KEY, keyOrValue, valueOrOptions);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
if (!valueOrOptions) {
|
|
150
|
+
return appendInternal(DEFAULT_STREAM_KEY, keyOrValue, options);
|
|
151
|
+
}
|
|
152
|
+
return appendInternal(keyOrValue, valueOrOptions, options);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
if (isAppendStreamOptions(valueOrOptions)) {
|
|
157
|
+
return appendInternal(DEFAULT_STREAM_KEY, keyOrValue, valueOrOptions);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
return appendInternal(DEFAULT_STREAM_KEY, keyOrValue, options);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async function appendInternal(key, part, options) {
|
|
165
|
+
const runId = getRunIdForOptions(options);
|
|
166
|
+
if (!runId) {
|
|
167
|
+
throw new Error("Could not determine the target run ID for the realtime stream. Please specify a target run ID using the `target` option or use this function from inside a task.");
|
|
168
|
+
}
|
|
169
|
+
const span = tracer_js_1.tracer.startSpan("streams.append()", {
|
|
170
|
+
attributes: {
|
|
171
|
+
key,
|
|
172
|
+
runId,
|
|
173
|
+
[v3_1.SemanticInternalAttributes.ENTITY_TYPE]: "realtime-stream",
|
|
174
|
+
[v3_1.SemanticInternalAttributes.ENTITY_ID]: `${runId}:${key}`,
|
|
175
|
+
[v3_1.SemanticInternalAttributes.STYLE_ICON]: "streams",
|
|
176
|
+
...(0, v3_1.accessoryAttributes)({
|
|
177
|
+
items: [
|
|
178
|
+
{
|
|
179
|
+
text: key,
|
|
180
|
+
variant: "normal",
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
style: "codepath",
|
|
184
|
+
}),
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
try {
|
|
188
|
+
await v3_1.realtimeStreams.append(key, part, options);
|
|
189
|
+
span.end();
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
// if the error is a signal abort error, we need to end the span but not record an exception
|
|
193
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
194
|
+
span.end();
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
197
|
+
if (error instanceof Error || typeof error === "string") {
|
|
198
|
+
span.recordException(error);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
span.recordException(String(error));
|
|
202
|
+
}
|
|
203
|
+
span.setStatus({ code: api_1.SpanStatusCode.ERROR });
|
|
204
|
+
span.end();
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function isAppendStreamOptions(val) {
|
|
209
|
+
return (typeof val === "object" &&
|
|
210
|
+
val !== null &&
|
|
211
|
+
!Array.isArray(val) &&
|
|
212
|
+
(("target" in val && typeof val.target === "string") ||
|
|
213
|
+
("requestOptions" in val && typeof val.requestOptions === "object")));
|
|
214
|
+
}
|
|
215
|
+
function writer(keyOrOptions, valueOrOptions) {
|
|
216
|
+
if (typeof keyOrOptions === "string") {
|
|
217
|
+
return writerInternal(keyOrOptions, valueOrOptions);
|
|
218
|
+
}
|
|
219
|
+
return writerInternal(DEFAULT_STREAM_KEY, keyOrOptions);
|
|
220
|
+
}
|
|
221
|
+
function writerInternal(key, options) {
|
|
222
|
+
let controller;
|
|
223
|
+
const ongoingStreamPromises = [];
|
|
224
|
+
const stream = new ReadableStream({
|
|
225
|
+
start(controllerArg) {
|
|
226
|
+
controller = controllerArg;
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
function safeEnqueue(data) {
|
|
230
|
+
try {
|
|
231
|
+
controller.enqueue(data);
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
// suppress errors when the stream has been closed
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
const result = options.execute({
|
|
239
|
+
write(part) {
|
|
240
|
+
safeEnqueue(part);
|
|
241
|
+
},
|
|
242
|
+
merge(streamArg) {
|
|
243
|
+
ongoingStreamPromises.push((async () => {
|
|
244
|
+
const reader = streamArg.getReader();
|
|
245
|
+
while (true) {
|
|
246
|
+
const { done, value } = await reader.read();
|
|
247
|
+
if (done)
|
|
248
|
+
break;
|
|
249
|
+
safeEnqueue(value);
|
|
250
|
+
}
|
|
251
|
+
})().catch((error) => {
|
|
252
|
+
console.error(error);
|
|
253
|
+
}));
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
if (result) {
|
|
257
|
+
ongoingStreamPromises.push(result.catch((error) => {
|
|
258
|
+
console.error(error);
|
|
259
|
+
}));
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
console.error(error);
|
|
264
|
+
}
|
|
265
|
+
const waitForStreams = new Promise((resolve, reject) => {
|
|
266
|
+
(async () => {
|
|
267
|
+
while (ongoingStreamPromises.length > 0) {
|
|
268
|
+
await ongoingStreamPromises.shift();
|
|
269
|
+
}
|
|
270
|
+
resolve();
|
|
271
|
+
})().catch(reject);
|
|
272
|
+
});
|
|
273
|
+
waitForStreams.finally(() => {
|
|
274
|
+
try {
|
|
275
|
+
controller.close();
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
// suppress errors when the stream has been closed
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
return pipeInternal(key, stream, options, "streams.writer()");
|
|
282
|
+
}
|
|
283
|
+
function define(opts) {
|
|
284
|
+
return {
|
|
285
|
+
id: opts.id,
|
|
286
|
+
pipe(value, options) {
|
|
287
|
+
return pipe(opts.id, value, options);
|
|
288
|
+
},
|
|
289
|
+
read(runId, options) {
|
|
290
|
+
return read(runId, opts.id, options);
|
|
291
|
+
},
|
|
292
|
+
append(value, options) {
|
|
293
|
+
return append(opts.id, value, options);
|
|
294
|
+
},
|
|
295
|
+
writer(options) {
|
|
296
|
+
return writer(opts.id, options);
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
exports.streams = {
|
|
301
|
+
pipe,
|
|
302
|
+
read,
|
|
303
|
+
append,
|
|
304
|
+
writer,
|
|
305
|
+
define,
|
|
306
|
+
};
|
|
307
|
+
function getRunIdForOptions(options) {
|
|
308
|
+
if (options?.target) {
|
|
309
|
+
if (options.target === "parent") {
|
|
310
|
+
return v3_1.taskContext.ctx?.run?.parentTaskRunId;
|
|
311
|
+
}
|
|
312
|
+
if (options.target === "root") {
|
|
313
|
+
return v3_1.taskContext.ctx?.run?.rootTaskRunId;
|
|
314
|
+
}
|
|
315
|
+
if (options.target === "self") {
|
|
316
|
+
return v3_1.taskContext.ctx?.run?.id;
|
|
317
|
+
}
|
|
318
|
+
return options.target;
|
|
319
|
+
}
|
|
320
|
+
return v3_1.taskContext.ctx?.run?.id;
|
|
321
|
+
}
|
|
322
|
+
//# sourceMappingURL=streams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streams.js","sourceRoot":"","sources":["../../../src/v3/streams.ts"],"names":[],"mappings":";;;AAAA,6CAiB8B;AAC9B,2CAAqC;AACrC,4CAAoD;AAEpD,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAqFrC,SAAS,IAAI,CACX,UAAyD,EACzD,cAAyE,EACzE,OAA2B;IAE3B,uEAAuE;IACvE,IAAI,GAAW,CAAC;IAChB,IAAI,KAA2C,CAAC;IAChD,IAAI,IAAmC,CAAC;IAExC,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,6BAA6B;QAC7B,GAAG,GAAG,UAAU,CAAC;QACjB,KAAK,GAAG,cAAsD,CAAC;QAC/D,IAAI,GAAG,OAAO,CAAC;IACjB,CAAC;SAAM,CAAC;QACN,wBAAwB;QACxB,GAAG,GAAG,kBAAkB,CAAC;QACzB,KAAK,GAAG,UAAU,CAAC;QACnB,IAAI,GAAG,cAA+C,CAAC;IACzD,CA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el.js";
|
|
17
17
|
export * from "./schemas.js";
|
|
18
18
|
export * from "./heartbeats.js";
|
|
19
|
+
export * from "./streams.js";
|
|
19
20
|
export type { Context };
|
|
20
21
|
import type { Context } from "./shared.js";
|
|
21
22
|
import type { ApiClientConfiguration } from "@trigger.dev/core/v3";
|
package/dist/esm/v3/index.js
CHANGED
|
@@ -16,6 +16,7 @@ export * from "./locals.js";
|
|
|
16
16
|
export * from "./otel.js";
|
|
17
17
|
export * from "./schemas.js";
|
|
18
18
|
export * from "./heartbeats.js";
|
|
19
|
+
export * from "./streams.js";
|
|
19
20
|
export { ApiError, AuthenticationError, BadRequestError, ConflictError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, UnprocessableEntityError, AbortTaskRunError, OutOfMemoryError, CompleteTaskWithOutput, logger, } from "@trigger.dev/core/v3";
|
|
20
21
|
export { runs, } from "./runs.js";
|
|
21
22
|
export * as schedules from "./schedules/index.js";
|
package/dist/esm/v3/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v3/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAqB,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v3/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAqB,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAS7B,OAAO,EACL,QAAQ,EACR,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,qBAAqB,EACrB,cAAc,EACd,wBAAwB,EACxB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,EACtB,MAAM,GAEP,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,IAAI,GAQL,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAGtC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -188,6 +188,9 @@ declare function flushMetadata(requestOptions?: ApiRequestOptions): Promise<void
|
|
|
188
188
|
* @returns {Promise<void>} A promise that resolves when the metadata refresh operation is complete.
|
|
189
189
|
*/
|
|
190
190
|
declare function refreshMetadata(requestOptions?: ApiRequestOptions): Promise<void>;
|
|
191
|
+
/**
|
|
192
|
+
* @deprecated Use `streams.pipe()` instead.
|
|
193
|
+
*/
|
|
191
194
|
declare function stream<T>(key: string, value: AsyncIterable<T> | ReadableStream<T>, signal?: AbortSignal): Promise<AsyncIterable<T>>;
|
|
192
195
|
declare function fetchStream<T>(key: string, signal?: AbortSignal): Promise<AsyncIterableStream<T>>;
|
|
193
196
|
export {};
|
package/dist/esm/v3/metadata.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { mergeRequestOptions, runMetadata, } from "@trigger.dev/core/v3";
|
|
2
2
|
import { tracer } from "./tracer.js";
|
|
3
|
+
import { streams } from "./streams.js";
|
|
3
4
|
const parentMetadataUpdater = runMetadata.parent;
|
|
4
5
|
const rootMetadataUpdater = runMetadata.root;
|
|
5
6
|
/**
|
|
@@ -193,8 +194,14 @@ async function refreshMetadata(requestOptions) {
|
|
|
193
194
|
}, requestOptions);
|
|
194
195
|
await runMetadata.refresh($requestOptions);
|
|
195
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* @deprecated Use `streams.pipe()` instead.
|
|
199
|
+
*/
|
|
196
200
|
async function stream(key, value, signal) {
|
|
197
|
-
|
|
201
|
+
const streamInstance = await streams.pipe(key, value, {
|
|
202
|
+
signal,
|
|
203
|
+
});
|
|
204
|
+
return streamInstance.stream;
|
|
198
205
|
}
|
|
199
206
|
async function fetchStream(key, signal) {
|
|
200
207
|
return runMetadata.fetchStream(key, signal);
|