@agentshouse/mdruntime 0.1.0-alpha.9 → 0.1.0-c009335e08279
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 +208 -0
- package/README.md +44 -0
- package/dist/adapter.d.ts +147 -12
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +2 -3
- package/dist/attachment.d.ts +3 -0
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +8 -0
- package/dist/bootstrap.d.ts +3 -7
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +28 -27
- package/dist/change-set.d.ts +33 -0
- package/dist/change-set.d.ts.map +1 -0
- package/dist/change-set.js +83 -0
- package/dist/change.d.ts +9 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +6 -5
- package/dist/client.d.ts +38 -32
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +115 -177
- package/dist/collection.d.ts +13 -16
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +45 -88
- package/dist/connection.d.ts +46 -39
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1376 -975
- package/dist/conversation.d.ts +41 -19
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +483 -327
- package/dist/durability.js +6 -6
- package/dist/file.d.ts +2 -2
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +48 -71
- package/dist/host.d.ts +6 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +83 -108
- package/dist/identity.d.ts +1 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +10 -9
- package/dist/index.d.ts +12 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/log.js +5 -6
- package/dist/memory.d.ts +6 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +205 -210
- package/dist/model.d.ts +10 -25
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +18 -21
- package/dist/observation.d.ts +25 -0
- package/dist/observation.d.ts.map +1 -0
- package/dist/observation.js +85 -0
- package/dist/outcome.d.ts +10 -29
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +1 -23
- package/dist/overlay.d.ts +9 -2
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +187 -43
- package/dist/paths.d.ts +0 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +12 -19
- package/dist/query.d.ts +210 -10
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +420 -15
- package/dist/read-side.d.ts +14 -0
- package/dist/read-side.d.ts.map +1 -0
- package/dist/read-side.js +371 -0
- package/dist/refresh.d.ts +4 -5
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +45 -30
- package/dist/replica.d.ts +25 -5
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +228 -38
- package/dist/room-draft.d.ts +124 -0
- package/dist/room-draft.d.ts.map +1 -0
- package/dist/room-draft.js +327 -0
- package/dist/rows.d.ts +41 -0
- package/dist/rows.d.ts.map +1 -0
- package/dist/rows.js +100 -0
- package/dist/save.d.ts +8 -4
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +264 -350
- package/dist/search.d.ts +61 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +125 -0
- package/dist/status.d.ts +4 -6
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +9 -13
- package/dist/store.d.ts +59 -31
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +338 -134
- package/dist/transfer.d.ts +5 -0
- package/dist/transfer.d.ts.map +1 -1
- package/dist/transfer.js +1 -5
- package/dist/wire.d.ts +4 -3
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +47 -68
- package/package.json +6 -12
- package/dist/adapter.js.map +0 -1
- package/dist/bootstrap.js.map +0 -1
- package/dist/change.js.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/collection.js.map +0 -1
- package/dist/connection.js.map +0 -1
- package/dist/conversation.js.map +0 -1
- package/dist/durability.js.map +0 -1
- package/dist/file.js.map +0 -1
- package/dist/host.js.map +0 -1
- package/dist/identity.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/log.js.map +0 -1
- package/dist/memory.js.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/outcome.js.map +0 -1
- package/dist/overlay.js.map +0 -1
- package/dist/paths.js.map +0 -1
- package/dist/query.js.map +0 -1
- package/dist/refresh.js.map +0 -1
- package/dist/replica.js.map +0 -1
- package/dist/save.js.map +0 -1
- package/dist/status.js.map +0 -1
- package/dist/store.js.map +0 -1
- package/dist/transfer.js.map +0 -1
- package/dist/wire.js.map +0 -1
package/dist/client.js
CHANGED
|
@@ -1,227 +1,165 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { observed } from './observation.js';
|
|
2
|
+
import { answer, AUTHORIZATION_ENDED, carried, envelope, PORT_CLOSED, PROTOCOL_MISMATCH, } from './wire.js';
|
|
2
3
|
export function connectMdRuntime(port) {
|
|
3
4
|
let sequence = 0;
|
|
4
5
|
let refusal = null;
|
|
5
|
-
let ended =
|
|
6
|
+
let ended = null;
|
|
6
7
|
const calls = new Map();
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const send = (message)=>{
|
|
8
|
+
const opening = new Map();
|
|
9
|
+
const observations = new Map();
|
|
10
|
+
const send = (message) => {
|
|
10
11
|
port.postMessage(envelope(message));
|
|
11
12
|
};
|
|
13
|
+
function begin(id, topic, first) {
|
|
14
|
+
const handle = observed(first, () => {
|
|
15
|
+
observations.delete(id);
|
|
16
|
+
if (refusal === null)
|
|
17
|
+
send({ kind: 'stop', id });
|
|
18
|
+
}, topic === 'query');
|
|
19
|
+
observations.set(id, { topic, handle });
|
|
20
|
+
return handle.observation;
|
|
21
|
+
}
|
|
12
22
|
function refuse(reported) {
|
|
13
23
|
refusal = reported;
|
|
14
|
-
for (const
|
|
15
|
-
|
|
24
|
+
for (const { topic, handle } of observations.values()) {
|
|
25
|
+
if (topic === 'connection-refusal')
|
|
26
|
+
handle.receive(reported);
|
|
27
|
+
}
|
|
16
28
|
const failure = new Error(reported.reason);
|
|
17
|
-
for (const waiting of
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
29
|
+
for (const [id, waiting] of opening) {
|
|
30
|
+
if (waiting.topic === 'connection-refusal')
|
|
31
|
+
waiting.settle(begin(id, waiting.topic, reported));
|
|
32
|
+
else
|
|
33
|
+
waiting.fail(failure);
|
|
21
34
|
}
|
|
35
|
+
opening.clear();
|
|
36
|
+
for (const waiting of calls.values())
|
|
37
|
+
waiting.fail(failure);
|
|
38
|
+
calls.clear();
|
|
22
39
|
}
|
|
23
|
-
function end() {
|
|
24
|
-
ended
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
for (const waiting of
|
|
40
|
+
function end(reason) {
|
|
41
|
+
if (ended !== null)
|
|
42
|
+
return;
|
|
43
|
+
ended = reason;
|
|
44
|
+
const failure = new Error(reason);
|
|
45
|
+
for (const waiting of opening.values())
|
|
46
|
+
waiting.fail(failure);
|
|
47
|
+
opening.clear();
|
|
48
|
+
for (const waiting of calls.values())
|
|
49
|
+
waiting.fail(failure);
|
|
29
50
|
calls.clear();
|
|
30
|
-
|
|
51
|
+
for (const { handle } of observations.values())
|
|
52
|
+
handle.end();
|
|
53
|
+
observations.clear();
|
|
31
54
|
}
|
|
32
|
-
port.addEventListener('message', (event)=>{
|
|
55
|
+
port.addEventListener('message', (event) => {
|
|
33
56
|
const wire = carried(event.data);
|
|
34
|
-
if (wire === null)
|
|
57
|
+
if (wire === null)
|
|
58
|
+
return;
|
|
35
59
|
if (!wire.matching) {
|
|
36
60
|
refuse(PROTOCOL_MISMATCH);
|
|
37
61
|
return;
|
|
38
62
|
}
|
|
39
63
|
const message = answer(wire.message);
|
|
40
|
-
if (message === null)
|
|
64
|
+
if (message === null)
|
|
65
|
+
return;
|
|
41
66
|
if (message.kind === 'refusal') {
|
|
42
67
|
refuse(message.refusal);
|
|
43
68
|
return;
|
|
44
69
|
}
|
|
45
70
|
if (message.kind === 'ended') {
|
|
46
|
-
end();
|
|
71
|
+
end(AUTHORIZATION_ENDED);
|
|
47
72
|
return;
|
|
48
73
|
}
|
|
49
74
|
if (message.kind === 'event') {
|
|
50
|
-
|
|
75
|
+
observations.get(message.id)?.handle.receive(message.value);
|
|
51
76
|
return;
|
|
52
77
|
}
|
|
53
|
-
const
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
if (message.kind === 'failure')
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
78
|
+
const waiting = opening.get(message.id);
|
|
79
|
+
if (waiting !== undefined) {
|
|
80
|
+
opening.delete(message.id);
|
|
81
|
+
if (message.kind === 'failure')
|
|
82
|
+
waiting.fail(new Error(message.message));
|
|
83
|
+
else
|
|
84
|
+
waiting.settle(begin(message.id, waiting.topic, message.value));
|
|
60
85
|
return;
|
|
61
86
|
}
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
87
|
+
const called = calls.get(message.id);
|
|
88
|
+
if (called === undefined)
|
|
89
|
+
return;
|
|
64
90
|
calls.delete(message.id);
|
|
65
|
-
if (message.kind === 'failure')
|
|
66
|
-
|
|
91
|
+
if (message.kind === 'failure')
|
|
92
|
+
called.fail(new Error(message.message));
|
|
93
|
+
else
|
|
94
|
+
called.settle(message.value);
|
|
67
95
|
});
|
|
68
|
-
port.
|
|
69
|
-
|
|
70
|
-
kind: 'hello'
|
|
96
|
+
port.addEventListener('close', () => {
|
|
97
|
+
end(PORT_CLOSED);
|
|
71
98
|
});
|
|
99
|
+
port.start();
|
|
100
|
+
send({ kind: 'hello' });
|
|
72
101
|
function ask(member, input) {
|
|
73
|
-
if (ended
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
});
|
|
81
|
-
send({
|
|
82
|
-
kind: 'call',
|
|
83
|
-
id,
|
|
84
|
-
member,
|
|
85
|
-
input
|
|
86
|
-
});
|
|
102
|
+
if (ended !== null)
|
|
103
|
+
return Promise.reject(new Error(ended));
|
|
104
|
+
if (refusal !== null)
|
|
105
|
+
return Promise.reject(new Error(refusal.reason));
|
|
106
|
+
const id = (sequence += 1);
|
|
107
|
+
return new Promise((settle, fail) => {
|
|
108
|
+
calls.set(id, { settle: settle, fail });
|
|
109
|
+
send({ kind: 'call', id, member, input });
|
|
87
110
|
});
|
|
88
111
|
}
|
|
89
|
-
function watch(topic, input
|
|
90
|
-
if (ended
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
topic,
|
|
94
|
-
notify
|
|
95
|
-
});
|
|
96
|
-
const end = ()=>{
|
|
97
|
-
if (!listeners.delete(id)) return;
|
|
98
|
-
if (refusal === null) send({
|
|
99
|
-
kind: 'stop',
|
|
100
|
-
id
|
|
101
|
-
});
|
|
102
|
-
};
|
|
112
|
+
function watch(topic, input) {
|
|
113
|
+
if (ended !== null)
|
|
114
|
+
return Promise.reject(new Error(ended));
|
|
115
|
+
const id = (sequence += 1);
|
|
103
116
|
if (refusal !== null) {
|
|
104
|
-
|
|
105
|
-
|
|
117
|
+
return topic === 'connection-refusal'
|
|
118
|
+
? Promise.resolve(begin(id, topic, refusal))
|
|
119
|
+
: Promise.reject(new Error(refusal.reason));
|
|
106
120
|
}
|
|
107
|
-
return new Promise((settle, fail)=>{
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
fail
|
|
111
|
-
});
|
|
112
|
-
send({
|
|
113
|
-
kind: 'observe',
|
|
114
|
-
id,
|
|
115
|
-
topic,
|
|
116
|
-
input
|
|
117
|
-
});
|
|
121
|
+
return new Promise((settle, fail) => {
|
|
122
|
+
opening.set(id, { topic, settle, fail });
|
|
123
|
+
send({ kind: 'observe', id, topic, input });
|
|
118
124
|
});
|
|
119
125
|
}
|
|
120
126
|
return {
|
|
121
|
-
rooms: ()=>ask('rooms', []),
|
|
122
|
-
query: (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
]),
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
list: ()=>ask('draft.list', []),
|
|
131
|
-
read: (locator, path)=>ask('draft.read', [
|
|
132
|
-
locator,
|
|
133
|
-
path
|
|
134
|
-
]),
|
|
135
|
-
replace: (locator, path, content)=>ask('draft.replace', [
|
|
136
|
-
locator,
|
|
137
|
-
path,
|
|
138
|
-
content
|
|
139
|
-
]),
|
|
140
|
-
discard: (locator, path)=>ask('draft.discard', [
|
|
141
|
-
locator,
|
|
142
|
-
path
|
|
143
|
-
])
|
|
144
|
-
},
|
|
145
|
-
save: (locator, changes, replacing)=>ask('save', [
|
|
146
|
-
locator,
|
|
147
|
-
changes,
|
|
148
|
-
replacing
|
|
149
|
-
]),
|
|
150
|
-
outcome: (identifier)=>ask('outcome', [
|
|
151
|
-
identifier
|
|
152
|
-
]),
|
|
153
|
-
queue: {
|
|
154
|
-
discard: (locator, identifier)=>ask('queue.discard', [
|
|
155
|
-
locator,
|
|
156
|
-
identifier
|
|
157
|
-
])
|
|
127
|
+
rooms: () => ask('rooms', []),
|
|
128
|
+
query: ((query) => ask('query', [query])),
|
|
129
|
+
search: (request) => ask('search', [request]),
|
|
130
|
+
types: (locator) => ask('types', [locator]),
|
|
131
|
+
roomDraft: {
|
|
132
|
+
list: () => ask('roomDraft.list', []),
|
|
133
|
+
read: (room, path) => ask('roomDraft.read', [room, path]),
|
|
134
|
+
write: (room, path, revision, parts) => ask('roomDraft.write', [room, path, revision, parts]),
|
|
135
|
+
discard: (room, path, revision) => ask('roomDraft.discard', [room, path, revision]),
|
|
158
136
|
},
|
|
137
|
+
save: (room, roomDrafts) => ask('save', [room, roomDrafts]),
|
|
159
138
|
presentation: {
|
|
160
|
-
read: ()=>ask('presentation.read', []),
|
|
161
|
-
write: (value)=>ask('presentation.write', [
|
|
162
|
-
value
|
|
163
|
-
])
|
|
139
|
+
read: () => ask('presentation.read', []),
|
|
140
|
+
write: (value) => ask('presentation.write', [value]),
|
|
164
141
|
},
|
|
165
142
|
conversation: {
|
|
166
|
-
list: ()=>ask('conversation.list', []),
|
|
167
|
-
read: (conversation)=>ask('conversation.read', [
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
instruction
|
|
176
|
-
]),
|
|
177
|
-
discard: (conversation)=>ask('conversation.discard', [
|
|
178
|
-
conversation
|
|
179
|
-
]),
|
|
180
|
-
create: (input)=>ask('conversation.create', [
|
|
181
|
-
input
|
|
182
|
-
]),
|
|
183
|
-
send: (conversation)=>ask('conversation.send', [
|
|
184
|
-
conversation
|
|
185
|
-
]),
|
|
186
|
-
answer: (conversation, answer)=>ask('conversation.answer', [
|
|
187
|
-
conversation,
|
|
188
|
-
answer
|
|
189
|
-
]),
|
|
190
|
-
interrupt: (conversation)=>ask('conversation.interrupt', [
|
|
191
|
-
conversation
|
|
192
|
-
]),
|
|
193
|
-
kill: (conversation)=>ask('conversation.kill', [
|
|
194
|
-
conversation
|
|
195
|
-
]),
|
|
196
|
-
cancel: (conversation, turn)=>ask('conversation.cancel', [
|
|
197
|
-
conversation,
|
|
198
|
-
turn
|
|
199
|
-
]),
|
|
200
|
-
delete: (conversation)=>ask('conversation.delete', [
|
|
201
|
-
conversation
|
|
202
|
-
])
|
|
143
|
+
list: () => ask('conversation.list', []),
|
|
144
|
+
read: (conversation, options) => ask('conversation.read', [conversation, options]),
|
|
145
|
+
create: (input) => ask('conversation.create', [input]),
|
|
146
|
+
send: (conversation) => ask('conversation.send', [conversation]),
|
|
147
|
+
answer: (conversation, answer) => ask('conversation.answer', [conversation, answer]),
|
|
148
|
+
interrupt: (conversation) => ask('conversation.interrupt', [conversation]),
|
|
149
|
+
kill: (conversation) => ask('conversation.kill', [conversation]),
|
|
150
|
+
cancel: (conversation, turn) => ask('conversation.cancel', [conversation, turn]),
|
|
151
|
+
delete: (conversation) => ask('conversation.delete', [conversation]),
|
|
203
152
|
},
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
query
|
|
208
|
-
]),
|
|
209
|
-
call: (name, input)=>ask('call', [
|
|
210
|
-
name,
|
|
211
|
-
input
|
|
212
|
-
]),
|
|
213
|
-
log: ()=>ask('log', []),
|
|
214
|
-
storageLoss: ()=>ask('storageLoss', []),
|
|
215
|
-
persistence: ()=>ask('persistence', []),
|
|
216
|
-
observe (topic, second, third) {
|
|
217
|
-
const positional = topic === 'query' || topic === 'queue' || topic === 'conversation';
|
|
218
|
-
const notify = positional ? third : second;
|
|
219
|
-
return watch(topic, positional ? [
|
|
220
|
-
second
|
|
221
|
-
] : [], notify);
|
|
153
|
+
chatDraft: {
|
|
154
|
+
write: (conversation, draft) => ask('chatDraft.write', [conversation, draft]),
|
|
155
|
+
discard: (conversation) => ask('chatDraft.discard', [conversation]),
|
|
222
156
|
},
|
|
223
|
-
|
|
157
|
+
history: (locator, path, query) => ask('history', [locator, path, query]),
|
|
158
|
+
call: (name, input) => ask('call', [name, input]),
|
|
159
|
+
reached: (locator, roomVersion, path) => ask('reached', [locator, roomVersion, path]),
|
|
160
|
+
log: () => ask('log', []),
|
|
161
|
+
persistence: () => ask('persistence', []),
|
|
162
|
+
observe: ((topic, ...input) => watch(topic, input)),
|
|
163
|
+
reauthorize: () => ask('reauthorize', []),
|
|
224
164
|
};
|
|
225
165
|
}
|
|
226
|
-
|
|
227
|
-
//# sourceMappingURL=client.js.map
|
package/dist/collection.d.ts
CHANGED
|
@@ -1,21 +1,13 @@
|
|
|
1
1
|
import { type Document, type Validation } from '@agentshouse/mdmodel';
|
|
2
|
-
import type {
|
|
3
|
-
import type { AttachedModelBinding, ModelState } from './model.js';
|
|
2
|
+
import type { ModelState } from './model.js';
|
|
4
3
|
import type { MdModelIdentity } from './adapter.js';
|
|
4
|
+
import type { Refused } from './transfer.js';
|
|
5
5
|
export declare const MD_MODEL: MdModelIdentity;
|
|
6
|
-
export declare const PRESENTED: Selector;
|
|
7
|
-
export type MdType = {
|
|
8
|
-
name: string;
|
|
9
|
-
path: string;
|
|
10
|
-
fields: Readonly<Record<string, unknown>>;
|
|
11
|
-
sections: Readonly<Record<string, unknown>>;
|
|
12
|
-
};
|
|
13
6
|
export type Collection = {
|
|
14
7
|
documents: Readonly<Record<string, Document>>;
|
|
15
8
|
composition: Composition;
|
|
16
9
|
};
|
|
17
10
|
export type Composition = {
|
|
18
|
-
collectionRoot: string;
|
|
19
11
|
model: ModelState;
|
|
20
12
|
selection: {
|
|
21
13
|
roots: readonly string[];
|
|
@@ -23,11 +15,16 @@ export type Composition = {
|
|
|
23
15
|
} | null;
|
|
24
16
|
};
|
|
25
17
|
export declare function governing(composition: Composition, path: string): ModelState;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
export declare function validRoot(root: unknown): root is string;
|
|
30
|
-
export declare function validateCollection(text: Readonly<Record<string, string>>, binaryTargets: readonly string[], composition: Composition, binding: AttachedModelBinding | null): Validation & {
|
|
31
|
-
source?: 'content' | 'model';
|
|
18
|
+
type Previous = {
|
|
19
|
+
text: Readonly<Record<string, string>>;
|
|
20
|
+
collection: Collection;
|
|
32
21
|
};
|
|
22
|
+
export declare function parseCollection(text: Readonly<Record<string, string>>, composition: Composition, previous?: Previous): Collection;
|
|
23
|
+
export declare function readCollection(text: Readonly<Record<string, string>>, composition: Composition, previous?: Previous): {
|
|
24
|
+
kind: 'read';
|
|
25
|
+
collection: Collection;
|
|
26
|
+
} | Refused;
|
|
27
|
+
export declare function validRoot(root: unknown): root is string;
|
|
28
|
+
export declare function validateCollection(text: Readonly<Record<string, string>>, binaryTargets: readonly string[], composition: Composition): Validation;
|
|
29
|
+
export {};
|
|
33
30
|
//# 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,EAIL,KAAK,QAAQ,EAEb,KAAK,UAAU,EAEhB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,eAAO,MAAM,QAAQ,EAAE,eAAwE,CAAC;AAIhG,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC9C,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,UAAU,CAAC;IAClB,SAAS,EAAE;QAAE,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE,UAAU,CAAA;KAAE,GAAG,IAAI,CAAC;CACnE,CAAC;AASF,wBAAgB,SAAS,CAAC,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAI5E;AAED,KAAK,QAAQ,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,CAAC;AAanF,wBAAgB,eAAe,CAC7B,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,WAAW,EAAE,WAAW,EACxB,QAAQ,CAAC,EAAE,QAAQ,GAClB,UAAU,CAOZ;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,WAAW,EAAE,WAAW,EACxB,QAAQ,CAAC,EAAE,QAAQ,GAClB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,GAAG,OAAO,CAQpD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAEvD;AAwBD,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,aAAa,EAAE,SAAS,MAAM,EAAE,EAChC,WAAW,EAAE,WAAW,GACvB,UAAU,CA0BZ"}
|
package/dist/collection.js
CHANGED
|
@@ -1,115 +1,72 @@
|
|
|
1
|
-
import { parse, validate, VERSION } from '@agentshouse/mdmodel';
|
|
1
|
+
import { parse, validate, VERSION, } from '@agentshouse/mdmodel';
|
|
2
2
|
import { beneath, normalize } from './paths.js';
|
|
3
|
-
export const MD_MODEL = {
|
|
4
|
-
|
|
5
|
-
version: VERSION
|
|
6
|
-
};
|
|
7
|
-
export const PRESENTED = {
|
|
8
|
-
path: {
|
|
9
|
-
$regex: '\\.md$'
|
|
10
|
-
}
|
|
11
|
-
};
|
|
3
|
+
export const MD_MODEL = { identity: '@agentshouse/mdmodel', version: VERSION };
|
|
4
|
+
const NO_TYPES = { types: {} };
|
|
12
5
|
function selected(composition, path) {
|
|
13
|
-
return composition.selection !== null &&
|
|
6
|
+
return (composition.selection !== null &&
|
|
7
|
+
composition.selection.roots.some((root) => beneath(root, path)));
|
|
14
8
|
}
|
|
15
9
|
export function governing(composition, path) {
|
|
16
|
-
return composition.selection !== null && selected(composition, path)
|
|
10
|
+
return composition.selection !== null && selected(composition, path)
|
|
11
|
+
? composition.selection.model
|
|
12
|
+
: composition.model;
|
|
17
13
|
}
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
return
|
|
14
|
+
function parsedAt(text, path, previous) {
|
|
15
|
+
const retained = previous?.collection.documents[path];
|
|
16
|
+
return retained !== undefined && previous?.text[path] === text[path]
|
|
17
|
+
? { ok: true, document: retained }
|
|
18
|
+
: parse(text[path], path);
|
|
21
19
|
}
|
|
22
|
-
export function parseCollection(text, composition) {
|
|
20
|
+
export function parseCollection(text, composition, previous) {
|
|
23
21
|
const documents = {};
|
|
24
|
-
for (const path of Object.keys(text).sort()){
|
|
25
|
-
const parsed =
|
|
26
|
-
if (parsed.ok)
|
|
22
|
+
for (const path of Object.keys(text).sort()) {
|
|
23
|
+
const parsed = parsedAt(text, path, previous);
|
|
24
|
+
if (parsed.ok)
|
|
25
|
+
documents[path] = parsed.document;
|
|
27
26
|
}
|
|
28
|
-
return {
|
|
29
|
-
documents,
|
|
30
|
-
composition
|
|
31
|
-
};
|
|
27
|
+
return { documents, composition };
|
|
32
28
|
}
|
|
33
|
-
export function readCollection(text, composition) {
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
export function readCollection(text, composition, previous) {
|
|
30
|
+
const documents = {};
|
|
31
|
+
for (const path of Object.keys(text).sort()) {
|
|
32
|
+
const parsed = parsedAt(text, path, previous);
|
|
33
|
+
if (!parsed.ok)
|
|
34
|
+
return { kind: 'refused', refusal: parsed.refusal };
|
|
35
|
+
documents[path] = parsed.document;
|
|
36
|
+
}
|
|
37
|
+
return { kind: 'read', collection: { documents, composition } };
|
|
39
38
|
}
|
|
40
39
|
export function validRoot(root) {
|
|
41
40
|
return typeof root === 'string' && normalize(root) === root;
|
|
42
41
|
}
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
function validateAgainst(documents, binaryTargets, prefix, model, binding) {
|
|
47
|
-
if (model.status === 'unavailable' || binding === null) {
|
|
48
|
-
const typed = Object.entries(documents).find(([, content])=>{
|
|
42
|
+
function validateAgainst(documents, binaryTargets, model) {
|
|
43
|
+
if (model.status === 'unavailable') {
|
|
44
|
+
const typed = Object.entries(documents).find(([, content]) => {
|
|
49
45
|
const parsed = parse(content);
|
|
50
46
|
return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
|
|
51
47
|
});
|
|
52
|
-
if (typed !== undefined)
|
|
53
|
-
verdict: 'refuse',
|
|
54
|
-
rule: 'model-unavailable',
|
|
55
|
-
file: `${prefix}${typed[0]}`,
|
|
56
|
-
version: VERSION
|
|
57
|
-
};
|
|
58
|
-
return validate(documents, {
|
|
59
|
-
binaryTargets
|
|
60
|
-
});
|
|
48
|
+
if (typed !== undefined)
|
|
49
|
+
return { verdict: 'refuse', rule: 'model-unavailable', file: typed[0] };
|
|
61
50
|
}
|
|
62
|
-
|
|
63
|
-
model: model.snapshot,
|
|
64
|
-
documents,
|
|
65
|
-
binaryTargets
|
|
66
|
-
});
|
|
67
|
-
if (verdict.verdict === 'refuse' && verdict.source === 'model') return verdict;
|
|
68
|
-
if (verdict.verdict === 'accept') return verdict;
|
|
69
|
-
return {
|
|
70
|
-
...verdict,
|
|
71
|
-
file: `${prefix}${verdict.file}`,
|
|
72
|
-
...verdict.referrers === undefined ? {} : {
|
|
73
|
-
referrers: verdict.referrers.map((path)=>`${prefix}${path}`)
|
|
74
|
-
}
|
|
75
|
-
};
|
|
51
|
+
return validate(documents, { binaryTargets }, model.status === 'unavailable' ? NO_TYPES : { types: model.types });
|
|
76
52
|
}
|
|
77
|
-
export function validateCollection(text, binaryTargets, composition
|
|
78
|
-
const prefix = composition.collectionRoot === '' ? '' : `${composition.collectionRoot}/`;
|
|
53
|
+
export function validateCollection(text, binaryTargets, composition) {
|
|
79
54
|
const collection = {};
|
|
80
55
|
const selection = {};
|
|
81
|
-
for (const [path, content] of Object.entries(text)){
|
|
82
|
-
if (
|
|
83
|
-
collection[path.slice(prefix.length)] = content;
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
if (selected(composition, path)) {
|
|
56
|
+
for (const [path, content] of Object.entries(text)) {
|
|
57
|
+
if (selected(composition, path))
|
|
87
58
|
selection[path] = content;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const parsed = parse(content, path);
|
|
91
|
-
if (!parsed.ok) return {
|
|
92
|
-
verdict: 'refuse',
|
|
93
|
-
...parsed.refusal
|
|
94
|
-
};
|
|
95
|
-
if (Object.hasOwn(parsed.document.fields, 'type') && parsed.document.fields.type !== 'any') {
|
|
96
|
-
return {
|
|
97
|
-
verdict: 'refuse',
|
|
98
|
-
rule: 'outside-collection-type',
|
|
99
|
-
file: path,
|
|
100
|
-
version: VERSION
|
|
101
|
-
};
|
|
102
|
-
}
|
|
59
|
+
else
|
|
60
|
+
collection[path] = content;
|
|
103
61
|
}
|
|
104
62
|
const verdicts = [
|
|
105
|
-
validateAgainst(collection, binaryTargets.filter((path)=>
|
|
63
|
+
validateAgainst(collection, binaryTargets.filter((path) => !selected(composition, path)), composition.model),
|
|
106
64
|
];
|
|
107
65
|
if (composition.selection !== null) {
|
|
108
|
-
verdicts.push(validateAgainst(selection, binaryTargets.filter((path)=>selected(composition, path)),
|
|
66
|
+
verdicts.push(validateAgainst(selection, binaryTargets.filter((path) => selected(composition, path)), composition.selection.model));
|
|
109
67
|
}
|
|
110
|
-
const refusals = verdicts.filter((verdict)=>verdict.verdict === 'refuse');
|
|
111
|
-
if (refusals.length === 0)
|
|
112
|
-
|
|
68
|
+
const refusals = verdicts.filter((verdict) => verdict.verdict === 'refuse');
|
|
69
|
+
if (refusals.length === 0)
|
|
70
|
+
return verdicts[0];
|
|
71
|
+
return refusals.find((refusal) => refusal.rule !== 'model-unavailable') ?? refusals[0];
|
|
113
72
|
}
|
|
114
|
-
|
|
115
|
-
//# sourceMappingURL=collection.js.map
|