@agentshouse/mdruntime 0.1.0-ccad597a8a1f0 → 0.1.0-ccae62c0cab02

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 (241) hide show
  1. package/README.md +9 -9
  2. package/dist/acceptance.d.ts.map +1 -1
  3. package/dist/acceptance.js +32 -3
  4. package/dist/actions.d.ts.map +1 -1
  5. package/dist/actions.js +62 -19
  6. package/dist/adapter.d.ts +176 -21
  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 +88 -0
  14. package/dist/authored.d.ts.map +1 -0
  15. package/dist/authored.js +345 -0
  16. package/dist/chain.d.ts +1 -1
  17. package/dist/chain.d.ts.map +1 -1
  18. package/dist/chain.js +5 -2
  19. package/dist/change.d.ts +6 -2
  20. package/dist/change.d.ts.map +1 -1
  21. package/dist/change.js +3 -0
  22. package/dist/chat-types.js +2 -2
  23. package/dist/client.d.ts +23 -8
  24. package/dist/client.d.ts.map +1 -1
  25. package/dist/client.js +25 -52
  26. package/dist/collection.d.ts +3 -1
  27. package/dist/collection.d.ts.map +1 -1
  28. package/dist/collection.js +16 -9
  29. package/dist/column.d.ts +5 -0
  30. package/dist/column.d.ts.map +1 -0
  31. package/dist/column.js +9 -0
  32. package/dist/compile.d.ts +2 -1
  33. package/dist/compile.d.ts.map +1 -1
  34. package/dist/compile.js +71 -39
  35. package/dist/connection.d.ts +1 -1
  36. package/dist/connection.d.ts.map +1 -1
  37. package/dist/connection.js +11 -4
  38. package/dist/context.d.ts.map +1 -1
  39. package/dist/context.js +1 -1
  40. package/dist/conversation-live.d.ts +3 -3
  41. package/dist/conversation-live.d.ts.map +1 -1
  42. package/dist/conversation-live.js +4 -3
  43. package/dist/conversation-row.d.ts +21 -1
  44. package/dist/conversation-row.d.ts.map +1 -1
  45. package/dist/conversation-row.js +35 -8
  46. package/dist/conversation.d.ts +19 -7
  47. package/dist/conversation.d.ts.map +1 -1
  48. package/dist/conversation.js +74 -51
  49. package/dist/declaration.js +3 -3
  50. package/dist/discovery.d.ts +3 -1
  51. package/dist/discovery.d.ts.map +1 -1
  52. package/dist/discovery.js +30 -5
  53. package/dist/download.d.ts +6 -0
  54. package/dist/download.d.ts.map +1 -0
  55. package/dist/download.js +42 -0
  56. package/dist/durability.d.ts +1 -0
  57. package/dist/durability.d.ts.map +1 -1
  58. package/dist/durability.js +3 -0
  59. package/dist/entry.d.ts +26 -1
  60. package/dist/entry.d.ts.map +1 -1
  61. package/dist/entry.js +126 -36
  62. package/dist/failure.d.ts.map +1 -1
  63. package/dist/failure.js +3 -1
  64. package/dist/figures.d.ts +1 -1
  65. package/dist/figures.d.ts.map +1 -1
  66. package/dist/figures.js +2 -2
  67. package/dist/file.d.ts +1 -1
  68. package/dist/file.d.ts.map +1 -1
  69. package/dist/file.js +1 -1
  70. package/dist/host.d.ts +6 -2
  71. package/dist/host.d.ts.map +1 -1
  72. package/dist/host.js +57 -21
  73. package/dist/house-query.d.ts +24 -0
  74. package/dist/house-query.d.ts.map +1 -0
  75. package/dist/house-query.js +102 -0
  76. package/dist/identity.d.ts +1 -1
  77. package/dist/identity.d.ts.map +1 -1
  78. package/dist/identity.js +1 -1
  79. package/dist/index.d.ts +20 -12
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +10 -5
  82. package/dist/lifecycle.d.ts +1 -1
  83. package/dist/lifecycle.d.ts.map +1 -1
  84. package/dist/lifecycle.js +30 -16
  85. package/dist/linked-file.d.ts +7 -0
  86. package/dist/linked-file.d.ts.map +1 -0
  87. package/dist/linked-file.js +16 -0
  88. package/dist/listing.d.ts +20 -12
  89. package/dist/listing.d.ts.map +1 -1
  90. package/dist/listing.js +33 -17
  91. package/dist/live.d.ts +14 -0
  92. package/dist/live.d.ts.map +1 -1
  93. package/dist/live.js +29 -12
  94. package/dist/loaded.d.ts +7 -0
  95. package/dist/loaded.d.ts.map +1 -0
  96. package/dist/loaded.js +46 -0
  97. package/dist/locks.d.ts.map +1 -1
  98. package/dist/locks.js +2 -0
  99. package/dist/media.d.ts +19 -3
  100. package/dist/media.d.ts.map +1 -1
  101. package/dist/media.js +177 -27
  102. package/dist/memory.d.ts +4 -2
  103. package/dist/memory.d.ts.map +1 -1
  104. package/dist/memory.js +48 -16
  105. package/dist/messages.d.ts +10 -1
  106. package/dist/messages.d.ts.map +1 -1
  107. package/dist/messages.js +25 -7
  108. package/dist/modal.d.ts +2 -0
  109. package/dist/modal.d.ts.map +1 -0
  110. package/dist/modal.js +11 -0
  111. package/dist/model.d.ts +10 -7
  112. package/dist/model.d.ts.map +1 -1
  113. package/dist/model.js +7 -1
  114. package/dist/name.d.ts +0 -1
  115. package/dist/name.d.ts.map +1 -1
  116. package/dist/name.js +3 -7
  117. package/dist/observation.d.ts +2 -0
  118. package/dist/observation.d.ts.map +1 -1
  119. package/dist/observation.js +42 -9
  120. package/dist/online.d.ts +7 -0
  121. package/dist/online.d.ts.map +1 -0
  122. package/dist/online.js +29 -0
  123. package/dist/opened.d.ts +5 -5
  124. package/dist/opened.d.ts.map +1 -1
  125. package/dist/opened.js +2 -2
  126. package/dist/opening.d.ts.map +1 -1
  127. package/dist/opening.js +20 -2
  128. package/dist/outcome.d.ts +27 -14
  129. package/dist/outcome.d.ts.map +1 -1
  130. package/dist/outcome.js +14 -5
  131. package/dist/overlay.d.ts +20 -9
  132. package/dist/overlay.d.ts.map +1 -1
  133. package/dist/overlay.js +108 -39
  134. package/dist/parts.d.ts +4 -1
  135. package/dist/parts.d.ts.map +1 -1
  136. package/dist/parts.js +30 -7
  137. package/dist/paths.d.ts +1 -1
  138. package/dist/paths.js +1 -1
  139. package/dist/preparation.d.ts +10 -5
  140. package/dist/preparation.d.ts.map +1 -1
  141. package/dist/preparation.js +78 -48
  142. package/dist/queries.d.ts.map +1 -1
  143. package/dist/queries.js +75 -53
  144. package/dist/query.d.ts +2 -2
  145. package/dist/query.d.ts.map +1 -1
  146. package/dist/questions.d.ts +1 -0
  147. package/dist/questions.d.ts.map +1 -1
  148. package/dist/questions.js +3 -1
  149. package/dist/queue.d.ts +1 -1
  150. package/dist/queue.d.ts.map +1 -1
  151. package/dist/queue.js +55 -23
  152. package/dist/reach.d.ts +13 -3
  153. package/dist/reach.d.ts.map +1 -1
  154. package/dist/reach.js +130 -25
  155. package/dist/react.d.ts +11 -1
  156. package/dist/react.d.ts.map +1 -1
  157. package/dist/readiness.d.ts +17 -4
  158. package/dist/readiness.d.ts.map +1 -1
  159. package/dist/readiness.js +17 -7
  160. package/dist/reads.d.ts +1 -1
  161. package/dist/reads.d.ts.map +1 -1
  162. package/dist/reads.js +17 -6
  163. package/dist/recovery.d.ts +1 -0
  164. package/dist/recovery.d.ts.map +1 -1
  165. package/dist/recovery.js +2 -1
  166. package/dist/refresh.d.ts +1 -1
  167. package/dist/refresh.js +4 -4
  168. package/dist/replica.d.ts +3 -8
  169. package/dist/replica.d.ts.map +1 -1
  170. package/dist/replica.js +5 -5
  171. package/dist/room-draft.d.ts +29 -4
  172. package/dist/room-draft.d.ts.map +1 -1
  173. package/dist/room-draft.js +229 -8
  174. package/dist/room-drafts.d.ts.map +1 -1
  175. package/dist/room-drafts.js +12 -7
  176. package/dist/room-list.d.ts +10 -0
  177. package/dist/room-list.d.ts.map +1 -0
  178. package/dist/room-list.js +47 -0
  179. package/dist/rows.d.ts +9 -2
  180. package/dist/rows.d.ts.map +1 -1
  181. package/dist/rows.js +19 -5
  182. package/dist/run-tables.d.ts +25 -0
  183. package/dist/run-tables.d.ts.map +1 -0
  184. package/dist/run-tables.js +98 -0
  185. package/dist/running.d.ts +5 -0
  186. package/dist/running.d.ts.map +1 -0
  187. package/dist/running.js +10 -0
  188. package/dist/runs.d.ts +27 -0
  189. package/dist/runs.d.ts.map +1 -0
  190. package/dist/runs.js +92 -0
  191. package/dist/runtime.d.ts +6 -3
  192. package/dist/runtime.d.ts.map +1 -1
  193. package/dist/save.d.ts +1 -0
  194. package/dist/save.d.ts.map +1 -1
  195. package/dist/save.js +29 -91
  196. package/dist/saves.d.ts +7 -5
  197. package/dist/saves.d.ts.map +1 -1
  198. package/dist/saves.js +107 -52
  199. package/dist/selector.d.ts +3 -0
  200. package/dist/selector.d.ts.map +1 -0
  201. package/dist/selector.js +22 -0
  202. package/dist/shown.d.ts +3 -1
  203. package/dist/shown.d.ts.map +1 -1
  204. package/dist/shown.js +32 -14
  205. package/dist/socket/session.d.ts +4 -1
  206. package/dist/socket/session.d.ts.map +1 -1
  207. package/dist/socket/session.js +3 -0
  208. package/dist/socket.d.ts +4 -1
  209. package/dist/socket.d.ts.map +1 -1
  210. package/dist/socket.js +8 -0
  211. package/dist/source.d.ts +42 -0
  212. package/dist/source.d.ts.map +1 -1
  213. package/dist/source.js +76 -9
  214. package/dist/store/records.d.ts +22 -5
  215. package/dist/store/records.d.ts.map +1 -1
  216. package/dist/store/records.js +14 -4
  217. package/dist/store.d.ts +9 -5
  218. package/dist/store.d.ts.map +1 -1
  219. package/dist/store.js +7 -4
  220. package/dist/stored.d.ts +17 -3
  221. package/dist/stored.d.ts.map +1 -1
  222. package/dist/stored.js +139 -35
  223. package/dist/surface.d.ts +18 -7
  224. package/dist/surface.d.ts.map +1 -1
  225. package/dist/surface.js +51 -15
  226. package/dist/sync.d.ts +4 -2
  227. package/dist/sync.d.ts.map +1 -1
  228. package/dist/sync.js +45 -23
  229. package/dist/tables.d.ts +28 -47
  230. package/dist/tables.d.ts.map +1 -1
  231. package/dist/tables.js +83 -321
  232. package/dist/tallies.js +2 -2
  233. package/dist/validation.d.ts +2 -0
  234. package/dist/validation.d.ts.map +1 -1
  235. package/dist/validation.js +49 -3
  236. package/dist/wire.d.ts +29 -6
  237. package/dist/wire.d.ts.map +1 -1
  238. package/dist/wire.js +18 -11
  239. package/package.json +4 -4
  240. package/dist/binary.d.ts.map +0 -1
  241. package/dist/binary.js +0 -8
