@agentshouse/mdruntime 0.1.0-ce41fec66d91b → 0.1.0-ce46f015571d6
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 +10 -10
- package/dist/acceptance.d.ts +3 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +318 -0
- package/dist/act-lanes.d.ts +29 -0
- package/dist/act-lanes.d.ts.map +1 -0
- package/dist/act-lanes.js +177 -0
- package/dist/actions.d.ts +25 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +261 -0
- package/dist/adapter.d.ts +71 -69
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +3 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +21 -56
- package/dist/bootstrap.d.ts +9 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +204 -85
- package/dist/cell.d.ts +6 -0
- package/dist/cell.d.ts.map +1 -0
- package/dist/cell.js +9 -0
- package/dist/chain.d.ts +2 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/change-set.d.ts +4 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +6 -0
- package/dist/change.d.ts +1 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +4 -2
- package/dist/chat-types.d.ts +5 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +13 -0
- package/dist/client.d.ts +25 -14
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +32 -14
- package/dist/collection.d.ts +23 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +12 -2
- package/dist/compile.d.ts +6 -6
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +240 -315
- package/dist/connection.d.ts +5 -141
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +110 -5057
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- package/dist/conversation-live.d.ts +138 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +249 -0
- package/dist/conversation-row.d.ts +33 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +53 -0
- package/dist/conversation.d.ts +54 -45
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +930 -899
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- package/dist/discovery.d.ts +10 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +153 -0
- package/dist/durability.d.ts +18 -0
- 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 +17 -7
- package/dist/expectation.d.ts +26 -13
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +72 -19
- package/dist/failure.d.ts +3 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +6 -0
- package/dist/figures.d.ts +49 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +197 -0
- package/dist/holdings.d.ts +29 -0
- package/dist/holdings.d.ts.map +1 -0
- package/dist/holdings.js +95 -0
- package/dist/host.d.ts +20 -6
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +61 -30
- 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 +31 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -3
- package/dist/install.d.ts +54 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +539 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +279 -0
- package/dist/listing.d.ts +48 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +139 -0
- package/dist/live.d.ts +5 -4
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +63 -21
- package/dist/locks.d.ts +7 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +33 -0
- package/dist/log.d.ts +1 -0
- package/dist/log.d.ts.map +1 -1
- package/dist/lost.d.ts +5 -0
- package/dist/lost.d.ts.map +1 -0
- package/dist/lost.js +50 -0
- package/dist/media.d.ts +1 -1
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +4 -4
- package/dist/memory.d.ts +8 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +83 -26
- package/dist/messages.d.ts +24 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +92 -32
- package/dist/model.d.ts +2 -10
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +0 -14
- package/dist/models.d.ts +10 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +156 -0
- package/dist/observation.d.ts +2 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +14 -14
- package/dist/opened.d.ts +1 -1
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +5 -5
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +59 -0
- package/dist/outcome.d.ts +7 -1
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +18 -0
- package/dist/overlay.d.ts +3 -1
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +43 -21
- package/dist/page-metadata.d.ts +8 -0
- package/dist/page-metadata.d.ts.map +1 -0
- package/dist/page-metadata.js +19 -0
- package/dist/parts.d.ts +11 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +21 -0
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +22 -0
- package/dist/preparation.d.ts +20 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +233 -0
- package/dist/presence.d.ts +52 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +220 -0
- package/dist/queries.d.ts +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +270 -0
- package/dist/query.d.ts +13 -209
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -505
- package/dist/questions.d.ts +34 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +122 -0
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +455 -0
- package/dist/reach.d.ts +14 -12
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +193 -121
- package/dist/react.d.ts +15 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +33 -1
- package/dist/read.d.ts +7 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +17 -0
- package/dist/readiness.d.ts +0 -3
- package/dist/readiness.d.ts.map +1 -1
- package/dist/reads.d.ts +39 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +178 -0
- package/dist/recovery.d.ts +3 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +38 -8
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +9 -2
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +57 -0
- package/dist/replica.d.ts +11 -16
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +64 -30
- package/dist/retried.d.ts +30 -0
- package/dist/retried.d.ts.map +1 -0
- package/dist/retried.js +72 -0
- package/dist/room-draft.d.ts +7 -8
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +100 -103
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +217 -0
- package/dist/rows.d.ts +14 -21
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +49 -186
- package/dist/runtime.d.ts +36 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +41 -86
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +239 -116
- package/dist/saves.d.ts +32 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +413 -0
- package/dist/search.d.ts +12 -63
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +9 -52
- package/dist/seed.d.ts +11 -2
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +71 -1
- package/dist/shared.d.ts +1 -6
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +13 -95
- package/dist/shown.d.ts +32 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +290 -0
- package/dist/socket/admission.d.ts +7 -0
- package/dist/socket/admission.d.ts.map +1 -0
- package/dist/socket/admission.js +39 -0
- package/dist/socket/answers.d.ts +6 -0
- package/dist/socket/answers.d.ts.map +1 -0
- package/dist/socket/answers.js +20 -0
- package/dist/socket/lanes.d.ts +21 -0
- package/dist/socket/lanes.d.ts.map +1 -0
- package/dist/socket/lanes.js +80 -0
- package/dist/socket/reads.d.ts +10 -0
- package/dist/socket/reads.d.ts.map +1 -0
- package/dist/socket/reads.js +31 -0
- package/dist/socket/session.d.ts +38 -0
- package/dist/socket/session.d.ts.map +1 -0
- package/dist/socket/session.js +23 -0
- package/dist/socket.d.ts +68 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +171 -0
- package/dist/source.d.ts +61 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +82 -0
- package/dist/status.d.ts +0 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -6
- package/dist/store/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +34 -0
- package/dist/store/readiness.d.ts +10 -0
- package/dist/store/readiness.d.ts.map +1 -0
- package/dist/store/readiness.js +52 -0
- package/dist/store/records.d.ts +212 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +430 -0
- package/dist/store/room-held.d.ts +8 -0
- package/dist/store/room-held.d.ts.map +1 -0
- package/dist/store/room-held.js +17 -0
- package/dist/store/space.d.ts +11 -0
- package/dist/store/space.d.ts.map +1 -0
- package/dist/store/space.js +41 -0
- package/dist/store/watchers.d.ts +17 -0
- package/dist/store/watchers.d.ts.map +1 -0
- package/dist/store/watchers.js +56 -0
- package/dist/store/writes.d.ts +24 -0
- package/dist/store/writes.d.ts.map +1 -0
- package/dist/store/writes.js +125 -0
- package/dist/store.d.ts +112 -145
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +167 -365
- package/dist/stored.d.ts +59 -33
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +279 -190
- package/dist/surface.d.ts +88 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +223 -0
- package/dist/sync.d.ts +19 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +540 -0
- package/dist/tables.d.ts +116 -29
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +213 -54
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +129 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +8 -5
- 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 +57 -5
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +19 -3
- package/package.json +3 -2
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- package/dist/fence.d.ts +0 -6
- package/dist/fence.d.ts.map +0 -1
- package/dist/fence.js +0 -10
- package/dist/fulltext.d.ts +0 -27
- package/dist/fulltext.d.ts.map +0 -1
- package/dist/fulltext.js +0 -370
- package/dist/words.d.ts +0 -19
- package/dist/words.d.ts.map +0 -1
- package/dist/words.js +0 -156
package/dist/locks.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { uncaught } from './failure.js';
|
|
2
|
+
import { emitRooms, LOCKS_TOPIC } from './shown.js';
|
|
3
|
+
export async function locked({ store, presence }, locator) {
|
|
4
|
+
return presence.locked(locator, async () => (await store.open()).offline(locator));
|
|
5
|
+
}
|
|
6
|
+
export async function lockedRooms({ store, presence }) {
|
|
7
|
+
const held = (await store.covering()).rooms;
|
|
8
|
+
return presence.lockedAmong(new Map([...held].map(([locator, { offline }]) => [locator, offline])));
|
|
9
|
+
}
|
|
10
|
+
export async function relocked(runtime, before) {
|
|
11
|
+
const after = await lockedRooms(runtime);
|
|
12
|
+
if (JSON.stringify(after) === JSON.stringify(before))
|
|
13
|
+
return;
|
|
14
|
+
runtime.journal.record(`locked ${after.length}`);
|
|
15
|
+
emitRooms(runtime);
|
|
16
|
+
runtime.store.tell(LOCKS_TOPIC, undefined);
|
|
17
|
+
}
|
|
18
|
+
export function connectionLost(runtime) {
|
|
19
|
+
const { socket, presence } = runtime;
|
|
20
|
+
if (socket.closed())
|
|
21
|
+
return;
|
|
22
|
+
presence.connectionLost(() => {
|
|
23
|
+
if (socket.isOpen() || socket.closed())
|
|
24
|
+
return;
|
|
25
|
+
void lockedRooms(runtime).then((before) => {
|
|
26
|
+
presence.lapse();
|
|
27
|
+
return relocked(runtime, before);
|
|
28
|
+
}, uncaught);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export function watchLocks({ store }, notify) {
|
|
32
|
+
return store.watch(LOCKS_TOPIC, notify).stop;
|
|
33
|
+
}
|
package/dist/log.d.ts
CHANGED
package/dist/log.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAEA,wBAAgB,SAAS;IAGrB,MAAM,QAAQ,MAAM;IAIpB,MAAM;EAIT"}
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAEA,wBAAgB,SAAS;IAGrB,MAAM,QAAQ,MAAM;IAIpB,MAAM;EAIT;AAED,MAAM,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC"}
|
package/dist/lost.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Runtime } from './runtime.js';
|
|
2
|
+
export declare function eraseFenced({ store }: Runtime, locators: readonly string[]): Promise<void>;
|
|
3
|
+
export declare function fenceLive(runtime: Runtime, locators: readonly string[]): void;
|
|
4
|
+
export declare function loseRooms(runtime: Runtime, locators: readonly string[]): Promise<void>;
|
|
5
|
+
//# sourceMappingURL=lost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lost.d.ts","sourceRoot":"","sources":["../src/lost.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAK5C,wBAAsB,WAAW,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,iBAIhF;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,QAOtE;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,iBA+B5E"}
|
package/dist/lost.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { changeSet, mergeChangeSets } from './change-set.js';
|
|
2
|
+
import { ERASE_BATCH } from './install.js';
|
|
3
|
+
import { unpair } from './queue.js';
|
|
4
|
+
import { recoverReads } from './shown.js';
|
|
5
|
+
import { yielded } from './turn.js';
|
|
6
|
+
export async function eraseFenced({ store }, locators) {
|
|
7
|
+
for (const locator of locators) {
|
|
8
|
+
while (await store.durably((local) => local.erase(locator, ERASE_BATCH)))
|
|
9
|
+
await yielded();
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function fenceLive(runtime, locators) {
|
|
13
|
+
const { store, socket, presence, journal } = runtime;
|
|
14
|
+
for (const locator of new Set(locators)) {
|
|
15
|
+
if (!presence.lose(locator, socket.session.now().discoveries))
|
|
16
|
+
continue;
|
|
17
|
+
store.forget(locator);
|
|
18
|
+
journal.record(`room lost ${locator}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export async function loseRooms(runtime, locators) {
|
|
22
|
+
const { store, presence } = runtime;
|
|
23
|
+
fenceLive(runtime, locators);
|
|
24
|
+
const fresh = [...new Set(locators)].filter((locator) => presence.writing(locator));
|
|
25
|
+
if (fresh.length === 0)
|
|
26
|
+
return;
|
|
27
|
+
let held = [];
|
|
28
|
+
try {
|
|
29
|
+
await store.durably(async (local) => {
|
|
30
|
+
held = await local.roomDrafts();
|
|
31
|
+
await local.fence(fresh);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
for (const locator of fresh)
|
|
36
|
+
presence.unwritten(locator);
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
store.changed(mergeChangeSets(fresh.map((locator) => changeSet(locator, {
|
|
41
|
+
documents: null,
|
|
42
|
+
room: true,
|
|
43
|
+
queue: true,
|
|
44
|
+
drafts: held.filter((draft) => draft.locator === locator).map(({ path }) => path),
|
|
45
|
+
}))));
|
|
46
|
+
recoverReads(runtime);
|
|
47
|
+
}
|
|
48
|
+
await unpair(runtime);
|
|
49
|
+
await eraseFenced(runtime, fresh);
|
|
50
|
+
}
|
package/dist/media.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ import { type ShownAnswer } from './outcome.js';
|
|
|
3
3
|
export declare const ROOM_MEDIA = "room-media";
|
|
4
4
|
type Show = (room: string, path: string, revision?: string) => Promise<ShownAnswer>;
|
|
5
5
|
export declare function shownBy(show: Show, client: MdRuntimeClient): MdRuntimeClient;
|
|
6
|
-
export declare function defineRoomMedia(client: Promise<MdRuntimeClient> | MdRuntimeClient
|
|
6
|
+
export declare function defineRoomMedia(client: Promise<MdRuntimeClient> | MdRuntimeClient): void;
|
|
7
7
|
export {};
|
|
8
8
|
//# sourceMappingURL=media.d.ts.map
|
package/dist/media.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3D,eAAO,MAAM,UAAU,eAAe,CAAC;AAwBvC,KAAK,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;AAIpF,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,GAAG,eAAe,CAG5E;AAsBD,wBAAgB,eAAe,
|
|
1
|
+
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3D,eAAO,MAAM,UAAU,eAAe,CAAC;AAwBvC,KAAK,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;AAIpF,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,GAAG,eAAe,CAG5E;AAsBD,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,GAAG,IAAI,CA0LxF"}
|
package/dist/media.js
CHANGED
|
@@ -37,8 +37,8 @@ function drawnFor(mediaType) {
|
|
|
37
37
|
return 'audio';
|
|
38
38
|
return null;
|
|
39
39
|
}
|
|
40
|
-
export function defineRoomMedia(client
|
|
41
|
-
if (
|
|
40
|
+
export function defineRoomMedia(client) {
|
|
41
|
+
if (customElements.get(ROOM_MEDIA) !== undefined)
|
|
42
42
|
return;
|
|
43
43
|
const connected = Promise.resolve(client);
|
|
44
44
|
class RoomMedia extends HTMLElement {
|
|
@@ -179,7 +179,7 @@ export function defineRoomMedia(client, registry = customElements) {
|
|
|
179
179
|
if (drawn instanceof HTMLMediaElement) {
|
|
180
180
|
drawn.controls = true;
|
|
181
181
|
drawn.preload = 'metadata';
|
|
182
|
-
if (drawn instanceof HTMLVideoElement)
|
|
182
|
+
if (drawn instanceof HTMLVideoElement && 'playsInline' in drawn)
|
|
183
183
|
drawn.playsInline = true;
|
|
184
184
|
}
|
|
185
185
|
drawn.addEventListener(drawn instanceof HTMLImageElement ? 'load' : 'loadedmetadata', () => {
|
|
@@ -214,5 +214,5 @@ export function defineRoomMedia(client, registry = customElements) {
|
|
|
214
214
|
void this.#load();
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
-
|
|
217
|
+
customElements.define(ROOM_MEDIA, RoomMedia);
|
|
218
218
|
}
|
package/dist/memory.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { ModelResult } from './model.js';
|
|
2
|
-
import { type AcceptedMessage, type ActionResult, type Adapter, type BinaryFile, type Capability, type ConversationAction, type ConversationEvent, type DiscoveredRoom, type HeadChange, type ListedAgent, type ListedConversation, type Member, type ProviderLimit, type Retention, type ServiceMode } from './adapter.js';
|
|
3
|
-
export type MemoryRoom = DiscoveredRoom & {
|
|
2
|
+
import { type AcceptedMessage, type ActionResult, type Adapter, type BinaryFile, type Capability, type ConversationAction, type ConversationEvent, type DiscoveredRoom, type SavedFacts, type HeadChange, type ListedAgent, type ListedConversation, type Member, type ProviderLimit, type Retention, type ServiceMode, type TypedPath, type TypedSelection } from './adapter.js';
|
|
3
|
+
export type MemoryRoom = Omit<DiscoveredRoom, 'typedSelection' | 'authoredPaths'> & {
|
|
4
|
+
typedSelection?: TypedSelection | null;
|
|
5
|
+
authoredPaths?: readonly string[];
|
|
4
6
|
model?: ModelResult;
|
|
5
7
|
documents?: Readonly<Record<string, string>>;
|
|
8
|
+
facts?: Readonly<Record<string, SavedFacts>>;
|
|
6
9
|
revisions?: Readonly<Record<string, string>>;
|
|
7
10
|
fileIds?: Readonly<Record<string, string>>;
|
|
11
|
+
created?: Readonly<Record<string, string>>;
|
|
8
12
|
changes?: Readonly<Record<string, HeadChange>>;
|
|
9
13
|
binaryFiles?: Readonly<Record<string, BinaryFile>>;
|
|
10
14
|
folders?: readonly string[];
|
|
@@ -28,6 +32,7 @@ export type MemoryAdapterOptions = {
|
|
|
28
32
|
member?: Member;
|
|
29
33
|
unopened?: boolean;
|
|
30
34
|
roomTypes?: string;
|
|
35
|
+
typedPaths?: readonly TypedPath[];
|
|
31
36
|
};
|
|
32
37
|
export type MemoryAdapter = Adapter & {
|
|
33
38
|
discover: NonNullable<Adapter['discover']>;
|
|
@@ -39,6 +44,7 @@ export type MemoryAdapter = Adapter & {
|
|
|
39
44
|
close(closing?: {
|
|
40
45
|
revoked?: boolean;
|
|
41
46
|
lost?: boolean;
|
|
47
|
+
authorityChanged?: boolean;
|
|
42
48
|
}): void;
|
|
43
49
|
expire(locators: readonly string[]): void;
|
|
44
50
|
notifyRoomVersion(notification: {
|
package/dist/memory.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,YAAY,EACjB,KAAK,OAAO,EAIZ,KAAK,UAAU,EAMf,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAKtB,K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IAAI,IAAI,IAAI,CAAC;IACb,KAAK,CAAC,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC;QAAC,gBAAgB,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IACzF,MAAM,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IAC1C,iBAAiB,CAAC,YAAY,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAChF,sBAAsB,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IAC3D,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACnD,iBAAiB,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3C,SAAS,IAAI,SAAS,MAAM,EAAE,CAAC;IAC/B,uBAAuB,IAAI,SAAS,MAAM,EAAE,CAAC;IAC7C,sBAAsB,IAAI,MAAM,GAAG,IAAI,CAAC;CACzC,CAAC;AA0CF,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,oBAAyB,GAAG,aAAa,CA0qBrF"}
|
package/dist/memory.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { definitionAt, documentFacts, parse } from '@agentshouse/mdmodel';
|
|
2
|
+
import { NO_ROOM_TYPES, schemaTypes } from './attached-model.js';
|
|
1
3
|
import { sameChange } from './overlay.js';
|
|
2
4
|
const ATTACHMENTS = 'attachments';
|
|
3
5
|
function lastName(path) {
|
|
@@ -5,7 +7,6 @@ function lastName(path) {
|
|
|
5
7
|
}
|
|
6
8
|
const FIXTURE_RETENTION = {
|
|
7
9
|
history: { kind: 'duration', seconds: 1 },
|
|
8
|
-
outcome: 604_800,
|
|
9
10
|
refreshHorizon: 1,
|
|
10
11
|
};
|
|
11
12
|
function declaredRetention(value) {
|
|
@@ -52,7 +53,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
52
53
|
const listeners = new Set();
|
|
53
54
|
const modeObservers = new Set();
|
|
54
55
|
const scripted = new Map();
|
|
55
|
-
const
|
|
56
|
+
const repeats = new Map();
|
|
56
57
|
const historyPageSize = options.historyPageSize;
|
|
57
58
|
const attached = new Map();
|
|
58
59
|
const linked = new WeakMap();
|
|
@@ -102,8 +103,37 @@ export function createMemoryAdapter(options = {}) {
|
|
|
102
103
|
return path;
|
|
103
104
|
}
|
|
104
105
|
}
|
|
106
|
+
const saved = new WeakMap();
|
|
107
|
+
function factsAt(room, path, content) {
|
|
108
|
+
const types = schemaTypes(room.model?.kind === 'model' ? room.model.snapshot.schema : null, NO_ROOM_TYPES);
|
|
109
|
+
let held = saved.get(types);
|
|
110
|
+
if (held === undefined) {
|
|
111
|
+
held = new Map();
|
|
112
|
+
saved.set(types, held);
|
|
113
|
+
}
|
|
114
|
+
const key = `${path}\u0000${content}`;
|
|
115
|
+
if (!held.has(key)) {
|
|
116
|
+
const facts = documentFacts(path, parse(content, path, definitionAt({ types }, path, options.typedPaths)), {
|
|
117
|
+
types,
|
|
118
|
+
});
|
|
119
|
+
held.set(key, facts === null ? null : JSON.parse(JSON.stringify(facts)));
|
|
120
|
+
}
|
|
121
|
+
return held.get(key);
|
|
122
|
+
}
|
|
123
|
+
function factsIn(room, paths) {
|
|
124
|
+
const facts = {};
|
|
125
|
+
for (const path of paths) {
|
|
126
|
+
const content = room.documents?.[path];
|
|
127
|
+
const held = room.facts?.[path] ?? (content === undefined ? null : factsAt(room, path, content));
|
|
128
|
+
if (held !== null)
|
|
129
|
+
facts[path] = held;
|
|
130
|
+
}
|
|
131
|
+
return facts;
|
|
132
|
+
}
|
|
105
133
|
function retain(entries) {
|
|
106
134
|
for (const room of entries) {
|
|
135
|
+
for (const [path, content] of Object.entries(room.documents ?? {}))
|
|
136
|
+
factsAt(room, path, content);
|
|
107
137
|
note(room.locator, room);
|
|
108
138
|
const versions = served.get(room.locator) ?? new Map();
|
|
109
139
|
versions.set(room.roomVersion, room);
|
|
@@ -119,8 +149,9 @@ export function createMemoryAdapter(options = {}) {
|
|
|
119
149
|
roomVersion: room.roomVersion,
|
|
120
150
|
operations: room.operations,
|
|
121
151
|
replica: room.replica,
|
|
122
|
-
|
|
152
|
+
typedSelection: room.typedSelection ?? null,
|
|
123
153
|
providerOwnedPaths: room.providerOwnedPaths,
|
|
154
|
+
authoredPaths: room.authoredPaths ?? ['**'],
|
|
124
155
|
};
|
|
125
156
|
}
|
|
126
157
|
function page(room, after) {
|
|
@@ -136,10 +167,14 @@ export function createMemoryAdapter(options = {}) {
|
|
|
136
167
|
roomVersion: room.roomVersion,
|
|
137
168
|
...(opening ? { models: modelsOf(room) } : {}),
|
|
138
169
|
documents: named(room.documents ?? {}, taken),
|
|
170
|
+
facts: factsIn(room, taken),
|
|
139
171
|
revisions: named(room.revisions ?? {}, [...taken, ...targets]),
|
|
140
172
|
...(room.fileIds === undefined
|
|
141
173
|
? {}
|
|
142
174
|
: { fileIds: named(room.fileIds, [...taken, ...targets]) }),
|
|
175
|
+
...(room.created === undefined
|
|
176
|
+
? {}
|
|
177
|
+
: { created: named(room.created, [...taken, ...targets]) }),
|
|
143
178
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
144
179
|
binaryFiles: named(room.binaryFiles ?? {}, targets),
|
|
145
180
|
...(opening && room.folders !== undefined ? { folders: room.folders } : {}),
|
|
@@ -163,6 +198,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
163
198
|
const previousTargets = new Set(Object.keys(from.binaryFiles ?? {}));
|
|
164
199
|
const headMoved = (path) => room.revisions?.[path] !== from.revisions?.[path] ||
|
|
165
200
|
room.fileIds?.[path] !== from.fileIds?.[path] ||
|
|
201
|
+
room.created?.[path] !== from.created?.[path] ||
|
|
166
202
|
!sameChange(room.changes?.[path], from.changes?.[path]);
|
|
167
203
|
const changed = Object.keys(current)
|
|
168
204
|
.filter((path) => current[path] !== previous[path] || headMoved(path))
|
|
@@ -183,10 +219,14 @@ export function createMemoryAdapter(options = {}) {
|
|
|
183
219
|
roomVersion: room.roomVersion,
|
|
184
220
|
...(models === undefined ? {} : { models }),
|
|
185
221
|
documents: named(current, taken),
|
|
222
|
+
facts: factsIn(room, taken),
|
|
186
223
|
revisions: named(room.revisions ?? {}, [...taken, ...targets]),
|
|
187
224
|
...(room.fileIds === undefined
|
|
188
225
|
? {}
|
|
189
226
|
: { fileIds: named(room.fileIds, [...taken, ...targets]) }),
|
|
227
|
+
...(room.created === undefined
|
|
228
|
+
? {}
|
|
229
|
+
: { created: named(room.created, [...taken, ...targets]) }),
|
|
190
230
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
191
231
|
binaryFiles: named(room.binaryFiles ?? {}, targets),
|
|
192
232
|
...(opening ? foldersMoved(room, from) : {}),
|
|
@@ -221,16 +261,14 @@ export function createMemoryAdapter(options = {}) {
|
|
|
221
261
|
}
|
|
222
262
|
function pageOf(conversation, after) {
|
|
223
263
|
const messages = conversation.messages ?? [];
|
|
224
|
-
const first = typeof after === 'string' ? messages.findIndex((message) => message.
|
|
264
|
+
const first = typeof after === 'string' ? messages.findIndex((message) => message.change > after) : 0;
|
|
225
265
|
const from = first === -1 ? messages.length : first;
|
|
226
266
|
const page = messages.slice(from, from + (historyPageSize ?? messages.length));
|
|
227
267
|
const last = page.at(-1);
|
|
228
268
|
return {
|
|
229
269
|
conversation: conversation.conversation,
|
|
230
270
|
messages: page,
|
|
231
|
-
...(last !== undefined && from + page.length < messages.length
|
|
232
|
-
? { next: last.position }
|
|
233
|
-
: {}),
|
|
271
|
+
...(last !== undefined && from + page.length < messages.length ? { next: last.change } : {}),
|
|
234
272
|
};
|
|
235
273
|
}
|
|
236
274
|
function historiesOf(request) {
|
|
@@ -250,11 +288,20 @@ export function createMemoryAdapter(options = {}) {
|
|
|
250
288
|
function conversationAction(request) {
|
|
251
289
|
const name = request.name;
|
|
252
290
|
const input = (request.input ?? {});
|
|
291
|
+
const operation = typeof input.operation_id === 'string' ? `${name}\u0000${input.operation_id}` : null;
|
|
292
|
+
const first = (answer) => {
|
|
293
|
+
if (operation !== null)
|
|
294
|
+
repeats.set(operation, answer);
|
|
295
|
+
return answer;
|
|
296
|
+
};
|
|
297
|
+
const repeated = operation === null ? undefined : repeats.get(operation);
|
|
253
298
|
if (name === 'conversations/create') {
|
|
299
|
+
if (repeated !== undefined)
|
|
300
|
+
return repeated;
|
|
254
301
|
issued += 1;
|
|
255
302
|
const conversation = `conversation-${issued}`;
|
|
256
303
|
scripted.set(conversation, { conversation });
|
|
257
|
-
return { kind: 'action', result: { conversation_id: conversation } };
|
|
304
|
+
return first({ kind: 'action', result: { conversation_id: conversation } });
|
|
258
305
|
}
|
|
259
306
|
const named = typeof input.conversation_id === 'string' ? input.conversation_id : '';
|
|
260
307
|
const conversation = scripted.get(named);
|
|
@@ -270,24 +317,30 @@ export function createMemoryAdapter(options = {}) {
|
|
|
270
317
|
if (outcome !== undefined)
|
|
271
318
|
return outcome;
|
|
272
319
|
if (name === 'conversations/send') {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
if (answered !== undefined)
|
|
276
|
-
return { kind: 'action', result: { message_id: answered } };
|
|
320
|
+
if (repeated !== undefined)
|
|
321
|
+
return repeated;
|
|
277
322
|
issued += 1;
|
|
278
|
-
|
|
279
|
-
if (operation !== null)
|
|
280
|
-
sentTurns.set(operation, turn);
|
|
281
|
-
return { kind: 'action', result: { message_id: turn } };
|
|
323
|
+
return first({ kind: 'action', result: { message_id: `turn-${issued}` } });
|
|
282
324
|
}
|
|
283
325
|
if (name === 'conversations/delete')
|
|
284
326
|
scripted.delete(named);
|
|
285
327
|
return { kind: 'action', result: { conversation_id: named } };
|
|
286
328
|
}
|
|
329
|
+
function decided(request) {
|
|
330
|
+
const { request: asked, message, decision, } = (request.input ?? {});
|
|
331
|
+
return {
|
|
332
|
+
kind: 'action',
|
|
333
|
+
result: {
|
|
334
|
+
request: asked,
|
|
335
|
+
...(message === undefined ? {} : { message }),
|
|
336
|
+
state: decision === 'approve' ? 'started' : 'declined',
|
|
337
|
+
},
|
|
338
|
+
};
|
|
339
|
+
}
|
|
287
340
|
function announceList() {
|
|
288
341
|
const entries = [...scripted.values()].flatMap(({ conversation, listed, messages = [] }) => listed === undefined
|
|
289
342
|
? []
|
|
290
|
-
: [{ conversation, ...listed, newest: messages.at(-1)?.
|
|
343
|
+
: [{ conversation, ...listed, newest: messages.at(-1)?.change ?? null }]);
|
|
291
344
|
for (const listener of listeners) {
|
|
292
345
|
listener({ kind: 'list', entries, whole: true, more: false, cursor: null });
|
|
293
346
|
}
|
|
@@ -322,7 +375,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
322
375
|
openings += 1;
|
|
323
376
|
carried.clear();
|
|
324
377
|
const revoked = answer.kind === 'revoked-authorization';
|
|
325
|
-
notify({ kind: 'closed', revoked, lost: !revoked });
|
|
378
|
+
notify({ kind: 'closed', revoked, lost: !revoked, authorityChanged: false });
|
|
326
379
|
return;
|
|
327
380
|
}
|
|
328
381
|
declaredRooms.clear();
|
|
@@ -337,6 +390,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
337
390
|
}
|
|
338
391
|
return {
|
|
339
392
|
...(options.roomTypes === undefined ? {} : { roomTypes: options.roomTypes }),
|
|
393
|
+
...(options.typedPaths === undefined ? {} : { typedPaths: options.typedPaths }),
|
|
340
394
|
setRooms(next) {
|
|
341
395
|
rooms = [...next];
|
|
342
396
|
retain(rooms);
|
|
@@ -349,10 +403,10 @@ export function createMemoryAdapter(options = {}) {
|
|
|
349
403
|
announceList();
|
|
350
404
|
opened(emitAll);
|
|
351
405
|
},
|
|
352
|
-
close({ revoked = false, lost = !revoked } = {}) {
|
|
406
|
+
close({ revoked = false, lost = !revoked, authorityChanged = false } = {}) {
|
|
353
407
|
openings += 1;
|
|
354
408
|
carried.clear();
|
|
355
|
-
emitAll({ kind: 'closed', revoked, lost });
|
|
409
|
+
emitAll({ kind: 'closed', revoked, lost, authorityChanged });
|
|
356
410
|
},
|
|
357
411
|
expire(locators) {
|
|
358
412
|
expiring = [...locators];
|
|
@@ -423,9 +477,10 @@ export function createMemoryAdapter(options = {}) {
|
|
|
423
477
|
const named = asked.map((room) => room.locator);
|
|
424
478
|
const unknown = asked.flatMap((room) => {
|
|
425
479
|
const current = rooms.find((entry) => entry.locator === room.locator);
|
|
480
|
+
const version = room.roomVersion;
|
|
426
481
|
return current === undefined ||
|
|
427
|
-
|
|
428
|
-
|
|
482
|
+
(version !== null &&
|
|
483
|
+
(current.roomVersion === version || served.get(room.locator)?.has(version) === true))
|
|
429
484
|
? []
|
|
430
485
|
: [room.locator];
|
|
431
486
|
});
|
|
@@ -435,7 +490,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
435
490
|
expiring = expiring.filter((locator) => !named.includes(locator));
|
|
436
491
|
queueMicrotask(() => {
|
|
437
492
|
for (const room of asked) {
|
|
438
|
-
if (expired.includes(room.locator))
|
|
493
|
+
if (expired.includes(room.locator) || room.roomVersion === null)
|
|
439
494
|
carried.delete(room.locator);
|
|
440
495
|
else {
|
|
441
496
|
carried.set(room.locator, room.roomVersion);
|
|
@@ -451,7 +506,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
451
506
|
if (!observers.has(notify))
|
|
452
507
|
return;
|
|
453
508
|
if (options.unopened === true) {
|
|
454
|
-
notify({ kind: 'closed', revoked: false, lost: true });
|
|
509
|
+
notify({ kind: 'closed', revoked: false, lost: true, authorityChanged: false });
|
|
455
510
|
return;
|
|
456
511
|
}
|
|
457
512
|
announceList();
|
|
@@ -559,7 +614,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
559
614
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
560
615
|
const blob = heldBlob(room, request.path);
|
|
561
616
|
return blob === undefined
|
|
562
|
-
? { kind: 'rejected', code: '
|
|
617
|
+
? { kind: 'rejected', code: 'not_found', fields: {}, retryable: false }
|
|
563
618
|
: { kind: 'binary', body: blob.stream(), mediaType: blob.type };
|
|
564
619
|
}, request);
|
|
565
620
|
},
|
|
@@ -570,7 +625,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
570
625
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
571
626
|
const blob = heldBlob(room, request.path);
|
|
572
627
|
if (blob === undefined) {
|
|
573
|
-
return { kind: 'rejected', code: '
|
|
628
|
+
return { kind: 'rejected', code: 'not_found', fields: {}, retryable: false };
|
|
574
629
|
}
|
|
575
630
|
const url = linked.get(blob) ?? URL.createObjectURL(blob);
|
|
576
631
|
linked.set(blob, url);
|
|
@@ -591,6 +646,8 @@ export function createMemoryAdapter(options = {}) {
|
|
|
591
646
|
return resolveScript(scripts.action, () => {
|
|
592
647
|
if (request.name.startsWith('conversations/'))
|
|
593
648
|
return conversationAction(request);
|
|
649
|
+
if (request.name === 'agent-functions/decide')
|
|
650
|
+
return decided(request);
|
|
594
651
|
return { kind: 'rejected', code: 'unscripted-action', fields: {}, retryable: false };
|
|
595
652
|
}, request).then((answer) => {
|
|
596
653
|
if (answer.kind === 'action' && answer.at !== undefined)
|
package/dist/messages.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AcceptedMessage } from './adapter.js';
|
|
2
2
|
import type { Connection } from './tables.js';
|
|
3
3
|
export declare const MESSAGE_TABLES: readonly string[];
|
|
4
|
+
export declare const ROWS = "WITH chosen AS (\n SELECT listed.value AS conversation,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'assistant' ORDER BY position DESC, identity DESC LIMIT 1) AS answer,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND text <> '' ORDER BY position DESC, identity DESC LIMIT 1) AS said,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'house' ORDER BY position, identity LIMIT 1) AS opened,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'house' AND json_extract(message, '$.waiting') = 1 ORDER BY position, identity LIMIT 1) AS asking\n FROM json_each(?) AS listed\n )\n SELECT chosen.conversation AS conversation,\n substr(said.text, 1, 512) AS said_text,\n json_extract(said.message, '$.role') AS said_role,\n json_extract(said.message, '$.accepted_at') AS said_at,\n substr(json_extract(answer.message, '$.failure'), 1, 512) AS failure,\n json_extract(opened.message, '$.source') AS opened_source,\n json_extract(opened.message, '$.sender') AS opened_sender,\n asking.identity AS asking_identity,\n asking.text AS asking_text,\n json_extract(asking.message, '$.accepted_at') AS asking_at,\n json_extract(asking.message, '$.source') AS asking_source,\n json_extract(asking.message, '$.sender') AS asking_sender\n FROM chosen\n LEFT JOIN conversation_messages said ON said.id = chosen.said\n LEFT JOIN conversation_messages answer ON answer.id = chosen.answer\n LEFT JOIN conversation_messages opened ON opened.id = chosen.opened\n LEFT JOIN conversation_messages asking ON asking.id = chosen.asking";
|
|
4
5
|
export type HeldConversation = {
|
|
5
6
|
readonly conversation: string;
|
|
6
7
|
readonly read: string | null | undefined;
|
|
@@ -10,6 +11,25 @@ export type MessageWindow = {
|
|
|
10
11
|
readonly messages: AcceptedMessage[];
|
|
11
12
|
readonly more: boolean;
|
|
12
13
|
};
|
|
14
|
+
export type HeldSource = {
|
|
15
|
+
readonly source: unknown;
|
|
16
|
+
readonly sender: string | null;
|
|
17
|
+
};
|
|
18
|
+
export type HeldRow = {
|
|
19
|
+
readonly conversation: string;
|
|
20
|
+
readonly said: {
|
|
21
|
+
readonly text: string;
|
|
22
|
+
readonly role: string | null;
|
|
23
|
+
readonly at: string | null;
|
|
24
|
+
} | null;
|
|
25
|
+
readonly failure: string | null;
|
|
26
|
+
readonly opened: HeldSource | null;
|
|
27
|
+
readonly asking: (HeldSource & {
|
|
28
|
+
readonly identity: string;
|
|
29
|
+
readonly text: string;
|
|
30
|
+
readonly at: string | null;
|
|
31
|
+
}) | null;
|
|
32
|
+
};
|
|
13
33
|
export type ConversationWrite = {
|
|
14
34
|
readonly conversation: string;
|
|
15
35
|
readonly messages: readonly AcceptedMessage[];
|
|
@@ -18,10 +38,11 @@ export type ConversationWrite = {
|
|
|
18
38
|
readonly partial: boolean;
|
|
19
39
|
};
|
|
20
40
|
};
|
|
21
|
-
export declare function heldConversations(connection: Connection): HeldConversation[];
|
|
41
|
+
export declare function heldConversations(connection: Connection, conversations: readonly string[] | null): HeldConversation[];
|
|
22
42
|
export declare function keptMessages(connection: Connection, { conversation, messages, read }: ConversationWrite): null;
|
|
23
|
-
export declare function messageWindow(connection: Connection, conversation: string, limit: number, before: readonly [string, string] | null): MessageWindow;
|
|
24
|
-
export declare function messageCount(connection: Connection, conversation: string): number;
|
|
43
|
+
export declare function messageWindow(connection: Connection, conversation: string, limit: number, before: readonly [string, string] | null, phrase: string | null): MessageWindow;
|
|
44
|
+
export declare function messageCount(connection: Connection, conversation: string, phrase: string | null): number;
|
|
45
|
+
export declare function conversationRows(connection: Connection, conversations: readonly string[]): HeldRow[];
|
|
25
46
|
export declare function turnArrived(connection: Connection, conversation: string, turn: string): boolean;
|
|
26
47
|
export declare function droppedMessages(connection: Connection, conversations: readonly string[]): void;
|
|
27
48
|
export declare function forgottenMessages(connection: Connection): void;
|
package/dist/messages.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAM1D,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAO3C,CAAC;AAQF,eAAO,MAAM,IAAI,qwDAwBqD,CAAC;AAEvE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,IA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