@semiont/make-meaning 0.4.20 → 0.4.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,12 +1,13 @@
1
- import { JobQueue, ReferenceAnnotationWorker, GenerationWorker, HighlightAnnotationWorker, AssessmentAnnotationWorker, CommentAnnotationWorker, TagAnnotationWorker } from '@semiont/jobs';
1
+ import { JobQueue } from '@semiont/jobs';
2
2
  import { SemiontProject } from '@semiont/core/node';
3
- import { GraphServiceConfig, VectorsServiceConfig, EmbeddingServiceConfig, EventBus, Logger, StoredEvent, ResourceId, AnnotationId, components, UserId, CreationMethod, ResourceAnnotations, AnnotationCategory, GraphPath, GraphConnection } from '@semiont/core';
3
+ import { GraphServiceConfig, VectorsServiceConfig, EmbeddingServiceConfig, EventBus, Logger, StoredEvent, ResourceId, ResourceDescriptor, AnnotationId, components, ITransport, BaseUrl, ConnectionState, UserDID, EventMap, Email, GoogleCredential, RefreshToken, UserResponse, ListUsersResponse, UpdateUserRequest, UpdateUserResponse, ProgressCallback, ProgressEvent, HealthCheckResponse, StatusResponse, IContentTransport, PutBinaryRequest, AccessToken, ContentFormat as ContentFormat$1, Annotation, UserId, CreationMethod, ResourceAnnotations, AnnotationCategory, GraphPath, GraphConnection } from '@semiont/core';
4
4
  export { AssembledAnnotation, applyBodyOperations, assembleAnnotation } from '@semiont/core';
5
5
  import { EventStore, ViewStorage } from '@semiont/event-sourcing';
6
6
  import { WorkingTreeStore } from '@semiont/content';
7
7
  import { GraphDatabase } from '@semiont/graph';
8
- import { VectorStore, EmbeddingProvider, ChunkingConfig } from '@semiont/vectors';
8
+ import { VectorStore, EmbeddingProvider } from '@semiont/vectors';
9
9
  import { InferenceClient } from '@semiont/inference';
10
+ import { BehaviorSubject, Observable } from 'rxjs';
10
11
  import { Writable, Readable } from 'node:stream';
11
12
 
12
13
  /**
@@ -79,8 +80,7 @@ interface MakeMeaningConfig {
79
80
  * per-resource serialization — the same invariant enforced by `Smelter`,
80
81
  * `Gatherer`, and (in a different shape) `ViewManager`. See
81
82
  * `packages/core/src/serialize-per-key.ts` for the shared primitive used
82
- * by RPC-style services, and `.plans/PerResourceSerializer.md` for the
83
- * broader design that would unify the two shapes.
83
+ * by RPC-style services.
84
84
  */
85
85
 
