uvd-x402-sdk 2.51.0 → 2.52.1

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.
@@ -1658,6 +1658,33 @@ interface IdentityByOwnerResponse {
1658
1658
  /**
1659
1659
  * Response from GET /identity/{network}/{agent_id}/metadata/{key}
1660
1660
  */
1661
+ /**
1662
+ * Lifecycle of an async registration. `mint_confirmed` and `done` carry an
1663
+ * `agentId`; `failed` carries an `error`.
1664
+ */
1665
+ type RegisterJobStatus = 'pending' | 'mint_confirmed' | 'done' | 'failed';
1666
+ /**
1667
+ * Status of an asynchronous registration.
1668
+ *
1669
+ * Returned by `POST /register` with `Prefer: respond-async` (HTTP 202) and by
1670
+ * `GET /register/status/{jobId}`.
1671
+ *
1672
+ * Terminal jobs are retained for one hour and then age out, after which the
1673
+ * status endpoint 404s. Read the agent id before then, or it is only
1674
+ * recoverable from the chain.
1675
+ */
1676
+ interface RegisterJobResponse {
1677
+ jobId: string;
1678
+ status: RegisterJobStatus;
1679
+ network?: string;
1680
+ agentId?: AgentId;
1681
+ transaction?: string;
1682
+ transferTransaction?: string;
1683
+ owner?: string;
1684
+ error?: string;
1685
+ }
1686
+ /** Whether polling can stop: the job either finished or failed. */
1687
+ declare function isRegisterJobTerminal(job: RegisterJobResponse): boolean;
1661
1688
  interface IdentityMetadataResponse {
1662
1689
  /** Agent ID (EVM: number, Solana: string) */
1663
1690
  agentId: AgentId;
@@ -1918,6 +1945,39 @@ declare class Erc8004Client {
1918
1945
  * ```
1919
1946
  */
1920
1947
  registerAgent(request: RegisterAgentRequest): Promise<RegisterAgentResponse>;
1948
+ /**
1949
+ * Start a registration without waiting for the chain to confirm it.
1950
+ *
1951
+ * Registration waits on a mint receipt, which on a congested chain outlives
1952
+ * client and proxy timeouts. A timed-out synchronous call is genuinely
1953
+ * ambiguous — the mint may well have landed — and retrying it is how five
1954
+ * duplicate agents once got minted. This returns immediately with a job id
1955
+ * instead; poll {@link getRegisterStatus} or use {@link waitForRegistration}.
1956
+ *
1957
+ * On Solana, `recipient` is a base58 address: the facilitator mints,
1958
+ * initializes the ATOM stats and transfers, paying every fee.
1959
+ */
1960
+ registerAgentAsync(request: RegisterAgentRequest): Promise<RegisterJobResponse>;
1961
+ /**
1962
+ * Read the current state of an asynchronous registration.
1963
+ *
1964
+ * Throws {@link Erc8004LookupError} with `notFound` when the job is unknown or
1965
+ * has aged out — terminal jobs are kept for one hour.
1966
+ */
1967
+ getRegisterStatus(jobId: string): Promise<RegisterJobResponse>;
1968
+ /**
1969
+ * Poll an asynchronous registration until it finishes.
1970
+ *
1971
+ * Rejects on timeout rather than resolving with the last non-terminal status,
1972
+ * so "still pending" is never mistaken for "did not happen": the mint may
1973
+ * still land afterwards, and treating a timeout as failure is what leads to
1974
+ * registering the same agent twice. Keep the job id and poll again rather
1975
+ * than re-registering.
1976
+ */
1977
+ waitForRegistration(jobId: string, options?: {
1978
+ pollIntervalMs?: number;
1979
+ timeoutMs?: number;
1980
+ }): Promise<RegisterJobResponse>;
1921
1981
  /**
1922
1982
  * Get registration endpoint metadata
1923
1983
  *
@@ -2411,4 +2471,4 @@ declare class AdvancedEscrowClient {
2411
2471
  private sendViaAdapter;
2412
2472
  }
2413
2473
 
2414
- export { type AdvancedAuthorizationResult, AdvancedEscrowClient, type AdvancedEscrowClientOptions, type AdvancedEscrowContracts, type AdvancedEscrowTaskTier, type AdvancedPaymentInfo, type AdvancedTransactionResult, type AgentId, type AgentIdentity, type AgentRegistration, type AgentRegistrationFile, type AgentService, type AtomStats, BASE_MAINNET_CONTRACTS, BazaarClient, type BazaarClientOptions, type BazaarDiscoverOptions, type BazaarDiscoverResponse, type BazaarRegisterOptions, type BazaarResource, type CreateEscrowOptions, DEPOSIT_LIMIT_USDC, type DiscoveryAccepts, type DiscoveryCuration, type DiscoveryHealth, type DiscoveryHealthStatus, type DiscoveryListOptions, type DiscoveryPagination, type DiscoveryRegisterOptions, type DiscoveryResource, type DiscoveryResponse, type DiscoverySource, type DiscoveryStats, type DiscoveryTier, type Dispute, type DisputeOutcome, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, ESCROW_TIMEOUT_MS, Erc8004Client, type Erc8004ClientOptions, Erc8004LookupError, type Erc8004Network, EscrowClient, type EscrowClientOptions, type EscrowPayment, type EscrowStateResponse, type EscrowStatus, FacilitatorClient, type FacilitatorClientOptions, type FeedbackEntry, type FeedbackParams, type FeedbackRequest, type FeedbackResponse, HEALTH_FILTERS, type HonoMiddlewareOptions, type IdentityByOwnerResponse, type IdentityMetadataResponse, type IdentityTotalSupplyResponse, MAX_SEARCH_LEN, type MetadataEntryParam, OPERATOR_ABI, OPERATOR_ABI_CREATE3, PAYMENT_INFO_TYPEHASH, type PaymentAcceptance, type PaymentMiddlewareOptions, type PaymentPayloadV2, type PaymentRequirementResolver, type PaymentRequirements, type PaymentRequirementsOptions, type PaymentRequirementsV2, type ProofOfPayment, type RefundRequest, type RefundStatus, type RegisterAgentRequest, type RegisterAgentResponse, type ReputationResponse, type ReputationSummary, type RequestRefundOptions, type ResourceInfoV2, type SettleRequest, type SettleRequestV2, type SettleResponse, type SettleResponseWithProof, TIER_FILTERS, TIER_TIMINGS, USDC_DOMAIN_NAME, type VerifiedPaymentState, type VerifyRequest, type VerifyRequestV2, type VerifyResponse, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentRequirements, buildSettleRequest, buildSettleRequestV2, buildVerifyRequest, buildVerifyRequestV2, canRefundEscrow, canReleaseEscrow, create402Response, createHonoMiddleware, createPaymentMiddleware, epochToDate, escrowTimeRemaining, extractPaymentFromHeaders, getCorsHeaders, getEscrowContractsByChainId, getEscrowSupportedChainIds, isAlive, isEscrowExpired, isEscrowSupportedOnChain, parsePaymentHeader };
2474
+ export { type AdvancedAuthorizationResult, AdvancedEscrowClient, type AdvancedEscrowClientOptions, type AdvancedEscrowContracts, type AdvancedEscrowTaskTier, type AdvancedPaymentInfo, type AdvancedTransactionResult, type AgentId, type AgentIdentity, type AgentRegistration, type AgentRegistrationFile, type AgentService, type AtomStats, BASE_MAINNET_CONTRACTS, BazaarClient, type BazaarClientOptions, type BazaarDiscoverOptions, type BazaarDiscoverResponse, type BazaarRegisterOptions, type BazaarResource, type CreateEscrowOptions, DEPOSIT_LIMIT_USDC, type DiscoveryAccepts, type DiscoveryCuration, type DiscoveryHealth, type DiscoveryHealthStatus, type DiscoveryListOptions, type DiscoveryPagination, type DiscoveryRegisterOptions, type DiscoveryResource, type DiscoveryResponse, type DiscoverySource, type DiscoveryStats, type DiscoveryTier, type Dispute, type DisputeOutcome, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, ESCROW_TIMEOUT_MS, Erc8004Client, type Erc8004ClientOptions, Erc8004LookupError, type Erc8004Network, EscrowClient, type EscrowClientOptions, type EscrowPayment, type EscrowStateResponse, type EscrowStatus, FacilitatorClient, type FacilitatorClientOptions, type FeedbackEntry, type FeedbackParams, type FeedbackRequest, type FeedbackResponse, HEALTH_FILTERS, type HonoMiddlewareOptions, type IdentityByOwnerResponse, type IdentityMetadataResponse, type IdentityTotalSupplyResponse, MAX_SEARCH_LEN, type MetadataEntryParam, OPERATOR_ABI, OPERATOR_ABI_CREATE3, PAYMENT_INFO_TYPEHASH, type PaymentAcceptance, type PaymentMiddlewareOptions, type PaymentPayloadV2, type PaymentRequirementResolver, type PaymentRequirements, type PaymentRequirementsOptions, type PaymentRequirementsV2, type ProofOfPayment, type RefundRequest, type RefundStatus, type RegisterAgentRequest, type RegisterAgentResponse, type RegisterJobResponse, type RegisterJobStatus, type ReputationResponse, type ReputationSummary, type RequestRefundOptions, type ResourceInfoV2, type SettleRequest, type SettleRequestV2, type SettleResponse, type SettleResponseWithProof, TIER_FILTERS, TIER_TIMINGS, USDC_DOMAIN_NAME, type VerifiedPaymentState, type VerifyRequest, type VerifyRequestV2, type VerifyResponse, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentRequirements, buildSettleRequest, buildSettleRequestV2, buildVerifyRequest, buildVerifyRequestV2, canRefundEscrow, canReleaseEscrow, create402Response, createHonoMiddleware, createPaymentMiddleware, epochToDate, escrowTimeRemaining, extractPaymentFromHeaders, getCorsHeaders, getEscrowContractsByChainId, getEscrowSupportedChainIds, isAlive, isEscrowExpired, isEscrowSupportedOnChain, isRegisterJobTerminal, parsePaymentHeader };
@@ -1658,6 +1658,33 @@ interface IdentityByOwnerResponse {
1658
1658
  /**
1659
1659
  * Response from GET /identity/{network}/{agent_id}/metadata/{key}
1660
1660
  */
1661
+ /**
1662
+ * Lifecycle of an async registration. `mint_confirmed` and `done` carry an
1663
+ * `agentId`; `failed` carries an `error`.
1664
+ */
1665
+ type RegisterJobStatus = 'pending' | 'mint_confirmed' | 'done' | 'failed';
1666
+ /**
1667
+ * Status of an asynchronous registration.
1668
+ *
1669
+ * Returned by `POST /register` with `Prefer: respond-async` (HTTP 202) and by
1670
+ * `GET /register/status/{jobId}`.
1671
+ *
1672
+ * Terminal jobs are retained for one hour and then age out, after which the
1673
+ * status endpoint 404s. Read the agent id before then, or it is only
1674
+ * recoverable from the chain.
1675
+ */
1676
+ interface RegisterJobResponse {
1677
+ jobId: string;
1678
+ status: RegisterJobStatus;
1679
+ network?: string;
1680
+ agentId?: AgentId;
1681
+ transaction?: string;
1682
+ transferTransaction?: string;
1683
+ owner?: string;
1684
+ error?: string;
1685
+ }
1686
+ /** Whether polling can stop: the job either finished or failed. */
1687
+ declare function isRegisterJobTerminal(job: RegisterJobResponse): boolean;
1661
1688
  interface IdentityMetadataResponse {
1662
1689
  /** Agent ID (EVM: number, Solana: string) */
1663
1690
  agentId: AgentId;
@@ -1918,6 +1945,39 @@ declare class Erc8004Client {
1918
1945
  * ```
1919
1946
  */
1920
1947
  registerAgent(request: RegisterAgentRequest): Promise<RegisterAgentResponse>;
1948
+ /**
1949
+ * Start a registration without waiting for the chain to confirm it.
1950
+ *
1951
+ * Registration waits on a mint receipt, which on a congested chain outlives
1952
+ * client and proxy timeouts. A timed-out synchronous call is genuinely
1953
+ * ambiguous — the mint may well have landed — and retrying it is how five
1954
+ * duplicate agents once got minted. This returns immediately with a job id
1955
+ * instead; poll {@link getRegisterStatus} or use {@link waitForRegistration}.
1956
+ *
1957
+ * On Solana, `recipient` is a base58 address: the facilitator mints,
1958
+ * initializes the ATOM stats and transfers, paying every fee.
1959
+ */
1960
+ registerAgentAsync(request: RegisterAgentRequest): Promise<RegisterJobResponse>;
1961
+ /**
1962
+ * Read the current state of an asynchronous registration.
1963
+ *
1964
+ * Throws {@link Erc8004LookupError} with `notFound` when the job is unknown or
1965
+ * has aged out — terminal jobs are kept for one hour.
1966
+ */
1967
+ getRegisterStatus(jobId: string): Promise<RegisterJobResponse>;
1968
+ /**
1969
+ * Poll an asynchronous registration until it finishes.
1970
+ *
1971
+ * Rejects on timeout rather than resolving with the last non-terminal status,
1972
+ * so "still pending" is never mistaken for "did not happen": the mint may
1973
+ * still land afterwards, and treating a timeout as failure is what leads to
1974
+ * registering the same agent twice. Keep the job id and poll again rather
1975
+ * than re-registering.
1976
+ */
1977
+ waitForRegistration(jobId: string, options?: {
1978
+ pollIntervalMs?: number;
1979
+ timeoutMs?: number;
1980
+ }): Promise<RegisterJobResponse>;
1921
1981
  /**
1922
1982
  * Get registration endpoint metadata
1923
1983
  *
@@ -2411,4 +2471,4 @@ declare class AdvancedEscrowClient {
2411
2471
  private sendViaAdapter;
2412
2472
  }
2413
2473
 
2414
- export { type AdvancedAuthorizationResult, AdvancedEscrowClient, type AdvancedEscrowClientOptions, type AdvancedEscrowContracts, type AdvancedEscrowTaskTier, type AdvancedPaymentInfo, type AdvancedTransactionResult, type AgentId, type AgentIdentity, type AgentRegistration, type AgentRegistrationFile, type AgentService, type AtomStats, BASE_MAINNET_CONTRACTS, BazaarClient, type BazaarClientOptions, type BazaarDiscoverOptions, type BazaarDiscoverResponse, type BazaarRegisterOptions, type BazaarResource, type CreateEscrowOptions, DEPOSIT_LIMIT_USDC, type DiscoveryAccepts, type DiscoveryCuration, type DiscoveryHealth, type DiscoveryHealthStatus, type DiscoveryListOptions, type DiscoveryPagination, type DiscoveryRegisterOptions, type DiscoveryResource, type DiscoveryResponse, type DiscoverySource, type DiscoveryStats, type DiscoveryTier, type Dispute, type DisputeOutcome, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, ESCROW_TIMEOUT_MS, Erc8004Client, type Erc8004ClientOptions, Erc8004LookupError, type Erc8004Network, EscrowClient, type EscrowClientOptions, type EscrowPayment, type EscrowStateResponse, type EscrowStatus, FacilitatorClient, type FacilitatorClientOptions, type FeedbackEntry, type FeedbackParams, type FeedbackRequest, type FeedbackResponse, HEALTH_FILTERS, type HonoMiddlewareOptions, type IdentityByOwnerResponse, type IdentityMetadataResponse, type IdentityTotalSupplyResponse, MAX_SEARCH_LEN, type MetadataEntryParam, OPERATOR_ABI, OPERATOR_ABI_CREATE3, PAYMENT_INFO_TYPEHASH, type PaymentAcceptance, type PaymentMiddlewareOptions, type PaymentPayloadV2, type PaymentRequirementResolver, type PaymentRequirements, type PaymentRequirementsOptions, type PaymentRequirementsV2, type ProofOfPayment, type RefundRequest, type RefundStatus, type RegisterAgentRequest, type RegisterAgentResponse, type ReputationResponse, type ReputationSummary, type RequestRefundOptions, type ResourceInfoV2, type SettleRequest, type SettleRequestV2, type SettleResponse, type SettleResponseWithProof, TIER_FILTERS, TIER_TIMINGS, USDC_DOMAIN_NAME, type VerifiedPaymentState, type VerifyRequest, type VerifyRequestV2, type VerifyResponse, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentRequirements, buildSettleRequest, buildSettleRequestV2, buildVerifyRequest, buildVerifyRequestV2, canRefundEscrow, canReleaseEscrow, create402Response, createHonoMiddleware, createPaymentMiddleware, epochToDate, escrowTimeRemaining, extractPaymentFromHeaders, getCorsHeaders, getEscrowContractsByChainId, getEscrowSupportedChainIds, isAlive, isEscrowExpired, isEscrowSupportedOnChain, parsePaymentHeader };
2474
+ export { type AdvancedAuthorizationResult, AdvancedEscrowClient, type AdvancedEscrowClientOptions, type AdvancedEscrowContracts, type AdvancedEscrowTaskTier, type AdvancedPaymentInfo, type AdvancedTransactionResult, type AgentId, type AgentIdentity, type AgentRegistration, type AgentRegistrationFile, type AgentService, type AtomStats, BASE_MAINNET_CONTRACTS, BazaarClient, type BazaarClientOptions, type BazaarDiscoverOptions, type BazaarDiscoverResponse, type BazaarRegisterOptions, type BazaarResource, type CreateEscrowOptions, DEPOSIT_LIMIT_USDC, type DiscoveryAccepts, type DiscoveryCuration, type DiscoveryHealth, type DiscoveryHealthStatus, type DiscoveryListOptions, type DiscoveryPagination, type DiscoveryRegisterOptions, type DiscoveryResource, type DiscoveryResponse, type DiscoverySource, type DiscoveryStats, type DiscoveryTier, type Dispute, type DisputeOutcome, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, ESCROW_TIMEOUT_MS, Erc8004Client, type Erc8004ClientOptions, Erc8004LookupError, type Erc8004Network, EscrowClient, type EscrowClientOptions, type EscrowPayment, type EscrowStateResponse, type EscrowStatus, FacilitatorClient, type FacilitatorClientOptions, type FeedbackEntry, type FeedbackParams, type FeedbackRequest, type FeedbackResponse, HEALTH_FILTERS, type HonoMiddlewareOptions, type IdentityByOwnerResponse, type IdentityMetadataResponse, type IdentityTotalSupplyResponse, MAX_SEARCH_LEN, type MetadataEntryParam, OPERATOR_ABI, OPERATOR_ABI_CREATE3, PAYMENT_INFO_TYPEHASH, type PaymentAcceptance, type PaymentMiddlewareOptions, type PaymentPayloadV2, type PaymentRequirementResolver, type PaymentRequirements, type PaymentRequirementsOptions, type PaymentRequirementsV2, type ProofOfPayment, type RefundRequest, type RefundStatus, type RegisterAgentRequest, type RegisterAgentResponse, type RegisterJobResponse, type RegisterJobStatus, type ReputationResponse, type ReputationSummary, type RequestRefundOptions, type ResourceInfoV2, type SettleRequest, type SettleRequestV2, type SettleResponse, type SettleResponseWithProof, TIER_FILTERS, TIER_TIMINGS, USDC_DOMAIN_NAME, type VerifiedPaymentState, type VerifyRequest, type VerifyRequestV2, type VerifyResponse, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentRequirements, buildSettleRequest, buildSettleRequestV2, buildVerifyRequest, buildVerifyRequestV2, canRefundEscrow, canReleaseEscrow, create402Response, createHonoMiddleware, createPaymentMiddleware, epochToDate, escrowTimeRemaining, extractPaymentFromHeaders, getCorsHeaders, getEscrowContractsByChainId, getEscrowSupportedChainIds, isAlive, isEscrowExpired, isEscrowSupportedOnChain, isRegisterJobTerminal, parsePaymentHeader };
@@ -2573,6 +2573,9 @@ var Erc8004LookupError = class extends Error {
2573
2573
  return this.status === 503;
2574
2574
  }
2575
2575
  };
2576
+ function isRegisterJobTerminal(job) {
2577
+ return job.status === "done" || job.status === "failed";
2578
+ }
2576
2579
  var Erc8004Client = class {
2577
2580
  baseUrl;
2578
2581
  timeout;
@@ -2992,6 +2995,19 @@ var Erc8004Client = class {
2992
2995
  clearTimeout(timeoutId);
2993
2996
  if (!response.ok) {
2994
2997
  const errorText = await response.text();
2998
+ try {
2999
+ const parsed = JSON.parse(errorText);
3000
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
3001
+ return {
3002
+ ...parsed,
3003
+ // Never let a 4xx body claim success, whatever it says.
3004
+ success: false,
3005
+ error: parsed.error ?? `Facilitator error: ${response.status}`,
3006
+ network: parsed.network ?? request.network
3007
+ };
3008
+ }
3009
+ } catch {
3010
+ }
2995
3011
  return {
2996
3012
  success: false,
2997
3013
  error: `Facilitator error: ${response.status} - ${errorText}`,
@@ -3008,6 +3024,107 @@ var Erc8004Client = class {
3008
3024
  };
3009
3025
  }
3010
3026
  }
3027
+ /**
3028
+ * Start a registration without waiting for the chain to confirm it.
3029
+ *
3030
+ * Registration waits on a mint receipt, which on a congested chain outlives
3031
+ * client and proxy timeouts. A timed-out synchronous call is genuinely
3032
+ * ambiguous — the mint may well have landed — and retrying it is how five
3033
+ * duplicate agents once got minted. This returns immediately with a job id
3034
+ * instead; poll {@link getRegisterStatus} or use {@link waitForRegistration}.
3035
+ *
3036
+ * On Solana, `recipient` is a base58 address: the facilitator mints,
3037
+ * initializes the ATOM stats and transfers, paying every fee.
3038
+ */
3039
+ async registerAgentAsync(request) {
3040
+ const url = `${this.baseUrl}/register`;
3041
+ const controller = new AbortController();
3042
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
3043
+ try {
3044
+ const response = await fetch(url, {
3045
+ method: "POST",
3046
+ headers: {
3047
+ "Content-Type": "application/json",
3048
+ "Accept": "application/json",
3049
+ "Prefer": "respond-async"
3050
+ },
3051
+ body: JSON.stringify(request),
3052
+ signal: controller.signal
3053
+ });
3054
+ clearTimeout(timeoutId);
3055
+ if (!response.ok) {
3056
+ const errorText = await response.text();
3057
+ throw new Erc8004LookupError(
3058
+ `ERC-8004 API error: ${response.status} - ${errorText}`,
3059
+ response.status,
3060
+ errorText
3061
+ );
3062
+ }
3063
+ return await response.json();
3064
+ } catch (error) {
3065
+ clearTimeout(timeoutId);
3066
+ throw error;
3067
+ }
3068
+ }
3069
+ /**
3070
+ * Read the current state of an asynchronous registration.
3071
+ *
3072
+ * Throws {@link Erc8004LookupError} with `notFound` when the job is unknown or
3073
+ * has aged out — terminal jobs are kept for one hour.
3074
+ */
3075
+ async getRegisterStatus(jobId) {
3076
+ const url = `${this.baseUrl}/register/status/${encodeURIComponent(jobId)}`;
3077
+ const controller = new AbortController();
3078
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
3079
+ try {
3080
+ const response = await fetch(url, {
3081
+ method: "GET",
3082
+ headers: { "Accept": "application/json" },
3083
+ signal: controller.signal
3084
+ });
3085
+ clearTimeout(timeoutId);
3086
+ if (!response.ok) {
3087
+ const errorText = await response.text();
3088
+ throw new Erc8004LookupError(
3089
+ `ERC-8004 API error: ${response.status} - ${errorText}`,
3090
+ response.status,
3091
+ errorText
3092
+ );
3093
+ }
3094
+ return await response.json();
3095
+ } catch (error) {
3096
+ clearTimeout(timeoutId);
3097
+ throw error;
3098
+ }
3099
+ }
3100
+ /**
3101
+ * Poll an asynchronous registration until it finishes.
3102
+ *
3103
+ * Rejects on timeout rather than resolving with the last non-terminal status,
3104
+ * so "still pending" is never mistaken for "did not happen": the mint may
3105
+ * still land afterwards, and treating a timeout as failure is what leads to
3106
+ * registering the same agent twice. Keep the job id and poll again rather
3107
+ * than re-registering.
3108
+ */
3109
+ async waitForRegistration(jobId, options) {
3110
+ const pollIntervalMs = options?.pollIntervalMs ?? 2e3;
3111
+ const timeoutMs = options?.timeoutMs ?? 3e5;
3112
+ const deadline = Date.now() + timeoutMs;
3113
+ for (; ; ) {
3114
+ const job = await this.getRegisterStatus(jobId);
3115
+ if (isRegisterJobTerminal(job)) {
3116
+ return job;
3117
+ }
3118
+ if (Date.now() >= deadline) {
3119
+ throw new Error(
3120
+ `Registration job ${jobId} still '${job.status}' after ${Math.round(
3121
+ timeoutMs / 1e3
3122
+ )}s. It may still complete: poll getRegisterStatus('${jobId}') rather than registering again.`
3123
+ );
3124
+ }
3125
+ await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
3126
+ }
3127
+ }
3011
3128
  /**
3012
3129
  * Get registration endpoint metadata
3013
3130
  *
@@ -4065,6 +4182,7 @@ exports.getEscrowSupportedChainIds = getEscrowSupportedChainIds;
4065
4182
  exports.isAlive = isAlive;
4066
4183
  exports.isEscrowExpired = isEscrowExpired;
4067
4184
  exports.isEscrowSupportedOnChain = isEscrowSupportedOnChain;
4185
+ exports.isRegisterJobTerminal = isRegisterJobTerminal;
4068
4186
  exports.parsePaymentHeader = parsePaymentHeader;
4069
4187
  //# sourceMappingURL=index.js.map
4070
4188
  //# sourceMappingURL=index.js.map