@semiont/core 0.5.29 → 0.5.31

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.js CHANGED
@@ -1,6 +1,6 @@
1
- export { createTomlConfigLoader, loadTomlConfig } from './chunk-VBMXNYPL.js';
2
- import { BUS_OPERATIONS } from './chunk-MM4HBHMM.js';
3
- export { BRIDGED_CHANNELS, BUS_OPERATIONS, EventBus, ScopedEventBus, accessToken, annotationUri, authCode, baseUrl, busLog, busLogEnabled, cloneToken, email, entityType, googleCredential, jobId, mcpToken, refreshToken, resourceAnnotationUri, resourceUri, searchQuery, setBusLogTraceIdProvider, userDID } from './chunk-MM4HBHMM.js';
1
+ export { createTomlConfigLoader, loadTomlConfig } from './chunk-UGI6IOOX.js';
2
+ import { BUS_OPERATIONS } from './chunk-W6N56PWO.js';
3
+ export { BRIDGED_CHANNELS, BUS_OPERATIONS, EventBus, ScopedEventBus, accessToken, annotationUri, authCode, baseUrl, busLog, busLogEnabled, cloneToken, email, entityType, googleCredential, jobId, mcpToken, refreshToken, resourceAnnotationUri, resourceUri, searchQuery, setBusLogTraceIdProvider, userDID } from './chunk-W6N56PWO.js';
4
4
  import './chunk-YLJ4XMA6.js';
5
5
  import { Observable, merge, TimeoutError, throwError, firstValueFrom } from 'rxjs';
6
6
  import { filter, map, take, timeout, catchError, defaultIfEmpty } from 'rxjs/operators';
