@semiont/make-meaning 0.5.30 → 0.5.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { JobQueue } from '@semiont/jobs';
2
2
  import { SemiontProject, SemiontState } from '@semiont/core/node';
3
- import { GraphServiceConfig, VectorsServiceConfig, EmbeddingServiceConfig, ArchivistServiceConfig, EnvironmentConfig, StateUnit, EventBus, Logger, ResourceId, ResourceDescriptor, components, AnnotationId, GatheredContext, ResourceAnnotations, Annotation, AnnotationCategory, ITransport, BaseUrl, ConnectionState, SemiontError, UserDID, EventMap, IContentTransport, PutBinaryRequest, PutBinaryOptions, ExtractionOutcome, AccessToken, BusRequestPrimitive, ChunkingConfig, UserId } from '@semiont/core';
3
+ import { GraphServiceConfig, VectorsServiceConfig, EmbeddingServiceConfig, ArchivistServiceConfig, EnvironmentConfig, StateUnit, EventBus, Logger, ResourceId, ResourceDescriptor, components, AnnotationId, GatheredContext, ResourceAnnotations, Annotation, AnnotationCategory, ITransport, BaseUrl, ConnectionState, SemiontError, UserDID, EventMap, IContentTransport, PutBinaryRequest, PutBinaryOptions, AccessToken, BusRequestPrimitive, ChunkingConfig, UserId } from '@semiont/core';
4
4
  import { EventReadStorage, ViewMaterializer, EventStore, ViewStorage, EventLog } from '@semiont/event-sourcing';
5
5
  import { WorkingTreeStore, AnchoredTextStore, ContentReads } from '@semiont/content';
6
6
  import { GraphDatabase } from '@semiont/graph';
