@niscorp/moss 0.6.0 → 0.7.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/CHANGELOG.md +100 -0
- package/DESIGN.md +77 -40
- package/DOCS.md +636 -78
- package/README.md +2 -2
- package/dist/{chunk-VBWNHF4H.cjs → chunk-C2DNDIQX.cjs} +4 -3
- package/dist/chunk-C2DNDIQX.cjs.map +1 -0
- package/dist/{chunk-R66WUKGC.cjs → chunk-DSTHFSTO.cjs} +1988 -1328
- package/dist/chunk-DSTHFSTO.cjs.map +1 -0
- package/dist/chunk-F45SFR7W.cjs +903 -0
- package/dist/chunk-F45SFR7W.cjs.map +1 -0
- package/dist/{chunk-NSK7QSSG.js → chunk-IMZZB4JE.js} +4 -3
- package/dist/chunk-IMZZB4JE.js.map +1 -0
- package/dist/{chunk-V5YMJL7Z.js → chunk-MTC46PGQ.js} +1971 -1309
- package/dist/chunk-MTC46PGQ.js.map +1 -0
- package/dist/chunk-MYGVHWS5.js +870 -0
- package/dist/chunk-MYGVHWS5.js.map +1 -0
- package/dist/{chunk-WKBH3UMB.js → chunk-X2Q546EB.js} +3 -3
- package/dist/{chunk-WKBH3UMB.js.map → chunk-X2Q546EB.js.map} +1 -1
- package/dist/{chunk-D3YZIAYV.cjs → chunk-Z2VA6AOE.cjs} +5 -5
- package/dist/{chunk-D3YZIAYV.cjs.map → chunk-Z2VA6AOE.cjs.map} +1 -1
- package/dist/document-AbQUbQaP.d.ts +381 -0
- package/dist/document-wHHxIXJz.d.cts +381 -0
- package/dist/{index-B411sK9M.d.cts → index-Dml1klpZ.d.cts} +4 -0
- package/dist/{index-B411sK9M.d.ts → index-Dml1klpZ.d.ts} +4 -0
- package/dist/index.cjs +17 -17
- package/dist/index.d.cts +7 -9
- package/dist/index.d.ts +7 -9
- package/dist/index.js +3 -3
- package/dist/integrations.cjs +3 -3
- package/dist/integrations.d.cts +1 -1
- package/dist/integrations.d.ts +1 -1
- package/dist/integrations.js +1 -1
- package/dist/node.cjs +8 -8
- package/dist/node.d.cts +3 -4
- package/dist/node.d.ts +3 -4
- package/dist/node.js +4 -4
- package/dist/tide.d.cts +1 -1
- package/dist/tide.d.ts +1 -1
- package/dist/unverified.cjs +3 -3
- package/dist/unverified.js +2 -2
- package/dist/vite.cjs +9 -9
- package/dist/vite.d.cts +6 -1
- package/dist/vite.d.ts +6 -1
- package/dist/vite.js +4 -4
- package/package.json +13 -13
- package/dist/app-CUnDcXQu.d.ts +0 -143
- package/dist/app-CdANzi2q.d.cts +0 -143
- package/dist/chunk-NSK7QSSG.js.map +0 -1
- package/dist/chunk-PWUO4RET.js +0 -374
- package/dist/chunk-PWUO4RET.js.map +0 -1
- package/dist/chunk-R2YPQHQH.cjs +0 -383
- package/dist/chunk-R2YPQHQH.cjs.map +0 -1
- package/dist/chunk-R66WUKGC.cjs.map +0 -1
- package/dist/chunk-V5YMJL7Z.js.map +0 -1
- package/dist/chunk-VBWNHF4H.cjs.map +0 -1
- package/dist/document-D7nroBww.d.cts +0 -169
- package/dist/document-DeTPGBil.d.ts +0 -169
package/dist/chunk-PWUO4RET.js
DELETED
|
@@ -1,374 +0,0 @@
|
|
|
1
|
-
import { spanClock } from './chunk-NSK7QSSG.js';
|
|
2
|
-
import { CLOSE_SIGNED_OUT, encodeDelta, frameHash } from './chunk-4ZGAFZGS.js';
|
|
3
|
-
import { canvasTreeOf, NovaEventSchema, createComponentRegistry, createLayoutStore, createShell } from '@niscorp/nova';
|
|
4
|
-
import { evaluate } from '@niscorp/prism';
|
|
5
|
-
|
|
6
|
-
// src/shells/host-state.ts
|
|
7
|
-
var layoutsOf = (made) => ({
|
|
8
|
-
...made.frame !== void 0 ? { frame: made.frame } : {},
|
|
9
|
-
layoutStore: made.layoutStore ?? {},
|
|
10
|
-
fragments: made.fragments ?? {}
|
|
11
|
-
});
|
|
12
|
-
var canvasesOf = (live) => Object.keys(live.shell.getState().canvases);
|
|
13
|
-
var endShell = (host, live) => {
|
|
14
|
-
live.ended = true;
|
|
15
|
-
host.living.delete(live);
|
|
16
|
-
};
|
|
17
|
-
var treeOf = (live, canvasId) => canvasTreeOf(live.shell, canvasId);
|
|
18
|
-
var canvasMessage = (live, canvasId) => {
|
|
19
|
-
const message = { type: "render", canvas: canvasId, tree: treeOf(live, canvasId) };
|
|
20
|
-
return JSON.stringify(message);
|
|
21
|
-
};
|
|
22
|
-
var canvasMessageOf = (live, canvasId) => {
|
|
23
|
-
try {
|
|
24
|
-
return canvasMessage(live, canvasId);
|
|
25
|
-
} catch (error) {
|
|
26
|
-
console.error(`[moss/shells] canvas "${canvasId}" failed to render \u2014 holding its last tree:`, error);
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
var DELTA_CEILING = 0.6;
|
|
31
|
-
var DELTA_MAX_FRAME = 64 * 1024;
|
|
32
|
-
var shorterAsDelta = (previous, next, canvasId) => {
|
|
33
|
-
if (previous.length > DELTA_MAX_FRAME || next.length > DELTA_MAX_FRAME) return null;
|
|
34
|
-
try {
|
|
35
|
-
const ops = encodeDelta(previous, next);
|
|
36
|
-
const message = { type: "render-delta", canvas: canvasId, ops, hash: frameHash(next) };
|
|
37
|
-
const text = JSON.stringify(message);
|
|
38
|
-
return text.length <= next.length * DELTA_CEILING ? text : null;
|
|
39
|
-
} catch (error) {
|
|
40
|
-
console.error(`[moss/shells] canvas "${canvasId}" failed to encode as a delta \u2014 sending it whole:`, error);
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
var pass = (live, delta) => {
|
|
45
|
-
if (live.ended) return;
|
|
46
|
-
const canvases = canvasesOf(live);
|
|
47
|
-
for (const gone of [...live.sentByCanvas.keys()].filter((canvasId) => !canvases.includes(canvasId))) {
|
|
48
|
-
live.sentByCanvas.delete(gone);
|
|
49
|
-
const empty = JSON.stringify({ type: "render", canvas: gone, tree: [] });
|
|
50
|
-
for (const connection of live.connections) connection.send(empty);
|
|
51
|
-
}
|
|
52
|
-
for (const canvasId of canvases) {
|
|
53
|
-
const next = canvasMessageOf(live, canvasId);
|
|
54
|
-
const previous = live.sentByCanvas.get(canvasId);
|
|
55
|
-
if (next === null || previous === next) continue;
|
|
56
|
-
live.sentByCanvas.set(canvasId, next);
|
|
57
|
-
const short = delta && previous !== void 0 && live.deltaReady.size > 0 ? shorterAsDelta(previous, next, canvasId) : null;
|
|
58
|
-
for (const connection of live.connections) {
|
|
59
|
-
connection.send(short !== null && live.deltaReady.has(connection) ? short : next);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
let frame;
|
|
63
|
-
try {
|
|
64
|
-
frame = JSON.stringify({ type: "frame", tree: live.shell.getShellRenderTree() });
|
|
65
|
-
} catch (error) {
|
|
66
|
-
console.error("[moss/shells] the shell frame failed to render on a flush \u2014 leaving the last one in place:", error);
|
|
67
|
-
}
|
|
68
|
-
if (frame !== void 0 && frame !== live.sentFrame) {
|
|
69
|
-
live.sentFrame = frame;
|
|
70
|
-
for (const connection of live.connections) connection.send(frame);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
var follow = (live, delta) => {
|
|
74
|
-
const flush = () => {
|
|
75
|
-
if (live.flushing) return;
|
|
76
|
-
live.flushing = true;
|
|
77
|
-
queueMicrotask(() => {
|
|
78
|
-
live.flushing = false;
|
|
79
|
-
pass(live, delta);
|
|
80
|
-
setTimeout(() => pass(live, delta), 0);
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
live.shell.onStateChange(flush);
|
|
84
|
-
live.shell.onDataChange(flush);
|
|
85
|
-
};
|
|
86
|
-
var attach = (live, connection, wantsDelta) => {
|
|
87
|
-
live.connections.add(connection);
|
|
88
|
-
if (wantsDelta) live.deltaReady.add(connection);
|
|
89
|
-
live.idleSince = null;
|
|
90
|
-
let frameTree;
|
|
91
|
-
try {
|
|
92
|
-
frameTree = live.shell.getShellRenderTree();
|
|
93
|
-
} catch (error) {
|
|
94
|
-
console.error("[moss/shells] the shell frame failed to render \u2014 serving an empty arrangement:", error);
|
|
95
|
-
}
|
|
96
|
-
const frameMessage = JSON.stringify({ type: "frame", tree: frameTree ?? [] });
|
|
97
|
-
connection.send(frameMessage);
|
|
98
|
-
if (frameTree === void 0) {
|
|
99
|
-
delete live.sentFrame;
|
|
100
|
-
} else {
|
|
101
|
-
if (live.sentFrame !== frameMessage) {
|
|
102
|
-
for (const other of live.connections) if (other !== connection) other.send(frameMessage);
|
|
103
|
-
}
|
|
104
|
-
live.sentFrame = frameMessage;
|
|
105
|
-
}
|
|
106
|
-
for (const canvasId of canvasesOf(live)) {
|
|
107
|
-
const next = canvasMessageOf(live, canvasId);
|
|
108
|
-
if (next === null) continue;
|
|
109
|
-
if (live.sentByCanvas.get(canvasId) !== next) {
|
|
110
|
-
for (const other of live.connections) if (other !== connection) other.send(next);
|
|
111
|
-
}
|
|
112
|
-
live.sentByCanvas.set(canvasId, next);
|
|
113
|
-
connection.send(next);
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
var resync = (live, connection) => {
|
|
117
|
-
if (!live.connections.has(connection)) return;
|
|
118
|
-
let frameTree = [];
|
|
119
|
-
try {
|
|
120
|
-
frameTree = live.shell.getShellRenderTree();
|
|
121
|
-
} catch (error) {
|
|
122
|
-
console.error("[moss/shells] the shell frame failed to render on resync \u2014 serving an empty arrangement:", error);
|
|
123
|
-
}
|
|
124
|
-
connection.send(JSON.stringify({ type: "frame", tree: frameTree }));
|
|
125
|
-
for (const canvasId of canvasesOf(live)) {
|
|
126
|
-
const current = live.sentByCanvas.get(canvasId) ?? canvasMessageOf(live, canvasId);
|
|
127
|
-
if (current === null || current === void 0) continue;
|
|
128
|
-
connection.send(current);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
// src/shells/sessions.ts
|
|
133
|
-
var instrumentFunctions = (fns, emit, principal) => Object.fromEntries(
|
|
134
|
-
Object.entries(fns).map(([name, handler]) => [
|
|
135
|
-
name,
|
|
136
|
-
async (data, signal) => {
|
|
137
|
-
const clock = spanClock();
|
|
138
|
-
const hasPrincipal = principal !== null;
|
|
139
|
-
try {
|
|
140
|
-
const out = await handler(data, signal);
|
|
141
|
-
emit({ name: "fn.call", startUnixNano: clock.startUnixNano, endUnixNano: clock.endUnixNano(), status: "ok", attributes: { fn: name, hasPrincipal } });
|
|
142
|
-
return out;
|
|
143
|
-
} catch (err) {
|
|
144
|
-
emit({ name: "fn.call", startUnixNano: clock.startUnixNano, endUnixNano: clock.endUnixNano(), status: "error", attributes: { fn: name, hasPrincipal } });
|
|
145
|
-
throw err;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
])
|
|
149
|
-
);
|
|
150
|
-
var grant = (shellRef, token) => {
|
|
151
|
-
const message = JSON.stringify({ type: "session", token });
|
|
152
|
-
for (const connection of shellRef.live?.connections ?? []) {
|
|
153
|
-
if (connection.seal === void 0) connection.send(message);
|
|
154
|
-
else {
|
|
155
|
-
void connection.seal(token).then(
|
|
156
|
-
(sealed) => connection.send(JSON.stringify({ type: "session", sealed })),
|
|
157
|
-
(error) => console.error("[moss] a sign-in could not be sealed, and was not handed over:", error)
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
var revoke = (host, shellRef, principal) => {
|
|
163
|
-
const { config, durable } = host;
|
|
164
|
-
const forgotten = config.revokeSessions !== void 0 && principal !== null ? config.revokeSessions(principal) : Promise.resolve();
|
|
165
|
-
forgotten.catch((error) => console.error(`[moss] sign-out of ${principal ?? "anonymous"} did not revoke its sessions:`, error));
|
|
166
|
-
queueMicrotask(() => {
|
|
167
|
-
const live = shellRef.live;
|
|
168
|
-
if (live === void 0) return;
|
|
169
|
-
endShell(host, live);
|
|
170
|
-
if (principal !== null && durable.get(principal)?.live === live) durable.delete(principal);
|
|
171
|
-
for (const connection of [...live.connections]) connection.close(CLOSE_SIGNED_OUT, "signed out");
|
|
172
|
-
live.connections.clear();
|
|
173
|
-
if (principal !== null) live.shell.dispose();
|
|
174
|
-
});
|
|
175
|
-
return forgotten;
|
|
176
|
-
};
|
|
177
|
-
var functionSessionFor = (host, who, wire, shellRef) => {
|
|
178
|
-
const { config } = host;
|
|
179
|
-
const { principal } = who;
|
|
180
|
-
const session = {
|
|
181
|
-
principal,
|
|
182
|
-
roles: who.roles,
|
|
183
|
-
identity: who.scope,
|
|
184
|
-
actions: who.actions,
|
|
185
|
-
wire,
|
|
186
|
-
get shell() {
|
|
187
|
-
if (shellRef.sessionShell === void 0) throw new Error("moss: a function touched the shell before the session finished building.");
|
|
188
|
-
return shellRef.sessionShell;
|
|
189
|
-
},
|
|
190
|
-
grant: (token) => grant(shellRef, token),
|
|
191
|
-
revoke: () => revoke(host, shellRef, principal),
|
|
192
|
-
answerIntent: (writers, asked) => config.answerIntent === void 0 ? Promise.reject(new Error("moss: this shell host was given no way to answer an intent.")) : config.answerIntent(principal, writers, asked),
|
|
193
|
-
recordRun: (run) => {
|
|
194
|
-
config.hooks.runs?.({ ...run, at: Date.now(), principal, shellId: shellRef.shell?.id ?? "" }, session);
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
return session;
|
|
198
|
-
};
|
|
199
|
-
var sessionOn = (host, cell, ephemeral, reset) => ({
|
|
200
|
-
get shell() {
|
|
201
|
-
return cell.live.sessionShell;
|
|
202
|
-
},
|
|
203
|
-
attach: (connection, options) => attach(cell.live, connection, host.delta && options?.delta === true),
|
|
204
|
-
resync: (connection) => resync(cell.live, connection),
|
|
205
|
-
detach: (connection) => {
|
|
206
|
-
const live = cell.live;
|
|
207
|
-
live.connections.delete(connection);
|
|
208
|
-
live.deltaReady.delete(connection);
|
|
209
|
-
if (live.connections.size > 0) return;
|
|
210
|
-
live.idleSince = Date.now();
|
|
211
|
-
if (!ephemeral) return;
|
|
212
|
-
endShell(host, live);
|
|
213
|
-
live.shell.dispose();
|
|
214
|
-
},
|
|
215
|
-
// An event without an origin goes to every instance of the shell, so one for
|
|
216
|
-
// a canvas the shell does not have is dropped. An origin a terminal names
|
|
217
|
-
// comes off the wire and is held to that canvas; with none named, the
|
|
218
|
-
// canvas's active instance is the origin.
|
|
219
|
-
dispatch: (canvas, event) => {
|
|
220
|
-
const { shell } = cell.live;
|
|
221
|
-
const state = shell.getState().canvases[canvas];
|
|
222
|
-
if (state === void 0) return;
|
|
223
|
-
const claimed = event["origin"];
|
|
224
|
-
if (claimed !== void 0 && (typeof claimed !== "string" || !state.stack.some((item) => item.id === claimed))) return;
|
|
225
|
-
const active = state.active;
|
|
226
|
-
const parsed = NovaEventSchema.safeParse(claimed !== void 0 || active === void 0 ? event : { ...event, origin: active.id });
|
|
227
|
-
if (parsed.success) shell.dispatch(parsed.data);
|
|
228
|
-
},
|
|
229
|
-
publish: (channel, payload) => cell.live.shell.publish(channel, payload),
|
|
230
|
-
back: () => cell.live.shell.back(),
|
|
231
|
-
popTo: (canvas, instance) => cell.live.shell.popTo(canvas, instance),
|
|
232
|
-
reset: () => reset(cell)
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
// src/shells/build.ts
|
|
236
|
-
var whole = /* @__PURE__ */ new WeakMap();
|
|
237
|
-
var refuse = (member) => () => {
|
|
238
|
-
throw new Error(
|
|
239
|
-
`moss: ${member} was called on a session's shell. It changes what the shell is made of without moss: what it adds is not verified, is in nobody's catalog, and is gone when the shell is rebuilt. Code that means to do that takes the whole shell: \`unverifiedShell(session)\`, from \`@niscorp/moss/unverified\`.`
|
|
240
|
-
);
|
|
241
|
-
};
|
|
242
|
-
var sessionShellOf = (shell) => {
|
|
243
|
-
const guarded = {
|
|
244
|
-
...shell,
|
|
245
|
-
registerAction: refuse("registerAction"),
|
|
246
|
-
removeAction: refuse("removeAction"),
|
|
247
|
-
registerFragment: refuse("registerFragment"),
|
|
248
|
-
addCanvas: refuse("addCanvas"),
|
|
249
|
-
removeCanvas: refuse("removeCanvas"),
|
|
250
|
-
setCanvasLayout: refuse("setCanvasLayout"),
|
|
251
|
-
setLayout: refuse("setLayout"),
|
|
252
|
-
setPhrases: refuse("setPhrases"),
|
|
253
|
-
dispose: refuse("dispose")
|
|
254
|
-
};
|
|
255
|
-
whole.set(guarded, shell);
|
|
256
|
-
whole.set(shell, shell);
|
|
257
|
-
return guarded;
|
|
258
|
-
};
|
|
259
|
-
var wholeShellOf = (sessionShell) => {
|
|
260
|
-
const shell = whole.get(sessionShell);
|
|
261
|
-
if (shell === void 0) throw new Error("moss: this is not the shell of a session moss built.");
|
|
262
|
-
return shell;
|
|
263
|
-
};
|
|
264
|
-
var today = () => (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
265
|
-
var mountedCanvases = (declared, granted, inputs, given) => declared.map((canvas) => {
|
|
266
|
-
const declared2 = canvas.initial;
|
|
267
|
-
const candidates = declared2 === void 0 ? [] : Array.isArray(declared2) ? declared2 : [declared2];
|
|
268
|
-
const seed = candidates.find((c) => granted.has(typeof c === "string" ? c : c.action));
|
|
269
|
-
if (seed === void 0) {
|
|
270
|
-
const { initial: _dropped, ...rest } = canvas;
|
|
271
|
-
return rest;
|
|
272
|
-
}
|
|
273
|
-
const action = typeof seed === "string" ? seed : seed.action;
|
|
274
|
-
const staticInput = typeof seed === "string" ? {} : seed.input ?? {};
|
|
275
|
-
const withFragments = typeof seed === "string" ? void 0 : seed.with;
|
|
276
|
-
return {
|
|
277
|
-
...canvas,
|
|
278
|
-
initial: { action, input: { ...staticInput, ...inputs[canvas.id] ?? {}, ...given?.[canvas.id] ?? {} }, ...withFragments !== void 0 ? { with: withFragments } : {} }
|
|
279
|
-
};
|
|
280
|
-
});
|
|
281
|
-
var seedCanvases = (live, declaredSeeds, granted) => {
|
|
282
|
-
if (declaredSeeds === void 0) return;
|
|
283
|
-
live.seeded = Promise.resolve(declaredSeeds).then((byCanvas) => {
|
|
284
|
-
if (live.ended) return;
|
|
285
|
-
for (const [canvasId, seeds] of Object.entries(byCanvas ?? {})) {
|
|
286
|
-
for (const seed of seeds) {
|
|
287
|
-
const action = typeof seed === "string" ? seed : seed.action;
|
|
288
|
-
if (!granted.has(action)) continue;
|
|
289
|
-
const input = typeof seed === "string" ? void 0 : seed.input;
|
|
290
|
-
const withFragments = typeof seed === "string" ? void 0 : seed.with;
|
|
291
|
-
try {
|
|
292
|
-
live.shell.push(canvasId, action, input, withFragments, { history: false });
|
|
293
|
-
} catch (error) {
|
|
294
|
-
console.error(`[moss/shells] the seed "${action}" on canvas "${canvasId}" could not be pushed, and was skipped:`, error);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}).catch((error) => {
|
|
299
|
-
console.error("[moss/shells] the seeds of a shell could not be derived, and none was pushed:", error);
|
|
300
|
-
});
|
|
301
|
-
};
|
|
302
|
-
var buildShell = async (host, asked) => {
|
|
303
|
-
const { config, emit, kept, delta } = host;
|
|
304
|
-
const { hooks } = config;
|
|
305
|
-
const { token, principal, opening, reset, wanted } = asked;
|
|
306
|
-
const buildClock = emit === void 0 ? void 0 : spanClock();
|
|
307
|
-
const made = await config.composition(principal);
|
|
308
|
-
if (!wanted()) return void 0;
|
|
309
|
-
const ids = Object.keys(made.actions);
|
|
310
|
-
const granted = new Set(ids);
|
|
311
|
-
const inputs = await hooks.inputs?.({ principal, actions: ids, roles: made.roles, identity: made.scope, wire: config.wire(token) }) ?? {};
|
|
312
|
-
if (!wanted()) return void 0;
|
|
313
|
-
const canvases = mountedCanvases(made.canvases, granted, inputs, opening?.inputs);
|
|
314
|
-
const wire = config.wrapWire === void 0 ? config.wire(token) : config.wrapWire(config.wire(token));
|
|
315
|
-
const userId = principal ?? "anonymous";
|
|
316
|
-
const registry = createComponentRegistry();
|
|
317
|
-
for (const [name, contract] of Object.entries(made.components)) registry.register(name, contract);
|
|
318
|
-
const shellRef = {};
|
|
319
|
-
const session = functionSessionFor(host, { principal, roles: made.roles, scope: made.scope, actions: ids }, wire, shellRef);
|
|
320
|
-
const phrases = await hooks.phrases?.({ principal, identity: made.scope, wire: config.wire(token) }) ?? {};
|
|
321
|
-
if (!wanted()) return void 0;
|
|
322
|
-
const rawFunctions = hooks.functions?.(session) ?? {};
|
|
323
|
-
const functions = emit === void 0 ? rawFunctions : instrumentFunctions(rawFunctions, emit, principal);
|
|
324
|
-
if (kept) hooks.onSession?.(session);
|
|
325
|
-
const layoutStore = createLayoutStore();
|
|
326
|
-
for (const [refId, node] of Object.entries(made.layoutStore ?? {})) layoutStore.set(refId, node);
|
|
327
|
-
let minted = 0;
|
|
328
|
-
const idSeed = opening?.seed;
|
|
329
|
-
const shell = createShell({
|
|
330
|
-
registry,
|
|
331
|
-
canvases,
|
|
332
|
-
layoutStore,
|
|
333
|
-
...idSeed === void 0 ? {} : { instanceIdFn: () => `act-${idSeed}-${minted += 1}` },
|
|
334
|
-
...made.frame !== void 0 ? { canvasLayout: made.frame } : {},
|
|
335
|
-
actions: { ...made.actions },
|
|
336
|
-
...made.fragments !== void 0 ? { fragments: { ...made.fragments } } : {},
|
|
337
|
-
transform: (config2, source) => evaluate(config2, source !== null && typeof source === "object" && !Array.isArray(source) ? { ...source, userId, today: today() } : source),
|
|
338
|
-
fetch: wire,
|
|
339
|
-
functions,
|
|
340
|
-
...config.limits?.endpointTimeoutMs === void 0 ? {} : { endpointTimeoutMs: config.limits.endpointTimeoutMs },
|
|
341
|
-
// An empty book is withheld: nova runs its phrase pass whenever one is given.
|
|
342
|
-
...Object.keys(phrases).length === 0 ? {} : { phrases },
|
|
343
|
-
...config.phraseKeys === void 0 ? {} : { phraseKeys: config.phraseKeys }
|
|
344
|
-
});
|
|
345
|
-
const sessionShell = sessionShellOf(shell);
|
|
346
|
-
shellRef.shell = shell;
|
|
347
|
-
shellRef.sessionShell = sessionShell;
|
|
348
|
-
const live = {
|
|
349
|
-
shell,
|
|
350
|
-
sessionShell,
|
|
351
|
-
actionIds: granted,
|
|
352
|
-
entries: made.entries,
|
|
353
|
-
layouts: layoutsOf(made),
|
|
354
|
-
connections: /* @__PURE__ */ new Set(),
|
|
355
|
-
sentByCanvas: /* @__PURE__ */ new Map(),
|
|
356
|
-
deltaReady: /* @__PURE__ */ new Set(),
|
|
357
|
-
flushing: false,
|
|
358
|
-
ended: false,
|
|
359
|
-
builtAt: Date.now(),
|
|
360
|
-
idleSince: Date.now(),
|
|
361
|
-
seeded: Promise.resolve()
|
|
362
|
-
};
|
|
363
|
-
shellRef.live = live;
|
|
364
|
-
seedCanvases(live, hooks.seeds?.({ principal, actions: ids, roles: made.roles, wire }), granted);
|
|
365
|
-
follow(live, delta);
|
|
366
|
-
if (emit !== void 0 && buildClock !== void 0) {
|
|
367
|
-
emit({ name: "shell.build", startUnixNano: buildClock.startUnixNano, endUnixNano: buildClock.endUnixNano(), status: "ok", attributes: { reset, hasPrincipal: principal !== null } });
|
|
368
|
-
}
|
|
369
|
-
return live;
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
export { attach, buildShell, canvasesOf, endShell, layoutsOf, sessionOn, treeOf, wholeShellOf };
|
|
373
|
-
//# sourceMappingURL=chunk-PWUO4RET.js.map
|
|
374
|
-
//# sourceMappingURL=chunk-PWUO4RET.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/shells/host-state.ts","../src/shells/stream.ts","../src/shells/sessions.ts","../src/shells/build.ts"],"names":["declared","config"],"mappings":";;;;;;AAWO,IAAM,SAAA,GAAY,CAAC,IAAA,MAAuF;AAAA,EAC/G,GAAI,KAAK,KAAA,KAAU,MAAA,GAAY,EAAE,KAAA,EAAO,IAAA,CAAK,KAAA,EAAM,GAAI,EAAC;AAAA,EACxD,WAAA,EAAa,IAAA,CAAK,WAAA,IAAe,EAAC;AAAA,EAClC,SAAA,EAAW,IAAA,CAAK,SAAA,IAAa;AAC/B,CAAA;AAmBO,IAAM,UAAA,GAAa,CAAC,IAAA,KAAyB,MAAA,CAAO,KAAK,IAAA,CAAK,KAAA,CAAM,QAAA,EAAS,CAAE,QAAQ;AA4BvF,IAAM,QAAA,GAAW,CAAC,IAAA,EAAiB,IAAA,KAAqB;AAC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,EAAS,GAAA,EAAK,KAAA,EAAO,IAAA,CAAK,KAAA,EAAO,IAAA,EAAM,GAAG,OAAO,CAAA;AAC/F,EAAA,MAAA,CAAO,MAAM,KAAK,CAAA;AAElB,EAAA,IAAI,IAAA,KAAS,MAAA,IAAa,UAAA,KAAe,MAAA,EAAW;AAClD,IAAA,IAAA,CAAK,EAAE,IAAA,EAAM,aAAA,EAAe,eAAe,UAAA,CAAW,aAAA,EAAe,aAAa,UAAA,CAAW,WAAA,IAAe,MAAA,EAAQ,IAAA,EAAM,YAAY,EAAE,KAAA,EAAO,cAAc,SAAA,KAAc,IAAA,IAAQ,CAAA;AAAA,EACrL;AAEA,EAAA,OAAO,IAAA;AACT","file":"chunk-PWUO4RET.js","sourcesContent":["import type { ActionFragment, LayoutNode, Shell } from '@niscorp/nova';\nimport type { SeedEntry, SeedMutation } from '@niscorp/vex';\nimport type { Emit } from '../runtime';\nimport type { ShellComposition, ShellConnection, ShellHostConfig, ShellOpening } from './types';\n\nexport type ShellLayouts = {\n frame?: LayoutNode;\n layoutStore: Readonly<Record<string, LayoutNode>>;\n fragments: Readonly<Record<string, ActionFragment>>;\n};\n\nexport const layoutsOf = (made: Pick<ShellComposition, 'frame' | 'layoutStore' | 'fragments'>): ShellLayouts => ({\n ...(made.frame !== undefined ? { frame: made.frame } : {}),\n layoutStore: made.layoutStore ?? {},\n fragments: made.fragments ?? {},\n});\n\nexport type Live = {\n shell: Shell;\n sessionShell: Shell;\n actionIds: ReadonlySet<string>;\n entries: ReadonlyMap<string, SeedEntry | SeedMutation> | undefined;\n layouts: ShellLayouts;\n connections: Set<ShellConnection>;\n sentByCanvas: Map<string, string>;\n sentFrame?: string;\n deltaReady: Set<ShellConnection>;\n flushing: boolean;\n ended: boolean;\n builtAt: number;\n idleSince: number | null;\n seeded: Promise<void>;\n};\n\nexport const canvasesOf = (live: Live): string[] => Object.keys(live.shell.getState().canvases);\n\n// Every holder addresses a shell through its cell, so a reset that replaces\n// `live` reaches them all.\nexport type Cell = {\n live: Live;\n token: string | null;\n principal: string | null;\n opening?: ShellOpening;\n resetting?: Promise<void>;\n // How many of the host's changes its shell reflects.\n changes: number;\n};\n\nexport type HostState = {\n config: ShellHostConfig;\n emit: Emit | undefined;\n kept: boolean;\n delta: boolean;\n durable: Map<string, Cell>;\n building: Map<string, Promise<Cell>>;\n living: Map<Live, Cell>;\n // How many times what is in force has changed since the host was made.\n changes: number;\n};\n\n// Disposing stays with the caller: the shell of a session that signs out\n// nobody is disposed when its last terminal leaves.\nexport const endShell = (host: HostState, live: Live): void => {\n live.ended = true;\n host.living.delete(live);\n};\n","import { canvasTreeOf } from '@niscorp/nova';\nimport type { RenderNode } from '@niscorp/nova';\nimport { encodeDelta, frameHash } from '../protocol';\nimport type { ServerMessage } from '../protocol';\nimport { canvasesOf } from './host-state';\nimport type { Live } from './host-state';\nimport type { ShellConnection } from './types';\n\nexport const treeOf = (live: Live, canvasId: string): RenderNode[] => canvasTreeOf(live.shell, canvasId);\n\nconst canvasMessage = (live: Live, canvasId: string): string => {\n const message: ServerMessage = { type: 'render', canvas: canvasId, tree: treeOf(live, canvasId) };\n return JSON.stringify(message);\n};\n\nexport const canvasMessageOf = (live: Live, canvasId: string): string | null => {\n try {\n return canvasMessage(live, canvasId);\n } catch (error) {\n console.error(`[moss/shells] canvas \"${canvasId}\" failed to render — holding its last tree:`, error);\n return null;\n }\n};\n\n// A delta has to be decisively smaller: the transport compresses both, and a\n// delta still costs the terminal a rebuild and a checksum.\nconst DELTA_CEILING = 0.6;\n\n// The encode costs by the size of the frames, not of the change, on the thread\n// every session shares: a longer frame goes whole.\nconst DELTA_MAX_FRAME = 64 * 1024;\n\nconst shorterAsDelta = (previous: string, next: string, canvasId: string): string | null => {\n if (previous.length > DELTA_MAX_FRAME || next.length > DELTA_MAX_FRAME) return null;\n try {\n const ops = encodeDelta(previous, next);\n const message: ServerMessage = { type: 'render-delta', canvas: canvasId, ops, hash: frameHash(next) };\n const text = JSON.stringify(message);\n return text.length <= next.length * DELTA_CEILING ? text : null;\n } catch (error) {\n console.error(`[moss/shells] canvas \"${canvasId}\" failed to encode as a delta — sending it whole:`, error);\n return null;\n }\n};\n\nconst pass = (live: Live, delta: boolean): void => {\n if (live.ended) return;\n const canvases = canvasesOf(live);\n for (const gone of [...live.sentByCanvas.keys()].filter((canvasId) => !canvases.includes(canvasId))) {\n live.sentByCanvas.delete(gone);\n const empty = JSON.stringify({ type: 'render', canvas: gone, tree: [] } satisfies ServerMessage);\n for (const connection of live.connections) connection.send(empty);\n }\n for (const canvasId of canvases) {\n const next = canvasMessageOf(live, canvasId);\n const previous = live.sentByCanvas.get(canvasId);\n if (next === null || previous === next) continue;\n live.sentByCanvas.set(canvasId, next);\n const short = delta && previous !== undefined && live.deltaReady.size > 0 ? shorterAsDelta(previous, next, canvasId) : null;\n for (const connection of live.connections) {\n connection.send(short !== null && live.deltaReady.has(connection) ? short : next);\n }\n }\n // The frame goes after the canvases, so one that references a canvas rendered\n // in this pass finds its tree already delivered.\n let frame: string | undefined;\n try {\n frame = JSON.stringify({ type: 'frame', tree: live.shell.getShellRenderTree() } satisfies ServerMessage);\n } catch (error) {\n console.error('[moss/shells] the shell frame failed to render on a flush — leaving the last one in place:', error);\n }\n if (frame !== undefined && frame !== live.sentFrame) {\n live.sentFrame = frame;\n for (const connection of live.connections) connection.send(frame);\n }\n};\n\n// The second pass, a tick later, catches what settles after the last\n// notification (an instance's status, once its loads are in).\nexport const follow = (live: Live, delta: boolean): void => {\n const flush = (): void => {\n if (live.flushing) return;\n live.flushing = true;\n queueMicrotask(() => {\n live.flushing = false;\n pass(live, delta);\n setTimeout(() => pass(live, delta), 0);\n });\n };\n live.shell.onStateChange(flush);\n live.shell.onDataChange(flush);\n};\n\nexport const attach = (live: Live, connection: ShellConnection, wantsDelta: boolean): void => {\n live.connections.add(connection);\n if (wantsDelta) live.deltaReady.add(connection);\n live.idleSince = null;\n let frameTree: RenderNode[] | undefined;\n try {\n frameTree = live.shell.getShellRenderTree();\n } catch (error) {\n console.error('[moss/shells] the shell frame failed to render — serving an empty arrangement:', error);\n }\n const frameMessage = JSON.stringify({ type: 'frame', tree: frameTree ?? [] } satisfies ServerMessage);\n connection.send(frameMessage);\n if (frameTree === undefined) {\n delete live.sentFrame;\n } else {\n // Attaching renders, and can pick up a change no pass has sent yet. The\n // baseline then moves, so the others are sent it too: a pass would find\n // nothing changed. The canvases below do the same, and a delta relies on it.\n if (live.sentFrame !== frameMessage) {\n for (const other of live.connections) if (other !== connection) other.send(frameMessage);\n }\n live.sentFrame = frameMessage;\n }\n for (const canvasId of canvasesOf(live)) {\n const next = canvasMessageOf(live, canvasId);\n if (next === null) continue;\n if (live.sentByCanvas.get(canvasId) !== next) {\n for (const other of live.connections) if (other !== connection) other.send(next);\n }\n live.sentByCanvas.set(canvasId, next);\n connection.send(next);\n }\n};\n\n// What `sentByCanvas` holds, not a fresh render: the connection ends level with the\n// baseline the others share, and stays delta-capable.\nexport const resync = (live: Live, connection: ShellConnection): void => {\n if (!live.connections.has(connection)) return;\n let frameTree: RenderNode[] = [];\n try {\n frameTree = live.shell.getShellRenderTree();\n } catch (error) {\n console.error('[moss/shells] the shell frame failed to render on resync — serving an empty arrangement:', error);\n }\n connection.send(JSON.stringify({ type: 'frame', tree: frameTree } satisfies ServerMessage));\n for (const canvasId of canvasesOf(live)) {\n const current = live.sentByCanvas.get(canvasId) ?? canvasMessageOf(live, canvasId);\n if (current === null || current === undefined) continue;\n connection.send(current);\n }\n};\n","import { NovaEventSchema } from '@niscorp/nova';\nimport type { FetchFn, FunctionHandler, Shell } from '@niscorp/nova';\nimport type { FunctionSession } from '../manifest';\nimport { CLOSE_SIGNED_OUT } from '../protocol';\nimport type { ServerMessage } from '../protocol';\nimport { spanClock } from '../runtime';\nimport type { Emit } from '../runtime';\nimport { endShell } from './host-state';\nimport type { Cell, HostState, Live } from './host-state';\nimport { attach, resync } from './stream';\nimport type { ShellSession } from './types';\n\nexport const instrumentFunctions = (\n fns: Record<string, FunctionHandler>,\n emit: Emit,\n principal: string | null,\n): Record<string, FunctionHandler> =>\n Object.fromEntries(\n Object.entries(fns).map(([name, handler]): [string, FunctionHandler] => [\n name,\n async (data, signal) => {\n const clock = spanClock();\n const hasPrincipal = principal !== null;\n try {\n const out = await handler(data, signal);\n emit({ name: 'fn.call', startUnixNano: clock.startUnixNano, endUnixNano: clock.endUnixNano(), status: 'ok', attributes: { fn: name, hasPrincipal } });\n return out;\n } catch (err) {\n emit({ name: 'fn.call', startUnixNano: clock.startUnixNano, endUnixNano: clock.endUnixNano(), status: 'error', attributes: { fn: name, hasPrincipal } });\n throw err;\n }\n },\n ]),\n );\n\nexport type ShellRef = { shell?: Shell; sessionShell?: Shell; live?: Live };\n\nconst grant = (shellRef: ShellRef, token: string): void => {\n const message = JSON.stringify({ type: 'session', token } satisfies ServerMessage);\n for (const connection of shellRef.live?.connections ?? []) {\n if (connection.seal === undefined) connection.send(message);\n else {\n void connection.seal(token).then(\n (sealed) => connection.send(JSON.stringify({ type: 'session', sealed } satisfies ServerMessage)),\n (error: unknown) => console.error('[moss] a sign-in could not be sealed, and was not handed over:', error),\n );\n }\n }\n};\n\n// The teardown waits a microtask, so the trigger that called this finishes\n// before its own shell is disposed.\nconst revoke = (host: HostState, shellRef: ShellRef, principal: string | null): Promise<void> => {\n const { config, durable } = host;\n const forgotten = config.revokeSessions !== undefined && principal !== null ? config.revokeSessions(principal) : Promise.resolve();\n // Logged here, so a caller that does not await leaves no unhandled rejection;\n // one that does still sees the failure.\n forgotten.catch((error: unknown) => console.error(`[moss] sign-out of ${principal ?? 'anonymous'} did not revoke its sessions:`, error));\n queueMicrotask(() => {\n const live = shellRef.live;\n if (live === undefined) return;\n endShell(host, live);\n // Only while the map still holds this shell: a reset since the sign-out\n // has put another in its cell.\n if (principal !== null && durable.get(principal)?.live === live) durable.delete(principal);\n for (const connection of [...live.connections]) connection.close(CLOSE_SIGNED_OUT, 'signed out');\n live.connections.clear();\n if (principal !== null) live.shell.dispose();\n });\n return forgotten;\n};\n\nexport const functionSessionFor = (\n host: HostState,\n who: { principal: string | null; roles: readonly string[]; scope: Record<string, unknown>; actions: readonly string[] },\n wire: FetchFn,\n shellRef: ShellRef,\n): FunctionSession => {\n const { config } = host;\n const { principal } = who;\n const session: FunctionSession = {\n principal,\n roles: who.roles,\n identity: who.scope,\n actions: who.actions,\n wire,\n get shell(): Shell {\n if (shellRef.sessionShell === undefined) throw new Error('moss: a function touched the shell before the session finished building.');\n return shellRef.sessionShell;\n },\n grant: (token) => grant(shellRef, token),\n revoke: () => revoke(host, shellRef, principal),\n answerIntent: (writers, asked) =>\n config.answerIntent === undefined\n ? Promise.reject(new Error('moss: this shell host was given no way to answer an intent.'))\n : config.answerIntent(principal, writers, asked),\n recordRun: (run) => {\n config.hooks.runs?.({ ...run, at: Date.now(), principal, shellId: shellRef.shell?.id ?? '' }, session);\n },\n };\n return session;\n};\n\nexport const sessionOn = (host: HostState, cell: Cell, ephemeral: boolean, reset: (cell: Cell) => void): ShellSession => ({\n get shell(): Shell {\n return cell.live.sessionShell;\n },\n attach: (connection, options) => attach(cell.live, connection, host.delta && options?.delta === true),\n resync: (connection) => resync(cell.live, connection),\n detach: (connection) => {\n const live = cell.live;\n live.connections.delete(connection);\n live.deltaReady.delete(connection);\n if (live.connections.size > 0) return;\n live.idleSince = Date.now();\n if (!ephemeral) return;\n endShell(host, live);\n live.shell.dispose();\n },\n // An event without an origin goes to every instance of the shell, so one for\n // a canvas the shell does not have is dropped. An origin a terminal names\n // comes off the wire and is held to that canvas; with none named, the\n // canvas's active instance is the origin.\n dispatch: (canvas, event) => {\n const { shell } = cell.live;\n const state = shell.getState().canvases[canvas];\n if (state === undefined) return;\n const claimed = event['origin'];\n if (claimed !== undefined && (typeof claimed !== 'string' || !state.stack.some((item) => item.id === claimed))) return;\n const active = state.active;\n const parsed = NovaEventSchema.safeParse(claimed !== undefined || active === undefined ? event : { ...event, origin: active.id });\n if (parsed.success) shell.dispatch(parsed.data);\n },\n publish: (channel, payload) => cell.live.shell.publish(channel, payload),\n back: () => cell.live.shell.back(),\n popTo: (canvas: string, instance: string) => cell.live.shell.popTo(canvas, instance),\n reset: () => reset(cell),\n});\n","import { createComponentRegistry, createLayoutStore, createShell } from '@niscorp/nova';\nimport type { CanvasConfig, Shell } from '@niscorp/nova';\nimport { evaluate } from '@niscorp/prism';\nimport type { CanvasSeed, ShellCanvas } from '../manifest';\nimport { spanClock } from '../runtime';\nimport { functionSessionFor, instrumentFunctions } from './sessions';\nimport type { ShellRef } from './sessions';\nimport { layoutsOf } from './host-state';\nimport type { HostState, Live } from './host-state';\nimport { follow } from './stream';\nimport type { ShellOpening } from './types';\n\nconst whole = new WeakMap<Shell, Shell>();\n\nconst refuse =\n (member: string) =>\n (): never => {\n throw new Error(\n `moss: ${member} was called on a session's shell. It changes what the shell is made of without moss: ` +\n 'what it adds is not verified, is in nobody\\'s catalog, and is gone when the shell is rebuilt. ' +\n 'Code that means to do that takes the whole shell: `unverifiedShell(session)`, from `@niscorp/moss/unverified`.',\n );\n };\n\nconst sessionShellOf = (shell: Shell): Shell => {\n const guarded: Shell = {\n ...shell,\n registerAction: refuse('registerAction'),\n removeAction: refuse('removeAction'),\n registerFragment: refuse('registerFragment'),\n addCanvas: refuse('addCanvas'),\n removeCanvas: refuse('removeCanvas'),\n setCanvasLayout: refuse('setCanvasLayout'),\n setLayout: refuse('setLayout'),\n setPhrases: refuse('setPhrases'),\n dispose: refuse('dispose'),\n };\n whole.set(guarded, shell);\n whole.set(shell, shell);\n return guarded;\n};\n\nexport const wholeShellOf = (sessionShell: Shell): Shell => {\n const shell = whole.get(sessionShell);\n if (shell === undefined) throw new Error('moss: this is not the shell of a session moss built.');\n return shell;\n};\n\nconst today = (): string => new Date().toISOString().slice(0, 10);\n\nconst mountedCanvases = (\n declared: readonly ShellCanvas[],\n granted: ReadonlySet<string>,\n inputs: Record<string, Record<string, unknown>>,\n given: ShellOpening['inputs'],\n): CanvasConfig[] =>\n declared.map((canvas) => {\n const declared = canvas.initial;\n const candidates = declared === undefined ? [] : Array.isArray(declared) ? declared : [declared];\n const seed = candidates.find((c) => granted.has(typeof c === 'string' ? c : c.action));\n if (seed === undefined) {\n const { initial: _dropped, ...rest } = canvas;\n return rest;\n }\n const action = typeof seed === 'string' ? seed : seed.action;\n const staticInput = typeof seed === 'string' ? {} : (seed.input ?? {});\n const withFragments = typeof seed === 'string' ? undefined : seed.with;\n return {\n ...canvas,\n initial: { action, input: { ...staticInput, ...(inputs[canvas.id] ?? {}), ...(given?.[canvas.id] ?? {}) }, ...(withFragments !== undefined ? { with: withFragments } : {}) },\n };\n });\n\nconst seedCanvases = (\n live: Live,\n declaredSeeds: Promise<Record<string, CanvasSeed[]>> | Record<string, CanvasSeed[]> | undefined,\n granted: ReadonlySet<string>,\n): void => {\n if (declaredSeeds === undefined) return;\n live.seeded = Promise.resolve(declaredSeeds)\n .then((byCanvas) => {\n if (live.ended) return;\n for (const [canvasId, seeds] of Object.entries(byCanvas ?? {})) {\n for (const seed of seeds) {\n const action = typeof seed === 'string' ? seed : seed.action;\n if (!granted.has(action)) continue;\n const input = typeof seed === 'string' ? undefined : seed.input;\n const withFragments = typeof seed === 'string' ? undefined : seed.with;\n try {\n // Not a navigation: `back` must not undo the screen somebody arrives on.\n live.shell.push(canvasId, action, input, withFragments, { history: false });\n } catch (error) {\n console.error(`[moss/shells] the seed \"${action}\" on canvas \"${canvasId}\" could not be pushed, and was skipped:`, error);\n }\n }\n }\n })\n .catch((error: unknown) => {\n console.error('[moss/shells] the seeds of a shell could not be derived, and none was pushed:', error);\n });\n};\n\nexport type BuildRequest = {\n token: string | null;\n principal: string | null;\n opening?: ShellOpening;\n reset: boolean;\n wanted: () => boolean;\n};\n\nexport const buildShell = async (host: HostState, asked: BuildRequest): Promise<Live | undefined> => {\n const { config, emit, kept, delta } = host;\n const { hooks } = config;\n const { token, principal, opening, reset, wanted } = asked;\n const buildClock = emit === undefined ? undefined : spanClock();\n const made = await config.composition(principal);\n if (!wanted()) return undefined;\n const ids = Object.keys(made.actions);\n const granted = new Set(ids);\n const inputs = (await hooks.inputs?.({ principal, actions: ids, roles: made.roles, identity: made.scope, wire: config.wire(token) })) ?? {};\n if (!wanted()) return undefined;\n const canvases = mountedCanvases(made.canvases, granted, inputs, opening?.inputs);\n\n const wire = config.wrapWire === undefined ? config.wire(token) : config.wrapWire(config.wire(token));\n const userId = principal ?? 'anonymous';\n\n const registry = createComponentRegistry();\n for (const [name, contract] of Object.entries(made.components)) registry.register(name, contract);\n\n const shellRef: ShellRef = {};\n const session = functionSessionFor(host, { principal, roles: made.roles, scope: made.scope, actions: ids }, wire, shellRef);\n\n const phrases = (await hooks.phrases?.({ principal, identity: made.scope, wire: config.wire(token) })) ?? {};\n if (!wanted()) return undefined;\n\n // No await between here and `shellRef.shell = shell`: app code defers its\n // first touch of `session.shell` by a microtask, which has to find the shell\n // there and still land before the shell's mount calls answer.\n const rawFunctions = hooks.functions?.(session) ?? {};\n const functions = emit === undefined ? rawFunctions : instrumentFunctions(rawFunctions, emit, principal);\n if (kept) hooks.onSession?.(session);\n\n const layoutStore = createLayoutStore();\n for (const [refId, node] of Object.entries(made.layoutStore ?? {})) layoutStore.set(refId, node);\n\n // Two builds from one seed mint the same instance ids: the shell a document\n // was rendered from, and the one the socket builds a moment later for the\n // same visitor.\n let minted = 0;\n const idSeed = opening?.seed;\n const shell = createShell({\n registry,\n canvases,\n layoutStore,\n ...(idSeed === undefined ? {} : { instanceIdFn: () => `act-${idSeed}-${(minted += 1)}` }),\n ...(made.frame !== undefined ? { canvasLayout: made.frame } : {}),\n actions: { ...made.actions },\n ...(made.fragments !== undefined ? { fragments: { ...made.fragments } } : {}),\n transform: (config, source) =>\n evaluate(config, source !== null && typeof source === 'object' && !Array.isArray(source) ? { ...source, userId, today: today() } : source),\n fetch: wire,\n functions,\n ...(config.limits?.endpointTimeoutMs === undefined ? {} : { endpointTimeoutMs: config.limits.endpointTimeoutMs }),\n // An empty book is withheld: nova runs its phrase pass whenever one is given.\n ...(Object.keys(phrases).length === 0 ? {} : { phrases }),\n ...(config.phraseKeys === undefined ? {} : { phraseKeys: config.phraseKeys }),\n });\n const sessionShell = sessionShellOf(shell);\n shellRef.shell = shell;\n shellRef.sessionShell = sessionShell;\n\n const live: Live = {\n shell,\n sessionShell,\n actionIds: granted,\n entries: made.entries,\n layouts: layoutsOf(made),\n connections: new Set(),\n sentByCanvas: new Map(),\n deltaReady: new Set(),\n flushing: false,\n ended: false,\n builtAt: Date.now(),\n idleSince: Date.now(),\n seeded: Promise.resolve(),\n };\n shellRef.live = live;\n\n seedCanvases(live, hooks.seeds?.({ principal, actions: ids, roles: made.roles, wire }), granted);\n follow(live, delta);\n\n if (emit !== undefined && buildClock !== undefined) {\n emit({ name: 'shell.build', startUnixNano: buildClock.startUnixNano, endUnixNano: buildClock.endUnixNano(), status: 'ok', attributes: { reset, hasPrincipal: principal !== null } });\n }\n\n return live;\n};\n"]}
|