@semiont/make-meaning 0.5.1 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -115,14 +115,14 @@ graph TB
115
115
  CTM -->|query| KB
116
116
  end
117
117
 
118
- BUS -->|"yield:create, yield:update, yield:mv<br/>mark:create, mark:delete, mark:update-body<br/>mark:add-entity-type, mark:archive, mark:unarchive<br/>mark:update-entity-types, job:start, job:*"| STOWER
118
+ BUS -->|"yield:create, yield:update, yield:mv<br/>mark:create, mark:delete, mark:update-body<br/>frame:add-entity-type, mark:archive, mark:unarchive<br/>mark:update-entity-types, job:start, job:*"| STOWER
119
119
  BUS -->|"browse:resource-requested, browse:resources-requested<br/>browse:annotations-requested, browse:annotation-requested<br/>browse:events-requested, browse:annotation-history-requested<br/>browse:referenced-by-requested, browse:entity-types-requested<br/>browse:directory-requested"| BROWSER
120
120
  BUS -->|"gather:requested<br/>gather:resource-requested"| GATHERER
121
121
  BUS -->|"match:search-requested"| MATCHER
122
122
  BUS -->|"yield:created, mark:created,<br/>mark:body-updated"| SMELTER
123
123
  BUS -->|"yield:clone-token-requested<br/>yield:clone-resource-requested<br/>yield:clone-create"| CTM
124
124
 
125
- STOWER -->|"yield:created, yield:updated, yield:moved<br/>mark:created, mark:deleted, mark:body-updated<br/>mark:entity-type-added, ..."| BUS
125
+ STOWER -->|"yield:created, yield:updated, yield:moved<br/>mark:created, mark:deleted, mark:body-updated<br/>frame:entity-type-added, ..."| BUS
126
126
  BROWSER -->|"browse:resource-result, browse:resources-result<br/>browse:annotations-result, browse:annotation-result<br/>browse:events-result, browse:annotation-history-result<br/>browse:referenced-by-result, browse:entity-types-result<br/>browse:directory-result"| BUS
127
127
  GATHERER -->|"gather:complete, gather:failed<br/>gather:resource-complete, gather:resource-failed"| BUS
128
128
  MATCHER -->|"match:search-results, match:search-failed"| BUS
@@ -170,6 +170,19 @@ const kb = await createKnowledgeBase(eventStore, project, graphDb, logger);
170
170
 
171
171
  The EventBus is created by the backend (or script) and passed into `startMakeMeaning()` as a dependency. Make-meaning does not own or encapsulate the EventBus — it is shared across the entire system.
172
172
 
173
+ ### Pure projection validators
174
+
175
+ The dispatcher in [`src/handlers/job-commands.ts`](src/handlers/job-commands.ts) does projection-validated job creation: when a `mark.assist` (linking) or `yield.fromAnnotation` job arrives with `entityTypes`, the dispatcher validates that every tag is registered; when a tagging job arrives with a `schemaId`, the dispatcher resolves it against the registered tag-schema set.
176
+
177
+ Both rules are pure functions in [`src/views/projection-validators.ts`](src/views/projection-validators.ts):
178
+
179
+ - `resolveTagSchema(schemas, schemaId)` → `{ schema } | { error }` — id lookup with the standard "Tag schema not registered" / "tag-annotation requires schemaId" error formats.
180
+ - `validateEntityTypes(registered, requested)` → `{ ok: true } | { ok: false; unknown }` — set membership check that lists the offending tags in caller order.
181
+
182
+ The dispatcher is the I/O shell: read the projection (via the readers in `src/views/`), pass it to the validator (pure), then either stash the resolved value or rethrow as `job:create-failed`. Validator unit tests run in single-digit milliseconds with no filesystem, no event-bus, no mock JobQueue — the dispatcher integration tests in `__tests__/handlers/job-commands.test.ts` keep the wiring covered.
183
+
184
+ This pattern (functional core, imperative shell) is shared with `@semiont/event-sourcing`'s projection reducers; see [`docs/system/PROJECTION-PATTERN.md`](../../docs/system/PROJECTION-PATTERN.md) for the architectural narrative, the full axiom catalog, and guidance for adding new validators.
185
+
173
186
  ## Documentation
