@agentshouse/mdruntime 0.1.0-cedd665dffa4c → 0.1.0-cee2924c82d23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/README.md +9 -9
  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 +48 -9
  6. package/dist/adapter.d.ts +118 -19
  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 +347 -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 +2 -2
  20. package/dist/chat-types.js +2 -2
  21. package/dist/client.d.ts +16 -7
  22. package/dist/client.d.ts.map +1 -1
  23. package/dist/client.js +24 -51
  24. package/dist/collection.d.ts +3 -1
  25. package/dist/collection.d.ts.map +1 -1
  26. package/dist/collection.js +16 -9
  27. package/dist/column.d.ts +5 -0
  28. package/dist/column.d.ts.map +1 -0
  29. package/dist/column.js +9 -0
  30. package/dist/compile.d.ts +2 -1
  31. package/dist/compile.d.ts.map +1 -1
  32. package/dist/compile.js +71 -39
  33. package/dist/connection.d.ts +1 -1
  34. package/dist/connection.d.ts.map +1 -1
  35. package/dist/connection.js +6 -2
  36. package/dist/conversation-live.d.ts +2 -3
  37. package/dist/conversation-live.d.ts.map +1 -1
  38. package/dist/conversation-live.js +2 -2
  39. package/dist/conversation.d.ts +18 -9
  40. package/dist/conversation.d.ts.map +1 -1
  41. package/dist/conversation.js +38 -22
  42. package/dist/declaration.js +3 -3
  43. package/dist/discovery.d.ts +3 -1
  44. package/dist/discovery.d.ts.map +1 -1
  45. package/dist/discovery.js +30 -5
  46. package/dist/download.d.ts +6 -0
  47. package/dist/download.d.ts.map +1 -0
  48. package/dist/download.js +42 -0
  49. package/dist/durability.d.ts +1 -0
  50. package/dist/durability.d.ts.map +1 -1
  51. package/dist/durability.js +3 -0
  52. package/dist/entry.d.ts +25 -1
  53. package/dist/entry.d.ts.map +1 -1
  54. package/dist/entry.js +111 -34
  55. package/dist/failure.d.ts.map +1 -1
  56. package/dist/failure.js +3 -1
  57. package/dist/figures.d.ts +1 -1
  58. package/dist/figures.d.ts.map +1 -1
  59. package/dist/figures.js +2 -2
  60. package/dist/file.d.ts +1 -1
  61. package/dist/file.d.ts.map +1 -1
  62. package/dist/file.js +1 -1
  63. package/dist/host.d.ts +6 -2
  64. package/dist/host.d.ts.map +1 -1
  65. package/dist/host.js +57 -21
  66. package/dist/house-query.d.ts +24 -0
  67. package/dist/house-query.d.ts.map +1 -0
  68. package/dist/house-query.js +102 -0
  69. package/dist/identity.d.ts +1 -1
  70. package/dist/identity.d.ts.map +1 -1
  71. package/dist/identity.js +1 -1
  72. package/dist/index.d.ts +17 -10
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.js +10 -5
  75. package/dist/lifecycle.d.ts +1 -1
  76. package/dist/lifecycle.d.ts.map +1 -1
  77. package/dist/lifecycle.js +28 -16
  78. package/dist/listing.d.ts +20 -12
  79. package/dist/listing.d.ts.map +1 -1
  80. package/dist/listing.js +33 -17
  81. package/dist/live.d.ts +14 -0
  82. package/dist/live.d.ts.map +1 -1
  83. package/dist/live.js +29 -12
  84. package/dist/loaded.d.ts +5 -3
  85. package/dist/loaded.d.ts.map +1 -1
  86. package/dist/loaded.js +12 -6
  87. package/dist/locks.d.ts.map +1 -1
  88. package/dist/locks.js +2 -0
  89. package/dist/media.d.ts +14 -3
  90. package/dist/media.d.ts.map +1 -1
  91. package/dist/media.js +126 -30
  92. package/dist/memory.d.ts +4 -2
  93. package/dist/memory.d.ts.map +1 -1
  94. package/dist/memory.js +47 -16
  95. package/dist/messages.d.ts +6 -1
  96. package/dist/messages.d.ts.map +1 -1
  97. package/dist/messages.js +11 -4
  98. package/dist/modal.d.ts +2 -0
  99. package/dist/modal.d.ts.map +1 -0
  100. package/dist/modal.js +11 -0
  101. package/dist/model.d.ts +10 -7
  102. package/dist/model.d.ts.map +1 -1
  103. package/dist/model.js +7 -1
  104. package/dist/name.d.ts +0 -1
  105. package/dist/name.d.ts.map +1 -1
  106. package/dist/name.js +3 -7
  107. package/dist/observation.d.ts +2 -0
  108. package/dist/observation.d.ts.map +1 -1
  109. package/dist/observation.js +42 -9
  110. package/dist/online.d.ts +7 -0
  111. package/dist/online.d.ts.map +1 -0
  112. package/dist/online.js +29 -0
  113. package/dist/opened.d.ts +5 -5
  114. package/dist/opened.d.ts.map +1 -1
  115. package/dist/opened.js +2 -2
  116. package/dist/opening.d.ts.map +1 -1
  117. package/dist/opening.js +18 -2
  118. package/dist/outcome.d.ts +27 -14
  119. package/dist/outcome.d.ts.map +1 -1
  120. package/dist/outcome.js +14 -5
  121. package/dist/overlay.d.ts +19 -8
  122. package/dist/overlay.d.ts.map +1 -1
  123. package/dist/overlay.js +108 -37
  124. package/dist/parts.d.ts +3 -1
  125. package/dist/parts.d.ts.map +1 -1
  126. package/dist/parts.js +30 -7
  127. package/dist/paths.d.ts +1 -1
  128. package/dist/paths.js +1 -1
  129. package/dist/preparation.d.ts +10 -5
  130. package/dist/preparation.d.ts.map +1 -1
  131. package/dist/preparation.js +78 -48
  132. package/dist/queries.d.ts.map +1 -1
  133. package/dist/queries.js +75 -53
  134. package/dist/query.d.ts +2 -2
  135. package/dist/query.d.ts.map +1 -1
  136. package/dist/questions.d.ts +1 -0
  137. package/dist/questions.d.ts.map +1 -1
  138. package/dist/questions.js +3 -1
  139. package/dist/reach.d.ts +13 -3
  140. package/dist/reach.d.ts.map +1 -1
  141. package/dist/reach.js +114 -25
  142. package/dist/react.d.ts +5 -1
  143. package/dist/react.d.ts.map +1 -1
  144. package/dist/readiness.d.ts +17 -4
  145. package/dist/readiness.d.ts.map +1 -1
  146. package/dist/readiness.js +17 -7
  147. package/dist/reads.d.ts +1 -1
  148. package/dist/reads.d.ts.map +1 -1
  149. package/dist/reads.js +17 -6
  150. package/dist/recovery.d.ts +1 -0
  151. package/dist/recovery.d.ts.map +1 -1
  152. package/dist/recovery.js +2 -1
  153. package/dist/reference-forms.d.ts +4 -0
  154. package/dist/reference-forms.d.ts.map +1 -0
  155. package/dist/reference-forms.js +74 -0
  156. package/dist/refresh.d.ts +1 -1
  157. package/dist/refresh.js +4 -4
  158. package/dist/replica.d.ts +3 -8
  159. package/dist/replica.d.ts.map +1 -1
  160. package/dist/replica.js +3 -3
  161. package/dist/room-draft.d.ts +1 -1
  162. package/dist/room-draft.d.ts.map +1 -1
  163. package/dist/room-draft.js +9 -6
  164. package/dist/room-drafts.d.ts.map +1 -1
  165. package/dist/room-drafts.js +8 -6
  166. package/dist/room-list.d.ts +10 -0
  167. package/dist/room-list.d.ts.map +1 -0
  168. package/dist/room-list.js +45 -0
  169. package/dist/rows.d.ts +9 -1
  170. package/dist/rows.d.ts.map +1 -1
  171. package/dist/rows.js +18 -4
  172. package/dist/running.d.ts +5 -0
  173. package/dist/running.d.ts.map +1 -0
  174. package/dist/running.js +10 -0
  175. package/dist/runtime.d.ts +5 -2
  176. package/dist/runtime.d.ts.map +1 -1
  177. package/dist/save.d.ts +1 -0
  178. package/dist/save.d.ts.map +1 -1
  179. package/dist/save.js +6 -6
  180. package/dist/saves.d.ts +7 -5
  181. package/dist/saves.d.ts.map +1 -1
  182. package/dist/saves.js +86 -49
  183. package/dist/selector.d.ts +3 -0
  184. package/dist/selector.d.ts.map +1 -0
  185. package/dist/selector.js +22 -0
  186. package/dist/shown.d.ts +2 -0
  187. package/dist/shown.d.ts.map +1 -1
  188. package/dist/shown.js +21 -4
  189. package/dist/socket/session.d.ts +4 -1
  190. package/dist/socket/session.d.ts.map +1 -1
  191. package/dist/socket/session.js +3 -0
  192. package/dist/socket.d.ts +1 -0
  193. package/dist/socket.d.ts.map +1 -1
  194. package/dist/socket.js +1 -0
  195. package/dist/source.d.ts +2 -0
  196. package/dist/source.d.ts.map +1 -1
  197. package/dist/source.js +2 -0
  198. package/dist/store/records.d.ts +22 -5
  199. package/dist/store/records.d.ts.map +1 -1
  200. package/dist/store/records.js +14 -4
  201. package/dist/store.d.ts +3 -2
  202. package/dist/store.d.ts.map +1 -1
  203. package/dist/store.js +4 -1
  204. package/dist/stored.d.ts +17 -3
  205. package/dist/stored.d.ts.map +1 -1
  206. package/dist/stored.js +139 -35
  207. package/dist/surface.d.ts +12 -7
  208. package/dist/surface.d.ts.map +1 -1
  209. package/dist/surface.js +48 -15
  210. package/dist/sync.d.ts +4 -2
  211. package/dist/sync.d.ts.map +1 -1
  212. package/dist/sync.js +45 -23
  213. package/dist/tables.d.ts +16 -47
  214. package/dist/tables.d.ts.map +1 -1
  215. package/dist/tables.js +69 -321
  216. package/dist/tallies.js +2 -2
  217. package/dist/validation.d.ts +2 -0
  218. package/dist/validation.d.ts.map +1 -1
  219. package/dist/validation.js +49 -3
  220. package/dist/wire.d.ts +28 -6
  221. package/dist/wire.d.ts.map +1 -1
  222. package/dist/wire.js +17 -11
  223. package/package.json +4 -4
  224. package/dist/binary.d.ts.map +0 -1
  225. package/dist/binary.js +0 -8
