@opendatalabs/vana-sdk 3.20.1 → 3.22.0

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.
Files changed (40) hide show
  1. package/README.md +64 -0
  2. package/dist/direct/access-request-client.cjs +100 -2
  3. package/dist/direct/access-request-client.cjs.map +1 -1
  4. package/dist/direct/access-request-client.d.ts +23 -1
  5. package/dist/direct/access-request-client.js +98 -1
  6. package/dist/direct/access-request-client.js.map +1 -1
  7. package/dist/direct/controller.cjs +4 -0
  8. package/dist/direct/controller.cjs.map +1 -1
  9. package/dist/direct/controller.d.ts +10 -1
  10. package/dist/direct/controller.js +6 -1
  11. package/dist/direct/controller.js.map +1 -1
  12. package/dist/direct/types.cjs.map +1 -1
  13. package/dist/direct/types.d.ts +45 -0
  14. package/dist/direct/types.js.map +1 -1
  15. package/dist/index.browser.d.ts +2 -1
  16. package/dist/index.browser.js +186 -0
  17. package/dist/index.browser.js.map +4 -4
  18. package/dist/index.node.cjs +196 -0
  19. package/dist/index.node.cjs.map +4 -4
  20. package/dist/index.node.d.ts +2 -1
  21. package/dist/index.node.js +186 -0
  22. package/dist/index.node.js.map +4 -4
  23. package/dist/protocol/derivative-questions.cjs +22 -0
  24. package/dist/protocol/derivative-questions.cjs.map +1 -1
  25. package/dist/protocol/derivative-questions.d.ts +53 -0
  26. package/dist/protocol/derivative-questions.js +19 -0
  27. package/dist/protocol/derivative-questions.js.map +1 -1
  28. package/dist/protocol/derivative-status.cjs +209 -0
  29. package/dist/protocol/derivative-status.cjs.map +1 -0
  30. package/dist/protocol/derivative-status.d.ts +196 -0
  31. package/dist/protocol/derivative-status.js +190 -0
  32. package/dist/protocol/derivative-status.js.map +1 -0
  33. package/dist/protocol/derivative-status.test.d.ts +1 -0
  34. package/dist/server.cjs +4 -2
  35. package/dist/server.cjs.map +1 -1
  36. package/dist/server.d.ts +2 -2
  37. package/dist/server.js +4 -2
  38. package/dist/server.js.map +1 -1
  39. package/dist/tests/mock-personal-server.d.ts +9 -0
  40. package/package.json +1 -1
