@semiont/core 0.5.23 → 0.5.24
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/dist/chunk-3WTQZOGO.js +143 -0
- package/dist/chunk-3WTQZOGO.js.map +1 -0
- package/dist/chunk-4JTZMWZB.js +330 -0
- package/dist/chunk-4JTZMWZB.js.map +1 -0
- package/dist/chunk-XQTWEBJ5.js +293 -0
- package/dist/chunk-XQTWEBJ5.js.map +1 -0
- package/dist/config/node-config-loader.d.ts +7 -7
- package/dist/config/node-config-loader.js +1 -288
- package/dist/config/node-config-loader.js.map +1 -1
- package/dist/index.d.ts +22 -4
- package/dist/index.js +20 -618
- package/dist/index.js.map +1 -1
- package/dist/testing/axioms.d.ts +180 -0
- package/dist/testing/axioms.js +365 -0
- package/dist/testing/axioms.js.map +1 -0
- package/dist/testing.d.ts +16 -178
- package/dist/testing.js +2 -761
- package/dist/testing.js.map +1 -1
- package/package.json +6 -1
package/dist/index.js
CHANGED
|
@@ -1,65 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
export { createTomlConfigLoader, loadTomlConfig } from './chunk-XQTWEBJ5.js';
|
|
2
|
+
import { BUS_OPERATIONS } from './chunk-4JTZMWZB.js';
|
|
3
|
+
export { BRIDGED_CHANNELS, BUS_OPERATIONS, EventBus, ScopedEventBus, accessToken, annotationUri, authCode, baseUrl, busLog, busLogEnabled, cloneToken, email, entityType, googleCredential, jobId, mcpToken, refreshToken, resourceAnnotationUri, resourceUri, searchQuery, setBusLogTraceIdProvider, userDID } from './chunk-4JTZMWZB.js';
|
|
4
|
+
import { Observable, merge, TimeoutError, throwError, firstValueFrom } from 'rxjs';
|
|
2
5
|
import { filter, map, take, timeout, catchError, defaultIfEmpty } from 'rxjs/operators';
|
|
3
|
-
import { parse } from 'smol-toml';
|
|
4
|
-
|
|
5
|
-
// src/branded-types.ts
|
|
6
|
-
function email(value) {
|
|
7
|
-
return value;
|
|
8
|
-
}
|
|
9
|
-
function authCode(value) {
|
|
10
|
-
return value;
|
|
11
|
-
}
|
|
12
|
-
function googleCredential(value) {
|
|
13
|
-
return value;
|
|
14
|
-
}
|
|
15
|
-
function accessToken(value) {
|
|
16
|
-
return value;
|
|
17
|
-
}
|
|
18
|
-
function refreshToken(value) {
|
|
19
|
-
return value;
|
|
20
|
-
}
|
|
21
|
-
function mcpToken(value) {
|
|
22
|
-
return value;
|
|
23
|
-
}
|
|
24
|
-
function cloneToken(value) {
|
|
25
|
-
return value;
|
|
26
|
-
}
|
|
27
|
-
function jobId(value) {
|
|
28
|
-
return value;
|
|
29
|
-
}
|
|
30
|
-
function userDID(value) {
|
|
31
|
-
return value;
|
|
32
|
-
}
|
|
33
|
-
function entityType(value) {
|
|
34
|
-
return value;
|
|
35
|
-
}
|
|
36
|
-
function searchQuery(value) {
|
|
37
|
-
return value;
|
|
38
|
-
}
|
|
39
|
-
function baseUrl(value) {
|
|
40
|
-
return value;
|
|
41
|
-
}
|
|
42
|
-
function resourceUri(uri) {
|
|
43
|
-
if (!uri.startsWith("http://") && !uri.startsWith("https://")) {
|
|
44
|
-
throw new TypeError(`Expected ResourceUri, got: ${uri}`);
|
|
45
|
-
}
|
|
46
|
-
return uri;
|
|
47
|
-
}
|
|
48
|
-
function annotationUri(uri) {
|
|
49
|
-
if (!uri.startsWith("http://") && !uri.startsWith("https://")) {
|
|
50
|
-
throw new TypeError(`Expected AnnotationUri, got: ${uri}`);
|
|
51
|
-
}
|
|
52
|
-
return uri;
|
|
53
|
-
}
|
|
54
|
-
function resourceAnnotationUri(uri) {
|
|
55
|
-
if (!uri.startsWith("http://") && !uri.startsWith("https://")) {
|
|
56
|
-
throw new TypeError(`Expected ResourceAnnotationUri, got: ${uri}`);
|
|
57
|
-
}
|
|
58
|
-
if (!uri.includes("/resources/") || !uri.includes("/annotations/")) {
|
|
59
|
-
throw new TypeError(`Expected nested ResourceAnnotationUri format, got: ${uri}`);
|
|
60
|
-
}
|
|
61
|
-
return uri;
|
|
62
|
-
}
|
|
63
6
|
|
|
64
7
|
// src/identifiers.ts
|
|
65
8
|
function isResourceId(value) {
|
|
@@ -369,274 +312,6 @@ function isEventRelatedToAnnotation(event, annotationUri2) {
|
|
|
369
312
|
function isStoredEvent(event) {
|
|
370
313
|
return event && typeof event.id === "string" && typeof event.timestamp === "string" && typeof event.type === "string" && typeof event.metadata === "object" && typeof event.metadata.sequenceNumber === "number";
|
|
371
314
|
}
|
|
372
|
-
|
|
373
|
-
// src/bus-operations.ts
|
|
374
|
-
var BUS_OPERATIONS = {
|
|
375
|
-
// ── BIND ────────────────────────────────────────────────────────
|
|
376
|
-
"bind:update-body": { result: "bind:body-updated", failure: "bind:body-update-failed" },
|
|
377
|
-
// ── BROWSE (reads) ──────────────────────────────────────────────
|
|
378
|
-
"browse:resource-requested": { result: "browse:resource-result", failure: "browse:resource-failed" },
|
|
379
|
-
"browse:resources-requested": { result: "browse:resources-result", failure: "browse:resources-failed" },
|
|
380
|
-
"browse:annotation-requested": { result: "browse:annotation-result", failure: "browse:annotation-failed" },
|
|
381
|
-
"browse:annotations-requested": { result: "browse:annotations-result", failure: "browse:annotations-failed" },
|
|
382
|
-
"browse:annotation-history-requested": { result: "browse:annotation-history-result", failure: "browse:annotation-history-failed" },
|
|
383
|
-
"browse:events-requested": { result: "browse:events-result", failure: "browse:events-failed" },
|
|
384
|
-
"browse:referenced-by-requested": { result: "browse:referenced-by-result", failure: "browse:referenced-by-failed" },
|
|
385
|
-
"browse:entity-types-requested": { result: "browse:entity-types-result", failure: "browse:entity-types-failed" },
|
|
386
|
-
"browse:tag-schemas-requested": { result: "browse:tag-schemas-result", failure: "browse:tag-schemas-failed" },
|
|
387
|
-
"browse:agents-requested": { result: "browse:agents-result", failure: "browse:agents-failed" },
|
|
388
|
-
"browse:directory-requested": { result: "browse:directory-result", failure: "browse:directory-failed" },
|
|
389
|
-
// dormant — backend handler complete, no client caller yet (annotation-detail capability)
|
|
390
|
-
"browse:annotation-context-requested": { result: "browse:annotation-context-result", failure: "browse:annotation-context-failed" },
|
|
391
|
-
// ── FRAME (KB schema writes) ────────────────────────────────────
|
|
392
|
-
"frame:add-entity-type": { result: "frame:entity-type-add-ok", failure: "frame:entity-type-add-failed" },
|
|
393
|
-
"frame:add-tag-schema": { result: "frame:tag-schema-add-ok", failure: "frame:tag-schema-add-failed" },
|
|
394
|
-
// ── GATHER ──────────────────────────────────────────────────────
|
|
395
|
-
// streaming: take-1 result + failure plus an intermediate progress channel
|
|
396
|
-
"gather:requested": { result: "gather:complete", failure: "gather:failed", progress: "gather:annotation-progress" },
|
|
397
|
-
"gather:resource-requested": { result: "gather:resource-complete", failure: "gather:resource-failed" },
|
|
398
|
-
// dormant — backend handler complete, no client caller yet (annotation summary)
|
|
399
|
-
"gather:summary-requested": { result: "gather:summary-result", failure: "gather:summary-failed" },
|
|
400
|
-
// ── JOB ─────────────────────────────────────────────────────────
|
|
401
|
-
"job:create": { result: "job:created", failure: "job:create-failed" },
|
|
402
|
-
"job:status-requested": { result: "job:status-result", failure: "job:status-failed" },
|
|
403
|
-
"job:cancel-requested": { result: "job:cancel-ok", failure: "job:cancel-failed" },
|
|
404
|
-
// worker-side: the worker claims a queued job (not an SDK call)
|
|
405
|
-
"job:claim": { result: "job:claimed", failure: "job:claim-failed" },
|
|
406
|
-
// ── MARK ────────────────────────────────────────────────────────
|
|
407
|
-
"mark:create-request": { result: "mark:create-ok", failure: "mark:create-failed" },
|
|
408
|
-
"mark:delete": { result: "mark:delete-ok", failure: "mark:delete-failed" },
|
|
409
|
-
"mark:archive": { result: "mark:archive-ok", failure: "mark:archive-failed" },
|
|
410
|
-
"mark:unarchive": { result: "mark:unarchive-ok", failure: "mark:unarchive-failed" },
|
|
411
|
-
"mark:update-entity-types": { result: "mark:update-entity-types-ok", failure: "mark:update-entity-types-failed" },
|
|
412
|
-
// ── MATCH ───────────────────────────────────────────────────────
|
|
413
|
-
// take-1 dressed as an Observable in the SDK; no progress channel
|
|
414
|
-
"match:search-requested": { result: "match:search-results", failure: "match:search-failed" },
|
|
415
|
-
// ── WEAVE ───────────────────────────────────────────────────────
|
|
416
|
-
// Graph-projection rebuild, served by the Weaver (WEAVER-ISOLATION D3)
|
|
417
|
-
"weave:rebuild": { result: "weave:rebuild-ok", failure: "weave:rebuild-failed" },
|
|
418
|
-
// ── YIELD ───────────────────────────────────────────────────────
|
|
419
|
-
// live in-process (resource-operations.ts emits + awaits via race()); the
|
|
420
|
-
// client also .on()-subscribes -ok for cache invalidation
|
|
421
|
-
"yield:create": { result: "yield:create-ok", failure: "yield:create-failed" },
|
|
422
|
-
// dormant — handler in stower exists, no request emitter; client pre-subscribes -ok
|
|
423
|
-
"yield:update": { result: "yield:update-ok", failure: "yield:update-failed" },
|
|
424
|
-
"yield:clone-create": { result: "yield:clone-created", failure: "yield:clone-create-failed" },
|
|
425
|
-
"yield:clone-resource-requested": { result: "yield:clone-resource-result", failure: "yield:clone-resource-failed" },
|
|
426
|
-
"yield:clone-token-requested": { result: "yield:clone-token-generated", failure: "yield:clone-token-failed" }
|
|
427
|
-
};
|
|
428
|
-
|
|
429
|
-
// src/bridged-channels.ts
|
|
430
|
-
var BRIDGED_BROADCASTS = [
|
|
431
|
-
"job:report-progress",
|
|
432
|
-
"job:complete",
|
|
433
|
-
"job:fail",
|
|
434
|
-
"frame:entity-type-added",
|
|
435
|
-
"frame:tag-schema-added",
|
|
436
|
-
"beckon:focus",
|
|
437
|
-
"beckon:sparkle",
|
|
438
|
-
"bus:resume-gap"
|
|
439
|
-
];
|
|
440
|
-
var REGISTRY_REPLIES = Object.keys(BUS_OPERATIONS).flatMap(
|
|
441
|
-
(key) => {
|
|
442
|
-
const op = BUS_OPERATIONS[key];
|
|
443
|
-
return "progress" in op ? [op.result, op.failure, op.progress] : [op.result, op.failure];
|
|
444
|
-
}
|
|
445
|
-
);
|
|
446
|
-
var BRIDGED_CHANNELS = [
|
|
447
|
-
...REGISTRY_REPLIES,
|
|
448
|
-
...BRIDGED_BROADCASTS
|
|
449
|
-
];
|
|
450
|
-
|
|
451
|
-
// src/bus-log.ts
|
|
452
|
-
var NODE_BUS_LOG = typeof process !== "undefined" && !!process.env?.SEMIONT_BUS_LOG;
|
|
453
|
-
var IS_NODE = typeof process !== "undefined" && !!process.versions?.node;
|
|
454
|
-
function busLogEnabled() {
|
|
455
|
-
const g = globalThis;
|
|
456
|
-
if (g.__SEMIONT_BUS_LOG__) return true;
|
|
457
|
-
return NODE_BUS_LOG;
|
|
458
|
-
}
|
|
459
|
-
var traceIdProvider;
|
|
460
|
-
function setBusLogTraceIdProvider(fn) {
|
|
461
|
-
traceIdProvider = fn;
|
|
462
|
-
}
|
|
463
|
-
function busLog(op, channel, payload, scope) {
|
|
464
|
-
if (!busLogEnabled()) return;
|
|
465
|
-
const cidRaw = payload?.correlationId;
|
|
466
|
-
const cid = typeof cidRaw === "string" ? cidRaw.slice(0, 8) : void 0;
|
|
467
|
-
let traceId;
|
|
468
|
-
if (traceIdProvider) {
|
|
469
|
-
try {
|
|
470
|
-
traceId = traceIdProvider();
|
|
471
|
-
} catch {
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
const tag = `[bus ${op}] ${channel}` + (scope ? ` scope=${scope}` : "") + (cid ? ` cid=${cid}` : "") + (traceId ? ` trace=${traceId.slice(0, 8)}` : "");
|
|
475
|
-
console.debug(tag, payload);
|
|
476
|
-
}
|
|
477
|
-
function warnUnobservedRepliesEnabled() {
|
|
478
|
-
return IS_NODE;
|
|
479
|
-
}
|
|
480
|
-
var unobservedReplyWarned = /* @__PURE__ */ new Set();
|
|
481
|
-
function warnIfUnobservedReply(channel, payload, observerCount) {
|
|
482
|
-
if (observerCount > 0) return;
|
|
483
|
-
const cidRaw = payload?.correlationId;
|
|
484
|
-
if (typeof cidRaw !== "string" || cidRaw.length === 0) return;
|
|
485
|
-
if (BRIDGED_CHANNELS.includes(channel)) return;
|
|
486
|
-
if (unobservedReplyWarned.has(channel)) return;
|
|
487
|
-
unobservedReplyWarned.add(channel);
|
|
488
|
-
console.warn(
|
|
489
|
-
`[bus DROP] ${channel} cid=${cidRaw.slice(0, 8)} emitted with 0 subscribers and not in BRIDGED_CHANNELS \u2014 a correlation reply with no forwarder is dropped, so the awaiting client times out (no error). Bridge it by declaring its operation in BUS_OPERATIONS (packages/core/src/bus-operations.ts) \u2014 or, if it is a non-reply broadcast, add it to BRIDGED_BROADCASTS (packages/core/src/bridged-channels.ts) \u2014 so transports subscribe to it.`
|
|
490
|
-
);
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
// src/event-bus.ts
|
|
494
|
-
var EventBus = class {
|
|
495
|
-
subjects;
|
|
496
|
-
isDestroyed;
|
|
497
|
-
constructor() {
|
|
498
|
-
this.subjects = /* @__PURE__ */ new Map();
|
|
499
|
-
this.isDestroyed = false;
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* Get the RxJS Subject for an event
|
|
503
|
-
*
|
|
504
|
-
* Returns a typed Subject that can be used with all RxJS operators.
|
|
505
|
-
* Subjects are created lazily on first access.
|
|
506
|
-
*
|
|
507
|
-
* @param eventName - The event name
|
|
508
|
-
* @returns The RxJS Subject for this event
|
|
509
|
-
*
|
|
510
|
-
* @example
|
|
511
|
-
* ```typescript
|
|
512
|
-
* // Emit
|
|
513
|
-
* eventBus.get('beckon:hover').next({ annotationId: 'ann-1' });
|
|
514
|
-
*
|
|
515
|
-
* // Subscribe
|
|
516
|
-
* const sub = eventBus.get('beckon:hover').subscribe(handleHover);
|
|
517
|
-
*
|
|
518
|
-
* // With operators
|
|
519
|
-
* eventBus.get('beckon:hover')
|
|
520
|
-
* .pipe(debounceTime(100), distinctUntilChanged())
|
|
521
|
-
* .subscribe(handleHover);
|
|
522
|
-
* ```
|
|
523
|
-
*/
|
|
524
|
-
get(eventName) {
|
|
525
|
-
if (this.isDestroyed) {
|
|
526
|
-
throw new Error(`Cannot access event '${String(eventName)}' on destroyed bus`);
|
|
527
|
-
}
|
|
528
|
-
if (!this.subjects.has(eventName)) {
|
|
529
|
-
const subject = new Subject();
|
|
530
|
-
const wantBusLog = busLogEnabled();
|
|
531
|
-
const wantDropCheck = warnUnobservedRepliesEnabled();
|
|
532
|
-
if (wantBusLog || wantDropCheck) {
|
|
533
|
-
const wrapped = subject;
|
|
534
|
-
const originalNext = subject.next.bind(subject);
|
|
535
|
-
subject.next = (value) => {
|
|
536
|
-
if (wantBusLog) busLog("EMIT", String(eventName), value);
|
|
537
|
-
if (wantDropCheck) warnIfUnobservedReply(String(eventName), value, wrapped.observers.length);
|
|
538
|
-
originalNext(value);
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
this.subjects.set(eventName, subject);
|
|
542
|
-
}
|
|
543
|
-
return this.subjects.get(eventName);
|
|
544
|
-
}
|
|
545
|
-
/**
|
|
546
|
-
* Get the RxJS Subject for a domain event type (PersistedEventType).
|
|
547
|
-
*
|
|
548
|
-
* Domain event channels carry `StoredEvent`. This method avoids the need
|
|
549
|
-
* for `as keyof EventMap` casts when subscribing to domain event channels
|
|
550
|
-
* using runtime `PersistedEventType` strings.
|
|
551
|
-
*/
|
|
552
|
-
getDomainEvent(eventType) {
|
|
553
|
-
return this.get(eventType);
|
|
554
|
-
}
|
|
555
|
-
/**
|
|
556
|
-
* Destroy the event bus and complete all subjects
|
|
557
|
-
*
|
|
558
|
-
* After calling destroy(), no new events can be emitted or subscribed to.
|
|
559
|
-
* All active subscriptions will be completed.
|
|
560
|
-
*/
|
|
561
|
-
destroy() {
|
|
562
|
-
if (this.isDestroyed) {
|
|
563
|
-
return;
|
|
564
|
-
}
|
|
565
|
-
for (const subject of this.subjects.values()) {
|
|
566
|
-
subject.complete();
|
|
567
|
-
}
|
|
568
|
-
this.subjects.clear();
|
|
569
|
-
this.isDestroyed = true;
|
|
570
|
-
}
|
|
571
|
-
/**
|
|
572
|
-
* Check if the event bus has been destroyed
|
|
573
|
-
*/
|
|
574
|
-
get destroyed() {
|
|
575
|
-
return this.isDestroyed;
|
|
576
|
-
}
|
|
577
|
-
/**
|
|
578
|
-
* Create a resource-scoped event bus
|
|
579
|
-
*
|
|
580
|
-
* Events emitted or subscribed through the scoped bus are isolated to that resource.
|
|
581
|
-
* Internally, events are namespaced but the API remains identical to the parent bus.
|
|
582
|
-
*
|
|
583
|
-
* @param resourceId - Resource identifier to scope events to
|
|
584
|
-
* @returns A scoped event bus for this resource
|
|
585
|
-
*
|
|
586
|
-
* @example
|
|
587
|
-
* ```typescript
|
|
588
|
-
* const eventBus = new EventBus();
|
|
589
|
-
* const resource1 = eventBus.scope('resource-1');
|
|
590
|
-
* const resource2 = eventBus.scope('resource-2');
|
|
591
|
-
*
|
|
592
|
-
* // These are isolated - only resource1 subscribers will fire
|
|
593
|
-
* resource1.get('detection:progress').next({ status: 'started' });
|
|
594
|
-
* ```
|
|
595
|
-
*/
|
|
596
|
-
scope(resourceId2) {
|
|
597
|
-
return new ScopedEventBus(this, resourceId2);
|
|
598
|
-
}
|
|
599
|
-
};
|
|
600
|
-
var ScopedEventBus = class _ScopedEventBus {
|
|
601
|
-
constructor(parent, scopePrefix) {
|
|
602
|
-
this.parent = parent;
|
|
603
|
-
this.scopePrefix = scopePrefix;
|
|
604
|
-
}
|
|
605
|
-
parent;
|
|
606
|
-
scopePrefix;
|
|
607
|
-
/**
|
|
608
|
-
* Get the RxJS Subject for a scoped event
|
|
609
|
-
*
|
|
610
|
-
* Returns the same type as the parent bus, but events are isolated to this scope.
|
|
611
|
-
* Internally uses namespaced keys but preserves type safety.
|
|
612
|
-
*
|
|
613
|
-
* @param event - The event name
|
|
614
|
-
* @returns The RxJS Subject for this scoped event
|
|
615
|
-
*/
|
|
616
|
-
get(event) {
|
|
617
|
-
const scopedKey = `${this.scopePrefix}:${event}`;
|
|
618
|
-
const parentSubjects = this.parent.subjects;
|
|
619
|
-
if (!parentSubjects.has(scopedKey)) {
|
|
620
|
-
parentSubjects.set(scopedKey, new Subject());
|
|
621
|
-
}
|
|
622
|
-
return parentSubjects.get(scopedKey);
|
|
623
|
-
}
|
|
624
|
-
/** Get the RxJS Subject for a domain event type on this scoped bus. */
|
|
625
|
-
getDomainEvent(eventType) {
|
|
626
|
-
return this.get(eventType);
|
|
627
|
-
}
|
|
628
|
-
/**
|
|
629
|
-
* Create a nested scope
|
|
630
|
-
*
|
|
631
|
-
* Allows hierarchical scoping like `resource-1:subsystem-a`
|
|
632
|
-
*
|
|
633
|
-
* @param subScope - Additional scope level
|
|
634
|
-
* @returns A nested scoped event bus
|
|
635
|
-
*/
|
|
636
|
-
scope(subScope) {
|
|
637
|
-
return new _ScopedEventBus(this.parent, `${this.scopePrefix}:${subScope}`);
|
|
638
|
-
}
|
|
639
|
-
};
|
|
640
315
|
function burstBuffer(options) {
|
|
641
316
|
const { burstWindowMs, maxBatchSize, idleTimeoutMs } = options;
|
|
642
317
|
return (source) => new Observable((subscriber) => {
|
|
@@ -781,8 +456,21 @@ function findBodyItem(body, identity) {
|
|
|
781
456
|
}
|
|
782
457
|
|
|
783
458
|
// src/id-generation.ts
|
|
459
|
+
function v4Bytes() {
|
|
460
|
+
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
461
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
462
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
463
|
+
return bytes;
|
|
464
|
+
}
|
|
465
|
+
function hex(bytes) {
|
|
466
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
467
|
+
}
|
|
784
468
|
function generateUuid() {
|
|
785
|
-
return
|
|
469
|
+
return hex(v4Bytes());
|
|
470
|
+
}
|
|
471
|
+
function uuidV4() {
|
|
472
|
+
const h = hex(v4Bytes());
|
|
473
|
+
return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;
|
|
786
474
|
}
|
|
787
475
|
|
|
788
476
|
// src/annotation-assembly.ts
|
|
@@ -1172,7 +860,7 @@ var BusRequestError = class extends SemiontError {
|
|
|
1172
860
|
}
|
|
1173
861
|
};
|
|
1174
862
|
async function busRequest(bus, operation, payload, timeoutMs = 3e4) {
|
|
1175
|
-
const correlationId =
|
|
863
|
+
const correlationId = uuidV4();
|
|
1176
864
|
const fullPayload = { ...payload, correlationId };
|
|
1177
865
|
const { result: resultChannel, failure: failureChannel } = BUS_OPERATIONS[operation];
|
|
1178
866
|
const result$ = merge(
|
|
@@ -2112,292 +1800,6 @@ function didToAgent(did) {
|
|
|
2112
1800
|
name: decodeURIComponent(encoded)
|
|
2113
1801
|
};
|
|
2114
1802
|
}
|
|
2115
|
-
function deepMerge(base, override) {
|
|
2116
|
-
const result = { ...base };
|
|
2117
|
-
for (const key of Object.keys(override)) {
|
|
2118
|
-
const b = base[key];
|
|
2119
|
-
const o = override[key];
|
|
2120
|
-
if (o !== void 0 && o !== null && typeof o === "object" && !Array.isArray(o) && b !== void 0 && b !== null && typeof b === "object" && !Array.isArray(b)) {
|
|
2121
|
-
result[key] = deepMerge(b, o);
|
|
2122
|
-
} else if (o !== void 0) {
|
|
2123
|
-
result[key] = o;
|
|
2124
|
-
}
|
|
2125
|
-
}
|
|
2126
|
-
return result;
|
|
2127
|
-
}
|
|
2128
|
-
function resolveEnvVars(obj, env) {
|
|
2129
|
-
if (typeof obj === "string") {
|
|
2130
|
-
return obj.replace(/\$\{([^}]+)\}/g, (match, expr) => {
|
|
2131
|
-
const sepIdx = expr.indexOf(":-");
|
|
2132
|
-
const varName = sepIdx >= 0 ? expr.slice(0, sepIdx) : expr;
|
|
2133
|
-
const defaultValue = sepIdx >= 0 ? expr.slice(sepIdx + 2) : void 0;
|
|
2134
|
-
const value = env[varName];
|
|
2135
|
-
if (value !== void 0) return value;
|
|
2136
|
-
if (defaultValue !== void 0) return defaultValue;
|
|
2137
|
-
throw new Error(`Environment variable ${varName} is not set (referenced in config as ${match})`);
|
|
2138
|
-
});
|
|
2139
|
-
}
|
|
2140
|
-
if (Array.isArray(obj)) {
|
|
2141
|
-
return obj.map((item) => resolveEnvVars(item, env));
|
|
2142
|
-
}
|
|
2143
|
-
if (obj !== null && typeof obj === "object") {
|
|
2144
|
-
const resolved = {};
|
|
2145
|
-
for (const key in obj) {
|
|
2146
|
-
resolved[key] = resolveEnvVars(obj[key], env);
|
|
2147
|
-
}
|
|
2148
|
-
return resolved;
|
|
2149
|
-
}
|
|
2150
|
-
return obj;
|
|
2151
|
-
}
|
|
2152
|
-
function requirePlatform(value, serviceName) {
|
|
2153
|
-
if (!value) {
|
|
2154
|
-
throw new Error(`platform is required for service '${serviceName}' \u2014 add 'platform = "posix"|"container"|"external"' to its config section`);
|
|
2155
|
-
}
|
|
2156
|
-
return value;
|
|
2157
|
-
}
|
|
2158
|
-
function loadTomlConfig(projectRoot, environment, globalConfigPath, reader, env) {
|
|
2159
|
-
const projectConfigContent = projectRoot ? reader.readIfExists(`${projectRoot}/.semiont/config`) : null;
|
|
2160
|
-
const projectConfig = projectConfigContent ? parse(projectConfigContent) : void 0;
|
|
2161
|
-
const projectName = projectConfig?.project?.name ?? "semiont-project";
|
|
2162
|
-
const projectVersion = projectConfig?.project?.version;
|
|
2163
|
-
const projectSite = projectConfig?.site;
|
|
2164
|
-
const globalContent = reader.readIfExists(globalConfigPath);
|
|
2165
|
-
const raw = globalContent ? parse(globalContent) : {};
|
|
2166
|
-
const resolvedEnvironment = environment ?? env.SEMIONT_ENV ?? raw.defaults?.environment;
|
|
2167
|
-
if (!resolvedEnvironment) {
|
|
2168
|
-
throw new Error(
|
|
2169
|
-
"No environment selected: pass one explicitly, set SEMIONT_ENV, or declare `[defaults] environment` in ~/.semiontconfig."
|
|
2170
|
-
);
|
|
2171
|
-
}
|
|
2172
|
-
const projectHasSection = projectConfig?.environments != null && resolvedEnvironment in projectConfig.environments;
|
|
2173
|
-
const globalHasSection = raw.environments != null && resolvedEnvironment in raw.environments;
|
|
2174
|
-
if (!projectHasSection && !globalHasSection) {
|
|
2175
|
-
throw new Error(
|
|
2176
|
-
`Environment "${resolvedEnvironment}" is selected but no [environments.${resolvedEnvironment}] section exists in the project (.semiont/config) or global (~/.semiontconfig) config. Declare the section, or select an environment that exists.`
|
|
2177
|
-
);
|
|
2178
|
-
}
|
|
2179
|
-
const projectEnvSection = projectConfig?.environments?.[resolvedEnvironment] ?? {};
|
|
2180
|
-
const userEnvSection = raw.environments?.[resolvedEnvironment] ?? {};
|
|
2181
|
-
const envSection = deepMerge(
|
|
2182
|
-
projectEnvSection,
|
|
2183
|
-
userEnvSection
|
|
2184
|
-
);
|
|
2185
|
-
const resolved = resolveEnvVars(envSection, env);
|
|
2186
|
-
const flatInference = resolved.inference;
|
|
2187
|
-
const makeMeaningSection = resolved["make-meaning"];
|
|
2188
|
-
const workersSection = resolved.workers ?? {};
|
|
2189
|
-
const actorsSection = resolved.actors ?? {};
|
|
2190
|
-
const defaultWorkerInference = workersSection["default"]?.inference;
|
|
2191
|
-
const defaultMakeMeaningInference = makeMeaningSection?.default?.inference;
|
|
2192
|
-
function mergeWithFlatInference(specific) {
|
|
2193
|
-
if (!flatInference) return specific;
|
|
2194
|
-
const providerDefaults = {};
|
|
2195
|
-
if (specific.type === "anthropic") {
|
|
2196
|
-
const a = flatInference.anthropic;
|
|
2197
|
-
if (a) {
|
|
2198
|
-
providerDefaults.apiKey = a.apiKey;
|
|
2199
|
-
providerDefaults.endpoint = a.endpoint;
|
|
2200
|
-
} else {
|
|
2201
|
-
if (!flatInference.type) {
|
|
2202
|
-
throw new Error(
|
|
2203
|
-
`[environments.${resolvedEnvironment}.inference] is missing 'type'. Add type = "anthropic" or use [inference.anthropic] sub-section.`
|
|
2204
|
-
);
|
|
2205
|
-
}
|
|
2206
|
-
providerDefaults.apiKey = flatInference.apiKey;
|
|
2207
|
-
providerDefaults.endpoint = flatInference.endpoint;
|
|
2208
|
-
}
|
|
2209
|
-
} else if (specific.type === "ollama") {
|
|
2210
|
-
const o = flatInference.ollama;
|
|
2211
|
-
if (o) {
|
|
2212
|
-
providerDefaults.baseURL = o.baseURL;
|
|
2213
|
-
} else {
|
|
2214
|
-
if (!flatInference.type) {
|
|
2215
|
-
throw new Error(
|
|
2216
|
-
`[environments.${resolvedEnvironment}.inference] is missing 'type'. Add type = "ollama" or use [inference.ollama] sub-section.`
|
|
2217
|
-
);
|
|
2218
|
-
}
|
|
2219
|
-
providerDefaults.baseURL = flatInference.baseURL;
|
|
2220
|
-
}
|
|
2221
|
-
}
|
|
2222
|
-
return {
|
|
2223
|
-
maxTokens: flatInference.maxTokens,
|
|
2224
|
-
...providerDefaults,
|
|
2225
|
-
...specific
|
|
2226
|
-
};
|
|
2227
|
-
}
|
|
2228
|
-
function resolveActorInference(fromMakeMeaning, fromActors) {
|
|
2229
|
-
const base = fromMakeMeaning ?? fromActors ?? defaultMakeMeaningInference;
|
|
2230
|
-
if (!base) return void 0;
|
|
2231
|
-
return mergeWithFlatInference(base);
|
|
2232
|
-
}
|
|
2233
|
-
const actors = {};
|
|
2234
|
-
const gathererInference = resolveActorInference(
|
|
2235
|
-
makeMeaningSection?.actors?.gatherer?.inference,
|
|
2236
|
-
actorsSection["gatherer"]?.inference
|
|
2237
|
-
);
|
|
2238
|
-
if (gathererInference) actors.gatherer = gathererInference;
|
|
2239
|
-
const matcherInference = resolveActorInference(
|
|
2240
|
-
makeMeaningSection?.actors?.matcher?.inference,
|
|
2241
|
-
actorsSection["matcher"]?.inference
|
|
2242
|
-
);
|
|
2243
|
-
if (matcherInference) actors.matcher = matcherInference;
|
|
2244
|
-
const workers = {};
|
|
2245
|
-
const workerTypes = ["reference-annotation", "highlight-annotation", "assessment-annotation", "comment-annotation", "tag-annotation", "generation"];
|
|
2246
|
-
if (defaultWorkerInference) {
|
|
2247
|
-
workers.default = mergeWithFlatInference(defaultWorkerInference);
|
|
2248
|
-
}
|
|
2249
|
-
for (const wt of workerTypes) {
|
|
2250
|
-
const specific = workersSection[wt]?.inference;
|
|
2251
|
-
if (specific) {
|
|
2252
|
-
workers[wt] = mergeWithFlatInference(specific);
|
|
2253
|
-
}
|
|
2254
|
-
}
|
|
2255
|
-
const backend = resolved.backend;
|
|
2256
|
-
const site = resolved.site ?? projectSite;
|
|
2257
|
-
const inferenceSection = resolved.inference;
|
|
2258
|
-
let inferenceProviders;
|
|
2259
|
-
if (inferenceSection) {
|
|
2260
|
-
inferenceProviders = {};
|
|
2261
|
-
if (inferenceSection.anthropic) {
|
|
2262
|
-
const a = inferenceSection.anthropic;
|
|
2263
|
-
inferenceProviders.anthropic = {
|
|
2264
|
-
platform: requirePlatform(a.platform, "inference.anthropic"),
|
|
2265
|
-
endpoint: a.endpoint ?? "https://api.anthropic.com",
|
|
2266
|
-
apiKey: a.apiKey ?? ""
|
|
2267
|
-
};
|
|
2268
|
-
} else if (inferenceSection.type === "anthropic") {
|
|
2269
|
-
inferenceProviders.anthropic = {
|
|
2270
|
-
platform: requirePlatform(inferenceSection.platform, "inference"),
|
|
2271
|
-
endpoint: inferenceSection.endpoint ?? "https://api.anthropic.com",
|
|
2272
|
-
apiKey: inferenceSection.apiKey ?? ""
|
|
2273
|
-
};
|
|
2274
|
-
}
|
|
2275
|
-
if (inferenceSection.ollama) {
|
|
2276
|
-
const o = inferenceSection.ollama;
|
|
2277
|
-
inferenceProviders.ollama = {
|
|
2278
|
-
platform: { type: requirePlatform(o.platform, "inference.ollama") },
|
|
2279
|
-
baseURL: o.baseURL,
|
|
2280
|
-
port: o.baseURL ? void 0 : o.port ?? 11434
|
|
2281
|
-
};
|
|
2282
|
-
} else if (inferenceSection.type === "ollama") {
|
|
2283
|
-
inferenceProviders.ollama = {
|
|
2284
|
-
platform: { type: requirePlatform(inferenceSection.platform, "inference") },
|
|
2285
|
-
baseURL: inferenceSection.baseURL,
|
|
2286
|
-
port: inferenceSection.baseURL ? void 0 : 11434
|
|
2287
|
-
};
|
|
2288
|
-
}
|
|
2289
|
-
}
|
|
2290
|
-
const topLevelWorkers = {};
|
|
2291
|
-
for (const [name, w] of Object.entries(workersSection)) {
|
|
2292
|
-
if (w.inference) {
|
|
2293
|
-
topLevelWorkers[name] = { inference: { type: w.inference.type, model: w.inference.model } };
|
|
2294
|
-
}
|
|
2295
|
-
}
|
|
2296
|
-
const topLevelActors = {};
|
|
2297
|
-
for (const [name, a] of Object.entries(actorsSection)) {
|
|
2298
|
-
if (a.inference) {
|
|
2299
|
-
topLevelActors[name] = { inference: { type: a.inference.type, model: a.inference.model } };
|
|
2300
|
-
}
|
|
2301
|
-
}
|
|
2302
|
-
if (makeMeaningSection?.actors?.gatherer?.inference) {
|
|
2303
|
-
topLevelActors["gatherer"] = { inference: { type: makeMeaningSection.actors.gatherer.inference.type, model: makeMeaningSection.actors.gatherer.inference.model } };
|
|
2304
|
-
}
|
|
2305
|
-
if (makeMeaningSection?.actors?.matcher?.inference) {
|
|
2306
|
-
topLevelActors["matcher"] = { inference: { type: makeMeaningSection.actors.matcher.inference.type, model: makeMeaningSection.actors.matcher.inference.model } };
|
|
2307
|
-
}
|
|
2308
|
-
const frontend = resolved.frontend;
|
|
2309
|
-
const services = {};
|
|
2310
|
-
if (backend) {
|
|
2311
|
-
services.backend = {
|
|
2312
|
-
platform: { type: requirePlatform(backend.platform, "backend") },
|
|
2313
|
-
port: backend.port ?? 4e3,
|
|
2314
|
-
publicURL: backend.publicURL ?? `http://localhost:${backend.port ?? 4e3}`
|
|
2315
|
-
};
|
|
2316
|
-
}
|
|
2317
|
-
if (frontend) {
|
|
2318
|
-
services.frontend = {
|
|
2319
|
-
platform: { type: requirePlatform(frontend.platform, "frontend") },
|
|
2320
|
-
port: frontend.port ?? 3e3,
|
|
2321
|
-
siteName: site?.siteName ?? "Semiont",
|
|
2322
|
-
publicURL: frontend.publicURL
|
|
2323
|
-
};
|
|
2324
|
-
}
|
|
2325
|
-
if (resolved.graph) {
|
|
2326
|
-
services.graph = {
|
|
2327
|
-
...resolved.graph,
|
|
2328
|
-
platform: { type: requirePlatform(resolved.graph.platform, "graph") },
|
|
2329
|
-
type: resolved.graph.type ?? "neo4j"
|
|
2330
|
-
};
|
|
2331
|
-
} else if (makeMeaningSection?.graph) {
|
|
2332
|
-
services.graph = makeMeaningSection.graph;
|
|
2333
|
-
}
|
|
2334
|
-
if (resolved.database) {
|
|
2335
|
-
services.database = {
|
|
2336
|
-
platform: { type: requirePlatform(resolved.database.platform, "database") },
|
|
2337
|
-
type: "postgres",
|
|
2338
|
-
image: resolved.database.image,
|
|
2339
|
-
host: resolved.database.host ?? "localhost",
|
|
2340
|
-
port: resolved.database.port ?? 5432,
|
|
2341
|
-
name: resolved.database.name,
|
|
2342
|
-
user: resolved.database.user,
|
|
2343
|
-
password: resolved.database.password
|
|
2344
|
-
};
|
|
2345
|
-
}
|
|
2346
|
-
if (resolved.vectors) {
|
|
2347
|
-
services.vectors = {
|
|
2348
|
-
platform: { type: "external" },
|
|
2349
|
-
type: resolved.vectors.type ?? "qdrant",
|
|
2350
|
-
host: resolved.vectors.host,
|
|
2351
|
-
port: resolved.vectors.port ?? 6333
|
|
2352
|
-
};
|
|
2353
|
-
}
|
|
2354
|
-
const embeddingSource = resolved.embedding ?? resolved.vectors?.embedding;
|
|
2355
|
-
if (embeddingSource) {
|
|
2356
|
-
services.embedding = {
|
|
2357
|
-
platform: { type: "external" },
|
|
2358
|
-
type: embeddingSource.type,
|
|
2359
|
-
model: embeddingSource.model,
|
|
2360
|
-
apiKey: embeddingSource.apiKey,
|
|
2361
|
-
baseURL: embeddingSource.baseURL,
|
|
2362
|
-
endpoint: embeddingSource.endpoint,
|
|
2363
|
-
chunking: resolved.embedding?.chunking ?? resolved.vectors?.chunking ? {
|
|
2364
|
-
chunkSize: (resolved.embedding?.chunking ?? resolved.vectors?.chunking)?.chunkSize ?? 512,
|
|
2365
|
-
overlap: (resolved.embedding?.chunking ?? resolved.vectors?.chunking)?.overlap ?? 64
|
|
2366
|
-
} : void 0
|
|
2367
|
-
};
|
|
2368
|
-
}
|
|
2369
|
-
const config = {
|
|
2370
|
-
services,
|
|
2371
|
-
...inferenceProviders ? { inference: inferenceProviders } : {},
|
|
2372
|
-
...Object.keys(topLevelWorkers).length > 0 ? { workers: topLevelWorkers } : {},
|
|
2373
|
-
...Object.keys(topLevelActors).length > 0 ? { actors: topLevelActors } : {},
|
|
2374
|
-
site: site ? {
|
|
2375
|
-
domain: site.domain ?? "localhost",
|
|
2376
|
-
siteName: site.siteName,
|
|
2377
|
-
adminEmail: site.adminEmail,
|
|
2378
|
-
oauthAllowedDomains: site.oauthAllowedDomains
|
|
2379
|
-
} : void 0,
|
|
2380
|
-
logLevel: resolved.logLevel,
|
|
2381
|
-
_metadata: {
|
|
2382
|
-
environment: resolvedEnvironment,
|
|
2383
|
-
projectRoot,
|
|
2384
|
-
projectName,
|
|
2385
|
-
projectVersion,
|
|
2386
|
-
...Object.keys(actors).length > 0 ? { actors } : {},
|
|
2387
|
-
...Object.keys(workers).length > 0 ? { workers } : {},
|
|
2388
|
-
// Always set — the loader is the ONE home of this default (D5).
|
|
2389
|
-
// Consuming code (make-meaning's gather path) receives a required
|
|
2390
|
-
// value and defaults nothing.
|
|
2391
|
-
gather: { settleTimeoutMs: makeMeaningSection?.gather?.settleTimeoutMs ?? 15e3 }
|
|
2392
|
-
}
|
|
2393
|
-
};
|
|
2394
|
-
return config;
|
|
2395
|
-
}
|
|
2396
|
-
function createTomlConfigLoader(reader, globalConfigPath, env) {
|
|
2397
|
-
return (projectRoot, environment) => {
|
|
2398
|
-
return loadTomlConfig(projectRoot, environment, globalConfigPath, reader, env);
|
|
2399
|
-
};
|
|
2400
|
-
}
|
|
2401
1803
|
|
|
2402
1804
|
// src/config/environment-validator.ts
|
|
2403
1805
|
function isValidEnvironment(value, availableEnvironments) {
|
|
@@ -2523,6 +1925,6 @@ async function retryWithBackoff(fn, isRetryable, policy, onRetry) {
|
|
|
2523
1925
|
// src/discovery.ts
|
|
2524
1926
|
var DISCOVERY_URL_PATH = "/discovery/kbs.json";
|
|
2525
1927
|
|
|
2526
|
-
export { AUTHORABLE_MEDIA_TYPES,
|
|
1928
|
+
export { AUTHORABLE_MEDIA_TYPES, BusRequestError, CHANNEL_SCHEMAS, CONTEXT_FULL_WEIGHT, CONTEXT_PARTIAL_WEIGHT, ConfigurationError, ConflictError, DISCOVERY_URL_PATH, EMBEDDABLE_MEDIA_TYPES, JWTTokenSchema, LOCALES, MEDIA_TYPES, NotFoundError, PERSISTED_EVENT_TYPES, POSITION_WEIGHT_MAX, POSITION_WINDOW, RESOURCE_BROADCAST_TYPES, STARTUP_FETCH_RETRY, ScriptError, SemiontError, UnauthorizedError, ValidationError, agentToDid, anchorAnnotation, annotationId, applyBodyOperations, assembleAnnotation, baseMediaType, buildContentCache, burstBuffer, busRequest, capabilitiesOf, createCircleSvg, createFragmentSelector, createPolygonSvg, createRectangleSvg, decodeRepresentation, decodeWithCharset, deriveViews, didToAgent, errField, extensionForMediaType, extractBoundingBox, extractCharset, extractContext, findBestTextMatch, findBodyItem, formatLocaleDisplay, generateUuid, getAllLocaleCodes, getAllPlatformTypes, getAnnotationExactText, getAnnotationUriFromEvent, getBodySource, getBodyType, getChecksum, getCommentText, getCreator, getDerivedFrom, getExactText, getFragmentSelector, getLanguage, getLocaleEnglishName, getLocaleInfo, getLocaleNativeName, getNodeEncoding, getPageFromFragment, getPrimaryMediaType, getPrimaryRepresentation, getPrimarySelector, getResourceEntityTypes, getResourceId, getStorageUri, getSvgSelector, getTargetSelector, getTargetSource, getTextPositionSelector, getTextQuoteSelector, hasTargetSelector, isAnnotationId, isArchived, isArray, isAssessment, isBodyResolved, isBoolean, isComment, isDefined, isDraft, isEventRelatedToAnnotation, isFunction, isHighlight, isNull, isNullish, isNumber, isObject, isReference, isResolvedReference, isResourceId, isStoredEvent, isString, isStubReference, isSupportedMediaType, isTag, isTransientFetchError, isUndefined, isValidEmail, isValidPlatformType, kbDid, mediaTypeForExtension, normalizeCoordinates, normalizeText, parseEnvironment, parseFragmentSelector, parseSvgSelector, reconcileSelector, resourceId, retryWithBackoff, scaleSvgToNative, serializePerKey, softwareToAgent, textExtractionOf, userId, userToAgent, userToDid, uuidV4, validateData, validateEnvironment, validateSvgMarkup, verifyPosition };
|
|
2527
1929
|
//# sourceMappingURL=index.js.map
|
|
2528
1930
|
//# sourceMappingURL=index.js.map
|