86
86
  declare class GraphDBConsumer {
@@ -156,157 +156,6 @@ declare class GraphDBConsumer {
156
156
  shutdown(): Promise<void>;
157
157
  }
158
158
 
159
- /**
160
- * EmbeddingStore
161
- *
162
- * Durable file-based cache for pre-computed embedding vectors.
163
- * Stored under .semiont/embeddings/ — committed to git alongside events,
164
- * but overwritten in place rather than appended.
165
- *
166
- * File layout (same 4-hex Jump Consistent Hash sharding as events):
167
- *
168
- * .semiont/embeddings/{ab}/{cd}/{resourceId}.jsonl
169
- * Line 0: { model, dimensions } ← model header
170
- * Line N: { chunkIndex, text, embedding[] } ← one chunk per line
171
- *
172
- * .semiont/embeddings/{ab}/{cd}/{annotationId}.json
173
- * { model, dimensions, resourceId, text, embedding[], motivation, entityTypes }
174
- *
175
- * rebuildAll() in Smelter reads these files and upserts into Qdrant without
176
- * calling the embedding provider — unless the stored model doesn't match the
177
- * configured provider, in which case the file is re-embedded and overwritten.
178
- */
179
-
180
- interface StoredChunk {
181
- chunkIndex: number;
182
- text: string;
183
- embedding: number[];
184
- }
185
- interface ResourceEmbeddingFile {
186
- model: string;
187
- dimensions: number;
188
- chunks: StoredChunk[];
189
- }
190
- interface AnnotationEmbeddingFile {
191
- model: string;
192
- dimensions: number;
193
- resourceId: string;
194
- text: string;
195
- embedding: number[];
196
- motivation: string;
197
- entityTypes: string[];
198
- }
199
- declare class EmbeddingStore {
200
- private readonly project;
201
- constructor(project: SemiontProject);
202
- private resourceFilePath;
203
- private annotationFilePath;
204
- writeResourceChunks(resourceId: ResourceId, model: string, dimensions: number, chunks: StoredChunk[]): Promise<void>;
205
- readResourceEmbeddings(resourceId: ResourceId): Promise<ResourceEmbeddingFile | null>;
206
- deleteResourceEmbeddings(resourceId: ResourceId): Promise<void>;
207
- writeAnnotationEmbedding(annotationId: AnnotationId, resourceId: ResourceId, model: string, dimensions: number, text: string, embedding: number[], motivation: string, entityTypes: string[]): Promise<void>;
208
- readAnnotationEmbedding(annotationId: AnnotationId): Promise<AnnotationEmbeddingFile | null>;
209
- deleteAnnotationEmbedding(annotationId: AnnotationId): Promise<void>;
210
- /**
211
- * Scan embeddings directory and return all resource IDs (from *.jsonl files).
212
- */
213
- getAllResourceIds(): Promise<string[]>;
214
- /**
215
- * Scan embeddings directory and return all annotation IDs (from *.json files).
216
- */
217
- getAllAnnotationIds(): Promise<string[]>;
218
- private scanIds;
219
- }
220
-
221
- /**
222
- * Smelter Actor
223
- *
224
- * Takes raw content, refines it into embedding vectors, persists them to the
225
- * EmbeddingStore (.semiont/embeddings/), and indexes them into the VectorStore
226
- * (Qdrant). Peer to the Graph Consumer.
227
- *
228
- * Pipeline:
229
- * 1. Subscribe to resource and annotation events from the EventStore
230
- * 2. Chunk resource text into overlapping passages
231
- * 3. Embed each chunk via the configured EmbeddingProvider
232
- * 4. Write vectors to EmbeddingStore (overwrite-in-place, git-durable)
233
- * 5. Index vectors into the VectorStore (Qdrant) for fast similarity search
234
- *
235
- * Uses the same burst-buffer RxJS pipeline as GraphDBConsumer.
236
- *
237
- * ## Per-resource serialization
238
- *
239
- * Smelter processes events strictly in order per resourceId via
240
- * `groupBy(resourceId) + concatMap(...)`. This is the stream-consumer
241
- * flavor of per-resource serialization — the same invariant enforced by
242
- * `GraphDBConsumer`, `Gatherer`, and (in a different shape) `ViewManager`.
243
- * See `packages/core/src/serialize-per-key.ts` for the shared primitive
244
- * used by RPC-style services, and `.plans/PerResourceSerializer.md` for
245
- * the broader design that would unify the two shapes.
246
- */
247
-
248
- declare class Smelter {
249
- private eventBus;
250
- private vectorStore;
251
- private embeddingProvider;
252
- private contentStore;
253
- private embeddingStore;
254
- private viewStorage;
255
- private static readonly SMELTER_RELEVANT_EVENTS;
256
- private static readonly BURST_WINDOW_MS;
257
- private static readonly MAX_BATCH_SIZE;
258
- private static readonly IDLE_TIMEOUT_MS;
259
- private _globalSubscriptions;
260
- private eventSubject;
261
- private pipelineSubscription;
262
- private readonly logger;
263
- private readonly chunkingConfig;
264
- constructor(_eventStore: EventStore, eventBus: EventBus, vectorStore: VectorStore, embeddingProvider: EmbeddingProvider, contentStore: WorkingTreeStore, embeddingStore: EmbeddingStore, viewStorage: ViewStorage, logger: Logger, chunkingConfig?: ChunkingConfig);
265
- initialize(): Promise<void>;
266
- stop(): Promise<void>;
267
- /**
268
- * Rebuild the vector store from the EmbeddingStore (.semiont/embeddings/).
269
- *
270
- * For each stored file, checks whether the model matches the configured
271
- * provider. On mismatch, re-embeds from the stored text and overwrites the
272
- * file before upserting into Qdrant. On match, loads the stored vectors
273
- * directly — no embedding provider calls needed.
274
- */
275
- rebuildAll(): Promise<void>;
276
- private processBatch;
277
- /**
278
- * Batch-optimized processing for consecutive events of the same type.
279
- */
280
- private applyBatchByType;
281
- /**
282
- * Batch-embed chunks from multiple yield:created events in a single
283
- * embedBatch() call, then write to EmbeddingStore and index per resource.
284
- */
285
- private batchResourceCreated;
286
- /**
287
- * Batch-embed exact texts from multiple mark:added events in a single
288
- * embedBatch() call, then write to EmbeddingStore and index per annotation.
289
- */
290
- private batchAnnotationAdded;
291
- private safeProcessEvent;
292
- private processEvent;
293
- private handleResourceCreated;
294
- /**
295
- * Re-embed a resource whose content has changed in-place.
296
- *
297
- * Used by yield:updated and yield:representation-added handlers. Reads the
298
- * current storageUri from the materialized view (which is updated before the
299
- * EventBus fires), deletes stale Qdrant vectors, and overwrites the
300
- * EmbeddingStore file with fresh chunks.
301
- */
302
- private reembedResource;
303
- private handleResourceUpdated;
304
- private handleRepresentationAdded;
305
- private handleResourceArchived;
306
- private handleAnnotationAdded;
307
- private handleAnnotationRemoved;
308
- }
309
-
310
159
  /**
311
160
  * Knowledge Base
312
161
  *
@@ -318,10 +167,11 @@ declare class Smelter {
318
167
  * - Content Store (working-tree files, URI-addressed) — via WorkingTreeStore
319
168
  * - Graph (eventually consistent relationship projection) — via GraphDatabase
320
169
  * - Graph Consumer (event-to-graph projection) — via GraphDBConsumer
321
- * - Vectors (semantic search) — via VectorStore (optional)
322
- * - Smelter (event-to-vector projection) — via Smelter (optional)
170
+ * - Vectors (semantic search) — via VectorStore (optional, read-only)
323
171
  *
324
- * The Gatherer and Matcher are the only actors that read from these stores directly.
172
+ * The Smelter (event-to-vector projection) runs as an external actor
173
+ * via @semiont/jobs/smelter-main. It subscribes to domain events via
174
+ * the EventBus gateway, embeds content, and writes to Qdrant directly.
325
175
  */
326
176
 
327
177
  interface KnowledgeBase {
@@ -331,13 +181,10 @@ interface KnowledgeBase {
331
181
  graph: GraphDatabase;
332
182
  graphConsumer: GraphDBConsumer;
333
183
  vectors?: VectorStore;
334
- smelter?: Smelter;
335
184
  projectionsDir: string;
336
185
  }
337
186
  interface CreateKnowledgeBaseOptions {
338
187
  vectorStore?: VectorStore;
339
- embeddingProvider?: EmbeddingProvider;
340
- chunkingConfig?: ChunkingConfig;
341
188
  skipRebuild?: boolean;
342
189
  }
343
190
  declare function createKnowledgeBase(eventStore: EventStore, project: SemiontProject, graphDb: GraphDatabase, eventBus: EventBus, logger: Logger, options?: CreateKnowledgeBaseOptions): Promise<KnowledgeBase>;
@@ -369,15 +216,19 @@ declare function createKnowledgeBase(eventStore: EventStore, project: SemiontPro
369
216
  * - mark:add-entity-type → entitytype.added → mark:entity-type-added / mark:entity-type-add-failed
370
217
  * - mark:update-entity-types → entitytag.added / entitytag.removed
371
218
  * - job:start → job.started
372
- * - job:report-progress → job.progress
373
219
  * - job:complete → job.completed
374
220
  * - job:fail → job.failed
221
+ *
222
+ * Note: `job:report-progress` is intentionally NOT persisted. Progress
223
+ * events are ephemeral UI feedback and would clutter the event log
224
+ * (historical logs show ~3× as many progress entries as start+complete
225
+ * combined). UI consumers subscribe to the bus directly for live
226
+ * progress; the event log keeps only the durable lifecycle boundaries.
375
227
  */
376
228
 
377
- type ResourceDescriptor$3 = components['schemas']['ResourceDescriptor'];
378
229
  interface CreateResourceResult {
379
230
  resourceId: ResourceId;
380
- resource: ResourceDescriptor$3;
231
+ resource: ResourceDescriptor;
381
232
  }
382
233
  declare class Stower {
383
234
  private kb;
@@ -397,7 +248,6 @@ declare class Stower {
397
248
  private handleAddEntityType;
398
249
  private handleUpdateEntityTypes;
399
250
  private handleJobStart;
400
- private handleJobReportProgress;
401
251
  private handleJobComplete;
402
252
  private handleJobFail;
403
253
  stop(): Promise<void>;
@@ -426,11 +276,10 @@ declare class Stower {
426
276
  * per-resource serialization — the same invariant enforced by `Smelter`,
427
277
  * `GraphDBConsumer`, and (in a different shape) `ViewManager`. See
428
278
  * `packages/core/src/serialize-per-key.ts` for the shared primitive used
429
- * by RPC-style services, and `.plans/PerResourceSerializer.md` for the
430
- * broader design that would unify the two shapes.
279
+ * by RPC-style services.
431
280
  */
432
281
 
433
- declare class Gatherer {
282
+ declare class Gatherer$1 {
434
283
  private kb;
435
284
  private eventBus;
436
285
  private inferenceClient;
@@ -588,7 +437,7 @@ declare class CloneTokenManager {
588
437
  interface KnowledgeSystem {
589
438
  kb: KnowledgeBase;
590
439
  stower: Stower;
591
- gatherer: Gatherer;
440
+ gatherer: Gatherer$1;
592
441
  matcher: Matcher;
593
442
  browser: Browser;
594
443
  cloneTokenManager: CloneTokenManager;
@@ -606,21 +455,204 @@ declare function stopKnowledgeSystem(ks: KnowledgeSystem): Promise<void>;
606
455
  interface MakeMeaningService {
607
456
  knowledgeSystem: KnowledgeSystem;
608
457
  jobQueue: JobQueue;
609
- workers: Workers;
610
458
  stop: () => Promise<void>;
611
459
  }
612
- type Workers = {
613
- detection: ReferenceAnnotationWorker;
614
- generation: GenerationWorker;
615
- highlight: HighlightAnnotationWorker;
616
- assessment: AssessmentAnnotationWorker;
617
- comment: CommentAnnotationWorker;
618
- tag: TagAnnotationWorker;
619
- };
620
460
  declare function startMakeMeaning(project: SemiontProject, config: MakeMeaningConfig, eventBus: EventBus, logger: Logger, options?: {
621
461
  skipRebuild?: boolean;
622
462
  }): Promise<MakeMeaningService>;
623
463
 
464
+ /**
465
+ * LocalTransport — `ITransport` for an in-process `KnowledgeSystem`.
466
+ *
467
+ * Bus-ownership pattern (see `packages/core/docs/TRANSPORT-CONTRACT.md`):
468
+ * - The caller owns a make-meaning `EventBus` and passes it to both
469
+ * `startMakeMeaning` and `LocalTransport` so the transport can publish
470
+ * directly onto the bus the `KnowledgeSystem` actors are listening on.
471
+ * - `SemiontClient` constructs its own `clientBus` and calls
472
+ * `bridgeInto(clientBus)` during construction. `LocalTransport`
473
+ * subscribes to every `BRIDGED_CHANNELS` entry on the make-meaning bus
474
+ * and forwards each onto `clientBus`.
475
+ * - The bus reference flows client → transport, never the other way.
476
+ *
477
+ * Auth, admin, and exchange methods are not implemented in Phase 2 — local
478
+ * mode runs as a single host-process identity supplied at construction.
479
+ * Calling them throws.
480
+ */
481
+
482
+ type AuthResponse = components['schemas']['AuthResponse'];
483
+ type TokenRefreshResponse = components['schemas']['TokenRefreshResponse'];
484
+ type AdminUserStatsResponse = components['schemas']['AdminUserStatsResponse'];
485
+ type OAuthConfigResponse = components['schemas']['OAuthConfigResponse'];
486
+ interface LocalTransportConfig {
487
+ /**
488
+ * The in-process knowledge system. Lifetime is owned by the caller —
489
+ * `dispose()` on this transport does not stop the KnowledgeSystem.
490
+ */
491
+ knowledgeSystem: KnowledgeSystem;
492
+ /**
493
+ * The make-meaning `EventBus`. Must be the same instance passed to
494
+ * `startMakeMeaning` so that emits land on the bus KnowledgeSystem
495
+ * actors are subscribed to.
496
+ */
497
+ eventBus: EventBus;
498
+ /**
499
+ * Host-process identity. Stamped onto every emit as `_userId`, mirroring
500
+ * the gateway-injection convention used by `HttpTransport` (where the
501
+ * `/bus/emit` gateway reads the JWT subject and injects `_userId`).
502
+ * Handlers downstream trust nothing else.
503
+ */
504
+ userId: UserDID;
505
+ /**
506
+ * Cosmetic base URL for diagnostics and URL composition. Defaults to
507
+ * `local://in-process`. Local code never makes outgoing HTTP requests
508
+ * with it.
509
+ */
510
+ baseUrl?: BaseUrl;
511
+ }
512
+ declare class LocalTransport implements ITransport {
513
+ readonly baseUrl: BaseUrl;
514
+ readonly state$: BehaviorSubject<ConnectionState>;
515
+ private readonly bus;
516
+ private readonly userId;
517
+ private readonly bridges;
518
+ private readonly bridgeSubs;
519
+ private disposed;
520
+ constructor(cfg: LocalTransportConfig);
521
+ emit<K extends keyof EventMap>(channel: K, payload: EventMap[K], resourceScope?: ResourceId): Promise<void>;
522
+ on<K extends keyof EventMap>(channel: K, handler: (payload: EventMap[K]) => void): () => void;
523
+ stream<K extends keyof EventMap>(channel: K): Observable<EventMap[K]>;
524
+ subscribeToResource(_resourceId: ResourceId): () => void;
525
+ bridgeInto(bus: EventBus): void;
526
+ authenticatePassword(_email: Email, _password: string): Promise<AuthResponse>;
527
+ authenticateGoogle(_credential: GoogleCredential): Promise<AuthResponse>;
528
+ refreshAccessToken(_token: RefreshToken): Promise<TokenRefreshResponse>;
529
+ logout(): Promise<void>;
530
+ acceptTerms(): Promise<void>;
531
+ getCurrentUser(): Promise<UserResponse>;
532
+ generateMcpToken(): Promise<{
533
+ token: string;
534
+ }>;
535
+ getMediaToken(_resourceId: ResourceId): Promise<{
536
+ token: string;
537
+ }>;
538
+ listUsers(): Promise<ListUsersResponse>;
539
+ getUserStats(): Promise<AdminUserStatsResponse>;
540
+ updateUser(_id: UserDID, _data: UpdateUserRequest): Promise<UpdateUserResponse>;
541
+ getOAuthConfig(): Promise<OAuthConfigResponse>;
542
+ backupKnowledgeBase(): Promise<Response>;
543
+ restoreKnowledgeBase(_file: File, _onProgress?: ProgressCallback): Promise<ProgressEvent>;
544
+ exportKnowledgeBase(_params?: {
545
+ includeArchived?: boolean;
546
+ }): Promise<Response>;
547
+ importKnowledgeBase(_file: File, _onProgress?: ProgressCallback): Promise<ProgressEvent>;
548
+ healthCheck(): Promise<HealthCheckResponse>;
549
+ getStatus(): Promise<StatusResponse>;
550
+ dispose(): void;
551
+ }
552
+
553
+ /**
554
+ * LocalContentTransport — `IContentTransport` for an in-process
555
+ * `KnowledgeSystem`.
556
+ *
557
+ * Reads go straight to `kb.views` (resource lookup) + `kb.content`
558
+ * (byte retrieval). No network, no auth — local mode runs as a single
559
+ * host-process identity.
560
+ *
561
+ * `putBinary` is intentionally not implemented in Phase 2: in-process
562
+ * resource creation is exercised through bus emits (mark/yield
563
+ * namespaces), not multipart upload. If a future caller needs raw
564
+ * binary upload from a local context, wire it through the same
565
+ * resource-creation pipeline the HTTP `/resources` handler uses.
566
+ */
567
+
568
+ declare class LocalContentTransport implements IContentTransport {
569
+ private readonly ks;
570
+ constructor(ks: KnowledgeSystem);
571
+ putBinary(_request: PutBinaryRequest, _options?: {
572
+ auth?: AccessToken;
573
+ }): Promise<{
574
+ resourceId: ResourceId;
575
+ }>;
576
+ getBinary(resourceId: ResourceId, options?: {
577
+ accept?: ContentFormat$1 | string;
578
+ auth?: AccessToken;
579
+ }): Promise<{
580
+ data: ArrayBuffer;
581
+ contentType: string;
582
+ }>;
583
+ getBinaryStream(resourceId: ResourceId, options?: {
584
+ accept?: ContentFormat$1 | string;
585
+ auth?: AccessToken;
586
+ }): Promise<{
587
+ stream: ReadableStream<Uint8Array>;
588
+ contentType: string;
589
+ }>;
590
+ private loadBinary;
591
+ dispose(): void;
592
+ }
593
+
594
+ /**
595
+ * Handles `mark:create-request` — the bus command for creating an annotation.
596
+ *
597
+ * Flow:
598
+ * 1. Assemble the W3C annotation from the request using the injected user DID.
599
+ * 2. Emit `mark:create` with the correlationId threaded through.
600
+ * 3. Stower picks up `mark:create`, appends to the event store (threading
601
+ * correlationId into event metadata), and publishes `mark:added` on the
602
+ * core EventBus.
603
+ * 4. This handler subscribes to `mark:added` and `mark:create-failed`,
604
+ * matches by correlationId, and emits `mark:create-ok` / `mark:create-failed`
605
+ * to the caller only after persistence has actually completed.
606
+ *
607
+ * This is a deferred-ack pattern: the result event attests that Stower has
608
+ * persisted the annotation, not merely that the command was well-formed.
609
+ */
610
+ declare function registerAnnotationAssemblyHandler(eventBus: EventBus, parentLogger: Logger): void;
611
+
612
+ interface Gatherer {
613
+ generateAnnotationSummary(annId: AnnotationId, resId: ResourceId): Promise<Record<string, unknown>>;
614
+ }
615
+ declare function registerAnnotationLookupHandlers(eventBus: EventBus, kb: KnowledgeBase, gatherer: Gatherer, parentLogger: Logger): void;
616
+
617
+ /**
618
+ * Handles `bind:update-body` — the Bind flow's authoritative "apply body
619
+ * operations to an annotation" command. Bind remains a first-class flow
620
+ * despite delegating persistence to Mark — the semantic distinction (Bind =
621
+ * reference linking, Mark = annotation CRUD) is meaningful at the UX and
622
+ * agent-reasoning layers even when the downstream storage event is shared.
623
+ *
624
+ * Flow:
625
+ * 1. Receive bind:update-body with correlationId.
626
+ * 2. Forward to mark:update-body with correlationId threaded through.
627
+ * 3. Stower persists (via EventStore.appendEvent) and publishes mark:body-updated
628
+ * with correlationId in metadata.
629
+ * 4. This handler subscribes to mark:body-updated and mark:body-update-failed,
630
+ * matches by correlationId, and emits bind:body-updated / bind:body-update-failed
631
+ * so the caller learns the real outcome — not an optimistic ack.
632
+ */
633
+ declare function registerBindUpdateBodyHandler(eventBus: EventBus, parentLogger: Logger): void;
634
+
635
+ declare function registerJobCommandHandlers(eventBus: EventBus, jobQueue: JobQueue, parentLogger: Logger): void;
636
+
637
+ /**
638
+ * Bus command handlers — pure bus-event translators that bridge the
639
+ * "request" channels callers emit (`mark:create-request`, `bind:update-body`,
640
+ * `job:create`, `browse:annotation-context-requested`,
641
+ * `gather:summary-requested`) to the underlying make-meaning pipeline
642
+ * (Stower, Browser, Gatherer, JobQueue).
643
+ *
644
+ * These ran in `apps/backend` historically because the HTTP gateway was
645
+ * the only consumer that needed them. They are not HTTP-specific — moving
646
+ * them here means `LocalTransport` consumers (and any future transport)
647
+ * get the same contract automatically.
648
+ */
649
+
650
+ /**
651
+ * Register all bus command handlers on the make-meaning EventBus. Called
652
+ * during `startMakeMeaning` after the JobQueue and KnowledgeSystem exist.
653
+ */
654
+ declare function registerBusHandlers(eventBus: EventBus, knowledgeSystem: KnowledgeSystem, jobQueue: JobQueue, logger: Logger): void;
655
+
624
656
  /**
625
657
  * Entity Types Bootstrap
626
658
  *
@@ -812,14 +844,12 @@ declare function importBackup(archive: Readable, options: BackupImporterOptions)
812
844
  * {checksum}.{ext} - Content blobs (root level)
813
845
  */
814
846
 
815
- type ResourceDescriptor$2 = components['schemas']['ResourceDescriptor'];
816
- type Annotation$3 = components['schemas']['Annotation'];
817
847
  /** Subset of ViewStorage used by the linked-data exporter. */
818
848
  interface LinkedDataViewReader {
819
849
  getAll(): Promise<Array<{
820
- resource: ResourceDescriptor$2;
850
+ resource: ResourceDescriptor;
821
851
  annotations: {
822
- annotations: Annotation$3[];
852
+ annotations: Annotation[];
823
853
  };
824
854
  }>>;
825
855
  }
@@ -887,19 +917,10 @@ declare function importLinkedData(archive: Readable, options: LinkedDataImporter
887
917
  * — the Stower actor subscribes and handles persistence.
888
918
  *
889
919
  * For create: emits yield:create, awaits yield:created / yield:create-failed.
890
- * For archive/unarchive: emits mark:archive / mark:unarchive on scoped bus.
891
- * For entity type updates: emits mark:update-entity-types.
892
920
  */
893
921
 
894
922
  type ContentFormat = components['schemas']['ContentFormat'];
895
- interface UpdateResourceInput {
896
- resourceId: ResourceId;
897
- userId: UserId;
898
- currentArchived?: boolean;
899
- updatedArchived?: boolean;
900
- currentEntityTypes?: string[];
901
- updatedEntityTypes?: string[];
902
- }
923
+ type Agent$1 = components['schemas']['Agent'];
903
924
  interface CreateResourceInput {
904
925
  name: string;
905
926
  storageUri: string;
@@ -909,16 +930,20 @@ interface CreateResourceInput {
909
930
  language?: string;
910
931
  entityTypes?: string[];
911
932
  creationMethod?: CreationMethod;
933
+ /** Provenance for AI-generated resources: source resource + annotation. */
934
+ generatedFrom?: {
935
+ resourceId?: string;
936
+ annotationId?: string;
937
+ };
938
+ generationPrompt?: string;
939
+ generator?: Agent$1 | Agent$1[];
940
+ isDraft?: boolean;
912
941
  }
913
942
  declare class ResourceOperations {
914
943
  /**
915
944
  * Create a new resource via EventBus → Stower
916
945
  */
917
946
  static createResource(input: CreateResourceInput, userId: UserId, eventBus: EventBus): Promise<ResourceId>;
918
- /**
919
- * Update resource metadata via EventBus → Stower
920
- */
921
- static updateResource(input: UpdateResourceInput, eventBus: EventBus): Promise<void>;
922
947
  }
923
948
 
924
949
  /**
@@ -927,20 +952,21 @@ declare class ResourceOperations {
927
952
  * Business logic for annotation CRUD operations. All writes go through the
928
953
  * EventBus — the Stower actor subscribes and handles persistence.
929
954
  *
930
- * - Create: emits mark:create with full annotation + userId + resourceId
931
- * - Update body: emits mark:update-body
932
- * - Delete: emits mark:delete with annotationId + userId + resourceId
955
+ * In-process callers pass a `UserId` to these operations; the
956
+ * EventBus emits stamp it onto the gateway-injection field `_userId`,
957
+ * matching the wire-side convention so Stower handlers see one shape
958
+ * regardless of where the command originated.
933
959
  */
934
960
 
935
961
  type Agent = components['schemas']['Agent'];
936
- type Annotation$2 = components['schemas']['Annotation'];
962
+
937
963
  type CreateAnnotationRequest = components['schemas']['CreateAnnotationRequest'];
938
964
  type UpdateAnnotationBodyRequest = components['schemas']['UpdateAnnotationBodyRequest'];
939
965
  interface CreateAnnotationResult {
940
- annotation: Annotation$2;
966
+ annotation: Annotation;
941
967
  }
942
968
  interface UpdateAnnotationBodyResult {
943
- annotation: Annotation$2;
969
+ annotation: Annotation;
944
970
  }
945
971
  declare class AnnotationOperations {
946
972
  /**
@@ -964,7 +990,6 @@ declare class AnnotationOperations {
964
990
  * Does NOT touch the graph - graph queries go through GraphContext
965
991
  */
966
992
 
967
- type ResourceDescriptor$1 = components['schemas']['ResourceDescriptor'];
968
993
  interface ListResourcesFilters {
969
994
  search?: string;
970
995
  archived?: boolean;
@@ -973,7 +998,7 @@ declare class ResourceContext {
973
998
  /**
974
999
  * Get resource metadata from view storage
975
1000
  */
976
- static getResourceMetadata(resourceId: ResourceId, kb: KnowledgeBase): Promise<ResourceDescriptor$1 | null>;
1001
+ static getResourceMetadata(resourceId: ResourceId, kb: KnowledgeBase): Promise<ResourceDescriptor | null>;
977
1002
  /**
978
1003
  * List resources, optionally filtered.
979
1004
  *
@@ -984,20 +1009,20 @@ declare class ResourceContext {
984
1009
  * When `search` is unset, falls back to scanning all materialized views.
985
1010
  * (TODO: also push the listing path through the graph for large KBs.)
986
1011
  */
987
- static listResources(filters: ListResourcesFilters | undefined, kb: KnowledgeBase): Promise<ResourceDescriptor$1[]>;
1012
+ static listResources(filters: ListResourcesFilters | undefined, kb: KnowledgeBase): Promise<ResourceDescriptor[]>;
988
1013
  private static sortByDateDesc;
989
1014
  /**
990
1015
  * Add content previews to resources (for search results)
991
1016
  * Retrieves and decodes the first 200 characters of each resource's primary representation
992
1017
  */
993
- static addContentPreviews(resources: ResourceDescriptor$1[], kb: KnowledgeBase): Promise<Array<ResourceDescriptor$1 & {
1018
+ static addContentPreviews(resources: ResourceDescriptor[], kb: KnowledgeBase): Promise<Array<ResourceDescriptor & {
994
1019
  content: string;
995
1020
  }>>;
996
1021
  /**
997
1022
  * Get full content for a resource
998
1023
  * Retrieves and decodes the primary representation
999
1024
  */
1000
- static getResourceContent(resource: ResourceDescriptor$1, kb: KnowledgeBase): Promise<string | undefined>;
1025
+ static getResourceContent(resource: ResourceDescriptor, kb: KnowledgeBase): Promise<string | undefined>;
1001
1026
  }
1002
1027
 
1003
1028
  /**
@@ -1012,7 +1037,7 @@ declare class ResourceContext {
1012
1037
  */
1013
1038
 
1014
1039
  type AnnotationLLMContextResponse = components['schemas']['AnnotationLLMContextResponse'];
1015
- type Annotation$1 = components['schemas']['Annotation'];
1040
+
1016
1041
  type AnnotationContextResponse = components['schemas']['AnnotationContextResponse'];
1017
1042
  type ContextualSummaryResponse = components['schemas']['ContextualSummaryResponse'];
1018
1043
  interface BuildContextOptions {
@@ -1042,7 +1067,7 @@ declare class AnnotationContext {
1042
1067
  * Get all annotations
1043
1068
  * @returns Array of all annotation objects
1044
1069
  */
1045
- static getAllAnnotations(resourceId: ResourceId, kb: KnowledgeBase): Promise<Annotation$1[]>;
1070
+ static getAllAnnotations(resourceId: ResourceId, kb: KnowledgeBase): Promise<Annotation[]>;
1046
1071
  /**
1047
1072
  * Enrich reference annotations with resolved document names
1048
1073
  * Adds _resolvedDocumentName property to annotations that link to documents
@@ -1066,7 +1091,7 @@ declare class AnnotationContext {
1066
1091
  * Get a single annotation by ID
1067
1092
  * O(1) lookup using resource ID to access view storage
1068
1093
  */
1069
- static getAnnotation(annotationId: AnnotationId, resourceId: ResourceId, kb: KnowledgeBase): Promise<Annotation$1 | null>;
1094
+ static getAnnotation(annotationId: AnnotationId, resourceId: ResourceId, kb: KnowledgeBase): Promise<Annotation | null>;
1070
1095
  /**
1071
1096
  * List annotations with optional filtering
1072
1097
  * @param filters - Optional filters like resourceId and type
@@ -1075,7 +1100,7 @@ declare class AnnotationContext {
1075
1100
  static listAnnotations(filters: {
1076
1101
  resourceId?: ResourceId;
1077
1102
  type?: AnnotationCategory;
1078
- } | undefined, kb: KnowledgeBase): Promise<Annotation$1[]>;
1103
+ } | undefined, kb: KnowledgeBase): Promise<Annotation[]>;
1079
1104
  /**
1080
1105
  * Get annotation context (selected text with surrounding context)
1081
1106
  */
@@ -1106,8 +1131,6 @@ declare class AnnotationContext {
1106
1131
  * All methods require graph traversal - must use graph database.
1107
1132
  */
1108
1133
 
1109
- type Annotation = components['schemas']['Annotation'];
1110
- type ResourceDescriptor = components['schemas']['ResourceDescriptor'];
1111
1134
  interface GraphNode {
1112
1135
  id: string;
1113
1136
  type: string;
@@ -1199,4 +1222,4 @@ declare function generateReferenceSuggestions(referenceTitle: string, client: In
1199
1222
  declare const PACKAGE_NAME = "@semiont/make-meaning";
1200
1223
  declare const VERSION = "0.1.0";
1201
1224
 
1202
- export { AnnotationContext, AnnotationOperations, BACKUP_FORMAT, type BackupContentReader, type BackupEventStoreReader, type BackupExporterOptions, type BackupImportResult, type BackupImporterOptions, type BackupManifestHeader, type BackupStreamSummary, Browser, type BuildContextOptions, CloneTokenManager, type ContentBlobResolver, type CreateAnnotationResult, type CreateResourceInput, type CreateResourceResult, FORMAT_VERSION, Gatherer, GraphContext, type GraphEdge, type GraphNode, type GraphRepresentation, type KnowledgeBase, type KnowledgeSystem, LLMContext, type LLMContextOptions, type LinkedDataContentReader, type LinkedDataExporterOptions, type LinkedDataImportResult, type LinkedDataImporterOptions, type LinkedDataViewReader, type ListResourcesFilters, type MakeMeaningConfig, type MakeMeaningService, Matcher, PACKAGE_NAME, type ReplayStats, ResourceContext, ResourceOperations, Smelter, Stower, type UpdateAnnotationBodyResult, type UpdateResourceInput, VERSION, bootstrapEntityTypes, createKnowledgeBase, exportBackup, exportLinkedData, generateReferenceSuggestions, generateResourceSummary, importBackup, importLinkedData, isBackupManifest, readEntityTypesProjection, startMakeMeaning, stopKnowledgeSystem, validateManifestVersion };
1225
+ export { AnnotationContext, AnnotationOperations, BACKUP_FORMAT, type BackupContentReader, type BackupEventStoreReader, type BackupExporterOptions, type BackupImportResult, type BackupImporterOptions, type BackupManifestHeader, type BackupStreamSummary, Browser, type BuildContextOptions, CloneTokenManager, type ContentBlobResolver, type CreateAnnotationResult, type CreateResourceInput, type CreateResourceResult, FORMAT_VERSION, Gatherer$1 as Gatherer, GraphContext, type GraphEdge, type GraphNode, type GraphRepresentation, type KnowledgeBase, type KnowledgeSystem, LLMContext, type LLMContextOptions, type LinkedDataContentReader, type LinkedDataExporterOptions, type LinkedDataImportResult, type LinkedDataImporterOptions, type LinkedDataViewReader, type ListResourcesFilters, LocalContentTransport, LocalTransport, type LocalTransportConfig, type MakeMeaningConfig, type MakeMeaningService, Matcher, PACKAGE_NAME, type ReplayStats, ResourceContext, ResourceOperations, Stower, type UpdateAnnotationBodyResult, VERSION, bootstrapEntityTypes, createKnowledgeBase, exportBackup, exportLinkedData, generateReferenceSuggestions, generateResourceSummary, importBackup, importLinkedData, isBackupManifest, readEntityTypesProjection, registerAnnotationAssemblyHandler, registerAnnotationLookupHandlers, registerBindUpdateBodyHandler, registerBusHandlers, registerJobCommandHandlers, startMakeMeaning, stopKnowledgeSystem, validateManifestVersion };