@agentshouse/mdruntime-adapter 0.1.0-c392f202fd8ec → 0.1.0-c39809d14a99f

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 (53) hide show
  1. package/dist/actions.d.ts +2 -163
  2. package/dist/actions.d.ts.map +1 -1
  3. package/dist/actions.js +7 -222
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/adapter.js +65 -70
  6. package/dist/chunks.d.ts +38 -0
  7. package/dist/chunks.d.ts.map +1 -0
  8. package/dist/chunks.js +247 -0
  9. package/dist/discovery.d.ts +10 -3
  10. package/dist/discovery.d.ts.map +1 -1
  11. package/dist/discovery.js +35 -8
  12. package/dist/history.d.ts +12 -0
  13. package/dist/history.d.ts.map +1 -0
  14. package/dist/history.js +92 -0
  15. package/dist/house-model.d.ts +282 -2593
  16. package/dist/house-model.d.ts.map +1 -1
  17. package/dist/house-model.js +153 -1419
  18. package/dist/index.d.ts +6 -4
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +5 -3
  21. package/dist/model.d.ts +5 -7
  22. package/dist/model.d.ts.map +1 -1
  23. package/dist/model.js +30 -18
  24. package/dist/read.d.ts +19 -9
  25. package/dist/read.d.ts.map +1 -1
  26. package/dist/read.js +46 -143
  27. package/dist/room-types.d.ts +2 -2
  28. package/dist/room-types.d.ts.map +1 -1
  29. package/dist/room-types.js +6 -9
  30. package/dist/search.d.ts +5 -0
  31. package/dist/search.d.ts.map +1 -0
  32. package/dist/search.js +47 -0
  33. package/dist/site.d.ts.map +1 -1
  34. package/dist/site.js +34 -42
  35. package/dist/space-schema.d.ts +7 -0
  36. package/dist/space-schema.d.ts.map +1 -0
  37. package/dist/space-schema.js +18 -0
  38. package/dist/stream.d.ts +6 -4
  39. package/dist/stream.d.ts.map +1 -1
  40. package/dist/stream.js +119 -20
  41. package/dist/transport.d.ts +20 -11
  42. package/dist/transport.d.ts.map +1 -1
  43. package/dist/transport.js +5 -1
  44. package/dist/write.d.ts +2 -1
  45. package/dist/write.d.ts.map +1 -1
  46. package/dist/write.js +8 -23
  47. package/package.json +2 -2
  48. package/dist/part.d.ts +0 -14
  49. package/dist/part.d.ts.map +0 -1
  50. package/dist/part.js +0 -90
  51. package/dist/room-stream.d.ts +0 -19
  52. package/dist/room-stream.d.ts.map +0 -1
  53. package/dist/room-stream.js +0 -57
package/dist/actions.d.ts CHANGED
@@ -1,168 +1,7 @@
1
- import { type AcceptedMessage, type ActionDeclaration, type ActionRequest, type ActionResult, type ConversationHistories, type ConversationHistoryRequest } from '@agentshouse/mdruntime';
1
+ import type { ActionDeclaration, ActionRequest, ActionResult } from '@agentshouse/mdruntime';
2
2
  import type { HouseDoorAnswer, HouseTransport } from './transport.js';
3
3
  export type HouseActDoor = Pick<HouseTransport, 'door'>;
