@agentshouse/mdruntime-adapter 0.1.0-cadc6f4d88eda → 0.1.0-cae0ffbb88f87
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 +1 -1
- package/dist/actions.d.ts +0 -1
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +8 -7
- package/dist/adapter.d.ts +0 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +116 -94
- 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 +2 -4
- package/dist/chunks.d.ts.map +1 -1
- package/dist/chunks.js +71 -37
- package/dist/digest.d.ts +0 -1
- package/dist/discovery.d.ts +19 -8
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +143 -13
- 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 +5 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -5
- 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 +5 -20
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +34 -35
- package/dist/refusal.d.ts +5 -2
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +24 -7
- package/dist/room-query.d.ts +3 -0
- package/dist/room-query.d.ts.map +1 -0
- package/dist/room-query.js +22 -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/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 +28 -21
- 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 +85 -79
- package/dist/transport.d.ts +44 -18
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +12 -2
- 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 +19 -19
- 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 -682
- package/dist/house-model.d.ts.map +0 -1
- package/dist/house-model.js +0 -396
- package/dist/room-types.d.ts +0 -5
- package/dist/room-types.d.ts.map +0 -1
- package/dist/room-types.js +0 -120
package/dist/site.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
+
import { HOUSE_ROOM_TYPES, HOUSE_TYPED_PATHS } from '@agentshouse/mdmodel';
|
|
1
2
|
import { actionOutcome } from './actions.js';
|
|
2
3
|
import { chunkedHead, chunkPart, siteChunkList } from './chunks.js';
|
|
3
4
|
import { mapDiscovery, parseSiteDiscovery, siteCapabilities, siteTracked, } from './discovery.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { HOUSE_TYPED_PATHS } from './house-model.js';
|
|
7
|
-
import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
|
|
5
|
+
import { answeredFailure, discoveryFailure } from './refusal.js';
|
|
6
|
+
import { admittedPath } from './authored-path.js';
|
|
8
7
|
import { houseNotifications } from './stream.js';
|
|
9
|
-
import { houseSiteRoute,
|
|
8
|
+
import { houseSiteRoute, SITE_DOOR_ACTS, SITE_FILES, } from './transport.js';
|
|
9
|
+
import { UNANSWERED, unusable } from './uncertain.js';
|
|
10
10
|
import { followsVersion, reachedVersion, roomVersion } from './version.js';
|
|
11
|
-
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
12
11
|
function unfound() {
|
|
13
|
-
return { kind: 'rejected', code: '
|
|
12
|
+
return { kind: 'rejected', code: 'not_found', fields: {}, retryable: false };
|
|
14
13
|
}
|
|
15
14
|
function siteRoom(tracked) {
|
|
16
15
|
return {
|
|
@@ -20,18 +19,19 @@ function siteRoom(tracked) {
|
|
|
20
19
|
roomVersion: roomVersion(tracked),
|
|
21
20
|
operations: { write: [], erase: [] },
|
|
22
21
|
replica: { selection: tracked.locator, admission: 'admitted', offline: 'open' },
|
|
22
|
+
typedSelection: null,
|
|
23
23
|
providerOwnedPaths: [],
|
|
24
|
+
authoredPaths: ['**'],
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
27
|
export function createSiteAdapter(transport, snapshot = false) {
|
|
27
|
-
const spaces = spaceSchemas();
|
|
28
28
|
const notifications = houseNotifications(transport, 'site', {
|
|
29
29
|
opened: async () => {
|
|
30
30
|
const found = await discovered();
|
|
31
31
|
return found.kind === 'discovery' ? found : null;
|
|
32
32
|
},
|
|
33
33
|
changed: () => null,
|
|
34
|
-
}
|
|
34
|
+
});
|
|
35
35
|
const tracked = new Map();
|
|
36
36
|
const chunked = new Map();
|
|
37
37
|
function fileRoute(request) {
|
|
@@ -45,7 +45,7 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
45
45
|
const listed = siteChunkList(await transport.read(`${houseSiteRoute('chunks')}/${entry.authority}${past === undefined ? '' : `?expired=${past}`}`), entry.locator);
|
|
46
46
|
if ('kind' in listed)
|
|
47
47
|
return listed;
|
|
48
|
-
const head = await chunkedHead(listed, entry
|
|
48
|
+
const head = await chunkedHead(listed, entry);
|
|
49
49
|
if (head.kind === 'bootstrap')
|
|
50
50
|
chunked.set(entry.locator, listed);
|
|
51
51
|
return head;
|
|
@@ -54,10 +54,10 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
54
54
|
const room = chunked.get(entry.locator);
|
|
55
55
|
const address = room?.chunks.get(id);
|
|
56
56
|
if (room === undefined || address === undefined)
|
|
57
|
-
return
|
|
57
|
+
return UNANSWERED;
|
|
58
58
|
const read = await transport.download(address.url);
|
|
59
59
|
if (read.status !== 200)
|
|
60
|
-
return
|
|
60
|
+
return answeredFailure(read.status, null);
|
|
61
61
|
return chunkPart(read.body, room, id, arriving);
|
|
62
62
|
}
|
|
63
63
|
async function discovered() {
|
|
@@ -67,7 +67,7 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
67
67
|
return failed;
|
|
68
68
|
const document = parseSiteDiscovery(answer.body);
|
|
69
69
|
if (document === null)
|
|
70
|
-
return
|
|
70
|
+
return unusable();
|
|
71
71
|
const entries = siteTracked(document);
|
|
72
72
|
tracked.clear();
|
|
73
73
|
for (const entry of entries)
|
|
@@ -78,8 +78,8 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
78
78
|
return {
|
|
79
79
|
localSaves: true,
|
|
80
80
|
roomTypes: HOUSE_ROOM_TYPES,
|
|
81
|
-
nameableRoomTypes: HOUSE_NAMEABLE_ROOM_TYPES,
|
|
82
81
|
typedPaths: HOUSE_TYPED_PATHS,
|
|
82
|
+
pathRule: admittedPath,
|
|
83
83
|
async authorize() {
|
|
84
84
|
return {};
|
|
85
85
|
},
|
|
@@ -99,7 +99,7 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
99
99
|
if (entry === undefined)
|
|
100
100
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
101
101
|
if (request.pageToken !== undefined)
|
|
102
|
-
return
|
|
102
|
+
return UNANSWERED;
|
|
103
103
|
return request.fromRoomVersion === roomVersion(entry)
|
|
104
104
|
? { kind: 'still-current' }
|
|
105
105
|
: { kind: 'beyond-horizon' };
|
|
@@ -122,11 +122,15 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
122
122
|
const read = await transport.download(route);
|
|
123
123
|
if (read.status === 404)
|
|
124
124
|
return unfound();
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
if (read.status !== 200)
|
|
126
|
+
return answeredFailure(read.status, null);
|
|
127
|
+
if (read.body === null)
|
|
128
|
+
return unusable();
|
|
129
|
+
return { kind: 'binary', body: read.body, mediaType: read.mediaType };
|
|
128
130
|
},
|
|
129
131
|
async link(_authorization, request) {
|
|
132
|
+
if (request.kind === 'key')
|
|
133
|
+
return unfound();
|
|
130
134
|
const route = fileRoute(request);
|
|
131
135
|
if (typeof route !== 'string')
|
|
132
136
|
return route;
|
|
@@ -143,7 +147,10 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
143
147
|
return followsVersion(version, next);
|
|
144
148
|
},
|
|
145
149
|
async action(_authorization, request) {
|
|
146
|
-
|
|
150
|
+
const route = Object.hasOwn(SITE_DOOR_ACTS, request.name)
|
|
151
|
+
? SITE_DOOR_ACTS[request.name]
|
|
152
|
+
: null;
|
|
153
|
+
if (route === null) {
|
|
147
154
|
return {
|
|
148
155
|
kind: 'rejected',
|
|
149
156
|
code: 'action-unimplemented',
|
|
@@ -152,8 +159,8 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
152
159
|
};
|
|
153
160
|
}
|
|
154
161
|
if (!transport.online())
|
|
155
|
-
return
|
|
156
|
-
return actionOutcome(await transport.door(
|
|
162
|
+
return UNANSWERED;
|
|
163
|
+
return actionOutcome(await transport.door(route, request.input), request.name, request.input);
|
|
157
164
|
},
|
|
158
165
|
roomStream: snapshot
|
|
159
166
|
? undefined
|
package/dist/space-schema.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"space-schema.d.ts","sourceRoot":"","sources":["../src/space-schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"space-schema.d.ts","sourceRoot":"","sources":["../src/space-schema.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAC1D,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3D,CAAC;AAEF,wBAAgB,YAAY,IAAI,YAAY,CAO3C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD"}
|
package/dist/space-schema.js
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
const HELD_TEXTS = 16;
|
|
2
1
|
export function spaceSchemas() {
|
|
3
2
|
const texts = new Map();
|
|
4
3
|
const key = (space, revision) => `${space} ${revision}`;
|
|
5
4
|
return {
|
|
6
5
|
held: (space, revision) => texts.get(key(space, revision)),
|
|
7
|
-
keep(space, revision, text)
|
|
8
|
-
const named = key(space, revision);
|
|
9
|
-
texts.delete(named);
|
|
10
|
-
texts.set(named, text);
|
|
11
|
-
if (texts.size > HELD_TEXTS)
|
|
12
|
-
texts.delete(texts.keys().next().value);
|
|
13
|
-
},
|
|
6
|
+
keep: (space, revision, text) => void texts.set(key(space, revision), text),
|
|
14
7
|
};
|
|
15
8
|
}
|
|
16
9
|
export function spaceIdentity(space) {
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type AuthorityChange, type Discovery, type ConversationStream, type HeldRoom, type RoomStreamEvent, type ServiceModeSignal } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
-
import type { SpaceSchemas } from './space-schema.js';
|
|
4
3
|
import { type HouseDoor, type HouseMode, type HouseStreamFrame } from './transport.js';
|
|
5
4
|
export type HouseOpeningFrame = Extract<HouseStreamFrame, {
|
|
6
5
|
type: 'opening';
|
|
@@ -11,7 +10,7 @@ export type HouseAuthorityChangedFrame = Extract<HouseStreamFrame, {
|
|
|
11
10
|
export type HouseDiscovering = {
|
|
12
11
|
opened(frame: HouseOpeningFrame | null): Promise<Discovery | null>;
|
|
13
12
|
changed(frame: HouseAuthorityChangedFrame): AuthorityChange | null;
|
|
14
|
-
expired?(
|
|
13
|
+
expired?(entries: readonly TrackedAuthority[]): void;
|
|
15
14
|
};
|
|
16
15
|
export type HouseNotifications = {
|
|
17
16
|
runtime: string;
|
|
@@ -21,5 +20,4 @@ export type HouseNotifications = {
|
|
|
21
20
|
conversations: ConversationStream;
|
|
22
21
|
serviceMode: ServiceModeSignal;
|
|
23
22
|
};
|
|
24
|
-
export declare function houseNotifications(transport: HouseDoor, mode: HouseMode, discovering: HouseDiscovering
|
|
25
|
-
//# sourceMappingURL=stream.d.ts.map
|
|
23
|
+
export declare function houseNotifications(transport: HouseDoor, mode: HouseMode, discovering: HouseDiscovering): HouseNotifications;
|
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,EAGL,KAAK,eAAe,EAEpB,KAAK,SAAS,EACd,KAAK,kBAAkB,EAEvB,KAAK,QAAQ,EAGb,KAAK,eAAe,EAEpB,KAAK,iBAAiB,EAEvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,eAAe,EAEpB,KAAK,SAAS,EACd,KAAK,kBAAkB,EAEvB,KAAK,QAAQ,EAGb,KAAK,eAAe,EAEpB,KAAK,iBAAiB,EAEvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAYvD,OAAO,EACL,KAAK,SAAS,EAEd,KAAK,SAAS,EAGd,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAC;AAaxB,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,EAAE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC,CAAC;AAE/E,MAAM,MAAM,0BAA0B,GAAG,OAAO,CAAC,gBAAgB,EAAE;IAAE,IAAI,EAAE,mBAAmB,CAAA;CAAE,CAAC,CAAC;AAElG,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IACnE,OAAO,CAAC,KAAK,EAAE,0BAA0B,GAAG,eAAe,GAAG,IAAI,CAAC;IACnE,OAAO,CAAC,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,GAAG,IAAI,CAAC;CACtD,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAC9D,IAAI,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,GAAG,IAAI,CAAC;IACvC,KAAK,CAAC,WAAW,EAAE,SAAS,gBAAgB,EAAE,GAAG,IAAI,CAAC;IACtD,aAAa,EAAE,kBAAkB,CAAC;IAClC,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAyFF,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,SAAS,EACf,WAAW,EAAE,gBAAgB,GAC5B,kBAAkB,CAoYpB"}
|
package/dist/stream.js
CHANGED
|
@@ -1,38 +1,43 @@
|
|
|
1
1
|
import { ROW_WEIGHT, stepped, } from '@agentshouse/mdruntime';
|
|
2
|
-
import { acceptedMessage,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { acceptedMessage, changeCursor, houseHistory } from './history.js';
|
|
3
|
+
import { spaceSchemaTexts, streamedModels } from './model.js';
|
|
4
|
+
import { spaceSchemas } from './space-schema.js';
|
|
5
|
+
import { answered, answering, documentEntry, folded, forgotten, kept, } from './read.js';
|
|
6
6
|
import { DECIMAL, logPosition, presented, roomVersion } from './version.js';
|
|
7
7
|
function turnOperation(frame) {
|
|
8
|
-
|
|
9
|
-
return structuredClone(operation);
|
|
8
|
+
return 'at' in frame ? { op: 'begin', at: frame.at } : structuredClone(frame.operation);
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
function listedAgent(agent) {
|
|
11
|
+
return {
|
|
12
|
+
id: agent.id,
|
|
13
|
+
name: agent.name,
|
|
14
|
+
revision: agent.revision,
|
|
15
|
+
environment: agent.environment,
|
|
16
|
+
environment_name: agent.environment_name,
|
|
17
|
+
environment_connected: agent.environment_connected,
|
|
18
|
+
launch_directory: agent.launch_directory,
|
|
19
|
+
cli: agent.cli,
|
|
20
|
+
model: agent.model,
|
|
21
|
+
effort: agent.effort,
|
|
22
|
+
mode: agent.mode,
|
|
23
|
+
base_instructions: agent.base_instructions,
|
|
24
|
+
in_telegram: agent.in_telegram,
|
|
25
|
+
created: agent.created,
|
|
26
|
+
retired_at: agent.retired_at,
|
|
27
|
+
};
|
|
22
28
|
}
|
|
23
29
|
function listedConversation(listed) {
|
|
24
30
|
return {
|
|
25
31
|
conversation: listed.conversation_id,
|
|
26
32
|
agent: listed.agent_id,
|
|
27
|
-
agentName: listed.agent_name,
|
|
28
|
-
agentRetired: listed.agent_retired,
|
|
29
33
|
name: listed.name,
|
|
30
34
|
created: listed.created_at,
|
|
31
35
|
finished: listed.finished_at,
|
|
32
36
|
outcome: listed.outcome,
|
|
33
37
|
waiting: listed.waiting,
|
|
34
|
-
newest: listed.newest === null ? null :
|
|
38
|
+
newest: listed.newest === null ? null : changeCursor(listed.newest),
|
|
35
39
|
processEnded: listed.process_ended_at,
|
|
40
|
+
subject: listed.subject,
|
|
36
41
|
};
|
|
37
42
|
}
|
|
38
43
|
function position(value) {
|
|
@@ -40,55 +45,47 @@ function position(value) {
|
|
|
40
45
|
return null;
|
|
41
46
|
return BigInt(value);
|
|
42
47
|
}
|
|
43
|
-
function* changed(tracked, entries, version, schemas) {
|
|
48
|
+
function* changed(tracked, entries, version, mode, schemas) {
|
|
44
49
|
const answer = answering();
|
|
45
50
|
for (const entry of entries) {
|
|
46
|
-
yield ROW_WEIGHT + (entry.
|
|
51
|
+
yield ROW_WEIGHT + (entry.content?.length ?? 0);
|
|
47
52
|
if (entry.kind === 'folder') {
|
|
48
53
|
folded(answer, entry.path, entry.removed === true);
|
|
49
54
|
continue;
|
|
50
55
|
}
|
|
51
|
-
if (entry.path === tracked.schema)
|
|
52
|
-
schemas.set(entry.path, entry);
|
|
53
|
-
forgotten(answer, entry.path);
|
|
54
|
-
if (entry.space !== undefined) {
|
|
55
|
-
answer.removals.add(entry.path);
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
56
|
if (entry.kind === 'removed') {
|
|
57
|
+
if (entry.path === tracked.schema)
|
|
58
|
+
schemas.set(entry.path, null);
|
|
59
|
+
forgotten(answer, entry.path);
|
|
59
60
|
answer.removals.add(entry.path);
|
|
60
61
|
continue;
|
|
61
62
|
}
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const head = headChange(entry);
|
|
73
|
-
if (head)
|
|
74
|
-
answer.changes.set(entry.path, head);
|
|
75
|
-
const created = createdOf(entry);
|
|
76
|
-
if (created)
|
|
77
|
-
answer.created.set(entry.path, created);
|
|
63
|
+
const file = documentEntry(entry, mode);
|
|
64
|
+
if (file === null)
|
|
65
|
+
throw new Error(`the stream carried ${entry.path} as no file`);
|
|
66
|
+
if (entry.path === tracked.schema)
|
|
67
|
+
schemas.set(entry.path, file);
|
|
68
|
+
forgotten(answer, file.path);
|
|
69
|
+
if (file.space === undefined)
|
|
70
|
+
kept(answer, file);
|
|
71
|
+
else
|
|
72
|
+
answer.removals.add(file.path);
|
|
78
73
|
}
|
|
79
74
|
return { kind: 'net-advancement', roomVersion: version, ...(yield* answered(answer)) };
|
|
80
75
|
}
|
|
81
|
-
async function changePage(tracked, entries, version, mode,
|
|
76
|
+
async function changePage(tracked, entries, version, mode, whole) {
|
|
82
77
|
const schemas = new Map();
|
|
83
|
-
const page = await stepped(changed(tracked, entries, version, schemas));
|
|
84
|
-
const models = await streamedModels(schemas, tracked,
|
|
78
|
+
const page = await stepped(changed(tracked, entries, version, mode, schemas));
|
|
79
|
+
const models = await streamedModels(schemas, tracked, whole);
|
|
85
80
|
return models === undefined ? page : { ...page, models };
|
|
86
81
|
}
|
|
87
|
-
export function houseNotifications(transport, mode, discovering
|
|
82
|
+
export function houseNotifications(transport, mode, discovering) {
|
|
88
83
|
const stream = transport.stream;
|
|
89
84
|
const staged = new Map();
|
|
85
|
+
let spaces = spaceSchemas();
|
|
90
86
|
let socket = null;
|
|
91
87
|
const tracking = new Map();
|
|
88
|
+
const located = new Map();
|
|
92
89
|
const observers = new Set();
|
|
93
90
|
const replaying = new Map();
|
|
94
91
|
const conversationObservers = new Set();
|
|
@@ -117,7 +114,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
117
114
|
event.kind === 'commands' ||
|
|
118
115
|
event.kind === 'options' ||
|
|
119
116
|
event.kind === 'starting' ||
|
|
120
|
-
event.kind === '
|
|
117
|
+
event.kind === 'state' ||
|
|
121
118
|
event.kind === 'link' ||
|
|
122
119
|
event.kind === 'deliveries') {
|
|
123
120
|
live.add(event.conversation);
|
|
@@ -130,6 +127,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
130
127
|
announced = null;
|
|
131
128
|
socket = next;
|
|
132
129
|
staged.clear();
|
|
130
|
+
spaces = spaceSchemas();
|
|
133
131
|
unanswered.length = 0;
|
|
134
132
|
heldAtZero.clear();
|
|
135
133
|
const gapped = new Set([...replicated, ...live]);
|
|
@@ -150,9 +148,9 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
150
148
|
}
|
|
151
149
|
announced = { kind: 'discovered', discovery };
|
|
152
150
|
emit(announced);
|
|
153
|
-
}, () => {
|
|
151
|
+
}, (failure) => {
|
|
154
152
|
if (socket === via)
|
|
155
|
-
via.close();
|
|
153
|
+
via.close(failure);
|
|
156
154
|
});
|
|
157
155
|
}
|
|
158
156
|
function converse(frame) {
|
|
@@ -172,7 +170,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
172
170
|
return;
|
|
173
171
|
emitConversation({ kind: 'commands', conversation, commands: [] });
|
|
174
172
|
emitConversation({ kind: 'options', conversation, options: [] });
|
|
175
|
-
emitConversation({ kind: '
|
|
173
|
+
emitConversation({ kind: 'state', conversation, state: null });
|
|
176
174
|
return;
|
|
177
175
|
}
|
|
178
176
|
if (frame.type === 'commands') {
|
|
@@ -191,12 +189,8 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
191
189
|
emitConversation({ kind: 'starting', conversation, step: frame.step });
|
|
192
190
|
return;
|
|
193
191
|
}
|
|
194
|
-
if (frame.type === '
|
|
195
|
-
emitConversation({
|
|
196
|
-
kind: 'subagents',
|
|
197
|
-
conversation,
|
|
198
|
-
subagents: structuredClone(frame.subagents),
|
|
199
|
-
});
|
|
192
|
+
if (frame.type === 'state') {
|
|
193
|
+
emitConversation({ kind: 'state', conversation, state: structuredClone(frame.state) });
|
|
200
194
|
return;
|
|
201
195
|
}
|
|
202
196
|
if (frame.type === 'link') {
|
|
@@ -204,7 +198,12 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
204
198
|
return;
|
|
205
199
|
}
|
|
206
200
|
if (frame.type === 'deliveries') {
|
|
207
|
-
emitConversation({
|
|
201
|
+
emitConversation({
|
|
202
|
+
kind: 'deliveries',
|
|
203
|
+
conversation,
|
|
204
|
+
waiting: [...frame.waiting],
|
|
205
|
+
unknown: [...frame.unknown],
|
|
206
|
+
});
|
|
208
207
|
return;
|
|
209
208
|
}
|
|
210
209
|
if (frame.type === 'interactions') {
|
|
@@ -221,6 +220,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
221
220
|
emitConversation({ kind: 'accepted-message', conversation, message });
|
|
222
221
|
}
|
|
223
222
|
function stage(frame, via) {
|
|
223
|
+
const entries = spaceSchemaTexts(frame.entries, spaces);
|
|
224
224
|
const held = staged.get(frame.carry);
|
|
225
225
|
if (frame.index !== (held?.parts ?? 0)) {
|
|
226
226
|
staged.delete(frame.carry);
|
|
@@ -233,8 +233,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
235
|
const next = held ?? { authority: frame.authority, parts: 0, entries: [] };
|
|
236
|
-
|
|
237
|
-
next.entries.push(...frame.entries);
|
|
236
|
+
next.entries.push(...entries);
|
|
238
237
|
next.parts += 1;
|
|
239
238
|
staged.set(frame.carry, next);
|
|
240
239
|
via?.received(frame.authority, frame.carry, frame.index);
|
|
@@ -261,16 +260,18 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
261
260
|
return;
|
|
262
261
|
}
|
|
263
262
|
if (frame.type === 'caught_up') {
|
|
264
|
-
|
|
263
|
+
const expired = frame.expired.flatMap((authority) => tracking.get(authority) ?? []);
|
|
264
|
+
discovering.expired?.(expired);
|
|
265
265
|
emit({
|
|
266
266
|
kind: 'caught-up',
|
|
267
|
-
expired: [
|
|
268
|
-
...frame.expired.flatMap((authority) => (tracking.get(authority) ?? []).map((tracked) => tracked.locator)),
|
|
269
|
-
...(unanswered.shift() ?? []),
|
|
270
|
-
],
|
|
267
|
+
expired: [...expired.map(({ locator }) => locator), ...(unanswered.shift() ?? [])],
|
|
271
268
|
});
|
|
272
269
|
return;
|
|
273
270
|
}
|
|
271
|
+
if (frame.type === 'report') {
|
|
272
|
+
emit({ kind: 'reported' });
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
274
275
|
if (frame.type === 'authority_changed') {
|
|
275
276
|
const change = discovering.changed(frame);
|
|
276
277
|
if (change !== null)
|
|
@@ -280,6 +281,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
280
281
|
if (frame.type === 'conversations') {
|
|
281
282
|
emitConversation({
|
|
282
283
|
kind: 'list',
|
|
284
|
+
agents: frame.agents.map(listedAgent),
|
|
283
285
|
entries: frame.conversations.map(listedConversation),
|
|
284
286
|
whole: frame.whole,
|
|
285
287
|
more: frame.more,
|
|
@@ -291,6 +293,10 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
291
293
|
emitConversation({ kind: 'listed', entry: listedConversation(frame.conversation) });
|
|
292
294
|
return;
|
|
293
295
|
}
|
|
296
|
+
if (frame.type === 'agent') {
|
|
297
|
+
emitConversation({ kind: 'agent', agent: listedAgent(frame.agent) });
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
294
300
|
if (frame.type === 'conversation_deleted') {
|
|
295
301
|
emitConversation({ kind: 'unlisted', conversation: frame.conversation_id });
|
|
296
302
|
return;
|
|
@@ -300,7 +306,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
300
306
|
frame.type === 'commands' ||
|
|
301
307
|
frame.type === 'options' ||
|
|
302
308
|
frame.type === 'starting' ||
|
|
303
|
-
frame.type === '
|
|
309
|
+
frame.type === 'state' ||
|
|
304
310
|
frame.type === 'link' ||
|
|
305
311
|
frame.type === 'deliveries' ||
|
|
306
312
|
frame.type === 'interactions' ||
|
|
@@ -328,7 +334,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
328
334
|
locator: tracked.locator,
|
|
329
335
|
from,
|
|
330
336
|
roomVersion: version,
|
|
331
|
-
read: () => changePage(tracked, entries, version, mode,
|
|
337
|
+
read: () => changePage(tracked, entries, version, mode, from === null),
|
|
332
338
|
});
|
|
333
339
|
}
|
|
334
340
|
}
|
|
@@ -339,6 +345,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
339
345
|
announced = null;
|
|
340
346
|
socket = null;
|
|
341
347
|
staged.clear();
|
|
348
|
+
spaces = spaceSchemas();
|
|
342
349
|
unanswered.length = 0;
|
|
343
350
|
heldAtZero.clear();
|
|
344
351
|
emit({ kind: 'closed', revoked, lost, authorityChanged });
|
|
@@ -366,12 +373,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
366
373
|
conversationObservers.delete(notify);
|
|
367
374
|
};
|
|
368
375
|
},
|
|
369
|
-
...(mode === 'credential'
|
|
370
|
-
? {
|
|
371
|
-
agents: () => houseAgents(transport),
|
|
372
|
-
history: (request) => houseHistory(transport, request),
|
|
373
|
-
}
|
|
374
|
-
: {}),
|
|
376
|
+
...(mode === 'credential' ? { history: (request) => houseHistory(transport, request) } : {}),
|
|
375
377
|
},
|
|
376
378
|
observe(notify) {
|
|
377
379
|
observers.add(notify);
|
|
@@ -396,14 +398,13 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
396
398
|
announced = null;
|
|
397
399
|
if (socket === null)
|
|
398
400
|
return;
|
|
399
|
-
const entries = new Map([...tracking.values()].flat().map((tracked) => [tracked.locator, tracked]));
|
|
400
401
|
const named = rooms.flatMap((room) => {
|
|
401
|
-
const entry =
|
|
402
|
+
const entry = located.get(room.locator);
|
|
402
403
|
const at = room.roomVersion === null ? null : logPosition(room.roomVersion);
|
|
403
404
|
return entry === undefined || at === null ? [] : [{ entry, at }];
|
|
404
405
|
});
|
|
405
406
|
const unheld = rooms.flatMap((room) => {
|
|
406
|
-
const entry =
|
|
407
|
+
const entry = located.get(room.locator);
|
|
407
408
|
return entry === undefined || room.roomVersion !== null ? [] : [entry];
|
|
408
409
|
});
|
|
409
410
|
for (const { entry, at } of named) {
|
|
@@ -431,16 +432,21 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
431
432
|
locator: entry.locator,
|
|
432
433
|
from: null,
|
|
433
434
|
roomVersion: version,
|
|
434
|
-
read: () => changePage(entry, [], version, mode,
|
|
435
|
+
read: () => changePage(entry, [], version, mode, true),
|
|
435
436
|
});
|
|
436
437
|
}
|
|
437
438
|
});
|
|
438
439
|
},
|
|
439
440
|
track(entries) {
|
|
440
441
|
tracking.clear();
|
|
442
|
+
located.clear();
|
|
441
443
|
for (const entry of entries) {
|
|
442
444
|
tracking.set(entry.authority, [...(tracking.get(entry.authority) ?? []), entry]);
|
|
443
445
|
}
|
|
446
|
+
for (const held of tracking.values()) {
|
|
447
|
+
for (const entry of held)
|
|
448
|
+
located.set(entry.locator, entry);
|
|
449
|
+
}
|
|
444
450
|
for (const [carry, held] of staged) {
|
|
445
451
|
if (!tracking.has(held.authority))
|
|
446
452
|
staged.delete(carry);
|