@agentshouse/mdruntime 0.1.0-c03e7b79830dd → 0.1.0-c0bed82db8d73
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/AGENTS.md +65 -65
- package/README.md +8 -7
- package/dist/adapter.d.ts +10 -14
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +1 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +2 -2
- package/dist/binary.d.ts +0 -5
- package/dist/binary.d.ts.map +1 -1
- package/dist/binary.js +1 -1
- package/dist/bootstrap.d.ts +13 -2
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +94 -57
- package/dist/change-set.d.ts +1 -7
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +1 -4
- package/dist/client.d.ts +2 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -2
- package/dist/compile.d.ts +6 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +12 -3
- package/dist/connection.d.ts +4 -5
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +481 -448
- package/dist/conversation.d.ts +2 -0
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +40 -19
- package/dist/durability.d.ts +2 -5
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +5 -0
- package/dist/fulltext.d.ts +27 -0
- package/dist/fulltext.d.ts.map +1 -0
- package/dist/fulltext.js +368 -0
- package/dist/host.d.ts +4 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +35 -15
- 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 +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +0 -11
- package/dist/messages.d.ts +28 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +90 -0
- package/dist/outcome.d.ts +0 -1
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +0 -3
- package/dist/overlay.js +1 -1
- package/dist/query.d.ts +4 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +12 -1
- package/dist/reach.d.ts +0 -2
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +17 -28
- package/dist/readiness.d.ts +20 -9
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +6 -6
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +3 -1
- package/dist/refresh.d.ts +6 -2
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +60 -22
- package/dist/replica.d.ts +3 -1
- package/dist/replica.d.ts.map +1 -1
- package/dist/room-draft.d.ts +1 -0
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +33 -0
- package/dist/save.js +2 -2
- package/dist/search.d.ts +11 -43
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +0 -296
- package/dist/store.d.ts +17 -36
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +28 -227
- package/dist/stored.d.ts +9 -7
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +46 -40
- package/dist/tables.d.ts +46 -12
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +94 -7
- package/dist/wire.d.ts +0 -4
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +0 -1
- package/dist/words.d.ts +19 -0
- package/dist/words.d.ts.map +1 -0
- package/dist/words.js +150 -0
- package/package.json +11 -18
- package/dist/chat/acts.d.ts +0 -33
- package/dist/chat/acts.d.ts.map +0 -1
- package/dist/chat/acts.js +0 -36
- package/dist/chat/context.d.ts +0 -3
- package/dist/chat/context.d.ts.map +0 -1
- package/dist/chat/context.js +0 -10
- package/dist/chat/earlier.d.ts +0 -10
- package/dist/chat/earlier.d.ts.map +0 -1
- package/dist/chat/earlier.js +0 -54
- package/dist/chat/house.d.ts +0 -25
- package/dist/chat/house.d.ts.map +0 -1
- package/dist/chat/house.js +0 -38
- package/dist/chat/input.d.ts +0 -11
- package/dist/chat/input.d.ts.map +0 -1
- package/dist/chat/input.js +0 -92
- package/dist/chat/kit.d.ts +0 -61
- package/dist/chat/kit.d.ts.map +0 -1
- package/dist/chat/kit.js +0 -123
- package/dist/chat/lasting.d.ts +0 -6
- package/dist/chat/lasting.d.ts.map +0 -1
- package/dist/chat/lasting.js +0 -19
- package/dist/chat/list.d.ts +0 -28
- package/dist/chat/list.d.ts.map +0 -1
- package/dist/chat/list.js +0 -103
- package/dist/chat/markdown.d.ts +0 -21
- package/dist/chat/markdown.d.ts.map +0 -1
- package/dist/chat/markdown.js +0 -246
- package/dist/chat/message.d.ts +0 -7
- package/dist/chat/message.d.ts.map +0 -1
- package/dist/chat/message.js +0 -244
- package/dist/chat/messages.d.ts +0 -30
- package/dist/chat/messages.d.ts.map +0 -1
- package/dist/chat/messages.js +0 -198
- package/dist/chat/name.d.ts +0 -7
- package/dist/chat/name.d.ts.map +0 -1
- package/dist/chat/name.js +0 -37
- package/dist/chat/opened.d.ts +0 -12
- package/dist/chat/opened.d.ts.map +0 -1
- package/dist/chat/opened.js +0 -19
- package/dist/chat/overlay.d.ts +0 -32
- package/dist/chat/overlay.d.ts.map +0 -1
- package/dist/chat/overlay.js +0 -103
- package/dist/chat/parts.d.ts +0 -58
- package/dist/chat/parts.d.ts.map +0 -1
- package/dist/chat/parts.js +0 -120
- package/dist/chat/pieces.d.ts +0 -62
- package/dist/chat/pieces.d.ts.map +0 -1
- package/dist/chat/pieces.js +0 -1110
- package/dist/chat/process.d.ts +0 -20
- package/dist/chat/process.d.ts.map +0 -1
- package/dist/chat/process.js +0 -32
- package/dist/chat/provider.d.ts +0 -70
- package/dist/chat/provider.d.ts.map +0 -1
- package/dist/chat/provider.js +0 -635
- package/dist/chat/question.d.ts +0 -9
- package/dist/chat/question.d.ts.map +0 -1
- package/dist/chat/question.js +0 -69
- package/dist/chat/questions.d.ts +0 -31
- package/dist/chat/questions.d.ts.map +0 -1
- package/dist/chat/questions.js +0 -111
- package/dist/chat/read.d.ts +0 -5
- package/dist/chat/read.d.ts.map +0 -1
- package/dist/chat/read.js +0 -13
- package/dist/chat/ready.d.ts +0 -37
- package/dist/chat/ready.d.ts.map +0 -1
- package/dist/chat/ready.js +0 -93
- package/dist/chat/room-file.d.ts +0 -8
- package/dist/chat/room-file.d.ts.map +0 -1
- package/dist/chat/room-file.js +0 -72
- package/dist/chat/steady.d.ts +0 -3
- package/dist/chat/steady.d.ts.map +0 -1
- package/dist/chat/steady.js +0 -26
- package/dist/chat/style.d.ts +0 -4
- package/dist/chat/style.d.ts.map +0 -1
- package/dist/chat/style.js +0 -306
- package/dist/chat.d.ts +0 -15
- package/dist/chat.d.ts.map +0 -1
- package/dist/chat.js +0 -8
package/dist/conversation.d.ts
CHANGED
|
@@ -85,6 +85,7 @@ export type ConversationDependencies = {
|
|
|
85
85
|
stream(): ConversationStream | undefined;
|
|
86
86
|
publish(set: ChangeSet): void;
|
|
87
87
|
online(): boolean;
|
|
88
|
+
full(): boolean;
|
|
88
89
|
closed(): boolean;
|
|
89
90
|
unanswered(): void;
|
|
90
91
|
expired(operation: string): boolean;
|
|
@@ -112,6 +113,7 @@ export type ConversationStore = {
|
|
|
112
113
|
};
|
|
113
114
|
export declare function unheldView(conversation: string): ConversationView;
|
|
114
115
|
export declare const SESSION_STARTED = "Session started";
|
|
116
|
+
export declare const HISTORY_CONVERSATIONS = 64;
|
|
115
117
|
export declare function newChat(agent: string): string;
|
|
116
118
|
export declare function createConversationStore(deps: ConversationDependencies): ConversationStore;
|
|
117
119
|
//# sourceMappingURL=conversation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../src/conversation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EAEjB,mBAAmB,EACnB,kBAAkB,EAElB,cA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C,OAAO,IAAI,OAAO,CAAC;IACnB,KAAK,IAAI,OAAO,CAAC;IACjB,WAAW,IAAI,IAAI,CAAC;IACpB,QAAQ,IAAI,IAAI,CAAC;IACjB,IAAI,IAAI,IAAI,CAAC;IACb,KAAK,CACH,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,mBAAmB,EAC5B,OAAO,EAAE,CAAC,IAAI,EAAE,gBAAgB,KAAK,IAAI,GACxC,MAAM,IAAI,CAAC;IACd,SAAS,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,SAAS,iBAAiB,EAAE,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAChF,WAAW,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,SAAS,iBAAiB,EAAE,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACjF,OAAO,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC;IAC9B,OAAO,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC;IAC3C,UAAU,IAAI,SAAS,MAAM,EAAE,CAAC;IAChC,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC;IACxC,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAyCF,wBAAgB,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,gBAAgB,CAcjE;AAED,eAAO,MAAM,eAAe,oBAAoB,CAAC;AAIjD,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAExC,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAoQD,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,wBAAwB,GAAG,iBAAiB,CAm4BzF"}
|
package/dist/conversation.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { conversationChangeSet } from './change-set.js';
|
|
2
2
|
import { runtimeError } from './failure.js';
|
|
3
|
+
import { refusedForSpace } from './durability.js';
|
|
3
4
|
import { declaredFile } from './file.js';
|
|
4
5
|
import { changeBatchIdentity, chatDraftRevision } from './identity.js';
|
|
5
6
|
import { OFFLINE } from './outcome.js';
|
|
@@ -40,6 +41,7 @@ export function unheldView(conversation) {
|
|
|
40
41
|
}
|
|
41
42
|
export const SESSION_STARTED = 'Session started';
|
|
42
43
|
const NEW_CHAT = 'new:';
|
|
44
|
+
export const HISTORY_CONVERSATIONS = 64;
|
|
43
45
|
export function newChat(agent) {
|
|
44
46
|
return `${NEW_CHAT}${agent}`;
|
|
45
47
|
}
|
|
@@ -209,6 +211,12 @@ function askedOf(options) {
|
|
|
209
211
|
return { limit: capped(limit), after, before: beforeOf(after), total: total === true };
|
|
210
212
|
}
|
|
211
213
|
const EXPIRED = { kind: 'rejected', code: 'expired', fields: {}, retryable: false };
|
|
214
|
+
const DURABLE_WRITE = {
|
|
215
|
+
kind: 'rejected',
|
|
216
|
+
code: 'durable-write',
|
|
217
|
+
fields: {},
|
|
218
|
+
retryable: true,
|
|
219
|
+
};
|
|
212
220
|
function unwritten(draft) {
|
|
213
221
|
return draft.text === '';
|
|
214
222
|
}
|
|
@@ -324,9 +332,6 @@ export function createConversationStore(deps) {
|
|
|
324
332
|
}
|
|
325
333
|
}
|
|
326
334
|
}
|
|
327
|
-
function changesOf(conversation, arriving) {
|
|
328
|
-
return arriving.map(({ identity, text }) => ({ conversation, identity, text }));
|
|
329
|
-
}
|
|
330
335
|
function stateOf(conversation) {
|
|
331
336
|
const facts = liveOf(conversation);
|
|
332
337
|
if (facts.questions.length > 0)
|
|
@@ -485,12 +490,6 @@ export function createConversationStore(deps) {
|
|
|
485
490
|
}
|
|
486
491
|
async function remove(leaving) {
|
|
487
492
|
await deps.durably(async (local) => {
|
|
488
|
-
const removed = [];
|
|
489
|
-
for (const conversation of leaving) {
|
|
490
|
-
for (const identity of await local.messageIdentities(conversation)) {
|
|
491
|
-
removed.push({ conversation, identity, text: null });
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
493
|
await local.dropConversations(leaving);
|
|
495
494
|
const changed = [];
|
|
496
495
|
for (const conversation of leaving) {
|
|
@@ -507,7 +506,7 @@ export function createConversationStore(deps) {
|
|
|
507
506
|
await slide(local, conversation, null);
|
|
508
507
|
}
|
|
509
508
|
if (changed.length > 0)
|
|
510
|
-
deps.publish(conversationChangeSet(
|
|
509
|
+
deps.publish(conversationChangeSet(changed));
|
|
511
510
|
});
|
|
512
511
|
}
|
|
513
512
|
function gap(conversation) {
|
|
@@ -533,16 +532,17 @@ export function createConversationStore(deps) {
|
|
|
533
532
|
reads.set(conversation, message.position);
|
|
534
533
|
sealTurns(conversation, new Set([message.turn]));
|
|
535
534
|
await slide(local, conversation, [message]);
|
|
536
|
-
deps.publish(conversationChangeSet(
|
|
535
|
+
deps.publish(conversationChangeSet([conversation]));
|
|
537
536
|
});
|
|
538
537
|
}
|
|
539
538
|
async function readHistories(conversations, ended) {
|
|
540
539
|
const generations = new Map(conversations.map((one) => [one, gaps.get(one) ?? 0]));
|
|
541
|
-
let
|
|
540
|
+
let waiting = conversations.map((conversation) => ({
|
|
542
541
|
conversation,
|
|
543
542
|
after: reads.get(conversation) ?? undefined,
|
|
544
543
|
}));
|
|
545
|
-
while (
|
|
544
|
+
while (waiting.length > 0) {
|
|
545
|
+
const asking = waiting.slice(0, HISTORY_CONVERSATIONS);
|
|
546
546
|
const result = await deps.call('conversation.history', {
|
|
547
547
|
conversations: asking.map(({ conversation, after }) => ({
|
|
548
548
|
conversation,
|
|
@@ -566,7 +566,7 @@ export function createConversationStore(deps) {
|
|
|
566
566
|
if (!following.some((next) => next.conversation === conversation))
|
|
567
567
|
ended(conversation);
|
|
568
568
|
}
|
|
569
|
-
|
|
569
|
+
waiting = [...waiting.slice(HISTORY_CONVERSATIONS), ...following];
|
|
570
570
|
}
|
|
571
571
|
return null;
|
|
572
572
|
}
|
|
@@ -609,7 +609,7 @@ export function createConversationStore(deps) {
|
|
|
609
609
|
behind.delete(conversation);
|
|
610
610
|
await slide(local, conversation, arriving);
|
|
611
611
|
if (arriving.length > 0 || sealing || whole) {
|
|
612
|
-
deps.publish(conversationChangeSet(
|
|
612
|
+
deps.publish(conversationChangeSet([conversation]));
|
|
613
613
|
}
|
|
614
614
|
});
|
|
615
615
|
}
|
|
@@ -658,7 +658,14 @@ export function createConversationStore(deps) {
|
|
|
658
658
|
if (arriving === null)
|
|
659
659
|
return;
|
|
660
660
|
if (replicated.has(conversation)) {
|
|
661
|
-
|
|
661
|
+
if (deps.full()) {
|
|
662
|
+
gap(conversation);
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
void keep(conversation, arriving).catch((error) => {
|
|
666
|
+
if (refusedForSpace(error))
|
|
667
|
+
gap(conversation);
|
|
668
|
+
});
|
|
662
669
|
return;
|
|
663
670
|
}
|
|
664
671
|
if (sealTurns(conversation, new Set([arriving.turn])))
|
|
@@ -702,7 +709,7 @@ export function createConversationStore(deps) {
|
|
|
702
709
|
drafts.set(from, left);
|
|
703
710
|
for (const one of taken)
|
|
704
711
|
drafts.set(to, one);
|
|
705
|
-
deps.publish(conversationChangeSet([
|
|
712
|
+
deps.publish(conversationChangeSet([from, to]));
|
|
706
713
|
});
|
|
707
714
|
}
|
|
708
715
|
function withDraft(conversation, next) {
|
|
@@ -711,7 +718,7 @@ export function createConversationStore(deps) {
|
|
|
711
718
|
if (following === undefined)
|
|
712
719
|
return;
|
|
713
720
|
await kept(local, conversation, following);
|
|
714
|
-
deps.publish(conversationChangeSet([
|
|
721
|
+
deps.publish(conversationChangeSet([conversation]));
|
|
715
722
|
});
|
|
716
723
|
}
|
|
717
724
|
async function submitted(conversation, operation, draft) {
|
|
@@ -805,8 +812,17 @@ export function createConversationStore(deps) {
|
|
|
805
812
|
return result;
|
|
806
813
|
},
|
|
807
814
|
async send(conversation, operation = changeBatchIdentity(), draft) {
|
|
815
|
+
if (deps.full())
|
|
816
|
+
return DURABLE_WRITE;
|
|
808
817
|
if (deps.online()) {
|
|
809
|
-
const
|
|
818
|
+
const held = await submitted(conversation, operation, draft).catch((error) => {
|
|
819
|
+
if (refusedForSpace(error))
|
|
820
|
+
return null;
|
|
821
|
+
throw error;
|
|
822
|
+
});
|
|
823
|
+
if (held === null)
|
|
824
|
+
return DURABLE_WRITE;
|
|
825
|
+
const { submission, earlier } = held;
|
|
810
826
|
if (!earlier || !deps.expired(operation))
|
|
811
827
|
return dispatched(conversation, submission);
|
|
812
828
|
await forgotten(conversation, submission);
|
|
@@ -913,6 +929,11 @@ export function createConversationStore(deps) {
|
|
|
913
929
|
await remove(leaving);
|
|
914
930
|
},
|
|
915
931
|
async catchUp(progress) {
|
|
932
|
+
if (deps.full()) {
|
|
933
|
+
if (behind.size > 0)
|
|
934
|
+
progress.complete = false;
|
|
935
|
+
return;
|
|
936
|
+
}
|
|
916
937
|
const owed = (conversation) => behind.has(conversation) && replicated.has(conversation);
|
|
917
938
|
const read = async (conversations) => {
|
|
918
939
|
if (conversations.length === 0 || deps.closed())
|
package/dist/durability.d.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import type { Persistence } from './readiness.js';
|
|
2
|
-
export type StorageEstimate = {
|
|
3
|
-
readonly usage: number;
|
|
4
|
-
readonly total: number;
|
|
5
|
-
};
|
|
6
2
|
export type RuntimeShell = {
|
|
7
3
|
persistence: Persistence;
|
|
8
4
|
generation: string | null;
|
|
5
|
+
onScreen: boolean;
|
|
9
6
|
keepGeneration(value: string): void | Promise<void>;
|
|
10
7
|
dropGeneration(): void | Promise<void>;
|
|
11
|
-
estimate?(): Promise<StorageEstimate | null>;
|
|
12
8
|
cleanUp?(): Promise<number>;
|
|
13
9
|
};
|
|
10
|
+
export declare function refusedForSpace(error: unknown): boolean;
|
|
14
11
|
export declare function detectStorageLoss(stored: string | null, reported: string | null): string | null;
|
|
15
12
|
export declare function nextGeneration(stored: string | null, reported: string | null): string;
|
|
16
13
|
//# sourceMappingURL=durability.d.ts.map
|
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,
|
|
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,QAAQ,EAAE,OAAO,CAAC;IAClB,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/durability.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
const STORAGE_LOSS_CODE = 'storage-loss';
|
|
2
|
+
export function refusedForSpace(error) {
|
|
3
|
+
return (typeof error === 'object' &&
|
|
4
|
+
error !== null &&
|
|
5
|
+
error.name === 'QuotaExceededError');
|
|
6
|
+
}
|
|
2
7
|
export function detectStorageLoss(stored, reported) {
|
|
3
8
|
if (reported === null || reported === stored)
|
|
4
9
|
return null;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type QueryRoom } from './compile.js';
|
|
2
|
+
import type { Plan } from './query.js';
|
|
3
|
+
import type { HitCursor, SearchWindow } from './search.js';
|
|
4
|
+
import type { Connection } from './tables.js';
|
|
5
|
+
export declare const SEARCH_TABLES: readonly string[];
|
|
6
|
+
export type SearchAsk = {
|
|
7
|
+
readonly text: string;
|
|
8
|
+
readonly limit: number;
|
|
9
|
+
readonly after: readonly [HitCursor, HitCursor] | null;
|
|
10
|
+
readonly total: boolean;
|
|
11
|
+
readonly documents: {
|
|
12
|
+
readonly plan: Plan;
|
|
13
|
+
readonly rooms: readonly QueryRoom[];
|
|
14
|
+
readonly beneath: readonly {
|
|
15
|
+
readonly key: number;
|
|
16
|
+
readonly roots: readonly string[];
|
|
17
|
+
}[];
|
|
18
|
+
} | null;
|
|
19
|
+
readonly conversations: readonly string[];
|
|
20
|
+
};
|
|
21
|
+
export declare function indexDocument(connection: Connection, id: number, path: string, content: string): void;
|
|
22
|
+
export declare function indexMessage(connection: Connection, id: number, text: string): void;
|
|
23
|
+
export declare function unindexDocuments(connection: Connection, ids: Iterable<number>): void;
|
|
24
|
+
export declare function unindexMessages(connection: Connection, ids: Iterable<number>): void;
|
|
25
|
+
export declare function unindexAll(connection: Connection): void;
|
|
26
|
+
export declare function searched(connection: Connection, ask: SearchAsk): SearchWindow;
|
|
27
|
+
//# sourceMappingURL=fulltext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fulltext.d.ts","sourceRoot":"","sources":["../src/fulltext.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,KAAK,EAGV,SAAS,EAET,YAAY,EAEb,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,UAAU,EAAS,MAAM,aAAa,CAAC;AAmBrD,eAAO,MAAM,aAAa,EAAE,SAAS,MAAM,EAG1C,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AAY,CAsB7E"}
|
package/dist/fulltext.js
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { parse } from '@agentshouse/mdmodel';
|
|
2
|
+
import { selected } from './compile.js';
|
|
3
|
+
import { markdownPath } from './rows.js';
|
|
4
|
+
import { indexed, matchClauses, matched, matchExpression, queryTerms, snippet, } from './words.js';
|
|
5
|
+
const TOKENIZER = "porter unicode61 remove_diacritics 2 categories 'L* N* Co M*'";
|
|
6
|
+
const CONTENTLESS = `content='', contentless_delete=1, detail=full, tokenize="${TOKENIZER}"`;
|
|
7
|
+
const DOCUMENTS = 'replica_search';
|
|
8
|
+
const MESSAGES = 'conversation_search';
|
|
9
|
+
export const SEARCH_TABLES = [
|
|
10
|
+
`CREATE VIRTUAL TABLE ${DOCUMENTS} USING fts5(path, fields, sections, preamble, ${CONTENTLESS})`,
|
|
11
|
+
`CREATE VIRTUAL TABLE ${MESSAGES} USING fts5(text, ${CONTENTLESS})`,
|
|
12
|
+
];
|
|
13
|
+
const CHUNKS = 4096;
|
|
14
|
+
const CHUNK_CHARACTERS = 32_768;
|
|
15
|
+
const CANDIDATES = 5_000;
|
|
16
|
+
const LEAST_WINDOW = 32;
|
|
17
|
+
const SNIPPET_REACH = 80;
|
|
18
|
+
function scalars(value) {
|
|
19
|
+
if (value === null || value === undefined)
|
|
20
|
+
return [];
|
|
21
|
+
if (Array.isArray(value))
|
|
22
|
+
return value.flatMap(scalars);
|
|
23
|
+
if (typeof value === 'object')
|
|
24
|
+
return Object.values(value).flatMap(scalars);
|
|
25
|
+
return [String(value)];
|
|
26
|
+
}
|
|
27
|
+
function partsOf(path, content) {
|
|
28
|
+
if (!markdownPath(path))
|
|
29
|
+
return null;
|
|
30
|
+
const read = parse(content, path);
|
|
31
|
+
if (!read.ok)
|
|
32
|
+
return null;
|
|
33
|
+
return {
|
|
34
|
+
fields: scalars(read.document.fields).join('\n'),
|
|
35
|
+
sections: Object.entries(read.document.sections)
|
|
36
|
+
.map(([heading, text]) => `${heading}\n${text}`)
|
|
37
|
+
.join('\n'),
|
|
38
|
+
preamble: read.document.preamble,
|
|
39
|
+
path,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function chunked(text) {
|
|
43
|
+
const chunks = [];
|
|
44
|
+
let start = 0;
|
|
45
|
+
do {
|
|
46
|
+
let end = Math.min(text.length, start + CHUNK_CHARACTERS);
|
|
47
|
+
if (end < text.length) {
|
|
48
|
+
const space = text.lastIndexOf(' ', end);
|
|
49
|
+
if (space > start + CHUNK_CHARACTERS / 2)
|
|
50
|
+
end = space;
|
|
51
|
+
else if (/[\ud800-\udbff]/u.test(text[end - 1]))
|
|
52
|
+
end -= 1;
|
|
53
|
+
}
|
|
54
|
+
chunks.push(text.slice(start, end));
|
|
55
|
+
start = end;
|
|
56
|
+
} while (start < text.length && chunks.length < CHUNKS);
|
|
57
|
+
return chunks;
|
|
58
|
+
}
|
|
59
|
+
function rowOf(id, chunk) {
|
|
60
|
+
return id * CHUNKS + chunk;
|
|
61
|
+
}
|
|
62
|
+
export function indexDocument(connection, id, path, content) {
|
|
63
|
+
const parts = partsOf(path, content);
|
|
64
|
+
if (parts === null)
|
|
65
|
+
return;
|
|
66
|
+
chunked(parts.sections).forEach((sections, chunk) => {
|
|
67
|
+
const head = chunk === 0;
|
|
68
|
+
connection.run(`INSERT INTO ${DOCUMENTS} (rowid, path, fields, sections, preamble) VALUES (?, ?, ?, ?, ?)`, [
|
|
69
|
+
rowOf(id, chunk),
|
|
70
|
+
head ? indexed(parts.path) : null,
|
|
71
|
+
head ? indexed(parts.fields) : null,
|
|
72
|
+
indexed(sections),
|
|
73
|
+
head ? indexed(parts.preamble) : null,
|
|
74
|
+
]);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
export function indexMessage(connection, id, text) {
|
|
78
|
+
chunked(text).forEach((chunk, at) => {
|
|
79
|
+
connection.run(`INSERT INTO ${MESSAGES} (rowid, text) VALUES (?, ?)`, [
|
|
80
|
+
rowOf(id, at),
|
|
81
|
+
indexed(chunk),
|
|
82
|
+
]);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function unindexed(connection, table, ids) {
|
|
86
|
+
for (const id of ids) {
|
|
87
|
+
connection.run(`DELETE FROM ${table} WHERE rowid >= ? AND rowid < ?`, [
|
|
88
|
+
rowOf(id, 0),
|
|
89
|
+
rowOf(id + 1, 0),
|
|
90
|
+
]);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export function unindexDocuments(connection, ids) {
|
|
94
|
+
unindexed(connection, DOCUMENTS, ids);
|
|
95
|
+
}
|
|
96
|
+
export function unindexMessages(connection, ids) {
|
|
97
|
+
unindexed(connection, MESSAGES, ids);
|
|
98
|
+
}
|
|
99
|
+
export function unindexAll(connection) {
|
|
100
|
+
for (const table of [DOCUMENTS, MESSAGES]) {
|
|
101
|
+
connection.run(`INSERT INTO ${table} (${table}) VALUES ('delete-all')`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function pair(left, right) {
|
|
105
|
+
if (left[0] !== right[0])
|
|
106
|
+
return left[0] < right[0] ? -1 : 1;
|
|
107
|
+
if (left[1] !== right[1])
|
|
108
|
+
return left[1] < right[1] ? -1 : 1;
|
|
109
|
+
return 0;
|
|
110
|
+
}
|
|
111
|
+
function byRank(left, right) {
|
|
112
|
+
return right.score - left.score || pair(left.tie, right.tie);
|
|
113
|
+
}
|
|
114
|
+
function beyond(hit, cursor) {
|
|
115
|
+
if (cursor.length === 0)
|
|
116
|
+
return true;
|
|
117
|
+
return (hit.score < cursor[0] || (hit.score === cursor[0] && pair(hit.tie, [cursor[1], cursor[2]]) > 0));
|
|
118
|
+
}
|
|
119
|
+
function rankedWithin(connection, listed, sources, cursor, needed) {
|
|
120
|
+
const { table } = listed;
|
|
121
|
+
let window = Math.max(needed * 2, LEAST_WINDOW);
|
|
122
|
+
for (;;) {
|
|
123
|
+
const rows = [];
|
|
124
|
+
const boundaries = [];
|
|
125
|
+
for (const source of sources) {
|
|
126
|
+
const found = connection.rows(`SELECT rowid, bm25(${table}) AS score FROM ${table} WHERE ${table} MATCH ? ${source.sql} ORDER BY score, rowid LIMIT ?`, [source.expression, ...source.bind, window]);
|
|
127
|
+
for (const row of found)
|
|
128
|
+
rows.push([Number(row.rowid), Number(row.score)]);
|
|
129
|
+
if (found.length === window)
|
|
130
|
+
boundaries.push(-Number(found.at(-1).score));
|
|
131
|
+
}
|
|
132
|
+
rows.sort((left, right) => left[1] - right[1] || left[0] - right[0]);
|
|
133
|
+
const best = new Map();
|
|
134
|
+
for (const [row, score] of rows) {
|
|
135
|
+
const id = Math.floor(row / CHUNKS);
|
|
136
|
+
if (!best.has(id))
|
|
137
|
+
best.set(id, { chunk: row % CHUNKS, score: -score });
|
|
138
|
+
}
|
|
139
|
+
const ties = listed.ties([...best.keys()]);
|
|
140
|
+
const kept = [...best]
|
|
141
|
+
.flatMap(([id, held]) => {
|
|
142
|
+
const tie = ties.get(id);
|
|
143
|
+
return tie === undefined ? [] : [{ id, ...held, tie }];
|
|
144
|
+
})
|
|
145
|
+
.sort(byRank)
|
|
146
|
+
.filter((hit) => beyond(hit, cursor))
|
|
147
|
+
.slice(0, needed);
|
|
148
|
+
const last = kept.at(-1);
|
|
149
|
+
if (boundaries.length === 0)
|
|
150
|
+
return kept;
|
|
151
|
+
if (kept.length === needed &&
|
|
152
|
+
last !== undefined &&
|
|
153
|
+
boundaries.every((boundary) => boundary < last.score)) {
|
|
154
|
+
return kept;
|
|
155
|
+
}
|
|
156
|
+
window *= 4;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function reaches(connection, listed, expression, reach) {
|
|
160
|
+
const { table, scope } = listed;
|
|
161
|
+
const [counted] = connection.rows(`SELECT count(*) AS held FROM (SELECT rowid FROM ${table} WHERE ${table} MATCH ? AND ${scope.sql} LIMIT ?)`, [expression, ...scope.bind, reach + 1]);
|
|
162
|
+
return Number(counted?.held ?? 0) > reach;
|
|
163
|
+
}
|
|
164
|
+
function candidates(connection, listed, clauses, cursor, needed) {
|
|
165
|
+
const { table, scope } = listed;
|
|
166
|
+
const expression = matchExpression(clauses);
|
|
167
|
+
const within = { sql: `AND ${scope.sql}`, bind: scope.bind };
|
|
168
|
+
let reach = CANDIDATES;
|
|
169
|
+
for (;;) {
|
|
170
|
+
const [edge] = connection.rows(`SELECT rowid FROM ${table} WHERE ${table} MATCH ? ${within.sql} ORDER BY rowid LIMIT 1 OFFSET ?`, [expression, ...within.bind, reach]);
|
|
171
|
+
const floor = edge === undefined ? null : Number(edge.rowid);
|
|
172
|
+
const sources = [
|
|
173
|
+
floor === null
|
|
174
|
+
? { expression, ...within }
|
|
175
|
+
: { expression, sql: `${within.sql} AND rowid < ?`, bind: [...within.bind, floor] },
|
|
176
|
+
];
|
|
177
|
+
if (floor !== null) {
|
|
178
|
+
const common = new Set();
|
|
179
|
+
const selective = [];
|
|
180
|
+
const frequent = [];
|
|
181
|
+
for (const clause of clauses) {
|
|
182
|
+
if (clause.kind === 'phrase')
|
|
183
|
+
continue;
|
|
184
|
+
if (clause.kind !== 'term' && common.has(clause.term)) {
|
|
185
|
+
frequent.push(clause);
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (reaches(connection, listed, clause.text, reach)) {
|
|
189
|
+
if (clause.kind === 'term')
|
|
190
|
+
common.add(clause.term);
|
|
191
|
+
frequent.push(clause);
|
|
192
|
+
}
|
|
193
|
+
else
|
|
194
|
+
selective.push(clause);
|
|
195
|
+
}
|
|
196
|
+
const phrase = clauses.find((clause) => clause.kind === 'phrase');
|
|
197
|
+
if (phrase !== undefined) {
|
|
198
|
+
const rare = !clauses
|
|
199
|
+
.filter((clause) => clause.kind === 'term')
|
|
200
|
+
.every((clause) => common.has(clause.term)) ||
|
|
201
|
+
!reaches(connection, listed, phrase.text, reach);
|
|
202
|
+
(rare ? selective : frequent).push(phrase);
|
|
203
|
+
}
|
|
204
|
+
if (selective.length > 0) {
|
|
205
|
+
const chosen = `(${matchExpression(selective)})`;
|
|
206
|
+
const tail = { sql: `${within.sql} AND rowid >= ?`, bind: [...within.bind, floor] };
|
|
207
|
+
if (frequent.length === 0)
|
|
208
|
+
sources.push({ ...tail, expression: chosen });
|
|
209
|
+
else {
|
|
210
|
+
const rest = `(${matchExpression(frequent)})`;
|
|
211
|
+
sources.push({ ...tail, expression: `${chosen} AND ${rest}` }, { ...tail, expression: `${chosen} NOT ${rest}` });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const kept = rankedWithin(connection, listed, sources, cursor, needed);
|
|
216
|
+
if (floor === null || kept.length >= needed)
|
|
217
|
+
return kept;
|
|
218
|
+
reach *= 4;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
function windowOf(connection, listed, clauses, cursor, limit) {
|
|
222
|
+
if (cursor === null || listed === null || clauses === null)
|
|
223
|
+
return { kept: [], cursor: null };
|
|
224
|
+
const found = candidates(connection, listed, clauses, cursor, limit + 1);
|
|
225
|
+
if (found.length <= limit)
|
|
226
|
+
return { kept: found, cursor: null };
|
|
227
|
+
const kept = found.slice(0, limit);
|
|
228
|
+
const last = kept.at(-1);
|
|
229
|
+
return { kept, cursor: last === undefined ? cursor : [last.score, ...last.tie] };
|
|
230
|
+
}
|
|
231
|
+
function totalOf(connection, listed, clauses) {
|
|
232
|
+
if (listed === null || clauses === null)
|
|
233
|
+
return 0;
|
|
234
|
+
const { table, scope } = listed;
|
|
235
|
+
const [counted] = connection.rows(`SELECT count(DISTINCT rowid / ${CHUNKS}) AS held FROM ${table} WHERE ${table} MATCH ? AND ${scope.sql}`, [matchExpression(clauses), ...scope.bind]);
|
|
236
|
+
return Number(counted?.held ?? 0);
|
|
237
|
+
}
|
|
238
|
+
function ids(found) {
|
|
239
|
+
return JSON.stringify(found);
|
|
240
|
+
}
|
|
241
|
+
function documentsListed(connection, documents) {
|
|
242
|
+
if (documents.rooms.length === 0)
|
|
243
|
+
return null;
|
|
244
|
+
const filter = selected(connection, documents.plan, documents.rooms);
|
|
245
|
+
const outside = documents.beneath.flatMap(({ key, roots }) => roots.map((root) => ({
|
|
246
|
+
sql: 'NOT (d.key = ? AND (d.path = ? OR (d.path >= ? AND d.path < ?)))',
|
|
247
|
+
bind: [key, root, `${root}/`, `${root}0`],
|
|
248
|
+
})));
|
|
249
|
+
const conditions = [filter, ...outside];
|
|
250
|
+
const locators = new Map(documents.rooms.map(({ key, locator }) => [key, locator]));
|
|
251
|
+
return {
|
|
252
|
+
table: DOCUMENTS,
|
|
253
|
+
scope: {
|
|
254
|
+
sql: `EXISTS (SELECT 1 FROM replica_entries d WHERE d.id = ${DOCUMENTS}.rowid / ${CHUNKS} AND d.type IS NOT NULL AND ${conditions.map(({ sql }) => `(${sql})`).join(' AND ')})`,
|
|
255
|
+
bind: conditions.flatMap(({ bind }) => bind),
|
|
256
|
+
},
|
|
257
|
+
ties(found) {
|
|
258
|
+
const tied = new Map();
|
|
259
|
+
for (const row of connection.rows('SELECT id, key, path FROM replica_entries WHERE id IN (SELECT value FROM json_each(?))', [ids(found)])) {
|
|
260
|
+
const locator = locators.get(Number(row.key));
|
|
261
|
+
if (locator !== undefined)
|
|
262
|
+
tied.set(Number(row.id), [locator, String(row.path)]);
|
|
263
|
+
}
|
|
264
|
+
return tied;
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
function messagesListed(connection, conversations) {
|
|
269
|
+
if (conversations.length === 0)
|
|
270
|
+
return null;
|
|
271
|
+
return {
|
|
272
|
+
table: MESSAGES,
|
|
273
|
+
scope: {
|
|
274
|
+
sql: `EXISTS (SELECT 1 FROM conversation_messages m WHERE m.id = ${MESSAGES}.rowid / ${CHUNKS} AND m.conversation IN (SELECT value FROM json_each(?)))`,
|
|
275
|
+
bind: [JSON.stringify(conversations)],
|
|
276
|
+
},
|
|
277
|
+
ties(found) {
|
|
278
|
+
return new Map(connection
|
|
279
|
+
.rows('SELECT id, conversation, identity FROM conversation_messages WHERE id IN (SELECT value FROM json_each(?))', [ids(found)])
|
|
280
|
+
.map((row) => [Number(row.id), [String(row.conversation), String(row.identity)]]));
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
function cut(candidates, terms) {
|
|
285
|
+
for (const [part, text] of candidates) {
|
|
286
|
+
const found = snippet(text, terms, SNIPPET_REACH);
|
|
287
|
+
if (found !== null)
|
|
288
|
+
return { snippet: { part, text: found.text, at: [...found.at] } };
|
|
289
|
+
}
|
|
290
|
+
return {};
|
|
291
|
+
}
|
|
292
|
+
function documentHit(connection, hit, terms) {
|
|
293
|
+
const [row] = connection.rows('SELECT type, content FROM replica_entries WHERE id = ?', [hit.id]);
|
|
294
|
+
if (row === undefined)
|
|
295
|
+
return null;
|
|
296
|
+
const [room, path] = hit.tie;
|
|
297
|
+
const parts = typeof row.content === 'string' ? partsOf(path, row.content) : null;
|
|
298
|
+
const whole = parts === null
|
|
299
|
+
? []
|
|
300
|
+
: [
|
|
301
|
+
['fields', parts.fields],
|
|
302
|
+
['sections', parts.sections],
|
|
303
|
+
['preamble', parts.preamble],
|
|
304
|
+
['path', parts.path],
|
|
305
|
+
];
|
|
306
|
+
const matches = {};
|
|
307
|
+
for (const [part, text] of whole) {
|
|
308
|
+
for (const term of matched(text, terms))
|
|
309
|
+
(matches[term] ??= []).push(part);
|
|
310
|
+
}
|
|
311
|
+
const sections = parts === null ? [] : chunked(parts.sections);
|
|
312
|
+
const chunk = parts === null
|
|
313
|
+
? []
|
|
314
|
+
: hit.chunk === 0
|
|
315
|
+
? [
|
|
316
|
+
['fields', parts.fields],
|
|
317
|
+
['sections', sections[0] ?? ''],
|
|
318
|
+
['preamble', parts.preamble],
|
|
319
|
+
['path', parts.path],
|
|
320
|
+
]
|
|
321
|
+
: [['sections', sections[hit.chunk] ?? '']];
|
|
322
|
+
return {
|
|
323
|
+
room,
|
|
324
|
+
path,
|
|
325
|
+
type: String(row.type),
|
|
326
|
+
score: hit.score,
|
|
327
|
+
matches,
|
|
328
|
+
...cut(chunk, terms),
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
function messageHit(connection, hit, terms) {
|
|
332
|
+
const [row] = connection.rows('SELECT text FROM conversation_messages WHERE id = ?', [hit.id]);
|
|
333
|
+
const text = typeof row?.text === 'string' ? row.text : '';
|
|
334
|
+
const matches = {};
|
|
335
|
+
for (const term of matched(text, terms))
|
|
336
|
+
matches[term] = ['text'];
|
|
337
|
+
const [conversation, identity] = hit.tie;
|
|
338
|
+
return {
|
|
339
|
+
conversation,
|
|
340
|
+
identity,
|
|
341
|
+
score: hit.score,
|
|
342
|
+
matches,
|
|
343
|
+
...cut([['text', chunked(text)[hit.chunk] ?? '']], terms),
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
export function searched(connection, ask) {
|
|
347
|
+
const clauses = matchClauses(ask.text);
|
|
348
|
+
const terms = queryTerms(ask.text);
|
|
349
|
+
const documents = ask.documents === null ? null : documentsListed(connection, ask.documents);
|
|
350
|
+
const messages = messagesListed(connection, ask.conversations);
|
|
351
|
+
const [documentsAfter, messagesAfter] = ask.after ?? [[], []];
|
|
352
|
+
const documentWindow = windowOf(connection, documents, clauses, documentsAfter, ask.limit);
|
|
353
|
+
const messageWindow = windowOf(connection, messages, clauses, messagesAfter, ask.limit);
|
|
354
|
+
const more = documentWindow.cursor !== null || messageWindow.cursor !== null;
|
|
355
|
+
return {
|
|
356
|
+
documents: documentWindow.kept.flatMap((hit) => documentHit(connection, hit, terms) ?? []),
|
|
357
|
+
messages: messageWindow.kept.map((hit) => messageHit(connection, hit, terms)),
|
|
358
|
+
...(more ? { next: JSON.stringify([documentWindow.cursor, messageWindow.cursor]) } : {}),
|
|
359
|
+
...(ask.total
|
|
360
|
+
? {
|
|
361
|
+
total: {
|
|
362
|
+
documents: totalOf(connection, documents, clauses),
|
|
363
|
+
messages: totalOf(connection, messages, clauses),
|
|
364
|
+
},
|
|
365
|
+
}
|
|
366
|
+
: {}),
|
|
367
|
+
};
|
|
368
|
+
}
|
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 {
|
|
3
|
+
import type { CodeAvailability, Persistence, Readiness, SearchObligation, Space } 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,13 +11,14 @@ 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,
|
|
14
|
+
code(code: CodeAvailability, space: Space | null): void;
|
|
15
15
|
search(search: SearchObligation): void;
|
|
16
16
|
};
|
|
17
17
|
export type MdRuntimeHost = {
|
|
18
18
|
attach(port: RuntimePort, app: string, release?: string, reach?: PortReach, code?: CodeAvailability, search?: SearchObligation): AttachedPort;
|
|
19
19
|
seed(entry: EntrySeed): void;
|
|
20
20
|
persisted(answer: Persistence): void;
|
|
21
|
+
shown(onScreen: boolean): void;
|
|
21
22
|
endAuthorization(holder?: string): Promise<void>;
|
|
22
23
|
lose(locators: readonly string[]): Promise<void>;
|
|
23
24
|
stop(): Promise<void>;
|
|
@@ -25,8 +26,7 @@ export type MdRuntimeHost = {
|
|
|
25
26
|
export declare function serveMdRuntime(options: MdRuntimeHostOptions): MdRuntimeHost;
|
|
26
27
|
export { entrySeedOf, type EntrySeed } from './seed.js';
|
|
27
28
|
export type { PortReach, ReachedDocument } from './reach.js';
|
|
28
|
-
export type {
|
|
29
|
+
export type { CodeAvailability, Persistence, SearchObligation, Space } from './readiness.js';
|
|
29
30
|
export { createRecovery, retryDelay, type Attempt, type Attempted, type AttemptOptions, type Recovery, type RecoveryOptions, } from './recovery.js';
|
|
30
|
-
export { openDatabase, STORE_SCHEMA, transacted } from './store.js';
|
|
31
31
|
export type { RuntimePort } from './wire.js';
|
|
32
32
|
//# sourceMappingURL=host.d.ts.map
|