@agentshouse/mdruntime-adapter 0.1.0-cb0e03e5f0ff6 → 0.1.0-cb1a2f809f691
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.
- package/README.md +2 -2
- package/dist/actions.d.ts +9 -1
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +129 -9
- package/dist/adapter.d.ts +0 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +131 -122
- package/dist/authored-path.d.ts +61 -0
- package/dist/authored-path.d.ts.map +1 -0
- package/dist/authored-path.js +166 -0
- package/dist/chunks.d.ts +2 -4
- package/dist/chunks.d.ts.map +1 -1
- package/dist/chunks.js +72 -38
- package/dist/digest.d.ts +0 -1
- package/dist/discovery.d.ts +26 -8
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +174 -26
- package/dist/history.d.ts +1 -7
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +21 -28
- package/dist/index.d.ts +8 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -8
- package/dist/map.d.ts +0 -1
- package/dist/model.d.ts +5 -6
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +18 -28
- package/dist/read.d.ts +11 -25
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +74 -47
- package/dist/refusal.d.ts +6 -2
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +28 -7
- package/dist/renamed.d.ts +10 -0
- package/dist/renamed.d.ts.map +1 -0
- package/dist/renamed.js +20 -0
- package/dist/room-query.d.ts +4 -0
- package/dist/room-query.d.ts.map +1 -0
- package/dist/room-query.js +63 -0
- package/dist/search.d.ts +0 -1
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +4 -4
- package/dist/session-content/check.d.ts +17 -0
- package/dist/session-content/index.d.ts +6 -0
- package/dist/session-content/parts.d.ts +30 -0
- package/dist/session-content/state.d.ts +59 -0
- package/dist/session-content/turn.d.ts +137 -0
- package/dist/site.d.ts +0 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +61 -23
- package/dist/space-schema.d.ts +0 -1
- package/dist/space-schema.d.ts.map +1 -1
- package/dist/space-schema.js +1 -8
- package/dist/stream.d.ts +2 -4
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +89 -86
- package/dist/transport.d.ts +60 -24
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +44 -8
- package/dist/uncertain.d.ts +5 -0
- package/dist/uncertain.d.ts.map +1 -0
- package/dist/uncertain.js +11 -0
- package/dist/upload.d.ts +7 -2
- package/dist/upload.d.ts.map +1 -1
- package/dist/upload.js +49 -6
- package/dist/version.d.ts +0 -1
- package/dist/write.d.ts +3 -10
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +90 -110
- package/package.json +4 -3
- package/dist/app-reference.d.ts +0 -2
- package/dist/app-reference.d.ts.map +0 -1
- package/dist/app-reference.js +0 -2
- package/dist/crockford.d.ts +0 -4
- package/dist/crockford.d.ts.map +0 -1
- package/dist/crockford.js +0 -3
- package/dist/house-model.d.ts +0 -672
- package/dist/house-model.d.ts.map +0 -1
- package/dist/house-model.js +0 -377
- package/dist/room-types.d.ts +0 -7
- package/dist/room-types.d.ts.map +0 -1
- package/dist/room-types.js +0 -123
package/README.md
CHANGED
|
@@ -20,12 +20,12 @@ import { createAgentsHouseAdapter } from '@agentshouse/mdruntime-adapter';
|
|
|
20
20
|
|
|
21
21
|
const adapter = createAgentsHouseAdapter({ transport, authorize });
|
|
22
22
|
const host = serveMdRuntime({ adapter, shell });
|
|
23
|
-
host.attach(port, 'my-app');
|
|
23
|
+
host.attach(port, { app: 'my-app' });
|
|
24
24
|
```
|
|
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
|
|
28
|
+
of House's Guide, which House's `guide` tool opens.
|
|
29
29
|
|
|
30
30
|
## License
|
|
31
31
|
|
package/dist/actions.d.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
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 HOUSE_UNKEPT_READS: readonly string[];
|
|
5
|
+
export declare const HOUSE_LEADING_READS: readonly string[];
|
|
6
|
+
export declare const HOUSE_RENAMED_UNTIL_2026_12_18: ReadonlyMap<string, string>;
|
|
7
|
+
type Rewrites = ReadonlyMap<string, (input: unknown) => unknown>;
|
|
8
|
+
export declare const HOUSE_REWRITTEN_UNTIL_2026_12_19: Rewrites;
|
|
9
|
+
export declare const HOUSE_RENAMED_UNTIL_2026_12_21: ReadonlyMap<string, string>;
|
|
10
|
+
export declare const HOUSE_REWRITTEN_UNTIL_2026_12_21: Rewrites;
|
|
11
|
+
export declare function rewrittenInTurn(...rewrites: readonly Rewrites[]): Rewrites;
|
|
4
12
|
export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
|
|
5
13
|
export declare function houseAction(transport: HouseActDoor, request: ActionRequest): Promise<ActionResult>;
|
|
6
14
|
export declare function actionOutcome(answer: HouseDoorAnswer, name: string, input: unknown): ActionResult;
|
|
7
|
-
|
|
15
|
+
export {};
|
package/dist/actions.d.ts.map
CHANGED
|
@@ -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;
|
|
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;AAI7F,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEtE,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;AAExD,eAAO,MAAM,kBAAkB,EAAE,SAAS,MAAM,EAI/C,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAMhD,CAAC;AAEF,eAAO,MAAM,8BAA8B,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAErE,CAAC;AAgCH,KAAK,QAAQ,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC;AAEjE,eAAO,MAAM,gCAAgC,EAAE,QAAgD,CAAC;AAEhG,eAAO,MAAM,8BAA8B,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAWrE,CAAC;AA4BH,eAAO,MAAM,gCAAgC,EAAE,QAY7C,CAAC;AAEH,wBAAgB,eAAe,CAAC,GAAG,QAAQ,EAAE,SAAS,QAAQ,EAAE,GAAG,QAAQ,CAQ1E;AAWD,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,iBAAiB,EAAE,CAOvF;AAED,wBAAgB,WAAW,CACzB,SAAS,EAAE,YAAY,EACvB,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,CAajG"}
|
package/dist/actions.js
CHANGED
|
@@ -1,6 +1,119 @@
|
|
|
1
|
-
import { doorRefusal } from './refusal.js';
|
|
1
|
+
import { answeredFailure, doorRefusal, resetOf } from './refusal.js';
|
|
2
|
+
import { movedPaths, renamedHandle } from './renamed.js';
|
|
3
|
+
import { refusedFor } from './uncertain.js';
|
|
4
|
+
export const HOUSE_UNKEPT_READS = [
|
|
5
|
+
'account/security/read',
|
|
6
|
+
'billing/read',
|
|
7
|
+
'clients/last-use/list',
|
|
8
|
+
];
|
|
9
|
+
export const HOUSE_LEADING_READS = [
|
|
10
|
+
'app.list',
|
|
11
|
+
'apps/list',
|
|
12
|
+
'sites/list',
|
|
13
|
+
'rooms/members/list',
|
|
14
|
+
'sharing.members',
|
|
15
|
+
];
|
|
16
|
+
export const HOUSE_RENAMED_UNTIL_2026_12_18 = new Map([
|
|
17
|
+
['files/batch', 'update'],
|
|
18
|
+
]);
|
|
19
|
+
function withoutRoomRef(input) {
|
|
20
|
+
if (typeof input !== 'object' || input === null || !('room_ref' in input))
|
|
21
|
+
return input;
|
|
22
|
+
const { room_ref: _room, ...paths } = input;
|
|
23
|
+
return paths;
|
|
24
|
+
}
|
|
25
|
+
const CURRENT_OPS = new Map([
|
|
26
|
+
['create', 'write'],
|
|
27
|
+
['replace', 'write'],
|
|
28
|
+
['patch', 'edit'],
|
|
29
|
+
['rename', 'move'],
|
|
30
|
+
['remove', 'delete'],
|
|
31
|
+
['create_folder', 'mkdir'],
|
|
32
|
+
['remove_folder', 'delete'],
|
|
33
|
+
]);
|
|
34
|
+
function withCurrentOps(input) {
|
|
35
|
+
if (typeof input !== 'object' || input === null || !('changes' in input))
|
|
36
|
+
return input;
|
|
37
|
+
const { changes } = input;
|
|
38
|
+
if (!Array.isArray(changes))
|
|
39
|
+
return input;
|
|
40
|
+
return {
|
|
41
|
+
...input,
|
|
42
|
+
changes: changes.map((change) => {
|
|
43
|
+
if (typeof change !== 'object' || change === null || !('op' in change))
|
|
44
|
+
return change;
|
|
45
|
+
const op = CURRENT_OPS.get(change.op);
|
|
46
|
+
return op === undefined ? change : { ...change, op };
|
|
47
|
+
}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export const HOUSE_REWRITTEN_UNTIL_2026_12_19 = new Map([['update', withoutRoomRef]]);
|
|
51
|
+
export const HOUSE_RENAMED_UNTIL_2026_12_21 = new Map([
|
|
52
|
+
['apps/create', 'app_update'],
|
|
53
|
+
['apps/upload', 'app_update'],
|
|
54
|
+
['shares/accept', 'sharing_update'],
|
|
55
|
+
['shares/decline', 'sharing_update'],
|
|
56
|
+
['shares/join-requests/approve', 'sharing_update'],
|
|
57
|
+
['shares/join-requests/decline', 'sharing_update'],
|
|
58
|
+
['rooms/ownership/offer', 'sharing_update'],
|
|
59
|
+
['rooms/ownership/accept', 'sharing_update'],
|
|
60
|
+
['rooms/ownership/decline', 'sharing_update'],
|
|
61
|
+
['rooms/instructions/follow', 'sharing_update'],
|
|
62
|
+
]);
|
|
63
|
+
function held(input) {
|
|
64
|
+
return typeof input === 'object' && input !== null
|
|
65
|
+
? { ...input }
|
|
66
|
+
: {};
|
|
67
|
+
}
|
|
68
|
+
function created(input) {
|
|
69
|
+
return { op: 'create', ...held(input) };
|
|
70
|
+
}
|
|
71
|
+
function uploaded(input) {
|
|
72
|
+
const { app_ref: app, ...files } = held(input);
|
|
73
|
+
return { op: 'publish', app, ...files };
|
|
74
|
+
}
|
|
75
|
+
function decided(op) {
|
|
76
|
+
return (input) => ({ op, ...held(input) });
|
|
77
|
+
}
|
|
78
|
+
function roomNamed(op) {
|
|
79
|
+
return (input) => {
|
|
80
|
+
const { room_ref: room, ...named } = held(input);
|
|
81
|
+
return { op, room, ...named };
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export const HOUSE_REWRITTEN_UNTIL_2026_12_21 = new Map([
|
|
85
|
+
['apps/create', created],
|
|
86
|
+
['apps/upload', uploaded],
|
|
87
|
+
['shares/accept', decided('share_accept')],
|
|
88
|
+
['shares/decline', decided('share_decline')],
|
|
89
|
+
['shares/join-requests/approve', decided('join_request_approve')],
|
|
90
|
+
['shares/join-requests/decline', decided('join_request_decline')],
|
|
91
|
+
['rooms/ownership/offer', roomNamed('ownership_offer')],
|
|
92
|
+
['rooms/ownership/accept', decided('ownership_accept')],
|
|
93
|
+
['rooms/ownership/decline', decided('ownership_decline')],
|
|
94
|
+
['rooms/instructions/follow', roomNamed('instructions_follow')],
|
|
95
|
+
['update', withCurrentOps],
|
|
96
|
+
]);
|
|
97
|
+
export function rewrittenInTurn(...rewrites) {
|
|
98
|
+
const names = new Set(rewrites.flatMap((each) => [...each.keys()]));
|
|
99
|
+
return new Map([...names].map((name) => [
|
|
100
|
+
name,
|
|
101
|
+
(input) => rewrites.reduce((held, each) => each.get(name)?.(held) ?? held, input),
|
|
102
|
+
]));
|
|
103
|
+
}
|
|
104
|
+
const ROOM_SELECTORS = new Map([
|
|
105
|
+
['update', { room: 'changes.room', roomPaths: ['changes.path', 'changes.to', 'paths', 'mount'] }],
|
|
106
|
+
['sharing', { room: 'room' }],
|
|
107
|
+
['sharing_update', { room: 'room' }],
|
|
108
|
+
['inbox_update', { room: 'room', roomPaths: ['path'] }],
|
|
109
|
+
]);
|
|
2
110
|
export function declaredActions(routes) {
|
|
3
|
-
return routes.map((name) => ({
|
|
111
|
+
return routes.map((name) => ({
|
|
112
|
+
name,
|
|
113
|
+
inputShape: {},
|
|
114
|
+
resultKind: 'house',
|
|
115
|
+
...(ROOM_SELECTORS.get(name) ?? { room: 'room_ref' }),
|
|
116
|
+
}));
|
|
4
117
|
}
|
|
5
118
|
export function houseAction(transport, request) {
|
|
6
119
|
const route = routeOf(request.name);
|
|
@@ -32,17 +145,24 @@ export function actionOutcome(answer, name, input) {
|
|
|
32
145
|
if (answer.status === 401)
|
|
33
146
|
return { kind: 'revoked-authorization' };
|
|
34
147
|
const refusal = doorRefusal(answer.body);
|
|
35
|
-
if (refusal?.code === 'operation_contended' && numbered(input))
|
|
36
|
-
return
|
|
148
|
+
if (refusal?.code === 'operation_contended' && numbered(input))
|
|
149
|
+
return refusedFor(refusal);
|
|
150
|
+
if (refusal !== null) {
|
|
151
|
+
const reset = resetOf(refusal);
|
|
152
|
+
return { kind: 'rejected', ...refusal, ...(reset === undefined ? {} : { reset }) };
|
|
37
153
|
}
|
|
38
|
-
if (refusal !== null)
|
|
39
|
-
return { kind: 'rejected', ...refusal };
|
|
40
154
|
if (answer.status === 404)
|
|
41
155
|
return unimplemented(name);
|
|
42
|
-
if (answer.status === 0 || answer.status >= 400)
|
|
43
|
-
return
|
|
156
|
+
if (answer.status === 0 || answer.status >= 400) {
|
|
157
|
+
return answeredFailure(answer.status, answer.body);
|
|
158
|
+
}
|
|
44
159
|
return { kind: 'action', result: answer.body };
|
|
45
160
|
}
|
|
46
161
|
async function carry(transport, route, name, input) {
|
|
47
|
-
|
|
162
|
+
const answered = actionOutcome(await transport.door(route, input), name, input);
|
|
163
|
+
const renamed = renamedHandle(answered);
|
|
164
|
+
if (renamed === null)
|
|
165
|
+
return answered;
|
|
166
|
+
const moved = movedPaths(input, ROOM_SELECTORS.get(name)?.roomPaths ?? [], renamed);
|
|
167
|
+
return actionOutcome(await transport.door(route, moved), name, moved);
|
|
48
168
|
}
|
package/dist/adapter.d.ts
CHANGED
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"
|
|
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;AAmChC,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,CA8cpF"}
|
package/dist/adapter.js
CHANGED
|
@@ -1,22 +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 {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { finishedUpload, houseUpload, stagedBatch } from './upload.js';
|
|
8
|
+
import { houseAction, HOUSE_LEADING_READS, HOUSE_RENAMED_UNTIL_2026_12_18, HOUSE_RENAMED_UNTIL_2026_12_21, HOUSE_REWRITTEN_UNTIL_2026_12_19, HOUSE_REWRITTEN_UNTIL_2026_12_21, HOUSE_UNKEPT_READS, rewrittenInTurn, } from './actions.js';
|
|
9
|
+
import { houseQuery } from './room-query.js';
|
|
9
10
|
import { houseSearch } from './search.js';
|
|
10
|
-
import { classifyDoor,
|
|
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
|
-
import {
|
|
15
|
-
import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
|
|
17
|
+
import { admittedPath } from './authored-path.js';
|
|
16
18
|
import { followsVersion, reachedVersion, roomVersion } from './version.js';
|
|
17
|
-
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
18
|
-
const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
|
|
19
|
-
const OCTET_STREAM = 'application/octet-stream';
|
|
20
19
|
const EXPIRED_ADDRESS = 403;
|
|
21
20
|
function lapsedGrant(outcome) {
|
|
22
21
|
return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
|
|
@@ -25,14 +24,13 @@ export function createAgentsHouseAdapter(options) {
|
|
|
25
24
|
if ('site' in options)
|
|
26
25
|
return createSiteAdapter(options.site, options.snapshot === true);
|
|
27
26
|
const transport = options.transport;
|
|
28
|
-
const spaces = spaceSchemas();
|
|
29
27
|
const notifications = houseNotifications(transport, 'credential', {
|
|
30
28
|
opened: async (frame) => (frame === null ? null : opened(frame)),
|
|
31
29
|
changed,
|
|
32
|
-
expired: (
|
|
33
|
-
}
|
|
30
|
+
expired: (entries) => lister.askAll(entries),
|
|
31
|
+
});
|
|
34
32
|
const tracked = new Map();
|
|
35
|
-
const lister = chunkLister(transport, () => declared().max_prefixes);
|
|
33
|
+
const lister = chunkLister(transport, () => declared().max_prefixes, (locator) => tracked.get(locator));
|
|
36
34
|
const chunked = new Map();
|
|
37
35
|
const renewals = new WeakMap();
|
|
38
36
|
let bounds;
|
|
@@ -54,13 +52,16 @@ export function createAgentsHouseAdapter(options) {
|
|
|
54
52
|
return {
|
|
55
53
|
...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions)),
|
|
56
54
|
member: document.member,
|
|
55
|
+
timeZone: document.timeZone,
|
|
56
|
+
roomList: document.roomList,
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
function changed(frame) {
|
|
60
60
|
const change = parseAuthorityChange(frame);
|
|
61
61
|
if (change === null)
|
|
62
62
|
return null;
|
|
63
|
-
|
|
63
|
+
const unheld = [...change.left, ...change.listed];
|
|
64
|
+
for (const locator of unheld)
|
|
64
65
|
tracked.delete(locator);
|
|
65
66
|
for (const entry of trackedFrom(change))
|
|
66
67
|
tracked.set(entry.locator, entry);
|
|
@@ -68,15 +69,17 @@ export function createAgentsHouseAdapter(options) {
|
|
|
68
69
|
return {
|
|
69
70
|
kind: 'authority-changed',
|
|
70
71
|
rooms: change.authorities.map((authority) => discoveredRoom(authority)),
|
|
71
|
-
left:
|
|
72
|
+
left: unheld,
|
|
72
73
|
member: change.member,
|
|
74
|
+
timeZone: change.timeZone,
|
|
75
|
+
roomList: { ...change.roomList, left: change.left },
|
|
73
76
|
};
|
|
74
77
|
}
|
|
75
78
|
async function listedRoom(entry) {
|
|
76
79
|
const listed = await lister.list(entry);
|
|
77
80
|
if ('kind' in listed)
|
|
78
81
|
return listed;
|
|
79
|
-
const head = await chunkedHead(listed, entry
|
|
82
|
+
const head = await chunkedHead(listed, entry);
|
|
80
83
|
if (head.kind === 'bootstrap')
|
|
81
84
|
chunked.set(entry.locator, listed);
|
|
82
85
|
return head;
|
|
@@ -85,15 +88,18 @@ export function createAgentsHouseAdapter(options) {
|
|
|
85
88
|
const room = chunked.get(entry.locator);
|
|
86
89
|
const address = room?.chunks.get(id);
|
|
87
90
|
if (room === undefined || address === undefined)
|
|
88
|
-
return
|
|
91
|
+
return UNANSWERED;
|
|
89
92
|
const read = await transport.download(address.url);
|
|
90
93
|
if (read.status !== EXPIRED_ADDRESS)
|
|
91
94
|
return { room, read };
|
|
92
95
|
const renewed = await renewal(entry, room);
|
|
93
|
-
if ('kind' in renewed
|
|
94
|
-
return
|
|
96
|
+
if ('kind' in renewed)
|
|
97
|
+
return renewed;
|
|
98
|
+
const renewedAddress = renewed.chunks.get(id);
|
|
99
|
+
if (renewedAddress === undefined)
|
|
100
|
+
return unusable();
|
|
95
101
|
chunked.set(entry.locator, renewed);
|
|
96
|
-
return { room: renewed, read: await transport.download(
|
|
102
|
+
return { room: renewed, read: await transport.download(renewedAddress.url) };
|
|
97
103
|
}
|
|
98
104
|
function renewal(entry, stale) {
|
|
99
105
|
const held = renewals.get(stale);
|
|
@@ -115,8 +121,10 @@ export function createAgentsHouseAdapter(options) {
|
|
|
115
121
|
}
|
|
116
122
|
async function chunkPage(entry, id, arriving) {
|
|
117
123
|
const fetched = await chunkRead(entry, id);
|
|
118
|
-
if (
|
|
119
|
-
return
|
|
124
|
+
if ('kind' in fetched)
|
|
125
|
+
return fetched;
|
|
126
|
+
if (fetched.read.status !== 200)
|
|
127
|
+
return answeredFailure(fetched.read.status, null);
|
|
120
128
|
return chunkPart(fetched.read.body, fetched.room, id, arriving);
|
|
121
129
|
}
|
|
122
130
|
function authorityFor(locator) {
|
|
@@ -142,8 +150,9 @@ export function createAgentsHouseAdapter(options) {
|
|
|
142
150
|
if (handed !== undefined && handed.sha256 === sha256) {
|
|
143
151
|
return { body: { ...head, paths, upload: handed, runtime: notifications.runtime } };
|
|
144
152
|
}
|
|
145
|
-
const minted = await transport.door(houseDoorRoute('
|
|
153
|
+
const minted = await transport.door(houseDoorRoute('update'), {
|
|
146
154
|
...head,
|
|
155
|
+
op: 'stage',
|
|
147
156
|
paths,
|
|
148
157
|
bytes,
|
|
149
158
|
sha256,
|
|
@@ -155,39 +164,21 @@ export function createAgentsHouseAdapter(options) {
|
|
|
155
164
|
}
|
|
156
165
|
const grant = parseGrant(minted.body);
|
|
157
166
|
if (grant === null)
|
|
158
|
-
return { outcome:
|
|
167
|
+
return { outcome: unusable() };
|
|
159
168
|
const delivered = await transport.transfer({
|
|
160
|
-
act: 'authored_batch_upload',
|
|
161
169
|
url: grant.url,
|
|
162
170
|
body: `${grant.operation}\n${delta}`,
|
|
163
171
|
});
|
|
164
|
-
if (delivered.status !== 200)
|
|
165
|
-
return { outcome:
|
|
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:
|
|
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
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
|
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
|
|
260
|
-
return
|
|
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,8 +309,12 @@ 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,
|
|
313
|
+
pathRule: admittedPath,
|
|
314
|
+
unkeptReads: HOUSE_UNKEPT_READS,
|
|
315
|
+
leadingReads: HOUSE_LEADING_READS,
|
|
316
|
+
renamedActions: new Map([...HOUSE_RENAMED_UNTIL_2026_12_18, ...HOUSE_RENAMED_UNTIL_2026_12_21]),
|
|
317
|
+
rewrittenInputs: rewrittenInTurn(HOUSE_REWRITTEN_UNTIL_2026_12_19, HOUSE_REWRITTEN_UNTIL_2026_12_21),
|
|
282
318
|
async authorize() {
|
|
283
319
|
return options.authorize();
|
|
284
320
|
},
|
|
@@ -294,26 +330,17 @@ export function createAgentsHouseAdapter(options) {
|
|
|
294
330
|
const entry = authorityFor(request.locator);
|
|
295
331
|
if (entry === undefined)
|
|
296
332
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
297
|
-
const
|
|
298
|
-
const destination = batch.between?.destination.room;
|
|
333
|
+
const destination = request.changeBatch.between?.destination.room;
|
|
299
334
|
const into = destination === undefined ? undefined : authorityFor(destination);
|
|
300
335
|
if (destination !== undefined && into === undefined) {
|
|
301
336
|
return { kind: 'room-not-readable', locator: destination };
|
|
302
337
|
}
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
if (mapped.kind === 'unmapped')
|
|
307
|
-
return rejectedMapping(mapped);
|
|
308
|
-
const head = operationHead(batch, entry.authority);
|
|
309
|
-
const delta = deltaBody(mapped.changes);
|
|
310
|
-
const bytes = deltaBytes(delta);
|
|
311
|
-
const handed = request.upload;
|
|
312
|
-
const answer = (upload) => submit(request, head, mapped.changes, delta, bytes, entry, upload, keep, into);
|
|
313
|
-
const outcome = await answer(handed);
|
|
314
|
-
if (handed === undefined || !lapsedGrant(outcome))
|
|
338
|
+
const outcome = await mutated(request, keep, entry, into);
|
|
339
|
+
const renamed = renamedHandle(outcome);
|
|
340
|
+
if (renamed === null)
|
|
315
341
|
return outcome;
|
|
316
|
-
|
|
342
|
+
const moved = (held) => held.handle === renamed.from ? { ...held, handle: renamed.to } : held;
|
|
343
|
+
return mutated(request, keep, moved(entry), into === undefined ? undefined : moved(into));
|
|
317
344
|
},
|
|
318
345
|
async history(_authorization, request) {
|
|
319
346
|
const entry = authorityFor(request.locator);
|
|
@@ -325,10 +352,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
325
352
|
...(request.revision === undefined ? {} : { revision: request.revision }),
|
|
326
353
|
...(request.pageToken === undefined ? {} : { pageToken: request.pageToken }),
|
|
327
354
|
}));
|
|
328
|
-
return historyOutcome(answer.status, answer.body, entry.locator,
|
|
329
|
-
path: request.path,
|
|
330
|
-
...(request.revision === undefined ? {} : { revision: request.revision }),
|
|
331
|
-
});
|
|
355
|
+
return historyOutcome(answer.status, answer.body, entry.locator, request);
|
|
332
356
|
},
|
|
333
357
|
async binary(_authorization, request) {
|
|
334
358
|
const ask = pathAddress(request);
|
|
@@ -337,39 +361,21 @@ export function createAgentsHouseAdapter(options) {
|
|
|
337
361
|
return downloaded(ask, request.locator);
|
|
338
362
|
},
|
|
339
363
|
async link(_authorization, request) {
|
|
364
|
+
if (request.kind === 'key') {
|
|
365
|
+
return linked(await transport.door(houseDoorRoute('files/read'), { link: request.link }), null);
|
|
366
|
+
}
|
|
340
367
|
const ask = pathAddress(request);
|
|
341
368
|
if (ask === null)
|
|
342
369
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
343
370
|
return linked(await ask(), request.locator);
|
|
344
371
|
},
|
|
345
372
|
async attach(_authorization, request) {
|
|
373
|
+
if (request.locator === undefined)
|
|
374
|
+
return attached(request, null);
|
|
346
375
|
const entry = authorityFor(request.locator);
|
|
347
376
|
if (entry === undefined)
|
|
348
377
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
349
|
-
|
|
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;
|
|
378
|
+
return attached(request, entry);
|
|
373
379
|
},
|
|
374
380
|
reached(locator, version, target) {
|
|
375
381
|
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
|
@@ -383,6 +389,9 @@ export function createAgentsHouseAdapter(options) {
|
|
|
383
389
|
search(_authorization, request) {
|
|
384
390
|
return houseSearch(transport, [...tracked.values()], request);
|
|
385
391
|
},
|
|
392
|
+
queryHouse(_authorization, request) {
|
|
393
|
+
return houseQuery(transport, request);
|
|
394
|
+
},
|
|
386
395
|
roomStream: {
|
|
387
396
|
hold,
|
|
388
397
|
observe: notifications.observe,
|