@semiont/make-meaning 0.4.21 → 0.5.0

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/index.js CHANGED
@@ -1399,26 +1399,26 @@ var require_BehaviorSubject = __commonJS({
1399
1399
  Object.defineProperty(exports, "__esModule", { value: true });
1400
1400
  exports.BehaviorSubject = void 0;
1401
1401
  var Subject_1 = require_Subject();
1402
- var BehaviorSubject = (function(_super) {
1403
- __extends(BehaviorSubject2, _super);
1404
- function BehaviorSubject2(_value) {
1402
+ var BehaviorSubject2 = (function(_super) {
1403
+ __extends(BehaviorSubject3, _super);
1404
+ function BehaviorSubject3(_value) {
1405
1405
  var _this = _super.call(this) || this;
1406
1406
  _this._value = _value;
1407
1407
  return _this;
1408
1408
  }
1409
- Object.defineProperty(BehaviorSubject2.prototype, "value", {
1409
+ Object.defineProperty(BehaviorSubject3.prototype, "value", {
1410
1410
  get: function() {
1411
1411
  return this.getValue();
1412
1412
  },
1413
1413
  enumerable: false,
1414
1414
  configurable: true
1415
1415
  });
1416
- BehaviorSubject2.prototype._subscribe = function(subscriber) {
1416
+ BehaviorSubject3.prototype._subscribe = function(subscriber) {
1417
1417
  var subscription = _super.prototype._subscribe.call(this, subscriber);
1418
1418
  !subscription.closed && subscriber.next(this._value);
1419
1419
  return subscription;
1420
1420
  };
1421
- BehaviorSubject2.prototype.getValue = function() {
1421
+ BehaviorSubject3.prototype.getValue = function() {
1422
1422
  var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, _value = _a._value;
1423
1423
  if (hasError) {
1424
1424
  throw thrownError;
@@ -1426,12 +1426,12 @@ var require_BehaviorSubject = __commonJS({
1426
1426
  this._throwIfClosed();
1427
1427
  return _value;
1428
1428
  };
1429
- BehaviorSubject2.prototype.next = function(value) {
1429
+ BehaviorSubject3.prototype.next = function(value) {
1430
1430
  _super.prototype.next.call(this, this._value = value);
1431
1431
  };
1432
- return BehaviorSubject2;
1432
+ return BehaviorSubject3;
1433
1433
  })(Subject_1.Subject);
1434
- exports.BehaviorSubject = BehaviorSubject;
1434
+ exports.BehaviorSubject = BehaviorSubject2;
1435
1435
  }
1436
1436
  });
1437
1437
 
@@ -9945,7 +9945,8 @@ var require_operators = __commonJS({
9945
9945
  // src/service.ts
9946
9946
  import { FsJobQueue } from "@semiont/jobs";
9947
9947
  import { createEventStore as createEventStoreCore } from "@semiont/event-sourcing";
9948
- import { jobId } from "@semiont/core";
9948
+ import { jobId as jobId2 } from "@semiont/core";
9949
+ import { registerJobQueueProvider } from "@semiont/observability";
9949
9950
 
9950
9951
  // src/config.ts
9951
9952
  function resolveActorInference(config, actor) {
@@ -10314,20 +10315,20 @@ var GraphDBConsumer = class _GraphDBConsumer {
10314
10315
  * Rebuild entire resource from events.
10315
10316
  * Bypasses the live pipeline — reads directly from event store.
10316
10317
  */
10317
- async rebuildResource(resourceId7) {
10318
+ async rebuildResource(resourceId10) {
10318
10319
  const graphDb = this.ensureInitialized();
10319
- this.logger.info("Rebuilding resource from events", { resourceId: resourceId7 });
10320
+ this.logger.info("Rebuilding resource from events", { resourceId: resourceId10 });
10320
10321
  try {
10321
- await graphDb.deleteResource(resourceId7);
10322
+ await graphDb.deleteResource(resourceId10);
10322
10323
  } catch (error) {
10323
- this.logger.debug("No existing resource to delete", { resourceId: resourceId7 });
10324
+ this.logger.debug("No existing resource to delete", { resourceId: resourceId10 });
10324
10325
  }
10325
10326
  const query = new EventQuery(this.eventStore.log.storage);
10326
- const events = await query.getResourceEvents(resourceId7);
10327
+ const events = await query.getResourceEvents(resourceId10);
10327
10328
  for (const storedEvent of events) {
10328
10329
  await this.safeApplyEvent(storedEvent);
10329
10330
  }
10330
- this.logger.info("Resource rebuild complete", { resourceId: resourceId7, eventCount: events.length });
10331
+ this.logger.info("Resource rebuild complete", { resourceId: resourceId10, eventCount: events.length });
10331
10332
  }
10332
10333
  /**
10333
10334
  * Rebuild entire GraphDB from all events.
@@ -10343,8 +10344,8 @@ var GraphDBConsumer = class _GraphDBConsumer {
10343
10344
  const allResourceIds = await this.eventStore.log.getAllResourceIds();
10344
10345
  this.logger.info("Found resources to rebuild", { count: allResourceIds.length });
10345
10346
  this.logger.info("PASS 1: Creating all nodes (resources + annotations)");
10346
- for (const resourceId7 of allResourceIds) {
10347
- const events = await query.getResourceEvents(makeResourceId(resourceId7));
10347
+ for (const resourceId10 of allResourceIds) {
10348
+ const events = await query.getResourceEvents(makeResourceId(resourceId10));
10348
10349
  for (const storedEvent of events) {
10349
10350
  if (storedEvent.type === "mark:body-updated") {
10350
10351
  continue;
@@ -10354,8 +10355,8 @@ var GraphDBConsumer = class _GraphDBConsumer {
10354
10355
  }
10355
10356
  this.logger.info("Pass 1 complete - all nodes created");
10356
10357
  this.logger.info("PASS 2: Creating all REFERENCES edges");
10357
- for (const resourceId7 of allResourceIds) {
10358
- const events = await query.getResourceEvents(makeResourceId(resourceId7));
10358
+ for (const resourceId10 of allResourceIds) {
10359
+ const events = await query.getResourceEvents(makeResourceId(resourceId10));
10359
10360
  for (const storedEvent of events) {
10360
10361
  if (storedEvent.type === "mark:body-updated") {
10361
10362
  await this.safeApplyEvent(storedEvent);
@@ -10420,6 +10421,7 @@ async function createKnowledgeBase(eventStore, project, graphDb, eventBus, logge
10420
10421
  var import_rxjs2 = __toESM(require_cjs(), 1);
10421
10422
  var import_operators2 = __toESM(require_operators(), 1);
10422
10423
  import { annotationId as makeAnnotationId2, resourceId, errField as errField2 } from "@semiont/core";
10424
+ import { withActorSpan } from "@semiont/observability";
10423
10425
 
10424
10426
  // src/generation/resource-generation.ts
10425
10427
  async function generateResourceSummary(resourceName, content, entityTypes, client) {
@@ -10431,10 +10433,10 @@ Resource content:
10431
10433
  ${truncatedContent}
10432
10434
 
10433
10435
  Write a 2-3 sentence summary that captures the key points and would help someone understand what this resource contains.`;
10434
- return await client.generateText(prompt, 150, 0.5);
10436
+ return client.generateText(prompt, 150, 0.5);
10435
10437
  }
10436
- async function generateReferenceSuggestions(referenceTitle, client, entityType, currentContent) {
10437
- const prompt = `For a reference titled "${referenceTitle}"${entityType ? ` (type: ${entityType})` : ""}${currentContent ? ` with current stub: "${currentContent}"` : ""}, suggest 3 specific, actionable next steps or related topics to explore.
10438
+ async function generateReferenceSuggestions(referenceTitle, client, entityType2, currentContent) {
10439
+ const prompt = `For a reference titled "${referenceTitle}"${entityType2 ? ` (type: ${entityType2})` : ""}${currentContent ? ` with current stub: "${currentContent}"` : ""}, suggest 3 specific, actionable next steps or related topics to explore.
10438
10440
 
10439
10441
  Format as a simple list, one suggestion per line.`;
10440
10442
  const response = await client.generateText(prompt, 200, 0.8);
@@ -10445,27 +10447,18 @@ Format as a simple list, one suggestion per line.`;
10445
10447
  }
10446
10448
 
10447
10449
  // src/annotation-context.ts
10448
- import {
10449
- getBodySource,
10450
- getResourceId,
10451
- getTargetSource,
10452
- getTargetSelector,
10453
- getResourceEntityTypes,
10454
- getTextPositionSelector,
10455
- getPrimaryRepresentation as getPrimaryRepresentation2,
10456
- decodeRepresentation as decodeRepresentation2
10457
- } from "@semiont/api-client";
10450
+ import { getBodySource, getResourceId, getTargetSource, getTargetSelector, getResourceEntityTypes, getTextPositionSelector, getPrimaryRepresentation as getPrimaryRepresentation2, decodeRepresentation as decodeRepresentation2 } from "@semiont/core";
10458
10451
  import { resourceId as createResourceId } from "@semiont/core";
10459
10452
  import { getEntityTypes } from "@semiont/ontology";
10460
10453
 
10461
10454
  // src/resource-context.ts
10462
- import { getPrimaryRepresentation, decodeRepresentation } from "@semiont/api-client";
10455
+ import { getPrimaryRepresentation, decodeRepresentation } from "@semiont/core";
10463
10456
  var ResourceContext = class _ResourceContext {
10464
10457
  /**
10465
10458
  * Get resource metadata from view storage
10466
10459
  */
10467
- static async getResourceMetadata(resourceId7, kb) {
10468
- const view = await kb.views.get(resourceId7);
10460
+ static async getResourceMetadata(resourceId10, kb) {
10461
+ const view = await kb.views.get(resourceId10);
10469
10462
  if (!view) {
10470
10463
  return null;
10471
10464
  }
@@ -10510,7 +10503,7 @@ var ResourceContext = class _ResourceContext {
10510
10503
  * Retrieves and decodes the first 200 characters of each resource's primary representation
10511
10504
  */
10512
10505
  static async addContentPreviews(resources, kb) {
10513
- return await Promise.all(
10506
+ return Promise.all(
10514
10507
  resources.map(async (doc) => {
10515
10508
  try {
10516
10509
  if (doc.storageUri) {
@@ -10553,7 +10546,7 @@ var AnnotationContext = class {
10553
10546
  * @returns Rich context for LLM processing
10554
10547
  * @throws Error if annotation or resource not found
10555
10548
  */
10556
- static async buildLLMContext(annotationId3, resourceId7, kb, options = {}, inferenceClient, logger, embeddingProvider) {
10549
+ static async buildLLMContext(annotationId5, resourceId10, kb, options = {}, inferenceClient, logger, embeddingProvider) {
10557
10550
  const {
10558
10551
  includeSourceContext = true,
10559
10552
  includeTargetContext = true,
@@ -10562,34 +10555,34 @@ var AnnotationContext = class {
10562
10555
  if (contextWindow < 100 || contextWindow > 5e3) {
10563
10556
  throw new Error("contextWindow must be between 100 and 5000");
10564
10557
  }
10565
- logger?.debug("Building LLM context", { annotationId: annotationId3, resourceId: resourceId7 });
10566
- logger?.debug("Getting view for resource", { resourceId: resourceId7 });
10558
+ logger?.debug("Building LLM context", { annotationId: annotationId5, resourceId: resourceId10 });
10559
+ logger?.debug("Getting view for resource", { resourceId: resourceId10 });
10567
10560
  let sourceView;
10568
10561
  try {
10569
- sourceView = await kb.views.get(resourceId7);
10562
+ sourceView = await kb.views.get(resourceId10);
10570
10563
  logger?.debug("Retrieved view", { hasView: !!sourceView });
10571
10564
  if (!sourceView) {
10572
10565
  throw new Error("Source resource not found");
10573
10566
  }
10574
10567
  } catch (error) {
10575
- logger?.error("Error getting view", { resourceId: resourceId7, error });
10568
+ logger?.error("Error getting view", { resourceId: resourceId10, error });
10576
10569
  throw error;
10577
10570
  }
10578
10571
  logger?.debug("Looking for annotation in resource", {
10579
- annotationId: annotationId3,
10580
- resourceId: resourceId7,
10572
+ annotationId: annotationId5,
10573
+ resourceId: resourceId10,
10581
10574
  totalAnnotations: sourceView.annotations.annotations.length,
10582
10575
  firstFiveIds: sourceView.annotations.annotations.slice(0, 5).map((a) => a.id)
10583
10576
  });
10584
- const annotation = sourceView.annotations.annotations.find((a) => a.id === annotationId3);
10577
+ const annotation = sourceView.annotations.annotations.find((a) => a.id === annotationId5);
10585
10578
  logger?.debug("Annotation search result", { found: !!annotation });
10586
10579
  if (!annotation) {
10587
10580
  throw new Error("Annotation not found in view");
10588
10581
  }
10589
10582
  const targetSource = getTargetSource(annotation.target);
10590
- logger?.debug("Validating target resource", { targetSource, expectedResourceId: resourceId7 });
10591
- if (targetSource !== String(resourceId7)) {
10592
- throw new Error(`Annotation target resource ID (${targetSource}) does not match expected resource ID (${resourceId7})`);
10583
+ logger?.debug("Validating target resource", { targetSource, expectedResourceId: resourceId10 });
10584
+ if (targetSource !== String(resourceId10)) {
10585
+ throw new Error(`Annotation target resource ID (${targetSource}) does not match expected resource ID (${resourceId10})`);
10593
10586
  }
10594
10587
  const sourceDoc = sourceView.resource;
10595
10588
  const bodySource = getBodySource(annotation.body);
@@ -10653,16 +10646,16 @@ var AnnotationContext = class {
10653
10646
  }
10654
10647
  }
10655
10648
  const suggestedResolution = void 0;
10656
- logger?.debug("Building graph context", { resourceId: resourceId7 });
10649
+ logger?.debug("Building graph context", { resourceId: resourceId10 });
10657
10650
  const [connections, referencedByAnnotations, entityTypeStats] = await Promise.all([
10658
- kb.graph.getResourceConnections(resourceId7),
10659
- kb.graph.getResourceReferencedBy(resourceId7),
10651
+ kb.graph.getResourceConnections(resourceId10),
10652
+ kb.graph.getResourceReferencedBy(resourceId10),
10660
10653
  kb.graph.getEntityTypeStats()
10661
10654
  ]);
10662
10655
  const citedByMap = /* @__PURE__ */ new Map();
10663
10656
  for (const ann of referencedByAnnotations) {
10664
10657
  const source = getTargetSource(ann.target);
10665
- if (source && source !== String(resourceId7)) {
10658
+ if (source && source !== String(resourceId10)) {
10666
10659
  const sourceResId = createResourceId(source);
10667
10660
  const sourceView2 = await kb.views.get(sourceResId);
10668
10661
  if (sourceView2?.resource) {
@@ -10673,7 +10666,7 @@ var AnnotationContext = class {
10673
10666
  const annotationEntityTypes = getEntityTypes(annotation);
10674
10667
  const siblingEntityTypes = /* @__PURE__ */ new Set();
10675
10668
  for (const ann of sourceView.annotations.annotations) {
10676
- if (ann.id !== annotationId3) {
10669
+ if (ann.id !== annotationId5) {
10677
10670
  for (const et of getEntityTypes(ann)) {
10678
10671
  siblingEntityTypes.add(et);
10679
10672
  }
@@ -10734,7 +10727,7 @@ Summary:`;
10734
10727
  const results = await kb.vectors.searchAnnotations(focalEmbedding, {
10735
10728
  limit: 10,
10736
10729
  scoreThreshold: 0.5,
10737
- filter: { excludeResourceId: resourceId7 }
10730
+ filter: { excludeResourceId: resourceId10 }
10738
10731
  });
10739
10732
  if (results.length > 0) {
10740
10733
  semanticContext = {
@@ -10786,10 +10779,10 @@ Summary:`;
10786
10779
  * Get resource annotations from view storage (fast path)
10787
10780
  * Throws if view missing
10788
10781
  */
10789
- static async getResourceAnnotations(resourceId7, kb) {
10790
- const view = await kb.views.get(resourceId7);
10782
+ static async getResourceAnnotations(resourceId10, kb) {
10783
+ const view = await kb.views.get(resourceId10);
10791
10784
  if (!view) {
10792
- throw new Error(`Resource ${resourceId7} not found in view storage`);
10785
+ throw new Error(`Resource ${resourceId10} not found in view storage`);
10793
10786
  }
10794
10787
  return view.annotations;
10795
10788
  }
@@ -10797,9 +10790,9 @@ Summary:`;
10797
10790
  * Get all annotations
10798
10791
  * @returns Array of all annotation objects
10799
10792
  */
10800
- static async getAllAnnotations(resourceId7, kb) {
10801
- const annotations = await this.getResourceAnnotations(resourceId7, kb);
10802
- return await this.enrichResolvedReferences(annotations.annotations, kb);
10793
+ static async getAllAnnotations(resourceId10, kb) {
10794
+ const annotations = await this.getResourceAnnotations(resourceId10, kb);
10795
+ return this.enrichResolvedReferences(annotations.annotations, kb);
10803
10796
  }
10804
10797
  /**
10805
10798
  * Enrich reference annotations with resolved document names
@@ -10867,8 +10860,8 @@ Summary:`;
10867
10860
  * Get resource stats (version info)
10868
10861
  * @returns Version and timestamp info for the annotations
10869
10862
  */
10870
- static async getResourceStats(resourceId7, kb) {
10871
- const annotations = await this.getResourceAnnotations(resourceId7, kb);
10863
+ static async getResourceStats(resourceId10, kb) {
10864
+ const annotations = await this.getResourceAnnotations(resourceId10, kb);
10872
10865
  return {
10873
10866
  resourceId: annotations.resourceId,
10874
10867
  version: annotations.version,
@@ -10878,16 +10871,16 @@ Summary:`;
10878
10871
  /**
10879
10872
  * Check if resource exists in view storage
10880
10873
  */
10881
- static async resourceExists(resourceId7, kb) {
10882
- return await kb.views.exists(resourceId7);
10874
+ static async resourceExists(resourceId10, kb) {
10875
+ return kb.views.exists(resourceId10);
10883
10876
  }
10884
10877
  /**
10885
10878
  * Get a single annotation by ID
10886
10879
  * O(1) lookup using resource ID to access view storage
10887
10880
  */
10888
- static async getAnnotation(annotationId3, resourceId7, kb) {
10889
- const annotations = await this.getResourceAnnotations(resourceId7, kb);
10890
- return annotations.annotations.find((a) => a.id === annotationId3) || null;
10881
+ static async getAnnotation(annotationId5, resourceId10, kb) {
10882
+ const annotations = await this.getResourceAnnotations(resourceId10, kb);
10883
+ return annotations.annotations.find((a) => a.id === annotationId5) || null;
10891
10884
  }
10892
10885
  /**
10893
10886
  * List annotations with optional filtering
@@ -10898,13 +10891,13 @@ Summary:`;
10898
10891
  if (!filters?.resourceId) {
10899
10892
  throw new Error("resourceId is required for annotation listing - cross-resource queries not supported in view storage");
10900
10893
  }
10901
- return await this.getAllAnnotations(filters.resourceId, kb);
10894
+ return this.getAllAnnotations(filters.resourceId, kb);
10902
10895
  }
10903
10896
  /**
10904
10897
  * Get annotation context (selected text with surrounding context)
10905
10898
  */
10906
- static async getAnnotationContext(annotationId3, resourceId7, contextBefore, contextAfter, kb) {
10907
- const annotation = await this.getAnnotation(annotationId3, resourceId7, kb);
10899
+ static async getAnnotationContext(annotationId5, resourceId10, contextBefore, contextAfter, kb) {
10900
+ const annotation = await this.getAnnotation(annotationId5, resourceId10, kb);
10908
10901
  if (!annotation) {
10909
10902
  throw new Error("Annotation not found");
10910
10903
  }
@@ -10936,8 +10929,8 @@ Summary:`;
10936
10929
  /**
10937
10930
  * Generate AI summary of annotation in context
10938
10931
  */
10939
- static async generateAnnotationSummary(annotationId3, resourceId7, kb, inferenceClient) {
10940
- const annotation = await this.getAnnotation(annotationId3, resourceId7, kb);
10932
+ static async generateAnnotationSummary(annotationId5, resourceId10, kb, inferenceClient) {
10933
+ const annotation = await this.getAnnotation(annotationId5, resourceId10, kb);
10941
10934
  if (!annotation) {
10942
10935
  throw new Error("Annotation not found");
10943
10936
  }
@@ -11012,51 +11005,51 @@ Context after: "${context.after.substring(0, 200)}"
11012
11005
 
11013
11006
  Resource: ${resource.name}
11014
11007
  Entity types: ${entityTypes.join(", ")}`;
11015
- return await inferenceClient.generateText(summaryPrompt, 500, 0.5);
11008
+ return inferenceClient.generateText(summaryPrompt, 500, 0.5);
11016
11009
  }
11017
11010
  };
11018
11011
 
11019
11012
  // src/graph-context.ts
11020
- import { getResourceId as getResourceId2, getResourceEntityTypes as getResourceEntityTypes2 } from "@semiont/api-client";
11013
+ import { getResourceId as getResourceId2, getResourceEntityTypes as getResourceEntityTypes2 } from "@semiont/core";
11021
11014
  var GraphContext = class {
11022
11015
  /**
11023
11016
  * Get all resources referencing this resource (backlinks)
11024
11017
  * Requires graph traversal - must use graph database
11025
11018
  */
11026
- static async getBacklinks(resourceId7, kb) {
11027
- return await kb.graph.getResourceReferencedBy(resourceId7);
11019
+ static async getBacklinks(resourceId10, kb) {
11020
+ return kb.graph.getResourceReferencedBy(resourceId10);
11028
11021
  }
11029
11022
  /**
11030
11023
  * Find shortest path between two resources
11031
11024
  * Requires graph traversal - must use graph database
11032
11025
  */
11033
11026
  static async findPath(fromResourceId, toResourceId, kb, maxDepth) {
11034
- return await kb.graph.findPath(fromResourceId, toResourceId, maxDepth);
11027
+ return kb.graph.findPath(fromResourceId, toResourceId, maxDepth);
11035
11028
  }
11036
11029
  /**
11037
11030
  * Get resource connections (graph edges)
11038
11031
  * Requires graph traversal - must use graph database
11039
11032
  */
11040
- static async getResourceConnections(resourceId7, kb) {
11041
- return await kb.graph.getResourceConnections(resourceId7);
11033
+ static async getResourceConnections(resourceId10, kb) {
11034
+ return kb.graph.getResourceConnections(resourceId10);
11042
11035
  }
11043
11036
  /**
11044
11037
  * Search resources by name (cross-resource query)
11045
11038
  * Requires full-text search - must use graph database
11046
11039
  */
11047
11040
  static async searchResources(query, kb, limit) {
11048
- return await kb.graph.searchResources(query, limit);
11041
+ return kb.graph.searchResources(query, limit);
11049
11042
  }
11050
11043
  /**
11051
11044
  * Build graph representation with nodes and edges for a resource and its connections
11052
11045
  * Retrieves connections from graph and builds visualization-ready structure
11053
11046
  */
11054
- static async buildGraphRepresentation(resourceId7, maxRelated, kb) {
11055
- const mainDoc = await kb.graph.getResource(resourceId7);
11047
+ static async buildGraphRepresentation(resourceId10, maxRelated, kb) {
11048
+ const mainDoc = await kb.graph.getResource(resourceId10);
11056
11049
  if (!mainDoc) {
11057
11050
  throw new Error("Resource not found");
11058
11051
  }
11059
- const connections = await kb.graph.getResourceConnections(resourceId7);
11052
+ const connections = await kb.graph.getResourceConnections(resourceId10);
11060
11053
  const relatedDocs = connections.map((conn) => conn.targetResource).slice(0, maxRelated - 1);
11061
11054
  const nodes = [
11062
11055
  {
@@ -11073,7 +11066,7 @@ var GraphContext = class {
11073
11066
  }))
11074
11067
  ].filter((node) => node.id !== void 0);
11075
11068
  const edges = connections.slice(0, maxRelated - 1).map((conn) => ({
11076
- source: resourceId7,
11069
+ source: resourceId10,
11077
11070
  target: getResourceId2(conn.targetResource),
11078
11071
  type: conn.relationshipType || "link",
11079
11072
  metadata: {}
@@ -11083,26 +11076,26 @@ var GraphContext = class {
11083
11076
  };
11084
11077
 
11085
11078
  // src/llm-context.ts
11086
- import { getResourceEntityTypes as getResourceEntityTypes3, getResourceId as getResourceId3 } from "@semiont/api-client";
11079
+ import { getResourceEntityTypes as getResourceEntityTypes3, getResourceId as getResourceId3 } from "@semiont/core";
11087
11080
  import { resourceId as makeResourceId2 } from "@semiont/core";
11088
11081
  var LLMContext = class {
11089
11082
  /**
11090
11083
  * Get comprehensive LLM context for a resource
11091
11084
  * Includes: main resource, related resources, annotations, graph, content, summary, references
11092
11085
  */
11093
- static async getResourceContext(resourceId7, options, kb, inferenceClient) {
11094
- const mainDoc = await ResourceContext.getResourceMetadata(resourceId7, kb);
11086
+ static async getResourceContext(resourceId10, options, kb, inferenceClient) {
11087
+ const mainDoc = await ResourceContext.getResourceMetadata(resourceId10, kb);
11095
11088
  if (!mainDoc) {
11096
11089
  throw new Error("Resource not found");
11097
11090
  }
11098
11091
  const mainContent = options.includeContent ? await ResourceContext.getResourceContent(mainDoc, kb) : void 0;
11099
11092
  const graph = await GraphContext.buildGraphRepresentation(
11100
- resourceId7,
11093
+ resourceId10,
11101
11094
  options.maxResources,
11102
11095
  kb
11103
11096
  );
11104
11097
  const relatedDocs = [];
11105
- const resourceIdStr = resourceId7.toString();
11098
+ const resourceIdStr = resourceId10.toString();
11106
11099
  for (const node of graph.nodes) {
11107
11100
  if (node.id !== resourceIdStr) {
11108
11101
  const relatedDoc = await ResourceContext.getResourceMetadata(makeResourceId2(node.id), kb);
@@ -11124,7 +11117,7 @@ var LLMContext = class {
11124
11117
  })
11125
11118
  );
11126
11119
  }
11127
- const annotations = await AnnotationContext.getAllAnnotations(resourceId7, kb);
11120
+ const annotations = await AnnotationContext.getAllAnnotations(resourceId10, kb);
11128
11121
  const summary = options.includeSummary && mainContent ? await generateResourceSummary(
11129
11122
  mainDoc.name,
11130
11123
  mainContent,
@@ -11163,7 +11156,9 @@ var Gatherer = class {
11163
11156
  (0, import_operators2.groupBy)((event) => event.resourceId),
11164
11157
  (0, import_operators2.mergeMap)(
11165
11158
  (group$) => group$.pipe(
11166
- (0, import_operators2.concatMap)((event) => (0, import_rxjs2.from)(this.handleAnnotationGather(event)))
11159
+ (0, import_operators2.concatMap)(
11160
+ (event) => (0, import_rxjs2.from)(withActorSpan("gatherer", "gather:requested", () => this.handleAnnotationGather(event)))
11161
+ )
11167
11162
  )
11168
11163
  )
11169
11164
  );
@@ -11171,7 +11166,9 @@ var Gatherer = class {
11171
11166
  (0, import_operators2.groupBy)((event) => event.resourceId),
11172
11167
  (0, import_operators2.mergeMap)(
11173
11168
  (group$) => group$.pipe(
11174
- (0, import_operators2.concatMap)((event) => (0, import_rxjs2.from)(this.handleResourceGather(event)))
11169
+ (0, import_operators2.concatMap)(
11170
+ (event) => (0, import_rxjs2.from)(withActorSpan("gatherer", "gather:resource-requested", () => this.handleResourceGather(event)))
11171
+ )
11175
11172
  )
11176
11173
  )
11177
11174
  );
@@ -11243,10 +11240,10 @@ var Gatherer = class {
11243
11240
  });
11244
11241
  }
11245
11242
  }
11246
- async generateAnnotationSummary(annotationId3, resourceId7) {
11243
+ async generateAnnotationSummary(annotationId5, resourceId10) {
11247
11244
  return AnnotationContext.generateAnnotationSummary(
11248
- annotationId3,
11249
- resourceId7,
11245
+ annotationId5,
11246
+ resourceId10,
11250
11247
  this.kb,
11251
11248
  this.inferenceClient
11252
11249
  );
@@ -11264,7 +11261,8 @@ var Gatherer = class {
11264
11261
  var import_rxjs3 = __toESM(require_cjs(), 1);
11265
11262
  var import_operators3 = __toESM(require_operators(), 1);
11266
11263
  import { resourceId as resourceId2, errField as errField3 } from "@semiont/core";
11267
- import { getResourceId as getResourceId4, getResourceEntityTypes as getResourceEntityTypes4 } from "@semiont/api-client";
11264
+ import { getResourceId as getResourceId4, getResourceEntityTypes as getResourceEntityTypes4 } from "@semiont/core";
11265
+ import { withActorSpan as withActorSpan2 } from "@semiont/observability";
11268
11266
  var Matcher = class {
11269
11267
  constructor(kb, eventBus, logger, inferenceClient, embeddingProvider) {
11270
11268
  this.kb = kb;
@@ -11279,7 +11277,9 @@ var Matcher = class {
11279
11277
  this.logger.info("Matcher actor initialized");
11280
11278
  const errorHandler = (err) => this.logger.error("Matcher pipeline error", { error: err });
11281
11279
  const search$ = this.eventBus.get("match:search-requested").pipe(
11282
- (0, import_operators3.concatMap)((event) => (0, import_rxjs3.from)(this.handleSearch(event)))
11280
+ (0, import_operators3.concatMap)(
11281
+ (event) => (0, import_rxjs3.from)(withActorSpan2("matcher", "match:search-requested", () => this.handleSearch(event)))
11282
+ )
11283
11283
  );
11284
11284
  this.subscriptions.push(
11285
11285
  search$.subscribe({ error: errorHandler })
@@ -11582,7 +11582,8 @@ For each candidate, output a line with the number and score, like:
11582
11582
  var import_rxjs4 = __toESM(require_cjs(), 1);
11583
11583
  var import_operators4 = __toESM(require_operators(), 1);
11584
11584
  import { promises as fs } from "fs";
11585
- import { errField as errField4, resourceId as resourceId3, userId as makeUserId, CREATION_METHODS, generateUuid } from "@semiont/core";
11585
+ import { annotationId, errField as errField4, resourceId as resourceId3, userId as makeUserId, CREATION_METHODS, generateUuid } from "@semiont/core";
11586
+ import { withActorSpan as withActorSpan3 } from "@semiont/observability";
11586
11587
  import { resolveStorageUri } from "@semiont/event-sourcing";
11587
11588
  var Stower = class {
11588
11589
  constructor(kb, eventBus, logger) {
@@ -11594,7 +11595,11 @@ var Stower = class {
11594
11595
  logger;
11595
11596
  async initialize() {
11596
11597
  this.logger.info("Stower actor initialized");
11597
- const pipe = (event, handler) => this.eventBus.get(event).pipe((0, import_operators4.concatMap)((e) => (0, import_rxjs4.from)(handler(e))));
11598
+ const pipe = (event, handler) => this.eventBus.get(event).pipe(
11599
+ (0, import_operators4.concatMap)(
11600
+ (e) => (0, import_rxjs4.from)(withActorSpan3("stower", event, () => handler(e)))
11601
+ )
11602
+ );
11598
11603
  this.subscription = (0, import_rxjs4.merge)(
11599
11604
  pipe("yield:create", (e) => this.handleYieldCreate(e)),
11600
11605
  pipe("yield:update", (e) => this.handleYieldUpdate(e)),
@@ -11617,6 +11622,10 @@ var Stower = class {
11617
11622
  // Event handlers
11618
11623
  // ========================================================================
11619
11624
  async handleYieldCreate(event) {
11625
+ if (!event._userId) {
11626
+ throw new Error("yield:create missing _userId (gateway injection)");
11627
+ }
11628
+ const uid = makeUserId(event._userId);
11620
11629
  try {
11621
11630
  const rId = resourceId3(generateUuid());
11622
11631
  const stored = await this.kb.content.register(event.storageUri, event.contentChecksum, { noGit: event.noGit });
@@ -11624,11 +11633,14 @@ var Stower = class {
11624
11633
  const byteSize = event.byteSize;
11625
11634
  const validCreationMethods = Object.values(CREATION_METHODS);
11626
11635
  const validatedCreationMethod = event.creationMethod && validCreationMethods.includes(event.creationMethod) ? event.creationMethod : CREATION_METHODS.API;
11627
- const generatedFrom = event.generatedFrom?.resourceId && event.generatedFrom?.annotationId ? { resourceId: event.generatedFrom.resourceId, annotationId: event.generatedFrom.annotationId } : void 0;
11636
+ const generatedFrom = event.generatedFrom?.resourceId && event.generatedFrom?.annotationId ? {
11637
+ resourceId: resourceId3(event.generatedFrom.resourceId),
11638
+ annotationId: annotationId(event.generatedFrom.annotationId)
11639
+ } : void 0;
11628
11640
  await this.kb.eventStore.appendEvent({
11629
11641
  type: "yield:created",
11630
11642
  resourceId: rId,
11631
- userId: makeUserId(event.userId),
11643
+ userId: uid,
11632
11644
  version: 1,
11633
11645
  payload: {
11634
11646
  name: event.name,
@@ -11669,7 +11681,7 @@ var Stower = class {
11669
11681
  if (generatedFrom) {
11670
11682
  this.eventBus.get("mark:update-body").next({
11671
11683
  annotationId: generatedFrom.annotationId,
11672
- userId: event.userId,
11684
+ _userId: event._userId,
11673
11685
  resourceId: generatedFrom.resourceId,
11674
11686
  operations: [
11675
11687
  {
@@ -11696,12 +11708,15 @@ var Stower = class {
11696
11708
  }
11697
11709
  }
11698
11710
  async handleYieldUpdate(event) {
11711
+ if (!event._userId) {
11712
+ throw new Error("yield:update missing _userId (gateway injection)");
11713
+ }
11699
11714
  try {
11700
11715
  await this.kb.content.register(event.storageUri, event.contentChecksum, { noGit: event.noGit });
11701
11716
  await this.kb.eventStore.appendEvent({
11702
11717
  type: "yield:updated",
11703
11718
  resourceId: resourceId3(event.resourceId),
11704
- userId: makeUserId(event.userId),
11719
+ userId: makeUserId(event._userId),
11705
11720
  version: 1,
11706
11721
  payload: {
11707
11722
  contentChecksum: event.contentChecksum,
@@ -11730,12 +11745,15 @@ var Stower = class {
11730
11745
  });
11731
11746
  return;
11732
11747
  }
11748
+ if (!event._userId) {
11749
+ throw new Error("yield:mv missing _userId (gateway injection)");
11750
+ }
11733
11751
  try {
11734
11752
  await this.kb.content.move(event.fromUri, event.toUri, { noGit: event.noGit });
11735
11753
  await this.kb.eventStore.appendEvent({
11736
11754
  type: "yield:moved",
11737
11755
  resourceId: rId,
11738
- userId: makeUserId(event.userId),
11756
+ userId: makeUserId(event._userId),
11739
11757
  version: 1,
11740
11758
  payload: {
11741
11759
  fromUri: event.fromUri,
@@ -11752,13 +11770,16 @@ var Stower = class {
11752
11770
  }
11753
11771
  }
11754
11772
  async handleMarkCreate(event) {
11773
+ if (!event._userId) {
11774
+ throw new Error("mark:create missing _userId (gateway injection)");
11775
+ }
11755
11776
  try {
11756
11777
  this.logger.debug("Stowing annotation", { annotationId: event.annotation.id });
11757
11778
  await this.kb.eventStore.appendEvent(
11758
11779
  {
11759
11780
  type: "mark:added",
11760
11781
  resourceId: resourceId3(event.resourceId),
11761
- userId: makeUserId(event.userId),
11782
+ userId: makeUserId(event._userId),
11762
11783
  version: 1,
11763
11784
  payload: { annotation: event.annotation }
11764
11785
  },
@@ -11773,16 +11794,19 @@ var Stower = class {
11773
11794
  }
11774
11795
  }
11775
11796
  async handleMarkDelete(event) {
11776
- if (!event.userId || !event.resourceId) {
11777
- return;
11797
+ if (!event._userId) {
11798
+ throw new Error("mark:delete missing _userId (gateway injection)");
11799
+ }
11800
+ if (!event.resourceId) {
11801
+ throw new Error("mark:delete missing resourceId");
11778
11802
  }
11779
11803
  try {
11780
11804
  await this.kb.eventStore.appendEvent({
11781
11805
  type: "mark:removed",
11782
11806
  resourceId: resourceId3(event.resourceId),
11783
- userId: makeUserId(event.userId),
11807
+ userId: makeUserId(event._userId),
11784
11808
  version: 1,
11785
- payload: { annotationId: event.annotationId }
11809
+ payload: { annotationId: annotationId(event.annotationId) }
11786
11810
  });
11787
11811
  this.eventBus.get("mark:delete-ok").next({ annotationId: event.annotationId });
11788
11812
  } catch (error) {
@@ -11793,12 +11817,15 @@ var Stower = class {
11793
11817
  }
11794
11818
  }
11795
11819
  async handleMarkUpdateBody(event) {
11820
+ if (!event._userId) {
11821
+ throw new Error("mark:update-body missing _userId (gateway injection)");
11822
+ }
11796
11823
  try {
11797
11824
  await this.kb.eventStore.appendEvent(
11798
11825
  {
11799
11826
  type: "mark:body-updated",
11800
11827
  resourceId: resourceId3(event.resourceId),
11801
- userId: makeUserId(event.userId),
11828
+ userId: makeUserId(event._userId),
11802
11829
  version: 1,
11803
11830
  payload: { annotationId: event.annotationId, operations: event.operations }
11804
11831
  },
@@ -11815,9 +11842,8 @@ var Stower = class {
11815
11842
  }
11816
11843
  }
11817
11844
  async handleMarkArchive(event) {
11818
- if (!event.userId) {
11819
- this.logger.warn("mark:archive missing userId \u2014 skipping (frontend-only event?)");
11820
- return;
11845
+ if (!event._userId) {
11846
+ throw new Error("mark:archive missing _userId (gateway injection)");
11821
11847
  }
11822
11848
  if (event.storageUri) {
11823
11849
  await this.kb.content.remove(event.storageUri, { keepFile: event.keepFile, noGit: event.noGit });
@@ -11825,15 +11851,14 @@ var Stower = class {
11825
11851
  await this.kb.eventStore.appendEvent({
11826
11852
  type: "mark:archived",
11827
11853
  resourceId: resourceId3(event.resourceId),
11828
- userId: makeUserId(event.userId),
11854
+ userId: makeUserId(event._userId),
11829
11855
  version: 1,
11830
11856
  payload: { reason: void 0 }
11831
11857
  });
11832
11858
  }
11833
11859
  async handleMarkUnarchive(event) {
11834
- if (!event.userId) {
11835
- this.logger.warn("mark:unarchive missing userId \u2014 skipping (frontend-only event?)");
11836
- return;
11860
+ if (!event._userId) {
11861
+ throw new Error("mark:unarchive missing _userId (gateway injection)");
11837
11862
  }
11838
11863
  if (event.storageUri) {
11839
11864
  const absPath = this.kb.content.resolveUri(event.storageUri);
@@ -11847,16 +11872,19 @@ var Stower = class {
11847
11872
  await this.kb.eventStore.appendEvent({
11848
11873
  type: "mark:unarchived",
11849
11874
  resourceId: resourceId3(event.resourceId),
11850
- userId: makeUserId(event.userId),
11875
+ userId: makeUserId(event._userId),
11851
11876
  version: 1,
11852
11877
  payload: {}
11853
11878
  });
11854
11879
  }
11855
11880
  async handleAddEntityType(event) {
11881
+ if (!event._userId) {
11882
+ throw new Error("mark:add-entity-type missing _userId (gateway injection)");
11883
+ }
11856
11884
  try {
11857
11885
  await this.kb.eventStore.appendEvent({
11858
11886
  type: "mark:entity-type-added",
11859
- userId: makeUserId(event.userId),
11887
+ userId: makeUserId(event._userId),
11860
11888
  version: 1,
11861
11889
  payload: { entityType: event.tag }
11862
11890
  });
@@ -11868,32 +11896,39 @@ var Stower = class {
11868
11896
  }
11869
11897
  }
11870
11898
  async handleUpdateEntityTypes(event) {
11899
+ if (!event._userId) {
11900
+ throw new Error("mark:update-entity-types missing _userId (gateway injection)");
11901
+ }
11902
+ const uid = makeUserId(event._userId);
11871
11903
  const added = event.updatedEntityTypes.filter((et) => !event.currentEntityTypes.includes(et));
11872
11904
  const removed = event.currentEntityTypes.filter((et) => !event.updatedEntityTypes.includes(et));
11873
- for (const entityType of added) {
11905
+ for (const entityType2 of added) {
11874
11906
  await this.kb.eventStore.appendEvent({
11875
11907
  type: "mark:entity-tag-added",
11876
11908
  resourceId: resourceId3(event.resourceId),
11877
- userId: makeUserId(event.userId),
11909
+ userId: uid,
11878
11910
  version: 1,
11879
- payload: { entityType }
11911
+ payload: { entityType: entityType2 }
11880
11912
  });
11881
11913
  }
11882
- for (const entityType of removed) {
11914
+ for (const entityType2 of removed) {
11883
11915
  await this.kb.eventStore.appendEvent({
11884
11916
  type: "mark:entity-tag-removed",
11885
11917
  resourceId: resourceId3(event.resourceId),
11886
- userId: makeUserId(event.userId),
11918
+ userId: uid,
11887
11919
  version: 1,
11888
- payload: { entityType }
11920
+ payload: { entityType: entityType2 }
11889
11921
  });
11890
11922
  }
11891
11923
  }
11892
11924
  async handleJobStart(event) {
11925
+ if (!event._userId) {
11926
+ throw new Error("job:start missing _userId (gateway injection)");
11927
+ }
11893
11928
  await this.kb.eventStore.appendEvent({
11894
11929
  type: "job:started",
11895
11930
  resourceId: resourceId3(event.resourceId),
11896
- userId: makeUserId(event.userId),
11931
+ userId: makeUserId(event._userId),
11897
11932
  version: 1,
11898
11933
  payload: {
11899
11934
  jobId: event.jobId,
@@ -11903,10 +11938,13 @@ var Stower = class {
11903
11938
  });
11904
11939
  }
11905
11940
  async handleJobComplete(event) {
11941
+ if (!event._userId) {
11942
+ throw new Error("job:complete missing _userId (gateway injection)");
11943
+ }
11906
11944
  await this.kb.eventStore.appendEvent({
11907
11945
  type: "job:completed",
11908
11946
  resourceId: resourceId3(event.resourceId),
11909
- userId: makeUserId(event.userId),
11947
+ userId: makeUserId(event._userId),
11910
11948
  version: 1,
11911
11949
  payload: {
11912
11950
  jobId: event.jobId,
@@ -11917,10 +11955,13 @@ var Stower = class {
11917
11955
  });
11918
11956
  }
11919
11957
  async handleJobFail(event) {
11958
+ if (!event._userId) {
11959
+ throw new Error("job:fail missing _userId (gateway injection)");
11960
+ }
11920
11961
  await this.kb.eventStore.appendEvent({
11921
11962
  type: "job:failed",
11922
11963
  resourceId: resourceId3(event.resourceId),
11923
- userId: makeUserId(event.userId),
11964
+ userId: makeUserId(event._userId),
11924
11965
  version: 1,
11925
11966
  payload: {
11926
11967
  jobId: event.jobId,
@@ -11942,8 +11983,9 @@ var import_rxjs5 = __toESM(require_cjs(), 1);
11942
11983
  var import_operators5 = __toESM(require_operators(), 1);
11943
11984
  import { promises as fs3 } from "fs";
11944
11985
  import * as path2 from "path";
11945
- import { resourceId as resourceId4, annotationId, errField as errField5 } from "@semiont/core";
11946
- import { getExactText, getTargetSource as getTargetSource2, getTargetSelector as getTargetSelector2, getResourceEntityTypes as getResourceEntityTypes5, getBodySource as getBodySource2 } from "@semiont/api-client";
11986
+ import { resourceId as resourceId4, annotationId as annotationId2, errField as errField5 } from "@semiont/core";
11987
+ import { withActorSpan as withActorSpan4 } from "@semiont/observability";
11988
+ import { getExactText, getTargetSource as getTargetSource2, getTargetSelector as getTargetSelector2, getResourceEntityTypes as getResourceEntityTypes5, getBodySource as getBodySource2 } from "@semiont/core";
11947
11989
  import { EventQuery as EventQuery2 } from "@semiont/event-sourcing";
11948
11990
  import { getEntityTypes as getEntityTypes2 } from "@semiont/ontology";
11949
11991
 
@@ -11983,7 +12025,11 @@ var Browser = class {
11983
12025
  async initialize() {
11984
12026
  this.logger.info("Browser actor initialized");
11985
12027
  const errorHandler = (err) => this.logger.error("Browser pipeline error", { error: err });
11986
- const pipe = (name, handler) => this.eventBus.get(name).pipe((0, import_operators5.mergeMap)((event) => (0, import_rxjs5.from)(handler(event))));
12028
+ const pipe = (name, handler) => this.eventBus.get(name).pipe(
12029
+ (0, import_operators5.mergeMap)(
12030
+ (event) => (0, import_rxjs5.from)(withActorSpan4("browser", name, () => handler(event)))
12031
+ )
12032
+ );
11987
12033
  this.subscriptions.push(
11988
12034
  pipe("browse:resource-requested", (e) => this.handleBrowseResource(e)).subscribe({ error: errorHandler }),
11989
12035
  pipe("browse:resources-requested", (e) => this.handleBrowseResources(e)).subscribe({ error: errorHandler }),
@@ -12082,7 +12128,7 @@ var Browser = class {
12082
12128
  }
12083
12129
  async handleBrowseAnnotation(event) {
12084
12130
  try {
12085
- const annotation = await AnnotationContext.getAnnotation(annotationId(event.annotationId), resourceId4(event.resourceId), this.kb);
12131
+ const annotation = await AnnotationContext.getAnnotation(annotationId2(event.annotationId), resourceId4(event.resourceId), this.kb);
12086
12132
  if (!annotation) {
12087
12133
  this.eventBus.get("browse:annotation-failed").next({
12088
12134
  correlationId: event.correlationId,
@@ -12146,7 +12192,7 @@ var Browser = class {
12146
12192
  }
12147
12193
  async handleBrowseAnnotationHistory(event) {
12148
12194
  try {
12149
- const annotation = await AnnotationContext.getAnnotation(annotationId(event.annotationId), resourceId4(event.resourceId), this.kb);
12195
+ const annotation = await AnnotationContext.getAnnotation(annotationId2(event.annotationId), resourceId4(event.resourceId), this.kb);
12150
12196
  if (!annotation) {
12151
12197
  this.eventBus.get("browse:annotation-history-failed").next({
12152
12198
  correlationId: event.correlationId,
@@ -12198,7 +12244,7 @@ var Browser = class {
12198
12244
  const referencedBy = references.map((ref) => {
12199
12245
  const targetSource = getTargetSource2(ref.target);
12200
12246
  const targetSelector = getTargetSelector2(ref.target);
12201
- const doc = docMap.get(targetSource);
12247
+ const doc = targetSource ? docMap.get(resourceId4(targetSource)) : void 0;
12202
12248
  return {
12203
12249
  id: ref.id,
12204
12250
  resourceName: doc?.name || "Untitled Resource",
@@ -12355,16 +12401,16 @@ function eventAnnotationId(event) {
12355
12401
  return null;
12356
12402
  }
12357
12403
  }
12358
- async function readAnnotationFromView(kb, resourceId7, annotationId3) {
12359
- const allAnnotations = await AnnotationContext.getAllAnnotations(resourceId7, kb);
12360
- return allAnnotations.find((a) => a.id === annotationId3) ?? null;
12404
+ async function readAnnotationFromView(kb, resourceId10, annotationId5) {
12405
+ const allAnnotations = await AnnotationContext.getAllAnnotations(resourceId10, kb);
12406
+ return allAnnotations.find((a) => a.id === annotationId5) ?? null;
12361
12407
  }
12362
12408
 
12363
12409
  // src/clone-token-manager.ts
12364
12410
  var import_rxjs7 = __toESM(require_cjs(), 1);
12365
12411
  var import_operators7 = __toESM(require_operators(), 1);
12366
12412
  import { CREATION_METHODS as CREATION_METHODS2, cloneToken as makeCloneToken, resourceId as resourceId5, userId as makeUserId2 } from "@semiont/core";
12367
- import { getPrimaryRepresentation as getPrimaryRepresentation3, getResourceEntityTypes as getResourceEntityTypes6 } from "@semiont/api-client";
12413
+ import { getPrimaryRepresentation as getPrimaryRepresentation3, getResourceEntityTypes as getResourceEntityTypes6 } from "@semiont/core";
12368
12414
  import { deriveStorageUri } from "@semiont/content";
12369
12415
 
12370
12416
  // src/resource-operations.ts
@@ -12375,7 +12421,7 @@ var ResourceOperations = class {
12375
12421
  /**
12376
12422
  * Create a new resource via EventBus → Stower
12377
12423
  */
12378
- static async createResource(input, userId2, eventBus) {
12424
+ static async createResource(input, userId3, eventBus) {
12379
12425
  const result$ = (0, import_rxjs6.race)(
12380
12426
  eventBus.get("yield:create-ok").pipe(
12381
12427
  (0, import_operators6.take)(1),
@@ -12395,7 +12441,7 @@ var ResourceOperations = class {
12395
12441
  contentChecksum: input.contentChecksum,
12396
12442
  byteSize: input.byteSize,
12397
12443
  format: input.format,
12398
- userId: userId2,
12444
+ _userId: userId3,
12399
12445
  language: input.language,
12400
12446
  entityTypes: input.entityTypes,
12401
12447
  creationMethod: input.creationMethod,
@@ -12410,26 +12456,6 @@ var ResourceOperations = class {
12410
12456
  }
12411
12457
  return makeResourceId3(outcome.result.resourceId);
12412
12458
  }
12413
- /**
12414
- * Update resource metadata via EventBus → Stower
12415
- */
12416
- static async updateResource(input, eventBus) {
12417
- if (input.updatedArchived !== void 0 && input.updatedArchived !== input.currentArchived) {
12418
- if (input.updatedArchived) {
12419
- eventBus.get("mark:archive").next({ userId: input.userId, resourceId: input.resourceId });
12420
- } else {
12421
- eventBus.get("mark:unarchive").next({ userId: input.userId, resourceId: input.resourceId });
12422
- }
12423
- }
12424
- if (input.updatedEntityTypes && input.currentEntityTypes) {
12425
- eventBus.get("mark:update-entity-types").next({
12426
- resourceId: input.resourceId,
12427
- userId: input.userId,
12428
- currentEntityTypes: input.currentEntityTypes,
12429
- updatedEntityTypes: input.updatedEntityTypes
12430
- });
12431
- }
12432
- }
12433
12459
  };
12434
12460
 
12435
12461
  // src/clone-token-manager.ts
@@ -12594,16 +12620,11 @@ var CloneTokenManager = class {
12594
12620
  makeUserId2(event.userId),
12595
12621
  this.eventBus
12596
12622
  );
12597
- if (event.archiveOriginal) {
12598
- ResourceOperations.updateResource(
12599
- {
12600
- resourceId: tokenData.resourceId,
12601
- userId: makeUserId2(event.userId),
12602
- currentArchived: sourceDoc.archived,
12603
- updatedArchived: true
12604
- },
12605
- this.eventBus
12606
- );
12623
+ if (event.archiveOriginal && !sourceDoc.archived) {
12624
+ this.eventBus.get("mark:archive").next({
12625
+ _userId: event.userId,
12626
+ resourceId: tokenData.resourceId
12627
+ });
12607
12628
  }
12608
12629
  this.tokens.delete(token);
12609
12630
  this.eventBus.get("yield:clone-created").next({
@@ -12645,14 +12666,14 @@ async function bootstrapEntityTypes(eventBus, eventStore, logger) {
12645
12666
  }
12646
12667
  logger?.info("Bootstrapping missing entity types", { missing: missing.length, existing: existingTypes.size });
12647
12668
  const SYSTEM_USER_ID = userId("00000000-0000-0000-0000-000000000000");
12648
- for (const entityType of missing) {
12649
- logger?.debug("Adding entity type via EventBus", { entityType });
12669
+ for (const entityType2 of missing) {
12670
+ logger?.debug("Adding entity type via EventBus", { entityType: entityType2 });
12650
12671
  const result$ = (0, import_rxjs8.race)(
12651
12672
  eventBus.get("mark:entity-type-added").pipe((0, import_operators8.take)(1), (0, import_operators8.map)(() => ({ ok: true }))),
12652
12673
  eventBus.get("mark:entity-type-add-failed").pipe((0, import_operators8.take)(1), (0, import_operators8.map)((f) => ({ ok: false, error: new Error(f.message) }))),
12653
- (0, import_rxjs8.timer)(1e4).pipe((0, import_operators8.map)(() => ({ ok: false, error: new Error(`Timeout adding entity type: ${entityType}`) })))
12674
+ (0, import_rxjs8.timer)(1e4).pipe((0, import_operators8.map)(() => ({ ok: false, error: new Error(`Timeout adding entity type: ${entityType2}`) })))
12654
12675
  );
12655
- eventBus.get("mark:add-entity-type").next({ tag: entityType, userId: SYSTEM_USER_ID });
12676
+ eventBus.get("mark:add-entity-type").next({ tag: entityType2, _userId: SYSTEM_USER_ID });
12656
12677
  const outcome = await (0, import_rxjs8.firstValueFrom)(result$);
12657
12678
  if (!outcome.ok) {
12658
12679
  throw outcome.error;
@@ -12672,15 +12693,281 @@ async function stopKnowledgeSystem(ks) {
12672
12693
  await ks.kb.graph.disconnect();
12673
12694
  }
12674
12695
 
12696
+ // src/handlers/annotation-assembly.ts
12697
+ import { resourceId as resourceId7, didToAgent as didToAgent2, assembleAnnotation } from "@semiont/core";
12698
+ function registerAnnotationAssemblyHandler(eventBus, parentLogger) {
12699
+ const logger = parentLogger.child({ component: "annotation-assembly" });
12700
+ const inflight = /* @__PURE__ */ new Map();
12701
+ eventBus.get("mark:create-request").subscribe((command) => {
12702
+ const { correlationId, resourceId: resId, request, _userId } = command;
12703
+ const cid = correlationId;
12704
+ try {
12705
+ if (!_userId || typeof _userId !== "string") {
12706
+ throw new Error("_userId is required (injected by bus gateway)");
12707
+ }
12708
+ if (!cid) {
12709
+ throw new Error("correlationId is required on mark:create-request");
12710
+ }
12711
+ const agent = didToAgent2(_userId);
12712
+ const { annotation } = assembleAnnotation(request, agent);
12713
+ inflight.set(cid, { annotationId: annotation.id });
12714
+ eventBus.get("mark:create").next({
12715
+ correlationId: cid,
12716
+ annotation,
12717
+ _userId,
12718
+ resourceId: resourceId7(resId)
12719
+ });
12720
+ logger.info("Annotation assembled, awaiting persistence", {
12721
+ annotationId: annotation.id,
12722
+ correlationId: cid
12723
+ });
12724
+ } catch (error) {
12725
+ logger.warn("mark:create-request failed during assembly", {
12726
+ correlationId: cid,
12727
+ error: error.message
12728
+ });
12729
+ eventBus.get("mark:create-failed").next({
12730
+ correlationId: cid,
12731
+ message: error.message
12732
+ });
12733
+ }
12734
+ });
12735
+ eventBus.get("mark:added").subscribe((event) => {
12736
+ const cid = event.metadata?.correlationId;
12737
+ if (!cid) return;
12738
+ const pending = inflight.get(cid);
12739
+ if (!pending) return;
12740
+ inflight.delete(cid);
12741
+ eventBus.get("mark:create-ok").next({
12742
+ correlationId: cid,
12743
+ response: { annotationId: pending.annotationId }
12744
+ });
12745
+ logger.info("Annotation persisted", { annotationId: pending.annotationId, correlationId: cid });
12746
+ });
12747
+ eventBus.get("mark:create-failed").subscribe((event) => {
12748
+ const cid = event.correlationId;
12749
+ if (!cid || !inflight.has(cid)) return;
12750
+ inflight.delete(cid);
12751
+ });
12752
+ }
12753
+
12754
+ // src/handlers/annotation-lookups.ts
12755
+ import { annotationId as makeAnnotationId3, resourceId as makeResourceId4 } from "@semiont/core";
12756
+ function registerAnnotationLookupHandlers(eventBus, kb, gatherer, parentLogger) {
12757
+ const logger = parentLogger.child({ component: "annotation-lookups" });
12758
+ eventBus.get("browse:annotation-context-requested").subscribe(async (command) => {
12759
+ const { correlationId } = command;
12760
+ const annId = command.annotationId;
12761
+ const resId = command.resourceId;
12762
+ const contextBefore = command.contextBefore ?? 100;
12763
+ const contextAfter = command.contextAfter ?? 100;
12764
+ try {
12765
+ const response = await AnnotationContext.getAnnotationContext(
12766
+ makeAnnotationId3(annId),
12767
+ makeResourceId4(resId),
12768
+ contextBefore,
12769
+ contextAfter,
12770
+ kb
12771
+ );
12772
+ eventBus.get("browse:annotation-context-result").next({
12773
+ correlationId,
12774
+ response
12775
+ });
12776
+ } catch (error) {
12777
+ logger.warn("annotation-context failed", { correlationId, error: error.message });
12778
+ eventBus.get("browse:annotation-context-failed").next({
12779
+ correlationId,
12780
+ message: error.message
12781
+ });
12782
+ }
12783
+ });
12784
+ eventBus.get("gather:summary-requested").subscribe(async (command) => {
12785
+ const { correlationId } = command;
12786
+ const annId = command.annotationId;
12787
+ const resId = command.resourceId;
12788
+ try {
12789
+ const response = await gatherer.generateAnnotationSummary(
12790
+ makeAnnotationId3(annId),
12791
+ makeResourceId4(resId)
12792
+ );
12793
+ eventBus.get("gather:summary-result").next({
12794
+ correlationId,
12795
+ response
12796
+ });
12797
+ } catch (error) {
12798
+ logger.warn("gather:summary failed", { correlationId, error: error.message });
12799
+ eventBus.get("gather:summary-failed").next({
12800
+ correlationId,
12801
+ message: error.message
12802
+ });
12803
+ }
12804
+ });
12805
+ }
12806
+
12807
+ // src/handlers/bind-update-body.ts
12808
+ import { resourceId as resourceId8, annotationId as annotationId3 } from "@semiont/core";
12809
+ function registerBindUpdateBodyHandler(eventBus, parentLogger) {
12810
+ const logger = parentLogger.child({ component: "bind-update-body" });
12811
+ const inflight = /* @__PURE__ */ new Set();
12812
+ eventBus.get("bind:update-body").subscribe((command) => {
12813
+ const { correlationId, annotationId: annId, resourceId: resId, operations, _userId } = command;
12814
+ const cid = correlationId;
12815
+ try {
12816
+ if (!_userId || typeof _userId !== "string") {
12817
+ throw new Error("_userId is required (injected by bus gateway)");
12818
+ }
12819
+ if (!cid) {
12820
+ throw new Error("correlationId is required on bind:update-body");
12821
+ }
12822
+ inflight.add(cid);
12823
+ eventBus.get("mark:update-body").next({
12824
+ correlationId: cid,
12825
+ annotationId: annotationId3(annId),
12826
+ _userId,
12827
+ resourceId: resourceId8(resId),
12828
+ operations
12829
+ });
12830
+ logger.info("Bind update-body forwarded to mark:update-body, awaiting persistence", {
12831
+ annotationId: annId,
12832
+ correlationId: cid
12833
+ });
12834
+ } catch (error) {
12835
+ logger.warn("bind:update-body failed before forwarding", {
12836
+ correlationId: cid,
12837
+ error: error.message
12838
+ });
12839
+ eventBus.get("bind:body-update-failed").next({
12840
+ correlationId: cid,
12841
+ message: error.message
12842
+ });
12843
+ }
12844
+ });
12845
+ eventBus.get("mark:body-updated").subscribe((event) => {
12846
+ const cid = event.metadata?.correlationId;
12847
+ if (!cid || !inflight.has(cid)) return;
12848
+ inflight.delete(cid);
12849
+ const annId = event.payload?.annotationId;
12850
+ eventBus.get("bind:body-updated").next({
12851
+ correlationId: cid,
12852
+ annotationId: annId
12853
+ });
12854
+ logger.info("Bind body-updated confirmed", { annotationId: annId, correlationId: cid });
12855
+ });
12856
+ eventBus.get("mark:body-update-failed").subscribe((event) => {
12857
+ const cid = event.correlationId;
12858
+ if (!cid || !inflight.has(cid)) return;
12859
+ inflight.delete(cid);
12860
+ const message = event.message ?? "Unknown error";
12861
+ eventBus.get("bind:body-update-failed").next({
12862
+ correlationId: cid,
12863
+ message
12864
+ });
12865
+ logger.warn("Bind body-update failed after forwarding", { correlationId: cid, message });
12866
+ });
12867
+ }
12868
+
12869
+ // src/handlers/job-commands.ts
12870
+ import { generateUuid as generateUuid2, jobId, userId as userId2, resourceId as resourceId9, entityType } from "@semiont/core";
12871
+ function parseDidUser(did) {
12872
+ const parts = did.split(":");
12873
+ const usersIdx = parts.indexOf("users");
12874
+ const domain = parts.slice(2, usersIdx).join(":");
12875
+ const email = decodeURIComponent(parts.slice(usersIdx + 1).join(":"));
12876
+ return { userId: did, email, domain };
12877
+ }
12878
+ function registerJobCommandHandlers(eventBus, jobQueue, parentLogger) {
12879
+ const logger = parentLogger.child({ component: "job-commands" });
12880
+ eventBus.get("job:create").subscribe(async (command) => {
12881
+ const { correlationId, jobType, resourceId: resId, params, _userId } = command;
12882
+ try {
12883
+ if (!_userId || typeof _userId !== "string") {
12884
+ throw new Error("_userId is required (injected by bus gateway)");
12885
+ }
12886
+ const user = parseDidUser(_userId);
12887
+ const job = {
12888
+ status: "pending",
12889
+ metadata: {
12890
+ id: jobId(`job-${generateUuid2()}`),
12891
+ type: jobType,
12892
+ userId: userId2(_userId),
12893
+ userName: user.email,
12894
+ userEmail: user.email,
12895
+ userDomain: user.domain,
12896
+ created: (/* @__PURE__ */ new Date()).toISOString(),
12897
+ retryCount: 0,
12898
+ maxRetries: jobType === "generation" ? 3 : 1
12899
+ },
12900
+ params: {
12901
+ resourceId: resourceId9(resId),
12902
+ ...params
12903
+ }
12904
+ };
12905
+ const jobParams = job.params;
12906
+ if (jobType === "reference-annotation" && jobParams.entityTypes) {
12907
+ jobParams.entityTypes = jobParams.entityTypes.map((et) => entityType(et));
12908
+ }
12909
+ await jobQueue.createJob(job);
12910
+ logger.info("Job created via bus", { jobId: job.metadata.id, jobType, correlationId });
12911
+ eventBus.get("job:created").next({
12912
+ correlationId,
12913
+ response: { jobId: job.metadata.id }
12914
+ });
12915
+ } catch (error) {
12916
+ logger.error("job:create failed", { correlationId, error: error.message });
12917
+ eventBus.get("job:create-failed").next({
12918
+ correlationId,
12919
+ message: error.message
12920
+ });
12921
+ }
12922
+ });
12923
+ eventBus.get("job:claim").subscribe(async (command) => {
12924
+ const { correlationId, jobId: jid } = command;
12925
+ try {
12926
+ const job = await jobQueue.getJob(jobId(jid));
12927
+ if (!job) {
12928
+ throw new Error("Job not found");
12929
+ }
12930
+ if (job.status !== "pending") {
12931
+ throw new Error("Job already claimed");
12932
+ }
12933
+ const runningJob = {
12934
+ ...job,
12935
+ status: "running",
12936
+ startedAt: (/* @__PURE__ */ new Date()).toISOString(),
12937
+ progress: {}
12938
+ };
12939
+ await jobQueue.updateJob(runningJob, "pending");
12940
+ eventBus.get("job:claimed").next({
12941
+ correlationId,
12942
+ response: runningJob
12943
+ });
12944
+ } catch (error) {
12945
+ eventBus.get("job:claim-failed").next({
12946
+ correlationId,
12947
+ message: error.message
12948
+ });
12949
+ }
12950
+ });
12951
+ }
12952
+
12953
+ // src/handlers/index.ts
12954
+ function registerBusHandlers(eventBus, knowledgeSystem, jobQueue, logger) {
12955
+ registerAnnotationAssemblyHandler(eventBus, logger);
12956
+ registerAnnotationLookupHandlers(eventBus, knowledgeSystem.kb, knowledgeSystem.gatherer, logger);
12957
+ registerBindUpdateBodyHandler(eventBus, logger);
12958
+ registerJobCommandHandlers(eventBus, jobQueue, logger);
12959
+ }
12960
+
12675
12961
  // src/service.ts
12676
12962
  async function createJobQueue(project, eventBus, logger) {
12677
12963
  const jobQueueLogger = logger.child({ component: "job-queue" });
12678
12964
  const jobQueue = new FsJobQueue(project, jobQueueLogger, eventBus);
12679
12965
  await jobQueue.initialize();
12966
+ registerJobQueueProvider(() => jobQueue.getStats());
12680
12967
  const jobStatusSubscription = eventBus.get("job:status-requested").pipe(
12681
12968
  (0, import_operators9.mergeMap)((event) => (0, import_rxjs9.from)((async () => {
12682
12969
  try {
12683
- const job = await jobQueue.getJob(jobId(event.jobId));
12970
+ const job = await jobQueue.getJob(jobId2(event.jobId));
12684
12971
  if (!job) {
12685
12972
  eventBus.get("job:status-failed").next({ correlationId: event.correlationId, message: "Job not found" });
12686
12973
  return;
@@ -12739,10 +13026,10 @@ async function createKnowledgeSystemFromConfig(project, config, eventBus, logger
12739
13026
  vectorStore,
12740
13027
  skipRebuild
12741
13028
  });
12742
- eventStore.setEnrichEvent(async (event, resourceId7) => {
13029
+ eventStore.setEnrichEvent(async (event, resourceId10) => {
12743
13030
  const annId = eventAnnotationId(event);
12744
13031
  if (annId === null) return event;
12745
- const annotation = await readAnnotationFromView(kb, resourceId7, annId);
13032
+ const annotation = await readAnnotationFromView(kb, resourceId10, annId);
12746
13033
  if (annotation === null) return event;
12747
13034
  return { ...event, annotation };
12748
13035
  });
@@ -12779,6 +13066,7 @@ async function startMakeMeaning(project, config, eventBus, logger, options) {
12779
13066
  const skipRebuild = options?.skipRebuild ?? process.env.SEMIONT_SKIP_REBUILD === "true";
12780
13067
  const { jobQueue, jobStatusSubscription } = await createJobQueue(project, eventBus, logger);
12781
13068
  const knowledgeSystem = await createKnowledgeSystemFromConfig(project, config, eventBus, logger, skipRebuild);
13069
+ registerBusHandlers(eventBus, knowledgeSystem, jobQueue, logger);
12782
13070
  return {
12783
13071
  knowledgeSystem,
12784
13072
  jobQueue,
@@ -12791,6 +13079,212 @@ async function startMakeMeaning(project, config, eventBus, logger, options) {
12791
13079
  };
12792
13080
  }
12793
13081
 
13082
+ // src/local-transport.ts
13083
+ var import_rxjs10 = __toESM(require_cjs(), 1);
13084
+ import { baseUrl as makeBaseUrl, busLog } from "@semiont/core";
13085
+ import { SpanKind, recordBusEmit, withSpan } from "@semiont/observability";
13086
+ import {
13087
+ BRIDGED_CHANNELS
13088
+ } from "@semiont/core";
13089
+ var NOT_SUPPORTED = (method) => new Error(`LocalTransport does not support ${method}() \u2014 local mode runs as a single host-process identity`);
13090
+ var LocalTransport = class {
13091
+ baseUrl;
13092
+ state$;
13093
+ bus;
13094
+ userId;
13095
+ bridges = [];
13096
+ bridgeSubs = [];
13097
+ disposed = false;
13098
+ constructor(cfg) {
13099
+ this.bus = cfg.eventBus;
13100
+ this.userId = cfg.userId;
13101
+ this.baseUrl = cfg.baseUrl ?? makeBaseUrl("local://in-process");
13102
+ this.state$ = new import_rxjs10.BehaviorSubject("open");
13103
+ }
13104
+ // ── Bus primitives ──────────────────────────────────────────────────────
13105
+ async emit(channel, payload, resourceScope) {
13106
+ busLog("EMIT", channel, payload, resourceScope);
13107
+ recordBusEmit(channel, resourceScope);
13108
+ await withSpan(
13109
+ `bus.emit:${channel}`,
13110
+ () => {
13111
+ const stamped = { ...payload, _userId: this.userId };
13112
+ const target = resourceScope === void 0 ? this.bus.get(channel) : this.bus.scope(resourceScope).get(channel);
13113
+ target.next(stamped);
13114
+ },
13115
+ {
13116
+ kind: SpanKind.PRODUCER,
13117
+ attrs: {
13118
+ "bus.channel": channel,
13119
+ ...resourceScope ? { "bus.scope": resourceScope } : {}
13120
+ }
13121
+ }
13122
+ );
13123
+ }
13124
+ on(channel, handler) {
13125
+ const sub = this.bus.get(channel).subscribe(handler);
13126
+ return () => sub.unsubscribe();
13127
+ }
13128
+ stream(channel) {
13129
+ return this.bus.get(channel);
13130
+ }
13131
+ subscribeToResource(_resourceId) {
13132
+ return () => {
13133
+ };
13134
+ }
13135
+ bridgeInto(bus) {
13136
+ if (this.bridges.includes(bus)) return;
13137
+ this.bridges.push(bus);
13138
+ for (const channel of BRIDGED_CHANNELS) {
13139
+ const upstream = this.bus.get(channel);
13140
+ this.bridgeSubs.push(
13141
+ upstream.subscribe((payload) => {
13142
+ busLog("RECV", channel, payload);
13143
+ void withSpan(
13144
+ `bus.recv:${channel}`,
13145
+ () => {
13146
+ bus.get(channel).next(payload);
13147
+ },
13148
+ { kind: SpanKind.CONSUMER, attrs: { "bus.channel": channel } }
13149
+ );
13150
+ })
13151
+ );
13152
+ }
13153
+ }
13154
+ // ── Auth (not supported) ────────────────────────────────────────────────
13155
+ async authenticatePassword(_email, _password) {
13156
+ throw NOT_SUPPORTED("authenticatePassword");
13157
+ }
13158
+ async authenticateGoogle(_credential) {
13159
+ throw NOT_SUPPORTED("authenticateGoogle");
13160
+ }
13161
+ async refreshAccessToken(_token) {
13162
+ throw NOT_SUPPORTED("refreshAccessToken");
13163
+ }
13164
+ async logout() {
13165
+ }
13166
+ async acceptTerms() {
13167
+ }
13168
+ async getCurrentUser() {
13169
+ return {
13170
+ did: this.userId,
13171
+ email: "",
13172
+ isAdmin: false,
13173
+ isModerator: false,
13174
+ termsAcceptedAt: null
13175
+ };
13176
+ }
13177
+ async generateMcpToken() {
13178
+ throw NOT_SUPPORTED("generateMcpToken");
13179
+ }
13180
+ async getMediaToken(_resourceId) {
13181
+ throw NOT_SUPPORTED("getMediaToken");
13182
+ }
13183
+ // ── Admin (not supported) ───────────────────────────────────────────────
13184
+ async listUsers() {
13185
+ throw NOT_SUPPORTED("listUsers");
13186
+ }
13187
+ async getUserStats() {
13188
+ throw NOT_SUPPORTED("getUserStats");
13189
+ }
13190
+ async updateUser(_id, _data) {
13191
+ throw NOT_SUPPORTED("updateUser");
13192
+ }
13193
+ async getOAuthConfig() {
13194
+ throw NOT_SUPPORTED("getOAuthConfig");
13195
+ }
13196
+ // ── Exchange (not supported) ────────────────────────────────────────────
13197
+ async backupKnowledgeBase() {
13198
+ throw NOT_SUPPORTED("backupKnowledgeBase");
13199
+ }
13200
+ async restoreKnowledgeBase(_file, _onProgress) {
13201
+ throw NOT_SUPPORTED("restoreKnowledgeBase");
13202
+ }
13203
+ async exportKnowledgeBase(_params) {
13204
+ throw NOT_SUPPORTED("exportKnowledgeBase");
13205
+ }
13206
+ async importKnowledgeBase(_file, _onProgress) {
13207
+ throw NOT_SUPPORTED("importKnowledgeBase");
13208
+ }
13209
+ // ── System ──────────────────────────────────────────────────────────────
13210
+ async healthCheck() {
13211
+ return { status: "ok" };
13212
+ }
13213
+ async getStatus() {
13214
+ return { status: "ok" };
13215
+ }
13216
+ // ── Lifecycle ───────────────────────────────────────────────────────────
13217
+ dispose() {
13218
+ if (this.disposed) return;
13219
+ this.disposed = true;
13220
+ for (const sub of this.bridgeSubs) sub.unsubscribe();
13221
+ this.bridgeSubs.length = 0;
13222
+ this.bridges.length = 0;
13223
+ this.state$.next("closed");
13224
+ this.state$.complete();
13225
+ }
13226
+ };
13227
+
13228
+ // src/local-content-transport.ts
13229
+ import { busLog as busLog2 } from "@semiont/core";
13230
+ import { SpanKind as SpanKind2, withSpan as withSpan2 } from "@semiont/observability";
13231
+ function primaryRepresentation(reps) {
13232
+ if (!reps) return void 0;
13233
+ return Array.isArray(reps) ? reps[0] : reps;
13234
+ }
13235
+ var LocalContentTransport = class {
13236
+ constructor(ks) {
13237
+ this.ks = ks;
13238
+ }
13239
+ async putBinary(_request, _options) {
13240
+ throw new Error(
13241
+ "LocalContentTransport does not support putBinary() \u2014 create resources via bus emits (mark/yield namespaces) in local mode"
13242
+ );
13243
+ }
13244
+ async getBinary(resourceId10, options) {
13245
+ busLog2("GET", "content", { resourceId: resourceId10, accept: options?.accept });
13246
+ return withSpan2(
13247
+ "content.get",
13248
+ () => this.loadBinary(resourceId10),
13249
+ { kind: SpanKind2.INTERNAL, attrs: { "resource.id": resourceId10 } }
13250
+ );
13251
+ }
13252
+ async getBinaryStream(resourceId10, options) {
13253
+ busLog2("GET", "content", { resourceId: resourceId10, accept: options?.accept, stream: true });
13254
+ return withSpan2(
13255
+ "content.get",
13256
+ async () => {
13257
+ const { data, contentType } = await this.loadBinary(resourceId10);
13258
+ const bytes = new Uint8Array(data);
13259
+ const stream = new ReadableStream({
13260
+ start(controller) {
13261
+ controller.enqueue(bytes);
13262
+ controller.close();
13263
+ }
13264
+ });
13265
+ return { stream, contentType };
13266
+ },
13267
+ {
13268
+ kind: SpanKind2.INTERNAL,
13269
+ attrs: { "resource.id": resourceId10, "content.stream": true }
13270
+ }
13271
+ );
13272
+ }
13273
+ async loadBinary(resourceId10) {
13274
+ const view = await this.ks.kb.views.get(resourceId10);
13275
+ if (!view) throw new Error(`Resource not found: ${resourceId10}`);
13276
+ const rep = primaryRepresentation(view.resource.representations);
13277
+ if (!rep?.storageUri) {
13278
+ throw new Error(`Resource ${resourceId10} has no representation with a storageUri`);
13279
+ }
13280
+ const buf = await this.ks.kb.content.retrieve(rep.storageUri);
13281
+ const data = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
13282
+ return { data, contentType: rep.mediaType };
13283
+ }
13284
+ dispose() {
13285
+ }
13286
+ };
13287
+
12794
13288
  // src/exchange/backup-exporter.ts
12795
13289
  import { getExtensionForMimeType } from "@semiont/content";
12796
13290
 
@@ -12982,7 +13476,7 @@ function collectContentRefs(streamData) {
12982
13476
  }
12983
13477
 
12984
13478
  // src/exchange/replay.ts
12985
- var import_rxjs10 = __toESM(require_cjs(), 1);
13479
+ var import_rxjs11 = __toESM(require_cjs(), 1);
12986
13480
  var import_operators10 = __toESM(require_operators(), 1);
12987
13481
  import { deriveStorageUri as deriveStorageUri2 } from "@semiont/content";
12988
13482
  var REPLAY_TIMEOUT_MS = 3e4;
@@ -13048,20 +13542,20 @@ async function replayEvent(event, eventBus, resolveBlob, contentStore, stats, lo
13048
13542
  }
13049
13543
  }
13050
13544
  async function replayEntityTypeAdded(event, eventBus, logger) {
13051
- const result$ = (0, import_rxjs10.race)(
13545
+ const result$ = (0, import_rxjs11.race)(
13052
13546
  eventBus.get("mark:entity-type-added").pipe((0, import_operators10.map)(() => "ok")),
13053
13547
  eventBus.get("mark:entity-type-add-failed").pipe((0, import_operators10.map)((e) => {
13054
13548
  throw new Error(e.message);
13055
13549
  })),
13056
- (0, import_rxjs10.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators10.map)(() => {
13550
+ (0, import_rxjs11.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators10.map)(() => {
13057
13551
  throw new Error("Timeout waiting for mark:entity-type-added");
13058
13552
  }))
13059
13553
  );
13060
13554
  eventBus.get("mark:add-entity-type").next({
13061
13555
  tag: event.payload.entityType,
13062
- userId: event.userId
13556
+ _userId: event.userId
13063
13557
  });
13064
- await (0, import_rxjs10.firstValueFrom)(result$);
13558
+ await (0, import_rxjs11.firstValueFrom)(result$);
13065
13559
  logger?.debug("Replayed entitytype.added", { entityType: event.payload.entityType });
13066
13560
  }
13067
13561
  async function replayResourceCreated(event, eventBus, resolveBlob, contentStore, logger) {
@@ -13072,12 +13566,12 @@ async function replayResourceCreated(event, eventBus, resolveBlob, contentStore,
13072
13566
  }
13073
13567
  const resolvedUri = payload.storageUri || deriveStorageUri2(payload.name, payload.format);
13074
13568
  const stored = await contentStore.store(blob, resolvedUri);
13075
- const result$ = (0, import_rxjs10.race)(
13569
+ const result$ = (0, import_rxjs11.race)(
13076
13570
  eventBus.get("yield:create-ok").pipe((0, import_operators10.map)((r) => r)),
13077
13571
  eventBus.get("yield:create-failed").pipe((0, import_operators10.map)((e) => {
13078
13572
  throw new Error(e.message);
13079
13573
  })),
13080
- (0, import_rxjs10.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators10.map)(() => {
13574
+ (0, import_rxjs11.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators10.map)(() => {
13081
13575
  throw new Error("Timeout waiting for yield:create-ok");
13082
13576
  }))
13083
13577
  );
@@ -13087,7 +13581,7 @@ async function replayResourceCreated(event, eventBus, resolveBlob, contentStore,
13087
13581
  contentChecksum: stored.checksum,
13088
13582
  byteSize: stored.byteSize,
13089
13583
  format: payload.format,
13090
- userId: event.userId,
13584
+ _userId: event.userId,
13091
13585
  language: payload.language,
13092
13586
  entityTypes: payload.entityTypes,
13093
13587
  creationMethod: payload.creationMethod,
@@ -13095,97 +13589,97 @@ async function replayResourceCreated(event, eventBus, resolveBlob, contentStore,
13095
13589
  generatedFrom: payload.generatedFrom,
13096
13590
  generationPrompt: payload.generationPrompt
13097
13591
  });
13098
- await (0, import_rxjs10.firstValueFrom)(result$);
13592
+ await (0, import_rxjs11.firstValueFrom)(result$);
13099
13593
  logger?.debug("Replayed resource.created", { name: payload.name });
13100
13594
  }
13101
13595
  async function replayAnnotationAdded(event, eventBus, logger) {
13102
- const result$ = (0, import_rxjs10.race)(
13596
+ const result$ = (0, import_rxjs11.race)(
13103
13597
  eventBus.get("mark:create-ok").pipe((0, import_operators10.map)(() => "ok")),
13104
13598
  eventBus.get("mark:create-failed").pipe((0, import_operators10.map)((e) => {
13105
13599
  throw new Error(e.message);
13106
13600
  })),
13107
- (0, import_rxjs10.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators10.map)(() => {
13601
+ (0, import_rxjs11.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators10.map)(() => {
13108
13602
  throw new Error("Timeout waiting for mark:create-ok");
13109
13603
  }))
13110
13604
  );
13111
13605
  eventBus.get("mark:create").next({
13112
13606
  annotation: event.payload.annotation,
13113
- userId: event.userId,
13607
+ _userId: event.userId,
13114
13608
  resourceId: event.resourceId
13115
13609
  });
13116
- await (0, import_rxjs10.firstValueFrom)(result$);
13610
+ await (0, import_rxjs11.firstValueFrom)(result$);
13117
13611
  logger?.debug("Replayed annotation.added", { annotationId: event.payload.annotation.id });
13118
13612
  }
13119
13613
  async function replayAnnotationBodyUpdated(event, eventBus, logger) {
13120
- const result$ = (0, import_rxjs10.race)(
13614
+ const result$ = (0, import_rxjs11.race)(
13121
13615
  eventBus.get("mark:body-updated").pipe((0, import_operators10.map)(() => "ok")),
13122
13616
  eventBus.get("mark:body-update-failed").pipe((0, import_operators10.map)((e) => {
13123
13617
  throw new Error(e.message);
13124
13618
  })),
13125
- (0, import_rxjs10.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators10.map)(() => {
13619
+ (0, import_rxjs11.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators10.map)(() => {
13126
13620
  throw new Error("Timeout waiting for mark:body-updated");
13127
13621
  }))
13128
13622
  );
13129
13623
  eventBus.get("mark:update-body").next({
13130
13624
  annotationId: event.payload.annotationId,
13131
- userId: event.userId,
13625
+ _userId: event.userId,
13132
13626
  resourceId: event.resourceId,
13133
13627
  operations: event.payload.operations
13134
13628
  });
13135
- await (0, import_rxjs10.firstValueFrom)(result$);
13629
+ await (0, import_rxjs11.firstValueFrom)(result$);
13136
13630
  logger?.debug("Replayed annotation.body.updated", { annotationId: event.payload.annotationId });
13137
13631
  }
13138
13632
  async function replayAnnotationRemoved(event, eventBus, logger) {
13139
- const result$ = (0, import_rxjs10.race)(
13633
+ const result$ = (0, import_rxjs11.race)(
13140
13634
  eventBus.get("mark:delete-ok").pipe((0, import_operators10.map)(() => "ok")),
13141
13635
  eventBus.get("mark:delete-failed").pipe((0, import_operators10.map)((e) => {
13142
13636
  throw new Error(e.message);
13143
13637
  })),
13144
- (0, import_rxjs10.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators10.map)(() => {
13638
+ (0, import_rxjs11.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators10.map)(() => {
13145
13639
  throw new Error("Timeout waiting for mark:delete-ok");
13146
13640
  }))
13147
13641
  );
13148
13642
  eventBus.get("mark:delete").next({
13149
13643
  annotationId: event.payload.annotationId,
13150
- userId: event.userId,
13644
+ _userId: event.userId,
13151
13645
  resourceId: event.resourceId
13152
13646
  });
13153
- await (0, import_rxjs10.firstValueFrom)(result$);
13647
+ await (0, import_rxjs11.firstValueFrom)(result$);
13154
13648
  logger?.debug("Replayed annotation.removed", { annotationId: event.payload.annotationId });
13155
13649
  }
13156
13650
  async function replayResourceArchived(event, eventBus, logger) {
13157
13651
  eventBus.get("mark:archive").next({
13158
- userId: event.userId,
13652
+ _userId: event.userId,
13159
13653
  resourceId: event.resourceId
13160
13654
  });
13161
13655
  logger?.debug("Replayed resource.archived", { resourceId: event.resourceId });
13162
13656
  }
13163
13657
  async function replayResourceUnarchived(event, eventBus, logger) {
13164
13658
  eventBus.get("mark:unarchive").next({
13165
- userId: event.userId,
13659
+ _userId: event.userId,
13166
13660
  resourceId: event.resourceId
13167
13661
  });
13168
13662
  logger?.debug("Replayed resource.unarchived", { resourceId: event.resourceId });
13169
13663
  }
13170
13664
  async function replayEntityTagChange(event, eventBus, logger) {
13171
- const resourceId7 = event.resourceId;
13172
- const entityType = event.payload.entityType;
13665
+ const resourceId10 = event.resourceId;
13666
+ const entityType2 = event.payload.entityType;
13173
13667
  if (event.type === "mark:entity-tag-added") {
13174
13668
  eventBus.get("mark:update-entity-types").next({
13175
- resourceId: resourceId7,
13176
- userId: event.userId,
13669
+ resourceId: resourceId10,
13670
+ _userId: event.userId,
13177
13671
  currentEntityTypes: [],
13178
- updatedEntityTypes: [entityType]
13672
+ updatedEntityTypes: [entityType2]
13179
13673
  });
13180
13674
  } else {
13181
13675
  eventBus.get("mark:update-entity-types").next({
13182
- resourceId: resourceId7,
13183
- userId: event.userId,
13184
- currentEntityTypes: [entityType],
13676
+ resourceId: resourceId10,
13677
+ _userId: event.userId,
13678
+ currentEntityTypes: [entityType2],
13185
13679
  updatedEntityTypes: []
13186
13680
  });
13187
13681
  }
13188
- logger?.debug("Replayed entity tag change", { type: event.type, entityType });
13682
+ logger?.debug("Replayed entity tag change", { type: event.type, entityType: entityType2 });
13189
13683
  }
13190
13684
 
13191
13685
  // src/exchange/backup-importer.ts
@@ -13359,10 +13853,10 @@ async function exportLinkedData(options, output) {
13359
13853
  data: Buffer.from(JSON.stringify(manifest, null, 2), "utf8")
13360
13854
  };
13361
13855
  for (const view of resourceViews) {
13362
- const resourceId7 = view.resource["@id"];
13856
+ const resourceId10 = view.resource["@id"];
13363
13857
  const jsonld = buildResourceJsonLd(view.resource, view.annotations.annotations, sourceUrl);
13364
13858
  yield {
13365
- name: `.semiont/resources/${resourceId7}.jsonld`,
13859
+ name: `.semiont/resources/${resourceId10}.jsonld`,
13366
13860
  data: Buffer.from(JSON.stringify(jsonld, null, 2), "utf8")
13367
13861
  };
13368
13862
  }
@@ -13379,8 +13873,8 @@ async function exportLinkedData(options, output) {
13379
13873
  return manifest;
13380
13874
  }
13381
13875
  function buildResourceJsonLd(resource, annotations, sourceUrl) {
13382
- const resourceId7 = resource["@id"];
13383
- const resourceUri = resourceId7.startsWith("http") ? resourceId7 : `${sourceUrl}/resources/${resourceId7}`;
13876
+ const resourceId10 = resource["@id"];
13877
+ const resourceUri = resourceId10.startsWith("http") ? resourceId10 : `${sourceUrl}/resources/${resourceId10}`;
13384
13878
  const doc = {
13385
13879
  "@context": SEMIONT_CONTEXT,
13386
13880
  "@id": resourceUri,
@@ -13440,9 +13934,9 @@ function collectContentRefsFromResource(resource, refs) {
13440
13934
  }
13441
13935
 
13442
13936
  // src/exchange/linked-data-importer.ts
13443
- var import_rxjs11 = __toESM(require_cjs(), 1);
13937
+ var import_rxjs12 = __toESM(require_cjs(), 1);
13444
13938
  var import_operators11 = __toESM(require_operators(), 1);
13445
- import { resourceId as makeResourceId4 } from "@semiont/core";
13939
+ import { annotationId as annotationIdFactory, resourceId as makeResourceId5 } from "@semiont/core";
13446
13940
  import { deriveStorageUri as deriveStorageUri3 } from "@semiont/content";
13447
13941
  var IMPORT_TIMEOUT_MS = 3e4;
13448
13942
  function stripUriToId(uri) {
@@ -13453,7 +13947,7 @@ function stripUriToId(uri) {
13453
13947
  function dehydrateAnnotation(annotation) {
13454
13948
  const dehydrated = { ...annotation };
13455
13949
  if (dehydrated.id) {
13456
- dehydrated.id = stripUriToId(dehydrated.id);
13950
+ dehydrated.id = annotationIdFactory(stripUriToId(dehydrated.id));
13457
13951
  }
13458
13952
  if (typeof dehydrated.target === "string") {
13459
13953
  dehydrated.target = stripUriToId(dehydrated.target);
@@ -13497,7 +13991,7 @@ function buildBlobResolver2(entries) {
13497
13991
  };
13498
13992
  }
13499
13993
  async function importLinkedData(archive, options) {
13500
- const { eventBus, contentStore, userId: userId2, logger } = options;
13994
+ const { eventBus, contentStore, userId: userId3, logger } = options;
13501
13995
  const entries = /* @__PURE__ */ new Map();
13502
13996
  for await (const entry of readTarGz(archive)) {
13503
13997
  entries.set(entry.name, entry.data);
@@ -13519,8 +14013,8 @@ async function importLinkedData(archive, options) {
13519
14013
  });
13520
14014
  const resolveBlob = buildBlobResolver2(entries);
13521
14015
  let entityTypesAdded = 0;
13522
- for (const entityType of manifest["semiont:entityTypes"]) {
13523
- await addEntityType(entityType, userId2, eventBus, logger);
14016
+ for (const entityType2 of manifest["semiont:entityTypes"]) {
14017
+ await addEntityType(entityType2, userId3, eventBus, logger);
13524
14018
  entityTypesAdded++;
13525
14019
  }
13526
14020
  const resourceEntries = [...entries.keys()].filter((name) => name.startsWith(".semiont/resources/") && name.endsWith(".jsonld")).sort();
@@ -13528,7 +14022,7 @@ async function importLinkedData(archive, options) {
13528
14022
  let annotationsCreated = 0;
13529
14023
  for (const entryName of resourceEntries) {
13530
14024
  const resourceDoc = JSON.parse(entries.get(entryName).toString("utf8"));
13531
- const result = await importResource(resourceDoc, userId2, eventBus, contentStore, resolveBlob, logger);
14025
+ const result = await importResource(resourceDoc, userId3, eventBus, contentStore, resolveBlob, logger);
13532
14026
  resourcesCreated++;
13533
14027
  annotationsCreated += result.annotationsCreated;
13534
14028
  }
@@ -13544,24 +14038,24 @@ async function importLinkedData(archive, options) {
13544
14038
  entityTypesAdded
13545
14039
  };
13546
14040
  }
13547
- async function addEntityType(entityType, userId2, eventBus, logger) {
13548
- const result$ = (0, import_rxjs11.race)(
14041
+ async function addEntityType(entityType2, userId3, eventBus, logger) {
14042
+ const result$ = (0, import_rxjs12.race)(
13549
14043
  eventBus.get("mark:entity-type-added").pipe((0, import_operators11.map)(() => "ok")),
13550
14044
  eventBus.get("mark:entity-type-add-failed").pipe((0, import_operators11.map)((e) => {
13551
14045
  throw new Error(e.message);
13552
14046
  })),
13553
- (0, import_rxjs11.timer)(IMPORT_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
14047
+ (0, import_rxjs12.timer)(IMPORT_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
13554
14048
  throw new Error("Timeout waiting for mark:entity-type-added");
13555
14049
  }))
13556
14050
  );
13557
14051
  eventBus.get("mark:add-entity-type").next({
13558
- tag: entityType,
13559
- userId: userId2
14052
+ tag: entityType2,
14053
+ _userId: userId3
13560
14054
  });
13561
- await (0, import_rxjs11.firstValueFrom)(result$);
13562
- logger?.debug("Added entity type", { entityType });
14055
+ await (0, import_rxjs12.firstValueFrom)(result$);
14056
+ logger?.debug("Added entity type", { entityType: entityType2 });
13563
14057
  }
13564
- async function importResource(doc, userId2, eventBus, contentStore, resolveBlob, logger) {
14058
+ async function importResource(doc, userId3, eventBus, contentStore, resolveBlob, logger) {
13565
14059
  const name = doc["name"];
13566
14060
  const representations = doc["representations"];
13567
14061
  const annotations = doc["annotations"];
@@ -13585,12 +14079,12 @@ async function importResource(doc, userId2, eventBus, contentStore, resolveBlob,
13585
14079
  }
13586
14080
  const resolvedUri = deriveStorageUri3(name, format);
13587
14081
  const stored = await contentStore.store(blob, resolvedUri);
13588
- const createResult$ = (0, import_rxjs11.race)(
14082
+ const createResult$ = (0, import_rxjs12.race)(
13589
14083
  eventBus.get("yield:create-ok").pipe((0, import_operators11.map)((r) => r)),
13590
14084
  eventBus.get("yield:create-failed").pipe((0, import_operators11.map)((e) => {
13591
14085
  throw new Error(e.message);
13592
14086
  })),
13593
- (0, import_rxjs11.timer)(IMPORT_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
14087
+ (0, import_rxjs12.timer)(IMPORT_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
13594
14088
  throw new Error("Timeout waiting for yield:create-ok");
13595
14089
  }))
13596
14090
  );
@@ -13600,60 +14094,60 @@ async function importResource(doc, userId2, eventBus, contentStore, resolveBlob,
13600
14094
  contentChecksum: stored.checksum,
13601
14095
  byteSize: stored.byteSize,
13602
14096
  format,
13603
- userId: userId2,
14097
+ _userId: userId3,
13604
14098
  language,
13605
14099
  entityTypes: entityTypes ?? [],
13606
14100
  creationMethod
13607
14101
  });
13608
- const created = await (0, import_rxjs11.firstValueFrom)(createResult$);
13609
- const resourceId7 = makeResourceId4(created.resourceId);
13610
- logger?.debug("Created resource from JSON-LD", { name, resourceId: resourceId7 });
14102
+ const created = await (0, import_rxjs12.firstValueFrom)(createResult$);
14103
+ const resourceId10 = makeResourceId5(created.resourceId);
14104
+ logger?.debug("Created resource from JSON-LD", { name, resourceId: resourceId10 });
13611
14105
  let annotationsCreated = 0;
13612
14106
  if (annotations && annotations.length > 0) {
13613
14107
  for (const annotation of annotations) {
13614
- await createAnnotation(annotation, resourceId7, userId2, eventBus, logger);
14108
+ await createAnnotation(annotation, resourceId10, userId3, eventBus, logger);
13615
14109
  annotationsCreated++;
13616
14110
  }
13617
14111
  }
13618
14112
  return { annotationsCreated };
13619
14113
  }
13620
- async function createAnnotation(annotation, resourceId7, userId2, eventBus, logger) {
13621
- const result$ = (0, import_rxjs11.race)(
14114
+ async function createAnnotation(annotation, resourceId10, userId3, eventBus, logger) {
14115
+ const result$ = (0, import_rxjs12.race)(
13622
14116
  eventBus.get("mark:create-ok").pipe((0, import_operators11.map)(() => "ok")),
13623
14117
  eventBus.get("mark:create-failed").pipe((0, import_operators11.map)((e) => {
13624
14118
  throw new Error(e.message);
13625
14119
  })),
13626
- (0, import_rxjs11.timer)(IMPORT_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
14120
+ (0, import_rxjs12.timer)(IMPORT_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
13627
14121
  throw new Error("Timeout waiting for mark:create-ok");
13628
14122
  }))
13629
14123
  );
13630
14124
  eventBus.get("mark:create").next({
13631
14125
  annotation: dehydrateAnnotation(annotation),
13632
- userId: userId2,
13633
- resourceId: resourceId7
14126
+ _userId: userId3,
14127
+ resourceId: resourceId10
13634
14128
  });
13635
- await (0, import_rxjs11.firstValueFrom)(result$);
14129
+ await (0, import_rxjs12.firstValueFrom)(result$);
13636
14130
  logger?.debug("Created annotation", { annotationId: annotation.id });
13637
14131
  }
13638
14132
 
13639
14133
  // src/annotation-assembly.ts
13640
14134
  import {
13641
- assembleAnnotation,
14135
+ assembleAnnotation as assembleAnnotation2,
13642
14136
  applyBodyOperations
13643
14137
  } from "@semiont/core";
13644
14138
 
13645
14139
  // src/annotation-operations.ts
13646
- import { annotationId as annotationId2, resourceId as makeResourceId5, assembleAnnotation as assembleAnnotation2, applyBodyOperations as applyBodyOperations2 } from "@semiont/core";
14140
+ import { annotationId as annotationId4, resourceId as makeResourceId6, assembleAnnotation as assembleAnnotation3, applyBodyOperations as applyBodyOperations2 } from "@semiont/core";
13647
14141
  var AnnotationOperations = class {
13648
14142
  /**
13649
14143
  * Create a new annotation via EventBus → Stower
13650
14144
  */
13651
- static async createAnnotation(request, userId2, creator, eventBus) {
13652
- const { annotation } = assembleAnnotation2(request, creator);
13653
- const resId = makeResourceId5(request.target.source);
14145
+ static async createAnnotation(request, userId3, creator, eventBus) {
14146
+ const { annotation } = assembleAnnotation3(request, creator);
14147
+ const resId = makeResourceId6(request.target.source);
13654
14148
  eventBus.get("mark:create").next({
13655
14149
  annotation,
13656
- userId: userId2,
14150
+ _userId: userId3,
13657
14151
  resourceId: resId
13658
14152
  });
13659
14153
  return { annotation };
@@ -13661,10 +14155,10 @@ var AnnotationOperations = class {
13661
14155
  /**
13662
14156
  * Update annotation body via EventBus → Stower
13663
14157
  */
13664
- static async updateAnnotationBody(id, request, userId2, eventBus, kb) {
13665
- const resId = makeResourceId5(request.resourceId);
14158
+ static async updateAnnotationBody(id, request, userId3, eventBus, kb) {
14159
+ const resId = makeResourceId6(request.resourceId);
13666
14160
  const annotation = await AnnotationContext.getAnnotation(
13667
- annotationId2(id),
14161
+ annotationId4(id),
13668
14162
  resId,
13669
14163
  kb
13670
14164
  );
@@ -13672,8 +14166,8 @@ var AnnotationOperations = class {
13672
14166
  throw new Error("Annotation not found");
13673
14167
  }
13674
14168
  eventBus.get("mark:update-body").next({
13675
- annotationId: annotationId2(id),
13676
- userId: userId2,
14169
+ annotationId: annotationId4(id),
14170
+ _userId: userId3,
13677
14171
  resourceId: resId,
13678
14172
  operations: request.operations
13679
14173
  });
@@ -13688,8 +14182,8 @@ var AnnotationOperations = class {
13688
14182
  /**
13689
14183
  * Delete an annotation via EventBus → Stower
13690
14184
  */
13691
- static async deleteAnnotation(id, resourceIdStr, userId2, eventBus, kb, logger) {
13692
- const resId = makeResourceId5(resourceIdStr);
14185
+ static async deleteAnnotation(id, resourceIdStr, userId3, eventBus, kb, logger) {
14186
+ const resId = makeResourceId6(resourceIdStr);
13693
14187
  const projection = await AnnotationContext.getResourceAnnotations(resId, kb);
13694
14188
  const annotation = projection.annotations.find((a) => a.id === id);
13695
14189
  if (!annotation) {
@@ -13697,8 +14191,8 @@ var AnnotationOperations = class {
13697
14191
  }
13698
14192
  logger?.debug("Removing annotation via EventBus", { annotationId: id });
13699
14193
  eventBus.get("mark:delete").next({
13700
- annotationId: annotationId2(id),
13701
- userId: userId2,
14194
+ annotationId: annotationId4(id),
14195
+ _userId: userId3,
13702
14196
  resourceId: resId
13703
14197
  });
13704
14198
  logger?.debug("Annotation delete event emitted");
@@ -13718,6 +14212,8 @@ export {
13718
14212
  Gatherer,
13719
14213
  GraphContext,
13720
14214
  LLMContext,
14215
+ LocalContentTransport,
14216
+ LocalTransport,
13721
14217
  Matcher,
13722
14218
  PACKAGE_NAME,
13723
14219
  ResourceContext,
@@ -13725,7 +14221,7 @@ export {
13725
14221
  Stower,
13726
14222
  VERSION,
13727
14223
  applyBodyOperations,
13728
- assembleAnnotation,
14224
+ assembleAnnotation2 as assembleAnnotation,
13729
14225
  bootstrapEntityTypes,
13730
14226
  createKnowledgeBase,
13731
14227
  exportBackup,
@@ -13736,6 +14232,11 @@ export {
13736
14232
  importLinkedData,
13737
14233
  isBackupManifest,
13738
14234
  readEntityTypesProjection,
14235
+ registerAnnotationAssemblyHandler,
14236
+ registerAnnotationLookupHandlers,
14237
+ registerBindUpdateBodyHandler,
14238
+ registerBusHandlers,
14239
+ registerJobCommandHandlers,
13739
14240
  startMakeMeaning,
13740
14241
  stopKnowledgeSystem,
13741
14242
  validateManifestVersion