@agentshouse/mdruntime 0.1.0-c193f3bb8a163 → 0.1.0-c1996d5af6e1f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. package/README.md +1 -1
  2. package/dist/acceptance.d.ts.map +1 -1
  3. package/dist/acceptance.js +30 -1
  4. package/dist/actions.d.ts.map +1 -1
  5. package/dist/actions.js +35 -7
  6. package/dist/adapter.d.ts +97 -21
  7. package/dist/adapter.d.ts.map +1 -1
  8. package/dist/attached-model.d.ts.map +1 -1
  9. package/dist/attached-model.js +2 -2
  10. package/dist/{binary.d.ts → attachment.d.ts} +8 -4
  11. package/dist/attachment.d.ts.map +1 -0
  12. package/dist/attachment.js +15 -0
  13. package/dist/chain.d.ts +1 -1
  14. package/dist/chain.d.ts.map +1 -1
  15. package/dist/chain.js +5 -2
  16. package/dist/change.d.ts +2 -2
  17. package/dist/chat-types.js +2 -2
  18. package/dist/client.d.ts +17 -8
  19. package/dist/client.d.ts.map +1 -1
  20. package/dist/client.js +16 -16
  21. package/dist/collection.d.ts +1 -0
  22. package/dist/collection.d.ts.map +1 -1
  23. package/dist/collection.js +7 -1
  24. package/dist/compile.d.ts +2 -1
  25. package/dist/compile.d.ts.map +1 -1
  26. package/dist/compile.js +71 -39
  27. package/dist/connection.d.ts +1 -1
  28. package/dist/connection.d.ts.map +1 -1
  29. package/dist/connection.js +5 -3
  30. package/dist/conversation-live.d.ts +3 -3
  31. package/dist/conversation-live.d.ts.map +1 -1
  32. package/dist/conversation-live.js +4 -3
  33. package/dist/conversation-row.d.ts +12 -0
  34. package/dist/conversation-row.d.ts.map +1 -1
  35. package/dist/conversation-row.js +10 -0
  36. package/dist/conversation.d.ts +14 -8
  37. package/dist/conversation.d.ts.map +1 -1
  38. package/dist/conversation.js +68 -49
  39. package/dist/declaration.js +3 -3
  40. package/dist/discovery.d.ts +1 -1
  41. package/dist/discovery.d.ts.map +1 -1
  42. package/dist/discovery.js +18 -5
  43. package/dist/download.d.ts +2 -2
  44. package/dist/download.d.ts.map +1 -1
  45. package/dist/entry.d.ts +22 -3
  46. package/dist/entry.d.ts.map +1 -1
  47. package/dist/entry.js +111 -45
  48. package/dist/figures.d.ts +1 -1
  49. package/dist/figures.d.ts.map +1 -1
  50. package/dist/figures.js +2 -2
  51. package/dist/host.d.ts +5 -2
  52. package/dist/host.d.ts.map +1 -1
  53. package/dist/host.js +50 -22
  54. package/dist/house-query.d.ts +14 -11
  55. package/dist/house-query.d.ts.map +1 -1
  56. package/dist/house-query.js +69 -8
  57. package/dist/identity.d.ts +1 -1
  58. package/dist/identity.d.ts.map +1 -1
  59. package/dist/identity.js +1 -1
  60. package/dist/index.d.ts +17 -13
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +8 -6
  63. package/dist/lifecycle.d.ts +1 -1
  64. package/dist/lifecycle.d.ts.map +1 -1
  65. package/dist/lifecycle.js +24 -19
  66. package/dist/live.d.ts +14 -0
  67. package/dist/live.d.ts.map +1 -1
  68. package/dist/live.js +29 -12
  69. package/dist/loaded.d.ts +5 -3
  70. package/dist/loaded.d.ts.map +1 -1
  71. package/dist/loaded.js +12 -6
  72. package/dist/locks.d.ts.map +1 -1
  73. package/dist/locks.js +2 -0
  74. package/dist/media.d.ts +5 -6
  75. package/dist/media.d.ts.map +1 -1
  76. package/dist/media.js +94 -25
  77. package/dist/memory.d.ts +2 -2
  78. package/dist/memory.js +9 -9
  79. package/dist/messages.d.ts +10 -1
  80. package/dist/messages.d.ts.map +1 -1
  81. package/dist/messages.js +24 -4
  82. package/dist/model.d.ts +6 -5
  83. package/dist/model.d.ts.map +1 -1
  84. package/dist/name.d.ts +0 -1
  85. package/dist/name.d.ts.map +1 -1
  86. package/dist/name.js +3 -7
  87. package/dist/opened.d.ts +5 -5
  88. package/dist/opened.d.ts.map +1 -1
  89. package/dist/opened.js +2 -2
  90. package/dist/opening.d.ts.map +1 -1
  91. package/dist/opening.js +20 -2
  92. package/dist/outcome.d.ts +21 -13
  93. package/dist/outcome.d.ts.map +1 -1
  94. package/dist/outcome.js +5 -5
  95. package/dist/overlay.d.ts +19 -8
  96. package/dist/overlay.d.ts.map +1 -1
  97. package/dist/overlay.js +108 -37
  98. package/dist/parts.d.ts +1 -0
  99. package/dist/parts.d.ts.map +1 -1
  100. package/dist/parts.js +1 -0
  101. package/dist/paths.d.ts +1 -1
  102. package/dist/paths.js +1 -1
  103. package/dist/preparation.d.ts +10 -5
  104. package/dist/preparation.d.ts.map +1 -1
  105. package/dist/preparation.js +78 -48
  106. package/dist/queries.d.ts.map +1 -1
  107. package/dist/queries.js +59 -14
  108. package/dist/query.d.ts +2 -2
  109. package/dist/query.d.ts.map +1 -1
  110. package/dist/questions.d.ts.map +1 -1
  111. package/dist/questions.js +2 -1
  112. package/dist/reach.d.ts +5 -2
  113. package/dist/reach.d.ts.map +1 -1
  114. package/dist/reach.js +55 -15
  115. package/dist/react.d.ts +6 -0
  116. package/dist/react.d.ts.map +1 -1
  117. package/dist/readiness.d.ts +17 -4
  118. package/dist/readiness.d.ts.map +1 -1
  119. package/dist/readiness.js +17 -7
  120. package/dist/reads.d.ts.map +1 -1
  121. package/dist/reads.js +15 -4
  122. package/dist/refresh.d.ts +1 -1
  123. package/dist/refresh.js +4 -4
  124. package/dist/replica.d.ts +3 -8
  125. package/dist/replica.d.ts.map +1 -1
  126. package/dist/replica.js +3 -3
  127. package/dist/room-draft.d.ts +1 -1
  128. package/dist/room-draft.d.ts.map +1 -1
  129. package/dist/room-draft.js +9 -6
  130. package/dist/room-drafts.d.ts.map +1 -1
  131. package/dist/room-drafts.js +8 -6
  132. package/dist/room-list.d.ts.map +1 -1
  133. package/dist/room-list.js +2 -0
  134. package/dist/rows.d.ts +9 -2
  135. package/dist/rows.d.ts.map +1 -1
  136. package/dist/rows.js +19 -5
  137. package/dist/run-tables.d.ts +25 -0
  138. package/dist/run-tables.d.ts.map +1 -0
  139. package/dist/run-tables.js +98 -0
  140. package/dist/runs.d.ts +27 -0
  141. package/dist/runs.d.ts.map +1 -0
  142. package/dist/runs.js +92 -0
  143. package/dist/runtime.d.ts +4 -2
  144. package/dist/runtime.d.ts.map +1 -1
  145. package/dist/save.d.ts +1 -0
  146. package/dist/save.d.ts.map +1 -1
  147. package/dist/save.js +6 -6
  148. package/dist/saves.d.ts +5 -5
  149. package/dist/saves.d.ts.map +1 -1
  150. package/dist/saves.js +71 -45
  151. package/dist/selector.d.ts +3 -0
  152. package/dist/selector.d.ts.map +1 -0
  153. package/dist/selector.js +22 -0
  154. package/dist/shown.d.ts.map +1 -1
  155. package/dist/shown.js +17 -4
  156. package/dist/socket/session.d.ts +3 -1
  157. package/dist/socket/session.d.ts.map +1 -1
  158. package/dist/socket/session.js +2 -0
  159. package/dist/socket.d.ts +3 -1
  160. package/dist/socket.d.ts.map +1 -1
  161. package/dist/socket.js +7 -0
  162. package/dist/source.d.ts +19 -0
  163. package/dist/source.d.ts.map +1 -1
  164. package/dist/source.js +35 -7
  165. package/dist/store/records.d.ts +14 -5
  166. package/dist/store/records.d.ts.map +1 -1
  167. package/dist/store/records.js +11 -4
  168. package/dist/store.d.ts +3 -2
  169. package/dist/store.d.ts.map +1 -1
  170. package/dist/store.js +4 -1
  171. package/dist/stored.d.ts +17 -3
  172. package/dist/stored.d.ts.map +1 -1
  173. package/dist/stored.js +138 -31
  174. package/dist/surface.d.ts +11 -5
  175. package/dist/surface.d.ts.map +1 -1
  176. package/dist/surface.js +9 -6
  177. package/dist/sync.d.ts +2 -1
  178. package/dist/sync.d.ts.map +1 -1
  179. package/dist/sync.js +26 -18
  180. package/dist/tables.d.ts +26 -2
  181. package/dist/tables.d.ts.map +1 -1
  182. package/dist/tables.js +24 -3
  183. package/dist/tallies.js +2 -2
  184. package/dist/validation.d.ts +2 -0
  185. package/dist/validation.d.ts.map +1 -1
  186. package/dist/validation.js +49 -3
  187. package/dist/wire.d.ts +11 -6
  188. package/dist/wire.d.ts.map +1 -1
  189. package/dist/wire.js +12 -11
  190. package/package.json +4 -4
  191. package/dist/binary.d.ts.map +0 -1
  192. package/dist/binary.js +0 -8
