@agentshouse/mdruntime-adapter 0.1.0-cefa8b4106453 → 0.1.0-cf03cdc5ecb06

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 (75) hide show
  1. package/README.md +1 -1
  2. package/dist/actions.d.ts.map +1 -1
  3. package/dist/actions.js +34 -11
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/adapter.js +124 -116
  6. package/dist/authored-path.d.ts +54 -3
  7. package/dist/authored-path.d.ts.map +1 -1
  8. package/dist/authored-path.js +142 -11
  9. package/dist/chunks.d.ts +2 -3
  10. package/dist/chunks.d.ts.map +1 -1
  11. package/dist/chunks.js +72 -38
  12. package/dist/discovery.d.ts +25 -5
  13. package/dist/discovery.d.ts.map +1 -1
  14. package/dist/discovery.js +169 -21
  15. package/dist/history.d.ts +1 -6
  16. package/dist/history.d.ts.map +1 -1
  17. package/dist/history.js +21 -28
  18. package/dist/index.d.ts +7 -9
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +7 -9
  21. package/dist/model.d.ts +5 -5
  22. package/dist/model.d.ts.map +1 -1
  23. package/dist/model.js +17 -27
  24. package/dist/read.d.ts +11 -24
  25. package/dist/read.d.ts.map +1 -1
  26. package/dist/read.js +74 -47
  27. package/dist/refusal.d.ts +5 -1
  28. package/dist/refusal.d.ts.map +1 -1
  29. package/dist/refusal.js +23 -6
  30. package/dist/renamed.d.ts +10 -0
  31. package/dist/renamed.d.ts.map +1 -0
  32. package/dist/renamed.js +20 -0
  33. package/dist/room-query.d.ts +4 -0
  34. package/dist/room-query.d.ts.map +1 -0
  35. package/dist/room-query.js +63 -0
  36. package/dist/search.d.ts.map +1 -1
  37. package/dist/search.js +4 -4
  38. package/dist/session-content/check.d.ts +4 -2
  39. package/dist/session-content/index.d.ts +3 -4
  40. package/dist/session-content/parts.d.ts +16 -88
  41. package/dist/session-content/state.d.ts +21 -23
  42. package/dist/session-content/turn.d.ts +82 -258
  43. package/dist/site.d.ts.map +1 -1
  44. package/dist/site.js +56 -22
  45. package/dist/space-schema.d.ts.map +1 -1
  46. package/dist/space-schema.js +1 -8
  47. package/dist/stream.d.ts +4 -4
  48. package/dist/stream.d.ts.map +1 -1
  49. package/dist/stream.js +151 -82
  50. package/dist/transport.d.ts +70 -18
  51. package/dist/transport.d.ts.map +1 -1
  52. package/dist/transport.js +47 -9
  53. package/dist/uncertain.d.ts +5 -0
  54. package/dist/uncertain.d.ts.map +1 -0
  55. package/dist/uncertain.js +11 -0
  56. package/dist/upload.d.ts +7 -1
  57. package/dist/upload.d.ts.map +1 -1
  58. package/dist/upload.js +49 -6
  59. package/dist/write.d.ts +3 -8
  60. package/dist/write.d.ts.map +1 -1
  61. package/dist/write.js +88 -106
  62. package/package.json +4 -3
  63. package/dist/app-reference.d.ts +0 -1
  64. package/dist/app-reference.d.ts.map +0 -1
  65. package/dist/app-reference.js +0 -2
  66. package/dist/crockford.d.ts +0 -3
  67. package/dist/crockford.d.ts.map +0 -1
  68. package/dist/crockford.js +0 -3
  69. package/dist/house-model.d.ts +0 -830
  70. package/dist/house-model.d.ts.map +0 -1
  71. package/dist/house-model.js +0 -465
  72. package/dist/room-types.d.ts +0 -4
  73. package/dist/room-types.d.ts.map +0 -1
  74. package/dist/room-types.js +0 -135
  75. package/dist/session-content/bounds.d.ts +0 -7
