@nyte-ai/protocol 0.0.29-nightly.20261119.112 → 0.3.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/README.md +1 -1
- package/THIRD-PARTY-NOTICES.md +61 -3
- package/dist/chunks/{client-ha6yznqf.js → index-0q4bw06r.js} +12 -5
- package/dist/chunks/{client-wn6q96dq.js → index-1gda64ex.js} +27 -9
- package/dist/chunks/{client-4fq758q8.js → index-362qtcjf.js} +43 -20
- package/dist/chunks/index-7v2tp03w.js +224 -0
- package/dist/chunks/{client-wqkvb55q.js → index-gw4eefqr.js} +72 -37
- package/dist/chunks/{client-3sbyne3r.js → index-h14s9gt3.js} +1 -1
- package/dist/chunks/{client-eggvt9rc.js → index-ht11mtxs.js} +1 -1
- package/dist/chunks/{client-sw8vswjs.js → index-k7th682a.js} +53 -15
- package/dist/chunks/{client-xscg1xbf.js → index-kr00kac7.js} +1 -1
- package/dist/chunks/{client-j4157t87.js → index-q0t950kb.js} +10 -4
- package/dist/chunks/{client-101w6sd1.js → index-ra9p4jfx.js} +1 -1
- package/dist/chunks/{client-b8brz84x.js → index-rzv8zrzf.js} +3 -1
- package/dist/chunks/index-t6hyhcet.js +36 -0
- package/dist/chunks/{client-kqr7p5nh.js → index-vbt1c8yx.js} +3 -2
- package/dist/src/client/directory-store.d.ts +24 -0
- package/dist/src/{directory-store.js → client/directory-store.js} +1 -1
- package/dist/src/{session-store.d.ts → client/session-store.d.ts} +3 -1
- package/dist/src/{session-store.js → client/session-store.js} +1 -1
- package/dist/src/{socket-client.d.ts → client/socket-client.d.ts} +5 -0
- package/dist/src/client/socket-client.js +9 -0
- package/dist/src/client/stream-client.d.ts +11 -0
- package/dist/src/client/stream-client.js +14 -0
- package/dist/src/{client.d.ts → client/transport.d.ts} +2 -3
- package/dist/src/client/transport.js +11 -0
- package/dist/src/index.d.ts +13 -13
- package/dist/src/index.js +20 -16
- package/dist/src/{codec.js → operations/codec.js} +3 -2
- package/dist/src/operations/declarations.js +1 -0
- package/dist/src/{digest.js → operations/digest.js} +1 -1
- package/dist/src/{raw-parts.js → operations/raw-parts.js} +1 -1
- package/dist/src/wire/frame-checks.d.ts +247 -0
- package/dist/src/{frame-checks.js → wire/frame-checks.js} +1 -1
- package/dist/src/wire/json.d.ts +6 -0
- package/dist/src/wire/json.js +10 -0
- package/dist/src/{stream-buffer.js → wire/stream-buffer.js} +1 -1
- package/dist/src/{stream-channel.js → wire/stream-channel.js} +1 -1
- package/dist/src/{streams.js → wire/streams.js} +1 -1
- package/dist/src/{wire.d.ts → wire/wire.d.ts} +2 -1
- package/dist/src/{wire.js → wire/wire.js} +2 -2
- package/package.json +9 -9
- package/dist/chunks/client-6vn29412.js +0 -138
- package/dist/chunks/client-rk08pxm6.js +0 -12
- package/dist/src/client.js +0 -11
- package/dist/src/declarations.js +0 -1
- package/dist/src/directory-store.d.ts +0 -16
- package/dist/src/frame-checks.d.ts +0 -246
- package/dist/src/json.d.ts +0 -2
- package/dist/src/json.js +0 -6
- package/dist/src/socket-client.js +0 -9
- package/dist/src/stream-client.d.ts +0 -7
- package/dist/src/stream-client.js +0 -10
- /package/dist/chunks/{client-x7k53ygp.js → index-r3zsnw1t.js} +0 -0
- /package/dist/src/{codec.d.ts → operations/codec.d.ts} +0 -0
- /package/dist/src/{declarations.d.ts → operations/declarations.d.ts} +0 -0
- /package/dist/src/{digest.d.ts → operations/digest.d.ts} +0 -0
- /package/dist/src/{raw-parts.d.ts → operations/raw-parts.d.ts} +0 -0
- /package/dist/src/{stream-buffer.d.ts → wire/stream-buffer.d.ts} +0 -0
- /package/dist/src/{stream-channel.d.ts → wire/stream-channel.d.ts} +0 -0
- /package/dist/src/{streams.d.ts → wire/streams.d.ts} +0 -0
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
unchecked2
|
|
3
|
+
} from "./index-t6hyhcet.js";
|
|
1
4
|
import {
|
|
2
5
|
rawPart2
|
|
3
|
-
} from "./
|
|
6
|
+
} from "./index-ht11mtxs.js";
|
|
4
7
|
|
|
5
|
-
// src/codec.ts
|
|
8
|
+
// src/operations/codec.ts
|
|
6
9
|
import { Compile } from "typebox/compile";
|
|
7
10
|
import { Guard } from "typebox/guard";
|
|
8
11
|
import { OPERATIONS, SdkError } from "@nyte-ai/schema";
|
|
@@ -201,32 +204,76 @@ function encode(plan, value) {
|
|
|
201
204
|
const member = select(plan, json);
|
|
202
205
|
return member === null ? json : encode(member, json);
|
|
203
206
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
return items === null ? toJson(value) :
|
|
207
|
-
}
|
|
207
|
+
const items = plan.items;
|
|
208
|
+
if (value instanceof Set || Guard.IsArray(value))
|
|
209
|
+
return items === null ? toJson(value) : encodeItems(value instanceof Set ? [...value] : value, items.plan);
|
|
208
210
|
if (typeof value !== "object" || value === null)
|
|
209
211
|
return toJson(value);
|
|
210
|
-
|
|
211
|
-
if (properties === null && rest === null)
|
|
212
|
+
if (plan.properties === null && plan.rest === null)
|
|
212
213
|
return toJson(value);
|
|
213
|
-
|
|
214
|
-
|
|
214
|
+
return encodeFields(value, plan.properties, plan.rest, plan.nulled);
|
|
215
|
+
}
|
|
216
|
+
function encodeItems(value, plan) {
|
|
217
|
+
let copy = null;
|
|
218
|
+
for (let index = 0;index < value.length; index += 1) {
|
|
219
|
+
const item = value[index];
|
|
220
|
+
const json = encode(plan, item) ?? null;
|
|
221
|
+
if (copy === null) {
|
|
222
|
+
if (json === item)
|
|
223
|
+
continue;
|
|
224
|
+
copy = value.slice(0, index).map(walked);
|
|
225
|
+
}
|
|
226
|
+
copy.push(json);
|
|
227
|
+
}
|
|
228
|
+
return copy ?? walked(value);
|
|
229
|
+
}
|
|
230
|
+
function encodeFields(value, properties, rest, nulled) {
|
|
231
|
+
if (value instanceof Map) {
|
|
232
|
+
const record = {};
|
|
233
|
+
for (const entry of value) {
|
|
234
|
+
const key = String(entry[0]);
|
|
235
|
+
const target = properties?.get(key) ?? rest;
|
|
236
|
+
const json = target === null ? undefined : encode(target, entry[1]);
|
|
237
|
+
if (json !== undefined)
|
|
238
|
+
put(record, key, json);
|
|
239
|
+
}
|
|
240
|
+
for (const key of nulled)
|
|
241
|
+
if (!Object.hasOwn(record, key))
|
|
242
|
+
put(record, key, null);
|
|
243
|
+
return record;
|
|
244
|
+
}
|
|
245
|
+
if (!Guard.IsObjectNotArray(value))
|
|
246
|
+
return {};
|
|
247
|
+
const keys = Object.keys(value);
|
|
248
|
+
let copy = Object.getPrototypeOf(value) === Object.prototype ? null : {};
|
|
249
|
+
for (let index = 0;index < keys.length; index += 1) {
|
|
250
|
+
const key = keys[index] ?? "";
|
|
251
|
+
const item = value[key];
|
|
215
252
|
const target = properties?.get(key) ?? rest;
|
|
216
253
|
const json = target === null ? undefined : encode(target, item);
|
|
254
|
+
if (copy === null) {
|
|
255
|
+
if (json !== undefined && json === item)
|
|
256
|
+
continue;
|
|
257
|
+
copy = copyFields(value, keys, index);
|
|
258
|
+
}
|
|
217
259
|
if (json !== undefined)
|
|
218
|
-
put(
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
260
|
+
put(copy, key, json);
|
|
261
|
+
}
|
|
262
|
+
for (const key of nulled)
|
|
263
|
+
if (!Object.hasOwn(copy ?? value, key)) {
|
|
264
|
+
copy ??= copyFields(value, keys, keys.length);
|
|
265
|
+
put(copy, key, null);
|
|
266
|
+
}
|
|
267
|
+
return copy ?? walked(value);
|
|
268
|
+
}
|
|
269
|
+
function copyFields(value, keys, end) {
|
|
270
|
+
const copy = {};
|
|
271
|
+
for (const key of keys.slice(0, end))
|
|
272
|
+
put(copy, key, walked(value[key]));
|
|
273
|
+
return copy;
|
|
274
|
+
}
|
|
275
|
+
function walked(value) {
|
|
276
|
+
return unchecked2.Check(value) ? value : null;
|
|
230
277
|
}
|
|
231
278
|
function known(plan, value) {
|
|
232
279
|
if (plan.form === "inert")
|
|
@@ -353,24 +400,12 @@ function toJson(value) {
|
|
|
353
400
|
if (value instanceof Uint8Array)
|
|
354
401
|
return btoa(Array.from(value, (byte) => String.fromCharCode(byte)).join(""));
|
|
355
402
|
if (value instanceof Set)
|
|
356
|
-
return
|
|
403
|
+
return encodeItems([...value], INERT);
|
|
357
404
|
if (Guard.IsArray(value))
|
|
358
|
-
return value
|
|
405
|
+
return encodeItems(value, INERT);
|
|
359
406
|
if (typeof value !== "object")
|
|
360
407
|
return;
|
|
361
|
-
|
|
362
|
-
const keep = (key, item) => {
|
|
363
|
-
const json = toJson(item);
|
|
364
|
-
if (json !== undefined)
|
|
365
|
-
put(record, key, json);
|
|
366
|
-
};
|
|
367
|
-
if (value instanceof Map)
|
|
368
|
-
for (const [key, item] of value)
|
|
369
|
-
keep(String(key), item);
|
|
370
|
-
else if (Guard.IsObjectNotArray(value))
|
|
371
|
-
for (const key of Object.keys(value))
|
|
372
|
-
keep(key, value[key]);
|
|
373
|
-
return record;
|
|
408
|
+
return encodeFields(value, null, INERT, []);
|
|
374
409
|
}
|
|
375
410
|
function put(record, key, json) {
|
|
376
411
|
if (key === "__proto__")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
parseJson2
|
|
3
|
-
} from "./
|
|
3
|
+
} from "./index-t6hyhcet.js";
|
|
4
4
|
import {
|
|
5
5
|
HOST_HEADER2,
|
|
6
6
|
OPERATIONS_HEADER2,
|
|
@@ -8,21 +8,23 @@ import {
|
|
|
8
8
|
parseSse2,
|
|
9
9
|
parseOutputFrames2,
|
|
10
10
|
withInputHeader2
|
|
11
|
-
} from "./
|
|
11
|
+
} from "./index-362qtcjf.js";
|
|
12
12
|
import {
|
|
13
|
+
hostAnswer2,
|
|
13
14
|
createStreamClient2
|
|
14
|
-
} from "./
|
|
15
|
+
} from "./index-1gda64ex.js";
|
|
15
16
|
|
|
16
|
-
// src/client.ts
|
|
17
|
+
// src/client/transport.ts
|
|
17
18
|
import { asId, OPERATIONS, SdkError } from "@nyte-ai/schema";
|
|
18
19
|
var DONE = { done: true, value: undefined };
|
|
20
|
+
var CALL_MS = 30000;
|
|
19
21
|
function createTransport2(options) {
|
|
20
22
|
const base = options.url.replace(/\/+$/, "");
|
|
21
23
|
const send = options.fetch ?? fetch;
|
|
22
24
|
let credential = null;
|
|
23
25
|
let host = null;
|
|
24
26
|
let operations = null;
|
|
25
|
-
const post = async (name, init) => {
|
|
27
|
+
const post = async (name, init, operation = false) => {
|
|
26
28
|
const headers = { ...await options.headers(), ...init.headers };
|
|
27
29
|
let response;
|
|
28
30
|
try {
|
|
@@ -45,7 +47,8 @@ function createTransport2(options) {
|
|
|
45
47
|
credential = response.headers.get("X-Nyte-Credential") ?? credential;
|
|
46
48
|
if (response.ok)
|
|
47
49
|
return response;
|
|
48
|
-
|
|
50
|
+
const error = decodeError2(jsonOrText(await response.text()), response.status);
|
|
51
|
+
throw operation && answered !== null ? hostAnswer2(error) : error;
|
|
49
52
|
};
|
|
50
53
|
const json = (input, headers) => ({
|
|
51
54
|
body: JSON.stringify(input),
|
|
@@ -63,21 +66,24 @@ function createTransport2(options) {
|
|
|
63
66
|
controller.abort();
|
|
64
67
|
}
|
|
65
68
|
}
|
|
66
|
-
const
|
|
67
|
-
|
|
69
|
+
const call = async (signal) => {
|
|
70
|
+
const response = await post(name, { ...json(input), signal }, true);
|
|
71
|
+
return parseJson2(await response.text());
|
|
72
|
+
};
|
|
73
|
+
return OPERATIONS[name].kind === "command" ? call(request?.signal) : answered(name, request?.signal, call);
|
|
68
74
|
},
|
|
69
75
|
frames(name, input) {
|
|
70
76
|
return cancellable(async function* (signal) {
|
|
71
|
-
yield*
|
|
77
|
+
yield* answering(await stream(name, input, signal), parseSse2);
|
|
72
78
|
});
|
|
73
79
|
},
|
|
74
80
|
output(input) {
|
|
75
81
|
return cancellable(async function* (signal) {
|
|
76
|
-
yield*
|
|
82
|
+
yield* answering(await stream("job.output", input, signal), parseOutputFrames2);
|
|
77
83
|
});
|
|
78
84
|
},
|
|
79
85
|
async bytes(name, input, request) {
|
|
80
|
-
const response = await post(name, { ...json(input), signal: request?.signal });
|
|
86
|
+
const response = await post(name, { ...json(input), signal: request?.signal }, true);
|
|
81
87
|
const length = response.headers.get("Content-Length");
|
|
82
88
|
const version = response.headers.get("X-Nyte-Version");
|
|
83
89
|
const body = response.body;
|
|
@@ -104,10 +110,7 @@ function createTransport2(options) {
|
|
|
104
110
|
};
|
|
105
111
|
},
|
|
106
112
|
async upload(name, input, body, request) {
|
|
107
|
-
const response = await post(name, {
|
|
108
|
-
...withInputHeader2(input, body),
|
|
109
|
-
signal: request?.signal
|
|
110
|
-
});
|
|
113
|
+
const response = await post(name, { ...withInputHeader2(input, body), signal: request?.signal }, true);
|
|
111
114
|
return parseJson2(await response.text());
|
|
112
115
|
},
|
|
113
116
|
credential: () => credential,
|
|
@@ -115,6 +118,19 @@ function createTransport2(options) {
|
|
|
115
118
|
operations: () => operations
|
|
116
119
|
};
|
|
117
120
|
}
|
|
121
|
+
async function answered(name, outer, run) {
|
|
122
|
+
const deadline = new AbortController;
|
|
123
|
+
const timer = setTimeout(() => deadline.abort(), CALL_MS);
|
|
124
|
+
try {
|
|
125
|
+
return await run(outer === undefined ? deadline.signal : AbortSignal.any([outer, deadline.signal]));
|
|
126
|
+
} catch (error) {
|
|
127
|
+
if (!deadline.signal.aborted || outer?.aborted === true)
|
|
128
|
+
throw error;
|
|
129
|
+
throw new SdkError("unavailable", `The host didn't answer ${name} within ${CALL_MS / 1000} s.`);
|
|
130
|
+
} finally {
|
|
131
|
+
clearTimeout(timer);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
118
134
|
function cancellable(open) {
|
|
119
135
|
return {
|
|
120
136
|
[Symbol.asyncIterator]() {
|
|
@@ -170,6 +186,28 @@ function cancellable(open) {
|
|
|
170
186
|
}
|
|
171
187
|
};
|
|
172
188
|
}
|
|
189
|
+
async function* answering(body, parse) {
|
|
190
|
+
const reader = body.getReader();
|
|
191
|
+
let broken = false;
|
|
192
|
+
const read = new ReadableStream({
|
|
193
|
+
async pull(controller) {
|
|
194
|
+
const next = await reader.read().catch((cause) => {
|
|
195
|
+
broken = true;
|
|
196
|
+
throw cause;
|
|
197
|
+
});
|
|
198
|
+
if (next.done)
|
|
199
|
+
controller.close();
|
|
200
|
+
else
|
|
201
|
+
controller.enqueue(next.value);
|
|
202
|
+
},
|
|
203
|
+
cancel: (reason) => reader.cancel(reason)
|
|
204
|
+
});
|
|
205
|
+
try {
|
|
206
|
+
yield* parse(read);
|
|
207
|
+
} catch (error) {
|
|
208
|
+
throw error instanceof SdkError && !broken ? hostAnswer2(error) : error;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
173
211
|
function crossesNetwork(url) {
|
|
174
212
|
const { hostname } = new URL(url);
|
|
175
213
|
return hostname !== "localhost" && hostname !== "[::1]" && !hostname.startsWith("127.");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// src/session-store.ts
|
|
2
|
-
import { backgroundRowKey, catalogRowKey } from "@nyte-ai/schema";
|
|
1
|
+
// src/client/session-store.ts
|
|
2
|
+
import { backgroundRowKey, catalogRowKey, digestIds } from "@nyte-ai/schema";
|
|
3
3
|
function openSessionStore2(window) {
|
|
4
4
|
const head = window.head;
|
|
5
5
|
let rows = emptyRows();
|
|
@@ -7,6 +7,7 @@ function openSessionStore2(window) {
|
|
|
7
7
|
let order = window.order;
|
|
8
8
|
let leadingPrompt = window.leadingPrompt;
|
|
9
9
|
let stale = false;
|
|
10
|
+
let described = [];
|
|
10
11
|
write(rows, window.tables);
|
|
11
12
|
const move = (path) => {
|
|
12
13
|
if (path.after === null) {
|
|
@@ -40,11 +41,16 @@ function openSessionStore2(window) {
|
|
|
40
41
|
if (path.head === head && !stale)
|
|
41
42
|
move(path);
|
|
42
43
|
},
|
|
44
|
+
describe() {
|
|
45
|
+
described = order;
|
|
46
|
+
const from = order[0] ?? null;
|
|
47
|
+
return from === null ? { seq, from } : { seq, from, held: { count: order.length, digest: digestIds(order) } };
|
|
48
|
+
},
|
|
43
49
|
resume(next) {
|
|
44
50
|
seq = next.seq;
|
|
45
|
-
order = next.order;
|
|
51
|
+
order = next.kept === undefined ? next.order : [...described.slice(described.length - next.kept), ...next.order];
|
|
46
52
|
leadingPrompt = next.leadingPrompt;
|
|
47
|
-
stale =
|
|
53
|
+
stale = next.kept !== undefined && next.kept > described.length;
|
|
48
54
|
if (next.complete)
|
|
49
55
|
rows = emptyRows();
|
|
50
56
|
for (const entry of rows.background)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// src/stream-buffer.ts
|
|
1
|
+
// src/wire/stream-buffer.ts
|
|
2
|
+
import { dev } from "@nyte-ai/core/client";
|
|
2
3
|
var MAX_BYTES = 8 * 1024 * 1024;
|
|
3
4
|
var MAX_CHUNKS = 4096;
|
|
4
5
|
function streamBuffer2(cancel) {
|
|
@@ -80,6 +81,7 @@ function streamBuffer2(cancel) {
|
|
|
80
81
|
return;
|
|
81
82
|
if (push(part))
|
|
82
83
|
break;
|
|
84
|
+
dev("stream", "write waits", { buffered: bytes, waiting: part.byteLength });
|
|
83
85
|
await new Promise((resolve) => {
|
|
84
86
|
const ready = () => {
|
|
85
87
|
writers.delete(ready);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/wire/json.ts
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
import { compile, isJsonObject, SdkError } from "@nyte-ai/schema";
|
|
4
|
+
var unchecked2 = compile(Type.Unsafe({}));
|
|
5
|
+
function parseJson2(text) {
|
|
6
|
+
const value = readJson2(text);
|
|
7
|
+
if (value === undefined)
|
|
8
|
+
throw new SdkError("invalid", "The body is not JSON.");
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
function readJson2(text) {
|
|
12
|
+
try {
|
|
13
|
+
const value = JSON.parse(text);
|
|
14
|
+
return unchecked2.Check(value) && finite(value) ? value : undefined;
|
|
15
|
+
} catch {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function finite(value) {
|
|
20
|
+
if (typeof value === "number")
|
|
21
|
+
return Number.isFinite(value);
|
|
22
|
+
if (typeof value !== "object" || value === null)
|
|
23
|
+
return true;
|
|
24
|
+
if (isJsonObject(value)) {
|
|
25
|
+
for (const key in value)
|
|
26
|
+
if (!finite(value[key] ?? null))
|
|
27
|
+
return false;
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
for (const item of value)
|
|
31
|
+
if (!finite(item))
|
|
32
|
+
return false;
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { unchecked2, parseJson2, readJson2 };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/frame-checks.ts
|
|
1
|
+
// src/wire/frame-checks.ts
|
|
2
2
|
import {
|
|
3
3
|
compile,
|
|
4
4
|
ErrorFrameType,
|
|
@@ -9,11 +9,12 @@ import {
|
|
|
9
9
|
WelcomeFrameType,
|
|
10
10
|
withJson
|
|
11
11
|
} from "@nyte-ai/schema";
|
|
12
|
+
import { Type } from "typebox";
|
|
12
13
|
function checkOnly(validator) {
|
|
13
14
|
return validator;
|
|
14
15
|
}
|
|
15
16
|
var welcomes2 = checkOnly(compile(withJson(WelcomeFrameType)));
|
|
16
|
-
var results2 = checkOnly(compile(
|
|
17
|
+
var results2 = checkOnly(compile(Type.Object({ ...ResultFrameType.properties, output: Type.Unsafe({}) })));
|
|
17
18
|
var errors2 = checkOnly(compile(withJson(ErrorFrameType)));
|
|
18
19
|
var events2 = checkOnly(compile(withJson(EventFrameType)));
|
|
19
20
|
var texts2 = checkOnly(compile(withJson(TextFrameType)));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Held, 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
|
+
/** What a `sessions.read` selected, which the store applies to every row the host pushes after it, so a row that leaves the window, like an unpinned chat in a pinned window, drops out. */
|
|
7
|
+
export interface DirectoryWindow {
|
|
8
|
+
readonly parents?: ParentFilter;
|
|
9
|
+
readonly pinned?: boolean;
|
|
10
|
+
readonly query?: string;
|
|
11
|
+
readonly limit?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface DirectoryStore {
|
|
14
|
+
readonly seq: number;
|
|
15
|
+
apply(change: SessionsChange): void;
|
|
16
|
+
/** The `resume` a `sessions.read` sends: the seq, and `held`, which describes the set of ids listed. A `kept` in the next `resume` keeps the ids described here. */
|
|
17
|
+
describe(): {
|
|
18
|
+
readonly seq: number;
|
|
19
|
+
readonly held: Held;
|
|
20
|
+
};
|
|
21
|
+
resume(read: SessionsRead): void;
|
|
22
|
+
snapshot(): DirectorySnapshot;
|
|
23
|
+
}
|
|
24
|
+
export declare function openDirectoryStore(read: SessionsRead, window?: DirectoryWindow): DirectoryStore;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BackgroundRow, CatalogRow, FileChange, HeadRow, HeadSettingsRow, HeadUsageRow, HeadWindow, Message, MessageId, PartView, Seq, SessionChange, TurnInfo } from "@nyte-ai/schema";
|
|
1
|
+
import type { BackgroundRow, CatalogRow, FileChange, HeadRow, HeadSettingsRow, HeadUsageRow, HeadWindow, Message, MessageId, PartView, Resume, Seq, SessionChange, TurnInfo } from "@nyte-ai/schema";
|
|
2
2
|
export interface SessionRows {
|
|
3
3
|
readonly messages: Map<string, Message>;
|
|
4
4
|
readonly turns: Map<string, TurnInfo>;
|
|
@@ -19,6 +19,8 @@ export interface SessionStore {
|
|
|
19
19
|
readonly seq: Seq;
|
|
20
20
|
readonly stale: boolean;
|
|
21
21
|
apply(change: SessionChange): void;
|
|
22
|
+
/** The `resume` a `head.read` sends: the seq, the first id of the order, and `held`, which describes the order. The next `resume` applies its `kept` to the order described here. */
|
|
23
|
+
describe(): Resume;
|
|
22
24
|
resume(window: HeadWindow): void;
|
|
23
25
|
snapshot(): SessionSnapshot;
|
|
24
26
|
}
|
|
@@ -17,12 +17,17 @@ export type SocketClosed = {
|
|
|
17
17
|
readonly reason: string;
|
|
18
18
|
};
|
|
19
19
|
export type SocketEvent = EventFrame & JsonSchema;
|
|
20
|
+
/**
|
|
21
|
+
* One client's socket to its host. It counts itself lost when the host stops answering: no WebSocket API shows the host's pings to the page, so it asks the host something after a quiet spell, and closes itself when nothing comes back. Losing it fails every pending call with the `unavailable` a dropped socket fails them with, and settles `closed` at once, without waiting for a close handshake a dead link never finishes.
|
|
22
|
+
*/
|
|
20
23
|
export interface HostSocket {
|
|
21
24
|
readonly welcome: Promise<WelcomeFrame>;
|
|
22
25
|
readonly closed: Promise<SocketClosed>;
|
|
23
26
|
call(op: string, input: Json): Promise<Json>;
|
|
24
27
|
onEvent(listener: (event: SocketEvent) => void): () => void;
|
|
25
28
|
onText(listener: (frame: TextFrame) => void): () => void;
|
|
29
|
+
/** Asks the host something now and resolves when anything arrives; rejects, and loses the socket, when nothing does within `ASKED_PROBE_MS`. */
|
|
30
|
+
probe(): Promise<void>;
|
|
26
31
|
close(): void;
|
|
27
32
|
}
|
|
28
33
|
export declare function openHostSocket(input: {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SdkError } from "@nyte-ai/schema";
|
|
2
|
+
import type { Json } from "@nyte-ai/schema";
|
|
3
|
+
type Post = (path: string, init: RequestInit & {
|
|
4
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
5
|
+
}) => Promise<Response>;
|
|
6
|
+
export declare function hostAnswer(error: SdkError): SdkError;
|
|
7
|
+
/** Returns whether an error is a failure of the link to the host, so the request may be retried once the host is back: an `unavailable` the transport raised (a failed `fetch`, a stream channel that dropped, was refused or was closed by the host), an error answer without `X-Nyte-Host` (a relay or proxy answering for an unreachable host), or a host answer with `retry` set, asking the client to come back later (a listener that is closed, a host that disconnected its clients or is still opening). Any other `unavailable` the host answered an operation with is final, whatever its message says. */
|
|
8
|
+
export declare function linkLost(error: unknown): error is SdkError;
|
|
9
|
+
/** Multiplex streams over one channel opened through `post`, asking for `deflated` frames when `deflate`; the channel closes when its last stream is released. */
|
|
10
|
+
export declare function createStreamClient(post: Post, deflate: boolean): (name: string, input: Json, signal: AbortSignal) => Promise<ReadableStream<Uint8Array>>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hostAnswer2,
|
|
3
|
+
linkLost2,
|
|
4
|
+
createStreamClient2
|
|
5
|
+
} from "../../chunks/index-1gda64ex.js";
|
|
6
|
+
import"../../chunks/index-rzv8zrzf.js";
|
|
7
|
+
import"../../chunks/index-h14s9gt3.js";
|
|
8
|
+
import"../../chunks/index-362qtcjf.js";
|
|
9
|
+
import"../../chunks/index-t6hyhcet.js";
|
|
10
|
+
export {
|
|
11
|
+
createStreamClient2 as createStreamClient,
|
|
12
|
+
hostAnswer2 as hostAnswer,
|
|
13
|
+
linkLost2 as linkLost
|
|
14
|
+
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { ByteReader, FileVersion, HostId, Json, OutputFrame, RequestOptions } from "@nyte-ai/schema";
|
|
2
|
-
import type { OperationName } from "
|
|
3
|
-
/** Describes where a transport sends requests, the headers each carries (credentials, read again per request), and the `fetch` it uses. */
|
|
2
|
+
import type { OperationName } from "../operations/declarations.ts";
|
|
4
3
|
export type TransportOptions = {
|
|
5
4
|
readonly url: string;
|
|
6
5
|
headers(): Promise<Readonly<Record<string, string>>>;
|
|
@@ -10,7 +9,7 @@ export type TransportOptions = {
|
|
|
10
9
|
export type ResponseReader = ByteReader & {
|
|
11
10
|
readonly version?: FileVersion;
|
|
12
11
|
};
|
|
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. */
|
|
12
|
+
/** 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, and `linkLost` tells an operation's answer from a failure of the link. */
|
|
14
13
|
export type Transport = {
|
|
15
14
|
invoke(name: OperationName, input: Json, options?: RequestOptions): Promise<Json>;
|
|
16
15
|
frames(name: OperationName, input: Json): AsyncIterable<Json>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createTransport2
|
|
3
|
+
} from "../../chunks/index-k7th682a.js";
|
|
4
|
+
import"../../chunks/index-1gda64ex.js";
|
|
5
|
+
import"../../chunks/index-rzv8zrzf.js";
|
|
6
|
+
import"../../chunks/index-h14s9gt3.js";
|
|
7
|
+
import"../../chunks/index-362qtcjf.js";
|
|
8
|
+
import"../../chunks/index-t6hyhcet.js";
|
|
9
|
+
export {
|
|
10
|
+
createTransport2 as createTransport
|
|
11
|
+
};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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 "./session-store.ts";
|
|
7
|
-
export * from "./directory-store.ts";
|
|
8
|
-
export * from "./socket-client.ts";
|
|
9
|
-
export { parseJson } from "./json.ts";
|
|
10
|
-
export { streamBuffer } from "./stream-buffer.ts";
|
|
11
|
-
export { createStreamClient } from "./stream-client.ts";
|
|
12
|
-
export { abortable, mapped } from "./streams.ts";
|
|
13
|
-
export { operationsDigest } from "./digest.ts";
|
|
1
|
+
export * from "./client/transport.ts";
|
|
2
|
+
export * from "./operations/codec.ts";
|
|
3
|
+
export * from "./operations/declarations.ts";
|
|
4
|
+
export * from "./wire/stream-channel.ts";
|
|
5
|
+
export * from "./wire/wire.ts";
|
|
6
|
+
export * from "./client/session-store.ts";
|
|
7
|
+
export * from "./client/directory-store.ts";
|
|
8
|
+
export * from "./client/socket-client.ts";
|
|
9
|
+
export { parseJson, readJson } from "./wire/json.ts";
|
|
10
|
+
export { streamBuffer } from "./wire/stream-buffer.ts";
|
|
11
|
+
export { createStreamClient, linkLost } from "./client/stream-client.ts";
|
|
12
|
+
export { abortable, mapped } from "./wire/streams.ts";
|
|
13
|
+
export { operationsDigest } from "./operations/digest.ts";
|