@agentshouse/mdruntime 0.1.0-alpha.9 → 0.1.0-c436a939f2119
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 +210 -0
- package/README.md +44 -0
- package/dist/adapter.d.ts +155 -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 +29 -27
- package/dist/change-set.d.ts +33 -0
- package/dist/change-set.d.ts.map +1 -0
- package/dist/change-set.js +87 -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 +40 -28
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +121 -177
- package/dist/collection.d.ts +15 -16
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +54 -87
- package/dist/connection.d.ts +57 -35
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1475 -964
- 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 +7 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +100 -102
- 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 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- 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 +206 -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 +17 -20
- 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 +232 -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 +265 -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 +68 -30
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +360 -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 +50 -65
- 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,171 @@
|
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
types: (locator)=>ask('types', [
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
+
slots: () => ask('slots', []),
|
|
129
|
+
query: ((query) => ask('query', [query])),
|
|
130
|
+
search: (request) => ask('search', [request]),
|
|
131
|
+
types: (locator) => ask('types', [locator]),
|
|
132
|
+
syncStatus: () => ask('syncStatus', []),
|
|
133
|
+
serviceMode: () => ask('serviceMode', []),
|
|
134
|
+
roomDraft: {
|
|
135
|
+
list: () => ask('roomDraft.list', []),
|
|
136
|
+
read: (room, path) => ask('roomDraft.read', [room, path]),
|
|
137
|
+
write: (room, path, revision, parts) => ask('roomDraft.write', [room, path, revision, parts]),
|
|
138
|
+
discard: (room, path, revision) => ask('roomDraft.discard', [room, path, revision]),
|
|
158
139
|
},
|
|
140
|
+
save: (room, roomDrafts) => ask('save', [room, roomDrafts]),
|
|
141
|
+
outcome: (identifier) => ask('outcome', [identifier]),
|
|
159
142
|
presentation: {
|
|
160
|
-
read: ()=>ask('presentation.read', []),
|
|
161
|
-
write: (value)=>ask('presentation.write', [
|
|
162
|
-
value
|
|
163
|
-
])
|
|
143
|
+
read: () => ask('presentation.read', []),
|
|
144
|
+
write: (value) => ask('presentation.write', [value]),
|
|
164
145
|
},
|
|
165
146
|
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
|
-
])
|
|
147
|
+
list: () => ask('conversation.list', []),
|
|
148
|
+
read: (conversation, options) => ask('conversation.read', [conversation, options]),
|
|
149
|
+
create: (input) => ask('conversation.create', [input]),
|
|
150
|
+
send: (conversation) => ask('conversation.send', [conversation]),
|
|
151
|
+
answer: (conversation, answer) => ask('conversation.answer', [conversation, answer]),
|
|
152
|
+
interrupt: (conversation) => ask('conversation.interrupt', [conversation]),
|
|
153
|
+
kill: (conversation) => ask('conversation.kill', [conversation]),
|
|
154
|
+
cancel: (conversation, turn) => ask('conversation.cancel', [conversation, turn]),
|
|
155
|
+
delete: (conversation) => ask('conversation.delete', [conversation]),
|
|
203
156
|
},
|
|
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);
|
|
157
|
+
chatDraft: {
|
|
158
|
+
write: (conversation, draft) => ask('chatDraft.write', [conversation, draft]),
|
|
159
|
+
discard: (conversation) => ask('chatDraft.discard', [conversation]),
|
|
222
160
|
},
|
|
223
|
-
|
|
161
|
+
history: (locator, path, query) => ask('history', [locator, path, query]),
|
|
162
|
+
call: (name, input) => ask('call', [name, input]),
|
|
163
|
+
reached: (locator, roomVersion, path) => ask('reached', [locator, roomVersion, path]),
|
|
164
|
+
log: () => ask('log', []),
|
|
165
|
+
storageLoss: () => ask('storageLoss', []),
|
|
166
|
+
persistence: () => ask('persistence', []),
|
|
167
|
+
deploymentFacts: () => ask('deploymentFacts', []),
|
|
168
|
+
observe: ((topic, ...input) => watch(topic, input)),
|
|
169
|
+
reauthorize: () => ask('reauthorize', []),
|
|
224
170
|
};
|
|
225
171
|
}
|
|
226
|
-
|
|
227
|
-
//# sourceMappingURL=client.js.map
|
package/dist/collection.d.ts
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
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[];
|
|
22
14
|
model: ModelState;
|
|
23
15
|
} | null;
|
|
16
|
+
untypedFolders: readonly string[];
|
|
24
17
|
};
|
|
18
|
+
export declare function untyped(roots: readonly string[], path: string): boolean;
|
|
25
19
|
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';
|
|
20
|
+
type Previous = {
|
|
21
|
+
text: Readonly<Record<string, string>>;
|
|
22
|
+
collection: Collection;
|
|
32
23
|
};
|
|
24
|
+
export declare function parseCollection(text: Readonly<Record<string, string>>, composition: Composition, previous?: Previous): Collection;
|
|
25
|
+
export declare function readCollection(text: Readonly<Record<string, string>>, composition: Composition, previous?: Previous): {
|
|
26
|
+
kind: 'read';
|
|
27
|
+
collection: Collection;
|
|
28
|
+
} | Refused;
|
|
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): Validation;
|
|
31
|
+
export {};
|
|
33
32
|
//# 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;IAClE,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC,CAAC;AASF,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAEvE;AAED,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,CAQZ;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,CASpD;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,CA4BZ"}
|
package/dist/collection.js
CHANGED
|
@@ -1,115 +1,82 @@
|
|
|
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)));
|
|
8
|
+
}
|
|
9
|
+
export function untyped(roots, path) {
|
|
10
|
+
return roots.some((root) => beneath(root, path));
|
|
14
11
|
}
|
|
15
12
|
export function governing(composition, path) {
|
|
16
|
-
return composition.selection !== null && selected(composition, path)
|
|
13
|
+
return composition.selection !== null && selected(composition, path)
|
|
14
|
+
? composition.selection.model
|
|
15
|
+
: composition.model;
|
|
17
16
|
}
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
return
|
|
17
|
+
function parsedAt(text, path, previous) {
|
|
18
|
+
const retained = previous?.collection.documents[path];
|
|
19
|
+
return retained !== undefined && previous?.text[path] === text[path]
|
|
20
|
+
? { ok: true, document: retained }
|
|
21
|
+
: parse(text[path], path);
|
|
21
22
|
}
|
|
22
|
-
export function parseCollection(text, composition) {
|
|
23
|
+
export function parseCollection(text, composition, previous) {
|
|
23
24
|
const documents = {};
|
|
24
|
-
for (const path of Object.keys(text).sort()){
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
for (const path of Object.keys(text).sort()) {
|
|
26
|
+
if (untyped(composition.untypedFolders, path))
|
|
27
|
+
continue;
|
|
28
|
+
const parsed = parsedAt(text, path, previous);
|
|
29
|
+
if (parsed.ok)
|
|
30
|
+
documents[path] = parsed.document;
|
|
27
31
|
}
|
|
28
|
-
return {
|
|
29
|
-
documents,
|
|
30
|
-
composition
|
|
31
|
-
};
|
|
32
|
+
return { documents, composition };
|
|
32
33
|
}
|
|
33
|
-
export function readCollection(text, composition) {
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
export function readCollection(text, composition, previous) {
|
|
35
|
+
const documents = {};
|
|
36
|
+
for (const path of Object.keys(text).sort()) {
|
|
37
|
+
if (untyped(composition.untypedFolders, path))
|
|
38
|
+
continue;
|
|
39
|
+
const parsed = parsedAt(text, path, previous);
|
|
40
|
+
if (!parsed.ok)
|
|
41
|
+
return { kind: 'refused', refusal: parsed.refusal };
|
|
42
|
+
documents[path] = parsed.document;
|
|
43
|
+
}
|
|
44
|
+
return { kind: 'read', collection: { documents, composition } };
|
|
39
45
|
}
|
|
40
46
|
export function validRoot(root) {
|
|
41
47
|
return typeof root === 'string' && normalize(root) === root;
|
|
42
48
|
}
|
|
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])=>{
|
|
49
|
+
function validateAgainst(documents, binaryTargets, model) {
|
|
50
|
+
if (model.status === 'unavailable') {
|
|
51
|
+
const typed = Object.entries(documents).find(([, content]) => {
|
|
49
52
|
const parsed = parse(content);
|
|
50
53
|
return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
|
|
51
54
|
});
|
|
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
|
-
});
|
|
55
|
+
if (typed !== undefined)
|
|
56
|
+
return { verdict: 'refuse', rule: 'model-unavailable', file: typed[0] };
|
|
61
57
|
}
|
|
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
|
-
};
|
|
58
|
+
return validate(documents, { binaryTargets }, model.status === 'unavailable' ? NO_TYPES : { types: model.types });
|
|
76
59
|
}
|
|
77
|
-
export function validateCollection(text, binaryTargets, composition
|
|
78
|
-
const prefix = composition.collectionRoot === '' ? '' : `${composition.collectionRoot}/`;
|
|
60
|
+
export function validateCollection(text, binaryTargets, composition) {
|
|
79
61
|
const collection = {};
|
|
80
62
|
const selection = {};
|
|
81
|
-
for (const [path, content] of Object.entries(text)){
|
|
82
|
-
if (
|
|
83
|
-
collection[path.slice(prefix.length)] = content;
|
|
63
|
+
for (const [path, content] of Object.entries(text)) {
|
|
64
|
+
if (untyped(composition.untypedFolders, path))
|
|
84
65
|
continue;
|
|
85
|
-
|
|
86
|
-
if (selected(composition, path)) {
|
|
66
|
+
if (selected(composition, path))
|
|
87
67
|
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
|
-
}
|
|
68
|
+
else
|
|
69
|
+
collection[path] = content;
|
|
103
70
|
}
|
|
71
|
+
const linked = binaryTargets.filter((path) => !untyped(composition.untypedFolders, path));
|
|
104
72
|
const verdicts = [
|
|
105
|
-
validateAgainst(collection,
|
|
73
|
+
validateAgainst(collection, linked.filter((path) => !selected(composition, path)), composition.model),
|
|
106
74
|
];
|
|
107
75
|
if (composition.selection !== null) {
|
|
108
|
-
verdicts.push(validateAgainst(selection,
|
|
76
|
+
verdicts.push(validateAgainst(selection, linked.filter((path) => selected(composition, path)), composition.selection.model));
|
|
109
77
|
}
|
|
110
|
-
const refusals = verdicts.filter((verdict)=>verdict.verdict === 'refuse');
|
|
111
|
-
if (refusals.length === 0)
|
|
112
|
-
|
|
78
|
+
const refusals = verdicts.filter((verdict) => verdict.verdict === 'refuse');
|
|
79
|
+
if (refusals.length === 0)
|
|
80
|
+
return verdicts[0];
|
|
81
|
+
return refusals.find((refusal) => refusal.rule !== 'model-unavailable') ?? refusals[0];
|
|
113
82
|
}
|
|
114
|
-
|
|
115
|
-
//# sourceMappingURL=collection.js.map
|