@ai-sdk/langchain 3.0.0-beta.9 → 3.0.0-beta.91

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
@@ -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
- var import_messages2 = require("@langchain/core/messages");
32
- var import_ai = require("ai");
2
+ import {
3
+ SystemMessage
4
+ } from "@langchain/core/messages";
5
+ import {
6
+ convertToModelMessages
7
+ } from "ai";
33
8
 
34
9
  // src/utils.ts
35
- var import_messages = require("@langchain/core/messages");
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 import_messages.ToolMessage({
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 import_messages.AIMessage({ content });
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 import_messages.AIMessage({
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 import_messages.HumanMessage({ content });
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 import_messages.HumanMessage({
198
+ return new HumanMessage({
219
199
  content: contentBlocks.map((block) => block.text).join("")
220
200
  });
221
201
  }
222
- return new import_messages.HumanMessage({ content: contentBlocks });
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 (import_messages.AIMessageChunk.isInstance(msg)) return true;
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 (import_messages.ToolMessage.isInstance(msg)) return true;
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 (import_messages.AIMessageChunk.isInstance(msg)) {
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 (import_messages.AIMessageChunk.isInstance(msg)) {
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 (import_messages.AIMessageChunk.isInstance(msg) || import_messages.AIMessage.isInstance(msg)) {
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 (0, import_ai.convertToModelMessages)(messages);
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 import_messages2.SystemMessage({ content: message.content }));
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
- var import_remote = require("@langchain/langgraph/remote");
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 import_remote.RemoteGraph({
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
- // Annotate the CommonJS export names for ESM import in node:
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