@semiont/make-meaning 0.4.14 → 0.4.15
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/README.md +4 -4
- package/dist/index.d.ts +34 -24
- package/dist/index.js +441 -482
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9945,6 +9945,7 @@ var require_operators = __commonJS({
|
|
|
9945
9945
|
// src/service.ts
|
|
9946
9946
|
import { JobQueue } from "@semiont/jobs";
|
|
9947
9947
|
import { createEventStore as createEventStoreCore } from "@semiont/event-sourcing";
|
|
9948
|
+
import { jobId } from "@semiont/core";
|
|
9948
9949
|
|
|
9949
9950
|
// src/config.ts
|
|
9950
9951
|
function resolveActorInference(config, actor) {
|
|
@@ -10007,7 +10008,7 @@ function partitionByType(events) {
|
|
|
10007
10008
|
const runs = [];
|
|
10008
10009
|
let currentRun = [];
|
|
10009
10010
|
for (const event of events) {
|
|
10010
|
-
if (currentRun.length > 0 && currentRun[0].
|
|
10011
|
+
if (currentRun.length > 0 && currentRun[0].type !== event.type) {
|
|
10011
10012
|
runs.push(currentRun);
|
|
10012
10013
|
currentRun = [];
|
|
10013
10014
|
}
|
|
@@ -10019,28 +10020,29 @@ function partitionByType(events) {
|
|
|
10019
10020
|
|
|
10020
10021
|
// src/graph/consumer.ts
|
|
10021
10022
|
var GraphDBConsumer = class _GraphDBConsumer {
|
|
10022
|
-
constructor(eventStore, graphDb, logger) {
|
|
10023
|
+
constructor(eventStore, graphDb, coreEventBus, logger) {
|
|
10023
10024
|
this.eventStore = eventStore;
|
|
10024
10025
|
this.graphDb = graphDb;
|
|
10026
|
+
this.coreEventBus = coreEventBus;
|
|
10025
10027
|
this.logger = logger;
|
|
10026
10028
|
}
|
|
10027
10029
|
// Event types that produce GraphDB mutations — filter everything else
|
|
10028
10030
|
static GRAPH_RELEVANT_EVENTS = /* @__PURE__ */ new Set([
|
|
10029
|
-
"
|
|
10030
|
-
"
|
|
10031
|
-
"
|
|
10032
|
-
"
|
|
10033
|
-
"
|
|
10034
|
-
"
|
|
10035
|
-
"
|
|
10036
|
-
"
|
|
10037
|
-
"
|
|
10031
|
+
"yield:created",
|
|
10032
|
+
"mark:archived",
|
|
10033
|
+
"mark:unarchived",
|
|
10034
|
+
"mark:added",
|
|
10035
|
+
"mark:removed",
|
|
10036
|
+
"mark:body-updated",
|
|
10037
|
+
"mark:entity-tag-added",
|
|
10038
|
+
"mark:entity-tag-removed",
|
|
10039
|
+
"mark:entity-type-added"
|
|
10038
10040
|
]);
|
|
10039
10041
|
// Burst buffer thresholds — see class doc and BATCH-GRAPH-CONSUMER-RX.md
|
|
10040
10042
|
static BURST_WINDOW_MS = 50;
|
|
10041
10043
|
static MAX_BATCH_SIZE = 500;
|
|
10042
10044
|
static IDLE_TIMEOUT_MS = 200;
|
|
10043
|
-
|
|
10045
|
+
_globalSubscriptions = [];
|
|
10044
10046
|
eventSubject = new import_rxjs.Subject();
|
|
10045
10047
|
pipelineSubscription = null;
|
|
10046
10048
|
lastProcessed = /* @__PURE__ */ new Map();
|
|
@@ -10054,15 +10056,16 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10054
10056
|
* and wire through the RxJS burst-buffered pipeline.
|
|
10055
10057
|
*/
|
|
10056
10058
|
async subscribeToGlobalEvents() {
|
|
10057
|
-
|
|
10058
|
-
(
|
|
10059
|
-
|
|
10060
|
-
|
|
10061
|
-
|
|
10062
|
-
|
|
10059
|
+
for (const eventType of _GraphDBConsumer.GRAPH_RELEVANT_EVENTS) {
|
|
10060
|
+
this._globalSubscriptions.push(
|
|
10061
|
+
this.coreEventBus.getDomainEvent(eventType).subscribe(
|
|
10062
|
+
(storedEvent) => this.eventSubject.next(storedEvent)
|
|
10063
|
+
)
|
|
10064
|
+
);
|
|
10065
|
+
}
|
|
10063
10066
|
this.pipelineSubscription = this.eventSubject.pipe(
|
|
10064
10067
|
// Split into one inner Observable per resource (system events grouped under '__system__')
|
|
10065
|
-
(0, import_operators.groupBy)((se) => se.
|
|
10068
|
+
(0, import_operators.groupBy)((se) => se.resourceId ?? "__system__"),
|
|
10066
10069
|
(0, import_operators.mergeMap)((group) => {
|
|
10067
10070
|
if (group.key === "__system__") {
|
|
10068
10071
|
return group.pipe(
|
|
@@ -10081,7 +10084,7 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10081
10084
|
}
|
|
10082
10085
|
return (0, import_rxjs.from)(this.safeApplyEvent(eventOrBatch).then(() => {
|
|
10083
10086
|
this.lastProcessed.set(
|
|
10084
|
-
eventOrBatch.
|
|
10087
|
+
eventOrBatch.resourceId,
|
|
10085
10088
|
eventOrBatch.metadata.sequenceNumber
|
|
10086
10089
|
);
|
|
10087
10090
|
}));
|
|
@@ -10099,12 +10102,13 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10099
10102
|
* Wrap applyEventToGraph in try/catch so one failed event doesn't kill the pipeline.
|
|
10100
10103
|
*/
|
|
10101
10104
|
async safeApplyEvent(storedEvent) {
|
|
10105
|
+
await new Promise((resolve2) => setTimeout(resolve2, 0));
|
|
10102
10106
|
try {
|
|
10103
10107
|
await this.applyEventToGraph(storedEvent);
|
|
10104
10108
|
} catch (error) {
|
|
10105
10109
|
this.logger.error("Failed to apply event to graph", {
|
|
10106
|
-
eventType: storedEvent.
|
|
10107
|
-
resourceId: storedEvent.
|
|
10110
|
+
eventType: storedEvent.type,
|
|
10111
|
+
resourceId: storedEvent.resourceId,
|
|
10108
10112
|
error
|
|
10109
10113
|
});
|
|
10110
10114
|
}
|
|
@@ -10117,10 +10121,8 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10117
10121
|
*/
|
|
10118
10122
|
async stop() {
|
|
10119
10123
|
this.logger.info("Stopping GraphDB consumer");
|
|
10120
|
-
|
|
10121
|
-
|
|
10122
|
-
}
|
|
10123
|
-
this._globalSubscription = null;
|
|
10124
|
+
for (const sub of this._globalSubscriptions) sub.unsubscribe();
|
|
10125
|
+
this._globalSubscriptions = [];
|
|
10124
10126
|
this.eventSubject.complete();
|
|
10125
10127
|
if (this.pipelineSubscription) {
|
|
10126
10128
|
this.pipelineSubscription.unsubscribe();
|
|
@@ -10144,18 +10146,18 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10144
10146
|
}
|
|
10145
10147
|
} catch (error) {
|
|
10146
10148
|
this.logger.error("Failed to process batch run", {
|
|
10147
|
-
eventType: run[0].
|
|
10149
|
+
eventType: run[0].type,
|
|
10148
10150
|
runSize: run.length,
|
|
10149
10151
|
error
|
|
10150
10152
|
});
|
|
10151
10153
|
}
|
|
10152
10154
|
const last = run[run.length - 1];
|
|
10153
|
-
if (last.
|
|
10154
|
-
this.lastProcessed.set(last.
|
|
10155
|
+
if (last.resourceId) {
|
|
10156
|
+
this.lastProcessed.set(last.resourceId, last.metadata.sequenceNumber);
|
|
10155
10157
|
}
|
|
10156
10158
|
}
|
|
10157
10159
|
this.logger.debug("Processed batch", {
|
|
10158
|
-
resourceId: events[0]?.
|
|
10160
|
+
resourceId: events[0]?.resourceId,
|
|
10159
10161
|
batchSize: events.length
|
|
10160
10162
|
});
|
|
10161
10163
|
}
|
|
@@ -10165,17 +10167,17 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10165
10167
|
*/
|
|
10166
10168
|
async applyBatchByType(events) {
|
|
10167
10169
|
const graphDb = this.ensureInitialized();
|
|
10168
|
-
const type = events[0].
|
|
10170
|
+
const type = events[0].type;
|
|
10169
10171
|
switch (type) {
|
|
10170
|
-
case "
|
|
10172
|
+
case "yield:created": {
|
|
10171
10173
|
const resources = events.map((e) => this.buildResourceDescriptor(e));
|
|
10172
10174
|
await graphDb.batchCreateResources(resources);
|
|
10173
10175
|
this.logger.info("Batch created resources in graph", { count: events.length });
|
|
10174
10176
|
break;
|
|
10175
10177
|
}
|
|
10176
|
-
case "
|
|
10178
|
+
case "mark:added": {
|
|
10177
10179
|
const inputs = events.map((e) => {
|
|
10178
|
-
const event = e
|
|
10180
|
+
const event = e;
|
|
10179
10181
|
return {
|
|
10180
10182
|
...event.payload.annotation,
|
|
10181
10183
|
creator: didToAgent(event.userId)
|
|
@@ -10196,12 +10198,12 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10196
10198
|
* Extracted for reuse by both applyEventToGraph and applyBatchByType.
|
|
10197
10199
|
*/
|
|
10198
10200
|
buildResourceDescriptor(storedEvent) {
|
|
10199
|
-
const event = storedEvent
|
|
10200
|
-
if (event.type !== "
|
|
10201
|
+
const event = storedEvent;
|
|
10202
|
+
if (event.type !== "yield:created") {
|
|
10201
10203
|
throw new Error("Expected resource.created event");
|
|
10202
10204
|
}
|
|
10203
10205
|
if (!event.resourceId) {
|
|
10204
|
-
throw new Error("
|
|
10206
|
+
throw new Error("yield:created requires resourceId");
|
|
10205
10207
|
}
|
|
10206
10208
|
return {
|
|
10207
10209
|
"@context": "https://schema.org/",
|
|
@@ -10224,32 +10226,32 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10224
10226
|
*/
|
|
10225
10227
|
async applyEventToGraph(storedEvent) {
|
|
10226
10228
|
const graphDb = this.ensureInitialized();
|
|
10227
|
-
const event = storedEvent
|
|
10229
|
+
const event = storedEvent;
|
|
10228
10230
|
this.logger.debug("Applying event to GraphDB", {
|
|
10229
10231
|
eventType: event.type,
|
|
10230
10232
|
sequenceNumber: storedEvent.metadata.sequenceNumber
|
|
10231
10233
|
});
|
|
10232
10234
|
switch (event.type) {
|
|
10233
|
-
case "
|
|
10235
|
+
case "yield:created": {
|
|
10234
10236
|
const resource = this.buildResourceDescriptor(storedEvent);
|
|
10235
10237
|
this.logger.debug("Creating resource in graph", { resourceUri: resource["@id"] });
|
|
10236
10238
|
await graphDb.createResource(resource);
|
|
10237
10239
|
this.logger.info("Resource created in graph", { resourceUri: resource["@id"] });
|
|
10238
10240
|
break;
|
|
10239
10241
|
}
|
|
10240
|
-
case "
|
|
10241
|
-
if (!event.resourceId) throw new Error("
|
|
10242
|
+
case "mark:archived":
|
|
10243
|
+
if (!event.resourceId) throw new Error("mark:archived requires resourceId");
|
|
10242
10244
|
await graphDb.updateResource(makeResourceId(event.resourceId), {
|
|
10243
10245
|
archived: true
|
|
10244
10246
|
});
|
|
10245
10247
|
break;
|
|
10246
|
-
case "
|
|
10247
|
-
if (!event.resourceId) throw new Error("
|
|
10248
|
+
case "mark:unarchived":
|
|
10249
|
+
if (!event.resourceId) throw new Error("mark:unarchived requires resourceId");
|
|
10248
10250
|
await graphDb.updateResource(makeResourceId(event.resourceId), {
|
|
10249
10251
|
archived: false
|
|
10250
10252
|
});
|
|
10251
10253
|
break;
|
|
10252
|
-
case "
|
|
10254
|
+
case "mark:added":
|
|
10253
10255
|
this.logger.debug("Processing annotation.added event", {
|
|
10254
10256
|
annotationId: event.payload.annotation.id
|
|
10255
10257
|
});
|
|
@@ -10261,10 +10263,10 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10261
10263
|
annotationId: event.payload.annotation.id
|
|
10262
10264
|
});
|
|
10263
10265
|
break;
|
|
10264
|
-
case "
|
|
10266
|
+
case "mark:removed":
|
|
10265
10267
|
await graphDb.deleteAnnotation(makeAnnotationId(event.payload.annotationId));
|
|
10266
10268
|
break;
|
|
10267
|
-
case "
|
|
10269
|
+
case "mark:body-updated":
|
|
10268
10270
|
this.logger.debug("Processing annotation.body.updated event", {
|
|
10269
10271
|
annotationId: event.payload.annotationId,
|
|
10270
10272
|
payload: event.payload
|
|
@@ -10307,8 +10309,8 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10307
10309
|
});
|
|
10308
10310
|
}
|
|
10309
10311
|
break;
|
|
10310
|
-
case "
|
|
10311
|
-
if (!event.resourceId) throw new Error("
|
|
10312
|
+
case "mark:entity-tag-added":
|
|
10313
|
+
if (!event.resourceId) throw new Error("mark:entity-tag-added requires resourceId");
|
|
10312
10314
|
{
|
|
10313
10315
|
const rid = makeResourceId(event.resourceId);
|
|
10314
10316
|
const doc = await graphDb.getResource(rid);
|
|
@@ -10319,8 +10321,8 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10319
10321
|
}
|
|
10320
10322
|
}
|
|
10321
10323
|
break;
|
|
10322
|
-
case "
|
|
10323
|
-
if (!event.resourceId) throw new Error("
|
|
10324
|
+
case "mark:entity-tag-removed":
|
|
10325
|
+
if (!event.resourceId) throw new Error("mark:entity-tag-removed requires resourceId");
|
|
10324
10326
|
{
|
|
10325
10327
|
const rid = makeResourceId(event.resourceId);
|
|
10326
10328
|
const doc = await graphDb.getResource(rid);
|
|
@@ -10331,7 +10333,7 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10331
10333
|
}
|
|
10332
10334
|
}
|
|
10333
10335
|
break;
|
|
10334
|
-
case "
|
|
10336
|
+
case "mark:entity-type-added":
|
|
10335
10337
|
await graphDb.addEntityType(event.payload.entityType);
|
|
10336
10338
|
break;
|
|
10337
10339
|
default:
|
|
@@ -10342,20 +10344,20 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10342
10344
|
* Rebuild entire resource from events.
|
|
10343
10345
|
* Bypasses the live pipeline — reads directly from event store.
|
|
10344
10346
|
*/
|
|
10345
|
-
async rebuildResource(
|
|
10347
|
+
async rebuildResource(resourceId7) {
|
|
10346
10348
|
const graphDb = this.ensureInitialized();
|
|
10347
|
-
this.logger.info("Rebuilding resource from events", { resourceId:
|
|
10349
|
+
this.logger.info("Rebuilding resource from events", { resourceId: resourceId7 });
|
|
10348
10350
|
try {
|
|
10349
|
-
await graphDb.deleteResource(
|
|
10351
|
+
await graphDb.deleteResource(resourceId7);
|
|
10350
10352
|
} catch (error) {
|
|
10351
|
-
this.logger.debug("No existing resource to delete", { resourceId:
|
|
10353
|
+
this.logger.debug("No existing resource to delete", { resourceId: resourceId7 });
|
|
10352
10354
|
}
|
|
10353
10355
|
const query = new EventQuery(this.eventStore.log.storage);
|
|
10354
|
-
const events = await query.getResourceEvents(
|
|
10356
|
+
const events = await query.getResourceEvents(resourceId7);
|
|
10355
10357
|
for (const storedEvent of events) {
|
|
10356
10358
|
await this.applyEventToGraph(storedEvent);
|
|
10357
10359
|
}
|
|
10358
|
-
this.logger.info("Resource rebuild complete", { resourceId:
|
|
10360
|
+
this.logger.info("Resource rebuild complete", { resourceId: resourceId7, eventCount: events.length });
|
|
10359
10361
|
}
|
|
10360
10362
|
/**
|
|
10361
10363
|
* Rebuild entire GraphDB from all events.
|
|
@@ -10371,10 +10373,10 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10371
10373
|
const allResourceIds = await this.eventStore.log.getAllResourceIds();
|
|
10372
10374
|
this.logger.info("Found resources to rebuild", { count: allResourceIds.length });
|
|
10373
10375
|
this.logger.info("PASS 1: Creating all nodes (resources + annotations)");
|
|
10374
|
-
for (const
|
|
10375
|
-
const events = await query.getResourceEvents(makeResourceId(
|
|
10376
|
+
for (const resourceId7 of allResourceIds) {
|
|
10377
|
+
const events = await query.getResourceEvents(makeResourceId(resourceId7));
|
|
10376
10378
|
for (const storedEvent of events) {
|
|
10377
|
-
if (storedEvent.
|
|
10379
|
+
if (storedEvent.type === "mark:body-updated") {
|
|
10378
10380
|
continue;
|
|
10379
10381
|
}
|
|
10380
10382
|
await this.applyEventToGraph(storedEvent);
|
|
@@ -10382,10 +10384,10 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10382
10384
|
}
|
|
10383
10385
|
this.logger.info("Pass 1 complete - all nodes created");
|
|
10384
10386
|
this.logger.info("PASS 2: Creating all REFERENCES edges");
|
|
10385
|
-
for (const
|
|
10386
|
-
const events = await query.getResourceEvents(makeResourceId(
|
|
10387
|
+
for (const resourceId7 of allResourceIds) {
|
|
10388
|
+
const events = await query.getResourceEvents(makeResourceId(resourceId7));
|
|
10387
10389
|
for (const storedEvent of events) {
|
|
10388
|
-
if (storedEvent.
|
|
10390
|
+
if (storedEvent.type === "mark:body-updated") {
|
|
10389
10391
|
await this.applyEventToGraph(storedEvent);
|
|
10390
10392
|
}
|
|
10391
10393
|
}
|
|
@@ -10398,7 +10400,7 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10398
10400
|
*/
|
|
10399
10401
|
getHealthMetrics() {
|
|
10400
10402
|
return {
|
|
10401
|
-
subscriptions: this.
|
|
10403
|
+
subscriptions: this._globalSubscriptions.length,
|
|
10402
10404
|
lastProcessed: Object.fromEntries(this.lastProcessed),
|
|
10403
10405
|
pipelineActive: !!this.pipelineSubscription
|
|
10404
10406
|
};
|
|
@@ -10431,29 +10433,30 @@ var Smelter = class _Smelter {
|
|
|
10431
10433
|
this.chunkingConfig = chunkingConfig ?? DEFAULT_CHUNKING_CONFIG;
|
|
10432
10434
|
}
|
|
10433
10435
|
static SMELTER_RELEVANT_EVENTS = /* @__PURE__ */ new Set([
|
|
10434
|
-
"
|
|
10435
|
-
"
|
|
10436
|
-
"
|
|
10437
|
-
"
|
|
10436
|
+
"yield:created",
|
|
10437
|
+
"mark:archived",
|
|
10438
|
+
"mark:added",
|
|
10439
|
+
"mark:removed"
|
|
10438
10440
|
]);
|
|
10439
10441
|
static BURST_WINDOW_MS = 50;
|
|
10440
10442
|
static MAX_BATCH_SIZE = 100;
|
|
10441
10443
|
static IDLE_TIMEOUT_MS = 200;
|
|
10442
|
-
|
|
10444
|
+
_globalSubscriptions = [];
|
|
10443
10445
|
eventSubject = new import_rxjs2.Subject();
|
|
10444
10446
|
pipelineSubscription = null;
|
|
10445
10447
|
logger;
|
|
10446
10448
|
chunkingConfig;
|
|
10447
10449
|
async initialize() {
|
|
10448
10450
|
this.logger.info("Smelter actor initializing");
|
|
10449
|
-
|
|
10450
|
-
(
|
|
10451
|
-
|
|
10452
|
-
|
|
10453
|
-
|
|
10454
|
-
|
|
10451
|
+
for (const eventType of _Smelter.SMELTER_RELEVANT_EVENTS) {
|
|
10452
|
+
this._globalSubscriptions.push(
|
|
10453
|
+
this.eventBus.getDomainEvent(eventType).subscribe(
|
|
10454
|
+
(storedEvent) => this.eventSubject.next(storedEvent)
|
|
10455
|
+
)
|
|
10456
|
+
);
|
|
10457
|
+
}
|
|
10455
10458
|
this.pipelineSubscription = this.eventSubject.pipe(
|
|
10456
|
-
(0, import_operators2.groupBy)((se) => se.
|
|
10459
|
+
(0, import_operators2.groupBy)((se) => se.resourceId ?? "__unknown__"),
|
|
10457
10460
|
(0, import_operators2.mergeMap)(
|
|
10458
10461
|
(group) => group.pipe(
|
|
10459
10462
|
burstBuffer2({
|
|
@@ -10475,17 +10478,15 @@ var Smelter = class _Smelter {
|
|
|
10475
10478
|
this.logger.info("Smelter actor initialized");
|
|
10476
10479
|
}
|
|
10477
10480
|
async stop() {
|
|
10478
|
-
|
|
10479
|
-
|
|
10480
|
-
}
|
|
10481
|
-
this._globalSubscription = null;
|
|
10481
|
+
for (const sub of this._globalSubscriptions) sub.unsubscribe();
|
|
10482
|
+
this._globalSubscriptions = [];
|
|
10482
10483
|
this.pipelineSubscription?.unsubscribe();
|
|
10483
10484
|
this.eventSubject.complete();
|
|
10484
10485
|
this.logger.info("Smelter actor stopped");
|
|
10485
10486
|
}
|
|
10486
10487
|
/**
|
|
10487
10488
|
* Rebuild the vector store from persisted embedding events in the event log.
|
|
10488
|
-
* Reads all embedding
|
|
10489
|
+
* Reads all embedding:computed / embedding:deleted events and replays them.
|
|
10489
10490
|
* Bypasses the live pipeline — reads directly from the event store.
|
|
10490
10491
|
*/
|
|
10491
10492
|
async rebuildAll() {
|
|
@@ -10498,24 +10499,24 @@ var Smelter = class _Smelter {
|
|
|
10498
10499
|
for (const rid of allResourceIds) {
|
|
10499
10500
|
const events = await query.getResourceEvents(makeResourceId2(rid));
|
|
10500
10501
|
const embeddingEvents = events.filter(
|
|
10501
|
-
(e) => e.
|
|
10502
|
+
(e) => e.type === "embedding:computed" || e.type === "embedding:deleted"
|
|
10502
10503
|
);
|
|
10503
10504
|
if (embeddingEvents.length === 0) continue;
|
|
10504
10505
|
const lastEvent = embeddingEvents[embeddingEvents.length - 1];
|
|
10505
|
-
if (lastEvent.
|
|
10506
|
+
if (lastEvent.type === "embedding:deleted" && !lastEvent.payload.annotationId) {
|
|
10506
10507
|
continue;
|
|
10507
10508
|
}
|
|
10508
10509
|
const deletedAnnotations = /* @__PURE__ */ new Set();
|
|
10509
10510
|
for (const e of embeddingEvents) {
|
|
10510
|
-
if (e.
|
|
10511
|
-
const payload = e.
|
|
10511
|
+
if (e.type === "embedding:deleted") {
|
|
10512
|
+
const payload = e.payload;
|
|
10512
10513
|
if (payload.annotationId) deletedAnnotations.add(String(payload.annotationId));
|
|
10513
10514
|
}
|
|
10514
10515
|
}
|
|
10515
10516
|
const resourceChunks = [];
|
|
10516
10517
|
for (const e of embeddingEvents) {
|
|
10517
|
-
if (e.
|
|
10518
|
-
const payload = e.
|
|
10518
|
+
if (e.type !== "embedding:computed") continue;
|
|
10519
|
+
const payload = e.payload;
|
|
10519
10520
|
if (payload.annotationId) {
|
|
10520
10521
|
if (deletedAnnotations.has(String(payload.annotationId))) continue;
|
|
10521
10522
|
await this.vectorStore.upsertAnnotationVector(
|
|
@@ -10523,7 +10524,7 @@ var Smelter = class _Smelter {
|
|
|
10523
10524
|
payload.embedding,
|
|
10524
10525
|
{
|
|
10525
10526
|
annotationId: makeAnnotationId2(String(payload.annotationId)),
|
|
10526
|
-
resourceId: makeResourceId2(e.
|
|
10527
|
+
resourceId: makeResourceId2(e.resourceId),
|
|
10527
10528
|
motivation: "",
|
|
10528
10529
|
entityTypes: [],
|
|
10529
10530
|
exactText: payload.chunkText
|
|
@@ -10558,7 +10559,7 @@ var Smelter = class _Smelter {
|
|
|
10558
10559
|
}
|
|
10559
10560
|
} catch (error) {
|
|
10560
10561
|
this.logger.error("Smelter failed to process batch run", {
|
|
10561
|
-
eventType: run[0].
|
|
10562
|
+
eventType: run[0].type,
|
|
10562
10563
|
runSize: run.length,
|
|
10563
10564
|
error
|
|
10564
10565
|
});
|
|
@@ -10571,12 +10572,12 @@ var Smelter = class _Smelter {
|
|
|
10571
10572
|
* then distributes results back to their respective resources/annotations.
|
|
10572
10573
|
*/
|
|
10573
10574
|
async applyBatchByType(events) {
|
|
10574
|
-
const type = events[0].
|
|
10575
|
+
const type = events[0].type;
|
|
10575
10576
|
switch (type) {
|
|
10576
|
-
case "
|
|
10577
|
+
case "yield:created":
|
|
10577
10578
|
await this.batchResourceCreated(events);
|
|
10578
10579
|
break;
|
|
10579
|
-
case "
|
|
10580
|
+
case "mark:added":
|
|
10580
10581
|
await this.batchAnnotationAdded(events);
|
|
10581
10582
|
break;
|
|
10582
10583
|
default:
|
|
@@ -10593,7 +10594,7 @@ var Smelter = class _Smelter {
|
|
|
10593
10594
|
const resourceData = [];
|
|
10594
10595
|
const allChunks = [];
|
|
10595
10596
|
for (const storedEvent of events) {
|
|
10596
|
-
const event = storedEvent
|
|
10597
|
+
const event = storedEvent;
|
|
10597
10598
|
const rid = makeResourceId2(event.resourceId);
|
|
10598
10599
|
const storageUri = event.payload.storageUri;
|
|
10599
10600
|
if (!storageUri) continue;
|
|
@@ -10614,7 +10615,7 @@ var Smelter = class _Smelter {
|
|
|
10614
10615
|
for (const { rid, chunks } of resourceData) {
|
|
10615
10616
|
const embeddingChunks = chunks.map((text, i) => {
|
|
10616
10617
|
const embedding = allEmbeddings[offset + i];
|
|
10617
|
-
this.eventBus.get("embedding:
|
|
10618
|
+
this.eventBus.get("embedding:compute").next({
|
|
10618
10619
|
resourceId: rid,
|
|
10619
10620
|
chunkIndex: i,
|
|
10620
10621
|
chunkText: text,
|
|
@@ -10639,7 +10640,7 @@ var Smelter = class _Smelter {
|
|
|
10639
10640
|
async batchAnnotationAdded(events) {
|
|
10640
10641
|
const annotationData = [];
|
|
10641
10642
|
for (const storedEvent of events) {
|
|
10642
|
-
const event = storedEvent
|
|
10643
|
+
const event = storedEvent;
|
|
10643
10644
|
const annotation = event.payload.annotation;
|
|
10644
10645
|
if (!annotation?.id) continue;
|
|
10645
10646
|
const selector = getTargetSelector(annotation.target);
|
|
@@ -10659,7 +10660,7 @@ var Smelter = class _Smelter {
|
|
|
10659
10660
|
for (let i = 0; i < annotationData.length; i++) {
|
|
10660
10661
|
const { rid, aid, exactText, annotation } = annotationData[i];
|
|
10661
10662
|
const embedding = allEmbeddings[i];
|
|
10662
|
-
this.eventBus.get("embedding:
|
|
10663
|
+
this.eventBus.get("embedding:compute").next({
|
|
10663
10664
|
resourceId: rid,
|
|
10664
10665
|
annotationId: aid,
|
|
10665
10666
|
chunkIndex: 0,
|
|
@@ -10687,26 +10688,26 @@ var Smelter = class _Smelter {
|
|
|
10687
10688
|
await this.processEvent(storedEvent);
|
|
10688
10689
|
} catch (err) {
|
|
10689
10690
|
this.logger.error("Smelter failed to process event", {
|
|
10690
|
-
type: storedEvent.
|
|
10691
|
-
resourceId: storedEvent.
|
|
10691
|
+
type: storedEvent.type,
|
|
10692
|
+
resourceId: storedEvent.resourceId,
|
|
10692
10693
|
error: err instanceof Error ? err.message : String(err),
|
|
10693
10694
|
stack: err instanceof Error ? err.stack : void 0
|
|
10694
10695
|
});
|
|
10695
10696
|
}
|
|
10696
10697
|
}
|
|
10697
10698
|
async processEvent(storedEvent) {
|
|
10698
|
-
const event = storedEvent
|
|
10699
|
+
const event = storedEvent;
|
|
10699
10700
|
switch (event.type) {
|
|
10700
|
-
case "
|
|
10701
|
+
case "yield:created":
|
|
10701
10702
|
await this.handleResourceCreated(event);
|
|
10702
10703
|
break;
|
|
10703
|
-
case "
|
|
10704
|
+
case "mark:archived":
|
|
10704
10705
|
await this.handleResourceArchived(event);
|
|
10705
10706
|
break;
|
|
10706
|
-
case "
|
|
10707
|
+
case "mark:added":
|
|
10707
10708
|
await this.handleAnnotationAdded(event);
|
|
10708
10709
|
break;
|
|
10709
|
-
case "
|
|
10710
|
+
case "mark:removed":
|
|
10710
10711
|
await this.handleAnnotationRemoved(event);
|
|
10711
10712
|
break;
|
|
10712
10713
|
}
|
|
@@ -10743,7 +10744,7 @@ var Smelter = class _Smelter {
|
|
|
10743
10744
|
heapMB: Math.round(process.memoryUsage().heapUsed / 1024 / 1024)
|
|
10744
10745
|
});
|
|
10745
10746
|
const embeddingChunks = chunks.map((text2, i) => {
|
|
10746
|
-
this.eventBus.get("embedding:
|
|
10747
|
+
this.eventBus.get("embedding:compute").next({
|
|
10747
10748
|
resourceId: rid,
|
|
10748
10749
|
chunkIndex: i,
|
|
10749
10750
|
chunkText: text2,
|
|
@@ -10768,7 +10769,7 @@ var Smelter = class _Smelter {
|
|
|
10768
10769
|
async handleResourceArchived(event) {
|
|
10769
10770
|
const rid = makeResourceId2(event.resourceId);
|
|
10770
10771
|
await this.vectorStore.deleteResourceVectors(rid);
|
|
10771
|
-
this.eventBus.get("embedding:
|
|
10772
|
+
this.eventBus.get("embedding:delete").next({ resourceId: rid });
|
|
10772
10773
|
this.logger.debug("Smelter deleted resource vectors", {
|
|
10773
10774
|
resourceId: String(rid)
|
|
10774
10775
|
});
|
|
@@ -10789,7 +10790,7 @@ var Smelter = class _Smelter {
|
|
|
10789
10790
|
heapMB: Math.round(process.memoryUsage().heapUsed / 1024 / 1024)
|
|
10790
10791
|
});
|
|
10791
10792
|
const embedding = await this.embeddingProvider.embed(exactText);
|
|
10792
|
-
this.eventBus.get("embedding:
|
|
10793
|
+
this.eventBus.get("embedding:compute").next({
|
|
10793
10794
|
resourceId: rid,
|
|
10794
10795
|
annotationId: aid,
|
|
10795
10796
|
chunkIndex: 0,
|
|
@@ -10812,12 +10813,12 @@ var Smelter = class _Smelter {
|
|
|
10812
10813
|
});
|
|
10813
10814
|
}
|
|
10814
10815
|
async handleAnnotationRemoved(event) {
|
|
10815
|
-
const
|
|
10816
|
-
if (!
|
|
10816
|
+
const annotationId3 = String(event.payload.annotationId);
|
|
10817
|
+
if (!annotationId3) return;
|
|
10817
10818
|
const rid = makeResourceId2(event.resourceId);
|
|
10818
|
-
const aid = makeAnnotationId2(
|
|
10819
|
+
const aid = makeAnnotationId2(annotationId3);
|
|
10819
10820
|
await this.vectorStore.deleteAnnotationVector(aid);
|
|
10820
|
-
this.eventBus.get("embedding:
|
|
10821
|
+
this.eventBus.get("embedding:delete").next({
|
|
10821
10822
|
resourceId: rid,
|
|
10822
10823
|
annotationId: aid
|
|
10823
10824
|
});
|
|
@@ -10828,7 +10829,7 @@ var Smelter = class _Smelter {
|
|
|
10828
10829
|
};
|
|
10829
10830
|
|
|
10830
10831
|
// src/knowledge-base.ts
|
|
10831
|
-
async function createKnowledgeBase(eventStore, project, graphDb, logger, options) {
|
|
10832
|
+
async function createKnowledgeBase(eventStore, project, graphDb, eventBus, logger, options) {
|
|
10832
10833
|
const views = new FilesystemViewStorage(project);
|
|
10833
10834
|
const content = new WorkingTreeStore(
|
|
10834
10835
|
project,
|
|
@@ -10837,10 +10838,12 @@ async function createKnowledgeBase(eventStore, project, graphDb, logger, options
|
|
|
10837
10838
|
const graphConsumer = new GraphDBConsumer(
|
|
10838
10839
|
eventStore,
|
|
10839
10840
|
graphDb,
|
|
10841
|
+
eventBus,
|
|
10840
10842
|
logger.child({ component: "graph-consumer" })
|
|
10841
10843
|
);
|
|
10842
10844
|
await graphConsumer.initialize();
|
|
10843
10845
|
if (!options?.skipRebuild) {
|
|
10846
|
+
await eventStore.views.rebuildAll(eventStore.log);
|
|
10844
10847
|
await graphConsumer.rebuildAll();
|
|
10845
10848
|
}
|
|
10846
10849
|
const kb = {
|
|
@@ -10851,11 +10854,11 @@ async function createKnowledgeBase(eventStore, project, graphDb, logger, options
|
|
|
10851
10854
|
graphConsumer,
|
|
10852
10855
|
projectionsDir: project.projectionsDir
|
|
10853
10856
|
};
|
|
10854
|
-
if (options?.vectorStore && options?.embeddingProvider
|
|
10857
|
+
if (options?.vectorStore && options?.embeddingProvider) {
|
|
10855
10858
|
kb.vectors = options.vectorStore;
|
|
10856
10859
|
kb.smelter = new Smelter(
|
|
10857
10860
|
eventStore,
|
|
10858
|
-
|
|
10861
|
+
eventBus,
|
|
10859
10862
|
options.vectorStore,
|
|
10860
10863
|
options.embeddingProvider,
|
|
10861
10864
|
content,
|
|
@@ -10873,7 +10876,7 @@ async function createKnowledgeBase(eventStore, project, graphDb, logger, options
|
|
|
10873
10876
|
// src/gatherer.ts
|
|
10874
10877
|
var import_rxjs3 = __toESM(require_cjs(), 1);
|
|
10875
10878
|
var import_operators3 = __toESM(require_operators(), 1);
|
|
10876
|
-
import { annotationId as makeAnnotationId3 } from "@semiont/core";
|
|
10879
|
+
import { annotationId as makeAnnotationId3, resourceId } from "@semiont/core";
|
|
10877
10880
|
|
|
10878
10881
|
// src/generation/resource-generation.ts
|
|
10879
10882
|
async function generateResourceSummary(resourceName, content, entityTypes, client) {
|
|
@@ -10918,8 +10921,8 @@ var ResourceContext = class {
|
|
|
10918
10921
|
/**
|
|
10919
10922
|
* Get resource metadata from view storage
|
|
10920
10923
|
*/
|
|
10921
|
-
static async getResourceMetadata(
|
|
10922
|
-
const view = await kb.views.get(
|
|
10924
|
+
static async getResourceMetadata(resourceId7, kb) {
|
|
10925
|
+
const view = await kb.views.get(resourceId7);
|
|
10923
10926
|
if (!view) {
|
|
10924
10927
|
return null;
|
|
10925
10928
|
}
|
|
@@ -10999,7 +11002,7 @@ var AnnotationContext = class {
|
|
|
10999
11002
|
* @returns Rich context for LLM processing
|
|
11000
11003
|
* @throws Error if annotation or resource not found
|
|
11001
11004
|
*/
|
|
11002
|
-
static async buildLLMContext(
|
|
11005
|
+
static async buildLLMContext(annotationId3, resourceId7, kb, options = {}, inferenceClient, logger, embeddingProvider) {
|
|
11003
11006
|
const {
|
|
11004
11007
|
includeSourceContext = true,
|
|
11005
11008
|
includeTargetContext = true,
|
|
@@ -11008,34 +11011,34 @@ var AnnotationContext = class {
|
|
|
11008
11011
|
if (contextWindow < 100 || contextWindow > 5e3) {
|
|
11009
11012
|
throw new Error("contextWindow must be between 100 and 5000");
|
|
11010
11013
|
}
|
|
11011
|
-
logger?.debug("Building LLM context", { annotationId:
|
|
11012
|
-
logger?.debug("Getting view for resource", { resourceId:
|
|
11014
|
+
logger?.debug("Building LLM context", { annotationId: annotationId3, resourceId: resourceId7 });
|
|
11015
|
+
logger?.debug("Getting view for resource", { resourceId: resourceId7 });
|
|
11013
11016
|
let sourceView;
|
|
11014
11017
|
try {
|
|
11015
|
-
sourceView = await kb.views.get(
|
|
11018
|
+
sourceView = await kb.views.get(resourceId7);
|
|
11016
11019
|
logger?.debug("Retrieved view", { hasView: !!sourceView });
|
|
11017
11020
|
if (!sourceView) {
|
|
11018
11021
|
throw new Error("Source resource not found");
|
|
11019
11022
|
}
|
|
11020
11023
|
} catch (error) {
|
|
11021
|
-
logger?.error("Error getting view", { resourceId:
|
|
11024
|
+
logger?.error("Error getting view", { resourceId: resourceId7, error });
|
|
11022
11025
|
throw error;
|
|
11023
11026
|
}
|
|
11024
11027
|
logger?.debug("Looking for annotation in resource", {
|
|
11025
|
-
annotationId:
|
|
11026
|
-
resourceId:
|
|
11028
|
+
annotationId: annotationId3,
|
|
11029
|
+
resourceId: resourceId7,
|
|
11027
11030
|
totalAnnotations: sourceView.annotations.annotations.length,
|
|
11028
11031
|
firstFiveIds: sourceView.annotations.annotations.slice(0, 5).map((a) => a.id)
|
|
11029
11032
|
});
|
|
11030
|
-
const annotation = sourceView.annotations.annotations.find((a) => a.id ===
|
|
11033
|
+
const annotation = sourceView.annotations.annotations.find((a) => a.id === annotationId3);
|
|
11031
11034
|
logger?.debug("Annotation search result", { found: !!annotation });
|
|
11032
11035
|
if (!annotation) {
|
|
11033
11036
|
throw new Error("Annotation not found in view");
|
|
11034
11037
|
}
|
|
11035
11038
|
const targetSource = getTargetSource(annotation.target);
|
|
11036
|
-
logger?.debug("Validating target resource", { targetSource, expectedResourceId:
|
|
11037
|
-
if (targetSource !== String(
|
|
11038
|
-
throw new Error(`Annotation target resource ID (${targetSource}) does not match expected resource ID (${
|
|
11039
|
+
logger?.debug("Validating target resource", { targetSource, expectedResourceId: resourceId7 });
|
|
11040
|
+
if (targetSource !== String(resourceId7)) {
|
|
11041
|
+
throw new Error(`Annotation target resource ID (${targetSource}) does not match expected resource ID (${resourceId7})`);
|
|
11039
11042
|
}
|
|
11040
11043
|
const sourceDoc = sourceView.resource;
|
|
11041
11044
|
const bodySource = getBodySource(annotation.body);
|
|
@@ -11099,16 +11102,16 @@ var AnnotationContext = class {
|
|
|
11099
11102
|
}
|
|
11100
11103
|
}
|
|
11101
11104
|
const suggestedResolution = void 0;
|
|
11102
|
-
logger?.debug("Building graph context", { resourceId:
|
|
11105
|
+
logger?.debug("Building graph context", { resourceId: resourceId7 });
|
|
11103
11106
|
const [connections, referencedByAnnotations, entityTypeStats] = await Promise.all([
|
|
11104
|
-
kb.graph.getResourceConnections(
|
|
11105
|
-
kb.graph.getResourceReferencedBy(
|
|
11107
|
+
kb.graph.getResourceConnections(resourceId7),
|
|
11108
|
+
kb.graph.getResourceReferencedBy(resourceId7),
|
|
11106
11109
|
kb.graph.getEntityTypeStats()
|
|
11107
11110
|
]);
|
|
11108
11111
|
const citedByMap = /* @__PURE__ */ new Map();
|
|
11109
11112
|
for (const ann of referencedByAnnotations) {
|
|
11110
11113
|
const source = getTargetSource(ann.target);
|
|
11111
|
-
if (source && source !== String(
|
|
11114
|
+
if (source && source !== String(resourceId7)) {
|
|
11112
11115
|
const sourceResId = createResourceId(source);
|
|
11113
11116
|
const sourceView2 = await kb.views.get(sourceResId);
|
|
11114
11117
|
if (sourceView2?.resource) {
|
|
@@ -11119,7 +11122,7 @@ var AnnotationContext = class {
|
|
|
11119
11122
|
const annotationEntityTypes = getEntityTypes(annotation);
|
|
11120
11123
|
const siblingEntityTypes = /* @__PURE__ */ new Set();
|
|
11121
11124
|
for (const ann of sourceView.annotations.annotations) {
|
|
11122
|
-
if (ann.id !==
|
|
11125
|
+
if (ann.id !== annotationId3) {
|
|
11123
11126
|
for (const et of getEntityTypes(ann)) {
|
|
11124
11127
|
siblingEntityTypes.add(et);
|
|
11125
11128
|
}
|
|
@@ -11180,7 +11183,7 @@ Summary:`;
|
|
|
11180
11183
|
const results = await kb.vectors.searchAnnotations(focalEmbedding, {
|
|
11181
11184
|
limit: 10,
|
|
11182
11185
|
scoreThreshold: 0.5,
|
|
11183
|
-
filter: { excludeResourceId:
|
|
11186
|
+
filter: { excludeResourceId: resourceId7 }
|
|
11184
11187
|
});
|
|
11185
11188
|
if (results.length > 0) {
|
|
11186
11189
|
semanticContext = {
|
|
@@ -11232,10 +11235,10 @@ Summary:`;
|
|
|
11232
11235
|
* Get resource annotations from view storage (fast path)
|
|
11233
11236
|
* Throws if view missing
|
|
11234
11237
|
*/
|
|
11235
|
-
static async getResourceAnnotations(
|
|
11236
|
-
const view = await kb.views.get(
|
|
11238
|
+
static async getResourceAnnotations(resourceId7, kb) {
|
|
11239
|
+
const view = await kb.views.get(resourceId7);
|
|
11237
11240
|
if (!view) {
|
|
11238
|
-
throw new Error(`Resource ${
|
|
11241
|
+
throw new Error(`Resource ${resourceId7} not found in view storage`);
|
|
11239
11242
|
}
|
|
11240
11243
|
return view.annotations;
|
|
11241
11244
|
}
|
|
@@ -11243,8 +11246,8 @@ Summary:`;
|
|
|
11243
11246
|
* Get all annotations
|
|
11244
11247
|
* @returns Array of all annotation objects
|
|
11245
11248
|
*/
|
|
11246
|
-
static async getAllAnnotations(
|
|
11247
|
-
const annotations = await this.getResourceAnnotations(
|
|
11249
|
+
static async getAllAnnotations(resourceId7, kb) {
|
|
11250
|
+
const annotations = await this.getResourceAnnotations(resourceId7, kb);
|
|
11248
11251
|
return await this.enrichResolvedReferences(annotations.annotations, kb);
|
|
11249
11252
|
}
|
|
11250
11253
|
/**
|
|
@@ -11313,8 +11316,8 @@ Summary:`;
|
|
|
11313
11316
|
* Get resource stats (version info)
|
|
11314
11317
|
* @returns Version and timestamp info for the annotations
|
|
11315
11318
|
*/
|
|
11316
|
-
static async getResourceStats(
|
|
11317
|
-
const annotations = await this.getResourceAnnotations(
|
|
11319
|
+
static async getResourceStats(resourceId7, kb) {
|
|
11320
|
+
const annotations = await this.getResourceAnnotations(resourceId7, kb);
|
|
11318
11321
|
return {
|
|
11319
11322
|
resourceId: annotations.resourceId,
|
|
11320
11323
|
version: annotations.version,
|
|
@@ -11324,16 +11327,16 @@ Summary:`;
|
|
|
11324
11327
|
/**
|
|
11325
11328
|
* Check if resource exists in view storage
|
|
11326
11329
|
*/
|
|
11327
|
-
static async resourceExists(
|
|
11328
|
-
return await kb.views.exists(
|
|
11330
|
+
static async resourceExists(resourceId7, kb) {
|
|
11331
|
+
return await kb.views.exists(resourceId7);
|
|
11329
11332
|
}
|
|
11330
11333
|
/**
|
|
11331
11334
|
* Get a single annotation by ID
|
|
11332
11335
|
* O(1) lookup using resource ID to access view storage
|
|
11333
11336
|
*/
|
|
11334
|
-
static async getAnnotation(
|
|
11335
|
-
const annotations = await this.getResourceAnnotations(
|
|
11336
|
-
return annotations.annotations.find((a) => a.id ===
|
|
11337
|
+
static async getAnnotation(annotationId3, resourceId7, kb) {
|
|
11338
|
+
const annotations = await this.getResourceAnnotations(resourceId7, kb);
|
|
11339
|
+
return annotations.annotations.find((a) => a.id === annotationId3) || null;
|
|
11337
11340
|
}
|
|
11338
11341
|
/**
|
|
11339
11342
|
* List annotations with optional filtering
|
|
@@ -11349,8 +11352,8 @@ Summary:`;
|
|
|
11349
11352
|
/**
|
|
11350
11353
|
* Get annotation context (selected text with surrounding context)
|
|
11351
11354
|
*/
|
|
11352
|
-
static async getAnnotationContext(
|
|
11353
|
-
const annotation = await this.getAnnotation(
|
|
11355
|
+
static async getAnnotationContext(annotationId3, resourceId7, contextBefore, contextAfter, kb) {
|
|
11356
|
+
const annotation = await this.getAnnotation(annotationId3, resourceId7, kb);
|
|
11354
11357
|
if (!annotation) {
|
|
11355
11358
|
throw new Error("Annotation not found");
|
|
11356
11359
|
}
|
|
@@ -11382,8 +11385,8 @@ Summary:`;
|
|
|
11382
11385
|
/**
|
|
11383
11386
|
* Generate AI summary of annotation in context
|
|
11384
11387
|
*/
|
|
11385
|
-
static async generateAnnotationSummary(
|
|
11386
|
-
const annotation = await this.getAnnotation(
|
|
11388
|
+
static async generateAnnotationSummary(annotationId3, resourceId7, kb, inferenceClient) {
|
|
11389
|
+
const annotation = await this.getAnnotation(annotationId3, resourceId7, kb);
|
|
11387
11390
|
if (!annotation) {
|
|
11388
11391
|
throw new Error("Annotation not found");
|
|
11389
11392
|
}
|
|
@@ -11469,8 +11472,8 @@ var GraphContext = class {
|
|
|
11469
11472
|
* Get all resources referencing this resource (backlinks)
|
|
11470
11473
|
* Requires graph traversal - must use graph database
|
|
11471
11474
|
*/
|
|
11472
|
-
static async getBacklinks(
|
|
11473
|
-
return await kb.graph.getResourceReferencedBy(
|
|
11475
|
+
static async getBacklinks(resourceId7, kb) {
|
|
11476
|
+
return await kb.graph.getResourceReferencedBy(resourceId7);
|
|
11474
11477
|
}
|
|
11475
11478
|
/**
|
|
11476
11479
|
* Find shortest path between two resources
|
|
@@ -11483,8 +11486,8 @@ var GraphContext = class {
|
|
|
11483
11486
|
* Get resource connections (graph edges)
|
|
11484
11487
|
* Requires graph traversal - must use graph database
|
|
11485
11488
|
*/
|
|
11486
|
-
static async getResourceConnections(
|
|
11487
|
-
return await kb.graph.getResourceConnections(
|
|
11489
|
+
static async getResourceConnections(resourceId7, kb) {
|
|
11490
|
+
return await kb.graph.getResourceConnections(resourceId7);
|
|
11488
11491
|
}
|
|
11489
11492
|
/**
|
|
11490
11493
|
* Search resources by name (cross-resource query)
|
|
@@ -11497,12 +11500,12 @@ var GraphContext = class {
|
|
|
11497
11500
|
* Build graph representation with nodes and edges for a resource and its connections
|
|
11498
11501
|
* Retrieves connections from graph and builds visualization-ready structure
|
|
11499
11502
|
*/
|
|
11500
|
-
static async buildGraphRepresentation(
|
|
11501
|
-
const mainDoc = await kb.graph.getResource(
|
|
11503
|
+
static async buildGraphRepresentation(resourceId7, maxRelated, kb) {
|
|
11504
|
+
const mainDoc = await kb.graph.getResource(resourceId7);
|
|
11502
11505
|
if (!mainDoc) {
|
|
11503
11506
|
throw new Error("Resource not found");
|
|
11504
11507
|
}
|
|
11505
|
-
const connections = await kb.graph.getResourceConnections(
|
|
11508
|
+
const connections = await kb.graph.getResourceConnections(resourceId7);
|
|
11506
11509
|
const relatedDocs = connections.map((conn) => conn.targetResource).slice(0, maxRelated - 1);
|
|
11507
11510
|
const nodes = [
|
|
11508
11511
|
{
|
|
@@ -11519,7 +11522,7 @@ var GraphContext = class {
|
|
|
11519
11522
|
}))
|
|
11520
11523
|
].filter((node) => node.id !== void 0);
|
|
11521
11524
|
const edges = connections.slice(0, maxRelated - 1).map((conn) => ({
|
|
11522
|
-
source:
|
|
11525
|
+
source: resourceId7,
|
|
11523
11526
|
target: getResourceId2(conn.targetResource),
|
|
11524
11527
|
type: conn.relationshipType || "link",
|
|
11525
11528
|
metadata: {}
|
|
@@ -11536,19 +11539,19 @@ var LLMContext = class {
|
|
|
11536
11539
|
* Get comprehensive LLM context for a resource
|
|
11537
11540
|
* Includes: main resource, related resources, annotations, graph, content, summary, references
|
|
11538
11541
|
*/
|
|
11539
|
-
static async getResourceContext(
|
|
11540
|
-
const mainDoc = await ResourceContext.getResourceMetadata(
|
|
11542
|
+
static async getResourceContext(resourceId7, options, kb, inferenceClient) {
|
|
11543
|
+
const mainDoc = await ResourceContext.getResourceMetadata(resourceId7, kb);
|
|
11541
11544
|
if (!mainDoc) {
|
|
11542
11545
|
throw new Error("Resource not found");
|
|
11543
11546
|
}
|
|
11544
11547
|
const mainContent = options.includeContent ? await ResourceContext.getResourceContent(mainDoc, kb) : void 0;
|
|
11545
11548
|
const graph = await GraphContext.buildGraphRepresentation(
|
|
11546
|
-
|
|
11549
|
+
resourceId7,
|
|
11547
11550
|
options.maxResources,
|
|
11548
11551
|
kb
|
|
11549
11552
|
);
|
|
11550
11553
|
const relatedDocs = [];
|
|
11551
|
-
const resourceIdStr =
|
|
11554
|
+
const resourceIdStr = resourceId7.toString();
|
|
11552
11555
|
for (const node of graph.nodes) {
|
|
11553
11556
|
if (node.id !== resourceIdStr) {
|
|
11554
11557
|
const relatedDoc = await ResourceContext.getResourceMetadata(makeResourceId3(node.id), kb);
|
|
@@ -11570,7 +11573,7 @@ var LLMContext = class {
|
|
|
11570
11573
|
})
|
|
11571
11574
|
);
|
|
11572
11575
|
}
|
|
11573
|
-
const annotations = await AnnotationContext.getAllAnnotations(
|
|
11576
|
+
const annotations = await AnnotationContext.getAllAnnotations(resourceId7, kb);
|
|
11574
11577
|
const summary = options.includeSummary && mainContent ? await generateResourceSummary(
|
|
11575
11578
|
mainDoc.name,
|
|
11576
11579
|
mainContent,
|
|
@@ -11630,6 +11633,7 @@ var Gatherer = class {
|
|
|
11630
11633
|
// Gather handlers (existing)
|
|
11631
11634
|
// ========================================================================
|
|
11632
11635
|
async handleAnnotationGather(event) {
|
|
11636
|
+
const resultBus = this.eventBus.scope(event.resourceId);
|
|
11633
11637
|
try {
|
|
11634
11638
|
this.logger.debug("Gathering annotation context", {
|
|
11635
11639
|
annotationId: event.annotationId,
|
|
@@ -11637,14 +11641,14 @@ var Gatherer = class {
|
|
|
11637
11641
|
});
|
|
11638
11642
|
const response = await AnnotationContext.buildLLMContext(
|
|
11639
11643
|
makeAnnotationId3(event.annotationId),
|
|
11640
|
-
event.resourceId,
|
|
11644
|
+
resourceId(event.resourceId),
|
|
11641
11645
|
this.kb,
|
|
11642
11646
|
event.options ?? {},
|
|
11643
11647
|
this.inferenceClient,
|
|
11644
11648
|
this.logger,
|
|
11645
11649
|
this.embeddingProvider
|
|
11646
11650
|
);
|
|
11647
|
-
|
|
11651
|
+
resultBus.get("gather:complete").next({
|
|
11648
11652
|
correlationId: event.correlationId,
|
|
11649
11653
|
annotationId: event.annotationId,
|
|
11650
11654
|
response
|
|
@@ -11654,25 +11658,26 @@ var Gatherer = class {
|
|
|
11654
11658
|
annotationId: event.annotationId,
|
|
11655
11659
|
error
|
|
11656
11660
|
});
|
|
11657
|
-
|
|
11661
|
+
resultBus.get("gather:failed").next({
|
|
11658
11662
|
correlationId: event.correlationId,
|
|
11659
11663
|
annotationId: event.annotationId,
|
|
11660
|
-
|
|
11664
|
+
message: error instanceof Error ? error.message : String(error)
|
|
11661
11665
|
});
|
|
11662
11666
|
}
|
|
11663
11667
|
}
|
|
11664
11668
|
async handleResourceGather(event) {
|
|
11669
|
+
const resultBus = this.eventBus.scope(event.resourceId);
|
|
11665
11670
|
try {
|
|
11666
11671
|
this.logger.debug("Gathering resource context", {
|
|
11667
11672
|
resourceId: event.resourceId
|
|
11668
11673
|
});
|
|
11669
11674
|
const result = await LLMContext.getResourceContext(
|
|
11670
|
-
event.resourceId,
|
|
11675
|
+
resourceId(event.resourceId),
|
|
11671
11676
|
event.options,
|
|
11672
11677
|
this.kb,
|
|
11673
11678
|
this.inferenceClient
|
|
11674
11679
|
);
|
|
11675
|
-
|
|
11680
|
+
resultBus.get("gather:resource-complete").next({
|
|
11676
11681
|
correlationId: event.correlationId,
|
|
11677
11682
|
resourceId: event.resourceId,
|
|
11678
11683
|
response: result
|
|
@@ -11682,17 +11687,17 @@ var Gatherer = class {
|
|
|
11682
11687
|
resourceId: event.resourceId,
|
|
11683
11688
|
error
|
|
11684
11689
|
});
|
|
11685
|
-
|
|
11690
|
+
resultBus.get("gather:resource-failed").next({
|
|
11686
11691
|
correlationId: event.correlationId,
|
|
11687
11692
|
resourceId: event.resourceId,
|
|
11688
|
-
|
|
11693
|
+
message: error instanceof Error ? error.message : String(error)
|
|
11689
11694
|
});
|
|
11690
11695
|
}
|
|
11691
11696
|
}
|
|
11692
|
-
async generateAnnotationSummary(
|
|
11697
|
+
async generateAnnotationSummary(annotationId3, resourceId7) {
|
|
11693
11698
|
return AnnotationContext.generateAnnotationSummary(
|
|
11694
|
-
|
|
11695
|
-
|
|
11699
|
+
annotationId3,
|
|
11700
|
+
resourceId7,
|
|
11696
11701
|
this.kb,
|
|
11697
11702
|
this.inferenceClient
|
|
11698
11703
|
);
|
|
@@ -11709,7 +11714,7 @@ var Gatherer = class {
|
|
|
11709
11714
|
// src/matcher.ts
|
|
11710
11715
|
var import_rxjs4 = __toESM(require_cjs(), 1);
|
|
11711
11716
|
var import_operators4 = __toESM(require_operators(), 1);
|
|
11712
|
-
import { resourceId } from "@semiont/core";
|
|
11717
|
+
import { resourceId as resourceId2 } from "@semiont/core";
|
|
11713
11718
|
import { getResourceId as getResourceId4, getResourceEntityTypes as getResourceEntityTypes4 } from "@semiont/api-client";
|
|
11714
11719
|
var Matcher = class {
|
|
11715
11720
|
constructor(kb, eventBus, logger, inferenceClient, embeddingProvider) {
|
|
@@ -11733,6 +11738,7 @@ var Matcher = class {
|
|
|
11733
11738
|
}
|
|
11734
11739
|
async handleSearch(event) {
|
|
11735
11740
|
try {
|
|
11741
|
+
const resultBus = this.eventBus.scope(event.resourceId);
|
|
11736
11742
|
const context = event.context;
|
|
11737
11743
|
const selectedText = context.sourceContext?.selected ?? "";
|
|
11738
11744
|
const userHint = context.userHint ?? "";
|
|
@@ -11749,7 +11755,7 @@ var Matcher = class {
|
|
|
11749
11755
|
event.useSemanticScoring
|
|
11750
11756
|
);
|
|
11751
11757
|
const limited = event.limit ? scored.slice(0, event.limit) : scored;
|
|
11752
|
-
|
|
11758
|
+
resultBus.get("match:search-results").next({
|
|
11753
11759
|
correlationId: event.correlationId,
|
|
11754
11760
|
referenceId: event.referenceId,
|
|
11755
11761
|
response: limited
|
|
@@ -11759,7 +11765,7 @@ var Matcher = class {
|
|
|
11759
11765
|
referenceId: event.referenceId,
|
|
11760
11766
|
error
|
|
11761
11767
|
});
|
|
11762
|
-
this.eventBus.get("match:search-failed").next({
|
|
11768
|
+
this.eventBus.scope(event.resourceId).get("match:search-failed").next({
|
|
11763
11769
|
correlationId: event.correlationId,
|
|
11764
11770
|
referenceId: event.referenceId,
|
|
11765
11771
|
error: error instanceof Error ? error.message : String(error)
|
|
@@ -11792,7 +11798,7 @@ var Matcher = class {
|
|
|
11792
11798
|
]);
|
|
11793
11799
|
const neighborResources = await Promise.all(
|
|
11794
11800
|
connections.map(
|
|
11795
|
-
(conn) => this.kb.graph.getResource(
|
|
11801
|
+
(conn) => this.kb.graph.getResource(resourceId2(conn.resourceId)).catch(() => null)
|
|
11796
11802
|
)
|
|
11797
11803
|
);
|
|
11798
11804
|
const candidateMap = /* @__PURE__ */ new Map();
|
|
@@ -11814,7 +11820,7 @@ var Matcher = class {
|
|
|
11814
11820
|
const semanticScores = /* @__PURE__ */ new Map();
|
|
11815
11821
|
for (const sm of semanticMatches) {
|
|
11816
11822
|
semanticScores.set(sm.resourceId, sm.score);
|
|
11817
|
-
const resource = await this.kb.graph.getResource(
|
|
11823
|
+
const resource = await this.kb.graph.getResource(resourceId2(sm.resourceId)).catch(() => null);
|
|
11818
11824
|
if (resource) addCandidate(resource, "semantic");
|
|
11819
11825
|
}
|
|
11820
11826
|
this.logger.debug("Candidate retrieval", {
|
|
@@ -12029,9 +12035,8 @@ No explanations.`;
|
|
|
12029
12035
|
var import_rxjs5 = __toESM(require_cjs(), 1);
|
|
12030
12036
|
var import_operators5 = __toESM(require_operators(), 1);
|
|
12031
12037
|
import { promises as fs } from "fs";
|
|
12032
|
-
import { resourceId as
|
|
12038
|
+
import { resourceId as resourceId3, userId as makeUserId, annotationId as makeAnnotationId4, CREATION_METHODS, generateUuid } from "@semiont/core";
|
|
12033
12039
|
import { resolveStorageUri } from "@semiont/event-sourcing";
|
|
12034
|
-
import { getExtensionForMimeType } from "@semiont/content";
|
|
12035
12040
|
var Stower = class {
|
|
12036
12041
|
constructor(kb, eventBus, logger) {
|
|
12037
12042
|
this.kb = kb;
|
|
@@ -12058,8 +12063,8 @@ var Stower = class {
|
|
|
12058
12063
|
pipe("job:report-progress", (e) => this.handleJobReportProgress(e)),
|
|
12059
12064
|
pipe("job:complete", (e) => this.handleJobComplete(e)),
|
|
12060
12065
|
pipe("job:fail", (e) => this.handleJobFail(e)),
|
|
12061
|
-
pipe("embedding:
|
|
12062
|
-
pipe("embedding:
|
|
12066
|
+
pipe("embedding:compute", (e) => this.handleEmbeddingComputed(e)),
|
|
12067
|
+
pipe("embedding:delete", (e) => this.handleEmbeddingDeleted(e))
|
|
12063
12068
|
).subscribe({
|
|
12064
12069
|
error: (err) => this.logger.error("Stower pipeline error", { error: err })
|
|
12065
12070
|
});
|
|
@@ -12069,40 +12074,29 @@ var Stower = class {
|
|
|
12069
12074
|
// ========================================================================
|
|
12070
12075
|
async handleYieldCreate(event) {
|
|
12071
12076
|
try {
|
|
12072
|
-
const rId =
|
|
12073
|
-
|
|
12074
|
-
|
|
12075
|
-
const
|
|
12076
|
-
if (event.content !== void 0) {
|
|
12077
|
-
const stored = await this.kb.content.store(event.content, resolvedStorageUri, { noGit: event.noGit });
|
|
12078
|
-
checksum = stored.checksum;
|
|
12079
|
-
byteSize = stored.byteSize;
|
|
12080
|
-
} else {
|
|
12081
|
-
if (!event.storageUri) {
|
|
12082
|
-
throw new Error("yield:create without content requires storageUri");
|
|
12083
|
-
}
|
|
12084
|
-
const stored = await this.kb.content.register(resolvedStorageUri, event.contentChecksum, { noGit: event.noGit });
|
|
12085
|
-
checksum = stored.checksum;
|
|
12086
|
-
byteSize = stored.byteSize;
|
|
12087
|
-
}
|
|
12077
|
+
const rId = resourceId3(generateUuid());
|
|
12078
|
+
const stored = await this.kb.content.register(event.storageUri, event.contentChecksum, { noGit: event.noGit });
|
|
12079
|
+
const checksum = stored.checksum;
|
|
12080
|
+
const byteSize = event.byteSize;
|
|
12088
12081
|
const validCreationMethods = Object.values(CREATION_METHODS);
|
|
12089
12082
|
const validatedCreationMethod = event.creationMethod && validCreationMethods.includes(event.creationMethod) ? event.creationMethod : CREATION_METHODS.API;
|
|
12083
|
+
const generatedFrom = event.generatedFrom?.resourceId && event.generatedFrom?.annotationId ? { resourceId: event.generatedFrom.resourceId, annotationId: event.generatedFrom.annotationId } : void 0;
|
|
12090
12084
|
await this.kb.eventStore.appendEvent({
|
|
12091
|
-
type: "
|
|
12085
|
+
type: "yield:created",
|
|
12092
12086
|
resourceId: rId,
|
|
12093
|
-
userId: event.userId,
|
|
12087
|
+
userId: makeUserId(event.userId),
|
|
12094
12088
|
version: 1,
|
|
12095
12089
|
payload: {
|
|
12096
12090
|
name: event.name,
|
|
12097
12091
|
format: event.format,
|
|
12098
12092
|
contentChecksum: checksum,
|
|
12099
12093
|
contentByteSize: byteSize,
|
|
12100
|
-
storageUri:
|
|
12094
|
+
storageUri: event.storageUri,
|
|
12101
12095
|
creationMethod: validatedCreationMethod,
|
|
12102
12096
|
entityTypes: event.entityTypes || [],
|
|
12103
12097
|
language: event.language || void 0,
|
|
12104
12098
|
isDraft: event.isDraft ?? false,
|
|
12105
|
-
generatedFrom
|
|
12099
|
+
generatedFrom,
|
|
12106
12100
|
generationPrompt: event.generationPrompt,
|
|
12107
12101
|
generator: event.generator
|
|
12108
12102
|
}
|
|
@@ -12127,40 +12121,33 @@ var Stower = class {
|
|
|
12127
12121
|
}
|
|
12128
12122
|
]
|
|
12129
12123
|
};
|
|
12130
|
-
this.eventBus.get("yield:
|
|
12124
|
+
this.eventBus.get("yield:create-ok").next({ resourceId: rId, resource });
|
|
12131
12125
|
} catch (error) {
|
|
12132
12126
|
this.logger.error("Failed to create resource", { error });
|
|
12133
12127
|
this.eventBus.get("yield:create-failed").next({
|
|
12134
|
-
|
|
12128
|
+
message: error instanceof Error ? error.message : String(error)
|
|
12135
12129
|
});
|
|
12136
12130
|
}
|
|
12137
12131
|
}
|
|
12138
12132
|
async handleYieldUpdate(event) {
|
|
12139
12133
|
try {
|
|
12140
|
-
|
|
12141
|
-
if (event.content) {
|
|
12142
|
-
const stored = await this.kb.content.store(event.content, event.storageUri, { noGit: event.noGit });
|
|
12143
|
-
byteSize = stored.byteSize;
|
|
12144
|
-
} else {
|
|
12145
|
-
const stored = await this.kb.content.register(event.storageUri, event.contentChecksum, { noGit: event.noGit });
|
|
12146
|
-
byteSize = stored.byteSize;
|
|
12147
|
-
}
|
|
12134
|
+
await this.kb.content.register(event.storageUri, event.contentChecksum, { noGit: event.noGit });
|
|
12148
12135
|
await this.kb.eventStore.appendEvent({
|
|
12149
|
-
type: "
|
|
12150
|
-
resourceId: event.resourceId,
|
|
12151
|
-
userId: event.userId,
|
|
12136
|
+
type: "yield:updated",
|
|
12137
|
+
resourceId: resourceId3(event.resourceId),
|
|
12138
|
+
userId: makeUserId(event.userId),
|
|
12152
12139
|
version: 1,
|
|
12153
12140
|
payload: {
|
|
12154
12141
|
contentChecksum: event.contentChecksum,
|
|
12155
|
-
contentByteSize: byteSize
|
|
12142
|
+
contentByteSize: event.byteSize
|
|
12156
12143
|
}
|
|
12157
12144
|
});
|
|
12158
|
-
this.eventBus.get("yield:
|
|
12145
|
+
this.eventBus.get("yield:update-ok").next({ resourceId: event.resourceId });
|
|
12159
12146
|
} catch (error) {
|
|
12160
12147
|
this.logger.error("Failed to update resource", { error });
|
|
12161
12148
|
this.eventBus.get("yield:update-failed").next({
|
|
12162
12149
|
resourceId: event.resourceId,
|
|
12163
|
-
|
|
12150
|
+
message: error instanceof Error ? error.message : String(error)
|
|
12164
12151
|
});
|
|
12165
12152
|
}
|
|
12166
12153
|
}
|
|
@@ -12173,28 +12160,28 @@ var Stower = class {
|
|
|
12173
12160
|
this.logger.error("Failed to resolve resource for move", { fromUri: event.fromUri, error });
|
|
12174
12161
|
this.eventBus.get("yield:move-failed").next({
|
|
12175
12162
|
fromUri: event.fromUri,
|
|
12176
|
-
|
|
12163
|
+
message: error instanceof Error ? error.message : String(error)
|
|
12177
12164
|
});
|
|
12178
12165
|
return;
|
|
12179
12166
|
}
|
|
12180
12167
|
try {
|
|
12181
12168
|
await this.kb.content.move(event.fromUri, event.toUri, { noGit: event.noGit });
|
|
12182
12169
|
await this.kb.eventStore.appendEvent({
|
|
12183
|
-
type: "
|
|
12170
|
+
type: "yield:moved",
|
|
12184
12171
|
resourceId: rId,
|
|
12185
|
-
userId: event.userId,
|
|
12172
|
+
userId: makeUserId(event.userId),
|
|
12186
12173
|
version: 1,
|
|
12187
12174
|
payload: {
|
|
12188
12175
|
fromUri: event.fromUri,
|
|
12189
12176
|
toUri: event.toUri
|
|
12190
12177
|
}
|
|
12191
12178
|
});
|
|
12192
|
-
this.eventBus.get("yield:
|
|
12179
|
+
this.eventBus.get("yield:move-ok").next({ resourceId: rId });
|
|
12193
12180
|
} catch (error) {
|
|
12194
12181
|
this.logger.error("Failed to move resource", { error });
|
|
12195
12182
|
this.eventBus.get("yield:move-failed").next({
|
|
12196
12183
|
fromUri: event.fromUri,
|
|
12197
|
-
|
|
12184
|
+
message: error instanceof Error ? error.message : String(error)
|
|
12198
12185
|
});
|
|
12199
12186
|
}
|
|
12200
12187
|
}
|
|
@@ -12202,17 +12189,17 @@ var Stower = class {
|
|
|
12202
12189
|
try {
|
|
12203
12190
|
this.logger.debug("Stowing annotation", { annotationId: event.annotation.id });
|
|
12204
12191
|
await this.kb.eventStore.appendEvent({
|
|
12205
|
-
type: "
|
|
12206
|
-
resourceId: event.resourceId,
|
|
12207
|
-
userId: event.userId,
|
|
12192
|
+
type: "mark:added",
|
|
12193
|
+
resourceId: resourceId3(event.resourceId),
|
|
12194
|
+
userId: makeUserId(event.userId),
|
|
12208
12195
|
version: 1,
|
|
12209
12196
|
payload: { annotation: event.annotation }
|
|
12210
12197
|
});
|
|
12211
|
-
this.eventBus.get("mark:
|
|
12198
|
+
this.eventBus.get("mark:create-ok").next({ annotationId: makeAnnotationId4(event.annotation.id) });
|
|
12212
12199
|
} catch (error) {
|
|
12213
12200
|
this.logger.error("Failed to create annotation", { error });
|
|
12214
12201
|
this.eventBus.get("mark:create-failed").next({
|
|
12215
|
-
|
|
12202
|
+
message: error instanceof Error ? error.message : String(error)
|
|
12216
12203
|
});
|
|
12217
12204
|
}
|
|
12218
12205
|
}
|
|
@@ -12222,54 +12209,60 @@ var Stower = class {
|
|
|
12222
12209
|
}
|
|
12223
12210
|
try {
|
|
12224
12211
|
await this.kb.eventStore.appendEvent({
|
|
12225
|
-
type: "
|
|
12226
|
-
resourceId: event.resourceId,
|
|
12227
|
-
userId: event.userId,
|
|
12212
|
+
type: "mark:removed",
|
|
12213
|
+
resourceId: resourceId3(event.resourceId),
|
|
12214
|
+
userId: makeUserId(event.userId),
|
|
12228
12215
|
version: 1,
|
|
12229
12216
|
payload: { annotationId: event.annotationId }
|
|
12230
12217
|
});
|
|
12231
|
-
this.eventBus.get("mark:
|
|
12218
|
+
this.eventBus.get("mark:delete-ok").next({ annotationId: event.annotationId });
|
|
12232
12219
|
} catch (error) {
|
|
12233
12220
|
this.logger.error("Failed to delete annotation", { error });
|
|
12234
12221
|
this.eventBus.get("mark:delete-failed").next({
|
|
12235
|
-
|
|
12222
|
+
message: error instanceof Error ? error.message : String(error)
|
|
12236
12223
|
});
|
|
12237
12224
|
}
|
|
12238
12225
|
}
|
|
12239
12226
|
async handleMarkUpdateBody(event) {
|
|
12240
12227
|
try {
|
|
12241
|
-
|
|
12242
|
-
|
|
12243
|
-
|
|
12244
|
-
|
|
12245
|
-
|
|
12246
|
-
|
|
12247
|
-
|
|
12248
|
-
|
|
12228
|
+
await this.kb.eventStore.appendEvent(
|
|
12229
|
+
{
|
|
12230
|
+
type: "mark:body-updated",
|
|
12231
|
+
resourceId: resourceId3(event.resourceId),
|
|
12232
|
+
userId: makeUserId(event.userId),
|
|
12233
|
+
version: 1,
|
|
12234
|
+
payload: { annotationId: event.annotationId, operations: event.operations }
|
|
12235
|
+
},
|
|
12236
|
+
// Thread correlationId from the command into event metadata so the
|
|
12237
|
+
// events-stream can deliver it to the client that initiated the bind.
|
|
12238
|
+
event.correlationId ? { correlationId: event.correlationId } : void 0
|
|
12239
|
+
);
|
|
12249
12240
|
} catch (error) {
|
|
12250
12241
|
this.logger.error("Failed to update annotation body", { error });
|
|
12251
12242
|
this.eventBus.get("mark:body-update-failed").next({
|
|
12252
|
-
|
|
12243
|
+
message: error instanceof Error ? error.message : String(error)
|
|
12253
12244
|
});
|
|
12254
12245
|
}
|
|
12255
12246
|
}
|
|
12256
12247
|
async handleMarkArchive(event) {
|
|
12257
|
-
if (!event
|
|
12248
|
+
if (!event.userId) {
|
|
12249
|
+
this.logger.warn("mark:archive missing userId \u2014 skipping (frontend-only event?)");
|
|
12258
12250
|
return;
|
|
12259
12251
|
}
|
|
12260
12252
|
if (event.storageUri) {
|
|
12261
12253
|
await this.kb.content.remove(event.storageUri, { keepFile: event.keepFile, noGit: event.noGit });
|
|
12262
12254
|
}
|
|
12263
12255
|
await this.kb.eventStore.appendEvent({
|
|
12264
|
-
type: "
|
|
12265
|
-
resourceId: event.resourceId,
|
|
12266
|
-
userId: event.userId,
|
|
12256
|
+
type: "mark:archived",
|
|
12257
|
+
resourceId: resourceId3(event.resourceId),
|
|
12258
|
+
userId: makeUserId(event.userId),
|
|
12267
12259
|
version: 1,
|
|
12268
12260
|
payload: { reason: void 0 }
|
|
12269
12261
|
});
|
|
12270
12262
|
}
|
|
12271
12263
|
async handleMarkUnarchive(event) {
|
|
12272
|
-
if (!event
|
|
12264
|
+
if (!event.userId) {
|
|
12265
|
+
this.logger.warn("mark:unarchive missing userId \u2014 skipping (frontend-only event?)");
|
|
12273
12266
|
return;
|
|
12274
12267
|
}
|
|
12275
12268
|
if (event.storageUri) {
|
|
@@ -12282,9 +12275,9 @@ var Stower = class {
|
|
|
12282
12275
|
}
|
|
12283
12276
|
}
|
|
12284
12277
|
await this.kb.eventStore.appendEvent({
|
|
12285
|
-
type: "
|
|
12286
|
-
resourceId: event.resourceId,
|
|
12287
|
-
userId: event.userId,
|
|
12278
|
+
type: "mark:unarchived",
|
|
12279
|
+
resourceId: resourceId3(event.resourceId),
|
|
12280
|
+
userId: makeUserId(event.userId),
|
|
12288
12281
|
version: 1,
|
|
12289
12282
|
payload: {}
|
|
12290
12283
|
});
|
|
@@ -12292,16 +12285,15 @@ var Stower = class {
|
|
|
12292
12285
|
async handleAddEntityType(event) {
|
|
12293
12286
|
try {
|
|
12294
12287
|
await this.kb.eventStore.appendEvent({
|
|
12295
|
-
type: "
|
|
12296
|
-
userId: event.userId,
|
|
12288
|
+
type: "mark:entity-type-added",
|
|
12289
|
+
userId: makeUserId(event.userId),
|
|
12297
12290
|
version: 1,
|
|
12298
12291
|
payload: { entityType: event.tag }
|
|
12299
12292
|
});
|
|
12300
|
-
this.eventBus.get("mark:entity-type-added").next({ tag: event.tag });
|
|
12301
12293
|
} catch (error) {
|
|
12302
12294
|
this.logger.error("Failed to add entity type", { error });
|
|
12303
12295
|
this.eventBus.get("mark:entity-type-add-failed").next({
|
|
12304
|
-
|
|
12296
|
+
message: error instanceof Error ? error.message : String(error)
|
|
12305
12297
|
});
|
|
12306
12298
|
}
|
|
12307
12299
|
}
|
|
@@ -12310,18 +12302,18 @@ var Stower = class {
|
|
|
12310
12302
|
const removed = event.currentEntityTypes.filter((et) => !event.updatedEntityTypes.includes(et));
|
|
12311
12303
|
for (const entityType of added) {
|
|
12312
12304
|
await this.kb.eventStore.appendEvent({
|
|
12313
|
-
type: "
|
|
12314
|
-
resourceId: event.resourceId,
|
|
12315
|
-
userId: event.userId,
|
|
12305
|
+
type: "mark:entity-tag-added",
|
|
12306
|
+
resourceId: resourceId3(event.resourceId),
|
|
12307
|
+
userId: makeUserId(event.userId),
|
|
12316
12308
|
version: 1,
|
|
12317
12309
|
payload: { entityType }
|
|
12318
12310
|
});
|
|
12319
12311
|
}
|
|
12320
12312
|
for (const entityType of removed) {
|
|
12321
12313
|
await this.kb.eventStore.appendEvent({
|
|
12322
|
-
type: "
|
|
12323
|
-
resourceId: event.resourceId,
|
|
12324
|
-
userId: event.userId,
|
|
12314
|
+
type: "mark:entity-tag-removed",
|
|
12315
|
+
resourceId: resourceId3(event.resourceId),
|
|
12316
|
+
userId: makeUserId(event.userId),
|
|
12325
12317
|
version: 1,
|
|
12326
12318
|
payload: { entityType }
|
|
12327
12319
|
});
|
|
@@ -12329,18 +12321,18 @@ var Stower = class {
|
|
|
12329
12321
|
}
|
|
12330
12322
|
async handleJobStart(event) {
|
|
12331
12323
|
await this.kb.eventStore.appendEvent({
|
|
12332
|
-
type: "job
|
|
12333
|
-
resourceId: event.resourceId,
|
|
12334
|
-
userId: event.userId,
|
|
12324
|
+
type: "job:started",
|
|
12325
|
+
resourceId: resourceId3(event.resourceId),
|
|
12326
|
+
userId: makeUserId(event.userId),
|
|
12335
12327
|
version: 1,
|
|
12336
12328
|
payload: { jobId: event.jobId, jobType: event.jobType }
|
|
12337
12329
|
});
|
|
12338
12330
|
}
|
|
12339
12331
|
async handleJobReportProgress(event) {
|
|
12340
12332
|
await this.kb.eventStore.appendEvent({
|
|
12341
|
-
type: "job
|
|
12342
|
-
resourceId: event.resourceId,
|
|
12343
|
-
userId: event.userId,
|
|
12333
|
+
type: "job:progress",
|
|
12334
|
+
resourceId: resourceId3(event.resourceId),
|
|
12335
|
+
userId: makeUserId(event.userId),
|
|
12344
12336
|
version: 1,
|
|
12345
12337
|
payload: {
|
|
12346
12338
|
jobId: event.jobId,
|
|
@@ -12352,9 +12344,9 @@ var Stower = class {
|
|
|
12352
12344
|
}
|
|
12353
12345
|
async handleJobComplete(event) {
|
|
12354
12346
|
await this.kb.eventStore.appendEvent({
|
|
12355
|
-
type: "job
|
|
12356
|
-
resourceId: event.resourceId,
|
|
12357
|
-
userId: event.userId,
|
|
12347
|
+
type: "job:completed",
|
|
12348
|
+
resourceId: resourceId3(event.resourceId),
|
|
12349
|
+
userId: makeUserId(event.userId),
|
|
12358
12350
|
version: 1,
|
|
12359
12351
|
payload: {
|
|
12360
12352
|
jobId: event.jobId,
|
|
@@ -12365,9 +12357,9 @@ var Stower = class {
|
|
|
12365
12357
|
}
|
|
12366
12358
|
async handleJobFail(event) {
|
|
12367
12359
|
await this.kb.eventStore.appendEvent({
|
|
12368
|
-
type: "job
|
|
12369
|
-
resourceId: event.resourceId,
|
|
12370
|
-
userId: event.userId,
|
|
12360
|
+
type: "job:failed",
|
|
12361
|
+
resourceId: resourceId3(event.resourceId),
|
|
12362
|
+
userId: makeUserId(event.userId),
|
|
12371
12363
|
version: 1,
|
|
12372
12364
|
payload: {
|
|
12373
12365
|
jobId: event.jobId,
|
|
@@ -12378,8 +12370,8 @@ var Stower = class {
|
|
|
12378
12370
|
}
|
|
12379
12371
|
async handleEmbeddingComputed(event) {
|
|
12380
12372
|
await this.kb.eventStore.appendEvent({
|
|
12381
|
-
type: "embedding
|
|
12382
|
-
resourceId: event.resourceId,
|
|
12373
|
+
type: "embedding:computed",
|
|
12374
|
+
resourceId: resourceId3(event.resourceId),
|
|
12383
12375
|
userId: makeUserId("did:web:system:smelter"),
|
|
12384
12376
|
version: 1,
|
|
12385
12377
|
payload: {
|
|
@@ -12394,8 +12386,8 @@ var Stower = class {
|
|
|
12394
12386
|
}
|
|
12395
12387
|
async handleEmbeddingDeleted(event) {
|
|
12396
12388
|
await this.kb.eventStore.appendEvent({
|
|
12397
|
-
type: "embedding
|
|
12398
|
-
resourceId: event.resourceId,
|
|
12389
|
+
type: "embedding:deleted",
|
|
12390
|
+
resourceId: resourceId3(event.resourceId),
|
|
12399
12391
|
userId: makeUserId("did:web:system:smelter"),
|
|
12400
12392
|
version: 1,
|
|
12401
12393
|
payload: {
|
|
@@ -12409,18 +12401,13 @@ var Stower = class {
|
|
|
12409
12401
|
this.logger.info("Stower actor stopped");
|
|
12410
12402
|
}
|
|
12411
12403
|
};
|
|
12412
|
-
function deriveStorageUri(name, format) {
|
|
12413
|
-
const slug = name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
12414
|
-
const ext = getExtensionForMimeType(format);
|
|
12415
|
-
return `file://${slug}${ext}`;
|
|
12416
|
-
}
|
|
12417
12404
|
|
|
12418
12405
|
// src/browser.ts
|
|
12419
12406
|
var import_rxjs6 = __toESM(require_cjs(), 1);
|
|
12420
12407
|
var import_operators6 = __toESM(require_operators(), 1);
|
|
12421
12408
|
import { promises as fs3 } from "fs";
|
|
12422
12409
|
import * as path2 from "path";
|
|
12423
|
-
import { resourceId as
|
|
12410
|
+
import { resourceId as resourceId4, annotationId } from "@semiont/core";
|
|
12424
12411
|
import { getExactText as getExactText2, getTargetSource as getTargetSource2, getTargetSelector as getTargetSelector3, getResourceEntityTypes as getResourceEntityTypes5, getBodySource as getBodySource2 } from "@semiont/api-client";
|
|
12425
12412
|
import { EventQuery as EventQuery3 } from "@semiont/event-sourcing";
|
|
12426
12413
|
import { getEntityTypes as getEntityTypes2 } from "@semiont/ontology";
|
|
@@ -12480,12 +12467,12 @@ var Browser = class {
|
|
|
12480
12467
|
async handleBrowseResource(event) {
|
|
12481
12468
|
try {
|
|
12482
12469
|
const eventQuery = new EventQuery3(this.kb.eventStore.log.storage);
|
|
12483
|
-
const events = await eventQuery.getResourceEvents(event.resourceId);
|
|
12484
|
-
const stored = await this.kb.eventStore.views.materializer.materialize(events, event.resourceId);
|
|
12470
|
+
const events = await eventQuery.getResourceEvents(resourceId4(event.resourceId));
|
|
12471
|
+
const stored = await this.kb.eventStore.views.materializer.materialize(events, resourceId4(event.resourceId));
|
|
12485
12472
|
if (!stored) {
|
|
12486
12473
|
this.eventBus.get("browse:resource-failed").next({
|
|
12487
12474
|
correlationId: event.correlationId,
|
|
12488
|
-
|
|
12475
|
+
message: "Resource not found"
|
|
12489
12476
|
});
|
|
12490
12477
|
return;
|
|
12491
12478
|
}
|
|
@@ -12506,7 +12493,7 @@ var Browser = class {
|
|
|
12506
12493
|
this.logger.error("Browse resource failed", { resourceId: event.resourceId, error });
|
|
12507
12494
|
this.eventBus.get("browse:resource-failed").next({
|
|
12508
12495
|
correlationId: event.correlationId,
|
|
12509
|
-
|
|
12496
|
+
message: error instanceof Error ? error.message : String(error)
|
|
12510
12497
|
});
|
|
12511
12498
|
}
|
|
12512
12499
|
}
|
|
@@ -12536,13 +12523,13 @@ var Browser = class {
|
|
|
12536
12523
|
this.logger.error("Browse resources failed", { error });
|
|
12537
12524
|
this.eventBus.get("browse:resources-failed").next({
|
|
12538
12525
|
correlationId: event.correlationId,
|
|
12539
|
-
|
|
12526
|
+
message: error instanceof Error ? error.message : String(error)
|
|
12540
12527
|
});
|
|
12541
12528
|
}
|
|
12542
12529
|
}
|
|
12543
12530
|
async handleBrowseAnnotations(event) {
|
|
12544
12531
|
try {
|
|
12545
|
-
const annotations = await AnnotationContext.getAllAnnotations(event.resourceId, this.kb);
|
|
12532
|
+
const annotations = await AnnotationContext.getAllAnnotations(resourceId4(event.resourceId), this.kb);
|
|
12546
12533
|
this.eventBus.get("browse:annotations-result").next({
|
|
12547
12534
|
correlationId: event.correlationId,
|
|
12548
12535
|
response: {
|
|
@@ -12554,25 +12541,25 @@ var Browser = class {
|
|
|
12554
12541
|
this.logger.error("Browse annotations failed", { resourceId: event.resourceId, error });
|
|
12555
12542
|
this.eventBus.get("browse:annotations-failed").next({
|
|
12556
12543
|
correlationId: event.correlationId,
|
|
12557
|
-
|
|
12544
|
+
message: error instanceof Error ? error.message : String(error)
|
|
12558
12545
|
});
|
|
12559
12546
|
}
|
|
12560
12547
|
}
|
|
12561
12548
|
async handleBrowseAnnotation(event) {
|
|
12562
12549
|
try {
|
|
12563
|
-
const annotation = await AnnotationContext.getAnnotation(event.annotationId, event.resourceId, this.kb);
|
|
12550
|
+
const annotation = await AnnotationContext.getAnnotation(annotationId(event.annotationId), resourceId4(event.resourceId), this.kb);
|
|
12564
12551
|
if (!annotation) {
|
|
12565
12552
|
this.eventBus.get("browse:annotation-failed").next({
|
|
12566
12553
|
correlationId: event.correlationId,
|
|
12567
|
-
|
|
12554
|
+
message: "Annotation not found"
|
|
12568
12555
|
});
|
|
12569
12556
|
return;
|
|
12570
12557
|
}
|
|
12571
|
-
const resource = await ResourceContext.getResourceMetadata(event.resourceId, this.kb);
|
|
12558
|
+
const resource = await ResourceContext.getResourceMetadata(resourceId4(event.resourceId), this.kb);
|
|
12572
12559
|
let resolvedResource = null;
|
|
12573
12560
|
const bodySource = getBodySource2(annotation.body);
|
|
12574
12561
|
if (bodySource) {
|
|
12575
|
-
resolvedResource = await ResourceContext.getResourceMetadata(
|
|
12562
|
+
resolvedResource = await ResourceContext.getResourceMetadata(resourceId4(bodySource), this.kb);
|
|
12576
12563
|
}
|
|
12577
12564
|
this.eventBus.get("browse:annotation-result").next({
|
|
12578
12565
|
correlationId: event.correlationId,
|
|
@@ -12586,7 +12573,7 @@ var Browser = class {
|
|
|
12586
12573
|
this.logger.error("Browse annotation failed", { resourceId: event.resourceId, annotationId: event.annotationId, error });
|
|
12587
12574
|
this.eventBus.get("browse:annotation-failed").next({
|
|
12588
12575
|
correlationId: event.correlationId,
|
|
12589
|
-
|
|
12576
|
+
message: error instanceof Error ? error.message : String(error)
|
|
12590
12577
|
});
|
|
12591
12578
|
}
|
|
12592
12579
|
}
|
|
@@ -12594,7 +12581,7 @@ var Browser = class {
|
|
|
12594
12581
|
try {
|
|
12595
12582
|
const eventQuery = new EventQuery3(this.kb.eventStore.log.storage);
|
|
12596
12583
|
const filters = {
|
|
12597
|
-
resourceId: event.resourceId
|
|
12584
|
+
resourceId: resourceId4(event.resourceId)
|
|
12598
12585
|
};
|
|
12599
12586
|
if (event.type) {
|
|
12600
12587
|
filters.eventTypes = [event.type];
|
|
@@ -12606,26 +12593,11 @@ var Browser = class {
|
|
|
12606
12593
|
filters.limit = event.limit;
|
|
12607
12594
|
}
|
|
12608
12595
|
const storedEvents = await eventQuery.queryEvents(filters);
|
|
12609
|
-
const events = storedEvents.map((stored) => ({
|
|
12610
|
-
event: {
|
|
12611
|
-
id: stored.event.id,
|
|
12612
|
-
type: stored.event.type,
|
|
12613
|
-
timestamp: stored.event.timestamp,
|
|
12614
|
-
userId: stored.event.userId,
|
|
12615
|
-
resourceId: stored.event.resourceId,
|
|
12616
|
-
payload: stored.event.payload
|
|
12617
|
-
},
|
|
12618
|
-
metadata: {
|
|
12619
|
-
sequenceNumber: stored.metadata.sequenceNumber,
|
|
12620
|
-
prevEventHash: stored.metadata.prevEventHash,
|
|
12621
|
-
checksum: stored.metadata.checksum
|
|
12622
|
-
}
|
|
12623
|
-
}));
|
|
12624
12596
|
this.eventBus.get("browse:events-result").next({
|
|
12625
12597
|
correlationId: event.correlationId,
|
|
12626
12598
|
response: {
|
|
12627
|
-
events,
|
|
12628
|
-
total:
|
|
12599
|
+
events: storedEvents,
|
|
12600
|
+
total: storedEvents.length,
|
|
12629
12601
|
resourceId: event.resourceId
|
|
12630
12602
|
}
|
|
12631
12603
|
});
|
|
@@ -12633,47 +12605,34 @@ var Browser = class {
|
|
|
12633
12605
|
this.logger.error("Browse events failed", { resourceId: event.resourceId, error });
|
|
12634
12606
|
this.eventBus.get("browse:events-failed").next({
|
|
12635
12607
|
correlationId: event.correlationId,
|
|
12636
|
-
|
|
12608
|
+
message: error instanceof Error ? error.message : String(error)
|
|
12637
12609
|
});
|
|
12638
12610
|
}
|
|
12639
12611
|
}
|
|
12640
12612
|
async handleBrowseAnnotationHistory(event) {
|
|
12641
12613
|
try {
|
|
12642
|
-
const annotation = await AnnotationContext.getAnnotation(event.annotationId, event.resourceId, this.kb);
|
|
12614
|
+
const annotation = await AnnotationContext.getAnnotation(annotationId(event.annotationId), resourceId4(event.resourceId), this.kb);
|
|
12643
12615
|
if (!annotation) {
|
|
12644
12616
|
this.eventBus.get("browse:annotation-history-failed").next({
|
|
12645
12617
|
correlationId: event.correlationId,
|
|
12646
|
-
|
|
12618
|
+
message: "Annotation not found"
|
|
12647
12619
|
});
|
|
12648
12620
|
return;
|
|
12649
12621
|
}
|
|
12650
12622
|
const eventQuery = new EventQuery3(this.kb.eventStore.log.storage);
|
|
12651
|
-
const allEvents = await eventQuery.queryEvents({ resourceId: event.resourceId });
|
|
12623
|
+
const allEvents = await eventQuery.queryEvents({ resourceId: resourceId4(event.resourceId) });
|
|
12652
12624
|
const annotationEvents = allEvents.filter((stored) => {
|
|
12653
|
-
const
|
|
12654
|
-
if (
|
|
12655
|
-
if (
|
|
12625
|
+
const p = stored.payload;
|
|
12626
|
+
if (p?.highlightId === event.annotationId) return true;
|
|
12627
|
+
if (p?.referenceId === event.annotationId) return true;
|
|
12656
12628
|
return false;
|
|
12657
12629
|
});
|
|
12658
|
-
|
|
12659
|
-
id: stored.event.id,
|
|
12660
|
-
type: stored.event.type,
|
|
12661
|
-
timestamp: stored.event.timestamp,
|
|
12662
|
-
userId: stored.event.userId,
|
|
12663
|
-
resourceId: stored.event.resourceId,
|
|
12664
|
-
payload: stored.event.payload,
|
|
12665
|
-
metadata: {
|
|
12666
|
-
sequenceNumber: stored.metadata.sequenceNumber,
|
|
12667
|
-
prevEventHash: stored.metadata.prevEventHash,
|
|
12668
|
-
checksum: stored.metadata.checksum
|
|
12669
|
-
}
|
|
12670
|
-
}));
|
|
12671
|
-
events.sort((a, b) => a.metadata.sequenceNumber - b.metadata.sequenceNumber);
|
|
12630
|
+
annotationEvents.sort((a, b) => a.metadata.sequenceNumber - b.metadata.sequenceNumber);
|
|
12672
12631
|
this.eventBus.get("browse:annotation-history-result").next({
|
|
12673
12632
|
correlationId: event.correlationId,
|
|
12674
12633
|
response: {
|
|
12675
|
-
events,
|
|
12676
|
-
total:
|
|
12634
|
+
events: annotationEvents,
|
|
12635
|
+
total: annotationEvents.length,
|
|
12677
12636
|
annotationId: event.annotationId,
|
|
12678
12637
|
resourceId: event.resourceId
|
|
12679
12638
|
}
|
|
@@ -12682,7 +12641,7 @@ var Browser = class {
|
|
|
12682
12641
|
this.logger.error("Browse annotation history failed", { resourceId: event.resourceId, annotationId: event.annotationId, error });
|
|
12683
12642
|
this.eventBus.get("browse:annotation-history-failed").next({
|
|
12684
12643
|
correlationId: event.correlationId,
|
|
12685
|
-
|
|
12644
|
+
message: error instanceof Error ? error.message : String(error)
|
|
12686
12645
|
});
|
|
12687
12646
|
}
|
|
12688
12647
|
}
|
|
@@ -12692,9 +12651,9 @@ var Browser = class {
|
|
|
12692
12651
|
resourceId: event.resourceId,
|
|
12693
12652
|
motivation: event.motivation || "all"
|
|
12694
12653
|
});
|
|
12695
|
-
const references = await this.kb.graph.getResourceReferencedBy(event.resourceId, event.motivation);
|
|
12654
|
+
const references = await this.kb.graph.getResourceReferencedBy(resourceId4(event.resourceId), event.motivation);
|
|
12696
12655
|
const sourceIds = [...new Set(references.map((ref) => getTargetSource2(ref.target)))];
|
|
12697
|
-
const resources = await Promise.all(sourceIds.map((id) => this.kb.graph.getResource(
|
|
12656
|
+
const resources = await Promise.all(sourceIds.map((id) => this.kb.graph.getResource(resourceId4(id))));
|
|
12698
12657
|
for (let i = 0; i < sourceIds.length; i++) {
|
|
12699
12658
|
if (resources[i] === null) {
|
|
12700
12659
|
this.logger.warn("Referenced resource not found in graph", { resourceId: sourceIds[i] });
|
|
@@ -12724,7 +12683,7 @@ var Browser = class {
|
|
|
12724
12683
|
this.logger.error("Referenced-by query failed", { resourceId: event.resourceId, error });
|
|
12725
12684
|
this.eventBus.get("browse:referenced-by-failed").next({
|
|
12726
12685
|
correlationId: event.correlationId,
|
|
12727
|
-
|
|
12686
|
+
message: error instanceof Error ? error.message : String(error)
|
|
12728
12687
|
});
|
|
12729
12688
|
}
|
|
12730
12689
|
}
|
|
@@ -12739,7 +12698,7 @@ var Browser = class {
|
|
|
12739
12698
|
this.logger.error("Entity types read failed", { error });
|
|
12740
12699
|
this.eventBus.get("browse:entity-types-failed").next({
|
|
12741
12700
|
correlationId: event.correlationId,
|
|
12742
|
-
|
|
12701
|
+
message: error instanceof Error ? error.message : String(error)
|
|
12743
12702
|
});
|
|
12744
12703
|
}
|
|
12745
12704
|
}
|
|
@@ -12754,7 +12713,7 @@ var Browser = class {
|
|
|
12754
12713
|
this.eventBus.get("browse:directory-failed").next({
|
|
12755
12714
|
correlationId,
|
|
12756
12715
|
path: reqPath,
|
|
12757
|
-
|
|
12716
|
+
message: "path escapes project root"
|
|
12758
12717
|
});
|
|
12759
12718
|
return;
|
|
12760
12719
|
}
|
|
@@ -12766,7 +12725,7 @@ var Browser = class {
|
|
|
12766
12725
|
this.eventBus.get("browse:directory-failed").next({
|
|
12767
12726
|
correlationId,
|
|
12768
12727
|
path: reqPath,
|
|
12769
|
-
|
|
12728
|
+
message: msg
|
|
12770
12729
|
});
|
|
12771
12730
|
return;
|
|
12772
12731
|
}
|
|
@@ -12851,25 +12810,27 @@ var Browser = class {
|
|
|
12851
12810
|
// src/clone-token-manager.ts
|
|
12852
12811
|
var import_rxjs8 = __toESM(require_cjs(), 1);
|
|
12853
12812
|
var import_operators8 = __toESM(require_operators(), 1);
|
|
12854
|
-
import { CREATION_METHODS as CREATION_METHODS2, cloneToken as makeCloneToken } from "@semiont/core";
|
|
12813
|
+
import { CREATION_METHODS as CREATION_METHODS2, cloneToken as makeCloneToken, resourceId as resourceId5, userId as makeUserId2 } from "@semiont/core";
|
|
12855
12814
|
import { getPrimaryRepresentation as getPrimaryRepresentation3, getResourceEntityTypes as getResourceEntityTypes6 } from "@semiont/api-client";
|
|
12815
|
+
import { deriveStorageUri } from "@semiont/content";
|
|
12856
12816
|
|
|
12857
12817
|
// src/resource-operations.ts
|
|
12858
12818
|
var import_rxjs7 = __toESM(require_cjs(), 1);
|
|
12859
12819
|
var import_operators7 = __toESM(require_operators(), 1);
|
|
12820
|
+
import { resourceId as makeResourceId4 } from "@semiont/core";
|
|
12860
12821
|
var ResourceOperations = class {
|
|
12861
12822
|
/**
|
|
12862
12823
|
* Create a new resource via EventBus → Stower
|
|
12863
12824
|
*/
|
|
12864
12825
|
static async createResource(input, userId2, eventBus) {
|
|
12865
12826
|
const result$ = (0, import_rxjs7.race)(
|
|
12866
|
-
eventBus.get("yield:
|
|
12827
|
+
eventBus.get("yield:create-ok").pipe(
|
|
12867
12828
|
(0, import_operators7.take)(1),
|
|
12868
12829
|
(0, import_operators7.map)((result) => ({ ok: true, result }))
|
|
12869
12830
|
),
|
|
12870
12831
|
eventBus.get("yield:create-failed").pipe(
|
|
12871
12832
|
(0, import_operators7.take)(1),
|
|
12872
|
-
(0, import_operators7.map)((failure) => ({ ok: false, error: failure.
|
|
12833
|
+
(0, import_operators7.map)((failure) => ({ ok: false, error: new Error(failure.message) }))
|
|
12873
12834
|
),
|
|
12874
12835
|
(0, import_rxjs7.timer)(3e4).pipe(
|
|
12875
12836
|
(0, import_operators7.map)(() => ({ ok: false, error: new Error("Resource creation timed out") }))
|
|
@@ -12877,19 +12838,20 @@ var ResourceOperations = class {
|
|
|
12877
12838
|
);
|
|
12878
12839
|
eventBus.get("yield:create").next({
|
|
12879
12840
|
name: input.name,
|
|
12880
|
-
|
|
12841
|
+
storageUri: input.storageUri,
|
|
12842
|
+
contentChecksum: input.contentChecksum,
|
|
12843
|
+
byteSize: input.byteSize,
|
|
12881
12844
|
format: input.format,
|
|
12882
12845
|
userId: userId2,
|
|
12883
12846
|
language: input.language,
|
|
12884
12847
|
entityTypes: input.entityTypes,
|
|
12885
|
-
creationMethod: input.creationMethod
|
|
12886
|
-
storageUri: input.storageUri
|
|
12848
|
+
creationMethod: input.creationMethod
|
|
12887
12849
|
});
|
|
12888
12850
|
const outcome = await (0, import_rxjs7.firstValueFrom)(result$);
|
|
12889
12851
|
if (!outcome.ok) {
|
|
12890
12852
|
throw outcome.error;
|
|
12891
12853
|
}
|
|
12892
|
-
return outcome.result.resourceId;
|
|
12854
|
+
return makeResourceId4(outcome.result.resourceId);
|
|
12893
12855
|
}
|
|
12894
12856
|
/**
|
|
12895
12857
|
* Update resource metadata via EventBus → Stower
|
|
@@ -12943,18 +12905,18 @@ var CloneTokenManager = class {
|
|
|
12943
12905
|
}
|
|
12944
12906
|
async handleGenerateToken(event) {
|
|
12945
12907
|
try {
|
|
12946
|
-
const resource = await ResourceContext.getResourceMetadata(event.resourceId, this.kb);
|
|
12908
|
+
const resource = await ResourceContext.getResourceMetadata(resourceId5(event.resourceId), this.kb);
|
|
12947
12909
|
if (!resource) {
|
|
12948
12910
|
this.eventBus.get("yield:clone-token-failed").next({
|
|
12949
12911
|
correlationId: event.correlationId,
|
|
12950
|
-
|
|
12912
|
+
message: "Resource not found"
|
|
12951
12913
|
});
|
|
12952
12914
|
return;
|
|
12953
12915
|
}
|
|
12954
12916
|
if (!resource.storageUri) {
|
|
12955
12917
|
this.eventBus.get("yield:clone-token-failed").next({
|
|
12956
12918
|
correlationId: event.correlationId,
|
|
12957
|
-
|
|
12919
|
+
message: "Resource content not found"
|
|
12958
12920
|
});
|
|
12959
12921
|
return;
|
|
12960
12922
|
}
|
|
@@ -12963,14 +12925,14 @@ var CloneTokenManager = class {
|
|
|
12963
12925
|
} catch {
|
|
12964
12926
|
this.eventBus.get("yield:clone-token-failed").next({
|
|
12965
12927
|
correlationId: event.correlationId,
|
|
12966
|
-
|
|
12928
|
+
message: "Resource content not found"
|
|
12967
12929
|
});
|
|
12968
12930
|
return;
|
|
12969
12931
|
}
|
|
12970
12932
|
const tokenStr = `clone_${Math.random().toString(36).substring(2, 11)}_${Date.now()}`;
|
|
12971
12933
|
const token = makeCloneToken(tokenStr);
|
|
12972
12934
|
const expiresAt = new Date(Date.now() + 15 * 60 * 1e3);
|
|
12973
|
-
this.tokens.set(token, { resourceId: event.resourceId, expiresAt });
|
|
12935
|
+
this.tokens.set(token, { resourceId: resourceId5(event.resourceId), expiresAt });
|
|
12974
12936
|
this.eventBus.get("yield:clone-token-generated").next({
|
|
12975
12937
|
correlationId: event.correlationId,
|
|
12976
12938
|
response: {
|
|
@@ -12983,7 +12945,7 @@ var CloneTokenManager = class {
|
|
|
12983
12945
|
this.logger.error("Generate clone token failed", { resourceId: event.resourceId, error });
|
|
12984
12946
|
this.eventBus.get("yield:clone-token-failed").next({
|
|
12985
12947
|
correlationId: event.correlationId,
|
|
12986
|
-
|
|
12948
|
+
message: error instanceof Error ? error.message : String(error)
|
|
12987
12949
|
});
|
|
12988
12950
|
}
|
|
12989
12951
|
}
|
|
@@ -12994,7 +12956,7 @@ var CloneTokenManager = class {
|
|
|
12994
12956
|
if (!tokenData) {
|
|
12995
12957
|
this.eventBus.get("yield:clone-resource-failed").next({
|
|
12996
12958
|
correlationId: event.correlationId,
|
|
12997
|
-
|
|
12959
|
+
message: "Invalid or expired token"
|
|
12998
12960
|
});
|
|
12999
12961
|
return;
|
|
13000
12962
|
}
|
|
@@ -13002,7 +12964,7 @@ var CloneTokenManager = class {
|
|
|
13002
12964
|
this.tokens.delete(token);
|
|
13003
12965
|
this.eventBus.get("yield:clone-resource-failed").next({
|
|
13004
12966
|
correlationId: event.correlationId,
|
|
13005
|
-
|
|
12967
|
+
message: "Token expired"
|
|
13006
12968
|
});
|
|
13007
12969
|
return;
|
|
13008
12970
|
}
|
|
@@ -13010,7 +12972,7 @@ var CloneTokenManager = class {
|
|
|
13010
12972
|
if (!sourceResource) {
|
|
13011
12973
|
this.eventBus.get("yield:clone-resource-failed").next({
|
|
13012
12974
|
correlationId: event.correlationId,
|
|
13013
|
-
|
|
12975
|
+
message: "Source resource not found"
|
|
13014
12976
|
});
|
|
13015
12977
|
return;
|
|
13016
12978
|
}
|
|
@@ -13025,7 +12987,7 @@ var CloneTokenManager = class {
|
|
|
13025
12987
|
this.logger.error("Get clone resource failed", { token: event.token, error });
|
|
13026
12988
|
this.eventBus.get("yield:clone-resource-failed").next({
|
|
13027
12989
|
correlationId: event.correlationId,
|
|
13028
|
-
|
|
12990
|
+
message: error instanceof Error ? error.message : String(error)
|
|
13029
12991
|
});
|
|
13030
12992
|
}
|
|
13031
12993
|
}
|
|
@@ -13036,7 +12998,7 @@ var CloneTokenManager = class {
|
|
|
13036
12998
|
if (!tokenData) {
|
|
13037
12999
|
this.eventBus.get("yield:clone-create-failed").next({
|
|
13038
13000
|
correlationId: event.correlationId,
|
|
13039
|
-
|
|
13001
|
+
message: "Invalid or expired token"
|
|
13040
13002
|
});
|
|
13041
13003
|
return;
|
|
13042
13004
|
}
|
|
@@ -13044,7 +13006,7 @@ var CloneTokenManager = class {
|
|
|
13044
13006
|
this.tokens.delete(token);
|
|
13045
13007
|
this.eventBus.get("yield:clone-create-failed").next({
|
|
13046
13008
|
correlationId: event.correlationId,
|
|
13047
|
-
|
|
13009
|
+
message: "Token expired"
|
|
13048
13010
|
});
|
|
13049
13011
|
return;
|
|
13050
13012
|
}
|
|
@@ -13052,7 +13014,7 @@ var CloneTokenManager = class {
|
|
|
13052
13014
|
if (!sourceDoc) {
|
|
13053
13015
|
this.eventBus.get("yield:clone-create-failed").next({
|
|
13054
13016
|
correlationId: event.correlationId,
|
|
13055
|
-
|
|
13017
|
+
message: "Source resource not found"
|
|
13056
13018
|
});
|
|
13057
13019
|
return;
|
|
13058
13020
|
}
|
|
@@ -13060,22 +13022,26 @@ var CloneTokenManager = class {
|
|
|
13060
13022
|
const mediaType = primaryRep?.mediaType || "text/plain";
|
|
13061
13023
|
const validFormats = ["text/plain", "text/markdown"];
|
|
13062
13024
|
const format = validFormats.includes(mediaType) ? mediaType : "text/plain";
|
|
13063
|
-
const
|
|
13025
|
+
const resolvedUri = deriveStorageUri(event.name, format);
|
|
13026
|
+
const stored = await this.kb.content.store(Buffer.from(event.content), resolvedUri);
|
|
13027
|
+
const newResourceId = await ResourceOperations.createResource(
|
|
13064
13028
|
{
|
|
13065
13029
|
name: event.name,
|
|
13066
|
-
|
|
13030
|
+
storageUri: resolvedUri,
|
|
13031
|
+
contentChecksum: stored.checksum,
|
|
13032
|
+
byteSize: stored.byteSize,
|
|
13067
13033
|
format,
|
|
13068
13034
|
entityTypes: getResourceEntityTypes6(sourceDoc),
|
|
13069
13035
|
creationMethod: CREATION_METHODS2.CLONE
|
|
13070
13036
|
},
|
|
13071
|
-
event.userId,
|
|
13037
|
+
makeUserId2(event.userId),
|
|
13072
13038
|
this.eventBus
|
|
13073
13039
|
);
|
|
13074
13040
|
if (event.archiveOriginal) {
|
|
13075
13041
|
ResourceOperations.updateResource(
|
|
13076
13042
|
{
|
|
13077
13043
|
resourceId: tokenData.resourceId,
|
|
13078
|
-
userId: event.userId,
|
|
13044
|
+
userId: makeUserId2(event.userId),
|
|
13079
13045
|
currentArchived: sourceDoc.archived,
|
|
13080
13046
|
updatedArchived: true
|
|
13081
13047
|
},
|
|
@@ -13085,13 +13051,13 @@ var CloneTokenManager = class {
|
|
|
13085
13051
|
this.tokens.delete(token);
|
|
13086
13052
|
this.eventBus.get("yield:clone-created").next({
|
|
13087
13053
|
correlationId: event.correlationId,
|
|
13088
|
-
response: { resourceId:
|
|
13054
|
+
response: { resourceId: newResourceId }
|
|
13089
13055
|
});
|
|
13090
13056
|
} catch (error) {
|
|
13091
13057
|
this.logger.error("Clone create failed", { token: event.token, error });
|
|
13092
13058
|
this.eventBus.get("yield:clone-create-failed").next({
|
|
13093
13059
|
correlationId: event.correlationId,
|
|
13094
|
-
|
|
13060
|
+
message: error instanceof Error ? error.message : String(error)
|
|
13095
13061
|
});
|
|
13096
13062
|
}
|
|
13097
13063
|
}
|
|
@@ -13108,39 +13074,25 @@ var CloneTokenManager = class {
|
|
|
13108
13074
|
// src/bootstrap/entity-types.ts
|
|
13109
13075
|
var import_rxjs9 = __toESM(require_cjs(), 1);
|
|
13110
13076
|
var import_operators9 = __toESM(require_operators(), 1);
|
|
13111
|
-
import { promises as fs4 } from "fs";
|
|
13112
|
-
import * as path3 from "path";
|
|
13113
13077
|
import { DEFAULT_ENTITY_TYPES } from "@semiont/ontology";
|
|
13114
|
-
import { userId } from "@semiont/core";
|
|
13115
|
-
|
|
13116
|
-
|
|
13117
|
-
|
|
13118
|
-
|
|
13119
|
-
return;
|
|
13120
|
-
}
|
|
13121
|
-
const projectionPath = path3.join(
|
|
13122
|
-
project.stateDir,
|
|
13123
|
-
"projections",
|
|
13124
|
-
"__system__",
|
|
13125
|
-
"entitytypes.json"
|
|
13078
|
+
import { userId, resourceId as resourceId6 } from "@semiont/core";
|
|
13079
|
+
async function bootstrapEntityTypes(eventBus, eventStore, logger) {
|
|
13080
|
+
const systemEvents = await eventStore.log.getEvents(resourceId6("__system__"));
|
|
13081
|
+
const existingTypes = new Set(
|
|
13082
|
+
systemEvents.filter((e) => e.type === "mark:entity-type-added").map((e) => e.payload.entityType)
|
|
13126
13083
|
);
|
|
13127
|
-
|
|
13128
|
-
|
|
13129
|
-
logger?.info("
|
|
13130
|
-
bootstrapCompleted = true;
|
|
13084
|
+
const missing = DEFAULT_ENTITY_TYPES.filter((t) => !existingTypes.has(t));
|
|
13085
|
+
if (missing.length === 0) {
|
|
13086
|
+
logger?.info("All entity types already in event log, skipping bootstrap", { count: existingTypes.size });
|
|
13131
13087
|
return;
|
|
13132
|
-
} catch (error) {
|
|
13133
|
-
if (error.code !== "ENOENT") {
|
|
13134
|
-
throw error;
|
|
13135
|
-
}
|
|
13136
|
-
logger?.info("Entity types projection does not exist, bootstrapping with DEFAULT_ENTITY_TYPES");
|
|
13137
13088
|
}
|
|
13089
|
+
logger?.info("Bootstrapping missing entity types", { missing: missing.length, existing: existingTypes.size });
|
|
13138
13090
|
const SYSTEM_USER_ID = userId("00000000-0000-0000-0000-000000000000");
|
|
13139
|
-
for (const entityType of
|
|
13091
|
+
for (const entityType of missing) {
|
|
13140
13092
|
logger?.debug("Adding entity type via EventBus", { entityType });
|
|
13141
13093
|
const result$ = (0, import_rxjs9.race)(
|
|
13142
13094
|
eventBus.get("mark:entity-type-added").pipe((0, import_operators9.take)(1), (0, import_operators9.map)(() => ({ ok: true }))),
|
|
13143
|
-
eventBus.get("mark:entity-type-add-failed").pipe((0, import_operators9.take)(1), (0, import_operators9.map)((f) => ({ ok: false, error: f.
|
|
13095
|
+
eventBus.get("mark:entity-type-add-failed").pipe((0, import_operators9.take)(1), (0, import_operators9.map)((f) => ({ ok: false, error: new Error(f.message) }))),
|
|
13144
13096
|
(0, import_rxjs9.timer)(1e4).pipe((0, import_operators9.map)(() => ({ ok: false, error: new Error(`Timeout adding entity type: ${entityType}`) })))
|
|
13145
13097
|
);
|
|
13146
13098
|
eventBus.get("mark:add-entity-type").next({ tag: entityType, userId: SYSTEM_USER_ID });
|
|
@@ -13149,11 +13101,7 @@ async function bootstrapEntityTypes(eventBus, project, logger) {
|
|
|
13149
13101
|
throw outcome.error;
|
|
13150
13102
|
}
|
|
13151
13103
|
}
|
|
13152
|
-
logger?.info("Entity types bootstrap completed", {
|
|
13153
|
-
bootstrapCompleted = true;
|
|
13154
|
-
}
|
|
13155
|
-
function resetBootstrap() {
|
|
13156
|
-
bootstrapCompleted = false;
|
|
13104
|
+
logger?.info("Entity types bootstrap completed", { added: missing.length, total: DEFAULT_ENTITY_TYPES.length });
|
|
13157
13105
|
}
|
|
13158
13106
|
|
|
13159
13107
|
// src/knowledge-system.ts
|
|
@@ -13175,9 +13123,9 @@ async function createJobQueue(project, eventBus, logger) {
|
|
|
13175
13123
|
const jobStatusSubscription = eventBus.get("job:status-requested").pipe(
|
|
13176
13124
|
(0, import_operators10.mergeMap)((event) => (0, import_rxjs10.from)((async () => {
|
|
13177
13125
|
try {
|
|
13178
|
-
const job = await jobQueue.getJob(event.jobId);
|
|
13126
|
+
const job = await jobQueue.getJob(jobId(event.jobId));
|
|
13179
13127
|
if (!job) {
|
|
13180
|
-
eventBus.get("job:status-failed").next({ correlationId: event.correlationId,
|
|
13128
|
+
eventBus.get("job:status-failed").next({ correlationId: event.correlationId, message: "Job not found" });
|
|
13181
13129
|
return;
|
|
13182
13130
|
}
|
|
13183
13131
|
eventBus.get("job:status-result").next({
|
|
@@ -13198,7 +13146,7 @@ async function createJobQueue(project, eventBus, logger) {
|
|
|
13198
13146
|
} catch (error) {
|
|
13199
13147
|
eventBus.get("job:status-failed").next({
|
|
13200
13148
|
correlationId: event.correlationId,
|
|
13201
|
-
|
|
13149
|
+
message: error instanceof Error ? error.message : String(error)
|
|
13202
13150
|
});
|
|
13203
13151
|
}
|
|
13204
13152
|
})()))
|
|
@@ -13230,10 +13178,9 @@ async function createKnowledgeSystemFromConfig(project, config, eventBus, logger
|
|
|
13230
13178
|
model: embeddingConfig.model
|
|
13231
13179
|
});
|
|
13232
13180
|
}
|
|
13233
|
-
const kb = await createKnowledgeBase(eventStore, project, graphDb, logger, {
|
|
13181
|
+
const kb = await createKnowledgeBase(eventStore, project, graphDb, eventBus, logger, {
|
|
13234
13182
|
vectorStore,
|
|
13235
13183
|
embeddingProvider,
|
|
13236
|
-
eventBus,
|
|
13237
13184
|
chunkingConfig: embeddingConfig?.chunking ? {
|
|
13238
13185
|
chunkSize: embeddingConfig.chunking.chunkSize ?? 512,
|
|
13239
13186
|
overlap: embeddingConfig.chunking.overlap ?? 64
|
|
@@ -13242,7 +13189,7 @@ async function createKnowledgeSystemFromConfig(project, config, eventBus, logger
|
|
|
13242
13189
|
});
|
|
13243
13190
|
const stower = new Stower(kb, eventBus, logger.child({ component: "stower" }));
|
|
13244
13191
|
await stower.initialize();
|
|
13245
|
-
await bootstrapEntityTypes(eventBus,
|
|
13192
|
+
await bootstrapEntityTypes(eventBus, eventStore, logger.child({ component: "entity-types-bootstrap" }));
|
|
13246
13193
|
const gatherer = new Gatherer(
|
|
13247
13194
|
kb,
|
|
13248
13195
|
eventBus,
|
|
@@ -13267,22 +13214,22 @@ async function createKnowledgeSystemFromConfig(project, config, eventBus, logger
|
|
|
13267
13214
|
return ks;
|
|
13268
13215
|
}
|
|
13269
13216
|
function createContentFetcher(ks) {
|
|
13270
|
-
return async (
|
|
13271
|
-
const view = await ks.kb.views.get(
|
|
13217
|
+
return async (resourceId7) => {
|
|
13218
|
+
const view = await ks.kb.views.get(resourceId7);
|
|
13272
13219
|
if (!view?.resource.storageUri) return null;
|
|
13273
13220
|
const buffer = await ks.kb.content.retrieve(view.resource.storageUri);
|
|
13274
13221
|
if (!buffer) return null;
|
|
13275
13222
|
return Readable.from([buffer]);
|
|
13276
13223
|
};
|
|
13277
13224
|
}
|
|
13278
|
-
function createWorkers(jobQueue, contentFetcher, eventBus, config, logger) {
|
|
13225
|
+
function createWorkers(jobQueue, contentFetcher, contentStore, eventBus, config, logger) {
|
|
13279
13226
|
const detection = (() => {
|
|
13280
13227
|
const cfg = resolveWorkerInference(config, "reference-annotation");
|
|
13281
13228
|
return new ReferenceAnnotationWorker(jobQueue, createInferenceClient(cfg, logger.child({ component: "inference-client-reference-annotation" })), inferenceConfigToGenerator("Reference Worker", cfg), eventBus, contentFetcher, logger.child({ component: "reference-detection-worker" }));
|
|
13282
13229
|
})();
|
|
13283
13230
|
const generation = (() => {
|
|
13284
13231
|
const cfg = resolveWorkerInference(config, "generation");
|
|
13285
|
-
return new GenerationWorker(jobQueue, createInferenceClient(cfg, logger.child({ component: "inference-client-generation" })), inferenceConfigToGenerator("Generation Worker", cfg), eventBus, logger.child({ component: "generation-worker" }));
|
|
13232
|
+
return new GenerationWorker(jobQueue, createInferenceClient(cfg, logger.child({ component: "inference-client-generation" })), inferenceConfigToGenerator("Generation Worker", cfg), eventBus, contentStore, logger.child({ component: "generation-worker" }));
|
|
13286
13233
|
})();
|
|
13287
13234
|
const highlight = (() => {
|
|
13288
13235
|
const cfg = resolveWorkerInference(config, "highlight-annotation");
|
|
@@ -13325,7 +13272,7 @@ async function startMakeMeaning(project, config, eventBus, logger, options) {
|
|
|
13325
13272
|
const { jobQueue, jobStatusSubscription } = await createJobQueue(project, eventBus, logger);
|
|
13326
13273
|
const knowledgeSystem = await createKnowledgeSystemFromConfig(project, config, eventBus, logger, skipRebuild);
|
|
13327
13274
|
const contentFetcher = createContentFetcher(knowledgeSystem);
|
|
13328
|
-
const workers = createWorkers(jobQueue, contentFetcher, eventBus, config, logger);
|
|
13275
|
+
const workers = createWorkers(jobQueue, contentFetcher, knowledgeSystem.kb.content, eventBus, config, logger);
|
|
13329
13276
|
startWorkers(workers, logger);
|
|
13330
13277
|
return {
|
|
13331
13278
|
knowledgeSystem,
|
|
@@ -13342,7 +13289,7 @@ async function startMakeMeaning(project, config, eventBus, logger, options) {
|
|
|
13342
13289
|
}
|
|
13343
13290
|
|
|
13344
13291
|
// src/exchange/backup-exporter.ts
|
|
13345
|
-
import { getExtensionForMimeType
|
|
13292
|
+
import { getExtensionForMimeType } from "@semiont/content";
|
|
13346
13293
|
|
|
13347
13294
|
// src/exchange/tar.ts
|
|
13348
13295
|
import { createGzip, createGunzip } from "zlib";
|
|
@@ -13468,7 +13415,7 @@ async function exportBackup(options, output) {
|
|
|
13468
13415
|
let totalContentBytes = 0;
|
|
13469
13416
|
for (const [storageUri, mediaType] of contentRefs) {
|
|
13470
13417
|
const data = await content.retrieve(storageUri);
|
|
13471
|
-
const ext =
|
|
13418
|
+
const ext = getExtensionForMimeType(mediaType);
|
|
13472
13419
|
contentBlobs.set(storageUri, { data, ext });
|
|
13473
13420
|
totalContentBytes += data.length;
|
|
13474
13421
|
}
|
|
@@ -13522,8 +13469,8 @@ function collectContentRefs(streamData) {
|
|
|
13522
13469
|
const refs = /* @__PURE__ */ new Map();
|
|
13523
13470
|
for (const [, events] of streamData) {
|
|
13524
13471
|
for (const stored of events) {
|
|
13525
|
-
if (stored.
|
|
13526
|
-
const payload = stored.
|
|
13472
|
+
if (stored.type === "yield:created") {
|
|
13473
|
+
const payload = stored.payload;
|
|
13527
13474
|
if (payload.storageUri && payload.format) {
|
|
13528
13475
|
refs.set(payload.storageUri, payload.format);
|
|
13529
13476
|
}
|
|
@@ -13536,8 +13483,9 @@ function collectContentRefs(streamData) {
|
|
|
13536
13483
|
// src/exchange/replay.ts
|
|
13537
13484
|
var import_rxjs11 = __toESM(require_cjs(), 1);
|
|
13538
13485
|
var import_operators11 = __toESM(require_operators(), 1);
|
|
13486
|
+
import { deriveStorageUri as deriveStorageUri2 } from "@semiont/content";
|
|
13539
13487
|
var REPLAY_TIMEOUT_MS = 3e4;
|
|
13540
|
-
async function replayEventStream(jsonl, eventBus, resolveBlob, logger) {
|
|
13488
|
+
async function replayEventStream(jsonl, eventBus, resolveBlob, contentStore, logger) {
|
|
13541
13489
|
const lines = jsonl.trim().split("\n").filter((l) => l.length > 0);
|
|
13542
13490
|
const storedEvents = lines.map((line) => JSON.parse(line));
|
|
13543
13491
|
const stats = {
|
|
@@ -13562,51 +13510,51 @@ async function replayEventStream(jsonl, eventBus, resolveBlob, logger) {
|
|
|
13562
13510
|
}
|
|
13563
13511
|
}
|
|
13564
13512
|
for (const stored of storedEvents) {
|
|
13565
|
-
await replayEvent(stored
|
|
13513
|
+
await replayEvent(stored, eventBus, resolveBlob, contentStore, stats, logger);
|
|
13566
13514
|
stats.eventsReplayed++;
|
|
13567
13515
|
}
|
|
13568
13516
|
return { stats, hashChainValid };
|
|
13569
13517
|
}
|
|
13570
|
-
async function replayEvent(event, eventBus, resolveBlob, stats, logger) {
|
|
13518
|
+
async function replayEvent(event, eventBus, resolveBlob, contentStore, stats, logger) {
|
|
13571
13519
|
switch (event.type) {
|
|
13572
|
-
case "
|
|
13520
|
+
case "mark:entity-type-added":
|
|
13573
13521
|
await replayEntityTypeAdded(event, eventBus, logger);
|
|
13574
13522
|
stats.entityTypesAdded++;
|
|
13575
13523
|
break;
|
|
13576
|
-
case "
|
|
13577
|
-
await replayResourceCreated(event, eventBus, resolveBlob, logger);
|
|
13524
|
+
case "yield:created":
|
|
13525
|
+
await replayResourceCreated(event, eventBus, resolveBlob, contentStore, logger);
|
|
13578
13526
|
stats.resourcesCreated++;
|
|
13579
13527
|
break;
|
|
13580
|
-
case "
|
|
13528
|
+
case "mark:added":
|
|
13581
13529
|
await replayAnnotationAdded(event, eventBus, logger);
|
|
13582
13530
|
stats.annotationsCreated++;
|
|
13583
13531
|
break;
|
|
13584
|
-
case "
|
|
13532
|
+
case "mark:body-updated":
|
|
13585
13533
|
await replayAnnotationBodyUpdated(event, eventBus, logger);
|
|
13586
13534
|
break;
|
|
13587
|
-
case "
|
|
13535
|
+
case "mark:removed":
|
|
13588
13536
|
await replayAnnotationRemoved(event, eventBus, logger);
|
|
13589
13537
|
break;
|
|
13590
|
-
case "
|
|
13538
|
+
case "mark:archived":
|
|
13591
13539
|
await replayResourceArchived(event, eventBus, logger);
|
|
13592
13540
|
break;
|
|
13593
|
-
case "
|
|
13541
|
+
case "mark:unarchived":
|
|
13594
13542
|
await replayResourceUnarchived(event, eventBus, logger);
|
|
13595
13543
|
break;
|
|
13596
|
-
case "
|
|
13597
|
-
case "
|
|
13544
|
+
case "mark:entity-tag-added":
|
|
13545
|
+
case "mark:entity-tag-removed":
|
|
13598
13546
|
await replayEntityTagChange(event, eventBus, logger);
|
|
13599
13547
|
break;
|
|
13600
13548
|
// Job events are transient — skip during replay
|
|
13601
|
-
case "job
|
|
13602
|
-
case "job
|
|
13603
|
-
case "job
|
|
13604
|
-
case "job
|
|
13549
|
+
case "job:started":
|
|
13550
|
+
case "job:progress":
|
|
13551
|
+
case "job:completed":
|
|
13552
|
+
case "job:failed":
|
|
13605
13553
|
logger?.debug("Skipping job event during replay", { type: event.type });
|
|
13606
13554
|
break;
|
|
13607
|
-
// Representation events — content is already stored via
|
|
13608
|
-
case "representation
|
|
13609
|
-
case "representation
|
|
13555
|
+
// Representation events — content is already stored via yield:created replay
|
|
13556
|
+
case "yield:representation-added":
|
|
13557
|
+
case "yield:representation-removed":
|
|
13610
13558
|
logger?.debug("Skipping representation event during replay", { type: event.type });
|
|
13611
13559
|
break;
|
|
13612
13560
|
default:
|
|
@@ -13617,7 +13565,7 @@ async function replayEntityTypeAdded(event, eventBus, logger) {
|
|
|
13617
13565
|
const result$ = (0, import_rxjs11.race)(
|
|
13618
13566
|
eventBus.get("mark:entity-type-added").pipe((0, import_operators11.map)(() => "ok")),
|
|
13619
13567
|
eventBus.get("mark:entity-type-add-failed").pipe((0, import_operators11.map)((e) => {
|
|
13620
|
-
throw e.
|
|
13568
|
+
throw new Error(e.message);
|
|
13621
13569
|
})),
|
|
13622
13570
|
(0, import_rxjs11.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
|
|
13623
13571
|
throw new Error("Timeout waiting for mark:entity-type-added");
|
|
@@ -13630,24 +13578,28 @@ async function replayEntityTypeAdded(event, eventBus, logger) {
|
|
|
13630
13578
|
await (0, import_rxjs11.firstValueFrom)(result$);
|
|
13631
13579
|
logger?.debug("Replayed entitytype.added", { entityType: event.payload.entityType });
|
|
13632
13580
|
}
|
|
13633
|
-
async function replayResourceCreated(event, eventBus, resolveBlob, logger) {
|
|
13581
|
+
async function replayResourceCreated(event, eventBus, resolveBlob, contentStore, logger) {
|
|
13634
13582
|
const { payload } = event;
|
|
13635
13583
|
const blob = resolveBlob(payload.contentChecksum);
|
|
13636
13584
|
if (!blob) {
|
|
13637
13585
|
throw new Error(`Missing content blob for checksum ${payload.contentChecksum}`);
|
|
13638
13586
|
}
|
|
13587
|
+
const resolvedUri = payload.storageUri || deriveStorageUri2(payload.name, payload.format);
|
|
13588
|
+
const stored = await contentStore.store(blob, resolvedUri);
|
|
13639
13589
|
const result$ = (0, import_rxjs11.race)(
|
|
13640
|
-
eventBus.get("yield:
|
|
13590
|
+
eventBus.get("yield:create-ok").pipe((0, import_operators11.map)((r) => r)),
|
|
13641
13591
|
eventBus.get("yield:create-failed").pipe((0, import_operators11.map)((e) => {
|
|
13642
|
-
throw e.
|
|
13592
|
+
throw new Error(e.message);
|
|
13643
13593
|
})),
|
|
13644
13594
|
(0, import_rxjs11.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
|
|
13645
|
-
throw new Error("Timeout waiting for yield:
|
|
13595
|
+
throw new Error("Timeout waiting for yield:create-ok");
|
|
13646
13596
|
}))
|
|
13647
13597
|
);
|
|
13648
13598
|
eventBus.get("yield:create").next({
|
|
13649
13599
|
name: payload.name,
|
|
13650
|
-
|
|
13600
|
+
storageUri: resolvedUri,
|
|
13601
|
+
contentChecksum: stored.checksum,
|
|
13602
|
+
byteSize: stored.byteSize,
|
|
13651
13603
|
format: payload.format,
|
|
13652
13604
|
userId: event.userId,
|
|
13653
13605
|
language: payload.language,
|
|
@@ -13662,12 +13614,12 @@ async function replayResourceCreated(event, eventBus, resolveBlob, logger) {
|
|
|
13662
13614
|
}
|
|
13663
13615
|
async function replayAnnotationAdded(event, eventBus, logger) {
|
|
13664
13616
|
const result$ = (0, import_rxjs11.race)(
|
|
13665
|
-
eventBus.get("mark:
|
|
13617
|
+
eventBus.get("mark:create-ok").pipe((0, import_operators11.map)(() => "ok")),
|
|
13666
13618
|
eventBus.get("mark:create-failed").pipe((0, import_operators11.map)((e) => {
|
|
13667
|
-
throw e.
|
|
13619
|
+
throw new Error(e.message);
|
|
13668
13620
|
})),
|
|
13669
13621
|
(0, import_rxjs11.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
|
|
13670
|
-
throw new Error("Timeout waiting for mark:
|
|
13622
|
+
throw new Error("Timeout waiting for mark:create-ok");
|
|
13671
13623
|
}))
|
|
13672
13624
|
);
|
|
13673
13625
|
eventBus.get("mark:create").next({
|
|
@@ -13682,7 +13634,7 @@ async function replayAnnotationBodyUpdated(event, eventBus, logger) {
|
|
|
13682
13634
|
const result$ = (0, import_rxjs11.race)(
|
|
13683
13635
|
eventBus.get("mark:body-updated").pipe((0, import_operators11.map)(() => "ok")),
|
|
13684
13636
|
eventBus.get("mark:body-update-failed").pipe((0, import_operators11.map)((e) => {
|
|
13685
|
-
throw e.
|
|
13637
|
+
throw new Error(e.message);
|
|
13686
13638
|
})),
|
|
13687
13639
|
(0, import_rxjs11.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
|
|
13688
13640
|
throw new Error("Timeout waiting for mark:body-updated");
|
|
@@ -13699,12 +13651,12 @@ async function replayAnnotationBodyUpdated(event, eventBus, logger) {
|
|
|
13699
13651
|
}
|
|
13700
13652
|
async function replayAnnotationRemoved(event, eventBus, logger) {
|
|
13701
13653
|
const result$ = (0, import_rxjs11.race)(
|
|
13702
|
-
eventBus.get("mark:
|
|
13654
|
+
eventBus.get("mark:delete-ok").pipe((0, import_operators11.map)(() => "ok")),
|
|
13703
13655
|
eventBus.get("mark:delete-failed").pipe((0, import_operators11.map)((e) => {
|
|
13704
|
-
throw e.
|
|
13656
|
+
throw new Error(e.message);
|
|
13705
13657
|
})),
|
|
13706
13658
|
(0, import_rxjs11.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
|
|
13707
|
-
throw new Error("Timeout waiting for mark:
|
|
13659
|
+
throw new Error("Timeout waiting for mark:delete-ok");
|
|
13708
13660
|
}))
|
|
13709
13661
|
);
|
|
13710
13662
|
eventBus.get("mark:delete").next({
|
|
@@ -13730,18 +13682,18 @@ async function replayResourceUnarchived(event, eventBus, logger) {
|
|
|
13730
13682
|
logger?.debug("Replayed resource.unarchived", { resourceId: event.resourceId });
|
|
13731
13683
|
}
|
|
13732
13684
|
async function replayEntityTagChange(event, eventBus, logger) {
|
|
13733
|
-
const
|
|
13685
|
+
const resourceId7 = event.resourceId;
|
|
13734
13686
|
const entityType = event.payload.entityType;
|
|
13735
|
-
if (event.type === "
|
|
13687
|
+
if (event.type === "mark:entity-tag-added") {
|
|
13736
13688
|
eventBus.get("mark:update-entity-types").next({
|
|
13737
|
-
resourceId:
|
|
13689
|
+
resourceId: resourceId7,
|
|
13738
13690
|
userId: event.userId,
|
|
13739
13691
|
currentEntityTypes: [],
|
|
13740
13692
|
updatedEntityTypes: [entityType]
|
|
13741
13693
|
});
|
|
13742
13694
|
} else {
|
|
13743
13695
|
eventBus.get("mark:update-entity-types").next({
|
|
13744
|
-
resourceId:
|
|
13696
|
+
resourceId: resourceId7,
|
|
13745
13697
|
userId: event.userId,
|
|
13746
13698
|
currentEntityTypes: [entityType],
|
|
13747
13699
|
updatedEntityTypes: []
|
|
@@ -13766,7 +13718,7 @@ function buildBlobResolver(entries) {
|
|
|
13766
13718
|
};
|
|
13767
13719
|
}
|
|
13768
13720
|
async function importBackup(archive, options) {
|
|
13769
|
-
const { eventBus, logger } = options;
|
|
13721
|
+
const { eventBus, contentStore, logger } = options;
|
|
13770
13722
|
const entries = /* @__PURE__ */ new Map();
|
|
13771
13723
|
for await (const entry of readTarGz(archive)) {
|
|
13772
13724
|
entries.set(entry.name, entry.data);
|
|
@@ -13796,6 +13748,7 @@ async function importBackup(archive, options) {
|
|
|
13796
13748
|
systemData.toString("utf8"),
|
|
13797
13749
|
eventBus,
|
|
13798
13750
|
resolveBlob,
|
|
13751
|
+
contentStore,
|
|
13799
13752
|
logger
|
|
13800
13753
|
);
|
|
13801
13754
|
stats = mergeStats(stats, result.stats);
|
|
@@ -13812,6 +13765,7 @@ async function importBackup(archive, options) {
|
|
|
13812
13765
|
eventData.toString("utf8"),
|
|
13813
13766
|
eventBus,
|
|
13814
13767
|
resolveBlob,
|
|
13768
|
+
contentStore,
|
|
13815
13769
|
logger
|
|
13816
13770
|
);
|
|
13817
13771
|
stats = mergeStats(stats, result.stats);
|
|
@@ -13830,7 +13784,7 @@ function mergeStats(a, b) {
|
|
|
13830
13784
|
}
|
|
13831
13785
|
|
|
13832
13786
|
// src/exchange/linked-data-exporter.ts
|
|
13833
|
-
import { getExtensionForMimeType as
|
|
13787
|
+
import { getExtensionForMimeType as getExtensionForMimeType2 } from "@semiont/content";
|
|
13834
13788
|
var SEMIONT_CONTEXT = [
|
|
13835
13789
|
"https://schema.org/",
|
|
13836
13790
|
"http://www.w3.org/ns/anno.jsonld",
|
|
@@ -13897,7 +13851,7 @@ async function exportLinkedData(options, output) {
|
|
|
13897
13851
|
for (const [storageUri, mediaType] of contentRefs) {
|
|
13898
13852
|
try {
|
|
13899
13853
|
const data = await content.retrieve(storageUri);
|
|
13900
|
-
const ext =
|
|
13854
|
+
const ext = getExtensionForMimeType2(mediaType);
|
|
13901
13855
|
contentBlobs.set(storageUri, { data, ext });
|
|
13902
13856
|
} catch (err) {
|
|
13903
13857
|
logger?.warn("Failed to retrieve content blob", { storageUri, error: String(err) });
|
|
@@ -13922,10 +13876,10 @@ async function exportLinkedData(options, output) {
|
|
|
13922
13876
|
data: Buffer.from(JSON.stringify(manifest, null, 2), "utf8")
|
|
13923
13877
|
};
|
|
13924
13878
|
for (const view of resourceViews) {
|
|
13925
|
-
const
|
|
13879
|
+
const resourceId7 = view.resource["@id"];
|
|
13926
13880
|
const jsonld = buildResourceJsonLd(view.resource, view.annotations.annotations, sourceUrl);
|
|
13927
13881
|
yield {
|
|
13928
|
-
name: `.semiont/resources/${
|
|
13882
|
+
name: `.semiont/resources/${resourceId7}.jsonld`,
|
|
13929
13883
|
data: Buffer.from(JSON.stringify(jsonld, null, 2), "utf8")
|
|
13930
13884
|
};
|
|
13931
13885
|
}
|
|
@@ -13942,8 +13896,8 @@ async function exportLinkedData(options, output) {
|
|
|
13942
13896
|
return manifest;
|
|
13943
13897
|
}
|
|
13944
13898
|
function buildResourceJsonLd(resource, annotations, sourceUrl) {
|
|
13945
|
-
const
|
|
13946
|
-
const resourceUri =
|
|
13899
|
+
const resourceId7 = resource["@id"];
|
|
13900
|
+
const resourceUri = resourceId7.startsWith("http") ? resourceId7 : `${sourceUrl}/resources/${resourceId7}`;
|
|
13947
13901
|
const doc = {
|
|
13948
13902
|
"@context": SEMIONT_CONTEXT,
|
|
13949
13903
|
"@id": resourceUri,
|
|
@@ -13977,7 +13931,7 @@ function buildResourceJsonLd(resource, annotations, sourceUrl) {
|
|
|
13977
13931
|
if (rep.checksum) {
|
|
13978
13932
|
const rawChecksum = rep.checksum.startsWith("sha256:") ? rep.checksum.slice(7) : rep.checksum;
|
|
13979
13933
|
mediaObj["sha256"] = rawChecksum;
|
|
13980
|
-
const ext =
|
|
13934
|
+
const ext = getExtensionForMimeType2(rep.mediaType);
|
|
13981
13935
|
mediaObj["name"] = `${rawChecksum}${ext}`;
|
|
13982
13936
|
}
|
|
13983
13937
|
if (rep.language) mediaObj["inLanguage"] = rep.language;
|
|
@@ -14005,6 +13959,8 @@ function collectContentRefsFromResource(resource, refs) {
|
|
|
14005
13959
|
// src/exchange/linked-data-importer.ts
|
|
14006
13960
|
var import_rxjs12 = __toESM(require_cjs(), 1);
|
|
14007
13961
|
var import_operators12 = __toESM(require_operators(), 1);
|
|
13962
|
+
import { resourceId as makeResourceId5 } from "@semiont/core";
|
|
13963
|
+
import { deriveStorageUri as deriveStorageUri3 } from "@semiont/content";
|
|
14008
13964
|
var IMPORT_TIMEOUT_MS = 3e4;
|
|
14009
13965
|
function stripUriToId(uri) {
|
|
14010
13966
|
if (!uri.includes("/")) return uri;
|
|
@@ -14058,7 +14014,7 @@ function buildBlobResolver2(entries) {
|
|
|
14058
14014
|
};
|
|
14059
14015
|
}
|
|
14060
14016
|
async function importLinkedData(archive, options) {
|
|
14061
|
-
const { eventBus, userId: userId2, logger } = options;
|
|
14017
|
+
const { eventBus, contentStore, userId: userId2, logger } = options;
|
|
14062
14018
|
const entries = /* @__PURE__ */ new Map();
|
|
14063
14019
|
for await (const entry of readTarGz(archive)) {
|
|
14064
14020
|
entries.set(entry.name, entry.data);
|
|
@@ -14089,7 +14045,7 @@ async function importLinkedData(archive, options) {
|
|
|
14089
14045
|
let annotationsCreated = 0;
|
|
14090
14046
|
for (const entryName of resourceEntries) {
|
|
14091
14047
|
const resourceDoc = JSON.parse(entries.get(entryName).toString("utf8"));
|
|
14092
|
-
const result = await importResource(resourceDoc, userId2, eventBus, resolveBlob, logger);
|
|
14048
|
+
const result = await importResource(resourceDoc, userId2, eventBus, contentStore, resolveBlob, logger);
|
|
14093
14049
|
resourcesCreated++;
|
|
14094
14050
|
annotationsCreated += result.annotationsCreated;
|
|
14095
14051
|
}
|
|
@@ -14109,7 +14065,7 @@ async function addEntityType(entityType, userId2, eventBus, logger) {
|
|
|
14109
14065
|
const result$ = (0, import_rxjs12.race)(
|
|
14110
14066
|
eventBus.get("mark:entity-type-added").pipe((0, import_operators12.map)(() => "ok")),
|
|
14111
14067
|
eventBus.get("mark:entity-type-add-failed").pipe((0, import_operators12.map)((e) => {
|
|
14112
|
-
throw e.
|
|
14068
|
+
throw new Error(e.message);
|
|
14113
14069
|
})),
|
|
14114
14070
|
(0, import_rxjs12.timer)(IMPORT_TIMEOUT_MS).pipe((0, import_operators12.map)(() => {
|
|
14115
14071
|
throw new Error("Timeout waiting for mark:entity-type-added");
|
|
@@ -14122,7 +14078,7 @@ async function addEntityType(entityType, userId2, eventBus, logger) {
|
|
|
14122
14078
|
await (0, import_rxjs12.firstValueFrom)(result$);
|
|
14123
14079
|
logger?.debug("Added entity type", { entityType });
|
|
14124
14080
|
}
|
|
14125
|
-
async function importResource(doc, userId2, eventBus, resolveBlob, logger) {
|
|
14081
|
+
async function importResource(doc, userId2, eventBus, contentStore, resolveBlob, logger) {
|
|
14126
14082
|
const name = doc["name"];
|
|
14127
14083
|
const representations = doc["representations"];
|
|
14128
14084
|
const annotations = doc["annotations"];
|
|
@@ -14144,18 +14100,22 @@ async function importResource(doc, userId2, eventBus, resolveBlob, logger) {
|
|
|
14144
14100
|
if (!blob) {
|
|
14145
14101
|
throw new Error(`Missing content blob for checksum ${contentChecksum} (resource "${name}")`);
|
|
14146
14102
|
}
|
|
14103
|
+
const resolvedUri = deriveStorageUri3(name, format);
|
|
14104
|
+
const stored = await contentStore.store(blob, resolvedUri);
|
|
14147
14105
|
const createResult$ = (0, import_rxjs12.race)(
|
|
14148
|
-
eventBus.get("yield:
|
|
14106
|
+
eventBus.get("yield:create-ok").pipe((0, import_operators12.map)((r) => r)),
|
|
14149
14107
|
eventBus.get("yield:create-failed").pipe((0, import_operators12.map)((e) => {
|
|
14150
|
-
throw e.
|
|
14108
|
+
throw new Error(e.message);
|
|
14151
14109
|
})),
|
|
14152
14110
|
(0, import_rxjs12.timer)(IMPORT_TIMEOUT_MS).pipe((0, import_operators12.map)(() => {
|
|
14153
|
-
throw new Error("Timeout waiting for yield:
|
|
14111
|
+
throw new Error("Timeout waiting for yield:create-ok");
|
|
14154
14112
|
}))
|
|
14155
14113
|
);
|
|
14156
14114
|
eventBus.get("yield:create").next({
|
|
14157
14115
|
name,
|
|
14158
|
-
|
|
14116
|
+
storageUri: resolvedUri,
|
|
14117
|
+
contentChecksum: stored.checksum,
|
|
14118
|
+
byteSize: stored.byteSize,
|
|
14159
14119
|
format,
|
|
14160
14120
|
userId: userId2,
|
|
14161
14121
|
language,
|
|
@@ -14163,31 +14123,31 @@ async function importResource(doc, userId2, eventBus, resolveBlob, logger) {
|
|
|
14163
14123
|
creationMethod
|
|
14164
14124
|
});
|
|
14165
14125
|
const created = await (0, import_rxjs12.firstValueFrom)(createResult$);
|
|
14166
|
-
const
|
|
14167
|
-
logger?.debug("Created resource from JSON-LD", { name, resourceId:
|
|
14126
|
+
const resourceId7 = makeResourceId5(created.resourceId);
|
|
14127
|
+
logger?.debug("Created resource from JSON-LD", { name, resourceId: resourceId7 });
|
|
14168
14128
|
let annotationsCreated = 0;
|
|
14169
14129
|
if (annotations && annotations.length > 0) {
|
|
14170
14130
|
for (const annotation of annotations) {
|
|
14171
|
-
await createAnnotation(annotation,
|
|
14131
|
+
await createAnnotation(annotation, resourceId7, userId2, eventBus, logger);
|
|
14172
14132
|
annotationsCreated++;
|
|
14173
14133
|
}
|
|
14174
14134
|
}
|
|
14175
14135
|
return { annotationsCreated };
|
|
14176
14136
|
}
|
|
14177
|
-
async function createAnnotation(annotation,
|
|
14137
|
+
async function createAnnotation(annotation, resourceId7, userId2, eventBus, logger) {
|
|
14178
14138
|
const result$ = (0, import_rxjs12.race)(
|
|
14179
|
-
eventBus.get("mark:
|
|
14139
|
+
eventBus.get("mark:create-ok").pipe((0, import_operators12.map)(() => "ok")),
|
|
14180
14140
|
eventBus.get("mark:create-failed").pipe((0, import_operators12.map)((e) => {
|
|
14181
|
-
throw e.
|
|
14141
|
+
throw new Error(e.message);
|
|
14182
14142
|
})),
|
|
14183
14143
|
(0, import_rxjs12.timer)(IMPORT_TIMEOUT_MS).pipe((0, import_operators12.map)(() => {
|
|
14184
|
-
throw new Error("Timeout waiting for mark:
|
|
14144
|
+
throw new Error("Timeout waiting for mark:create-ok");
|
|
14185
14145
|
}))
|
|
14186
14146
|
);
|
|
14187
14147
|
eventBus.get("mark:create").next({
|
|
14188
14148
|
annotation: dehydrateAnnotation(annotation),
|
|
14189
14149
|
userId: userId2,
|
|
14190
|
-
resourceId:
|
|
14150
|
+
resourceId: resourceId7
|
|
14191
14151
|
});
|
|
14192
14152
|
await (0, import_rxjs12.firstValueFrom)(result$);
|
|
14193
14153
|
logger?.debug("Created annotation", { annotationId: annotation.id });
|
|
@@ -14200,14 +14160,14 @@ import {
|
|
|
14200
14160
|
} from "@semiont/core";
|
|
14201
14161
|
|
|
14202
14162
|
// src/annotation-operations.ts
|
|
14203
|
-
import { annotationId, resourceId as
|
|
14163
|
+
import { annotationId as annotationId2, resourceId as makeResourceId6, assembleAnnotation as assembleAnnotation2, applyBodyOperations as applyBodyOperations2 } from "@semiont/core";
|
|
14204
14164
|
var AnnotationOperations = class {
|
|
14205
14165
|
/**
|
|
14206
14166
|
* Create a new annotation via EventBus → Stower
|
|
14207
14167
|
*/
|
|
14208
14168
|
static async createAnnotation(request, userId2, creator, eventBus) {
|
|
14209
14169
|
const { annotation } = assembleAnnotation2(request, creator);
|
|
14210
|
-
const resId =
|
|
14170
|
+
const resId = makeResourceId6(request.target.source);
|
|
14211
14171
|
eventBus.get("mark:create").next({
|
|
14212
14172
|
annotation,
|
|
14213
14173
|
userId: userId2,
|
|
@@ -14219,9 +14179,9 @@ var AnnotationOperations = class {
|
|
|
14219
14179
|
* Update annotation body via EventBus → Stower
|
|
14220
14180
|
*/
|
|
14221
14181
|
static async updateAnnotationBody(id, request, userId2, eventBus, kb) {
|
|
14222
|
-
const resId =
|
|
14182
|
+
const resId = makeResourceId6(request.resourceId);
|
|
14223
14183
|
const annotation = await AnnotationContext.getAnnotation(
|
|
14224
|
-
|
|
14184
|
+
annotationId2(id),
|
|
14225
14185
|
resId,
|
|
14226
14186
|
kb
|
|
14227
14187
|
);
|
|
@@ -14229,7 +14189,7 @@ var AnnotationOperations = class {
|
|
|
14229
14189
|
throw new Error("Annotation not found");
|
|
14230
14190
|
}
|
|
14231
14191
|
eventBus.get("mark:update-body").next({
|
|
14232
|
-
annotationId:
|
|
14192
|
+
annotationId: annotationId2(id),
|
|
14233
14193
|
userId: userId2,
|
|
14234
14194
|
resourceId: resId,
|
|
14235
14195
|
operations: request.operations
|
|
@@ -14246,7 +14206,7 @@ var AnnotationOperations = class {
|
|
|
14246
14206
|
* Delete an annotation via EventBus → Stower
|
|
14247
14207
|
*/
|
|
14248
14208
|
static async deleteAnnotation(id, resourceIdStr, userId2, eventBus, kb, logger) {
|
|
14249
|
-
const resId =
|
|
14209
|
+
const resId = makeResourceId6(resourceIdStr);
|
|
14250
14210
|
const projection = await AnnotationContext.getResourceAnnotations(resId, kb);
|
|
14251
14211
|
const annotation = projection.annotations.find((a) => a.id === id);
|
|
14252
14212
|
if (!annotation) {
|
|
@@ -14254,7 +14214,7 @@ var AnnotationOperations = class {
|
|
|
14254
14214
|
}
|
|
14255
14215
|
logger?.debug("Removing annotation via EventBus", { annotationId: id });
|
|
14256
14216
|
eventBus.get("mark:delete").next({
|
|
14257
|
-
annotationId:
|
|
14217
|
+
annotationId: annotationId2(id),
|
|
14258
14218
|
userId: userId2,
|
|
14259
14219
|
resourceId: resId
|
|
14260
14220
|
});
|
|
@@ -14294,7 +14254,6 @@ export {
|
|
|
14294
14254
|
importLinkedData,
|
|
14295
14255
|
isBackupManifest,
|
|
14296
14256
|
readEntityTypesProjection,
|
|
14297
|
-
resetBootstrap,
|
|
14298
14257
|
startMakeMeaning,
|
|
14299
14258
|
stopKnowledgeSystem,
|
|
14300
14259
|
validateManifestVersion
|