@librechat/agents 4.0.6 → 4.1.1

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 (180) hide show
  1. package/dist/cjs/agents/AgentContext.cjs +6 -4
  2. package/dist/cjs/agents/AgentContext.cjs.map +1 -1
  3. package/dist/cjs/decisions/breaker.cjs +59 -0
  4. package/dist/cjs/decisions/breaker.cjs.map +1 -0
  5. package/dist/cjs/decisions/core.cjs +44 -0
  6. package/dist/cjs/decisions/dialect.cjs +65 -12
  7. package/dist/cjs/decisions/dialect.cjs.map +1 -1
  8. package/dist/cjs/decisions/hook.cjs +19 -0
  9. package/dist/cjs/decisions/hook.cjs.map +1 -0
  10. package/dist/cjs/decisions/http.cjs +2 -1
  11. package/dist/cjs/decisions/http.cjs.map +1 -1
  12. package/dist/cjs/decisions/index.cjs +6 -0
  13. package/dist/cjs/decisions/node.cjs +315 -0
  14. package/dist/cjs/decisions/node.cjs.map +1 -0
  15. package/dist/cjs/decisions/probe.cjs +56 -0
  16. package/dist/cjs/decisions/probe.cjs.map +1 -0
  17. package/dist/cjs/decisions/redact.cjs +109 -0
  18. package/dist/cjs/decisions/redact.cjs.map +1 -0
  19. package/dist/cjs/decisions/structuredChat.cjs +2 -3
  20. package/dist/cjs/decisions/structuredChat.cjs.map +1 -1
  21. package/dist/cjs/decisions/transport.cjs +56 -23
  22. package/dist/cjs/decisions/transport.cjs.map +1 -1
  23. package/dist/cjs/decisions/types.cjs +2 -0
  24. package/dist/cjs/decisions/types.cjs.map +1 -1
  25. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +1 -0
  26. package/dist/cjs/llm/bedrock/cachePoints.cjs +20 -0
  27. package/dist/cjs/llm/bedrock/cachePoints.cjs.map +1 -1
  28. package/dist/cjs/llm/bedrock/index.cjs +8 -5
  29. package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
  30. package/dist/cjs/main.cjs +45 -0
  31. package/dist/cjs/rerank/bm25.cjs +110 -0
  32. package/dist/cjs/rerank/bm25.cjs.map +1 -0
  33. package/dist/cjs/rerank/cache.cjs +50 -0
  34. package/dist/cjs/rerank/cache.cjs.map +1 -0
  35. package/dist/cjs/rerank/core.cjs +29 -0
  36. package/dist/cjs/rerank/crossEncoder.cjs +172 -0
  37. package/dist/cjs/rerank/crossEncoder.cjs.map +1 -0
  38. package/dist/cjs/rerank/fallback.cjs +280 -0
  39. package/dist/cjs/rerank/fallback.cjs.map +1 -0
  40. package/dist/cjs/rerank/index.cjs +8 -0
  41. package/dist/cjs/rerank/outcome.cjs +382 -0
  42. package/dist/cjs/rerank/outcome.cjs.map +1 -0
  43. package/dist/cjs/rerank/pin.cjs +74 -0
  44. package/dist/cjs/rerank/pin.cjs.map +1 -0
  45. package/dist/cjs/rerank/semaphore.cjs +38 -0
  46. package/dist/cjs/rerank/semaphore.cjs.map +1 -0
  47. package/dist/cjs/rerank/systemone.cjs +476 -50
  48. package/dist/cjs/rerank/systemone.cjs.map +1 -1
  49. package/dist/cjs/session/AgentSession.cjs +1 -1
  50. package/dist/cjs/session/AgentSession.cjs.map +1 -1
  51. package/dist/cjs/tools/local/LocalCodingTools.cjs +67 -19
  52. package/dist/cjs/tools/local/LocalCodingTools.cjs.map +1 -1
  53. package/dist/cjs/tools/local/LocalExecutionTools.cjs +12 -1
  54. package/dist/cjs/tools/local/LocalExecutionTools.cjs.map +1 -1
  55. package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs +63 -16
  56. package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs.map +1 -1
  57. package/dist/cjs/tools/local/toolResultCaps.cjs +32 -0
  58. package/dist/cjs/tools/local/toolResultCaps.cjs.map +1 -0
  59. package/dist/cjs/utils/schema.cjs +19 -0
  60. package/dist/cjs/utils/schema.cjs.map +1 -1
  61. package/dist/esm/agents/AgentContext.mjs +7 -5
  62. package/dist/esm/agents/AgentContext.mjs.map +1 -1
  63. package/dist/esm/decisions/breaker.mjs +56 -0
  64. package/dist/esm/decisions/breaker.mjs.map +1 -0
  65. package/dist/esm/decisions/core.mjs +11 -0
  66. package/dist/esm/decisions/dialect.mjs +65 -12
  67. package/dist/esm/decisions/dialect.mjs.map +1 -1
  68. package/dist/esm/decisions/hook.mjs +19 -0
  69. package/dist/esm/decisions/hook.mjs.map +1 -0
  70. package/dist/esm/decisions/http.mjs +2 -1
  71. package/dist/esm/decisions/http.mjs.map +1 -1
  72. package/dist/esm/decisions/index.mjs +6 -0
  73. package/dist/esm/decisions/node.mjs +313 -0
  74. package/dist/esm/decisions/node.mjs.map +1 -0
  75. package/dist/esm/decisions/probe.mjs +54 -0
  76. package/dist/esm/decisions/probe.mjs.map +1 -0
  77. package/dist/esm/decisions/redact.mjs +108 -0
  78. package/dist/esm/decisions/redact.mjs.map +1 -0
  79. package/dist/esm/decisions/structuredChat.mjs +2 -3
  80. package/dist/esm/decisions/structuredChat.mjs.map +1 -1
  81. package/dist/esm/decisions/transport.mjs +56 -23
  82. package/dist/esm/decisions/transport.mjs.map +1 -1
  83. package/dist/esm/decisions/types.mjs +2 -0
  84. package/dist/esm/decisions/types.mjs.map +1 -1
  85. package/dist/esm/llm/anthropic/utils/message_inputs.mjs +1 -1
  86. package/dist/esm/llm/bedrock/cachePoints.mjs +20 -1
  87. package/dist/esm/llm/bedrock/cachePoints.mjs.map +1 -1
  88. package/dist/esm/llm/bedrock/index.mjs +7 -4
  89. package/dist/esm/llm/bedrock/index.mjs.map +1 -1
  90. package/dist/esm/main.mjs +15 -3
  91. package/dist/esm/rerank/bm25.mjs +108 -0
  92. package/dist/esm/rerank/bm25.mjs.map +1 -0
  93. package/dist/esm/rerank/cache.mjs +50 -0
  94. package/dist/esm/rerank/cache.mjs.map +1 -0
  95. package/dist/esm/rerank/core.mjs +9 -0
  96. package/dist/esm/rerank/crossEncoder.mjs +172 -0
  97. package/dist/esm/rerank/crossEncoder.mjs.map +1 -0
  98. package/dist/esm/rerank/fallback.mjs +278 -0
  99. package/dist/esm/rerank/fallback.mjs.map +1 -0
  100. package/dist/esm/rerank/index.mjs +8 -0
  101. package/dist/esm/rerank/outcome.mjs +360 -0
  102. package/dist/esm/rerank/outcome.mjs.map +1 -0
  103. package/dist/esm/rerank/pin.mjs +73 -0
  104. package/dist/esm/rerank/pin.mjs.map +1 -0
  105. package/dist/esm/rerank/semaphore.mjs +38 -0
  106. package/dist/esm/rerank/semaphore.mjs.map +1 -0
  107. package/dist/esm/rerank/systemone.mjs +476 -50
  108. package/dist/esm/rerank/systemone.mjs.map +1 -1
  109. package/dist/esm/session/AgentSession.mjs +1 -1
  110. package/dist/esm/session/AgentSession.mjs.map +1 -1
  111. package/dist/esm/tools/local/LocalCodingTools.mjs +67 -19
  112. package/dist/esm/tools/local/LocalCodingTools.mjs.map +1 -1
  113. package/dist/esm/tools/local/LocalExecutionTools.mjs +12 -1
  114. package/dist/esm/tools/local/LocalExecutionTools.mjs.map +1 -1
  115. package/dist/esm/tools/local/resolveLocalExecutionTools.mjs +63 -17
  116. package/dist/esm/tools/local/resolveLocalExecutionTools.mjs.map +1 -1
  117. package/dist/esm/tools/local/toolResultCaps.mjs +31 -0
  118. package/dist/esm/tools/local/toolResultCaps.mjs.map +1 -0
  119. package/dist/esm/utils/schema.mjs +19 -0
  120. package/dist/esm/utils/schema.mjs.map +1 -1
  121. package/dist/types/decisions/breaker.d.ts +37 -0
  122. package/dist/types/decisions/core.d.ts +19 -0
  123. package/dist/types/decisions/hook.d.ts +9 -0
  124. package/dist/types/decisions/index.d.ts +3 -8
  125. package/dist/types/decisions/node.d.ts +90 -0
  126. package/dist/types/decisions/probe.d.ts +37 -0
  127. package/dist/types/decisions/redact.d.ts +22 -0
  128. package/dist/types/decisions/structuredChat.d.ts +1 -0
  129. package/dist/types/decisions/transport.d.ts +16 -3
  130. package/dist/types/decisions/types.d.ts +43 -4
  131. package/dist/types/llm/bedrock/cachePoints.d.ts +7 -0
  132. package/dist/types/llm/bedrock/index.d.ts +2 -1
  133. package/dist/types/rerank/bm25.d.ts +46 -0
  134. package/dist/types/rerank/cache.d.ts +40 -0
  135. package/dist/types/rerank/core.d.ts +24 -0
  136. package/dist/types/rerank/crossEncoder.d.ts +48 -0
  137. package/dist/types/rerank/fallback.d.ts +67 -0
  138. package/dist/types/rerank/index.d.ts +1 -3
  139. package/dist/types/rerank/outcome.d.ts +144 -0
  140. package/dist/types/rerank/pin.d.ts +48 -0
  141. package/dist/types/rerank/semaphore.d.ts +9 -0
  142. package/dist/types/rerank/systemone.d.ts +51 -5
  143. package/dist/types/rerank/types.d.ts +116 -1
  144. package/dist/types/tools/local/resolveLocalExecutionTools.d.ts +6 -0
  145. package/dist/types/tools/local/toolResultCaps.d.ts +16 -0
  146. package/dist/types/types/tools.d.ts +16 -0
  147. package/package.json +30 -2
  148. package/src/agents/AgentContext.ts +33 -4
  149. package/src/decisions/breaker.ts +110 -0
  150. package/src/decisions/core.ts +23 -0
  151. package/src/decisions/dialect.ts +134 -20
  152. package/src/decisions/hook.ts +32 -0
  153. package/src/decisions/http.ts +4 -1
  154. package/src/decisions/index.ts +3 -12
  155. package/src/decisions/node.ts +671 -0
  156. package/src/decisions/probe.ts +114 -0
  157. package/src/decisions/redact.ts +222 -0
  158. package/src/decisions/structuredChat.ts +6 -8
  159. package/src/decisions/transport.ts +104 -22
  160. package/src/decisions/types.ts +46 -5
  161. package/src/llm/bedrock/cachePoints.ts +47 -0
  162. package/src/llm/bedrock/index.ts +35 -13
  163. package/src/rerank/bm25.ts +190 -0
  164. package/src/rerank/cache.ts +103 -0
  165. package/src/rerank/core.ts +47 -0
  166. package/src/rerank/crossEncoder.ts +289 -0
  167. package/src/rerank/fallback.ts +625 -0
  168. package/src/rerank/index.ts +1 -3
  169. package/src/rerank/outcome.ts +767 -0
  170. package/src/rerank/pin.ts +157 -0
  171. package/src/rerank/semaphore.ts +47 -0
  172. package/src/rerank/systemone.ts +914 -88
  173. package/src/rerank/types.ts +143 -1
  174. package/src/session/AgentSession.ts +3 -1
  175. package/src/tools/local/LocalCodingTools.ts +139 -19
  176. package/src/tools/local/LocalExecutionTools.ts +21 -1
  177. package/src/tools/local/resolveLocalExecutionTools.ts +116 -11
  178. package/src/tools/local/toolResultCaps.ts +60 -0
  179. package/src/types/tools.ts +16 -0
  180. package/src/utils/schema.ts +29 -1
