@librechat/agents 4.2.16 → 4.2.18
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/cjs/agents/AgentContext.cjs +63 -2
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +152 -10
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/acceptedModelResponse.cjs +24 -15
- package/dist/cjs/graphs/acceptedModelResponse.cjs.map +1 -1
- package/dist/cjs/llm/truncation.cjs +4 -0
- package/dist/cjs/llm/truncation.cjs.map +1 -1
- package/dist/cjs/llm/vertexai/index.cjs +2 -3
- package/dist/cjs/llm/vertexai/index.cjs.map +1 -1
- package/dist/cjs/main.cjs +2 -1
- package/dist/cjs/messages/cache.cjs +1 -0
- package/dist/cjs/messages/cache.cjs.map +1 -1
- package/dist/cjs/messages/core.cjs +20 -5
- package/dist/cjs/messages/core.cjs.map +1 -1
- package/dist/cjs/run.cjs +4 -0
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +55 -30
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +20 -2
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/utils/toolContent.cjs +32 -16
- package/dist/cjs/utils/toolContent.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +64 -3
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +153 -11
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/acceptedModelResponse.mjs +24 -15
- package/dist/esm/graphs/acceptedModelResponse.mjs.map +1 -1
- package/dist/esm/llm/truncation.mjs +4 -1
- package/dist/esm/llm/truncation.mjs.map +1 -1
- package/dist/esm/llm/vertexai/index.mjs +2 -3
- package/dist/esm/llm/vertexai/index.mjs.map +1 -1
- package/dist/esm/main.mjs +3 -3
- package/dist/esm/messages/cache.mjs +1 -1
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/messages/core.mjs +22 -7
- package/dist/esm/messages/core.mjs.map +1 -1
- package/dist/esm/run.mjs +4 -0
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +55 -31
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +20 -2
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/utils/toolContent.mjs +32 -17
- package/dist/esm/utils/toolContent.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +15 -0
- package/dist/types/graphs/Graph.d.ts +12 -2
- package/dist/types/llm/truncation.d.ts +8 -0
- package/dist/types/messages/cache.d.ts +9 -0
- package/dist/types/run.d.ts +2 -0
- package/dist/types/summarization/node.d.ts +5 -0
- package/dist/types/types/graph.d.ts +9 -1
- package/dist/types/types/run.d.ts +2 -0
- package/dist/types/types/stream.d.ts +2 -0
- package/dist/types/types/summarize.d.ts +7 -2
- package/dist/types/utils/toolContent.d.ts +6 -0
- package/package.json +1 -1
- package/src/agents/AgentContext.ts +137 -1
- package/src/graphs/Graph.ts +468 -180
- package/src/graphs/acceptedModelResponse.ts +31 -24
- package/src/llm/truncation.ts +16 -0
- package/src/llm/vertexai/index.ts +5 -4
- package/src/messages/cache.ts +1 -1
- package/src/messages/core.ts +37 -5
- package/src/run.ts +8 -0
- package/src/summarization/node.ts +74 -33
- package/src/tools/ToolNode.ts +67 -8
- package/src/types/graph.ts +9 -0
- package/src/types/run.ts +2 -0
- package/src/types/stream.ts +2 -0
- package/src/types/summarize.ts +11 -2
- package/src/utils/toolContent.ts +72 -21
package/src/utils/toolContent.ts
CHANGED
|
@@ -1956,6 +1956,17 @@ export type CompactToolContentResult = {
|
|
|
1956
1956
|
originalChars: number;
|
|
1957
1957
|
};
|
|
1958
1958
|
|
|
1959
|
+
/** Whether `value` has a control or space character before index `end`. */
|
|
1960
|
+
function hasUrlControlChars(value: string, end: number): boolean {
|
|
1961
|
+
for (let i = 0; i < end; i++) {
|
|
1962
|
+
const code = value.charCodeAt(i);
|
|
1963
|
+
if (code <= 0x20 || code === 0x7f) {
|
|
1964
|
+
return true;
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
return false;
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1959
1970
|
function isProviderImageUrl(value: unknown): value is string {
|
|
1960
1971
|
if (typeof value !== 'string' || value === '') {
|
|
1961
1972
|
return false;
|
|
@@ -1969,20 +1980,17 @@ function isProviderImageUrl(value: unknown): value is string {
|
|
|
1969
1980
|
) {
|
|
1970
1981
|
return false;
|
|
1971
1982
|
}
|
|
1972
|
-
for (let i = 0; i < value.length; i++) {
|
|
1973
|
-
const code = value.charCodeAt(i);
|
|
1974
|
-
if (code <= 0x20 || code === 0x7f) {
|
|
1975
|
-
return false;
|
|
1976
|
-
}
|
|
1977
|
-
}
|
|
1978
1983
|
if (isDataImage) {
|
|
1979
1984
|
const separator = value.indexOf(',');
|
|
1980
1985
|
if (
|
|
1981
1986
|
separator < 0 ||
|
|
1987
|
+
hasUrlControlChars(value, separator) ||
|
|
1982
1988
|
!value.slice(0, separator).toLowerCase().endsWith(';base64')
|
|
1983
1989
|
) {
|
|
1984
1990
|
return false;
|
|
1985
1991
|
}
|
|
1992
|
+
/** The base64 alphabet excludes every control and space character, so the
|
|
1993
|
+
* payload, up to megabytes of it, needs no separate character scan. */
|
|
1986
1994
|
const payload = value.slice(separator + 1);
|
|
1987
1995
|
return (
|
|
1988
1996
|
payload.length > 0 &&
|
|
@@ -1990,6 +1998,9 @@ function isProviderImageUrl(value: unknown): value is string {
|
|
|
1990
1998
|
/^[a-z0-9+/]+={0,2}$/i.test(payload)
|
|
1991
1999
|
);
|
|
1992
2000
|
}
|
|
2001
|
+
if (hasUrlControlChars(value, value.length)) {
|
|
2002
|
+
return false;
|
|
2003
|
+
}
|
|
1993
2004
|
try {
|
|
1994
2005
|
const url = new URL(value);
|
|
1995
2006
|
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
@@ -2281,26 +2292,66 @@ export function getComputerCallOutputScreenshot(
|
|
|
2281
2292
|
file_id: validFileId as string,
|
|
2282
2293
|
};
|
|
2283
2294
|
}
|
|
2295
|
+
if (type.value === 'image_url') {
|
|
2296
|
+
const url = readImageUrlBlockUrl(block, type, imageUrl, fileId);
|
|
2297
|
+
return url != null ? { type: 'input_image', image_url: url } : undefined;
|
|
2298
|
+
}
|
|
2299
|
+
return undefined;
|
|
2300
|
+
}
|
|
2301
|
+
|
|
2302
|
+
function readImageUrlBlockUrl(
|
|
2303
|
+
block: Record<string, unknown>,
|
|
2304
|
+
type: OwnDataProperty,
|
|
2305
|
+
imageUrl: OwnDataProperty,
|
|
2306
|
+
fileId: OwnDataProperty
|
|
2307
|
+
): string | undefined {
|
|
2284
2308
|
if (
|
|
2285
|
-
type.
|
|
2286
|
-
|
|
2287
|
-
|
|
2309
|
+
!type.found ||
|
|
2310
|
+
type.value !== 'image_url' ||
|
|
2311
|
+
fileId.found ||
|
|
2312
|
+
!imageUrl.found ||
|
|
2313
|
+
!hasOnlyEnumerableKeys(block, IMAGE_URL_KEYS)
|
|
2288
2314
|
) {
|
|
2289
|
-
|
|
2290
|
-
|
|
2315
|
+
return undefined;
|
|
2316
|
+
}
|
|
2317
|
+
if (isProviderImageUrl(imageUrl.value)) {
|
|
2318
|
+
return imageUrl.value;
|
|
2319
|
+
}
|
|
2320
|
+
if (
|
|
2321
|
+
!isRecord(imageUrl.value) ||
|
|
2322
|
+
!hasOnlyEnumerableKeys(imageUrl.value, NESTED_IMAGE_URL_KEYS)
|
|
2323
|
+
) {
|
|
2324
|
+
return undefined;
|
|
2325
|
+
}
|
|
2326
|
+
const url = readOwnEnumerableDataProperty(imageUrl.value, 'url');
|
|
2327
|
+
return url.found && isProviderImageUrl(url.value) ? url.value : undefined;
|
|
2328
|
+
}
|
|
2329
|
+
|
|
2330
|
+
/**
|
|
2331
|
+
* Returns the URL of a well-formed `image_url` block (an `http(s)` URL or a
|
|
2332
|
+
* base64 image data URL within the inline image ceiling), reading only own
|
|
2333
|
+
* data properties and never invoking serialization hooks.
|
|
2334
|
+
*/
|
|
2335
|
+
export function getToolContentImageUrl(block: unknown): string | undefined {
|
|
2336
|
+
try {
|
|
2337
|
+
if (!isRecord(block) || isProxy(block)) {
|
|
2338
|
+
return undefined;
|
|
2291
2339
|
}
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
const url = readOwnEnumerableDataProperty(imageUrl.value, 'url');
|
|
2298
|
-
if (url.found && isProviderImageUrl(url.value)) {
|
|
2299
|
-
return { type: 'input_image', image_url: url.value };
|
|
2300
|
-
}
|
|
2340
|
+
/** Every content block passes through here; settle the type from its own
|
|
2341
|
+
* data property before walking the block for serialization hooks. */
|
|
2342
|
+
const type = readOwnEnumerableDataProperty(block, 'type');
|
|
2343
|
+
if (type.value !== 'image_url' || hasUnsafeCallableToJSON(block)) {
|
|
2344
|
+
return undefined;
|
|
2301
2345
|
}
|
|
2346
|
+
return readImageUrlBlockUrl(
|
|
2347
|
+
block,
|
|
2348
|
+
type,
|
|
2349
|
+
readOwnEnumerableDataProperty(block, 'image_url'),
|
|
2350
|
+
readOwnEnumerableDataProperty(block, 'file_id')
|
|
2351
|
+
);
|
|
2352
|
+
} catch {
|
|
2353
|
+
return undefined;
|
|
2302
2354
|
}
|
|
2303
|
-
return undefined;
|
|
2304
2355
|
}
|
|
2305
2356
|
|
|
2306
2357
|
/** Returns the provider image URL when a screenshot is URL-backed. */
|