@agentshouse/mdruntime 0.1.0-cb9c79aee537a → 0.1.0-cba6f2439bb25

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.
Files changed (229) hide show
  1. package/README.md +18 -15
  2. package/dist/adapter.d.ts +70 -32
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/attached-model.d.ts +5 -1
  5. package/dist/attached-model.d.ts.map +1 -1
  6. package/dist/attached-model.js +38 -4
  7. package/dist/binary.d.ts +0 -5
  8. package/dist/binary.d.ts.map +1 -1
  9. package/dist/binary.js +1 -1
  10. package/dist/bootstrap.d.ts +26 -8
  11. package/dist/bootstrap.d.ts.map +1 -1
  12. package/dist/bootstrap.js +174 -102
  13. package/dist/chain.d.ts +11 -0
  14. package/dist/chain.d.ts.map +1 -0
  15. package/dist/chain.js +64 -0
  16. package/dist/change-set.d.ts +9 -16
  17. package/dist/change-set.d.ts.map +1 -1
  18. package/dist/change-set.js +11 -89
  19. package/dist/change.d.ts +31 -1
  20. package/dist/change.d.ts.map +1 -1
  21. package/dist/change.js +10 -1
  22. package/dist/client.d.ts +9 -5
  23. package/dist/client.d.ts.map +1 -1
  24. package/dist/client.js +80 -6
  25. package/dist/collection.d.ts +11 -20
  26. package/dist/collection.d.ts.map +1 -1
  27. package/dist/collection.js +53 -354
  28. package/dist/compile.d.ts +16 -0
  29. package/dist/compile.d.ts.map +1 -0
  30. package/dist/compile.js +771 -0
  31. package/dist/connection.d.ts +18 -10
  32. package/dist/connection.d.ts.map +1 -1
  33. package/dist/connection.js +2631 -986
  34. package/dist/conversation.d.ts +14 -6
  35. package/dist/conversation.d.ts.map +1 -1
  36. package/dist/conversation.js +237 -90
  37. package/dist/digest.d.ts +7 -0
  38. package/dist/digest.d.ts.map +1 -0
  39. package/dist/digest.js +113 -0
  40. package/dist/durability.d.ts +3 -5
  41. package/dist/durability.d.ts.map +1 -1
  42. package/dist/durability.js +5 -0
  43. package/dist/entry.d.ts +4 -1
  44. package/dist/entry.d.ts.map +1 -1
  45. package/dist/entry.js +18 -24
  46. package/dist/file.d.ts +2 -19
  47. package/dist/file.d.ts.map +1 -1
  48. package/dist/file.js +7 -122
  49. package/dist/fulltext.d.ts +27 -0
  50. package/dist/fulltext.d.ts.map +1 -0
  51. package/dist/fulltext.js +370 -0
  52. package/dist/host.d.ts +4 -4
  53. package/dist/host.d.ts.map +1 -1
  54. package/dist/host.js +45 -15
  55. package/dist/identity.d.ts +0 -1
  56. package/dist/identity.d.ts.map +1 -1
  57. package/dist/identity.js +0 -3
  58. package/dist/index.d.ts +12 -10
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +5 -2
  61. package/dist/live.d.ts +22 -0
  62. package/dist/live.d.ts.map +1 -0
  63. package/dist/live.js +124 -0
  64. package/dist/media.d.ts +8 -0
  65. package/dist/media.d.ts.map +1 -0
  66. package/dist/media.js +208 -0
  67. package/dist/memory.d.ts +3 -2
  68. package/dist/memory.d.ts.map +1 -1
  69. package/dist/memory.js +66 -23
  70. package/dist/messages.d.ts +28 -0
  71. package/dist/messages.d.ts.map +1 -0
  72. package/dist/messages.js +90 -0
  73. package/dist/model.d.ts +6 -0
  74. package/dist/model.d.ts.map +1 -1
  75. package/dist/model.js +7 -1
  76. package/dist/name.d.ts +4 -0
  77. package/dist/name.d.ts.map +1 -0
  78. package/dist/name.js +122 -0
  79. package/dist/observation.d.ts +13 -0
  80. package/dist/observation.d.ts.map +1 -1
  81. package/dist/observation.js +84 -0
  82. package/dist/opened.d.ts +22 -0
  83. package/dist/opened.d.ts.map +1 -0
  84. package/dist/opened.js +107 -0
  85. package/dist/outcome.d.ts +40 -5
  86. package/dist/outcome.d.ts.map +1 -1
  87. package/dist/outcome.js +38 -2
  88. package/dist/overlay.d.ts +2 -6
  89. package/dist/overlay.d.ts.map +1 -1
  90. package/dist/overlay.js +87 -176
  91. package/dist/paths.d.ts +1 -0
  92. package/dist/paths.d.ts.map +1 -1
  93. package/dist/paths.js +4 -0
  94. package/dist/query.d.ts +11 -1
  95. package/dist/query.d.ts.map +1 -1
  96. package/dist/query.js +13 -1
  97. package/dist/reach.d.ts +13 -4
  98. package/dist/reach.d.ts.map +1 -1
  99. package/dist/reach.js +201 -72
  100. package/dist/readiness.d.ts +19 -9
  101. package/dist/readiness.d.ts.map +1 -1
  102. package/dist/readiness.js +6 -6
  103. package/dist/reads.d.ts.map +1 -1
  104. package/dist/reads.js +10 -17
  105. package/dist/recovery.d.ts +2 -2
  106. package/dist/recovery.d.ts.map +1 -1
  107. package/dist/recovery.js +8 -7
  108. package/dist/refresh.d.ts +15 -14
  109. package/dist/refresh.d.ts.map +1 -1
  110. package/dist/refresh.js +113 -56
  111. package/dist/replica.d.ts +56 -38
  112. package/dist/replica.d.ts.map +1 -1
  113. package/dist/replica.js +279 -195
  114. package/dist/room-draft.d.ts +21 -3
  115. package/dist/room-draft.d.ts.map +1 -1
  116. package/dist/room-draft.js +102 -28
  117. package/dist/rows.d.ts +38 -31
  118. package/dist/rows.d.ts.map +1 -1
  119. package/dist/rows.js +173 -101
  120. package/dist/save.d.ts +52 -15
  121. package/dist/save.d.ts.map +1 -1
  122. package/dist/save.js +504 -182
  123. package/dist/search.d.ts +11 -43
  124. package/dist/search.d.ts.map +1 -1
  125. package/dist/search.js +0 -213
  126. package/dist/shared.d.ts +5 -3
  127. package/dist/shared.d.ts.map +1 -1
  128. package/dist/shared.js +72 -35
  129. package/dist/status.d.ts +5 -0
  130. package/dist/status.d.ts.map +1 -1
  131. package/dist/status.js +3 -1
  132. package/dist/store.d.ts +85 -93
  133. package/dist/store.d.ts.map +1 -1
  134. package/dist/store.js +323 -687
  135. package/dist/stored.d.ts +135 -0
  136. package/dist/stored.d.ts.map +1 -0
  137. package/dist/stored.js +568 -0
  138. package/dist/tables.d.ts +352 -0
  139. package/dist/tables.d.ts.map +1 -0
  140. package/dist/tables.js +621 -0
  141. package/dist/turn.d.ts +2 -2
  142. package/dist/turn.d.ts.map +1 -1
  143. package/dist/turn.js +34 -23
  144. package/dist/validation.d.ts +30 -0
  145. package/dist/validation.d.ts.map +1 -0
  146. package/dist/validation.js +162 -0
  147. package/dist/windows.d.ts +2 -6
  148. package/dist/windows.d.ts.map +1 -1
  149. package/dist/windows.js +30 -34
  150. package/dist/wire.d.ts +17 -1
  151. package/dist/wire.d.ts.map +1 -1
  152. package/dist/wire.js +5 -1
  153. package/dist/words.d.ts +19 -0
  154. package/dist/words.d.ts.map +1 -0
  155. package/dist/words.js +156 -0
  156. package/package.json +18 -19
  157. package/AGENTS.md +0 -299
  158. package/dist/chat/acts.d.ts +0 -33
  159. package/dist/chat/acts.d.ts.map +0 -1
  160. package/dist/chat/acts.js +0 -36
  161. package/dist/chat/context.d.ts +0 -3
  162. package/dist/chat/context.d.ts.map +0 -1
  163. package/dist/chat/context.js +0 -10
  164. package/dist/chat/earlier.d.ts +0 -10
  165. package/dist/chat/earlier.d.ts.map +0 -1
  166. package/dist/chat/earlier.js +0 -54
  167. package/dist/chat/input.d.ts +0 -9
  168. package/dist/chat/input.d.ts.map +0 -1
  169. package/dist/chat/input.js +0 -99
  170. package/dist/chat/kit.d.ts +0 -61
  171. package/dist/chat/kit.d.ts.map +0 -1
  172. package/dist/chat/kit.js +0 -123
  173. package/dist/chat/lasting.d.ts +0 -6
  174. package/dist/chat/lasting.d.ts.map +0 -1
  175. package/dist/chat/lasting.js +0 -19
  176. package/dist/chat/list.d.ts +0 -27
  177. package/dist/chat/list.d.ts.map +0 -1
  178. package/dist/chat/list.js +0 -99
  179. package/dist/chat/markdown.d.ts +0 -21
  180. package/dist/chat/markdown.d.ts.map +0 -1
  181. package/dist/chat/markdown.js +0 -246
  182. package/dist/chat/message.d.ts +0 -6
  183. package/dist/chat/message.d.ts.map +0 -1
  184. package/dist/chat/message.js +0 -192
  185. package/dist/chat/messages.d.ts +0 -22
  186. package/dist/chat/messages.d.ts.map +0 -1
  187. package/dist/chat/messages.js +0 -155
  188. package/dist/chat/name.d.ts +0 -6
  189. package/dist/chat/name.d.ts.map +0 -1
  190. package/dist/chat/name.js +0 -37
  191. package/dist/chat/opened.d.ts +0 -11
  192. package/dist/chat/opened.d.ts.map +0 -1
  193. package/dist/chat/opened.js +0 -17
  194. package/dist/chat/overlay.d.ts +0 -31
  195. package/dist/chat/overlay.d.ts.map +0 -1
  196. package/dist/chat/overlay.js +0 -97
  197. package/dist/chat/parts.d.ts +0 -57
  198. package/dist/chat/parts.d.ts.map +0 -1
  199. package/dist/chat/parts.js +0 -119
  200. package/dist/chat/pieces.d.ts +0 -51
  201. package/dist/chat/pieces.d.ts.map +0 -1
  202. package/dist/chat/pieces.js +0 -797
  203. package/dist/chat/process.d.ts +0 -20
  204. package/dist/chat/process.d.ts.map +0 -1
  205. package/dist/chat/process.js +0 -32
  206. package/dist/chat/provider.d.ts +0 -63
  207. package/dist/chat/provider.d.ts.map +0 -1
  208. package/dist/chat/provider.js +0 -628
  209. package/dist/chat/question.d.ts +0 -9
  210. package/dist/chat/question.d.ts.map +0 -1
  211. package/dist/chat/question.js +0 -69
  212. package/dist/chat/questions.d.ts +0 -31
  213. package/dist/chat/questions.d.ts.map +0 -1
  214. package/dist/chat/questions.js +0 -111
  215. package/dist/chat/read.d.ts +0 -5
  216. package/dist/chat/read.d.ts.map +0 -1
  217. package/dist/chat/read.js +0 -13
  218. package/dist/chat/ready.d.ts +0 -34
  219. package/dist/chat/ready.d.ts.map +0 -1
  220. package/dist/chat/ready.js +0 -91
  221. package/dist/chat/style.d.ts +0 -4
  222. package/dist/chat/style.d.ts.map +0 -1
  223. package/dist/chat/style.js +0 -302
  224. package/dist/chat.d.ts +0 -14
  225. package/dist/chat.d.ts.map +0 -1
  226. package/dist/chat.js +0 -8
  227. package/dist/read-side.d.ts +0 -27
  228. package/dist/read-side.d.ts.map +0 -1
  229. package/dist/read-side.js +0 -824
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
+ }
@@ -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
@@ -2,17 +2,17 @@ import type { ModelResult } from './model.js';
2
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;
@@ -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,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CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IAC7D,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,KAAK,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;IACrD,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;CAC9C,CAAC;AA0CF,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,oBAAyB,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,6 +56,8 @@ 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
62
  let expiring = [];
