@assistant-ui/react-langgraph 0.2.4 → 0.2.6

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/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import * as _assistant_ui_react from '@assistant-ui/react';
2
- import { AttachmentAdapter, SpeechSynthesisAdapter, FeedbackAdapter, useExternalMessageConverter } from '@assistant-ui/react';
1
+ import * as _assistant_ui_react_internal from '@assistant-ui/react/internal';
3
2
  import * as react from 'react';
3
+ import { AttachmentAdapter, SpeechSynthesisAdapter, FeedbackAdapter, useExternalMessageConverter } from '@assistant-ui/react';
4
4
 
5
5
  type ReadonlyJSONValue = null | string | number | boolean | ReadonlyJSONObject | ReadonlyJSONArray;
6
6
  type ReadonlyJSONObject = {
@@ -9,6 +9,7 @@ type ReadonlyJSONObject = {
9
9
  type ReadonlyJSONArray = readonly ReadonlyJSONValue[];
10
10
 
11
11
  type LangChainToolCallChunk = {
12
+ index: number;
12
13
  id: string;
13
14
  name: string;
14
15
  args: string;
@@ -16,6 +17,7 @@ type LangChainToolCallChunk = {
16
17
  type LangChainToolCall = {
17
18
  id: string;
18
19
  name: string;
20
+ argsText: string;
19
21
  args: ReadonlyJSONObject;
20
22
  };
21
23
  type MessageContentText = {
@@ -49,6 +51,7 @@ type LangChainMessage = {
49
51
  content: string;
50
52
  tool_call_id: string;
51
53
  name: string;
54
+ artifact?: any;
52
55
  } | {
53
56
  id?: string;
54
57
  type: "ai";
@@ -56,6 +59,14 @@ type LangChainMessage = {
56
59
  tool_call_chunks?: LangChainToolCallChunk[];
57
60
  tool_calls?: LangChainToolCall[];
58
61
  };
62
+ type LangChainMessageChunk = {
63
+ id: string;
64
+ type: "AIMessageChunk";
65
+ content: (AssistantMessageContentComplex & {
66
+ index: number;
67
+ })[];
68
+ tool_call_chunks: LangChainToolCallChunk[];
69
+ };
59
70
  type LangChainEvent = {
60
71
  event: "messages/partial" | "messages/complete";
61
72
  data: LangChainMessage[];
@@ -69,7 +80,7 @@ type LangGraphSendMessageConfig = {
69
80
  runConfig?: unknown;
70
81
  };
71
82
  type LangGraphMessagesEvent<TMessage> = {
72
- event: "messages/partial" | "messages/complete" | "metadata" | "updates" | string;
83
+ event: "messages" | "messages/partial" | "messages/complete" | "metadata" | "updates" | string;
73
84
  data: TMessage[] | any;
74
85
  };
75
86
  type LangGraphStreamCallback<TMessage> = (messages: TMessage[], config: LangGraphSendMessageConfig & {
@@ -79,17 +90,19 @@ type LangGraphInterruptState = {
79
90
  value: any;
80
91
  resumable: boolean;
81
92
  when: string;
82
- ns: string[];
93
+ ns?: string[];
83
94
  };
84
95
  declare const useLangGraphMessages: <TMessage extends {
85
96
  id?: string;
86
- }>({ stream, }: {
97
+ }>({ stream, appendMessage, }: {
87
98
  stream: LangGraphStreamCallback<TMessage>;
99
+ appendMessage?: (prev: TMessage | undefined, curr: TMessage) => TMessage;
88
100
  }) => {
89
101
  interrupt: LangGraphInterruptState | undefined;
90
102
  messages: TMessage[];
91
103
  sendMessage: (newMessages: TMessage[], config: LangGraphSendMessageConfig) => Promise<void>;
92
104
  cancel: () => void;
105
+ setInterrupt: react.Dispatch<react.SetStateAction<LangGraphInterruptState | undefined>>;
93
106
  setMessages: react.Dispatch<react.SetStateAction<TMessage[]>>;
94
107
  };
95
108
 
@@ -114,14 +127,33 @@ declare const useLangGraphRuntime: ({ autoCancelPendingToolCalls, adapters: { at
114
127
  onSwitchToNewThread?: () => Promise<void> | void;
115
128
  onSwitchToThread?: (threadId: string) => Promise<{
116
129
  messages: LangChainMessage[];
130
+ interrupts?: LangGraphInterruptState[];
117
131
  }>;
118
132
  adapters?: {
119
133
  attachments?: AttachmentAdapter;
120
134
  speech?: SpeechSynthesisAdapter;
121
135
  feedback?: FeedbackAdapter;
122
136
  } | undefined;
123
- }) => _assistant_ui_react.AssistantRuntime;
137
+ }) => _assistant_ui_react_internal.AssistantRuntimeImpl;
138
+
139
+ declare const convertLangChainMessages: useExternalMessageConverter.Callback<LangChainMessage>;
140
+
141
+ type LangGraphStateAccumulatorConfig<TMessage> = {
142
+ initialMessages?: TMessage[];
143
+ appendMessage?: (prev: TMessage | undefined, curr: TMessage) => TMessage;
144
+ };
145
+ declare class LangGraphMessageAccumulator<TMessage extends {
146
+ id?: string;
147
+ }> {
148
+ private messagesMap;
149
+ private appendMessage;
150
+ constructor({ initialMessages, appendMessage, }?: LangGraphStateAccumulatorConfig<TMessage>);
151
+ private ensureMessageId;
152
+ addMessages(newMessages: TMessage[]): TMessage[];
153
+ getMessages(): TMessage[];
154
+ clear(): void;
155
+ }
124
156
 
125
- declare const convertLangchainMessages: useExternalMessageConverter.Callback<LangChainMessage>;
157
+ declare const appendLangChainChunk: (prev: LangChainMessage | undefined, curr: LangChainMessage | LangChainMessageChunk) => LangChainMessage;
126
158
 
127
- export { type LangChainEvent, type LangChainMessage, type LangChainToolCall, type LangChainToolCallChunk, type LangGraphCommand, type LangGraphInterruptState, type LangGraphSendMessageConfig, type LangGraphStreamCallback, convertLangchainMessages, useLangGraphInterruptState, useLangGraphMessages, useLangGraphRuntime, useLangGraphSend, useLangGraphSendCommand };
159
+ export { type LangChainEvent, type LangChainMessage, type LangChainToolCall, type LangChainToolCallChunk, type LangGraphCommand, type LangGraphInterruptState, LangGraphMessageAccumulator, type LangGraphSendMessageConfig, type LangGraphStreamCallback, appendLangChainChunk, convertLangChainMessages, convertLangChainMessages as convertLangchainMessages, useLangGraphInterruptState, useLangGraphMessages, useLangGraphRuntime, useLangGraphSend, useLangGraphSendCommand };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import * as _assistant_ui_react from '@assistant-ui/react';
2
- import { AttachmentAdapter, SpeechSynthesisAdapter, FeedbackAdapter, useExternalMessageConverter } from '@assistant-ui/react';
1
+ import * as _assistant_ui_react_internal from '@assistant-ui/react/internal';
3
2
  import * as react from 'react';
3
+ import { AttachmentAdapter, SpeechSynthesisAdapter, FeedbackAdapter, useExternalMessageConverter } from '@assistant-ui/react';
4
4
 
5
5
  type ReadonlyJSONValue = null | string | number | boolean | ReadonlyJSONObject | ReadonlyJSONArray;
6
6
  type ReadonlyJSONObject = {
@@ -9,6 +9,7 @@ type ReadonlyJSONObject = {
9
9
  type ReadonlyJSONArray = readonly ReadonlyJSONValue[];
10
10
 
11
11
  type LangChainToolCallChunk = {
12
+ index: number;
12
13
  id: string;
13
14
  name: string;
14
15
  args: string;
@@ -16,6 +17,7 @@ type LangChainToolCallChunk = {
16
17
  type LangChainToolCall = {
17
18
  id: string;
18
19
  name: string;
20
+ argsText: string;
19
21
  args: ReadonlyJSONObject;
20
22
  };
21
23
  type MessageContentText = {
@@ -49,6 +51,7 @@ type LangChainMessage = {
49
51
  content: string;
50
52
  tool_call_id: string;
51
53
  name: string;
54
+ artifact?: any;
52
55
  } | {
53
56
  id?: string;
54
57
  type: "ai";
@@ -56,6 +59,14 @@ type LangChainMessage = {
56
59
  tool_call_chunks?: LangChainToolCallChunk[];
57
60
  tool_calls?: LangChainToolCall[];
58
61
  };
62
+ type LangChainMessageChunk = {
63
+ id: string;
64
+ type: "AIMessageChunk";
65
+ content: (AssistantMessageContentComplex & {
66
+ index: number;
67
+ })[];
68
+ tool_call_chunks: LangChainToolCallChunk[];
69
+ };
59
70
  type LangChainEvent = {
60
71
  event: "messages/partial" | "messages/complete";
61
72
  data: LangChainMessage[];
@@ -69,7 +80,7 @@ type LangGraphSendMessageConfig = {
69
80
  runConfig?: unknown;
70
81
  };
71
82
  type LangGraphMessagesEvent<TMessage> = {
72
- event: "messages/partial" | "messages/complete" | "metadata" | "updates" | string;
83
+ event: "messages" | "messages/partial" | "messages/complete" | "metadata" | "updates" | string;
73
84
  data: TMessage[] | any;
74
85
  };
75
86
  type LangGraphStreamCallback<TMessage> = (messages: TMessage[], config: LangGraphSendMessageConfig & {
@@ -79,17 +90,19 @@ type LangGraphInterruptState = {
79
90
  value: any;
80
91
  resumable: boolean;
81
92
  when: string;
82
- ns: string[];
93
+ ns?: string[];
83
94
  };
84
95
  declare const useLangGraphMessages: <TMessage extends {
85
96
  id?: string;
86
- }>({ stream, }: {
97
+ }>({ stream, appendMessage, }: {
87
98
  stream: LangGraphStreamCallback<TMessage>;
99
+ appendMessage?: (prev: TMessage | undefined, curr: TMessage) => TMessage;
88
100
  }) => {
89
101
  interrupt: LangGraphInterruptState | undefined;
90
102
  messages: TMessage[];
91
103
  sendMessage: (newMessages: TMessage[], config: LangGraphSendMessageConfig) => Promise<void>;
92
104
  cancel: () => void;
105
+ setInterrupt: react.Dispatch<react.SetStateAction<LangGraphInterruptState | undefined>>;
93
106
  setMessages: react.Dispatch<react.SetStateAction<TMessage[]>>;
94
107
  };
95
108
 
@@ -114,14 +127,33 @@ declare const useLangGraphRuntime: ({ autoCancelPendingToolCalls, adapters: { at
114
127
  onSwitchToNewThread?: () => Promise<void> | void;
115
128
  onSwitchToThread?: (threadId: string) => Promise<{
116
129
  messages: LangChainMessage[];
130
+ interrupts?: LangGraphInterruptState[];
117
131
  }>;
118
132
  adapters?: {
119
133
  attachments?: AttachmentAdapter;
120
134
  speech?: SpeechSynthesisAdapter;
121
135
  feedback?: FeedbackAdapter;
122
136
  } | undefined;
123
- }) => _assistant_ui_react.AssistantRuntime;
137
+ }) => _assistant_ui_react_internal.AssistantRuntimeImpl;
138
+
139
+ declare const convertLangChainMessages: useExternalMessageConverter.Callback<LangChainMessage>;
140
+
141
+ type LangGraphStateAccumulatorConfig<TMessage> = {
142
+ initialMessages?: TMessage[];
143
+ appendMessage?: (prev: TMessage | undefined, curr: TMessage) => TMessage;
144
+ };
145
+ declare class LangGraphMessageAccumulator<TMessage extends {
146
+ id?: string;
147
+ }> {
148
+ private messagesMap;
149
+ private appendMessage;
150
+ constructor({ initialMessages, appendMessage, }?: LangGraphStateAccumulatorConfig<TMessage>);
151
+ private ensureMessageId;
152
+ addMessages(newMessages: TMessage[]): TMessage[];
153
+ getMessages(): TMessage[];
154
+ clear(): void;
155
+ }
124
156
 
125
- declare const convertLangchainMessages: useExternalMessageConverter.Callback<LangChainMessage>;
157
+ declare const appendLangChainChunk: (prev: LangChainMessage | undefined, curr: LangChainMessage | LangChainMessageChunk) => LangChainMessage;
126
158
 
127
- export { type LangChainEvent, type LangChainMessage, type LangChainToolCall, type LangChainToolCallChunk, type LangGraphCommand, type LangGraphInterruptState, type LangGraphSendMessageConfig, type LangGraphStreamCallback, convertLangchainMessages, useLangGraphInterruptState, useLangGraphMessages, useLangGraphRuntime, useLangGraphSend, useLangGraphSendCommand };
159
+ export { type LangChainEvent, type LangChainMessage, type LangChainToolCall, type LangChainToolCallChunk, type LangGraphCommand, type LangGraphInterruptState, LangGraphMessageAccumulator, type LangGraphSendMessageConfig, type LangGraphStreamCallback, appendLangChainChunk, convertLangChainMessages, convertLangChainMessages as convertLangchainMessages, useLangGraphInterruptState, useLangGraphMessages, useLangGraphRuntime, useLangGraphSend, useLangGraphSendCommand };