@cloudbase/agent-adapter-langgraph 0.0.13 → 1.0.1-alpha.7

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.js CHANGED
@@ -34,9 +34,7 @@ __export(index_exports, {
34
34
  ClientStateAnnotation: () => ClientStateAnnotation,
35
35
  LanggraphAgent: () => LanggraphAgent,
36
36
  TDAISaver: () => TDAISaver,
37
- TDAIStore: () => TDAIStore,
38
- createConsoleLogger: () => import_agent_shared2.createConsoleLogger,
39
- noopLogger: () => import_agent_shared2.noopLogger
37
+ TDAIStore: () => TDAIStore
40
38
  });
41
39
  module.exports = __toCommonJS(index_exports);
42
40
 
@@ -93,7 +91,6 @@ function convertJsonSchemaToZodSchema(jsonSchema, required) {
93
91
  }
94
92
 
95
93
  // src/agent.ts
96
- var import_agent_shared = require("@cloudbase/agent-shared");
97
94
  var ClientPropertiesAnnotation = import_langgraph.Annotation.Root({
98
95
  tools: import_langgraph.Annotation
99
96
  });
@@ -105,8 +102,6 @@ var LanggraphAgent = class extends import_client.AbstractAgent {
105
102
  constructor(agentConfig) {
106
103
  super(agentConfig);
107
104
  this.compiledWorkflow = agentConfig.compiledWorkflow;
108
- const baseLogger = agentConfig.logger ?? import_agent_shared.noopLogger;
109
- this.logger = baseLogger.child?.({ component: "langgraph-agent" }) ?? baseLogger;
110
105
  }
111
106
  run(input) {
112
107
  return new import_rxjs.Observable((subscriber) => {
@@ -115,29 +110,12 @@ var LanggraphAgent = class extends import_client.AbstractAgent {
115
110
  }
116
111
  async _run(subscriber, input) {
117
112
  const { messages, runId, threadId } = input;
118
- const logger = this.logger.child?.({ runId, threadId }) ?? this.logger;
119
- logger.info?.("Run started");
120
- const runStartedEvent = {
113
+ subscriber.next({
121
114
  type: import_client.EventType.RUN_STARTED,
122
115
  threadId,
123
116
  runId
124
- };
125
- logger.trace?.({ aguiEvent: runStartedEvent }, "Emitting AGUI event");
126
- subscriber.next(runStartedEvent);
127
- const isResume = !!input.forwardedProps?.resume;
128
- const lastUserMessage = messages.filter((m) => m.role === "user").pop();
129
- logger.debug?.(
130
- {
131
- isResume,
132
- messageCount: messages.length,
133
- toolCount: input.tools?.length ?? 0,
134
- tools: input.tools?.map((t) => t.name),
135
- lastUserMessage: typeof lastUserMessage?.content === "string" ? lastUserMessage.content.slice(0, 200) : void 0
136
- },
137
- "Preparing stream input"
138
- );
139
- logger.trace?.({ messages, tools: input.tools }, "Full input messages");
140
- const streamEventInput = isResume ? new import_langgraph.Command({
117
+ });
118
+ const streamEventInput = input.forwardedProps?.resume ? new import_langgraph.Command({
141
119
  resume: JSON.stringify(input.forwardedProps?.resume?.payload)
142
120
  }) : {
143
121
  messages: aguiMessagesToLangChain(messages),
@@ -157,7 +135,6 @@ var LanggraphAgent = class extends import_client.AbstractAgent {
157
135
  thread_id: threadId
158
136
  }
159
137
  });
160
- logger.debug?.("Stream created, starting event processing");
161
138
  const chatModelRuns = [];
162
139
  const handledToolCallIds = /* @__PURE__ */ new Set();
163
140
  for (const msg of messages) {
@@ -165,32 +142,14 @@ var LanggraphAgent = class extends import_client.AbstractAgent {
165
142
  handledToolCallIds.add(msg.toolCallId);
166
143
  }
167
144
  }
168
- if (handledToolCallIds.size > 0) {
169
- logger.debug?.(
170
- { count: handledToolCallIds.size },
171
- "Pre-populated handled tool call IDs from input messages"
172
- );
173
- }
174
145
  let interrupt;
175
146
  let currentToolCall = null;
176
- let eventCount = 0;
177
- let toolCallCount = 0;
178
- let textChunkCount = 0;
179
147
  try {
180
148
  for await (const event of stream) {
181
- eventCount++;
182
- logger.trace?.(
183
- { eventType: event.event, eventCount, langGraphEvent: event },
184
- "Processing stream event"
185
- );
186
149
  if (event.event.startsWith("ChannelWrite<")) {
187
150
  continue;
188
151
  }
189
152
  if (event.event === "on_chat_model_start") {
190
- logger.debug?.(
191
- { chatModelRunId: event.run_id },
192
- "Chat model started"
193
- );
194
153
  chatModelRuns.push({ runId: event.run_id });
195
154
  continue;
196
155
  }
@@ -199,10 +158,6 @@ var LanggraphAgent = class extends import_client.AbstractAgent {
199
158
  (run) => run.runId === event.run_id
200
159
  );
201
160
  if (!chatModelRun) {
202
- logger.warn?.(
203
- { chatModelRunId: event.run_id },
204
- "Received message from unknown chat model run"
205
- );
206
161
  subscriber.next({
207
162
  type: import_client.EventType.RUN_ERROR,
208
163
  message: `Received a message from an unknown chat model run. Run Id: ${event.run_id}`
@@ -212,26 +167,12 @@ var LanggraphAgent = class extends import_client.AbstractAgent {
212
167
  const chunkId = event.data.chunk.id;
213
168
  if (!chatModelRun.messageId) {
214
169
  chatModelRun.messageId = chunkId;
215
- const textStartEvent = {
170
+ subscriber.next({
216
171
  messageId: chunkId,
217
172
  type: import_client.EventType.TEXT_MESSAGE_START,
218
173
  role: "assistant"
219
- };
220
- logger.debug?.({ messageId: chunkId }, "Text message started");
221
- logger.trace?.(
222
- { aguiEvent: textStartEvent },
223
- "Emitting AGUI event"
224
- );
225
- subscriber.next(textStartEvent);
174
+ });
226
175
  } else if (chatModelRun.messageId !== chunkId) {
227
- logger.warn?.(
228
- {
229
- expectedMessageId: chatModelRun.messageId,
230
- receivedMessageId: chunkId,
231
- chatModelRunId: event.run_id
232
- },
233
- "Received message with unexpected ID"
234
- );
235
176
  subscriber.next({
236
177
  type: import_client.EventType.RUN_ERROR,
237
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}`
@@ -246,68 +187,29 @@ var LanggraphAgent = class extends import_client.AbstractAgent {
246
187
  })).forEach((toolCall) => {
247
188
  if (currentToolCall) {
248
189
  if (toolCall.id && currentToolCall.id !== toolCall.id) {
249
- const toolEndEvent = {
190
+ subscriber.next({
250
191
  toolCallId: currentToolCall.id,
251
192
  type: import_client.EventType.TOOL_CALL_END
252
- };
253
- logger.debug?.(
254
- {
255
- toolCallId: currentToolCall.id,
256
- toolCallName: currentToolCall.name
257
- },
258
- "Tool call ended"
259
- );
260
- logger.trace?.(
261
- { aguiEvent: toolEndEvent },
262
- "Emitting AGUI event"
263
- );
264
- subscriber.next(toolEndEvent);
193
+ });
265
194
  if (toolCall.name && toolCall.id) {
266
195
  currentToolCall = toolCall;
267
- toolCallCount++;
268
- const toolStartEvent = {
196
+ subscriber.next({
269
197
  toolCallId: currentToolCall.id,
270
198
  toolCallName: currentToolCall.name,
271
199
  parentMessageId,
272
200
  type: import_client.EventType.TOOL_CALL_START
273
- };
274
- logger.debug?.(
275
- {
276
- toolCallId: toolCall.id,
277
- toolCallName: toolCall.name
278
- },
279
- "Tool call started"
280
- );
281
- logger.trace?.(
282
- { aguiEvent: toolStartEvent },
283
- "Emitting AGUI event"
284
- );
285
- subscriber.next(toolStartEvent);
201
+ });
286
202
  if (currentToolCall.args) {
287
- const toolArgsEvent = {
203
+ subscriber.next({
288
204
  toolCallId: currentToolCall.id,
289
205
  delta: currentToolCall.args,
290
206
  type: import_client.EventType.TOOL_CALL_ARGS
291
- };
292
- logger.trace?.(
293
- { aguiEvent: toolArgsEvent },
294
- "Emitting AGUI event"
295
- );
296
- subscriber.next(toolArgsEvent);
207
+ });
297
208
  if (isValidJson(currentToolCall.args)) {
298
- const toolEndEvent2 = {
209
+ subscriber.next({
299
210
  toolCallId: currentToolCall.id,
300
211
  type: import_client.EventType.TOOL_CALL_END
301
- };
302
- logger.debug?.(
303
- { toolCallId: currentToolCall.id },
304
- "Tool call ended (args complete)"
305
- );
306
- logger.trace?.(
307
- { aguiEvent: toolEndEvent2 },
308
- "Emitting AGUI event"
309
- );
310
- subscriber.next(toolEndEvent2);
212
+ });
311
213
  currentToolCall = null;
312
214
  }
313
215
  }
@@ -315,30 +217,16 @@ var LanggraphAgent = class extends import_client.AbstractAgent {
315
217
  } else {
316
218
  if (toolCall.args) {
317
219
  currentToolCall.args += toolCall.args;
318
- const toolArgsEvent = {
220
+ subscriber.next({
319
221
  toolCallId: currentToolCall.id,
320
222
  delta: toolCall.args,
321
223
  type: import_client.EventType.TOOL_CALL_ARGS
322
- };
323
- logger.trace?.(
324
- { aguiEvent: toolArgsEvent },
325
- "Emitting AGUI event"
326
- );
327
- subscriber.next(toolArgsEvent);
224
+ });
328
225
  if (isValidJson(currentToolCall.args)) {
329
- const toolEndEvent = {
226
+ subscriber.next({
330
227
  toolCallId: currentToolCall.id,
331
228
  type: import_client.EventType.TOOL_CALL_END
332
- };
333
- logger.debug?.(
334
- { toolCallId: currentToolCall.id },
335
- "Tool call ended (args complete)"
336
- );
337
- logger.trace?.(
338
- { aguiEvent: toolEndEvent },
339
- "Emitting AGUI event"
340
- );
341
- subscriber.next(toolEndEvent);
229
+ });
342
230
  currentToolCall = null;
343
231
  }
344
232
  }
@@ -346,47 +234,23 @@ var LanggraphAgent = class extends import_client.AbstractAgent {
346
234
  } else {
347
235
  if (toolCall.name && toolCall.id) {
348
236
  currentToolCall = toolCall;
349
- toolCallCount++;
350
- const toolStartEvent = {
237
+ subscriber.next({
351
238
  toolCallId: toolCall.id,
352
239
  toolCallName: toolCall.name,
353
240
  parentMessageId,
354
241
  type: import_client.EventType.TOOL_CALL_START
355
- };
356
- logger.debug?.(
357
- { toolCallId: toolCall.id, toolCallName: toolCall.name },
358
- "Tool call started"
359
- );
360
- logger.trace?.(
361
- { aguiEvent: toolStartEvent },
362
- "Emitting AGUI event"
363
- );
364
- subscriber.next(toolStartEvent);
242
+ });
365
243
  if (toolCall.args) {
366
- const toolArgsEvent = {
244
+ subscriber.next({
367
245
  toolCallId: toolCall.id,
368
246
  delta: toolCall.args,
369
247
  type: import_client.EventType.TOOL_CALL_ARGS
370
- };
371
- logger.trace?.(
372
- { aguiEvent: toolArgsEvent },
373
- "Emitting AGUI event"
374
- );
375
- subscriber.next(toolArgsEvent);
248
+ });
376
249
  if (isValidJson(toolCall.args)) {
377
- const toolEndEvent = {
250
+ subscriber.next({
378
251
  toolCallId: toolCall.id,
379
252
  type: import_client.EventType.TOOL_CALL_END
380
- };
381
- logger.debug?.(
382
- { toolCallId: toolCall.id },
383
- "Tool call ended (args complete)"
384
- );
385
- logger.trace?.(
386
- { aguiEvent: toolEndEvent },
387
- "Emitting AGUI event"
388
- );
389
- subscriber.next(toolEndEvent);
253
+ });
390
254
  currentToolCall = null;
391
255
  }
392
256
  }
@@ -396,17 +260,11 @@ var LanggraphAgent = class extends import_client.AbstractAgent {
396
260
  }
397
261
  const delta = event.data.chunk.content;
398
262
  if (typeof delta === "string" && delta) {
399
- textChunkCount++;
400
- const textContentEvent = {
263
+ subscriber.next({
401
264
  messageId: chatModelRun.messageId,
402
265
  type: import_client.EventType.TEXT_MESSAGE_CONTENT,
403
266
  delta
404
- };
405
- logger.trace?.(
406
- { aguiEvent: textContentEvent },
407
- "Emitting AGUI event"
408
- );
409
- subscriber.next(textContentEvent);
267
+ });
410
268
  }
411
269
  continue;
412
270
  }
@@ -415,26 +273,16 @@ var LanggraphAgent = class extends import_client.AbstractAgent {
415
273
  (run) => run.runId === event.run_id
416
274
  );
417
275
  if (!chatModelRun) {
418
- logger.warn?.(
419
- { chatModelRunId: event.run_id },
420
- "Received on_chat_model_end from unknown run"
421
- );
422
276
  subscriber.next({
423
277
  type: import_client.EventType.RUN_ERROR,
424
278
  message: `Received a on_chat_model_end event from an unknown chat model run. Run Id: ${event.run_id}`
425
279
  });
426
280
  continue;
427
281
  }
428
- const textEndEvent = {
282
+ subscriber.next({
429
283
  type: import_client.EventType.TEXT_MESSAGE_END,
430
284
  messageId: chatModelRun.messageId
431
- };
432
- logger.debug?.(
433
- { messageId: chatModelRun.messageId },
434
- "Text message ended"
435
- );
436
- logger.trace?.({ aguiEvent: textEndEvent }, "Emitting AGUI event");
437
- subscriber.next(textEndEvent);
285
+ });
438
286
  continue;
439
287
  }
440
288
  if (event.event === "on_tool_end") {
@@ -447,40 +295,19 @@ var LanggraphAgent = class extends import_client.AbstractAgent {
447
295
  toolMessage.lc_kwargs.id = toolMessage.id;
448
296
  }
449
297
  }
450
- const toolResultEvent = {
298
+ subscriber.next({
451
299
  toolCallId: toolMessage.tool_call_id,
452
300
  type: import_client.EventType.TOOL_CALL_RESULT,
453
301
  content: typeof toolMessage.content === "string" ? toolMessage.content : JSON.stringify(toolMessage.content),
454
302
  messageId: toolMessage.id
455
- };
456
- logger.debug?.(
457
- {
458
- toolCallId: toolMessage.tool_call_id,
459
- messageId: toolMessage.id
460
- },
461
- "Tool call result received"
462
- );
463
- logger.trace?.(
464
- { aguiEvent: toolResultEvent },
465
- "Emitting AGUI event"
466
- );
467
- subscriber.next(toolResultEvent);
303
+ });
468
304
  handledToolCallIds.add(toolMessage.tool_call_id);
469
- } else {
470
- logger.trace?.(
471
- { toolCallId: toolMessage.tool_call_id },
472
- "Skipping duplicate tool call result"
473
- );
474
305
  }
475
306
  }
476
307
  continue;
477
308
  }
478
309
  if (event.event === "on_chain_stream" && event.data.chunk?.__interrupt__ && Array.isArray(event.data.chunk.__interrupt__) && event.data.chunk.__interrupt__.length > 0) {
479
310
  const rawInterrupt = event.data.chunk.__interrupt__[0];
480
- logger.debug?.(
481
- { interruptId: rawInterrupt.id },
482
- "Interrupt received"
483
- );
484
311
  interrupt = {
485
312
  id: rawInterrupt.id,
486
313
  // TODO: replace with actual reason
@@ -489,36 +316,23 @@ var LanggraphAgent = class extends import_client.AbstractAgent {
489
316
  };
490
317
  }
491
318
  }
492
- const stats = { eventCount, toolCallCount, textChunkCount };
493
319
  if (interrupt) {
494
- const runFinishedEvent = {
320
+ subscriber.next({
495
321
  type: import_client.EventType.RUN_FINISHED,
496
322
  threadId,
497
323
  runId,
498
324
  outcome: "interrupt",
499
325
  interrupt
500
- };
501
- logger.info?.(
502
- { outcome: "interrupt", interruptId: interrupt.id, ...stats },
503
- "Run finished with interrupt"
504
- );
505
- logger.trace?.({ aguiEvent: runFinishedEvent }, "Emitting AGUI event");
506
- subscriber.next(runFinishedEvent);
326
+ });
507
327
  } else {
508
- const runFinishedEvent = {
328
+ subscriber.next({
509
329
  type: import_client.EventType.RUN_FINISHED,
510
330
  threadId,
511
331
  runId
512
- };
513
- logger.info?.({ outcome: "complete", ...stats }, "Run finished");
514
- logger.trace?.({ aguiEvent: runFinishedEvent }, "Emitting AGUI event");
515
- subscriber.next(runFinishedEvent);
332
+ });
516
333
  }
517
334
  } catch (error) {
518
- logger.error?.(
519
- { err: error, eventCount, toolCallCount, textChunkCount },
520
- "Error during stream processing"
521
- );
335
+ console.error("[LanggraphAgent] Error during stream processing:", error);
522
336
  subscriber.next({
523
337
  type: import_client.EventType.RUN_ERROR,
524
338
  message: error instanceof Error ? error.message : String(error)
@@ -528,12 +342,10 @@ var LanggraphAgent = class extends import_client.AbstractAgent {
528
342
  }
529
343
  clone() {
530
344
  const workflow = this.compiledWorkflow;
531
- const logger = this.logger;
532
345
  this.compiledWorkflow = void 0;
533
346
  const cloned = super.clone();
534
347
  this.compiledWorkflow = workflow;
535
348
  cloned.compiledWorkflow = workflow;
536
- cloned.logger = logger;
537
349
  return cloned;
538
350
  }
539
351
  };
@@ -585,7 +397,8 @@ function aguiMessagesToLangChain(messages) {
585
397
  id: message.id
586
398
  };
587
399
  default:
588
- throw new Error(`Message role ${message.role} is not supported.`);
400
+ console.error(`Message role ${message.role} is not implemented`);
401
+ throw new Error("message role is not supported.");
589
402
  }
590
403
  });
591
404
  }
@@ -1273,17 +1086,12 @@ var TDAIStore = class extends import_langgraph3.BaseStore {
1273
1086
  }
1274
1087
  }
1275
1088
  };
1276
-
1277
- // src/index.ts
1278
- var import_agent_shared2 = require("@cloudbase/agent-shared");
1279
1089
  // Annotate the CommonJS export names for ESM import in node:
1280
1090
  0 && (module.exports = {
1281
1091
  ClientPropertiesAnnotation,
1282
1092
  ClientStateAnnotation,
1283
1093
  LanggraphAgent,
1284
1094
  TDAISaver,
1285
- TDAIStore,
1286
- createConsoleLogger,
1287
- noopLogger
1095
+ TDAIStore
1288
1096
  });
1289
1097
  //# sourceMappingURL=index.js.map