@agentshouse/mdruntime 0.1.0-cfcbb238a5fa0 → 0.1.0-cfcfcecad6596
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 +24 -19
- package/dist/acceptance.d.ts +3 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +328 -0
- package/dist/act-lanes.d.ts +30 -0
- package/dist/act-lanes.d.ts.map +1 -0
- package/dist/act-lanes.js +225 -0
- package/dist/actions.d.ts +26 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +341 -0
- package/dist/adapter.d.ts +287 -127
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +6 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +35 -41
- package/dist/{binary.d.ts → attachment.d.ts} +8 -9
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +15 -0
- package/dist/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +347 -0
- package/dist/bootstrap.d.ts +30 -11
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +309 -113
- 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 +12 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +67 -0
- package/dist/change-set.d.ts +13 -16
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +17 -89
- package/dist/change.d.ts +36 -1
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +17 -3
- package/dist/chat-types.d.ts +3 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +11 -0
- package/dist/client.d.ts +51 -27
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +95 -28
- package/dist/collection.d.ts +34 -21
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +58 -286
- package/dist/column.d.ts +5 -0
- package/dist/column.d.ts.map +1 -0
- package/dist/column.js +9 -0
- package/dist/compile.d.ts +19 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +755 -0
- package/dist/connection.d.ts +7 -132
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +113 -3468
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/{chat/context.js → context.js} +2 -5
- package/dist/conversation-live.d.ts +149 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +259 -0
- package/dist/conversation-row.d.ts +40 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +66 -0
- package/dist/conversation.d.ts +90 -51
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +1082 -759
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- package/dist/digest.d.ts +7 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +113 -0
- package/dist/discovery.d.ts +12 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +175 -0
- package/dist/download.d.ts +6 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +42 -0
- package/dist/durability.d.ts +21 -4
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +12 -0
- package/dist/entry.d.ts +29 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +121 -39
- 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 +8 -0
- package/dist/figures.d.ts +49 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +199 -0
- package/dist/file.d.ts +2 -19
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +8 -122
- 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 +25 -11
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +165 -56
- package/dist/house-query.d.ts +24 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +102 -0
- package/dist/identity.d.ts +1 -3
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +1 -7
- package/dist/index.d.ts +49 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -5
- package/dist/install.d.ts +60 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +537 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +290 -0
- package/dist/listing.d.ts +60 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +168 -0
- package/dist/live.d.ts +39 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +223 -0
- package/dist/loaded.d.ts +7 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +46 -0
- package/dist/locks.d.ts +7 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +34 -0
- package/dist/lost.d.ts +5 -0
- package/dist/lost.d.ts.map +1 -0
- package/dist/lost.js +49 -0
- package/dist/media.d.ts +24 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +365 -0
- package/dist/memory.d.ts +22 -8
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +321 -122
- package/dist/messages.d.ts +63 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +169 -0
- package/dist/modal.d.ts +2 -0
- package/dist/modal.d.ts.map +1 -0
- package/dist/modal.js +11 -0
- package/dist/model.d.ts +15 -15
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +11 -22
- package/dist/models.d.ts +10 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +153 -0
- package/dist/name.d.ts +3 -0
- package/dist/name.d.ts.map +1 -0
- package/dist/name.js +118 -0
- package/dist/observation.d.ts +42 -10
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +266 -39
- package/dist/online.d.ts +7 -0
- package/dist/online.d.ts.map +1 -0
- package/dist/online.js +29 -0
- package/dist/opened.d.ts +22 -0
- package/dist/opened.d.ts.map +1 -0
- package/dist/opened.js +107 -0
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +69 -0
- package/dist/outcome.d.ts +71 -10
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +75 -3
- package/dist/overlay.d.ts +24 -11
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +190 -180
- 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 +6 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +36 -0
- package/dist/paths.d.ts +2 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +26 -0
- package/dist/preparation.d.ts +46 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +344 -0
- package/dist/presence.d.ts +58 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +231 -0
- package/dist/queries.d.ts +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +330 -0
- package/dist/query.d.ts +27 -193
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -470
- package/dist/{chat/questions.d.ts → questions.d.ts} +6 -7
- package/dist/questions.d.ts.map +1 -0
- package/dist/{chat/questions.js → questions.js} +14 -8
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +480 -0
- package/dist/reach.d.ts +31 -11
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +444 -112
- package/dist/react.d.ts +22 -5
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +35 -15
- package/dist/{chat/read.d.ts → read.d.ts} +2 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/{chat/read.js → read.js} +4 -0
- package/dist/readiness.d.ts +36 -21
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +20 -18
- package/dist/reads.d.ts +38 -10
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +174 -83
- package/dist/recovery.d.ts +6 -2
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +67 -9
- package/dist/reference-forms.d.ts +4 -0
- package/dist/reference-forms.d.ts.map +1 -0
- package/dist/reference-forms.js +74 -0
- package/dist/refresh.d.ts +18 -15
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +145 -60
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +55 -0
- package/dist/replica.d.ts +45 -33
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +340 -200
- 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 +56 -14
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +424 -127
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +222 -0
- package/dist/room-list.d.ts +10 -0
- package/dist/room-list.d.ts.map +1 -0
- package/dist/room-list.js +45 -0
- package/dist/rows.d.ts +40 -30
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +73 -119
- package/dist/running.d.ts +5 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +10 -0
- package/dist/runtime.d.ts +37 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +44 -48
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +751 -303
- package/dist/saves.d.ts +34 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +463 -0
- package/dist/search.d.ts +12 -82
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +10 -207
- package/dist/seed.d.ts +11 -2
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +89 -5
- package/dist/selector.d.ts +3 -0
- package/dist/selector.d.ts.map +1 -0
- package/dist/selector.js +22 -0
- package/dist/shared.d.ts +6 -7
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +75 -104
- package/dist/shown.d.ts +35 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +326 -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 +28 -0
- package/dist/socket/lanes.d.ts.map +1 -0
- package/dist/socket/lanes.js +103 -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 +41 -0
- package/dist/socket/session.d.ts.map +1 -0
- package/dist/socket/session.js +26 -0
- package/dist/socket.d.ts +68 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +165 -0
- package/dist/source.d.ts +61 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +95 -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/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +40 -0
- package/dist/store/readiness.d.ts +11 -0
- package/dist/store/readiness.d.ts.map +1 -0
- package/dist/store/readiness.js +68 -0
- package/dist/store/records.d.ts +234 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +474 -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/rooms-shown.d.ts +8 -0
- package/dist/store/rooms-shown.d.ts.map +1 -0
- package/dist/store/rooms-shown.js +13 -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 +115 -149
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +166 -716
- package/dist/stored.d.ts +181 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +807 -0
- package/dist/surface.d.ts +94 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +255 -0
- package/dist/sync.d.ts +21 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +557 -0
- package/dist/tables.d.ts +388 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +506 -0
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +128 -0
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/turn.d.ts +5 -3
- package/dist/turn.d.ts.map +1 -1
- package/dist/turn.js +51 -21
- package/dist/validation.d.ts +31 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +144 -0
- package/dist/windows.d.ts +11 -0
- package/dist/windows.d.ts.map +1 -0
- package/dist/windows.js +16 -0
- package/dist/wire.d.ts +113 -10
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +42 -12
- package/package.json +20 -20
- package/AGENTS.md +0 -299
- package/dist/acquisition.d.ts +0 -14
- package/dist/acquisition.d.ts.map +0 -1
- package/dist/acquisition.js +0 -24
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- package/dist/binary.d.ts.map +0 -1
- package/dist/binary.js +0 -8
- 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/input.d.ts +0 -9
- package/dist/chat/input.d.ts.map +0 -1
- package/dist/chat/input.js +0 -99
- 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 -27
- package/dist/chat/list.d.ts.map +0 -1
- package/dist/chat/list.js +0 -63
- package/dist/chat/markdown.d.ts +0 -20
- package/dist/chat/markdown.d.ts.map +0 -1
- package/dist/chat/markdown.js +0 -188
- package/dist/chat/message.d.ts +0 -6
- package/dist/chat/message.d.ts.map +0 -1
- package/dist/chat/message.js +0 -192
- package/dist/chat/messages.d.ts +0 -22
- package/dist/chat/messages.d.ts.map +0 -1
- package/dist/chat/messages.js +0 -155
- package/dist/chat/name.d.ts +0 -6
- package/dist/chat/name.d.ts.map +0 -1
- package/dist/chat/name.js +0 -37
- package/dist/chat/opened.d.ts +0 -11
- package/dist/chat/opened.d.ts.map +0 -1
- package/dist/chat/opened.js +0 -17
- package/dist/chat/overlay.d.ts +0 -31
- package/dist/chat/overlay.d.ts.map +0 -1
- package/dist/chat/overlay.js +0 -97
- package/dist/chat/parts.d.ts +0 -57
- package/dist/chat/parts.d.ts.map +0 -1
- package/dist/chat/parts.js +0 -119
- 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 -63
- package/dist/chat/provider.d.ts.map +0 -1
- package/dist/chat/provider.js +0 -629
- package/dist/chat/question.d.ts +0 -9
- package/dist/chat/question.d.ts.map +0 -1
- package/dist/chat/question.js +0 -80
- package/dist/chat/questions.d.ts.map +0 -1
- package/dist/chat/read.d.ts.map +0 -1
- package/dist/chat/ready.d.ts +0 -34
- package/dist/chat/ready.d.ts.map +0 -1
- package/dist/chat/ready.js +0 -91
- package/dist/chat/style.d.ts +0 -4
- package/dist/chat/style.d.ts.map +0 -1
- package/dist/chat/style.js +0 -302
- package/dist/chat.d.ts +0 -14
- package/dist/chat.d.ts.map +0 -1
- package/dist/chat.js +0 -8
- package/dist/fence.d.ts +0 -6
- package/dist/fence.d.ts.map +0 -1
- package/dist/fence.js +0 -10
- package/dist/log.d.ts +0 -5
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
- package/dist/read-side.d.ts +0 -25
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -642
package/dist/saves.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ChangeBatch, type WrittenBy } from './change.js';
|
|
2
|
+
import type { ConversationFiles } from './conversation.js';
|
|
3
|
+
import { type AttachAnswer, type AttachmentLinkAnswer, type HeldAttachmentAnswer, type HeldShownAnswer } from './outcome.js';
|
|
4
|
+
import { type RoomDraftParts } from './room-draft.js';
|
|
5
|
+
import type { Runtime } from './runtime.js';
|
|
6
|
+
import { type SaveRefusal } from './save.js';
|
|
7
|
+
import type { Store } from './store.js';
|
|
8
|
+
export type SaveResult = {
|
|
9
|
+
outcome: 'saved';
|
|
10
|
+
identifier: string;
|
|
11
|
+
} | ({
|
|
12
|
+
outcome: 'refused';
|
|
13
|
+
} & SaveRefusal);
|
|
14
|
+
export type SavedRoomDraft = {
|
|
15
|
+
readonly path: string;
|
|
16
|
+
readonly revision: string;
|
|
17
|
+
};
|
|
18
|
+
export type SavedParts = {
|
|
19
|
+
readonly path: string;
|
|
20
|
+
readonly parts: RoomDraftParts;
|
|
21
|
+
};
|
|
22
|
+
export type AttachmentSurface = {
|
|
23
|
+
read(room: string, path: string, revision?: string): Promise<HeldAttachmentAnswer>;
|
|
24
|
+
link(room: string, path: string, revision?: string): Promise<AttachmentLinkAnswer>;
|
|
25
|
+
show(room: string, path: string, revision?: string): Promise<HeldShownAnswer>;
|
|
26
|
+
attach(room: string, file: File): Promise<AttachAnswer>;
|
|
27
|
+
part(file: string, part: number): Promise<Uint8Array | null>;
|
|
28
|
+
};
|
|
29
|
+
export declare function saveRoomDrafts(runtime: Runtime, locator: string, named: readonly SavedRoomDraft[], writtenBy: WrittenBy | undefined): Promise<SaveResult>;
|
|
30
|
+
export declare function saveParts(runtime: Runtime, locator: string, named: readonly SavedParts[], writtenBy: WrittenBy | undefined): Promise<SaveResult>;
|
|
31
|
+
export declare function batchFile(store: Store, batch: ChangeBatch): (localId: string) => Promise<Blob>;
|
|
32
|
+
export declare function conversationFiles(runtime: Runtime): ConversationFiles;
|
|
33
|
+
export declare function attachmentSurface(runtime: Runtime): AttachmentSurface;
|
|
34
|
+
//# sourceMappingURL=saves.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"saves.d.ts","sourceRoot":"","sources":["../src/saves.ts"],"names":[],"mappings":"AAUA,OAAO,EAA2B,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAKxF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAI3D,OAAO,EASL,KAAK,YAAY,EACjB,KAAK,oBAAoB,EAGzB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACrB,MAAM,cAAc,CAAC;AAatB,OAAO,EAQL,KAAK,cAAc,EAGpB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAGL,KAAK,WAAW,EAGjB,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAsB,KAAK,EAAoB,MAAM,YAAY,CAAC;AAK9E,MAAM,MAAM,UAAU,GAClB;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACxC,CAAC;IAAE,OAAO,EAAE,SAAS,CAAA;CAAE,GAAG,WAAW,CAAC,CAAC;AAE3C,MAAM,MAAM,cAAc,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAElF,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAA;CAAE,CAAC;AAEnF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACnF,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACnF,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAC9E,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACxD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;CAC9D,CAAC;AAYF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,SAAS,cAAc,EAAE,EAChC,SAAS,EAAE,SAAS,GAAG,SAAS,GAC/B,OAAO,CAAC,UAAU,CAAC,CAsCrB;AAuBD,wBAAgB,SAAS,CACvB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,SAAS,EAAE,SAAS,GAAG,SAAS,GAC/B,OAAO,CAAC,UAAU,CAAC,CAyBrB;AAuOD,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAK9F;AA+RD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,iBAAiB,CAKrE;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,iBAAiB,CAQrE"}
|
package/dist/saves.js
ADDED
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
import { isImageType, parse } from '@agentshouse/mdmodel';
|
|
2
|
+
import { attachmentRecord } from './attachment.js';
|
|
3
|
+
import { changeSet } from './change-set.js';
|
|
4
|
+
import { queuedFile } from './change.js';
|
|
5
|
+
import { available, definitionsAt, typeAt } from './collection.js';
|
|
6
|
+
import { runtimeError } from './failure.js';
|
|
7
|
+
import { attachedFile } from './file.js';
|
|
8
|
+
import { roomDraftRevision } from './identity.js';
|
|
9
|
+
import { compositionFor } from './listing.js';
|
|
10
|
+
import { scoped } from './models.js';
|
|
11
|
+
import { absentAttachment, attachAnswer, attachmentAnswer, attachmentLinkAnswer, failure, linkedAnswer, OFFLINE, UNCERTAIN, } from './outcome.js';
|
|
12
|
+
import { sameAttachment } from './overlay.js';
|
|
13
|
+
import { ancestors } from './paths.js';
|
|
14
|
+
import { connectionNow } from './preparation.js';
|
|
15
|
+
import { append, sliceAt, withdrawable } from './queue.js';
|
|
16
|
+
import { entryAt, replaying, slicing, } from './replica.js';
|
|
17
|
+
import { attachmentBase, changesOf, held, heldFile, joinedOver, moveTarget, readSavedParts, } from './room-draft.js';
|
|
18
|
+
import { refuse } from './refusal.js';
|
|
19
|
+
import { visibleOf } from './room-drafts.js';
|
|
20
|
+
import { destination, planSave, } from './save.js';
|
|
21
|
+
import { pendingShown } from './shown.js';
|
|
22
|
+
import { paced, ROW_WEIGHT, stepped } from './turn.js';
|
|
23
|
+
import { validatedNeighbourhood } from './validation.js';
|
|
24
|
+
const FULL = { outcome: 'refused', code: 'durable-write', retryable: true };
|
|
25
|
+
async function savedRoom({ store, presence }, locator) {
|
|
26
|
+
const replica = await store.replica(locator);
|
|
27
|
+
if (replica === undefined || presence.lost(locator)) {
|
|
28
|
+
throw runtimeError('unknown-room', `Unknown Room ${locator}`);
|
|
29
|
+
}
|
|
30
|
+
return replica;
|
|
31
|
+
}
|
|
32
|
+
export function saveRoomDrafts(runtime, locator, named, writtenBy) {
|
|
33
|
+
const { store } = runtime;
|
|
34
|
+
return store.exclusive(async () => {
|
|
35
|
+
if (store.space.full())
|
|
36
|
+
return FULL;
|
|
37
|
+
const replica = await savedRoom(runtime, locator);
|
|
38
|
+
const drafts = new Map((await store.drafts(locator, named.map(({ path }) => path))).map((record) => [record.path, record]));
|
|
39
|
+
const saved = [];
|
|
40
|
+
for (const { path, revision } of named) {
|
|
41
|
+
const record = drafts.get(path);
|
|
42
|
+
if (record === undefined || record.revision !== revision) {
|
|
43
|
+
return { outcome: 'refused', code: 'stale', retryable: false, file: path };
|
|
44
|
+
}
|
|
45
|
+
if (!saved.some((draft) => draft.path === path))
|
|
46
|
+
saved.push({ path, parts: record.parts });
|
|
47
|
+
}
|
|
48
|
+
const result = await loaded(runtime, locator, replica, saved, new Set(saved.map(({ path }) => path)), [], writtenBy);
|
|
49
|
+
if (result.outcome !== 'refused' || result.code !== 'changed-underneath')
|
|
50
|
+
return result;
|
|
51
|
+
return joinedUnderneath(runtime, locator, saved.map(({ path }) => drafts.get(path)), result);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async function joinedUnderneath({ store }, locator, records, refused) {
|
|
55
|
+
const visible = (await visibleOf(store, locator, records.map(({ path }) => path)));
|
|
56
|
+
const joined = records.flatMap((record) => {
|
|
57
|
+
const join = joinedOver(record.parts, record.marks, record.path, visible);
|
|
58
|
+
return join === null ? [] : [{ ...record, ...join, revision: roomDraftRevision() }];
|
|
59
|
+
});
|
|
60
|
+
if (joined.length === 0)
|
|
61
|
+
return refused;
|
|
62
|
+
await (await store.open()).commit({ rooms: [], writes: [{ locator, roomDrafts: joined }] });
|
|
63
|
+
await store.changed(changeSet(locator, { drafts: joined.map(({ path }) => path) }));
|
|
64
|
+
return refused;
|
|
65
|
+
}
|
|
66
|
+
export function saveParts(runtime, locator, named, writtenBy) {
|
|
67
|
+
const { store } = runtime;
|
|
68
|
+
return store.exclusive(async () => {
|
|
69
|
+
const read = readSavedParts(named);
|
|
70
|
+
if (store.space.full())
|
|
71
|
+
return FULL;
|
|
72
|
+
const replica = await savedRoom(runtime, locator);
|
|
73
|
+
const saved = [];
|
|
74
|
+
const files = [];
|
|
75
|
+
const filed = read.filter(({ parts }) => parts.file !== undefined).map(({ path }) => path);
|
|
76
|
+
const visible = filed.length === 0 ? undefined : await visibleOf(store, locator, filed);
|
|
77
|
+
for (const { path, parts } of read) {
|
|
78
|
+
const file = parts.file === undefined
|
|
79
|
+
? undefined
|
|
80
|
+
: await heldFile(parts.file.blob, parts.file.base === undefined ? attachmentBase(visible, path) : parts.file.base);
|
|
81
|
+
if (parts.file !== undefined && file !== undefined) {
|
|
82
|
+
files.push({ key: file.localId, blob: parts.file.blob });
|
|
83
|
+
}
|
|
84
|
+
saved.push({ path, parts: held(undefined, parts, file) });
|
|
85
|
+
}
|
|
86
|
+
return loaded(runtime, locator, replica, saved, new Set(), files, writtenBy);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async function unmodeledIn(runtime, record) {
|
|
90
|
+
const composition = compositionFor(runtime, record);
|
|
91
|
+
if (available(composition))
|
|
92
|
+
return false;
|
|
93
|
+
const local = await runtime.store.open();
|
|
94
|
+
const roots = record.declaration.typedSelection?.roots ?? [];
|
|
95
|
+
return local.typedWithin(record.key, 'visible', roots, false);
|
|
96
|
+
}
|
|
97
|
+
async function savingRoom(runtime, replica, changes, extra, drafted) {
|
|
98
|
+
const { store } = runtime;
|
|
99
|
+
const { record, queue, states } = replica;
|
|
100
|
+
const local = await store.open();
|
|
101
|
+
const paths = [
|
|
102
|
+
...extra,
|
|
103
|
+
...changes.flatMap((change) => change.kind === 'move' ? [change.path, change.to] : [change.path]),
|
|
104
|
+
];
|
|
105
|
+
const moved = changes.flatMap((change) => (change.kind === 'move' ? [change.path] : []));
|
|
106
|
+
const removed = changes.flatMap((change) => (change.kind === 'remove' ? [change.path] : []));
|
|
107
|
+
const referring = removed.length === 0
|
|
108
|
+
? []
|
|
109
|
+
: (await local.referrers(record.key, 'confirmed', removed)).map(({ path }) => path);
|
|
110
|
+
const confirmed = await sliceAt(store, record, 'confirmed', queue, [...paths, ...paths.flatMap(ancestors), ...referring], moved);
|
|
111
|
+
const composition = store.composed(record);
|
|
112
|
+
const changeable = withdrawable(states);
|
|
113
|
+
return {
|
|
114
|
+
held: { replica, confirmed },
|
|
115
|
+
room: {
|
|
116
|
+
record,
|
|
117
|
+
rule: runtime.writeRule(record.declaration),
|
|
118
|
+
composition: compositionFor(runtime, record),
|
|
119
|
+
queue,
|
|
120
|
+
changeable: new Set(queue.filter(changeable).map(({ id }) => id)),
|
|
121
|
+
saved: new Map([...states].map(([id, state]) => [id, state.drafts])),
|
|
122
|
+
*replay(over) {
|
|
123
|
+
return (yield* replaying(confirmed, over, record.locator, composition)).visible;
|
|
124
|
+
},
|
|
125
|
+
folders: new Set(await local.folders(record.key, paths)),
|
|
126
|
+
modelled: !(await unmodeledIn(runtime, record)),
|
|
127
|
+
drafts: new Map(drafted.length === 0
|
|
128
|
+
? []
|
|
129
|
+
: (await store.drafts(record.locator, drafted)).map((held) => [held.path, held])),
|
|
130
|
+
validate: validatorOf(runtime, record, confirmed),
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function targetsOf(saved) {
|
|
135
|
+
return saved.flatMap(({ parts }) => (parts.move === undefined ? [] : [moveTarget(parts.move)]));
|
|
136
|
+
}
|
|
137
|
+
async function loaded(runtime, locator, replica, saved, consumed, files, writtenBy) {
|
|
138
|
+
const { store, localSaves } = runtime;
|
|
139
|
+
const into = destination(locator, saved);
|
|
140
|
+
const target = into === null ? undefined : await savedRoom(runtime, into);
|
|
141
|
+
const paths = saved.map(({ path }) => path);
|
|
142
|
+
const targets = targetsOf(saved);
|
|
143
|
+
const parts = saved.map(({ path, parts: held }) => changesOf(path, held));
|
|
144
|
+
const source = target === undefined
|
|
145
|
+
? await savingRoom(runtime, replica, parts.flatMap(({ changes }) => changes), [...paths, ...parts.flatMap(({ bases }) => bases.map(({ path }) => path))], targets.length === 0 ? [] : [...paths, ...targets])
|
|
146
|
+
: await savingRoom(runtime, replica, paths.map((path) => ({ kind: 'remove', path })), paths, paths);
|
|
147
|
+
const arriving = target === undefined ? undefined : await savingRoom(runtime, target, [], targets, targets);
|
|
148
|
+
const { providerLimits } = await (await store.open()).facts();
|
|
149
|
+
const plan = await planSave({ saved, consumed, writtenBy, local: localSaves, providerLimits }, source.room, arriving?.room);
|
|
150
|
+
return append(runtime, {
|
|
151
|
+
plan,
|
|
152
|
+
files,
|
|
153
|
+
held: new Map([source, ...(arriving === undefined ? [] : [arriving])].map(({ room, held }) => [
|
|
154
|
+
room.record.locator,
|
|
155
|
+
held,
|
|
156
|
+
])),
|
|
157
|
+
after: () => pendingShown(runtime),
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
function textDiffers(left, right) {
|
|
161
|
+
return ((left?.content ?? undefined) !== (right?.content ?? undefined) ||
|
|
162
|
+
!sameAttachment(left?.binary ?? undefined, right?.binary ?? undefined));
|
|
163
|
+
}
|
|
164
|
+
function textOf(entry) {
|
|
165
|
+
if (entry === null)
|
|
166
|
+
return undefined;
|
|
167
|
+
return entry.binary !== null ? null : entry.content;
|
|
168
|
+
}
|
|
169
|
+
function lookupOf(local, key, view) {
|
|
170
|
+
return async (paths) => {
|
|
171
|
+
if (paths.length === 0)
|
|
172
|
+
return new Map();
|
|
173
|
+
return new Map((await local.typed(key, view, paths)).map(({ path, type, binary }) => [
|
|
174
|
+
path,
|
|
175
|
+
{ type: type ?? undefined, binary },
|
|
176
|
+
]));
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function declaredOf(composition, path, entry) {
|
|
180
|
+
if (entry.binary !== null)
|
|
181
|
+
return { type: undefined, binary: true };
|
|
182
|
+
const content = entry.content ?? '';
|
|
183
|
+
return {
|
|
184
|
+
type: typeAt(composition, path, parse(content, path, definitionsAt(composition, path))),
|
|
185
|
+
binary: false,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function overriddenLookup(composition, lookup, overrides) {
|
|
189
|
+
return async (paths) => {
|
|
190
|
+
const known = new Map(await lookup(paths.filter((path) => !overrides.has(path))));
|
|
191
|
+
for (const path of paths) {
|
|
192
|
+
const entry = overrides.get(path);
|
|
193
|
+
if (entry === undefined)
|
|
194
|
+
continue;
|
|
195
|
+
if (entry === null)
|
|
196
|
+
known.delete(path);
|
|
197
|
+
else
|
|
198
|
+
known.set(path, declaredOf(composition, path, entry));
|
|
199
|
+
}
|
|
200
|
+
return known;
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function validatorOf(runtime, record, confirmedLayer) {
|
|
204
|
+
return async (resulting, touched) => {
|
|
205
|
+
const local = await runtime.store.open();
|
|
206
|
+
const changes = [];
|
|
207
|
+
const overrides = new Map();
|
|
208
|
+
const pace = paced();
|
|
209
|
+
for (const path of new Set([...confirmedLayer.held, ...touched])) {
|
|
210
|
+
await pace(ROW_WEIGHT);
|
|
211
|
+
const was = entryAt(confirmedLayer, path);
|
|
212
|
+
const now = entryAt(resulting, path);
|
|
213
|
+
if (!textDiffers(was, now))
|
|
214
|
+
continue;
|
|
215
|
+
overrides.set(path, now);
|
|
216
|
+
if (textOf(was) !== textOf(now))
|
|
217
|
+
changes.push({ path, was: textOf(was), now: textOf(now) });
|
|
218
|
+
}
|
|
219
|
+
const composition = compositionFor(runtime, record);
|
|
220
|
+
return validatedNeighbourhood(changes, composition, {
|
|
221
|
+
lookup: overriddenLookup(composition, lookupOf(local, record.key, 'confirmed'), overrides),
|
|
222
|
+
texts: textsOf(local, record.key, 'confirmed'),
|
|
223
|
+
referrers: referrersOf(local, record.key, 'confirmed'),
|
|
224
|
+
holders: (sought) => local.holders(record.key, 'confirmed', sought),
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function textsOf(local, key, view) {
|
|
229
|
+
return async (paths) => new Map((await local.entries(key, view, paths)).map(({ path, content, binary }) => [
|
|
230
|
+
path,
|
|
231
|
+
binary !== null ? null : content,
|
|
232
|
+
]));
|
|
233
|
+
}
|
|
234
|
+
function referrersOf(local, key, view) {
|
|
235
|
+
return async (targets) => [
|
|
236
|
+
...new Set((await local.referrers(key, view, targets)).map(({ path }) => path)),
|
|
237
|
+
];
|
|
238
|
+
}
|
|
239
|
+
async function queuedFacts(store, locator, path, localId) {
|
|
240
|
+
for (const batch of (await store.replica(locator))?.queue ?? []) {
|
|
241
|
+
const change = batch.changes[queuedFile(batch, path, localId)];
|
|
242
|
+
if (change?.kind === 'binary')
|
|
243
|
+
return change;
|
|
244
|
+
}
|
|
245
|
+
const drafted = (await store.draft(locator, path))?.parts.file;
|
|
246
|
+
return drafted?.localId === localId ? drafted : null;
|
|
247
|
+
}
|
|
248
|
+
export function batchFile(store, batch) {
|
|
249
|
+
return async (localId) => {
|
|
250
|
+
const change = batch.changes.find((held) => held.kind === 'binary' && held.localId === localId);
|
|
251
|
+
return (await store.open()).file(localId, change?.kind === 'binary' ? change.mediaType : '');
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
async function transferAttachment(runtime, request, transfer, answer) {
|
|
255
|
+
const { store, socket, presence } = runtime;
|
|
256
|
+
const { session } = socket;
|
|
257
|
+
if (socket.closed() || session.now().refusal !== null)
|
|
258
|
+
return UNCERTAIN;
|
|
259
|
+
await socket.firstDiscovery;
|
|
260
|
+
if (!session.now().roomsNamed)
|
|
261
|
+
return UNCERTAIN;
|
|
262
|
+
try {
|
|
263
|
+
await socket.authorize();
|
|
264
|
+
}
|
|
265
|
+
catch {
|
|
266
|
+
return UNCERTAIN;
|
|
267
|
+
}
|
|
268
|
+
const { closed, authorization, refusal } = session.now();
|
|
269
|
+
if (closed || authorization === undefined || refusal !== null)
|
|
270
|
+
return UNCERTAIN;
|
|
271
|
+
const since = presence.losses();
|
|
272
|
+
try {
|
|
273
|
+
const result = await transfer(authorization);
|
|
274
|
+
const settled = result;
|
|
275
|
+
if (request.locator !== null && presence.lostSince(request.locator, since))
|
|
276
|
+
return failure({ kind: 'room-not-readable', locator: request.locator });
|
|
277
|
+
if (settled.kind === 'scoped-refusal') {
|
|
278
|
+
const room = await store.record(settled.locator);
|
|
279
|
+
if (room !== undefined)
|
|
280
|
+
await scoped(runtime, settled, room.locator, room.declaration);
|
|
281
|
+
}
|
|
282
|
+
if (settled.kind === 'revoked-authorization')
|
|
283
|
+
await refuse(runtime, 'revoked-authorization');
|
|
284
|
+
return answer(result);
|
|
285
|
+
}
|
|
286
|
+
catch {
|
|
287
|
+
return UNCERTAIN;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
function fetchAttachment(runtime, request, name) {
|
|
291
|
+
const { store, socket } = runtime;
|
|
292
|
+
return transferAttachment(runtime, request, (authorization) => store.opened.fetch(name, () => socket.binary(authorization, request)), attachmentAnswer);
|
|
293
|
+
}
|
|
294
|
+
async function readAttachment(runtime, request, name) {
|
|
295
|
+
if (runtime.socket.closed())
|
|
296
|
+
return UNCERTAIN;
|
|
297
|
+
const held = await runtime.store.opened.find(name);
|
|
298
|
+
if (held !== null)
|
|
299
|
+
return held;
|
|
300
|
+
return fetchAttachment(runtime, request, name);
|
|
301
|
+
}
|
|
302
|
+
async function attachmentPath(store, locator, path, revision) {
|
|
303
|
+
if (revision !== undefined)
|
|
304
|
+
return { kind: 'path', locator, path, revision };
|
|
305
|
+
const replica = await store.replica(locator);
|
|
306
|
+
const local = await store.open();
|
|
307
|
+
const [held] = replica === undefined ? [] : await local.entries(replica.record.key, 'visible', [path]);
|
|
308
|
+
const attached = held === undefined ? store.attached.of(locator, path) : undefined;
|
|
309
|
+
if (attached !== undefined)
|
|
310
|
+
return { kind: 'path', locator, path, revision: attached.revision };
|
|
311
|
+
if (replica === undefined || held?.binary === undefined || held.binary === null)
|
|
312
|
+
return null;
|
|
313
|
+
if (held.binary.state === 'pending')
|
|
314
|
+
return { kind: 'pending', localId: held.binary.localId };
|
|
315
|
+
const record = attachmentRecord(path, held.binary, held.revision ?? undefined);
|
|
316
|
+
if (record.state !== 'accepted')
|
|
317
|
+
return null;
|
|
318
|
+
const queued = replica.queue.flatMap((batch) => batch.changes);
|
|
319
|
+
const sources = queued.flatMap((change) => (change.kind === 'move' ? [change.path] : []));
|
|
320
|
+
const confirmedLayer = await stepped(slicing(await local.entries(replica.record.key, 'confirmed', [path, ...sources]), [
|
|
321
|
+
path,
|
|
322
|
+
...sources,
|
|
323
|
+
]));
|
|
324
|
+
const holds = (at) => {
|
|
325
|
+
const kept = confirmedLayer.binaries[at];
|
|
326
|
+
return (kept?.state === 'accepted' &&
|
|
327
|
+
kept.sha256 === record.sha256 &&
|
|
328
|
+
confirmedLayer.revisions[at] === record.revision);
|
|
329
|
+
};
|
|
330
|
+
let confirmedAt = path;
|
|
331
|
+
for (let index = queued.length - 1; index >= 0 && !holds(confirmedAt); index -= 1) {
|
|
332
|
+
const change = queued[index];
|
|
333
|
+
if (change.kind === 'move' && change.to === confirmedAt)
|
|
334
|
+
confirmedAt = change.path;
|
|
335
|
+
}
|
|
336
|
+
return {
|
|
337
|
+
kind: 'path',
|
|
338
|
+
locator,
|
|
339
|
+
path: confirmedAt,
|
|
340
|
+
revision: record.revision,
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
async function askedAttachment({ store, socket }, locator, path, revision) {
|
|
344
|
+
await socket.ready;
|
|
345
|
+
const drafted = (await store.draft(locator, path))?.parts.file;
|
|
346
|
+
return drafted !== undefined && drafted.localId === revision
|
|
347
|
+
? { kind: 'pending', localId: revision }
|
|
348
|
+
: attachmentPath(store, locator, path, revision);
|
|
349
|
+
}
|
|
350
|
+
async function pendingAttachment(store, locator, path, localId) {
|
|
351
|
+
const facts = await queuedFacts(store, locator, path, localId);
|
|
352
|
+
return facts === null
|
|
353
|
+
? absentAttachment(path)
|
|
354
|
+
: {
|
|
355
|
+
kind: 'binary',
|
|
356
|
+
file: localId,
|
|
357
|
+
byteLength: facts.byteLength,
|
|
358
|
+
mediaType: facts.mediaType,
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
async function readAttachmentPath(runtime, locator, path, revision) {
|
|
362
|
+
const asked = await askedAttachment(runtime, locator, path, revision);
|
|
363
|
+
if (asked === null)
|
|
364
|
+
return absentAttachment(path);
|
|
365
|
+
if (asked.kind === 'pending')
|
|
366
|
+
return pendingAttachment(runtime.store, locator, path, asked.localId);
|
|
367
|
+
return readAttachment(runtime, asked, { locator, path: asked.path, revision: asked.revision });
|
|
368
|
+
}
|
|
369
|
+
async function heldMediaType(store, locator, path) {
|
|
370
|
+
const replica = await store.record(locator);
|
|
371
|
+
const [held] = replica === undefined ? [] : await (await store.open()).entries(replica.key, 'visible', [path]);
|
|
372
|
+
return held === undefined ? store.attached.of(locator, path)?.mediaType : held.binary?.mediaType;
|
|
373
|
+
}
|
|
374
|
+
function linkOf(runtime, asked, held) {
|
|
375
|
+
return transferAttachment(runtime, asked, (authorization) => runtime.socket.link(authorization, asked), (result) => attachmentLinkAnswer(result, held));
|
|
376
|
+
}
|
|
377
|
+
async function linkAttachmentPath(runtime, locator, path, revision) {
|
|
378
|
+
const { store, socket } = runtime;
|
|
379
|
+
await socket.ready;
|
|
380
|
+
const asked = await attachmentPath(store, locator, path, revision);
|
|
381
|
+
if (asked === null || asked.kind === 'pending')
|
|
382
|
+
return absentAttachment(path);
|
|
383
|
+
return linkOf(runtime, asked, revision === undefined ? await heldMediaType(store, locator, path) : undefined);
|
|
384
|
+
}
|
|
385
|
+
function shownImage(runtime, asked, name) {
|
|
386
|
+
const { store, socket } = runtime;
|
|
387
|
+
return new Promise((answer) => {
|
|
388
|
+
void transferAttachment(runtime, asked, (authorization) => store.opened.fetch(name, async () => {
|
|
389
|
+
const read = await socket.binary(authorization, asked);
|
|
390
|
+
const copies = read.kind === 'binary' ? (read.copies ?? []) : [];
|
|
391
|
+
if (read.kind === 'binary' && read.url !== undefined && copies.length > 0) {
|
|
392
|
+
answer({
|
|
393
|
+
kind: 'link',
|
|
394
|
+
url: read.url,
|
|
395
|
+
name: asked.path.slice(asked.path.lastIndexOf('/') + 1),
|
|
396
|
+
mediaType: read.mediaType,
|
|
397
|
+
copies,
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
return read;
|
|
401
|
+
}), attachmentAnswer).then(answer);
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
async function showAttachmentPath(runtime, locator, path, revision) {
|
|
405
|
+
const { store } = runtime;
|
|
406
|
+
const asked = await askedAttachment(runtime, locator, path, revision);
|
|
407
|
+
if (asked === null)
|
|
408
|
+
return absentAttachment(path);
|
|
409
|
+
if (asked.kind === 'pending')
|
|
410
|
+
return pendingAttachment(store, locator, path, asked.localId);
|
|
411
|
+
if (runtime.socket.closed())
|
|
412
|
+
return UNCERTAIN;
|
|
413
|
+
const name = { locator, path: asked.path, revision: asked.revision };
|
|
414
|
+
const kept = await store.opened.find(name);
|
|
415
|
+
if (kept !== null)
|
|
416
|
+
return kept;
|
|
417
|
+
const mediaType = await heldMediaType(store, locator, path);
|
|
418
|
+
if (mediaType !== undefined && isImageType(mediaType))
|
|
419
|
+
return shownImage(runtime, asked, name);
|
|
420
|
+
const linked = await linkOf(runtime, asked, revision === undefined ? mediaType : undefined);
|
|
421
|
+
return linked.kind === 'link' ? { ...linked, copies: [] } : linked;
|
|
422
|
+
}
|
|
423
|
+
async function attachFile(runtime, locator, file, answer) {
|
|
424
|
+
const { store, socket } = runtime;
|
|
425
|
+
await socket.ready;
|
|
426
|
+
await socket.firstDiscovery;
|
|
427
|
+
if (socket.closed() ||
|
|
428
|
+
!socket.session.now().roomsNamed ||
|
|
429
|
+
(await connectionNow(runtime)) === 'unreachable' ||
|
|
430
|
+
socket.session.now().refusal !== null)
|
|
431
|
+
return OFFLINE;
|
|
432
|
+
const request = await attachedFile(locator, file);
|
|
433
|
+
return transferAttachment(runtime, { locator }, async (held) => {
|
|
434
|
+
const result = await socket.attach(held, request);
|
|
435
|
+
if (result.kind === 'attached' && locator !== null) {
|
|
436
|
+
store.attached.hold(locator, result.path, {
|
|
437
|
+
revision: result.revision,
|
|
438
|
+
mediaType: request.mediaType,
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
return result;
|
|
442
|
+
}, answer);
|
|
443
|
+
}
|
|
444
|
+
async function keyedAttachment(runtime, link) {
|
|
445
|
+
await runtime.socket.ready;
|
|
446
|
+
const asked = { kind: 'key', link };
|
|
447
|
+
return transferAttachment(runtime, { locator: null }, (authorization) => runtime.socket.link(authorization, asked), (result) => attachmentLinkAnswer(result));
|
|
448
|
+
}
|
|
449
|
+
export function conversationFiles(runtime) {
|
|
450
|
+
return {
|
|
451
|
+
attach: (file) => attachFile(runtime, null, file, linkedAnswer),
|
|
452
|
+
attachment: (link) => keyedAttachment(runtime, link),
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
export function attachmentSurface(runtime) {
|
|
456
|
+
return {
|
|
457
|
+
part: runtime.store.part,
|
|
458
|
+
read: (room, path, revision) => readAttachmentPath(runtime, room, path, revision),
|
|
459
|
+
link: (room, path, revision) => linkAttachmentPath(runtime, room, path, revision),
|
|
460
|
+
show: (room, path, revision) => showAttachmentPath(runtime, room, path, revision),
|
|
461
|
+
attach: (room, file) => attachFile(runtime, room, file, attachAnswer),
|
|
462
|
+
};
|
|
463
|
+
}
|
package/dist/search.d.ts
CHANGED
|
@@ -1,92 +1,22 @@
|
|
|
1
|
-
import type { ProviderRefusal } from './adapter.js';
|
|
2
|
-
import type {
|
|
3
|
-
import { type CoveredRoom, type Filter, type PendingRoom } from './query.js';
|
|
4
|
-
import type { Open } from './open.js';
|
|
5
|
-
export type DocumentPart = Open<'fields' | 'sections' | 'preamble' | 'path'>;
|
|
1
|
+
import type { ProviderRefusal, SearchHit } from './adapter.js';
|
|
2
|
+
import type { Failure, Offline } from './outcome.js';
|
|
6
3
|
export type SearchRequest = {
|
|
7
4
|
text: string;
|
|
8
|
-
|
|
9
|
-
collection?: true;
|
|
10
|
-
conversations?: readonly string[];
|
|
11
|
-
limit?: number;
|
|
5
|
+
rooms?: readonly string[];
|
|
12
6
|
};
|
|
13
|
-
export type
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
score: number;
|
|
18
|
-
matches: Readonly<Record<string, readonly DocumentPart[]>>;
|
|
7
|
+
export type { SearchHit } from './adapter.js';
|
|
8
|
+
export type SearchFound = {
|
|
9
|
+
kind: 'found';
|
|
10
|
+
documents: readonly SearchHit[];
|
|
19
11
|
};
|
|
20
|
-
export type
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
score: number;
|
|
24
|
-
matches: Readonly<Record<string, readonly Open<'text'>[]>>;
|
|
25
|
-
};
|
|
26
|
-
export type SearchCoverage = {
|
|
27
|
-
rooms: readonly CoveredRoom[];
|
|
28
|
-
conversations: readonly string[];
|
|
29
|
-
index: string;
|
|
30
|
-
overlay: readonly string[];
|
|
31
|
-
};
|
|
32
|
-
export type PendingConversation = {
|
|
33
|
-
conversation: string;
|
|
34
|
-
awaits: Open<'index'>;
|
|
35
|
-
};
|
|
36
|
-
export type SearchHits = {
|
|
37
|
-
documents: readonly DocumentHit[];
|
|
38
|
-
messages: readonly MessageHit[];
|
|
39
|
-
};
|
|
40
|
-
export type SearchPending = SearchHits & {
|
|
41
|
-
pending: readonly (PendingRoom | PendingConversation)[];
|
|
42
|
-
coverage: SearchCoverage;
|
|
43
|
-
};
|
|
44
|
-
export type SearchUndeclared = ProviderRefusal & {
|
|
12
|
+
export type SearchResult = SearchFound | Offline | (ProviderRefusal & {
|
|
13
|
+
kind: 'rejected';
|
|
14
|
+
}) | (ProviderRefusal & {
|
|
45
15
|
kind: 'undeclared';
|
|
46
|
-
};
|
|
47
|
-
export type SearchResult = (SearchHits & {
|
|
48
|
-
coverage: SearchCoverage;
|
|
49
|
-
}) | SearchPending | SearchUndeclared;
|
|
50
|
-
export declare function undeclaredSearch(): SearchUndeclared;
|
|
51
|
-
export type SearchedDocument = {
|
|
52
|
-
room: string;
|
|
53
|
-
path: string;
|
|
54
|
-
type: string;
|
|
55
|
-
fields: Readonly<Record<string, unknown>>;
|
|
56
|
-
preamble: string;
|
|
57
|
-
sections: Readonly<Record<string, string>>;
|
|
58
|
-
};
|
|
59
|
-
export type SearchedMessage = {
|
|
60
|
-
conversation: string;
|
|
61
|
-
identity: string;
|
|
62
|
-
text: string;
|
|
63
|
-
};
|
|
64
|
-
export type SearchSource = {
|
|
65
|
-
room(room: string): readonly string[];
|
|
66
|
-
document(room: string, path: string): SearchedDocument | null;
|
|
67
|
-
};
|
|
16
|
+
}) | Failure;
|
|
68
17
|
export type SearchPlan = {
|
|
69
18
|
text: string;
|
|
70
|
-
|
|
71
|
-
collection: boolean;
|
|
72
|
-
conversations: readonly string[] | null;
|
|
73
|
-
limit: number | null;
|
|
74
|
-
};
|
|
75
|
-
export type SearchIndex = {
|
|
76
|
-
generation(): string;
|
|
77
|
-
rooms(): ReadonlySet<string>;
|
|
78
|
-
conversations(): ReadonlySet<string>;
|
|
79
|
-
indexRoom(room: string): Promise<void>;
|
|
80
|
-
indexMessages(conversation: string, messages: readonly SearchedMessage[], whole: boolean): void;
|
|
81
|
-
forget(rooms: readonly string[]): void;
|
|
82
|
-
changed(set: ChangeSet): void;
|
|
83
|
-
changes(): number;
|
|
84
|
-
caughtUp(): Promise<void>;
|
|
85
|
-
search(plan: SearchPlan, documents: readonly {
|
|
86
|
-
room: string;
|
|
87
|
-
path: string;
|
|
88
|
-
}[] | null, conversations: readonly string[], rooms: ReadonlySet<string> | null, selections: ReadonlyMap<string, readonly string[]> | null): SearchHits;
|
|
19
|
+
rooms: readonly string[] | null;
|
|
89
20
|
};
|
|
90
21
|
export declare function searchPlanOf(input: unknown): SearchPlan;
|
|
91
|
-
export declare function createSearchIndex(source: SearchSource): SearchIndex;
|
|
92
22
|
//# sourceMappingURL=search.d.ts.map
|
package/dist/search.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAErD,MAAM,MAAM,aAAa,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAExE,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,MAAM,WAAW,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,SAAS,SAAS,EAAE,CAAA;CAAE,CAAC;AAE7E,MAAM,MAAM,YAAY,GACpB,WAAW,GACX,OAAO,GACP,CAAC,eAAe,GAAG;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,GACxC,CAAC,eAAe,GAAG;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,CAAC,GAC1C,OAAO,CAAC;AAEZ,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAA;CAAE,CAAC;AAE3E,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAYvD"}
|