@agentshouse/mdruntime 0.1.0-ca6edc1abd618 → 0.1.0-ca8707258fdde

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 (220) hide show
  1. package/README.md +2 -2
  2. package/dist/acceptance.d.ts +26 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +384 -0
  5. package/dist/adapter.d.ts +102 -70
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/attached-model.d.ts +3 -10
  8. package/dist/attached-model.d.ts.map +1 -1
  9. package/dist/attached-model.js +29 -47
  10. package/dist/bootstrap.d.ts +16 -14
  11. package/dist/bootstrap.d.ts.map +1 -1
  12. package/dist/bootstrap.js +272 -129
  13. package/dist/chain.d.ts +2 -1
  14. package/dist/chain.d.ts.map +1 -1
  15. package/dist/change.d.ts +1 -0
  16. package/dist/change.d.ts.map +1 -1
  17. package/dist/chat-types.d.ts +3 -0
  18. package/dist/chat-types.d.ts.map +1 -0
  19. package/dist/chat-types.js +2 -0
  20. package/dist/client.d.ts +20 -10
  21. package/dist/client.d.ts.map +1 -1
  22. package/dist/client.js +55 -6
  23. package/dist/collection.d.ts +7 -4
  24. package/dist/collection.d.ts.map +1 -1
  25. package/dist/collection.js +23 -17
  26. package/dist/compile.d.ts +6 -6
  27. package/dist/compile.d.ts.map +1 -1
  28. package/dist/compile.js +278 -282
  29. package/dist/connection.d.ts +22 -44
  30. package/dist/connection.d.ts.map +1 -1
  31. package/dist/connection.js +1600 -3577
  32. package/dist/context.d.ts +2 -0
  33. package/dist/context.d.ts.map +1 -0
  34. package/dist/context.js +7 -0
  35. package/dist/conversation-row.d.ts +33 -0
  36. package/dist/conversation-row.d.ts.map +1 -0
  37. package/dist/conversation-row.js +47 -0
  38. package/dist/conversation.d.ts +27 -18
  39. package/dist/conversation.d.ts.map +1 -1
  40. package/dist/conversation.js +484 -258
  41. package/dist/durability.d.ts +6 -1
  42. package/dist/durability.d.ts.map +1 -1
  43. package/dist/entry.d.ts +3 -2
  44. package/dist/entry.d.ts.map +1 -1
  45. package/dist/entry.js +18 -8
  46. package/dist/figures.d.ts +48 -0
  47. package/dist/figures.d.ts.map +1 -0
  48. package/dist/figures.js +197 -0
  49. package/dist/file.d.ts +2 -11
  50. package/dist/file.d.ts.map +1 -1
  51. package/dist/file.js +6 -4
  52. package/dist/host.d.ts +3 -7
  53. package/dist/host.d.ts.map +1 -1
  54. package/dist/host.js +29 -32
  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 +20 -10
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +6 -1
  61. package/dist/install.d.ts +86 -0
  62. package/dist/install.d.ts.map +1 -0
  63. package/dist/install.js +537 -0
  64. package/dist/job.d.ts +33 -0
  65. package/dist/job.d.ts.map +1 -0
  66. package/dist/job.js +54 -0
  67. package/dist/live.d.ts +5 -4
  68. package/dist/live.d.ts.map +1 -1
  69. package/dist/live.js +62 -20
  70. package/dist/log.d.ts +1 -0
  71. package/dist/log.d.ts.map +1 -1
  72. package/dist/media.d.ts +8 -0
  73. package/dist/media.d.ts.map +1 -0
  74. package/dist/media.js +218 -0
  75. package/dist/memory.d.ts +12 -5
  76. package/dist/memory.d.ts.map +1 -1
  77. package/dist/memory.js +216 -85
  78. package/dist/messages.d.ts +27 -3
  79. package/dist/messages.d.ts.map +1 -1
  80. package/dist/messages.js +97 -19
  81. package/dist/model.d.ts +8 -10
  82. package/dist/model.d.ts.map +1 -1
  83. package/dist/model.js +5 -17
  84. package/dist/observation.d.ts +3 -2
  85. package/dist/observation.d.ts.map +1 -1
  86. package/dist/observation.js +8 -3
  87. package/dist/outcome.d.ts +14 -5
  88. package/dist/outcome.d.ts.map +1 -1
  89. package/dist/outcome.js +19 -2
  90. package/dist/overlay.d.ts +1 -0
  91. package/dist/overlay.d.ts.map +1 -1
  92. package/dist/overlay.js +11 -0
  93. package/dist/parts.d.ts +59 -0
  94. package/dist/parts.d.ts.map +1 -0
  95. package/dist/parts.js +118 -0
  96. package/dist/paths.d.ts +1 -0
  97. package/dist/paths.d.ts.map +1 -1
  98. package/dist/paths.js +4 -0
  99. package/dist/query.d.ts +18 -207
  100. package/dist/query.d.ts.map +1 -1
  101. package/dist/query.js +3 -505
  102. package/dist/questions.d.ts +32 -0
  103. package/dist/questions.d.ts.map +1 -0
  104. package/dist/questions.js +118 -0
  105. package/dist/reach.d.ts +18 -11
  106. package/dist/reach.d.ts.map +1 -1
  107. package/dist/reach.js +206 -126
  108. package/dist/react.d.ts +5 -2
  109. package/dist/react.d.ts.map +1 -1
  110. package/dist/read.d.ts +7 -0
  111. package/dist/read.d.ts.map +1 -0
  112. package/dist/read.js +17 -0
  113. package/dist/readiness.d.ts +3 -17
  114. package/dist/readiness.d.ts.map +1 -1
  115. package/dist/readiness.js +4 -10
  116. package/dist/reads.d.ts +34 -10
  117. package/dist/reads.d.ts.map +1 -1
  118. package/dist/reads.js +114 -86
  119. package/dist/recovery.d.ts +1 -0
  120. package/dist/recovery.d.ts.map +1 -1
  121. package/dist/recovery.js +35 -1
  122. package/dist/refresh.d.ts +7 -5
  123. package/dist/refresh.d.ts.map +1 -1
  124. package/dist/refresh.js +33 -5
  125. package/dist/replica.d.ts +10 -11
  126. package/dist/replica.d.ts.map +1 -1
  127. package/dist/replica.js +52 -20
  128. package/dist/room-draft.d.ts +21 -5
  129. package/dist/room-draft.d.ts.map +1 -1
  130. package/dist/room-draft.js +98 -51
  131. package/dist/room-drafts.d.ts +29 -0
  132. package/dist/room-drafts.d.ts.map +1 -0
  133. package/dist/room-drafts.js +216 -0
  134. package/dist/rows.d.ts +18 -16
  135. package/dist/rows.d.ts.map +1 -1
  136. package/dist/rows.js +45 -153
  137. package/dist/save.d.ts +2 -0
  138. package/dist/save.d.ts.map +1 -1
  139. package/dist/save.js +22 -13
  140. package/dist/saves.d.ts +96 -0
  141. package/dist/saves.d.ts.map +1 -0
  142. package/dist/saves.js +999 -0
  143. package/dist/search.d.ts +12 -63
  144. package/dist/search.d.ts.map +1 -1
  145. package/dist/search.js +9 -52
  146. package/dist/seed.d.ts +16 -2
  147. package/dist/seed.d.ts.map +1 -1
  148. package/dist/seed.js +66 -0
  149. package/dist/shared.d.ts +0 -1
  150. package/dist/shared.d.ts.map +1 -1
  151. package/dist/shared.js +0 -10
  152. package/dist/socket/admission.d.ts +7 -0
  153. package/dist/socket/admission.d.ts.map +1 -0
  154. package/dist/socket/admission.js +39 -0
  155. package/dist/socket/answers.d.ts +6 -0
  156. package/dist/socket/answers.d.ts.map +1 -0
  157. package/dist/socket/answers.js +20 -0
  158. package/dist/socket/reads.d.ts +10 -0
  159. package/dist/socket/reads.d.ts.map +1 -0
  160. package/dist/socket/reads.js +31 -0
  161. package/dist/socket.d.ts +43 -0
  162. package/dist/socket.d.ts.map +1 -0
  163. package/dist/socket.js +96 -0
  164. package/dist/source.d.ts +61 -0
  165. package/dist/source.d.ts.map +1 -0
  166. package/dist/source.js +81 -0
  167. package/dist/status.d.ts +4 -5
  168. package/dist/status.d.ts.map +1 -1
  169. package/dist/status.js +3 -7
  170. package/dist/store/fences.d.ts +16 -0
  171. package/dist/store/fences.d.ts.map +1 -0
  172. package/dist/store/fences.js +26 -0
  173. package/dist/store/installs.d.ts +30 -0
  174. package/dist/store/installs.d.ts.map +1 -0
  175. package/dist/store/installs.js +34 -0
  176. package/dist/store/records.d.ts +212 -0
  177. package/dist/store/records.d.ts.map +1 -0
  178. package/dist/store/records.js +408 -0
  179. package/dist/store/room-held.d.ts +8 -0
  180. package/dist/store/room-held.d.ts.map +1 -0
  181. package/dist/store/room-held.js +17 -0
  182. package/dist/store/watchers.d.ts +15 -0
  183. package/dist/store/watchers.d.ts.map +1 -0
  184. package/dist/store/watchers.js +36 -0
  185. package/dist/store/writes.d.ts +24 -0
  186. package/dist/store/writes.d.ts.map +1 -0
  187. package/dist/store/writes.js +125 -0
  188. package/dist/store.d.ts +76 -158
  189. package/dist/store.d.ts.map +1 -1
  190. package/dist/store.js +117 -403
  191. package/dist/stored.d.ts +66 -55
  192. package/dist/stored.d.ts.map +1 -1
  193. package/dist/stored.js +343 -273
  194. package/dist/tables.d.ts +118 -65
  195. package/dist/tables.d.ts.map +1 -1
  196. package/dist/tables.js +199 -99
  197. package/dist/tallies.d.ts +18 -0
  198. package/dist/tallies.d.ts.map +1 -0
  199. package/dist/tallies.js +129 -0
  200. package/dist/transfer.d.ts +0 -5
  201. package/dist/transfer.d.ts.map +1 -1
  202. package/dist/validation.d.ts +3 -4
  203. package/dist/validation.d.ts.map +1 -1
  204. package/dist/validation.js +42 -100
  205. package/dist/windows.d.ts +1 -12
  206. package/dist/windows.d.ts.map +1 -1
  207. package/dist/windows.js +2 -75
  208. package/dist/wire.d.ts +23 -8
  209. package/dist/wire.d.ts.map +1 -1
  210. package/dist/wire.js +8 -2
  211. package/package.json +2 -2
  212. package/dist/fence.d.ts +0 -6
  213. package/dist/fence.d.ts.map +0 -1
  214. package/dist/fence.js +0 -10
  215. package/dist/fulltext.d.ts +0 -27
  216. package/dist/fulltext.d.ts.map +0 -1
  217. package/dist/fulltext.js +0 -368
  218. package/dist/words.d.ts +0 -19
  219. package/dist/words.d.ts.map +0 -1
  220. package/dist/words.js +0 -150
