@langchain/core 0.3.24 → 0.3.26
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/messages/base.d.ts +1 -1
- package/dist/messages/transformers.cjs +24 -0
- package/dist/messages/transformers.js +24 -0
- package/dist/messages/utils.cjs +10 -1
- package/dist/messages/utils.js +10 -1
- package/dist/runnables/base.cjs +27 -20
- package/dist/runnables/base.js +27 -20
- package/package.json +1 -1
package/dist/messages/base.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export interface StoredMessageV1 {
|
|
|
23
23
|
role: string | undefined;
|
|
24
24
|
text: string;
|
|
25
25
|
}
|
|
26
|
-
export type MessageType = "human" | "ai" | "generic" | "system" | "function" | "tool" | "remove";
|
|
26
|
+
export type MessageType = "human" | "ai" | "generic" | "developer" | "system" | "function" | "tool" | "remove";
|
|
27
27
|
export type ImageDetail = "auto" | "low" | "high";
|
|
28
28
|
export type MessageContentText = {
|
|
29
29
|
type: "text";
|
|
@@ -292,6 +292,10 @@ const _MSG_CHUNK_MAP = {
|
|
|
292
292
|
message: system_js_1.SystemMessage,
|
|
293
293
|
messageChunk: system_js_1.SystemMessageChunk,
|
|
294
294
|
},
|
|
295
|
+
developer: {
|
|
296
|
+
message: system_js_1.SystemMessage,
|
|
297
|
+
messageChunk: system_js_1.SystemMessageChunk,
|
|
298
|
+
},
|
|
295
299
|
tool: {
|
|
296
300
|
message: tool_js_1.ToolMessage,
|
|
297
301
|
messageChunk: tool_js_1.ToolMessageChunk,
|
|
@@ -351,6 +355,26 @@ function _switchTypeToMessage(messageType, fields, returnChunk) {
|
|
|
351
355
|
msg = new system_js_1.SystemMessage(fields);
|
|
352
356
|
}
|
|
353
357
|
break;
|
|
358
|
+
case "developer":
|
|
359
|
+
if (returnChunk) {
|
|
360
|
+
chunk = new system_js_1.SystemMessageChunk({
|
|
361
|
+
...fields,
|
|
362
|
+
additional_kwargs: {
|
|
363
|
+
...fields.additional_kwargs,
|
|
364
|
+
__openai_role__: "developer",
|
|
365
|
+
},
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
msg = new system_js_1.SystemMessage({
|
|
370
|
+
...fields,
|
|
371
|
+
additional_kwargs: {
|
|
372
|
+
...fields.additional_kwargs,
|
|
373
|
+
__openai_role__: "developer",
|
|
374
|
+
},
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
break;
|
|
354
378
|
case "tool":
|
|
355
379
|
if ("tool_call_id" in fields) {
|
|
356
380
|
if (returnChunk) {
|
|
@@ -286,6 +286,10 @@ const _MSG_CHUNK_MAP = {
|
|
|
286
286
|
message: SystemMessage,
|
|
287
287
|
messageChunk: SystemMessageChunk,
|
|
288
288
|
},
|
|
289
|
+
developer: {
|
|
290
|
+
message: SystemMessage,
|
|
291
|
+
messageChunk: SystemMessageChunk,
|
|
292
|
+
},
|
|
289
293
|
tool: {
|
|
290
294
|
message: ToolMessage,
|
|
291
295
|
messageChunk: ToolMessageChunk,
|
|
@@ -345,6 +349,26 @@ function _switchTypeToMessage(messageType, fields, returnChunk) {
|
|
|
345
349
|
msg = new SystemMessage(fields);
|
|
346
350
|
}
|
|
347
351
|
break;
|
|
352
|
+
case "developer":
|
|
353
|
+
if (returnChunk) {
|
|
354
|
+
chunk = new SystemMessageChunk({
|
|
355
|
+
...fields,
|
|
356
|
+
additional_kwargs: {
|
|
357
|
+
...fields.additional_kwargs,
|
|
358
|
+
__openai_role__: "developer",
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
msg = new SystemMessage({
|
|
364
|
+
...fields,
|
|
365
|
+
additional_kwargs: {
|
|
366
|
+
...fields.additional_kwargs,
|
|
367
|
+
__openai_role__: "developer",
|
|
368
|
+
},
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
break;
|
|
348
372
|
case "tool":
|
|
349
373
|
if ("tool_call_id" in fields) {
|
|
350
374
|
if (returnChunk) {
|
package/dist/messages/utils.cjs
CHANGED
|
@@ -83,6 +83,15 @@ function _constructMessageFromParams(params) {
|
|
|
83
83
|
else if (type === "system") {
|
|
84
84
|
return new system_js_1.SystemMessage(rest);
|
|
85
85
|
}
|
|
86
|
+
else if (type === "developer") {
|
|
87
|
+
return new system_js_1.SystemMessage({
|
|
88
|
+
...rest,
|
|
89
|
+
additional_kwargs: {
|
|
90
|
+
...rest.additional_kwargs,
|
|
91
|
+
__openai_role__: "developer",
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}
|
|
86
95
|
else if (type === "tool" && "tool_call_id" in rest) {
|
|
87
96
|
return new tool_js_1.ToolMessage({
|
|
88
97
|
...rest,
|
|
@@ -92,7 +101,7 @@ function _constructMessageFromParams(params) {
|
|
|
92
101
|
});
|
|
93
102
|
}
|
|
94
103
|
else {
|
|
95
|
-
const error = (0, index_js_1.addLangChainErrorFields)(new Error(`Unable to coerce message from array: only human, AI, system, or tool message coercion is currently supported.\n\nReceived: ${JSON.stringify(params, null, 2)}`), "MESSAGE_COERCION_FAILURE");
|
|
104
|
+
const error = (0, index_js_1.addLangChainErrorFields)(new Error(`Unable to coerce message from array: only human, AI, system, developer, or tool message coercion is currently supported.\n\nReceived: ${JSON.stringify(params, null, 2)}`), "MESSAGE_COERCION_FAILURE");
|
|
96
105
|
throw error;
|
|
97
106
|
}
|
|
98
107
|
}
|
package/dist/messages/utils.js
CHANGED
|
@@ -80,6 +80,15 @@ function _constructMessageFromParams(params) {
|
|
|
80
80
|
else if (type === "system") {
|
|
81
81
|
return new SystemMessage(rest);
|
|
82
82
|
}
|
|
83
|
+
else if (type === "developer") {
|
|
84
|
+
return new SystemMessage({
|
|
85
|
+
...rest,
|
|
86
|
+
additional_kwargs: {
|
|
87
|
+
...rest.additional_kwargs,
|
|
88
|
+
__openai_role__: "developer",
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
}
|
|
83
92
|
else if (type === "tool" && "tool_call_id" in rest) {
|
|
84
93
|
return new ToolMessage({
|
|
85
94
|
...rest,
|
|
@@ -89,7 +98,7 @@ function _constructMessageFromParams(params) {
|
|
|
89
98
|
});
|
|
90
99
|
}
|
|
91
100
|
else {
|
|
92
|
-
const error = addLangChainErrorFields(new Error(`Unable to coerce message from array: only human, AI, system, or tool message coercion is currently supported.\n\nReceived: ${JSON.stringify(params, null, 2)}`), "MESSAGE_COERCION_FAILURE");
|
|
101
|
+
const error = addLangChainErrorFields(new Error(`Unable to coerce message from array: only human, AI, system, developer, or tool message coercion is currently supported.\n\nReceived: ${JSON.stringify(params, null, 2)}`), "MESSAGE_COERCION_FAILURE");
|
|
93
102
|
throw error;
|
|
94
103
|
}
|
|
95
104
|
}
|
package/dist/runnables/base.cjs
CHANGED
|
@@ -1944,32 +1944,38 @@ class RunnableWithFallbacks extends Runnable {
|
|
|
1944
1944
|
}
|
|
1945
1945
|
async invoke(input, options) {
|
|
1946
1946
|
const config = (0, config_js_1.ensureConfig)(options);
|
|
1947
|
-
const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(
|
|
1947
|
+
const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(config);
|
|
1948
1948
|
const { runId, ...otherConfigFields } = config;
|
|
1949
1949
|
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), runId, undefined, undefined, undefined, otherConfigFields?.runName);
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1950
|
+
const childConfig = (0, config_js_1.patchConfig)(otherConfigFields, {
|
|
1951
|
+
callbacks: runManager?.getChild(),
|
|
1952
|
+
});
|
|
1953
|
+
const res = await index_js_1.AsyncLocalStorageProviderSingleton.runWithConfig(childConfig, async () => {
|
|
1954
|
+
let firstError;
|
|
1955
|
+
for (const runnable of this.runnables()) {
|
|
1956
|
+
config?.signal?.throwIfAborted();
|
|
1957
|
+
try {
|
|
1958
|
+
const output = await runnable.invoke(input, childConfig);
|
|
1959
|
+
await runManager?.handleChainEnd(_coerceToDict(output, "output"));
|
|
1960
|
+
return output;
|
|
1961
|
+
}
|
|
1962
|
+
catch (e) {
|
|
1963
|
+
if (firstError === undefined) {
|
|
1964
|
+
firstError = e;
|
|
1965
|
+
}
|
|
1961
1966
|
}
|
|
1962
1967
|
}
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1968
|
+
if (firstError === undefined) {
|
|
1969
|
+
throw new Error("No error stored at end of fallback.");
|
|
1970
|
+
}
|
|
1971
|
+
await runManager?.handleChainError(firstError);
|
|
1972
|
+
throw firstError;
|
|
1973
|
+
});
|
|
1974
|
+
return res;
|
|
1969
1975
|
}
|
|
1970
1976
|
async *_streamIterator(input, options) {
|
|
1971
1977
|
const config = (0, config_js_1.ensureConfig)(options);
|
|
1972
|
-
const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(
|
|
1978
|
+
const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(config);
|
|
1973
1979
|
const { runId, ...otherConfigFields } = config;
|
|
1974
1980
|
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), runId, undefined, undefined, undefined, otherConfigFields?.runName);
|
|
1975
1981
|
let firstError;
|
|
@@ -1980,7 +1986,8 @@ class RunnableWithFallbacks extends Runnable {
|
|
|
1980
1986
|
callbacks: runManager?.getChild(),
|
|
1981
1987
|
});
|
|
1982
1988
|
try {
|
|
1983
|
-
|
|
1989
|
+
const originalStream = await runnable.stream(input, childConfig);
|
|
1990
|
+
stream = (0, iter_js_1.consumeAsyncIterableInContext)(childConfig, originalStream);
|
|
1984
1991
|
break;
|
|
1985
1992
|
}
|
|
1986
1993
|
catch (e) {
|
package/dist/runnables/base.js
CHANGED
|
@@ -1928,32 +1928,38 @@ export class RunnableWithFallbacks extends Runnable {
|
|
|
1928
1928
|
}
|
|
1929
1929
|
async invoke(input, options) {
|
|
1930
1930
|
const config = ensureConfig(options);
|
|
1931
|
-
const callbackManager_ = await getCallbackManagerForConfig(
|
|
1931
|
+
const callbackManager_ = await getCallbackManagerForConfig(config);
|
|
1932
1932
|
const { runId, ...otherConfigFields } = config;
|
|
1933
1933
|
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), runId, undefined, undefined, undefined, otherConfigFields?.runName);
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1934
|
+
const childConfig = patchConfig(otherConfigFields, {
|
|
1935
|
+
callbacks: runManager?.getChild(),
|
|
1936
|
+
});
|
|
1937
|
+
const res = await AsyncLocalStorageProviderSingleton.runWithConfig(childConfig, async () => {
|
|
1938
|
+
let firstError;
|
|
1939
|
+
for (const runnable of this.runnables()) {
|
|
1940
|
+
config?.signal?.throwIfAborted();
|
|
1941
|
+
try {
|
|
1942
|
+
const output = await runnable.invoke(input, childConfig);
|
|
1943
|
+
await runManager?.handleChainEnd(_coerceToDict(output, "output"));
|
|
1944
|
+
return output;
|
|
1945
|
+
}
|
|
1946
|
+
catch (e) {
|
|
1947
|
+
if (firstError === undefined) {
|
|
1948
|
+
firstError = e;
|
|
1949
|
+
}
|
|
1945
1950
|
}
|
|
1946
1951
|
}
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1952
|
+
if (firstError === undefined) {
|
|
1953
|
+
throw new Error("No error stored at end of fallback.");
|
|
1954
|
+
}
|
|
1955
|
+
await runManager?.handleChainError(firstError);
|
|
1956
|
+
throw firstError;
|
|
1957
|
+
});
|
|
1958
|
+
return res;
|
|
1953
1959
|
}
|
|
1954
1960
|
async *_streamIterator(input, options) {
|
|
1955
1961
|
const config = ensureConfig(options);
|
|
1956
|
-
const callbackManager_ = await getCallbackManagerForConfig(
|
|
1962
|
+
const callbackManager_ = await getCallbackManagerForConfig(config);
|
|
1957
1963
|
const { runId, ...otherConfigFields } = config;
|
|
1958
1964
|
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), runId, undefined, undefined, undefined, otherConfigFields?.runName);
|
|
1959
1965
|
let firstError;
|
|
@@ -1964,7 +1970,8 @@ export class RunnableWithFallbacks extends Runnable {
|
|
|
1964
1970
|
callbacks: runManager?.getChild(),
|
|
1965
1971
|
});
|
|
1966
1972
|
try {
|
|
1967
|
-
|
|
1973
|
+
const originalStream = await runnable.stream(input, childConfig);
|
|
1974
|
+
stream = consumeAsyncIterableInContext(childConfig, originalStream);
|
|
1968
1975
|
break;
|
|
1969
1976
|
}
|
|
1970
1977
|
catch (e) {
|