@agentshouse/mdruntime 0.1.0-cff8ba8fa2542 → 0.1.0-cffcba9cd9c2f

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 (327) hide show
  1. package/README.md +24 -11
  2. package/dist/acceptance.d.ts +3 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +309 -0
  5. package/dist/actions.d.ts +20 -0
  6. package/dist/actions.d.ts.map +1 -0
  7. package/dist/actions.js +251 -0
  8. package/dist/adapter.d.ts +195 -88
  9. package/dist/adapter.d.ts.map +1 -1
  10. package/dist/attached-model.d.ts +7 -10
  11. package/dist/attached-model.d.ts.map +1 -1
  12. package/dist/attached-model.js +40 -28
  13. package/dist/attempt.d.ts +16 -0
  14. package/dist/attempt.d.ts.map +1 -0
  15. package/dist/attempt.js +70 -0
  16. package/dist/binary.d.ts +18 -0
  17. package/dist/binary.d.ts.map +1 -0
  18. package/dist/binary.js +8 -0
  19. package/dist/bootstrap.d.ts +37 -5
  20. package/dist/bootstrap.d.ts.map +1 -1
  21. package/dist/bootstrap.js +324 -51
  22. package/dist/cell.d.ts +6 -0
  23. package/dist/cell.d.ts.map +1 -0
  24. package/dist/cell.js +9 -0
  25. package/dist/chain.d.ts +12 -0
  26. package/dist/chain.d.ts.map +1 -0
  27. package/dist/chain.js +64 -0
  28. package/dist/change-set.d.ts +13 -14
  29. package/dist/change-set.d.ts.map +1 -1
  30. package/dist/change-set.js +17 -56
  31. package/dist/change.d.ts +46 -0
  32. package/dist/change.d.ts.map +1 -1
  33. package/dist/change.js +36 -0
  34. package/dist/chat-types.d.ts +5 -0
  35. package/dist/chat-types.d.ts.map +1 -0
  36. package/dist/chat-types.js +13 -0
  37. package/dist/client.d.ts +56 -18
  38. package/dist/client.d.ts.map +1 -1
  39. package/dist/client.js +164 -23
  40. package/dist/collection.d.ts +31 -14
  41. package/dist/collection.d.ts.map +1 -1
  42. package/dist/collection.js +61 -55
  43. package/dist/compile.d.ts +16 -0
  44. package/dist/compile.d.ts.map +1 -0
  45. package/dist/compile.js +711 -0
  46. package/dist/connection.d.ts +8 -103
  47. package/dist/connection.d.ts.map +1 -1
  48. package/dist/connection.js +103 -2076
  49. package/dist/context.d.ts +2 -0
  50. package/dist/context.d.ts.map +1 -0
  51. package/dist/context.js +7 -0
  52. package/dist/conversation-live.d.ts +135 -0
  53. package/dist/conversation-live.d.ts.map +1 -0
  54. package/dist/conversation-live.js +247 -0
  55. package/dist/conversation-row.d.ts +33 -0
  56. package/dist/conversation-row.d.ts.map +1 -0
  57. package/dist/conversation-row.js +53 -0
  58. package/dist/conversation.d.ts +67 -44
  59. package/dist/conversation.d.ts.map +1 -1
  60. package/dist/conversation.js +1010 -549
  61. package/dist/declaration.d.ts +10 -0
  62. package/dist/declaration.d.ts.map +1 -0
  63. package/dist/declaration.js +24 -0
  64. package/dist/digest.d.ts +7 -0
  65. package/dist/digest.d.ts.map +1 -0
  66. package/dist/digest.js +113 -0
  67. package/dist/discovery.d.ts +10 -0
  68. package/dist/discovery.d.ts.map +1 -0
  69. package/dist/discovery.js +177 -0
  70. package/dist/durability.d.ts +19 -1
  71. package/dist/durability.d.ts.map +1 -1
  72. package/dist/durability.js +5 -0
  73. package/dist/entry.d.ts +20 -0
  74. package/dist/entry.d.ts.map +1 -0
  75. package/dist/entry.js +161 -0
  76. package/dist/expectation.d.ts +23 -0
  77. package/dist/expectation.d.ts.map +1 -0
  78. package/dist/expectation.js +92 -0
  79. package/dist/failure.d.ts +14 -0
  80. package/dist/failure.d.ts.map +1 -0
  81. package/dist/failure.js +22 -0
  82. package/dist/figures.d.ts +49 -0
  83. package/dist/figures.d.ts.map +1 -0
  84. package/dist/figures.js +197 -0
  85. package/dist/file.d.ts +2 -19
  86. package/dist/file.d.ts.map +1 -1
  87. package/dist/file.js +7 -122
  88. package/dist/holdings.d.ts +29 -0
  89. package/dist/holdings.d.ts.map +1 -0
  90. package/dist/holdings.js +95 -0
  91. package/dist/host.d.ts +28 -3
  92. package/dist/host.d.ts.map +1 -1
  93. package/dist/host.js +149 -26
  94. package/dist/identity.d.ts +3 -0
  95. package/dist/identity.d.ts.map +1 -1
  96. package/dist/identity.js +13 -1
  97. package/dist/index.d.ts +39 -10
  98. package/dist/index.d.ts.map +1 -1
  99. package/dist/index.js +16 -0
  100. package/dist/install.d.ts +55 -0
  101. package/dist/install.d.ts.map +1 -0
  102. package/dist/install.js +543 -0
  103. package/dist/job.d.ts +5 -0
  104. package/dist/job.d.ts.map +1 -0
  105. package/dist/job.js +7 -0
  106. package/dist/lifecycle.d.ts +7 -0
  107. package/dist/lifecycle.d.ts.map +1 -0
  108. package/dist/lifecycle.js +271 -0
  109. package/dist/listing.d.ts +52 -0
  110. package/dist/listing.d.ts.map +1 -0
  111. package/dist/listing.js +168 -0
  112. package/dist/live.d.ts +23 -0
  113. package/dist/live.d.ts.map +1 -0
  114. package/dist/live.js +165 -0
  115. package/dist/locks.d.ts +9 -0
  116. package/dist/locks.d.ts.map +1 -0
  117. package/dist/locks.js +62 -0
  118. package/dist/log.d.ts +1 -0
  119. package/dist/log.d.ts.map +1 -1
  120. package/dist/lost.d.ts +5 -0
  121. package/dist/lost.d.ts.map +1 -0
  122. package/dist/lost.js +61 -0
  123. package/dist/media.d.ts +8 -0
  124. package/dist/media.d.ts.map +1 -0
  125. package/dist/media.js +218 -0
  126. package/dist/memory.d.ts +25 -8
  127. package/dist/memory.d.ts.map +1 -1
  128. package/dist/memory.js +296 -93
  129. package/dist/messages.d.ts +49 -0
  130. package/dist/messages.d.ts.map +1 -0
  131. package/dist/messages.js +148 -0
  132. package/dist/model.d.ts +16 -9
  133. package/dist/model.d.ts.map +1 -1
  134. package/dist/model.js +9 -15
  135. package/dist/models.d.ts +10 -0
  136. package/dist/models.d.ts.map +1 -0
  137. package/dist/models.js +170 -0
  138. package/dist/name.d.ts +4 -0
  139. package/dist/name.d.ts.map +1 -0
  140. package/dist/name.js +122 -0
  141. package/dist/observation.d.ts +22 -4
  142. package/dist/observation.d.ts.map +1 -1
  143. package/dist/observation.js +127 -26
  144. package/dist/open.d.ts +2 -0
  145. package/dist/open.d.ts.map +1 -0
  146. package/dist/open.js +1 -0
  147. package/dist/opened.d.ts +22 -0
  148. package/dist/opened.d.ts.map +1 -0
  149. package/dist/opened.js +107 -0
  150. package/dist/opening.d.ts +4 -0
  151. package/dist/opening.d.ts.map +1 -0
  152. package/dist/opening.js +59 -0
  153. package/dist/outcome.d.ts +75 -5
  154. package/dist/outcome.d.ts.map +1 -1
  155. package/dist/outcome.js +84 -1
  156. package/dist/overlay.d.ts +17 -5
  157. package/dist/overlay.d.ts.map +1 -1
  158. package/dist/overlay.js +168 -190
  159. package/dist/parts.d.ts +11 -0
  160. package/dist/parts.d.ts.map +1 -0
  161. package/dist/parts.js +21 -0
  162. package/dist/paths.d.ts +2 -1
  163. package/dist/paths.d.ts.map +1 -1
  164. package/dist/paths.js +26 -16
  165. package/dist/preparation.d.ts +20 -0
  166. package/dist/preparation.d.ts.map +1 -0
  167. package/dist/preparation.js +233 -0
  168. package/dist/queries.d.ts +16 -0
  169. package/dist/queries.d.ts.map +1 -0
  170. package/dist/queries.js +272 -0
  171. package/dist/query.d.ts +51 -181
  172. package/dist/query.d.ts.map +1 -1
  173. package/dist/query.js +3 -431
  174. package/dist/questions.d.ts +34 -0
  175. package/dist/questions.d.ts.map +1 -0
  176. package/dist/questions.js +122 -0
  177. package/dist/queue.d.ts +32 -0
  178. package/dist/queue.d.ts.map +1 -0
  179. package/dist/queue.js +402 -0
  180. package/dist/reach.d.ts +21 -5
  181. package/dist/reach.d.ts.map +1 -1
  182. package/dist/reach.js +306 -96
  183. package/dist/react.d.ts +43 -19
  184. package/dist/react.d.ts.map +1 -1
  185. package/dist/react.js +22 -21
  186. package/dist/read.d.ts +7 -0
  187. package/dist/read.d.ts.map +1 -0
  188. package/dist/read.js +17 -0
  189. package/dist/readiness.d.ts +49 -0
  190. package/dist/readiness.d.ts.map +1 -0
  191. package/dist/readiness.js +27 -0
  192. package/dist/reads.d.ts +37 -0
  193. package/dist/reads.d.ts.map +1 -0
  194. package/dist/reads.js +174 -0
  195. package/dist/recovery.d.ts +26 -0
  196. package/dist/recovery.d.ts.map +1 -0
  197. package/dist/recovery.js +232 -0
  198. package/dist/refresh.d.ts +20 -7
  199. package/dist/refresh.d.ts.map +1 -1
  200. package/dist/refresh.js +155 -59
  201. package/dist/refusal.d.ts +5 -0
  202. package/dist/refusal.d.ts.map +1 -0
  203. package/dist/refusal.js +57 -0
  204. package/dist/replica.d.ts +53 -33
  205. package/dist/replica.d.ts.map +1 -1
  206. package/dist/replica.js +361 -164
  207. package/dist/room-draft.d.ts +59 -12
  208. package/dist/room-draft.d.ts.map +1 -1
  209. package/dist/room-draft.js +299 -90
  210. package/dist/room-drafts.d.ts +24 -0
  211. package/dist/room-drafts.d.ts.map +1 -0
  212. package/dist/room-drafts.js +217 -0
  213. package/dist/rows.d.ts +32 -34
  214. package/dist/rows.d.ts.map +1 -1
  215. package/dist/rows.js +67 -87
  216. package/dist/runtime.d.ts +32 -0
  217. package/dist/runtime.d.ts.map +1 -0
  218. package/dist/runtime.js +1 -0
  219. package/dist/save.d.ts +74 -5
  220. package/dist/save.d.ts.map +1 -1
  221. package/dist/save.js +914 -188
  222. package/dist/saves.d.ts +32 -0
  223. package/dist/saves.d.ts.map +1 -0
  224. package/dist/saves.js +679 -0
  225. package/dist/search.d.ts +15 -54
  226. package/dist/search.d.ts.map +1 -1
  227. package/dist/search.js +10 -121
  228. package/dist/seed.d.ts +25 -0
  229. package/dist/seed.d.ts.map +1 -0
  230. package/dist/seed.js +145 -0
  231. package/dist/shared.d.ts +10 -0
  232. package/dist/shared.d.ts.map +1 -0
  233. package/dist/shared.js +339 -0
  234. package/dist/shown.d.ts +32 -0
  235. package/dist/shown.d.ts.map +1 -0
  236. package/dist/shown.js +299 -0
  237. package/dist/socket/admission.d.ts +7 -0
  238. package/dist/socket/admission.d.ts.map +1 -0
  239. package/dist/socket/admission.js +39 -0
  240. package/dist/socket/answers.d.ts +6 -0
  241. package/dist/socket/answers.d.ts.map +1 -0
  242. package/dist/socket/answers.js +20 -0
  243. package/dist/socket/lanes.d.ts +20 -0
  244. package/dist/socket/lanes.d.ts.map +1 -0
  245. package/dist/socket/lanes.js +77 -0
  246. package/dist/socket/reads.d.ts +10 -0
  247. package/dist/socket/reads.d.ts.map +1 -0
  248. package/dist/socket/reads.js +31 -0
  249. package/dist/socket/rooms.d.ts +41 -0
  250. package/dist/socket/rooms.d.ts.map +1 -0
  251. package/dist/socket/rooms.js +90 -0
  252. package/dist/socket/session.d.ts +38 -0
  253. package/dist/socket/session.d.ts.map +1 -0
  254. package/dist/socket/session.js +23 -0
  255. package/dist/socket.d.ts +69 -0
  256. package/dist/socket.d.ts.map +1 -0
  257. package/dist/socket.js +175 -0
  258. package/dist/source.d.ts +61 -0
  259. package/dist/source.d.ts.map +1 -0
  260. package/dist/source.js +82 -0
  261. package/dist/status.d.ts +7 -4
  262. package/dist/status.d.ts.map +1 -1
  263. package/dist/status.js +3 -15
  264. package/dist/store/fences.d.ts +16 -0
  265. package/dist/store/fences.d.ts.map +1 -0
  266. package/dist/store/fences.js +26 -0
  267. package/dist/store/installs.d.ts +30 -0
  268. package/dist/store/installs.d.ts.map +1 -0
  269. package/dist/store/installs.js +34 -0
  270. package/dist/store/readiness.d.ts +10 -0
  271. package/dist/store/readiness.d.ts.map +1 -0
  272. package/dist/store/readiness.js +52 -0
  273. package/dist/store/records.d.ts +210 -0
  274. package/dist/store/records.d.ts.map +1 -0
  275. package/dist/store/records.js +428 -0
  276. package/dist/store/room-held.d.ts +8 -0
  277. package/dist/store/room-held.d.ts.map +1 -0
  278. package/dist/store/room-held.js +17 -0
  279. package/dist/store/space.d.ts +11 -0
  280. package/dist/store/space.d.ts.map +1 -0
  281. package/dist/store/space.js +41 -0
  282. package/dist/store/watchers.d.ts +17 -0
  283. package/dist/store/watchers.d.ts.map +1 -0
  284. package/dist/store/watchers.js +56 -0
  285. package/dist/store/writes.d.ts +24 -0
  286. package/dist/store/writes.d.ts.map +1 -0
  287. package/dist/store/writes.js +125 -0
  288. package/dist/store.d.ts +106 -92
  289. package/dist/store.d.ts.map +1 -1
  290. package/dist/store.js +142 -385
  291. package/dist/stored.d.ts +156 -0
  292. package/dist/stored.d.ts.map +1 -0
  293. package/dist/stored.js +649 -0
  294. package/dist/surface.d.ts +88 -0
  295. package/dist/surface.d.ts.map +1 -0
  296. package/dist/surface.js +224 -0
  297. package/dist/sync.d.ts +19 -0
  298. package/dist/sync.d.ts.map +1 -0
  299. package/dist/sync.js +530 -0
  300. package/dist/tables.d.ts +412 -0
  301. package/dist/tables.d.ts.map +1 -0
  302. package/dist/tables.js +737 -0
  303. package/dist/tallies.d.ts +18 -0
  304. package/dist/tallies.d.ts.map +1 -0
  305. package/dist/tallies.js +129 -0
  306. package/dist/transfer.d.ts +0 -5
  307. package/dist/transfer.d.ts.map +1 -1
  308. package/dist/turn.d.ts +9 -0
  309. package/dist/turn.d.ts.map +1 -0
  310. package/dist/turn.js +75 -0
  311. package/dist/validation.d.ts +29 -0
  312. package/dist/validation.d.ts.map +1 -0
  313. package/dist/validation.js +104 -0
  314. package/dist/windows.d.ts +11 -0
  315. package/dist/windows.d.ts.map +1 -0
  316. package/dist/windows.js +16 -0
  317. package/dist/wire.d.ts +189 -37
  318. package/dist/wire.d.ts.map +1 -1
  319. package/dist/wire.js +77 -33
  320. package/package.json +27 -15
  321. package/AGENTS.md +0 -231
  322. package/dist/attachment.d.ts +0 -3
  323. package/dist/attachment.d.ts.map +0 -1
  324. package/dist/attachment.js +0 -8
  325. package/dist/read-side.d.ts +0 -18
  326. package/dist/read-side.d.ts.map +0 -1
  327. package/dist/read-side.js +0 -377
