@nyte-ai/protocol 0.0.0-stage → 0.0.19

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.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +22 -2
  3. package/THIRD-PARTY-NOTICES.md +866 -0
  4. package/dist/chunks/client-053qg1fq.js +165 -0
  5. package/dist/chunks/client-3sbyne3r.js +22 -0
  6. package/dist/chunks/client-5xm0heem.js +185 -0
  7. package/dist/chunks/client-b8brz84x.js +113 -0
  8. package/dist/chunks/client-eggvt9rc.js +36 -0
  9. package/dist/chunks/client-hrkzqw6w.js +21 -0
  10. package/dist/chunks/client-kq4yq8n4.js +305 -0
  11. package/dist/chunks/client-rk08pxm6.js +12 -0
  12. package/dist/chunks/client-sffw3se8.js +157 -0
  13. package/dist/chunks/client-wffhcyad.js +387 -0
  14. package/dist/chunks/client-x7k53ygp.js +0 -0
  15. package/dist/chunks/client-xscg1xbf.js +44 -0
  16. package/dist/src/client.d.ts +25 -0
  17. package/dist/src/client.js +11 -0
  18. package/dist/src/codec.d.ts +15 -0
  19. package/dist/src/codec.js +19 -0
  20. package/dist/src/declarations.d.ts +25 -0
  21. package/dist/src/declarations.js +1 -0
  22. package/dist/src/digest.d.ts +2 -0
  23. package/dist/src/digest.js +6 -0
  24. package/dist/src/index.d.ts +11 -0
  25. package/dist/src/index.js +98 -0
  26. package/dist/src/json.d.ts +2 -0
  27. package/dist/src/json.js +6 -0
  28. package/dist/src/raw-parts.d.ts +10 -0
  29. package/dist/src/raw-parts.js +6 -0
  30. package/dist/src/stream-buffer.d.ts +7 -0
  31. package/dist/src/stream-buffer.js +6 -0
  32. package/dist/src/stream-channel.d.ts +27 -0
  33. package/dist/src/stream-channel.js +16 -0
  34. package/dist/src/stream-client.d.ts +7 -0
  35. package/dist/src/stream-client.js +10 -0
  36. package/dist/src/streams.d.ts +2 -0
  37. package/dist/src/streams.js +8 -0
  38. package/dist/src/view-frames.d.ts +5 -0
  39. package/dist/src/view-frames.js +9 -0
  40. package/dist/src/wire.d.ts +46 -0
  41. package/dist/src/wire.js +35 -0
  42. package/package.json +44 -3
@@ -0,0 +1,6 @@
1
+ import {
2
+ rawPart2
3
+ } from "../chunks/client-eggvt9rc.js";
4
+ export {
5
+ rawPart2 as rawPart
6
+ };
@@ -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,6 @@
1
+ import {
2
+ streamBuffer2
3
+ } from "../chunks/client-b8brz84x.js";
4
+ export {
5
+ streamBuffer2 as streamBuffer
6
+ };
@@ -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,2 @@
1
+ export declare function mapped<T, U>(source: AsyncIterable<T>, map: (value: T) => U): AsyncIterable<U>;
2
+ export declare function abortable<T>(source: AsyncIterable<T>, signal: AbortSignal): AsyncIterable<T>;
@@ -0,0 +1,8 @@
1
+ import {
2
+ mapped2,
3
+ abortable2
4
+ } from "../chunks/client-xscg1xbf.js";
5
+ export {
6
+ abortable2 as abortable,
7
+ mapped2 as mapped
8
+ };
@@ -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,9 @@
1
+ import {
2
+ viewFrames2,
3
+ applyViewFrame2
4
+ } from "../chunks/client-sffw3se8.js";
5
+ import"../chunks/client-xscg1xbf.js";
6
+ export {
7
+ applyViewFrame2 as applyViewFrame,
8
+ viewFrames2 as viewFrames
9
+ };
@@ -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;
@@ -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.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.19",
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.19",
29
+ "@nyte-ai/schema": "0.0.19",
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": "tsrs --noEmit",
44
+ "test": "vitest --run",
45
+ "build:package": "bun ../../scripts/sdk-packages.mjs build protocol"
46
+ }
6
47
  }