@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.mjs CHANGED
@@ -58,7 +58,6 @@ function convertJsonSchemaToZodSchema(jsonSchema, required) {
58
58
  }
59
59
 
60
60
  // src/agent.ts
61
- import { noopLogger } from "@cloudbase/agent-shared";
62
61
  var ClientPropertiesAnnotation = Annotation.Root({
63
62
  tools: Annotation
64
63
  });
@@ -70,8 +69,6 @@ var LanggraphAgent = class extends AbstractAgent {
70
69
  constructor(agentConfig) {
71
70
  super(agentConfig);
72
71
  this.compiledWorkflow = agentConfig.compiledWorkflow;
73
- const baseLogger = agentConfig.logger ?? noopLogger;
74
- this.logger = baseLogger.child?.({ component: "langgraph-agent" }) ?? baseLogger;
75
72
  }
76
73
  run(input) {
77
74
  return new Observable((subscriber) => {
@@ -80,29 +77,12 @@ var LanggraphAgent = class extends AbstractAgent {
80
77
  }
81
78
  async _run(subscriber, input) {
82
79
  const { messages, runId, threadId } = input;
83
- const logger = this.logger.child?.({ runId, threadId }) ?? this.logger;
84
- logger.info?.("Run started");
85
- const runStartedEvent = {
80
+ subscriber.next({
86
81
  type: EventType.RUN_STARTED,
87
82
  threadId,
88
83
  runId
89
- };
90
- logger.trace?.({ aguiEvent: runStartedEvent }, "Emitting AGUI event");
91
- subscriber.next(runStartedEvent);
92
- const isResume = !!input.forwardedProps?.resume;
93
- const lastUserMessage = messages.filter((m) => m.role === "user").pop();
94
- logger.debug?.(
95
- {
96
- isResume,
97
- messageCount: messages.length,
98
- toolCount: input.tools?.length ?? 0,
99
- tools: input.tools?.map((t) => t.name),
100
- lastUserMessage: typeof lastUserMessage?.content === "string" ? lastUserMessage.content.slice(0, 200) : void 0
101
- },
102
- "Preparing stream input"
103
- );
104
- logger.trace?.({ messages, tools: input.tools }, "Full input messages");
105
- const streamEventInput = isResume ? new Command({
84
+ });
85
+ const streamEventInput = input.forwardedProps?.resume ? new Command({
106
86
  resume: JSON.stringify(input.forwardedProps?.resume?.payload)
107
87
  }) : {
108
88
  messages: aguiMessagesToLangChain(messages),
@@ -122,7 +102,6 @@ var LanggraphAgent = class extends AbstractAgent {
122
102
  thread_id: threadId
123
103
  }
124
104
  });
125
- logger.debug?.("Stream created, starting event processing");
126
105
  const chatModelRuns = [];
127
106
  const handledToolCallIds = /* @__PURE__ */ new Set();
128
107
  for (const msg of messages) {
@@ -130,32 +109,14 @@ var LanggraphAgent = class extends AbstractAgent {
130
109
  handledToolCallIds.add(msg.toolCallId);
131
110
  }
132
111
  }
133
- if (handledToolCallIds.size > 0) {
134
- logger.debug?.(
135
- { count: handledToolCallIds.size },
136
- "Pre-populated handled tool call IDs from input messages"
137
- );
138
- }
139
112
  let interrupt;
140
113
  let currentToolCall = null;
141
- let eventCount = 0;
142
- let toolCallCount = 0;
143
- let textChunkCount = 0;
144
114
  try {
145
115
  for await (const event of stream) {
146
- eventCount++;
147
- logger.trace?.(
148
- { eventType: event.event, eventCount, langGraphEvent: event },
149
- "Processing stream event"
150
- );
151
116
  if (event.event.startsWith("ChannelWrite<")) {
152
117
  continue;
153
118
  }
154
119
  if (event.event === "on_chat_model_start") {
155
- logger.debug?.(
156
- { chatModelRunId: event.run_id },
157
- "Chat model started"
158
- );
159
120
  chatModelRuns.push({ runId: event.run_id });
160
121
  continue;
161
122
  }
@@ -164,10 +125,6 @@ var LanggraphAgent = class extends AbstractAgent {
164
125
  (run) => run.runId === event.run_id
165
126
  );
166
127
  if (!chatModelRun) {
167
- logger.warn?.(
168
- { chatModelRunId: event.run_id },
169
- "Received message from unknown chat model run"
170
- );
171
128
  subscriber.next({
172
129
  type: EventType.RUN_ERROR,
173
130
  message: `Received a message from an unknown chat model run. Run Id: ${event.run_id}`
@@ -177,26 +134,12 @@ var LanggraphAgent = class extends AbstractAgent {
177
134
  const chunkId = event.data.chunk.id;
178
135
  if (!chatModelRun.messageId) {
179
136
  chatModelRun.messageId = chunkId;
180
- const textStartEvent = {
137
+ subscriber.next({
181
138
  messageId: chunkId,
182
139
  type: EventType.TEXT_MESSAGE_START,
183
140
  role: "assistant"
184
- };
185
- logger.debug?.({ messageId: chunkId }, "Text message started");
186
- logger.trace?.(
187
- { aguiEvent: textStartEvent },
188
- "Emitting AGUI event"
189
- );
190
- subscriber.next(textStartEvent);
141
+ });
191
142
  } else if (chatModelRun.messageId !== chunkId) {
192
- logger.warn?.(
193
- {
194
- expectedMessageId: chatModelRun.messageId,
195
- receivedMessageId: chunkId,
196
- chatModelRunId: event.run_id
197
- },
198
- "Received message with unexpected ID"
199
- );
200
143
  subscriber.next({
201
144
  type: EventType.RUN_ERROR,
202
145
  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}`
@@ -211,68 +154,29 @@ var LanggraphAgent = class extends AbstractAgent {
211
154
  })).forEach((toolCall) => {
212
155
  if (currentToolCall) {
213
156
  if (toolCall.id && currentToolCall.id !== toolCall.id) {
214
- const toolEndEvent = {
157
+ subscriber.next({
215
158
  toolCallId: currentToolCall.id,
216
159
  type: EventType.TOOL_CALL_END
217
- };
218
- logger.debug?.(
219
- {
220
- toolCallId: currentToolCall.id,
221
- toolCallName: currentToolCall.name
222
- },
223
- "Tool call ended"
224
- );
225
- logger.trace?.(
226
- { aguiEvent: toolEndEvent },
227
- "Emitting AGUI event"
228
- );
229
- subscriber.next(toolEndEvent);
160
+ });
230
161
  if (toolCall.name && toolCall.id) {
231
162
  currentToolCall = toolCall;
232
- toolCallCount++;
233
- const toolStartEvent = {
163
+ subscriber.next({
234
164
  toolCallId: currentToolCall.id,
235
165
  toolCallName: currentToolCall.name,
236
166
  parentMessageId,
237
167
  type: EventType.TOOL_CALL_START
238
- };
239
- logger.debug?.(
240
- {
241
- toolCallId: toolCall.id,
242
- toolCallName: toolCall.name
243
- },
244
- "Tool call started"
245
- );
246
- logger.trace?.(
247
- { aguiEvent: toolStartEvent },
248
- "Emitting AGUI event"
249
- );
250
- subscriber.next(toolStartEvent);
168
+ });
251
169
  if (currentToolCall.args) {
252
- const toolArgsEvent = {
170
+ subscriber.next({
253
171
  toolCallId: currentToolCall.id,
254
172
  delta: currentToolCall.args,
255
173
  type: EventType.TOOL_CALL_ARGS
256
- };
257
- logger.trace?.(
258
- { aguiEvent: toolArgsEvent },
259
- "Emitting AGUI event"
260
- );
261
- subscriber.next(toolArgsEvent);
174
+ });
262
175
  if (isValidJson(currentToolCall.args)) {
263
- const toolEndEvent2 = {
176
+ subscriber.next({
264
177
  toolCallId: currentToolCall.id,
265
178
  type: EventType.TOOL_CALL_END
266
- };
267
- logger.debug?.(
268
- { toolCallId: currentToolCall.id },
269
- "Tool call ended (args complete)"
270
- );
271
- logger.trace?.(
272
- { aguiEvent: toolEndEvent2 },
273
- "Emitting AGUI event"
274
- );
275
- subscriber.next(toolEndEvent2);
179
+ });
276
180
  currentToolCall = null;
277
181
  }
278
182
  }
@@ -280,30 +184,16 @@ var LanggraphAgent = class extends AbstractAgent {
280
184
  } else {
281
185
  if (toolCall.args) {
282
186
  currentToolCall.args += toolCall.args;
283
- const toolArgsEvent = {
187
+ subscriber.next({
284
188
  toolCallId: currentToolCall.id,
285
189
  delta: toolCall.args,
286
190
  type: EventType.TOOL_CALL_ARGS
287
- };
288
- logger.trace?.(
289
- { aguiEvent: toolArgsEvent },
290
- "Emitting AGUI event"
291
- );
292
- subscriber.next(toolArgsEvent);
191
+ });
293
192
  if (isValidJson(currentToolCall.args)) {
294
- const toolEndEvent = {
193
+ subscriber.next({
295
194
  toolCallId: currentToolCall.id,
296
195
  type: EventType.TOOL_CALL_END
297
- };
298
- logger.debug?.(
299
- { toolCallId: currentToolCall.id },
300
- "Tool call ended (args complete)"
301
- );
302
- logger.trace?.(
303
- { aguiEvent: toolEndEvent },
304
- "Emitting AGUI event"
305
- );
306
- subscriber.next(toolEndEvent);
196
+ });
307
197
  currentToolCall = null;
308
198
  }
309
199
  }
@@ -311,47 +201,23 @@ var LanggraphAgent = class extends AbstractAgent {
311
201
  } else {
312
202
  if (toolCall.name && toolCall.id) {
313
203
  currentToolCall = toolCall;
314
- toolCallCount++;
315
- const toolStartEvent = {
204
+ subscriber.next({
316
205
  toolCallId: toolCall.id,
317
206
  toolCallName: toolCall.name,
318
207
  parentMessageId,
319
208
  type: EventType.TOOL_CALL_START
320
- };
321
- logger.debug?.(
322
- { toolCallId: toolCall.id, toolCallName: toolCall.name },
323
- "Tool call started"
324
- );
325
- logger.trace?.(
326
- { aguiEvent: toolStartEvent },
327
- "Emitting AGUI event"
328
- );
329
- subscriber.next(toolStartEvent);
209
+ });
330
210
  if (toolCall.args) {
331
- const toolArgsEvent = {
211
+ subscriber.next({
332
212
  toolCallId: toolCall.id,
333
213
  delta: toolCall.args,
334
214
  type: EventType.TOOL_CALL_ARGS
335
- };
336
- logger.trace?.(
337
- { aguiEvent: toolArgsEvent },
338
- "Emitting AGUI event"
339
- );
340
- subscriber.next(toolArgsEvent);
215
+ });
341
216
  if (isValidJson(toolCall.args)) {
342
- const toolEndEvent = {
217
+ subscriber.next({
343
218
  toolCallId: toolCall.id,
344
219
  type: EventType.TOOL_CALL_END
345
- };
346
- logger.debug?.(
347
- { toolCallId: toolCall.id },
348
- "Tool call ended (args complete)"
349
- );
350
- logger.trace?.(
351
- { aguiEvent: toolEndEvent },
352
- "Emitting AGUI event"
353
- );
354
- subscriber.next(toolEndEvent);
220
+ });
355
221
  currentToolCall = null;
356
222
  }
357
223
  }
@@ -361,17 +227,11 @@ var LanggraphAgent = class extends AbstractAgent {
361
227
  }
362
228
  const delta = event.data.chunk.content;
363
229
  if (typeof delta === "string" && delta) {
364
- textChunkCount++;
365
- const textContentEvent = {
230
+ subscriber.next({
366
231
  messageId: chatModelRun.messageId,
367
232
  type: EventType.TEXT_MESSAGE_CONTENT,
368
233
  delta
369
- };
370
- logger.trace?.(
371
- { aguiEvent: textContentEvent },
372
- "Emitting AGUI event"
373
- );
374
- subscriber.next(textContentEvent);
234
+ });
375
235
  }
376
236
  continue;
377
237
  }
@@ -380,26 +240,16 @@ var LanggraphAgent = class extends AbstractAgent {
380
240
  (run) => run.runId === event.run_id
381
241
  );
382
242
  if (!chatModelRun) {
383
- logger.warn?.(
384
- { chatModelRunId: event.run_id },
385
- "Received on_chat_model_end from unknown run"
386
- );
387
243
  subscriber.next({
388
244
  type: EventType.RUN_ERROR,
389
245
  message: `Received a on_chat_model_end event from an unknown chat model run. Run Id: ${event.run_id}`
390
246
  });
391
247
  continue;
392
248
  }
393
- const textEndEvent = {
249
+ subscriber.next({
394
250
  type: EventType.TEXT_MESSAGE_END,
395
251
  messageId: chatModelRun.messageId
396
- };
397
- logger.debug?.(
398
- { messageId: chatModelRun.messageId },
399
- "Text message ended"
400
- );
401
- logger.trace?.({ aguiEvent: textEndEvent }, "Emitting AGUI event");
402
- subscriber.next(textEndEvent);
252
+ });
403
253
  continue;
404
254
  }
405
255
  if (event.event === "on_tool_end") {
@@ -412,40 +262,19 @@ var LanggraphAgent = class extends AbstractAgent {
412
262
  toolMessage.lc_kwargs.id = toolMessage.id;
413
263
  }
414
264
  }
415
- const toolResultEvent = {
265
+ subscriber.next({
416
266
  toolCallId: toolMessage.tool_call_id,
417
267
  type: EventType.TOOL_CALL_RESULT,
418
268
  content: typeof toolMessage.content === "string" ? toolMessage.content : JSON.stringify(toolMessage.content),
419
269
  messageId: toolMessage.id
420
- };
421
- logger.debug?.(
422
- {
423
- toolCallId: toolMessage.tool_call_id,
424
- messageId: toolMessage.id
425
- },
426
- "Tool call result received"
427
- );
428
- logger.trace?.(
429
- { aguiEvent: toolResultEvent },
430
- "Emitting AGUI event"
431
- );
432
- subscriber.next(toolResultEvent);
270
+ });
433
271
  handledToolCallIds.add(toolMessage.tool_call_id);
434
- } else {
435
- logger.trace?.(
436
- { toolCallId: toolMessage.tool_call_id },
437
- "Skipping duplicate tool call result"
438
- );
439
272
  }
440
273
  }
441
274
  continue;
442
275
  }
443
276
  if (event.event === "on_chain_stream" && event.data.chunk?.__interrupt__ && Array.isArray(event.data.chunk.__interrupt__) && event.data.chunk.__interrupt__.length > 0) {
444
277
  const rawInterrupt = event.data.chunk.__interrupt__[0];
445
- logger.debug?.(
446
- { interruptId: rawInterrupt.id },
447
- "Interrupt received"
448
- );
449
278
  interrupt = {
450
279
  id: rawInterrupt.id,
451
280
  // TODO: replace with actual reason
@@ -454,36 +283,23 @@ var LanggraphAgent = class extends AbstractAgent {
454
283
  };
455
284
  }
456
285
  }
457
- const stats = { eventCount, toolCallCount, textChunkCount };
458
286
  if (interrupt) {
459
- const runFinishedEvent = {
287
+ subscriber.next({
460
288
  type: EventType.RUN_FINISHED,
461
289
  threadId,
462
290
  runId,
463
291
  outcome: "interrupt",
464
292
  interrupt
465
- };
466
- logger.info?.(
467
- { outcome: "interrupt", interruptId: interrupt.id, ...stats },
468
- "Run finished with interrupt"
469
- );
470
- logger.trace?.({ aguiEvent: runFinishedEvent }, "Emitting AGUI event");
471
- subscriber.next(runFinishedEvent);
293
+ });
472
294
  } else {
473
- const runFinishedEvent = {
295
+ subscriber.next({
474
296
  type: EventType.RUN_FINISHED,
475
297
  threadId,
476
298
  runId
477
- };
478
- logger.info?.({ outcome: "complete", ...stats }, "Run finished");
479
- logger.trace?.({ aguiEvent: runFinishedEvent }, "Emitting AGUI event");
480
- subscriber.next(runFinishedEvent);
299
+ });
481
300
  }
482
301
  } catch (error) {
483
- logger.error?.(
484
- { err: error, eventCount, toolCallCount, textChunkCount },
485
- "Error during stream processing"
486
- );
302
+ console.error("[LanggraphAgent] Error during stream processing:", error);
487
303
  subscriber.next({
488
304
  type: EventType.RUN_ERROR,
489
305
  message: error instanceof Error ? error.message : String(error)
@@ -493,12 +309,10 @@ var LanggraphAgent = class extends AbstractAgent {
493
309
  }
494
310
  clone() {
495
311
  const workflow = this.compiledWorkflow;
496
- const logger = this.logger;
497
312
  this.compiledWorkflow = void 0;
498
313
  const cloned = super.clone();
499
314
  this.compiledWorkflow = workflow;
500
315
  cloned.compiledWorkflow = workflow;
501
- cloned.logger = logger;
502
316
  return cloned;
503
317
  }
504
318
  };
@@ -550,7 +364,8 @@ function aguiMessagesToLangChain(messages) {
550
364
  id: message.id
551
365
  };
552
366
  default:
553
- throw new Error(`Message role ${message.role} is not supported.`);
367
+ console.error(`Message role ${message.role} is not implemented`);
368
+ throw new Error("message role is not supported.");
554
369
  }
555
370
  });
556
371
  }
@@ -1245,16 +1060,11 @@ var TDAIStore = class extends BaseStore {
1245
1060
  }
1246
1061
  }
1247
1062
  };
1248
-
1249
- // src/index.ts
1250
- import { noopLogger as noopLogger2, createConsoleLogger } from "@cloudbase/agent-shared";
1251
1063
  export {
1252
1064
  ClientPropertiesAnnotation,
1253
1065
  ClientStateAnnotation,
1254
1066
  LanggraphAgent,
1255
1067
  TDAISaver,
1256
- TDAIStore,
1257
- createConsoleLogger,
1258
- noopLogger2 as noopLogger
1068
+ TDAIStore
1259
1069
  };
1260
1070
  //# sourceMappingURL=index.mjs.map