62
63
  let replicated = [];
@@ -87,6 +88,19 @@ export function createMemoryAdapter(options = {}) {
87
88
  const wanted = ordinals.get(`${locator}\u0000${target}`);
88
89
  return held !== undefined && wanted !== undefined && held >= wanted;
89
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
+ }
90
104
  function retain(entries) {
91
105
  for (const room of entries) {
92
106
  note(room.locator, room);
@@ -127,9 +141,20 @@ export function createMemoryAdapter(options = {}) {
127
141
  : { fileIds: named(room.fileIds, [...taken, ...targets]) }),
128
142
  changes: named(room.changes ?? {}, [...taken, ...targets]),
129
143
  binaryFiles: named(room.binaryFiles ?? {}, targets),
144
+ ...(opening && room.folders !== undefined ? { folders: room.folders } : {}),
130
145
  ...(next < paths.length ? { pageToken: taken.at(-1) } : {}),
131
146
  };
132
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
+ }
133
158
  function advancement(room, from, at) {
134
159
  const current = room.documents ?? {};
135
160
  const previous = from.documents ?? {};
@@ -163,6 +188,7 @@ export function createMemoryAdapter(options = {}) {
163
188
  : { fileIds: named(room.fileIds, [...taken, ...targets]) }),
164
189
  changes: named(room.changes ?? {}, [...taken, ...targets]),
165
190
  binaryFiles: named(room.binaryFiles ?? {}, targets),
191
+ ...(opening ? foldersMoved(room, from) : {}),
166
192
  removals: opening
167
193
  ? [
168
194
  ...Object.keys(previous).filter((path) => !(path in current) && !currentTargets.has(path)),
@@ -252,7 +278,9 @@ export function createMemoryAdapter(options = {}) {
252
278
  return { kind: 'action', result: { conversation: named } };
253
279
  }
254
280
  function announceList() {
255
- const entries = [...scripted.values()].flatMap(({ conversation, listed }) => listed === undefined ? [] : [{ conversation, ...listed }]);
281
+ const entries = [...scripted.values()].flatMap(({ conversation, listed, messages = [] }) => listed === undefined
282
+ ? []
283
+ : [{ conversation, ...listed, newest: messages.at(-1)?.position ?? null }]);
256
284
  for (const listener of listeners)
257
285
  listener({ kind: 'list', entries });
258
286
  }
@@ -268,6 +296,7 @@ export function createMemoryAdapter(options = {}) {
268
296
  }
269
297
  return {
270
298
  ...(options.exhaustiveDiscovery === undefined ? {} : { exhaustiveDiscovery: true }),
299
+ ...(options.roomTypes === undefined ? {} : { roomTypes: options.roomTypes }),
271
300
  setRooms(next) {
272
301
  rooms = [...next];
273
302
  retain(rooms);
@@ -453,7 +482,13 @@ export function createMemoryAdapter(options = {}) {
453
482
  retryable: false,
454
483
  affected: {},
455
484
  };
456
- }, request).then((answer) => note(request.locator, 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
+ });
457
492
  },
458
493
  async history(_authorization, request) {
459
494
  return resolveScript(scripts.history, () => {
@@ -469,30 +504,38 @@ export function createMemoryAdapter(options = {}) {
469
504
  },
470
505
  async binary(_authorization, request) {
471
506
  return resolveScript(scripts.binary, () => {
472
- if (request.kind === 'reference') {
473
- return { kind: 'rejected', code: 'unscripted-binary', fields: {}, retryable: false };
474
- }
475
507
  const room = rooms.find((entry) => entry.locator === request.locator);
476
508
  if (room === undefined)
477
509
  return { kind: 'room-not-readable', locator: request.locator };
478
- const blob = room.blobs?.[request.path];
510
+ const blob = heldBlob(room, request.path);
479
511
  return blob === undefined
480
512
  ? { kind: 'rejected', code: 'file_not_found', fields: {}, retryable: false }
481
- : { kind: 'binary', blob };
513
+ : { kind: 'binary', body: blob.stream(), mediaType: blob.type };
482
514
  }, request);
483
515
  },
484
516
  async link(_authorization, request) {
485
- return resolveScript(scripts.link, () => ({ kind: 'rejected', code: 'unscripted-link', fields: {}, retryable: false }), request);
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);
486
529
  },
487
- referrerScope(referrer) {
488
- if (typeof referrer !== 'object' || referrer === null)
489
- return null;
490
- const { room, path, message } = referrer;
491
- if (typeof message === 'string')
492
- return { kind: 'conversations' };
493
- if (typeof room !== 'string')
494
- return null;
495
- return { kind: 'room', locator: room, ...(typeof path === 'string' ? { path } : {}) };
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);
496
539
  },
497
540
  async action(_authorization, request) {
498
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,EA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