@agentshouse/mdruntime 0.1.0-cf6041a06849c → 0.1.0-cf96c797c5fa8
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 +135 -48
- package/README.md +20 -10
- package/dist/adapter.d.ts +49 -14
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +15 -2
- package/dist/attempt.d.ts +16 -0
- package/dist/attempt.d.ts.map +1 -0
- package/dist/attempt.js +57 -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 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +89 -38
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +19 -12
- package/dist/change.d.ts +15 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +26 -1
- 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 +20 -0
- package/dist/chat/list.d.ts.map +1 -0
- package/dist/chat/list.js +59 -0
- package/dist/chat/markdown.d.ts +19 -0
- package/dist/chat/markdown.d.ts.map +1 -0
- package/dist/chat/markdown.js +187 -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 +14 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +65 -15
- package/dist/collection.d.ts +6 -11
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +56 -19
- package/dist/connection.d.ts +22 -9
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +472 -142
- package/dist/conversation.d.ts +11 -3
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +47 -7
- 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/host.d.ts +1 -0
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +9 -8
- package/dist/identity.d.ts +3 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +13 -1
- package/dist/index.d.ts +9 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/memory.d.ts +4 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +61 -20
- package/dist/model.d.ts +10 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +2 -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 +28 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +41 -1
- package/dist/overlay.d.ts +14 -3
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +75 -37
- package/dist/paths.d.ts +0 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +0 -16
- package/dist/query.d.ts +5 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +52 -19
- package/dist/reach.d.ts +2 -0
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +44 -35
- package/dist/react.d.ts +26 -16
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +10 -8
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +111 -48
- package/dist/refresh.d.ts +10 -0
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +42 -38
- package/dist/replica.d.ts +8 -5
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +76 -56
- package/dist/room-draft.d.ts +26 -9
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +132 -23
- package/dist/rows.d.ts +7 -2
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +87 -39
- package/dist/save.d.ts +28 -1
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +429 -75
- package/dist/search.d.ts +3 -2
- package/dist/search.d.ts.map +1 -1
- package/dist/status.d.ts +2 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -8
- package/dist/store.d.ts +34 -9
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +273 -164
- package/dist/wire.d.ts +7 -3
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +15 -2
- package/package.json +17 -9
- package/dist/attachment.d.ts +0 -3
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -8
package/dist/paths.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
function dirname(path) {
|
|
2
|
-
const index = path.lastIndexOf('/');
|
|
3
|
-
return index === -1 ? '' : path.slice(0, index);
|
|
4
|
-
}
|
|
5
1
|
export function normalize(path) {
|
|
6
2
|
const parts = [];
|
|
7
3
|
for (const part of path.split('/')) {
|
|
@@ -17,18 +13,6 @@ export function normalize(path) {
|
|
|
17
13
|
}
|
|
18
14
|
return parts.join('/');
|
|
19
15
|
}
|
|
20
|
-
export function relative(from, target) {
|
|
21
|
-
const base = dirname(from)
|
|
22
|
-
.split('/')
|
|
23
|
-
.filter((part) => part !== '');
|
|
24
|
-
const parts = target.split('/');
|
|
25
|
-
let shared = 0;
|
|
26
|
-
while (shared < base.length && shared + 1 < parts.length && base[shared] === parts[shared]) {
|
|
27
|
-
shared += 1;
|
|
28
|
-
}
|
|
29
|
-
const up = Array.from({ length: base.length - shared }, () => '..');
|
|
30
|
-
return [...up, ...parts.slice(shared)].join('/');
|
|
31
|
-
}
|
|
32
16
|
export function beneath(prefix, path) {
|
|
33
17
|
return path === prefix || path.startsWith(`${prefix}/`);
|
|
34
18
|
}
|
package/dist/query.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Definition } from '@agentshouse/mdmodel';
|
|
2
2
|
import type { HeadChange } from './adapter.js';
|
|
3
|
+
import type { BinaryFileRecord } from './binary.js';
|
|
3
4
|
export type Value = string | number | boolean | null;
|
|
4
5
|
export type Predicate = Value | {
|
|
5
6
|
$eq: Value;
|
|
@@ -93,6 +94,7 @@ export type QueryDocument = {
|
|
|
93
94
|
markdown?: string;
|
|
94
95
|
backlinks?: readonly Backlink[];
|
|
95
96
|
change?: HeadChange | null;
|
|
97
|
+
binaryFile?: BinaryFileRecord;
|
|
96
98
|
};
|
|
97
99
|
export type QueryGroup = {
|
|
98
100
|
key: readonly unknown[];
|
|
@@ -204,6 +206,8 @@ export type Plan = {
|
|
|
204
206
|
limit: number | null;
|
|
205
207
|
};
|
|
206
208
|
export declare class QueryError extends Error {
|
|
209
|
+
readonly code: QueryErrorCode;
|
|
210
|
+
readonly retryable = false;
|
|
207
211
|
constructor(code: QueryErrorCode, at: string, problem: string);
|
|
208
212
|
}
|
|
209
213
|
type Entries = Readonly<Record<string, unknown>>;
|
package/dist/query.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EAGhB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAIpD,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAErD,MAAM,MAAM,SAAS,GACjB,KAAK,GACL;IAAE,GAAG,EAAE,KAAK,CAAA;CAAE,GACd;IAAE,GAAG,EAAE,KAAK,CAAA;CAAE,GACd;IA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GAAG,IAAI,CAI/F;AAaD,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE7C"}
|
package/dist/query.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { pointerFacts, } from '@agentshouse/mdmodel';
|
|
1
2
|
import { referenceField } from './model.js';
|
|
2
3
|
import { normalize } from './paths.js';
|
|
3
4
|
export class QueryError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
retryable = false;
|
|
4
7
|
constructor(code, at, problem) {
|
|
5
8
|
super(`${code} at ${at}: ${problem}`);
|
|
9
|
+
this.code = code;
|
|
6
10
|
}
|
|
7
11
|
}
|
|
8
12
|
const RANGE = ['$gt', '$gte', '$lt', '$lte'];
|
|
@@ -12,6 +16,7 @@ const RELATED = ['types', 'where', 'pathPrefix', 'field'];
|
|
|
12
16
|
const PARTS = ['fields', 'sections', 'preamble', 'markdown', 'backlinks', 'change'];
|
|
13
17
|
const ORDER = ['by', 'direction', 'nulls', 'stringSort', 'locale', 'localeOptions'];
|
|
14
18
|
const CALENDAR_DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
19
|
+
const STRAY_ESCAPE = /~(?![01])/u;
|
|
15
20
|
export function invalid(at, problem) {
|
|
16
21
|
throw new QueryError('invalid-query', at, problem);
|
|
17
22
|
}
|
|
@@ -109,23 +114,46 @@ function typing(facts, rooms, types, at) {
|
|
|
109
114
|
types: types === null ? declared : declared.filter((type) => types.includes(type.name)),
|
|
110
115
|
};
|
|
111
116
|
}
|
|
112
|
-
function
|
|
113
|
-
|
|
117
|
+
function pointer(input, at) {
|
|
118
|
+
if (typeof input !== 'string' || !input.startsWith('/') || STRAY_ESCAPE.test(input)) {
|
|
119
|
+
invalid(at, 'expects a JSON Pointer');
|
|
120
|
+
}
|
|
121
|
+
return input;
|
|
122
|
+
}
|
|
123
|
+
function specs(typed, input, at) {
|
|
124
|
+
const field = pointer(input, at);
|
|
125
|
+
const declared = typed.types.flatMap((type) => {
|
|
126
|
+
const spec = pointerFacts(type, field);
|
|
127
|
+
return spec === undefined ? [] : [spec];
|
|
128
|
+
});
|
|
114
129
|
if (declared.length === 0 && !typed.untyped) {
|
|
115
130
|
throw new QueryError('unknown-field', at, `no MD Type it reads declares ${field}`);
|
|
116
131
|
}
|
|
117
|
-
|
|
132
|
+
if (!declared.some((spec) => spec.conditional))
|
|
133
|
+
return declared;
|
|
134
|
+
return declared.map((spec) => ({
|
|
135
|
+
facts: { prose: false },
|
|
136
|
+
through: several(spec),
|
|
137
|
+
conditional: true,
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
function several(spec) {
|
|
141
|
+
return spec.through || spec.facts.type === 'array';
|
|
142
|
+
}
|
|
143
|
+
function single(spec) {
|
|
144
|
+
return spec.facts.type !== undefined && spec.facts.type !== 'array';
|
|
145
|
+
}
|
|
146
|
+
function every(declared, holds) {
|
|
147
|
+
return declared.length > 0 && declared.every(holds);
|
|
118
148
|
}
|
|
119
149
|
function kind(declared, checked, at) {
|
|
120
|
-
if (checked === null ||
|
|
150
|
+
if (checked === null ||
|
|
151
|
+
declared.length === 0 ||
|
|
152
|
+
declared.some((spec) => fits(spec.facts, checked))) {
|
|
121
153
|
return;
|
|
122
154
|
}
|
|
123
155
|
throw new QueryError('wrong-kind', at, `${JSON.stringify(checked)} is not of its field's kind`);
|
|
124
156
|
}
|
|
125
|
-
function listed(declared, list) {
|
|
126
|
-
return (declared.length > 0 &&
|
|
127
|
-
declared.every((facts) => facts.type !== undefined && (facts.type === 'array') === list));
|
|
128
|
-
}
|
|
129
157
|
function test(declared, input, at) {
|
|
130
158
|
if (!plain(input)) {
|
|
131
159
|
const equal = value(input, at);
|
|
@@ -139,8 +167,11 @@ function test(declared, input, at) {
|
|
|
139
167
|
const stray = operators.find((operator) => !RANGE.includes(operator));
|
|
140
168
|
if (stray !== undefined)
|
|
141
169
|
invalid(place(at, stray), 'cannot join a range');
|
|
142
|
-
if (
|
|
170
|
+
if (every(declared, (spec) => spec.facts.type === 'array'))
|
|
143
171
|
invalid(at, 'a range on a list');
|
|
172
|
+
if (every(declared, (spec) => spec.facts.type === 'boolean' || spec.facts.type === 'object')) {
|
|
173
|
+
throw new QueryError('wrong-kind', at, 'its field does not compare in order');
|
|
174
|
+
}
|
|
144
175
|
return {
|
|
145
176
|
op: 'range',
|
|
146
177
|
bounds: RANGE.filter((operator) => operators.includes(operator)).map((operator) => {
|
|
@@ -173,7 +204,7 @@ function test(declared, input, at) {
|
|
|
173
204
|
return { op: 'nin', values: compared };
|
|
174
205
|
if (compared.includes(null))
|
|
175
206
|
invalid(where, 'a list holds no null');
|
|
176
|
-
if (
|
|
207
|
+
if (every(declared, single))
|
|
177
208
|
invalid(where, 'the field is not a list');
|
|
178
209
|
return { op: 'all', values: compared };
|
|
179
210
|
}
|
|
@@ -181,7 +212,7 @@ function test(declared, input, at) {
|
|
|
181
212
|
if (!Number.isSafeInteger(operand) || operand < 0) {
|
|
182
213
|
invalid(where, 'expects a nonnegative integer');
|
|
183
214
|
}
|
|
184
|
-
if (
|
|
215
|
+
if (every(declared, single))
|
|
185
216
|
invalid(where, 'the field is not a list');
|
|
186
217
|
return { op: 'size', size: operand };
|
|
187
218
|
}
|
|
@@ -194,7 +225,7 @@ function condition(typed, input, at) {
|
|
|
194
225
|
invalid(at, 'expects an object of field predicates');
|
|
195
226
|
const conditions = [];
|
|
196
227
|
for (const name of Object.keys(input).sort()) {
|
|
197
|
-
const where = place(at, name);
|
|
228
|
+
const where = name.startsWith('/') ? `${at}${name}` : place(at, name);
|
|
198
229
|
const entry = input[name];
|
|
199
230
|
if (name === '$and' || name === '$or') {
|
|
200
231
|
const nested = list(entry, where).map((item, index) => condition(typed, item, `${where}[${index}]`));
|
|
@@ -224,11 +255,11 @@ function scope(facts, rooms, input, at) {
|
|
|
224
255
|
};
|
|
225
256
|
}
|
|
226
257
|
function referenceName(typed, field, at) {
|
|
227
|
-
if (typeof field !== 'string')
|
|
228
|
-
invalid(at, 'expects a field name');
|
|
229
258
|
const declared = specs(typed, field, at);
|
|
230
|
-
if (declared.length > 0 &&
|
|
259
|
+
if (declared.length > 0 &&
|
|
260
|
+
!declared.some((spec) => spec.conditional || referenceField(spec.facts))) {
|
|
231
261
|
invalid(at, 'not a reference field');
|
|
262
|
+
}
|
|
232
263
|
return field;
|
|
233
264
|
}
|
|
234
265
|
function hopOf(facts, rooms, root, input) {
|
|
@@ -250,8 +281,10 @@ function backlinksOf(facts, rooms, input) {
|
|
|
250
281
|
function keyPlan(typed, input, at, path) {
|
|
251
282
|
if (input === 'room' || input === 'type' || (path && input === 'path'))
|
|
252
283
|
return { of: input };
|
|
253
|
-
if (plain(input) &&
|
|
254
|
-
specs(typed, input.field, place(at, 'field'))
|
|
284
|
+
if (plain(input) && Object.hasOwn(input, 'field') && Object.keys(input).length === 1) {
|
|
285
|
+
if (specs(typed, input.field, place(at, 'field')).some(several)) {
|
|
286
|
+
invalid(place(at, 'field'), 'a path that can hold several values');
|
|
287
|
+
}
|
|
255
288
|
return { of: 'field', field: input.field };
|
|
256
289
|
}
|
|
257
290
|
return invalid(at, path ? 'expects room, path, type or a field' : 'expects room, type or a field');
|
|
@@ -309,10 +342,10 @@ function parts(typed, input, at, fields) {
|
|
|
309
342
|
return 'all';
|
|
310
343
|
const named = list(input, at);
|
|
311
344
|
named.forEach((name, index) => {
|
|
312
|
-
if (typeof name !== 'string')
|
|
313
|
-
invalid(`${at}[${index}]`, 'expects a name');
|
|
314
345
|
if (fields)
|
|
315
346
|
specs(typed, name, `${at}[${index}]`);
|
|
347
|
+
else if (typeof name !== 'string')
|
|
348
|
+
invalid(`${at}[${index}]`, 'expects a name');
|
|
316
349
|
});
|
|
317
350
|
return named;
|
|
318
351
|
}
|
package/dist/reach.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ReferrerScope } from './adapter.js';
|
|
1
2
|
import type { MdRuntime, RuntimeTopic } from './connection.js';
|
|
2
3
|
import type { Plan, PlanReach, QueryResult } from './query.js';
|
|
3
4
|
import type { SearchResult } from './search.js';
|
|
@@ -24,6 +25,7 @@ export type Reachable = RuntimeView & {
|
|
|
24
25
|
query(plan: Plan): Promise<QueryResult>;
|
|
25
26
|
watchPlan(plan: Plan, deliver: (message: unknown) => void): () => void;
|
|
26
27
|
search(input: unknown, reach: PortReach | null): Promise<SearchResult>;
|
|
28
|
+
referrerScope(referrer: unknown): ReferrerScope | null;
|
|
27
29
|
};
|
|
28
30
|
export declare function holds(reach: PortReach | null, room: string): boolean;
|
|
29
31
|
export declare function governs(reach: PortReach | null, room: {
|
package/dist/reach.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reach.d.ts","sourceRoot":"","sources":["../src/reach.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,SAAS,EAAe,YAAY,EAAc,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"reach.d.ts","sourceRoot":"","sources":["../src/reach.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAW,SAAS,EAAe,YAAY,EAAc,MAAM,iBAAiB,CAAC;AAajG,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAU/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,MAAM,MAAM,eAAe,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/E,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,SAAS,EAAE,SAAS,eAAe,EAAE,CAAC;IAC/C,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,OAAO,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AA;CAAE,GAC/F;IAAE,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAU/D;AA2BD,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CASnE;AA8ED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,GAAG,YAAY,CA4KlF"}
|
package/dist/reach.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import { unheldView } from './conversation.js';
|
|
2
2
|
import { modelTypes, NO_MODEL } from './model.js';
|
|
3
3
|
import { applied, observing } from './observation.js';
|
|
4
|
+
import { runtimeError } from './failure.js';
|
|
5
|
+
import { failure, undeclared, } from './outcome.js';
|
|
4
6
|
import { beneath } from './paths.js';
|
|
5
7
|
import { reconciled } from './read-side.js';
|
|
6
|
-
import { moveTarget, readParts } from './room-draft.js';
|
|
8
|
+
import { moveTarget, readParts, staleWrite, } from './room-draft.js';
|
|
7
9
|
import { documentKey } from './rows.js';
|
|
8
10
|
const UNHELD_TYPES = { collection: modelTypes(NO_MODEL), typedSelection: null };
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return Promise.resolve(UNDECLARED);
|
|
11
|
+
function unconversed(name) {
|
|
12
|
+
return () => Promise.resolve(undeclared(name));
|
|
12
13
|
}
|
|
13
14
|
const NO_CONVERSATION = {
|
|
14
15
|
list: () => Promise.resolve([]),
|
|
15
16
|
read: (conversation) => Promise.resolve(unheldView(conversation)),
|
|
16
|
-
create:
|
|
17
|
-
send:
|
|
18
|
-
answer:
|
|
19
|
-
interrupt:
|
|
20
|
-
kill:
|
|
21
|
-
cancel:
|
|
22
|
-
delete:
|
|
17
|
+
create: unconversed('conversation.create'),
|
|
18
|
+
send: unconversed('conversation.send'),
|
|
19
|
+
answer: unconversed('conversation.answer'),
|
|
20
|
+
interrupt: unconversed('conversation.interrupt'),
|
|
21
|
+
kill: unconversed('conversation.kill'),
|
|
22
|
+
cancel: unconversed('conversation.cancel'),
|
|
23
|
+
delete: unconversed('conversation.delete'),
|
|
23
24
|
};
|
|
24
25
|
const NO_CHAT_DRAFT = {
|
|
25
26
|
write: () => Promise.resolve(),
|
|
@@ -51,6 +52,20 @@ function covers(reach, room, path) {
|
|
|
51
52
|
function conversing(reach) {
|
|
52
53
|
return reach === null || reach.conversations;
|
|
53
54
|
}
|
|
55
|
+
function refers(reach, scope) {
|
|
56
|
+
if (reach === null)
|
|
57
|
+
return true;
|
|
58
|
+
if (scope === null)
|
|
59
|
+
return false;
|
|
60
|
+
if (scope.kind === 'conversations')
|
|
61
|
+
return reach.conversations;
|
|
62
|
+
return scope.path === undefined
|
|
63
|
+
? wholly(reach, scope.locator)
|
|
64
|
+
: covers(reach, scope.locator, scope.path);
|
|
65
|
+
}
|
|
66
|
+
function unreachedReference(fileRef) {
|
|
67
|
+
return { kind: 'absent', code: 'binary-file-absent', fields: { fileRef }, retryable: false };
|
|
68
|
+
}
|
|
54
69
|
export function planReach(reach) {
|
|
55
70
|
return reach === null
|
|
56
71
|
? null
|
|
@@ -62,22 +77,7 @@ export function planReach(reach) {
|
|
|
62
77
|
};
|
|
63
78
|
}
|
|
64
79
|
function roomsWithin(reach, rooms) {
|
|
65
|
-
|
|
66
|
-
return rooms;
|
|
67
|
-
return rooms
|
|
68
|
-
.filter((room) => holds(reach, room.locator))
|
|
69
|
-
.map((room) => {
|
|
70
|
-
if (wholly(reach, room.locator))
|
|
71
|
-
return room;
|
|
72
|
-
const governed = governs(reach, room);
|
|
73
|
-
return {
|
|
74
|
-
...room,
|
|
75
|
-
model: governed.collection ? room.model : modelTypes(NO_MODEL),
|
|
76
|
-
typedSelection: governed.selection ? room.typedSelection : null,
|
|
77
|
-
roomVersion: null,
|
|
78
|
-
attachments: [],
|
|
79
|
-
};
|
|
80
|
-
});
|
|
80
|
+
return rooms.filter((room) => wholly(reach, room.locator));
|
|
81
81
|
}
|
|
82
82
|
function typesWithin(reach, room, types) {
|
|
83
83
|
if (room === undefined)
|
|
@@ -103,7 +103,7 @@ function shownDraft(reach, draft) {
|
|
|
103
103
|
function writeWithin(reach, write) {
|
|
104
104
|
return write.outcome === 'written'
|
|
105
105
|
? { outcome: 'written', roomDraft: shownDraft(reach, write.roomDraft) }
|
|
106
|
-
:
|
|
106
|
+
: staleWrite(shownDraft(reach, write.current));
|
|
107
107
|
}
|
|
108
108
|
function savedWithin(reach, room, result) {
|
|
109
109
|
if (reach === null || result.outcome === 'saved')
|
|
@@ -130,7 +130,7 @@ function queueWithin(reach, room, entries) {
|
|
|
130
130
|
(change.kind !== 'move' || covers(reach, room, change.to))));
|
|
131
131
|
}
|
|
132
132
|
function unreached(room) {
|
|
133
|
-
return
|
|
133
|
+
return runtimeError('room-not-held', `No Local Replica for ${room}`);
|
|
134
134
|
}
|
|
135
135
|
export function narrowed(runtime, given) {
|
|
136
136
|
const { md, watch } = runtime;
|
|
@@ -201,7 +201,7 @@ export function narrowed(runtime, given) {
|
|
|
201
201
|
return () => { };
|
|
202
202
|
});
|
|
203
203
|
}
|
|
204
|
-
if (topic === 'conversations') {
|
|
204
|
+
if (topic === 'conversations' || topic === 'agents') {
|
|
205
205
|
return following(() => {
|
|
206
206
|
if (conversing(reach))
|
|
207
207
|
return watch(topic, input, deliver);
|
|
@@ -231,13 +231,22 @@ export function narrowed(runtime, given) {
|
|
|
231
231
|
throw unreached(room);
|
|
232
232
|
const outside = roomDrafts.find(({ path }) => !covers(reach, room, path) ||
|
|
233
233
|
!moves(reach, room, md.roomDraft.read(room, path)?.parts.move));
|
|
234
|
-
if (outside !== undefined)
|
|
235
|
-
return { outcome: 'refused',
|
|
234
|
+
if (outside !== undefined) {
|
|
235
|
+
return { outcome: 'refused', code: 'stale', retryable: false, file: outside.path };
|
|
236
|
+
}
|
|
236
237
|
return savedWithin(reach, room, await md.save(room, roomDrafts, writtenBy));
|
|
237
238
|
},
|
|
238
239
|
history: (room, path, query) => covers(reach, room, path)
|
|
239
240
|
? md.history(room, path, query)
|
|
240
|
-
: Promise.resolve({ kind: 'room-not-readable', locator: room }),
|
|
241
|
+
: Promise.resolve(failure({ kind: 'room-not-readable', locator: room })),
|
|
242
|
+
binaryFile: {
|
|
243
|
+
read: (room, path, revision) => covers(reach, room, path)
|
|
244
|
+
? md.binaryFile.read(room, path, revision)
|
|
245
|
+
: Promise.resolve(failure({ kind: 'room-not-readable', locator: room })),
|
|
246
|
+
readReference: (reference) => refers(reach, runtime.referrerScope(reference.referrer))
|
|
247
|
+
? md.binaryFile.readReference(reference)
|
|
248
|
+
: Promise.resolve(unreachedReference(reference.fileRef)),
|
|
249
|
+
},
|
|
241
250
|
reached: (room, roomVersion, path) => (path === undefined ? wholly(reach, room) : covers(reach, room, path)) &&
|
|
242
251
|
md.reached(room, roomVersion, path),
|
|
243
252
|
log: () => (reach === null ? md.log() : ''),
|
|
@@ -252,7 +261,7 @@ export function narrowed(runtime, given) {
|
|
|
252
261
|
},
|
|
253
262
|
async discard(room, path, revision) {
|
|
254
263
|
if (!covers(reach, room, path))
|
|
255
|
-
return
|
|
264
|
+
return staleWrite(null);
|
|
256
265
|
return writeWithin(reach, await md.roomDraft.discard(room, path, revision));
|
|
257
266
|
},
|
|
258
267
|
},
|
|
@@ -268,7 +277,7 @@ export function narrowed(runtime, given) {
|
|
|
268
277
|
delete: (id) => conversation().delete(id),
|
|
269
278
|
},
|
|
270
279
|
chatDraft: {
|
|
271
|
-
write: (id, draft) => chatDraft().write(id, draft),
|
|
280
|
+
write: (id, draft, revision) => chatDraft().write(id, draft, revision),
|
|
272
281
|
discard: (id) => chatDraft().discard(id),
|
|
273
282
|
},
|
|
274
283
|
observe: observing(within),
|
package/dist/react.d.ts
CHANGED
|
@@ -1,31 +1,41 @@
|
|
|
1
1
|
import type { MdRuntimeClient } from './client.js';
|
|
2
2
|
import type { AppRoom, ConnectionRefusal, SaveResult } from './connection.js';
|
|
3
|
-
import type { ServiceMode } from './adapter.js';
|
|
4
|
-
import type { ConversationEntry, ConversationOptions, ConversationView } from './conversation.js';
|
|
3
|
+
import type { Member, ServiceMode } from './adapter.js';
|
|
4
|
+
import type { ConversationAgent, ConversationEntry, ConversationOptions, ConversationView } from './conversation.js';
|
|
5
|
+
import { type RuntimeError } from './failure.js';
|
|
5
6
|
import type { QueueEntry } from './outcome.js';
|
|
6
7
|
import type { DocumentQuery, DocumentResult, GroupQuery, GroupResult } from './query.js';
|
|
7
8
|
import type { RoomDraft, RoomDraftParts } from './room-draft.js';
|
|
8
9
|
import type { SyncStatus } from './status.js';
|
|
9
10
|
type Client = MdRuntimeClient | null;
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export declare function useObserve(client: Client, topic: '
|
|
17
|
-
export declare function useObserve(client: Client, topic: '
|
|
18
|
-
export declare function useObserve(client: Client, topic: '
|
|
19
|
-
export declare function useObserve(client: Client, topic: '
|
|
20
|
-
export declare function useObserve(client: Client, topic: '
|
|
21
|
-
export declare function useObserve(client: Client, topic: '
|
|
22
|
-
export declare function useObserve(client: Client, topic: '
|
|
11
|
+
export type Observed<T> = {
|
|
12
|
+
readonly state: 'loading';
|
|
13
|
+
} | {
|
|
14
|
+
readonly state: 'ready';
|
|
15
|
+
readonly value: T;
|
|
16
|
+
};
|
|
17
|
+
export declare function useObserve(client: Client, topic: 'deployment-facts'): Observed<unknown>;
|
|
18
|
+
export declare function useObserve(client: Client, topic: 'rooms'): Observed<readonly AppRoom[]>;
|
|
19
|
+
export declare function useObserve(client: Client, topic: 'connection-refusal'): Observed<ConnectionRefusal | null>;
|
|
20
|
+
export declare function useObserve(client: Client, topic: 'storage-loss'): Observed<string | null>;
|
|
21
|
+
export declare function useObserve(client: Client, topic: 'sync-status'): Observed<SyncStatus>;
|
|
22
|
+
export declare function useObserve(client: Client, topic: 'service-mode'): Observed<ServiceMode>;
|
|
23
|
+
export declare function useObserve(client: Client, topic: 'member'): Observed<Member | null>;
|
|
24
|
+
export declare function useObserve(client: Client, topic: 'query', query: DocumentQuery): Observed<DocumentResult>;
|
|
25
|
+
export declare function useObserve(client: Client, topic: 'query', query: GroupQuery): Observed<GroupResult>;
|
|
26
|
+
export declare function useObserve(client: Client, topic: 'queue', locator: string): Observed<readonly QueueEntry[]>;
|
|
27
|
+
export declare function useObserve(client: Client, topic: 'room-drafts'): Observed<readonly RoomDraft[]>;
|
|
28
|
+
export declare function useObserve(client: Client, topic: 'presentation'): Observed<unknown>;
|
|
29
|
+
export declare function useObserve(client: Client, topic: 'conversation', conversation: string, options: ConversationOptions): Observed<ConversationView>;
|
|
30
|
+
export declare function useObserve(client: Client, topic: 'conversations'): Observed<readonly ConversationEntry[]>;
|
|
31
|
+
export declare function useObserve(client: Client, topic: 'agents'): Observed<readonly ConversationAgent[]>;
|
|
23
32
|
export type Saving = {
|
|
24
33
|
readonly busy: boolean;
|
|
25
34
|
readonly outcome: SaveResult | null;
|
|
26
|
-
readonly failure:
|
|
35
|
+
readonly failure: RuntimeError | null;
|
|
27
36
|
save(room: string, roomDrafts: ReadonlyMap<string, RoomDraftParts>): Promise<SaveResult>;
|
|
28
37
|
};
|
|
38
|
+
export declare function saveRoomDrafts(client: MdRuntimeClient, room: string, roomDrafts: ReadonlyMap<string, RoomDraftParts>): Promise<SaveResult>;
|
|
29
39
|
export declare function useSave(client: MdRuntimeClient): Saving;
|
|
30
40
|
export {};
|
|
31
41
|
//# sourceMappingURL=react.d.ts.map
|
package/dist/react.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAkB,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC9F,OAAO,KAAK,EAAE,W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Ac,EACrB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,mBAAmB,GAC3B,QAAQ,CAAC,gBAAgB,CAAC,CAAC;AAC9B,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,eAAe,GACrB,QAAQ,CAAC,SAAS,iBAAiB,EAAE,CAAC,CAAC;AAC1C,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,QAAQ,CAAC,SAAS,iBAAiB,EAAE,CAAC,CAAC;AAsCpG,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IACtC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAC1F,CAAC;AAMF,wBAAsB,cAAc,CAClC,MAAM,EAAE,eAAe,EACvB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,GAC9C,OAAO,CAAC,UAAU,CAAC,CAcrB;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAkBvD"}
|
package/dist/react.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { useCallback,
|
|
1
|
+
import { useCallback, useLayoutEffect, useRef, useState } from 'react';
|
|
2
|
+
import { failed, runtimeError } from './failure.js';
|
|
3
|
+
const LOADING = { state: 'loading' };
|
|
2
4
|
export function useObserve(client, topic, ...input) {
|
|
3
5
|
const key = JSON.stringify([topic, ...input]);
|
|
4
6
|
const [held, setHeld] = useState(null);
|
|
5
7
|
const opened = useRef(input);
|
|
6
8
|
opened.current = input;
|
|
7
|
-
|
|
9
|
+
useLayoutEffect(() => {
|
|
8
10
|
if (client === null)
|
|
9
11
|
return;
|
|
10
12
|
let live = true;
|
|
@@ -18,7 +20,7 @@ export function useObserve(client, topic, ...input) {
|
|
|
18
20
|
observation = open;
|
|
19
21
|
const take = (value) => {
|
|
20
22
|
if (live)
|
|
21
|
-
setHeld({ client, key, value });
|
|
23
|
+
setHeld({ client, key, observed: { state: 'ready', value } });
|
|
22
24
|
};
|
|
23
25
|
take(open.current());
|
|
24
26
|
open.subscribe(take);
|
|
@@ -28,16 +30,16 @@ export function useObserve(client, topic, ...input) {
|
|
|
28
30
|
observation?.close();
|
|
29
31
|
};
|
|
30
32
|
}, [client, key]);
|
|
31
|
-
return held !== null && held.client === client && held.key === key ? held.
|
|
33
|
+
return held !== null && held.client === client && held.key === key ? held.observed : LOADING;
|
|
32
34
|
}
|
|
33
35
|
const IDLE = { busy: false, outcome: null, failure: null };
|
|
34
|
-
async function
|
|
36
|
+
export async function saveRoomDrafts(client, room, roomDrafts) {
|
|
35
37
|
const kept = [];
|
|
36
38
|
for (const [path, parts] of roomDrafts) {
|
|
37
39
|
const prior = await client.roomDraft.read(room, path);
|
|
38
40
|
const write = await client.roomDraft.write(room, path, prior?.revision ?? null, parts);
|
|
39
41
|
if (write.outcome !== 'written' || write.roomDraft === null) {
|
|
40
|
-
throw
|
|
42
|
+
throw runtimeError(write.outcome === 'stale' ? write.code : 'room-draft-unwritten', `the Room Draft at ${path} was not written`);
|
|
41
43
|
}
|
|
42
44
|
kept.push({ path, revision: write.roomDraft.revision });
|
|
43
45
|
}
|
|
@@ -48,12 +50,12 @@ export function useSave(client) {
|
|
|
48
50
|
const save = useCallback(async (room, roomDrafts) => {
|
|
49
51
|
setState({ busy: true, outcome: null, failure: null });
|
|
50
52
|
try {
|
|
51
|
-
const outcome = await
|
|
53
|
+
const outcome = await saveRoomDrafts(client, room, roomDrafts);
|
|
52
54
|
setState({ busy: false, outcome, failure: null });
|
|
53
55
|
return outcome;
|
|
54
56
|
}
|
|
55
57
|
catch (error) {
|
|
56
|
-
const failure =
|
|
58
|
+
const failure = failed(error);
|
|
57
59
|
setState({ busy: false, outcome: null, failure });
|
|
58
60
|
throw failure;
|
|
59
61
|
}
|
package/dist/read-side.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-side.d.ts","sourceRoot":"","sources":["../src/read-side.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"read-side.d.ts","sourceRoot":"","sources":["../src/read-side.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAU,KAAK,WAAW,EAAE,KAAK,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC3F,OAAO,KAAK,EAOV,IAAI,EAIJ,WAAW,EAIZ,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAuDpD,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC;IAC5B,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IACxC,KAAK,CACH,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,KAAK,IAAI,GACpD,MAAM,IAAI,CAAC;IACd,SAAS,IAAI,SAAS,gBAAgB,EAAE,CAAC;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAAC;IAC9D,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAuVF,wBAAgB,UAAU,CACxB,QAAQ,EAAE,WAAW,EACrB,IAAI,EAAE,WAAW,GAChB;IAAE,KAAK,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,GAAG,IAAI,CA4BpD;AAED,wBAAgB,cAAc,IAAI,QAAQ,CA4HzC"}
|