@@ -741,8 +741,6 @@ interface LimitsDiscovery {
741
741
  *
742
742
  * Handles:
743
743
  * - browse:resource-requested — single resource metadata (materialized from events)
744
- * - browse:anchored-text-by-checksum-requested — the detection workers' read-through
745
- * cache consult: a stored extraction outcome by content identity (ANCHORED-TEXT-TO-SMELTER P2)
746
744
  * - browse:resources-requested — list resources
747
745
  * - browse:annotations-requested — all annotations for a resource
748
746
  * - browse:annotation-requested — single annotation with resolved resource
@@ -813,7 +811,6 @@ declare class Browser {
813
811
  * parser nor engine. Read-only over the wire: the Smelter is the sole
814
812
  * writer and never answers here.
815
813
  */
816
- private handleAnchoredTextByChecksum;
817
814
  private handleBrowseResource;
818
815
  private handleBrowseResources;
819
816
  private handleBrowseAnnotations;
@@ -1152,36 +1149,6 @@ declare class LocalContentTransport implements IContentTransport {
1152
1149
  putBinary(_request: PutBinaryRequest, _options?: PutBinaryOptions): Promise<{
1153
1150
  resourceId: ResourceId;
1154
1151
  }>;
1155
- /**
1156
- * Store a derived coordinate map under the content checksum the producer
1157
- * read (PERSIST-ANCHORS decision A — see the interface doc for why the
1158
- * producer supplies the key). In local mode this is the same store the
1159
- * HTTP route writes to — one storage authority, reached the same way from
1160
- * every process (ANCHORED-TEXT-CACHE Lane 5).
1161
- */
1162
- putAnchoredText(checksum: string, outcome: ExtractionOutcome, _options?: {
1163
- auth?: AccessToken;
1164
- }): Promise<void>;
1165
- /** The stored outcome, or null when nothing has derived one — the common case. */
1166
- getAnchoredText(resourceId: ResourceId, _options?: {
1167
- auth?: AccessToken;
1168
- }): Promise<ExtractionOutcome | null>;
1169
- /**
1170
- * The cache-consult read (PERSIST-ANCHORS P2c), straight from the store —
1171
- * checksum-addressed, so no view resolution and no settle barrier: the
1172
- * caller holds the content identity already.
1173
- */
1174
- getAnchoredTextByChecksum(checksum: string, _options?: {
1175
- auth?: AccessToken;
1176
- }): Promise<ExtractionOutcome | null>;
1177
- /**
1178
- * The store's would-hit keys, straight from the store — planning data for
1179
- * the reconcile diff (PERSIST-ANCHORS P0), so no settle barrier applies:
1180
- * presence is being asked, not content at a moment.
1181
- */
1182
- listAnchoredTextKeys(_options?: {
1183
- auth?: AccessToken;
1184
- }): Promise<string[]>;
1185
1152
  getBinary(resourceId: ResourceId, _options?: {
1186
1153
  auth?: AccessToken;
1187
1154
  }): Promise<{
@@ -1673,10 +1640,12 @@ declare class Smelter {
1673
1640
  * representation's checksum (the bytes the smelter would read), the
1674
1641
  * current entity-type set (the discriminator the stamps must carry), and
1675
1642
  * whether the media type's extractor derives geometry (whether an
1676
- * anchored-text artifact should exist). Embeddable an extractor exists
1677
- * for the media type's strategy the same registry the live fetch
1678
- * resolves, and `yieldsGeometry` is declared on the extractor itself, so
1679
- * every gate here and the live fetch's behavior are twins by construction.
1643
+ * anchored-text artifact should exist). Both answers are core's, keyed by the
1644
+ * media type's strategy: embeddable the type has any text-reading strategy
1645
+ * at all, and geometry that strategy derives it. Until READ-VS-EXTRACT P2
1646
+ * embeddability was asked as `EXTRACTORS[strategy] !== null` true, but a
1647
+ * second statement of `strategy !== 'none'`, answered by resolving an
1648
+ * implementation to learn a fact about a media type.
1680
1649
  * Shared by `reconcile()` and the `smelt:rebuild-anchors` planner.
1681
1650
  */
1682
1651
  private classifyEmbeddable;
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { STALL_THRESHOLD_MS, FsJobQueue } from '@semiont/jobs';
2
2
  import { FilesystemViewStorage, resolveStorageUri, EventQuery, createEventStore } from '@semiont/event-sourcing';
3
- import { getResourceEntityTypes, getResourceId, getTargetSource, resourceId, decodeRepresentation, getBodySource, getStorageUri, getPrimaryRepresentation, getTargetSelector, deriveViews, getTextPositionSelector, annotationId, errField, userId, generateUuid, getExactText, busRequest, cloneToken, assembleAnnotation, applyBodyOperations, didToAgent, isGenerationJobParams, jobId, entityType, baseUrl, busLog, BRIDGED_CHANNELS, burstBuffer, textExtractionOf, chunkText, getPrimaryMediaType, isAnnotatable, softwareToAgent } from '@semiont/core';
3
+ import { getResourceEntityTypes, getResourceId, getTargetSource, resourceId, decodeRepresentation, getBodySource, getStorageUri, getPrimaryRepresentation, getTargetSelector, deriveViews, getTextPositionSelector, annotationId, errField, userId, generateUuid, getExactText, busRequest, cloneToken, assembleAnnotation, applyBodyOperations, didToAgent, isGenerationJobParams, jobId, entityType, baseUrl, busLog, BRIDGED_CHANNELS, burstBuffer, textSourceOf, chunkText, getPrimaryMediaType, yieldsGeometryOf, isAnnotatable, softwareToAgent } from '@semiont/core';
4
4
  import { recordGatherDegrade, withActorSpan, recordBusEmit, withSpan, SpanKind, registerJobQueueProvider, registerVectorIndexSizeProvider } from '@semiont/observability';
5
5
  import { createInferenceClient } from '@semiont/inference';
6
6
  import { compareByRecencyThenId, getGraphDatabase } from '@semiont/graph';
7
- import { WorkingTreeStore, createAnchoredTextStore, RepresentationMissing, ChecksumMismatchError, EXTRACTORS, calculateChecksum } from '@semiont/content';
7
+ import { WorkingTreeStore, createAnchoredTextStore, RepresentationMissing, ChecksumMismatchError, derivingExtractorFor, calculateChecksum } from '@semiont/content';
8
8
  import { getEntityTypes, DEFAULT_ENTITY_TYPES } from '@semiont/ontology';
9
9
  import { mergeByResource } from '@semiont/vectors';
10
10
  import { promises } from 'fs';
@@ -11861,17 +11861,19 @@ var Stower = class {
11861
11861
  var import_rxjs4 = __toESM(require_cjs());
11862
11862
  var import_operators4 = __toESM(require_operators());
11863
11863
  var ANCHORED_TEXT_SETTLE_TIMEOUT_MS = 15e3;
11864
- async function readAnchoredText(kb, resourceId10) {
11864
+ async function readAnchoredText(kb, resourceId10, settleTimeoutMs = ANCHORED_TEXT_SETTLE_TIMEOUT_MS) {
11865
11865
  const view = await kb.views.get(resourceId(resourceId10));
11866
11866
  const checksum = getPrimaryRepresentation(view?.resource)?.checksum;
11867
- if (!checksum) return null;
11867
+ if (!checksum) return { kind: "unknown" };
11868
11868
  const hit = await kb.anchoredText.read(checksum);
11869
11869
  if (hit) return hit;
11870
11870
  try {
11871
- const outcome = await kb.smeltProgress.whenSettled(resourceId10, checksum, ANCHORED_TEXT_SETTLE_TIMEOUT_MS);
11872
- return outcome === "indexed" ? kb.anchoredText.read(checksum) : null;
11871
+ const outcome = await kb.smeltProgress.whenSettled(resourceId10, checksum, settleTimeoutMs);
11872
+ if (outcome === "skipped") return { kind: "no-map" };
11873
+ if (outcome === "inert") return { kind: "not-yet" };
11874
+ return await kb.anchoredText.read(checksum) ?? { kind: "not-yet" };
11873
11875
  } catch (error) {
11874
- if (error instanceof SmeltProgressTimeout) return null;
11876
+ if (error instanceof SmeltProgressTimeout) return { kind: "not-yet" };
11875
11877
  throw error;
11876
11878
  }
11877
11879
  }
@@ -12003,7 +12005,6 @@ var Browser = class {
12003
12005
  this.subscriptions.push(
12004
12006
  pipe("browse:resource-requested", (e) => this.handleBrowseResource(e)).subscribe({ error: errorHandler }),
12005
12007
  pipe("browse:anchored-text-requested", (e) => this.handleAnchoredText(e)).subscribe({ error: errorHandler }),
12006
- pipe("browse:anchored-text-by-checksum-requested", (e) => this.handleAnchoredTextByChecksum(e)).subscribe({ error: errorHandler }),
12007
12008
  pipe("browse:resources-requested", (e) => this.handleBrowseResources(e)).subscribe({ error: errorHandler }),
12008
12009
  pipe("browse:annotations-requested", (e) => this.handleBrowseAnnotations(e)).subscribe({ error: errorHandler }),
12009
12010
  pipe("browse:annotation-requested", (e) => this.handleBrowseAnnotation(e)).subscribe({ error: errorHandler }),
@@ -12057,20 +12058,6 @@ var Browser = class {
12057
12058
  * parser nor engine. Read-only over the wire: the Smelter is the sole
12058
12059
  * writer and never answers here.
12059
12060
  */
12060
- async handleAnchoredTextByChecksum(event) {
12061
- try {
12062
- this.eventBus.get("browse:anchored-text-by-checksum-result").next({
12063
- correlationId: event.correlationId,
12064
- response: await this.kb.anchoredText.read(event.checksum)
12065
- });
12066
- } catch (error) {
12067
- this.logger.error("Browse anchored text by checksum failed", { checksum: event.checksum, error: errField(error) });
12068
- this.eventBus.get("browse:anchored-text-by-checksum-failed").next({
12069
- correlationId: event.correlationId,
12070
- message: error instanceof Error ? error.message : String(error)
12071
- });
12072
- }
12073
- }
12074
12061
  async handleBrowseResource(event) {
12075
12062
  try {
12076
12063
  const response = await assembleResourceGraph(this.kb, resourceId(event.resourceId));
@@ -13732,40 +13719,6 @@ var LocalContentTransport = class {
13732
13719
  "LocalContentTransport does not support putBinary() \u2014 create resources via bus emits (mark/yield namespaces) in local mode"
13733
13720
  );
13734
13721
  }
13735
- /**
13736
- * Store a derived coordinate map under the content checksum the producer
13737
- * read (PERSIST-ANCHORS decision A — see the interface doc for why the
13738
- * producer supplies the key). In local mode this is the same store the
13739
- * HTTP route writes to — one storage authority, reached the same way from
13740
- * every process (ANCHORED-TEXT-CACHE Lane 5).
13741
- */
13742
- async putAnchoredText(checksum, outcome, _options) {
13743
- busLog("PUT", "anchored-text", { checksum });
13744
- await this.kb.anchoredText.write(checksum, outcome);
13745
- }
13746
- /** The stored outcome, or null when nothing has derived one — the common case. */
13747
- async getAnchoredText(resourceId10, _options) {
13748
- busLog("GET", "anchored-text", { resourceId: resourceId10 });
13749
- return readAnchoredText(this.kb, resourceId10);
13750
- }
13751
- /**
13752
- * The cache-consult read (PERSIST-ANCHORS P2c), straight from the store —
13753
- * checksum-addressed, so no view resolution and no settle barrier: the
13754
- * caller holds the content identity already.
13755
- */
13756
- async getAnchoredTextByChecksum(checksum, _options) {
13757
- busLog("GET", "anchored-text-by-checksum", { checksum });
13758
- return this.kb.anchoredText.read(checksum);
13759
- }
13760
- /**
13761
- * The store's would-hit keys, straight from the store — planning data for
13762
- * the reconcile diff (PERSIST-ANCHORS P0), so no settle barrier applies:
13763
- * presence is being asked, not content at a moment.
13764
- */
13765
- async listAnchoredTextKeys(_options) {
13766
- busLog("GET", "anchored-text-keys", {});
13767
- return this.kb.anchoredText.list();
13768
- }
13769
13722
  async getBinary(resourceId10, _options) {
13770
13723
  busLog("GET", "content", { resourceId: resourceId10 });
13771
13724
  return withSpan(
@@ -14107,8 +14060,8 @@ var Smelter = class _Smelter {
14107
14060
  if (!rid) return;
14108
14061
  const { data, contentType } = await this.content.getBinary(resourceId(rid));
14109
14062
  const bytes = Buffer.from(data);
14110
- const extractor = EXTRACTORS[textExtractionOf(contentType)];
14111
- if (!extractor?.yieldsGeometry) {
14063
+ const extractor = derivingExtractorFor(contentType);
14064
+ if (!extractor) {
14112
14065
  this.logger.info("Re-anchor found no geometry-capable extractor", { resourceId: rid, contentType });
14113
14066
  return;
14114
14067
  }
@@ -14147,15 +14100,12 @@ var Smelter = class _Smelter {
14147
14100
  const { data, contentType } = await this.content.getBinary(resourceId(resourceId10));
14148
14101
  const bytes = Buffer.from(data);
14149
14102
  const checksum = calculateChecksum(bytes);
14150
- const extractor = EXTRACTORS[textExtractionOf(contentType)];
14151
- if (!extractor) {
14152
- this.logger.debug("Skipping resource with no extractor for its media type", { resourceId: resourceId10, contentType });
14103
+ const extractor = derivingExtractorFor(contentType);
14104
+ if (!extractor && textSourceOf(contentType) === "none") {
14105
+ this.logger.debug("Skipping resource with no way to read its media type", { resourceId: resourceId10, contentType });
14153
14106
  return { kind: "skipped", checksum, reason: "no-extractor" };
14154
14107
  }
14155
- const extracted = await extractor.extract(bytes, contentType, {
14156
- key: checksum,
14157
- store: this.anchoredStore
14158
- });
14108
+ const extracted = extractor ? await extractor.extract(bytes, contentType, { key: checksum, store: this.anchoredStore }) : { kind: "extracted", text: decodeRepresentation(bytes, contentType), method: "text-passthrough" };
14159
14109
  if (extracted.kind === "declined") {
14160
14110
  this.logger.debug("Extractor declined", { resourceId: resourceId10, contentType, reason: extracted.declined });
14161
14111
  return { kind: "skipped", checksum, reason: extracted.declined };
@@ -14570,22 +14520,24 @@ var Smelter = class _Smelter {
14570
14520
  * representation's checksum (the bytes the smelter would read), the
14571
14521
  * current entity-type set (the discriminator the stamps must carry), and
14572
14522
  * whether the media type's extractor derives geometry (whether an
14573
- * anchored-text artifact should exist). Embeddable an extractor exists
14574
- * for the media type's strategy the same registry the live fetch
14575
- * resolves, and `yieldsGeometry` is declared on the extractor itself, so
14576
- * every gate here and the live fetch's behavior are twins by construction.
14523
+ * anchored-text artifact should exist). Both answers are core's, keyed by the
14524
+ * media type's strategy: embeddable the type has any text-reading strategy
14525
+ * at all, and geometry that strategy derives it. Until READ-VS-EXTRACT P2
14526
+ * embeddability was asked as `EXTRACTORS[strategy] !== null` true, but a
14527
+ * second statement of `strategy !== 'none'`, answered by resolving an
14528
+ * implementation to learn a fact about a media type.
14577
14529
  * Shared by `reconcile()` and the `smelt:rebuild-anchors` planner.
14578
14530
  */
14579
14531
  classifyEmbeddable(resources) {
14580
14532
  const embeddable = /* @__PURE__ */ new Map();
14581
14533
  for (const resource of resources) {
14582
14534
  const mediaType = getPrimaryMediaType(resource);
14583
- const extractor = mediaType ? EXTRACTORS[textExtractionOf(mediaType)] : null;
14584
- if (resource["@id"] && extractor) {
14535
+ const readable = mediaType !== void 0 && textSourceOf(mediaType) !== "none";
14536
+ if (resource["@id"] && mediaType && readable) {
14585
14537
  embeddable.set(resource["@id"], {
14586
14538
  checksum: getPrimaryRepresentation(resource)?.checksum,
14587
14539
  entityTypes: getResourceEntityTypes(resource),
14588
- yieldsGeometry: extractor.yieldsGeometry
14540
+ yieldsGeometry: yieldsGeometryOf(mediaType)
14589
14541
  });
14590
14542
  }
14591
14543
  }