@@ -1,9 +1,28 @@
1
1
  import { zodToJsonSchema } from "zod-to-json-schema";
2
+ import { isZodSchemaV4 } from "@langchain/core/utils/types";
3
+ import { globalRegistry } from "zod/v4/core";
4
+ import { globalRegistry as globalRegistry$1, registry, toJSONSchema } from "zod-v4";
2
5
  //#region src/utils/schema.ts
6
+ const earlyMetadata = globalRegistry;
7
+ const schemaMetadata = registry();
8
+ schemaMetadata.get = (schema) => {
9
+ const annotated = schema;
10
+ return typeof annotated.meta === "function" ? annotated.meta() : globalRegistry$1.get(schema) ?? earlyMetadata.get(schema);
11
+ };
3
12
  function isZodSchema(schema) {
4
13
  return schema != null && typeof schema === "object" && "_def" in schema;
5
14
  }
6
15
  function toJsonSchema(schema, name, description) {
16
+ if (isZodSchemaV4(schema)) return {
17
+ ...toJSONSchema(schema, {
18
+ target: "draft-7",
19
+ io: "input",
20
+ unrepresentable: "any",
21
+ metadata: schemaMetadata
22
+ }),
23
+ ...name != null && name !== "" ? { title: name } : {},
24
+ ...description != null && description !== "" ? { description } : {}
25
+ };
7
26
  if (isZodSchema(schema)) return zodToJsonSchema(description != null && description !== "" ? schema.describe(description) : schema, name ?? "");
8
27
  return schema;
9
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"schema.mjs","names":["zodSchema"],"sources":["../../../src/utils/schema.ts"],"mappings":";;AAKA,SAAgB,YAAY,QAAuC;CACjE,OACE,UAAU,QAAQ,OAAO,WAAW,YAAY,UAAW;AAE/D;AAMA,SAAgB,aACd,QACA,MACA,aACyB;CACzB,IAAI,YAAY,MAAM,GAQpB,OAAO,gBAHL,eAAe,QAAQ,gBAAgB,KACnCA,OAAU,SAAS,WAAW,IAC9B,QAGJ,QAAQ,EACV;CAEF,OAAO;AACT"}
1
+ {"version":3,"file":"schema.mjs","names":["earlyRegistry","globalRegistry","zodSchema"],"sources":["../../../src/utils/schema.ts"],"mappings":";;;;;AASA,MAAM,gBAAgBA;AAGtB,MAAM,iBAAiB,SAAqB;AAC5C,eAAe,OAAO,WAAmC;CACvD,MAAM,YAAY;CAClB,OAAO,OAAO,UAAU,SAAS,aAC7B,UAAU,KAAK,IACdC,iBAAe,IAAI,MAAM,KAAK,cAAc,IAAI,MAAM;AAC7D;AAGA,SAAgB,YAAY,QAAuC;CACjE,OACE,UAAU,QAAQ,OAAO,WAAW,YAAY,UAAW;AAE/D;AAMA,SAAgB,aACd,QACA,MACA,aACyB;CACzB,IAAI,cAAc,MAAM,GACtB,OAAO;EACL,GAAG,aAAa,QAAoB;GAClC,QAAQ;GACR,IAAI;GACJ,iBAAiB;GACjB,UAAU;EACZ,CAAC;EACD,GAAI,QAAQ,QAAQ,SAAS,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;EACrD,GAAI,eAAe,QAAQ,gBAAgB,KAAK,EAAE,YAAY,IAAI,CAAC;CACrE;CAEF,IAAI,YAAY,MAAM,GAQpB,OAAO,gBAHL,eAAe,QAAQ,gBAAgB,KACnCC,OAAU,SAAS,WAAW,IAC9B,QAGJ,QAAQ,EACV;CAEF,OAAO;AACT"}
@@ -0,0 +1,37 @@
1
+ import type { DecisionModel, DecisionFailure } from './types';
2
+ import { DecisionError } from './types';
3
+ /** Failures that belong to the credential, not the request: the next request would be refused the same way. */
4
+ export declare const FATAL_DECISION_FAILURES: ReadonlySet<DecisionFailure>;
5
+ export declare function isFatalDecisionError(error: unknown): error is DecisionError;
6
+ /** A fuse: `open` once `trip` has recorded an error, until `reset`. */
7
+ export interface DecisionBreaker {
8
+ readonly open: boolean;
9
+ /** The first error that tripped the breaker, or `null` while it is closed. */
10
+ readonly error: DecisionError | null;
11
+ /** Counts resets; a call captures it before its request so a stale failure cannot reopen a reset breaker. */
12
+ readonly generation: number;
13
+ /**
14
+ * Records `error` unless the breaker is already open; the first error wins.
15
+ * With `generation`, records it only if no `reset` happened since that
16
+ * generation was read.
17
+ */
18
+ trip(error: DecisionError, generation?: number): void;
19
+ reset(): void;
20
+ }
21
+ export interface BreakerDecisionModel extends DecisionModel {
22
+ readonly breaker: DecisionBreaker;
23
+ }
24
+ export declare function createBreaker(): DecisionBreaker;
25
+ /**
26
+ * The model, fused: after one `unauthorized` or `quota` failure every later
27
+ * call rejects at once, without a request, with the same failure, status, and
28
+ * `circuitOpen: true`, until `breaker.reset()`. Rate limits, server errors,
29
+ * timeouts, and network failures never trip it; the transport retries those.
30
+ * A fatal failure from a call that started before a `reset()` does not reopen
31
+ * it; a minter that shares one run between calls must not let a call made
32
+ * after a reset join a run from before it or reuse a token such a run minted
33
+ * (`commandToken` takes the breaker for this). Share one breaker between
34
+ * models that share a credential. A refusal sends nothing and reports no
35
+ * request; `reportsRequests` is kept.
36
+ */
37
+ export declare function withBreaker(model: DecisionModel, breaker?: DecisionBreaker): BreakerDecisionModel;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Light `@librechat/agents/decisions` entry: the System One HTTP decision
3
+ * stack with no LangChain or other third-party runtime import. The
4
+ * structured-chat adapter stays on the root entry because it binds a
5
+ * LangChain chat model.
6
+ */
7
+ export * from './types';
8
+ export * from './questions';
9
+ export * from './presets';
10
+ export { createHttpDecisionModel, parseEnvelope, HTTP_PROVIDER_ID, } from './http';
11
+ export type { HttpDecisionModelOptions } from './http';
12
+ export { toWireQuestion, readAnswer } from './dialect';
13
+ export { createTransport, failureForStatus, retryAfterMs } from './transport';
14
+ export type { DecisionFetch, Transport, TransportOptions } from './transport';
15
+ export { withDecisionDeadline } from './deadline';
16
+ export type { AwaitWithinDeadline } from './deadline';
17
+ export * from './breaker';
18
+ export * from './probe';
19
+ export { redact } from './redact';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Calls a caller-supplied hook whose failure must not reach the caller's
3
+ * work: a synchronous throw is dropped, and so is the rejection of a returned
4
+ * promise, which a `void`-typed hook may still produce (TypeScript accepts an
5
+ * `async` function there) and which would otherwise be unhandled. Returns the
6
+ * hook's synchronous result, or `undefined` when it threw or returned a
7
+ * promise; nothing waits for that promise.
8
+ */
9
+ export declare function callHook(hook: () => unknown): unknown;
@@ -1,10 +1,5 @@
1
- export * from './types';
2
- export * from './questions';
3
- export * from './presets';
4
- export { createHttpDecisionModel, parseEnvelope, HTTP_PROVIDER_ID, } from './http';
1
+ export * from './core';
5
2
  export { createStructuredChatDecisionModel } from './structuredChat';
