@agentshouse/mdruntime-adapter 0.1.0-c29c7d612b2d0 → 0.1.0-c2a26717e70ca

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 (66) hide show
  1. package/README.md +2 -2
  2. package/dist/actions.d.ts +12 -23
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +27 -148
  5. package/dist/adapter.d.ts +1 -0
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +296 -171
  8. package/dist/app-reference.d.ts +2 -0
  9. package/dist/app-reference.d.ts.map +1 -0
  10. package/dist/app-reference.js +2 -0
  11. package/dist/crockford.d.ts +4 -0
  12. package/dist/crockford.d.ts.map +1 -0
  13. package/dist/crockford.js +3 -0
  14. package/dist/discovery.d.ts +7 -10
  15. package/dist/discovery.d.ts.map +1 -1
  16. package/dist/discovery.js +39 -34
  17. package/dist/gather.d.ts +1 -2
  18. package/dist/gather.d.ts.map +1 -1
  19. package/dist/gather.js +5 -15
  20. package/dist/house-model.d.ts +2 -0
  21. package/dist/house-model.d.ts.map +1 -0
  22. package/dist/house-model.js +486 -0
  23. package/dist/index.d.ts +8 -2
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +7 -1
  26. package/dist/model.d.ts +5 -1
  27. package/dist/model.d.ts.map +1 -1
  28. package/dist/model.js +11 -13
  29. package/dist/part.d.ts +14 -0
  30. package/dist/part.d.ts.map +1 -0
  31. package/dist/part.js +90 -0
  32. package/dist/read.d.ts +66 -20
  33. package/dist/read.d.ts.map +1 -1
  34. package/dist/read.js +314 -136
  35. package/dist/room-stream.d.ts +19 -0
  36. package/dist/room-stream.d.ts.map +1 -0
  37. package/dist/room-stream.js +57 -0
  38. package/dist/room-types.d.ts +7 -0
  39. package/dist/room-types.d.ts.map +1 -0
  40. package/dist/room-types.js +125 -0
  41. package/dist/site.d.ts +1 -1
  42. package/dist/site.d.ts.map +1 -1
  43. package/dist/site.js +112 -139
  44. package/dist/stream.d.ts +5 -4
  45. package/dist/stream.d.ts.map +1 -1
  46. package/dist/stream.js +278 -79
  47. package/dist/transport.d.ts +56 -9
  48. package/dist/transport.d.ts.map +1 -1
  49. package/dist/transport.js +2 -1
  50. package/dist/upload.d.ts +12 -0
  51. package/dist/upload.d.ts.map +1 -0
  52. package/dist/upload.js +63 -0
  53. package/dist/version.d.ts +1 -0
  54. package/dist/version.d.ts.map +1 -1
  55. package/dist/version.js +1 -1
  56. package/dist/write.d.ts +16 -1
  57. package/dist/write.d.ts.map +1 -1
  58. package/dist/write.js +106 -57
  59. package/package.json +8 -4
  60. package/AGENTS.md +0 -299
  61. package/dist/handed.d.ts +0 -15
  62. package/dist/handed.d.ts.map +0 -1
  63. package/dist/handed.js +0 -38
  64. package/dist/referrer.d.ts +0 -7
  65. package/dist/referrer.d.ts.map +0 -1
  66. package/dist/referrer.js +0 -35
package/dist/stream.js CHANGED
@@ -1,6 +1,7 @@
1
- import { acceptedMessage } from './actions.js';
1
+ import { ROW_WEIGHT, } from '@agentshouse/mdruntime';
2
+ import { acceptedMessage, cursorPosition } from './actions.js';
2
3
  import { sha256Hex } from './digest.js';
3
- import { binaryFileOf, headChange } from './read.js';
4
+ import { answered, answering, binaryFileOf, folded, forgotten, headChange, revised, } from './read.js';
4
5
  import { roomVersion } from './version.js';
5
6
  const HELD_FRAMES_MAX = 256;
6
7
  function turnOperation(frame) {
@@ -15,6 +16,8 @@ function listedConversation(listed) {
15
16
  created: listed.created_at,
16
17
  finished: listed.finished_at,
17
18
  outcome: listed.outcome,
19
+ waiting: listed.waiting,
20
+ newest: listed.newest === null ? null : cursorPosition(listed.newest),
18
21
  };
19
22
  }
