@librechat/agents 4.2.14 → 4.2.15

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.
Files changed (45) hide show
  1. package/dist/cjs/agents/AgentContext.cjs +75 -19
  2. package/dist/cjs/agents/AgentContext.cjs.map +1 -1
  3. package/dist/cjs/graphs/Graph.cjs +7 -3
  4. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  5. package/dist/cjs/llm/prepareProviderRequest.cjs +24 -6
  6. package/dist/cjs/llm/prepareProviderRequest.cjs.map +1 -1
  7. package/dist/cjs/main.cjs +1 -0
  8. package/dist/cjs/messages/content.cjs +3 -3
  9. package/dist/cjs/messages/content.cjs.map +1 -1
  10. package/dist/cjs/messages/vision.cjs +77 -0
  11. package/dist/cjs/messages/vision.cjs.map +1 -0
  12. package/dist/cjs/summarization/node.cjs +6 -2
  13. package/dist/cjs/summarization/node.cjs.map +1 -1
  14. package/dist/cjs/utils/tokens.cjs +1 -0
  15. package/dist/cjs/utils/tokens.cjs.map +1 -1
  16. package/dist/esm/agents/AgentContext.mjs +76 -20
  17. package/dist/esm/agents/AgentContext.mjs.map +1 -1
  18. package/dist/esm/graphs/Graph.mjs +7 -3
  19. package/dist/esm/graphs/Graph.mjs.map +1 -1
  20. package/dist/esm/llm/prepareProviderRequest.mjs +24 -6
  21. package/dist/esm/llm/prepareProviderRequest.mjs.map +1 -1
  22. package/dist/esm/main.mjs +2 -2
  23. package/dist/esm/messages/content.mjs +3 -3
  24. package/dist/esm/messages/content.mjs.map +1 -1
  25. package/dist/esm/messages/vision.mjs +73 -0
  26. package/dist/esm/messages/vision.mjs.map +1 -0
  27. package/dist/esm/summarization/node.mjs +6 -2
  28. package/dist/esm/summarization/node.mjs.map +1 -1
  29. package/dist/esm/utils/tokens.mjs +1 -1
  30. package/dist/esm/utils/tokens.mjs.map +1 -1
  31. package/dist/types/agents/AgentContext.d.ts +20 -1
  32. package/dist/types/llm/prepareProviderRequest.d.ts +7 -1
  33. package/dist/types/messages/content.d.ts +2 -1
  34. package/dist/types/messages/vision.d.ts +20 -0
  35. package/dist/types/types/graph.d.ts +8 -0
  36. package/dist/types/utils/tokens.d.ts +2 -0
  37. package/package.json +1 -1
  38. package/src/agents/AgentContext.ts +188 -78
  39. package/src/graphs/Graph.ts +14 -5
  40. package/src/llm/prepareProviderRequest.ts +52 -3
  41. package/src/messages/content.ts +10 -4
  42. package/src/messages/vision.ts +109 -0
  43. package/src/summarization/node.ts +4 -0
  44. package/src/types/graph.ts +8 -0
  45. package/src/utils/tokens.ts +4 -1
