@ai-sdk/langchain 2.0.300 → 2.0.302
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 +15 -0
- package/dist/index.js +38 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/adapter.ts +1 -0
- package/src/types.ts +2 -0
- package/src/utils.ts +69 -3
package/dist/index.mjs
CHANGED
|
@@ -616,6 +616,16 @@ function markToolCallEmitted(state, toolCallId, namespace) {
|
|
|
616
616
|
).add(toolCallId);
|
|
617
617
|
}
|
|
618
618
|
}
|
|
619
|
+
function markToolCallStarted(state, toolCallId, namespace) {
|
|
620
|
+
markToolCallEmitted(state, toolCallId, namespace);
|
|
621
|
+
getOrCreateNamespaceSet(state.unfinishedToolCallsByNamespace, namespace).add(
|
|
622
|
+
toolCallId
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
function hasUnfinishedToolCall(state, toolCallId, namespace) {
|
|
626
|
+
var _a;
|
|
627
|
+
return ((_a = state.unfinishedToolCallsByNamespace.get(namespace)) == null ? void 0 : _a.has(toolCallId)) === true;
|
|
628
|
+
}
|
|
619
629
|
function findMessageCurrentStepNamespace(state, messageId) {
|
|
620
630
|
for (const [
|
|
621
631
|
namespace,
|
|
@@ -653,7 +663,7 @@ function closeStepNamespaceMessages(state, stepNamespace, controller) {
|
|
|
653
663
|
return hasConcurrentMessageParts;
|
|
654
664
|
}
|
|
655
665
|
function processLangGraphEvent(event, state, controller) {
|
|
656
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
666
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
657
667
|
const {
|
|
658
668
|
messageSeen,
|
|
659
669
|
messageConcat,
|
|
@@ -697,12 +707,14 @@ function processLangGraphEvent(event, state, controller) {
|
|
|
697
707
|
if (namespace !== void 0) {
|
|
698
708
|
state.messageNamespaces.set(msgId, namespace);
|
|
699
709
|
}
|
|
710
|
+
let startedUIReducerStep = false;
|
|
700
711
|
const langgraphStep = typeof (metadata == null ? void 0 : metadata.langgraph_step) === "number" ? metadata.langgraph_step : null;
|
|
701
712
|
if (langgraphStep !== null) {
|
|
702
713
|
const currentStep = (_a = state.currentStepsByNamespace.get(eventNamespace)) != null ? _a : null;
|
|
703
714
|
if (currentStep === null) {
|
|
704
715
|
if (state.currentStepsByNamespace.size === 0) {
|
|
705
716
|
controller.enqueue({ type: "start-step" });
|
|
717
|
+
startedUIReducerStep = true;
|
|
706
718
|
}
|
|
707
719
|
state.currentStepsByNamespace.set(eventNamespace, langgraphStep);
|
|
708
720
|
state.messageIdsInCurrentStepByNamespace.set(
|
|
@@ -723,6 +735,7 @@ function processLangGraphEvent(event, state, controller) {
|
|
|
723
735
|
controller.enqueue({ type: "finish-step" });
|
|
724
736
|
}
|
|
725
737
|
controller.enqueue({ type: "start-step" });
|
|
738
|
+
startedUIReducerStep = true;
|
|
726
739
|
state.currentStepsByNamespace.set(eventNamespace, langgraphStep);
|
|
727
740
|
state.messageIdsInCurrentStepByNamespace.set(
|
|
728
741
|
eventNamespace,
|
|
@@ -797,7 +810,7 @@ function processLangGraphEvent(event, state, controller) {
|
|
|
797
810
|
toolCallId,
|
|
798
811
|
eventNamespace
|
|
799
812
|
)) {
|
|
800
|
-
|
|
813
|
+
markToolCallStarted(state, toolCallId, eventNamespace);
|
|
801
814
|
controller.enqueue({
|
|
802
815
|
type: "tool-input-start",
|
|
803
816
|
toolCallId,
|
|
@@ -870,6 +883,25 @@ function processLangGraphEvent(event, state, controller) {
|
|
|
870
883
|
const toolCallId = dataSource.tool_call_id;
|
|
871
884
|
const status = dataSource.status;
|
|
872
885
|
if (toolCallId) {
|
|
886
|
+
const wasEmittedInCurrentStep = hasEmittedToolCallInCurrentStep(
|
|
887
|
+
state,
|
|
888
|
+
toolCallId,
|
|
889
|
+
eventNamespace
|
|
890
|
+
);
|
|
891
|
+
const isDelayedOutputForPreviousLifecycle = !wasEmittedInCurrentStep && hasUnfinishedToolCall(state, toolCallId, eventNamespace);
|
|
892
|
+
if (!wasEmittedInCurrentStep && !isDelayedOutputForPreviousLifecycle) {
|
|
893
|
+
if (!startedUIReducerStep && state.currentStepsByNamespace.has(eventNamespace) && emittedToolCalls.has(toolCallId)) {
|
|
894
|
+
controller.enqueue({ type: "start-step" });
|
|
895
|
+
}
|
|
896
|
+
markToolCallStarted(state, toolCallId, eventNamespace);
|
|
897
|
+
controller.enqueue({
|
|
898
|
+
type: "tool-input-start",
|
|
899
|
+
toolCallId,
|
|
900
|
+
toolName: typeof dataSource.name === "string" ? dataSource.name : "unknown",
|
|
901
|
+
dynamic: true
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
(_n = state.unfinishedToolCallsByNamespace.get(eventNamespace)) == null ? void 0 : _n.delete(toolCallId);
|
|
873
905
|
if (status === "error") {
|
|
874
906
|
controller.enqueue({
|
|
875
907
|
type: "tool-output-error",
|
|
@@ -896,7 +928,7 @@ function processLangGraphEvent(event, state, controller) {
|
|
|
896
928
|
if (seen.tool) {
|
|
897
929
|
for (const toolCallId of seen.tool) {
|
|
898
930
|
const concatMsg = messageConcat.get(id);
|
|
899
|
-
const toolCall = (
|
|
931
|
+
const toolCall = (_o = concatMsg == null ? void 0 : concatMsg.tool_calls) == null ? void 0 : _o.find(
|
|
900
932
|
(call) => call.id === toolCallId
|
|
901
933
|
);
|
|
902
934
|
if (toolCall) {
|
|
@@ -989,7 +1021,7 @@ function processLangGraphEvent(event, state, controller) {
|
|
|
989
1021
|
toolCall.id,
|
|
990
1022
|
lifecycleNamespace
|
|
991
1023
|
) && (wasObservedInCurrentStep || !emittedToolCalls.has(toolCall.id) && !completedToolCallIds.has(toolCall.id))) {
|
|
992
|
-
|
|
1024
|
+
markToolCallStarted(state, toolCall.id, lifecycleNamespace);
|
|
993
1025
|
const toolCallKey = `${toolCall.name}:${JSON.stringify(toolCall.args)}`;
|
|
994
1026
|
emittedToolCallsByKey.set(toolCallKey, toolCall.id);
|
|
995
1027
|
controller.enqueue({
|
|
@@ -1054,7 +1086,7 @@ function processLangGraphEvent(event, state, controller) {
|
|
|
1054
1086
|
const toolCallKey = `${toolName}:${JSON.stringify(input)}`;
|
|
1055
1087
|
const toolCallId = emittedToolCallsByKey.get(toolCallKey) || actionRequest.id || `hitl-${toolName}-${Date.now()}`;
|
|
1056
1088
|
if (!emittedToolCalls.has(toolCallId)) {
|
|
1057
|
-
|
|
1089
|
+
markToolCallStarted(state, toolCallId, eventNamespace);
|
|
1058
1090
|
emittedToolCallsByKey.set(toolCallKey, toolCallId);
|
|
1059
1091
|
controller.enqueue({
|
|
1060
1092
|
type: "tool-input-start",
|
|
@@ -1268,6 +1300,7 @@ function toUIMessageStream(stream, callbacks) {
|
|
|
1268
1300
|
messageIdsInCurrentStepByNamespace: /* @__PURE__ */ new Map(),
|
|
1269
1301
|
emittedToolCalls: /* @__PURE__ */ new Set(),
|
|
1270
1302
|
emittedToolCallsInCurrentStepByNamespace: /* @__PURE__ */ new Map(),
|
|
1303
|
+
unfinishedToolCallsByNamespace: /* @__PURE__ */ new Map(),
|
|
1271
1304
|
emittedImages: /* @__PURE__ */ new Set(),
|
|
1272
1305
|
emittedReasoningIds: /* @__PURE__ */ new Set(),
|
|
1273
1306
|
messageReasoningIds: /* @__PURE__ */ new Map(),
|