package/dist/client.js CHANGED
@@ -1,12 +1,38 @@
1
+ import { shownBy } from './media.js';
1
2
  import { observed } from './observation.js';
2
- import { answer, AUTHORIZATION_ENDED, PORT_CLOSED, } from './wire.js';
3
- export function connectMdRuntime(port) {
3
+ import { runtimeError } from './failure.js';
4
+ import { AUTHORIZATION_ENDED, PORT_CLOSED, wireAnswer, } from './wire.js';
5
+ // React renders an arrived value in a later task and opens what that render observes as it commits, so this many frames opening nothing mean the page drew what it observes.
6
+ const SETTLED_FRAMES = 2;
7
+ // A browser reads a download's address only after the click that hands it returns, so a copy's address is released a minute later.
8
+ const HANDED_COPY_MS = 60_000;
9
+ const PAGE = /\.html?$/iu;
10
+ const STARTED = { kind: 'started' };
11
+ const BLOCKED = {
12
+ kind: 'blocked',
13
+ code: 'popup-blocked',
14
+ fields: {},
15
+ retryable: true,
16
+ };
17
+ function handed(url, name) {
18
+ const anchor = document.createElement('a');
19
+ anchor.href = url;
20
+ anchor.download = name;
21
+ anchor.click();
22
+ }
23
+ function refused(refusal) {
24
+ return runtimeError(refusal.code);
25
+ }
26
+ const UNBUILT = () => Promise.resolve(null);
27
+ export function connectMdRuntime(port, buildFile = UNBUILT) {
4
28
  let sequence = 0;
5
29
  let refusal = null;
6
30
  let ended = null;
7
31
  const calls = new Map();
8
32
  const opening = new Map();
9
33
  const observations = new Map();
34
+ let drawing = null;
35
+ let settling = null;
10
36
  const send = (message) => {
11
37
  port.postMessage(message);
12
38
  };
@@ -25,7 +51,7 @@ export function connectMdRuntime(port) {
25
51
  if (topic === 'connection-refusal')
26
52
  handle.receive(reported);
27
53
  }
28
- const failure = new Error(reported.reason);
54
+ const failure = refused(reported);
29
55
  for (const [id, waiting] of opening) {
30
56
  if (waiting.topic === 'connection-refusal')
31
57
  waiting.settle(begin(id, waiting.topic, reported));
@@ -36,12 +62,12 @@ export function connectMdRuntime(port) {
36
62
  for (const waiting of calls.values())
37
63
  waiting.fail(failure);
38
64
  calls.clear();
65
+ drawing?.();
39
66
  }
40
- function end(reason) {
67
+ function end(failure) {
41
68
  if (ended !== null)
42
69
  return;
43
- ended = reason;
44
- const failure = new Error(reason);
70
+ ended = failure;
45
71
  for (const waiting of opening.values())
46
72
  waiting.fail(failure);
47
73
  opening.clear();
@@ -51,9 +77,10 @@ export function connectMdRuntime(port) {
51
77
  for (const { handle } of observations.values())
52
78
  handle.end();
53
79
  observations.clear();
80
+ drawing?.();
54
81
  }
55
82
  port.addEventListener('message', (event) => {
56
- const message = answer(event.data);
83
+ const message = wireAnswer(event.data);
57
84
  if (message === null)
58
85
  return;
59
86
  if (message.kind === 'refusal') {
@@ -61,7 +88,11 @@ export function connectMdRuntime(port) {
61
88
  return;
62
89
  }
63
90
  if (message.kind === 'ended') {
64
- end(AUTHORIZATION_ENDED);
91
+ for (const { topic, handle } of observations.values()) {
92
+ if (topic === 'member')
93
+ handle.receive(null);
94
+ }
95
+ end(runtimeError('authorization-ended', AUTHORIZATION_ENDED));
65
96
  return;
66
97
  }
67
98
  if (message.kind === 'event') {
@@ -71,31 +102,34 @@ export function connectMdRuntime(port) {
71
102
  const waiting = opening.get(message.id);
72
103
  if (waiting !== undefined) {
73
104
  opening.delete(message.id);
74
- if (message.kind === 'failure')
75
- waiting.fail(new Error(message.message));
105
+ if (message.kind === 'failure') {
106
+ waiting.fail(runtimeError(message.code, message.message, message.retryable));
107
+ }
76
108
  else
77
109
  waiting.settle(begin(message.id, waiting.topic, message.value));
110
+ drawing?.();
78
111
  return;
79
112
  }
80
113
  const called = calls.get(message.id);
81
114
  if (called === undefined)
82
115
  return;
83
116
  calls.delete(message.id);
84
- if (message.kind === 'failure')
85
- called.fail(new Error(message.message));
117
+ if (message.kind === 'failure') {
118
+ called.fail(runtimeError(message.code, message.message, message.retryable));
119
+ }
86
120
  else
87
121
  called.settle(message.value);
88
122
  });
89
123
  port.addEventListener('close', () => {
90
- end(PORT_CLOSED);
124
+ end(runtimeError('port-closed', PORT_CLOSED));
91
125
  });
92
126
  port.start();
93
127
  send({ kind: 'hello' });
94
128
  function ask(member, input) {
95
129
  if (ended !== null)
96
- return Promise.reject(new Error(ended));
130
+ return Promise.reject(ended);
97
131
  if (refusal !== null)
98
- return Promise.reject(new Error(refusal.reason));
132
+ return Promise.reject(refused(refusal));
99
133
  const id = (sequence += 1);
100
134
  return new Promise((settle, fail) => {
101
135
  calls.set(id, { settle: settle, fail });
@@ -104,19 +138,102 @@ export function connectMdRuntime(port) {
104
138
  }
105
139
  function watch(topic, input) {
106
140
  if (ended !== null)
107
- return Promise.reject(new Error(ended));
141
+ return Promise.reject(ended);
108
142
  const id = (sequence += 1);
109
143
  if (refusal !== null) {
110
144
  return topic === 'connection-refusal'
111
145
  ? Promise.resolve(begin(id, topic, refusal))
112
- : Promise.reject(new Error(refusal.reason));
146
+ : Promise.reject(refused(refusal));
113
147
  }
114
148
  return new Promise((settle, fail) => {
115
149
  opening.set(id, { topic, settle, fail });
116
150
  send({ kind: 'observe', id, topic, input });
151
+ drawing?.();
117
152
  });
118
153
  }
119
- return {
154
+ function streamed(answer) {
155
+ if (answer.kind !== 'binary')
156
+ return answer;
157
+ const { file, byteLength, mediaType } = answer;
158
+ let part = 0;
159
+ let received = 0;
160
+ const stream = new ReadableStream({
161
+ async pull(controller) {
162
+ const bytes = await ask('binaryFile.part', [file, part]);
163
+ if (bytes === null) {
164
+ if (received === byteLength)
165
+ controller.close();
166
+ else
167
+ controller.error(runtimeError('binary-file-absent', 'The file ended early'));
168
+ return;
169
+ }
170
+ part += 1;
171
+ received += bytes.byteLength;
172
+ controller.enqueue(bytes);
173
+ },
174
+ }, { highWaterMark: 0 });
175
+ return { kind: 'binary', stream, byteLength, mediaType };
176
+ }
177
+ async function download(room, path, revision) {
178
+ const tab = PAGE.test(path) ? globalThis.open('', '_blank') : null;
179
+ const linked = await ask('binaryFile.link', [room, path, revision]);
180
+ if (linked.kind === 'link' && PAGE.test(linked.name)) {
181
+ const away = tab ?? globalThis.open('', '_blank');
182
+ if (away === null)
183
+ return BLOCKED;
184
+ away.location.replace(linked.url);
185
+ return STARTED;
186
+ }
187
+ tab?.close();
188
+ if (linked.kind === 'link') {
189
+ handed(linked.url, linked.name);
190
+ return STARTED;
191
+ }
192
+ if (linked.kind !== 'absent')
193
+ return linked;
194
+ const read = streamed(await ask('binaryFile.read', [room, path, revision]));
195
+ if (read.kind !== 'binary')
196
+ return read;
197
+ const copy = await new Response(read.stream, {
198
+ headers: { 'content-type': read.mediaType },
199
+ }).blob();
200
+ const url = URL.createObjectURL(copy);
201
+ handed(url, path.slice(path.lastIndexOf('/') + 1));
202
+ setTimeout(() => URL.revokeObjectURL(url), HANDED_COPY_MS);
203
+ return STARTED;
204
+ }
205
+ function settled() {
206
+ if (settling !== null)
207
+ return settling;
208
+ settling = new Promise((resolve) => {
209
+ let moved = 0;
210
+ const check = () => {
211
+ moved += 1;
212
+ if (opening.size > 0)
213
+ return;
214
+ const at = moved;
215
+ const waited = (frames) => {
216
+ requestAnimationFrame(() => {
217
+ if (frames < SETTLED_FRAMES) {
218
+ waited(frames + 1);
219
+ return;
220
+ }
221
+ if (moved !== at || opening.size > 0)
222
+ return;
223
+ drawing = null;
224
+ resolve();
225
+ });
226
+ };
227
+ waited(1);
228
+ };
229
+ drawing = check;
230
+ check();
231
+ });
232
+ return settling;
233
+ }
234
+ const show = (room, path, revision) => ask('binaryFile.show', [room, path, revision]).then((shown) => streamed(shown));
235
+ return shownBy(show, {
236
+ buildFile,
120
237
  rooms: () => ask('rooms', []),
121
238
  query: ((query) => ask('query', [query])),
122
239
  search: (request) => ask('search', [request]),
@@ -124,35 +241,59 @@ export function connectMdRuntime(port) {
124
241
  roomDraft: {
125
242
  list: () => ask('roomDraft.list', []),
126
243
  read: (room, path) => ask('roomDraft.read', [room, path]),
127
- write: (room, path, revision, parts) => ask('roomDraft.write', [room, path, revision, parts]),
244
+ write: (room, path, revision, parts, next) => ask('roomDraft.write', next === undefined ? [room, path, revision, parts] : [room, path, revision, parts, next]),
128
245
  discard: (room, path, revision) => ask('roomDraft.discard', [room, path, revision]),
129
246
  },
130
247
  save: (room, roomDrafts) => ask('save', [room, roomDrafts]),
248
+ saveParts: (room, parts) => ask('saveParts', [room, parts]),
131
249
  presentation: {
132
250
  read: () => ask('presentation.read', []),
133
251
  write: (value) => ask('presentation.write', [value]),
252
+ edit: (members) => ask('presentation.edit', [members]),
134
253
  },
135
254
  conversation: {
136
255
  list: () => ask('conversation.list', []),
137
256
  read: (conversation, options) => ask('conversation.read', [conversation, options]),
138
257
  create: (input) => ask('conversation.create', [input]),
139
- send: (conversation) => ask('conversation.send', [conversation]),
258
+ send: (conversation, operation, draft) => ask('conversation.send', [conversation, operation, draft]),
140
259
  answer: (conversation, answer) => ask('conversation.answer', [conversation, answer]),
141
260
  interrupt: (conversation) => ask('conversation.interrupt', [conversation]),
142
261
  kill: (conversation) => ask('conversation.kill', [conversation]),
143
- cancel: (conversation, turn) => ask('conversation.cancel', [conversation, turn]),
144
262
  delete: (conversation) => ask('conversation.delete', [conversation]),
145
263
  },
146
264
  chatDraft: {
147
- write: (conversation, draft) => ask('chatDraft.write', [conversation, draft]),
265
+ write: (conversation, draft, revision) => ask('chatDraft.write', [conversation, draft, revision]),
266
+ prepend: (conversation, draft) => ask('chatDraft.prepend', [conversation, draft]),
148
267
  discard: (conversation) => ask('chatDraft.discard', [conversation]),
149
268
  },
150
269
  history: (locator, path, query) => ask('history', [locator, path, query]),
270
+ resolve: (room, path, destination) => ask('resolve', [room, path, destination]),
271
+ binaryFile: {
272
+ read: (room, path, revision) => ask('binaryFile.read', [room, path, revision]).then((read) => streamed(read)),
273
+ attach: (room, file) => ask('binaryFile.attach', [room, file]),
274
+ download,
275
+ },
151
276
  call: (name, input) => ask('call', [name, input]),
152
277
  reached: (locator, roomVersion, path) => ask('reached', [locator, roomVersion, path]),
153
278
  log: () => ask('log', []),
154
279
  persistence: () => ask('persistence', []),
280
+ retry: () => ask('retry', []),
281
+ cleanUp: () => ask('cleanUp', []),
282
+ unsent: () => ask('unsent', []),
283
+ reset: () => ask('reset', []),
284
+ readAgain: () => ask('readAgain', []),
155
285
  observe: ((topic, ...input) => watch(topic, input)),
156
286
  reauthorize: () => ask('reauthorize', []),
157
- };
287
+ settled,
288
+ });
289
+ }
290
+ const turns = new WeakMap();
291
+ export function inTurn(client, work) {
292
+ const turn = (turns.get(client) ?? Promise.resolve()).then(work);
293
+ turns.set(client, turn.then(() => undefined, () => undefined));
294
+ return turn;
158
295
  }
296
+ export { chainedWindows } from './chain.js';
297
+ export { roomDraftRevision } from './identity.js';
298
+ export { defineRoomMedia, ROOM_MEDIA } from './media.js';
299
+ export { unanswered } from './wire.js';
@@ -1,11 +1,12 @@
1
- import { type Document, type Validation } from '@agentshouse/mdmodel';
2
- import type { ModelState } from './model.js';
1
+ import { type DefinitionOf, type Document, type TypedPath } from '@agentshouse/mdmodel';
2
+ import type { ModelState, TypesResult } from './model.js';
3
+ import type { AppTypedSelection } from './listing.js';
3
4
  import type { MdModelIdentity } from './adapter.js';
4
- import type { Refused } from './transfer.js';
5
5
  export declare const MD_MODEL: MdModelIdentity;
6
6
  export type Collection = {
7
- documents: Readonly<Record<string, Document>>;
7
+ text: Readonly<Record<string, string>>;
8
8
  composition: Composition;
9
+ document(path: string): Document | undefined;
9
10
  };
10
11
  export type Composition = {
11
12
  model: ModelState;
@@ -13,18 +14,34 @@ export type Composition = {
13
14
  roots: readonly string[];
14
15
  model: ModelState;
15
16
  } | null;
17
+ typedPaths: readonly TypedPath[];
16
18
  };
17
- export declare function governing(composition: Composition, path: string): ModelState;
18
- type Previous = {
19
- text: Readonly<Record<string, string>>;
20
- collection: Collection;
19
+ export type Composed = {
20
+ readonly composition: Composition;
21
+ readonly fingerprint: string;
21
22
  };
22
- export declare function parseCollection(text: Readonly<Record<string, string>>, composition: Composition, previous?: Previous): Collection;
23
- export declare function readCollection(text: Readonly<Record<string, string>>, composition: Composition, previous?: Previous): {
24
- kind: 'read';
25
- collection: Collection;
26
- } | Refused;
23
+ export declare function composedOf(composition: Composition): Composed;
24
+ type Selecting<M> = {
25
+ readonly model: M;
26
+ readonly selection: {
27
+ readonly roots: readonly string[];
28
+ readonly model: M;
29
+ } | null;
30
+ };
31
+ export declare function selected(composition: {
32
+ readonly selection: {
33
+ readonly roots: readonly string[];
34
+ } | null;
35
+ }, path: string): boolean;
36
+ export declare function governing<M>(composition: Selecting<M>, path: string): M;
37
+ export declare function definitionsAt(composition: Composition, path: string): DefinitionOf;
38
+ export declare function definitionsIn(room: {
39
+ readonly model: TypesResult;
40
+ readonly typedSelection: AppTypedSelection | null;
41
+ }, path: string, typedPaths: readonly TypedPath[]): DefinitionOf;
42
+ export declare function collectionOf(text: Readonly<Record<string, string>>, composition: Composition): Collection;
43
+ export declare function documentsOf(collection: Collection): Generator<number, Iterable<readonly [string, Document]>, void>;
27
44
  export declare function validRoot(root: unknown): root is string;
28
- export declare function validateCollection(text: Readonly<Record<string, string>>, binaryTargets: readonly string[], composition: Composition): Validation;
45
+ export declare function available(composition: Composition): boolean;
29
46
  export {};
30
47
  //# sourceMappingURL=collection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,QAAQ,EAEb,KAAK,UAAU,EAEhB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,eAAO,MAAM,QAAQ,EAAE,eAAwE,CAAC;AAIhG,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC9C,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,UAAU,CAAC;IAClB,SAAS,EAAE;QAAE,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE,UAAU,CAAA;KAAE,GAAG,IAAI,CAAC;CACnE,CAAC;AASF,wBAA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AG,CAAC,CAIvE;AAYD,wBAAgB,aAAa,CAAC,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAIlF;AAED,wBAAgB,aAAa,CAC3B,IAAI,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,cAAc,EAAE,iBAAiB,GAAG,IAAI,CAAA;CAAE,EACxF,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,SAAS,SAAS,EAAE,GAC/B,YAAY,CAQd;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,WAAW,EAAE,WAAW,GACvB,UAAU,CAcZ;AAED,wBAAiB,WAAW,CAC1B,UAAU,EAAE,UAAU,GACrB,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,CAQhE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAEvD;AAED,wBAAgB,SAAS,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAE3D"}
@@ -1,8 +1,30 @@
1
- import { parse, validate, VERSION, } from '@agentshouse/mdmodel';
1
+ import { definitionAt, parse, VERSION, } from '@agentshouse/mdmodel';
2
2
  import { beneath, normalize } from './paths.js';
3
+ import { hashed } from './observation.js';
4
+ import { sortedKeys } from './shared.js';
3
5
  export const MD_MODEL = { identity: '@agentshouse/mdmodel', version: VERSION };
4
- const NO_TYPES = { types: {} };
5
- function selected(composition, path) {
6
+ const typesPrinted = new WeakMap();
7
+ function typesPrint(model) {
8
+ if (model.status === 'unavailable')
9
+ return '';
10
+ let print = typesPrinted.get(model.types);
11
+ if (print === undefined) {
12
+ print = hashed(JSON.stringify(model.types)).toString(36);
13
+ typesPrinted.set(model.types, print);
14
+ }
15
+ return print;
16
+ }
17
+ export function composedOf(composition) {
18
+ const { model, selection } = composition;
19
+ return {
20
+ composition,
21
+ fingerprint: JSON.stringify([
22
+ typesPrint(model),
23
+ selection === null ? null : [selection.roots, typesPrint(selection.model)],
24
+ ]),
25
+ };
26
+ }
27
+ export function selected(composition, path) {
6
28
  return (composition.selection !== null &&
7
29
  composition.selection.roots.some((root) => beneath(root, path)));
8
30
  }
@@ -11,62 +33,46 @@ export function governing(composition, path) {
11
33
  ? composition.selection.model
12
34
  : composition.model;
13
35
  }
14
- function parsedAt(text, path, previous) {
15
- const retained = previous?.collection.documents[path];
16
- return retained !== undefined && previous?.text[path] === text[path]
17
- ? { ok: true, document: retained }
18
- : parse(text[path], path);
36
+ function definitionsUnder(composition, path, typedPaths, typesOf) {
37
+ const types = typesOf(governing(composition, path));
38
+ return types === null ? () => undefined : definitionAt({ types }, path, typedPaths);
19
39
  }
20
- export function parseCollection(text, composition, previous) {
21
- const documents = {};
22
- for (const path of Object.keys(text).sort()) {
23
- const parsed = parsedAt(text, path, previous);
24
- if (parsed.ok)
25
- documents[path] = parsed.document;
26
- }
27
- return { documents, composition };
40
+ export function definitionsAt(composition, path) {
41
+ return definitionsUnder(composition, path, composition.typedPaths, (model) => model.status === 'unavailable' ? null : model.types);
28
42
  }
29
- export function readCollection(text, composition, previous) {
30
- const documents = {};
31
- for (const path of Object.keys(text).sort()) {
32
- const parsed = parsedAt(text, path, previous);
33
- if (!parsed.ok)
34
- return { kind: 'refused', refusal: parsed.refusal };
35
- documents[path] = parsed.document;
36
- }
37
- return { kind: 'read', collection: { documents, composition } };
43
+ export function definitionsIn(room, path, typedPaths) {
44
+ return definitionsUnder({ model: room.model, selection: room.typedSelection }, path, typedPaths, ({ types }) => types === null ? null : Object.fromEntries(types.map((type) => [type.name, type])));
45
+ }
46
+ export function collectionOf(text, composition) {
47
+ const parsed = new Map();
48
+ return {
49
+ text,
50
+ composition,
51
+ document(path) {
52
+ if (parsed.has(path))
53
+ return parsed.get(path) ?? undefined;
54
+ const content = text[path];
55
+ if (content === undefined)
56
+ return undefined;
57
+ const read = parse(content, path, definitionsAt(composition, path));
58
+ parsed.set(path, read.ok ? read.document : null);
59
+ return read.ok ? read.document : undefined;
60
+ },
61
+ };
62
+ }
63
+ export function* documentsOf(collection) {
64
+ const paths = yield* sortedKeys(collection.text);
65
+ return (function* () {
66
+ for (const path of paths) {
67
+ const document = collection.document(path);
68
+ if (document !== undefined)
69
+ yield [path, document];
70
+ }
71
+ })();
38
72
  }
39
73
  export function validRoot(root) {
40
74
  return typeof root === 'string' && normalize(root) === root;
41
75
  }
42
- function validateAgainst(documents, binaryTargets, model) {
43
- if (model.status === 'unavailable') {
44
- const typed = Object.entries(documents).find(([, content]) => {
45
- const parsed = parse(content);
46
- return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
47
- });
48
- if (typed !== undefined)
49
- return { verdict: 'refuse', rule: 'model-unavailable', file: typed[0] };
50
- }
51
- return validate(documents, { binaryTargets }, model.status === 'unavailable' ? NO_TYPES : { types: model.types });
52
- }
53
- export function validateCollection(text, binaryTargets, composition) {
54
- const collection = {};
55
- const selection = {};
56
- for (const [path, content] of Object.entries(text)) {
57
- if (selected(composition, path))
58
- selection[path] = content;
59
- else
60
- collection[path] = content;
61
- }
62
- const verdicts = [
63
- validateAgainst(collection, binaryTargets.filter((path) => !selected(composition, path)), composition.model),
64
- ];
65
- if (composition.selection !== null) {
66
- verdicts.push(validateAgainst(selection, binaryTargets.filter((path) => selected(composition, path)), composition.selection.model));
67
- }
68
- const refusals = verdicts.filter((verdict) => verdict.verdict === 'refuse');
69
- if (refusals.length === 0)
70
- return verdicts[0];
71
- return refusals.find((refusal) => refusal.rule !== 'model-unavailable') ?? refusals[0];
76
+ export function available(composition) {
77
+ return composition.model.status !== 'unavailable';
72
78
  }
@@ -0,0 +1,16 @@
1
+ import { sql } from '@agentshouse/mdmodel';
2
+ import type { Plan, QueryRows } from './query.js';
3
+ import type { Connection } from './tables.js';
4
+ export type QueryRoom = {
5
+ readonly locator: string;
6
+ readonly key: number;
7
+ };
8
+ type Fragment = sql.Fragment;
9
+ export declare const VISIBLE: (alias: string) => string;
10
+ export declare function within(alias: string, path: string): Fragment;
11
+ export type QueryAnswer = QueryRows & {
12
+ readonly more?: string;
13
+ };
14
+ export declare function answerQuery(connection: Connection, plan: Plan, rooms: readonly QueryRoom[], budget?: number | null): QueryAnswer;
15
+ export {};
16
+ //# sourceMappingURL=compile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,GAAG,EAOJ,MAAM,sBAAsB,CAAC;AAI9B,OAAO,KAAK,EAAE,IAAI,EAAuC,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvF,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAG1D,MAAM,MAAM,SAAS,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3E,KAAK,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;AAI7B,eAAO,MAAM,OAAO,UAAW,MAAM,KAAG,MACkC,CAAC;AAa3E,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,CAM5D;AA2cD,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AA6ZjE,wBAAgB,WAAW,CACzB,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,MAAM,GAAE,MAAM,GAAG,IAAW,GAC3B,WAAW,CAUb"}