@agentshouse/mdruntime-adapter 0.1.0-c14f4ba3ce8c5 → 0.1.0-c15a971c6743c

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 (52) hide show
  1. package/README.md +2 -2
  2. package/dist/actions.d.ts +120 -13
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +5 -69
  5. package/dist/adapter.d.ts.map +1 -1
  6. package/dist/adapter.js +82 -140
  7. package/dist/app-reference.d.ts +2 -0
  8. package/dist/app-reference.d.ts.map +1 -0
  9. package/dist/app-reference.js +2 -0
  10. package/dist/crockford.d.ts +4 -0
  11. package/dist/crockford.d.ts.map +1 -0
  12. package/dist/crockford.js +3 -0
  13. package/dist/discovery.d.ts +5 -10
  14. package/dist/discovery.d.ts.map +1 -1
  15. package/dist/discovery.js +18 -32
  16. package/dist/gather.d.ts +0 -1
  17. package/dist/gather.d.ts.map +1 -1
  18. package/dist/gather.js +1 -1
  19. package/dist/house-model.d.ts +2938 -0
  20. package/dist/house-model.d.ts.map +1 -0
  21. package/dist/house-model.js +1614 -0
  22. package/dist/index.d.ts +7 -3
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +6 -2
  25. package/dist/model.d.ts +2 -2
  26. package/dist/model.d.ts.map +1 -1
  27. package/dist/model.js +4 -13
  28. package/dist/part.d.ts +11 -12
  29. package/dist/part.d.ts.map +1 -1
  30. package/dist/part.js +63 -55
  31. package/dist/read.d.ts +10 -15
  32. package/dist/read.d.ts.map +1 -1
  33. package/dist/read.js +35 -47
  34. package/dist/room-stream.d.ts +19 -0
  35. package/dist/room-stream.d.ts.map +1 -0
  36. package/dist/room-stream.js +57 -0
  37. package/dist/room-types.d.ts +2 -1
  38. package/dist/room-types.d.ts.map +1 -1
  39. package/dist/room-types.js +44 -1
  40. package/dist/site.d.ts.map +1 -1
  41. package/dist/site.js +35 -78
  42. package/dist/stream.d.ts +3 -6
  43. package/dist/stream.d.ts.map +1 -1
  44. package/dist/stream.js +38 -288
  45. package/dist/transport.d.ts +13 -20
  46. package/dist/transport.d.ts.map +1 -1
  47. package/dist/transport.js +1 -0
  48. package/dist/write.d.ts +4 -0
  49. package/dist/write.d.ts.map +1 -1
  50. package/dist/write.js +10 -2
  51. package/package.json +7 -3
  52. package/AGENTS.md +0 -312
