@agentshouse/mdruntime-adapter 0.1.0-alpha.2 → 0.1.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +112 -22
- package/dist/actions.d.ts +3 -11
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +118 -223
- package/dist/actions.js.map +1 -1
- package/dist/adapter.d.ts +3 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +45 -101
- package/dist/adapter.js.map +1 -1
- package/dist/discovery.d.ts +34 -7
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +132 -29
- package/dist/discovery.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/model.d.ts +19 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +64 -0
- package/dist/model.js.map +1 -0
- package/dist/read.d.ts +16 -12
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +109 -30
- package/dist/read.js.map +1 -1
- package/dist/refusal.d.ts +4 -1
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +13 -0
- package/dist/refusal.js.map +1 -1
- package/dist/site.d.ts +4 -0
- package/dist/site.d.ts.map +1 -0
- package/dist/site.js +205 -0
- package/dist/site.js.map +1 -0
- package/dist/stream.d.ts +7 -5
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +117 -82
- package/dist/stream.js.map +1 -1
- package/dist/transport.d.ts +16 -5
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +5 -1
- package/dist/transport.js.map +1 -1
- package/dist/version.d.ts +14 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +29 -0
- package/dist/version.js.map +1 -0
- package/dist/write.d.ts +6 -0
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +24 -7
- package/dist/write.js.map +1 -1
- package/package.json +3 -3
package/dist/site.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/site.ts"],"sourcesContent":["import type {\n Adapter,\n AdapterFailure,\n BootstrapResult,\n DiscoverResult,\n DiscoveredRoom,\n ModelResult,\n RefreshResult,\n} from '@agentshouse/mdruntime';\nimport { actionOutcome } from './actions.js';\nimport {\n mapDiscovery,\n parseSiteDiscovery,\n siteCapabilities,\n siteSlots,\n siteTracked,\n type SiteTracked,\n} from './discovery.js';\nimport {\n MODEL_ABSENT,\n failedModel,\n heldModel,\n modelKey,\n modelShelf,\n type HeldModel,\n} from './model.js';\nimport {\n advancedScope,\n authorityRoot,\n bootstrapOf,\n definitionsOf,\n parseEnumeration,\n parseSiteBootstrap,\n refreshFrom,\n selectionRoots,\n type HouseEnumeration,\n type HouseScope,\n} from './read.js';\nimport { classifyDoor, discoveryFailure } from './refusal.js';\nimport { houseNotifications } from './stream.js';\nimport {\n PRIVATE_LOCATOR,\n SITE_DOOR_BOOTSTRAP,\n SITE_DOOR_DISCOVER,\n SITE_DOOR_ENUMERATE,\n SITE_DOOR_SUBMIT,\n type HouseSiteTransport,\n} from './transport.js';\nimport { logPosition, presented, roomVersion, type LogPosition } from './version.js';\n\ntype Refused = AdapterFailure | { kind: 'beyond-horizon' };\n\ntype CaughtUp = { scope: HouseScope } | { failure: AdapterFailure };\n\ntype Acquired = { roomVersion: string; model: HeldModel };\n\nconst UNCERTAIN = { kind: 'transport-uncertainty' } as const;\n\nfunction siteRoom(\n tracked: SiteTracked,\n attachedModel: DiscoveredRoom['attachedModel'],\n): DiscoveredRoom {\n const read = selectionRoots(tracked);\n return {\n name: tracked.handle,\n locator: tracked.locator,\n collectionRoot: tracked.collectionRoot,\n roomVersion: roomVersion(tracked),\n operations: { read: [...read], sync: [...read], write: [], delete: [] },\n replica: { selection: tracked.locator, admission: 'admitted' },\n attachedModel,\n providerOwnedPaths: [],\n };\n}\n\nfunction settled(refused: Refused): AdapterFailure {\n return refused.kind === 'beyond-horizon' ? UNCERTAIN : refused;\n}\n\nexport function createSiteAdapter(transport: HouseSiteTransport): Adapter {\n const notifications = houseNotifications(transport, 'site');\n const tracked = new Map<string, SiteTracked>();\n const models = modelShelf();\n const acquired = new Map<string, Acquired>();\n let caught = new Map<string, CaughtUp>();\n\n async function enumeration(\n entry: SiteTracked,\n from: LogPosition,\n ): Promise<HouseEnumeration | Refused> {\n const answer = await transport.door(SITE_DOOR_ENUMERATE, {\n positions: [presented(entry.authority, from)],\n });\n const classified = classifyDoor(answer.status, answer.body, entry.locator);\n if (classified !== null) return classified;\n return parseEnumeration(answer.body, 'site') ?? UNCERTAIN;\n }\n\n async function caughtUp(entry: SiteTracked): Promise<CaughtUp> {\n const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}`);\n const classified = classifyDoor(answer.status, answer.body, entry.locator);\n if (classified !== null) return { failure: settled(classified) };\n const scope = parseSiteBootstrap(answer.body);\n if (scope === null) return { failure: UNCERTAIN };\n if (roomVersion(scope) === roomVersion(entry)) return { scope };\n const found = await enumeration(entry, scope);\n if ('kind' in found) return { failure: settled(found) };\n const view = found.authorities.find((held) => held.authority === entry.authority);\n if (view === undefined)\n return { failure: { kind: 'room-not-readable', locator: entry.locator } };\n return { scope: advancedScope(scope, view) };\n }\n\n async function refreshed(entry: SiteTracked, fromRoomVersion: string): Promise<RefreshResult> {\n const from = logPosition(fromRoomVersion);\n if (from === null) return { kind: 'beyond-horizon' };\n const streamed = notifications.advance(entry, from);\n if (streamed !== null) return streamed;\n const found = await enumeration(entry, from);\n if ('kind' in found) return found;\n return refreshFrom(found, entry, fromRoomVersion);\n }\n\n async function acquire(entry: SiteTracked, held: CaughtUp): Promise<HeldModel> {\n if ('failure' in held) return { snapshot: failedModel(held.failure), identity: null };\n const model = await heldModel(\n definitionsOf(held.scope, entry.modelRoot),\n `${authorityRoot(entry.handle)}/${entry.modelRoot}`,\n MODEL_ABSENT,\n );\n acquired.set(entry.authority, { roomVersion: roomVersion(held.scope), model });\n return model;\n }\n\n return {\n async authorize() {\n return {};\n },\n\n async model(_authorization, request): Promise<ModelResult> {\n return models.answer(request);\n },\n\n async discover(): Promise<DiscoverResult> {\n const answer = await transport.door(SITE_DOOR_DISCOVER, {});\n const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);\n if (classified !== null) return discoveryFailure(classified);\n const document = parseSiteDiscovery(answer.body);\n if (document === null) return UNCERTAIN;\n const entries = siteTracked(document);\n tracked.clear();\n for (const entry of entries) tracked.set(entry.locator, entry);\n notifications.track(entries);\n const published = new Set(entries.map((entry) => entry.authority));\n for (const authority of [...acquired.keys()]) {\n if (!published.has(authority)) acquired.delete(authority);\n }\n const fresh = new Map<string, CaughtUp>();\n const current = new Map<string, HeldModel>();\n for (const entry of entries) {\n const kept = acquired.get(entry.authority);\n if (kept !== undefined && kept.roomVersion === roomVersion(entry)) {\n current.set(entry.authority, kept.model);\n continue;\n }\n const held = await caughtUp(entry);\n fresh.set(entry.authority, held);\n current.set(entry.authority, await acquire(entry, held));\n }\n caught = fresh;\n const rooms = entries.map((entry) => {\n const shelved = models.retain(\n modelKey(entry.locator, 'collection'),\n current.get(entry.authority),\n );\n return siteRoom(entry, shelved?.identity ?? null);\n });\n models.keep(entries.map((entry) => entry.locator));\n return { ...mapDiscovery(document, rooms, siteCapabilities()), slots: siteSlots(document) };\n },\n\n async bootstrap(_authorization, request): Promise<BootstrapResult> {\n const entry = tracked.get(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return UNCERTAIN;\n const held = caught.get(entry.authority) ?? (await caughtUp(entry));\n if ('failure' in held) return held.failure;\n return bootstrapOf(held.scope, entry);\n },\n\n async refresh(_authorization, request): Promise<RefreshResult> {\n const entry = tracked.get(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return UNCERTAIN;\n const result = await refreshed(entry, request.fromRoomVersion);\n if (result.kind === 'beyond-horizon') caught.delete(entry.authority);\n return result;\n },\n\n async mutate() {\n return { kind: 'rejected', affected: {}, code: 'write-grant', fields: {} };\n },\n\n async history() {\n return { kind: 'no-history' };\n },\n\n async action(_authorization, request) {\n if (request.name !== 'submit') {\n return { kind: 'rejected', code: 'action-unimplemented', fields: { name: request.name } };\n }\n if (!transport.online()) return UNCERTAIN;\n return actionOutcome(await transport.door(SITE_DOOR_SUBMIT, request.input), 'submit');\n },\n\n roomVersions: notifications,\n };\n}\n"],"names":["actionOutcome","mapDiscovery","parseSiteDiscovery","siteCapabilities","siteSlots","siteTracked","MODEL_ABSENT","failedModel","heldModel","modelKey","modelShelf","advancedScope","authorityRoot","bootstrapOf","definitionsOf","parseEnumeration","parseSiteBootstrap","refreshFrom","selectionRoots","classifyDoor","discoveryFailure","houseNotifications","PRIVATE_LOCATOR","SITE_DOOR_BOOTSTRAP","SITE_DOOR_DISCOVER","SITE_DOOR_ENUMERATE","SITE_DOOR_SUBMIT","logPosition","presented","roomVersion","UNCERTAIN","kind","siteRoom","tracked","attachedModel","read","name","handle","locator","collectionRoot","operations","sync","write","delete","replica","selection","admission","providerOwnedPaths","settled","refused","createSiteAdapter","transport","notifications","Map","models","acquired","caught","enumeration","entry","from","answer","door","positions","authority","classified","status","body","caughtUp","failure","scope","found","view","authorities","find","held","undefined","refreshed","fromRoomVersion","streamed","advance","acquire","snapshot","identity","model","modelRoot","set","authorize","_authorization","request","discover","document","entries","clear","track","published","Set","map","keys","has","fresh","current","kept","get","rooms","shelved","retain","keep","slots","bootstrap","pageToken","refresh","result","mutate","affected","code","fields","history","action","online","input","roomVersions"],"mappings":"AASA,SAASA,aAAa,QAAQ,eAAe;AAC7C,SACEC,YAAY,EACZC,kBAAkB,EAClBC,gBAAgB,EAChBC,SAAS,EACTC,WAAW,QAEN,iBAAiB;AACxB,SACEC,YAAY,EACZC,WAAW,EACXC,SAAS,EACTC,QAAQ,EACRC,UAAU,QAEL,aAAa;AACpB,SACEC,aAAa,EACbC,aAAa,EACbC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AAKN,OAAO;YAC1C,OAAOvD,YAAY6D,KAAKL,KAAK,EAAEX;QACjC;QAEA,MAAMoD,SAAQvB,cAAc,EAAEC,OAAO;YACnC,MAAM9B,QAAQzB,QAAQqE,GAAG,CAACd,QAAQlD,OAAO;YACzC,IAAIoB,UAAUiB,WAAW,OAAO;gBAAE5C,MAAM;gBAAqBO,SAASkD,QAAQlD,OAAO;YAAC;YACtF,IAAIkD,QAAQqB,SAAS,KAAKlC,WAAW,OAAO7C;YAC5C,MAAMiF,SAAS,MAAMnC,UAAUlB,OAAO8B,QAAQX,eAAe;YAC7D,IAAIkC,OAAOhF,IAAI,KAAK,kBAAkByB,OAAOb,MAAM,CAACe,MAAMK,SAAS;YACnE,OAAOgD;QACT;QAEA,MAAMC;YACJ,OAAO;gBAAEjF,MAAM;gBAAYkF,UAAU,CAAC;gBAAGC,MAAM;gBAAeC,QAAQ,CAAC;YAAE;QAC3E;QAEA,MAAMC;YACJ,OAAO;gBAAErF,MAAM;YAAa;QAC9B;QAEA,MAAMsF,QAAO9B,cAAc,EAAEC,OAAO;YAClC,IAAIA,QAAQpD,IAAI,KAAK,UAAU;gBAC7B,OAAO;oBAAEL,MAAM;oBAAYmF,MAAM;oBAAwBC,QAAQ;wBAAE/E,MAAMoD,QAAQpD,IAAI;oBAAC;gBAAE;YAC1F;YACA,IAAI,CAACe,UAAUmE,MAAM,IAAI,OAAOxF;YAChC,OAAO9B,cAAc,MAAMmD,UAAUU,IAAI,CAACnC,kBAAkB8D,QAAQ+B,KAAK,GAAG;QAC9E;QAEAC,cAAcpE;IAChB;AACF"}
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type { RefreshPage, SelectedRooms
|
|
1
|
+
import type { ConversationStream, RefreshPage, SelectedRooms } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
-
import {
|
|
3
|
+
import type { HouseDoor } from './transport.js';
|
|
4
|
+
import type { HouseMode } from './transport.js';
|
|
5
|
+
import { type LogPosition } from './version.js';
|
|
4
6
|
export type HouseNotifications = SelectedRooms & {
|
|
5
7
|
track(authorities: readonly TrackedAuthority[]): void;
|
|
6
|
-
advance(tracked: TrackedAuthority,
|
|
7
|
-
conversations:
|
|
8
|
+
advance(tracked: TrackedAuthority, from: LogPosition): RefreshPage | null;
|
|
9
|
+
conversations: ConversationStream;
|
|
8
10
|
};
|
|
9
|
-
export declare function houseNotifications(transport:
|
|
11
|
+
export declare function houseNotifications(transport: HouseDoor, mode: HouseMode): HouseNotifications;
|
|
10
12
|
//# sourceMappingURL=stream.d.ts.map
|
package/dist/stream.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,WAAW,EAEX,aAAa,
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAClB,WAAW,EAEX,aAAa,EACd,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,KAAK,EAAE,SAAS,EAAwB,MAAM,gBAAgB,CAAC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAsC,MAAM,gBAAgB,CAAC;AACpF,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAc7D,MAAM,MAAM,kBAAkB,GAAG,aAAa,GAAG;IAC/C,KAAK,CAAC,WAAW,EAAE,SAAS,gBAAgB,EAAE,GAAG,IAAI,CAAC;IACtD,OAAO,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,WAAW,GAAG,IAAI,CAAC;IAC1E,aAAa,EAAE,kBAAkB,CAAC;CACnC,CAAC;AAOF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,kBAAkB,CA6N5F"}
|
package/dist/stream.js
CHANGED
|
@@ -1,39 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { acceptedMessage, actionOutcome } from './actions.js';
|
|
2
2
|
import { selects } from './read.js';
|
|
3
|
-
import {
|
|
3
|
+
import { roomVersion } from './version.js';
|
|
4
4
|
const HELD_POSITIONS_MAX = 256;
|
|
5
5
|
function position(value) {
|
|
6
6
|
if (!/^(?:0|[1-9][0-9]*)$/.test(value)) return null;
|
|
7
7
|
return BigInt(value);
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
if (typeof message !== 'object' || message === null) return null;
|
|
11
|
-
const turn = message.message_id;
|
|
12
|
-
return typeof turn === 'string' ? turn : null;
|
|
13
|
-
}
|
|
14
|
-
export function houseNotifications(transport) {
|
|
9
|
+
export function houseNotifications(transport, mode) {
|
|
15
10
|
const stream = transport.stream;
|
|
16
|
-
const
|
|
11
|
+
const lines = new Map();
|
|
17
12
|
const locators = new Map();
|
|
18
13
|
const authorities = new Map();
|
|
19
14
|
const observers = new Set();
|
|
20
15
|
const conversationObservers = new Set();
|
|
21
|
-
const subscribedConversations = new Set();
|
|
22
16
|
let selected = [];
|
|
17
|
+
let replicated = [];
|
|
23
18
|
let viewed = [];
|
|
24
19
|
let listening = false;
|
|
25
20
|
function subscribe() {
|
|
26
21
|
const named = [];
|
|
22
|
+
const rooms = new Set();
|
|
27
23
|
for (const locator of selected){
|
|
28
24
|
const authority = authorities.get(locator);
|
|
29
|
-
if (authority === undefined
|
|
30
|
-
|
|
31
|
-
kind: 'room',
|
|
32
|
-
room: authority
|
|
33
|
-
});
|
|
25
|
+
if (authority === undefined) continue;
|
|
26
|
+
rooms.add(authority);
|
|
34
27
|
}
|
|
35
|
-
|
|
36
|
-
kind: '
|
|
28
|
+
for (const room of rooms)named.push({
|
|
29
|
+
kind: 'room',
|
|
30
|
+
room
|
|
37
31
|
});
|
|
38
32
|
for (const conversation of viewed){
|
|
39
33
|
named.push({
|
|
@@ -44,10 +38,11 @@ export function houseNotifications(transport) {
|
|
|
44
38
|
stream.subscribe(named);
|
|
45
39
|
}
|
|
46
40
|
function emitConversation(event) {
|
|
47
|
-
|
|
41
|
+
const delivered = event.kind === 'accepted-message' || event.kind === 'gap' ? replicated : viewed;
|
|
42
|
+
if (!delivered.includes(event.conversation)) return;
|
|
48
43
|
for (const observer of conversationObservers)observer(event);
|
|
49
44
|
}
|
|
50
|
-
async function
|
|
45
|
+
async function summarize(conversation) {
|
|
51
46
|
const viewedAnswer = await transport.door('/door/conversations/view', {
|
|
52
47
|
conversation_id: conversation
|
|
53
48
|
});
|
|
@@ -59,23 +54,38 @@ export function houseNotifications(transport) {
|
|
|
59
54
|
summary: structuredClone('session' in summary.result ? summary.result.session : null)
|
|
60
55
|
});
|
|
61
56
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
emitConversation({
|
|
70
|
-
kind: 'accepted-message',
|
|
71
|
-
conversation,
|
|
72
|
-
message: {
|
|
73
|
-
turn,
|
|
74
|
-
message: structuredClone(entry)
|
|
75
|
-
}
|
|
57
|
+
}
|
|
58
|
+
function announce(authority, at) {
|
|
59
|
+
const version = roomVersion(at);
|
|
60
|
+
for (const locator of locators.get(authority) ?? []){
|
|
61
|
+
for (const observer of observers)observer({
|
|
62
|
+
locator,
|
|
63
|
+
roomVersion: version
|
|
76
64
|
});
|
|
77
65
|
}
|
|
78
66
|
}
|
|
67
|
+
function interrupt(authority) {
|
|
68
|
+
const line = lines.get(authority);
|
|
69
|
+
if (line !== undefined) lines.set(authority, {
|
|
70
|
+
logEpoch: line.logEpoch,
|
|
71
|
+
frames: []
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function resubscribed(authority, position, logEpoch) {
|
|
75
|
+
if (position === undefined || logEpoch === undefined) {
|
|
76
|
+
interrupt(authority);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const held = lines.get(authority)?.logEpoch;
|
|
80
|
+
lines.set(authority, {
|
|
81
|
+
logEpoch,
|
|
82
|
+
frames: []
|
|
83
|
+
});
|
|
84
|
+
if (held !== logEpoch) announce(authority, {
|
|
85
|
+
position,
|
|
86
|
+
logEpoch
|
|
87
|
+
});
|
|
88
|
+
}
|
|
79
89
|
function receive(frame) {
|
|
80
90
|
if (frame.type === 'draft') {
|
|
81
91
|
emitConversation({
|
|
@@ -87,15 +97,12 @@ export function houseNotifications(transport) {
|
|
|
87
97
|
return;
|
|
88
98
|
}
|
|
89
99
|
if (frame.type === 'message') {
|
|
90
|
-
const
|
|
91
|
-
if (
|
|
100
|
+
const message = acceptedMessage(frame.message);
|
|
101
|
+
if (message === null) return;
|
|
92
102
|
emitConversation({
|
|
93
103
|
kind: 'accepted-message',
|
|
94
104
|
conversation: frame.conversation_id,
|
|
95
|
-
message
|
|
96
|
-
turn,
|
|
97
|
-
message: structuredClone(frame.message)
|
|
98
|
-
}
|
|
105
|
+
message
|
|
99
106
|
});
|
|
100
107
|
return;
|
|
101
108
|
}
|
|
@@ -108,50 +115,62 @@ export function houseNotifications(transport) {
|
|
|
108
115
|
return;
|
|
109
116
|
}
|
|
110
117
|
if (frame.type === 'subscribed' && viewed.includes(frame.authority)) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
118
|
+
emitConversation({
|
|
119
|
+
kind: 'gap',
|
|
120
|
+
conversation: frame.authority
|
|
121
|
+
});
|
|
122
|
+
void summarize(frame.authority);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (frame.type === 'subscribed') {
|
|
126
|
+
resubscribed(frame.authority, frame.position, frame.log_epoch);
|
|
114
127
|
return;
|
|
115
128
|
}
|
|
116
129
|
if (frame.type !== 'entries') {
|
|
117
|
-
|
|
130
|
+
interrupt(frame.authority);
|
|
118
131
|
return;
|
|
119
132
|
}
|
|
120
133
|
const at = position(frame.position);
|
|
121
134
|
if (at === null) {
|
|
122
|
-
|
|
135
|
+
interrupt(frame.authority);
|
|
123
136
|
return;
|
|
124
137
|
}
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
138
|
+
const line = lines.get(frame.authority);
|
|
139
|
+
if (line?.logEpoch === frame.log_epoch) {
|
|
140
|
+
const last = line.frames.at(-1);
|
|
141
|
+
const continued = last !== undefined && last.position + 1n === at;
|
|
142
|
+
const next = continued ? [
|
|
143
|
+
...line.frames,
|
|
144
|
+
{
|
|
145
|
+
position: at,
|
|
146
|
+
entries: frame.entries
|
|
147
|
+
}
|
|
148
|
+
] : [
|
|
149
|
+
{
|
|
150
|
+
position: at,
|
|
151
|
+
entries: frame.entries
|
|
152
|
+
}
|
|
153
|
+
];
|
|
154
|
+
lines.set(frame.authority, {
|
|
155
|
+
logEpoch: line.logEpoch,
|
|
156
|
+
frames: next.length > HELD_POSITIONS_MAX ? [] : next
|
|
157
|
+
});
|
|
158
|
+
} else {
|
|
159
|
+
interrupt(frame.authority);
|
|
160
|
+
}
|
|
161
|
+
announce(frame.authority, {
|
|
162
|
+
position: frame.position,
|
|
163
|
+
logEpoch: frame.log_epoch
|
|
146
164
|
});
|
|
147
165
|
}
|
|
148
166
|
return {
|
|
149
167
|
conversations: {
|
|
168
|
+
replicate (next) {
|
|
169
|
+
replicated = [
|
|
170
|
+
...next
|
|
171
|
+
];
|
|
172
|
+
},
|
|
150
173
|
view (next) {
|
|
151
|
-
const open = new Set(next);
|
|
152
|
-
for (const conversation of subscribedConversations){
|
|
153
|
-
if (!open.has(conversation)) subscribedConversations.delete(conversation);
|
|
154
|
-
}
|
|
155
174
|
viewed = [
|
|
156
175
|
...next
|
|
157
176
|
];
|
|
@@ -172,11 +191,20 @@ export function houseNotifications(transport) {
|
|
|
172
191
|
locators.clear();
|
|
173
192
|
authorities.clear();
|
|
174
193
|
for (const entry of entries){
|
|
175
|
-
locators.set(entry.authority,
|
|
194
|
+
locators.set(entry.authority, [
|
|
195
|
+
...locators.get(entry.authority) ?? [],
|
|
196
|
+
entry.locator
|
|
197
|
+
]);
|
|
176
198
|
authorities.set(entry.locator, entry.authority);
|
|
199
|
+
if (lines.get(entry.authority)?.logEpoch !== entry.logEpoch) {
|
|
200
|
+
lines.set(entry.authority, {
|
|
201
|
+
logEpoch: entry.logEpoch,
|
|
202
|
+
frames: []
|
|
203
|
+
});
|
|
204
|
+
}
|
|
177
205
|
}
|
|
178
|
-
for (const authority of
|
|
179
|
-
if (!locators.has(authority))
|
|
206
|
+
for (const authority of lines.keys()){
|
|
207
|
+
if (!locators.has(authority)) lines.delete(authority);
|
|
180
208
|
}
|
|
181
209
|
},
|
|
182
210
|
select (named) {
|
|
@@ -195,13 +223,13 @@ export function houseNotifications(transport) {
|
|
|
195
223
|
observers.delete(notify);
|
|
196
224
|
};
|
|
197
225
|
},
|
|
198
|
-
advance (tracked,
|
|
199
|
-
const
|
|
200
|
-
const
|
|
201
|
-
if (
|
|
202
|
-
const at =
|
|
226
|
+
advance (tracked, from) {
|
|
227
|
+
const line = lines.get(tracked.authority);
|
|
228
|
+
const start = position(from.position);
|
|
229
|
+
if (line === undefined || start === null || line.logEpoch !== from.logEpoch) return null;
|
|
230
|
+
const at = line.frames.findIndex((frame)=>frame.position === start + 1n);
|
|
203
231
|
if (at === -1) return null;
|
|
204
|
-
const pending =
|
|
232
|
+
const pending = line.frames.slice(at);
|
|
205
233
|
const documents = {};
|
|
206
234
|
const revisions = {};
|
|
207
235
|
const removals = [];
|
|
@@ -214,19 +242,26 @@ export function houseNotifications(transport) {
|
|
|
214
242
|
if (!removals.includes(entry.path)) removals.push(entry.path);
|
|
215
243
|
continue;
|
|
216
244
|
}
|
|
217
|
-
if (entry.text === undefined
|
|
245
|
+
if (entry.text === undefined) return null;
|
|
246
|
+
if (mode === 'credential' && entry.revision === undefined) return null;
|
|
218
247
|
documents[entry.path] = entry.text;
|
|
219
|
-
revisions[entry.path] = entry.revision;
|
|
248
|
+
if (entry.revision !== undefined) revisions[entry.path] = entry.revision;
|
|
220
249
|
const removed = removals.indexOf(entry.path);
|
|
221
250
|
if (removed !== -1) removals.splice(removed, 1);
|
|
222
251
|
}
|
|
223
252
|
}
|
|
224
253
|
const last = pending.at(-1);
|
|
225
254
|
if (last === undefined) return null;
|
|
226
|
-
|
|
255
|
+
lines.set(tracked.authority, {
|
|
256
|
+
logEpoch: line.logEpoch,
|
|
257
|
+
frames: pending
|
|
258
|
+
});
|
|
227
259
|
return {
|
|
228
260
|
kind: 'net-advancement',
|
|
229
|
-
roomVersion:
|
|
261
|
+
roomVersion: roomVersion({
|
|
262
|
+
position: last.position.toString(),
|
|
263
|
+
logEpoch: line.logEpoch
|
|
264
|
+
}),
|
|
230
265
|
documents,
|
|
231
266
|
revisions,
|
|
232
267
|
binaryTargets: [],
|
package/dist/stream.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/stream.ts"],"sourcesContent":["import type {\n ConversationEvent,\n RefreshPage,\n RoomVersionNotification,\n SelectedRooms,\n ViewedConversations,\n} from '@agentshouse/mdruntime';\nimport { actionOutcome, HISTORY_PAGE, readConversationHistory } from './actions.js';\nimport type { TrackedAuthority } from './discovery.js';\nimport { selects } from './read.js';\nimport { PRIVATE_AUTHORITY, type HouseStreamAuthority, type HouseTransport } from './transport.js';\nimport type { HouseStreamEntry, HouseStreamFrame } from './transport.js';\n\nconst HELD_POSITIONS_MAX = 256;\n\ntype HeldFrame = {\n position: bigint;\n entries: readonly HouseStreamEntry[];\n};\n\nexport type HouseNotifications = SelectedRooms & {\n track(authorities: readonly TrackedAuthority[]): void;\n advance(tracked: TrackedAuthority, fromRoomVersion: string): RefreshPage | null;\n conversations: ViewedConversations;\n};\n\nfunction position(value: string): bigint | null {\n if (!/^(?:0|[1-9][0-9]*)$/.test(value)) return null;\n return BigInt(value);\n}\n\nfunction messageTurn(message: unknown): string | null {\n if (typeof message !== 'object' || message === null) return null;\n const turn = (message as { message_id?: unknown }).message_id;\n return typeof turn === 'string' ? turn : null;\n}\n\nexport function houseNotifications(transport: HouseTransport): HouseNotifications {\n const stream = transport.stream;\n const held = new Map<string, HeldFrame[]>();\n const locators = new Map<string, string>();\n const authorities = new Map<string, string>();\n const observers = new Set<(notification: RoomVersionNotification) => void>();\n const conversationObservers = new Set<(event: ConversationEvent) => void>();\n const subscribedConversations = new Set<string>();\n let selected: readonly string[] = [];\n let viewed: readonly string[] = [];\n let listening = false;\n\n function subscribe() {\n const named: HouseStreamAuthority[] = [];\n for (const locator of selected) {\n const authority = authorities.get(locator);\n if (authority === undefined || authority === PRIVATE_AUTHORITY) continue;\n named.push({ kind: 'room', room: authority });\n }\n if (authorities.has(PRIVATE_AUTHORITY)) named.push({ kind: 'private' });\n for (const conversation of viewed) {\n named.push({ kind: 'conversation', conversation });\n }\n stream.subscribe(named);\n }\n\n function emitConversation(event: ConversationEvent) {\n if (!viewed.includes(event.conversation)) return;\n for (const observer of conversationObservers) observer(event);\n }\n\n async function catchUp(conversation: string, history: boolean) {\n const viewedAnswer = await transport.door('/door/conversations/view', {\n conversation_id: conversation,\n });\n const summary = actionOutcome(viewedAnswer, 'conversations/view');\n if (\n summary.kind === 'action' &&\n typeof summary.result === 'object' &&\n summary.result !== null\n ) {\n emitConversation({\n kind: 'session-summary',\n conversation,\n summary: structuredClone('session' in summary.result ? summary.result.session : null),\n });\n }\n if (!history) return;\n const heldHistory = await readConversationHistory(transport, conversation);\n if ('outcome' in heldHistory) return;\n const newest = heldHistory.messages.slice(-HISTORY_PAGE);\n for (const entry of newest) {\n const turn = messageTurn(entry);\n if (turn === null) return;\n emitConversation({\n kind: 'accepted-message',\n conversation,\n message: { turn, message: structuredClone(entry) },\n });\n }\n }\n\n function receive(frame: HouseStreamFrame) {\n if (frame.type === 'draft') {\n emitConversation({\n kind: 'growing-text',\n conversation: frame.conversation_id,\n turn: frame.turn_id,\n text: frame.text,\n });\n return;\n }\n if (frame.type === 'message') {\n const turn = messageTurn(frame.message);\n if (turn === null) return;\n emitConversation({\n kind: 'accepted-message',\n conversation: frame.conversation_id,\n message: { turn, message: structuredClone(frame.message) },\n });\n return;\n }\n if (frame.type === 'session') {\n emitConversation({\n kind: 'session-summary',\n conversation: frame.conversation_id,\n summary: structuredClone(frame.summary),\n });\n return;\n }\n if (frame.type === 'subscribed' && viewed.includes(frame.authority)) {\n const reconnect = subscribedConversations.has(frame.authority);\n subscribedConversations.add(frame.authority);\n void catchUp(frame.authority, reconnect);\n return;\n }\n if (frame.type !== 'entries') {\n held.delete(frame.authority);\n return;\n }\n const at = position(frame.position);\n if (at === null) {\n held.delete(frame.authority);\n return;\n }\n const run = held.get(frame.authority) ?? [];\n const last = run.at(-1);\n const continued = last !== undefined && last.position + 1n === at;\n const next = continued\n ? [...run, { position: at, entries: frame.entries }]\n : [{ position: at, entries: frame.entries }];\n held.set(frame.authority, next.length > HELD_POSITIONS_MAX ? [] : next);\n const locator = locators.get(frame.authority);\n if (locator === undefined) return;\n for (const observer of observers) observer({ locator, roomVersion: frame.position });\n }\n\n return {\n conversations: {\n view(next) {\n const open = new Set(next);\n for (const conversation of subscribedConversations) {\n if (!open.has(conversation)) subscribedConversations.delete(conversation);\n }\n viewed = [...next];\n subscribe();\n },\n observe(notify) {\n conversationObservers.add(notify);\n if (!listening) {\n listening = true;\n stream.observe(receive);\n }\n return () => {\n conversationObservers.delete(notify);\n };\n },\n },\n track(entries) {\n locators.clear();\n authorities.clear();\n for (const entry of entries) {\n locators.set(entry.authority, entry.locator);\n authorities.set(entry.locator, entry.authority);\n }\n for (const authority of held.keys()) {\n if (!locators.has(authority)) held.delete(authority);\n }\n },\n select(named) {\n selected = [...named];\n subscribe();\n },\n observe(notify) {\n observers.add(notify);\n if (!listening) {\n listening = true;\n stream.observe(receive);\n }\n return () => {\n observers.delete(notify);\n };\n },\n advance(tracked, fromRoomVersion) {\n const run = held.get(tracked.authority);\n const from = position(fromRoomVersion);\n if (run === undefined || from === null) return null;\n const at = run.findIndex((frame) => frame.position === from + 1n);\n if (at === -1) return null;\n const pending = run.slice(at);\n const documents: Record<string, string> = {};\n const revisions: Record<string, string> = {};\n const removals: string[] = [];\n for (const frame of pending) {\n for (const entry of frame.entries) {\n if (!selects(tracked, entry.path)) continue;\n if (entry.kind === 'removed') {\n delete documents[entry.path];\n delete revisions[entry.path];\n if (!removals.includes(entry.path)) removals.push(entry.path);\n continue;\n }\n if (entry.text === undefined || entry.revision === undefined) return null;\n documents[entry.path] = entry.text;\n revisions[entry.path] = entry.revision;\n const removed = removals.indexOf(entry.path);\n if (removed !== -1) removals.splice(removed, 1);\n }\n }\n const last = pending.at(-1);\n if (last === undefined) return null;\n held.set(tracked.authority, pending);\n return {\n kind: 'net-advancement',\n roomVersion: last.position.toString(),\n documents,\n revisions,\n binaryTargets: [],\n removals: removals.sort(),\n };\n },\n };\n}\n"],"names":["actionOutcome","HISTORY_PAGE","readConversationHistory","selects","PRIVATE_AUTHORITY","HELD_POSITIONS_MAX","position","value","test","BigInt","messageTurn","message","turn","message_id","houseNotifications","transport","stream","held","Map","locators","authorities","observers","Set","conversationObservers","subscribedConversations","selected","viewed","listening","subscribe","named","locator","authority","get","undefined","push","kind","room","has","conversation","emitConversation","event","includes","observer","catchUp","history","viewedAnswer","door","conversation_id","summary","result","structuredClone","session","heldHistory","newest","messages","slice","entry","receive","frame","type","turn_id","text","reconnect","add","delete","at","run","last","continued","next","entries","set","length","roomVersion","conversations","view","open","observe","notify","track","clear","keys","select","advance","tracked","fromRoomVersion","from","findIndex","pending","documents","revisions","removals","path","revision","removed","indexOf","splice","toString","binaryTarg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2F,QAAQ;gBACnCR;gBACAC;gBACAQ,eAAe,EAAE;gBACjBP,UAAUA,SAASQ,IAAI;YACzB;QACF;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/stream.ts"],"sourcesContent":["import type {\n ConversationEvent,\n ConversationStream,\n RefreshPage,\n RoomVersionNotification,\n SelectedRooms,\n} from '@agentshouse/mdruntime';\nimport { acceptedMessage, actionOutcome } from './actions.js';\nimport type { TrackedAuthority } from './discovery.js';\nimport { selects } from './read.js';\nimport type { HouseDoor, HouseStreamAuthority } from './transport.js';\nimport type { HouseMode, HouseStreamEntry, HouseStreamFrame } from './transport.js';\nimport { roomVersion, type LogPosition } from './version.js';\n\nconst HELD_POSITIONS_MAX = 256;\n\ntype HeldFrame = {\n position: bigint;\n entries: readonly HouseStreamEntry[];\n};\n\ntype HeldLine = {\n logEpoch: string;\n frames: readonly HeldFrame[];\n};\n\nexport type HouseNotifications = SelectedRooms & {\n track(authorities: readonly TrackedAuthority[]): void;\n advance(tracked: TrackedAuthority, from: LogPosition): RefreshPage | null;\n conversations: ConversationStream;\n};\n\nfunction position(value: string): bigint | null {\n if (!/^(?:0|[1-9][0-9]*)$/.test(value)) return null;\n return BigInt(value);\n}\n\nexport function houseNotifications(transport: HouseDoor, mode: HouseMode): HouseNotifications {\n const stream = transport.stream;\n const lines = new Map<string, HeldLine>();\n const locators = new Map<string, string[]>();\n const authorities = new Map<string, string>();\n const observers = new Set<(notification: RoomVersionNotification) => void>();\n const conversationObservers = new Set<(event: ConversationEvent) => void>();\n let selected: readonly string[] = [];\n let replicated: readonly string[] = [];\n let viewed: readonly string[] = [];\n let listening = false;\n\n function subscribe() {\n const named: HouseStreamAuthority[] = [];\n const rooms = new Set<string>();\n for (const locator of selected) {\n const authority = authorities.get(locator);\n if (authority === undefined) continue;\n rooms.add(authority);\n }\n for (const room of rooms) named.push({ kind: 'room', room });\n for (const conversation of viewed) {\n named.push({ kind: 'conversation', conversation });\n }\n stream.subscribe(named);\n }\n\n function emitConversation(event: ConversationEvent) {\n const delivered =\n event.kind === 'accepted-message' || event.kind === 'gap' ? replicated : viewed;\n if (!delivered.includes(event.conversation)) return;\n for (const observer of conversationObservers) observer(event);\n }\n\n async function summarize(conversation: string) {\n const viewedAnswer = await transport.door('/door/conversations/view', {\n conversation_id: conversation,\n });\n const summary = actionOutcome(viewedAnswer, 'conversations/view');\n if (\n summary.kind === 'action' &&\n typeof summary.result === 'object' &&\n summary.result !== null\n ) {\n emitConversation({\n kind: 'session-summary',\n conversation,\n summary: structuredClone('session' in summary.result ? summary.result.session : null),\n });\n }\n }\n\n function announce(authority: string, at: LogPosition) {\n const version = roomVersion(at);\n for (const locator of locators.get(authority) ?? []) {\n for (const observer of observers) observer({ locator, roomVersion: version });\n }\n }\n\n function interrupt(authority: string) {\n const line = lines.get(authority);\n if (line !== undefined) lines.set(authority, { logEpoch: line.logEpoch, frames: [] });\n }\n\n function resubscribed(authority: string, position?: string, logEpoch?: string) {\n if (position === undefined || logEpoch === undefined) {\n interrupt(authority);\n return;\n }\n const held = lines.get(authority)?.logEpoch;\n lines.set(authority, { logEpoch, frames: [] });\n if (held !== logEpoch) announce(authority, { position, logEpoch });\n }\n\n function receive(frame: HouseStreamFrame) {\n if (frame.type === 'draft') {\n emitConversation({\n kind: 'growing-text',\n conversation: frame.conversation_id,\n turn: frame.turn_id,\n text: frame.text,\n });\n return;\n }\n if (frame.type === 'message') {\n const message = acceptedMessage(frame.message);\n if (message === null) return;\n emitConversation({ kind: 'accepted-message', conversation: frame.conversation_id, message });\n return;\n }\n if (frame.type === 'session') {\n emitConversation({\n kind: 'session-summary',\n conversation: frame.conversation_id,\n summary: structuredClone(frame.summary),\n });\n return;\n }\n if (frame.type === 'subscribed' && viewed.includes(frame.authority)) {\n emitConversation({ kind: 'gap', conversation: frame.authority });\n void summarize(frame.authority);\n return;\n }\n if (frame.type === 'subscribed') {\n resubscribed(frame.authority, frame.position, frame.log_epoch);\n return;\n }\n if (frame.type !== 'entries') {\n interrupt(frame.authority);\n return;\n }\n const at = position(frame.position);\n if (at === null) {\n interrupt(frame.authority);\n return;\n }\n const line = lines.get(frame.authority);\n if (line?.logEpoch === frame.log_epoch) {\n const last = line.frames.at(-1);\n const continued = last !== undefined && last.position + 1n === at;\n const next = continued\n ? [...line.frames, { position: at, entries: frame.entries }]\n : [{ position: at, entries: frame.entries }];\n lines.set(frame.authority, {\n logEpoch: line.logEpoch,\n frames: next.length > HELD_POSITIONS_MAX ? [] : next,\n });\n } else {\n interrupt(frame.authority);\n }\n announce(frame.authority, { position: frame.position, logEpoch: frame.log_epoch });\n }\n\n return {\n conversations: {\n replicate(next) {\n replicated = [...next];\n },\n view(next) {\n viewed = [...next];\n subscribe();\n },\n observe(notify) {\n conversationObservers.add(notify);\n if (!listening) {\n listening = true;\n stream.observe(receive);\n }\n return () => {\n conversationObservers.delete(notify);\n };\n },\n },\n track(entries) {\n locators.clear();\n authorities.clear();\n for (const entry of entries) {\n locators.set(entry.authority, [...(locators.get(entry.authority) ?? []), entry.locator]);\n authorities.set(entry.locator, entry.authority);\n if (lines.get(entry.authority)?.logEpoch !== entry.logEpoch) {\n lines.set(entry.authority, { logEpoch: entry.logEpoch, frames: [] });\n }\n }\n for (const authority of lines.keys()) {\n if (!locators.has(authority)) lines.delete(authority);\n }\n },\n select(named) {\n selected = [...named];\n subscribe();\n },\n observe(notify) {\n observers.add(notify);\n if (!listening) {\n listening = true;\n stream.observe(receive);\n }\n return () => {\n observers.delete(notify);\n };\n },\n advance(tracked, from) {\n const line = lines.get(tracked.authority);\n const start = position(from.position);\n if (line === undefined || start === null || line.logEpoch !== from.logEpoch) return null;\n const at = line.frames.findIndex((frame) => frame.position === start + 1n);\n if (at === -1) return null;\n const pending = line.frames.slice(at);\n const documents: Record<string, string> = {};\n const revisions: Record<string, string> = {};\n const removals: string[] = [];\n for (const frame of pending) {\n for (const entry of frame.entries) {\n if (!selects(tracked, entry.path)) continue;\n if (entry.kind === 'removed') {\n delete documents[entry.path];\n delete revisions[entry.path];\n if (!removals.includes(entry.path)) removals.push(entry.path);\n continue;\n }\n if (entry.text === undefined) return null;\n if (mode === 'credential' && entry.revision === undefined) return null;\n documents[entry.path] = entry.text;\n if (entry.revision !== undefined) revisions[entry.path] = entry.revision;\n const removed = removals.indexOf(entry.path);\n if (removed !== -1) removals.splice(removed, 1);\n }\n }\n const last = pending.at(-1);\n if (last === undefined) return null;\n lines.set(tracked.authority, { logEpoch: line.logEpoch, frames: pending });\n return {\n kind: 'net-advancement',\n roomVersion: roomVersion({ position: last.position.toString(), logEpoch: line.logEpoch }),\n documents,\n revisions,\n binaryTargets: [],\n removals: removals.sort(),\n };\n },\n };\n}\n"],"names":["acceptedMessage","actionOutcome","selects","roomVersion","HELD_POSITIONS_MAX","position","value","test","BigInt","houseNotifications","transport","mode","stream","lines","Map","locators","authorities","observers","Set","conversationObservers","selected","replicated","viewed","listening","subscribe","named","rooms","locator","authority","get","undefined","add","room","push","kind","conversation","emitConversation","event","delivered","includes","observer","summarize","viewedAnswer","door","conversation_id","summary","result","structuredClone","session","announce","at","version","interrupt","line","set","logEpoch","frames","resubscribed","held","receive","frame","type","turn","turn_id","text","message","log_epoch","last","continued","next","entries","length","conversations","replicate","view","observe","notify","delete","track","clear","entry","keys","has","select","advance","tracked","from","start","findIndex","pending","slice","documents","revisions","removals","path","revision","removed","indexOf","splice","toString","binaryTargets","sort"],"mappings":"AAOA,SAASA,eAAe,EAAEC,aAAa,QAAQ,eAAe;AAE9D,SAASC,OAAO,QAAQ,YAAY;AAGpC,SAASC,WAAW,QAA0B,eAAe;AAE7D,MAAMC,qBAAqB;AAkB3B,SAASC,SAASC,KAAa;IAC7B,IAAI,CAAC,sBAAsBC,IAAI,CAACD,QAAQ,OAAO;IAC/C,OAAOE,OAAOF;AAChB;AAEA,OAAO,SAASG,mBAAmBC,SAAoB,EAAEC,IAAe;IACtE,MAAMC,SAASF,UAAUE,MAAM;IAC/B,MAAMC,QAAQ,IA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AQ;oBACxE,MAAMC,UAAUH,SAASI,OAAO,CAACjB,MAAMc,IAAI;oBAC3C,IAAIE,YAAY,CAAC,GAAGH,SAASK,MAAM,CAACF,SAAS;gBAC/C;YACF;YACA,MAAM7B,OAAOsB,QAAQvC,EAAE,CAAC,CAAC;YACzB,IAAIiB,SAASrC,WAAW,OAAO;YAC/BjB,MAAMyC,GAAG,CAAC+B,QAAQzD,SAAS,EAAE;gBAAE2B,UAAUF,KAAKE,QAAQ;gBAAEC,QAAQiC;YAAQ;YACxE,OAAO;gBACLvD,MAAM;gBACN/B,aAAaA,YAAY;oBAAEE,UAAU8D,KAAK9D,QAAQ,CAAC8F,QAAQ;oBAAI5C,UAAUF,KAAKE,QAAQ;gBAAC;gBACvFoC;gBACAC;gBACAQ,eAAe,EAAE;gBACjBP,UAAUA,SAASQ,IAAI;YACzB;QACF;IACF;AACF"}
|
package/dist/transport.d.ts
CHANGED
|
@@ -4,7 +4,12 @@ export declare const DOOR_ENUMERATE = "/door/enumerate";
|
|
|
4
4
|
export declare const DOOR_BATCH = "/door/batch";
|
|
5
5
|
export declare const DOOR_BATCH_UPLOAD = "/door/batch-upload";
|
|
6
6
|
export declare const DOOR_REVISIONS = "/door/revisions";
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const SITE_DOOR_DISCOVER = "/_house/door/discover";
|
|
8
|
+
export declare const SITE_DOOR_BOOTSTRAP = "/_house/door/bootstrap/";
|
|
9
|
+
export declare const SITE_DOOR_ENUMERATE = "/_house/door/enumerate";
|
|
10
|
+
export declare const SITE_DOOR_SUBMIT = "/_house/door/submit";
|
|
11
|
+
export declare const PRIVATE_LOCATOR = "private";
|
|
12
|
+
export type HouseMode = 'credential' | 'site';
|
|
8
13
|
export type HouseDoorAnswer = {
|
|
9
14
|
status: number;
|
|
10
15
|
body: unknown;
|
|
@@ -21,8 +26,6 @@ export type HouseByteTransfer = {
|
|
|
21
26
|
export type HouseStreamAuthority = {
|
|
22
27
|
kind: 'room';
|
|
23
28
|
room: string;
|
|
24
|
-
} | {
|
|
25
|
-
kind: 'private';
|
|
26
29
|
} | {
|
|
27
30
|
kind: 'conversation';
|
|
28
31
|
conversation: string;
|
|
@@ -37,11 +40,13 @@ export type HouseStreamFrame = {
|
|
|
37
40
|
type: 'entries';
|
|
38
41
|
authority: string;
|
|
39
42
|
position: string;
|
|
43
|
+
log_epoch: string;
|
|
40
44
|
entries: readonly HouseStreamEntry[];
|
|
41
45
|
} | {
|
|
42
46
|
type: 'subscribed';
|
|
43
47
|
authority: string;
|
|
44
48
|
position?: string;
|
|
49
|
+
log_epoch?: string;
|
|
45
50
|
} | {
|
|
46
51
|
type: 'refused';
|
|
47
52
|
authority: string;
|
|
@@ -69,9 +74,15 @@ export type HouseStream = {
|
|
|
69
74
|
subscribe(authorities: readonly HouseStreamAuthority[]): void;
|
|
70
75
|
observe(receive: (frame: HouseStreamFrame) => void): () => void;
|
|
71
76
|
};
|
|
72
|
-
export type
|
|
77
|
+
export type HouseDoor = {
|
|
73
78
|
door(route: string, body: unknown): Promise<HouseDoorAnswer>;
|
|
74
|
-
transfer(request: HouseByteTransfer): Promise<HouseDoorAnswer>;
|
|
75
79
|
stream: HouseStream;
|
|
76
80
|
};
|
|
81
|
+
export type HouseTransport = HouseDoor & {
|
|
82
|
+
transfer(request: HouseByteTransfer): Promise<HouseDoorAnswer>;
|
|
83
|
+
};
|
|
84
|
+
export type HouseSiteTransport = HouseDoor & {
|
|
85
|
+
online(): boolean;
|
|
86
|
+
read(route: string): Promise<HouseDoorAnswer>;
|
|
87
|
+
};
|
|
77
88
|
//# sourceMappingURL=transport.d.ts.map
|
package/dist/transport.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,mBAAmB,CAAC;AAE9C,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAEhD,eAAO,MAAM,cAAc,oBAAo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OAAO,CAAA;CAAE,CAAC;AAEnE,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,CAAC,WAAW,EAAE,SAAS,oBAAoB,EAAE,GAAG,IAAI,CAAC;IAC9D,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CACjE,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAC7D,MAAM,EAAE,WAAW,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG;IACvC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAChE,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG;IAC3C,MAAM,IAAI,OAAO,CAAC;IAClB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAC/C,CAAC"}
|
package/dist/transport.js
CHANGED
|
@@ -4,6 +4,10 @@ export const DOOR_ENUMERATE = '/door/enumerate';
|
|
|
4
4
|
export const DOOR_BATCH = '/door/batch';
|
|
5
5
|
export const DOOR_BATCH_UPLOAD = '/door/batch-upload';
|
|
6
6
|
export const DOOR_REVISIONS = '/door/revisions';
|
|
7
|
-
export const
|
|
7
|
+
export const SITE_DOOR_DISCOVER = '/_house/door/discover';
|
|
8
|
+
export const SITE_DOOR_BOOTSTRAP = '/_house/door/bootstrap/';
|
|
9
|
+
export const SITE_DOOR_ENUMERATE = '/_house/door/enumerate';
|
|
10
|
+
export const SITE_DOOR_SUBMIT = '/_house/door/submit';
|
|
11
|
+
export const PRIVATE_LOCATOR = 'private';
|
|
8
12
|
|
|
9
13
|
//# sourceMappingURL=transport.js.map
|
package/dist/transport.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/transport.ts"],"sourcesContent":["export const DOOR_DISCOVER = '/door/discover';\n\nexport const DOOR_BOOTSTRAP = '/door/bootstrap';\n\nexport const DOOR_ENUMERATE = '/door/enumerate';\n\nexport const DOOR_BATCH = '/door/batch';\n\nexport const DOOR_BATCH_UPLOAD = '/door/batch-upload';\n\nexport const DOOR_REVISIONS = '/door/revisions';\n\nexport const
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/transport.ts"],"sourcesContent":["export const DOOR_DISCOVER = '/door/discover';\n\nexport const DOOR_BOOTSTRAP = '/door/bootstrap';\n\nexport const DOOR_ENUMERATE = '/door/enumerate';\n\nexport const DOOR_BATCH = '/door/batch';\n\nexport const DOOR_BATCH_UPLOAD = '/door/batch-upload';\n\nexport const DOOR_REVISIONS = '/door/revisions';\n\nexport const SITE_DOOR_DISCOVER = '/_house/door/discover';\n\nexport const SITE_DOOR_BOOTSTRAP = '/_house/door/bootstrap/';\n\nexport const SITE_DOOR_ENUMERATE = '/_house/door/enumerate';\n\nexport const SITE_DOOR_SUBMIT = '/_house/door/submit';\n\nexport const PRIVATE_LOCATOR = 'private';\n\nexport type HouseMode = 'credential' | 'site';\n\nexport type HouseDoorAnswer = {\n status: number;\n body: unknown;\n};\n\nexport type HouseByteAct =\n | 'working_copy_bundle'\n | 'authored_batch_upload'\n | 'conversation_original_upload';\n\nexport type HouseByteBody = string | ArrayBuffer | Uint8Array;\n\nexport type HouseByteTransfer = {\n act: HouseByteAct;\n method: 'GET' | 'POST';\n url: string;\n body?: HouseByteBody;\n operation?: string;\n};\n\nexport type HouseStreamAuthority =\n | { kind: 'room'; room: string }\n | { kind: 'conversation'; conversation: string };\n\nexport type HouseStreamEntry = {\n path: string;\n kind: 'edited' | 'removed';\n revision?: string;\n text?: string;\n};\n\nexport type HouseStreamFrame =\n | {\n type: 'entries';\n authority: string;\n position: string;\n log_epoch: string;\n entries: readonly HouseStreamEntry[];\n }\n | { type: 'subscribed'; authority: string; position?: string; log_epoch?: string }\n | { type: 'refused'; authority: string; code: string }\n | { type: 'unsubscribed'; authority: string; code?: string }\n | {\n type: 'draft';\n conversation_id: string;\n session_id: string;\n turn_id: string;\n text: string;\n }\n | { type: 'message'; conversation_id: string; message: unknown }\n | { type: 'session'; conversation_id: string; summary: unknown };\n\nexport type HouseStream = {\n subscribe(authorities: readonly HouseStreamAuthority[]): void;\n observe(receive: (frame: HouseStreamFrame) => void): () => void;\n};\n\nexport type HouseDoor = {\n door(route: string, body: unknown): Promise<HouseDoorAnswer>;\n stream: HouseStream;\n};\n\nexport type HouseTransport = HouseDoor & {\n transfer(request: HouseByteTransfer): Promise<HouseDoorAnswer>;\n};\n\nexport type HouseSiteTransport = HouseDoor & {\n online(): boolean;\n read(route: string): Promise<HouseDoorAnswer>;\n};\n"],"names":["DOOR_DISCOVER","DOOR_BOOTSTRAP","DOOR_ENUMERATE","DOOR_BATCH","DOOR_BATCH_UPLOAD","DOOR_REVISIONS","SITE_DOOR_DISCOVER","SITE_DOOR_BOOTSTRAP","SITE_DOOR_ENUMERATE","SITE_DOOR_SUBMIT","PRIVATE_LOCATOR"],"mappings":"AAAA,OAAO,MAAMA,gBAAgB,iBAAiB;AAE9C,OAAO,MAAMC,iBAAiB,kBAAkB;AAEhD,OAAO,MAAMC,iBAAiB,kBAAkB;AAEhD,OAAO,MAAMC,aAAa,cAAc;AAExC,OAAO,MAAMC,oBAAoB,qBAAqB;AAEtD,OAAO,MAAMC,iBAAiB,kBAAkB;AAEhD,OAAO,MAAMC,qBAAqB,wBAAwB;AAE1D,OAAO,MAAMC,sBAAsB,0BAA0B;AAE7D,OAAO,MAAMC,sBAAsB,yBAAyB;AAE5D,OAAO,MAAMC,mBAAmB,sBAAsB;AAEtD,OAAO,MAAMC,kBAAkB,UAAU"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type LogPosition = {
|
|
2
|
+
position: string;
|
|
3
|
+
logEpoch: string;
|
|
4
|
+
};
|
|
5
|
+
export type PresentedPosition = {
|
|
6
|
+
authority: string;
|
|
7
|
+
position: string;
|
|
8
|
+
log_epoch: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function roomVersion(at: LogPosition): string;
|
|
11
|
+
export declare function logPosition(version: string): LogPosition | null;
|
|
12
|
+
export declare function readPosition(held: Readonly<Record<string, unknown>>): LogPosition | null;
|
|
13
|
+
export declare function presented(authority: string, at: LogPosition): PresentedPosition;
|
|
14
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,wBAAgB,WAAW,CAAC,EAAE,EAAE,WAAW,GAAG,MAAM,CAEnD;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAI/D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,WAAW,GAAG,IAAI,CAKxF;AAED,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,WAAW,GAAG,iBAAiB,CAE/E"}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function roomVersion(at) {
|
|
2
|
+
return `${at.logEpoch}:${at.position}`;
|
|
3
|
+
}
|
|
4
|
+
export function logPosition(version) {
|
|
5
|
+
const split = version.lastIndexOf(':');
|
|
6
|
+
if (split < 1 || split === version.length - 1) return null;
|
|
7
|
+
return {
|
|
8
|
+
logEpoch: version.slice(0, split),
|
|
9
|
+
position: version.slice(split + 1)
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function readPosition(held) {
|
|
13
|
+
const { position, log_epoch: logEpoch } = held;
|
|
14
|
+
if (typeof position !== 'string' || position.length === 0) return null;
|
|
15
|
+
if (typeof logEpoch !== 'string' || logEpoch.length === 0) return null;
|
|
16
|
+
return {
|
|
17
|
+
position,
|
|
18
|
+
logEpoch
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function presented(authority, at) {
|
|
22
|
+
return {
|
|
23
|
+
authority,
|
|
24
|
+
position: at.position,
|
|
25
|
+
log_epoch: at.logEpoch
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/version.ts"],"sourcesContent":["export type LogPosition = {\n position: string;\n logEpoch: string;\n};\n\nexport type PresentedPosition = {\n authority: string;\n position: string;\n log_epoch: string;\n};\n\nexport function roomVersion(at: LogPosition): string {\n return `${at.logEpoch}:${at.position}`;\n}\n\nexport function logPosition(version: string): LogPosition | null {\n const split = version.lastIndexOf(':');\n if (split < 1 || split === version.length - 1) return null;\n return { logEpoch: version.slice(0, split), position: version.slice(split + 1) };\n}\n\nexport function readPosition(held: Readonly<Record<string, unknown>>): LogPosition | null {\n const { position, log_epoch: logEpoch } = held;\n if (typeof position !== 'string' || position.length === 0) return null;\n if (typeof logEpoch !== 'string' || logEpoch.length === 0) return null;\n return { position, logEpoch };\n}\n\nexport function presented(authority: string, at: LogPosition): PresentedPosition {\n return { authority, position: at.position, log_epoch: at.logEpoch };\n}\n"],"names":["roomVersion","at","logEpoch","position","logPosition","version","split","lastIndexOf","length","slice","readPosition","held","log_epoch","presented","authority"],"mappings":"AAWA,OAAO,SAASA,YAAYC,EAAe;IACzC,OAAO,GAAGA,GAAGC,QAAQ,CAAC,CAAC,EAAED,GAAGE,QAAQ,EAAE;AACxC;AAEA,OAAO,SAASC,YAAYC,OAAe;IACzC,MAAMC,QAAQD,QAAQE,WAAW,CAAC;IAClC,IAAID,QAAQ,KAAKA,UAAUD,QAAQG,MAAM,GAAG,GAAG,OAAO;IACtD,OAAO;QAAEN,UAAUG,QAAQI,KAAK,CAAC,GAAGH;QAAQH,UAAUE,QAAQI,KAAK,CAACH,QAAQ;IAAG;AACjF;AAEA,OAAO,SAASI,aAAaC,IAAuC;IAClE,MAAM,EAAER,QAAQ,EAAES,WAAWV,QAAQ,EAAE,GAAGS;IAC1C,IAAI,OAAOR,aAAa,YAAYA,SAASK,MAAM,KAAK,GAAG,OAAO;IAClE,IAAI,OAAON,aAAa,YAAYA,SAASM,MAAM,KAAK,GAAG,OAAO;IAClE,OAAO;QAAEL;QAAUD;IAAS;AAC9B;AAEA,OAAO,SAASW,UAAUC,SAAiB,EAAEb,EAAe;IAC1D,OAAO;QAAEa;QAAWX,UAAUF,GAAGE,QAAQ;QAAES,WAAWX,GAAGC,QAAQ;IAAC;AACpE"}
|
package/dist/write.d.ts
CHANGED
|
@@ -12,6 +12,12 @@ export type ChangeMapping = {
|
|
|
12
12
|
rule: string;
|
|
13
13
|
};
|
|
14
14
|
export declare function houseChanges(batch: ChangeBatch, handle: string | undefined): ChangeMapping;
|
|
15
|
+
export type OperationHead = {
|
|
16
|
+
readonly operation_id: string;
|
|
17
|
+
readonly app_ref?: string;
|
|
18
|
+
readonly release?: string;
|
|
19
|
+
};
|
|
20
|
+
export declare function operationHead(batch: ChangeBatch): OperationHead;
|
|
15
21
|
export declare function batchPaths(changes: readonly HouseOperation[]): readonly string[];
|
|
16
22
|
export declare function deltaBody(changes: readonly HouseOperation[]): string;
|
|
17
23
|
export declare function deltaBytes(delta: string): number;
|
package/dist/write.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write.d.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