@librechat/agents 3.7.9 → 3.7.10

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.
@@ -344,7 +344,9 @@ export interface JinaRerankerResult {
344
344
 
345
345
  export interface JinaRerankerResponse {
346
346
  model: string;
347
- usage: {
347
+ /** Telemetry only, and absent from some Jina-compatible endpoints — never
348
+ * dereference it on a path that would discard a usable ranking. */
349
+ usage?: {
348
350
  total_tokens: number;
349
351
  };
350
352
  results: JinaRerankerResult[];
@@ -358,12 +360,13 @@ export interface CohereRerankerResult {
358
360
  export interface CohereRerankerResponse {
359
361
  results: CohereRerankerResult[];
360
362
  id: string;
361
- meta: {
362
- api_version: {
363
+ /** Telemetry only; see {@link JinaRerankerResponse.usage}. */
364
+ meta?: {
365
+ api_version?: {
363
366
  version: string;
364
367
  is_experimental: boolean;
365
368
  };
366
- billed_units: {
369
+ billed_units?: {
367
370
  search_units: number;
368
371
  };
369
372
  };
@@ -407,6 +410,96 @@ export interface RagApiRerankResponse {
407
410
  export type SafeSearchLevel = 0 | 1 | 2;
408
411
 
409
412
  export type Logger = WinstonLogger;
413
+
414
+ /** Compact, redacted view of a thrown error, safe to hand to a logger. */
415
+ export interface SafeErrorLog {
416
+ message: string;
417
+ name?: string;
418
+ code?: string;
419
+ status?: number;
420
+ method?: string;
421
+ url?: string;
422
+ responseDataSummary?: string;
423
+ value?: string;
424
+ }
425
+
426
+ /** Why a rerank returned the candidates' original order instead of a ranking. */
427
+ export type RerankFallback =
428
+ | 'no_api_key'
429
+ | 'no_base_url'
430
+ | 'no_token_supplier'
431
+ | 'bad_response'
432
+ | 'invalid_results'
433
+ | 'chunk_error'
434
+ | 'placeholder'
435
+ | 'error';
436
+
437
+ /** One provider query. `results` is the row count that query contributed. */
438
+ export interface SearchObservation {
439
+ provider: string;
440
+ type: string;
441
+ results: number;
442
+ durationMs: number;
443
+ error?: string;
444
+ /** The query rejected rather than reporting failure in its response. Those
445
+ * were logged at error level before they were aggregated, so the summary
446
+ * has to carry the distinction to keep that severity. */
447
+ thrown?: boolean;
448
+ }
449
+
450
+ /** One scraped link. A failure carries `error`; a success carries the sizes
451
+ * the scrape produced, so the summary can report both without a second pass. */
452
+ export interface ScrapeObservation {
453
+ url: string;
454
+ chars?: number;
455
+ highlights?: number;
456
+ error?: string;
457
+ }
458
+
459
+ /** One reranker round trip. A search reranks once per scraped source, so
460
+ * these fold into a single summary rather than logging per source. */
461
+ export interface RerankObservation {
462
+ provider: string;
463
+ chunks: number;
464
+ results: number;
465
+ durationMs: number;
466
+ model?: string;
467
+ /** Provider-reported usage: Jina tokens, Cohere billed search units. */
468
+ units?: number;
469
+ /** Chunks a provider candidate cap dropped before submission. */
470
+ dropped?: number;
471
+ /** Set only when a provider cap reduced the requested result count, so a
472
+ * search returning fewer highlights than configured says why. */
473
+ topK?: number;
474
+ topKLimit?: number;
475
+ reason?: RerankFallback;
476
+ error?: SafeErrorLog;
477
+ }
478
+
479
+ /** Per-rerank state threaded from the start of a call to whichever exit it
480
+ * takes, so every path records exactly one observation. */
481
+ export interface RerankRun {
482
+ metrics: SearchMetrics;
483
+ documents: string[];
484
+ topK: number;
485
+ startedAt: number;
486
+ model?: string;
487
+ units?: number;
488
+ dropped?: number;
489
+ topKLimit?: number;
490
+ }
491
+
492
+ /**
493
+ * Fold-as-you-go counters for one `web_search` call. Recording is O(1) and
494
+ * allocation-free past a bounded reason map; {@link SearchMetrics.flush}
495
+ * emits at most one line per phase that actually ran.
496
+ */
497
+ export interface SearchMetrics {
498
+ recordSearch(observation: SearchObservation): void;
499
+ recordScrape(observation: ScrapeObservation): void;
500
+ recordRerank(observation: RerankObservation): void;
501
+ flush(): void;
502
+ }
410
503
  export interface SearchToolConfig
411
504
  extends SearchConfig,
412
505
  ProcessSourcesConfig,
@@ -702,6 +795,10 @@ export interface FirecrawlScraperConfig extends BaseSearchProviderConfig {
702
795
  changeTrackingOptions?: object;
703
796
  }
704
797
 
798
+ /** Result kind a parallel sub-search covers; `web` is the untyped main
799
+ * search, which every provider serves without a `type` parameter. */
800
+ export type SubSearchType = 'web' | 'images' | 'videos' | 'news';
801
+
705
802
  export type GetSourcesParams = {
706
803
  query: string;
707
804
  date?: DATE_RANGE;
@@ -1038,6 +1135,9 @@ export type ProcessSourcesFields = {
1038
1135
  news: boolean;
1039
1136
  proMode: boolean;
1040
1137
  onGetHighlights: SearchToolConfig['onGetHighlights'];
1138
+ /** Collector owned by the caller; when omitted, one is created and flushed
1139
+ * for this call so a direct `processSources` still summarizes itself. */
1140
+ metrics?: SearchMetrics;
1041
1141
  };
1042
1142
 
1043
1143
  export interface SearchToolSchema {
@@ -2,21 +2,13 @@
2
2
 
3
3
  import { isAxiosError } from 'axios';
4
4
 
5
+ import type { SafeErrorLog } from './types';
5
6
  import type { AxiosError } from 'axios';
6
7
  import type * as t from './types';
7
8
 
8
9
  const LOG_VALUE_MAX_LENGTH = 2048;
9
10
 
10
- export interface SafeErrorLog {
11
- message: string;
12
- name?: string;
13
- code?: string;
14
- status?: number;
15
- method?: string;
16
- url?: string;
17
- responseDataSummary?: string;
18
- value?: string;
19
- }
11
+ export type { SafeErrorLog } from './types';
20
12
 
21
13
  /**
22
14
  * Singleton instance of the default logger