@agentshouse/mdruntime 0.1.0-cfb2ae0107054 → 0.1.0-cfcbb238a5fa0
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 +262 -262
- package/dist/acquisition.d.ts +14 -0
- package/dist/acquisition.d.ts.map +1 -0
- package/dist/acquisition.js +24 -0
- package/dist/adapter.d.ts +14 -7
- package/dist/adapter.d.ts.map +1 -1
- package/dist/bootstrap.d.ts +2 -1
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +4 -0
- package/dist/change-set.d.ts +2 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +36 -10
- package/dist/chat/kit.d.ts +2 -1
- package/dist/chat/kit.d.ts.map +1 -1
- package/dist/chat/kit.js +3 -3
- package/dist/chat/list.d.ts +2 -1
- package/dist/chat/list.d.ts.map +1 -1
- package/dist/chat/list.js +4 -3
- package/dist/chat/message.d.ts.map +1 -1
- package/dist/chat/message.js +2 -2
- package/dist/chat/messages.d.ts +1 -0
- package/dist/chat/messages.d.ts.map +1 -1
- package/dist/chat/messages.js +4 -0
- package/dist/chat/provider.d.ts +1 -1
- package/dist/chat/provider.d.ts.map +1 -1
- package/dist/chat/provider.js +26 -17
- package/dist/chat/ready.d.ts +1 -0
- package/dist/chat/ready.d.ts.map +1 -1
- package/dist/chat/ready.js +2 -2
- package/dist/client.d.ts +10 -6
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +11 -2
- package/dist/collection.d.ts +17 -3
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +230 -19
- package/dist/connection.d.ts +23 -7
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1065 -192
- package/dist/conversation.d.ts +11 -5
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +241 -100
- package/dist/durability.d.ts +7 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +2 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +3 -3
- package/dist/host.d.ts +16 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +82 -8
- package/dist/identity.d.ts +2 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +6 -0
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/memory.d.ts +7 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +20 -7
- package/dist/model.d.ts +4 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +10 -1
- package/dist/observation.d.ts +5 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +22 -11
- package/dist/overlay.d.ts +2 -0
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +58 -55
- package/dist/query.d.ts +35 -3
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +8 -2
- package/dist/reach.d.ts +6 -3
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +16 -4
- package/dist/react.d.ts +7 -4
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +6 -4
- package/dist/read-side.d.ts +13 -6
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +285 -83
- package/dist/readiness.d.ts +53 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +33 -0
- package/dist/reads.d.ts +11 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +98 -0
- package/dist/recovery.d.ts +25 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +197 -0
- package/dist/refresh.d.ts +4 -4
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +17 -10
- package/dist/replica.d.ts +1 -1
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +57 -20
- package/dist/room-draft.d.ts +13 -1
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +2 -2
- package/dist/rows.d.ts +5 -13
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +5 -13
- package/dist/save.d.ts +5 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +36 -13
- package/dist/search.d.ts +36 -6
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +132 -46
- package/dist/seed.d.ts +16 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +61 -0
- package/dist/shared.d.ts +11 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +368 -0
- package/dist/status.d.ts +4 -0
- package/dist/status.d.ts.map +1 -1
- package/dist/store.d.ts +21 -5
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +157 -53
- package/dist/turn.d.ts +7 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +45 -0
- package/dist/wire.d.ts +136 -32
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +48 -31
- package/package.json +2 -2
package/dist/chat/provider.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createContext, createElement, useCallback, useContext, useEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore, } from 'react';
|
|
2
2
|
import { AssistantRuntimeProvider, createMessageQueue, generateId, useExternalStoreRuntime, } from '@assistant-ui/react';
|
|
3
3
|
import { attempts } from '../attempt.js';
|
|
4
|
+
import { newChat, } from '../conversation.js';
|
|
4
5
|
import { expectedList } from '../expectation.js';
|
|
5
6
|
import { chatDraftRevision } from '../identity.js';
|
|
6
7
|
import { useObserve } from '../react.js';
|
|
@@ -19,9 +20,6 @@ function sharedOf(client) {
|
|
|
19
20
|
SHARED.set(client, fresh);
|
|
20
21
|
return fresh;
|
|
21
22
|
}
|
|
22
|
-
function newChat(agent) {
|
|
23
|
-
return `new:${agent}`;
|
|
24
|
-
}
|
|
25
23
|
function ready(observed) {
|
|
26
24
|
return observed.state === 'ready' ? observed.value : null;
|
|
27
25
|
}
|
|
@@ -177,7 +175,8 @@ export function ChatProvider({ client, conversation = null, agent = null, onOpen
|
|
|
177
175
|
const sync = ready(useObserve(client, 'sync-status'));
|
|
178
176
|
const refusal = ready(useObserve(client, 'connection-refusal'));
|
|
179
177
|
const online = sync !== null && !sync.providerUnreachable && refusal === null;
|
|
180
|
-
const thread = open.conversation ??
|
|
178
|
+
const thread = open.conversation ??
|
|
179
|
+
(open.agent === null ? null : (shared.created.get(open.agent) ?? newChat(open.agent)));
|
|
181
180
|
const held = ready(useObserve(thread === null ? null : client, 'conversation', thread ?? '', {}));
|
|
182
181
|
const version = useSyncExternalStore(shared.overlay.subscribe, shared.overlay.version);
|
|
183
182
|
useEffect(() => {
|
|
@@ -206,6 +205,14 @@ export function ChatProvider({ client, conversation = null, agent = null, onOpen
|
|
|
206
205
|
const current = useRef(thread);
|
|
207
206
|
current.current = thread;
|
|
208
207
|
const seeding = useRef(false);
|
|
208
|
+
const mounted = useRef(true);
|
|
209
|
+
useEffect(() => {
|
|
210
|
+
mounted.current = true;
|
|
211
|
+
return () => {
|
|
212
|
+
mounted.current = false;
|
|
213
|
+
};
|
|
214
|
+
}, []);
|
|
215
|
+
const was = useRef(null);
|
|
209
216
|
const heard = useRef('');
|
|
210
217
|
const shown = useRef('');
|
|
211
218
|
const own = useRef([]);
|
|
@@ -223,6 +230,10 @@ export function ChatProvider({ client, conversation = null, agent = null, onOpen
|
|
|
223
230
|
heard.current = '';
|
|
224
231
|
shown.current = '';
|
|
225
232
|
own.current = own.current.filter((one) => one.startsWith(`${thread}\u0000`));
|
|
233
|
+
const created = was.current === open;
|
|
234
|
+
was.current = open;
|
|
235
|
+
if (created)
|
|
236
|
+
return;
|
|
226
237
|
sending.clear();
|
|
227
238
|
acting.clear();
|
|
228
239
|
setAgain(null);
|
|
@@ -230,7 +241,6 @@ export function ChatProvider({ client, conversation = null, agent = null, onOpen
|
|
|
230
241
|
const sendTo = (to, said, key, idle, acts = sending) => acts.call((send) => deliver(client, send, to, said, key, idle), sentMessage(key, [to], said, null));
|
|
231
242
|
const first = (to, said, key, returning, idle) => {
|
|
232
243
|
const drafted = [newChat(to)];
|
|
233
|
-
let made = null;
|
|
234
244
|
return sending.call(async (send) => {
|
|
235
245
|
let conversation = shared.created.get(to);
|
|
236
246
|
if (conversation === undefined) {
|
|
@@ -259,20 +269,17 @@ export function ChatProvider({ client, conversation = null, agent = null, onOpen
|
|
|
259
269
|
started: null,
|
|
260
270
|
}));
|
|
261
271
|
}
|
|
262
|
-
made = conversation;
|
|
263
272
|
send.draw(sentMessage(key, [...drafted, conversation], said, null));
|
|
264
273
|
const result = await deliver(client, send, conversation, said, key, idle);
|
|
265
|
-
if (accepted(result))
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}, sentMessage(key, drafted, said, null), () => {
|
|
269
|
-
if (made === null)
|
|
270
|
-
return;
|
|
271
|
-
void client.chatDraft.discard(newChat(to));
|
|
274
|
+
if (!accepted(result))
|
|
275
|
+
return result;
|
|
276
|
+
shared.created.delete(to);
|
|
272
277
|
const now = opened.current;
|
|
273
|
-
if (now.conversation === null && now.agent === to)
|
|
274
|
-
go({ conversation
|
|
275
|
-
|
|
278
|
+
if (mounted.current && now.conversation === null && now.agent === to) {
|
|
279
|
+
go({ conversation, agent: to });
|
|
280
|
+
}
|
|
281
|
+
return result;
|
|
282
|
+
}, sentMessage(key, drafted, said, null));
|
|
276
283
|
};
|
|
277
284
|
const returned = async (to, one) => {
|
|
278
285
|
const now = (await client.conversation.read(to)).chatDraft;
|
|
@@ -559,8 +566,10 @@ export function ChatProvider({ client, conversation = null, agent = null, onOpen
|
|
|
559
566
|
.then(() => Promise.all((draft?.files ?? []).map((file) => composer.addAttachment(fileOf(file)))))
|
|
560
567
|
.finally(() => {
|
|
561
568
|
seeding.current = false;
|
|
562
|
-
if (current.current !== thread)
|
|
569
|
+
if (current.current !== thread) {
|
|
570
|
+
reconcile.current();
|
|
563
571
|
return;
|
|
572
|
+
}
|
|
564
573
|
const seeded = composer.getState();
|
|
565
574
|
shown.current = `${at}${composed(seeded)}`;
|
|
566
575
|
if (kept)
|
package/dist/chat/ready.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export type ChatProps = AgentLook & {
|
|
|
17
17
|
readonly about?: (chat: ChatState) => ReactNode;
|
|
18
18
|
readonly actions?: ReactNode;
|
|
19
19
|
readonly note?: (note: ChatNoteProps) => ReactNode;
|
|
20
|
+
readonly waiting?: string | null;
|
|
20
21
|
readonly messageLength?: number;
|
|
21
22
|
readonly autoFocus?: boolean;
|
|
22
23
|
};
|
package/dist/chat/ready.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ready.d.ts","sourceRoot":"","sources":["../../src/chat/ready.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAUf,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAGpD,OAAO,EASL,KAAK,aAAa,EACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAwC,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAGjF,OAAO,EAA8B,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AAI5F,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AAEvD,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG;IAClC,QAAQ,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IAC/C,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM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jsx("div", { className: "ahc-deleted", children: _jsxs("div", { role: "note", className: "ahc-column ahc-deleted__note", children: [_jsx("span", { className: "ahc-deleted__icon", children: _jsx(Info, { "aria-hidden": "true" }) }), _jsx("span", { children: `${chat.name} was deleted. Its chats stay here for you to read or delete.` })] }) }));
|
|
64
64
|
}
|
|
65
|
-
function Frame({ showChats, onLink, about, actions, note, messageLength, autoFocus, }) {
|
|
65
|
+
function Frame({ showChats, onLink, about, actions, note, waiting, messageLength, autoFocus, }) {
|
|
66
66
|
const chat = useOpened();
|
|
67
67
|
const [listed, setListed] = useState(false);
|
|
68
68
|
const thread = chat.conversation ?? `new:${chat.agent ?? ''}`;
|
|
69
|
-
return (_jsxs("div", { className: "ahc-frame", children: [showChats === true ? (_jsx("div", { className: "ahc-side", "data-open": listed ? '' : undefined, children: _jsx(ChatList, { onChoose: () => setListed(false) }) })) : null, _jsxs("div", { className: "ahc-pane", children: [_jsx(Head, { about: about, actions: actions, listing: showChats === true ? () => setListed((open) => !open) : null }, thread), chat.deleted ? _jsx(Deleted, {}) : null, _jsx(ChatMessageList, { ...(onLink === undefined ? {} : { onLink }), footer: _jsx(ChatInput, { ...(messageLength === undefined ? {} : { messageLength }), ...(note === undefined ? {} : { note }), autoFocus: autoFocus === true }) })] })] }));
|
|
69
|
+
return (_jsxs("div", { className: "ahc-frame", children: [showChats === true ? (_jsx("div", { className: "ahc-side", "data-open": listed ? '' : undefined, children: _jsx(ChatList, { onChoose: () => setListed(false) }) })) : null, _jsxs("div", { className: "ahc-pane", children: [_jsx(Head, { about: about, actions: actions, listing: showChats === true ? () => setListed((open) => !open) : null }, thread), chat.deleted ? _jsx(Deleted, {}) : null, _jsx(ChatMessageList, { ...(onLink === undefined ? {} : { onLink }), waiting: waiting ?? null, footer: _jsx(ChatInput, { ...(messageLength === undefined ? {} : { messageLength }), ...(note === undefined ? {} : { note }), autoFocus: autoFocus === true }) })] })] }));
|
|
70
70
|
}
|
|
71
71
|
function Ready({ width = 'full', className, style, agentMark, agentDetail, AgentLink, ...rest }) {
|
|
72
72
|
const [root, setRoot] = useState(null);
|
package/dist/client.d.ts
CHANGED
|
@@ -4,16 +4,17 @@ import type { ChatDraft, ConversationAgent, ConversationEntry, ConversationOptio
|
|
|
4
4
|
import { type Observation } from './observation.js';
|
|
5
5
|
import type { BinaryReference } from './binary.js';
|
|
6
6
|
import type { BinaryAnswer, CallResult, HistoryAnswer, Offline, QueueEntry } from './outcome.js';
|
|
7
|
-
import type { DocumentQuery, DocumentResult, GroupQuery, GroupResult } from './query.js';
|
|
7
|
+
import type { DocumentQuery, DocumentResult, GroupQuery, GroupResult, PendingResult } from './query.js';
|
|
8
8
|
import type { RoomDraft, RoomDraftParts, RoomDraftWrite } from './room-draft.js';
|
|
9
9
|
import type { SearchRequest, SearchResult } from './search.js';
|
|
10
|
+
import type { Readiness } from './readiness.js';
|
|
10
11
|
import type { SyncStatus } from './status.js';
|
|
11
12
|
import { type RuntimePort } from './wire.js';
|
|
12
13
|
export type MdRuntimeClient = {
|
|
13
14
|
rooms(): Promise<readonly AppRoom[]>;
|
|
14
15
|
query: {
|
|
15
|
-
(query: DocumentQuery): Promise<DocumentResult>;
|
|
16
|
-
(query: GroupQuery): Promise<GroupResult>;
|
|
16
|
+
(query: DocumentQuery): Promise<DocumentResult | PendingResult>;
|
|
17
|
+
(query: GroupQuery): Promise<GroupResult | PendingResult>;
|
|
17
18
|
};
|
|
18
19
|
search(request: SearchRequest): Promise<SearchResult>;
|
|
19
20
|
types(locator: string): Promise<RoomSchemas>;
|
|
@@ -52,16 +53,18 @@ export type MdRuntimeClient = {
|
|
|
52
53
|
reached(locator: string, roomVersion: string, path?: string): Promise<boolean>;
|
|
53
54
|
log(): Promise<string>;
|
|
54
55
|
persistence(): Promise<boolean>;
|
|
56
|
+
retry(): Promise<void>;
|
|
55
57
|
observe: {
|
|
56
58
|
(topic: 'deployment-facts'): Promise<Observation<unknown>>;
|
|
57
59
|
(topic: 'rooms'): Promise<Observation<readonly AppRoom[]>>;
|
|
60
|
+
(topic: 'readiness'): Promise<Observation<Readiness>>;
|
|
58
61
|
(topic: 'connection-refusal'): Promise<Observation<ConnectionRefusal | null>>;
|
|
59
62
|
(topic: 'storage-loss'): Promise<Observation<string | null>>;
|
|
60
63
|
(topic: 'sync-status'): Promise<Observation<SyncStatus>>;
|
|
61
64
|
(topic: 'service-mode'): Promise<Observation<ServiceMode>>;
|
|
62
65
|
(topic: 'member'): Promise<Observation<Member | null>>;
|
|
63
|
-
(topic: 'query', query: DocumentQuery): Promise<Observation<DocumentResult>>;
|
|
64
|
-
(topic: 'query', query: GroupQuery): Promise<Observation<GroupResult>>;
|
|
66
|
+
(topic: 'query', query: DocumentQuery): Promise<Observation<DocumentResult | PendingResult>>;
|
|
67
|
+
(topic: 'query', query: GroupQuery): Promise<Observation<GroupResult | PendingResult>>;
|
|
65
68
|
(topic: 'queue', locator: string): Promise<Observation<readonly QueueEntry[]>>;
|
|
66
69
|
(topic: 'room-drafts'): Promise<Observation<readonly RoomDraft[]>>;
|
|
67
70
|
(topic: 'presentation'): Promise<Observation<unknown>>;
|
|
@@ -75,5 +78,6 @@ export type MdRuntimeClient = {
|
|
|
75
78
|
export declare function connectMdRuntime(port: RuntimePort): MdRuntimeClient;
|
|
76
79
|
export declare function inTurn(client: MdRuntimeClient, work: () => Promise<void>): Promise<void>;
|
|
77
80
|
export type { Observation } from './observation.js';
|
|
78
|
-
export type {
|
|
81
|
+
export type { Open } from './open.js';
|
|
82
|
+
export { unanswered, type RuntimePort, type WireMember } from './wire.js';
|
|
79
83
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,cAAc,EACd,UAAU,EACX,MAAM,iBAAiB,CAAC;AACzB,OAAO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AAgB,MAAM,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAIxF;AAED,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,YAAY,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { observed } from './observation.js';
|
|
2
2
|
import { runtimeError } from './failure.js';
|
|
3
3
|
import { answer, AUTHORIZATION_ENDED, PORT_CLOSED, } from './wire.js';
|
|
4
|
+
// React renders an arrived value in a later task and opens what that render observes as it commits, so this many frames opening nothing mean the page drew what it observes.
|
|
5
|
+
const SETTLED_FRAMES = 2;
|
|
4
6
|
function refused(refusal) {
|
|
5
7
|
return runtimeError(refusal.code, refusal.code, refusal.retryable);
|
|
6
8
|
}
|
|
@@ -141,14 +143,19 @@ export function connectMdRuntime(port) {
|
|
|
141
143
|
if (opening.size > 0)
|
|
142
144
|
return;
|
|
143
145
|
const at = moved;
|
|
144
|
-
|
|
146
|
+
const waited = (frames) => {
|
|
145
147
|
requestAnimationFrame(() => {
|
|
148
|
+
if (frames < SETTLED_FRAMES) {
|
|
149
|
+
waited(frames + 1);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
146
152
|
if (moved !== at || opening.size > 0)
|
|
147
153
|
return;
|
|
148
154
|
drawing = null;
|
|
149
155
|
resolve();
|
|
150
156
|
});
|
|
151
|
-
}
|
|
157
|
+
};
|
|
158
|
+
waited(1);
|
|
152
159
|
};
|
|
153
160
|
drawing = check;
|
|
154
161
|
check();
|
|
@@ -195,6 +202,7 @@ export function connectMdRuntime(port) {
|
|
|
195
202
|
reached: (locator, roomVersion, path) => ask('reached', [locator, roomVersion, path]),
|
|
196
203
|
log: () => ask('log', []),
|
|
197
204
|
persistence: () => ask('persistence', []),
|
|
205
|
+
retry: () => ask('retry', []),
|
|
198
206
|
observe: ((topic, ...input) => watch(topic, input)),
|
|
199
207
|
reauthorize: () => ask('reauthorize', []),
|
|
200
208
|
settled,
|
|
@@ -206,3 +214,4 @@ export function inTurn(client, work) {
|
|
|
206
214
|
turns.set(client, next);
|
|
207
215
|
return next;
|
|
208
216
|
}
|
|
217
|
+
export { unanswered } from './wire.js';
|
package/dist/collection.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { type Document, type Validation } from '@agentshouse/mdmodel';
|
|
2
|
-
import type
|
|
1
|
+
import { type Document, type Frontmatter, type Validation } from '@agentshouse/mdmodel';
|
|
2
|
+
import { type ModelState } from './model.js';
|
|
3
3
|
import type { MdModelIdentity } from './adapter.js';
|
|
4
|
+
import { type Paths } from './shared.js';
|
|
4
5
|
import type { Refused } from './transfer.js';
|
|
6
|
+
import { type Later } from './turn.js';
|
|
5
7
|
export declare const MD_MODEL: MdModelIdentity;
|
|
6
8
|
export type Collection = {
|
|
7
9
|
text: Readonly<Record<string, string>>;
|
|
@@ -17,9 +19,21 @@ export type Composition = {
|
|
|
17
19
|
};
|
|
18
20
|
export declare function governing(composition: Composition, path: string): ModelState;
|
|
19
21
|
export declare function collectionOf(text: Readonly<Record<string, string>>, composition: Composition, previous?: Collection): Collection;
|
|
20
|
-
export declare function
|
|
22
|
+
export declare function passingFrontmatter(collection: Collection, path: string): Frontmatter | undefined;
|
|
21
23
|
export declare function documentsOf(collection: Collection): Generator<readonly [string, Document]>;
|
|
22
24
|
export declare function unreadable(text: Readonly<Record<string, string>>, previous?: Readonly<Record<string, string>>): Refused | null;
|
|
23
25
|
export declare function validRoot(root: unknown): root is string;
|
|
24
26
|
export declare function validateCollection(text: Readonly<Record<string, string>>, binaryTargets: readonly string[], composition: Composition): Validation;
|
|
27
|
+
type Held = {
|
|
28
|
+
text: Paths<string>;
|
|
29
|
+
binaries: Paths<unknown>;
|
|
30
|
+
};
|
|
31
|
+
export declare function indexReferrers(held: Held, composition: Composition): Later<void>;
|
|
32
|
+
export declare function referencesIndexed(held: Held, composition: Composition): boolean;
|
|
33
|
+
export declare function referring(held: Held, composition: Composition, targets: Iterable<string>): ReadonlySet<string> | null;
|
|
34
|
+
export declare function available(composition: Composition): boolean;
|
|
35
|
+
export declare function changedCleanly(next: Held, previous: Held & {
|
|
36
|
+
composition: Composition;
|
|
37
|
+
}, composition: Composition): boolean;
|
|
38
|
+
export {};
|
|
25
39
|
//# sourceMappingURL=collection.d.ts.map
|
package/dist/collection.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,KAAK,QAAQ,EAEb,KAAK,WAAW,EAChB,KAAK,UAAU,EAEhB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAA8B,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAuB,KAAK,KAAK,EAAE,MAAM,WAAW,CAAC;AAE5D,eAAO,MAAM,QAAQ,EAAE,eAAwE,CAAC;AAIhG,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACvC,WAAW,EAAE,WAAW,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;CAC9C,CAAC;AAEF,MAAM,MAAM,WA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GF,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,CAwBhF;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAE/E;AAED,wBAAgB,SAAS,CACvB,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,GACxB,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI,CAS5B;AAED,wBAAgB,SAAS,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAK3D;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,IAAI,GAAG;IAAE,WAAW,EAAE,WAAW,CAAA;CAAE,EAC7C,WAAW,EAAE,WAAW,GACvB,OAAO,CAiET"}
|
package/dist/collection.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { parse, validate, VERSION, } from '@agentshouse/mdmodel';
|
|
1
|
+
import { checkDocument, parseFrontmatter, references, sectionReferences, target, parse, resolves, validate, VERSION, } from '@agentshouse/mdmodel';
|
|
2
2
|
import { beneath, normalize } from './paths.js';
|
|
3
|
+
import { sameTyping } from './model.js';
|
|
4
|
+
import { differing, patched, shared } from './shared.js';
|
|
5
|
+
import { inUnits, ROW_WEIGHT } from './turn.js';
|
|
3
6
|
export const MD_MODEL = { identity: '@agentshouse/mdmodel', version: VERSION };
|
|
4
7
|
const NO_TYPES = { types: {} };
|
|
5
8
|
function selected(composition, path) {
|
|
@@ -12,46 +15,59 @@ export function governing(composition, path) {
|
|
|
12
15
|
: composition.model;
|
|
13
16
|
}
|
|
14
17
|
const parsedIn = new WeakMap();
|
|
18
|
+
function carried(previous, text) {
|
|
19
|
+
const held = parsedIn.get(previous);
|
|
20
|
+
if (held === undefined)
|
|
21
|
+
return shared({});
|
|
22
|
+
const kept = patched(held.base, held.added);
|
|
23
|
+
held.base = kept;
|
|
24
|
+
held.added = new Map();
|
|
25
|
+
return patched(kept, [], differing(previous.text, text));
|
|
26
|
+
}
|
|
27
|
+
function cachedIn(collection, path) {
|
|
28
|
+
const held = parsedIn.get(collection);
|
|
29
|
+
if (held === undefined)
|
|
30
|
+
return undefined;
|
|
31
|
+
if (held.added.has(path))
|
|
32
|
+
return held.added.get(path);
|
|
33
|
+
return Object.hasOwn(held.base, path) ? held.base[path] : undefined;
|
|
34
|
+
}
|
|
15
35
|
export function collectionOf(text, composition, previous) {
|
|
16
|
-
const parsed =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
parsed.set(path, held);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
36
|
+
const parsed = {
|
|
37
|
+
base: previous === undefined ? shared({}) : carried(previous, text),
|
|
38
|
+
added: new Map(),
|
|
39
|
+
};
|
|
23
40
|
const collection = {
|
|
24
41
|
text,
|
|
25
42
|
composition,
|
|
26
43
|
document(path) {
|
|
27
|
-
const held =
|
|
44
|
+
const held = cachedIn(collection, path);
|
|
28
45
|
if (held !== undefined)
|
|
29
46
|
return held ?? undefined;
|
|
30
47
|
const content = text[path];
|
|
31
48
|
if (content === undefined)
|
|
32
49
|
return undefined;
|
|
33
50
|
const read = parse(content, path);
|
|
34
|
-
parsed.set(path, read.ok ? read.document : null);
|
|
51
|
+
parsed.added.set(path, read.ok ? read.document : null);
|
|
35
52
|
return read.ok ? read.document : undefined;
|
|
36
53
|
},
|
|
37
54
|
};
|
|
38
55
|
parsedIn.set(collection, parsed);
|
|
39
56
|
return collection;
|
|
40
57
|
}
|
|
41
|
-
export function
|
|
42
|
-
const held =
|
|
58
|
+
export function passingFrontmatter(collection, path) {
|
|
59
|
+
const held = cachedIn(collection, path);
|
|
43
60
|
if (held !== undefined)
|
|
44
61
|
return held ?? undefined;
|
|
45
62
|
const content = collection.text[path];
|
|
46
63
|
if (content === undefined)
|
|
47
64
|
return undefined;
|
|
48
|
-
const read =
|
|
49
|
-
return read.ok ? read.
|
|
65
|
+
const read = parseFrontmatter(content, path);
|
|
66
|
+
return read.ok ? read.frontmatter : undefined;
|
|
50
67
|
}
|
|
51
68
|
export function* documentsOf(collection) {
|
|
52
|
-
const parsed = parsedIn.get(collection);
|
|
53
69
|
for (const path of Object.keys(collection.text).sort()) {
|
|
54
|
-
const held =
|
|
70
|
+
const held = cachedIn(collection, path);
|
|
55
71
|
if (held === null)
|
|
56
72
|
continue;
|
|
57
73
|
if (held !== undefined) {
|
|
@@ -64,9 +80,10 @@ export function* documentsOf(collection) {
|
|
|
64
80
|
}
|
|
65
81
|
}
|
|
66
82
|
export function unreadable(text, previous) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
83
|
+
const paths = previous === undefined
|
|
84
|
+
? Object.keys(text)
|
|
85
|
+
: [...differing(previous, text)].filter((path) => text[path] !== undefined);
|
|
86
|
+
for (const path of paths.sort()) {
|
|
70
87
|
const read = parse(text[path], path);
|
|
71
88
|
if (!read.ok)
|
|
72
89
|
return { kind: 'refused', refusal: read.refusal };
|
|
@@ -107,3 +124,197 @@ export function validateCollection(text, binaryTargets, composition) {
|
|
|
107
124
|
return verdicts[0];
|
|
108
125
|
return refusals.find((refusal) => refusal.rule !== 'model-unavailable') ?? refusals[0];
|
|
109
126
|
}
|
|
127
|
+
const referrersOf = new WeakMap();
|
|
128
|
+
function typing(left, right) {
|
|
129
|
+
return (sameTyping(left.model, right.model) &&
|
|
130
|
+
(left.selection === null || right.selection === null
|
|
131
|
+
? left.selection === right.selection
|
|
132
|
+
: sameTyping(left.selection.model, right.selection.model)) &&
|
|
133
|
+
JSON.stringify(left.selection?.roots ?? null) === JSON.stringify(right.selection?.roots ?? null));
|
|
134
|
+
}
|
|
135
|
+
function declared(content) {
|
|
136
|
+
if (content === undefined)
|
|
137
|
+
return undefined;
|
|
138
|
+
const read = parseFrontmatter(content);
|
|
139
|
+
return read.ok ? (read.frontmatter.type ?? 'any') : undefined;
|
|
140
|
+
}
|
|
141
|
+
function typedIn(content) {
|
|
142
|
+
const type = declared(content);
|
|
143
|
+
return type !== undefined && type !== 'any';
|
|
144
|
+
}
|
|
145
|
+
function modelOf(composition, path) {
|
|
146
|
+
const model = governing(composition, path);
|
|
147
|
+
return model.status === 'unavailable' ? null : { types: model.types };
|
|
148
|
+
}
|
|
149
|
+
function checked(path, content, composition) {
|
|
150
|
+
return checkDocument(path, content, modelOf(composition, path) ?? NO_TYPES);
|
|
151
|
+
}
|
|
152
|
+
function targetsOf(check) {
|
|
153
|
+
if (!check.ok)
|
|
154
|
+
return [];
|
|
155
|
+
return [...new Set(check.references.flatMap(({ target }) => (target === null ? [] : [target])))];
|
|
156
|
+
}
|
|
157
|
+
function referencedBy(path, content, composition) {
|
|
158
|
+
const model = modelOf(composition, path);
|
|
159
|
+
if (model === null)
|
|
160
|
+
return [];
|
|
161
|
+
const read = parseFrontmatter(content, path);
|
|
162
|
+
const type = read.ok ? read.frontmatter.type : undefined;
|
|
163
|
+
if (!read.ok || type === undefined || !Object.hasOwn(model.types, type))
|
|
164
|
+
return [];
|
|
165
|
+
const definition = model.types[type];
|
|
166
|
+
return [
|
|
167
|
+
...new Set([
|
|
168
|
+
...references(read.frontmatter, definition).flatMap(({ value }) => {
|
|
169
|
+
const found = target(path, value);
|
|
170
|
+
return found === null ? [] : [found];
|
|
171
|
+
}),
|
|
172
|
+
...sectionReferences(path, content, definition).flatMap(({ target }) => target === null ? [] : [target]),
|
|
173
|
+
]),
|
|
174
|
+
];
|
|
175
|
+
}
|
|
176
|
+
function reindexed(index, changed) {
|
|
177
|
+
const referrers = new Map();
|
|
178
|
+
const touch = (target) => {
|
|
179
|
+
let held = referrers.get(target);
|
|
180
|
+
if (held === undefined) {
|
|
181
|
+
held = new Set(Object.hasOwn(index.referrers, target) ? index.referrers[target] : []);
|
|
182
|
+
referrers.set(target, held);
|
|
183
|
+
}
|
|
184
|
+
return held;
|
|
185
|
+
};
|
|
186
|
+
for (const [path, found] of changed) {
|
|
187
|
+
const before = Object.hasOwn(index.targets, path) ? index.targets[path] : [];
|
|
188
|
+
for (const target of before)
|
|
189
|
+
touch(target).delete(path);
|
|
190
|
+
for (const target of found)
|
|
191
|
+
touch(target).add(path);
|
|
192
|
+
}
|
|
193
|
+
const emptied = [...referrers].filter(([, held]) => held.size === 0).map(([target]) => target);
|
|
194
|
+
return {
|
|
195
|
+
composition: index.composition,
|
|
196
|
+
targets: patched(index.targets, [...changed].filter(([, found]) => found.length > 0), [...changed].filter(([, found]) => found.length === 0).map(([path]) => path)),
|
|
197
|
+
referrers: patched(index.referrers, [...referrers]
|
|
198
|
+
.filter(([, held]) => held.size > 0)
|
|
199
|
+
.map(([target, held]) => [target, [...held]]), emptied),
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function heldIndex(held, composition) {
|
|
203
|
+
const index = referrersOf.get(held.text);
|
|
204
|
+
return index !== undefined && typing(index.composition, composition) ? index : null;
|
|
205
|
+
}
|
|
206
|
+
const indexing = new WeakMap();
|
|
207
|
+
export function indexReferrers(held, composition) {
|
|
208
|
+
if (heldIndex(held, composition) !== null)
|
|
209
|
+
return;
|
|
210
|
+
const running = indexing.get(held.text);
|
|
211
|
+
if (running !== undefined)
|
|
212
|
+
return running;
|
|
213
|
+
const targets = new Map();
|
|
214
|
+
const referrers = new Map();
|
|
215
|
+
const filled = inUnits(Object.keys(held.text), (path) => {
|
|
216
|
+
const content = held.text[path];
|
|
217
|
+
const found = referencedBy(path, content, composition);
|
|
218
|
+
if (found.length > 0)
|
|
219
|
+
targets.set(path, found);
|
|
220
|
+
for (const target of found)
|
|
221
|
+
referrers.set(target, [...(referrers.get(target) ?? []), path]);
|
|
222
|
+
return ROW_WEIGHT + content.length;
|
|
223
|
+
});
|
|
224
|
+
const indexed = () => {
|
|
225
|
+
referrersOf.set(held.text, {
|
|
226
|
+
composition,
|
|
227
|
+
targets: patched(shared({}), targets),
|
|
228
|
+
referrers: patched(shared({}), referrers),
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
if (!(filled instanceof Promise))
|
|
232
|
+
return indexed();
|
|
233
|
+
const building = filled.then(indexed).finally(() => indexing.delete(held.text));
|
|
234
|
+
indexing.set(held.text, building);
|
|
235
|
+
return building;
|
|
236
|
+
}
|
|
237
|
+
export function referencesIndexed(held, composition) {
|
|
238
|
+
return heldIndex(held, composition) !== null;
|
|
239
|
+
}
|
|
240
|
+
export function referring(held, composition, targets) {
|
|
241
|
+
const index = heldIndex(held, composition);
|
|
242
|
+
if (index === null)
|
|
243
|
+
return null;
|
|
244
|
+
const found = new Set();
|
|
245
|
+
for (const target of targets) {
|
|
246
|
+
if (!Object.hasOwn(index.referrers, target))
|
|
247
|
+
continue;
|
|
248
|
+
for (const file of index.referrers[target])
|
|
249
|
+
found.add(file);
|
|
250
|
+
}
|
|
251
|
+
return found;
|
|
252
|
+
}
|
|
253
|
+
export function available(composition) {
|
|
254
|
+
return (composition.model.status !== 'unavailable' &&
|
|
255
|
+
(composition.selection === null || composition.selection.model.status !== 'unavailable'));
|
|
256
|
+
}
|
|
257
|
+
export function changedCleanly(next, previous, composition) {
|
|
258
|
+
if (!typing(previous.composition, composition))
|
|
259
|
+
return false;
|
|
260
|
+
const paths = new Set([
|
|
261
|
+
...differing(previous.text, next.text),
|
|
262
|
+
...differing(previous.binaries, next.binaries, () => true),
|
|
263
|
+
]);
|
|
264
|
+
const binary = (path) => Object.hasOwn(next.binaries, path);
|
|
265
|
+
const within = (file) => (path) => selected(composition, path) === selected(composition, file);
|
|
266
|
+
const reaching = (file, check) => {
|
|
267
|
+
if (!check.ok)
|
|
268
|
+
return false;
|
|
269
|
+
const part = within(file);
|
|
270
|
+
return check.references.every((reference) => resolves(reference, (path) => (part(path) ? declared(next.text[path]) : undefined), (path) => part(path) && binary(path)));
|
|
271
|
+
};
|
|
272
|
+
const changedTargets = new Map();
|
|
273
|
+
const shifted = [];
|
|
274
|
+
for (const path of paths) {
|
|
275
|
+
const now = next.text[path];
|
|
276
|
+
const was = previous.text[path];
|
|
277
|
+
const modeled = modelOf(composition, path) !== null;
|
|
278
|
+
if ((now === undefined) !== (was === undefined) ||
|
|
279
|
+
declared(now) !== declared(was) ||
|
|
280
|
+
binary(path) !== Object.hasOwn(previous.binaries, path)) {
|
|
281
|
+
shifted.push(path);
|
|
282
|
+
}
|
|
283
|
+
if (!modeled && typedIn(was) && !typedIn(now))
|
|
284
|
+
return false;
|
|
285
|
+
if (now === undefined) {
|
|
286
|
+
if (modeled)
|
|
287
|
+
changedTargets.set(path, []);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
if (binary(path))
|
|
291
|
+
return false;
|
|
292
|
+
if (!modeled) {
|
|
293
|
+
if (declared(now) === undefined)
|
|
294
|
+
return false;
|
|
295
|
+
if (!typedIn(now) && !checked(path, now, composition).ok)
|
|
296
|
+
return false;
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
const check = checked(path, now, composition);
|
|
300
|
+
if (!reaching(path, check))
|
|
301
|
+
return false;
|
|
302
|
+
changedTargets.set(path, targetsOf(check));
|
|
303
|
+
}
|
|
304
|
+
const index = heldIndex(previous, composition);
|
|
305
|
+
if (index === null && shifted.length > 0)
|
|
306
|
+
return false;
|
|
307
|
+
for (const target of shifted) {
|
|
308
|
+
const files = index !== null && Object.hasOwn(index.referrers, target) ? index.referrers[target] : [];
|
|
309
|
+
for (const file of files) {
|
|
310
|
+
if (paths.has(file))
|
|
311
|
+
continue;
|
|
312
|
+
if (!reaching(file, checked(file, next.text[file], composition)))
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
if (index !== null) {
|
|
317
|
+
referrersOf.set(next.text, changedTargets.size === 0 ? index : reindexed(index, changedTargets));
|
|
318
|
+
}
|
|
319
|
+
return true;
|
|
320
|
+
}
|