narrarium-engine 0.1.5 → 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 +90 -12
- 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 +374 -126
- package/dist/ai/fetch-client.js.map +1 -1
- package/dist/ai/request.d.ts +8 -1
- package/dist/ai/request.d.ts.map +1 -1
- package/dist/ai/request.js +18 -1
- package/dist/ai/request.js.map +1 -1
- package/dist/ai/types.d.ts +47 -1
- package/dist/ai/types.d.ts.map +1 -1
- package/dist/ai/types.js +2 -0
- package/dist/ai/types.js.map +1 -1
- package/dist/autopilot/errors.d.ts +32 -0
- package/dist/autopilot/errors.d.ts.map +1 -0
- package/dist/autopilot/errors.js +190 -0
- package/dist/autopilot/errors.js.map +1 -0
- package/dist/autopilot/runner.d.ts +12 -3
- package/dist/autopilot/runner.d.ts.map +1 -1
- package/dist/autopilot/runner.js +60 -26
- package/dist/autopilot/runner.js.map +1 -1
- package/dist/autopilot/session.d.ts +1 -1
- package/dist/autopilot/session.d.ts.map +1 -1
- package/dist/autopilot/session.js +16 -7
- package/dist/autopilot/session.js.map +1 -1
- package/dist/autopilot/state.d.ts +35 -2
- package/dist/autopilot/state.d.ts.map +1 -1
- package/dist/autopilot/state.js +117 -4
- package/dist/autopilot/state.js.map +1 -1
- package/dist/autopilot/tasks.d.ts.map +1 -1
- package/dist/autopilot/tasks.js +11 -2
- package/dist/autopilot/tasks.js.map +1 -1
- package/dist/autopilot/types.d.ts +112 -8
- package/dist/autopilot/types.d.ts.map +1 -1
- package/dist/autopilot/types.js +1 -0
- package/dist/autopilot/types.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/server/client.d.ts +9 -0
- package/dist/server/client.d.ts.map +1 -1
- package/dist/server/client.js +15 -0
- package/dist/server/client.js.map +1 -1
- package/dist/server/protocol.d.ts +19 -0
- package/dist/server/protocol.d.ts.map +1 -1
- package/dist/server/protocol.js +11 -0
- package/dist/server/protocol.js.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
|
@@ -15,14 +15,14 @@ npm install narrarium-engine
|
|
|
15
15
|
| Area | Main exports |
|
|
16
16
|
|---|---|
|
|
17
17
|
| Book access | `BookStore` (list/read/commit with compare-and-swap, `readMany`), `BookConflictError`, `loadBookSnapshot` |
|
|
18
|
-
| Autopilot | `AutopilotSession`, `AutopilotRun`, `advanceState`, `nextStep`, `applyIntervention`, `summarizeAutopilotState`, `effectivePublish`, `hostDefaultPublish`, `normalizeRunLimits`, `runnerActivity`, `runnerHeartbeatAgeMs`, `AutopilotRuleError` |
|
|
18
|
+
| Autopilot | `AutopilotSession`, `AutopilotRun`, `advanceState`, `nextStep`, `applyIntervention`, `summarizeAutopilotState`, `effectivePublish`, `hostDefaultPublish`, `normalizeRunLimits`, `runnerActivity`, `runnerHeartbeatAgeMs`, `AutopilotRuleError`, `classifyAutopilotError`, `AUTOPILOT_ERROR_KINDS`, `AUTOPILOT_RULE_ERROR_CODES` |
|
|
19
19
|
| Director | `askDirector`, `listDirectorOpinions`, `parseDirector`, `serializeDirector`, `directorPrompt` |
|
|
20
20
|
| Readers | `readerPersonaSystemPrompt`, `mergeReaderPersonas`, `READER_EVALUATION_TOOL`, `chapterReaderText` |
|
|
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`, `redactSecrets` |
|
|
25
|
-
| Personal server | `NarrariumServerClient`, `pairWithServer`, `pairWithServerDetailed`, `verifyServerIdentity`, `serverCompatibility`, `remoteBookStore`, protocol types (scopes, pairing, updates), `ServerSentEventParser` |
|
|
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
|
+
| 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` |
|
|
28
28
|
|
|
@@ -112,10 +112,43 @@ The engine applies it, so a host only says *how* to publish: `hooks.afterCommit`
|
|
|
112
112
|
|
|
113
113
|
**Changing settings during a run.** `session.updateOptions(partial)` saves the options and answers the saved state. While a run is active only `publishEvery` (`null` takes the choice back, so that the host decides again) and `pauseAfterEachChapter` can change (`LIVE_AUTOPILOT_OPTIONS`); any other option throws `AutopilotBusyError`, as `configure` does, and nothing of that request is applied. With no run active any option can change. The change is a compare-and-swap commit, like an intervention: the step in flight is neither failed nor repeated, the run takes the author's value into the state the step saves (`reconcileAuthorChanges`) and reads it at the end of that step, or of the chapter. A value nobody knows changes nothing, and a request that changes nothing writes nothing.
|
|
114
114
|
|
|
115
|
-
**What the summary says.** `AutopilotStateSummary`, which the `state` events carry and `snapshot().summary` holds for a client that connects later, has
|
|
115
|
+
**What the summary says.** `AutopilotStateSummary`, which the `state` events carry and `snapshot().summary` holds for a client that connects later, has four fields that are never saved: `pausePending` (`"after-step"`, `"after-chapter"` or `null`), `limits` (`{ steps?, chapters?, stepsDone, chaptersDone }` of the run in progress, `null` when it has none or is over; `chapters` is the stricter of the run's limit and `chaptersPerRun`), `publish` (`effectivePublish` of the options and the host's default) and `retry` (the retry the run is waiting for, present only while it is: see *What the interface reads*). A summary made from the state file alone (`summarizeAutopilotState(state)`) has no `pausePending`, no `limits` and no `retry`: nothing in the file says them, so a client takes them from the events and the snapshot. They change without the state being written, so `updatedAt` does not move: every change of the pause that waits, and every saved step, is a `state` event, and a client keeps the newest event it has seen, whatever its `updatedAt`.
|
|
116
116
|
|
|
117
117
|
**Message codes.** `run-ended` and `insight` events carry a `code` when a client can say it in its own language: `chapterPause`, `stepLimit` and `chapterLimit` join `takenOver` and the others (`AutopilotMessageCode`). The `message` of the event, and of the saved state, is always in the language of the book.
|
|
118
118
|
|
|
119
|
+
### What the interface reads
|
|
120
|
+
|
|
121
|
+
Data the web app's pages used to have to guess (from the text of a step, from the 200 activities of the log) and now find in the state and in the summary. All of it is additive: every field is absent until the engine that writes it has something to say, and a state or a summary without one is what an older engine wrote.
|
|
122
|
+
|
|
123
|
+
**The final verdict.** When the `final` step is done, `state.finalReview` is `{ verdict, score, text, at }`: the director's judgement of the whole book as data, where the line of the step said `approve 8/10 — …`. `verdict` is `"approve"` or `"revise"` (a `rewrite` is a `revise`, and so is an approval withheld because its score is under the `approvalScore` of `director.md`); the book is closed all the same, as it always was. `score` is on the scale of the chapters (0-10, one decimal at most), `text` is the director's summary cut with `clipText` at `FINAL_REVIEW_TEXT_CHARACTERS` (1200) characters, and `at` is when the director gave it. `summary.finalReview` has the same fields with the text cut at `FINAL_REVIEW_SUMMARY_CHARACTERS` (400). A book that is not complete any more (its chapters were extended, or a `rewrite` reopened it) has none until the final step is done again.
|
|
124
|
+
|
|
125
|
+
**Working time.** `stats.workedMs` is the sum, over every run, of the durations of the steps that were saved, each from its start to its end as its activity shows. Not counted: the wait for the author, the pauses between runs, the attempts of a step that failed and the waits between them (a step counts the attempt that was saved), the steps that were abandoned. A whole number of milliseconds, never negative, in the state (so it outlives the 200 activities of the log) and in `summary.stats`. A state written before it existed has none (and neither has its summary: not zero, not `NaN`) and it counts from zero at the first step that is saved.
|
|
126
|
+
|
|
127
|
+
**Errors.** A step that fails puts `errorKind` and `errorDetail` in its activity (the `task-finished` event carries them too) and, when it ends the run, in `state.lastError`; `summary.lastError` has the same two under the names `kind` and `detail` as well. A step that the author cancelled is no failure and has neither. `AutopilotErrorKind` is a closed list (`AUTOPILOT_ERROR_KINDS`), told from what the engine knows of its errors (`classifyAutopilotError(error)` is the one function, a status or a flag deciding before the words do):
|
|
128
|
+
|
|
129
|
+
| Kind | What it is |
|
|
130
|
+
|---|---|
|
|
131
|
+
| `auth` | 401 or 403: a key, or a permission. |
|
|
132
|
+
| `rate_limit` | 429. |
|
|
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
|
+
| `network` | The provider could not be reached, or the connection dropped: no status, `transient`, or the words of a network failure. |
|
|
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
|
+
| `truncated` | The reply was cut by the output limit (`truncated`, `reasoningOnly` included). |
|
|
137
|
+
| `refused` | Nothing was called: the privacy setting for fallbacks left no candidate (`AiFallbackBlockedError`), or no model is routed to the task (`AiUnavailableError`). |
|
|
138
|
+
| `budget` | The routing limits leave no candidate to call (`AiRoutingBudgetError`). |
|
|
139
|
+
| `limit` | No context window holds the prompt (`AiPromptTooLargeError`), or the run's own ceiling of steps. |
|
|
140
|
+
| `profile` | A file of the book the autopilot would rewrite cannot be read: its frontmatter is not valid YAML (`FrontmatterError`). The author fixes it. |
|
|
141
|
+
| `conflict` | A file changed under the step and the retries are used up (`BookConflictError`). |
|
|
142
|
+
| `unknown` | Everything else. |
|
|
143
|
+
|
|
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
|
+
|
|
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
|
+
|
|
148
|
+
**The rounds of every chapter.** `PlannedChapter.rounds` is a compact history of the rounds of review of a chapter that closed: one `{ director?, readers?, accepted?, rejected? }` for each, oldest first, written when the director judges the round and kept after the chapter is closed (`state.review` is the round in progress and is cleared when the chapter closes). `director` is the director's vote and `readers` the average of the simulated readers' votes (0-10, one decimal at most); `accepted` and `rejected` are what the director decided, whole numbers. The readers read a chapter once, in the first round of its review, so only that round has `readers` (a chapter rewritten after the author's request is reviewed again without readers). A chapter keeps at most `MAX_CHAPTER_ROUNDS` (8): a chapter that is rewritten adds the rounds of its new review and the oldest leave. A chapter that was never reviewed has none (`rounds` is absent, never an empty list), and the history survives the plan being made again around the chapters when the author raises the number of chapters of a finished book. In `state.json` every round takes one line of about 75 bytes (the file is still plain JSON), so a book of 5000 chapters with three rounds each adds about 1.1 MB to a file the server accepts up to 8 MiB.
|
|
149
|
+
|
|
150
|
+
**Older and newer engines.** Every new field is read tolerantly (a value that is not valid is dropped, never made up) and an older file reads as it always did. An engine from before these fields reads a file that has them without trouble but does not know them: `normalizeAutopilotState` of that engine drops `finalReview`, `stats.workedMs`, the kind and the detail of `lastError`, and the `rounds` of the chapters, so the first time it writes the state the history is lost (the activities keep their `errorKind` and `errorDetail`, which it does not look at). The worked time then starts again from zero in the engine that knows it, and the rounds start again with the next review.
|
|
151
|
+
|
|
119
152
|
### Long books
|
|
120
153
|
|
|
121
154
|
There is no maximum number of chapters. A plan longer than `PLAN_BATCH_CHAPTERS` (20) is made of several `plan` steps, one per batch, so that no reply outgrows the model's output; `plan.revisionBatches` lists the first chapter of every batch a revision of the plan still has to regenerate, and `plan.skippedReaders` the readers whose reaction stayed incomplete after a retry and who are not asked again. The lists of chapters in a prompt are windowed around the chapter at hand (`outline`, at most `OUTLINE_MAX_CHARS`, 24 000 characters), so a prompt never outgrows its budget and the work to build it grows linearly with the book.
|
|
@@ -153,7 +186,7 @@ A profile with warnings is not what the author wrote, so the engine never goes o
|
|
|
153
186
|
| Path | Content |
|
|
154
187
|
|---|---|
|
|
155
188
|
| `director.md` | Director profile (`type: director`). |
|
|
156
|
-
| `autopilot/state.json` | Autopilot state: brief, options, plan, review cycle, rules, interventions, statistics. |
|
|
189
|
+
| `autopilot/state.json` | Autopilot state: brief, options, plan (with the compact `rounds` of review of every chapter), review cycle, rules, interventions, statistics (with `workedMs`), the final review of the book (`finalReview`) and the last error with its kind. |
|
|
157
190
|
| `autopilot/activity.json` | Last 200 activities (what, why, next, result, model, tokens, cost). |
|
|
158
191
|
| `autopilot/plan.md` | Human-readable mirror of the plan. |
|
|
159
192
|
| `chapters/<chapter>/chapter.md` | The chapter, with its `summary` (written when it is closed, or by the summary step for a chapter the author wrote). |
|
|
@@ -185,7 +218,8 @@ Limits on the reply of a step are sized for Latin script (2.4 tokens a word) and
|
|
|
185
218
|
|---|---|
|
|
186
219
|
| `fetch` | The `fetch` to use (default the global one). |
|
|
187
220
|
| `githubModelsBaseUrl` | Origin of GitHub Models, or of a proxy that forwards `/inference`. |
|
|
188
|
-
| `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*. |
|
|
189
223
|
| `onAttempt`, `onAttemptEnd` | Hooks that see every attempt that is sent and how it ended (below). |
|
|
190
224
|
| `acknowledgeFallback` | Asked before content goes to an integration of another account than the one it went to so far (below). |
|
|
191
225
|
|
|
@@ -193,16 +227,51 @@ What every host gets, whatever its options:
|
|
|
193
227
|
|
|
194
228
|
| What | How |
|
|
195
229
|
|---|---|
|
|
196
|
-
| 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*. |
|
|
197
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. |
|
|
198
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. |
|
|
199
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. |
|
|
200
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. |
|
|
201
|
-
|
|
|
202
|
-
| 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. |
|
|
203
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. |
|
|
204
|
-
| 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. |
|
|
205
|
-
| 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.
|
|
206
275
|
|
|
207
276
|
### Costs and budgets
|
|
208
277
|
|
|
@@ -210,7 +279,7 @@ What every host gets, whatever its options:
|
|
|
210
279
|
|
|
211
280
|
### Retries
|
|
212
281
|
|
|
213
|
-
A step that failed with a transient provider error is retried up to three times, after about 4 s, 12 s and 36 s (with jitter, never sooner than the provider's `Retry-After`); the `failureRetry` insight carries `attempt`, `retries` and `waitMs`. A rejected reply, or a failure that is not the provider's, is retried once, the first with the reason. The same failure twice in a row that does not depend on the moment (an empty reply, a 500 with the same message) stops the run at once. A reply cut while the model had only reasoned is retried once with an output limit three times larger (`AiRequest.outputBoost`), and the next steps of that kind start with it. `retryDelayMs` is the base delay: every delay scales with it, `0` makes them instant. A pause ends the wait.
|
|
282
|
+
A step that failed with a transient provider error is retried up to three times, after about 4 s, 12 s and 36 s (with jitter, never sooner than the provider's `Retry-After`); the `failureRetry` insight carries `attempt`, `retries` and `waitMs`. A rejected reply, or a failure that is not the provider's, is retried once, the first with the reason. The same failure twice in a row that does not depend on the moment (an empty reply, a 500 with the same message) stops the run at once. A reply cut while the model had only reasoned is retried once with an output limit three times larger (`AiRequest.outputBoost`), and the next steps of that kind start with it. `retryDelayMs` is the base delay: every delay scales with it, `0` makes them instant. A pause ends the wait. While the run waits, `summary.retry` says when the next attempt is (see *What the interface reads*).
|
|
214
283
|
|
|
215
284
|
### What the model's replies must be
|
|
216
285
|
|
|
@@ -251,6 +320,15 @@ A skipped file is not recorded as synced (a file that was never synced stays out
|
|
|
251
320
|
|
|
252
321
|
The server answers with the engine's `session.pause`, `session.cancelPause`, `session.start({ …, limits })` and `session.updateOptions`, and takes `defaultPublish: "step"` as its default (which is what it does when it passes none). It can validate the bodies against the lists the engine exports for that: `PAUSE_AUTOPILOT_MODES`, `AUTOPILOT_PUBLISH_MODES` and `LIVE_AUTOPILOT_OPTIONS`. For a GitHub book its `afterCommit` hook pushes (what the engine calls after every step in `step` mode) and its `afterChapter` hook pushes too (what it calls when a chapter is closed in `chapter` and `step` mode): without that one, `chapter` would publish nothing.
|
|
253
322
|
|
|
323
|
+
- **Permanent rules.** The rules the author gave with `from_now` (`state.constraints`, in the order the author sees them) are edited and removed with two calls, which the engine's session already has (`session.updateRule`, `session.removeRule`). A server that implements the routes below announces `SERVER_FEATURE_AUTOPILOT_RULES` (`"autopilot-rules"`) in the `features` of `GET /api/v1/info`, and `serverSupportsAutopilotRules(info)` reads it (never throws; an older server, or an odd answer, says no): a client asks before it offers to edit or remove a rule, because an older server answers `404 not_found` to the routes. The calls need the `run` permission, like the other commands that steer a run, and answer the snapshot (`AutopilotSnapshot`), as `configure` does; the `index` is the position of the rule in `state.constraints`, from 0. `expectedText` is the rule as the author saw it: when the rule at that index is no longer that (compared without the spaces around it), nothing is written and the answer is `409 rule_changed`, so a rule that changed in the meantime, on another device or by the director's answer, is never overwritten or removed by mistake. Every call also answers `401 unauthorized`, `403 scope` (no `run` permission) and `404 book_not_found`.
|
|
324
|
+
|
|
325
|
+
| Client method | Request | Answer |
|
|
326
|
+
|---|---|---|
|
|
327
|
+
| `updateRule(bookId, index, text, expectedText?)` | `PUT /api/v1/books/:id/autopilot/rules/:index` with `{ "text": string, "expectedText"?: string }`. | `200` the snapshot, of the state that was saved (also while the autopilot runs: the step in flight is not repeated, and the next step has the new rule). A text equal to the rule it replaces changes nothing. `400 rule_empty` (nothing but spaces), `400 rule_too_long` (over `MAX_RULE_CHARACTERS`, 800: it is refused, never cut), `400 rule_duplicate` (another rule already says it), `404 rule_not_found` (no rule at that index), `409 rule_changed`, `409 conflict` when the state file kept changing under the write (try again) and `409 state_corrupt` when it cannot be read, `503 maintenance` while the server is about to restart. |
|
|
328
|
+
| `removeRule(bookId, index, expectedText?)` | `DELETE /api/v1/books/:id/autopilot/rules/:index`, with `?expectedText=…` (URL-encoded) when the client has it. No body. | `200` the snapshot. `404 rule_not_found`, `409 rule_changed`, `409 conflict`, `409 state_corrupt`, `503 maintenance`. The rules after the one that was removed move up by one: a client reads the answer, not its own list. |
|
|
329
|
+
|
|
330
|
+
The `code` of a refusal of a rule is the `code` of the engine's `AutopilotRuleError` (`AUTOPILOT_RULE_ERROR_CODES`: `rule_empty`, `rule_too_long`, `rule_not_found`, `rule_changed`, `rule_duplicate`), which a server can answer as it is (`400` for the first, the third and the last, `404` for `rule_not_found`, `409` for `rule_changed`); `isAutopilotRuleErrorCode(error.code)` tells a refusal of a rule from the other codes of `ServerRequestError`. The client sends the text as it is given and an index as it is given (a number that names no rule is `404 rule_not_found`), and what it gets back is the error it always gives, with the status and the code of the server. The answer to a question of the director that is kept as a rule needs nothing new: `answer(bookId, { questionId, answer, asRule: true })` has always carried `asRule` (`QuestionAnswer`), and a note used once is still the default.
|
|
331
|
+
|
|
254
332
|
## Tests
|
|
255
333
|
|
|
256
334
|
```bash
|
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":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AC;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,EAAE,CAAC;IAChB,kBAAkB,EAAE,OAAO;IAC3B,gBAAgB,EAAE,OAAO;IACzB,gBAAgB,EAAE,CAAC;CACpB,CAAC,CAAC;AAmBH,MAAM,SAAS,GAAqB,CAAC,cAAc,EAAE,QAAQ,EAAE,eAAe,EAAE,cAAc,CAAC,CAAC;AAEhG,SAAS,MAAM,CAAC,KAAc;IAC5B,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAgC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC7G,CAAC;AAED,SAAS,IAAI,CAAC,KAAc;IAC1B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9E,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC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E,WAAW,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACzE,MAAM,EAAE,CAAC,WAAW,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,CAAC,YAAY,EAAE,CAAC,CAAC;SAChH,CAAC,CAAC;QACH,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE;QACzD,GAAG,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,MAAM,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvF,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC,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,KAAK,EAAE,MAAM,CAAC;CACf;AAED,kFAAkF;AAClF,MAAM,WAAW,iBAAkB,SAAQ,gBAAgB;IACzD,+DAA+D;IAC/D,SAAS,EAAE,MAAM,CAAC;IAClB,+HAA+H;IAC/H,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0FAA0F;IAC1F,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,gHAAgH;IAChH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,wDAAwD;IACxD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mIAAmI;IACnI,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAMD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,IAAI,CAAC,mBAAmB,EAAE,kBAAkB,GAAG,eAAe,CAAC,EAAE,OAAO,GAAE,eAAoB,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,iBAAiB,CA0BvL;AAED,iEAAiE;AACjE,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,cAAc,CAAC;IACtB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,wEAAwE;AACxE,wBAAgB,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAK3D;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAkBjI;AAED,6EAA6E;AAC7E,MAAM,WAAW,aAAa;IAC5B,6EAA6E;IAC7E,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B;;;OAGG;IACH,KAAK,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC1C,kIAAkI;IAClI,SAAS,IAAI,IAAI,CAAC;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
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