@agentshouse/mdruntime 0.1.0-cba6f2439bb25 → 0.1.0-cbe358f60d1d3
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 +66 -52
- package/dist/adapter.d.ts.map +1 -1
- package/dist/bootstrap.d.ts +6 -9
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +28 -22
- package/dist/chain.d.ts +2 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/client.d.ts +9 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -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 +91 -276
- package/dist/connection.d.ts +8 -8
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +738 -968
- 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 -14
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +141 -167
- package/dist/durability.d.ts +6 -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 +13 -5
- package/dist/host.d.ts +3 -7
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +22 -27
- package/dist/identity.d.ts +0 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +0 -3
- package/dist/index.d.ts +11 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -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/media.d.ts +1 -1
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +19 -9
- package/dist/memory.d.ts +9 -4
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +132 -82
- 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 +4 -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 +34 -45
- 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/recovery.d.ts +1 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +26 -0
- package/dist/refresh.d.ts +6 -4
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +26 -5
- package/dist/replica.d.ts +2 -2
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +2 -5
- package/dist/room-draft.d.ts +4 -3
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +65 -52
- package/dist/rows.d.ts +1 -17
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +4 -137
- 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 +5 -20
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +10 -44
- package/dist/stored.d.ts +0 -6
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +42 -115
- package/dist/tables.d.ts +10 -34
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +23 -57
- 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 +9 -4
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +3 -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,9 +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
|
-
import {
|
|
7
|
+
import { untilAnswered } from './recovery.js';
|
|
8
|
+
import { capped, FROM_START, messageOrder, precedes } from './windows.js';
|
|
7
9
|
const QUIET = {
|
|
8
10
|
turn: null,
|
|
9
11
|
questions: [],
|
|
@@ -11,6 +13,7 @@ const QUIET = {
|
|
|
11
13
|
commands: [],
|
|
12
14
|
options: [],
|
|
13
15
|
starting: null,
|
|
16
|
+
subagents: [],
|
|
14
17
|
link: null,
|
|
15
18
|
deliveryUnknown: [],
|
|
16
19
|
};
|
|
@@ -20,6 +23,7 @@ const FACTS = [
|
|
|
20
23
|
'commands',
|
|
21
24
|
'options',
|
|
22
25
|
'starting',
|
|
26
|
+
'subagents',
|
|
23
27
|
'link',
|
|
24
28
|
'deliveryUnknown',
|
|
25
29
|
];
|
|
@@ -30,9 +34,11 @@ export function unheldView(conversation) {
|
|
|
30
34
|
turn: null,
|
|
31
35
|
questions: [],
|
|
32
36
|
process: null,
|
|
37
|
+
processEnded: null,
|
|
33
38
|
commands: [],
|
|
34
39
|
options: [],
|
|
35
40
|
starting: null,
|
|
41
|
+
subagents: [],
|
|
36
42
|
link: null,
|
|
37
43
|
deliveryUnknown: [],
|
|
38
44
|
chatDraft: null,
|
|
@@ -47,10 +53,8 @@ export function newChat(agent) {
|
|
|
47
53
|
function creationOf(input) {
|
|
48
54
|
if (typeof input !== 'object' || input === null)
|
|
49
55
|
return null;
|
|
50
|
-
const { agent_id: agent, operation_id: operation
|
|
51
|
-
return typeof agent === 'string' && typeof operation === 'string'
|
|
52
|
-
? { agent, operation }
|
|
53
|
-
: null;
|
|
56
|
+
const { agent_id: agent, operation_id: operation } = input;
|
|
57
|
+
return typeof agent === 'string' && typeof operation === 'string' ? { agent, operation } : null;
|
|
54
58
|
}
|
|
55
59
|
function startedTurn(turn, operation) {
|
|
56
60
|
if (operation.op === 'begin')
|
|
@@ -209,7 +213,14 @@ function askedOf(options) {
|
|
|
209
213
|
}
|
|
210
214
|
return { limit: capped(limit), after, before: beforeOf(after), total: total === true };
|
|
211
215
|
}
|
|
212
|
-
|
|
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 DURABLE_WRITE = {
|
|
214
225
|
kind: 'rejected',
|
|
215
226
|
code: 'durable-write',
|
|
@@ -255,6 +266,8 @@ export function createConversationStore(deps) {
|
|
|
255
266
|
const unsent = new Map();
|
|
256
267
|
const views = new Map();
|
|
257
268
|
const listing = new Map();
|
|
269
|
+
let relisting = null;
|
|
270
|
+
let listCursor = null;
|
|
258
271
|
const creations = new Set();
|
|
259
272
|
const listWatchers = new Set();
|
|
260
273
|
const unlisted = new Set();
|
|
@@ -263,11 +276,9 @@ export function createConversationStore(deps) {
|
|
|
263
276
|
let listKept = false;
|
|
264
277
|
const agentWatchers = new Set();
|
|
265
278
|
const unnamed = new Set();
|
|
266
|
-
let
|
|
267
|
-
let
|
|
268
|
-
let
|
|
269
|
-
let agentsRead = null;
|
|
270
|
-
let agentsFrom;
|
|
279
|
+
let agentsShown = null;
|
|
280
|
+
let listedAgents = null;
|
|
281
|
+
let agentsReading = false;
|
|
271
282
|
let replicated = new Set();
|
|
272
283
|
let handedReplicated;
|
|
273
284
|
function liveOf(conversation) {
|
|
@@ -288,9 +299,11 @@ export function createConversationStore(deps) {
|
|
|
288
299
|
turn: structuredClone(facts.turn),
|
|
289
300
|
questions: structuredClone(facts.questions),
|
|
290
301
|
process: facts.process === null ? null : { ...facts.process },
|
|
302
|
+
processEnded: listing.get(conversation)?.processEnded ?? null,
|
|
291
303
|
commands: structuredClone(facts.commands),
|
|
292
304
|
options: structuredClone(facts.options),
|
|
293
305
|
starting: facts.starting,
|
|
306
|
+
subagents: structuredClone(facts.subagents),
|
|
294
307
|
link: facts.link === null ? null : { ...facts.link },
|
|
295
308
|
deliveryUnknown: [...facts.deliveryUnknown],
|
|
296
309
|
chatDraft: draft === undefined || unwritten(draft)
|
|
@@ -346,7 +359,7 @@ export function createConversationStore(deps) {
|
|
|
346
359
|
function entries() {
|
|
347
360
|
return [...listing.values()].map((entry) => ({
|
|
348
361
|
conversation: entry.conversation,
|
|
349
|
-
agent: { identity: entry.agent, name:
|
|
362
|
+
agent: { identity: entry.agent, name: entry.agentName },
|
|
350
363
|
name: entry.name,
|
|
351
364
|
created: entry.created,
|
|
352
365
|
finished: entry.finished,
|
|
@@ -365,9 +378,22 @@ export function createConversationStore(deps) {
|
|
|
365
378
|
if (deps.closed())
|
|
366
379
|
return;
|
|
367
380
|
const entries = [...listing.values()];
|
|
368
|
-
|
|
381
|
+
const cursor = listCursor;
|
|
382
|
+
void deps
|
|
383
|
+
.durably(async (local) => {
|
|
384
|
+
await local.fact('conversationList', entries);
|
|
385
|
+
await local.fact('conversationCursor', cursor);
|
|
386
|
+
})
|
|
387
|
+
.catch(() => { });
|
|
369
388
|
});
|
|
370
389
|
}
|
|
390
|
+
function listed(entry) {
|
|
391
|
+
const ended = listing.get(entry.conversation)?.processEnded ?? null;
|
|
392
|
+
listing.set(entry.conversation, { ...entry });
|
|
393
|
+
creations.delete(entry.conversation);
|
|
394
|
+
if (entry.processEnded !== ended)
|
|
395
|
+
emit(entry.conversation);
|
|
396
|
+
}
|
|
371
397
|
function emitList() {
|
|
372
398
|
if (deps.closed())
|
|
373
399
|
return;
|
|
@@ -376,18 +402,15 @@ export function createConversationStore(deps) {
|
|
|
376
402
|
for (const watcher of listWatchers)
|
|
377
403
|
watcher(value);
|
|
378
404
|
}
|
|
405
|
+
emitAgents();
|
|
379
406
|
learned();
|
|
380
407
|
}
|
|
381
|
-
function unlearnable() {
|
|
382
|
-
return !deps.online() || (deps.listed() && deps.agents() === undefined);
|
|
383
|
-
}
|
|
384
408
|
function learned() {
|
|
385
409
|
if (deps.closed())
|
|
386
410
|
return;
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
(listKnown || listHeld || deps.stream() === undefined || unlearnable())) {
|
|
411
|
+
if (!listKnown && !listHeld && deps.stream() !== undefined && deps.online())
|
|
412
|
+
return;
|
|
413
|
+
if (unlisted.size > 0) {
|
|
391
414
|
const value = entries();
|
|
392
415
|
for (const watcher of [...unlisted]) {
|
|
393
416
|
unlisted.delete(watcher);
|
|
@@ -395,7 +418,7 @@ export function createConversationStore(deps) {
|
|
|
395
418
|
watcher(value);
|
|
396
419
|
}
|
|
397
420
|
}
|
|
398
|
-
if (unnamed.size > 0
|
|
421
|
+
if (unnamed.size > 0) {
|
|
399
422
|
const value = agents();
|
|
400
423
|
for (const watcher of [...unnamed]) {
|
|
401
424
|
unnamed.delete(watcher);
|
|
@@ -405,17 +428,44 @@ export function createConversationStore(deps) {
|
|
|
405
428
|
}
|
|
406
429
|
}
|
|
407
430
|
function agents() {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
.
|
|
431
|
+
const named = new Map();
|
|
432
|
+
for (const agent of listedAgents ?? [])
|
|
433
|
+
named.set(agent.agent, agent);
|
|
434
|
+
for (const entry of listing.values()) {
|
|
435
|
+
named.set(entry.agent, { name: entry.agentName, retired: entry.agentRetired });
|
|
436
|
+
}
|
|
437
|
+
return [...named]
|
|
438
|
+
.filter(([, agent]) => !agent.retired)
|
|
439
|
+
.map(([identity, agent]) => ({ identity, name: agent.name }))
|
|
411
440
|
.sort((left, right) => left.name === right.name
|
|
412
441
|
? left.identity.localeCompare(right.identity)
|
|
413
442
|
: left.name.localeCompare(right.name));
|
|
414
443
|
}
|
|
444
|
+
function readAgents() {
|
|
445
|
+
const stream = deps.stream();
|
|
446
|
+
if (stream?.agents === undefined || !deps.online() || agentsReading)
|
|
447
|
+
return;
|
|
448
|
+
agentsReading = true;
|
|
449
|
+
void stream
|
|
450
|
+
.agents()
|
|
451
|
+
.then((read) => {
|
|
452
|
+
if (read === null)
|
|
453
|
+
return;
|
|
454
|
+
listedAgents = read;
|
|
455
|
+
emitAgents();
|
|
456
|
+
}, () => { })
|
|
457
|
+
.finally(() => {
|
|
458
|
+
agentsReading = false;
|
|
459
|
+
});
|
|
460
|
+
}
|
|
415
461
|
function emitAgents() {
|
|
416
462
|
if (deps.closed() || agentWatchers.size === 0)
|
|
417
463
|
return;
|
|
418
464
|
const value = agents();
|
|
465
|
+
const shown = JSON.stringify(value);
|
|
466
|
+
if (shown === agentsShown)
|
|
467
|
+
return;
|
|
468
|
+
agentsShown = shown;
|
|
419
469
|
for (const watcher of agentWatchers)
|
|
420
470
|
watcher(value);
|
|
421
471
|
}
|
|
@@ -431,60 +481,11 @@ export function createConversationStore(deps) {
|
|
|
431
481
|
if (stateOf(conversation) !== before || next?.turn?.started !== began)
|
|
432
482
|
emitList();
|
|
433
483
|
}
|
|
434
|
-
async function readAgents() {
|
|
435
|
-
const declaration = deps.agents();
|
|
436
|
-
agentsFrom = JSON.stringify(declaration);
|
|
437
|
-
if (declaration === undefined)
|
|
438
|
-
return;
|
|
439
|
-
const names = new Map();
|
|
440
|
-
const retired = new Set();
|
|
441
|
-
let covered = null;
|
|
442
|
-
for (let after;;) {
|
|
443
|
-
const read = await deps.documents(declaration, after);
|
|
444
|
-
if ('pending' in read)
|
|
445
|
-
return;
|
|
446
|
-
const coverage = JSON.stringify(read.coverage);
|
|
447
|
-
if (covered !== null && coverage !== covered)
|
|
448
|
-
return readAgents();
|
|
449
|
-
covered = coverage;
|
|
450
|
-
for (const document of read.documents) {
|
|
451
|
-
const identity = document.fields?.[declaration.identity];
|
|
452
|
-
const name = document.fields?.[declaration.name];
|
|
453
|
-
if (typeof identity !== 'string' || typeof name !== 'string')
|
|
454
|
-
continue;
|
|
455
|
-
names.set(identity, name);
|
|
456
|
-
const ended = declaration.retired === undefined ? null : document.fields?.[declaration.retired];
|
|
457
|
-
if (ended !== undefined && ended !== null)
|
|
458
|
-
retired.add(identity);
|
|
459
|
-
}
|
|
460
|
-
if (read.next === undefined)
|
|
461
|
-
break;
|
|
462
|
-
after = read.next;
|
|
463
|
-
}
|
|
464
|
-
agentsKnown = true;
|
|
465
|
-
const named = JSON.stringify([...names]) !== JSON.stringify([...agentNames]);
|
|
466
|
-
if (!named && JSON.stringify([...retired]) === JSON.stringify([...retiredAgents])) {
|
|
467
|
-
learned();
|
|
468
|
-
return;
|
|
469
|
-
}
|
|
470
|
-
agentNames = names;
|
|
471
|
-
retiredAgents = retired;
|
|
472
|
-
emitAgents();
|
|
473
|
-
if (named)
|
|
474
|
-
emitList();
|
|
475
|
-
learned();
|
|
476
|
-
const ended = [...drafts.keys()].filter(retiredChat);
|
|
477
|
-
if (ended.length > 0)
|
|
478
|
-
await remove(ended);
|
|
479
|
-
}
|
|
480
484
|
function retiredChat(conversation) {
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
agentsRead = null;
|
|
486
|
-
});
|
|
487
|
-
return agentsRead;
|
|
485
|
+
if (!conversation.startsWith(NEW_CHAT))
|
|
486
|
+
return false;
|
|
487
|
+
const agent = conversation.slice(NEW_CHAT.length);
|
|
488
|
+
return [...listing.values()].some((entry) => entry.agent === agent && entry.agentRetired);
|
|
488
489
|
}
|
|
489
490
|
function live(conversation, change) {
|
|
490
491
|
const owed = unsent.get(conversation);
|
|
@@ -507,6 +508,7 @@ export function createConversationStore(deps) {
|
|
|
507
508
|
commands: facts.has('commands') ? QUIET.commands : held.commands,
|
|
508
509
|
options: facts.has('options') ? QUIET.options : held.options,
|
|
509
510
|
starting: facts.has('starting') ? QUIET.starting : held.starting,
|
|
511
|
+
subagents: facts.has('subagents') ? QUIET.subagents : held.subagents,
|
|
510
512
|
link: facts.has('link') ? QUIET.link : held.link,
|
|
511
513
|
deliveryUnknown: facts.has('deliveryUnknown')
|
|
512
514
|
? QUIET.deliveryUnknown
|
|
@@ -608,7 +610,7 @@ export function createConversationStore(deps) {
|
|
|
608
610
|
}));
|
|
609
611
|
while (waiting.length > 0) {
|
|
610
612
|
const asking = waiting.slice(0, HISTORY_CONVERSATIONS);
|
|
611
|
-
const result = await deps.
|
|
613
|
+
const result = await deps.history({
|
|
612
614
|
conversations: asking.map(({ conversation, after }) => ({
|
|
613
615
|
conversation,
|
|
614
616
|
...(after === undefined ? {} : { after }),
|
|
@@ -711,6 +713,10 @@ export function createConversationStore(deps) {
|
|
|
711
713
|
live(conversation, { starting: event.step });
|
|
712
714
|
return;
|
|
713
715
|
}
|
|
716
|
+
if (event.kind === 'subagents') {
|
|
717
|
+
live(conversation, { subagents: structuredClone(event.subagents) });
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
714
720
|
if (event.kind === 'link') {
|
|
715
721
|
live(conversation, { link: { connected: event.connected } });
|
|
716
722
|
return;
|
|
@@ -760,7 +766,7 @@ export function createConversationStore(deps) {
|
|
|
760
766
|
const from = newChat(agent);
|
|
761
767
|
return deps.durably(async (local) => {
|
|
762
768
|
const held = drafts.get(from);
|
|
763
|
-
const earlier =
|
|
769
|
+
const earlier = held?.moves ?? [];
|
|
764
770
|
if (earlier.includes(operation))
|
|
765
771
|
return;
|
|
766
772
|
const blank = {
|
|
@@ -789,10 +795,8 @@ export function createConversationStore(deps) {
|
|
|
789
795
|
}
|
|
790
796
|
async function submitted(conversation, operation, draft) {
|
|
791
797
|
let submission;
|
|
792
|
-
let earlier = false;
|
|
793
798
|
await withDraft(conversation, (current) => {
|
|
794
799
|
submission = current?.submitted?.find((one) => one.operation === operation);
|
|
795
|
-
earlier = submission !== undefined;
|
|
796
800
|
if (submission !== undefined)
|
|
797
801
|
return undefined;
|
|
798
802
|
const said = draft ?? current;
|
|
@@ -805,23 +809,15 @@ export function createConversationStore(deps) {
|
|
|
805
809
|
submitted: [...(current?.submitted ?? []), submission],
|
|
806
810
|
};
|
|
807
811
|
});
|
|
808
|
-
return
|
|
809
|
-
}
|
|
810
|
-
function forgotten(conversation, submission) {
|
|
811
|
-
return withDraft(conversation, (current) => {
|
|
812
|
-
const held = current?.submitted ?? [];
|
|
813
|
-
if (current === undefined || !held.includes(submission))
|
|
814
|
-
return undefined;
|
|
815
|
-
return withSubmitted(current, held.filter((one) => one !== submission));
|
|
816
|
-
});
|
|
812
|
+
return submission;
|
|
817
813
|
}
|
|
818
814
|
async function dispatched(conversation, submission) {
|
|
819
815
|
const dispatch = { answered: false };
|
|
820
816
|
sending.set(submission.operation, dispatch);
|
|
821
817
|
try {
|
|
822
|
-
const result = await invoke('
|
|
823
|
-
text: submission.text,
|
|
818
|
+
const result = await invoke('conversations/send', conversation, {
|
|
824
819
|
operation_id: submission.operation,
|
|
820
|
+
text: submission.text,
|
|
825
821
|
});
|
|
826
822
|
dispatch.answered = result.kind !== 'transport-uncertainty';
|
|
827
823
|
if (result.kind === 'revoked-authorization')
|
|
@@ -830,7 +826,7 @@ export function createConversationStore(deps) {
|
|
|
830
826
|
deps.unanswered();
|
|
831
827
|
return result;
|
|
832
828
|
}
|
|
833
|
-
const turn = answered(result, '
|
|
829
|
+
const turn = answered(result, 'message_id');
|
|
834
830
|
await withDraft(conversation, async (current, local) => {
|
|
835
831
|
const held = current?.submitted?.find((one) => one.operation === submission.operation);
|
|
836
832
|
if (current === undefined || held === undefined || held.turn !== null)
|
|
@@ -850,12 +846,11 @@ export function createConversationStore(deps) {
|
|
|
850
846
|
sending.delete(submission.operation);
|
|
851
847
|
}
|
|
852
848
|
}
|
|
853
|
-
function invoke(name, conversation, extra = {}) {
|
|
854
|
-
return deps.call(name, { conversation, ...extra });
|
|
849
|
+
function invoke(name, conversation, extra = { operation_id: changeBatchIdentity() }) {
|
|
850
|
+
return deps.call(name, { conversation_id: conversation, ...extra });
|
|
855
851
|
}
|
|
856
852
|
const surface = {
|
|
857
|
-
|
|
858
|
-
await agentsReady();
|
|
853
|
+
list() {
|
|
859
854
|
return new Promise((settle) => {
|
|
860
855
|
const answer = (listed) => {
|
|
861
856
|
unlisted.delete(answer);
|
|
@@ -867,16 +862,18 @@ export function createConversationStore(deps) {
|
|
|
867
862
|
});
|
|
868
863
|
},
|
|
869
864
|
async read(conversation, options = {}) {
|
|
870
|
-
const
|
|
865
|
+
const { text, ...windowed } = options;
|
|
866
|
+
const asked = askedOf(windowed);
|
|
867
|
+
const phrase = phraseOf(text);
|
|
871
868
|
return deps.durably(async (local) => {
|
|
872
|
-
const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before);
|
|
873
|
-
const total = asked.total ? await local.messageCount(conversation) : null;
|
|
869
|
+
const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before, phrase);
|
|
870
|
+
const total = asked.total ? await local.messageCount(conversation, phrase) : null;
|
|
874
871
|
return structuredClone(viewOf(conversation, messages, frameOf(asked, messages, more, total)));
|
|
875
872
|
});
|
|
876
873
|
},
|
|
877
874
|
async create(input) {
|
|
878
|
-
const result = await deps.call('
|
|
879
|
-
const conversation = answered(result, '
|
|
875
|
+
const result = await deps.call('conversations/create', input);
|
|
876
|
+
const conversation = answered(result, 'conversation_id');
|
|
880
877
|
if (conversation === null)
|
|
881
878
|
return result;
|
|
882
879
|
if (!listing.has(conversation))
|
|
@@ -897,11 +894,7 @@ export function createConversationStore(deps) {
|
|
|
897
894
|
});
|
|
898
895
|
if (held === null)
|
|
899
896
|
return DURABLE_WRITE;
|
|
900
|
-
|
|
901
|
-
if (!earlier || !deps.expired(operation))
|
|
902
|
-
return dispatched(conversation, submission);
|
|
903
|
-
await forgotten(conversation, submission);
|
|
904
|
-
return EXPIRED;
|
|
897
|
+
return dispatched(conversation, held);
|
|
905
898
|
}
|
|
906
899
|
if (draft !== undefined) {
|
|
907
900
|
await withDraft(conversation, (current) => current?.submitted?.some((one) => one.operation === operation) === true
|
|
@@ -911,28 +904,19 @@ export function createConversationStore(deps) {
|
|
|
911
904
|
return OFFLINE;
|
|
912
905
|
},
|
|
913
906
|
answer(conversation, answer) {
|
|
914
|
-
return invoke('
|
|
907
|
+
return invoke('conversations/interaction/answer', conversation, {
|
|
908
|
+
operation_id: changeBatchIdentity(),
|
|
909
|
+
...answer,
|
|
910
|
+
});
|
|
915
911
|
},
|
|
916
912
|
interrupt(conversation) {
|
|
917
|
-
return invoke('
|
|
913
|
+
return invoke('conversations/interrupt', conversation);
|
|
918
914
|
},
|
|
919
915
|
kill(conversation) {
|
|
920
|
-
return invoke('
|
|
921
|
-
},
|
|
922
|
-
async cancel(conversation, turn) {
|
|
923
|
-
const result = await invoke('conversation.cancel', conversation, { turn });
|
|
924
|
-
if (result.kind !== 'action')
|
|
925
|
-
return result;
|
|
926
|
-
await withDraft(conversation, (current) => {
|
|
927
|
-
const held = current?.submitted?.find((one) => one.turn === turn);
|
|
928
|
-
if (current === undefined || held === undefined)
|
|
929
|
-
return undefined;
|
|
930
|
-
return returned(current, held, current.submitted.filter((one) => one !== held));
|
|
931
|
-
});
|
|
932
|
-
return result;
|
|
916
|
+
return invoke('conversations/kill', conversation);
|
|
933
917
|
},
|
|
934
918
|
delete(conversation) {
|
|
935
|
-
return invoke('
|
|
919
|
+
return invoke('conversations/delete', conversation);
|
|
936
920
|
},
|
|
937
921
|
};
|
|
938
922
|
const chatDraft = {
|
|
@@ -961,12 +945,14 @@ export function createConversationStore(deps) {
|
|
|
961
945
|
return {
|
|
962
946
|
surface,
|
|
963
947
|
chatDraft,
|
|
964
|
-
hydrate(held, kept, list) {
|
|
948
|
+
hydrate(held, kept, list, cursor) {
|
|
965
949
|
if (list !== null && !listKnown) {
|
|
966
950
|
listing.clear();
|
|
967
951
|
for (const entry of list)
|
|
968
952
|
listing.set(entry.conversation, { ...entry });
|
|
969
953
|
listHeld = true;
|
|
954
|
+
listCursor = cursor;
|
|
955
|
+
deps.stream()?.hold(cursor);
|
|
970
956
|
}
|
|
971
957
|
stored.clear();
|
|
972
958
|
reads.clear();
|
|
@@ -1032,10 +1018,6 @@ export function createConversationStore(deps) {
|
|
|
1032
1018
|
continue;
|
|
1033
1019
|
if (deps.closed())
|
|
1034
1020
|
return;
|
|
1035
|
-
if (deps.expired(submission.operation)) {
|
|
1036
|
-
await forgotten(conversation, submission);
|
|
1037
|
-
continue;
|
|
1038
|
-
}
|
|
1039
1021
|
const result = await dispatched(conversation, submission);
|
|
1040
1022
|
if (result.kind === 'revoked-authorization')
|
|
1041
1023
|
return;
|
|
@@ -1057,6 +1039,7 @@ export function createConversationStore(deps) {
|
|
|
1057
1039
|
return listKnown;
|
|
1058
1040
|
},
|
|
1059
1041
|
reopened() {
|
|
1042
|
+
relisting = null;
|
|
1060
1043
|
for (const [operation, dispatch] of sending)
|
|
1061
1044
|
if (!dispatch.answered)
|
|
1062
1045
|
sending.delete(operation);
|
|
@@ -1078,15 +1061,15 @@ export function createConversationStore(deps) {
|
|
|
1078
1061
|
views.set(key, view);
|
|
1079
1062
|
const watcher = { notify: deliver, ready: false };
|
|
1080
1063
|
view.watchers.add(watcher);
|
|
1081
|
-
|
|
1082
|
-
|
|
1064
|
+
const reading = new AbortController();
|
|
1065
|
+
void untilAnswered(() => deps.durably(async (local) => {
|
|
1083
1066
|
if (view.window !== null)
|
|
1084
1067
|
return;
|
|
1085
1068
|
const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before);
|
|
1086
1069
|
view.window = messages;
|
|
1087
1070
|
view.more = more;
|
|
1088
1071
|
view.total = asked.total ? await local.messageCount(conversation) : null;
|
|
1089
|
-
})
|
|
1072
|
+
}), reading.signal)
|
|
1090
1073
|
.then(() => {
|
|
1091
1074
|
if (deps.closed() || !view.watchers.has(watcher))
|
|
1092
1075
|
return;
|
|
@@ -1096,6 +1079,7 @@ export function createConversationStore(deps) {
|
|
|
1096
1079
|
})
|
|
1097
1080
|
.catch(() => { });
|
|
1098
1081
|
return () => {
|
|
1082
|
+
reading.abort();
|
|
1099
1083
|
if (!view.watchers.delete(watcher))
|
|
1100
1084
|
return;
|
|
1101
1085
|
if (view.watchers.size === 0)
|
|
@@ -1103,56 +1087,50 @@ export function createConversationStore(deps) {
|
|
|
1103
1087
|
};
|
|
1104
1088
|
},
|
|
1105
1089
|
watchList(deliver) {
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
if (ended)
|
|
1109
|
-
return;
|
|
1110
|
-
unlisted.add(deliver);
|
|
1111
|
-
learned();
|
|
1112
|
-
});
|
|
1090
|
+
unlisted.add(deliver);
|
|
1091
|
+
learned();
|
|
1113
1092
|
return () => {
|
|
1114
|
-
ended = true;
|
|
1115
1093
|
unlisted.delete(deliver);
|
|
1116
1094
|
listWatchers.delete(deliver);
|
|
1117
1095
|
};
|
|
1118
1096
|
},
|
|
1119
1097
|
watchAgents(deliver) {
|
|
1120
1098
|
unnamed.add(deliver);
|
|
1121
|
-
|
|
1099
|
+
learned();
|
|
1100
|
+
readAgents();
|
|
1122
1101
|
return () => {
|
|
1123
1102
|
unnamed.delete(deliver);
|
|
1124
1103
|
agentWatchers.delete(deliver);
|
|
1125
1104
|
};
|
|
1126
1105
|
},
|
|
1127
1106
|
learned,
|
|
1128
|
-
declared() {
|
|
1129
|
-
if (JSON.stringify(deps.agents()) === agentsFrom)
|
|
1130
|
-
return;
|
|
1131
|
-
agentsRead = readAgents().catch(() => {
|
|
1132
|
-
agentsRead = null;
|
|
1133
|
-
});
|
|
1134
|
-
},
|
|
1135
1107
|
changed(set) {
|
|
1136
1108
|
for (const conversation of set.conversations)
|
|
1137
1109
|
emit(conversation);
|
|
1138
|
-
const declaration = deps.agents();
|
|
1139
|
-
if (declaration !== undefined &&
|
|
1140
|
-
set.documents.some((change) => change.locator === declaration.locator)) {
|
|
1141
|
-
agentsRead = readAgents().catch(() => {
|
|
1142
|
-
agentsRead = null;
|
|
1143
|
-
});
|
|
1144
|
-
}
|
|
1145
1110
|
},
|
|
1146
1111
|
receive(event) {
|
|
1147
1112
|
if (deps.closed())
|
|
1148
1113
|
return false;
|
|
1149
1114
|
if (event.kind === 'list' || event.kind === 'listed' || event.kind === 'unlisted') {
|
|
1150
1115
|
if (event.kind === 'list') {
|
|
1151
|
-
|
|
1116
|
+
if (event.whole)
|
|
1117
|
+
relisting ??= new Map();
|
|
1152
1118
|
for (const entry of event.entries) {
|
|
1153
|
-
|
|
1154
|
-
|
|
1119
|
+
if (relisting === null)
|
|
1120
|
+
listed(entry);
|
|
1121
|
+
else
|
|
1122
|
+
relisting.set(entry.conversation, { ...entry });
|
|
1123
|
+
}
|
|
1124
|
+
if (event.more)
|
|
1125
|
+
return false;
|
|
1126
|
+
if (relisting !== null) {
|
|
1127
|
+
listing.clear();
|
|
1128
|
+
for (const entry of relisting.values())
|
|
1129
|
+
listed(entry);
|
|
1130
|
+
relisting = null;
|
|
1155
1131
|
}
|
|
1132
|
+
listCursor = event.cursor;
|
|
1133
|
+
deps.stream()?.hold(event.cursor);
|
|
1156
1134
|
listKnown = true;
|
|
1157
1135
|
for (const conversation of replicated) {
|
|
1158
1136
|
if (!listing.has(conversation))
|
|
@@ -1165,28 +1143,24 @@ export function createConversationStore(deps) {
|
|
|
1165
1143
|
openingEnded();
|
|
1166
1144
|
}
|
|
1167
1145
|
else if (event.kind === 'listed') {
|
|
1168
|
-
|
|
1169
|
-
|
|
1146
|
+
listed(event.entry);
|
|
1147
|
+
relisting?.set(event.entry.conversation, { ...event.entry });
|
|
1170
1148
|
}
|
|
1171
1149
|
else {
|
|
1172
1150
|
listing.delete(event.conversation);
|
|
1151
|
+
relisting?.delete(event.conversation);
|
|
1173
1152
|
}
|
|
1174
1153
|
keepList();
|
|
1175
1154
|
emitList();
|
|
1176
|
-
return (event.kind !== 'list' &&
|
|
1155
|
+
return ((event.kind !== 'list' &&
|
|
1177
1156
|
listKnown &&
|
|
1178
1157
|
(listing.size !== replicated.size ||
|
|
1179
|
-
[...listing.keys()].some((conversation) => !replicated.has(conversation))))
|
|
1158
|
+
[...listing.keys()].some((conversation) => !replicated.has(conversation)))) ||
|
|
1159
|
+
(listKnown && [...drafts.keys()].some(retiredChat)));
|
|
1180
1160
|
}
|
|
1181
1161
|
heard(event);
|
|
1182
1162
|
return false;
|
|
1183
1163
|
},
|
|
1184
|
-
searchable() {
|
|
1185
|
-
return [...(listKnown ? listing.keys() : stored)].sort();
|
|
1186
|
-
},
|
|
1187
|
-
acquired(conversation) {
|
|
1188
|
-
return reads.has(conversation) && !partials.has(conversation);
|
|
1189
|
-
},
|
|
1190
1164
|
close() {
|
|
1191
1165
|
views.clear();
|
|
1192
1166
|
lives.clear();
|
package/dist/durability.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import type { Persistence } from './readiness.js';
|
|
2
|
+
export type UnsentKind = 'pending-change' | 'call' | 'room-draft' | 'chat-draft';
|
|
3
|
+
export type UnsentWork = {
|
|
4
|
+
readonly kind: UnsentKind;
|
|
5
|
+
readonly count: number;
|
|
6
|
+
};
|
|
2
7
|
export type RuntimeShell = {
|
|
3
8
|
persistence: Persistence;
|
|
4
9
|
generation: string | null;
|
|
5
|
-
onScreen: boolean;
|
|
6
10
|
keepGeneration(value: string): void | Promise<void>;
|
|
7
11
|
dropGeneration(): void | Promise<void>;
|
|
8
12
|
cleanUp?(): Promise<number>;
|
|
13
|
+
reset(): Promise<void>;
|
|
9
14
|
};
|
|
10
15
|
export declare function refusedForSpace(error: unknown): boolean;
|
|
11
16
|
export declare function detectStorageLoss(stored: string | null, reported: string | null): string | null;
|
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,UAAU,GAAG,gBAAgB,GAAG,MAAM,GAAG,YAAY,GAAG,YAAY,CAAC;AAEjF,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/E,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;IAC5B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB,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,CAmDZ"}
|