6
- export type { HttpDecisionModelOptions } from './http';
7
3
  export type { StructuredChatDecisionModelOptions } from './structuredChat';
8
- export { toWireQuestion, readAnswer } from './dialect';
9
- export { createTransport } from './transport';
10
- export type { DecisionFetch, Transport, TransportOptions } from './transport';
4
+ export { commandToken, COMMAND_TOKEN_PROVIDER } from './node';
5
+ export type { CommandTokenOptions } from './node';
@@ -0,0 +1,90 @@
1
+ import type { DecisionTokenMinter } from './types';
2
+ import type { DecisionBreaker } from './breaker';
3
+ export declare const COMMAND_TOKEN_PROVIDER = "command";
4
+ export interface CommandTokenOptions {
5
+ /**
6
+ * How long a minted token is reused without running the command again,
7
+ * counted from when the command finished; `0` mints on every call. Leave
8
+ * headroom under the issuer's lifetime for the command's own runtime.
9
+ */
10
+ ttlMs?: number;
11
+ /** Bounds one run of the command. */
12
+ timeoutMs?: number;
13
+ /**
14
+ * How long a killed run gets to exit on `SIGTERM` before it is sent
15
+ * `SIGKILL`, so a command that traps or ignores `SIGTERM` cannot outlive
16
+ * its run; `0` escalates at once. Defaults to two seconds.
17
+ */
18
+ killGraceMs?: number;
19
+ /**
20
+ * The exit statuses that mean the credential was refused. A run that exits
21
+ * with any other non-zero status is a `network` failure, which the
22
+ * transport retries and which never trips a breaker, so a token CLI that
23
+ * exits 7 when its auth server is unreachable cannot open the breaker until
24
+ * a manual reset. By default every non-zero status outside 129–192 is a
25
+ * refusal.
26
+ */
27
+ refusalExitCodes?: ReadonlyArray<number>;
28
+ /**
29
+ * The breaker this credential's model is fused with. Neither a run that
30
+ * started before `breaker.reset()` nor a token it minted, cached or still in
31
+ * flight, serves callers that arrive after it, so the operator's fix is
32
+ * tested by a fresh run instead of failing on stale evidence and reopening
33
+ * the breaker.
34
+ */
35
+ breaker?: Pick<DecisionBreaker, 'generation'>;
36
+ }
37
+ /**
38
+ * A credential minted by a shell command that prints a short-lived bearer
39
+ * token (for example `dataplanectl chai auth token`); the last non-empty line
40
+ * of stdout is the token, and the command reads no stdin. The token is reused
41
+ * for `ttlMs` (default 50 minutes) after the run that minted it finishes,
42
+ * concurrent calls share one run of the command, and a `refresh` (the
43
+ * transport asks after a 401) runs it again unless the token it `refused` has
44
+ * already been replaced, in which case the newer token (or the run minting
45
+ * it) is shared instead. Given the model's `breaker`, a call made after
46
+ * `breaker.reset()` never joins a run that started before it.
47
+ *
48
+ * A run ends when its shell exits: a process the command leaves behind
49
+ * holding stdout or stderr gets 100 ms to let go, then the run settles from
50
+ * what it printed and that process is left running, unkilled.
51
+ *
52
+ * A caller whose `signal` aborts rejects at once with `aborted`; the run is
53
+ * killed when every caller sharing it has aborted, and the next call starts a
54
+ * fresh one. A run that exits non-zero or prints nothing rejects with an
55
+ * `unauthorized` `DecisionError`, unless `refusalExitCodes` is given and does
56
+ * not list its status, which makes it `network`; a run killed at `timeoutMs`
57
+ * rejects with `timeout`, and a spawn failure, output overflow, or kill from
58
+ * outside with `network`, so a slow command or one that cannot start never
59
+ * trips a breaker. Off Windows an exit status of 129–192 is how a shell
60
+ * reports a command it forked being killed by a signal (137 for `SIGKILL`),
61
+ * so it is a kill, not a refusal; a pipeline such as `cmd | tail -1` hides a
62
+ * killed `cmd` behind a clean exit with no output, which reads as
63
+ * `unauthorized`, so keep the token command last in a pipeline. A kill sends
64
+ * `SIGTERM`, then `SIGKILL` once `killGraceMs` passes with the run still
65
+ * alive, so a killed run overlaps the next one for at most that grace; the
66
+ * escalation is dropped as soon as nothing it would reach is left. Off
67
+ * Windows a kill reaches the command's whole process group; on Windows it
68
+ * ends only the shell, not the command the shell launched.
69
+ *
70
+ * Off Windows the command runs in its own session, with no controlling
71
+ * terminal, so a signal sent to the host's process group (a terminal's
72
+ * Ctrl-C) does not reach it. When the host process exits, each run still
73
+ * going is sent `SIGKILL`; a host killed by a signal it does not handle never
74
+ * reaches its `exit` event, so it leaves such a run going.
75
+ *
76
+ * The message carries the exit status and a redacted stderr excerpt, never
77
+ * a line of stdout, the command or any word of it (split at whitespace,
78
+ * quotes, `=`, braces, commas, and the shell operators `;`, `&`, `|`, `(`,
79
+ * `)`, `<`, and `>`), or any of the last eight tokens it minted
80
+ * or was told were refused, cached or not, whatever their length, including a
81
+ * refused token whose refresh failed. The excerpt reads only the start of
82
+ * stderr, so formatting it stays cheap whatever the command printed. When the
83
+ * shell may pass the program an argument built from text the command does
84
+ * not show, such as a variable, command output, or a decoded escape (off
85
+ * Windows, a backslash escape or a `$` or backtick expansion outside single
86
+ * quotes; on Windows, `%`, `^`, or `\"`), stderr is withheld instead.
87
+ * Pathname (`*`, `?`, `[`) and tilde expansion do not withhold it: they
88
+ * substitute existing paths, which can reach the excerpt.
89
+ */
90
+ export declare function commandToken(command: string, options?: CommandTokenOptions): DecisionTokenMinter;
@@ -0,0 +1,37 @@
1
+ import type { DecisionModel, DecisionFailure, DecisionRequest } from './types';
2
+ /** How long a probe without `timeoutMs` waits for a model that never settles. */
3
+ export declare const PROBE_MAX_WAIT_MS = 60000;
4
+ export type DecisionProbe = {
5
+ ok: true;
6
+ model: string;
7
+ } | {
8
+ ok: false;
9
+ failure: DecisionFailure;
10
+ status?: number;
11
+ circuitOpen: boolean;
12
+ /** Redacted, whitespace-collapsed, and truncated; safe for a log line or a status row. */
13
+ detail: string;
14
+ };
15
+ export interface DecisionProbeOptions {
16
+ /**
17
+ * Passed to the model and enforced around its call, so a model that ignores
18
+ * it still settles; allow for a slow first token mint. Without it the model
19
+ * keeps its own timeout and the wait is bounded at `PROBE_MAX_WAIT_MS`.
20
+ */
21
+ timeoutMs?: number;
22
+ signal?: AbortSignal;
23
+ /** Credentials the failure detail must never contain. */
24
+ secrets?: ReadonlyArray<string | null | undefined>;
25
+ }
26
+ export type DecisionProbeRequest = Pick<DecisionRequest, 'state' | 'questions' | 'label'>;
27
+ /** One yes/no question a host answers in a few tokens; the answer itself is irrelevant. */
28
+ export declare function probeRequest(): DecisionProbeRequest;
29
+ /**
30
+ * Can this model answer right now? Asks one tiny boolean question and never
31
+ * throws, and settles by its deadline or the caller's abort even when the
32
+ * model ignores both: any reply is `ok`, and any failure, including a non-SDK
33
+ * exception (read as `network`), is returned with a redacted detail. Through
34
+ * `withBreaker`, a fatal failure trips the breaker and an open breaker answers
35
+ * without a request.
36
+ */
37
+ export declare function probe(model: DecisionModel, options?: DecisionProbeOptions): Promise<DecisionProbe>;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Removes credentials from text bound for a log line or a status row: every
3
+ * listed secret verbatim, plus anything shaped like a bearer value, a JWT, or
4
+ * a long opaque token. Every recognizer reads the original text and the
5
+ * union of their matches is replaced at once, so a listed secret that
6
+ * overlaps a `Bearer` keyword or splits a long token cannot hide a credential
7
+ * from the shape checks. Unlisted short secrets are not recognizable by
8
+ * shape, so pass every credential the text could contain. Memory stays
9
+ * proportional to the text however often a secret repeats in it; time grows
10
+ * with the text times the number of distinct secrets.
11
+ */
12
+ export declare function redact(text: string, secrets?: ReadonlyArray<string | null | undefined>): string;
13
+ /**
14
+ * The first `limit` characters of `text` redacted, with whitespace
15
+ * collapsed. Only the first 4096 characters after collapsing, drawn from at
16
+ * most the first 16384 of the text, are read, so the cost stays bounded
17
+ * however long the text and however many secrets there are. When the text runs past that window, its tail is redacted as far
18
+ * back as the longest listed secret could reach and through any token-shaped
19
+ * run the cut splits, so a credential the window cuts off cannot show its
20
+ * first characters.
21
+ */
22
+ export declare function redactExcerpt(text: string, secrets: ReadonlyArray<string | null | undefined>, limit: number): string;
@@ -11,6 +11,7 @@ export interface StructuredChatDecisionModelOptions {
11
11
  method: DecisionOutputMethod;
12
12
  timeoutMs?: number;
13
13
  maxQuestions?: number;
14
+ /** Called after a valid decision. Not awaited; a throw or a rejected promise is ignored. */
14
15
  onAnswered?: (label: string, ms: number) => void;
15
16
  }
