@agentshouse/mdruntime-adapter 0.1.0-c68e0cc9f37b1 → 0.1.0-c699cfc0760da
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/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +1 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +68 -59
- package/dist/authored-path.d.ts +0 -1
- package/dist/authored-path.d.ts.map +1 -1
- package/dist/authored-path.js +1 -2
- package/dist/chunks.d.ts +2 -3
- package/dist/chunks.d.ts.map +1 -1
- package/dist/chunks.js +46 -34
- package/dist/discovery.d.ts +23 -5
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +152 -17
- package/dist/index.d.ts +4 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -7
- package/dist/model.d.ts +5 -5
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +17 -27
- package/dist/read.d.ts +5 -19
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +34 -35
- package/dist/refusal.d.ts +4 -1
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +11 -0
- package/dist/room-query.d.ts +4 -0
- package/dist/room-query.d.ts.map +1 -0
- package/dist/room-query.js +36 -0
- package/dist/session-content/index.d.ts +1 -1
- package/dist/session-content/parts.d.ts +4 -3
- package/dist/session-content/state.d.ts +4 -6
- package/dist/session-content/turn.d.ts +7 -9
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +21 -11
- package/dist/space-schema.d.ts +1 -1
- package/dist/space-schema.d.ts.map +1 -1
- package/dist/space-schema.js +2 -9
- package/dist/stream.d.ts +2 -3
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +70 -86
- package/dist/transport.d.ts +35 -7
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +36 -1
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +2 -4
- package/package.json +3 -2
- package/dist/app-reference.d.ts +0 -1
- package/dist/app-reference.d.ts.map +0 -1
- package/dist/app-reference.js +0 -2
- package/dist/crockford.d.ts +0 -3
- package/dist/crockford.d.ts.map +0 -1
- package/dist/crockford.js +0 -3
- package/dist/house-model.d.ts +0 -826
- package/dist/house-model.d.ts.map +0 -1
- package/dist/house-model.js +0 -464
- package/dist/room-types.d.ts +0 -4
- package/dist/room-types.d.ts.map +0 -1
- package/dist/room-types.js +0 -136
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { answeredFailure, doorRefusal } from './refusal.js';
|
|
2
|
+
import { houseDoorRoute, SITE_QUERY_ROUTE_CHARACTERS, siteQueryRoute, } from './transport.js';
|
|
3
|
+
const TOO_LONG_FOR_AN_ADDRESS = {
|
|
4
|
+
kind: 'rejected',
|
|
5
|
+
code: 'query_too_large',
|
|
6
|
+
fields: {},
|
|
7
|
+
retryable: false,
|
|
8
|
+
};
|
|
9
|
+
export async function houseQuery(transport, request) {
|
|
10
|
+
return queriedRows(await transport.door(houseDoorRoute('rooms/query'), {
|
|
11
|
+
room_ref: request.room,
|
|
12
|
+
query: request.query,
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
export async function siteQuery(transport, request) {
|
|
16
|
+
const route = siteQueryRoute(request.room, request.query);
|
|
17
|
+
if (route.length > SITE_QUERY_ROUTE_CHARACTERS)
|
|
18
|
+
return TOO_LONG_FOR_AN_ADDRESS;
|
|
19
|
+
return queriedRows(await transport.read(route));
|
|
20
|
+
}
|
|
21
|
+
function queriedRows(answer) {
|
|
22
|
+
if (answer.status === 401)
|
|
23
|
+
return { kind: 'revoked-authorization' };
|
|
24
|
+
const refusal = doorRefusal(answer.body);
|
|
25
|
+
if (refusal !== null)
|
|
26
|
+
return { kind: 'rejected', ...refusal };
|
|
27
|
+
const { documents, next } = (answer.body ?? {});
|
|
28
|
+
if (answer.status !== 200 || !Array.isArray(documents)) {
|
|
29
|
+
return answeredFailure(answer.status, answer.body);
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
kind: 'rows',
|
|
33
|
+
documents: documents,
|
|
34
|
+
...(typeof next === 'string' ? { next } : {}),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { DIFF_CHARACTERS, FIRST_PART_CHARACTERS, firstPart, keptDiff, lastLines, OUTPUT_CHARACTERS, OUTPUT_LINES, } from './bounds.js';
|
|
2
2
|
export { isOwn, isPart } from './parts.js';
|
|
3
|
-
export type { Call, FileChange, Part, Status } from './parts.js';
|
|
3
|
+
export type { Call, FileChange, Part, PartOf, Status } from './parts.js';
|
|
4
4
|
export { isState, standingState } from './state.js';
|
|
5
5
|
export type { SessionState, Tokens } from './state.js';
|
|
6
6
|
export { applied, isOperation, isTurn } from './turn.js';
|
|
@@ -66,7 +66,7 @@ declare const PART: Check<import("./check.js").Shaped<{
|
|
|
66
66
|
}> | import("./check.js").Shaped<{
|
|
67
67
|
readonly type: Check<"message">;
|
|
68
68
|
readonly parent: Check<number | null>;
|
|
69
|
-
readonly command: Check<
|
|
69
|
+
readonly command: Check<"agent-functions/cancel" | "agent-functions/mail/send" | "agent-functions/send">;
|
|
70
70
|
readonly target: Check<string | null>;
|
|
71
71
|
}> | import("./check.js").Shaped<{
|
|
72
72
|
readonly type: Check<"image">;
|
|
@@ -94,9 +94,10 @@ declare const PART: Check<import("./check.js").Shaped<{
|
|
|
94
94
|
readonly status: Check<"done" | "failed" | "running" | "stopped">;
|
|
95
95
|
}>>;
|
|
96
96
|
export type Part = Checked<typeof PART>;
|
|
97
|
-
export type
|
|
98
|
-
readonly type:
|
|
97
|
+
export type PartOf<T extends Part['type']> = Extract<Part, {
|
|
98
|
+
readonly type: T;
|
|
99
99
|
}>;
|
|
100
|
+
export type Call = PartOf<'call'>;
|
|
100
101
|
export declare const isPart: Check<Part>;
|
|
101
102
|
export declare function isOwn(part: Part): boolean;
|
|
102
103
|
export {};
|
|
@@ -33,11 +33,11 @@ declare const STATE: Check<import("./check.js").Shaped<{
|
|
|
33
33
|
readonly cache_write: Check<number>;
|
|
34
34
|
}> | null>;
|
|
35
35
|
readonly duration: Check<number | null>;
|
|
36
|
-
readonly files: Check<
|
|
37
|
-
readonly
|
|
36
|
+
readonly files: Check<import("./check.js").Shaped<{
|
|
37
|
+
readonly count: Check<number>;
|
|
38
38
|
readonly added: Check<number>;
|
|
39
39
|
readonly removed: Check<number>;
|
|
40
|
-
}
|
|
40
|
+
}>>;
|
|
41
41
|
readonly branch: Check<string | null>;
|
|
42
42
|
readonly worktree: Check<string | null>;
|
|
43
43
|
readonly pull: Check<import("./check.js").Shaped<{
|
|
@@ -50,9 +50,7 @@ declare const STATE: Check<import("./check.js").Shaped<{
|
|
|
50
50
|
readonly suggestion: Check<string | null>;
|
|
51
51
|
readonly running: Check<readonly import("./check.js").Shaped<{
|
|
52
52
|
readonly kind: Check<"monitor" | "schedule" | "shell" | "subagent" | "task">;
|
|
53
|
-
readonly
|
|
54
|
-
readonly progress: Check<string | null>;
|
|
55
|
-
readonly next: Check<string | null>;
|
|
53
|
+
readonly count: Check<number>;
|
|
56
54
|
}>[]>;
|
|
57
55
|
}>>;
|
|
58
56
|
export type SessionState = Checked<typeof STATE>;
|
|
@@ -60,7 +60,7 @@ declare const OPERATION: Check<import("./check.js").Shaped<{
|
|
|
60
60
|
}> | import("./check.js").Shaped<{
|
|
61
61
|
readonly type: Check<"message">;
|
|
62
62
|
readonly parent: Check<number | null>;
|
|
63
|
-
readonly command: Check<
|
|
63
|
+
readonly command: Check<"agent-functions/cancel" | "agent-functions/mail/send" | "agent-functions/send">;
|
|
64
64
|
readonly target: Check<string | null>;
|
|
65
65
|
}> | import("./check.js").Shaped<{
|
|
66
66
|
readonly type: Check<"image">;
|
|
@@ -151,7 +151,7 @@ declare const OPERATION: Check<import("./check.js").Shaped<{
|
|
|
151
151
|
}> | import("./check.js").Shaped<{
|
|
152
152
|
readonly type: Check<"message">;
|
|
153
153
|
readonly parent: Check<number | null>;
|
|
154
|
-
readonly command: Check<
|
|
154
|
+
readonly command: Check<"agent-functions/cancel" | "agent-functions/mail/send" | "agent-functions/send">;
|
|
155
155
|
readonly target: Check<string | null>;
|
|
156
156
|
}> | import("./check.js").Shaped<{
|
|
157
157
|
readonly type: Check<"image">;
|
|
@@ -239,7 +239,7 @@ declare const TURN: Check<import("./check.js").Shaped<{
|
|
|
239
239
|
}> | import("./check.js").Shaped<{
|
|
240
240
|
readonly type: Check<"message">;
|
|
241
241
|
readonly parent: Check<number | null>;
|
|
242
|
-
readonly command: Check<
|
|
242
|
+
readonly command: Check<"agent-functions/cancel" | "agent-functions/mail/send" | "agent-functions/send">;
|
|
243
243
|
readonly target: Check<string | null>;
|
|
244
244
|
}> | import("./check.js").Shaped<{
|
|
245
245
|
readonly type: Check<"image">;
|
|
@@ -299,11 +299,11 @@ declare const TURN: Check<import("./check.js").Shaped<{
|
|
|
299
299
|
readonly cache_write: Check<number>;
|
|
300
300
|
}> | null>;
|
|
301
301
|
readonly duration: Check<number | null>;
|
|
302
|
-
readonly files: Check<
|
|
303
|
-
readonly
|
|
302
|
+
readonly files: Check<import("./check.js").Shaped<{
|
|
303
|
+
readonly count: Check<number>;
|
|
304
304
|
readonly added: Check<number>;
|
|
305
305
|
readonly removed: Check<number>;
|
|
306
|
-
}
|
|
306
|
+
}>>;
|
|
307
307
|
readonly branch: Check<string | null>;
|
|
308
308
|
readonly worktree: Check<string | null>;
|
|
309
309
|
readonly pull: Check<import("./check.js").Shaped<{
|
|
@@ -316,9 +316,7 @@ declare const TURN: Check<import("./check.js").Shaped<{
|
|
|
316
316
|
readonly suggestion: Check<string | null>;
|
|
317
317
|
readonly running: Check<readonly import("./check.js").Shaped<{
|
|
318
318
|
readonly kind: Check<"monitor" | "schedule" | "shell" | "subagent" | "task">;
|
|
319
|
-
readonly
|
|
320
|
-
readonly progress: Check<string | null>;
|
|
321
|
-
readonly next: Check<string | null>;
|
|
319
|
+
readonly count: Check<number>;
|
|
322
320
|
}>[]>;
|
|
323
321
|
}>>;
|
|
324
322
|
}>>;
|
package/dist/site.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,OAAO,EAQR,MAAM,wBAAwB,CAAC;AAchC,OAAO,EAIL,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAwBxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,EAAE,QAAQ,UAAQ,GAAG,OAAO,CAoK1F"}
|
package/dist/site.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
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 { spaceSchemas } from './space-schema.js';
|
|
5
5
|
import { answeredFailure, discoveryFailure } from './refusal.js';
|
|
6
6
|
import { admittedPath } from './authored-path.js';
|
|
7
|
-
import {
|
|
8
|
-
import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
|
|
7
|
+
import { siteQuery } from './room-query.js';
|
|
9
8
|
import { houseNotifications } from './stream.js';
|
|
10
|
-
import { houseSiteRoute,
|
|
9
|
+
import { houseSiteRoute, SITE_DOOR_ACTS, SITE_FILES, } from './transport.js';
|
|
11
10
|
import { UNANSWERED, unusable } from './uncertain.js';
|
|
12
11
|
import { followsVersion, reachedVersion, roomVersion } from './version.js';
|
|
13
12
|
function unfound() {
|
|
@@ -27,14 +26,13 @@ function siteRoom(tracked) {
|
|
|
27
26
|
};
|
|
28
27
|
}
|
|
29
28
|
export function createSiteAdapter(transport, snapshot = false) {
|
|
30
|
-
const spaces = spaceSchemas();
|
|
31
29
|
const notifications = houseNotifications(transport, 'site', {
|
|
32
30
|
opened: async () => {
|
|
33
31
|
const found = await discovered();
|
|
34
32
|
return found.kind === 'discovery' ? found : null;
|
|
35
33
|
},
|
|
36
34
|
changed: () => null,
|
|
37
|
-
}
|
|
35
|
+
});
|
|
38
36
|
const tracked = new Map();
|
|
39
37
|
const chunked = new Map();
|
|
40
38
|
function fileRoute(request) {
|
|
@@ -48,7 +46,7 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
48
46
|
const listed = siteChunkList(await transport.read(`${houseSiteRoute('chunks')}/${entry.authority}${past === undefined ? '' : `?expired=${past}`}`), entry.locator);
|
|
49
47
|
if ('kind' in listed)
|
|
50
48
|
return listed;
|
|
51
|
-
const head = await chunkedHead(listed, entry
|
|
49
|
+
const head = await chunkedHead(listed, entry);
|
|
52
50
|
if (head.kind === 'bootstrap')
|
|
53
51
|
chunked.set(entry.locator, listed);
|
|
54
52
|
return head;
|
|
@@ -76,12 +74,18 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
76
74
|
for (const entry of entries)
|
|
77
75
|
tracked.set(entry.locator, entry);
|
|
78
76
|
notifications.track(entries);
|
|
79
|
-
return
|
|
77
|
+
return {
|
|
78
|
+
...mapDiscovery(document, entries.map(siteRoom), siteCapabilities()),
|
|
79
|
+
queriesOnly: document.queriesOnly.map(({ roomRef, roomHandle }) => ({
|
|
80
|
+
locator: roomRef,
|
|
81
|
+
handle: roomHandle,
|
|
82
|
+
name: roomHandle,
|
|
83
|
+
})),
|
|
84
|
+
};
|
|
80
85
|
}
|
|
81
86
|
return {
|
|
82
87
|
localSaves: true,
|
|
83
88
|
roomTypes: HOUSE_ROOM_TYPES,
|
|
84
|
-
nameableRoomTypes: HOUSE_NAMEABLE_ROOM_TYPES,
|
|
85
89
|
typedPaths: HOUSE_TYPED_PATHS,
|
|
86
90
|
pathRule: admittedPath,
|
|
87
91
|
async authorize() {
|
|
@@ -119,6 +123,7 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
119
123
|
async history() {
|
|
120
124
|
return { kind: 'no-history' };
|
|
121
125
|
},
|
|
126
|
+
queryHouse: snapshot ? undefined : (_authorization, request) => siteQuery(transport, request),
|
|
122
127
|
async binary(_authorization, request) {
|
|
123
128
|
const route = fileRoute(request);
|
|
124
129
|
if (typeof route !== 'string')
|
|
@@ -133,6 +138,8 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
133
138
|
return { kind: 'binary', body: read.body, mediaType: read.mediaType };
|
|
134
139
|
},
|
|
135
140
|
async link(_authorization, request) {
|
|
141
|
+
if (request.kind === 'key')
|
|
142
|
+
return unfound();
|
|
136
143
|
const route = fileRoute(request);
|
|
137
144
|
if (typeof route !== 'string')
|
|
138
145
|
return route;
|
|
@@ -149,7 +156,10 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
149
156
|
return followsVersion(version, next);
|
|
150
157
|
},
|
|
151
158
|
async action(_authorization, request) {
|
|
152
|
-
|
|
159
|
+
const route = Object.hasOwn(SITE_DOOR_ACTS, request.name)
|
|
160
|
+
? SITE_DOOR_ACTS[request.name]
|
|
161
|
+
: null;
|
|
162
|
+
if (route === null) {
|
|
153
163
|
return {
|
|
154
164
|
kind: 'rejected',
|
|
155
165
|
code: 'action-unimplemented',
|
|
@@ -159,7 +169,7 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
159
169
|
}
|
|
160
170
|
if (!transport.online())
|
|
161
171
|
return UNANSWERED;
|
|
162
|
-
return actionOutcome(await transport.door(
|
|
172
|
+
return actionOutcome(await transport.door(route, request.input), request.name, request.input);
|
|
163
173
|
},
|
|
164
174
|
roomStream: snapshot
|
|
165
175
|
? undefined
|
package/dist/space-schema.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ export type SpaceSchemas = {
|
|
|
2
2
|
held(space: string, revision: string): string | undefined;
|
|
3
3
|
keep(space: string, revision: string, text: string): void;
|
|
4
4
|
};
|
|
5
|
-
export declare function spaceSchemas(
|
|
5
|
+
export declare function spaceSchemas(): SpaceSchemas;
|
|
6
6
|
export declare function spaceIdentity(space: string): string;
|
|
@@ -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
|
-
|
|
2
|
-
export function spaceSchemas(most = HELD_TEXTS) {
|
|
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 > most)
|
|
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,4 +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
|
|
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,
|
|
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,52 +1,35 @@
|
|
|
1
|
-
import { ROW_WEIGHT, stepped,
|
|
1
|
+
import { ROW_WEIGHT, stepped, } from '@agentshouse/mdruntime';
|
|
2
2
|
import { acceptedMessage, changeCursor, houseHistory } from './history.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { houseDoorRoute, } from './transport.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';
|
|
7
6
|
import { DECIMAL, logPosition, presented, roomVersion } from './version.js';
|
|
8
7
|
function turnOperation(frame) {
|
|
9
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
{
|
|
30
|
-
agent: id,
|
|
31
|
-
name,
|
|
32
|
-
retired: retired !== null && retired !== undefined,
|
|
33
|
-
cli,
|
|
34
|
-
environment: {
|
|
35
|
-
identity: environment,
|
|
36
|
-
name: environmentName,
|
|
37
|
-
state: connected ? 'online' : 'offline',
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
]
|
|
41
|
-
: [];
|
|
42
|
-
});
|
|
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
|
+
};
|
|
43
28
|
}
|
|
44
29
|
function listedConversation(listed) {
|
|
45
30
|
return {
|
|
46
31
|
conversation: listed.conversation_id,
|
|
47
32
|
agent: listed.agent_id,
|
|
48
|
-
agentName: listed.agent_name,
|
|
49
|
-
agentRetired: listed.agent_retired,
|
|
50
33
|
name: listed.name,
|
|
51
34
|
created: listed.created_at,
|
|
52
35
|
finished: listed.finished_at,
|
|
@@ -54,6 +37,7 @@ function listedConversation(listed) {
|
|
|
54
37
|
waiting: listed.waiting,
|
|
55
38
|
newest: listed.newest === null ? null : changeCursor(listed.newest),
|
|
56
39
|
processEnded: listed.process_ended_at,
|
|
40
|
+
subject: listed.subject,
|
|
57
41
|
};
|
|
58
42
|
}
|
|
59
43
|
function position(value) {
|
|
@@ -61,55 +45,47 @@ function position(value) {
|
|
|
61
45
|
return null;
|
|
62
46
|
return BigInt(value);
|
|
63
47
|
}
|
|
64
|
-
function* changed(tracked, entries, version, schemas) {
|
|
48
|
+
function* changed(tracked, entries, version, mode, schemas) {
|
|
65
49
|
const answer = answering();
|
|
66
50
|
for (const entry of entries) {
|
|
67
|
-
yield ROW_WEIGHT + (entry.
|
|
51
|
+
yield ROW_WEIGHT + (entry.content?.length ?? 0);
|
|
68
52
|
if (entry.kind === 'folder') {
|
|
69
53
|
folded(answer, entry.path, entry.removed === true);
|
|
70
54
|
continue;
|
|
71
55
|
}
|
|
72
|
-
if (entry.path === tracked.schema)
|
|
73
|
-
schemas.set(entry.path, entry);
|
|
74
|
-
forgotten(answer, entry.path);
|
|
75
|
-
if (entry.space !== undefined) {
|
|
76
|
-
answer.removals.add(entry.path);
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
56
|
if (entry.kind === 'removed') {
|
|
57
|
+
if (entry.path === tracked.schema)
|
|
58
|
+
schemas.set(entry.path, null);
|
|
59
|
+
forgotten(answer, entry.path);
|
|
80
60
|
answer.removals.add(entry.path);
|
|
81
61
|
continue;
|
|
82
62
|
}
|
|
83
|
-
const
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const head = headChange(entry);
|
|
94
|
-
if (head)
|
|
95
|
-
answer.changes.set(entry.path, head);
|
|
96
|
-
const created = createdOf(entry);
|
|
97
|
-
if (created)
|
|
98
|
-
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);
|
|
99
73
|
}
|
|
100
74
|
return { kind: 'net-advancement', roomVersion: version, ...(yield* answered(answer)) };
|
|
101
75
|
}
|
|
102
|
-
async function changePage(tracked, entries, version, mode,
|
|
76
|
+
async function changePage(tracked, entries, version, mode, whole) {
|
|
103
77
|
const schemas = new Map();
|
|
104
|
-
const page = await stepped(changed(tracked, entries, version, schemas));
|
|
105
|
-
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);
|
|
106
80
|
return models === undefined ? page : { ...page, models };
|
|
107
81
|
}
|
|
108
|
-
export function houseNotifications(transport, mode, discovering
|
|
82
|
+
export function houseNotifications(transport, mode, discovering) {
|
|
109
83
|
const stream = transport.stream;
|
|
110
84
|
const staged = new Map();
|
|
85
|
+
let spaces = spaceSchemas();
|
|
111
86
|
let socket = null;
|
|
112
87
|
const tracking = new Map();
|
|
88
|
+
const located = new Map();
|
|
113
89
|
const observers = new Set();
|
|
114
90
|
const replaying = new Map();
|
|
115
91
|
const conversationObservers = new Set();
|
|
@@ -151,6 +127,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
151
127
|
announced = null;
|
|
152
128
|
socket = next;
|
|
153
129
|
staged.clear();
|
|
130
|
+
spaces = spaceSchemas();
|
|
154
131
|
unanswered.length = 0;
|
|
155
132
|
heldAtZero.clear();
|
|
156
133
|
const gapped = new Set([...replicated, ...live]);
|
|
@@ -243,6 +220,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
243
220
|
emitConversation({ kind: 'accepted-message', conversation, message });
|
|
244
221
|
}
|
|
245
222
|
function stage(frame, via) {
|
|
223
|
+
const entries = spaceSchemaTexts(frame.entries, spaces);
|
|
246
224
|
const held = staged.get(frame.carry);
|
|
247
225
|
if (frame.index !== (held?.parts ?? 0)) {
|
|
248
226
|
staged.delete(frame.carry);
|
|
@@ -255,8 +233,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
255
233
|
}
|
|
256
234
|
}
|
|
257
235
|
const next = held ?? { authority: frame.authority, parts: 0, entries: [] };
|
|
258
|
-
|
|
259
|
-
next.entries.push(...frame.entries);
|
|
236
|
+
next.entries.push(...entries);
|
|
260
237
|
next.parts += 1;
|
|
261
238
|
staged.set(frame.carry, next);
|
|
262
239
|
via?.received(frame.authority, frame.carry, frame.index);
|
|
@@ -283,16 +260,18 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
283
260
|
return;
|
|
284
261
|
}
|
|
285
262
|
if (frame.type === 'caught_up') {
|
|
286
|
-
|
|
263
|
+
const expired = frame.expired.flatMap((authority) => tracking.get(authority) ?? []);
|
|
264
|
+
discovering.expired?.(expired);
|
|
287
265
|
emit({
|
|
288
266
|
kind: 'caught-up',
|
|
289
|
-
expired: [
|
|
290
|
-
...frame.expired.flatMap((authority) => (tracking.get(authority) ?? []).map((tracked) => tracked.locator)),
|
|
291
|
-
...(unanswered.shift() ?? []),
|
|
292
|
-
],
|
|
267
|
+
expired: [...expired.map(({ locator }) => locator), ...(unanswered.shift() ?? [])],
|
|
293
268
|
});
|
|
294
269
|
return;
|
|
295
270
|
}
|
|
271
|
+
if (frame.type === 'report') {
|
|
272
|
+
emit({ kind: 'reported' });
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
296
275
|
if (frame.type === 'authority_changed') {
|
|
297
276
|
const change = discovering.changed(frame);
|
|
298
277
|
if (change !== null)
|
|
@@ -302,6 +281,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
302
281
|
if (frame.type === 'conversations') {
|
|
303
282
|
emitConversation({
|
|
304
283
|
kind: 'list',
|
|
284
|
+
agents: frame.agents.map(listedAgent),
|
|
305
285
|
entries: frame.conversations.map(listedConversation),
|
|
306
286
|
whole: frame.whole,
|
|
307
287
|
more: frame.more,
|
|
@@ -313,6 +293,10 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
313
293
|
emitConversation({ kind: 'listed', entry: listedConversation(frame.conversation) });
|
|
314
294
|
return;
|
|
315
295
|
}
|
|
296
|
+
if (frame.type === 'agent') {
|
|
297
|
+
emitConversation({ kind: 'agent', agent: listedAgent(frame.agent) });
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
316
300
|
if (frame.type === 'conversation_deleted') {
|
|
317
301
|
emitConversation({ kind: 'unlisted', conversation: frame.conversation_id });
|
|
318
302
|
return;
|
|
@@ -350,7 +334,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
350
334
|
locator: tracked.locator,
|
|
351
335
|
from,
|
|
352
336
|
roomVersion: version,
|
|
353
|
-
read: () => changePage(tracked, entries, version, mode,
|
|
337
|
+
read: () => changePage(tracked, entries, version, mode, from === null),
|
|
354
338
|
});
|
|
355
339
|
}
|
|
356
340
|
}
|
|
@@ -361,6 +345,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
361
345
|
announced = null;
|
|
362
346
|
socket = null;
|
|
363
347
|
staged.clear();
|
|
348
|
+
spaces = spaceSchemas();
|
|
364
349
|
unanswered.length = 0;
|
|
365
350
|
heldAtZero.clear();
|
|
366
351
|
emit({ kind: 'closed', revoked, lost, authorityChanged });
|
|
@@ -388,12 +373,7 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
388
373
|
conversationObservers.delete(notify);
|
|
389
374
|
};
|
|
390
375
|
},
|
|
391
|
-
...(mode === 'credential'
|
|
392
|
-
? {
|
|
393
|
-
agents: () => houseAgents(transport),
|
|
394
|
-
history: (request) => houseHistory(transport, request),
|
|
395
|
-
}
|
|
396
|
-
: {}),
|
|
376
|
+
...(mode === 'credential' ? { history: (request) => houseHistory(transport, request) } : {}),
|
|
397
377
|
},
|
|
398
378
|
observe(notify) {
|
|
399
379
|
observers.add(notify);
|
|
@@ -418,14 +398,13 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
418
398
|
announced = null;
|
|
419
399
|
if (socket === null)
|
|
420
400
|
return;
|
|
421
|
-
const entries = new Map([...tracking.values()].flat().map((tracked) => [tracked.locator, tracked]));
|
|
422
401
|
const named = rooms.flatMap((room) => {
|
|
423
|
-
const entry =
|
|
402
|
+
const entry = located.get(room.locator);
|
|
424
403
|
const at = room.roomVersion === null ? null : logPosition(room.roomVersion);
|
|
425
404
|
return entry === undefined || at === null ? [] : [{ entry, at }];
|
|
426
405
|
});
|
|
427
406
|
const unheld = rooms.flatMap((room) => {
|
|
428
|
-
const entry =
|
|
407
|
+
const entry = located.get(room.locator);
|
|
429
408
|
return entry === undefined || room.roomVersion !== null ? [] : [entry];
|
|
430
409
|
});
|
|
431
410
|
for (const { entry, at } of named) {
|
|
@@ -453,16 +432,21 @@ export function houseNotifications(transport, mode, discovering, spaces) {
|
|
|
453
432
|
locator: entry.locator,
|
|
454
433
|
from: null,
|
|
455
434
|
roomVersion: version,
|
|
456
|
-
read: () => changePage(entry, [], version, mode,
|
|
435
|
+
read: () => changePage(entry, [], version, mode, true),
|
|
457
436
|
});
|
|
458
437
|
}
|
|
459
438
|
});
|
|
460
439
|
},
|
|
461
440
|
track(entries) {
|
|
462
441
|
tracking.clear();
|
|
442
|
+
located.clear();
|
|
463
443
|
for (const entry of entries) {
|
|
464
444
|
tracking.set(entry.authority, [...(tracking.get(entry.authority) ?? []), entry]);
|
|
465
445
|
}
|
|
446
|
+
for (const held of tracking.values()) {
|
|
447
|
+
for (const entry of held)
|
|
448
|
+
located.set(entry.locator, entry);
|
|
449
|
+
}
|
|
466
450
|
for (const [carry, held] of staged) {
|
|
467
451
|
if (!tracking.has(held.authority))
|
|
468
452
|
staged.delete(carry);
|