@agentshouse/mdruntime-adapter 0.1.0-cf863e7a50d6e → 0.1.0-cfab89da09586
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/actions.d.ts +3 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +26 -9
- package/dist/adapter.d.ts +0 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +118 -112
- package/dist/authored-path.d.ts +9 -0
- package/dist/authored-path.d.ts.map +1 -0
- package/dist/authored-path.js +34 -0
- package/dist/chunks.d.ts +36 -0
- package/dist/chunks.d.ts.map +1 -0
- package/dist/chunks.js +289 -0
- package/dist/digest.d.ts +0 -1
- package/dist/discovery.d.ts +11 -6
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +39 -13
- package/dist/history.d.ts +1 -7
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +24 -30
- package/dist/index.d.ts +4 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/map.d.ts +0 -1
- package/dist/model.d.ts +5 -8
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +29 -18
- package/dist/read.d.ts +19 -10
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +48 -145
- package/dist/refusal.d.ts +3 -2
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +17 -7
- package/dist/search.d.ts +4 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +47 -0
- package/dist/session-content/bounds.d.ts +7 -0
- package/dist/session-content/check.d.ts +18 -0
- package/dist/session-content/index.d.ts +7 -0
- package/dist/session-content/parts.d.ts +103 -0
- package/dist/session-content/state.d.ts +61 -0
- package/dist/session-content/turn.d.ts +328 -0
- package/dist/site.d.ts +0 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +44 -50
- package/dist/space-schema.d.ts +6 -0
- package/dist/space-schema.d.ts.map +1 -0
- package/dist/space-schema.js +11 -0
- package/dist/stream.d.ts +4 -4
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +138 -53
- package/dist/transport.d.ts +31 -25
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +13 -12
- 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 +24 -38
- package/package.json +3 -2
- package/dist/app-reference.d.ts +0 -2
- package/dist/app-reference.d.ts.map +0 -1
- package/dist/app-reference.js +0 -2
- package/dist/crockford.d.ts +0 -4
- package/dist/crockford.d.ts.map +0 -1
- package/dist/crockford.js +0 -3
- package/dist/house-model.d.ts +0 -955
- package/dist/house-model.d.ts.map +0 -1
- package/dist/house-model.js +0 -521
- package/dist/part.d.ts +0 -14
- package/dist/part.d.ts.map +0 -1
- package/dist/part.js +0 -90
- package/dist/room-stream.d.ts +0 -19
- package/dist/room-stream.d.ts.map +0 -1
- package/dist/room-stream.js +0 -57
- package/dist/room-types.d.ts +0 -7
- package/dist/room-types.d.ts.map +0 -1
- package/dist/room-types.js +0 -125
package/dist/site.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HOUSE_ROOM_TYPES, HOUSE_TYPED_PATHS } from '@agentshouse/mdmodel';
|
|
2
2
|
import { actionOutcome } from './actions.js';
|
|
3
|
+
import { chunkedHead, chunkPart, siteChunkList } from './chunks.js';
|
|
3
4
|
import { mapDiscovery, parseSiteDiscovery, siteCapabilities, siteTracked, } from './discovery.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { classifyDoor, discoveryFailure } from './refusal.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, SITE_DOOR_SUBMIT, SITE_FILES,
|
|
10
|
-
import {
|
|
11
|
-
|
|
8
|
+
import { houseSiteRoute, SITE_DOOR_SUBMIT, SITE_FILES, SITES_SUBMISSIONS_CREATE, } from './transport.js';
|
|
9
|
+
import { UNANSWERED, unusable } from './uncertain.js';
|
|
10
|
+
import { followsVersion, reachedVersion, roomVersion } from './version.js';
|
|
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 {
|
|
@@ -18,9 +17,11 @@ function siteRoom(tracked) {
|
|
|
18
17
|
locator: tracked.locator,
|
|
19
18
|
handle: tracked.handle,
|
|
20
19
|
roomVersion: roomVersion(tracked),
|
|
21
|
-
operations: { write: [],
|
|
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) {
|
|
@@ -32,36 +33,32 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
32
33
|
changed: () => null,
|
|
33
34
|
});
|
|
34
35
|
const tracked = new Map();
|
|
35
|
-
const
|
|
36
|
-
const rooms = roomStreams('site');
|
|
36
|
+
const chunked = new Map();
|
|
37
37
|
function fileRoute(request) {
|
|
38
38
|
const entry = tracked.get(request.locator);
|
|
39
39
|
if (entry === undefined)
|
|
40
40
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
41
41
|
return `${SITE_FILES}${entry.authority}/${encodeURIComponent(request.revision)}/${encodeURIComponent(request.path)}`;
|
|
42
42
|
}
|
|
43
|
-
async function
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
if (
|
|
47
|
-
return
|
|
48
|
-
const head = await
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
read.set(entry.locator, at.position);
|
|
43
|
+
async function listedRoom(entry) {
|
|
44
|
+
const past = chunked.get(entry.locator)?.position;
|
|
45
|
+
const listed = siteChunkList(await transport.read(`${houseSiteRoute('chunks')}/${entry.authority}${past === undefined ? '' : `?expired=${past}`}`), entry.locator);
|
|
46
|
+
if ('kind' in listed)
|
|
47
|
+
return listed;
|
|
48
|
+
const head = await chunkedHead(listed, entry);
|
|
49
|
+
if (head.kind === 'bootstrap')
|
|
50
|
+
chunked.set(entry.locator, listed);
|
|
52
51
|
return head;
|
|
53
52
|
}
|
|
54
|
-
async function
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
bytes: part.bytes,
|
|
64
|
-
};
|
|
53
|
+
async function chunkPage(entry, id, arriving) {
|
|
54
|
+
const room = chunked.get(entry.locator);
|
|
55
|
+
const address = room?.chunks.get(id);
|
|
56
|
+
if (room === undefined || address === undefined)
|
|
57
|
+
return UNANSWERED;
|
|
58
|
+
const read = await transport.download(address.url);
|
|
59
|
+
if (read.status !== 200)
|
|
60
|
+
return answeredFailure(read.status, null);
|
|
61
|
+
return chunkPart(read.body, room, id, arriving);
|
|
65
62
|
}
|
|
66
63
|
async function discovered() {
|
|
67
64
|
const answer = await transport.read(houseSiteRoute('discover'));
|
|
@@ -70,7 +67,7 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
70
67
|
return failed;
|
|
71
68
|
const document = parseSiteDiscovery(answer.body);
|
|
72
69
|
if (document === null)
|
|
73
|
-
return
|
|
70
|
+
return unusable();
|
|
74
71
|
const entries = siteTracked(document);
|
|
75
72
|
tracked.clear();
|
|
76
73
|
for (const entry of entries)
|
|
@@ -81,7 +78,8 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
81
78
|
return {
|
|
82
79
|
localSaves: true,
|
|
83
80
|
roomTypes: HOUSE_ROOM_TYPES,
|
|
84
|
-
|
|
81
|
+
typedPaths: HOUSE_TYPED_PATHS,
|
|
82
|
+
pathRule: admittedPath,
|
|
85
83
|
async authorize() {
|
|
86
84
|
return {};
|
|
87
85
|
},
|
|
@@ -90,8 +88,8 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
90
88
|
if (entry === undefined)
|
|
91
89
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
92
90
|
return request.pageToken === undefined
|
|
93
|
-
?
|
|
94
|
-
:
|
|
91
|
+
? listedRoom(entry)
|
|
92
|
+
: chunkPage(entry, request.pageToken, request.arriving);
|
|
95
93
|
},
|
|
96
94
|
...(snapshot
|
|
97
95
|
? {
|
|
@@ -101,7 +99,7 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
101
99
|
if (entry === undefined)
|
|
102
100
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
103
101
|
if (request.pageToken !== undefined)
|
|
104
|
-
return
|
|
102
|
+
return UNANSWERED;
|
|
105
103
|
return request.fromRoomVersion === roomVersion(entry)
|
|
106
104
|
? { kind: 'still-current' }
|
|
107
105
|
: { kind: 'beyond-horizon' };
|
|
@@ -124,9 +122,11 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
124
122
|
const read = await transport.download(route);
|
|
125
123
|
if (read.status === 404)
|
|
126
124
|
return unfound();
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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 };
|
|
130
130
|
},
|
|
131
131
|
async link(_authorization, request) {
|
|
132
132
|
const route = fileRoute(request);
|
|
@@ -145,7 +145,7 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
145
145
|
return followsVersion(version, next);
|
|
146
146
|
},
|
|
147
147
|
async action(_authorization, request) {
|
|
148
|
-
if (request.name !==
|
|
148
|
+
if (request.name !== SITES_SUBMISSIONS_CREATE) {
|
|
149
149
|
return {
|
|
150
150
|
kind: 'rejected',
|
|
151
151
|
code: 'action-unimplemented',
|
|
@@ -154,19 +154,13 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
156
|
if (!transport.online())
|
|
157
|
-
return
|
|
158
|
-
return actionOutcome(await transport.door(SITE_DOOR_SUBMIT, request.input),
|
|
157
|
+
return UNANSWERED;
|
|
158
|
+
return actionOutcome(await transport.door(SITE_DOOR_SUBMIT, request.input), SITES_SUBMISSIONS_CREATE, request.input);
|
|
159
159
|
},
|
|
160
160
|
roomStream: snapshot
|
|
161
161
|
? undefined
|
|
162
162
|
: {
|
|
163
|
-
hold
|
|
164
|
-
notifications.send(rooms.flatMap((room) => {
|
|
165
|
-
const entry = tracked.get(room.locator);
|
|
166
|
-
const at = logPosition(room.roomVersion);
|
|
167
|
-
return entry === undefined || at === null ? [] : [presented(entry.authority, at)];
|
|
168
|
-
}));
|
|
169
|
-
},
|
|
163
|
+
hold: notifications.send,
|
|
170
164
|
observe: notifications.observe,
|
|
171
165
|
},
|
|
172
166
|
serviceMode: notifications.serviceMode,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type SpaceSchemas = {
|
|
2
|
+
held(space: string, revision: string): string | undefined;
|
|
3
|
+
keep(space: string, revision: string, text: string): void;
|
|
4
|
+
};
|
|
5
|
+
export declare function spaceSchemas(): SpaceSchemas;
|
|
6
|
+
export declare function spaceIdentity(space: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function spaceSchemas() {
|
|
2
|
+
const texts = new Map();
|
|
3
|
+
const key = (space, revision) => `${space} ${revision}`;
|
|
4
|
+
return {
|
|
5
|
+
held: (space, revision) => texts.get(key(space, revision)),
|
|
6
|
+
keep: (space, revision, text) => void texts.set(key(space, revision), text),
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export function spaceIdentity(space) {
|
|
10
|
+
return `space:${space}`;
|
|
11
|
+
}
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type AuthorityChange, type Discovery, type ConversationStream, type RoomStreamEvent, type ServiceModeSignal } from '@agentshouse/mdruntime';
|
|
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 HouseDoor, type
|
|
3
|
+
import { type HouseDoor, type HouseMode, type HouseStreamFrame } from './transport.js';
|
|
4
4
|
export type HouseOpeningFrame = Extract<HouseStreamFrame, {
|
|
5
5
|
type: 'opening';
|
|
6
6
|
}>;
|
|
@@ -10,14 +10,14 @@ export type HouseAuthorityChangedFrame = Extract<HouseStreamFrame, {
|
|
|
10
10
|
export type HouseDiscovering = {
|
|
11
11
|
opened(frame: HouseOpeningFrame | null): Promise<Discovery | null>;
|
|
12
12
|
changed(frame: HouseAuthorityChangedFrame): AuthorityChange | null;
|
|
13
|
+
expired?(entries: readonly TrackedAuthority[]): void;
|
|
13
14
|
};
|
|
14
15
|
export type HouseNotifications = {
|
|
15
16
|
runtime: string;
|
|
16
17
|
observe(notify: (event: RoomStreamEvent) => void): () => void;
|
|
17
|
-
send(rooms: readonly
|
|
18
|
+
send(rooms: readonly HeldRoom[]): void;
|
|
18
19
|
track(authorities: readonly TrackedAuthority[]): void;
|
|
19
20
|
conversations: ConversationStream;
|
|
20
21
|
serviceMode: ServiceModeSignal;
|
|
21
22
|
};
|
|
22
23
|
export declare function houseNotifications(transport: HouseDoor, mode: HouseMode, discovering: HouseDiscovering): HouseNotifications;
|
|
23
|
-
//# 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,EAGL,KAAK,eAAe,EAEpB,KAAK,SAAS,EACd,KAAK,kBAAkB,
|
|
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;AAavD,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;AAiGF,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,SAAS,EACf,WAAW,EAAE,gBAAgB,GAC5B,kBAAkB,CAgYpB"}
|
package/dist/stream.js
CHANGED
|
@@ -1,37 +1,43 @@
|
|
|
1
1
|
import { ROW_WEIGHT, stepped, } from '@agentshouse/mdruntime';
|
|
2
|
-
import { acceptedMessage,
|
|
3
|
-
import { streamedModels } from './model.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { DECIMAL, roomVersion } from './version.js';
|
|
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, binaryFileOf, createdOf, folded, forgotten, headChange, revised, } from './read.js';
|
|
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),
|
|
39
|
+
processEnded: listed.process_ended_at,
|
|
40
|
+
subject: listed.subject,
|
|
35
41
|
};
|
|
36
42
|
}
|
|
37
43
|
function position(value) {
|
|
@@ -50,6 +56,10 @@ function* changed(tracked, entries, version, schemas) {
|
|
|
50
56
|
if (entry.path === tracked.schema)
|
|
51
57
|
schemas.set(entry.path, entry);
|
|
52
58
|
forgotten(answer, entry.path);
|
|
59
|
+
if (entry.space !== undefined) {
|
|
60
|
+
answer.removals.add(entry.path);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
53
63
|
if (entry.kind === 'removed') {
|
|
54
64
|
answer.removals.add(entry.path);
|
|
55
65
|
continue;
|
|
@@ -59,38 +69,53 @@ function* changed(tracked, entries, version, schemas) {
|
|
|
59
69
|
answer.documents.set(entry.path, entry.text ?? '');
|
|
60
70
|
else if (binary !== null)
|
|
61
71
|
answer.binaryFiles.set(entry.path, binary);
|
|
72
|
+
if (binary === undefined && entry.facts !== undefined)
|
|
73
|
+
answer.facts.set(entry.path, entry.facts);
|
|
62
74
|
const revision = entry.revision ?? binary?.sha256;
|
|
63
75
|
if (revision !== undefined)
|
|
64
76
|
revised(answer, entry.path, revision);
|
|
65
77
|
const head = headChange(entry);
|
|
66
78
|
if (head)
|
|
67
79
|
answer.changes.set(entry.path, head);
|
|
80
|
+
const created = createdOf(entry);
|
|
81
|
+
if (created)
|
|
82
|
+
answer.created.set(entry.path, created);
|
|
68
83
|
}
|
|
69
84
|
return { kind: 'net-advancement', roomVersion: version, ...(yield* answered(answer)) };
|
|
70
85
|
}
|
|
71
|
-
async function changePage(tracked, entries, version, mode) {
|
|
86
|
+
async function changePage(tracked, entries, version, mode, whole) {
|
|
72
87
|
const schemas = new Map();
|
|
73
88
|
const page = await stepped(changed(tracked, entries, version, schemas));
|
|
74
|
-
const models = await streamedModels(schemas, tracked, mode);
|
|
89
|
+
const models = await streamedModels(schemas, tracked, mode, whole);
|
|
75
90
|
return models === undefined ? page : { ...page, models };
|
|
76
91
|
}
|
|
77
92
|
export function houseNotifications(transport, mode, discovering) {
|
|
78
93
|
const stream = transport.stream;
|
|
79
94
|
const staged = new Map();
|
|
95
|
+
let spaces = spaceSchemas();
|
|
80
96
|
let socket = null;
|
|
81
97
|
const tracking = new Map();
|
|
98
|
+
const located = new Map();
|
|
82
99
|
const observers = new Set();
|
|
100
|
+
const replaying = new Map();
|
|
83
101
|
const conversationObservers = new Set();
|
|
84
102
|
const modeObservers = new Set();
|
|
85
103
|
let replicated = [];
|
|
86
104
|
let listedCursor = null;
|
|
105
|
+
const unanswered = [];
|
|
106
|
+
const heldAtZero = new Set();
|
|
87
107
|
const live = new Set();
|
|
88
108
|
let opening = null;
|
|
89
109
|
let announced = null;
|
|
90
110
|
const runtime = crypto.randomUUID();
|
|
91
111
|
function emit(event) {
|
|
92
|
-
for (const observer of observers)
|
|
93
|
-
observer
|
|
112
|
+
for (const observer of observers) {
|
|
113
|
+
const held = replaying.get(observer);
|
|
114
|
+
if (held === undefined)
|
|
115
|
+
observer(event);
|
|
116
|
+
else
|
|
117
|
+
held.push(event);
|
|
118
|
+
}
|
|
94
119
|
}
|
|
95
120
|
function emitConversation(event) {
|
|
96
121
|
if (event.kind === 'turn' ||
|
|
@@ -99,7 +124,7 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
99
124
|
event.kind === 'commands' ||
|
|
100
125
|
event.kind === 'options' ||
|
|
101
126
|
event.kind === 'starting' ||
|
|
102
|
-
event.kind === '
|
|
127
|
+
event.kind === 'state' ||
|
|
103
128
|
event.kind === 'link' ||
|
|
104
129
|
event.kind === 'deliveries') {
|
|
105
130
|
live.add(event.conversation);
|
|
@@ -112,6 +137,9 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
112
137
|
announced = null;
|
|
113
138
|
socket = next;
|
|
114
139
|
staged.clear();
|
|
140
|
+
spaces = spaceSchemas();
|
|
141
|
+
unanswered.length = 0;
|
|
142
|
+
heldAtZero.clear();
|
|
115
143
|
const gapped = new Set([...replicated, ...live]);
|
|
116
144
|
live.clear();
|
|
117
145
|
for (const conversation of gapped)
|
|
@@ -130,9 +158,9 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
130
158
|
}
|
|
131
159
|
announced = { kind: 'discovered', discovery };
|
|
132
160
|
emit(announced);
|
|
133
|
-
}, () => {
|
|
161
|
+
}, (failure) => {
|
|
134
162
|
if (socket === via)
|
|
135
|
-
via.close();
|
|
163
|
+
via.close(failure);
|
|
136
164
|
});
|
|
137
165
|
}
|
|
138
166
|
function converse(frame) {
|
|
@@ -152,7 +180,7 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
152
180
|
return;
|
|
153
181
|
emitConversation({ kind: 'commands', conversation, commands: [] });
|
|
154
182
|
emitConversation({ kind: 'options', conversation, options: [] });
|
|
155
|
-
emitConversation({ kind: '
|
|
183
|
+
emitConversation({ kind: 'state', conversation, state: null });
|
|
156
184
|
return;
|
|
157
185
|
}
|
|
158
186
|
if (frame.type === 'commands') {
|
|
@@ -171,12 +199,8 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
171
199
|
emitConversation({ kind: 'starting', conversation, step: frame.step });
|
|
172
200
|
return;
|
|
173
201
|
}
|
|
174
|
-
if (frame.type === '
|
|
175
|
-
emitConversation({
|
|
176
|
-
kind: 'subagents',
|
|
177
|
-
conversation,
|
|
178
|
-
subagents: structuredClone(frame.subagents),
|
|
179
|
-
});
|
|
202
|
+
if (frame.type === 'state') {
|
|
203
|
+
emitConversation({ kind: 'state', conversation, state: structuredClone(frame.state) });
|
|
180
204
|
return;
|
|
181
205
|
}
|
|
182
206
|
if (frame.type === 'link') {
|
|
@@ -184,7 +208,12 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
184
208
|
return;
|
|
185
209
|
}
|
|
186
210
|
if (frame.type === 'deliveries') {
|
|
187
|
-
emitConversation({
|
|
211
|
+
emitConversation({
|
|
212
|
+
kind: 'deliveries',
|
|
213
|
+
conversation,
|
|
214
|
+
waiting: [...frame.waiting],
|
|
215
|
+
unknown: [...frame.unknown],
|
|
216
|
+
});
|
|
188
217
|
return;
|
|
189
218
|
}
|
|
190
219
|
if (frame.type === 'interactions') {
|
|
@@ -201,6 +230,7 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
201
230
|
emitConversation({ kind: 'accepted-message', conversation, message });
|
|
202
231
|
}
|
|
203
232
|
function stage(frame, via) {
|
|
233
|
+
const entries = spaceSchemaTexts(frame.entries, spaces);
|
|
204
234
|
const held = staged.get(frame.carry);
|
|
205
235
|
if (frame.index !== (held?.parts ?? 0)) {
|
|
206
236
|
staged.delete(frame.carry);
|
|
@@ -213,7 +243,7 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
213
243
|
}
|
|
214
244
|
}
|
|
215
245
|
const next = held ?? { authority: frame.authority, parts: 0, entries: [] };
|
|
216
|
-
next.entries.push(...
|
|
246
|
+
next.entries.push(...entries);
|
|
217
247
|
next.parts += 1;
|
|
218
248
|
staged.set(frame.carry, next);
|
|
219
249
|
via?.received(frame.authority, frame.carry, frame.index);
|
|
@@ -240,9 +270,11 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
240
270
|
return;
|
|
241
271
|
}
|
|
242
272
|
if (frame.type === 'caught_up') {
|
|
273
|
+
const expired = frame.expired.flatMap((authority) => tracking.get(authority) ?? []);
|
|
274
|
+
discovering.expired?.(expired);
|
|
243
275
|
emit({
|
|
244
276
|
kind: 'caught-up',
|
|
245
|
-
expired:
|
|
277
|
+
expired: [...expired.map(({ locator }) => locator), ...(unanswered.shift() ?? [])],
|
|
246
278
|
});
|
|
247
279
|
return;
|
|
248
280
|
}
|
|
@@ -255,6 +287,7 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
255
287
|
if (frame.type === 'conversations') {
|
|
256
288
|
emitConversation({
|
|
257
289
|
kind: 'list',
|
|
290
|
+
agents: frame.agents.map(listedAgent),
|
|
258
291
|
entries: frame.conversations.map(listedConversation),
|
|
259
292
|
whole: frame.whole,
|
|
260
293
|
more: frame.more,
|
|
@@ -266,6 +299,10 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
266
299
|
emitConversation({ kind: 'listed', entry: listedConversation(frame.conversation) });
|
|
267
300
|
return;
|
|
268
301
|
}
|
|
302
|
+
if (frame.type === 'agent') {
|
|
303
|
+
emitConversation({ kind: 'agent', agent: listedAgent(frame.agent) });
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
269
306
|
if (frame.type === 'conversation_deleted') {
|
|
270
307
|
emitConversation({ kind: 'unlisted', conversation: frame.conversation_id });
|
|
271
308
|
return;
|
|
@@ -275,7 +312,7 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
275
312
|
frame.type === 'commands' ||
|
|
276
313
|
frame.type === 'options' ||
|
|
277
314
|
frame.type === 'starting' ||
|
|
278
|
-
frame.type === '
|
|
315
|
+
frame.type === 'state' ||
|
|
279
316
|
frame.type === 'link' ||
|
|
280
317
|
frame.type === 'deliveries' ||
|
|
281
318
|
frame.type === 'interactions' ||
|
|
@@ -293,7 +330,9 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
293
330
|
const after = position(frame.after);
|
|
294
331
|
if (at === null || after === null || after >= at)
|
|
295
332
|
return;
|
|
296
|
-
const from =
|
|
333
|
+
const from = after === 0n && !heldAtZero.has(frame.authority)
|
|
334
|
+
? null
|
|
335
|
+
: roomVersion({ position: frame.after, logEpoch: frame.log_epoch });
|
|
297
336
|
const version = roomVersion({ position: frame.position, logEpoch: frame.log_epoch });
|
|
298
337
|
for (const tracked of tracking.get(frame.authority) ?? []) {
|
|
299
338
|
emit({
|
|
@@ -301,18 +340,21 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
301
340
|
locator: tracked.locator,
|
|
302
341
|
from,
|
|
303
342
|
roomVersion: version,
|
|
304
|
-
read: () => changePage(tracked, entries, version, mode),
|
|
343
|
+
read: () => changePage(tracked, entries, version, mode, from === null),
|
|
305
344
|
});
|
|
306
345
|
}
|
|
307
346
|
}
|
|
308
347
|
stream.observe((frame) => handle(frame, socket));
|
|
309
348
|
stream.opened(reopened);
|
|
310
|
-
stream.closed(({ revoked, lost }) => {
|
|
349
|
+
stream.closed(({ revoked, lost, authorityChanged }) => {
|
|
311
350
|
opening = null;
|
|
312
351
|
announced = null;
|
|
313
352
|
socket = null;
|
|
314
353
|
staged.clear();
|
|
315
|
-
|
|
354
|
+
spaces = spaceSchemas();
|
|
355
|
+
unanswered.length = 0;
|
|
356
|
+
heldAtZero.clear();
|
|
357
|
+
emit({ kind: 'closed', revoked, lost, authorityChanged });
|
|
316
358
|
});
|
|
317
359
|
return {
|
|
318
360
|
runtime,
|
|
@@ -337,20 +379,19 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
337
379
|
conversationObservers.delete(notify);
|
|
338
380
|
};
|
|
339
381
|
},
|
|
340
|
-
...(mode === 'credential'
|
|
341
|
-
? {
|
|
342
|
-
agents: () => houseAgents(transport),
|
|
343
|
-
history: (request) => houseHistory(transport, request),
|
|
344
|
-
}
|
|
345
|
-
: {}),
|
|
382
|
+
...(mode === 'credential' ? { history: (request) => houseHistory(transport, request) } : {}),
|
|
346
383
|
},
|
|
347
384
|
observe(notify) {
|
|
348
385
|
observers.add(notify);
|
|
349
|
-
|
|
350
|
-
|
|
386
|
+
if (opening !== null) {
|
|
387
|
+
const replayed = [{ kind: 'opened' }];
|
|
388
|
+
if (announced !== null)
|
|
389
|
+
replayed.push(announced);
|
|
390
|
+
replaying.set(notify, replayed);
|
|
351
391
|
queueMicrotask(() => {
|
|
392
|
+
replaying.delete(notify);
|
|
352
393
|
for (const event of replayed)
|
|
353
|
-
if (
|
|
394
|
+
if (observers.has(notify))
|
|
354
395
|
notify(event);
|
|
355
396
|
});
|
|
356
397
|
}
|
|
@@ -361,13 +402,57 @@ export function houseNotifications(transport, mode, discovering) {
|
|
|
361
402
|
send(rooms) {
|
|
362
403
|
opening = null;
|
|
363
404
|
announced = null;
|
|
364
|
-
socket
|
|
405
|
+
if (socket === null)
|
|
406
|
+
return;
|
|
407
|
+
const named = rooms.flatMap((room) => {
|
|
408
|
+
const entry = located.get(room.locator);
|
|
409
|
+
const at = room.roomVersion === null ? null : logPosition(room.roomVersion);
|
|
410
|
+
return entry === undefined || at === null ? [] : [{ entry, at }];
|
|
411
|
+
});
|
|
412
|
+
const unheld = rooms.flatMap((room) => {
|
|
413
|
+
const entry = located.get(room.locator);
|
|
414
|
+
return entry === undefined || room.roomVersion !== null ? [] : [entry];
|
|
415
|
+
});
|
|
416
|
+
for (const { entry, at } of named) {
|
|
417
|
+
if (at.position === '0')
|
|
418
|
+
heldAtZero.add(entry.authority);
|
|
419
|
+
else
|
|
420
|
+
heldAtZero.delete(entry.authority);
|
|
421
|
+
}
|
|
422
|
+
for (const entry of unheld)
|
|
423
|
+
heldAtZero.delete(entry.authority);
|
|
424
|
+
const site = mode === 'site';
|
|
425
|
+
unanswered.push(site ? unheld.map((entry) => entry.locator) : []);
|
|
426
|
+
socket.hold([
|
|
427
|
+
...named.map(({ entry, at }) => presented(entry.authority, at)),
|
|
428
|
+
...(site ? [] : unheld).map((entry) => presented(entry.authority, { position: '0', logEpoch: entry.logEpoch })),
|
|
429
|
+
], runtime, listedCursor);
|
|
430
|
+
if (site)
|
|
431
|
+
return;
|
|
432
|
+
const made = unheld.filter((entry) => entry.position === '0');
|
|
433
|
+
queueMicrotask(() => {
|
|
434
|
+
for (const entry of made) {
|
|
435
|
+
const version = roomVersion(entry);
|
|
436
|
+
emit({
|
|
437
|
+
kind: 'room-change',
|
|
438
|
+
locator: entry.locator,
|
|
439
|
+
from: null,
|
|
440
|
+
roomVersion: version,
|
|
441
|
+
read: () => changePage(entry, [], version, mode, true),
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
});
|
|
365
445
|
},
|
|
366
446
|
track(entries) {
|
|
367
447
|
tracking.clear();
|
|
448
|
+
located.clear();
|
|
368
449
|
for (const entry of entries) {
|
|
369
450
|
tracking.set(entry.authority, [...(tracking.get(entry.authority) ?? []), entry]);
|
|
370
451
|
}
|
|
452
|
+
for (const held of tracking.values()) {
|
|
453
|
+
for (const entry of held)
|
|
454
|
+
located.set(entry.locator, entry);
|
|
455
|
+
}
|
|
371
456
|
for (const [carry, held] of staged) {
|
|
372
457
|
if (!tracking.has(held.authority))
|
|
373
458
|
staged.delete(carry);
|