16
17
  /** Strict provider schema or strict tool calling, without an agent loop or fabricated probabilities. */
@@ -16,14 +16,27 @@ export interface TransportOptions {
16
16
  maxRetries?: number;
17
17
  fetch?: DecisionFetch;
18
18
  sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
19
- /** Called only after the response parses, with no state, answers, or credentials. */
19
+ /**
20
+ * Called only after the response parses, with no state, answers, or
21
+ * credentials. Not awaited; a throw or a rejected promise is ignored.
22
+ */
20
23
  onAnswered?: (label: string, ms: number) => void;
21
24
  }
25
+ /**
26
+ * `onRequest` is called once per HTTP request, just before it is sent:
27
+ * retries and every re-send after a 401 included. `onResponse` is called once
28
+ * per such request that ended before the deadline or the caller's abort, with
29
+ * its HTTP status (after a successful body is read in full) or `null` when the
30
+ * fetch failed or a successful body could not be read, and a reply's
31
+ * `Retry-After` in milliseconds when it was not OK and sent one; a request
32
+ * interrupted in flight gets none. Neither is awaited; a throw or a rejected
33
+ * promise is ignored.
34
+ */
22
35
  export type Transport = <T>(prepare: () => {
23
36
  payload: string;
24
37
  parse: (body: string) => T;
25
- }, signal: AbortSignal | undefined, label: string, timeoutOverrideMs?: number) => Promise<T>;
26
- export declare function failureForStatus(status: number): 'unauthorized' | 'rate_limited' | 'server_error' | 'bad_request';
38
+ }, signal: AbortSignal | undefined, label: string, timeoutOverrideMs?: number, onRequest?: () => void, onResponse?: (status: number | null, retryAfterMs?: number) => void) => Promise<T>;
39
+ export declare function failureForStatus(status: number): 'unauthorized' | 'quota' | 'rate_limited' | 'server_error' | 'bad_request';
27
40
  export declare function retryAfterMs(header: string | null): number | undefined;
