@semiont/make-meaning 0.5.12 → 0.5.14

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.
@@ -1,4 +1,4 @@
1
- import { createTomlConfigLoader, accessToken, baseUrl as baseUrl$1, errField, burstBuffer, busRequest, resourceId, didToAgent, annotationId, findBodyItem } from '@semiont/core';
1
+ import { createTomlConfigLoader, accessToken, baseUrl as baseUrl$1, retryWithBackoff, isTransientFetchError, STARTUP_FETCH_RETRY, errField, burstBuffer, busRequest, resourceId, didToAgent, annotationId, findBodyItem } from '@semiont/core';
2
2
  import { existsSync, readFileSync, promises } from 'fs';
3
3
  import * as path from 'path';
4
4
  import { join } from 'path';
@@ -10095,6 +10095,21 @@ var Weaver = class _Weaver {
10095
10095
  }
10096
10096
  return summary;
10097
10097
  }
10098
+ /**
10099
+ * Key-order-independent serialization for deep equality (W9-deep): two
10100
+ * structurally equal bodies must compare equal regardless of the property
10101
+ * order their storage backend happens to preserve.
10102
+ */
10103
+ static canonicalJson(value) {
10104
+ if (Array.isArray(value)) {
10105
+ return `[${value.map((v) => _Weaver.canonicalJson(v)).join(",")}]`;
10106
+ }
10107
+ if (value !== null && typeof value === "object") {
10108
+ const entries = Object.entries(value).filter(([, v]) => v !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
10109
+ return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${_Weaver.canonicalJson(v)}`).join(",")}}`;
10110
+ }
10111
+ return JSON.stringify(value) ?? "null";
10112
+ }
10098
10113
  /** Compare one resource's graph state against its view; null = in sync. */
10099
10114
  async divergenceOf(resource) {
10100
10115
  const graphDb = this.ensureInitialized();
@@ -10115,6 +10130,14 @@ var Weaver = class _Weaver {
10115
10130
  for (const id of viewIds) {
10116
10131
  if (!graphIds.has(id)) return "annotation-set-mismatch";
10117
10132
  }
10133
+ const viewById = new Map(annotations.map((a) => [String(a.id), a]));
10134
+ for (const graphAnnotation of graphAnnotations) {
10135
+ const viewAnnotation = viewById.get(String(graphAnnotation.id));
10136
+ if (!viewAnnotation) continue;
10137
+ if (_Weaver.canonicalJson(graphAnnotation.body) !== _Weaver.canonicalJson(viewAnnotation.body)) {
10138
+ return "annotation-body-mismatch";
10139
+ }
10140
+ }
10118
10141
  return null;
10119
10142
  }
10120
10143
  async handleRebuildCommand(command) {
@@ -10471,7 +10494,12 @@ var Weaver = class _Weaver {
10471
10494
  const graphDb = this.ensureInitialized();
10472
10495
  this.logger.info("Rebuilding entire GraphDB from events");
10473
10496
  this.logger.info("Using two-pass approach: nodes first, then edges");
10497
+ const entityTypes = await graphDb.getEntityTypes();
10474
10498
  await graphDb.clearDatabase();
10499
+ if (entityTypes.length > 0) {
10500
+ await graphDb.addEntityTypes(entityTypes);
10501
+ this.logger.info("Re-registered frame vocabulary across the wipe", { count: entityTypes.length });
10502
+ }
10475
10503
  const allResourceIds = (await this.fetchAllResources()).map((resource) => resource["@id"]).filter((rid) => !!rid);
10476
10504
  this.logger.info("Found resources to rebuild", { count: allResourceIds.length });
10477
10505
  const ledger = /* @__PURE__ */ new Map();
@@ -10612,20 +10640,34 @@ async function authenticate() {
10612
10640
  logger.warn("No SEMIONT_WORKER_SECRET set \u2014 using empty token");
10613
10641
  return "";
10614
10642
  }
10615
- const response = await fetch(`${baseUrl}/api/tokens/agent`, {
10616
- method: "POST",
10617
- headers: { "Content-Type": "application/json" },
10618
- body: JSON.stringify({
10619
- secret: workerSecret,
10620
- provider: "semiont",
10621
- model: "weaver"
10622
- })
10623
- });
10624
- if (!response.ok) {
10625
- throw new Error(`Authentication failed: ${response.status} ${response.statusText}`);
10626
- }
10627
- const { token } = await response.json();
10628
- return token;
10643
+ return retryWithBackoff(
10644
+ async () => {
10645
+ const response = await fetch(`${baseUrl}/api/tokens/agent`, {
10646
+ method: "POST",
10647
+ headers: { "Content-Type": "application/json" },
10648
+ body: JSON.stringify({
10649
+ secret: workerSecret,
10650
+ provider: "semiont",
10651
+ model: "weaver"
10652
+ })
10653
+ });
10654
+ if (!response.ok) {
10655
+ throw new Error(`Authentication failed: ${response.status} ${response.statusText}`);
10656
+ }
10657
+ const { token } = await response.json();
10658
+ return token;
10659
+ },
10660
+ isTransientFetchError,
10661
+ STARTUP_FETCH_RETRY,
10662
+ ({ attempt, attempts, delayMs, error }) => {
10663
+ logger.warn("Backend unreachable, retrying authentication", {
10664
+ attempt,
10665
+ attempts,
10666
+ retryInMs: delayMs,
10667
+ error: error instanceof Error ? error.message : String(error)
10668
+ });
10669
+ }
10670
+ );
10629
10671
  }
10630
10672
  async function main() {
10631
10673
  const { initObservabilityNode } = await import('@semiont/observability/node');