4
- export declare const HISTORY_PAGE = 100;
5
- type Operated = {
6
- readonly operation_id?: string;
7
- };
8
- type ConversationControl = Operated & {
9
- readonly conversation: string;
10
- };
11
- export type AppInputs = {
12
- readonly 'conversation.answer': ConversationControl & {
13
- readonly answer: {
14
- readonly interaction_id: string;
15
- readonly response: unknown;
16
- };
17
- };
18
- readonly 'conversation.create': Operated & {
19
- readonly agent_id: string;
20
- readonly replaces?: string;
21
- };
22
- readonly 'conversation.delete': ConversationControl;
23
- readonly 'conversation.history': ConversationHistoryRequest;
24
- readonly 'conversation.interrupt': ConversationControl;
25
- readonly 'conversation.kill': ConversationControl;
26
- readonly 'conversation.send': ConversationControl & {
27
- readonly operation_id: string;
28
- readonly text: string;
29
- };
30
- };
31
- export type AppAnswers = {
32
- readonly 'conversation.history': ConversationHistories;
33
- };
34
- export type AppAnswerAdditions = {
35
- readonly 'conversation.create': {
36
- readonly conversation: string;
37
- };
38
- readonly 'conversation.send': {
39
- readonly turn: string;
40
- };
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
- 'triggerEvent.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
- };
154
- export declare const HOUSE_APP_ACTS: Readonly<Record<string, string>>;
155
- export declare const SITE_SUBMIT = "submit";
156
- export declare const HOUSE_SITE_ACTS: Readonly<Record<string, string>>;
157
- export declare const HOUSE_APP_BATCHES: Readonly<Partial<Record<string, readonly string[]>>>;
158
4
  export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
159
5
  export declare function houseAction(transport: HouseActDoor, request: ActionRequest): Promise<ActionResult>;
160
- export declare function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult;
161
- type HistoryCursor = {
162
- accepted_at: string;
163
- message_id: string;
164
- };
165
- export declare function cursorPosition(cursor: HistoryCursor): string;
166
- export declare function acceptedMessage(entry: unknown): AcceptedMessage | null;
167
- export {};
6
+ export declare function actionOutcome(answer: HouseDoorAnswer, name: string, input: unknown): ActionResult;
168
7
  //# sourceMappingURL=actions.d.ts.map
@@ -1 +1 @@
1
- {"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OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAIvB;AAwBD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,YAAY,CAUjG"}
package/dist/actions.js CHANGED
@@ -1,71 +1,8 @@
1
- import { changeBatchIdentity, HISTORY_CONVERSATIONS, } from '@agentshouse/mdruntime';
2
1
  import { doorRefusal } from './refusal.js';
3
- export const HISTORY_PAGE = 100;
4
- function mapped(door, input = (given) => given) {
5
- return {
6
- door,
7
- async carry(transport, given, name) {
8
- return actionOutcome(await transport.door(`/door/${door}`, input(given)), name);
9
- },
10
- };
11
- }
12
- function carried(door, carry, batched) {
13
- return {
14
- door,
15
- ...(batched === undefined ? {} : { batched }),
16
- carry: (transport, input, name) => carry(transport, `/door/${door}`, input, name),
17
- };
18
- }
19
- const APP_ACTS = {
20
- 'access.read': mapped('rooms/access/read'),
21
- 'conversation.answer': mapped('conversations/interaction/answer', answerBody),
22
- 'conversation.create': carried('conversations/create', createAction),
23
- 'conversation.delete': mapped('conversations/delete', controlBody),
24
- 'conversation.history': carried('conversations/history', historyAction, ['conversations']),
25
- 'conversation.interrupt': mapped('conversations/interrupt', controlBody),
26
- 'conversation.kill': mapped('conversations/kill', controlBody),
27
- 'conversation.markDone': mapped('conversations/done'),
28
- 'conversation.rename': mapped('conversations/rename'),
29
- 'conversation.retry': mapped('conversations/retry'),
30
- 'conversation.send': carried('conversations/send', sendAction),
31
- 'conversation.setOption': mapped('conversations/option'),
32
- 'feature.list': mapped('apps/features/read'),
33
- 'holder.list': mapped('apps/holders'),
34
- 'holder.ring': mapped('apps/ring'),
35
- 'inboxChat.assign': mapped('chats/assign'),
36
- 'inboxChat.return': mapped('chats/return'),
37
- 'inboxChat.takeControl': mapped('chats/take-control'),
38
- 'member.list': mapped('rooms/members'),
39
- 'message.send': mapped('apps/messages/send'),
40
- 'processing.read': mapped('rooms/settings/processing/read'),
41
- 'record.list': mapped('records/read'),
42
- 'relay.read': mapped('apps/relay'),
43
- 'routine.list': mapped('routines/access'),
44
- 'routineAccess.list': mapped('routines/granted'),
45
- 'routineAllowance.list': mapped('routines/allowance'),
46
- 'routineRequest.list': mapped('routines/requests'),
47
- 'storage.read': mapped('storage/inventory'),
48
- 'triggerEvent.list': mapped('triggers/fired'),
49
- };
50
- export const HOUSE_APP_ACTS = Object.fromEntries(Object.entries(APP_ACTS).map(([name, act]) => [name, act.door]));
51
- export const SITE_SUBMIT = 'submit';
52
- export const HOUSE_SITE_ACTS = {
53
- [SITE_SUBMIT]: 'site/submission',
54
- };
55
- export const HOUSE_APP_BATCHES = Object.fromEntries(Object.entries(APP_ACTS).flatMap(([name, act]) => act.batched === undefined ? [] : [[name, act.batched]]));
56
- const APP_NAMES = new Map(Object.entries(APP_ACTS).map(([name, act]) => [act.door, name]));
57
2
  export function declaredActions(routes) {
58
- return routes.map((route) => {
59
- const name = APP_NAMES.get(route) ?? route;
60
- return { name, inputShape: {}, resultKind: 'house', room: 'room_ref' };
61
- });
3
+ return routes.map((name) => ({ name, inputShape: {}, resultKind: 'house', room: 'room_ref' }));
62
4
  }
