@nyte-ai/protocol 0.0.0-stage → 0.0.18
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/LICENSE +21 -0
- package/README.md +22 -2
- package/THIRD-PARTY-NOTICES.md +800 -0
- package/dist/chunks/client-053qg1fq.js +165 -0
- package/dist/chunks/client-3sbyne3r.js +22 -0
- package/dist/chunks/client-5xm0heem.js +185 -0
- package/dist/chunks/client-624vz0q1.js +155 -0
- package/dist/chunks/client-b8brz84x.js +113 -0
- package/dist/chunks/client-eggvt9rc.js +36 -0
- package/dist/chunks/client-hrkzqw6w.js +21 -0
- package/dist/chunks/client-kq4yq8n4.js +305 -0
- package/dist/chunks/client-rk08pxm6.js +12 -0
- package/dist/chunks/client-wffhcyad.js +387 -0
- package/dist/chunks/client-x7k53ygp.js +0 -0
- package/dist/chunks/client-xscg1xbf.js +44 -0
- package/dist/src/client.d.ts +25 -0
- package/dist/src/client.js +11 -0
- package/dist/src/codec.d.ts +15 -0
- package/dist/src/codec.js +19 -0
- package/dist/src/declarations.d.ts +25 -0
- package/dist/src/declarations.js +1 -0
- package/dist/src/digest.d.ts +2 -0
- package/dist/src/digest.js +6 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.js +98 -0
- package/dist/src/json.d.ts +2 -0
- package/dist/src/json.js +6 -0
- package/dist/src/raw-parts.d.ts +10 -0
- package/dist/src/raw-parts.js +6 -0
- package/dist/src/stream-buffer.d.ts +7 -0
- package/dist/src/stream-buffer.js +6 -0
- package/dist/src/stream-channel.d.ts +27 -0
- package/dist/src/stream-channel.js +16 -0
- package/dist/src/stream-client.d.ts +7 -0
- package/dist/src/stream-client.js +10 -0
- package/dist/src/streams.d.ts +2 -0
- package/dist/src/streams.js +8 -0
- package/dist/src/view-frames.d.ts +5 -0
- package/dist/src/view-frames.js +9 -0
- package/dist/src/wire.d.ts +46 -0
- package/dist/src/wire.js +35 -0
- package/package.json +44 -3
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// src/streams.ts
|
|
2
|
+
function mapped2(source, map) {
|
|
3
|
+
return {
|
|
4
|
+
[Symbol.asyncIterator]() {
|
|
5
|
+
const iterator = source[Symbol.asyncIterator]();
|
|
6
|
+
return {
|
|
7
|
+
async next() {
|
|
8
|
+
const next = await iterator.next();
|
|
9
|
+
return next.done === true ? { done: true, value: undefined } : { done: false, value: map(next.value) };
|
|
10
|
+
},
|
|
11
|
+
async return() {
|
|
12
|
+
await iterator.return?.();
|
|
13
|
+
return { done: true, value: undefined };
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function abortable2(source, signal) {
|
|
20
|
+
return {
|
|
21
|
+
[Symbol.asyncIterator]() {
|
|
22
|
+
const iterator = source[Symbol.asyncIterator]();
|
|
23
|
+
const close = () => void iterator.return?.();
|
|
24
|
+
signal.addEventListener("abort", close, { once: true });
|
|
25
|
+
return {
|
|
26
|
+
async next() {
|
|
27
|
+
if (signal.aborted)
|
|
28
|
+
return { done: true, value: undefined };
|
|
29
|
+
const next = await iterator.next();
|
|
30
|
+
if (next.done === true)
|
|
31
|
+
signal.removeEventListener("abort", close);
|
|
32
|
+
return next;
|
|
33
|
+
},
|
|
34
|
+
async return() {
|
|
35
|
+
signal.removeEventListener("abort", close);
|
|
36
|
+
await iterator.return?.();
|
|
37
|
+
return { done: true, value: undefined };
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { mapped2, abortable2 };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ByteReader, FileVersion, HostId, Json, OutputFrame, RequestOptions } from "@nyte-ai/schema";
|
|
2
|
+
import type { OperationName } from "./declarations.ts";
|
|
3
|
+
/** Describes where a transport sends requests, the headers each carries (credentials, read again per request), and the `fetch` it uses. */
|
|
4
|
+
export type TransportOptions = {
|
|
5
|
+
readonly url: string;
|
|
6
|
+
headers(): Promise<Readonly<Record<string, string>>>;
|
|
7
|
+
readonly fetch?: (url: string, init?: RequestInit) => Promise<Response>;
|
|
8
|
+
};
|
|
9
|
+
/** Returns a byte reader over a response body: its size from `Content-Length` and its mime from `X-Nyte-Mime` when the host sent them (§40w), and the file version the host read when it sent one (`X-Nyte-Version`, §40h). */
|
|
10
|
+
export type ResponseReader = ByteReader & {
|
|
11
|
+
readonly version?: FileVersion;
|
|
12
|
+
};
|
|
13
|
+
/** Returns the low-level client, one primitive per wire shape: `invoke` (JSON in and out), `frames` (a stream row's event-stream JSON frames), `output` (`job.output`'s framed octets as byte, `gap` and `exit` frames), `bytes` (an octet answer as a reader), `upload` (bytes as the body, the input in `X-Nyte-Input`; its signal aborts the request), `credential` (the `X-Nyte-Credential` a pairing exchange returned, §40j) and `host` (the `X-Nyte-Host` of the first response that carried one, error answers included, §43j; a later response naming another host throws `stale` with that host's id, its answer unread); only a `TypeError` from `fetch` is `unavailable`, any other exception reaching the caller as thrown (§47m); `return()` on a `frames` or `output` iterator aborts its request and resolves at once (§40x); every error answer is rethrown as the `SdkError` it encodes. */
|
|
14
|
+
export type Transport = {
|
|
15
|
+
invoke(name: OperationName, input: Json, options?: RequestOptions): Promise<Json>;
|
|
16
|
+
frames(name: OperationName, input: Json): AsyncIterable<Json>;
|
|
17
|
+
output(input: Json): AsyncIterable<OutputFrame>;
|
|
18
|
+
bytes(name: OperationName, input: Json, options?: RequestOptions): Promise<ResponseReader>;
|
|
19
|
+
upload(name: OperationName, input: Json, body: Uint8Array | ReadableStream<Uint8Array>, options?: RequestOptions): Promise<Json>;
|
|
20
|
+
credential(): string | null;
|
|
21
|
+
host(): HostId | null;
|
|
22
|
+
operations(): string | null;
|
|
23
|
+
};
|
|
24
|
+
/** Returns a transport over `fetch` and `ReadableStream`, with no `EventSource`, so headers reach every request and it runs in browsers and React Native; a host off loopback is asked for deflated stream frames. */
|
|
25
|
+
export declare function createTransport(options: TransportOptions): Transport;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createTransport2
|
|
3
|
+
} from "../chunks/client-5xm0heem.js";
|
|
4
|
+
import"../chunks/client-053qg1fq.js";
|
|
5
|
+
import"../chunks/client-3sbyne3r.js";
|
|
6
|
+
import"../chunks/client-kq4yq8n4.js";
|
|
7
|
+
import"../chunks/client-rk08pxm6.js";
|
|
8
|
+
import"../chunks/client-b8brz84x.js";
|
|
9
|
+
export {
|
|
10
|
+
createTransport2 as createTransport
|
|
11
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Json } from "@nyte-ai/schema";
|
|
2
|
+
import type { ByteName, CallName, OperationInput, OperationName, OperationOutput } from "./declarations.ts";
|
|
3
|
+
/** Whether `name` names a row of the operations table. */
|
|
4
|
+
export declare function namesOperation(name: string): name is OperationName;
|
|
5
|
+
/** Whether a row is answered once with JSON: a query, command or receipt. */
|
|
6
|
+
export declare function answersOnce(name: OperationName): name is CallName;
|
|
7
|
+
/** Whether a row is a stream of bytes, answered as a raw octet stream. */
|
|
8
|
+
export declare function answersBytes(name: OperationName): name is ByteName;
|
|
9
|
+
/** Decodes an operation's input strictly: a value failing the row's input schema, or carrying a field the schema does not name, throws `SdkError("invalid")` with its issues. */
|
|
10
|
+
export declare function decodeInput<N extends OperationName>(name: N, value: unknown): OperationInput<N>;
|
|
11
|
+
/** Encodes an operation's input as the JSON the wire carries. */
|
|
12
|
+
export declare function encodeInput<N extends OperationName>(_name: N, input: OperationInput<N>): Json;
|
|
13
|
+
/** Encodes an operation's output, or one frame of it, as the JSON the wire carries: `Set`s become arrays, `Map`s objects and bytes base64; fields its schema does not name are stripped; an undefined field is omitted, or null where the schema requires it and accepts null (`part.act`'s output, §40f). */
|
|
14
|
+
export declare function encodeOutput<N extends OperationName>(name: N, value: OperationOutput<N>): Json;
|
|
15
|
+
export declare function decodeOutput<N extends OperationName>(name: N, value: unknown): OperationOutput<N>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
namesOperation2,
|
|
3
|
+
answersOnce2,
|
|
4
|
+
answersBytes2,
|
|
5
|
+
decodeInput2,
|
|
6
|
+
encodeInput2,
|
|
7
|
+
encodeOutput2,
|
|
8
|
+
decodeOutput2
|
|
9
|
+
} from "../chunks/client-wffhcyad.js";
|
|
10
|
+
import"../chunks/client-eggvt9rc.js";
|
|
11
|
+
export {
|
|
12
|
+
answersBytes2 as answersBytes,
|
|
13
|
+
answersOnce2 as answersOnce,
|
|
14
|
+
decodeInput2 as decodeInput,
|
|
15
|
+
decodeOutput2 as decodeOutput,
|
|
16
|
+
encodeInput2 as encodeInput,
|
|
17
|
+
encodeOutput2 as encodeOutput,
|
|
18
|
+
namesOperation2 as namesOperation
|
|
19
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Infer, Json, OPERATIONS } from "@nyte-ai/schema";
|
|
2
|
+
type Frozen<T> = [Json] extends [T] ? T : T extends string | number | boolean | null | undefined | Uint8Array ? T : T extends readonly (infer E)[] ? readonly Frozen<E>[] : {
|
|
3
|
+
readonly [K in keyof T]: Frozen<T[K]>;
|
|
4
|
+
};
|
|
5
|
+
/** Returns the operations table's type: each row's literal kind, authority and scope, and its schemas. */
|
|
6
|
+
export type Declarations = typeof OPERATIONS;
|
|
7
|
+
/** Names one served operation: a key of the table. */
|
|
8
|
+
export type OperationName = keyof Declarations;
|
|
9
|
+
/** Returns one operation's decoded input, as its schema types it, read-only. */
|
|
10
|
+
export type OperationInput<N extends OperationName> = Frozen<Infer<Declarations[N]["input"]>>;
|
|
11
|
+
/** Returns one operation's decoded output, as its schema types it, read-only: its value, or one frame of a `watch` or `stream` row. */
|
|
12
|
+
export type OperationOutput<N extends OperationName> = Frozen<Infer<Declarations[N]["output"]>>;
|
|
13
|
+
/** Names the rows answered once with JSON: queries, commands and receipts. */
|
|
14
|
+
export type CallName = {
|
|
15
|
+
[N in OperationName]: Declarations[N]["kind"] extends "query" | "command" | "receipt" ? N : never;
|
|
16
|
+
}[OperationName];
|
|
17
|
+
/** Names the stream rows whose frames are bytes, answered as a raw octet stream. */
|
|
18
|
+
export type ByteName = {
|
|
19
|
+
[N in OperationName]: Declarations[N]["kind"] extends "stream" ? OperationOutput<N> extends Uint8Array ? N : never : never;
|
|
20
|
+
}[OperationName];
|
|
21
|
+
/** Names the rows answered with JSON frames over server-sent events: every watch and the JSON streams. */
|
|
22
|
+
export type FrameName = Exclude<{
|
|
23
|
+
[N in OperationName]: Declarations[N]["kind"] extends "watch" | "stream" ? N : never;
|
|
24
|
+
}[OperationName], ByteName | "job.output">;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"../chunks/client-x7k53ygp.js";
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** Returns the operations table's SHA-256 digest, the first 16 hex digits: it hashes each row's name, kind, access and wire schemas in table order, so two builds whose tables differ in any operation or schema get different digests. */
|
|
2
|
+
export declare function operationsDigest(): Promise<string>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./client.ts";
|
|
2
|
+
export * from "./codec.ts";
|
|
3
|
+
export * from "./declarations.ts";
|
|
4
|
+
export * from "./stream-channel.ts";
|
|
5
|
+
export * from "./wire.ts";
|
|
6
|
+
export * from "./view-frames.ts";
|
|
7
|
+
export { parseJson } from "./json.ts";
|
|
8
|
+
export { streamBuffer } from "./stream-buffer.ts";
|
|
9
|
+
export { createStreamClient } from "./stream-client.ts";
|
|
10
|
+
export { abortable, mapped } from "./streams.ts";
|
|
11
|
+
export { operationsDigest } from "./digest.ts";
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseJson2
|
|
3
|
+
} from "../chunks/client-rk08pxm6.js";
|
|
4
|
+
import {
|
|
5
|
+
errorStatus2,
|
|
6
|
+
INPUT_HEADER2,
|
|
7
|
+
HOST_HEADER2,
|
|
8
|
+
OPERATIONS_HEADER2,
|
|
9
|
+
encodeError2,
|
|
10
|
+
decodeError2,
|
|
11
|
+
statusCode2,
|
|
12
|
+
sseFrames2,
|
|
13
|
+
parseSse2,
|
|
14
|
+
octetStream2,
|
|
15
|
+
outputFrames2,
|
|
16
|
+
parseOutputFrames2,
|
|
17
|
+
withInputHeader2,
|
|
18
|
+
readInputHeader2,
|
|
19
|
+
asSdkError2
|
|
20
|
+
} from "../chunks/client-kq4yq8n4.js";
|
|
21
|
+
import {
|
|
22
|
+
CHANNEL_PATH2,
|
|
23
|
+
CANCEL_PATH2,
|
|
24
|
+
CHANNEL_HEADER2,
|
|
25
|
+
STREAM_HEADER2,
|
|
26
|
+
DEFLATE_REQUEST2,
|
|
27
|
+
readStreamFrame2
|
|
28
|
+
} from "../chunks/client-3sbyne3r.js";
|
|
29
|
+
import {
|
|
30
|
+
streamBuffer2
|
|
31
|
+
} from "../chunks/client-b8brz84x.js";
|
|
32
|
+
import {
|
|
33
|
+
createStreamClient2
|
|
34
|
+
} from "../chunks/client-053qg1fq.js";
|
|
35
|
+
import {
|
|
36
|
+
createTransport2
|
|
37
|
+
} from "../chunks/client-5xm0heem.js";
|
|
38
|
+
import"../chunks/client-eggvt9rc.js";
|
|
39
|
+
import {
|
|
40
|
+
namesOperation2,
|
|
41
|
+
answersOnce2,
|
|
42
|
+
answersBytes2,
|
|
43
|
+
decodeInput2,
|
|
44
|
+
encodeInput2,
|
|
45
|
+
encodeOutput2,
|
|
46
|
+
decodeOutput2
|
|
47
|
+
} from "../chunks/client-wffhcyad.js";
|
|
48
|
+
import"../chunks/client-x7k53ygp.js";
|
|
49
|
+
import {
|
|
50
|
+
mapped2,
|
|
51
|
+
abortable2
|
|
52
|
+
} from "../chunks/client-xscg1xbf.js";
|
|
53
|
+
import {
|
|
54
|
+
viewFrames2,
|
|
55
|
+
applyViewFrame2
|
|
56
|
+
} from "../chunks/client-624vz0q1.js";
|
|
57
|
+
import {
|
|
58
|
+
operationsDigest2
|
|
59
|
+
} from "../chunks/client-hrkzqw6w.js";
|
|
60
|
+
export {
|
|
61
|
+
CANCEL_PATH2 as CANCEL_PATH,
|
|
62
|
+
CHANNEL_HEADER2 as CHANNEL_HEADER,
|
|
63
|
+
CHANNEL_PATH2 as CHANNEL_PATH,
|
|
64
|
+
DEFLATE_REQUEST2 as DEFLATE_REQUEST,
|
|
65
|
+
HOST_HEADER2 as HOST_HEADER,
|
|
66
|
+
INPUT_HEADER2 as INPUT_HEADER,
|
|
67
|
+
OPERATIONS_HEADER2 as OPERATIONS_HEADER,
|
|
68
|
+
STREAM_HEADER2 as STREAM_HEADER,
|
|
69
|
+
abortable2 as abortable,
|
|
70
|
+
answersBytes2 as answersBytes,
|
|
71
|
+
answersOnce2 as answersOnce,
|
|
72
|
+
applyViewFrame2 as applyViewFrame,
|
|
73
|
+
asSdkError2 as asSdkError,
|
|
74
|
+
createStreamClient2 as createStreamClient,
|
|
75
|
+
createTransport2 as createTransport,
|
|
76
|
+
decodeError2 as decodeError,
|
|
77
|
+
decodeInput2 as decodeInput,
|
|
78
|
+
decodeOutput2 as decodeOutput,
|
|
79
|
+
encodeError2 as encodeError,
|
|
80
|
+
encodeInput2 as encodeInput,
|
|
81
|
+
encodeOutput2 as encodeOutput,
|
|
82
|
+
errorStatus2 as errorStatus,
|
|
83
|
+
mapped2 as mapped,
|
|
84
|
+
namesOperation2 as namesOperation,
|
|
85
|
+
octetStream2 as octetStream,
|
|
86
|
+
operationsDigest2 as operationsDigest,
|
|
87
|
+
outputFrames2 as outputFrames,
|
|
88
|
+
parseJson2 as parseJson,
|
|
89
|
+
parseOutputFrames2 as parseOutputFrames,
|
|
90
|
+
parseSse2 as parseSse,
|
|
91
|
+
readInputHeader2 as readInputHeader,
|
|
92
|
+
readStreamFrame2 as readStreamFrame,
|
|
93
|
+
sseFrames2 as sseFrames,
|
|
94
|
+
statusCode2 as statusCode,
|
|
95
|
+
streamBuffer2 as streamBuffer,
|
|
96
|
+
viewFrames2 as viewFrames,
|
|
97
|
+
withInputHeader2 as withInputHeader
|
|
98
|
+
};
|
package/dist/src/json.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Json } from "@nyte-ai/schema";
|
|
2
|
+
/**
|
|
3
|
+
* Returns a message or part view a newer host sent that this client cannot
|
|
4
|
+
* read as a raw part of the same id, or null when the item is neither. Its
|
|
5
|
+
* kind is the part's kind, or the message's own when it is not a part; its
|
|
6
|
+
* state is the part's state, or the whole item. It reads as settled, since
|
|
7
|
+
* this client cannot tell a newer status apart. Clients draw a part with no
|
|
8
|
+
* renderer as its kind and raw state.
|
|
9
|
+
*/
|
|
10
|
+
export declare function rawPart(item: unknown): Json | null;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function streamBuffer(cancel: () => void): {
|
|
2
|
+
body: import("node:stream/web").ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
3
|
+
push: (chunk: Uint8Array) => boolean;
|
|
4
|
+
write(chunk: Uint8Array, signal: AbortSignal): Promise<void>;
|
|
5
|
+
end(final?: Uint8Array): void;
|
|
6
|
+
fail(error: Error): void;
|
|
7
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Json } from "@nyte-ai/schema";
|
|
2
|
+
export declare const CHANNEL_PATH = ".nyte/streams";
|
|
3
|
+
export declare const CANCEL_PATH = ".nyte/streams/cancel";
|
|
4
|
+
export declare const CHANNEL_HEADER = "X-Nyte-Channel";
|
|
5
|
+
export declare const STREAM_HEADER = "X-Nyte-Stream";
|
|
6
|
+
/** The channel-open body of a client that inflates `deflated` frames. */
|
|
7
|
+
export declare const DEFLATE_REQUEST: {
|
|
8
|
+
readonly deflate: true;
|
|
9
|
+
};
|
|
10
|
+
/** A `chunk` carries a stream's bytes as base64; a `deflated` one carries them raw-deflated (RFC 1951), then base64, for a client that opened its channel with `DEFLATE_REQUEST`. */
|
|
11
|
+
export type StreamFrame = {
|
|
12
|
+
readonly kind: "chunk";
|
|
13
|
+
readonly stream: string;
|
|
14
|
+
readonly data: string;
|
|
15
|
+
} | {
|
|
16
|
+
readonly kind: "deflated";
|
|
17
|
+
readonly stream: string;
|
|
18
|
+
readonly data: string;
|
|
19
|
+
} | {
|
|
20
|
+
readonly kind: "end";
|
|
21
|
+
readonly stream: string;
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: "error";
|
|
24
|
+
readonly stream: string;
|
|
25
|
+
readonly error: string;
|
|
26
|
+
};
|
|
27
|
+
export declare function readStreamFrame(value: Json): StreamFrame;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CHANNEL_PATH2,
|
|
3
|
+
CANCEL_PATH2,
|
|
4
|
+
CHANNEL_HEADER2,
|
|
5
|
+
STREAM_HEADER2,
|
|
6
|
+
DEFLATE_REQUEST2,
|
|
7
|
+
readStreamFrame2
|
|
8
|
+
} from "../chunks/client-3sbyne3r.js";
|
|
9
|
+
export {
|
|
10
|
+
CANCEL_PATH2 as CANCEL_PATH,
|
|
11
|
+
CHANNEL_HEADER2 as CHANNEL_HEADER,
|
|
12
|
+
CHANNEL_PATH2 as CHANNEL_PATH,
|
|
13
|
+
DEFLATE_REQUEST2 as DEFLATE_REQUEST,
|
|
14
|
+
STREAM_HEADER2 as STREAM_HEADER,
|
|
15
|
+
readStreamFrame2 as readStreamFrame
|
|
16
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Json } from "@nyte-ai/schema";
|
|
2
|
+
type Post = (path: string, init: RequestInit & {
|
|
3
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
4
|
+
}) => Promise<Response>;
|
|
5
|
+
/** Multiplex streams over one channel opened through `post`, asking for `deflated` frames when `deflate`; the channel closes when its last stream is released. */
|
|
6
|
+
export declare function createStreamClient(post: Post, deflate: boolean): (name: string, input: Json, signal: AbortSignal) => Promise<ReadableStream<Uint8Array>>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createStreamClient2
|
|
3
|
+
} from "../chunks/client-053qg1fq.js";
|
|
4
|
+
import"../chunks/client-3sbyne3r.js";
|
|
5
|
+
import"../chunks/client-kq4yq8n4.js";
|
|
6
|
+
import"../chunks/client-rk08pxm6.js";
|
|
7
|
+
import"../chunks/client-b8brz84x.js";
|
|
8
|
+
export {
|
|
9
|
+
createStreamClient2 as createStreamClient
|
|
10
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SessionView, ViewFrame } from "@nyte-ai/schema";
|
|
2
|
+
/** Returns each view as the frame `head.watch` sends: the first whole, each later one as what changed since the view before it, compared by identity, so a view that reuses its predecessor's items sends only the items it replaced; a streaming part's message sends only its appended text. */
|
|
3
|
+
export declare function viewFrames(views: AsyncIterable<SessionView>): AsyncIterable<ViewFrame>;
|
|
4
|
+
/** Returns the view a frame describes: a whole view as it is, a delta applied to `view`, the frame before it, keeping every item the delta copies; a delta with no view before it, or one that does not fit it, throws `SdkError("invalid")`. */
|
|
5
|
+
export declare function applyViewFrame(view: SessionView | null, frame: ViewFrame): SessionView;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { SdkError } from "@nyte-ai/schema";
|
|
2
|
+
import type { ByteReader, Json, OutputFrame, SdkErrorCode, SdkErrorWire } from "@nyte-ai/schema";
|
|
3
|
+
/** Maps each error code to the HTTP status the handler answers it with. */
|
|
4
|
+
export declare const errorStatus: {
|
|
5
|
+
readonly invalid: 400;
|
|
6
|
+
readonly unauthenticated: 401;
|
|
7
|
+
readonly denied: 403;
|
|
8
|
+
readonly unknown: 404;
|
|
9
|
+
readonly stale: 409;
|
|
10
|
+
readonly internal: 500;
|
|
11
|
+
readonly unavailable: 503;
|
|
12
|
+
};
|
|
13
|
+
/** Names the request header that carries an operation's JSON input when the body carries its bytes. */
|
|
14
|
+
export declare const INPUT_HEADER = "X-Nyte-Input";
|
|
15
|
+
/** Names the response header carrying the id of the host that answered, `X-Nyte-Host: <hostId>`, on every response a listener sends, so a client compares it with `expect.hostId` on its first answer (§43a, §43j). */
|
|
16
|
+
export declare const HOST_HEADER = "X-Nyte-Host";
|
|
17
|
+
export declare const OPERATIONS_HEADER = "X-Nyte-Operations";
|
|
18
|
+
/** Serialises an `SdkError` as the wire error: code, message, host, issues and correlation. */
|
|
19
|
+
export declare function encodeError(error: SdkError): SdkErrorWire;
|
|
20
|
+
/** Rebuilds the `SdkError` a wire error carries; a body that is not a wire error is the code `statusCode` gives the response's status, `internal` without one. */
|
|
21
|
+
export declare function decodeError(value: Json, status?: number): SdkError;
|
|
22
|
+
/** Returns the error code an HTTP status stands for when the body is not a wire error: `invalid` for 400 and 413, `internal` for any status the table does not name. */
|
|
23
|
+
export declare function statusCode(status: number): SdkErrorCode;
|
|
24
|
+
/** Frames JSON values as server-sent events, each one `data:` line; a `: ping` comment every `heartbeatMs` while it waits; an error the source throws is the last frame, an `error` event carrying the wire error. Cancelling the stream returns the source. */
|
|
25
|
+
export declare function sseFrames(source: AsyncIterable<Json>, options?: {
|
|
26
|
+
readonly heartbeatMs?: number;
|
|
27
|
+
}): ReadableStream<Uint8Array>;
|
|
28
|
+
/** Parses a server-sent event stream into each frame's JSON data; comments and any other field are skipped, and an `error` event throws the `SdkError` it carries. Returning early cancels the stream. */
|
|
29
|
+
export declare function parseSse(stream: ReadableStream<Uint8Array>): AsyncGenerator<Json>;
|
|
30
|
+
/** Returns an `application/octet-stream` response over a byte reader: its mime in `X-Nyte-Mime`, its size as `Content-Length` when known (§40w), plus `headers`. The reader closes once, when the body ends, is cancelled, or `signal` aborts; an abort also errors the body. */
|
|
31
|
+
export declare function octetStream(body: {
|
|
32
|
+
readonly reader: ByteReader;
|
|
33
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
34
|
+
}, signal: AbortSignal): Response;
|
|
35
|
+
/** Frames a job's output as one octet stream (§40h): each `bytes` frame `0x00 <u32be length> <bytes>`, each `gap` and the `exit` `0x01 <u32be length> <json>`; an error the source throws is a last control frame carrying the wire error. Cancelling the stream returns the source. */
|
|
36
|
+
export declare function outputFrames(source: AsyncIterable<OutputFrame>): ReadableStream<Uint8Array>;
|
|
37
|
+
/** Parses an octet stream framed by `outputFrames` back into output frames; a control frame of a kind it does not know is skipped, and an error frame throws the `SdkError` it carries. Returning early cancels the stream. */
|
|
38
|
+
export declare function parseOutputFrames(stream: ReadableStream<Uint8Array>): AsyncGenerator<OutputFrame>;
|
|
39
|
+
/** Returns the request init for an operation whose bytes travel as the body: the JSON input base64url in `X-Nyte-Input`, the bytes as `application/octet-stream`. A stream is sent half-duplex. */
|
|
40
|
+
export declare function withInputHeader(input: Json, body: Uint8Array | ReadableStream<Uint8Array>): RequestInit & {
|
|
41
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
42
|
+
};
|
|
43
|
+
/** Returns the JSON input a request carries in `X-Nyte-Input`, or null when it carries none; a header that is not base64url JSON throws `SdkError("invalid")`. */
|
|
44
|
+
export declare function readInputHeader(request: Request): Json | null;
|
|
45
|
+
/** Returns an error as the `SdkError` the wire carries: itself when it is one, else `internal` with a fresh correlation id. */
|
|
46
|
+
export declare function asSdkError(error: unknown): SdkError;
|
package/dist/src/wire.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
errorStatus2,
|
|
3
|
+
INPUT_HEADER2,
|
|
4
|
+
HOST_HEADER2,
|
|
5
|
+
OPERATIONS_HEADER2,
|
|
6
|
+
encodeError2,
|
|
7
|
+
decodeError2,
|
|
8
|
+
statusCode2,
|
|
9
|
+
sseFrames2,
|
|
10
|
+
parseSse2,
|
|
11
|
+
octetStream2,
|
|
12
|
+
outputFrames2,
|
|
13
|
+
parseOutputFrames2,
|
|
14
|
+
withInputHeader2,
|
|
15
|
+
readInputHeader2,
|
|
16
|
+
asSdkError2
|
|
17
|
+
} from "../chunks/client-kq4yq8n4.js";
|
|
18
|
+
import"../chunks/client-rk08pxm6.js";
|
|
19
|
+
export {
|
|
20
|
+
HOST_HEADER2 as HOST_HEADER,
|
|
21
|
+
INPUT_HEADER2 as INPUT_HEADER,
|
|
22
|
+
OPERATIONS_HEADER2 as OPERATIONS_HEADER,
|
|
23
|
+
asSdkError2 as asSdkError,
|
|
24
|
+
decodeError2 as decodeError,
|
|
25
|
+
encodeError2 as encodeError,
|
|
26
|
+
errorStatus2 as errorStatus,
|
|
27
|
+
octetStream2 as octetStream,
|
|
28
|
+
outputFrames2 as outputFrames,
|
|
29
|
+
parseOutputFrames2 as parseOutputFrames,
|
|
30
|
+
parseSse2 as parseSse,
|
|
31
|
+
readInputHeader2 as readInputHeader,
|
|
32
|
+
sseFrames2 as sseFrames,
|
|
33
|
+
statusCode2 as statusCode,
|
|
34
|
+
withInputHeader2 as withInputHeader
|
|
35
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nyte-ai/protocol",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.18",
|
|
4
|
+
"private": false,
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/interfaces-lab/nyte.git",
|
|
9
|
+
"directory": "packages/protocol"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"LICENSE",
|
|
14
|
+
"THIRD-PARTY-NOTICES.md"
|
|
15
|
+
],
|
|
16
|
+
"type": "module",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/src/index.d.ts",
|
|
20
|
+
"import": "./dist/src/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public",
|
|
25
|
+
"provenance": true
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@nyte-ai/core": "0.0.18",
|
|
29
|
+
"@nyte-ai/schema": "0.0.18",
|
|
30
|
+
"fflate": "0.8.3",
|
|
31
|
+
"typebox": "1.3.36"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "^26.6.5",
|
|
35
|
+
"typescript": "6.0.3",
|
|
36
|
+
"vitest": "^5.0.5"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=26.4.0"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"clean": "rm -rf node_modules .turbo",
|
|
43
|
+
"typecheck": "tsgo --noEmit",
|
|
44
|
+
"test": "vitest --run",
|
|
45
|
+
"build:package": "bun ../../scripts/sdk-packages.mjs build protocol"
|
|
46
|
+
}
|
|
6
47
|
}
|