20
23
  function position(value) {
@@ -53,7 +56,9 @@ function assembled(entries) {
53
56
  async function verified(entries) {
54
57
  try {
55
58
  for (const entry of entries) {
56
- if ((await sha256Hex(entry.text ?? '')) !== entry.sha256)
59
+ if (entry.text === undefined || entry.sha256 === undefined)
60
+ continue;
61
+ if ((await sha256Hex(entry.text)) !== entry.sha256)
57
62
  return false;
58
63
  }
59
64
  return true;
@@ -62,10 +67,34 @@ async function verified(entries) {
62
67
  return false;
63
68
  }
64
69
  }
70
+ function resumed(kept, frame) {
71
+ const last = frame.entries.at(-1);
72
+ const point = { parts: frame.index + 1, from: frame.from, target: frame.target };
73
+ if (last?.continued !== true)
74
+ return { ...point, handled: frame.handled, piece: null };
75
+ const text = last.text?.length ?? 0;
76
+ if (last.kind !== 'piece') {
77
+ return last.sha256 === undefined
78
+ ? kept.resume
79
+ : { ...point, handled: frame.handled, piece: { sha256: last.sha256, offset: text } };
80
+ }
81
+ const piece = kept.resume?.piece ?? null;
82
+ if (piece === null)
83
+ return kept.resume;
84
+ const pieces = frame.entries.reduce((sum, entry) => sum + (entry.kind === 'piece' ? (entry.text?.length ?? 0) : 0), 0);
85
+ return {
86
+ ...point,
87
+ handled: frame.handled,
88
+ piece: { sha256: piece.sha256, offset: piece.offset + pieces },
89
+ };
90
+ }
65
91
  export function houseNotifications(transport, mode) {
66
92
  const stream = transport.stream;
67
93
  const lines = new Map();
68
- const staged = new Map();
94
+ const kept = new Map();
95
+ let receipts = null;
96
+ let loaded = Promise.resolve();
97
+ let acknowledging = null;
69
98
  let receiving = Promise.resolve();
70
99
  let verifying = 0;
71
100
  const locators = new Map();
@@ -85,7 +114,10 @@ export function houseNotifications(transport, mode) {
85
114
  event.kind === 'questions' ||
86
115
  event.kind === 'process' ||
87
116
  event.kind === 'commands' ||
88
- event.kind === 'options') {
117
+ event.kind === 'options' ||
118
+ event.kind === 'starting' ||
119
+ event.kind === 'link' ||
120
+ event.kind === 'deliveries') {
89
121
  live.add(event.conversation);
90
122
  }
91
123
  for (const observer of conversationObservers)
@@ -93,7 +125,7 @@ export function houseNotifications(transport, mode) {
93
125
  }
94
126
  function reopened(next) {
95
127
  opening = next;
96
- staged.clear();
128
+ acknowledging = next;
97
129
  const gapped = new Set([...replicated, ...live]);
98
130
  live.clear();
99
131
  for (const conversation of gapped)
@@ -131,6 +163,18 @@ export function houseNotifications(transport, mode) {
131
163
  emitConversation({ kind: 'options', conversation, options: structuredClone(frame.options) });
132
164
  return;
133
165
  }
166
+ if (frame.type === 'starting') {
167
+ emitConversation({ kind: 'starting', conversation, step: frame.step });
168
+ return;
169
+ }
170
+ if (frame.type === 'link') {
171
+ emitConversation({ kind: 'link', conversation, connected: frame.connected });
172
+ return;
173
+ }
174
+ if (frame.type === 'deliveries') {
175
+ emitConversation({ kind: 'deliveries', conversation, unknown: [...frame.unknown] });
176
+ return;
177
+ }
134
178
  if (frame.type === 'interactions') {
135
179
  emitConversation({
136
180
  kind: 'questions',
@@ -155,46 +199,162 @@ export function houseNotifications(transport, mode) {
155
199
  if (line !== undefined)
156
200
  lines.set(authority, { ...line, frames: [] });
157
201
  }
158
- function stage(frame) {
159
- const held = staged.get(frame.authority);
160
- if (frame.index === 0) {
161
- staged.set(frame.authority, { carry: frame.carry, parts: 1, entries: [...frame.entries] });
202
+ async function forget(carries) {
203
+ const held = carries.filter((carry) => kept.delete(carry));
204
+ if (held.length > 0)
205
+ await receipts?.drop(held).catch(() => { });
206
+ }
207
+ async function lost(authority, carry) {
208
+ interrupt(authority);
209
+ await forget([carry]);
210
+ }
211
+ async function stage(frame, via) {
212
+ await loaded;
213
+ const port = receipts;
214
+ if (port === null)
162
215
  return;
163
- }
164
- if (held?.carry !== frame.carry || held.parts !== frame.index) {
165
- staged.delete(frame.authority);
216
+ const held = kept.get(frame.carry);
217
+ if (held === undefined && frame.index !== 0) {
166
218
  interrupt(frame.authority);
167
219
  return;
168
220
  }
169
- held.parts += 1;
170
- held.entries.push(...frame.entries);
221
+ if (held !== undefined &&
222
+ (held.fenced !== null || frame.index > held.parts || frame.index < (held.resume?.parts ?? 0))) {
223
+ await lost(frame.authority, frame.carry);
224
+ return;
225
+ }
226
+ if (held === undefined) {
227
+ await forget([...kept.values()]
228
+ .filter((other) => other.authority === frame.authority && other.fenced === null)
229
+ .map((other) => other.carry));
230
+ }
231
+ const start = held ?? {
232
+ authority: frame.authority,
233
+ carry: frame.carry,
234
+ logEpoch: lines.get(frame.authority)?.logEpoch ?? null,
235
+ after: frame.after,
236
+ parts: 0,
237
+ resume: null,
238
+ fenced: null,
239
+ };
240
+ const next = { ...start, parts: frame.index + 1, resume: resumed(start, frame) };
241
+ const part = { entries: frame.entries };
242
+ try {
243
+ await port.keep(frame.carry, next, { index: frame.index, value: part });
244
+ }
245
+ catch {
246
+ await lost(frame.authority, frame.carry);
247
+ return;
248
+ }
249
+ kept.set(frame.carry, next);
250
+ via?.received(frame.authority, frame.carry, frame.index);
171
251
  }
172
- function carried(frame) {
173
- const held = staged.get(frame.authority);
174
- staged.delete(frame.authority);
175
- const parts = frame.parts === 0
176
- ? []
177
- : held?.carry === frame.carry && held.parts === frame.parts
178
- ? held.entries
179
- : null;
180
- const entries = parts === null ? null : assembled(parts);
252
+ async function keptEntries(carry, parts) {
253
+ if (parts === 0)
254
+ return [];
255
+ if (receipts === null)
256
+ return null;
257
+ const read = (await receipts.parts(carry, parts));
258
+ if (read.length !== parts)
259
+ return null;
260
+ const entries = assembled(read.flatMap((part) => part.entries));
261
+ return entries !== null && (await verified(entries)) ? entries : null;
262
+ }
263
+ async function carried(frame) {
264
+ await loaded;
265
+ const held = kept.get(frame.carry);
266
+ if (frame.parts > 0 && held?.parts !== frame.parts) {
267
+ await lost(frame.authority, frame.carry);
268
+ return;
269
+ }
270
+ const entries = await keptEntries(frame.carry, frame.parts).catch(() => null);
181
271
  if (entries === null) {
182
- interrupt(frame.authority);
272
+ await lost(frame.authority, frame.carry);
183
273
  return;
184
274
  }
185
- const digested = entries.filter((entry) => entry.text !== undefined && entry.sha256 !== undefined);
186
- if (digested.length === 0) {
187
- publish(frame, entries);
275
+ const fenced = {
276
+ ...(held ?? {
277
+ authority: frame.authority,
278
+ carry: frame.carry,
279
+ logEpoch: frame.log_epoch,
280
+ after: frame.after,
281
+ parts: 0,
282
+ resume: null,
283
+ }),
284
+ after: frame.after,
285
+ fenced: { position: frame.position, logEpoch: frame.log_epoch },
286
+ };
287
+ try {
288
+ await receipts?.keep(frame.carry, fenced);
289
+ }
290
+ catch {
291
+ await lost(frame.authority, frame.carry);
188
292
  return;
189
293
  }
190
- return verified(digested).then((whole) => {
191
- if (whole)
192
- publish(frame, entries);
193
- else
194
- interrupt(frame.authority);
195
- });
294
+ kept.set(frame.carry, fenced);
295
+ publish(frame, entries);
196
296
  }
197
- function handle(frame) {
297
+ async function load(port) {
298
+ try {
299
+ for (const { key, head } of await port.heads())
300
+ kept.set(key, head);
301
+ }
302
+ catch {
303
+ kept.clear();
304
+ }
305
+ }
306
+ async function restored(room) {
307
+ const line = lines.get(room.authority);
308
+ let at = room.position;
309
+ const chain = [];
310
+ for (;;) {
311
+ const next = [...kept.values()].find((carry) => carry.authority === room.authority &&
312
+ carry.after === at &&
313
+ carry.fenced?.logEpoch === room.log_epoch);
314
+ if (next?.fenced == null)
315
+ break;
316
+ const entries = await keptEntries(next.carry, next.parts).catch(() => null);
317
+ if (entries === null)
318
+ break;
319
+ chain.push({ carry: next, entries });
320
+ at = next.fenced.position;
321
+ }
322
+ const partial = [...kept.values()].find((carry) => carry.authority === room.authority &&
323
+ carry.fenced === null &&
324
+ carry.logEpoch === room.log_epoch &&
325
+ carry.after === at &&
326
+ carry.resume !== null &&
327
+ carry.resume.parts > 0);
328
+ const stale = [...kept.values()].filter((carry) => carry.authority === room.authority &&
329
+ carry !== partial &&
330
+ !chain.some((link) => link.carry === carry));
331
+ await forget(stale.map((carry) => carry.carry));
332
+ if (line !== undefined && line.logEpoch === room.log_epoch && chain.length > 0) {
333
+ const frames = chain.map(({ carry, entries }) => ({
334
+ after: BigInt(carry.after),
335
+ position: BigInt(carry.fenced.position),
336
+ entries,
337
+ }));
338
+ lines.set(room.authority, { ...line, frames: [...line.frames, ...frames] });
339
+ }
340
+ return {
341
+ ...room,
342
+ position: at,
343
+ ...(partial?.resume == null
344
+ ? {}
345
+ : {
346
+ carry: {
347
+ id: partial.carry,
348
+ parts: partial.resume.parts,
349
+ from: partial.resume.from,
350
+ target: partial.resume.target,
351
+ handled: partial.resume.handled,
352
+ ...(partial.resume.piece === null ? {} : { piece: partial.resume.piece }),
353
+ },
354
+ }),
355
+ };
356
+ }
357
+ function handle(frame, via) {
198
358
  if (frame.type === 'signal') {
199
359
  const mode = frame.service_mode;
200
360
  if (mode !== 'open' && mode !== 'write-halted')
@@ -210,6 +370,10 @@ export function houseNotifications(transport, mode) {
210
370
  });
211
371
  return;
212
372
  }
373
+ if (frame.type === 'authority_changed') {
374
+ emit({ kind: 'authority-changed', scope: { authorities: frame.rooms } });
375
+ return;
376
+ }
213
377
  if (frame.type === 'conversations') {
214
378
  emitConversation({ kind: 'list', entries: frame.conversations.map(listedConversation) });
215
379
  return;
@@ -226,15 +390,16 @@ export function houseNotifications(transport, mode) {
226
390
  frame.type === 'process' ||
227
391
  frame.type === 'commands' ||
228
392
  frame.type === 'options' ||
393
+ frame.type === 'starting' ||
394
+ frame.type === 'link' ||
395
+ frame.type === 'deliveries' ||
229
396
  frame.type === 'interactions' ||
230
397
  frame.type === 'message') {
231
398
  converse(frame);
232
399
  return;
233
400
  }
234
- if (frame.type === 'part') {
235
- stage(frame);
236
- return;
237
- }
401
+ if (frame.type === 'part')
402
+ return stage(frame, via);
238
403
  if (frame.type === 'carried')
239
404
  return carried(frame);
240
405
  }
@@ -262,8 +427,9 @@ export function houseNotifications(transport, mode) {
262
427
  announce(frame.authority, { position: frame.position, logEpoch: frame.log_epoch });
263
428
  }
264
429
  stream.observe((frame) => {
430
+ const via = acknowledging;
265
431
  if (verifying === 0) {
266
- const handled = handle(frame);
432
+ const handled = handle(frame, via);
267
433
  if (handled === undefined)
268
434
  return;
269
435
  verifying += 1;
@@ -274,16 +440,16 @@ export function houseNotifications(transport, mode) {
274
440
  }
275
441
  verifying += 1;
276
442
  receiving = receiving
277
- .then(() => handle(frame))
443
+ .then(() => handle(frame, via))
278
444
  .finally(() => {
279
445
  verifying -= 1;
280
446
  });
281
447
  });
282
448
  stream.opened(reopened);
283
- stream.closed((revoked) => {
449
+ stream.closed(({ revoked, lost }) => {
284
450
  opening = null;
285
- staged.clear();
286
- emit({ kind: 'closed', revoked });
451
+ acknowledging = null;
452
+ emit({ kind: 'closed', revoked, lost });
287
453
  });
288
454
  return {
289
455
  runtime,
@@ -306,8 +472,12 @@ export function houseNotifications(transport, mode) {
306
472
  };
307
473
  },
308
474
  },
309
- observe(notify) {
475
+ observe(notify, port) {
310
476
  observers.add(notify);
477
+ if (receipts === null) {
478
+ receipts = port;
479
+ loaded = load(port);
480
+ }
311
481
  if (opening !== null) {
312
482
  queueMicrotask(() => {
313
483
  if (observers.has(notify))
@@ -328,7 +498,30 @@ export function houseNotifications(transport, mode) {
328
498
  }
329
499
  const current = opening;
330
500
  opening = null;
331
- current?.hold(rooms, runtime);
501
+ if (current === null)
502
+ return;
503
+ void loaded
504
+ .then(() => Promise.all(rooms.map(restored)))
505
+ .then((presented) => {
506
+ current.hold(presented, runtime);
507
+ for (const [index, room] of presented.entries()) {
508
+ if (room.position === rooms[index].position)
509
+ continue;
510
+ announce(room.authority, { position: room.position, logEpoch: room.log_epoch });
511
+ }
512
+ });
513
+ },
514
+ published(locator, at) {
515
+ const authority = [...locators].find(([, held]) => held.includes(locator))?.[0];
516
+ const reached = position(at.position);
517
+ if (authority === undefined || reached === null)
518
+ return;
519
+ void forget([...kept.values()]
520
+ .filter((carry) => carry.authority === authority &&
521
+ carry.fenced !== null &&
522
+ carry.fenced.logEpoch === at.logEpoch &&
523
+ BigInt(carry.fenced.position) <= reached)
524
+ .map((carry) => carry.carry));
332
525
  },
333
526
  reopen() {
334
527
  const current = opening;
@@ -347,6 +540,9 @@ export function houseNotifications(transport, mode) {
347
540
  if (!locators.has(authority))
348
541
  lines.delete(authority);
349
542
  }
543
+ void loaded.then(() => forget([...kept.values()]
544
+ .filter((carry) => !locators.has(carry.authority))
545
+ .map((carry) => carry.carry)));
350
546
  },
351
547
  reach(authority, at) {
352
548
  const line = lines.get(authority);
@@ -361,7 +557,18 @@ export function houseNotifications(transport, mode) {
361
557
  held,
362
558
  });
363
559
  },
364
- advance(tracked, from, holds) {
560
+ edited(tracked, from) {
561
+ const line = lines.get(tracked.authority);
562
+ const start = position(from.position);
563
+ if (line === undefined || start === null || line.logEpoch !== from.logEpoch)
564
+ return [];
565
+ return [
566
+ ...new Set(line.frames
567
+ .filter((frame) => frame.position > start)
568
+ .flatMap((frame) => frame.entries.flatMap((entry) => entry.kind === 'edited' && entry.revision !== undefined ? [entry.path] : []))),
569
+ ];
570
+ },
571
+ *advance(tracked, from, holds) {
365
572
  const line = lines.get(tracked.authority);
366
573
  const start = position(from.position);
367
574
  if (line === undefined || start === null || line.logEpoch !== from.logEpoch)
@@ -370,36 +577,26 @@ export function houseNotifications(transport, mode) {
370
577
  const first = pending[0];
371
578
  if (first === undefined || first.after > start)
372
579
  return null;
373
- const documents = {};
374
- const revisions = {};
375
- const changes = {};
376
- const binaryFiles = {};
377
- const removals = [];
378
- const applied = [];
580
+ const answer = answering();
379
581
  const schemas = new Map();
380
- const forget = (path) => {
381
- delete documents[path];
382
- delete revisions[path];
383
- delete changes[path];
384
- delete binaryFiles[path];
385
- const removed = removals.indexOf(path);
386
- if (removed !== -1)
387
- removals.splice(removed, 1);
388
- };
389
582
  for (const frame of pending) {
390
583
  for (const entry of frame.entries) {
584
+ yield ROW_WEIGHT + (entry.text?.length ?? 0);
585
+ if (entry.kind === 'folder') {
586
+ folded(answer, entry.path, entry.removed === true);
587
+ continue;
588
+ }
391
589
  if (entry.kind === 'edited' &&
392
590
  entry.revision !== undefined &&
393
591
  holds?.(entry.path, entry.revision) === true) {
394
- forget(entry.path);
592
+ forgotten(answer, entry.path);
395
593
  continue;
396
594
  }
397
- applied.push(entry);
398
- if (tracked.schemas.includes(entry.path))
595
+ if (entry.path === tracked.schema)
399
596
  schemas.set(entry.path, entry);
400
597
  if (entry.kind === 'removed') {
401
- forget(entry.path);
402
- removals.push(entry.path);
598
+ forgotten(answer, entry.path);
599
+ answer.removals.add(entry.path);
403
600
  continue;
404
601
  }
405
602
  const binary = binaryFileOf(entry);
@@ -410,31 +607,33 @@ export function houseNotifications(transport, mode) {
410
607
  const head = headChange(entry);
411
608
  if (head === null)
412
609
  return null;
413
- forget(entry.path);
610
+ forgotten(answer, entry.path);
414
611
  if (binary === undefined)
415
- documents[entry.path] = entry.text;
612
+ answer.documents.set(entry.path, entry.text);
416
613
  else
417
- binaryFiles[entry.path] = binary;
614
+ answer.binaryFiles.set(entry.path, binary);
418
615
  const revision = entry.revision ?? binary?.sha256;
419
616
  if (revision !== undefined)
420
- revisions[entry.path] = revision;
617
+ revised(answer, entry.path, revision);
421
618
  if (head !== undefined)
422
- changes[entry.path] = head;
619
+ answer.changes.set(entry.path, head);
423
620
  }
424
621
  }
425
622
  const last = pending.at(-1);
426
- lines.set(tracked.authority, { ...line, frames: pending, held: last.position });
623
+ const current = lines.get(tracked.authority);
624
+ if (current?.logEpoch === line.logEpoch) {
625
+ lines.set(tracked.authority, {
626
+ ...current,
627
+ frames: current.frames.filter((frame) => frame.position > start),
628
+ held: current.held !== null && current.held > last.position ? current.held : last.position,
629
+ });
630
+ }
427
631
  return {
428
632
  page: {
429
633
  kind: 'net-advancement',
430
634
  roomVersion: roomVersion({ position: last.position.toString(), logEpoch: line.logEpoch }),
431
- documents,
432
- revisions,
433
- changes,
434
- binaryFiles,
435
- removals: removals.sort(),
635
+ ...(yield* answered(answer)),
436
636
  },
437
- entries: applied,
438
637
  schemas,
439
638
  };
440
639
  },
@@ -15,27 +15,27 @@ export type HouseDoorAnswer = {
15
15
  body: unknown;
16
16
  };
17
17
  export declare const DOOR_FILES_GET = "/door/files/get";
18
+ export declare const DOOR_FILES_ATTACH = "/door/files/attach";
19
+ export declare const DOOR_FILES_FINISH = "/door/files/finish";
18
20
  export declare const SITE_FILES = "/_house/files/";
19
- export declare const SITE_FILE_RECORD = "record";
20
- export type HouseByteAct = 'authored_batch_upload' | 'conversation_file_upload' | 'binary_stage';
21
- export type HouseByteBody = string | ArrayBuffer | Uint8Array | Blob;
21
+ export type HouseByteAct = 'authored_batch_upload';
22
22
  export type HouseBytesAnswer = {
23
23
  status: number;
24
- blob: Blob | null;
24
+ body: ReadableStream<Uint8Array> | null;
25
+ mediaType: string;
25
26
  };
26
27
  export type HouseByteTransfer = {
27
28
  act: HouseByteAct;
28
29
  url: string;
29
- body: HouseByteBody;
30
- operation?: string;
30
+ body: string;
31
31
  };
32
32
  export type HouseStreamEntry = {
33
33
  path: string;
34
- kind: 'edited' | 'removed' | 'piece';
34
+ kind: 'edited' | 'removed' | 'piece' | 'folder';
35
+ removed?: true;
35
36
  revision?: string;
36
37
  sha256?: string;
37
38
  text?: string;
38
- file?: string;
39
39
  bytes?: number;
40
40
  media_type?: string;
41
41
  author?: {
@@ -58,12 +58,21 @@ export type HouseListedConversation = {
58
58
  created_at: string;
59
59
  finished_at: string | null;
60
60
  outcome: string | null;
61
+ waiting: boolean;
62
+ newest: {
63
+ accepted_at: string;
64
+ message_id: string;
65
+ } | null;
61
66
  };
62
67
  export type HouseStreamFrame = {
63
68
  type: 'part';
64
69
  authority: string;
65
70
  carry: string;
66
71
  index: number;
72
+ after: string;
73
+ from: string;
74
+ target: string;
75
+ handled: number;
67
76
  entries: readonly HouseStreamEntry[];
68
77
  } | {
69
78
  type: 'carried';
@@ -76,6 +85,9 @@ export type HouseStreamFrame = {
76
85
  } | {
77
86
  type: 'opening';
78
87
  expired: readonly string[];
88
+ } | {
89
+ type: 'authority_changed';
90
+ rooms: readonly string[];
79
91
  } | ({
80
92
  type: 'turn';
81
93
  conversation_id: string;
@@ -88,6 +100,10 @@ export type HouseStreamFrame = {
88
100
  type: 'interactions';
89
101
  conversation_id: string;
90
102
  interactions: readonly unknown[];
103
+ } | {
104
+ type: 'deliveries';
105
+ conversation_id: string;
106
+ unknown: readonly string[];
91
107
  } | {
92
108
  type: 'process';
93
109
  conversation_id: string;
@@ -100,6 +116,14 @@ export type HouseStreamFrame = {
100
116
  type: 'options';
101
117
  conversation_id: string;
102
118
  options: LiveFact<'options'>['options'];
119
+ } | {
120
+ type: 'starting';
121
+ conversation_id: string;
122
+ step: string | null;
123
+ } | {
124
+ type: 'link';
125
+ conversation_id: string;
126
+ connected: boolean;
103
127
  } | {
104
128
  type: 'conversations';
105
129
  conversations: readonly HouseListedConversation[];
@@ -113,31 +137,54 @@ export type HouseStreamFrame = {
113
137
  type: 'signal';
114
138
  service_mode: string;
115
139
  };
140
+ export type HouseHeldCarry = {
141
+ id: string;
142
+ parts: number;
143
+ from: string;
144
+ target: string;
145
+ handled: number;
146
+ piece?: {
147
+ sha256: string;
148
+ offset: number;
149
+ };
150
+ };
116
151
  export type HouseHeldRoom = {
117
152
  authority: string;
118
153
  position: string;
119
154
  log_epoch: string;
155
+ carry?: HouseHeldCarry;
120
156
  };
121
157
  export type HouseOpening = {
122
158
  hold(rooms: readonly HouseHeldRoom[], runtime: string): void;
159
+ received(authority: string, carry: string, index: number): void;
123
160
  close(): void;
124
161
  };
162
+ export type HouseClosing = {
163
+ revoked: boolean;
164
+ lost: boolean;
165
+ };
125
166
  export type HouseStream = {
126
167
  observe(receive: (frame: HouseStreamFrame) => void): () => void;
127
168
  opened(notify: (opening: HouseOpening) => void): () => void;
128
- closed(notify: (revoked: boolean) => void): () => void;
169
+ closed(notify: (closing: HouseClosing) => void): () => void;
170
+ };
171
+ export type HouseStreamed = HouseDoorAnswer & {
172
+ room: ReadableStream<Uint8Array> | null;
129
173
  };
130
174
  export type HouseDoor = {
131
175
  door(route: string, body: unknown): Promise<HouseDoorAnswer>;
132
176
  stream: HouseStream;
133
177
  };
134
178
  export type HouseTransport = HouseDoor & {
179
+ streamed(route: string, body: unknown, signal: AbortSignal): Promise<HouseStreamed>;
135
180
  transfer(request: HouseByteTransfer): Promise<HouseDoorAnswer>;
181
+ put(url: string, body: Blob, headers: Readonly<Record<string, string>>): Promise<number>;
136
182
  download(url: string): Promise<HouseBytesAnswer>;
137
183
  };
138
184
  export type HouseSiteTransport = HouseDoor & {
139
185
  online(): boolean;
140
186
  read(route: string): Promise<HouseDoorAnswer>;
187
+ streamed(route: string, signal: AbortSignal): Promise<HouseStreamed>;
141
188
  download(route: string): Promise<HouseBytesAnswer>;
142
189
  };
143
190
  export {};