uvd-x402-sdk 2.51.0 → 2.52.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.
- package/dist/backend/index.d.mts +61 -1
- package/dist/backend/index.d.ts +61 -1
- package/dist/backend/index.js +105 -0
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/index.mjs +105 -1
- package/dist/backend/index.mjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/backend/index.ts +150 -0
package/dist/backend/index.d.mts
CHANGED
|
@@ -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 };
|
package/dist/backend/index.d.ts
CHANGED
|
@@ -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 };
|
package/dist/backend/index.js
CHANGED
|
@@ -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;
|
|
@@ -3008,6 +3011,107 @@ var Erc8004Client = class {
|
|
|
3008
3011
|
};
|
|
3009
3012
|
}
|
|
3010
3013
|
}
|
|
3014
|
+
/**
|
|
3015
|
+
* Start a registration without waiting for the chain to confirm it.
|
|
3016
|
+
*
|
|
3017
|
+
* Registration waits on a mint receipt, which on a congested chain outlives
|
|
3018
|
+
* client and proxy timeouts. A timed-out synchronous call is genuinely
|
|
3019
|
+
* ambiguous — the mint may well have landed — and retrying it is how five
|
|
3020
|
+
* duplicate agents once got minted. This returns immediately with a job id
|
|
3021
|
+
* instead; poll {@link getRegisterStatus} or use {@link waitForRegistration}.
|
|
3022
|
+
*
|
|
3023
|
+
* On Solana, `recipient` is a base58 address: the facilitator mints,
|
|
3024
|
+
* initializes the ATOM stats and transfers, paying every fee.
|
|
3025
|
+
*/
|
|
3026
|
+
async registerAgentAsync(request) {
|
|
3027
|
+
const url = `${this.baseUrl}/register`;
|
|
3028
|
+
const controller = new AbortController();
|
|
3029
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
3030
|
+
try {
|
|
3031
|
+
const response = await fetch(url, {
|
|
3032
|
+
method: "POST",
|
|
3033
|
+
headers: {
|
|
3034
|
+
"Content-Type": "application/json",
|
|
3035
|
+
"Accept": "application/json",
|
|
3036
|
+
"Prefer": "respond-async"
|
|
3037
|
+
},
|
|
3038
|
+
body: JSON.stringify(request),
|
|
3039
|
+
signal: controller.signal
|
|
3040
|
+
});
|
|
3041
|
+
clearTimeout(timeoutId);
|
|
3042
|
+
if (!response.ok) {
|
|
3043
|
+
const errorText = await response.text();
|
|
3044
|
+
throw new Erc8004LookupError(
|
|
3045
|
+
`ERC-8004 API error: ${response.status} - ${errorText}`,
|
|
3046
|
+
response.status,
|
|
3047
|
+
errorText
|
|
3048
|
+
);
|
|
3049
|
+
}
|
|
3050
|
+
return await response.json();
|
|
3051
|
+
} catch (error) {
|
|
3052
|
+
clearTimeout(timeoutId);
|
|
3053
|
+
throw error;
|
|
3054
|
+
}
|
|
3055
|
+
}
|
|
3056
|
+
/**
|
|
3057
|
+
* Read the current state of an asynchronous registration.
|
|
3058
|
+
*
|
|
3059
|
+
* Throws {@link Erc8004LookupError} with `notFound` when the job is unknown or
|
|
3060
|
+
* has aged out — terminal jobs are kept for one hour.
|
|
3061
|
+
*/
|
|
3062
|
+
async getRegisterStatus(jobId) {
|
|
3063
|
+
const url = `${this.baseUrl}/register/status/${encodeURIComponent(jobId)}`;
|
|
3064
|
+
const controller = new AbortController();
|
|
3065
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
3066
|
+
try {
|
|
3067
|
+
const response = await fetch(url, {
|
|
3068
|
+
method: "GET",
|
|
3069
|
+
headers: { "Accept": "application/json" },
|
|
3070
|
+
signal: controller.signal
|
|
3071
|
+
});
|
|
3072
|
+
clearTimeout(timeoutId);
|
|
3073
|
+
if (!response.ok) {
|
|
3074
|
+
const errorText = await response.text();
|
|
3075
|
+
throw new Erc8004LookupError(
|
|
3076
|
+
`ERC-8004 API error: ${response.status} - ${errorText}`,
|
|
3077
|
+
response.status,
|
|
3078
|
+
errorText
|
|
3079
|
+
);
|
|
3080
|
+
}
|
|
3081
|
+
return await response.json();
|
|
3082
|
+
} catch (error) {
|
|
3083
|
+
clearTimeout(timeoutId);
|
|
3084
|
+
throw error;
|
|
3085
|
+
}
|
|
3086
|
+
}
|
|
3087
|
+
/**
|
|
3088
|
+
* Poll an asynchronous registration until it finishes.
|
|
3089
|
+
*
|
|
3090
|
+
* Rejects on timeout rather than resolving with the last non-terminal status,
|
|
3091
|
+
* so "still pending" is never mistaken for "did not happen": the mint may
|
|
3092
|
+
* still land afterwards, and treating a timeout as failure is what leads to
|
|
3093
|
+
* registering the same agent twice. Keep the job id and poll again rather
|
|
3094
|
+
* than re-registering.
|
|
3095
|
+
*/
|
|
3096
|
+
async waitForRegistration(jobId, options) {
|
|
3097
|
+
const pollIntervalMs = options?.pollIntervalMs ?? 2e3;
|
|
3098
|
+
const timeoutMs = options?.timeoutMs ?? 3e5;
|
|
3099
|
+
const deadline = Date.now() + timeoutMs;
|
|
3100
|
+
for (; ; ) {
|
|
3101
|
+
const job = await this.getRegisterStatus(jobId);
|
|
3102
|
+
if (isRegisterJobTerminal(job)) {
|
|
3103
|
+
return job;
|
|
3104
|
+
}
|
|
3105
|
+
if (Date.now() >= deadline) {
|
|
3106
|
+
throw new Error(
|
|
3107
|
+
`Registration job ${jobId} still '${job.status}' after ${Math.round(
|
|
3108
|
+
timeoutMs / 1e3
|
|
3109
|
+
)}s. It may still complete: poll getRegisterStatus('${jobId}') rather than registering again.`
|
|
3110
|
+
);
|
|
3111
|
+
}
|
|
3112
|
+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
3113
|
+
}
|
|
3114
|
+
}
|
|
3011
3115
|
/**
|
|
3012
3116
|
* Get registration endpoint metadata
|
|
3013
3117
|
*
|
|
@@ -4065,6 +4169,7 @@ exports.getEscrowSupportedChainIds = getEscrowSupportedChainIds;
|
|
|
4065
4169
|
exports.isAlive = isAlive;
|
|
4066
4170
|
exports.isEscrowExpired = isEscrowExpired;
|
|
4067
4171
|
exports.isEscrowSupportedOnChain = isEscrowSupportedOnChain;
|
|
4172
|
+
exports.isRegisterJobTerminal = isRegisterJobTerminal;
|
|
4068
4173
|
exports.parsePaymentHeader = parsePaymentHeader;
|
|
4069
4174
|
//# sourceMappingURL=index.js.map
|
|
4070
4175
|
//# sourceMappingURL=index.js.map
|