63
5
  export function houseAction(transport, request) {
64
- if (Object.hasOwn(APP_ACTS, request.name)) {
65
- return APP_ACTS[request.name].carry(transport, request.input, request.name);
66
- }
67
- if (APP_NAMES.has(request.name))
68
- return Promise.resolve(unimplemented(request.name));
69
6
  const route = routeOf(request.name);
70
7
  if (route === null)
71
8
  return Promise.resolve(malformed());
@@ -82,68 +19,22 @@ function routeOf(name) {
82
19
  return null;
83
20
  }
84
21
  }
85
- function record(value) {
86
- return typeof value === 'object' && value !== null ? value : {};
87
- }
88
- function text(value, name) {
89
- const held = record(value)[name];
90
- return typeof held === 'string' ? held : undefined;
91
- }
92
- function operationId(input) {
93
- return text(input, 'operation_id') ?? changeBatchIdentity();
94
- }
95
22
  function malformed() {
96
23
  return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
97
24
  }
98
25
  function unimplemented(name) {
99
26
  return { kind: 'rejected', code: 'action-unimplemented', fields: { name }, retryable: false };
100
27
  }
101
- function createBody(input) {
102
- const replaces = text(input, 'replaces');
103
- return {
104
- agent_id: text(input, 'agent_id'),
105
- operation_id: operationId(input),
106
- ...(replaces === undefined ? {} : { replaces }),
107
- };
108
- }
109
- function controlBody(input) {
110
- return { conversation_id: text(input, 'conversation'), operation_id: operationId(input) };
111
- }
112
- function answerBody(input) {
113
- const nested = record(record(input).answer);
114
- return {
115
- conversation_id: text(input, 'conversation'),
116
- operation_id: operationId(input),
117
- interaction_id: text(nested, 'interaction_id'),
118
- response: nested.response,
119
- };
120
- }
121
- async function createAction(transport, route, input, name) {
122
- const outcome = actionOutcome(await transport.door(route, createBody(input)), name);
123
- if (outcome.kind !== 'action')
124
- return outcome;
125
- const held = record(outcome.result);
126
- const conversation = text(held, 'conversation_id');
127
- return conversation === undefined
128
- ? outcome
129
- : {
130
- ...outcome,
131
- result: { ...held, conversation },
132
- };
28
+ function numbered(input) {
29
+ return typeof input?.operation_id === 'string';
133
30
  }
134
- function withTurn(body) {
135
- const held = record(body);
136
- const turn = text(held, 'message_id');
137
- return turn === undefined
138
- ? body
139
- : { ...held, turn };
140
- }
141
- export function actionOutcome(answer, name) {
31
+ export function actionOutcome(answer, name, input) {
142
32
  if (answer.status === 401)
143
33
  return { kind: 'revoked-authorization' };
144
34
  const refusal = doorRefusal(answer.body);
145
- if (refusal?.code === 'operation_contended')
35
+ if (refusal?.code === 'operation_contended' && numbered(input)) {
146
36
  return { kind: 'transport-uncertainty' };
37
+ }
147
38
  if (refusal !== null)
148
39
  return { kind: 'rejected', ...refusal };
149
40
  if (answer.status === 404)
@@ -153,111 +44,5 @@ export function actionOutcome(answer, name) {
153
44
  return { kind: 'action', result: answer.body };
154
45
  }
155
46
  async function carry(transport, route, name, input) {
156
- return actionOutcome(await transport.door(route, input), name);
157
- }
158
- function sendBody(input) {
159
- const operation = text(input, 'operation_id');
160
- const said = text(input, 'text');
161
- if (operation === undefined || said === undefined)
162
- return null;
163
- return { conversation_id: text(input, 'conversation'), operation_id: operation, text: said };
164
- }
165
- async function sendAction(transport, route, input, name) {
166
- const body = sendBody(input);
167
- if (body === null)
168
- return malformed();
169
- const outcome = actionOutcome(await transport.door(route, body), name);
170
- if (outcome.kind !== 'action')
171
- return outcome;
172
- return { ...outcome, result: withTurn(outcome.result) };
173
- }
174
- function historyCursor(value) {
175
- const acceptedAt = text(value, 'accepted_at');
176
- const messageId = text(value, 'message_id');
177
- if (acceptedAt === undefined || messageId === undefined)
178
- return null;
179
- return { accepted_at: acceptedAt, message_id: messageId };
180
- }
181
- export function cursorPosition(cursor) {
182
- return JSON.stringify({ accepted_at: cursor.accepted_at, message_id: cursor.message_id });
183
- }
184
- function positionCursor(value) {
185
- try {
186
- return historyCursor(JSON.parse(value));
187
- }
188
- catch {
189
- return null;
190
- }
191
- }
192
- export function acceptedMessage(entry) {
193
- const cursor = historyCursor(entry);
194
- if (cursor === null)
195
- return null;
196
- return {
197
- identity: cursor.message_id,
198
- turn: text(entry, 'turn_id') ?? cursor.message_id,
199
- position: cursorPosition(cursor),
200
- text: text(entry, 'text') ?? '',
201
- message: structuredClone(record(entry)),
202
- };
203
- }
204
- function historyPage(entry) {
205
- const held = record(entry);
206
- const conversation = text(held, 'conversation_id');
207
- if (conversation === undefined || !Array.isArray(held.messages))
208
- return null;
209
- const messages = [];
210
- for (const one of held.messages) {
211
- const message = acceptedMessage(one);
212
- if (message === null)
213
- return null;
214
- messages.push(message);
215
- }
216
- const next = held.next === null || held.next === undefined ? undefined : historyCursor(held.next);
217
- if (next === null)
218
- return null;
219
- return { conversation, messages, ...(next === undefined ? {} : { next: cursorPosition(next) }) };
220
- }
221
- function historyAsks(input) {
222
- const asked = record(input).conversations;
223
- if (!Array.isArray(asked) || asked.length === 0)
224
- return null;
225
- const asks = [];
226
- for (const entry of asked) {
227
- const conversationId = text(entry, 'conversation');
228
- if (conversationId === undefined)
229
- return null;
230
- const afterValue = text(entry, 'after');
231
- const after = afterValue === undefined ? undefined : positionCursor(afterValue);
232
- if (after === null)
233
- return null;
234
- asks.push({ conversation_id: conversationId, ...(after === undefined ? {} : { after }) });
235
- }
236
- return asks;
237
- }
238
- async function historyAction(transport, route, input, name) {
239
- const asks = historyAsks(input);
240
- if (asks === null)
241
- return malformed();
242
- const histories = [];
243
- for (let at = 0; at < asks.length; at += HISTORY_CONVERSATIONS) {
244
- const answer = await transport.door(route, {
245
- conversations: asks.slice(at, at + HISTORY_CONVERSATIONS),
246
- limit: HISTORY_PAGE,
247
- });
248
- const outcome = actionOutcome(answer, name);
249
- if (outcome.kind !== 'action')
250
- return outcome;
251
- const answered = record(outcome.result).histories;
252
- if (!Array.isArray(answered))
253
- return { kind: 'transport-uncertainty' };
254
- for (const entry of answered) {
255
- const page = historyPage(entry);
256
- if (page === null)
257
- return { kind: 'transport-uncertainty' };
258
- histories.push(page);
259
- }
260
- }
261
- const result = { histories };
262
- return { kind: 'action', result };
47
+ return actionOutcome(await transport.door(route, input), name, input);
263
48
  }
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,OAAO,EAIP,aAAa,EAcd,MAAM,wBAAwB,CAAC;AA+BhC,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAmBxB,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;AA6DrD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAyZpF"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,OAAO,EAIP,aAAa,EAed,MAAM,wBAAwB,CAAC;AAyBhC,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAoBxB,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;AAoBrD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA8apF"}
package/dist/adapter.js CHANGED
@@ -1,17 +1,19 @@
1
1
  import { stepped } from '@agentshouse/mdruntime';
2
2
  import { capabilities, discoveredRoom, mapDiscovery, parseAuthorityChange, parseDiscovery, trackedFrom, } from './discovery.js';
3
3
  import { createSiteAdapter } from './site.js';
4
- import { authorityRoot, bootstrapping, parseFileAddress, parseGrant, } from './read.js';
5
- import { roomStreams } from './room-stream.js';
6
- import { sha256Hex } from './digest.js';
4
+ import { parseFileAddress, parseGrant } from './read.js';
5
+ import { chunkedHead, chunkLister, chunkPart } from './chunks.js';
6
+ import { spaceSchemas } from './space-schema.js';
7
7
  import { finishedUpload, houseUpload } from './upload.js';
8
8
  import { houseAction } from './actions.js';
9
+ import { houseSearch } from './search.js';
9
10
  import { classifyDoor, doorRefusal } from './refusal.js';
10
11
  import { houseNotifications, } from './stream.js';
11
12
  import { houseDoorRoute, } from './transport.js';
12
13
  import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, houseMove, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
14
+ import { HOUSE_TYPED_PATHS } from './house-model.js';
13
15
  import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
14
- import { followsVersion, logPosition, presented, reachedVersion, roomVersion } from './version.js';
16
+ import { followsVersion, reachedVersion, roomVersion } from './version.js';
15
17
  const UNCERTAIN = { kind: 'transport-uncertainty' };
16
18
  const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
17
19
  const OCTET_STREAM = 'application/octet-stream';
@@ -19,43 +21,20 @@ const EXPIRED_ADDRESS = 403;
19
21
  function lapsedGrant(outcome) {
20
22
  return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
21
23
  }
22
- async function heldFiles(authority, held, bound) {
23
- const listed = await held.files(null, bound + 1);
24
- const files = listed.slice(0, bound);
25
- const through = listed.length > bound ? (files.at(-1)?.path ?? null) : null;
26
- return files.length === 0 ? null : { room: authority, through, files };
27
- }
28
- async function reused(scope, held) {
29
- const sent = new Set(scope.contents.map((entry) => entry.path));
30
- const contents = [...scope.contents];
31
- const asked = scope.files.filter((file) => file.binary === undefined && !sent.has(file.path));
32
- if (asked.length === 0)
33
- return scope;
34
- if (held === undefined)
35
- return null;
36
- const kept = await held.contents(asked.map(({ path }) => path));
37
- for (const file of asked) {
38
- const found = kept.get(file.path);
39
- if (found === undefined ||
40
- found.revision !== file.revision ||
41
- (await sha256Hex(found.content)) !== file.sha256) {
42
- return null;
43
- }
44
- contents.push({ path: file.path, content: found.content });
45
- }
46
- return { ...scope, contents };
47
- }
48
24
  export function createAgentsHouseAdapter(options) {
49
25
  if ('site' in options)
50
26
  return createSiteAdapter(options.site, options.snapshot === true);
51
27
  const transport = options.transport;
28
+ const spaces = spaceSchemas();
52
29
  const notifications = houseNotifications(transport, 'credential', {
53
30
  opened: async (frame) => (frame === null ? null : opened(frame)),
54
31
  changed,
55
- });
32
+ expired: (authorities) => lister.askAll(authorities.flatMap((authority) => [...tracked.values()].filter((entry) => entry.authority === authority))),
33
+ }, spaces);
56
34
  const tracked = new Map();
57
- const rooms = roomStreams('credential');
58
- const unreused = new Set();
35
+ const lister = chunkLister(transport, () => declared().max_prefixes);
36
+ const chunked = new Map();
37
+ const renewals = new WeakMap();
59
38
  let bounds;
60
39
  function declared() {
61
40
  if (bounds === undefined)
@@ -68,6 +47,7 @@ export function createAgentsHouseAdapter(options) {
68
47
  return null;
69
48
  bounds = document.bounds;
70
49
  tracked.clear();
50
+ lister.forget();
71
51
  for (const entry of trackedFrom(document))
72
52
  tracked.set(entry.locator, entry);
73
53
  notifications.track([...tracked.values()]);
@@ -92,41 +72,52 @@ export function createAgentsHouseAdapter(options) {
92
72
  member: change.member,
93
73
  };
94
74
  }
95
- async function streamedPage(entry, token, held) {
96
- const part = await rooms.part(entry, token);
97
- if ('kind' in part)
98
- return part;
99
- const scope = await reused(part.scope, held);
100
- if (scope === null) {
101
- unreused.add(entry.locator);
102
- return UNCERTAIN_READ;
103
- }
104
- return {
105
- ...(await stepped(bootstrapping(scope))),
106
- ...(part.models === undefined ? {} : { models: part.models }),
107
- ...(part.pageToken === undefined ? {} : { pageToken: part.pageToken }),
108
- bytes: part.bytes,
109
- };
75
+ async function listedRoom(entry) {
76
+ const listed = await lister.list(entry);
77
+ if ('kind' in listed)
78
+ return listed;
79
+ const head = await chunkedHead(listed, entry, spaces);
80
+ if (head.kind === 'bootstrap')
81
+ chunked.set(entry.locator, listed);
82
+ return head;
83
+ }
84
+ async function chunkRead(entry, id) {
85
+ const room = chunked.get(entry.locator);
86
+ const address = room?.chunks.get(id);
87
+ if (room === undefined || address === undefined)
88
+ return null;
89
+ const read = await transport.download(address.url);
90
+ if (read.status !== EXPIRED_ADDRESS)
91
+ return { room, read };
92
+ const renewed = await renewal(entry, room);
93
+ if ('kind' in renewed || !renewed.chunks.has(id))
94
+ return null;
95
+ chunked.set(entry.locator, renewed);
96
+ return { room: renewed, read: await transport.download(renewed.chunks.get(id).url) };
110
97
  }
111
- async function openedRoom(entry, request) {
112
- const reusing = unreused.delete(entry.locator) ? undefined : request.held;
113
- const files = reusing === undefined
114
- ? null
115
- : await heldFiles(entry.authority, reusing, declared().max_held_files);
116
- const answered = await transport.streamed(houseDoorRoute('bootstrap'), {
117
- prefixes: [authorityRoot(entry.handle)],
118
- ...(files === null ? {} : { held: [files] }),
119
- }, request.signal ?? new AbortController().signal);
120
- if (answered.room === null)
121
- return classifyDoor(answered.status, answered.body, entry.locator) ?? UNCERTAIN_READ;
122
- return rooms.head(entry, answered.room, request.arriving, request.signal);
98
+ function renewal(entry, stale) {
99
+ const held = renewals.get(stale);
100
+ if (held !== undefined)
101
+ return held;
102
+ const renewed = lister.renew(entry, [...chunked.keys()].flatMap((locator) => tracked.get(locator) ?? []));
103
+ renewals.set(stale, renewed);
104
+ return renewed;
123
105
  }
124
- function held(rooms) {
125
- notifications.send(rooms.flatMap((room) => {
126
- const entry = tracked.get(room.locator);
127
- const at = logPosition(room.roomVersion);
128
- return entry === undefined || at === null ? [] : [presented(entry.authority, at)];
129
- }));
106
+ function hold(rooms) {
107
+ for (const room of rooms) {
108
+ const listed = chunked.get(room.locator);
109
+ if (listed !== undefined &&
110
+ room.roomVersion !== null &&
111
+ reachedVersion(room.roomVersion, roomVersion(listed), listed.logEpoch))
112
+ chunked.delete(room.locator);
113
+ }
114
+ notifications.send(rooms);
115
+ }
116
+ async function chunkPage(entry, id, arriving) {
117
+ const fetched = await chunkRead(entry, id);
118
+ if (fetched === null || fetched.read.status !== 200)
119
+ return UNCERTAIN_READ;
120
+ return chunkPart(fetched.read.body, fetched.room, id, arriving);
130
121
  }
131
122
  function authorityFor(locator) {
132
123
  return tracked.get(locator);
@@ -285,6 +276,7 @@ export function createAgentsHouseAdapter(options) {
285
276
  return {
286
277
  roomTypes: HOUSE_ROOM_TYPES,
287
278
  nameableRoomTypes: HOUSE_NAMEABLE_ROOM_TYPES,
279
+ typedPaths: HOUSE_TYPED_PATHS,
288
280
  async authorize() {
289
281
  return options.authorize();
290
282
  },
@@ -293,8 +285,8 @@ export function createAgentsHouseAdapter(options) {
293
285
  if (entry === undefined)
294
286
  return { kind: 'room-not-readable', locator: request.locator };
295
287
  return request.pageToken === undefined
296
- ? openedRoom(entry, request)
297
- : streamedPage(entry, request.pageToken, request.held);
288
+ ? listedRoom(entry)
289
+ : chunkPage(entry, request.pageToken, request.arriving);
298
290
  },
299
291
  async mutate(_authorization, request, keep) {
300
292
  const entry = authorityFor(request.locator);
@@ -311,7 +303,7 @@ export function createAgentsHouseAdapter(options) {
311
303
  : houseMove(batch, entry.handle, into.handle);
312
304
  if (mapped.kind === 'unmapped')
313
305
  return rejectedMapping(mapped);
314
- const head = operationHead(batch);
306
+ const head = operationHead(batch, entry.authority);
315
307
  const delta = deltaBody(mapped.changes);
316
308
  const bytes = deltaBytes(delta);
317
309
  const handed = request.upload;
@@ -386,8 +378,11 @@ export function createAgentsHouseAdapter(options) {
386
378
  async action(_authorization, request) {
387
379
  return withAt(await houseAction(transport, request));
388
380
  },
381
+ search(_authorization, request) {
382
+ return houseSearch(transport, [...tracked.values()], request);
383
+ },
389
384
  roomStream: {
390
- hold: held,
385
+ hold,
391
386
  observe: notifications.observe,
392
387
  },
393
388
  conversations: notifications.conversations,