package/dist/entry.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import { invalid, plain, QueryError, } from '@agentshouse/mdmodel';
2
2
  import { attachedModel } from './attached-model.js';
3
+ import { writtenDocuments } from './overlay.js';
3
4
  import { answerQuery } from './compile.js';
4
5
  import { planWithin } from './query.js';
5
- import { writtenFacts } from './rows.js';
6
- import { entered, REPLICA_TABLES } from './stored.js';
6
+ import { documentKey, writtenFacts } from './rows.js';
7
+ import { entered, enteredValues, REPLICA_TABLES, } from './stored.js';
7
8
  export { QueryError } from '@agentshouse/mdmodel';
9
+ export { documentKey, pathOfKey } from './rows.js';
8
10
  const PARAMETER = '$param';
9
11
  const KIND = 'as';
10
12
  const INTEGER = /^-?(?:0|[1-9][0-9]*)$/u;
@@ -100,8 +102,8 @@ function sampled(template, key) {
100
102
  }
101
103
  return template;
102
104
  }
103
- function entryPlan(query, facts) {
104
- const plan = planWithin(query, facts);
105
+ function entryPlan(query, facts, reach = null) {
106
+ const plan = planWithin(query, facts, reach);
105
107
  if (plan.fileIds !== null)
106
108
  invalid('fileIds', 'an entry Room holds no file IDs');
107
109
  return plan;
@@ -117,56 +119,120 @@ export function entryRefusal(template) {
117
119
  throw error;
118
120
  }
119
121
  }
120
- export function entryScope(rooms, roomTypes, connection) {
121
- for (const table of REPLICA_TABLES)
122
- connection.run(table);
123
- const held = [];
124
- const keys = rooms.map((room) => {
125
- const model = attachedModel({
126
- kind: 'model',
127
- snapshot: { identity: room.locator, version: '', schema: room.schema, revision: null },
128
- }, roomTypes);
129
- held.push({
122
+ function composedRoom(room, roomTypes) {
123
+ const model = attachedModel({
124
+ kind: 'model',
125
+ snapshot: { identity: room.locator, version: '', schema: room.schema, revision: null },
126
+ }, roomTypes);
127
+ return { model, selection: null, typedPaths: [] };
128
+ }
129
+ export function writtenIn(room, roomTypes, batch) {
130
+ const written = writtenDocuments({
131
+ documents: room.documents,
132
+ binaries: {},
133
+ revisions: room.revisions ?? {},
134
+ fileIds: {},
135
+ created: {},
136
+ changes: {},
137
+ }, batch, composedRoom(room, roomTypes));
138
+ for (;;) {
139
+ const step = written.next();
140
+ if (step.done === true)
141
+ return step.value;
142
+ }
143
+ }
144
+ function enteredRoom(room, roomTypes, connection) {
145
+ const composition = composedRoom(room, roomTypes);
146
+ const { model } = composition;
147
+ const key = room.enter(composition);
148
+ if (room.handle !== undefined)
149
+ connection.run("INSERT INTO replica_rooms (locator, key, record) VALUES (?, ?, json_object('declaration', json_object('handle', ?)))", [room.locator, key, room.handle]);
150
+ return {
151
+ locator: room.locator,
152
+ key,
153
+ composition,
154
+ ...(room.handle === undefined ? {} : { handle: room.handle }),
155
+ facts: {
130
156
  locator: room.locator,
131
157
  available: model.status !== 'unavailable',
132
158
  types: model.status === 'unavailable' ? [] : Object.values(model.types),
133
- });
134
- const composition = { model, selection: null, typedPaths: [] };
135
- const heads = (path) => ({
136
- revision: room.revisions?.[path] ?? null,
137
- fileId: room.fileIds?.[path] ?? null,
138
- created: room.created?.[path] ?? null,
139
- change: room.changes?.[path] ?? null,
140
- written: null,
141
- });
142
- const entries = [
143
- ...Object.entries(room.documents).map(([path, content]) => ({
144
- path,
145
- content,
146
- facts: writtenFacts(path, content, composition),
147
- binary: null,
148
- ...heads(path),
149
- })),
150
- ...Object.entries(room.binaryFiles ?? {}).map(([path, binary]) => ({
151
- path,
152
- content: null,
153
- facts: null,
154
- binary: { state: 'accepted', ...binary },
155
- ...heads(path),
156
- })),
157
- ];
158
- const key = entered(connection, room.locator, composition, entries.sort((left, right) => (left.path < right.path ? -1 : 1)));
159
- return { locator: room.locator, key, composition };
160
- });
161
- const planned = { listed: true, rooms: held };
159
+ },
160
+ };
161
+ }
162
+ function reachOf(rooms, followed) {
163
+ if (followed.every(({ readable, areas }) => readable === undefined && areas === undefined))
164
+ return null;
165
+ return {
166
+ rooms: [...rooms, ...followed.filter(({ readable }) => readable === undefined)].map(({ locator }) => locator),
167
+ documents: followed.flatMap(({ locator, readable }) => (readable ?? []).map((path) => documentKey(locator, path))),
168
+ areas: followed.flatMap(({ locator, areas }) => (areas ?? []).map(({ path, open }) => ({ room: locator, path, open }))),
169
+ };
170
+ }
171
+ function scope(rooms, roomTypes, connection, followed = []) {
172
+ for (const table of REPLICA_TABLES)
173
+ connection.run(table);
174
+ const keys = rooms.map((room) => enteredRoom(room, roomTypes, connection));
175
+ const follows = [
176
+ ...keys,
177
+ ...followed.map((room) => enteredRoom(room, roomTypes, connection)),
178
+ ].filter(({ handle }) => handle !== undefined);
179
+ const planned = { listed: true, rooms: keys.map(({ facts }) => facts) };
180
+ const reach = reachOf(rooms, followed);
162
181
  return {
163
182
  async results(queries) {
164
183
  const results = {};
165
184
  for (const [name, query] of Object.entries(queries)) {
166
- const plan = entryPlan(query, planned);
167
- results[name] = answerQuery(connection, plan, keys.filter(({ locator }) => plan.rooms === null || plan.rooms.includes(locator)));
185
+ const plan = entryPlan(query, planned, reach);
186
+ results[name] = answerQuery(connection, plan, keys.filter(({ locator }) => plan.rooms === null || plan.rooms.includes(locator)), null, follows);
168
187
  }
169
188
  return results;
170
189
  },
171
190
  };
172
191
  }
192
+ function scopedRoom(room, connection) {
193
+ return {
194
+ locator: room.locator,
195
+ ...(room.handle === undefined ? {} : { handle: room.handle }),
196
+ ...(room.readable === undefined ? {} : { readable: room.readable }),
197
+ ...(room.areas === undefined ? {} : { areas: room.areas }),
198
+ schema: room.schema,
199
+ enter(composition) {
200
+ const heads = (path) => ({
201
+ revision: room.revisions?.[path] ?? null,
202
+ fileId: room.fileIds?.[path] ?? null,
203
+ created: room.created?.[path] ?? null,
204
+ change: room.changes?.[path] ?? null,
205
+ written: null,
206
+ });
207
+ const entries = [
208
+ ...Object.entries(room.documents).map(([path, content]) => ({
209
+ path,
210
+ content,
211
+ facts: writtenFacts(path, content, composition),
212
+ binary: null,
213
+ ...heads(path),
214
+ })),
215
+ ...Object.entries(room.attachments ?? {}).map(([path, binary]) => ({
216
+ path,
217
+ content: null,
218
+ facts: null,
219
+ binary: { state: 'accepted', ...binary },
220
+ ...heads(path),
221
+ })),
222
+ ];
223
+ return entered(connection, room.locator, composition, entries.sort((left, right) => (left.path < right.path ? -1 : 1)));
224
+ },
225
+ };
226
+ }
227
+ export function entryScope(rooms, roomTypes, connection, followed = []) {
228
+ return scope(rooms.map((room) => scopedRoom(room, connection)), roomTypes, connection, followed.map((room) => scopedRoom(room, connection)));
229
+ }
230
+ export function countScope(room, roomTypes, connection) {
231
+ return scope([
232
+ {
233
+ locator: room.locator,
234
+ schema: room.schema,
235
+ enter: (composition) => enteredValues(connection, room.locator, composition, room.documents),
236
+ },
237
+ ], roomTypes, connection);
238
+ }
package/dist/figures.d.ts CHANGED
@@ -3,7 +3,7 @@ import type { GroupTotal, PendingResult } from './query.js';
3
3
  import type { Deliver, Fail } from './reach.js';
4
4
  import type { ConversationTally, RoomTally } from './tallies.js';
5
5
  import type { QueryRoom } from './tables.js';
6
- export declare const HOUSE_DIRECTORY = "house";
6
+ export declare const HOUSE_FOLDER = "house";
7
7
  export declare const ROOM_TOTALS: {
8
8
  readonly outside: readonly ["house"];
9
9
  readonly groupBy: readonly ["room"];
@@ -1 +1 @@
1
- {"version":3,"file":"figures.d.ts","sourceRoot":"","sources":["../src/figures.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,eAAO,MAAM,eAAe,UAAU,CAAC;AAEvC,eAAO,MAAM,WAAW;;;;iBAGZ,IAAI;;CACe,CAA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AAC;AAEF,MAAM,MAAM,OAAO,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,CAAC;IAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjG,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,aAAa,CAAC;AAEpD,MAAM,MAAM,YAAY,GAAG,aAAa,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,CAAA;CAAE,CAAC;AAEpF,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC;IAC/B,KAAK,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,SAAS,EAAE,CAAC,CAAC;IACjF,aAAa,CACX,aAAa,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,EACvC,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,SAAS,iBAAiB,EAAE,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,IAAI,CAAC;IAChD,OAAO,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC;IAC9B,OAAO,IAAI,IAAI,CAAC;IAChB,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAgDF,wBAAgB,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,WAAW,CAwIlE"}
package/dist/figures.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { instantKey } from '@agentshouse/mdmodel';
2
- export const HOUSE_DIRECTORY = 'house';
2
+ export const HOUSE_FOLDER = 'house';
3
3
  export const ROOM_TOTALS = {
4
- outside: [HOUSE_DIRECTORY],
4
+ outside: [HOUSE_FOLDER],
5
5
  groupBy: ['room'],
6
6
  select: { size: true },
7
7
  };
package/dist/host.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { type MdRuntimeOptions } from './connection.js';
2
2
  import type { PortReach } from './reach.js';
3
- import type { CodeAvailability, Persistence, Readiness } from './readiness.js';
3
+ import type { CodeAvailability, FirstTier, Persistence, Readiness } from './readiness.js';
4
4
  import type { EntrySeed } from './seed.js';
5
5
  import { type CallResult } from './outcome.js';
6
6
  import { type RuntimePort } from './wire.js';
7
7
  export type MdRuntimeHostOptions = MdRuntimeOptions & {
8
8
  deploymentFacts?: unknown;
9
+ saveMessages?: Readonly<Record<string, string>>;
9
10
  };
10
11
  export type Admitted = {
11
12
  readonly admitted: unknown;
@@ -19,10 +20,12 @@ export type AttachOptions = {
19
20
  readonly reach?: PortReach;
20
21
  readonly admission?: ActionAdmission;
21
22
  readonly code?: CodeAvailability;
23
+ readonly first?: FirstTier;
22
24
  };
23
25
  export type AttachedPort = {
24
26
  detach(): void;
25
27
  narrow(reach: PortReach): void;
28
+ code(code: CodeAvailability): void;
26
29
  readiness(deliver: (readiness: Readiness) => void): () => void;
27
30
  answered(queries: readonly unknown[], done: () => void): void;
28
31
  };
@@ -38,7 +41,7 @@ export declare function serveMdRuntime(options: MdRuntimeHostOptions): MdRuntime
38
41
  export { entrySeedOf, type EntrySeed } from './seed.js';
39
42
  export type { QueriedRoom } from './adapter.js';
40
43
  export type { PortReach, ReachedDocument } from './reach.js';
41
- export type { CodeAvailability, Persistence, Space } from './readiness.js';
44
+ export type { CodeAvailability, FirstTier, Persistence, Space } from './readiness.js';
42
45
  export { createRecovery, retryDelay, type Attempt, type Attempted, type AttemptOptions, type Recovery, type RecoveryOptions, } from './recovery.js';
43
46
  export { replaces } from './observation.js';
44
47
  export { undeclared } from './outcome.js';
@@ -1 +1 @@
1
- {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAUxE,OAAO,KAAK,EAAE,SAAS,EAAE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ACd,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EACL,UAAU,EACV,WAAW,EACX,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,WAAW,GACjB,MAAM,WAAW,CAAC"}
package/dist/host.js CHANGED
@@ -6,7 +6,17 @@ import { observed } from './observation.js';
6
6
  import { answeredResult } from './outcome.js';
7
7
  import { AUTHORIZATION_ENDED, WIRE, wireRequest, } from './wire.js';
8
8
  const NARROWED = new Set(['within', 'whole']);
9
- function answered(md, app, writtenBy, member, input) {
9
+ const UNWAITED_MEMBERS = new Set(['call', 'queryHouse']);
10
+ const UNWAITED_TOPICS = new Set([
11
+ 'deployment-facts',
12
+ 'room-drafts',
13
+ 'sync-status',
14
+ 'connection-refusal',
15
+ 'storage-loss',
16
+ 'service-mode',
17
+ 'authority-changes',
18
+ ]);
19
+ function answered(md, app, writtenBy, member, input, said) {
10
20
  switch (member) {
11
21
  case 'rooms':
12
22
  return md.rooms();
@@ -15,27 +25,31 @@ function answered(md, app, writtenBy, member, input) {
15
25
  case 'search':
16
26
  return md.search(input[0]);
17
27
  case 'queryHouse':
18
- return md.queryHouse(input[0]);
28
+ return md.queryHouse(input[0], input[1]);
19
29
  case 'types':
20
30
  return md.types(input[0]);
21
31
  case 'save':
22
- return md.save(input[0], input[1], writtenBy);
32
+ return md
33
+ .save(input[0], input[1], writtenBy)
34
+ .then(said);
23
35
  case 'saveParts':
24
- return md.saveParts(input[0], input[1], writtenBy);
36
+ return md
37
+ .saveParts(input[0], input[1], writtenBy)
38
+ .then(said);
25
39
  case 'history':
26
40
  return md.history(input[0], input[1], input[2]);
27
41
  case 'resolve':
28
42
  return md.resolve(input[0], input[1], input[2]);
29
- case 'binaryFile.read':
30
- return md.binaryFile.read(input[0], input[1], input[2]);
31
- case 'binaryFile.link':
32
- return md.binaryFile.link(input[0], input[1], input[2]);
33
- case 'binaryFile.show':
34
- return md.binaryFile.show(input[0], input[1], input[2]);
35
- case 'binaryFile.attach':
36
- return md.binaryFile.attach(input[0], input[1]);
37
- case 'binaryFile.part':
38
- return md.binaryFile.part(input[0], input[1]);
43
+ case 'attachment.read':
44
+ return md.attachment.read(input[0], input[1], input[2]);
45
+ case 'attachment.link':
46
+ return md.attachment.link(input[0], input[1], input[2]);
47
+ case 'attachment.show':
48
+ return md.attachment.show(input[0], input[1], input[2]);
49
+ case 'attachment.attach':
50
+ return md.attachment.attach(input[0], input[1]);
51
+ case 'attachment.part':
52
+ return md.attachment.part(input[0], input[1]);
39
53
  case 'call':
40
54
  return md.call(input[0], input[1]);
41
55
  case 'answered':
@@ -94,8 +108,8 @@ function answered(md, app, writtenBy, member, input) {
94
108
  return md.conversation.decide(input[0], input[1], input[2]);
95
109
  case 'conversation.rename':
96
110
  return md.conversation.rename(input[0], input[1], input[2]);
97
- case 'conversation.option':
98
- return md.conversation.option(input[0], input[1], input[2], input[3]);
111
+ case 'conversation.set':
112
+ return md.conversation.set(input[0], input[1], input[2]);
99
113
  case 'conversation.retry':
100
114
  return md.conversation.retry(input[0], input[1], input[2]);
101
115
  case 'conversation.pin':
@@ -133,6 +147,13 @@ function answeredMessage(value) {
133
147
  }
134
148
  export function serveMdRuntime(options) {
135
149
  const deploymentFacts = structuredClone(options.deploymentFacts);
150
+ const saveMessages = new Map(Object.entries(options.saveMessages ?? {}));
151
+ const said = (result) => {
152
+ if (result.outcome !== 'refused')
153
+ return result;
154
+ const message = saveMessages.get(result.code);
155
+ return message === undefined ? result : { ...result, message };
156
+ };
136
157
  const closing = new AbortController();
137
158
  const close = () => {
138
159
  closing.abort();
@@ -153,9 +174,9 @@ export function serveMdRuntime(options) {
153
174
  function attach(port, options) {
154
175
  if (!authorized)
155
176
  throw new Error(AUTHORIZATION_ENDED);
156
- const { app, release, reach, admission, code = 'stored' } = options;
177
+ const { app, release, reach, admission, code = 'stored', first = null } = options;
157
178
  const writtenBy = release === undefined ? undefined : { app, release };
158
- const view = runtime.within(reach ?? null, { target: app, code });
179
+ const view = runtime.within(reach ?? null, { target: app, code, first, inboxed: null });
159
180
  const observations = new Map();
160
181
  const followed = new Set();
161
182
  const answeredKeys = new Set();
@@ -181,6 +202,7 @@ export function serveMdRuntime(options) {
181
202
  observations.clear();
182
203
  for (const end of [...followed])
183
204
  end();
205
+ view.close();
184
206
  attachments.delete(detach);
185
207
  };
186
208
  const observe = (id, topic, input) => {
@@ -236,10 +258,12 @@ export function serveMdRuntime(options) {
236
258
  return;
237
259
  }
238
260
  try {
239
- if (message.kind !== 'observe')
261
+ if (message.kind === 'observe') {
262
+ if (!UNWAITED_TOPICS.has(message.topic))
263
+ await opened();
264
+ }
265
+ else if (!UNWAITED_MEMBERS.has(message.member))
240
266
  await md.loaded();
241
- else if (message.topic !== 'room-drafts')
242
- await opened();
243
267
  if (message.kind === 'observe') {
244
268
  if (serving)
245
269
  observe(message.id, message.topic, message.input);
@@ -252,7 +276,7 @@ export function serveMdRuntime(options) {
252
276
  return;
253
277
  }
254
278
  const { id, member, input } = message;
255
- const pending = attempted(() => answered(NARROWED.has(WIRE.members[member].reach) ? admitted : md, app, writtenBy, member, input));
279
+ const pending = attempted(() => answered(NARROWED.has(WIRE.members[member].reach) ? admitted : md, app, writtenBy, member, input, said));
256
280
  return reply(id, member === 'query' ? input[0] : undefined, pending);
257
281
  };
258
282
  port.addEventListener('message', (event) => {
@@ -272,6 +296,10 @@ export function serveMdRuntime(options) {
272
296
  if (serving)
273
297
  view.narrow(next);
274
298
  },
299
+ code(next) {
300
+ if (serving)
301
+ view.code(next);
302
+ },
275
303
  answered(queries, done) {
276
304
  const keys = queries.map(queryKey);
277
305
  if (keys.every((key) => answeredKeys.has(key)))
@@ -1,21 +1,24 @@
1
- import { type DocumentQuery } from '@agentshouse/mdmodel';
2
- import type { ProviderRefusal } from './adapter.js';
1
+ import { type DocumentQuery, type GroupQuery } from '@agentshouse/mdmodel';
2
+ import type { HouseQueryGroups, HouseQueryRows, ProviderRefusal } from './adapter.js';
3
3
  import { type Failure, type Offline } from './outcome.js';
4
- import type { QueryDocument } from './query.js';
5
4
  import { type PortReach } from './reach.js';
6
5
  import type { Runtime } from './runtime.js';
7
- export type HouseQuery = DocumentQuery & {
8
- rooms: readonly [string];
6
+ type HouseViewQuery = {
7
+ readonly rooms: readonly [string];
8
+ readonly path: string;
9
+ readonly after?: string;
9
10
  };
10
- export type HouseQueryRows = {
11
- kind: 'rows';
12
- documents: readonly QueryDocument[];
13
- next?: string;
11
+ export type HouseQuery = ((DocumentQuery | GroupQuery) & {
12
+ rooms: readonly [string];
13
+ }) | HouseViewQuery;
14
+ export type HouseQueryOptions = {
15
+ readonly fresh?: boolean;
14
16
  };
15
- export type HouseQueryResult = HouseQueryRows | Offline | (ProviderRefusal & {
17
+ export type HouseQueryResult = HouseQueryRows | HouseQueryGroups | Offline | (ProviderRefusal & {
16
18
  kind: 'rejected';
17
19
  }) | (ProviderRefusal & {
18
20
  kind: 'undeclared';
19
21
  }) | Failure;
20
- export declare function queriedHouse(runtime: Runtime, input: unknown, reach: PortReach | null): Promise<HouseQueryResult>;
22
+ export declare function queriedHouse(runtime: Runtime, input: unknown, reach: PortReach | null, options: unknown): Promise<HouseQueryResult>;
23
+ export {};
21
24
  //# sourceMappingURL=house-query.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"house-query.d.ts","sourceRoot":"","sources":["../src/house-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,KAAK,EAAiB,eAAe,EAAE,MAAM,cAAc,CAAC;AAEnE,OAAO,EAA2C,KAAK,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAEnG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,O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,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,UAAU,GAClB,CAAC,CAAC,aAAa,GAAG,UAAU,CAAC,GAAG;IAAE,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC,GAC7D,cAAc,CAAC;AAEnB,MAAM,MAAM,iBAAiB,GAAG;IAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAE7D,MAAM,MAAM,gBAAgB,GACxB,cAAc,GACd,gBAAgB,GAChB,OAAO,GACP,CAAC,eAAe,GAAG;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,GACxC,CAAC,eAAe,GAAG;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,CAAC,GAC1C,OAAO,CAAC;AAgFZ,wBAAsB,YAAY,CAChC,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,SAAS,GAAG,IAAI,EACvB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,gBAAgB,CAAC,CAiB3B"}
@@ -1,33 +1,92 @@
1
- import { invalid, plain } from '@agentshouse/mdmodel';
1
+ import { invalid, known, plain } from '@agentshouse/mdmodel';
2
2
  import { listedOrHeld } from './listing.js';
3
+ import { normalize } from './paths.js';
3
4
  import { failure, OFFLINE, UNCERTAIN, undeclared } from './outcome.js';
4
5
  import { askedOnline, offline } from './online.js';
5
6
  import { holds, queriedOnly } from './reach.js';
7
+ import { documentKey } from './rows.js';
6
8
  const HELD_ON_DEVICE = {
7
9
  kind: 'rejected',
8
10
  code: 'held-on-device',
9
11
  fields: {},
10
12
  retryable: false,
11
13
  };
12
- function houseQueryOf(input) {
14
+ function freshOf(options) {
15
+ if (options === undefined)
16
+ return false;
17
+ if (!plain(options))
18
+ invalid('options', 'expects { fresh }');
19
+ known(options, ['fresh'], 'options');
20
+ const { fresh = false } = options;
21
+ if (typeof fresh !== 'boolean')
22
+ invalid('fresh', 'expects true or false');
23
+ return fresh;
24
+ }
25
+ function viewOf(query) {
26
+ known(query, ['path', 'after'], '');
27
+ const { path, after } = query;
28
+ if (typeof path !== 'string' || path === '' || normalize(path) !== path)
29
+ invalid('path', 'names a View by its Path in the Room');
30
+ if (after === undefined)
31
+ return { path };
32
+ if (typeof after !== 'string')
33
+ invalid('after', 'expects the next an earlier page answered');
34
+ return { path, after };
35
+ }
36
+ function followedOf(reach) {
37
+ if (reach === null)
38
+ return {};
39
+ const whole = new Set([
40
+ ...reach.rooms,
41
+ ...(reach.queriesOnly ?? []).map(({ locator }) => locator),
42
+ ]);
43
+ const documents = new Map(reach.documents
44
+ .filter(({ room }) => !whole.has(room))
45
+ .map(({ room, path }) => [documentKey(room, path), { room, path }]));
46
+ const followed = new Set([...whole, ...[...documents.values()].map(({ room }) => room)]);
47
+ const areas = new Map((reach.areas ?? [])
48
+ .filter(({ room }) => followed.has(room))
49
+ .map(({ room, path, open }) => [
50
+ documentKey(room, path),
51
+ { room, path, open: [...new Set(open)].sort() },
52
+ ]));
53
+ return {
54
+ follows: [
55
+ ...[...whole].sort(),
56
+ ...[...documents.keys()].sort().map((key) => documents.get(key)),
57
+ ...[...areas.keys()].sort().map((key) => areas.get(key)),
58
+ ],
59
+ };
60
+ }
61
+ function houseQueryOf(input, options, reach) {
13
62
  if (!plain(input))
14
63
  invalid('query', 'expects a query object');
15
64
  const { rooms, ...query } = input;
16
65
  if (!Array.isArray(rooms) || rooms.length !== 1 || typeof rooms[0] !== 'string')
17
66
  invalid('rooms', 'names the one Room House answers');
18
- return { room: rooms[0], query };
67
+ const asked = { room: rooms[0], fresh: freshOf(options), ...followedOf(reach) };
68
+ return query.path === undefined ? { ...asked, query } : { ...asked, ...viewOf(query) };
19
69
  }
20
70
  async function heldHere(runtime, reach, room) {
21
71
  return holds(reach, room) && listedOrHeld(runtime, await runtime.store.rooms([room]), room);
22
72
  }
23
- export async function queriedHouse(runtime, input, reach) {
73
+ async function searchListed(runtime, room) {
74
+ const { roomList } = await (await runtime.store.open()).facts(['roomList']);
75
+ return roomList?.rooms.some((one) => one.room_ref === room && one.level === 'search') === true;
76
+ }
77
+ async function queriedHere(runtime, reach, room) {
78
+ if (queriedOnly(reach, runtime.socket.session.now().queriesOnly, room))
79
+ return true;
80
+ return reach === null && (await searchListed(runtime, room));
81
+ }
82
+ export async function queriedHouse(runtime, input, reach, options) {
24
83
  const { socket } = runtime;
25
- const asked = houseQueryOf(input);
26
- await socket.ready;
27
84
  const query = socket.queryHouse();
28
85
  if (query === undefined)
29
86
  return undeclared('queryHouse');
30
- if (!queriedOnly(reach, socket.session.now().queriesOnly, asked.room)) {
87
+ const asked = houseQueryOf(input, options, reach);
88
+ await socket.ready;
89
+ if (!(await queriedHere(runtime, reach, asked.room))) {
31
90
  return (await heldHere(runtime, reach, asked.room))
32
91
  ? HELD_ON_DEVICE
33
92
  : failure({ kind: 'room-not-readable', locator: asked.room });
@@ -37,5 +96,7 @@ export async function queriedHouse(runtime, input, reach) {
37
96
  const answer = await askedOnline(runtime, (authorization) => query(authorization, asked));
38
97
  if (answer === null)
39
98
  return UNCERTAIN;
40
- return answer.kind === 'rows' || answer.kind === 'rejected' ? answer : failure(answer);
99
+ return answer.kind === 'rows' || answer.kind === 'groups' || answer.kind === 'rejected'
100
+ ? answer
101
+ : failure(answer);
41
102
  }
@@ -2,5 +2,5 @@ export declare function changeBatchIdentity(at?: number): string;
2
2
  export declare function roomDraftRevision(): string;
3
3
  export declare function chatDraftRevision(): string;
4
4
  export declare function transferIdentity(): string;
5
- export declare function binaryLocalId(): string;
5
+ export declare function attachmentLocalId(): string;
6
6
  //# sourceMappingURL=identity.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,EAAE,GAAE,MAAmB,GAAG,MAAM,CAWnE;AAQD,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,wBAAgB,aAAa,IAAI,MAAM,CAEtC"}
1
+ {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,EAAE,GAAE,MAAmB,GAAG,MAAM,CAWnE;AAQD,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C"}
package/dist/identity.js CHANGED
@@ -24,6 +24,6 @@ export function chatDraftRevision() {
24
24
  export function transferIdentity() {
25
25
  return randomIdentity();
26
26
  }
27
- export function binaryLocalId() {
27
+ export function attachmentLocalId() {
28
28
  return randomIdentity();
29
29
  }