@procedures/http 0.2.3 → 0.4.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 +71 -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
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* http.sse procedure
|
|
3
3
|
*
|
|
4
|
-
* Read a stream of server-sent events. The procedure sends a GET with
|
|
5
|
-
* `accept: text/event-stream
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Read a stream of server-sent events. The procedure sends a GET, or a POST with a body of JSON or
|
|
5
|
+
* text, with `accept: text/event-stream`. An LLM API sends its answer to a POST as such a stream.
|
|
6
|
+
* Each event is one item: its type, its data and the last event ID. The procedure does not
|
|
7
|
+
* connect again after the end of the stream. To continue, a caller sends the last ID in
|
|
8
|
+
* `lastEventId`. The stream can run without an end (roadmap R15).
|
|
8
9
|
*
|
|
9
10
|
* The call waits for the status of the response. A refused host, a failed connection, a status
|
|
10
11
|
* outside 200 to 299 and another content type fail the call itself, before the first item.
|
|
11
12
|
*/
|
|
12
13
|
|
|
13
14
|
import { HttpError } from "../../errors.js";
|
|
14
|
-
import { DEFAULT_ITEM_BYTES, DEFAULT_SETTINGS, exchange, headerText, isOk,
|
|
15
|
+
import { DEFAULT_ITEM_BYTES, DEFAULT_SETTINGS, exchange, headerText, isOk, prepareStream, statusError, touching, type Exchange, type HttpSettings } from "../../exchange.js";
|
|
15
16
|
import { sseEvents } from "../../parsers.js";
|
|
16
17
|
import { CallScope, type ScopeContext } from "../../scope.js";
|
|
17
18
|
import type { HttpSseInput, HttpSseOutput } from "../../types.js";
|
|
@@ -43,7 +44,7 @@ async function* events(opened: Exchange, scope: CallScope, maxEventBytes: number
|
|
|
43
44
|
export async function httpSse(input: HttpSseInput, ctx: ScopeContext = {}, settings: HttpSettings = DEFAULT_SETTINGS): Promise<AsyncGenerator<HttpSseOutput, void, undefined>> {
|
|
44
45
|
const headers: Record<string, string> = { accept: "text/event-stream", "cache-control": "no-cache" };
|
|
45
46
|
if (input.lastEventId !== undefined) headers["last-event-id"] = input.lastEventId;
|
|
46
|
-
const prepared =
|
|
47
|
+
const prepared = prepareStream(input, PATH, settings, headers);
|
|
47
48
|
const scope = new CallScope(PATH, ctx, { timeoutMs: input.timeoutMs, idleTimeoutMs: input.idleTimeoutMs });
|
|
48
49
|
let opened: Exchange | undefined;
|
|
49
50
|
try {
|
package/src/types.ts
CHANGED
|
@@ -93,6 +93,12 @@ export interface HttpJsonOutput {
|
|
|
93
93
|
// =============================================================================
|
|
94
94
|
|
|
95
95
|
export interface HttpStreamInput extends HttpTarget {
|
|
96
|
+
/** GET, or POST. The default is POST with `body` or `json`, and GET without them. */
|
|
97
|
+
method?: "GET" | "POST" | undefined;
|
|
98
|
+
/** A body of text for a POST. */
|
|
99
|
+
body?: string | undefined;
|
|
100
|
+
/** A body of JSON for a POST: the procedure sets `content-type: application/json`. */
|
|
101
|
+
json?: unknown;
|
|
96
102
|
/** The time of the whole stream, in milliseconds. The default is no limit. */
|
|
97
103
|
timeoutMs?: number | undefined;
|
|
98
104
|
/** The longest time without data, in milliseconds. The default is no limit. */
|