@agentshouse/mdruntime 0.1.0-cefbc8bb8a1c0 → 0.1.0-cf1e7fdb9c600
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/adapter.d.ts +69 -49
- package/dist/adapter.d.ts.map +1 -1
- package/dist/bootstrap.d.ts +5 -8
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +20 -21
- package/dist/chain.d.ts +2 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/client.d.ts +6 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +0 -1
- package/dist/collection.d.ts +2 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +1 -17
- package/dist/compile.d.ts +1 -6
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +97 -281
- package/dist/connection.d.ts +5 -7
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +816 -846
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- package/dist/conversation.d.ts +15 -13
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +133 -142
- package/dist/durability.d.ts +0 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +2 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +14 -5
- package/dist/host.d.ts +3 -7
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +12 -26
- package/dist/index.d.ts +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/job.d.ts +14 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +28 -0
- package/dist/live.d.ts +2 -1
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +10 -7
- package/dist/memory.d.ts +9 -4
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +132 -81
- package/dist/messages.d.ts +2 -2
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +15 -16
- package/dist/model.d.ts +1 -3
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +0 -12
- package/dist/observation.d.ts +2 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +7 -2
- package/dist/outcome.d.ts +0 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/query.d.ts +5 -209
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -505
- package/dist/reach.d.ts +7 -7
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +31 -44
- package/dist/react.d.ts +3 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/readiness.d.ts +2 -15
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +4 -10
- package/dist/refresh.d.ts +7 -5
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +46 -6
- package/dist/replica.d.ts +2 -2
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +5 -5
- package/dist/room-draft.d.ts +2 -1
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +65 -52
- package/dist/rows.d.ts +3 -19
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +36 -164
- package/dist/search.d.ts +12 -63
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +9 -52
- package/dist/shared.d.ts +0 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +0 -10
- package/dist/status.d.ts +0 -4
- package/dist/status.d.ts.map +1 -1
- package/dist/store.d.ts +15 -19
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +40 -39
- package/dist/stored.d.ts +33 -6
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +87 -124
- package/dist/tables.d.ts +34 -33
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +21 -54
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/validation.d.ts +3 -4
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +39 -97
- package/dist/windows.d.ts +1 -12
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +2 -75
- package/dist/wire.d.ts +1 -4
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +1 -1
- package/package.json +2 -2
- package/dist/fulltext.d.ts +0 -27
- package/dist/fulltext.d.ts.map +0 -1
- package/dist/fulltext.js +0 -370
- package/dist/reads.d.ts +0 -11
- package/dist/reads.d.ts.map +0 -1
- package/dist/reads.js +0 -91
- package/dist/words.d.ts +0 -19
- package/dist/words.d.ts.map +0 -1
- package/dist/words.js +0 -156
package/dist/conversation.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { cursorOf, decodedCursor } from '@agentshouse/mdmodel';
|
|
1
2
|
import { conversationChangeSet } from './change-set.js';
|
|
2
3
|
import { runtimeError } from './failure.js';
|
|
3
4
|
import { refusedForSpace } from './durability.js';
|
|
4
5
|
import { changeBatchIdentity, chatDraftRevision } from './identity.js';
|
|
5
6
|
import { OFFLINE } from './outcome.js';
|
|
6
7
|
import { untilAnswered } from './recovery.js';
|
|
7
|
-
import { capped,
|
|
8
|
+
import { capped, FROM_START, messageOrder, precedes } from './windows.js';
|
|
8
9
|
const QUIET = {
|
|
9
10
|
turn: null,
|
|
10
11
|
questions: [],
|
|
@@ -12,6 +13,7 @@ const QUIET = {
|
|
|
12
13
|
commands: [],
|
|
13
14
|
options: [],
|
|
14
15
|
starting: null,
|
|
16
|
+
subagents: [],
|
|
15
17
|
link: null,
|
|
16
18
|
deliveryUnknown: [],
|
|
17
19
|
};
|
|
@@ -21,6 +23,7 @@ const FACTS = [
|
|
|
21
23
|
'commands',
|
|
22
24
|
'options',
|
|
23
25
|
'starting',
|
|
26
|
+
'subagents',
|
|
24
27
|
'link',
|
|
25
28
|
'deliveryUnknown',
|
|
26
29
|
];
|
|
@@ -31,9 +34,11 @@ export function unheldView(conversation) {
|
|
|
31
34
|
turn: null,
|
|
32
35
|
questions: [],
|
|
33
36
|
process: null,
|
|
37
|
+
processEnded: null,
|
|
34
38
|
commands: [],
|
|
35
39
|
options: [],
|
|
36
40
|
starting: null,
|
|
41
|
+
subagents: [],
|
|
37
42
|
link: null,
|
|
38
43
|
deliveryUnknown: [],
|
|
39
44
|
chatDraft: null,
|
|
@@ -48,10 +53,8 @@ export function newChat(agent) {
|
|
|
48
53
|
function creationOf(input) {
|
|
49
54
|
if (typeof input !== 'object' || input === null)
|
|
50
55
|
return null;
|
|
51
|
-
const { agent_id: agent, operation_id: operation
|
|
52
|
-
return typeof agent === 'string' && typeof operation === 'string'
|
|
53
|
-
? { agent, operation }
|
|
54
|
-
: null;
|
|
56
|
+
const { agent_id: agent, operation_id: operation } = input;
|
|
57
|
+
return typeof agent === 'string' && typeof operation === 'string' ? { agent, operation } : null;
|
|
55
58
|
}
|
|
56
59
|
function startedTurn(turn, operation) {
|
|
57
60
|
if (operation.op === 'begin')
|
|
@@ -210,6 +213,14 @@ function askedOf(options) {
|
|
|
210
213
|
}
|
|
211
214
|
return { limit: capped(limit), after, before: beforeOf(after), total: total === true };
|
|
212
215
|
}
|
|
216
|
+
function phraseOf(text) {
|
|
217
|
+
if (text === undefined)
|
|
218
|
+
return null;
|
|
219
|
+
if (typeof text !== 'string' || text === '') {
|
|
220
|
+
throw runtimeError('invalid-text', 'a conversation is found by a phrase');
|
|
221
|
+
}
|
|
222
|
+
return text;
|
|
223
|
+
}
|
|
213
224
|
const EXPIRED = { kind: 'rejected', code: 'expired', fields: {}, retryable: false };
|
|
214
225
|
const DURABLE_WRITE = {
|
|
215
226
|
kind: 'rejected',
|
|
@@ -256,6 +267,8 @@ export function createConversationStore(deps) {
|
|
|
256
267
|
const unsent = new Map();
|
|
257
268
|
const views = new Map();
|
|
258
269
|
const listing = new Map();
|
|
270
|
+
let relisting = null;
|
|
271
|
+
let listCursor = null;
|
|
259
272
|
const creations = new Set();
|
|
260
273
|
const listWatchers = new Set();
|
|
261
274
|
const unlisted = new Set();
|
|
@@ -264,11 +277,9 @@ export function createConversationStore(deps) {
|
|
|
264
277
|
let listKept = false;
|
|
265
278
|
const agentWatchers = new Set();
|
|
266
279
|
const unnamed = new Set();
|
|
267
|
-
let
|
|
268
|
-
let
|
|
269
|
-
let
|
|
270
|
-
let agentsRead = null;
|
|
271
|
-
let agentsFrom;
|
|
280
|
+
let agentsShown = null;
|
|
281
|
+
let listedAgents = null;
|
|
282
|
+
let agentsReading = false;
|
|
272
283
|
let replicated = new Set();
|
|
273
284
|
let handedReplicated;
|
|
274
285
|
function liveOf(conversation) {
|
|
@@ -289,9 +300,11 @@ export function createConversationStore(deps) {
|
|
|
289
300
|
turn: structuredClone(facts.turn),
|
|
290
301
|
questions: structuredClone(facts.questions),
|
|
291
302
|
process: facts.process === null ? null : { ...facts.process },
|
|
303
|
+
processEnded: listing.get(conversation)?.processEnded ?? null,
|
|
292
304
|
commands: structuredClone(facts.commands),
|
|
293
305
|
options: structuredClone(facts.options),
|
|
294
306
|
starting: facts.starting,
|
|
307
|
+
subagents: structuredClone(facts.subagents),
|
|
295
308
|
link: facts.link === null ? null : { ...facts.link },
|
|
296
309
|
deliveryUnknown: [...facts.deliveryUnknown],
|
|
297
310
|
chatDraft: draft === undefined || unwritten(draft)
|
|
@@ -347,7 +360,7 @@ export function createConversationStore(deps) {
|
|
|
347
360
|
function entries() {
|
|
348
361
|
return [...listing.values()].map((entry) => ({
|
|
349
362
|
conversation: entry.conversation,
|
|
350
|
-
agent: { identity: entry.agent, name:
|
|
363
|
+
agent: { identity: entry.agent, name: entry.agentName },
|
|
351
364
|
name: entry.name,
|
|
352
365
|
created: entry.created,
|
|
353
366
|
finished: entry.finished,
|
|
@@ -366,9 +379,22 @@ export function createConversationStore(deps) {
|
|
|
366
379
|
if (deps.closed())
|
|
367
380
|
return;
|
|
368
381
|
const entries = [...listing.values()];
|
|
369
|
-
|
|
382
|
+
const cursor = listCursor;
|
|
383
|
+
void deps
|
|
384
|
+
.durably(async (local) => {
|
|
385
|
+
await local.fact('conversationList', entries);
|
|
386
|
+
await local.fact('conversationCursor', cursor);
|
|
387
|
+
})
|
|
388
|
+
.catch(() => { });
|
|
370
389
|
});
|
|
371
390
|
}
|
|
391
|
+
function listed(entry) {
|
|
392
|
+
const ended = listing.get(entry.conversation)?.processEnded ?? null;
|
|
393
|
+
listing.set(entry.conversation, { ...entry });
|
|
394
|
+
creations.delete(entry.conversation);
|
|
395
|
+
if (entry.processEnded !== ended)
|
|
396
|
+
emit(entry.conversation);
|
|
397
|
+
}
|
|
372
398
|
function emitList() {
|
|
373
399
|
if (deps.closed())
|
|
374
400
|
return;
|
|
@@ -377,18 +403,15 @@ export function createConversationStore(deps) {
|
|
|
377
403
|
for (const watcher of listWatchers)
|
|
378
404
|
watcher(value);
|
|
379
405
|
}
|
|
406
|
+
emitAgents();
|
|
380
407
|
learned();
|
|
381
408
|
}
|
|
382
|
-
function unlearnable() {
|
|
383
|
-
return !deps.online() || (deps.listed() && deps.agents() === undefined);
|
|
384
|
-
}
|
|
385
409
|
function learned() {
|
|
386
410
|
if (deps.closed())
|
|
387
411
|
return;
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
(listKnown || listHeld || deps.stream() === undefined || unlearnable())) {
|
|
412
|
+
if (!listKnown && !listHeld && deps.stream() !== undefined && deps.online())
|
|
413
|
+
return;
|
|
414
|
+
if (unlisted.size > 0) {
|
|
392
415
|
const value = entries();
|
|
393
416
|
for (const watcher of [...unlisted]) {
|
|
394
417
|
unlisted.delete(watcher);
|
|
@@ -396,7 +419,7 @@ export function createConversationStore(deps) {
|
|
|
396
419
|
watcher(value);
|
|
397
420
|
}
|
|
398
421
|
}
|
|
399
|
-
if (unnamed.size > 0
|
|
422
|
+
if (unnamed.size > 0) {
|
|
400
423
|
const value = agents();
|
|
401
424
|
for (const watcher of [...unnamed]) {
|
|
402
425
|
unnamed.delete(watcher);
|
|
@@ -406,17 +429,44 @@ export function createConversationStore(deps) {
|
|
|
406
429
|
}
|
|
407
430
|
}
|
|
408
431
|
function agents() {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
.
|
|
432
|
+
const named = new Map();
|
|
433
|
+
for (const agent of listedAgents ?? [])
|
|
434
|
+
named.set(agent.agent, agent);
|
|
435
|
+
for (const entry of listing.values()) {
|
|
436
|
+
named.set(entry.agent, { name: entry.agentName, retired: entry.agentRetired });
|
|
437
|
+
}
|
|
438
|
+
return [...named]
|
|
439
|
+
.filter(([, agent]) => !agent.retired)
|
|
440
|
+
.map(([identity, agent]) => ({ identity, name: agent.name }))
|
|
412
441
|
.sort((left, right) => left.name === right.name
|
|
413
442
|
? left.identity.localeCompare(right.identity)
|
|
414
443
|
: left.name.localeCompare(right.name));
|
|
415
444
|
}
|
|
445
|
+
function readAgents() {
|
|
446
|
+
const stream = deps.stream();
|
|
447
|
+
if (stream?.agents === undefined || !deps.online() || agentsReading)
|
|
448
|
+
return;
|
|
449
|
+
agentsReading = true;
|
|
450
|
+
void stream
|
|
451
|
+
.agents()
|
|
452
|
+
.then((read) => {
|
|
453
|
+
if (read === null)
|
|
454
|
+
return;
|
|
455
|
+
listedAgents = read;
|
|
456
|
+
emitAgents();
|
|
457
|
+
}, () => { })
|
|
458
|
+
.finally(() => {
|
|
459
|
+
agentsReading = false;
|
|
460
|
+
});
|
|
461
|
+
}
|
|
416
462
|
function emitAgents() {
|
|
417
463
|
if (deps.closed() || agentWatchers.size === 0)
|
|
418
464
|
return;
|
|
419
465
|
const value = agents();
|
|
466
|
+
const shown = JSON.stringify(value);
|
|
467
|
+
if (shown === agentsShown)
|
|
468
|
+
return;
|
|
469
|
+
agentsShown = shown;
|
|
420
470
|
for (const watcher of agentWatchers)
|
|
421
471
|
watcher(value);
|
|
422
472
|
}
|
|
@@ -432,60 +482,11 @@ export function createConversationStore(deps) {
|
|
|
432
482
|
if (stateOf(conversation) !== before || next?.turn?.started !== began)
|
|
433
483
|
emitList();
|
|
434
484
|
}
|
|
435
|
-
async function readAgents() {
|
|
436
|
-
const declaration = deps.agents();
|
|
437
|
-
agentsFrom = JSON.stringify(declaration);
|
|
438
|
-
if (declaration === undefined)
|
|
439
|
-
return;
|
|
440
|
-
const names = new Map();
|
|
441
|
-
const retired = new Set();
|
|
442
|
-
let covered = null;
|
|
443
|
-
for (let after;;) {
|
|
444
|
-
const read = await deps.documents(declaration, after);
|
|
445
|
-
if ('pending' in read)
|
|
446
|
-
return;
|
|
447
|
-
const coverage = JSON.stringify(read.coverage);
|
|
448
|
-
if (covered !== null && coverage !== covered)
|
|
449
|
-
return readAgents();
|
|
450
|
-
covered = coverage;
|
|
451
|
-
for (const document of read.documents) {
|
|
452
|
-
const identity = document.fields?.[declaration.identity];
|
|
453
|
-
const name = document.fields?.[declaration.name];
|
|
454
|
-
if (typeof identity !== 'string' || typeof name !== 'string')
|
|
455
|
-
continue;
|
|
456
|
-
names.set(identity, name);
|
|
457
|
-
const ended = declaration.retired === undefined ? null : document.fields?.[declaration.retired];
|
|
458
|
-
if (ended !== undefined && ended !== null)
|
|
459
|
-
retired.add(identity);
|
|
460
|
-
}
|
|
461
|
-
if (read.next === undefined)
|
|
462
|
-
break;
|
|
463
|
-
after = read.next;
|
|
464
|
-
}
|
|
465
|
-
agentsKnown = true;
|
|
466
|
-
const named = JSON.stringify([...names]) !== JSON.stringify([...agentNames]);
|
|
467
|
-
if (!named && JSON.stringify([...retired]) === JSON.stringify([...retiredAgents])) {
|
|
468
|
-
learned();
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
|
-
agentNames = names;
|
|
472
|
-
retiredAgents = retired;
|
|
473
|
-
emitAgents();
|
|
474
|
-
if (named)
|
|
475
|
-
emitList();
|
|
476
|
-
learned();
|
|
477
|
-
const ended = [...drafts.keys()].filter(retiredChat);
|
|
478
|
-
if (ended.length > 0)
|
|
479
|
-
await remove(ended);
|
|
480
|
-
}
|
|
481
485
|
function retiredChat(conversation) {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
agentsRead = null;
|
|
487
|
-
});
|
|
488
|
-
return agentsRead;
|
|
486
|
+
if (!conversation.startsWith(NEW_CHAT))
|
|
487
|
+
return false;
|
|
488
|
+
const agent = conversation.slice(NEW_CHAT.length);
|
|
489
|
+
return [...listing.values()].some((entry) => entry.agent === agent && entry.agentRetired);
|
|
489
490
|
}
|
|
490
491
|
function live(conversation, change) {
|
|
491
492
|
const owed = unsent.get(conversation);
|
|
@@ -508,6 +509,7 @@ export function createConversationStore(deps) {
|
|
|
508
509
|
commands: facts.has('commands') ? QUIET.commands : held.commands,
|
|
509
510
|
options: facts.has('options') ? QUIET.options : held.options,
|
|
510
511
|
starting: facts.has('starting') ? QUIET.starting : held.starting,
|
|
512
|
+
subagents: facts.has('subagents') ? QUIET.subagents : held.subagents,
|
|
511
513
|
link: facts.has('link') ? QUIET.link : held.link,
|
|
512
514
|
deliveryUnknown: facts.has('deliveryUnknown')
|
|
513
515
|
? QUIET.deliveryUnknown
|
|
@@ -609,7 +611,7 @@ export function createConversationStore(deps) {
|
|
|
609
611
|
}));
|
|
610
612
|
while (waiting.length > 0) {
|
|
611
613
|
const asking = waiting.slice(0, HISTORY_CONVERSATIONS);
|
|
612
|
-
const result = await deps.
|
|
614
|
+
const result = await deps.history({
|
|
613
615
|
conversations: asking.map(({ conversation, after }) => ({
|
|
614
616
|
conversation,
|
|
615
617
|
...(after === undefined ? {} : { after }),
|
|
@@ -712,6 +714,10 @@ export function createConversationStore(deps) {
|
|
|
712
714
|
live(conversation, { starting: event.step });
|
|
713
715
|
return;
|
|
714
716
|
}
|
|
717
|
+
if (event.kind === 'subagents') {
|
|
718
|
+
live(conversation, { subagents: structuredClone(event.subagents) });
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
715
721
|
if (event.kind === 'link') {
|
|
716
722
|
live(conversation, { link: { connected: event.connected } });
|
|
717
723
|
return;
|
|
@@ -820,9 +826,9 @@ export function createConversationStore(deps) {
|
|
|
820
826
|
const dispatch = { answered: false };
|
|
821
827
|
sending.set(submission.operation, dispatch);
|
|
822
828
|
try {
|
|
823
|
-
const result = await invoke('
|
|
824
|
-
text: submission.text,
|
|
829
|
+
const result = await invoke('conversations/send', conversation, {
|
|
825
830
|
operation_id: submission.operation,
|
|
831
|
+
text: submission.text,
|
|
826
832
|
});
|
|
827
833
|
dispatch.answered = result.kind !== 'transport-uncertainty';
|
|
828
834
|
if (result.kind === 'revoked-authorization')
|
|
@@ -831,7 +837,7 @@ export function createConversationStore(deps) {
|
|
|
831
837
|
deps.unanswered();
|
|
832
838
|
return result;
|
|
833
839
|
}
|
|
834
|
-
const turn = answered(result, '
|
|
840
|
+
const turn = answered(result, 'message_id');
|
|
835
841
|
await withDraft(conversation, async (current, local) => {
|
|
836
842
|
const held = current?.submitted?.find((one) => one.operation === submission.operation);
|
|
837
843
|
if (current === undefined || held === undefined || held.turn !== null)
|
|
@@ -851,12 +857,11 @@ export function createConversationStore(deps) {
|
|
|
851
857
|
sending.delete(submission.operation);
|
|
852
858
|
}
|
|
853
859
|
}
|
|
854
|
-
function invoke(name, conversation, extra = {}) {
|
|
855
|
-
return deps.call(name, { conversation, ...extra });
|
|
860
|
+
function invoke(name, conversation, extra = { operation_id: changeBatchIdentity() }) {
|
|
861
|
+
return deps.call(name, { conversation_id: conversation, ...extra });
|
|
856
862
|
}
|
|
857
863
|
const surface = {
|
|
858
|
-
|
|
859
|
-
await agentsReady();
|
|
864
|
+
list() {
|
|
860
865
|
return new Promise((settle) => {
|
|
861
866
|
const answer = (listed) => {
|
|
862
867
|
unlisted.delete(answer);
|
|
@@ -868,16 +873,18 @@ export function createConversationStore(deps) {
|
|
|
868
873
|
});
|
|
869
874
|
},
|
|
870
875
|
async read(conversation, options = {}) {
|
|
871
|
-
const
|
|
876
|
+
const { text, ...windowed } = options;
|
|
877
|
+
const asked = askedOf(windowed);
|
|
878
|
+
const phrase = phraseOf(text);
|
|
872
879
|
return deps.durably(async (local) => {
|
|
873
|
-
const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before);
|
|
874
|
-
const total = asked.total ? await local.messageCount(conversation) : null;
|
|
880
|
+
const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before, phrase);
|
|
881
|
+
const total = asked.total ? await local.messageCount(conversation, phrase) : null;
|
|
875
882
|
return structuredClone(viewOf(conversation, messages, frameOf(asked, messages, more, total)));
|
|
876
883
|
});
|
|
877
884
|
},
|
|
878
885
|
async create(input) {
|
|
879
|
-
const result = await deps.call('
|
|
880
|
-
const conversation = answered(result, '
|
|
886
|
+
const result = await deps.call('conversations/create', input);
|
|
887
|
+
const conversation = answered(result, 'conversation_id');
|
|
881
888
|
if (conversation === null)
|
|
882
889
|
return result;
|
|
883
890
|
if (!listing.has(conversation))
|
|
@@ -912,28 +919,19 @@ export function createConversationStore(deps) {
|
|
|
912
919
|
return OFFLINE;
|
|
913
920
|
},
|
|
914
921
|
answer(conversation, answer) {
|
|
915
|
-
return invoke('
|
|
922
|
+
return invoke('conversations/interaction/answer', conversation, {
|
|
923
|
+
operation_id: changeBatchIdentity(),
|
|
924
|
+
...answer,
|
|
925
|
+
});
|
|
916
926
|
},
|
|
917
927
|
interrupt(conversation) {
|
|
918
|
-
return invoke('
|
|
928
|
+
return invoke('conversations/interrupt', conversation);
|
|
919
929
|
},
|
|
920
930
|
kill(conversation) {
|
|
921
|
-
return invoke('
|
|
922
|
-
},
|
|
923
|
-
async cancel(conversation, turn) {
|
|
924
|
-
const result = await invoke('conversation.cancel', conversation, { turn });
|
|
925
|
-
if (result.kind !== 'action')
|
|
926
|
-
return result;
|
|
927
|
-
await withDraft(conversation, (current) => {
|
|
928
|
-
const held = current?.submitted?.find((one) => one.turn === turn);
|
|
929
|
-
if (current === undefined || held === undefined)
|
|
930
|
-
return undefined;
|
|
931
|
-
return returned(current, held, current.submitted.filter((one) => one !== held));
|
|
932
|
-
});
|
|
933
|
-
return result;
|
|
931
|
+
return invoke('conversations/kill', conversation);
|
|
934
932
|
},
|
|
935
933
|
delete(conversation) {
|
|
936
|
-
return invoke('
|
|
934
|
+
return invoke('conversations/delete', conversation);
|
|
937
935
|
},
|
|
938
936
|
};
|
|
939
937
|
const chatDraft = {
|
|
@@ -962,12 +960,14 @@ export function createConversationStore(deps) {
|
|
|
962
960
|
return {
|
|
963
961
|
surface,
|
|
964
962
|
chatDraft,
|
|
965
|
-
hydrate(held, kept, list) {
|
|
963
|
+
hydrate(held, kept, list, cursor) {
|
|
966
964
|
if (list !== null && !listKnown) {
|
|
967
965
|
listing.clear();
|
|
968
966
|
for (const entry of list)
|
|
969
967
|
listing.set(entry.conversation, { ...entry });
|
|
970
968
|
listHeld = true;
|
|
969
|
+
listCursor = cursor;
|
|
970
|
+
deps.stream()?.hold(cursor);
|
|
971
971
|
}
|
|
972
972
|
stored.clear();
|
|
973
973
|
reads.clear();
|
|
@@ -1058,6 +1058,7 @@ export function createConversationStore(deps) {
|
|
|
1058
1058
|
return listKnown;
|
|
1059
1059
|
},
|
|
1060
1060
|
reopened() {
|
|
1061
|
+
relisting = null;
|
|
1061
1062
|
for (const [operation, dispatch] of sending)
|
|
1062
1063
|
if (!dispatch.answered)
|
|
1063
1064
|
sending.delete(operation);
|
|
@@ -1105,56 +1106,50 @@ export function createConversationStore(deps) {
|
|
|
1105
1106
|
};
|
|
1106
1107
|
},
|
|
1107
1108
|
watchList(deliver) {
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
if (ended)
|
|
1111
|
-
return;
|
|
1112
|
-
unlisted.add(deliver);
|
|
1113
|
-
learned();
|
|
1114
|
-
});
|
|
1109
|
+
unlisted.add(deliver);
|
|
1110
|
+
learned();
|
|
1115
1111
|
return () => {
|
|
1116
|
-
ended = true;
|
|
1117
1112
|
unlisted.delete(deliver);
|
|
1118
1113
|
listWatchers.delete(deliver);
|
|
1119
1114
|
};
|
|
1120
1115
|
},
|
|
1121
1116
|
watchAgents(deliver) {
|
|
1122
1117
|
unnamed.add(deliver);
|
|
1123
|
-
|
|
1118
|
+
learned();
|
|
1119
|
+
readAgents();
|
|
1124
1120
|
return () => {
|
|
1125
1121
|
unnamed.delete(deliver);
|
|
1126
1122
|
agentWatchers.delete(deliver);
|
|
1127
1123
|
};
|
|
1128
1124
|
},
|
|
1129
1125
|
learned,
|
|
1130
|
-
declared() {
|
|
1131
|
-
if (JSON.stringify(deps.agents()) === agentsFrom)
|
|
1132
|
-
return;
|
|
1133
|
-
agentsRead = readAgents().catch(() => {
|
|
1134
|
-
agentsRead = null;
|
|
1135
|
-
});
|
|
1136
|
-
},
|
|
1137
1126
|
changed(set) {
|
|
1138
1127
|
for (const conversation of set.conversations)
|
|
1139
1128
|
emit(conversation);
|
|
1140
|
-
const declaration = deps.agents();
|
|
1141
|
-
if (declaration !== undefined &&
|
|
1142
|
-
set.documents.some((change) => change.locator === declaration.locator)) {
|
|
1143
|
-
agentsRead = readAgents().catch(() => {
|
|
1144
|
-
agentsRead = null;
|
|
1145
|
-
});
|
|
1146
|
-
}
|
|
1147
1129
|
},
|
|
1148
1130
|
receive(event) {
|
|
1149
1131
|
if (deps.closed())
|
|
1150
1132
|
return false;
|
|
1151
1133
|
if (event.kind === 'list' || event.kind === 'listed' || event.kind === 'unlisted') {
|
|
1152
1134
|
if (event.kind === 'list') {
|
|
1153
|
-
|
|
1135
|
+
if (event.whole)
|
|
1136
|
+
relisting ??= new Map();
|
|
1154
1137
|
for (const entry of event.entries) {
|
|
1155
|
-
|
|
1156
|
-
|
|
1138
|
+
if (relisting === null)
|
|
1139
|
+
listed(entry);
|
|
1140
|
+
else
|
|
1141
|
+
relisting.set(entry.conversation, { ...entry });
|
|
1157
1142
|
}
|
|
1143
|
+
if (event.more)
|
|
1144
|
+
return false;
|
|
1145
|
+
if (relisting !== null) {
|
|
1146
|
+
listing.clear();
|
|
1147
|
+
for (const entry of relisting.values())
|
|
1148
|
+
listed(entry);
|
|
1149
|
+
relisting = null;
|
|
1150
|
+
}
|
|
1151
|
+
listCursor = event.cursor;
|
|
1152
|
+
deps.stream()?.hold(event.cursor);
|
|
1158
1153
|
listKnown = true;
|
|
1159
1154
|
for (const conversation of replicated) {
|
|
1160
1155
|
if (!listing.has(conversation))
|
|
@@ -1167,28 +1162,24 @@ export function createConversationStore(deps) {
|
|
|
1167
1162
|
openingEnded();
|
|
1168
1163
|
}
|
|
1169
1164
|
else if (event.kind === 'listed') {
|
|
1170
|
-
|
|
1171
|
-
|
|
1165
|
+
listed(event.entry);
|
|
1166
|
+
relisting?.set(event.entry.conversation, { ...event.entry });
|
|
1172
1167
|
}
|
|
1173
1168
|
else {
|
|
1174
1169
|
listing.delete(event.conversation);
|
|
1170
|
+
relisting?.delete(event.conversation);
|
|
1175
1171
|
}
|
|
1176
1172
|
keepList();
|
|
1177
1173
|
emitList();
|
|
1178
|
-
return (event.kind !== 'list' &&
|
|
1174
|
+
return ((event.kind !== 'list' &&
|
|
1179
1175
|
listKnown &&
|
|
1180
1176
|
(listing.size !== replicated.size ||
|
|
1181
|
-
[...listing.keys()].some((conversation) => !replicated.has(conversation))))
|
|
1177
|
+
[...listing.keys()].some((conversation) => !replicated.has(conversation)))) ||
|
|
1178
|
+
(listKnown && [...drafts.keys()].some(retiredChat)));
|
|
1182
1179
|
}
|
|
1183
1180
|
heard(event);
|
|
1184
1181
|
return false;
|
|
1185
1182
|
},
|
|
1186
|
-
searchable() {
|
|
1187
|
-
return [...(listKnown ? listing.keys() : stored)].sort();
|
|
1188
|
-
},
|
|
1189
|
-
acquired(conversation) {
|
|
1190
|
-
return reads.has(conversation) && !partials.has(conversation);
|
|
1191
|
-
},
|
|
1192
1183
|
close() {
|
|
1193
1184
|
views.clear();
|
|
1194
1185
|
lives.clear();
|
package/dist/durability.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { Persistence } from './readiness.js';
|
|
|
2
2
|
export type RuntimeShell = {
|
|
3
3
|
persistence: Persistence;
|
|
4
4
|
generation: string | null;
|
|
5
|
-
onScreen: boolean;
|
|
6
5
|
keepGeneration(value: string): void | Promise<void>;
|
|
7
6
|
dropGeneration(): void | Promise<void>;
|
|
8
7
|
cleanUp?(): Promise<number>;
|
package/dist/durability.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durability.d.ts","sourceRoot":"","sources":["../src/durability.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAIlD,MAAM,MAAM,YAAY,GAAG;IACzB,WAAW,EAAE,WAAW,CAAC;IACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,
|
|
1
|
+
{"version":3,"file":"durability.d.ts","sourceRoot":"","sources":["../src/durability.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAIlD,MAAM,MAAM,YAAY,GAAG;IACzB,WAAW,EAAE,WAAW,CAAC;IACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,cAAc,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7B,CAAC;AAEF,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAMvD;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAG/F;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAGrF"}
|
package/dist/entry.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type VerifiedModel } from '@agentshouse/mdmodel';
|
|
2
2
|
import { type QueryRows } from './query.js';
|
|
3
3
|
import type { Connection } from './tables.js';
|
|
4
|
-
export { QueryError } from '
|
|
4
|
+
export { QueryError } from '@agentshouse/mdmodel';
|
|
5
5
|
export type EntryRoom = {
|
|
6
6
|
locator: string;
|
|
7
7
|
schema: string | null;
|
package/dist/entry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,aAAa,EACnB,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EAAyB,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAEnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5C,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC9C,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE9D,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;AA0D7E,wBAAgB,UAAU,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAE3E;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,MAAM,EAAE,CAMpE;AAyCD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAQ7D;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;CACzF,CAAC;AAEF,wBAAgB,UAAU,CACxB,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,SAAS,EAAE,aAAa,EACxB,UAAU,EAAE,UAAU,GACrB,UAAU,CAoDZ"}
|
package/dist/entry.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { invalid, plain, QueryError, } from '@agentshouse/mdmodel';
|
|
1
2
|
import { attachedModel } from './attached-model.js';
|
|
2
3
|
import { answerQuery } from './compile.js';
|
|
3
4
|
import { NO_MODEL } from './model.js';
|
|
4
|
-
import {
|
|
5
|
+
import { planWithin } from './query.js';
|
|
5
6
|
import { entered, REPLICA_TABLES } from './stored.js';
|
|
6
|
-
export { QueryError } from '
|
|
7
|
+
export { QueryError } from '@agentshouse/mdmodel';
|
|
7
8
|
const PARAMETER = '$param';
|
|
8
9
|
const KIND = 'as';
|
|
9
10
|
const INTEGER = /^-?(?:0|[1-9][0-9]*)$/u;
|
|
@@ -83,6 +84,7 @@ const SAMPLED = {
|
|
|
83
84
|
$all: 'entry',
|
|
84
85
|
$size: 0,
|
|
85
86
|
$exists: true,
|
|
87
|
+
$prefix: 'entry',
|
|
86
88
|
$gt: 0,
|
|
87
89
|
$gte: 0,
|
|
88
90
|
$lt: 0,
|
|
@@ -98,9 +100,15 @@ function sampled(template, key) {
|
|
|
98
100
|
}
|
|
99
101
|
return template;
|
|
100
102
|
}
|
|
103
|
+
function entryPlan(query, facts) {
|
|
104
|
+
const plan = planWithin(query, facts);
|
|
105
|
+
if (plan.fileIds !== null)
|
|
106
|
+
invalid('fileIds', 'an entry Room holds no file IDs');
|
|
107
|
+
return plan;
|
|
108
|
+
}
|
|
101
109
|
export function entryRefusal(template) {
|
|
102
110
|
try {
|
|
103
|
-
|
|
111
|
+
entryPlan(sampled(template, ''), { listed: false, rooms: [] });
|
|
104
112
|
return null;
|
|
105
113
|
}
|
|
106
114
|
catch (error) {
|
|
@@ -123,12 +131,13 @@ export function entryScope(rooms, roomTypes, connection) {
|
|
|
123
131
|
available: model.status !== 'unavailable',
|
|
124
132
|
types: model.status === 'unavailable' ? [] : Object.values(model.types),
|
|
125
133
|
});
|
|
126
|
-
const composition = { model, selection: null };
|
|
134
|
+
const composition = { model, selection: null, typedPaths: [] };
|
|
127
135
|
const key = entered(connection, room.locator, composition, Object.keys(room.documents)
|
|
128
136
|
.sort()
|
|
129
137
|
.map((path) => ({
|
|
130
138
|
path,
|
|
131
139
|
content: room.documents[path],
|
|
140
|
+
outline: null,
|
|
132
141
|
binary: null,
|
|
133
142
|
revision: room.revisions?.[path] ?? null,
|
|
134
143
|
fileId: null,
|
|
@@ -142,7 +151,7 @@ export function entryScope(rooms, roomTypes, connection) {
|
|
|
142
151
|
async results(queries) {
|
|
143
152
|
const results = {};
|
|
144
153
|
for (const [name, query] of Object.entries(queries)) {
|
|
145
|
-
const plan =
|
|
154
|
+
const plan = entryPlan(query, planned);
|
|
146
155
|
results[name] = answerQuery(connection, plan, keys.filter(({ locator }) => plan.rooms === null || plan.rooms.includes(locator)));
|
|
147
156
|
}
|
|
148
157
|
return results;
|
package/dist/host.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type MdRuntimeOptions } from './connection.js';
|
|
2
2
|
import type { PortReach } from './reach.js';
|
|
3
|
-
import type { CodeAvailability, Persistence, Readiness
|
|
3
|
+
import type { CodeAvailability, Persistence, Readiness } from './readiness.js';
|
|
4
4
|
import type { EntrySeed } from './seed.js';
|
|
5
5
|
import { type RuntimePort } from './wire.js';
|
|
6
6
|
export type MdRuntimeHostOptions = MdRuntimeOptions & {
|
|
@@ -11,22 +11,18 @@ export type AttachedPort = {
|
|
|
11
11
|
narrow(reach: PortReach): void;
|
|
12
12
|
readiness(deliver: (readiness: Readiness) => void): () => void;
|
|
13
13
|
answered(queries: readonly unknown[], done: () => void): void;
|
|
14
|
-
code(code: CodeAvailability, space: Space | null): void;
|
|
15
|
-
search(search: SearchObligation): void;
|
|
16
14
|
};
|
|
17
15
|
export type MdRuntimeHost = {
|
|
18
|
-
attach(port: RuntimePort, app: string, release?: string, reach?: PortReach, code?: CodeAvailability
|
|
16
|
+
attach(port: RuntimePort, app: string, release?: string, reach?: PortReach, code?: CodeAvailability): AttachedPort;
|
|
19
17
|
seed(entry: EntrySeed): void;
|
|
20
18
|
persisted(answer: Persistence): void;
|
|
21
|
-
shown(onScreen: boolean): void;
|
|
22
19
|
endAuthorization(holder?: string): Promise<void>;
|
|
23
|
-
lose(locators: readonly string[]): Promise<void>;
|
|
24
20
|
stop(): Promise<void>;
|
|
25
21
|
};
|
|
26
22
|
export declare function serveMdRuntime(options: MdRuntimeHostOptions): MdRuntimeHost;
|
|
27
23
|
export { entrySeedOf, type EntrySeed } from './seed.js';
|
|
28
24
|
export type { PortReach, ReachedDocument } from './reach.js';
|
|
29
|
-
export type { CodeAvailability, Persistence,
|
|
25
|
+
export type { CodeAvailability, Persistence, Space } from './readiness.js';
|
|
30
26
|
export { createRecovery, retryDelay, type Attempt, type Attempted, type AttemptOptions, type Recovery, type RecoveryOptions, } from './recovery.js';
|
|
31
27
|
export type { RuntimePort } from './wire.js';
|
|
32
28
|
//# sourceMappingURL=host.d.ts.map
|