@@ -122,6 +122,9 @@ var CHANNEL_SCHEMAS = {
122
122
  "frame:add-tag-schema": "FrameAddTagSchemaCommand",
123
123
  "mark:create-ok": "MarkCreateOk",
124
124
  "mark:create-failed": "CommandError",
125
+ "mark:commit": "MarkCommitCommand",
126
+ "mark:commit-ok": "MarkCommitOk",
127
+ "mark:commit-failed": "CommandError",
125
128
  "mark:delete-ok": "MarkDeleteOk",
126
129
  "mark:delete-failed": "CommandError",
127
130
  "mark:archive-ok": null,
@@ -187,10 +190,6 @@ var CHANNEL_SCHEMAS = {
187
190
  "browse:anchored-text-result": "BrowseAnchoredTextResult",
188
191
  "browse:anchored-text-failed": null,
189
192
  // { correlationId } & CommandError
190
- "browse:anchored-text-by-checksum-requested": "BrowseAnchoredTextByChecksumRequest",
191
- "browse:anchored-text-by-checksum-result": "BrowseAnchoredTextResult",
192
- "browse:anchored-text-by-checksum-failed": null,
193
- // { correlationId } & CommandError
194
193
  "browse:resources-requested": "BrowseResourcesRequest",
195
194
  "browse:resources-result": "BrowseResourcesResult",
196
195
  "browse:resources-failed": null,
@@ -258,8 +257,10 @@ var CHANNEL_SCHEMAS = {
258
257
  "job:report-progress": "JobReportProgressCommand",
259
258
  "job:complete": "JobCompleteCommand",
260
259
  "job:fail": "JobFailCommand",
260
+ "job:checkpoint": "JobCheckpointCommand",
261
261
  "job:queued": "JobQueuedEvent",
262
262
  "job:cancel-requested": "JobCancelRequest",
263
+ "job:cancel": "JobCancelCommand",
263
264
  "job:status-requested": "JobStatusRequest",
264
265
  "job:create": "JobCreateCommand",
265
266
  "job:claim": "JobClaimCommand",
@@ -1008,10 +1009,32 @@ var BusRequestError = class extends SemiontError {
1008
1009
  this.name = "BusRequestError";
1009
1010
  }
1010
1011
  };
1012
+ function replyChannelsFor(channels) {
1013
+ const out = /* @__PURE__ */ new Set();
1014
+ for (const ch of channels) {
1015
+ const op = BUS_OPERATIONS[ch];
1016
+ if (!op) continue;
1017
+ out.add(op.result);
1018
+ out.add(op.failure);
1019
+ if ("progress" in op && op.progress) out.add(op.progress);
1020
+ }
1021
+ return [...out];
1022
+ }
1011
1023
  async function busRequest(bus, operation, payload, timeoutMs = 3e4) {
1012
1024
  const correlationId = uuidV4();
1013
1025
  const fullPayload = { ...payload, correlationId };
1014
1026
  const { result: resultChannel, failure: failureChannel } = BUS_OPERATIONS[operation];
1027
+ if (bus.isSubscribed) {
1028
+ for (const replyChannel of [resultChannel, failureChannel]) {
1029
+ if (!bus.isSubscribed(replyChannel)) {
1030
+ throw new BusRequestError(
1031
+ `Transport is not subscribed to reply channel ${replyChannel} \u2014 a reply to ${operation} can never arrive. Add this operation's reply channels to the transport's channel set.`,
1032
+ "bus.unsubscribed",
1033
+ { channel: operation, resultChannel, failureChannel }
1034
+ );
1035
+ }
1036
+ }
1037
+ }
1015
1038
  const result$ = merge(
1016
1039
  bus.stream(resultChannel).pipe(
1017
1040
  filter((e) => e.correlationId === correlationId),
@@ -1726,26 +1749,26 @@ var storedBinary = (extension, label) => ({
1726
1749
  label,
1727
1750
  render: "none",
1728
1751
  anchoring: "none",
1729
- extractText: "none",
1752
+ textSource: "none",
1730
1753
  authorable: false,
1731
1754
  uploadable: true,
1732
1755
  generatable: false
1733
1756
  });
1734
1757
  var storedText = (extension, label) => ({
1735
1758
  ...storedBinary(extension, label),
1736
- extractText: "decode"
1759
+ textSource: "decode"
1737
1760
  });
1738
1761
  var MEDIA_TYPES = {
1739
1762
  // Full-capability tier
1740
1763
  // `generatable: application/pdf` — the Typst renderer (PDF-GENERATION P3):
1741
1764
  // the model writes Typst, the worker's pinned binary compiles it.
1742
- "text/markdown": { extension: ".md", label: "Markdown", render: "text", anchoring: "text-selector", extractText: "decode", authorable: true, uploadable: true, generatable: true },
1743
- "text/plain": { extension: ".txt", label: "Plain Text", render: "text", anchoring: "text-selector", extractText: "decode", authorable: true, uploadable: true, generatable: true },
1744
- "text/html": { extension: ".html", label: "HTML", render: "text", anchoring: "text-selector", extractText: "decode", authorable: true, uploadable: true, generatable: false },
1745
- "application/json": { extension: ".json", label: "JSON", render: "text", anchoring: "text-selector", extractText: "decode", authorable: false, uploadable: true, generatable: false },
1746
- "image/png": { extension: ".png", label: "PNG image", render: "image", anchoring: "spatial", extractText: "none", authorable: false, uploadable: true, generatable: false },
1747
- "image/jpeg": { extension: ".jpg", label: "JPEG image", render: "image", anchoring: "spatial", extractText: "none", authorable: false, uploadable: true, generatable: false },
1748
- "application/pdf": { extension: ".pdf", label: "PDF", render: "pdf", anchoring: "spatial", extractText: "pdf-text-layer", authorable: false, uploadable: true, generatable: true },
1765
+ "text/markdown": { extension: ".md", label: "Markdown", render: "text", anchoring: "text-selector", textSource: "decode", authorable: true, uploadable: true, generatable: true },
1766
+ "text/plain": { extension: ".txt", label: "Plain Text", render: "text", anchoring: "text-selector", textSource: "decode", authorable: true, uploadable: true, generatable: true },
1767
+ "text/html": { extension: ".html", label: "HTML", render: "text", anchoring: "text-selector", textSource: "decode", authorable: true, uploadable: true, generatable: false },
1768
+ "application/json": { extension: ".json", label: "JSON", render: "text", anchoring: "text-selector", textSource: "decode", authorable: false, uploadable: true, generatable: false },
1769
+ "image/png": { extension: ".png", label: "PNG image", render: "image", anchoring: "spatial", textSource: "none", authorable: false, uploadable: true, generatable: false },
1770
+ "image/jpeg": { extension: ".jpg", label: "JPEG image", render: "image", anchoring: "spatial", textSource: "none", authorable: false, uploadable: true, generatable: false },
1771
+ "application/pdf": { extension: ".pdf", label: "PDF", render: "pdf", anchoring: "spatial", textSource: "pdf-text-layer", authorable: false, uploadable: true, generatable: true },
1749
1772
  // Storage tier — the big tent. Every row is a deliberate admission,
1750
1773
  // promotable by editing its row. Text-flavored rows embed (decode).
1751
1774
  // Text
@@ -1851,11 +1874,19 @@ function mediaTypeForExtension(ext) {
1851
1874
  const dotted = lower.startsWith(".") ? lower : `.${lower}`;
1852
1875
  return EXTENSION_TO_MEDIA_TYPE.get(EXTENSION_ALIASES[dotted] ?? dotted);
1853
1876
  }
1854
- function textExtractionOf(format) {
1877
+ function textSourceOf(format) {
1855
1878
  const caps = capabilitiesOf(format);
1856
- if (caps) return caps.extractText;
1879
+ if (caps) return caps.textSource;
1857
1880
  return baseMediaType(format).startsWith("text/") ? "decode" : "none";
1858
1881
  }
1882
+ var GEOMETRY_BY_STRATEGY = {
1883
+ "decode": false,
1884
+ "pdf-text-layer": true,
1885
+ "none": false
1886
+ };
1887
+ function yieldsGeometryOf(format) {
1888
+ return GEOMETRY_BY_STRATEGY[textSourceOf(format)];
1889
+ }
1859
1890
  function isAnnotatable(format) {
1860
1891
  const caps = capabilitiesOf(format);
1861
1892
  return caps !== void 0 && caps.anchoring !== "none";
@@ -1865,7 +1896,7 @@ var AUTHORABLE_MEDIA_TYPES = REGISTRY_KEYS.filter(
1865
1896
  (type) => MEDIA_TYPES[type].authorable
1866
1897
  );
1867
1898
  var EMBEDDABLE_MEDIA_TYPES = REGISTRY_KEYS.filter(
1868
- (type) => MEDIA_TYPES[type].extractText !== "none"
1899
+ (type) => MEDIA_TYPES[type].textSource !== "none"
1869
1900
  );
1870
1901
  var GENERATABLE_MEDIA_TYPES = REGISTRY_KEYS.filter(
1871
1902
  (type) => MEDIA_TYPES[type].generatable
@@ -2140,6 +2171,9 @@ function deriveViews(graph, mainResourceId, focalAnnotationId) {
2140
2171
  }
2141
2172
 
2142
2173
  // src/retry.ts
2174
+ function equalJitter(cap) {
2175
+ return cap / 2 + Math.random() * (cap / 2);
2176
+ }
2143
2177
  var STARTUP_FETCH_RETRY = {
2144
2178
  attempts: 8,
2145
2179
  initialDelayMs: 1e3,
@@ -2151,16 +2185,25 @@ function isTransientFetchError(error) {
2151
2185
  const code = error.cause?.code;
2152
2186
  return typeof code === "string" && code.length > 0;
2153
2187
  }
2188
+ var RETRYABLE_STATUSES = /* @__PURE__ */ new Set([429, 503, 504]);
2189
+ function isRetryableRequestError(error) {
2190
+ if (isTransientFetchError(error)) return true;
2191
+ if (typeof error !== "object" || error === null) return false;
2192
+ if (error.name === "TimeoutError") return true;
2193
+ const status = error.status;
2194
+ return typeof status === "number" && RETRYABLE_STATUSES.has(status);
2195
+ }
2154
2196
  async function retryWithBackoff(fn, isRetryable, policy, onRetry) {
2155
- let delayMs = policy.initialDelayMs;
2197
+ let cap = policy.initialDelayMs;
2156
2198
  for (let attempt = 1; ; attempt++) {
2157
2199
  try {
2158
2200
  return await fn();
2159
2201
  } catch (error) {
2160
2202
  if (attempt >= policy.attempts || !isRetryable(error)) throw error;
2203
+ const delayMs = equalJitter(cap);
2161
2204
  onRetry?.({ attempt, attempts: policy.attempts, delayMs, error });
2162
2205
  await new Promise((resolve) => setTimeout(resolve, delayMs));
2163
- delayMs = Math.min(delayMs * 2, policy.maxDelayMs);
2206
+ cap = Math.min(cap * 2, policy.maxDelayMs);
2164
2207
  }
2165
2208
  }
2166
2209
  }
@@ -2195,6 +2238,6 @@ function getShardPath(key, numBuckets = 65536) {
2195
2238
  // src/discovery.ts
2196
2239
  var DISCOVERY_URL_PATH = "/discovery/kbs.json";
2197
2240
 
2198
- export { AUTHORABLE_MEDIA_TYPES, BusRequestError, CHANNEL_SCHEMAS, CONTEXT_FULL_WEIGHT, CONTEXT_PARTIAL_WEIGHT, ConfigurationError, ConflictError, DEFAULT_CHUNKING_CONFIG, DISCOVERY_URL_PATH, EMBEDDABLE_MEDIA_TYPES, GENERATABLE_MEDIA_TYPES, JWTTokenSchema, LOCALES, MEDIA_TYPES, NotFoundError, PERSISTED_EVENT_TYPES, POSITION_WEIGHT_MAX, POSITION_WINDOW, RESOURCE_BROADCAST_TYPES, STARTUP_FETCH_RETRY, ScriptError, SemiontError, UnauthorizedError, ValidationError, agentToDid, anchorAnnotation, anchorRuns, annotationId, applyBodyOperations, assembleAnnotation, baseMediaType, buildContentCache, burstBuffer, busRequest, capabilitiesOf, chunkText, cloneFormat, createCircleSvg, createFragmentSelector, createPolygonSvg, createRectangleSvg, decodeRepresentation, decodeWithCharset, deriveStorageUri, deriveViews, didToAgent, errField, estimateTokens, extensionForMediaType, extractBoundingBox, extractCharset, extractContext, findBestTextMatch, findBodyItem, findClaimSpan, folderOf, formatLocaleDisplay, generateUuid, getAllLocaleCodes, getAllPlatformTypes, getAnnotationExactText, getAnnotationUriFromEvent, getBodySource, getBodyType, getChecksum, getCommentText, getCreator, getDerivedFrom, getExactText, getFragmentSelector, getLanguage, getLocaleEnglishName, getLocaleInfo, getLocaleNativeName, getNodeEncoding, getPageFromFragment, getPrimaryMediaType, getPrimaryRepresentation, getPrimarySelector, getResourceEntityTypes, getResourceId, getShardPath, getStorageUri, getSvgSelector, getTargetSelector, getTargetSource, getTextPositionSelector, getTextQuoteSelector, hasTargetSelector, isAnnotatable, isAnnotationId, isArchived, isArray, isAssessment, isBodyResolved, isBoolean, isComment, isDefined, isDraft, isEventRelatedToAnnotation, isFunction, isGatheredContext, isGenerationJobParams, isHighlight, isNull, isNullish, isNumber, isObject, isReference, isResolvedReference, isResourceId, isStoredEvent, isString, isStubReference, isSupportedMediaType, isTag, isTextRun, isTransientFetchError, isUndefined, isValidEmail, isValidPlatformType, jumpConsistentHash, kbDid, locate, mediaTypeForExtension, normalizeCoordinates, normalizeText, parseEnvironment, parseFragmentSelector, parseSvgSelector, proposeStoragePath, reconcileSelector, resourceId, retryWithBackoff, scaleSvgToNative, serializePerKey, softwareToAgent, storageFileName, textExtractionOf, textUnder, userId, userToAgent, userToDid, uuidV4, validateData, validateEnvironment, validateSvgMarkup, verifyPosition };
2241
+ export { AUTHORABLE_MEDIA_TYPES, BusRequestError, CHANNEL_SCHEMAS, CONTEXT_FULL_WEIGHT, CONTEXT_PARTIAL_WEIGHT, ConfigurationError, ConflictError, DEFAULT_CHUNKING_CONFIG, DISCOVERY_URL_PATH, EMBEDDABLE_MEDIA_TYPES, GENERATABLE_MEDIA_TYPES, JWTTokenSchema, LOCALES, MEDIA_TYPES, NotFoundError, PERSISTED_EVENT_TYPES, POSITION_WEIGHT_MAX, POSITION_WINDOW, RESOURCE_BROADCAST_TYPES, STARTUP_FETCH_RETRY, ScriptError, SemiontError, UnauthorizedError, ValidationError, agentToDid, anchorAnnotation, anchorRuns, annotationId, applyBodyOperations, assembleAnnotation, baseMediaType, buildContentCache, burstBuffer, busRequest, capabilitiesOf, chunkText, cloneFormat, createCircleSvg, createFragmentSelector, createPolygonSvg, createRectangleSvg, decodeRepresentation, decodeWithCharset, deriveStorageUri, deriveViews, didToAgent, errField, estimateTokens, extensionForMediaType, extractBoundingBox, extractCharset, extractContext, findBestTextMatch, findBodyItem, findClaimSpan, folderOf, formatLocaleDisplay, generateUuid, getAllLocaleCodes, getAllPlatformTypes, getAnnotationExactText, getAnnotationUriFromEvent, getBodySource, getBodyType, getChecksum, getCommentText, getCreator, getDerivedFrom, getExactText, getFragmentSelector, getLanguage, getLocaleEnglishName, getLocaleInfo, getLocaleNativeName, getNodeEncoding, getPageFromFragment, getPrimaryMediaType, getPrimaryRepresentation, getPrimarySelector, getResourceEntityTypes, getResourceId, getShardPath, getStorageUri, getSvgSelector, getTargetSelector, getTargetSource, getTextPositionSelector, getTextQuoteSelector, hasTargetSelector, isAnnotatable, isAnnotationId, isArchived, isArray, isAssessment, isBodyResolved, isBoolean, isComment, isDefined, isDraft, isEventRelatedToAnnotation, isFunction, isGatheredContext, isGenerationJobParams, isHighlight, isNull, isNullish, isNumber, isObject, isReference, isResolvedReference, isResourceId, isRetryableRequestError, isStoredEvent, isString, isStubReference, isSupportedMediaType, isTag, isTextRun, isTransientFetchError, isUndefined, isValidEmail, isValidPlatformType, jumpConsistentHash, kbDid, locate, mediaTypeForExtension, normalizeCoordinates, normalizeText, parseEnvironment, parseFragmentSelector, parseSvgSelector, proposeStoragePath, reconcileSelector, replyChannelsFor, resourceId, retryWithBackoff, scaleSvgToNative, serializePerKey, softwareToAgent, storageFileName, textSourceOf, textUnder, userId, userToAgent, userToDid, uuidV4, validateData, validateEnvironment, validateSvgMarkup, verifyPosition, yieldsGeometryOf };
2199
2242
  //# sourceMappingURL=index.js.map
2200
2243
  //# sourceMappingURL=index.js.map