package/dist/live.js CHANGED
@@ -22,13 +22,15 @@ function affected(plan, set) {
22
22
  const paths = narrowed(plan) ? new Set(plan.paths) : null;
23
23
  return set.documents.some(({ locator, path }) => reads(plan, locator) && (paths === null || path === null || paths.has(path)));
24
24
  }
25
- function shown(entry) {
26
- const cover = entry.cover();
25
+ function shown(entry, held) {
26
+ const cover = entry.cover(held);
27
27
  return JSON.stringify('pending' in cover ? cover : cover.coverage);
28
28
  }
29
- export function createLiveQueries(run) {
29
+ export function createLiveQueries(run, holding) {
30
30
  const entries = new Map();
31
31
  let closed = false;
32
+ let recovering = false;
33
+ let recoverAgain = false;
32
34
  function deliver(entry, next) {
33
35
  const previous = entry.digest;
34
36
  entry.digest = digestOf(next);
@@ -38,12 +40,19 @@ export function createLiveQueries(run) {
38
40
  for (const listener of entry.ready)
39
41
  listener(change);
40
42
  }
41
- for (const listener of entry.fresh) {
43
+ for (const listener of entry.fresh.keys()) {
42
44
  entry.ready.add(listener);
43
45
  listener(next);
44
46
  }
45
47
  entry.fresh.clear();
46
48
  }
49
+ async function delivered(entry) {
50
+ const { current, ...next } = await run(entry.plan, async () => entry.cover(await holding()));
51
+ if (closed || entry.listeners.size === 0)
52
+ return null;
53
+ deliver(entry, next);
54
+ return current;
55
+ }
47
56
  function schedule(entry) {
48
57
  if (closed || entry.listeners.size === 0)
49
58
  return;
@@ -56,22 +65,62 @@ export function createLiveQueries(run) {
56
65
  try {
57
66
  for (;;) {
58
67
  entry.dirty = false;
59
- const { current, ...next } = await run(entry.plan, entry.cover);
60
- if (closed || entry.listeners.size === 0)
68
+ const current = await delivered(entry);
69
+ if (current === null)
61
70
  return;
62
- deliver(entry, next);
63
- if (!(entry.dirty && !current()) && shown(entry) === entry.covered)
71
+ const held = await holding();
72
+ if (entry.fresh.size > 0 || (entry.dirty && !current()))
73
+ continue;
74
+ if (shown(entry, held) === entry.covered)
64
75
  break;
65
76
  }
66
77
  }
67
- catch {
78
+ catch (error) {
68
79
  entry.dirty = false;
80
+ const unanswered = [...entry.fresh.values()];
81
+ entry.fresh.clear();
82
+ for (const failed of unanswered)
83
+ failed(error);
69
84
  }
70
85
  finally {
71
86
  entry.running = false;
72
87
  }
73
88
  })();
74
89
  }
90
+ function recovered() {
91
+ if (recovering) {
92
+ recoverAgain = true;
93
+ return;
94
+ }
95
+ recovering = true;
96
+ void (async () => {
97
+ try {
98
+ do {
99
+ recoverAgain = false;
100
+ for (const entry of entries.values()) {
101
+ if (entry.running)
102
+ entry.dirty = true;
103
+ }
104
+ const waiting = [...entries.values()].filter((entry) => !entry.running);
105
+ if (waiting.length === 0 || closed)
106
+ continue;
107
+ const held = await holding();
108
+ for (const entry of waiting) {
109
+ if (entry.running)
110
+ continue;
111
+ if (entry.digest === undefined || shown(entry, held) !== entry.covered)
112
+ schedule(entry);
113
+ }
114
+ } while (recoverAgain && !closed);
115
+ }
116
+ catch {
117
+ recoverAgain = false;
118
+ }
119
+ finally {
120
+ recovering = false;
121
+ }
122
+ })();
123
+ }
75
124
  return {
76
125
  touched(set) {
77
126
  for (const entry of entries.values()) {
@@ -79,22 +128,15 @@ export function createLiveQueries(run) {
79
128
  schedule(entry);
80
129
  }
81
130
  },
82
- recover() {
83
- for (const entry of entries.values()) {
84
- if (entry.running)
85
- continue;
86
- if (entry.digest === undefined || shown(entry) !== entry.covered)
87
- schedule(entry);
88
- }
89
- },
90
- watch(plan, identity, cover, listener) {
131
+ recover: recovered,
132
+ watch(plan, identity, cover, listener, failed) {
91
133
  let entry = entries.get(identity);
92
134
  if (entry === undefined) {
93
135
  entry = {
94
136
  plan,
95
137
  cover,
96
138
  listeners: new Set(),
97
- fresh: new Set(),
139
+ fresh: new Map(),
98
140
  ready: new Set(),
99
141
  digest: undefined,
100
142
  covered: '',
@@ -105,7 +147,7 @@ export function createLiveQueries(run) {
105
147
  }
106
148
  const held = entry;
107
149
  held.listeners.add(listener);
108
- held.fresh.add(listener);
150
+ held.fresh.set(listener, failed);
109
151
  schedule(held);
110
152
  return () => {
111
153
  held.listeners.delete(listener);
package/dist/log.d.ts CHANGED
@@ -2,4 +2,5 @@ export declare function createLog(): {
2
2
  record(event: string): void;
3
3
  export(): string;
4
4
  };
5
+ export type Log = ReturnType<typeof createLog>;
5
6
  //# sourceMappingURL=log.d.ts.map
package/dist/log.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAEA,wBAAgB,SAAS;IAGrB,MAAM,QAAQ,MAAM;IAIpB,MAAM;EAIT"}
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAEA,wBAAgB,SAAS;IAGrB,MAAM,QAAQ,MAAM;IAIpB,MAAM;EAIT;AAED,MAAM,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC"}
@@ -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,EAAa,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3D,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,CA0LN"}
package/dist/media.js ADDED
@@ -0,0 +1,218 @@
1
+ import { UNCERTAIN } from './outcome.js';
2
+ export const ROOM_MEDIA = 'room-media';
3
+ const ATTRIBUTES = ['room', 'path', 'revision', 'width', 'height', 'alt'];
4
+ const LOADING = new Set(['room', 'path', 'revision']);
5
+ const NEARING = '600px 0px';
6
+ const RELINKS = 2;
7
+ // 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.
8
+ const UNSHOWN_MS = 3_000;
9
+ const SHAPE = '16 / 9';
10
+ const STYLE = `:host{display:block}
11
+ [part=box]{position:relative;overflow:hidden}
12
+ [part=box]>img,[part=box]>video,[part=box]>audio{display:block;width:100%;height:100%;object-fit:contain}
13
+ [part=box]>slot{display:flex;align-items:center;justify-content:center;width:100%;height:100%;text-align:center}`;
14
+ const shows = new WeakMap();
15
+ export function shownBy(show, client) {
16
+ shows.set(client, show);
17
+ return client;
18
+ }
19
+ function ratioOf(width, height) {
20
+ const across = Number(width);
21
+ const down = Number(height);
22
+ return Number.isFinite(across) && Number.isFinite(down) && across > 0 && down > 0
23
+ ? `${across} / ${down}`
24
+ : SHAPE;
25
+ }
26
+ function refusedForGood(shown) {
27
+ if (shown.kind === 'revoked-authorization')
28
+ return true;
29
+ return (shown.kind === 'rejected' || shown.kind === 'scoped-refusal') && !shown.retryable;
30
+ }
31
+ function drawnFor(mediaType) {
32
+ if (mediaType.startsWith('image/'))
33
+ return 'img';
34
+ if (mediaType.startsWith('video/'))
35
+ return 'video';
36
+ if (mediaType.startsWith('audio/'))
37
+ return 'audio';
38
+ return null;
39
+ }
40
+ export function defineRoomMedia(client, registry = customElements) {
41
+ if (registry.get(ROOM_MEDIA) !== undefined)
42
+ return;
43
+ const connected = Promise.resolve(client);
44
+ class RoomMedia extends HTMLElement {
45
+ static observedAttributes = ATTRIBUTES;
46
+ #root = this.attachShadow({ mode: 'open' });
47
+ #box = document.createElement('div');
48
+ #fallback = document.createElement('slot');
49
+ #watching = null;
50
+ #near = false;
51
+ #asked = 0;
52
+ #shown = null;
53
+ #drawn = null;
54
+ #loaded = false;
55
+ #relinked = 0;
56
+ constructor() {
57
+ super();
58
+ this.#box.setAttribute('part', 'box');
59
+ this.#root.append(Object.assign(document.createElement('style'), { textContent: STYLE }), this.#box);
60
+ this.#shape();
61
+ }
62
+ connectedCallback() {
63
+ this.#label();
64
+ this.#watching ??= new IntersectionObserver((seen) => {
65
+ if (!seen.some((entry) => entry.isIntersecting) || this.#near)
66
+ return;
67
+ this.#near = true;
68
+ void this.#load();
69
+ }, { rootMargin: NEARING });
70
+ this.#watching.observe(this);
71
+ }
72
+ disconnectedCallback() {
73
+ this.#watching?.disconnect();
74
+ this.#watching = null;
75
+ this.#near = false;
76
+ this.#asked += 1;
77
+ this.#show(null);
78
+ }
79
+ attributeChangedCallback(name, before, after) {
80
+ if (before === after)
81
+ return;
82
+ this.#shape();
83
+ if (this.isConnected)
84
+ this.#label();
85
+ if (!LOADING.has(name) || !this.#near)
86
+ return;
87
+ this.#relinked = 0;
88
+ void this.#load();
89
+ }
90
+ #shape() {
91
+ this.#box.style.aspectRatio = ratioOf(this.getAttribute('width'), this.getAttribute('height'));
92
+ }
93
+ #label() {
94
+ const alt = this.getAttribute('alt') ?? '';
95
+ const drawn = this.#drawn;
96
+ if (drawn instanceof HTMLMediaElement) {
97
+ this.removeAttribute('role');
98
+ this.removeAttribute('aria-label');
99
+ drawn.setAttribute('aria-label', alt);
100
+ return;
101
+ }
102
+ this.setAttribute('role', 'img');
103
+ this.setAttribute('aria-label', alt);
104
+ if (drawn !== null)
105
+ drawn.alt = '';
106
+ }
107
+ async #load() {
108
+ const asked = (this.#asked += 1);
109
+ this.#loaded = false;
110
+ const room = this.getAttribute('room');
111
+ const path = this.getAttribute('path');
112
+ const revision = this.getAttribute('revision') ?? undefined;
113
+ if (room === null || path === null) {
114
+ this.#unreadable();
115
+ return;
116
+ }
117
+ const show = shows.get(await connected);
118
+ const shown = show === undefined ? null : await show(room, path, revision).catch(() => UNCERTAIN);
119
+ if (asked !== this.#asked)
120
+ return;
121
+ if (shown?.kind === 'link') {
122
+ this.#draw({ url: shown.url, copy: false }, shown.mediaType);
123
+ return;
124
+ }
125
+ if (shown?.kind !== 'binary') {
126
+ if (shown === null || refusedForGood(shown))
127
+ this.#unreadable();
128
+ else
129
+ this.#unshown(asked);
130
+ return;
131
+ }
132
+ const copy = await new Response(shown.stream, {
133
+ headers: { 'content-type': shown.mediaType },
134
+ })
135
+ .blob()
136
+ .catch(() => null);
137
+ if (asked !== this.#asked)
138
+ return;
139
+ if (copy === null)
140
+ this.#unshown(asked);
141
+ else
142
+ this.#draw({ url: URL.createObjectURL(copy), copy: true }, shown.mediaType);
143
+ }
144
+ #unshown(asked) {
145
+ this.#unreadable();
146
+ setTimeout(() => {
147
+ if (asked === this.#asked && this.#near)
148
+ void this.#load();
149
+ }, UNSHOWN_MS);
150
+ }
151
+ #show(shown, content = null) {
152
+ if (this.#shown?.copy === true)
153
+ URL.revokeObjectURL(this.#shown.url);
154
+ this.#shown = shown;
155
+ if (content !== this.#drawn)
156
+ this.#drawn = null;
157
+ if (content === null)
158
+ this.#box.replaceChildren();
159
+ else if (content.parentNode !== this.#box)
160
+ this.#box.replaceChildren(content);
161
+ this.#label();
162
+ }
163
+ #unreadable() {
164
+ this.#show(null, this.#fallback);
165
+ }
166
+ #draw(shown, mediaType) {
167
+ const tag = drawnFor(mediaType);
168
+ if (tag === null) {
169
+ if (shown.copy)
170
+ URL.revokeObjectURL(shown.url);
171
+ this.#unreadable();
172
+ return;
173
+ }
174
+ const kept = this.#drawn?.localName === tag ? this.#drawn : null;
175
+ const drawn = kept ?? document.createElement(tag);
176
+ if (kept === null) {
177
+ if (drawn instanceof HTMLImageElement)
178
+ drawn.decoding = 'async';
179
+ if (drawn instanceof HTMLMediaElement) {
180
+ drawn.controls = true;
181
+ drawn.preload = 'metadata';
182
+ if (drawn instanceof HTMLVideoElement)
183
+ drawn.playsInline = true;
184
+ }
185
+ drawn.addEventListener(drawn instanceof HTMLImageElement ? 'load' : 'loadedmetadata', () => {
186
+ if (drawn !== this.#drawn)
187
+ return;
188
+ this.#loaded = true;
189
+ this.#relinked = 0;
190
+ });
191
+ drawn.addEventListener('error', () => this.#failed(drawn));
192
+ }
193
+ this.#drawn = drawn;
194
+ this.#show(shown, drawn);
195
+ drawn.src = shown.url;
196
+ }
197
+ #failed(drawn) {
198
+ if (drawn !== this.#drawn)
199
+ return;
200
+ if (this.#shown?.copy !== false || !this.#loaded || this.#relinked >= RELINKS) {
201
+ this.#unreadable();
202
+ return;
203
+ }
204
+ this.#relinked += 1;
205
+ if (drawn instanceof HTMLMediaElement) {
206
+ const at = drawn.currentTime;
207
+ const playing = !drawn.paused;
208
+ drawn.addEventListener('loadedmetadata', () => {
209
+ drawn.currentTime = at;
210
+ if (playing)
211
+ void drawn.play().catch(() => undefined);
212
+ }, { once: true });
213
+ }
214
+ void this.#load();
215
+ }
216
+ }
217
+ registry.define(ROOM_MEDIA, RoomMedia);
218
+ }
package/dist/memory.d.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  import type { ModelResult } from './model.js';
2
- import { type AcceptedMessage, type ActionResult, type Adapter, type BinaryFile, type Capability, type ConversationAction, type ConversationEvent, type DiscoveryScope, type DiscoveredRoom, type HeadChange, type ListedConversation, type Member, type ProviderLimit, type Retention, type ServiceMode } from './adapter.js';
2
+ import { type AcceptedMessage, type ActionResult, type Adapter, type BinaryFile, type Capability, type ConversationAction, type ConversationEvent, type DiscoveredRoom, type SavedFacts, type HeadChange, type ListedAgent, type ListedConversation, type Member, type ProviderLimit, type Retention, type ServiceMode, type TypedPath } from './adapter.js';
3
3
  export type MemoryRoom = DiscoveredRoom & {
4
4
  model?: ModelResult;
5
5
  documents?: Readonly<Record<string, string>>;
6
+ facts?: Readonly<Record<string, SavedFacts>>;
6
7
  revisions?: Readonly<Record<string, string>>;
7
8
  fileIds?: Readonly<Record<string, string>>;
9
+ created?: Readonly<Record<string, string>>;
8
10
  changes?: Readonly<Record<string, HeadChange>>;
9
11
  binaryFiles?: Readonly<Record<string, BinaryFile>>;
10
12
  folders?: readonly string[];
@@ -12,13 +14,14 @@ export type MemoryRoom = DiscoveredRoom & {
12
14
  };
13
15
  export type MemoryConversation = {
14
16
  conversation: string;
15
- listed?: Omit<ListedConversation, 'conversation'>;
17
+ listed?: Omit<ListedConversation, 'conversation' | 'newest'>;
16
18
  messages?: readonly AcceptedMessage[];
17
- outcomes?: Partial<Record<ConversationAction, ActionResult>>;
19
+ outcomes?: Partial<Record<ConversationAction | 'history', ActionResult>>;
18
20
  };
19
21
  export type MemoryAdapterOptions = {
20
22
  rooms?: readonly MemoryRoom[];
21
23
  conversations?: readonly MemoryConversation[];
24
+ agents?: readonly ListedAgent[];
22
25
  historyPageSize?: number;
23
26
  pageSize?: number;
24
27
  capabilities?: readonly Capability[];
@@ -26,10 +29,12 @@ export type MemoryAdapterOptions = {
26
29
  retention?: Retention;
27
30
  member?: Member;
28
31
  unopened?: boolean;
29
- exhaustiveDiscovery?: true;
30
32
  roomTypes?: string;
33
+ typedPaths?: readonly TypedPath[];
31
34
  };
32
35
  export type MemoryAdapter = Adapter & {
36
+ discover: NonNullable<Adapter['discover']>;
37
+ refresh: NonNullable<Adapter['refresh']>;
33
38
  setRooms(rooms: readonly MemoryRoom[]): void;
34
39
  setConversations(conversations: readonly MemoryConversation[]): void;
35
40
  script(operation: keyof Adapter, answer: unknown): void;
@@ -37,17 +42,19 @@ export type MemoryAdapter = Adapter & {
37
42
  close(closing?: {
38
43
  revoked?: boolean;
39
44
  lost?: boolean;
45
+ authorityChanged?: boolean;
40
46
  }): void;
41
47
  expire(locators: readonly string[]): void;
42
48
  notifyRoomVersion(notification: {
43
49
  locator: string;
44
50
  roomVersion: string;
45
51
  }): void;
46
- notifyAuthorityChanged(scope?: DiscoveryScope): void;
52
+ notifyAuthorityChanged(locators?: readonly string[]): void;
47
53
  notifyConversation(event: ConversationEvent): void;
48
54
  notifyServiceMode(mode: ServiceMode): void;
49
55
  heldRooms(): readonly string[];
50
56
  replicatedConversations(): readonly string[];
57
+ heldConversationCursor(): string | null;
51
58
  };
52
59
  export declare function createMemoryAdapter(options?: MemoryAdapterOptions): MemoryAdapter;
53
60
  //# sourceMappingURL=memory.d.ts.map
@@ -1 +1 @@
1
- {"version":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