@@ -0,0 +1,10 @@
1
+ import type { AuthorityChange, RoomList } from './adapter.js';
2
+ import type { Runtime } from './runtime.js';
3
+ import type { Deliver } from './reach.js';
4
+ export declare const ROOM_LIST_TOPIC = "room-list";
5
+ type RoomListChange = NonNullable<AuthorityChange['roomList']>;
6
+ export declare function roomsListed(runtime: Runtime, list: RoomList | undefined): Promise<void>;
7
+ export declare function roomListChanged(runtime: Runtime, change: RoomListChange | undefined): Promise<void>;
8
+ export declare function watchRoomList(runtime: Runtime, deliver: Deliver): () => void;
9
+ export {};
10
+ //# sourceMappingURL=room-list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"room-list.d.ts","sourceRoot":"","sources":["../src/room-list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,eAAO,MAAM,eAAe,cAAc,CAAC;AAE3C,KAAK,cAAc,GAAG,WAAW,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC;AA0B/D,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAGvF;AAED,wBAAgB,eAAe,CAC7B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,cAAc,GAAG,SAAS,GACjC,OAAO,CAAC,IAAI,CAAC,CAGf;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,IAAI,CAU5E"}
@@ -0,0 +1,45 @@
1
+ import { uncaught } from './failure.js';
2
+ export const ROOM_LIST_TOPIC = 'room-list';
3
+ async function kept(runtime, next) {
4
+ const local = await runtime.store.open();
5
+ const { roomList } = await local.facts(['roomList']);
6
+ const listed = next(roomList);
7
+ if (listed === null || JSON.stringify(listed) === JSON.stringify(roomList))
8
+ return;
9
+ await local.fact('roomList', listed);
10
+ runtime.store.tell(ROOM_LIST_TOPIC, listed);
11
+ }
12
+ function changed(held, change) {
13
+ const named = new Map(change.rooms.map((room) => [room.room_ref, room]));
14
+ const left = new Set(change.left);
15
+ const known = new Set(held.rooms.map((room) => room.room_ref));
16
+ return {
17
+ rooms: [
18
+ ...held.rooms.flatMap((room) => left.has(room.room_ref) ? [] : [named.get(room.room_ref) ?? room]),
19
+ ...change.rooms.filter((room) => !known.has(room.room_ref)),
20
+ ],
21
+ spaces: change.spaces,
22
+ };
23
+ }
24
+ export function roomsListed(runtime, list) {
25
+ if (list === undefined)
26
+ return Promise.resolve();
27
+ return kept(runtime, () => list).catch(uncaught);
28
+ }
29
+ export function roomListChanged(runtime, change) {
30
+ if (change === undefined)
31
+ return Promise.resolve();
32
+ return kept(runtime, (held) => (held === null ? null : changed(held, change))).catch(uncaught);
33
+ }
34
+ export function watchRoomList(runtime, deliver) {
35
+ const { store } = runtime;
36
+ const watcher = store.watch(ROOM_LIST_TOPIC, deliver);
37
+ void store
38
+ .open()
39
+ .then((local) => local.facts(['roomList']))
40
+ .then(({ roomList }) => {
41
+ if (watcher.held())
42
+ deliver(roomList);
43
+ }, uncaught);
44
+ return watcher.stop;
45
+ }
package/dist/rows.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type HeldValue } from '@agentshouse/mdmodel';
1
+ import { type Definition, type HeldValue } from '@agentshouse/mdmodel';
2
2
  import type { SavedFacts } from './adapter.js';
