@agentshouse/mdruntime 0.1.0-c0bed82db8d73 → 0.1.0-c0c1e81da9166
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 +3 -2
- package/dist/adapter.d.ts +101 -71
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +4 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +35 -46
- package/dist/bootstrap.d.ts +16 -15
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +273 -131
- package/dist/chain.d.ts +2 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/change.d.ts +1 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/chat-types.d.ts +3 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +2 -0
- package/dist/client.d.ts +15 -9
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +54 -6
- package/dist/collection.d.ts +7 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +24 -19
- package/dist/compile.d.ts +6 -6
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +278 -282
- package/dist/connection.d.ts +16 -11
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +2312 -1988
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- package/dist/conversation-row.d.ts +33 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +47 -0
- package/dist/conversation.d.ts +27 -18
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +489 -260
- package/dist/durability.d.ts +6 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +3 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +18 -8
- package/dist/figures.d.ts +48 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +197 -0
- package/dist/file.d.ts +2 -11
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +6 -4
- package/dist/host.d.ts +3 -7
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +26 -29
- 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 +16 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/job.d.ts +33 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +54 -0
- package/dist/live.d.ts +5 -4
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +62 -20
- package/dist/media.d.ts +8 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +218 -0
- package/dist/memory.d.ts +13 -6
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +218 -91
- package/dist/messages.d.ts +27 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +97 -19
- package/dist/model.d.ts +8 -10
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +6 -18
- package/dist/observation.d.ts +3 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +8 -3
- package/dist/outcome.d.ts +13 -5
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +16 -2
- package/dist/overlay.d.ts +1 -0
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +11 -0
- package/dist/parts.d.ts +59 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +118 -0
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +4 -0
- package/dist/query.d.ts +18 -207
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -505
- package/dist/questions.d.ts +32 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +118 -0
- package/dist/reach.d.ts +18 -11
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +201 -126
- package/dist/react.d.ts +3 -1
- package/dist/react.d.ts.map +1 -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 +3 -17
- 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 +35 -1
- package/dist/refresh.d.ts +7 -5
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +34 -10
- package/dist/replica.d.ts +10 -9
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +53 -21
- package/dist/room-draft.d.ts +21 -5
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +98 -51
- package/dist/rows.d.ts +18 -16
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +45 -153
- package/dist/save.d.ts +2 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +22 -13
- 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/source.d.ts +61 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +81 -0
- package/dist/status.d.ts +4 -5
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -7
- package/dist/store.d.ts +104 -62
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +159 -161
- package/dist/stored.d.ts +66 -55
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +343 -273
- package/dist/tables.d.ts +110 -65
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +188 -99
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +129 -0
- 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 +42 -100
- 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 +18 -8
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +6 -2
- package/package.json +2 -3
- package/AGENTS.md +0 -312
- 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 -368
- package/dist/reads.d.ts +0 -11
- package/dist/reads.d.ts.map +0 -1
- package/dist/reads.js +0 -100
- package/dist/words.d.ts +0 -19
- package/dist/words.d.ts.map +0 -1
- package/dist/words.js +0 -150
package/dist/memory.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
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
|
|
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 } from './adapter.js';
|
|
3
3
|
export type MemoryRoom = DiscoveredRoom & {
|
|
4
4
|
model?: ModelResult;
|
|
5
|
-
selectionModel?: ModelResult;
|
|
6
5
|
documents?: Readonly<Record<string, string>>;
|
|
6
|
+
facts?: Readonly<Record<string, SavedFacts>>;
|
|
7
7
|
revisions?: Readonly<Record<string, string>>;
|
|
8
8
|
fileIds?: Readonly<Record<string, string>>;
|
|
9
|
+
created?: Readonly<Record<string, string>>;
|
|
9
10
|
changes?: Readonly<Record<string, HeadChange>>;
|
|
10
11
|
binaryFiles?: Readonly<Record<string, BinaryFile>>;
|
|
11
12
|
folders?: readonly string[];
|
|
@@ -13,13 +14,14 @@ export type MemoryRoom = DiscoveredRoom & {
|
|
|
13
14
|
};
|
|
14
15
|
export type MemoryConversation = {
|
|
15
16
|
conversation: string;
|
|
16
|
-
listed?: Omit<ListedConversation, 'conversation'>;
|
|
17
|
+
listed?: Omit<ListedConversation, 'conversation' | 'newest'>;
|
|
17
18
|
messages?: readonly AcceptedMessage[];
|
|
18
|
-
outcomes?: Partial<Record<ConversationAction, ActionResult>>;
|
|
19
|
+
outcomes?: Partial<Record<ConversationAction | 'history', ActionResult>>;
|
|
19
20
|
};
|
|
20
21
|
export type MemoryAdapterOptions = {
|
|
21
22
|
rooms?: readonly MemoryRoom[];
|
|
22
23
|
conversations?: readonly MemoryConversation[];
|
|
24
|
+
agents?: readonly ListedAgent[];
|
|
23
25
|
historyPageSize?: number;
|
|
24
26
|
pageSize?: number;
|
|
25
27
|
capabilities?: readonly Capability[];
|
|
@@ -27,9 +29,12 @@ export type MemoryAdapterOptions = {
|
|
|
27
29
|
retention?: Retention;
|
|
28
30
|
member?: Member;
|
|
29
31
|
unopened?: boolean;
|
|
30
|
-
|
|
32
|
+
roomTypes?: string;
|
|
33
|
+
typedPaths?: readonly TypedPath[];
|
|
31
34
|
};
|
|
32
35
|
export type MemoryAdapter = Adapter & {
|
|
36
|
+
discover: NonNullable<Adapter['discover']>;
|
|
37
|
+
refresh: NonNullable<Adapter['refresh']>;
|
|
33
38
|
setRooms(rooms: readonly MemoryRoom[]): void;
|
|
34
39
|
setConversations(conversations: readonly MemoryConversation[]): void;
|
|
35
40
|
script(operation: keyof Adapter, answer: unknown): void;
|
|
@@ -37,17 +42,19 @@ export type MemoryAdapter = Adapter & {
|
|
|
37
42
|
close(closing?: {
|
|
38
43
|
revoked?: boolean;
|
|
39
44
|
lost?: boolean;
|
|
45
|
+
authorityChanged?: boolean;
|
|
40
46
|
}): void;
|
|
41
47
|
expire(locators: readonly string[]): void;
|
|
42
48
|
notifyRoomVersion(notification: {
|
|
43
49
|
locator: string;
|
|
44
50
|
roomVersion: string;
|
|
45
51
|
}): void;
|
|
46
|
-
notifyAuthorityChanged(
|
|
52
|
+
notifyAuthorityChanged(locators?: readonly string[]): void;
|
|
47
53
|
notifyConversation(event: ConversationEvent): void;
|
|
48
54
|
notifyServiceMode(mode: ServiceMode): void;
|
|
49
55
|
heldRooms(): readonly string[];
|
|
50
56
|
replicatedConversations(): readonly string[];
|
|
57
|
+
heldConversationCursor(): string | null;
|
|
51
58
|
};
|
|
52
59
|
export declare function createMemoryAdapter(options?: MemoryAdapterOptions): MemoryAdapter;
|
|
53
60
|
//# sourceMappingURL=memory.d.ts.map
|
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,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,UAAU,EAGf,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,MAAM,EAGX,KAAK,aAAa,EAIlB,KAAK,SAAS,EAGd,KAAK,WAAW,EAChB,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAuBtB,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG;IACxC,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7C,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IAC7C,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC3C,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC3C,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IAC/C,WAAW,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IACnD,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,IAAI,CAAC,kBAAkB,EAAE,cAAc,GAAG,QAAQ,CAAC,CAAC;IAC7D,QAAQ,CAAC,EAAE,SAAS,eAAe,EAAE,CAAC;IACtC,QAAQ,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,kBAAkB,GAAG,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC;CAC1E,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;IAC9B,aAAa,CAAC,EAAE,SAAS,kBAAkB,EAAE,CAAC;IAC9C,MAAM,CAAC,EAAE,SAAS,WAAW,EAAE,CAAC;IAChC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;IACrC,cAAc,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;IAC1C,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG;IACpC,QAAQ,EAAE,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;IAC3C,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;IACzC,QAAQ,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,IAAI,CAAC;IAC7C,gBAAgB,CAAC,aAAa,EAAE,SAAS,kBAAkB,EAAE,GAAG,IAAI,CAAC;IACrE,MAAM,CAAC,SAAS,EAAE,MAAM,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IACxD,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,CAgpBrF"}
|
package/dist/memory.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import { documentFacts, parse } from '@agentshouse/mdmodel';
|
|
2
|
+
import { NO_ROOM_TYPES, schemaTypes } from './attached-model.js';
|
|
1
3
|
import { sameChange } from './overlay.js';
|
|
4
|
+
const ATTACHMENTS = 'attachments';
|
|
5
|
+
function lastName(path) {
|
|
6
|
+
return path.slice(path.lastIndexOf('/') + 1);
|
|
7
|
+
}
|
|
2
8
|
const FIXTURE_RETENTION = {
|
|
3
9
|
history: { kind: 'duration', seconds: 1 },
|
|
4
|
-
outcome: 604_800,
|
|
5
10
|
refreshHorizon: 1,
|
|
6
11
|
};
|
|
7
12
|
function declaredRetention(value) {
|
|
@@ -15,12 +20,7 @@ function declaredRetention(value) {
|
|
|
15
20
|
}
|
|
16
21
|
const MODEL_ABSENT = { kind: 'model-unavailable', reason: 'not-readable' };
|
|
17
22
|
function modelsOf(room) {
|
|
18
|
-
return {
|
|
19
|
-
collection: room.model ?? MODEL_ABSENT,
|
|
20
|
-
...(room.typedSelection === undefined
|
|
21
|
-
? {}
|
|
22
|
-
: { selection: room.selectionModel ?? MODEL_ABSENT }),
|
|
23
|
-
};
|
|
23
|
+
return { collection: room.model ?? MODEL_ABSENT };
|
|
24
24
|
}
|
|
25
25
|
function changedModels(room, from) {
|
|
26
26
|
const now = modelsOf(room);
|
|
@@ -53,13 +53,16 @@ export function createMemoryAdapter(options = {}) {
|
|
|
53
53
|
const listeners = new Set();
|
|
54
54
|
const modeObservers = new Set();
|
|
55
55
|
const scripted = new Map();
|
|
56
|
-
const unsealed = new Map();
|
|
57
|
-
const sealed = new Set();
|
|
58
56
|
const sentTurns = new Map();
|
|
59
57
|
const historyPageSize = options.historyPageSize;
|
|
60
|
-
|
|
58
|
+
const attached = new Map();
|
|
59
|
+
const linked = new WeakMap();
|
|
60
|
+
const carried = new Map();
|
|
61
61
|
let expiring = [];
|
|
62
|
+
let openings = 0;
|
|
63
|
+
const declaredRooms = new Set();
|
|
62
64
|
let replicated = [];
|
|
65
|
+
let heldCursor = null;
|
|
63
66
|
let issued = 0;
|
|
64
67
|
function scriptConversations(entries) {
|
|
65
68
|
scripted.clear();
|
|
@@ -87,8 +90,48 @@ export function createMemoryAdapter(options = {}) {
|
|
|
87
90
|
const wanted = ordinals.get(`${locator}\u0000${target}`);
|
|
88
91
|
return held !== undefined && wanted !== undefined && held >= wanted;
|
|
89
92
|
}
|
|
93
|
+
function heldBlob(room, path) {
|
|
94
|
+
return attached.get(`${room.locator}\u0000${path}`) ?? room.blobs?.[path];
|
|
95
|
+
}
|
|
96
|
+
function freePath(room, name) {
|
|
97
|
+
const dot = name.lastIndexOf('.');
|
|
98
|
+
const stem = dot > 0 ? name.slice(0, dot) : name;
|
|
99
|
+
const extension = dot > 0 ? name.slice(dot) : '';
|
|
100
|
+
for (let count = 1;; count += 1) {
|
|
101
|
+
const path = `${ATTACHMENTS}/${count === 1 ? stem : `${stem}-${count}`}${extension}`;
|
|
102
|
+
if (heldBlob(room, path) === undefined && room.documents?.[path] === undefined)
|
|
103
|
+
return path;
|
|
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), { types });
|
|
117
|
+
held.set(key, facts === null ? null : JSON.parse(JSON.stringify(facts)));
|
|
118
|
+
}
|
|
119
|
+
return held.get(key);
|
|
120
|
+
}
|
|
121
|
+
function factsIn(room, paths) {
|
|
122
|
+
const facts = {};
|
|
123
|
+
for (const path of paths) {
|
|
124
|
+
const content = room.documents?.[path];
|
|
125
|
+
const held = room.facts?.[path] ?? (content === undefined ? null : factsAt(room, path, content));
|
|
126
|
+
if (held !== null)
|
|
127
|
+
facts[path] = held;
|
|
128
|
+
}
|
|
129
|
+
return facts;
|
|
130
|
+
}
|
|
90
131
|
function retain(entries) {
|
|
91
132
|
for (const room of entries) {
|
|
133
|
+
for (const [path, content] of Object.entries(room.documents ?? {}))
|
|
134
|
+
factsAt(room, path, content);
|
|
92
135
|
note(room.locator, room);
|
|
93
136
|
const versions = served.get(room.locator) ?? new Map();
|
|
94
137
|
versions.set(room.roomVersion, room);
|
|
@@ -121,10 +164,14 @@ export function createMemoryAdapter(options = {}) {
|
|
|
121
164
|
roomVersion: room.roomVersion,
|
|
122
165
|
...(opening ? { models: modelsOf(room) } : {}),
|
|
123
166
|
documents: named(room.documents ?? {}, taken),
|
|
167
|
+
facts: factsIn(room, taken),
|
|
124
168
|
revisions: named(room.revisions ?? {}, [...taken, ...targets]),
|
|
125
169
|
...(room.fileIds === undefined
|
|
126
170
|
? {}
|
|
127
171
|
: { fileIds: named(room.fileIds, [...taken, ...targets]) }),
|
|
172
|
+
...(room.created === undefined
|
|
173
|
+
? {}
|
|
174
|
+
: { created: named(room.created, [...taken, ...targets]) }),
|
|
128
175
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
129
176
|
binaryFiles: named(room.binaryFiles ?? {}, targets),
|
|
130
177
|
...(opening && room.folders !== undefined ? { folders: room.folders } : {}),
|
|
@@ -141,18 +188,19 @@ export function createMemoryAdapter(options = {}) {
|
|
|
141
188
|
...(folderRemovals.length === 0 ? {} : { folderRemovals }),
|
|
142
189
|
};
|
|
143
190
|
}
|
|
144
|
-
function advancement(room, from, at) {
|
|
191
|
+
function advancement(room, from, at, whole = false) {
|
|
145
192
|
const current = room.documents ?? {};
|
|
146
193
|
const previous = from.documents ?? {};
|
|
147
194
|
const currentTargets = new Set(Object.keys(room.binaryFiles ?? {}));
|
|
148
195
|
const previousTargets = new Set(Object.keys(from.binaryFiles ?? {}));
|
|
149
196
|
const headMoved = (path) => room.revisions?.[path] !== from.revisions?.[path] ||
|
|
150
197
|
room.fileIds?.[path] !== from.fileIds?.[path] ||
|
|
198
|
+
room.created?.[path] !== from.created?.[path] ||
|
|
151
199
|
!sameChange(room.changes?.[path], from.changes?.[path]);
|
|
152
200
|
const changed = Object.keys(current)
|
|
153
201
|
.filter((path) => current[path] !== previous[path] || headMoved(path))
|
|
154
202
|
.sort();
|
|
155
|
-
const size = pageSize ?? changed.length;
|
|
203
|
+
const size = whole ? changed.length : (pageSize ?? changed.length);
|
|
156
204
|
const taken = changed.slice(at, at + size);
|
|
157
205
|
const next = at + taken.length;
|
|
158
206
|
const opening = at === 0;
|
|
@@ -168,10 +216,14 @@ export function createMemoryAdapter(options = {}) {
|
|
|
168
216
|
roomVersion: room.roomVersion,
|
|
169
217
|
...(models === undefined ? {} : { models }),
|
|
170
218
|
documents: named(current, taken),
|
|
219
|
+
facts: factsIn(room, taken),
|
|
171
220
|
revisions: named(room.revisions ?? {}, [...taken, ...targets]),
|
|
172
221
|
...(room.fileIds === undefined
|
|
173
222
|
? {}
|
|
174
223
|
: { fileIds: named(room.fileIds, [...taken, ...targets]) }),
|
|
224
|
+
...(room.created === undefined
|
|
225
|
+
? {}
|
|
226
|
+
: { created: named(room.created, [...taken, ...targets]) }),
|
|
175
227
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
176
228
|
binaryFiles: named(room.binaryFiles ?? {}, targets),
|
|
177
229
|
...(opening ? foldersMoved(room, from) : {}),
|
|
@@ -184,6 +236,26 @@ export function createMemoryAdapter(options = {}) {
|
|
|
184
236
|
...(pageToken === undefined ? {} : { pageToken }),
|
|
185
237
|
};
|
|
186
238
|
}
|
|
239
|
+
function carry(locator) {
|
|
240
|
+
const at = carried.get(locator);
|
|
241
|
+
const current = rooms.find((entry) => entry.locator === locator);
|
|
242
|
+
if (at === undefined || current === undefined || current.roomVersion === at)
|
|
243
|
+
return;
|
|
244
|
+
const from = served.get(locator)?.get(at);
|
|
245
|
+
carried.set(locator, current.roomVersion);
|
|
246
|
+
if (from === undefined)
|
|
247
|
+
return;
|
|
248
|
+
const page = advancement(current, from, 0, true);
|
|
249
|
+
for (const observer of observers) {
|
|
250
|
+
observer({
|
|
251
|
+
kind: 'room-change',
|
|
252
|
+
locator,
|
|
253
|
+
from: at,
|
|
254
|
+
roomVersion: current.roomVersion,
|
|
255
|
+
read: async () => page,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
}
|
|
187
259
|
function pageOf(conversation, after) {
|
|
188
260
|
const messages = conversation.messages ?? [];
|
|
189
261
|
const first = typeof after === 'string' ? messages.findIndex((message) => message.position > after) : 0;
|
|
@@ -198,16 +270,13 @@ export function createMemoryAdapter(options = {}) {
|
|
|
198
270
|
: {}),
|
|
199
271
|
};
|
|
200
272
|
}
|
|
201
|
-
function historiesOf(
|
|
202
|
-
const asked = input?.conversations;
|
|
203
|
-
if (!Array.isArray(asked))
|
|
204
|
-
return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
|
|
273
|
+
function historiesOf(request) {
|
|
205
274
|
const histories = [];
|
|
206
|
-
for (const entry of
|
|
207
|
-
const conversation =
|
|
275
|
+
for (const entry of request.conversations) {
|
|
276
|
+
const conversation = scripted.get(entry.conversation);
|
|
208
277
|
if (conversation === undefined)
|
|
209
278
|
continue;
|
|
210
|
-
const outcome = conversation.outcomes?.
|
|
279
|
+
const outcome = conversation.outcomes?.history;
|
|
211
280
|
if (outcome !== undefined)
|
|
212
281
|
return outcome;
|
|
213
282
|
histories.push(pageOf(conversation, entry.after));
|
|
@@ -218,15 +287,13 @@ export function createMemoryAdapter(options = {}) {
|
|
|
218
287
|
function conversationAction(request) {
|
|
219
288
|
const name = request.name;
|
|
220
289
|
const input = (request.input ?? {});
|
|
221
|
-
if (name === '
|
|
222
|
-
return historiesOf(request.input);
|
|
223
|
-
if (name === 'conversation.create') {
|
|
290
|
+
if (name === 'conversations/create') {
|
|
224
291
|
issued += 1;
|
|
225
292
|
const conversation = `conversation-${issued}`;
|
|
226
293
|
scripted.set(conversation, { conversation });
|
|
227
|
-
return { kind: 'action', result: { conversation } };
|
|
294
|
+
return { kind: 'action', result: { conversation_id: conversation } };
|
|
228
295
|
}
|
|
229
|
-
const named = typeof input.
|
|
296
|
+
const named = typeof input.conversation_id === 'string' ? input.conversation_id : '';
|
|
230
297
|
const conversation = scripted.get(named);
|
|
231
298
|
if (conversation === undefined) {
|
|
232
299
|
return {
|
|
@@ -239,34 +306,28 @@ export function createMemoryAdapter(options = {}) {
|
|
|
239
306
|
const outcome = conversation.outcomes?.[name];
|
|
240
307
|
if (outcome !== undefined)
|
|
241
308
|
return outcome;
|
|
242
|
-
if (name === '
|
|
309
|
+
if (name === 'conversations/send') {
|
|
243
310
|
const operation = typeof input.operation_id === 'string' ? input.operation_id : null;
|
|
244
311
|
const answered = operation === null ? undefined : sentTurns.get(operation);
|
|
245
312
|
if (answered !== undefined)
|
|
246
|
-
return { kind: 'action', result: {
|
|
313
|
+
return { kind: 'action', result: { message_id: answered } };
|
|
247
314
|
issued += 1;
|
|
248
315
|
const turn = `turn-${issued}`;
|
|
249
|
-
unsealed.set(turn, named);
|
|
250
316
|
if (operation !== null)
|
|
251
317
|
sentTurns.set(operation, turn);
|
|
252
|
-
return { kind: 'action', result: { turn } };
|
|
253
|
-
}
|
|
254
|
-
if (name === 'conversation.cancel') {
|
|
255
|
-
const turn = typeof input.turn === 'string' ? input.turn : '';
|
|
256
|
-
if (sealed.has(turn) || !unsealed.has(turn)) {
|
|
257
|
-
return { kind: 'rejected', code: 'turn-sealed', fields: { turn }, retryable: false };
|
|
258
|
-
}
|
|
259
|
-
unsealed.delete(turn);
|
|
260
|
-
return { kind: 'action', result: { turn, cancelled: true } };
|
|
318
|
+
return { kind: 'action', result: { message_id: turn } };
|
|
261
319
|
}
|
|
262
|
-
if (name === '
|
|
320
|
+
if (name === 'conversations/delete')
|
|
263
321
|
scripted.delete(named);
|
|
264
|
-
return { kind: 'action', result: {
|
|
322
|
+
return { kind: 'action', result: { conversation_id: named } };
|
|
265
323
|
}
|
|
266
324
|
function announceList() {
|
|
267
|
-
const entries = [...scripted.values()].flatMap(({ conversation, listed }) => listed === undefined
|
|
268
|
-
|
|
269
|
-
|
|
325
|
+
const entries = [...scripted.values()].flatMap(({ conversation, listed, messages = [] }) => listed === undefined
|
|
326
|
+
? []
|
|
327
|
+
: [{ conversation, ...listed, newest: messages.at(-1)?.position ?? null }]);
|
|
328
|
+
for (const listener of listeners) {
|
|
329
|
+
listener({ kind: 'list', entries, whole: true, more: false, cursor: null });
|
|
330
|
+
}
|
|
270
331
|
}
|
|
271
332
|
function discovery() {
|
|
272
333
|
return {
|
|
@@ -278,8 +339,42 @@ export function createMemoryAdapter(options = {}) {
|
|
|
278
339
|
...(options.member === undefined ? {} : { member: options.member }),
|
|
279
340
|
};
|
|
280
341
|
}
|
|
342
|
+
function discovered() {
|
|
343
|
+
return resolveScript(scripts.discover, discovery, undefined).then((answer) => {
|
|
344
|
+
if (answer.kind === 'discovery')
|
|
345
|
+
for (const room of answer.rooms)
|
|
346
|
+
note(room.locator, room);
|
|
347
|
+
return answer;
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
function opened(notify) {
|
|
351
|
+
const opening = ++openings;
|
|
352
|
+
notify({ kind: 'opened' });
|
|
353
|
+
void discovered()
|
|
354
|
+
.catch(() => ({ kind: 'transport-uncertainty' }))
|
|
355
|
+
.then((answer) => {
|
|
356
|
+
if (opening !== openings)
|
|
357
|
+
return;
|
|
358
|
+
if (answer.kind !== 'discovery') {
|
|
359
|
+
openings += 1;
|
|
360
|
+
carried.clear();
|
|
361
|
+
const revoked = answer.kind === 'revoked-authorization';
|
|
362
|
+
notify({ kind: 'closed', revoked, lost: !revoked, authorityChanged: false });
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
declaredRooms.clear();
|
|
366
|
+
for (const room of answer.rooms)
|
|
367
|
+
declaredRooms.add(room.locator);
|
|
368
|
+
notify({ kind: 'discovered', discovery: answer });
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
function emitAll(event) {
|
|
372
|
+
for (const observer of observers)
|
|
373
|
+
observer(event);
|
|
374
|
+
}
|
|
281
375
|
return {
|
|
282
|
-
...(options.
|
|
376
|
+
...(options.roomTypes === undefined ? {} : { roomTypes: options.roomTypes }),
|
|
377
|
+
...(options.typedPaths === undefined ? {} : { typedPaths: options.typedPaths }),
|
|
283
378
|
setRooms(next) {
|
|
284
379
|
rooms = [...next];
|
|
285
380
|
retain(rooms);
|
|
@@ -288,33 +383,37 @@ export function createMemoryAdapter(options = {}) {
|
|
|
288
383
|
scriptConversations(next);
|
|
289
384
|
},
|
|
290
385
|
open() {
|
|
386
|
+
carried.clear();
|
|
291
387
|
announceList();
|
|
292
|
-
|
|
293
|
-
observer({ kind: 'opened' });
|
|
388
|
+
opened(emitAll);
|
|
294
389
|
},
|
|
295
|
-
close({ revoked = false, lost = !revoked } = {}) {
|
|
296
|
-
|
|
297
|
-
|
|
390
|
+
close({ revoked = false, lost = !revoked, authorityChanged = false } = {}) {
|
|
391
|
+
openings += 1;
|
|
392
|
+
carried.clear();
|
|
393
|
+
emitAll({ kind: 'closed', revoked, lost, authorityChanged });
|
|
298
394
|
},
|
|
299
395
|
expire(locators) {
|
|
300
396
|
expiring = [...locators];
|
|
301
397
|
},
|
|
302
|
-
notifyRoomVersion({ locator
|
|
303
|
-
|
|
304
|
-
observer({ kind: 'room-version', locator, roomVersion });
|
|
398
|
+
notifyRoomVersion({ locator }) {
|
|
399
|
+
carry(locator);
|
|
305
400
|
},
|
|
306
|
-
notifyAuthorityChanged(
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
401
|
+
notifyAuthorityChanged(locators) {
|
|
402
|
+
const named = new Set(locators ?? [...declaredRooms, ...rooms.map((room) => room.locator)]);
|
|
403
|
+
const listed = rooms.filter((room) => named.has(room.locator));
|
|
404
|
+
const left = [...named].filter((locator) => !listed.some((room) => room.locator === locator));
|
|
405
|
+
for (const room of listed)
|
|
406
|
+
declaredRooms.add(room.locator);
|
|
407
|
+
for (const locator of left)
|
|
408
|
+
declaredRooms.delete(locator);
|
|
409
|
+
emitAll({
|
|
410
|
+
kind: 'authority-changed',
|
|
411
|
+
rooms: listed.map(declared),
|
|
412
|
+
left,
|
|
413
|
+
...(options.member === undefined ? {} : { member: options.member }),
|
|
414
|
+
});
|
|
312
415
|
},
|
|
313
416
|
notifyConversation(event) {
|
|
314
|
-
if (event.kind === 'accepted-message') {
|
|
315
|
-
sealed.add(event.message.turn);
|
|
316
|
-
unsealed.delete(event.message.turn);
|
|
317
|
-
}
|
|
318
417
|
for (const listener of listeners)
|
|
319
418
|
listener(event);
|
|
320
419
|
},
|
|
@@ -323,21 +422,31 @@ export function createMemoryAdapter(options = {}) {
|
|
|
323
422
|
observer(mode);
|
|
324
423
|
},
|
|
325
424
|
heldRooms() {
|
|
326
|
-
return
|
|
425
|
+
return [...carried.keys()].sort();
|
|
327
426
|
},
|
|
328
427
|
replicatedConversations() {
|
|
329
428
|
return replicated;
|
|
330
429
|
},
|
|
430
|
+
heldConversationCursor() {
|
|
431
|
+
return heldCursor;
|
|
432
|
+
},
|
|
331
433
|
conversations: {
|
|
332
434
|
replicate(next) {
|
|
333
435
|
replicated = [...next];
|
|
334
436
|
},
|
|
437
|
+
hold(cursor) {
|
|
438
|
+
heldCursor = cursor;
|
|
439
|
+
},
|
|
335
440
|
observe(notify) {
|
|
336
441
|
listeners.add(notify);
|
|
337
442
|
return () => {
|
|
338
443
|
listeners.delete(notify);
|
|
339
444
|
};
|
|
340
445
|
},
|
|
446
|
+
history: (request) => Promise.resolve(historiesOf(request)),
|
|
447
|
+
...(options.agents === undefined
|
|
448
|
+
? {}
|
|
449
|
+
: { agents: () => Promise.resolve(structuredClone(options.agents)) }),
|
|
341
450
|
},
|
|
342
451
|
serviceMode: {
|
|
343
452
|
observe(notify) {
|
|
@@ -349,44 +458,46 @@ export function createMemoryAdapter(options = {}) {
|
|
|
349
458
|
},
|
|
350
459
|
roomStream: {
|
|
351
460
|
hold(asked) {
|
|
352
|
-
|
|
353
|
-
const
|
|
354
|
-
expiring = [];
|
|
355
|
-
const moved = asked.flatMap((room) => {
|
|
461
|
+
const named = asked.map((room) => room.locator);
|
|
462
|
+
const unknown = asked.flatMap((room) => {
|
|
356
463
|
const current = rooms.find((entry) => entry.locator === room.locator);
|
|
464
|
+
const version = room.roomVersion;
|
|
357
465
|
return current === undefined ||
|
|
358
|
-
|
|
359
|
-
|
|
466
|
+
(version !== null &&
|
|
467
|
+
(current.roomVersion === version || served.get(room.locator)?.has(version) === true))
|
|
360
468
|
? []
|
|
361
|
-
: [
|
|
469
|
+
: [room.locator];
|
|
362
470
|
});
|
|
471
|
+
const expired = [
|
|
472
|
+
...new Set([...expiring.filter((locator) => named.includes(locator)), ...unknown]),
|
|
473
|
+
];
|
|
474
|
+
expiring = expiring.filter((locator) => !named.includes(locator));
|
|
363
475
|
queueMicrotask(() => {
|
|
364
|
-
for (const
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
476
|
+
for (const room of asked) {
|
|
477
|
+
if (expired.includes(room.locator) || room.roomVersion === null)
|
|
478
|
+
carried.delete(room.locator);
|
|
479
|
+
else {
|
|
480
|
+
carried.set(room.locator, room.roomVersion);
|
|
481
|
+
carry(room.locator);
|
|
482
|
+
}
|
|
368
483
|
}
|
|
484
|
+
emitAll({ kind: 'caught-up', expired });
|
|
369
485
|
});
|
|
370
486
|
},
|
|
371
|
-
reopen() {
|
|
372
|
-
queueMicrotask(() => {
|
|
373
|
-
for (const observer of observers) {
|
|
374
|
-
observer({ kind: 'closed', revoked: false, lost: false });
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
},
|
|
378
|
-
published() { },
|
|
379
487
|
observe(notify) {
|
|
380
488
|
observers.add(notify);
|
|
381
489
|
queueMicrotask(() => {
|
|
382
490
|
if (!observers.has(notify))
|
|
383
491
|
return;
|
|
384
492
|
if (options.unopened === true) {
|
|
385
|
-
notify({ kind: 'closed', revoked: false, lost: true });
|
|
493
|
+
notify({ kind: 'closed', revoked: false, lost: true, authorityChanged: false });
|
|
386
494
|
return;
|
|
387
495
|
}
|
|
388
496
|
announceList();
|
|
389
|
-
|
|
497
|
+
opened((event) => {
|
|
498
|
+
if (observers.has(notify))
|
|
499
|
+
notify(event);
|
|
500
|
+
});
|
|
390
501
|
});
|
|
391
502
|
return () => {
|
|
392
503
|
observers.delete(notify);
|
|
@@ -403,12 +514,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
403
514
|
return resolveScript(scripts.authorize, () => ({}), undefined);
|
|
404
515
|
},
|
|
405
516
|
async discover(_authorization) {
|
|
406
|
-
return
|
|
407
|
-
if (answer.kind === 'discovery')
|
|
408
|
-
for (const room of answer.rooms)
|
|
409
|
-
note(room.locator, room);
|
|
410
|
-
return answer;
|
|
411
|
-
});
|
|
517
|
+
return discovered();
|
|
412
518
|
},
|
|
413
519
|
reached,
|
|
414
520
|
follows(locator, roomVersion, next) {
|
|
@@ -490,18 +596,39 @@ export function createMemoryAdapter(options = {}) {
|
|
|
490
596
|
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
491
597
|
if (room === undefined)
|
|
492
598
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
493
|
-
const blob = room
|
|
599
|
+
const blob = heldBlob(room, request.path);
|
|
494
600
|
return blob === undefined
|
|
495
601
|
? { kind: 'rejected', code: 'file_not_found', fields: {}, retryable: false }
|
|
496
602
|
: { kind: 'binary', body: blob.stream(), mediaType: blob.type };
|
|
497
603
|
}, request);
|
|
498
604
|
},
|
|
499
605
|
async link(_authorization, request) {
|
|
500
|
-
return resolveScript(scripts.link, () =>
|
|
606
|
+
return resolveScript(scripts.link, () => {
|
|
607
|
+
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
608
|
+
if (room === undefined)
|
|
609
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
610
|
+
const blob = heldBlob(room, request.path);
|
|
611
|
+
if (blob === undefined) {
|
|
612
|
+
return { kind: 'rejected', code: 'file_not_found', fields: {}, retryable: false };
|
|
613
|
+
}
|
|
614
|
+
const url = linked.get(blob) ?? URL.createObjectURL(blob);
|
|
615
|
+
linked.set(blob, url);
|
|
616
|
+
return { kind: 'link', url, name: lastName(request.path), mediaType: blob.type };
|
|
617
|
+
}, request);
|
|
618
|
+
},
|
|
619
|
+
async attach(_authorization, request) {
|
|
620
|
+
return resolveScript(scripts.attach, () => {
|
|
621
|
+
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
622
|
+
if (room === undefined)
|
|
623
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
624
|
+
const path = freePath(room, request.name);
|
|
625
|
+
attached.set(`${room.locator}\u0000${path}`, request.blob);
|
|
626
|
+
return { kind: 'attached', path, revision: `attached-${attached.size}` };
|
|
627
|
+
}, request);
|
|
501
628
|
},
|
|
502
629
|
async action(_authorization, request) {
|
|
503
630
|
return resolveScript(scripts.action, () => {
|
|
504
|
-
if (request.name.startsWith('
|
|
631
|
+
if (request.name.startsWith('conversations/'))
|
|
505
632
|
return conversationAction(request);
|
|
506
633
|
return { kind: 'rejected', code: 'unscripted-action', fields: {}, retryable: false };
|
|
507
634
|
}, request).then((answer) => {
|
package/dist/messages.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { AcceptedMessage } from './adapter.js';
|
|
2
|
+
import type { JobMarker } from './job.js';
|
|
2
3
|
import type { Connection } from './tables.js';
|
|
3
4
|
export declare const MESSAGE_TABLES: readonly string[];
|
|
5
|
+
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 substr(asking.text, 1, 512) 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";
|
|
6
|
+
export declare const JOB_MARKERS = "SELECT json_extract(part.value, '$.text') AS said,\n json_extract(message, '$.accepted_at') AS at\n FROM conversation_messages, json_each(message, '$.parts') AS part\n WHERE conversation = ? AND instr(message, '\"marker\":\"job\"') > 0\n AND json_extract(part.value, '$.type') = 'marker'\n AND json_extract(part.value, '$.marker') = 'job'\n ORDER BY position, identity, part.key";
|
|
4
7
|
export type HeldConversation = {
|
|
5
8
|
readonly conversation: string;
|
|
6
9
|
readonly read: string | null | undefined;
|
|
@@ -10,6 +13,25 @@ export type MessageWindow = {
|
|
|
10
13
|
readonly messages: AcceptedMessage[];
|
|
11
14
|
readonly more: boolean;
|
|
12
15
|
};
|
|
16
|
+
export type HeldSource = {
|
|
17
|
+
readonly source: unknown;
|
|
18
|
+
readonly sender: string | null;
|
|
19
|
+
};
|
|
20
|
+
export type HeldRow = {
|
|
21
|
+
readonly conversation: string;
|
|
22
|
+
readonly said: {
|
|
23
|
+
readonly text: string;
|
|
24
|
+
readonly role: string | null;
|
|
25
|
+
readonly at: string | null;
|
|
26
|
+
} | null;
|
|
27
|
+
readonly failure: string | null;
|
|
28
|
+
readonly opened: HeldSource | null;
|
|
29
|
+
readonly asking: (HeldSource & {
|
|
30
|
+
readonly identity: string;
|
|
31
|
+
readonly text: string;
|
|
32
|
+
readonly at: string | null;
|
|
33
|
+
}) | null;
|
|
34
|
+
};
|
|
13
35
|
export type ConversationWrite = {
|
|
14
36
|
readonly conversation: string;
|
|
15
37
|
readonly messages: readonly AcceptedMessage[];
|
|
@@ -18,10 +40,12 @@ export type ConversationWrite = {
|
|
|
18
40
|
readonly partial: boolean;
|
|
19
41
|
};
|
|
20
42
|
};
|
|
21
|
-
export declare function heldConversations(connection: Connection): HeldConversation[];
|
|
43
|
+
export declare function heldConversations(connection: Connection, conversations: readonly string[] | null): HeldConversation[];
|
|
22
44
|
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;
|
|
45
|
+
export declare function messageWindow(connection: Connection, conversation: string, limit: number, before: readonly [string, string] | null, phrase: string | null): MessageWindow;
|
|
46
|
+
export declare function messageCount(connection: Connection, conversation: string, phrase: string | null): number;
|
|
47
|
+
export declare function conversationRows(connection: Connection, conversations: readonly string[]): HeldRow[];
|
|
48
|
+
export declare function jobMarkers(connection: Connection, conversation: string): JobMarker[];
|
|
25
49
|
export declare function turnArrived(connection: Connection, conversation: string, turn: string): boolean;
|
|
26
50
|
export declare function droppedMessages(connection: Connection, conversations: readonly string[]): void;
|
|
27
51
|
export declare function forgottenMessages(connection: Connection): void;
|