@coasys/ad4m 0.13.1-staging.2 → 0.13.1-staging.3
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/lib/index.cjs +584 -203
- package/lib/index.js +581 -204
- package/lib/src/Ad4mClient.d.ts +7 -0
- package/lib/src/Ad4mClient.js +9 -0
- package/lib/src/apiClient.d.ts +13 -0
- package/lib/src/apiClient.js +67 -12
- package/lib/src/generated/api/AuthInfo.d.ts +4 -0
- package/lib/src/generated/api/RuntimeInfo.d.ts +5 -0
- package/lib/src/index.d.ts +1 -0
- package/lib/src/index.js +1 -0
- package/lib/src/model/Ad4mModel.js +45 -18
- package/lib/src/model/ModelQueryBuilder.d.ts +7 -3
- package/lib/src/model/ModelQueryBuilder.js +9 -4
- package/lib/src/model/query-common.js +7 -1
- package/lib/src/model/types.d.ts +45 -2
- package/lib/src/model/types.js +8 -0
- package/lib/src/perspectives/Container.d.ts +41 -0
- package/lib/src/perspectives/Container.js +62 -0
- package/lib/src/perspectives/PerspectiveProxy.d.ts +6 -3
- package/lib/src/perspectives/PerspectiveProxy.js +10 -4
- package/lib/src/perspectives/WakerSubscriptionManager.d.ts +94 -12
- package/lib/src/perspectives/WakerSubscriptionManager.js +273 -72
- package/lib/src/runtime/RuntimeTypes.d.ts +2 -0
- package/package.json +2 -2
- package/src/Ad4mClient.test.ts +1 -1
- package/src/Ad4mClient.ts +10 -0
- package/src/apiClient.test.ts +128 -2
- package/src/apiClient.ts +64 -11
- package/src/generated/api/AuthInfo.ts +6 -1
- package/src/generated/api/RuntimeInfo.ts +6 -1
- package/src/index.ts +1 -0
- package/src/model/Ad4mModel.ts +51 -19
- package/src/model/ModelQueryBuilder.ts +9 -6
- package/src/model/containment-scope.test.ts +104 -0
- package/src/model/query-common.ts +10 -1
- package/src/model/types.ts +56 -2
- package/src/perspectives/Container.test.ts +65 -0
- package/src/perspectives/Container.ts +46 -0
- package/src/perspectives/PerspectiveProxy.test.ts +11 -0
- package/src/perspectives/PerspectiveProxy.ts +10 -4
- package/src/perspectives/WakerSubscriptionManager.test.ts +398 -80
- package/src/perspectives/WakerSubscriptionManager.ts +318 -82
- package/src/runtime/RuntimeTypes.ts +2 -0
package/lib/index.cjs
CHANGED
|
@@ -141,7 +141,12 @@ function nextId() {
|
|
|
141
141
|
* for the next socket is safe for writes too. This covers an executor that
|
|
142
142
|
* is still binding its port (about 1.5 s with the reconnect backoff). */
|
|
143
143
|
const MAX_CONNECT_ATTEMPTS = 3;
|
|
144
|
-
const closedError = () => new RpcError(503, 'WebSocket connection closed');
|
|
144
|
+
const closedError = (reason) => new RpcError(503, reason || 'WebSocket connection closed');
|
|
145
|
+
/** Close code for "try again later": the executor's wallet is locked, so it cannot check the
|
|
146
|
+
* token yet. The token may be good: reconnect as for any close, and pass the reason on. */
|
|
147
|
+
const CLOSE_TRY_AGAIN_LATER = 1013;
|
|
148
|
+
/** Close code the executor uses when the socket's token opens no session, expired or was revoked. */
|
|
149
|
+
const CLOSE_AUTH_FAILED = 1008;
|
|
145
150
|
class ApiClient {
|
|
146
151
|
constructor(baseUrl, token, webSocketImpl, fetchImpl) {
|
|
147
152
|
// ── WebSocket ───────────────────────────────────────────────────────────
|
|
@@ -152,6 +157,10 @@ class ApiClient {
|
|
|
152
157
|
/** `on()` handlers by event type; a type with none has no entry. */
|
|
153
158
|
this._handlers = new Map();
|
|
154
159
|
this._reconnectCallbacks = new Set();
|
|
160
|
+
this._authFailedCallbacks = new Set();
|
|
161
|
+
/** Set once the executor refused the token: the reason. The client then
|
|
162
|
+
* never connects again; a new token needs a new client. */
|
|
163
|
+
this._authFailed = null;
|
|
155
164
|
this._hasConnectedOnce = false;
|
|
156
165
|
this._pendingCalls = new Map();
|
|
157
166
|
this._wsReconnectTimer = null;
|
|
@@ -187,6 +196,8 @@ class ApiClient {
|
|
|
187
196
|
_ensureWs() {
|
|
188
197
|
if (this._ws)
|
|
189
198
|
return;
|
|
199
|
+
if (this._authFailed !== null)
|
|
200
|
+
throw new RpcError(401, this._authFailed);
|
|
190
201
|
const WsImpl = this._webSocketImpl ?? globalThis.WebSocket;
|
|
191
202
|
const ws = new WsImpl(this._getWsUrl());
|
|
192
203
|
this._ws = ws;
|
|
@@ -195,9 +206,17 @@ class ApiClient {
|
|
|
195
206
|
resolve();
|
|
196
207
|
this._onOpen(ws);
|
|
197
208
|
};
|
|
198
|
-
ws.onclose = () => {
|
|
199
|
-
|
|
200
|
-
|
|
209
|
+
ws.onclose = (event) => {
|
|
210
|
+
// Classify the close for watchApplied() as for every other waiting call.
|
|
211
|
+
reject(event?.code === CLOSE_AUTH_FAILED
|
|
212
|
+
? new RpcError(401, event.reason || 'token expired or revoked')
|
|
213
|
+
: closedError(event?.code === CLOSE_TRY_AGAIN_LATER ? event.reason : undefined));
|
|
214
|
+
if (event?.code === CLOSE_AUTH_FAILED && this._ws === ws) {
|
|
215
|
+
this._failAuth(event.reason || 'token expired or revoked');
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
this._onClose(ws, event?.code === CLOSE_TRY_AGAIN_LATER ? event.reason : undefined);
|
|
219
|
+
}
|
|
201
220
|
};
|
|
202
221
|
});
|
|
203
222
|
// Only watchApplied() awaits this; a close before open is not an error otherwise.
|
|
@@ -217,10 +236,15 @@ class ApiClient {
|
|
|
217
236
|
if (!pending)
|
|
218
237
|
return; // late reply to a timed-out or aborted call, or a cancel ack
|
|
219
238
|
const error = parsed.error;
|
|
220
|
-
if (error)
|
|
221
|
-
pending.reject(new RpcError(error.code ?? 500, error.message ?? 'Unknown error'));
|
|
222
|
-
else
|
|
239
|
+
if (!error) {
|
|
223
240
|
pending.resolve(parsed.result);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const rpcError = new RpcError(error.code ?? 500, error.message ?? 'Unknown error');
|
|
244
|
+
pending.reject(rpcError);
|
|
245
|
+
// The executor answers 401 only when the token stopped working, then closes the socket.
|
|
246
|
+
if (rpcError.status === 401)
|
|
247
|
+
this._failAuth(rpcError.body);
|
|
224
248
|
return;
|
|
225
249
|
}
|
|
226
250
|
if (parsed.type === 'pong')
|
|
@@ -269,7 +293,8 @@ class ApiClient {
|
|
|
269
293
|
}
|
|
270
294
|
this._hasConnectedOnce = true;
|
|
271
295
|
}
|
|
272
|
-
|
|
296
|
+
/** `reason` is set when the executor asked to try again later; calls that fail carry it. */
|
|
297
|
+
_onClose(ws, reason) {
|
|
273
298
|
// A socket closed by _closeWs() can report after a new one exists.
|
|
274
299
|
if (this._ws !== ws)
|
|
275
300
|
return;
|
|
@@ -284,12 +309,25 @@ class ApiClient {
|
|
|
284
309
|
pending.retry = false;
|
|
285
310
|
}
|
|
286
311
|
else {
|
|
287
|
-
pending.reject(closedError());
|
|
312
|
+
pending.reject(closedError(reason));
|
|
288
313
|
}
|
|
289
314
|
}
|
|
290
315
|
if (this._handlers.size > 0 || this._pendingCalls.size > 0)
|
|
291
316
|
this._scheduleReconnect();
|
|
292
317
|
}
|
|
318
|
+
/** The executor refused the token: fail every call with 401, stop
|
|
319
|
+
* reconnecting and tell the `onAuthFailed` callbacks, once. */
|
|
320
|
+
_failAuth(reason) {
|
|
321
|
+
if (this._authFailed !== null)
|
|
322
|
+
return;
|
|
323
|
+
this._authFailed = reason;
|
|
324
|
+
const error = new RpcError(401, reason);
|
|
325
|
+
for (const pending of this._pendingCalls.values())
|
|
326
|
+
pending.reject(error);
|
|
327
|
+
this._closeWs();
|
|
328
|
+
for (const cb of [...this._authFailedCallbacks])
|
|
329
|
+
callSafely(cb, 'Error in auth-failed callback:', reason);
|
|
330
|
+
}
|
|
293
331
|
_startPing() {
|
|
294
332
|
this._stopPing();
|
|
295
333
|
this._wsPingTimer = setInterval(() => {
|
|
@@ -305,7 +343,7 @@ class ApiClient {
|
|
|
305
343
|
}
|
|
306
344
|
}
|
|
307
345
|
_scheduleReconnect() {
|
|
308
|
-
if (this._wsReconnectTimer)
|
|
346
|
+
if (this._wsReconnectTimer || this._authFailed !== null)
|
|
309
347
|
return;
|
|
310
348
|
const delay = this._wsReconnectDelay;
|
|
311
349
|
this._wsReconnectDelay = Math.min(this._wsReconnectDelay * 2, MAX_RECONNECT_DELAY_MS);
|
|
@@ -405,7 +443,9 @@ class ApiClient {
|
|
|
405
443
|
regs.add(reg);
|
|
406
444
|
this._scheduleWatch();
|
|
407
445
|
}
|
|
408
|
-
|
|
446
|
+
// A client whose token was refused keeps the handler but opens no socket.
|
|
447
|
+
if (this._authFailed === null)
|
|
448
|
+
this._ensureWs();
|
|
409
449
|
return () => {
|
|
410
450
|
const regs = this._handlers.get(type);
|
|
411
451
|
if (!regs?.delete(reg))
|
|
@@ -472,10 +512,13 @@ class ApiClient {
|
|
|
472
512
|
if (key === this._watching)
|
|
473
513
|
return;
|
|
474
514
|
this._watching = key;
|
|
475
|
-
|
|
515
|
+
const sent = this._request('events.watch', events).then(() => { this._watchRetries = 0; }, (e) => {
|
|
476
516
|
if (this._watching !== key)
|
|
477
517
|
return;
|
|
478
518
|
this._watching = null;
|
|
519
|
+
// A refused token (401) gets no next socket: watchApplied() must not resolve.
|
|
520
|
+
if (e instanceof RpcError && e.status === 401)
|
|
521
|
+
throw e;
|
|
479
522
|
// A closed socket (503) gets the watch again when the next one opens.
|
|
480
523
|
if (e instanceof RpcError && e.status === 503)
|
|
481
524
|
return;
|
|
@@ -487,6 +530,9 @@ class ApiClient {
|
|
|
487
530
|
}, WATCH_RETRY_DELAY_MS);
|
|
488
531
|
}
|
|
489
532
|
});
|
|
533
|
+
// Only watchApplied() awaits this; a refused watch is not an unhandled rejection otherwise.
|
|
534
|
+
sent.catch(() => { });
|
|
535
|
+
this._watchSent = sent;
|
|
490
536
|
}
|
|
491
537
|
_closeWs() {
|
|
492
538
|
this._stopPing();
|
|
@@ -510,6 +556,14 @@ class ApiClient {
|
|
|
510
556
|
this._reconnectCallbacks.add(callback);
|
|
511
557
|
return () => { this._reconnectCallbacks.delete(callback); };
|
|
512
558
|
}
|
|
559
|
+
/** Register a callback that fires once when the executor refuses this
|
|
560
|
+
* client's token: a 401 reply, or a socket closed with code 1008. Every
|
|
561
|
+
* call then fails with a 401 `RpcError` and the client does not reconnect;
|
|
562
|
+
* build a new client to use another token. Returns an unsubscribe function. */
|
|
563
|
+
onAuthFailed(callback) {
|
|
564
|
+
this._authFailedCallbacks.add(callback);
|
|
565
|
+
return () => { this._authFailedCallbacks.delete(callback); };
|
|
566
|
+
}
|
|
513
567
|
/** Close the WebSocket and reject pending calls. */
|
|
514
568
|
closeAll() {
|
|
515
569
|
for (const pending of this._pendingCalls.values()) {
|
|
@@ -518,6 +572,7 @@ class ApiClient {
|
|
|
518
572
|
this._closeWs();
|
|
519
573
|
this._handlers.clear();
|
|
520
574
|
this._reconnectCallbacks.clear();
|
|
575
|
+
this._authFailedCallbacks.clear();
|
|
521
576
|
// A reused client must not fire onReconnect on its next first open.
|
|
522
577
|
this._hasConnectedOnce = false;
|
|
523
578
|
}
|
|
@@ -7491,7 +7546,7 @@ function extractNamespaceFromUri(uri) {
|
|
|
7491
7546
|
return uri.substring(0, colonIdx + 1);
|
|
7492
7547
|
return uri;
|
|
7493
7548
|
}
|
|
7494
|
-
/** A live SPARQL query with its latest result.
|
|
7549
|
+
/** A live SPARQL or model query with its latest result.
|
|
7495
7550
|
*
|
|
7496
7551
|
* `subscribe()` opens the query and resolves once the first result is in;
|
|
7497
7552
|
* `onResult()` callbacks then get every later result. The executor sends
|
|
@@ -7505,14 +7560,20 @@ function extractNamespaceFromUri(uri) {
|
|
|
7505
7560
|
* ```
|
|
7506
7561
|
*/
|
|
7507
7562
|
class QuerySubscriptionProxy {
|
|
7508
|
-
|
|
7563
|
+
/** With `className`, `query` is a model query (JSON) over that class or
|
|
7564
|
+
* union of classes, opened with `modelSubscribe`; results are
|
|
7565
|
+
* `{ instances, totalCount }`. Without it, `query` is SPARQL. */
|
|
7566
|
+
constructor(uuid, query, client, className) {
|
|
7509
7567
|
_QuerySubscriptionProxy_instances.add(this);
|
|
7510
7568
|
_QuerySubscriptionProxy_live.set(this, void 0);
|
|
7511
7569
|
_QuerySubscriptionProxy_callbacks.set(this, new Set());
|
|
7512
7570
|
_QuerySubscriptionProxy_initialized.set(this, void 0);
|
|
7513
7571
|
_QuerySubscriptionProxy_initResolve.set(this, void 0);
|
|
7514
7572
|
_QuerySubscriptionProxy_initReject.set(this, void 0);
|
|
7515
|
-
|
|
7573
|
+
const open = className === undefined
|
|
7574
|
+
? () => client.subscribeQuery(uuid, query)
|
|
7575
|
+
: () => client.modelSubscribe(uuid, className, query);
|
|
7576
|
+
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_live, new LiveQuery(client, uuid, open, result => __classPrivateFieldGet$6(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_deliver).call(this, result)), "f");
|
|
7516
7577
|
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_initialized, new Promise((resolve, reject) => {
|
|
7517
7578
|
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_initResolve, resolve, "f");
|
|
7518
7579
|
__classPrivateFieldSet$6(this, _QuerySubscriptionProxy_initReject, reject, "f");
|
|
@@ -7934,7 +7995,7 @@ class PerspectiveProxy {
|
|
|
7934
7995
|
*
|
|
7935
7996
|
* The state is not stored on the graph: the engine derives it from the
|
|
7936
7997
|
* signed proposals and keeps what it derived per agent, outside the
|
|
7937
|
-
* perspective. So no other agent — a co-owner on the same
|
|
7998
|
+
* perspective. So no other agent — a co-owner on the same executor included —
|
|
7938
7999
|
* can read or write your entries, and a link query never sees them.
|
|
7939
8000
|
* `FlowInstance.findAll` / `start` call this for you.
|
|
7940
8001
|
*/
|
|
@@ -17454,6 +17515,14 @@ _AIClient_apiClient = new WeakMap(), _AIClient_transcriptionUnsubscribers = new
|
|
|
17454
17515
|
* (`query-utils.ts`, `decorators.ts`, etc.) can import types without
|
|
17455
17516
|
* creating circular runtime dependencies on `Ad4mModel.ts`.
|
|
17456
17517
|
*/
|
|
17518
|
+
/** Whether this traversal follows containment rather than a named predicate. */
|
|
17519
|
+
function isContainmentTraversal(scope) {
|
|
17520
|
+
return isTraverseScope(scope) && !('predicate' in scope && scope.predicate) && !('model' in scope && scope.model);
|
|
17521
|
+
}
|
|
17522
|
+
/** Whether this scope is the containment form, `{ id }` alone. */
|
|
17523
|
+
function isContainedScope(scope) {
|
|
17524
|
+
return !isTraverseScope(scope) && !('predicate' in scope) && !('model' in scope);
|
|
17525
|
+
}
|
|
17457
17526
|
/**
|
|
17458
17527
|
* Whether this scope is a traversal rather than a single named parent.
|
|
17459
17528
|
*
|
|
@@ -17499,6 +17568,12 @@ function resolveParentPredicate(parent, childCtor) {
|
|
|
17499
17568
|
// Raw form — explicit predicate
|
|
17500
17569
|
if ('predicate' in parent)
|
|
17501
17570
|
return parent.predicate;
|
|
17571
|
+
// Containment form — one predicate per containment edge, resolved by the
|
|
17572
|
+
// executor from the installed classes. There is no single one to return.
|
|
17573
|
+
if (isContainedScope(parent) || isContainmentTraversal(parent)) {
|
|
17574
|
+
throw new Error('parent(): a containment scope { id } names no single predicate; the executor resolves ' +
|
|
17575
|
+
'it. Use the model query path (findAll / query / subscribe) to read it.');
|
|
17576
|
+
}
|
|
17502
17577
|
// Model form — resolve from relation metadata
|
|
17503
17578
|
const { model } = parent;
|
|
17504
17579
|
const relMeta = getRelationsMetadata(model);
|
|
@@ -18624,9 +18699,10 @@ class ModelQueryBuilder {
|
|
|
18624
18699
|
* 3. **String id + model class** — same metadata scan (or field lookup if
|
|
18625
18700
|
* options include `field`).
|
|
18626
18701
|
* 4. **String id + string predicate** — raw escape hatch, no metadata lookup.
|
|
18627
|
-
*
|
|
18628
|
-
*
|
|
18629
|
-
*
|
|
18702
|
+
* 5. **String id alone** — containment through the built-in `Container`:
|
|
18703
|
+
* the id's `ad4m://has_child` targets, and the targets of the `children`
|
|
18704
|
+
* relation of every class the id is an instance of. The executor
|
|
18705
|
+
* resolves the predicates; nothing is looked up here.
|
|
18630
18706
|
*
|
|
18631
18707
|
* @param idOrInstance - The parent's expression URI **or** an Ad4mModel instance
|
|
18632
18708
|
* @param modelOrPredicate - A model class (predicate auto-resolved) **or** a raw predicate string
|
|
@@ -18649,6 +18725,9 @@ class ModelQueryBuilder {
|
|
|
18649
18725
|
*
|
|
18650
18726
|
* // String id + raw predicate (escape hatch)
|
|
18651
18727
|
* Recipe.query(perspective).parent(cookbookId, "cookbook://recipe").get();
|
|
18728
|
+
*
|
|
18729
|
+
* // String id alone: whatever cookbookId contains
|
|
18730
|
+
* Recipe.query(perspective).parent(cookbookId).get();
|
|
18652
18731
|
* ```
|
|
18653
18732
|
*/
|
|
18654
18733
|
parent(idOrInstance, modelOrPredicate, options) {
|
|
@@ -18676,7 +18755,8 @@ class ModelQueryBuilder {
|
|
|
18676
18755
|
this.queryParams.parent = { id, model: idOrInstance.constructor, ...(field && { field }) };
|
|
18677
18756
|
}
|
|
18678
18757
|
else {
|
|
18679
|
-
|
|
18758
|
+
// String id alone → containment form of Scope
|
|
18759
|
+
this.queryParams.parent = { id };
|
|
18680
18760
|
}
|
|
18681
18761
|
return this;
|
|
18682
18762
|
}
|
|
@@ -19475,6 +19555,24 @@ function jsonToModelInstance(ModelClass, perspective, json, include, properties)
|
|
|
19475
19555
|
}
|
|
19476
19556
|
return instance;
|
|
19477
19557
|
}
|
|
19558
|
+
/**
|
|
19559
|
+
* Put `childId` under `parent`. A containment scope `{ id }` writes through the
|
|
19560
|
+
* built-in `Container` (#1446): the executor runs the adder of the parent's own
|
|
19561
|
+
* `children` relation when its class has one (a block's `we://child`), else
|
|
19562
|
+
* writes `ad4m://has_child`. The other forms write their one predicate.
|
|
19563
|
+
*/
|
|
19564
|
+
async function linkToParent(perspective, parent, childCtor, childId, batchId) {
|
|
19565
|
+
if (isContainedScope(parent)) {
|
|
19566
|
+
await perspective.updateSubject("ad4m://Container", parent.id, { children: { action: "adder", value: [childId] } }, batchId);
|
|
19567
|
+
return;
|
|
19568
|
+
}
|
|
19569
|
+
const link = new Link({
|
|
19570
|
+
source: parent.id,
|
|
19571
|
+
predicate: resolveParentPredicate(parent, childCtor),
|
|
19572
|
+
target: childId,
|
|
19573
|
+
});
|
|
19574
|
+
await perspective.add(link, 'shared', batchId);
|
|
19575
|
+
}
|
|
19478
19576
|
/**
|
|
19479
19577
|
* Base class for defining data models in AD4M.
|
|
19480
19578
|
*
|
|
@@ -20132,7 +20230,28 @@ class Ad4mModel {
|
|
|
20132
20230
|
query = { ...query, include: { ...expanded, ...query.include } };
|
|
20133
20231
|
}
|
|
20134
20232
|
const queryInput = {};
|
|
20135
|
-
if (query.parent) {
|
|
20233
|
+
if (query.parent && isContainedScope(query.parent)) {
|
|
20234
|
+
// Containment: the executor resolves the predicates from the installed
|
|
20235
|
+
// classes, so only the id travels.
|
|
20236
|
+
queryInput.parent = { id: query.parent.id };
|
|
20237
|
+
}
|
|
20238
|
+
else if (query.parent && isContainmentTraversal(query.parent)) {
|
|
20239
|
+
// A traversal over containment: no predicate travels either.
|
|
20240
|
+
const t = query.parent;
|
|
20241
|
+
const traverse = { ids: t.ids };
|
|
20242
|
+
if (t.transitive !== undefined)
|
|
20243
|
+
traverse.transitive = t.transitive;
|
|
20244
|
+
if (t.direction !== undefined)
|
|
20245
|
+
traverse.direction = t.direction;
|
|
20246
|
+
if (t.limitPerAnchor !== undefined)
|
|
20247
|
+
traverse.limitPerAnchor = t.limitPerAnchor;
|
|
20248
|
+
if (t.levels !== undefined)
|
|
20249
|
+
traverse.levels = t.levels;
|
|
20250
|
+
if (t.maxDepth !== undefined)
|
|
20251
|
+
traverse.maxDepth = t.maxDepth;
|
|
20252
|
+
queryInput.parent = traverse;
|
|
20253
|
+
}
|
|
20254
|
+
else if (query.parent) {
|
|
20136
20255
|
const parentPredicate = resolveParentPredicate(query.parent, this);
|
|
20137
20256
|
// A traversal keeps its own shape on the wire: the executor reads `ids`,
|
|
20138
20257
|
// and flattening it to one `id` here is how a request for a whole level
|
|
@@ -20156,6 +20275,8 @@ class Ad4mModel {
|
|
|
20156
20275
|
traverse.limitPerAnchor = t.limitPerAnchor;
|
|
20157
20276
|
if (t.levels !== undefined)
|
|
20158
20277
|
traverse.levels = t.levels;
|
|
20278
|
+
if (t.maxDepth !== undefined)
|
|
20279
|
+
traverse.maxDepth = t.maxDepth;
|
|
20159
20280
|
queryInput.parent = traverse;
|
|
20160
20281
|
}
|
|
20161
20282
|
else {
|
|
@@ -21120,14 +21241,7 @@ class Ad4mModel {
|
|
|
21120
21241
|
if (options?.parent && !options?.batchId) {
|
|
21121
21242
|
const batchId = await perspective.createBatch();
|
|
21122
21243
|
await instance.save(batchId);
|
|
21123
|
-
|
|
21124
|
-
const predicate = resolveParentPredicate(parent, this);
|
|
21125
|
-
const link = new Link({
|
|
21126
|
-
source: parent.id,
|
|
21127
|
-
predicate,
|
|
21128
|
-
target: instance.id,
|
|
21129
|
-
});
|
|
21130
|
-
await perspective.add(link, 'shared', batchId);
|
|
21244
|
+
await linkToParent(perspective, requireSingleParent(options.parent), this, instance.id, batchId);
|
|
21131
21245
|
await perspective.commitBatch(batchId);
|
|
21132
21246
|
// Hydrate the instance now that the batch has been committed (mirrors the
|
|
21133
21247
|
// behaviour of save() when it manages its own batch).
|
|
@@ -21137,14 +21251,7 @@ class Ad4mModel {
|
|
|
21137
21251
|
await instance.save(options?.batchId);
|
|
21138
21252
|
// Create parent → child link if a parent scope was provided
|
|
21139
21253
|
if (options?.parent) {
|
|
21140
|
-
|
|
21141
|
-
const predicate = resolveParentPredicate(parent, this);
|
|
21142
|
-
const link = new Link({
|
|
21143
|
-
source: parent.id,
|
|
21144
|
-
predicate,
|
|
21145
|
-
target: instance.id,
|
|
21146
|
-
});
|
|
21147
|
-
await perspective.add(link, 'shared', options?.batchId);
|
|
21254
|
+
await linkToParent(perspective, requireSingleParent(options.parent), this, instance.id, options?.batchId);
|
|
21148
21255
|
}
|
|
21149
21256
|
return instance;
|
|
21150
21257
|
}
|
|
@@ -21551,6 +21658,15 @@ class Ad4mClient {
|
|
|
21551
21658
|
on(type, handler, filter) {
|
|
21552
21659
|
return __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f").on(type, handler, filter);
|
|
21553
21660
|
}
|
|
21661
|
+
/**
|
|
21662
|
+
* Call `callback` once when the executor refuses this client's token
|
|
21663
|
+
* (expired, revoked, or no session). Every call then fails with a 401
|
|
21664
|
+
* `RpcError` and the client stops reconnecting: log in again and build a
|
|
21665
|
+
* new client. Returns a function that removes the callback.
|
|
21666
|
+
*/
|
|
21667
|
+
onAuthFailed(callback) {
|
|
21668
|
+
return __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f").onAuthFailed(callback);
|
|
21669
|
+
}
|
|
21554
21670
|
/** Close all event connections and clear in-memory caches */
|
|
21555
21671
|
close() {
|
|
21556
21672
|
__classPrivateFieldGet$1(this, _Ad4mClient_agentClient, "f").clearByDidCache();
|
|
@@ -21702,13 +21818,13 @@ class LanguageLanguageInput {
|
|
|
21702
21818
|
* const runs = await InterpretationRun.findAll(perspective);
|
|
21703
21819
|
* const configs = await AutoProcessorConfig.findAll(perspective);
|
|
21704
21820
|
*/
|
|
21705
|
-
var __decorate$
|
|
21821
|
+
var __decorate$3 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
21706
21822
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
21707
21823
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21708
21824
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
21709
21825
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
21710
21826
|
};
|
|
21711
|
-
var __metadata$
|
|
21827
|
+
var __metadata$3 = (undefined && undefined.__metadata) || function (k, v) {
|
|
21712
21828
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
21713
21829
|
};
|
|
21714
21830
|
// ── AutoProcessorConfig ─────────────────────────────────────────────────────
|
|
@@ -21749,71 +21865,71 @@ exports.AutoProcessorConfig = class AutoProcessorConfig extends Ad4mModel {
|
|
|
21749
21865
|
// `batchMax` + `claimTtlMs` — the Rust SDNA takes the same shape.
|
|
21750
21866
|
}
|
|
21751
21867
|
};
|
|
21752
|
-
__decorate$
|
|
21868
|
+
__decorate$3([
|
|
21753
21869
|
Property({ through: "ad4m://processor_id", required: true, identity: true }),
|
|
21754
|
-
__metadata$
|
|
21870
|
+
__metadata$3("design:type", String)
|
|
21755
21871
|
], exports.AutoProcessorConfig.prototype, "processorId", void 0);
|
|
21756
|
-
__decorate$
|
|
21872
|
+
__decorate$3([
|
|
21757
21873
|
Property({ through: "ad4m://source_scope_query", required: true }),
|
|
21758
|
-
__metadata$
|
|
21874
|
+
__metadata$3("design:type", String)
|
|
21759
21875
|
], exports.AutoProcessorConfig.prototype, "sourceScopeQuery", void 0);
|
|
21760
|
-
__decorate$
|
|
21876
|
+
__decorate$3([
|
|
21761
21877
|
Optional({ through: "ad4m://base_prefix" }),
|
|
21762
|
-
__metadata$
|
|
21878
|
+
__metadata$3("design:type", String)
|
|
21763
21879
|
], exports.AutoProcessorConfig.prototype, "basePrefix", void 0);
|
|
21764
|
-
__decorate$
|
|
21880
|
+
__decorate$3([
|
|
21765
21881
|
HasMany({ through: "ad4m://interpretation_class", datatype: "xsd:string" }),
|
|
21766
|
-
__metadata$
|
|
21882
|
+
__metadata$3("design:type", Array)
|
|
21767
21883
|
], exports.AutoProcessorConfig.prototype, "interpretationClasses", void 0);
|
|
21768
|
-
__decorate$
|
|
21884
|
+
__decorate$3([
|
|
21769
21885
|
HasMany({ through: "ad4m://flow", datatype: "xsd:string" }),
|
|
21770
|
-
__metadata$
|
|
21886
|
+
__metadata$3("design:type", Array)
|
|
21771
21887
|
], exports.AutoProcessorConfig.prototype, "flows", void 0);
|
|
21772
|
-
__decorate$
|
|
21888
|
+
__decorate$3([
|
|
21773
21889
|
Property({ through: "ad4m://debounce_ms", required: true }),
|
|
21774
|
-
__metadata$
|
|
21890
|
+
__metadata$3("design:type", String)
|
|
21775
21891
|
], exports.AutoProcessorConfig.prototype, "debounceMs", void 0);
|
|
21776
|
-
__decorate$
|
|
21892
|
+
__decorate$3([
|
|
21777
21893
|
Optional({ through: "ad4m://batch_min" }),
|
|
21778
|
-
__metadata$
|
|
21894
|
+
__metadata$3("design:type", String)
|
|
21779
21895
|
], exports.AutoProcessorConfig.prototype, "batchMin", void 0);
|
|
21780
|
-
__decorate$
|
|
21896
|
+
__decorate$3([
|
|
21781
21897
|
Property({ through: "ad4m://batch_max", required: true }),
|
|
21782
|
-
__metadata$
|
|
21898
|
+
__metadata$3("design:type", String)
|
|
21783
21899
|
], exports.AutoProcessorConfig.prototype, "batchMax", void 0);
|
|
21784
|
-
__decorate$
|
|
21900
|
+
__decorate$3([
|
|
21785
21901
|
Optional({ through: "ad4m://max_wait_ms" }),
|
|
21786
|
-
__metadata$
|
|
21902
|
+
__metadata$3("design:type", String)
|
|
21787
21903
|
], exports.AutoProcessorConfig.prototype, "maxWaitMs", void 0);
|
|
21788
|
-
__decorate$
|
|
21904
|
+
__decorate$3([
|
|
21789
21905
|
Property({ through: "ad4m://claim_ttl_ms", required: true }),
|
|
21790
|
-
__metadata$
|
|
21906
|
+
__metadata$3("design:type", String)
|
|
21791
21907
|
], exports.AutoProcessorConfig.prototype, "claimTtlMs", void 0);
|
|
21792
|
-
__decorate$
|
|
21908
|
+
__decorate$3([
|
|
21793
21909
|
Optional({ through: "ad4m://source_window_ms" }),
|
|
21794
|
-
__metadata$
|
|
21910
|
+
__metadata$3("design:type", String)
|
|
21795
21911
|
], exports.AutoProcessorConfig.prototype, "sourceWindowMs", void 0);
|
|
21796
|
-
__decorate$
|
|
21912
|
+
__decorate$3([
|
|
21797
21913
|
Optional({ through: "ad4m://dedup_strategy" }),
|
|
21798
|
-
__metadata$
|
|
21914
|
+
__metadata$3("design:type", String)
|
|
21799
21915
|
], exports.AutoProcessorConfig.prototype, "dedupStrategy", void 0);
|
|
21800
|
-
__decorate$
|
|
21916
|
+
__decorate$3([
|
|
21801
21917
|
Optional({ through: "ad4m://existing_scope" }),
|
|
21802
|
-
__metadata$
|
|
21918
|
+
__metadata$3("design:type", String)
|
|
21803
21919
|
], exports.AutoProcessorConfig.prototype, "existingScope", void 0);
|
|
21804
|
-
__decorate$
|
|
21920
|
+
__decorate$3([
|
|
21805
21921
|
Optional({ through: "ad4m://mint_scope" }),
|
|
21806
|
-
__metadata$
|
|
21922
|
+
__metadata$3("design:type", String)
|
|
21807
21923
|
], exports.AutoProcessorConfig.prototype, "mintScope", void 0);
|
|
21808
|
-
__decorate$
|
|
21924
|
+
__decorate$3([
|
|
21809
21925
|
Optional({ through: "ad4m://max_tool_calls" }),
|
|
21810
|
-
__metadata$
|
|
21926
|
+
__metadata$3("design:type", String)
|
|
21811
21927
|
], exports.AutoProcessorConfig.prototype, "maxToolCalls", void 0);
|
|
21812
|
-
__decorate$
|
|
21928
|
+
__decorate$3([
|
|
21813
21929
|
Optional({ through: "ad4m://emit_debug_events", resolveLanguage: "literal" }),
|
|
21814
|
-
__metadata$
|
|
21930
|
+
__metadata$3("design:type", String)
|
|
21815
21931
|
], exports.AutoProcessorConfig.prototype, "emitDebugEvents", void 0);
|
|
21816
|
-
exports.AutoProcessorConfig = __decorate$
|
|
21932
|
+
exports.AutoProcessorConfig = __decorate$3([
|
|
21817
21933
|
Model$1({ name: "AutoProcessor" })
|
|
21818
21934
|
], exports.AutoProcessorConfig);
|
|
21819
21935
|
// ── InterpretationRun ───────────────────────────────────────────────────────
|
|
@@ -21837,39 +21953,39 @@ exports.InterpretationRun = class InterpretationRun extends Ad4mModel {
|
|
|
21837
21953
|
this.sources = [];
|
|
21838
21954
|
}
|
|
21839
21955
|
};
|
|
21840
|
-
__decorate$
|
|
21956
|
+
__decorate$3([
|
|
21841
21957
|
Property({ through: "ad4m://interp/run_id", required: true, identity: true }),
|
|
21842
|
-
__metadata$
|
|
21958
|
+
__metadata$3("design:type", String)
|
|
21843
21959
|
], exports.InterpretationRun.prototype, "runId", void 0);
|
|
21844
|
-
__decorate$
|
|
21960
|
+
__decorate$3([
|
|
21845
21961
|
Optional({ through: "ad4m://interp/model" }),
|
|
21846
|
-
__metadata$
|
|
21962
|
+
__metadata$3("design:type", String)
|
|
21847
21963
|
], exports.InterpretationRun.prototype, "model", void 0);
|
|
21848
|
-
__decorate$
|
|
21964
|
+
__decorate$3([
|
|
21849
21965
|
Optional({ through: "ad4m://interp/prompt_version" }),
|
|
21850
|
-
__metadata$
|
|
21966
|
+
__metadata$3("design:type", String)
|
|
21851
21967
|
], exports.InterpretationRun.prototype, "promptVersion", void 0);
|
|
21852
|
-
__decorate$
|
|
21968
|
+
__decorate$3([
|
|
21853
21969
|
Optional({ through: "ad4m://interp/ran_at" }),
|
|
21854
|
-
__metadata$
|
|
21970
|
+
__metadata$3("design:type", String)
|
|
21855
21971
|
], exports.InterpretationRun.prototype, "ranAt", void 0);
|
|
21856
|
-
__decorate$
|
|
21972
|
+
__decorate$3([
|
|
21857
21973
|
Optional({ through: "ad4m://interp/processor" }),
|
|
21858
|
-
__metadata$
|
|
21974
|
+
__metadata$3("design:type", String)
|
|
21859
21975
|
], exports.InterpretationRun.prototype, "processor", void 0);
|
|
21860
|
-
__decorate$
|
|
21976
|
+
__decorate$3([
|
|
21861
21977
|
HasMany({ through: "ad4m://interp/sources", datatype: "xsd:string" }),
|
|
21862
|
-
__metadata$
|
|
21978
|
+
__metadata$3("design:type", Array)
|
|
21863
21979
|
], exports.InterpretationRun.prototype, "sources", void 0);
|
|
21864
|
-
__decorate$
|
|
21980
|
+
__decorate$3([
|
|
21865
21981
|
Optional({ through: "ad4m://interp/debug_prompt", resolveLanguage: "literal" }),
|
|
21866
|
-
__metadata$
|
|
21982
|
+
__metadata$3("design:type", String)
|
|
21867
21983
|
], exports.InterpretationRun.prototype, "debugPrompt", void 0);
|
|
21868
|
-
__decorate$
|
|
21984
|
+
__decorate$3([
|
|
21869
21985
|
Optional({ through: "ad4m://interp/debug_response", resolveLanguage: "literal" }),
|
|
21870
|
-
__metadata$
|
|
21986
|
+
__metadata$3("design:type", String)
|
|
21871
21987
|
], exports.InterpretationRun.prototype, "debugResponse", void 0);
|
|
21872
|
-
exports.InterpretationRun = __decorate$
|
|
21988
|
+
exports.InterpretationRun = __decorate$3([
|
|
21873
21989
|
Model$1({ name: "InterpretationRun" })
|
|
21874
21990
|
], exports.InterpretationRun);
|
|
21875
21991
|
// ── InterpretationOverlay ───────────────────────────────────────────────────
|
|
@@ -21899,15 +22015,15 @@ exports.InterpretationOverlay = class InterpretationOverlay extends Ad4mModel {
|
|
|
21899
22015
|
this.kind = "";
|
|
21900
22016
|
}
|
|
21901
22017
|
};
|
|
21902
|
-
__decorate$
|
|
22018
|
+
__decorate$3([
|
|
21903
22019
|
Property({ through: "ad4m://interp/kind", required: true }),
|
|
21904
|
-
__metadata$
|
|
22020
|
+
__metadata$3("design:type", String)
|
|
21905
22021
|
], exports.InterpretationOverlay.prototype, "kind", void 0);
|
|
21906
|
-
__decorate$
|
|
22022
|
+
__decorate$3([
|
|
21907
22023
|
Optional({ through: "ad4m://interp/run" }),
|
|
21908
|
-
__metadata$
|
|
22024
|
+
__metadata$3("design:type", String)
|
|
21909
22025
|
], exports.InterpretationOverlay.prototype, "run", void 0);
|
|
21910
|
-
exports.InterpretationOverlay = __decorate$
|
|
22026
|
+
exports.InterpretationOverlay = __decorate$3([
|
|
21911
22027
|
Model$1({ name: "InterpretationOverlay" })
|
|
21912
22028
|
], exports.InterpretationOverlay);
|
|
21913
22029
|
|
|
@@ -21931,13 +22047,13 @@ exports.InterpretationOverlay = __decorate$2([
|
|
|
21931
22047
|
* - the SDNA-parity test locks TS/Rust drift against
|
|
21932
22048
|
* `rust-executor/src/perspectives/hardwired_sdna/flow_transition_proposal.json`.
|
|
21933
22049
|
*/
|
|
21934
|
-
var __decorate$
|
|
22050
|
+
var __decorate$2 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
21935
22051
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
21936
22052
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21937
22053
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
21938
22054
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
21939
22055
|
};
|
|
21940
|
-
var __metadata$
|
|
22056
|
+
var __metadata$2 = (undefined && undefined.__metadata) || function (k, v) {
|
|
21941
22057
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
21942
22058
|
};
|
|
21943
22059
|
/**
|
|
@@ -22044,55 +22160,55 @@ exports.FlowTransitionProposal = class FlowTransitionProposal extends Ad4mModel
|
|
|
22044
22160
|
// of the proposal's own links (all written together during create_subject).
|
|
22045
22161
|
}
|
|
22046
22162
|
};
|
|
22047
|
-
__decorate$
|
|
22163
|
+
__decorate$2([
|
|
22048
22164
|
Property({ through: "ad4m://flow/instance", required: true, identity: true }),
|
|
22049
|
-
__metadata$
|
|
22165
|
+
__metadata$2("design:type", String)
|
|
22050
22166
|
], exports.FlowTransitionProposal.prototype, "flowInstance", void 0);
|
|
22051
|
-
__decorate$
|
|
22167
|
+
__decorate$2([
|
|
22052
22168
|
Property({ through: "ad4m://flow/from_state", required: true }),
|
|
22053
|
-
__metadata$
|
|
22169
|
+
__metadata$2("design:type", String)
|
|
22054
22170
|
], exports.FlowTransitionProposal.prototype, "fromState", void 0);
|
|
22055
|
-
__decorate$
|
|
22171
|
+
__decorate$2([
|
|
22056
22172
|
Property({ through: "ad4m://flow/to_state", required: true }),
|
|
22057
|
-
__metadata$
|
|
22173
|
+
__metadata$2("design:type", String)
|
|
22058
22174
|
], exports.FlowTransitionProposal.prototype, "toState", void 0);
|
|
22059
|
-
__decorate$
|
|
22175
|
+
__decorate$2([
|
|
22060
22176
|
Property({ through: "ad4m://flow/proposer", required: true, getter: PROPOSER_GETTER, datatype: "xsd:string" }),
|
|
22061
|
-
__metadata$
|
|
22177
|
+
__metadata$2("design:type", String)
|
|
22062
22178
|
], exports.FlowTransitionProposal.prototype, "proposer", void 0);
|
|
22063
|
-
__decorate$
|
|
22179
|
+
__decorate$2([
|
|
22064
22180
|
HasMany({ through: "ad4m://flow/evidence", datatype: "xsd:string" }),
|
|
22065
|
-
__metadata$
|
|
22181
|
+
__metadata$2("design:type", Array)
|
|
22066
22182
|
], exports.FlowTransitionProposal.prototype, "evidence", void 0);
|
|
22067
|
-
__decorate$
|
|
22183
|
+
__decorate$2([
|
|
22068
22184
|
Property({ through: "ad4m://flow/evidence_hashes", required: true }),
|
|
22069
|
-
__metadata$
|
|
22185
|
+
__metadata$2("design:type", String)
|
|
22070
22186
|
], exports.FlowTransitionProposal.prototype, "evidenceHashes", void 0);
|
|
22071
|
-
__decorate$
|
|
22187
|
+
__decorate$2([
|
|
22072
22188
|
HasMany({ through: "ad4m://flow/output", datatype: "xsd:string" }),
|
|
22073
|
-
__metadata$
|
|
22189
|
+
__metadata$2("design:type", Array)
|
|
22074
22190
|
], exports.FlowTransitionProposal.prototype, "outputs", void 0);
|
|
22075
|
-
__decorate$
|
|
22191
|
+
__decorate$2([
|
|
22076
22192
|
Property({ through: "ad4m://flow/outputs_hash" }),
|
|
22077
|
-
__metadata$
|
|
22193
|
+
__metadata$2("design:type", String)
|
|
22078
22194
|
], exports.FlowTransitionProposal.prototype, "outputsHash", void 0);
|
|
22079
|
-
__decorate$
|
|
22195
|
+
__decorate$2([
|
|
22080
22196
|
Property({ through: "ad4m://flow/nonce" }),
|
|
22081
|
-
__metadata$
|
|
22197
|
+
__metadata$2("design:type", String)
|
|
22082
22198
|
], exports.FlowTransitionProposal.prototype, "nonce", void 0);
|
|
22083
|
-
__decorate$
|
|
22199
|
+
__decorate$2([
|
|
22084
22200
|
Optional({ through: "ad4m://flow/run_uri" }),
|
|
22085
|
-
__metadata$
|
|
22201
|
+
__metadata$2("design:type", String)
|
|
22086
22202
|
], exports.FlowTransitionProposal.prototype, "runUri", void 0);
|
|
22087
|
-
__decorate$
|
|
22203
|
+
__decorate$2([
|
|
22088
22204
|
Optional({ through: "ad4m://flow/rationale" }),
|
|
22089
|
-
__metadata$
|
|
22205
|
+
__metadata$2("design:type", String)
|
|
22090
22206
|
], exports.FlowTransitionProposal.prototype, "rationale", void 0);
|
|
22091
|
-
__decorate$
|
|
22207
|
+
__decorate$2([
|
|
22092
22208
|
HasMany({ through: "ad4m://acceptedBy", getter: ACCEPTED_BY_GETTER, readOnly: true }),
|
|
22093
|
-
__metadata$
|
|
22209
|
+
__metadata$2("design:type", Array)
|
|
22094
22210
|
], exports.FlowTransitionProposal.prototype, "acceptedBy", void 0);
|
|
22095
|
-
exports.FlowTransitionProposal = __decorate$
|
|
22211
|
+
exports.FlowTransitionProposal = __decorate$2([
|
|
22096
22212
|
Model$1({ name: "FlowTransitionProposal" })
|
|
22097
22213
|
], exports.FlowTransitionProposal);
|
|
22098
22214
|
// ── FlowInstanceRecord ──────────────────────────────────────────────────────
|
|
@@ -22152,25 +22268,25 @@ exports.FlowInstanceRecord = class FlowInstanceRecord extends Ad4mModel {
|
|
|
22152
22268
|
// of the instance's own links (all written together during `mint_flow_instance`).
|
|
22153
22269
|
}
|
|
22154
22270
|
};
|
|
22155
|
-
__decorate$
|
|
22271
|
+
__decorate$2([
|
|
22156
22272
|
Property({ through: "ad4m://flow/flow_uri", required: true, identity: true }),
|
|
22157
|
-
__metadata$
|
|
22273
|
+
__metadata$2("design:type", String)
|
|
22158
22274
|
], exports.FlowInstanceRecord.prototype, "flowUri", void 0);
|
|
22159
|
-
__decorate$
|
|
22275
|
+
__decorate$2([
|
|
22160
22276
|
Property({ through: "ad4m://flow/base", required: true }),
|
|
22161
|
-
__metadata$
|
|
22277
|
+
__metadata$2("design:type", String)
|
|
22162
22278
|
], exports.FlowInstanceRecord.prototype, "subject", void 0);
|
|
22163
|
-
exports.FlowInstanceRecord = __decorate$
|
|
22279
|
+
exports.FlowInstanceRecord = __decorate$2([
|
|
22164
22280
|
Model$1({ name: "FlowInstance" })
|
|
22165
22281
|
], exports.FlowInstanceRecord);
|
|
22166
22282
|
|
|
22167
|
-
var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
22283
|
+
var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
22168
22284
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
22169
22285
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
22170
22286
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22171
22287
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22172
22288
|
};
|
|
22173
|
-
var __metadata = (undefined && undefined.__metadata) || function (k, v) {
|
|
22289
|
+
var __metadata$1 = (undefined && undefined.__metadata) || function (k, v) {
|
|
22174
22290
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22175
22291
|
};
|
|
22176
22292
|
/**
|
|
@@ -22206,14 +22322,74 @@ exports.TextContent = class TextContent extends Ad4mModel {
|
|
|
22206
22322
|
};
|
|
22207
22323
|
/** The URI the executor reads it by. */
|
|
22208
22324
|
exports.TextContent.builtinUri = "ad4m://TextContent";
|
|
22209
|
-
__decorate([
|
|
22325
|
+
__decorate$1([
|
|
22210
22326
|
Property({ through: "ad4m://text" }),
|
|
22211
|
-
__metadata("design:type", String)
|
|
22327
|
+
__metadata$1("design:type", String)
|
|
22212
22328
|
], exports.TextContent.prototype, "text", void 0);
|
|
22213
|
-
exports.TextContent = __decorate([
|
|
22329
|
+
exports.TextContent = __decorate$1([
|
|
22214
22330
|
Model$1({ name: "TextContent", abstract: true })
|
|
22215
22331
|
], exports.TextContent);
|
|
22216
22332
|
|
|
22333
|
+
var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
22334
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
22335
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
22336
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22337
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22338
|
+
};
|
|
22339
|
+
var __metadata = (undefined && undefined.__metadata) || function (k, v) {
|
|
22340
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22341
|
+
};
|
|
22342
|
+
/**
|
|
22343
|
+
* The built-in abstract class `Container { children }` (#1446): what holds
|
|
22344
|
+
* other records — a channel, a thread, a post, a call, a document, a board.
|
|
22345
|
+
*
|
|
22346
|
+
* X is contained in P when `P ad4m://has_child X` exists, whatever P is (an
|
|
22347
|
+
* instance of any class, or a node no class describes, such as
|
|
22348
|
+
* `ad4m://self`), or when P is an instance of a class whose `children`
|
|
22349
|
+
* relation (by name, or aliased to `children`) links X:
|
|
22350
|
+
*
|
|
22351
|
+
* ```typescript
|
|
22352
|
+
* @Model({ name: "Block", implements: [Container] })
|
|
22353
|
+
* class Block extends Ad4mModel {
|
|
22354
|
+
* @HasMany({ through: "we://child", alias: { Container: "children" } })
|
|
22355
|
+
* blocks: string[] = [];
|
|
22356
|
+
* }
|
|
22357
|
+
*
|
|
22358
|
+
* // Messages held by P, through has_child or a Block's we://child:
|
|
22359
|
+
* await Message.findAll(perspective, { parent: { id: P } });
|
|
22360
|
+
* // Everything that holds X:
|
|
22361
|
+
* await Container.findAll(perspective, { parent: { ids: [X], direction: "in" } });
|
|
22362
|
+
* ```
|
|
22363
|
+
*
|
|
22364
|
+
* A row's `children` is everything it holds, merged across its classes. A
|
|
22365
|
+
* node no class describes is a row of its own when it holds something by
|
|
22366
|
+
* `has_child`. Always scope a `Container` query (`where: { id }`, a
|
|
22367
|
+
* `children` filter or `parent`): unscoped, it reads every holder in the
|
|
22368
|
+
* perspective.
|
|
22369
|
+
*
|
|
22370
|
+
* Built in: the executor declares it (mirrors
|
|
22371
|
+
* `rust-executor/src/perspectives/hardwired_sdna/container.json`) and reads
|
|
22372
|
+
* it by its URI, `ad4m://Container`, so a perspective never stores it and an
|
|
22373
|
+
* app class named `Container` does not replace it. `register()` on it writes
|
|
22374
|
+
* nothing.
|
|
22375
|
+
*/
|
|
22376
|
+
exports.Container = class Container extends Ad4mModel {
|
|
22377
|
+
constructor() {
|
|
22378
|
+
super(...arguments);
|
|
22379
|
+
/** What it holds, whatever their class. */
|
|
22380
|
+
this.children = [];
|
|
22381
|
+
}
|
|
22382
|
+
};
|
|
22383
|
+
/** The URI the executor reads it by. */
|
|
22384
|
+
exports.Container.builtinUri = "ad4m://Container";
|
|
22385
|
+
__decorate([
|
|
22386
|
+
HasMany({ through: "ad4m://has_child" }),
|
|
22387
|
+
__metadata("design:type", Array)
|
|
22388
|
+
], exports.Container.prototype, "children", void 0);
|
|
22389
|
+
exports.Container = __decorate([
|
|
22390
|
+
Model$1({ name: "Container", abstract: true })
|
|
22391
|
+
], exports.Container);
|
|
22392
|
+
|
|
22217
22393
|
/**
|
|
22218
22394
|
* `FlowInstance` — object-oriented wrapper for a running flow.
|
|
22219
22395
|
*
|
|
@@ -22802,6 +22978,107 @@ function parseLitBoolean(val) {
|
|
|
22802
22978
|
* module (`plugins/ad4m/wakerSubscriptionManager.ts`) rather than carrying its
|
|
22803
22979
|
* own copy. Any behaviour change belongs here.
|
|
22804
22980
|
*/
|
|
22981
|
+
/** A letter, combining mark, digit or underscore: what a term must not touch. */
|
|
22982
|
+
const WORD_CHAR = "[\\p{L}\\p{M}\\p{N}_]";
|
|
22983
|
+
/**
|
|
22984
|
+
* The elements a message's HTML is made of. A `<` before any other name is text:
|
|
22985
|
+
* We stores plain text, where "<hey Data> can you look" is words.
|
|
22986
|
+
*/
|
|
22987
|
+
const ELEMENT = "a|abbr|b|bdi|bdo|blockquote|br|caption|center|cite|code|col|colgroup|dd|del|details|dfn|div|dl|dt|em|" +
|
|
22988
|
+
"figcaption|figure|font|h[1-6]|hr|i|img|ins|kbd|label|li|mark|ol|p|pre|q|s|samp|section|article|small|" +
|
|
22989
|
+
"span|strike|strong|sub|summary|sup|table|tbody|td|tfoot|th|thead|time|tr|u|ul|var|wbr|script|style";
|
|
22990
|
+
/** An attribute: a name, then optionally `=` and a quoted value (which may hold `>`) or an unquoted one. */
|
|
22991
|
+
const ATTRIBUTE = `\\s+[A-Za-z_:][-\\w:.]*(?:\\s*=\\s*(?:"[^"]*"|'[^']*'|[^\\s"'=<>\`]+))?`;
|
|
22992
|
+
/**
|
|
22993
|
+
* Markup: a comment, a `<script>`/`<style>` element with its contents, or a tag of
|
|
22994
|
+
* a known element whose rest is a valid attribute list. "a < b" and
|
|
22995
|
+
* "if a <b then ask Data, else c -> d" are text: the comma is no attribute.
|
|
22996
|
+
*/
|
|
22997
|
+
const TAG = new RegExp(`<!--[\\s\\S]*?-->` +
|
|
22998
|
+
`|<(script|style)(?=[\\s/>])(?:${ATTRIBUTE})*\\s*>[\\s\\S]*?<\\/\\1\\s*>` +
|
|
22999
|
+
`|<(?:${ELEMENT})(?=[\\s/>])(?:${ATTRIBUTE})*\\s*\\/?>` +
|
|
23000
|
+
`|<\\/(?:${ELEMENT})\\s*>`, "gi");
|
|
23001
|
+
/** Tags that break a line: replaced by a space, so `<p>hi</p><p>Data</p>` keeps "Data" a word. */
|
|
23002
|
+
const BREAKING_TAG = /^<\/?(?:p|div|br|hr|li|ul|ol|h[1-6]|blockquote|pre|tr|td|th|table|section|article)\b/i;
|
|
23003
|
+
/**
|
|
23004
|
+
* The attributes a mention puts its target's DID in: Flux's `<a data-type="mention"
|
|
23005
|
+
* href="did:…">`, older Flux messages' `<span data-id="did:…">`, and We's editor chip
|
|
23006
|
+
* `<span class="we-mention" data-did="did:…">`.
|
|
23007
|
+
*/
|
|
23008
|
+
const ATTRIBUTES = new RegExp(ATTRIBUTE, "g");
|
|
23009
|
+
const MENTION_TARGET = /^\s+(?:href|data-id|data-did)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+))$/i;
|
|
23010
|
+
/**
|
|
23011
|
+
* How much of a record's text the word check reads. Dropping markup costs time
|
|
23012
|
+
* quadratic in a run of unclosed `<script>`, `<style>` or `<!--` openers, so a
|
|
23013
|
+
* very long text could hold the event loop for seconds, and a row that holds
|
|
23014
|
+
* no term is checked again on every result while it is in the window. A term
|
|
23015
|
+
* past this many characters does not wake.
|
|
23016
|
+
*/
|
|
23017
|
+
const MENTION_TEXT_LIMIT = 16384;
|
|
23018
|
+
const ENTITIES = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'", nbsp: " " };
|
|
23019
|
+
function decodeEntities(s) {
|
|
23020
|
+
return s.replace(/&(#x[0-9a-f]+|#[0-9]+|[a-z]+);/gi, (whole, ref) => {
|
|
23021
|
+
if (ref[0] !== "#")
|
|
23022
|
+
return ENTITIES[ref.toLowerCase()] ?? whole;
|
|
23023
|
+
const code = ref[1] === "x" || ref[1] === "X" ? parseInt(ref.slice(2), 16) : parseInt(ref.slice(1), 10);
|
|
23024
|
+
return code > 0 && code <= 0x10ffff ? String.fromCodePoint(code) : whole;
|
|
23025
|
+
});
|
|
23026
|
+
}
|
|
23027
|
+
/**
|
|
23028
|
+
* What a reader sees of `text`, and the DIDs its mentions point at. `text` may be
|
|
23029
|
+
* HTML (TextContent allows it): tag names and attributes are markup, not words, so
|
|
23030
|
+
* a bot named "Data" must not wake on `data-type="mention"` in a mention of
|
|
23031
|
+
* someone else. Plain text passes through unchanged, apart from entities.
|
|
23032
|
+
*/
|
|
23033
|
+
function readableParts(text) {
|
|
23034
|
+
const targets = [];
|
|
23035
|
+
const visible = text.replace(TAG, (tag, scriptOrStyle) => {
|
|
23036
|
+
if (scriptOrStyle)
|
|
23037
|
+
return " ";
|
|
23038
|
+
if (tag.startsWith("<!--"))
|
|
23039
|
+
return "";
|
|
23040
|
+
// Parse complete attributes first: a DID-shaped string inside `title`
|
|
23041
|
+
// is not a target attribute and must not wake an agent.
|
|
23042
|
+
for (const attribute of tag.matchAll(ATTRIBUTES)) {
|
|
23043
|
+
const target = MENTION_TARGET.exec(attribute[0]);
|
|
23044
|
+
if (target)
|
|
23045
|
+
targets.push(decodeEntities(target[1] ?? target[2] ?? target[3]));
|
|
23046
|
+
}
|
|
23047
|
+
return BREAKING_TAG.test(tag) ? " " : "";
|
|
23048
|
+
});
|
|
23049
|
+
return { visible: decodeEntities(visible), targets };
|
|
23050
|
+
}
|
|
23051
|
+
/**
|
|
23052
|
+
* Whether `text` holds one of `terms` as a whole word, case-insensitively:
|
|
23053
|
+
* "Data" is in "hi Data!", "@data" and "Data's turn", not in "metadata" or
|
|
23054
|
+
* "database". A term is matched literally (regex characters, quotes) and must
|
|
23055
|
+
* not touch a letter, mark, digit or underscore on either side, so a name
|
|
23056
|
+
* that starts or ends with punctuation still matches. Same rule as #1459's
|
|
23057
|
+
* SPARQL `(?:^|\W)term(?:\W|$)`.
|
|
23058
|
+
*
|
|
23059
|
+
* The rule runs on the visible text only: in HTML, tags and attributes are
|
|
23060
|
+
* dropped and entities decoded first. A mention's target attribute
|
|
23061
|
+
* (`href`, `data-id`, `data-did`) matches an exact, case-sensitive DID term, which
|
|
23062
|
+
* is how a mention by DID is found when the DID is not in the visible text.
|
|
23063
|
+
*
|
|
23064
|
+
* The mention query's `contains` matches substrings (model query has no word
|
|
23065
|
+
* match); this is the check that keeps "data" from waking on "metadata".
|
|
23066
|
+
* It reads the first {@link MENTION_TEXT_LIMIT} characters only.
|
|
23067
|
+
*/
|
|
23068
|
+
function holdsAWholeWordTerm(text, terms) {
|
|
23069
|
+
const { visible, targets } = readableParts(text.slice(0, MENTION_TEXT_LIMIT));
|
|
23070
|
+
return terms.some((term) => {
|
|
23071
|
+
if (!term)
|
|
23072
|
+
return false;
|
|
23073
|
+
if (term.startsWith("did:") && targets.includes(term))
|
|
23074
|
+
return true;
|
|
23075
|
+
const escaped = term.replace(/[\\^$.*+?()[\]{}|\/]/g, "\\$&");
|
|
23076
|
+
return new RegExp(`(?<!${WORD_CHAR})${escaped}(?!${WORD_CHAR})`, "iu").test(visible);
|
|
23077
|
+
});
|
|
23078
|
+
}
|
|
23079
|
+
/** The built-in `Container` (`Container.builtinUri`; not imported, so the
|
|
23080
|
+
* plugin bundle does not pull in the model layer). */
|
|
23081
|
+
const CONTAINER = "ad4m://Container";
|
|
22805
23082
|
/**
|
|
22806
23083
|
* Add a short cause hint to known subscription failures.
|
|
22807
23084
|
* The executor needs its main key to register a live query; on a restarted
|
|
@@ -22868,6 +23145,20 @@ class WakerSubscriptionManager {
|
|
|
22868
23145
|
/** Per-subscription set of already-processed message addresses (for mention subs)
|
|
22869
23146
|
* or serialized result hash (for channel-messages subs). */
|
|
22870
23147
|
this.seenMessages = new Map();
|
|
23148
|
+
/**
|
|
23149
|
+
* Per mention subscription: the addresses whose wake was delivered, or that were history when
|
|
23150
|
+
* the subscription opened. This, not `seenMessages`, is what gets persisted: an address joins
|
|
23151
|
+
* `seenMessages` as soon as it is read, while its parents are still resolving and before any
|
|
23152
|
+
* wake, so a restart in between must not take it as done.
|
|
23153
|
+
*/
|
|
23154
|
+
this.delivered = new Map();
|
|
23155
|
+
/**
|
|
23156
|
+
* Per mention subscription: mentions read but whose wake has not been delivered yet, keyed by
|
|
23157
|
+
* address. They accumulate across a debounce window, so one wake names all of them.
|
|
23158
|
+
*/
|
|
23159
|
+
this.undelivered = new Map();
|
|
23160
|
+
/** Failed wake attempts in a row per subscription, for the retry backoff. */
|
|
23161
|
+
this.wakeFailures = new Map();
|
|
22871
23162
|
this.perspectiveClient = options.perspectiveClient;
|
|
22872
23163
|
this.logger = options.logger;
|
|
22873
23164
|
this.debounceMs = options.debounceMs ?? 2000;
|
|
@@ -22878,6 +23169,7 @@ class WakerSubscriptionManager {
|
|
|
22878
23169
|
this.previousSeenMessages = options.previousSeenMessages ?? {};
|
|
22879
23170
|
this.retryPendingMs = options.retryPendingMs ?? 30000;
|
|
22880
23171
|
this.subscribeTimeoutMs = options.subscribeTimeoutMs ?? 15000;
|
|
23172
|
+
this.retryWakeMs = options.retryWakeMs ?? 5000;
|
|
22881
23173
|
}
|
|
22882
23174
|
/** A token identifying this attempt at subscribing `id`. */
|
|
22883
23175
|
beginAttempt(id) {
|
|
@@ -22890,7 +23182,7 @@ class WakerSubscriptionManager {
|
|
|
22890
23182
|
return token.epoch !== this.epoch || this.generations.get(id) !== token.gen;
|
|
22891
23183
|
}
|
|
22892
23184
|
/**
|
|
22893
|
-
* Create a live SPARQL
|
|
23185
|
+
* Create a live subscription: SPARQL, or a model query when `sub.className` is set.
|
|
22894
23186
|
* If a subscription with the same id already exists, it is disposed first.
|
|
22895
23187
|
*/
|
|
22896
23188
|
async subscribe(sub) {
|
|
@@ -22901,9 +23193,16 @@ class WakerSubscriptionManager {
|
|
|
22901
23193
|
throw new Error("WakerSubscriptionManager: QuerySubscriptionProxy must be provided via constructor options");
|
|
22902
23194
|
}
|
|
22903
23195
|
const QuerySubscriptionProxy = this.QuerySubscriptionProxyCtor;
|
|
23196
|
+
if (sub.type === "mention" && sub.className && !sub.terms?.length) {
|
|
23197
|
+
// Without terms the whole-word check cannot run, and every substring
|
|
23198
|
+
// ("metadata" for "data") would wake the agent.
|
|
23199
|
+
throw new Error(`Waker subscription ${sub.id}: a mention subscription needs its terms (get_mention_waker_config returns them)`);
|
|
23200
|
+
}
|
|
22904
23201
|
this.logger.info(`[waker] ${sub.id}: creating subscription (perspective=${sub.perspective}, type=${sub.type})`);
|
|
22905
|
-
this.logger.info(`[waker] ${sub.id}: SPARQL query:\n${sub.query}`);
|
|
22906
|
-
const proxy =
|
|
23202
|
+
this.logger.info(`[waker] ${sub.id}: ${sub.className ? `model query over ${sub.className}` : "SPARQL query"}:\n${sub.query}`);
|
|
23203
|
+
const proxy = sub.className
|
|
23204
|
+
? new QuerySubscriptionProxy(sub.perspective, sub.query, this.perspectiveClient, sub.className)
|
|
23205
|
+
: new QuerySubscriptionProxy(sub.perspective, sub.query, this.perspectiveClient);
|
|
22907
23206
|
// Suppress unhandled rejection from proxy.initialized — QuerySubscriptionProxy
|
|
22908
23207
|
// rejects this promise internally when subscribe() fails, and if nobody catches
|
|
22909
23208
|
// it before the next microtask it crashes the process.
|
|
@@ -22944,6 +23243,7 @@ class WakerSubscriptionManager {
|
|
|
22944
23243
|
// reported as active or persisted as if it were.
|
|
22945
23244
|
this.activeSubscriptions.delete(sub.id);
|
|
22946
23245
|
this.seenMessages.delete(sub.id);
|
|
23246
|
+
this.delivered.delete(sub.id);
|
|
22947
23247
|
this.persist();
|
|
22948
23248
|
// Keep it pending and re-attempt: the usual cause (locked wallet, executor
|
|
22949
23249
|
// mid-restart, a handshake the executor never answered) clears on its
|
|
@@ -22968,33 +23268,62 @@ class WakerSubscriptionManager {
|
|
|
22968
23268
|
this.pendingSubscriptions.delete(sub.id);
|
|
22969
23269
|
this.logger.info(`[waker] ${sub.id}: subscription initialized successfully`);
|
|
22970
23270
|
// Seed from persisted seen messages so we don't re-wake after restart
|
|
23271
|
+
const restored = Object.prototype.hasOwnProperty.call(this.previousSeenMessages, sub.id);
|
|
22971
23272
|
const seen = new Set(this.previousSeenMessages[sub.id] ?? []);
|
|
22972
23273
|
this.seenMessages.set(sub.id, seen);
|
|
23274
|
+
this.delivered.set(sub.id, new Set(seen));
|
|
22973
23275
|
if (seen.size > 0) {
|
|
22974
23276
|
this.logger.info(`[waker] ${sub.id}: seeded ${seen.size} seen message(s) from persisted state`);
|
|
22975
23277
|
}
|
|
22976
|
-
proxy.
|
|
22977
|
-
|
|
22978
|
-
|
|
22979
|
-
|
|
22980
|
-
|
|
23278
|
+
// `opening` is the result the subscription holds when it opens (`proxy.result`): `onResult`
|
|
23279
|
+
// only reports later changes, so this is the one chance to see what was written meanwhile.
|
|
23280
|
+
const handleResult = async (result, opening = false) => {
|
|
23281
|
+
this.logger.info(`[waker] ${sub.id}: ${opening ? "opening result" : "onResult fired"} — type=${typeof result}, isArray=${Array.isArray(result)}, value=${String(JSON.stringify(result)).substring(0, 500)}`);
|
|
23282
|
+
// A model subscription delivers `{ instances }`, SPARQL an array of
|
|
23283
|
+
// rows. Anything else (e.g. `false` on a disconnect/reconnect) is
|
|
23284
|
+
// ignored.
|
|
23285
|
+
const rows = sub.className ? result?.instances : result;
|
|
23286
|
+
if (!Array.isArray(rows)) {
|
|
23287
|
+
this.logger.warn(`[waker] ${sub.id}: ignoring result without ${sub.className ? "instances" : "rows"}: ${JSON.stringify(result)}`);
|
|
22981
23288
|
return;
|
|
22982
23289
|
}
|
|
22983
23290
|
if (sub.type === "mention") {
|
|
22984
|
-
// For mention subscriptions: track seen
|
|
22985
|
-
// Only wake for
|
|
23291
|
+
// For mention subscriptions: track seen record ids.
|
|
23292
|
+
// Only wake for records we haven't seen before.
|
|
22986
23293
|
const currentSeen = this.seenMessages.get(sub.id) ?? new Set();
|
|
22987
23294
|
const newMessages = [];
|
|
22988
|
-
|
|
22989
|
-
|
|
22990
|
-
|
|
23295
|
+
const terms = sub.terms ?? [];
|
|
23296
|
+
for (const item of rows) {
|
|
23297
|
+
// A SPARQL row names the record as `source`, a model row as `id`.
|
|
23298
|
+
const address = sub.className ? item?.id : item?.source;
|
|
23299
|
+
if (typeof address !== "string" || !address || currentSeen.has(address))
|
|
23300
|
+
continue;
|
|
23301
|
+
if (terms.length) {
|
|
23302
|
+
// The mention query matched a substring; wake only on a whole word.
|
|
23303
|
+
const text = Array.isArray(item.text) ? item.text.join(" ") : item.text;
|
|
23304
|
+
if (typeof text !== "string" || !holdsAWholeWordTerm(text, terms)) {
|
|
23305
|
+
this.logger.debug(`[waker] ${sub.id}: ${address} holds no term as a whole word, skipping`);
|
|
23306
|
+
continue;
|
|
23307
|
+
}
|
|
22991
23308
|
}
|
|
23309
|
+
currentSeen.add(address);
|
|
23310
|
+
newMessages.push(address);
|
|
22992
23311
|
}
|
|
22993
23312
|
if (newMessages.length === 0) {
|
|
22994
|
-
this.logger.info(`[waker] ${sub.id}:
|
|
23313
|
+
this.logger.info(`[waker] ${sub.id}: no new mention among ${rows.length} items, skipping`);
|
|
23314
|
+
return;
|
|
23315
|
+
}
|
|
23316
|
+
if (opening && !restored) {
|
|
23317
|
+
// A new subscription: what it opens on is history, readable on demand, not news.
|
|
23318
|
+
this.seenMessages.set(sub.id, currentSeen);
|
|
23319
|
+
const done = this.delivered.get(sub.id) ?? new Set();
|
|
23320
|
+
for (const address of newMessages)
|
|
23321
|
+
done.add(address);
|
|
23322
|
+
this.delivered.set(sub.id, done);
|
|
23323
|
+
this.logger.info(`[waker] ${sub.id}: ${newMessages.length} existing mention(s) taken as history, not woken`);
|
|
22995
23324
|
return;
|
|
22996
23325
|
}
|
|
22997
|
-
this.logger.info(`[waker] ${sub.id}: ${newMessages.length} new message(s) out of ${
|
|
23326
|
+
this.logger.info(`[waker] ${sub.id}: ${newMessages.length} new message(s) out of ${rows.length} total`);
|
|
22998
23327
|
// Resolve parents, and the chain above them, per new message
|
|
22999
23328
|
const mentions = [];
|
|
23000
23329
|
for (const msgAddr of newMessages) {
|
|
@@ -23005,25 +23334,20 @@ class WakerSubscriptionManager {
|
|
|
23005
23334
|
(ancestors.length ? `; ancestors: ${ancestors.join(", ")}` : ""));
|
|
23006
23335
|
mentions.push({ address: msgAddr, parents, ancestors });
|
|
23007
23336
|
}
|
|
23008
|
-
// Mark all new messages as seen
|
|
23009
|
-
for (const addr of newMessages) {
|
|
23010
|
-
currentSeen.add(addr);
|
|
23011
|
-
}
|
|
23012
23337
|
this.seenMessages.set(sub.id, currentSeen);
|
|
23013
|
-
|
|
23014
|
-
const
|
|
23015
|
-
|
|
23016
|
-
|
|
23017
|
-
this.
|
|
23018
|
-
this.onWake(sub, result, mentions);
|
|
23019
|
-
this.debounceTimers.delete(sub.id);
|
|
23020
|
-
this.persist();
|
|
23021
|
-
}, this.debounceMs));
|
|
23338
|
+
const pending = this.undelivered.get(sub.id) ?? new Map();
|
|
23339
|
+
for (const mention of mentions)
|
|
23340
|
+
pending.set(mention.address, mention);
|
|
23341
|
+
this.undelivered.set(sub.id, pending);
|
|
23342
|
+
this.scheduleMentionWake(sub, result, this.debounceMs);
|
|
23022
23343
|
}
|
|
23023
23344
|
else {
|
|
23345
|
+
// A container's contents when the subscription opens are not an update.
|
|
23346
|
+
if (opening)
|
|
23347
|
+
return;
|
|
23024
23348
|
// For channel-messages: always notify the agent on every subscription push.
|
|
23025
23349
|
// No deduplication — the agent reads recent messages itself.
|
|
23026
|
-
this.logger.info(`[waker] ${sub.id}: channel update (${
|
|
23350
|
+
this.logger.info(`[waker] ${sub.id}: channel update (${rows.length} items)`);
|
|
23027
23351
|
const existing = this.debounceTimers.get(sub.id);
|
|
23028
23352
|
if (existing)
|
|
23029
23353
|
clearTimeout(existing);
|
|
@@ -23032,7 +23356,8 @@ class WakerSubscriptionManager {
|
|
|
23032
23356
|
this.debounceTimers.delete(sub.id);
|
|
23033
23357
|
}, this.debounceMs));
|
|
23034
23358
|
}
|
|
23035
|
-
}
|
|
23359
|
+
};
|
|
23360
|
+
proxy.onResult((result) => handleResult(result));
|
|
23036
23361
|
if (this.isStale(sub.id, token)) {
|
|
23037
23362
|
try {
|
|
23038
23363
|
proxy.dispose();
|
|
@@ -23042,6 +23367,16 @@ class WakerSubscriptionManager {
|
|
|
23042
23367
|
}
|
|
23043
23368
|
this.proxies.set(sub.id, proxy);
|
|
23044
23369
|
this.activeSubscriptions.set(sub.id, sub);
|
|
23370
|
+
// After a restart this wakes on mentions written while the waker was down; on a new
|
|
23371
|
+
// subscription it records the existing ones as history.
|
|
23372
|
+
if (proxy.result !== undefined) {
|
|
23373
|
+
try {
|
|
23374
|
+
await handleResult(proxy.result, true);
|
|
23375
|
+
}
|
|
23376
|
+
catch (e) {
|
|
23377
|
+
this.logger.warn(`[waker] ${sub.id}: reading the opening result failed: ${e?.message ?? e}`);
|
|
23378
|
+
}
|
|
23379
|
+
}
|
|
23045
23380
|
this.persist();
|
|
23046
23381
|
this.logger.info(`[waker] Subscription ${sub.id} active (type=${sub.type}, perspective=${sub.perspective})`);
|
|
23047
23382
|
}
|
|
@@ -23117,9 +23452,61 @@ class WakerSubscriptionManager {
|
|
|
23117
23452
|
this.activeSubscriptions.delete(id);
|
|
23118
23453
|
this.pendingSubscriptions.delete(id);
|
|
23119
23454
|
this.seenMessages.delete(id);
|
|
23455
|
+
this.delivered.delete(id);
|
|
23456
|
+
this.undelivered.delete(id);
|
|
23457
|
+
this.wakeFailures.delete(id);
|
|
23120
23458
|
if (persist)
|
|
23121
23459
|
this.persist();
|
|
23122
23460
|
}
|
|
23461
|
+
/** (Re)start the timer that offers `sub`'s undelivered mentions to `onWake` after `delayMs`. */
|
|
23462
|
+
scheduleMentionWake(sub, result, delayMs) {
|
|
23463
|
+
const existing = this.debounceTimers.get(sub.id);
|
|
23464
|
+
if (existing)
|
|
23465
|
+
clearTimeout(existing);
|
|
23466
|
+
this.debounceTimers.set(sub.id, setTimeout(() => {
|
|
23467
|
+
this.debounceTimers.delete(sub.id);
|
|
23468
|
+
void this.deliverMentions(sub, result);
|
|
23469
|
+
}, delayMs));
|
|
23470
|
+
}
|
|
23471
|
+
/**
|
|
23472
|
+
* Offer every undelivered mention of `sub` in one wake. On delivery they join the persisted
|
|
23473
|
+
* seen set; on failure they stay undelivered and are offered again with backoff.
|
|
23474
|
+
*/
|
|
23475
|
+
async deliverMentions(sub, result) {
|
|
23476
|
+
const pending = this.undelivered.get(sub.id);
|
|
23477
|
+
if (!pending?.size || !this.activeSubscriptions.has(sub.id))
|
|
23478
|
+
return;
|
|
23479
|
+
const mentions = Array.from(pending.values());
|
|
23480
|
+
let delivered;
|
|
23481
|
+
try {
|
|
23482
|
+
delivered = (await this.onWake(sub, result, mentions)) !== false;
|
|
23483
|
+
}
|
|
23484
|
+
catch (e) {
|
|
23485
|
+
this.logger.warn(`[waker] ${sub.id}: wake callback threw: ${e?.message ?? e}`);
|
|
23486
|
+
delivered = false;
|
|
23487
|
+
}
|
|
23488
|
+
// Disposed while the wake was in flight: nothing left to retry or persist.
|
|
23489
|
+
if (this.undelivered.get(sub.id) !== pending)
|
|
23490
|
+
return;
|
|
23491
|
+
if (!delivered) {
|
|
23492
|
+
const failures = (this.wakeFailures.get(sub.id) ?? 0) + 1;
|
|
23493
|
+
this.wakeFailures.set(sub.id, failures);
|
|
23494
|
+
const delay = Math.min(this.retryWakeMs * 2 ** (failures - 1), 60000);
|
|
23495
|
+
this.logger.warn(`[waker] ${sub.id}: wake for ${mentions.length} mention(s) not delivered, offering again in ${delay}ms`);
|
|
23496
|
+
// A newer result arriving meanwhile restarts the timer and joins this wake.
|
|
23497
|
+
if (!this.debounceTimers.has(sub.id))
|
|
23498
|
+
this.scheduleMentionWake(sub, result, delay);
|
|
23499
|
+
return;
|
|
23500
|
+
}
|
|
23501
|
+
this.wakeFailures.delete(sub.id);
|
|
23502
|
+
const done = this.delivered.get(sub.id) ?? new Set();
|
|
23503
|
+
for (const mention of mentions) {
|
|
23504
|
+
pending.delete(mention.address);
|
|
23505
|
+
done.add(mention.address);
|
|
23506
|
+
}
|
|
23507
|
+
this.delivered.set(sub.id, done);
|
|
23508
|
+
this.persist();
|
|
23509
|
+
}
|
|
23123
23510
|
/** Dispose all active subscriptions and drop anything still pending. */
|
|
23124
23511
|
disposeAll() {
|
|
23125
23512
|
// Bump the epoch first: in-flight subscribe() calls have no proxy in the
|
|
@@ -23142,60 +23529,50 @@ class WakerSubscriptionManager {
|
|
|
23142
23529
|
has(id) {
|
|
23143
23530
|
return this.activeSubscriptions.has(id);
|
|
23144
23531
|
}
|
|
23145
|
-
/**
|
|
23532
|
+
/**
|
|
23533
|
+
* Everything holding any of `addresses`, in one model query: a `Container`
|
|
23534
|
+
* step in (#1446). The executor follows `ad4m://has_child` on any node and
|
|
23535
|
+
* each class's own `children` relation on its instances, so the waker
|
|
23536
|
+
* looks up no predicate. Failures count as none.
|
|
23537
|
+
*/
|
|
23146
23538
|
async parentsOf(sub, addresses) {
|
|
23147
|
-
|
|
23148
|
-
if (/[<>"{}|^`\\\s\x00-\x20]/.test(address)) {
|
|
23149
|
-
this.logger.warn(`[waker] ${sub.id}: skipping parent lookup for unsafe address ${JSON.stringify(address)}`);
|
|
23150
|
-
return false;
|
|
23151
|
-
}
|
|
23152
|
-
return true;
|
|
23153
|
-
});
|
|
23154
|
-
if (!safe.length)
|
|
23539
|
+
if (!addresses.length)
|
|
23155
23540
|
return [];
|
|
23156
|
-
|
|
23157
|
-
const query = safe.length === 1
|
|
23158
|
-
? `SELECT ?source WHERE { ?source <ad4m://has_child> <${safe[0]}> . }`
|
|
23159
|
-
: `SELECT ?source WHERE { VALUES ?child { ${safe.map((address) => `<${address}>`).join(" ")} } ?source <ad4m://has_child> ?child . }`;
|
|
23160
|
-
const rows = await this.perspectiveClient.querySparql(sub.perspective, query);
|
|
23161
|
-
if (!Array.isArray(rows))
|
|
23162
|
-
return [];
|
|
23163
|
-
// A row omits a variable left unbound in its solution.
|
|
23164
|
-
return rows.map((row) => row?.source).filter((source) => typeof source === "string");
|
|
23165
|
-
}
|
|
23166
|
-
catch (err) {
|
|
23167
|
-
this.logger.warn(`[waker] ${sub.id}: parent resolution failed for ${JSON.stringify(safe)} — ${err?.message ?? err}`);
|
|
23168
|
-
return [];
|
|
23169
|
-
}
|
|
23541
|
+
return this.containers(sub, { ids: [...new Set(addresses)], direction: "in" }, addresses);
|
|
23170
23542
|
}
|
|
23171
23543
|
/**
|
|
23172
|
-
* The chain above an item's parents,
|
|
23173
|
-
*
|
|
23174
|
-
*
|
|
23175
|
-
*
|
|
23176
|
-
* Each level uses one batched parent lookup, bounded by the depth.
|
|
23544
|
+
* The chain above an item's parents, nearest first, up to `ancestorDepth` levels: one
|
|
23545
|
+
* transitive `Container` walk in from the parents, bounded by `maxDepth`. The executor walks
|
|
23546
|
+
* containment as a graph, so each address comes once however many paths reach it, and a
|
|
23547
|
+
* cycle ends. The item and its parents are never reported as ancestors.
|
|
23177
23548
|
*/
|
|
23178
23549
|
async ancestorsOf(sub, address, parents) {
|
|
23550
|
+
if (!parents.length || this.ancestorDepth <= 0)
|
|
23551
|
+
return [];
|
|
23552
|
+
const scope = { ids: parents, direction: "in", transitive: true, maxDepth: this.ancestorDepth };
|
|
23179
23553
|
const seen = new Set([address, ...parents]);
|
|
23180
|
-
|
|
23181
|
-
|
|
23182
|
-
|
|
23183
|
-
|
|
23184
|
-
|
|
23185
|
-
|
|
23186
|
-
|
|
23187
|
-
|
|
23188
|
-
|
|
23189
|
-
|
|
23190
|
-
|
|
23191
|
-
|
|
23554
|
+
return (await this.containers(sub, scope, parents)).filter((id) => !seen.has(id));
|
|
23555
|
+
}
|
|
23556
|
+
/** The ids of the `Container` rows `parent` scopes to, in the executor's order. */
|
|
23557
|
+
async containers(sub, parent, from) {
|
|
23558
|
+
try {
|
|
23559
|
+
const query = JSON.stringify({ parent, properties: [] });
|
|
23560
|
+
const result = await this.perspectiveClient.modelQuery(sub.perspective, CONTAINER, query);
|
|
23561
|
+
const instances = result?.instances;
|
|
23562
|
+
if (!Array.isArray(instances))
|
|
23563
|
+
return [];
|
|
23564
|
+
return instances.map((row) => row?.id).filter((id) => typeof id === "string");
|
|
23565
|
+
}
|
|
23566
|
+
catch (err) {
|
|
23567
|
+
this.logger.warn(`[waker] ${sub.id}: containment lookup failed for ${JSON.stringify(from)} — ${err?.message ?? err}`);
|
|
23568
|
+
return [];
|
|
23192
23569
|
}
|
|
23193
|
-
return ancestors;
|
|
23194
23570
|
}
|
|
23195
23571
|
persist() {
|
|
23196
23572
|
if (this.onPersist) {
|
|
23197
23573
|
const seen = {};
|
|
23198
|
-
|
|
23574
|
+
// Only what was delivered: anything else must wake again after a restart.
|
|
23575
|
+
for (const [id, set] of this.delivered) {
|
|
23199
23576
|
seen[id] = Array.from(set);
|
|
23200
23577
|
}
|
|
23201
23578
|
this.onPersist(this.getActive(), seen);
|
|
@@ -23711,6 +24088,7 @@ exports.Literal = Literal;
|
|
|
23711
24088
|
exports.LiveQuery = LiveQuery;
|
|
23712
24089
|
exports.LocalModel = LocalModel;
|
|
23713
24090
|
exports.LocalModelInput = LocalModelInput;
|
|
24091
|
+
exports.MENTION_TEXT_LIMIT = MENTION_TEXT_LIMIT;
|
|
23714
24092
|
exports.MeshManager = MeshManager;
|
|
23715
24093
|
exports.Model = Model$1;
|
|
23716
24094
|
exports.ModelApi = ModelApi;
|
|
@@ -23793,9 +24171,12 @@ exports.getPropertyOption = getPropertyOption;
|
|
|
23793
24171
|
exports.getRelationsMetadata = getRelationsMetadata;
|
|
23794
24172
|
exports.hasJsOnlyWhereFilters = hasJsOnlyWhereFilters;
|
|
23795
24173
|
exports.hintFor = hintFor;
|
|
24174
|
+
exports.holdsAWholeWordTerm = holdsAWholeWordTerm;
|
|
23796
24175
|
exports.ifExpr = ifExpr;
|
|
23797
24176
|
exports.invalidatePerspectiveCache = invalidatePerspectiveCache;
|
|
23798
24177
|
exports.isArrayType = isArrayType;
|
|
24178
|
+
exports.isContainedScope = isContainedScope;
|
|
24179
|
+
exports.isContainmentTraversal = isContainmentTraversal;
|
|
23799
24180
|
exports.isExpression = isExpression;
|
|
23800
24181
|
exports.isIncludeProjection = isIncludeProjection;
|
|
23801
24182
|
exports.isLink = isLink;
|