package/README.md CHANGED
@@ -25,7 +25,7 @@ host.attach(port, { app: 'my-app' });
25
25
 
26
26
  App code never imports this package; it reaches the Runtime only through the
27
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 `guide/open` opens.
28
+ of House's Guide, which House's `guide` tool opens.
29
29
 
30
30
  ## License
31
31
 
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE7F,OAAO,KAAK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AK,EAAE,OAAO,GAAG,YAAY,CAajG"}
package/dist/actions.js CHANGED
@@ -1,16 +1,34 @@
1
- import { doorRefusal, resetOf } from './refusal.js';
1
+ import { answeredFailure, doorRefusal, resetOf } from './refusal.js';
2
+ import { movedPaths, renamedHandle } from './renamed.js';
3
+ import { refusedFor } from './uncertain.js';
2
4
  export const HOUSE_UNKEPT_READS = [
3
- 'account/security/read',
4
- 'clients/last-use/list',
5
+ 'account.read security',
6
+ 'account.billing',
7
+ 'account.clients',
5
8
  ];
6
9
  export const HOUSE_LEADING_READS = [
7
- 'rooms/list',
10
+ 'app.list',
8
11
  'apps/list',
9
12
  'sites/list',
10
13
  'rooms/members/list',
14
+ 'sharing.members',
11
15
  ];
16
+ const ROOM_SELECTORS = new Map([
17
+ ['update', { room: 'changes.room', roomPaths: ['changes.path', 'changes.to', 'paths', 'mount'] }],
18
+ ['sharing', { room: 'room' }],
19
+ ['sharing_update', { room: 'room' }],
20
+ ['inbox_update', { room: 'room', roomPaths: ['path'] }],
21
+ ['agent', { room: 'room' }],
22
+ ['agent_update', { room: 'room' }],
23
+ ['environment', { room: 'room' }],
24
+ ]);
12
25
  export function declaredActions(routes) {
13
- return routes.map((name) => ({ name, inputShape: {}, resultKind: 'house', room: 'room_ref' }));
26
+ return routes.map((name) => ({
27
+ name,
28
+ inputShape: {},
29
+ resultKind: 'house',
30
+ ...(ROOM_SELECTORS.get(name) ?? { room: 'room_ref' }),
31
+ }));
14
32
  }
15
33
  export function houseAction(transport, request) {
16
34
  const route = routeOf(request.name);
@@ -42,19 +60,24 @@ export function actionOutcome(answer, name, input) {
42
60
  if (answer.status === 401)
43
61
  return { kind: 'revoked-authorization' };
44
62
  const refusal = doorRefusal(answer.body);
45
- if (refusal?.code === 'operation_contended' && numbered(input)) {
46
- return { kind: 'transport-uncertainty' };
47
- }
63
+ if (refusal?.code === 'operation_contended' && numbered(input))
64
+ return refusedFor(refusal);
48
65
  if (refusal !== null) {
49
66
  const reset = resetOf(refusal);
50
67
  return { kind: 'rejected', ...refusal, ...(reset === undefined ? {} : { reset }) };
51
68
  }
52
69
  if (answer.status === 404)
53
70
  return unimplemented(name);
54
- if (answer.status === 0 || answer.status >= 400)
55
- return { kind: 'transport-uncertainty' };
71
+ if (answer.status === 0 || answer.status >= 400) {
72
+ return answeredFailure(answer.status, answer.body);
73
+ }
56
74
  return { kind: 'action', result: answer.body };
57
75
  }
58
76
  async function carry(transport, route, name, input) {
59
- return actionOutcome(await transport.door(route, input), name, input);
77
+ const answered = actionOutcome(await transport.door(route, input), name, input);
78
+ const renamed = renamedHandle(answered);
79
+ if (renamed === null)
80
+ return answered;
81
+ const moved = movedPaths(input, ROOM_SELECTORS.get(name)?.roomPaths ?? [], renamed);
82
+ return actionOutcome(await transport.door(route, moved), name, moved);
60
83
  }
@@ -1 +1 @@
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;AAqBxB,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,CA+apF"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAIV,OAAO,EAIP,aAAa,EAkBd,MAAM,wBAAwB,CAAC;AA0BhC,OAAO,EAIL,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;AAcrD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA0cpF"}
package/dist/adapter.js CHANGED
@@ -1,23 +1,21 @@
1
+ import { HOUSE_ROOM_TYPES, HOUSE_TYPED_PATHS } from '@agentshouse/mdmodel';
1
2
  import { stepped } from '@agentshouse/mdruntime';
