@cloudbase/agent-adapter-langgraph 0.0.9 → 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 +12 -0
- package/dist/index.js +149 -146
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +149 -146
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
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,37 +144,82 @@ var LanggraphAgent = class extends import_client.AbstractAgent {
|
|
|
144
144
|
}
|
|
145
145
|
let interrupt;
|
|
146
146
|
let currentToolCall = null;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
147
|
+
try {
|
|
148
|
+
for await (const event of stream) {
|
|
149
|
+
if (event.event.startsWith("ChannelWrite<")) {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (event.event === "on_chat_model_start") {
|
|
153
|
+
chatModelRuns.push({ runId: event.run_id });
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
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) {
|
|
169
190
|
subscriber.next({
|
|
170
191
|
toolCallId: currentToolCall.id,
|
|
171
|
-
|
|
172
|
-
type: import_client.EventType.TOOL_CALL_START
|
|
192
|
+
type: import_client.EventType.TOOL_CALL_END
|
|
173
193
|
});
|
|
174
|
-
if (
|
|
194
|
+
if (toolCall.name && toolCall.id) {
|
|
195
|
+
currentToolCall = toolCall;
|
|
175
196
|
subscriber.next({
|
|
176
197
|
toolCallId: currentToolCall.id,
|
|
177
|
-
|
|
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,
|
|
178
223
|
type: import_client.EventType.TOOL_CALL_ARGS
|
|
179
224
|
});
|
|
180
225
|
if (isValidJson(currentToolCall.args)) {
|
|
@@ -187,152 +232,110 @@ var LanggraphAgent = class extends import_client.AbstractAgent {
|
|
|
187
232
|
}
|
|
188
233
|
}
|
|
189
234
|
} else {
|
|
190
|
-
if (toolCall.
|
|
191
|
-
currentToolCall
|
|
192
|
-
subscriber.next({
|
|
193
|
-
toolCallId: currentToolCall.id,
|
|
194
|
-
delta: toolCall.args,
|
|
195
|
-
type: import_client.EventType.TOOL_CALL_ARGS
|
|
196
|
-
});
|
|
197
|
-
if (isValidJson(currentToolCall.args)) {
|
|
198
|
-
subscriber.next({
|
|
199
|
-
toolCallId: currentToolCall.id,
|
|
200
|
-
type: import_client.EventType.TOOL_CALL_END
|
|
201
|
-
});
|
|
202
|
-
currentToolCall = null;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
} else {
|
|
207
|
-
if (toolCall.name && toolCall.id) {
|
|
208
|
-
currentToolCall = toolCall;
|
|
209
|
-
subscriber.next({
|
|
210
|
-
toolCallId: toolCall.id,
|
|
211
|
-
toolCallName: toolCall.name,
|
|
212
|
-
type: import_client.EventType.TOOL_CALL_START
|
|
213
|
-
});
|
|
214
|
-
if (toolCall.args) {
|
|
235
|
+
if (toolCall.name && toolCall.id) {
|
|
236
|
+
currentToolCall = toolCall;
|
|
215
237
|
subscriber.next({
|
|
216
238
|
toolCallId: toolCall.id,
|
|
217
|
-
|
|
218
|
-
|
|
239
|
+
toolCallName: toolCall.name,
|
|
240
|
+
parentMessageId,
|
|
241
|
+
type: import_client.EventType.TOOL_CALL_START
|
|
219
242
|
});
|
|
220
|
-
if (
|
|
243
|
+
if (toolCall.args) {
|
|
221
244
|
subscriber.next({
|
|
222
245
|
toolCallId: toolCall.id,
|
|
223
|
-
|
|
246
|
+
delta: toolCall.args,
|
|
247
|
+
type: import_client.EventType.TOOL_CALL_ARGS
|
|
224
248
|
});
|
|
225
|
-
|
|
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
|
+
}
|
|
226
256
|
}
|
|
227
257
|
}
|
|
228
258
|
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
const chatModelRun = chatModelRuns.find(
|
|
233
|
-
(run) => run.runId === event.run_id
|
|
234
|
-
);
|
|
235
|
-
if (!chatModelRun) {
|
|
236
|
-
subscriber.next({
|
|
237
|
-
type: import_client.EventType.RUN_ERROR,
|
|
238
|
-
message: `Received a message from an unknown chat model run. Run Id: ${event.run_id}`
|
|
239
|
-
});
|
|
240
|
-
continue;
|
|
241
|
-
}
|
|
242
|
-
if (!chatModelRun.messageId) {
|
|
243
|
-
const messageId = event.data.chunk.id;
|
|
244
|
-
chatModelRun.messageId = messageId;
|
|
245
|
-
subscriber.next({
|
|
246
|
-
messageId,
|
|
247
|
-
type: import_client.EventType.TEXT_MESSAGE_START,
|
|
248
|
-
role: "assistant"
|
|
249
|
-
});
|
|
259
|
+
});
|
|
260
|
+
}
|
|
250
261
|
const delta = event.data.chunk.content;
|
|
251
|
-
typeof delta === "string" && delta
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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
|
+
}
|
|
256
269
|
continue;
|
|
257
|
-
}
|
|
258
|
-
|
|
270
|
+
}
|
|
271
|
+
if (event.event === "on_chat_model_end") {
|
|
272
|
+
const chatModelRun = chatModelRuns.find(
|
|
273
|
+
(run) => run.runId === event.run_id
|
|
274
|
+
);
|
|
275
|
+
if (!chatModelRun) {
|
|
259
276
|
subscriber.next({
|
|
260
277
|
type: import_client.EventType.RUN_ERROR,
|
|
261
|
-
message: `Received a
|
|
278
|
+
message: `Received a on_chat_model_end event from an unknown chat model run. Run Id: ${event.run_id}`
|
|
262
279
|
});
|
|
263
280
|
continue;
|
|
264
281
|
}
|
|
265
|
-
const delta = event.data.chunk.content;
|
|
266
|
-
typeof delta === "string" && delta && subscriber.next({
|
|
267
|
-
messageId: chatModelRun.messageId,
|
|
268
|
-
type: import_client.EventType.TEXT_MESSAGE_CONTENT,
|
|
269
|
-
delta
|
|
270
|
-
});
|
|
271
|
-
continue;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
if (event.event === "on_chat_model_end") {
|
|
275
|
-
const chatModelRun = chatModelRuns.find(
|
|
276
|
-
(run) => run.runId === event.run_id
|
|
277
|
-
);
|
|
278
|
-
if (!chatModelRun) {
|
|
279
282
|
subscriber.next({
|
|
280
|
-
type: import_client.EventType.
|
|
281
|
-
|
|
283
|
+
type: import_client.EventType.TEXT_MESSAGE_END,
|
|
284
|
+
messageId: chatModelRun.messageId
|
|
282
285
|
});
|
|
283
286
|
continue;
|
|
284
287
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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
|
+
}
|
|
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);
|
|
301
305
|
}
|
|
302
|
-
|
|
303
|
-
toolCallId: x.tool_call_id,
|
|
304
|
-
type: import_client.EventType.TOOL_CALL_RESULT,
|
|
305
|
-
content: x.content,
|
|
306
|
-
messageId
|
|
307
|
-
});
|
|
308
|
-
handledToolCallIds.add(x.tool_call_id);
|
|
309
|
-
});
|
|
306
|
+
}
|
|
310
307
|
continue;
|
|
311
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
|
+
};
|
|
317
|
+
}
|
|
312
318
|
}
|
|
313
|
-
if (
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
};
|
|
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
|
+
});
|
|
321
333
|
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
subscriber.next({
|
|
325
|
-
type: import_client.EventType.RUN_FINISHED,
|
|
326
|
-
threadId,
|
|
327
|
-
runId,
|
|
328
|
-
outcome: "interrupt",
|
|
329
|
-
interrupt
|
|
330
|
-
});
|
|
331
|
-
} else {
|
|
334
|
+
} catch (error) {
|
|
335
|
+
console.error("[LanggraphAgent] Error during stream processing:", error);
|
|
332
336
|
subscriber.next({
|
|
333
|
-
type: import_client.EventType.
|
|
334
|
-
|
|
335
|
-
runId
|
|
337
|
+
type: import_client.EventType.RUN_ERROR,
|
|
338
|
+
message: error instanceof Error ? error.message : String(error)
|
|
336
339
|
});
|
|
337
340
|
}
|
|
338
341
|
subscriber.complete();
|