3
3
  import { type Composition } from './collection.js';
4
4
  import type { PlanReach } from './query.js';
@@ -7,6 +7,7 @@ type HeldLink = {
7
7
  readonly kind: LinkKind;
8
8
  readonly keys: string;
9
9
  readonly places: string;
10
+ readonly handle: string | null;
10
11
  readonly target: string;
11
12
  readonly field: string;
12
13
  };
@@ -22,9 +23,15 @@ export type Held = {
22
23
  readonly fields: Readonly<Record<string, unknown>> | null;
23
24
  readonly links: readonly string[];
24
25
  };
26
+ export type Sought = {
27
+ readonly type: string;
28
+ readonly field: string;
29
+ readonly value: string;
30
+ };
25
31
  export type Derived = {
26
32
  readonly values: readonly HeldValue[];
27
33
  readonly links: readonly HeldLink[];
34
+ readonly unique: readonly Sought[];
28
35
  };
29
36
  export declare function documentKey(room: string, path: string): string;
30
37
  export declare function roomOfKey(key: string): string;
@@ -35,6 +42,7 @@ export declare function folderOf(path: string): string;
35
42
  export declare function writtenFacts(path: string, content: string, composition: Composition): SavedFacts | null;
36
43
  export declare function described(path: string, content: string | null, facts: SavedFacts | null): Described;
37
44
  export declare function heldOf(path: string, content: string | null, facts: SavedFacts | null): Held;
45
+ export declare function uniqueValues(type: string, fields: Readonly<Record<string, unknown>>, definition: Definition | undefined): Sought[];
38
46
  export declare function derived(path: string, held: Held, composition: Composition): Derived;
39
47
  export {};
40
48
  //# sourceMappingURL=rows.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8C,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAClG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAA4B,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,KAAK,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;AAEjC,KAAK,QAAQ,GAAG;IACd,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG;IACjB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,Q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CAC1B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACzC,UAAU,EAAE,UAAU,GAAG,SAAS,GACjC,MAAM,EAAE,CAMV;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAiBnF"}
package/dist/rows.js CHANGED
@@ -1,4 +1,4 @@
1
- import { byCodePoint, documentFacts, indexed, parse } from '@agentshouse/mdmodel';
1
+ import { byCodePoint, documentFacts, fieldKey, indexed, parse, } from '@agentshouse/mdmodel';
2
2
  import { definitionsAt, governing } from './collection.js';