2
3
  import { capabilities, discoveredRoom, mapDiscovery, parseAuthorityChange, parseDiscovery, trackedFrom, } from './discovery.js';
3
4
  import { createSiteAdapter } from './site.js';
4
5
  import { parseFileAddress, parseGrant } from './read.js';
5
6
  import { chunkedHead, chunkLister, chunkPart } from './chunks.js';
6
- import { spaceSchemas } from './space-schema.js';
7
- import { finishedUpload, houseUpload } from './upload.js';
7
+ import { finishedUpload, houseUpload, stagedBatch } from './upload.js';
8
8
  import { houseAction, HOUSE_LEADING_READS, HOUSE_UNKEPT_READS } from './actions.js';
9
+ import { houseQuery } from './room-query.js';
9
10
  import { houseSearch } from './search.js';
10
- import { classifyDoor, doorRefusal } from './refusal.js';
11
+ import { answeredFailure, classifyDoor, keyedFailure } from './refusal.js';
12
+ import { UNANSWERED, unusable } from './uncertain.js';
11
13
  import { houseNotifications, } from './stream.js';
12
14
  import { houseDoorRoute, } from './transport.js';
15
+ import { renamedHandle } from './renamed.js';
13
16
  import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, houseMove, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
14
17
  import { admittedPath } from './authored-path.js';
15
- import { HOUSE_TYPED_PATHS } from './house-model.js';
16
- import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
17
18
  import { followsVersion, reachedVersion, roomVersion } from './version.js';
18
- const UNCERTAIN = { kind: 'transport-uncertainty' };
19
- const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
20
- const OCTET_STREAM = 'application/octet-stream';
21
19
  const EXPIRED_ADDRESS = 403;
22
20
  function lapsedGrant(outcome) {
23
21
  return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
@@ -26,14 +24,13 @@ export function createAgentsHouseAdapter(options) {
26
24
  if ('site' in options)
27
25
  return createSiteAdapter(options.site, options.snapshot === true);
28
26
  const transport = options.transport;
29
- const spaces = spaceSchemas();
30
27
  const notifications = houseNotifications(transport, 'credential', {
31
28
  opened: async (frame) => (frame === null ? null : opened(frame)),
32
29
  changed,
33
- expired: (authorities) => lister.askAll(authorities.flatMap((authority) => [...tracked.values()].filter((entry) => entry.authority === authority))),
34
- }, spaces);
30
+ expired: (entries) => lister.askAll(entries),
31
+ });
35
32
  const tracked = new Map();
36
- const lister = chunkLister(transport, () => declared().max_prefixes);
33
+ const lister = chunkLister(transport, () => declared().max_prefixes, (locator) => tracked.get(locator));
37
34
  const chunked = new Map();
38
35
  const renewals = new WeakMap();
39
36
  let bounds;
@@ -55,13 +52,16 @@ export function createAgentsHouseAdapter(options) {
55
52
  return {
56
53
  ...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions)),
57
54
  member: document.member,
55
+ timeZone: document.timeZone,
56
+ roomList: document.roomList,
58
57
  };
59
58
  }
