@librechat/agents 4.2.4 → 4.2.6

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 (103) hide show
  1. package/dist/cjs/harness/identity.cjs +26 -0
  2. package/dist/cjs/harness/identity.cjs.map +1 -0
  3. package/dist/cjs/harness/index.cjs +3 -15
  4. package/dist/cjs/harness/index.cjs.map +1 -1
  5. package/dist/cjs/harness/providerText.cjs +79 -0
  6. package/dist/cjs/harness/providerText.cjs.map +1 -0
  7. package/dist/cjs/llm/contextPressureMeter.cjs +1 -1
  8. package/dist/cjs/llm/contextPressureMeter.cjs.map +1 -1
  9. package/dist/cjs/llm/google/index.cjs +27 -6
  10. package/dist/cjs/llm/google/index.cjs.map +1 -1
  11. package/dist/cjs/llm/google/utils/common.cjs +27 -14
  12. package/dist/cjs/llm/google/utils/common.cjs.map +1 -1
  13. package/dist/cjs/llm/google/utils/signatures.cjs +137 -0
  14. package/dist/cjs/llm/google/utils/signatures.cjs.map +1 -0
  15. package/dist/cjs/llm/openai/index.cjs +21 -12
  16. package/dist/cjs/llm/openai/index.cjs.map +1 -1
  17. package/dist/cjs/llm/openai/streamMetadata.cjs +4 -1
  18. package/dist/cjs/llm/openai/streamMetadata.cjs.map +1 -1
  19. package/dist/cjs/llm/providerTextBoundary.cjs +3 -0
  20. package/dist/cjs/llm/providerTextBoundary.cjs.map +1 -1
  21. package/dist/cjs/llm/vertexai/index.cjs +90 -7
  22. package/dist/cjs/llm/vertexai/index.cjs.map +1 -1
  23. package/dist/cjs/main.cjs +11 -0
  24. package/dist/cjs/messages/content.cjs +4 -1
  25. package/dist/cjs/messages/content.cjs.map +1 -1
  26. package/dist/cjs/messages/format.cjs +11 -8
  27. package/dist/cjs/messages/format.cjs.map +1 -1
  28. package/dist/cjs/stream.cjs +4 -1
  29. package/dist/cjs/stream.cjs.map +1 -1
  30. package/dist/cjs/tools/BashExecutor.cjs +2 -1
  31. package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
  32. package/dist/cjs/tools/ToolNode.cjs +141 -94
  33. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  34. package/dist/cjs/tools/toolOutputReferences.cjs +39 -17
  35. package/dist/cjs/tools/toolOutputReferences.cjs.map +1 -1
  36. package/dist/esm/harness/identity.mjs +24 -0
  37. package/dist/esm/harness/identity.mjs.map +1 -0
  38. package/dist/esm/harness/index.mjs +3 -15
  39. package/dist/esm/harness/index.mjs.map +1 -1
  40. package/dist/esm/harness/providerText.mjs +78 -0
  41. package/dist/esm/harness/providerText.mjs.map +1 -0
  42. package/dist/esm/llm/contextPressureMeter.mjs +1 -1
  43. package/dist/esm/llm/contextPressureMeter.mjs.map +1 -1
  44. package/dist/esm/llm/google/index.mjs +23 -7
  45. package/dist/esm/llm/google/index.mjs.map +1 -1
  46. package/dist/esm/llm/google/utils/common.mjs +27 -14
  47. package/dist/esm/llm/google/utils/common.mjs.map +1 -1
  48. package/dist/esm/llm/google/utils/signatures.mjs +132 -0
  49. package/dist/esm/llm/google/utils/signatures.mjs.map +1 -0
  50. package/dist/esm/llm/openai/index.mjs +21 -12
  51. package/dist/esm/llm/openai/index.mjs.map +1 -1
  52. package/dist/esm/llm/openai/streamMetadata.mjs +4 -1
  53. package/dist/esm/llm/openai/streamMetadata.mjs.map +1 -1
  54. package/dist/esm/llm/providerTextBoundary.mjs +3 -0
  55. package/dist/esm/llm/providerTextBoundary.mjs.map +1 -1
  56. package/dist/esm/llm/vertexai/index.mjs +91 -8
  57. package/dist/esm/llm/vertexai/index.mjs.map +1 -1
  58. package/dist/esm/main.mjs +4 -1
  59. package/dist/esm/messages/content.mjs +4 -1
  60. package/dist/esm/messages/content.mjs.map +1 -1
  61. package/dist/esm/messages/format.mjs +11 -8
  62. package/dist/esm/messages/format.mjs.map +1 -1
  63. package/dist/esm/stream.mjs +4 -1
  64. package/dist/esm/stream.mjs.map +1 -1
  65. package/dist/esm/tools/BashExecutor.mjs +2 -1
  66. package/dist/esm/tools/BashExecutor.mjs.map +1 -1
  67. package/dist/esm/tools/ToolNode.mjs +142 -95
  68. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  69. package/dist/esm/tools/toolOutputReferences.mjs +39 -18
  70. package/dist/esm/tools/toolOutputReferences.mjs.map +1 -1
  71. package/dist/types/harness/identity.d.ts +14 -0
  72. package/dist/types/harness/index.d.ts +5 -9
  73. package/dist/types/harness/providerText.d.ts +32 -0
  74. package/dist/types/index.d.ts +2 -0
  75. package/dist/types/llm/google/index.d.ts +4 -2
  76. package/dist/types/llm/google/utils/common.d.ts +5 -1
  77. package/dist/types/llm/google/utils/signatures.d.ts +23 -0
  78. package/dist/types/llm/openai/streamMetadata.d.ts +3 -3
  79. package/dist/types/llm/vertexai/index.d.ts +2 -17
  80. package/dist/types/messages/format.d.ts +3 -1
  81. package/dist/types/tools/ToolNode.d.ts +7 -7
  82. package/dist/types/tools/toolOutputReferences.d.ts +16 -4
  83. package/dist/types/types/llm.d.ts +2 -2
  84. package/package.json +1 -1
  85. package/src/harness/identity.ts +34 -0
  86. package/src/harness/index.ts +15 -23
  87. package/src/harness/providerText.ts +128 -0
  88. package/src/index.ts +9 -0
  89. package/src/llm/contextPressureMeter.ts +2 -4
  90. package/src/llm/google/index.ts +20 -6
  91. package/src/llm/google/utils/common.ts +23 -10
  92. package/src/llm/google/utils/signatures.ts +215 -0
  93. package/src/llm/openai/index.ts +60 -20
  94. package/src/llm/openai/streamMetadata.ts +14 -3
  95. package/src/llm/providerTextBoundary.ts +3 -0
  96. package/src/llm/vertexai/index.ts +127 -39
  97. package/src/messages/content.ts +14 -6
  98. package/src/messages/format.ts +42 -29
  99. package/src/stream.ts +10 -1
  100. package/src/tools/BashExecutor.ts +2 -1
  101. package/src/tools/ToolNode.ts +333 -256
  102. package/src/tools/toolOutputReferences.ts +101 -32
  103. package/src/types/llm.ts +10 -2
