@semiont/core 0.5.12 → 0.5.13
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 +51 -2
- package/dist/index.js +27 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -7218,5 +7218,54 @@ interface GraphViews {
|
|
|
7218
7218
|
}
|
|
7219
7219
|
declare function deriveViews(graph: KnowledgeGraph, mainResourceId: string, focalAnnotationId?: string): GraphViews;
|
|
7220
7220
|
|
|
7221
|
-
|
|
7222
|
-
|
|
7221
|
+
/**
|
|
7222
|
+
* Bounded retry with exponential backoff.
|
|
7223
|
+
*
|
|
7224
|
+
* Exists for startup-critical network calls in long-running peers (worker,
|
|
7225
|
+
* smelter, weaver): each authenticates against the KS the moment its
|
|
7226
|
+
* container starts, and the backend may not be reachable for a few seconds
|
|
7227
|
+
* (backend restart, container-network warm-up). Orchestration runs these
|
|
7228
|
+
* processes with `--rm` and no restart policy, so a process that dies on
|
|
7229
|
+
* the first `TypeError: fetch failed` is dead for good — the retry window
|
|
7230
|
+
* here is the only recovery it gets.
|
|
7231
|
+
*/
|
|
7232
|
+
interface RetryPolicy {
|
|
7233
|
+
/** Total attempts, including the first one. */
|
|
7234
|
+
attempts: number;
|
|
7235
|
+
/** Delay before the second attempt; doubles each retry. */
|
|
7236
|
+
initialDelayMs: number;
|
|
7237
|
+
/** Ceiling for the doubled delay. */
|
|
7238
|
+
maxDelayMs: number;
|
|
7239
|
+
}
|
|
7240
|
+
interface RetryAttemptInfo {
|
|
7241
|
+
/** 1-based number of the attempt that just failed. */
|
|
7242
|
+
attempt: number;
|
|
7243
|
+
/** Total attempt budget from the policy. */
|
|
7244
|
+
attempts: number;
|
|
7245
|
+
/** How long we wait before the next attempt. */
|
|
7246
|
+
delayMs: number;
|
|
7247
|
+
error: unknown;
|
|
7248
|
+
}
|
|
7249
|
+
/**
|
|
7250
|
+
* Default policy for startup connections to the backend: 8 attempts with
|
|
7251
|
+
* delays 1s, 2s, 4s, then capped at 8s — ~39s of patience before giving up.
|
|
7252
|
+
*/
|
|
7253
|
+
declare const STARTUP_FETCH_RETRY: RetryPolicy;
|
|
7254
|
+
/**
|
|
7255
|
+
* True for the errors `fetch` throws when the connection itself fails —
|
|
7256
|
+
* undici's `TypeError: fetch failed` (ECONNREFUSED, ENOTFOUND, reset,
|
|
7257
|
+
* timeout — the socket error rides in `cause`). Deliberately false for
|
|
7258
|
+
* HTTP-level failures (a 401 means the backend is UP and rejected us;
|
|
7259
|
+
* retrying won't change its mind) and for programming errors.
|
|
7260
|
+
*/
|
|
7261
|
+
declare function isTransientFetchError(error: unknown): boolean;
|
|
7262
|
+
/**
|
|
7263
|
+
* Run `fn`, retrying on errors `isRetryable` accepts, with exponential
|
|
7264
|
+
* backoff per `policy`. `onRetry` fires before each wait — the caller's
|
|
7265
|
+
* hook for logging the attempt. The final error (retryable budget
|
|
7266
|
+
* exhausted, or the first non-retryable one) is rethrown verbatim.
|
|
7267
|
+
*/
|
|
7268
|
+
declare function retryWithBackoff<T>(fn: () => Promise<T>, isRetryable: (error: unknown) => boolean, policy: RetryPolicy, onRetry?: (info: RetryAttemptInfo) => void): Promise<T>;
|
|
7269
|
+
|
|
7270
|
+
export { AUTHORABLE_MEDIA_TYPES, BRIDGED_CHANNELS, BusRequestError, CHANNEL_SCHEMAS, CONTEXT_FULL_WEIGHT, CONTEXT_PARTIAL_WEIGHT, ConfigurationError, ConflictError, EMBEDDABLE_MEDIA_TYPES, EventBus, JWTTokenSchema, LOCALES, MEDIA_TYPES, NotFoundError, PERSISTED_EVENT_TYPES, POSITION_WEIGHT_MAX, POSITION_WINDOW, RESOURCE_BROADCAST_TYPES, STARTUP_FETCH_RETRY, ScopedEventBus, ScriptError, SemiontError, UnauthorizedError, ValidationError, accessToken, agentToDid, anchorAnnotation, annotationId, annotationUri, applyBodyOperations, assembleAnnotation, authCode, baseMediaType, baseUrl, buildContentCache, burstBuffer, busLog, busLogEnabled, busRequest, capabilitiesOf, cloneToken, createCircleSvg, createFragmentSelector, createPolygonSvg, createRectangleSvg, createTomlConfigLoader, decodeRepresentation, decodeWithCharset, deriveViews, didToAgent, email, entityType, errField, extensionForMediaType, extractBoundingBox, extractCharset, extractContext, findBestTextMatch, findBodyItem, 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, getStorageUri, getSvgSelector, getTargetSelector, getTargetSource, getTextPositionSelector, getTextQuoteSelector, googleCredential, hasTargetSelector, isAnnotationId, isArchived, isArray, isAssessment, isBodyResolved, isBoolean, isComment, isDefined, isDraft, isEventRelatedToAnnotation, isFunction, isHighlight, isNull, isNullish, isNumber, isObject, isReference, isResolvedReference, isResourceId, isStoredEvent, isString, isStubReference, isSupportedMediaType, isTag, isTransientFetchError, isUndefined, isValidEmail, isValidPlatformType, jobId, loadTomlConfig, mcpToken, mediaTypeForExtension, normalizeCoordinates, normalizeText, parseEnvironment, parseFragmentSelector, parseSvgSelector, reconcileSelector, refreshToken, resourceAnnotationUri, resourceId, resourceUri, retryWithBackoff, scaleSvgToNative, searchQuery, serializePerKey, setBusLogTraceIdProvider, softwareToAgent, textExtractionOf, userDID, userId, userToAgent, userToDid, validateData, validateEnvironment, validateSvgMarkup, verifyPosition };
|
|
7271
|
+
export type { AccessToken, AnchorConfidence, AnchorMethod, AnchorRect, AnchorSelectors, AnchorStrategy, AnchoringModel, Annotation, AnnotationCategory, AnnotationId, AnnotationUri, AnthropicProviderConfig, AppConfig, AssembledAnnotation, AuthCode, BackendDownload, BackendServiceConfig, BaseUrl, BodyItem, BodyItemIdentity, BodyOperation, BoundingBox, Brand, BridgedChannel, BurstBufferOptions, BusOp, BusRequestErrorCode, BusRequestPrimitive, CloneToken, CollaboratorEntry, ConnectionState, ContentCache, ContentFormat, CreateAnnotationInternal, DatabaseServiceConfig, Email, EmbeddingServiceConfig, EmittableChannel, EntityType, EntityTypeStats, Environment, EnvironmentConfig, EventBase, EventInput, EventMap, EventMetadata, EventName, EventOfType, EventQuery, EventSignature, FragmentSelector, FrontendServiceConfig, GatheredContext, GoogleAuthRequest, GoogleCredential, GraphConnection, GraphDatabaseType, GraphPath, GraphServiceConfig, GraphViews, HealthCheckResponse, IBackendOperations, IContentTransport, ITransport, InferenceProvidersConfig, JobId, JobType, ListUsersResponse, LlmSelectorInput, LocaleInfo, Logger, MCPToken, MatchQuality, McpServiceConfig, MediaTypeCapabilities, Motivation, OllamaProviderConfig, PdfCoordinate, PersistedEvent, PersistedEventType, PlatformType, Point, ProgressCallback, ProgressEvent, PutBinaryOptions, PutBinaryProgress, PutBinaryRequest, ReconciledSelector, RefreshToken, RenderMode, RenderedAnchor, ResourceAnnotationUri, ResourceAnnotations, ResourceBroadcastType, ResourceDescriptor, ResourceFilter, ResourceId, ResourceUri, RetryAttemptInfo, RetryPolicy, SearchQuery, SelectionData, Selector, SemiontConfig, ServicePlatformConfig, ServicesConfig, SiteConfig, StateUnit, StatusResponse, StoredEvent, StoredEventLike, SupportedMediaType, SvgSelector, TagCategory, TagSchema, TextExtraction, TextPosition, TextPositionSelector, TextQuoteSelector, ActorInferenceConfig as TomlActorInferenceConfig, TomlFileReader, InferenceConfig as TomlInferenceConfig, WorkerInferenceConfig as TomlWorkerInferenceConfig, TransportErrorCode, UpdateResourceInput, UpdateUserRequest, UpdateUserResponse, UserDID, UserId, UserResponse, ValidationFailure, ValidationResult, ValidationSuccess, VectorsServiceConfig, components, operations, paths };
|
package/dist/index.js
CHANGED
|
@@ -2423,6 +2423,32 @@ function deriveViews(graph, mainResourceId, focalAnnotationId) {
|
|
|
2423
2423
|
};
|
|
2424
2424
|
}
|
|
2425
2425
|
|
|
2426
|
-
|
|
2426
|
+
// src/retry.ts
|
|
2427
|
+
var STARTUP_FETCH_RETRY = {
|
|
2428
|
+
attempts: 8,
|
|
2429
|
+
initialDelayMs: 1e3,
|
|
2430
|
+
maxDelayMs: 8e3
|
|
2431
|
+
};
|
|
2432
|
+
function isTransientFetchError(error) {
|
|
2433
|
+
if (!(error instanceof TypeError)) return false;
|
|
2434
|
+
if (error.message === "fetch failed") return true;
|
|
2435
|
+
const code = error.cause?.code;
|
|
2436
|
+
return typeof code === "string" && code.length > 0;
|
|
2437
|
+
}
|
|
2438
|
+
async function retryWithBackoff(fn, isRetryable, policy, onRetry) {
|
|
2439
|
+
let delayMs = policy.initialDelayMs;
|
|
2440
|
+
for (let attempt = 1; ; attempt++) {
|
|
2441
|
+
try {
|
|
2442
|
+
return await fn();
|
|
2443
|
+
} catch (error) {
|
|
2444
|
+
if (attempt >= policy.attempts || !isRetryable(error)) throw error;
|
|
2445
|
+
onRetry?.({ attempt, attempts: policy.attempts, delayMs, error });
|
|
2446
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
2447
|
+
delayMs = Math.min(delayMs * 2, policy.maxDelayMs);
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
|
|
2452
|
+
export { AUTHORABLE_MEDIA_TYPES, BRIDGED_CHANNELS, BusRequestError, CHANNEL_SCHEMAS, CONTEXT_FULL_WEIGHT, CONTEXT_PARTIAL_WEIGHT, ConfigurationError, ConflictError, EMBEDDABLE_MEDIA_TYPES, EventBus, JWTTokenSchema, LOCALES, MEDIA_TYPES, NotFoundError, PERSISTED_EVENT_TYPES, POSITION_WEIGHT_MAX, POSITION_WINDOW, RESOURCE_BROADCAST_TYPES, STARTUP_FETCH_RETRY, ScopedEventBus, ScriptError, SemiontError, UnauthorizedError, ValidationError, accessToken, agentToDid, anchorAnnotation, annotationId, annotationUri, applyBodyOperations, assembleAnnotation, authCode, baseMediaType, baseUrl, buildContentCache, burstBuffer, busLog, busLogEnabled, busRequest, capabilitiesOf, cloneToken, createCircleSvg, createFragmentSelector, createPolygonSvg, createRectangleSvg, createTomlConfigLoader, decodeRepresentation, decodeWithCharset, deriveViews, didToAgent, email, entityType, errField, extensionForMediaType, extractBoundingBox, extractCharset, extractContext, findBestTextMatch, findBodyItem, 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, getStorageUri, getSvgSelector, getTargetSelector, getTargetSource, getTextPositionSelector, getTextQuoteSelector, googleCredential, hasTargetSelector, isAnnotationId, isArchived, isArray, isAssessment, isBodyResolved, isBoolean, isComment, isDefined, isDraft, isEventRelatedToAnnotation, isFunction, isHighlight, isNull, isNullish, isNumber, isObject, isReference, isResolvedReference, isResourceId, isStoredEvent, isString, isStubReference, isSupportedMediaType, isTag, isTransientFetchError, isUndefined, isValidEmail, isValidPlatformType, jobId, loadTomlConfig, mcpToken, mediaTypeForExtension, normalizeCoordinates, normalizeText, parseEnvironment, parseFragmentSelector, parseSvgSelector, reconcileSelector, refreshToken, resourceAnnotationUri, resourceId, resourceUri, retryWithBackoff, scaleSvgToNative, searchQuery, serializePerKey, setBusLogTraceIdProvider, softwareToAgent, textExtractionOf, userDID, userId, userToAgent, userToDid, validateData, validateEnvironment, validateSvgMarkup, verifyPosition };
|
|
2427
2453
|
//# sourceMappingURL=index.js.map
|
|
2428
2454
|
//# sourceMappingURL=index.js.map
|