@cmodjs/core 8.9.0 → 8.10.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/docs/commands.md +13 -11
- package/docs/dependencies.md +6 -3
- package/docs/index.md +1 -1
- package/docs/jobs.md +1 -1
- package/docs/mod.md +1 -1
- package/docs/session.md +8 -7
- package/docs/testing.md +2 -2
- package/docs/ui.md +6 -5
- package/jobs/program.d.ts.map +1 -1
- package/jobs/program.js +5 -4
- package/mod.d.ts +34 -5
- package/mod.d.ts.map +1 -1
- package/package.json +1 -1
- package/records.d.ts +4 -2
- package/records.d.ts.map +1 -1
- package/records.js +6 -3
- package/register.d.ts.map +1 -1
- package/register.js +14 -5
- package/rpc.d.ts.map +1 -1
- package/rpc.js +1 -0
- package/runtime/bun.d.ts +7 -2
- package/runtime/bun.d.ts.map +1 -1
- package/runtime/bun.js +61 -7
- package/runtime/conversations.d.ts +3 -1
- package/runtime/conversations.d.ts.map +1 -1
- package/runtime/conversations.js +43 -36
- package/runtime/device.d.ts +2 -1
- package/runtime/device.d.ts.map +1 -1
- package/runtime/device.js +22 -1
- package/runtime/drawing-rules.d.ts +9 -0
- package/runtime/drawing-rules.d.ts.map +1 -0
- package/runtime/drawing-rules.js +46 -0
- package/runtime/engine.d.ts +3 -1
- package/runtime/engine.d.ts.map +1 -1
- package/runtime/hooks.d.ts +1 -1
- package/runtime/hooks.d.ts.map +1 -1
- package/runtime/hotkeys.d.ts.map +1 -1
- package/runtime/hotkeys.js +0 -7
- package/runtime/installer.js +3 -3
- package/runtime/interfaces.d.ts +47 -8
- package/runtime/interfaces.d.ts.map +1 -1
- package/runtime/interfaces.js +151 -15
- package/runtime/lifecycle.d.ts.map +1 -1
- package/runtime/lifecycle.js +61 -29
- package/runtime/parts.d.ts +2 -2
- package/runtime/parts.d.ts.map +1 -1
- package/runtime/parts.js +61 -35
- package/runtime/rpc.d.ts +11 -3
- package/runtime/rpc.d.ts.map +1 -1
- package/runtime/rpc.js +56 -19
- package/runtime/sessions.d.ts +2 -1
- package/runtime/sessions.d.ts.map +1 -1
- package/runtime/sessions.js +11 -4
- package/runtime/ui.d.ts +1 -0
- package/runtime/ui.d.ts.map +1 -1
- package/runtime/ui.js +62 -45
- package/runtime/widgets.d.ts +4 -2
- package/runtime/widgets.d.ts.map +1 -1
- package/runtime/widgets.js +6 -5
- package/session/session.d.ts +5 -1
- package/session/session.d.ts.map +1 -1
- package/src/jobs/program.ts +5 -4
- package/src/mod.ts +12 -4
- package/src/records.ts +8 -4
- package/src/register.ts +15 -5
- package/src/rpc.ts +2 -1
- package/src/runtime/bun.ts +58 -6
- package/src/runtime/conversations.ts +45 -36
- package/src/runtime/device.ts +21 -1
- package/src/runtime/drawing-rules.ts +42 -0
- package/src/runtime/engine.ts +3 -1
- package/src/runtime/hooks.ts +0 -1
- package/src/runtime/hotkeys.ts +0 -7
- package/src/runtime/installer.ts +3 -3
- package/src/runtime/interfaces.ts +187 -22
- package/src/runtime/lifecycle.ts +63 -29
- package/src/runtime/parts.ts +61 -33
- package/src/runtime/rpc.ts +65 -20
- package/src/runtime/sessions.ts +11 -5
- package/src/runtime/ui.ts +61 -38
- package/src/runtime/widgets.ts +9 -5
- package/src/session/session.ts +3 -1
- package/src/testing/fake-elements.ts +7 -23
- package/src/testing/fake-serve.ts +51 -9
- package/src/testing/fake-sessions.ts +5 -3
- package/src/testing.ts +9 -3
- package/src/ui/components.ts +13 -14
- package/src/ui/elements.ts +4 -4
- package/src/ui/palette.ts +38 -0
- package/src/ui/styles.ts +2 -0
- package/testing/fake-elements.d.ts.map +1 -1
- package/testing/fake-elements.js +9 -26
- package/testing/fake-serve.d.ts +6 -1
- package/testing/fake-serve.d.ts.map +1 -1
- package/testing/fake-serve.js +42 -5
- package/testing/fake-sessions.d.ts +1 -0
- package/testing/fake-sessions.d.ts.map +1 -1
- package/testing/fake-sessions.js +4 -2
- package/testing.d.ts.map +1 -1
- package/testing.js +12 -4
- package/ui/components.d.ts.map +1 -1
- package/ui/components.js +12 -13
- package/ui/elements.d.ts +2 -1
- package/ui/elements.d.ts.map +1 -1
- package/ui/elements.js +3 -3
- package/ui/palette.d.ts +17 -0
- package/ui/palette.d.ts.map +1 -0
- package/ui/palette.js +20 -0
- package/ui/styles.d.ts +1 -0
- package/ui/styles.d.ts.map +1 -1
- package/ui/styles.js +1 -0
package/runtime/interfaces.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { interfaceName, isObject } from '../records.js';
|
|
2
|
+
import { Note } from '../session/context/turn/message/note.js';
|
|
3
|
+
import { Prompt } from '../session/context/turn/message/prompt.js';
|
|
4
|
+
import { Person } from '../session/context/turn/message/sender.js';
|
|
2
5
|
import { matches, receivedMatcher, sentMatcher } from '../utils/matcher.js';
|
|
3
6
|
import { messageOf } from '../utils/text.js';
|
|
4
7
|
import { beforeDeadline, callDeadline, hookMs, listenerMs, listenerOf } from './deadline.js';
|
|
@@ -29,6 +32,9 @@ export const terminalInterface = 'cmod/Terminal';
|
|
|
29
32
|
export const providersInterface = 'cmod/Providers';
|
|
30
33
|
export const terminalPlaces = ['focus', 'peek', 'tab', 'right', 'down', 'hide'];
|
|
31
34
|
const terminalEvents = ['Shown', 'Pressed'];
|
|
35
|
+
export const storeInterface = 'cmod/Store';
|
|
36
|
+
export const storeParts = ['plugins', 'widgets', 'buildFailures', 'preferences', 'links'];
|
|
37
|
+
export const programsInterface = 'cmod/Programs';
|
|
32
38
|
export const interfaceMethods = { providers: 'cmod:providers', provider: 'cmod:provider', provided: 'cmod:provided', listen: 'cmod:listenProvided', unlisten: 'cmod:unlistenProvided', tell: 'cmod:tellProvided', ask: 'cmod:askProvided', heard: 'cmod:heard' };
|
|
33
39
|
export const providerActs = { provide: '$/provide', unprovide: '$/unprovide', providers: '$/providers', provider: '$/provider', call: '$/call', link: '$/link' };
|
|
34
40
|
export const providerHoldMs = hookMs / 4;
|
|
@@ -136,13 +142,17 @@ export function interfaceListeners({ report: reportAll }) {
|
|
|
136
142
|
if (!isConnectionGone(error))
|
|
137
143
|
reportAll(error);
|
|
138
144
|
};
|
|
139
|
-
const send = (request, each) => request.request(listenMethod, { ...each.listening, ...(each.cursor === undefined ? {} : { after: each.cursor }) })
|
|
140
|
-
|
|
145
|
+
const send = (request, each) => request.request(listenMethod, { ...each.listening, ...(each.cursor === undefined ? {} : { after: each.cursor }) }).then(() => void (each.isPending = false), (error) => {
|
|
146
|
+
each.isPending = error instanceof RpcError && error.code === rpcCodes.notProvided;
|
|
147
|
+
if (!each.isPending)
|
|
148
|
+
report(error);
|
|
149
|
+
});
|
|
150
|
+
const listeners = {
|
|
141
151
|
listen(request, listening, listener) {
|
|
142
152
|
const id = `${(next += 1)}`;
|
|
143
|
-
const each = { listening: { ...listening, id }, listener, cursor: undefined };
|
|
153
|
+
const each = { listening: { ...listening, id }, listener, cursor: undefined, isPending: false };
|
|
144
154
|
registered.set(id, each);
|
|
145
|
-
void send(request, each)
|
|
155
|
+
void send(request, each);
|
|
146
156
|
return {
|
|
147
157
|
remove() {
|
|
148
158
|
if (!registered.delete(id))
|
|
@@ -167,9 +177,15 @@ export function interfaceListeners({ report: reportAll }) {
|
|
|
167
177
|
return (async () => ({ result: (await each.listener(heard.payload, signal)) ?? null }))();
|
|
168
178
|
},
|
|
169
179
|
async replay(request) {
|
|
170
|
-
await Promise.all([...registered.values()].map((each) => send(request, each)
|
|
180
|
+
await Promise.all([...registered.values()].map((each) => send(request, each)));
|
|
171
181
|
},
|
|
182
|
+
followProviders: (request) => listeners.listen(request, listeningOf(providersInterface, 'on', 'Change', [], undefined), (told) => {
|
|
183
|
+
for (const each of registered.values())
|
|
184
|
+
if (each.isPending && each.listening.interface === told.interface)
|
|
185
|
+
void send(request, each);
|
|
186
|
+
}),
|
|
172
187
|
};
|
|
188
|
+
return listeners;
|
|
173
189
|
}
|
|
174
190
|
export function listeningOf(name, kind, event, args, matcher, options = {}) {
|
|
175
191
|
return {
|
|
@@ -199,9 +215,9 @@ export function providerClient(name, identity, call, listen) {
|
|
|
199
215
|
},
|
|
200
216
|
});
|
|
201
217
|
}
|
|
202
|
-
export const sessionActions = ['send', 'abort', 'end', 'fork', 'startTask', 'callTool', 'usage', 'surfaces', 'visit', 'delete', 'compact', 'startBackgroundTask'
|
|
218
|
+
export const sessionActions = ['send', 'abort', 'end', 'fork', 'startTask', 'callTool', 'usage', 'surfaces', 'visit', 'delete', 'compact', 'startBackgroundTask'];
|
|
203
219
|
export const showLeaseMs = 16_000;
|
|
204
|
-
export function routeSessions({ computer, device, now, after, report, aliases = [], programs, terminals, }) {
|
|
220
|
+
export function routeSessions({ computer, device, now, after, report, aliases = [], programs, terminals, onListen = () => undefined, }) {
|
|
205
221
|
const holders = new Map();
|
|
206
222
|
const holderOf = (session) => [...holders.values()].find((holder) => holder.session === session);
|
|
207
223
|
const toldAt = () => new Map([...holders.values()].map((holder) => [holder.session, holder.toldAt]));
|
|
@@ -214,6 +230,24 @@ export function routeSessions({ computer, device, now, after, report, aliases =
|
|
|
214
230
|
for (const name of names)
|
|
215
231
|
interfaces.emit(name, 'Change', change, [change.session]);
|
|
216
232
|
};
|
|
233
|
+
const store = {
|
|
234
|
+
changed: (part) => {
|
|
235
|
+
if (!storeParts.includes(part))
|
|
236
|
+
throw new RpcError(rpcCodes.invalidParams, `${storeInterface}.changed takes the part a writer stored: ${storeParts.join(', ')}.`);
|
|
237
|
+
interfaces.emit(storeInterface, 'Change', { part: part });
|
|
238
|
+
return null;
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
const programChanges = {
|
|
242
|
+
changed: async (mod, program) => {
|
|
243
|
+
if (typeof mod !== 'string' || typeof program !== 'string')
|
|
244
|
+
throw new RpcError(rpcCodes.invalidParams, `${programsInterface}.changed takes the mod and the program whose instance file changed.`);
|
|
245
|
+
interfaces.emit(programsInterface, 'Change', { mod, program });
|
|
246
|
+
await providers.programChanged(mod, program);
|
|
247
|
+
return null;
|
|
248
|
+
},
|
|
249
|
+
};
|
|
250
|
+
const isServed = (name) => name === storeInterface || name === programsInterface;
|
|
217
251
|
const call = async (session, action, input, context = {}) => {
|
|
218
252
|
if (!sessionActions.includes(action))
|
|
219
253
|
throw new RpcError(rpcCodes.methodNotFound, `A session takes no ${action}.`);
|
|
@@ -229,6 +263,8 @@ export function routeSessions({ computer, device, now, after, report, aliases =
|
|
|
229
263
|
changed({ session, part: 'deleted' });
|
|
230
264
|
return null;
|
|
231
265
|
}
|
|
266
|
+
if (action === 'send' && context['task'] === undefined)
|
|
267
|
+
return send(session, input, context);
|
|
232
268
|
const holder = holderOf(session);
|
|
233
269
|
if (holder !== undefined)
|
|
234
270
|
return holder.connection.request(sessionActs.act, { action, input, ...context });
|
|
@@ -253,6 +289,60 @@ export function routeSessions({ computer, device, now, after, report, aliases =
|
|
|
253
289
|
}
|
|
254
290
|
return undefined;
|
|
255
291
|
};
|
|
292
|
+
const chains = new Map();
|
|
293
|
+
const refused = new Set();
|
|
294
|
+
const inOrder = (session, work) => {
|
|
295
|
+
const run = Promise.allSettled([chains.get(session)]).then(work);
|
|
296
|
+
chains.set(session, run);
|
|
297
|
+
void Promise.allSettled([run]).then(() => chains.get(session) === run && chains.delete(session));
|
|
298
|
+
return run;
|
|
299
|
+
};
|
|
300
|
+
const deliver = (session, resumes) => inOrder(session, async () => {
|
|
301
|
+
const done = [];
|
|
302
|
+
for (const mail of await computer.queued(session)) {
|
|
303
|
+
const holder = holderOf(session);
|
|
304
|
+
if (holder === undefined && (!resumes || done.length > 0))
|
|
305
|
+
break;
|
|
306
|
+
const sent = { type: mail.type, text: labelledText(mail), ...(mail.asUser ? { as: Person } : {}) };
|
|
307
|
+
const context = mail.caller === undefined ? {} : { caller: mail.caller };
|
|
308
|
+
try {
|
|
309
|
+
await (holder === undefined ? computer.unheld(session, 'send', sent, context, holding) : holder.connection.request(sessionActs.act, { action: 'send', input: sent, ...context }));
|
|
310
|
+
}
|
|
311
|
+
catch (error) {
|
|
312
|
+
if (!refused.has(mail.id))
|
|
313
|
+
report(error);
|
|
314
|
+
refused.add(mail.id);
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
refused.delete(mail.id);
|
|
318
|
+
await computer.delivered(mail.id, new Date(now()).toISOString());
|
|
319
|
+
done.push(mail.id);
|
|
320
|
+
}
|
|
321
|
+
return done;
|
|
322
|
+
});
|
|
323
|
+
const unheldSession = async (session) => {
|
|
324
|
+
const runner = await runnerElsewhere(session);
|
|
325
|
+
if (runner !== undefined)
|
|
326
|
+
throw new RpcError(rpcCodes.notHeld, `Session ${session} runs on ${runner}, so this computer takes no send for it.`);
|
|
327
|
+
const found = await computer.session(session, holding, toldAt());
|
|
328
|
+
if (found === undefined)
|
|
329
|
+
throw new RpcError(rpcCodes.notHeld, `No session ${session} on this computer.`);
|
|
330
|
+
return found;
|
|
331
|
+
};
|
|
332
|
+
const send = async (session, input, context) => {
|
|
333
|
+
const sent = sentMail(input);
|
|
334
|
+
const found = holderOf(session) === undefined ? await unheldSession(session) : undefined;
|
|
335
|
+
const caller = typeof context['caller'] === 'string' ? { caller: context['caller'] } : {};
|
|
336
|
+
const id = await computer.queue({ session, ...sent, ...caller, sentAt: new Date(now()).toISOString() });
|
|
337
|
+
const done = await deliver(session, found?.isRunning === false);
|
|
338
|
+
return { id, state: done.includes(id) ? 'delivered' : 'queued' };
|
|
339
|
+
};
|
|
340
|
+
const readMail = async (session, options) => {
|
|
341
|
+
const kept = await computer.mail(session, typeof options['last'] === 'number' ? { last: options['last'] } : {});
|
|
342
|
+
if (kept.length > 0 || holderOf(session) !== undefined || (await computer.session(session, holding, toldAt())) !== undefined)
|
|
343
|
+
return kept;
|
|
344
|
+
throw new RpcError(rpcCodes.notHeld, `No session ${session} on this computer.`);
|
|
345
|
+
};
|
|
256
346
|
const withStatus = (listed, told) => {
|
|
257
347
|
if (told === undefined)
|
|
258
348
|
return listed;
|
|
@@ -271,6 +361,8 @@ export function routeSessions({ computer, device, now, after, report, aliases =
|
|
|
271
361
|
},
|
|
272
362
|
search: (text, options = {}) => computer.search(text, options),
|
|
273
363
|
read: async (session, part, options = {}) => {
|
|
364
|
+
if (part === 'mail')
|
|
365
|
+
return readMail(session, options);
|
|
274
366
|
const saved = await computer.read(session, part, options, holding);
|
|
275
367
|
const holder = holderOf(session);
|
|
276
368
|
if (part !== 'tasks' || holder === undefined)
|
|
@@ -364,7 +456,7 @@ export function routeSessions({ computer, device, now, after, report, aliases =
|
|
|
364
456
|
},
|
|
365
457
|
};
|
|
366
458
|
const interfaces = interfaceServer({
|
|
367
|
-
implementations: { ...Object.fromEntries(names.map((name) => [name, implementation])), [uiInterface]: ui, [providersInterface]: {}, ...(terminal === undefined ? {} : { [terminalInterface]: terminal }) },
|
|
459
|
+
implementations: { ...Object.fromEntries(names.map((name) => [name, implementation])), [uiInterface]: ui, [providersInterface]: {}, [storeInterface]: store, [programsInterface]: programChanges, ...(terminal === undefined ? {} : { [terminalInterface]: terminal }) },
|
|
368
460
|
onListen: (_connection, listening) => {
|
|
369
461
|
if (listening.interface === uiInterface) {
|
|
370
462
|
if (!uiEvents.includes(listening.event))
|
|
@@ -377,7 +469,8 @@ export function routeSessions({ computer, device, now, after, report, aliases =
|
|
|
377
469
|
return;
|
|
378
470
|
}
|
|
379
471
|
if (listening.event !== 'Change')
|
|
380
|
-
throw new RpcError(rpcCodes.methodNotFound, listening.interface === providersInterface ? `${
|
|
472
|
+
throw new RpcError(rpcCodes.methodNotFound, listening.interface === providersInterface || isServed(listening.interface) ? `${listening.interface} tells only Change.` : `${listening.interface} tells only Change, because a mod hears only the session it runs in.`);
|
|
473
|
+
after(0, () => onListen(listening));
|
|
381
474
|
},
|
|
382
475
|
extraMethod: (connection, method, params) => {
|
|
383
476
|
if (method === sessionActs.uiEvent) {
|
|
@@ -398,6 +491,7 @@ export function routeSessions({ computer, device, now, after, report, aliases =
|
|
|
398
491
|
relisted(session);
|
|
399
492
|
toldShown.delete(session);
|
|
400
493
|
tellShown(session);
|
|
494
|
+
void deliver(session, false).catch(report);
|
|
401
495
|
return { result: {} };
|
|
402
496
|
}
|
|
403
497
|
if (method === sessionActs.changed) {
|
|
@@ -426,7 +520,7 @@ export function routeSessions({ computer, device, now, after, report, aliases =
|
|
|
426
520
|
interfaces.emit(providersInterface, 'Change', { interface: each, device: at });
|
|
427
521
|
}
|
|
428
522
|
})().catch(report);
|
|
429
|
-
const providers = routeProviders({ isOwn: (name) => names.includes(name) || name === uiInterface || name === providersInterface || (terminal !== undefined && name === terminalInterface), listsSelf: (name) => name === providersInterface || (terminal !== undefined && name === terminalInterface), changed: providersChanged, own: (connection) => interfaces.handler(connection), device, report, channel: (send) => routes.channel(send), ...(programs === undefined ? {} : { programs }) });
|
|
523
|
+
const providers = routeProviders({ isOwn: (name) => names.includes(name) || name === uiInterface || name === providersInterface || isServed(name) || (terminal !== undefined && name === terminalInterface), listsSelf: (name) => name === providersInterface || isServed(name) || (terminal !== undefined && name === terminalInterface), changed: providersChanged, own: (connection) => interfaces.handler(connection), device, report, channel: (send) => routes.channel(send), ...(programs === undefined ? {} : { programs }) });
|
|
430
524
|
const routes = rpcRoutes({
|
|
431
525
|
handle: (connection) => {
|
|
432
526
|
const own = interfaces.handler(connection);
|
|
@@ -446,6 +540,7 @@ export function routeSessions({ computer, device, now, after, report, aliases =
|
|
|
446
540
|
if (Object.keys(holder.told).length > 0)
|
|
447
541
|
changed({ session: holder.session, part: 'status' });
|
|
448
542
|
},
|
|
543
|
+
onUnpolled: (connection) => providers.unpolled(connection),
|
|
449
544
|
now,
|
|
450
545
|
});
|
|
451
546
|
return {
|
|
@@ -462,6 +557,25 @@ export function routeSessions({ computer, device, now, after, report, aliases =
|
|
|
462
557
|
},
|
|
463
558
|
};
|
|
464
559
|
}
|
|
560
|
+
function sentMail(input) {
|
|
561
|
+
const { type, text, from, replyTo, as } = (isObject(input) ? input : {});
|
|
562
|
+
if (type !== Prompt && type !== Note)
|
|
563
|
+
throw new RpcError(rpcCodes.invalidParams, `send takes a type, ${Prompt} or ${Note}.`);
|
|
564
|
+
if (typeof text !== 'string' || text.trim() === '')
|
|
565
|
+
throw new RpcError(rpcCodes.invalidParams, 'send needs text.');
|
|
566
|
+
if (from !== undefined && !(isObject(from) && typeof from['session'] === 'string' && from['session'] !== '' && typeof from['title'] === 'string'))
|
|
567
|
+
throw new RpcError(rpcCodes.invalidParams, 'send takes from as { session, title }, the session that sends it.');
|
|
568
|
+
if (replyTo !== undefined && !Number.isInteger(replyTo))
|
|
569
|
+
throw new RpcError(rpcCodes.invalidParams, 'send takes replyTo as the id of the mail it answers.');
|
|
570
|
+
return { type, text, ...(isObject(from) ? { from: String(from['session']), fromTitle: String(from['title']) } : {}), ...(typeof replyTo === 'number' ? { replyTo } : {}), asUser: as === Person };
|
|
571
|
+
}
|
|
572
|
+
function labelledText(mail) {
|
|
573
|
+
if (mail.from === undefined)
|
|
574
|
+
return mail.text;
|
|
575
|
+
const quoted = (value) => value.replaceAll('&', '&').replaceAll('"', '"').replaceAll('<', '<').replaceAll('>', '>');
|
|
576
|
+
const replyTo = mail.replyTo === undefined ? '' : ` reply-to="${mail.replyTo}"`;
|
|
577
|
+
return `<cmod-message from="${quoted(mail.from)}" title="${quoted(mail.fromTitle ?? '')}" reply="cmod sessions send ${quoted(mail.from.slice(0, 8))} --reply-to ${mail.id}"${replyTo}>\n${mail.text}\n</cmod-message>`;
|
|
578
|
+
}
|
|
465
579
|
export function providerPeer(serve, identity) {
|
|
466
580
|
return {
|
|
467
581
|
request: (method, params, signal) => {
|
|
@@ -481,6 +595,13 @@ export function routeProviders({ isOwn, listsSelf, own, device, report, channel,
|
|
|
481
595
|
let following = Promise.resolve();
|
|
482
596
|
const keyOf = ({ mod, program }) => `${mod}\n${program ?? ''}`;
|
|
483
597
|
const named = ({ mod, program }) => `${mod}'s ${program ?? mod} program`;
|
|
598
|
+
const closeIfExited = async (end, connection) => {
|
|
599
|
+
if (programs === undefined)
|
|
600
|
+
return;
|
|
601
|
+
const { mod, program = mod } = end.identity;
|
|
602
|
+
if ((await programs.hasExited(mod, program)) && end.connection === connection)
|
|
603
|
+
connection.close(new Error(`${named(end.identity)} exited`));
|
|
604
|
+
};
|
|
484
605
|
const isSelf = ({ mod, program }) => mod === cmodPluginName && program === cmodPluginName;
|
|
485
606
|
const endOf = (identity) => {
|
|
486
607
|
const known = ends.get(keyOf(identity));
|
|
@@ -537,7 +658,7 @@ export function routeProviders({ isOwn, listsSelf, own, device, report, channel,
|
|
|
537
658
|
if (end.older?.address === address)
|
|
538
659
|
return;
|
|
539
660
|
void end.older?.client.close();
|
|
540
|
-
const client = connectRpc({ call: addressCall(reach.fetch, address), handle: heardBy(end.listeners, named(end.identity)), onConnect: (connected) => end.listeners.replay(connected),
|
|
661
|
+
const client = connectRpc({ call: addressCall(reach.fetch, address), handle: heardBy(end.listeners, named(end.identity)), onConnect: (connected) => end.listeners.replay(connected), clock: reach.clock });
|
|
541
662
|
end.older = { address, client };
|
|
542
663
|
};
|
|
543
664
|
const isLinked = (each) => 'carrier' in each;
|
|
@@ -635,7 +756,7 @@ export function routeProviders({ isOwn, listsSelf, own, device, report, channel,
|
|
|
635
756
|
await listeners.replay(connected);
|
|
636
757
|
},
|
|
637
758
|
onError: () => reached(),
|
|
638
|
-
|
|
759
|
+
clock: reach.clock,
|
|
639
760
|
keepsConnecting: true,
|
|
640
761
|
});
|
|
641
762
|
devices.set(id, { name, address, client, listeners });
|
|
@@ -687,7 +808,7 @@ export function routeProviders({ isOwn, listsSelf, own, device, report, channel,
|
|
|
687
808
|
if (asked.device !== undefined && asked.device.id !== (await device()).id) {
|
|
688
809
|
const carrier = devices.get(asked.device.id);
|
|
689
810
|
if (carrier === undefined)
|
|
690
|
-
throw new
|
|
811
|
+
throw new RpcError(rpcCodes.notProvided, `cmod serve reaches no device ${asked.device.name}, so ${named(asked)} there answers no ${name}.`);
|
|
691
812
|
return { listeners: carrier.listeners, link: providerPeer(peerOf(carrier), asked), provider: asked };
|
|
692
813
|
}
|
|
693
814
|
if (isSelf(asked))
|
|
@@ -700,7 +821,7 @@ export function routeProviders({ isOwn, listsSelf, own, device, report, channel,
|
|
|
700
821
|
return end;
|
|
701
822
|
const older = programs === undefined ? undefined : (await instances(name)).find((each) => keyOf(each) === keyOf(asked));
|
|
702
823
|
if (older === undefined || programs === undefined)
|
|
703
|
-
throw new
|
|
824
|
+
throw new RpcError(rpcCodes.notProvided, `${named(asked)} does not run, so it answers no ${name}.`);
|
|
704
825
|
reachOlder(end, older.address, programs);
|
|
705
826
|
return end;
|
|
706
827
|
};
|
|
@@ -818,6 +939,20 @@ export function routeProviders({ isOwn, listsSelf, own, device, report, channel,
|
|
|
818
939
|
},
|
|
819
940
|
list: (name) => listed(name, undefined),
|
|
820
941
|
call: (called, signal) => call(undefined, called, signal),
|
|
942
|
+
async hear(listening, provider, heard) {
|
|
943
|
+
const target = await targetOf(listening.interface, provider);
|
|
944
|
+
if (target === undefined)
|
|
945
|
+
throw new Error(`cmod serve hears its own ${listening.interface} on a connection.`);
|
|
946
|
+
return target.listeners.listen(target.link, { ...listening, ...(target.provider === undefined ? {} : { provider: target.provider }) }, (payload) => heard(payload));
|
|
947
|
+
},
|
|
948
|
+
unpolled(connection) {
|
|
949
|
+
const end = [...ends.values()].find((each) => each.connection === connection);
|
|
950
|
+
if (end !== undefined)
|
|
951
|
+
void closeIfExited(end, connection).catch(report);
|
|
952
|
+
},
|
|
953
|
+
async programChanged(mod, program) {
|
|
954
|
+
await Promise.all([...ends.values()].flatMap((end) => (end.connection !== undefined && end.identity.mod === mod && (end.identity.program ?? mod) === program ? [closeIfExited(end, end.connection)] : [])));
|
|
955
|
+
},
|
|
821
956
|
closed(connection) {
|
|
822
957
|
let listedDevices = false;
|
|
823
958
|
for (const end of ends.values()) {
|
|
@@ -923,7 +1058,7 @@ export function createProviders({ name, call, changed, after, report }) {
|
|
|
923
1058
|
checkInterfaceName(named);
|
|
924
1059
|
provided.set(named, methods);
|
|
925
1060
|
changed();
|
|
926
|
-
const send = (method, event, payload) =>
|
|
1061
|
+
const send = (method, event, payload) => call(cmodPluginName, method, { interface: named, event, payload });
|
|
927
1062
|
return {
|
|
928
1063
|
remove() {
|
|
929
1064
|
if (provided.get(named) === methods && provided.delete(named))
|
|
@@ -937,6 +1072,7 @@ export function createProviders({ name, call, changed, after, report }) {
|
|
|
937
1072
|
const listed = (await call(cmodPluginName, interfaceMethods.providers, { name: named }));
|
|
938
1073
|
return [...listed.mods.map((mod) => client(named, { mod, device: listed.device })), ...listed.programs.map((identity) => client(named, identity))];
|
|
939
1074
|
},
|
|
1075
|
+
serveProvider: (named) => client(named, { mod: cmodPluginName, program: cmodPluginName }),
|
|
940
1076
|
answer,
|
|
941
1077
|
};
|
|
942
1078
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/runtime/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAqB,WAAW,EAAE,MAAM,EAAE,aAAa,EAAyC,MAAM,aAAa,CAAA;AAG7I,OAAO,KAAK,EAAW,GAAG,EAAE,aAAa,EAAkF,MAAM,WAAW,CAAA;AAC5I,OAAO,KAAK,EAAE,OAAO,EAAgB,MAAM,eAAe,CAAA;AAC1D,OAAO,
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/runtime/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAqB,WAAW,EAAE,MAAM,EAAE,aAAa,EAAyC,MAAM,aAAa,CAAA;AAG7I,OAAO,KAAK,EAAW,GAAG,EAAE,aAAa,EAAkF,MAAM,WAAW,CAAA;AAC5I,OAAO,KAAK,EAAE,OAAO,EAAgB,MAAM,eAAe,CAAA;AAC1D,OAAO,EAAkT,KAAK,KAAK,EAAE,MAAM,eAAe,CAAA;AAG1V,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAIzC,OAAO,KAAK,EAAE,aAAa,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AAE,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;IACtE,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;IACpC,QAAQ,CAAC,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;IAChE,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAA;IACjD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,CAAA;CACjD,KAAK,UAAU,CAAA;AAwGhB,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAsBhE;AAwBD,wBAAgB,eAAe,CAAC,KAAK,SAAS,MAAM,EAAE,QAAQ,SAAS,OAAO,GAAG,OAAO,EACtF,UAAU,EAAE,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAClD,gBAAgB,GAAE,MAAM,gBAAgB,GAAG,SAA2B,EACtE,OAAO,GAAE,aAAkB,EAC3B,UAAU,UAAO,EACjB,eAAe,CAAC,EAAE,eAAe,GAChC,SAAS,CAAC,KAAK,CAAC,CA4kBlB"}
|
package/runtime/lifecycle.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cacheFolder, dataFolder, finishStepsMethod, isAtLeast, isNerdFontTerminal, parsePreferences, preferencesPath, isProgramNewer, oldestCmodVersion, pendingStepsMethod, parseEvent, programModifiedMs, readRecord, readSteps, recordPath, scriptsSha256, serviceFolder } from '../records.js';
|
|
1
|
+
import { cacheFolder, dataFolder, finishStepsMethod, isAtLeast, isNerdFontTerminal, parsePreferences, preferencesPath, isProgramNewer, oldestCmodVersion, pendingStepsMethod, parseEvent, programModifiedMs, readRecord, readSteps, recordPath, isObject, scriptsSha256, serviceFolder } from '../records.js';
|
|
2
2
|
import { homePrefix, ifMissing, relativePath } from '../utils/paths.js';
|
|
3
3
|
import { firstLine, formatExit, messageOf } from '../utils/text.js';
|
|
4
4
|
import { beforeDeadline, callDeadline, hookMs, settledAfterAbort } from './deadline.js';
|
|
@@ -44,21 +44,52 @@ const stallTicks = 3;
|
|
|
44
44
|
const stallMs = 60_000;
|
|
45
45
|
const settingsLoadMs = 500;
|
|
46
46
|
const shellTools = ['Bash', 'PowerShell'];
|
|
47
|
+
const factsMs = 2000;
|
|
47
48
|
async function roundsBarEnds(claude) {
|
|
48
49
|
const path = preferencesPath(await cmodStore(claude));
|
|
49
50
|
const text = await claude.fs.read(path).catch(ifMissing(undefined));
|
|
50
51
|
return parsePreferences(text === undefined ? undefined : JSON.parse(text), path).roundsBarEnds;
|
|
51
52
|
}
|
|
53
|
+
function followDrawnIn(claude, name) {
|
|
54
|
+
let facts = { hasNerdFont: false, theme: 'dark' };
|
|
55
|
+
let isNerdFont;
|
|
56
|
+
let readAt = Number.NEGATIVE_INFINITY;
|
|
57
|
+
let isReading = false;
|
|
58
|
+
const read = async (now) => {
|
|
59
|
+
readAt = now;
|
|
60
|
+
isNerdFont ??= claude.env.terminal().then(isNerdFontTerminal);
|
|
61
|
+
const [rounds, rows, isKnown] = await Promise.all([
|
|
62
|
+
roundsBarEnds(claude).catch((error) => (claude.ui.warn('preferences:read', `${name} rounds its bars only in a terminal it knows: ${messageOf(error)}`), false)),
|
|
63
|
+
claude.config.list().catch((error) => (claude.ui.warn('config:read', `${name} draws for a theme with full color: ${messageOf(error)}`), [])),
|
|
64
|
+
isNerdFont,
|
|
65
|
+
]);
|
|
66
|
+
const theme = rows.find((row) => row.key === 'theme')?.value;
|
|
67
|
+
const next = { hasNerdFont: rounds || isKnown, theme: typeof theme === 'string' ? theme : 'dark' };
|
|
68
|
+
const isChanged = next.hasNerdFont !== facts.hasNerdFont || next.theme !== facts.theme;
|
|
69
|
+
facts = next;
|
|
70
|
+
return isChanged;
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
facts: () => facts,
|
|
74
|
+
read: async () => void (await read(await claude.clock.now())),
|
|
75
|
+
drawn: () => {
|
|
76
|
+
if (isReading)
|
|
77
|
+
return;
|
|
78
|
+
isReading = true;
|
|
79
|
+
void claude.clock
|
|
80
|
+
.now()
|
|
81
|
+
.then((now) => now - readAt >= factsMs && read(now))
|
|
82
|
+
.then((isChanged) => isChanged && claude.ui.invalidate('ui.render'))
|
|
83
|
+
.finally(() => void (isReading = false));
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
52
87
|
export async function readPlugin(claude) {
|
|
53
88
|
const { name, root } = claude.plugin;
|
|
54
|
-
const read =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
};
|
|
58
|
-
const manifest = (await readJson(read, `${root}/.claude-plugin/plugin.json`));
|
|
59
|
-
const version = typeof manifest?.version === 'string' ? manifest.version : undefined;
|
|
60
|
-
const store = await cmodStore(claude);
|
|
61
|
-
const steps = readSteps(await readJson(read, `${root}/package.json`)) ?? {};
|
|
89
|
+
const read = (path) => claude.fs.read(path).catch(ifMissing(undefined));
|
|
90
|
+
const [manifest, packageJson, store] = await Promise.all([readJson(read, `${root}/.claude-plugin/plugin.json`), readJson(read, `${root}/package.json`), cmodStore(claude)]);
|
|
91
|
+
const version = isObject(manifest) && typeof manifest['version'] === 'string' ? manifest['version'] : undefined;
|
|
92
|
+
const steps = readSteps(packageJson) ?? {};
|
|
62
93
|
if (name === cmodPluginName) {
|
|
63
94
|
const installed = await newestCmodVersion(claude);
|
|
64
95
|
return { name, root, version, store, steps, isInstalled: version !== undefined && installed !== undefined && isAtLeast(installed, version), shouldRecord: false };
|
|
@@ -67,8 +98,9 @@ export async function readPlugin(claude) {
|
|
|
67
98
|
const record = await readRecord(read, store, name);
|
|
68
99
|
if (Object.keys(steps).length === 0)
|
|
69
100
|
return { ...plugin, isInstalled: true, shouldRecord: record?.version !== version };
|
|
101
|
+
const readStepFile = async (path) => ((await claude.fs.stat(path).catch(ifMissing(undefined)))?.kind === 'file' ? claude.fs.read(path) : undefined);
|
|
70
102
|
const scripts = await scriptsSha256(steps, {
|
|
71
|
-
read: (path) =>
|
|
103
|
+
read: (path) => readStepFile(`${root}/${path}`),
|
|
72
104
|
list: (folder) => filesBelow(claude, `${root}/${folder}`),
|
|
73
105
|
});
|
|
74
106
|
if (version === undefined || record?.scriptsSha256 !== scripts)
|
|
@@ -333,22 +365,19 @@ export function createLifecycle(definition, permissionRoutes = () => undefined,
|
|
|
333
365
|
void activeRouter.dispatch('cmod.call', call, async () => ({ deny: `${definition.name} has no method ${call.method}.` })).then((answer) => ('deny' in answer ? failed(new Error(answer.deny)) : undefined), failed);
|
|
334
366
|
}
|
|
335
367
|
runtime.claude.ui.invalidate('ui.render');
|
|
336
|
-
if (definition.name === cmodPluginName)
|
|
337
|
-
runtime.claude.ui.invalidate('command.describe');
|
|
338
368
|
void runSteps(active.mod).catch((error) => toastFailure({ id: 'cmod:steps', message: 'Its installer stopped', error, isCritical: true }));
|
|
339
369
|
const missed = missedSessionStart;
|
|
340
370
|
missedSessionStart = undefined;
|
|
341
371
|
if (missed !== undefined)
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
.catch((error) => toastFailure({ id: installId, message: 'Could not say what it installed', error }));
|
|
372
|
+
void replaySessionStart(missed);
|
|
373
|
+
void announce(runtime, plugin, added).catch((error) => toastFailure({ id: installId, message: 'Could not say what it installed', error }));
|
|
374
|
+
};
|
|
375
|
+
const announce = async ({ claude: engine, toaster }, installed, added) => {
|
|
376
|
+
if ((await engine.store.get(announcedKey)) !== undefined)
|
|
377
|
+
return toaster.toast.dismiss(installId);
|
|
378
|
+
await engine.store.set(announcedKey, { version: installed.version ?? '' });
|
|
379
|
+
const { message, ...options } = await announcementOf(engine, installed, added, openSettings);
|
|
380
|
+
toaster.toast.success(message, { id: installId, duration: announcementMs, ...options });
|
|
352
381
|
};
|
|
353
382
|
const replaySessionStart = async (e) => {
|
|
354
383
|
hasHeardSessionStart = true;
|
|
@@ -642,13 +671,16 @@ export function createLifecycle(definition, permissionRoutes = () => undefined,
|
|
|
642
671
|
if (runtime !== undefined)
|
|
643
672
|
return;
|
|
644
673
|
const open = (href, press) => void openLink(claudeCalls, href, press.surface).then((done) => done === 'copied' && runtime?.toaster.toast.success('Copied the link', { description: 'Paste it in your browser.' }), (error) => toastFailure({ id: 'open-link', message: 'Could not open the link', error, isCritical: true }));
|
|
645
|
-
|
|
674
|
+
const drawnFacts = followDrawnIn(claudeCalls, definition.name);
|
|
646
675
|
const naming = {
|
|
647
676
|
...claudeCalls,
|
|
648
677
|
ui: {
|
|
649
678
|
...claudeCalls.ui,
|
|
650
679
|
warn: (id, text) => (runtime === undefined ? claudeCalls.ui.warn(id, text) : runtime.toaster.warn(id, text)),
|
|
651
|
-
resolve: (e) =>
|
|
680
|
+
resolve: (e) => {
|
|
681
|
+
drawnFacts.drawn();
|
|
682
|
+
return forClaudeCode(claudeCalls.ui.resolve(e), e.surface, open, drawnFacts.facts());
|
|
683
|
+
},
|
|
652
684
|
},
|
|
653
685
|
session: { ...claudeCalls.session, id: async () => startingSession ?? claudeCalls.session.id() },
|
|
654
686
|
};
|
|
@@ -667,9 +699,7 @@ export function createLifecycle(definition, permissionRoutes = () => undefined,
|
|
|
667
699
|
readStarted = read;
|
|
668
700
|
try {
|
|
669
701
|
drawCount = (await claudeCalls.clock.now()) * drawsPerMs;
|
|
670
|
-
|
|
671
|
-
await programs.refresh();
|
|
672
|
-
await begin().catch(report);
|
|
702
|
+
await Promise.all([drawnFacts.read(), programs.refresh().then(() => begin().catch(report))]);
|
|
673
703
|
}
|
|
674
704
|
finally {
|
|
675
705
|
settleStart();
|
|
@@ -726,11 +756,11 @@ async function createMod(definition, runtime) {
|
|
|
726
756
|
const borrowed = (styler, cached, input, scope) => {
|
|
727
757
|
const name = `The markdown style of ${styler}`;
|
|
728
758
|
void parts?.fill(styler, cached, input, name)?.then(() => claude.ui.invalidate('ui.render'));
|
|
729
|
-
return parts?.element(styler, cached, `${styler}/markdown:${scope}:`, name, `markdown:${styler}`);
|
|
759
|
+
return parts?.element(styler, cached, `${styler}/markdown:${scope}:`, name, `markdown:${styler}`) ?? undefined;
|
|
730
760
|
};
|
|
731
761
|
const provided = createProviders({
|
|
732
762
|
name: definition.name,
|
|
733
|
-
call: (to, method, input) => claude.cmod.call({ to, method, input }),
|
|
763
|
+
call: (to, method, input) => new Promise((resolve) => claude.clock.after(0, () => resolve(claude.cmod.call({ to, method, input })))),
|
|
734
764
|
changed: () => area.relisted(),
|
|
735
765
|
after: (ms, run) => claude.clock.after(ms, run),
|
|
736
766
|
report: (error) => report({ id: 'interfaces', message: 'A provider listener failed', error }),
|
|
@@ -1140,6 +1170,8 @@ async function createMod(definition, runtime) {
|
|
|
1140
1170
|
interfaces: provided,
|
|
1141
1171
|
...(widgets === undefined ? {} : { widgets }),
|
|
1142
1172
|
onServeUnreached: (listener) => conversations?.onUnreached(listener),
|
|
1173
|
+
onStoreChange: (listener) => conversations?.onStoreChange(listener),
|
|
1174
|
+
storeChanged: (part) => conversations?.tellStore(part),
|
|
1143
1175
|
...(servedParts === undefined ? {} : { parts: servedParts }),
|
|
1144
1176
|
});
|
|
1145
1177
|
const names = new Set();
|
package/runtime/parts.d.ts
CHANGED
|
@@ -8,9 +8,9 @@ import { type PageDeclaration, type PartPress, type PartRequest, type PartsUpdat
|
|
|
8
8
|
import { type Widgets } from './widgets.js';
|
|
9
9
|
export type DrawnParts = {
|
|
10
10
|
fill(mod: string, cached: string, input: Readonly<Record<string, unknown>>, name: string): Promise<void> | undefined;
|
|
11
|
-
element(mod: string, cached: string, keyPrefix: string, name: string, reportId: string): RenderElement | undefined;
|
|
11
|
+
element(mod: string, cached: string, keyPrefix: string, name: string, reportId: string): RenderElement | null | undefined;
|
|
12
12
|
failure(mod: string, cached: string): string | undefined;
|
|
13
|
-
forget(mod: string): void;
|
|
13
|
+
forget(mod: string, ids?: readonly string[]): void;
|
|
14
14
|
};
|
|
15
15
|
export declare function drawnParts({ claude, report, press }: {
|
|
16
16
|
readonly claude: Claude;
|
package/runtime/parts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parts.d.ts","sourceRoot":"","sources":["../src/runtime/parts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,aAAa,EAAE,MAAM,aAAa,CAAA;AACjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAExC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAI1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"parts.d.ts","sourceRoot":"","sources":["../src/runtime/parts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,aAAa,EAAE,MAAM,aAAa,CAAA;AACjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAExC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAI1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAGzC,OAAO,EAA2B,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAA2C,KAAK,eAAe,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,KAAK,eAAe,EAAE,KAAK,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAC1M,OAAO,EAA6B,KAAK,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtE,MAAM,MAAM,UA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