@agentshouse/mdruntime 0.1.0-cf6d5f0a5c9c8 → 0.1.0-cf890bb538119

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 (256) hide show
  1. package/AGENTS.md +298 -232
  2. package/README.md +19 -8
  3. package/dist/adapter.d.ts +127 -32
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/attached-model.d.ts +4 -1
  6. package/dist/attached-model.d.ts.map +1 -1
  7. package/dist/attached-model.js +13 -3
  8. package/dist/attempt.d.ts +16 -0
  9. package/dist/attempt.d.ts.map +1 -0
  10. package/dist/attempt.js +70 -0
  11. package/dist/binary.d.ts +23 -0
  12. package/dist/binary.d.ts.map +1 -0
  13. package/dist/binary.js +8 -0
  14. package/dist/bootstrap.d.ts +16 -8
  15. package/dist/bootstrap.d.ts.map +1 -1
  16. package/dist/bootstrap.js +102 -50
  17. package/dist/chain.d.ts +11 -0
  18. package/dist/chain.d.ts.map +1 -0
  19. package/dist/chain.js +64 -0
  20. package/dist/change-set.d.ts +9 -14
  21. package/dist/change-set.d.ts.map +1 -1
  22. package/dist/change-set.js +11 -62
  23. package/dist/change.d.ts +45 -0
  24. package/dist/change.d.ts.map +1 -1
  25. package/dist/change.js +34 -0
  26. package/dist/chat/acts.d.ts +33 -0
  27. package/dist/chat/acts.d.ts.map +1 -0
  28. package/dist/chat/acts.js +36 -0
  29. package/dist/chat/context.d.ts +3 -0
  30. package/dist/chat/context.d.ts.map +1 -0
  31. package/dist/chat/context.js +10 -0
  32. package/dist/chat/earlier.d.ts +10 -0
  33. package/dist/chat/earlier.d.ts.map +1 -0
  34. package/dist/chat/earlier.js +54 -0
  35. package/dist/chat/house.d.ts +25 -0
  36. package/dist/chat/house.d.ts.map +1 -0
  37. package/dist/chat/house.js +38 -0
  38. package/dist/chat/input.d.ts +11 -0
  39. package/dist/chat/input.d.ts.map +1 -0
  40. package/dist/chat/input.js +92 -0
  41. package/dist/chat/kit.d.ts +61 -0
  42. package/dist/chat/kit.d.ts.map +1 -0
  43. package/dist/chat/kit.js +123 -0
  44. package/dist/chat/lasting.d.ts +6 -0
  45. package/dist/chat/lasting.d.ts.map +1 -0
  46. package/dist/chat/lasting.js +19 -0
  47. package/dist/chat/list.d.ts +28 -0
  48. package/dist/chat/list.d.ts.map +1 -0
  49. package/dist/chat/list.js +103 -0
  50. package/dist/chat/markdown.d.ts +21 -0
  51. package/dist/chat/markdown.d.ts.map +1 -0
  52. package/dist/chat/markdown.js +246 -0
  53. package/dist/chat/message.d.ts +7 -0
  54. package/dist/chat/message.d.ts.map +1 -0
  55. package/dist/chat/message.js +254 -0
  56. package/dist/chat/messages.d.ts +35 -0
  57. package/dist/chat/messages.d.ts.map +1 -0
  58. package/dist/chat/messages.js +210 -0
  59. package/dist/chat/name.d.ts +7 -0
  60. package/dist/chat/name.d.ts.map +1 -0
  61. package/dist/chat/name.js +37 -0
  62. package/dist/chat/opened.d.ts +12 -0
  63. package/dist/chat/opened.d.ts.map +1 -0
  64. package/dist/chat/opened.js +19 -0
  65. package/dist/chat/overlay.d.ts +32 -0
  66. package/dist/chat/overlay.d.ts.map +1 -0
  67. package/dist/chat/overlay.js +103 -0
  68. package/dist/chat/parts.d.ts +58 -0
  69. package/dist/chat/parts.d.ts.map +1 -0
  70. package/dist/chat/parts.js +120 -0
  71. package/dist/chat/pieces.d.ts +62 -0
  72. package/dist/chat/pieces.d.ts.map +1 -0
  73. package/dist/chat/pieces.js +1110 -0
  74. package/dist/chat/process.d.ts +20 -0
  75. package/dist/chat/process.d.ts.map +1 -0
  76. package/dist/chat/process.js +32 -0
  77. package/dist/chat/provider.d.ts +70 -0
  78. package/dist/chat/provider.d.ts.map +1 -0
  79. package/dist/chat/provider.js +635 -0
  80. package/dist/chat/question.d.ts +9 -0
  81. package/dist/chat/question.d.ts.map +1 -0
  82. package/dist/chat/question.js +69 -0
  83. package/dist/chat/questions.d.ts +31 -0
  84. package/dist/chat/questions.d.ts.map +1 -0
  85. package/dist/chat/questions.js +111 -0
  86. package/dist/chat/read.d.ts +5 -0
  87. package/dist/chat/read.d.ts.map +1 -0
  88. package/dist/chat/read.js +13 -0
  89. package/dist/chat/ready.d.ts +37 -0
  90. package/dist/chat/ready.d.ts.map +1 -0
  91. package/dist/chat/ready.js +93 -0
  92. package/dist/chat/room-file.d.ts +8 -0
  93. package/dist/chat/room-file.d.ts.map +1 -0
  94. package/dist/chat/room-file.js +72 -0
  95. package/dist/chat/steady.d.ts +3 -0
  96. package/dist/chat/steady.d.ts.map +1 -0
  97. package/dist/chat/steady.js +26 -0
  98. package/dist/chat/style.d.ts +4 -0
  99. package/dist/chat/style.d.ts.map +1 -0
  100. package/dist/chat/style.js +307 -0
  101. package/dist/chat.d.ts +15 -0
  102. package/dist/chat.d.ts.map +1 -0
  103. package/dist/chat.js +8 -0
  104. package/dist/client.d.ts +33 -13
  105. package/dist/client.d.ts.map +1 -1
  106. package/dist/client.js +73 -18
  107. package/dist/collection.d.ts +7 -6
  108. package/dist/collection.d.ts.map +1 -1
  109. package/dist/collection.js +31 -77
  110. package/dist/compile.d.ts +16 -0
  111. package/dist/compile.d.ts.map +1 -0
  112. package/dist/compile.js +721 -0
  113. package/dist/connection.d.ts +56 -18
  114. package/dist/connection.d.ts.map +1 -1
  115. package/dist/connection.js +3320 -686
  116. package/dist/conversation.d.ts +39 -12
  117. package/dist/conversation.d.ts.map +1 -1
  118. package/dist/conversation.js +552 -177
  119. package/dist/digest.d.ts +7 -0
  120. package/dist/digest.d.ts.map +1 -0
  121. package/dist/digest.js +113 -0
  122. package/dist/durability.d.ts +8 -1
  123. package/dist/durability.d.ts.map +1 -1
  124. package/dist/entry.d.ts +19 -0
  125. package/dist/entry.d.ts.map +1 -0
  126. package/dist/entry.js +151 -0
  127. package/dist/expectation.d.ts +21 -0
  128. package/dist/expectation.d.ts.map +1 -0
  129. package/dist/expectation.js +70 -0
  130. package/dist/failure.d.ts +13 -0
  131. package/dist/failure.d.ts.map +1 -0
  132. package/dist/failure.js +19 -0
  133. package/dist/fence.d.ts +6 -0
  134. package/dist/fence.d.ts.map +1 -0
  135. package/dist/fence.js +10 -0
  136. package/dist/file.d.ts +2 -10
  137. package/dist/file.d.ts.map +1 -1
  138. package/dist/file.js +3 -120
  139. package/dist/fulltext.d.ts +27 -0
  140. package/dist/fulltext.d.ts.map +1 -0
  141. package/dist/fulltext.js +368 -0
  142. package/dist/host.d.ts +14 -3
  143. package/dist/host.d.ts.map +1 -1
  144. package/dist/host.js +110 -21
  145. package/dist/identity.d.ts +3 -0
  146. package/dist/identity.d.ts.map +1 -1
  147. package/dist/identity.js +9 -0
  148. package/dist/index.d.ts +21 -10
  149. package/dist/index.d.ts.map +1 -1
  150. package/dist/index.js +8 -0
  151. package/dist/live.d.ts +22 -0
  152. package/dist/live.d.ts.map +1 -0
  153. package/dist/live.js +123 -0
  154. package/dist/memory.d.ts +11 -4
  155. package/dist/memory.d.ts.map +1 -1
  156. package/dist/memory.js +97 -23
  157. package/dist/messages.d.ts +28 -0
  158. package/dist/messages.d.ts.map +1 -0
  159. package/dist/messages.js +90 -0
  160. package/dist/model.d.ts +7 -4
  161. package/dist/model.d.ts.map +1 -1
  162. package/dist/model.js +10 -1
  163. package/dist/name.d.ts +4 -0
  164. package/dist/name.d.ts.map +1 -0
  165. package/dist/name.js +122 -0
  166. package/dist/observation.d.ts +19 -2
  167. package/dist/observation.d.ts.map +1 -1
  168. package/dist/observation.js +113 -12
  169. package/dist/open.d.ts +2 -0
  170. package/dist/open.d.ts.map +1 -0
  171. package/dist/open.js +1 -0
  172. package/dist/opened.d.ts +22 -0
  173. package/dist/opened.d.ts.map +1 -0
  174. package/dist/opened.js +107 -0
  175. package/dist/outcome.d.ts +63 -3
  176. package/dist/outcome.d.ts.map +1 -1
  177. package/dist/outcome.js +70 -1
  178. package/dist/overlay.d.ts +15 -5
  179. package/dist/overlay.d.ts.map +1 -1
  180. package/dist/overlay.js +136 -180
  181. package/dist/query.d.ts +64 -4
  182. package/dist/query.d.ts.map +1 -1
  183. package/dist/query.js +51 -7
  184. package/dist/reach.d.ts +13 -4
  185. package/dist/reach.d.ts.map +1 -1
  186. package/dist/reach.js +212 -57
  187. package/dist/react.d.ts +12 -8
  188. package/dist/react.d.ts.map +1 -1
  189. package/dist/react.js +8 -17
  190. package/dist/readiness.d.ts +53 -0
  191. package/dist/readiness.d.ts.map +1 -0
  192. package/dist/readiness.js +33 -0
  193. package/dist/reads.d.ts +11 -0
  194. package/dist/reads.d.ts.map +1 -0
  195. package/dist/reads.js +98 -0
  196. package/dist/recovery.d.ts +25 -0
  197. package/dist/recovery.d.ts.map +1 -0
  198. package/dist/recovery.js +198 -0
  199. package/dist/refresh.d.ts +12 -15
  200. package/dist/refresh.d.ts.map +1 -1
  201. package/dist/refresh.js +74 -49
  202. package/dist/replica.d.ts +58 -33
  203. package/dist/replica.d.ts.map +1 -1
  204. package/dist/replica.js +317 -157
  205. package/dist/room-draft.d.ts +40 -9
  206. package/dist/room-draft.d.ts.map +1 -1
  207. package/dist/room-draft.js +152 -36
  208. package/dist/rows.d.ts +28 -35
  209. package/dist/rows.d.ts.map +1 -1
  210. package/dist/rows.js +113 -70
  211. package/dist/save.d.ts +71 -4
  212. package/dist/save.d.ts.map +1 -1
  213. package/dist/save.js +810 -147
  214. package/dist/search.d.ts +41 -29
  215. package/dist/search.d.ts.map +1 -1
  216. package/dist/search.js +37 -105
  217. package/dist/seed.d.ts +16 -0
  218. package/dist/seed.d.ts.map +1 -0
  219. package/dist/seed.js +75 -0
  220. package/dist/shared.d.ts +16 -0
  221. package/dist/shared.d.ts.map +1 -0
  222. package/dist/shared.js +431 -0
  223. package/dist/status.d.ts +6 -2
  224. package/dist/status.d.ts.map +1 -1
  225. package/dist/status.js +0 -8
  226. package/dist/store.d.ts +113 -79
  227. package/dist/store.d.ts.map +1 -1
  228. package/dist/store.js +351 -463
  229. package/dist/stored.d.ts +138 -0
  230. package/dist/stored.d.ts.map +1 -0
  231. package/dist/stored.js +544 -0
  232. package/dist/tables.d.ts +332 -0
  233. package/dist/tables.d.ts.map +1 -0
  234. package/dist/tables.js +570 -0
  235. package/dist/turn.d.ts +9 -0
  236. package/dist/turn.d.ts.map +1 -0
  237. package/dist/turn.js +75 -0
  238. package/dist/validation.d.ts +30 -0
  239. package/dist/validation.d.ts.map +1 -0
  240. package/dist/validation.js +162 -0
  241. package/dist/windows.d.ts +22 -0
  242. package/dist/windows.d.ts.map +1 -0
  243. package/dist/windows.js +89 -0
  244. package/dist/wire.d.ts +172 -33
  245. package/dist/wire.d.ts.map +1 -1
  246. package/dist/wire.js +68 -31
  247. package/dist/words.d.ts +19 -0
  248. package/dist/words.d.ts.map +1 -0
  249. package/dist/words.js +150 -0
  250. package/package.json +33 -15
  251. package/dist/attachment.d.ts +0 -3
  252. package/dist/attachment.d.ts.map +0 -1
  253. package/dist/attachment.js +0 -8
  254. package/dist/read-side.d.ts +0 -18
  255. package/dist/read-side.d.ts.map +0 -1
  256. package/dist/read-side.js +0 -433
