@ai-sdk/langchain 3.0.0-beta.1 → 3.0.0-beta.100
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 +669 -0
- package/dist/index.js +50 -50
- package/dist/index.js.map +1 -1
- package/package.json +6 -8
- package/src/adapter.ts +14 -0
- package/src/transport.ts +3 -3
- package/src/utils.ts +15 -1
- package/dist/index.d.mts +0 -159
- package/dist/index.mjs +0 -1087
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,38 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
LangSmithDeploymentTransport: () => LangSmithDeploymentTransport,
|
|
24
|
-
convertModelMessages: () => convertModelMessages,
|
|
25
|
-
toBaseMessages: () => toBaseMessages,
|
|
26
|
-
toUIMessageStream: () => toUIMessageStream
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(src_exports);
|
|
29
|
-
|
|
30
1
|
// src/adapter.ts
|
|
31
|
-
|
|
32
|
-
|
|
2
|
+
import {
|
|
3
|
+
SystemMessage
|
|
4
|
+
} from "@langchain/core/messages";
|
|
5
|
+
import {
|
|
6
|
+
convertToModelMessages
|
|
7
|
+
} from "ai";
|
|
33
8
|
|
|
34
9
|
// src/utils.ts
|
|
35
|
-
|
|
10
|
+
import {
|
|
11
|
+
AIMessage,
|
|
12
|
+
HumanMessage,
|
|
13
|
+
ToolMessage,
|
|
14
|
+
AIMessageChunk
|
|
15
|
+
} from "@langchain/core/messages";
|
|
36
16
|
function parseLangGraphEvent(event) {
|
|
37
17
|
return event.length === 3 ? [event[1], event[2]] : [event[0], event[1]];
|
|
38
18
|
}
|
|
@@ -54,14 +34,14 @@ function convertToolResultPart(block) {
|
|
|
54
34
|
}
|
|
55
35
|
return "";
|
|
56
36
|
})();
|
|
57
|
-
return new
|
|
37
|
+
return new ToolMessage({
|
|
58
38
|
tool_call_id: block.toolCallId,
|
|
59
39
|
content
|
|
60
40
|
});
|
|
61
41
|
}
|
|
62
42
|
function convertAssistantContent(content) {
|
|
63
43
|
if (typeof content === "string") {
|
|
64
|
-
return new
|
|
44
|
+
return new AIMessage({ content });
|
|
65
45
|
}
|
|
66
46
|
const textParts = [];
|
|
67
47
|
const toolCalls = [];
|
|
@@ -76,7 +56,7 @@ function convertAssistantContent(content) {
|
|
|
76
56
|
});
|
|
77
57
|
}
|
|
78
58
|
}
|
|
79
|
-
return new
|
|
59
|
+
return new AIMessage({
|
|
80
60
|
content: textParts.join(""),
|
|
81
61
|
tool_calls: toolCalls.length > 0 ? toolCalls : void 0
|
|
82
62
|
});
|
|
@@ -88,7 +68,7 @@ function getDefaultFilename(mediaType, prefix = "file") {
|
|
|
88
68
|
function convertUserContent(content) {
|
|
89
69
|
var _a;
|
|
90
70
|
if (typeof content === "string") {
|
|
91
|
-
return new
|
|
71
|
+
return new HumanMessage({ content });
|
|
92
72
|
}
|
|
93
73
|
const contentBlocks = [];
|
|
94
74
|
for (const part of content) {
|
|
@@ -215,11 +195,11 @@ function convertUserContent(content) {
|
|
|
215
195
|
}
|
|
216
196
|
}
|
|
217
197
|
if (contentBlocks.every((block) => block.type === "text")) {
|
|
218
|
-
return new
|
|
198
|
+
return new HumanMessage({
|
|
219
199
|
content: contentBlocks.map((block) => block.text).join("")
|
|
220
200
|
});
|
|
221
201
|
}
|
|
222
|
-
return new
|
|
202
|
+
return new HumanMessage({ content: contentBlocks });
|
|
223
203
|
}
|
|
224
204
|
function isToolResultPart(item) {
|
|
225
205
|
return item != null && typeof item === "object" && "type" in item && item.type === "tool-result";
|
|
@@ -304,7 +284,7 @@ function getMessageId(msg) {
|
|
|
304
284
|
return void 0;
|
|
305
285
|
}
|
|
306
286
|
function isAIMessageChunk(msg) {
|
|
307
|
-
if (
|
|
287
|
+
if (AIMessageChunk.isInstance(msg)) return true;
|
|
308
288
|
if (isPlainMessageObject(msg)) {
|
|
309
289
|
const obj = msg;
|
|
310
290
|
if ("type" in obj && obj.type === "ai") return true;
|
|
@@ -315,7 +295,7 @@ function isAIMessageChunk(msg) {
|
|
|
315
295
|
return false;
|
|
316
296
|
}
|
|
317
297
|
function isToolMessageType(msg) {
|
|
318
|
-
if (
|
|
298
|
+
if (ToolMessage.isInstance(msg)) return true;
|
|
319
299
|
if (isPlainMessageObject(msg)) {
|
|
320
300
|
const obj = msg;
|
|
321
301
|
if ("type" in obj && obj.type === "tool") return true;
|
|
@@ -327,7 +307,7 @@ function isToolMessageType(msg) {
|
|
|
327
307
|
}
|
|
328
308
|
function getMessageText(msg) {
|
|
329
309
|
var _a;
|
|
330
|
-
if (
|
|
310
|
+
if (AIMessageChunk.isInstance(msg)) {
|
|
331
311
|
return (_a = msg.text) != null ? _a : "";
|
|
332
312
|
}
|
|
333
313
|
if (msg == null || typeof msg !== "object") return "";
|
|
@@ -495,12 +475,23 @@ function processLangGraphEvent(event, state, controller) {
|
|
|
495
475
|
const langgraphStep = typeof (metadata == null ? void 0 : metadata.langgraph_step) === "number" ? metadata.langgraph_step : null;
|
|
496
476
|
if (langgraphStep !== null && langgraphStep !== state.currentStep) {
|
|
497
477
|
if (state.currentStep !== null) {
|
|
478
|
+
for (const [id, seen] of Object.entries(messageSeen)) {
|
|
479
|
+
if (seen.text) {
|
|
480
|
+
controller.enqueue({ type: "text-end", id });
|
|
481
|
+
}
|
|
482
|
+
if (seen.reasoning) {
|
|
483
|
+
controller.enqueue({ type: "reasoning-end", id });
|
|
484
|
+
}
|
|
485
|
+
delete messageSeen[id];
|
|
486
|
+
delete messageConcat[id];
|
|
487
|
+
delete messageReasoningIds[id];
|
|
488
|
+
}
|
|
498
489
|
controller.enqueue({ type: "finish-step" });
|
|
499
490
|
}
|
|
500
491
|
controller.enqueue({ type: "start-step" });
|
|
501
492
|
state.currentStep = langgraphStep;
|
|
502
493
|
}
|
|
503
|
-
if (
|
|
494
|
+
if (AIMessageChunk.isInstance(msg)) {
|
|
504
495
|
if (messageConcat[msgId]) {
|
|
505
496
|
messageConcat[msgId] = messageConcat[msgId].concat(
|
|
506
497
|
msg
|
|
@@ -672,7 +663,7 @@ function processLangGraphEvent(event, state, controller) {
|
|
|
672
663
|
const msgId = getMessageId(msg);
|
|
673
664
|
if (!msgId) continue;
|
|
674
665
|
let toolCalls;
|
|
675
|
-
if (
|
|
666
|
+
if (AIMessageChunk.isInstance(msg) || AIMessage.isInstance(msg)) {
|
|
676
667
|
toolCalls = msg.tool_calls;
|
|
677
668
|
} else if (isPlainMessageObject(msg)) {
|
|
678
669
|
const obj = msg;
|
|
@@ -795,7 +786,7 @@ function processLangGraphEvent(event, state, controller) {
|
|
|
795
786
|
|
|
796
787
|
// src/adapter.ts
|
|
797
788
|
async function toBaseMessages(messages) {
|
|
798
|
-
const modelMessages = await
|
|
789
|
+
const modelMessages = await convertToModelMessages(messages);
|
|
799
790
|
return convertModelMessages(modelMessages);
|
|
800
791
|
}
|
|
801
792
|
function convertModelMessages(modelMessages) {
|
|
@@ -815,7 +806,7 @@ function convertModelMessages(modelMessages) {
|
|
|
815
806
|
break;
|
|
816
807
|
}
|
|
817
808
|
case "system": {
|
|
818
|
-
result.push(new
|
|
809
|
+
result.push(new SystemMessage({ content: message.content }));
|
|
819
810
|
break;
|
|
820
811
|
}
|
|
821
812
|
case "user": {
|
|
@@ -1046,6 +1037,14 @@ function toUIMessageStream(stream, callbacks) {
|
|
|
1046
1037
|
}
|
|
1047
1038
|
controller.enqueue({ type: "finish" });
|
|
1048
1039
|
} else if (streamType === "langgraph") {
|
|
1040
|
+
for (const [id, seen] of Object.entries(langGraphState.messageSeen)) {
|
|
1041
|
+
if (seen.text) {
|
|
1042
|
+
controller.enqueue({ type: "text-end", id });
|
|
1043
|
+
}
|
|
1044
|
+
if (seen.reasoning) {
|
|
1045
|
+
controller.enqueue({ type: "reasoning-end", id });
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1049
1048
|
if (langGraphState.currentStep !== null) {
|
|
1050
1049
|
controller.enqueue({ type: "finish-step" });
|
|
1051
1050
|
}
|
|
@@ -1073,11 +1072,13 @@ function toUIMessageStream(stream, callbacks) {
|
|
|
1073
1072
|
}
|
|
1074
1073
|
|
|
1075
1074
|
// src/transport.ts
|
|
1076
|
-
|
|
1075
|
+
import {
|
|
1076
|
+
RemoteGraph
|
|
1077
|
+
} from "@langchain/langgraph/remote";
|
|
1077
1078
|
var LangSmithDeploymentTransport = class {
|
|
1078
1079
|
constructor(options) {
|
|
1079
1080
|
var _a;
|
|
1080
|
-
this.graph = new
|
|
1081
|
+
this.graph = new RemoteGraph({
|
|
1081
1082
|
...options,
|
|
1082
1083
|
graphId: (_a = options.graphId) != null ? _a : "agent"
|
|
1083
1084
|
});
|
|
@@ -1096,11 +1097,10 @@ var LangSmithDeploymentTransport = class {
|
|
|
1096
1097
|
throw new Error("Method not implemented.");
|
|
1097
1098
|
}
|
|
1098
1099
|
};
|
|
1099
|
-
|
|
1100
|
-
0 && (module.exports = {
|
|
1100
|
+
export {
|
|
1101
1101
|
LangSmithDeploymentTransport,
|
|
1102
1102
|
convertModelMessages,
|
|
1103
1103
|
toBaseMessages,
|
|
1104
1104
|
toUIMessageStream
|
|
1105
|
-
}
|
|
1105
|
+
};
|
|
1106
1106
|
//# sourceMappingURL=index.js.map
|