@langchain/langgraph-sdk 0.0.38 → 0.0.40

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 (40) hide show
  1. package/dist/client.cjs +10 -67
  2. package/dist/client.d.ts +18 -23
  3. package/dist/client.js +10 -67
  4. package/dist/index.d.ts +3 -0
  5. package/dist/react/debug.cjs +32 -0
  6. package/dist/react/debug.d.ts +23 -0
  7. package/dist/react/debug.js +28 -0
  8. package/dist/react/index.cjs +5 -0
  9. package/dist/react/index.d.ts +1 -0
  10. package/dist/react/index.js +1 -0
  11. package/dist/react/stream.cjs +411 -0
  12. package/dist/react/stream.d.ts +46 -0
  13. package/dist/react/stream.js +407 -0
  14. package/dist/types.d.ts +6 -16
  15. package/dist/types.messages.d.ts +88 -0
  16. package/dist/types.stream.cjs +2 -0
  17. package/dist/types.stream.d.ts +156 -0
  18. package/dist/types.stream.js +1 -0
  19. package/dist/utils/async_caller.cjs +2 -1
  20. package/dist/utils/async_caller.js +2 -1
  21. package/dist/utils/sse.cjs +157 -0
  22. package/dist/utils/sse.d.ts +11 -0
  23. package/dist/utils/sse.js +152 -0
  24. package/package.json +23 -3
  25. package/react.cjs +1 -0
  26. package/react.d.cts +1 -0
  27. package/react.d.ts +1 -0
  28. package/react.js +1 -0
  29. package/dist/utils/eventsource-parser/index.cjs +0 -7
  30. package/dist/utils/eventsource-parser/index.d.ts +0 -2
  31. package/dist/utils/eventsource-parser/index.js +0 -3
  32. package/dist/utils/eventsource-parser/parse.cjs +0 -150
  33. package/dist/utils/eventsource-parser/parse.d.ts +0 -18
  34. package/dist/utils/eventsource-parser/parse.js +0 -146
  35. package/dist/utils/eventsource-parser/stream.cjs +0 -34
  36. package/dist/utils/eventsource-parser/stream.d.ts +0 -17
  37. package/dist/utils/eventsource-parser/stream.js +0 -30
  38. package/dist/utils/eventsource-parser/types.d.ts +0 -81
  39. /package/dist/{utils/eventsource-parser/types.cjs → types.messages.cjs} +0 -0
  40. /package/dist/{utils/eventsource-parser/types.js → types.messages.js} +0 -0
