@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.
- package/LICENSE +21 -0
- package/README.md +22 -2
- package/THIRD-PARTY-NOTICES.md +866 -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-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-sffw3se8.js +157 -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,387 @@
|
|
|
1
|
+
import {
|
|
2
|
+
rawPart2
|
|
3
|
+
} from "./client-eggvt9rc.js";
|
|
4
|
+
|
|
5
|
+
// src/codec.ts
|
|
6
|
+
import { Compile } from "typebox/compile";
|
|
7
|
+
import { Guard } from "typebox/guard";
|
|
8
|
+
import { OPERATIONS, SdkError } from "@nyte-ai/schema";
|
|
9
|
+
var INERT = { form: "inert" };
|
|
10
|
+
var PRIMITIVE_TYPES = new Set(["string", "number", "integer", "boolean", "null"]);
|
|
11
|
+
var VIEW_DEPTH = 2;
|
|
12
|
+
var rows = OPERATIONS;
|
|
13
|
+
var plans = new WeakMap;
|
|
14
|
+
var BYTE_ROWS = {
|
|
15
|
+
"connection.blob": true,
|
|
16
|
+
"files.bytes": true,
|
|
17
|
+
"page.capture": true
|
|
18
|
+
};
|
|
19
|
+
function namesOperation2(name) {
|
|
20
|
+
return Object.hasOwn(OPERATIONS, name);
|
|
21
|
+
}
|
|
22
|
+
function answersOnce2(name) {
|
|
23
|
+
const { kind } = OPERATIONS[name];
|
|
24
|
+
return kind === "query" || kind === "command" || kind === "receipt";
|
|
25
|
+
}
|
|
26
|
+
function answersBytes2(name) {
|
|
27
|
+
return Object.hasOwn(BYTE_ROWS, name);
|
|
28
|
+
}
|
|
29
|
+
function decodeInput2(name, value) {
|
|
30
|
+
const schema = rows[name].input;
|
|
31
|
+
const input = validated(schema, value);
|
|
32
|
+
const unknown = [];
|
|
33
|
+
collect(plan(schema), value, [], unknown);
|
|
34
|
+
if (unknown.length > 0)
|
|
35
|
+
throw new SdkError("invalid", `${name} does not take ${unknown.map(pointer).join(", ")}.`, {
|
|
36
|
+
issues: unknown.map((path) => ({ severity: "error", path, message: "Unknown field." }))
|
|
37
|
+
});
|
|
38
|
+
return input;
|
|
39
|
+
}
|
|
40
|
+
function encodeInput2(_name, input) {
|
|
41
|
+
return toJson(input) ?? null;
|
|
42
|
+
}
|
|
43
|
+
function encodeOutput2(name, value) {
|
|
44
|
+
return encode(plan(rows[name].output), value) ?? null;
|
|
45
|
+
}
|
|
46
|
+
function decodeOutput2(name, value) {
|
|
47
|
+
const schema = rows[name].output;
|
|
48
|
+
const result = schema["~standard"].validate(value);
|
|
49
|
+
if (!(result instanceof Promise) && result.issues === undefined)
|
|
50
|
+
return result.value;
|
|
51
|
+
return validated(schema, known(plan(schema), value, name === "head.watch" ? VIEW_DEPTH : null));
|
|
52
|
+
}
|
|
53
|
+
function validated(schema, value) {
|
|
54
|
+
const result = schema["~standard"].validate(value);
|
|
55
|
+
if (result instanceof Promise)
|
|
56
|
+
throw new SdkError("internal", "A wire schema is asynchronous.");
|
|
57
|
+
if (result.issues === undefined)
|
|
58
|
+
return result.value;
|
|
59
|
+
const issues = result.issues.map((issue) => ({
|
|
60
|
+
severity: "error",
|
|
61
|
+
path: (issue.path ?? []).map((segment) => {
|
|
62
|
+
const key = typeof segment === "object" ? segment.key : segment;
|
|
63
|
+
return typeof key === "number" ? key : String(key);
|
|
64
|
+
}),
|
|
65
|
+
message: issue.message
|
|
66
|
+
}));
|
|
67
|
+
throw new SdkError("invalid", issues.map((issue) => `${pointer(issue.path)}: ${issue.message}`).join("; "), { issues });
|
|
68
|
+
}
|
|
69
|
+
function plan(schema) {
|
|
70
|
+
const cached = plans.get(schema);
|
|
71
|
+
if (cached !== undefined)
|
|
72
|
+
return cached;
|
|
73
|
+
const built = compilePlan(schema["~standard"].jsonSchema.input({ target: "draft-2020-12" }), {}, new Map);
|
|
74
|
+
plans.set(schema, built);
|
|
75
|
+
return built;
|
|
76
|
+
}
|
|
77
|
+
function compilePlan(start, scope, memo) {
|
|
78
|
+
const resolved = resolve(start, scope);
|
|
79
|
+
if (resolved === null)
|
|
80
|
+
return INERT;
|
|
81
|
+
const { node, definitions } = resolved;
|
|
82
|
+
const cached = memo.get(node);
|
|
83
|
+
if (cached !== undefined)
|
|
84
|
+
return cached;
|
|
85
|
+
if (Guard.IsArray(node.anyOf)) {
|
|
86
|
+
const choice = { form: "choice", members: [], kinded: new Map, unkinded: [] };
|
|
87
|
+
memo.set(node, choice);
|
|
88
|
+
for (const entry of node.anyOf) {
|
|
89
|
+
const member = readNode(entry);
|
|
90
|
+
if (member === null)
|
|
91
|
+
continue;
|
|
92
|
+
let validator = null;
|
|
93
|
+
choice.members.push({
|
|
94
|
+
plan: compilePlan(member, definitions, memo),
|
|
95
|
+
kinds: readKinds(member, definitions, new Map),
|
|
96
|
+
check: (value) => (validator ??= Compile(definitions, member)).Check(value)
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (choice.members.every((candidate) => candidate.plan === INERT)) {
|
|
100
|
+
memo.set(node, INERT);
|
|
101
|
+
return INERT;
|
|
102
|
+
}
|
|
103
|
+
const kinds = new Set(choice.members.flatMap((candidate) => [...candidate.kinds ?? []]));
|
|
104
|
+
for (const kind of kinds)
|
|
105
|
+
choice.kinded.set(kind, choice.members.filter((candidate) => candidate.kinds?.has(kind) ?? true));
|
|
106
|
+
choice.unkinded.push(...choice.members.filter((candidate) => candidate.kinds === null));
|
|
107
|
+
return choice;
|
|
108
|
+
}
|
|
109
|
+
if (typeof node.type === "string" && PRIMITIVE_TYPES.has(node.type)) {
|
|
110
|
+
memo.set(node, INERT);
|
|
111
|
+
return INERT;
|
|
112
|
+
}
|
|
113
|
+
const declared = readNode(node.properties);
|
|
114
|
+
const properties = declared === null ? null : new Map;
|
|
115
|
+
const composite = {
|
|
116
|
+
form: "composite",
|
|
117
|
+
properties,
|
|
118
|
+
rest: null,
|
|
119
|
+
items: null,
|
|
120
|
+
nulled: []
|
|
121
|
+
};
|
|
122
|
+
memo.set(node, composite);
|
|
123
|
+
for (const [key, property] of Object.entries(declared ?? {})) {
|
|
124
|
+
const child = readNode(property);
|
|
125
|
+
if (child !== null)
|
|
126
|
+
properties?.set(key, compilePlan(child, definitions, memo));
|
|
127
|
+
}
|
|
128
|
+
const rest = readRest(node);
|
|
129
|
+
composite.rest = rest === null ? null : compilePlan(rest, definitions, memo);
|
|
130
|
+
const items = readNode(node.items);
|
|
131
|
+
if (items !== null) {
|
|
132
|
+
let validator = null;
|
|
133
|
+
composite.items = {
|
|
134
|
+
plan: compilePlan(items, definitions, memo),
|
|
135
|
+
kinds: readKinds(items, definitions, new Map),
|
|
136
|
+
reads: (value) => (validator ??= Compile(definitions, items)).Check(value)
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
for (const key of Guard.IsArray(node.required) ? node.required : []) {
|
|
140
|
+
if (typeof key !== "string" || declared === null || !Object.hasOwn(declared, key))
|
|
141
|
+
continue;
|
|
142
|
+
const property = readNode(declared[key]);
|
|
143
|
+
if (property !== null && accepts(property, definitions))
|
|
144
|
+
composite.nulled.push(key);
|
|
145
|
+
}
|
|
146
|
+
return composite;
|
|
147
|
+
}
|
|
148
|
+
function collect(plan, value, path, found) {
|
|
149
|
+
if (plan.form === "inert")
|
|
150
|
+
return;
|
|
151
|
+
if (plan.form === "choice") {
|
|
152
|
+
const member = select(plan, value);
|
|
153
|
+
if (member !== null)
|
|
154
|
+
collect(member, value, path, found);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (Guard.IsArray(value)) {
|
|
158
|
+
const { items } = plan;
|
|
159
|
+
if (items !== null)
|
|
160
|
+
for (const [index, item] of value.entries())
|
|
161
|
+
collect(items.plan, item, [...path, index], found);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (typeof value !== "object" || value === null)
|
|
165
|
+
return;
|
|
166
|
+
for (const [key, field] of Object.entries(value)) {
|
|
167
|
+
const known = plan.properties?.get(key) ?? plan.rest;
|
|
168
|
+
if (known === null)
|
|
169
|
+
found.push([...path, key]);
|
|
170
|
+
else
|
|
171
|
+
collect(known, field, [...path, key], found);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function encode(plan, value) {
|
|
175
|
+
if (plan.form === "inert" || value instanceof Uint8Array)
|
|
176
|
+
return toJson(value);
|
|
177
|
+
if (plan.form === "choice") {
|
|
178
|
+
if (!(value instanceof Map)) {
|
|
179
|
+
const candidates = candidatesFor(plan, readKind(value));
|
|
180
|
+
const [only] = candidates;
|
|
181
|
+
if (candidates.length === 0)
|
|
182
|
+
return toJson(value);
|
|
183
|
+
if (candidates.length === 1 && only !== undefined)
|
|
184
|
+
return encode(only.plan, value);
|
|
185
|
+
}
|
|
186
|
+
const json = toJson(value);
|
|
187
|
+
if (json === undefined)
|
|
188
|
+
return;
|
|
189
|
+
const member = select(plan, json);
|
|
190
|
+
return member === null ? json : encode(member, json);
|
|
191
|
+
}
|
|
192
|
+
if (Guard.IsArray(value) || value instanceof Set) {
|
|
193
|
+
const { items } = plan;
|
|
194
|
+
return items === null ? toJson(value) : Array.from(value, (item) => encode(items.plan, item) ?? null);
|
|
195
|
+
}
|
|
196
|
+
if (typeof value !== "object" || value === null)
|
|
197
|
+
return toJson(value);
|
|
198
|
+
const { properties, rest } = plan;
|
|
199
|
+
if (properties === null && rest === null)
|
|
200
|
+
return toJson(value);
|
|
201
|
+
const record = {};
|
|
202
|
+
const keep = (key, item) => {
|
|
203
|
+
const target = properties?.get(key) ?? rest;
|
|
204
|
+
const json = target === null ? undefined : encode(target, item);
|
|
205
|
+
if (json !== undefined)
|
|
206
|
+
put(record, key, json);
|
|
207
|
+
};
|
|
208
|
+
if (value instanceof Map)
|
|
209
|
+
for (const [key, item] of value)
|
|
210
|
+
keep(String(key), item);
|
|
211
|
+
else if (Guard.IsObjectNotArray(value))
|
|
212
|
+
for (const key of Object.keys(value))
|
|
213
|
+
keep(key, value[key]);
|
|
214
|
+
for (const key of plan.nulled)
|
|
215
|
+
if (!Object.hasOwn(record, key))
|
|
216
|
+
put(record, key, null);
|
|
217
|
+
return record;
|
|
218
|
+
}
|
|
219
|
+
function known(plan, value, positional) {
|
|
220
|
+
if (plan.form === "inert")
|
|
221
|
+
return value;
|
|
222
|
+
if (plan.form === "choice") {
|
|
223
|
+
const member = select(plan, value);
|
|
224
|
+
return member === null ? value : known(member, value, positional);
|
|
225
|
+
}
|
|
226
|
+
if (Guard.IsArray(value)) {
|
|
227
|
+
const { items } = plan;
|
|
228
|
+
if (items === null)
|
|
229
|
+
return value;
|
|
230
|
+
const { kinds, reads } = items;
|
|
231
|
+
const keeps = positional !== null && positional >= 0;
|
|
232
|
+
return value.flatMap((item) => {
|
|
233
|
+
const kind = readKind(item);
|
|
234
|
+
const listed = kinds === null || kind === undefined || kinds.has(kind);
|
|
235
|
+
const read = listed ? known(items.plan, item, null) : item;
|
|
236
|
+
if (listed && reads(read))
|
|
237
|
+
return [read];
|
|
238
|
+
const raw = rawPart2(item);
|
|
239
|
+
if (raw !== null && reads(raw))
|
|
240
|
+
return [raw];
|
|
241
|
+
return keeps ? [read] : [];
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
const { properties } = plan;
|
|
245
|
+
if (typeof value !== "object" || value === null || properties === null)
|
|
246
|
+
return value;
|
|
247
|
+
const inner = positional === null ? null : positional - 1;
|
|
248
|
+
return Object.fromEntries(Object.entries(value).map(([key, field]) => {
|
|
249
|
+
const property = properties.get(key);
|
|
250
|
+
return [key, property === undefined ? field : known(property, field, inner)];
|
|
251
|
+
}));
|
|
252
|
+
}
|
|
253
|
+
function select(choice, value) {
|
|
254
|
+
const candidates = candidatesFor(choice, readKind(value));
|
|
255
|
+
const [only] = candidates;
|
|
256
|
+
if (candidates.length === 1 && only !== undefined)
|
|
257
|
+
return only.plan;
|
|
258
|
+
return candidates.find((candidate) => candidate.check(value))?.plan ?? null;
|
|
259
|
+
}
|
|
260
|
+
function candidatesFor(choice, kind) {
|
|
261
|
+
if (kind === undefined)
|
|
262
|
+
return choice.members;
|
|
263
|
+
return choice.kinded.get(kind) ?? choice.unkinded;
|
|
264
|
+
}
|
|
265
|
+
function resolve(start, scope) {
|
|
266
|
+
let node = start;
|
|
267
|
+
let definitions = scope;
|
|
268
|
+
for (;; ) {
|
|
269
|
+
const local = readNode(node.$defs);
|
|
270
|
+
if (local !== null) {
|
|
271
|
+
const merged = Object.assign({}, definitions);
|
|
272
|
+
for (const [key, entry] of Object.entries(local)) {
|
|
273
|
+
const definition = readNode(entry);
|
|
274
|
+
if (definition !== null)
|
|
275
|
+
merged[key] = definition;
|
|
276
|
+
}
|
|
277
|
+
definitions = merged;
|
|
278
|
+
}
|
|
279
|
+
const ref = node.$ref;
|
|
280
|
+
if (typeof ref !== "string")
|
|
281
|
+
return { node, definitions };
|
|
282
|
+
if (ref === "Json")
|
|
283
|
+
return null;
|
|
284
|
+
const target = definitions[ref];
|
|
285
|
+
if (target === undefined)
|
|
286
|
+
return null;
|
|
287
|
+
node = target;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
function readKinds(start, scope, seen) {
|
|
291
|
+
const resolved = resolve(start, scope);
|
|
292
|
+
if (resolved === null)
|
|
293
|
+
return null;
|
|
294
|
+
const { node, definitions } = resolved;
|
|
295
|
+
if (seen.has(node))
|
|
296
|
+
return seen.get(node) ?? null;
|
|
297
|
+
seen.set(node, null);
|
|
298
|
+
if (Guard.IsArray(node.anyOf)) {
|
|
299
|
+
const sets = node.anyOf.map((member) => {
|
|
300
|
+
const child = readNode(member);
|
|
301
|
+
return child === null ? null : readKinds(child, definitions, seen);
|
|
302
|
+
});
|
|
303
|
+
const kinds = sets.every((set) => set !== null) ? new Set(sets.flatMap((set) => [...set ?? []])) : null;
|
|
304
|
+
seen.set(node, kinds);
|
|
305
|
+
return kinds;
|
|
306
|
+
}
|
|
307
|
+
const kind = readNode(readNode(node.properties)?.kind);
|
|
308
|
+
if (kind === null)
|
|
309
|
+
return null;
|
|
310
|
+
const kinds = typeof kind.const === "string" ? new Set([kind.const]) : Guard.IsArray(kind.enum) && kind.enum.every((entry) => typeof entry === "string") ? new Set(kind.enum) : null;
|
|
311
|
+
seen.set(node, kinds);
|
|
312
|
+
return kinds;
|
|
313
|
+
}
|
|
314
|
+
function accepts(start, scope) {
|
|
315
|
+
if (start.$ref === "Json")
|
|
316
|
+
return true;
|
|
317
|
+
const resolved = resolve(start, scope);
|
|
318
|
+
if (resolved === null)
|
|
319
|
+
return false;
|
|
320
|
+
const { node, definitions } = resolved;
|
|
321
|
+
if (node.type === "null")
|
|
322
|
+
return true;
|
|
323
|
+
return Guard.IsArray(node.anyOf) && node.anyOf.some((member) => {
|
|
324
|
+
const child = readNode(member);
|
|
325
|
+
return child !== null && accepts(child, definitions);
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
function readRest(node) {
|
|
329
|
+
const additional = readNode(node.additionalProperties);
|
|
330
|
+
if (additional !== null)
|
|
331
|
+
return additional;
|
|
332
|
+
const patterns = readNode(node.patternProperties);
|
|
333
|
+
if (patterns === null)
|
|
334
|
+
return null;
|
|
335
|
+
const [first] = Object.values(patterns);
|
|
336
|
+
return readNode(first);
|
|
337
|
+
}
|
|
338
|
+
function toJson(value) {
|
|
339
|
+
if (value === null || typeof value === "boolean" || typeof value === "string")
|
|
340
|
+
return value;
|
|
341
|
+
if (typeof value === "number")
|
|
342
|
+
return Number.isFinite(value) ? value : null;
|
|
343
|
+
if (value instanceof Uint8Array)
|
|
344
|
+
return btoa(Array.from(value, (byte) => String.fromCharCode(byte)).join(""));
|
|
345
|
+
if (value instanceof Set)
|
|
346
|
+
return Array.from(value, (item) => toJson(item) ?? null);
|
|
347
|
+
if (Guard.IsArray(value))
|
|
348
|
+
return value.map((item) => toJson(item) ?? null);
|
|
349
|
+
if (typeof value !== "object")
|
|
350
|
+
return;
|
|
351
|
+
const record = {};
|
|
352
|
+
const keep = (key, item) => {
|
|
353
|
+
const json = toJson(item);
|
|
354
|
+
if (json !== undefined)
|
|
355
|
+
put(record, key, json);
|
|
356
|
+
};
|
|
357
|
+
if (value instanceof Map)
|
|
358
|
+
for (const [key, item] of value)
|
|
359
|
+
keep(String(key), item);
|
|
360
|
+
else if (Guard.IsObjectNotArray(value))
|
|
361
|
+
for (const key of Object.keys(value))
|
|
362
|
+
keep(key, value[key]);
|
|
363
|
+
return record;
|
|
364
|
+
}
|
|
365
|
+
function put(record, key, json) {
|
|
366
|
+
if (key === "__proto__")
|
|
367
|
+
Object.defineProperty(record, key, {
|
|
368
|
+
value: json,
|
|
369
|
+
enumerable: true,
|
|
370
|
+
writable: true,
|
|
371
|
+
configurable: true
|
|
372
|
+
});
|
|
373
|
+
else
|
|
374
|
+
record[key] = json;
|
|
375
|
+
}
|
|
376
|
+
function readNode(value) {
|
|
377
|
+
return Guard.IsObjectNotArray(value) ? value : null;
|
|
378
|
+
}
|
|
379
|
+
function readKind(value) {
|
|
380
|
+
const kind = Guard.IsObjectNotArray(value) ? value.kind : undefined;
|
|
381
|
+
return typeof kind === "string" ? kind : undefined;
|
|
382
|
+
}
|
|
383
|
+
function pointer(path) {
|
|
384
|
+
return path.length === 0 ? "the input" : `/${path.join("/")}`;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export { namesOperation2, answersOnce2, answersBytes2, decodeInput2, encodeInput2, encodeOutput2, decodeOutput2 };
|
|
File without changes
|
|
@@ -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-sffw3se8.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;
|