@agentshouse/mdruntime 0.1.0-alpha.9 → 0.1.0-c0105dbd22806
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 +299 -0
- package/README.md +54 -0
- package/dist/adapter.d.ts +246 -40
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +1 -10
- package/dist/attached-model.d.ts +11 -0
- package/dist/attached-model.d.ts.map +1 -0
- package/dist/attached-model.js +47 -0
- package/dist/attempt.d.ts +16 -0
- package/dist/attempt.d.ts.map +1 -0
- package/dist/attempt.js +70 -0
- package/dist/binary.d.ts +23 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +8 -0
- package/dist/bootstrap.d.ts +17 -7
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +97 -41
- package/dist/change-set.d.ts +33 -0
- package/dist/change-set.d.ts.map +1 -0
- package/dist/change-set.js +90 -0
- package/dist/change.d.ts +24 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +31 -5
- package/dist/chat/acts.d.ts +34 -0
- package/dist/chat/acts.d.ts.map +1 -0
- package/dist/chat/acts.js +36 -0
- package/dist/chat/context.d.ts +3 -0
- package/dist/chat/context.d.ts.map +1 -0
- package/dist/chat/context.js +10 -0
- package/dist/chat/input.d.ts +9 -0
- package/dist/chat/input.d.ts.map +1 -0
- package/dist/chat/input.js +99 -0
- package/dist/chat/kit.d.ts +60 -0
- package/dist/chat/kit.d.ts.map +1 -0
- package/dist/chat/kit.js +123 -0
- package/dist/chat/lasting.d.ts +6 -0
- package/dist/chat/lasting.d.ts.map +1 -0
- package/dist/chat/lasting.js +19 -0
- package/dist/chat/list.d.ts +26 -0
- package/dist/chat/list.d.ts.map +1 -0
- package/dist/chat/list.js +62 -0
- package/dist/chat/markdown.d.ts +20 -0
- package/dist/chat/markdown.d.ts.map +1 -0
- package/dist/chat/markdown.js +188 -0
- package/dist/chat/message.d.ts +6 -0
- package/dist/chat/message.d.ts.map +1 -0
- package/dist/chat/message.js +192 -0
- package/dist/chat/messages.d.ts +21 -0
- package/dist/chat/messages.d.ts.map +1 -0
- package/dist/chat/messages.js +151 -0
- package/dist/chat/name.d.ts +6 -0
- package/dist/chat/name.d.ts.map +1 -0
- package/dist/chat/name.js +37 -0
- package/dist/chat/opened.d.ts +11 -0
- package/dist/chat/opened.d.ts.map +1 -0
- package/dist/chat/opened.js +17 -0
- package/dist/chat/overlay.d.ts +31 -0
- package/dist/chat/overlay.d.ts.map +1 -0
- package/dist/chat/overlay.js +97 -0
- package/dist/chat/parts.d.ts +57 -0
- package/dist/chat/parts.d.ts.map +1 -0
- package/dist/chat/parts.js +119 -0
- package/dist/chat/process.d.ts +20 -0
- package/dist/chat/process.d.ts.map +1 -0
- package/dist/chat/process.js +32 -0
- package/dist/chat/provider.d.ts +63 -0
- package/dist/chat/provider.d.ts.map +1 -0
- package/dist/chat/provider.js +645 -0
- package/dist/chat/question.d.ts +9 -0
- package/dist/chat/question.d.ts.map +1 -0
- package/dist/chat/question.js +80 -0
- package/dist/chat/questions.d.ts +31 -0
- package/dist/chat/questions.d.ts.map +1 -0
- package/dist/chat/questions.js +111 -0
- package/dist/chat/read.d.ts +5 -0
- package/dist/chat/read.d.ts.map +1 -0
- package/dist/chat/read.js +13 -0
- package/dist/chat/ready.d.ts +33 -0
- package/dist/chat/ready.d.ts.map +1 -0
- package/dist/chat/ready.js +91 -0
- package/dist/chat/style.d.ts +4 -0
- package/dist/chat/style.d.ts.map +1 -0
- package/dist/chat/style.js +302 -0
- package/dist/chat.d.ts +14 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +8 -0
- package/dist/client.d.ts +49 -33
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +164 -183
- package/dist/collection.d.ts +9 -17
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +83 -89
- package/dist/connection.d.ts +66 -48
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1964 -1173
- package/dist/conversation.d.ts +65 -24
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +675 -334
- package/dist/durability.js +6 -6
- package/dist/entry.d.ts +17 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +156 -0
- package/dist/expectation.d.ts +21 -0
- package/dist/expectation.d.ts.map +1 -0
- package/dist/expectation.js +70 -0
- package/dist/failure.d.ts +13 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +19 -0
- package/dist/fence.d.ts +6 -0
- package/dist/fence.d.ts.map +1 -0
- package/dist/fence.js +10 -0
- 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 +15 -3
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +109 -127
- package/dist/identity.d.ts +4 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +22 -9
- package/dist/index.d.ts +17 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/log.js +5 -6
- package/dist/memory.d.ts +19 -8
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +304 -216
- package/dist/model.d.ts +16 -30
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +21 -21
- package/dist/observation.d.ts +27 -0
- package/dist/observation.d.ts.map +1 -0
- package/dist/observation.js +95 -0
- package/dist/open.d.ts +2 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +1 -0
- package/dist/outcome.d.ts +37 -31
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +36 -18
- package/dist/overlay.d.ts +22 -4
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +236 -54
- package/dist/paths.d.ts +0 -2
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +6 -29
- package/dist/query.d.ts +219 -10
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +462 -15
- package/dist/reach.d.ts +42 -0
- package/dist/reach.d.ts.map +1 -0
- package/dist/reach.js +294 -0
- package/dist/react.d.ts +41 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +64 -0
- package/dist/read-side.d.ts +18 -0
- package/dist/read-side.d.ts.map +1 -0
- package/dist/read-side.js +440 -0
- package/dist/refresh.d.ts +15 -5
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +64 -41
- package/dist/replica.d.ts +28 -5
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +249 -40
- package/dist/room-draft.d.ts +144 -0
- package/dist/room-draft.d.ts.map +1 -0
- package/dist/room-draft.js +438 -0
- package/dist/rows.d.ts +46 -0
- package/dist/rows.d.ts.map +1 -0
- package/dist/rows.js +145 -0
- package/dist/save.d.ts +33 -5
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +630 -366
- package/dist/search.d.ts +62 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +125 -0
- package/dist/status.d.ts +6 -8
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +8 -20
- package/dist/store.d.ts +89 -34
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +513 -132
- 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 +59 -19
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +88 -105
- package/package.json +34 -16
- 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,208 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { observed } from './observation.js';
|
|
2
|
+
import { runtimeError } from './failure.js';
|
|
3
|
+
import { answer, AUTHORIZATION_ENDED, PORT_CLOSED, } from './wire.js';
|
|
4
|
+
function refused(refusal) {
|
|
5
|
+
return runtimeError(refusal.code, refusal.code, refusal.retryable);
|
|
6
|
+
}
|
|
2
7
|
export function connectMdRuntime(port) {
|
|
3
8
|
let sequence = 0;
|
|
4
9
|
let refusal = null;
|
|
5
|
-
let ended =
|
|
10
|
+
let ended = null;
|
|
6
11
|
const calls = new Map();
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
const opening = new Map();
|
|
13
|
+
const observations = new Map();
|
|
14
|
+
let drawing = null;
|
|
15
|
+
let settling = null;
|
|
16
|
+
const send = (message) => {
|
|
17
|
+
port.postMessage(message);
|
|
11
18
|
};
|
|
19
|
+
function begin(id, topic, first) {
|
|
20
|
+
const handle = observed(first, () => {
|
|
21
|
+
observations.delete(id);
|
|
22
|
+
if (refusal === null)
|
|
23
|
+
send({ kind: 'stop', id });
|
|
24
|
+
}, topic === 'query');
|
|
25
|
+
observations.set(id, { topic, handle });
|
|
26
|
+
return handle.observation;
|
|
27
|
+
}
|
|
12
28
|
function refuse(reported) {
|
|
13
29
|
refusal = reported;
|
|
14
|
-
for (const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
for (const waiting of calls.values())waiting.fail(failure);
|
|
18
|
-
calls.clear();
|
|
19
|
-
for (const listener of listeners.values()){
|
|
20
|
-
if (listener.topic === 'connection-refusal') listener.notify(reported);
|
|
30
|
+
for (const { topic, handle } of observations.values()) {
|
|
31
|
+
if (topic === 'connection-refusal')
|
|
32
|
+
handle.receive(reported);
|
|
21
33
|
}
|
|
34
|
+
const failure = refused(reported);
|
|
35
|
+
for (const [id, waiting] of opening) {
|
|
36
|
+
if (waiting.topic === 'connection-refusal')
|
|
37
|
+
waiting.settle(begin(id, waiting.topic, reported));
|
|
38
|
+
else
|
|
39
|
+
waiting.fail(failure);
|
|
40
|
+
}
|
|
41
|
+
opening.clear();
|
|
42
|
+
for (const waiting of calls.values())
|
|
43
|
+
waiting.fail(failure);
|
|
44
|
+
calls.clear();
|
|
45
|
+
drawing?.();
|
|
22
46
|
}
|
|
23
|
-
function end() {
|
|
24
|
-
ended
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
47
|
+
function end(failure) {
|
|
48
|
+
if (ended !== null)
|
|
49
|
+
return;
|
|
50
|
+
ended = failure;
|
|
51
|
+
for (const waiting of opening.values())
|
|
52
|
+
waiting.fail(failure);
|
|
53
|
+
opening.clear();
|
|
54
|
+
for (const waiting of calls.values())
|
|
55
|
+
waiting.fail(failure);
|
|
29
56
|
calls.clear();
|
|
30
|
-
|
|
57
|
+
for (const { handle } of observations.values())
|
|
58
|
+
handle.end();
|
|
59
|
+
observations.clear();
|
|
60
|
+
drawing?.();
|
|
31
61
|
}
|
|
32
|
-
port.addEventListener('message', (event)=>{
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
if (!wire.matching) {
|
|
36
|
-
refuse(PROTOCOL_MISMATCH);
|
|
62
|
+
port.addEventListener('message', (event) => {
|
|
63
|
+
const message = answer(event.data);
|
|
64
|
+
if (message === null)
|
|
37
65
|
return;
|
|
38
|
-
}
|
|
39
|
-
const message = answer(wire.message);
|
|
40
|
-
if (message === null) return;
|
|
41
66
|
if (message.kind === 'refusal') {
|
|
42
67
|
refuse(message.refusal);
|
|
43
68
|
return;
|
|
44
69
|
}
|
|
45
70
|
if (message.kind === 'ended') {
|
|
46
|
-
|
|
71
|
+
for (const { topic, handle } of observations.values()) {
|
|
72
|
+
if (topic === 'member')
|
|
73
|
+
handle.receive(null);
|
|
74
|
+
}
|
|
75
|
+
end(runtimeError('authorization-ended', AUTHORIZATION_ENDED));
|
|
47
76
|
return;
|
|
48
77
|
}
|
|
49
78
|
if (message.kind === 'event') {
|
|
50
|
-
|
|
79
|
+
observations.get(message.id)?.handle.receive(message.value);
|
|
51
80
|
return;
|
|
52
81
|
}
|
|
53
|
-
const
|
|
54
|
-
if (
|
|
55
|
-
|
|
82
|
+
const waiting = opening.get(message.id);
|
|
83
|
+
if (waiting !== undefined) {
|
|
84
|
+
opening.delete(message.id);
|
|
56
85
|
if (message.kind === 'failure') {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
86
|
+
waiting.fail(runtimeError(message.code, message.message, message.retryable));
|
|
87
|
+
}
|
|
88
|
+
else
|
|
89
|
+
waiting.settle(begin(message.id, waiting.topic, message.value));
|
|
90
|
+
drawing?.();
|
|
60
91
|
return;
|
|
61
92
|
}
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
93
|
+
const called = calls.get(message.id);
|
|
94
|
+
if (called === undefined)
|
|
95
|
+
return;
|
|
64
96
|
calls.delete(message.id);
|
|
65
|
-
if (message.kind === 'failure')
|
|
66
|
-
|
|
97
|
+
if (message.kind === 'failure') {
|
|
98
|
+
called.fail(runtimeError(message.code, message.message, message.retryable));
|
|
99
|
+
}
|
|
100
|
+
else
|
|
101
|
+
called.settle(message.value);
|
|
67
102
|
});
|
|
68
|
-
port.
|
|
69
|
-
|
|
70
|
-
kind: 'hello'
|
|
103
|
+
port.addEventListener('close', () => {
|
|
104
|
+
end(runtimeError('port-closed', PORT_CLOSED));
|
|
71
105
|
});
|
|
106
|
+
port.start();
|
|
107
|
+
send({ kind: 'hello' });
|
|
72
108
|
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
|
-
});
|
|
109
|
+
if (ended !== null)
|
|
110
|
+
return Promise.reject(ended);
|
|
111
|
+
if (refusal !== null)
|
|
112
|
+
return Promise.reject(refused(refusal));
|
|
113
|
+
const id = (sequence += 1);
|
|
114
|
+
return new Promise((settle, fail) => {
|
|
115
|
+
calls.set(id, { settle: settle, fail });
|
|
116
|
+
send({ kind: 'call', id, member, input });
|
|
87
117
|
});
|
|
88
118
|
}
|
|
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
|
-
};
|
|
119
|
+
function watch(topic, input) {
|
|
120
|
+
if (ended !== null)
|
|
121
|
+
return Promise.reject(ended);
|
|
122
|
+
const id = (sequence += 1);
|
|
103
123
|
if (refusal !== null) {
|
|
104
|
-
|
|
105
|
-
|
|
124
|
+
return topic === 'connection-refusal'
|
|
125
|
+
? Promise.resolve(begin(id, topic, refusal))
|
|
126
|
+
: Promise.reject(refused(refusal));
|
|
106
127
|
}
|
|
107
|
-
return new Promise((settle, fail)=>{
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
128
|
+
return new Promise((settle, fail) => {
|
|
129
|
+
opening.set(id, { topic, settle, fail });
|
|
130
|
+
send({ kind: 'observe', id, topic, input });
|
|
131
|
+
drawing?.();
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function settled() {
|
|
135
|
+
if (settling !== null)
|
|
136
|
+
return settling;
|
|
137
|
+
settling = new Promise((resolve) => {
|
|
138
|
+
let moved = 0;
|
|
139
|
+
const check = () => {
|
|
140
|
+
moved += 1;
|
|
141
|
+
if (opening.size > 0)
|
|
142
|
+
return;
|
|
143
|
+
const at = moved;
|
|
144
|
+
requestAnimationFrame(() => {
|
|
145
|
+
requestAnimationFrame(() => {
|
|
146
|
+
if (moved !== at || opening.size > 0)
|
|
147
|
+
return;
|
|
148
|
+
drawing = null;
|
|
149
|
+
resolve();
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
drawing = check;
|
|
154
|
+
check();
|
|
118
155
|
});
|
|
156
|
+
return settling;
|
|
119
157
|
}
|
|
120
158
|
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
|
-
])
|
|
159
|
+
rooms: () => ask('rooms', []),
|
|
160
|
+
query: ((query) => ask('query', [query])),
|
|
161
|
+
search: (request) => ask('search', [request]),
|
|
162
|
+
types: (locator) => ask('types', [locator]),
|
|
163
|
+
roomDraft: {
|
|
164
|
+
list: () => ask('roomDraft.list', []),
|
|
165
|
+
read: (room, path) => ask('roomDraft.read', [room, path]),
|
|
166
|
+
write: (room, path, revision, parts) => ask('roomDraft.write', [room, path, revision, parts]),
|
|
167
|
+
discard: (room, path, revision) => ask('roomDraft.discard', [room, path, revision]),
|
|
158
168
|
},
|
|
169
|
+
save: (room, roomDrafts) => ask('save', [room, roomDrafts]),
|
|
159
170
|
presentation: {
|
|
160
|
-
read: ()=>ask('presentation.read', []),
|
|
161
|
-
write: (value)=>ask('presentation.write', [
|
|
162
|
-
value
|
|
163
|
-
])
|
|
171
|
+
read: () => ask('presentation.read', []),
|
|
172
|
+
write: (value) => ask('presentation.write', [value]),
|
|
164
173
|
},
|
|
165
174
|
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
|
-
])
|
|
175
|
+
list: () => ask('conversation.list', []),
|
|
176
|
+
read: (conversation, options) => ask('conversation.read', [conversation, options]),
|
|
177
|
+
create: (input) => ask('conversation.create', [input]),
|
|
178
|
+
send: (conversation) => ask('conversation.send', [conversation]),
|
|
179
|
+
answer: (conversation, answer) => ask('conversation.answer', [conversation, answer]),
|
|
180
|
+
interrupt: (conversation) => ask('conversation.interrupt', [conversation]),
|
|
181
|
+
kill: (conversation) => ask('conversation.kill', [conversation]),
|
|
182
|
+
cancel: (conversation, turn) => ask('conversation.cancel', [conversation, turn]),
|
|
183
|
+
delete: (conversation) => ask('conversation.delete', [conversation]),
|
|
203
184
|
},
|
|
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);
|
|
185
|
+
chatDraft: {
|
|
186
|
+
write: (conversation, draft, revision) => ask('chatDraft.write', [conversation, draft, revision]),
|
|
187
|
+
discard: (conversation) => ask('chatDraft.discard', [conversation]),
|
|
222
188
|
},
|
|
223
|
-
|
|
189
|
+
history: (locator, path, query) => ask('history', [locator, path, query]),
|
|
190
|
+
binaryFile: {
|
|
191
|
+
read: (room, path, revision) => ask('binaryFile.read', [room, path, revision]),
|
|
192
|
+
readReference: (reference) => ask('binaryFile.readReference', [reference]),
|
|
193
|
+
},
|
|
194
|
+
call: (name, input) => ask('call', [name, input]),
|
|
195
|
+
reached: (locator, roomVersion, path) => ask('reached', [locator, roomVersion, path]),
|
|
196
|
+
log: () => ask('log', []),
|
|
197
|
+
persistence: () => ask('persistence', []),
|
|
198
|
+
observe: ((topic, ...input) => watch(topic, input)),
|
|
199
|
+
reauthorize: () => ask('reauthorize', []),
|
|
200
|
+
settled,
|
|
224
201
|
};
|
|
225
202
|
}
|
|
226
|
-
|
|
227
|
-
|
|
203
|
+
const turns = new WeakMap();
|
|
204
|
+
export function inTurn(client, work) {
|
|
205
|
+
const next = (turns.get(client) ?? Promise.resolve()).then(work).catch(() => undefined);
|
|
206
|
+
turns.set(client, next);
|
|
207
|
+
return next;
|
|
208
|
+
}
|
package/dist/collection.d.ts
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
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
|
+
text: Readonly<Record<string, string>>;
|
|
15
8
|
composition: Composition;
|
|
9
|
+
document(path: string): Document | undefined;
|
|
16
10
|
};
|
|
17
11
|
export type Composition = {
|
|
18
|
-
collectionRoot: string;
|
|
19
12
|
model: ModelState;
|
|
20
13
|
selection: {
|
|
21
14
|
roots: readonly string[];
|
|
@@ -23,11 +16,10 @@ export type Composition = {
|
|
|
23
16
|
} | null;
|
|
24
17
|
};
|
|
25
18
|
export declare function governing(composition: Composition, path: string): ModelState;
|
|
26
|
-
export declare function
|
|
27
|
-
export declare function
|
|
28
|
-
export declare function
|
|
19
|
+
export declare function collectionOf(text: Readonly<Record<string, string>>, composition: Composition, previous?: Collection): Collection;
|
|
20
|
+
export declare function passingDocument(collection: Collection, path: string): Document | undefined;
|
|
21
|
+
export declare function documentsOf(collection: Collection): Generator<readonly [string, Document]>;
|
|
22
|
+
export declare function unreadable(text: Readonly<Record<string, string>>, previous?: Readonly<Record<string, string>>): Refused | null;
|
|
29
23
|
export declare function validRoot(root: unknown): root is string;
|
|
30
|
-
export declare function validateCollection(text: Readonly<Record<string, string>>, binaryTargets: readonly string[], composition: Composition
|
|
31
|
-
source?: 'content' | 'model';
|
|
32
|
-
};
|
|
24
|
+
export declare function validateCollection(text: Readonly<Record<string, string>>, binaryTargets: readonly string[], composition: Composition): Validation;
|
|
33
25
|
//# 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,EACb,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,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,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;AAID,wBAAgB,YAAY,CAC1B,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,WAAW,EAAE,WAAW,EACxB,QAAQ,CAAC,EAAE,UAAU,GACpB,UAAU,CAsBZ;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAO1F;AAED,wBAAiB,WAAW,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAY3F;AAED,wBAAgB,UAAU,CACxB,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAC1C,OAAO,GAAG,IAAI,CAOhB;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,109 @@
|
|
|
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)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const model = governing(composition, path);
|
|
20
|
-
return model.status === 'unavailable' ? [] : model.types;
|
|
10
|
+
return composition.selection !== null && selected(composition, path)
|
|
11
|
+
? composition.selection.model
|
|
12
|
+
: composition.model;
|
|
21
13
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
const parsedIn = new WeakMap();
|
|
15
|
+
export function collectionOf(text, composition, previous) {
|
|
16
|
+
const parsed = new Map();
|
|
17
|
+
if (previous !== undefined) {
|
|
18
|
+
for (const [path, held] of parsedIn.get(previous) ?? []) {
|
|
19
|
+
if (previous.text[path] === text[path])
|
|
20
|
+
parsed.set(path, held);
|
|
21
|
+
}
|
|
27
22
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
composition
|
|
23
|
+
const collection = {
|
|
24
|
+
text,
|
|
25
|
+
composition,
|
|
26
|
+
document(path) {
|
|
27
|
+
const held = parsed.get(path);
|
|
28
|
+
if (held !== undefined)
|
|
29
|
+
return held ?? undefined;
|
|
30
|
+
const content = text[path];
|
|
31
|
+
if (content === undefined)
|
|
32
|
+
return undefined;
|
|
33
|
+
const read = parse(content, path);
|
|
34
|
+
parsed.set(path, read.ok ? read.document : null);
|
|
35
|
+
return read.ok ? read.document : undefined;
|
|
36
|
+
},
|
|
31
37
|
};
|
|
32
|
-
|
|
33
|
-
export function readCollection(text, composition) {
|
|
34
|
-
if (!validRoot(composition.collectionRoot)) return null;
|
|
35
|
-
const collection = parseCollection(text, composition);
|
|
36
|
-
if (Object.keys(collection.documents).length !== Object.keys(text).length) return null;
|
|
37
|
-
if (Object.entries(collection.documents).some(([path, document])=>!member(path, composition.collectionRoot) && !selected(composition, path) && document.type !== undefined && document.type !== 'any')) return null;
|
|
38
|
+
parsedIn.set(collection, parsed);
|
|
38
39
|
return collection;
|
|
39
40
|
}
|
|
41
|
+
export function passingDocument(collection, path) {
|
|
42
|
+
const held = parsedIn.get(collection)?.get(path);
|
|
43
|
+
if (held !== undefined)
|
|
44
|
+
return held ?? undefined;
|
|
45
|
+
const content = collection.text[path];
|
|
46
|
+
if (content === undefined)
|
|
47
|
+
return undefined;
|
|
48
|
+
const read = parse(content, path);
|
|
49
|
+
return read.ok ? read.document : undefined;
|
|
50
|
+
}
|
|
51
|
+
export function* documentsOf(collection) {
|
|
52
|
+
const parsed = parsedIn.get(collection);
|
|
53
|
+
for (const path of Object.keys(collection.text).sort()) {
|
|
54
|
+
const held = parsed?.get(path);
|
|
55
|
+
if (held === null)
|
|
56
|
+
continue;
|
|
57
|
+
if (held !== undefined) {
|
|
58
|
+
yield [path, held];
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const read = parse(collection.text[path], path);
|
|
62
|
+
if (read.ok)
|
|
63
|
+
yield [path, read.document];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export function unreadable(text, previous) {
|
|
67
|
+
for (const path of Object.keys(text).sort()) {
|
|
68
|
+
if (previous?.[path] === text[path])
|
|
69
|
+
continue;
|
|
70
|
+
const read = parse(text[path], path);
|
|
71
|
+
if (!read.ok)
|
|
72
|
+
return { kind: 'refused', refusal: read.refusal };
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
40
76
|
export function validRoot(root) {
|
|
41
77
|
return typeof root === 'string' && normalize(root) === root;
|
|
42
78
|
}
|
|
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])=>{
|
|
79
|
+
function validateAgainst(documents, binaryTargets, model) {
|
|
80
|
+
if (model.status === 'unavailable') {
|
|
81
|
+
const typed = Object.entries(documents).find(([, content]) => {
|
|
49
82
|
const parsed = parse(content);
|
|
50
83
|
return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
|
|
51
84
|
});
|
|
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
|
-
});
|
|
85
|
+
if (typed !== undefined)
|
|
86
|
+
return { verdict: 'refuse', rule: 'model-unavailable', file: typed[0] };
|
|
61
87
|
}
|
|
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
|
-
};
|
|
88
|
+
return validate(documents, { binaryTargets }, model.status === 'unavailable' ? NO_TYPES : { types: model.types });
|
|
76
89
|
}
|
|
77
|
-
export function validateCollection(text, binaryTargets, composition
|
|
78
|
-
const prefix = composition.collectionRoot === '' ? '' : `${composition.collectionRoot}/`;
|
|
90
|
+
export function validateCollection(text, binaryTargets, composition) {
|
|
79
91
|
const collection = {};
|
|
80
92
|
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)) {
|
|
93
|
+
for (const [path, content] of Object.entries(text)) {
|
|
94
|
+
if (selected(composition, path))
|
|
87
95
|
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
|
-
}
|
|
96
|
+
else
|
|
97
|
+
collection[path] = content;
|
|
103
98
|
}
|
|
104
99
|
const verdicts = [
|
|
105
|
-
validateAgainst(collection, binaryTargets.filter((path)=>
|
|
100
|
+
validateAgainst(collection, binaryTargets.filter((path) => !selected(composition, path)), composition.model),
|
|
106
101
|
];
|
|
107
102
|
if (composition.selection !== null) {
|
|
108
|
-
verdicts.push(validateAgainst(selection, binaryTargets.filter((path)=>selected(composition, path)),
|
|
103
|
+
verdicts.push(validateAgainst(selection, binaryTargets.filter((path) => selected(composition, path)), composition.selection.model));
|
|
109
104
|
}
|
|
110
|
-
const refusals = verdicts.filter((verdict)=>verdict.verdict === 'refuse');
|
|
111
|
-
if (refusals.length === 0)
|
|
112
|
-
|
|
105
|
+
const refusals = verdicts.filter((verdict) => verdict.verdict === 'refuse');
|
|
106
|
+
if (refusals.length === 0)
|
|
107
|
+
return verdicts[0];
|
|
108
|
+
return refusals.find((refusal) => refusal.rule !== 'model-unavailable') ?? refusals[0];
|
|
113
109
|
}
|
|
114
|
-
|
|
115
|
-
//# sourceMappingURL=collection.js.map
|