174
187
 
175
188
  - **[Architecture](./docs/architecture.md)** — Actor model, data flow, storage architecture
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { JobQueue } from '@semiont/jobs';
2
2
  import { SemiontProject } from '@semiont/core/node';
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';
3
+ import { GraphServiceConfig, VectorsServiceConfig, EmbeddingServiceConfig, EventBus, Logger, StoredEvent, ResourceId, ResourceDescriptor, AnnotationId, components, ITransport, BaseUrl, ConnectionState, SemiontError, UserDID, EventMap, IContentTransport, PutBinaryRequest, PutBinaryOptions, ContentFormat as ContentFormat$1, AccessToken, 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';
@@ -8,6 +8,7 @@ import { GraphDatabase } from '@semiont/graph';
8
8
  import { VectorStore, EmbeddingProvider } from '@semiont/vectors';
9
9
  import { InferenceClient } from '@semiont/inference';
10
10
  import { BehaviorSubject, Observable } from 'rxjs';
11
+ import { StateUnit, WorkerBus } from '@semiont/sdk';
11
12
  import { Writable, Readable } from 'node:stream';
12
13
 
13
14
  /**
@@ -170,8 +171,8 @@ declare class GraphDBConsumer {
170
171
  * - Vectors (semantic search) — via VectorStore (optional, read-only)
171
172
  *
172
173
  * 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.
174
+ * via @semiont/make-meaning/smelter-main. It subscribes to domain events
175
+ * via the EventBus gateway, embeds content, and writes to Qdrant directly.
175
176
  */
176
177
 
177
178
  interface KnowledgeBase {
@@ -213,7 +214,8 @@ declare function createKnowledgeBase(eventStore: EventStore, project: SemiontPro
213
214
  * - mark:update-body → annotation.body.updated → (no result event yet)
214
215
  * - mark:archive → resource.archived (+ file removal) (resource-scoped, no result event)
215
216
  * - mark:unarchive → resource.unarchived (resource-scoped, no result event)
216
- * - mark:add-entity-type → entitytype.added → mark:entity-type-added / mark:entity-type-add-failed
217
+ * - frame:add-entity-type → entitytype.added → frame:entity-type-added / frame:entity-type-add-failed
218
+ * - frame:add-tag-schema → tagschema.added → frame:tag-schema-added / frame:tag-schema-add-failed
217
219
  * - mark:update-entity-types → entitytag.added / entitytag.removed
218
220
  * - job:start → job.started
219
221
  * - job:complete → job.completed
@@ -246,6 +248,7 @@ declare class Stower {
246
248
  private handleMarkArchive;
247
249
  private handleMarkUnarchive;
248
250
  private handleAddEntityType;
251
+ private handleAddTagSchema;
249
252
  private handleUpdateEntityTypes;
250
253
  private handleJobStart;
251
254
  private handleJobComplete;
@@ -365,6 +368,7 @@ declare class Matcher {
365
368
  * - browse:annotation-history-requested — annotation event history
366
369
  * - browse:referenced-by-requested — find annotations in the KB graph that reference a resource
367
370
  * - browse:entity-types-requested — list entity types from the project projection
371
+ * - browse:tag-schemas-requested — list tag schemas from the project projection
368
372
  * - browse:directory-requested — list a project directory, merging fs + ViewStorage
369
373
  */
370
374
 
@@ -385,6 +389,7 @@ declare class Browser {
385
389
  private handleBrowseAnnotationHistory;
386
390
  private handleReferencedBy;
387
391
  private handleEntityTypes;
392
+ private handleTagSchemas;
388
393
  private handleBrowseDirectory;
389
394
  stop(): Promise<void>;
390
395
  }
@@ -474,15 +479,13 @@ declare function startMakeMeaning(project: SemiontProject, config: MakeMeaningCo
474
479
  * and forwards each onto `clientBus`.
475
480
  * - The bus reference flows client → transport, never the other way.
476
481
  *
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.
482
+ * LocalTransport implements `ITransport` only. Auth, admin, and exchange
483
+ * (`IBackendOperations`) are HTTP-shaped concepts that don't apply
484
+ * in-process local mode runs as a single host-process identity supplied
485
+ * at construction, with no token/credential lifecycle. A `SemiontClient`
486
+ * built over this transport has no `.auth` / `.admin` namespaces.
480
487
  */
481
488
 
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
489
  interface LocalTransportConfig {
487
490
  /**
488
491
  * The in-process knowledge system. Lifetime is owned by the caller —
@@ -512,6 +515,18 @@ interface LocalTransportConfig {
512
515
  declare class LocalTransport implements ITransport {
513
516
  readonly baseUrl: BaseUrl;
514
517
  readonly state$: BehaviorSubject<ConnectionState>;
518
+ private readonly errorsSubject;
519
+ /**
520
+ * Stream of `SemiontError` instances surfaced from transport-mediated
521
+ * round-trips (typed-wire methods on this transport that fail). The
522
+ * in-process implementation does not currently surface errors through
523
+ * this stream — most failures here originate inside the make-meaning
524
+ * actors and surface through bus channels (correlation-ID failures via
525
+ * `busRequest`). The Subject exists to satisfy the `ITransport`
526
+ * contract; future expansion (e.g. transport-level guard failures)
527
+ * can publish into it.
528
+ */
529
+ readonly errors$: Observable<SemiontError>;
515
530
  private readonly bus;
516
531
  private readonly userId;
517
532
  private readonly bridges;
@@ -523,30 +538,6 @@ declare class LocalTransport implements ITransport {
523
538
  stream<K extends keyof EventMap>(channel: K): Observable<EventMap[K]>;
524
539
  subscribeToResource(_resourceId: ResourceId): () => void;
525
540
  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
541
  dispose(): void;
551
542
  }
552
543
 
@@ -568,9 +559,7 @@ declare class LocalTransport implements ITransport {
568
559
  declare class LocalContentTransport implements IContentTransport {
569
560
  private readonly ks;
570
561
  constructor(ks: KnowledgeSystem);
571
- putBinary(_request: PutBinaryRequest, _options?: {
572
- auth?: AccessToken;
573
- }): Promise<{
562
+ putBinary(_request: PutBinaryRequest, _options?: PutBinaryOptions): Promise<{
574
563
  resourceId: ResourceId;
575
564
  }>;
576
565
  getBinary(resourceId: ResourceId, options?: {
@@ -632,7 +621,7 @@ declare function registerAnnotationLookupHandlers(eventBus: EventBus, kb: Knowle
632
621
  */
633
622
  declare function registerBindUpdateBodyHandler(eventBus: EventBus, parentLogger: Logger): void;
634
623
 
635
- declare function registerJobCommandHandlers(eventBus: EventBus, jobQueue: JobQueue, parentLogger: Logger): void;
624
+ declare function registerJobCommandHandlers(eventBus: EventBus, jobQueue: JobQueue, project: SemiontProject, parentLogger: Logger): void;
636
625
 
637
626
  /**
638
627
  * Bus command handlers — pure bus-event translators that bridge the
@@ -651,13 +640,13 @@ declare function registerJobCommandHandlers(eventBus: EventBus, jobQueue: JobQue
651
640
  * Register all bus command handlers on the make-meaning EventBus. Called
652
641
  * during `startMakeMeaning` after the JobQueue and KnowledgeSystem exist.
653
642
  */
654
- declare function registerBusHandlers(eventBus: EventBus, knowledgeSystem: KnowledgeSystem, jobQueue: JobQueue, logger: Logger): void;
643
+ declare function registerBusHandlers(eventBus: EventBus, knowledgeSystem: KnowledgeSystem, jobQueue: JobQueue, project: SemiontProject, logger: Logger): void;
655
644
 
656
645
  /**
657
646
  * Entity Types Bootstrap
658
647
  *
659
648
  * On startup, seeds the KB with DEFAULT_ENTITY_TYPES by emitting
660
- * mark:add-entity-type for each missing type. Reads the __system__ event
649
+ * frame:add-entity-type for each missing type. Reads the __system__ event
661
650
  * stream (the durable source of truth in .semiont/events/) to determine
662
651
  * which types already exist.
663
652
  *
@@ -673,7 +662,7 @@ declare function registerBusHandlers(eventBus: EventBus, knowledgeSystem: Knowle
673
662
 
674
663
  /**
675
664
  * Bootstrap entity types if any are missing from the event log.
676
- * Reads the __system__ stream to find existing mark:entity-type-added events,
665
+ * Reads the __system__ stream to find existing frame:entity-type-added events,
677
666
  * then emits only the missing ones.
678
667
  */
679
668
  declare function bootstrapEntityTypes(eventBus: EventBus, eventStore: EventStore, logger?: Logger): Promise<void>;
@@ -690,6 +679,36 @@ declare function bootstrapEntityTypes(eventBus: EventBus, eventStore: EventStore
690
679
  */
691
680
  declare function readEntityTypesProjection(project: SemiontProject): Promise<string[]>;
692
681
 
682
+ /**
683
+ * SmelterActorStateUnit — domain-event fan-in for the Smelter worker.
684
+ *
685
+ * Subscribes to the six smelter-relevant channels on a shared bus and
686
+ * exposes them as a single typed `events$` stream. Transport-neutral —
687
+ * the caller passes a `WorkerBus` (HTTP `ActorStateUnit` today, an in-process
688
+ * bus shim if/when one exists). The state unit does not own the bus and does
689
+ * not dispose it.
690
+ *
691
+ * `start()` widens the bus's channel-subscription set to include the
692
+ * smelter channels. On HTTP this extends the SSE subscription URL;
693
+ * on an in-process bus this is a no-op (the underlying `EventBus`
694
+ * already delivers every emit).
695
+ */
696
+
697
+ interface SmelterEvent {
698
+ type: string;
699
+ resourceId?: string;
700
+ payload: Record<string, unknown>;
701
+ }
702
+ interface SmelterActorStateUnitOptions {
703
+ bus: WorkerBus;
704
+ }
705
+ interface SmelterActorStateUnit extends StateUnit {
706
+ events$: Observable<SmelterEvent>;
707
+ emit(channel: string, payload: Record<string, unknown>): Promise<void>;
708
+ start(): void;
709
+ }
710
+ declare function createSmelterActorStateUnit(options: SmelterActorStateUnitOptions): SmelterActorStateUnit;
711
+
693
712
  /**
694
713
  * Exchange Format Manifest Types
695
714
  *
@@ -901,7 +920,7 @@ interface LinkedDataImportResult {
901
920
  * 1. Stream and decompress tar.gz entries
902
921
  * 2. Parse .semiont/manifest.jsonld → validate format
903
922
  * 3. Build blob resolver over root-level content entries
904
- * 4. Add entity types from manifest via mark:add-entity-type
923
+ * 4. Add entity types from manifest via frame:add-entity-type
905
924
  * 5. For each .semiont/resources/{id}.jsonld:
906
925
  * a. Parse JSON-LD document
907
926
  * b. Resolve content blob by checksum from representations
@@ -1222,4 +1241,4 @@ declare function generateReferenceSuggestions(referenceTitle: string, client: In
1222
1241
  declare const PACKAGE_NAME = "@semiont/make-meaning";
1223
1242
  declare const VERSION = "0.1.0";
1224
1243
 
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 };
1244
+ 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, type SmelterActorStateUnit, type SmelterActorStateUnitOptions, type SmelterEvent, Stower, type UpdateAnnotationBodyResult, VERSION, bootstrapEntityTypes, createKnowledgeBase, createSmelterActorStateUnit, exportBackup, exportLinkedData, generateReferenceSuggestions, generateResourceSummary, importBackup, importLinkedData, isBackupManifest, readEntityTypesProjection, registerAnnotationAssemblyHandler, registerAnnotationLookupHandlers, registerBindUpdateBodyHandler, registerBusHandlers, registerJobCommandHandlers, startMakeMeaning, stopKnowledgeSystem, validateManifestVersion };