@agentshouse/mdruntime-adapter 0.1.0-alpha.8 → 0.1.0-c17fae3d012d0
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/AGENTS.md +155 -27
- package/README.md +32 -0
- package/dist/actions.d.ts +4 -12
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +239 -332
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +272 -198
- package/dist/digest.js +1 -5
- package/dist/discovery.d.ts +22 -26
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +154 -223
- package/dist/gather.d.ts +3 -0
- package/dist/gather.d.ts.map +1 -0
- package/dist/gather.js +40 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -3
- package/dist/links.d.ts +12 -0
- package/dist/links.d.ts.map +1 -0
- package/dist/links.js +66 -0
- package/dist/map.d.ts +2 -2
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +6 -7
- package/dist/model.d.ts +2 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +21 -39
- package/dist/read.d.ts +31 -26
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +208 -199
- package/dist/refusal.d.ts +3 -1
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +27 -62
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +110 -124
- package/dist/stream.d.ts +11 -5
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +190 -218
- package/dist/transport.d.ts +41 -32
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +2 -3
- package/dist/version.d.ts +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +23 -18
- package/dist/write.d.ts +11 -7
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +130 -208
- package/package.json +4 -12
- package/dist/actions.js.map +0 -1
- package/dist/adapter.js.map +0 -1
- package/dist/digest.js.map +0 -1
- package/dist/discovery.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/map.js.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/read.js.map +0 -1
- package/dist/refusal.js.map +0 -1
- package/dist/site.js.map +0 -1
- package/dist/stream.js.map +0 -1
- package/dist/transport.js.map +0 -1
- package/dist/version.js.map +0 -1
- package/dist/write.js.map +0 -1
package/dist/version.js
CHANGED
|
@@ -3,27 +3,32 @@ export function roomVersion(at) {
|
|
|
3
3
|
}
|
|
4
4
|
export function logPosition(version) {
|
|
5
5
|
const split = version.lastIndexOf(':');
|
|
6
|
-
if (split < 1 || split === version.length - 1)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
position: version.slice(split + 1)
|
|
10
|
-
};
|
|
6
|
+
if (split < 1 || split === version.length - 1)
|
|
7
|
+
return null;
|
|
8
|
+
return { logEpoch: version.slice(0, split), position: version.slice(split + 1) };
|
|
11
9
|
}
|
|
12
10
|
export function readPosition(held) {
|
|
13
11
|
const { position, log_epoch: logEpoch } = held;
|
|
14
|
-
if (typeof position !== 'string' || position.length === 0)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
12
|
+
if (typeof position !== 'string' || position.length === 0)
|
|
13
|
+
return null;
|
|
14
|
+
if (typeof logEpoch !== 'string' || logEpoch.length === 0)
|
|
15
|
+
return null;
|
|
16
|
+
return { position, logEpoch };
|
|
20
17
|
}
|
|
21
18
|
export function presented(authority, at) {
|
|
22
|
-
return {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
return { authority, position: at.position, log_epoch: at.logEpoch };
|
|
20
|
+
}
|
|
21
|
+
const DECIMAL = /^(?:0|[1-9][0-9]*)$/;
|
|
22
|
+
export function reachedVersion(roomVersion, target, currentEpoch) {
|
|
23
|
+
if (roomVersion === target)
|
|
24
|
+
return true;
|
|
25
|
+
const held = logPosition(roomVersion);
|
|
26
|
+
const wanted = logPosition(target);
|
|
27
|
+
if (held === null || wanted === null)
|
|
28
|
+
return false;
|
|
29
|
+
if (!DECIMAL.test(held.position) || !DECIMAL.test(wanted.position))
|
|
30
|
+
return false;
|
|
31
|
+
if (held.logEpoch === wanted.logEpoch)
|
|
32
|
+
return BigInt(held.position) >= BigInt(wanted.position);
|
|
33
|
+
return held.logEpoch === currentEpoch;
|
|
27
34
|
}
|
|
28
|
-
|
|
29
|
-
//# sourceMappingURL=version.js.map
|
package/dist/write.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { ChangeBatch, HistoryResult, MutationResult } from '@agentshouse/mdruntime';
|
|
2
|
-
|
|
3
|
-
export declare const UPLOAD_LINE_BYTES = 37;
|
|
4
|
-
export declare const UPLOAD_BYTES_MAX: number;
|
|
2
|
+
import type { HouseBounds } from './discovery.js';
|
|
5
3
|
export type HouseOperation = Readonly<Record<string, unknown>>;
|
|
6
4
|
export type ChangeMapping = {
|
|
7
5
|
kind: 'changes';
|
|
@@ -11,13 +9,19 @@ export type ChangeMapping = {
|
|
|
11
9
|
path: string;
|
|
12
10
|
rule: string;
|
|
13
11
|
};
|
|
14
|
-
export declare function houseChanges(batch: ChangeBatch, handle: string
|
|
12
|
+
export declare function houseChanges(batch: ChangeBatch, handle: string): ChangeMapping;
|
|
13
|
+
export type OperationHead = {
|
|
14
|
+
readonly operation_id: string;
|
|
15
|
+
readonly app_ref?: string;
|
|
16
|
+
readonly release?: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function operationHead(batch: ChangeBatch): OperationHead;
|
|
15
19
|
export declare function batchPaths(changes: readonly HouseOperation[]): readonly string[];
|
|
16
20
|
export declare function deltaBody(changes: readonly HouseOperation[]): string;
|
|
17
21
|
export declare function deltaBytes(delta: string): number;
|
|
18
|
-
export declare function uploadable(bytes: number): boolean;
|
|
22
|
+
export declare function uploadable(inline: Readonly<Record<string, unknown>>, bytes: number, bounds: Pick<HouseBounds, 'max_inline_body_bytes' | 'max_upload_bytes'>): boolean;
|
|
19
23
|
export declare function deltaDigest(delta: string): Promise<string>;
|
|
20
|
-
export declare function mutationOutcome(status: number, body: unknown, locator: string, handle: string
|
|
24
|
+
export declare function mutationOutcome(status: number, body: unknown, locator: string, handle: string): MutationResult;
|
|
21
25
|
export declare function rejectedMapping(mapping: Extract<ChangeMapping, {
|
|
22
26
|
kind: 'unmapped';
|
|
23
27
|
}>): {
|
|
@@ -30,7 +34,7 @@ export declare function rejectedMapping(mapping: Extract<ChangeMapping, {
|
|
|
30
34
|
};
|
|
31
35
|
export declare function revisionBody(input: {
|
|
32
36
|
path: string;
|
|
33
|
-
handle: string
|
|
37
|
+
handle: string;
|
|
34
38
|
revision?: string;
|
|
35
39
|
pageToken?: string;
|
|
36
40
|
}): Record<string, unknown>;
|
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,KAAK,EAEV,WAAW,
|
|
1
|
+
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../src/write.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,WAAW,EAEX,aAAa,EAEb,cAAc,EAEf,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAMlD,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAE/D,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,SAAS,cAAc,EAAE,CAAA;CAAE,GACvD;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAuGrD,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CAQ9E;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,aAAa,CAK/D;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,GAAG,SAAS,MAAM,EAAE,CAQhF;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,GAAG,MAAM,CAEpE;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,UAAU,CACxB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACzC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,uBAAuB,GAAG,kBAAkB,CAAC,GACtE,OAAO,CAKT;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAE1D;AAqCD,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,cAAc,CAwDhB;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,aAAa,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC;IAEjF,IAAI,EAAE,UAAU;IAChB,QAAQ;IACR,IAAI;IACJ,MAAM;QAAI,IAAI;;EAEjB;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAM1B;AAeD,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3C,aAAa,CAiDf"}
|
package/dist/write.js
CHANGED
|
@@ -2,270 +2,208 @@ import { sha256Hex, textBytes } from './digest.js';
|
|
|
2
2
|
import { nativePath, roomLocalPath } from './map.js';
|
|
3
3
|
import { classifyDoor, doorRefusal, scopedRefusal } from './refusal.js';
|
|
4
4
|
import { readPosition, roomVersion } from './version.js';
|
|
5
|
-
export const INLINE_BODY_LIMIT_BYTES = 4 * 1024 * 1024;
|
|
6
|
-
export const UPLOAD_LINE_BYTES = 37;
|
|
7
|
-
export const UPLOAD_BYTES_MAX = 32 * 1024 * 1024 - UPLOAD_LINE_BYTES;
|
|
8
5
|
function priorField(batch, path, name) {
|
|
9
|
-
return batch.preconditions.find((precondition)=>precondition.kind === 'field' && precondition.path === path && precondition.name === name);
|
|
6
|
+
return batch.preconditions.find((precondition) => precondition.kind === 'field' && precondition.path === path && precondition.name === name);
|
|
10
7
|
}
|
|
11
8
|
function priorSection(batch, path, name) {
|
|
12
|
-
return batch.preconditions.find((precondition)=>precondition.kind === 'section' && precondition.path === path && precondition.name === name);
|
|
9
|
+
return batch.preconditions.find((precondition) => precondition.kind === 'section' && precondition.path === path && precondition.name === name);
|
|
13
10
|
}
|
|
14
11
|
function priorPreamble(batch, path) {
|
|
15
|
-
return batch.preconditions.find((precondition)=>precondition.kind === 'preamble' && precondition.path === path);
|
|
12
|
+
return batch.preconditions.find((precondition) => precondition.kind === 'preamble' && precondition.path === path);
|
|
16
13
|
}
|
|
17
14
|
function priorAbsence(batch, path) {
|
|
18
|
-
return batch.preconditions.find((precondition)=>precondition.kind === 'absent' && precondition.path === path);
|
|
15
|
+
return batch.preconditions.find((precondition) => precondition.kind === 'absent' && precondition.path === path);
|
|
19
16
|
}
|
|
20
17
|
function priorExistence(batch, path) {
|
|
21
|
-
const precondition = batch.preconditions.find((held)=>held.path === path && (held.kind === 'revision' || held.kind === 'present'));
|
|
22
|
-
if (precondition === undefined)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
} : {
|
|
26
|
-
kind: 'presence'
|
|
27
|
-
};
|
|
18
|
+
const precondition = batch.preconditions.find((held) => held.path === path && (held.kind === 'revision' || held.kind === 'present'));
|
|
19
|
+
if (precondition === undefined)
|
|
20
|
+
return undefined;
|
|
21
|
+
return precondition.kind === 'revision' ? { base: precondition.revision } : { kind: 'presence' };
|
|
28
22
|
}
|
|
29
|
-
function
|
|
23
|
+
function created(change, path) {
|
|
24
|
+
if ('content' in change)
|
|
25
|
+
return { op: 'create', path, content: change.content };
|
|
30
26
|
const { type, ...fields } = change.fields;
|
|
31
|
-
if (typeof type !== 'string' || type.length === 0)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
path,
|
|
35
|
-
type,
|
|
36
|
-
fields,
|
|
37
|
-
sections: change.sections
|
|
38
|
-
};
|
|
27
|
+
if (typeof type !== 'string' || type.length === 0)
|
|
28
|
+
return null;
|
|
29
|
+
return { op: 'create_typed', path, type, fields, sections: change.sections };
|
|
39
30
|
}
|
|
40
31
|
function operationOf(batch, change, handle) {
|
|
41
32
|
const path = nativePath(change.path, handle);
|
|
42
33
|
if (change.kind === 'field') {
|
|
43
34
|
const prior = priorField(batch, change.path, change.name);
|
|
44
|
-
if (prior === undefined)
|
|
45
|
-
rule: 'precondition-missing'
|
|
46
|
-
};
|
|
35
|
+
if (prior === undefined)
|
|
36
|
+
return { rule: 'precondition-missing' };
|
|
47
37
|
return {
|
|
48
38
|
operation: {
|
|
49
39
|
op: 'set_field',
|
|
50
40
|
path,
|
|
51
41
|
field: change.name,
|
|
52
42
|
value: change.value,
|
|
53
|
-
...prior.value === undefined ? {} : {
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
}
|
|
43
|
+
...(prior.value === undefined ? {} : { base: prior.value }),
|
|
44
|
+
},
|
|
57
45
|
};
|
|
58
46
|
}
|
|
59
47
|
if (change.kind === 'section') {
|
|
60
48
|
const prior = priorSection(batch, change.path, change.name);
|
|
61
|
-
if (prior === undefined)
|
|
62
|
-
rule: 'precondition-missing'
|
|
63
|
-
};
|
|
49
|
+
if (prior === undefined)
|
|
50
|
+
return { rule: 'precondition-missing' };
|
|
64
51
|
return {
|
|
65
52
|
operation: {
|
|
66
53
|
op: 'replace_section',
|
|
67
54
|
path,
|
|
68
55
|
section: change.name,
|
|
69
56
|
base: prior.value,
|
|
70
|
-
content: change.value
|
|
71
|
-
}
|
|
57
|
+
content: change.value,
|
|
58
|
+
},
|
|
72
59
|
};
|
|
73
60
|
}
|
|
74
61
|
if (change.kind === 'preamble') {
|
|
75
62
|
const prior = priorPreamble(batch, change.path);
|
|
76
|
-
if (prior === undefined)
|
|
77
|
-
rule: 'precondition-missing'
|
|
78
|
-
};
|
|
63
|
+
if (prior === undefined)
|
|
64
|
+
return { rule: 'precondition-missing' };
|
|
79
65
|
return {
|
|
80
|
-
operation: {
|
|
81
|
-
op: 'replace_preamble',
|
|
82
|
-
path,
|
|
83
|
-
base: prior.value,
|
|
84
|
-
content: change.value
|
|
85
|
-
}
|
|
66
|
+
operation: { op: 'replace_preamble', path, base: prior.value, content: change.value },
|
|
86
67
|
};
|
|
87
68
|
}
|
|
88
69
|
if (change.kind === 'create') {
|
|
89
|
-
if (priorAbsence(batch, change.path) === undefined)
|
|
90
|
-
rule: 'precondition-missing'
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return created === null ? {
|
|
94
|
-
rule: 'type-missing'
|
|
95
|
-
} : {
|
|
96
|
-
operation: created
|
|
97
|
-
};
|
|
70
|
+
if (priorAbsence(batch, change.path) === undefined)
|
|
71
|
+
return { rule: 'precondition-missing' };
|
|
72
|
+
const operation = created(change, path);
|
|
73
|
+
return operation === null ? { rule: 'type-missing' } : { operation };
|
|
98
74
|
}
|
|
99
75
|
const existence = priorExistence(batch, change.path);
|
|
100
|
-
if (existence === undefined)
|
|
101
|
-
rule: 'precondition-missing'
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
rule: 'presence-base-unrepresentable'
|
|
105
|
-
};
|
|
76
|
+
if (existence === undefined)
|
|
77
|
+
return { rule: 'precondition-missing' };
|
|
78
|
+
if (!('base' in existence))
|
|
79
|
+
return { rule: 'presence-base-unrepresentable' };
|
|
106
80
|
if (change.kind === 'replace') {
|
|
107
|
-
return {
|
|
108
|
-
operation: {
|
|
109
|
-
op: 'replace',
|
|
110
|
-
path,
|
|
111
|
-
base: existence.base,
|
|
112
|
-
content: change.content
|
|
113
|
-
}
|
|
114
|
-
};
|
|
81
|
+
return { operation: { op: 'replace', path, base: existence.base, content: change.content } };
|
|
115
82
|
}
|
|
116
83
|
if (change.kind === 'move') {
|
|
117
|
-
if (priorAbsence(batch, change.to) === undefined)
|
|
118
|
-
rule: 'precondition-missing'
|
|
119
|
-
};
|
|
84
|
+
if (priorAbsence(batch, change.to) === undefined)
|
|
85
|
+
return { rule: 'precondition-missing' };
|
|
120
86
|
return {
|
|
121
|
-
operation: {
|
|
122
|
-
op: 'rename',
|
|
123
|
-
path,
|
|
124
|
-
to: nativePath(change.to, handle),
|
|
125
|
-
base: existence.base
|
|
126
|
-
}
|
|
87
|
+
operation: { op: 'rename', path, to: nativePath(change.to, handle), base: existence.base },
|
|
127
88
|
};
|
|
128
89
|
}
|
|
129
|
-
return {
|
|
130
|
-
operation: {
|
|
131
|
-
op: 'remove',
|
|
132
|
-
path,
|
|
133
|
-
base: existence.base
|
|
134
|
-
}
|
|
135
|
-
};
|
|
90
|
+
return { operation: { op: 'remove', path, base: existence.base } };
|
|
136
91
|
}
|
|
137
92
|
export function houseChanges(batch, handle) {
|
|
138
93
|
const changes = [];
|
|
139
|
-
for (const change of batch.changes){
|
|
94
|
+
for (const change of batch.changes) {
|
|
140
95
|
const mapped = operationOf(batch, change, handle);
|
|
141
|
-
if ('rule' in mapped)
|
|
142
|
-
kind: 'unmapped',
|
|
143
|
-
path: change.path,
|
|
144
|
-
rule: mapped.rule
|
|
145
|
-
};
|
|
96
|
+
if ('rule' in mapped)
|
|
97
|
+
return { kind: 'unmapped', path: change.path, rule: mapped.rule };
|
|
146
98
|
changes.push(mapped.operation);
|
|
147
99
|
}
|
|
148
|
-
return {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
100
|
+
return { kind: 'changes', changes };
|
|
101
|
+
}
|
|
102
|
+
export function operationHead(batch) {
|
|
103
|
+
const writer = batch.writtenBy;
|
|
104
|
+
return writer === undefined
|
|
105
|
+
? { operation_id: batch.id }
|
|
106
|
+
: { operation_id: batch.id, app_ref: writer.app, release: writer.release };
|
|
152
107
|
}
|
|
153
108
|
export function batchPaths(changes) {
|
|
154
109
|
return [
|
|
155
|
-
...new Set(changes.flatMap((change)=>change.op === 'rename' ? [
|
|
156
|
-
String(change.path),
|
|
157
|
-
String(change.to)
|
|
158
|
-
] : [
|
|
159
|
-
String(change.path)
|
|
160
|
-
]))
|
|
110
|
+
...new Set(changes.flatMap((change) => change.op === 'rename' ? [String(change.path), String(change.to)] : [String(change.path)])),
|
|
161
111
|
].sort();
|
|
162
112
|
}
|
|
163
113
|
export function deltaBody(changes) {
|
|
164
|
-
return JSON.stringify({
|
|
165
|
-
changes
|
|
166
|
-
});
|
|
114
|
+
return JSON.stringify({ changes });
|
|
167
115
|
}
|
|
168
116
|
export function deltaBytes(delta) {
|
|
169
117
|
return textBytes(delta);
|
|
170
118
|
}
|
|
171
|
-
export function uploadable(bytes) {
|
|
172
|
-
return
|
|
119
|
+
export function uploadable(inline, bytes, bounds) {
|
|
120
|
+
return (textBytes(JSON.stringify(inline)) > bounds.max_inline_body_bytes &&
|
|
121
|
+
bytes <= bounds.max_upload_bytes);
|
|
173
122
|
}
|
|
174
123
|
export function deltaDigest(delta) {
|
|
175
124
|
return sha256Hex(delta);
|
|
176
125
|
}
|
|
177
126
|
function material(value, handle) {
|
|
178
|
-
if (!Array.isArray(value))
|
|
127
|
+
if (!Array.isArray(value))
|
|
128
|
+
return null;
|
|
179
129
|
const held = [];
|
|
180
|
-
for (const entry of value){
|
|
181
|
-
if (typeof entry !== 'object' || entry === null)
|
|
130
|
+
for (const entry of value) {
|
|
131
|
+
if (typeof entry !== 'object' || entry === null)
|
|
132
|
+
return null;
|
|
182
133
|
const file = entry;
|
|
183
|
-
if (typeof file.path !== 'string')
|
|
184
|
-
|
|
185
|
-
if (file.
|
|
134
|
+
if (typeof file.path !== 'string')
|
|
135
|
+
return null;
|
|
136
|
+
if (file.content !== null && typeof file.content !== 'string')
|
|
137
|
+
return null;
|
|
138
|
+
if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string')
|
|
139
|
+
return null;
|
|
186
140
|
let path;
|
|
187
141
|
try {
|
|
188
142
|
path = roomLocalPath(file.path, handle);
|
|
189
|
-
}
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
190
145
|
return null;
|
|
191
146
|
}
|
|
192
147
|
held.push({
|
|
193
148
|
path,
|
|
194
149
|
content: file.content,
|
|
195
|
-
revision: typeof file.revision === 'string' ? file.revision : null
|
|
150
|
+
revision: typeof file.revision === 'string' ? file.revision : null,
|
|
196
151
|
});
|
|
197
152
|
}
|
|
198
153
|
return held;
|
|
199
154
|
}
|
|
200
155
|
function affectedOf(held) {
|
|
201
156
|
const affected = {};
|
|
202
|
-
for (const entry of held){
|
|
203
|
-
if (entry.content !== null)
|
|
157
|
+
for (const entry of held) {
|
|
158
|
+
if (entry.content !== null)
|
|
159
|
+
affected[entry.path] = entry.content;
|
|
204
160
|
}
|
|
205
161
|
return affected;
|
|
206
162
|
}
|
|
207
163
|
export function mutationOutcome(status, body, locator, handle) {
|
|
208
164
|
const refusal = doorRefusal(body);
|
|
209
|
-
if (refusal !== null && refusal.code === '
|
|
210
|
-
|
|
211
|
-
return {
|
|
212
|
-
kind: 'retryable-refusal',
|
|
213
|
-
code: refusal.code,
|
|
214
|
-
fields: refusal.fields,
|
|
215
|
-
...typeof reset === 'string' ? {
|
|
216
|
-
reset
|
|
217
|
-
} : {}
|
|
218
|
-
};
|
|
165
|
+
if (refusal !== null && refusal.code === 'service_mode_write_halted') {
|
|
166
|
+
return { kind: 'write-halted' };
|
|
219
167
|
}
|
|
220
|
-
if (refusal !== null && refusal.code === 'operation_expired')
|
|
221
|
-
kind: 'expired'
|
|
222
|
-
};
|
|
168
|
+
if (refusal !== null && refusal.code === 'operation_expired')
|
|
169
|
+
return { kind: 'expired' };
|
|
223
170
|
if (refusal !== null && refusal.code === 'edit_conflict') {
|
|
224
171
|
const { current, ...fields } = refusal.fields;
|
|
225
172
|
const held = material(current, handle) ?? [];
|
|
226
|
-
return {
|
|
227
|
-
kind: 'conflicted',
|
|
228
|
-
affected: affectedOf(held),
|
|
229
|
-
code: refusal.code,
|
|
230
|
-
fields
|
|
231
|
-
};
|
|
173
|
+
return { kind: 'conflicted', affected: affectedOf(held), code: refusal.code, fields };
|
|
232
174
|
}
|
|
233
175
|
if (refusal !== null && status === 404) {
|
|
234
176
|
return scopedRefusal(locator, 'undisclosed', refusal);
|
|
235
177
|
}
|
|
236
178
|
const classified = classifyDoor(status, body, locator);
|
|
179
|
+
const reset = refusal?.fields.retry_at;
|
|
180
|
+
if (refusal?.retryable === true &&
|
|
181
|
+
typeof reset === 'string' &&
|
|
182
|
+
classified?.kind === 'transport-uncertainty') {
|
|
183
|
+
return { kind: 'retryable-refusal', code: refusal.code, fields: refusal.fields, reset };
|
|
184
|
+
}
|
|
237
185
|
if (classified !== null && classified.kind !== 'scoped-refusal') {
|
|
238
|
-
return classified.kind === 'beyond-horizon' ? {
|
|
239
|
-
kind: 'expired'
|
|
240
|
-
} : classified;
|
|
186
|
+
return classified.kind === 'beyond-horizon' ? { kind: 'expired' } : classified;
|
|
241
187
|
}
|
|
242
|
-
if (classified !== null && status === 403)
|
|
188
|
+
if (classified !== null && status === 403)
|
|
189
|
+
return classified;
|
|
243
190
|
if (refusal !== null && status >= 400) {
|
|
244
|
-
return {
|
|
245
|
-
kind: 'rejected',
|
|
246
|
-
affected: {},
|
|
247
|
-
code: refusal.code,
|
|
248
|
-
fields: refusal.fields
|
|
249
|
-
};
|
|
191
|
+
return { kind: 'rejected', affected: {}, code: refusal.code, fields: refusal.fields };
|
|
250
192
|
}
|
|
251
193
|
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
252
|
-
return {
|
|
253
|
-
kind: 'transport-uncertainty'
|
|
254
|
-
};
|
|
194
|
+
return { kind: 'transport-uncertainty' };
|
|
255
195
|
}
|
|
256
196
|
const held = body;
|
|
257
197
|
const at = readPosition(held);
|
|
258
|
-
if (at === null)
|
|
259
|
-
kind: 'transport-uncertainty'
|
|
260
|
-
};
|
|
198
|
+
if (at === null)
|
|
199
|
+
return { kind: 'transport-uncertainty' };
|
|
261
200
|
const contents = material(held.contents, handle);
|
|
262
|
-
if (contents === null)
|
|
263
|
-
kind: 'transport-uncertainty'
|
|
264
|
-
};
|
|
201
|
+
if (contents === null)
|
|
202
|
+
return { kind: 'transport-uncertainty' };
|
|
265
203
|
const documents = {};
|
|
266
204
|
const revisions = {};
|
|
267
205
|
const removals = [];
|
|
268
|
-
for (const entry of contents){
|
|
206
|
+
for (const entry of contents) {
|
|
269
207
|
if (entry.content === null || entry.revision === null) {
|
|
270
208
|
removals.push(entry.path);
|
|
271
209
|
continue;
|
|
@@ -278,7 +216,7 @@ export function mutationOutcome(status, body, locator, handle) {
|
|
|
278
216
|
roomVersion: roomVersion(at),
|
|
279
217
|
documents,
|
|
280
218
|
revisions,
|
|
281
|
-
removals: removals.sort()
|
|
219
|
+
removals: removals.sort(),
|
|
282
220
|
};
|
|
283
221
|
}
|
|
284
222
|
export function rejectedMapping(mapping) {
|
|
@@ -286,94 +224,78 @@ export function rejectedMapping(mapping) {
|
|
|
286
224
|
kind: 'rejected',
|
|
287
225
|
affected: {},
|
|
288
226
|
code: mapping.rule,
|
|
289
|
-
fields: {
|
|
290
|
-
path: mapping.path
|
|
291
|
-
}
|
|
227
|
+
fields: { path: mapping.path },
|
|
292
228
|
};
|
|
293
229
|
}
|
|
294
230
|
export function revisionBody(input) {
|
|
295
231
|
return {
|
|
296
232
|
path: nativePath(input.path, input.handle),
|
|
297
|
-
...input.revision === undefined ? {} : {
|
|
298
|
-
|
|
299
|
-
},
|
|
300
|
-
...input.pageToken === undefined ? {} : {
|
|
301
|
-
before: Number(input.pageToken)
|
|
302
|
-
}
|
|
233
|
+
...(input.revision === undefined ? {} : { revision: input.revision }),
|
|
234
|
+
...(input.pageToken === undefined ? {} : { before: Number(input.pageToken) }),
|
|
303
235
|
};
|
|
304
236
|
}
|
|
237
|
+
function revisionAuthor(entry) {
|
|
238
|
+
const user = entry.author_user;
|
|
239
|
+
const site = entry.author_site;
|
|
240
|
+
const name = entry.author_site_name;
|
|
241
|
+
if (typeof user === 'string' && site === undefined && name === undefined) {
|
|
242
|
+
return { kind: 'user', id: user };
|
|
243
|
+
}
|
|
244
|
+
if (user === null && typeof site === 'string' && typeof name === 'string') {
|
|
245
|
+
return { kind: 'site', id: site, name };
|
|
246
|
+
}
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
305
249
|
export function historyOutcome(status, body, locator, request) {
|
|
306
250
|
const classified = classifyDoor(status, body, locator);
|
|
307
251
|
if (classified !== null) {
|
|
308
|
-
return classified.kind === 'beyond-horizon' ? {
|
|
309
|
-
kind: 'transport-uncertainty'
|
|
310
|
-
} : classified;
|
|
252
|
+
return classified.kind === 'beyond-horizon' ? { kind: 'transport-uncertainty' } : classified;
|
|
311
253
|
}
|
|
312
254
|
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
313
|
-
return {
|
|
314
|
-
kind: 'transport-uncertainty'
|
|
315
|
-
};
|
|
255
|
+
return { kind: 'transport-uncertainty' };
|
|
316
256
|
}
|
|
317
257
|
const held = body;
|
|
318
|
-
if (!Array.isArray(held.revisions))
|
|
319
|
-
kind: 'transport-uncertainty'
|
|
320
|
-
};
|
|
258
|
+
if (!Array.isArray(held.revisions))
|
|
259
|
+
return { kind: 'transport-uncertainty' };
|
|
321
260
|
const entries = [];
|
|
322
|
-
for (const entry of held.revisions){
|
|
323
|
-
if (typeof entry !== 'object' || entry === null)
|
|
324
|
-
kind: 'transport-uncertainty'
|
|
325
|
-
};
|
|
261
|
+
for (const entry of held.revisions) {
|
|
262
|
+
if (typeof entry !== 'object' || entry === null)
|
|
263
|
+
return { kind: 'transport-uncertainty' };
|
|
326
264
|
entries.push(entry);
|
|
327
265
|
}
|
|
328
266
|
if (request.revision !== undefined) {
|
|
329
267
|
const named = entries[0];
|
|
330
|
-
if (named === undefined)
|
|
331
|
-
kind: 'no-history'
|
|
332
|
-
};
|
|
268
|
+
if (named === undefined)
|
|
269
|
+
return { kind: 'no-history' };
|
|
333
270
|
if (named.unavailable === true) {
|
|
334
271
|
return {
|
|
335
272
|
kind: 'scoped-refusal',
|
|
336
273
|
locator,
|
|
337
274
|
scope: 'content',
|
|
338
275
|
code: 'retained_history_unavailable',
|
|
339
|
-
fields: {
|
|
340
|
-
path: request.path,
|
|
341
|
-
revision: request.revision
|
|
342
|
-
}
|
|
276
|
+
fields: { path: request.path, revision: request.revision },
|
|
343
277
|
};
|
|
344
278
|
}
|
|
345
|
-
if (typeof named.content !== 'string')
|
|
346
|
-
kind: 'transport-uncertainty'
|
|
347
|
-
};
|
|
348
|
-
return {
|
|
349
|
-
kind: 'revision',
|
|
350
|
-
content: named.content
|
|
351
|
-
};
|
|
279
|
+
if (typeof named.content !== 'string')
|
|
280
|
+
return { kind: 'transport-uncertainty' };
|
|
281
|
+
return { kind: 'revision', content: named.content };
|
|
352
282
|
}
|
|
353
|
-
if (entries.length === 0)
|
|
354
|
-
kind: 'no-history'
|
|
355
|
-
};
|
|
283
|
+
if (entries.length === 0)
|
|
284
|
+
return { kind: 'no-history' };
|
|
356
285
|
const revisions = [];
|
|
357
|
-
for (const entry of entries){
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
286
|
+
for (const entry of entries) {
|
|
287
|
+
const author = revisionAuthor(entry);
|
|
288
|
+
if (typeof entry.revision !== 'string' ||
|
|
289
|
+
author === null ||
|
|
290
|
+
typeof entry.created_at !== 'string') {
|
|
291
|
+
return { kind: 'transport-uncertainty' };
|
|
362
292
|
}
|
|
363
|
-
revisions.push({
|
|
364
|
-
revision: entry.revision,
|
|
365
|
-
author: entry.author_user,
|
|
366
|
-
time: entry.created_at
|
|
367
|
-
});
|
|
293
|
+
revisions.push({ revision: entry.revision, author, time: entry.created_at });
|
|
368
294
|
}
|
|
369
295
|
const next = held.next_before;
|
|
370
296
|
return {
|
|
371
297
|
kind: 'history',
|
|
372
298
|
revisions,
|
|
373
|
-
...typeof next === 'number' ? {
|
|
374
|
-
pageToken: String(next)
|
|
375
|
-
} : {}
|
|
299
|
+
...(typeof next === 'number' ? { pageToken: String(next) } : {}),
|
|
376
300
|
};
|
|
377
301
|
}
|
|
378
|
-
|
|
379
|
-
//# sourceMappingURL=write.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/mdruntime-adapter",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-c17fae3d012d0",
|
|
4
4
|
"description": "Agents House Adapter for the MD Runtime",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -21,19 +21,11 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"dist",
|
|
23
23
|
"AGENTS.md",
|
|
24
|
+
"README.md",
|
|
24
25
|
"LICENSE"
|
|
25
26
|
],
|
|
26
|
-
"repository": {
|
|
27
|
-
"type": "git",
|
|
28
|
-
"url": "git+https://github.com/agentshouse/mdruntime.git",
|
|
29
|
-
"directory": "packages/mdruntime-adapter"
|
|
30
|
-
},
|
|
31
|
-
"homepage": "https://github.com/agentshouse/mdruntime#readme",
|
|
32
|
-
"bugs": {
|
|
33
|
-
"url": "https://github.com/agentshouse/mdruntime/issues"
|
|
34
|
-
},
|
|
35
27
|
"dependencies": {
|
|
36
|
-
"@agentshouse/mdmodel": "0.1.0-
|
|
37
|
-
"@agentshouse/mdruntime": "0.1.0-
|
|
28
|
+
"@agentshouse/mdmodel": "0.1.0-ce804f6363a19",
|
|
29
|
+
"@agentshouse/mdruntime": "0.1.0-ce531b51ff088"
|
|
38
30
|
}
|
|
39
31
|
}
|