@nyte-ai/protocol 0.0.19 → 0.0.23
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.
|
@@ -7,6 +7,7 @@ import { Type } from "typebox";
|
|
|
7
7
|
import { Compile } from "typebox/compile";
|
|
8
8
|
import { SdkError } from "@nyte-ai/schema";
|
|
9
9
|
var TAKE = -1;
|
|
10
|
+
var NO_SESSIONS = { ids: [], list: [] };
|
|
10
11
|
var streamed = Compile(Type.Object({ markdown: Type.String() }));
|
|
11
12
|
function viewFrames2(views) {
|
|
12
13
|
let previous = null;
|
|
@@ -40,6 +41,34 @@ function applyViewFrame2(view, frame) {
|
|
|
40
41
|
catalog: frame.catalog ?? view.catalog
|
|
41
42
|
};
|
|
42
43
|
}
|
|
44
|
+
function sessionsFrames2(lists) {
|
|
45
|
+
let previous = null;
|
|
46
|
+
return mapped2(lists, (list) => {
|
|
47
|
+
const { runs, items } = splice(previous ?? [], list) ?? { runs: [0, list.length], items: [] };
|
|
48
|
+
const kind = previous === null ? "list" : "delta";
|
|
49
|
+
previous = list;
|
|
50
|
+
return { kind, order: { runs, items: items.map((info) => info.id) }, items };
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function sessionLists2(frames) {
|
|
54
|
+
return {
|
|
55
|
+
[Symbol.asyncIterator]() {
|
|
56
|
+
let shown = null;
|
|
57
|
+
return mapped2(frames, (frame) => {
|
|
58
|
+
const before = frame.kind === "list" ? NO_SESSIONS : shown;
|
|
59
|
+
if (before === null)
|
|
60
|
+
throw unfit("A sessions delta arrived before its list.");
|
|
61
|
+
const taken = new Set(frame.order.items);
|
|
62
|
+
const rows = new Map(frame.items.map((info) => [info.id, info]));
|
|
63
|
+
const kept = new Map(before.list.map((info) => [info.id, info]));
|
|
64
|
+
const ids = applySplice(before.ids, frame.order);
|
|
65
|
+
const list = ids.flatMap((id) => (taken.has(id) ? rows.get(id) : kept.get(id)) ?? []);
|
|
66
|
+
shown = { ids, list };
|
|
67
|
+
return list;
|
|
68
|
+
})[Symbol.asyncIterator]();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
43
72
|
function viewDelta(previous, next) {
|
|
44
73
|
const appends = [];
|
|
45
74
|
const messages = splice(previous.messages, next.messages, (before, after, at) => {
|
|
@@ -154,4 +183,4 @@ function unfit(message) {
|
|
|
154
183
|
return new SdkError("invalid", message);
|
|
155
184
|
}
|
|
156
185
|
|
|
157
|
-
export { viewFrames2, applyViewFrame2 };
|
|
186
|
+
export { viewFrames2, applyViewFrame2, sessionsFrames2, sessionLists2 };
|
package/dist/src/index.js
CHANGED
|
@@ -52,8 +52,10 @@ import {
|
|
|
52
52
|
} from "../chunks/client-xscg1xbf.js";
|
|
53
53
|
import {
|
|
54
54
|
viewFrames2,
|
|
55
|
-
applyViewFrame2
|
|
56
|
-
|
|
55
|
+
applyViewFrame2,
|
|
56
|
+
sessionsFrames2,
|
|
57
|
+
sessionLists2
|
|
58
|
+
} from "../chunks/client-st5jk59p.js";
|
|
57
59
|
import {
|
|
58
60
|
operationsDigest2
|
|
59
61
|
} from "../chunks/client-hrkzqw6w.js";
|
|
@@ -90,6 +92,8 @@ export {
|
|
|
90
92
|
parseSse2 as parseSse,
|
|
91
93
|
readInputHeader2 as readInputHeader,
|
|
92
94
|
readStreamFrame2 as readStreamFrame,
|
|
95
|
+
sessionLists2 as sessionLists,
|
|
96
|
+
sessionsFrames2 as sessionsFrames,
|
|
93
97
|
sseFrames2 as sseFrames,
|
|
94
98
|
statusCode2 as statusCode,
|
|
95
99
|
streamBuffer2 as streamBuffer,
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import type { SessionView, ViewFrame } from "@nyte-ai/schema";
|
|
1
|
+
import type { SessionInfo, SessionsFrame, SessionView, ViewFrame } from "@nyte-ai/schema";
|
|
2
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
3
|
export declare function viewFrames(views: AsyncIterable<SessionView>): AsyncIterable<ViewFrame>;
|
|
4
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
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[]>;
|
package/dist/src/view-frames.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
viewFrames2,
|
|
3
|
-
applyViewFrame2
|
|
4
|
-
|
|
3
|
+
applyViewFrame2,
|
|
4
|
+
sessionsFrames2,
|
|
5
|
+
sessionLists2
|
|
6
|
+
} from "../chunks/client-st5jk59p.js";
|
|
5
7
|
import"../chunks/client-xscg1xbf.js";
|
|
6
8
|
export {
|
|
7
9
|
applyViewFrame2 as applyViewFrame,
|
|
10
|
+
sessionLists2 as sessionLists,
|
|
11
|
+
sessionsFrames2 as sessionsFrames,
|
|
8
12
|
viewFrames2 as viewFrames
|
|
9
13
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nyte-ai/protocol",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"provenance": true
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@nyte-ai/core": "0.0.
|
|
29
|
-
"@nyte-ai/schema": "0.0.
|
|
30
|
-
"fflate": "0.8.3",
|
|
31
|
-
"typebox": "1.
|
|
28
|
+
"@nyte-ai/core": "0.0.23",
|
|
29
|
+
"@nyte-ai/schema": "0.0.23",
|
|
30
|
+
"fflate": "^0.8.3",
|
|
31
|
+
"typebox": "^1.4.2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/node": "^26.6.5",
|