package/dist/client.cjs CHANGED
@@ -2,11 +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");
9
- const fetch_js_1 = require("./singletons/fetch.cjs");
8
+ const sse_js_1 = require("./utils/sse.cjs");
10
9
  /**
11
10
  * Get the API key from the environment.
12
11
  * Precedence:
@@ -113,7 +112,7 @@ class BaseClient {
113
112
  return [targetUrl, mutatedOptions];
114
113
  }
115
114
  async fetch(path, options) {
116
- const response = await this.asyncCaller.call((0, fetch_js_1._getFetchImplementation)(), ...this.prepareFetchOptions(path, options));
115
+ const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(path, options));
117
116
  if (response.status === 202 || response.status === 204) {
118
117
  return undefined;
119
118
  }
@@ -519,43 +518,15 @@ class RunsClient extends BaseClient {
519
518
  if_not_exists: payload?.ifNotExists,
520
519
  };
521
520
  const endpoint = threadId == null ? `/runs/stream` : `/threads/${threadId}/runs/stream`;
522
- const response = await this.asyncCaller.call((0, fetch_js_1._getFetchImplementation)(), ...this.prepareFetchOptions(endpoint, {
521
+ const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(endpoint, {
523
522
  method: "POST",
524
523
  json,
525
524
  timeoutMs: null,
526
525
  signal: payload?.signal,
527
526
  }));
528
- let parser;
529
- let onEndEvent;
530
- const textDecoder = new TextDecoder();
531
- const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() })).pipeThrough(new TransformStream({
532
- async start(ctrl) {
533
- parser = (0, index_js_1.createParser)((event) => {
534
- if ((payload?.signal && payload.signal.aborted) ||
535
- (event.type === "event" && event.data === "[DONE]")) {
536
- ctrl.terminate();
537
- return;
538
- }
539
- if ("data" in event) {
540
- ctrl.enqueue({
541
- event: event.event ?? "message",
542
- data: JSON.parse(event.data),
543
- });
544
- }
545
- });
546
- onEndEvent = () => {
547
- ctrl.enqueue({ event: "end", data: undefined });
548
- };
549
- },
550
- async transform(chunk) {
551
- const payload = textDecoder.decode(chunk);
552
- parser.feed(payload);
553
- // eventsource-parser will ignore events
554
- // that are not terminated by a newline
555
- if (payload.trim() === "event: end")
556
- onEndEvent();
557
- },
558
- }));
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());
559
530
  yield* stream_js_1.IterableReadableStream.fromReadableStream(stream);
560
531
  }
561
532
  /**
@@ -723,43 +694,15 @@ class RunsClient extends BaseClient {
723
694
  options instanceof AbortSignal
724
695
  ? { signal: options }
725
696
  : options;
726
- const response = await this.asyncCaller.call((0, fetch_js_1._getFetchImplementation)(), ...this.prepareFetchOptions(`/threads/${threadId}/runs/${runId}/stream`, {
697
+ const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(`/threads/${threadId}/runs/${runId}/stream`, {
727
698
  method: "GET",
728
699
  timeoutMs: null,
729
700
  signal: opts?.signal,
730
701
  params: { cancel_on_disconnect: opts?.cancelOnDisconnect ? "1" : "0" },
731
702
  }));
732
- let parser;
733
- let onEndEvent;
734
- const textDecoder = new TextDecoder();
735
- const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() })).pipeThrough(new TransformStream({
736
- async start(ctrl) {
737
- parser = (0, index_js_1.createParser)((event) => {
738
- if ((opts?.signal && opts.signal.aborted) ||
739
- (event.type === "event" && event.data === "[DONE]")) {
740
- ctrl.terminate();
741
- return;
742
- }
743
- if ("data" in event) {
744
- ctrl.enqueue({
745
- event: event.event ?? "message",
746
- data: JSON.parse(event.data),
747
- });
748
- }
749
- });
750
- onEndEvent = () => {
751
- ctrl.enqueue({ event: "end", data: undefined });
752
- };
753
- },
754
- async transform(chunk) {
755
- const payload = textDecoder.decode(chunk);
756
- parser.feed(payload);
757
- // eventsource-parser will ignore events
758
- // that are not terminated by a newline
759
- if (payload.trim() === "event: end")
760
- onEndEvent();
761
- },
762
- }));
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());
763
706
  yield* stream_js_1.IterableReadableStream.fromReadableStream(stream);
764
707
  }
765
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;
@@ -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 = DefaultValues>(threadId: string, checkpoint?: Checkpoint | string, options?: {
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 = DefaultValues>(threadId: string, options: {
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 = DefaultValues>(threadId: string, options?: {
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">): AsyncGenerator<{
287
- event: StreamEvent;
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,9 +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";
6
- import { _getFetchImplementation } from "./singletons/fetch.js";
5
+ import { BytesLineDecoder, SSEDecoder } from "./utils/sse.js";
7
6
  /**
8
7
  * Get the API key from the environment.
9
8
  * Precedence:
@@ -109,7 +108,7 @@ class BaseClient {
109
108
  return [targetUrl, mutatedOptions];
110
109
  }
111
110
  async fetch(path, options) {
112
- const response = await this.asyncCaller.call(_getFetchImplementation(), ...this.prepareFetchOptions(path, options));
111
+ const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(path, options));
113
112
  if (response.status === 202 || response.status === 204) {
114
113
  return undefined;
115
114
  }
@@ -512,43 +511,15 @@ export class RunsClient extends BaseClient {
512
511
  if_not_exists: payload?.ifNotExists,
513
512
  };
514
513
  const endpoint = threadId == null ? `/runs/stream` : `/threads/${threadId}/runs/stream`;
515
- const response = await this.asyncCaller.call(_getFetchImplementation(), ...this.prepareFetchOptions(endpoint, {
514
+ const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(endpoint, {
516
515
  method: "POST",
517
516
  json,
518
517
  timeoutMs: null,
519
518
  signal: payload?.signal,
520
519
  }));
521
- let parser;
522
- let onEndEvent;
523
- const textDecoder = new TextDecoder();
524
- const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() })).pipeThrough(new TransformStream({
525
- async start(ctrl) {
526
- parser = createParser((event) => {
527
- if ((payload?.signal && payload.signal.aborted) ||
528
- (event.type === "event" && event.data === "[DONE]")) {
529
- ctrl.terminate();
530
- return;
531
- }
532
- if ("data" in event) {
533
- ctrl.enqueue({
534
- event: event.event ?? "message",
535
- data: JSON.parse(event.data),
536
- });
537
- }
538
- });
539
- onEndEvent = () => {
540
- ctrl.enqueue({ event: "end", data: undefined });
541
- };
542
- },
543
- async transform(chunk) {
544
- const payload = textDecoder.decode(chunk);
545
- parser.feed(payload);
546
- // eventsource-parser will ignore events
547
- // that are not terminated by a newline
548
- if (payload.trim() === "event: end")
549
- onEndEvent();
550
- },
551
- }));
520
+ const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() }))
521
+ .pipeThrough(new BytesLineDecoder())
522
+ .pipeThrough(new SSEDecoder());
552
523
  yield* IterableReadableStream.fromReadableStream(stream);
553
524
  }
554
525
  /**
@@ -716,43 +687,15 @@ export class RunsClient extends BaseClient {
716
687
  options instanceof AbortSignal
717
688
  ? { signal: options }
718
689
  : options;
719
- const response = await this.asyncCaller.call(_getFetchImplementation(), ...this.prepareFetchOptions(`/threads/${threadId}/runs/${runId}/stream`, {
690
+ const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(`/threads/${threadId}/runs/${runId}/stream`, {
720
691
  method: "GET",
721
692
  timeoutMs: null,
722
693
  signal: opts?.signal,
723
694
  params: { cancel_on_disconnect: opts?.cancelOnDisconnect ? "1" : "0" },
724
695
  }));
725
- let parser;
726
- let onEndEvent;
727
- const textDecoder = new TextDecoder();
728
- const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() })).pipeThrough(new TransformStream({
729
- async start(ctrl) {
730
- parser = createParser((event) => {
731
- if ((opts?.signal && opts.signal.aborted) ||
732
- (event.type === "event" && event.data === "[DONE]")) {
733
- ctrl.terminate();
734
- return;
735
- }
736
- if ("data" in event) {
737
- ctrl.enqueue({
738
- event: event.event ?? "message",
739
- data: JSON.parse(event.data),
740
- });
741
- }
742
- });
743
- onEndEvent = () => {
744
- ctrl.enqueue({ event: "end", data: undefined });
745
- };
746
- },
747
- async transform(chunk) {
748
- const payload = textDecoder.decode(chunk);
749
- parser.feed(payload);
750
- // eventsource-parser will ignore events
751
- // that are not terminated by a newline
752
- if (payload.trim() === "event: end")
753
- onEndEvent();
754
- },
755
- }));
696
+ const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() }))
697
+ .pipeThrough(new BytesLineDecoder())
698
+ .pipeThrough(new SSEDecoder());
756
699
  yield* IterableReadableStream.fromReadableStream(stream);
757
700
  }
758
701
  /**
package/dist/index.d.ts CHANGED
@@ -2,3 +2,6 @@ export { Client } from "./client.js";
2
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
3
  export { overrideFetchImplementation } from "./singletons/fetch.js";
4
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";
@@ -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";