@cloudbase/agent-adapter-langgraph 1.0.1-alpha.28 → 1.0.1-alpha.29
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 +44 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -139,7 +139,7 @@ var LanggraphAgent = class extends import_client.AbstractAgent {
|
|
|
139
139
|
"Preparing stream input"
|
|
140
140
|
);
|
|
141
141
|
logger.trace?.({ messages, tools: input.tools }, "Full input messages");
|
|
142
|
-
const langChainMessages = aguiMessagesToLangChain(messages);
|
|
142
|
+
const langChainMessages = aguiMessagesToLangChain(messages, logger);
|
|
143
143
|
logger.trace?.(
|
|
144
144
|
{
|
|
145
145
|
langChainMessages,
|
|
@@ -576,7 +576,7 @@ var LanggraphAgent = class extends import_client.AbstractAgent {
|
|
|
576
576
|
traceId: serverContextData.traceId,
|
|
577
577
|
spanId: serverContextData.spanId,
|
|
578
578
|
traceFlags: serverContextData.traceFlags,
|
|
579
|
-
isRemote:
|
|
579
|
+
isRemote: true
|
|
580
580
|
};
|
|
581
581
|
this.observabilityCallback.setExternalParentContext(serverSpanContext, {
|
|
582
582
|
threadId: input.threadId,
|
|
@@ -594,7 +594,7 @@ var LanggraphAgent = class extends import_client.AbstractAgent {
|
|
|
594
594
|
}
|
|
595
595
|
}
|
|
596
596
|
};
|
|
597
|
-
function aguiMessagesToLangChain(messages) {
|
|
597
|
+
function aguiMessagesToLangChain(messages, logger) {
|
|
598
598
|
return messages.map((message) => {
|
|
599
599
|
switch (message.role) {
|
|
600
600
|
case "user":
|
|
@@ -606,10 +606,34 @@ function aguiMessagesToLangChain(messages) {
|
|
|
606
606
|
type: "human"
|
|
607
607
|
};
|
|
608
608
|
} else {
|
|
609
|
+
const langChainContent = [];
|
|
610
|
+
for (const part of message.content) {
|
|
611
|
+
if (part.type === "text") {
|
|
612
|
+
langChainContent.push({ type: "text", text: part.text });
|
|
613
|
+
} else if (part.type === "binary") {
|
|
614
|
+
const imageUrl = convertBinaryToImageUrl(
|
|
615
|
+
part,
|
|
616
|
+
message.id,
|
|
617
|
+
logger
|
|
618
|
+
);
|
|
619
|
+
if (imageUrl) {
|
|
620
|
+
langChainContent.push({
|
|
621
|
+
type: "image_url",
|
|
622
|
+
image_url: { url: imageUrl }
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
if (langChainContent.length === 0) {
|
|
628
|
+
logger?.warn?.(
|
|
629
|
+
{ messageId: message.id },
|
|
630
|
+
"User message content array resulted in empty LangChain content"
|
|
631
|
+
);
|
|
632
|
+
}
|
|
609
633
|
return {
|
|
610
634
|
id: message.id,
|
|
611
635
|
role: message.role,
|
|
612
|
-
content:
|
|
636
|
+
content: langChainContent,
|
|
613
637
|
type: "human"
|
|
614
638
|
};
|
|
615
639
|
}
|
|
@@ -654,6 +678,22 @@ function isValidJson(json) {
|
|
|
654
678
|
return false;
|
|
655
679
|
}
|
|
656
680
|
}
|
|
681
|
+
function convertBinaryToImageUrl(part, messageId, logger) {
|
|
682
|
+
if (!part.mimeType.startsWith("image/")) {
|
|
683
|
+
logger?.debug?.(
|
|
684
|
+
{ mimeType: part.mimeType, messageId },
|
|
685
|
+
"Skipping non-image binary content"
|
|
686
|
+
);
|
|
687
|
+
return void 0;
|
|
688
|
+
}
|
|
689
|
+
if (part.url) {
|
|
690
|
+
return part.url;
|
|
691
|
+
}
|
|
692
|
+
if (part.data) {
|
|
693
|
+
return `data:${part.mimeType};base64,${part.data}`;
|
|
694
|
+
}
|
|
695
|
+
return void 0;
|
|
696
|
+
}
|
|
657
697
|
|
|
658
698
|
// src/checkpoint.ts
|
|
659
699
|
var import_langgraph2 = require("@langchain/langgraph");
|