28
41
  /** One immutable transport; every call owns its signal, deadline, and credentials. */
29
42
  export declare function createTransport(options: TransportOptions): Transport;
@@ -67,6 +67,25 @@ export interface DecisionRequest {
67
67
  label?: string;
68
68
  /** Overrides the provider's timeout for this request alone. */
69
69
  timeoutMs?: number;
70
+ /**
71
+ * Called once per request the model sends, just before it goes out, so a
72
+ * caller can count retries and every re-send after a 401. The HTTP
73
+ * decision model calls it; a model that does not report requests leaves the
74
+ * caller to count one per `decide()`. Not awaited; a throw is ignored.
75
+ */
76
+ onRequest?: () => void;
77
+ /**
78
+ * Called once per request `onRequest` announced that ended before the
79
+ * deadline or the caller's abort: with the HTTP status once the host
80
+ * replied (a successful reply's body read in full), or `null` when the
81
+ * request failed without a reply or a successful reply's body could not be
82
+ * read, and for a reply that was not OK its
83
+ * `Retry-After` in milliseconds when it sent one. A request still in
84
+ * flight when the call is interrupted gets none, so the announced requests
85
+ * without one are the ones the host may still be working on. Not awaited;
86
+ * a throw is ignored.
87
+ */
88
+ onResponse?: (status: number | null, retryAfterMs?: number) => void;
70
89
  }
