@procedures/http 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/README.md +27 -3
- package/dist/.tsbuildinfo +1 -1
- package/dist/exchange.d.ts +15 -0
- package/dist/exchange.d.ts.map +1 -1
- package/dist/exchange.js +19 -0
- package/dist/exchange.js.map +1 -1
- package/dist/module.d.ts.map +1 -1
- package/dist/module.js +15 -11
- package/dist/module.js.map +1 -1
- package/dist/procedures/http/ndjson.d.ts +4 -3
- package/dist/procedures/http/ndjson.d.ts.map +1 -1
- package/dist/procedures/http/ndjson.js +6 -5
- package/dist/procedures/http/ndjson.js.map +1 -1
- package/dist/procedures/http/sse.d.ts +5 -4
- package/dist/procedures/http/sse.d.ts.map +1 -1
- package/dist/procedures/http/sse.js +7 -6
- package/dist/procedures/http/sse.js.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/exchange.ts +28 -0
- package/src/module.ts +15 -12
- package/src/procedures/http/ndjson.ts +6 -5
- package/src/procedures/http/sse.ts +7 -6
- package/src/types.ts +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# @procedures/http
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [0f75644]
|
|
8
|
+
- Updated dependencies [09e5566]
|
|
9
|
+
- Updated dependencies [ab77f75]
|
|
10
|
+
- Updated dependencies [a47bee6]
|
|
11
|
+
- Updated dependencies [bc74091]
|
|
12
|
+
- @procedures/client@0.5.0
|
|
13
|
+
|
|
14
|
+
## 0.4.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- ff87747: `http.ndjson` and `http.sse` send a POST too. Their inputs have `method` (`GET` or `POST`), `json` (a body of JSON) and `body` (a body of text), as `http.request` has them. The default method is `POST` with a body, and `GET` without one. An LLM API sends its answer to a POST as server-sent events: `http.sse` now reads such a stream.
|
|
19
|
+
|
|
20
|
+
A POST of a stream gets the host check, the size limit of the request body, `timeoutMs`, `idleTimeoutMs` and the deadline of the call. Two bodies, or a `GET` with a body, fail before the request.
|
|
21
|
+
|
|
22
|
+
A POST can change remote data, so the two streams now declare `writes: ["network"]`, as `http.json` does. Before, they declared `writes: []`.
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Updated dependencies [d919678]
|
|
27
|
+
- Updated dependencies [057d69a]
|
|
28
|
+
- Updated dependencies [b2a1a1e]
|
|
29
|
+
- Updated dependencies [057d69a]
|
|
30
|
+
- Updated dependencies [057d69a]
|
|
31
|
+
- Updated dependencies [057d69a]
|
|
32
|
+
- Updated dependencies [057d69a]
|
|
33
|
+
- Updated dependencies [057d69a]
|
|
34
|
+
- Updated dependencies [afd6a19]
|
|
35
|
+
- Updated dependencies [057d69a]
|
|
36
|
+
- Updated dependencies [4e751da]
|
|
37
|
+
- @procedures/client@0.4.0
|
|
38
|
+
|
|
3
39
|
## 0.3.0
|
|
4
40
|
|
|
5
41
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -14,10 +14,10 @@ HTTP requests as procedures. A host allowlist refuses loopback, private and link
|
|
|
14
14
|
|---|---|---|
|
|
15
15
|
| `http.request` | It sends a request with each method and gives the status, the headers and the body. | reads and writes `network` |
|
|
16
16
|
| `http.json` | It sends a GET or a POST of JSON and gives the parsed body. | reads and writes `network` |
|
|
17
|
-
| `http.ndjson` | It sends a GET and gives a stream of the JSON values of the lines. | reads `network` |
|
|
18
|
-
| `http.sse` | It sends a GET and gives a stream of server-sent events. | reads `network` |
|
|
17
|
+
| `http.ndjson` | It sends a GET or a POST and gives a stream of the JSON values of the lines. | reads and writes `network` |
|
|
18
|
+
| `http.sse` | It sends a GET or a POST and gives a stream of server-sent events. | reads and writes `network` |
|
|
19
19
|
|
|
20
|
-
-
|
|
20
|
+
- Each procedure can change remote data with a POST, so each procedure declares a write. `http.request` also sends a PUT or a DELETE.
|
|
21
21
|
- `http.ndjson` and `http.sse` declare `stream: { unbounded: true }`, because a server can send a stream without an end. A face that collects a stream refuses them or stops them at its limits.
|
|
22
22
|
|
|
23
23
|
```ts
|
|
@@ -27,6 +27,29 @@ await client.call(["http", "json"], { url: "https://api.github.com/repos/nodejs/
|
|
|
27
27
|
await client.call(["http", "request"], { url: "https://example.com/upload", method: "PUT", body: "text" });
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
### The streams of a POST
|
|
31
|
+
|
|
32
|
+
An LLM API sends its answer to a POST as server-sent events. `http.sse` and `http.ndjson` take the same request fields as `http.request`:
|
|
33
|
+
|
|
34
|
+
| Field | Meaning |
|
|
35
|
+
|---|---|
|
|
36
|
+
| `method` | `GET` or `POST`. The default is `POST` with `body` or `json`, and `GET` without them. |
|
|
37
|
+
| `json` | A body of JSON. The procedure sets `content-type: application/json`. |
|
|
38
|
+
| `body` | A body of text. The procedure sets `content-type: text/plain; charset=utf-8`. |
|
|
39
|
+
| `headers` | The headers of the request. A header of the input replaces a header that the procedure sets. |
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
const events = client.stream(["http", "sse"], {
|
|
43
|
+
url: "https://api.example.com/v1/chat",
|
|
44
|
+
headers: { authorization: `Bearer ${key}` },
|
|
45
|
+
json: { prompt: "Hello", stream: true },
|
|
46
|
+
});
|
|
47
|
+
for await (const event of events) console.log(event.data);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- A POST of a stream gets the same host check, size limit of the request, time limits and deadline as the other requests.
|
|
51
|
+
- Two bodies, or a `GET` with a body, fail before the request.
|
|
52
|
+
|
|
30
53
|
## The hosts
|
|
31
54
|
|
|
32
55
|
The default module (`httpModule`) reaches each public host. It refuses these addresses:
|
|
@@ -106,6 +129,7 @@ const registry = createRegistry(createHttpModule({ allow: ["localhost:11434", "1
|
|
|
106
129
|
- The parse obeys the rules of the HTML standard. A line ends at CR, LF or CRLF. A blank line sends an event. A line that starts with a colon is a comment.
|
|
107
130
|
- An event has `event` (`message` by default), `data`, the last event ID `id` and `retry`.
|
|
108
131
|
- The procedure does not connect again after the end of the stream. To continue, a caller sends the last ID in `lastEventId`.
|
|
132
|
+
- A redirect of a POST obeys the rules of the redirects. A 303, or a 301 or 302, continues with a GET without the body.
|
|
109
133
|
|
|
110
134
|
## Limits of this package
|
|
111
135
|
|