@langchain/langgraph-sdk 0.0.37 → 0.0.39
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/client.cjs +10 -66
- package/dist/client.d.ts +19 -24
- package/dist/client.js +10 -66
- package/dist/index.cjs +3 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +1 -0
- package/dist/react/debug.cjs +32 -0
- package/dist/react/debug.d.ts +23 -0
- package/dist/react/debug.js +28 -0
- package/dist/react/index.cjs +5 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +1 -0
- package/dist/react/stream.cjs +411 -0
- package/dist/react/stream.d.ts +46 -0
- package/dist/react/stream.js +407 -0
- package/dist/schema.d.ts +7 -7
- package/dist/singletons/fetch.cjs +27 -0
- package/dist/singletons/fetch.d.ts +11 -0
- package/dist/singletons/fetch.js +22 -0
- package/dist/types.d.ts +6 -16
- package/dist/types.messages.d.ts +88 -0
- package/dist/types.stream.cjs +2 -0
- package/dist/types.stream.d.ts +156 -0
- package/dist/types.stream.js +1 -0
- package/dist/utils/async_caller.cjs +2 -1
- package/dist/utils/async_caller.js +2 -1
- package/dist/utils/sse.cjs +151 -0
- package/dist/utils/sse.d.ts +11 -0
- package/dist/utils/sse.js +146 -0
- package/package.json +23 -3
- package/react.cjs +1 -0
- package/react.d.cts +1 -0
- package/react.d.ts +1 -0
- package/react.js +1 -0
- package/dist/utils/eventsource-parser/index.cjs +0 -7
- package/dist/utils/eventsource-parser/index.d.ts +0 -2
- package/dist/utils/eventsource-parser/index.js +0 -3
- package/dist/utils/eventsource-parser/parse.cjs +0 -150
- package/dist/utils/eventsource-parser/parse.d.ts +0 -18
- package/dist/utils/eventsource-parser/parse.js +0 -146
- package/dist/utils/eventsource-parser/stream.cjs +0 -34
- package/dist/utils/eventsource-parser/stream.d.ts +0 -17
- package/dist/utils/eventsource-parser/stream.js +0 -30
- package/dist/utils/eventsource-parser/types.d.ts +0 -81
- /package/dist/{utils/eventsource-parser/types.cjs → types.messages.cjs} +0 -0
- /package/dist/{utils/eventsource-parser/types.js → types.messages.js} +0 -0
package/dist/client.cjs
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Client = exports.StoreClient = exports.RunsClient = exports.ThreadsClient = exports.AssistantsClient = exports.CronsClient = exports.getApiKey = void 0;
|
|
4
4
|
const async_caller_js_1 = require("./utils/async_caller.cjs");
|
|
5
|
-
const index_js_1 = require("./utils/eventsource-parser/index.cjs");
|
|
6
5
|
const stream_js_1 = require("./utils/stream.cjs");
|
|
7
6
|
const signals_js_1 = require("./utils/signals.cjs");
|
|
8
7
|
const env_js_1 = require("./utils/env.cjs");
|
|
8
|
+
const sse_js_1 = require("./utils/sse.cjs");
|
|
9
9
|
/**
|
|
10
10
|
* Get the API key from the environment.
|
|
11
11
|
* Precedence:
|
|
@@ -63,7 +63,7 @@ class BaseClient {
|
|
|
63
63
|
maxConcurrency: 4,
|
|
64
64
|
...config?.callerOptions,
|
|
65
65
|
});
|
|
66
|
-
this.timeoutMs = config?.timeoutMs
|
|
66
|
+
this.timeoutMs = config?.timeoutMs;
|
|
67
67
|
// default limit being capped by Chrome
|
|
68
68
|
// https://github.com/nodejs/undici/issues/1373
|
|
69
69
|
// Regex to remove trailing slash, if present
|
|
@@ -93,7 +93,7 @@ class BaseClient {
|
|
|
93
93
|
timeoutSignal = AbortSignal.timeout(options.timeoutMs);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
else {
|
|
96
|
+
else if (this.timeoutMs != null) {
|
|
97
97
|
timeoutSignal = AbortSignal.timeout(this.timeoutMs);
|
|
98
98
|
}
|
|
99
99
|
mutatedOptions.signal = (0, signals_js_1.mergeSignals)(timeoutSignal, mutatedOptions.signal);
|
|
@@ -455,7 +455,7 @@ class ThreadsClient extends BaseClient {
|
|
|
455
455
|
async patchState(threadIdOrConfig, metadata) {
|
|
456
456
|
let threadId;
|
|
457
457
|
if (typeof threadIdOrConfig !== "string") {
|
|
458
|
-
if (typeof threadIdOrConfig.configurable
|
|
458
|
+
if (typeof threadIdOrConfig.configurable?.thread_id !== "string") {
|
|
459
459
|
throw new Error("Thread ID is required when updating state with a config.");
|
|
460
460
|
}
|
|
461
461
|
threadId = threadIdOrConfig.configurable.thread_id;
|
|
@@ -524,37 +524,9 @@ class RunsClient extends BaseClient {
|
|
|
524
524
|
timeoutMs: null,
|
|
525
525
|
signal: payload?.signal,
|
|
526
526
|
}));
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() })).pipeThrough(new TransformStream({
|
|
531
|
-
async start(ctrl) {
|
|
532
|
-
parser = (0, index_js_1.createParser)((event) => {
|
|
533
|
-
if ((payload?.signal && payload.signal.aborted) ||
|
|
534
|
-
(event.type === "event" && event.data === "[DONE]")) {
|
|
535
|
-
ctrl.terminate();
|
|
536
|
-
return;
|
|
537
|
-
}
|
|
538
|
-
if ("data" in event) {
|
|
539
|
-
ctrl.enqueue({
|
|
540
|
-
event: event.event ?? "message",
|
|
541
|
-
data: JSON.parse(event.data),
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
});
|
|
545
|
-
onEndEvent = () => {
|
|
546
|
-
ctrl.enqueue({ event: "end", data: undefined });
|
|
547
|
-
};
|
|
548
|
-
},
|
|
549
|
-
async transform(chunk) {
|
|
550
|
-
const payload = textDecoder.decode(chunk);
|
|
551
|
-
parser.feed(payload);
|
|
552
|
-
// eventsource-parser will ignore events
|
|
553
|
-
// that are not terminated by a newline
|
|
554
|
-
if (payload.trim() === "event: end")
|
|
555
|
-
onEndEvent();
|
|
556
|
-
},
|
|
557
|
-
}));
|
|
527
|
+
const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() }))
|
|
528
|
+
.pipeThrough(new sse_js_1.BytesLineDecoder())
|
|
529
|
+
.pipeThrough(new sse_js_1.SSEDecoder());
|
|
558
530
|
yield* stream_js_1.IterableReadableStream.fromReadableStream(stream);
|
|
559
531
|
}
|
|
560
532
|
/**
|
|
@@ -728,37 +700,9 @@ class RunsClient extends BaseClient {
|
|
|
728
700
|
signal: opts?.signal,
|
|
729
701
|
params: { cancel_on_disconnect: opts?.cancelOnDisconnect ? "1" : "0" },
|
|
730
702
|
}));
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() })).pipeThrough(new TransformStream({
|
|
735
|
-
async start(ctrl) {
|
|
736
|
-
parser = (0, index_js_1.createParser)((event) => {
|
|
737
|
-
if ((opts?.signal && opts.signal.aborted) ||
|
|
738
|
-
(event.type === "event" && event.data === "[DONE]")) {
|
|
739
|
-
ctrl.terminate();
|
|
740
|
-
return;
|
|
741
|
-
}
|
|
742
|
-
if ("data" in event) {
|
|
743
|
-
ctrl.enqueue({
|
|
744
|
-
event: event.event ?? "message",
|
|
745
|
-
data: JSON.parse(event.data),
|
|
746
|
-
});
|
|
747
|
-
}
|
|
748
|
-
});
|
|
749
|
-
onEndEvent = () => {
|
|
750
|
-
ctrl.enqueue({ event: "end", data: undefined });
|
|
751
|
-
};
|
|
752
|
-
},
|
|
753
|
-
async transform(chunk) {
|
|
754
|
-
const payload = textDecoder.decode(chunk);
|
|
755
|
-
parser.feed(payload);
|
|
756
|
-
// eventsource-parser will ignore events
|
|
757
|
-
// that are not terminated by a newline
|
|
758
|
-
if (payload.trim() === "event: end")
|
|
759
|
-
onEndEvent();
|
|
760
|
-
},
|
|
761
|
-
}));
|
|
703
|
+
const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() }))
|
|
704
|
+
.pipeThrough(new sse_js_1.BytesLineDecoder())
|
|
705
|
+
.pipeThrough(new sse_js_1.SSEDecoder());
|
|
762
706
|
yield* stream_js_1.IterableReadableStream.fromReadableStream(stream);
|
|
763
707
|
}
|
|
764
708
|
/**
|
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Assistant, AssistantGraph, CancelAction, Config, DefaultValues, GraphSchema, Metadata, Run, RunStatus, Thread, ThreadState, Cron, AssistantVersion, Subgraphs, Checkpoint, SearchItemsResponse, ListNamespaceResponse, Item, ThreadStatus, CronCreateResponse, CronCreateForThreadResponse } from "./schema.js";
|
|
2
2
|
import { AsyncCaller, AsyncCallerParams } from "./utils/async_caller.js";
|
|
3
|
-
import { RunsCreatePayload, RunsStreamPayload, RunsWaitPayload, StreamEvent, CronsCreatePayload, OnConflictBehavior } from "./types.js";
|
|
3
|
+
import type { RunsCreatePayload, RunsStreamPayload, RunsWaitPayload, StreamEvent, CronsCreatePayload, OnConflictBehavior } from "./types.js";
|
|
4
|
+
import type { TypedAsyncGenerator, StreamMode } from "./types.stream.js";
|
|
4
5
|
/**
|
|
5
6
|
* Get the API key from the environment.
|
|
6
7
|
* Precedence:
|
|
@@ -13,7 +14,7 @@ import { RunsCreatePayload, RunsStreamPayload, RunsWaitPayload, StreamEvent, Cro
|
|
|
13
14
|
* @returns The API key if found, otherwise undefined
|
|
14
15
|
*/
|
|
15
16
|
export declare function getApiKey(apiKey?: string): string | undefined;
|
|
16
|
-
interface ClientConfig {
|
|
17
|
+
export interface ClientConfig {
|
|
17
18
|
apiUrl?: string;
|
|
18
19
|
apiKey?: string;
|
|
19
20
|
callerOptions?: AsyncCallerParams;
|
|
@@ -22,7 +23,7 @@ interface ClientConfig {
|
|
|
22
23
|
}
|
|
23
24
|
declare class BaseClient {
|
|
24
25
|
protected asyncCaller: AsyncCaller;
|
|
25
|
-
protected timeoutMs: number;
|
|
26
|
+
protected timeoutMs: number | undefined;
|
|
26
27
|
protected apiUrl: string;
|
|
27
28
|
protected defaultHeaders: Record<string, string | null | undefined>;
|
|
28
29
|
constructor(config?: ClientConfig);
|
|
@@ -167,14 +168,14 @@ export declare class AssistantsClient extends BaseClient {
|
|
|
167
168
|
*/
|
|
168
169
|
setLatest(assistantId: string, version: number): Promise<Assistant>;
|
|
169
170
|
}
|
|
170
|
-
export declare class ThreadsClient extends BaseClient {
|
|
171
|
+
export declare class ThreadsClient<TStateType = DefaultValues, TUpdateType = TStateType> extends BaseClient {
|
|
171
172
|
/**
|
|
172
173
|
* Get a thread by ID.
|
|
173
174
|
*
|
|
174
175
|
* @param threadId ID of the thread.
|
|
175
176
|
* @returns The thread.
|
|
176
177
|
*/
|
|
177
|
-
get(threadId: string): Promise<Thread
|
|
178
|
+
get<ValuesType = TStateType>(threadId: string): Promise<Thread<ValuesType>>;
|
|
178
179
|
/**
|
|
179
180
|
* Create a new thread.
|
|
180
181
|
*
|
|
@@ -188,13 +189,13 @@ export declare class ThreadsClient extends BaseClient {
|
|
|
188
189
|
metadata?: Metadata;
|
|
189
190
|
threadId?: string;
|
|
190
191
|
ifExists?: OnConflictBehavior;
|
|
191
|
-
}): Promise<Thread
|
|
192
|
+
}): Promise<Thread<TStateType>>;
|
|
192
193
|
/**
|
|
193
194
|
* Copy an existing thread
|
|
194
195
|
* @param threadId ID of the thread to be copied
|
|
195
196
|
* @returns Newly copied thread
|
|
196
197
|
*/
|
|
197
|
-
copy(threadId: string): Promise<Thread
|
|
198
|
+
copy(threadId: string): Promise<Thread<TStateType>>;
|
|
198
199
|
/**
|
|
199
200
|
* Update a thread.
|
|
200
201
|
*
|
|
@@ -220,7 +221,7 @@ export declare class ThreadsClient extends BaseClient {
|
|
|
220
221
|
* @param query Query options
|
|
221
222
|
* @returns List of threads
|
|
222
223
|
*/
|
|
223
|
-
search(query?: {
|
|
224
|
+
search<ValuesType = TStateType>(query?: {
|
|
224
225
|
/**
|
|
225
226
|
* Metadata to filter threads by.
|
|
226
227
|
*/
|
|
@@ -239,14 +240,14 @@ export declare class ThreadsClient extends BaseClient {
|
|
|
239
240
|
* Must be one of 'idle', 'busy', 'interrupted' or 'error'.
|
|
240
241
|
*/
|
|
241
242
|
status?: ThreadStatus;
|
|
242
|
-
}): Promise<Thread[]>;
|
|
243
|
+
}): Promise<Thread<ValuesType>[]>;
|
|
243
244
|
/**
|
|
244
245
|
* Get state for a thread.
|
|
245
246
|
*
|
|
246
247
|
* @param threadId ID of the thread.
|
|
247
248
|
* @returns Thread state.
|
|
248
249
|
*/
|
|
249
|
-
getState<ValuesType =
|
|
250
|
+
getState<ValuesType = TStateType>(threadId: string, checkpoint?: Checkpoint | string, options?: {
|
|
250
251
|
subgraphs?: boolean;
|
|
251
252
|
}): Promise<ThreadState<ValuesType>>;
|
|
252
253
|
/**
|
|
@@ -255,7 +256,7 @@ export declare class ThreadsClient extends BaseClient {
|
|
|
255
256
|
* @param threadId The ID of the thread.
|
|
256
257
|
* @returns
|
|
257
258
|
*/
|
|
258
|
-
updateState<ValuesType =
|
|
259
|
+
updateState<ValuesType = TUpdateType>(threadId: string, options: {
|
|
259
260
|
values: ValuesType;
|
|
260
261
|
checkpoint?: Checkpoint;
|
|
261
262
|
checkpointId?: string;
|
|
@@ -275,22 +276,16 @@ export declare class ThreadsClient extends BaseClient {
|
|
|
275
276
|
* @param options Additional options.
|
|
276
277
|
* @returns List of thread states.
|
|
277
278
|
*/
|
|
278
|
-
getHistory<ValuesType =
|
|
279
|
+
getHistory<ValuesType = TStateType>(threadId: string, options?: {
|
|
279
280
|
limit?: number;
|
|
280
281
|
before?: Config;
|
|
281
282
|
checkpoint?: Partial<Omit<Checkpoint, "thread_id">>;
|
|
282
283
|
metadata?: Metadata;
|
|
283
284
|
}): Promise<ThreadState<ValuesType>[]>;
|
|
284
285
|
}
|
|
285
|
-
export declare class RunsClient extends BaseClient {
|
|
286
|
-
stream(threadId: null, assistantId: string, payload?: Omit<RunsStreamPayload, "multitaskStrategy" | "onCompletion">):
|
|
287
|
-
|
|
288
|
-
data: any;
|
|
289
|
-
}>;
|
|
290
|
-
stream(threadId: string, assistantId: string, payload?: RunsStreamPayload): AsyncGenerator<{
|
|
291
|
-
event: StreamEvent;
|
|
292
|
-
data: any;
|
|
293
|
-
}>;
|
|
286
|
+
export declare class RunsClient<TStateType = DefaultValues, TUpdateType = TStateType, TCustomEventType = unknown> extends BaseClient {
|
|
287
|
+
stream<TStreamMode extends StreamMode | StreamMode[] = StreamMode, TSubgraphs extends boolean = false>(threadId: null, assistantId: string, payload?: Omit<RunsStreamPayload<TStreamMode, TSubgraphs>, "multitaskStrategy" | "onCompletion">): TypedAsyncGenerator<TStreamMode, TSubgraphs, TStateType, TUpdateType, TCustomEventType>;
|
|
288
|
+
stream<TStreamMode extends StreamMode | StreamMode[] = StreamMode, TSubgraphs extends boolean = false>(threadId: string, assistantId: string, payload?: RunsStreamPayload<TStreamMode, TSubgraphs>): TypedAsyncGenerator<TStreamMode, TSubgraphs, TStateType, TUpdateType, TCustomEventType>;
|
|
294
289
|
/**
|
|
295
290
|
* Create a run.
|
|
296
291
|
*
|
|
@@ -447,7 +442,7 @@ export declare class StoreClient extends BaseClient {
|
|
|
447
442
|
offset?: number;
|
|
448
443
|
}): Promise<ListNamespaceResponse>;
|
|
449
444
|
}
|
|
450
|
-
export declare class Client {
|
|
445
|
+
export declare class Client<TStateType = DefaultValues, TUpdateType = TStateType, TCustomEventType = unknown> {
|
|
451
446
|
/**
|
|
452
447
|
* The client for interacting with assistants.
|
|
453
448
|
*/
|
|
@@ -455,11 +450,11 @@ export declare class Client {
|
|
|
455
450
|
/**
|
|
456
451
|
* The client for interacting with threads.
|
|
457
452
|
*/
|
|
458
|
-
threads: ThreadsClient
|
|
453
|
+
threads: ThreadsClient<TStateType, TUpdateType>;
|
|
459
454
|
/**
|
|
460
455
|
* The client for interacting with runs.
|
|
461
456
|
*/
|
|
462
|
-
runs: RunsClient
|
|
457
|
+
runs: RunsClient<TStateType, TUpdateType, TCustomEventType>;
|
|
463
458
|
/**
|
|
464
459
|
* The client for interacting with cron runs.
|
|
465
460
|
*/
|
package/dist/client.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AsyncCaller } from "./utils/async_caller.js";
|
|
2
|
-
import { createParser, } from "./utils/eventsource-parser/index.js";
|
|
3
2
|
import { IterableReadableStream } from "./utils/stream.js";
|
|
4
3
|
import { mergeSignals } from "./utils/signals.js";
|
|
5
4
|
import { getEnvironmentVariable } from "./utils/env.js";
|
|
5
|
+
import { BytesLineDecoder, SSEDecoder } from "./utils/sse.js";
|
|
6
6
|
/**
|
|
7
7
|
* Get the API key from the environment.
|
|
8
8
|
* Precedence:
|
|
@@ -59,7 +59,7 @@ class BaseClient {
|
|
|
59
59
|
maxConcurrency: 4,
|
|
60
60
|
...config?.callerOptions,
|
|
61
61
|
});
|
|
62
|
-
this.timeoutMs = config?.timeoutMs
|
|
62
|
+
this.timeoutMs = config?.timeoutMs;
|
|
63
63
|
// default limit being capped by Chrome
|
|
64
64
|
// https://github.com/nodejs/undici/issues/1373
|
|
65
65
|
// Regex to remove trailing slash, if present
|
|
@@ -89,7 +89,7 @@ class BaseClient {
|
|
|
89
89
|
timeoutSignal = AbortSignal.timeout(options.timeoutMs);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
else {
|
|
92
|
+
else if (this.timeoutMs != null) {
|
|
93
93
|
timeoutSignal = AbortSignal.timeout(this.timeoutMs);
|
|
94
94
|
}
|
|
95
95
|
mutatedOptions.signal = mergeSignals(timeoutSignal, mutatedOptions.signal);
|
|
@@ -449,7 +449,7 @@ export class ThreadsClient extends BaseClient {
|
|
|
449
449
|
async patchState(threadIdOrConfig, metadata) {
|
|
450
450
|
let threadId;
|
|
451
451
|
if (typeof threadIdOrConfig !== "string") {
|
|
452
|
-
if (typeof threadIdOrConfig.configurable
|
|
452
|
+
if (typeof threadIdOrConfig.configurable?.thread_id !== "string") {
|
|
453
453
|
throw new Error("Thread ID is required when updating state with a config.");
|
|
454
454
|
}
|
|
455
455
|
threadId = threadIdOrConfig.configurable.thread_id;
|
|
@@ -517,37 +517,9 @@ export class RunsClient extends BaseClient {
|
|
|
517
517
|
timeoutMs: null,
|
|
518
518
|
signal: payload?.signal,
|
|
519
519
|
}));
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() })).pipeThrough(new TransformStream({
|
|
524
|
-
async start(ctrl) {
|
|
525
|
-
parser = createParser((event) => {
|
|
526
|
-
if ((payload?.signal && payload.signal.aborted) ||
|
|
527
|
-
(event.type === "event" && event.data === "[DONE]")) {
|
|
528
|
-
ctrl.terminate();
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
if ("data" in event) {
|
|
532
|
-
ctrl.enqueue({
|
|
533
|
-
event: event.event ?? "message",
|
|
534
|
-
data: JSON.parse(event.data),
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
});
|
|
538
|
-
onEndEvent = () => {
|
|
539
|
-
ctrl.enqueue({ event: "end", data: undefined });
|
|
540
|
-
};
|
|
541
|
-
},
|
|
542
|
-
async transform(chunk) {
|
|
543
|
-
const payload = textDecoder.decode(chunk);
|
|
544
|
-
parser.feed(payload);
|
|
545
|
-
// eventsource-parser will ignore events
|
|
546
|
-
// that are not terminated by a newline
|
|
547
|
-
if (payload.trim() === "event: end")
|
|
548
|
-
onEndEvent();
|
|
549
|
-
},
|
|
550
|
-
}));
|
|
520
|
+
const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() }))
|
|
521
|
+
.pipeThrough(new BytesLineDecoder())
|
|
522
|
+
.pipeThrough(new SSEDecoder());
|
|
551
523
|
yield* IterableReadableStream.fromReadableStream(stream);
|
|
552
524
|
}
|
|
553
525
|
/**
|
|
@@ -721,37 +693,9 @@ export class RunsClient extends BaseClient {
|
|
|
721
693
|
signal: opts?.signal,
|
|
722
694
|
params: { cancel_on_disconnect: opts?.cancelOnDisconnect ? "1" : "0" },
|
|
723
695
|
}));
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() })).pipeThrough(new TransformStream({
|
|
728
|
-
async start(ctrl) {
|
|
729
|
-
parser = createParser((event) => {
|
|
730
|
-
if ((opts?.signal && opts.signal.aborted) ||
|
|
731
|
-
(event.type === "event" && event.data === "[DONE]")) {
|
|
732
|
-
ctrl.terminate();
|
|
733
|
-
return;
|
|
734
|
-
}
|
|
735
|
-
if ("data" in event) {
|
|
736
|
-
ctrl.enqueue({
|
|
737
|
-
event: event.event ?? "message",
|
|
738
|
-
data: JSON.parse(event.data),
|
|
739
|
-
});
|
|
740
|
-
}
|
|
741
|
-
});
|
|
742
|
-
onEndEvent = () => {
|
|
743
|
-
ctrl.enqueue({ event: "end", data: undefined });
|
|
744
|
-
};
|
|
745
|
-
},
|
|
746
|
-
async transform(chunk) {
|
|
747
|
-
const payload = textDecoder.decode(chunk);
|
|
748
|
-
parser.feed(payload);
|
|
749
|
-
// eventsource-parser will ignore events
|
|
750
|
-
// that are not terminated by a newline
|
|
751
|
-
if (payload.trim() === "event: end")
|
|
752
|
-
onEndEvent();
|
|
753
|
-
},
|
|
754
|
-
}));
|
|
696
|
+
const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() }))
|
|
697
|
+
.pipeThrough(new BytesLineDecoder())
|
|
698
|
+
.pipeThrough(new SSEDecoder());
|
|
755
699
|
yield* IterableReadableStream.fromReadableStream(stream);
|
|
756
700
|
}
|
|
757
701
|
/**
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Client = void 0;
|
|
3
|
+
exports.overrideFetchImplementation = exports.Client = void 0;
|
|
4
4
|
var client_js_1 = require("./client.cjs");
|
|
5
5
|
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_js_1.Client; } });
|
|
6
|
+
var fetch_js_1 = require("./singletons/fetch.cjs");
|
|
7
|
+
Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true, get: function () { return fetch_js_1.overrideFetchImplementation; } });
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
export { Client } from "./client.js";
|
|
2
|
-
export type { Assistant, AssistantVersion, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run, Thread, ThreadTask, ThreadState, ThreadStatus, Cron, Checkpoint, Interrupt, } from "./schema.js";
|
|
2
|
+
export type { Assistant, AssistantVersion, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run, Thread, ThreadTask, ThreadState, ThreadStatus, Cron, Checkpoint, Interrupt, ListNamespaceResponse, Item, SearchItem, SearchItemsResponse, CronCreateResponse, CronCreateForThreadResponse, } from "./schema.js";
|
|
3
|
+
export { overrideFetchImplementation } from "./singletons/fetch.js";
|
|
3
4
|
export type { OnConflictBehavior, Command } from "./types.js";
|
|
5
|
+
export type { StreamMode } from "./types.stream.js";
|
|
6
|
+
export type { ValuesStreamEvent, MessagesTupleStreamEvent, MetadataStreamEvent, UpdatesStreamEvent, CustomStreamEvent, MessagesStreamEvent, DebugStreamEvent, EventsStreamEvent, ErrorStreamEvent, FeedbackStreamEvent, } from "./types.stream.js";
|
|
7
|
+
export type { Message, HumanMessage, AIMessage, ToolMessage, SystemMessage, FunctionMessage, RemoveMessage, } from "./types.messages.js";
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DebugSegmentsView = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
function DebugSegmentsView(props) {
|
|
6
|
+
const concatContent = (value) => {
|
|
7
|
+
let content;
|
|
8
|
+
try {
|
|
9
|
+
content = value.values?.messages?.at(-1)?.content ?? "";
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
content = JSON.stringify(value.values);
|
|
13
|
+
}
|
|
14
|
+
content = content.replace(/(\n|\r\n)/g, "");
|
|
15
|
+
if (content.length <= 23)
|
|
16
|
+
return content;
|
|
17
|
+
return `${content.slice(0, 10)}...${content.slice(-10)}`;
|
|
18
|
+
};
|
|
19
|
+
return ((0, jsx_runtime_1.jsx)("div", { children: props.sequence.items.map((item, index) => {
|
|
20
|
+
if (item.type === "fork") {
|
|
21
|
+
return ((0, jsx_runtime_1.jsx)("div", { children: item.items.map((fork, idx) => {
|
|
22
|
+
const [first] = fork.items;
|
|
23
|
+
return ((0, jsx_runtime_1.jsxs)("details", { children: [(0, jsx_runtime_1.jsxs)("summary", { children: ["Fork", " ", (0, jsx_runtime_1.jsxs)("span", { className: "font-mono", children: ["...", first.path.at(-1)?.slice(-4)] })] }), (0, jsx_runtime_1.jsx)("div", { className: "ml-4", children: (0, jsx_runtime_1.jsx)(DebugSegmentsView, { sequence: fork }) })] }, idx));
|
|
24
|
+
}) }, index));
|
|
25
|
+
}
|
|
26
|
+
if (item.type === "node") {
|
|
27
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-2", children: [(0, jsx_runtime_1.jsxs)("pre", { children: ["(", item.value.metadata?.step, ") ...", item.value.checkpoint.checkpoint_id?.slice(-4), " (", item.value.metadata?.source, "): ", concatContent(item.value)] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "border rounded-sm text-sm py-0.5 px-1 text-muted-foreground", onClick: () => console.log(item.path, item.value), children: "console.log" })] }, index));
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}) }));
|
|
31
|
+
}
|
|
32
|
+
exports.DebugSegmentsView = DebugSegmentsView;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ThreadState } from "../schema.js";
|
|
2
|
+
interface Node<StateType = any> {
|
|
3
|
+
type: "node";
|
|
4
|
+
value: ThreadState<StateType>;
|
|
5
|
+
path: string[];
|
|
6
|
+
}
|
|
7
|
+
interface ValidFork<StateType = any> {
|
|
8
|
+
type: "fork";
|
|
9
|
+
items: Array<ValidSequence<StateType>>;
|
|
10
|
+
}
|
|
11
|
+
interface ValidSequence<StateType = any> {
|
|
12
|
+
type: "sequence";
|
|
13
|
+
items: [Node<StateType>, ...(Node<StateType> | ValidFork<StateType>)[]];
|
|
14
|
+
}
|
|
15
|
+
export type CheckpointBranchPath = string[];
|
|
16
|
+
export type MessageBranch = {
|
|
17
|
+
current: CheckpointBranchPath;
|
|
18
|
+
options: CheckpointBranchPath[];
|
|
19
|
+
};
|
|
20
|
+
export declare function DebugSegmentsView(props: {
|
|
21
|
+
sequence: ValidSequence<ThreadState>;
|
|
22
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
export function DebugSegmentsView(props) {
|
|
3
|
+
const concatContent = (value) => {
|
|
4
|
+
let content;
|
|
5
|
+
try {
|
|
6
|
+
content = value.values?.messages?.at(-1)?.content ?? "";
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
content = JSON.stringify(value.values);
|
|
10
|
+
}
|
|
11
|
+
content = content.replace(/(\n|\r\n)/g, "");
|
|
12
|
+
if (content.length <= 23)
|
|
13
|
+
return content;
|
|
14
|
+
return `${content.slice(0, 10)}...${content.slice(-10)}`;
|
|
15
|
+
};
|
|
16
|
+
return (_jsx("div", { children: props.sequence.items.map((item, index) => {
|
|
17
|
+
if (item.type === "fork") {
|
|
18
|
+
return (_jsx("div", { children: item.items.map((fork, idx) => {
|
|
19
|
+
const [first] = fork.items;
|
|
20
|
+
return (_jsxs("details", { children: [_jsxs("summary", { children: ["Fork", " ", _jsxs("span", { className: "font-mono", children: ["...", first.path.at(-1)?.slice(-4)] })] }), _jsx("div", { className: "ml-4", children: _jsx(DebugSegmentsView, { sequence: fork }) })] }, idx));
|
|
21
|
+
}) }, index));
|
|
22
|
+
}
|
|
23
|
+
if (item.type === "node") {
|
|
24
|
+
return (_jsxs("div", { className: "flex items-center gap-2", children: [_jsxs("pre", { children: ["(", item.value.metadata?.step, ") ...", item.value.checkpoint.checkpoint_id?.slice(-4), " (", item.value.metadata?.source, "): ", concatContent(item.value)] }), _jsx("button", { type: "button", className: "border rounded-sm text-sm py-0.5 px-1 text-muted-foreground", onClick: () => console.log(item.path, item.value), children: "console.log" })] }, index));
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}) }));
|
|
28
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useStream = void 0;
|
|
4
|
+
var stream_js_1 = require("./stream.cjs");
|
|
5
|
+
Object.defineProperty(exports, "useStream", { enumerable: true, get: function () { return stream_js_1.useStream; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useStream, type MessageMetadata } from "./stream.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useStream } from "./stream.js";
|