@agentshouse/mdruntime-adapter 0.1.0-c5eff18c1e13b → 0.1.0-c6025c99835d4
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 +3 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +26 -9
- package/dist/adapter.d.ts +0 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +169 -178
- package/dist/authored-path.d.ts +9 -0
- package/dist/authored-path.d.ts.map +1 -0
- package/dist/authored-path.js +34 -0
- package/dist/chunks.d.ts +36 -0
- package/dist/chunks.d.ts.map +1 -0
- package/dist/chunks.js +281 -0
- package/dist/digest.d.ts +0 -1
- package/dist/discovery.d.ts +25 -7
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +168 -16
- package/dist/history.d.ts +1 -7
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +24 -30
- package/dist/index.d.ts +5 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/map.d.ts +0 -1
- package/dist/model.d.ts +6 -9
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +28 -26
- package/dist/read.d.ts +15 -24
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +66 -189
- package/dist/refusal.d.ts +6 -2
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +28 -7
- package/dist/search.d.ts +4 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +47 -0
- package/dist/session-content/bounds.d.ts +7 -0
- package/dist/session-content/check.d.ts +18 -0
- package/dist/session-content/index.d.ts +7 -0
- package/dist/session-content/parts.d.ts +103 -0
- package/dist/session-content/state.d.ts +61 -0
- package/dist/session-content/turn.d.ts +328 -0
- package/dist/site.d.ts +0 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +46 -50
- package/dist/space-schema.d.ts +6 -0
- package/dist/space-schema.d.ts.map +1 -0
- package/dist/space-schema.js +11 -0
- package/dist/stream.d.ts +4 -4
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +148 -74
- package/dist/transport.d.ts +50 -27
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +16 -13
- 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 +3 -2
- package/dist/upload.d.ts.map +1 -1
- package/dist/upload.js +8 -6
- package/dist/version.d.ts +0 -1
- package/dist/write.d.ts +0 -2
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +22 -29
- package/package.json +3 -2
- 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 -955
- package/dist/house-model.d.ts.map +0 -1
- package/dist/house-model.js +0 -521
- package/dist/part.d.ts +0 -14
- package/dist/part.d.ts.map +0 -1
- package/dist/part.js +0 -90
- package/dist/room-stream.d.ts +0 -19
- package/dist/room-stream.d.ts.map +0 -1
- package/dist/room-stream.js +0 -57
- package/dist/room-types.d.ts +0 -7
- package/dist/room-types.d.ts.map +0 -1
- package/dist/room-types.js +0 -125
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 `
|
|
28
|
+
of House's Guide, which House's `guide/open` opens.
|
|
29
29
|
|
|
30
30
|
## License
|
|
31
31
|
|
package/dist/actions.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
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[];
|
|
4
6
|
export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
|
|
5
7
|
export declare function houseAction(transport: HouseActDoor, request: ActionRequest): Promise<ActionResult>;
|
|
6
|
-
export declare function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult;
|
|
7
|
-
//# sourceMappingURL=actions.d.ts.map
|
|
8
|
+
export declare function actionOutcome(answer: HouseDoorAnswer, name: string, input: unknown): ActionResult;
|
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;AAG7F,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,EAIhD,CAAC;AAEF,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,iBAAiB,EAAE,CAEvF;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,4 +1,15 @@
|
|
|
1
|
-
import { doorRefusal } from './refusal.js';
|
|
1
|
+
import { answeredFailure, doorRefusal, resetOf } from './refusal.js';
|
|
2
|
+
import { refusedFor } from './uncertain.js';
|
|
3
|
+
export const HOUSE_UNKEPT_READS = [
|
|
4
|
+
'account/security/read',
|
|
5
|
+
'billing/read',
|
|
6
|
+
'clients/last-use/list',
|
|
7
|
+
];
|
|
8
|
+
export const HOUSE_LEADING_READS = [
|
|
9
|
+
'apps/list',
|
|
10
|
+
'sites/list',
|
|
11
|
+
'rooms/members/list',
|
|
12
|
+
];
|
|
2
13
|
export function declaredActions(routes) {
|
|
3
14
|
return routes.map((name) => ({ name, inputShape: {}, resultKind: 'house', room: 'room_ref' }));
|
|
4
15
|
}
|
|
@@ -25,20 +36,26 @@ function malformed() {
|
|
|
25
36
|
function unimplemented(name) {
|
|
26
37
|
return { kind: 'rejected', code: 'action-unimplemented', fields: { name }, retryable: false };
|
|
27
38
|
}
|
|
28
|
-
|
|
39
|
+
function numbered(input) {
|
|
40
|
+
return typeof input?.operation_id === 'string';
|
|
41
|
+
}
|
|
42
|
+
export function actionOutcome(answer, name, input) {
|
|
29
43
|
if (answer.status === 401)
|
|
30
44
|
return { kind: 'revoked-authorization' };
|
|
31
45
|
const refusal = doorRefusal(answer.body);
|
|
32
|
-
if (refusal?.code === 'operation_contended')
|
|
33
|
-
return
|
|
34
|
-
if (refusal !== null)
|
|
35
|
-
|
|
46
|
+
if (refusal?.code === 'operation_contended' && numbered(input))
|
|
47
|
+
return refusedFor(refusal);
|
|
48
|
+
if (refusal !== null) {
|
|
49
|
+
const reset = resetOf(refusal);
|
|
50
|
+
return { kind: 'rejected', ...refusal, ...(reset === undefined ? {} : { reset }) };
|
|
51
|
+
}
|
|
36
52
|
if (answer.status === 404)
|
|
37
53
|
return unimplemented(name);
|
|
38
|
-
if (answer.status === 0 || answer.status >= 400)
|
|
39
|
-
return
|
|
54
|
+
if (answer.status === 0 || answer.status >= 400) {
|
|
55
|
+
return answeredFailure(answer.status, answer.body);
|
|
56
|
+
}
|
|
40
57
|
return { kind: 'action', result: answer.body };
|
|
41
58
|
}
|
|
42
59
|
async function carry(transport, route, name, input) {
|
|
43
|
-
return actionOutcome(await transport.door(route, input), name);
|
|
60
|
+
return actionOutcome(await transport.door(route, input), name, input);
|
|
44
61
|
}
|
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;AAyBhC,OAAO,EAIL,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;AAmBrD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA0cpF"}
|
package/dist/adapter.js
CHANGED
|
@@ -1,49 +1,26 @@
|
|
|
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
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { sha256Hex } from './digest.js';
|
|
5
|
+
import { parseFileAddress, parseGrant } from './read.js';
|
|
6
|
+
import { chunkedHead, chunkLister, chunkPart } from './chunks.js';
|
|
7
7
|
import { finishedUpload, houseUpload } from './upload.js';
|
|
8
|
-
import { houseAction } from './actions.js';
|
|
9
|
-
import {
|
|
8
|
+
import { houseAction, HOUSE_LEADING_READS, HOUSE_UNKEPT_READS } from './actions.js';
|
|
9
|
+
import { houseSearch } from './search.js';
|
|
10
|
+
import { answeredFailure, classifyDoor, doorRefusal, keyedFailure } from './refusal.js';
|
|
11
|
+
import { UNANSWERED, unusable } from './uncertain.js';
|
|
10
12
|
import { houseNotifications, } from './stream.js';
|
|
11
13
|
import { houseDoorRoute, } from './transport.js';
|
|
12
14
|
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, houseMove, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
|
|
13
|
-
import {
|
|
14
|
-
import { followsVersion,
|
|
15
|
-
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
16
|
-
const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
|
|
17
|
-
const OCTET_STREAM = 'application/octet-stream';
|
|
15
|
+
import { admittedPath } from './authored-path.js';
|
|
16
|
+
import { followsVersion, reachedVersion, roomVersion } from './version.js';
|
|
18
17
|
const EXPIRED_ADDRESS = 403;
|
|
19
18
|
function lapsedGrant(outcome) {
|
|
20
19
|
return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
|
|
21
20
|
}
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
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 && file.outline === 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 };
|
|
21
|
+
function unstagedRefusal(answer) {
|
|
22
|
+
const refusal = doorRefusal(answer.body);
|
|
23
|
+
return refusal?.code === 'files_unstaged' ? refusal : null;
|
|
47
24
|
}
|
|
48
25
|
export function createAgentsHouseAdapter(options) {
|
|
49
26
|
if ('site' in options)
|
|
@@ -52,10 +29,12 @@ export function createAgentsHouseAdapter(options) {
|
|
|
52
29
|
const notifications = houseNotifications(transport, 'credential', {
|
|
53
30
|
opened: async (frame) => (frame === null ? null : opened(frame)),
|
|
54
31
|
changed,
|
|
32
|
+
expired: (entries) => lister.askAll(entries),
|
|
55
33
|
});
|
|
56
34
|
const tracked = new Map();
|
|
57
|
-
const
|
|
58
|
-
const
|
|
35
|
+
const lister = chunkLister(transport, () => declared().max_prefixes, (locator) => tracked.get(locator));
|
|
36
|
+
const chunked = new Map();
|
|
37
|
+
const renewals = new WeakMap();
|
|
59
38
|
let bounds;
|
|
60
39
|
function declared() {
|
|
61
40
|
if (bounds === undefined)
|
|
@@ -68,19 +47,23 @@ 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()]);
|
|
74
54
|
return {
|
|
75
55
|
...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions)),
|
|
76
56
|
member: document.member,
|
|
57
|
+
timeZone: document.timeZone,
|
|
58
|
+
roomList: document.roomList,
|
|
77
59
|
};
|
|
78
60
|
}
|
|
79
61
|
function changed(frame) {
|
|
80
62
|
const change = parseAuthorityChange(frame);
|
|
81
63
|
if (change === null)
|
|
82
64
|
return null;
|
|
83
|
-
|
|
65
|
+
const unheld = [...change.left, ...change.listed];
|
|
66
|
+
for (const locator of unheld)
|
|
84
67
|
tracked.delete(locator);
|
|
85
68
|
for (const entry of trackedFrom(change))
|
|
86
69
|
tracked.set(entry.locator, entry);
|
|
@@ -88,69 +71,63 @@ export function createAgentsHouseAdapter(options) {
|
|
|
88
71
|
return {
|
|
89
72
|
kind: 'authority-changed',
|
|
90
73
|
rooms: change.authorities.map((authority) => discoveredRoom(authority)),
|
|
91
|
-
left:
|
|
74
|
+
left: unheld,
|
|
92
75
|
member: change.member,
|
|
76
|
+
timeZone: change.timeZone,
|
|
77
|
+
roomList: { ...change.roomList, left: change.left },
|
|
93
78
|
};
|
|
94
79
|
}
|
|
95
|
-
async function
|
|
96
|
-
const
|
|
97
|
-
if ('kind' in
|
|
98
|
-
return
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
};
|
|
80
|
+
async function listedRoom(entry) {
|
|
81
|
+
const listed = await lister.list(entry);
|
|
82
|
+
if ('kind' in listed)
|
|
83
|
+
return listed;
|
|
84
|
+
const head = await chunkedHead(listed, entry);
|
|
85
|
+
if (head.kind === 'bootstrap')
|
|
86
|
+
chunked.set(entry.locator, listed);
|
|
87
|
+
return head;
|
|
110
88
|
}
|
|
111
|
-
async function
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
last = part.scope;
|
|
128
|
-
token = part.pageToken;
|
|
129
|
-
}
|
|
130
|
-
if (last === null)
|
|
131
|
-
return UNCERTAIN_READ;
|
|
132
|
-
return stepped(bootstrapping({ ...last, files, contents }));
|
|
89
|
+
async function chunkRead(entry, id) {
|
|
90
|
+
const room = chunked.get(entry.locator);
|
|
91
|
+
const address = room?.chunks.get(id);
|
|
92
|
+
if (room === undefined || address === undefined)
|
|
93
|
+
return UNANSWERED;
|
|
94
|
+
const read = await transport.download(address.url);
|
|
95
|
+
if (read.status !== EXPIRED_ADDRESS)
|
|
96
|
+
return { room, read };
|
|
97
|
+
const renewed = await renewal(entry, room);
|
|
98
|
+
if ('kind' in renewed)
|
|
99
|
+
return renewed;
|
|
100
|
+
const renewedAddress = renewed.chunks.get(id);
|
|
101
|
+
if (renewedAddress === undefined)
|
|
102
|
+
return unusable();
|
|
103
|
+
chunked.set(entry.locator, renewed);
|
|
104
|
+
return { room: renewed, read: await transport.download(renewedAddress.url) };
|
|
133
105
|
}
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
106
|
+
function renewal(entry, stale) {
|
|
107
|
+
const held = renewals.get(stale);
|
|
108
|
+
if (held !== undefined)
|
|
109
|
+
return held;
|
|
110
|
+
const renewed = lister.renew(entry, [...chunked.keys()].flatMap((locator) => tracked.get(locator) ?? []));
|
|
111
|
+
renewals.set(stale, renewed);
|
|
112
|
+
return renewed;
|
|
113
|
+
}
|
|
114
|
+
function hold(rooms) {
|
|
115
|
+
for (const room of rooms) {
|
|
116
|
+
const listed = chunked.get(room.locator);
|
|
117
|
+
if (listed !== undefined &&
|
|
118
|
+
room.roomVersion !== null &&
|
|
119
|
+
reachedVersion(room.roomVersion, roomVersion(listed), listed.logEpoch))
|
|
120
|
+
chunked.delete(room.locator);
|
|
121
|
+
}
|
|
122
|
+
notifications.send(rooms);
|
|
147
123
|
}
|
|
148
|
-
function
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
124
|
+
async function chunkPage(entry, id, arriving) {
|
|
125
|
+
const fetched = await chunkRead(entry, id);
|
|
126
|
+
if ('kind' in fetched)
|
|
127
|
+
return fetched;
|
|
128
|
+
if (fetched.read.status !== 200)
|
|
129
|
+
return answeredFailure(fetched.read.status, null);
|
|
130
|
+
return chunkPart(fetched.read.body, fetched.room, id, arriving);
|
|
154
131
|
}
|
|
155
132
|
function authorityFor(locator) {
|
|
156
133
|
return tracked.get(locator);
|
|
@@ -175,7 +152,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
175
152
|
if (handed !== undefined && handed.sha256 === sha256) {
|
|
176
153
|
return { body: { ...head, paths, upload: handed, runtime: notifications.runtime } };
|
|
177
154
|
}
|
|
178
|
-
const minted = await transport.door(houseDoorRoute('batch-upload'), {
|
|
155
|
+
const minted = await transport.door(houseDoorRoute('files/batch-upload'), {
|
|
179
156
|
...head,
|
|
180
157
|
paths,
|
|
181
158
|
bytes,
|
|
@@ -188,38 +165,38 @@ export function createAgentsHouseAdapter(options) {
|
|
|
188
165
|
}
|
|
189
166
|
const grant = parseGrant(minted.body);
|
|
190
167
|
if (grant === null)
|
|
191
|
-
return { outcome:
|
|
168
|
+
return { outcome: unusable() };
|
|
192
169
|
const delivered = await transport.transfer({
|
|
193
|
-
act: 'authored_batch_upload',
|
|
194
170
|
url: grant.url,
|
|
195
171
|
body: `${grant.operation}\n${delta}`,
|
|
196
172
|
});
|
|
197
|
-
if (delivered.status !== 200)
|
|
198
|
-
return { outcome:
|
|
173
|
+
if (delivered.status !== 200) {
|
|
174
|
+
return { outcome: answeredFailure(delivered.status, delivered.body) };
|
|
175
|
+
}
|
|
199
176
|
const holding = parseGrant(delivered.body);
|
|
200
177
|
if (holding === null)
|
|
201
|
-
return { outcome:
|
|
178
|
+
return { outcome: unusable() };
|
|
202
179
|
const upload = { url: holding.url, operation: holding.operation, bytes, sha256 };
|
|
203
180
|
await keep(upload);
|
|
204
181
|
return { body: { ...head, paths, upload, runtime: notifications.runtime } };
|
|
205
182
|
}
|
|
206
|
-
async function staged(
|
|
207
|
-
const refusal = doorRefusal(answer.body);
|
|
208
|
-
if (refusal?.code !== 'files_unstaged')
|
|
209
|
-
return null;
|
|
210
|
-
const uploads = refusal.fields.upload;
|
|
183
|
+
async function staged(uploads, { changeBatch: batch, file }) {
|
|
211
184
|
if (!Array.isArray(uploads))
|
|
212
|
-
return
|
|
185
|
+
return unusable();
|
|
213
186
|
for (const named of uploads) {
|
|
214
187
|
const upload = houseUpload(named);
|
|
215
188
|
const change = batch.changes.find((held) => held.kind === 'binary' && held.sha256 === named.sha256);
|
|
216
189
|
if (upload === null || change === undefined)
|
|
217
|
-
return
|
|
190
|
+
return unusable();
|
|
218
191
|
const finished = await finishedUpload(transport, upload, await file(change.localId));
|
|
219
|
-
if (
|
|
220
|
-
return
|
|
192
|
+
if ('unfinished' in finished)
|
|
193
|
+
return answeredFailure(finished.unfinished, null);
|
|
194
|
+
if (finished.status !== 200)
|
|
195
|
+
return answeredFailure(finished.status, finished.body);
|
|
196
|
+
if (finished.body?.staged !== true)
|
|
197
|
+
return unusable();
|
|
221
198
|
}
|
|
222
|
-
return
|
|
199
|
+
return null;
|
|
223
200
|
}
|
|
224
201
|
async function submit(request, head, changes, delta, bytes, entry, handed, keep, into) {
|
|
225
202
|
const inline = { ...head, changes, runtime: notifications.runtime };
|
|
@@ -228,13 +205,19 @@ export function createAgentsHouseAdapter(options) {
|
|
|
228
205
|
: { body: inline };
|
|
229
206
|
if ('outcome' in prepared)
|
|
230
207
|
return prepared.outcome;
|
|
231
|
-
const answer = await transport.door(houseDoorRoute('batch'), prepared.body);
|
|
232
|
-
const
|
|
233
|
-
if (
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
208
|
+
const answer = await transport.door(houseDoorRoute('files/batch'), prepared.body);
|
|
209
|
+
const unstaged = unstagedRefusal(answer);
|
|
210
|
+
if (unstaged !== null) {
|
|
211
|
+
const staging = await staged(unstaged.fields.upload, request);
|
|
212
|
+
if (staging !== null)
|
|
213
|
+
return staging;
|
|
214
|
+
}
|
|
215
|
+
const settled = unstaged === null
|
|
216
|
+
? answer
|
|
217
|
+
: await transport.door(houseDoorRoute('files/batch'), prepared.body);
|
|
218
|
+
if (unstaged !== null && unstagedRefusal(settled) !== null) {
|
|
219
|
+
return answeredFailure(settled.status, settled.body);
|
|
220
|
+
}
|
|
238
221
|
return stepped(mutationOutcome(settled.status, settled.body, entry.locator, entry.handle, into === undefined
|
|
239
222
|
? undefined
|
|
240
223
|
: {
|
|
@@ -242,28 +225,9 @@ export function createAgentsHouseAdapter(options) {
|
|
|
242
225
|
destination: { authority: into.authority, handle: into.handle },
|
|
243
226
|
}));
|
|
244
227
|
}
|
|
245
|
-
function
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
return failure.kind === 'scoped-refusal'
|
|
249
|
-
? {
|
|
250
|
-
kind: 'rejected',
|
|
251
|
-
code: failure.code,
|
|
252
|
-
fields: failure.fields,
|
|
253
|
-
retryable: failure.retryable,
|
|
254
|
-
}
|
|
255
|
-
: failure;
|
|
256
|
-
}
|
|
257
|
-
const address = parseFileAddress(answer.body);
|
|
258
|
-
return address === null ? UNCERTAIN_READ : { kind: 'address', ...address };
|
|
259
|
-
}
|
|
260
|
-
function linked(answer, locator) {
|
|
261
|
-
const address = addressed(answer, locator);
|
|
262
|
-
return address.kind === 'address'
|
|
263
|
-
? { kind: 'link', url: address.url, name: address.name, mediaType: address.mediaType }
|
|
264
|
-
: address;
|
|
265
|
-
}
|
|
266
|
-
function refusedAttach(answer, locator) {
|
|
228
|
+
function refusedOn(answer, locator) {
|
|
229
|
+
if (locator === null)
|
|
230
|
+
return keyedFailure(answer.status, answer.body);
|
|
267
231
|
const failure = classifyDoor(answer.status, answer.body, locator);
|
|
268
232
|
if (failure === null)
|
|
269
233
|
return null;
|
|
@@ -276,6 +240,48 @@ export function createAgentsHouseAdapter(options) {
|
|
|
276
240
|
}
|
|
277
241
|
: failure;
|
|
278
242
|
}
|
|
243
|
+
function addressed(answer, locator) {
|
|
244
|
+
const failure = refusedOn(answer, locator);
|
|
245
|
+
if (failure !== null)
|
|
246
|
+
return failure;
|
|
247
|
+
const address = parseFileAddress(answer.body);
|
|
248
|
+
return address === null ? unusable() : { kind: 'address', ...address };
|
|
249
|
+
}
|
|
250
|
+
function linked(answer, locator) {
|
|
251
|
+
const address = addressed(answer, locator);
|
|
252
|
+
return address.kind === 'address'
|
|
253
|
+
? { kind: 'link', url: address.url, name: address.name, mediaType: address.mediaType }
|
|
254
|
+
: address;
|
|
255
|
+
}
|
|
256
|
+
async function attached(request, into) {
|
|
257
|
+
const locator = into?.locator ?? null;
|
|
258
|
+
const declared = await transport.door(houseDoorRoute('files/attach'), {
|
|
259
|
+
...(into === null ? {} : { room_ref: into.authority }),
|
|
260
|
+
name: request.name,
|
|
261
|
+
bytes: request.byteLength,
|
|
262
|
+
sha256: request.sha256,
|
|
263
|
+
media_type: request.mediaType,
|
|
264
|
+
});
|
|
265
|
+
const refused = refusedOn(declared, locator);
|
|
266
|
+
if (refused !== null)
|
|
267
|
+
return refused;
|
|
268
|
+
const upload = houseUpload(declared.body?.upload);
|
|
269
|
+
if (upload === null)
|
|
270
|
+
return unusable();
|
|
271
|
+
const finished = await finishedUpload(transport, upload, request.blob);
|
|
272
|
+
if ('unfinished' in finished)
|
|
273
|
+
return answeredFailure(finished.unfinished, null);
|
|
274
|
+
const unfinished = refusedOn(finished, locator);
|
|
275
|
+
if (unfinished !== null)
|
|
276
|
+
return unfinished;
|
|
277
|
+
const { path, revision, link } = (finished.body ?? {});
|
|
278
|
+
if (into === null)
|
|
279
|
+
return typeof link === 'string' ? { kind: 'linked', link } : unusable();
|
|
280
|
+
const root = `/rooms/${into.handle}/`;
|
|
281
|
+
return typeof path === 'string' && path.startsWith(root) && typeof revision === 'string'
|
|
282
|
+
? { kind: 'attached', path: path.slice(root.length), revision }
|
|
283
|
+
: unusable();
|
|
284
|
+
}
|
|
279
285
|
async function downloaded(ask, locator) {
|
|
280
286
|
let address = addressed(await ask(), locator);
|
|
281
287
|
if (address.kind !== 'address')
|
|
@@ -287,8 +293,10 @@ export function createAgentsHouseAdapter(options) {
|
|
|
287
293
|
return address;
|
|
288
294
|
read = await transport.download(address.url);
|
|
289
295
|
}
|
|
290
|
-
if (read.status !== 200
|
|
291
|
-
return
|
|
296
|
+
if (read.status !== 200)
|
|
297
|
+
return answeredFailure(read.status, null);
|
|
298
|
+
if (read.body === null)
|
|
299
|
+
return unusable();
|
|
292
300
|
return {
|
|
293
301
|
kind: 'binary',
|
|
294
302
|
body: read.body,
|
|
@@ -300,7 +308,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
300
308
|
const entry = authorityFor(request.locator);
|
|
301
309
|
if (entry === undefined)
|
|
302
310
|
return null;
|
|
303
|
-
return () => transport.door(houseDoorRoute('files/
|
|
311
|
+
return () => transport.door(houseDoorRoute('files/read'), {
|
|
304
312
|
room_ref: entry.authority,
|
|
305
313
|
path: request.path,
|
|
306
314
|
revision: request.revision,
|
|
@@ -308,7 +316,10 @@ export function createAgentsHouseAdapter(options) {
|
|
|
308
316
|
}
|
|
309
317
|
return {
|
|
310
318
|
roomTypes: HOUSE_ROOM_TYPES,
|
|
311
|
-
|
|
319
|
+
typedPaths: HOUSE_TYPED_PATHS,
|
|
320
|
+
pathRule: admittedPath,
|
|
321
|
+
unkeptReads: HOUSE_UNKEPT_READS,
|
|
322
|
+
leadingReads: HOUSE_LEADING_READS,
|
|
312
323
|
async authorize() {
|
|
313
324
|
return options.authorize();
|
|
314
325
|
},
|
|
@@ -316,11 +327,9 @@ export function createAgentsHouseAdapter(options) {
|
|
|
316
327
|
const entry = authorityFor(request.locator);
|
|
317
328
|
if (entry === undefined)
|
|
318
329
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
319
|
-
if (request.path !== undefined)
|
|
320
|
-
return namedDocument(entry, request.path, request.signal);
|
|
321
330
|
return request.pageToken === undefined
|
|
322
|
-
?
|
|
323
|
-
:
|
|
331
|
+
? listedRoom(entry)
|
|
332
|
+
: chunkPage(entry, request.pageToken, request.arriving);
|
|
324
333
|
},
|
|
325
334
|
async mutate(_authorization, request, keep) {
|
|
326
335
|
const entry = authorityFor(request.locator);
|
|
@@ -351,16 +360,13 @@ export function createAgentsHouseAdapter(options) {
|
|
|
351
360
|
const entry = authorityFor(request.locator);
|
|
352
361
|
if (entry === undefined)
|
|
353
362
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
354
|
-
const answer = await transport.door(houseDoorRoute('revisions'), revisionBody({
|
|
363
|
+
const answer = await transport.door(houseDoorRoute('files/revisions/list'), revisionBody({
|
|
355
364
|
path: request.path,
|
|
356
365
|
handle: entry.handle,
|
|
357
366
|
...(request.revision === undefined ? {} : { revision: request.revision }),
|
|
358
367
|
...(request.pageToken === undefined ? {} : { pageToken: request.pageToken }),
|
|
359
368
|
}));
|
|
360
|
-
return historyOutcome(answer.status, answer.body, entry.locator,
|
|
361
|
-
path: request.path,
|
|
362
|
-
...(request.revision === undefined ? {} : { revision: request.revision }),
|
|
363
|
-
});
|
|
369
|
+
return historyOutcome(answer.status, answer.body, entry.locator, request);
|
|
364
370
|
},
|
|
365
371
|
async binary(_authorization, request) {
|
|
366
372
|
const ask = pathAddress(request);
|
|
@@ -369,39 +375,21 @@ export function createAgentsHouseAdapter(options) {
|
|
|
369
375
|
return downloaded(ask, request.locator);
|
|
370
376
|
},
|
|
371
377
|
async link(_authorization, request) {
|
|
378
|
+
if (request.kind === 'key') {
|
|
379
|
+
return linked(await transport.door(houseDoorRoute('files/read'), { link: request.link }), null);
|
|
380
|
+
}
|
|
372
381
|
const ask = pathAddress(request);
|
|
373
382
|
if (ask === null)
|
|
374
383
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
375
384
|
return linked(await ask(), request.locator);
|
|
376
385
|
},
|
|
377
386
|
async attach(_authorization, request) {
|
|
387
|
+
if (request.locator === undefined)
|
|
388
|
+
return attached(request, null);
|
|
378
389
|
const entry = authorityFor(request.locator);
|
|
379
390
|
if (entry === undefined)
|
|
380
391
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
381
|
-
|
|
382
|
-
room_ref: entry.authority,
|
|
383
|
-
name: request.name,
|
|
384
|
-
bytes: request.byteLength,
|
|
385
|
-
sha256: request.sha256,
|
|
386
|
-
media_type: request.mediaType.length > 0 ? request.mediaType : OCTET_STREAM,
|
|
387
|
-
});
|
|
388
|
-
const refused = refusedAttach(declared, request.locator);
|
|
389
|
-
if (refused !== null)
|
|
390
|
-
return refused;
|
|
391
|
-
const upload = houseUpload(declared.body?.upload);
|
|
392
|
-
if (upload === null)
|
|
393
|
-
return UNCERTAIN_READ;
|
|
394
|
-
const finished = await finishedUpload(transport, upload, request.blob);
|
|
395
|
-
if (finished === null)
|
|
396
|
-
return UNCERTAIN_READ;
|
|
397
|
-
const unfinished = refusedAttach(finished, request.locator);
|
|
398
|
-
if (unfinished !== null)
|
|
399
|
-
return unfinished;
|
|
400
|
-
const { path, revision } = (finished.body ?? {});
|
|
401
|
-
const root = `/rooms/${entry.handle}/`;
|
|
402
|
-
return typeof path === 'string' && path.startsWith(root) && typeof revision === 'string'
|
|
403
|
-
? { kind: 'attached', path: path.slice(root.length), revision }
|
|
404
|
-
: UNCERTAIN_READ;
|
|
392
|
+
return attached(request, entry);
|
|
405
393
|
},
|
|
406
394
|
reached(locator, version, target) {
|
|
407
395
|
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
|
@@ -412,8 +400,11 @@ export function createAgentsHouseAdapter(options) {
|
|
|
412
400
|
async action(_authorization, request) {
|
|
413
401
|
return withAt(await houseAction(transport, request));
|
|
414
402
|
},
|
|
403
|
+
search(_authorization, request) {
|
|
404
|
+
return houseSearch(transport, [...tracked.values()], request);
|
|
405
|
+
},
|
|
415
406
|
roomStream: {
|
|
416
|
-
hold
|
|
407
|
+
hold,
|
|
417
408
|
observe: notifications.observe,
|
|
418
409
|
},
|
|
419
410
|
conversations: notifications.conversations,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const GENERATED_PROVENANCE = "_provenance";
|
|
2
|
+
export declare const GENERATED_REVISIONS = "_revisions";
|
|
3
|
+
export declare const RESERVED_DERIVED = "_derived";
|
|
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
|
+
export declare const LOCAL_COPY_MANIFEST = ".house";
|
|
8
|
+
export declare const LOCAL_COPY_ROOT_NAMES: readonly string[];
|
|
9
|
+
export declare function admittedPath(path: string): boolean;
|
|
@@ -0,0 +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;AASF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAQlD"}
|