3
3
  function keyOf(...parts) {
4
4
  return `${parts.join('\u0000')}\u0000`;
@@ -15,8 +15,9 @@ export function roomsOfReach(reach) {
15
15
  export function pathOfKey(key) {
16
16
  return key.split('\u0000')[2];
17
17
  }
18
+ const MARKDOWN = /\.md$/iu;
18
19
  export function markdownPath(path) {
19
- return path.endsWith('.md');
20
+ return MARKDOWN.test(path);
20
21
  }
21
22
  export function folderOf(path) {
22
23
  return path.slice(0, Math.max(path.lastIndexOf('/'), 0));
@@ -61,17 +62,30 @@ export function heldOf(path, content, facts) {
61
62
  ? { type: facts.type, fields: facts.fields, links: facts.links }
62
63
  : { type: null, fields: null, links: facts.links };
63
64
  }
65
+ export function uniqueValues(type, fields, definition) {
66
+ if (definition === undefined)
67
+ return [];
68
+ return (definition.unique ?? []).flatMap((field) => {
69
+ const { key, unique } = fieldKey(definition, fields, field);
70
+ return unique ? [{ type, field, value: key }] : [];
71
+ });
72
+ }
64
73
  export function derived(path, held, composition) {
65
74
  const stored = held.links.map((target) => ({
66
75
  kind: 'link',
67
76
  keys: '',
68
77
  places: '',
78
+ handle: null,
69
79
  target,
70
80
  field: '',
71
81
  }));
72
82
  if (held.type === null || held.fields === null)
73
- return { values: [], links: stored };
83
+ return { values: [], links: stored, unique: [] };
74
84
  const definition = definitionsAt(composition, path)(held.type);
75
85
  const { values, links: fields } = indexed(path, held.fields, definition);
76
- return { values, links: [...fields, ...stored] };
86
+ return {
87
+ values,
88
+ links: [...fields, ...stored],
89
+ unique: uniqueValues(held.type, held.fields, definition),
90
+ };
77
91
  }
@@ -0,0 +1,5 @@
1
+ import type { SessionState } from '@agentshouse/session-content';
2
+ type Running = SessionState['running'][number];
3
+ export declare function runningWords(running: readonly Running[]): readonly string[];
4
+ export {};
5
+ //# sourceMappingURL=running.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"running.d.ts","sourceRoot":"","sources":["../src/running.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAEjE,KAAK,OAAO,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAU/C,wBAAgB,YAAY,CAAC,OAAO,EAAE,SAAS,OAAO,EAAE,GAAG,SAAS,MAAM,EAAE,CAE3E"}
@@ -0,0 +1,10 @@
1
+ const NOUNS = {
2
+ subagent: ['sub-agent', 'sub-agents'],
3
+ shell: ['command', 'commands'],
4
+ task: ['task', 'tasks'],
5
+ monitor: ['monitor', 'monitors'],
6
+ schedule: ['schedule', 'schedules'],
7
+ };
8
+ export function runningWords(running) {
9
+ return running.map(({ kind, count }) => `${count} ${NOUNS[kind][count === 1 ? 0 : 1]}`);
10
+ }
package/dist/runtime.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { RoomDeclaration, TypedPath } from './adapter.js';
1
+ import type { Discovery, RoomDeclaration, TypedPath } from './adapter.js';
2
2
  import type { RuntimeShell } from './durability.js';
3
3
  import type { LiveConversations } from './conversation-live.js';
4
4
  import type { WriteRule } from './declaration.js';
@@ -23,12 +23,15 @@ export type Runtime = {
23
23
  readonly roomTypes: Parameters<typeof schemaTypes>[1];
24
24
  readonly builtIn: ModelState;
25
25
  readonly typedPaths: readonly TypedPath[];
26
+ readonly renamedActions: ReadonlyMap<string, string>;
27
+ readonly rewrittenInputs: ReadonlyMap<string, (input: unknown) => unknown>;
26
28
  readonly writeRule: (declaration: RoomDeclaration) => WriteRule;
27
- readonly usableWhenHeld: readonly string[];
28
29
  readonly build: string;
29
30
  readonly conversations: LiveConversations;
30
31
  readonly liveQueries: LiveQueries<HeldCover>;
31
32
  readonly figures: FiguresRead;
32
33
  readonly lastAnswers: ReadAnswers;
34
+ readonly discover: () => Promise<void>;
35
+ readonly adopt: (unstored: Discovery) => Promise<void>;
33
36
  };
34
37
  //# sourceMappingURL=runtime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAA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,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC;IAC3E,QAAQ,CAAC,SAAS,EAAE,CAAC,WAAW,EAAE,eAAe,KAAK,SAAS,CAAC;IAChE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,aAAa,EAAE,iBAAiB,CAAC;IAC1C,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAC7C,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,QAAQ,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD,CAAC"}
package/dist/save.d.ts CHANGED
@@ -9,6 +9,7 @@ import { type ChangedPart, type RoomDraftRecord, type SavedDraft } from './room-
9
9
  export type SaveRefusal = {
10
10
  code: string;
11
11
  retryable: boolean;
12
+ message?: string;
12
13
  file?: string;
13
14
  location?: string;
14
15
  line?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../src/save.ts"],"names":[],"mappings":"AACA,OAAO,EAqBL,KAAK,UAAU,EAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAmB,aAAa,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAOL,KAAK,WAAW,EAIhB,KAAK,SAAS,EACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAQL,KAAK,WAAW,EACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAwB,KAAK,KAAK,EAAE,MAAM,cAAc,CAAC;AAEhE,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc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,CAAC,CAE7F"}
package/dist/save.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { apply, ARRAY_INDEX, ATTACHMENT, create, links, parse, pointerSegments, references, relative, relativize, retarget, roomReferences, serialize, target, } from '@agentshouse/mdmodel';
2
2
  import { immutable, isPart, leaving, queuedFile, departure, } from './change.js';
3
- import { collectionOf, definitionsAt, documentsOf, governing, textType, typedText, } from './collection.js';
3
+ import { collectionOf, definitionsAt, documentsOf, governing, typeAt, UNTYPED, } from './collection.js';
4
4
  import { changeBatchIdentity, roomDraftRevision } from './identity.js';
5
5
  import { composed, overlaying } from './overlay.js';
6
6
  import { ancestors } from './paths.js';
@@ -817,8 +817,8 @@ function* limiting(queue, batch, limits, state) {
817
817
  const limited = yield* exceeding(limits, batch.changes, rewritten.changes, yield* state(queue.slice(0, at + 1)));
818
818
  return limited?.refusal ?? null;
819
819
  }
820
- function typedContent(content) {
821
- return content !== undefined && typedText(parse(content));
820
+ function typedContent(composition, path, content) {
821
+ return (content !== undefined && (typeAt(composition, path, parse(content)) ?? UNTYPED) !== UNTYPED);
822
822
  }
823
823
  function touchedLibrary(resulting, touched, composition) {
824
824
  const entries = touched
@@ -838,7 +838,7 @@ function touchedLibrary(resulting, touched, composition) {
838
838
  if (binaries.has(path))
839
839
  known.set(path, { type: undefined, binary: true });
840
840
  else if (content !== undefined && content !== null) {
841
- const type = textType(parse(content, path, definitionsAt(composition, path)));
841
+ const type = typeAt(composition, path, parse(content, path, definitionsAt(composition, path)));
842
842
  if (type !== undefined)
843
843
  known.set(path, { type, binary: false });
844
844
  await pace(content.length + ROW_WEIGHT);
@@ -858,7 +858,7 @@ async function judging(visible, resulting, composition, validate, removed, touch
858
858
  for (const path of touched) {
859
859
  const before = visible.documents[path];
860
860
  const after = resulting.documents[path];
861
- if (typedContent(before) || typedContent(after))
861
+ if (typedContent(composition, path, before) || typedContent(composition, path, after))
862
862
  typedPaths.push(path);
863
863
  await pace((before?.length ?? 0) + (after?.length ?? 0) + ROW_WEIGHT);
864
864
  }
@@ -1097,7 +1097,7 @@ function unreadable(saved, visible, composition) {
1097
1097
  const path = saved.find(({ path: at, parts }) => (parts.fields !== undefined ||
1098
1098
  parts.sections !== undefined ||
1099
1099
  parts.preamble !== undefined) &&
1100
- typedContent(visible.documents[at]) &&
1100
+ typedContent(composition, at, visible.documents[at]) &&
1101
1101
  governing(composition, at).status === 'unavailable')?.path;
1102
1102
  return path === undefined ? null : refuse('model-unavailable', path);
1103
1103
  }
package/dist/saves.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { type ChangeBatch, type WrittenBy } from './change.js';
2
- import { type AttachAnswer, type BinaryLinkAnswer, type HeldBinaryAnswer, type HeldShownAnswer } from './outcome.js';
2
+ import type { ConversationFiles } from './conversation.js';
3
+ import { type AttachAnswer, type AttachmentLinkAnswer, type HeldAttachmentAnswer, type HeldShownAnswer } from './outcome.js';
3
4
  import { type RoomDraftParts } from './room-draft.js';
4
5
  import type { Runtime } from './runtime.js';
5
6
  import { type SaveRefusal } from './save.js';
@@ -18,9 +19,9 @@ export type SavedParts = {
18
19
  readonly path: string;
19
20
  readonly parts: RoomDraftParts;
20
21
  };
21
- export type BinaryFileSurface = {
22
- read(room: string, path: string, revision?: string): Promise<HeldBinaryAnswer>;
23
- link(room: string, path: string, revision?: string): Promise<BinaryLinkAnswer>;
22
+ export type AttachmentSurface = {
23
+ read(room: string, path: string, revision?: string): Promise<HeldAttachmentAnswer>;
24
+ link(room: string, path: string, revision?: string): Promise<AttachmentLinkAnswer>;
24
25
  show(room: string, path: string, revision?: string): Promise<HeldShownAnswer>;
25
26
  attach(room: string, file: File): Promise<AttachAnswer>;
26
27
  part(file: string, part: number): Promise<Uint8Array | null>;
@@ -28,5 +29,6 @@ export type BinaryFileSurface = {
28
29
  export declare function saveRoomDrafts(runtime: Runtime, locator: string, named: readonly SavedRoomDraft[], writtenBy: WrittenBy | undefined): Promise<SaveResult>;
29
30
  export declare function saveParts(runtime: Runtime, locator: string, named: readonly SavedParts[], writtenBy: WrittenBy | undefined): Promise<SaveResult>;
30
31
  export declare function batchFile(store: Store, batch: ChangeBatch): (localId: string) => Promise<Blob>;
31
- export declare function binaryFileSurface(runtime: Runtime): BinaryFileSurface;
32
+ export declare function conversationFiles(runtime: Runtime): ConversationFiles;
33
+ export declare function attachmentSurface(runtime: Runtime): AttachmentSurface;
32
34
  //# sourceMappingURL=saves.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"saves.d.ts","sourceRoot":"","sources":["../src/saves.ts"],"names":[],"mappings":"AAIA,OAAO,EAA2B,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAQxF,OAAO,EAQL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EAErB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACrB,MAAM,cAAc,CAAC;AAatB,OAAO,EAQL,KAAK,cAAc,EAGpB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAGL,KAAK,WAAW,EAGjB,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAsB,KAAK,EAAoB,MAAM,YAAY,CAAC;AAK9E,MAAM,MAAM,UAAU,GAClB;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACxC,CAAC;IAAE,OAAO,EAAE,SAAS,CAAA;CAAE,GAAG,WAAW,CAAC,CAAC;AAE3C,MAAM,MAAM,cAAc,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAElF,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAA;CAAE,CAAC;AAEnF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,CAAC,IA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AE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAC9E,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACxD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;CAC9D,CAAC;AAYF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,SAAS,cAAc,EAAE,EAChC,SAAS,EAAE,SAAS,GAAG,SAAS,GAC/B,OAAO,CAAC,UAAU,CAAC,CAsCrB;AAuBD,wBAAgB,SAAS,CACvB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,SAAS,EAAE,SAAS,GAAG,SAAS,GAC/B,OAAO,CAAC,UAAU,CAAC,CAyBrB;AAuOD,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAK9F;AA+RD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,iBAAiB,CAKrE;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,iBAAiB,CAQrE"}
package/dist/saves.js CHANGED
@@ -1,20 +1,20 @@
1
1
  import { isImageType, parse } from '@agentshouse/mdmodel';
2
- import { binaryRecord } from './binary.js';
2
+ import { attachmentRecord } from './attachment.js';
3
3
  import { changeSet } from './change-set.js';
4
4
  import { queuedFile } from './change.js';
5
- import { available, textType } from './collection.js';
5
+ import { available, definitionsAt, typeAt } from './collection.js';
6
6
  import { runtimeError } from './failure.js';
7
7
  import { attachedFile } from './file.js';
8
8
  import { roomDraftRevision } from './identity.js';
9
9
  import { compositionFor } from './listing.js';
10
10
  import { scoped } from './models.js';
11
- import { absentBinary, attachAnswer, binaryAnswer, binaryLinkAnswer, failure, OFFLINE, UNCERTAIN, } from './outcome.js';
12
- import { sameBinary } from './overlay.js';
11
+ import { absentAttachment, attachAnswer, attachmentAnswer, attachmentLinkAnswer, failure, linkedAnswer, OFFLINE, UNCERTAIN, } from './outcome.js';
12
+ import { sameAttachment } from './overlay.js';
13
13
  import { ancestors } from './paths.js';
14
14
  import { connectionNow } from './preparation.js';
15
15
  import { append, sliceAt, withdrawable } from './queue.js';
16
16
  import { entryAt, replaying, slicing, } from './replica.js';
17
- import { binaryBase, changesOf, held, heldFile, joinedOver, moveTarget, readSavedParts, } from './room-draft.js';
17
+ import { attachmentBase, changesOf, held, heldFile, joinedOver, moveTarget, readSavedParts, } from './room-draft.js';
18
18
  import { refuse } from './refusal.js';
19
19
  import { visibleOf } from './room-drafts.js';
20
20
  import { destination, planSave, } from './save.js';
@@ -77,7 +77,7 @@ export function saveParts(runtime, locator, named, writtenBy) {
77
77
  for (const { path, parts } of read) {
78
78
  const file = parts.file === undefined
79
79
  ? undefined
80
- : await heldFile(parts.file.blob, parts.file.base === undefined ? binaryBase(visible, path) : parts.file.base);
80
+ : await heldFile(parts.file.blob, parts.file.base === undefined ? attachmentBase(visible, path) : parts.file.base);
81
81
  if (parts.file !== undefined && file !== undefined) {
82
82
  files.push({ key: file.localId, blob: parts.file.blob });
83
83
  }
@@ -159,7 +159,7 @@ async function loaded(runtime, locator, replica, saved, consumed, files, written
159
159
  }
160
160
  function textDiffers(left, right) {
161
161
  return ((left?.content ?? undefined) !== (right?.content ?? undefined) ||
162
- !sameBinary(left?.binary ?? undefined, right?.binary ?? undefined));
162
+ !sameAttachment(left?.binary ?? undefined, right?.binary ?? undefined));
163
163
  }
164
164
  function textOf(entry) {
165
165
  if (entry === null)
@@ -176,12 +176,16 @@ function lookupOf(local, key, view) {
176
176
  ]));
177
177
  };
178
178
  }
179
- function declaredOf(entry) {
179
+ function declaredOf(composition, path, entry) {
180
180
  if (entry.binary !== null)
181
181
  return { type: undefined, binary: true };
182
- return { type: textType(parse(entry.content ?? '')), binary: false };
182
+ const content = entry.content ?? '';
183
+ return {
184
+ type: typeAt(composition, path, parse(content, path, definitionsAt(composition, path))),
185
+ binary: false,
186
+ };
183
187
  }
184
- function overriddenLookup(lookup, overrides) {
188
+ function overriddenLookup(composition, lookup, overrides) {
185
189
  return async (paths) => {
186
190
  const known = new Map(await lookup(paths.filter((path) => !overrides.has(path))));
187
191
  for (const path of paths) {
@@ -191,7 +195,7 @@ function overriddenLookup(lookup, overrides) {
191
195
  if (entry === null)
192
196
  known.delete(path);
193
197
  else
194
- known.set(path, declaredOf(entry));
198
+ known.set(path, declaredOf(composition, path, entry));
195
199
  }
196
200
  return known;
197
201
  };
@@ -212,10 +216,12 @@ function validatorOf(runtime, record, confirmedLayer) {
212
216
  if (textOf(was) !== textOf(now))
213
217
  changes.push({ path, was: textOf(was), now: textOf(now) });
214
218
  }
215
- return validatedNeighbourhood(changes, compositionFor(runtime, record), {
216
- lookup: overriddenLookup(lookupOf(local, record.key, 'confirmed'), overrides),
219
+ const composition = compositionFor(runtime, record);
220
+ return validatedNeighbourhood(changes, composition, {
221
+ lookup: overriddenLookup(composition, lookupOf(local, record.key, 'confirmed'), overrides),
217
222
  texts: textsOf(local, record.key, 'confirmed'),
218
223
  referrers: referrersOf(local, record.key, 'confirmed'),
224
+ holders: (sought) => local.holders(record.key, 'confirmed', sought),
219
225
  });
220
226
  };
221
227
  }
@@ -245,7 +251,7 @@ export function batchFile(store, batch) {
245
251
  return (await store.open()).file(localId, change?.kind === 'binary' ? change.mediaType : '');
246
252
  };
247
253
  }
248
- async function transferBinary(runtime, request, transfer, answer) {
254
+ async function transferAttachment(runtime, request, transfer, answer) {
249
255
  const { store, socket, presence } = runtime;
250
256
  const { session } = socket;
251
257
  if (socket.closed() || session.now().refusal !== null)
@@ -266,7 +272,7 @@ async function transferBinary(runtime, request, transfer, answer) {
266
272
  try {
267
273
  const result = await transfer(authorization);
268
274
  const settled = result;
269
- if (presence.lostSince(request.locator, since))
275
+ if (request.locator !== null && presence.lostSince(request.locator, since))
270
276
  return failure({ kind: 'room-not-readable', locator: request.locator });
271
277
  if (settled.kind === 'scoped-refusal') {
272
278
  const room = await store.record(settled.locator);
@@ -281,19 +287,19 @@ async function transferBinary(runtime, request, transfer, answer) {
281
287
  return UNCERTAIN;
282
288
  }
283
289
  }
284
- function fetchBinary(runtime, request, name) {
290
+ function fetchAttachment(runtime, request, name) {
285
291
  const { store, socket } = runtime;
286
- return transferBinary(runtime, request, (authorization) => store.opened.fetch(name, () => socket.binary(authorization, request)), binaryAnswer);
292
+ return transferAttachment(runtime, request, (authorization) => store.opened.fetch(name, () => socket.binary(authorization, request)), attachmentAnswer);
287
293
  }
288
- async function readBinary(runtime, request, name) {
294
+ async function readAttachment(runtime, request, name) {
289
295
  if (runtime.socket.closed())
290
296
  return UNCERTAIN;
291
297
  const held = await runtime.store.opened.find(name);
292
298
  if (held !== null)
293
299
  return held;
294
- return fetchBinary(runtime, request, name);
300
+ return fetchAttachment(runtime, request, name);
295
301
  }
296
- async function binaryPath(store, locator, path, revision) {
302
+ async function attachmentPath(store, locator, path, revision) {
297
303
  if (revision !== undefined)
298
304
  return { kind: 'path', locator, path, revision };
299
305
  const replica = await store.replica(locator);
@@ -306,7 +312,7 @@ async function binaryPath(store, locator, path, revision) {
306
312
  return null;
307
313
  if (held.binary.state === 'pending')
308
314
  return { kind: 'pending', localId: held.binary.localId };
309
- const record = binaryRecord(path, held.binary, held.revision ?? undefined);
315
+ const record = attachmentRecord(path, held.binary, held.revision ?? undefined);
310
316
  if (record.state !== 'accepted')
311
317
  return null;
312
318
  const queued = replica.queue.flatMap((batch) => batch.changes);
@@ -334,17 +340,17 @@ async function binaryPath(store, locator, path, revision) {
334
340
  revision: record.revision,
335
341
  };
336
342
  }
337
- async function askedBinary({ store, socket }, locator, path, revision) {
343
+ async function askedAttachment({ store, socket }, locator, path, revision) {
338
344
  await socket.ready;
339
345
  const drafted = (await store.draft(locator, path))?.parts.file;
340
346
  return drafted !== undefined && drafted.localId === revision
341
347
  ? { kind: 'pending', localId: revision }
342
- : binaryPath(store, locator, path, revision);
348
+ : attachmentPath(store, locator, path, revision);
343
349
  }
344
- async function pendingBinary(store, locator, path, localId) {
350
+ async function pendingAttachment(store, locator, path, localId) {
345
351
  const facts = await queuedFacts(store, locator, path, localId);
346
352
  return facts === null
347
- ? absentBinary(path)
353
+ ? absentAttachment(path)
348
354
  : {
349
355
  kind: 'binary',
350
356
  file: localId,
@@ -352,13 +358,13 @@ async function pendingBinary(store, locator, path, localId) {
352
358
  mediaType: facts.mediaType,
353
359
  };
354
360
  }
355
- async function readBinaryPath(runtime, locator, path, revision) {
356
- const asked = await askedBinary(runtime, locator, path, revision);
361
+ async function readAttachmentPath(runtime, locator, path, revision) {
362
+ const asked = await askedAttachment(runtime, locator, path, revision);
357
363
  if (asked === null)
358
- return absentBinary(path);
364
+ return absentAttachment(path);
359
365
  if (asked.kind === 'pending')
360
- return pendingBinary(runtime.store, locator, path, asked.localId);
361
- return readBinary(runtime, asked, { locator, path: asked.path, revision: asked.revision });
366
+ return pendingAttachment(runtime.store, locator, path, asked.localId);
367
+ return readAttachment(runtime, asked, { locator, path: asked.path, revision: asked.revision });
362
368
  }
363
369
  async function heldMediaType(store, locator, path) {
364
370
  const replica = await store.record(locator);
@@ -366,23 +372,42 @@ async function heldMediaType(store, locator, path) {
366
372
  return held === undefined ? store.attached.of(locator, path)?.mediaType : held.binary?.mediaType;
367
373
  }
368
374
  function linkOf(runtime, asked, held) {
369
- return transferBinary(runtime, asked, (authorization) => runtime.socket.link(authorization, asked), (result) => binaryLinkAnswer(result, held));
375
+ return transferAttachment(runtime, asked, (authorization) => runtime.socket.link(authorization, asked), (result) => attachmentLinkAnswer(result, held));
370
376
  }
371
- async function linkBinaryPath(runtime, locator, path, revision) {
377
+ async function linkAttachmentPath(runtime, locator, path, revision) {
372
378
  const { store, socket } = runtime;
373
379
  await socket.ready;
374
- const asked = await binaryPath(store, locator, path, revision);
380
+ const asked = await attachmentPath(store, locator, path, revision);
375
381
  if (asked === null || asked.kind === 'pending')
376
- return absentBinary(path);
382
+ return absentAttachment(path);
377
383
  return linkOf(runtime, asked, revision === undefined ? await heldMediaType(store, locator, path) : undefined);
378
384
  }
379
- async function showBinaryPath(runtime, locator, path, revision) {
385
+ function shownImage(runtime, asked, name) {
386
+ const { store, socket } = runtime;
387
+ return new Promise((answer) => {
388
+ void transferAttachment(runtime, asked, (authorization) => store.opened.fetch(name, async () => {
389
+ const read = await socket.binary(authorization, asked);
390
+ const copies = read.kind === 'binary' ? (read.copies ?? []) : [];
391
+ if (read.kind === 'binary' && read.url !== undefined && copies.length > 0) {
392
+ answer({
393
+ kind: 'link',
394
+ url: read.url,
395
+ name: asked.path.slice(asked.path.lastIndexOf('/') + 1),
396
+ mediaType: read.mediaType,
397
+ copies,
398
+ });
399
+ }
400
+ return read;
401
+ }), attachmentAnswer).then(answer);
402
+ });
403
+ }
404
+ async function showAttachmentPath(runtime, locator, path, revision) {
380
405
  const { store } = runtime;
381
- const asked = await askedBinary(runtime, locator, path, revision);
406
+ const asked = await askedAttachment(runtime, locator, path, revision);
382
407
  if (asked === null)
383
- return absentBinary(path);
408
+ return absentAttachment(path);
384
409
  if (asked.kind === 'pending')
385
- return pendingBinary(store, locator, path, asked.localId);
410
+ return pendingAttachment(store, locator, path, asked.localId);
386
411
  if (runtime.socket.closed())
387
412
  return UNCERTAIN;
388
413
  const name = { locator, path: asked.path, revision: asked.revision };
@@ -391,10 +416,11 @@ async function showBinaryPath(runtime, locator, path, revision) {
391
416
  return kept;
392
417
  const mediaType = await heldMediaType(store, locator, path);
393
418
  if (mediaType !== undefined && isImageType(mediaType))
394
- return fetchBinary(runtime, asked, name);
395
- return linkOf(runtime, asked, revision === undefined ? mediaType : undefined);
419
+ return shownImage(runtime, asked, name);
420
+ const linked = await linkOf(runtime, asked, revision === undefined ? mediaType : undefined);
421
+ return linked.kind === 'link' ? { ...linked, copies: [] } : linked;
396
422
  }
397
- async function attachBinary(runtime, locator, file) {
423
+ async function attachFile(runtime, locator, file, answer) {
398
424
  const { store, socket } = runtime;
399
425
  await socket.ready;
400
426
  await socket.firstDiscovery;
@@ -404,23 +430,34 @@ async function attachBinary(runtime, locator, file) {
404
430
  socket.session.now().refusal !== null)
405
431
  return OFFLINE;
406
432
  const request = await attachedFile(locator, file);
407
- return transferBinary(runtime, { locator, path: file.name }, async (held) => {
433
+ return transferAttachment(runtime, { locator }, async (held) => {
408
434
  const result = await socket.attach(held, request);
409
- if (result.kind === 'attached') {
435
+ if (result.kind === 'attached' && locator !== null) {
410
436
  store.attached.hold(locator, result.path, {
411
437
  revision: result.revision,
412
438
  mediaType: request.mediaType,
413
439
  });
414
440
  }
415
441
  return result;
416
- }, attachAnswer);
442
+ }, answer);
443
+ }
444
+ async function keyedAttachment(runtime, link) {
445
+ await runtime.socket.ready;
446
+ const asked = { kind: 'key', link };
447
+ return transferAttachment(runtime, { locator: null }, (authorization) => runtime.socket.link(authorization, asked), (result) => attachmentLinkAnswer(result));
448
+ }
449
+ export function conversationFiles(runtime) {
450
+ return {
451
+ attach: (file) => attachFile(runtime, null, file, linkedAnswer),
452
+ attachment: (link) => keyedAttachment(runtime, link),
453
+ };
417
454
  }
418
- export function binaryFileSurface(runtime) {
455
+ export function attachmentSurface(runtime) {
419
456
  return {
420
457
  part: runtime.store.part,
421
- read: (room, path, revision) => readBinaryPath(runtime, room, path, revision),
422
- link: (room, path, revision) => linkBinaryPath(runtime, room, path, revision),
423
- show: (room, path, revision) => showBinaryPath(runtime, room, path, revision),
424
- attach: (room, file) => attachBinary(runtime, room, file),
458
+ read: (room, path, revision) => readAttachmentPath(runtime, room, path, revision),
459
+ link: (room, path, revision) => linkAttachmentPath(runtime, room, path, revision),
460
+ show: (room, path, revision) => showAttachmentPath(runtime, room, path, revision),
461
+ attach: (room, file) => attachFile(runtime, room, file, attachAnswer),
425
462
  };
426
463
  }
@@ -0,0 +1,3 @@
1
+ export declare function selectorRewritten(value: unknown, selector: string, rewrite: (selected: unknown) => unknown): unknown;
2
+ export declare function selectorValues(value: unknown, selector: string): readonly unknown[];
3
+ //# sourceMappingURL=selector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selector.d.ts","sourceRoot":"","sources":["../src/selector.ts"],"names":[],"mappings":"AAaA,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,OAAO,GACtC,OAAO,CAET;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,OAAO,EAAE,CAOnF"}