@mcp-abap-adt/llm-agent 26.0.0 → 28.0.0

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 (147) hide show
  1. package/README.md +2 -0
  2. package/dist/credentials/static.d.ts +9 -0
  3. package/dist/credentials/static.d.ts.map +1 -0
  4. package/dist/credentials/static.js +12 -0
  5. package/dist/credentials/static.js.map +1 -0
  6. package/dist/index.d.ts +6 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +5 -0
  9. package/dist/index.js.map +1 -1
  10. package/dist/interfaces/builder.d.ts +11 -1
  11. package/dist/interfaces/builder.d.ts.map +1 -1
  12. package/dist/interfaces/collect-server-descriptors.d.ts +12 -0
  13. package/dist/interfaces/collect-server-descriptors.d.ts.map +1 -0
  14. package/dist/interfaces/collect-server-descriptors.js +19 -0
  15. package/dist/interfaces/collect-server-descriptors.js.map +1 -0
  16. package/dist/interfaces/index.d.ts +3 -2
  17. package/dist/interfaces/index.d.ts.map +1 -1
  18. package/dist/interfaces/index.js.map +1 -1
  19. package/dist/interfaces/mcp-connection-strategy.d.ts +29 -2
  20. package/dist/interfaces/mcp-connection-strategy.d.ts.map +1 -1
  21. package/dist/interfaces/mcp-server-from-factory.d.ts +15 -0
  22. package/dist/interfaces/mcp-server-from-factory.d.ts.map +1 -0
  23. package/dist/interfaces/mcp-server-from-factory.js +37 -0
  24. package/dist/interfaces/mcp-server-from-factory.js.map +1 -0
  25. package/dist/interfaces/mcp-server.d.ts +24 -0
  26. package/dist/interfaces/mcp-server.d.ts.map +1 -0
  27. package/dist/interfaces/mcp-server.js +2 -0
  28. package/dist/interfaces/mcp-server.js.map +1 -0
  29. package/dist/interfaces/pipeline-plugin.d.ts +16 -6
  30. package/dist/interfaces/pipeline-plugin.d.ts.map +1 -1
  31. package/dist/interfaces/plugin.d.ts +11 -3
  32. package/dist/interfaces/plugin.d.ts.map +1 -1
  33. package/dist/interfaces/rag.d.ts +124 -21
  34. package/dist/interfaces/rag.d.ts.map +1 -1
  35. package/dist/interfaces/rag.js.map +1 -1
  36. package/dist/interfaces/tool-catalog.d.ts +4 -2
  37. package/dist/interfaces/tool-catalog.d.ts.map +1 -1
  38. package/dist/interfaces/tool-catalog.js.map +1 -1
  39. package/dist/interfaces/types.d.ts +2 -1
  40. package/dist/interfaces/types.d.ts.map +1 -1
  41. package/dist/interfaces/types.js.map +1 -1
  42. package/dist/llm/base-llm-provider.d.ts +29 -4
  43. package/dist/llm/base-llm-provider.d.ts.map +1 -1
  44. package/dist/llm/base-llm-provider.js +45 -9
  45. package/dist/llm/base-llm-provider.js.map +1 -1
  46. package/dist/logger/normalise-logger.d.ts +28 -0
  47. package/dist/logger/normalise-logger.d.ts.map +1 -0
  48. package/dist/logger/normalise-logger.js +50 -0
  49. package/dist/logger/normalise-logger.js.map +1 -0
  50. package/dist/logger/text-logger.d.ts +14 -0
  51. package/dist/logger/text-logger.d.ts.map +1 -0
  52. package/dist/logger/text-logger.js +2 -0
  53. package/dist/logger/text-logger.js.map +1 -0
  54. package/dist/policy/fallback-llm-call-strategy.d.ts +3 -3
  55. package/dist/policy/fallback-llm-call-strategy.d.ts.map +1 -1
  56. package/dist/policy/fallback-llm-call-strategy.js +3 -2
  57. package/dist/policy/fallback-llm-call-strategy.js.map +1 -1
  58. package/dist/rag/catalog/index.d.ts +2 -0
  59. package/dist/rag/catalog/index.d.ts.map +1 -0
  60. package/dist/rag/catalog/index.js +2 -0
  61. package/dist/rag/catalog/index.js.map +1 -0
  62. package/dist/rag/catalog/validation.d.ts +56 -0
  63. package/dist/rag/catalog/validation.d.ts.map +1 -0
  64. package/dist/rag/catalog/validation.js +168 -0
  65. package/dist/rag/catalog/validation.js.map +1 -0
  66. package/dist/rag/corrections/errors.d.ts +47 -0
  67. package/dist/rag/corrections/errors.d.ts.map +1 -1
  68. package/dist/rag/corrections/errors.js +73 -0
  69. package/dist/rag/corrections/errors.js.map +1 -1
  70. package/dist/rag/identity-filter.d.ts +19 -0
  71. package/dist/rag/identity-filter.d.ts.map +1 -0
  72. package/dist/rag/identity-filter.js +31 -0
  73. package/dist/rag/identity-filter.js.map +1 -0
  74. package/dist/rag/in-memory-rag.d.ts +3 -1
  75. package/dist/rag/in-memory-rag.d.ts.map +1 -1
  76. package/dist/rag/in-memory-rag.js +20 -15
  77. package/dist/rag/in-memory-rag.js.map +1 -1
  78. package/dist/rag/index.d.ts +3 -0
  79. package/dist/rag/index.d.ts.map +1 -1
  80. package/dist/rag/index.js +2 -0
  81. package/dist/rag/index.js.map +1 -1
  82. package/dist/rag/mcp-tools/index.d.ts +1 -1
  83. package/dist/rag/mcp-tools/index.d.ts.map +1 -1
  84. package/dist/rag/mcp-tools/index.js.map +1 -1
  85. package/dist/rag/mcp-tools/rag-collection-tools.d.ts +36 -5
  86. package/dist/rag/mcp-tools/rag-collection-tools.d.ts.map +1 -1
  87. package/dist/rag/mcp-tools/rag-collection-tools.js +121 -58
  88. package/dist/rag/mcp-tools/rag-collection-tools.js.map +1 -1
  89. package/dist/rag/providers/base-provider.d.ts +8 -6
  90. package/dist/rag/providers/base-provider.d.ts.map +1 -1
  91. package/dist/rag/providers/base-provider.js +18 -0
  92. package/dist/rag/providers/base-provider.js.map +1 -1
  93. package/dist/rag/providers/in-memory-rag-provider.d.ts +4 -7
  94. package/dist/rag/providers/in-memory-rag-provider.d.ts.map +1 -1
  95. package/dist/rag/providers/in-memory-rag-provider.js +11 -4
  96. package/dist/rag/providers/in-memory-rag-provider.js.map +1 -1
  97. package/dist/rag/providers/vector-rag-provider.d.ts +4 -7
  98. package/dist/rag/providers/vector-rag-provider.d.ts.map +1 -1
  99. package/dist/rag/providers/vector-rag-provider.js +11 -4
  100. package/dist/rag/providers/vector-rag-provider.js.map +1 -1
  101. package/dist/rag/registry/index.d.ts +1 -0
  102. package/dist/rag/registry/index.d.ts.map +1 -1
  103. package/dist/rag/registry/index.js +1 -0
  104. package/dist/rag/registry/index.js.map +1 -1
  105. package/dist/rag/registry/simple-rag-registry.d.ts +74 -30
  106. package/dist/rag/registry/simple-rag-registry.d.ts.map +1 -1
  107. package/dist/rag/registry/simple-rag-registry.js +265 -100
  108. package/dist/rag/registry/simple-rag-registry.js.map +1 -1
  109. package/dist/rag/registry/store-key.d.ts +15 -0
  110. package/dist/rag/registry/store-key.d.ts.map +1 -0
  111. package/dist/rag/registry/store-key.js +25 -0
  112. package/dist/rag/registry/store-key.js.map +1 -0
  113. package/dist/rag/search-strategy.d.ts +9 -0
  114. package/dist/rag/search-strategy.d.ts.map +1 -1
  115. package/dist/rag/search-strategy.js +49 -22
  116. package/dist/rag/search-strategy.js.map +1 -1
  117. package/dist/rag/tokenizer.d.ts +17 -0
  118. package/dist/rag/tokenizer.d.ts.map +1 -0
  119. package/dist/rag/tokenizer.js +38 -0
  120. package/dist/rag/tokenizer.js.map +1 -0
  121. package/dist/rag/vector-rag.d.ts +2 -2
  122. package/dist/rag/vector-rag.d.ts.map +1 -1
  123. package/dist/rag/vector-rag.js +29 -21
  124. package/dist/rag/vector-rag.js.map +1 -1
  125. package/dist/resilience/embedder-resilience.d.ts +2 -2
  126. package/dist/resilience/embedder-resilience.d.ts.map +1 -1
  127. package/dist/resilience/embedder-resilience.js +3 -1
  128. package/dist/resilience/embedder-resilience.js.map +1 -1
  129. package/dist/testing/rag-filter-conformance.d.ts +60 -0
  130. package/dist/testing/rag-filter-conformance.d.ts.map +1 -0
  131. package/dist/testing/rag-filter-conformance.js +379 -0
  132. package/dist/testing/rag-filter-conformance.js.map +1 -0
  133. package/dist/types.d.ts +11 -2
  134. package/dist/types.d.ts.map +1 -1
  135. package/package.json +11 -2
  136. package/dist/interfaces/failure-strategy.d.ts +0 -95
  137. package/dist/interfaces/failure-strategy.d.ts.map +0 -1
  138. package/dist/interfaces/failure-strategy.js +0 -96
  139. package/dist/interfaces/failure-strategy.js.map +0 -1
  140. package/dist/llm/rate-limit.d.ts +0 -165
  141. package/dist/llm/rate-limit.d.ts.map +0 -1
  142. package/dist/llm/rate-limit.js +0 -394
  143. package/dist/llm/rate-limit.js.map +0 -1
  144. package/dist/resilience/status.d.ts +0 -29
  145. package/dist/resilience/status.d.ts.map +0 -1
  146. package/dist/resilience/status.js +0 -51
  147. package/dist/resilience/status.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"failure-strategy.js","sourceRoot":"","sources":["../../src/interfaces/failure-strategy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AA6B5D;;;;;;GAMG;AACH,MAAM,OAAO,aAAa;IACf,IAAI,GAAG,gBAAgB,CAAC;IAEjC,MAAM;QACJ,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;IACzD,CAAC;CACF;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,gBAAgB;IAClB,IAAI,GAAG,oBAAoB,CAAC;IACpB,QAAQ,CAAS;IACjB,WAAW,CAAS;IACpB,QAAQ,CAAsB;IAC9B,cAAc,CAAoB;IAEnD,YAAY,OASX;QACC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC1C,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,EAAE,CAAC;IACrD,CAAC;IAED,MAAM,CAAC,EACL,MAAM,EACN,OAAO,EACP,SAAS,EACT,KAAK,GACU;QACf,IAAI,OAAO,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;QACzD,CAAC;QACD,MAAM,cAAc,GAAG,SAAS;YAC9B,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;YACzB,CAAC,CAAC,MAAM,KAAK,SAAS;gBACpB,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC;gBAC3B,CAAC,CAAC,uEAAuE;oBACvE,sEAAsE;oBACtE,qEAAqE;oBACrE,iBAAiB,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;QACnD,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,OAAO;gBACL,MAAM,EAAE,CAAC;gBACT,KAAK,EAAE,KAAK;gBACZ,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,eAAe;aACnD,CAAC;QACJ,CAAC;QACD,oEAAoE;QACpE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,WAAW,GAAG,CAAC,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACxE,CAAC;IAEO,WAAW,CAAC,KAAc;QAChC,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACnD,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IACpE,CAAC;CACF"}
