narrarium-engine 0.1.6 → 0.1.7
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/README.md +45 -9
- package/dist/ai/config.d.ts +22 -0
- package/dist/ai/config.d.ts.map +1 -1
- package/dist/ai/config.js +19 -0
- package/dist/ai/config.js.map +1 -1
- package/dist/ai/deadlines.d.ts +79 -0
- package/dist/ai/deadlines.d.ts.map +1 -0
- package/dist/ai/deadlines.js +151 -0
- package/dist/ai/deadlines.js.map +1 -0
- package/dist/ai/fetch-client.d.ts +41 -5
- package/dist/ai/fetch-client.d.ts.map +1 -1
- package/dist/ai/fetch-client.js +369 -125
- package/dist/ai/fetch-client.js.map +1 -1
- package/dist/ai/request.d.ts +3 -1
- package/dist/ai/request.d.ts.map +1 -1
- package/dist/ai/request.js +3 -1
- package/dist/ai/request.js.map +1 -1
- package/dist/ai/types.d.ts +32 -1
- package/dist/ai/types.d.ts.map +1 -1
- package/dist/ai/types.js +1 -0
- package/dist/ai/types.js.map +1 -1
- package/dist/autopilot/errors.d.ts +2 -1
- package/dist/autopilot/errors.d.ts.map +1 -1
- package/dist/autopilot/errors.js +25 -1
- package/dist/autopilot/errors.js.map +1 -1
- package/dist/autopilot/types.d.ts +8 -1
- package/dist/autopilot/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ npm install narrarium-engine
|
|
|
21
21
|
| Ghostwriters | `parseGhostwriter`, `ghostwriterPrompt` |
|
|
22
22
|
| Markdown | `parseMarkdown` (with `error`), `splitFrontmatter`, `stripFrontmatter`, `renderMarkdown`, `FrontmatterError` |
|
|
23
23
|
| Text | `clipMiddle`, `truncate`, `tail`, `countWords`, `languageCode`, `tokensPerWord`, `scaleOutputTokens`, `sceneCharacterLimit` |
|
|
24
|
-
| AI | `AiPort` (the only door to language models), `createFetchAi` (OpenAI, Azure OpenAI, GitHub Models), `buildChatRequest`, `resolveAiCandidates`, `pickAiRuntimeConfig`, `effectiveAiBase`, `endpointOrigin`, `redactSecrets` |
|
|
24
|
+
| AI | `AiPort` (the only door to language models), `createFetchAi` (OpenAI, Azure OpenAI, GitHub Models), `buildChatRequest`, `resolveAiCandidates`, `pickAiRuntimeConfig`, `effectiveAiBase`, `endpointOrigin`, `redactSecrets`, the deadlines and limits of a call (`DEFAULT_REQUEST_TIMEOUT_MS`, `MIN_REQUEST_TIMEOUT_MS`, `DEFAULT_IDLE_TIMEOUT_MS`, `TOTAL_REQUEST_CAP_MS`, `MAX_STREAM_TRANSPORT_BYTES`…) |
|
|
25
25
|
| Personal server | `NarrariumServerClient`, `pairWithServer`, `pairWithServerDetailed`, `verifyServerIdentity`, `serverCompatibility`, `serverSupportsAutopilotControls`, `serverSupportsAutopilotRules`, `remoteBookStore`, protocol types (scopes, pairing, updates), `ServerSentEventParser` |
|
|
26
26
|
| Sync | `planFileSync`, `syncBookStores` (three-way sync of two book stores, with the files it leaves out in `skipped`) |
|
|
27
27
|
| Testing | `narrarium-engine/testing`: `MemoryBookStore`, `seedBookFiles`, `createFakeAutopilotAi` |
|
|
@@ -130,7 +130,7 @@ Data the web app's pages used to have to guess (from the text of a step, from th
|
|
|
130
130
|
|---|---|
|
|
131
131
|
| `auth` | 401 or 403: a key, or a permission. |
|
|
132
132
|
| `rate_limit` | 429. |
|
|
133
|
-
| `timeout` | The request ran out of time (`timedOut
|
|
133
|
+
| `timeout` | The request ran out of time (`timedOut`: the provider did not begin answering, it went silent, or the call took too long), or 408. |
|
|
134
134
|
| `network` | The provider could not be reached, or the connection dropped: no status, `transient`, or the words of a network failure. |
|
|
135
135
|
| `provider` | Any other failure of the provider (another 4xx or 5xx, an error inside the stream) or of its reply (`AiReplyRejectedError`, a reply that is not JSON). |
|
|
136
136
|
| `truncated` | The reply was cut by the output limit (`truncated`, `reasoningOnly` included). |
|
|
@@ -141,7 +141,7 @@ Data the web app's pages used to have to guess (from the text of a step, from th
|
|
|
141
141
|
| `conflict` | A file changed under the step and the retries are used up (`BookConflictError`). |
|
|
142
142
|
| `unknown` | Everything else. |
|
|
143
143
|
|
|
144
|
-
`errorDetail` is `{ status?, endpoint?, model?, provider?, integration?, attempt?, retries? }`, short and with no secret in any field: `status` is the HTTP status when the provider answered; `endpoint` is only the **origin** of the integration's address (`new URL(address).origin`: never a path, a query, a fragment or credentials, and nothing at all for an address that is not a web address); `model`, `provider` and `integration` (the id) are passed through `redactSecrets` and cut at 160 characters. `attempt` and `retries` are there only for a failure that is retried: the retry it belongs to (the one that followed it, or the last one made when the run gave up) and how many retries this kind of failure gets, the numbers of the `failureRetry` insight; a failure that is never retried (a 401) has neither. Where an error came from is `AiProviderError.target` (`{ provider, model, integrationId, endpoint? }`, the endpoint already an origin), which the engine's client sets on the error of the last candidate it tried; it is separate from the error's own `model`, `provider` and `integrationId`, whose presence means that the model had started to answer and is billed. A state written before the errors were classified has `lastError` with a message and no kind: `summary.lastError` then has none either.
|
|
144
|
+
`errorDetail` is `{ status?, endpoint?, model?, provider?, integration?, attempt?, retries?, timeoutMs?, timeoutPhase? }`, short and with no secret in any field: `status` is the HTTP status when the provider answered; `endpoint` is only the **origin** of the integration's address (`new URL(address).origin`: never a path, a query, a fragment or credentials, and nothing at all for an address that is not a web address); `model`, `provider` and `integration` (the id) are passed through `redactSecrets` and cut at 160 characters. `attempt` and `retries` are there only for a failure that is retried: the retry it belongs to (the one that followed it, or the last one made when the run gave up) and how many retries this kind of failure gets, the numbers of the `failureRetry` insight; a failure that is never retried (a 401) has neither. `timeoutPhase` (`"start"`, `"idle"` or `"total"`) and `timeoutMs` are there only for a timeout of the engine's client: which deadline ran out (the provider did not begin answering, it went silent while it answered, or the call took longer than any call may) and how long it was, in milliseconds (a value read from a file is a whole number from 1 ms to a day, else it is dropped); see *Timeouts and streaming*. Where an error came from is `AiProviderError.target` (`{ provider, model, integrationId, endpoint? }`, the endpoint already an origin), which the engine's client sets on the error of the last candidate it tried; it is separate from the error's own `model`, `provider` and `integrationId`, whose presence means that the model had started to answer and is billed. A state written before the errors were classified has `lastError` with a message and no kind: `summary.lastError` then has none either.
|
|
145
145
|
|
|
146
146
|
**The retry that is waiting.** While the run waits to try a failed step again, `summary.retry` is `{ at, attempt, retries }`: `at` is the ISO time of the next attempt, `attempt` and `retries` those of the `failureRetry` insight (`retry 2 of 3`). It is never saved, and it is the fourth field of the summary that only a live session knows (see *What the summary says*). Every change is a `state` event, so a client counts down without guessing: one event when the wait begins (right after the `failureRetry` insight), one when it is over and the attempt starts (the summary has no `retry` then), and the last summary of a run that ends, or is paused, during the wait has none. A host that gets the state from a `state` event replaces its summary by the newest one it has seen, and so the retry goes away.
|
|
147
147
|
|
|
@@ -218,7 +218,8 @@ Limits on the reply of a step are sized for Latin script (2.4 tokens a word) and
|
|
|
218
218
|
|---|---|
|
|
219
219
|
| `fetch` | The `fetch` to use (default the global one). |
|
|
220
220
|
| `githubModelsBaseUrl` | Origin of GitHub Models, or of a proxy that forwards `/inference`. |
|
|
221
|
-
| `defaultTimeoutMs` |
|
|
221
|
+
| `defaultTimeoutMs` | The time the provider has to begin answering for an integration that has no `requestTimeoutMs` (default `DEFAULT_REQUEST_TIMEOUT_MS`). |
|
|
222
|
+
| `minimumTimeoutMs` | The shortest start or idle deadline a call is given (default `MIN_REQUEST_TIMEOUT_MS`, 30 s). It is there for tests that count in milliseconds; a host has no reason to lower it. See *Timeouts and streaming*. |
|
|
222
223
|
| `onAttempt`, `onAttemptEnd` | Hooks that see every attempt that is sent and how it ended (below). |
|
|
223
224
|
| `acknowledgeFallback` | Asked before content goes to an integration of another account than the one it went to so far (below). |
|
|
224
225
|
|
|
@@ -226,16 +227,51 @@ What every host gets, whatever its options:
|
|
|
226
227
|
|
|
227
228
|
| What | How |
|
|
228
229
|
|---|---|
|
|
229
|
-
| Request | `buildChatRequest(candidate, request, { githubModelsBaseUrl })` is the only place a request is built: URL, headers, body, streaming, tools or JSON-in-prompt, and the output limit parameter of the model family. Pure and exported, so hosts can test their configuration against it. |
|
|
230
|
+
| Request | `buildChatRequest(candidate, request, { githubModelsBaseUrl })` is the only place a request is built: URL, headers, body, streaming, tools or JSON-in-prompt, and the output limit parameter of the model family. Pure and exported, so hosts can test their configuration against it. Every request streams (`stream: true`, `stream_options: { include_usage: true }`), a structured one included, unless the integration's `streamMode` is `"off"`: see *Timeouts and streaming*. |
|
|
230
231
|
| Output limit | A structured request gets at least `STRUCTURED_OUTPUT_FLOOR` (4096) tokens. A model known to reason by name (o1/o3/o4, gpt-5, codex-mini; for Azure the declared underlying model, else the deployment name) gets `REASONING_OUTPUT_MARGIN` (12 000) more, because its reasoning is counted in the limit. Never above the model's own `maxOutputTokens`. An Azure deployment of unknown identity gets `max_completion_tokens` from API version 2024-09-01, `max_tokens` before. |
|
|
231
232
|
| Prompt size | A candidate whose `maxInputTokens` (context window) cannot hold the prompt (estimated with `likelyMessageTokens`, the tool schema included, against `resolveModelTokenBudgets`: window minus the output reserve minus a 5% margin) is skipped. If no candidate can, `AiPromptTooLargeError` (not retryable) gives the estimate and the largest budget. A prompt is never cut. |
|
|
232
233
|
| Privacy of fallbacks | `fallbackDisclosure.sameBoundaryOnly` excludes fallbacks outside the primary's integration (the boundary). `requireAcknowledgement` asks `options.acknowledgeFallback(from, to, { capability, label })` before content goes to an integration it has not gone to: only `true` allows it, a throw cancels the call, and a host without the hook (the server) never crosses (fail closed). The engine asks at every call that needs the crossing (once per pair of accounts within a call), so a host that remembers acknowledgements answers from its memory. When nothing is left to call, the error names the setting and how to change it. |
|
|
233
234
|
| Routing limits | `routingExecution`: `maxCandidates`, `maxTotalDurationMs`, `maxTokenAttempts`, `maxEstimatedCost`. The total time never interrupts the first candidate before its own timeout; later candidates start only while time remains and run for what remains. Tokens and cost are estimated per attempt from the real prompt and the output limit (reasoning margin included): candidates are kept while the sum fits, and a first attempt that alone exceeds a limit gives `AiRoutingBudgetError`. A configuration without these fields (saved by an older host) has no such limits and no privacy policy. |
|
|
234
|
-
|
|
|
235
|
-
| Hooks | `onAttempt(attempt)`: `attemptId`, the effective `messages` (with the JSON instruction a model without tools receives), the output limit, `stream`, `tools`, `endpoint` and `
|
|
235
|
+
| Timeouts | Three, in every host: how long the provider has to begin answering (an integration's `requestTimeoutMs`, else `options.defaultTimeoutMs`, else `DEFAULT_REQUEST_TIMEOUT_MS`, 600 s; never under 30 s), the longest silence while it answers (`idleTimeoutMs`, 600 s) and the most one call may take (4 h). See *Timeouts and streaming*. |
|
|
236
|
+
| Hooks | `onAttempt(attempt)`: `attemptId`, the effective `messages` (with the JSON instruction a model without tools receives), the output limit, `stream`, `streamMode`, `tools`, `endpoint`, `timeoutMs` and `timeouts` (the three deadlines: see *Timeouts and streaming*). `onAttemptEnd(end)`: the same `attemptId`, `outcome` (`ok`, `failed`, `cancelled`), `usage`, `cost`, `usageKnown`, `costKnown`, the reply `text` or the `error` (without credentials), `failureKind` (`timeout`, `cancelled`, `provider`), `status`, `retryAfterMs`, `timeoutMs` and `timeoutPhase` (for a timeout), `streamed`, `firstByteMs`, `toolCalled` and `durationMs`, for every attempt that was sent, failed ones included. A hook that throws never breaks a call. |
|
|
236
237
|
| Approving endpoints | `effectiveAiBase(integration, githubModelsBaseUrl?)` is the origin and path every request of an integration starts with, defaults included (`https://api.openai.com/v1`, `https://models.github.ai/inference`). A host that approves where API keys may be sent should compare these. |
|
|
237
|
-
| Wire format | Server-sent events with several `data:` lines are joined with a newline; a JSON reply to a streaming request (a server that ignores `stream`) is read as the reply; an `error` in a 200 reply is a provider error. |
|
|
238
|
-
| Errors | `AiProviderError` carries `status`, `retryable`, `transient` (it depends on the moment: 408, 429, 502, 503, 504, network), `retryAfterMs` (the `Retry-After` of a 429 or 503, at most five minutes), `timedOut
|
|
238
|
+
| Wire format | Server-sent events with several `data:` lines are joined with a newline; the pieces of a forced function call (`delta.tool_calls[].function.arguments`) are joined into the arguments of the reply, and a last piece that carries the whole `message.tool_calls` is read too; a JSON reply to a streaming request (a server that ignores `stream`) is read as the reply; an `error` in a 200 reply is a provider error. |
|
|
239
|
+
| Errors | `AiProviderError` carries `status`, `retryable`, `transient` (it depends on the moment: 408, 429, 502, 503, 504, network), `retryAfterMs` (the `Retry-After` of a 429 or 503, at most five minutes), `timedOut` with `timeout` (which deadline ran out, for how long), `truncated` and `reasoningOnly`. Keys, `Bearer …`, `api-key: …`, `?key=…` and `sk-…` are removed from every message (`redactSecrets`), also before the runner saves it. The error of a candidate that was tried carries `target` (`{ provider, model, integrationId, endpoint? }`, the endpoint only an origin: see *What the interface reads*). |
|
|
240
|
+
|
|
241
|
+
### Timeouts and streaming
|
|
242
|
+
|
|
243
|
+
*Why.* A slow model (a 30B one) behind a proxy used to fail every time with "request timed out": the client had **one** absolute timer for the whole call, and a structured reply (a forced function call) was never streamed, so the only thing that arrived was the whole answer once the model had finished. Any timeout shorter than the generation failed, and even a long one could be cut by a proxy or a tunnel that closes a connection that stays silent (100 s is typical). Now the deadlines are separate and every reply streams, so a model that is alive is never silent and a connection that is dead is found.
|
|
244
|
+
|
|
245
|
+
**The deadlines** of one call, in every host:
|
|
246
|
+
|
|
247
|
+
| Deadline | What it limits | Default | Where it is set |
|
|
248
|
+
|---|---|---|---|
|
|
249
|
+
| **Start** | From sending the request until the headers arrive (the connection included). For a request that does not stream (`streamMode: "off"`) it is the whole call, body included, as it always was. | 600 s (`DEFAULT_REQUEST_TIMEOUT_MS`), never under 30 s (`MIN_REQUEST_TIMEOUT_MS`) | The integration's `requestTimeoutMs`, else `options.defaultTimeoutMs`. A lower value (6000) is **raised to 30 s when the call is made** and says so; the configuration keeps what the author wrote. |
|
|
250
|
+
| **Idle** | The longest silence between two pieces of a stream, from the headers on. Every byte starts it again, a comment such as `: keep-alive` included. | 600 s (`DEFAULT_IDLE_TIMEOUT_MS`) | The integration's `idleTimeoutMs`, kept between 30 s and 3600 s (`MIN_IDLE_TIMEOUT_MS`, `MAX_IDLE_TIMEOUT_MS`). |
|
|
251
|
+
| **Total** | The whole call, whatever the provider keeps sending. | 4 h (`TOTAL_REQUEST_CAP_MS`) | Nowhere: it is not configurable. |
|
|
252
|
+
|
|
253
|
+
The author's `signal` wins over all three: a call cancelled is an `AbortError` and never a timeout, even when a deadline runs out at the same moment. `routingExecution.maxTotalDurationMs` is unchanged: the first candidate runs for its own deadlines, and a later one for the routing time that is left, which limits all three and which no minimum raises. No timer outlives a call, however it ended.
|
|
254
|
+
|
|
255
|
+
**Streaming.** `integration.streamMode` is `"auto"` (the default) or `"off"` (`pickAiRuntimeConfig` leaves out anything else). In `auto` **every** chat request streams, the forced function of a structured one included (`stream`, `tools` and `tool_choice` travel together). The arguments of the function arrive in pieces (`choices[].delta.tool_calls[].function.arguments`): the reader joins them by `index` (a piece without one belongs to the only call there is), takes the call of the function that was asked for, else the first, and ignores any other; a stream whose last piece carries the whole `message.tool_calls` is understood as well. The joined arguments are what `structuredFromReply` reads, exactly as before, and their characters are what an estimated `usage` counts when the provider reports none. `"off"` never streams: use it for a provider or a proxy that cannot. A JSON body in answer to a streaming request (a server that ignores `stream`) is read as a whole. Prose is unchanged: `onText` gets the text so far (and once, whole, for a reply that came as one JSON body). For a structured request `onText` is never called.
|
|
256
|
+
|
|
257
|
+
**Node's own limits.** In Node the platform's `fetch` (undici) has two limits of its own, 300 s each, whatever the engine's deadlines say: `headersTimeout` (the headers of a response) and `bodyTimeout` (the silence between two pieces of a body). A host that runs the engine in Node and wants a longer silence than five minutes (a model that thinks for ten without sending anything) passes, as `options.fetch`, a `fetch` over a dispatcher with those two raised, or off (`0`).
|
|
258
|
+
|
|
259
|
+
**Progress.** `AiRequest.onProgress({ bytes, events, characters })` is called while a reply streams, at most every 250 ms, with numbers and never a word of the reply: the bytes received (comments included), the events of the stream and the characters of the reply so far (text and function arguments, not reasoning). It is how a host says "the model is answering (12 KB)" for a structured reply. A listener that throws never breaks the call.
|
|
260
|
+
|
|
261
|
+
**Closures and limits.** A stream that closes without `[DONE]` and without a `finish_reason` is still *incomplete* (retried as a transient failure); the reader is cancelled however a call ends, the end of the stream aside: after `[DONE]`, an error in the stream, a deadline, the author's cancel. Two limits stop a model that loops: **256 MB** of transport (`MAX_STREAM_TRANSPORT_BYTES`; the JSON envelope of every piece counts) and **16 million characters** of reasoning (`MAX_STREAM_REASONING_CHARACTERS`). Each is an error that says what it used and what to do ("Lower the thinking effort of the model or choose another one") and is **not** retried, because the same loop would come back; what it used is counted in the cost.
|
|
262
|
+
|
|
263
|
+
**What a timeout says.** The `AiProviderError` of a timeout is `timedOut`, `transient` and `retryable` as ever (the run retries it like any transient failure, and its `errorKind` is `timeout`), and carries `timeout: { phase: "start" | "idle" | "total", ms, raisedFrom? }`, which is also in `errorDetail` as `timeoutPhase` and `timeoutMs` (see *What the interface reads*). The message, in English and without a key or an address, says which deadline ran out, how long it was and where it is changed:
|
|
264
|
+
|
|
265
|
+
- `openai muse-glimmer-30b: the provider did not start answering within 30 s (the "Provider timeout" of the integration "LlmProxy" was 6 s and was raised to the 30 s minimum)`
|
|
266
|
+
- `openai muse-glimmer-30b: the provider sent nothing for 600 s while answering (the "Idle timeout" of the integration "LlmProxy")`
|
|
267
|
+
- `openai muse-glimmer-30b: the provider did not finish within 4 h (the longest one request may take: it cannot be changed)`
|
|
268
|
+
- a later candidate cut by the routing time: `…: request timed out: the provider did not finish within the 150 ms left of the total routing time (maxTotalDurationMs)`
|
|
269
|
+
|
|
270
|
+
An integration without its own value says `the default provider timeout` or `the default idle timeout` and where to change it.
|
|
271
|
+
|
|
272
|
+
**What the hooks say.** `onAttempt(attempt)` carries `timeouts: { startMs, idleMs, capMs, raised?: { from } }` (the deadlines as they are applied, `raised` when the minimum lifted the provider timeout) and `streamMode`; `timeoutMs` is `timeouts.startMs`. `onAttemptEnd(end)` carries `streamed` (the reply was read as a stream), `firstByteMs` (milliseconds to the first byte of its body, or of the response for a JSON reply; absent when nothing arrived), `toolCalled` (for a structured request, whether the model delivered the result as a function call; absent otherwise) and, for a timeout, `timeoutMs` and `timeoutPhase`.
|
|
273
|
+
|
|
274
|
+
**Providers that cannot stream.** A provider that rejects `stream_options`, or does not stream with functions, answers 400: the error then adds `If this provider cannot stream its replies, set "Streaming" of the integration "…" to "off"` (only when its own message talks about streaming), and `streamMode: "off"` brings the old behavior back for that integration. A connection that is lost while the provider answers is told with what to check: the proxy or the tunnel between the app and the provider.
|
|
239
275
|
|
|
240
276
|
### Costs and budgets
|
|
241
277
|
|
package/dist/ai/config.d.ts
CHANGED
|
@@ -16,6 +16,16 @@ export interface AiChatModelConfig {
|
|
|
16
16
|
maxOutputTokens?: number;
|
|
17
17
|
pricing?: AiPricingConfig;
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Whether requests ask for a streamed reply: `auto` (the default) streams every chat request, the forced function of a structured one
|
|
21
|
+
* included, so that a provider that answers slowly is never silent; `off` never streams, for a provider or a proxy that cannot.
|
|
22
|
+
*/
|
|
23
|
+
export type AiStreamMode = "auto" | "off";
|
|
24
|
+
/** The longest silence the engine waits for between two pieces of a streamed reply, unless the integration says otherwise. */
|
|
25
|
+
export declare const DEFAULT_IDLE_TIMEOUT_MS = 600000;
|
|
26
|
+
/** An integration's idle timeout is kept within these limits. */
|
|
27
|
+
export declare const MIN_IDLE_TIMEOUT_MS = 30000;
|
|
28
|
+
export declare const MAX_IDLE_TIMEOUT_MS = 3600000;
|
|
19
29
|
export interface AiIntegrationConfig {
|
|
20
30
|
id: string;
|
|
21
31
|
name: string;
|
|
@@ -23,7 +33,15 @@ export interface AiIntegrationConfig {
|
|
|
23
33
|
endpoint?: string;
|
|
24
34
|
apiKey: string;
|
|
25
35
|
apiVersion?: string;
|
|
36
|
+
/**
|
|
37
|
+
* How long the provider has to begin answering (the connection and the headers), as the author wrote it. A call raises a value
|
|
38
|
+
* under `MIN_REQUEST_TIMEOUT_MS` to that minimum and says so; the configuration is never changed.
|
|
39
|
+
*/
|
|
26
40
|
requestTimeoutMs?: number;
|
|
41
|
+
/** The longest silence between two pieces of a streamed reply (`DEFAULT_IDLE_TIMEOUT_MS`; kept within 30 s and an hour). */
|
|
42
|
+
idleTimeoutMs?: number;
|
|
43
|
+
/** Absent: `auto`. */
|
|
44
|
+
streamMode?: AiStreamMode;
|
|
27
45
|
chatModels?: AiChatModelConfig[];
|
|
28
46
|
/** @deprecated legacy single-model fields, still honored. */
|
|
29
47
|
modelWriting?: string;
|
|
@@ -80,6 +98,10 @@ export interface RedactedAiIntegration {
|
|
|
80
98
|
provider: AiProviderKind;
|
|
81
99
|
endpoint?: string;
|
|
82
100
|
hasApiKey: boolean;
|
|
101
|
+
/** The longest silence between two pieces of a streamed reply, when the integration sets one. */
|
|
102
|
+
idleTimeoutMs?: number;
|
|
103
|
+
/** Whether replies stream, when the integration says (absent: `auto`). */
|
|
104
|
+
streamMode?: AiStreamMode;
|
|
83
105
|
models: Array<{
|
|
84
106
|
name: string;
|
|
85
107
|
capabilities: string[];
|
package/dist/ai/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/ai/config.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,cAAc,GAAG,QAAQ,GAAG,eAAe,GAAG,cAAc,CAAC;AAE1F,+EAA+E;AAC/E,eAAO,MAAM,yBAAyB,eAAe,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAA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C,EAAE,MAAM,CAAC;IACrC,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wFAAwF;IACxF,kBAAkB,CAAC,EAAE,oBAAoB,CAAC;IAC1C,sIAAsI;IACtI,gBAAgB,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAChD;AA2CD,oHAAoH;AACpH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,OAAO,GAAG,kBAAkB,CAY1E;AAMD,0GAA0G;AAC1G,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,OAAO,GAAG,eAAe,CA6DtE;AAED,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,cAAc,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,iGAAiG;IACjG,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,0EAA0E;IAC1E,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;CACzD;AAED,4DAA4D;AAC5D,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,eAAe,GAAG;IAAE,YAAY,EAAE,qBAAqB,EAAE,CAAC;IAAC,WAAW,EAAE,MAAM,EAAE,CAAC;IAAC,kBAAkB,CAAC,EAAE,oBAAoB,CAAC;IAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAA;CAAE,CAgB1N"}
|
package/dist/ai/config.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/** The Azure OpenAI API version used when an integration does not name one. */
|
|
2
2
|
export const DEFAULT_AZURE_API_VERSION = "2024-10-21";
|
|
3
|
+
/** The longest silence the engine waits for between two pieces of a streamed reply, unless the integration says otherwise. */
|
|
4
|
+
export const DEFAULT_IDLE_TIMEOUT_MS = 600_000;
|
|
5
|
+
/** An integration's idle timeout is kept within these limits. */
|
|
6
|
+
export const MIN_IDLE_TIMEOUT_MS = 30_000;
|
|
7
|
+
export const MAX_IDLE_TIMEOUT_MS = 3_600_000;
|
|
3
8
|
/** The web app's defaults for the routing limits. */
|
|
4
9
|
export const DEFAULT_ROUTING_EXECUTION = Object.freeze({
|
|
5
10
|
maxCandidates: 4,
|
|
@@ -17,6 +22,14 @@ function text(value) {
|
|
|
17
22
|
function positive(value) {
|
|
18
23
|
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined;
|
|
19
24
|
}
|
|
25
|
+
function streamMode(value) {
|
|
26
|
+
return value === "auto" || value === "off" ? value : undefined;
|
|
27
|
+
}
|
|
28
|
+
/** An idle timeout as the engine keeps it: a whole number of milliseconds within 30 s and an hour. What is not a number is no value. */
|
|
29
|
+
function idleTimeout(value) {
|
|
30
|
+
const milliseconds = positive(value);
|
|
31
|
+
return milliseconds === undefined ? undefined : Math.min(MAX_IDLE_TIMEOUT_MS, Math.max(MIN_IDLE_TIMEOUT_MS, Math.round(milliseconds)));
|
|
32
|
+
}
|
|
20
33
|
function pricing(value) {
|
|
21
34
|
const source = record(value);
|
|
22
35
|
const output = {};
|
|
@@ -77,6 +90,8 @@ export function pickAiRuntimeConfig(settings) {
|
|
|
77
90
|
pricing: pricing(model.pricing),
|
|
78
91
|
});
|
|
79
92
|
}
|
|
93
|
+
const idleTimeoutMs = idleTimeout(item.idleTimeoutMs);
|
|
94
|
+
const mode = streamMode(item.streamMode);
|
|
80
95
|
integrations.push({
|
|
81
96
|
id,
|
|
82
97
|
name: text(item.name) ?? provider,
|
|
@@ -85,6 +100,8 @@ export function pickAiRuntimeConfig(settings) {
|
|
|
85
100
|
apiKey: typeof item.apiKey === "string" ? item.apiKey.trim() : "",
|
|
86
101
|
apiVersion: text(item.apiVersion),
|
|
87
102
|
requestTimeoutMs: positive(item.requestTimeoutMs),
|
|
103
|
+
...(idleTimeoutMs !== undefined ? { idleTimeoutMs } : {}),
|
|
104
|
+
...(mode ? { streamMode: mode } : {}),
|
|
88
105
|
chatModels,
|
|
89
106
|
modelWriting: text(item.modelWriting),
|
|
90
107
|
modelReview: text(item.modelReview),
|
|
@@ -121,6 +138,8 @@ export function redactAiRuntimeConfig(config) {
|
|
|
121
138
|
provider: integration.provider,
|
|
122
139
|
endpoint: integration.endpoint,
|
|
123
140
|
hasApiKey: Boolean(integration.apiKey),
|
|
141
|
+
...(integration.idleTimeoutMs !== undefined ? { idleTimeoutMs: integration.idleTimeoutMs } : {}),
|
|
142
|
+
...(integration.streamMode ? { streamMode: integration.streamMode } : {}),
|
|
124
143
|
models: (integration.chatModels ?? []).map((model) => ({ name: model.name, capabilities: model.capabilities })),
|
|
125
144
|
})),
|
|
126
145
|
routedTasks: Object.keys(config.taskRouting ?? {}).sort(),
|
package/dist/ai/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/ai/config.ts"],"names":[],"mappings":"AAEA,+EAA+E;AAC/E,MAAM,CAAC,MAAM,yBAAyB,GAAG,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/ai/config.ts"],"names":[],"mappings":"AAEA,+EAA+E;AAC/E,MAAM,CAAC,MAAM,yBAAyB,GAAG,YAAY,CAAC;AAyBtD,8HAA8H;AAC9H,MAAM,CAAC,MAAM,uBAAuB,GAAG,OAAO,CAAC;AAC/C,iEAAiE;AACjE,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC;AAC1C,MAAM,CAAC,MAAM,mBAAmB,GAAG,SAAS,CAAC;AAmD7C,qDAAqD;AACrD,MAAM,CAAC,MAAM,yBAAyB,GAAiC,MAAM,CAAC,MAAM,CAAC;IACnF,aAAa,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AAC,CAAC,EAAE,CAAC;KAClF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type AiIntegrationConfig } from "./config.js";
|
|
2
|
+
import type { AiTimeoutPhase } from "./types.js";
|
|
3
|
+
/** How long the provider has to begin answering (the connection and the headers) when nobody says, for every host. An integration's own timeout wins. */
|
|
4
|
+
export declare const DEFAULT_REQUEST_TIMEOUT_MS = 600000;
|
|
5
|
+
/** The shortest time a provider is given to begin answering: a smaller value is raised to it when a call is made, and the call says so. */
|
|
6
|
+
export declare const MIN_REQUEST_TIMEOUT_MS = 30000;
|
|
7
|
+
/** The most one attempt may take, whatever the provider keeps sending: four hours. It is not configurable. */
|
|
8
|
+
export declare const TOTAL_REQUEST_CAP_MS: number;
|
|
9
|
+
/** The deadlines one attempt runs under, already limited by the routing time that is left. */
|
|
10
|
+
export interface AttemptDeadlines {
|
|
11
|
+
/** How long the provider has to begin answering: the connection and the headers. */
|
|
12
|
+
startMs: number;
|
|
13
|
+
/** The longest silence between two pieces of a streamed reply. */
|
|
14
|
+
idleMs: number;
|
|
15
|
+
/** The most the attempt may take, whatever the provider keeps sending. */
|
|
16
|
+
capMs: number;
|
|
17
|
+
}
|
|
18
|
+
/** The deadlines of an attempt and what is needed to explain them in an error. */
|
|
19
|
+
export interface ResolvedDeadlines extends AttemptDeadlines {
|
|
20
|
+
/** The shortest start or idle deadline an attempt is given. */
|
|
21
|
+
minimumMs: number;
|
|
22
|
+
/** The provider timeout the integration asked for, when the minimum raised it (and the raise is what the attempt runs for). */
|
|
23
|
+
raisedFrom?: number;
|
|
24
|
+
/** Whether the start and the idle deadline are the integration's own, or the defaults. */
|
|
25
|
+
startOwn: boolean;
|
|
26
|
+
idleOwn: boolean;
|
|
27
|
+
/** The routing time that was left, when it is what limits this attempt (a later candidate of a routed call). */
|
|
28
|
+
routingMs?: number;
|
|
29
|
+
}
|
|
30
|
+
export interface DeadlineOptions {
|
|
31
|
+
/** Used when an integration has no provider timeout. */
|
|
32
|
+
defaultTimeoutMs?: number;
|
|
33
|
+
/** Replaces the minimum of the start and of the idle deadline (`MIN_REQUEST_TIMEOUT_MS`): for tests that count in milliseconds. */
|
|
34
|
+
minimumTimeoutMs?: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The deadlines of one attempt. The start deadline is the integration's provider timeout, else the host's default, else 600 s, and never
|
|
38
|
+
* under the minimum (30 s). The idle deadline is the integration's, else 600 s, kept between the minimum and an hour. The cap is four hours.
|
|
39
|
+
* What is left of the routing time (`maxTotalDurationMs`) limits all three of a later candidate, and no minimum raises that.
|
|
40
|
+
*/
|
|
41
|
+
export declare function resolveDeadlines(integration: Pick<AiIntegrationConfig, "requestTimeoutMs" | "idleTimeoutMs">, options?: DeadlineOptions, routingLeftMs?: number): ResolvedDeadlines;
|
|
42
|
+
/** The deadline that ran out: which one, and how long it was. */
|
|
43
|
+
export interface ExpiredDeadline {
|
|
44
|
+
phase: AiTimeoutPhase;
|
|
45
|
+
ms: number;
|
|
46
|
+
}
|
|
47
|
+
/** A duration as a person says it: `150 ms`, `30 s`, `1.5 s`, `4 h`. */
|
|
48
|
+
export declare function formatDuration(milliseconds: number): string;
|
|
49
|
+
/**
|
|
50
|
+
* What a timeout says: which deadline ran out, how long it was and where it is changed, without a key or an address.
|
|
51
|
+
* `label` is `provider model`, and `integration` the name the author gave the integration.
|
|
52
|
+
*/
|
|
53
|
+
export declare function timeoutMessage(label: string, expired: ExpiredDeadline, deadlines: ResolvedDeadlines, integration: string): string;
|
|
54
|
+
/** What watches one attempt: the author's signal and the three deadlines. */
|
|
55
|
+
export interface DeadlineClock {
|
|
56
|
+
/** For `fetch`: it aborts when the author cancels or a deadline runs out. */
|
|
57
|
+
readonly signal: AbortSignal;
|
|
58
|
+
/**
|
|
59
|
+
* Settles as `promise` does, unless the author cancels or a deadline runs out first: then it rejects at once, whatever `promise` does
|
|
60
|
+
* (a `fetch` or a stream that ignores its signal cannot hold the call).
|
|
61
|
+
*/
|
|
62
|
+
guard<T>(promise: Promise<T>): Promise<T>;
|
|
63
|
+
/** The reply began as a stream: the start deadline is over, and from now on the silence between two pieces is what is watched. */
|
|
64
|
+
streaming(): void;
|
|
65
|
+
/** Bytes arrived: the silence begins again. */
|
|
66
|
+
activity(): void;
|
|
67
|
+
/** The deadline that ran out, when one did (and the author had not cancelled first). */
|
|
68
|
+
expired(): ExpiredDeadline | undefined;
|
|
69
|
+
/** The call was cancelled, or ran out of time, or is over: a reply that arrives now is to be dropped. */
|
|
70
|
+
interrupted(): boolean;
|
|
71
|
+
/** Clears every timer and lets the connection go. Always to be called. */
|
|
72
|
+
dispose(): void;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Starts watching an attempt. The cap and the start deadline run from now; the idle deadline from the moment `streaming()` is called,
|
|
76
|
+
* and again from every `activity()`. The author's signal wins over every deadline: when both happen, the call is cancelled, never timed out.
|
|
77
|
+
*/
|
|
78
|
+
export declare function startClock(parent: AbortSignal | undefined, deadlines: AttemptDeadlines): DeadlineClock;
|
|
79
|
+
//# sourceMappingURL=deadlines.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deadlines.d.ts","sourceRoot":"","sources":["../../src/ai/deadlines.ts"],"names":[],"mappings":"AACA,OAAO,EAAgD,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACrG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,yJAAyJ;AACzJ,eAAO,MAAM,0BAA0B,SAAU,CAAC;AAClD,2IAA2I;AAC3I,eAAO,MAAM,sBAAsB,QAAS,CAAC;AAC7C,8GAA8G;AAC9G,eAAO,MAAM,oBAAoB,QAAqB,CAAC;AAEvD,8FAA8F;AAC9F,MAAM,WAAW,gBAAgB;IAC/B,oFAAoF;IACpF,OAAO,EAAE,MAAM,CAAC;IAChB,kEAAkE;IAClE,MAAM,EAAE,MAAM,CAAC;IACf,0EAA0E;IAC1E,K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;IAClB,+CAA+C;IAC/C,QAAQ,IAAI,IAAI,CAAC;IACjB,wFAAwF;IACxF,OAAO,IAAI,eAAe,GAAG,SAAS,CAAC;IACvC,yGAAyG;IACzG,WAAW,IAAI,OAAO,CAAC;IACvB,0EAA0E;IAC1E,OAAO,IAAI,IAAI,CAAC;CACjB;AAID;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,EAAE,SAAS,EAAE,gBAAgB,GAAG,aAAa,CA8DtG"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { abortError } from "../util/abort.js";
|
|
2
|
+
import { DEFAULT_IDLE_TIMEOUT_MS, MAX_IDLE_TIMEOUT_MS } from "./config.js";
|
|
3
|
+
/** How long the provider has to begin answering (the connection and the headers) when nobody says, for every host. An integration's own timeout wins. */
|
|
4
|
+
export const DEFAULT_REQUEST_TIMEOUT_MS = 600_000;
|
|
5
|
+
/** The shortest time a provider is given to begin answering: a smaller value is raised to it when a call is made, and the call says so. */
|
|
6
|
+
export const MIN_REQUEST_TIMEOUT_MS = 30_000;
|
|
7
|
+
/** The most one attempt may take, whatever the provider keeps sending: four hours. It is not configurable. */
|
|
8
|
+
export const TOTAL_REQUEST_CAP_MS = 4 * 60 * 60 * 1000;
|
|
9
|
+
function positiveNumber(value) {
|
|
10
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The deadlines of one attempt. The start deadline is the integration's provider timeout, else the host's default, else 600 s, and never
|
|
14
|
+
* under the minimum (30 s). The idle deadline is the integration's, else 600 s, kept between the minimum and an hour. The cap is four hours.
|
|
15
|
+
* What is left of the routing time (`maxTotalDurationMs`) limits all three of a later candidate, and no minimum raises that.
|
|
16
|
+
*/
|
|
17
|
+
export function resolveDeadlines(integration, options = {}, routingLeftMs) {
|
|
18
|
+
const minimumMs = positiveNumber(options.minimumTimeoutMs) ?? MIN_REQUEST_TIMEOUT_MS;
|
|
19
|
+
const ownStart = positiveNumber(integration.requestTimeoutMs);
|
|
20
|
+
const written = ownStart ?? positiveNumber(options.defaultTimeoutMs) ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
21
|
+
const ownIdle = positiveNumber(integration.idleTimeoutMs);
|
|
22
|
+
let capMs = TOTAL_REQUEST_CAP_MS;
|
|
23
|
+
let routingMs;
|
|
24
|
+
if (routingLeftMs !== undefined) {
|
|
25
|
+
const left = Math.max(1, Math.ceil(routingLeftMs));
|
|
26
|
+
if (left < capMs) {
|
|
27
|
+
capMs = left;
|
|
28
|
+
routingMs = left;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const startMs = Math.min(Math.max(minimumMs, written), capMs);
|
|
32
|
+
const idleMs = Math.min(Math.min(MAX_IDLE_TIMEOUT_MS, Math.max(minimumMs, ownIdle ?? DEFAULT_IDLE_TIMEOUT_MS)), capMs);
|
|
33
|
+
return {
|
|
34
|
+
startMs,
|
|
35
|
+
idleMs,
|
|
36
|
+
capMs,
|
|
37
|
+
minimumMs,
|
|
38
|
+
startOwn: ownStart !== undefined,
|
|
39
|
+
idleOwn: ownIdle !== undefined,
|
|
40
|
+
...(written < minimumMs && startMs > written ? { raisedFrom: written } : {}),
|
|
41
|
+
...(routingMs !== undefined ? { routingMs } : {}),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** A duration as a person says it: `150 ms`, `30 s`, `1.5 s`, `4 h`. */
|
|
45
|
+
export function formatDuration(milliseconds) {
|
|
46
|
+
if (milliseconds < 1000)
|
|
47
|
+
return `${Math.round(milliseconds)} ms`;
|
|
48
|
+
if (milliseconds >= 3_600_000 && milliseconds % 3_600_000 === 0)
|
|
49
|
+
return `${milliseconds / 3_600_000} h`;
|
|
50
|
+
const seconds = milliseconds / 1000;
|
|
51
|
+
return `${Number.isInteger(seconds) ? seconds : Math.round(seconds * 10) / 10} s`;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* What a timeout says: which deadline ran out, how long it was and where it is changed, without a key or an address.
|
|
55
|
+
* `label` is `provider model`, and `integration` the name the author gave the integration.
|
|
56
|
+
*/
|
|
57
|
+
export function timeoutMessage(label, expired, deadlines, integration) {
|
|
58
|
+
const ms = formatDuration(expired.ms);
|
|
59
|
+
const named = `"${integration}"`;
|
|
60
|
+
if (deadlines.routingMs !== undefined && expired.ms === deadlines.routingMs) {
|
|
61
|
+
return `${label}: request timed out: the provider did not finish within the ${ms} left of the total routing time (maxTotalDurationMs)`;
|
|
62
|
+
}
|
|
63
|
+
if (expired.phase === "start") {
|
|
64
|
+
const raised = deadlines.raisedFrom !== undefined ? ` was ${formatDuration(deadlines.raisedFrom)} and was raised to the ${formatDuration(deadlines.minimumMs)} minimum` : "";
|
|
65
|
+
const where = deadlines.startOwn
|
|
66
|
+
? `the "Provider timeout" of the integration ${named}${raised}`
|
|
67
|
+
: `the default provider timeout${raised ? `, which${raised}` : ""}; the integration ${named} can change it with its "Provider timeout"`;
|
|
68
|
+
return `${label}: the provider did not start answering within ${ms} (${where})`;
|
|
69
|
+
}
|
|
70
|
+
if (expired.phase === "idle") {
|
|
71
|
+
const where = deadlines.idleOwn ? `the "Idle timeout" of the integration ${named}` : `the default idle timeout; the integration ${named} can change it with its "Idle timeout"`;
|
|
72
|
+
return `${label}: the provider sent nothing for ${ms} while answering (${where})`;
|
|
73
|
+
}
|
|
74
|
+
return `${label}: the provider did not finish within ${ms} (the longest one request may take: it cannot be changed)`;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Starts watching an attempt. The cap and the start deadline run from now; the idle deadline from the moment `streaming()` is called,
|
|
78
|
+
* and again from every `activity()`. The author's signal wins over every deadline: when both happen, the call is cancelled, never timed out.
|
|
79
|
+
*/
|
|
80
|
+
export function startClock(parent, deadlines) {
|
|
81
|
+
const controller = new AbortController();
|
|
82
|
+
let expired;
|
|
83
|
+
let over = false;
|
|
84
|
+
let watching = false;
|
|
85
|
+
let reject = () => undefined;
|
|
86
|
+
const interruption = new Promise((_resolve, rejectIt) => {
|
|
87
|
+
reject = rejectIt;
|
|
88
|
+
});
|
|
89
|
+
// Nobody may be racing it when it rejects: that is not an unhandled rejection.
|
|
90
|
+
interruption.catch(() => undefined);
|
|
91
|
+
let capTimer;
|
|
92
|
+
let startTimer;
|
|
93
|
+
let idleTimer;
|
|
94
|
+
const interrupt = (reason) => {
|
|
95
|
+
if (over || controller.signal.aborted)
|
|
96
|
+
return;
|
|
97
|
+
controller.abort(reason);
|
|
98
|
+
reject(reason);
|
|
99
|
+
};
|
|
100
|
+
const expire = (phase, ms) => () => {
|
|
101
|
+
if (over || controller.signal.aborted)
|
|
102
|
+
return;
|
|
103
|
+
expired = { phase, ms };
|
|
104
|
+
interrupt(new DOMException(`The request ran out of time (${phase}, ${ms} ms).`, "TimeoutError"));
|
|
105
|
+
};
|
|
106
|
+
const armIdle = () => {
|
|
107
|
+
if (idleTimer !== undefined)
|
|
108
|
+
clearTimeout(idleTimer);
|
|
109
|
+
idleTimer = setTimeout(expire("idle", deadlines.idleMs), deadlines.idleMs);
|
|
110
|
+
};
|
|
111
|
+
const onAbort = () => interrupt(parent?.reason instanceof Error ? parent.reason : abortError());
|
|
112
|
+
if (parent?.aborted)
|
|
113
|
+
onAbort();
|
|
114
|
+
else
|
|
115
|
+
parent?.addEventListener("abort", onAbort, { once: true });
|
|
116
|
+
if (!controller.signal.aborted) {
|
|
117
|
+
// The cap first: when the routing time left is all the three have, the call ends as the total it is.
|
|
118
|
+
capTimer = setTimeout(expire("total", deadlines.capMs), deadlines.capMs);
|
|
119
|
+
startTimer = setTimeout(expire("start", deadlines.startMs), deadlines.startMs);
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
signal: controller.signal,
|
|
123
|
+
guard: (promise) => Promise.race([interruption, promise]),
|
|
124
|
+
streaming() {
|
|
125
|
+
if (over || controller.signal.aborted)
|
|
126
|
+
return;
|
|
127
|
+
if (startTimer !== undefined)
|
|
128
|
+
clearTimeout(startTimer);
|
|
129
|
+
startTimer = undefined;
|
|
130
|
+
watching = true;
|
|
131
|
+
armIdle();
|
|
132
|
+
},
|
|
133
|
+
activity() {
|
|
134
|
+
if (watching && !over && !controller.signal.aborted)
|
|
135
|
+
armIdle();
|
|
136
|
+
},
|
|
137
|
+
expired: () => expired,
|
|
138
|
+
interrupted: () => over || controller.signal.aborted,
|
|
139
|
+
dispose() {
|
|
140
|
+
over = true;
|
|
141
|
+
for (const timer of [capTimer, startTimer, idleTimer])
|
|
142
|
+
if (timer !== undefined)
|
|
143
|
+
clearTimeout(timer);
|
|
144
|
+
capTimer = startTimer = idleTimer = undefined;
|
|
145
|
+
parent?.removeEventListener("abort", onAbort);
|
|
146
|
+
if (!controller.signal.aborted)
|
|
147
|
+
controller.abort(abortError("The request is over."));
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=deadlines.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deadlines.js","sourceRoot":"","sources":["../../src/ai/deadlines.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAA4B,MAAM,aAAa,CAAC;AAGrG,yJAAyJ;AACzJ,MAAM,CAAC,MAAM,0BAA0B,GAAG,OAAO,CAAC;AAClD,2IAA2I;AAC3I,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC;AAC7C,8GAA8G;AAC9G,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAgCvD,SAAS,cAAc,CAAC,KAAc;IACpC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAA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U,CAAC,KAAK,CAAC,UAAU,CAAC,sBAAsB,CAAC,CAAC,CAAC;QACvF,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,11 +1,30 @@
|
|
|
1
|
-
import type { AiPricingConfig, AiRuntimeConfig } from "./config.js";
|
|
2
|
-
import { type AiPort, type AiUsage } from "./types.js";
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { AiPricingConfig, AiRuntimeConfig, AiStreamMode } from "./config.js";
|
|
2
|
+
import { type AiPort, type AiTimeoutPhase, type AiUsage } from "./types.js";
|
|
3
|
+
export { DEFAULT_REQUEST_TIMEOUT_MS, MIN_REQUEST_TIMEOUT_MS, TOTAL_REQUEST_CAP_MS } from "./deadlines.js";
|
|
4
|
+
/**
|
|
5
|
+
* Raw bytes of a stream include the JSON envelope of every piece (a few hundred bytes for a few characters), so a long reasoning phase is
|
|
6
|
+
* far larger than its text. A stream over this many bytes is a model that loops, and is stopped.
|
|
7
|
+
*/
|
|
8
|
+
export declare const MAX_STREAM_TRANSPORT_BYTES = 256000000;
|
|
9
|
+
/** The characters of reasoning a stream may carry before it is taken for a loop and stopped. */
|
|
10
|
+
export declare const MAX_STREAM_REASONING_CHARACTERS = 16000000;
|
|
5
11
|
export interface FetchAiMessage {
|
|
6
12
|
role: "system" | "user";
|
|
7
13
|
content: string;
|
|
8
14
|
}
|
|
15
|
+
/** The three deadlines of an attempt, in milliseconds, as they are applied (the routing time that is left included). */
|
|
16
|
+
export interface FetchAiTimeouts {
|
|
17
|
+
/** How long the provider has to begin answering: the connection and the headers. For a request that does not stream it is the whole call. */
|
|
18
|
+
startMs: number;
|
|
19
|
+
/** The longest silence between two pieces of a stream (it applies to streamed replies only). */
|
|
20
|
+
idleMs: number;
|
|
21
|
+
/** The most the attempt may take, whatever the provider keeps sending. */
|
|
22
|
+
capMs: number;
|
|
23
|
+
/** The provider timeout the integration asked for, when the minimum raised it to `startMs`. */
|
|
24
|
+
raised?: {
|
|
25
|
+
from: number;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
9
28
|
export interface FetchAiAttempt {
|
|
10
29
|
label: string;
|
|
11
30
|
capability: string;
|
|
@@ -25,8 +44,12 @@ export interface FetchAiAttempt {
|
|
|
25
44
|
tools: boolean;
|
|
26
45
|
/** The origin and path every request of this integration starts with (never a key). */
|
|
27
46
|
endpoint: string | null;
|
|
28
|
-
/** How long
|
|
47
|
+
/** How long the provider has to begin answering (`timeouts.startMs`). */
|
|
29
48
|
timeoutMs: number;
|
|
49
|
+
/** The three deadlines of this attempt. */
|
|
50
|
+
timeouts: FetchAiTimeouts;
|
|
51
|
+
/** What the integration says about streaming (`auto` unless it says `off`). */
|
|
52
|
+
streamMode: AiStreamMode;
|
|
30
53
|
}
|
|
31
54
|
export interface FetchAiAttemptEnd {
|
|
32
55
|
attemptId: string;
|
|
@@ -55,6 +78,14 @@ export interface FetchAiAttemptEnd {
|
|
|
55
78
|
retryAfterMs?: number;
|
|
56
79
|
/** The limit that ran out, for a timeout. */
|
|
57
80
|
timeoutMs?: number;
|
|
81
|
+
/** Which deadline ran out, for a timeout. */
|
|
82
|
+
timeoutPhase?: AiTimeoutPhase;
|
|
83
|
+
/** The reply was read as a stream of events (and not as one JSON body). */
|
|
84
|
+
streamed: boolean;
|
|
85
|
+
/** Milliseconds from the start of the attempt to the first byte of the reply: of its body for a stream, of the response for a JSON body. Absent when nothing arrived. */
|
|
86
|
+
firstByteMs?: number;
|
|
87
|
+
/** For a structured request: whether the model delivered the result as a function call. Absent for any other request and when nothing arrived. */
|
|
88
|
+
toolCalled?: boolean;
|
|
58
89
|
durationMs: number;
|
|
59
90
|
}
|
|
60
91
|
/** One side of a fallback that crosses a privacy boundary. */
|
|
@@ -76,6 +107,11 @@ export interface FetchAiOptions {
|
|
|
76
107
|
githubModelsBaseUrl?: string;
|
|
77
108
|
/** Used when an integration has no request timeout (default `DEFAULT_REQUEST_TIMEOUT_MS`). */
|
|
78
109
|
defaultTimeoutMs?: number;
|
|
110
|
+
/**
|
|
111
|
+
* The shortest start or idle deadline an attempt is given (default `MIN_REQUEST_TIMEOUT_MS`, 30 s). It exists for tests that count in
|
|
112
|
+
* milliseconds: a host has no reason to lower it.
|
|
113
|
+
*/
|
|
114
|
+
minimumTimeoutMs?: number;
|
|
79
115
|
/** An attempt is about to be sent. Never breaks the call. */
|
|
80
116
|
onAttempt?: (attempt: FetchAiAttempt) => void;
|
|
81
117
|
/** An attempt ended, whether it worked or not: for costs and debug panels. Never breaks the call. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-client.d.ts","sourceRoot":"","sources":["../../src/ai/fetch-client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"fetch-client.d.ts","sourceRoot":"","sources":["../../src/ai/fetch-client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAOlF,OAAO,EAAiE,KAAK,MAAM,EAAgE,KAAK,cAAc,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAGzM,OAAO,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAE1G;;;GAGG;AACH,eAAO,MAAM,0BAA0B,YAAc,CAAC;AACtD,gGAAgG;AAChG,eAAO,MAAM,+BAA+B,WAAa,CAAC;AAK1D,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,QAAQ,GAAG,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wHAAwH;AACxH,MAAM,WAAW,eAAe;IAC9B,6IAA6I;IAC7I,OAAO,EAAE,MAAM,CAAC;IAChB,gGAAgG;IAChG,MAAM,EAAE,MAAM,CAAC;IACf,0EAA0E;IAC1E,KAAK,EAAE,MAAM,CAAC;IACd,+FAA+F;IAC/F,MAAM,C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