@@ -0,0 +1,109 @@
1
+ import type { MessageContentComplex } from '@langchain/core/messages';
2
+ import { getCacheControl, withCacheControl } from './cache';
3
+ import { getMediaMimeType } from '@/utils/tokens';
4
+
5
+ /** Stands in for each image a model without image input cannot read. */
6
+ export const OMITTED_IMAGE_TEXT =
7
+ '[Image omitted because this model does not accept image input.]';
8
+
9
+ const IMAGE_BLOCK_TYPES = new Set(['image', 'image_url', 'input_image']);
10
+ const MIME_TYPED_BLOCK_TYPES = new Set(['file', 'media']);
11
+
12
+ /** Whether a content block carries an image, in any provider's shape. */
13
+ export function isImageContentBlock(block: MessageContentComplex): boolean {
14
+ const type = block.type;
15
+ if (typeof type !== 'string') {
16
+ return false;
17
+ }
18
+ if (IMAGE_BLOCK_TYPES.has(type) || type.startsWith('image/')) {
19
+ return true;
20
+ }
21
+ if (!MIME_TYPED_BLOCK_TYPES.has(type)) {
22
+ return false;
23
+ }
24
+ return (
25
+ getMediaMimeType(block as Record<string, unknown>)?.startsWith('image/') ===
26
+ true
27
+ );
28
+ }
29
+
30
+ /** The text marker standing in for `image`, carrying its prompt-cache breakpoint. */
31
+ export function toOmittedImageBlock(
32
+ image: MessageContentComplex
33
+ ): MessageContentComplex {
34
+ const text: MessageContentComplex = {
35
+ type: 'text',
36
+ text: OMITTED_IMAGE_TEXT,
37
+ };
38
+ const marker = getCacheControl(image);
39
+ return marker == null ? text : withCacheControl(text, marker);
40
+ }
41
+
42
+ /**
43
+ * `block` with its image replaced by the marker, or a native `tool_result` or
44
+ * custom-content `document` with the images inside it replaced; `block` itself
45
+ * when it holds no image.
46
+ */
47
+ export function omitImageBlock(
48
+ block: MessageContentComplex
49
+ ): MessageContentComplex {
50
+ if (isImageContentBlock(block)) {
51
+ return toOmittedImageBlock(block);
52
+ }
53
+ if (block.type === 'tool_result' && Array.isArray(block.content)) {
54
+ const nested = omitImageBlocks(block.content as MessageContentComplex[]);
55
+ return nested == null ? block : { ...block, content: nested };
56
+ }
57
+ const source =
58
+ block.type === 'document'
59
+ ? (block as { source?: { type?: unknown; content?: unknown } }).source
60
+ : undefined;
61
+ if (
62
+ source == null ||
63
+ typeof source !== 'object' ||
64
+ source.type !== 'content' ||
65
+ !Array.isArray(source.content)
66
+ ) {
67
+ return block;
68
+ }
69
+ const nested = omitImageBlocks(source.content as MessageContentComplex[]);
70
+ return nested == null
71
+ ? block
72
+ : { ...block, source: { ...source, content: nested } };
73
+ }
74
+
75
+ /**
76
+ * A tool artifact with the images in its `content` replaced by markers, for
77
+ * the request it is expanded into; `undefined` when it holds none.
78
+ */
79
+ export function omitArtifactImages(
80
+ artifact: unknown
81
+ ): Record<string, unknown> | undefined {
82
+ if (artifact == null || typeof artifact !== 'object') {
83
+ return undefined;
84
+ }
85
+ const { content } = artifact as { content?: unknown };
86
+ if (!Array.isArray(content)) {
87
+ return undefined;
88
+ }
89
+ const omitted = omitImageBlocks(content as MessageContentComplex[]);
90
+ return omitted == null ? undefined : { ...artifact, content: omitted };
91
+ }
92
+
93
+ /** `content` with every image replaced by its marker; `undefined` when it holds none. */
94
+ export function omitImageBlocks(
95
+ content: MessageContentComplex[]
96
+ ): MessageContentComplex[] | undefined {
97
+ let omitted: MessageContentComplex[] | undefined;
98
+ for (let index = 0; index < content.length; index++) {
99
+ const block = content[index];
100
+ const replacement = omitImageBlock(block);
101
+ if (replacement === block) {
102
+ omitted?.push(block);
103
+ continue;
104
+ }
105
+ omitted ??= content.slice(0, index);
106
+ omitted.push(replacement);
107
+ }
108
+ return omitted;
109
+ }
@@ -1238,6 +1238,8 @@ async function runSummarizationAttempts(
1238
1238
  provider,
1239
1239
  context: graph,
1240
1240
  config,
1241
+ vision: agentContext.vision,
1242
+ useLegacyContent: agentContext.useLegacyContent,
1241
1243
  });
1242
1244
  fallbackIdentity = {
1243
1245
  provider,
@@ -2554,6 +2556,8 @@ async function summarizeWithCacheHit({
2554
2556
  provider,
2555
2557
  context: graph,
2556
2558
  config: signalConfig,
2559
+ vision: agentContext.vision,
2560
+ useLegacyContent: agentContext.useLegacyContent,
2557
2561
  });
2558
2562
  result = await attemptInvoke(
2559
2563
  {
@@ -1043,6 +1043,14 @@ interface AgentInputFields {
1043
1043
  reasoningKey?: 'reasoning_content' | 'reasoning';
1044
1044
  /** Format content blocks as strings (for legacy compatibility i.e. Ollama/Azure Serverless) */
1045
1045
  useLegacyContent?: boolean;
1046
+ /**
1047
+ * Whether this agent's model reads image input. `false` replaces every
1048
+ * image in the agent's provider requests (its own calls, fallbacks and
1049
+ * summarization) with a short text marker, so a text-only model in a
1050
+ * multi-agent run never receives images the other agents can read. Unset
1051
+ * sends images unchanged.
1052
+ */
1053
+ vision?: boolean;
1046
1054
  /**
1047
1055
  * Tool definitions for all tools, including deferred and programmatic.
1048
1056
  * Used for tool search and programmatic tool calling.
@@ -516,7 +516,10 @@ function timedMediaKind(
516
516
  return null;
517
517
  }
518
518
 
519
- function getMediaMimeType(block: Record<string, unknown>): string | undefined {
519
+ /** The normalized MIME type a media or file content block declares, if any. */
520
+ export function getMediaMimeType(
521
+ block: Record<string, unknown>
522
+ ): string | undefined {
520
523
  if (typeof block.mimeType === 'string') {
521
524
  return normalizeMediaMimeType(block.mimeType);
522
525
  }