@agentshouse/mdruntime-adapter 0.1.0-cb0e03e5f0ff6 → 0.1.0-cb0fb2a5f1359
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 +11 -1
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +196 -9
- package/dist/adapter.d.ts +0 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +135 -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 +90 -86
- package/dist/transport.d.ts +59 -24
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +45 -10
- 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/dist/transport.js
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
+
import { plain, queryKey } from '@agentshouse/mdmodel';
|
|
1
2
|
export const HOUSE_RUNTIME_READS = {
|
|
2
3
|
acts: [
|
|
3
|
-
'
|
|
4
|
-
'
|
|
5
|
-
'
|
|
6
|
-
'
|
|
7
|
-
'apps/source/top/read',
|
|
4
|
+
'account_update.set',
|
|
5
|
+
'app.screenshot',
|
|
6
|
+
'app.source',
|
|
7
|
+
'app_update.feature_set',
|
|
8
8
|
'conversations/history/list',
|
|
9
9
|
'files/attach',
|
|
10
|
-
'files/batch',
|
|
11
|
-
'files/batch-upload',
|
|
12
10
|
'files/finish',
|
|
13
11
|
'files/read',
|
|
14
12
|
'files/revisions/list',
|
|
13
|
+
'info',
|
|
15
14
|
'room-chunks/list',
|
|
16
15
|
'rooms/discover',
|
|
17
16
|
'rooms/search',
|
|
18
|
-
'
|
|
17
|
+
'update',
|
|
19
18
|
],
|
|
20
19
|
frames: [
|
|
20
|
+
'agent',
|
|
21
21
|
'app-message',
|
|
22
|
+
'app-rooms',
|
|
22
23
|
'authority_changed',
|
|
23
24
|
'carried',
|
|
24
25
|
'caught_up',
|
|
@@ -30,17 +31,17 @@ export const HOUSE_RUNTIME_READS = {
|
|
|
30
31
|
'deployment',
|
|
31
32
|
'held',
|
|
32
33
|
'interactions',
|
|
33
|
-
'link',
|
|
34
34
|
'message',
|
|
35
35
|
'opening',
|
|
36
36
|
'options',
|
|
37
37
|
'part',
|
|
38
38
|
'process',
|
|
39
39
|
'received',
|
|
40
|
+
'report',
|
|
40
41
|
'signal',
|
|
41
42
|
'site',
|
|
42
43
|
'starting',
|
|
43
|
-
'
|
|
44
|
+
'state',
|
|
44
45
|
'tab-icon',
|
|
45
46
|
'turn',
|
|
46
47
|
],
|
|
@@ -51,6 +52,40 @@ export function houseDoorRoute(act) {
|
|
|
51
52
|
export function houseSiteRoute(act) {
|
|
52
53
|
return `/_house/door/${act}`;
|
|
53
54
|
}
|
|
55
|
+
export const SITE_QUERY = 'query';
|
|
56
|
+
export const SITE_FRESH_QUERY = 'fresh';
|
|
57
|
+
export const SITE_QUERY_ROUTE_CHARACTERS = 12_000;
|
|
58
|
+
function addressed(text) {
|
|
59
|
+
let binary = '';
|
|
60
|
+
for (const byte of new TextEncoder().encode(text))
|
|
61
|
+
binary += String.fromCharCode(byte);
|
|
62
|
+
return btoa(binary).replaceAll('+', '-').replaceAll('/', '_').replace(/=+$/u, '');
|
|
63
|
+
}
|
|
64
|
+
export function siteQueryRoute(room, query, fresh = false) {
|
|
65
|
+
const canonical = queryKey(JSON.parse(JSON.stringify(query)));
|
|
66
|
+
const named = fresh ? SITE_FRESH_QUERY : SITE_QUERY;
|
|
67
|
+
return `${houseSiteRoute('query')}/${room}?${named}=${addressed(canonical)}`;
|
|
68
|
+
}
|
|
69
|
+
export function siteQueryAsked(address) {
|
|
70
|
+
let asked;
|
|
71
|
+
try {
|
|
72
|
+
const binary = atob(address.replaceAll('-', '+').replaceAll('_', '/'));
|
|
73
|
+
const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
74
|
+
asked = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes));
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
return plain(asked) && addressed(queryKey(asked)) === address ? asked : null;
|
|
80
|
+
}
|
|
54
81
|
export const SITES_SUBMISSIONS_CREATE = 'sites/submissions/create';
|
|
55
82
|
export const SITE_DOOR_SUBMIT = '/_house/door/submit';
|
|
83
|
+
export const SITES_FUNCTIONS_CALL = 'sites/functions/call';
|
|
84
|
+
export const SITE_DOOR_FUNCTION = '/_house/door/function';
|
|
85
|
+
export const SITE_DOOR_ACTS = {
|
|
86
|
+
[SITES_SUBMISSIONS_CREATE]: { op: 'submission_create', route: SITE_DOOR_SUBMIT },
|
|
87
|
+
[SITES_FUNCTIONS_CALL]: { op: 'function_call', route: SITE_DOOR_FUNCTION },
|
|
88
|
+
};
|
|
89
|
+
export const SITE_DOOR_TOOL = 'app_update';
|
|
56
90
|
export const SITE_FILES = '/_house/files/';
|
|
91
|
+
export const SITE_IMAGE_COPIES_HEADER = 'X-House-Image-Copies';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ProviderRefusal, type TransportUncertainty } from '@agentshouse/mdruntime';
|
|
2
|
+
export declare const UNANSWERED: TransportUncertainty;
|
|
3
|
+
export declare function failedOn(failure: unknown): TransportUncertainty;
|
|
4
|
+
export declare function unusable(): TransportUncertainty;
|
|
5
|
+
export declare function refusedFor(refusal: ProviderRefusal): TransportUncertainty;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uncertain.d.ts","sourceRoot":"","sources":["../src/uncertain.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,oBAAoB,EAC1B,MAAM,wBAAwB,CAAC;AAEhC,eAAO,MAAM,UAAU,EAAE,oBAAwD,CAAC;AAElF,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,oBAAoB,CAE/D;AAED,wBAAgB,QAAQ,IAAI,oBAAoB,CAE/C;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,eAAe,GAAG,oBAAoB,CAEzE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { refusalError, } from '@agentshouse/mdruntime';
|
|
2
|
+
export const UNANSWERED = { kind: 'transport-uncertainty' };
|
|
3
|
+
export function failedOn(failure) {
|
|
4
|
+
return { kind: 'transport-uncertainty', failure };
|
|
5
|
+
}
|
|
6
|
+
export function unusable() {
|
|
7
|
+
return failedOn(new Error());
|
|
8
|
+
}
|
|
9
|
+
export function refusedFor(refusal) {
|
|
10
|
+
return failedOn(refusalError(refusal));
|
|
11
|
+
}
|
package/dist/upload.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TransportUncertainty } from '@agentshouse/mdruntime';
|
|
1
2
|
import { type HouseDoorAnswer, type HouseTransport } from './transport.js';
|
|
2
3
|
export type HouseUpload = {
|
|
3
4
|
readonly id: string;
|
|
@@ -8,5 +9,9 @@ export type HouseUpload = {
|
|
|
8
9
|
}[];
|
|
9
10
|
};
|
|
10
11
|
export declare function houseUpload(value: unknown): HouseUpload | null;
|
|
11
|
-
export declare function finishedUpload(transport: HouseTransport, first: HouseUpload, blob: Blob): Promise<HouseDoorAnswer |
|
|
12
|
-
|
|
12
|
+
export declare function finishedUpload(transport: HouseTransport, first: HouseUpload, blob: Blob): Promise<HouseDoorAnswer | {
|
|
13
|
+
readonly unfinished: number;
|
|
14
|
+
}>;
|
|
15
|
+
type StagedFile = (sha256: unknown) => Promise<Blob> | null;
|
|
16
|
+
export declare function stagedBatch(transport: HouseTransport, body: Readonly<Record<string, unknown>>, file: StagedFile): Promise<HouseDoorAnswer | TransportUncertainty>;
|
|
17
|
+
export {};
|
package/dist/upload.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../src/upload.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../src/upload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAGpF,OAAO,EAAkB,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAG3F,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,SAAS;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC5E,CAAC;AAeF,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,CAQ9D;AA+BD,wBAAsB,cAAc,CAClC,SAAS,EAAE,cAAc,EACzB,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,eAAe,GAAG;IAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CAgB5D;AAED,KAAK,UAAU,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAsB5D,wBAAsB,WAAW,CAC/B,SAAS,EAAE,cAAc,EACzB,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACvC,IAAI,EAAE,UAAU,GACf,OAAO,CAAC,eAAe,GAAG,oBAAoB,CAAC,CAoBjD"}
|
package/dist/upload.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { sha256 } from '@agentshouse/mdruntime/digest';
|
|
2
|
+
import { answeredFailure, doorRefusal } from './refusal.js';
|
|
2
3
|
import { houseDoorRoute } from './transport.js';
|
|
4
|
+
import { unusable } from './uncertain.js';
|
|
3
5
|
const FINISHING_ROUNDS = 24;
|
|
4
6
|
function record(value) {
|
|
5
7
|
return value !== null && typeof value === 'object' ? value : {};
|
|
@@ -37,17 +39,19 @@ async function sent(transport, upload, blob, digests) {
|
|
|
37
39
|
for (const { part: number, url } of upload.parts) {
|
|
38
40
|
const start = (number - 1) * upload.partBytes;
|
|
39
41
|
const slice = blob.slice(start, start + upload.partBytes);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
const stored = await transport.put(url, slice, checksum(digests[number - 1]));
|
|
43
|
+
if (stored !== 200)
|
|
44
|
+
return stored;
|
|
42
45
|
}
|
|
43
|
-
return
|
|
46
|
+
return 200;
|
|
44
47
|
}
|
|
45
48
|
export async function finishedUpload(transport, first, blob) {
|
|
46
49
|
const digests = await partSha256(blob, first.partBytes);
|
|
47
50
|
let upload = first;
|
|
48
51
|
for (let round = 0; round < FINISHING_ROUNDS; round += 1) {
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
const stored = await sent(transport, upload, blob, digests);
|
|
53
|
+
if (stored !== 200)
|
|
54
|
+
return { unfinished: stored };
|
|
51
55
|
const answer = await transport.door(houseDoorRoute('files/finish'), {
|
|
52
56
|
upload: upload.id,
|
|
53
57
|
part_sha256: digests,
|
|
@@ -59,5 +63,44 @@ export async function finishedUpload(transport, first, blob) {
|
|
|
59
63
|
return answer;
|
|
60
64
|
upload = missing;
|
|
61
65
|
}
|
|
62
|
-
return
|
|
66
|
+
return { unfinished: 200 };
|
|
67
|
+
}
|
|
68
|
+
function unstagedRefusal(answer) {
|
|
69
|
+
const refusal = doorRefusal(answer.body);
|
|
70
|
+
return refusal?.code === 'files_unstaged' ? refusal : null;
|
|
71
|
+
}
|
|
72
|
+
async function staged(transport, named, file) {
|
|
73
|
+
const upload = houseUpload(named);
|
|
74
|
+
if (upload === null)
|
|
75
|
+
return unusable();
|
|
76
|
+
const blob = file(record(named).sha256);
|
|
77
|
+
if (blob === null)
|
|
78
|
+
return unusable();
|
|
79
|
+
const sent = await finishedUpload(transport, upload, await blob);
|
|
80
|
+
if ('unfinished' in sent)
|
|
81
|
+
return answeredFailure(sent.unfinished, null);
|
|
82
|
+
if (sent.status !== 200)
|
|
83
|
+
return answeredFailure(sent.status, sent.body);
|
|
84
|
+
return record(sent.body).staged === true ? null : unusable();
|
|
85
|
+
}
|
|
86
|
+
export async function stagedBatch(transport, body, file) {
|
|
87
|
+
let answer = await transport.door(houseDoorRoute('update'), body);
|
|
88
|
+
const finished = new Set();
|
|
89
|
+
for (let unstaged = unstagedRefusal(answer); unstaged !== null; unstaged = unstagedRefusal(answer)) {
|
|
90
|
+
const named = unstaged.fields.upload;
|
|
91
|
+
if (!Array.isArray(named))
|
|
92
|
+
return unusable();
|
|
93
|
+
const fresh = named.filter((upload) => !finished.has(record(upload).id));
|
|
94
|
+
if (fresh.length === 0)
|
|
95
|
+
return answeredFailure(answer.status, answer.body);
|
|
96
|
+
for (const upload of fresh) {
|
|
97
|
+
const staging = await staged(transport, upload, file);
|
|
98
|
+
if (staging !== null)
|
|
99
|
+
return staging;
|
|
100
|
+
}
|
|
101
|
+
for (const upload of fresh)
|
|
102
|
+
finished.add(record(upload).id);
|
|
103
|
+
answer = await transport.door(houseDoorRoute('update'), body);
|
|
104
|
+
}
|
|
105
|
+
return answer;
|
|
63
106
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -14,4 +14,3 @@ export declare function presented(authority: string, at: LogPosition): Presented
|
|
|
14
14
|
export declare const DECIMAL: RegExp;
|
|
15
15
|
export declare function reachedVersion(roomVersion: string, target: string, currentEpoch: string | undefined): boolean;
|
|
16
16
|
export declare function followsVersion(roomVersion: string, next: string): boolean;
|
|
17
|
-
//# sourceMappingURL=version.d.ts.map
|
package/dist/write.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ChangeBatch, type HistoryResult, type MutationResult } from '@agentshouse/mdruntime';
|
|
1
|
+
import { type ChangeBatch, type HistoryResult, type MutationResult, type Written } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { HouseBounds } from './discovery.js';
|
|
3
3
|
export type HouseOperation = Readonly<Record<string, unknown>>;
|
|
4
4
|
export type ChangeMapping = {
|
|
@@ -9,19 +9,14 @@ export type ChangeMapping = {
|
|
|
9
9
|
path: string;
|
|
10
10
|
rule: string;
|
|
11
11
|
};
|
|
12
|
-
export declare function houseChanges(batch: ChangeBatch, handle: string): ChangeMapping;
|
|
13
|
-
export declare function houseParts(saved: readonly {
|
|
14
|
-
readonly path: string;
|
|
15
|
-
readonly parts: unknown;
|
|
16
|
-
}[], handle: string): ChangeMapping;
|
|
12
|
+
export declare function houseChanges(batch: ChangeBatch, handle: string, written: Written): ChangeMapping;
|
|
17
13
|
export declare function houseMove(batch: ChangeBatch, source: string, destination: string): ChangeMapping;
|
|
18
14
|
export type OperationHead = {
|
|
19
15
|
readonly operation_id: string;
|
|
20
|
-
readonly room_ref: string;
|
|
21
16
|
readonly app_ref?: string;
|
|
22
17
|
readonly release?: string;
|
|
23
18
|
};
|
|
24
|
-
export declare function operationHead(batch: ChangeBatch
|
|
19
|
+
export declare function operationHead(batch: ChangeBatch): OperationHead;
|
|
25
20
|
export declare function batchPaths(changes: readonly HouseOperation[]): readonly string[];
|
|
26
21
|
export declare function deltaBody(changes: readonly HouseOperation[]): string;
|
|
27
22
|
export declare function deltaBytes(delta: string): number;
|
|
@@ -56,7 +51,5 @@ export declare function revisionBody(input: {
|
|
|
56
51
|
pageToken?: string;
|
|
57
52
|
}): Record<string, unknown>;
|
|
58
53
|
export declare function historyOutcome(status: number, body: unknown, locator: string, request: {
|
|
59
|
-
path: string;
|
|
60
54
|
revision?: string;
|
|
61
55
|
}): HistoryResult;
|
|
62
|
-
//# sourceMappingURL=write.d.ts.map
|
package/dist/write.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../src/write.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,WAAW,EAEhB,KAAK,aAAa,EAElB,KAAK,cAAc,
|
|
1
|
+
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../src/write.ts"],"names":[],"mappings":"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"}
|
package/dist/write.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import { departure,
|
|
2
|
-
import { answered, answering,
|
|
1
|
+
import { departure, isPart, ROW_WEIGHT, } from '@agentshouse/mdruntime';
|
|
2
|
+
import { answered, answering, attachmentOf, headChange, revised } from './read.js';
|
|
3
3
|
import { sha256Hex, textBytes } from './digest.js';
|
|
4
4
|
import { nativePath, roomLocalPath } from './map.js';
|
|
5
|
-
import { classifyDoor, doorRefusal, scopedRefusal } from './refusal.js';
|
|
5
|
+
import { answeredFailure, classifyDoor, doorRefusal, resetOf, scopedRefusal } from './refusal.js';
|
|
6
6
|
import { readPosition, roomVersion } from './version.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
function priorPreamble(batch, path) {
|
|
14
|
-
return batch.preconditions.find((precondition) => precondition.kind === 'preamble' && precondition.path === path);
|
|
7
|
+
import { unusable } from './uncertain.js';
|
|
8
|
+
function priorPart(batch, change) {
|
|
9
|
+
return batch.preconditions.find((held) => held.kind === change.kind &&
|
|
10
|
+
held.path === change.path &&
|
|
11
|
+
(change.kind === 'preamble' || ('name' in held && held.name === change.name)));
|
|
15
12
|
}
|
|
16
13
|
function priorAbsence(batch, path) {
|
|
17
14
|
return batch.preconditions.find((precondition) => precondition.kind === 'absent' && precondition.path === path);
|
|
@@ -22,60 +19,30 @@ function priorExistence(batch, path) {
|
|
|
22
19
|
return undefined;
|
|
23
20
|
return precondition.kind === 'revision' ? { base: precondition.revision } : { kind: 'presence' };
|
|
24
21
|
}
|
|
25
|
-
function
|
|
26
|
-
if (
|
|
27
|
-
return {
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
function textOf(batch, change, path, document) {
|
|
23
|
+
if (isPart(change) && priorPart(batch, change) === undefined)
|
|
24
|
+
return { rule: 'precondition-missing' };
|
|
25
|
+
if (change.kind === 'create' && priorAbsence(batch, change.path) === undefined)
|
|
26
|
+
return { rule: 'precondition-missing' };
|
|
27
|
+
if (change.kind === 'replace' && priorExistence(batch, change.path) === undefined)
|
|
28
|
+
return { rule: 'precondition-missing' };
|
|
29
|
+
if (document === null || document === undefined)
|
|
30
30
|
return null;
|
|
31
|
-
|
|
31
|
+
if (document.stale)
|
|
32
|
+
return { rule: 'precondition-stale' };
|
|
33
|
+
if (document.created)
|
|
34
|
+
return { operation: { op: 'write', path, content: document.content } };
|
|
35
|
+
if (document.base === null)
|
|
36
|
+
return { rule: 'presence-base-unrepresentable' };
|
|
37
|
+
return { operation: { op: 'write', path, base: document.base, content: document.content } };
|
|
32
38
|
}
|
|
33
|
-
function operationOf(batch,
|
|
39
|
+
function operationOf(batch, index, handle, written) {
|
|
40
|
+
const change = batch.changes[index];
|
|
34
41
|
const path = nativePath(change.path, handle);
|
|
35
|
-
if (change.kind === '
|
|
36
|
-
|
|
37
|
-
if (prior === undefined)
|
|
38
|
-
return { rule: 'precondition-missing' };
|
|
39
|
-
return {
|
|
40
|
-
operation: {
|
|
41
|
-
op: 'set_field',
|
|
42
|
-
path,
|
|
43
|
-
field: change.name,
|
|
44
|
-
value: change.value,
|
|
45
|
-
...(prior.value === undefined ? {} : { base: prior.value }),
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
if (change.kind === 'section') {
|
|
50
|
-
const prior = priorSection(batch, change.path, change.name);
|
|
51
|
-
if (prior === undefined)
|
|
52
|
-
return { rule: 'precondition-missing' };
|
|
53
|
-
return {
|
|
54
|
-
operation: {
|
|
55
|
-
op: 'replace_section',
|
|
56
|
-
path,
|
|
57
|
-
section: change.name,
|
|
58
|
-
base: prior.value,
|
|
59
|
-
content: change.value,
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
if (change.kind === 'preamble') {
|
|
64
|
-
const prior = priorPreamble(batch, change.path);
|
|
65
|
-
if (prior === undefined)
|
|
66
|
-
return { rule: 'precondition-missing' };
|
|
67
|
-
return {
|
|
68
|
-
operation: { op: 'replace_preamble', path, base: prior.value, content: change.value },
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
if (change.kind === 'create') {
|
|
72
|
-
if (priorAbsence(batch, change.path) === undefined)
|
|
73
|
-
return { rule: 'precondition-missing' };
|
|
74
|
-
const operation = created(change, path);
|
|
75
|
-
return operation === null ? { rule: 'type-missing' } : { operation };
|
|
76
|
-
}
|
|
42
|
+
if (isPart(change) || change.kind === 'create' || change.kind === 'replace')
|
|
43
|
+
return textOf(batch, change, path, written[index]);
|
|
77
44
|
if (change.kind === 'binary') {
|
|
78
|
-
const
|
|
45
|
+
const uploaded = {
|
|
79
46
|
op: 'upload',
|
|
80
47
|
path,
|
|
81
48
|
local_id: change.localId,
|
|
@@ -83,45 +50,61 @@ function operationOf(batch, change, handle) {
|
|
|
83
50
|
sha256: change.sha256,
|
|
84
51
|
media_type: change.mediaType,
|
|
85
52
|
};
|
|
86
|
-
const from = departure(batch.changes,
|
|
53
|
+
const from = departure(batch.changes, index);
|
|
87
54
|
if (from === change.path && priorAbsence(batch, change.path) !== undefined)
|
|
88
|
-
return { operation:
|
|
55
|
+
return { operation: uploaded };
|
|
89
56
|
const replaced = priorExistence(batch, from);
|
|
90
57
|
if (replaced === undefined)
|
|
91
58
|
return { rule: 'precondition-missing' };
|
|
92
59
|
if (!('base' in replaced))
|
|
93
60
|
return { rule: 'presence-base-unrepresentable' };
|
|
94
|
-
return { operation: { ...
|
|
61
|
+
return { operation: { ...uploaded, base: replaced.base } };
|
|
95
62
|
}
|
|
96
63
|
const existence = priorExistence(batch, change.path);
|
|
97
64
|
if (existence === undefined)
|
|
98
65
|
return { rule: 'precondition-missing' };
|
|
99
66
|
if (!('base' in existence))
|
|
100
67
|
return { rule: 'presence-base-unrepresentable' };
|
|
101
|
-
if (change.kind === 'replace') {
|
|
102
|
-
return { operation: { op: 'replace', path, base: existence.base, content: change.content } };
|
|
103
|
-
}
|
|
104
68
|
if (change.kind === 'move') {
|
|
105
69
|
if (priorAbsence(batch, change.to) === undefined)
|
|
106
70
|
return { rule: 'precondition-missing' };
|
|
107
71
|
return {
|
|
108
|
-
operation: { op: '
|
|
72
|
+
operation: { op: 'move', path, to: nativePath(change.to, handle), base: existence.base },
|
|
109
73
|
};
|
|
110
74
|
}
|
|
111
|
-
return { operation: { op: '
|
|
75
|
+
return { operation: { op: 'delete', path, base: existence.base } };
|
|
112
76
|
}
|
|
113
|
-
export function houseChanges(batch, handle) {
|
|
77
|
+
export function houseChanges(batch, handle, written) {
|
|
114
78
|
const changes = [];
|
|
115
|
-
|
|
116
|
-
|
|
79
|
+
const moves = new Map();
|
|
80
|
+
const before = new Map();
|
|
81
|
+
for (const [index, change] of batch.changes.entries()) {
|
|
82
|
+
const mapped = operationOf(batch, index, handle, written);
|
|
83
|
+
if (mapped === null)
|
|
84
|
+
continue;
|
|
117
85
|
if ('rule' in mapped)
|
|
118
86
|
return { kind: 'unmapped', path: change.path, rule: mapped.rule };
|
|
119
|
-
|
|
87
|
+
const { operation } = mapped;
|
|
88
|
+
const from = departure(batch.changes, index);
|
|
89
|
+
if (change.kind === 'move' && !moves.has(from))
|
|
90
|
+
moves.set(from, changes.length);
|
|
91
|
+
const moved = moves.get(from);
|
|
92
|
+
if (change.kind !== 'move' &&
|
|
93
|
+
moved !== undefined &&
|
|
94
|
+
operation.op === 'write' &&
|
|
95
|
+
'base' in operation) {
|
|
96
|
+
before.set(moved, { ...operation, path: nativePath(from, handle) });
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
changes.push(operation);
|
|
120
100
|
}
|
|
121
|
-
return {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
101
|
+
return {
|
|
102
|
+
kind: 'changes',
|
|
103
|
+
changes: changes.flatMap((operation, at) => {
|
|
104
|
+
const written = before.get(at);
|
|
105
|
+
return written === undefined ? [operation] : [written, operation];
|
|
106
|
+
}),
|
|
107
|
+
};
|
|
125
108
|
}
|
|
126
109
|
export function houseMove(batch, source, destination) {
|
|
127
110
|
const changes = [];
|
|
@@ -133,7 +116,7 @@ export function houseMove(batch, source, destination) {
|
|
|
133
116
|
return { kind: 'unmapped', path, rule: 'presence-base-unrepresentable' };
|
|
134
117
|
}
|
|
135
118
|
changes.push({
|
|
136
|
-
op: '
|
|
119
|
+
op: 'move',
|
|
137
120
|
path: nativePath(path, source),
|
|
138
121
|
to: nativePath(to, destination),
|
|
139
122
|
base: existence.base,
|
|
@@ -141,14 +124,14 @@ export function houseMove(batch, source, destination) {
|
|
|
141
124
|
}
|
|
142
125
|
return { kind: 'changes', changes };
|
|
143
126
|
}
|
|
144
|
-
export function operationHead(batch
|
|
127
|
+
export function operationHead(batch) {
|
|
145
128
|
const writer = batch.writtenBy;
|
|
146
|
-
const head = { operation_id: batch.id
|
|
129
|
+
const head = { operation_id: batch.id };
|
|
147
130
|
return writer === undefined ? head : { ...head, app_ref: writer.app, release: writer.release };
|
|
148
131
|
}
|
|
149
132
|
export function batchPaths(changes) {
|
|
150
133
|
return [
|
|
151
|
-
...new Set(changes.flatMap((change) => change.op === '
|
|
134
|
+
...new Set(changes.flatMap((change) => change.op === 'move' ? [String(change.path), String(change.to)] : [String(change.path)])),
|
|
152
135
|
];
|
|
153
136
|
}
|
|
154
137
|
export function deltaBody(changes) {
|
|
@@ -181,7 +164,7 @@ function* material(value, handle, within = () => true) {
|
|
|
181
164
|
return null;
|
|
182
165
|
if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string')
|
|
183
166
|
return null;
|
|
184
|
-
const binary =
|
|
167
|
+
const binary = attachmentOf(file);
|
|
185
168
|
if (binary === null)
|
|
186
169
|
return null;
|
|
187
170
|
const head = headChange(file);
|
|
@@ -224,14 +207,14 @@ function* acceptedOf(at, contents) {
|
|
|
224
207
|
if (entry.content !== null)
|
|
225
208
|
answer.documents.set(entry.path, entry.content);
|
|
226
209
|
if (entry.binary !== undefined)
|
|
227
|
-
answer.
|
|
210
|
+
answer.attachments.set(entry.path, entry.binary);
|
|
228
211
|
revised(answer, entry.path, entry.revision);
|
|
229
212
|
if (entry.head !== undefined)
|
|
230
213
|
answer.changes.set(entry.path, entry.head);
|
|
231
214
|
}
|
|
232
|
-
const unbinaried = answer.
|
|
233
|
-
const {
|
|
234
|
-
return { roomVersion: roomVersion(at), ...room, ...(unbinaried ? {} : {
|
|
215
|
+
const unbinaried = answer.attachments.size === 0;
|
|
216
|
+
const { attachments, facts: _facts, ...room } = yield* answered(answer);
|
|
217
|
+
return { roomVersion: roomVersion(at), ...room, ...(unbinaried ? {} : { attachments }) };
|
|
235
218
|
}
|
|
236
219
|
function* movedOutcome(held, move) {
|
|
237
220
|
const authorities = Array.isArray(held.authorities) ? held.authorities : [];
|
|
@@ -244,12 +227,12 @@ function* movedOutcome(held, move) {
|
|
|
244
227
|
const left = at(move.source.authority);
|
|
245
228
|
const arrived = at(move.destination.authority);
|
|
246
229
|
if (left === null || arrived === null)
|
|
247
|
-
return
|
|
230
|
+
return unusable();
|
|
248
231
|
const under = (handle) => (path) => path.startsWith(`/rooms/${handle}/`);
|
|
249
232
|
const leaving = yield* material(held.contents, move.source.handle, under(move.source.handle));
|
|
250
233
|
const arriving = yield* material(held.contents, move.destination.handle, under(move.destination.handle));
|
|
251
234
|
if (leaving === null || arriving === null)
|
|
252
|
-
return
|
|
235
|
+
return unusable();
|
|
253
236
|
return {
|
|
254
237
|
kind: 'accepted',
|
|
255
238
|
...(yield* acceptedOf(left, leaving)),
|
|
@@ -276,10 +259,8 @@ export function* mutationOutcome(status, body, locator, handle, move) {
|
|
|
276
259
|
return scopedRefusal(locator, 'undisclosed', refusal);
|
|
277
260
|
}
|
|
278
261
|
const classified = classifyDoor(status, body, locator);
|
|
279
|
-
const reset = refusal
|
|
280
|
-
if (refusal?.
|
|
281
|
-
typeof reset === 'string' &&
|
|
282
|
-
classified?.kind === 'transport-uncertainty') {
|
|
262
|
+
const reset = resetOf(refusal);
|
|
263
|
+
if (refusal !== null && reset !== undefined && classified?.kind === 'transport-uncertainty') {
|
|
283
264
|
return {
|
|
284
265
|
kind: 'retryable-refusal',
|
|
285
266
|
code: refusal.code,
|
|
@@ -302,18 +283,19 @@ export function* mutationOutcome(status, body, locator, handle, move) {
|
|
|
302
283
|
retryable: refusal.retryable,
|
|
303
284
|
};
|
|
304
285
|
}
|
|
305
|
-
if (status !== 200
|
|
306
|
-
return
|
|
307
|
-
|
|
286
|
+
if (status !== 200)
|
|
287
|
+
return answeredFailure(status, body);
|
|
288
|
+
if (typeof body !== 'object' || body === null)
|
|
289
|
+
return unusable();
|
|
308
290
|
const held = body;
|
|
309
291
|
if (move !== undefined)
|
|
310
292
|
return yield* movedOutcome(held, move);
|
|
311
293
|
const at = readPosition(held);
|
|
312
294
|
if (at === null)
|
|
313
|
-
return
|
|
295
|
+
return unusable();
|
|
314
296
|
const contents = yield* material(held.contents, handle);
|
|
315
297
|
if (contents === null)
|
|
316
|
-
return
|
|
298
|
+
return unusable();
|
|
317
299
|
return { kind: 'accepted', ...(yield* acceptedOf(at, contents)) };
|
|
318
300
|
}
|
|
319
301
|
export function rejectedMapping(mapping) {
|
|
@@ -362,25 +344,23 @@ export function historyOutcome(status, body, locator, request) {
|
|
|
362
344
|
if (classified !== null)
|
|
363
345
|
return classified;
|
|
364
346
|
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
365
|
-
return
|
|
347
|
+
return unusable();
|
|
366
348
|
}
|
|
367
349
|
const held = body;
|
|
368
350
|
if (!Array.isArray(held.revisions))
|
|
369
|
-
return
|
|
351
|
+
return unusable();
|
|
370
352
|
const entries = [];
|
|
371
353
|
for (const entry of held.revisions) {
|
|
372
354
|
if (typeof entry !== 'object' || entry === null)
|
|
373
|
-
return
|
|
355
|
+
return unusable();
|
|
374
356
|
entries.push(entry);
|
|
375
357
|
}
|
|
376
|
-
|
|
377
|
-
|
|
358
|
+
const named = entries[0];
|
|
359
|
+
if (request.revision !== undefined && typeof named?.media_type !== 'string') {
|
|
378
360
|
if (named === undefined)
|
|
379
361
|
return { kind: 'no-history' };
|
|
380
|
-
if (typeof named.media_type === 'string')
|
|
381
|
-
return { kind: 'no-history' };
|
|
382
362
|
if (typeof named.content !== 'string')
|
|
383
|
-
return
|
|
363
|
+
return unusable();
|
|
384
364
|
return { kind: 'revision', content: named.content };
|
|
385
365
|
}
|
|
386
366
|
if (entries.length === 0)
|
|
@@ -391,16 +371,16 @@ export function historyOutcome(status, body, locator, request) {
|
|
|
391
371
|
if (typeof entry.revision !== 'string' ||
|
|
392
372
|
author === null ||
|
|
393
373
|
typeof entry.created_at !== 'string') {
|
|
394
|
-
return
|
|
374
|
+
return unusable();
|
|
395
375
|
}
|
|
396
|
-
const
|
|
397
|
-
if (
|
|
398
|
-
return
|
|
376
|
+
const attachment = attachmentOf(entry);
|
|
377
|
+
if (attachment === null)
|
|
378
|
+
return unusable();
|
|
399
379
|
revisions.push({
|
|
400
380
|
revision: entry.revision,
|
|
401
381
|
author,
|
|
402
382
|
time: entry.created_at,
|
|
403
|
-
...(
|
|
383
|
+
...(attachment === undefined ? {} : { attachment }),
|
|
404
384
|
});
|
|
405
385
|
}
|
|
406
386
|
const next = held.next_before;
|
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/mdruntime-adapter",
|
|
3
|
-
"version": "0.1.0-cb0e03e5f0ff6",
|
|
4
3
|
"description": "Agents House Adapter for the MD Runtime",
|
|
5
4
|
"license": "MIT",
|
|
6
5
|
"type": "module",
|
|
@@ -24,11 +23,13 @@
|
|
|
24
23
|
"LICENSE"
|
|
25
24
|
],
|
|
26
25
|
"dependencies": {
|
|
27
|
-
"@agentshouse/
|
|
26
|
+
"@agentshouse/mdmodel": "0.1.0-c47d22bab1bc8",
|
|
27
|
+
"@agentshouse/mdruntime": "0.1.0-cdf8ca5c0fa11"
|
|
28
28
|
},
|
|
29
29
|
"repository": {
|
|
30
30
|
"type": "git",
|
|
31
31
|
"url": "git+https://github.com/agentshouse/core.git",
|
|
32
32
|
"directory": "mdruntime/packages/mdruntime-adapter"
|
|
33
|
-
}
|
|
33
|
+
},
|
|
34
|
+
"version": "0.1.0-cb0fb2a5f1359"
|
|
34
35
|
}
|
package/dist/app-reference.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"app-reference.d.ts","sourceRoot":"","sources":["../src/app-reference.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,qBAAqB,QAEjC,CAAC"}
|