@@ -10,7 +10,12 @@
10
10
  * Subsequent tool calls can pipe a previous output into their args by
11
11
  * embedding `{{tool<idx>turn<turn>}}` inside any string argument;
12
12
  * {@link ToolOutputReferenceRegistry.resolve} walks the args and
13
- * substitutes the placeholders immediately before invocation.
13
+ * substitutes the placeholders immediately before invocation. Backslashes
14
+ * directly before a placeholder follow the usual escape rule: each pair
15
+ * collapses to one literal backslash, and a remaining single backslash is
16
+ * removed and escapes the placeholder, which then passes through as literal
17
+ * text without a registry lookup. So `\{{tool0turn0}}` is the literal
18
+ * placeholder and `\\{{tool0turn0}}` is a backslash followed by the output.
14
19
  *
15
20
  * The registry stores the *raw, untruncated* tool output so a later
16
21
  * `{{…}}` substitution pipes the full payload into the next tool —
@@ -118,6 +123,7 @@ export type ResolveResult<T> = {
118
123
  * point in time, ignoring any subsequent registrations.
119
124
  */
120
125
  export interface ToolOutputResolveView {
126
+ readonly availableKeys?: readonly string[];
121
127
  resolve<T>(args: T, options?: ResolveOptions): ResolveResult<T>;
122
128
  }
123
129
 
@@ -130,6 +136,8 @@ export interface ToolOutputResolveView {
130
136
  */
131
137
  export type ResolveOptions = {
132
138
  substituteIntentKey?: boolean;
139
+ /** Detached pre-editor input; unchanged string leaves stay literal. */
140
+ previouslyResolved?: Record<string, unknown> | string;
133
141
  };
134
142
 
135
143
  /**
@@ -152,6 +160,11 @@ export type ResolvedArgsByCallId = Map<string, Record<string, unknown>>;
152
160
 
153
161
  const EMPTY_ENTRIES: ReadonlyMap<string, string> = new Map<string, string>();
154
162
 
163
+ const BACKSLASH = 0x5c;
164
+
165
+ /** Keys a snapshot offers as a correction hint for an unknown reference. */
166
+ const AVAILABLE_KEY_HINT_LIMIT = 10;
167
+
155
168
  /**
156
169
  * Per-run state bucket held inside the registry. Each distinct
157
170
  * `run_id` gets its own bucket so overlapping concurrent runs on a
@@ -196,9 +209,11 @@ export class ToolOutputReferenceRegistry {
196
209
  private readonly maxTotalSize: number;
197
210
  private readonly maxActiveRuns: number;
198
211
  /**
199
- * Local stateful matcher used only by `replaceInString`. Kept
200
- * off-module so callers of the exported `TOOL_OUTPUT_REF_PATTERN`
201
- * never see a stale `lastIndex`.
212
+ * Global matcher used only by `replaceInString`. Kept off-module so
213
+ * callers of the exported `TOOL_OUTPUT_REF_PATTERN` never see a stale
214
+ * `lastIndex`. Leading backslashes are counted by hand rather than
215
+ * matched: a `\\*` prefix would backtrack quadratically over a long
216
+ * backslash run that no placeholder follows.
202
217
  */
203
218
  private static readonly PLACEHOLDER_MATCHER = /\{\{(tool\d+turn\d+)\}\}/g;
204
219
 
@@ -378,7 +393,7 @@ export class ToolOutputReferenceRegistry {
378
393
  args: T,
379
394
  options?: ResolveOptions
380
395
  ): ResolveResult<T> {
381
- if (!hasAnyPlaceholder(args)) {
396
+ if (options?.previouslyResolved == null && !hasAnyPlaceholder(args)) {
382
397
  return { resolved: args, unresolved: [] };
383
398
  }
384
399
  const bucket = this.runStates.get(this.keyFor(runId));
@@ -402,6 +417,10 @@ export class ToolOutputReferenceRegistry {
402
417
  ? new Map(bucket.entries)
403
418
  : EMPTY_ENTRIES;
404
419
  return {
420
+ /** Newest registrations: the key a model mistyped is usually recent. */
421
+ get availableKeys(): readonly string[] {
422
+ return [...entries.keys()].slice(-AVAILABLE_KEY_HINT_LIMIT);
423
+ },
405
424
  resolve: <T>(args: T, options?: ResolveOptions): ResolveResult<T> =>
406
425
  this.resolveAgainst(entries, args, options),
407
426
  };
@@ -421,7 +440,10 @@ export class ToolOutputReferenceRegistry {
421
440
  }
422
441
 
423
442
  /** Restore batch inputs without rolling back graph-owned concurrent outputs. */
424
- resumeBatch(runId: string, state: ToolOutputReferenceState): ToolOutputResolveView {
443
+ resumeBatch(
444
+ runId: string,
445
+ state: ToolOutputReferenceState
446
+ ): ToolOutputResolveView {
425
447
  if (!this.runStates.has(runId)) {
426
448
  this.restoreState(runId, state);
427
449
  }
@@ -457,24 +479,26 @@ export class ToolOutputReferenceRegistry {
457
479
  args: T,
458
480
  options?: ResolveOptions
459
481
  ): ResolveResult<T> {
460
- if (!hasAnyPlaceholder(args)) {
482
+ if (options?.previouslyResolved == null && !hasAnyPlaceholder(args)) {
461
483
  return { resolved: args, unresolved: [] };
462
484
  }
463
485
  const exemptIntentKey = options?.substituteIntentKey !== true;
464
486
  const unresolved = new Set<string>();
465
- /**
466
- * Providers may deliver the args OBJECT as a JSON string. A plain
467
- * string-root transform would expand placeholders inside the `intent`
468
- * label too, bypassing the top-level exclusion below — parse, transform
469
- * key-aware, and re-serialize so the label stays verbatim while every
470
- * other field still substitutes. Only taken when an `intent` key is
471
- * actually present; other strings keep the fast raw-string path.
472
- */
473
- if (exemptIntentKey && typeof args === 'string') {
487
+ /** Parse object-shaped provider args before substitution so keys, intent
488
+ * labels and JSON escaping obey the same contract as object inputs. */
489
+ if (typeof args === 'string') {
474
490
  const parsedRoot = parseStringifiedArgsObject(args);
475
- if (parsedRoot != null && INTENT_ARG in parsedRoot) {
491
+ if (parsedRoot != null) {
476
492
  const resolved = JSON.stringify(
477
- this.transform(entries, parsedRoot, unresolved, true)
493
+ this.transform(
494
+ entries,
495
+ parsedRoot,
496
+ unresolved,
497
+ exemptIntentKey,
498
+ typeof options?.previouslyResolved === 'string'
499
+ ? parseStringifiedArgsObject(options.previouslyResolved)
500
+ : options?.previouslyResolved
501
+ )
478
502
  ) as T;
479
503
  return { resolved, unresolved: Array.from(unresolved) };
480
504
  }
@@ -483,7 +507,8 @@ export class ToolOutputReferenceRegistry {
483
507
  entries,
484
508
  args,
485
509
  unresolved,
486
- exemptIntentKey
510
+ exemptIntentKey,
511
+ options?.previouslyResolved
487
512
  ) as T;
488
513
  return { resolved, unresolved: Array.from(unresolved) };
489
514
  }
@@ -492,13 +517,25 @@ export class ToolOutputReferenceRegistry {
492
517
  entries: ReadonlyMap<string, string>,
493
518
  value: unknown,
494
519
  unresolved: Set<string>,
495
- exemptRootIntent = false
520
+ exemptRootIntent = false,
521
+ previouslyResolved?: unknown
496
522
  ): unknown {
497
523
  if (typeof value === 'string') {
524
+ if (value === previouslyResolved) return value;
498
525
  return this.replaceInString(entries, value, unresolved);
499
526
  }
500
527
  if (Array.isArray(value)) {
501
- return value.map((item) => this.transform(entries, item, unresolved));
528
+ return value.map((item, index) =>
529
+ this.transform(
530
+ entries,
531
+ item,
532
+ unresolved,
533
+ false,
534
+ Array.isArray(previouslyResolved)
535
+ ? previouslyResolved[index]
536
+ : undefined
537
+ )
538
+ );
502
539
  }
503
540
  if (value !== null && typeof value === 'object') {
504
541
  const source = value as Record<string, unknown>;
@@ -513,7 +550,16 @@ export class ToolOutputReferenceRegistry {
513
550
  next[key] =
514
551
  exemptRootIntent && key === INTENT_ARG
515
552
  ? item
516
- : this.transform(entries, item, unresolved);
553
+ : this.transform(
554
+ entries,
555
+ item,
556
+ unresolved,
557
+ false,
558
+ previouslyResolved != null &&
559
+ typeof previouslyResolved === 'object'
560
+ ? (previouslyResolved as Record<string, unknown>)[key]
561
+ : undefined
562
+ );
517
563
  }
518
564
  return next;
519
565
  }
@@ -528,17 +574,31 @@ export class ToolOutputReferenceRegistry {
528
574
  if (input.indexOf('{{tool') === -1) {
529
575
  return input;
530
576
  }
531
- return input.replace(
532
- ToolOutputReferenceRegistry.PLACEHOLDER_MATCHER,
533
- (match, key: string) => {
534
- const stored = entries.get(key);
535
- if (stored == null) {
536
- unresolved.add(key);
537
- return match;
538
- }
539
- return stored;
577
+ let output = '';
578
+ let cursor = 0;
579
+ for (const match of input.matchAll(
580
+ ToolOutputReferenceRegistry.PLACEHOLDER_MATCHER
581
+ )) {
582
+ const [placeholder, key] = match;
583
+ let start = match.index;
584
+ while (start > cursor && input.charCodeAt(start - 1) === BACKSLASH) {
585
+ start--;
540
586
  }
541
- );
587
+ const backslashes = match.index - start;
588
+ const replacement =
589
+ backslashes % 2 === 1 ? placeholder : entries.get(key);
590
+ if (replacement == null) {
591
+ /** Left verbatim: the caller rejects the call on any unresolved key. */
592
+ unresolved.add(key);
593
+ continue;
594
+ }
595
+ output +=
596
+ input.slice(cursor, start) +
597
+ '\\'.repeat(backslashes >> 1) +
598
+ replacement;
599
+ cursor = match.index + placeholder.length;
600
+ }
601
+ return cursor === 0 ? input : output + input.slice(cursor);
542
602
  }
543
603
 
544
604
  private evictWithinBucket(bucket: RunStateBucket): void {
@@ -587,6 +647,15 @@ function hasAnyPlaceholder(value: unknown): boolean {
587
647
  return false;
588
648
  }
589
649
 
650
+ const EMPTY_RESOLVED_ARGS: Record<string, unknown> = Object.freeze({});
651
+
652
+ /** Detached editor baseline; reference-free inputs need no retained values. */
653
+ export function snapshotResolvedArgs(
654
+ args: Record<string, unknown>
655
+ ): Record<string, unknown> {
656
+ return hasAnyPlaceholder(args) ? structuredClone(args) : EMPTY_RESOLVED_ARGS;
657
+ }
658
+
590
659
  /**
591
660
  * Annotates `content` with a reference key and/or unresolved-ref
592
661
  * warnings so the LLM sees both alongside the tool output.
package/src/types/llm.ts CHANGED
@@ -74,7 +74,12 @@ export type AnthropicReasoning = {
74
74
  export type GoogleThinkingConfig = {
75
75
  thinkingBudget?: number;
76
76
  includeThoughts?: boolean;
77
- thinkingLevel?: 'THINKING_LEVEL_UNSPECIFIED' | 'LOW' | 'MEDIUM' | 'HIGH';
77
+ thinkingLevel?:
78
+ | 'THINKING_LEVEL_UNSPECIFIED'
79
+ | 'LOW'
80
+ | 'MEDIUM'
81
+ | 'HIGH'
82
+ | 'XHIGH';
78
83
  };
79
84
  /** GPT-5.6 managed-request passthrough fields, shared by the OpenAI and
80
85
  * Azure wrappers that both read them. */
@@ -153,7 +158,10 @@ export type BedrockAnthropicInput = ChatBedrockConverseInput &
153
158
  };
154
159
  export type BedrockConverseClientOptions = BedrockAnthropicInput;
155
160
  export type BedrockAnthropicClientOptions = BedrockAnthropicInput;
156
- export type GoogleClientOptions = GoogleGenerativeAIChatInput &
161
+ export type GoogleClientOptions = Omit<
162
+ GoogleGenerativeAIChatInput,
163
+ 'thinkingConfig'
164
+ > &
157
165
  StreamSmoothingOptions & {
158
166
  customHeaders?: RequestOptions['customHeaders'];
159
167
  thinkingConfig?: GoogleThinkingConfig;