@agentshouse/mdruntime 0.1.0-cedd665dffa4c → 0.1.0-cee2924c82d23
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 +9 -9
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +30 -1
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +48 -9
- package/dist/adapter.d.ts +118 -19
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +2 -2
- package/dist/{binary.d.ts → attachment.d.ts} +8 -4
- 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/chain.d.ts +1 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +5 -2
- package/dist/change.d.ts +2 -2
- package/dist/chat-types.js +2 -2
- package/dist/client.d.ts +16 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +24 -51
- package/dist/collection.d.ts +3 -1
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +16 -9
- 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 +2 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +71 -39
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +6 -2
- package/dist/conversation-live.d.ts +2 -3
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +2 -2
- package/dist/conversation.d.ts +18 -9
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +38 -22
- package/dist/declaration.js +3 -3
- package/dist/discovery.d.ts +3 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +30 -5
- 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 +1 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +3 -0
- package/dist/entry.d.ts +25 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +111 -34
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +3 -1
- package/dist/figures.d.ts +1 -1
- package/dist/figures.d.ts.map +1 -1
- package/dist/figures.js +2 -2
- package/dist/file.d.ts +1 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +1 -1
- package/dist/host.d.ts +6 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +57 -21
- 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 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +1 -1
- package/dist/index.d.ts +17 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -5
- package/dist/lifecycle.d.ts +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +28 -16
- package/dist/listing.d.ts +20 -12
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +33 -17
- package/dist/live.d.ts +14 -0
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +29 -12
- package/dist/loaded.d.ts +5 -3
- package/dist/loaded.d.ts.map +1 -1
- package/dist/loaded.js +12 -6
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +2 -0
- package/dist/media.d.ts +14 -3
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +126 -30
- package/dist/memory.d.ts +4 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +47 -16
- package/dist/messages.d.ts +6 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +11 -4
- 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 +10 -7
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +7 -1
- package/dist/name.d.ts +0 -1
- package/dist/name.d.ts.map +1 -1
- package/dist/name.js +3 -7
- package/dist/observation.d.ts +2 -0
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +42 -9
- 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 +5 -5
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +2 -2
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +18 -2
- package/dist/outcome.d.ts +27 -14
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +14 -5
- package/dist/overlay.d.ts +19 -8
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +108 -37
- package/dist/parts.d.ts +3 -1
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +30 -7
- package/dist/paths.d.ts +1 -1
- package/dist/paths.js +1 -1
- package/dist/preparation.d.ts +10 -5
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +78 -48
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +75 -53
- package/dist/query.d.ts +2 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.d.ts +1 -0
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +3 -1
- package/dist/reach.d.ts +13 -3
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +114 -25
- package/dist/react.d.ts +5 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/readiness.d.ts +17 -4
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +17 -7
- package/dist/reads.d.ts +1 -1
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +17 -6
- package/dist/recovery.d.ts +1 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +2 -1
- 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 +1 -1
- package/dist/refresh.js +4 -4
- package/dist/replica.d.ts +3 -8
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +3 -3
- package/dist/room-draft.d.ts +1 -1
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +9 -6
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +8 -6
- 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 +9 -1
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +18 -4
- 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 +5 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +1 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +6 -6
- package/dist/saves.d.ts +7 -5
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +86 -49
- package/dist/selector.d.ts +3 -0
- package/dist/selector.d.ts.map +1 -0
- package/dist/selector.js +22 -0
- package/dist/shown.d.ts +2 -0
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +21 -4
- package/dist/socket/session.d.ts +4 -1
- package/dist/socket/session.d.ts.map +1 -1
- package/dist/socket/session.js +3 -0
- package/dist/socket.d.ts +1 -0
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +1 -0
- package/dist/source.d.ts +2 -0
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +2 -0
- package/dist/store/records.d.ts +22 -5
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +14 -4
- package/dist/store.d.ts +3 -2
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +4 -1
- package/dist/stored.d.ts +17 -3
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +139 -35
- package/dist/surface.d.ts +12 -7
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +48 -15
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +45 -23
- package/dist/tables.d.ts +16 -47
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +69 -321
- package/dist/tallies.js +2 -2
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +49 -3
- package/dist/wire.d.ts +28 -6
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +17 -11
- package/package.json +4 -4
- package/dist/binary.d.ts.map +0 -1
- package/dist/binary.js +0 -8
package/dist/media.d.ts
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import type { MdRuntimeClient } from './client.js';
|
|
2
|
-
import { type
|
|
2
|
+
import { type DownloadAnswer } from './outcome.js';
|
|
3
3
|
export declare const ROOM_MEDIA = "room-media";
|
|
4
|
+
export declare const KEYED_MEDIA = "ahc-attachment";
|
|
5
|
+
export declare const MEDIA = "room-media, ahc-attachment";
|
|
4
6
|
export declare const DIAGRAM = "md-diagram";
|
|
5
7
|
export declare const VIEWING = "ahc-viewer";
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
+
type RoomAt = {
|
|
9
|
+
readonly room: string;
|
|
10
|
+
readonly path: string;
|
|
11
|
+
readonly revision: string | undefined;
|
|
12
|
+
};
|
|
13
|
+
export type MediaAt = {
|
|
14
|
+
readonly link: string;
|
|
15
|
+
} | RoomAt;
|
|
16
|
+
export declare function mediaAt(media: Element): MediaAt | null;
|
|
17
|
+
export declare function mediaTag(at: MediaAt): string;
|
|
18
|
+
export declare function downloadAt(client: MdRuntimeClient, at: MediaAt): Promise<DownloadAnswer>;
|
|
8
19
|
export declare function rendered(element: Element): boolean;
|
|
9
20
|
export declare function viewable(element: Element): boolean;
|
|
10
21
|
export declare function viewFile(client: MdRuntimeClient, media: Element): void;
|
package/dist/media.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"
|
|
1
|
+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1,14 +1,18 @@
|
|
|
1
1
|
import { isAudioType, isImageType, isVideoType } from '@agentshouse/mdmodel';
|
|
2
2
|
import { loaded } from './loaded.js';
|
|
3
|
-
import {
|
|
3
|
+
import { downloadAttachment } from './download.js';
|
|
4
|
+
import { attachmentBlob, UNCERTAIN } from './outcome.js';
|
|
4
5
|
export const ROOM_MEDIA = 'room-media';
|
|
6
|
+
export const KEYED_MEDIA = 'ahc-attachment';
|
|
7
|
+
export const MEDIA = `${ROOM_MEDIA}, ${KEYED_MEDIA}`;
|
|
5
8
|
const VIEWER = 'viewer';
|
|
6
9
|
const RENDERED = '.ahc, .ahc-markdown';
|
|
7
10
|
export const DIAGRAM = 'md-diagram';
|
|
8
11
|
export const VIEWING = 'ahc-viewer';
|
|
9
12
|
const PRESSED_ELSEWHERE = 'a[href], button, input, select, textarea, summary, label, [role="button"], [role="link"]';
|
|
10
13
|
const ATTRIBUTES = ['room', 'path', 'revision', 'width', 'height', 'alt'];
|
|
11
|
-
const
|
|
14
|
+
const KEYED_ATTRIBUTES = ['link', 'alt'];
|
|
15
|
+
const LOADING = new Set(['link', 'room', 'path', 'revision']);
|
|
12
16
|
const NEARING = '600px 0px';
|
|
13
17
|
const RELINKS = 2;
|
|
14
18
|
// 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.
|
|
@@ -21,17 +25,59 @@ const STYLE = `:host{display:block}
|
|
|
21
25
|
[part=box]>slot{display:flex;align-items:center;justify-content:center;width:100%;height:100%;text-align:center}
|
|
22
26
|
[part=play]{position:absolute;top:50%;left:50%;width:56px;height:56px;margin:-28px 0 0 -28px;border-radius:50%;background:rgb(0 0 0/.6);pointer-events:none}
|
|
23
27
|
[part=play]::before{content:"";position:absolute;top:18px;left:22px;border-style:solid;border-width:10px 0 10px 16px;border-color:transparent transparent transparent #fff}`;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
export function mediaAt(media) {
|
|
29
|
+
if (media.localName === KEYED_MEDIA) {
|
|
30
|
+
const link = media.getAttribute('link');
|
|
31
|
+
return link === null ? null : { link };
|
|
32
|
+
}
|
|
33
|
+
const room = media.getAttribute('room');
|
|
34
|
+
const path = media.getAttribute('path');
|
|
35
|
+
return room === null || path === null
|
|
36
|
+
? null
|
|
37
|
+
: { room, path, revision: media.getAttribute('revision') ?? undefined };
|
|
38
|
+
}
|
|
39
|
+
export function mediaTag(at) {
|
|
40
|
+
return 'link' in at ? KEYED_MEDIA : ROOM_MEDIA;
|
|
41
|
+
}
|
|
42
|
+
export function downloadAt(client, at) {
|
|
43
|
+
return 'link' in at
|
|
44
|
+
? downloadAttachment(client, at.link)
|
|
45
|
+
: client.attachment.download(at.room, at.path, at.revision);
|
|
46
|
+
}
|
|
47
|
+
function shownAt(client, at) {
|
|
48
|
+
if (at === null)
|
|
49
|
+
return null;
|
|
50
|
+
if ('link' in at) {
|
|
51
|
+
return client.conversation
|
|
52
|
+
.attachment(at.link)
|
|
53
|
+
.then((shown) => (shown.kind === 'link' ? { ...shown, copies: [] } : shown));
|
|
54
|
+
}
|
|
55
|
+
return client.attachment.show(at.room, at.path, at.revision);
|
|
28
56
|
}
|
|
29
57
|
function ratioOf(width, height) {
|
|
30
58
|
const across = Number(width);
|
|
31
59
|
const down = Number(height);
|
|
32
60
|
return Number.isFinite(across) && Number.isFinite(down) && across > 0 && down > 0
|
|
33
61
|
? `${across} / ${down}`
|
|
34
|
-
:
|
|
62
|
+
: null;
|
|
63
|
+
}
|
|
64
|
+
function ownRatio(found, at) {
|
|
65
|
+
const record = 'documents' in found ? found.documents[0]?.attachment : undefined;
|
|
66
|
+
if (record?.state !== 'accepted' ||
|
|
67
|
+
(at.revision !== undefined && record.revision !== at.revision)) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return ratioOf(record.width, record.height);
|
|
71
|
+
}
|
|
72
|
+
function offered(drawn, box, copies) {
|
|
73
|
+
if (copies.length === 0) {
|
|
74
|
+
drawn.removeAttribute('srcset');
|
|
75
|
+
drawn.removeAttribute('sizes');
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const across = Math.ceil(box.getBoundingClientRect().width);
|
|
79
|
+
drawn.sizes = across > 0 ? `${across}px` : '100vw';
|
|
80
|
+
drawn.srcset = copies.map(({ url, width }) => `${url} ${width}w`).join(', ');
|
|
35
81
|
}
|
|
36
82
|
function refusedForGood(shown) {
|
|
37
83
|
if (shown.kind === 'revoked-authorization')
|
|
@@ -53,18 +99,29 @@ export function rendered(element) {
|
|
|
53
99
|
export function viewable(element) {
|
|
54
100
|
if (element.localName === 'figure')
|
|
55
101
|
return element.classList.contains(DIAGRAM);
|
|
56
|
-
if (element.
|
|
102
|
+
if (!element.matches(MEDIA) || element.closest(`.${VIEWING}`) !== null)
|
|
57
103
|
return false;
|
|
58
104
|
return (rendered(element) || (element.shadowRoot?.querySelector('[part=box] > video') ?? null) !== null);
|
|
59
105
|
}
|
|
60
|
-
function viewed(client, opener, alone) {
|
|
61
|
-
void loaded(client.buildFile, VIEWER).then((file) =>
|
|
62
|
-
opener
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
106
|
+
function viewed(client, opener, alone, taken = () => true) {
|
|
107
|
+
void loaded(client.buildFile, VIEWER).then((file) => {
|
|
108
|
+
if (!opener.isConnected || !taken())
|
|
109
|
+
return;
|
|
110
|
+
file?.openViewer({
|
|
111
|
+
opener,
|
|
112
|
+
alone,
|
|
113
|
+
download: (at) => void downloadAt(client, at),
|
|
114
|
+
});
|
|
115
|
+
});
|
|
66
116
|
}
|
|
67
117
|
function pressed(client) {
|
|
118
|
+
let latest = null;
|
|
119
|
+
const taken = (opener) => () => {
|
|
120
|
+
if (latest !== opener)
|
|
121
|
+
return false;
|
|
122
|
+
latest = null;
|
|
123
|
+
return true;
|
|
124
|
+
};
|
|
68
125
|
return (event) => {
|
|
69
126
|
if (event.defaultPrevented || event.detail > 1)
|
|
70
127
|
return;
|
|
@@ -73,7 +130,8 @@ function pressed(client) {
|
|
|
73
130
|
continue;
|
|
74
131
|
if (viewable(node)) {
|
|
75
132
|
event.preventDefault();
|
|
76
|
-
|
|
133
|
+
latest = node;
|
|
134
|
+
void client.then((one) => viewed(one, node, !rendered(node), taken(node)));
|
|
77
135
|
return;
|
|
78
136
|
}
|
|
79
137
|
if (node.matches(PRESSED_ELSEWHERE))
|
|
@@ -102,6 +160,9 @@ export function defineRoomMedia(client) {
|
|
|
102
160
|
#drawn = null;
|
|
103
161
|
#loaded = false;
|
|
104
162
|
#relinked = 0;
|
|
163
|
+
#failedAt = 0;
|
|
164
|
+
#own = null;
|
|
165
|
+
#measuring = null;
|
|
105
166
|
constructor() {
|
|
106
167
|
super();
|
|
107
168
|
this.#box.setAttribute('part', 'box');
|
|
@@ -118,17 +179,21 @@ export function defineRoomMedia(client) {
|
|
|
118
179
|
void this.#load();
|
|
119
180
|
}, { rootMargin: NEARING });
|
|
120
181
|
this.#watching.observe(this);
|
|
182
|
+
this.#measure();
|
|
121
183
|
}
|
|
122
184
|
disconnectedCallback() {
|
|
123
185
|
this.#watching?.disconnect();
|
|
124
186
|
this.#watching = null;
|
|
125
187
|
this.#near = false;
|
|
126
188
|
this.#asked += 1;
|
|
189
|
+
this.#measure();
|
|
127
190
|
this.#show(null);
|
|
128
191
|
}
|
|
129
192
|
attributeChangedCallback(name, before, after) {
|
|
130
193
|
if (before === after)
|
|
131
194
|
return;
|
|
195
|
+
if (LOADING.has(name))
|
|
196
|
+
this.#measure();
|
|
132
197
|
this.#shape();
|
|
133
198
|
if (this.isConnected)
|
|
134
199
|
this.#label();
|
|
@@ -138,7 +203,28 @@ export function defineRoomMedia(client) {
|
|
|
138
203
|
void this.#load();
|
|
139
204
|
}
|
|
140
205
|
#shape() {
|
|
141
|
-
this.#box.style.aspectRatio =
|
|
206
|
+
this.#box.style.aspectRatio =
|
|
207
|
+
ratioOf(this.getAttribute('width'), this.getAttribute('height')) ?? this.#own ?? SHAPE;
|
|
208
|
+
}
|
|
209
|
+
#measure() {
|
|
210
|
+
void this.#measuring?.then((measured) => measured.close(), () => undefined);
|
|
211
|
+
this.#measuring = null;
|
|
212
|
+
this.#own = null;
|
|
213
|
+
const at = mediaAt(this);
|
|
214
|
+
if (this.#watching === null || at === null || 'link' in at)
|
|
215
|
+
return;
|
|
216
|
+
const measuring = connected.then((one) => one.observe('query', { rooms: [at.room], paths: [at.path], select: {} }));
|
|
217
|
+
this.#measuring = measuring;
|
|
218
|
+
void measuring.then((measured) => {
|
|
219
|
+
const heard = () => {
|
|
220
|
+
if (this.#measuring !== measuring)
|
|
221
|
+
return;
|
|
222
|
+
this.#own = ownRatio(measured.current(), at);
|
|
223
|
+
this.#shape();
|
|
224
|
+
};
|
|
225
|
+
measured.subscribe(heard);
|
|
226
|
+
heard();
|
|
227
|
+
}, () => undefined);
|
|
142
228
|
}
|
|
143
229
|
#label() {
|
|
144
230
|
const alt = this.getAttribute('alt') ?? '';
|
|
@@ -157,19 +243,12 @@ export function defineRoomMedia(client) {
|
|
|
157
243
|
async #load() {
|
|
158
244
|
const asked = (this.#asked += 1);
|
|
159
245
|
this.#loaded = false;
|
|
160
|
-
const
|
|
161
|
-
const
|
|
162
|
-
const revision = this.getAttribute('revision') ?? undefined;
|
|
163
|
-
if (room === null || path === null) {
|
|
164
|
-
this.#unreadable();
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
const show = shows.get(await connected);
|
|
168
|
-
const shown = show === undefined ? null : await show(room, path, revision).catch(() => UNCERTAIN);
|
|
246
|
+
const showing = shownAt(await connected, mediaAt(this));
|
|
247
|
+
const shown = showing === null ? null : await showing.catch(() => UNCERTAIN);
|
|
169
248
|
if (asked !== this.#asked)
|
|
170
249
|
return;
|
|
171
250
|
if (shown?.kind === 'link') {
|
|
172
|
-
this.#draw({ url: shown.url, copy: false }, shown.mediaType);
|
|
251
|
+
this.#draw({ url: shown.url, copy: false }, shown.mediaType, shown.copies);
|
|
173
252
|
return;
|
|
174
253
|
}
|
|
175
254
|
if (shown?.kind !== 'binary') {
|
|
@@ -179,13 +258,13 @@ export function defineRoomMedia(client) {
|
|
|
179
258
|
this.#unshown(asked);
|
|
180
259
|
return;
|
|
181
260
|
}
|
|
182
|
-
const copy = await
|
|
261
|
+
const copy = await attachmentBlob(shown).catch(() => null);
|
|
183
262
|
if (asked !== this.#asked)
|
|
184
263
|
return;
|
|
185
264
|
if (copy === null)
|
|
186
265
|
this.#unshown(asked);
|
|
187
266
|
else
|
|
188
|
-
this.#draw({ url: URL.createObjectURL(copy), copy: true }, shown.mediaType);
|
|
267
|
+
this.#draw({ url: URL.createObjectURL(copy), copy: true }, shown.mediaType, []);
|
|
189
268
|
}
|
|
190
269
|
#unshown(asked) {
|
|
191
270
|
this.#unreadable();
|
|
@@ -211,7 +290,7 @@ export function defineRoomMedia(client) {
|
|
|
211
290
|
#unreadable() {
|
|
212
291
|
this.#show(null, this.#fallback);
|
|
213
292
|
}
|
|
214
|
-
#draw(shown, mediaType) {
|
|
293
|
+
#draw(shown, mediaType, copies) {
|
|
215
294
|
const tag = drawnFor(mediaType);
|
|
216
295
|
if (tag === null) {
|
|
217
296
|
if (shown.copy)
|
|
@@ -237,12 +316,25 @@ export function defineRoomMedia(client) {
|
|
|
237
316
|
if (drawn !== this.#drawn)
|
|
238
317
|
return;
|
|
239
318
|
this.#loaded = true;
|
|
240
|
-
|
|
319
|
+
if (drawn instanceof HTMLImageElement)
|
|
320
|
+
this.#relinked = 0;
|
|
241
321
|
});
|
|
322
|
+
if (drawn instanceof HTMLMediaElement) {
|
|
323
|
+
const played = () => {
|
|
324
|
+
if (drawn !== this.#drawn || drawn.seeking)
|
|
325
|
+
return;
|
|
326
|
+
if (drawn.ended || drawn.currentTime > this.#failedAt)
|
|
327
|
+
this.#relinked = 0;
|
|
328
|
+
};
|
|
329
|
+
drawn.addEventListener('timeupdate', played);
|
|
330
|
+
drawn.addEventListener('ended', played);
|
|
331
|
+
}
|
|
242
332
|
drawn.addEventListener('error', () => this.#failed(drawn));
|
|
243
333
|
}
|
|
244
334
|
this.#drawn = drawn;
|
|
245
335
|
this.#show(shown, drawn);
|
|
336
|
+
if (drawn instanceof HTMLImageElement)
|
|
337
|
+
offered(drawn, this.#box, copies);
|
|
246
338
|
drawn.src = shown.url;
|
|
247
339
|
}
|
|
248
340
|
#failed(drawn) {
|
|
@@ -256,6 +348,7 @@ export function defineRoomMedia(client) {
|
|
|
256
348
|
if (drawn instanceof HTMLMediaElement) {
|
|
257
349
|
const at = drawn.currentTime;
|
|
258
350
|
const playing = !drawn.paused;
|
|
351
|
+
this.#failedAt = at;
|
|
259
352
|
drawn.addEventListener('loadedmetadata', () => {
|
|
260
353
|
drawn.currentTime = at;
|
|
261
354
|
if (playing)
|
|
@@ -266,4 +359,7 @@ export function defineRoomMedia(client) {
|
|
|
266
359
|
}
|
|
267
360
|
}
|
|
268
361
|
customElements.define(ROOM_MEDIA, RoomMedia);
|
|
362
|
+
customElements.define(KEYED_MEDIA, class extends RoomMedia {
|
|
363
|
+
static observedAttributes = KEYED_ATTRIBUTES;
|
|
364
|
+
});
|
|
269
365
|
}
|
package/dist/memory.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type VerifiedModel } from '@agentshouse/mdmodel';
|
|
2
2
|
import type { ModelResult } from './model.js';
|
|
3
|
-
import { type AcceptedMessage, type ActionResult, type Adapter, type
|
|
3
|
+
import { type AcceptedMessage, type ActionResult, type Adapter, type Attachment, type Capability, type ConversationAction, type ConversationEvent, type DiscoveredRoom, type SavedFacts, type HeadChange, type ListedAgent, type ListedConversation, type Member, type ProviderLimit, type Retention, type ServiceMode, type TypedPath, type TypedSelection } from './adapter.js';
|
|
4
4
|
export type MemoryRoom = Omit<DiscoveredRoom, 'typedSelection' | 'authoredPaths'> & {
|
|
5
5
|
typedSelection?: TypedSelection | null;
|
|
6
6
|
authoredPaths?: readonly string[];
|
|
@@ -11,7 +11,7 @@ export type MemoryRoom = Omit<DiscoveredRoom, 'typedSelection' | 'authoredPaths'
|
|
|
11
11
|
fileIds?: Readonly<Record<string, string>>;
|
|
12
12
|
created?: Readonly<Record<string, string>>;
|
|
13
13
|
changes?: Readonly<Record<string, HeadChange>>;
|
|
14
|
-
|
|
14
|
+
attachments?: Readonly<Record<string, Attachment>>;
|
|
15
15
|
folders?: readonly string[];
|
|
16
16
|
blobs?: Readonly<Record<string, Blob>>;
|
|
17
17
|
};
|
|
@@ -31,9 +31,11 @@ export type MemoryAdapterOptions = {
|
|
|
31
31
|
providerLimits?: readonly ProviderLimit[];
|
|
32
32
|
retention?: Retention;
|
|
33
33
|
member?: Member;
|
|
34
|
+
timeZone?: string | null;
|
|
34
35
|
unopened?: boolean;
|
|
35
36
|
roomTypes?: VerifiedModel;
|
|
36
37
|
typedPaths?: readonly TypedPath[];
|
|
38
|
+
privateRoom?: string;
|
|
37
39
|
};
|
|
38
40
|
export type MemoryAdapter = Adapter & {
|
|
39
41
|
discover: NonNullable<Adapter['discover']>;
|
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,
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,aAAa,EACnB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,YAAY,EACjB,KAAK,OAAO,EAIZ,KAAK,UAAU,EAOf,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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O,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,CA8sBrF"}
|
package/dist/memory.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import { definitionAt, documentFacts, parse } from '@agentshouse/mdmodel';
|
|
1
|
+
import { definitionAt, documentFacts, keyedDestination, keyedLink, parse, } from '@agentshouse/mdmodel';
|
|
2
2
|
import { NO_ROOM_TYPES, schemaTypes } from './attached-model.js';
|
|
3
3
|
import { selected } from './collection.js';
|
|
4
4
|
import { declaredType } from './outcome.js';
|
|
5
5
|
import { sameChange } from './overlay.js';
|
|
6
6
|
const ATTACHMENTS = 'attachments';
|
|
7
|
+
const UNFOUND = {
|
|
8
|
+
kind: 'rejected',
|
|
9
|
+
code: 'not_found',
|
|
10
|
+
fields: {},
|
|
11
|
+
retryable: false,
|
|
12
|
+
};
|
|
7
13
|
function lastName(path) {
|
|
8
14
|
return path.slice(path.lastIndexOf('/') + 1);
|
|
9
15
|
}
|
|
@@ -58,6 +64,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
58
64
|
const repeats = new Map();
|
|
59
65
|
const historyPageSize = options.historyPageSize;
|
|
60
66
|
const attached = new Map();
|
|
67
|
+
const keyed = new Map();
|
|
61
68
|
const linked = new WeakMap();
|
|
62
69
|
const carried = new Map();
|
|
63
70
|
let expiring = [];
|
|
@@ -93,16 +100,35 @@ export function createMemoryAdapter(options = {}) {
|
|
|
93
100
|
const wanted = ordinals.get(`${locator}\u0000${target}`);
|
|
94
101
|
return held !== undefined && wanted !== undefined && held >= wanted;
|
|
95
102
|
}
|
|
96
|
-
function
|
|
103
|
+
function heldBytes(room, path) {
|
|
97
104
|
return attached.get(`${room.locator}\u0000${path}`) ?? room.blobs?.[path];
|
|
98
105
|
}
|
|
106
|
+
function linkTo(room, path) {
|
|
107
|
+
const blob = room === undefined ? undefined : heldBytes(room, path);
|
|
108
|
+
if (blob === undefined)
|
|
109
|
+
return UNFOUND;
|
|
110
|
+
const url = linked.get(blob) ?? URL.createObjectURL(blob);
|
|
111
|
+
linked.set(blob, url);
|
|
112
|
+
return { kind: 'link', url, name: lastName(path), mediaType: declaredType(blob) };
|
|
113
|
+
}
|
|
114
|
+
function attachedKeyed(request) {
|
|
115
|
+
const room = rooms.find((entry) => entry.locator === options.privateRoom);
|
|
116
|
+
if (room === undefined) {
|
|
117
|
+
return { kind: 'rejected', code: 'room_not_found', fields: {}, retryable: false };
|
|
118
|
+
}
|
|
119
|
+
const path = freePath(room, request.name);
|
|
120
|
+
attached.set(`${room.locator}\u0000${path}`, request.blob);
|
|
121
|
+
const key = `memory-${keyed.size + 1}`;
|
|
122
|
+
keyed.set(key, { locator: room.locator, path });
|
|
123
|
+
return { kind: 'linked', link: keyedDestination(`/rooms/${room.handle}/${path}`, key) };
|
|
124
|
+
}
|
|
99
125
|
function freePath(room, name) {
|
|
100
126
|
const dot = name.lastIndexOf('.');
|
|
101
127
|
const stem = dot > 0 ? name.slice(0, dot) : name;
|
|
102
128
|
const extension = dot > 0 ? name.slice(dot) : '';
|
|
103
129
|
for (let count = 1;; count += 1) {
|
|
104
130
|
const path = `${ATTACHMENTS}/${count === 1 ? stem : `${stem}-${count}`}${extension}`;
|
|
105
|
-
if (
|
|
131
|
+
if (heldBytes(room, path) === undefined && room.documents?.[path] === undefined)
|
|
106
132
|
return path;
|
|
107
133
|
}
|
|
108
134
|
}
|
|
@@ -167,7 +193,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
167
193
|
const size = pageSize ?? paths.length;
|
|
168
194
|
const taken = paths.slice(from, from + size);
|
|
169
195
|
const next = from + taken.length;
|
|
170
|
-
const targets = opening ? Object.keys(room.
|
|
196
|
+
const targets = opening ? Object.keys(room.attachments ?? {}) : [];
|
|
171
197
|
return {
|
|
172
198
|
kind: 'bootstrap',
|
|
173
199
|
roomVersion: room.roomVersion,
|
|
@@ -182,7 +208,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
182
208
|
? {}
|
|
183
209
|
: { created: named(room.created, [...taken, ...targets]) }),
|
|
184
210
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
185
|
-
|
|
211
|
+
attachments: named(room.attachments ?? {}, targets),
|
|
186
212
|
...(opening && room.folders !== undefined ? { folders: room.folders } : {}),
|
|
187
213
|
...(next < paths.length ? { pageToken: taken.at(-1) } : {}),
|
|
188
214
|
};
|
|
@@ -200,8 +226,8 @@ export function createMemoryAdapter(options = {}) {
|
|
|
200
226
|
function advancement(room, from, at, whole = false) {
|
|
201
227
|
const current = room.documents ?? {};
|
|
202
228
|
const previous = from.documents ?? {};
|
|
203
|
-
const currentTargets = new Set(Object.keys(room.
|
|
204
|
-
const previousTargets = new Set(Object.keys(from.
|
|
229
|
+
const currentTargets = new Set(Object.keys(room.attachments ?? {}));
|
|
230
|
+
const previousTargets = new Set(Object.keys(from.attachments ?? {}));
|
|
205
231
|
const headMoved = (path) => room.revisions?.[path] !== from.revisions?.[path] ||
|
|
206
232
|
room.fileIds?.[path] !== from.fileIds?.[path] ||
|
|
207
233
|
room.created?.[path] !== from.created?.[path] ||
|
|
@@ -234,7 +260,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
234
260
|
? {}
|
|
235
261
|
: { created: named(room.created, [...taken, ...targets]) }),
|
|
236
262
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
237
|
-
|
|
263
|
+
attachments: named(room.attachments ?? {}, targets),
|
|
238
264
|
...(opening ? foldersMoved(room, from) : {}),
|
|
239
265
|
removals: opening
|
|
240
266
|
? [
|
|
@@ -366,6 +392,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
366
392
|
providerLimits,
|
|
367
393
|
retention,
|
|
368
394
|
...(options.member === undefined ? {} : { member: options.member }),
|
|
395
|
+
...(options.timeZone === undefined ? {} : { timeZone: options.timeZone }),
|
|
369
396
|
};
|
|
370
397
|
}
|
|
371
398
|
function discovered() {
|
|
@@ -443,6 +470,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
443
470
|
rooms: listed.map(declared),
|
|
444
471
|
left,
|
|
445
472
|
...(options.member === undefined ? {} : { member: options.member }),
|
|
473
|
+
...(options.timeZone === undefined ? {} : { timeZone: options.timeZone }),
|
|
446
474
|
});
|
|
447
475
|
},
|
|
448
476
|
notifyConversation(event) {
|
|
@@ -625,7 +653,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
625
653
|
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
626
654
|
if (room === undefined)
|
|
627
655
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
628
|
-
const blob =
|
|
656
|
+
const blob = heldBytes(room, request.path);
|
|
629
657
|
return blob === undefined
|
|
630
658
|
? { kind: 'rejected', code: 'not_found', fields: {}, retryable: false }
|
|
631
659
|
: { kind: 'binary', body: blob.stream(), mediaType: declaredType(blob) };
|
|
@@ -633,20 +661,23 @@ export function createMemoryAdapter(options = {}) {
|
|
|
633
661
|
},
|
|
634
662
|
async link(_authorization, request) {
|
|
635
663
|
return resolveScript(scripts.link, () => {
|
|
664
|
+
if (request.kind === 'key') {
|
|
665
|
+
const key = keyedLink(request.link)?.key;
|
|
666
|
+
const named = key === undefined ? undefined : keyed.get(key);
|
|
667
|
+
if (named === undefined)
|
|
668
|
+
return UNFOUND;
|
|
669
|
+
return linkTo(rooms.find((entry) => entry.locator === named.locator), named.path);
|
|
670
|
+
}
|
|
636
671
|
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
637
672
|
if (room === undefined)
|
|
638
673
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
639
|
-
|
|
640
|
-
if (blob === undefined) {
|
|
641
|
-
return { kind: 'rejected', code: 'not_found', fields: {}, retryable: false };
|
|
642
|
-
}
|
|
643
|
-
const url = linked.get(blob) ?? URL.createObjectURL(blob);
|
|
644
|
-
linked.set(blob, url);
|
|
645
|
-
return { kind: 'link', url, name: lastName(request.path), mediaType: declaredType(blob) };
|
|
674
|
+
return linkTo(room, request.path);
|
|
646
675
|
}, request);
|
|
647
676
|
},
|
|
648
677
|
async attach(_authorization, request) {
|
|
649
678
|
return resolveScript(scripts.attach, () => {
|
|
679
|
+
if (request.locator === undefined)
|
|
680
|
+
return attachedKeyed(request);
|
|
650
681
|
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
651
682
|
if (room === undefined)
|
|
652
683
|
return { kind: 'room-not-readable', locator: request.locator };
|
package/dist/messages.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { SessionState } from '@agentshouse/session-content';
|
|
1
2
|
import type { AcceptedMessage } from './adapter.js';
|
|
2
3
|
import type { Connection } from './tables.js';
|
|
3
4
|
export declare const MESSAGE_TABLES: readonly string[];
|
|
4
|
-
export declare const ROWS = "WITH chosen AS (\n SELECT listed.value AS conversation,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'assistant' ORDER BY position DESC, identity DESC LIMIT 1) AS answer,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND text <> '' ORDER BY position DESC, identity DESC LIMIT 1) AS said,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'house' ORDER BY position, identity LIMIT 1) AS opened,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'house' AND json_extract(message, '$.waiting') = 1 ORDER BY position, identity LIMIT 1) AS asking\n FROM json_each(?) AS listed\n )\n SELECT chosen.conversation AS conversation,\n substr(said.text, 1, 512) AS said_text,\n json_extract(said.message, '$.role') AS said_role,\n json_extract(said.message, '$.accepted_at') AS said_at,\n answer.turn AS answered,\n substr(json_extract(answer.message, '$.failure'), 1, 512) AS failure,\n (SELECT value FROM conversation_facts WHERE conversation = chosen.conversation AND name = 'openedTurn') AS opened_turn,\n json_extract(opened.message, '$.source') AS opened_source,\n json_extract(opened.message, '$.sender') AS opened_sender,\n asking.identity AS asking_identity,\n asking.text AS asking_text,\n json_extract(asking.message, '$.accepted_at') AS asking_at,\n json_extract(asking.message, '$.source') AS asking_source,\n json_extract(asking.message, '$.sender') AS asking_sender\n FROM chosen\n LEFT JOIN conversation_messages said ON said.id = chosen.said\n LEFT JOIN conversation_messages answer ON answer.id = chosen.answer\n LEFT JOIN conversation_messages opened ON opened.id = chosen.opened\n LEFT JOIN conversation_messages asking ON asking.id = chosen.asking";
|
|
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 answer.turn AS answered,\n json_extract(answer.message, '$.content.state') AS saved_state,\n json_extract(answer.message, '$.accepted_at') AS saved_at,\n substr(json_extract(answer.message, '$.failure'), 1, 512) AS failure,\n COALESCE(\n (SELECT value FROM conversation_facts WHERE conversation = chosen.conversation AND name = 'openedTurn'),\n CASE WHEN julianday(json_extract(answer.message, '$.accepted_at')) < (SELECT julianday(json_extract(value, '$')) FROM replica_facts WHERE name = 'readUntil') THEN answer.turn END\n ) AS opened_turn,\n json_extract(opened.message, '$.source') AS opened_source,\n json_extract(opened.message, '$.sender') AS opened_sender,\n asking.identity AS asking_identity,\n asking.text AS asking_text,\n json_extract(asking.message, '$.accepted_at') AS asking_at,\n json_extract(asking.message, '$.source') AS asking_source,\n json_extract(asking.message, '$.sender') AS asking_sender\n FROM chosen\n LEFT JOIN conversation_messages said ON said.id = chosen.said\n LEFT JOIN conversation_messages answer ON answer.id = chosen.answer\n LEFT JOIN conversation_messages opened ON opened.id = chosen.opened\n LEFT JOIN conversation_messages asking ON asking.id = chosen.asking";
|
|
5
6
|
export type HeldConversation = {
|
|
6
7
|
readonly conversation: string;
|
|
7
8
|
readonly read: string | null | undefined;
|
|
@@ -23,6 +24,10 @@ export type HeldRow = {
|
|
|
23
24
|
readonly at: string | null;
|
|
24
25
|
} | null;
|
|
25
26
|
readonly answered: string | null;
|
|
27
|
+
readonly saved: {
|
|
28
|
+
readonly state: SessionState;
|
|
29
|
+
readonly at: string;
|
|
30
|
+
} | null;
|
|
26
31
|
readonly openedTurn: string | null;
|
|
27
32
|
readonly failure: string | null;
|
|
28
33
|
readonly opened: HeldSource | null;
|
package/dist/messages.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAIpD,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAM1D,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAQ3C,CAAC;AAUF,eAAO,MAAM,IAAI,wvEA+BqD,CAAC;AAEvE,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,UAAU,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAEtF,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE;QACb,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QAC7B,QA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B,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,GACtC,gBAAgB,EAAE,CA0BpB;AAED,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,iBAAiB,GAClD,IAAI,CAsBN;AAmBD,wBAAgB,aAAa,CAC3B,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,EACxC,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,aAAa,CAWf;AAED,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,MAAM,CAOR;AAaD,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,SAAS,MAAM,EAAE,GAC/B,OAAO,EAAE,CA6BX;AAED,wBAAgB,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAO/F;AAED,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,QAAQ,EAAE,CAMpE;AAED,wBAAgB,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,QAAQ,GAAG,IAAI,CAM9F;AAED,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAEnE"}
|
package/dist/messages.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { sql } from '@agentshouse/mdmodel';
|
|
2
|
+
import { text } from './column.js';
|
|
2
3
|
import { EXCERPT } from './read.js';
|
|
3
4
|
import { tablesOf } from './stored.js';
|
|
4
5
|
const SAID_BY_HOUSE = `json_extract(message, '$.role') = 'house'`;
|
|
@@ -15,6 +16,7 @@ export const MESSAGE_TABLES = [
|
|
|
15
16
|
const NEWEST_FIRST = 'ORDER BY position DESC, identity DESC LIMIT 1';
|
|
16
17
|
const OLDEST_FIRST = 'ORDER BY position, identity LIMIT 1';
|
|
17
18
|
const OF_THE_ROW = 'SELECT id FROM conversation_messages WHERE conversation = listed.value';
|
|
19
|
+
const READ_UNTIL = `(SELECT julianday(json_extract(value, '$')) FROM replica_facts WHERE name = 'readUntil')`;
|
|
18
20
|
export const ROWS = `WITH chosen AS (
|
|
19
21
|
SELECT listed.value AS conversation,
|
|
20
22
|
(${OF_THE_ROW} AND ${ANSWERS_THE_TURN} ${NEWEST_FIRST}) AS answer,
|
|
@@ -28,8 +30,13 @@ export const ROWS = `WITH chosen AS (
|
|
|
28
30
|
json_extract(said.message, '$.role') AS said_role,
|
|
29
31
|
json_extract(said.message, '$.accepted_at') AS said_at,
|
|
30
32
|
answer.turn AS answered,
|
|
33
|
+
json_extract(answer.message, '$.content.state') AS saved_state,
|
|
34
|
+
json_extract(answer.message, '$.accepted_at') AS saved_at,
|
|
31
35
|
substr(json_extract(answer.message, '$.failure'), 1, ${EXCERPT}) AS failure,
|
|
32
|
-
(
|
|
36
|
+
COALESCE(
|
|
37
|
+
(SELECT value FROM conversation_facts WHERE conversation = chosen.conversation AND name = 'openedTurn'),
|
|
38
|
+
CASE WHEN julianday(json_extract(answer.message, '$.accepted_at')) < ${READ_UNTIL} THEN answer.turn END
|
|
39
|
+
) AS opened_turn,
|
|
33
40
|
json_extract(opened.message, '$.source') AS opened_source,
|
|
34
41
|
json_extract(opened.message, '$.sender') AS opened_sender,
|
|
35
42
|
asking.identity AS asking_identity,
|
|
@@ -42,9 +49,6 @@ export const ROWS = `WITH chosen AS (
|
|
|
42
49
|
LEFT JOIN conversation_messages answer ON answer.id = chosen.answer
|
|
43
50
|
LEFT JOIN conversation_messages opened ON opened.id = chosen.opened
|
|
44
51
|
LEFT JOIN conversation_messages asking ON asking.id = chosen.asking`;
|
|
45
|
-
function text(value) {
|
|
46
|
-
return typeof value === 'string' ? value : String(value);
|
|
47
|
-
}
|
|
48
52
|
export function heldConversations(connection, conversations) {
|
|
49
53
|
const named = conversations === null ? '' : ' AND conversation IN (SELECT value FROM json_each(?))';
|
|
50
54
|
const bound = conversations === null ? [] : [JSON.stringify(conversations)];
|
|
@@ -129,6 +133,9 @@ export function conversationRows(connection, conversations) {
|
|
|
129
133
|
at: textOrNull(row.said_at),
|
|
130
134
|
},
|
|
131
135
|
answered: textOrNull(row.answered),
|
|
136
|
+
saved: row.saved_state === null || row.saved_at === null
|
|
137
|
+
? null
|
|
138
|
+
: { state: JSON.parse(text(row.saved_state)), at: text(row.saved_at) },
|
|
132
139
|
openedTurn: textOrNull(row.opened_turn),
|
|
133
140
|
failure: textOrNull(row.failure),
|
|
134
141
|
opened: row.opened_source === null ? null : heldSource(row.opened_source, row.opened_sender),
|
package/dist/modal.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modal.d.ts","sourceRoot":"","sources":["../src/modal.ts"],"names":[],"mappings":"AAMA,wBAAgB,UAAU,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAI1D"}
|
package/dist/modal.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function unfocused(page) {
|
|
2
|
+
let held = page.activeElement;
|
|
3
|
+
while (held?.shadowRoot?.activeElement)
|
|
4
|
+
held = held.shadowRoot.activeElement;
|
|
5
|
+
held.blur();
|
|
6
|
+
}
|
|
7
|
+
export function shownModal(dialog) {
|
|
8
|
+
unfocused(dialog.ownerDocument);
|
|
9
|
+
dialog.showModal();
|
|
10
|
+
unfocused(dialog.ownerDocument);
|
|
11
|
+
}
|