package/README.md CHANGED
@@ -24,8 +24,8 @@ host.attach(port, 'my-app');
24
24
  ```
25
25
 
26
26
  App code never imports this package; it reaches the Runtime only through the
27
- client its host hands it. The rules an App's agent follows are in the
28
- package's `AGENTS.md`.
27
+ client its host hands it. The rules an App's agent follows are the `apps/` pages
28
+ of House's Guide, which House's `open_guide` opens.
29
29
 
30
30
  ## License
31
31
 
package/dist/actions.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { type AcceptedMessage, type ActionDeclaration, type ActionRequest, type ActionResult, type ConversationAgents, type ConversationHistories, type ConversationHistoryRequest, type FileDeclaration } from '@agentshouse/mdruntime';
1
+ import { type AcceptedMessage, type ActionDeclaration, type ActionRequest, type ActionResult, type ConversationAgents, type ConversationHistories, type ConversationHistoryRequest } from '@agentshouse/mdruntime';
2
2
  import type { HouseDoorAnswer, HouseTransport } from './transport.js';
3
+ export type HouseActDoor = Pick<HouseTransport, 'door'>;
3
4
  export declare const HISTORY_PAGE = 100;
4
- export declare const TRIGGER_ROOMS = 100;
5
5
  type Operated = {
6
6
  readonly operation_id?: string;
7
7
  };
@@ -9,10 +9,6 @@ type ConversationControl = Operated & {
9
9
  readonly conversation: string;
10
10
  };
11
11
  export type AppInputs = {
12
- readonly 'conversation.attach': FileDeclaration & {
13
- readonly room: string;
14
- readonly blob: Blob;
15
- };
16
12
  readonly 'conversation.answer': ConversationControl & {
17
13
  readonly answer: {
18
14
  readonly interaction_id: string;
@@ -31,14 +27,8 @@ export type AppInputs = {
31
27
  readonly operation_id: string;
32
28
  readonly text: string;
33
29
  };
34
- readonly 'trigger.list': {
35
- readonly room_refs: readonly string[];
36
- };
37
30
  };
38
31
  export type AppAnswers = {
39
- readonly 'conversation.attach': {
40
- readonly path: string;
41
- };
42
32
  readonly 'conversation.history': ConversationHistories;
43
33
  };
44
34
  export type AppAnswerAdditions = {
@@ -49,14 +39,131 @@ export type AppAnswerAdditions = {
49
39
  readonly turn: string;
50
40
  };
51
41
  };
42
+ type AppAct<Input = unknown> = {
43
+ readonly door: string;
44
+ readonly batched?: readonly string[];
45
+ carry(transport: HouseActDoor, input: Input, name: string): Promise<ActionResult>;
46
+ };
47
+ declare const APP_ACTS: {
48
+ 'access.read': AppAct<unknown> & {
49
+ readonly door: "rooms/access/read";
50
+ };
51
+ 'conversation.answer': AppAct<Operated & {
52
+ readonly conversation: string;
53
+ } & {
54
+ readonly answer: {
55
+ readonly interaction_id: string;
56
+ readonly response: unknown;
57
+ };
58
+ }> & {
59
+ readonly door: "conversations/interaction/answer";
60
+ };
61
+ 'conversation.create': AppAct<Operated & {
62
+ readonly agent_id: string;
63
+ readonly replaces?: string;
64
+ }> & {
65
+ readonly door: "conversations/create";
66
+ };
67
+ 'conversation.delete': AppAct<ConversationControl> & {
68
+ readonly door: "conversations/delete";
69
+ };
70
+ 'conversation.history': AppAct<ConversationHistoryRequest> & {
71
+ readonly door: "conversations/history";
72
+ };
73
+ 'conversation.interrupt': AppAct<ConversationControl> & {
74
+ readonly door: "conversations/interrupt";
75
+ };
76
+ 'conversation.kill': AppAct<ConversationControl> & {
77
+ readonly door: "conversations/kill";
78
+ };
79
+ 'conversation.markDone': AppAct<unknown> & {
80
+ readonly door: "conversations/done";
81
+ };
82
+ 'conversation.rename': AppAct<unknown> & {
83
+ readonly door: "conversations/rename";
84
+ };
85
+ 'conversation.retry': AppAct<unknown> & {
86
+ readonly door: "conversations/retry";
87
+ };
88
+ 'conversation.send': AppAct<Operated & {
89
+ readonly conversation: string;
90
+ } & {
91
+ readonly operation_id: string;
92
+ readonly text: string;
93
+ }> & {
94
+ readonly door: "conversations/send";
95
+ };
96
+ 'conversation.setOption': AppAct<unknown> & {
97
+ readonly door: "conversations/option";
98
+ };
99
+ 'feature.list': AppAct<unknown> & {
100
+ readonly door: "apps/features/read";
101
+ };
102
+ 'holder.list': AppAct<unknown> & {
103
+ readonly door: "apps/holders";
104
+ };
105
+ 'holder.ring': AppAct<unknown> & {
106
+ readonly door: "apps/ring";
107
+ };
108
+ 'inboxChat.assign': AppAct<unknown> & {
109
+ readonly door: "chats/assign";
110
+ };
111
+ 'inboxChat.return': AppAct<unknown> & {
112
+ readonly door: "chats/return";
113
+ };
114
+ 'inboxChat.takeControl': AppAct<unknown> & {
115
+ readonly door: "chats/take-control";
116
+ };
117
+ 'member.list': AppAct<unknown> & {
118
+ readonly door: "rooms/members";
119
+ };
120
+ 'message.send': AppAct<unknown> & {
121
+ readonly door: "apps/messages/send";
122
+ };
123
+ 'processing.read': AppAct<unknown> & {
124
+ readonly door: "rooms/settings/processing/read";
125
+ };
126
+ 'record.list': AppAct<unknown> & {
127
+ readonly door: "records/read";
128
+ };
129
+ 'relay.read': AppAct<unknown> & {
130
+ readonly door: "apps/relay";
131
+ };
132
+ 'routine.list': AppAct<unknown> & {
133
+ readonly door: "routines/access";
134
+ };
135
+ 'routineAccess.list': AppAct<unknown> & {
136
+ readonly door: "routines/granted";
137
+ };
138
+ 'routineAllowance.list': AppAct<unknown> & {
139
+ readonly door: "routines/allowance";
140
+ };
141
+ 'routineRequest.list': AppAct<unknown> & {
142
+ readonly door: "routines/requests";
143
+ };
144
+ 'storage.read': AppAct<unknown> & {
145
+ readonly door: "storage/inventory";
146
+ };
147
+ 'triggerOccurrence.list': AppAct<unknown> & {
148
+ readonly door: "triggers/fired";
149
+ };
150
+ };
151
+ export type HouseAppActs = {
152
+ readonly [Name in keyof typeof APP_ACTS]: (typeof APP_ACTS)[Name]['door'];
153
+ };
52
154
  export declare const HOUSE_APP_ACTS: Readonly<Record<string, string>>;
53
155
  export declare const SITE_SUBMIT = "submit";
54
156
  export declare const HOUSE_SITE_ACTS: Readonly<Record<string, string>>;
55
157
  export declare const HOUSE_APP_BATCHES: Readonly<Partial<Record<string, readonly string[]>>>;
56
158
  export declare function houseConversationAgents(locator: string): ConversationAgents;
57
159
  export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
58
- export declare function houseAction(transport: HouseTransport, request: ActionRequest): Promise<ActionResult>;
160
+ export declare function houseAction(transport: HouseActDoor, request: ActionRequest): Promise<ActionResult>;
59
161
  export declare function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult;
162
+ type HistoryCursor = {
163
+ accepted_at: string;
164
+ message_id: string;
165
+ };
166
+ export declare function cursorPosition(cursor: HistoryCursor): string;
60
167
  export declare function acceptedMessage(entry: unknown): AcceptedMessage | null;
61
168
  export {};
62
169
  //# sourceMappingURL=actions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAE1B,KAAK,0BAA0B,EAC/B,KAAK,eAAe,EACrB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEtE,eAAO,MAAM,YAAY,MAAM,CAAC;AAEhC,eAAO,MAAM,aAAa,MAAM,CAAC;AAIjC,KAAK,QAAQ,GAAG;IAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnD,KAAK,mBAAmB,GAAG,QAAQ,GAAG;IAAE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAExE,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,qBAAqB,EAAE,eAAe,GAAG;QAChD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,IAAI,EAAE,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;AAED,wBAAgB,WAAW,CACzB,SAAS,EAAE,YAAY,EACvB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAYvB;AAkFD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAQjF;AA+BD,KAAK,aAAa,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AASjE,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAE5D;AAUD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAUtE"}
package/dist/actions.js CHANGED
@@ -1,9 +1,6 @@
1
1
  import { changeBatchIdentity, HISTORY_CONVERSATIONS, } from '@agentshouse/mdruntime';
2
2
  import { doorRefusal } from './refusal.js';
3
- import { finishedUpload, houseUpload } from './upload.js';
4
3
  export const HISTORY_PAGE = 100;
5
- export const TRIGGER_ROOMS = 100;
6
- const OCTET_STREAM = 'application/octet-stream';
7
4
  function mapped(door, input = (given) => given) {
8
5
  return {
9
6
  door,
@@ -12,18 +9,16 @@ function mapped(door, input = (given) => given) {
12
9
  },
13
10
  };
14
11
  }
15
- function carried(door, carry, batched, room) {
12
+ function carried(door, carry, batched) {
16
13
  return {
17
14
  door,
18
15
  ...(batched === undefined ? {} : { batched }),
19
- ...(room === undefined ? {} : { room }),
20
16
  carry: (transport, input, name) => carry(transport, `/door/${door}`, input, name),
21
17
  };
22
18
  }
23
19
  const APP_ACTS = {
24
20
  'access.read': mapped('rooms/access/read'),
25
21
  'conversation.answer': mapped('conversations/interaction/answer', answerBody),
26
- 'conversation.attach': carried('conversations/attach', attachAction, undefined, 'room'),
27
22
  'conversation.create': carried('conversations/create', createAction),
28
23
  'conversation.delete': mapped('conversations/delete', controlBody),
29
24
  'conversation.history': carried('conversations/history', historyAction, ['conversations']),
@@ -50,7 +45,6 @@ const APP_ACTS = {
50
45
  'routineAllowance.list': mapped('routines/allowance'),
51
46
  'routineRequest.list': mapped('routines/requests'),
52
47
  'storage.read': mapped('storage/inventory'),
53
- 'trigger.list': carried('triggers/read', triggersAction, ['room_refs'], 'room_refs'),
54
48
  'triggerOccurrence.list': mapped('triggers/fired'),
55
49
  };
56
50
  export const HOUSE_APP_ACTS = Object.fromEntries(Object.entries(APP_ACTS).map(([name, act]) => [name, act.door]));
@@ -60,14 +54,13 @@ export const HOUSE_SITE_ACTS = {
60
54
  };
61
55
  export const HOUSE_APP_BATCHES = Object.fromEntries(Object.entries(APP_ACTS).flatMap(([name, act]) => act.batched === undefined ? [] : [[name, act.batched]]));
62
56
  const APP_NAMES = new Map(Object.entries(APP_ACTS).map(([name, act]) => [act.door, name]));
63
- const APP_ROOMS = new Map(Object.entries(APP_ACTS).flatMap(([name, act]) => act.room === undefined ? [] : [[name, act.room]]));
64
57
  export function houseConversationAgents(locator) {
65
58
  return { locator, type: 'house-agent', identity: 'agent', name: 'name', retired: 'retired' };
66
59
  }
67
60
  export function declaredActions(routes) {
68
61
  return routes.map((route) => {
69
62
  const name = APP_NAMES.get(route) ?? route;
70
- return { name, inputShape: {}, resultKind: 'house', room: APP_ROOMS.get(name) ?? 'room_ref' };
63
+ return { name, inputShape: {}, resultKind: 'house', room: 'room_ref' };
71
64
  });
72
65
  }
73
66
  export function houseAction(transport, request) {
@@ -181,47 +174,6 @@ async function sendAction(transport, route, input, name) {
181
174
  return outcome;
182
175
  return { ...outcome, result: withTurn(outcome.result) };
183
176
  }
184
- function attachBody(input) {
185
- const room = text(input, 'room');
186
- const name = text(input, 'name');
187
- const sha256 = text(input, 'contentHash');
188
- const bytes = record(input).byteLength;
189
- if (room === undefined || name === undefined || sha256 === undefined)
190
- return null;
191
- if (typeof bytes !== 'number')
192
- return null;
193
- const mediaType = text(input, 'mediaType');
194
- return {
195
- room_ref: room,
196
- name,
197
- bytes,
198
- sha256,
199
- media_type: mediaType !== undefined && mediaType.length > 0 ? mediaType : OCTET_STREAM,
200
- };
201
- }
202
- async function attachAction(transport, route, input, name) {
203
- const body = attachBody(input);
204
- const blob = record(input).blob;
205
- if (body === null || !(blob instanceof Blob))
206
- return malformed();
207
- const outcome = actionOutcome(await transport.door(route, body), name);
208
- if (outcome.kind !== 'action')
209
- return outcome;
210
- const upload = houseUpload(record(outcome.result).upload);
211
- if (upload === null)
212
- return { kind: 'transport-uncertainty' };
213
- const finished = await finishedUpload(transport, upload, blob);
214
- if (finished === null)
215
- return { kind: 'transport-uncertainty' };
216
- const settled = actionOutcome(finished, name);
217
- if (settled.kind !== 'action')
218
- return settled;
219
- const path = text(settled.result, 'path');
220
- if (path === undefined)
221
- return { kind: 'transport-uncertainty' };
222
- const result = { path };
223
- return { kind: 'action', result };
224
- }
225
177
  function historyCursor(value) {
226
178
  const acceptedAt = text(value, 'accepted_at');
227
179
  const messageId = text(value, 'message_id');
@@ -229,7 +181,7 @@ function historyCursor(value) {
229
181
  return null;
230
182
  return { accepted_at: acceptedAt, message_id: messageId };
231
183
  }
232
- function position(cursor) {
184
+ export function cursorPosition(cursor) {
233
185
  return JSON.stringify({ accepted_at: cursor.accepted_at, message_id: cursor.message_id });
234
186
  }
235
187
  function positionCursor(value) {
@@ -247,7 +199,7 @@ export function acceptedMessage(entry) {
247
199
  return {
248
200
  identity: cursor.message_id,
249
201
  turn: text(entry, 'turn_id') ?? cursor.message_id,
250
- position: position(cursor),
202
+ position: cursorPosition(cursor),
251
203
  text: text(entry, 'text') ?? '',
252
204
  message: structuredClone(record(entry)),
253
205
  };
@@ -267,7 +219,7 @@ function historyPage(entry) {
267
219
  const next = held.next === null || held.next === undefined ? undefined : historyCursor(held.next);
268
220
  if (next === null)
269
221
  return null;
270
- return { conversation, messages, ...(next === undefined ? {} : { next: position(next) }) };
222
+ return { conversation, messages, ...(next === undefined ? {} : { next: cursorPosition(next) }) };
271
223
  }
272
224
  function historyAsks(input) {
273
225
  const asked = record(input).conversations;
@@ -286,22 +238,6 @@ function historyAsks(input) {
286
238
  }
287
239
  return asks;
288
240
  }
289
- async function triggersAction(transport, route, input, name) {
290
- const asked = record(input).room_refs;
291
- if (!Array.isArray(asked) || asked.length === 0)
292
- return malformed();
293
- const rooms = [];
294
- for (let at = 0; at < asked.length; at += TRIGGER_ROOMS) {
295
- const outcome = actionOutcome(await transport.door(route, { room_refs: asked.slice(at, at + TRIGGER_ROOMS) }), name);
296
- if (outcome.kind !== 'action')
297
- return outcome;
298
- const answered = record(outcome.result).rooms;
299
- if (!Array.isArray(answered))
300
- return { kind: 'transport-uncertainty' };
301
- rooms.push(...answered);
302
- }
303
- return { kind: 'action', result: { rooms } };
304
- }
305
241
  async function historyAction(transport, route, input, name) {
306
242
  const asks = historyAsks(input);
307
243
  if (asks === null)
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,OAAO,EACP,aAAa,EAkBd,MAAM,wBAAwB,CAAC;AA0ChC,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AA0BxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AA8ErD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAkoBpF"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,OAAO,EAGP,aAAa,EAiBd,MAAM,wBAAwB,CAAC;AAoChC,OAAO,EAUL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AA0BxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAqErD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAgjBpF"}
package/dist/adapter.js CHANGED
@@ -1,21 +1,22 @@
1
1
  import { stepped } from '@agentshouse/mdruntime';
2
2
  import { DISCOVER_PREFIXES, capabilities, discoveredRoom, mapDiscovery, parseDiscovery, trackedFrom, } from './discovery.js';
3
- import { manifestedModels, partModels, streamedModels, viewModels } from './model.js';
4
- import { gathered, gatheredEach, selections } from './gather.js';
3
+ import { streamedModels, viewModels } from './model.js';
4
+ import { gathered, selections } from './gather.js';
5
5
  import { createSiteAdapter } from './site.js';
6
- import { authorityRoot, bootstrapping, emptyScope, housePart, manifested, parseEnumeration, parseFileAddress, parseGrant, parseParted, partInventory, refreshFrom, viewOf, wholeView, } from './read.js';
7
- import { PART_ATTEMPTS, partArrival, partFrame, unverifiedPart } from './part.js';
6
+ import { authorityRoot, bootstrapping, parseEnumeration, parseFileAddress, parseGrant, refreshFrom, viewOf, wholeView, } from './read.js';
7
+ import { roomStreams } from './room-stream.js';
8
8
  import { sha256Hex } from './digest.js';
9
9
  import { finishedUpload, houseUpload } from './upload.js';
10
10
  import { houseAction } from './actions.js';
11
11
  import { classifyDoor, classifyRead, discoveryFailure, doorRefusal } from './refusal.js';
12
12
  import { houseNotifications } from './stream.js';
13
- import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_FILES_GET, DOOR_REVISIONS, } from './transport.js';
13
+ import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_FILES_ATTACH, DOOR_FILES_GET, DOOR_REVISIONS, } from './transport.js';
14
14
  import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, houseMove, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
15
- import { HOUSE_ROOM_TYPES } from './room-types.js';
15
+ import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
16
16
  import { followsVersion, logPosition, presented, reachedVersion, roomVersion, } from './version.js';
17
17
  const UNCERTAIN = { kind: 'transport-uncertainty' };
18
18
  const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
19
+ const OCTET_STREAM = 'application/octet-stream';
19
20
  const EXPIRED_ADDRESS = 403;
20
21
  function lapsedGrant(outcome) {
21
22
  return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
@@ -53,80 +54,48 @@ export function createAgentsHouseAdapter(options) {
53
54
  const notifications = houseNotifications(transport, 'credential');
54
55
  const tracked = new Map();
55
56
  const handed = new Map();
56
- let heldRevisions;
57
+ const rooms = roomStreams('credential');
58
+ const unreused = new Set();
57
59
  let bounds;
58
60
  function declared() {
59
61
  if (bounds === undefined)
60
62
  throw new Error('no Discovery declared the bounds');
61
63
  return bounds;
62
64
  }
63
- async function fetchedPart(entry, continued, listed, received, arriving) {
64
- if (received !== undefined) {
65
- const kept = new Uint8Array(received);
66
- const held = await housePart(continued.room, kept, listed, 'credential');
67
- if (held !== null)
68
- return 'kind' in held ? held : { scope: held, frame: kept };
69
- }
70
- for (let attempt = 0; attempt < PART_ATTEMPTS; attempt += 1) {
71
- const answered = await transport.door(DOOR_BOOTSTRAP, {
72
- prefixes: [authorityRoot(entry.handle)],
73
- part: listed.part,
74
- ...(continued.held === undefined ? {} : { held: [continued.held] }),
75
- }, partArrival(listed, arriving));
76
- const failure = classifyRead(answered.status, answered.body, entry.locator);
77
- if (failure !== null)
78
- return failure;
79
- const frame = partFrame(answered.body);
80
- if (frame === null)
81
- continue;
82
- const scope = await housePart(continued.room, frame, listed, 'credential');
83
- if (scope !== null)
84
- return 'kind' in scope ? scope : { scope, frame };
85
- }
86
- return unverifiedPart(entry.locator);
87
- }
88
- async function manifestPage(asked, continued) {
89
- const inventory = partInventory(continued.room);
90
- if (inventory.parts === 0) {
91
- const page = await partPage(asked, continued, undefined, undefined);
92
- return page.kind === 'bootstrap' ? { ...page, inventory } : page;
93
- }
94
- const { models, seen } = await manifestedModels(continued.room, asked.entry);
95
- return manifested(continued.room, inventory, JSON.stringify({ ...continued, seen }), models);
96
- }
97
- async function partPage(asked, continued, received, arriving) {
98
- const { entry } = asked;
99
- const listed = continued.room.parts[continued.next];
100
- const sent = listed === undefined
101
- ? { scope: emptyScope(continued.room), frame: null }
102
- : await fetchedPart(entry, continued, listed, received, arriving);
103
- if ('kind' in sent)
104
- return sent;
105
- const scope = await reused(sent.scope, asked.held);
65
+ async function streamedPage(entry, token, held) {
66
+ const part = await rooms.part(entry, token);
67
+ if ('kind' in part)
68
+ return part;
69
+ const scope = await reused(part.scope, held);
106
70
  if (scope === null) {
107
- return asked.held === undefined
108
- ? UNCERTAIN_READ
109
- : bootstrapTogether({ entry, held: undefined });
71
+ unreused.add(entry.locator);
72
+ return UNCERTAIN_READ;
110
73
  }
111
- const next = continued.next + 1;
112
- const more = next < continued.room.parts.length;
113
- if (continued.next === 0 && !more)
74
+ if (part.first && part.ended)
114
75
  handed.set(entry.locator, roomVersion(scope));
115
76
  else
116
77
  handed.delete(entry.locator);
117
78
  notifications.reach(entry.authority, scope);
118
- const seen = [
119
- ...continued.seen,
120
- ...entry.schemas.filter((schema) => scope.files.some((file) => file.path === schema)),
121
- ];
122
- const models = await partModels(scope, entry, new Set(seen), !more);
123
79
  return {
124
80
  ...(await stepped(bootstrapping(scope))),
125
- ...(models === undefined ? {} : { models }),
126
- ...(more ? { pageToken: JSON.stringify({ ...continued, next, seen }) } : {}),
127
- ...(sent.frame === null ? {} : { received: sent.frame }),
81
+ ...(part.models === undefined ? {} : { models: part.models }),
82
+ ...(part.pageToken === undefined ? {} : { pageToken: part.pageToken }),
83
+ bytes: part.bytes,
128
84
  };
129
85
  }
86
+ async function openedRoom(entry, request) {
87
+ const reusing = unreused.delete(entry.locator) ? undefined : request.held;
88
+ const files = reusing === undefined
89
+ ? null
90
+ : await heldFiles(entry.authority, reusing, declared().max_held_files);
91
+ const answered = await transport.streamed(DOOR_BOOTSTRAP, {
92
+ prefixes: [authorityRoot(entry.handle)],
93
+ ...(files === null ? {} : { held: [files] }),
94
+ }, request.signal ?? new AbortController().signal);
95
+ if (answered.room === null)
96
+ return classifyDoor(answered.status, answered.body, entry.locator) ?? UNCERTAIN_READ;
97
+ return rooms.head(entry, answered.room, request.arriving, request.signal);
98
+ }
130
99
  async function enumeratedPage(ask, page) {
131
100
  const answer = await transport.door(DOOR_ENUMERATE, {
132
101
  prefixes: [authorityRoot(ask.entry.handle)],
@@ -163,11 +132,7 @@ export function createAgentsHouseAdapter(options) {
163
132
  async function streamed(entry, request, from) {
164
133
  if (handed.get(entry.locator) !== request.fromRoomVersion)
165
134
  return null;
166
- const asked = notifications.edited(entry, from);
167
- const kept = asked.length === 0 || heldRevisions === undefined
168
- ? new Map()
169
- : await heldRevisions(entry.locator, asked);
170
- const advanced = await stepped(notifications.advance(entry, from, (path, revision) => kept.get(path) === revision));
135
+ const advanced = await stepped(notifications.advance(entry, from));
171
136
  if (advanced === null)
172
137
  return null;
173
138
  handed.set(entry.locator, advanced.page.roomVersion);
@@ -223,61 +188,6 @@ export function createAgentsHouseAdapter(options) {
223
188
  return result;
224
189
  return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };
225
190
  }
226
- async function holding(asks) {
227
- const bound = Math.floor(declared().max_held_files / Math.max(1, asks.filter((ask) => ask.held !== undefined).length));
228
- const held = [];
229
- for (const ask of asks) {
230
- if (ask.held === undefined || bound === 0)
231
- continue;
232
- const files = await heldFiles(ask.entry.authority, ask.held, bound);
233
- if (files !== null)
234
- held.push(files);
235
- }
236
- return held;
237
- }
238
- async function bootstrapped(asks, answer) {
239
- let open = asks.map((asked, ask) => ({ entry: asked.entry, asked, ask }));
240
- while (open.length > 0) {
241
- const unreached = [];
242
- for (const part of selections(open, declared().max_prefixes)) {
243
- const held = await holding(part.map(({ asked }) => asked));
244
- const answered = await transport.door(DOOR_BOOTSTRAP, {
245
- prefixes: part.map(({ entry }) => authorityRoot(entry.handle)),
246
- ...(held.length === 0 ? {} : { held }),
247
- });
248
- const classified = part.map(({ entry }) => classifyDoor(answered.status, answered.body, entry.locator));
249
- const parted = classified[0] === null ? parseParted(answered.body) : null;
250
- for (const [index, asked] of part.entries()) {
251
- const failure = classified[index];
252
- if (failure !== null && failure !== undefined) {
253
- answer(asked.ask, failure);
254
- continue;
255
- }
256
- if (parted === null) {
257
- answer(asked.ask, UNCERTAIN_READ);
258
- continue;
259
- }
260
- const room = parted.rooms.find((candidate) => candidate.anchor === asked.entry.authority);
261
- if (room === undefined && parted.next !== undefined) {
262
- unreached.push(asked);
263
- continue;
264
- }
265
- if (room === undefined) {
266
- answer(asked.ask, { kind: 'room-not-readable', locator: asked.entry.locator });
267
- continue;
268
- }
269
- const kept = held.find((files) => files.room === asked.entry.authority);
270
- answer(asked.ask, await manifestPage(asked.asked, {
271
- room,
272
- next: 0,
273
- seen: [],
274
- ...(kept === undefined ? {} : { held: kept }),
275
- }));
276
- }
277
- }
278
- open = unreached;
279
- }
280
- }
281
191
  function layered(asks) {
282
192
  const depths = new Map();
283
193
  const layers = [];
@@ -324,7 +234,6 @@ export function createAgentsHouseAdapter(options) {
324
234
  }
325
235
  return answers;
326
236
  }
327
- const bootstrapTogether = gatheredEach(bootstrapped);
328
237
  const enumerateTogether = gathered(enumerated);
329
238
  async function uploaded(head, changes, delta, bytes, entry, handed, keep) {
330
239
  const paths = batchPaths(changes);
@@ -412,9 +321,22 @@ export function createAgentsHouseAdapter(options) {
412
321
  function linked(answer, locator) {
413
322
  const address = addressed(answer, locator);
414
323
  return address.kind === 'address'
415
- ? { kind: 'link', url: address.url, name: address.name }
324
+ ? { kind: 'link', url: address.url, name: address.name, mediaType: address.mediaType }
416
325
  : address;
417
326
  }
327
+ function refusedAttach(answer, locator) {
328
+ const failure = classifyDoor(answer.status, answer.body, locator);
329
+ if (failure === null)
330
+ return null;
331
+ return failure.kind === 'scoped-refusal'
332
+ ? {
333
+ kind: 'rejected',
334
+ code: failure.code,
335
+ fields: failure.fields,
336
+ retryable: failure.retryable,
337
+ }
338
+ : failure;
339
+ }
418
340
  async function downloaded(ask, locator) {
419
341
  let address = addressed(await ask(), locator);
420
342
  if (address.kind !== 'address')
@@ -447,6 +369,7 @@ export function createAgentsHouseAdapter(options) {
447
369
  }
448
370
  return {
449
371
  roomTypes: HOUSE_ROOM_TYPES,
372
+ nameableRoomTypes: HOUSE_NAMEABLE_ROOM_TYPES,
450
373
  async authorize() {
451
374
  return options.authorize();
452
375
  },
@@ -494,11 +417,9 @@ export function createAgentsHouseAdapter(options) {
494
417
  const entry = authorityFor(request.locator);
495
418
  if (entry === undefined)
496
419
  return { kind: 'room-not-readable', locator: request.locator };
497
- const asked = { entry, held: request.held };
498
- if (request.pageToken !== undefined) {
499
- return partPage(asked, JSON.parse(request.pageToken), request.received, request.arriving);
500
- }
501
- return bootstrapTogether(asked);
420
+ return request.pageToken === undefined
421
+ ? openedRoom(entry, request)
422
+ : streamedPage(entry, request.pageToken, request.held);
502
423
  },
503
424
  async refresh(_authorization, request) {
504
425
  const entry = authorityFor(request.locator);
@@ -567,6 +488,35 @@ export function createAgentsHouseAdapter(options) {
567
488
  return { kind: 'room-not-readable', locator: request.locator };
568
489
  return linked(await ask(), request.locator);
569
490
  },
491
+ async attach(_authorization, request) {
492
+ const entry = authorityFor(request.locator);
493
+ if (entry === undefined)
494
+ return { kind: 'room-not-readable', locator: request.locator };
495
+ const declared = await transport.door(DOOR_FILES_ATTACH, {
496
+ room_ref: entry.authority,
497
+ name: request.name,
498
+ bytes: request.byteLength,
499
+ sha256: request.sha256,
500
+ media_type: request.mediaType.length > 0 ? request.mediaType : OCTET_STREAM,
501
+ });
502
+ const refused = refusedAttach(declared, request.locator);
503
+ if (refused !== null)
504
+ return refused;
505
+ const upload = houseUpload(declared.body?.upload);
506
+ if (upload === null)
507
+ return UNCERTAIN_READ;
508
+ const finished = await finishedUpload(transport, upload, request.blob);
509
+ if (finished === null)
510
+ return UNCERTAIN_READ;
511
+ const unfinished = refusedAttach(finished, request.locator);
512
+ if (unfinished !== null)
513
+ return unfinished;
514
+ const { path, revision } = (finished.body ?? {});
515
+ const root = `/rooms/${entry.handle}/`;
516
+ return typeof path === 'string' && path.startsWith(root) && typeof revision === 'string'
517
+ ? { kind: 'attached', path: path.slice(root.length), revision }
518
+ : UNCERTAIN_READ;
519
+ },
570
520
  reached(locator, version, target) {
571
521
  return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
572
522
  },
@@ -579,15 +529,7 @@ export function createAgentsHouseAdapter(options) {
579
529
  roomStream: {
580
530
  hold: held,
581
531
  reopen: notifications.reopen,
582
- observe(notify, receipts, revisions) {
583
- heldRevisions = revisions;
584
- return notifications.observe(notify, receipts);
585
- },
586
- published(locator, roomVersion) {
587
- const at = logPosition(roomVersion);
588
- if (at !== null)
589
- notifications.published(locator, at);
590
- },
532
+ observe: notifications.observe,
591
533
  },
592
534
  conversations: notifications.conversations,
593
535
  serviceMode: notifications.serviceMode,