71
90
  export interface DecisionResult {
72
91
  model: string;
@@ -77,14 +96,29 @@ export interface DecisionResult {
77
96
  export interface DecisionModel {
78
97
  readonly id: string;
79
98
  readonly model: string;
99
+ /**
100
+ * True when `decide` reports every request it sends through `onRequest`
101
+ * and every one that ends through `onResponse`, as the HTTP decision model
102
+ * does, so a caller can count what was really sent: a `decide` that fails
103
+ * before its first `onRequest` sent nothing.
104
+ */
105
+ readonly reportsRequests?: boolean;
80
106
  decide(request: DecisionRequest): Promise<DecisionResult>;
81
107
  }
82
108
  export type DecisionDialect = 'port' | 'systemone';
83
- /** A bearer key, or a per-request token minter; a 401 requests one fresh token for that call. */
84
- export type DecisionCredential = string | ((options: {
109
+ /**
110
+ * Mints a bearer token; `refresh` asks for a new one after a 401. On a
111
+ * refresh, `refused` is the token the 401 refused (as sent, trimmed), so a
112
+ * caching minter can hand out a token minted since then instead of
113
+ * discarding it.
114
+ */
115
+ export type DecisionTokenMinter = (options: {
85
116
  refresh: boolean;
117
+ refused?: string;
86
118
  signal?: AbortSignal;
87
- }) => Promise<string>);
119
+ }) => Promise<string>;
120
+ /** A bearer key, or a per-request token minter; a 401 requests one fresh token for that call, and a second 401 one recheck (`refresh: false`) for a token minted since. */
121
+ export type DecisionCredential = string | DecisionTokenMinter;
88
122
  export interface DecisionProviderSettings {
89
123
  /** Full URL of the decision endpoint, not a base path. */
90
124
  baseURL?: string;
@@ -98,15 +132,20 @@ export interface DecisionProviderSettings {
98
132
  requiresAuth?: boolean;
99
133
  apiKeyEnv?: string;
100
134
  }
101
- export type DecisionFailure = 'timeout' | 'aborted' | 'rate_limited' | 'unauthorized' | 'bad_request' | 'server_error' | 'network' | 'unsupported_question' | 'unsupported_mode' | 'malformed_response';
135
+ export type DecisionFailure = 'timeout' | 'aborted' | 'rate_limited' | 'unauthorized'
136
+ /** HTTP 402: the credential is out of credits; never retried. */
137
+ | 'quota' | 'bad_request' | 'server_error' | 'network' | 'unsupported_question' | 'unsupported_mode' | 'malformed_response';
102
138
  export declare class DecisionError extends Error {
103
139
  readonly failure: DecisionFailure;
104
140
  readonly provider: string;
105
141
  readonly status?: number;
106
142
  retryAfterMs?: number;
143
+ /** True when a breaker refused the call without a request; see `withBreaker`. */
144
+ readonly circuitOpen: boolean;
107
145
  constructor(failure: DecisionFailure, message: string, options?: {
108
146
  provider?: string;
109
147
  status?: number;
148
+ circuitOpen?: boolean;
110
149
  });
111
150
  }
112
151
  /** A JSON boundary guard; never trust a parsed response's declared TypeScript type. */
@@ -7,3 +7,10 @@ export declare function applyCachePointsToConversePayload(fields: {
7
7
  params?: Partial<ConverseCommandParams>;
8
8
  modelId: string;
9
9
  }): void;
10
+ /**
11
+ * Drop trailing assistant turns for Claude models that reject a prefill (4.6 and
12
+ * later), mirroring `stripUnsupportedAssistantPrefill` for the Converse payload.
13
+ * A cache point that rode a stripped turn is re-anchored on the new tail when no
14
+ * surviving message carries one, so the request keeps its message caching.
15
+ */
16
+ export declare function stripUnsupportedConversePrefill(messages: Bedrock.Message[], model?: string): Bedrock.Message[];
@@ -147,7 +147,8 @@ export declare class CustomChatBedrockConverse extends ChatBedrockConverse {
147
147
  /**
148
148
  * Non-streaming Converse through this package's converter, as the stream already uses.
149
149
  * The parent's converter replays reasoning and sends harmony control tokens as written,
150
- * both of which OpenAI models on Bedrock fail on.
150
+ * both of which OpenAI models on Bedrock fail on, and it cannot strip a trailing
151
+ * assistant prefill that Claude 4.6 and later reject.
151
152
  */
152
153
  private generateWithLocalConverter;
153
154
  /**
@@ -0,0 +1,46 @@
1
+ import type { OutcomeReranker } from './types';
2
+ /**
3
+ * Codegraph's measured BM25 tokenizer for code and its prose: camelCase,
4
+ * snake_case, kebab-case, dotted names, and paths split into words, which
5
+ * are lower-cased; words of two letters or fewer and English stop words are
6
+ * dropped. It keeps only ASCII letters and digits, so CJK text yields no
7
+ * words and accented words split into fragments; pass a `tokenize` of your
8
+ * own for other scripts.
9
+ */
10
+ export declare function tokenizeCode(text: string): string[];
11
+ export type Tokenize = (text: string) => string[];
12
+ export interface CorpusStats {
13
+ /** Okapi idf, +1 smoothed so it is never negative. */
14
+ idf: Map<string, number>;
15
+ /** Mean document length in tokens. */
16
+ avgdl: number;
17
+ /** Documents counted. */
18
+ n: number;
19
+ }
20
+ /** Statistics over the whole corpus a shortlist is drawn from, not over the shortlist. */
21
+ export declare function corpusStats(documents: Iterable<string>, options?: {
22
+ tokenize?: Tokenize;
23
+ }): CorpusStats;
24
+ export interface Bm25RerankerOptions {
25
+ /** Corpus idf from `corpusStats`, or a function of the term. */
26
+ idf: ReadonlyMap<string, number> | ((term: string) => number);
27
+ /** The corpus's mean document length in tokens. */
28
+ avgdl: number;
29
+ /** Defaults to 1.2. */
30
+ k1?: number;
31
+ /** Defaults to 0.75. */
32
+ b?: number;
33
+ /** Must match the tokenizer the statistics were built with. Defaults to `tokenizeCode`. */
34
+ tokenize?: Tokenize;
35
+ }
36
+ /**
37
+ * In-process Okapi BM25. Corpus statistics are required: idf over a 50-document
38
+ * shortlist alone is close to degenerate. A term the corpus never saw counts
39
+ * as rare as its rarest term. Never throws once built, and costs nothing.
40
+ * Scoring is synchronous: an already-aborted `signal` is `aborted` before any
41
+ * work, and neither an abort nor `deadlineMs` stops a pass once it starts. A
42
+ * query the tokenizer leaves no terms in (only stop words, or a script it
43
+ * does not read) is `unsupported`, not an all-zero ranking, so a chain moves
44
+ * on.
45
+ */
46
+ export declare function createBm25Reranker(options: Bm25RerankerOptions): OutcomeReranker;
@@ -0,0 +1,40 @@
1
+ /** What a cached score is keyed on: the document text, not an identity that survives edits. */
2
+ export interface RerankCacheKey {
3
+ query: string;
4
+ document: string;
5
+ /** The model that produced the score; only an echo of the configured model is cached. */
6
+ model: string;
7
+ /** Identifies the rubric and instructions the score answers. */
8
+ rubric: string;
9
+ /**
10
+ * The serialized decision state the score was measured in when a custom
11
+ * `state` built it; empty for the default `{ query, document }`.
12
+ */
13
+ state: string;
14
+ }
15
+ /**
16
+ * Per-document scores; a host can supply its own (for example, hashed keys or
17
+ * a shared store). Both are synchronous: a throw from either is a miss, `set`
18
+ * is not awaited, and a promise either returns is ignored (its rejection
19
+ * included), so an asynchronous store must be fronted by a synchronous one.
20
+ */
21
+ export interface RerankScoreCache {
22
+ get(key: RerankCacheKey): number | undefined;
23
+ set(key: RerankCacheKey, score: number): void;
24
+ }
25
+ export interface MemoryScoreCache extends RerankScoreCache {
26
+ readonly size: number;
27
+ clear(): void;
28
+ }
29
+ export interface ScoreCacheOptions {
30
+ /** Entries kept, a positive integer, least recently used evicted first. Defaults to 20,000. */
31
+ max?: number;
32
+ /** A positive finite lifetime. Defaults to one day. */
33
+ ttlMs?: number;
34
+ now?: () => number;
35
+ }
36
+ /**
37
+ * A bounded in-memory LRU whose entries expire after `ttlMs`; keys hold the
38
+ * full document text. Throws on a `max` or `ttlMs` that would unbound it.
39
+ */
40
+ export declare function createScoreCache(options?: ScoreCacheOptions): MemoryScoreCache;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Light `@librechat/agents/rerank` entry: the index-based reranking contract,
3
+ * the never-throwing outcome layer, and the System One, cross-encoder, BM25,
4
+ * and fallback rerankers, with no LangChain or other third-party runtime
5
+ * import. The web-search adapter stays on the root entry because it extends
6
+ * the search tool's reranker.
7
+ */
8
+ export type * from './types';
9
+ export { createSystemOneReranker } from './systemone';
10
+ export type { SystemOnePin, SystemOneMode, SystemOneReranker, SystemOneRerankerOptions, } from './systemone';
11
+ export { createCrossEncoderReranker } from './crossEncoder';
12
+ export type { CrossEncoderRerankerOptions } from './crossEncoder';
13
+ export { createBm25Reranker, corpusStats, tokenizeCode } from './bm25';
14
+ export type { Bm25RerankerOptions, CorpusStats, Tokenize } from './bm25';
15
+ export { noneReranker, withFallback, STEP_GRACE_MS } from './fallback';
16
+ export type { FallbackStep, FallbackOptions, FallbackReranker, } from './fallback';
17
+ export { probePin, PIN_SENTINEL_MODEL } from './pin';
18
+ export type { PinProbe, PinProbeOptions } from './pin';
19
+ export { createSemaphore } from './semaphore';
20
+ export type { RerankSemaphore } from './semaphore';
21
+ export { createScoreCache } from './cache';
22
+ export type { RerankCacheKey, RerankScoreCache, MemoryScoreCache, ScoreCacheOptions, } from './cache';
23
+ export { rerankCost, rankedEntries, estimatedUsage, identityOutcome, emptyRerankUsage, toOutcomeReranker, isRerankPermutation, ESTIMATED_TOKENS_PER_DOCUMENT, } from './outcome';
24
+ export type { RerankCost, RerankPrice, RerankPrices } from './outcome';
@@ -0,0 +1,48 @@
1
+ import type { OutcomeReranker } from './types';
2
+ import type { DecisionCredential } from '../decisions/types';
3
+ import type { DecisionFetch } from '../decisions/transport';
4
+ export interface CrossEncoderRerankerOptions {
5
+ /**
6
+ * Full URL of a Cohere-shaped rerank endpoint: Cohere's `/v2/rerank`,
7
+ * Jina's `/v1/rerank`, an Infinity server, or the ClickHouse gateway's
8
+ * `${GATEWAY_URL}/rerank` (no `/v1`), which serves `qwen3-reranker-8b` and
9
+ * `cohere-rerank-v3-5`. TEI's `/rerank` takes `texts` and answers a bare
10
+ * array, so it does not fit. A response is capped at 256 KiB, so a host
11
+ * that echoes each document back (Jina does by default) fails a large
12
+ * shortlist as `bad_response`. Without a URL, every ranking is skipped
13
+ * with `no_endpoint`.
14
+ */
15
+ url?: string;
16
+ model: string;
17
+ /** A bearer key or token minter; a 401 mints one fresh token for that call. */
18
+ apiKey?: DecisionCredential;
19
+ /** Defaults to true; without a key every ranking is skipped with `no_api_key`. */
20
+ requiresAuth?: boolean;
21
+ /**
22
+ * Whole milliseconds from 1 to an hour; anything else throws at
23
+ * construction. Defaults to 30 seconds; a request's `deadlineMs` can
24
+ * shorten it, never extend it.
25
+ */
26
+ timeoutMs?: number;
27
+ /** Retries for rate limits, server errors, and network failures. Defaults to 0. */
28
+ maxRetries?: number;
29
+ /** Defaults to 1,000, Cohere's limit; larger sets are skipped, never truncated. */
30
+ maxDocuments?: number;
31
+ /**
32
+ * The estimate charged for a request a deadline abandoned. Defaults to 200;
33
+ * anything but a finite number of at least 0 throws at construction.
34
+ */
35
+ estimatedTokensPerDocument?: number;
36
+ fetch?: DecisionFetch;
37
+ }
38
+ /**
39
+ * A Cohere-shaped rerank endpoint: one `POST { model, query, documents }`
40
+ * answered by `results[{ index, relevance_score }]`. Never throws. The
41
+ * response must score every document exactly once; scores are the host's and
42
+ * carry no calibrated threshold, so `kept` is never set. Requests do not
43
+ * follow redirects, and a deadline that fires while a request is in flight
44
+ * is charged at `estimatedUsage`; one that fires after the latest request
45
+ * ended with a 429 or 5xx reply, before its retry is sent, charges nothing and
46
+ * reports that reply's reason.
47
+ */
48
+ export declare function createCrossEncoderReranker(options: CrossEncoderRerankerOptions): OutcomeReranker;
@@ -0,0 +1,67 @@
1
+ import type { RerankOutcome, OutcomeReranker } from './types';
2
+ /**
3
+ * Identity order, never a request: the last step of a chain, or the whole
4
+ * chain when nothing is configured. Its one attempt is `skipped` with
5
+ * `reason` and no usage, so a chain's history shows it ran. A malformed
6
+ * request is `invalid_request` and an empty one `empty`, as for every other
7
+ * reranker, so a bad call is never mistaken for a disabled one.
8
+ */
9
+ export declare function noneReranker(options?: {
10
+ reason?: string;
11
+ }): OutcomeReranker;
12
+ export interface FallbackStep {
13
+ reranker: OutcomeReranker;
14
+ /** This step's own deadline, so a hung step cannot starve the next one. */
15
+ deadlineMs?: number;
16
+ }
17
+ export interface FallbackOptions {
18
+ /**
19
+ * Returns a reason to skip a step without a request (a backoff, a budget,
20
+ * an unverified pin), or nothing to run it. Not consulted for `none` steps.
21
+ * A gate that throws skips its step with `error`. The wait for it is
22
+ * bounded like a step: a gate still pending when the request's deadline
23
+ * passes or its signal aborts is abandoned and the chain stops with
24
+ * `timeout` or `aborted`.
25
+ */
26
+ gate?: (reranker: OutcomeReranker) => string | null | undefined | Promise<string | null | undefined>;
27
+ /**
28
+ * Sees every step that ran, for backoff bookkeeping, as a copy: changing
29
+ * it changes nothing the chain returns. Not awaited; a throw or a rejected
30
+ * promise is ignored.
31
+ */
32
+ onAttempt?: (reranker: OutcomeReranker, outcome: RerankOutcome) => void;
33
+ }
34
+ export interface FallbackReranker extends OutcomeReranker {
35
+ readonly steps: readonly FallbackStep[];
36
+ }
37
+ /**
38
+ * Grace after a step's deadline or the caller's abort for a reranker that
39
+ * honors its abort to report its own timeout and spend. A full answer that
40
+ * arrives within it is accepted: waiting for it costs nothing the timeout
41
+ * would not.
42
+ */
43
+ export declare const STEP_GRACE_MS = 50;
44
+ /**
45
+ * A chain of steps tried in order; the first that answers wins. Step 0
46
+ * answering is `ok`; a later step is `degraded` with the first failed step's
47
+ * reason; none answering is `skipped` in identity order with that reason. A
48
+ * `none` step never answers. `kept`, `threshold`, and `pinVerified` come from
49
+ * the answering step only, so falling back to a cross-encoder never carries a
50
+ * System One threshold. A step that throws, rejects, returns something that
51
+ * breaks the `RerankOutcome` contract (a full permutation in score order,
52
+ * every document scored when it answers, `kept` only with a `threshold` and
53
+ * then on every entry, `true` exactly where the score reaches it, well-formed
54
+ * attempts whose usage counters and durations are finite counts of at least
55
+ * zero, and well-formed fields), or outlives its deadline or the
56
+ * caller's abort by `STEP_GRACE_MS` is a failed step; a step that ran but
57
+ * reported no attempt is recorded as one. A request's `deadlineMs` bounds the whole
58
+ * chain, gates included: each step gets the lesser of its own deadline and
59
+ * what is left, a step without one gets what is left, and once nothing is
60
+ * left the chain stops with `timeout`. A step's deadline reaches it as
61
+ * `RankRequest.deadlineMs`, which caps the reranker's own timeout and never
62
+ * extends it. Usage sums every attempt, from the
63
+ * attempts themselves rather than a step's own total: spend counts what was
64
+ * sent, not what answered. An invalid request is identity order over every
65
+ * document. Never throws.
66
+ */
67
+ export declare function withFallback(steps: readonly FallbackStep[], options?: FallbackOptions): FallbackReranker;