@cloudbase/agent-adapter-langgraph 0.0.11 → 0.0.12

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @cloudbase/agent-adapter-langgraph
2
2
 
3
+ ## 1.0.1-alpha.6
4
+
5
+ ### Patch Changes
6
+
7
+ - alpha release 0.1.2-alpha.1
8
+ - Update all public packages to version 0.1.2-alpha.1
9
+ - Trigger automated alpha release workflow
10
+ - Includes latest features and improvements
11
+
12
+ - Updated dependencies
13
+ - @cloudbase/agent-agents@1.0.1-alpha.6
14
+
3
15
  ## 1.0.1-alpha.5
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -144,64 +144,82 @@ var LanggraphAgent = class extends import_client.AbstractAgent {
144
144
  }
145
145
  let interrupt;
146
146
  let currentToolCall = null;
147
- for await (const event of stream) {
148
- if (event.event.startsWith("ChannelWrite<")) {
149
- continue;
150
- }
151
- if (event.event === "on_chat_model_start") {
152
- chatModelRuns.push({ runId: event.run_id });
153
- continue;
154
- }
155
- if (event.event === "on_chat_model_stream") {
156
- let chatModelRun = chatModelRuns.find(
157
- (run) => run.runId === event.run_id
158
- );
159
- if (!chatModelRun) {
160
- subscriber.next({
161
- type: import_client.EventType.RUN_ERROR,
162
- message: `Received a message from an unknown chat model run. Run Id: ${event.run_id}`
163
- });
147
+ try {
148
+ for await (const event of stream) {
149
+ if (event.event.startsWith("ChannelWrite<")) {
164
150
  continue;
165
151
  }
166
- const chunkId = event.data.chunk.id;
167
- if (!chatModelRun.messageId) {
168
- chatModelRun.messageId = chunkId;
169
- subscriber.next({
170
- messageId: chunkId,
171
- type: import_client.EventType.TEXT_MESSAGE_START,
172
- role: "assistant"
173
- });
174
- } else if (chatModelRun.messageId !== chunkId) {
175
- subscriber.next({
176
- type: import_client.EventType.RUN_ERROR,
177
- message: `Received a message of unknown message id from current run. Run Id: ${event.run_id} Message Id from current run: ${chatModelRun.messageId} Message Id from received message: ${chunkId}`
178
- });
152
+ if (event.event === "on_chat_model_start") {
153
+ chatModelRuns.push({ runId: event.run_id });
179
154
  continue;
180
155
  }
181
- if (Array.isArray(event.data.chunk?.tool_call_chunks) && event.data.chunk?.tool_call_chunks?.length > 0) {
182
- const parentMessageId = chatModelRun.messageId;
183
- event.data.chunk.tool_call_chunks.map((x) => ({
184
- ...x,
185
- args: typeof x.args === "string" ? x.args : x.args ? JSON.stringify(x.args) : ""
186
- })).forEach((toolCall) => {
187
- if (currentToolCall) {
188
- if (toolCall.id && currentToolCall.id !== toolCall.id) {
189
- subscriber.next({
190
- toolCallId: currentToolCall.id,
191
- type: import_client.EventType.TOOL_CALL_END
192
- });
193
- if (toolCall.name && toolCall.id) {
194
- currentToolCall = toolCall;
156
+ if (event.event === "on_chat_model_stream") {
157
+ const chatModelRun = chatModelRuns.find(
158
+ (run) => run.runId === event.run_id
159
+ );
160
+ if (!chatModelRun) {
161
+ subscriber.next({
162
+ type: import_client.EventType.RUN_ERROR,
163
+ message: `Received a message from an unknown chat model run. Run Id: ${event.run_id}`
164
+ });
165
+ continue;
166
+ }
167
+ const chunkId = event.data.chunk.id;
168
+ if (!chatModelRun.messageId) {
169
+ chatModelRun.messageId = chunkId;
170
+ subscriber.next({
171
+ messageId: chunkId,
172
+ type: import_client.EventType.TEXT_MESSAGE_START,
173
+ role: "assistant"
174
+ });
175
+ } else if (chatModelRun.messageId !== chunkId) {
176
+ subscriber.next({
177
+ type: import_client.EventType.RUN_ERROR,
178
+ message: `Received a message of unknown message id from current run. Run Id: ${event.run_id} Message Id from current run: ${chatModelRun.messageId} Message Id from received message: ${chunkId}`
179
+ });
180
+ continue;
181
+ }
182
+ if (Array.isArray(event.data.chunk?.tool_call_chunks) && event.data.chunk?.tool_call_chunks?.length > 0) {
183
+ const parentMessageId = chatModelRun.messageId;
184
+ event.data.chunk.tool_call_chunks.map((x) => ({
185
+ ...x,
186
+ args: typeof x.args === "string" ? x.args : x.args ? JSON.stringify(x.args) : ""
187
+ })).forEach((toolCall) => {
188
+ if (currentToolCall) {
189
+ if (toolCall.id && currentToolCall.id !== toolCall.id) {
195
190
  subscriber.next({
196
191
  toolCallId: currentToolCall.id,
197
- toolCallName: currentToolCall.name,
198
- parentMessageId,
199
- type: import_client.EventType.TOOL_CALL_START
192
+ type: import_client.EventType.TOOL_CALL_END
200
193
  });
201
- if (currentToolCall.args) {
194
+ if (toolCall.name && toolCall.id) {
195
+ currentToolCall = toolCall;
202
196
  subscriber.next({
203
197
  toolCallId: currentToolCall.id,
204
- delta: currentToolCall.args,
198
+ toolCallName: currentToolCall.name,
199
+ parentMessageId,
200
+ type: import_client.EventType.TOOL_CALL_START
201
+ });
202
+ if (currentToolCall.args) {
203
+ subscriber.next({
204
+ toolCallId: currentToolCall.id,
205
+ delta: currentToolCall.args,
206
+ type: import_client.EventType.TOOL_CALL_ARGS
207
+ });
208
+ if (isValidJson(currentToolCall.args)) {
209
+ subscriber.next({
210
+ toolCallId: currentToolCall.id,
211
+ type: import_client.EventType.TOOL_CALL_END
212
+ });
213
+ currentToolCall = null;
214
+ }
215
+ }
216
+ }
217
+ } else {
218
+ if (toolCall.args) {
219
+ currentToolCall.args += toolCall.args;
220
+ subscriber.next({
221
+ toolCallId: currentToolCall.id,
222
+ delta: toolCall.args,
205
223
  type: import_client.EventType.TOOL_CALL_ARGS
206
224
  });
207
225
  if (isValidJson(currentToolCall.args)) {
@@ -214,120 +232,110 @@ var LanggraphAgent = class extends import_client.AbstractAgent {
214
232
  }
215
233
  }
216
234
  } else {
217
- if (toolCall.args) {
218
- currentToolCall.args += toolCall.args;
219
- subscriber.next({
220
- toolCallId: currentToolCall.id,
221
- delta: toolCall.args,
222
- type: import_client.EventType.TOOL_CALL_ARGS
223
- });
224
- if (isValidJson(currentToolCall.args)) {
225
- subscriber.next({
226
- toolCallId: currentToolCall.id,
227
- type: import_client.EventType.TOOL_CALL_END
228
- });
229
- currentToolCall = null;
230
- }
231
- }
232
- }
233
- } else {
234
- if (toolCall.name && toolCall.id) {
235
- currentToolCall = toolCall;
236
- subscriber.next({
237
- toolCallId: toolCall.id,
238
- toolCallName: toolCall.name,
239
- parentMessageId,
240
- type: import_client.EventType.TOOL_CALL_START
241
- });
242
- if (toolCall.args) {
235
+ if (toolCall.name && toolCall.id) {
236
+ currentToolCall = toolCall;
243
237
  subscriber.next({
244
238
  toolCallId: toolCall.id,
245
- delta: toolCall.args,
246
- type: import_client.EventType.TOOL_CALL_ARGS
239
+ toolCallName: toolCall.name,
240
+ parentMessageId,
241
+ type: import_client.EventType.TOOL_CALL_START
247
242
  });
248
- if (isValidJson(toolCall.args)) {
243
+ if (toolCall.args) {
249
244
  subscriber.next({
250
245
  toolCallId: toolCall.id,
251
- type: import_client.EventType.TOOL_CALL_END
246
+ delta: toolCall.args,
247
+ type: import_client.EventType.TOOL_CALL_ARGS
252
248
  });
253
- currentToolCall = null;
249
+ if (isValidJson(toolCall.args)) {
250
+ subscriber.next({
251
+ toolCallId: toolCall.id,
252
+ type: import_client.EventType.TOOL_CALL_END
253
+ });
254
+ currentToolCall = null;
255
+ }
254
256
  }
255
257
  }
256
258
  }
257
- }
258
- });
259
- }
260
- const delta = event.data.chunk.content;
261
- if (typeof delta === "string" && delta) {
262
- subscriber.next({
263
- messageId: chatModelRun.messageId,
264
- type: import_client.EventType.TEXT_MESSAGE_CONTENT,
265
- delta
266
- });
259
+ });
260
+ }
261
+ const delta = event.data.chunk.content;
262
+ if (typeof delta === "string" && delta) {
263
+ subscriber.next({
264
+ messageId: chatModelRun.messageId,
265
+ type: import_client.EventType.TEXT_MESSAGE_CONTENT,
266
+ delta
267
+ });
268
+ }
269
+ continue;
267
270
  }
268
- continue;
269
- }
270
- if (event.event === "on_chat_model_end") {
271
- const chatModelRun = chatModelRuns.find(
272
- (run) => run.runId === event.run_id
273
- );
274
- if (!chatModelRun) {
271
+ if (event.event === "on_chat_model_end") {
272
+ const chatModelRun = chatModelRuns.find(
273
+ (run) => run.runId === event.run_id
274
+ );
275
+ if (!chatModelRun) {
276
+ subscriber.next({
277
+ type: import_client.EventType.RUN_ERROR,
278
+ message: `Received a on_chat_model_end event from an unknown chat model run. Run Id: ${event.run_id}`
279
+ });
280
+ continue;
281
+ }
275
282
  subscriber.next({
276
- type: import_client.EventType.RUN_ERROR,
277
- message: `Received a on_chat_model_end event from an unknown chat model run. Run Id: ${event.run_id}`
283
+ type: import_client.EventType.TEXT_MESSAGE_END,
284
+ messageId: chatModelRun.messageId
278
285
  });
279
286
  continue;
280
287
  }
281
- subscriber.next({
282
- type: import_client.EventType.TEXT_MESSAGE_END,
283
- messageId: chatModelRun.messageId
284
- });
285
- continue;
286
- }
287
- if (event.event === "on_tool_end") {
288
- const toolMessage = event.data.output;
289
- if (toolMessage && toolMessage.tool_call_id) {
290
- if (!handledToolCallIds.has(toolMessage.tool_call_id)) {
291
- if (!toolMessage.id) {
292
- toolMessage.id = crypto.randomUUID();
293
- if (toolMessage.lc_kwargs) {
294
- toolMessage.lc_kwargs.id = toolMessage.id;
288
+ if (event.event === "on_tool_end") {
289
+ const toolMessage = event.data.output;
290
+ if (toolMessage && toolMessage.tool_call_id) {
291
+ if (!handledToolCallIds.has(toolMessage.tool_call_id)) {
292
+ if (!toolMessage.id) {
293
+ toolMessage.id = crypto.randomUUID();
294
+ if (toolMessage.lc_kwargs) {
295
+ toolMessage.lc_kwargs.id = toolMessage.id;
296
+ }
295
297
  }
298
+ subscriber.next({
299
+ toolCallId: toolMessage.tool_call_id,
300
+ type: import_client.EventType.TOOL_CALL_RESULT,
301
+ content: typeof toolMessage.content === "string" ? toolMessage.content : JSON.stringify(toolMessage.content),
302
+ messageId: toolMessage.id
303
+ });
304
+ handledToolCallIds.add(toolMessage.tool_call_id);
296
305
  }
297
- subscriber.next({
298
- toolCallId: toolMessage.tool_call_id,
299
- type: import_client.EventType.TOOL_CALL_RESULT,
300
- content: typeof toolMessage.content === "string" ? toolMessage.content : JSON.stringify(toolMessage.content),
301
- messageId: toolMessage.id
302
- });
303
- handledToolCallIds.add(toolMessage.tool_call_id);
304
306
  }
307
+ continue;
308
+ }
309
+ if (event.event === "on_chain_stream" && event.data.chunk?.__interrupt__ && Array.isArray(event.data.chunk.__interrupt__) && event.data.chunk.__interrupt__.length > 0) {
310
+ const rawInterrupt = event.data.chunk.__interrupt__[0];
311
+ interrupt = {
312
+ id: rawInterrupt.id,
313
+ // TODO: replace with actual reason
314
+ reason: "agent requested interrupt",
315
+ payload: rawInterrupt.value
316
+ };
305
317
  }
306
- continue;
307
318
  }
308
- if (event.event === "on_chain_stream" && event.data.chunk?.__interrupt__ && Array.isArray(event.data.chunk.__interrupt__) && event.data.chunk.__interrupt__.length > 0) {
309
- const rawInterrupt = event.data.chunk.__interrupt__[0];
310
- interrupt = {
311
- id: rawInterrupt.id,
312
- // TODO: replace with actual reason
313
- reason: "agent requested interrupt",
314
- payload: rawInterrupt.value
315
- };
319
+ if (interrupt) {
320
+ subscriber.next({
321
+ type: import_client.EventType.RUN_FINISHED,
322
+ threadId,
323
+ runId,
324
+ outcome: "interrupt",
325
+ interrupt
326
+ });
327
+ } else {
328
+ subscriber.next({
329
+ type: import_client.EventType.RUN_FINISHED,
330
+ threadId,
331
+ runId
332
+ });
316
333
  }
317
- }
318
- if (interrupt) {
319
- subscriber.next({
320
- type: import_client.EventType.RUN_FINISHED,
321
- threadId,
322
- runId,
323
- outcome: "interrupt",
324
- interrupt
325
- });
326
- } else {
334
+ } catch (error) {
335
+ console.error("[LanggraphAgent] Error during stream processing:", error);
327
336
  subscriber.next({
328
- type: import_client.EventType.RUN_FINISHED,
329
- threadId,
330
- runId
337
+ type: import_client.EventType.RUN_ERROR,
338
+ message: error instanceof Error ? error.message : String(error)
331
339
  });
332
340
  }
333
341
  subscriber.complete();