@agentshouse/mdruntime 0.1.0-cdf6e063566ab → 0.1.0-cdf8ca5c0fa11

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 (192) hide show
  1. package/README.md +1 -1
  2. package/dist/acceptance.d.ts.map +1 -1
  3. package/dist/acceptance.js +30 -1
  4. package/dist/actions.d.ts.map +1 -1
  5. package/dist/actions.js +35 -7
  6. package/dist/adapter.d.ts +71 -16
  7. package/dist/adapter.d.ts.map +1 -1
  8. package/dist/attached-model.d.ts.map +1 -1
  9. package/dist/attached-model.js +2 -2
  10. package/dist/{binary.d.ts → attachment.d.ts} +8 -4
  11. package/dist/attachment.d.ts.map +1 -0
  12. package/dist/attachment.js +15 -0
  13. package/dist/authored.d.ts.map +1 -1
  14. package/dist/authored.js +2 -0
  15. package/dist/chain.d.ts +1 -1
  16. package/dist/chain.d.ts.map +1 -1
  17. package/dist/chain.js +5 -2
  18. package/dist/change.d.ts +2 -2
  19. package/dist/chat-types.js +2 -2
  20. package/dist/client.d.ts +11 -6
  21. package/dist/client.d.ts.map +1 -1
  22. package/dist/client.js +16 -15
  23. package/dist/collection.d.ts +1 -0
  24. package/dist/collection.d.ts.map +1 -1
  25. package/dist/collection.js +7 -1
  26. package/dist/compile.d.ts +2 -1
  27. package/dist/compile.d.ts.map +1 -1
  28. package/dist/compile.js +71 -39
  29. package/dist/connection.d.ts +1 -1
  30. package/dist/connection.d.ts.map +1 -1
  31. package/dist/connection.js +5 -3
  32. package/dist/conversation-live.d.ts +2 -3
  33. package/dist/conversation-live.d.ts.map +1 -1
  34. package/dist/conversation-live.js +2 -2
  35. package/dist/conversation.d.ts +13 -7
  36. package/dist/conversation.d.ts.map +1 -1
  37. package/dist/conversation.js +35 -20
  38. package/dist/declaration.js +3 -3
  39. package/dist/discovery.d.ts +1 -1
  40. package/dist/discovery.d.ts.map +1 -1
  41. package/dist/discovery.js +21 -3
  42. package/dist/download.d.ts +2 -2
  43. package/dist/download.d.ts.map +1 -1
  44. package/dist/entry.d.ts +22 -3
  45. package/dist/entry.d.ts.map +1 -1
  46. package/dist/entry.js +111 -45
  47. package/dist/figures.d.ts +1 -1
  48. package/dist/figures.d.ts.map +1 -1
  49. package/dist/figures.js +2 -2
  50. package/dist/host.d.ts +6 -2
  51. package/dist/host.d.ts.map +1 -1
  52. package/dist/host.js +51 -21
  53. package/dist/house-query.d.ts +24 -0
  54. package/dist/house-query.d.ts.map +1 -0
  55. package/dist/house-query.js +102 -0
  56. package/dist/identity.d.ts +1 -1
  57. package/dist/identity.d.ts.map +1 -1
  58. package/dist/identity.js +1 -1
  59. package/dist/index.d.ts +16 -10
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +9 -5
  62. package/dist/lifecycle.d.ts +1 -1
  63. package/dist/lifecycle.d.ts.map +1 -1
  64. package/dist/lifecycle.js +21 -13
  65. package/dist/listing.d.ts +1 -0
  66. package/dist/listing.d.ts.map +1 -1
  67. package/dist/live.d.ts +14 -0
  68. package/dist/live.d.ts.map +1 -1
  69. package/dist/live.js +29 -12
  70. package/dist/loaded.d.ts +5 -3
  71. package/dist/loaded.d.ts.map +1 -1
  72. package/dist/loaded.js +12 -6
  73. package/dist/locks.d.ts.map +1 -1
  74. package/dist/locks.js +2 -0
  75. package/dist/media.d.ts +5 -6
  76. package/dist/media.d.ts.map +1 -1
  77. package/dist/media.js +94 -25
  78. package/dist/memory.d.ts +2 -2
  79. package/dist/memory.js +9 -9
  80. package/dist/messages.d.ts +6 -1
  81. package/dist/messages.d.ts.map +1 -1
  82. package/dist/messages.js +10 -1
  83. package/dist/model.d.ts +6 -5
  84. package/dist/model.d.ts.map +1 -1
  85. package/dist/name.d.ts +0 -1
  86. package/dist/name.d.ts.map +1 -1
  87. package/dist/name.js +3 -7
  88. package/dist/online.d.ts +7 -0
  89. package/dist/online.d.ts.map +1 -0
  90. package/dist/online.js +29 -0
  91. package/dist/opened.d.ts +5 -5
  92. package/dist/opened.d.ts.map +1 -1
  93. package/dist/opened.js +2 -2
  94. package/dist/opening.d.ts.map +1 -1
  95. package/dist/opening.js +18 -2
  96. package/dist/outcome.d.ts +21 -13
  97. package/dist/outcome.d.ts.map +1 -1
  98. package/dist/outcome.js +5 -5
  99. package/dist/overlay.d.ts +19 -8
  100. package/dist/overlay.d.ts.map +1 -1
  101. package/dist/overlay.js +108 -37
  102. package/dist/parts.d.ts +3 -1
  103. package/dist/parts.d.ts.map +1 -1
  104. package/dist/parts.js +30 -7
  105. package/dist/paths.d.ts +1 -1
  106. package/dist/paths.js +1 -1
  107. package/dist/preparation.d.ts +10 -5
  108. package/dist/preparation.d.ts.map +1 -1
  109. package/dist/preparation.js +78 -48
  110. package/dist/queries.d.ts.map +1 -1
  111. package/dist/queries.js +75 -53
  112. package/dist/query.d.ts +2 -2
  113. package/dist/query.d.ts.map +1 -1
  114. package/dist/questions.d.ts.map +1 -1
  115. package/dist/questions.js +2 -1
  116. package/dist/reach.d.ts +11 -1
  117. package/dist/reach.d.ts.map +1 -1
  118. package/dist/reach.js +97 -23
  119. package/dist/readiness.d.ts +17 -4
  120. package/dist/readiness.d.ts.map +1 -1
  121. package/dist/readiness.js +17 -7
  122. package/dist/reads.d.ts.map +1 -1
  123. package/dist/reads.js +15 -4
  124. package/dist/reference-forms.d.ts +4 -0
  125. package/dist/reference-forms.d.ts.map +1 -0
  126. package/dist/reference-forms.js +74 -0
  127. package/dist/refresh.d.ts +1 -1
  128. package/dist/refresh.js +4 -4
  129. package/dist/replica.d.ts +3 -8
  130. package/dist/replica.d.ts.map +1 -1
  131. package/dist/replica.js +3 -3
  132. package/dist/room-draft.d.ts +1 -1
  133. package/dist/room-draft.d.ts.map +1 -1
  134. package/dist/room-draft.js +9 -6
  135. package/dist/room-drafts.d.ts.map +1 -1
  136. package/dist/room-drafts.js +8 -6
  137. package/dist/rows.d.ts +9 -1
  138. package/dist/rows.d.ts.map +1 -1
  139. package/dist/rows.js +18 -4
  140. package/dist/running.d.ts +5 -0
  141. package/dist/running.d.ts.map +1 -0
  142. package/dist/running.js +10 -0
  143. package/dist/runtime.d.ts +4 -2
  144. package/dist/runtime.d.ts.map +1 -1
  145. package/dist/save.d.ts +1 -0
  146. package/dist/save.d.ts.map +1 -1
  147. package/dist/save.js +6 -6
  148. package/dist/saves.d.ts +5 -5
  149. package/dist/saves.d.ts.map +1 -1
  150. package/dist/saves.js +71 -45
  151. package/dist/selector.d.ts +3 -0
  152. package/dist/selector.d.ts.map +1 -0
  153. package/dist/selector.js +22 -0
  154. package/dist/shown.d.ts.map +1 -1
  155. package/dist/shown.js +17 -4
  156. package/dist/socket/session.d.ts +4 -1
  157. package/dist/socket/session.d.ts.map +1 -1
  158. package/dist/socket/session.js +3 -0
  159. package/dist/socket.d.ts +1 -0
  160. package/dist/socket.d.ts.map +1 -1
  161. package/dist/socket.js +1 -0
  162. package/dist/source.d.ts +2 -0
  163. package/dist/source.d.ts.map +1 -1
  164. package/dist/source.js +2 -0
  165. package/dist/store/records.d.ts +15 -5
  166. package/dist/store/records.d.ts.map +1 -1
  167. package/dist/store/records.js +12 -4
  168. package/dist/store.d.ts +3 -2
  169. package/dist/store.d.ts.map +1 -1
  170. package/dist/store.js +4 -1
  171. package/dist/stored.d.ts +17 -3
  172. package/dist/stored.d.ts.map +1 -1
  173. package/dist/stored.js +138 -31
  174. package/dist/surface.d.ts +4 -2
  175. package/dist/surface.d.ts.map +1 -1
  176. package/dist/surface.js +7 -3
  177. package/dist/sync.d.ts +2 -1
  178. package/dist/sync.d.ts.map +1 -1
  179. package/dist/sync.js +26 -18
  180. package/dist/tables.d.ts +14 -2
  181. package/dist/tables.d.ts.map +1 -1
  182. package/dist/tables.js +10 -3
  183. package/dist/tallies.js +2 -2
  184. package/dist/validation.d.ts +2 -0
  185. package/dist/validation.d.ts.map +1 -1
  186. package/dist/validation.js +49 -3
  187. package/dist/wire.d.ts +14 -6
  188. package/dist/wire.d.ts.map +1 -1
  189. package/dist/wire.js +12 -11
  190. package/package.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AAQ,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAQjE;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAEjE;AAyBD,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAwKxF"}