@@ -1,165 +0,0 @@
1
- /**
2
- * Shared rate-limit handling for every LLM provider.
3
- *
4
- * None of the providers handled HTTP 429 (issue #282). Each one let the status
5
- * collapse into an error message, so consumers were reduced to matching the
6
- * substring "429" in prose to decide whether to retry.
7
- *
8
- * The policy lives here rather than in a provider because the providers differ
9
- * in SDK but not in the shape of the problem: a shared quota, a documented
10
- * `Retry-After`, and a herd of concurrent callers that will all rediscover the
11
- * same limit unless something holds them back together.
12
- *
13
- * SAP AI Core states the rules this implements
14
- * (help.sap.com, Rate Limit Management):
15
- *
16
- * Do not retry immediately after a 429. Use exponential backoff with jitter
17
- * to prevent thundering-herd behavior. If the response includes a
18
- * `Retry-After` header, use its value as the wait interval. Limit retries by
19
- * using a maximum cap (for example, 5 retries or 60 seconds total wait).
20
- *
21
- * The same rules fit Anthropic and OpenAI, which return 429 with `Retry-After`
22
- * as ordinary HTTP. Ollama is local and never rate-limited; it simply never
23
- * enters this path.
24
- */
25
- export interface RateLimitPolicy {
26
- /** Set false to pass every error straight through. */
27
- enabled: boolean;
28
- /** Total attempts INCLUDING the first. 1 disables retrying without disabling the gate. */
29
- maxAttempts: number;
30
- /** Give up once the accumulated waiting would exceed this. */
31
- maxTotalWaitMs: number;
32
- /** First backoff step when the server names no time of its own. */
33
- baseDelayMs: number;
34
- /** Ceiling for one computed step, before jitter. */
35
- maxDelayMs: number;
36
- }
37
- export declare const DEFAULT_RATE_LIMIT_POLICY: RateLimitPolicy;
38
- /** An error annotated by this module, so consumers read a fact instead of prose. */
39
- export interface RateLimitedError extends Error {
40
- rateLimited: true;
41
- /** What the server asked for, when it asked. */
42
- retryAfterSeconds?: number;
43
- /** How many attempts were spent before giving up. */
44
- attempts: number;
45
- }
46
- export declare function isRateLimitedError(e: unknown): e is RateLimitedError;
47
- /**
48
- * One shared pause per quota.
49
- *
50
- * A rate limit belongs to the quota, not to the request that happened to
51
- * discover it. When one call is told to wait, every other call against the same
52
- * quota is already over the limit too — letting each find that out for itself
53
- * means N more rejected requests and N more penalties, which is how a limit
54
- * that should last one window lasts several.
55
- *
56
- * Keyed because limits are per model: one model being throttled says nothing
57
- * about another.
58
- */
59
- export declare class RateLimitGate {
60
- private notBefore;
61
- /** Hold every caller until the named time. Never shortens an existing hold. */
62
- penalise(ms: number, now?: number): void;
63
- /** Milliseconds still to wait, or 0. */
64
- remaining(now?: number): number;
65
- clear(): void;
66
- /**
67
- * Wait out any active hold.
68
- *
69
- * Re-checked after every wake, because the hold is not fixed at the moment
70
- * this caller started waiting: another caller's 429 extends it, and a sleeper
71
- * timed against the old deadline would wake early and spend a request on a
72
- * quota the server has since said is still closed.
73
- *
74
- * The wait is jittered per caller: without that, everyone released by one
75
- * penalty wakes in the same millisecond and rebuilds the herd the penalty was
76
- * meant to break up.
77
- */
78
- waitUntilOpen(signal?: AbortSignal, maxWaitMs?: number): Promise<void>;
79
- }
80
- /**
81
- * Keys are open-ended — a per-request model override mints a new one — so the
82
- * registry is pruned rather than left to grow for the life of the process.
83
- * Only entries that are both open and long idle are dropped: a held gate is
84
- * doing its job, and a recently used one may still be someone's in-flight call.
85
- */
86
- export declare const GATE_IDLE_TTL_MS: number;
87
- /**
88
- * How many quotas the registry keeps. Enforced by evicting gates that are both
89
- * open and unheld, so a process with more than this many pauses or in-flight
90
- * calls at once can exceed it — those gates are load-bearing. Evicting an idle
91
- * one costs nothing: it carries no deadline, and the next call mints an
92
- * equivalent.
93
- */
94
- export declare const GATE_LIMIT = 500;
95
- /** The gate for one quota. Shared across every provider instance in the process. */
96
- export declare function gateFor(key: string): RateLimitGate;
97
- /**
98
- * Hold a gate for the length of one call, and keep it in the registry meanwhile.
99
- *
100
- * Being open is not the same as being unused. A request is in flight for as
101
- * long as it takes the server to answer, and until that answer arrives the gate
102
- * it belongs to has no pause on it. Evicted in that window, the call would go on
103
- * to penalise an object the registry no longer knows: the pause would be real
104
- * and invisible, and the next caller would be handed a fresh open gate and sent
105
- * straight into a quota that had just closed. Worse than no gate at all, since
106
- * the penalty is paid and nothing is bought with it.
107
- *
108
- * Release in a `finally`. Releasing twice is harmless.
109
- */
110
- export declare function leaseRateLimitGate(key: string): {
111
- gate: RateLimitGate;
112
- release: () => void;
113
- };
114
- /**
115
- * Reclaim gates that are open and long idle. Exported so a long-lived host can
116
- * run it on a timer, and so the reclaim can be tested at a chosen `now` without
117
- * waiting ten minutes. It frees only what is certainly stale; the size bound is
118
- * enforced separately, by `reclaimGates`.
119
- */
120
- export declare function pruneRateLimitGates(now?: number): void;
121
- /** How many quotas are currently tracked. Diagnostics and tests. */
122
- export declare function rateLimitGateCount(): number;
123
- /** Test seam — drops every gate. */
124
- export declare function resetRateLimitGates(): void;
125
- export interface RateLimitRetryOptions {
126
- /** Identifies the quota being spent. Limits are per model, so include it. */
127
- key: string;
128
- policy?: Partial<RateLimitPolicy>;
129
- /** Does this error mean "too many requests"? */
130
- isRateLimited: (error: unknown) => boolean;
131
- /** What the server asked us to wait, in seconds, if it said. */
132
- retryAfterSeconds?: (error: unknown) => number | undefined;
133
- signal?: AbortSignal;
134
- onRetry?: (info: {
135
- attempt: number;
136
- delayMs: number;
137
- retryAfterSeconds?: number;
138
- }) => void;
139
- }
140
- /**
141
- * Run `fn`, respecting the shared pause and retrying a rate limit.
142
- *
143
- * Any error that is not a rate limit is rethrown untouched and immediately —
144
- * this is not a general-purpose retry, and turning a genuine failure into four
145
- * more of them would be worse than the failure.
146
- */
147
- export declare function runWithRateLimitRetry<T>(fn: () => Promise<T>, opts: RateLimitRetryOptions): Promise<T>;
148
- /**
149
- * The rate-limit marker on an error or anywhere in its `cause` chain.
150
- *
151
- * Layers above the provider rewrap errors — the ILlm adapter turns anything
152
- * thrown into an `LlmError` — so the marker is rarely still on the outermost
153
- * object by the time a retry decorator inspects it. Bounded by depth and a
154
- * visited set, like `extractStatusCode`, so a cyclic chain cannot hang.
155
- */
156
- export declare function findRateLimit(err: unknown): RateLimitedError | undefined;
157
- /**
158
- * Carry the rate-limit facts onto a provider's own error.
159
- *
160
- * Every provider catches its transport error and rethrows something friendlier.
161
- * That is fine for a message and fatal for a fact: the 429 would be lost at the
162
- * exact boundary where the consumer needs it. This moves the facts across.
163
- */
164
- export declare function preserveRateLimit<E extends Error>(original: unknown, wrapped: E): E;
165
- //# sourceMappingURL=rate-limit.d.ts.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Q,EAAE,OAAO,EACjB,OAAO,EAAE,CAAC,GACT,CAAC,CASH"}
@@ -1,394 +0,0 @@
1
- /**
2
- * Shared rate-limit handling for every LLM provider.
3
- *
4
- * None of the providers handled HTTP 429 (issue #282). Each one let the status
5
- * collapse into an error message, so consumers were reduced to matching the
6
- * substring "429" in prose to decide whether to retry.
7
- *
8
- * The policy lives here rather than in a provider because the providers differ
9
- * in SDK but not in the shape of the problem: a shared quota, a documented
10
- * `Retry-After`, and a herd of concurrent callers that will all rediscover the
11
- * same limit unless something holds them back together.
12
- *
13
- * SAP AI Core states the rules this implements
14
- * (help.sap.com, Rate Limit Management):
15
- *
16
- * Do not retry immediately after a 429. Use exponential backoff with jitter
17
- * to prevent thundering-herd behavior. If the response includes a
18
- * `Retry-After` header, use its value as the wait interval. Limit retries by
19
- * using a maximum cap (for example, 5 retries or 60 seconds total wait).
20
- *
21
- * The same rules fit Anthropic and OpenAI, which return 429 with `Retry-After`
22
- * as ordinary HTTP. Ollama is local and never rate-limited; it simply never
23
- * enters this path.
24
- */
25
- import { DefaultWaitStrategy } from '../interfaces/wait-strategy.js';
26
- export const DEFAULT_RATE_LIMIT_POLICY = {
27
- enabled: true,
28
- maxAttempts: 5,
29
- maxTotalWaitMs: 60_000,
30
- baseDelayMs: 1_000,
31
- maxDelayMs: 20_000,
32
- };
33
- export function isRateLimitedError(e) {
34
- return (typeof e === 'object' &&
35
- e !== null &&
36
- e.rateLimited === true);
37
- }
38
- const waiter = new DefaultWaitStrategy();
39
- /**
40
- * Sleep, or throw if the signal aborts.
41
- *
42
- * Delegated to the shared wait strategy rather than hand-rolled: the listener
43
- * bookkeeping is where a sleep like this goes wrong. One added per backoff and
44
- * never removed accumulates on a request- or session-scoped signal until Node
45
- * warns about the leak — a defect this repository has already fixed once, in
46
- * the retry decorators. Fixed in one place, it stays fixed for every waiter.
47
- */
48
- const sleep = async (ms, signal) => {
49
- const aborted = () => signal?.reason ?? new Error('Aborted');
50
- if (signal?.aborted)
51
- throw aborted();
52
- if ((await waiter.wait(ms, signal)) === 'aborted')
53
- throw aborted();
54
- };
55
- /**
56
- * Per-caller spread on waking, so everyone released by one penalty does not
57
- * wake in the same millisecond and rebuild the herd the penalty broke up.
58
- *
59
- * It is added to a wait, never to a budget: a wait capped at exactly the budget
60
- * simply loses the spread, which costs nothing — a caller whose budget ends
61
- * with the pause is leaving either way.
62
- */
63
- const WAKE_SPREAD_MS = 250;
64
- /**
65
- * One shared pause per quota.
66
- *
67
- * A rate limit belongs to the quota, not to the request that happened to
68
- * discover it. When one call is told to wait, every other call against the same
69
- * quota is already over the limit too — letting each find that out for itself
70
- * means N more rejected requests and N more penalties, which is how a limit
71
- * that should last one window lasts several.
72
- *
73
- * Keyed because limits are per model: one model being throttled says nothing
74
- * about another.
75
- */
76
- export class RateLimitGate {
77
- notBefore = 0;
78
- /** Hold every caller until the named time. Never shortens an existing hold. */
79
- penalise(ms, now = Date.now()) {
80
- this.notBefore = Math.max(this.notBefore, now + ms);
81
- }
82
- /** Milliseconds still to wait, or 0. */
83
- remaining(now = Date.now()) {
84
- return Math.max(0, this.notBefore - now);
85
- }
86
- clear() {
87
- this.notBefore = 0;
88
- }
89
- /**
90
- * Wait out any active hold.
91
- *
92
- * Re-checked after every wake, because the hold is not fixed at the moment
93
- * this caller started waiting: another caller's 429 extends it, and a sleeper
94
- * timed against the old deadline would wake early and spend a request on a
95
- * quota the server has since said is still closed.
96
- *
97
- * The wait is jittered per caller: without that, everyone released by one
98
- * penalty wakes in the same millisecond and rebuilds the herd the penalty was
99
- * meant to break up.
100
- */
101
- async waitUntilOpen(signal, maxWaitMs = Number.POSITIVE_INFINITY) {
102
- const deadline = Date.now() + maxWaitMs;
103
- for (;;) {
104
- const left = this.remaining();
105
- if (left <= 0)
106
- return;
107
- const budget = deadline - Date.now();
108
- // Out of the caller's budget with the gate still shut. It is told, not
109
- // held: `remaining()` still reports the hold, and the caller decides.
110
- if (budget <= 0)
111
- return;
112
- // A timer that lands a hair early is simply waited out again on the next
113
- // turn, which is why the cap needs no padding to be safe.
114
- await sleep(Math.min(left + Math.random() * WAKE_SPREAD_MS, budget), signal);
115
- }
116
- }
117
- }
118
- const gates = new Map();
119
- /**
120
- * Keys are open-ended — a per-request model override mints a new one — so the
121
- * registry is pruned rather than left to grow for the life of the process.
122
- * Only entries that are both open and long idle are dropped: a held gate is
123
- * doing its job, and a recently used one may still be someone's in-flight call.
124
- */
125
- export const GATE_IDLE_TTL_MS = 10 * 60_000;
126
- /**
127
- * How many quotas the registry keeps. Enforced by evicting gates that are both
128
- * open and unheld, so a process with more than this many pauses or in-flight
129
- * calls at once can exceed it — those gates are load-bearing. Evicting an idle
130
- * one costs nothing: it carries no deadline, and the next call mints an
131
- * equivalent.
132
- */
133
- export const GATE_LIMIT = 500;
134
- /** The gate for one quota. Shared across every provider instance in the process. */
135
- export function gateFor(key) {
136
- const now = Date.now();
137
- const existing = gates.get(key);
138
- if (existing) {
139
- existing.lastUsed = now;
140
- return existing.gate;
141
- }
142
- if (gates.size >= GATE_LIMIT)
143
- reclaimGates(now);
144
- const entry = {
145
- gate: new RateLimitGate(),
146
- lastUsed: now,
147
- leases: 0,
148
- };
149
- gates.set(key, entry);
150
- return entry.gate;
151
- }
152
- /**
153
- * Hold a gate for the length of one call, and keep it in the registry meanwhile.
154
- *
155
- * Being open is not the same as being unused. A request is in flight for as
156
- * long as it takes the server to answer, and until that answer arrives the gate
157
- * it belongs to has no pause on it. Evicted in that window, the call would go on
158
- * to penalise an object the registry no longer knows: the pause would be real
159
- * and invisible, and the next caller would be handed a fresh open gate and sent
160
- * straight into a quota that had just closed. Worse than no gate at all, since
161
- * the penalty is paid and nothing is bought with it.
162
- *
163
- * Release in a `finally`. Releasing twice is harmless.
164
- */
165
- export function leaseRateLimitGate(key) {
166
- const gate = gateFor(key);
167
- // By identity, not by key: `resetRateLimitGates` may have replaced the entry
168
- // by the time this is released, and that entry's count is not ours to touch.
169
- const entry = gates.get(key);
170
- if (entry)
171
- entry.leases += 1;
172
- let released = false;
173
- return {
174
- gate,
175
- release: () => {
176
- if (released || !entry)
177
- return;
178
- released = true;
179
- entry.leases -= 1;
180
- entry.lastUsed = Date.now();
181
- },
182
- };
183
- }
184
- /**
185
- * Reclaim gates that are open and long idle. Exported so a long-lived host can
186
- * run it on a timer, and so the reclaim can be tested at a chosen `now` without
187
- * waiting ten minutes. It frees only what is certainly stale; the size bound is
188
- * enforced separately, by `reclaimGates`.
189
- */
190
- export function pruneRateLimitGates(now = Date.now()) {
191
- for (const [key, entry] of gates) {
192
- if (isEvictable(entry, now) && now - entry.lastUsed > GATE_IDLE_TTL_MS) {
193
- gates.delete(key);
194
- }
195
- }
196
- }
197
- /**
198
- * Safe to forget: nobody is waiting behind it, and no call is holding it.
199
- *
200
- * An open, unleased gate carries no state at all — the next call mints an
201
- * equivalent one and loses nothing.
202
- */
203
- function isEvictable(entry, now) {
204
- return entry.leases === 0 && entry.gate.remaining(now) === 0;
205
- }
206
- /**
207
- * Hold the registry at `GATE_LIMIT`.
208
- *
209
- * Age alone is not a bound: a burst of per-request model overrides mints keys
210
- * far faster than the ten-minute idle rule retires them, and the map grows for
211
- * as long as the burst lasts. So once the stale entries are gone, the least
212
- * recently used OPEN gates go too, oldest first, until the registry is back
213
- * under the limit.
214
- *
215
- * Only idle gates are evicted: not one holding a pause, which IS the pause, and
216
- * not one a call is still holding, which may be about to become a pause.
217
- */
218
- function reclaimGates(now) {
219
- pruneRateLimitGates(now);
220
- if (gates.size < GATE_LIMIT)
221
- return;
222
- const evictable = [...gates]
223
- .filter(([, entry]) => isEvictable(entry, now))
224
- .sort((a, b) => a[1].lastUsed - b[1].lastUsed);
225
- for (const [key] of evictable) {
226
- if (gates.size < GATE_LIMIT)
227
- return;
228
- gates.delete(key);
229
- }
230
- }
231
- /** How many quotas are currently tracked. Diagnostics and tests. */
232
- export function rateLimitGateCount() {
233
- return gates.size;
234
- }
235
- /** Test seam — drops every gate. */
236
- export function resetRateLimitGates() {
237
- gates.clear();
238
- }
239
- /**
240
- * Run `fn`, respecting the shared pause and retrying a rate limit.
241
- *
242
- * Any error that is not a rate limit is rethrown untouched and immediately —
243
- * this is not a general-purpose retry, and turning a genuine failure into four
244
- * more of them would be worse than the failure.
245
- */
246
- export async function runWithRateLimitRetry(fn, opts) {
247
- const policy = { ...DEFAULT_RATE_LIMIT_POLICY, ...opts.policy };
248
- if (!policy.enabled)
249
- return fn();
250
- const { gate, release } = leaseRateLimitGate(opts.key);
251
- try {
252
- return await attemptWithGate(fn, opts, policy, gate);
253
- }
254
- finally {
255
- release();
256
- }
257
- }
258
- async function attemptWithGate(fn, opts, policy, gate) {
259
- let attempt = 0;
260
- let waited = 0;
261
- for (;;) {
262
- // Waiting at the gate is waiting. Uncounted it was free, so a caller with a
263
- // ten-millisecond budget could sit out a minute-long pause another caller
264
- // had earned, its declared budget saying nothing about the time it spent.
265
- // Decided before the wait, never during it: a hold longer than what is left
266
- // of the budget is refused outright rather than half-served.
267
- const hold = gate.remaining();
268
- if (hold > 0) {
269
- const budgetLeft = policy.maxTotalWaitMs - waited;
270
- if (hold > budgetLeft)
271
- throw outOfBudgetAtGate(hold, attempt);
272
- const before = Date.now();
273
- // Capped as well as pre-checked: a pause that fits when the wait starts
274
- // can be extended past the budget by someone else's 429 while it runs.
275
- // The cap is the budget exactly. Padding it to protect the wake spread
276
- // would make the budget the one thing it must not be — approximate.
277
- await gate.waitUntilOpen(opts.signal, budgetLeft);
278
- waited += Date.now() - before;
279
- const stillShut = gate.remaining();
280
- if (stillShut > 0)
281
- throw outOfBudgetAtGate(stillShut, attempt);
282
- }
283
- try {
284
- return await fn();
285
- }
286
- catch (error) {
287
- if (!opts.isRateLimited(error))
288
- throw error;
289
- attempt += 1;
290
- const retryAfter = opts.retryAfterSeconds?.(error);
291
- const served = retryAfter !== undefined && Number.isFinite(retryAfter);
292
- // The server's own number wins. A computed guess is for when it stays
293
- // silent — it is an estimate of something the server already knows.
294
- const wait = served
295
- ? retryAfter * 1000
296
- : jittered(policy.baseDelayMs * 2 ** (attempt - 1), policy.maxDelayMs);
297
- // Hold everyone else too, and hold them whether or not THIS caller has
298
- // budget left to retry. The pause describes the quota, not one request:
299
- // giving up with the gate open sends every other caller straight back
300
- // into a limit the server just said was closed.
301
- //
302
- // The gate is given the interval alone. This caller then serves its own
303
- // backoff there, on the next turn of the loop, rather than sleeping
304
- // beside it: two mechanisms waiting out one pause double-count it, and
305
- // the leftover milliseconds between them decide outcomes at the margin.
306
- // The per-caller spread that keeps the released callers from waking
307
- // together lives in `waitUntilOpen`, where the waiting is done.
308
- gate.penalise(wait);
309
- const outOfAttempts = attempt >= policy.maxAttempts;
310
- const outOfTime = waited + wait > policy.maxTotalWaitMs;
311
- if (outOfAttempts || outOfTime) {
312
- throw annotate(error, attempt, retryAfter);
313
- }
314
- opts.onRetry?.({
315
- attempt,
316
- delayMs: wait,
317
- retryAfterSeconds: retryAfter,
318
- });
319
- }
320
- }
321
- }
322
- /**
323
- * Full jitter: a random point in [0, computed], not computed ± a nudge.
324
- *
325
- * Scaling a shared delay by a factor near 1 keeps the herd together; drawing
326
- * from the whole interval is what actually spreads it.
327
- */
328
- function jittered(computed, maxDelayMs) {
329
- return Math.random() * Math.min(computed, maxDelayMs);
330
- }
331
- const MAX_CAUSE_DEPTH = 5;
332
- /**
333
- * The rate-limit marker on an error or anywhere in its `cause` chain.
334
- *
335
- * Layers above the provider rewrap errors — the ILlm adapter turns anything
336
- * thrown into an `LlmError` — so the marker is rarely still on the outermost
337
- * object by the time a retry decorator inspects it. Bounded by depth and a
338
- * visited set, like `extractStatusCode`, so a cyclic chain cannot hang.
339
- */
340
- export function findRateLimit(err) {
341
- const visited = new Set();
342
- let cur = err;
343
- for (let depth = 0; depth < MAX_CAUSE_DEPTH; depth++) {
344
- if (typeof cur !== 'object' || cur === null || visited.has(cur))
345
- return undefined;
346
- visited.add(cur);
347
- if (isRateLimitedError(cur))
348
- return cur;
349
- cur = cur.cause;
350
- }
351
- return undefined;
352
- }
353
- /**
354
- * Carry the rate-limit facts onto a provider's own error.
355
- *
356
- * Every provider catches its transport error and rethrows something friendlier.
357
- * That is fine for a message and fatal for a fact: the 429 would be lost at the
358
- * exact boundary where the consumer needs it. This moves the facts across.
359
- */
360
- export function preserveRateLimit(original, wrapped) {
361
- if (!isRateLimitedError(original))
362
- return wrapped;
363
- const w = wrapped;
364
- w.rateLimited = true;
365
- w.attempts = original.attempts;
366
- if (original.retryAfterSeconds !== undefined) {
367
- w.retryAfterSeconds = original.retryAfterSeconds;
368
- }
369
- return w;
370
- }
371
- /**
372
- * The shared pause outlasts what this caller said it would wait.
373
- *
374
- * There is no server error to annotate here — the request was never sent,
375
- * because sending it into a quota known to be closed is the one thing the gate
376
- * exists to prevent. It is still a rate limit, and says so, carrying what is
377
- * left of the pause so the consumer can decide.
378
- */
379
- function outOfBudgetAtGate(remainingMs, attempts) {
380
- const e = new Error('rate limited: the pause on this quota outlasts the configured wait budget');
381
- e.rateLimited = true;
382
- e.attempts = attempts;
383
- e.retryAfterSeconds = remainingMs / 1000;
384
- return e;
385
- }
386
- function annotate(error, attempts, retryAfterSeconds) {
387
- const e = (error instanceof Error ? error : new Error(String(error)));
388
- e.rateLimited = true;
389
- e.attempts = attempts;
390
- if (retryAfterSeconds !== undefined)
391
- e.retryAfterSeconds = retryAfterSeconds;
392
- return e;
393
- }
394
- //# sourceMappingURL=rate-limit.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rate-limit.js","sourceRoot":"","sources":["../../src/llm/rate-limit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAerE,MAAM,CAAC,MAAM,yBAAyB,GAAoB;IACxD,OAAO,EAAE,IAAI;IACb,WAAW,EAAE,CAAC;IACd,cAAc,EAAE,MAAM;IACtB,WAAW,EAAE,KAAK;IAClB,UAAU,EAAE,MAAM;CACnB,CAAC;AAWF,MAAM,UAAU,kB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;AAED,SAAS,QAAQ,CACf,KAAc,EACd,QAAgB,EAChB,iBAA0B;IAE1B,MAAM,CAAC,GAAG,CACR,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CACtC,CAAC;IACtB,CAAC,CAAC,WAAW,GAAG,IAAI,CAAC;IACrB,CAAC,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACtB,IAAI,iBAAiB,KAAK,SAAS;QAAE,CAAC,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC7E,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -1,29 +0,0 @@
1
- /**
2
- * Resolving an HTTP status from a thrown value.
3
- *
4
- * A leaf module on purpose: it imports nothing, so both the retry decorators
5
- * and the strategies in `interfaces/` can share one classification without a
6
- * cycle between the two layers. Which statuses are worth repeating is a
7
- * decision and lives in a strategy; what status this error carries is a fact
8
- * and lives here.
9
- */
10
- /**
11
- * Resolve an HTTP status from an unknown thrown value: own status/statusCode,
12
- * then the same walking `cause`, bounded by depth and a visited set so a cyclic
13
- * chain cannot hang. Returns undefined when no numeric status is present.
14
- */
15
- export declare function extractStatusCode(err: unknown): number | undefined;
16
- /**
17
- * Whether a thrown value matches one of a set of HTTP status codes.
18
- *
19
- * A structured status (own `status`/`statusCode`, or the same on `cause`) is
20
- * authoritative. Only when none is present does it fall back to the message,
21
- * and there it matches on **word boundaries** — a bare `includes('429')` also
22
- * fires on `4290`, an id, or a byte count, turning a hard error into a
23
- * multi-second backoff stall.
24
- *
25
- * Shared by the embedder decorator and the LLM failure strategy so the
26
- * classification cannot drift between them.
27
- */
28
- export declare function isRetryableStatus(err: unknown, retryOn: readonly number[]): boolean;
29
- //# sourceMappingURL=status.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/resilience/status.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAgBlE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,OAAO,CAKT"}
@@ -1,51 +0,0 @@
1
- /**
2
- * Resolving an HTTP status from a thrown value.
3
- *
4
- * A leaf module on purpose: it imports nothing, so both the retry decorators
5
- * and the strategies in `interfaces/` can share one classification without a
6
- * cycle between the two layers. Which statuses are worth repeating is a
7
- * decision and lives in a strategy; what status this error carries is a fact
8
- * and lives here.
9
- */
10
- const MAX_CAUSE_DEPTH = 5;
11
- /**
12
- * Resolve an HTTP status from an unknown thrown value: own status/statusCode,
13
- * then the same walking `cause`, bounded by depth and a visited set so a cyclic
14
- * chain cannot hang. Returns undefined when no numeric status is present.
15
- */
16
- export function extractStatusCode(err) {
17
- const visited = new Set();
18
- let cur = err;
19
- for (let depth = 0; depth < MAX_CAUSE_DEPTH; depth++) {
20
- if (typeof cur !== 'object' || cur === null || visited.has(cur))
21
- return;
22
- visited.add(cur);
23
- const rec = cur;
24
- if (typeof rec.status === 'number')
25
- return rec.status;
26
- if (typeof rec.statusCode === 'number')
27
- return rec.statusCode;
28
- cur = rec.cause;
29
- }
30
- return undefined;
31
- }
32
- /**
33
- * Whether a thrown value matches one of a set of HTTP status codes.
34
- *
35
- * A structured status (own `status`/`statusCode`, or the same on `cause`) is
36
- * authoritative. Only when none is present does it fall back to the message,
37
- * and there it matches on **word boundaries** — a bare `includes('429')` also
38
- * fires on `4290`, an id, or a byte count, turning a hard error into a
39
- * multi-second backoff stall.
40
- *
41
- * Shared by the embedder decorator and the LLM failure strategy so the
42
- * classification cannot drift between them.
43
- */
44
- export function isRetryableStatus(err, retryOn) {
45
- const status = extractStatusCode(err);
46
- if (status !== undefined)
47
- return retryOn.includes(status);
48
- const msg = err instanceof Error ? err.message : String(err);
49
- return retryOn.some((code) => new RegExp(`\\b${code}\\b`).test(msg));
50
- }
51
- //# sourceMappingURL=status.js.map