@agentshouse/mdruntime 0.1.0-c91a238f9703e → 0.1.0-c9260f23cccf4
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 +18 -15
- package/dist/adapter.d.ts +72 -37
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +5 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +38 -4
- package/dist/binary.d.ts +0 -5
- package/dist/binary.d.ts.map +1 -1
- package/dist/binary.js +1 -1
- package/dist/bootstrap.d.ts +26 -8
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +174 -102
- package/dist/chain.d.ts +11 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +68 -0
- package/dist/change-set.d.ts +9 -16
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +11 -89
- package/dist/change.d.ts +31 -1
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +10 -1
- package/dist/client.d.ts +9 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +80 -6
- package/dist/collection.d.ts +11 -19
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +53 -289
- package/dist/compile.d.ts +16 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +773 -0
- package/dist/connection.d.ts +18 -12
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +2729 -1085
- package/dist/conversation.d.ts +14 -6
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +263 -94
- package/dist/digest.d.ts +7 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +113 -0
- package/dist/durability.d.ts +3 -5
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +5 -0
- package/dist/entry.d.ts +4 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +18 -23
- package/dist/file.d.ts +2 -19
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +7 -122
- package/dist/fulltext.d.ts +27 -0
- package/dist/fulltext.d.ts.map +1 -0
- package/dist/fulltext.js +370 -0
- package/dist/host.d.ts +4 -7
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +45 -18
- 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 +12 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/live.d.ts +22 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +124 -0
- package/dist/media.d.ts +8 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +208 -0
- package/dist/memory.d.ts +4 -4
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +67 -29
- package/dist/messages.d.ts +28 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +90 -0
- package/dist/model.d.ts +6 -0
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +7 -1
- package/dist/name.d.ts +4 -0
- package/dist/name.d.ts.map +1 -0
- package/dist/name.js +122 -0
- package/dist/observation.d.ts +13 -0
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +84 -0
- package/dist/opened.d.ts +22 -0
- package/dist/opened.d.ts.map +1 -0
- package/dist/opened.js +107 -0
- package/dist/outcome.d.ts +40 -5
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +38 -2
- package/dist/overlay.d.ts +2 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +87 -172
- 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 +11 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +13 -1
- package/dist/reach.d.ts +13 -4
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +201 -72
- package/dist/readiness.d.ts +19 -9
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +6 -6
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +10 -17
- package/dist/recovery.d.ts +2 -2
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +8 -7
- package/dist/refresh.d.ts +15 -14
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +113 -56
- package/dist/replica.d.ts +55 -36
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +280 -186
- package/dist/room-draft.d.ts +21 -3
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +102 -28
- package/dist/rows.d.ts +38 -31
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +173 -101
- package/dist/save.d.ts +52 -14
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +513 -185
- package/dist/search.d.ts +11 -43
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +0 -213
- package/dist/shared.d.ts +8 -3
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +129 -66
- package/dist/status.d.ts +5 -0
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -1
- package/dist/store.d.ts +85 -93
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +323 -687
- package/dist/stored.d.ts +135 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +569 -0
- package/dist/tables.d.ts +352 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +621 -0
- 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 +30 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +162 -0
- package/dist/windows.d.ts +2 -6
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +30 -34
- package/dist/wire.d.ts +17 -1
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +5 -1
- package/dist/words.d.ts +19 -0
- package/dist/words.d.ts.map +1 -0
- package/dist/words.js +156 -0
- package/package.json +18 -19
- package/AGENTS.md +0 -305
- package/dist/acquisition.d.ts +0 -14
- package/dist/acquisition.d.ts.map +0 -1
- package/dist/acquisition.js +0 -24
- package/dist/chat/acts.d.ts +0 -33
- package/dist/chat/acts.d.ts.map +0 -1
- package/dist/chat/acts.js +0 -36
- package/dist/chat/context.d.ts +0 -3
- package/dist/chat/context.d.ts.map +0 -1
- package/dist/chat/context.js +0 -10
- package/dist/chat/earlier.d.ts +0 -10
- package/dist/chat/earlier.d.ts.map +0 -1
- package/dist/chat/earlier.js +0 -54
- package/dist/chat/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 -99
- 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 -628
- package/dist/chat/question.d.ts +0 -9
- package/dist/chat/question.d.ts.map +0 -1
- package/dist/chat/question.js +0 -69
- package/dist/chat/questions.d.ts +0 -31
- package/dist/chat/questions.d.ts.map +0 -1
- package/dist/chat/questions.js +0 -111
- package/dist/chat/read.d.ts +0 -5
- package/dist/chat/read.d.ts.map +0 -1
- package/dist/chat/read.js +0 -13
- package/dist/chat/ready.d.ts +0 -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/read-side.d.ts +0 -25
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -767
package/dist/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export { departure } from './change.js';
|
|
2
|
-
export { partsAfter } from './room-draft.js';
|
|
3
|
-
export {
|
|
2
|
+
export { partsAfter, partsChanges } from './room-draft.js';
|
|
3
|
+
export { cutName, nameFrom, transliterated } from './name.js';
|
|
4
|
+
export { HISTORY_CONVERSATIONS, SESSION_STARTED } from './conversation.js';
|
|
4
5
|
export { changeBatchIdentity } from './identity.js';
|
|
6
|
+
export { paced, ROW_WEIGHT, stepped } from './turn.js';
|
|
7
|
+
export { entriesIn, patching, sortedKeys } from './shared.js';
|
|
5
8
|
export { attempts, identities, intentOf, } from './attempt.js';
|
|
6
9
|
export { expectedList, expecting } from './expectation.js';
|
package/dist/live.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ChangeSet } from './change-set.js';
|
|
2
|
+
import { type KeyedResult, type QueryMessage } from './observation.js';
|
|
3
|
+
import type { PendingResult, Plan, QueryCoverage } from './query.js';
|
|
4
|
+
import type { QueryRoom } from './tables.js';
|
|
5
|
+
export type Cover = {
|
|
6
|
+
coverage: QueryCoverage;
|
|
7
|
+
rooms: readonly QueryRoom[];
|
|
8
|
+
} | PendingResult;
|
|
9
|
+
export type Ran = KeyedResult & {
|
|
10
|
+
readonly current: () => boolean;
|
|
11
|
+
};
|
|
12
|
+
export type Run = (plan: Plan, cover: () => Cover) => Promise<Ran>;
|
|
13
|
+
type Listener = (message: QueryMessage) => void;
|
|
14
|
+
export type LiveQueries = {
|
|
15
|
+
touched(set: ChangeSet): void;
|
|
16
|
+
recover(): void;
|
|
17
|
+
watch(plan: Plan, identity: string, cover: () => Cover, deliver: Listener): () => void;
|
|
18
|
+
close(): void;
|
|
19
|
+
};
|
|
20
|
+
export declare function createLiveQueries(run: Run): LiveQueries;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=live.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live.d.ts","sourceRoot":"","sources":["../src/live.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAIL,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAErE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,MAAM,KAAK,GAAG;IAAE,QAAQ,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,SAAS,SAAS,EAAE,CAAA;CAAE,GAAG,aAAa,CAAC;AAE7F,MAAM,MAAM,GAAG,GAAG,WAAW,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,OAAO,CAAA;CAAE,CAAC;AAEpE,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAEnE,KAAK,QAAQ,GAAG,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,CAAC;AAchD,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC;IAC9B,OAAO,IAAI,IAAI,CAAC;IAChB,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,EAAE,OAAO,EAAE,QAAQ,GAAG,MAAM,IAAI,CAAC;IACvF,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAoCF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,GAAG,WAAW,CAuFvD"}
|
package/dist/live.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { changeOf, digestOf, } from './observation.js';
|
|
2
|
+
import { roomOfKey } from './rows.js';
|
|
3
|
+
function narrowed(plan) {
|
|
4
|
+
return (plan.paths !== null &&
|
|
5
|
+
plan.hop === null &&
|
|
6
|
+
plan.backlinks === null &&
|
|
7
|
+
!(plan.shape.kind === 'documents' && plan.shape.backlinks));
|
|
8
|
+
}
|
|
9
|
+
function reads(plan, locator) {
|
|
10
|
+
if (plan.locked.includes(locator))
|
|
11
|
+
return false;
|
|
12
|
+
if (plan.rooms !== null && !plan.rooms.includes(locator))
|
|
13
|
+
return false;
|
|
14
|
+
if (plan.reach === null)
|
|
15
|
+
return true;
|
|
16
|
+
return (plan.reach.rooms.includes(locator) ||
|
|
17
|
+
plan.reach.documents.some((document) => roomOfKey(document) === locator) ||
|
|
18
|
+
plan.reach.areas.some((area) => area.room === locator && area.types.length > 0));
|
|
19
|
+
}
|
|
20
|
+
function affected(plan, set) {
|
|
21
|
+
if (set.rooms.some((locator) => reads(plan, locator)))
|
|
22
|
+
return true;
|
|
23
|
+
const paths = narrowed(plan) ? new Set(plan.paths) : null;
|
|
24
|
+
return set.documents.some(({ locator, path }) => reads(plan, locator) && (paths === null || path === null || paths.has(path)));
|
|
25
|
+
}
|
|
26
|
+
function shown(entry) {
|
|
27
|
+
const cover = entry.cover();
|
|
28
|
+
return JSON.stringify('pending' in cover ? cover : cover.coverage);
|
|
29
|
+
}
|
|
30
|
+
export function createLiveQueries(run) {
|
|
31
|
+
const entries = new Map();
|
|
32
|
+
let closed = false;
|
|
33
|
+
function deliver(entry, next) {
|
|
34
|
+
const previous = entry.digest;
|
|
35
|
+
entry.digest = digestOf(next);
|
|
36
|
+
entry.covered = JSON.stringify('pending' in next.result ? next.result : next.result.coverage);
|
|
37
|
+
const change = previous === undefined ? null : changeOf(previous, next);
|
|
38
|
+
if (change !== null) {
|
|
39
|
+
for (const listener of entry.ready)
|
|
40
|
+
listener(change);
|
|
41
|
+
}
|
|
42
|
+
for (const listener of entry.fresh) {
|
|
43
|
+
entry.ready.add(listener);
|
|
44
|
+
listener(next);
|
|
45
|
+
}
|
|
46
|
+
entry.fresh.clear();
|
|
47
|
+
}
|
|
48
|
+
function schedule(entry) {
|
|
49
|
+
if (closed || entry.listeners.size === 0)
|
|
50
|
+
return;
|
|
51
|
+
if (entry.running) {
|
|
52
|
+
entry.dirty = true;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
entry.running = true;
|
|
56
|
+
void (async () => {
|
|
57
|
+
try {
|
|
58
|
+
for (;;) {
|
|
59
|
+
entry.dirty = false;
|
|
60
|
+
const { current, ...next } = await run(entry.plan, entry.cover);
|
|
61
|
+
if (closed || entry.listeners.size === 0)
|
|
62
|
+
return;
|
|
63
|
+
deliver(entry, next);
|
|
64
|
+
if (!(entry.dirty && !current()) && shown(entry) === entry.covered)
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
entry.dirty = false;
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
entry.running = false;
|
|
73
|
+
}
|
|
74
|
+
})();
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
touched(set) {
|
|
78
|
+
for (const entry of entries.values()) {
|
|
79
|
+
if (affected(entry.plan, set))
|
|
80
|
+
schedule(entry);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
recover() {
|
|
84
|
+
for (const entry of entries.values()) {
|
|
85
|
+
if (entry.running)
|
|
86
|
+
continue;
|
|
87
|
+
if (entry.digest === undefined || shown(entry) !== entry.covered)
|
|
88
|
+
schedule(entry);
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
watch(plan, identity, cover, listener) {
|
|
92
|
+
let entry = entries.get(identity);
|
|
93
|
+
if (entry === undefined) {
|
|
94
|
+
entry = {
|
|
95
|
+
plan,
|
|
96
|
+
cover,
|
|
97
|
+
listeners: new Set(),
|
|
98
|
+
fresh: new Set(),
|
|
99
|
+
ready: new Set(),
|
|
100
|
+
digest: undefined,
|
|
101
|
+
covered: '',
|
|
102
|
+
dirty: false,
|
|
103
|
+
running: false,
|
|
104
|
+
};
|
|
105
|
+
entries.set(identity, entry);
|
|
106
|
+
}
|
|
107
|
+
const held = entry;
|
|
108
|
+
held.listeners.add(listener);
|
|
109
|
+
held.fresh.add(listener);
|
|
110
|
+
schedule(held);
|
|
111
|
+
return () => {
|
|
112
|
+
held.listeners.delete(listener);
|
|
113
|
+
held.fresh.delete(listener);
|
|
114
|
+
held.ready.delete(listener);
|
|
115
|
+
if (held.listeners.size === 0 && entries.get(identity) === held)
|
|
116
|
+
entries.delete(identity);
|
|
117
|
+
};
|
|
118
|
+
},
|
|
119
|
+
close() {
|
|
120
|
+
closed = true;
|
|
121
|
+
entries.clear();
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
package/dist/media.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MdRuntimeClient } from './client.js';
|
|
2
|
+
import type { ShownAnswer } from './outcome.js';
|
|
3
|
+
export declare const ROOM_MEDIA = "room-media";
|
|
4
|
+
type Show = (room: string, path: string, revision?: string) => Promise<ShownAnswer>;
|
|
5
|
+
export declare function shownBy(show: Show, client: MdRuntimeClient): MdRuntimeClient;
|
|
6
|
+
export declare function defineRoomMedia(client: Promise<MdRuntimeClient> | MdRuntimeClient, registry?: CustomElementRegistry): void;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=media.d.ts.map
|
|
@@ -0,0 +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,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,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,CAC7B,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,EAClD,QAAQ,GAAE,qBAAsC,GAC/C,IAAI,CAkLN"}
|
package/dist/media.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
export const ROOM_MEDIA = 'room-media';
|
|
2
|
+
const ATTRIBUTES = ['room', 'path', 'revision', 'width', 'height', 'alt'];
|
|
3
|
+
const LOADING = new Set(['room', 'path', 'revision']);
|
|
4
|
+
const NEARING = '600px 0px';
|
|
5
|
+
const RELINKS = 2;
|
|
6
|
+
// The Room's stream brings a file seconds after the text that links it, minutes after on a first open, and a page's reach of its Rooms settles seconds after it opens, so a file not shown yet is asked for again every three seconds.
|
|
7
|
+
const UNSHOWN_MS = 3_000;
|
|
8
|
+
const SHAPE = '16 / 9';
|
|
9
|
+
const STYLE = `:host{display:block}
|
|
10
|
+
[part=box]{position:relative;overflow:hidden}
|
|
11
|
+
[part=box]>img,[part=box]>video,[part=box]>audio{display:block;width:100%;height:100%;object-fit:contain}
|
|
12
|
+
[part=box]>slot{display:flex;align-items:center;justify-content:center;width:100%;height:100%;text-align:center}`;
|
|
13
|
+
const shows = new WeakMap();
|
|
14
|
+
export function shownBy(show, client) {
|
|
15
|
+
shows.set(client, show);
|
|
16
|
+
return client;
|
|
17
|
+
}
|
|
18
|
+
function ratioOf(width, height) {
|
|
19
|
+
const across = Number(width);
|
|
20
|
+
const down = Number(height);
|
|
21
|
+
return Number.isFinite(across) && Number.isFinite(down) && across > 0 && down > 0
|
|
22
|
+
? `${across} / ${down}`
|
|
23
|
+
: SHAPE;
|
|
24
|
+
}
|
|
25
|
+
function refusedForGood(shown) {
|
|
26
|
+
if (shown.kind === 'revoked-authorization')
|
|
27
|
+
return true;
|
|
28
|
+
return (shown.kind === 'rejected' || shown.kind === 'scoped-refusal') && !shown.retryable;
|
|
29
|
+
}
|
|
30
|
+
function drawnFor(mediaType) {
|
|
31
|
+
if (mediaType.startsWith('image/'))
|
|
32
|
+
return 'img';
|
|
33
|
+
if (mediaType.startsWith('video/'))
|
|
34
|
+
return 'video';
|
|
35
|
+
if (mediaType.startsWith('audio/'))
|
|
36
|
+
return 'audio';
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
export function defineRoomMedia(client, registry = customElements) {
|
|
40
|
+
if (registry.get(ROOM_MEDIA) !== undefined)
|
|
41
|
+
return;
|
|
42
|
+
const connected = Promise.resolve(client);
|
|
43
|
+
class RoomMedia extends HTMLElement {
|
|
44
|
+
static observedAttributes = ATTRIBUTES;
|
|
45
|
+
#root = this.attachShadow({ mode: 'open' });
|
|
46
|
+
#box = document.createElement('div');
|
|
47
|
+
#fallback = document.createElement('slot');
|
|
48
|
+
#watching = null;
|
|
49
|
+
#near = false;
|
|
50
|
+
#asked = 0;
|
|
51
|
+
#shown = null;
|
|
52
|
+
#drawn = null;
|
|
53
|
+
#loaded = false;
|
|
54
|
+
#relinked = 0;
|
|
55
|
+
constructor() {
|
|
56
|
+
super();
|
|
57
|
+
this.#box.setAttribute('part', 'box');
|
|
58
|
+
this.#root.append(Object.assign(document.createElement('style'), { textContent: STYLE }), this.#box);
|
|
59
|
+
this.#shape();
|
|
60
|
+
}
|
|
61
|
+
connectedCallback() {
|
|
62
|
+
this.#label();
|
|
63
|
+
this.#watching ??= new IntersectionObserver((seen) => {
|
|
64
|
+
if (!seen.some((entry) => entry.isIntersecting) || this.#near)
|
|
65
|
+
return;
|
|
66
|
+
this.#near = true;
|
|
67
|
+
void this.#load();
|
|
68
|
+
}, { rootMargin: NEARING });
|
|
69
|
+
this.#watching.observe(this);
|
|
70
|
+
}
|
|
71
|
+
disconnectedCallback() {
|
|
72
|
+
this.#watching?.disconnect();
|
|
73
|
+
this.#watching = null;
|
|
74
|
+
this.#near = false;
|
|
75
|
+
this.#asked += 1;
|
|
76
|
+
this.#show(null);
|
|
77
|
+
}
|
|
78
|
+
attributeChangedCallback(name, before, after) {
|
|
79
|
+
if (before === after)
|
|
80
|
+
return;
|
|
81
|
+
this.#shape();
|
|
82
|
+
if (this.isConnected)
|
|
83
|
+
this.#label();
|
|
84
|
+
if (!LOADING.has(name) || !this.#near)
|
|
85
|
+
return;
|
|
86
|
+
this.#relinked = 0;
|
|
87
|
+
void this.#load();
|
|
88
|
+
}
|
|
89
|
+
#shape() {
|
|
90
|
+
this.#box.style.aspectRatio = ratioOf(this.getAttribute('width'), this.getAttribute('height'));
|
|
91
|
+
}
|
|
92
|
+
#label() {
|
|
93
|
+
const alt = this.getAttribute('alt') ?? '';
|
|
94
|
+
const drawn = this.#drawn;
|
|
95
|
+
if (drawn instanceof HTMLMediaElement) {
|
|
96
|
+
this.removeAttribute('role');
|
|
97
|
+
this.removeAttribute('aria-label');
|
|
98
|
+
drawn.setAttribute('aria-label', alt);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
this.setAttribute('role', 'img');
|
|
102
|
+
this.setAttribute('aria-label', alt);
|
|
103
|
+
if (drawn !== null)
|
|
104
|
+
drawn.alt = '';
|
|
105
|
+
}
|
|
106
|
+
async #load() {
|
|
107
|
+
const asked = (this.#asked += 1);
|
|
108
|
+
this.#loaded = false;
|
|
109
|
+
const room = this.getAttribute('room');
|
|
110
|
+
const path = this.getAttribute('path');
|
|
111
|
+
const revision = this.getAttribute('revision') ?? undefined;
|
|
112
|
+
if (room === null || path === null) {
|
|
113
|
+
this.#unreadable();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const show = shows.get(await connected);
|
|
117
|
+
const shown = show === undefined ? null : await show(room, path, revision);
|
|
118
|
+
if (asked !== this.#asked)
|
|
119
|
+
return;
|
|
120
|
+
if (shown?.kind === 'link') {
|
|
121
|
+
this.#draw({ url: shown.url, copy: false }, shown.mediaType);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (shown?.kind !== 'binary') {
|
|
125
|
+
this.#unreadable();
|
|
126
|
+
if (shown === null || refusedForGood(shown))
|
|
127
|
+
return;
|
|
128
|
+
setTimeout(() => {
|
|
129
|
+
if (asked === this.#asked && this.#near)
|
|
130
|
+
void this.#load();
|
|
131
|
+
}, UNSHOWN_MS);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const copy = await new Response(shown.stream, {
|
|
135
|
+
headers: { 'content-type': shown.mediaType },
|
|
136
|
+
}).blob();
|
|
137
|
+
if (asked !== this.#asked)
|
|
138
|
+
return;
|
|
139
|
+
this.#draw({ url: URL.createObjectURL(copy), copy: true }, shown.mediaType);
|
|
140
|
+
}
|
|
141
|
+
#show(shown, content = null) {
|
|
142
|
+
if (this.#shown?.copy === true)
|
|
143
|
+
URL.revokeObjectURL(this.#shown.url);
|
|
144
|
+
this.#shown = shown;
|
|
145
|
+
if (content !== this.#drawn)
|
|
146
|
+
this.#drawn = null;
|
|
147
|
+
if (content === null)
|
|
148
|
+
this.#box.replaceChildren();
|
|
149
|
+
else if (content.parentNode !== this.#box)
|
|
150
|
+
this.#box.replaceChildren(content);
|
|
151
|
+
this.#label();
|
|
152
|
+
}
|
|
153
|
+
#unreadable() {
|
|
154
|
+
this.#show(null, this.#fallback);
|
|
155
|
+
}
|
|
156
|
+
#draw(shown, mediaType) {
|
|
157
|
+
const tag = drawnFor(mediaType);
|
|
158
|
+
if (tag === null) {
|
|
159
|
+
if (shown.copy)
|
|
160
|
+
URL.revokeObjectURL(shown.url);
|
|
161
|
+
this.#unreadable();
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const kept = this.#drawn?.localName === tag ? this.#drawn : null;
|
|
165
|
+
const drawn = kept ?? document.createElement(tag);
|
|
166
|
+
if (kept === null) {
|
|
167
|
+
if (drawn instanceof HTMLImageElement)
|
|
168
|
+
drawn.decoding = 'async';
|
|
169
|
+
if (drawn instanceof HTMLMediaElement) {
|
|
170
|
+
drawn.controls = true;
|
|
171
|
+
drawn.preload = 'metadata';
|
|
172
|
+
if (drawn instanceof HTMLVideoElement)
|
|
173
|
+
drawn.playsInline = true;
|
|
174
|
+
}
|
|
175
|
+
drawn.addEventListener(drawn instanceof HTMLImageElement ? 'load' : 'loadedmetadata', () => {
|
|
176
|
+
if (drawn !== this.#drawn)
|
|
177
|
+
return;
|
|
178
|
+
this.#loaded = true;
|
|
179
|
+
this.#relinked = 0;
|
|
180
|
+
});
|
|
181
|
+
drawn.addEventListener('error', () => this.#failed(drawn));
|
|
182
|
+
}
|
|
183
|
+
this.#drawn = drawn;
|
|
184
|
+
this.#show(shown, drawn);
|
|
185
|
+
drawn.src = shown.url;
|
|
186
|
+
}
|
|
187
|
+
#failed(drawn) {
|
|
188
|
+
if (drawn !== this.#drawn)
|
|
189
|
+
return;
|
|
190
|
+
if (this.#shown?.copy !== false || !this.#loaded || this.#relinked >= RELINKS) {
|
|
191
|
+
this.#unreadable();
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
this.#relinked += 1;
|
|
195
|
+
if (drawn instanceof HTMLMediaElement) {
|
|
196
|
+
const at = drawn.currentTime;
|
|
197
|
+
const playing = !drawn.paused;
|
|
198
|
+
drawn.addEventListener('loadedmetadata', () => {
|
|
199
|
+
drawn.currentTime = at;
|
|
200
|
+
if (playing)
|
|
201
|
+
void drawn.play().catch(() => undefined);
|
|
202
|
+
}, { once: true });
|
|
203
|
+
}
|
|
204
|
+
void this.#load();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
registry.define(ROOM_MEDIA, RoomMedia);
|
|
208
|
+
}
|
package/dist/memory.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
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 DiscoveryScope, type DiscoveredRoom, type HeadChange, type ListedConversation, type Member, type ProviderLimit, type Retention, type
|
|
2
|
+
import { type AcceptedMessage, type ActionResult, type Adapter, type BinaryFile, type Capability, type ConversationAction, type ConversationEvent, type DiscoveryScope, type DiscoveredRoom, type HeadChange, type ListedConversation, type Member, type ProviderLimit, type Retention, type ServiceMode } from './adapter.js';
|
|
3
3
|
export type MemoryRoom = DiscoveredRoom & {
|
|
4
4
|
model?: ModelResult;
|
|
5
|
-
selectionModel?: ModelResult;
|
|
6
5
|
documents?: Readonly<Record<string, string>>;
|
|
7
6
|
revisions?: Readonly<Record<string, string>>;
|
|
8
7
|
fileIds?: Readonly<Record<string, string>>;
|
|
9
8
|
changes?: Readonly<Record<string, HeadChange>>;
|
|
10
9
|
binaryFiles?: Readonly<Record<string, BinaryFile>>;
|
|
10
|
+
folders?: readonly string[];
|
|
11
11
|
blobs?: Readonly<Record<string, Blob>>;
|
|
12
12
|
};
|
|
13
13
|
export type MemoryConversation = {
|
|
14
14
|
conversation: string;
|
|
15
|
-
listed?: Omit<ListedConversation, 'conversation'>;
|
|
15
|
+
listed?: Omit<ListedConversation, 'conversation' | 'newest'>;
|
|
16
16
|
messages?: readonly AcceptedMessage[];
|
|
17
17
|
outcomes?: Partial<Record<ConversationAction, ActionResult>>;
|
|
18
18
|
};
|
|
@@ -27,6 +27,7 @@ export type MemoryAdapterOptions = {
|
|
|
27
27
|
member?: Member;
|
|
28
28
|
unopened?: boolean;
|
|
29
29
|
exhaustiveDiscovery?: true;
|
|
30
|
+
roomTypes?: string;
|
|
30
31
|
};
|
|
31
32
|
export type MemoryAdapter = Adapter & {
|
|
32
33
|
setRooms(rooms: readonly MemoryRoom[]): void;
|
|
@@ -46,7 +47,6 @@ export type MemoryAdapter = Adapter & {
|
|
|
46
47
|
notifyConversation(event: ConversationEvent): void;
|
|
47
48
|
notifyServiceMode(mode: ServiceMode): void;
|
|
48
49
|
heldRooms(): readonly string[];
|
|
49
|
-
heldDemand(): AcquiredDemand | null;
|
|
50
50
|
replicatedConversations(): readonly string[];
|
|
51
51
|
};
|
|
52
52
|
export declare function createMemoryAdapter(options?: MemoryAdapterOptions): MemoryAdapter;
|
package/dist/memory.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,YAAY,EACjB,KAAK,OAAO,
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA,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,EAItB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,UAAU,EAGf,KAAK,kBAAkB,EACvB,KAAK,MAAM,EAGX,KAAK,aAAa,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GAAG,aAAa,CAijBrF"}
|
package/dist/memory.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { sameChange } from './overlay.js';
|
|
2
|
+
const ATTACHMENTS = 'attachments';
|
|
3
|
+
function lastName(path) {
|
|
4
|
+
return path.slice(path.lastIndexOf('/') + 1);
|
|
5
|
+
}
|
|
2
6
|
const FIXTURE_RETENTION = {
|
|
3
7
|
history: { kind: 'duration', seconds: 1 },
|
|
4
8
|
outcome: 604_800,
|
|
@@ -15,12 +19,7 @@ function declaredRetention(value) {
|
|
|
15
19
|
}
|
|
16
20
|
const MODEL_ABSENT = { kind: 'model-unavailable', reason: 'not-readable' };
|
|
17
21
|
function modelsOf(room) {
|
|
18
|
-
return {
|
|
19
|
-
collection: room.model ?? MODEL_ABSENT,
|
|
20
|
-
...(room.typedSelection === undefined
|
|
21
|
-
? {}
|
|
22
|
-
: { selection: room.selectionModel ?? MODEL_ABSENT }),
|
|
23
|
-
};
|
|
22
|
+
return { collection: room.model ?? MODEL_ABSENT };
|
|
24
23
|
}
|
|
25
24
|
function changedModels(room, from) {
|
|
26
25
|
const now = modelsOf(room);
|
|
@@ -57,8 +56,9 @@ export function createMemoryAdapter(options = {}) {
|
|
|
57
56
|
const sealed = new Set();
|
|
58
57
|
const sentTurns = new Map();
|
|
59
58
|
const historyPageSize = options.historyPageSize;
|
|
59
|
+
const attached = new Map();
|
|
60
|
+
const linked = new WeakMap();
|
|
60
61
|
let held = [];
|
|
61
|
-
let heldDemand = null;
|
|
62
62
|
let expiring = [];
|
|
63
63
|
let replicated = [];
|
|
64
64
|
let issued = 0;
|
|
@@ -88,6 +88,19 @@ export function createMemoryAdapter(options = {}) {
|
|
|
88
88
|
const wanted = ordinals.get(`${locator}\u0000${target}`);
|
|
89
89
|
return held !== undefined && wanted !== undefined && held >= wanted;
|
|
90
90
|
}
|
|
91
|
+
function heldBlob(room, path) {
|
|
92
|
+
return attached.get(`${room.locator}\u0000${path}`) ?? room.blobs?.[path];
|
|
93
|
+
}
|
|
94
|
+
function freePath(room, name) {
|
|
95
|
+
const dot = name.lastIndexOf('.');
|
|
96
|
+
const stem = dot > 0 ? name.slice(0, dot) : name;
|
|
97
|
+
const extension = dot > 0 ? name.slice(dot) : '';
|
|
98
|
+
for (let count = 1;; count += 1) {
|
|
99
|
+
const path = `${ATTACHMENTS}/${count === 1 ? stem : `${stem}-${count}`}${extension}`;
|
|
100
|
+
if (heldBlob(room, path) === undefined && room.documents?.[path] === undefined)
|
|
101
|
+
return path;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
91
104
|
function retain(entries) {
|
|
92
105
|
for (const room of entries) {
|
|
93
106
|
note(room.locator, room);
|
|
@@ -128,9 +141,20 @@ export function createMemoryAdapter(options = {}) {
|
|
|
128
141
|
: { fileIds: named(room.fileIds, [...taken, ...targets]) }),
|
|
129
142
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
130
143
|
binaryFiles: named(room.binaryFiles ?? {}, targets),
|
|
144
|
+
...(opening && room.folders !== undefined ? { folders: room.folders } : {}),
|
|
131
145
|
...(next < paths.length ? { pageToken: taken.at(-1) } : {}),
|
|
132
146
|
};
|
|
133
147
|
}
|
|
148
|
+
function foldersMoved(room, from) {
|
|
149
|
+
const now = new Set(room.folders ?? []);
|
|
150
|
+
const before = new Set(from.folders ?? []);
|
|
151
|
+
const folders = [...now].filter((folder) => !before.has(folder)).sort();
|
|
152
|
+
const folderRemovals = [...before].filter((folder) => !now.has(folder)).sort();
|
|
153
|
+
return {
|
|
154
|
+
...(folders.length === 0 ? {} : { folders }),
|
|
155
|
+
...(folderRemovals.length === 0 ? {} : { folderRemovals }),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
134
158
|
function advancement(room, from, at) {
|
|
135
159
|
const current = room.documents ?? {};
|
|
136
160
|
const previous = from.documents ?? {};
|
|
@@ -164,6 +188,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
164
188
|
: { fileIds: named(room.fileIds, [...taken, ...targets]) }),
|
|
165
189
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
166
190
|
binaryFiles: named(room.binaryFiles ?? {}, targets),
|
|
191
|
+
...(opening ? foldersMoved(room, from) : {}),
|
|
167
192
|
removals: opening
|
|
168
193
|
? [
|
|
169
194
|
...Object.keys(previous).filter((path) => !(path in current) && !currentTargets.has(path)),
|
|
@@ -253,7 +278,9 @@ export function createMemoryAdapter(options = {}) {
|
|
|
253
278
|
return { kind: 'action', result: { conversation: named } };
|
|
254
279
|
}
|
|
255
280
|
function announceList() {
|
|
256
|
-
const entries = [...scripted.values()].flatMap(({ conversation, listed }) => listed === undefined
|
|
281
|
+
const entries = [...scripted.values()].flatMap(({ conversation, listed, messages = [] }) => listed === undefined
|
|
282
|
+
? []
|
|
283
|
+
: [{ conversation, ...listed, newest: messages.at(-1)?.position ?? null }]);
|
|
257
284
|
for (const listener of listeners)
|
|
258
285
|
listener({ kind: 'list', entries });
|
|
259
286
|
}
|
|
@@ -269,6 +296,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
269
296
|
}
|
|
270
297
|
return {
|
|
271
298
|
...(options.exhaustiveDiscovery === undefined ? {} : { exhaustiveDiscovery: true }),
|
|
299
|
+
...(options.roomTypes === undefined ? {} : { roomTypes: options.roomTypes }),
|
|
272
300
|
setRooms(next) {
|
|
273
301
|
rooms = [...next];
|
|
274
302
|
retain(rooms);
|
|
@@ -314,9 +342,6 @@ export function createMemoryAdapter(options = {}) {
|
|
|
314
342
|
heldRooms() {
|
|
315
343
|
return held;
|
|
316
344
|
},
|
|
317
|
-
heldDemand() {
|
|
318
|
-
return heldDemand;
|
|
319
|
-
},
|
|
320
345
|
replicatedConversations() {
|
|
321
346
|
return replicated;
|
|
322
347
|
},
|
|
@@ -340,9 +365,8 @@ export function createMemoryAdapter(options = {}) {
|
|
|
340
365
|
},
|
|
341
366
|
},
|
|
342
367
|
roomStream: {
|
|
343
|
-
hold(asked
|
|
368
|
+
hold(asked) {
|
|
344
369
|
held = asked.map((room) => room.locator);
|
|
345
|
-
heldDemand = demand;
|
|
346
370
|
const expired = expiring.filter((locator) => held.includes(locator));
|
|
347
371
|
expiring = [];
|
|
348
372
|
const moved = asked.flatMap((room) => {
|
|
@@ -458,7 +482,13 @@ export function createMemoryAdapter(options = {}) {
|
|
|
458
482
|
retryable: false,
|
|
459
483
|
affected: {},
|
|
460
484
|
};
|
|
461
|
-
}, request).then((answer) =>
|
|
485
|
+
}, request).then((answer) => {
|
|
486
|
+
const destination = request.changeBatch.between?.destination.room;
|
|
487
|
+
if (answer.kind === 'accepted' && answer.destination !== undefined && destination) {
|
|
488
|
+
note(destination, answer.destination);
|
|
489
|
+
}
|
|
490
|
+
return note(request.locator, answer);
|
|
491
|
+
});
|
|
462
492
|
},
|
|
463
493
|
async history(_authorization, request) {
|
|
464
494
|
return resolveScript(scripts.history, () => {
|
|
@@ -474,30 +504,38 @@ export function createMemoryAdapter(options = {}) {
|
|
|
474
504
|
},
|
|
475
505
|
async binary(_authorization, request) {
|
|
476
506
|
return resolveScript(scripts.binary, () => {
|
|
477
|
-
if (request.kind === 'reference') {
|
|
478
|
-
return { kind: 'rejected', code: 'unscripted-binary', fields: {}, retryable: false };
|
|
479
|
-
}
|
|
480
507
|
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
481
508
|
if (room === undefined)
|
|
482
509
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
483
|
-
const blob = room
|
|
510
|
+
const blob = heldBlob(room, request.path);
|
|
484
511
|
return blob === undefined
|
|
485
512
|
? { kind: 'rejected', code: 'file_not_found', fields: {}, retryable: false }
|
|
486
|
-
: { kind: 'binary', blob };
|
|
513
|
+
: { kind: 'binary', body: blob.stream(), mediaType: blob.type };
|
|
487
514
|
}, request);
|
|
488
515
|
},
|
|
489
516
|
async link(_authorization, request) {
|
|
490
|
-
return resolveScript(scripts.link, () =>
|
|
517
|
+
return resolveScript(scripts.link, () => {
|
|
518
|
+
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
519
|
+
if (room === undefined)
|
|
520
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
521
|
+
const blob = heldBlob(room, request.path);
|
|
522
|
+
if (blob === undefined) {
|
|
523
|
+
return { kind: 'rejected', code: 'file_not_found', fields: {}, retryable: false };
|
|
524
|
+
}
|
|
525
|
+
const url = linked.get(blob) ?? URL.createObjectURL(blob);
|
|
526
|
+
linked.set(blob, url);
|
|
527
|
+
return { kind: 'link', url, name: lastName(request.path), mediaType: blob.type };
|
|
528
|
+
}, request);
|
|
491
529
|
},
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
return
|
|
500
|
-
|
|
530
|
+
async attach(_authorization, request) {
|
|
531
|
+
return resolveScript(scripts.attach, () => {
|
|
532
|
+
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
533
|
+
if (room === undefined)
|
|
534
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
535
|
+
const path = freePath(room, request.name);
|
|
536
|
+
attached.set(`${room.locator}\u0000${path}`, request.blob);
|
|
537
|
+
return { kind: 'attached', path, revision: `attached-${attached.size}` };
|
|
538
|
+
}, request);
|
|
501
539
|
},
|
|
502
540
|
async action(_authorization, request) {
|
|
503
541
|
return resolveScript(scripts.action, () => {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AcceptedMessage } from './adapter.js';
|
|
2
|
+
import type { Connection } from './tables.js';
|
|
3
|
+
export declare const MESSAGE_TABLES: readonly string[];
|
|
4
|
+
export type HeldConversation = {
|
|
5
|
+
readonly conversation: string;
|
|
6
|
+
readonly read: string | null | undefined;
|
|
7
|
+
readonly partial: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type MessageWindow = {
|
|
10
|
+
readonly messages: AcceptedMessage[];
|
|
11
|
+
readonly more: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type ConversationWrite = {
|
|
14
|
+
readonly conversation: string;
|
|
15
|
+
readonly messages: readonly AcceptedMessage[];
|
|
16
|
+
readonly read?: {
|
|
17
|
+
readonly at: string | null;
|
|
18
|
+
readonly partial: boolean;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export declare function heldConversations(connection: Connection): HeldConversation[];
|
|
22
|
+
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;
|
|
25
|
+
export declare function turnArrived(connection: Connection, conversation: string, turn: string): boolean;
|
|
26
|
+
export declare function droppedMessages(connection: Connection, conversations: readonly string[]): void;
|
|
27
|
+
export declare function forgottenMessages(connection: Connection): void;
|
|
28
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAE1D,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAM3C,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,eAAe,EAAE,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAE7F,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAA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