@@ -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 (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'house' AND json_extract(message, '$.source.kind') = 'instructions_proposal' AND json_extract(message, '$.source.state') = 'waiting' ORDER BY position DESC, identity DESC LIMIT 1) AS proposing\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 json_extract(proposing.message, '$.source') AS proposing_source,\n json_extract(proposing.message, '$.accepted_at') AS proposing_at\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\n LEFT JOIN conversation_messages proposing ON proposing.id = chosen.proposing";
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;
@@ -31,6 +36,10 @@ export type HeldRow = {
31
36
  readonly text: string;
32
37
  readonly at: string | null;
33
38
  }) | null;
39
+ readonly proposing: {
40
+ readonly source: unknown;
41
+ readonly at: string | null;
42
+ } | null;
34
43
  };
35
44
  export type ConversationFact = 'openedTurn' | 'dismissedSuggestion';
36
45
  export type HeldFact = {
@@ -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;AAGpD,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,IA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BAAiB,CAC/B,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,GACtC,gBAAgB,EAAE,CA0BpB;AAED,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,iBAAiB,GAClD,IAAI,CAsBN;AAmBD,wBAAgB,aAAa,CAC3B,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,EACxC,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,aAAa,CAWf;AAED,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,MAAM,CAOR;AAaD,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,SAAS,MAAM,EAAE,GAC/B,OAAO,EAAE,CAoCX;AAED,wBAAgB,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAO/F;AAED,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,QAAQ,EAAE,CAMpE;AAED,wBAAgB,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,QAAQ,GAAG,IAAI,CAM9F;AAED,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAEnE"}
package/dist/messages.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import { sql } from '@agentshouse/mdmodel';
2
+ import { text } from './column.js';
2
3
  import { EXCERPT } from './read.js';
3
4
  import { tablesOf } from './stored.js';
4
5
  const SAID_BY_HOUSE = `json_extract(message, '$.role') = 'house'`;
5
6
  const ANSWERS_THE_TURN = `json_extract(message, '$.role') = 'assistant'`;
7
+ const WAITING_PROPOSAL = `json_extract(message, '$.source.kind') = 'instructions_proposal' AND json_extract(message, '$.source.state') = 'waiting'`;
6
8
  export const MESSAGE_TABLES = [
7
9
  'CREATE TABLE conversation_reads (conversation TEXT PRIMARY KEY, read TEXT, partial INTEGER NOT NULL) WITHOUT ROWID',
8
10
  'CREATE TABLE conversation_messages (id INTEGER PRIMARY KEY, conversation TEXT NOT NULL, identity TEXT NOT NULL, turn TEXT NOT NULL, position TEXT NOT NULL, change TEXT NOT NULL, message TEXT NOT NULL, text TEXT NOT NULL)',
@@ -15,12 +17,14 @@ export const MESSAGE_TABLES = [
15
17
  const NEWEST_FIRST = 'ORDER BY position DESC, identity DESC LIMIT 1';
16
18
  const OLDEST_FIRST = 'ORDER BY position, identity LIMIT 1';
17
19
  const OF_THE_ROW = 'SELECT id FROM conversation_messages WHERE conversation = listed.value';
20
+ const READ_UNTIL = `(SELECT julianday(json_extract(value, '$')) FROM replica_facts WHERE name = 'readUntil')`;
18
21
  export const ROWS = `WITH chosen AS (
19
22
  SELECT listed.value AS conversation,
20
23
  (${OF_THE_ROW} AND ${ANSWERS_THE_TURN} ${NEWEST_FIRST}) AS answer,
21
24
  (${OF_THE_ROW} AND text <> '' ${NEWEST_FIRST}) AS said,
22
25
  (${OF_THE_ROW} AND ${SAID_BY_HOUSE} ${OLDEST_FIRST}) AS opened,
23
- (${OF_THE_ROW} AND ${SAID_BY_HOUSE} AND json_extract(message, '$.waiting') = 1 ${OLDEST_FIRST}) AS asking
26
+ (${OF_THE_ROW} AND ${SAID_BY_HOUSE} AND json_extract(message, '$.waiting') = 1 ${OLDEST_FIRST}) AS asking,
27
+ (${OF_THE_ROW} AND ${SAID_BY_HOUSE} AND ${WAITING_PROPOSAL} ${NEWEST_FIRST}) AS proposing
24
28
  FROM json_each(?) AS listed
25
29
  )
26
30
  SELECT chosen.conversation AS conversation,
@@ -28,23 +32,28 @@ export const ROWS = `WITH chosen AS (
28
32
  json_extract(said.message, '$.role') AS said_role,
29
33
  json_extract(said.message, '$.accepted_at') AS said_at,
30
34
  answer.turn AS answered,
35
+ json_extract(answer.message, '$.content.state') AS saved_state,
36
+ json_extract(answer.message, '$.accepted_at') AS saved_at,
31
37
  substr(json_extract(answer.message, '$.failure'), 1, ${EXCERPT}) AS failure,
32
- (SELECT value FROM conversation_facts WHERE conversation = chosen.conversation AND name = 'openedTurn') AS opened_turn,
38
+ COALESCE(
39
+ (SELECT value FROM conversation_facts WHERE conversation = chosen.conversation AND name = 'openedTurn'),
40
+ CASE WHEN julianday(json_extract(answer.message, '$.accepted_at')) < ${READ_UNTIL} THEN answer.turn END
41
+ ) AS opened_turn,
33
42
  json_extract(opened.message, '$.source') AS opened_source,
34
43
  json_extract(opened.message, '$.sender') AS opened_sender,
35
44
  asking.identity AS asking_identity,
36
45
  asking.text AS asking_text,
37
46
  json_extract(asking.message, '$.accepted_at') AS asking_at,
38
47
  json_extract(asking.message, '$.source') AS asking_source,
39
- json_extract(asking.message, '$.sender') AS asking_sender
48
+ json_extract(asking.message, '$.sender') AS asking_sender,
49
+ json_extract(proposing.message, '$.source') AS proposing_source,
50
+ json_extract(proposing.message, '$.accepted_at') AS proposing_at
40
51
  FROM chosen
41
52
  LEFT JOIN conversation_messages said ON said.id = chosen.said
42
53
  LEFT JOIN conversation_messages answer ON answer.id = chosen.answer
43
54
  LEFT JOIN conversation_messages opened ON opened.id = chosen.opened
44
- LEFT JOIN conversation_messages asking ON asking.id = chosen.asking`;
45
- function text(value) {
46
- return typeof value === 'string' ? value : String(value);
47
- }
55
+ LEFT JOIN conversation_messages asking ON asking.id = chosen.asking
56
+ LEFT JOIN conversation_messages proposing ON proposing.id = chosen.proposing`;
48
57
  export function heldConversations(connection, conversations) {
49
58
  const named = conversations === null ? '' : ' AND conversation IN (SELECT value FROM json_each(?))';
50
59
  const bound = conversations === null ? [] : [JSON.stringify(conversations)];
@@ -129,6 +138,9 @@ export function conversationRows(connection, conversations) {
129
138
  at: textOrNull(row.said_at),
130
139
  },
131
140
  answered: textOrNull(row.answered),
141
+ saved: row.saved_state === null || row.saved_at === null
142
+ ? null
143
+ : { state: JSON.parse(text(row.saved_state)), at: text(row.saved_at) },
132
144
  openedTurn: textOrNull(row.opened_turn),
133
145
  failure: textOrNull(row.failure),
134
146
  opened: row.opened_source === null ? null : heldSource(row.opened_source, row.opened_sender),
@@ -140,6 +152,12 @@ export function conversationRows(connection, conversations) {
140
152
  text: text(row.asking_text),
141
153
  at: textOrNull(row.asking_at),
142
154
  },
155
+ proposing: row.proposing_source === null
156
+ ? null
157
+ : {
158
+ source: JSON.parse(text(row.proposing_source)),
159
+ at: textOrNull(row.proposing_at),
160
+ },
143
161
  }));
144
162
  }
145
163
  export function turnArrived(connection, conversation, turn) {
@@ -0,0 +1,2 @@
1
+ export declare function shownModal(dialog: HTMLDialogElement): void;
2
+ //# sourceMappingURL=modal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modal.d.ts","sourceRoot":"","sources":["../src/modal.ts"],"names":[],"mappings":"AAMA,wBAAgB,UAAU,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAI1D"}
package/dist/modal.js ADDED
@@ -0,0 +1,11 @@
1
+ function unfocused(page) {
2
+ let held = page.activeElement;
3
+ while (held?.shadowRoot?.activeElement)
4
+ held = held.shadowRoot.activeElement;
5
+ held.blur();
6
+ }
7
+ export function shownModal(dialog) {
8
+ unfocused(dialog.ownerDocument);
9
+ dialog.showModal();
10
+ unfocused(dialog.ownerDocument);
11
+ }
package/dist/model.d.ts CHANGED
@@ -17,21 +17,22 @@ export type ModelResult = {
17
17
  reason: ModelUnavailableReason;
18
18
  };
19
19
  export type MdType = Definition;
20
- export type ModelState = {
20
+ export type StoredModel = {
21
21
  status: 'unavailable';
22
22
  reason: ModelUnavailableReason;
23
23
  } | {
24
24
  status: 'current' | 'cached';
25
25
  snapshot: ModelSnapshot;
26
26
  verifiedWith: ModelIdentity;
27
- types: VerifiedModel['types'];
28
27
  };
29
- export type StoredModel = Extract<ModelState, {
28
+ export type ModelState = Extract<StoredModel, {
30
29
  status: 'unavailable';
31
- }> | Omit<Extract<ModelState, {
30
+ }> | (Extract<StoredModel, {
32
31
  status: 'current' | 'cached';
33
- }>, 'types'>;
34
- export type TypesResult = {
32
+ }> & {
33
+ types: VerifiedModel['types'];
34
+ });
35
+ export type TypesResult<Types = readonly MdType[]> = {
35
36
  status: Open<'unavailable'>;
36
37
  reason: ModelUnavailableReason;
37
38
  types: null;
@@ -40,7 +41,7 @@ export type TypesResult = {
40
41
  identity: string;
41
42
  version: string;
42
43
  verifiedWith: ModelIdentity;
43
- types: readonly MdType[];
44
+ types: Types;
44
45
  schema: string | null;
45
46
  revision: string | null;
46
47
  };
@@ -50,6 +51,8 @@ export type ValidationReceipt = {
50
51
  source: Open<'current' | 'cached'>;
51
52
  };
52
53
  export declare const NO_MODEL: ModelState;
54
+ export declare function sortedTypes(types: VerifiedModel['types']): readonly MdType[];
53
55
  export declare function modelTypes(state: ModelState): TypesResult;
56
+ export declare function modelResult<Types>(state: ModelState, types: (held: VerifiedModel['types']) => Types): TypesResult<Types>;
54
57
  export declare function storedModel(state: ModelState): StoredModel;
55
58
  //# sourceMappingURL=model.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAClE,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG;IAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,EAAE,MA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,WAAW,CAAC,KAAK,EAC/B,KAAK,EAAE,UAAU,EACjB,KAAK,EAAE,CAAC,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,KAAK,KAAK,GAC7C,WAAW,CAAC,KAAK,CAAC,CAYpB;AACD,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAI1D"}
package/dist/model.js CHANGED
@@ -1,5 +1,11 @@
1
1
  export const NO_MODEL = { status: 'unavailable', reason: 'not-acquired' };
2
+ export function sortedTypes(types) {
3
+ return Object.values(types).sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
4
+ }
2
5
  export function modelTypes(state) {
6
+ return modelResult(state, sortedTypes);
7
+ }
8
+ export function modelResult(state, types) {
3
9
  return state.status === 'unavailable'
4
10
  ? { ...state, types: null }
5
11
  : {
@@ -9,7 +15,7 @@ export function modelTypes(state) {
9
15
  verifiedWith: { ...state.verifiedWith },
10
16
  schema: state.snapshot.schema,
11
17
  revision: state.snapshot.revision,
12
- types: Object.values(state.types).sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0),
18
+ types: types(state.types),
13
19
  };
14
20
  }
15
21
  export function storedModel(state) {
package/dist/name.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export declare function transliterated(text: string): string;
2
1
  export declare function nameFrom(title: string): string;
3
2
  export declare function cutName(name: string, most: number): string;
4
3
  //# sourceMappingURL=name.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"name.d.ts","sourceRoot":"","sources":["../src/name.ts"],"names":[],"mappings":"AAgHA,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAK9C;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE1D"}
1
+ {"version":3,"file":"name.d.ts","sourceRoot":"","sources":["../src/name.ts"],"names":[],"mappings":"AA+GA,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAK9C;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE1D"}
package/dist/name.js CHANGED
@@ -97,22 +97,18 @@ function lowerLetterOf(character) {
97
97
  function codePoint(character) {
98
98
  return WORDLIKE.test(character) ? `-u${character.codePointAt(0)?.toString(16) ?? ''}-` : '-';
99
99
  }
100
- function latin(text, unknown) {
100
+ function latin(text) {
101
101
  return [...text]
102
102
  .map((character) => {
103
103
  if ((character.codePointAt(0) ?? 0) < 0x80)
104
104
  return character;
105
105
  const lower = character.toLowerCase();
106
- const letter = lowerLetterOf(lower) ?? unknown(lower);
107
- return lower === character ? letter : `${letter.charAt(0).toUpperCase()}${letter.slice(1)}`;
106
+ return lowerLetterOf(lower) ?? codePoint(lower);
108
107
  })
109
108
  .join('');
110
109
  }
111
- export function transliterated(text) {
112
- return latin(text, () => '-');
113
- }
114
110
  export function nameFrom(title) {
115
- return latin(title, codePoint)
111
+ return latin(title)
116
112
  .toLowerCase()
117
113
  .replace(/[^a-z0-9]+/g, '-')
118
114
  .replace(/^-+|-+$/g, '');
@@ -1,5 +1,6 @@
1
1
  import type { PendingRoom, QueryCoverage, QueryDocument, QueryGroup, QueryResult } from './query.js';
2
2
  import type { ReadinessShown, RoomCoverage } from './readiness.js';
3
+ import type { AppRoom, ListedRooms } from './listing.js';
3
4
  export type Observation<T> = {
4
5
  current(): T;
5
6
  subscribe(listener: (value: T) => void): () => void;
@@ -41,6 +42,7 @@ export declare function keyedChange<K, H, T>(held: ReadonlyMap<K, H>, keys: read
41
42
  export declare function keyedAt<K, H, T>(held: ReadonlyMap<K, H>, at: ReadonlyMap<K, T | null>, same: (was: H, now: T) => boolean): KeyedChange<K, T> | null;
42
43
  export declare function keyedInto<K, T>(held: Map<K, T>, change: KeyedChange<K, T>): void;
43
44
  export declare function samePending(was: PendingRoom, now: PendingRoom): boolean;
45
+ export declare function appRooms({ rooms, models }: ListedRooms): readonly AppRoom[];
44
46
  export declare function replaces(topic: string, message: unknown): boolean;
45
47
  export declare function observed(first: unknown, stop: () => void, topic: string): Observed;
46
48
  export declare function opened(watch: (deliver: (message: unknown) => void, fail: (error: unknown) => void) => () => void, topic: string): Promise<Observation<unknown>>;
@@ -1 +1 @@
1
- {"version":3,"file":"observation.d.ts","sourceRoot":"","sources":["../src/observation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACb,aAAa,EACb,UAAU,EACV,WAAW,EACZ,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAa,cAAc,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9E,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC3B,OAAO,IAAI,CAAC,CAAC;IACb,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACpD,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAErC,MAAM,MAAM,WAAW,GAAG;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAE3E,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,IAAI;IAC9B,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/C,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,GAAG,IAAI,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,MAAM,EAAE,aAAa,GAAG,UAAU,CAAC,GAAG;IAC1E,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C1B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;CACpC,CAAC;AAEN,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAa3C;AAMD,wBAAgB,QAAQ,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,WAAW,GAAG,MAAM,CAU9D;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,MAAM,CAkB3E;AAED,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,YAAY,GAAG,IAAI,CAsBjF"}
@@ -70,18 +70,51 @@ function keyedRows(keys, rows) {
70
70
  },
71
71
  };
72
72
  }
73
- function located(rooms) {
74
- return keyedRows(rooms.map(({ locator }) => locator), rooms);
73
+ function heldModels(held, sent) {
74
+ return new Map(Object.entries(sent).map(([key, types]) => [key, held.get(key) ?? types]));
75
+ }
76
+ function namedModels(models, rooms) {
77
+ const named = new Set(rooms.flatMap(({ model, typedSelection }) => [model.types, typedSelection?.model.types]));
78
+ return new Map([...models].filter(([, types]) => named.has(types)));
79
+ }
80
+ function typed(model, models) {
81
+ return model.types === null ? model : { ...model, types: models.get(model.types) };
82
+ }
83
+ function appRoom({ model, typedSelection, ...room }, models) {
84
+ return {
85
+ ...room,
86
+ model: typed(model, models),
87
+ typedSelection: typedSelection === null
88
+ ? null
89
+ : { roots: typedSelection.roots, model: typed(typedSelection.model, models) },
90
+ };
91
+ }
92
+ export function appRooms({ rooms, models }) {
93
+ const held = heldModels(new Map(), models);
94
+ return rooms.map((room) => appRoom(room, held));
75
95
  }
76
96
  function keyedRooms(first) {
77
- let held = located(first);
97
+ let models = new Map();
98
+ let held = keyedRows([], []);
99
+ const whole = (listed) => {
100
+ models = heldModels(models, listed.models);
101
+ held = keyedRows(listed.rooms.map(({ locator }) => locator), listed.rooms.map((room) => appRoom(room, models)));
102
+ return held.rows();
103
+ };
78
104
  return {
79
- value: first,
105
+ value: whole(first),
80
106
  next(message) {
81
- if (!Array.isArray(message))
82
- return held.apply(message);
83
- held = located(message);
84
- return held.rows();
107
+ if ('rooms' in message)
108
+ return whole(message);
109
+ const change = message;
110
+ const sent = heldModels(models, change.models);
111
+ const rows = held.apply({
112
+ changed: change.changed.map(([locator, room]) => [locator, appRoom(room, sent)]),
113
+ removed: change.removed,
114
+ order: change.order,
115
+ });
116
+ models = namedModels(new Map([...models, ...sent]), rows);
117
+ return rows;
85
118
  },
86
119
  };
87
120
  }
@@ -154,7 +187,7 @@ const FOLDS = {
154
187
  };
155
188
  const WHOLE = {
156
189
  query: (message) => whole(message),
157
- rooms: (message) => Array.isArray(message),
190
+ rooms: (message) => 'rooms' in message,
158
191
  readiness: (message) => !('shown' in message),
159
192
  };
160
193
  export function replaces(topic, message) {
@@ -0,0 +1,7 @@
1
+ import type { Authorization } from './adapter.js';
2
+ import type { Runtime } from './runtime.js';
3
+ export declare function offline(runtime: Runtime): Promise<boolean>;
4
+ export declare function askedOnline<T extends {
5
+ readonly kind: string;
6
+ }>(runtime: Runtime, ask: (authorization: Authorization) => Promise<T>): Promise<T | null>;
7
+ //# sourceMappingURL=online.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"online.d.ts","sourceRoot":"","sources":["../src/online.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGlD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,wBAAsB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAOhE;AAED,wBAAsB,WAAW,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EACnE,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,CAAC,aAAa,EAAE,aAAa,KAAK,OAAO,CAAC,CAAC,CAAC,GAChD,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAgBnB"}
package/dist/online.js ADDED
@@ -0,0 +1,29 @@
1
+ import { connectionNow } from './preparation.js';
2
+ import { refuse } from './refusal.js';
3
+ export async function offline(runtime) {
4
+ const { socket } = runtime;
5
+ return (socket.closed() ||
6
+ socket.session.now().refusal !== null ||
7
+ (await connectionNow(runtime)) !== 'connected');
8
+ }
9
+ export async function askedOnline(runtime, ask) {
10
+ const { socket } = runtime;
11
+ try {
12
+ await socket.authorize();
13
+ }
14
+ catch {
15
+ return null;
16
+ }
17
+ const { closed, authorization, refusal } = socket.session.now();
18
+ if (closed || authorization === undefined || refusal !== null)
19
+ return null;
20
+ try {
21
+ const answer = await ask(authorization);
22
+ if (answer.kind === 'revoked-authorization')
23
+ await refuse(runtime, 'revoked-authorization');
24
+ return answer;
25
+ }
26
+ catch {
27
+ return null;
28
+ }
29
+ }
package/dist/opened.d.ts CHANGED
@@ -1,22 +1,22 @@
1
- import type { BinaryResult } from './adapter.js';
1
+ import type { AttachmentResult } from './adapter.js';
2
2
  import { type RuntimeDatabase } from './tables.js';
3
3
  export type OpenedName = {
4
4
  readonly locator: string;
5
5
  readonly path: string;
6
6
  readonly revision: string;
7
7
  };
8
- export type KeptBinary = {
8
+ export type KeptAttachment = {
9
9
  readonly kind: 'binary';
10
10
  readonly file: string;
11
11
  readonly byteLength: number;
12
12
  readonly mediaType: string;
13
13
  };
14
- export type KeptResult = KeptBinary | Exclude<BinaryResult, {
14
+ export type KeptResult = KeptAttachment | Exclude<AttachmentResult, {
15
15
  kind: 'binary';
16
16
  }>;
17
17
  export type OpenedFiles = {
18
- find(name: OpenedName): Promise<KeptBinary | null>;
19
- fetch(name: OpenedName, read: () => Promise<BinaryResult>): Promise<KeptResult>;
18
+ find(name: OpenedName): Promise<KeptAttachment | null>;
19
+ fetch(name: OpenedName, read: () => Promise<AttachmentResult>): Promise<KeptResult>;
20
20
  };
21
21
  export declare function openedFiles(database: RuntimeDatabase, lost: (locator: string) => boolean): OpenedFiles;
22
22
  //# sourceMappingURL=opened.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"opened.d.ts","sourceRoot":"","sources":["../src/opened.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAGjD,OAAO,EAAoC,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAErF,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,OAAO,CAAC,YAAY,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,CAAC;AAEhF,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IACnD,KAAK,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACjF,CAAC;AAsBF,wBAAgB,WAAW,CACzB,QAAQ,EAAE,eAAe,EACzB,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,GACjC,WAAW,CAsFb"}
1
+ {"version":3,"file":"opened.d.ts","sourceRoot":"","sources":["../src/opened.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGrD,OAAO,EAAoC,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAErF,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,OAAO,CAAC,gBAAgB,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,CAAC;AAExF,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IACvD,KAAK,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACrF,CAAC;AAsBF,wBAAgB,WAAW,CACzB,QAAQ,EAAE,eAAe,EACzB,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,GACjC,WAAW,CAsFb"}
package/dist/opened.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { digest } from './digest.js';
2
- import { binaryLocalId } from './identity.js';
2
+ import { attachmentLocalId } from './identity.js';
3
3
  import { FILE_PART_BYTES } from './tables.js';
4
4
  const UNCERTAIN = { kind: 'transport-uncertainty' };
5
5
  function kept({ key, byteLength, mediaType }) {
@@ -27,7 +27,7 @@ export function openedFiles(database, lost) {
27
27
  return held === null ? null : kept(held);
28
28
  }
29
29
  async function written(name, { body, mediaType, sha256 }) {
30
- const key = binaryLocalId();
30
+ const key = attachmentLocalId();
31
31
  const reader = body.getReader();
32
32
  const hashed = digest();
33
33
  const chunks = [];
@@ -1 +1 @@
1
- {"version":3,"file":"opening.d.ts","sourceRoot":"","sources":["../src/opening.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,wBAAsB,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAqCxF"}
1
+ {"version":3,"file":"opening.d.ts","sourceRoot":"","sources":["../src/opening.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,wBAAsB,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAuCxF"}
package/dist/opening.js CHANGED
@@ -5,9 +5,10 @@ import { sweep } from './install.js';
5
5
  import { eraseFenced } from './lost.js';
6
6
  import { prepare } from './preparation.js';
7
7
  import { unpair } from './queue.js';
8
+ import { runsOpened } from './runs.js';
8
9
  import { emitRooms, emitStorageLoss, statusShown } from './shown.js';
9
10
  export async function open(runtime, opened) {
10
- const { store, socket, shell, conversations, build, usableWhenHeld } = runtime;
11
+ const { store, socket, shell, conversations, build } = runtime;
11
12
  if (socket.closed())
12
13
  throw new Error('runtime closed');
13
14
  const interrupted = await opened.fences();
@@ -25,7 +26,7 @@ export async function open(runtime, opened) {
25
26
  }
26
27
  const held = await opened.opened();
27
28
  store.device.set({
28
- heldWhenOpened: usableWhenHeld.length > 0 && (await opened.covering()).rooms.size > 0,
29
+ completedWhenOpened: (await opened.facts(['lastCompleted'])).lastCompleted !== null,
29
30
  });
30
31
  try {
31
32
  await opened.demote();
@@ -40,14 +41,31 @@ export async function open(runtime, opened) {
40
41
  if (held.erasing || held.orphans.length > 0)
41
42
  queueMicrotask(() => sweep(runtime));
42
43
  await conversationsOpened(conversations, opened);
44
+ await runsOpened(runtime);
43
45
  if (interrupted.length > 0) {
44
46
  queueMicrotask(() => {
45
47
  void eraseFenced(runtime, interrupted).catch(uncaught);
46
48
  });
47
49
  }
50
+ await factsKept(runtime, opened);
48
51
  statusShown(runtime);
49
52
  prepare(runtime);
50
53
  emitRooms(runtime);
51
54
  void unpair(runtime).catch(uncaught);
52
55
  return opened;
53
56
  }
57
+ async function factsKept({ socket, adopt }, opened) {
58
+ const { session } = socket;
59
+ const { unstored } = session.now();
60
+ if (unstored !== null) {
61
+ queueMicrotask(() => {
62
+ void adopt(unstored).catch(uncaught);
63
+ });
64
+ return;
65
+ }
66
+ const { capabilities, queriesOnly } = await opened.facts(['capabilities', 'queriesOnly']);
67
+ if (queriesOnly.length > 0 && !session.now().roomsNamed)
68
+ session.set({ queriesOnly });
69
+ if (capabilities.length > 0)
70
+ socket.readyFromStore();
71
+ }
package/dist/outcome.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { ActionResult, AdapterFailure, AttachResult, BinaryLinkResult, HistoryResult, HistoryRevision, ProviderRefusal, RoomVersionAt, ScopedRefusal } from './adapter.js';
1
+ import type { ActionResult, AdapterFailure, AttachResult, AttachmentCopy, AttachmentLinkResult, HistoryResult, HistoryRevision, ProviderRefusal, RoomVersionAt, ScopedRefusal } from './adapter.js';
2
2
  import type { ChangeBatch } from './change.js';
3
3
  import type { Attempt, Retries } from './retried.js';
4
- import type { KeptBinary, KeptResult } from './opened.js';
4
+ import type { KeptAttachment, KeptResult } from './opened.js';
5
5
  type Refused<Kind extends string> = ProviderRefusal & {
6
6
  kind: Kind;
7
7
  };
@@ -20,26 +20,38 @@ export type CallResult = {
20
20
  export type HistoryAnswer = Exclude<HistoryResult, {
21
21
  kind: Failure['kind'];
22
22
  }> | Failure;
23
- type BinaryRefusal = Refused<'rejected'> | Refused<'absent'> | Failure;
24
- export type BinaryAnswer = {
23
+ type AttachmentRefusal = Refused<'rejected'> | Refused<'absent'> | Failure;
24
+ export type AttachmentAnswer = {
25
25
  kind: 'binary';
26
26
  stream: ReadableStream<Uint8Array>;
27
27
  byteLength: number;
28
28
  mediaType: string;
29
- } | BinaryRefusal;
30
- export type HeldBinaryAnswer = KeptBinary | BinaryRefusal;
31
- export type BinaryLinkAnswer = {
29
+ } | AttachmentRefusal;
30
+ export type HeldAttachmentAnswer = KeptAttachment | AttachmentRefusal;
31
+ export type AttachmentLinkAnswer = {
32
32
  kind: 'link';
33
33
  url: string;
34
34
  name: string;
35
35
  mediaType: string;
36
36
  } | Refused<'rejected'> | Refused<'absent'> | Failure;
37
- export type HeldShownAnswer = KeptBinary | BinaryLinkAnswer;
38
- export type ShownAnswer = BinaryAnswer | BinaryLinkAnswer;
37
+ export type ShownLinkAnswer = Extract<AttachmentLinkAnswer, {
38
+ kind: 'link';
39
+ }> & {
40
+ copies: readonly AttachmentCopy[];
41
+ };
42
+ type ShownRefusal = Exclude<AttachmentLinkAnswer, {
43
+ kind: 'link';
44
+ }>;
45
+ export type HeldShownAnswer = KeptAttachment | ShownLinkAnswer | ShownRefusal;
46
+ export type ShownAnswer = AttachmentAnswer | ShownLinkAnswer | ShownRefusal;
39
47
  export type AttachAnswer = {
40
48
  kind: 'attached';
41
49
  path: string;
42
50
  } | Offline | Refused<'rejected'> | Failure;
51
+ export type ConversationAttachAnswer = {
52
+ kind: 'attached';
53
+ link: string;
54
+ } | Offline | Refused<'rejected'> | Refused<'undeclared'> | Failure;
43
55
  export type DownloadAnswer = {
44
56
  kind: 'started';
45
57
  } | Refused<'rejected'> | Refused<'absent'> | Refused<'blocked'> | Failure;
@@ -56,14 +68,15 @@ export type Resolution = {
56
68
  export declare const UNREADABLE: Refused<'unreadable'>;
57
69
  export declare const LOCKED_UNREADABLE: Refused<'unreadable'>;
58
70
  export declare const ABSENT_TARGET: Refused<'absent'>;
59
- export declare function absentBinary(path: string): Refused<'absent'>;
71
+ export declare function absentAttachment(path: string): Refused<'absent'>;
60
72
  export declare function declaredType(blob: Blob): string;
61
- export declare function blobOf(binary: Extract<BinaryAnswer, {
73
+ export declare function attachmentBlob(binary: Extract<AttachmentAnswer, {
62
74
  kind: 'binary';
63
75
  }>): Promise<Blob>;
64
- export declare function binaryAnswer(result: KeptResult): HeldBinaryAnswer;
65
- export declare function binaryLinkAnswer(result: BinaryLinkResult, held?: string): BinaryLinkAnswer;
76
+ export declare function attachmentAnswer(result: KeptResult): HeldAttachmentAnswer;
77
+ export declare function attachmentLinkAnswer(result: AttachmentLinkResult, held?: string): AttachmentLinkAnswer;
66
78
  export declare function attachAnswer(result: AttachResult): AttachAnswer;
79
+ export declare function linkedAnswer(result: AttachResult): ConversationAttachAnswer;
67
80
  export declare const ROOM_LOCKED = "room-locked";
68
81
  export declare function lockedRoom(locator: string): Refused<'room-locked'> & {
69
82
  locator: string;
@@ -74,7 +87,7 @@ export type Offline = {
74
87
  export declare const OFFLINE: Offline;
75
88
  export declare function answeredResult(value: unknown): boolean;
76
89
  export declare const UNCERTAIN: Failure;
77
- export declare function undeclared(name: string): CallResult;
90
+ export declare function undeclared(name: string): Refused<'undeclared'>;
78
91
  export declare function failure(result: AdapterFailure): Failure;
79
92
  export declare function calledResult(result: ActionResult): CallResult;
80
93
  export declare function historyAnswer(result: HistoryResult): HistoryAnswer;