60
59
  function changed(frame) {
61
60
  const change = parseAuthorityChange(frame);
62
61
  if (change === null)
63
62
  return null;
64
- for (const locator of change.left)
63
+ const unheld = [...change.left, ...change.listed];
64
+ for (const locator of unheld)
65
65
  tracked.delete(locator);
66
66
  for (const entry of trackedFrom(change))
67
67
  tracked.set(entry.locator, entry);
@@ -69,15 +69,17 @@ export function createAgentsHouseAdapter(options) {
69
69
  return {
70
70
  kind: 'authority-changed',
71
71
  rooms: change.authorities.map((authority) => discoveredRoom(authority)),
72
- left: change.left,
72
+ left: unheld,
73
73
  member: change.member,
74
+ timeZone: change.timeZone,
75
+ roomList: { ...change.roomList, left: change.left },
74
76
  };
75
77
  }
76
78
  async function listedRoom(entry) {
77
79
  const listed = await lister.list(entry);
78
80
  if ('kind' in listed)
79
81
  return listed;
80
- const head = await chunkedHead(listed, entry, spaces);
82
+ const head = await chunkedHead(listed, entry);
81
83
  if (head.kind === 'bootstrap')
82
84
  chunked.set(entry.locator, listed);
83
85
  return head;
@@ -86,15 +88,18 @@ export function createAgentsHouseAdapter(options) {
86
88
  const room = chunked.get(entry.locator);
87
89
  const address = room?.chunks.get(id);
88
90
  if (room === undefined || address === undefined)
89
- return null;
91
+ return UNANSWERED;
90
92
  const read = await transport.download(address.url);
91
93
  if (read.status !== EXPIRED_ADDRESS)
92
94
  return { room, read };
93
95
  const renewed = await renewal(entry, room);
94
- if ('kind' in renewed || !renewed.chunks.has(id))
95
- return null;
96
+ if ('kind' in renewed)
97
+ return renewed;
98
+ const renewedAddress = renewed.chunks.get(id);
99
+ if (renewedAddress === undefined)
100
+ return unusable();
96
101
  chunked.set(entry.locator, renewed);
97
- return { room: renewed, read: await transport.download(renewed.chunks.get(id).url) };
102
+ return { room: renewed, read: await transport.download(renewedAddress.url) };
98
103
  }
99
104
  function renewal(entry, stale) {
100
105
  const held = renewals.get(stale);
@@ -116,8 +121,10 @@ export function createAgentsHouseAdapter(options) {
116
121
  }
117
122
  async function chunkPage(entry, id, arriving) {
118
123
  const fetched = await chunkRead(entry, id);
119
- if (fetched === null || fetched.read.status !== 200)
120
- return UNCERTAIN_READ;
124
+ if ('kind' in fetched)
125
+ return fetched;
126
+ if (fetched.read.status !== 200)
127
+ return answeredFailure(fetched.read.status, null);
121
128
  return chunkPart(fetched.read.body, fetched.room, id, arriving);
122
129
  }
123
130
  function authorityFor(locator) {
@@ -143,8 +150,9 @@ export function createAgentsHouseAdapter(options) {
143
150
  if (handed !== undefined && handed.sha256 === sha256) {
144
151
  return { body: { ...head, paths, upload: handed, runtime: notifications.runtime } };
145
152
  }
146
- const minted = await transport.door(houseDoorRoute('files/batch-upload'), {
153
+ const minted = await transport.door(houseDoorRoute('update'), {
147
154
  ...head,
155
+ op: 'stage',
148
156
  paths,
149
157
  bytes,
150
158
  sha256,
@@ -156,38 +164,21 @@ export function createAgentsHouseAdapter(options) {
156
164
  }
157
165
  const grant = parseGrant(minted.body);
158
166
  if (grant === null)
159
- return { outcome: UNCERTAIN };
167
+ return { outcome: unusable() };
160
168
  const delivered = await transport.transfer({
161
169
  url: grant.url,
162
170
  body: `${grant.operation}\n${delta}`,
163
171
  });
164
- if (delivered.status !== 200)
165
- return { outcome: UNCERTAIN };
172
+ if (delivered.status !== 200) {
173
+ return { outcome: answeredFailure(delivered.status, delivered.body) };
174
+ }
166
175
  const holding = parseGrant(delivered.body);
167
176
  if (holding === null)
168
- return { outcome: UNCERTAIN };
177
+ return { outcome: unusable() };
169
178
  const upload = { url: holding.url, operation: holding.operation, bytes, sha256 };
170
179
  await keep(upload);
171
180
  return { body: { ...head, paths, upload, runtime: notifications.runtime } };
172
181
  }
173
- async function staged(answer, { changeBatch: batch, file }) {
174
- const refusal = doorRefusal(answer.body);
175
- if (refusal?.code !== 'files_unstaged')
176
- return null;
177
- const uploads = refusal.fields.upload;
178
- if (!Array.isArray(uploads))
179
- return false;
180
- for (const named of uploads) {
181
- const upload = houseUpload(named);
182
- const change = batch.changes.find((held) => held.kind === 'binary' && held.sha256 === named.sha256);
183
- if (upload === null || change === undefined)
184
- return false;
185
- const finished = await finishedUpload(transport, upload, await file(change.localId));
186
- if (finished?.body?.staged !== true)
187
- return false;
188
- }
189
- return true;
190
- }
191
182
  async function submit(request, head, changes, delta, bytes, entry, handed, keep, into) {
192
183
  const inline = { ...head, changes, runtime: notifications.runtime };
193
184
  const prepared = uploadable(inline, bytes, declared())
@@ -195,15 +186,12 @@ export function createAgentsHouseAdapter(options) {
195
186
  : { body: inline };
196
187
  if ('outcome' in prepared)
197
188
  return prepared.outcome;
198
- const answer = await transport.door(houseDoorRoute('files/batch'), prepared.body);
199
- const stagedFiles = await staged(answer, request);
200
- if (stagedFiles === false)
201
- return UNCERTAIN;
202
- const settled = stagedFiles === null
203
- ? answer
204
- : await transport.door(houseDoorRoute('files/batch'), prepared.body);
205
- if (stagedFiles === true && (await staged(settled, request)) !== null)
206
- return UNCERTAIN;
189
+ const settled = await stagedBatch(transport, prepared.body, (sha256) => {
190
+ const change = request.changeBatch.changes.find((held) => held.kind === 'binary' && held.sha256 === sha256);
191
+ return change === undefined ? null : request.file(change.localId);
192
+ });
193
+ if ('kind' in settled)
194
+ return settled;
207
195
  return stepped(mutationOutcome(settled.status, settled.body, entry.locator, entry.handle, into === undefined
208
196
  ? undefined
209
197
  : {
@@ -211,28 +199,26 @@ export function createAgentsHouseAdapter(options) {
211
199
  destination: { authority: into.authority, handle: into.handle },
212
200
  }));
213
201
  }
214
- function addressed(answer, locator) {
215
- const failure = classifyDoor(answer.status, answer.body, locator);
216
- if (failure !== null) {
217
- return failure.kind === 'scoped-refusal'
218
- ? {
219
- kind: 'rejected',
220
- code: failure.code,
221
- fields: failure.fields,
222
- retryable: failure.retryable,
223
- }
224
- : failure;
225
- }
226
- const address = parseFileAddress(answer.body);
227
- return address === null ? UNCERTAIN_READ : { kind: 'address', ...address };
228
- }
229
- function linked(answer, locator) {
230
- const address = addressed(answer, locator);
231
- return address.kind === 'address'
232
- ? { kind: 'link', url: address.url, name: address.name, mediaType: address.mediaType }
233
- : address;
202
+ async function mutated(request, keep, entry, into) {
203
+ const batch = request.changeBatch;
204
+ const mapped = into === undefined
205
+ ? houseChanges(batch, entry.handle, request.written)
206
+ : houseMove(batch, entry.handle, into.handle);
207
+ if (mapped.kind === 'unmapped')
208
+ return rejectedMapping(mapped);
209
+ const head = operationHead(batch);
210
+ const delta = deltaBody(mapped.changes);
211
+ const bytes = deltaBytes(delta);
212
+ const handed = request.upload;
213
+ const answer = (upload) => submit(request, head, mapped.changes, delta, bytes, entry, upload, keep, into);
214
+ const outcome = await answer(handed);
215
+ if (handed === undefined || !lapsedGrant(outcome))
216
+ return outcome;
217
+ return answer(undefined);
234
218
  }
235
- function refusedAttach(answer, locator) {
219
+ function refusedOn(answer, locator) {
220
+ if (locator === null)
221
+ return keyedFailure(answer.status, answer.body);
236
222
  const failure = classifyDoor(answer.status, answer.body, locator);
237
223
  if (failure === null)
238
224
  return null;
@@ -245,6 +231,48 @@ export function createAgentsHouseAdapter(options) {
245
231
  }
246
232
  : failure;
247
233
  }
234
+ function addressed(answer, locator) {
235
+ const failure = refusedOn(answer, locator);
236
+ if (failure !== null)
237
+ return failure;
238
+ const address = parseFileAddress(answer.body);
239
+ return address === null ? unusable() : { kind: 'address', ...address };
240
+ }
241
+ function linked(answer, locator) {
242
+ const address = addressed(answer, locator);
243
+ return address.kind === 'address'
244
+ ? { kind: 'link', url: address.url, name: address.name, mediaType: address.mediaType }
245
+ : address;
246
+ }
247
+ async function attached(request, into) {
248
+ const locator = into?.locator ?? null;
249
+ const declared = await transport.door(houseDoorRoute('files/attach'), {
250
+ ...(into === null ? {} : { room_ref: into.authority }),
251
+ name: request.name,
252
+ bytes: request.byteLength,
253
+ sha256: request.sha256,
254
+ media_type: request.mediaType,
255
+ });
256
+ const refused = refusedOn(declared, locator);
257
+ if (refused !== null)
258
+ return refused;
259
+ const upload = houseUpload(declared.body?.upload);
260
+ if (upload === null)
261
+ return unusable();
262
+ const finished = await finishedUpload(transport, upload, request.blob);
263
+ if ('unfinished' in finished)
264
+ return answeredFailure(finished.unfinished, null);
265
+ const unfinished = refusedOn(finished, locator);
266
+ if (unfinished !== null)
267
+ return unfinished;
268
+ const { path, revision, link } = (finished.body ?? {});
269
+ if (into === null)
270
+ return typeof link === 'string' ? { kind: 'linked', link } : unusable();
271
+ const root = `/rooms/${into.handle}/`;
272
+ return typeof path === 'string' && path.startsWith(root) && typeof revision === 'string'
273
+ ? { kind: 'attached', path: path.slice(root.length), revision }
274
+ : unusable();
275
+ }
248
276
  async function downloaded(ask, locator) {
249
277
  let address = addressed(await ask(), locator);
250
278
  if (address.kind !== 'address')
@@ -256,13 +284,17 @@ export function createAgentsHouseAdapter(options) {
256
284
  return address;
257
285
  read = await transport.download(address.url);
258
286
  }
259
- if (read.status !== 200 || read.body === null)
260
- return UNCERTAIN_READ;
287
+ if (read.status !== 200)
288
+ return answeredFailure(read.status, null);
289
+ if (read.body === null)
290
+ return unusable();
261
291
  return {
262
292
  kind: 'binary',
263
293
  body: read.body,
264
294
  mediaType: address.mediaType,
265
295
  sha256: address.sha256,
296
+ url: address.url,
297
+ copies: address.copies,
266
298
  };
267
299
  }
268
300
  function pathAddress(request) {
@@ -277,7 +309,6 @@ export function createAgentsHouseAdapter(options) {
277
309
  }
278
310
  return {
279
311
  roomTypes: HOUSE_ROOM_TYPES,
280
- nameableRoomTypes: HOUSE_NAMEABLE_ROOM_TYPES,
281
312
  typedPaths: HOUSE_TYPED_PATHS,
282
313
  pathRule: admittedPath,
283
314
  unkeptReads: HOUSE_UNKEPT_READS,
@@ -297,26 +328,17 @@ export function createAgentsHouseAdapter(options) {
297
328
  const entry = authorityFor(request.locator);
298
329
  if (entry === undefined)
299
330
  return { kind: 'room-not-readable', locator: request.locator };
300
- const batch = request.changeBatch;
301
- const destination = batch.between?.destination.room;
331
+ const destination = request.changeBatch.between?.destination.room;
302
332
  const into = destination === undefined ? undefined : authorityFor(destination);
303
333
  if (destination !== undefined && into === undefined) {
304
334
  return { kind: 'room-not-readable', locator: destination };
305
335
  }
306
- const mapped = into === undefined
307
- ? houseChanges(batch, entry.handle)
308
- : houseMove(batch, entry.handle, into.handle);
309
- if (mapped.kind === 'unmapped')
310
- return rejectedMapping(mapped);
311
- const head = operationHead(batch, entry.authority);
312
- const delta = deltaBody(mapped.changes);
313
- const bytes = deltaBytes(delta);
314
- const handed = request.upload;
315
- const answer = (upload) => submit(request, head, mapped.changes, delta, bytes, entry, upload, keep, into);
316
- const outcome = await answer(handed);
317
- if (handed === undefined || !lapsedGrant(outcome))
336
+ const outcome = await mutated(request, keep, entry, into);
337
+ const renamed = renamedHandle(outcome);
338
+ if (renamed === null)
318
339
  return outcome;
319
- return answer(undefined);
340
+ const moved = (held) => held.handle === renamed.from ? { ...held, handle: renamed.to } : held;
341
+ return mutated(request, keep, moved(entry), into === undefined ? undefined : moved(into));
320
342
  },
321
343
  async history(_authorization, request) {
322
344
  const entry = authorityFor(request.locator);
@@ -337,39 +359,21 @@ export function createAgentsHouseAdapter(options) {
337
359
  return downloaded(ask, request.locator);
338
360
  },
339
361
  async link(_authorization, request) {
362
+ if (request.kind === 'key') {
363
+ return linked(await transport.door(houseDoorRoute('files/read'), { link: request.link }), null);
364
+ }
340
365
  const ask = pathAddress(request);
341
366
  if (ask === null)
342
367
  return { kind: 'room-not-readable', locator: request.locator };
343
368
  return linked(await ask(), request.locator);
344
369
  },
345
370
  async attach(_authorization, request) {
371
+ if (request.locator === undefined)
372
+ return attached(request, null);
346
373
  const entry = authorityFor(request.locator);
347
374
  if (entry === undefined)
348
375
  return { kind: 'room-not-readable', locator: request.locator };
349
- const declared = await transport.door(houseDoorRoute('files/attach'), {
350
- room_ref: entry.authority,
351
- name: request.name,
352
- bytes: request.byteLength,
353
- sha256: request.sha256,
354
- media_type: request.mediaType.length > 0 ? request.mediaType : OCTET_STREAM,
355
- });
356
- const refused = refusedAttach(declared, request.locator);
357
- if (refused !== null)
358
- return refused;
359
- const upload = houseUpload(declared.body?.upload);
360
- if (upload === null)
361
- return UNCERTAIN_READ;
362
- const finished = await finishedUpload(transport, upload, request.blob);
363
- if (finished === null)
364
- return UNCERTAIN_READ;
365
- const unfinished = refusedAttach(finished, request.locator);
366
- if (unfinished !== null)
367
- return unfinished;
368
- const { path, revision } = (finished.body ?? {});
369
- const root = `/rooms/${entry.handle}/`;
370
- return typeof path === 'string' && path.startsWith(root) && typeof revision === 'string'
371
- ? { kind: 'attached', path: path.slice(root.length), revision }
372
- : UNCERTAIN_READ;
376
+ return attached(request, entry);
373
377
  },
374
378
  reached(locator, version, target) {
375
379
  return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
@@ -383,11 +387,15 @@ export function createAgentsHouseAdapter(options) {
383
387
  search(_authorization, request) {
384
388
  return houseSearch(transport, [...tracked.values()], request);
385
389
  },
390
+ queryHouse(_authorization, request) {
391
+ return houseQuery(transport, request);
392
+ },
386
393
  roomStream: {
387
394
  hold,
388
395
  observe: notifications.observe,
389
396
  },
390
397
  conversations: notifications.conversations,
398
+ runs: notifications.runs,
391
399
  serviceMode: notifications.serviceMode,
392
400
  };
393
401
  }
@@ -2,9 +2,60 @@ export declare const GENERATED_PROVENANCE = "_provenance";
2
2
  export declare const GENERATED_REVISIONS = "_revisions";
3
3
  export declare const RESERVED_DERIVED = "_derived";
4
4
  export declare const WHOLE_ESCAPED_NAMES: readonly string[];
5
- export declare const AUTHORED_SEGMENT_MAX_CHARS = 255;
6
- export declare const AUTHORED_SEGMENT: RegExp;
7
5
  export declare const LOCAL_COPY_MANIFEST = ".house";
8
6
  export declare const LOCAL_COPY_ROOT_NAMES: readonly string[];
9
- export declare const APP_PREFERENCES_HOME = "settings/apps";
7
+ export declare const AUTHORED_NAME_MAX_BYTES = 255;
8
+ export declare const AUTHORED_PATH_MAX_BYTES = 768;
9
+ export declare const AUTHORED_NAME_RULE: {
10
+ readonly refusedCharacters: '/\\:*?"<>|';
11
+ readonly controlCharacters: 'Cc';
12
+ readonly refusedEnds: ' .';
13
+ readonly refusedStart: '-';
14
+ readonly gitNames: readonly ['.git', 'git~1'];
15
+ readonly windowsNames: readonly ["CON", "PRN", "AUX", "NUL", ...string[]];
16
+ readonly generatedNames: readonly ["_provenance", "_revisions", "_derived"];
17
+ readonly nameMaxBytes: 255;
18
+ readonly pathMaxBytes: 768;
19
+ };
20
+ export type NameRefusal = {
21
+ readonly rule: 'unicode';
22
+ } | {
23
+ readonly rule: 'character';
24
+ readonly character: string;
25
+ } | {
26
+ readonly rule: 'empty';
27
+ } | {
28
+ readonly rule: 'dots';
29
+ } | {
30
+ readonly rule: 'end';
31
+ readonly character: string;
32
+ } | {
33
+ readonly rule: 'git';
34
+ } | {
35
+ readonly rule: 'windows';
36
+ readonly reserved: string;
37
+ } | {
38
+ readonly rule: 'name_bytes';
39
+ readonly bytes: number;
40
+ } | {
41
+ readonly rule: 'start';
42
+ } | {
43
+ readonly rule: 'generated';
44
+ } | {
45
+ readonly rule: 'nfc';
46
+ };
47
+ export type PathRefusal = (NameRefusal & {
48
+ readonly name: string;
49
+ }) | {
50
+ readonly rule: 'root';
51
+ readonly name: string;
52
+ } | {
53
+ readonly rule: 'path_bytes';
54
+ readonly bytes: number;
55
+ };
56
+ export declare function utf8Bytes(text: string): number;
57
+ export declare function nameRefusal(name: string): NameRefusal | null;
58
+ export declare function pathRefusal(path: string): PathRefusal | null;
10
59
  export declare function admittedPath(path: string): boolean;
60
+ export declare function sameName(left: string, right: string): boolean;
61
+ export declare function fittedName(name: string, count?: number, tail?: string): string;
@@ -1 +1 @@
1
- {"version":3,"file":"authored-path.d.ts","sourceRoot":"","sources":["../src/authored-path.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,gBAAgB,CAAC;AAElD,eAAO,MAAM,mBAAmB,eAAe,CAAC;AAEhD,eAAO,MAAM,gBAAgB,aAAa,CAAC;AAE3C,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAMhD,CAAC;AAEF,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAO9C,eAAO,MAAM,gBAAgB,QAE5B,CAAC;AAEF,eAAO,MAAM,mBAAmB,WAAW,CAAC;AAE5C,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAIlD,CAAC;AAEF,eAAO,MAAM,oBAAoB,kBAAkB,CAAC;AASpD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAQlD"}
1
+ {"version":3,"file":"authored-path.d.ts","sourceRoot":"","sources":["../src/authored-path.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBA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