@nyte-ai/protocol 0.0.25-nightly.20261102.45 → 0.0.27

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/README.md CHANGED
@@ -1,23 +1,50 @@
1
1
  # @nyte-ai/protocol
2
2
 
3
- The wire between a Nyte host and a client in another process, generated from one
4
- table. `declarations` names every served operation by its Connection path
5
- (`head.send`, `git.patches`, `page.click`) with its input and output schemas
6
- from `@nyte-ai/schema`, its kind (`query`, `command`, `receipt`, `watch`,
7
- `stream`), the authority it needs and its recovery; `Signatures` types each row
8
- as core's signatures do, and a test checks the two agree both ways. The host
9
- (`@nyte-ai/host`'s `createHandler`) serves the table: exactly `POST /<name>` (a
10
- prefix is the host's mount), gated by the row's authority, input decoded strictly (an unknown
11
- field is `invalid`), output encoded leniently, a watch as server-sent events
12
- (`head.watch` sends the head's view from the host's fold whole, then each later
13
- view as what changed, so a reconnect simply starts over from the current view),
14
- bytes as `application/octet-stream` (the reader's mime in `X-Nyte-Mime`, the
15
- JSON input in `X-Nyte-Input` when bytes are the body), `job.output` as
16
- length-prefixed frames, and every failure as the encoded `SdkError` at its
17
- status; a watch or stream that fails mid-stream ends with an error frame
18
- carrying it (`event: error`, or a `0x01 { kind: "error" }` control frame on
19
- framed bytes), which the client rethrows. The sdk binds its typed client to the
20
- same table through `createTransport` (`fetch` and `ReadableStream` only, so it
21
- runs in browsers and React Native), decodes outputs with `decodeOutput` (an
22
- unknown field ignored, an array record of an unknown kind skipped) and rebuilds
23
- `Set`s and `Map`s from their wire forms.
3
+ The HTTP wire between a Nyte host and a client in another process. The host serves it, and `@nyte-ai/sdk` builds its typed client on it.
4
+
5
+ ## Operations
6
+
7
+ `OPERATIONS` in `@nyte-ai/schema` is the one table the wire comes from. Each row names an operation by its Connection path, such as `head.send`, `git.patches` or `page.click`. A row carries its input and output schemas, its kind, the authority it needs and its recovery. This package derives its types from that table: `Declarations`, `OperationName`, `OperationInput` and `OperationOutput`.
8
+
9
+ | Kind | Answer |
10
+ | --- | --- |
11
+ | `query`, `command`, `receipt` | One JSON value |
12
+ | `watch` | JSON frames as server-sent events. `connection.watch` sends the host's view each time it changes, so a reconnect starts over from the current view. |
13
+ | `stream` | JSON frames as server-sent events, or bytes as `application/octet-stream` |
14
+
15
+ ## Requests
16
+
17
+ - Each operation is `POST /<name>`.
18
+ - The host checks the row's authority before it runs the operation.
19
+ - The host decodes input strictly with `decodeInput`. An unknown field is `invalid`.
20
+ - The host encodes output with `encodeOutput`, which strips fields the schema doesn't name.
21
+ - A byte answer carries the reader's MIME type in `X-Nyte-Mime`. When bytes are the request body, the JSON input travels base64url-encoded in `X-Nyte-Input`.
22
+ - `job.output` answers length-prefixed frames. A `0x00` frame carries bytes and a `0x01` frame carries JSON control data.
23
+ - Every failure answers the encoded `SdkError` at its status.
24
+ - A watch or stream that fails partway ends with an error frame, `event: error` or a `0x01 { kind: "error" }` control frame. The client rethrows it.
25
+
26
+ ## Client
27
+
28
+ `createTransport` sends requests with `fetch` and `ReadableStream` only, so it runs in browsers and React Native:
29
+
30
+ ```ts
31
+ import { createTransport } from "@nyte-ai/protocol";
32
+
33
+ const transport = createTransport({
34
+ url: "http://127.0.0.1:4000",
35
+ headers: async () => ({ Authorization: "Bearer <token>" }),
36
+ });
37
+
38
+ const operations = await transport.invoke("operations.describe", {});
39
+ ```
40
+
41
+ `decodeOutput` decodes an answer leniently. It ignores unknown fields and skips array records of an unknown kind. The sdk then rebuilds `Set`s and `Map`s from their wire forms.
42
+
43
+ `openHostSocket` opens the host's WebSocket, which carries events and streamed text. The [host protocol](../../docs/host-protocol/README.md) describes it.
44
+
45
+ ## Development
46
+
47
+ ```sh
48
+ pnpm --dir packages/protocol test
49
+ pnpm --dir packages/protocol typecheck
50
+ ```
@@ -611,6 +611,71 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
611
611
  SOFTWARE.
612
612
  ```
613
613
 
614
+ ## Ghostty (`ghostty-org/ghostty`)
615
+
616
+ - Repository: https://github.com/ghostty-org/ghostty
617
+ - What: `packages/vt/ghostty-vt.wasm` is the signed libghostty-vt WebAssembly
618
+ build from Ghostty's `tip` release at the commit recorded in
619
+ `packages/vt/pin.json`, shipped unmodified. `packages/vt` binds its C API.
620
+
621
+ License: MIT, with the following notice:
622
+
623
+ ```text
624
+ MIT License
625
+
626
+ Copyright (c) 2024 Mitchell Hashimoto, Ghostty contributors
627
+
628
+ Permission is hereby granted, free of charge, to any person obtaining a copy
629
+ of this software and associated documentation files (the "Software"), to deal
630
+ in the Software without restriction, including without limitation the rights
631
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
632
+ copies of the Software, and to permit persons to whom the Software is
633
+ furnished to do so, subject to the following conditions:
634
+
635
+ The above copyright notice and this permission notice shall be included in all
636
+ copies or substantial portions of the Software.
637
+
638
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
639
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
640
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
641
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
642
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
643
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
644
+ SOFTWARE.
645
+ ```
646
+
647
+ ## ghostty-web (`coder/ghostty-web`)
648
+
649
+ - Repository: https://github.com/coder/ghostty-web
650
+ - What: the escape-heavy viewport row-merge fixture in `packages/vt/test` is
651
+ ported from ghostty-web's `lib/viewport-row-merge.test.ts`.
652
+
653
+ License: MIT, with the following notice:
654
+
655
+ ```text
656
+ MIT License
657
+
658
+ Copyright (c) 2025 Coder
659
+
660
+ Permission is hereby granted, free of charge, to any person obtaining a copy
661
+ of this software and associated documentation files (the "Software"), to deal
662
+ in the Software without restriction, including without limitation the rights
663
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
664
+ copies of the Software, and to permit persons to whom the Software is
665
+ furnished to do so, subject to the following conditions:
666
+
667
+ The above copyright notice and this permission notice shall be included in all
668
+ copies or substantial portions of the Software.
669
+
670
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
671
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
672
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
673
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
674
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
675
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
676
+ SOFTWARE.
677
+ ```
678
+
614
679
  ## Naybr, "Copyright Free Gameplay (No Commentary) - Minecraft Survival"
615
680
 
616
681
  - Source: https://www.youtube.com/watch?v=GPsGyv5zTlM, by Naybr (youtube.com/@Naybr)
@@ -11,6 +11,8 @@ async function operationsDigest2() {
11
11
  row.capability ?? null,
12
12
  row.recovery ?? null,
13
13
  row.wait ?? null,
14
+ row.local ?? null,
15
+ row.mcp ?? null,
14
16
  row.input["~standard"].jsonSchema.input({ target: "draft-2020-12" }),
15
17
  row.output["~standard"].jsonSchema.input({ target: "draft-2020-12" })
16
18
  ]);
@@ -12,7 +12,9 @@ var errorStatus2 = {
12
12
  unknown: 404,
13
13
  stale: 409,
14
14
  internal: 500,
15
- unavailable: 503
15
+ unavailable: 503,
16
+ not_supported: 501,
17
+ timeout: 504
16
18
  };
17
19
  var INPUT_HEADER2 = "X-Nyte-Input";
18
20
  var HOST_HEADER2 = "X-Nyte-Host";
@@ -15,7 +15,7 @@ import {
15
15
  import {
16
16
  decodeError2,
17
17
  parseSse2
18
- } from "./client-kq4yq8n4.js";
18
+ } from "./client-18p1wxbe.js";
19
19
 
20
20
  // src/stream-client.ts
21
21
  import { inflateSync } from "fflate";
@@ -8,7 +8,6 @@ import { Guard } from "typebox/guard";
8
8
  import { OPERATIONS, SdkError } from "@nyte-ai/schema";
9
9
  var INERT = { form: "inert" };
10
10
  var PRIMITIVE_TYPES = new Set(["string", "number", "integer", "boolean", "null"]);
11
- var VIEW_DEPTH = 2;
12
11
  var rows = OPERATIONS;
13
12
  var plans = new WeakMap;
14
13
  var BYTE_ROWS = {
@@ -52,7 +51,7 @@ function decodeOutput2(name, value) {
52
51
  const result = schema["~standard"].validate(value);
53
52
  if (!(result instanceof Promise) && result.issues === undefined)
54
53
  return result.value;
55
- return validated(schema, known(plan(schema), value, name === "head.watch" ? VIEW_DEPTH : null));
54
+ return validated(schema, known(plan(schema), value));
56
55
  }
57
56
  function validated(schema, value) {
58
57
  const result = schema["~standard"].validate(value);
@@ -228,38 +227,36 @@ function encode(plan, value) {
228
227
  put(record, key, null);
229
228
  return record;
230
229
  }
231
- function known(plan, value, positional) {
230
+ function known(plan, value) {
232
231
  if (plan.form === "inert")
233
232
  return value;
234
233
  if (plan.form === "choice") {
235
234
  const member = select(plan, value);
236
- return member === null ? value : known(member, value, positional);
235
+ return member === null ? value : known(member, value);
237
236
  }
238
237
  if (Guard.IsArray(value)) {
239
238
  const { items } = plan;
240
239
  if (items === null)
241
240
  return value;
242
241
  const { kinds, reads } = items;
243
- const keeps = positional !== null && positional >= 0;
244
242
  return value.flatMap((item) => {
245
243
  const kind = readKind(item);
246
244
  const listed = kinds === null || kind === undefined || kinds.has(kind);
247
- const read = listed ? known(items.plan, item, null) : item;
245
+ const read = listed ? known(items.plan, item) : item;
248
246
  if (listed && reads(read))
249
247
  return [read];
250
248
  const raw = rawPart2(item);
251
249
  if (raw !== null && reads(raw))
252
250
  return [raw];
253
- return keeps ? [read] : [];
251
+ return [];
254
252
  });
255
253
  }
256
254
  const { properties } = plan;
257
255
  if (typeof value !== "object" || value === null || properties === null)
258
256
  return value;
259
- const inner = positional === null ? null : positional - 1;
260
257
  return Object.fromEntries(Object.entries(value).map(([key, field]) => {
261
258
  const property = properties.get(key);
262
- return [key, property === undefined ? field : known(property, field, inner)];
259
+ return [key, property === undefined ? field : known(property, field)];
263
260
  }));
264
261
  }
265
262
  function select(choice, value) {
@@ -8,10 +8,10 @@ import {
8
8
  parseSse2,
9
9
  parseOutputFrames2,
10
10
  withInputHeader2
11
- } from "./client-kq4yq8n4.js";
11
+ } from "./client-18p1wxbe.js";
12
12
  import {
13
13
  createStreamClient2
14
- } from "./client-053qg1fq.js";
14
+ } from "./client-58wnq4mc.js";
15
15
 
16
16
  // src/client.ts
17
17
  import { asId, OPERATIONS, SdkError } from "@nyte-ai/schema";
@@ -0,0 +1,56 @@
1
+ // src/directory-store.ts
2
+ import { SESSIONS_LIMIT } from "@nyte-ai/schema";
3
+ function openDirectoryStore2(read, window = {}) {
4
+ const parents = window.parents ?? { kind: "all" };
5
+ const limit = Math.max(1, window.limit ?? SESSIONS_LIMIT);
6
+ const rows = new Map;
7
+ let ids = [];
8
+ let seq = 0;
9
+ const order = () => {
10
+ ids = [...rows.values()].toSorted((left, right) => right.lastActivityAt - left.lastActivityAt || compareIds(left.id, right.id)).slice(0, limit).map((row) => row.id);
11
+ };
12
+ const keep = (row) => {
13
+ if (parents.kind === "all" || row.parent === (parents.kind === "roots" ? null : parents.session))
14
+ rows.set(row.id, row);
15
+ else
16
+ rows.delete(row.id);
17
+ };
18
+ const resume = (next) => {
19
+ seq = next.seq;
20
+ for (const row of next.rows)
21
+ keep(row);
22
+ const kept = new Set(next.ids);
23
+ for (const id of rows.keys())
24
+ if (!kept.has(id))
25
+ rows.delete(id);
26
+ order();
27
+ };
28
+ resume(read);
29
+ return {
30
+ get seq() {
31
+ return seq;
32
+ },
33
+ apply(change) {
34
+ if (change.seq <= seq)
35
+ return;
36
+ seq = change.seq;
37
+ const table = change.tables.sessions;
38
+ if (table === undefined)
39
+ return;
40
+ for (const row of table.upsert)
41
+ keep(row);
42
+ for (const id of table.drop)
43
+ rows.delete(id);
44
+ order();
45
+ },
46
+ resume,
47
+ snapshot: () => ({ ids, rows })
48
+ };
49
+ }
50
+ function compareIds(left, right) {
51
+ if (left === right)
52
+ return 0;
53
+ return left < right ? -1 : 1;
54
+ }
55
+
56
+ export { openDirectoryStore2 };
@@ -0,0 +1,103 @@
1
+ // src/session-store.ts
2
+ import { backgroundRowKey, catalogRowKey } from "@nyte-ai/schema";
3
+ function openSessionStore2(window) {
4
+ const head = window.head;
5
+ let rows = emptyRows();
6
+ let seq = window.seq;
7
+ let order = window.order;
8
+ let leadingPrompt = window.leadingPrompt;
9
+ let stale = false;
10
+ write(rows, window.tables);
11
+ const move = (path) => {
12
+ if (path.after === null) {
13
+ const first = order[0];
14
+ const kept = first === undefined ? -1 : path.ids.indexOf(first);
15
+ order = kept < 0 ? path.ids : path.ids.slice(kept);
16
+ if (kept < 0)
17
+ leadingPrompt = null;
18
+ return;
19
+ }
20
+ const at = order.indexOf(path.after);
21
+ if (at < 0) {
22
+ stale = true;
23
+ return;
24
+ }
25
+ order = [...order.slice(0, at + 1), ...path.ids];
26
+ };
27
+ return {
28
+ get seq() {
29
+ return seq;
30
+ },
31
+ get stale() {
32
+ return stale;
33
+ },
34
+ apply(change) {
35
+ if (change.seq < seq)
36
+ return;
37
+ seq = change.seq;
38
+ write(rows, change.tables);
39
+ for (const path of change.paths)
40
+ if (path.head === head && !stale)
41
+ move(path);
42
+ },
43
+ resume(next) {
44
+ seq = next.seq;
45
+ order = next.order;
46
+ leadingPrompt = next.leadingPrompt;
47
+ stale = false;
48
+ if (next.complete)
49
+ rows = emptyRows();
50
+ for (const entry of rows.background)
51
+ if (entry[1].head === head)
52
+ rows.background.delete(entry[0]);
53
+ write(rows, next.tables);
54
+ const kept = new Set([
55
+ ...order,
56
+ ...leadingPrompt === null ? [] : [leadingPrompt],
57
+ ...rows.heads.get(head)?.queue ?? []
58
+ ]);
59
+ for (const id of rows.messages.keys())
60
+ if (!kept.has(id))
61
+ rows.messages.delete(id);
62
+ const turns = new Set(Array.from(rows.messages.values(), (message) => message.turn));
63
+ for (const id of rows.turns.keys())
64
+ if (!turns.has(id))
65
+ rows.turns.delete(id);
66
+ },
67
+ snapshot: () => ({ order, leadingPrompt, rows })
68
+ };
69
+ }
70
+ function emptyRows() {
71
+ return {
72
+ messages: new Map,
73
+ turns: new Map,
74
+ parts: new Map,
75
+ changes: new Map,
76
+ catalog: new Map,
77
+ heads: new Map,
78
+ settings: new Map,
79
+ usage: new Map,
80
+ background: new Map
81
+ };
82
+ }
83
+ function write(rows, tables) {
84
+ replace(rows.messages, tables.messages, (row) => row.id);
85
+ replace(rows.turns, tables.turns, (row) => row.id);
86
+ replace(rows.parts, tables.parts, (row) => row.id);
87
+ replace(rows.changes, tables.changes, (row) => row.path);
88
+ replace(rows.catalog, tables.catalog, catalogRowKey);
89
+ replace(rows.heads, tables.heads, (row) => row.name);
90
+ replace(rows.settings, tables.settings, (row) => row.name);
91
+ replace(rows.usage, tables.usage, (row) => row.name);
92
+ replace(rows.background, tables.background, backgroundRowKey);
93
+ }
94
+ function replace(rows, table, key) {
95
+ if (table === undefined)
96
+ return;
97
+ for (const row of table.upsert)
98
+ rows.set(key(row), row);
99
+ for (const id of table.drop)
100
+ rows.delete(id);
101
+ }
102
+
103
+ export { openSessionStore2 };
@@ -0,0 +1,116 @@
1
+ import {
2
+ decodeError2
3
+ } from "./client-18p1wxbe.js";
4
+
5
+ // src/socket-client.ts
6
+ import {
7
+ API_MIN_REVISION,
8
+ API_REVISION,
9
+ compile,
10
+ ErrorFrameType,
11
+ EventFrameType,
12
+ isJson,
13
+ isJsonObject,
14
+ ResultFrameType,
15
+ SdkError,
16
+ TextFrameType,
17
+ WelcomeFrameType,
18
+ withJson
19
+ } from "@nyte-ai/schema";
20
+ var welcomes = compile(withJson(WelcomeFrameType));
21
+ var results = compile(withJson(ResultFrameType));
22
+ var errors = compile(withJson(ErrorFrameType));
23
+ var events = compile(withJson(EventFrameType));
24
+ var texts = compile(withJson(TextFrameType));
25
+ async function openHostSocket2(input) {
26
+ const socket = input.socket;
27
+ const waiting = new Map;
28
+ const eventListeners = new Set;
29
+ const textListeners = new Set;
30
+ const greeted = Promise.withResolvers();
31
+ const ended = Promise.withResolvers();
32
+ let calls = 0;
33
+ greeted.promise.catch(() => {
34
+ return;
35
+ });
36
+ socket.addEventListener("message", (message) => {
37
+ const value = typeof message.data === "string" ? readJson(message.data) : undefined;
38
+ if (welcomes.Check(value))
39
+ greeted.resolve(value);
40
+ else if (results.Check(value))
41
+ settle(value.id, value.output, null);
42
+ else if (errors.Check(value))
43
+ settle(value.id, null, decodeError2(value.error));
44
+ else if (isJsonObject(value) && events.Check(value))
45
+ for (const listener of eventListeners)
46
+ listener(value);
47
+ else if (texts.Check(value))
48
+ for (const listener of textListeners)
49
+ listener(value);
50
+ });
51
+ socket.addEventListener("close", (event) => {
52
+ const closed = { code: event.code, reason: event.reason };
53
+ const failure = new SdkError("unavailable", closed.reason === "" ? `The host closed the socket (${closed.code}).` : closed.reason);
54
+ greeted.reject(failure);
55
+ for (const entry of waiting.values())
56
+ entry.reject(failure);
57
+ waiting.clear();
58
+ ended.resolve(closed);
59
+ });
60
+ const settle = (id, output, failure) => {
61
+ const entry = waiting.get(id);
62
+ if (entry === undefined)
63
+ return;
64
+ waiting.delete(id);
65
+ if (failure === null)
66
+ entry.resolve(output);
67
+ else
68
+ entry.reject(failure);
69
+ };
70
+ await new Promise((opened, failed) => {
71
+ socket.addEventListener("open", () => opened());
72
+ socket.addEventListener("error", () => failed(new SdkError("unavailable", "Couldn't open the host's socket.")));
73
+ });
74
+ socket.send(JSON.stringify({
75
+ c: "e",
76
+ type: "hello",
77
+ api_min_revision: input.apiMinRevision ?? API_MIN_REVISION,
78
+ api_revision: API_REVISION,
79
+ client: input.client
80
+ }));
81
+ return {
82
+ welcome: greeted.promise,
83
+ closed: ended.promise,
84
+ call(op, value) {
85
+ calls += 1;
86
+ const id = String(calls);
87
+ return new Promise((resolve, reject) => {
88
+ waiting.set(id, { resolve, reject });
89
+ socket.send(JSON.stringify({ c: "e", type: "call", id, op, input: value }));
90
+ });
91
+ },
92
+ onEvent(listener) {
93
+ eventListeners.add(listener);
94
+ return () => {
95
+ eventListeners.delete(listener);
96
+ };
97
+ },
98
+ onText(listener) {
99
+ textListeners.add(listener);
100
+ return () => {
101
+ textListeners.delete(listener);
102
+ };
103
+ },
104
+ close: () => socket.close(1000, "done")
105
+ };
106
+ }
107
+ function readJson(text) {
108
+ try {
109
+ const value = JSON.parse(text);
110
+ return isJson(value) ? value : undefined;
111
+ } catch {
112
+ return;
113
+ }
114
+ }
115
+
116
+ export { openHostSocket2 };
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  createTransport2
3
- } from "../chunks/client-5xm0heem.js";
4
- import"../chunks/client-053qg1fq.js";
3
+ } from "../chunks/client-d8smhemq.js";
4
+ import"../chunks/client-58wnq4mc.js";
5
+ import"../chunks/client-b8brz84x.js";
5
6
  import"../chunks/client-3sbyne3r.js";
6
- import"../chunks/client-kq4yq8n4.js";
7
+ import"../chunks/client-18p1wxbe.js";
7
8
  import"../chunks/client-rk08pxm6.js";
8
- import"../chunks/client-b8brz84x.js";
9
9
  export {
10
10
  createTransport2 as createTransport
11
11
  };
package/dist/src/codec.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  encodeInput2,
7
7
  encodeOutput2,
8
8
  decodeOutput2
9
- } from "../chunks/client-27229xc7.js";
9
+ } from "../chunks/client-ahvbzc2c.js";
10
10
  import"../chunks/client-eggvt9rc.js";
11
11
  export {
12
12
  answersBytes2 as answersBytes,
@@ -1,2 +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. */
1
+ /** Returns the operations table's SHA-256 digest, the first 16 hex digits: it hashes each row's name, kind, access, locality, MCP access and wire schemas in table order, so two builds whose tables differ in any operation or schema get different digests. */
2
2
  export declare function operationsDigest(): Promise<string>;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  operationsDigest2
3
- } from "../chunks/client-hrkzqw6w.js";
3
+ } from "../chunks/client-101w6sd1.js";
4
4
  export {
5
5
  operationsDigest2 as operationsDigest
6
6
  };
@@ -0,0 +1,16 @@
1
+ import type { ParentFilter, SessionId, SessionInfo, SessionsChange, SessionsRead } from "@nyte-ai/schema";
2
+ export interface DirectorySnapshot {
3
+ readonly ids: readonly SessionId[];
4
+ readonly rows: ReadonlyMap<SessionId, SessionInfo>;
5
+ }
6
+ export interface DirectoryWindow {
7
+ readonly parents?: ParentFilter;
8
+ readonly limit?: number;
9
+ }
10
+ export interface DirectoryStore {
11
+ readonly seq: number;
12
+ apply(change: SessionsChange): void;
13
+ resume(read: SessionsRead): void;
14
+ snapshot(): DirectorySnapshot;
15
+ }
16
+ export declare function openDirectoryStore(read: SessionsRead, window?: DirectoryWindow): DirectoryStore;
@@ -0,0 +1,6 @@
1
+ import {
2
+ openDirectoryStore2
3
+ } from "../chunks/client-ha6yznqf.js";
4
+ export {
5
+ openDirectoryStore2 as openDirectoryStore
6
+ };
@@ -3,7 +3,9 @@ export * from "./codec.ts";
3
3
  export * from "./declarations.ts";
4
4
  export * from "./stream-channel.ts";
5
5
  export * from "./wire.ts";
6
- export * from "./view-frames.ts";
6
+ export * from "./session-store.ts";
7
+ export * from "./directory-store.ts";
8
+ export * from "./socket-client.ts";
7
9
  export { parseJson } from "./json.ts";
8
10
  export { streamBuffer } from "./stream-buffer.ts";
9
11
  export { createStreamClient } from "./stream-client.ts";
package/dist/src/index.js CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  withInputHeader2,
18
18
  readInputHeader2,
19
19
  asSdkError2
20
- } from "../chunks/client-kq4yq8n4.js";
20
+ } from "../chunks/client-18p1wxbe.js";
21
21
  import {
22
22
  CHANNEL_PATH2,
23
23
  CANCEL_PATH2,
@@ -31,10 +31,10 @@ import {
31
31
  } from "../chunks/client-b8brz84x.js";
32
32
  import {
33
33
  createStreamClient2
34
- } from "../chunks/client-053qg1fq.js";
34
+ } from "../chunks/client-58wnq4mc.js";
35
35
  import {
36
36
  createTransport2
37
- } from "../chunks/client-5xm0heem.js";
37
+ } from "../chunks/client-d8smhemq.js";
38
38
  import"../chunks/client-eggvt9rc.js";
39
39
  import {
40
40
  namesOperation2,
@@ -44,21 +44,24 @@ import {
44
44
  encodeInput2,
45
45
  encodeOutput2,
46
46
  decodeOutput2
47
- } from "../chunks/client-27229xc7.js";
47
+ } from "../chunks/client-ahvbzc2c.js";
48
48
  import"../chunks/client-x7k53ygp.js";
49
+ import {
50
+ openSessionStore2
51
+ } from "../chunks/client-j4157t87.js";
52
+ import {
53
+ openDirectoryStore2
54
+ } from "../chunks/client-ha6yznqf.js";
55
+ import {
56
+ openHostSocket2
57
+ } from "../chunks/client-kyb2w6c2.js";
49
58
  import {
50
59
  mapped2,
51
60
  abortable2
52
61
  } from "../chunks/client-xscg1xbf.js";
53
- import {
54
- viewFrames2,
55
- applyViewFrame2,
56
- sessionsFrames2,
57
- sessionLists2
58
- } from "../chunks/client-f75bde33.js";
59
62
  import {
60
63
  operationsDigest2
61
- } from "../chunks/client-hrkzqw6w.js";
64
+ } from "../chunks/client-101w6sd1.js";
62
65
  export {
63
66
  CANCEL_PATH2 as CANCEL_PATH,
64
67
  CHANNEL_HEADER2 as CHANNEL_HEADER,
@@ -71,7 +74,6 @@ export {
71
74
  abortable2 as abortable,
72
75
  answersBytes2 as answersBytes,
73
76
  answersOnce2 as answersOnce,
74
- applyViewFrame2 as applyViewFrame,
75
77
  asSdkError2 as asSdkError,
76
78
  createStreamClient2 as createStreamClient,
77
79
  createTransport2 as createTransport,
@@ -85,6 +87,9 @@ export {
85
87
  mapped2 as mapped,
86
88
  namesOperation2 as namesOperation,
87
89
  octetStream2 as octetStream,
90
+ openDirectoryStore2 as openDirectoryStore,
91
+ openHostSocket2 as openHostSocket,
92
+ openSessionStore2 as openSessionStore,
88
93
  operationsDigest2 as operationsDigest,
89
94
  outputFrames2 as outputFrames,
90
95
  parseJson2 as parseJson,
@@ -92,11 +97,8 @@ export {
92
97
  parseSse2 as parseSse,
93
98
  readInputHeader2 as readInputHeader,
94
99
  readStreamFrame2 as readStreamFrame,
95
- sessionLists2 as sessionLists,
96
- sessionsFrames2 as sessionsFrames,
97
100
  sseFrames2 as sseFrames,
98
101
  statusCode2 as statusCode,
99
102
  streamBuffer2 as streamBuffer,
100
- viewFrames2 as viewFrames,
101
103
  withInputHeader2 as withInputHeader
102
104
  };
@@ -0,0 +1,25 @@
1
+ import type { BackgroundRow, CatalogRow, FileChange, HeadRow, HeadSettingsRow, HeadUsageRow, HeadWindow, Message, MessageId, PartView, Seq, SessionChange, TurnInfo } from "@nyte-ai/schema";
2
+ export interface SessionRows {
3
+ readonly messages: Map<string, Message>;
4
+ readonly turns: Map<string, TurnInfo>;
5
+ readonly parts: Map<string, PartView>;
6
+ readonly changes: Map<string, FileChange>;
7
+ readonly catalog: Map<string, CatalogRow>;
8
+ readonly heads: Map<string, HeadRow>;
9
+ readonly settings: Map<string, HeadSettingsRow>;
10
+ readonly usage: Map<string, HeadUsageRow>;
11
+ readonly background: Map<string, BackgroundRow>;
12
+ }
13
+ export interface SessionSnapshot {
14
+ readonly order: readonly MessageId[];
15
+ readonly leadingPrompt: MessageId | null;
16
+ readonly rows: SessionRows;
17
+ }
18
+ export interface SessionStore {
19
+ readonly seq: Seq;
20
+ readonly stale: boolean;
21
+ apply(change: SessionChange): void;
22
+ resume(window: HeadWindow): void;
23
+ snapshot(): SessionSnapshot;
24
+ }
25
+ export declare function openSessionStore(window: HeadWindow): SessionStore;
@@ -0,0 +1,6 @@
1
+ import {
2
+ openSessionStore2
3
+ } from "../chunks/client-j4157t87.js";
4
+ export {
5
+ openSessionStore2 as openSessionStore
6
+ };
@@ -0,0 +1,32 @@
1
+ import type { ClientInfo, EventFrame, Json, JsonSchema, TextFrame, WelcomeFrame } from "@nyte-ai/schema";
2
+ export interface SocketLike {
3
+ send(data: string): void;
4
+ close(code?: number, reason?: string): void;
5
+ addEventListener(type: "open", listener: () => void): void;
6
+ addEventListener(type: "message", listener: (event: {
7
+ readonly data: unknown;
8
+ }) => void): void;
9
+ addEventListener(type: "close", listener: (event: {
10
+ readonly code: number;
11
+ readonly reason: string;
12
+ }) => void): void;
13
+ addEventListener(type: "error", listener: () => void): void;
14
+ }
15
+ export type SocketClosed = {
16
+ readonly code: number;
17
+ readonly reason: string;
18
+ };
19
+ export type SocketEvent = EventFrame & JsonSchema;
20
+ export interface HostSocket {
21
+ readonly welcome: Promise<WelcomeFrame>;
22
+ readonly closed: Promise<SocketClosed>;
23
+ call(op: string, input: Json): Promise<Json>;
24
+ onEvent(listener: (event: SocketEvent) => void): () => void;
25
+ onText(listener: (frame: TextFrame) => void): () => void;
26
+ close(): void;
27
+ }
28
+ export declare function openHostSocket(input: {
29
+ readonly socket: SocketLike;
30
+ readonly client: ClientInfo;
31
+ readonly apiMinRevision?: number;
32
+ }): Promise<HostSocket>;
@@ -0,0 +1,8 @@
1
+ import {
2
+ openHostSocket2
3
+ } from "../chunks/client-kyb2w6c2.js";
4
+ import"../chunks/client-18p1wxbe.js";
5
+ import"../chunks/client-rk08pxm6.js";
6
+ export {
7
+ openHostSocket2 as openHostSocket
8
+ };
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  createStreamClient2
3
- } from "../chunks/client-053qg1fq.js";
3
+ } from "../chunks/client-58wnq4mc.js";
4
+ import"../chunks/client-b8brz84x.js";
4
5
  import"../chunks/client-3sbyne3r.js";
5
- import"../chunks/client-kq4yq8n4.js";
6
+ import"../chunks/client-18p1wxbe.js";
6
7
  import"../chunks/client-rk08pxm6.js";
7
- import"../chunks/client-b8brz84x.js";
8
8
  export {
9
9
  createStreamClient2 as createStreamClient
10
10
  };
@@ -9,6 +9,8 @@ export declare const errorStatus: {
9
9
  readonly stale: 409;
10
10
  readonly internal: 500;
11
11
  readonly unavailable: 503;
12
+ readonly not_supported: 501;
13
+ readonly timeout: 504;
12
14
  };
13
15
  /** Names the request header that carries an operation's JSON input when the body carries its bytes. */
14
16
  export declare const INPUT_HEADER = "X-Nyte-Input";
package/dist/src/wire.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  withInputHeader2,
15
15
  readInputHeader2,
16
16
  asSdkError2
17
- } from "../chunks/client-kq4yq8n4.js";
17
+ } from "../chunks/client-18p1wxbe.js";
18
18
  import"../chunks/client-rk08pxm6.js";
19
19
  export {
20
20
  HOST_HEADER2 as HOST_HEADER,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nyte-ai/protocol",
3
- "version": "0.0.25-nightly.20261102.45",
3
+ "version": "0.0.27",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -25,12 +25,13 @@
25
25
  "provenance": true
26
26
  },
27
27
  "dependencies": {
28
- "@nyte-ai/core": "0.0.25-nightly.20261102.45",
29
- "@nyte-ai/schema": "0.0.25-nightly.20261102.45",
28
+ "@nyte-ai/core": "0.0.27",
29
+ "@nyte-ai/schema": "0.0.27",
30
30
  "fflate": "^0.8.3",
31
- "typebox": "^1.4.2"
31
+ "typebox": "^1.4.3"
32
32
  },
33
33
  "devDependencies": {
34
+ "@nyte-ai/ai": "0.0.27",
34
35
  "@types/node": "^26.6.5",
35
36
  "vitest": "^5.0.5"
36
37
  },
@@ -41,6 +42,7 @@
41
42
  "clean": "rm -rf node_modules .turbo",
42
43
  "typecheck": "tsc --noEmit",
43
44
  "test": "vitest --run",
45
+ "bench:gate": "node bench/changes.bench.ts",
44
46
  "build:package": "bun ../../scripts/sdk-packages.mjs build protocol"
45
47
  }
46
48
  }
@@ -1,192 +0,0 @@
1
- import {
2
- mapped2
3
- } from "./client-xscg1xbf.js";
4
-
5
- // src/view-frames.ts
6
- import { Type } from "typebox";
7
- import { Compile } from "typebox/compile";
8
- import { SdkError } from "@nyte-ai/schema";
9
- var TAKE = -1;
10
- var NO_SESSIONS = { ids: [], list: [] };
11
- var streamed = Compile(Type.Object({ markdown: Type.String() }));
12
- function viewFrames2(views) {
13
- let previous = null;
14
- return mapped2(views, (view) => {
15
- const frame = previous === null ? { kind: "view", view } : viewDelta(previous, view);
16
- previous = view;
17
- return frame;
18
- });
19
- }
20
- function applyViewFrame2(view, frame) {
21
- if (frame.kind === "view")
22
- return frame.view;
23
- if (view === null)
24
- throw unfit("A view delta arrived before its view.");
25
- const messages = applySplice(view.messages, frame.messages);
26
- return {
27
- revision: frame.revision === undefined ? view.revision : frame.revision,
28
- seq: frame.seq,
29
- activation: frame.activation ?? view.activation,
30
- messages: frame.appends === undefined ? messages : applyAppends(messages, frame.appends),
31
- queue: applySplice(view.queue, frame.queue),
32
- leadingPrompt: frame.leadingPrompt === undefined ? view.leadingPrompt : frame.leadingPrompt,
33
- parts: applySplice(view.parts, frame.parts),
34
- turns: applySplice(view.turns, frame.turns),
35
- usage: frame.usage ?? view.usage,
36
- execution: frame.execution ?? view.execution,
37
- reportsHeld: frame.reportsHeld ?? view.reportsHeld,
38
- background: applySplice(view.background, frame.background),
39
- configuration: frame.configuration ?? view.configuration,
40
- context: frame.context ?? view.context,
41
- heads: applySplice(view.heads, frame.heads),
42
- changes: applySplice(view.changes, frame.changes),
43
- catalog: frame.catalog ?? view.catalog,
44
- seenThrough: frame.seenThrough === undefined ? view.seenThrough : frame.seenThrough
45
- };
46
- }
47
- function sessionsFrames2(lists) {
48
- let previous = null;
49
- return mapped2(lists, (list) => {
50
- const { runs, items } = splice(previous ?? [], list) ?? { runs: [0, list.length], items: [] };
51
- const kind = previous === null ? "list" : "delta";
52
- previous = list;
53
- return { kind, order: { runs, items: items.map((info) => info.id) }, items };
54
- });
55
- }
56
- function sessionLists2(frames) {
57
- return {
58
- [Symbol.asyncIterator]() {
59
- let shown = null;
60
- return mapped2(frames, (frame) => {
61
- const before = frame.kind === "list" ? NO_SESSIONS : shown;
62
- if (before === null)
63
- throw unfit("A sessions delta arrived before its list.");
64
- const taken = new Set(frame.order.items);
65
- const rows = new Map(frame.items.map((info) => [info.id, info]));
66
- const kept = new Map(before.list.map((info) => [info.id, info]));
67
- const ids = applySplice(before.ids, frame.order);
68
- const list = ids.flatMap((id) => (taken.has(id) ? rows.get(id) : kept.get(id)) ?? []);
69
- shown = { ids, list };
70
- return list;
71
- })[Symbol.asyncIterator]();
72
- }
73
- };
74
- }
75
- function viewDelta(previous, next) {
76
- const appends = [];
77
- const messages = splice(previous.messages, next.messages, (before, after, at) => {
78
- const grown = appendedText(before, after);
79
- if (grown !== null)
80
- appends.push({ at, ...grown });
81
- return grown !== null;
82
- });
83
- return {
84
- kind: "delta",
85
- seq: next.seq,
86
- revision: previous.revision === next.revision ? undefined : next.revision,
87
- activation: previous.activation === next.activation ? undefined : next.activation,
88
- messages,
89
- queue: splice(previous.queue, next.queue),
90
- appends: appends.length === 0 ? undefined : appends,
91
- leadingPrompt: previous.leadingPrompt === next.leadingPrompt ? undefined : next.leadingPrompt,
92
- parts: splice(previous.parts, next.parts),
93
- turns: splice(previous.turns, next.turns),
94
- usage: previous.usage === next.usage ? undefined : next.usage,
95
- execution: previous.execution === next.execution ? undefined : next.execution,
96
- reportsHeld: previous.reportsHeld === next.reportsHeld ? undefined : next.reportsHeld,
97
- background: splice(previous.background, next.background),
98
- configuration: previous.configuration === next.configuration ? undefined : next.configuration,
99
- context: previous.context === next.context ? undefined : next.context,
100
- heads: splice(previous.heads, next.heads),
101
- changes: splice(previous.changes, next.changes),
102
- catalog: previous.catalog === next.catalog ? undefined : next.catalog,
103
- seenThrough: previous.seenThrough === next.seenThrough ? undefined : next.seenThrough
104
- };
105
- }
106
- function splice(previous, next, grows) {
107
- if (previous === next)
108
- return;
109
- const runs = [];
110
- const items = [];
111
- let positions = null;
112
- let near = 0;
113
- next.forEach((item, at) => {
114
- const found = previous[near] === item ? near : (positions ??= indexed(previous)).get(item);
115
- if (found !== undefined) {
116
- extend(runs, found);
117
- near = found + 1;
118
- return;
119
- }
120
- const before = previous[near];
121
- if (near < previous.length && before !== undefined && grows?.(before, item, at) === true) {
122
- extend(runs, near);
123
- near += 1;
124
- return;
125
- }
126
- extend(runs, TAKE);
127
- items.push(item);
128
- });
129
- return runs.length === 2 && runs[0] === 0 && runs[1] === previous.length && items.length === 0 ? undefined : { runs, items };
130
- }
131
- function extend(runs, from) {
132
- const at = runs.length - 2;
133
- const last = runs[at];
134
- const count = runs[at + 1];
135
- if (last !== undefined && count !== undefined && (from === TAKE ? last === TAKE : last !== TAKE && last + count === from)) {
136
- runs[at + 1] = count + 1;
137
- return;
138
- }
139
- runs.push(from, 1);
140
- }
141
- function indexed(items) {
142
- const positions = new Map;
143
- items.forEach((item, at) => positions.set(item, at));
144
- return positions;
145
- }
146
- function applySplice(previous, change) {
147
- if (change === undefined)
148
- return previous;
149
- const next = [];
150
- let taken = 0;
151
- for (let at = 0;at < change.runs.length; at += 2) {
152
- const from = change.runs[at] ?? 0;
153
- const count = change.runs[at + 1] ?? 0;
154
- const source = from === TAKE ? change.items : previous;
155
- const start = from === TAKE ? taken : from;
156
- if (count < 0 || start < 0 || start + count > source.length)
157
- throw unfit("A view delta does not fit the view before it.");
158
- next.push(...source.slice(start, start + count));
159
- if (from === TAKE)
160
- taken += count;
161
- }
162
- return next;
163
- }
164
- function applyAppends(messages, appends) {
165
- const next = [...messages];
166
- for (const { at, append, version } of appends) {
167
- const message = next[at];
168
- const state = message?.kind === "part" ? message.state : null;
169
- if (message?.kind !== "part" || !streamed.Check(state))
170
- throw unfit("A view delta appends to a message that streams no text.");
171
- next[at] = { ...message, version, state: { ...state, markdown: state.markdown + append } };
172
- }
173
- return next;
174
- }
175
- function appendedText(before, after) {
176
- if (before.kind !== "part" || after.kind !== "part" || !streamed.Check(before.state) || !streamed.Check(after.state) || after.state.markdown.length <= before.state.markdown.length || !after.state.markdown.startsWith(before.state.markdown) || !sameBesides(before, after, ["version", "state"]) || !sameBesides(before.state, after.state, ["markdown"]))
177
- return null;
178
- return {
179
- append: after.state.markdown.slice(before.state.markdown.length),
180
- version: after.version
181
- };
182
- }
183
- function sameBesides(before, after, besides) {
184
- const kept = new Map(Object.entries(before));
185
- const entries = Object.entries(after);
186
- return entries.length === kept.size && entries.every(([key, value]) => besides.includes(key) || kept.has(key) && kept.get(key) === value);
187
- }
188
- function unfit(message) {
189
- return new SdkError("invalid", message);
190
- }
191
-
192
- export { viewFrames2, applyViewFrame2, sessionsFrames2, sessionLists2 };
@@ -1,9 +0,0 @@
1
- import type { SessionInfo, SessionsFrame, 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;
6
- /** Returns each list as the frame `sessions.watch` sends: the first a `list` spliced from none, each later one a `delta` from the list before it, its ids spliced by row identity and only the rows it takes. */
7
- export declare function sessionsFrames(lists: AsyncIterable<readonly SessionInfo[]>): AsyncIterable<SessionsFrame>;
8
- /** Returns the list each `sessions.watch` frame describes: a `list` frame's ids, or a delta's spliced into the ids before it, each with the row the frame carries for it or else the row it had; a delta before any list, or one that does not fit, throws `SdkError("invalid")`. A row the frame could not read is left out. */
9
- export declare function sessionLists(frames: AsyncIterable<SessionsFrame>): AsyncIterable<readonly SessionInfo[]>;
@@ -1,13 +0,0 @@
1
- import {
2
- viewFrames2,
3
- applyViewFrame2,
4
- sessionsFrames2,
5
- sessionLists2
6
- } from "../chunks/client-f75bde33.js";
7
- import"../chunks/client-xscg1xbf.js";
8
- export {
9
- applyViewFrame2 as applyViewFrame,
10
- sessionLists2 as sessionLists,
11
- sessionsFrames2 as sessionsFrames,
12
- viewFrames2 as viewFrames
13
- };