@agentshouse/mdruntime 0.1.0-c8c4b020a3ec7 → 0.1.0-c967d1ca66fee

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 (98) hide show
  1. package/AGENTS.md +94 -33
  2. package/README.md +10 -10
  3. package/dist/adapter.d.ts +92 -46
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/adapter.js +1 -9
  6. package/dist/attached-model.d.ts +11 -0
  7. package/dist/attached-model.d.ts.map +1 -0
  8. package/dist/attached-model.js +47 -0
  9. package/dist/bootstrap.d.ts +20 -6
  10. package/dist/bootstrap.d.ts.map +1 -1
  11. package/dist/bootstrap.js +89 -35
  12. package/dist/change-set.d.ts.map +1 -1
  13. package/dist/change-set.js +13 -7
  14. package/dist/change.d.ts +4 -0
  15. package/dist/change.d.ts.map +1 -1
  16. package/dist/client.d.ts +8 -5
  17. package/dist/client.d.ts.map +1 -1
  18. package/dist/client.js +57 -24
  19. package/dist/collection.d.ts +6 -11
  20. package/dist/collection.d.ts.map +1 -1
  21. package/dist/collection.js +56 -19
  22. package/dist/connection.d.ts +20 -16
  23. package/dist/connection.d.ts.map +1 -1
  24. package/dist/connection.js +711 -587
  25. package/dist/conversation.d.ts +23 -11
  26. package/dist/conversation.d.ts.map +1 -1
  27. package/dist/conversation.js +252 -106
  28. package/dist/failure.d.ts +13 -0
  29. package/dist/failure.d.ts.map +1 -0
  30. package/dist/failure.js +19 -0
  31. package/dist/host.d.ts +8 -1
  32. package/dist/host.d.ts.map +1 -1
  33. package/dist/host.js +38 -38
  34. package/dist/identity.d.ts +1 -0
  35. package/dist/identity.d.ts.map +1 -1
  36. package/dist/identity.js +7 -1
  37. package/dist/index.d.ts +5 -4
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/memory.d.ts +12 -5
  40. package/dist/memory.d.ts.map +1 -1
  41. package/dist/memory.js +108 -36
  42. package/dist/model.d.ts +13 -12
  43. package/dist/model.d.ts.map +1 -1
  44. package/dist/model.js +6 -3
  45. package/dist/observation.d.ts +2 -0
  46. package/dist/observation.d.ts.map +1 -1
  47. package/dist/observation.js +24 -14
  48. package/dist/open.d.ts +2 -0
  49. package/dist/open.d.ts.map +1 -0
  50. package/dist/open.js +1 -0
  51. package/dist/outcome.d.ts +22 -3
  52. package/dist/outcome.d.ts.map +1 -1
  53. package/dist/outcome.js +35 -1
  54. package/dist/overlay.d.ts +1 -1
  55. package/dist/overlay.d.ts.map +1 -1
  56. package/dist/overlay.js +19 -15
  57. package/dist/paths.d.ts +0 -1
  58. package/dist/paths.d.ts.map +1 -1
  59. package/dist/paths.js +0 -16
  60. package/dist/query.d.ts +10 -3
  61. package/dist/query.d.ts.map +1 -1
  62. package/dist/query.js +78 -36
  63. package/dist/reach.d.ts +40 -0
  64. package/dist/reach.d.ts.map +1 -0
  65. package/dist/reach.js +272 -0
  66. package/dist/react.d.ts +40 -0
  67. package/dist/react.d.ts.map +1 -0
  68. package/dist/react.js +64 -0
  69. package/dist/read-side.d.ts +4 -0
  70. package/dist/read-side.d.ts.map +1 -1
  71. package/dist/read-side.js +116 -54
  72. package/dist/refresh.d.ts +12 -1
  73. package/dist/refresh.d.ts.map +1 -1
  74. package/dist/refresh.js +35 -22
  75. package/dist/replica.d.ts +6 -6
  76. package/dist/replica.d.ts.map +1 -1
  77. package/dist/replica.js +53 -39
  78. package/dist/room-draft.d.ts +11 -8
  79. package/dist/room-draft.d.ts.map +1 -1
  80. package/dist/room-draft.js +19 -26
  81. package/dist/rows.d.ts +4 -1
  82. package/dist/rows.d.ts.map +1 -1
  83. package/dist/rows.js +82 -39
  84. package/dist/save.d.ts +4 -3
  85. package/dist/save.d.ts.map +1 -1
  86. package/dist/save.js +127 -68
  87. package/dist/search.d.ts +3 -2
  88. package/dist/search.d.ts.map +1 -1
  89. package/dist/status.d.ts +2 -2
  90. package/dist/status.d.ts.map +1 -1
  91. package/dist/status.js +0 -8
  92. package/dist/store.d.ts +25 -2
  93. package/dist/store.d.ts.map +1 -1
  94. package/dist/store.js +206 -90
  95. package/dist/wire.d.ts +55 -19
  96. package/dist/wire.d.ts.map +1 -1
  97. package/dist/wire.js +62 -61
  98. package/package.json +14 -2
