@agentshouse/mdruntime 0.1.0-c3903a68dcbbf → 0.1.0-c7b0ab1aa40a3
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 +51 -29
- package/README.md +11 -11
- package/dist/adapter.d.ts +78 -51
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +1 -9
- package/dist/attached-model.d.ts +11 -0
- package/dist/attached-model.d.ts.map +1 -0
- package/dist/attached-model.js +34 -0
- package/dist/bootstrap.d.ts +5 -3
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +2 -3
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +2 -6
- package/dist/client.d.ts +4 -9
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +3 -16
- package/dist/collection.d.ts +0 -2
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +2 -12
- package/dist/connection.d.ts +10 -28
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +516 -639
- package/dist/conversation.d.ts +22 -11
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +250 -105
- package/dist/host.d.ts +7 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +37 -57
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/memory.d.ts +11 -5
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +77 -27
- package/dist/model.d.ts +4 -11
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +4 -3
- package/dist/observation.d.ts +2 -0
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +24 -14
- package/dist/outcome.d.ts +5 -21
- package/dist/outcome.d.ts.map +1 -1
- package/dist/query.d.ts +7 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +29 -20
- package/dist/reach.d.ts +40 -0
- package/dist/reach.d.ts.map +1 -0
- package/dist/reach.js +270 -0
- package/dist/react.d.ts +31 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +62 -0
- package/dist/read-side.d.ts +4 -0
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +16 -10
- package/dist/refresh.d.ts +2 -1
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +7 -3
- package/dist/replica.d.ts +4 -4
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +14 -19
- package/dist/room-draft.d.ts +3 -0
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +6 -4
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +1 -4
- package/dist/save.d.ts +0 -2
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +5 -11
- package/dist/store.d.ts +5 -16
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +10 -32
- package/dist/wire.d.ts +51 -16
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +50 -65
- package/package.json +14 -2
package/dist/host.js
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
1
1
|
import { composeRuntime, } from './connection.js';
|
|
2
2
|
import { removeRuntimeStore } from './store.js';
|
|
3
|
-
import { AUTHORIZATION_ENDED,
|
|
4
|
-
|
|
3
|
+
import { AUTHORIZATION_ENDED, request, WIRE_REACH, } from './wire.js';
|
|
4
|
+
const NARROWED = new Set(['within', 'whole']);
|
|
5
|
+
function answered(md, app, writtenBy, member, input) {
|
|
5
6
|
switch (member) {
|
|
6
7
|
case 'rooms':
|
|
7
8
|
return md.rooms();
|
|
8
|
-
case 'slots':
|
|
9
|
-
return md.slots();
|
|
10
9
|
case 'query':
|
|
11
10
|
return md.query(input[0]);
|
|
12
11
|
case 'search':
|
|
13
12
|
return md.search(input[0]);
|
|
14
13
|
case 'types':
|
|
15
14
|
return md.types(input[0]);
|
|
16
|
-
case 'syncStatus':
|
|
17
|
-
return md.syncStatus();
|
|
18
|
-
case 'serviceMode':
|
|
19
|
-
return md.serviceMode();
|
|
20
15
|
case 'save':
|
|
21
16
|
return md.save(input[0], input[1], writtenBy);
|
|
22
|
-
case 'outcome':
|
|
23
|
-
return md.outcome(input[0]);
|
|
24
17
|
case 'history':
|
|
25
18
|
return md.history(input[0], input[1], input[2]);
|
|
26
19
|
case 'call':
|
|
@@ -29,10 +22,6 @@ function answered(md, app, writtenBy, member, input, deploymentFacts) {
|
|
|
29
22
|
return md.reached(input[0], input[1], input[2]);
|
|
30
23
|
case 'log':
|
|
31
24
|
return md.log();
|
|
32
|
-
case 'storageLoss':
|
|
33
|
-
return md.storageLoss();
|
|
34
|
-
case 'deploymentFacts':
|
|
35
|
-
return structuredClone(deploymentFacts);
|
|
36
25
|
case 'persistence':
|
|
37
26
|
return md.persistence();
|
|
38
27
|
case 'reauthorize':
|
|
@@ -74,7 +63,7 @@ function answered(md, app, writtenBy, member, input, deploymentFacts) {
|
|
|
74
63
|
}
|
|
75
64
|
}
|
|
76
65
|
export function serveMdRuntime(options) {
|
|
77
|
-
|
|
66
|
+
const deploymentFacts = structuredClone(options.deploymentFacts);
|
|
78
67
|
const closing = new AbortController();
|
|
79
68
|
const close = () => {
|
|
80
69
|
closing.abort();
|
|
@@ -83,61 +72,61 @@ export function serveMdRuntime(options) {
|
|
|
83
72
|
if (options.signal?.aborted === true)
|
|
84
73
|
close();
|
|
85
74
|
const runtime = composeRuntime({ ...options, signal: closing.signal });
|
|
86
|
-
const { md
|
|
75
|
+
const { md } = runtime;
|
|
87
76
|
const attachments = new Map();
|
|
88
77
|
let authorized = true;
|
|
89
|
-
const factsObservers = new Set();
|
|
90
78
|
const watchFacts = (deliver) => {
|
|
91
|
-
factsObservers.add(deliver);
|
|
92
79
|
deliver(structuredClone(deploymentFacts));
|
|
93
|
-
return () => {
|
|
94
|
-
factsObservers.delete(deliver);
|
|
95
|
-
};
|
|
80
|
+
return () => { };
|
|
96
81
|
};
|
|
97
|
-
function attach(port, app, release) {
|
|
82
|
+
function attach(port, app, release, reach) {
|
|
98
83
|
if (!authorized)
|
|
99
84
|
throw new Error(AUTHORIZATION_ENDED);
|
|
100
85
|
const writtenBy = release === undefined ? undefined : { app, release };
|
|
101
|
-
const
|
|
86
|
+
const view = runtime.within(reach ?? null);
|
|
87
|
+
const observations = new Map();
|
|
102
88
|
let serving = true;
|
|
103
89
|
const send = (message) => {
|
|
104
|
-
port.postMessage(
|
|
90
|
+
port.postMessage(message);
|
|
105
91
|
};
|
|
106
92
|
const detach = () => {
|
|
107
93
|
if (!serving)
|
|
108
94
|
return;
|
|
109
95
|
serving = false;
|
|
110
|
-
for (const end of
|
|
96
|
+
for (const end of observations.values())
|
|
111
97
|
end();
|
|
112
|
-
|
|
98
|
+
observations.clear();
|
|
113
99
|
attachments.delete(detach);
|
|
114
100
|
};
|
|
101
|
+
const observe = (id, topic, input) => {
|
|
102
|
+
let resolved = false;
|
|
103
|
+
const deliver = (value) => {
|
|
104
|
+
if (!serving)
|
|
105
|
+
return;
|
|
106
|
+
send(resolved ? { kind: 'event', id, value } : { kind: 'result', id, value });
|
|
107
|
+
resolved = true;
|
|
108
|
+
};
|
|
109
|
+
observations.set(id, topic === 'deployment-facts'
|
|
110
|
+
? watchFacts(deliver)
|
|
111
|
+
: (NARROWED.has(WIRE_REACH.topics[topic]) ? view : runtime).watch(topic, topic === 'presentation' ? [app] : input, deliver));
|
|
112
|
+
};
|
|
115
113
|
const serve = async (message) => {
|
|
116
114
|
if (message.kind === 'hello')
|
|
117
115
|
return;
|
|
118
116
|
if (message.kind === 'stop') {
|
|
119
|
-
|
|
120
|
-
|
|
117
|
+
observations.get(message.id)?.();
|
|
118
|
+
observations.delete(message.id);
|
|
121
119
|
return;
|
|
122
120
|
}
|
|
123
121
|
try {
|
|
124
122
|
if (message.kind !== 'observe' || message.topic !== 'room-drafts')
|
|
125
123
|
await md.loaded();
|
|
126
124
|
if (message.kind === 'observe') {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const deliver = (value) => {
|
|
130
|
-
if (!serving)
|
|
131
|
-
return;
|
|
132
|
-
send(resolved ? { kind: 'event', id, value } : { kind: 'result', id, value });
|
|
133
|
-
resolved = true;
|
|
134
|
-
};
|
|
135
|
-
subscriptions.set(id, topic === 'deployment-facts'
|
|
136
|
-
? watchFacts(deliver)
|
|
137
|
-
: watch(topic, topic === 'presentation' ? [app] : message.input, deliver));
|
|
125
|
+
if (serving)
|
|
126
|
+
observe(message.id, message.topic, message.input);
|
|
138
127
|
return;
|
|
139
128
|
}
|
|
140
|
-
const value = await answered(md, app, writtenBy, message.member, message.input
|
|
129
|
+
const value = await answered(NARROWED.has(WIRE_REACH.members[message.member]) ? view.md : md, app, writtenBy, message.member, message.input);
|
|
141
130
|
if (serving)
|
|
142
131
|
send({ kind: 'result', id: message.id, value });
|
|
143
132
|
}
|
|
@@ -154,15 +143,7 @@ export function serveMdRuntime(options) {
|
|
|
154
143
|
port.addEventListener('message', (event) => {
|
|
155
144
|
if (!serving)
|
|
156
145
|
return;
|
|
157
|
-
const
|
|
158
|
-
if (wire === null)
|
|
159
|
-
return;
|
|
160
|
-
if (!wire.matching) {
|
|
161
|
-
send({ kind: 'refusal', refusal: PROTOCOL_MISMATCH });
|
|
162
|
-
detach();
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
const message = request(wire.message);
|
|
146
|
+
const message = request(event.data);
|
|
166
147
|
if (message === null)
|
|
167
148
|
return;
|
|
168
149
|
void serve(message);
|
|
@@ -170,17 +151,16 @@ export function serveMdRuntime(options) {
|
|
|
170
151
|
port.addEventListener('close', detach);
|
|
171
152
|
port.start();
|
|
172
153
|
attachments.set(detach, send);
|
|
173
|
-
return
|
|
154
|
+
return {
|
|
155
|
+
detach,
|
|
156
|
+
narrow(next) {
|
|
157
|
+
if (serving)
|
|
158
|
+
view.narrow(next);
|
|
159
|
+
},
|
|
160
|
+
};
|
|
174
161
|
}
|
|
175
162
|
return {
|
|
176
163
|
attach,
|
|
177
|
-
replaceDeploymentFacts(value) {
|
|
178
|
-
if (!authorized)
|
|
179
|
-
throw new Error(AUTHORIZATION_ENDED);
|
|
180
|
-
deploymentFacts = structuredClone(value);
|
|
181
|
-
for (const deliver of factsObservers)
|
|
182
|
-
deliver(structuredClone(deploymentFacts));
|
|
183
|
-
},
|
|
184
164
|
async endAuthorization() {
|
|
185
165
|
authorized = false;
|
|
186
166
|
for (const [detach, send] of [...attachments]) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
export type { AcceptedMessage, ActionDeclaration, ActionRequest, ActionResult, Adapter, AdapterFailure, Authorization, BootstrapPage, BootstrapRequest, BootstrapResult, Capability, ChangeAuthor, ContractUnavailable, ConversationAction,
|
|
1
|
+
export type { AcceptedMessage, ActionDeclaration, ActionRequest, ActionResult, Adapter, AdapterFailure, Authorization, BootstrapPage, BootstrapRequest, BootstrapResult, Capability, ChangeAuthor, ContractUnavailable, ConversationAction, ConversationAgents, ConversationEvent, ConversationHistories, ConversationHistoryPage, ConversationHistoryRequest, ConversationMessage, ConversationStream, DiscoverResult, DiscoveredRoom, Discovery, HistoryAuthor, HistoryRequest, HistoryResult, HistoryRetention, HistoryRevision, HeldRoom, ListedConversation, MdModelIdentity, MutationRequest, MutationResult, PageToken, ProviderLimit, ProviderRefusal, RefreshPage, RefreshRequest, RefreshResult, Retention, RetryableRefusal, RevokedAuthorization, RoomAttachment, RoomModels, RoomNotReadable, RoomStream, RoomStreamEvent, RoomVersionAt, ServiceMode, ServiceModeSignal, TransportUncertainty, TurnContext, TurnOperation, TypedSelection, } from './adapter.js';
|
|
2
2
|
export type { Change, ChangeBatch, Precondition, WrittenBy } from './change.js';
|
|
3
|
-
export type { ChatDraft, ChatDraftSurface, ConversationEntry, ConversationOptions, ConversationSurface, ConversationView,
|
|
3
|
+
export type { ChatDraft, ChatDraftSurface, ConversationEntry, ConversationOptions, ConversationState, ConversationSurface, ConversationView, RunningTurn, } from './conversation.js';
|
|
4
4
|
export type { ChatDraftFile, FileDeclaration } from './file.js';
|
|
5
|
-
export type { AppRoom,
|
|
5
|
+
export type { AppRoom, AppTypedSelection, ConnectionRefusal, ConnectionRefusalReason, HistoryQuery, MdRuntime, MdRuntimeOptions, PresentationSurface, RoomDraftSurface, RoomSchemas, SavedRoomDraft, SaveResult, } from './connection.js';
|
|
6
6
|
export type { Observation } from './observation.js';
|
|
7
|
-
export type {
|
|
7
|
+
export type { CallResult, QueueEntry, Submission } from './outcome.js';
|
|
8
8
|
export type { ChangedPart, FieldValue, ReturnReason, RoomDraft, RoomDraftCreation, RoomDraftParts, RoomDraftWrite, } from './room-draft.js';
|
|
9
9
|
export type { SaveRefusal } from './save.js';
|
|
10
10
|
export type { DocumentHit, DocumentPart, MessageHit, SearchRequest, SearchResult, } from './search.js';
|
|
11
11
|
export { changeBatchIdentity } from './identity.js';
|
|
12
|
-
export { createMdRuntime } from './connection.js';
|
|
13
12
|
export type { RuntimeShell } from './durability.js';
|
|
14
13
|
export type { AttentionEntry, SyncStatus } from './status.js';
|
|
15
14
|
export type { Backlink, Direction, DocumentQuery, DocumentResult, Filter, GroupQuery, GroupResult, Key, LocalQuery, OrderOptions, Predicate, QueryDocument, QueryGroup, QueryResult, Related, Select, Value, Where, } from './query.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,OAAO,EACP,cAAc,EACd,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,OAAO,EACP,cAAc,EACd,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,eAAe,EAC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iBAAiB,EACjB,cAAc,EACd,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,YAAY,EACV,WAAW,EACX,YAAY,EACZ,UAAU,EACV,aAAa,EACb,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9D,YAAY,EACV,QAAQ,EACR,SAAS,EACT,aAAa,EACb,cAAc,EACd,MAAM,EACN,UAAU,EACV,WAAW,EACX,GAAG,EACH,UAAU,EACV,YAAY,EACZ,SAAS,EACT,aAAa,EACb,UAAU,EACV,WAAW,EACX,OAAO,EACP,MAAM,EACN,KAAK,EACL,KAAK,GACN,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,MAAM,EACN,aAAa,EACb,aAAa,EACb,UAAU,EACV,WAAW,EACX,WAAW,EACX,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/memory.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ModelResult } from './model.js';
|
|
2
|
-
import { type AcceptedMessage, type ActionResult, type Adapter, type Capability, type ConversationAction, type ConversationEvent, type DiscoveredRoom, type HeadChange, type
|
|
2
|
+
import { type AcceptedMessage, type ActionResult, type Adapter, type Capability, type ConversationAction, type ConversationEvent, type DiscoveredRoom, type HeadChange, type ListedConversation, type ProviderLimit, type Retention, type RoomAttachment, type ServiceMode } from './adapter.js';
|
|
3
3
|
export type MemoryRoom = DiscoveredRoom & {
|
|
4
4
|
model?: ModelResult;
|
|
5
5
|
selectionModel?: ModelResult;
|
|
@@ -11,6 +11,7 @@ export type MemoryRoom = DiscoveredRoom & {
|
|
|
11
11
|
};
|
|
12
12
|
export type MemoryConversation = {
|
|
13
13
|
conversation: string;
|
|
14
|
+
listed?: Omit<ListedConversation, 'conversation'>;
|
|
14
15
|
messages?: readonly AcceptedMessage[];
|
|
15
16
|
outcomes?: Partial<Record<ConversationAction, ActionResult>>;
|
|
16
17
|
};
|
|
@@ -19,20 +20,25 @@ export type MemoryAdapterOptions = {
|
|
|
19
20
|
conversations?: readonly MemoryConversation[];
|
|
20
21
|
historyPageSize?: number;
|
|
21
22
|
pageSize?: number;
|
|
22
|
-
mdModel?: MdModelIdentity;
|
|
23
|
-
supportedVersions?: readonly number[];
|
|
24
23
|
capabilities?: readonly Capability[];
|
|
25
24
|
providerLimits?: readonly ProviderLimit[];
|
|
26
25
|
retention?: Retention;
|
|
26
|
+
unopened?: boolean;
|
|
27
27
|
};
|
|
28
28
|
export type MemoryAdapter = Adapter & {
|
|
29
29
|
setRooms(rooms: readonly MemoryRoom[]): void;
|
|
30
30
|
setConversations(conversations: readonly MemoryConversation[]): void;
|
|
31
31
|
script(operation: keyof Adapter, answer: unknown): void;
|
|
32
|
-
|
|
32
|
+
open(): void;
|
|
33
|
+
close(revoked?: boolean): void;
|
|
34
|
+
expire(locators: readonly string[]): void;
|
|
35
|
+
notifyRoomVersion(notification: {
|
|
36
|
+
locator: string;
|
|
37
|
+
roomVersion: string;
|
|
38
|
+
}): void;
|
|
33
39
|
notifyConversation(event: ConversationEvent): void;
|
|
34
40
|
notifyServiceMode(mode: ServiceMode): void;
|
|
35
|
-
|
|
41
|
+
heldRooms(): readonly string[];
|
|
36
42
|
replicatedConversations(): readonly string[];
|
|
37
43
|
};
|
|
38
44
|
export declare function createMemoryAdapter(options?: MemoryAdapterOptions): MemoryAdapter;
|
package/dist/memory.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AA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"}
|
package/dist/memory.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { ROOM_CONTRACT_VERSION, } from './adapter.js';
|
|
2
|
-
import { MD_MODEL } from './collection.js';
|
|
3
1
|
import { sameChange } from './overlay.js';
|
|
4
2
|
const FIXTURE_RETENTION = {
|
|
5
3
|
history: { kind: 'duration', seconds: 1 },
|
|
@@ -15,6 +13,19 @@ function declaredRetention(value) {
|
|
|
15
13
|
}
|
|
16
14
|
throw new Error('history retention duration must be a finite positive number of seconds');
|
|
17
15
|
}
|
|
16
|
+
const MODEL_ABSENT = { kind: 'model-unavailable', reason: 'not-readable' };
|
|
17
|
+
function modelsOf(room) {
|
|
18
|
+
return {
|
|
19
|
+
collection: room.model ?? MODEL_ABSENT,
|
|
20
|
+
...(room.typedSelection === undefined
|
|
21
|
+
? {}
|
|
22
|
+
: { selection: room.selectionModel ?? MODEL_ABSENT }),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function changedModels(room, from) {
|
|
26
|
+
const now = modelsOf(room);
|
|
27
|
+
return JSON.stringify(now) === JSON.stringify(modelsOf(from)) ? undefined : now;
|
|
28
|
+
}
|
|
18
29
|
function named(source, paths) {
|
|
19
30
|
const taken = {};
|
|
20
31
|
for (const path of paths) {
|
|
@@ -31,8 +42,6 @@ async function resolveScript(answer, fallback, request) {
|
|
|
31
42
|
}
|
|
32
43
|
export function createMemoryAdapter(options = {}) {
|
|
33
44
|
let rooms = options.rooms === undefined ? [] : [...options.rooms];
|
|
34
|
-
const mdModel = options.mdModel ?? MD_MODEL;
|
|
35
|
-
const supportedVersions = options.supportedVersions ?? [ROOM_CONTRACT_VERSION];
|
|
36
45
|
const capabilities = options.capabilities ?? [];
|
|
37
46
|
const providerLimits = options.providerLimits ?? [];
|
|
38
47
|
const retention = declaredRetention(options.retention);
|
|
@@ -47,7 +56,8 @@ export function createMemoryAdapter(options = {}) {
|
|
|
47
56
|
const unsealed = new Map();
|
|
48
57
|
const sealed = new Set();
|
|
49
58
|
const historyPageSize = options.historyPageSize;
|
|
50
|
-
let
|
|
59
|
+
let held = [];
|
|
60
|
+
let expiring = [];
|
|
51
61
|
let replicated = [];
|
|
52
62
|
let issued = 0;
|
|
53
63
|
function scriptConversations(entries) {
|
|
@@ -92,9 +102,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
92
102
|
roomVersion: room.roomVersion,
|
|
93
103
|
operations: room.operations,
|
|
94
104
|
replica: room.replica,
|
|
95
|
-
attachedModel: room.attachedModel,
|
|
96
105
|
...(room.typedSelection === undefined ? {} : { typedSelection: room.typedSelection }),
|
|
97
|
-
...(room.untypedFolders === undefined ? {} : { untypedFolders: room.untypedFolders }),
|
|
98
106
|
providerOwnedPaths: room.providerOwnedPaths,
|
|
99
107
|
};
|
|
100
108
|
}
|
|
@@ -107,6 +115,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
107
115
|
return {
|
|
108
116
|
kind: 'bootstrap',
|
|
109
117
|
roomVersion: room.roomVersion,
|
|
118
|
+
...(from === 0 ? { models: modelsOf(room) } : {}),
|
|
110
119
|
documents: named(room.documents ?? {}, taken),
|
|
111
120
|
revisions: named(room.revisions ?? {}, taken),
|
|
112
121
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
@@ -137,9 +146,11 @@ export function createMemoryAdapter(options = {}) {
|
|
|
137
146
|
: [];
|
|
138
147
|
const attachments = room.attachments ?? [];
|
|
139
148
|
const declared = opening && JSON.stringify(attachments) !== JSON.stringify(from.attachments ?? []);
|
|
149
|
+
const models = opening ? changedModels(room, from) : undefined;
|
|
140
150
|
return {
|
|
141
151
|
kind: 'net-advancement',
|
|
142
152
|
roomVersion: room.roomVersion,
|
|
153
|
+
...(models === undefined ? {} : { models }),
|
|
143
154
|
documents: named(current, taken),
|
|
144
155
|
revisions: named(room.revisions ?? {}, taken),
|
|
145
156
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
@@ -222,11 +233,14 @@ export function createMemoryAdapter(options = {}) {
|
|
|
222
233
|
scripted.delete(named);
|
|
223
234
|
return { kind: 'action', result: { conversation: named } };
|
|
224
235
|
}
|
|
236
|
+
function announceList() {
|
|
237
|
+
const entries = [...scripted.values()].flatMap(({ conversation, listed }) => listed === undefined ? [] : [{ conversation, ...listed }]);
|
|
238
|
+
for (const listener of listeners)
|
|
239
|
+
listener({ kind: 'list', entries });
|
|
240
|
+
}
|
|
225
241
|
function discovery() {
|
|
226
242
|
return {
|
|
227
243
|
kind: 'discovery',
|
|
228
|
-
supportedVersions,
|
|
229
|
-
mdModel,
|
|
230
244
|
rooms: rooms.map(declared),
|
|
231
245
|
capabilities,
|
|
232
246
|
providerLimits,
|
|
@@ -241,9 +255,21 @@ export function createMemoryAdapter(options = {}) {
|
|
|
241
255
|
setConversations(next) {
|
|
242
256
|
scriptConversations(next);
|
|
243
257
|
},
|
|
244
|
-
|
|
258
|
+
open() {
|
|
259
|
+
announceList();
|
|
260
|
+
for (const observer of observers)
|
|
261
|
+
observer({ kind: 'opened' });
|
|
262
|
+
},
|
|
263
|
+
close(revoked = false) {
|
|
264
|
+
for (const observer of observers)
|
|
265
|
+
observer({ kind: 'closed', revoked });
|
|
266
|
+
},
|
|
267
|
+
expire(locators) {
|
|
268
|
+
expiring = [...locators];
|
|
269
|
+
},
|
|
270
|
+
notifyRoomVersion({ locator, roomVersion }) {
|
|
245
271
|
for (const observer of observers)
|
|
246
|
-
observer(
|
|
272
|
+
observer({ kind: 'room-version', locator, roomVersion });
|
|
247
273
|
},
|
|
248
274
|
notifyConversation(event) {
|
|
249
275
|
if (event.kind === 'accepted-message') {
|
|
@@ -257,8 +283,8 @@ export function createMemoryAdapter(options = {}) {
|
|
|
257
283
|
for (const observer of modeObservers)
|
|
258
284
|
observer(mode);
|
|
259
285
|
},
|
|
260
|
-
|
|
261
|
-
return
|
|
286
|
+
heldRooms() {
|
|
287
|
+
return held;
|
|
262
288
|
},
|
|
263
289
|
replicatedConversations() {
|
|
264
290
|
return replicated;
|
|
@@ -282,12 +308,39 @@ export function createMemoryAdapter(options = {}) {
|
|
|
282
308
|
};
|
|
283
309
|
},
|
|
284
310
|
},
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
311
|
+
roomStream: {
|
|
312
|
+
hold(asked) {
|
|
313
|
+
held = asked.map((room) => room.locator);
|
|
314
|
+
const expired = expiring.filter((locator) => held.includes(locator));
|
|
315
|
+
expiring = [];
|
|
316
|
+
const moved = asked.flatMap((room) => {
|
|
317
|
+
const current = rooms.find((entry) => entry.locator === room.locator);
|
|
318
|
+
return current === undefined ||
|
|
319
|
+
expired.includes(room.locator) ||
|
|
320
|
+
current.roomVersion === room.roomVersion
|
|
321
|
+
? []
|
|
322
|
+
: [{ locator: room.locator, roomVersion: current.roomVersion }];
|
|
323
|
+
});
|
|
324
|
+
queueMicrotask(() => {
|
|
325
|
+
for (const observer of observers) {
|
|
326
|
+
for (const room of moved)
|
|
327
|
+
observer({ kind: 'room-version', ...room });
|
|
328
|
+
observer({ kind: 'opening', expired });
|
|
329
|
+
}
|
|
330
|
+
});
|
|
288
331
|
},
|
|
289
332
|
observe(notify) {
|
|
290
333
|
observers.add(notify);
|
|
334
|
+
queueMicrotask(() => {
|
|
335
|
+
if (!observers.has(notify))
|
|
336
|
+
return;
|
|
337
|
+
if (options.unopened === true) {
|
|
338
|
+
notify({ kind: 'closed', revoked: false });
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
announceList();
|
|
342
|
+
notify({ kind: 'opened' });
|
|
343
|
+
});
|
|
291
344
|
return () => {
|
|
292
345
|
observers.delete(notify);
|
|
293
346
|
};
|
|
@@ -299,13 +352,6 @@ export function createMemoryAdapter(options = {}) {
|
|
|
299
352
|
else
|
|
300
353
|
scripts[operation] = answer;
|
|
301
354
|
},
|
|
302
|
-
async model(_authorization, request) {
|
|
303
|
-
return resolveScript(scripts.model, () => {
|
|
304
|
-
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
305
|
-
const answer = request.attached === 'collection' ? room?.model : room?.selectionModel;
|
|
306
|
-
return answer ?? { kind: 'model-unavailable', reason: 'not-readable' };
|
|
307
|
-
}, request);
|
|
308
|
-
},
|
|
309
355
|
async authorize() {
|
|
310
356
|
return resolveScript(scripts.authorize, () => ({}), undefined);
|
|
311
357
|
},
|
|
@@ -318,6 +364,14 @@ export function createMemoryAdapter(options = {}) {
|
|
|
318
364
|
});
|
|
319
365
|
},
|
|
320
366
|
reached,
|
|
367
|
+
follows(locator, roomVersion, next) {
|
|
368
|
+
const scripted = scripts.follows;
|
|
369
|
+
if (typeof scripted === 'boolean')
|
|
370
|
+
return scripted;
|
|
371
|
+
if (scripted !== undefined)
|
|
372
|
+
return scripted(locator, roomVersion, next);
|
|
373
|
+
return true;
|
|
374
|
+
},
|
|
321
375
|
async bootstrap(_authorization, request) {
|
|
322
376
|
return resolveScript(scripts.bootstrap, () => {
|
|
323
377
|
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
@@ -342,10 +396,6 @@ export function createMemoryAdapter(options = {}) {
|
|
|
342
396
|
}
|
|
343
397
|
return advancement(continuation.room, continuation.from, continuation.at);
|
|
344
398
|
}
|
|
345
|
-
if (request.minPosition !== undefined &&
|
|
346
|
-
!reached(room.locator, room.roomVersion, request.minPosition)) {
|
|
347
|
-
return { kind: 'retryable-refusal', code: 'replica_behind', fields: {} };
|
|
348
|
-
}
|
|
349
399
|
if (request.fromRoomVersion === room.roomVersion) {
|
|
350
400
|
return { kind: 'still-current' };
|
|
351
401
|
}
|
package/dist/model.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Definition,
|
|
1
|
+
import type { Definition, ValueFacts, VerifiedModel } from '@agentshouse/mdmodel';
|
|
2
2
|
export type ModelIdentity = {
|
|
3
3
|
identity: string;
|
|
4
4
|
version: string;
|
|
@@ -6,23 +6,15 @@ export type ModelIdentity = {
|
|
|
6
6
|
export type ModelSnapshot = ModelIdentity & {
|
|
7
7
|
schema: string | null;
|
|
8
8
|
};
|
|
9
|
-
export type ModelUnavailableReason = 'not-readable' | 'revoked' | 'not-acquired' | '
|
|
9
|
+
export type ModelUnavailableReason = 'not-readable' | 'revoked' | 'not-acquired' | 'invalid';
|
|
10
10
|
export type ModelResult = {
|
|
11
11
|
kind: 'model';
|
|
12
12
|
snapshot: ModelSnapshot;
|
|
13
13
|
} | {
|
|
14
14
|
kind: 'model-unavailable';
|
|
15
15
|
reason: ModelUnavailableReason;
|
|
16
|
-
} | {
|
|
17
|
-
kind: 'transport-uncertainty';
|
|
18
|
-
} | {
|
|
19
|
-
kind: 'revoked-authorization';
|
|
20
|
-
};
|
|
21
|
-
export type MdType = {
|
|
22
|
-
name: string;
|
|
23
|
-
fields: Readonly<Record<string, FieldSpec>>;
|
|
24
|
-
sections: Readonly<Record<string, SectionSpec>>;
|
|
25
16
|
};
|
|
17
|
+
export type MdType = Definition;
|
|
26
18
|
export type ModelState = {
|
|
27
19
|
status: 'unavailable';
|
|
28
20
|
reason: ModelUnavailableReason;
|
|
@@ -52,4 +44,5 @@ export declare function definitionOf(state: ModelState, type: string | undefined
|
|
|
52
44
|
export declare function modelTypes(state: ModelState): TypesResult;
|
|
53
45
|
export declare function cached(state: ModelState): ModelState;
|
|
54
46
|
export declare function sameModel(left: ModelIdentity, right: ModelIdentity): boolean;
|
|
47
|
+
export declare function referenceField(facts: ValueFacts | undefined): boolean;
|
|
55
48
|
//# sourceMappingURL=model.d.ts.map
|
package/dist/model.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAElF,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ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AAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAGhG;AACD,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAczD;AACD,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAEpD;AACD,wBAAgB,SAAS,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO,CAE5E;AACD,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CAErE"}
|
package/dist/model.js
CHANGED
|
@@ -12,9 +12,7 @@ export function modelTypes(state) {
|
|
|
12
12
|
identity: state.snapshot.identity,
|
|
13
13
|
version: state.snapshot.version,
|
|
14
14
|
verifiedWith: { ...state.verifiedWith },
|
|
15
|
-
types: structuredClone(Object.values(state.types)
|
|
16
|
-
.sort((left, right) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0))
|
|
17
|
-
.map(({ name, fields, sections }) => ({ name, fields, sections }))),
|
|
15
|
+
types: structuredClone(Object.values(state.types).sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0)),
|
|
18
16
|
};
|
|
19
17
|
}
|
|
20
18
|
export function cached(state) {
|
|
@@ -23,3 +21,6 @@ export function cached(state) {
|
|
|
23
21
|
export function sameModel(left, right) {
|
|
24
22
|
return left.identity === right.identity && left.version === right.version;
|
|
25
23
|
}
|
|
24
|
+
export function referenceField(facts) {
|
|
25
|
+
return facts?.reference !== undefined || facts?.items?.reference !== undefined;
|
|
26
|
+
}
|
package/dist/observation.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export type Observed = {
|
|
|
20
20
|
end(): void;
|
|
21
21
|
};
|
|
22
22
|
export declare function rowsOf(result: QueryResult): readonly (QueryDocument | QueryGroup)[];
|
|
23
|
+
export declare function applied(keyed: KeyedResult, change: QueryChange): KeyedResult;
|
|
23
24
|
export declare function observed(first: unknown, stop: () => void, keyed: boolean): Observed;
|
|
24
25
|
export declare function opened(watch: (deliver: (message: unknown) => void) => () => void, keyed: boolean): Promise<Observation<unknown>>;
|
|
26
|
+
export declare function observing<Topic extends string>(watch: (topic: Topic, input: readonly unknown[], deliver: (message: unknown) => void) => () => void): (topic: Topic, ...input: unknown[]) => Promise<Observation<unknown>>;
|
|
25
27
|
//# sourceMappingURL=observation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observation.d.ts","sourceRoot":"","sources":["../src/observation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzE,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC3B,OAAO,IAAI,CAAC,CAAC;IACb,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACpD,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAErC,MAAM,MAAM,WAAW,GAAG;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAE3E,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,aAAa,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC;IACpE,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAClC,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAChC,GAAG,IAAI,IAAI,CAAC;CACb,CAAC;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,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,EAAE,KAAK,EAAE,OAAO,GAAG,QAAQ,CAkCnF;AAED,wBAAgB,MAAM,CACpB,KAAK,EAAE,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,KAAK,MAAM,IAAI,EAC1D,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAiB/B;AAED,wBAAgB,SAAS,CAAC,KAAK,SAAS,MAAM,EAC5C,KAAK,EAAE,CACL,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,SAAS,OAAO,EAAE,EACzB,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,KAChC,MAAM,IAAI,WAEA,KAAK,YAAY,OAAO,EAAE,KAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAQ1E"}
|
package/dist/observation.js
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
export function rowsOf(result) {
|
|
2
2
|
return 'groups' in result ? result.groups : result.documents;
|
|
3
3
|
}
|
|
4
|
+
export function applied(keyed, change) {
|
|
5
|
+
const rows = rowsOf(keyed.result);
|
|
6
|
+
const byKey = new Map(keyed.keys.map((key, index) => [key, rows[index]]));
|
|
7
|
+
for (const key of change.removed)
|
|
8
|
+
byKey.delete(key);
|
|
9
|
+
for (const [key, row] of change.changed)
|
|
10
|
+
byKey.set(key, row);
|
|
11
|
+
const keys = change.order ?? keyed.keys.filter((key) => byKey.has(key));
|
|
12
|
+
const next = keys.map((key) => byKey.get(key));
|
|
13
|
+
return {
|
|
14
|
+
result: 'groups' in keyed.result
|
|
15
|
+
? { groups: next }
|
|
16
|
+
: { documents: next },
|
|
17
|
+
keys,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
4
20
|
function keyedResult(first) {
|
|
5
|
-
|
|
6
|
-
const rows = rowsOf(first.result);
|
|
7
|
-
const byKey = new Map(first.keys.map((key, index) => [key, rows[index]]));
|
|
8
|
-
let keys = first.keys;
|
|
21
|
+
let keyed = first;
|
|
9
22
|
return {
|
|
10
23
|
value: first.result,
|
|
11
24
|
next(message) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
byKey.delete(key);
|
|
15
|
-
for (const [key, row] of change.changed)
|
|
16
|
-
byKey.set(key, row);
|
|
17
|
-
keys = change.order ?? keys.filter((key) => byKey.has(key));
|
|
18
|
-
const next = keys.map((key) => byKey.get(key));
|
|
19
|
-
return grouped
|
|
20
|
-
? { groups: next }
|
|
21
|
-
: { documents: next };
|
|
25
|
+
keyed = applied(keyed, message);
|
|
26
|
+
return keyed.result;
|
|
22
27
|
},
|
|
23
28
|
};
|
|
24
29
|
}
|
|
@@ -83,3 +88,8 @@ export function opened(watch, keyed) {
|
|
|
83
88
|
}
|
|
84
89
|
});
|
|
85
90
|
}
|
|
91
|
+
export function observing(watch) {
|
|
92
|
+
return (topic, ...input) => opened((deliver) => watch(topic, input, (message) => {
|
|
93
|
+
deliver(structuredClone(message));
|
|
94
|
+
}), topic === 'query');
|
|
95
|
+
}
|