@librechat/agents 4.2.5 → 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.
- package/dist/cjs/harness/identity.cjs +26 -0
- package/dist/cjs/harness/identity.cjs.map +1 -0
- package/dist/cjs/harness/index.cjs +3 -15
- package/dist/cjs/harness/index.cjs.map +1 -1
- package/dist/cjs/harness/providerText.cjs +79 -0
- package/dist/cjs/harness/providerText.cjs.map +1 -0
- package/dist/cjs/llm/contextPressureMeter.cjs +1 -1
- package/dist/cjs/llm/contextPressureMeter.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +21 -12
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/streamMetadata.cjs +4 -1
- package/dist/cjs/llm/openai/streamMetadata.cjs.map +1 -1
- package/dist/cjs/main.cjs +5 -0
- package/dist/cjs/stream.cjs +4 -1
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/tools/BashExecutor.cjs +2 -1
- package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +141 -94
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/toolOutputReferences.cjs +39 -17
- package/dist/cjs/tools/toolOutputReferences.cjs.map +1 -1
- package/dist/esm/harness/identity.mjs +24 -0
- package/dist/esm/harness/identity.mjs.map +1 -0
- package/dist/esm/harness/index.mjs +3 -15
- package/dist/esm/harness/index.mjs.map +1 -1
- package/dist/esm/harness/providerText.mjs +78 -0
- package/dist/esm/harness/providerText.mjs.map +1 -0
- package/dist/esm/llm/contextPressureMeter.mjs +1 -1
- package/dist/esm/llm/contextPressureMeter.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +21 -12
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/streamMetadata.mjs +4 -1
- package/dist/esm/llm/openai/streamMetadata.mjs.map +1 -1
- package/dist/esm/main.mjs +3 -1
- package/dist/esm/stream.mjs +4 -1
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/tools/BashExecutor.mjs +2 -1
- package/dist/esm/tools/BashExecutor.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +142 -95
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/toolOutputReferences.mjs +39 -18
- package/dist/esm/tools/toolOutputReferences.mjs.map +1 -1
- package/dist/types/harness/identity.d.ts +14 -0
- package/dist/types/harness/index.d.ts +5 -9
- package/dist/types/harness/providerText.d.ts +32 -0
- package/dist/types/llm/openai/streamMetadata.d.ts +3 -3
- package/dist/types/tools/ToolNode.d.ts +7 -7
- package/dist/types/tools/toolOutputReferences.d.ts +16 -4
- package/package.json +1 -1
- package/src/harness/identity.ts +34 -0
- package/src/harness/index.ts +15 -23
- package/src/harness/providerText.ts +128 -0
- package/src/llm/contextPressureMeter.ts +2 -4
- package/src/llm/openai/index.ts +60 -20
- package/src/llm/openai/streamMetadata.ts +14 -3
- package/src/stream.ts +10 -1
- package/src/tools/BashExecutor.ts +2 -1
- package/src/tools/ToolNode.ts +333 -256
- package/src/tools/toolOutputReferences.ts +101 -32
|
@@ -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
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
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(
|
|
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
|
-
*
|
|
467
|
-
|
|
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
|
|
491
|
+
if (parsedRoot != null) {
|
|
476
492
|
const resolved = JSON.stringify(
|
|
477
|
-
this.transform(
|
|
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) =>
|
|
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(
|
|
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
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
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.
|