@@ -1,12 +1,15 @@
1
1
  import type { ModelState } from './model.js';
2
- import type { Adapter, AdapterFailure, Authorization, DiscoveredRoom, RetryableRefusal, RoomModels } from './adapter.js';
3
- import { type ConfirmedLayer } from './replica.js';
4
- import type { StagedLayer, TransferRecord } from './store.js';
2
+ import type { Adapter, AdapterFailure, Authorization, DiscoveredRoom, HeldContent, RetryableRefusal, RoomModels } from './adapter.js';
3
+ import type { Composition } from './collection.js';
4
+ import { type Refreshing } from './refresh.js';
5
+ import type { ReplicaRecord } from './replica.js';
6
+ import type { StagedPage, TransferRecord } from './store.js';
7
+ import type { View } from './tables.js';
5
8
  import { type Refused, type Unconfirmed } from './transfer.js';
6
9
  export type Bootstrapped = {
7
10
  kind: 'staged';
8
- confirmed: ConfirmedLayer;
9
- stored: StagedLayer;
11
+ record: ReplicaRecord;
12
+ refreshed: boolean;
10
13
  };
11
14
  export type BootstrapOutcome = Bootstrapped | Refused | Unconfirmed | RetryableRefusal | AdapterFailure;
12
15
  export type HeldModels = {
@@ -14,11 +17,16 @@ export type HeldModels = {
14
17
  selection: ModelState;
15
18
  };
16
19
  export type Remodel = (models: RoomModels | undefined, held: HeldModels) => HeldModels;
20
+ export type Reads = Pick<Adapter, 'bootstrap' | 'refresh' | 'reached'>;
17
21
  export type Staging = {
18
22
  held(locator: string): TransferRecord | null;
19
- staged(record: TransferRecord): Promise<StagedLayer>;
20
- stage(record: TransferRecord, page: StagedLayer): Promise<boolean>;
23
+ stage(record: TransferRecord, page: StagedPage, composition: Composition): Promise<number | null>;
24
+ refreshing(key: number): Promise<Refreshing>;
21
25
  abandon(locator: string): Promise<void>;
26
+ setAside(locator: string): Promise<void>;
27
+ release(key: number): Promise<void>;
28
+ content(key: number): HeldContent;
29
+ validate(record: ReplicaRecord, view: View): Promise<Refused | null>;
22
30
  };
23
- export declare function bootstrapRoom(adapter: Adapter, authorization: Authorization, room: DiscoveredRoom, held: HeldModels, remodel: Remodel, continuing: () => boolean, staging: Staging): Promise<BootstrapOutcome>;
31
+ export declare function bootstrapRoom(adapter: Reads, authorization: Authorization, room: DiscoveredRoom, held: HeldModels, remodel: Remodel, continuing: () => boolean, staging: Staging, reuse: HeldContent | null): Promise<BootstrapOutcome>;
24
32
  //# sourceMappingURL=bootstrap.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,aAAa,EAEb,cAAc,EAEd,gBAAgB,EAChB,UAAU,EACX,MAAM,cAAc,CAAC;AAItB,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,EAAiB,WAAW,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO,EAAe,KAAK,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM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GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAC7C,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;CACtE,CAAC;AA4DF,wBAAsB,aAAa,CACjC,OAAO,EAAE,KAAK,EACd,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,cAAc,EACpB,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,MAAM,OAAO,EACzB,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,WAAW,GAAG,IAAI,GACxB,OAAO,CAAC,gBAAgB,CAAC,CAmC3B"}
package/dist/bootstrap.js CHANGED
@@ -1,42 +1,94 @@
1
- import { declaredAttachments } from './attachment.js';
2
1
  import { transferIdentity } from './identity.js';
3
2
  import { advancement } from './refresh.js';
4
- import { readStaged } from './replica.js';
5
3
  import { unconfirmed } from './transfer.js';
6
4
  const RESUMABLE = new Set([
7
5
  'transport-uncertainty',
8
6
  'retryable-refusal',
9
7
  'unconfirmed',
10
8
  ]);
11
- function pageLayer(page) {
9
+ function pageOf(page) {
10
+ const entries = [];
11
+ for (const [path, content] of Object.entries(page.documents)) {
12
+ entries.push({
13
+ path,
14
+ content,
15
+ binary: null,
16
+ revision: page.revisions[path] ?? null,
17
+ fileId: page.fileIds?.[path] ?? null,
18
+ change: page.changes[path] ?? null,
19
+ written: page.roomVersion,
20
+ });
21
+ }
22
+ for (const [path, file] of Object.entries(page.binaryFiles)) {
23
+ entries.push({
24
+ path,
25
+ content: null,
26
+ binary: { state: 'accepted', ...file },
27
+ revision: page.revisions[path] ?? null,
28
+ fileId: page.fileIds?.[path] ?? null,
29
+ change: page.changes[path] ?? null,
30
+ written: null,
31
+ });
32
+ }
33
+ return { entries, folders: page.folders ?? [] };
34
+ }
35
+ function heldTogether(first, second) {
36
+ if (first === null)
37
+ return second;
12
38
  return {
13
- documents: page.documents,
14
- revisions: page.revisions,
15
- changes: page.changes,
16
- written: Object.fromEntries(Object.keys(page.documents).map((path) => [path, page.roomVersion])),
17
- binaryTargets: page.binaryTargets,
39
+ async files(after, limit) {
40
+ const [left, right] = await Promise.all([
41
+ first.files(after, limit),
42
+ second.files(after, limit),
43
+ ]);
44
+ const merged = new Map([...left, ...right].map((file) => [file.path, file]));
45
+ return [...merged.values()]
46
+ .sort((one, other) => (one.path < other.path ? -1 : one.path > other.path ? 1 : 0))
47
+ .slice(0, limit);
48
+ },
49
+ async contents(paths) {
50
+ const [left, right] = await Promise.all([first.contents(paths), second.contents(paths)]);
51
+ return new Map([...left, ...right]);
52
+ },
18
53
  };
19
54
  }
20
- async function heldTransfer(staging, room) {
21
- const record = staging.held(room.locator);
22
- if (record === null)
23
- return null;
24
- if (record.selection === room.replica.selection) {
25
- return { record, layer: await staging.staged(record) };
55
+ const NO_CONTENT = {
56
+ files: () => Promise.resolve([]),
57
+ contents: () => Promise.resolve(new Map()),
58
+ };
59
+ export async function bootstrapRoom(adapter, authorization, room, held, remodel, continuing, staging, reuse) {
60
+ const kept = staging.held(room.locator);
61
+ const resumed = kept !== null && kept.selection === room.replica.selection ? kept : null;
62
+ if (kept !== null && resumed === null)
63
+ await staging.abandon(room.locator);
64
+ const first = await bundle(adapter, authorization, room, held, remodel, continuing, staging, resumed, reuse);
65
+ if (first.kind !== 'expired')
66
+ return first;
67
+ await staging.setAside(room.locator);
68
+ try {
69
+ const replacement = await bundle(adapter, authorization, room, held, remodel, continuing, staging, null, heldTogether(reuse, first.held));
70
+ if (replacement.kind !== 'expired')
71
+ return replacement;
72
+ await staging.abandon(room.locator);
73
+ return unconfirmed;
74
+ }
75
+ finally {
76
+ if (first.key !== null)
77
+ await staging.release(first.key);
26
78
  }
27
- await staging.abandon(room.locator);
28
- return null;
29
79
  }
30
- export async function bootstrapRoom(adapter, authorization, room, held, remodel, continuing, staging) {
80
+ function compositionFor(room, models) {
81
+ return {
82
+ model: models.collection,
83
+ selection: room.typedSelection === undefined
84
+ ? null
85
+ : { roots: room.typedSelection.roots, model: models.selection },
86
+ };
87
+ }
88
+ async function bundle(adapter, authorization, room, held, remodel, continuing, staging, kept, pool) {
31
89
  const locator = room.locator;
32
90
  const selection = room.replica.selection;
33
- const kept = await heldTransfer(staging, room);
34
- const documents = { ...kept?.layer.documents };
35
- const revisions = { ...kept?.layer.revisions };
36
- const changes = { ...kept?.layer.changes };
37
- const written = { ...kept?.layer.written };
38
- const binaryTargets = new Set(kept?.layer.binaryTargets);
39
- let transfer = kept?.record ?? null;
91
+ let transfer = kept;
40
92
  while (transfer === null || transfer.pageToken !== null) {
41
93
  if (!continuing())
42
94
  return unconfirmed;
@@ -44,31 +96,35 @@ export async function bootstrapRoom(adapter, authorization, room, held, remodel,
44
96
  locator,
45
97
  selection,
46
98
  ...(transfer?.pageToken == null ? {} : { pageToken: transfer.pageToken }),
99
+ ...(pool === null ? {} : { held: pool }),
47
100
  });
101
+ if (page.kind === 'beyond-horizon') {
102
+ const key = transfer?.key ?? null;
103
+ return { kind: 'expired', held: key === null ? NO_CONTENT : staging.content(key), key };
104
+ }
48
105
  if (page.kind !== 'bootstrap') {
49
106
  if (!RESUMABLE.has(page.kind))
50
107
  await staging.abandon(locator);
51
108
  return page;
52
109
  }
53
- transfer = {
110
+ const next = {
54
111
  locator,
55
112
  transfer: transfer?.transfer ?? transferIdentity(),
56
113
  selection,
57
- from: transfer?.from ?? page.roomVersion,
58
- last: page.roomVersion,
114
+ from: transfer !== null && adapter.reached(locator, page.roomVersion, transfer.from)
115
+ ? transfer.from
116
+ : page.roomVersion,
117
+ last: transfer !== null && !adapter.reached(locator, page.roomVersion, transfer.last)
118
+ ? transfer.last
119
+ : page.roomVersion,
59
120
  pageToken: page.pageToken ?? null,
60
121
  models: remodel(page.models, transfer?.models ?? held),
61
- attachments: [...(transfer?.attachments ?? []), page.attachments ?? []],
122
+ key: transfer?.key ?? null,
62
123
  };
63
- const staged = pageLayer(page);
64
- if (!(await staging.stage(transfer, staged)))
124
+ const key = await staging.stage(next, pageOf(page), compositionFor(room, next.models));
125
+ if (key === null)
65
126
  return unconfirmed;
66
- Object.assign(documents, staged.documents);
67
- Object.assign(revisions, staged.revisions);
68
- Object.assign(changes, staged.changes);
69
- Object.assign(written, staged.written);
70
- for (const target of staged.binaryTargets)
71
- binaryTargets.add(target);
127
+ transfer = { ...next, key };
72
128
  }
73
129
  const record = {
74
130
  locator,
@@ -82,27 +138,23 @@ export async function bootstrapRoom(adapter, authorization, room, held, remodel,
82
138
  providerOwnedPaths: room.providerOwnedPaths,
83
139
  roomVersion: transfer.from,
84
140
  transfer: transfer.transfer,
85
- documents,
86
- binaryTargets: [...binaryTargets].sort(),
87
- revisions,
88
- changes,
89
- written,
90
- attachments: declaredAttachments(transfer.attachments),
141
+ key: transfer.key,
91
142
  };
92
- const reconciled = transfer.last === transfer.from
143
+ const reconciled = transfer.last === transfer.from && adapter.reached(locator, transfer.last, room.roomVersion)
93
144
  ? { kind: 'still-current' }
94
- : await advancement(adapter, authorization, record, remodel, continuing);
145
+ : await advancement(adapter, authorization, record, remodel, continuing, await staging.refreshing(record.key));
95
146
  if (reconciled.kind === 'advanced' || reconciled.kind === 'still-current') {
96
- const read = readStaged(reconciled.kind === 'advanced' ? reconciled.record : record);
97
- if (read.kind === 'refused') {
147
+ const refreshed = reconciled.kind === 'advanced';
148
+ const result = refreshed ? reconciled.record : record;
149
+ const refused = await staging.validate(result, refreshed ? 'refreshed' : 'confirmed');
150
+ if (refused !== null) {
98
151
  await staging.abandon(locator);
99
- return read;
152
+ return refused;
100
153
  }
101
- return { kind: 'staged', confirmed: read.confirmed, stored: record };
154
+ return { kind: 'staged', record: result, refreshed };
102
155
  }
103
156
  if (reconciled.kind === 'beyond-horizon') {
104
- await staging.abandon(locator);
105
- return unconfirmed;
157
+ return { kind: 'expired', held: staging.content(record.key), key: record.key };
106
158
  }
107
159
  if (!RESUMABLE.has(reconciled.kind))
108
160
  await staging.abandon(locator);
@@ -0,0 +1,11 @@
1
+ import type { MdRuntimeClient } from './client.js';
2
+ import type { DocumentQuery, DocumentResult, GroupQuery, GroupResult, PendingResult } from './query.js';
3
+ type Rows = DocumentResult | GroupResult;
4
+ export type WindowAnswer = Rows | PendingResult;
5
+ export type WindowChain = {
6
+ want(count: number): void;
7
+ close(): void;
8
+ };
9
+ export declare function chainedWindows(runtime: MdRuntimeClient, query: DocumentQuery | GroupQuery, count: number, publish: (answers: readonly (WindowAnswer | null)[], settled: boolean) => void): WindowChain;
10
+ export {};
11
+ //# sourceMappingURL=chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../src/chain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,UAAU,EACV,WAAW,EACX,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB,KAAK,IAAI,GAAG,cAAc,GAAG,WAAW,CAAC;AAEzC,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,aAAa,CAAC;AAEhD,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAaF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,aAAa,GAAG,UAAU,EACjC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC,YAAY,GAAG,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,GAC7E,WAAW,CAkEb"}
package/dist/chain.js ADDED
@@ -0,0 +1,64 @@
1
+ function answered(answer) {
2
+ return answer !== null && !('pending' in answer);
3
+ }
4
+ export function chainedWindows(runtime, query, count, publish) {
5
+ let links = [];
6
+ let wanted = count;
7
+ let closed = false;
8
+ const observe = runtime.observe;
9
+ const open = (after, shown) => {
10
+ const link = { after, observation: null, value: shown, fresh: false };
11
+ void observe('query', after === undefined ? query : { ...query, after }).then((observation) => {
12
+ if (closed || !links.includes(link)) {
13
+ observation.close();
14
+ return;
15
+ }
16
+ link.observation = observation;
17
+ const take = (value) => {
18
+ link.value = value;
19
+ link.fresh = true;
20
+ settle();
21
+ };
22
+ observation.subscribe(take);
23
+ take(observation.current());
24
+ }, () => { });
25
+ return link;
26
+ };
27
+ const settle = () => {
28
+ if (closed)
29
+ return;
30
+ const next = [];
31
+ for (let at = 0; at < wanted; at += 1) {
32
+ const before = next[at - 1];
33
+ if (before !== undefined && !before.fresh) {
34
+ next.push(...links.slice(at, wanted));
35
+ break;
36
+ }
37
+ if (before !== undefined && (!answered(before.value) || before.value.next === undefined)) {
38
+ break;
39
+ }
40
+ const after = before === undefined ? undefined : before.value.next;
41
+ const held = links[at];
42
+ next.push(held !== undefined && held.after === after ? held : open(after, held?.value ?? null));
43
+ }
44
+ for (const link of links)
45
+ if (!next.includes(link))
46
+ link.observation?.close();
47
+ links = next;
48
+ publish(links.map((link) => link.value), links.every((link) => link.fresh));
49
+ };
50
+ settle();
51
+ return {
52
+ want(count) {
53
+ if (count === wanted)
54
+ return;
55
+ wanted = count;
56
+ settle();
57
+ },
58
+ close() {
59
+ closed = true;
60
+ for (const link of links)
61
+ link.observation?.close();
62
+ },
63
+ };
64
+ }
@@ -1,14 +1,6 @@
1
- import { type Replica } from './replica.js';
2
- import { type Row } from './rows.js';
3
1
  export type DocumentChange = {
4
- locator: string;
5
- path: string;
6
- before: readonly Row[];
7
- after: readonly Row[];
8
- };
9
- export type MessageChange = {
10
- conversation: string;
11
- identity: string;
2
+ readonly locator: string;
3
+ readonly path: string | null;
12
4
  };
13
5
  export type ChangeSet = {
14
6
  documents: readonly DocumentChange[];
@@ -19,15 +11,18 @@ export type ChangeSet = {
19
11
  rooms: readonly string[];
20
12
  queues: readonly string[];
21
13
  presentations: readonly string[];
22
- messages: readonly MessageChange[];
23
14
  conversations: readonly string[];
24
15
  };
25
- export declare function changeSet(locator: string, before: Replica | null, after: Replica | null, changed?: {
16
+ type Changed = {
17
+ documents?: readonly string[] | null;
26
18
  drafts?: readonly string[];
27
19
  room?: boolean;
28
20
  queue?: boolean;
29
21
  presentation?: string;
30
- }): ChangeSet;
31
- export declare function conversationChangeSet(messages: readonly MessageChange[], conversations: readonly string[]): ChangeSet;
22
+ };
23
+ export declare function changeSet(locator: string, changed?: Changed): ChangeSet;
24
+ export declare function conversationChangeSet(conversations: readonly string[]): ChangeSet;
32
25
  export declare function mergeChangeSets(sets: readonly ChangeSet[]): ChangeSet;
26
+ export declare function touches(set: ChangeSet, locator: string, path: string): boolean;
27
+ export {};
33
28
  //# sourceMappingURL=change-set.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"change-set.d.ts","sourceRoot":"","sources":["../src/change-set.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiC,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAwB,KAAK,GAAG,EAAE,MAAM,WAAW,CAAC;AAE3D,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,GAAG,EAAE,CAAC;IACvB,KAAK,EAAE,SAAS,GAAG,EAAE,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,C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AE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACrD,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC,CAAC;AAEF,KAAK,OAAO,GAAG;IACb,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IACrC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,OAAY,GAAG,SAAS,CAe3E;AAED,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CASjF;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,CASrE;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAI9E"}
@@ -1,78 +1,25 @@
1
- import { passingDocument } from './collection.js';
2
- import { sameChange } from './overlay.js';
3
- import { beneath } from './paths.js';
4
- import { compositionOf, sameMembership } from './replica.js';
5
- import { markdownPath, rowsOf } from './rows.js';
6
- function rowsAt(locator, replica, path) {
7
- if (replica === null)
8
- return [];
9
- const visible = replica.visible;
10
- const document = markdownPath(path) ? passingDocument(visible.collection, path) : null;
11
- const held = visible.documents[path] !== undefined && document !== undefined;
12
- if (!held && !visible.binaryTargets.includes(path))
13
- return [];
14
- return rowsOf(locator, path, document ?? null, compositionOf(replica.confirmed.record), visible.changes[path] ?? null);
15
- }
16
- function modelShape(model) {
17
- return model.status === 'unavailable' ? 'unavailable' : JSON.stringify(model.types);
18
- }
19
- export function changeSet(locator, before, after, changed = {}) {
20
- const paths = new Set([
21
- ...Object.keys(before?.visible.documents ?? {}),
22
- ...Object.keys(after?.visible.documents ?? {}),
23
- ...(before?.visible.binaryTargets ?? []),
24
- ...(after?.visible.binaryTargets ?? []),
25
- ]);
26
- const documents = [];
27
- const oldRoom = before?.confirmed.record;
28
- const newRoom = after?.confirmed.record;
29
- const collectionChanged = oldRoom !== undefined &&
30
- newRoom !== undefined &&
31
- modelShape(oldRoom.model) !== modelShape(newRoom.model);
32
- const selectionChanged = oldRoom !== undefined &&
33
- newRoom !== undefined &&
34
- modelShape(oldRoom.selectionModel) !== modelShape(newRoom.selectionModel);
35
- const reclassified = oldRoom !== undefined && newRoom !== undefined && !sameMembership(oldRoom, newRoom);
36
- for (const path of paths) {
37
- const selected = newRoom?.typedSelection?.roots.some((root) => beneath(root, path)) ?? false;
38
- const retyped = selected ? selectionChanged : collectionChanged;
39
- if (before?.visible.documents[path] === after?.visible.documents[path] &&
40
- before?.visible.binaryTargets.includes(path) ===
41
- after?.visible.binaryTargets.includes(path) &&
42
- before?.visible.revisions[path] === after?.visible.revisions[path] &&
43
- sameChange(before?.visible.changes[path], after?.visible.changes[path]) &&
44
- !retyped &&
45
- !reclassified)
46
- continue;
47
- documents.push({
48
- locator,
49
- path,
50
- get before() {
51
- return rowsAt(locator, before, path);
52
- },
53
- get after() {
54
- return rowsAt(locator, after, path);
55
- },
56
- });
57
- }
1
+ export function changeSet(locator, changed = {}) {
2
+ const documents = changed.documents;
58
3
  return {
59
- documents,
4
+ documents: documents === undefined
5
+ ? []
6
+ : documents === null
7
+ ? [{ locator, path: null }]
8
+ : documents.map((path) => ({ locator, path })),
60
9
  drafts: (changed.drafts ?? []).map((path) => ({ locator, path })),
61
10
  rooms: changed.room ? [locator] : [],
62
11
  queues: changed.queue ? [locator] : [],
63
12
  presentations: changed.presentation === undefined ? [] : [changed.presentation],
64
- messages: [],
65
13
  conversations: [],
66
14
  };
67
15
  }
68
- export function conversationChangeSet(messages, conversations) {
16
+ export function conversationChangeSet(conversations) {
69
17
  return {
70
18
  documents: [],
71
19
  drafts: [],
72
20
  rooms: [],
73
21
  queues: [],
74
22
  presentations: [],
75
- messages,
76
23
  conversations: [...new Set(conversations)],
77
24
  };
78
25
  }
@@ -83,7 +30,9 @@ export function mergeChangeSets(sets) {
83
30
  rooms: [...new Set(sets.flatMap((set) => set.rooms))],
84
31
  queues: [...new Set(sets.flatMap((set) => set.queues))],
85
32
  presentations: [...new Set(sets.flatMap((set) => set.presentations))],
86
- messages: sets.flatMap((set) => set.messages),
87
33
  conversations: [...new Set(sets.flatMap((set) => set.conversations))],
88
34
  };
89
35
  }
36
+ export function touches(set, locator, path) {
37
+ return set.documents.some((change) => change.locator === locator && (change.path === null || change.path === path));
38
+ }
package/dist/change.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { BinaryFile, HeadChange } from './adapter.js';
1
2
  export type Change = {
2
3
  readonly kind: 'field';
3
4
  readonly path: string;
@@ -25,6 +26,13 @@ export type Change = {
25
26
  readonly kind: 'replace';
26
27
  readonly path: string;
27
28
  readonly content: string;
29
+ } | {
30
+ readonly kind: 'binary';
31
+ readonly path: string;
32
+ readonly localId: string;
33
+ readonly byteLength: number;
34
+ readonly mediaType: string;
35
+ readonly sha256: string;
28
36
  } | {
29
37
  readonly kind: 'move';
30
38
  readonly path: string;
@@ -32,6 +40,32 @@ export type Change = {
32
40
  } | {
33
41
  readonly kind: 'remove';
34
42
  readonly path: string;
43
+ } | (Arriving & {
44
+ readonly content: string;
45
+ }) | (Arriving & {
46
+ readonly binary: BinaryFile;
47
+ });
48
+ type Arriving = {
49
+ readonly kind: 'arrival';
50
+ readonly path: string;
51
+ readonly revision?: string;
52
+ readonly fileId?: string;
53
+ readonly change?: HeadChange;
54
+ };
55
+ export type RoomMove = {
56
+ readonly source: {
57
+ readonly room: string;
58
+ readonly baseRoomVersion: string;
59
+ };
60
+ readonly destination: {
61
+ readonly room: string;
62
+ readonly baseRoomVersion: string;
63
+ readonly handle: string;
64
+ };
65
+ readonly moves: readonly {
66
+ readonly path: string;
67
+ readonly to: string;
68
+ }[];
35
69
  };
36
70
  export type Precondition = {
37
71
  readonly kind: 'field';
@@ -51,6 +85,10 @@ export type Precondition = {
51
85
  readonly kind: 'revision';
52
86
  readonly path: string;
53
87
  readonly revision: string;
88
+ } | {
89
+ readonly kind: 'content';
90
+ readonly path: string;
91
+ readonly content: string;
54
92
  } | {
55
93
  readonly kind: 'present';
56
94
  readonly path: string;
@@ -69,6 +107,13 @@ export type ChangeBatch = {
69
107
  readonly changes: readonly Change[];
70
108
  readonly preconditions: readonly Precondition[];
71
109
  readonly writtenBy?: WrittenBy;
110
+ readonly between?: RoomMove;
72
111
  };
73
112
  export declare function immutable(batch: ChangeBatch): ChangeBatch;
113
+ export declare function partnerOf(batch: ChangeBatch, locator: string): string | null;
114
+ export declare function leaving(batch: ChangeBatch, locator: string): boolean;
115
+ export declare function landing(changes: readonly Change[], index: number, path: string): string | null;
116
+ export declare function departure(changes: readonly Change[], index: number): string;
117
+ export declare function queuedFile(batch: ChangeBatch, path: string, localId: string): number;
118
+ export {};
74
119
  //# sourceMappingURL=change.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"change.d.ts","sourceRoot":"","sources":["../src/change.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GACd;IACE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAC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,SAAS,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3E,MAAM,MAAM,WAAW,GAAG;IACxB,UAAU,CAAC,EAAE,OAAO,YAAY,EAAE,iBAAiB,CAAC;IACpD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,aAAa,EAAE,SAAS,YAAY,EAAE,CAAC;IAChD,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC;IAC/B,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC;CAC7B,CAAC;AAUF,wBAAgB,SAAS,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW,CAEzD;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAI5E;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAEpE;AAED,wBAAgB,OAAO,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQ9F;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAM3E;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAOpF"}
package/dist/change.js CHANGED
@@ -11,3 +11,37 @@ function frozen(value) {
11
11
  export function immutable(batch) {
12
12
  return frozen(batch);
13
13
  }
14
+ export function partnerOf(batch, locator) {
15
+ const between = batch.between;
16
+ if (between === undefined)
17
+ return null;
18
+ return between.source.room === locator ? between.destination.room : between.source.room;
19
+ }
20
+ export function leaving(batch, locator) {
21
+ return batch.between?.source.room === locator;
22
+ }
23
+ export function landing(changes, index, path) {
24
+ let at = path;
25
+ for (const change of changes.slice(index + 1)) {
26
+ if (change.path !== at)
27
+ continue;
28
+ if (change.kind === 'remove')
29
+ return null;
30
+ if (change.kind === 'move')
31
+ at = change.to;
32
+ }
33
+ return at;
34
+ }
35
+ export function departure(changes, index) {
36
+ let at = changes[index].path;
37
+ for (const change of changes.slice(0, index).reverse()) {
38
+ if (change.kind === 'move' && change.to === at)
39
+ at = change.path;
40
+ }
41
+ return at;
42
+ }
43
+ export function queuedFile(batch, path, localId) {
44
+ return batch.changes.findIndex((change, index) => change.kind === 'binary' &&
45
+ change.localId === localId &&
46
+ landing(batch.changes, index, change.path) === path);
47
+ }
@@ -0,0 +1,33 @@
1
+ import { type Answered } from '../attempt.js';
2
+ import { type CallResult, type Offline } from '../outcome.js';
3
+ import type { Expected } from './overlay.js';
4
+ export type ChatResult = CallResult | Offline;
5
+ export type ChatOutcome = {
6
+ readonly state: 'sending';
7
+ } | {
8
+ readonly state: 'offline';
9
+ } | {
10
+ readonly state: 'failed';
11
+ readonly result: CallResult;
12
+ };
13
+ export declare function accepted(result: ChatResult): result is Extract<CallResult, {
14
+ readonly kind: 'action';
15
+ }>;
16
+ export declare function unanswered(result: ChatResult): boolean;
17
+ export declare function outcomeOf(result: ChatResult): ChatOutcome | null;
18
+ export declare function answeredOf(result: ChatResult): Answered;
19
+ export type Sender = {
20
+ carried(name: string, about: unknown, sending: (operation: string) => Promise<CallResult>): Promise<ChatResult>;
21
+ numbered(name: string, about: unknown, sending: (operation: string) => Promise<ChatResult>): Promise<ChatResult>;
22
+ expect(expected: Expected): void;
23
+ draw(expected: Expected): void;
24
+ };
25
+ type Senders = {
26
+ readonly online: boolean;
27
+ identity(intent: string): string;
28
+ expect(expected: Expected): void;
29
+ draw(expected: Expected): void;
30
+ };
31
+ export declare function sender({ online, identity, expect, draw }: Senders): Sender;
32
+ export {};
33
+ //# sourceMappingURL=acts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acts.d.ts","sourceRoot":"","sources":["../../src/chat/acts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAa,KAAK,UAAU,EAAE,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,OAAO,CAAC;AAE9C,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;CAAE,GAC7B;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;CAAE,GAC7B;IAAE,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC;AAE9D,wBAAgB,QAAQ,CACtB,MAAM,EAAE,UAAU,GACjB,MAAM,IAAI,OAAO,CAAC,UAAU,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,CAE5D;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAEtD;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,WAAW,GAAG,IAAI,CAGhE;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,QAAQ,CAIvD;AAED,MAAM,MAAM,MAAM,GAAG;IACnB,OAAO,CACL,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,CAAC,GAClD,OAAO,CAAC,UAAU,CAAC,CAAC;IACvB,QAAQ,C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