package/dist/store.js CHANGED
@@ -1,9 +1,11 @@
1
+ import { transferIdentity } from './identity.js';
1
2
  import { sameChange } from './overlay.js';
2
3
  const DATABASE = 'mdruntime';
3
4
  const ROOMS = 'rooms';
4
5
  const DOCUMENTS = 'documents';
5
6
  const BINARY_TARGETS = 'binaryTargets';
6
7
  const ATTACHMENTS = 'attachments';
8
+ const TRANSFERS = 'transfers';
7
9
  const PENDING_CHANGES = 'pendingChanges';
8
10
  const DECLARATIONS = 'declarations';
9
11
  const ROOM_DRAFTS = 'roomDrafts';
@@ -12,7 +14,10 @@ const CONVERSATIONS = 'conversations';
12
14
  const MESSAGES = 'messages';
13
15
  const CHAT_DRAFTS = 'chatDrafts';
14
16
  const CURRENT = 'current';
15
- const SCHEMA = 20;
17
+ const MEMBER = 'member';
18
+ export const STORE_SCHEMA = 21;
19
+ const PATH_KEYED_SCHEMA = 20;
20
+ const READ_BATCH = 256;
16
21
  function settled(request) {
17
22
  return new Promise((resolve, reject) => {
18
23
  request.onsuccess = () => resolve(request.result);
@@ -60,6 +65,97 @@ function roomRecord(record, queue) {
60
65
  const { documents, binaryTargets, revisions, changes, written, attachments, ...room } = record;
61
66
  return { ...room, order: queue.map((batch) => batch.id) };
62
67
  }
68
+ function underTransfer(locator, transfer, after) {
69
+ return after === undefined
70
+ ? IDBKeyRange.bound([locator, transfer], [locator, transfer, []])
71
+ : IDBKeyRange.bound([locator, transfer, after], [locator, transfer, []], true);
72
+ }
73
+ function underRoom(locator) {
74
+ return IDBKeyRange.bound([locator], [locator, []]);
75
+ }
76
+ async function readTransfer(store, locator, transfer, receive) {
77
+ let range = underTransfer(locator, transfer);
78
+ for (;;) {
79
+ const batch = await settled(store.getAll(range, READ_BATCH));
80
+ for (const record of batch)
81
+ receive(record);
82
+ if (batch.length < READ_BATCH)
83
+ return;
84
+ range = underTransfer(locator, transfer, batch[batch.length - 1].path);
85
+ }
86
+ }
87
+ function emptyLayer() {
88
+ return { documents: {}, binaryTargets: [], revisions: {}, changes: {}, written: {} };
89
+ }
90
+ async function readLayer(transaction, locator, transfer) {
91
+ const layer = emptyLayer();
92
+ const head = (held) => {
93
+ if (held.revision !== null)
94
+ layer.revisions[held.path] = held.revision;
95
+ if (held.change !== null)
96
+ layer.changes[held.path] = held.change;
97
+ };
98
+ await readTransfer(transaction.objectStore(DOCUMENTS), locator, transfer, (document) => {
99
+ layer.documents[document.path] = document.content;
100
+ if (document.written !== null)
101
+ layer.written[document.path] = document.written;
102
+ head(document);
103
+ });
104
+ await readTransfer(transaction.objectStore(BINARY_TARGETS), locator, transfer, (target) => {
105
+ layer.binaryTargets.push(target.path);
106
+ head(target);
107
+ });
108
+ return layer;
109
+ }
110
+ function documentRecord(locator, transfer, layer, path) {
111
+ return {
112
+ locator,
113
+ transfer,
114
+ path,
115
+ content: layer.documents[path],
116
+ revision: layer.revisions[path] ?? null,
117
+ change: layer.changes[path] ?? null,
118
+ written: layer.written[path] ?? null,
119
+ };
120
+ }
121
+ function targetRecord(locator, transfer, layer, path) {
122
+ return {
123
+ locator,
124
+ transfer,
125
+ path,
126
+ revision: layer.revisions[path] ?? null,
127
+ change: layer.changes[path] ?? null,
128
+ };
129
+ }
130
+ function writeLayer(transaction, locator, transfer, next, base) {
131
+ const documents = transaction.objectStore(DOCUMENTS);
132
+ for (const path of Object.keys(base?.documents ?? {})) {
133
+ if (next.documents[path] === undefined)
134
+ documents.delete([locator, transfer, path]);
135
+ }
136
+ for (const [path, content] of Object.entries(next.documents)) {
137
+ if (base?.documents[path] === content &&
138
+ base.revisions[path] === next.revisions[path] &&
139
+ base.written[path] === next.written[path] &&
140
+ sameChange(base.changes[path], next.changes[path]))
141
+ continue;
142
+ documents.put(documentRecord(locator, transfer, next, path));
143
+ }
144
+ const targets = transaction.objectStore(BINARY_TARGETS);
145
+ const beforeTargets = new Set(base?.binaryTargets ?? []);
146
+ const afterTargets = new Set(next.binaryTargets);
147
+ for (const path of beforeTargets) {
148
+ if (!afterTargets.has(path))
149
+ targets.delete([locator, transfer, path]);
150
+ }
151
+ for (const path of afterTargets) {
152
+ if (!beforeTargets.has(path) ||
153
+ base?.revisions[path] !== next.revisions[path] ||
154
+ !sameChange(base?.changes[path], next.changes[path])) {
155
+ targets.put(targetRecord(locator, transfer, next, path));
156
+ }
157
+ }
158
+ }
63
159
  function removeRoomEntries(store, locator) {
64
160
  const keys = store.getAllKeys();
65
161
  keys.onsuccess = () => {
@@ -76,15 +172,59 @@ export function removeRuntimeStore() {
76
172
  removal.onerror = () => reject(removal.error);
77
173
  });
78
174
  }
175
+ function keyByTransfer(database, upgrade) {
176
+ database.createObjectStore(TRANSFERS, { keyPath: 'locator' });
177
+ const moves = [DOCUMENTS, BINARY_TARGETS].map((name) => {
178
+ const from = upgrade.objectStore(name);
179
+ from.name = `${name}-${PATH_KEYED_SCHEMA}`;
180
+ return {
181
+ from,
182
+ to: database.createObjectStore(name, { keyPath: ['locator', 'transfer', 'path'] }),
183
+ };
184
+ });
185
+ const transfers = new Map();
186
+ const rooms = upgrade.objectStore(ROOMS).openCursor();
187
+ rooms.onsuccess = () => {
188
+ const room = rooms.result;
189
+ if (room !== null) {
190
+ const record = room.value;
191
+ const transfer = transferIdentity();
192
+ transfers.set(record.locator, transfer);
193
+ room.update({ ...record, transfer });
194
+ room.continue();
195
+ return;
196
+ }
197
+ for (const { from, to } of moves) {
198
+ const held = from.openCursor();
199
+ held.onsuccess = () => {
200
+ const entry = held.result;
201
+ if (entry === null) {
202
+ database.deleteObjectStore(from.name);
203
+ return;
204
+ }
205
+ const record = entry.value;
206
+ const transfer = transfers.get(record.locator);
207
+ if (transfer !== undefined)
208
+ to.put({ ...record, transfer });
209
+ entry.continue();
210
+ };
211
+ }
212
+ };
213
+ }
79
214
  export async function openRuntimeStore() {
80
- const opening = indexedDB.open(DATABASE, SCHEMA);
81
- opening.onupgradeneeded = () => {
215
+ const opening = indexedDB.open(DATABASE, STORE_SCHEMA);
216
+ opening.onupgradeneeded = (event) => {
82
217
  const database = opening.result;
218
+ if (event.oldVersion === PATH_KEYED_SCHEMA && opening.transaction !== null) {
219
+ keyByTransfer(database, opening.transaction);
220
+ return;
221
+ }
83
222
  for (const name of [...database.objectStoreNames])
84
223
  database.deleteObjectStore(name);
85
224
  database.createObjectStore(ROOMS, { keyPath: 'locator' });
86
- database.createObjectStore(DOCUMENTS, { keyPath: ['locator', 'path'] });
87
- database.createObjectStore(BINARY_TARGETS, { keyPath: ['locator', 'path'] });
225
+ database.createObjectStore(DOCUMENTS, { keyPath: ['locator', 'transfer', 'path'] });
226
+ database.createObjectStore(BINARY_TARGETS, { keyPath: ['locator', 'transfer', 'path'] });
227
+ database.createObjectStore(TRANSFERS, { keyPath: 'locator' });
88
228
  database.createObjectStore(ATTACHMENTS, { keyPath: ['locator', 'reference'] });
89
229
  database.createObjectStore(PENDING_CHANGES, { keyPath: ['locator', 'id'] });
90
230
  database.createObjectStore(DECLARATIONS);
@@ -101,99 +241,33 @@ export async function openRuntimeStore() {
101
241
  return {
102
242
  async all() {
103
243
  const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_TARGETS, ATTACHMENTS], 'readonly');
104
- const [rooms, documents, targets, attachments] = await Promise.all([
244
+ const [rooms, attachments] = await Promise.all([
105
245
  settled(transaction.objectStore(ROOMS).getAll()),
106
- settled(transaction.objectStore(DOCUMENTS).getAll()),
107
- settled(transaction.objectStore(BINARY_TARGETS).getAll()),
108
246
  settled(transaction.objectStore(ATTACHMENTS).getAll()),
109
247
  ]);
110
- const byRoom = new Map();
248
+ const records = [];
111
249
  for (const { order, ...room } of rooms) {
112
- byRoom.set(room.locator, {
250
+ const layer = await readLayer(transaction, room.locator, room.transfer);
251
+ records.push({
113
252
  ...room,
114
- documents: {},
115
- revisions: {},
116
- changes: {},
117
- written: {},
118
- binaryTargets: [],
119
- attachments: [],
253
+ ...layer,
254
+ attachments: attachments.flatMap(({ locator, ...attachment }) => locator === room.locator ? [attachment] : []),
120
255
  });
121
256
  }
122
- const head = (room, held) => {
123
- if (held.revision !== null) {
124
- room.revisions[held.path] = held.revision;
125
- }
126
- if (held.change !== null) {
127
- room.changes[held.path] = held.change;
128
- }
129
- };
130
- for (const document of documents) {
131
- const room = byRoom.get(document.locator);
132
- if (room === undefined)
133
- continue;
134
- room.documents[document.path] = document.content;
135
- if (document.written !== null) {
136
- room.written[document.path] = document.written;
137
- }
138
- head(room, document);
139
- }
140
- for (const target of targets) {
141
- const room = byRoom.get(target.locator);
142
- if (room === undefined)
143
- continue;
144
- room.binaryTargets.push(target.path);
145
- head(room, target);
146
- }
147
- for (const { locator, ...attachment } of attachments) {
148
- const room = byRoom.get(locator);
149
- if (room === undefined)
150
- continue;
151
- room.attachments.push(attachment);
152
- }
153
- return [...byRoom.values()];
257
+ return records;
154
258
  },
155
- async write({ next, previous, queue, previousQueue, saved, roomDrafts, consumedRoomDrafts }) {
156
- const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_TARGETS, ATTACHMENTS, PENDING_CHANGES, ROOM_DRAFTS], 'readwrite');
259
+ async write({ next, previous, stored, queue, previousQueue, saved, roomDrafts, consumedRoomDrafts, }) {
260
+ const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_TARGETS, ATTACHMENTS, TRANSFERS, PENDING_CHANGES, ROOM_DRAFTS], 'readwrite');
157
261
  transaction.objectStore(ROOMS).put(roomRecord(next, queue));
158
- const documents = transaction.objectStore(DOCUMENTS);
159
- for (const path of Object.keys(previous?.documents ?? {})) {
160
- if (next.documents[path] === undefined)
161
- documents.delete([next.locator, path]);
162
- }
163
- for (const [path, content] of Object.entries(next.documents)) {
164
- if (previous?.documents[path] === content &&
165
- previous.revisions[path] === next.revisions[path] &&
166
- previous.written[path] === next.written[path] &&
167
- sameChange(previous.changes[path], next.changes[path]))
168
- continue;
169
- documents.put({
170
- locator: next.locator,
171
- path,
172
- content,
173
- revision: next.revisions[path] ?? null,
174
- change: next.changes[path] ?? null,
175
- written: next.written[path] ?? null,
176
- });
177
- }
178
- const targets = transaction.objectStore(BINARY_TARGETS);
179
- const beforeTargets = new Set(previous?.binaryTargets ?? []);
180
- const afterTargets = new Set(next.binaryTargets);
181
- for (const path of beforeTargets) {
182
- if (!afterTargets.has(path))
183
- targets.delete([next.locator, path]);
184
- }
185
- for (const path of afterTargets) {
186
- if (!beforeTargets.has(path) ||
187
- previous?.revisions[path] !== next.revisions[path] ||
188
- !sameChange(previous?.changes[path], next.changes[path])) {
189
- targets.put({
190
- locator: next.locator,
191
- path,
192
- revision: next.revisions[path] ?? null,
193
- change: next.changes[path] ?? null,
194
- });
195
- }
262
+ const moved = previous?.transfer !== next.transfer;
263
+ if (moved && previous !== null) {
264
+ const range = underTransfer(previous.locator, previous.transfer);
265
+ transaction.objectStore(DOCUMENTS).delete(range);
266
+ transaction.objectStore(BINARY_TARGETS).delete(range);
196
267
  }
268
+ if (moved)
269
+ transaction.objectStore(TRANSFERS).delete(next.locator);
270
+ writeLayer(transaction, next.locator, next.transfer, next, moved ? (stored ?? null) : previous);
197
271
  const attachments = transaction.objectStore(ATTACHMENTS);
198
272
  const held = new Map((previous?.attachments ?? []).map((attachment) => [attachment.reference, attachment]));
199
273
  const declared = new Set(next.attachments.map((attachment) => attachment.reference));
@@ -262,6 +336,16 @@ export async function openRuntimeStore() {
262
336
  capabilities,
263
337
  }));
264
338
  },
339
+ async member() {
340
+ const transaction = database.transaction(DECLARATIONS, 'readonly');
341
+ const held = await settled(transaction.objectStore(DECLARATIONS).get(MEMBER));
342
+ return held ?? null;
343
+ },
344
+ async keepMember(member) {
345
+ const transaction = database.transaction(DECLARATIONS, 'readwrite');
346
+ transaction.objectStore(DECLARATIONS).put(member, MEMBER);
347
+ await completed(transaction);
348
+ },
265
349
  async queues() {
266
350
  const transaction = database.transaction([ROOMS, PENDING_CHANGES], 'readonly');
267
351
  const [rooms, pending] = await Promise.all([
@@ -373,15 +457,47 @@ export async function openRuntimeStore() {
373
457
  await completed(transaction);
374
458
  },
375
459
  async dropRooms(locators) {
376
- const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_TARGETS, ATTACHMENTS, PENDING_CHANGES, ROOM_DRAFTS], 'readwrite');
460
+ const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_TARGETS, ATTACHMENTS, TRANSFERS, PENDING_CHANGES, ROOM_DRAFTS], 'readwrite');
377
461
  for (const locator of locators) {
378
462
  transaction.objectStore(ROOMS).delete(locator);
379
- for (const name of [DOCUMENTS, BINARY_TARGETS, ATTACHMENTS, PENDING_CHANGES, ROOM_DRAFTS]) {
463
+ transaction.objectStore(TRANSFERS).delete(locator);
464
+ transaction.objectStore(DOCUMENTS).delete(underRoom(locator));
465
+ transaction.objectStore(BINARY_TARGETS).delete(underRoom(locator));
466
+ for (const name of [ATTACHMENTS, PENDING_CHANGES, ROOM_DRAFTS]) {
380
467
  removeRoomEntries(transaction.objectStore(name), locator);
381
468
  }
382
469
  }
383
470
  await completed(transaction);
384
471
  },
472
+ async transfers() {
473
+ const transaction = database.transaction(TRANSFERS, 'readonly');
474
+ return settled(transaction.objectStore(TRANSFERS).getAll());
475
+ },
476
+ staged(record) {
477
+ const transaction = database.transaction([DOCUMENTS, BINARY_TARGETS], 'readonly');
478
+ return readLayer(transaction, record.locator, record.transfer);
479
+ },
480
+ async stage(record, page) {
481
+ const transaction = database.transaction([TRANSFERS, DOCUMENTS, BINARY_TARGETS], 'readwrite');
482
+ writeLayer(transaction, record.locator, record.transfer, page, null);
483
+ transaction.objectStore(TRANSFERS).put(record);
484
+ await completed(transaction);
485
+ },
486
+ async abandon(locator) {
487
+ const transaction = database.transaction([TRANSFERS, DOCUMENTS, BINARY_TARGETS], 'readwrite');
488
+ const transfers = transaction.objectStore(TRANSFERS);
489
+ const held = transfers.get(locator);
490
+ held.onsuccess = () => {
491
+ const record = held.result;
492
+ if (record === undefined)
493
+ return;
494
+ transfers.delete(locator);
495
+ const range = underTransfer(locator, record.transfer);
496
+ transaction.objectStore(DOCUMENTS).delete(range);
497
+ transaction.objectStore(BINARY_TARGETS).delete(range);
498
+ };
499
+ await completed(transaction);
500
+ },
385
501
  async generation() {
386
502
  return (await declaration(database)).generation;
387
503
  },
package/dist/wire.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import type { ConnectionRefusal } from './connection.js';
2
- export declare const RUNTIME_WIRE_PROTOCOL = 8;
3
- export declare const PROTOCOL_MISMATCH: ConnectionRefusal;
2
+ import type { Described } from './failure.js';
4
3
  export type RuntimePort = {
5
4
  postMessage(message: unknown): void;
6
5
  addEventListener(type: 'message' | 'close', listener: (event: {
@@ -8,10 +7,58 @@ export type RuntimePort = {
8
7
  }) => void): void;
9
8
  start(): void;
10
9
  };
11
- declare const MEMBERS: readonly ['rooms', 'query', 'search', 'types', 'save', 'history', 'call', 'reached', 'log', 'persistence', 'reauthorize', 'roomDraft.list', 'roomDraft.read', 'roomDraft.write', 'roomDraft.discard', 'presentation.read', 'presentation.write', 'conversation.list', 'conversation.read', 'conversation.create', 'conversation.send', 'conversation.answer', 'conversation.interrupt', 'conversation.kill', 'conversation.cancel', 'conversation.delete', 'chatDraft.write', 'chatDraft.discard'];
12
- declare const TOPICS: readonly ['rooms', 'connection-refusal', 'storage-loss', 'deployment-facts', 'sync-status', 'service-mode', 'query', 'queue', 'room-drafts', 'presentation', 'conversation'];
13
- export type WireMember = (typeof MEMBERS)[number];
14
- export type WireTopic = (typeof TOPICS)[number];
10
+ export type WireReach = 'within' | 'app' | 'runtime' | 'actions' | 'whole';
11
+ declare const MEMBERS: {
12
+ readonly rooms: 'within';
13
+ readonly query: 'within';
14
+ readonly search: 'within';
15
+ readonly types: 'within';
16
+ readonly save: 'within';
17
+ readonly history: 'within';
18
+ readonly call: 'actions';
19
+ readonly reached: 'within';
20
+ readonly log: 'whole';
21
+ readonly persistence: 'runtime';
22
+ readonly reauthorize: 'runtime';
23
+ readonly 'roomDraft.list': 'within';
24
+ readonly 'roomDraft.read': 'within';
25
+ readonly 'roomDraft.write': 'within';
26
+ readonly 'roomDraft.discard': 'within';
27
+ readonly 'presentation.read': 'app';
28
+ readonly 'presentation.write': 'app';
29
+ readonly 'conversation.list': 'within';
30
+ readonly 'conversation.read': 'within';
31
+ readonly 'conversation.create': 'within';
32
+ readonly 'conversation.send': 'within';
33
+ readonly 'conversation.answer': 'within';
34
+ readonly 'conversation.interrupt': 'within';
35
+ readonly 'conversation.kill': 'within';
36
+ readonly 'conversation.cancel': 'within';
37
+ readonly 'conversation.delete': 'within';
38
+ readonly 'chatDraft.write': 'within';
39
+ readonly 'chatDraft.discard': 'within';
40
+ };
41
+ declare const TOPICS: {
42
+ readonly rooms: 'within';
43
+ readonly 'connection-refusal': 'runtime';
44
+ readonly 'storage-loss': 'runtime';
45
+ readonly 'deployment-facts': 'runtime';
46
+ readonly 'sync-status': 'within';
47
+ readonly 'service-mode': 'runtime';
48
+ readonly member: 'runtime';
49
+ readonly query: 'within';
50
+ readonly queue: 'within';
51
+ readonly 'room-drafts': 'within';
52
+ readonly presentation: 'app';
53
+ readonly conversation: 'within';
54
+ readonly conversations: 'within';
55
+ };
56
+ export declare const WIRE_REACH: {
57
+ readonly members: Readonly<Record<string, WireReach>>;
58
+ readonly topics: Readonly<Record<string, WireReach>>;
59
+ };
60
+ export type WireMember = keyof typeof MEMBERS;
61
+ export type WireTopic = keyof typeof TOPICS;
15
62
  export type WireRequest = {
16
63
  kind: 'hello';
17
64
  } | {
@@ -32,11 +79,10 @@ export type WireAnswer = {
32
79
  kind: 'result';
33
80
  id: number;
34
81
  value: unknown;
35
- } | {
82
+ } | ({
36
83
  kind: 'failure';
37
84
  id: number;
38
- message: string;
39
- } | {
85
+ } & Described) | {
40
86
  kind: 'event';
41
87
  id: number;
42
88
  value: unknown;
@@ -48,16 +94,6 @@ export type WireAnswer = {
48
94
  };
49
95
  export declare const AUTHORIZATION_ENDED = "the host authorization ended";
50
96
  export declare const PORT_CLOSED = "the port closed";
51
- export type WireEnvelope = {
52
- mdRuntime: number;
53
- message: WireRequest | WireAnswer;
54
- };
55
- export type Carried = {
56
- matching: boolean;
57
- message: unknown;
58
- };
59
- export declare function envelope(message: WireRequest | WireAnswer): WireEnvelope;
60
- export declare function carried(data: unknown): Carried | null;
61
97
  export declare function request(message: unknown): WireRequest | null;
62
98
  export declare function answer(message: unknown): WireAnswer | null;
63
99
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC,eAAO,MAAM,iBAAiB,EAAE,iBAI/B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACpC,gBAAgB,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,GAAG,IAAI,CAAC;IACjG,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAEF,QAAA,MAAM,OAAO,YACX,OAAO,EACP,OAAO,EACP,QAAQ,EACR,OAAO,EACP,MAAM,EACN,SAAS,EACT,MAAM,EACN,SAAS,EACT,KAAK,EACL,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,EACrB,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,CACX,CAAC;AAEX,QAAA,MAAM,MAAM,YACV,OAAO,EACP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EAAE,MAAM,CAAA;CAAE,CAAC;AAEjC,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAC9C,CAAC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAAC,GAC7C;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAC7C;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,iBAAiB,CAAA;CAAE,GAC/C;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAEtB,eAAO,MAAM,mBAAmB,iCAAiC,CAAC;AAElE,eAAO,MAAM,WAAW,oBAAoB,CAAC;AAQ7C,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,CAiC5D;AAED,wBAAgB,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,GAAG,IAAI,CAgC1D"}
package/dist/wire.js CHANGED
@@ -1,63 +1,51 @@
1
- export const RUNTIME_WIRE_PROTOCOL = 8;
2
- export const PROTOCOL_MISMATCH = {
3
- reason: 'client-host-protocol-mismatch',
4
- reauthorizationOffered: false,
5
- refusal: null,
1
+ const MEMBERS = {
2
+ rooms: 'within',
3
+ query: 'within',
4
+ search: 'within',
5
+ types: 'within',
6
+ save: 'within',
7
+ history: 'within',
8
+ call: 'actions',
9
+ reached: 'within',
10
+ log: 'whole',
11
+ persistence: 'runtime',
12
+ reauthorize: 'runtime',
13
+ 'roomDraft.list': 'within',
14
+ 'roomDraft.read': 'within',
15
+ 'roomDraft.write': 'within',
16
+ 'roomDraft.discard': 'within',
17
+ 'presentation.read': 'app',
18
+ 'presentation.write': 'app',
19
+ 'conversation.list': 'within',
20
+ 'conversation.read': 'within',
21
+ 'conversation.create': 'within',
22
+ 'conversation.send': 'within',
23
+ 'conversation.answer': 'within',
24
+ 'conversation.interrupt': 'within',
25
+ 'conversation.kill': 'within',
26
+ 'conversation.cancel': 'within',
27
+ 'conversation.delete': 'within',
28
+ 'chatDraft.write': 'within',
29
+ 'chatDraft.discard': 'within',
6
30
  };
7
- const MEMBERS = [
8
- 'rooms',
9
- 'query',
10
- 'search',
11
- 'types',
12
- 'save',
13
- 'history',
14
- 'call',
15
- 'reached',
16
- 'log',
17
- 'persistence',
18
- 'reauthorize',
19
- 'roomDraft.list',
20
- 'roomDraft.read',
21
- 'roomDraft.write',
22
- 'roomDraft.discard',
23
- 'presentation.read',
24
- 'presentation.write',
25
- 'conversation.list',
26
- 'conversation.read',
27
- 'conversation.create',
28
- 'conversation.send',
29
- 'conversation.answer',
30
- 'conversation.interrupt',
31
- 'conversation.kill',
32
- 'conversation.cancel',
33
- 'conversation.delete',
34
- 'chatDraft.write',
35
- 'chatDraft.discard',
36
- ];
37
- const TOPICS = [
38
- 'rooms',
39
- 'connection-refusal',
40
- 'storage-loss',
41
- 'deployment-facts',
42
- 'sync-status',
43
- 'service-mode',
44
- 'query',
45
- 'queue',
46
- 'room-drafts',
47
- 'presentation',
48
- 'conversation',
49
- ];
31
+ const TOPICS = {
32
+ rooms: 'within',
33
+ 'connection-refusal': 'runtime',
34
+ 'storage-loss': 'runtime',
35
+ 'deployment-facts': 'runtime',
36
+ 'sync-status': 'within',
37
+ 'service-mode': 'runtime',
38
+ member: 'runtime',
39
+ query: 'within',
40
+ queue: 'within',
41
+ 'room-drafts': 'within',
42
+ presentation: 'app',
43
+ conversation: 'within',
44
+ conversations: 'within',
45
+ };
46
+ export const WIRE_REACH = { members: MEMBERS, topics: TOPICS };
50
47
  export const AUTHORIZATION_ENDED = 'the host authorization ended';
51
48
  export const PORT_CLOSED = 'the port closed';
52
- export function envelope(message) {
53
- return { mdRuntime: RUNTIME_WIRE_PROTOCOL, message };
54
- }
55
- export function carried(data) {
56
- if (typeof data !== 'object' || data === null || !('mdRuntime' in data))
57
- return null;
58
- const record = data;
59
- return { matching: record.mdRuntime === RUNTIME_WIRE_PROTOCOL, message: record.message };
60
- }
61
49
  function body(message) {
62
50
  if (typeof message !== 'object' || message === null)
63
51
  return null;
@@ -77,7 +65,9 @@ export function request(message) {
77
65
  return { kind: 'stop', id: shape.id };
78
66
  if (!Array.isArray(record.input))
79
67
  return null;
80
- if (shape.kind === 'call' && MEMBERS.includes(record.member)) {
68
+ if (shape.kind === 'call' &&
69
+ typeof record.member === 'string' &&
70
+ Object.hasOwn(MEMBERS, record.member)) {
81
71
  return {
82
72
  kind: 'call',
83
73
  id: shape.id,
@@ -85,7 +75,9 @@ export function request(message) {
85
75
  input: record.input,
86
76
  };
87
77
  }
88
- if (shape.kind === 'observe' && TOPICS.includes(record.topic)) {
78
+ if (shape.kind === 'observe' &&
79
+ typeof record.topic === 'string' &&
80
+ Object.hasOwn(TOPICS, record.topic)) {
89
81
  return {
90
82
  kind: 'observe',
91
83
  id: shape.id,
@@ -111,8 +103,17 @@ export function answer(message) {
111
103
  return { kind: 'result', id: shape.id, value: record.value };
112
104
  if (shape.kind === 'event')
113
105
  return { kind: 'event', id: shape.id, value: record.value };
114
- if (shape.kind === 'failure' && typeof record.message === 'string') {
115
- return { kind: 'failure', id: shape.id, message: record.message };
106
+ if (shape.kind === 'failure' &&
107
+ typeof record.message === 'string' &&
108
+ typeof record.code === 'string' &&
109
+ typeof record.retryable === 'boolean') {
110
+ return {
111
+ kind: 'failure',
112
+ id: shape.id,
113
+ message: record.message,
114
+ code: record.code,
115
+ retryable: record.retryable,
116
+ };
116
117
  }
117
118
  return null;
118
119
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/mdruntime",
3
- "version": "0.1.0-c8c4b020a3ec7",
3
+ "version": "0.1.0-c967d1ca66fee",
4
4
  "description": "The headless core of MD App",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -28,6 +28,10 @@
28
28
  "types": "./dist/memory.d.ts",
29
29
  "import": "./dist/memory.js"
30
30
  },
31
+ "./react": {
32
+ "types": "./dist/react.d.ts",
33
+ "import": "./dist/react.js"
34
+ },
31
35
  "./package.json": "./package.json"
32
36
  },
33
37
  "files": [
@@ -37,8 +41,16 @@
37
41
  "LICENSE"
38
42
  ],
39
43
  "dependencies": {
40
- "@agentshouse/mdmodel": "0.1.0-cf72583e19192",
44
+ "@agentshouse/mdmodel": "0.1.0-c4d2418e88679",
41
45
  "@tanstack/db": "0.9.2",
42
46
  "minisearch": "7.2.0"
47
+ },
48
+ "peerDependencies": {
49
+ "react": ">=18"
50
+ },
51
+ "peerDependenciesMeta": {
52
+ "react": {
53
+ "optional": true
54
+ }
43
55
  }
44
56
  }