package/dist/live.js CHANGED
@@ -15,15 +15,24 @@ export function readerOf(plan) {
15
15
  (named === null || named.has(locator)) &&
16
16
  (reached === null || reached.has(locator));
17
17
  }
18
- function affected({ plan, reads }, set) {
19
- if (set.rooms.some(reads))
18
+ export function hearerOf(plan) {
19
+ return readerOf(plan.hop === null ? plan : { ...plan, rooms: null });
20
+ }
21
+ function affected({ plan, hears }, set) {
22
+ if (set.rooms.some(hears))
20
23
  return true;
21
24
  const paths = narrowed(plan) ? new Set(plan.paths) : null;
22
- return set.documents.some(({ locator, path }) => reads(locator) && (paths === null || path === null || paths.has(path)));
25
+ return set.documents.some(({ locator, path }) => hears(locator) && (paths === null || path === null || paths.has(path)));
26
+ }
27
+ function namingMoved(entry, set) {
28
+ return (entry.awaitsFollowed &&
29
+ (set.rooms.some(entry.reads) || set.documents.some(({ locator }) => entry.reads(locator))));
30
+ }
31
+ function coverShown(cover) {
32
+ return JSON.stringify('pending' in cover ? cover : [cover.coverage, cover.follows]);
23
33
  }
24
34
  function shown(entry, held) {
25
- const cover = entry.cover(held);
26
- return JSON.stringify('pending' in cover ? cover : cover.coverage);
35
+ return coverShown(entry.cover(held));
27
36
  }
28
37
  export function createLiveQueries(run, holding) {
29
38
  const entries = new Map();
@@ -31,11 +40,13 @@ export function createLiveQueries(run, holding) {
31
40
  let recoveringNow = false;
32
41
  let recoveringAll = false;
33
42
  const recovering = new Set();
34
- function deliver(entry, next) {
43
+ function deliver(entry, next, cover) {
35
44
  const previous = entry.digest;
36
45
  entry.digest = digestOf(next);
37
46
  entry.pending = 'pending' in entry.digest ? entry.digest.pending : null;
38
- entry.covered = JSON.stringify('pending' in next.result ? next.result : next.result.coverage);
47
+ entry.awaitsFollowed =
48
+ 'pending' in next.result && next.result.pending.some(({ room }) => !entry.reads(room));
49
+ entry.covered = coverShown(cover);
39
50
  const change = previous === undefined ? null : changeOf(previous, next);
40
51
  if (change !== null) {
41
52
  for (const listener of entry.ready)
@@ -48,10 +59,10 @@ export function createLiveQueries(run, holding) {
48
59
  entry.fresh.clear();
49
60
  }
50
61
  async function delivered(entry) {
51
- const { current, ...next } = await run(entry.plan, async () => entry.cover(await holding()));
62
+ const { current, cover, ...next } = await run(entry.plan, async () => entry.cover(await holding()));
52
63
  if (closed || entry.listeners.size === 0)
53
64
  return null;
54
- deliver(entry, next);
65
+ deliver(entry, next, cover);
55
66
  return current;
56
67
  }
57
68
  function schedule(entry) {
@@ -89,7 +100,11 @@ export function createLiveQueries(run, holding) {
89
100
  }
90
101
  function pendingMoved(entry, held, rooms) {
91
102
  const { pending } = entry;
92
- if (pending === null || pending.size === 0 || entry.running || entry.fresh.size > 0) {
103
+ if (pending === null ||
104
+ pending.size === 0 ||
105
+ entry.running ||
106
+ entry.fresh.size > 0 ||
107
+ entry.awaitsFollowed) {
93
108
  return false;
94
109
  }
95
110
  const at = entry.pendingAt(held, rooms);
@@ -120,7 +135,7 @@ export function createLiveQueries(run, holding) {
120
135
  const touched = [...recovering];
121
136
  recoveringAll = false;
122
137
  recovering.clear();
123
- const reached = [...entries.values()].filter((entry) => all || touched.some(entry.reads));
138
+ const reached = [...entries.values()].filter((entry) => all || touched.some(entry.hears));
124
139
  for (const entry of reached) {
125
140
  if (entry.running)
126
141
  entry.dirty = true;
@@ -154,7 +169,7 @@ export function createLiveQueries(run, holding) {
154
169
  for (const entry of entries.values()) {
155
170
  if (!affected(entry, set))
156
171
  continue;
157
- if (entry.pending === null || entry.running) {
172
+ if (entry.pending === null || entry.running || namingMoved(entry, set)) {
158
173
  schedule(entry);
159
174
  continue;
160
175
  }
@@ -173,6 +188,7 @@ export function createLiveQueries(run, holding) {
173
188
  entry = {
174
189
  plan,
175
190
  reads: readerOf(plan),
191
+ hears: hearerOf(plan),
176
192
  cover,
177
193
  pendingAt,
178
194
  listeners: new Set(),
@@ -180,6 +196,7 @@ export function createLiveQueries(run, holding) {
180
196
  ready: new Set(),
181
197
  digest: undefined,
182
198
  pending: null,
199
+ awaitsFollowed: false,
183
200
  covered: '',
184
201
  dirty: false,
185
202
  running: false,
package/dist/loaded.d.ts CHANGED
@@ -1,5 +1,7 @@
1
- import type { BuildFile } from './client.js';
2
- export declare function parsed(file: Blob | null): Promise<unknown>;
1
+ import type { BuildFile, BuiltFile } from './client.js';
2
+ export declare function atAddress<T>(file: BuiltFile, use: (address: string) => Promise<T>): Promise<T>;
3
+ export declare function importedFile(file: BuiltFile | null): Promise<unknown>;
4
+ export declare function parsed(file: BuiltFile | null): Promise<unknown>;
3
5
  export declare function perBuild<T>(buildFile: BuildFile, key: string, make: () => Promise<T>): Promise<T>;
4
- export declare function loaded<T>(buildFile: BuildFile, name: string, read?: (file: Blob | null) => Promise<unknown>): Promise<T | null>;
6
+ export declare function loaded<T>(buildFile: BuildFile, name: string, read?: (file: BuiltFile | null) => Promise<unknown>): Promise<T | null>;
5
7
  //# sourceMappingURL=loaded.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"loaded.d.ts","sourceRoot":"","sources":["../src/loaded.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAc7C,wBAAsB,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAEhE;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAYjG;AAED,wBAAgB,MAAM,CAAC,CAAC,EACtB,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,OAAO,CAAC,OAAO,CAAY,GACvD,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAEnB"}
1
+ {"version":3,"file":"loaded.d.ts","sourceRoot":"","sources":["../src/loaded.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAIxD,wBAAsB,SAAS,CAAC,CAAC,EAC/B,IAAI,EAAE,SAAS,EACf,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GACnC,OAAO,CAAC,CAAC,CAAC,CAQZ;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAErE;AAED,wBAAsB,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAIrE;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAYjG;AAED,wBAAgB,MAAM,CAAC,CAAC,EACtB,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,KAAK,OAAO,CAAC,OAAO,CAAgB,GAChE,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAEnB"}
package/dist/loaded.js CHANGED
@@ -7,19 +7,25 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
7
7
  return path;
8
8
  };
9
9
  const holdings = new WeakMap();
10
- async function imported(file) {
11
- if (file === null)
12
- return null;
10
+ export async function atAddress(file, use) {
11
+ if (typeof file === 'string')
12
+ return use(file);
13
13
  const address = URL.createObjectURL(file);
14
14
  try {
15
- return await import(__rewriteRelativeImportExtension(address));
15
+ return await use(address);
16
16
  }
17
17
  finally {
18
18
  URL.revokeObjectURL(address);
19
19
  }
20
20
  }
21
+ export function importedFile(file) {
22
+ return file === null ? Promise.resolve(null) : atAddress(file, (address) => import(__rewriteRelativeImportExtension(address)));
23
+ }
21
24
  export async function parsed(file) {
22
- return file === null ? null : JSON.parse(await file.text());
25
+ if (file === null)
26
+ return null;
27
+ const text = typeof file === 'string' ? await (await fetch(file)).text() : await file.text();
28
+ return JSON.parse(text);
23
29
  }
24
30
  export function perBuild(buildFile, key, make) {
25
31
  let named = holdings.get(buildFile);
@@ -35,6 +41,6 @@ export function perBuild(buildFile, key, make) {
35
41
  making.catch(() => named.delete(key));
36
42
  return making;
37
43
  }
38
- export function loaded(buildFile, name, read = imported) {
44
+ export function loaded(buildFile, name, read = importedFile) {
39
45
  return perBuild(buildFile, name, () => buildFile(name).then(read));
40
46
  }
@@ -1 +1 @@
1
- {"version":3,"file":"locks.d.ts","sourceRoot":"","sources":["../src/locks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C,wBAAsB,MAAM,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAE5F;AAED,wBAAsB,WAAW,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAG1F;AAED,wBAAsB,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,iBAKzE;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,QAU9C;AAED,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAE7E"}
1
+ {"version":3,"file":"locks.d.ts","sourceRoot":"","sources":["../src/locks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C,wBAAsB,MAAM,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAE5F;AAED,wBAAsB,WAAW,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAI1F;AAED,wBAAsB,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,iBAKzE;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,QAU9C;AAED,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAE7E"}
package/dist/locks.js CHANGED
@@ -4,6 +4,8 @@ export async function locked({ store, presence }, locator) {
4
4
  return presence.locked(locator, async () => (await store.open()).offline(locator));
5
5
  }
6
6
  export async function lockedRooms({ store, presence }) {
7
+ if (!store.needed())
8
+ return [];
7
9
  const { rooms, locking } = await store.covering();
8
10
  return presence.lockedAmong(rooms, locking);
9
11
  }
package/dist/media.d.ts CHANGED
@@ -1,19 +1,18 @@
1
1
  import type { MdRuntimeClient } from './client.js';
2
- import { type DownloadAnswer, type ShownAnswer } from './outcome.js';
2
+ import { type DownloadAnswer } from './outcome.js';
3
3
  export declare const ROOM_MEDIA = "room-media";
4
4
  export declare const KEYED_MEDIA = "ahc-attachment";
5
5
  export declare const MEDIA = "room-media, ahc-attachment";
6
6
  export declare const DIAGRAM = "md-diagram";
7
7
  export declare const VIEWING = "ahc-viewer";
8
- type Show = (room: string, path: string, revision?: string) => Promise<ShownAnswer>;
9
- export type MediaAt = {
10
- readonly link: string;
11
- } | {
8
+ type RoomAt = {
12
9
  readonly room: string;
13
10
  readonly path: string;
14
11
  readonly revision: string | undefined;
15
12
  };
16
- export declare function shownBy(show: Show, client: MdRuntimeClient): MdRuntimeClient;
13
+ export type MediaAt = {
14
+ readonly link: string;
15
+ } | RoomAt;
17
16
  export declare function mediaAt(media: Element): MediaAt | null;
18
17
  export declare function mediaTag(at: MediaAt): string;
19
18
  export declare function downloadAt(client: MdRuntimeClient, at: MediaAt): Promise<DownloadAnswer>;
@@ -1 +1 @@
1
- {"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAqB,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAExF,eAAO,MAAM,UAAU,eAAe,CAAC;AAEvC,eAAO,MAAM,WAAW,mBAAmB,CAAC;AAE5C,eAAO,MAAM,KAAK,+BAAkC,CAAC;AAMrD,eAAO,MAAM,OAAO,eAAe,CAAC;AAEpC,eAAO,MAAM,OAAO,eAAe,CAAC;AAgCpC,KAAK,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;AAEpF,MAAM,MAAM,OAAO,GACf;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACzB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAI5F,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,E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AG,MAAM,CAAC;AAEzD,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,GAAG,IAAI,CAUtD;AAED,wBAAgB,QAAQ,CAAC,EAAE,EAAE,OAAO,GAAG,MAAM,CAE5C;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,eAAe,EAAE,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,CAIxF;AA0DD,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAElD;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAMlD;AA0CD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAEtE;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,GAAG,IAAI,CAyOxF"}
package/dist/media.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { isAudioType, isImageType, isVideoType } from '@agentshouse/mdmodel';
2
2
  import { loaded } from './loaded.js';
3
3
  import { downloadAttachment } from './download.js';
4
- import { blobOf, UNCERTAIN } from './outcome.js';
4
+ import { attachmentBlob, UNCERTAIN } from './outcome.js';
5
5
  export const ROOM_MEDIA = 'room-media';
6
6
  export const KEYED_MEDIA = 'ahc-attachment';
7
7
  export const MEDIA = `${ROOM_MEDIA}, ${KEYED_MEDIA}`;
@@ -25,11 +25,6 @@ const STYLE = `:host{display:block}
25
25
  [part=box]>slot{display:flex;align-items:center;justify-content:center;width:100%;height:100%;text-align:center}
26
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}
27
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}`;
28
- const shows = new WeakMap();
29
- export function shownBy(show, client) {
30
- shows.set(client, show);
31
- return client;
32
- }
33
28
  export function mediaAt(media) {
34
29
  if (media.localName === KEYED_MEDIA) {
35
30
  const link = media.getAttribute('link');
@@ -47,22 +42,42 @@ export function mediaTag(at) {
47
42
  export function downloadAt(client, at) {
48
43
  return 'link' in at
49
44
  ? downloadAttachment(client, at.link)
50
- : client.binaryFile.download(at.room, at.path, at.revision);
45
+ : client.attachment.download(at.room, at.path, at.revision);
51
46
  }
52
47
  function shownAt(client, at) {
53
48
  if (at === null)
54
49
  return null;
55
- if ('link' in at)
56
- return client.conversation.attachment(at.link);
57
- const show = shows.get(client);
58
- return show === undefined ? null : show(at.room, at.path, at.revision);
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);
59
56
  }
60
57
  function ratioOf(width, height) {
61
58
  const across = Number(width);
62
59
  const down = Number(height);
63
60
  return Number.isFinite(across) && Number.isFinite(down) && across > 0 && down > 0
64
61
  ? `${across} / ${down}`
65
- : SHAPE;
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(', ');
66
81
  }
67
82
  function refusedForGood(shown) {
68
83
  if (shown.kind === 'revoked-authorization')
@@ -88,14 +103,25 @@ export function viewable(element) {
88
103
  return false;
89
104
  return (rendered(element) || (element.shadowRoot?.querySelector('[part=box] > video') ?? null) !== null);
90
105
  }
91
- function viewed(client, opener, alone) {
92
- void loaded(client.buildFile, VIEWER).then((file) => file?.openViewer({
93
- opener,
94
- alone,
95
- download: (at) => void downloadAt(client, at),
96
- }));
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
+ });
97
116
  }
98
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
+ };
99
125
  return (event) => {
100
126
  if (event.defaultPrevented || event.detail > 1)
101
127
  return;
@@ -104,7 +130,8 @@ function pressed(client) {
104
130
  continue;
105
131
  if (viewable(node)) {
106
132
  event.preventDefault();
107
- void client.then((one) => viewed(one, node, !rendered(node)));
133
+ latest = node;
134
+ void client.then((one) => viewed(one, node, !rendered(node), taken(node)));
108
135
  return;
109
136
  }
110
137
  if (node.matches(PRESSED_ELSEWHERE))
@@ -133,6 +160,9 @@ export function defineRoomMedia(client) {
133
160
  #drawn = null;
134
161
  #loaded = false;
135
162
  #relinked = 0;
163
+ #failedAt = 0;
164
+ #own = null;
165
+ #measuring = null;
136
166
  constructor() {
137
167
  super();
138
168
  this.#box.setAttribute('part', 'box');
@@ -149,17 +179,21 @@ export function defineRoomMedia(client) {
149
179
  void this.#load();
150
180
  }, { rootMargin: NEARING });
151
181
  this.#watching.observe(this);
182
+ this.#measure();
152
183
  }
153
184
  disconnectedCallback() {
154
185
  this.#watching?.disconnect();
155
186
  this.#watching = null;
156
187
  this.#near = false;
157
188
  this.#asked += 1;
189
+ this.#measure();
158
190
  this.#show(null);
159
191
  }
160
192
  attributeChangedCallback(name, before, after) {
161
193
  if (before === after)
162
194
  return;
195
+ if (LOADING.has(name))
196
+ this.#measure();
163
197
  this.#shape();
164
198
  if (this.isConnected)
165
199
  this.#label();
@@ -169,7 +203,28 @@ export function defineRoomMedia(client) {
169
203
  void this.#load();
170
204
  }
171
205
  #shape() {
172
- this.#box.style.aspectRatio = ratioOf(this.getAttribute('width'), this.getAttribute('height'));
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);
173
228
  }
174
229
  #label() {
175
230
  const alt = this.getAttribute('alt') ?? '';
@@ -193,7 +248,7 @@ export function defineRoomMedia(client) {
193
248
  if (asked !== this.#asked)
194
249
  return;
195
250
  if (shown?.kind === 'link') {
196
- this.#draw({ url: shown.url, copy: false }, shown.mediaType);
251
+ this.#draw({ url: shown.url, copy: false }, shown.mediaType, shown.copies);
197
252
  return;
198
253
  }
199
254
  if (shown?.kind !== 'binary') {
@@ -203,13 +258,13 @@ export function defineRoomMedia(client) {
203
258
  this.#unshown(asked);
204
259
  return;
205
260
  }
206
- const copy = await blobOf(shown).catch(() => null);
261
+ const copy = await attachmentBlob(shown).catch(() => null);
207
262
  if (asked !== this.#asked)
208
263
  return;
209
264
  if (copy === null)
210
265
  this.#unshown(asked);
211
266
  else
212
- this.#draw({ url: URL.createObjectURL(copy), copy: true }, shown.mediaType);
267
+ this.#draw({ url: URL.createObjectURL(copy), copy: true }, shown.mediaType, []);
213
268
  }
214
269
  #unshown(asked) {
215
270
  this.#unreadable();
@@ -235,7 +290,7 @@ export function defineRoomMedia(client) {
235
290
  #unreadable() {
236
291
  this.#show(null, this.#fallback);
237
292
  }
238
- #draw(shown, mediaType) {
293
+ #draw(shown, mediaType, copies) {
239
294
  const tag = drawnFor(mediaType);
240
295
  if (tag === null) {
241
296
  if (shown.copy)
@@ -261,12 +316,25 @@ export function defineRoomMedia(client) {
261
316
  if (drawn !== this.#drawn)
262
317
  return;
263
318
  this.#loaded = true;
264
- this.#relinked = 0;
319
+ if (drawn instanceof HTMLImageElement)
320
+ this.#relinked = 0;
265
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
+ }
266
332
  drawn.addEventListener('error', () => this.#failed(drawn));
267
333
  }
268
334
  this.#drawn = drawn;
269
335
  this.#show(shown, drawn);
336
+ if (drawn instanceof HTMLImageElement)
337
+ offered(drawn, this.#box, copies);
270
338
  drawn.src = shown.url;
271
339
  }
272
340
  #failed(drawn) {
@@ -280,6 +348,7 @@ export function defineRoomMedia(client) {
280
348
  if (drawn instanceof HTMLMediaElement) {
281
349
  const at = drawn.currentTime;
282
350
  const playing = !drawn.paused;
351
+ this.#failedAt = at;
283
352
  drawn.addEventListener('loadedmetadata', () => {
284
353
  drawn.currentTime = at;
285
354
  if (playing)
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 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, type TypedSelection } from './adapter.js';
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
- binaryFiles?: Readonly<Record<string, BinaryFile>>;
14
+ attachments?: Readonly<Record<string, Attachment>>;
15
15
  folders?: readonly string[];
16
16
  blobs?: Readonly<Record<string, Blob>>;
17
17
  };
package/dist/memory.js CHANGED
@@ -100,11 +100,11 @@ export function createMemoryAdapter(options = {}) {
100
100
  const wanted = ordinals.get(`${locator}\u0000${target}`);
101
101
  return held !== undefined && wanted !== undefined && held >= wanted;
102
102
  }
103
- function heldBlob(room, path) {
103
+ function heldBytes(room, path) {
104
104
  return attached.get(`${room.locator}\u0000${path}`) ?? room.blobs?.[path];
105
105
  }
106
106
  function linkTo(room, path) {
107
- const blob = room === undefined ? undefined : heldBlob(room, path);
107
+ const blob = room === undefined ? undefined : heldBytes(room, path);
108
108
  if (blob === undefined)
109
109
  return UNFOUND;
110
110
  const url = linked.get(blob) ?? URL.createObjectURL(blob);
@@ -128,7 +128,7 @@ export function createMemoryAdapter(options = {}) {
128
128
  const extension = dot > 0 ? name.slice(dot) : '';
129
129
  for (let count = 1;; count += 1) {
130
130
  const path = `${ATTACHMENTS}/${count === 1 ? stem : `${stem}-${count}`}${extension}`;
131
- if (heldBlob(room, path) === undefined && room.documents?.[path] === undefined)
131
+ if (heldBytes(room, path) === undefined && room.documents?.[path] === undefined)
132
132
  return path;
133
133
  }
134
134
  }
@@ -193,7 +193,7 @@ export function createMemoryAdapter(options = {}) {
193
193
  const size = pageSize ?? paths.length;
194
194
  const taken = paths.slice(from, from + size);
195
195
  const next = from + taken.length;
196
- const targets = opening ? Object.keys(room.binaryFiles ?? {}) : [];
196
+ const targets = opening ? Object.keys(room.attachments ?? {}) : [];
197
197
  return {
198
198
  kind: 'bootstrap',
199
199
  roomVersion: room.roomVersion,
@@ -208,7 +208,7 @@ export function createMemoryAdapter(options = {}) {
208
208
  ? {}
209
209
  : { created: named(room.created, [...taken, ...targets]) }),
210
210
  changes: named(room.changes ?? {}, [...taken, ...targets]),
211
- binaryFiles: named(room.binaryFiles ?? {}, targets),
211
+ attachments: named(room.attachments ?? {}, targets),
212
212
  ...(opening && room.folders !== undefined ? { folders: room.folders } : {}),
213
213
  ...(next < paths.length ? { pageToken: taken.at(-1) } : {}),
214
214
  };
@@ -226,8 +226,8 @@ export function createMemoryAdapter(options = {}) {
226
226
  function advancement(room, from, at, whole = false) {
227
227
  const current = room.documents ?? {};
228
228
  const previous = from.documents ?? {};
229
- const currentTargets = new Set(Object.keys(room.binaryFiles ?? {}));
230
- const previousTargets = new Set(Object.keys(from.binaryFiles ?? {}));
229
+ const currentTargets = new Set(Object.keys(room.attachments ?? {}));
230
+ const previousTargets = new Set(Object.keys(from.attachments ?? {}));
231
231
  const headMoved = (path) => room.revisions?.[path] !== from.revisions?.[path] ||
232
232
  room.fileIds?.[path] !== from.fileIds?.[path] ||
233
233
  room.created?.[path] !== from.created?.[path] ||
@@ -260,7 +260,7 @@ export function createMemoryAdapter(options = {}) {
260
260
  ? {}
261
261
  : { created: named(room.created, [...taken, ...targets]) }),
262
262
  changes: named(room.changes ?? {}, [...taken, ...targets]),
263
- binaryFiles: named(room.binaryFiles ?? {}, targets),
263
+ attachments: named(room.attachments ?? {}, targets),
264
264
  ...(opening ? foldersMoved(room, from) : {}),
265
265
  removals: opening
266
266
  ? [
@@ -653,7 +653,7 @@ export function createMemoryAdapter(options = {}) {
653
653
  const room = rooms.find((entry) => entry.locator === request.locator);
654
654
  if (room === undefined)
655
655
  return { kind: 'room-not-readable', locator: request.locator };
656
- const blob = heldBlob(room, request.path);
656
+ const blob = heldBytes(room, request.path);
657
657
  return blob === undefined
658
658
  ? { kind: 'rejected', code: 'not_found', fields: {}, retryable: false }
659
659
  : { kind: 'binary', body: blob.stream(), mediaType: declaredType(blob) };
@@ -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;
@@ -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;AAIpD,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAM1D,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAQ3C,CAAC;AAQF,eAAO,MAAM,IAAI,g6DA0BqD,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,CAA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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
@@ -16,6 +16,7 @@ export const MESSAGE_TABLES = [
16
16
  const NEWEST_FIRST = 'ORDER BY position DESC, identity DESC LIMIT 1';
17
17
  const OLDEST_FIRST = 'ORDER BY position, identity LIMIT 1';
18
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')`;
19
20
  export const ROWS = `WITH chosen AS (
20
21
  SELECT listed.value AS conversation,
21
22
  (${OF_THE_ROW} AND ${ANSWERS_THE_TURN} ${NEWEST_FIRST}) AS answer,
@@ -29,8 +30,13 @@ export const ROWS = `WITH chosen AS (
29
30
  json_extract(said.message, '$.role') AS said_role,
30
31
  json_extract(said.message, '$.accepted_at') AS said_at,
31
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,
32
35
  substr(json_extract(answer.message, '$.failure'), 1, ${EXCERPT}) AS failure,
33
- (SELECT value FROM conversation_facts WHERE conversation = chosen.conversation AND name = 'openedTurn') AS opened_turn,
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,
34
40
  json_extract(opened.message, '$.source') AS opened_source,
35
41
  json_extract(opened.message, '$.sender') AS opened_sender,
36
42
  asking.identity AS asking_identity,
@@ -127,6 +133,9 @@ export function conversationRows(connection, conversations) {
127
133
  at: textOrNull(row.said_at),
128
134
  },
129
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) },
130
139
  openedTurn: textOrNull(row.opened_turn),
131
140
  failure: textOrNull(row.failure),
132
141
  opened: row.opened_source === null ? null : heldSource(row.opened_source, row.opened_sender),