@semiont/core 0.5.0 → 0.5.2
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 +1 -1
- package/dist/index.d.ts +164 -85
- package/dist/index.js +47 -42
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/branded-types.ts","../src/creation-methods.ts","../src/identifiers.ts","../src/persisted-events.ts","../src/bus-protocol.ts","../src/event-utils.ts","../src/event-bus.ts","../src/operators/burst-buffer.ts","../src/serialize-per-key.ts","../src/logger.ts","../src/bus-log.ts","../src/annotation-utils.ts","../src/id-generation.ts","../src/annotation-assembly.ts","../src/web-annotation-utils.ts","../src/resource-utils.ts","../src/bridged-channels.ts","../src/fuzzy-anchor.ts","../src/locales.ts","../src/svg-utils.ts","../src/text-context.ts","../src/text-encoding.ts","../src/validation.ts","../src/mime-utils.ts","../src/type-guards.ts","../src/errors.ts","../src/did-utils.ts","../src/config/toml-loader.ts","../src/config/environment-validator.ts","../src/config/configuration-error.ts","../src/config/platform-types.ts","../src/index.ts"],"names":["resourceUri","baseUrl","annotationUri","resourceId","pos","context","email","parseToml"],"mappings":";;;;AA0CO,SAAS,MAAM,KAAA,EAAsB;AAAE,EAAA,OAAO,KAAA;AAAgB;AAC9D,SAAS,SAAS,KAAA,EAAyB;AAAE,EAAA,OAAO,KAAA;AAAmB;AACvE,SAAS,iBAAiB,KAAA,EAAiC;AAAE,EAAA,OAAO,KAAA;AAA2B;AAC/F,SAAS,YAAY,KAAA,EAA4B;AAAE,EAAA,OAAO,KAAA;AAAsB;AAChF,SAAS,aAAa,KAAA,EAA6B;AAAE,EAAA,OAAO,KAAA;AAAuB;AACnF,SAAS,SAAS,KAAA,EAAyB;AAAE,EAAA,OAAO,KAAA;AAAmB;AACvE,SAAS,WAAW,KAAA,EAA2B;AAAE,EAAA,OAAO,KAAA;AAAqB;AAC7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AAA,CAAK,KAAA,GAAQ,KAAA;AAAA,EACf;AAAA,EAXyB,KAAA;AAAA;AAAA;AAAA;AAAA,EAgBhB,QAAA,GAAmB;AAC1B,IAAA,IAAI,MAAA,GAAS,CAAA,OAAA,EAAK,IAAA,CAAK,OAAO,CAAA,CAAA;AAC9B,IAAA,IAAI,KAAK,WAAA,EAAa;AACpB,MAAA,MAAA,IAAU;AAAA,gBAAA,EAAqB,KAAK,WAAW,CAAA,CAAA;AAAA,IACjD;AACA,IAAA,IAAI,KAAK,UAAA,EAAY;AACnB,MAAA,MAAA,IAAU;AAAA,yBAAA,EAAuB,KAAK,UAAU,CAAA,CAAA;AAAA,IAClD;AACA,IAAA,OAAO,MAAA;AAAA,EACT;AACF;;;ACbO,SAAS,oBAAoB,KAAA,EAAsC;AACxE,EAAA,OAAO,CAAC,KAAA,EAAO,WAAA,EAAa,SAAS,UAAU,CAAA,CAAE,SAAS,KAAK,CAAA;AACjE;AAOO,SAAS,mBAAA,GAAsC;AACpD,EAAA,OAAO,CAAC,KAAA,EAAO,WAAA,EAAa,OAAA,EAAS,UAAU,CAAA;AACjD;;;ACoTO,IAAM,kBAAA,GAAqB;AAC3B,IAAM,WAAA,GAAc","file":"index.js","sourcesContent":["/**\n * Branded string types for compile-time type safety\n *\n * These types are zero-cost at runtime but prevent mixing\n * different string types at compile time.\n */\n\nimport type { components } from './types';\n\n// ============================================================================\n// OPENAPI-GENERATED TYPES (use directly from spec)\n// ============================================================================\n\nexport type Motivation = components['schemas']['Motivation'];\nexport type ContentFormat = components['schemas']['ContentFormat'];\n\n// ============================================================================\n// AUTHENTICATION & TOKENS\n// ============================================================================\n\nexport type Email = string & { readonly __brand: 'Email' };\nexport type AuthCode = string & { readonly __brand: 'AuthCode' };\nexport type GoogleCredential = string & { readonly __brand: 'GoogleCredential' };\nexport type AccessToken = string & { readonly __brand: 'AccessToken' };\nexport type RefreshToken = string & { readonly __brand: 'RefreshToken' };\nexport type MCPToken = string & { readonly __brand: 'MCPToken' };\nexport type CloneToken = string & { readonly __brand: 'CloneToken' };\n\n// ============================================================================\n// SYSTEM IDENTIFIERS\n// ============================================================================\n\nexport type JobId = string & { readonly __brand: 'JobId' };\nexport type UserDID = string & { readonly __brand: 'UserDID' };\nexport type EntityType = string & { readonly __brand: 'EntityType' };\nexport type SearchQuery = string & { readonly __brand: 'SearchQuery' };\nexport type BaseUrl = string & { readonly __brand: 'BaseUrl' };\n\n// ============================================================================\n// HELPER FUNCTIONS (minimal validation, just branding)\n// ============================================================================\n\nexport function email(value: string): Email { return value as Email; }\nexport function authCode(value: string): AuthCode { return value as AuthCode; }\nexport function googleCredential(value: string): GoogleCredential { return value as GoogleCredential; }\nexport function accessToken(value: string): AccessToken { return value as AccessToken; }\nexport function refreshToken(value: string): RefreshToken { return value as RefreshToken; }\nexport function mcpToken(value: string): MCPToken { return value as MCPToken; }\nexport function cloneToken(value: string): CloneToken { return value as CloneToken; }\nexport function jobId(value: string): JobId { return value as JobId; }\nexport function userDID(value: string): UserDID { return value as UserDID; }\nexport function entityType(value: string): EntityType { return value as EntityType; }\nexport function searchQuery(value: string): SearchQuery { return value as SearchQuery; }\nexport function baseUrl(value: string): BaseUrl { return value as BaseUrl; }\n\n// Motivation and ContentFormat use OpenAPI enums - no helpers needed\n// Use the enum values directly from the OpenAPI spec\n\n// ============================================================================\n// HTTP URI TYPES\n// ============================================================================\n\n// Branded type definitions for HTTP URIs returned by the API\nexport type ResourceUri = string & { readonly __brand: 'ResourceUri' };\n\n// W3C flat format for content negotiation: http://localhost:4000/annotations/{id}\nexport type AnnotationUri = string & { readonly __brand: 'AnnotationUri' };\n\n// Nested format for CRUD operations: http://localhost:4000/resources/{resourceId}/annotations/{annotationId}\nexport type ResourceAnnotationUri = string & { readonly __brand: 'ResourceAnnotationUri' };\n\n// Factory functions with runtime validation\nexport function resourceUri(uri: string): ResourceUri {\n if (!uri.startsWith('http://') && !uri.startsWith('https://')) {\n throw new TypeError(`Expected ResourceUri, got: ${uri}`);\n }\n return uri as ResourceUri;\n}\n\nexport function annotationUri(uri: string): AnnotationUri {\n if (!uri.startsWith('http://') && !uri.startsWith('https://')) {\n throw new TypeError(`Expected AnnotationUri, got: ${uri}`);\n }\n return uri as AnnotationUri;\n}\n\nexport function resourceAnnotationUri(uri: string): ResourceAnnotationUri {\n if (!uri.startsWith('http://') && !uri.startsWith('https://')) {\n throw new TypeError(`Expected ResourceAnnotationUri, got: ${uri}`);\n }\n // Additional validation: must contain /resources/ and /annotations/\n if (!uri.includes('/resources/') || !uri.includes('/annotations/')) {\n throw new TypeError(`Expected nested ResourceAnnotationUri format, got: ${uri}`);\n }\n return uri as ResourceAnnotationUri;\n}\n","/**\n * Resource creation methods - How resources are created in the system\n */\n\n/**\n * Enumeration of all possible resource creation methods\n */\nexport const CREATION_METHODS = {\n API: 'api',\n UPLOAD: 'upload',\n UI: 'ui',\n REFERENCE: 'reference',\n CLI: 'cli',\n CLONE: 'clone',\n GENERATED: 'generated',\n} as const;\n\n/**\n * Type for resource creation methods\n */\nexport type CreationMethod = typeof CREATION_METHODS[keyof typeof CREATION_METHODS];","/**\n * Branded identifier types for compile-time type safety.\n *\n * These types prevent mixing up resource IDs, annotation IDs, and user IDs\n * at compile time while having zero runtime overhead.\n *\n * URI types (ResourceUri, AnnotationUri) are in @semiont/api-client\n * since they deal with HTTP URIs returned by the API.\n */\n\n// Branded type definitions for IDs only\nexport type ResourceId = string & { readonly __brand: 'ResourceId' };\nexport type AnnotationId = string & { readonly __brand: 'AnnotationId' };\nexport type UserId = string & { readonly __brand: 'UserId' };\n\n// Type guards with runtime validation\nexport function isResourceId(value: string): value is ResourceId {\n return !value.includes('/');\n}\n\nexport function isAnnotationId(value: string): value is AnnotationId {\n return !value.includes('/');\n}\n\n// Factory functions with runtime validation\nexport function resourceId(id: string): ResourceId {\n if (id.includes('/')) {\n throw new TypeError(`Expected ResourceId, got URI: ${id}`);\n }\n return id as ResourceId;\n}\n\nexport function annotationId(id: string): AnnotationId {\n if (id.includes('/')) {\n throw new TypeError(`Expected AnnotationId, got URI: ${id}`);\n }\n return id as AnnotationId;\n}\n\nexport function userId(id: string): UserId {\n return id as UserId;\n}\n","/**\n * Persisted Events\n *\n * The 18 event types that get appended to the JSONL event log.\n * Each maps a type string to its OpenAPI payload schema.\n * The PersistedEvent union derives from this catalog.\n */\n\nimport type { components } from './types';\nimport type { AnnotationId, ResourceId } from './identifiers';\nimport type { Annotation } from './annotation-types';\nimport type { EventBase } from './event-base';\n\n// Branded payload overrides — the OpenAPI schemas reference the raw\n// `Annotation` type with `id: string`. At the TypeScript layer we narrow\n// to the branded `Annotation` so consumers read `payload.annotation.id`\n// as `AnnotationId` without an upcast at every seam.\ntype AnnotationAddedPayload =\n components['schemas']['AnnotationAddedPayload'] & { annotation: Annotation };\ntype AnnotationRemovedPayload =\n components['schemas']['AnnotationRemovedPayload'] & { annotationId: AnnotationId };\ntype AnnotationBodyUpdatedPayload =\n components['schemas']['AnnotationBodyUpdatedPayload'] & { annotationId: AnnotationId };\n\n// ── The Catalog ──────────────────────────────────────────────────────────────\n\n/**\n * Maps each persisted event type string to its OpenAPI payload schema.\n * Single source of truth for \"what events get written to the log.\"\n */\ntype PersistedEventCatalog = {\n 'yield:created': components['schemas']['ResourceCreatedPayload'];\n 'yield:cloned': components['schemas']['ResourceClonedPayload'];\n 'yield:updated': components['schemas']['ResourceUpdatedPayload'];\n 'yield:moved': components['schemas']['ResourceMovedPayload'];\n 'yield:representation-added': components['schemas']['RepresentationAddedPayload'];\n 'yield:representation-removed': components['schemas']['RepresentationRemovedPayload'];\n 'mark:added': AnnotationAddedPayload;\n 'mark:removed': AnnotationRemovedPayload;\n 'mark:body-updated': AnnotationBodyUpdatedPayload;\n 'mark:archived': components['schemas']['ResourceArchivedPayload'];\n 'mark:unarchived': components['schemas']['ResourceUnarchivedPayload'];\n 'mark:entity-tag-added': components['schemas']['EntityTagChangedPayload'];\n 'mark:entity-tag-removed': components['schemas']['EntityTagChangedPayload'];\n 'mark:entity-type-added': components['schemas']['EntityTypeAddedPayload'];\n 'job:started': components['schemas']['JobStartedPayload'];\n 'job:progress': components['schemas']['JobProgressPayload'];\n 'job:completed': components['schemas']['JobCompletedPayload'];\n 'job:failed': components['schemas']['JobFailedPayload'];\n};\n\n// ── Derived types ────────────────────────────────────────────────────────────\n\n/** System event types — persisted events that have no resourceId. */\ntype SystemEventType = 'mark:entity-type-added';\n\n/** Extract the concrete persisted event type for a given type string. */\nexport type EventOfType<K extends keyof PersistedEventCatalog> =\n K extends SystemEventType\n ? EventBase & { type: K; payload: PersistedEventCatalog[K] }\n : EventBase & { type: K; resourceId: ResourceId; payload: PersistedEventCatalog[K] };\n\n/** The union of all 20 persisted event types. Discriminated on `type`. */\nexport type PersistedEvent = {\n [K in keyof PersistedEventCatalog]: EventOfType<K>\n}[keyof PersistedEventCatalog];\n\nexport type PersistedEventType = PersistedEvent['type'];\n\n/**\n * Runtime list of every persisted event type.\n *\n * Single source of truth for code that needs to enumerate event types at\n * runtime — most importantly the per-resource `events-stream` SSE route,\n * which subscribes to all of them. The exhaustiveness check below makes\n * it impossible to add a new member to `PersistedEventCatalog` without\n * also adding it here: forgetting fails to typecheck rather than silently\n * dropping the event from the events-stream.\n */\nexport const PERSISTED_EVENT_TYPES = [\n 'yield:created',\n 'yield:cloned',\n 'yield:updated',\n 'yield:moved',\n 'yield:representation-added',\n 'yield:representation-removed',\n 'mark:added',\n 'mark:removed',\n 'mark:body-updated',\n 'mark:archived',\n 'mark:unarchived',\n 'mark:entity-tag-added',\n 'mark:entity-tag-removed',\n 'mark:entity-type-added',\n 'job:started',\n 'job:progress',\n 'job:completed',\n 'job:failed',\n] as const satisfies readonly PersistedEventType[];\n\n// Compile-time exhaustiveness: if PersistedEventType gains a member that\n// PERSISTED_EVENT_TYPES is missing, this assignment fails to typecheck.\n// The ERROR object names the missing-member case so the build error is\n// self-explanatory.\ntype _ExhaustivePersistedEventTypes =\n Exclude<PersistedEventType, typeof PERSISTED_EVENT_TYPES[number]> extends never\n ? true\n : { ERROR: 'PERSISTED_EVENT_TYPES is missing members of PersistedEventType' };\nconst _persistedEventTypesExhaustive: _ExhaustivePersistedEventTypes = true;\nvoid _persistedEventTypesExhaustive;\n\n/** Input type for appendEvent — PersistedEvent without id/timestamp (assigned at persistence time). */\nexport type EventInput = Omit<PersistedEvent, 'id' | 'timestamp'>;\n","/**\n * Bus Protocol\n *\n * The complete EventMap for the RxJS EventBus. Every channel name and\n * its payload type is defined here — domain events, commands, reads,\n * results, SSE stream payloads, and frontend UI events.\n *\n * Identifier discipline: where a payload carries an annotation or\n * resource id, the TypeScript layer narrows the OpenAPI `string` to the\n * branded type (`AnnotationId`, `ResourceId`, `UserId`). The runtime\n * wire shape is unchanged (brands have no runtime representation);\n * what this buys us is that command handlers don't have to re-brand\n * at every seam. Brand once at the entry boundary (HTTP route handler,\n * DOM attribute read, URL param parse), not at every bus hop in\n * between. See `.plans/BRAND-UPSTREAM.md` for the rationale.\n *\n * Organized by flow (verb), then by category within each flow.\n */\n\nimport type { components } from './types';\nimport type { AnnotationId, ResourceId } from './identifiers';\nimport type { StoredEvent } from './event-base';\nimport type { EventOfType } from './persisted-events';\n\n// Branded overrides for OpenAPI command payloads that carry identifier\n// fields. Narrows `string` → branded at the TypeScript layer.\n//\n// `_userId` is the gateway-injected authenticated DID (string at the\n// schema layer); handlers that need a `UserId` brand it locally.\ntype MarkDeleteCommand =\n components['schemas']['MarkDeleteCommand'] & {\n annotationId: AnnotationId;\n resourceId?: ResourceId;\n };\ntype MarkUpdateBodyCommand =\n components['schemas']['MarkUpdateBodyCommand'] & {\n annotationId: AnnotationId;\n resourceId: ResourceId;\n };\ntype BindInitiateCommand =\n components['schemas']['BindInitiateCommand'] & {\n annotationId: AnnotationId;\n resourceId: ResourceId;\n };\ntype BindUpdateBodyCommand =\n components['schemas']['BindUpdateBodyCommand'] & {\n annotationId: AnnotationId;\n resourceId: ResourceId;\n };\n\n/**\n * The unified EventMap — every channel on the EventBus.\n *\n * Convention:\n * - Domain events (past tense): StoredEvent<Interface> — branded types\n * - Commands/reads/results/UI: OpenAPI schema refs — plain strings\n * - void: UI-only signals with no payload\n */\nexport type EventMap = {\n\n // ========================================================================\n // YIELD FLOW — resource creation, update, move, clone\n // ========================================================================\n\n // Domain events (branded — system of record)\n 'yield:created': StoredEvent<EventOfType<'yield:created'>>;\n 'yield:cloned': StoredEvent<EventOfType<'yield:cloned'>>;\n 'yield:updated': StoredEvent<EventOfType<'yield:updated'>>;\n 'yield:moved': StoredEvent<EventOfType<'yield:moved'>>;\n 'yield:representation-added': StoredEvent<EventOfType<'yield:representation-added'>>;\n 'yield:representation-removed': StoredEvent<EventOfType<'yield:representation-removed'>>;\n\n // Generation lifecycle flows through the unified job:* family\n // (job:start, job:report-progress, job:complete, job:fail). The\n // pre-unification `yield:progress`/`yield:finished`/`yield:failed`\n // channels were removed on the lifecycle-unification.\n\n // Commands\n 'yield:request': components['schemas']['YieldRequestCommand'];\n 'yield:create': components['schemas']['YieldCreateCommand'];\n 'yield:update': components['schemas']['YieldUpdateCommand'];\n 'yield:mv': components['schemas']['YieldMvCommand'];\n 'yield:clone': void;\n 'yield:clone-token-requested': components['schemas']['YieldCloneTokenRequest'];\n 'yield:clone-resource-requested': components['schemas']['YieldCloneResourceRequest'];\n 'yield:clone-create': components['schemas']['YieldCloneCreateCommand'];\n\n // Command results\n 'yield:create-ok': components['schemas']['YieldCreateOk'];\n 'yield:create-failed': components['schemas']['CommandError'];\n 'yield:update-ok': components['schemas']['YieldUpdateOk'];\n 'yield:update-failed': components['schemas']['YieldUpdateOk'] & components['schemas']['CommandError'];\n 'yield:move-ok': components['schemas']['YieldMoveOk'];\n 'yield:move-failed': { fromUri: string } & components['schemas']['CommandError'];\n 'yield:clone-token-generated': { correlationId: string; response: components['schemas']['CloneResourceWithTokenResponse'] };\n 'yield:clone-token-failed': { correlationId: string } & components['schemas']['CommandError'];\n 'yield:clone-resource-result': { correlationId: string; response: components['schemas']['GetResourceByTokenResponse'] };\n 'yield:clone-resource-failed': { correlationId: string } & components['schemas']['CommandError'];\n 'yield:clone-created': components['schemas']['YieldCloneCreated'];\n 'yield:clone-create-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n // ========================================================================\n // MARK FLOW — annotation CRUD, entity types, AI assist\n // ========================================================================\n\n // Domain events (branded — system of record)\n 'mark:added': StoredEvent<EventOfType<'mark:added'>>;\n 'mark:removed': StoredEvent<EventOfType<'mark:removed'>>;\n 'mark:body-updated': StoredEvent<EventOfType<'mark:body-updated'>>;\n 'mark:entity-tag-added': StoredEvent<EventOfType<'mark:entity-tag-added'>>;\n 'mark:entity-tag-removed': StoredEvent<EventOfType<'mark:entity-tag-removed'>>;\n 'mark:entity-type-added': StoredEvent<EventOfType<'mark:entity-type-added'>>;\n 'mark:archived': StoredEvent<EventOfType<'mark:archived'>>;\n 'mark:unarchived': StoredEvent<EventOfType<'mark:unarchived'>>;\n\n // Annotation-job lifecycle flows through the unified job:* family\n // (job:start, job:report-progress, job:complete, job:fail). UI\n // consumers filter by jobType. The pre-unification channels\n // `mark:progress`/`mark:assist-finished`/`mark:assist-failed` were\n // removed on the lifecycle-unification.\n\n // Commands\n 'mark:create-request': components['schemas']['MarkCreateRequest'];\n 'mark:create': components['schemas']['MarkCreateCommand'];\n 'mark:delete': MarkDeleteCommand;\n 'mark:update-body': MarkUpdateBodyCommand;\n 'mark:archive': components['schemas']['MarkArchiveCommand'];\n 'mark:unarchive': components['schemas']['MarkUnarchiveCommand'];\n 'mark:update-entity-types': components['schemas']['MarkUpdateEntityTypesCommand'];\n 'mark:add-entity-type': components['schemas']['MarkAddEntityTypeCommand'];\n\n // Command results\n 'mark:create-ok': components['schemas']['MarkCreateOk'];\n 'mark:create-failed': components['schemas']['CommandError'];\n 'mark:delete-ok': components['schemas']['MarkDeleteOk'];\n 'mark:delete-failed': components['schemas']['CommandError'];\n 'mark:body-update-failed': components['schemas']['CommandError'];\n 'mark:entity-type-add-failed': components['schemas']['CommandError'];\n\n // UI events\n 'mark:select-comment': components['schemas']['SelectionData'];\n 'mark:select-tag': components['schemas']['SelectionData'];\n 'mark:select-assessment': components['schemas']['SelectionData'];\n 'mark:select-reference': components['schemas']['SelectionData'];\n 'mark:requested': components['schemas']['MarkRequestedEvent'];\n 'mark:cancel-pending': void;\n 'mark:submit': components['schemas']['MarkSubmitEvent'];\n 'mark:assist-request': components['schemas']['MarkAssistRequestEvent'];\n 'mark:assist-cancelled': void;\n 'mark:progress-dismiss': void;\n 'mark:mode-toggled': void;\n 'mark:selection-changed': components['schemas']['MarkSelectionChangedEvent'];\n 'mark:click-changed': components['schemas']['MarkClickChangedEvent'];\n 'mark:shape-changed': components['schemas']['MarkShapeChangedEvent'];\n\n // ========================================================================\n // BIND FLOW — reference linking\n // ========================================================================\n\n 'bind:initiate': BindInitiateCommand;\n 'bind:update-body': BindUpdateBodyCommand;\n 'bind:body-updated': components['schemas']['BindBodyUpdated'];\n 'bind:body-update-failed': components['schemas']['CommandError'];\n\n // ========================================================================\n // MATCH FLOW — search\n // ========================================================================\n\n 'match:search-requested': components['schemas']['MatchSearchRequest'];\n 'match:search-results': components['schemas']['MatchSearchResult'];\n 'match:search-failed': components['schemas']['MatchSearchFailed'];\n\n // ========================================================================\n // GATHER FLOW — context gathering\n // ========================================================================\n\n 'gather:requested': components['schemas']['GatherAnnotationRequest'];\n 'gather:complete': components['schemas']['GatherAnnotationComplete'];\n 'gather:failed': { correlationId: string; annotationId: string } & components['schemas']['CommandError'];\n 'gather:resource-requested': components['schemas']['GatherResourceRequest'];\n 'gather:resource-complete': components['schemas']['GatherResourceComplete'];\n 'gather:resource-failed': { correlationId: string; resourceId: string } & components['schemas']['CommandError'];\n\n 'gather:summary-requested': components['schemas']['GatherSummaryRequest'];\n 'gather:summary-result': { correlationId: string; response: Record<string, unknown> };\n 'gather:summary-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n // SSE stream payloads\n 'gather:annotation-progress': components['schemas']['GatherProgress'];\n 'gather:annotation-finished': components['schemas']['GatherAnnotationFinished'];\n 'gather:progress': components['schemas']['GatherProgress'];\n 'gather:finished': components['schemas']['GatherFinished'];\n\n // ========================================================================\n // BROWSE FLOW — knowledge base reads + UI navigation\n // ========================================================================\n\n // Reads\n 'browse:resource-requested': components['schemas']['BrowseResourceRequest'];\n 'browse:resource-result': components['schemas']['BrowseResourceResult'];\n 'browse:resource-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n 'browse:resources-requested': components['schemas']['BrowseResourcesRequest'];\n 'browse:resources-result': components['schemas']['BrowseResourcesResult'];\n 'browse:resources-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n 'browse:annotations-requested': components['schemas']['BrowseAnnotationsRequest'];\n 'browse:annotations-result': components['schemas']['BrowseAnnotationsResult'];\n 'browse:annotations-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n 'browse:annotation-requested': components['schemas']['BrowseAnnotationRequest'];\n 'browse:annotation-result': components['schemas']['BrowseAnnotationResult'];\n 'browse:annotation-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n 'browse:events-requested': components['schemas']['BrowseEventsRequest'];\n 'browse:events-result': components['schemas']['BrowseEventsResult'];\n 'browse:events-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n 'browse:annotation-history-requested': components['schemas']['BrowseAnnotationHistoryRequest'];\n 'browse:annotation-history-result': components['schemas']['BrowseAnnotationHistoryResult'];\n 'browse:annotation-history-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n 'browse:annotation-context-requested': components['schemas']['BrowseAnnotationContextRequest'];\n 'browse:annotation-context-result': { correlationId: string; response: Record<string, unknown> };\n 'browse:annotation-context-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n 'browse:referenced-by-requested': components['schemas']['BrowseReferencedByRequest'];\n 'browse:referenced-by-result': components['schemas']['BrowseReferencedByResult'];\n 'browse:referenced-by-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n 'browse:entity-types-requested': components['schemas']['BrowseEntityTypesRequest'];\n 'browse:entity-types-result': components['schemas']['BrowseEntityTypesResult'];\n 'browse:entity-types-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n 'browse:directory-requested': components['schemas']['BrowseDirectoryRequest'];\n 'browse:directory-result': components['schemas']['BrowseDirectoryResult'];\n 'browse:directory-failed': { correlationId: string; path: string } & components['schemas']['CommandError'];\n\n // UI events (session-scoped — fire on the client bus, tied to a KB)\n 'browse:click': components['schemas']['BrowseClickEvent'];\n 'browse:reference-navigate': components['schemas']['BrowseReferenceNavigateEvent'];\n 'browse:entity-type-clicked': components['schemas']['BrowseEntityTypeClickedEvent'];\n\n // ========================================================================\n // SHELL — app-scoped UI events (fire on SemiontBrowser's bus, not the\n // per-session client bus). These must work regardless of whether a\n // KB session is active: panel toggles, sidebar, tab bar, routing.\n // ========================================================================\n\n 'panel:toggle': components['schemas']['BrowsePanelToggleEvent'];\n 'panel:open': components['schemas']['BrowsePanelOpenEvent'];\n 'panel:close': void;\n 'shell:sidebar-toggle': void;\n 'tabs:close': components['schemas']['BrowseResourceCloseEvent'];\n 'tabs:reorder': components['schemas']['BrowseResourceReorderEvent'];\n 'nav:link-clicked': components['schemas']['BrowseLinkClickedEvent'];\n 'nav:push': components['schemas']['BrowseRouterPushEvent'];\n 'nav:external': components['schemas']['BrowseExternalNavigateEvent'] & { cancelFallback: () => void };\n\n // ========================================================================\n // BECKON FLOW — annotation attention\n // ========================================================================\n\n 'beckon:hover': components['schemas']['BeckonHoverEvent'];\n 'beckon:focus': components['schemas']['BeckonFocusEvent'];\n 'beckon:sparkle': components['schemas']['BeckonSparkleEvent'];\n\n // ========================================================================\n // JOB FLOW — worker commands + domain events\n // ========================================================================\n\n // Domain events (branded — system of record)\n 'job:started': StoredEvent<EventOfType<'job:started'>>;\n 'job:progress': StoredEvent<EventOfType<'job:progress'>>;\n 'job:completed': StoredEvent<EventOfType<'job:completed'>>;\n 'job:failed': StoredEvent<EventOfType<'job:failed'>>;\n\n // Commands\n 'job:start': components['schemas']['JobStartCommand'];\n 'job:report-progress': components['schemas']['JobReportProgressCommand'];\n 'job:complete': components['schemas']['JobCompleteCommand'];\n 'job:fail': components['schemas']['JobFailCommand'];\n 'job:queued': components['schemas']['JobQueuedEvent'];\n 'job:cancel-requested': components['schemas']['JobCancelRequest'];\n 'job:status-requested': components['schemas']['JobStatusRequest'];\n 'job:create': components['schemas']['JobCreateCommand'];\n 'job:claim': components['schemas']['JobClaimCommand'];\n\n // Results\n 'job:status-result': components['schemas']['JobStatusResult'];\n 'job:status-failed': { correlationId: string } & components['schemas']['CommandError'];\n 'job:created': components['schemas']['JobCreatedResult'];\n 'job:create-failed': { correlationId: string } & components['schemas']['CommandError'];\n 'job:claimed': { correlationId: string; response: Record<string, unknown> };\n 'job:claim-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n // ========================================================================\n // SETTINGS (frontend-only)\n // ========================================================================\n\n 'settings:theme-changed': components['schemas']['SettingsThemeChangedEvent'];\n 'settings:line-numbers-toggled': void;\n 'settings:locale-changed': components['schemas']['SettingsLocaleChangedEvent'];\n 'settings:hover-delay-changed': components['schemas']['SettingsHoverDelayChangedEvent'];\n\n // ========================================================================\n // SSE infrastructure\n // ========================================================================\n\n 'stream-connected': Record<string, never>;\n 'replay-window-exceeded': { resourceId?: string; lastEventId: number; missedCount: number; cap: number; message: string };\n /**\n * Emitted by the `/bus/subscribe` handler when a client reconnected\n * with `Last-Event-ID: p-<scope>-<seq>` but the server could not\n * replay all missed persisted events for that scope (retention\n * window exceeded, scope unknown, or request unparseable). The\n * client should treat this as a signal to fall back to the pre-\n * resumption contract: invalidate caches for the affected scope\n * and re-read from scratch. Analogous to `replay-window-exceeded`\n * but scoped to the bus gateway rather than the per-resource\n * events stream.\n *\n * `scope` is the scope string the client asked about (omitted for\n * global-persisted resumption gaps, if that path ever exists).\n * `reason` is human-readable, for logging.\n */\n 'bus:resume-gap': { scope?: string; lastSeenId?: string; reason: string };\n};\n\n/** Any valid channel name on the EventBus. */\nexport type EventName = keyof EventMap;\n\n/**\n * Genuine resource-bound broadcast event types.\n *\n * Publishers emit these on the scoped EventBus (`eventBus.scope(resourceId)`)\n * because every participant viewing the resource should receive them — not\n * just the caller who triggered the originating action. Examples: resource\n * generation progress, which multiple viewers of a generating resource all\n * want to see.\n *\n * Non-broadcast progress (AI-assist progress for one user, search results\n * for one caller) does NOT belong here. Those are per-caller correlation-ID\n * responses and publish globally — the caller filters by `correlationId`.\n *\n * The frontend's `subscribeToResource(id)` wires these channels via\n * `scope=id&scoped=<channel>` so the SSE route delivers them to that\n * participant. WorkerVM uses this list to decide which emitted events to\n * scope to their resource.\n */\n/**\n * Audit note (SIMPLE-BUS Phase 3 close): `yield:progress` was\n * considered for inclusion but has only one consumer — the\n * yield-initiator's Observable in `packages/api-client/src/namespaces/yield.ts`.\n * No viewer of the resource other than the initiator subscribes to\n * progress. Scoping therefore serves no fan-out-narrowing purpose for\n * that channel, so it stays global (as a correlation-ID-shaped\n * response, filtered by `referenceId`). Only `yield:finished` and\n * `yield:failed` have a genuine multi-participant consumer (the\n * ResourceViewerPage toast on the source resource).\n */\nexport const RESOURCE_BROADCAST_TYPES = [\n // Post-unification: job:complete / job:fail carry the \"job ended on\n // this resource\" signal that yield:finished / yield:failed used to.\n // Scope them by resource so every viewer of the affected resource\n // — not just the initiator — can react (toast, refresh, etc.).\n 'job:complete',\n 'job:fail',\n] as const satisfies readonly EventName[];\n\nexport type ResourceBroadcastType = typeof RESOURCE_BROADCAST_TYPES[number];\n\n/**\n * Authoritative map from bus channel to OpenAPI schema name.\n *\n * Every {@link EventName} must appear. The `satisfies` clause below\n * enforces completeness at compile time — adding a channel to\n * {@link EventMap} without adding an entry here is a build error.\n *\n * Values:\n * - `<SchemaName>`: payload validates against `components['schemas'][SchemaName]`.\n * - `null`: no single-schema validation. Used for branded\n * `StoredEvent` wrappers, `void` UI signals, and compound inline\n * types (e.g. `{ correlationId } & CommandError`). These are not\n * validated by `/bus/emit`.\n *\n * The `/bus/emit` route reads this map to validate incoming payloads.\n * Consumers can also use it to do client-side pre-flight validation\n * before emitting.\n */\nexport const CHANNEL_SCHEMAS = {\n // ── YIELD FLOW ──────────────────────────────────────────────────\n 'yield:created': null, // StoredEvent\n 'yield:cloned': null,\n 'yield:updated': null,\n 'yield:moved': null,\n 'yield:representation-added': null,\n 'yield:representation-removed': null,\n 'yield:request': 'YieldRequestCommand',\n 'yield:create': 'YieldCreateCommand',\n 'yield:update': 'YieldUpdateCommand',\n 'yield:mv': 'YieldMvCommand',\n 'yield:clone': null, // void\n 'yield:clone-token-requested': 'YieldCloneTokenRequest',\n 'yield:clone-resource-requested': 'YieldCloneResourceRequest',\n 'yield:clone-create': 'YieldCloneCreateCommand',\n 'yield:create-ok': 'YieldCreateOk',\n 'yield:create-failed': 'CommandError',\n 'yield:update-ok': 'YieldUpdateOk',\n 'yield:update-failed': null, // YieldUpdateOk & CommandError\n 'yield:move-ok': 'YieldMoveOk',\n 'yield:move-failed': null, // { fromUri } & CommandError\n 'yield:clone-token-generated': null, // { correlationId; response: CloneResourceWithTokenResponse }\n 'yield:clone-token-failed': null, // { correlationId } & CommandError\n 'yield:clone-resource-result': null, // { correlationId; response: GetResourceByTokenResponse }\n 'yield:clone-resource-failed': null, // { correlationId } & CommandError\n 'yield:clone-created': 'YieldCloneCreated',\n 'yield:clone-create-failed': null, // { correlationId } & CommandError\n\n // ── MARK FLOW ───────────────────────────────────────────────────\n 'mark:added': null, // StoredEvent\n 'mark:removed': null,\n 'mark:body-updated': null,\n 'mark:entity-tag-added': null,\n 'mark:entity-tag-removed': null,\n 'mark:entity-type-added': null,\n 'mark:archived': null,\n 'mark:unarchived': null,\n 'mark:create-request': 'MarkCreateRequest',\n 'mark:create': 'MarkCreateCommand',\n 'mark:delete': 'MarkDeleteCommand',\n 'mark:update-body': 'MarkUpdateBodyCommand',\n 'mark:archive': 'MarkArchiveCommand',\n 'mark:unarchive': 'MarkUnarchiveCommand',\n 'mark:update-entity-types': 'MarkUpdateEntityTypesCommand',\n 'mark:add-entity-type': 'MarkAddEntityTypeCommand',\n 'mark:create-ok': 'MarkCreateOk',\n 'mark:create-failed': 'CommandError',\n 'mark:delete-ok': 'MarkDeleteOk',\n 'mark:delete-failed': 'CommandError',\n 'mark:body-update-failed': 'CommandError',\n 'mark:entity-type-add-failed': 'CommandError',\n 'mark:select-comment': 'SelectionData',\n 'mark:select-tag': 'SelectionData',\n 'mark:select-assessment': 'SelectionData',\n 'mark:select-reference': 'SelectionData',\n 'mark:requested': 'MarkRequestedEvent',\n 'mark:cancel-pending': null, // void\n 'mark:submit': 'MarkSubmitEvent',\n 'mark:assist-request': 'MarkAssistRequestEvent',\n 'mark:assist-cancelled': null, // void\n 'mark:progress-dismiss': null, // void\n 'mark:mode-toggled': null, // void\n 'mark:selection-changed': 'MarkSelectionChangedEvent',\n 'mark:click-changed': 'MarkClickChangedEvent',\n 'mark:shape-changed': 'MarkShapeChangedEvent',\n\n // ── BIND FLOW ───────────────────────────────────────────────────\n 'bind:initiate': 'BindInitiateCommand',\n 'bind:update-body': 'BindUpdateBodyCommand',\n 'bind:body-updated': 'BindBodyUpdated',\n 'bind:body-update-failed': 'CommandError',\n\n // ── MATCH FLOW ──────────────────────────────────────────────────\n 'match:search-requested': 'MatchSearchRequest',\n 'match:search-results': 'MatchSearchResult',\n 'match:search-failed': 'MatchSearchFailed',\n\n // ── GATHER FLOW ─────────────────────────────────────────────────\n 'gather:requested': 'GatherAnnotationRequest',\n 'gather:complete': 'GatherAnnotationComplete',\n 'gather:failed': null, // { correlationId; annotationId } & CommandError\n 'gather:resource-requested': 'GatherResourceRequest',\n 'gather:resource-complete': 'GatherResourceComplete',\n 'gather:resource-failed': null, // { correlationId; resourceId } & CommandError\n 'gather:summary-requested': 'GatherSummaryRequest',\n 'gather:summary-result': null, // { correlationId; response: Record<string, unknown> }\n 'gather:summary-failed': null, // { correlationId } & CommandError\n 'gather:annotation-progress': 'GatherProgress',\n 'gather:annotation-finished': 'GatherAnnotationFinished',\n 'gather:progress': 'GatherProgress',\n 'gather:finished': 'GatherFinished',\n\n // ── BROWSE FLOW ─────────────────────────────────────────────────\n 'browse:resource-requested': 'BrowseResourceRequest',\n 'browse:resource-result': 'BrowseResourceResult',\n 'browse:resource-failed': null, // { correlationId } & CommandError\n 'browse:resources-requested': 'BrowseResourcesRequest',\n 'browse:resources-result': 'BrowseResourcesResult',\n 'browse:resources-failed': null,\n 'browse:annotations-requested': 'BrowseAnnotationsRequest',\n 'browse:annotations-result': 'BrowseAnnotationsResult',\n 'browse:annotations-failed': null,\n 'browse:annotation-requested': 'BrowseAnnotationRequest',\n 'browse:annotation-result': 'BrowseAnnotationResult',\n 'browse:annotation-failed': null,\n 'browse:events-requested': 'BrowseEventsRequest',\n 'browse:events-result': 'BrowseEventsResult',\n 'browse:events-failed': null,\n 'browse:annotation-history-requested': 'BrowseAnnotationHistoryRequest',\n 'browse:annotation-history-result': 'BrowseAnnotationHistoryResult',\n 'browse:annotation-history-failed': null,\n 'browse:annotation-context-requested': 'BrowseAnnotationContextRequest',\n 'browse:annotation-context-result': null, // { correlationId; response: Record<string, unknown> }\n 'browse:annotation-context-failed': null,\n 'browse:referenced-by-requested': 'BrowseReferencedByRequest',\n 'browse:referenced-by-result': 'BrowseReferencedByResult',\n 'browse:referenced-by-failed': null,\n 'browse:entity-types-requested': 'BrowseEntityTypesRequest',\n 'browse:entity-types-result': 'BrowseEntityTypesResult',\n 'browse:entity-types-failed': null,\n 'browse:directory-requested': 'BrowseDirectoryRequest',\n 'browse:directory-result': 'BrowseDirectoryResult',\n 'browse:directory-failed': null, // { correlationId; path } & CommandError\n 'browse:click': 'BrowseClickEvent',\n 'browse:reference-navigate': 'BrowseReferenceNavigateEvent',\n 'browse:entity-type-clicked': 'BrowseEntityTypeClickedEvent',\n\n // ── SHELL (app-scoped UI events, fire on SemiontBrowser bus) ────\n 'panel:toggle': 'BrowsePanelToggleEvent',\n 'panel:open': 'BrowsePanelOpenEvent',\n 'panel:close': null, // void\n 'shell:sidebar-toggle': null, // void\n 'tabs:close': 'BrowseResourceCloseEvent',\n 'tabs:reorder': 'BrowseResourceReorderEvent',\n 'nav:link-clicked': 'BrowseLinkClickedEvent',\n 'nav:push': 'BrowseRouterPushEvent',\n 'nav:external': null, // includes runtime `cancelFallback: () => void`\n\n // ── BECKON FLOW ─────────────────────────────────────────────────\n 'beckon:hover': 'BeckonHoverEvent',\n 'beckon:focus': 'BeckonFocusEvent',\n 'beckon:sparkle': 'BeckonSparkleEvent',\n\n // ── JOB FLOW ────────────────────────────────────────────────────\n 'job:started': null, // StoredEvent\n 'job:progress': null,\n 'job:completed': null,\n 'job:failed': null,\n 'job:start': 'JobStartCommand',\n 'job:report-progress': 'JobReportProgressCommand',\n 'job:complete': 'JobCompleteCommand',\n 'job:fail': 'JobFailCommand',\n 'job:queued': 'JobQueuedEvent',\n 'job:cancel-requested': 'JobCancelRequest',\n 'job:status-requested': 'JobStatusRequest',\n 'job:create': 'JobCreateCommand',\n 'job:claim': 'JobClaimCommand',\n 'job:status-result': 'JobStatusResult',\n 'job:status-failed': null, // { correlationId } & CommandError\n 'job:created': 'JobCreatedResult',\n 'job:create-failed': null,\n 'job:claimed': null, // { correlationId; response: Record<string, unknown> }\n 'job:claim-failed': null,\n\n // ── SETTINGS (frontend-only) ────────────────────────────────────\n 'settings:theme-changed': 'SettingsThemeChangedEvent',\n 'settings:line-numbers-toggled': null, // void\n 'settings:locale-changed': 'SettingsLocaleChangedEvent',\n 'settings:hover-delay-changed': 'SettingsHoverDelayChangedEvent',\n\n // ── SSE infrastructure ──────────────────────────────────────────\n 'stream-connected': null, // Record<string, never>\n 'replay-window-exceeded': null, // inline payload\n 'bus:resume-gap': null, // inline payload\n} as const satisfies Record<EventName, keyof components['schemas'] | null>;\n\n/** Channels where `/bus/emit` validates the payload (non-null schema). */\nexport type EmittableChannel = {\n [K in EventName]: typeof CHANNEL_SCHEMAS[K] extends null ? never : K\n}[EventName];\n","/**\n * Event Type Guards and Extraction Utilities\n *\n * Domain logic for working with resource events.\n * No React dependencies - safe to use in any JavaScript environment.\n */\n\nimport type { StoredEvent } from './event-base';\nimport type { AnnotationUri } from './branded-types';\n\n/**\n * Minimal event shape accepted by event utility functions.\n * Compatible with both the internal `StoredEvent` type and the OpenAPI-derived\n * schema type (`GetEventsResponse['events'][number]`), which lacks `version`.\n *\n * Flat shape — event fields and metadata are peers (no `event` wrapper).\n */\nexport interface StoredEventLike {\n id: string;\n type: string; // Intentionally loose — accepts OpenAPI-derived types where type is string\n timestamp: string;\n userId: string;\n resourceId?: string;\n payload?: unknown;\n metadata: {\n sequenceNumber: number;\n };\n}\n\n// =============================================================================\n// EVENT TYPE GUARDS AND EXTRACTION\n// =============================================================================\n\n/**\n * Extract annotation ID from event payload\n * Returns null if event is not annotation-related\n *\n * For mark:added: extracts full URI from payload.annotation.id\n * For mark:removed/mark:body-updated: constructs full URI from payload.annotationId (UUID) + resourceId\n */\nexport function getAnnotationUriFromEvent(event: StoredEventLike): AnnotationUri | null {\n const payload = event.payload as Record<string, any> | undefined;\n\n if (event.type === 'mark:added') {\n return payload?.annotation?.id as AnnotationUri || null;\n }\n\n if (event.type === 'mark:removed' || event.type === 'mark:body-updated') {\n if (payload?.annotationId && event.resourceId) {\n try {\n const resourceUri = event.resourceId;\n const baseUrl = resourceUri.substring(0, resourceUri.lastIndexOf('/resources/'));\n return `${baseUrl}/annotations/${payload.annotationId}` as AnnotationUri;\n } catch (e) {\n return null;\n }\n }\n }\n\n return null;\n}\n\n/**\n * Check if an event is related to a specific annotation\n */\nexport function isEventRelatedToAnnotation(event: StoredEventLike, annotationUri: AnnotationUri): boolean {\n const eventAnnotationUri = getAnnotationUriFromEvent(event);\n return eventAnnotationUri === annotationUri;\n}\n\n/**\n * Type guard to check if an object is a StoredEvent (flat shape)\n */\nexport function isStoredEvent(event: any): event is StoredEvent {\n return event &&\n typeof event.id === 'string' &&\n typeof event.timestamp === 'string' &&\n typeof event.type === 'string' &&\n typeof event.metadata === 'object' &&\n typeof event.metadata.sequenceNumber === 'number';\n}\n\n","/**\n * RxJS-based Event Bus\n *\n * Framework-agnostic event bus providing direct access to typed RxJS Subjects.\n *\n * Can be used in Node.js, browser, workers, CLI - anywhere RxJS runs.\n */\n\nimport { Subject } from 'rxjs';\nimport type { EventMap } from './bus-protocol';\nimport type { StoredEvent } from './event-base';\nimport type { PersistedEventType } from './persisted-events';\n\n/**\n * RxJS-based event bus\n *\n * Provides direct access to RxJS Subjects for each event type.\n * Use standard RxJS patterns for emitting and subscribing.\n *\n * @example\n * ```typescript\n * const eventBus = new EventBus();\n *\n * // Emit events\n * eventBus.get('beckon:hover').next({ annotationId: 'ann-1' });\n *\n * // Subscribe to events\n * const subscription = eventBus.get('beckon:hover').subscribe(({ annotationId }) => {\n * console.log('Hover:', annotationId);\n * });\n *\n * // Use RxJS operators\n * import { debounceTime } from 'rxjs/operators';\n * eventBus.get('beckon:hover')\n * .pipe(debounceTime(100))\n * .subscribe(handleHover);\n *\n * // Cleanup\n * subscription.unsubscribe();\n * eventBus.destroy();\n * ```\n */\nexport class EventBus {\n private subjects: Map<keyof EventMap, Subject<any>>;\n private isDestroyed: boolean;\n\n constructor() {\n this.subjects = new Map();\n this.isDestroyed = false;\n }\n\n /**\n * Get the RxJS Subject for an event\n *\n * Returns a typed Subject that can be used with all RxJS operators.\n * Subjects are created lazily on first access.\n *\n * @param eventName - The event name\n * @returns The RxJS Subject for this event\n *\n * @example\n * ```typescript\n * // Emit\n * eventBus.get('beckon:hover').next({ annotationId: 'ann-1' });\n *\n * // Subscribe\n * const sub = eventBus.get('beckon:hover').subscribe(handleHover);\n *\n * // With operators\n * eventBus.get('beckon:hover')\n * .pipe(debounceTime(100), distinctUntilChanged())\n * .subscribe(handleHover);\n * ```\n */\n get<K extends keyof EventMap>(eventName: K): Subject<EventMap[K]> {\n if (this.isDestroyed) {\n throw new Error(`Cannot access event '${String(eventName)}' on destroyed bus`);\n }\n\n if (!this.subjects.has(eventName)) {\n this.subjects.set(eventName, new Subject<EventMap[K]>());\n }\n return this.subjects.get(eventName)!;\n }\n\n /**\n * Get the RxJS Subject for a domain event type (PersistedEventType).\n *\n * Domain event channels carry `StoredEvent`. This method avoids the need\n * for `as keyof EventMap` casts when subscribing to domain event channels\n * using runtime `PersistedEventType` strings.\n */\n getDomainEvent(eventType: PersistedEventType): Subject<StoredEvent> {\n return this.get(eventType as keyof EventMap) as unknown as Subject<StoredEvent>;\n }\n\n /**\n * Destroy the event bus and complete all subjects\n *\n * After calling destroy(), no new events can be emitted or subscribed to.\n * All active subscriptions will be completed.\n */\n destroy(): void {\n if (this.isDestroyed) {\n return;\n }\n\n for (const subject of this.subjects.values()) {\n subject.complete();\n }\n\n this.subjects.clear();\n this.isDestroyed = true;\n }\n\n /**\n * Check if the event bus has been destroyed\n */\n get destroyed(): boolean {\n return this.isDestroyed;\n }\n\n /**\n * Create a resource-scoped event bus\n *\n * Events emitted or subscribed through the scoped bus are isolated to that resource.\n * Internally, events are namespaced but the API remains identical to the parent bus.\n *\n * @param resourceId - Resource identifier to scope events to\n * @returns A scoped event bus for this resource\n *\n * @example\n * ```typescript\n * const eventBus = new EventBus();\n * const resource1 = eventBus.scope('resource-1');\n * const resource2 = eventBus.scope('resource-2');\n *\n * // These are isolated - only resource1 subscribers will fire\n * resource1.get('detection:progress').next({ status: 'started' });\n * ```\n */\n scope(resourceId: string): ScopedEventBus {\n return new ScopedEventBus(this, resourceId);\n }\n}\n\n/**\n * Resource-scoped event bus\n *\n * Provides isolated event streams per resource while maintaining the same API\n * as the parent EventBus. Events are internally namespaced by resourceId.\n */\nexport class ScopedEventBus {\n constructor(\n private parent: EventBus,\n private scopePrefix: string\n ) {}\n\n /**\n * Get the RxJS Subject for a scoped event\n *\n * Returns the same type as the parent bus, but events are isolated to this scope.\n * Internally uses namespaced keys but preserves type safety.\n *\n * @param event - The event name\n * @returns The RxJS Subject for this scoped event\n */\n get<E extends keyof EventMap>(event: E): Subject<EventMap[E]> {\n // Internally namespace the event key, but preserve return type\n const scopedKey = `${this.scopePrefix}:${event as string}`;\n\n // Access parent's subjects map directly (needs cast for private access)\n const parentSubjects = (this.parent as any).subjects as Map<string, Subject<any>>;\n\n if (!parentSubjects.has(scopedKey)) {\n parentSubjects.set(scopedKey, new Subject<EventMap[E]>());\n }\n return parentSubjects.get(scopedKey)!;\n }\n\n /** Get the RxJS Subject for a domain event type on this scoped bus. */\n getDomainEvent(eventType: PersistedEventType): Subject<StoredEvent> {\n return this.get(eventType as keyof EventMap) as unknown as Subject<StoredEvent>;\n }\n\n /**\n * Create a nested scope\n *\n * Allows hierarchical scoping like `resource-1:subsystem-a`\n *\n * @param subScope - Additional scope level\n * @returns A nested scoped event bus\n */\n scope(subScope: string): ScopedEventBus {\n return new ScopedEventBus(this.parent, `${this.scopePrefix}:${subScope}`);\n }\n}\n","/**\n * Adaptive burst buffer RxJS operator.\n *\n * Passes the first event through immediately (zero latency for interactive use).\n * If more events arrive within the burst window, switches to accumulate mode\n * and flushes batches. Returns to passthrough mode after an idle period.\n *\n * Emits individual items (T) in passthrough mode and arrays (T[]) in batch mode.\n * Consumers distinguish via Array.isArray().\n *\n * Threshold tuning:\n * burstWindowMs — How long to wait for more events before flushing a batch.\n * 50ms is a good default: longer than event-loop jitter (~1-5ms)\n * but short enough to feel responsive.\n * maxBatchSize — Force-flush at this size to bound memory. 500 is safe for\n * Neo4j UNWIND queries. Increase if graph writes are cheap.\n * idleTimeoutMs — How long after the last flush before returning to passthrough.\n * 200ms is a good default. Must be >= burstWindowMs.\n *\n * See: BATCH-GRAPH-CONSUMER-RX.md for design rationale.\n * See: packages/graph/docs/ARCHITECTURE.md for graph consumer context.\n */\n\nimport { Observable, OperatorFunction } from 'rxjs';\n\nexport interface BurstBufferOptions {\n /**\n * Time window (ms) to detect burst activity after an event.\n * If another event arrives within this window, it is buffered.\n * The buffer flushes when no new event arrives for this duration (debounce).\n *\n * Recommended: 50ms.\n */\n burstWindowMs: number;\n\n /**\n * Maximum events to accumulate before forcing a flush.\n * Prevents unbounded memory growth during sustained bursts.\n *\n * Recommended: 500.\n */\n maxBatchSize: number;\n\n /**\n * Time (ms) of silence after the last flush before returning to passthrough mode.\n * The next event after this timeout emits immediately (leading edge).\n * Must be >= burstWindowMs.\n *\n * Recommended: 200ms.\n */\n idleTimeoutMs: number;\n}\n\n/**\n * Adaptive burst buffer operator.\n *\n * State machine:\n * PASSTHROUGH → event arrives → emit immediately, transition to ACCUMULATING\n * ACCUMULATING → event arrives → buffer it, reset burst timer\n * ACCUMULATING → burst timer fires (no new events for burstWindowMs) → flush buffer as T[]\n * ACCUMULATING → buffer reaches maxBatchSize → flush buffer as T[]\n * After flush → idle timer starts\n * Idle timer fires (no new events for idleTimeoutMs) → transition to PASSTHROUGH\n */\nexport function burstBuffer<T>(\n options: BurstBufferOptions\n): OperatorFunction<T, T | T[]> {\n const { burstWindowMs, maxBatchSize, idleTimeoutMs } = options;\n\n return (source: Observable<T>) =>\n new Observable<T | T[]>((subscriber) => {\n let mode: 'passthrough' | 'accumulating' = 'passthrough';\n let buffer: T[] = [];\n let burstTimer: ReturnType<typeof setTimeout> | null = null;\n let idleTimer: ReturnType<typeof setTimeout> | null = null;\n\n function clearBurstTimer() {\n if (burstTimer !== null) {\n clearTimeout(burstTimer);\n burstTimer = null;\n }\n }\n\n function clearIdleTimer() {\n if (idleTimer !== null) {\n clearTimeout(idleTimer);\n idleTimer = null;\n }\n }\n\n function flush() {\n if (buffer.length === 0) return;\n const batch = buffer;\n buffer = [];\n subscriber.next(batch);\n }\n\n function startIdleTimer() {\n clearIdleTimer();\n idleTimer = setTimeout(() => {\n idleTimer = null;\n mode = 'passthrough';\n }, idleTimeoutMs);\n }\n\n const subscription = source.subscribe({\n next(value: T) {\n clearIdleTimer();\n\n if (mode === 'passthrough') {\n // Leading edge: emit immediately\n subscriber.next(value);\n // Transition to accumulating — next event within burstWindowMs gets buffered\n mode = 'accumulating';\n // Start a burst timer: if nothing else arrives, start idle countdown\n burstTimer = setTimeout(() => {\n burstTimer = null;\n flush(); // flush anything accumulated (normally empty at this point)\n startIdleTimer();\n }, burstWindowMs);\n return;\n }\n\n // mode === 'accumulating'\n buffer.push(value);\n\n // Reset the burst window timer (debounce pattern)\n clearBurstTimer();\n\n if (buffer.length >= maxBatchSize) {\n // Force flush at max batch size\n flush();\n startIdleTimer();\n } else {\n // Debounce: flush after burstWindowMs of silence\n burstTimer = setTimeout(() => {\n burstTimer = null;\n flush();\n startIdleTimer();\n }, burstWindowMs);\n }\n },\n\n error(err) {\n clearBurstTimer();\n clearIdleTimer();\n flush();\n subscriber.error(err);\n },\n\n complete() {\n clearBurstTimer();\n clearIdleTimer();\n flush();\n subscriber.complete();\n },\n });\n\n // Teardown: clean up timers and unsubscribe from source\n return () => {\n clearBurstTimer();\n clearIdleTimer();\n subscription.unsubscribe();\n };\n });\n}\n","/**\n * serializePerKey — run async work serialized per key, parallel across keys.\n *\n * Invariant: two calls with the same `key` run strictly in sequence (the\n * second `work` does not start until the first has settled). Calls with\n * different keys overlap freely.\n *\n * Error isolation: a rejected work function does not poison subsequent\n * tasks for the same key. The next task starts fresh from whatever state\n * the failed task left behind. The rejection still propagates to *this*\n * caller.\n *\n * Registry cleanup: the entry for a key is removed as soon as its chain\n * empties, so the Map stays bounded by the number of keys with work\n * currently in flight, not by the total number of keys ever seen.\n *\n * ## Usage\n *\n * ```ts\n * const chains = new Map<string, Promise<void>>();\n *\n * async function write(resourceId: string, event: Event) {\n * return serializePerKey(resourceId, chains, async () => {\n * // Read-modify-write on a view file. Any two concurrent calls with\n * // the same resourceId will be serialized; different resourceIds\n * // will proceed in parallel.\n * const view = await viewStorage.get(resourceId);\n * applyEvent(view, event);\n * await viewStorage.save(resourceId, view);\n * });\n * }\n * ```\n *\n * ## When to use this vs RxJS `groupBy + concatMap`\n *\n * Use `serializePerKey` when the work arrives as **direct method calls**\n * that need to block the caller until completion. This is the RPC shape\n * — think `EventStore.appendEvent` calling `await views.materializeResource(...)`\n * and needing the view written before any subscriber sees the published\n * event.\n *\n * Use RxJS `groupBy(keyFn) + concatMap(...)` when the work arrives as an\n * **event stream** that a component subscribes to once at startup. This\n * is how `Smelter`, `GraphDBConsumer`, and `Gatherer` serialize their own\n * per-resource work — see their implementations in `packages/make-meaning`.\n *\n * Both patterns solve the same logical problem (\"serialize work per key\").\n * The choice is dictated by whether the caller is awaiting the result.\n */\nexport async function serializePerKey<K, T>(\n key: K,\n chains: Map<K, Promise<void>>,\n work: () => Promise<T>,\n): Promise<T> {\n const prev = chains.get(key) ?? Promise.resolve();\n\n // Chain onto prev, swallowing any error from the previous link so one\n // bad task doesn't poison subsequent ones for the same key. The new\n // link's own errors still propagate to our caller via `await next`.\n let result: T;\n const next = prev\n .catch(() => { /* prior failure doesn't block us */ })\n .then(async () => {\n result = await work();\n });\n\n chains.set(key, next);\n\n try {\n await next;\n return result!;\n } finally {\n // Only clear the entry if we're still the tail. If another caller\n // has already chained onto us, leave it so the chain stays intact.\n if (chains.get(key) === next) {\n chains.delete(key);\n }\n }\n}\n","/**\n * Logger interface for observability\n *\n * This interface is intentionally framework-agnostic to work with any logger\n * (winston, pino, bunyan, or simple console).\n *\n * Example usage:\n * ```typescript\n * import winston from 'winston';\n *\n * const logger = winston.createLogger({\n * level: 'debug',\n * transports: [new winston.transports.Console()]\n * });\n *\n * const service = new MyService(logger);\n * ```\n */\nexport interface Logger {\n debug(message: string, meta?: any): void;\n info(message: string, meta?: any): void;\n warn(message: string, meta?: any): void;\n error(message: string, meta?: any): void;\n child(meta: Record<string, any>): Logger;\n}\n\n/**\n * Serialize an error value into a form that JSON.stringify can handle\n * meaningfully.\n *\n * Winston's default JSON formatter serializes `Error` instances as `{}`\n * because `message`, `stack`, and `name` are non-enumerable properties on\n * the Error prototype. That means `logger.error('x', { error })` with a\n * raw Error argument produces useless log lines like\n * `{\"error\":{},\"message\":\"x\",...}`, throwing away the information you\n * actually need to diagnose the failure.\n *\n * This helper extracts the parts you want to see in a log — name,\n * message, stack, and cause — and leaves non-Error values alone (so\n * strings, numbers, and plain objects pass through unchanged).\n *\n * ## Usage\n *\n * ```ts\n * try {\n * await doSomething();\n * } catch (error) {\n * logger.error('Something failed', { error: errField(error) });\n * }\n * ```\n *\n * Use this at every `logger.error` call site that includes an `error`\n * field derived from a catch block. Raw `{ error }` without this helper\n * is almost always a bug.\n */\nexport function errField(error: unknown): unknown {\n if (error instanceof Error) {\n return {\n name: error.name,\n message: error.message,\n stack: error.stack,\n ...(error.cause !== undefined && { cause: errField(error.cause) }),\n };\n }\n return error;\n}\n","/**\n * Bus logging — runtime-toggleable cross-wire visibility.\n *\n * One line per event that crosses a process boundary, in a grep-able\n * format that's symmetric across frontend and backend:\n *\n * [bus EMIT] <channel> [scope=X] [cid=<first8>] <payload>\n * [bus RECV] <channel> [scope=X] [cid=<first8>] <payload>\n * [bus SSE] <channel> [scope=X] [cid=<first8>] <payload>\n *\n * Tier 1 of `.plans/OBSERVABILITY.md`. Forward-compatible with Tier 2:\n * the `cid` printed here is exactly the prefix of the W3C trace-id we\n * adopt later.\n *\n * Cost when disabled: one property read per call, zero allocations.\n *\n * Enable:\n * - Browser: `window.__SEMIONT_BUS_LOG__ = true` (DevTools or e2e init)\n * - Node: `SEMIONT_BUS_LOG=1` in the process env (read at module load)\n */\n\nconst NODE_BUS_LOG =\n typeof process !== 'undefined' && !!process.env?.SEMIONT_BUS_LOG;\n\nexport type BusOp = 'EMIT' | 'RECV' | 'SSE' | 'PUT' | 'GET';\n\nexport function busLogEnabled(): boolean {\n const g = globalThis as { __SEMIONT_BUS_LOG__?: boolean };\n if (g.__SEMIONT_BUS_LOG__) return true;\n return NODE_BUS_LOG;\n}\n\n/**\n * Optional active-span trace-id provider. When a Tier 2 OTel SDK is\n * initialized, `@semiont/observability` registers a provider here that\n * returns the active span's W3C `trace_id`. busLog appends it to each\n * emitted line so the grep-timeline correlates with the span tree in\n * an APM UI.\n *\n * Decoupling: `@semiont/core` does not depend on `@opentelemetry/api`.\n * If no provider is registered (Tier 1-only deployments, or before\n * `initObservabilityNode` runs), the field is omitted from the line —\n * same shape as before this hook existed.\n */\nlet traceIdProvider: (() => string | undefined) | undefined;\n\nexport function setBusLogTraceIdProvider(fn: (() => string | undefined) | undefined): void {\n traceIdProvider = fn;\n}\n\nexport function busLog(\n op: BusOp,\n channel: string,\n payload: unknown,\n scope?: string,\n): void {\n if (!busLogEnabled()) return;\n const cidRaw = (payload as { correlationId?: unknown } | null | undefined)?.correlationId;\n const cid = typeof cidRaw === 'string' ? cidRaw.slice(0, 8) : undefined;\n let traceId: string | undefined;\n if (traceIdProvider) {\n try { traceId = traceIdProvider(); } catch { /* noop */ }\n }\n const tag =\n `[bus ${op}] ${channel}` +\n (scope ? ` scope=${scope}` : '') +\n (cid ? ` cid=${cid}` : '') +\n (traceId ? ` trace=${traceId.slice(0, 8)}` : '');\n // eslint-disable-next-line no-console\n console.debug(tag, payload);\n}\n","/**\n * Annotation body utilities\n *\n * These are the matcher primitives used by the `mark:body-updated` event\n * replay path (ViewMaterializer and GraphDBConsumer) to apply add/remove/\n * replace operations against an annotation body.\n */\n\nimport type { components } from './types';\nimport type { Annotation } from './annotation-types';\n\ntype BodyPurpose = components['schemas']['BodyPurpose'];\n\n/**\n * Identity of a body item for matching purposes.\n *\n * Identity is `type + source` for SpecificResource and `type + value` for\n * TextualBody. `purpose` is OPTIONAL: if the caller provides it, it's\n * included in the match (used to disambiguate same-source bodies under\n * different purposes, per the W3C Web Annotation model). If the caller\n * omits it, the matcher ignores purpose and matches on identity alone.\n *\n * Callers SHOULD provide `purpose` when they know it (e.g., the bind flow\n * always unlinks a `purpose: 'linking'` body) so that future multi-purpose\n * annotations continue to disambiguate correctly. Leaving `purpose`\n * unspecified matches whichever purpose comes first in the body — which is\n * fine today because Semiont annotations currently have at most one body\n * item per (type, source/value) pair.\n */\nexport type BodyItemIdentity =\n | { type: 'SpecificResource'; source: string; purpose?: BodyPurpose }\n | { type: 'TextualBody'; value: string; purpose?: BodyPurpose };\n\n/**\n * Find a body item by identity. Returns the index of the first match, or -1.\n *\n * See `BodyItemIdentity` for matching semantics.\n */\nexport function findBodyItem(\n body: Annotation['body'],\n identity: BodyItemIdentity,\n): number {\n if (!Array.isArray(body)) {\n return -1;\n }\n\n for (let i = 0; i < body.length; i++) {\n const item = body[i];\n\n if (typeof item !== 'object' || item === null || !('type' in item)) {\n continue;\n }\n\n const itemType = (item as { type: unknown }).type;\n if (itemType !== identity.type) {\n continue;\n }\n\n // Identity field match (source or value)\n if (identity.type === 'SpecificResource') {\n if (!('source' in item)) continue;\n const itemSource = (item as { source: unknown }).source;\n if (itemSource !== identity.source) continue;\n } else {\n if (!('value' in item)) continue;\n const itemValue = (item as { value: unknown }).value;\n if (itemValue !== identity.value) continue;\n }\n\n // Purpose match — ONLY if the caller specified one. Omitted purpose\n // means \"any purpose on this identity\", which is what the bind-flow\n // unlinker wants today.\n if (identity.purpose !== undefined) {\n const itemPurpose = (item as { purpose?: unknown }).purpose;\n if (itemPurpose !== identity.purpose) continue;\n }\n\n return i;\n }\n\n return -1;\n}\n","/**\n * ID generation utilities\n */\n\n// crypto.randomUUID() is available as a global in Node 14.17+ and all modern browsers.\n// Declared here because the core package tsconfig uses lib:ES2022 (no dom types).\ndeclare const crypto: { randomUUID(): string };\n\n/**\n * Generate a UUID v4 string (without dashes)\n */\nexport function generateUuid(): string {\n return crypto.randomUUID().replace(/-/g, '');\n}\n","/**\n * Annotation Assembly\n *\n * Pure functions for building W3C Annotations and applying body operations.\n * No EventBus, no persistence — just data transformation.\n */\n\nimport type { components } from './types';\nimport type { Selector } from './payload-types';\nimport type { Annotation } from './annotation-types';\nimport { annotationId } from './identifiers';\nimport { generateUuid } from './id-generation';\n\ntype Agent = components['schemas']['Agent'];\ntype AnnotationBody = components['schemas']['AnnotationBody'];\ntype CreateAnnotationRequest = components['schemas']['CreateAnnotationRequest'];\ntype UpdateAnnotationBodyRequest = components['schemas']['UpdateAnnotationBodyRequest'];\ntype TextPositionSelector = components['schemas']['TextPositionSelector'];\ntype SvgSelector = components['schemas']['SvgSelector'];\ntype FragmentSelector = components['schemas']['FragmentSelector'];\n\nexport interface AssembledAnnotation {\n annotation: Annotation;\n bodyArray: AnnotationBody[];\n}\n\n// =============================================================================\n// Selector utilities used by assembleAnnotation\n// =============================================================================\n\n/**\n * Get TextPositionSelector from a selector (single or array)\n */\nexport function getTextPositionSelector(selector: Selector | Selector[] | undefined): TextPositionSelector | null {\n if (!selector) return null;\n const selectors = Array.isArray(selector) ? selector : [selector];\n const found = selectors.find(s => s.type === 'TextPositionSelector');\n if (!found) return null;\n return found.type === 'TextPositionSelector' ? found : null;\n}\n\n/**\n * Get SvgSelector from a selector (single or array)\n */\nexport function getSvgSelector(selector: Selector | Selector[] | undefined): SvgSelector | null {\n if (!selector) return null;\n const selectors = Array.isArray(selector) ? selector : [selector];\n const found = selectors.find(s => s.type === 'SvgSelector');\n if (!found) return null;\n return found.type === 'SvgSelector' ? found : null;\n}\n\n/**\n * Get FragmentSelector from a selector (single or array)\n */\nexport function getFragmentSelector(selector: Selector | Selector[] | undefined): FragmentSelector | null {\n if (!selector) return null;\n const selectors = Array.isArray(selector) ? selector : [selector];\n const found = selectors.find(s => s.type === 'FragmentSelector');\n if (!found) return null;\n return found.type === 'FragmentSelector' ? found : null;\n}\n\n/**\n * Validate SVG markup for W3C compliance\n *\n * @returns null if valid, error message if invalid\n */\nexport function validateSvgMarkup(svg: string): string | null {\n if (!svg.includes('xmlns=\"http://www.w3.org/2000/svg\"')) {\n return 'SVG must include xmlns=\"http://www.w3.org/2000/svg\" attribute';\n }\n\n if (!svg.includes('<svg') || !svg.includes('</svg>')) {\n return 'SVG must have opening and closing tags';\n }\n\n const shapeElements = ['rect', 'circle', 'ellipse', 'polygon', 'polyline', 'path', 'line'];\n const hasShape = shapeElements.some(shape =>\n svg.includes(`<${shape}`) || svg.includes(`<${shape} `)\n );\n\n if (!hasShape) {\n return 'SVG must contain at least one shape element (rect, circle, ellipse, polygon, polyline, path, or line)';\n }\n\n return null;\n}\n\n// =============================================================================\n// Annotation assembly\n// =============================================================================\n\n/**\n * Build a complete W3C Annotation from a CreateAnnotationRequest.\n *\n * Generates a bare annotation ID (no URL prefix). URIs are constructed\n * at the API boundary when returning responses to clients.\n *\n * Throws on invalid input (missing selector, missing motivation, invalid SVG).\n */\nexport function assembleAnnotation(\n request: CreateAnnotationRequest,\n creator: Agent,\n): AssembledAnnotation {\n const newAnnotationId = annotationId(generateUuid());\n\n // Validate selector: must have TextPositionSelector, SvgSelector, or FragmentSelector\n const posSelector = getTextPositionSelector(request.target.selector);\n const svgSelector = getSvgSelector(request.target.selector);\n const fragmentSelector = getFragmentSelector(request.target.selector);\n\n if (!posSelector && !svgSelector && !fragmentSelector) {\n throw new Error('Either TextPositionSelector, SvgSelector, or FragmentSelector is required for creating annotations');\n }\n\n // Validate SVG markup if SvgSelector is provided\n if (svgSelector) {\n const svgError = validateSvgMarkup(svgSelector.value);\n if (svgError) {\n throw new Error(`Invalid SVG markup: ${svgError}`);\n }\n }\n\n if (!request.motivation) {\n throw new Error('motivation is required');\n }\n\n const now = new Date().toISOString();\n const annotation: Annotation = {\n '@context': 'http://www.w3.org/ns/anno.jsonld' as const,\n 'type': 'Annotation' as const,\n id: newAnnotationId,\n motivation: request.motivation,\n target: request.target,\n body: request.body as Annotation['body'],\n creator,\n created: now,\n modified: now,\n };\n\n const bodyArray = (Array.isArray(request.body) ? request.body : request.body ? [request.body] : []) as AnnotationBody[];\n\n return { annotation, bodyArray };\n}\n\n/**\n * Apply body operations (add/remove/replace) to an annotation's body array.\n * Returns a new array — does not mutate the input.\n */\nexport function applyBodyOperations(\n body: Annotation['body'],\n operations: UpdateAnnotationBodyRequest['operations'],\n): AnnotationBody[] {\n const bodyArray = Array.isArray(body) ? [...body] : [];\n\n for (const op of operations) {\n if (op.op === 'add') {\n const exists = bodyArray.some(item =>\n JSON.stringify(item) === JSON.stringify(op.item)\n );\n if (!exists) {\n bodyArray.push(op.item);\n }\n } else if (op.op === 'remove') {\n const index = bodyArray.findIndex(item =>\n JSON.stringify(item) === JSON.stringify(op.item)\n );\n if (index !== -1) {\n bodyArray.splice(index, 1);\n }\n } else if (op.op === 'replace') {\n const index = bodyArray.findIndex(item =>\n JSON.stringify(item) === JSON.stringify(op.oldItem)\n );\n if (index !== -1) {\n bodyArray[index] = op.newItem;\n }\n }\n }\n\n return bodyArray;\n}\n","/**\n * Annotation and Selector Utilities\n *\n * Pure TypeScript utilities for working with W3C Web Annotations.\n * No React dependencies - safe to use in any JavaScript environment.\n *\n * Body is either empty array (stub) or single SpecificResource (resolved)\n * Body can be array of TextualBody (tagging) + SpecificResource (linking)\n * Target can be simple string IRI or object with source and optional selector\n */\n\nimport type { components } from './types';\nimport type { Selector } from './payload-types';\nimport type { Annotation } from './annotation-types';\n\n// Re-export selector utilities (canonical location is annotation-assembly)\nexport {\n getTextPositionSelector,\n getSvgSelector,\n getFragmentSelector,\n validateSvgMarkup,\n} from './annotation-assembly';\ntype HighlightAnnotation = Annotation;\ntype ReferenceAnnotation = Annotation;\ntype TextPositionSelector = components['schemas']['TextPositionSelector'];\ntype TextQuoteSelector = components['schemas']['TextQuoteSelector'];\ntype SvgSelector = components['schemas']['SvgSelector'];\ntype FragmentSelector = components['schemas']['FragmentSelector'];\n\n// Re-export selector types for convenience\nexport type { TextPositionSelector, TextQuoteSelector, SvgSelector, FragmentSelector, Selector };\n\n/**\n * Get the source from an annotation body (null if stub)\n * Search for SpecificResource in body array\n */\nexport function getBodySource(body: Annotation['body']): string | null {\n if (Array.isArray(body)) {\n // Search for SpecificResource with source\n for (const item of body) {\n if (\n typeof item === 'object' &&\n item !== null &&\n 'type' in item &&\n 'source' in item\n ) {\n const itemType = (item as { type: unknown }).type;\n const itemSource = (item as { source: unknown }).source;\n\n if (itemType === 'SpecificResource' && typeof itemSource === 'string') {\n return itemSource;\n }\n }\n }\n return null; // No SpecificResource found = stub\n }\n\n // Single body object (SpecificResource)\n if (\n typeof body === 'object' &&\n body !== null &&\n 'type' in body &&\n 'source' in body\n ) {\n const bodyType = (body as { type: unknown }).type;\n const bodySource = (body as { source: unknown }).source;\n\n if (bodyType === 'SpecificResource' && typeof bodySource === 'string') {\n return bodySource;\n }\n }\n\n return null;\n}\n\n/**\n * Get the type from an annotation body (returns first body type in array)\n */\nexport function getBodyType(body: Annotation['body']): 'TextualBody' | 'SpecificResource' | null {\n if (Array.isArray(body)) {\n if (body.length === 0) {\n return null;\n }\n // Return type of first body item\n if (typeof body[0] === 'object' && body[0] !== null && 'type' in body[0]) {\n const firstType = (body[0] as { type: unknown }).type;\n if (firstType === 'TextualBody' || firstType === 'SpecificResource') {\n return firstType;\n }\n }\n return null;\n }\n\n // Single body object\n if (typeof body === 'object' && body !== null && 'type' in body) {\n const bodyType = (body as { type: unknown }).type;\n if (bodyType === 'TextualBody' || bodyType === 'SpecificResource') {\n return bodyType;\n }\n }\n\n return null;\n}\n\n/**\n * Check if body is resolved (has a source)\n * Check for SpecificResource in body array\n */\nexport function isBodyResolved(body: Annotation['body']): boolean {\n return getBodySource(body) !== null;\n}\n\n/**\n * Get the source IRI from target (handles both string and object forms)\n */\nexport function getTargetSource(target: Annotation['target']): string {\n if (typeof target === 'string') {\n return target;\n }\n return target.source;\n}\n\n/**\n * Get the selector from target (undefined if string or no selector)\n */\nexport function getTargetSelector(target: Annotation['target']) {\n if (typeof target === 'string') {\n return undefined;\n }\n return target.selector;\n}\n\n/**\n * Check if target has a selector\n */\nexport function hasTargetSelector(target: Annotation['target']): boolean {\n return typeof target !== 'string' && target.selector !== undefined;\n}\n\n/**\n * Type guard to check if an annotation is a highlight\n */\nexport function isHighlight(annotation: Annotation): annotation is HighlightAnnotation {\n return annotation.motivation === 'highlighting';\n}\n\n/**\n * Type guard to check if an annotation is a reference (linking)\n */\nexport function isReference(annotation: Annotation): annotation is ReferenceAnnotation {\n return annotation.motivation === 'linking';\n}\n\n/**\n * Type guard to check if an annotation is an assessment\n */\nexport function isAssessment(annotation: Annotation): annotation is Annotation {\n return annotation.motivation === 'assessing';\n}\n\n/**\n * Type guard to check if an annotation is a comment\n */\nexport function isComment(annotation: Annotation): annotation is Annotation {\n return annotation.motivation === 'commenting';\n}\n\n/**\n * Type guard to check if an annotation is a tag\n */\nexport function isTag(annotation: Annotation): annotation is Annotation {\n return annotation.motivation === 'tagging';\n}\n\n/**\n * Extract comment text from a comment annotation's body\n * @param annotation - The annotation to extract comment text from\n * @returns The comment text, or undefined if not a comment or no text found\n */\nexport function getCommentText(annotation: Annotation): string | undefined {\n if (!isComment(annotation)) return undefined;\n const body = Array.isArray(annotation.body) ? annotation.body[0] : annotation.body;\n if (body && 'value' in body) {\n return body.value;\n }\n return undefined;\n}\n\n/**\n * Type guard to check if a reference annotation is a stub (unresolved)\n * Stub if no SpecificResource in body array\n */\nexport function isStubReference(annotation: Annotation): boolean {\n return isReference(annotation) && !isBodyResolved(annotation.body);\n}\n\n/**\n * Type guard to check if a reference annotation is resolved\n * Resolved if SpecificResource exists in body array\n */\nexport function isResolvedReference(annotation: Annotation): annotation is ReferenceAnnotation {\n return isReference(annotation) && isBodyResolved(annotation.body);\n}\n\n// =============================================================================\n// SELECTOR UTILITIES\n// =============================================================================\n\n/**\n * Get the exact text from a selector (single or array)\n *\n * When selector is an array, tries to find a TextQuoteSelector (which has exact text).\n * TextPositionSelector does not have exact text, only character offsets.\n * Handles undefined selector (when target is a string IRI with no selector)\n */\nexport function getExactText(selector: Selector | Selector[] | undefined): string {\n if (!selector) {\n return ''; // No selector means entire resource\n }\n const selectors = Array.isArray(selector) ? selector : [selector];\n\n // Try to find TextQuoteSelector (has exact text)\n const quoteSelector = selectors.find(s => s.type === 'TextQuoteSelector') as TextQuoteSelector | undefined;\n if (quoteSelector) {\n return quoteSelector.exact;\n }\n\n // No TextQuoteSelector found\n return '';\n}\n\n/**\n * Get the exact text from an annotation's target selector\n * Uses getTargetSelector helper to safely get selector\n */\nexport function getAnnotationExactText(annotation: Annotation): string {\n const selector = getTargetSelector(annotation.target);\n return getExactText(selector as Selector | Selector[] | undefined);\n}\n\n/**\n * Get the primary selector from a selector (single or array)\n *\n * When selector is an array, returns the first selector.\n * When selector is a single object, returns it as-is.\n */\nexport function getPrimarySelector(selector: Selector | Selector[]): Selector {\n if (Array.isArray(selector)) {\n if (selector.length === 0) {\n throw new Error('Empty selector array');\n }\n const first = selector[0];\n if (!first) {\n throw new Error('Invalid selector array');\n }\n return first;\n }\n return selector;\n}\n\n/**\n * Get TextQuoteSelector from a selector (single or array)\n *\n * Returns the first TextQuoteSelector found, or null if none exists.\n */\nexport function getTextQuoteSelector(selector: Selector | Selector[]): TextQuoteSelector | null {\n const selectors = Array.isArray(selector) ? selector : [selector];\n const found = selectors.find(s => s.type === 'TextQuoteSelector');\n if (!found) return null;\n return found.type === 'TextQuoteSelector' ? found : null;\n}\n\n/**\n * Extract bounding box from SVG markup\n *\n * Attempts to extract x, y, width, height from the SVG viewBox or root element.\n * Returns null if bounding box cannot be determined.\n */\nexport function extractBoundingBox(svg: string): { x: number; y: number; width: number; height: number } | null {\n // Try to extract viewBox attribute from SVG element\n const viewBoxMatch = svg.match(/<svg[^>]*viewBox=\"([^\"]+)\"/);\n if (viewBoxMatch) {\n const values = viewBoxMatch[1].split(/\\s+/).map(parseFloat);\n if (values.length === 4 && values.every(v => !isNaN(v))) {\n return {\n x: values[0],\n y: values[1],\n width: values[2],\n height: values[3]\n };\n }\n }\n\n // Try to extract width/height attributes from SVG element (assume x=0, y=0)\n const svgTagMatch = svg.match(/<svg[^>]*>/);\n if (svgTagMatch) {\n const svgTag = svgTagMatch[0];\n const widthMatch = svgTag.match(/width=\"([^\"]+)\"/);\n const heightMatch = svgTag.match(/height=\"([^\"]+)\"/);\n\n if (widthMatch && heightMatch) {\n const width = parseFloat(widthMatch[1]);\n const height = parseFloat(heightMatch[1]);\n\n if (!isNaN(width) && !isNaN(height)) {\n return { x: 0, y: 0, width, height };\n }\n }\n }\n\n return null;\n}\n","/**\n * Helper functions for working with W3C ResourceDescriptor\n */\n\nimport type { components } from './types';\nimport type { ResourceDescriptor } from './graph';\n\ntype Representation = components['schemas']['Representation'];\n\n/**\n * Get the resource ID from @id property\n *\n * @id is always a bare ID (UUID), never a full URI.\n */\nexport function getResourceId(resource: ResourceDescriptor | undefined): string | undefined {\n if (!resource) return undefined;\n return resource['@id'] || undefined;\n}\n\n/**\n * Get the primary representation (first or only representation)\n */\nexport function getPrimaryRepresentation(resource: ResourceDescriptor | undefined): Representation | undefined {\n if (!resource?.representations) return undefined;\n const reps = Array.isArray(resource.representations)\n ? resource.representations\n : [resource.representations];\n return reps[0];\n}\n\n/**\n * Get the media type from the primary representation\n */\nexport function getPrimaryMediaType(resource: ResourceDescriptor | undefined): string | undefined {\n return getPrimaryRepresentation(resource)?.mediaType;\n}\n\n/**\n * Get the checksum from the primary representation\n */\nexport function getChecksum(resource: ResourceDescriptor | undefined): string | undefined {\n return getPrimaryRepresentation(resource)?.checksum;\n}\n\n/**\n * Get the language from the primary representation\n */\nexport function getLanguage(resource: ResourceDescriptor | undefined): string | undefined {\n return getPrimaryRepresentation(resource)?.language;\n}\n\n/**\n * Get storage URI from primary representation\n *\n * @param resource - ResourceDescriptor\n * @returns Storage URI or undefined\n */\nexport function getStorageUri(resource: ResourceDescriptor | undefined): string | undefined {\n return getPrimaryRepresentation(resource)?.storageUri;\n}\n\n/**\n * Get creator agent from wasAttributedTo\n * Handles both single agent and array of agents\n *\n * @param resource - ResourceDescriptor\n * @returns First agent or undefined\n */\nexport function getCreator(resource: ResourceDescriptor | undefined): components['schemas']['Agent'] | undefined {\n if (!resource?.wasAttributedTo) return undefined;\n\n return Array.isArray(resource.wasAttributedTo)\n ? resource.wasAttributedTo[0]\n : resource.wasAttributedTo;\n}\n\n/**\n * Get derived-from URI\n * Handles both single URI and array of URIs\n *\n * @param resource - ResourceDescriptor\n * @returns First derivation URI or undefined\n */\nexport function getDerivedFrom(resource: ResourceDescriptor | undefined): string | undefined {\n if (!resource?.wasDerivedFrom) return undefined;\n\n return Array.isArray(resource.wasDerivedFrom)\n ? resource.wasDerivedFrom[0]\n : resource.wasDerivedFrom;\n}\n\n/**\n * Check if resource is archived (application-specific field)\n *\n * @param resource - ResourceDescriptor\n * @returns True if archived, false otherwise\n */\nexport function isArchived(resource: ResourceDescriptor | undefined): boolean {\n return resource?.archived === true;\n}\n\n/**\n * Get entity types from resource (application-specific field)\n *\n * @param resource - ResourceDescriptor\n * @returns Array of entity types, empty if not set\n */\nexport function getResourceEntityTypes(resource: ResourceDescriptor | undefined): string[] {\n return resource?.entityTypes || [];\n}\n\n/**\n * Check if resource is a draft (application-specific field)\n *\n * @param resource - ResourceDescriptor\n * @returns True if draft, false otherwise\n */\nexport function isDraft(resource: ResourceDescriptor | undefined): boolean {\n return resource?.isDraft === true;\n}\n\n/**\n * Map charset names to Node.js Buffer encoding names\n * Node.js Buffer.toString() supports: 'utf8', 'utf16le', 'latin1', 'base64', 'hex', 'ascii', 'binary', 'ucs2'\n *\n * @param charset - Charset name (e.g., \"UTF-8\", \"ISO-8859-1\", \"Windows-1252\")\n * @returns Node.js BufferEncoding\n */\nexport function getNodeEncoding(charset: string): BufferEncoding {\n const normalized = charset.toLowerCase().replace(/[-_]/g, '');\n\n // Map common charset names to Node.js encodings\n const charsetMap: Record<string, BufferEncoding> = {\n 'utf8': 'utf8',\n 'iso88591': 'latin1',\n 'latin1': 'latin1',\n 'ascii': 'ascii',\n 'usascii': 'ascii',\n 'utf16le': 'utf16le',\n 'ucs2': 'ucs2',\n 'binary': 'binary',\n 'windows1252': 'latin1', // Windows-1252 is a superset of Latin-1\n 'cp1252': 'latin1',\n };\n\n return charsetMap[normalized] || 'utf8';\n}\n\n/**\n * Decode a representation buffer to string using the correct charset\n * Extracts charset from media type and uses appropriate encoding\n *\n * @param buffer - The raw representation data\n * @param mediaType - Media type with optional charset (e.g., \"text/plain; charset=iso-8859-1\")\n * @returns Decoded string\n *\n * @example\n * ```typescript\n * const content = decodeRepresentation(buffer, \"text/plain; charset=utf-8\");\n * const legacy = decodeRepresentation(buffer, \"text/plain; charset=windows-1252\");\n * ```\n */\nexport function decodeRepresentation(buffer: Buffer, mediaType: string): string {\n // Extract charset from mediaType (e.g., \"text/plain; charset=iso-8859-1\")\n const charsetMatch = mediaType.match(/charset=([^\\s;]+)/i);\n const charset = (charsetMatch?.[1] || 'utf-8').toLowerCase();\n\n // Map to Node.js encoding\n const encoding = getNodeEncoding(charset);\n\n return buffer.toString(encoding);\n}\n","/**\n * BRIDGED_CHANNELS\n *\n * The set of bus channels that any concrete transport bridges into the\n * caller-supplied bus via `bridgeInto`. Transport-neutral: every concrete\n * `ITransport` shares the same set; HTTP delivers them via SSE,\n * in-process transports forward them directly from the local actor bus.\n *\n * Note: this is the *fan-in* set — channels for events the transport\n * receives and pushes onto the client's bus. It is not the same as the\n * channels the client emits (which is open-ended).\n *\n * Resource-scoped channels (joined/left via `subscribeToResource`) are\n * tracked separately by transports that care about scope (HTTP).\n */\nexport const BRIDGED_CHANNELS = [\n 'browse:resources-result', 'browse:resources-failed',\n 'browse:resource-result', 'browse:resource-failed',\n 'browse:annotations-result', 'browse:annotations-failed',\n 'browse:annotation-result', 'browse:annotation-failed',\n 'browse:annotation-history-result', 'browse:annotation-history-failed',\n 'browse:events-result', 'browse:events-failed',\n 'browse:referenced-by-result', 'browse:referenced-by-failed',\n 'browse:entity-types-result', 'browse:entity-types-failed',\n 'browse:directory-result', 'browse:directory-failed',\n 'browse:annotation-context-result', 'browse:annotation-context-failed',\n 'mark:delete-ok', 'mark:delete-failed',\n 'mark:create-ok', 'mark:create-failed',\n 'match:search-results', 'match:search-failed',\n 'gather:complete', 'gather:failed',\n 'gather:annotation-progress', 'gather:annotation-finished',\n 'gather:summary-result', 'gather:summary-failed',\n 'bind:body-updated', 'bind:body-update-failed',\n 'job:report-progress', 'job:complete', 'job:fail',\n 'job:status-result', 'job:status-failed',\n 'job:created', 'job:create-failed',\n 'job:claimed', 'job:claim-failed',\n 'yield:clone-token-generated', 'yield:clone-token-failed',\n 'yield:clone-resource-result', 'yield:clone-resource-failed',\n 'yield:clone-created', 'yield:clone-create-failed',\n 'mark:entity-type-added',\n 'beckon:focus', 'beckon:sparkle',\n 'bus:resume-gap',\n] as const;\n\nexport type BridgedChannel = typeof BRIDGED_CHANNELS[number];\n","/**\n * Fuzzy Anchoring for W3C Web Annotation TextQuoteSelector\n *\n * Uses prefix/suffix context to disambiguate when the same text appears multiple times.\n * Implements fuzzy matching as specified in the W3C Web Annotation Data Model.\n *\n * @see https://www.w3.org/TR/annotation-model/#text-quote-selector\n */\n\nexport interface TextPosition {\n start: number;\n end: number;\n}\n\nexport type MatchQuality = 'exact' | 'normalized' | 'case-insensitive' | 'fuzzy';\n\n/**\n * Normalize text for comparison - handles common document editing changes\n *\n * Collapses whitespace, converts curly quotes to straight quotes,\n * and normalizes common punctuation variations.\n */\nexport function normalizeText(text: string): string {\n return text\n .replace(/\\s+/g, ' ') // collapse whitespace\n .replace(/[\\u2018\\u2019]/g, \"'\") // curly single quotes → straight\n .replace(/[\\u201C\\u201D]/g, '\"') // curly double quotes → straight\n .replace(/\\u2014/g, '--') // em-dash → double hyphen\n .replace(/\\u2013/g, '-') // en-dash → hyphen\n .trim();\n}\n\n/**\n * Calculate Levenshtein distance between two strings\n * Used for fuzzy matching when exact text doesn't match\n */\nfunction levenshteinDistance(str1: string, str2: string): number {\n const len1 = str1.length;\n const len2 = str2.length;\n const matrix: number[][] = [];\n\n // Initialize matrix\n for (let i = 0; i <= len1; i++) {\n matrix[i] = [i];\n }\n for (let j = 0; j <= len2; j++) {\n matrix[0]![j] = j;\n }\n\n // Fill matrix\n for (let i = 1; i <= len1; i++) {\n for (let j = 1; j <= len2; j++) {\n const cost = str1[i - 1] === str2[j - 1] ? 0 : 1;\n const deletion = matrix[i - 1]![j]! + 1;\n const insertion = matrix[i]![j - 1]! + 1;\n const substitution = matrix[i - 1]![j - 1]! + cost;\n matrix[i]![j] = Math.min(deletion, insertion, substitution);\n }\n }\n\n return matrix[len1]![len2]!;\n}\n\n/**\n * Pre-computed content strings for batch fuzzy matching.\n * Avoids recomputing normalizeText(content) and content.toLowerCase()\n * for every annotation when processing many annotations against the same content.\n */\nexport interface ContentCache {\n normalizedContent: string;\n lowerContent: string;\n}\n\n/**\n * Build a ContentCache for a given content string.\n * Call once per content, pass to findBestTextMatch/findTextWithContext for all annotations.\n */\nexport function buildContentCache(content: string): ContentCache {\n return {\n normalizedContent: normalizeText(content),\n lowerContent: content.toLowerCase()\n };\n}\n\n/**\n * Find best match for text in content using multi-strategy search\n *\n * Shared core logic used by both findTextWithContext and validateAndCorrectOffsets.\n *\n * @param content - Full text content to search within\n * @param searchText - The text to find\n * @param positionHint - Hint for where to search (TextPositionSelector.start)\n * @param cache - Pre-computed normalized/lowered content (from buildContentCache)\n * @returns Match with position and quality, or null if not found\n */\nexport function findBestTextMatch(\n content: string,\n searchText: string,\n positionHint: number | undefined,\n cache: ContentCache\n): { start: number; end: number; matchQuality: MatchQuality } | null {\n const maxFuzzyDistance = Math.max(5, Math.floor(searchText.length * 0.05)); // 5% tolerance or min 5 chars\n\n // Strategy 1: Exact match (case-sensitive, exact whitespace)\n const exactIndex = content.indexOf(searchText);\n if (exactIndex !== -1) {\n return {\n start: exactIndex,\n end: exactIndex + searchText.length,\n matchQuality: 'exact'\n };\n }\n\n // Strategy 2: Normalized match (handles whitespace/quote variations)\n const normalizedSearch = normalizeText(searchText);\n const normalizedIndex = cache.normalizedContent.indexOf(normalizedSearch);\n if (normalizedIndex !== -1) {\n // Find actual position in original content by counting characters\n let actualPos = 0;\n let normalizedPos = 0;\n while (normalizedPos < normalizedIndex && actualPos < content.length) {\n const char = content[actualPos]!;\n const normalizedChar = normalizeText(char);\n if (normalizedChar) {\n normalizedPos += normalizedChar.length;\n }\n actualPos++;\n }\n return {\n start: actualPos,\n end: actualPos + searchText.length,\n matchQuality: 'normalized'\n };\n }\n\n // Strategy 3: Case-insensitive match\n const lowerSearch = searchText.toLowerCase();\n const caseInsensitiveIndex = cache.lowerContent.indexOf(lowerSearch);\n if (caseInsensitiveIndex !== -1) {\n return {\n start: caseInsensitiveIndex,\n end: caseInsensitiveIndex + searchText.length,\n matchQuality: 'case-insensitive'\n };\n }\n\n // Strategy 4: Fuzzy match using Levenshtein distance with sliding window\n // Search near position hint if provided, otherwise search full content\n const windowSize = searchText.length;\n const searchRadius = Math.min(500, content.length);\n const searchStart = positionHint !== undefined\n ? Math.max(0, positionHint - searchRadius)\n : 0;\n const searchEnd = positionHint !== undefined\n ? Math.min(content.length, positionHint + searchRadius)\n : content.length;\n\n let bestMatch: { start: number; distance: number } | null = null;\n\n // Scan through content with sliding window\n for (let i = searchStart; i <= searchEnd - windowSize; i++) {\n const candidate = content.substring(i, i + windowSize);\n const distance = levenshteinDistance(searchText, candidate);\n\n if (distance <= maxFuzzyDistance) {\n if (!bestMatch || distance < bestMatch.distance) {\n bestMatch = { start: i, distance };\n }\n }\n }\n\n if (bestMatch) {\n return {\n start: bestMatch.start,\n end: bestMatch.start + windowSize,\n matchQuality: 'fuzzy'\n };\n }\n\n return null;\n}\n\n/**\n * Find text using exact match with optional prefix/suffix context\n *\n * When the exact text appears multiple times in the content, prefix and suffix\n * are used to disambiguate and find the correct occurrence.\n *\n * If exact text is not found, uses multi-strategy fuzzy matching (normalization,\n * case-insensitive, Levenshtein distance) to locate changed text.\n *\n * @param content - Full text content to search within\n * @param exact - The exact text to find\n * @param prefix - Optional text that should appear immediately before the match\n * @param suffix - Optional text that should appear immediately after the match\n * @param positionHint - Optional position hint (from TextPositionSelector) for fuzzy search\n * @returns Position of the matched text, or null if not found\n *\n * @example\n * ```typescript\n * const content = \"The cat sat. The cat ran.\";\n * // Find second \"The cat\" occurrence\n * const pos = findTextWithContext(content, \"The cat\", \"sat. \", \" ran\");\n * // Returns { start: 13, end: 20 }\n * ```\n */\nexport function findTextWithContext(\n content: string,\n exact: string,\n prefix: string | undefined,\n suffix: string | undefined,\n positionHint: number | undefined,\n cache: ContentCache\n): TextPosition | null {\n if (!exact) return null;\n\n // Fast path: if positionHint points directly at the exact text, return immediately\n if (positionHint !== undefined && positionHint >= 0 && positionHint + exact.length <= content.length) {\n if (content.substring(positionHint, positionHint + exact.length) === exact) {\n return { start: positionHint, end: positionHint + exact.length };\n }\n }\n\n // Find all occurrences of exact text\n const occurrences: number[] = [];\n let index = content.indexOf(exact);\n while (index !== -1) {\n occurrences.push(index);\n index = content.indexOf(exact, index + 1);\n }\n\n // No exact matches found - try fuzzy matching\n if (occurrences.length === 0) {\n const fuzzyMatch = findBestTextMatch(content, exact, positionHint, cache);\n\n if (fuzzyMatch) {\n return { start: fuzzyMatch.start, end: fuzzyMatch.end };\n }\n\n return null;\n }\n\n // Only one match - no need for prefix/suffix disambiguation\n if (occurrences.length === 1) {\n const pos = occurrences[0]!; // Safe: length === 1 means first element exists\n return { start: pos, end: pos + exact.length };\n }\n\n // Multiple matches - use prefix/suffix to disambiguate\n if (prefix || suffix) {\n for (const pos of occurrences) {\n // Extract actual prefix from content\n const actualPrefixStart = Math.max(0, pos - (prefix?.length || 0));\n const actualPrefix = content.substring(actualPrefixStart, pos);\n\n // Extract actual suffix from content\n const actualSuffixEnd = Math.min(content.length, pos + exact.length + (suffix?.length || 0));\n const actualSuffix = content.substring(pos + exact.length, actualSuffixEnd);\n\n // Check if prefix matches\n const prefixMatch = !prefix || actualPrefix.endsWith(prefix);\n\n // Check if suffix matches\n const suffixMatch = !suffix || actualSuffix.startsWith(suffix);\n\n if (prefixMatch && suffixMatch) {\n return { start: pos, end: pos + exact.length };\n }\n }\n\n // No match with exact prefix/suffix - try partial prefix/suffix match\n for (const pos of occurrences) {\n const actualPrefix = content.substring(Math.max(0, pos - (prefix?.length || 0)), pos);\n const actualSuffix = content.substring(pos + exact.length, pos + exact.length + (suffix?.length || 0));\n\n // Fuzzy match: check if prefix/suffix are substrings (handles whitespace variations)\n const fuzzyPrefixMatch = !prefix || actualPrefix.includes(prefix.trim());\n const fuzzySuffixMatch = !suffix || actualSuffix.includes(suffix.trim());\n\n if (fuzzyPrefixMatch && fuzzySuffixMatch) {\n return { start: pos, end: pos + exact.length };\n }\n }\n }\n\n // Fallback: return first occurrence if no prefix/suffix or no match\n const pos = occurrences[0]!; // Safe: we checked length > 0 earlier\n return { start: pos, end: pos + exact.length };\n}\n\n/**\n * Verify that a position correctly points to the exact text\n * Useful for debugging and validation\n */\nexport function verifyPosition(\n content: string,\n position: TextPosition,\n expectedExact: string\n): boolean {\n const actualText = content.substring(position.start, position.end);\n return actualText === expectedExact;\n}\n","/**\n * Locale information\n * Copied from SDK for frontend use\n */\n\nexport interface LocaleInfo {\n code: string;\n nativeName: string;\n englishName: string;\n}\n\nexport const LOCALES: readonly LocaleInfo[] = [\n { code: 'ar', nativeName: 'العربية', englishName: 'Arabic' },\n { code: 'bn', nativeName: 'বাংলা', englishName: 'Bengali' },\n { code: 'cs', nativeName: 'Čeština', englishName: 'Czech' },\n { code: 'da', nativeName: 'Dansk', englishName: 'Danish' },\n { code: 'de', nativeName: 'Deutsch', englishName: 'German' },\n { code: 'el', nativeName: 'Ελληνικά', englishName: 'Greek' },\n { code: 'en', nativeName: 'English', englishName: 'English' },\n { code: 'es', nativeName: 'Español', englishName: 'Spanish' },\n { code: 'fa', nativeName: 'فارسی', englishName: 'Persian' },\n { code: 'fi', nativeName: 'Suomi', englishName: 'Finnish' },\n { code: 'fr', nativeName: 'Français', englishName: 'French' },\n { code: 'he', nativeName: 'עברית', englishName: 'Hebrew' },\n { code: 'hi', nativeName: 'हिन्दी', englishName: 'Hindi' },\n { code: 'id', nativeName: 'Bahasa Indonesia', englishName: 'Indonesian' },\n { code: 'it', nativeName: 'Italiano', englishName: 'Italian' },\n { code: 'ja', nativeName: '日本語', englishName: 'Japanese' },\n { code: 'ko', nativeName: '한국어', englishName: 'Korean' },\n { code: 'ms', nativeName: 'Bahasa Melayu', englishName: 'Malay' },\n { code: 'nl', nativeName: 'Nederlands', englishName: 'Dutch' },\n { code: 'no', nativeName: 'Norsk', englishName: 'Norwegian' },\n { code: 'pl', nativeName: 'Polski', englishName: 'Polish' },\n { code: 'pt', nativeName: 'Português', englishName: 'Portuguese' },\n { code: 'ro', nativeName: 'Română', englishName: 'Romanian' },\n { code: 'sv', nativeName: 'Svenska', englishName: 'Swedish' },\n { code: 'th', nativeName: 'ไทย', englishName: 'Thai' },\n { code: 'tr', nativeName: 'Türkçe', englishName: 'Turkish' },\n { code: 'uk', nativeName: 'Українська', englishName: 'Ukrainian' },\n { code: 'vi', nativeName: 'Tiếng Việt', englishName: 'Vietnamese' },\n { code: 'zh', nativeName: '中文', englishName: 'Chinese' },\n] as const;\n\n// Create lookup map for efficient access\nconst localeByCode = new Map<string, LocaleInfo>(\n LOCALES.map(locale => [locale.code.toLowerCase(), locale])\n);\n\n/**\n * Get locale information by code\n */\nexport function getLocaleInfo(code: string | undefined): LocaleInfo | undefined {\n if (!code) return undefined;\n return localeByCode.get(code.toLowerCase());\n}\n\n/**\n * Get the native name of a language by its locale code\n */\nexport function getLocaleNativeName(code: string | undefined): string | undefined {\n return getLocaleInfo(code)?.nativeName;\n}\n\n/**\n * Get the English name of a language by its locale code\n */\nexport function getLocaleEnglishName(code: string | undefined): string | undefined {\n return getLocaleInfo(code)?.englishName;\n}\n\n/**\n * Format locale code for display as \"Native Name (code)\"\n */\nexport function formatLocaleDisplay(code: string | undefined): string | undefined {\n if (!code) return undefined;\n\n const info = getLocaleInfo(code);\n if (!info) return code;\n\n return `${info.nativeName} (${code.toLowerCase()})`;\n}\n\n/**\n * Get all supported locale codes\n */\nexport function getAllLocaleCodes(): readonly string[] {\n return LOCALES.map(l => l.code);\n}\n","/**\n * SVG Utility Functions\n *\n * Utilities for creating, parsing, and manipulating W3C-compliant SVG selectors\n * for image annotation.\n */\n\nexport interface Point {\n x: number;\n y: number;\n}\n\nexport interface BoundingBox {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/**\n * Create W3C-compliant SVG rectangle selector\n */\nexport function createRectangleSvg(start: Point, end: Point): string {\n const x = Math.min(start.x, end.x);\n const y = Math.min(start.y, end.y);\n const width = Math.abs(end.x - start.x);\n const height = Math.abs(end.y - start.y);\n\n return `<svg xmlns=\"http://www.w3.org/2000/svg\"><rect x=\"${x}\" y=\"${y}\" width=\"${width}\" height=\"${height}\"/></svg>`;\n}\n\n/**\n * Create W3C-compliant SVG polygon selector\n */\nexport function createPolygonSvg(points: Point[]): string {\n if (points.length < 3) {\n throw new Error('Polygon requires at least 3 points');\n }\n\n const pointsStr = points.map(p => `${p.x},${p.y}`).join(' ');\n return `<svg xmlns=\"http://www.w3.org/2000/svg\"><polygon points=\"${pointsStr}\"/></svg>`;\n}\n\n/**\n * Create W3C-compliant SVG circle selector\n */\nexport function createCircleSvg(center: Point, radius: number): string {\n if (radius <= 0) {\n throw new Error('Circle radius must be positive');\n }\n\n return `<svg xmlns=\"http://www.w3.org/2000/svg\"><circle cx=\"${center.x}\" cy=\"${center.y}\" r=\"${radius}\"/></svg>`;\n}\n\n/**\n * Parse SVG selector to extract shape type and data\n */\nexport function parseSvgSelector(svg: string): {\n type: 'rect' | 'polygon' | 'circle' | 'path';\n data: any;\n} | null {\n // Extract rectangle\n const rectMatch = svg.match(/<rect\\s+([^>]+)\\/>/);\n if (rectMatch && rectMatch[1]) {\n const attrs = rectMatch[1];\n const x = parseFloat(attrs.match(/x=\"([^\"]+)\"/)?.[1] || '0');\n const y = parseFloat(attrs.match(/y=\"([^\"]+)\"/)?.[1] || '0');\n const width = parseFloat(attrs.match(/width=\"([^\"]+)\"/)?.[1] || '0');\n const height = parseFloat(attrs.match(/height=\"([^\"]+)\"/)?.[1] || '0');\n\n return {\n type: 'rect',\n data: { x, y, width, height }\n };\n }\n\n // Extract polygon\n const polygonMatch = svg.match(/<polygon\\s+points=\"([^\"]+)\"/);\n if (polygonMatch && polygonMatch[1]) {\n const pointsStr = polygonMatch[1];\n const points = pointsStr.split(/\\s+/).map(pair => {\n const [x, y] = pair.split(',').map(parseFloat);\n return { x, y };\n });\n\n return {\n type: 'polygon',\n data: { points }\n };\n }\n\n // Extract circle\n const circleMatch = svg.match(/<circle\\s+([^>]+)\\/>/);\n if (circleMatch && circleMatch[1]) {\n const attrs = circleMatch[1];\n const cx = parseFloat(attrs.match(/cx=\"([^\"]+)\"/)?.[1] || '0');\n const cy = parseFloat(attrs.match(/cy=\"([^\"]+)\"/)?.[1] || '0');\n const r = parseFloat(attrs.match(/r=\"([^\"]+)\"/)?.[1] || '0');\n\n return {\n type: 'circle',\n data: { cx, cy, r }\n };\n }\n\n return null;\n}\n\n/**\n * Normalize coordinates from display space to image native resolution\n */\nexport function normalizeCoordinates(\n point: Point,\n displayWidth: number,\n displayHeight: number,\n imageWidth: number,\n imageHeight: number\n): Point {\n return {\n x: (point.x / displayWidth) * imageWidth,\n y: (point.y / displayHeight) * imageHeight\n };\n}\n\n/**\n * Scale entire SVG selector from display space to image native resolution\n */\nexport function scaleSvgToNative(\n svg: string,\n displayWidth: number,\n displayHeight: number,\n imageWidth: number,\n imageHeight: number\n): string {\n const parsed = parseSvgSelector(svg);\n if (!parsed) return svg;\n\n const scaleX = imageWidth / displayWidth;\n const scaleY = imageHeight / displayHeight;\n\n switch (parsed.type) {\n case 'rect': {\n const { x, y, width, height } = parsed.data;\n return createRectangleSvg(\n { x: x * scaleX, y: y * scaleY },\n { x: (x + width) * scaleX, y: (y + height) * scaleY }\n );\n }\n\n case 'circle': {\n const { cx, cy, r } = parsed.data;\n return createCircleSvg(\n { x: cx * scaleX, y: cy * scaleY },\n r * Math.min(scaleX, scaleY)\n );\n }\n\n case 'polygon': {\n const points = parsed.data.points.map((p: Point) => ({\n x: p.x * scaleX,\n y: p.y * scaleY\n }));\n return createPolygonSvg(points);\n }\n }\n\n return svg;\n}\n","/**\n * Text context extraction utilities for W3C Web Annotation TextQuoteSelector\n *\n * Provides robust prefix/suffix context extraction with word boundary detection\n * to ensure fuzzy anchoring works correctly when the same text appears multiple times.\n *\n * Also provides AI offset validation and correction for handling AI-generated annotations\n * where the model may return slightly incorrect character offsets.\n *\n * @see https://www.w3.org/TR/annotation-model/#text-quote-selector\n */\n\nimport { findBestTextMatch, buildContentCache, type MatchQuality } from './fuzzy-anchor';\n\n/**\n * Extract prefix and suffix context for TextQuoteSelector\n *\n * Extracts up to 64 characters before and after the selected text,\n * extending to word boundaries to avoid cutting words in half.\n * This ensures prefix/suffix are meaningful context for fuzzy anchoring.\n *\n * @param content - Full text content\n * @param start - Start offset of selection\n * @param end - End offset of selection\n * @returns Object with prefix and suffix (undefined if at boundaries)\n *\n * @example\n * ```typescript\n * const content = \"The United States Congress...\";\n * const context = extractContext(content, 4, 17); // \"United States\"\n * // Returns: { prefix: \"The \", suffix: \" Congress...\" }\n * // NOT: { prefix: \"nited \", suffix: \"gress...\" }\n * ```\n */\nexport function extractContext(\n content: string,\n start: number,\n end: number\n): { prefix?: string; suffix?: string } {\n const CONTEXT_LENGTH = 64;\n const MAX_EXTENSION = 32; // Maximum additional chars to extend for word boundary\n\n // Extract prefix (up to CONTEXT_LENGTH chars before start, extended to word boundary)\n let prefix: string | undefined;\n if (start > 0) {\n let prefixStart = Math.max(0, start - CONTEXT_LENGTH);\n\n // Extend backward to word boundary (whitespace or punctuation)\n // Stop if we hit start of content or exceed MAX_EXTENSION\n let extensionCount = 0;\n while (prefixStart > 0 && extensionCount < MAX_EXTENSION) {\n const char = content[prefixStart - 1];\n // Break on whitespace, punctuation, or common delimiters\n if (!char || /[\\s.,;:!?'\"()\\[\\]{}<>\\/\\\\]/.test(char)) {\n break;\n }\n prefixStart--;\n extensionCount++;\n }\n\n prefix = content.substring(prefixStart, start);\n }\n\n // Extract suffix (up to CONTEXT_LENGTH chars after end, extended to word boundary)\n let suffix: string | undefined;\n if (end < content.length) {\n let suffixEnd = Math.min(content.length, end + CONTEXT_LENGTH);\n\n // Extend forward to word boundary (whitespace or punctuation)\n // Stop if we hit end of content or exceed MAX_EXTENSION\n let extensionCount = 0;\n while (suffixEnd < content.length && extensionCount < MAX_EXTENSION) {\n const char = content[suffixEnd];\n // Break on whitespace, punctuation, or common delimiters\n if (!char || /[\\s.,;:!?'\"()\\[\\]{}<>\\/\\\\]/.test(char)) {\n break;\n }\n suffixEnd++;\n extensionCount++;\n }\n\n suffix = content.substring(end, suffixEnd);\n }\n\n return { prefix, suffix };\n}\n\n/**\n * Result of validating and correcting AI-provided annotation offsets\n */\nexport interface ValidatedAnnotation {\n start: number;\n end: number;\n exact: string;\n prefix?: string;\n suffix?: string;\n corrected: boolean; // True if offsets were adjusted from AI's original values\n fuzzyMatched?: boolean; // True if we had to use fuzzy matching (minor text differences)\n matchQuality?: MatchQuality; // How we found the match\n}\n\n\n/**\n * Validate and correct AI-provided annotation offsets with fuzzy matching tolerance\n *\n * AI models sometimes return offsets that don't match the actual text position,\n * or provide text with minor variations (case differences, whitespace, typos).\n *\n * This function uses a multi-strategy approach:\n * 1. Check if AI's offsets are exactly correct\n * 2. Try exact case-sensitive search\n * 3. Try case-insensitive search\n * 4. Try fuzzy matching with Levenshtein distance (5% tolerance)\n *\n * This ensures we're maximally tolerant of AI errors while still maintaining\n * annotation quality and logging what corrections were made.\n *\n * @param content - Full text content\n * @param aiStart - Start offset from AI\n * @param aiEnd - End offset from AI\n * @param exact - The exact text that should be at this position (from AI)\n * @returns Validated annotation with corrected offsets and context\n * @throws Error if no acceptable match can be found\n *\n * @example\n * ```typescript\n * // AI said start=1143, but actual text is at 1161\n * const result = validateAndCorrectOffsets(\n * content,\n * 1143,\n * 1289,\n * \"the question \\\"whether...\"\n * );\n * // Returns: { start: 1161, end: 1303, exact: \"...\", corrected: true, matchQuality: 'exact', ... }\n * ```\n */\nexport function validateAndCorrectOffsets(\n content: string,\n aiStart: number,\n aiEnd: number,\n exact: string\n): ValidatedAnnotation {\n // First, check if AI's offsets are correct\n const textAtOffset = content.substring(aiStart, aiEnd);\n\n if (textAtOffset === exact) {\n // AI got it right! Just add proper context\n const context = extractContext(content, aiStart, aiEnd);\n return {\n start: aiStart,\n end: aiEnd,\n exact,\n prefix: context.prefix,\n suffix: context.suffix,\n corrected: false,\n matchQuality: 'exact'\n };\n }\n\n // AI's offsets are wrong - try to find the text using multiple strategies\n const cache = buildContentCache(content);\n const match = findBestTextMatch(content, exact, aiStart, cache);\n\n if (!match) {\n throw new Error(\n 'Cannot find acceptable match for text in content. ' +\n 'All search strategies failed. Text may be hallucinated.'\n );\n }\n\n // Found a match! Extract the actual text from content\n const actualText = content.substring(match.start, match.end);\n\n // Extract context using corrected offsets\n const context = extractContext(content, match.start, match.end);\n\n return {\n start: match.start,\n end: match.end,\n exact: actualText, // Use actual text from document, not AI's version\n prefix: context.prefix,\n suffix: context.suffix,\n corrected: true,\n fuzzyMatched: match.matchQuality !== 'exact',\n matchQuality: match.matchQuality\n };\n}\n","/**\n * Text encoding utilities for consistent charset handling\n *\n * Ensures frontend decoding matches backend decoding by respecting\n * charset parameters in mediaType (e.g., \"text/plain; charset=iso-8859-1\")\n */\n\n/**\n * Extract charset from mediaType parameter\n *\n * @param mediaType - Media type with optional charset (e.g., \"text/plain; charset=utf-8\")\n * @returns Charset name in lowercase (defaults to \"utf-8\")\n *\n * @example\n * extractCharset(\"text/plain; charset=iso-8859-1\") // \"iso-8859-1\"\n * extractCharset(\"text/plain\") // \"utf-8\"\n */\nexport function extractCharset(mediaType: string): string {\n const charsetMatch = mediaType.match(/charset=([^\\s;]+)/i);\n return (charsetMatch?.[1] || 'utf-8').toLowerCase();\n}\n\n/**\n * Decode ArrayBuffer to string using charset from mediaType\n *\n * Uses TextDecoder with the charset extracted from mediaType parameter.\n * This ensures the same character space is used for both annotation creation\n * (backend) and rendering (frontend).\n *\n * @param buffer - Binary data to decode\n * @param mediaType - Media type with optional charset parameter\n * @returns Decoded string in the original character space\n *\n * @example\n * const buffer = new Uint8Array([...]);\n * const text = decodeWithCharset(buffer, \"text/plain; charset=iso-8859-1\");\n */\nexport function decodeWithCharset(buffer: ArrayBuffer, mediaType: string): string {\n const charset = extractCharset(mediaType);\n\n // TextDecoder supports standard charset names\n // Common mappings that work in browsers:\n // - utf-8, utf-16, utf-16le, utf-16be\n // - iso-8859-1 through iso-8859-15\n // - windows-1252, windows-1251, etc.\n const decoder = new TextDecoder(charset);\n return decoder.decode(buffer);\n}\n","/**\n * Generic validation utilities for @semiont/api-client\n *\n * Pure TypeScript validation with no external dependencies.\n * Safe to use in any JavaScript environment (Node.js, browser, Deno, etc.)\n */\n\n/**\n * Validation result types\n */\nexport type ValidationSuccess<T> = { success: true; data: T };\nexport type ValidationFailure = { success: false; error: string; details?: string[] };\nexport type ValidationResult<T> = ValidationSuccess<T> | ValidationFailure;\n\n/**\n * JWT Token validation\n *\n * Validates JWT token format (header.payload.signature).\n * Does not verify signature - use for format validation only.\n */\nexport const JWTTokenSchema = {\n parse(token: unknown): string {\n if (typeof token !== 'string') {\n throw new Error('Token must be a string');\n }\n if (!token || token.length === 0) {\n throw new Error('Token is required');\n }\n // JWT format: header.payload.signature\n const jwtRegex = /^[A-Za-z0-9\\-_]+\\.[A-Za-z0-9\\-_]+\\.[A-Za-z0-9\\-_]*$/;\n if (!jwtRegex.test(token)) {\n throw new Error('Invalid JWT token format');\n }\n return token;\n },\n\n safeParse(token: unknown): ValidationResult<string> {\n try {\n const validated = this.parse(token);\n return { success: true, data: validated };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Invalid JWT token',\n };\n }\n },\n};\n\n/**\n * Generic validation helper with error formatting\n *\n * Wraps any schema's parse method with try/catch and returns ValidationResult.\n *\n * @example\n * ```typescript\n * const result = validateData(JWTTokenSchema, 'eyJ...');\n * if (result.success) {\n * console.log('Valid token:', result.data);\n * } else {\n * console.error('Invalid:', result.error);\n * }\n * ```\n */\nexport function validateData<T>(\n schema: { parse(data: unknown): T },\n data: unknown\n): ValidationResult<T> {\n try {\n const validated = schema.parse(data);\n return { success: true, data: validated };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Validation failed',\n };\n }\n}\n\n/**\n * Email validation helper\n *\n * Validates email format using RFC 5322 simplified regex.\n *\n * @param email - Email address to validate\n * @returns true if valid email format\n */\nexport function isValidEmail(email: string): boolean {\n if (email.length < 1 || email.length > 255) {\n return false;\n }\n // RFC 5322 simplified email regex\n const emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n return emailRegex.test(email);\n}\n","/**\n * MIME type utilities for Semiont\n *\n * Initial support for:\n * - text/plain\n * - text/markdown\n * - image/png\n * - image/jpeg\n * - application/pdf\n */\n\n/**\n * Map MIME type to file extension\n */\nexport function getExtensionForMimeType(mimeType: string): string {\n const map: Record<string, string> = {\n 'text/plain': 'txt',\n 'text/markdown': 'md',\n 'image/png': 'png',\n 'image/jpeg': 'jpg',\n 'application/pdf': 'pdf',\n };\n\n return map[mimeType] || 'dat'; // fallback to .dat for unknown types\n}\n\n/**\n * Detect if MIME type is an image (png or jpeg only for now)\n */\nexport function isImageMimeType(mimeType: string): boolean {\n return mimeType === 'image/png' || mimeType === 'image/jpeg';\n}\n\n/**\n * Detect if MIME type is text-based (plain or markdown only for now)\n */\nexport function isTextMimeType(mimeType: string): boolean {\n return mimeType === 'text/plain' || mimeType === 'text/markdown';\n}\n\n/**\n * Detect if MIME type is PDF\n */\nexport function isPdfMimeType(mimeType: string): boolean {\n return mimeType === 'application/pdf';\n}\n\n/**\n * Get category for MIME type (for routing to appropriate viewer)\n *\n * Categories represent annotation models, not file formats:\n * - 'text': Text-based annotations (TextPositionSelector, TextQuoteSelector)\n * - 'image': Spatial coordinate annotations (SvgSelector, FragmentSelector)\n *\n * PDFs use spatial coordinates for annotations, so they belong to 'image' category.\n */\nexport type MimeCategory = 'text' | 'image' | 'unsupported';\n\nexport function getMimeCategory(mimeType: string): MimeCategory {\n if (isTextMimeType(mimeType)) {\n return 'text';\n }\n if (isImageMimeType(mimeType) || isPdfMimeType(mimeType)) {\n return 'image';\n }\n return 'unsupported';\n}\n","/**\n * Common type guard utilities\n */\n\n/**\n * Check if value is a string\n */\nexport function isString(value: unknown): value is string {\n return typeof value === 'string';\n}\n\n/**\n * Check if value is a number (not NaN)\n */\nexport function isNumber(value: unknown): value is number {\n return typeof value === 'number' && !isNaN(value);\n}\n\n/**\n * Check if value is an object (not null, not array)\n */\nexport function isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Check if value is an array\n */\nexport function isArray(value: unknown): value is unknown[] {\n return Array.isArray(value);\n}\n\n/**\n * Check if value is a boolean\n */\nexport function isBoolean(value: unknown): value is boolean {\n return typeof value === 'boolean';\n}\n\n/**\n * Check if value is a function\n */\nexport function isFunction(value: unknown): value is Function {\n return typeof value === 'function';\n}\n\n/**\n * Check if value is null\n */\nexport function isNull(value: unknown): value is null {\n return value === null;\n}\n\n/**\n * Check if value is undefined\n */\nexport function isUndefined(value: unknown): value is undefined {\n return value === undefined;\n}\n\n/**\n * Check if value is null or undefined\n */\nexport function isNullish(value: unknown): value is null | undefined {\n return value === null || value === undefined;\n}\n\n/**\n * Check if value is defined (not null or undefined)\n */\nexport function isDefined<T>(value: T | null | undefined): value is T {\n return value !== null && value !== undefined;\n}","/**\n * Common error classes\n */\n\n/**\n * Base error class for Semiont applications\n */\nexport class SemiontError extends Error {\n constructor(\n message: string,\n public code: string,\n public details?: Record<string, any>\n ) {\n super(message);\n this.name = 'SemiontError';\n Error.captureStackTrace(this, this.constructor);\n }\n}\n\n/**\n * Error thrown when validation fails\n */\nexport class ValidationError extends SemiontError {\n constructor(message: string, details?: Record<string, any>) {\n super(message, 'VALIDATION_ERROR', details);\n this.name = 'ValidationError';\n }\n}\n\n/**\n * Error thrown by scripts\n */\nexport class ScriptError extends SemiontError {\n constructor(message: string, code: string = 'SCRIPT_ERROR', details?: Record<string, any>) {\n super(message, code, details);\n this.name = 'ScriptError';\n }\n}\n\n/**\n * Error thrown when a resource is not found\n */\nexport class NotFoundError extends SemiontError {\n constructor(resource: string, id?: string) {\n const message = id ? `${resource} with id '${id}' not found` : `${resource} not found`;\n super(message, 'NOT_FOUND', { resource, id });\n this.name = 'NotFoundError';\n }\n}\n\n/**\n * Error thrown when user is not authorized\n */\nexport class UnauthorizedError extends SemiontError {\n constructor(message: string = 'Unauthorized', details?: Record<string, any>) {\n super(message, 'UNAUTHORIZED', details);\n this.name = 'UnauthorizedError';\n }\n}\n\n/**\n * Error thrown when operation would conflict with existing data\n */\nexport class ConflictError extends SemiontError {\n constructor(message: string, details?: Record<string, any>) {\n super(message, 'CONFLICT', details);\n this.name = 'ConflictError';\n }\n}\n\n/**\n * API Error class for handling HTTP errors\n * Used by API clients to represent failed HTTP requests\n */\nexport class APIError extends Error {\n constructor(\n public status: number,\n public data: any,\n message?: string\n ) {\n super(message || `API Error: ${status}`);\n this.name = 'APIError';\n Error.captureStackTrace(this, this.constructor);\n }\n}","/**\n * DID (Decentralized Identifier) and W3C Agent utilities\n *\n * Provides utilities for working with DID:WEB identifiers and converting\n * between user representations and W3C Web Annotation Agent objects.\n */\n\nimport type { components } from './types';\n\ntype Agent = components['schemas']['Agent'];\n\n/**\n * Convert a user object to a DID:WEB identifier\n *\n * Format: did:web:domain.com:users:email%40domain.com\n * Example: did:web:example.com:users:alice%40example.com\n *\n * Email is used as the stable, human-readable identifier (URI-encoded).\n * This is used for W3C Web Annotation compliance and federation readiness.\n *\n * @param user - User object with email and domain\n * @returns DID:WEB identifier string\n */\nexport function userToDid(user: { email: string; domain: string }): string {\n return `did:web:${user.domain}:users:${encodeURIComponent(user.email)}`;\n}\n\n/**\n * Convert a user object to a W3C Agent object with DID:WEB identifier\n *\n * Creates a full Agent object for W3C Web Annotation compliance.\n * Includes DID:WEB identifier, type, and name.\n *\n * @param user - User object with id, domain, name, and email\n * @returns W3C Agent object\n */\nexport function userToAgent(user: {\n id: string;\n domain: string;\n name: string | null;\n email: string;\n}): Agent {\n return {\n type: 'Person' as const,\n id: userToDid(user),\n name: user.name || user.email,\n };\n}\n\n/**\n * Convert a DID string to a minimal W3C Agent object\n *\n * Used when reconstructing annotations from events where only the DID is available.\n * Creates a minimal Agent with just the required fields (id, type).\n * Name is derived from the DID for display purposes.\n *\n * @param did - DID:WEB identifier string\n * @returns Minimal W3C Agent object\n */\nexport function didToAgent(did: string | undefined | null): Agent {\n if (!did) {\n return { type: 'Person' as const, id: 'unknown', name: 'unknown' };\n }\n const parts = did.split(':');\n const encoded = parts[parts.length - 1] || 'unknown';\n const name = decodeURIComponent(encoded);\n\n return {\n type: 'Person' as const,\n id: did,\n name,\n };\n}\n","/**\n * TOML Config Loader\n *\n * Reads ~/.semiontconfig (TOML) and .semiont/config (TOML) and produces\n * an EnvironmentConfig for the requested environment.\n *\n * File format: see TOML-XDG-CONFIG.md\n *\n * Loading sequence:\n * 1. Read .semiont/config → projectName, site, environments.<env>.* (project base)\n * 2. Read ~/.semiontconfig → defaults, environments.<env>.* (user overrides)\n * 3. Deep-merge: project base ← user overrides (user wins on conflicts)\n * Any environment name is valid (local, staging, production, custom, ...)\n * 4. Resolve ${VAR} references from process.env\n * 5. Apply inheritance: workers.<name> → workers.default → error\n * 6. Map to EnvironmentConfig shape\n */\n\nimport { parse as parseToml } from 'smol-toml';\nimport type { EnvironmentConfig, OllamaProviderConfig, AnthropicProviderConfig } from './config.types';\nimport type { PlatformType } from './config.types';\n\n/**\n * Deep merge two plain objects. Arrays and primitives in `override` replace those in `base`.\n * Nested objects are merged recursively. `override` takes precedence on conflicts.\n */\nfunction deepMerge<T extends Record<string, unknown>>(base: T, override: Partial<T>): T {\n const result = { ...base } as Record<string, unknown>;\n for (const key of Object.keys(override)) {\n const b = base[key];\n const o = override[key];\n if (o !== undefined && o !== null && typeof o === 'object' && !Array.isArray(o) &&\n b !== undefined && b !== null && typeof b === 'object' && !Array.isArray(b)) {\n result[key] = deepMerge(b as Record<string, unknown>, o as Record<string, unknown>);\n } else if (o !== undefined) {\n result[key] = o;\n }\n }\n return result as T;\n}\n\nfunction resolveEnvVars(obj: unknown, env: Record<string, string | undefined>): unknown {\n if (typeof obj === 'string') {\n return obj.replace(/\\$\\{([^}]+)\\}/g, (match, expr: string) => {\n const sepIdx = expr.indexOf(':-');\n const varName = sepIdx >= 0 ? expr.slice(0, sepIdx) : expr;\n const defaultValue = sepIdx >= 0 ? expr.slice(sepIdx + 2) : undefined;\n const value = env[varName];\n if (value !== undefined) return value;\n if (defaultValue !== undefined) return defaultValue;\n throw new Error(`Environment variable ${varName} is not set (referenced in config as ${match})`);\n });\n }\n if (Array.isArray(obj)) {\n return obj.map(item => resolveEnvVars(item, env));\n }\n if (obj !== null && typeof obj === 'object') {\n const resolved: Record<string, unknown> = {};\n for (const key in obj as Record<string, unknown>) {\n resolved[key] = resolveEnvVars((obj as Record<string, unknown>)[key], env);\n }\n return resolved;\n }\n return obj;\n}\n\n// ── Inference config types (mirrored from packages/make-meaning/src/config.ts) ─\n// Kept here to avoid a circular dependency: core cannot import make-meaning.\n\nexport interface InferenceConfig {\n type: 'anthropic' | 'ollama';\n model: string;\n maxTokens?: number;\n apiKey?: string;\n endpoint?: string;\n baseURL?: string;\n}\n\nexport interface ActorInferenceConfig {\n gatherer?: InferenceConfig;\n matcher?: InferenceConfig;\n}\n\nexport interface WorkerInferenceConfig {\n default?: InferenceConfig;\n 'reference-annotation'?: InferenceConfig;\n 'highlight-annotation'?: InferenceConfig;\n 'assessment-annotation'?: InferenceConfig;\n 'comment-annotation'?: InferenceConfig;\n 'tag-annotation'?: InferenceConfig;\n 'generation'?: InferenceConfig;\n}\n\n// ── Types for ~/.semiontconfig ────────────────────────────────────────────────\n\ninterface SemiontConfigFile {\n user?: {\n name?: string;\n email?: string;\n };\n defaults?: {\n environment?: string;\n platform?: string;\n };\n environments?: Record<string, EnvironmentSection>;\n}\n\ninterface GraphSection {\n platform?: string;\n type?: string;\n name?: string;\n uri?: string;\n username?: string;\n password?: string;\n database?: string;\n [key: string]: unknown;\n}\n\ninterface InferenceFlatSection {\n // Flat (single-provider) format: type = \"anthropic\"|\"ollama\" at this level\n type?: 'anthropic' | 'ollama';\n platform?: string;\n model?: string;\n maxTokens?: number;\n apiKey?: string;\n endpoint?: string;\n baseURL?: string;\n // Keyed (multi-provider) format: [inference.anthropic] / [inference.ollama]\n anthropic?: { platform?: string; apiKey?: string; endpoint?: string };\n ollama?: { platform?: string; baseURL?: string; port?: number };\n}\n\ninterface EnvironmentSection {\n backend?: {\n platform?: string;\n port?: number;\n publicURL?: string;\n frontendURL?: string;\n corsOrigin?: string;\n };\n frontend?: {\n platform?: string;\n port?: number;\n publicURL?: string;\n };\n site?: {\n domain?: string;\n siteName?: string;\n adminEmail?: string;\n oauthAllowedDomains?: string[];\n enableLocalAuth?: boolean;\n };\n database?: {\n platform?: string;\n image?: string;\n host?: string;\n port?: number;\n name?: string;\n user?: string;\n password?: string;\n };\n graph?: GraphSection;\n vectors?: {\n type?: 'qdrant' | 'memory';\n host?: string;\n port?: number;\n // Legacy: embedding nested under vectors (migrated to top-level)\n embedding?: {\n type?: 'voyage' | 'ollama';\n model?: string;\n apiKey?: string;\n baseURL?: string;\n endpoint?: string;\n };\n chunking?: {\n chunkSize?: number;\n overlap?: number;\n };\n };\n embedding?: {\n type?: 'voyage' | 'ollama';\n model?: string;\n apiKey?: string;\n baseURL?: string;\n endpoint?: string;\n chunking?: {\n chunkSize?: number;\n overlap?: number;\n };\n };\n inference?: InferenceFlatSection;\n 'make-meaning'?: {\n graph?: Record<string, unknown>;\n actors?: {\n gatherer?: { inference?: InferenceConfig };\n matcher?: { inference?: InferenceConfig };\n };\n default?: { inference?: InferenceConfig };\n };\n workers?: Record<string, { inference?: InferenceConfig }>;\n actors?: Record<string, { inference?: InferenceConfig }>;\n logLevel?: 'error' | 'warn' | 'info' | 'http' | 'debug';\n}\n\n// ── File reader abstraction (same pattern as createConfigLoader) ──────────────\n\nexport type TomlFileReader = {\n readIfExists: (path: string) => string | null;\n};\n\nfunction requirePlatform(value: string | undefined, serviceName: string): PlatformType {\n if (!value) {\n throw new Error(`platform is required for service '${serviceName}' — add 'platform = \"posix\"|\"container\"|\"external\"' to its config section`);\n }\n return value as PlatformType;\n}\n\n// ── Main loader function ──────────────────────────────────────────────────────\n\n/**\n * Parse ~/.semiontconfig and .semiont/config and return EnvironmentConfig.\n *\n * @param projectRoot - Path to the project root (contains .semiont/config)\n * @param environment - Environment name (e.g. 'local', 'production')\n * @param globalConfigPath - Path to ~/.semiontconfig (caller resolves ~ expansion)\n * @param reader - File reader abstraction\n * @param env - Environment variables for ${VAR} resolution\n */\nexport function loadTomlConfig(\n projectRoot: string | null,\n environment: string,\n globalConfigPath: string,\n reader: TomlFileReader,\n env: Record<string, string | undefined>\n): EnvironmentConfig {\n // 1. Read project config from .semiont/config (skipped when no project root)\n const projectConfigContent = projectRoot ? reader.readIfExists(`${projectRoot}/.semiont/config`) : null;\n let projectName = 'semiont-project';\n let projectVersion: string | undefined;\n let projectSite: EnvironmentSection['site'] | undefined;\n let projectEnvSection: EnvironmentSection = {};\n if (projectConfigContent) {\n const projectConfig = parseToml(projectConfigContent) as {\n project?: { name?: string; version?: string };\n site?: EnvironmentSection['site'];\n environments?: Record<string, EnvironmentSection>;\n };\n projectName = projectConfig.project?.name ?? projectName;\n projectVersion = projectConfig.project?.version;\n projectSite = projectConfig.site;\n projectEnvSection = projectConfig.environments?.[environment] ?? {};\n }\n\n // 2. Read global config (optional — missing config yields empty environments)\n const globalContent = reader.readIfExists(globalConfigPath);\n const raw = globalContent ? (parseToml(globalContent) as SemiontConfigFile) : ({} as SemiontConfigFile);\n\n // 3. Deep-merge: project base + user overrides (user wins on conflicts)\n const userEnvSection: EnvironmentSection = raw.environments?.[environment] ?? {};\n const envSection: EnvironmentSection = deepMerge(\n projectEnvSection as Record<string, unknown>,\n userEnvSection as Record<string, unknown>\n ) as EnvironmentSection;\n\n // 4. Resolve ${VAR} references\n const resolved = resolveEnvVars(envSection, env) as EnvironmentSection;\n\n // 5. Build make-meaning actor/worker inference config with inheritance\n // The flat [inference] section provides defaults (apiKey, maxTokens, endpoint/baseURL).\n // Actor/worker sections only need to specify type and model; missing fields fall back\n // to the flat inference section.\n const flatInference = resolved.inference;\n const makeMeaningSection = resolved['make-meaning'];\n const workersSection = resolved.workers ?? {};\n const actorsSection = resolved.actors ?? {};\n const defaultWorkerInference = workersSection['default']?.inference;\n const defaultMakeMeaningInference = makeMeaningSection?.default?.inference;\n\n function mergeWithFlatInference(specific: InferenceConfig): InferenceConfig {\n if (!flatInference) return specific;\n // For keyed sub-sections, inherit credentials from the matching provider sub-section.\n // For flat (legacy) format, flatInference.type is required to know which fields apply.\n const providerDefaults: Partial<InferenceConfig> = {};\n if (specific.type === 'anthropic') {\n const a = flatInference.anthropic;\n if (a) {\n providerDefaults.apiKey = a.apiKey;\n providerDefaults.endpoint = a.endpoint;\n } else {\n if (!flatInference.type) {\n throw new Error(\n `[environments.${environment}.inference] is missing 'type'. ` +\n `Add type = \"anthropic\" or use [inference.anthropic] sub-section.`\n );\n }\n providerDefaults.apiKey = flatInference.apiKey;\n providerDefaults.endpoint = flatInference.endpoint;\n }\n } else if (specific.type === 'ollama') {\n const o = flatInference.ollama;\n if (o) {\n providerDefaults.baseURL = o.baseURL;\n } else {\n if (!flatInference.type) {\n throw new Error(\n `[environments.${environment}.inference] is missing 'type'. ` +\n `Add type = \"ollama\" or use [inference.ollama] sub-section.`\n );\n }\n providerDefaults.baseURL = flatInference.baseURL;\n }\n }\n return {\n maxTokens: flatInference.maxTokens,\n ...providerDefaults,\n ...specific,\n };\n }\n\n function resolveActorInference(fromMakeMeaning?: InferenceConfig, fromActors?: InferenceConfig): InferenceConfig | undefined {\n const base = fromMakeMeaning ?? fromActors ?? defaultMakeMeaningInference;\n if (!base) return undefined;\n return mergeWithFlatInference(base);\n }\n\n const actors: ActorInferenceConfig = {};\n const gathererInference = resolveActorInference(\n makeMeaningSection?.actors?.gatherer?.inference,\n actorsSection['gatherer']?.inference\n );\n if (gathererInference) actors.gatherer = gathererInference;\n\n const matcherInference = resolveActorInference(\n makeMeaningSection?.actors?.matcher?.inference,\n actorsSection['matcher']?.inference\n );\n if (matcherInference) actors.matcher = matcherInference;\n\n const workers: WorkerInferenceConfig = {};\n const workerTypes = ['reference-annotation', 'highlight-annotation', 'assessment-annotation', 'comment-annotation', 'tag-annotation', 'generation'] as const;\n if (defaultWorkerInference) {\n workers.default = mergeWithFlatInference(defaultWorkerInference);\n }\n for (const wt of workerTypes) {\n const specific = workersSection[wt]?.inference;\n if (specific) {\n (workers as Record<string, InferenceConfig>)[wt] = mergeWithFlatInference(specific);\n }\n }\n\n // 6. Map to EnvironmentConfig\n const backend = resolved.backend;\n const site = resolved.site ?? projectSite;\n const inferenceSection = resolved.inference;\n\n // Build inference providers config.\n // Supports two formats:\n // Flat: [environments.local.inference] type = \"anthropic\"|\"ollama\" (single provider)\n // Keyed: [environments.local.inference.anthropic] / [environments.local.inference.ollama] (multi-provider)\n let inferenceProviders: EnvironmentConfig['inference'] | undefined;\n if (inferenceSection) {\n inferenceProviders = {};\n // Keyed sub-sections take priority\n if (inferenceSection.anthropic) {\n const a = inferenceSection.anthropic;\n inferenceProviders.anthropic = {\n platform: requirePlatform(a.platform, 'inference.anthropic'),\n endpoint: a.endpoint ?? 'https://api.anthropic.com',\n apiKey: a.apiKey ?? '',\n } as AnthropicProviderConfig;\n } else if (inferenceSection.type === 'anthropic') {\n inferenceProviders.anthropic = {\n platform: requirePlatform(inferenceSection.platform, 'inference'),\n endpoint: inferenceSection.endpoint ?? 'https://api.anthropic.com',\n apiKey: inferenceSection.apiKey ?? '',\n } as AnthropicProviderConfig;\n }\n if (inferenceSection.ollama) {\n const o = inferenceSection.ollama;\n inferenceProviders.ollama = {\n platform: { type: requirePlatform(o.platform, 'inference.ollama') },\n baseURL: o.baseURL,\n port: o.baseURL ? undefined : (o.port ?? 11434),\n } as OllamaProviderConfig;\n } else if (inferenceSection.type === 'ollama') {\n inferenceProviders.ollama = {\n platform: { type: requirePlatform(inferenceSection.platform, 'inference') },\n baseURL: inferenceSection.baseURL,\n port: inferenceSection.baseURL ? undefined : 11434,\n } as OllamaProviderConfig;\n }\n }\n\n // Build top-level workers/actors maps for EnvironmentConfig\n const topLevelWorkers: EnvironmentConfig['workers'] = {};\n for (const [name, w] of Object.entries(workersSection)) {\n if (w.inference) {\n topLevelWorkers[name] = { inference: { type: w.inference.type, model: w.inference.model } };\n }\n }\n const topLevelActors: EnvironmentConfig['actors'] = {};\n for (const [name, a] of Object.entries(actorsSection)) {\n if (a.inference) {\n topLevelActors[name] = { inference: { type: a.inference.type, model: a.inference.model } };\n }\n }\n // Also include make-meaning actors\n if (makeMeaningSection?.actors?.gatherer?.inference) {\n topLevelActors['gatherer'] = { inference: { type: makeMeaningSection.actors.gatherer.inference.type, model: makeMeaningSection.actors.gatherer.inference.model } };\n }\n if (makeMeaningSection?.actors?.matcher?.inference) {\n topLevelActors['matcher'] = { inference: { type: makeMeaningSection.actors.matcher.inference.type, model: makeMeaningSection.actors.matcher.inference.model } };\n }\n\n const frontend = resolved.frontend;\n\n const services: EnvironmentConfig['services'] = {};\n\n if (backend) {\n services.backend = {\n platform: { type: requirePlatform(backend.platform, 'backend') },\n port: backend.port ?? 4000,\n publicURL: backend.publicURL ?? `http://localhost:${backend.port ?? 4000}`,\n corsOrigin: backend.corsOrigin ?? backend.frontendURL ?? 'http://localhost:3000',\n };\n }\n\n if (frontend) {\n services.frontend = {\n platform: { type: requirePlatform(frontend.platform, 'frontend') },\n port: frontend.port ?? 3000,\n siteName: site?.siteName ?? 'Semiont',\n publicURL: frontend.publicURL,\n };\n }\n\n if (resolved.graph) {\n services.graph = {\n ...resolved.graph,\n platform: { type: requirePlatform(resolved.graph.platform as string | undefined, 'graph') },\n type: (resolved.graph.type ?? 'neo4j') as import('./config.types').GraphDatabaseType,\n } as EnvironmentConfig['services']['graph'];\n } else if (makeMeaningSection?.graph) {\n services.graph = makeMeaningSection.graph as EnvironmentConfig['services']['graph'];\n }\n\n if (resolved.database) {\n services.database = {\n platform: { type: requirePlatform(resolved.database.platform, 'database') },\n type: 'postgres',\n image: resolved.database.image,\n host: resolved.database.host ?? 'localhost',\n port: resolved.database.port ?? 5432,\n name: resolved.database.name,\n user: resolved.database.user,\n password: resolved.database.password,\n } as EnvironmentConfig['services']['database'];\n }\n\n if (resolved.vectors) {\n services.vectors = {\n platform: { type: 'external' as PlatformType },\n type: (resolved.vectors.type ?? 'qdrant') as 'qdrant' | 'memory',\n host: resolved.vectors.host,\n port: resolved.vectors.port ?? 6333,\n } as EnvironmentConfig['services']['vectors'];\n }\n\n // Embedding: top-level takes precedence, fall back to legacy vectors.embedding\n const embeddingSource = resolved.embedding ?? resolved.vectors?.embedding;\n if (embeddingSource) {\n services.embedding = {\n platform: { type: 'external' as PlatformType },\n type: embeddingSource.type!,\n model: embeddingSource.model!,\n apiKey: embeddingSource.apiKey,\n baseURL: embeddingSource.baseURL,\n endpoint: embeddingSource.endpoint,\n chunking: (resolved.embedding?.chunking ?? resolved.vectors?.chunking) ? {\n chunkSize: (resolved.embedding?.chunking ?? resolved.vectors?.chunking)?.chunkSize ?? 512,\n overlap: (resolved.embedding?.chunking ?? resolved.vectors?.chunking)?.overlap ?? 64,\n } : undefined,\n } as EnvironmentConfig['services']['embedding'];\n }\n\n const config: EnvironmentConfig = {\n services,\n ...(inferenceProviders ? { inference: inferenceProviders } : {}),\n ...(Object.keys(topLevelWorkers).length > 0 ? { workers: topLevelWorkers } : {}),\n ...(Object.keys(topLevelActors).length > 0 ? { actors: topLevelActors } : {}),\n site: site ? {\n domain: site.domain ?? 'localhost',\n siteName: site.siteName,\n adminEmail: site.adminEmail,\n oauthAllowedDomains: site.oauthAllowedDomains as [string, ...string[]] | undefined,\n } : undefined,\n logLevel: resolved.logLevel,\n _metadata: {\n environment,\n projectRoot,\n projectName,\n projectVersion,\n ...(Object.keys(actors).length > 0 ? { actors } : {}),\n ...(Object.keys(workers).length > 0 ? { workers } : {}),\n },\n };\n\n return config;\n}\n\n/**\n * Create a TOML config loader backed by a file reader.\n * Drop-in replacement for createConfigLoader that reads TOML instead of JSON.\n * The caller must resolve globalConfigPath (e.g. expand '~' using process.env.HOME).\n */\nexport function createTomlConfigLoader(\n reader: TomlFileReader,\n globalConfigPath: string,\n env: Record<string, string | undefined>\n) {\n return (projectRoot: string | null, environment: string): EnvironmentConfig => {\n return loadTomlConfig(projectRoot, environment, globalConfigPath, reader, env);\n };\n}\n","/**\n * Environment validation utilities\n *\n * Pure functions - accept available environments as parameter instead of reading from filesystem\n */\n\nexport type Environment = string; // Allow any environment name\n\n/**\n * Type guard to check if a string is a valid Environment\n * @param value - The environment string to check\n * @param availableEnvironments - List of valid environment names\n */\nexport function isValidEnvironment(value: string | undefined, availableEnvironments: string[]): value is Environment {\n if (!value) return false;\n return availableEnvironments.includes(value);\n}\n\n/**\n * Parse environment string to Environment type\n * @param value - The environment string to parse\n * @param availableEnvironments - List of valid environment names\n * @returns Valid Environment type\n * @throws Error if environment is invalid or not provided\n */\nexport function parseEnvironment(value: string | undefined, availableEnvironments: string[]): Environment {\n if (!value) {\n throw new Error('Environment is required');\n }\n if (!isValidEnvironment(value, availableEnvironments)) {\n throw new Error(`Invalid environment: ${value}. Available environments: ${availableEnvironments.join(', ')}`);\n }\n return value;\n}\n\n/**\n * Validate and return environment or throw error\n * @param value - The environment string to validate\n * @param availableEnvironments - List of valid environment names\n * @throws Error if environment is invalid\n */\nexport function validateEnvironment(value: string | undefined, availableEnvironments: string[]): Environment {\n if (!value) {\n throw new Error('Environment is required');\n }\n if (!isValidEnvironment(value, availableEnvironments)) {\n throw new Error(`Invalid environment: ${value}. Available environments: ${availableEnvironments.join(', ')}`);\n }\n return value;\n}","/**\n * Configuration Error Class\n * \n * Custom error class for configuration validation and loading errors.\n * Provides structured error information with helpful suggestions.\n */\n\nexport class ConfigurationError extends Error {\n public override readonly cause?: Error;\n\n constructor(\n message: string,\n public environment?: string,\n public suggestion?: string,\n cause?: Error\n ) {\n super(message);\n this.name = 'ConfigurationError';\n this.cause = cause;\n }\n \n /**\n * Format the error nicely for CLI output\n */\n override toString(): string {\n let output = `❌ ${this.message}`;\n if (this.environment) {\n output += `\\n Environment: ${this.environment}`;\n }\n if (this.suggestion) {\n output += `\\n 💡 Suggestion: ${this.suggestion}`;\n }\n return output;\n }\n}","/**\n * Platform Types Module\n *\n * Re-exports PlatformType from schema-generated types.\n * Platforms represent WHERE services run (infrastructure targets).\n */\n\nimport { PlatformType as SchemaPlatformType } from './config.types';\n\n/**\n * Platform type literals from JSON Schema\n * These represent the infrastructure targets where services can be deployed\n */\nexport type PlatformType = SchemaPlatformType;\n\n/**\n * Type guard to check if a string is a valid platform type\n *\n * @param value - Value to check\n * @returns True if value is a valid PlatformType\n */\nexport function isValidPlatformType(value: string): value is PlatformType {\n return ['aws', 'container', 'posix', 'external'].includes(value);\n}\n\n/**\n * Get all valid platform types\n *\n * @returns Array of all platform types\n */\nexport function getAllPlatformTypes(): PlatformType[] {\n return ['aws', 'container', 'posix', 'external'];\n}","/**\n * @semiont/core\n *\n * Core domain logic and utilities for the Semiont semantic knowledge platform.\n * OpenAPI types are generated here and exported for use across the monorepo.\n */\n\n// OpenAPI-generated types (source of truth for API schemas)\nexport type { components, paths, operations } from './types';\n\n// Branded types (compile-time type safety)\nexport type {\n // OpenAPI types\n Motivation,\n ContentFormat,\n // Authentication & tokens\n Email,\n AuthCode,\n GoogleCredential,\n AccessToken,\n RefreshToken,\n MCPToken,\n CloneToken,\n // System identifiers\n JobId,\n UserDID,\n EntityType,\n SearchQuery,\n BaseUrl,\n // HTTP URI types\n ResourceUri,\n AnnotationUri,\n ResourceAnnotationUri,\n} from './branded-types';\nexport {\n // Helper functions\n email,\n authCode,\n googleCredential,\n accessToken,\n refreshToken,\n mcpToken,\n cloneToken,\n jobId,\n userDID,\n entityType,\n searchQuery,\n baseUrl,\n // URI factory functions\n resourceUri,\n annotationUri,\n resourceAnnotationUri,\n} from './branded-types';\n\n// Creation methods\nexport { CREATION_METHODS } from './creation-methods';\nexport type { CreationMethod } from './creation-methods';\n\n// Identifier types (only IDs - URIs are in @semiont/api-client)\nexport type { ResourceId, AnnotationId, UserId } from './identifiers';\nexport {\n resourceId,\n annotationId,\n userId,\n isResourceId,\n isAnnotationId,\n} from './identifiers';\n\n// Graph types\nexport type {\n GraphConnection,\n GraphPath,\n EntityTypeStats,\n ResourceDescriptor,\n} from './graph';\n\n// Event base types (persistence model foundations)\nexport type {\n Brand,\n EventBase,\n EventMetadata,\n EventSignature,\n StoredEvent,\n BodyOperation,\n BodyItem,\n EventQuery,\n ResourceAnnotations,\n} from './event-base';\n\n// Persisted events (the 20 event types written to the log)\nexport type {\n EventOfType,\n PersistedEvent,\n PersistedEventType,\n EventInput,\n} from './persisted-events';\nexport { PERSISTED_EVENT_TYPES } from './persisted-events';\n\n// Bus protocol (unified EventMap — all channels on the EventBus)\nexport type {\n EventMap,\n EventName,\n EmittableChannel,\n ResourceBroadcastType,\n} from './bus-protocol';\nexport { RESOURCE_BROADCAST_TYPES, CHANNEL_SCHEMAS } from './bus-protocol';\n\n// Payload type aliases (OpenAPI schema shortcuts used across the codebase)\nexport type {\n Selector,\n GatheredContext,\n SelectionData,\n} from './payload-types';\n\n// Event utilities\nexport type { StoredEventLike } from './event-utils';\nexport {\n getAnnotationUriFromEvent,\n isEventRelatedToAnnotation,\n isStoredEvent,\n} from './event-utils';\n\n// Event bus (RxJS-based, framework-agnostic)\nexport { EventBus, ScopedEventBus } from './event-bus';\n\n// RxJS operators\nexport { burstBuffer, type BurstBufferOptions } from './operators/burst-buffer';\n\n// Per-key serialization (for RPC-style callers; see also RxJS groupBy + concatMap\n// for stream-style callers in packages/make-meaning)\nexport { serializePerKey } from './serialize-per-key';\n\n// Logger interface (framework-agnostic)\nexport type { Logger } from './logger';\nexport { errField } from './logger';\n\n// Bus logging — Tier 1 cross-wire observability\nexport { busLog, busLogEnabled, setBusLogTraceIdProvider, type BusOp } from './bus-log';\n\n// Annotation body matcher (used by mark:body-updated event replay)\nexport { findBodyItem } from './annotation-utils';\nexport type { BodyItemIdentity } from './annotation-utils';\n\n// Annotation assembly (pure functions for building W3C Annotations)\nexport {\n assembleAnnotation,\n applyBodyOperations,\n getTextPositionSelector,\n getSvgSelector,\n getFragmentSelector,\n validateSvgMarkup,\n} from './annotation-assembly';\nexport type { AssembledAnnotation } from './annotation-assembly';\n\n// W3C Web Annotation accessors (target/body/selector helpers + type guards)\nexport {\n getBodySource,\n getBodyType,\n isBodyResolved,\n getTargetSource,\n getTargetSelector,\n hasTargetSelector,\n isHighlight,\n isReference,\n isAssessment,\n isComment,\n isTag,\n getCommentText,\n isStubReference,\n isResolvedReference,\n getExactText,\n getAnnotationExactText,\n getPrimarySelector,\n getTextQuoteSelector,\n extractBoundingBox,\n} from './web-annotation-utils';\nexport type {\n TextPositionSelector,\n TextQuoteSelector,\n SvgSelector,\n FragmentSelector,\n} from './web-annotation-utils';\n\n// ResourceDescriptor accessors\nexport {\n getResourceId,\n getPrimaryRepresentation,\n getPrimaryMediaType,\n getChecksum,\n getLanguage,\n getStorageUri,\n getCreator,\n getDerivedFrom,\n isArchived,\n getResourceEntityTypes,\n isDraft,\n getNodeEncoding,\n decodeRepresentation,\n} from './resource-utils';\n\n// Transport contract — interfaces every concrete transport must satisfy.\nexport type {\n ITransport,\n IContentTransport,\n PutBinaryRequest,\n ConnectionState,\n ProgressEvent,\n ProgressCallback,\n HealthCheckResponse,\n StatusResponse,\n UserResponse,\n UpdateUserRequest,\n UpdateUserResponse,\n ListUsersResponse,\n} from './transport';\n\n// Channel set every concrete transport bridges into the client's bus.\nexport { BRIDGED_CHANNELS, type BridgedChannel } from './bridged-channels';\n\n// Fuzzy text anchoring (annotation re-anchoring under content edits)\nexport {\n normalizeText,\n buildContentCache,\n findBestTextMatch,\n findTextWithContext,\n verifyPosition,\n} from './fuzzy-anchor';\nexport type { TextPosition, MatchQuality, ContentCache } from './fuzzy-anchor';\n\n// Locale info table\nexport {\n LOCALES,\n getLocaleInfo,\n getLocaleNativeName,\n getLocaleEnglishName,\n formatLocaleDisplay,\n getAllLocaleCodes,\n} from './locales';\nexport type { LocaleInfo } from './locales';\n\n// SVG utilities\nexport {\n createRectangleSvg,\n createPolygonSvg,\n createCircleSvg,\n parseSvgSelector,\n normalizeCoordinates,\n scaleSvgToNative,\n} from './svg-utils';\nexport type { Point, BoundingBox } from './svg-utils';\n\n// Text context extraction (depends on fuzzy-anchor)\nexport { extractContext, validateAndCorrectOffsets } from './text-context';\nexport type { ValidatedAnnotation } from './text-context';\n\n// Text encoding helpers\nexport { extractCharset, decodeWithCharset } from './text-encoding';\n\n// Schema validation helpers\nexport {\n JWTTokenSchema,\n validateData,\n isValidEmail,\n} from './validation';\nexport type { ValidationSuccess, ValidationFailure, ValidationResult } from './validation';\n\n// MIME type helpers\nexport {\n getExtensionForMimeType,\n isImageMimeType,\n isTextMimeType,\n isPdfMimeType,\n getMimeCategory,\n} from './mime-utils';\nexport type { MimeCategory } from './mime-utils';\n\n// Resource types\nexport type { UpdateResourceInput, ResourceFilter } from './resource-types';\n\n// Annotation types\nexport type { Annotation, AnnotationCategory, CreateAnnotationInternal } from './annotation-types';\n\n// Auth types\nexport type { GoogleAuthRequest } from './auth-types';\n\n// ID generation\nexport { generateUuid } from './id-generation';\n\n// Utility functions\nexport * from './type-guards';\nexport * from './errors';\nexport * from './did-utils';\n\n// Configuration types\nexport type {\n EnvironmentConfig,\n SiteConfig,\n AppConfig,\n} from './config/config.types';\n\nexport {\n loadTomlConfig,\n createTomlConfigLoader,\n type TomlFileReader,\n type InferenceConfig as TomlInferenceConfig,\n type ActorInferenceConfig as TomlActorInferenceConfig,\n type WorkerInferenceConfig as TomlWorkerInferenceConfig,\n} from './config/toml-loader';\n\nexport {\n parseEnvironment,\n validateEnvironment,\n type Environment,\n} from './config/environment-validator';\nexport { ConfigurationError } from './config/configuration-error';\nexport {\n type PlatformType,\n isValidPlatformType,\n getAllPlatformTypes,\n} from './config/platform-types';\n\n// Schema-generated configuration types\nexport type {\n BackendServiceConfig,\n FrontendServiceConfig,\n DatabaseServiceConfig,\n GraphServiceConfig,\n OllamaProviderConfig,\n AnthropicProviderConfig,\n InferenceProvidersConfig,\n McpServiceConfig,\n ServicesConfig,\n VectorsServiceConfig,\n EmbeddingServiceConfig,\n SemiontConfig,\n GraphDatabaseType,\n ServicePlatformConfig\n} from './config/config.types';\n\n// Version information\nexport const CORE_TYPES_VERSION = '0.1.0';\nexport const SDK_VERSION = '0.1.0';\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/branded-types.ts","../src/creation-methods.ts","../src/identifiers.ts","../src/persisted-events.ts","../src/bus-protocol.ts","../src/event-utils.ts","../src/bus-log.ts","../src/event-bus.ts","../src/operators/burst-buffer.ts","../src/serialize-per-key.ts","../src/logger.ts","../src/annotation-utils.ts","../src/id-generation.ts","../src/annotation-assembly.ts","../src/web-annotation-utils.ts","../src/resource-utils.ts","../src/bridged-channels.ts","../src/fuzzy-anchor.ts","../src/locales.ts","../src/svg-utils.ts","../src/text-context.ts","../src/text-encoding.ts","../src/validation.ts","../src/mime-utils.ts","../src/type-guards.ts","../src/errors.ts","../src/did-utils.ts","../src/config/toml-loader.ts","../src/config/environment-validator.ts","../src/config/configuration-error.ts","../src/config/platform-types.ts","../src/index.ts"],"names":["resourceUri","baseUrl","annotationUri","resourceId","pos","context","email","parseToml"],"mappings":";;;;AA0CO,SAAS,MAAM,KAAA,EAAsB;AAAE,EAAA,OAAO,KAAA;AAAgB;AAC9D,SAAS,SAAS,KAAA,EAAyB;AAAE,EAAA,OAAO,KAAA;AAAmB;AACvE,SAAS,iBAAiB,KAAA,EAAiC;AAAE,EAAA,OAAO,KAAA;AAA2B;AAC/F,SAAS,YAAY,KAAA,EAA4B;AAAE,EAAA,OAAO,KAAA;AAAsB;AAChF,SAAS,aAAa,KAAA,EAA6B;AAAE,EAAA,OAAO,KAAA;AAAuB;AACnF,SAAS,SAAS,KAAA,EAAyB;AAAE,EAAA,OAAO,KAAA;AAAmB;AACvE,SAAS,WAAW,KAAA,EAA2B;AAAE,EAAA,OAAO,KAAA;AAAqB;AAC7E,SAAS,MAAM,KAAA,EAAsB;AAAE,EAAA,OAAO,KAAA;AAAgB;AAC9D,SAAS,QAA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AAA,EACf;AAAA,EAXyB,KAAA;AAAA;AAAA;AAAA;AAAA,EAgBhB,QAAA,GAAmB;AAC1B,IAAA,IAAI,MAAA,GAAS,CAAA,OAAA,EAAK,IAAA,CAAK,OAAO,CAAA,CAAA;AAC9B,IAAA,IAAI,KAAK,WAAA,EAAa;AACpB,MAAA,MAAA,IAAU;AAAA,gBAAA,EAAqB,KAAK,WAAW,CAAA,CAAA;AAAA,IACjD;AACA,IAAA,IAAI,KAAK,UAAA,EAAY;AACnB,MAAA,MAAA,IAAU;AAAA,yBAAA,EAAuB,KAAK,UAAU,CAAA,CAAA;AAAA,IAClD;AACA,IAAA,OAAO,MAAA;AAAA,EACT;AACF;;;ACbO,SAAS,oBAAoB,KAAA,EAAsC;AACxE,EAAA,OAAO,CAAC,KAAA,EAAO,WAAA,EAAa,SAAS,UAAU,CAAA,CAAE,SAAS,KAAK,CAAA;AACjE;AAOO,SAAS,mBAAA,GAAsC;AACpD,EAAA,OAAO,CAAC,KAAA,EAAO,WAAA,EAAa,OAAA,EAAS,UAAU,CAAA;AACjD;;;ACwTO,IAAM,kBAAA,GAAqB;AAC3B,IAAM,WAAA,GAAc","file":"index.js","sourcesContent":["/**\n * Branded string types for compile-time type safety\n *\n * These types are zero-cost at runtime but prevent mixing\n * different string types at compile time.\n */\n\nimport type { components } from './types';\n\n// ============================================================================\n// OPENAPI-GENERATED TYPES (use directly from spec)\n// ============================================================================\n\nexport type Motivation = components['schemas']['Motivation'];\nexport type ContentFormat = components['schemas']['ContentFormat'];\n\n// ============================================================================\n// AUTHENTICATION & TOKENS\n// ============================================================================\n\nexport type Email = string & { readonly __brand: 'Email' };\nexport type AuthCode = string & { readonly __brand: 'AuthCode' };\nexport type GoogleCredential = string & { readonly __brand: 'GoogleCredential' };\nexport type AccessToken = string & { readonly __brand: 'AccessToken' };\nexport type RefreshToken = string & { readonly __brand: 'RefreshToken' };\nexport type MCPToken = string & { readonly __brand: 'MCPToken' };\nexport type CloneToken = string & { readonly __brand: 'CloneToken' };\n\n// ============================================================================\n// SYSTEM IDENTIFIERS\n// ============================================================================\n\nexport type JobId = string & { readonly __brand: 'JobId' };\nexport type UserDID = string & { readonly __brand: 'UserDID' };\nexport type EntityType = string & { readonly __brand: 'EntityType' };\nexport type SearchQuery = string & { readonly __brand: 'SearchQuery' };\nexport type BaseUrl = string & { readonly __brand: 'BaseUrl' };\n\n// ============================================================================\n// HELPER FUNCTIONS (minimal validation, just branding)\n// ============================================================================\n\nexport function email(value: string): Email { return value as Email; }\nexport function authCode(value: string): AuthCode { return value as AuthCode; }\nexport function googleCredential(value: string): GoogleCredential { return value as GoogleCredential; }\nexport function accessToken(value: string): AccessToken { return value as AccessToken; }\nexport function refreshToken(value: string): RefreshToken { return value as RefreshToken; }\nexport function mcpToken(value: string): MCPToken { return value as MCPToken; }\nexport function cloneToken(value: string): CloneToken { return value as CloneToken; }\nexport function jobId(value: string): JobId { return value as JobId; }\nexport function userDID(value: string): UserDID { return value as UserDID; }\nexport function entityType(value: string): EntityType { return value as EntityType; }\nexport function searchQuery(value: string): SearchQuery { return value as SearchQuery; }\nexport function baseUrl(value: string): BaseUrl { return value as BaseUrl; }\n\n// Motivation and ContentFormat use OpenAPI enums - no helpers needed\n// Use the enum values directly from the OpenAPI spec\n\n// ============================================================================\n// HTTP URI TYPES\n// ============================================================================\n\n// Branded type definitions for HTTP URIs returned by the API\nexport type ResourceUri = string & { readonly __brand: 'ResourceUri' };\n\n// W3C flat format for content negotiation: http://localhost:4000/annotations/{id}\nexport type AnnotationUri = string & { readonly __brand: 'AnnotationUri' };\n\n// Nested format for CRUD operations: http://localhost:4000/resources/{resourceId}/annotations/{annotationId}\nexport type ResourceAnnotationUri = string & { readonly __brand: 'ResourceAnnotationUri' };\n\n// Factory functions with runtime validation\nexport function resourceUri(uri: string): ResourceUri {\n if (!uri.startsWith('http://') && !uri.startsWith('https://')) {\n throw new TypeError(`Expected ResourceUri, got: ${uri}`);\n }\n return uri as ResourceUri;\n}\n\nexport function annotationUri(uri: string): AnnotationUri {\n if (!uri.startsWith('http://') && !uri.startsWith('https://')) {\n throw new TypeError(`Expected AnnotationUri, got: ${uri}`);\n }\n return uri as AnnotationUri;\n}\n\nexport function resourceAnnotationUri(uri: string): ResourceAnnotationUri {\n if (!uri.startsWith('http://') && !uri.startsWith('https://')) {\n throw new TypeError(`Expected ResourceAnnotationUri, got: ${uri}`);\n }\n // Additional validation: must contain /resources/ and /annotations/\n if (!uri.includes('/resources/') || !uri.includes('/annotations/')) {\n throw new TypeError(`Expected nested ResourceAnnotationUri format, got: ${uri}`);\n }\n return uri as ResourceAnnotationUri;\n}\n","/**\n * Resource creation methods - How resources are created in the system\n */\n\n/**\n * Enumeration of all possible resource creation methods\n */\nexport const CREATION_METHODS = {\n API: 'api',\n UPLOAD: 'upload',\n UI: 'ui',\n REFERENCE: 'reference',\n CLI: 'cli',\n CLONE: 'clone',\n GENERATED: 'generated',\n} as const;\n\n/**\n * Type for resource creation methods\n */\nexport type CreationMethod = typeof CREATION_METHODS[keyof typeof CREATION_METHODS];","/**\n * Branded identifier types for compile-time type safety.\n *\n * These types prevent mixing up resource IDs, annotation IDs, and user IDs\n * at compile time while having zero runtime overhead.\n *\n * URI types (ResourceUri, AnnotationUri) are in @semiont/api-client\n * since they deal with HTTP URIs returned by the API.\n */\n\n// Branded type definitions for IDs only\nexport type ResourceId = string & { readonly __brand: 'ResourceId' };\nexport type AnnotationId = string & { readonly __brand: 'AnnotationId' };\nexport type UserId = string & { readonly __brand: 'UserId' };\n\n// Type guards with runtime validation\nexport function isResourceId(value: string): value is ResourceId {\n return !value.includes('/');\n}\n\nexport function isAnnotationId(value: string): value is AnnotationId {\n return !value.includes('/');\n}\n\n// Factory functions with runtime validation\nexport function resourceId(id: string): ResourceId {\n if (id.includes('/')) {\n throw new TypeError(`Expected ResourceId, got URI: ${id}`);\n }\n return id as ResourceId;\n}\n\nexport function annotationId(id: string): AnnotationId {\n if (id.includes('/')) {\n throw new TypeError(`Expected AnnotationId, got URI: ${id}`);\n }\n return id as AnnotationId;\n}\n\nexport function userId(id: string): UserId {\n return id as UserId;\n}\n","/**\n * Persisted Events\n *\n * The 18 event types that get appended to the JSONL event log.\n * Each maps a type string to its OpenAPI payload schema.\n * The PersistedEvent union derives from this catalog.\n */\n\nimport type { components } from './types';\nimport type { AnnotationId, ResourceId } from './identifiers';\nimport type { Annotation } from './annotation-types';\nimport type { EventBase } from './event-base';\n\n// Branded payload overrides — the OpenAPI schemas reference the raw\n// `Annotation` type with `id: string`. At the TypeScript layer we narrow\n// to the branded `Annotation` so consumers read `payload.annotation.id`\n// as `AnnotationId` without an upcast at every seam.\ntype AnnotationAddedPayload =\n components['schemas']['AnnotationAddedPayload'] & { annotation: Annotation };\ntype AnnotationRemovedPayload =\n components['schemas']['AnnotationRemovedPayload'] & { annotationId: AnnotationId };\ntype AnnotationBodyUpdatedPayload =\n components['schemas']['AnnotationBodyUpdatedPayload'] & { annotationId: AnnotationId };\n\n// ── The Catalog ──────────────────────────────────────────────────────────────\n\n/**\n * Maps each persisted event type string to its OpenAPI payload schema.\n * Single source of truth for \"what events get written to the log.\"\n */\ntype PersistedEventCatalog = {\n 'yield:created': components['schemas']['ResourceCreatedPayload'];\n 'yield:cloned': components['schemas']['ResourceClonedPayload'];\n 'yield:updated': components['schemas']['ResourceUpdatedPayload'];\n 'yield:moved': components['schemas']['ResourceMovedPayload'];\n 'yield:representation-added': components['schemas']['RepresentationAddedPayload'];\n 'yield:representation-removed': components['schemas']['RepresentationRemovedPayload'];\n 'mark:added': AnnotationAddedPayload;\n 'mark:removed': AnnotationRemovedPayload;\n 'mark:body-updated': AnnotationBodyUpdatedPayload;\n 'mark:archived': components['schemas']['ResourceArchivedPayload'];\n 'mark:unarchived': components['schemas']['ResourceUnarchivedPayload'];\n 'mark:entity-tag-added': components['schemas']['EntityTagChangedPayload'];\n 'mark:entity-tag-removed': components['schemas']['EntityTagChangedPayload'];\n 'frame:entity-type-added': components['schemas']['EntityTypeAddedPayload'];\n 'job:started': components['schemas']['JobStartedPayload'];\n 'job:progress': components['schemas']['JobProgressPayload'];\n 'job:completed': components['schemas']['JobCompletedPayload'];\n 'job:failed': components['schemas']['JobFailedPayload'];\n};\n\n// ── Derived types ────────────────────────────────────────────────────────────\n\n/** System event types — persisted events that have no resourceId. */\ntype SystemEventType = 'frame:entity-type-added';\n\n/** Extract the concrete persisted event type for a given type string. */\nexport type EventOfType<K extends keyof PersistedEventCatalog> =\n K extends SystemEventType\n ? EventBase & { type: K; payload: PersistedEventCatalog[K] }\n : EventBase & { type: K; resourceId: ResourceId; payload: PersistedEventCatalog[K] };\n\n/** The union of all 20 persisted event types. Discriminated on `type`. */\nexport type PersistedEvent = {\n [K in keyof PersistedEventCatalog]: EventOfType<K>\n}[keyof PersistedEventCatalog];\n\nexport type PersistedEventType = PersistedEvent['type'];\n\n/**\n * Runtime list of every persisted event type.\n *\n * Single source of truth for code that needs to enumerate event types at\n * runtime — most importantly the per-resource `events-stream` SSE route,\n * which subscribes to all of them. The exhaustiveness check below makes\n * it impossible to add a new member to `PersistedEventCatalog` without\n * also adding it here: forgetting fails to typecheck rather than silently\n * dropping the event from the events-stream.\n */\nexport const PERSISTED_EVENT_TYPES = [\n 'yield:created',\n 'yield:cloned',\n 'yield:updated',\n 'yield:moved',\n 'yield:representation-added',\n 'yield:representation-removed',\n 'mark:added',\n 'mark:removed',\n 'mark:body-updated',\n 'mark:archived',\n 'mark:unarchived',\n 'mark:entity-tag-added',\n 'mark:entity-tag-removed',\n 'frame:entity-type-added',\n 'job:started',\n 'job:progress',\n 'job:completed',\n 'job:failed',\n] as const satisfies readonly PersistedEventType[];\n\n// Compile-time exhaustiveness: if PersistedEventType gains a member that\n// PERSISTED_EVENT_TYPES is missing, this assignment fails to typecheck.\n// The ERROR object names the missing-member case so the build error is\n// self-explanatory.\ntype _ExhaustivePersistedEventTypes =\n Exclude<PersistedEventType, typeof PERSISTED_EVENT_TYPES[number]> extends never\n ? true\n : { ERROR: 'PERSISTED_EVENT_TYPES is missing members of PersistedEventType' };\nconst _persistedEventTypesExhaustive: _ExhaustivePersistedEventTypes = true;\nvoid _persistedEventTypesExhaustive;\n\n/** Input type for appendEvent — PersistedEvent without id/timestamp (assigned at persistence time). */\nexport type EventInput = Omit<PersistedEvent, 'id' | 'timestamp'>;\n","/**\n * Bus Protocol\n *\n * The complete EventMap for the RxJS EventBus. Every channel name and\n * its payload type is defined here — domain events, commands, reads,\n * results, SSE stream payloads, and frontend UI events.\n *\n * Identifier discipline: where a payload carries an annotation or\n * resource id, the TypeScript layer narrows the OpenAPI `string` to the\n * branded type (`AnnotationId`, `ResourceId`, `UserId`). The runtime\n * wire shape is unchanged (brands have no runtime representation);\n * what this buys us is that command handlers don't have to re-brand\n * at every seam. Brand once at the entry boundary (HTTP route handler,\n * DOM attribute read, URL param parse), not at every bus hop in\n * between. See `.plans/BRAND-UPSTREAM.md` for the rationale.\n *\n * Organized by flow (verb), then by category within each flow.\n */\n\nimport type { components } from './types';\nimport type { AnnotationId, ResourceId } from './identifiers';\nimport type { StoredEvent } from './event-base';\nimport type { EventOfType } from './persisted-events';\n\n// Branded overrides for OpenAPI command payloads that carry identifier\n// fields. Narrows `string` → branded at the TypeScript layer.\n//\n// `_userId` is the gateway-injected authenticated DID (string at the\n// schema layer); handlers that need a `UserId` brand it locally.\ntype MarkDeleteCommand =\n components['schemas']['MarkDeleteCommand'] & {\n annotationId: AnnotationId;\n resourceId?: ResourceId;\n };\ntype MarkUpdateBodyCommand =\n components['schemas']['MarkUpdateBodyCommand'] & {\n annotationId: AnnotationId;\n resourceId: ResourceId;\n };\ntype BindInitiateCommand =\n components['schemas']['BindInitiateCommand'] & {\n annotationId: AnnotationId;\n resourceId: ResourceId;\n };\ntype BindUpdateBodyCommand =\n components['schemas']['BindUpdateBodyCommand'] & {\n annotationId: AnnotationId;\n resourceId: ResourceId;\n };\n\n/**\n * The unified EventMap — every channel on the EventBus.\n *\n * Convention:\n * - Domain events (past tense): StoredEvent<Interface> — branded types\n * - Commands/reads/results/UI: OpenAPI schema refs — plain strings\n * - void: UI-only signals with no payload\n */\nexport type EventMap = {\n\n // ========================================================================\n // YIELD FLOW — resource creation, update, move, clone\n // ========================================================================\n\n // Domain events (branded — system of record)\n 'yield:created': StoredEvent<EventOfType<'yield:created'>>;\n 'yield:cloned': StoredEvent<EventOfType<'yield:cloned'>>;\n 'yield:updated': StoredEvent<EventOfType<'yield:updated'>>;\n 'yield:moved': StoredEvent<EventOfType<'yield:moved'>>;\n 'yield:representation-added': StoredEvent<EventOfType<'yield:representation-added'>>;\n 'yield:representation-removed': StoredEvent<EventOfType<'yield:representation-removed'>>;\n\n // Generation lifecycle flows through the unified job:* family\n // (job:start, job:report-progress, job:complete, job:fail). The\n // pre-unification `yield:progress`/`yield:finished`/`yield:failed`\n // channels were removed on the lifecycle-unification.\n\n // Commands\n 'yield:request': components['schemas']['YieldRequestCommand'];\n 'yield:create': components['schemas']['YieldCreateCommand'];\n 'yield:update': components['schemas']['YieldUpdateCommand'];\n 'yield:mv': components['schemas']['YieldMvCommand'];\n 'yield:clone': void;\n 'yield:clone-token-requested': components['schemas']['YieldCloneTokenRequest'];\n 'yield:clone-resource-requested': components['schemas']['YieldCloneResourceRequest'];\n 'yield:clone-create': components['schemas']['YieldCloneCreateCommand'];\n\n // Command results\n 'yield:create-ok': components['schemas']['YieldCreateOk'];\n 'yield:create-failed': components['schemas']['CommandError'];\n 'yield:update-ok': components['schemas']['YieldUpdateOk'];\n 'yield:update-failed': components['schemas']['YieldUpdateOk'] & components['schemas']['CommandError'];\n 'yield:move-ok': components['schemas']['YieldMoveOk'];\n 'yield:move-failed': { fromUri: string } & components['schemas']['CommandError'];\n 'yield:clone-token-generated': { correlationId: string; response: components['schemas']['CloneResourceWithTokenResponse'] };\n 'yield:clone-token-failed': { correlationId: string } & components['schemas']['CommandError'];\n 'yield:clone-resource-result': { correlationId: string; response: components['schemas']['GetResourceByTokenResponse'] };\n 'yield:clone-resource-failed': { correlationId: string } & components['schemas']['CommandError'];\n 'yield:clone-created': components['schemas']['YieldCloneCreated'];\n 'yield:clone-create-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n // ========================================================================\n // MARK FLOW — annotation CRUD, AI assist, resource lifecycle\n // ========================================================================\n\n // Domain events (branded — system of record)\n 'mark:added': StoredEvent<EventOfType<'mark:added'>>;\n 'mark:removed': StoredEvent<EventOfType<'mark:removed'>>;\n 'mark:body-updated': StoredEvent<EventOfType<'mark:body-updated'>>;\n 'mark:entity-tag-added': StoredEvent<EventOfType<'mark:entity-tag-added'>>;\n 'mark:entity-tag-removed': StoredEvent<EventOfType<'mark:entity-tag-removed'>>;\n 'mark:archived': StoredEvent<EventOfType<'mark:archived'>>;\n 'mark:unarchived': StoredEvent<EventOfType<'mark:unarchived'>>;\n\n // Annotation-job lifecycle flows through the unified job:* family\n // (job:start, job:report-progress, job:complete, job:fail). UI\n // consumers filter by jobType. The pre-unification channels\n // `mark:progress`/`mark:assist-finished`/`mark:assist-failed` were\n // removed on the lifecycle-unification.\n\n // Commands\n 'mark:create-request': components['schemas']['MarkCreateRequest'];\n 'mark:create': components['schemas']['MarkCreateCommand'];\n 'mark:delete': MarkDeleteCommand;\n 'mark:update-body': MarkUpdateBodyCommand;\n 'mark:archive': components['schemas']['MarkArchiveCommand'];\n 'mark:unarchive': components['schemas']['MarkUnarchiveCommand'];\n 'mark:update-entity-types': components['schemas']['MarkUpdateEntityTypesCommand'];\n\n // Command results\n 'mark:create-ok': components['schemas']['MarkCreateOk'];\n 'mark:create-failed': components['schemas']['CommandError'];\n 'mark:delete-ok': components['schemas']['MarkDeleteOk'];\n 'mark:delete-failed': components['schemas']['CommandError'];\n 'mark:body-update-failed': components['schemas']['CommandError'];\n\n // UI events\n 'mark:select-comment': components['schemas']['SelectionData'];\n 'mark:select-tag': components['schemas']['SelectionData'];\n 'mark:select-assessment': components['schemas']['SelectionData'];\n 'mark:select-reference': components['schemas']['SelectionData'];\n 'mark:requested': components['schemas']['MarkRequestedEvent'];\n 'mark:cancel-pending': void;\n 'mark:submit': components['schemas']['MarkSubmitEvent'];\n 'mark:assist-request': components['schemas']['MarkAssistRequestEvent'];\n 'mark:assist-cancelled': void;\n 'mark:progress-dismiss': void;\n 'mark:mode-toggled': void;\n 'mark:selection-changed': components['schemas']['MarkSelectionChangedEvent'];\n 'mark:click-changed': components['schemas']['MarkClickChangedEvent'];\n 'mark:shape-changed': components['schemas']['MarkShapeChangedEvent'];\n\n // ========================================================================\n // FRAME FLOW — schema-layer vocabulary (entity types; future tag schemas,\n // relation/predicate types, ontology import). The eighth flow.\n // ========================================================================\n\n // Domain events (branded — system of record). System-level: no resourceId.\n 'frame:entity-type-added': StoredEvent<EventOfType<'frame:entity-type-added'>>;\n\n // Commands\n 'frame:add-entity-type': components['schemas']['FrameAddEntityTypeCommand'];\n\n // Command results\n 'frame:entity-type-add-failed': components['schemas']['CommandError'];\n\n // ========================================================================\n // BIND FLOW — reference linking\n // ========================================================================\n\n 'bind:initiate': BindInitiateCommand;\n 'bind:update-body': BindUpdateBodyCommand;\n 'bind:body-updated': components['schemas']['BindBodyUpdated'];\n 'bind:body-update-failed': components['schemas']['CommandError'];\n\n // ========================================================================\n // MATCH FLOW — search\n // ========================================================================\n\n 'match:search-requested': components['schemas']['MatchSearchRequest'];\n 'match:search-results': components['schemas']['MatchSearchResult'];\n 'match:search-failed': components['schemas']['MatchSearchFailed'];\n\n // ========================================================================\n // GATHER FLOW — context gathering\n // ========================================================================\n\n 'gather:requested': components['schemas']['GatherAnnotationRequest'];\n 'gather:complete': components['schemas']['GatherAnnotationComplete'];\n 'gather:failed': { correlationId: string; annotationId: string } & components['schemas']['CommandError'];\n 'gather:resource-requested': components['schemas']['GatherResourceRequest'];\n 'gather:resource-complete': components['schemas']['GatherResourceComplete'];\n 'gather:resource-failed': { correlationId: string; resourceId: string } & components['schemas']['CommandError'];\n\n 'gather:summary-requested': components['schemas']['GatherSummaryRequest'];\n 'gather:summary-result': { correlationId: string; response: Record<string, unknown> };\n 'gather:summary-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n // SSE stream payloads\n 'gather:annotation-progress': components['schemas']['GatherProgress'];\n 'gather:annotation-finished': components['schemas']['GatherAnnotationFinished'];\n 'gather:progress': components['schemas']['GatherProgress'];\n 'gather:finished': components['schemas']['GatherFinished'];\n\n // ========================================================================\n // BROWSE FLOW — knowledge base reads + UI navigation\n // ========================================================================\n\n // Reads\n 'browse:resource-requested': components['schemas']['BrowseResourceRequest'];\n 'browse:resource-result': components['schemas']['BrowseResourceResult'];\n 'browse:resource-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n 'browse:resources-requested': components['schemas']['BrowseResourcesRequest'];\n 'browse:resources-result': components['schemas']['BrowseResourcesResult'];\n 'browse:resources-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n 'browse:annotations-requested': components['schemas']['BrowseAnnotationsRequest'];\n 'browse:annotations-result': components['schemas']['BrowseAnnotationsResult'];\n 'browse:annotations-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n 'browse:annotation-requested': components['schemas']['BrowseAnnotationRequest'];\n 'browse:annotation-result': components['schemas']['BrowseAnnotationResult'];\n 'browse:annotation-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n 'browse:events-requested': components['schemas']['BrowseEventsRequest'];\n 'browse:events-result': components['schemas']['BrowseEventsResult'];\n 'browse:events-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n 'browse:annotation-history-requested': components['schemas']['BrowseAnnotationHistoryRequest'];\n 'browse:annotation-history-result': components['schemas']['BrowseAnnotationHistoryResult'];\n 'browse:annotation-history-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n 'browse:annotation-context-requested': components['schemas']['BrowseAnnotationContextRequest'];\n 'browse:annotation-context-result': { correlationId: string; response: Record<string, unknown> };\n 'browse:annotation-context-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n 'browse:referenced-by-requested': components['schemas']['BrowseReferencedByRequest'];\n 'browse:referenced-by-result': components['schemas']['BrowseReferencedByResult'];\n 'browse:referenced-by-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n 'browse:entity-types-requested': components['schemas']['BrowseEntityTypesRequest'];\n 'browse:entity-types-result': components['schemas']['BrowseEntityTypesResult'];\n 'browse:entity-types-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n 'browse:directory-requested': components['schemas']['BrowseDirectoryRequest'];\n 'browse:directory-result': components['schemas']['BrowseDirectoryResult'];\n 'browse:directory-failed': { correlationId: string; path: string } & components['schemas']['CommandError'];\n\n // UI events (session-scoped — fire on the client bus, tied to a KB)\n 'browse:click': components['schemas']['BrowseClickEvent'];\n 'browse:reference-navigate': components['schemas']['BrowseReferenceNavigateEvent'];\n 'browse:entity-type-clicked': components['schemas']['BrowseEntityTypeClickedEvent'];\n\n // ========================================================================\n // SHELL — app-scoped UI events (fire on SemiontBrowser's bus, not the\n // per-session client bus). These must work regardless of whether a\n // KB session is active: panel toggles, sidebar, tab bar, routing.\n // ========================================================================\n\n 'panel:toggle': components['schemas']['BrowsePanelToggleEvent'];\n 'panel:open': components['schemas']['BrowsePanelOpenEvent'];\n 'panel:close': void;\n 'shell:sidebar-toggle': void;\n 'tabs:close': components['schemas']['BrowseResourceCloseEvent'];\n 'tabs:reorder': components['schemas']['BrowseResourceReorderEvent'];\n 'nav:link-clicked': components['schemas']['BrowseLinkClickedEvent'];\n 'nav:push': components['schemas']['BrowseRouterPushEvent'];\n 'nav:external': components['schemas']['BrowseExternalNavigateEvent'] & { cancelFallback: () => void };\n\n // ========================================================================\n // BECKON FLOW — annotation attention\n // ========================================================================\n\n 'beckon:hover': components['schemas']['BeckonHoverEvent'];\n 'beckon:focus': components['schemas']['BeckonFocusEvent'];\n 'beckon:sparkle': components['schemas']['BeckonSparkleEvent'];\n\n // ========================================================================\n // JOB FLOW — worker commands + domain events\n // ========================================================================\n\n // Domain events (branded — system of record)\n 'job:started': StoredEvent<EventOfType<'job:started'>>;\n 'job:progress': StoredEvent<EventOfType<'job:progress'>>;\n 'job:completed': StoredEvent<EventOfType<'job:completed'>>;\n 'job:failed': StoredEvent<EventOfType<'job:failed'>>;\n\n // Commands\n 'job:start': components['schemas']['JobStartCommand'];\n 'job:report-progress': components['schemas']['JobReportProgressCommand'];\n 'job:complete': components['schemas']['JobCompleteCommand'];\n 'job:fail': components['schemas']['JobFailCommand'];\n 'job:queued': components['schemas']['JobQueuedEvent'];\n 'job:cancel-requested': components['schemas']['JobCancelRequest'];\n 'job:status-requested': components['schemas']['JobStatusRequest'];\n 'job:create': components['schemas']['JobCreateCommand'];\n 'job:claim': components['schemas']['JobClaimCommand'];\n\n // Results\n 'job:status-result': components['schemas']['JobStatusResult'];\n 'job:status-failed': { correlationId: string } & components['schemas']['CommandError'];\n 'job:created': components['schemas']['JobCreatedResult'];\n 'job:create-failed': { correlationId: string } & components['schemas']['CommandError'];\n 'job:claimed': { correlationId: string; response: Record<string, unknown> };\n 'job:claim-failed': { correlationId: string } & components['schemas']['CommandError'];\n\n // ========================================================================\n // SETTINGS (frontend-only)\n // ========================================================================\n\n 'settings:theme-changed': components['schemas']['SettingsThemeChangedEvent'];\n 'settings:line-numbers-toggled': void;\n 'settings:locale-changed': components['schemas']['SettingsLocaleChangedEvent'];\n 'settings:hover-delay-changed': components['schemas']['SettingsHoverDelayChangedEvent'];\n\n // ========================================================================\n // SSE infrastructure\n // ========================================================================\n\n 'stream-connected': Record<string, never>;\n 'replay-window-exceeded': { resourceId?: string; lastEventId: number; missedCount: number; cap: number; message: string };\n /**\n * Emitted by the `/bus/subscribe` handler when a client reconnected\n * with `Last-Event-ID: p-<scope>-<seq>` but the server could not\n * replay all missed persisted events for that scope (retention\n * window exceeded, scope unknown, or request unparseable). The\n * client should treat this as a signal to fall back to the pre-\n * resumption contract: invalidate caches for the affected scope\n * and re-read from scratch. Analogous to `replay-window-exceeded`\n * but scoped to the bus gateway rather than the per-resource\n * events stream.\n *\n * `scope` is the scope string the client asked about (omitted for\n * global-persisted resumption gaps, if that path ever exists).\n * `reason` is human-readable, for logging.\n */\n 'bus:resume-gap': { scope?: string; lastSeenId?: string; reason: string };\n};\n\n/** Any valid channel name on the EventBus. */\nexport type EventName = keyof EventMap;\n\n/**\n * Genuine resource-bound broadcast event types.\n *\n * Publishers emit these on the scoped EventBus (`eventBus.scope(resourceId)`)\n * because every participant viewing the resource should receive them — not\n * just the caller who triggered the originating action. Examples: resource\n * generation progress, which multiple viewers of a generating resource all\n * want to see.\n *\n * Non-broadcast progress (AI-assist progress for one user, search results\n * for one caller) does NOT belong here. Those are per-caller correlation-ID\n * responses and publish globally — the caller filters by `correlationId`.\n *\n * The frontend's `subscribeToResource(id)` wires these channels via\n * `scope=id&scoped=<channel>` so the SSE route delivers them to that\n * participant. WorkerStateUnit uses this list to decide which emitted events to\n * scope to their resource.\n */\n/**\n * Audit note (SIMPLE-BUS Phase 3 close): `yield:progress` was\n * considered for inclusion but has only one consumer — the\n * yield-initiator's Observable in `packages/api-client/src/namespaces/yield.ts`.\n * No viewer of the resource other than the initiator subscribes to\n * progress. Scoping therefore serves no fan-out-narrowing purpose for\n * that channel, so it stays global (as a correlation-ID-shaped\n * response, filtered by `referenceId`). Only `yield:finished` and\n * `yield:failed` have a genuine multi-participant consumer (the\n * ResourceViewerPage toast on the source resource).\n */\nexport const RESOURCE_BROADCAST_TYPES = [\n // Post-unification: job:complete / job:fail carry the \"job ended on\n // this resource\" signal that yield:finished / yield:failed used to.\n // Scope them by resource so every viewer of the affected resource\n // — not just the initiator — can react (toast, refresh, etc.).\n 'job:complete',\n 'job:fail',\n] as const satisfies readonly EventName[];\n\nexport type ResourceBroadcastType = typeof RESOURCE_BROADCAST_TYPES[number];\n\n/**\n * Authoritative map from bus channel to OpenAPI schema name.\n *\n * Every {@link EventName} must appear. The `satisfies` clause below\n * enforces completeness at compile time — adding a channel to\n * {@link EventMap} without adding an entry here is a build error.\n *\n * Values:\n * - `<SchemaName>`: payload validates against `components['schemas'][SchemaName]`.\n * - `null`: no single-schema validation. Used for branded\n * `StoredEvent` wrappers, `void` UI signals, and compound inline\n * types (e.g. `{ correlationId } & CommandError`). These are not\n * validated by `/bus/emit`.\n *\n * The `/bus/emit` route reads this map to validate incoming payloads.\n * Consumers can also use it to do client-side pre-flight validation\n * before emitting.\n */\nexport const CHANNEL_SCHEMAS = {\n // ── YIELD FLOW ──────────────────────────────────────────────────\n 'yield:created': null, // StoredEvent\n 'yield:cloned': null,\n 'yield:updated': null,\n 'yield:moved': null,\n 'yield:representation-added': null,\n 'yield:representation-removed': null,\n 'yield:request': 'YieldRequestCommand',\n 'yield:create': 'YieldCreateCommand',\n 'yield:update': 'YieldUpdateCommand',\n 'yield:mv': 'YieldMvCommand',\n 'yield:clone': null, // void\n 'yield:clone-token-requested': 'YieldCloneTokenRequest',\n 'yield:clone-resource-requested': 'YieldCloneResourceRequest',\n 'yield:clone-create': 'YieldCloneCreateCommand',\n 'yield:create-ok': 'YieldCreateOk',\n 'yield:create-failed': 'CommandError',\n 'yield:update-ok': 'YieldUpdateOk',\n 'yield:update-failed': null, // YieldUpdateOk & CommandError\n 'yield:move-ok': 'YieldMoveOk',\n 'yield:move-failed': null, // { fromUri } & CommandError\n 'yield:clone-token-generated': null, // { correlationId; response: CloneResourceWithTokenResponse }\n 'yield:clone-token-failed': null, // { correlationId } & CommandError\n 'yield:clone-resource-result': null, // { correlationId; response: GetResourceByTokenResponse }\n 'yield:clone-resource-failed': null, // { correlationId } & CommandError\n 'yield:clone-created': 'YieldCloneCreated',\n 'yield:clone-create-failed': null, // { correlationId } & CommandError\n\n // ── MARK FLOW ───────────────────────────────────────────────────\n 'mark:added': null, // StoredEvent\n 'mark:removed': null,\n 'mark:body-updated': null,\n 'mark:entity-tag-added': null,\n 'mark:entity-tag-removed': null,\n 'frame:entity-type-added': null,\n 'mark:archived': null,\n 'mark:unarchived': null,\n 'mark:create-request': 'MarkCreateRequest',\n 'mark:create': 'MarkCreateCommand',\n 'mark:delete': 'MarkDeleteCommand',\n 'mark:update-body': 'MarkUpdateBodyCommand',\n 'mark:archive': 'MarkArchiveCommand',\n 'mark:unarchive': 'MarkUnarchiveCommand',\n 'mark:update-entity-types': 'MarkUpdateEntityTypesCommand',\n 'frame:add-entity-type': 'FrameAddEntityTypeCommand',\n 'mark:create-ok': 'MarkCreateOk',\n 'mark:create-failed': 'CommandError',\n 'mark:delete-ok': 'MarkDeleteOk',\n 'mark:delete-failed': 'CommandError',\n 'mark:body-update-failed': 'CommandError',\n 'frame:entity-type-add-failed': 'CommandError',\n 'mark:select-comment': 'SelectionData',\n 'mark:select-tag': 'SelectionData',\n 'mark:select-assessment': 'SelectionData',\n 'mark:select-reference': 'SelectionData',\n 'mark:requested': 'MarkRequestedEvent',\n 'mark:cancel-pending': null, // void\n 'mark:submit': 'MarkSubmitEvent',\n 'mark:assist-request': 'MarkAssistRequestEvent',\n 'mark:assist-cancelled': null, // void\n 'mark:progress-dismiss': null, // void\n 'mark:mode-toggled': null, // void\n 'mark:selection-changed': 'MarkSelectionChangedEvent',\n 'mark:click-changed': 'MarkClickChangedEvent',\n 'mark:shape-changed': 'MarkShapeChangedEvent',\n\n // ── BIND FLOW ───────────────────────────────────────────────────\n 'bind:initiate': 'BindInitiateCommand',\n 'bind:update-body': 'BindUpdateBodyCommand',\n 'bind:body-updated': 'BindBodyUpdated',\n 'bind:body-update-failed': 'CommandError',\n\n // ── MATCH FLOW ──────────────────────────────────────────────────\n 'match:search-requested': 'MatchSearchRequest',\n 'match:search-results': 'MatchSearchResult',\n 'match:search-failed': 'MatchSearchFailed',\n\n // ── GATHER FLOW ─────────────────────────────────────────────────\n 'gather:requested': 'GatherAnnotationRequest',\n 'gather:complete': 'GatherAnnotationComplete',\n 'gather:failed': null, // { correlationId; annotationId } & CommandError\n 'gather:resource-requested': 'GatherResourceRequest',\n 'gather:resource-complete': 'GatherResourceComplete',\n 'gather:resource-failed': null, // { correlationId; resourceId } & CommandError\n 'gather:summary-requested': 'GatherSummaryRequest',\n 'gather:summary-result': null, // { correlationId; response: Record<string, unknown> }\n 'gather:summary-failed': null, // { correlationId } & CommandError\n 'gather:annotation-progress': 'GatherProgress',\n 'gather:annotation-finished': 'GatherAnnotationFinished',\n 'gather:progress': 'GatherProgress',\n 'gather:finished': 'GatherFinished',\n\n // ── BROWSE FLOW ─────────────────────────────────────────────────\n 'browse:resource-requested': 'BrowseResourceRequest',\n 'browse:resource-result': 'BrowseResourceResult',\n 'browse:resource-failed': null, // { correlationId } & CommandError\n 'browse:resources-requested': 'BrowseResourcesRequest',\n 'browse:resources-result': 'BrowseResourcesResult',\n 'browse:resources-failed': null,\n 'browse:annotations-requested': 'BrowseAnnotationsRequest',\n 'browse:annotations-result': 'BrowseAnnotationsResult',\n 'browse:annotations-failed': null,\n 'browse:annotation-requested': 'BrowseAnnotationRequest',\n 'browse:annotation-result': 'BrowseAnnotationResult',\n 'browse:annotation-failed': null,\n 'browse:events-requested': 'BrowseEventsRequest',\n 'browse:events-result': 'BrowseEventsResult',\n 'browse:events-failed': null,\n 'browse:annotation-history-requested': 'BrowseAnnotationHistoryRequest',\n 'browse:annotation-history-result': 'BrowseAnnotationHistoryResult',\n 'browse:annotation-history-failed': null,\n 'browse:annotation-context-requested': 'BrowseAnnotationContextRequest',\n 'browse:annotation-context-result': null, // { correlationId; response: Record<string, unknown> }\n 'browse:annotation-context-failed': null,\n 'browse:referenced-by-requested': 'BrowseReferencedByRequest',\n 'browse:referenced-by-result': 'BrowseReferencedByResult',\n 'browse:referenced-by-failed': null,\n 'browse:entity-types-requested': 'BrowseEntityTypesRequest',\n 'browse:entity-types-result': 'BrowseEntityTypesResult',\n 'browse:entity-types-failed': null,\n 'browse:directory-requested': 'BrowseDirectoryRequest',\n 'browse:directory-result': 'BrowseDirectoryResult',\n 'browse:directory-failed': null, // { correlationId; path } & CommandError\n 'browse:click': 'BrowseClickEvent',\n 'browse:reference-navigate': 'BrowseReferenceNavigateEvent',\n 'browse:entity-type-clicked': 'BrowseEntityTypeClickedEvent',\n\n // ── SHELL (app-scoped UI events, fire on SemiontBrowser bus) ────\n 'panel:toggle': 'BrowsePanelToggleEvent',\n 'panel:open': 'BrowsePanelOpenEvent',\n 'panel:close': null, // void\n 'shell:sidebar-toggle': null, // void\n 'tabs:close': 'BrowseResourceCloseEvent',\n 'tabs:reorder': 'BrowseResourceReorderEvent',\n 'nav:link-clicked': 'BrowseLinkClickedEvent',\n 'nav:push': 'BrowseRouterPushEvent',\n 'nav:external': null, // includes runtime `cancelFallback: () => void`\n\n // ── BECKON FLOW ─────────────────────────────────────────────────\n 'beckon:hover': 'BeckonHoverEvent',\n 'beckon:focus': 'BeckonFocusEvent',\n 'beckon:sparkle': 'BeckonSparkleEvent',\n\n // ── JOB FLOW ────────────────────────────────────────────────────\n 'job:started': null, // StoredEvent\n 'job:progress': null,\n 'job:completed': null,\n 'job:failed': null,\n 'job:start': 'JobStartCommand',\n 'job:report-progress': 'JobReportProgressCommand',\n 'job:complete': 'JobCompleteCommand',\n 'job:fail': 'JobFailCommand',\n 'job:queued': 'JobQueuedEvent',\n 'job:cancel-requested': 'JobCancelRequest',\n 'job:status-requested': 'JobStatusRequest',\n 'job:create': 'JobCreateCommand',\n 'job:claim': 'JobClaimCommand',\n 'job:status-result': 'JobStatusResult',\n 'job:status-failed': null, // { correlationId } & CommandError\n 'job:created': 'JobCreatedResult',\n 'job:create-failed': null,\n 'job:claimed': null, // { correlationId; response: Record<string, unknown> }\n 'job:claim-failed': null,\n\n // ── SETTINGS (frontend-only) ────────────────────────────────────\n 'settings:theme-changed': 'SettingsThemeChangedEvent',\n 'settings:line-numbers-toggled': null, // void\n 'settings:locale-changed': 'SettingsLocaleChangedEvent',\n 'settings:hover-delay-changed': 'SettingsHoverDelayChangedEvent',\n\n // ── SSE infrastructure ──────────────────────────────────────────\n 'stream-connected': null, // Record<string, never>\n 'replay-window-exceeded': null, // inline payload\n 'bus:resume-gap': null, // inline payload\n} as const satisfies Record<EventName, keyof components['schemas'] | null>;\n\n/** Channels where `/bus/emit` validates the payload (non-null schema). */\nexport type EmittableChannel = {\n [K in EventName]: typeof CHANNEL_SCHEMAS[K] extends null ? never : K\n}[EventName];\n","/**\n * Event Type Guards and Extraction Utilities\n *\n * Domain logic for working with resource events.\n * No React dependencies - safe to use in any JavaScript environment.\n */\n\nimport type { StoredEvent } from './event-base';\nimport type { AnnotationUri } from './branded-types';\n\n/**\n * Minimal event shape accepted by event utility functions.\n * Compatible with both the internal `StoredEvent` type and the OpenAPI-derived\n * schema type (`GetEventsResponse['events'][number]`), which lacks `version`.\n *\n * Flat shape — event fields and metadata are peers (no `event` wrapper).\n */\nexport interface StoredEventLike {\n id: string;\n type: string; // Intentionally loose — accepts OpenAPI-derived types where type is string\n timestamp: string;\n userId: string;\n resourceId?: string;\n payload?: unknown;\n metadata: {\n sequenceNumber: number;\n };\n}\n\n// =============================================================================\n// EVENT TYPE GUARDS AND EXTRACTION\n// =============================================================================\n\n/**\n * Extract annotation ID from event payload\n * Returns null if event is not annotation-related\n *\n * For mark:added: extracts full URI from payload.annotation.id\n * For mark:removed/mark:body-updated: constructs full URI from payload.annotationId (UUID) + resourceId\n */\nexport function getAnnotationUriFromEvent(event: StoredEventLike): AnnotationUri | null {\n const payload = event.payload as Record<string, any> | undefined;\n\n if (event.type === 'mark:added') {\n return payload?.annotation?.id as AnnotationUri || null;\n }\n\n if (event.type === 'mark:removed' || event.type === 'mark:body-updated') {\n if (payload?.annotationId && event.resourceId) {\n try {\n const resourceUri = event.resourceId;\n const baseUrl = resourceUri.substring(0, resourceUri.lastIndexOf('/resources/'));\n return `${baseUrl}/annotations/${payload.annotationId}` as AnnotationUri;\n } catch (e) {\n return null;\n }\n }\n }\n\n return null;\n}\n\n/**\n * Check if an event is related to a specific annotation\n */\nexport function isEventRelatedToAnnotation(event: StoredEventLike, annotationUri: AnnotationUri): boolean {\n const eventAnnotationUri = getAnnotationUriFromEvent(event);\n return eventAnnotationUri === annotationUri;\n}\n\n/**\n * Type guard to check if an object is a StoredEvent (flat shape)\n */\nexport function isStoredEvent(event: any): event is StoredEvent {\n return event &&\n typeof event.id === 'string' &&\n typeof event.timestamp === 'string' &&\n typeof event.type === 'string' &&\n typeof event.metadata === 'object' &&\n typeof event.metadata.sequenceNumber === 'number';\n}\n\n","/**\n * Bus logging — runtime-toggleable cross-wire visibility.\n *\n * One line per event that crosses a process boundary, in a grep-able\n * format that's symmetric across frontend and backend:\n *\n * [bus EMIT] <channel> [scope=X] [cid=<first8>] <payload>\n * [bus RECV] <channel> [scope=X] [cid=<first8>] <payload>\n * [bus SSE] <channel> [scope=X] [cid=<first8>] <payload>\n *\n * Tier 1 of `.plans/OBSERVABILITY.md`. Forward-compatible with Tier 2:\n * the `cid` printed here is exactly the prefix of the W3C trace-id we\n * adopt later.\n *\n * Cost when disabled: one property read per call, zero allocations.\n *\n * Enable:\n * - Browser: `window.__SEMIONT_BUS_LOG__ = true` (DevTools or e2e init)\n * - Node: `SEMIONT_BUS_LOG=1` in the process env (read at module load)\n */\n\nconst NODE_BUS_LOG =\n typeof process !== 'undefined' && !!process.env?.SEMIONT_BUS_LOG;\n\nexport type BusOp = 'EMIT' | 'RECV' | 'SSE' | 'PUT' | 'GET';\n\nexport function busLogEnabled(): boolean {\n const g = globalThis as { __SEMIONT_BUS_LOG__?: boolean };\n if (g.__SEMIONT_BUS_LOG__) return true;\n return NODE_BUS_LOG;\n}\n\n/**\n * Optional active-span trace-id provider. When a Tier 2 OTel SDK is\n * initialized, `@semiont/observability` registers a provider here that\n * returns the active span's W3C `trace_id`. busLog appends it to each\n * emitted line so the grep-timeline correlates with the span tree in\n * an APM UI.\n *\n * Decoupling: `@semiont/core` does not depend on `@opentelemetry/api`.\n * If no provider is registered (Tier 1-only deployments, or before\n * `initObservabilityNode` runs), the field is omitted from the line —\n * same shape as before this hook existed.\n */\nlet traceIdProvider: (() => string | undefined) | undefined;\n\nexport function setBusLogTraceIdProvider(fn: (() => string | undefined) | undefined): void {\n traceIdProvider = fn;\n}\n\nexport function busLog(\n op: BusOp,\n channel: string,\n payload: unknown,\n scope?: string,\n): void {\n if (!busLogEnabled()) return;\n const cidRaw = (payload as { correlationId?: unknown } | null | undefined)?.correlationId;\n const cid = typeof cidRaw === 'string' ? cidRaw.slice(0, 8) : undefined;\n let traceId: string | undefined;\n if (traceIdProvider) {\n try { traceId = traceIdProvider(); } catch { /* noop */ }\n }\n const tag =\n `[bus ${op}] ${channel}` +\n (scope ? ` scope=${scope}` : '') +\n (cid ? ` cid=${cid}` : '') +\n (traceId ? ` trace=${traceId.slice(0, 8)}` : '');\n // eslint-disable-next-line no-console\n console.debug(tag, payload);\n}\n","/**\n * RxJS-based Event Bus\n *\n * Framework-agnostic event bus providing direct access to typed RxJS Subjects.\n *\n * Can be used in Node.js, browser, workers, CLI - anywhere RxJS runs.\n */\n\nimport { Subject } from 'rxjs';\nimport { busLog, busLogEnabled } from './bus-log';\nimport type { EventMap } from './bus-protocol';\nimport type { StoredEvent } from './event-base';\nimport type { PersistedEventType } from './persisted-events';\n\n/**\n * RxJS-based event bus\n *\n * Provides direct access to RxJS Subjects for each event type.\n * Use standard RxJS patterns for emitting and subscribing.\n *\n * @example\n * ```typescript\n * const eventBus = new EventBus();\n *\n * // Emit events\n * eventBus.get('beckon:hover').next({ annotationId: 'ann-1' });\n *\n * // Subscribe to events\n * const subscription = eventBus.get('beckon:hover').subscribe(({ annotationId }) => {\n * console.log('Hover:', annotationId);\n * });\n *\n * // Use RxJS operators\n * import { debounceTime } from 'rxjs/operators';\n * eventBus.get('beckon:hover')\n * .pipe(debounceTime(100))\n * .subscribe(handleHover);\n *\n * // Cleanup\n * subscription.unsubscribe();\n * eventBus.destroy();\n * ```\n */\nexport class EventBus {\n private subjects: Map<keyof EventMap, Subject<any>>;\n private isDestroyed: boolean;\n\n constructor() {\n this.subjects = new Map();\n this.isDestroyed = false;\n }\n\n /**\n * Get the RxJS Subject for an event\n *\n * Returns a typed Subject that can be used with all RxJS operators.\n * Subjects are created lazily on first access.\n *\n * @param eventName - The event name\n * @returns The RxJS Subject for this event\n *\n * @example\n * ```typescript\n * // Emit\n * eventBus.get('beckon:hover').next({ annotationId: 'ann-1' });\n *\n * // Subscribe\n * const sub = eventBus.get('beckon:hover').subscribe(handleHover);\n *\n * // With operators\n * eventBus.get('beckon:hover')\n * .pipe(debounceTime(100), distinctUntilChanged())\n * .subscribe(handleHover);\n * ```\n */\n get<K extends keyof EventMap>(eventName: K): Subject<EventMap[K]> {\n if (this.isDestroyed) {\n throw new Error(`Cannot access event '${String(eventName)}' on destroyed bus`);\n }\n\n if (!this.subjects.has(eventName)) {\n const subject = new Subject<EventMap[K]>();\n // When bus-log is enabled (`SEMIONT_BUS_LOG=1` or\n // `window.__SEMIONT_BUS_LOG__ = true`), wrap `.next()` so every\n // local emit on this channel produces a `[bus EMIT] <channel> ...`\n // line on `console.debug` — same shape as cross-wire emits from\n // HttpTransport. This is what makes local-only fan-out signals\n // (`beckon.hover`, `beckon.sparkle`, `mark.changeShape`, etc.)\n // visible to the e2e bus capture and to a developer's DevTools.\n // The `busLogEnabled()` check is at first-`get` time per channel;\n // setting the flag after channels are constructed won't\n // retroactively wrap them. The bus capture fixture uses\n // `addInitScript` so the flag is set before any namespace\n // construction, which is when `get()` is first called.\n if (busLogEnabled()) {\n const originalNext = subject.next.bind(subject);\n subject.next = (value: EventMap[K]): void => {\n busLog('EMIT', String(eventName), value as object);\n originalNext(value);\n };\n }\n this.subjects.set(eventName, subject);\n }\n return this.subjects.get(eventName)!;\n }\n\n /**\n * Get the RxJS Subject for a domain event type (PersistedEventType).\n *\n * Domain event channels carry `StoredEvent`. This method avoids the need\n * for `as keyof EventMap` casts when subscribing to domain event channels\n * using runtime `PersistedEventType` strings.\n */\n getDomainEvent(eventType: PersistedEventType): Subject<StoredEvent> {\n return this.get(eventType as keyof EventMap) as unknown as Subject<StoredEvent>;\n }\n\n /**\n * Destroy the event bus and complete all subjects\n *\n * After calling destroy(), no new events can be emitted or subscribed to.\n * All active subscriptions will be completed.\n */\n destroy(): void {\n if (this.isDestroyed) {\n return;\n }\n\n for (const subject of this.subjects.values()) {\n subject.complete();\n }\n\n this.subjects.clear();\n this.isDestroyed = true;\n }\n\n /**\n * Check if the event bus has been destroyed\n */\n get destroyed(): boolean {\n return this.isDestroyed;\n }\n\n /**\n * Create a resource-scoped event bus\n *\n * Events emitted or subscribed through the scoped bus are isolated to that resource.\n * Internally, events are namespaced but the API remains identical to the parent bus.\n *\n * @param resourceId - Resource identifier to scope events to\n * @returns A scoped event bus for this resource\n *\n * @example\n * ```typescript\n * const eventBus = new EventBus();\n * const resource1 = eventBus.scope('resource-1');\n * const resource2 = eventBus.scope('resource-2');\n *\n * // These are isolated - only resource1 subscribers will fire\n * resource1.get('detection:progress').next({ status: 'started' });\n * ```\n */\n scope(resourceId: string): ScopedEventBus {\n return new ScopedEventBus(this, resourceId);\n }\n}\n\n/**\n * Resource-scoped event bus\n *\n * Provides isolated event streams per resource while maintaining the same API\n * as the parent EventBus. Events are internally namespaced by resourceId.\n */\nexport class ScopedEventBus {\n constructor(\n private parent: EventBus,\n private scopePrefix: string\n ) {}\n\n /**\n * Get the RxJS Subject for a scoped event\n *\n * Returns the same type as the parent bus, but events are isolated to this scope.\n * Internally uses namespaced keys but preserves type safety.\n *\n * @param event - The event name\n * @returns The RxJS Subject for this scoped event\n */\n get<E extends keyof EventMap>(event: E): Subject<EventMap[E]> {\n // Internally namespace the event key, but preserve return type\n const scopedKey = `${this.scopePrefix}:${event as string}`;\n\n // Access parent's subjects map directly (needs cast for private access)\n const parentSubjects = (this.parent as any).subjects as Map<string, Subject<any>>;\n\n if (!parentSubjects.has(scopedKey)) {\n parentSubjects.set(scopedKey, new Subject<EventMap[E]>());\n }\n return parentSubjects.get(scopedKey)!;\n }\n\n /** Get the RxJS Subject for a domain event type on this scoped bus. */\n getDomainEvent(eventType: PersistedEventType): Subject<StoredEvent> {\n return this.get(eventType as keyof EventMap) as unknown as Subject<StoredEvent>;\n }\n\n /**\n * Create a nested scope\n *\n * Allows hierarchical scoping like `resource-1:subsystem-a`\n *\n * @param subScope - Additional scope level\n * @returns A nested scoped event bus\n */\n scope(subScope: string): ScopedEventBus {\n return new ScopedEventBus(this.parent, `${this.scopePrefix}:${subScope}`);\n }\n}\n","/**\n * Adaptive burst buffer RxJS operator.\n *\n * Passes the first event through immediately (zero latency for interactive use).\n * If more events arrive within the burst window, switches to accumulate mode\n * and flushes batches. Returns to passthrough mode after an idle period.\n *\n * Emits individual items (T) in passthrough mode and arrays (T[]) in batch mode.\n * Consumers distinguish via Array.isArray().\n *\n * Threshold tuning:\n * burstWindowMs — How long to wait for more events before flushing a batch.\n * 50ms is a good default: longer than event-loop jitter (~1-5ms)\n * but short enough to feel responsive.\n * maxBatchSize — Force-flush at this size to bound memory. 500 is safe for\n * Neo4j UNWIND queries. Increase if graph writes are cheap.\n * idleTimeoutMs — How long after the last flush before returning to passthrough.\n * 200ms is a good default. Must be >= burstWindowMs.\n *\n * See: BATCH-GRAPH-CONSUMER-RX.md for design rationale.\n * See: packages/graph/docs/ARCHITECTURE.md for graph consumer context.\n */\n\nimport { Observable, OperatorFunction } from 'rxjs';\n\nexport interface BurstBufferOptions {\n /**\n * Time window (ms) to detect burst activity after an event.\n * If another event arrives within this window, it is buffered.\n * The buffer flushes when no new event arrives for this duration (debounce).\n *\n * Recommended: 50ms.\n */\n burstWindowMs: number;\n\n /**\n * Maximum events to accumulate before forcing a flush.\n * Prevents unbounded memory growth during sustained bursts.\n *\n * Recommended: 500.\n */\n maxBatchSize: number;\n\n /**\n * Time (ms) of silence after the last flush before returning to passthrough mode.\n * The next event after this timeout emits immediately (leading edge).\n * Must be >= burstWindowMs.\n *\n * Recommended: 200ms.\n */\n idleTimeoutMs: number;\n}\n\n/**\n * Adaptive burst buffer operator.\n *\n * State machine:\n * PASSTHROUGH → event arrives → emit immediately, transition to ACCUMULATING\n * ACCUMULATING → event arrives → buffer it, reset burst timer\n * ACCUMULATING → burst timer fires (no new events for burstWindowMs) → flush buffer as T[]\n * ACCUMULATING → buffer reaches maxBatchSize → flush buffer as T[]\n * After flush → idle timer starts\n * Idle timer fires (no new events for idleTimeoutMs) → transition to PASSTHROUGH\n */\nexport function burstBuffer<T>(\n options: BurstBufferOptions\n): OperatorFunction<T, T | T[]> {\n const { burstWindowMs, maxBatchSize, idleTimeoutMs } = options;\n\n return (source: Observable<T>) =>\n new Observable<T | T[]>((subscriber) => {\n let mode: 'passthrough' | 'accumulating' = 'passthrough';\n let buffer: T[] = [];\n let burstTimer: ReturnType<typeof setTimeout> | null = null;\n let idleTimer: ReturnType<typeof setTimeout> | null = null;\n\n function clearBurstTimer() {\n if (burstTimer !== null) {\n clearTimeout(burstTimer);\n burstTimer = null;\n }\n }\n\n function clearIdleTimer() {\n if (idleTimer !== null) {\n clearTimeout(idleTimer);\n idleTimer = null;\n }\n }\n\n function flush() {\n if (buffer.length === 0) return;\n const batch = buffer;\n buffer = [];\n subscriber.next(batch);\n }\n\n function startIdleTimer() {\n clearIdleTimer();\n idleTimer = setTimeout(() => {\n idleTimer = null;\n mode = 'passthrough';\n }, idleTimeoutMs);\n }\n\n const subscription = source.subscribe({\n next(value: T) {\n clearIdleTimer();\n\n if (mode === 'passthrough') {\n // Leading edge: emit immediately\n subscriber.next(value);\n // Transition to accumulating — next event within burstWindowMs gets buffered\n mode = 'accumulating';\n // Start a burst timer: if nothing else arrives, start idle countdown\n burstTimer = setTimeout(() => {\n burstTimer = null;\n flush(); // flush anything accumulated (normally empty at this point)\n startIdleTimer();\n }, burstWindowMs);\n return;\n }\n\n // mode === 'accumulating'\n buffer.push(value);\n\n // Reset the burst window timer (debounce pattern)\n clearBurstTimer();\n\n if (buffer.length >= maxBatchSize) {\n // Force flush at max batch size\n flush();\n startIdleTimer();\n } else {\n // Debounce: flush after burstWindowMs of silence\n burstTimer = setTimeout(() => {\n burstTimer = null;\n flush();\n startIdleTimer();\n }, burstWindowMs);\n }\n },\n\n error(err) {\n clearBurstTimer();\n clearIdleTimer();\n flush();\n subscriber.error(err);\n },\n\n complete() {\n clearBurstTimer();\n clearIdleTimer();\n flush();\n subscriber.complete();\n },\n });\n\n // Teardown: clean up timers and unsubscribe from source\n return () => {\n clearBurstTimer();\n clearIdleTimer();\n subscription.unsubscribe();\n };\n });\n}\n","/**\n * serializePerKey — run async work serialized per key, parallel across keys.\n *\n * Invariant: two calls with the same `key` run strictly in sequence (the\n * second `work` does not start until the first has settled). Calls with\n * different keys overlap freely.\n *\n * Error isolation: a rejected work function does not poison subsequent\n * tasks for the same key. The next task starts fresh from whatever state\n * the failed task left behind. The rejection still propagates to *this*\n * caller.\n *\n * Registry cleanup: the entry for a key is removed as soon as its chain\n * empties, so the Map stays bounded by the number of keys with work\n * currently in flight, not by the total number of keys ever seen.\n *\n * ## Usage\n *\n * ```ts\n * const chains = new Map<string, Promise<void>>();\n *\n * async function write(resourceId: string, event: Event) {\n * return serializePerKey(resourceId, chains, async () => {\n * // Read-modify-write on a view file. Any two concurrent calls with\n * // the same resourceId will be serialized; different resourceIds\n * // will proceed in parallel.\n * const view = await viewStorage.get(resourceId);\n * applyEvent(view, event);\n * await viewStorage.save(resourceId, view);\n * });\n * }\n * ```\n *\n * ## When to use this vs RxJS `groupBy + concatMap`\n *\n * Use `serializePerKey` when the work arrives as **direct method calls**\n * that need to block the caller until completion. This is the RPC shape\n * — think `EventStore.appendEvent` calling `await views.materializeResource(...)`\n * and needing the view written before any subscriber sees the published\n * event.\n *\n * Use RxJS `groupBy(keyFn) + concatMap(...)` when the work arrives as an\n * **event stream** that a component subscribes to once at startup. This\n * is how `Smelter`, `GraphDBConsumer`, and `Gatherer` serialize their own\n * per-resource work — see their implementations in `packages/make-meaning`.\n *\n * Both patterns solve the same logical problem (\"serialize work per key\").\n * The choice is dictated by whether the caller is awaiting the result.\n */\nexport async function serializePerKey<K, T>(\n key: K,\n chains: Map<K, Promise<void>>,\n work: () => Promise<T>,\n): Promise<T> {\n const prev = chains.get(key) ?? Promise.resolve();\n\n // Chain onto prev, swallowing any error from the previous link so one\n // bad task doesn't poison subsequent ones for the same key. The new\n // link's own errors still propagate to our caller via `await next`.\n let result: T;\n const next = prev\n .catch(() => { /* prior failure doesn't block us */ })\n .then(async () => {\n result = await work();\n });\n\n chains.set(key, next);\n\n try {\n await next;\n return result!;\n } finally {\n // Only clear the entry if we're still the tail. If another caller\n // has already chained onto us, leave it so the chain stays intact.\n if (chains.get(key) === next) {\n chains.delete(key);\n }\n }\n}\n","/**\n * Logger interface for observability\n *\n * This interface is intentionally framework-agnostic to work with any logger\n * (winston, pino, bunyan, or simple console).\n *\n * Example usage:\n * ```typescript\n * import winston from 'winston';\n *\n * const logger = winston.createLogger({\n * level: 'debug',\n * transports: [new winston.transports.Console()]\n * });\n *\n * const service = new MyService(logger);\n * ```\n */\nexport interface Logger {\n debug(message: string, meta?: any): void;\n info(message: string, meta?: any): void;\n warn(message: string, meta?: any): void;\n error(message: string, meta?: any): void;\n child(meta: Record<string, any>): Logger;\n}\n\n/**\n * Serialize an error value into a form that JSON.stringify can handle\n * meaningfully.\n *\n * Winston's default JSON formatter serializes `Error` instances as `{}`\n * because `message`, `stack`, and `name` are non-enumerable properties on\n * the Error prototype. That means `logger.error('x', { error })` with a\n * raw Error argument produces useless log lines like\n * `{\"error\":{},\"message\":\"x\",...}`, throwing away the information you\n * actually need to diagnose the failure.\n *\n * This helper extracts the parts you want to see in a log — name,\n * message, stack, and cause — and leaves non-Error values alone (so\n * strings, numbers, and plain objects pass through unchanged).\n *\n * ## Usage\n *\n * ```ts\n * try {\n * await doSomething();\n * } catch (error) {\n * logger.error('Something failed', { error: errField(error) });\n * }\n * ```\n *\n * Use this at every `logger.error` call site that includes an `error`\n * field derived from a catch block. Raw `{ error }` without this helper\n * is almost always a bug.\n */\nexport function errField(error: unknown): unknown {\n if (error instanceof Error) {\n return {\n name: error.name,\n message: error.message,\n stack: error.stack,\n ...(error.cause !== undefined && { cause: errField(error.cause) }),\n };\n }\n return error;\n}\n","/**\n * Annotation body utilities\n *\n * These are the matcher primitives used by the `mark:body-updated` event\n * replay path (ViewMaterializer and GraphDBConsumer) to apply add/remove/\n * replace operations against an annotation body.\n */\n\nimport type { components } from './types';\nimport type { Annotation } from './annotation-types';\n\ntype BodyPurpose = components['schemas']['BodyPurpose'];\n\n/**\n * Identity of a body item for matching purposes.\n *\n * Identity is `type + source` for SpecificResource and `type + value` for\n * TextualBody. `purpose` is OPTIONAL: if the caller provides it, it's\n * included in the match (used to disambiguate same-source bodies under\n * different purposes, per the W3C Web Annotation model). If the caller\n * omits it, the matcher ignores purpose and matches on identity alone.\n *\n * Callers SHOULD provide `purpose` when they know it (e.g., the bind flow\n * always unlinks a `purpose: 'linking'` body) so that future multi-purpose\n * annotations continue to disambiguate correctly. Leaving `purpose`\n * unspecified matches whichever purpose comes first in the body — which is\n * fine today because Semiont annotations currently have at most one body\n * item per (type, source/value) pair.\n */\nexport type BodyItemIdentity =\n | { type: 'SpecificResource'; source: string; purpose?: BodyPurpose }\n | { type: 'TextualBody'; value: string; purpose?: BodyPurpose };\n\n/**\n * Find a body item by identity. Returns the index of the first match, or -1.\n *\n * See `BodyItemIdentity` for matching semantics.\n */\nexport function findBodyItem(\n body: Annotation['body'],\n identity: BodyItemIdentity,\n): number {\n if (!Array.isArray(body)) {\n return -1;\n }\n\n for (let i = 0; i < body.length; i++) {\n const item = body[i];\n\n if (typeof item !== 'object' || item === null || !('type' in item)) {\n continue;\n }\n\n const itemType = (item as { type: unknown }).type;\n if (itemType !== identity.type) {\n continue;\n }\n\n // Identity field match (source or value)\n if (identity.type === 'SpecificResource') {\n if (!('source' in item)) continue;\n const itemSource = (item as { source: unknown }).source;\n if (itemSource !== identity.source) continue;\n } else {\n if (!('value' in item)) continue;\n const itemValue = (item as { value: unknown }).value;\n if (itemValue !== identity.value) continue;\n }\n\n // Purpose match — ONLY if the caller specified one. Omitted purpose\n // means \"any purpose on this identity\", which is what the bind-flow\n // unlinker wants today.\n if (identity.purpose !== undefined) {\n const itemPurpose = (item as { purpose?: unknown }).purpose;\n if (itemPurpose !== identity.purpose) continue;\n }\n\n return i;\n }\n\n return -1;\n}\n","/**\n * ID generation utilities\n */\n\n// crypto.randomUUID() is available as a global in Node 14.17+ and all modern browsers.\n// Declared here because the core package tsconfig uses lib:ES2022 (no dom types).\ndeclare const crypto: { randomUUID(): string };\n\n/**\n * Generate a UUID v4 string (without dashes)\n */\nexport function generateUuid(): string {\n return crypto.randomUUID().replace(/-/g, '');\n}\n","/**\n * Annotation Assembly\n *\n * Pure functions for building W3C Annotations and applying body operations.\n * No EventBus, no persistence — just data transformation.\n */\n\nimport type { components } from './types';\nimport type { Selector } from './payload-types';\nimport type { Annotation } from './annotation-types';\nimport { annotationId } from './identifiers';\nimport { generateUuid } from './id-generation';\n\ntype Agent = components['schemas']['Agent'];\ntype AnnotationBody = components['schemas']['AnnotationBody'];\ntype CreateAnnotationRequest = components['schemas']['CreateAnnotationRequest'];\ntype UpdateAnnotationBodyRequest = components['schemas']['UpdateAnnotationBodyRequest'];\ntype TextPositionSelector = components['schemas']['TextPositionSelector'];\ntype SvgSelector = components['schemas']['SvgSelector'];\ntype FragmentSelector = components['schemas']['FragmentSelector'];\n\nexport interface AssembledAnnotation {\n annotation: Annotation;\n bodyArray: AnnotationBody[];\n}\n\n// =============================================================================\n// Selector utilities used by assembleAnnotation\n// =============================================================================\n\n/**\n * Get TextPositionSelector from a selector (single or array)\n */\nexport function getTextPositionSelector(selector: Selector | Selector[] | undefined): TextPositionSelector | null {\n if (!selector) return null;\n const selectors = Array.isArray(selector) ? selector : [selector];\n const found = selectors.find(s => s.type === 'TextPositionSelector');\n if (!found) return null;\n return found.type === 'TextPositionSelector' ? found : null;\n}\n\n/**\n * Get SvgSelector from a selector (single or array)\n */\nexport function getSvgSelector(selector: Selector | Selector[] | undefined): SvgSelector | null {\n if (!selector) return null;\n const selectors = Array.isArray(selector) ? selector : [selector];\n const found = selectors.find(s => s.type === 'SvgSelector');\n if (!found) return null;\n return found.type === 'SvgSelector' ? found : null;\n}\n\n/**\n * Get FragmentSelector from a selector (single or array)\n */\nexport function getFragmentSelector(selector: Selector | Selector[] | undefined): FragmentSelector | null {\n if (!selector) return null;\n const selectors = Array.isArray(selector) ? selector : [selector];\n const found = selectors.find(s => s.type === 'FragmentSelector');\n if (!found) return null;\n return found.type === 'FragmentSelector' ? found : null;\n}\n\n/**\n * Validate SVG markup for W3C compliance\n *\n * @returns null if valid, error message if invalid\n */\nexport function validateSvgMarkup(svg: string): string | null {\n if (!svg.includes('xmlns=\"http://www.w3.org/2000/svg\"')) {\n return 'SVG must include xmlns=\"http://www.w3.org/2000/svg\" attribute';\n }\n\n if (!svg.includes('<svg') || !svg.includes('</svg>')) {\n return 'SVG must have opening and closing tags';\n }\n\n const shapeElements = ['rect', 'circle', 'ellipse', 'polygon', 'polyline', 'path', 'line'];\n const hasShape = shapeElements.some(shape =>\n svg.includes(`<${shape}`) || svg.includes(`<${shape} `)\n );\n\n if (!hasShape) {\n return 'SVG must contain at least one shape element (rect, circle, ellipse, polygon, polyline, path, or line)';\n }\n\n return null;\n}\n\n// =============================================================================\n// Annotation assembly\n// =============================================================================\n\n/**\n * Build a complete W3C Annotation from a CreateAnnotationRequest.\n *\n * Generates a bare annotation ID (no URL prefix). URIs are constructed\n * at the API boundary when returning responses to clients.\n *\n * Throws on invalid input (missing selector, missing motivation, invalid SVG).\n */\nexport function assembleAnnotation(\n request: CreateAnnotationRequest,\n creator: Agent,\n): AssembledAnnotation {\n const newAnnotationId = annotationId(generateUuid());\n\n // Validate selector: must have TextPositionSelector, SvgSelector, or FragmentSelector\n const posSelector = getTextPositionSelector(request.target.selector);\n const svgSelector = getSvgSelector(request.target.selector);\n const fragmentSelector = getFragmentSelector(request.target.selector);\n\n if (!posSelector && !svgSelector && !fragmentSelector) {\n throw new Error('Either TextPositionSelector, SvgSelector, or FragmentSelector is required for creating annotations');\n }\n\n // Validate SVG markup if SvgSelector is provided\n if (svgSelector) {\n const svgError = validateSvgMarkup(svgSelector.value);\n if (svgError) {\n throw new Error(`Invalid SVG markup: ${svgError}`);\n }\n }\n\n if (!request.motivation) {\n throw new Error('motivation is required');\n }\n\n const now = new Date().toISOString();\n const annotation: Annotation = {\n '@context': 'http://www.w3.org/ns/anno.jsonld' as const,\n 'type': 'Annotation' as const,\n id: newAnnotationId,\n motivation: request.motivation,\n target: request.target,\n body: request.body as Annotation['body'],\n creator,\n created: now,\n modified: now,\n };\n\n const bodyArray = (Array.isArray(request.body) ? request.body : request.body ? [request.body] : []) as AnnotationBody[];\n\n return { annotation, bodyArray };\n}\n\n/**\n * Apply body operations (add/remove/replace) to an annotation's body array.\n * Returns a new array — does not mutate the input.\n */\nexport function applyBodyOperations(\n body: Annotation['body'],\n operations: UpdateAnnotationBodyRequest['operations'],\n): AnnotationBody[] {\n const bodyArray = Array.isArray(body) ? [...body] : [];\n\n for (const op of operations) {\n if (op.op === 'add') {\n const exists = bodyArray.some(item =>\n JSON.stringify(item) === JSON.stringify(op.item)\n );\n if (!exists) {\n bodyArray.push(op.item);\n }\n } else if (op.op === 'remove') {\n const index = bodyArray.findIndex(item =>\n JSON.stringify(item) === JSON.stringify(op.item)\n );\n if (index !== -1) {\n bodyArray.splice(index, 1);\n }\n } else if (op.op === 'replace') {\n const index = bodyArray.findIndex(item =>\n JSON.stringify(item) === JSON.stringify(op.oldItem)\n );\n if (index !== -1) {\n bodyArray[index] = op.newItem;\n }\n }\n }\n\n return bodyArray;\n}\n","/**\n * Annotation and Selector Utilities\n *\n * Pure TypeScript utilities for working with W3C Web Annotations.\n * No React dependencies - safe to use in any JavaScript environment.\n *\n * Body is either empty array (stub) or single SpecificResource (resolved)\n * Body can be array of TextualBody (tagging) + SpecificResource (linking)\n * Target can be simple string IRI or object with source and optional selector\n */\n\nimport type { components } from './types';\nimport type { Selector } from './payload-types';\nimport type { Annotation } from './annotation-types';\n\n// Re-export selector utilities (canonical location is annotation-assembly)\nexport {\n getTextPositionSelector,\n getSvgSelector,\n getFragmentSelector,\n validateSvgMarkup,\n} from './annotation-assembly';\ntype HighlightAnnotation = Annotation;\ntype ReferenceAnnotation = Annotation;\ntype TextPositionSelector = components['schemas']['TextPositionSelector'];\ntype TextQuoteSelector = components['schemas']['TextQuoteSelector'];\ntype SvgSelector = components['schemas']['SvgSelector'];\ntype FragmentSelector = components['schemas']['FragmentSelector'];\n\n// Re-export selector types for convenience\nexport type { TextPositionSelector, TextQuoteSelector, SvgSelector, FragmentSelector, Selector };\n\n/**\n * Get the source from an annotation body (null if stub)\n * Search for SpecificResource in body array\n */\nexport function getBodySource(body: Annotation['body']): string | null {\n if (Array.isArray(body)) {\n // Search for SpecificResource with source\n for (const item of body) {\n if (\n typeof item === 'object' &&\n item !== null &&\n 'type' in item &&\n 'source' in item\n ) {\n const itemType = (item as { type: unknown }).type;\n const itemSource = (item as { source: unknown }).source;\n\n if (itemType === 'SpecificResource' && typeof itemSource === 'string') {\n return itemSource;\n }\n }\n }\n return null; // No SpecificResource found = stub\n }\n\n // Single body object (SpecificResource)\n if (\n typeof body === 'object' &&\n body !== null &&\n 'type' in body &&\n 'source' in body\n ) {\n const bodyType = (body as { type: unknown }).type;\n const bodySource = (body as { source: unknown }).source;\n\n if (bodyType === 'SpecificResource' && typeof bodySource === 'string') {\n return bodySource;\n }\n }\n\n return null;\n}\n\n/**\n * Get the type from an annotation body (returns first body type in array)\n */\nexport function getBodyType(body: Annotation['body']): 'TextualBody' | 'SpecificResource' | null {\n if (Array.isArray(body)) {\n if (body.length === 0) {\n return null;\n }\n // Return type of first body item\n if (typeof body[0] === 'object' && body[0] !== null && 'type' in body[0]) {\n const firstType = (body[0] as { type: unknown }).type;\n if (firstType === 'TextualBody' || firstType === 'SpecificResource') {\n return firstType;\n }\n }\n return null;\n }\n\n // Single body object\n if (typeof body === 'object' && body !== null && 'type' in body) {\n const bodyType = (body as { type: unknown }).type;\n if (bodyType === 'TextualBody' || bodyType === 'SpecificResource') {\n return bodyType;\n }\n }\n\n return null;\n}\n\n/**\n * Check if body is resolved (has a source)\n * Check for SpecificResource in body array\n */\nexport function isBodyResolved(body: Annotation['body']): boolean {\n return getBodySource(body) !== null;\n}\n\n/**\n * Get the source IRI from target (handles both string and object forms)\n */\nexport function getTargetSource(target: Annotation['target']): string {\n if (typeof target === 'string') {\n return target;\n }\n return target.source;\n}\n\n/**\n * Get the selector from target (undefined if string or no selector)\n */\nexport function getTargetSelector(target: Annotation['target']) {\n if (typeof target === 'string') {\n return undefined;\n }\n return target.selector;\n}\n\n/**\n * Check if target has a selector\n */\nexport function hasTargetSelector(target: Annotation['target']): boolean {\n return typeof target !== 'string' && target.selector !== undefined;\n}\n\n/**\n * Type guard to check if an annotation is a highlight\n */\nexport function isHighlight(annotation: Annotation): annotation is HighlightAnnotation {\n return annotation.motivation === 'highlighting';\n}\n\n/**\n * Type guard to check if an annotation is a reference (linking)\n */\nexport function isReference(annotation: Annotation): annotation is ReferenceAnnotation {\n return annotation.motivation === 'linking';\n}\n\n/**\n * Type guard to check if an annotation is an assessment\n */\nexport function isAssessment(annotation: Annotation): annotation is Annotation {\n return annotation.motivation === 'assessing';\n}\n\n/**\n * Type guard to check if an annotation is a comment\n */\nexport function isComment(annotation: Annotation): annotation is Annotation {\n return annotation.motivation === 'commenting';\n}\n\n/**\n * Type guard to check if an annotation is a tag\n */\nexport function isTag(annotation: Annotation): annotation is Annotation {\n return annotation.motivation === 'tagging';\n}\n\n/**\n * Extract comment text from a comment annotation's body\n * @param annotation - The annotation to extract comment text from\n * @returns The comment text, or undefined if not a comment or no text found\n */\nexport function getCommentText(annotation: Annotation): string | undefined {\n if (!isComment(annotation)) return undefined;\n const body = Array.isArray(annotation.body) ? annotation.body[0] : annotation.body;\n if (body && 'value' in body) {\n return body.value;\n }\n return undefined;\n}\n\n/**\n * Type guard to check if a reference annotation is a stub (unresolved)\n * Stub if no SpecificResource in body array\n */\nexport function isStubReference(annotation: Annotation): boolean {\n return isReference(annotation) && !isBodyResolved(annotation.body);\n}\n\n/**\n * Type guard to check if a reference annotation is resolved\n * Resolved if SpecificResource exists in body array\n */\nexport function isResolvedReference(annotation: Annotation): annotation is ReferenceAnnotation {\n return isReference(annotation) && isBodyResolved(annotation.body);\n}\n\n// =============================================================================\n// SELECTOR UTILITIES\n// =============================================================================\n\n/**\n * Get the exact text from a selector (single or array)\n *\n * When selector is an array, tries to find a TextQuoteSelector (which has exact text).\n * TextPositionSelector does not have exact text, only character offsets.\n * Handles undefined selector (when target is a string IRI with no selector)\n */\nexport function getExactText(selector: Selector | Selector[] | undefined): string {\n if (!selector) {\n return ''; // No selector means entire resource\n }\n const selectors = Array.isArray(selector) ? selector : [selector];\n\n // Try to find TextQuoteSelector (has exact text)\n const quoteSelector = selectors.find(s => s.type === 'TextQuoteSelector') as TextQuoteSelector | undefined;\n if (quoteSelector) {\n return quoteSelector.exact;\n }\n\n // No TextQuoteSelector found\n return '';\n}\n\n/**\n * Get the exact text from an annotation's target selector\n * Uses getTargetSelector helper to safely get selector\n */\nexport function getAnnotationExactText(annotation: Annotation): string {\n const selector = getTargetSelector(annotation.target);\n return getExactText(selector as Selector | Selector[] | undefined);\n}\n\n/**\n * Get the primary selector from a selector (single or array)\n *\n * When selector is an array, returns the first selector.\n * When selector is a single object, returns it as-is.\n */\nexport function getPrimarySelector(selector: Selector | Selector[]): Selector {\n if (Array.isArray(selector)) {\n if (selector.length === 0) {\n throw new Error('Empty selector array');\n }\n const first = selector[0];\n if (!first) {\n throw new Error('Invalid selector array');\n }\n return first;\n }\n return selector;\n}\n\n/**\n * Get TextQuoteSelector from a selector (single or array)\n *\n * Returns the first TextQuoteSelector found, or null if none exists.\n */\nexport function getTextQuoteSelector(selector: Selector | Selector[]): TextQuoteSelector | null {\n const selectors = Array.isArray(selector) ? selector : [selector];\n const found = selectors.find(s => s.type === 'TextQuoteSelector');\n if (!found) return null;\n return found.type === 'TextQuoteSelector' ? found : null;\n}\n\n/**\n * Extract bounding box from SVG markup\n *\n * Attempts to extract x, y, width, height from the SVG viewBox or root element.\n * Returns null if bounding box cannot be determined.\n */\nexport function extractBoundingBox(svg: string): { x: number; y: number; width: number; height: number } | null {\n // Try to extract viewBox attribute from SVG element\n const viewBoxMatch = svg.match(/<svg[^>]*viewBox=\"([^\"]+)\"/);\n if (viewBoxMatch) {\n const values = viewBoxMatch[1].split(/\\s+/).map(parseFloat);\n if (values.length === 4 && values.every(v => !isNaN(v))) {\n return {\n x: values[0],\n y: values[1],\n width: values[2],\n height: values[3]\n };\n }\n }\n\n // Try to extract width/height attributes from SVG element (assume x=0, y=0)\n const svgTagMatch = svg.match(/<svg[^>]*>/);\n if (svgTagMatch) {\n const svgTag = svgTagMatch[0];\n const widthMatch = svgTag.match(/width=\"([^\"]+)\"/);\n const heightMatch = svgTag.match(/height=\"([^\"]+)\"/);\n\n if (widthMatch && heightMatch) {\n const width = parseFloat(widthMatch[1]);\n const height = parseFloat(heightMatch[1]);\n\n if (!isNaN(width) && !isNaN(height)) {\n return { x: 0, y: 0, width, height };\n }\n }\n }\n\n return null;\n}\n","/**\n * Helper functions for working with W3C ResourceDescriptor\n */\n\nimport type { components } from './types';\nimport type { ResourceDescriptor } from './graph';\n\ntype Representation = components['schemas']['Representation'];\n\n/**\n * Get the resource ID from @id property\n *\n * @id is always a bare ID (UUID), never a full URI.\n */\nexport function getResourceId(resource: ResourceDescriptor | undefined): string | undefined {\n if (!resource) return undefined;\n return resource['@id'] || undefined;\n}\n\n/**\n * Get the primary representation (first or only representation)\n */\nexport function getPrimaryRepresentation(resource: ResourceDescriptor | undefined): Representation | undefined {\n if (!resource?.representations) return undefined;\n const reps = Array.isArray(resource.representations)\n ? resource.representations\n : [resource.representations];\n return reps[0];\n}\n\n/**\n * Get the media type from the primary representation\n */\nexport function getPrimaryMediaType(resource: ResourceDescriptor | undefined): string | undefined {\n return getPrimaryRepresentation(resource)?.mediaType;\n}\n\n/**\n * Get the checksum from the primary representation\n */\nexport function getChecksum(resource: ResourceDescriptor | undefined): string | undefined {\n return getPrimaryRepresentation(resource)?.checksum;\n}\n\n/**\n * Get the language from the primary representation\n */\nexport function getLanguage(resource: ResourceDescriptor | undefined): string | undefined {\n return getPrimaryRepresentation(resource)?.language;\n}\n\n/**\n * Get storage URI from primary representation\n *\n * @param resource - ResourceDescriptor\n * @returns Storage URI or undefined\n */\nexport function getStorageUri(resource: ResourceDescriptor | undefined): string | undefined {\n return getPrimaryRepresentation(resource)?.storageUri;\n}\n\n/**\n * Get creator agent from wasAttributedTo\n * Handles both single agent and array of agents\n *\n * @param resource - ResourceDescriptor\n * @returns First agent or undefined\n */\nexport function getCreator(resource: ResourceDescriptor | undefined): components['schemas']['Agent'] | undefined {\n if (!resource?.wasAttributedTo) return undefined;\n\n return Array.isArray(resource.wasAttributedTo)\n ? resource.wasAttributedTo[0]\n : resource.wasAttributedTo;\n}\n\n/**\n * Get derived-from URI\n * Handles both single URI and array of URIs\n *\n * @param resource - ResourceDescriptor\n * @returns First derivation URI or undefined\n */\nexport function getDerivedFrom(resource: ResourceDescriptor | undefined): string | undefined {\n if (!resource?.wasDerivedFrom) return undefined;\n\n return Array.isArray(resource.wasDerivedFrom)\n ? resource.wasDerivedFrom[0]\n : resource.wasDerivedFrom;\n}\n\n/**\n * Check if resource is archived (application-specific field)\n *\n * @param resource - ResourceDescriptor\n * @returns True if archived, false otherwise\n */\nexport function isArchived(resource: ResourceDescriptor | undefined): boolean {\n return resource?.archived === true;\n}\n\n/**\n * Get entity types from resource (application-specific field)\n *\n * @param resource - ResourceDescriptor\n * @returns Array of entity types, empty if not set\n */\nexport function getResourceEntityTypes(resource: ResourceDescriptor | undefined): string[] {\n return resource?.entityTypes || [];\n}\n\n/**\n * Check if resource is a draft (application-specific field)\n *\n * @param resource - ResourceDescriptor\n * @returns True if draft, false otherwise\n */\nexport function isDraft(resource: ResourceDescriptor | undefined): boolean {\n return resource?.isDraft === true;\n}\n\n/**\n * Map charset names to Node.js Buffer encoding names\n * Node.js Buffer.toString() supports: 'utf8', 'utf16le', 'latin1', 'base64', 'hex', 'ascii', 'binary', 'ucs2'\n *\n * @param charset - Charset name (e.g., \"UTF-8\", \"ISO-8859-1\", \"Windows-1252\")\n * @returns Node.js BufferEncoding\n */\nexport function getNodeEncoding(charset: string): BufferEncoding {\n const normalized = charset.toLowerCase().replace(/[-_]/g, '');\n\n // Map common charset names to Node.js encodings\n const charsetMap: Record<string, BufferEncoding> = {\n 'utf8': 'utf8',\n 'iso88591': 'latin1',\n 'latin1': 'latin1',\n 'ascii': 'ascii',\n 'usascii': 'ascii',\n 'utf16le': 'utf16le',\n 'ucs2': 'ucs2',\n 'binary': 'binary',\n 'windows1252': 'latin1', // Windows-1252 is a superset of Latin-1\n 'cp1252': 'latin1',\n };\n\n return charsetMap[normalized] || 'utf8';\n}\n\n/**\n * Decode a representation buffer to string using the correct charset\n * Extracts charset from media type and uses appropriate encoding\n *\n * @param buffer - The raw representation data\n * @param mediaType - Media type with optional charset (e.g., \"text/plain; charset=iso-8859-1\")\n * @returns Decoded string\n *\n * @example\n * ```typescript\n * const content = decodeRepresentation(buffer, \"text/plain; charset=utf-8\");\n * const legacy = decodeRepresentation(buffer, \"text/plain; charset=windows-1252\");\n * ```\n */\nexport function decodeRepresentation(buffer: Buffer, mediaType: string): string {\n // Extract charset from mediaType (e.g., \"text/plain; charset=iso-8859-1\")\n const charsetMatch = mediaType.match(/charset=([^\\s;]+)/i);\n const charset = (charsetMatch?.[1] || 'utf-8').toLowerCase();\n\n // Map to Node.js encoding\n const encoding = getNodeEncoding(charset);\n\n return buffer.toString(encoding);\n}\n","/**\n * BRIDGED_CHANNELS\n *\n * The set of bus channels that any concrete transport bridges into the\n * caller-supplied bus via `bridgeInto`. Transport-neutral: every concrete\n * `ITransport` shares the same set; HTTP delivers them via SSE,\n * in-process transports forward them directly from the local actor bus.\n *\n * Note: this is the *fan-in* set — channels for events the transport\n * receives and pushes onto the client's bus. It is not the same as the\n * channels the client emits (which is open-ended).\n *\n * Resource-scoped channels (joined/left via `subscribeToResource`) are\n * tracked separately by transports that care about scope (HTTP).\n */\nexport const BRIDGED_CHANNELS = [\n 'browse:resources-result', 'browse:resources-failed',\n 'browse:resource-result', 'browse:resource-failed',\n 'browse:annotations-result', 'browse:annotations-failed',\n 'browse:annotation-result', 'browse:annotation-failed',\n 'browse:annotation-history-result', 'browse:annotation-history-failed',\n 'browse:events-result', 'browse:events-failed',\n 'browse:referenced-by-result', 'browse:referenced-by-failed',\n 'browse:entity-types-result', 'browse:entity-types-failed',\n 'browse:directory-result', 'browse:directory-failed',\n 'browse:annotation-context-result', 'browse:annotation-context-failed',\n 'mark:delete-ok', 'mark:delete-failed',\n 'mark:create-ok', 'mark:create-failed',\n 'match:search-results', 'match:search-failed',\n 'gather:complete', 'gather:failed',\n 'gather:annotation-progress', 'gather:annotation-finished',\n 'gather:summary-result', 'gather:summary-failed',\n 'bind:body-updated', 'bind:body-update-failed',\n 'job:report-progress', 'job:complete', 'job:fail',\n 'job:status-result', 'job:status-failed',\n 'job:created', 'job:create-failed',\n 'job:claimed', 'job:claim-failed',\n 'yield:create-ok', 'yield:create-failed',\n 'yield:update-ok', 'yield:update-failed',\n 'yield:clone-token-generated', 'yield:clone-token-failed',\n 'yield:clone-resource-result', 'yield:clone-resource-failed',\n 'yield:clone-created', 'yield:clone-create-failed',\n 'frame:entity-type-added',\n 'beckon:focus', 'beckon:sparkle',\n 'bus:resume-gap',\n] as const;\n\nexport type BridgedChannel = typeof BRIDGED_CHANNELS[number];\n","/**\n * Fuzzy Anchoring for W3C Web Annotation TextQuoteSelector\n *\n * Uses prefix/suffix context to disambiguate when the same text appears multiple times.\n * Implements fuzzy matching as specified in the W3C Web Annotation Data Model.\n *\n * @see https://www.w3.org/TR/annotation-model/#text-quote-selector\n */\n\nexport interface TextPosition {\n start: number;\n end: number;\n}\n\nexport type MatchQuality = 'exact' | 'normalized' | 'case-insensitive' | 'fuzzy';\n\n/**\n * Normalize text for comparison - handles common document editing changes\n *\n * Collapses whitespace, converts curly quotes to straight quotes,\n * and normalizes common punctuation variations.\n */\nexport function normalizeText(text: string): string {\n return text\n .replace(/\\s+/g, ' ') // collapse whitespace\n .replace(/[\\u2018\\u2019]/g, \"'\") // curly single quotes → straight\n .replace(/[\\u201C\\u201D]/g, '\"') // curly double quotes → straight\n .replace(/\\u2014/g, '--') // em-dash → double hyphen\n .replace(/\\u2013/g, '-') // en-dash → hyphen\n .trim();\n}\n\n/**\n * Calculate Levenshtein distance between two strings\n * Used for fuzzy matching when exact text doesn't match\n */\nfunction levenshteinDistance(str1: string, str2: string): number {\n const len1 = str1.length;\n const len2 = str2.length;\n const matrix: number[][] = [];\n\n // Initialize matrix\n for (let i = 0; i <= len1; i++) {\n matrix[i] = [i];\n }\n for (let j = 0; j <= len2; j++) {\n matrix[0]![j] = j;\n }\n\n // Fill matrix\n for (let i = 1; i <= len1; i++) {\n for (let j = 1; j <= len2; j++) {\n const cost = str1[i - 1] === str2[j - 1] ? 0 : 1;\n const deletion = matrix[i - 1]![j]! + 1;\n const insertion = matrix[i]![j - 1]! + 1;\n const substitution = matrix[i - 1]![j - 1]! + cost;\n matrix[i]![j] = Math.min(deletion, insertion, substitution);\n }\n }\n\n return matrix[len1]![len2]!;\n}\n\n/**\n * Pre-computed content strings for batch fuzzy matching.\n * Avoids recomputing normalizeText(content) and content.toLowerCase()\n * for every annotation when processing many annotations against the same content.\n */\nexport interface ContentCache {\n normalizedContent: string;\n lowerContent: string;\n}\n\n/**\n * Build a ContentCache for a given content string.\n * Call once per content, pass to findBestTextMatch/findTextWithContext for all annotations.\n */\nexport function buildContentCache(content: string): ContentCache {\n return {\n normalizedContent: normalizeText(content),\n lowerContent: content.toLowerCase()\n };\n}\n\n/**\n * Find best match for text in content using multi-strategy search\n *\n * Shared core logic used by both findTextWithContext and validateAndCorrectOffsets.\n *\n * @param content - Full text content to search within\n * @param searchText - The text to find\n * @param positionHint - Hint for where to search (TextPositionSelector.start)\n * @param cache - Pre-computed normalized/lowered content (from buildContentCache)\n * @returns Match with position and quality, or null if not found\n */\nexport function findBestTextMatch(\n content: string,\n searchText: string,\n positionHint: number | undefined,\n cache: ContentCache\n): { start: number; end: number; matchQuality: MatchQuality } | null {\n const maxFuzzyDistance = Math.max(5, Math.floor(searchText.length * 0.05)); // 5% tolerance or min 5 chars\n\n // Strategy 1: Exact match (case-sensitive, exact whitespace)\n const exactIndex = content.indexOf(searchText);\n if (exactIndex !== -1) {\n return {\n start: exactIndex,\n end: exactIndex + searchText.length,\n matchQuality: 'exact'\n };\n }\n\n // Strategy 2: Normalized match (handles whitespace/quote variations)\n const normalizedSearch = normalizeText(searchText);\n const normalizedIndex = cache.normalizedContent.indexOf(normalizedSearch);\n if (normalizedIndex !== -1) {\n // Find actual position in original content by counting characters\n let actualPos = 0;\n let normalizedPos = 0;\n while (normalizedPos < normalizedIndex && actualPos < content.length) {\n const char = content[actualPos]!;\n const normalizedChar = normalizeText(char);\n if (normalizedChar) {\n normalizedPos += normalizedChar.length;\n }\n actualPos++;\n }\n return {\n start: actualPos,\n end: actualPos + searchText.length,\n matchQuality: 'normalized'\n };\n }\n\n // Strategy 3: Case-insensitive match\n const lowerSearch = searchText.toLowerCase();\n const caseInsensitiveIndex = cache.lowerContent.indexOf(lowerSearch);\n if (caseInsensitiveIndex !== -1) {\n return {\n start: caseInsensitiveIndex,\n end: caseInsensitiveIndex + searchText.length,\n matchQuality: 'case-insensitive'\n };\n }\n\n // Strategy 4: Fuzzy match using Levenshtein distance with sliding window\n // Search near position hint if provided, otherwise search full content\n const windowSize = searchText.length;\n const searchRadius = Math.min(500, content.length);\n const searchStart = positionHint !== undefined\n ? Math.max(0, positionHint - searchRadius)\n : 0;\n const searchEnd = positionHint !== undefined\n ? Math.min(content.length, positionHint + searchRadius)\n : content.length;\n\n let bestMatch: { start: number; distance: number } | null = null;\n\n // Scan through content with sliding window\n for (let i = searchStart; i <= searchEnd - windowSize; i++) {\n const candidate = content.substring(i, i + windowSize);\n const distance = levenshteinDistance(searchText, candidate);\n\n if (distance <= maxFuzzyDistance) {\n if (!bestMatch || distance < bestMatch.distance) {\n bestMatch = { start: i, distance };\n }\n }\n }\n\n if (bestMatch) {\n return {\n start: bestMatch.start,\n end: bestMatch.start + windowSize,\n matchQuality: 'fuzzy'\n };\n }\n\n return null;\n}\n\n/**\n * Find text using exact match with optional prefix/suffix context\n *\n * When the exact text appears multiple times in the content, prefix and suffix\n * are used to disambiguate and find the correct occurrence.\n *\n * If exact text is not found, uses multi-strategy fuzzy matching (normalization,\n * case-insensitive, Levenshtein distance) to locate changed text.\n *\n * @param content - Full text content to search within\n * @param exact - The exact text to find\n * @param prefix - Optional text that should appear immediately before the match\n * @param suffix - Optional text that should appear immediately after the match\n * @param positionHint - Optional position hint (from TextPositionSelector) for fuzzy search\n * @returns Position of the matched text, or null if not found\n *\n * @example\n * ```typescript\n * const content = \"The cat sat. The cat ran.\";\n * // Find second \"The cat\" occurrence\n * const pos = findTextWithContext(content, \"The cat\", \"sat. \", \" ran\");\n * // Returns { start: 13, end: 20 }\n * ```\n */\nexport function findTextWithContext(\n content: string,\n exact: string,\n prefix: string | undefined,\n suffix: string | undefined,\n positionHint: number | undefined,\n cache: ContentCache\n): TextPosition | null {\n if (!exact) return null;\n\n // Fast path: if positionHint points directly at the exact text, return immediately\n if (positionHint !== undefined && positionHint >= 0 && positionHint + exact.length <= content.length) {\n if (content.substring(positionHint, positionHint + exact.length) === exact) {\n return { start: positionHint, end: positionHint + exact.length };\n }\n }\n\n // Find all occurrences of exact text\n const occurrences: number[] = [];\n let index = content.indexOf(exact);\n while (index !== -1) {\n occurrences.push(index);\n index = content.indexOf(exact, index + 1);\n }\n\n // No exact matches found - try fuzzy matching\n if (occurrences.length === 0) {\n const fuzzyMatch = findBestTextMatch(content, exact, positionHint, cache);\n\n if (fuzzyMatch) {\n return { start: fuzzyMatch.start, end: fuzzyMatch.end };\n }\n\n return null;\n }\n\n // Only one match - no need for prefix/suffix disambiguation\n if (occurrences.length === 1) {\n const pos = occurrences[0]!; // Safe: length === 1 means first element exists\n return { start: pos, end: pos + exact.length };\n }\n\n // Multiple matches - use prefix/suffix to disambiguate\n if (prefix || suffix) {\n for (const pos of occurrences) {\n // Extract actual prefix from content\n const actualPrefixStart = Math.max(0, pos - (prefix?.length || 0));\n const actualPrefix = content.substring(actualPrefixStart, pos);\n\n // Extract actual suffix from content\n const actualSuffixEnd = Math.min(content.length, pos + exact.length + (suffix?.length || 0));\n const actualSuffix = content.substring(pos + exact.length, actualSuffixEnd);\n\n // Check if prefix matches\n const prefixMatch = !prefix || actualPrefix.endsWith(prefix);\n\n // Check if suffix matches\n const suffixMatch = !suffix || actualSuffix.startsWith(suffix);\n\n if (prefixMatch && suffixMatch) {\n return { start: pos, end: pos + exact.length };\n }\n }\n\n // No match with exact prefix/suffix - try partial prefix/suffix match\n for (const pos of occurrences) {\n const actualPrefix = content.substring(Math.max(0, pos - (prefix?.length || 0)), pos);\n const actualSuffix = content.substring(pos + exact.length, pos + exact.length + (suffix?.length || 0));\n\n // Fuzzy match: check if prefix/suffix are substrings (handles whitespace variations)\n const fuzzyPrefixMatch = !prefix || actualPrefix.includes(prefix.trim());\n const fuzzySuffixMatch = !suffix || actualSuffix.includes(suffix.trim());\n\n if (fuzzyPrefixMatch && fuzzySuffixMatch) {\n return { start: pos, end: pos + exact.length };\n }\n }\n }\n\n // Fallback: return first occurrence if no prefix/suffix or no match\n const pos = occurrences[0]!; // Safe: we checked length > 0 earlier\n return { start: pos, end: pos + exact.length };\n}\n\n/**\n * Verify that a position correctly points to the exact text\n * Useful for debugging and validation\n */\nexport function verifyPosition(\n content: string,\n position: TextPosition,\n expectedExact: string\n): boolean {\n const actualText = content.substring(position.start, position.end);\n return actualText === expectedExact;\n}\n","/**\n * Locale information\n * Copied from SDK for frontend use\n */\n\nexport interface LocaleInfo {\n code: string;\n nativeName: string;\n englishName: string;\n}\n\nexport const LOCALES: readonly LocaleInfo[] = [\n { code: 'ar', nativeName: 'العربية', englishName: 'Arabic' },\n { code: 'bn', nativeName: 'বাংলা', englishName: 'Bengali' },\n { code: 'cs', nativeName: 'Čeština', englishName: 'Czech' },\n { code: 'da', nativeName: 'Dansk', englishName: 'Danish' },\n { code: 'de', nativeName: 'Deutsch', englishName: 'German' },\n { code: 'el', nativeName: 'Ελληνικά', englishName: 'Greek' },\n { code: 'en', nativeName: 'English', englishName: 'English' },\n { code: 'es', nativeName: 'Español', englishName: 'Spanish' },\n { code: 'fa', nativeName: 'فارسی', englishName: 'Persian' },\n { code: 'fi', nativeName: 'Suomi', englishName: 'Finnish' },\n { code: 'fr', nativeName: 'Français', englishName: 'French' },\n { code: 'he', nativeName: 'עברית', englishName: 'Hebrew' },\n { code: 'hi', nativeName: 'हिन्दी', englishName: 'Hindi' },\n { code: 'id', nativeName: 'Bahasa Indonesia', englishName: 'Indonesian' },\n { code: 'it', nativeName: 'Italiano', englishName: 'Italian' },\n { code: 'ja', nativeName: '日本語', englishName: 'Japanese' },\n { code: 'ko', nativeName: '한국어', englishName: 'Korean' },\n { code: 'ms', nativeName: 'Bahasa Melayu', englishName: 'Malay' },\n { code: 'nl', nativeName: 'Nederlands', englishName: 'Dutch' },\n { code: 'no', nativeName: 'Norsk', englishName: 'Norwegian' },\n { code: 'pl', nativeName: 'Polski', englishName: 'Polish' },\n { code: 'pt', nativeName: 'Português', englishName: 'Portuguese' },\n { code: 'ro', nativeName: 'Română', englishName: 'Romanian' },\n { code: 'sv', nativeName: 'Svenska', englishName: 'Swedish' },\n { code: 'th', nativeName: 'ไทย', englishName: 'Thai' },\n { code: 'tr', nativeName: 'Türkçe', englishName: 'Turkish' },\n { code: 'uk', nativeName: 'Українська', englishName: 'Ukrainian' },\n { code: 'vi', nativeName: 'Tiếng Việt', englishName: 'Vietnamese' },\n { code: 'zh', nativeName: '中文', englishName: 'Chinese' },\n] as const;\n\n// Create lookup map for efficient access\nconst localeByCode = new Map<string, LocaleInfo>(\n LOCALES.map(locale => [locale.code.toLowerCase(), locale])\n);\n\n/**\n * Get locale information by code\n */\nexport function getLocaleInfo(code: string | undefined): LocaleInfo | undefined {\n if (!code) return undefined;\n return localeByCode.get(code.toLowerCase());\n}\n\n/**\n * Get the native name of a language by its locale code\n */\nexport function getLocaleNativeName(code: string | undefined): string | undefined {\n return getLocaleInfo(code)?.nativeName;\n}\n\n/**\n * Get the English name of a language by its locale code\n */\nexport function getLocaleEnglishName(code: string | undefined): string | undefined {\n return getLocaleInfo(code)?.englishName;\n}\n\n/**\n * Format locale code for display as \"Native Name (code)\"\n */\nexport function formatLocaleDisplay(code: string | undefined): string | undefined {\n if (!code) return undefined;\n\n const info = getLocaleInfo(code);\n if (!info) return code;\n\n return `${info.nativeName} (${code.toLowerCase()})`;\n}\n\n/**\n * Get all supported locale codes\n */\nexport function getAllLocaleCodes(): readonly string[] {\n return LOCALES.map(l => l.code);\n}\n","/**\n * SVG Utility Functions\n *\n * Utilities for creating, parsing, and manipulating W3C-compliant SVG selectors\n * for image annotation.\n */\n\nexport interface Point {\n x: number;\n y: number;\n}\n\nexport interface BoundingBox {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/**\n * Create W3C-compliant SVG rectangle selector\n */\nexport function createRectangleSvg(start: Point, end: Point): string {\n const x = Math.min(start.x, end.x);\n const y = Math.min(start.y, end.y);\n const width = Math.abs(end.x - start.x);\n const height = Math.abs(end.y - start.y);\n\n return `<svg xmlns=\"http://www.w3.org/2000/svg\"><rect x=\"${x}\" y=\"${y}\" width=\"${width}\" height=\"${height}\"/></svg>`;\n}\n\n/**\n * Create W3C-compliant SVG polygon selector\n */\nexport function createPolygonSvg(points: Point[]): string {\n if (points.length < 3) {\n throw new Error('Polygon requires at least 3 points');\n }\n\n const pointsStr = points.map(p => `${p.x},${p.y}`).join(' ');\n return `<svg xmlns=\"http://www.w3.org/2000/svg\"><polygon points=\"${pointsStr}\"/></svg>`;\n}\n\n/**\n * Create W3C-compliant SVG circle selector\n */\nexport function createCircleSvg(center: Point, radius: number): string {\n if (radius <= 0) {\n throw new Error('Circle radius must be positive');\n }\n\n return `<svg xmlns=\"http://www.w3.org/2000/svg\"><circle cx=\"${center.x}\" cy=\"${center.y}\" r=\"${radius}\"/></svg>`;\n}\n\n/**\n * Parse SVG selector to extract shape type and data\n */\nexport function parseSvgSelector(svg: string): {\n type: 'rect' | 'polygon' | 'circle' | 'path';\n data: any;\n} | null {\n // Extract rectangle\n const rectMatch = svg.match(/<rect\\s+([^>]+)\\/>/);\n if (rectMatch && rectMatch[1]) {\n const attrs = rectMatch[1];\n const x = parseFloat(attrs.match(/x=\"([^\"]+)\"/)?.[1] || '0');\n const y = parseFloat(attrs.match(/y=\"([^\"]+)\"/)?.[1] || '0');\n const width = parseFloat(attrs.match(/width=\"([^\"]+)\"/)?.[1] || '0');\n const height = parseFloat(attrs.match(/height=\"([^\"]+)\"/)?.[1] || '0');\n\n return {\n type: 'rect',\n data: { x, y, width, height }\n };\n }\n\n // Extract polygon\n const polygonMatch = svg.match(/<polygon\\s+points=\"([^\"]+)\"/);\n if (polygonMatch && polygonMatch[1]) {\n const pointsStr = polygonMatch[1];\n const points = pointsStr.split(/\\s+/).map(pair => {\n const [x, y] = pair.split(',').map(parseFloat);\n return { x, y };\n });\n\n return {\n type: 'polygon',\n data: { points }\n };\n }\n\n // Extract circle\n const circleMatch = svg.match(/<circle\\s+([^>]+)\\/>/);\n if (circleMatch && circleMatch[1]) {\n const attrs = circleMatch[1];\n const cx = parseFloat(attrs.match(/cx=\"([^\"]+)\"/)?.[1] || '0');\n const cy = parseFloat(attrs.match(/cy=\"([^\"]+)\"/)?.[1] || '0');\n const r = parseFloat(attrs.match(/r=\"([^\"]+)\"/)?.[1] || '0');\n\n return {\n type: 'circle',\n data: { cx, cy, r }\n };\n }\n\n return null;\n}\n\n/**\n * Normalize coordinates from display space to image native resolution\n */\nexport function normalizeCoordinates(\n point: Point,\n displayWidth: number,\n displayHeight: number,\n imageWidth: number,\n imageHeight: number\n): Point {\n return {\n x: (point.x / displayWidth) * imageWidth,\n y: (point.y / displayHeight) * imageHeight\n };\n}\n\n/**\n * Scale entire SVG selector from display space to image native resolution\n */\nexport function scaleSvgToNative(\n svg: string,\n displayWidth: number,\n displayHeight: number,\n imageWidth: number,\n imageHeight: number\n): string {\n const parsed = parseSvgSelector(svg);\n if (!parsed) return svg;\n\n const scaleX = imageWidth / displayWidth;\n const scaleY = imageHeight / displayHeight;\n\n switch (parsed.type) {\n case 'rect': {\n const { x, y, width, height } = parsed.data;\n return createRectangleSvg(\n { x: x * scaleX, y: y * scaleY },\n { x: (x + width) * scaleX, y: (y + height) * scaleY }\n );\n }\n\n case 'circle': {\n const { cx, cy, r } = parsed.data;\n return createCircleSvg(\n { x: cx * scaleX, y: cy * scaleY },\n r * Math.min(scaleX, scaleY)\n );\n }\n\n case 'polygon': {\n const points = parsed.data.points.map((p: Point) => ({\n x: p.x * scaleX,\n y: p.y * scaleY\n }));\n return createPolygonSvg(points);\n }\n }\n\n return svg;\n}\n","/**\n * Text context extraction utilities for W3C Web Annotation TextQuoteSelector\n *\n * Provides robust prefix/suffix context extraction with word boundary detection\n * to ensure fuzzy anchoring works correctly when the same text appears multiple times.\n *\n * Also provides AI offset validation and correction for handling AI-generated annotations\n * where the model may return slightly incorrect character offsets.\n *\n * @see https://www.w3.org/TR/annotation-model/#text-quote-selector\n */\n\nimport { findBestTextMatch, buildContentCache, type MatchQuality } from './fuzzy-anchor';\n\n/**\n * Extract prefix and suffix context for TextQuoteSelector\n *\n * Extracts up to 64 characters before and after the selected text,\n * extending to word boundaries to avoid cutting words in half.\n * This ensures prefix/suffix are meaningful context for fuzzy anchoring.\n *\n * @param content - Full text content\n * @param start - Start offset of selection\n * @param end - End offset of selection\n * @returns Object with prefix and suffix (undefined if at boundaries)\n *\n * @example\n * ```typescript\n * const content = \"The United States Congress...\";\n * const context = extractContext(content, 4, 17); // \"United States\"\n * // Returns: { prefix: \"The \", suffix: \" Congress...\" }\n * // NOT: { prefix: \"nited \", suffix: \"gress...\" }\n * ```\n */\nexport function extractContext(\n content: string,\n start: number,\n end: number\n): { prefix?: string; suffix?: string } {\n const CONTEXT_LENGTH = 64;\n const MAX_EXTENSION = 32; // Maximum additional chars to extend for word boundary\n\n // Extract prefix (up to CONTEXT_LENGTH chars before start, extended to word boundary)\n let prefix: string | undefined;\n if (start > 0) {\n let prefixStart = Math.max(0, start - CONTEXT_LENGTH);\n\n // Extend backward to word boundary (whitespace or punctuation)\n // Stop if we hit start of content or exceed MAX_EXTENSION\n let extensionCount = 0;\n while (prefixStart > 0 && extensionCount < MAX_EXTENSION) {\n const char = content[prefixStart - 1];\n // Break on whitespace, punctuation, or common delimiters\n if (!char || /[\\s.,;:!?'\"()\\[\\]{}<>\\/\\\\]/.test(char)) {\n break;\n }\n prefixStart--;\n extensionCount++;\n }\n\n prefix = content.substring(prefixStart, start);\n }\n\n // Extract suffix (up to CONTEXT_LENGTH chars after end, extended to word boundary)\n let suffix: string | undefined;\n if (end < content.length) {\n let suffixEnd = Math.min(content.length, end + CONTEXT_LENGTH);\n\n // Extend forward to word boundary (whitespace or punctuation)\n // Stop if we hit end of content or exceed MAX_EXTENSION\n let extensionCount = 0;\n while (suffixEnd < content.length && extensionCount < MAX_EXTENSION) {\n const char = content[suffixEnd];\n // Break on whitespace, punctuation, or common delimiters\n if (!char || /[\\s.,;:!?'\"()\\[\\]{}<>\\/\\\\]/.test(char)) {\n break;\n }\n suffixEnd++;\n extensionCount++;\n }\n\n suffix = content.substring(end, suffixEnd);\n }\n\n return { prefix, suffix };\n}\n\n/**\n * Result of validating and correcting AI-provided annotation offsets\n */\nexport interface ValidatedAnnotation {\n start: number;\n end: number;\n exact: string;\n prefix?: string;\n suffix?: string;\n corrected: boolean; // True if offsets were adjusted from AI's original values\n fuzzyMatched?: boolean; // True if we had to use fuzzy matching (minor text differences)\n matchQuality?: MatchQuality; // How we found the match\n}\n\n\n/**\n * Validate and correct AI-provided annotation offsets with fuzzy matching tolerance\n *\n * AI models sometimes return offsets that don't match the actual text position,\n * or provide text with minor variations (case differences, whitespace, typos).\n *\n * This function uses a multi-strategy approach:\n * 1. Check if AI's offsets are exactly correct\n * 2. Try exact case-sensitive search\n * 3. Try case-insensitive search\n * 4. Try fuzzy matching with Levenshtein distance (5% tolerance)\n *\n * This ensures we're maximally tolerant of AI errors while still maintaining\n * annotation quality and logging what corrections were made.\n *\n * @param content - Full text content\n * @param aiStart - Start offset from AI\n * @param aiEnd - End offset from AI\n * @param exact - The exact text that should be at this position (from AI)\n * @returns Validated annotation with corrected offsets and context\n * @throws Error if no acceptable match can be found\n *\n * @example\n * ```typescript\n * // AI said start=1143, but actual text is at 1161\n * const result = validateAndCorrectOffsets(\n * content,\n * 1143,\n * 1289,\n * \"the question \\\"whether...\"\n * );\n * // Returns: { start: 1161, end: 1303, exact: \"...\", corrected: true, matchQuality: 'exact', ... }\n * ```\n */\nexport function validateAndCorrectOffsets(\n content: string,\n aiStart: number,\n aiEnd: number,\n exact: string\n): ValidatedAnnotation {\n // First, check if AI's offsets are correct\n const textAtOffset = content.substring(aiStart, aiEnd);\n\n if (textAtOffset === exact) {\n // AI got it right! Just add proper context\n const context = extractContext(content, aiStart, aiEnd);\n return {\n start: aiStart,\n end: aiEnd,\n exact,\n prefix: context.prefix,\n suffix: context.suffix,\n corrected: false,\n matchQuality: 'exact'\n };\n }\n\n // AI's offsets are wrong - try to find the text using multiple strategies\n const cache = buildContentCache(content);\n const match = findBestTextMatch(content, exact, aiStart, cache);\n\n if (!match) {\n throw new Error(\n 'Cannot find acceptable match for text in content. ' +\n 'All search strategies failed. Text may be hallucinated.'\n );\n }\n\n // Found a match! Extract the actual text from content\n const actualText = content.substring(match.start, match.end);\n\n // Extract context using corrected offsets\n const context = extractContext(content, match.start, match.end);\n\n return {\n start: match.start,\n end: match.end,\n exact: actualText, // Use actual text from document, not AI's version\n prefix: context.prefix,\n suffix: context.suffix,\n corrected: true,\n fuzzyMatched: match.matchQuality !== 'exact',\n matchQuality: match.matchQuality\n };\n}\n","/**\n * Text encoding utilities for consistent charset handling\n *\n * Ensures frontend decoding matches backend decoding by respecting\n * charset parameters in mediaType (e.g., \"text/plain; charset=iso-8859-1\")\n */\n\n/**\n * Extract charset from mediaType parameter\n *\n * @param mediaType - Media type with optional charset (e.g., \"text/plain; charset=utf-8\")\n * @returns Charset name in lowercase (defaults to \"utf-8\")\n *\n * @example\n * extractCharset(\"text/plain; charset=iso-8859-1\") // \"iso-8859-1\"\n * extractCharset(\"text/plain\") // \"utf-8\"\n */\nexport function extractCharset(mediaType: string): string {\n const charsetMatch = mediaType.match(/charset=([^\\s;]+)/i);\n return (charsetMatch?.[1] || 'utf-8').toLowerCase();\n}\n\n/**\n * Decode ArrayBuffer to string using charset from mediaType\n *\n * Uses TextDecoder with the charset extracted from mediaType parameter.\n * This ensures the same character space is used for both annotation creation\n * (backend) and rendering (frontend).\n *\n * @param buffer - Binary data to decode\n * @param mediaType - Media type with optional charset parameter\n * @returns Decoded string in the original character space\n *\n * @example\n * const buffer = new Uint8Array([...]);\n * const text = decodeWithCharset(buffer, \"text/plain; charset=iso-8859-1\");\n */\nexport function decodeWithCharset(buffer: ArrayBuffer, mediaType: string): string {\n const charset = extractCharset(mediaType);\n\n // TextDecoder supports standard charset names\n // Common mappings that work in browsers:\n // - utf-8, utf-16, utf-16le, utf-16be\n // - iso-8859-1 through iso-8859-15\n // - windows-1252, windows-1251, etc.\n const decoder = new TextDecoder(charset);\n return decoder.decode(buffer);\n}\n","/**\n * Generic validation utilities for @semiont/api-client\n *\n * Pure TypeScript validation with no external dependencies.\n * Safe to use in any JavaScript environment (Node.js, browser, Deno, etc.)\n */\n\n/**\n * Validation result types\n */\nexport type ValidationSuccess<T> = { success: true; data: T };\nexport type ValidationFailure = { success: false; error: string; details?: string[] };\nexport type ValidationResult<T> = ValidationSuccess<T> | ValidationFailure;\n\n/**\n * JWT Token validation\n *\n * Validates JWT token format (header.payload.signature).\n * Does not verify signature - use for format validation only.\n */\nexport const JWTTokenSchema = {\n parse(token: unknown): string {\n if (typeof token !== 'string') {\n throw new Error('Token must be a string');\n }\n if (!token || token.length === 0) {\n throw new Error('Token is required');\n }\n // JWT format: header.payload.signature\n const jwtRegex = /^[A-Za-z0-9\\-_]+\\.[A-Za-z0-9\\-_]+\\.[A-Za-z0-9\\-_]*$/;\n if (!jwtRegex.test(token)) {\n throw new Error('Invalid JWT token format');\n }\n return token;\n },\n\n safeParse(token: unknown): ValidationResult<string> {\n try {\n const validated = this.parse(token);\n return { success: true, data: validated };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Invalid JWT token',\n };\n }\n },\n};\n\n/**\n * Generic validation helper with error formatting\n *\n * Wraps any schema's parse method with try/catch and returns ValidationResult.\n *\n * @example\n * ```typescript\n * const result = validateData(JWTTokenSchema, 'eyJ...');\n * if (result.success) {\n * console.log('Valid token:', result.data);\n * } else {\n * console.error('Invalid:', result.error);\n * }\n * ```\n */\nexport function validateData<T>(\n schema: { parse(data: unknown): T },\n data: unknown\n): ValidationResult<T> {\n try {\n const validated = schema.parse(data);\n return { success: true, data: validated };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Validation failed',\n };\n }\n}\n\n/**\n * Email validation helper\n *\n * Validates email format using RFC 5322 simplified regex.\n *\n * @param email - Email address to validate\n * @returns true if valid email format\n */\nexport function isValidEmail(email: string): boolean {\n if (email.length < 1 || email.length > 255) {\n return false;\n }\n // RFC 5322 simplified email regex\n const emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n return emailRegex.test(email);\n}\n","/**\n * MIME type utilities for Semiont\n *\n * Initial support for:\n * - text/plain\n * - text/markdown\n * - image/png\n * - image/jpeg\n * - application/pdf\n */\n\n/**\n * Map MIME type to file extension\n */\nexport function getExtensionForMimeType(mimeType: string): string {\n const map: Record<string, string> = {\n 'text/plain': 'txt',\n 'text/markdown': 'md',\n 'image/png': 'png',\n 'image/jpeg': 'jpg',\n 'application/pdf': 'pdf',\n };\n\n return map[mimeType] || 'dat'; // fallback to .dat for unknown types\n}\n\n/**\n * Detect if MIME type is an image (png or jpeg only for now)\n */\nexport function isImageMimeType(mimeType: string): boolean {\n return mimeType === 'image/png' || mimeType === 'image/jpeg';\n}\n\n/**\n * Detect if MIME type is text-based (plain or markdown only for now)\n */\nexport function isTextMimeType(mimeType: string): boolean {\n return mimeType === 'text/plain' || mimeType === 'text/markdown';\n}\n\n/**\n * Detect if MIME type is PDF\n */\nexport function isPdfMimeType(mimeType: string): boolean {\n return mimeType === 'application/pdf';\n}\n\n/**\n * Get category for MIME type (for routing to appropriate viewer)\n *\n * Categories represent annotation models, not file formats:\n * - 'text': Text-based annotations (TextPositionSelector, TextQuoteSelector)\n * - 'image': Spatial coordinate annotations (SvgSelector, FragmentSelector)\n *\n * PDFs use spatial coordinates for annotations, so they belong to 'image' category.\n */\nexport type MimeCategory = 'text' | 'image' | 'unsupported';\n\nexport function getMimeCategory(mimeType: string): MimeCategory {\n if (isTextMimeType(mimeType)) {\n return 'text';\n }\n if (isImageMimeType(mimeType) || isPdfMimeType(mimeType)) {\n return 'image';\n }\n return 'unsupported';\n}\n","/**\n * Common type guard utilities\n */\n\n/**\n * Check if value is a string\n */\nexport function isString(value: unknown): value is string {\n return typeof value === 'string';\n}\n\n/**\n * Check if value is a number (not NaN)\n */\nexport function isNumber(value: unknown): value is number {\n return typeof value === 'number' && !isNaN(value);\n}\n\n/**\n * Check if value is an object (not null, not array)\n */\nexport function isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Check if value is an array\n */\nexport function isArray(value: unknown): value is unknown[] {\n return Array.isArray(value);\n}\n\n/**\n * Check if value is a boolean\n */\nexport function isBoolean(value: unknown): value is boolean {\n return typeof value === 'boolean';\n}\n\n/**\n * Check if value is a function\n */\nexport function isFunction(value: unknown): value is Function {\n return typeof value === 'function';\n}\n\n/**\n * Check if value is null\n */\nexport function isNull(value: unknown): value is null {\n return value === null;\n}\n\n/**\n * Check if value is undefined\n */\nexport function isUndefined(value: unknown): value is undefined {\n return value === undefined;\n}\n\n/**\n * Check if value is null or undefined\n */\nexport function isNullish(value: unknown): value is null | undefined {\n return value === null || value === undefined;\n}\n\n/**\n * Check if value is defined (not null or undefined)\n */\nexport function isDefined<T>(value: T | null | undefined): value is T {\n return value !== null && value !== undefined;\n}","/**\n * Common error classes — the unified Semiont error hierarchy.\n *\n * `SemiontError` is the base every other Semiont error class extends:\n * `APIError` (api-client), `BusRequestError` and `SemiontSessionError` (sdk),\n * `ValidationError`, `ScriptError`, `NotFoundError`, `UnauthorizedError`,\n * `ConflictError` (here), and `AWSError` (cli). Subclasses tighten the\n * `code` field to a literal-union for discriminated handling.\n */\n\n/**\n * Transport-neutral error vocabulary. Every transport that surfaces\n * errors over `ITransport.errors$` maps its native failure modes to one\n * of these codes — HTTP `APIError` maps from status code, in-process\n * transports map from local failure shape, gRPC would map from status\n * code, etc. Routing layers (e.g. `SemiontBrowser`'s session-expired /\n * permission-denied modal routing) match on this vocabulary so they\n * stay transport-agnostic.\n *\n * - `unauthorized` — auth required / token missing or expired (HTTP 401)\n * - `forbidden` — auth ok but lacks permission (HTTP 403)\n * - `not-found` — resource missing (HTTP 404)\n * - `conflict` — concurrent modification, duplicate, etc. (HTTP 409)\n * - `bad-request` — request malformed (HTTP 400)\n * - `unavailable` — backend unreachable, network error, 5xx\n * - `error` — unclassified fallback\n */\nexport type TransportErrorCode =\n | 'unauthorized'\n | 'forbidden'\n | 'not-found'\n | 'conflict'\n | 'bad-request'\n | 'unavailable'\n | 'error';\n\nexport class SemiontError extends Error {\n constructor(\n message: string,\n public code: string,\n public details?: Record<string, unknown>,\n ) {\n super(message);\n this.name = 'SemiontError';\n Error.captureStackTrace(this, this.constructor);\n }\n}\n\nexport class ValidationError extends SemiontError {\n constructor(message: string, details?: Record<string, unknown>) {\n super(message, 'VALIDATION_ERROR', details);\n this.name = 'ValidationError';\n }\n}\n\nexport class ScriptError extends SemiontError {\n constructor(message: string, code: string = 'SCRIPT_ERROR', details?: Record<string, unknown>) {\n super(message, code, details);\n this.name = 'ScriptError';\n }\n}\n\nexport class NotFoundError extends SemiontError {\n constructor(resource: string, id?: string) {\n const message = id ? `${resource} with id '${id}' not found` : `${resource} not found`;\n super(message, 'NOT_FOUND', { resource, id });\n this.name = 'NotFoundError';\n }\n}\n\nexport class UnauthorizedError extends SemiontError {\n constructor(message: string = 'Unauthorized', details?: Record<string, unknown>) {\n super(message, 'UNAUTHORIZED', details);\n this.name = 'UnauthorizedError';\n }\n}\n\nexport class ConflictError extends SemiontError {\n constructor(message: string, details?: Record<string, unknown>) {\n super(message, 'CONFLICT', details);\n this.name = 'ConflictError';\n }\n}\n","/**\n * DID (Decentralized Identifier) and W3C Agent utilities\n *\n * Provides utilities for working with DID:WEB identifiers and converting\n * between user representations and W3C Web Annotation Agent objects.\n */\n\nimport type { components } from './types';\n\ntype Agent = components['schemas']['Agent'];\n\n/**\n * Convert a user object to a DID:WEB identifier\n *\n * Format: did:web:domain.com:users:email%40domain.com\n * Example: did:web:example.com:users:alice%40example.com\n *\n * Email is used as the stable, human-readable identifier (URI-encoded).\n * This is used for W3C Web Annotation compliance and federation readiness.\n *\n * @param user - User object with email and domain\n * @returns DID:WEB identifier string\n */\nexport function userToDid(user: { email: string; domain: string }): string {\n return `did:web:${user.domain}:users:${encodeURIComponent(user.email)}`;\n}\n\n/**\n * Convert a user object to a W3C Agent object with DID:WEB identifier\n *\n * Creates a full Agent object for W3C Web Annotation compliance.\n * Includes DID:WEB identifier, type, and name.\n *\n * @param user - User object with id, domain, name, and email\n * @returns W3C Agent object\n */\nexport function userToAgent(user: {\n id: string;\n domain: string;\n name: string | null;\n email: string;\n}): Agent {\n return {\n type: 'Person' as const,\n id: userToDid(user),\n name: user.name || user.email,\n };\n}\n\n/**\n * Convert a DID string to a minimal W3C Agent object\n *\n * Used when reconstructing annotations from events where only the DID is available.\n * Creates a minimal Agent with just the required fields (id, type).\n * Name is derived from the DID for display purposes.\n *\n * @param did - DID:WEB identifier string\n * @returns Minimal W3C Agent object\n */\nexport function didToAgent(did: string | undefined | null): Agent {\n if (!did) {\n return { type: 'Person' as const, id: 'unknown', name: 'unknown' };\n }\n const parts = did.split(':');\n const encoded = parts[parts.length - 1] || 'unknown';\n const name = decodeURIComponent(encoded);\n\n return {\n type: 'Person' as const,\n id: did,\n name,\n };\n}\n","/**\n * TOML Config Loader\n *\n * Reads ~/.semiontconfig (TOML) and .semiont/config (TOML) and produces\n * an EnvironmentConfig for the requested environment.\n *\n * File format: see TOML-XDG-CONFIG.md\n *\n * Loading sequence:\n * 1. Read .semiont/config → projectName, site, environments.<env>.* (project base)\n * 2. Read ~/.semiontconfig → defaults, environments.<env>.* (user overrides)\n * 3. Deep-merge: project base ← user overrides (user wins on conflicts)\n * Any environment name is valid (local, staging, production, custom, ...)\n * 4. Resolve ${VAR} references from process.env\n * 5. Apply inheritance: workers.<name> → workers.default → error\n * 6. Map to EnvironmentConfig shape\n */\n\nimport { parse as parseToml } from 'smol-toml';\nimport type { EnvironmentConfig, OllamaProviderConfig, AnthropicProviderConfig } from './config.types';\nimport type { PlatformType } from './config.types';\n\n/**\n * Deep merge two plain objects. Arrays and primitives in `override` replace those in `base`.\n * Nested objects are merged recursively. `override` takes precedence on conflicts.\n */\nfunction deepMerge<T extends Record<string, unknown>>(base: T, override: Partial<T>): T {\n const result = { ...base } as Record<string, unknown>;\n for (const key of Object.keys(override)) {\n const b = base[key];\n const o = override[key];\n if (o !== undefined && o !== null && typeof o === 'object' && !Array.isArray(o) &&\n b !== undefined && b !== null && typeof b === 'object' && !Array.isArray(b)) {\n result[key] = deepMerge(b as Record<string, unknown>, o as Record<string, unknown>);\n } else if (o !== undefined) {\n result[key] = o;\n }\n }\n return result as T;\n}\n\nfunction resolveEnvVars(obj: unknown, env: Record<string, string | undefined>): unknown {\n if (typeof obj === 'string') {\n return obj.replace(/\\$\\{([^}]+)\\}/g, (match, expr: string) => {\n const sepIdx = expr.indexOf(':-');\n const varName = sepIdx >= 0 ? expr.slice(0, sepIdx) : expr;\n const defaultValue = sepIdx >= 0 ? expr.slice(sepIdx + 2) : undefined;\n const value = env[varName];\n if (value !== undefined) return value;\n if (defaultValue !== undefined) return defaultValue;\n throw new Error(`Environment variable ${varName} is not set (referenced in config as ${match})`);\n });\n }\n if (Array.isArray(obj)) {\n return obj.map(item => resolveEnvVars(item, env));\n }\n if (obj !== null && typeof obj === 'object') {\n const resolved: Record<string, unknown> = {};\n for (const key in obj as Record<string, unknown>) {\n resolved[key] = resolveEnvVars((obj as Record<string, unknown>)[key], env);\n }\n return resolved;\n }\n return obj;\n}\n\n// ── Inference config types (mirrored from packages/make-meaning/src/config.ts) ─\n// Kept here to avoid a circular dependency: core cannot import make-meaning.\n\nexport interface InferenceConfig {\n type: 'anthropic' | 'ollama';\n model: string;\n maxTokens?: number;\n apiKey?: string;\n endpoint?: string;\n baseURL?: string;\n}\n\nexport interface ActorInferenceConfig {\n gatherer?: InferenceConfig;\n matcher?: InferenceConfig;\n}\n\nexport interface WorkerInferenceConfig {\n default?: InferenceConfig;\n 'reference-annotation'?: InferenceConfig;\n 'highlight-annotation'?: InferenceConfig;\n 'assessment-annotation'?: InferenceConfig;\n 'comment-annotation'?: InferenceConfig;\n 'tag-annotation'?: InferenceConfig;\n 'generation'?: InferenceConfig;\n}\n\n// ── Types for ~/.semiontconfig ────────────────────────────────────────────────\n\ninterface SemiontConfigFile {\n user?: {\n name?: string;\n email?: string;\n };\n defaults?: {\n environment?: string;\n platform?: string;\n };\n environments?: Record<string, EnvironmentSection>;\n}\n\ninterface GraphSection {\n platform?: string;\n type?: string;\n name?: string;\n uri?: string;\n username?: string;\n password?: string;\n database?: string;\n [key: string]: unknown;\n}\n\ninterface InferenceFlatSection {\n // Flat (single-provider) format: type = \"anthropic\"|\"ollama\" at this level\n type?: 'anthropic' | 'ollama';\n platform?: string;\n model?: string;\n maxTokens?: number;\n apiKey?: string;\n endpoint?: string;\n baseURL?: string;\n // Keyed (multi-provider) format: [inference.anthropic] / [inference.ollama]\n anthropic?: { platform?: string; apiKey?: string; endpoint?: string };\n ollama?: { platform?: string; baseURL?: string; port?: number };\n}\n\ninterface EnvironmentSection {\n backend?: {\n platform?: string;\n port?: number;\n publicURL?: string;\n frontendURL?: string;\n corsOrigin?: string;\n };\n frontend?: {\n platform?: string;\n port?: number;\n publicURL?: string;\n };\n site?: {\n domain?: string;\n siteName?: string;\n adminEmail?: string;\n oauthAllowedDomains?: string[];\n enableLocalAuth?: boolean;\n };\n database?: {\n platform?: string;\n image?: string;\n host?: string;\n port?: number;\n name?: string;\n user?: string;\n password?: string;\n };\n graph?: GraphSection;\n vectors?: {\n type?: 'qdrant' | 'memory';\n host?: string;\n port?: number;\n // Legacy: embedding nested under vectors (migrated to top-level)\n embedding?: {\n type?: 'voyage' | 'ollama';\n model?: string;\n apiKey?: string;\n baseURL?: string;\n endpoint?: string;\n };\n chunking?: {\n chunkSize?: number;\n overlap?: number;\n };\n };\n embedding?: {\n type?: 'voyage' | 'ollama';\n model?: string;\n apiKey?: string;\n baseURL?: string;\n endpoint?: string;\n chunking?: {\n chunkSize?: number;\n overlap?: number;\n };\n };\n inference?: InferenceFlatSection;\n 'make-meaning'?: {\n graph?: Record<string, unknown>;\n actors?: {\n gatherer?: { inference?: InferenceConfig };\n matcher?: { inference?: InferenceConfig };\n };\n default?: { inference?: InferenceConfig };\n };\n workers?: Record<string, { inference?: InferenceConfig }>;\n actors?: Record<string, { inference?: InferenceConfig }>;\n logLevel?: 'error' | 'warn' | 'info' | 'http' | 'debug';\n}\n\n// ── File reader abstraction (same pattern as createConfigLoader) ──────────────\n\nexport type TomlFileReader = {\n readIfExists: (path: string) => string | null;\n};\n\nfunction requirePlatform(value: string | undefined, serviceName: string): PlatformType {\n if (!value) {\n throw new Error(`platform is required for service '${serviceName}' — add 'platform = \"posix\"|\"container\"|\"external\"' to its config section`);\n }\n return value as PlatformType;\n}\n\n// ── Main loader function ──────────────────────────────────────────────────────\n\n/**\n * Parse ~/.semiontconfig and .semiont/config and return EnvironmentConfig.\n *\n * @param projectRoot - Path to the project root (contains .semiont/config)\n * @param environment - Environment name (e.g. 'local', 'production')\n * @param globalConfigPath - Path to ~/.semiontconfig (caller resolves ~ expansion)\n * @param reader - File reader abstraction\n * @param env - Environment variables for ${VAR} resolution\n */\nexport function loadTomlConfig(\n projectRoot: string | null,\n environment: string,\n globalConfigPath: string,\n reader: TomlFileReader,\n env: Record<string, string | undefined>\n): EnvironmentConfig {\n // 1. Read project config from .semiont/config (skipped when no project root)\n const projectConfigContent = projectRoot ? reader.readIfExists(`${projectRoot}/.semiont/config`) : null;\n let projectName = 'semiont-project';\n let projectVersion: string | undefined;\n let projectSite: EnvironmentSection['site'] | undefined;\n let projectEnvSection: EnvironmentSection = {};\n if (projectConfigContent) {\n const projectConfig = parseToml(projectConfigContent) as {\n project?: { name?: string; version?: string };\n site?: EnvironmentSection['site'];\n environments?: Record<string, EnvironmentSection>;\n };\n projectName = projectConfig.project?.name ?? projectName;\n projectVersion = projectConfig.project?.version;\n projectSite = projectConfig.site;\n projectEnvSection = projectConfig.environments?.[environment] ?? {};\n }\n\n // 2. Read global config (optional — missing config yields empty environments)\n const globalContent = reader.readIfExists(globalConfigPath);\n const raw = globalContent ? (parseToml(globalContent) as SemiontConfigFile) : ({} as SemiontConfigFile);\n\n // 3. Deep-merge: project base + user overrides (user wins on conflicts)\n const userEnvSection: EnvironmentSection = raw.environments?.[environment] ?? {};\n const envSection: EnvironmentSection = deepMerge(\n projectEnvSection as Record<string, unknown>,\n userEnvSection as Record<string, unknown>\n ) as EnvironmentSection;\n\n // 4. Resolve ${VAR} references\n const resolved = resolveEnvVars(envSection, env) as EnvironmentSection;\n\n // 5. Build make-meaning actor/worker inference config with inheritance\n // The flat [inference] section provides defaults (apiKey, maxTokens, endpoint/baseURL).\n // Actor/worker sections only need to specify type and model; missing fields fall back\n // to the flat inference section.\n const flatInference = resolved.inference;\n const makeMeaningSection = resolved['make-meaning'];\n const workersSection = resolved.workers ?? {};\n const actorsSection = resolved.actors ?? {};\n const defaultWorkerInference = workersSection['default']?.inference;\n const defaultMakeMeaningInference = makeMeaningSection?.default?.inference;\n\n function mergeWithFlatInference(specific: InferenceConfig): InferenceConfig {\n if (!flatInference) return specific;\n // For keyed sub-sections, inherit credentials from the matching provider sub-section.\n // For flat (legacy) format, flatInference.type is required to know which fields apply.\n const providerDefaults: Partial<InferenceConfig> = {};\n if (specific.type === 'anthropic') {\n const a = flatInference.anthropic;\n if (a) {\n providerDefaults.apiKey = a.apiKey;\n providerDefaults.endpoint = a.endpoint;\n } else {\n if (!flatInference.type) {\n throw new Error(\n `[environments.${environment}.inference] is missing 'type'. ` +\n `Add type = \"anthropic\" or use [inference.anthropic] sub-section.`\n );\n }\n providerDefaults.apiKey = flatInference.apiKey;\n providerDefaults.endpoint = flatInference.endpoint;\n }\n } else if (specific.type === 'ollama') {\n const o = flatInference.ollama;\n if (o) {\n providerDefaults.baseURL = o.baseURL;\n } else {\n if (!flatInference.type) {\n throw new Error(\n `[environments.${environment}.inference] is missing 'type'. ` +\n `Add type = \"ollama\" or use [inference.ollama] sub-section.`\n );\n }\n providerDefaults.baseURL = flatInference.baseURL;\n }\n }\n return {\n maxTokens: flatInference.maxTokens,\n ...providerDefaults,\n ...specific,\n };\n }\n\n function resolveActorInference(fromMakeMeaning?: InferenceConfig, fromActors?: InferenceConfig): InferenceConfig | undefined {\n const base = fromMakeMeaning ?? fromActors ?? defaultMakeMeaningInference;\n if (!base) return undefined;\n return mergeWithFlatInference(base);\n }\n\n const actors: ActorInferenceConfig = {};\n const gathererInference = resolveActorInference(\n makeMeaningSection?.actors?.gatherer?.inference,\n actorsSection['gatherer']?.inference\n );\n if (gathererInference) actors.gatherer = gathererInference;\n\n const matcherInference = resolveActorInference(\n makeMeaningSection?.actors?.matcher?.inference,\n actorsSection['matcher']?.inference\n );\n if (matcherInference) actors.matcher = matcherInference;\n\n const workers: WorkerInferenceConfig = {};\n const workerTypes = ['reference-annotation', 'highlight-annotation', 'assessment-annotation', 'comment-annotation', 'tag-annotation', 'generation'] as const;\n if (defaultWorkerInference) {\n workers.default = mergeWithFlatInference(defaultWorkerInference);\n }\n for (const wt of workerTypes) {\n const specific = workersSection[wt]?.inference;\n if (specific) {\n (workers as Record<string, InferenceConfig>)[wt] = mergeWithFlatInference(specific);\n }\n }\n\n // 6. Map to EnvironmentConfig\n const backend = resolved.backend;\n const site = resolved.site ?? projectSite;\n const inferenceSection = resolved.inference;\n\n // Build inference providers config.\n // Supports two formats:\n // Flat: [environments.local.inference] type = \"anthropic\"|\"ollama\" (single provider)\n // Keyed: [environments.local.inference.anthropic] / [environments.local.inference.ollama] (multi-provider)\n let inferenceProviders: EnvironmentConfig['inference'] | undefined;\n if (inferenceSection) {\n inferenceProviders = {};\n // Keyed sub-sections take priority\n if (inferenceSection.anthropic) {\n const a = inferenceSection.anthropic;\n inferenceProviders.anthropic = {\n platform: requirePlatform(a.platform, 'inference.anthropic'),\n endpoint: a.endpoint ?? 'https://api.anthropic.com',\n apiKey: a.apiKey ?? '',\n } as AnthropicProviderConfig;\n } else if (inferenceSection.type === 'anthropic') {\n inferenceProviders.anthropic = {\n platform: requirePlatform(inferenceSection.platform, 'inference'),\n endpoint: inferenceSection.endpoint ?? 'https://api.anthropic.com',\n apiKey: inferenceSection.apiKey ?? '',\n } as AnthropicProviderConfig;\n }\n if (inferenceSection.ollama) {\n const o = inferenceSection.ollama;\n inferenceProviders.ollama = {\n platform: { type: requirePlatform(o.platform, 'inference.ollama') },\n baseURL: o.baseURL,\n port: o.baseURL ? undefined : (o.port ?? 11434),\n } as OllamaProviderConfig;\n } else if (inferenceSection.type === 'ollama') {\n inferenceProviders.ollama = {\n platform: { type: requirePlatform(inferenceSection.platform, 'inference') },\n baseURL: inferenceSection.baseURL,\n port: inferenceSection.baseURL ? undefined : 11434,\n } as OllamaProviderConfig;\n }\n }\n\n // Build top-level workers/actors maps for EnvironmentConfig\n const topLevelWorkers: EnvironmentConfig['workers'] = {};\n for (const [name, w] of Object.entries(workersSection)) {\n if (w.inference) {\n topLevelWorkers[name] = { inference: { type: w.inference.type, model: w.inference.model } };\n }\n }\n const topLevelActors: EnvironmentConfig['actors'] = {};\n for (const [name, a] of Object.entries(actorsSection)) {\n if (a.inference) {\n topLevelActors[name] = { inference: { type: a.inference.type, model: a.inference.model } };\n }\n }\n // Also include make-meaning actors\n if (makeMeaningSection?.actors?.gatherer?.inference) {\n topLevelActors['gatherer'] = { inference: { type: makeMeaningSection.actors.gatherer.inference.type, model: makeMeaningSection.actors.gatherer.inference.model } };\n }\n if (makeMeaningSection?.actors?.matcher?.inference) {\n topLevelActors['matcher'] = { inference: { type: makeMeaningSection.actors.matcher.inference.type, model: makeMeaningSection.actors.matcher.inference.model } };\n }\n\n const frontend = resolved.frontend;\n\n const services: EnvironmentConfig['services'] = {};\n\n if (backend) {\n services.backend = {\n platform: { type: requirePlatform(backend.platform, 'backend') },\n port: backend.port ?? 4000,\n publicURL: backend.publicURL ?? `http://localhost:${backend.port ?? 4000}`,\n corsOrigin: backend.corsOrigin ?? backend.frontendURL ?? 'http://localhost:3000',\n };\n }\n\n if (frontend) {\n services.frontend = {\n platform: { type: requirePlatform(frontend.platform, 'frontend') },\n port: frontend.port ?? 3000,\n siteName: site?.siteName ?? 'Semiont',\n publicURL: frontend.publicURL,\n };\n }\n\n if (resolved.graph) {\n services.graph = {\n ...resolved.graph,\n platform: { type: requirePlatform(resolved.graph.platform as string | undefined, 'graph') },\n type: (resolved.graph.type ?? 'neo4j') as import('./config.types').GraphDatabaseType,\n } as EnvironmentConfig['services']['graph'];\n } else if (makeMeaningSection?.graph) {\n services.graph = makeMeaningSection.graph as EnvironmentConfig['services']['graph'];\n }\n\n if (resolved.database) {\n services.database = {\n platform: { type: requirePlatform(resolved.database.platform, 'database') },\n type: 'postgres',\n image: resolved.database.image,\n host: resolved.database.host ?? 'localhost',\n port: resolved.database.port ?? 5432,\n name: resolved.database.name,\n user: resolved.database.user,\n password: resolved.database.password,\n } as EnvironmentConfig['services']['database'];\n }\n\n if (resolved.vectors) {\n services.vectors = {\n platform: { type: 'external' as PlatformType },\n type: (resolved.vectors.type ?? 'qdrant') as 'qdrant' | 'memory',\n host: resolved.vectors.host,\n port: resolved.vectors.port ?? 6333,\n } as EnvironmentConfig['services']['vectors'];\n }\n\n // Embedding: top-level takes precedence, fall back to legacy vectors.embedding\n const embeddingSource = resolved.embedding ?? resolved.vectors?.embedding;\n if (embeddingSource) {\n services.embedding = {\n platform: { type: 'external' as PlatformType },\n type: embeddingSource.type!,\n model: embeddingSource.model!,\n apiKey: embeddingSource.apiKey,\n baseURL: embeddingSource.baseURL,\n endpoint: embeddingSource.endpoint,\n chunking: (resolved.embedding?.chunking ?? resolved.vectors?.chunking) ? {\n chunkSize: (resolved.embedding?.chunking ?? resolved.vectors?.chunking)?.chunkSize ?? 512,\n overlap: (resolved.embedding?.chunking ?? resolved.vectors?.chunking)?.overlap ?? 64,\n } : undefined,\n } as EnvironmentConfig['services']['embedding'];\n }\n\n const config: EnvironmentConfig = {\n services,\n ...(inferenceProviders ? { inference: inferenceProviders } : {}),\n ...(Object.keys(topLevelWorkers).length > 0 ? { workers: topLevelWorkers } : {}),\n ...(Object.keys(topLevelActors).length > 0 ? { actors: topLevelActors } : {}),\n site: site ? {\n domain: site.domain ?? 'localhost',\n siteName: site.siteName,\n adminEmail: site.adminEmail,\n oauthAllowedDomains: site.oauthAllowedDomains as [string, ...string[]] | undefined,\n } : undefined,\n logLevel: resolved.logLevel,\n _metadata: {\n environment,\n projectRoot,\n projectName,\n projectVersion,\n ...(Object.keys(actors).length > 0 ? { actors } : {}),\n ...(Object.keys(workers).length > 0 ? { workers } : {}),\n },\n };\n\n return config;\n}\n\n/**\n * Create a TOML config loader backed by a file reader.\n * Drop-in replacement for createConfigLoader that reads TOML instead of JSON.\n * The caller must resolve globalConfigPath (e.g. expand '~' using process.env.HOME).\n */\nexport function createTomlConfigLoader(\n reader: TomlFileReader,\n globalConfigPath: string,\n env: Record<string, string | undefined>\n) {\n return (projectRoot: string | null, environment: string): EnvironmentConfig => {\n return loadTomlConfig(projectRoot, environment, globalConfigPath, reader, env);\n };\n}\n","/**\n * Environment validation utilities\n *\n * Pure functions - accept available environments as parameter instead of reading from filesystem\n */\n\nexport type Environment = string; // Allow any environment name\n\n/**\n * Type guard to check if a string is a valid Environment\n * @param value - The environment string to check\n * @param availableEnvironments - List of valid environment names\n */\nexport function isValidEnvironment(value: string | undefined, availableEnvironments: string[]): value is Environment {\n if (!value) return false;\n return availableEnvironments.includes(value);\n}\n\n/**\n * Parse environment string to Environment type\n * @param value - The environment string to parse\n * @param availableEnvironments - List of valid environment names\n * @returns Valid Environment type\n * @throws Error if environment is invalid or not provided\n */\nexport function parseEnvironment(value: string | undefined, availableEnvironments: string[]): Environment {\n if (!value) {\n throw new Error('Environment is required');\n }\n if (!isValidEnvironment(value, availableEnvironments)) {\n throw new Error(`Invalid environment: ${value}. Available environments: ${availableEnvironments.join(', ')}`);\n }\n return value;\n}\n\n/**\n * Validate and return environment or throw error\n * @param value - The environment string to validate\n * @param availableEnvironments - List of valid environment names\n * @throws Error if environment is invalid\n */\nexport function validateEnvironment(value: string | undefined, availableEnvironments: string[]): Environment {\n if (!value) {\n throw new Error('Environment is required');\n }\n if (!isValidEnvironment(value, availableEnvironments)) {\n throw new Error(`Invalid environment: ${value}. Available environments: ${availableEnvironments.join(', ')}`);\n }\n return value;\n}","/**\n * Configuration Error Class\n * \n * Custom error class for configuration validation and loading errors.\n * Provides structured error information with helpful suggestions.\n */\n\nexport class ConfigurationError extends Error {\n public override readonly cause?: Error;\n\n constructor(\n message: string,\n public environment?: string,\n public suggestion?: string,\n cause?: Error\n ) {\n super(message);\n this.name = 'ConfigurationError';\n this.cause = cause;\n }\n \n /**\n * Format the error nicely for CLI output\n */\n override toString(): string {\n let output = `❌ ${this.message}`;\n if (this.environment) {\n output += `\\n Environment: ${this.environment}`;\n }\n if (this.suggestion) {\n output += `\\n 💡 Suggestion: ${this.suggestion}`;\n }\n return output;\n }\n}","/**\n * Platform Types Module\n *\n * Re-exports PlatformType from schema-generated types.\n * Platforms represent WHERE services run (infrastructure targets).\n */\n\nimport { PlatformType as SchemaPlatformType } from './config.types';\n\n/**\n * Platform type literals from JSON Schema\n * These represent the infrastructure targets where services can be deployed\n */\nexport type PlatformType = SchemaPlatformType;\n\n/**\n * Type guard to check if a string is a valid platform type\n *\n * @param value - Value to check\n * @returns True if value is a valid PlatformType\n */\nexport function isValidPlatformType(value: string): value is PlatformType {\n return ['aws', 'container', 'posix', 'external'].includes(value);\n}\n\n/**\n * Get all valid platform types\n *\n * @returns Array of all platform types\n */\nexport function getAllPlatformTypes(): PlatformType[] {\n return ['aws', 'container', 'posix', 'external'];\n}","/**\n * @semiont/core\n *\n * Core domain logic and utilities for the Semiont semantic knowledge platform.\n * OpenAPI types are generated here and exported for use across the monorepo.\n */\n\n// OpenAPI-generated types (source of truth for API schemas)\nexport type { components, paths, operations } from './types';\n\n// Branded types (compile-time type safety)\nexport type {\n // OpenAPI types\n Motivation,\n ContentFormat,\n // Authentication & tokens\n Email,\n AuthCode,\n GoogleCredential,\n AccessToken,\n RefreshToken,\n MCPToken,\n CloneToken,\n // System identifiers\n JobId,\n UserDID,\n EntityType,\n SearchQuery,\n BaseUrl,\n // HTTP URI types\n ResourceUri,\n AnnotationUri,\n ResourceAnnotationUri,\n} from './branded-types';\nexport {\n // Helper functions\n email,\n authCode,\n googleCredential,\n accessToken,\n refreshToken,\n mcpToken,\n cloneToken,\n jobId,\n userDID,\n entityType,\n searchQuery,\n baseUrl,\n // URI factory functions\n resourceUri,\n annotationUri,\n resourceAnnotationUri,\n} from './branded-types';\n\n// Creation methods\nexport { CREATION_METHODS } from './creation-methods';\nexport type { CreationMethod } from './creation-methods';\n\n// Identifier types (only IDs - URIs are in @semiont/api-client)\nexport type { ResourceId, AnnotationId, UserId } from './identifiers';\nexport {\n resourceId,\n annotationId,\n userId,\n isResourceId,\n isAnnotationId,\n} from './identifiers';\n\n// Graph types\nexport type {\n GraphConnection,\n GraphPath,\n EntityTypeStats,\n ResourceDescriptor,\n} from './graph';\n\n// Event base types (persistence model foundations)\nexport type {\n Brand,\n EventBase,\n EventMetadata,\n EventSignature,\n StoredEvent,\n BodyOperation,\n BodyItem,\n EventQuery,\n ResourceAnnotations,\n} from './event-base';\n\n// Persisted events (the 20 event types written to the log)\nexport type {\n EventOfType,\n PersistedEvent,\n PersistedEventType,\n EventInput,\n} from './persisted-events';\nexport { PERSISTED_EVENT_TYPES } from './persisted-events';\n\n// Bus protocol (unified EventMap — all channels on the EventBus)\nexport type {\n EventMap,\n EventName,\n EmittableChannel,\n ResourceBroadcastType,\n} from './bus-protocol';\nexport { RESOURCE_BROADCAST_TYPES, CHANNEL_SCHEMAS } from './bus-protocol';\n\n// Payload type aliases (OpenAPI schema shortcuts used across the codebase)\nexport type {\n Selector,\n GatheredContext,\n SelectionData,\n} from './payload-types';\n\n// Event utilities\nexport type { StoredEventLike } from './event-utils';\nexport {\n getAnnotationUriFromEvent,\n isEventRelatedToAnnotation,\n isStoredEvent,\n} from './event-utils';\n\n// Event bus (RxJS-based, framework-agnostic)\nexport { EventBus, ScopedEventBus } from './event-bus';\n\n// RxJS operators\nexport { burstBuffer, type BurstBufferOptions } from './operators/burst-buffer';\n\n// Per-key serialization (for RPC-style callers; see also RxJS groupBy + concatMap\n// for stream-style callers in packages/make-meaning)\nexport { serializePerKey } from './serialize-per-key';\n\n// Logger interface (framework-agnostic)\nexport type { Logger } from './logger';\nexport { errField } from './logger';\n\n// Bus logging — Tier 1 cross-wire observability\nexport { busLog, busLogEnabled, setBusLogTraceIdProvider, type BusOp } from './bus-log';\n\n// Annotation body matcher (used by mark:body-updated event replay)\nexport { findBodyItem } from './annotation-utils';\nexport type { BodyItemIdentity } from './annotation-utils';\n\n// Annotation assembly (pure functions for building W3C Annotations)\nexport {\n assembleAnnotation,\n applyBodyOperations,\n getTextPositionSelector,\n getSvgSelector,\n getFragmentSelector,\n validateSvgMarkup,\n} from './annotation-assembly';\nexport type { AssembledAnnotation } from './annotation-assembly';\n\n// W3C Web Annotation accessors (target/body/selector helpers + type guards)\nexport {\n getBodySource,\n getBodyType,\n isBodyResolved,\n getTargetSource,\n getTargetSelector,\n hasTargetSelector,\n isHighlight,\n isReference,\n isAssessment,\n isComment,\n isTag,\n getCommentText,\n isStubReference,\n isResolvedReference,\n getExactText,\n getAnnotationExactText,\n getPrimarySelector,\n getTextQuoteSelector,\n extractBoundingBox,\n} from './web-annotation-utils';\nexport type {\n TextPositionSelector,\n TextQuoteSelector,\n SvgSelector,\n FragmentSelector,\n} from './web-annotation-utils';\n\n// ResourceDescriptor accessors\nexport {\n getResourceId,\n getPrimaryRepresentation,\n getPrimaryMediaType,\n getChecksum,\n getLanguage,\n getStorageUri,\n getCreator,\n getDerivedFrom,\n isArchived,\n getResourceEntityTypes,\n isDraft,\n getNodeEncoding,\n decodeRepresentation,\n} from './resource-utils';\n\n// Transport contract — interfaces every concrete transport must satisfy.\nexport type {\n ITransport,\n IBackendOperations,\n IContentTransport,\n BackendDownload,\n PutBinaryRequest,\n PutBinaryOptions,\n PutBinaryProgress,\n ConnectionState,\n ProgressEvent,\n ProgressCallback,\n HealthCheckResponse,\n StatusResponse,\n UserResponse,\n UpdateUserRequest,\n UpdateUserResponse,\n ListUsersResponse,\n} from './transport';\n\n// Channel set every concrete transport bridges into the client's bus.\nexport { BRIDGED_CHANNELS, type BridgedChannel } from './bridged-channels';\n\n// Fuzzy text anchoring (annotation re-anchoring under content edits)\nexport {\n normalizeText,\n buildContentCache,\n findBestTextMatch,\n findTextWithContext,\n verifyPosition,\n} from './fuzzy-anchor';\nexport type { TextPosition, MatchQuality, ContentCache } from './fuzzy-anchor';\n\n// Locale info table\nexport {\n LOCALES,\n getLocaleInfo,\n getLocaleNativeName,\n getLocaleEnglishName,\n formatLocaleDisplay,\n getAllLocaleCodes,\n} from './locales';\nexport type { LocaleInfo } from './locales';\n\n// SVG utilities\nexport {\n createRectangleSvg,\n createPolygonSvg,\n createCircleSvg,\n parseSvgSelector,\n normalizeCoordinates,\n scaleSvgToNative,\n} from './svg-utils';\nexport type { Point, BoundingBox } from './svg-utils';\n\n// Text context extraction (depends on fuzzy-anchor)\nexport { extractContext, validateAndCorrectOffsets } from './text-context';\nexport type { ValidatedAnnotation } from './text-context';\n\n// Text encoding helpers\nexport { extractCharset, decodeWithCharset } from './text-encoding';\n\n// Schema validation helpers\nexport {\n JWTTokenSchema,\n validateData,\n isValidEmail,\n} from './validation';\nexport type { ValidationSuccess, ValidationFailure, ValidationResult } from './validation';\n\n// MIME type helpers\nexport {\n getExtensionForMimeType,\n isImageMimeType,\n isTextMimeType,\n isPdfMimeType,\n getMimeCategory,\n} from './mime-utils';\nexport type { MimeCategory } from './mime-utils';\n\n// Resource types\nexport type { UpdateResourceInput, ResourceFilter } from './resource-types';\n\n// Annotation types\nexport type { Annotation, AnnotationCategory, CreateAnnotationInternal } from './annotation-types';\n\n// Auth types\nexport type { GoogleAuthRequest } from './auth-types';\n\n// ID generation\nexport { generateUuid } from './id-generation';\n\n// Utility functions\nexport * from './type-guards';\nexport * from './errors';\nexport * from './did-utils';\n\n// Configuration types\nexport type {\n EnvironmentConfig,\n SiteConfig,\n AppConfig,\n} from './config/config.types';\n\nexport {\n loadTomlConfig,\n createTomlConfigLoader,\n type TomlFileReader,\n type InferenceConfig as TomlInferenceConfig,\n type ActorInferenceConfig as TomlActorInferenceConfig,\n type WorkerInferenceConfig as TomlWorkerInferenceConfig,\n} from './config/toml-loader';\n\nexport {\n parseEnvironment,\n validateEnvironment,\n type Environment,\n} from './config/environment-validator';\nexport { ConfigurationError } from './config/configuration-error';\nexport {\n type PlatformType,\n isValidPlatformType,\n getAllPlatformTypes,\n} from './config/platform-types';\n\n// Schema-generated configuration types\nexport type {\n BackendServiceConfig,\n FrontendServiceConfig,\n DatabaseServiceConfig,\n GraphServiceConfig,\n OllamaProviderConfig,\n AnthropicProviderConfig,\n InferenceProvidersConfig,\n McpServiceConfig,\n ServicesConfig,\n VectorsServiceConfig,\n EmbeddingServiceConfig,\n SemiontConfig,\n GraphDatabaseType,\n ServicePlatformConfig\n} from './config/config.types';\n\n// Version information\nexport const CORE_TYPES_VERSION = '0.1.0';\nexport const SDK_VERSION = '0.1.0';\n"]}
|