reliable-requests 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -2
- package/README.md +155 -47
- package/docs/MODEL_COMPATIBILITY.md +56 -0
- package/docs/STREAM_CONTRACT.md +68 -0
- package/docs/USAGE.md +11 -7
- package/package.json +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
- Unify the local recovery test proxy and CLI across Ollama and OpenAI-compatible servers; preserve the original Ollama command.
|
|
6
|
+
- Document and test completion markers, retry/reset ordering, cancellation, callback failures and fresh attempt metadata.
|
|
7
|
+
- Verify one-choice requests and real TCP fault recovery against fake upstream servers. Live LM Studio and llama.cpp recovery is still pending.
|
|
8
|
+
|
|
9
|
+
## 0.2.0 — 2026-11-30
|
|
4
10
|
|
|
5
11
|
- Add the public `reliable-requests` entry for HTTP requests, local model streams, metrics, and public error classes. Internal module paths are not package exports.
|
|
6
12
|
- Include TypeScript declarations with inferred `consume` results and discriminated stream events. Runtime code remains JavaScript with no runtime dependencies.
|
|
7
13
|
- Define the ESM package contents and verify an installed npm archive in a clean consumer project, including NodeNext and Bundler type resolution.
|
|
8
|
-
- Use MIT for the current source and
|
|
14
|
+
- Use MIT for the current source and published package. The existing v0.1.0 tag and release retain GPL-3.0-only.
|
|
9
15
|
- Preserve the existing request, retry, reset, and cancellation behavior.
|
|
10
16
|
|
|
11
17
|
## 0.1.0
|
package/README.md
CHANGED
|
@@ -1,65 +1,74 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<h1>reliable-requests</h1>
|
|
4
|
+
|
|
5
|
+
<strong>Recover from interrupted AI streams without mixing two different answers.</strong>
|
|
6
|
+
|
|
7
|
+
A small JavaScript toolkit for resilient HTTP requests and local AI streaming.<br>
|
|
8
|
+
No runtime dependencies. No telemetry. No framework required.
|
|
9
|
+
|
|
10
|
+
[](https://www.npmjs.com/package/reliable-requests)
|
|
11
|
+
[](LICENSE)
|
|
12
|
+
[](package.json)
|
|
13
|
+
[](package.json)
|
|
14
|
+
[](index.d.ts)
|
|
2
15
|
|
|
3
16
|
[](https://github.com/Stairrax/reliable-requests/actions/workflows/test.yml)
|
|
4
17
|
[](https://github.com/Stairrax/reliable-requests/actions/workflows/browser.yml)
|
|
5
|
-
[](LICENSE)
|
|
6
18
|
|
|
7
|
-
|
|
19
|
+
[Quick start](#quick-start) • [Demo](#try-the-demo) • [Documentation](#documentation) • [Contributing](#contributing)
|
|
8
20
|
|
|
9
|
-
|
|
21
|
+
</div>
|
|
10
22
|
|
|
11
|
-
|
|
12
|
-
- One total deadline, cancellation, and a shared jittered retry policy that respects Retry-After.
|
|
13
|
-
- Incremental SSE event parsing with multiline data and bounded line/event sizes.
|
|
14
|
-
- Interactive demo, diagnostic metrics, and real-HTTP failure tests.
|
|
23
|
+
---
|
|
15
24
|
|
|
16
|
-
|
|
25
|
+
## Why reliable-requests?
|
|
17
26
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Clone the repository and switch to the project directory:
|
|
27
|
+
Local AI servers can stop responding halfway through an answer. Retrying without clearing the partial output can leave two unrelated generations mixed together.
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
git clone https://github.com/Stairrax/reliable-requests.git
|
|
24
|
-
cd reliable-requests
|
|
25
|
-
npm ci
|
|
26
|
-
npm run check
|
|
27
|
-
npm run demo
|
|
28
|
-
```
|
|
29
|
+
reliable-requests makes recovery explicit: when a retry starts a new generation after partial output, the application receives a `reset` event.
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
- **Recover cleanly.** Discard the old partial answer before displaying the new one.
|
|
32
|
+
- **Stop waiting forever.** Keep one deadline across attempts, response reading and retry delays when using the streaming API.
|
|
33
|
+
- **Stay in control.** Cancel generation at any time. Remote model retries require explicit opt-in.
|
|
34
|
+
- **Keep it lightweight.** Native Fetch API, ESM, zero runtime dependencies.
|
|
31
35
|
|
|
32
|
-
|
|
36
|
+
## Features
|
|
33
37
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
- 🔄 Automatic restart of interrupted text streams with an explicit reset event
|
|
39
|
+
- 🔌 Ollama NDJSON and OpenAI-compatible SSE support
|
|
40
|
+
- ⏱️ Shared total deadline, cancellation and jittered retries with Retry-After support
|
|
41
|
+
- 🧩 Incremental parsing of multiline SSE events and fragmented UTF-8
|
|
42
|
+
- 🛡️ Bounded protocol line and event sizes
|
|
43
|
+
- 📊 Optional local stream metrics without telemetry
|
|
44
|
+
- 📦 TypeScript declarations included
|
|
45
|
+
- 🧪 Automated tests, real HTTP fault injection and an interactive browser demo
|
|
38
46
|
|
|
39
|
-
|
|
47
|
+
## Requirements
|
|
40
48
|
|
|
41
|
-
|
|
49
|
+
- Node.js 18+ or a modern browser with Fetch API support
|
|
50
|
+
- An ES module environment; browser npm imports need a bundler or import map
|
|
51
|
+
- A running model server and an installed model for live AI requests only
|
|
42
52
|
|
|
43
|
-
|
|
53
|
+
The simulated demo and core automated tests do not require a model or GPU.
|
|
44
54
|
|
|
45
|
-
|
|
46
|
-
npm ci
|
|
47
|
-
npm run check
|
|
48
|
-
npm pack
|
|
49
|
-
```
|
|
55
|
+
## Quick start
|
|
50
56
|
|
|
51
|
-
|
|
57
|
+
### 1. Install
|
|
52
58
|
|
|
53
59
|
```bash
|
|
54
|
-
npm install
|
|
60
|
+
npm install reliable-requests
|
|
55
61
|
```
|
|
56
62
|
|
|
57
|
-
|
|
63
|
+
### 2. Stream a local model
|
|
64
|
+
|
|
65
|
+
Start Ollama with an installed model, then run this example in an ES module:
|
|
58
66
|
|
|
59
67
|
```js
|
|
60
68
|
import { streamLocalChat } from 'reliable-requests';
|
|
61
69
|
|
|
62
70
|
let answer = '';
|
|
71
|
+
|
|
63
72
|
await streamLocalChat({
|
|
64
73
|
endpoint: 'http://127.0.0.1:11434',
|
|
65
74
|
protocol: 'ollama',
|
|
@@ -73,27 +82,126 @@ await streamLocalChat({
|
|
|
73
82
|
});
|
|
74
83
|
```
|
|
75
84
|
|
|
76
|
-
|
|
85
|
+
Replace the model name with one you have installed. For LM Studio or llama.cpp, use `protocol: 'openai'` and your server's endpoint.
|
|
86
|
+
|
|
87
|
+
For ordinary HTTP requests, the package also exports `reliableRequest`:
|
|
88
|
+
|
|
89
|
+
```js
|
|
90
|
+
import { reliableRequest } from 'reliable-requests';
|
|
91
|
+
|
|
92
|
+
const data = await reliableRequest('https://example.com/api/data', {
|
|
93
|
+
timeoutMs: 8_000,
|
|
94
|
+
retries: 2,
|
|
95
|
+
consume: response => response.json(),
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Without a `consume` callback, the general HTTP wrapper's deadline ends when response headers arrive. See the [usage guide](docs/USAGE.md) for cancellation, TypeScript configuration and metrics.
|
|
100
|
+
|
|
101
|
+
## Try the demo
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
git clone https://github.com/Stairrax/reliable-requests.git
|
|
105
|
+
cd reliable-requests
|
|
106
|
+
npm run demo
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Open [localhost:4173](http://127.0.0.1:4173) and select **Simulate interruption**. Watch an unfinished answer disappear before a fresh generation is displayed.
|
|
110
|
+
|
|
111
|
+
Switch to **Live local model** to connect to your own model server. The server must allow the demo's browser origin through CORS.
|
|
112
|
+
|
|
113
|
+
## How it works
|
|
114
|
+
|
|
115
|
+
```mermaid
|
|
116
|
+
flowchart LR
|
|
117
|
+
A[Start generation] --> B[Stream text]
|
|
118
|
+
B --> C{Completed?}
|
|
119
|
+
C -->|Yes| D[Done]
|
|
120
|
+
C -->|Recoverable failure| E{Retry allowed?}
|
|
121
|
+
E -->|Yes| F[Reset if partial text exists]
|
|
122
|
+
F --> A
|
|
123
|
+
E -->|No| G[Report error]
|
|
124
|
+
C -->|Terminal failure| G
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
A retry starts a **new generation**, not a continuation of the old one. Results may differ, and another request may consume more compute or incur additional charges. Automatic retries of remote model requests require explicit permission.
|
|
128
|
+
|
|
129
|
+
OpenAI-compatible streams require a complete `[DONE]` event; Ollama streams require `done: true`. The library handles text-only generation and does not execute tool calls.
|
|
130
|
+
|
|
131
|
+
## Compatibility
|
|
132
|
+
|
|
133
|
+
| Server | Protocol | Live streaming | Live interruption recovery |
|
|
134
|
+
| --- | --- | --- | --- |
|
|
135
|
+
| Ollama | NDJSON | Verified | Verified |
|
|
136
|
+
| LM Studio | SSE | Verified | Pending |
|
|
137
|
+
| llama.cpp | SSE | Verified | Pending |
|
|
138
|
+
|
|
139
|
+
Automated tests cover Node.js 18 and 22, both protocols and simulated browser flows in Chromium, Firefox and WebKit. Live checks were performed on Windows with Qwen models; they are not a guarantee of compatibility with every server version or model.
|
|
140
|
+
|
|
141
|
+
See the [live test record](https://github.com/Stairrax/reliable-requests/blob/main/docs/LIVE_TESTS_2026-11-29.md) and [roadmap](https://github.com/Stairrax/reliable-requests/blob/main/ROADMAP.md) for the exact scope and remaining work.
|
|
142
|
+
|
|
143
|
+
## Testing
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
npm ci
|
|
147
|
+
npm run check
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
This runs the automated test suite and verifies the actual npm package, including TypeScript consumer checks.
|
|
77
151
|
|
|
78
|
-
For
|
|
152
|
+
For an installed Ollama model (Git Bash, macOS or Linux):
|
|
79
153
|
|
|
80
|
-
|
|
154
|
+
```bash
|
|
155
|
+
MODEL_NAME=qwen2.5:0.5b npm run test:model
|
|
156
|
+
MODEL_NAME=qwen2.5:0.5b npm run test:ollama:recovery
|
|
157
|
+
```
|
|
81
158
|
|
|
82
|
-
|
|
159
|
+
The recovery test deliberately cuts one local connection without stopping Ollama. For LM Studio and llama.cpp, use `npm run test:model:recovery` with `MODEL_PROTOCOL=openai`, the server endpoint and exact model ID. Use only a local, non-billable server. See the [model compatibility guide](docs/MODEL_COMPATIBILITY.md) for Bash and PowerShell commands.
|
|
160
|
+
|
|
161
|
+
## Project layout
|
|
162
|
+
|
|
163
|
+
```text
|
|
164
|
+
reliable-requests/
|
|
165
|
+
├── index.js Public package entry
|
|
166
|
+
├── index.d.ts TypeScript declarations
|
|
167
|
+
├── src/
|
|
168
|
+
│ ├── index.js General HTTP wrapper
|
|
169
|
+
│ ├── local-chat.js Model streaming and recovery
|
|
170
|
+
│ ├── sse.js Incremental stream parsers
|
|
171
|
+
│ ├── stream-events.js Event validation
|
|
172
|
+
│ ├── retry.js Shared retry policy
|
|
173
|
+
│ ├── endpoint.js Endpoint validation
|
|
174
|
+
│ └── metrics.js Local stream metrics
|
|
175
|
+
├── examples/ Browser demo and live model checks
|
|
176
|
+
├── test/ Unit and HTTP integration tests
|
|
177
|
+
├── scripts/ Browser and package checks
|
|
178
|
+
└── docs/ Detailed documentation
|
|
179
|
+
```
|
|
83
180
|
|
|
84
181
|
## Documentation
|
|
85
182
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
183
|
+
| Guide | Description |
|
|
184
|
+
| --- | --- |
|
|
185
|
+
| [Usage](docs/USAGE.md) | API, configuration, errors and examples |
|
|
186
|
+
| [Stream contract](docs/STREAM_CONTRACT.md) | Completion, retries and event ordering |
|
|
187
|
+
| [Model compatibility](docs/MODEL_COMPATIBILITY.md) | Live recovery checks for both protocols |
|
|
188
|
+
| [Roadmap](https://github.com/Stairrax/reliable-requests/blob/main/ROADMAP.md) | Current progress and planned improvements |
|
|
189
|
+
| [Changelog](CHANGELOG.md) | Release history |
|
|
190
|
+
| [Release checklist](https://github.com/Stairrax/reliable-requests/blob/main/docs/RELEASING.md) | Package release process |
|
|
191
|
+
| [Live test record](https://github.com/Stairrax/reliable-requests/blob/main/docs/LIVE_TESTS_2026-11-29.md) | Recorded model compatibility checks |
|
|
192
|
+
|
|
193
|
+
## Contributing
|
|
90
194
|
|
|
91
|
-
|
|
195
|
+
Issues and pull requests are welcome. Bug reports, reproducible stream failures, tests and documentation improvements are especially useful.
|
|
196
|
+
|
|
197
|
+
Keep the runtime dependency-free, preserve explicit retry semantics, and read [CONTRIBUTING.md](https://github.com/Stairrax/reliable-requests/blob/main/CONTRIBUTING.md) before opening a PR. For vulnerability reports, see [SECURITY.md](https://github.com/Stairrax/reliable-requests/blob/main/SECURITY.md).
|
|
92
198
|
|
|
93
199
|
## Acknowledgements
|
|
94
200
|
|
|
95
|
-
Thanks to [TaKeSh13](https://github.com/
|
|
201
|
+
Thanks to [TaKeSh13](https://github.com/GiTakeshi) for helping discuss and develop solutions for local stream completion and callback reliability in [PR #4](https://github.com/Stairrax/reliable-requests/pull/4).
|
|
96
202
|
|
|
97
203
|
## License
|
|
98
204
|
|
|
99
|
-
[MIT](LICENSE)
|
|
205
|
+
[MIT](LICENSE) © 2026 Stairrax.
|
|
206
|
+
|
|
207
|
+
Free to use, modify and distribute, including in commercial and closed-source applications, subject to the MIT license. Provided without warranty.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Model compatibility and recovery checks
|
|
2
|
+
|
|
3
|
+
Compatibility depends on the server's streaming protocol, not the model family. The library sends text chat messages and reads text deltas from Ollama NDJSON or OpenAI-compatible Chat Completions SSE. A different model name does not require a separate adapter when the server keeps that contract.
|
|
4
|
+
|
|
5
|
+
## Evidence so far
|
|
6
|
+
|
|
7
|
+
| Server | Protocol | Recorded live model | Normal response | Forced-disconnect recovery |
|
|
8
|
+
| --- | --- | --- | --- | --- |
|
|
9
|
+
| Ollama | `ollama` | `qwen2.5:0.5b` | Passed on Windows | Passed on Windows |
|
|
10
|
+
| LM Studio | `openai` | `qwen2.5-7b-instruct-uncensored` | Passed in Node and browser on Windows | Pending live run |
|
|
11
|
+
| llama.cpp | `openai` | Qwen 2.5 0.5B | Passed on Windows, build 12212 | Pending live run |
|
|
12
|
+
|
|
13
|
+
These are limited observations, not certification of every server version or model. See [the recorded live checks](https://github.com/Stairrax/reliable-requests/blob/main/docs/LIVE_TESTS_2026-11-29.md) and [the roadmap](https://github.com/Stairrax/reliable-requests/blob/main/ROADMAP.md). Automated fake-server checks verify both protocols and the recovery command without loading a model.
|
|
14
|
+
|
|
15
|
+
## Run the same recovery check against your server
|
|
16
|
+
|
|
17
|
+
Run these commands from a repository checkout after `npm ci`. Test helpers are not shipped in the npm package. Start your local server and load a text chat model first. Use the exact model ID reported by that server.
|
|
18
|
+
|
|
19
|
+
Git Bash, Linux, or macOS:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
MODEL_PROTOCOL=ollama MODEL_ENDPOINT=http://127.0.0.1:11434 MODEL_NAME=qwen2.5:0.5b npm run test:model:recovery
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
LM Studio, using the model from the recorded checks:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
MODEL_PROTOCOL=openai MODEL_ENDPOINT=http://127.0.0.1:1234/v1 MODEL_NAME=qwen2.5-7b-instruct-uncensored MODEL_TIMEOUT_MS=300000 npm run test:model:recovery
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
For llama.cpp or another compatible server, set `MODEL_ENDPOINT` to its actual address and `MODEL_NAME` to its served model ID. The OpenAI endpoint may include `/v1`; a prefix such as `/inference/v1` is preserved.
|
|
32
|
+
|
|
33
|
+
PowerShell:
|
|
34
|
+
|
|
35
|
+
```powershell
|
|
36
|
+
$env:MODEL_PROTOCOL = 'openai'
|
|
37
|
+
$env:MODEL_ENDPOINT = 'http://127.0.0.1:1234/v1'
|
|
38
|
+
$env:MODEL_NAME = 'qwen2.5-7b-instruct-uncensored'
|
|
39
|
+
$env:MODEL_TIMEOUT_MS = '300000'
|
|
40
|
+
npm run test:model:recovery
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The command starts a temporary proxy on a random loopback port. It forwards the first text event, interrupts that connection, and lets the second response complete. It checks for exactly two attempts, one cut, one retry, and one reset. The server stays running. The old `test:ollama:recovery` command remains available.
|
|
44
|
+
|
|
45
|
+
The proxy only connects to HTTP on `127.0.0.1`, requires its generated token, rejects browser-origin requests, and forwards at most two model requests. It does not forward upstream credentials or follow redirects. This is a local development helper, not a production proxy. `MODEL_TIMEOUT_MS` covers generation and retry together; the helper does not speed up inference.
|
|
46
|
+
|
|
47
|
+
## What to record
|
|
48
|
+
|
|
49
|
+
Save the commit SHA (`git rev-parse HEAD`), Node version (`node --version`), OS, server version, model ID, command, and PASS/FAIL output. Note whether the run was in Node or a browser. Do not include private prompts or credentials. A failed test needs its error and event sequence; it must not be recorded as verified support.
|
|
50
|
+
|
|
51
|
+
## Limits
|
|
52
|
+
|
|
53
|
+
- Text chat only: tool calls, image/audio inputs, and separate reasoning output are not supported by this check.
|
|
54
|
+
- The model may produce a different answer after retry. The earlier partial answer must be discarded on `reset`.
|
|
55
|
+
- A successful Node check does not verify browser CORS or browser access to local servers. Those require a separate live browser check.
|
|
56
|
+
- Slower or larger models need a suitable timeout and enough local memory. No model weights are installed or changed by these commands.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Stream completion and recovery contract
|
|
2
|
+
|
|
3
|
+
This document records the current behavior of `streamLocalChat`. It does not introduce a new completion mode.
|
|
4
|
+
|
|
5
|
+
## Completion
|
|
6
|
+
|
|
7
|
+
| Input | Result |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| OpenAI SSE: fully framed `data: [DONE]` event | Success |
|
|
10
|
+
| OpenAI SSE: `finish_reason` followed by EOF, without a complete DONE event | Interrupted stream |
|
|
11
|
+
| OpenAI SSE: partial DONE event or partial data event at EOF | Interrupted stream; incomplete event is discarded |
|
|
12
|
+
| Ollama NDJSON: valid event with `done: true`, including a final line without a newline | Success |
|
|
13
|
+
| Ollama NDJSON: `done_reason` without `done: true`, followed by EOF | Interrupted stream |
|
|
14
|
+
| Both: malformed event, unsupported tool output or protocol limit | Failure, no automatic retry |
|
|
15
|
+
|
|
16
|
+
A completion reason is metadata, not a substitute for the completion marker. A successful protocol completion can still represent truncated text (for example, reason `length`). No reason is fabricated when the server omits it. Each attempt starts with a fresh parser and completion state.
|
|
17
|
+
|
|
18
|
+
## Retry decisions
|
|
19
|
+
|
|
20
|
+
| Failure | Eligible for another attempt? |
|
|
21
|
+
| --- | --- |
|
|
22
|
+
| HTTP 429, 500, 502, 503, 504 | Yes |
|
|
23
|
+
| Other HTTP errors | No |
|
|
24
|
+
| Fetch or reader failure | Only if the transport predicate accepts it (default: TypeError) |
|
|
25
|
+
| EOF without completion, missing body, incomplete UTF-8 at EOF | Yes |
|
|
26
|
+
| Invalid UTF-8 detected while decoding, invalid JSON or event fields | No |
|
|
27
|
+
| Model-reported error, unsupported output, redirect, parser limit | No |
|
|
28
|
+
| Exception from an event callback or retry predicate | No |
|
|
29
|
+
| Cancellation or total deadline reached | No |
|
|
30
|
+
|
|
31
|
+
Eligibility is not a guarantee of a retry. The remaining retry budget, total deadline, Retry-After delay and explicit remote-retry permission still apply. The transport predicate cannot override other safety rules. A fresh generation is not a continuation and can produce different text or incur another charge.
|
|
32
|
+
|
|
33
|
+
## Event ordering
|
|
34
|
+
|
|
35
|
+
With visible text followed by a recoverable failure, the normal sequence is:
|
|
36
|
+
|
|
37
|
+
`attempt(1) -> delta(1)* -> retry(1) -> reset(2) -> attempt(2) -> delta(2)* -> done(2)`
|
|
38
|
+
|
|
39
|
+
The reset is emitted after the retry delay, before the next attempt and before its first delta. If no text was emitted, reset is omitted. If cancelled during the delay, no reset or next attempt is emitted. If a callback throws, the exception is propagated without another request. A terminal failure does not automatically clear visible text; the application must choose how to mark or remove a failed answer. The UI must process reset synchronously before appending later deltas.
|
|
40
|
+
|
|
41
|
+
## Timeout scope
|
|
42
|
+
|
|
43
|
+
The default streaming timeout is 120,000 ms; the general request wrapper defaults to 30,000 ms. Both cover their respective total operations, including retry delays (and response consumption when applicable). A synchronous callback cannot be preempted. Separate first-text and idle timeouts are not implemented here.
|
|
44
|
+
|
|
45
|
+
## Optional live recovery check
|
|
46
|
+
|
|
47
|
+
The existing Ollama test remains available. The shared Node.js-only command exercises both Ollama and OpenAI-compatible servers through a temporary loopback HTTP proxy. It forwards the first valid text event and cuts the first TCP connection; the second request is passed through. The proxy accepts only authenticated requests from the test client, rejects browser origins, allows at most two requests, and only connects to an HTTP server at 127.0.0.1. The first text event is re-framed using its original protocol; the second response is forwarded unchanged. Do not use this test against remote or billable endpoints. Authentication to the upstream model server is not supported by this test.
|
|
48
|
+
|
|
49
|
+
PowerShell, LM Studio (set the exact loaded model identifier):
|
|
50
|
+
|
|
51
|
+
```powershell
|
|
52
|
+
$env:MODEL_PROTOCOL = 'openai'
|
|
53
|
+
$env:MODEL_ENDPOINT = 'http://127.0.0.1:1234/v1'
|
|
54
|
+
$env:MODEL_NAME = 'your-loaded-model-id'
|
|
55
|
+
npm run test:model:recovery
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
For Ollama, set MODEL_PROTOCOL to ollama and use the Ollama endpoint and model ID. For llama.cpp, use its actual listening port (for example 8080) and served model identifier. Increase `MODEL_TIMEOUT_MS` for slow inference if necessary. Expected result: two attempts, one TCP cut, one retry, one reset, a nonempty second answer and a valid completion marker.
|
|
59
|
+
|
|
60
|
+
## Live validation record template
|
|
61
|
+
|
|
62
|
+
| Server / build | Model ID | Node / OS | Checkout SHA | Normal | TCP recovery | Cancel | Timeout | CORS / browser |
|
|
63
|
+
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
|
64
|
+
| LM Studio | | | | | | | | |
|
|
65
|
+
| llama.cpp | | | | | | | | |
|
|
66
|
+
| Ollama | | | | | | | | |
|
|
67
|
+
|
|
68
|
+
Record PASS, FAIL, or NOT RUN separately for each check; include observed event order and errors. The synthetic TCP test uses a mock upstream. It is not evidence that a real model server passed.
|
package/docs/USAGE.md
CHANGED
|
@@ -83,7 +83,7 @@ A restart runs the model again and may produce different text. Local inference u
|
|
|
83
83
|
|
|
84
84
|
It gives one deadline to the whole operation: attempts, pauses before retries, and response reading **when you provide a `consume` function**. It uses `AbortSignal` for cancellation and retries only `GET` and `HEAD` by default.
|
|
85
85
|
|
|
86
|
-
Version 0.2.0 is
|
|
86
|
+
Version 0.2.0 is published on [npm](https://www.npmjs.com/package/reliable-requests). Install it with `npm install reliable-requests`; see the [installation example](../README.md#use-in-javascript). The package is ESM-only and includes TypeScript declarations. Its public entry is `reliable-requests`; internal `src/` paths are not package exports.
|
|
87
87
|
|
|
88
88
|
## Try it
|
|
89
89
|
|
|
@@ -172,11 +172,11 @@ The deadline includes the entire stream. If it expires after some chunks were de
|
|
|
172
172
|
|
|
173
173
|
## Retry policy and errors
|
|
174
174
|
|
|
175
|
-
`retries` means additional attempts (default 2); `timeoutMs` defaults to 30,000 ms
|
|
175
|
+
`retries` means additional attempts (default 2); `timeoutMs` defaults to 30,000 ms for `reliableRequest` and 120,000 ms for `streamLocalChat`. In `reliableRequest`, only `GET` and `HEAD` retry. `streamLocalChat` can retry text-generation POST requests under its separate safety policy. A fetch TypeError or HTTP 429, 500, 502, 503, or 504 may retry. HTTP 4xx errors such as 401 and 404 fail immediately. Both APIs use the same exponential backoff with bounded jitter (250 ms initial base, 5 s maximum base). A valid Retry-After value (seconds or HTTP date) is treated as a minimum delay, with small nonnegative jitter; it is never shortened to an earlier retry. Every delay consumes the same total time budget. If the next delay cannot fit, the operation rejects immediately with RequestTimeoutError rather than sending another request.
|
|
176
176
|
|
|
177
177
|
Both APIs accept an optional synchronous shouldRetryError(error, { attempt, method, phase }) predicate. Return true to retry an eligible transport error. The default accepts TypeError, which Fetch uses for network failures but also for some invalid request options; browsers do not reliably distinguish them. For example, shouldRetryError: () => false disables transport-error retries. In reliableRequest the predicate is called only for a fetch rejection on GET/HEAD, never for errors in consume. In streamLocalChat it may also receive phase: 'read' for a rejected stream read. It does not override HTTP-status rules, retry budgets, method safety, remote opt-in, or the interrupted-stream policy. It is not called for malformed SSE/NDJSON, callback errors, cancellation, or timeouts. Exceptions from the predicate propagate without another attempt. The streaming retry event also exposes delayMs.
|
|
178
178
|
|
|
179
|
-
`POST`, `PUT`, `PATCH`,
|
|
179
|
+
The general `reliableRequest` wrapper never retries `POST`, `PUT`, `PATCH`, or `DELETE`. Repeating one could create a duplicate operation or charge twice. If your API has an idempotency key contract, put a separate, explicit retry policy around that operation.
|
|
180
180
|
|
|
181
181
|
An unsuccessful final response throws `HttpError` with `status`, `response`, and `attempts`. The response body remains available for diagnosis. Transport errors retain their original error. Errors thrown by `consume` propagate and are not retried, because the body or a stream may already have been partly read.
|
|
182
182
|
|
|
@@ -269,6 +269,10 @@ PASS: 2 attempts, 1 real connection cut, 1 retry, 1 reset.
|
|
|
269
269
|
|
|
270
270
|
**Limits:** this generates twice, using extra local compute. It does **not** resume the interrupted generation or guarantee identical text. Do not use the fault proxy with remote or billable inference endpoints. The automatic CI test uses a fake local Ollama upstream with real TCP sockets, while this manual command checks against your actual installed model.
|
|
271
271
|
|
|
272
|
+
## Completion and recovery details
|
|
273
|
+
|
|
274
|
+
See the [stream contract](STREAM_CONTRACT.md) for completion markers, retry decisions, event ordering, and the optional `npm run test:model:recovery` command for Ollama or OpenAI-compatible servers. The recovery tools run from a source checkout, not the installed npm archive.
|
|
275
|
+
|
|
272
276
|
## Why another wrapper?
|
|
273
277
|
|
|
274
278
|
[Ky](https://github.com/sindresorhus/ky) is a more complete fetch client and already has a `totalTimeout` option. [p-retry](https://github.com/sindresorhus/p-retry) retries arbitrary async work with a time budget and cancellation. [Got](https://github.com/sindresorhus/got) is a capable Node.js HTTP client. Use one of them when you need its broader features. This project focuses on local text-model streams that can restart after partial output with an explicit reset event. The general fetch wrapper remains available for ordinary HTTP calls.
|
|
@@ -277,12 +281,12 @@ The design was informed by a timeout fix in [helper-with-conspects](https://gith
|
|
|
277
281
|
|
|
278
282
|
## Project status and contributing
|
|
279
283
|
|
|
280
|
-
|
|
284
|
+
Version **0.2.0** is published on npm under MIT. The API is still early; review the [changelog](../CHANGELOG.md) when upgrading.
|
|
281
285
|
|
|
282
|
-
- [CONTRIBUTING.md](
|
|
283
|
-
- [ROADMAP.md](
|
|
286
|
+
- [CONTRIBUTING.md](https://github.com/Stairrax/reliable-requests/blob/main/CONTRIBUTING.md) — how to run tests and propose changes
|
|
287
|
+
- [ROADMAP.md](https://github.com/Stairrax/reliable-requests/blob/main/ROADMAP.md) — current progress and planned improvements
|
|
284
288
|
- [GitHub Issues](https://github.com/Stairrax/reliable-requests/issues) — bug reports and features; remove access tokens and private prompts
|
|
285
|
-
- [SECURITY.md](
|
|
289
|
+
- [SECURITY.md](https://github.com/Stairrax/reliable-requests/blob/main/SECURITY.md) — security disclosure guidance
|
|
286
290
|
|
|
287
291
|
Node 18 and 22 are tested in CI. Real installed models and different browsers still need hands-on verification; passing automation does not prove universal compatibility.
|
|
288
292
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reliable-requests",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18"
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"test:ollama:recovery": "node examples/verify-ollama-recovery.mjs",
|
|
14
14
|
"test:ollama:stress": "node examples/verify-ollama-stress.mjs",
|
|
15
15
|
"test:package": "node scripts/verify-package.mjs",
|
|
16
|
-
"check": "npm test && npm run test:package"
|
|
16
|
+
"check": "npm test && npm run test:package",
|
|
17
|
+
"test:model:recovery": "node examples/verify-model-recovery.mjs"
|
|
17
18
|
},
|
|
18
19
|
"license": "MIT",
|
|
19
20
|
"description": "Resilient local-model text streams with explicit reset on retry",
|
|
@@ -30,6 +31,8 @@
|
|
|
30
31
|
"index.d.ts",
|
|
31
32
|
"src/",
|
|
32
33
|
"docs/USAGE.md",
|
|
34
|
+
"docs/STREAM_CONTRACT.md",
|
|
35
|
+
"docs/MODEL_COMPATIBILITY.md",
|
|
33
36
|
"CHANGELOG.md"
|
|
34
37
|
],
|
|
35
38
|
"repository": {
|