@@ -51,7 +51,8 @@ export { ScopeSchema, parseScope, scopeToPathSegments, scopeMatchesPattern, scop
51
51
  export { SCOPE_ACTIONS, InvalidScopeEntryError, parseScopeEntry, formatScopeEntry, grantPermissions, permissionsToScopes, tryGrantPermissions, hasAction, type ScopeAction, type ParsedScopeEntry, type GrantPermission, } from "./protocol/scope-actions.js";
52
52
  export { WRITE_SESSION_PATH, WRITE_SIGNATURE_HEADER, WRITE_METADATA_HEADER, WRITE_FILENAME_HEADER, WRITE_CONTENT_DISPOSITION_HEADER, WRITER_ATTRIBUTION_KEY, LINEAGE_KEY, LINEAGE_FIELD, MAX_LINEAGE_SOURCES, RESERVED_WRITE_KEYS, openWriteSession, writeData, writePersonalServerData, sessionCoversScope, binaryWriteSignedBytes, normalizeBinaryMimeType, parseWriteMetadataHeader, encodeWriteMetadataHeader, type WriteTransportRetryOptions, type WriteSession, type OpenWriteSessionParams, type WriteBinaryPayload, type LineageSource, type WriteJsonDataParams, type WriteBinaryDataParams, type WriteDataParams, type WriteDataResult, type WritePersonalServerDataParams, type WritePersonalServerDataResult, type BinaryWriteSignedBytesInput, } from "./protocol/personal-server-write.js";
53
53
  export { resolveWriteSigner, type WriteSigner, type WriteSignerSource, type ViemWriteAccount, type ViemWriteWalletClient, type ResolveWriteSignerOptions, } from "./protocol/write-signer.js";
54
- export { DERIVATIVE_QUESTIONS_PATH, MAX_QUESTION_SOURCE_SCOPES, MAX_QUESTION_CHARS, MAX_QUESTION_MODEL_CHARS, DEFAULT_QUESTION_TIMEOUT_MS, DEFAULT_QUESTION_POLL_INTERVAL_MS, QUESTION_STATUSES, registerQuestion, getQuestion, listQuestions, recomputeQuestion, deleteQuestion, waitForQuestion, askPersonalServer, QuestionStatusSchema, QuestionRegisteredBySchema, DerivativeQuestionSchema, QuestionRecomputeResultSchema, QuestionDeleteResultSchema, type QuestionStatus, type QuestionRegisteredBy, type DerivativeQuestion, type QuestionRecomputeResult, type QuestionDeleteResult, type DerivativeQuestionAuthParams, type RegisterQuestionParams, type GetQuestionParams, type ListQuestionsParams, type RecomputeQuestionParams, type DeleteQuestionParams, type WaitForQuestionParams, type AskPersonalServerParams, type AskPersonalServerResult, } from "./protocol/derivative-questions.js";
54
+ export { DERIVATIVE_QUESTIONS_PATH, MAX_QUESTION_SOURCE_SCOPES, MAX_QUESTION_CHARS, MAX_QUESTION_MODEL_CHARS, DEFAULT_QUESTION_TIMEOUT_MS, DEFAULT_QUESTION_POLL_INTERVAL_MS, QUESTION_STATUSES, DERIVATIVE_ERROR_CODES, DerivativeErrorCodeSchema, type DerivativeErrorCode, registerQuestion, getQuestion, listQuestions, recomputeQuestion, deleteQuestion, waitForQuestion, askPersonalServer, QuestionStatusSchema, QuestionRegisteredBySchema, DerivativeQuestionSchema, QuestionRecomputeResultSchema, QuestionDeleteResultSchema, type QuestionStatus, type QuestionRegisteredBy, type DerivativeQuestion, type QuestionRecomputeResult, type QuestionDeleteResult, type DerivativeQuestionAuthParams, type RegisterQuestionParams, type GetQuestionParams, type ListQuestionsParams, type RecomputeQuestionParams, type DeleteQuestionParams, type WaitForQuestionParams, type AskPersonalServerParams, type AskPersonalServerResult, } from "./protocol/derivative-questions.js";
55
+ export { DERIVATIVE_STATUS_PATH, DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS, DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS, derivativeStatusTarget, getDerivativeStatus, waitForDerivativeStatus, isDerivativeStatusSettled, DerivativeStatusSchema, type DerivativeStatus, type GetDerivativeStatusParams, type WaitForDerivativeStatusParams, } from "./protocol/derivative-status.js";
55
56
  export { deriveDataPointId, isDataPointId, scopeNamespace, derivedScopeViolatesNaming, assertDerivedScopeNaming, isRedactedLineageNode, personalServerLineagePath, gatewayLineagePath, getLineage, getPersonalServerLineage, getGatewayLineage, LineageNodeSchema, RedactedLineageNodeSchema, LineageEntrySchema, LineageGraphSchema, type LineageNode, type RedactedLineageNode, type LineageEntry, type LineageGraph, type LineageReadResult, type PersonalServerLineageParams, type GatewayLineageParams, type GetLineageParams, } from "./protocol/lineage.js";
56
57
  export { DataFileEnvelopeSchema, createDataFileEnvelope, IngestResponseSchema, type DataFileEnvelope, type IngestResponse, } from "./protocol/data-file.js";
57
58
  export { createGatewayClient, type GatewayEnvelope, type GatewayProof, type Builder, type Schema, type ServerInfo, type OwnerServerRecord, type OwnerServersResult, type GatewayGrantFee, type GatewayGrantStatus, type GatewayGrantResponse, type GrantListItem, type DataPointRecord, type DataPointListResult, type ListDataPointsOptions, type RegisterServerParams, type RegisterServerResult, type RegisterBuilderParams, type RegisterBuilderResult, type RegisterDataPointParams, type RegisterDataPointResult, type GetDataPointOptions, type DeleteDataPointParams, type DeleteDataPointResult, type CreateGrantParams, type RevokeGrantParams, type AccessRecord, type PayForOperationParams, type PayForOperationResult, type SettleOpType, type SettleItem, type SettlePromoteResult, type SettleReconcileItem, type SettleParams, type SettleResult, type GatewayClient, } from "./protocol/gateway.js";
@@ -34404,6 +34404,13 @@ var QUESTION_STATUSES = [
34404
34404
  "failed",
34405
34405
  "stale"
34406
34406
  ];
34407
+ var DERIVATIVE_ERROR_CODES = [
34408
+ "inference_unavailable",
34409
+ "source_missing",
34410
+ "grant_invalid",
34411
+ "internal"
34412
+ ];
34413
+ var DerivativeErrorCodeSchema = z5.enum(DERIVATIVE_ERROR_CODES);
34407
34414
  var QuestionStatusSchema = z5.enum(QUESTION_STATUSES);
34408
34415
  var QuestionRegisteredBySchema = z5.union([
34409
34416
  z5.object({ kind: z5.literal("owner") }),
@@ -34425,6 +34432,14 @@ var DerivativeQuestionSchema = z5.object({
34425
34432
  status: QuestionStatusSchema,
34426
34433
  /** A short reason, set only while `status` is `failed`. */
34427
34434
  error: nullableString,
34435
+ /**
34436
+ * The coarse failure class behind `error`, set only while `status` is
34437
+ * `failed`. `null` from a Personal Server that predates the class
34438
+ * (`personal-server-ts` before the status route).
34439
+ */
34440
+ errorCode: DerivativeErrorCodeSchema.nullish().transform(
34441
+ (value) => value ?? null
34442
+ ),
34428
34443
  createdAt: z5.string(),
34429
34444
  updatedAt: nullableString,
34430
34445
  /** When the last compute finished, or `null` while `pending`. */
@@ -34557,6 +34572,7 @@ async function questionErrorFromResponse(response, body) {
34557
34572
  );
34558
34573
  }
34559
34574
  }
34575
+ var personalServerErrorFromQuestionResponse = questionErrorFromResponse;
34560
34576
  async function sendOnce(params, resolved, session, spec, bodyBytes) {
34561
34577
  return sendWithFreshProof(
34562
34578
  spec.label,
@@ -34836,6 +34852,166 @@ async function askPersonalServer(params) {
34836
34852
  return { registration, record };
34837
34853
  }
34838
34854
 
34855
+ // src/protocol/derivative-status.ts
34856
+ import { z as z6 } from "zod";
34857
+ var DERIVATIVE_STATUS_PATH = "/v1/derivatives/status";
34858
+ var DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS = 12e4;
34859
+ var DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS = 2e3;
34860
+ var nullable = (schema) => schema.nullish().transform((value) => value ?? null);
34861
+ var DerivativeStatusSchema = z6.object({
34862
+ derivedScope: z6.string().min(1),
34863
+ status: QuestionStatusSchema,
34864
+ /** When the last compute finished, or `null` if none ever has. */
34865
+ lastComputedAt: nullable(z6.string()),
34866
+ /** Local version of the derived record the last compute wrote. */
34867
+ derivedVersion: nullable(z6.number()),
34868
+ derivedCollectedAt: nullable(z6.string()),
34869
+ /** The failure class; `null` unless `status` is `failed`. */
34870
+ errorCode: nullable(DerivativeErrorCodeSchema),
34871
+ /**
34872
+ * Seconds until the Personal Server's next automatic retry, or `null` when
34873
+ * none is pending or running — the terminal signature. Poll on this cadence
34874
+ * rather than guessing one.
34875
+ */
34876
+ retryAfterSeconds: nullable(z6.number())
34877
+ });
34878
+ function derivativeStatusTarget(derivedScope) {
34879
+ return `${DERIVATIVE_STATUS_PATH}?derivedScope=${encodeURIComponent(derivedScope)}`;
34880
+ }
34881
+ function normalizeBaseUrl3(url) {
34882
+ return url.replace(/\/+$/, "");
34883
+ }
34884
+ function resolveFetch3(fetchFn) {
34885
+ const resolved = fetchFn ?? globalThis.fetch;
34886
+ if (resolved === void 0) {
34887
+ throw new WriteRequestError("No fetch implementation available");
34888
+ }
34889
+ return resolved;
34890
+ }
34891
+ function requireDerivedScope(derivedScope) {
34892
+ if (typeof derivedScope !== "string" || derivedScope.length === 0) {
34893
+ throw new WriteRequestError("derivedScope is required");
34894
+ }
34895
+ return derivedScope;
34896
+ }
34897
+ function sleep3(ms, signal) {
34898
+ if (ms <= 0) return Promise.resolve();
34899
+ return new Promise((resolve, reject) => {
34900
+ const timer = setTimeout(() => {
34901
+ signal?.removeEventListener("abort", onAbort);
34902
+ resolve();
34903
+ }, ms);
34904
+ const onAbort = () => {
34905
+ clearTimeout(timer);
34906
+ reject(abortError2(signal));
34907
+ };
34908
+ signal?.addEventListener("abort", onAbort, { once: true });
34909
+ });
34910
+ }
34911
+ function timeoutError(latest, timeoutMs) {
34912
+ return new DerivativeQuestionTimeoutError(
34913
+ `Derived scope ${latest.derivedScope} was still ${latest.status} after ${timeoutMs}ms`,
34914
+ {
34915
+ derivedScope: latest.derivedScope,
34916
+ status: latest.status,
34917
+ errorCode: latest.errorCode,
34918
+ retryAfterSeconds: latest.retryAfterSeconds,
34919
+ timeoutMs
34920
+ }
34921
+ );
34922
+ }
34923
+ function abortError2(signal) {
34924
+ const reason = signal?.reason;
34925
+ return reason instanceof Error ? reason : new WriteRequestError("Derivative status wait was aborted");
34926
+ }
34927
+ function isDerivativeStatusSettled(status) {
34928
+ if (status.status === "ready") return true;
34929
+ return status.status === "failed" && status.retryAfterSeconds === null;
34930
+ }
34931
+ async function getDerivativeStatus(params) {
34932
+ const derivedScope = requireDerivedScope(params.derivedScope);
34933
+ const fetchFn = resolveFetch3(params.fetch);
34934
+ const baseUrl = normalizeBaseUrl3(params.personalServerUrl);
34935
+ const signer = resolveWriteSigner(params.signer, { account: params.account });
34936
+ const headers = new Headers(params.headers);
34937
+ headers.set(
34938
+ "Authorization",
34939
+ await buildWeb3SignedHeader({
34940
+ signMessage: signer.signMessage,
34941
+ aud: params.audience ?? baseUrl,
34942
+ method: "GET",
34943
+ uri: DERIVATIVE_STATUS_PATH,
34944
+ grantId: params.grantId
34945
+ })
34946
+ );
34947
+ let response;
34948
+ try {
34949
+ response = await fetchFn(
34950
+ `${baseUrl}${derivativeStatusTarget(derivedScope)}`,
34951
+ {
34952
+ method: "GET",
34953
+ headers,
34954
+ ...params.signal ? { signal: params.signal } : {}
34955
+ }
34956
+ );
34957
+ } catch (err) {
34958
+ throw new WriteTransportError(
34959
+ `Derivative status read failed: ${err instanceof Error ? err.message : String(err)}`,
34960
+ 1,
34961
+ err
34962
+ );
34963
+ }
34964
+ if (!response.ok) {
34965
+ throw await personalServerErrorFromQuestionResponse(
34966
+ response
34967
+ );
34968
+ }
34969
+ let body;
34970
+ try {
34971
+ body = await response.json();
34972
+ } catch (err) {
34973
+ throw new DerivativeQuestionRejectedError(
34974
+ "Derivative status response is not JSON",
34975
+ response.status,
34976
+ null,
34977
+ { cause: err instanceof Error ? err.message : String(err) }
34978
+ );
34979
+ }
34980
+ const parsed = DerivativeStatusSchema.safeParse(body);
34981
+ if (!parsed.success) {
34982
+ throw new DerivativeQuestionRejectedError(
34983
+ "Derivative status response is not a status view",
34984
+ response.status,
34985
+ null,
34986
+ { issues: parsed.error.issues }
34987
+ );
34988
+ }
34989
+ return parsed.data;
34990
+ }
34991
+ async function waitForDerivativeStatus(params) {
34992
+ const timeoutMs = Math.max(
34993
+ 0,
34994
+ params.timeoutMs ?? DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS
34995
+ );
34996
+ const pollIntervalMs = Math.max(
34997
+ 0,
34998
+ params.pollIntervalMs ?? DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS
34999
+ );
35000
+ const deadline = Date.now() + timeoutMs;
35001
+ for (; ; ) {
35002
+ if (params.signal?.aborted) throw abortError2(params.signal);
35003
+ const latest = await getDerivativeStatus(params);
35004
+ if (isDerivativeStatusSettled(latest)) return latest;
35005
+ const remaining = deadline - Date.now();
35006
+ if (remaining <= 0) throw timeoutError(latest, timeoutMs);
35007
+ const waitMs = latest.retryAfterSeconds === null ? pollIntervalMs : latest.retryAfterSeconds * 1e3;
35008
+ if (waitMs > remaining) {
35009
+ throw timeoutError(latest, timeoutMs);
35010
+ }
35011
+ await sleep3(waitMs, params.signal);
35012
+ }
35013
+ }
35014
+
34839
35015
  // src/protocol/gateway.ts
34840
35016
  function withGrantPermissions(grant) {
34841
35017
  const stripped = { ...grant };
@@ -35916,9 +36092,13 @@ export {
35916
36092
  ContractNotFoundError,
35917
36093
  DATA_ACCESS_OP_TYPE,
35918
36094
  DATA_REGISTRY_STATUS_ABI,
36095
+ DEFAULT_DERIVATIVE_STATUS_POLL_INTERVAL_MS,
36096
+ DEFAULT_DERIVATIVE_STATUS_TIMEOUT_MS,
35919
36097
  DEFAULT_QUESTION_POLL_INTERVAL_MS,
35920
36098
  DEFAULT_QUESTION_TIMEOUT_MS,
36099
+ DERIVATIVE_ERROR_CODES,
35921
36100
  DERIVATIVE_QUESTIONS_PATH,
36101
+ DERIVATIVE_STATUS_PATH,
35922
36102
  DataFileEnvelopeSchema,
35923
36103
  DataPointDeletedError,
35924
36104
  DataPointNotFoundError,
@@ -35927,6 +36107,7 @@ export {
35927
36107
  DerivativeComputeUnavailableError,
35928
36108
  DerivativeCycleError,
35929
36109
  DerivativeDerivedScopeRequiredError,
36110
+ DerivativeErrorCodeSchema,
35930
36111
  DerivativeQuestionFailedError,
35931
36112
  DerivativeQuestionInvalidError,
35932
36113
  DerivativeQuestionNotFoundError,
@@ -35934,6 +36115,7 @@ export {
35934
36115
  DerivativeQuestionSchema,
35935
36116
  DerivativeQuestionTimeoutError,
35936
36117
  DerivativeSourceNotGrantedError,
36118
+ DerivativeStatusSchema,
35937
36119
  DropboxStorage,
35938
36120
  ECIESError,
35939
36121
  ESCROW_DEPOSIT_ABI2 as ESCROW_DEPOSIT_ABI,
@@ -36069,6 +36251,7 @@ export {
36069
36251
  decryptWithPassword,
36070
36252
  deleteDataPoint,
36071
36253
  deleteQuestion,
36254
+ derivativeStatusTarget,
36072
36255
  deriveDataPointId,
36073
36256
  deriveMasterKey,
36074
36257
  deriveScopeKey,
@@ -36092,6 +36275,7 @@ export {
36092
36275
  getContractAddress,
36093
36276
  getContractController,
36094
36277
  getContractInfo,
36278
+ getDerivativeStatus,
36095
36279
  getFee,
36096
36280
  getGatewayLineage,
36097
36281
  getLineage,
@@ -36107,6 +36291,7 @@ export {
36107
36291
  isDataPointId,
36108
36292
  isDataPointTombstone,
36109
36293
  isDataPortabilityGatewayConfig,
36294
+ isDerivativeStatusSettled,
36110
36295
  isECIESEncrypted,
36111
36296
  isPlatformSupported,
36112
36297
  isRedactedLineageNode,
@@ -36154,6 +36339,7 @@ export {
36154
36339
  verifyGrantRegistration,
36155
36340
  verifyPkceChallenge,
36156
36341
  verifyWeb3Signed,
36342
+ waitForDerivativeStatus,
36157
36343
  waitForQuestion,
36158
36344
  writeData,
36159
36345
  writePersonalServerData