@agentshouse/mdruntime-adapter 0.1.0-alpha.8 → 0.1.0-c6ddfd288ac81
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 +157 -26
- 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 +257 -194
- package/dist/digest.js +1 -5
- package/dist/discovery.d.ts +20 -18
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +182 -210
- 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 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -2
- package/dist/links.d.ts +11 -0
- package/dist/links.d.ts.map +1 -0
- package/dist/links.js +51 -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 +29 -23
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +222 -195
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +30 -51
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +108 -124
- package/dist/stream.d.ts +9 -5
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +186 -203
- package/dist/transport.d.ts +45 -28
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +3 -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 +9 -3
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +123 -196
- 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/site.js
CHANGED
|
@@ -1,40 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { actionOutcome } from './actions.js';
|
|
2
|
+
import { UNTYPED_FOLDERS, mapDiscovery, parseSiteDiscovery, siteCapabilities, siteSlots, siteTracked, } from './discovery.js';
|
|
3
|
+
import { MODEL_ABSENT, failedModel, heldModel, modelKey, modelShelf, } from './model.js';
|
|
4
|
+
import { advancedScope, bootstrapOf, parseEnumeration, parseSiteBootstrap, refreshFrom, schemaOf, schemaPath, viewOf, } from './read.js';
|
|
5
|
+
import { classifyDoor, discoveryFailure, doorRefusal } from './refusal.js';
|
|
5
6
|
import { houseNotifications } from './stream.js';
|
|
6
|
-
import {
|
|
7
|
-
import { logPosition, presented, roomVersion } from './version.js';
|
|
8
|
-
const UNCERTAIN = {
|
|
9
|
-
kind: 'transport-uncertainty'
|
|
10
|
-
};
|
|
7
|
+
import { PRIVATE_LOCATOR, SITE_DOOR_BOOTSTRAP, SITE_DOOR_DISCOVER, SITE_DOOR_ENUMERATE, SITE_DOOR_SUBMIT, } from './transport.js';
|
|
8
|
+
import { logPosition, presented, reachedVersion, roomVersion, } from './version.js';
|
|
9
|
+
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
11
10
|
function siteRoom(tracked, attachedModel) {
|
|
12
|
-
const read = selectionRoots(tracked);
|
|
13
11
|
return {
|
|
14
|
-
name: tracked.
|
|
12
|
+
name: tracked.handle,
|
|
15
13
|
locator: tracked.locator,
|
|
16
|
-
collectionRoot: tracked.collectionRoot,
|
|
17
14
|
roomVersion: roomVersion(tracked),
|
|
18
|
-
operations: {
|
|
19
|
-
|
|
20
|
-
...read
|
|
21
|
-
],
|
|
22
|
-
sync: [
|
|
23
|
-
...read
|
|
24
|
-
],
|
|
25
|
-
write: [],
|
|
26
|
-
delete: []
|
|
27
|
-
},
|
|
28
|
-
replica: {
|
|
29
|
-
selection: tracked.locator,
|
|
30
|
-
admission: 'admitted'
|
|
31
|
-
},
|
|
15
|
+
operations: { read: [''], sync: [''], write: [], delete: [] },
|
|
16
|
+
replica: { selection: tracked.locator, admission: 'admitted' },
|
|
32
17
|
attachedModel,
|
|
33
|
-
|
|
18
|
+
untypedFolders: [...UNTYPED_FOLDERS],
|
|
19
|
+
providerOwnedPaths: [],
|
|
34
20
|
};
|
|
35
21
|
}
|
|
36
22
|
function settled(refused) {
|
|
37
|
-
return refused.kind === 'beyond-horizon'
|
|
23
|
+
return refused.kind === 'beyond-horizon' || refused.kind === 'retryable-refusal'
|
|
24
|
+
? UNCERTAIN
|
|
25
|
+
: refused;
|
|
38
26
|
}
|
|
39
27
|
export function createSiteAdapter(transport) {
|
|
40
28
|
const notifications = houseNotifications(transport, 'site');
|
|
@@ -44,92 +32,84 @@ export function createSiteAdapter(transport) {
|
|
|
44
32
|
let caught = new Map();
|
|
45
33
|
async function enumeration(entry, from) {
|
|
46
34
|
const answer = await transport.door(SITE_DOOR_ENUMERATE, {
|
|
47
|
-
positions: [
|
|
48
|
-
presented(entry.authority, from)
|
|
49
|
-
]
|
|
35
|
+
positions: [presented(entry.authority, from)],
|
|
50
36
|
});
|
|
37
|
+
const behind = doorRefusal(answer.body);
|
|
38
|
+
if (behind?.code === 'replica_behind')
|
|
39
|
+
return { kind: 'retryable-refusal', ...behind };
|
|
51
40
|
const classified = classifyDoor(answer.status, answer.body, entry.locator);
|
|
52
|
-
if (classified !== null)
|
|
41
|
+
if (classified !== null)
|
|
42
|
+
return classified;
|
|
53
43
|
return parseEnumeration(answer.body, 'site') ?? UNCERTAIN;
|
|
54
44
|
}
|
|
55
45
|
async function caughtUp(entry) {
|
|
56
46
|
const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}`);
|
|
57
47
|
const classified = classifyDoor(answer.status, answer.body, entry.locator);
|
|
58
|
-
if (classified !== null)
|
|
59
|
-
failure: settled(classified)
|
|
60
|
-
};
|
|
48
|
+
if (classified !== null)
|
|
49
|
+
return { failure: settled(classified) };
|
|
61
50
|
const scope = parseSiteBootstrap(answer.body);
|
|
62
|
-
if (scope === null)
|
|
63
|
-
failure: UNCERTAIN
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
scope
|
|
67
|
-
};
|
|
51
|
+
if (scope === null)
|
|
52
|
+
return { failure: UNCERTAIN };
|
|
53
|
+
if (roomVersion(scope) === roomVersion(entry))
|
|
54
|
+
return { scope };
|
|
68
55
|
const found = await enumeration(entry, scope);
|
|
69
|
-
if ('kind' in found)
|
|
70
|
-
failure: settled(found)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
kind: 'room-not-readable',
|
|
76
|
-
locator: entry.locator
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
return {
|
|
80
|
-
scope: advancedScope(scope, view)
|
|
81
|
-
};
|
|
56
|
+
if ('kind' in found)
|
|
57
|
+
return { failure: settled(found) };
|
|
58
|
+
const view = viewOf(found, entry);
|
|
59
|
+
if (view === undefined)
|
|
60
|
+
return { failure: { kind: 'room-not-readable', locator: entry.locator } };
|
|
61
|
+
return { scope: advancedScope(scope, view) };
|
|
82
62
|
}
|
|
83
63
|
async function refreshed(entry, fromRoomVersion) {
|
|
84
64
|
const from = logPosition(fromRoomVersion);
|
|
85
|
-
if (from === null)
|
|
86
|
-
kind: 'beyond-horizon'
|
|
87
|
-
};
|
|
65
|
+
if (from === null)
|
|
66
|
+
return { kind: 'beyond-horizon' };
|
|
88
67
|
const streamed = notifications.advance(entry, from);
|
|
89
|
-
if (streamed !== null)
|
|
68
|
+
if (streamed !== null)
|
|
69
|
+
return streamed.page;
|
|
90
70
|
const found = await enumeration(entry, from);
|
|
91
|
-
if ('kind' in found)
|
|
92
|
-
|
|
71
|
+
if ('kind' in found)
|
|
72
|
+
return found;
|
|
73
|
+
const view = viewOf(found, entry);
|
|
74
|
+
if (view === undefined)
|
|
75
|
+
return { kind: 'room-not-readable', locator: entry.locator };
|
|
76
|
+
return refreshFrom(view, entry, fromRoomVersion);
|
|
93
77
|
}
|
|
94
78
|
async function acquire(entry, held) {
|
|
95
|
-
if ('failure' in held)
|
|
96
|
-
snapshot: failedModel(held.failure),
|
|
97
|
-
|
|
98
|
-
};
|
|
99
|
-
const model = await heldModel(definitionsOf(held.scope, entry.modelRoot), `${authorityRoot(entry.handle)}/${entry.modelRoot}`, MODEL_ABSENT);
|
|
100
|
-
acquired.set(entry.authority, {
|
|
101
|
-
roomVersion: roomVersion(held.scope),
|
|
102
|
-
model
|
|
103
|
-
});
|
|
79
|
+
if ('failure' in held)
|
|
80
|
+
return { snapshot: failedModel(held.failure), identity: null };
|
|
81
|
+
const model = await heldModel(schemaOf(held.scope, entry.schema), schemaPath(entry.handle, entry.schema), MODEL_ABSENT);
|
|
82
|
+
acquired.set(entry.authority, { roomVersion: roomVersion(held.scope), model });
|
|
104
83
|
return model;
|
|
105
84
|
}
|
|
106
85
|
return {
|
|
107
|
-
async authorize
|
|
86
|
+
async authorize() {
|
|
108
87
|
return {};
|
|
109
88
|
},
|
|
110
|
-
async model
|
|
89
|
+
async model(_authorization, request) {
|
|
111
90
|
return models.answer(request);
|
|
112
91
|
},
|
|
113
|
-
async discover
|
|
114
|
-
const answer = await transport.
|
|
115
|
-
const classified = classifyDoor(answer.status, answer.body,
|
|
116
|
-
if (classified !== null)
|
|
92
|
+
async discover() {
|
|
93
|
+
const answer = await transport.read(SITE_DOOR_DISCOVER);
|
|
94
|
+
const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);
|
|
95
|
+
if (classified !== null)
|
|
96
|
+
return discoveryFailure(classified);
|
|
117
97
|
const document = parseSiteDiscovery(answer.body);
|
|
118
|
-
if (document === null)
|
|
98
|
+
if (document === null)
|
|
99
|
+
return UNCERTAIN;
|
|
119
100
|
const entries = siteTracked(document);
|
|
120
101
|
tracked.clear();
|
|
121
|
-
for (const entry of entries)
|
|
102
|
+
for (const entry of entries)
|
|
103
|
+
tracked.set(entry.locator, entry);
|
|
122
104
|
notifications.track(entries);
|
|
123
|
-
const published = new Set(entries.map((entry)=>entry.authority));
|
|
124
|
-
for (const authority of [
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (!published.has(authority)) acquired.delete(authority);
|
|
105
|
+
const published = new Set(entries.map((entry) => entry.authority));
|
|
106
|
+
for (const authority of [...acquired.keys()]) {
|
|
107
|
+
if (!published.has(authority))
|
|
108
|
+
acquired.delete(authority);
|
|
128
109
|
}
|
|
129
110
|
const fresh = new Map();
|
|
130
111
|
const current = new Map();
|
|
131
|
-
for (const entry of entries){
|
|
132
|
-
if (current.has(entry.authority)) continue;
|
|
112
|
+
for (const entry of entries) {
|
|
133
113
|
const kept = acquired.get(entry.authority);
|
|
134
114
|
if (kept !== undefined && kept.roomVersion === roomVersion(entry)) {
|
|
135
115
|
current.set(entry.authority, kept.model);
|
|
@@ -140,59 +120,63 @@ export function createSiteAdapter(transport) {
|
|
|
140
120
|
current.set(entry.authority, await acquire(entry, held));
|
|
141
121
|
}
|
|
142
122
|
caught = fresh;
|
|
143
|
-
const rooms = entries.map((entry)=>{
|
|
123
|
+
const rooms = entries.map((entry) => {
|
|
144
124
|
const shelved = models.retain(modelKey(entry.locator, 'collection'), current.get(entry.authority));
|
|
145
125
|
return siteRoom(entry, shelved?.identity ?? null);
|
|
146
126
|
});
|
|
147
|
-
models.keep(entries.map((entry)=>entry.locator));
|
|
148
|
-
return mapDiscovery(document, rooms, siteCapabilities());
|
|
127
|
+
models.keep(entries.map((entry) => entry.locator));
|
|
128
|
+
return { ...mapDiscovery(document, rooms, siteCapabilities()), slots: siteSlots(document) };
|
|
149
129
|
},
|
|
150
|
-
async bootstrap
|
|
130
|
+
async bootstrap(_authorization, request) {
|
|
151
131
|
const entry = tracked.get(request.locator);
|
|
152
|
-
if (entry === undefined)
|
|
153
|
-
kind: 'room-not-readable',
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
132
|
+
if (entry === undefined)
|
|
133
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
134
|
+
if (request.pageToken !== undefined)
|
|
135
|
+
return UNCERTAIN;
|
|
136
|
+
const held = caught.get(entry.authority) ?? (await caughtUp(entry));
|
|
137
|
+
if ('failure' in held)
|
|
138
|
+
return held.failure;
|
|
159
139
|
return bootstrapOf(held.scope, entry);
|
|
160
140
|
},
|
|
161
|
-
async refresh
|
|
141
|
+
async refresh(_authorization, request) {
|
|
162
142
|
const entry = tracked.get(request.locator);
|
|
163
|
-
if (entry === undefined)
|
|
164
|
-
kind: 'room-not-readable',
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (request.pageToken !== undefined) return UNCERTAIN;
|
|
143
|
+
if (entry === undefined)
|
|
144
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
145
|
+
if (request.pageToken !== undefined)
|
|
146
|
+
return UNCERTAIN;
|
|
168
147
|
const result = await refreshed(entry, request.fromRoomVersion);
|
|
169
|
-
if (result.kind === 'beyond-horizon')
|
|
148
|
+
if (result.kind === 'beyond-horizon')
|
|
149
|
+
caught.delete(entry.authority);
|
|
150
|
+
const answered = result.kind === 'net-advancement'
|
|
151
|
+
? result.roomVersion
|
|
152
|
+
: result.kind === 'still-current'
|
|
153
|
+
? request.fromRoomVersion
|
|
154
|
+
: null;
|
|
155
|
+
if (request.minPosition !== undefined &&
|
|
156
|
+
answered !== null &&
|
|
157
|
+
!reachedVersion(answered, request.minPosition, entry.logEpoch)) {
|
|
158
|
+
return { kind: 'retryable-refusal', code: 'replica_behind', fields: {} };
|
|
159
|
+
}
|
|
170
160
|
return result;
|
|
171
161
|
},
|
|
172
|
-
async mutate
|
|
173
|
-
return {
|
|
174
|
-
kind: 'rejected',
|
|
175
|
-
affected: {},
|
|
176
|
-
code: 'write-grant',
|
|
177
|
-
fields: {}
|
|
178
|
-
};
|
|
162
|
+
async mutate() {
|
|
163
|
+
return { kind: 'rejected', affected: {}, code: 'write-grant', fields: {} };
|
|
179
164
|
},
|
|
180
|
-
async history
|
|
181
|
-
return {
|
|
182
|
-
kind: 'no-history'
|
|
183
|
-
};
|
|
165
|
+
async history() {
|
|
166
|
+
return { kind: 'no-history' };
|
|
184
167
|
},
|
|
185
|
-
|
|
186
|
-
return
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
168
|
+
reached(locator, version, target) {
|
|
169
|
+
return reachedVersion(version, target, tracked.get(locator)?.logEpoch);
|
|
170
|
+
},
|
|
171
|
+
async action(_authorization, request) {
|
|
172
|
+
if (request.name !== 'submit') {
|
|
173
|
+
return { kind: 'rejected', code: 'action-unimplemented', fields: { name: request.name } };
|
|
174
|
+
}
|
|
175
|
+
if (!transport.online())
|
|
176
|
+
return UNCERTAIN;
|
|
177
|
+
return actionOutcome(await transport.door(SITE_DOOR_SUBMIT, request.input), 'submit');
|
|
193
178
|
},
|
|
194
|
-
roomVersions: notifications
|
|
179
|
+
roomVersions: notifications,
|
|
180
|
+
serviceMode: notifications.serviceMode,
|
|
195
181
|
};
|
|
196
182
|
}
|
|
197
|
-
|
|
198
|
-
//# sourceMappingURL=site.js.map
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import type { RefreshPage, SelectedRooms,
|
|
1
|
+
import type { ConversationStream, RefreshPage, SelectedRooms, ServiceModeSignal } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
-
import {
|
|
4
|
-
import type { HouseMode } from './transport.js';
|
|
3
|
+
import type { HouseDoor, HouseMode, HouseStreamEntry } from './transport.js';
|
|
5
4
|
import { type LogPosition } from './version.js';
|
|
5
|
+
export type StreamedAdvancement = {
|
|
6
|
+
page: RefreshPage;
|
|
7
|
+
entries: readonly HouseStreamEntry[];
|
|
8
|
+
};
|
|
6
9
|
export type HouseNotifications = SelectedRooms & {
|
|
7
10
|
track(authorities: readonly TrackedAuthority[]): void;
|
|
8
|
-
advance(tracked: TrackedAuthority, from: LogPosition):
|
|
9
|
-
conversations:
|
|
11
|
+
advance(tracked: TrackedAuthority, from: LogPosition): StreamedAdvancement | null;
|
|
12
|
+
conversations: ConversationStream;
|
|
13
|
+
serviceMode: ServiceModeSignal;
|
|
10
14
|
};
|
|
11
15
|
export declare function houseNotifications(transport: HouseDoor, mode: HouseMode): HouseNotifications;
|
|
12
16
|
//# sourceMappingURL=stream.d.ts.map
|
package/dist/stream.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,WAAW,EAEX,aAAa,
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAClB,WAAW,EAEX,aAAa,EAEb,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,gBAAgB,EAAoB,MAAM,gBAAgB,CAAC;AAC/F,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAc7D,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,SAAS,gBAAgB,EAAE,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,aAAa,GAAG;IAC/C,KAAK,CAAC,WAAW,EAAE,SAAS,gBAAgB,EAAE,GAAG,IAAI,CAAC;IACtD,OAAO,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,mBAAmB,GAAG,IAAI,CAAC;IAClF,aAAa,EAAE,kBAAkB,CAAC;IAClC,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAOF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,kBAAkB,CAsQ5F"}
|