vapi-network 0.9.0 → 0.9.4
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/README.md +22 -13
- package/dist/cli.js +1772 -938
- package/dist/cli.js.map +3 -3
- package/dist/index.js +1808 -956
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -28988,365 +28988,6 @@ function date4(params) {
|
|
|
28988
28988
|
return _coercedDate(ZodDate, params);
|
|
28989
28989
|
}
|
|
28990
28990
|
|
|
28991
|
-
// ../core/src/marketplace-contracts.ts
|
|
28992
|
-
var MARKETPLACE_DISCOVERY_PROTOCOL = "vapi.marketplace.discovery/1";
|
|
28993
|
-
var MARKETPLACE_RANKING_VERSION = "marketplace-ranking-v1";
|
|
28994
|
-
var MARKETPLACE_KINDS = ["api", "service_offer", "open_request"];
|
|
28995
|
-
var MARKETPLACE_EXECUTION_METHODS = [
|
|
28996
|
-
"GET",
|
|
28997
|
-
"HEAD",
|
|
28998
|
-
"POST",
|
|
28999
|
-
"PUT",
|
|
29000
|
-
"PATCH",
|
|
29001
|
-
"DELETE"
|
|
29002
|
-
];
|
|
29003
|
-
var marketplaceExecutionMethodSchema = external_exports.enum(MARKETPLACE_EXECUTION_METHODS);
|
|
29004
|
-
var marketplaceKindSchema = external_exports.enum(MARKETPLACE_KINDS);
|
|
29005
|
-
var EXECUTION_MODES = ["direct", "gateway"];
|
|
29006
|
-
var executionModeSchema = external_exports.enum(EXECUTION_MODES);
|
|
29007
|
-
var PROVENANCES = ["indexed", "self_listed", "partner"];
|
|
29008
|
-
var provenanceSchema = external_exports.enum(PROVENANCES);
|
|
29009
|
-
var FIRST_PARTY_PROVENANCES = ["self_listed", "partner"];
|
|
29010
|
-
var firstPartyProvenanceSchema = external_exports.enum(FIRST_PARTY_PROVENANCES);
|
|
29011
|
-
var LISTING_GROUPS = ["vapi", "added", "partner", "external"];
|
|
29012
|
-
var listingGroupSchema = external_exports.enum(LISTING_GROUPS);
|
|
29013
|
-
var listingFeeSchema = external_exports.looseObject({
|
|
29014
|
-
bps: external_exports.number().int().min(0),
|
|
29015
|
-
label: external_exports.string()
|
|
29016
|
-
});
|
|
29017
|
-
var LISTING_VERIFICATIONS = ["none", "requested", "verified"];
|
|
29018
|
-
var listingVerificationSchema = external_exports.enum(LISTING_VERIFICATIONS);
|
|
29019
|
-
var listingVerificationFieldSchema = listingVerificationSchema.default("none").catch("none");
|
|
29020
|
-
var listingLivenessSchema = external_exports.looseObject({
|
|
29021
|
-
uptime7d: external_exports.number().min(0).max(1),
|
|
29022
|
-
latencyP50Ms: external_exports.number().nonnegative().nullable(),
|
|
29023
|
-
latencyP95Ms: external_exports.number().nonnegative().nullable(),
|
|
29024
|
-
checks7d: external_exports.number().int().nonnegative()
|
|
29025
|
-
});
|
|
29026
|
-
var listingConformanceSchema = external_exports.looseObject({
|
|
29027
|
-
declaredVersion: external_exports.union([external_exports.literal(1), external_exports.literal(2)]).nullable(),
|
|
29028
|
-
versionConformant: external_exports.boolean(),
|
|
29029
|
-
offerTransport: external_exports.enum(["body", "header", "both"]),
|
|
29030
|
-
issues: external_exports.array(external_exports.string())
|
|
29031
|
-
});
|
|
29032
|
-
var listingIdentitySchema = external_exports.looseObject({
|
|
29033
|
-
erc8004Id: external_exports.string().trim().min(1),
|
|
29034
|
-
reputation: external_exports.looseObject({
|
|
29035
|
-
score: external_exports.number().finite(),
|
|
29036
|
-
count: external_exports.number().int().nonnegative()
|
|
29037
|
-
}).optional().catch(void 0)
|
|
29038
|
-
});
|
|
29039
|
-
var listingDisclosureShape = {
|
|
29040
|
-
group: listingGroupSchema.optional(),
|
|
29041
|
-
fee: listingFeeSchema.optional(),
|
|
29042
|
-
verification: listingVerificationFieldSchema,
|
|
29043
|
-
liveness: listingLivenessSchema.optional().catch(void 0),
|
|
29044
|
-
conformance: listingConformanceSchema.optional().catch(void 0),
|
|
29045
|
-
identity: listingIdentitySchema.optional().catch(void 0)
|
|
29046
|
-
};
|
|
29047
|
-
var marketplaceBadgeCodeSchema = external_exports.enum([
|
|
29048
|
-
"live_x402",
|
|
29049
|
-
"partner",
|
|
29050
|
-
"payout_wallet_confirmed",
|
|
29051
|
-
"vapi_verified",
|
|
29052
|
-
"external_catalog",
|
|
29053
|
-
"approved_vendor"
|
|
29054
|
-
]);
|
|
29055
|
-
var marketplaceBadgeSchema = external_exports.looseObject({
|
|
29056
|
-
code: marketplaceBadgeCodeSchema,
|
|
29057
|
-
label: external_exports.string().trim().min(1).max(80)
|
|
29058
|
-
});
|
|
29059
|
-
var marketplacePublicFactSchema = external_exports.looseObject({
|
|
29060
|
-
label: external_exports.string().trim().min(1).max(80),
|
|
29061
|
-
value: external_exports.string().trim().min(1).max(160)
|
|
29062
|
-
});
|
|
29063
|
-
var marketplaceHrefSchema = external_exports.union([
|
|
29064
|
-
external_exports.string().trim().min(1).max(2048).regex(/^\/(?!\/)/),
|
|
29065
|
-
external_exports.url().max(2048).regex(/^https:\/\//)
|
|
29066
|
-
]);
|
|
29067
|
-
var marketplaceCardSchema = external_exports.looseObject({
|
|
29068
|
-
title: external_exports.string().trim().min(1).max(160),
|
|
29069
|
-
summary: external_exports.string().trim().min(1).max(1e3),
|
|
29070
|
-
byline: external_exports.string().trim().min(1).max(160).optional(),
|
|
29071
|
-
bylineHref: marketplaceHrefSchema.optional(),
|
|
29072
|
-
badges: external_exports.array(marketplaceBadgeSchema).max(8),
|
|
29073
|
-
facts: external_exports.array(marketplacePublicFactSchema).max(12)
|
|
29074
|
-
});
|
|
29075
|
-
var marketplaceHitBase = {
|
|
29076
|
-
ref: external_exports.string().trim().min(1).max(512),
|
|
29077
|
-
card: marketplaceCardSchema,
|
|
29078
|
-
...listingDisclosureShape
|
|
29079
|
-
};
|
|
29080
|
-
var invokeApiActionSchema = external_exports.looseObject({
|
|
29081
|
-
type: external_exports.literal("invoke_api"),
|
|
29082
|
-
href: marketplaceHrefSchema
|
|
29083
|
-
});
|
|
29084
|
-
var firstPartyApiMarketplaceHitSchema = external_exports.looseObject({
|
|
29085
|
-
...marketplaceHitBase,
|
|
29086
|
-
kind: external_exports.literal("api"),
|
|
29087
|
-
provenance: firstPartyProvenanceSchema,
|
|
29088
|
-
execution: external_exports.looseObject({
|
|
29089
|
-
mode: executionModeSchema
|
|
29090
|
-
}),
|
|
29091
|
-
action: invokeApiActionSchema
|
|
29092
|
-
});
|
|
29093
|
-
var mirroredApiMarketplaceHitSchema = external_exports.looseObject({
|
|
29094
|
-
...marketplaceHitBase,
|
|
29095
|
-
kind: external_exports.literal("api"),
|
|
29096
|
-
provenance: external_exports.literal("indexed"),
|
|
29097
|
-
execution: external_exports.looseObject({
|
|
29098
|
-
mode: external_exports.literal("direct"),
|
|
29099
|
-
url: external_exports.url().max(2048).regex(/^https:\/\/(?![^/?#]*@)/),
|
|
29100
|
-
method: marketplaceExecutionMethodSchema.nullable(),
|
|
29101
|
-
network: external_exports.string().trim().max(160).regex(/^eip155:[1-9]\d*$/)
|
|
29102
|
-
}),
|
|
29103
|
-
action: invokeApiActionSchema
|
|
29104
|
-
});
|
|
29105
|
-
var apiMarketplaceHitSchema = external_exports.discriminatedUnion("provenance", [
|
|
29106
|
-
firstPartyApiMarketplaceHitSchema,
|
|
29107
|
-
mirroredApiMarketplaceHitSchema
|
|
29108
|
-
]);
|
|
29109
|
-
var serviceOfferMarketplaceHitSchema = external_exports.looseObject({
|
|
29110
|
-
...marketplaceHitBase,
|
|
29111
|
-
kind: external_exports.literal("service_offer"),
|
|
29112
|
-
action: external_exports.looseObject({
|
|
29113
|
-
type: external_exports.literal("start_engagement"),
|
|
29114
|
-
href: marketplaceHrefSchema
|
|
29115
|
-
})
|
|
29116
|
-
});
|
|
29117
|
-
var openRequestMarketplaceHitSchema = external_exports.looseObject({
|
|
29118
|
-
...marketplaceHitBase,
|
|
29119
|
-
kind: external_exports.literal("open_request"),
|
|
29120
|
-
action: external_exports.looseObject({
|
|
29121
|
-
type: external_exports.literal("propose_to_request"),
|
|
29122
|
-
href: marketplaceHrefSchema
|
|
29123
|
-
})
|
|
29124
|
-
});
|
|
29125
|
-
var marketplaceHitSchema = external_exports.union([
|
|
29126
|
-
apiMarketplaceHitSchema,
|
|
29127
|
-
serviceOfferMarketplaceHitSchema,
|
|
29128
|
-
openRequestMarketplaceHitSchema
|
|
29129
|
-
]);
|
|
29130
|
-
var marketplaceDiscoveryInputSchema = external_exports.strictObject({
|
|
29131
|
-
q: external_exports.string().trim().max(200).optional(),
|
|
29132
|
-
kinds: external_exports.array(marketplaceKindSchema).min(1).max(MARKETPLACE_KINDS.length).optional(),
|
|
29133
|
-
network: external_exports.string().trim().min(1).max(160).optional(),
|
|
29134
|
-
cursor: external_exports.string().trim().min(1).max(4096).optional(),
|
|
29135
|
-
limit: external_exports.number().int().min(1).max(50).optional(),
|
|
29136
|
-
includeUnverified: external_exports.boolean().optional()
|
|
29137
|
-
}).superRefine((input2, context) => {
|
|
29138
|
-
if (input2.kinds && new Set(input2.kinds).size !== input2.kinds.length) {
|
|
29139
|
-
context.addIssue({
|
|
29140
|
-
code: "custom",
|
|
29141
|
-
path: ["kinds"],
|
|
29142
|
-
message: "Marketplace kinds must be unique"
|
|
29143
|
-
});
|
|
29144
|
-
}
|
|
29145
|
-
});
|
|
29146
|
-
function isMirroredHit(hit) {
|
|
29147
|
-
return hit.kind === "api" && hit.provenance === "indexed";
|
|
29148
|
-
}
|
|
29149
|
-
var marketplaceDiscoveryPageSchema = external_exports.looseObject({
|
|
29150
|
-
protocol: external_exports.literal(MARKETPLACE_DISCOVERY_PROTOCOL),
|
|
29151
|
-
items: external_exports.array(marketplaceHitSchema),
|
|
29152
|
-
nextCursor: external_exports.string().min(1).max(4096).nullable(),
|
|
29153
|
-
unavailableKinds: external_exports.array(marketplaceKindSchema).max(MARKETPLACE_KINDS.length),
|
|
29154
|
-
rankingVersion: external_exports.literal(MARKETPLACE_RANKING_VERSION)
|
|
29155
|
-
});
|
|
29156
|
-
|
|
29157
|
-
// ../core/src/call-contracts-wire.ts
|
|
29158
|
-
var CALLABLE_CATEGORIES = ["ai", "data", "crypto", "compute", "search"];
|
|
29159
|
-
var callableCategorySchema = external_exports.enum(CALLABLE_CATEGORIES);
|
|
29160
|
-
var DISCOVERY_CATEGORIES = [...CALLABLE_CATEGORIES, "other"];
|
|
29161
|
-
var discoveryCategorySchema = external_exports.enum(DISCOVERY_CATEGORIES);
|
|
29162
|
-
var CALLABLE_CATEGORY_SET = new Set(CALLABLE_CATEGORIES);
|
|
29163
|
-
var serviceTierSchema = external_exports.enum(["listed", "verified", "partner"]);
|
|
29164
|
-
var discoveryEndpointSchema = external_exports.looseObject({
|
|
29165
|
-
name: external_exports.string(),
|
|
29166
|
-
method: external_exports.string(),
|
|
29167
|
-
url: external_exports.url(),
|
|
29168
|
-
price: external_exports.string(),
|
|
29169
|
-
description: external_exports.string(),
|
|
29170
|
-
operationId: external_exports.string().trim().min(1).optional(),
|
|
29171
|
-
requestContentType: external_exports.string().trim().min(1).optional(),
|
|
29172
|
-
requestSchema: external_exports.json().optional(),
|
|
29173
|
-
responseContentType: external_exports.string().trim().min(1).optional(),
|
|
29174
|
-
pathTemplate: external_exports.string().trim().min(1).optional(),
|
|
29175
|
-
pathParameters: external_exports.array(external_exports.string().trim().min(1)).optional(),
|
|
29176
|
-
payment: external_exports.looseObject({
|
|
29177
|
-
scheme: external_exports.literal("exact"),
|
|
29178
|
-
network: external_exports.string().regex(/^eip155:\d+$/),
|
|
29179
|
-
asset: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
29180
|
-
payTo: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
29181
|
-
checkedAt: external_exports.iso.datetime()
|
|
29182
|
-
}).optional()
|
|
29183
|
-
});
|
|
29184
|
-
var serviceSummarySchema = external_exports.looseObject({
|
|
29185
|
-
id: external_exports.string(),
|
|
29186
|
-
name: external_exports.string(),
|
|
29187
|
-
description: external_exports.string(),
|
|
29188
|
-
category: discoveryCategorySchema,
|
|
29189
|
-
tier: serviceTierSchema,
|
|
29190
|
-
...listingDisclosureShape,
|
|
29191
|
-
verified: external_exports.boolean(),
|
|
29192
|
-
wrapped: external_exports.boolean(),
|
|
29193
|
-
price: external_exports.string(),
|
|
29194
|
-
networks: external_exports.array(external_exports.string()),
|
|
29195
|
-
endpoints: external_exports.array(discoveryEndpointSchema)
|
|
29196
|
-
});
|
|
29197
|
-
var searchServicesResponseSchema = external_exports.looseObject({
|
|
29198
|
-
services: external_exports.array(serviceSummarySchema)
|
|
29199
|
-
});
|
|
29200
|
-
var discoveryResponseSchema = searchServicesResponseSchema;
|
|
29201
|
-
|
|
29202
|
-
// ../core/src/call-contracts.ts
|
|
29203
|
-
var DiscoveryCatalogError = class extends Error {
|
|
29204
|
-
name = "DiscoveryCatalogError";
|
|
29205
|
-
code;
|
|
29206
|
-
serviceId;
|
|
29207
|
-
constructor(code, message, serviceId) {
|
|
29208
|
-
super(message);
|
|
29209
|
-
this.code = code;
|
|
29210
|
-
this.serviceId = serviceId;
|
|
29211
|
-
}
|
|
29212
|
-
};
|
|
29213
|
-
function parseDiscovery(raw) {
|
|
29214
|
-
const parsed = discoveryResponseSchema.safeParse(raw);
|
|
29215
|
-
if (!parsed.success) {
|
|
29216
|
-
const malformedUrl = parsed.error.issues.find(
|
|
29217
|
-
(issue2) => issue2.path.at(-1) === "url" && issue2.path.includes("endpoints")
|
|
29218
|
-
);
|
|
29219
|
-
if (malformedUrl) {
|
|
29220
|
-
const serviceIndex = pathIndexAfter(malformedUrl.path, "services");
|
|
29221
|
-
const serviceId = rawServiceId(raw, serviceIndex);
|
|
29222
|
-
throw new DiscoveryCatalogError(
|
|
29223
|
-
"malformed_url",
|
|
29224
|
-
`Service ${JSON.stringify(serviceId ?? "unknown")} has a malformed endpoint URL.`,
|
|
29225
|
-
serviceId
|
|
29226
|
-
);
|
|
29227
|
-
}
|
|
29228
|
-
throw new DiscoveryCatalogError("invalid_discovery", "Discovery response is malformed.");
|
|
29229
|
-
}
|
|
29230
|
-
for (const service of parsed.data.services) {
|
|
29231
|
-
buildTargets(service);
|
|
29232
|
-
}
|
|
29233
|
-
const resolveListing = (serviceId, endpointName) => {
|
|
29234
|
-
const service = parsed.data.services.find((candidate) => candidate.id === serviceId);
|
|
29235
|
-
if (!service) {
|
|
29236
|
-
throw new DiscoveryCatalogError(
|
|
29237
|
-
"service_not_found",
|
|
29238
|
-
`No payable endpoint found for service ${JSON.stringify(serviceId)}.`,
|
|
29239
|
-
serviceId
|
|
29240
|
-
);
|
|
29241
|
-
}
|
|
29242
|
-
return { service, endpoint: resolveTarget(service, endpointName) };
|
|
29243
|
-
};
|
|
29244
|
-
return {
|
|
29245
|
-
services: parsed.data.services,
|
|
29246
|
-
resolve: (serviceId, endpointName) => resolveListing(serviceId, endpointName).endpoint,
|
|
29247
|
-
resolveListing
|
|
29248
|
-
};
|
|
29249
|
-
}
|
|
29250
|
-
function resolveTarget(service, endpointName) {
|
|
29251
|
-
const { targets, targetsByName } = buildTargets(service);
|
|
29252
|
-
if (endpointName !== void 0) {
|
|
29253
|
-
const selected = targetsByName.get(endpointName.trim());
|
|
29254
|
-
if (!selected) {
|
|
29255
|
-
throw new DiscoveryCatalogError(
|
|
29256
|
-
"endpoint_not_found",
|
|
29257
|
-
`Service ${JSON.stringify(service.id)} has no endpoint ${JSON.stringify(endpointName)}. Available endpoints: ${[...targetsByName.keys()].join(", ")}.`,
|
|
29258
|
-
service.id
|
|
29259
|
-
);
|
|
29260
|
-
}
|
|
29261
|
-
return { ...selected };
|
|
29262
|
-
}
|
|
29263
|
-
if (targets.size !== 1) {
|
|
29264
|
-
throw new DiscoveryCatalogError(
|
|
29265
|
-
"ambiguous_default",
|
|
29266
|
-
`Service ${JSON.stringify(service.id)} has ${targets.size} distinct payable endpoints. Choose one with endpoint: ${[...targetsByName.keys()].join(", ")}.`,
|
|
29267
|
-
service.id
|
|
29268
|
-
);
|
|
29269
|
-
}
|
|
29270
|
-
return targets.values().next().value;
|
|
29271
|
-
}
|
|
29272
|
-
function buildTargets(service) {
|
|
29273
|
-
if (service.endpoints.length === 0) {
|
|
29274
|
-
throw new DiscoveryCatalogError(
|
|
29275
|
-
"no_endpoint",
|
|
29276
|
-
`Service ${JSON.stringify(service.id)} has no payable endpoint.`,
|
|
29277
|
-
service.id
|
|
29278
|
-
);
|
|
29279
|
-
}
|
|
29280
|
-
const namedEndpoints = [...service.endpoints].sort(
|
|
29281
|
-
(left, right) => compareNames(left.name.trim(), right.name.trim())
|
|
29282
|
-
);
|
|
29283
|
-
const names = /* @__PURE__ */ new Set();
|
|
29284
|
-
const targets = /* @__PURE__ */ new Map();
|
|
29285
|
-
const targetsByName = /* @__PURE__ */ new Map();
|
|
29286
|
-
for (const endpoint of namedEndpoints) {
|
|
29287
|
-
const name = endpoint.name.trim();
|
|
29288
|
-
if (!name) {
|
|
29289
|
-
throw new DiscoveryCatalogError(
|
|
29290
|
-
"invalid_endpoint_name",
|
|
29291
|
-
`Service ${JSON.stringify(service.id)} has a blank endpoint name.`,
|
|
29292
|
-
service.id
|
|
29293
|
-
);
|
|
29294
|
-
}
|
|
29295
|
-
if (names.has(name)) {
|
|
29296
|
-
throw new DiscoveryCatalogError(
|
|
29297
|
-
"duplicate_endpoint_name",
|
|
29298
|
-
`Service ${JSON.stringify(service.id)} has duplicate endpoint name ${JSON.stringify(name)}.`,
|
|
29299
|
-
service.id
|
|
29300
|
-
);
|
|
29301
|
-
}
|
|
29302
|
-
names.add(name);
|
|
29303
|
-
const method = endpoint.method.trim().toUpperCase();
|
|
29304
|
-
if (!method) {
|
|
29305
|
-
throw new DiscoveryCatalogError(
|
|
29306
|
-
"blank_method",
|
|
29307
|
-
`Service ${JSON.stringify(service.id)} has a blank endpoint method.`,
|
|
29308
|
-
service.id
|
|
29309
|
-
);
|
|
29310
|
-
}
|
|
29311
|
-
const url2 = new URL(endpoint.url);
|
|
29312
|
-
if (url2.protocol !== "http:" && url2.protocol !== "https:") {
|
|
29313
|
-
throw new DiscoveryCatalogError(
|
|
29314
|
-
"malformed_url",
|
|
29315
|
-
`Service ${JSON.stringify(service.id)} has a non-HTTP endpoint URL.`,
|
|
29316
|
-
service.id
|
|
29317
|
-
);
|
|
29318
|
-
}
|
|
29319
|
-
const transportKey = `${method}\0${endpoint.url}`;
|
|
29320
|
-
const normalized = { ...endpoint, name, method };
|
|
29321
|
-
targetsByName.set(name, normalized);
|
|
29322
|
-
if (!targets.has(transportKey)) targets.set(transportKey, normalized);
|
|
29323
|
-
}
|
|
29324
|
-
return { targets, targetsByName };
|
|
29325
|
-
}
|
|
29326
|
-
function compareNames(left, right) {
|
|
29327
|
-
return left < right ? -1 : left > right ? 1 : 0;
|
|
29328
|
-
}
|
|
29329
|
-
function pathIndexAfter(path, key2) {
|
|
29330
|
-
const keyIndex = path.indexOf(key2);
|
|
29331
|
-
const candidate = path[keyIndex + 1];
|
|
29332
|
-
return typeof candidate === "number" ? candidate : void 0;
|
|
29333
|
-
}
|
|
29334
|
-
function rawServiceId(raw, serviceIndex) {
|
|
29335
|
-
if (serviceIndex === void 0 || typeof raw !== "object" || raw === null) {
|
|
29336
|
-
return void 0;
|
|
29337
|
-
}
|
|
29338
|
-
const services = Reflect.get(raw, "services");
|
|
29339
|
-
if (!Array.isArray(services)) {
|
|
29340
|
-
return void 0;
|
|
29341
|
-
}
|
|
29342
|
-
const service = services[serviceIndex];
|
|
29343
|
-
if (typeof service !== "object" || service === null) {
|
|
29344
|
-
return void 0;
|
|
29345
|
-
}
|
|
29346
|
-
const id2 = Reflect.get(service, "id");
|
|
29347
|
-
return typeof id2 === "string" ? id2 : void 0;
|
|
29348
|
-
}
|
|
29349
|
-
|
|
29350
28991
|
// ../../node_modules/.pnpm/viem@2.56.1_typescript@6.0.3_zod@4.5.4/node_modules/viem/_esm/index.js
|
|
29351
28992
|
init_exports();
|
|
29352
28993
|
|
|
@@ -39623,6 +39264,7 @@ var ARC_MAINNET_CAIP2 = "eip155:5042";
|
|
|
39623
39264
|
var ARC_TESTNET_CAIP2 = "eip155:5042002";
|
|
39624
39265
|
var SOLANA_MAINNET_CAIP2 = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d";
|
|
39625
39266
|
var X402_SOLANA_MAINNET_CAIP2 = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
39267
|
+
var SOLANA_DEVNET_CAIP2 = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
39626
39268
|
var SOLANA_MAINNET_USDC = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
39627
39269
|
function canonicalIdentity(usdc, eip712Domain) {
|
|
39628
39270
|
return Object.freeze({
|
|
@@ -39666,375 +39308,194 @@ var BROWSER_ENABLED_X402_NETWORK_CONFIG = Object.freeze({
|
|
|
39666
39308
|
[ARC_TESTNET_CAIP2]: browserNetwork(arcTestnetUsdc)
|
|
39667
39309
|
});
|
|
39668
39310
|
|
|
39669
|
-
// ../core/src/
|
|
39670
|
-
|
|
39671
|
-
|
|
39672
|
-
|
|
39673
|
-
|
|
39674
|
-
|
|
39675
|
-
|
|
39676
|
-
|
|
39677
|
-
|
|
39311
|
+
// ../core/src/marketplace-contracts.ts
|
|
39312
|
+
var MARKETPLACE_DISCOVERY_PROTOCOL = "vapi.marketplace.discovery/1";
|
|
39313
|
+
var MARKETPLACE_RANKING_VERSION = "marketplace-ranking-v1";
|
|
39314
|
+
var MARKETPLACE_KINDS = ["api", "service_offer", "open_request"];
|
|
39315
|
+
var MARKETPLACE_EXECUTION_METHODS = [
|
|
39316
|
+
"GET",
|
|
39317
|
+
"HEAD",
|
|
39318
|
+
"POST",
|
|
39319
|
+
"PUT",
|
|
39320
|
+
"PATCH",
|
|
39321
|
+
"DELETE"
|
|
39322
|
+
];
|
|
39323
|
+
var marketplaceExecutionMethodSchema = external_exports.enum(MARKETPLACE_EXECUTION_METHODS);
|
|
39324
|
+
var marketplaceKindSchema = external_exports.enum(MARKETPLACE_KINDS);
|
|
39325
|
+
var EXECUTION_MODES = ["direct", "gateway"];
|
|
39326
|
+
var executionModeSchema = external_exports.enum(EXECUTION_MODES);
|
|
39327
|
+
var PROVENANCES = ["indexed", "self_listed", "partner"];
|
|
39328
|
+
var provenanceSchema = external_exports.enum(PROVENANCES);
|
|
39329
|
+
var FIRST_PARTY_PROVENANCES = ["self_listed", "partner"];
|
|
39330
|
+
var firstPartyProvenanceSchema = external_exports.enum(FIRST_PARTY_PROVENANCES);
|
|
39331
|
+
var LISTING_GROUPS = ["vapi", "added", "partner", "external"];
|
|
39332
|
+
var listingGroupSchema = external_exports.enum(LISTING_GROUPS);
|
|
39333
|
+
var listingFeeSchema = external_exports.looseObject({
|
|
39334
|
+
bps: external_exports.number().int().min(0),
|
|
39335
|
+
label: external_exports.string()
|
|
39336
|
+
});
|
|
39337
|
+
var LISTING_VERIFICATIONS = ["none", "requested", "verified"];
|
|
39338
|
+
var listingVerificationSchema = external_exports.enum(LISTING_VERIFICATIONS);
|
|
39339
|
+
var listingVerificationFieldSchema = listingVerificationSchema.default("none").catch("none");
|
|
39340
|
+
var listingLivenessSchema = external_exports.looseObject({
|
|
39341
|
+
uptime7d: external_exports.number().min(0).max(1),
|
|
39342
|
+
latencyP50Ms: external_exports.number().nonnegative().nullable(),
|
|
39343
|
+
latencyP95Ms: external_exports.number().nonnegative().nullable(),
|
|
39344
|
+
checks7d: external_exports.number().int().nonnegative()
|
|
39345
|
+
});
|
|
39346
|
+
var listingConformanceSchema = external_exports.looseObject({
|
|
39347
|
+
declaredVersion: external_exports.union([external_exports.literal(1), external_exports.literal(2)]).nullable(),
|
|
39348
|
+
versionConformant: external_exports.boolean(),
|
|
39349
|
+
offerTransport: external_exports.enum(["body", "header", "both"]),
|
|
39350
|
+
issues: external_exports.array(external_exports.string())
|
|
39351
|
+
});
|
|
39352
|
+
var listingIdentitySchema = external_exports.looseObject({
|
|
39353
|
+
erc8004Id: external_exports.string().trim().min(1),
|
|
39354
|
+
reputation: external_exports.looseObject({
|
|
39355
|
+
score: external_exports.number().finite(),
|
|
39356
|
+
count: external_exports.number().int().nonnegative()
|
|
39357
|
+
}).optional().catch(void 0)
|
|
39358
|
+
});
|
|
39359
|
+
var listingDisclosureShape = {
|
|
39360
|
+
// Presentation metadata must not make an otherwise executable row vanish
|
|
39361
|
+
// when the registry adds a new group or changes the fee display shape.
|
|
39362
|
+
group: listingGroupSchema.optional().catch(void 0),
|
|
39363
|
+
fee: listingFeeSchema.optional().catch(void 0),
|
|
39364
|
+
verification: listingVerificationFieldSchema,
|
|
39365
|
+
liveness: listingLivenessSchema.optional().catch(void 0),
|
|
39366
|
+
conformance: listingConformanceSchema.optional().catch(void 0),
|
|
39367
|
+
identity: listingIdentitySchema.optional().catch(void 0)
|
|
39678
39368
|
};
|
|
39679
|
-
|
|
39680
|
-
|
|
39681
|
-
|
|
39682
|
-
|
|
39683
|
-
|
|
39684
|
-
|
|
39685
|
-
|
|
39686
|
-
|
|
39687
|
-
|
|
39688
|
-
|
|
39689
|
-
|
|
39690
|
-
|
|
39691
|
-
|
|
39692
|
-
|
|
39693
|
-
|
|
39694
|
-
|
|
39695
|
-
|
|
39696
|
-
|
|
39697
|
-
|
|
39698
|
-
|
|
39699
|
-
|
|
39700
|
-
|
|
39701
|
-
|
|
39702
|
-
|
|
39703
|
-
|
|
39704
|
-
|
|
39705
|
-
|
|
39706
|
-
|
|
39707
|
-
|
|
39708
|
-
|
|
39709
|
-
|
|
39710
|
-
|
|
39711
|
-
|
|
39712
|
-
|
|
39713
|
-
|
|
39714
|
-
|
|
39715
|
-
|
|
39716
|
-
|
|
39717
|
-
|
|
39718
|
-
|
|
39719
|
-
lookup: lookupFn,
|
|
39720
|
-
timeoutMs: 5e3
|
|
39721
|
-
});
|
|
39722
|
-
const normalized = new Request(input2, init);
|
|
39723
|
-
const bytes = normalized.body ? Buffer.from(await normalized.arrayBuffer()) : null;
|
|
39724
|
-
return await new Promise((resolve2, reject) => {
|
|
39725
|
-
const requestOptions2 = {
|
|
39726
|
-
method: normalized.method,
|
|
39727
|
-
headers: Object.fromEntries(normalized.headers),
|
|
39728
|
-
signal: normalized.signal,
|
|
39729
|
-
...options.allowPrivateNetwork ? {} : { lookup: pinnedLookup(lookupFn) }
|
|
39730
|
-
};
|
|
39731
|
-
const onResponse = (incoming) => {
|
|
39732
|
-
try {
|
|
39733
|
-
const headers = new Headers();
|
|
39734
|
-
for (const [name, value] of Object.entries(incoming.headers)) {
|
|
39735
|
-
if (Array.isArray(value)) {
|
|
39736
|
-
for (const item of value) headers.append(name, item);
|
|
39737
|
-
} else if (value !== void 0) {
|
|
39738
|
-
headers.set(name, value);
|
|
39739
|
-
}
|
|
39740
|
-
}
|
|
39741
|
-
const status = incoming.statusCode ?? 500;
|
|
39742
|
-
const bodyForbidden = normalized.method === "HEAD" || [204, 205, 304].includes(status);
|
|
39743
|
-
if (bodyForbidden) incoming.resume();
|
|
39744
|
-
const response = new Response(
|
|
39745
|
-
bodyForbidden ? null : Readable.toWeb(incoming),
|
|
39746
|
-
{ status, statusText: incoming.statusMessage, headers }
|
|
39747
|
-
);
|
|
39748
|
-
Object.defineProperty(response, "url", { value: url2.toString() });
|
|
39749
|
-
resolve2(response);
|
|
39750
|
-
} catch (error61) {
|
|
39751
|
-
incoming.destroy();
|
|
39752
|
-
reject(error61);
|
|
39753
|
-
}
|
|
39754
|
-
};
|
|
39755
|
-
const request = url2.protocol === "https:" ? httpsRequest(url2, requestOptions2, onResponse) : httpRequest(url2, requestOptions2, onResponse);
|
|
39756
|
-
request.on("error", reject);
|
|
39757
|
-
if (bytes) request.write(bytes);
|
|
39758
|
-
request.end();
|
|
39759
|
-
});
|
|
39760
|
-
});
|
|
39761
|
-
}
|
|
39762
|
-
function pinnedLookup(lookup) {
|
|
39763
|
-
return (hostname3, dnsOptions, callback) => {
|
|
39764
|
-
void lookup(normalizeHostname(hostname3)).then((addresses) => {
|
|
39765
|
-
if (addresses.length === 0 || addresses.some(isNonPublicAddress)) {
|
|
39766
|
-
callback(guardError(new URL(`https://${hostname3}`)), "");
|
|
39767
|
-
return;
|
|
39768
|
-
}
|
|
39769
|
-
const address4 = addresses[0];
|
|
39770
|
-
const family = isIP(address4);
|
|
39771
|
-
callback(
|
|
39772
|
-
null,
|
|
39773
|
-
dnsOptions.all ? [{ address: address4, family }] : address4,
|
|
39774
|
-
dnsOptions.all ? void 0 : family
|
|
39775
|
-
);
|
|
39776
|
-
}).catch(
|
|
39777
|
-
(error61) => callback(error61 instanceof Error ? error61 : new Error("DNS lookup failed."), "")
|
|
39778
|
-
);
|
|
39779
|
-
};
|
|
39780
|
-
}
|
|
39781
|
-
async function withTimeout2(operation, timeoutMs) {
|
|
39782
|
-
let timeout;
|
|
39783
|
-
try {
|
|
39784
|
-
return await Promise.race([
|
|
39785
|
-
operation,
|
|
39786
|
-
new Promise((_resolve, reject) => {
|
|
39787
|
-
timeout = setTimeout(() => reject(new Error("DNS lookup timed out.")), timeoutMs);
|
|
39788
|
-
})
|
|
39789
|
-
]);
|
|
39790
|
-
} finally {
|
|
39791
|
-
if (timeout) clearTimeout(timeout);
|
|
39792
|
-
}
|
|
39793
|
-
}
|
|
39794
|
-
function normalizeHostname(hostname3) {
|
|
39795
|
-
const unbracketed = hostname3.startsWith("[") && hostname3.endsWith("]") ? hostname3.slice(1, -1) : hostname3;
|
|
39796
|
-
return unbracketed.endsWith(".") ? unbracketed.slice(0, -1) : unbracketed;
|
|
39797
|
-
}
|
|
39798
|
-
function isNonPublicAddress(address4) {
|
|
39799
|
-
const normalized = normalizeHostname(address4);
|
|
39800
|
-
const version5 = isIP(normalized);
|
|
39801
|
-
if (version5 === 4) {
|
|
39802
|
-
return isNonPublicIpv4(parseIpv4(normalized));
|
|
39803
|
-
}
|
|
39804
|
-
if (version5 === 6) {
|
|
39805
|
-
return isNonPublicIpv6(parseIpv6(normalized));
|
|
39806
|
-
}
|
|
39807
|
-
return true;
|
|
39808
|
-
}
|
|
39809
|
-
function parseIpv4(address4) {
|
|
39810
|
-
const octets = address4.split(".").map(Number);
|
|
39811
|
-
return [octets[0], octets[1], octets[2], octets[3]];
|
|
39812
|
-
}
|
|
39813
|
-
function isNonPublicIpv4([first, second, third]) {
|
|
39814
|
-
return first === 0 || first === 10 || first === 100 && second >= 64 && second <= 127 || first === 127 || first === 169 && second === 254 || first === 172 && second >= 16 && second <= 31 || first === 192 && second === 0 && (third === 0 || third === 2) || first === 192 && second === 168 || first === 198 && second >= 18 && second <= 19 || first === 198 && second === 51 && third === 100 || first === 203 && second === 0 && third === 113 || first >= 224;
|
|
39815
|
-
}
|
|
39816
|
-
function parseIpv6(address4) {
|
|
39817
|
-
let normalized = address4.toLowerCase();
|
|
39818
|
-
const lastColon = normalized.lastIndexOf(":");
|
|
39819
|
-
const dottedTail = normalized.slice(lastColon + 1);
|
|
39820
|
-
if (dottedTail.includes(".")) {
|
|
39821
|
-
const [first, second, third, fourth] = parseIpv4(dottedTail);
|
|
39822
|
-
normalized = `${normalized.slice(0, lastColon + 1)}${(first << 8 | second).toString(16)}:${(third << 8 | fourth).toString(16)}`;
|
|
39823
|
-
}
|
|
39824
|
-
const halves = normalized.split("::");
|
|
39825
|
-
const left = halves[0] ? halves[0].split(":").map(parseHex) : [];
|
|
39826
|
-
const right = halves[1] ? halves[1].split(":").map(parseHex) : [];
|
|
39827
|
-
const omittedCount = 8 - left.length - right.length;
|
|
39828
|
-
return halves.length === 2 ? [...left, ...Array.from({ length: omittedCount }, () => 0), ...right] : left;
|
|
39829
|
-
}
|
|
39830
|
-
function parseHex(value) {
|
|
39831
|
-
return Number.parseInt(value, 16);
|
|
39832
|
-
}
|
|
39833
|
-
function isNonPublicIpv6(hextets) {
|
|
39834
|
-
if (hextets.slice(0, 5).every((hextet) => hextet === 0) && hextets[5] === 65535) {
|
|
39835
|
-
const embeddedIpv4 = [
|
|
39836
|
-
hextets[6] >> 8,
|
|
39837
|
-
hextets[6] & 255,
|
|
39838
|
-
hextets[7] >> 8,
|
|
39839
|
-
hextets[7] & 255
|
|
39840
|
-
];
|
|
39841
|
-
return isNonPublicIpv4(embeddedIpv4);
|
|
39842
|
-
}
|
|
39843
|
-
if (hextets.slice(0, 6).every((hextet) => hextet === 0)) {
|
|
39844
|
-
const compatibleIpv4 = [
|
|
39845
|
-
hextets[6] >> 8,
|
|
39846
|
-
hextets[6] & 255,
|
|
39847
|
-
hextets[7] >> 8,
|
|
39848
|
-
hextets[7] & 255
|
|
39849
|
-
];
|
|
39850
|
-
if (isNonPublicIpv4(compatibleIpv4)) return true;
|
|
39851
|
-
}
|
|
39852
|
-
const isUnspecified = hextets.every((hextet) => hextet === 0);
|
|
39853
|
-
const isLoopback = hextets.slice(0, 7).every((hextet) => hextet === 0) && hextets[7] === 1;
|
|
39854
|
-
const first = hextets[0];
|
|
39855
|
-
const isUniqueLocal = first >= 64512 && first <= 65023;
|
|
39856
|
-
const isLinkLocal = first >= 65152 && first <= 65215;
|
|
39857
|
-
const isSiteLocal = first >= 65216 && first <= 65279;
|
|
39858
|
-
const isMulticast = first >= 65280;
|
|
39859
|
-
const isDocumentation = first === 8193 && hextets[1] === 3512;
|
|
39860
|
-
return isUnspecified || isLoopback || isUniqueLocal || isLinkLocal || isSiteLocal || isMulticast || isDocumentation;
|
|
39861
|
-
}
|
|
39862
|
-
function guardError(url2) {
|
|
39863
|
-
return new Error(
|
|
39864
|
-
`URL hostname ${JSON.stringify(url2.hostname)} is not allowed; private or internal destinations require allowPrivateNetwork true in the vAPI config.`
|
|
39865
|
-
);
|
|
39866
|
-
}
|
|
39867
|
-
|
|
39868
|
-
// ../core/src/networks.ts
|
|
39869
|
-
var USDC_DECIMALS = 6;
|
|
39870
|
-
var DEFAULT_ARC_GAS_HEADROOM_ATOMIC = 50000n;
|
|
39871
|
-
var NETWORKS = {
|
|
39872
|
-
[BASE_MAINNET_CAIP2]: {
|
|
39873
|
-
family: "evm",
|
|
39874
|
-
chainId: 8453,
|
|
39875
|
-
name: "Base mainnet",
|
|
39876
|
-
usdc: CANONICAL_X402_USDC_NETWORKS[BASE_MAINNET_CAIP2].usdc,
|
|
39877
|
-
gasToken: "ETH",
|
|
39878
|
-
rpcEnv: "BASE_RPC_URL",
|
|
39879
|
-
publicRpcUrl: "https://mainnet.base.org",
|
|
39880
|
-
explorerUrl: "https://basescan.org"
|
|
39881
|
-
},
|
|
39882
|
-
[ARC_MAINNET_CAIP2]: {
|
|
39883
|
-
family: "evm",
|
|
39884
|
-
chainId: 5042,
|
|
39885
|
-
name: "Arc mainnet",
|
|
39886
|
-
usdc: CANONICAL_X402_USDC_NETWORKS[ARC_MAINNET_CAIP2].usdc,
|
|
39887
|
-
gasToken: "USDC",
|
|
39888
|
-
rpcEnv: "ARC_RPC_URL",
|
|
39889
|
-
publicRpcUrl: "https://rpc.mainnet.arc.io",
|
|
39890
|
-
explorerUrl: "https://explorer.arc.io"
|
|
39891
|
-
},
|
|
39892
|
-
[ARC_TESTNET_CAIP2]: {
|
|
39893
|
-
family: "evm",
|
|
39894
|
-
chainId: 5042002,
|
|
39895
|
-
name: "Arc testnet",
|
|
39896
|
-
usdc: CANONICAL_X402_USDC_NETWORKS[ARC_TESTNET_CAIP2].usdc,
|
|
39897
|
-
gasToken: "USDC",
|
|
39898
|
-
rpcEnv: "ARC_TESTNET_RPC_URL"
|
|
39899
|
-
},
|
|
39900
|
-
[SOLANA_MAINNET_CAIP2]: {
|
|
39901
|
-
family: "svm",
|
|
39902
|
-
name: "Solana mainnet",
|
|
39903
|
-
usdc: SOLANA_MAINNET_USDC,
|
|
39904
|
-
gasToken: "SOL",
|
|
39905
|
-
rpcEnv: "SOLANA_RPC_URL",
|
|
39906
|
-
publicRpcUrl: "https://api.mainnet-beta.solana.com"
|
|
39907
|
-
},
|
|
39908
|
-
[X402_SOLANA_MAINNET_CAIP2]: {
|
|
39909
|
-
family: "svm",
|
|
39910
|
-
name: "Solana mainnet",
|
|
39911
|
-
usdc: SOLANA_MAINNET_USDC,
|
|
39912
|
-
gasToken: "SOL",
|
|
39913
|
-
rpcEnv: "SOLANA_RPC_URL",
|
|
39914
|
-
publicRpcUrl: "https://api.mainnet-beta.solana.com"
|
|
39915
|
-
}
|
|
39369
|
+
var marketplaceBadgeCodeSchema = external_exports.enum([
|
|
39370
|
+
"live_x402",
|
|
39371
|
+
"mpp",
|
|
39372
|
+
"partner",
|
|
39373
|
+
"payout_wallet_confirmed",
|
|
39374
|
+
"vapi_verified",
|
|
39375
|
+
"external_catalog",
|
|
39376
|
+
"approved_vendor",
|
|
39377
|
+
"unverified"
|
|
39378
|
+
]);
|
|
39379
|
+
var marketplaceBadgeSchema = external_exports.looseObject({
|
|
39380
|
+
code: marketplaceBadgeCodeSchema,
|
|
39381
|
+
label: external_exports.string().trim().min(1).max(80)
|
|
39382
|
+
});
|
|
39383
|
+
var marketplacePublicFactSchema = external_exports.looseObject({
|
|
39384
|
+
label: external_exports.string().trim().min(1).max(80),
|
|
39385
|
+
value: external_exports.string().trim().min(1).max(160)
|
|
39386
|
+
});
|
|
39387
|
+
var marketplaceHrefSchema = external_exports.union([
|
|
39388
|
+
external_exports.string().trim().min(1).max(2048).regex(/^\/(?!\/)/),
|
|
39389
|
+
external_exports.url().max(2048).regex(/^https:\/\//)
|
|
39390
|
+
]);
|
|
39391
|
+
var marketplaceCardSchema = external_exports.looseObject({
|
|
39392
|
+
title: external_exports.string().trim().min(1).max(160),
|
|
39393
|
+
summary: external_exports.string().trim().min(1).max(1e3),
|
|
39394
|
+
byline: external_exports.string().trim().min(1).max(160).optional(),
|
|
39395
|
+
bylineHref: marketplaceHrefSchema.optional(),
|
|
39396
|
+
badges: external_exports.preprocess(
|
|
39397
|
+
(badges) => Array.isArray(badges) ? badges.flatMap((badge) => {
|
|
39398
|
+
const parsed = marketplaceBadgeSchema.safeParse(badge);
|
|
39399
|
+
return parsed.success ? [parsed.data] : [];
|
|
39400
|
+
}) : badges,
|
|
39401
|
+
external_exports.array(marketplaceBadgeSchema).max(8)
|
|
39402
|
+
),
|
|
39403
|
+
facts: external_exports.array(marketplacePublicFactSchema).max(12)
|
|
39404
|
+
});
|
|
39405
|
+
var marketplaceHitBase = {
|
|
39406
|
+
ref: external_exports.string().trim().min(1).max(512),
|
|
39407
|
+
card: marketplaceCardSchema,
|
|
39408
|
+
...listingDisclosureShape
|
|
39916
39409
|
};
|
|
39917
|
-
|
|
39918
|
-
|
|
39919
|
-
|
|
39920
|
-
|
|
39921
|
-
|
|
39922
|
-
|
|
39923
|
-
|
|
39924
|
-
|
|
39925
|
-
|
|
39926
|
-
|
|
39927
|
-
}
|
|
39928
|
-
|
|
39929
|
-
|
|
39930
|
-
|
|
39931
|
-
|
|
39932
|
-
|
|
39933
|
-
|
|
39934
|
-
|
|
39935
|
-
|
|
39936
|
-
|
|
39937
|
-
|
|
39938
|
-
|
|
39939
|
-
|
|
39940
|
-
|
|
39941
|
-
|
|
39942
|
-
|
|
39943
|
-
|
|
39944
|
-
|
|
39945
|
-
|
|
39946
|
-
|
|
39947
|
-
|
|
39948
|
-
|
|
39949
|
-
|
|
39950
|
-
|
|
39951
|
-
|
|
39952
|
-
|
|
39953
|
-
|
|
39954
|
-
|
|
39955
|
-
|
|
39956
|
-
|
|
39957
|
-
|
|
39958
|
-
|
|
39959
|
-
|
|
39960
|
-
|
|
39961
|
-
|
|
39962
|
-
}
|
|
39963
|
-
|
|
39964
|
-
|
|
39965
|
-
|
|
39966
|
-
|
|
39967
|
-
|
|
39968
|
-
|
|
39969
|
-
|
|
39970
|
-
|
|
39971
|
-
|
|
39972
|
-
|
|
39973
|
-
|
|
39974
|
-
|
|
39975
|
-
|
|
39976
|
-
|
|
39977
|
-
|
|
39978
|
-
|
|
39979
|
-
|
|
39980
|
-
|
|
39981
|
-
|
|
39982
|
-
|
|
39983
|
-
|
|
39984
|
-
|
|
39985
|
-
|
|
39986
|
-
|
|
39987
|
-
|
|
39988
|
-
|
|
39989
|
-
|
|
39990
|
-
|
|
39991
|
-
const rpcUrl = envUrl || configured.rpcUrl.trim();
|
|
39992
|
-
if (rpcUrl) {
|
|
39993
|
-
return rpcUrl;
|
|
39994
|
-
}
|
|
39995
|
-
if (network === ARC_TESTNET_CAIP2) {
|
|
39996
|
-
throw new Error(
|
|
39997
|
-
"Arc testnet RPC is required. Set ARC_TESTNET_RPC_URL or add rpcUrl for eip155:5042002 in config.json."
|
|
39998
|
-
);
|
|
39999
|
-
}
|
|
40000
|
-
throw new Error(`RPC URL is required for ${network}.`);
|
|
40001
|
-
}
|
|
40002
|
-
function createChain(network, rpcUrl) {
|
|
40003
|
-
const definition = getNetworkDefinition(network);
|
|
40004
|
-
if (definition.family !== "evm" || definition.chainId === void 0) {
|
|
40005
|
-
throw new Error(`Network ${network} is not an EVM chain.`);
|
|
39410
|
+
var invokeApiActionSchema = external_exports.looseObject({
|
|
39411
|
+
type: external_exports.literal("invoke_api"),
|
|
39412
|
+
href: marketplaceHrefSchema
|
|
39413
|
+
});
|
|
39414
|
+
var firstPartyApiMarketplaceHitSchema = external_exports.looseObject({
|
|
39415
|
+
...marketplaceHitBase,
|
|
39416
|
+
kind: external_exports.literal("api"),
|
|
39417
|
+
provenance: firstPartyProvenanceSchema,
|
|
39418
|
+
execution: external_exports.looseObject({
|
|
39419
|
+
mode: executionModeSchema
|
|
39420
|
+
}),
|
|
39421
|
+
action: invokeApiActionSchema
|
|
39422
|
+
});
|
|
39423
|
+
var mirroredApiMarketplaceHitSchema = external_exports.looseObject({
|
|
39424
|
+
...marketplaceHitBase,
|
|
39425
|
+
kind: external_exports.literal("api"),
|
|
39426
|
+
provenance: external_exports.literal("indexed"),
|
|
39427
|
+
execution: external_exports.looseObject({
|
|
39428
|
+
mode: external_exports.literal("direct"),
|
|
39429
|
+
url: external_exports.url().max(2048).regex(/^https:\/\/(?![^/?#]*@)/),
|
|
39430
|
+
method: marketplaceExecutionMethodSchema.nullable(),
|
|
39431
|
+
network: external_exports.string().trim().max(160).transform((network) => {
|
|
39432
|
+
if (network === "solana") return X402_SOLANA_MAINNET_CAIP2;
|
|
39433
|
+
if (network === "solana-devnet") return SOLANA_DEVNET_CAIP2;
|
|
39434
|
+
return network;
|
|
39435
|
+
}).pipe(
|
|
39436
|
+
external_exports.union([
|
|
39437
|
+
external_exports.string().regex(/^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}$/),
|
|
39438
|
+
// Persisted mainnet configs also use the full genesis hash.
|
|
39439
|
+
external_exports.literal(SOLANA_MAINNET_CAIP2)
|
|
39440
|
+
])
|
|
39441
|
+
)
|
|
39442
|
+
}),
|
|
39443
|
+
action: invokeApiActionSchema
|
|
39444
|
+
});
|
|
39445
|
+
var apiMarketplaceHitSchema = external_exports.discriminatedUnion("provenance", [
|
|
39446
|
+
firstPartyApiMarketplaceHitSchema,
|
|
39447
|
+
mirroredApiMarketplaceHitSchema
|
|
39448
|
+
]);
|
|
39449
|
+
var serviceOfferMarketplaceHitSchema = external_exports.looseObject({
|
|
39450
|
+
...marketplaceHitBase,
|
|
39451
|
+
kind: external_exports.literal("service_offer"),
|
|
39452
|
+
action: external_exports.looseObject({
|
|
39453
|
+
type: external_exports.literal("start_engagement"),
|
|
39454
|
+
href: marketplaceHrefSchema
|
|
39455
|
+
})
|
|
39456
|
+
});
|
|
39457
|
+
var openRequestMarketplaceHitSchema = external_exports.looseObject({
|
|
39458
|
+
...marketplaceHitBase,
|
|
39459
|
+
kind: external_exports.literal("open_request"),
|
|
39460
|
+
action: external_exports.looseObject({
|
|
39461
|
+
type: external_exports.literal("propose_to_request"),
|
|
39462
|
+
href: marketplaceHrefSchema
|
|
39463
|
+
})
|
|
39464
|
+
});
|
|
39465
|
+
var marketplaceHitSchema = external_exports.union([
|
|
39466
|
+
apiMarketplaceHitSchema,
|
|
39467
|
+
serviceOfferMarketplaceHitSchema,
|
|
39468
|
+
openRequestMarketplaceHitSchema
|
|
39469
|
+
]);
|
|
39470
|
+
var marketplaceDiscoveryInputSchema = external_exports.strictObject({
|
|
39471
|
+
q: external_exports.string().trim().max(200).optional(),
|
|
39472
|
+
kinds: external_exports.array(marketplaceKindSchema).min(1).max(MARKETPLACE_KINDS.length).optional(),
|
|
39473
|
+
network: external_exports.string().trim().min(1).max(160).optional(),
|
|
39474
|
+
cursor: external_exports.string().trim().min(1).max(4096).optional(),
|
|
39475
|
+
limit: external_exports.number().int().min(1).max(50).optional(),
|
|
39476
|
+
includeUnverified: external_exports.boolean().optional()
|
|
39477
|
+
}).superRefine((input2, context) => {
|
|
39478
|
+
if (input2.kinds && new Set(input2.kinds).size !== input2.kinds.length) {
|
|
39479
|
+
context.addIssue({
|
|
39480
|
+
code: "custom",
|
|
39481
|
+
path: ["kinds"],
|
|
39482
|
+
message: "Marketplace kinds must be unique"
|
|
39483
|
+
});
|
|
40006
39484
|
}
|
|
40007
|
-
|
|
40008
|
-
|
|
40009
|
-
|
|
40010
|
-
nativeCurrency: definition.gasToken === "USDC" ? { name: "USDC", symbol: "USDC", decimals: USDC_DECIMALS } : { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
40011
|
-
rpcUrls: {
|
|
40012
|
-
default: { http: [rpcUrl] }
|
|
40013
|
-
},
|
|
40014
|
-
...definition.explorerUrl ? {
|
|
40015
|
-
blockExplorers: {
|
|
40016
|
-
default: { name: `${definition.name} explorer`, url: definition.explorerUrl }
|
|
40017
|
-
}
|
|
40018
|
-
} : {}
|
|
40019
|
-
});
|
|
40020
|
-
}
|
|
40021
|
-
function createNetworkPublicClient(network, configured, options = {}) {
|
|
40022
|
-
const rpcUrl = requireRpcUrl(network, configured);
|
|
40023
|
-
return createPublicClient({
|
|
40024
|
-
chain: createChain(network, rpcUrl),
|
|
40025
|
-
transport: createNetworkHttpTransport(rpcUrl, options)
|
|
40026
|
-
});
|
|
40027
|
-
}
|
|
40028
|
-
function createNetworkHttpTransport(rpcUrl, options = {}) {
|
|
40029
|
-
const fetchFn = options.fetch ?? createPublicFetch({
|
|
40030
|
-
allowPrivateNetwork: options.allowPrivateNetwork ?? false,
|
|
40031
|
-
...options.lookup ? { lookup: options.lookup } : {}
|
|
40032
|
-
});
|
|
40033
|
-
return http(rpcUrl, { fetchFn, fetchOptions: { redirect: "manual" } });
|
|
40034
|
-
}
|
|
40035
|
-
function formatUsdc(amountAtomic2) {
|
|
40036
|
-
return formatUnits(amountAtomic2, USDC_DECIMALS);
|
|
39485
|
+
});
|
|
39486
|
+
function isMirroredHit(hit) {
|
|
39487
|
+
return hit.kind === "api" && hit.provenance === "indexed";
|
|
40037
39488
|
}
|
|
39489
|
+
var marketplaceDiscoveryEnvelopeSchema = external_exports.looseObject({
|
|
39490
|
+
protocol: external_exports.literal(MARKETPLACE_DISCOVERY_PROTOCOL),
|
|
39491
|
+
items: external_exports.array(external_exports.unknown()),
|
|
39492
|
+
nextCursor: external_exports.string().min(1).max(4096).nullable(),
|
|
39493
|
+
unavailableKinds: external_exports.array(marketplaceKindSchema).max(MARKETPLACE_KINDS.length),
|
|
39494
|
+
rankingVersion: external_exports.literal(MARKETPLACE_RANKING_VERSION)
|
|
39495
|
+
});
|
|
39496
|
+
var marketplaceDiscoveryPageSchema = marketplaceDiscoveryEnvelopeSchema.extend({
|
|
39497
|
+
items: external_exports.array(marketplaceHitSchema)
|
|
39498
|
+
});
|
|
40038
39499
|
|
|
40039
39500
|
// ../../node_modules/.pnpm/@solana+errors@5.5.1_typescript@6.0.3/node_modules/@solana/errors/dist/index.node.mjs
|
|
40040
39501
|
var SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED = 1;
|
|
@@ -45016,16 +44477,16 @@ var DEFAULT_COMPUTE_UNIT_PRICE_MICROLAMPORTS = 1;
|
|
|
45016
44477
|
var DEFAULT_COMPUTE_UNIT_LIMIT = 2e4;
|
|
45017
44478
|
var MAX_MEMO_BYTES = 256;
|
|
45018
44479
|
var SOLANA_MAINNET_CAIP22 = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
45019
|
-
var
|
|
44480
|
+
var SOLANA_DEVNET_CAIP22 = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
45020
44481
|
var SOLANA_TESTNET_CAIP2 = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z";
|
|
45021
44482
|
var V1_TO_V2_NETWORK_MAP = {
|
|
45022
44483
|
solana: SOLANA_MAINNET_CAIP22,
|
|
45023
|
-
"solana-devnet":
|
|
44484
|
+
"solana-devnet": SOLANA_DEVNET_CAIP22,
|
|
45024
44485
|
"solana-testnet": SOLANA_TESTNET_CAIP2
|
|
45025
44486
|
};
|
|
45026
44487
|
function normalizeNetwork(network) {
|
|
45027
44488
|
if (network.includes(":")) {
|
|
45028
|
-
const supported = [SOLANA_MAINNET_CAIP22,
|
|
44489
|
+
const supported = [SOLANA_MAINNET_CAIP22, SOLANA_DEVNET_CAIP22, SOLANA_TESTNET_CAIP2];
|
|
45029
44490
|
if (!supported.includes(network)) {
|
|
45030
44491
|
throw new Error(`Unsupported SVM network: ${network}`);
|
|
45031
44492
|
}
|
|
@@ -45073,7 +44534,7 @@ var DEFAULT_ASSETS = {
|
|
|
45073
44534
|
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS2
|
|
45074
44535
|
}
|
|
45075
44536
|
],
|
|
45076
|
-
[
|
|
44537
|
+
[SOLANA_DEVNET_CAIP22]: [
|
|
45077
44538
|
{
|
|
45078
44539
|
asset: USDC_DEVNET_ADDRESS,
|
|
45079
44540
|
decimals: 6,
|
|
@@ -45128,7 +44589,7 @@ var findDefaultAsset = (asset, network) => {
|
|
|
45128
44589
|
function createRpcClient(network, customRpcUrl) {
|
|
45129
44590
|
const caip2Network = normalizeNetwork(network);
|
|
45130
44591
|
switch (caip2Network) {
|
|
45131
|
-
case
|
|
44592
|
+
case SOLANA_DEVNET_CAIP22: {
|
|
45132
44593
|
const url2 = customRpcUrl || DEVNET_RPC_URL;
|
|
45133
44594
|
return createSolanaRpc(devnet(url2));
|
|
45134
44595
|
}
|
|
@@ -45326,6 +44787,376 @@ var ExactSvmScheme = class {
|
|
|
45326
44787
|
var addressEncoder = getAddressEncoder();
|
|
45327
44788
|
var compiledMessageDecoder = getCompiledTransactionMessageDecoder();
|
|
45328
44789
|
|
|
44790
|
+
// ../core/src/net-guard.ts
|
|
44791
|
+
import { lookup as dnsLookup } from "node:dns/promises";
|
|
44792
|
+
import { request as httpRequest } from "node:http";
|
|
44793
|
+
import { request as httpsRequest } from "node:https";
|
|
44794
|
+
import { isIP } from "node:net";
|
|
44795
|
+
import { Readable } from "node:stream";
|
|
44796
|
+
var defaultLookup = async (hostname3) => {
|
|
44797
|
+
const addresses = await dnsLookup(hostname3, { all: true });
|
|
44798
|
+
return addresses.map(({ address: address4 }) => address4);
|
|
44799
|
+
};
|
|
44800
|
+
async function assertPublicUrl(url2, options) {
|
|
44801
|
+
if (url2.username || url2.password) {
|
|
44802
|
+
throw guardError(url2);
|
|
44803
|
+
}
|
|
44804
|
+
if (url2.protocol !== "http:" && url2.protocol !== "https:") {
|
|
44805
|
+
throw guardError(url2);
|
|
44806
|
+
}
|
|
44807
|
+
if (options.allowPrivateNetwork) {
|
|
44808
|
+
return;
|
|
44809
|
+
}
|
|
44810
|
+
const hostname3 = normalizeHostname(url2.hostname);
|
|
44811
|
+
const lowercaseHostname = hostname3.toLowerCase();
|
|
44812
|
+
if (!lowercaseHostname || lowercaseHostname === "localhost" || lowercaseHostname.endsWith(".localhost") || lowercaseHostname.endsWith(".local") || lowercaseHostname.endsWith(".internal")) {
|
|
44813
|
+
throw guardError(url2);
|
|
44814
|
+
}
|
|
44815
|
+
if (isIP(hostname3)) {
|
|
44816
|
+
if (isNonPublicAddress(hostname3)) {
|
|
44817
|
+
throw guardError(url2);
|
|
44818
|
+
}
|
|
44819
|
+
return;
|
|
44820
|
+
}
|
|
44821
|
+
let addresses;
|
|
44822
|
+
try {
|
|
44823
|
+
addresses = await withTimeout2(
|
|
44824
|
+
(options.lookup ?? defaultLookup)(hostname3),
|
|
44825
|
+
options.timeoutMs ?? 5e3
|
|
44826
|
+
);
|
|
44827
|
+
} catch {
|
|
44828
|
+
throw guardError(url2);
|
|
44829
|
+
}
|
|
44830
|
+
if (addresses.length === 0 || addresses.some(isNonPublicAddress)) {
|
|
44831
|
+
throw guardError(url2);
|
|
44832
|
+
}
|
|
44833
|
+
}
|
|
44834
|
+
function createPublicFetch(options) {
|
|
44835
|
+
const lookupFn = options.lookup ?? defaultLookup;
|
|
44836
|
+
return (async (input2, init) => {
|
|
44837
|
+
const url2 = new URL(input2 instanceof Request ? input2.url : input2);
|
|
44838
|
+
await assertPublicUrl(url2, {
|
|
44839
|
+
allowPrivateNetwork: options.allowPrivateNetwork,
|
|
44840
|
+
lookup: lookupFn,
|
|
44841
|
+
timeoutMs: 5e3
|
|
44842
|
+
});
|
|
44843
|
+
const normalized = new Request(input2, init);
|
|
44844
|
+
const bytes = normalized.body ? Buffer.from(await normalized.arrayBuffer()) : null;
|
|
44845
|
+
return await new Promise((resolve2, reject) => {
|
|
44846
|
+
const requestOptions2 = {
|
|
44847
|
+
method: normalized.method,
|
|
44848
|
+
headers: Object.fromEntries(normalized.headers),
|
|
44849
|
+
signal: normalized.signal,
|
|
44850
|
+
...options.allowPrivateNetwork ? {} : { lookup: pinnedLookup(lookupFn) }
|
|
44851
|
+
};
|
|
44852
|
+
const onResponse = (incoming) => {
|
|
44853
|
+
try {
|
|
44854
|
+
const headers = new Headers();
|
|
44855
|
+
for (const [name, value] of Object.entries(incoming.headers)) {
|
|
44856
|
+
if (Array.isArray(value)) {
|
|
44857
|
+
for (const item of value) headers.append(name, item);
|
|
44858
|
+
} else if (value !== void 0) {
|
|
44859
|
+
headers.set(name, value);
|
|
44860
|
+
}
|
|
44861
|
+
}
|
|
44862
|
+
const status = incoming.statusCode ?? 500;
|
|
44863
|
+
const bodyForbidden = normalized.method === "HEAD" || [204, 205, 304].includes(status);
|
|
44864
|
+
if (bodyForbidden) incoming.resume();
|
|
44865
|
+
const response = new Response(
|
|
44866
|
+
bodyForbidden ? null : Readable.toWeb(incoming),
|
|
44867
|
+
{ status, statusText: incoming.statusMessage, headers }
|
|
44868
|
+
);
|
|
44869
|
+
Object.defineProperty(response, "url", { value: url2.toString() });
|
|
44870
|
+
resolve2(response);
|
|
44871
|
+
} catch (error61) {
|
|
44872
|
+
incoming.destroy();
|
|
44873
|
+
reject(error61);
|
|
44874
|
+
}
|
|
44875
|
+
};
|
|
44876
|
+
const request = url2.protocol === "https:" ? httpsRequest(url2, requestOptions2, onResponse) : httpRequest(url2, requestOptions2, onResponse);
|
|
44877
|
+
request.on("error", reject);
|
|
44878
|
+
if (bytes) request.write(bytes);
|
|
44879
|
+
request.end();
|
|
44880
|
+
});
|
|
44881
|
+
});
|
|
44882
|
+
}
|
|
44883
|
+
function pinnedLookup(lookup2) {
|
|
44884
|
+
return (hostname3, dnsOptions, callback) => {
|
|
44885
|
+
void lookup2(normalizeHostname(hostname3)).then((addresses) => {
|
|
44886
|
+
if (addresses.length === 0 || addresses.some(isNonPublicAddress)) {
|
|
44887
|
+
callback(guardError(new URL(`https://${hostname3}`)), "");
|
|
44888
|
+
return;
|
|
44889
|
+
}
|
|
44890
|
+
const address4 = addresses[0];
|
|
44891
|
+
const family = isIP(address4);
|
|
44892
|
+
callback(
|
|
44893
|
+
null,
|
|
44894
|
+
dnsOptions.all ? [{ address: address4, family }] : address4,
|
|
44895
|
+
dnsOptions.all ? void 0 : family
|
|
44896
|
+
);
|
|
44897
|
+
}).catch(
|
|
44898
|
+
(error61) => callback(error61 instanceof Error ? error61 : new Error("DNS lookup failed."), "")
|
|
44899
|
+
);
|
|
44900
|
+
};
|
|
44901
|
+
}
|
|
44902
|
+
async function withTimeout2(operation, timeoutMs) {
|
|
44903
|
+
let timeout;
|
|
44904
|
+
try {
|
|
44905
|
+
return await Promise.race([
|
|
44906
|
+
operation,
|
|
44907
|
+
new Promise((_resolve, reject) => {
|
|
44908
|
+
timeout = setTimeout(() => reject(new Error("DNS lookup timed out.")), timeoutMs);
|
|
44909
|
+
})
|
|
44910
|
+
]);
|
|
44911
|
+
} finally {
|
|
44912
|
+
if (timeout) clearTimeout(timeout);
|
|
44913
|
+
}
|
|
44914
|
+
}
|
|
44915
|
+
function normalizeHostname(hostname3) {
|
|
44916
|
+
const unbracketed = hostname3.startsWith("[") && hostname3.endsWith("]") ? hostname3.slice(1, -1) : hostname3;
|
|
44917
|
+
return unbracketed.endsWith(".") ? unbracketed.slice(0, -1) : unbracketed;
|
|
44918
|
+
}
|
|
44919
|
+
function isNonPublicAddress(address4) {
|
|
44920
|
+
const normalized = normalizeHostname(address4);
|
|
44921
|
+
const version5 = isIP(normalized);
|
|
44922
|
+
if (version5 === 4) {
|
|
44923
|
+
return isNonPublicIpv4(parseIpv4(normalized));
|
|
44924
|
+
}
|
|
44925
|
+
if (version5 === 6) {
|
|
44926
|
+
return isNonPublicIpv6(parseIpv6(normalized));
|
|
44927
|
+
}
|
|
44928
|
+
return true;
|
|
44929
|
+
}
|
|
44930
|
+
function parseIpv4(address4) {
|
|
44931
|
+
const octets = address4.split(".").map(Number);
|
|
44932
|
+
return [octets[0], octets[1], octets[2], octets[3]];
|
|
44933
|
+
}
|
|
44934
|
+
function isNonPublicIpv4([first, second, third]) {
|
|
44935
|
+
return first === 0 || first === 10 || first === 100 && second >= 64 && second <= 127 || first === 127 || first === 169 && second === 254 || first === 172 && second >= 16 && second <= 31 || first === 192 && second === 0 && (third === 0 || third === 2) || first === 192 && second === 168 || first === 198 && second >= 18 && second <= 19 || first === 198 && second === 51 && third === 100 || first === 203 && second === 0 && third === 113 || first >= 224;
|
|
44936
|
+
}
|
|
44937
|
+
function parseIpv6(address4) {
|
|
44938
|
+
let normalized = address4.toLowerCase();
|
|
44939
|
+
const lastColon = normalized.lastIndexOf(":");
|
|
44940
|
+
const dottedTail = normalized.slice(lastColon + 1);
|
|
44941
|
+
if (dottedTail.includes(".")) {
|
|
44942
|
+
const [first, second, third, fourth] = parseIpv4(dottedTail);
|
|
44943
|
+
normalized = `${normalized.slice(0, lastColon + 1)}${(first << 8 | second).toString(16)}:${(third << 8 | fourth).toString(16)}`;
|
|
44944
|
+
}
|
|
44945
|
+
const halves = normalized.split("::");
|
|
44946
|
+
const left = halves[0] ? halves[0].split(":").map(parseHex) : [];
|
|
44947
|
+
const right = halves[1] ? halves[1].split(":").map(parseHex) : [];
|
|
44948
|
+
const omittedCount = 8 - left.length - right.length;
|
|
44949
|
+
return halves.length === 2 ? [...left, ...Array.from({ length: omittedCount }, () => 0), ...right] : left;
|
|
44950
|
+
}
|
|
44951
|
+
function parseHex(value) {
|
|
44952
|
+
return Number.parseInt(value, 16);
|
|
44953
|
+
}
|
|
44954
|
+
function isNonPublicIpv6(hextets) {
|
|
44955
|
+
if (hextets.slice(0, 5).every((hextet) => hextet === 0) && hextets[5] === 65535) {
|
|
44956
|
+
const embeddedIpv4 = [
|
|
44957
|
+
hextets[6] >> 8,
|
|
44958
|
+
hextets[6] & 255,
|
|
44959
|
+
hextets[7] >> 8,
|
|
44960
|
+
hextets[7] & 255
|
|
44961
|
+
];
|
|
44962
|
+
return isNonPublicIpv4(embeddedIpv4);
|
|
44963
|
+
}
|
|
44964
|
+
if (hextets.slice(0, 6).every((hextet) => hextet === 0)) {
|
|
44965
|
+
const compatibleIpv4 = [
|
|
44966
|
+
hextets[6] >> 8,
|
|
44967
|
+
hextets[6] & 255,
|
|
44968
|
+
hextets[7] >> 8,
|
|
44969
|
+
hextets[7] & 255
|
|
44970
|
+
];
|
|
44971
|
+
if (isNonPublicIpv4(compatibleIpv4)) return true;
|
|
44972
|
+
}
|
|
44973
|
+
const isUnspecified = hextets.every((hextet) => hextet === 0);
|
|
44974
|
+
const isLoopback = hextets.slice(0, 7).every((hextet) => hextet === 0) && hextets[7] === 1;
|
|
44975
|
+
const first = hextets[0];
|
|
44976
|
+
const isUniqueLocal = first >= 64512 && first <= 65023;
|
|
44977
|
+
const isLinkLocal = first >= 65152 && first <= 65215;
|
|
44978
|
+
const isSiteLocal = first >= 65216 && first <= 65279;
|
|
44979
|
+
const isMulticast = first >= 65280;
|
|
44980
|
+
const isDocumentation = first === 8193 && hextets[1] === 3512;
|
|
44981
|
+
return isUnspecified || isLoopback || isUniqueLocal || isLinkLocal || isSiteLocal || isMulticast || isDocumentation;
|
|
44982
|
+
}
|
|
44983
|
+
function guardError(url2) {
|
|
44984
|
+
return new Error(
|
|
44985
|
+
`URL hostname ${JSON.stringify(url2.hostname)} is not allowed; private or internal destinations require allowPrivateNetwork true in the vAPI config.`
|
|
44986
|
+
);
|
|
44987
|
+
}
|
|
44988
|
+
|
|
44989
|
+
// ../core/src/networks.ts
|
|
44990
|
+
var USDC_DECIMALS = 6;
|
|
44991
|
+
var DEFAULT_ARC_GAS_HEADROOM_ATOMIC = 50000n;
|
|
44992
|
+
var NETWORKS2 = {
|
|
44993
|
+
[BASE_MAINNET_CAIP2]: {
|
|
44994
|
+
family: "evm",
|
|
44995
|
+
chainId: 8453,
|
|
44996
|
+
name: "Base mainnet",
|
|
44997
|
+
usdc: CANONICAL_X402_USDC_NETWORKS[BASE_MAINNET_CAIP2].usdc,
|
|
44998
|
+
gasToken: "ETH",
|
|
44999
|
+
rpcEnv: "BASE_RPC_URL",
|
|
45000
|
+
publicRpcUrl: "https://mainnet.base.org",
|
|
45001
|
+
explorerUrl: "https://basescan.org"
|
|
45002
|
+
},
|
|
45003
|
+
[ARC_MAINNET_CAIP2]: {
|
|
45004
|
+
family: "evm",
|
|
45005
|
+
chainId: 5042,
|
|
45006
|
+
name: "Arc mainnet",
|
|
45007
|
+
usdc: CANONICAL_X402_USDC_NETWORKS[ARC_MAINNET_CAIP2].usdc,
|
|
45008
|
+
gasToken: "USDC",
|
|
45009
|
+
rpcEnv: "ARC_RPC_URL",
|
|
45010
|
+
publicRpcUrl: "https://rpc.mainnet.arc.io",
|
|
45011
|
+
explorerUrl: "https://explorer.arc.io"
|
|
45012
|
+
},
|
|
45013
|
+
[ARC_TESTNET_CAIP2]: {
|
|
45014
|
+
family: "evm",
|
|
45015
|
+
chainId: 5042002,
|
|
45016
|
+
name: "Arc testnet",
|
|
45017
|
+
usdc: CANONICAL_X402_USDC_NETWORKS[ARC_TESTNET_CAIP2].usdc,
|
|
45018
|
+
gasToken: "USDC",
|
|
45019
|
+
rpcEnv: "ARC_TESTNET_RPC_URL"
|
|
45020
|
+
},
|
|
45021
|
+
[SOLANA_MAINNET_CAIP2]: {
|
|
45022
|
+
family: "svm",
|
|
45023
|
+
name: "Solana mainnet",
|
|
45024
|
+
usdc: SOLANA_MAINNET_USDC,
|
|
45025
|
+
gasToken: "SOL",
|
|
45026
|
+
rpcEnv: "SOLANA_RPC_URL",
|
|
45027
|
+
publicRpcUrl: "https://api.mainnet-beta.solana.com"
|
|
45028
|
+
},
|
|
45029
|
+
[X402_SOLANA_MAINNET_CAIP2]: {
|
|
45030
|
+
family: "svm",
|
|
45031
|
+
name: "Solana mainnet",
|
|
45032
|
+
usdc: SOLANA_MAINNET_USDC,
|
|
45033
|
+
gasToken: "SOL",
|
|
45034
|
+
rpcEnv: "SOLANA_RPC_URL",
|
|
45035
|
+
publicRpcUrl: "https://api.mainnet-beta.solana.com"
|
|
45036
|
+
}
|
|
45037
|
+
};
|
|
45038
|
+
function parseEip155ChainId(network) {
|
|
45039
|
+
const match = /^eip155:(\d+)$/.exec(network);
|
|
45040
|
+
if (!match) {
|
|
45041
|
+
throw new Error(`Unsupported network ${network}; expected eip155:<chainId>.`);
|
|
45042
|
+
}
|
|
45043
|
+
const chainId = Number(match[1]);
|
|
45044
|
+
if (!Number.isSafeInteger(chainId) || chainId <= 0) {
|
|
45045
|
+
throw new Error(`Invalid EVM chain ID in network ${network}.`);
|
|
45046
|
+
}
|
|
45047
|
+
return chainId;
|
|
45048
|
+
}
|
|
45049
|
+
function isSolanaNetwork(network) {
|
|
45050
|
+
return network === SOLANA_MAINNET_CAIP2 || network === X402_SOLANA_MAINNET_CAIP2;
|
|
45051
|
+
}
|
|
45052
|
+
function usesUsdcGas(network) {
|
|
45053
|
+
try {
|
|
45054
|
+
return getNetworkDefinition(network).gasToken === "USDC";
|
|
45055
|
+
} catch {
|
|
45056
|
+
return false;
|
|
45057
|
+
}
|
|
45058
|
+
}
|
|
45059
|
+
function explorerTransactionUrl(network, hash5) {
|
|
45060
|
+
try {
|
|
45061
|
+
const explorerUrl = getNetworkDefinition(network).explorerUrl;
|
|
45062
|
+
return explorerUrl ? `${explorerUrl}/tx/${hash5}` : void 0;
|
|
45063
|
+
} catch {
|
|
45064
|
+
return void 0;
|
|
45065
|
+
}
|
|
45066
|
+
}
|
|
45067
|
+
function explorerAddressUrl(network, address4) {
|
|
45068
|
+
try {
|
|
45069
|
+
const explorerUrl = getNetworkDefinition(network).explorerUrl;
|
|
45070
|
+
return explorerUrl ? `${explorerUrl}/address/${address4}` : void 0;
|
|
45071
|
+
} catch {
|
|
45072
|
+
return void 0;
|
|
45073
|
+
}
|
|
45074
|
+
}
|
|
45075
|
+
function areSamePaymentNetwork(left, right) {
|
|
45076
|
+
return left === right || isSolanaNetwork(left) && isSolanaNetwork(right);
|
|
45077
|
+
}
|
|
45078
|
+
function isSupportedPaymentNetwork(network) {
|
|
45079
|
+
if (isSolanaNetwork(network)) return true;
|
|
45080
|
+
try {
|
|
45081
|
+
parseEip155ChainId(network);
|
|
45082
|
+
return true;
|
|
45083
|
+
} catch {
|
|
45084
|
+
return false;
|
|
45085
|
+
}
|
|
45086
|
+
}
|
|
45087
|
+
function configuredNetworkFor(networks, network) {
|
|
45088
|
+
const configured = networks[network];
|
|
45089
|
+
if (configured) return configured;
|
|
45090
|
+
if (network === X402_SOLANA_MAINNET_CAIP2) return networks[SOLANA_MAINNET_CAIP2];
|
|
45091
|
+
if (network === SOLANA_MAINNET_CAIP2) return networks[X402_SOLANA_MAINNET_CAIP2];
|
|
45092
|
+
return void 0;
|
|
45093
|
+
}
|
|
45094
|
+
function getNetworkDefinition(network) {
|
|
45095
|
+
const known = NETWORKS2[network];
|
|
45096
|
+
if (known) {
|
|
45097
|
+
return known;
|
|
45098
|
+
}
|
|
45099
|
+
const chainId = parseEip155ChainId(network);
|
|
45100
|
+
return {
|
|
45101
|
+
family: "evm",
|
|
45102
|
+
chainId,
|
|
45103
|
+
name: network,
|
|
45104
|
+
usdc: getAddress("0x0000000000000000000000000000000000000000"),
|
|
45105
|
+
gasToken: "ETH",
|
|
45106
|
+
rpcEnv: ""
|
|
45107
|
+
};
|
|
45108
|
+
}
|
|
45109
|
+
function requireRpcUrl(network, configured) {
|
|
45110
|
+
const definition = getNetworkDefinition(network);
|
|
45111
|
+
const envUrl = definition.rpcEnv ? process.env[definition.rpcEnv]?.trim() : void 0;
|
|
45112
|
+
const rpcUrl = envUrl || configured.rpcUrl.trim();
|
|
45113
|
+
if (rpcUrl) {
|
|
45114
|
+
return rpcUrl;
|
|
45115
|
+
}
|
|
45116
|
+
if (network === ARC_TESTNET_CAIP2) {
|
|
45117
|
+
throw new Error(
|
|
45118
|
+
"Arc testnet RPC is required. Set ARC_TESTNET_RPC_URL or add rpcUrl for eip155:5042002 in config.json."
|
|
45119
|
+
);
|
|
45120
|
+
}
|
|
45121
|
+
throw new Error(`RPC URL is required for ${network}.`);
|
|
45122
|
+
}
|
|
45123
|
+
function createChain(network, rpcUrl) {
|
|
45124
|
+
const definition = getNetworkDefinition(network);
|
|
45125
|
+
if (definition.family !== "evm" || definition.chainId === void 0) {
|
|
45126
|
+
throw new Error(`Network ${network} is not an EVM chain.`);
|
|
45127
|
+
}
|
|
45128
|
+
return defineChain({
|
|
45129
|
+
id: definition.chainId,
|
|
45130
|
+
name: definition.name,
|
|
45131
|
+
nativeCurrency: definition.gasToken === "USDC" ? { name: "USDC", symbol: "USDC", decimals: USDC_DECIMALS } : { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
45132
|
+
rpcUrls: {
|
|
45133
|
+
default: { http: [rpcUrl] }
|
|
45134
|
+
},
|
|
45135
|
+
...definition.explorerUrl ? {
|
|
45136
|
+
blockExplorers: {
|
|
45137
|
+
default: { name: `${definition.name} explorer`, url: definition.explorerUrl }
|
|
45138
|
+
}
|
|
45139
|
+
} : {}
|
|
45140
|
+
});
|
|
45141
|
+
}
|
|
45142
|
+
function createNetworkPublicClient(network, configured, options = {}) {
|
|
45143
|
+
const rpcUrl = requireRpcUrl(network, configured);
|
|
45144
|
+
return createPublicClient({
|
|
45145
|
+
chain: createChain(network, rpcUrl),
|
|
45146
|
+
transport: createNetworkHttpTransport(rpcUrl, options)
|
|
45147
|
+
});
|
|
45148
|
+
}
|
|
45149
|
+
function createNetworkHttpTransport(rpcUrl, options = {}) {
|
|
45150
|
+
const fetchFn = options.fetch ?? createPublicFetch({
|
|
45151
|
+
allowPrivateNetwork: options.allowPrivateNetwork ?? false,
|
|
45152
|
+
...options.lookup ? { lookup: options.lookup } : {}
|
|
45153
|
+
});
|
|
45154
|
+
return http(rpcUrl, { fetchFn, fetchOptions: { redirect: "manual" } });
|
|
45155
|
+
}
|
|
45156
|
+
function formatUsdc(amountAtomic2) {
|
|
45157
|
+
return formatUnits(amountAtomic2, USDC_DECIMALS);
|
|
45158
|
+
}
|
|
45159
|
+
|
|
45329
45160
|
// ../core/src/x402.ts
|
|
45330
45161
|
var MAX_CHALLENGE_BYTES = 1048576;
|
|
45331
45162
|
var MAX_UINT256 = (1n << 256n) - 1n;
|
|
@@ -46185,6 +46016,242 @@ function isRecord2(value) {
|
|
|
46185
46016
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
46186
46017
|
}
|
|
46187
46018
|
|
|
46019
|
+
// ../core/src/call-contracts-wire.ts
|
|
46020
|
+
var CALLABLE_CATEGORIES = ["ai", "data", "crypto", "compute", "search"];
|
|
46021
|
+
var callableCategorySchema = external_exports.enum(CALLABLE_CATEGORIES);
|
|
46022
|
+
var DISCOVERY_CATEGORIES = [...CALLABLE_CATEGORIES, "other"];
|
|
46023
|
+
var discoveryCategorySchema = external_exports.string().trim().min(1);
|
|
46024
|
+
var CALLABLE_CATEGORY_SET = new Set(CALLABLE_CATEGORIES);
|
|
46025
|
+
var serviceTierSchema = external_exports.string().trim().min(1);
|
|
46026
|
+
var discoveryEndpointSchema = external_exports.looseObject({
|
|
46027
|
+
name: external_exports.string(),
|
|
46028
|
+
method: external_exports.string(),
|
|
46029
|
+
url: external_exports.url(),
|
|
46030
|
+
price: external_exports.string(),
|
|
46031
|
+
description: external_exports.string(),
|
|
46032
|
+
operationId: external_exports.string().trim().min(1).optional(),
|
|
46033
|
+
requestContentType: external_exports.string().trim().min(1).optional(),
|
|
46034
|
+
requestSchema: external_exports.json().optional(),
|
|
46035
|
+
responseContentType: external_exports.string().trim().min(1).optional(),
|
|
46036
|
+
pathTemplate: external_exports.string().trim().min(1).optional(),
|
|
46037
|
+
pathParameters: external_exports.array(external_exports.string().trim().min(1)).optional(),
|
|
46038
|
+
payment: external_exports.union([
|
|
46039
|
+
external_exports.looseObject({
|
|
46040
|
+
scheme: external_exports.literal("exact"),
|
|
46041
|
+
network: external_exports.string().regex(/^eip155:\d+$/),
|
|
46042
|
+
asset: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
46043
|
+
payTo: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
46044
|
+
checkedAt: external_exports.iso.datetime()
|
|
46045
|
+
}),
|
|
46046
|
+
external_exports.looseObject({
|
|
46047
|
+
scheme: external_exports.literal("exact"),
|
|
46048
|
+
network: external_exports.union([
|
|
46049
|
+
external_exports.string().regex(/^solana:[-_a-zA-Z0-9]{1,32}$/),
|
|
46050
|
+
external_exports.literal(SOLANA_MAINNET_CAIP2)
|
|
46051
|
+
]),
|
|
46052
|
+
asset: external_exports.string().refine(isSolanaAddress, "Expected a Solana base58 address."),
|
|
46053
|
+
payTo: external_exports.string().refine(isSolanaAddress, "Expected a Solana base58 address."),
|
|
46054
|
+
checkedAt: external_exports.iso.datetime()
|
|
46055
|
+
}),
|
|
46056
|
+
external_exports.looseObject({
|
|
46057
|
+
protocol: external_exports.literal("mpp"),
|
|
46058
|
+
intent: external_exports.enum(["charge", "authorize", "subscription"]).nullable(),
|
|
46059
|
+
method: external_exports.string().trim().min(1).max(40).nullable(),
|
|
46060
|
+
checkedAt: external_exports.iso.datetime(),
|
|
46061
|
+
// Keep common x402 properties readable on the union while making it
|
|
46062
|
+
// impossible for MPP metadata to masquerade as executable x402 terms.
|
|
46063
|
+
network: external_exports.never().optional(),
|
|
46064
|
+
payTo: external_exports.never().optional()
|
|
46065
|
+
}),
|
|
46066
|
+
external_exports.looseObject({
|
|
46067
|
+
// Future payment protocols remain visible to callers so the payment
|
|
46068
|
+
// layer can refuse them explicitly instead of discovery losing the row.
|
|
46069
|
+
protocol: external_exports.string().trim().min(1).max(40),
|
|
46070
|
+
checkedAt: external_exports.iso.datetime(),
|
|
46071
|
+
network: external_exports.never().optional(),
|
|
46072
|
+
payTo: external_exports.never().optional()
|
|
46073
|
+
})
|
|
46074
|
+
]).optional()
|
|
46075
|
+
});
|
|
46076
|
+
var serviceSummarySchema = external_exports.looseObject({
|
|
46077
|
+
id: external_exports.string(),
|
|
46078
|
+
name: external_exports.string(),
|
|
46079
|
+
description: external_exports.string(),
|
|
46080
|
+
category: discoveryCategorySchema,
|
|
46081
|
+
tier: serviceTierSchema,
|
|
46082
|
+
...listingDisclosureShape,
|
|
46083
|
+
verified: external_exports.boolean(),
|
|
46084
|
+
wrapped: external_exports.boolean(),
|
|
46085
|
+
price: external_exports.string(),
|
|
46086
|
+
networks: external_exports.array(external_exports.string()),
|
|
46087
|
+
endpoints: external_exports.array(discoveryEndpointSchema)
|
|
46088
|
+
});
|
|
46089
|
+
var searchServicesResponseSchema = external_exports.looseObject({
|
|
46090
|
+
services: external_exports.array(serviceSummarySchema)
|
|
46091
|
+
});
|
|
46092
|
+
var discoveryResponseSchema = searchServicesResponseSchema;
|
|
46093
|
+
|
|
46094
|
+
// ../core/src/call-contracts.ts
|
|
46095
|
+
var DiscoveryCatalogError = class extends Error {
|
|
46096
|
+
constructor(code, message, serviceId, paymentNetworks) {
|
|
46097
|
+
super(message);
|
|
46098
|
+
this.paymentNetworks = paymentNetworks;
|
|
46099
|
+
this.code = code;
|
|
46100
|
+
this.serviceId = serviceId;
|
|
46101
|
+
}
|
|
46102
|
+
paymentNetworks;
|
|
46103
|
+
name = "DiscoveryCatalogError";
|
|
46104
|
+
code;
|
|
46105
|
+
serviceId;
|
|
46106
|
+
};
|
|
46107
|
+
function isDiscoveryCatalogError(error61) {
|
|
46108
|
+
if (!(error61 instanceof Error) || error61.name !== "DiscoveryCatalogError" || !("code" in error61) || typeof error61.code !== "string") {
|
|
46109
|
+
return false;
|
|
46110
|
+
}
|
|
46111
|
+
const networks = Reflect.get(error61, "paymentNetworks");
|
|
46112
|
+
return networks === void 0 || Array.isArray(networks) && networks.every((network) => typeof network === "string");
|
|
46113
|
+
}
|
|
46114
|
+
function parseDiscovery(raw) {
|
|
46115
|
+
const parsed = discoveryResponseSchema.safeParse(raw);
|
|
46116
|
+
if (!parsed.success) {
|
|
46117
|
+
const malformedUrl = parsed.error.issues.find(
|
|
46118
|
+
(issue2) => issue2.path.at(-1) === "url" && issue2.path.includes("endpoints")
|
|
46119
|
+
);
|
|
46120
|
+
if (malformedUrl) {
|
|
46121
|
+
const serviceIndex = pathIndexAfter(malformedUrl.path, "services");
|
|
46122
|
+
const serviceId = rawServiceId(raw, serviceIndex);
|
|
46123
|
+
throw new DiscoveryCatalogError(
|
|
46124
|
+
"malformed_url",
|
|
46125
|
+
`Service ${JSON.stringify(serviceId ?? "unknown")} has a malformed endpoint URL.`,
|
|
46126
|
+
serviceId
|
|
46127
|
+
);
|
|
46128
|
+
}
|
|
46129
|
+
throw new DiscoveryCatalogError("invalid_discovery", "Discovery response is malformed.");
|
|
46130
|
+
}
|
|
46131
|
+
for (const service of parsed.data.services) {
|
|
46132
|
+
buildTargets(service);
|
|
46133
|
+
}
|
|
46134
|
+
const resolveListing = (serviceId, endpointName) => {
|
|
46135
|
+
const service = parsed.data.services.find((candidate) => candidate.id === serviceId);
|
|
46136
|
+
if (!service) {
|
|
46137
|
+
throw new DiscoveryCatalogError(
|
|
46138
|
+
"service_not_found",
|
|
46139
|
+
`No payable endpoint found for service ${JSON.stringify(serviceId)}.`,
|
|
46140
|
+
serviceId
|
|
46141
|
+
);
|
|
46142
|
+
}
|
|
46143
|
+
return { service, endpoint: resolveTarget(service, endpointName) };
|
|
46144
|
+
};
|
|
46145
|
+
return {
|
|
46146
|
+
services: parsed.data.services,
|
|
46147
|
+
resolve: (serviceId, endpointName) => resolveListing(serviceId, endpointName).endpoint,
|
|
46148
|
+
resolveListing
|
|
46149
|
+
};
|
|
46150
|
+
}
|
|
46151
|
+
function resolveTarget(service, endpointName) {
|
|
46152
|
+
const { targets, targetsByName } = buildTargets(service);
|
|
46153
|
+
if (endpointName !== void 0) {
|
|
46154
|
+
const selected = targetsByName.get(endpointName.trim());
|
|
46155
|
+
if (!selected) {
|
|
46156
|
+
throw new DiscoveryCatalogError(
|
|
46157
|
+
"endpoint_not_found",
|
|
46158
|
+
`Service ${JSON.stringify(service.id)} has no endpoint ${JSON.stringify(endpointName)}. Available endpoints: ${[...targetsByName.keys()].join(", ")}.`,
|
|
46159
|
+
service.id
|
|
46160
|
+
);
|
|
46161
|
+
}
|
|
46162
|
+
return { ...selected };
|
|
46163
|
+
}
|
|
46164
|
+
if (targets.size !== 1) {
|
|
46165
|
+
const paymentNetworks = service.endpoints.flatMap(
|
|
46166
|
+
(endpoint) => typeof endpoint.payment?.network === "string" ? [endpoint.payment.network] : []
|
|
46167
|
+
);
|
|
46168
|
+
throw new DiscoveryCatalogError(
|
|
46169
|
+
"ambiguous_default",
|
|
46170
|
+
`Service ${JSON.stringify(service.id)} has ${targets.size} distinct payable endpoints. Choose one with endpoint: ${[...targetsByName.keys()].join(", ")}.`,
|
|
46171
|
+
service.id,
|
|
46172
|
+
paymentNetworks.length === service.endpoints.length ? paymentNetworks : void 0
|
|
46173
|
+
);
|
|
46174
|
+
}
|
|
46175
|
+
return targets.values().next().value;
|
|
46176
|
+
}
|
|
46177
|
+
function buildTargets(service) {
|
|
46178
|
+
if (service.endpoints.length === 0) {
|
|
46179
|
+
throw new DiscoveryCatalogError(
|
|
46180
|
+
"no_endpoint",
|
|
46181
|
+
`Service ${JSON.stringify(service.id)} has no payable endpoint.`,
|
|
46182
|
+
service.id
|
|
46183
|
+
);
|
|
46184
|
+
}
|
|
46185
|
+
const namedEndpoints = [...service.endpoints].sort(
|
|
46186
|
+
(left, right) => compareNames(left.name.trim(), right.name.trim())
|
|
46187
|
+
);
|
|
46188
|
+
const names = /* @__PURE__ */ new Set();
|
|
46189
|
+
const targets = /* @__PURE__ */ new Map();
|
|
46190
|
+
const targetsByName = /* @__PURE__ */ new Map();
|
|
46191
|
+
for (const endpoint of namedEndpoints) {
|
|
46192
|
+
const name = endpoint.name.trim();
|
|
46193
|
+
if (!name) {
|
|
46194
|
+
throw new DiscoveryCatalogError(
|
|
46195
|
+
"invalid_endpoint_name",
|
|
46196
|
+
`Service ${JSON.stringify(service.id)} has a blank endpoint name.`,
|
|
46197
|
+
service.id
|
|
46198
|
+
);
|
|
46199
|
+
}
|
|
46200
|
+
if (names.has(name)) {
|
|
46201
|
+
throw new DiscoveryCatalogError(
|
|
46202
|
+
"duplicate_endpoint_name",
|
|
46203
|
+
`Service ${JSON.stringify(service.id)} has duplicate endpoint name ${JSON.stringify(name)}.`,
|
|
46204
|
+
service.id
|
|
46205
|
+
);
|
|
46206
|
+
}
|
|
46207
|
+
names.add(name);
|
|
46208
|
+
const method = endpoint.method.trim().toUpperCase();
|
|
46209
|
+
if (!method) {
|
|
46210
|
+
throw new DiscoveryCatalogError(
|
|
46211
|
+
"blank_method",
|
|
46212
|
+
`Service ${JSON.stringify(service.id)} has a blank endpoint method.`,
|
|
46213
|
+
service.id
|
|
46214
|
+
);
|
|
46215
|
+
}
|
|
46216
|
+
const url2 = new URL(endpoint.url);
|
|
46217
|
+
if (url2.protocol !== "http:" && url2.protocol !== "https:") {
|
|
46218
|
+
throw new DiscoveryCatalogError(
|
|
46219
|
+
"malformed_url",
|
|
46220
|
+
`Service ${JSON.stringify(service.id)} has a non-HTTP endpoint URL.`,
|
|
46221
|
+
service.id
|
|
46222
|
+
);
|
|
46223
|
+
}
|
|
46224
|
+
const transportKey = `${method}\0${endpoint.url}`;
|
|
46225
|
+
const normalized = { ...endpoint, name, method };
|
|
46226
|
+
targetsByName.set(name, normalized);
|
|
46227
|
+
if (!targets.has(transportKey)) targets.set(transportKey, normalized);
|
|
46228
|
+
}
|
|
46229
|
+
return { targets, targetsByName };
|
|
46230
|
+
}
|
|
46231
|
+
function compareNames(left, right) {
|
|
46232
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
46233
|
+
}
|
|
46234
|
+
function pathIndexAfter(path, key2) {
|
|
46235
|
+
const keyIndex = path.indexOf(key2);
|
|
46236
|
+
const candidate = path[keyIndex + 1];
|
|
46237
|
+
return typeof candidate === "number" ? candidate : void 0;
|
|
46238
|
+
}
|
|
46239
|
+
function rawServiceId(raw, serviceIndex) {
|
|
46240
|
+
if (serviceIndex === void 0 || typeof raw !== "object" || raw === null) {
|
|
46241
|
+
return void 0;
|
|
46242
|
+
}
|
|
46243
|
+
const services = Reflect.get(raw, "services");
|
|
46244
|
+
if (!Array.isArray(services)) {
|
|
46245
|
+
return void 0;
|
|
46246
|
+
}
|
|
46247
|
+
const service = services[serviceIndex];
|
|
46248
|
+
if (typeof service !== "object" || service === null) {
|
|
46249
|
+
return void 0;
|
|
46250
|
+
}
|
|
46251
|
+
const id2 = Reflect.get(service, "id");
|
|
46252
|
+
return typeof id2 === "string" ? id2 : void 0;
|
|
46253
|
+
}
|
|
46254
|
+
|
|
46188
46255
|
// ../core/src/sweep.ts
|
|
46189
46256
|
var ERC20_ABI = [
|
|
46190
46257
|
{
|
|
@@ -47033,7 +47100,7 @@ var configSchema = external_exports.object({
|
|
|
47033
47100
|
}
|
|
47034
47101
|
for (const [network, configured] of Object.entries(config2.networks)) {
|
|
47035
47102
|
if (isSolanaNetwork(network)) {
|
|
47036
|
-
if (configured.usdc !==
|
|
47103
|
+
if (configured.usdc !== NETWORKS2[SOLANA_MAINNET_CAIP2].usdc) {
|
|
47037
47104
|
context.addIssue({
|
|
47038
47105
|
code: "custom",
|
|
47039
47106
|
path: ["networks", network, "usdc"],
|
|
@@ -47044,7 +47111,7 @@ var configSchema = external_exports.object({
|
|
|
47044
47111
|
}
|
|
47045
47112
|
try {
|
|
47046
47113
|
const usdc = getAddress(configured.usdc);
|
|
47047
|
-
if ((network === ARC_MAINNET_CAIP2 || network === ARC_TESTNET_CAIP2) && usdc !== getAddress(
|
|
47114
|
+
if ((network === ARC_MAINNET_CAIP2 || network === ARC_TESTNET_CAIP2) && usdc !== getAddress(NETWORKS2[network].usdc)) {
|
|
47048
47115
|
context.addIssue({
|
|
47049
47116
|
code: "custom",
|
|
47050
47117
|
path: ["networks", network, "usdc"],
|
|
@@ -47071,7 +47138,8 @@ function getVapiPaths(directory = process.env.VAPI_HOME?.trim() || join2(homedir
|
|
|
47071
47138
|
keystore: join2(directory, "keystore.json"),
|
|
47072
47139
|
receipts: join2(directory, "receipts.jsonl"),
|
|
47073
47140
|
searches: join2(directory, "searches.jsonl"),
|
|
47074
|
-
ledger: join2(directory, "spend-ledger.json")
|
|
47141
|
+
ledger: join2(directory, "spend-ledger.json"),
|
|
47142
|
+
updateCheck: join2(directory, "update-check.json")
|
|
47075
47143
|
};
|
|
47076
47144
|
}
|
|
47077
47145
|
var getAgentCashPaths = getVapiPaths;
|
|
@@ -47196,15 +47264,15 @@ function getDefaultConfig(source = process.env, options = {}) {
|
|
|
47196
47264
|
const tasksEscrowFactoryOverrides = tasksFactoryOverridesFromEnv(source);
|
|
47197
47265
|
if (requested.has("base") || requested.has(BASE_MAINNET_CAIP2)) {
|
|
47198
47266
|
networks[BASE_MAINNET_CAIP2] = {
|
|
47199
|
-
rpcUrl: source.BASE_RPC_URL?.trim() ||
|
|
47200
|
-
usdc:
|
|
47267
|
+
rpcUrl: source.BASE_RPC_URL?.trim() || NETWORKS2[BASE_MAINNET_CAIP2].publicRpcUrl,
|
|
47268
|
+
usdc: NETWORKS2[BASE_MAINNET_CAIP2].usdc
|
|
47201
47269
|
};
|
|
47202
47270
|
}
|
|
47203
47271
|
const arcMainnetRpcUrl = source.ARC_RPC_URL?.trim();
|
|
47204
47272
|
if (arcMainnetRpcUrl || requested.has("arc") || requested.has(ARC_MAINNET_CAIP2)) {
|
|
47205
47273
|
networks[ARC_MAINNET_CAIP2] = {
|
|
47206
|
-
rpcUrl: arcMainnetRpcUrl ||
|
|
47207
|
-
usdc:
|
|
47274
|
+
rpcUrl: arcMainnetRpcUrl || NETWORKS2[ARC_MAINNET_CAIP2].publicRpcUrl,
|
|
47275
|
+
usdc: NETWORKS2[ARC_MAINNET_CAIP2].usdc
|
|
47208
47276
|
};
|
|
47209
47277
|
}
|
|
47210
47278
|
const arcTestnetRpcUrl = source.ARC_TESTNET_RPC_URL?.trim();
|
|
@@ -47216,14 +47284,14 @@ function getDefaultConfig(source = process.env, options = {}) {
|
|
|
47216
47284
|
}
|
|
47217
47285
|
networks[ARC_TESTNET_CAIP2] = {
|
|
47218
47286
|
rpcUrl: arcTestnetRpcUrl,
|
|
47219
|
-
usdc:
|
|
47287
|
+
usdc: NETWORKS2[ARC_TESTNET_CAIP2].usdc
|
|
47220
47288
|
};
|
|
47221
47289
|
}
|
|
47222
47290
|
const solanaRpcUrl = source.SOLANA_RPC_URL?.trim();
|
|
47223
47291
|
if (solanaRpcUrl || requested.has("solana") || requested.has(SOLANA_MAINNET_CAIP2)) {
|
|
47224
47292
|
networks[SOLANA_MAINNET_CAIP2] = {
|
|
47225
|
-
rpcUrl: solanaRpcUrl ||
|
|
47226
|
-
usdc:
|
|
47293
|
+
rpcUrl: solanaRpcUrl || NETWORKS2[SOLANA_MAINNET_CAIP2].publicRpcUrl,
|
|
47294
|
+
usdc: NETWORKS2[SOLANA_MAINNET_CAIP2].usdc
|
|
47227
47295
|
};
|
|
47228
47296
|
}
|
|
47229
47297
|
return {
|
|
@@ -47281,21 +47349,21 @@ Run vapi init to write the new URLs to ${path}.`
|
|
|
47281
47349
|
if (arcMainnetRpcUrl) {
|
|
47282
47350
|
const existing = config2.networks[ARC_MAINNET_CAIP2];
|
|
47283
47351
|
config2.networks[ARC_MAINNET_CAIP2] = {
|
|
47284
|
-
...existing ?? { usdc:
|
|
47352
|
+
...existing ?? { usdc: NETWORKS2[ARC_MAINNET_CAIP2].usdc },
|
|
47285
47353
|
rpcUrl: arcMainnetRpcUrl
|
|
47286
47354
|
};
|
|
47287
47355
|
}
|
|
47288
47356
|
if (arcTestnetRpcUrl) {
|
|
47289
47357
|
const existing = config2.networks[ARC_TESTNET_CAIP2];
|
|
47290
47358
|
config2.networks[ARC_TESTNET_CAIP2] = {
|
|
47291
|
-
...existing ?? { usdc:
|
|
47359
|
+
...existing ?? { usdc: NETWORKS2[ARC_TESTNET_CAIP2].usdc },
|
|
47292
47360
|
rpcUrl: arcTestnetRpcUrl
|
|
47293
47361
|
};
|
|
47294
47362
|
}
|
|
47295
47363
|
if (solanaRpcUrl) {
|
|
47296
47364
|
config2.networks[SOLANA_MAINNET_CAIP2] = {
|
|
47297
47365
|
rpcUrl: solanaRpcUrl,
|
|
47298
|
-
usdc: config2.networks[SOLANA_MAINNET_CAIP2]?.usdc ??
|
|
47366
|
+
usdc: config2.networks[SOLANA_MAINNET_CAIP2]?.usdc ?? NETWORKS2[SOLANA_MAINNET_CAIP2].usdc
|
|
47299
47367
|
};
|
|
47300
47368
|
}
|
|
47301
47369
|
if (registryUrl) {
|
|
@@ -47308,7 +47376,7 @@ Run vapi init to write the new URLs to ${path}.`
|
|
|
47308
47376
|
for (const [network, configured] of Object.entries(config2.networks)) {
|
|
47309
47377
|
configured.rpcUrl = configured.rpcUrl.trim();
|
|
47310
47378
|
configured.usdc = configured.usdc.trim();
|
|
47311
|
-
if (isSolanaNetwork(network) && configured.usdc !==
|
|
47379
|
+
if (isSolanaNetwork(network) && configured.usdc !== NETWORKS2[SOLANA_MAINNET_CAIP2].usdc) {
|
|
47312
47380
|
throw new Error(`Network ${network} must use canonical Solana mainnet USDC.`);
|
|
47313
47381
|
}
|
|
47314
47382
|
if (!configured.rpcUrl) delete config2.networks[network];
|
|
@@ -47364,14 +47432,14 @@ async function enableDefaultNetwork(network, path = getVapiPaths().config, sourc
|
|
|
47364
47432
|
const config2 = await loadConfig(path, source);
|
|
47365
47433
|
if (network === "solana") {
|
|
47366
47434
|
config2.networks[SOLANA_MAINNET_CAIP2] = {
|
|
47367
|
-
rpcUrl: source.SOLANA_RPC_URL?.trim() ||
|
|
47368
|
-
usdc:
|
|
47435
|
+
rpcUrl: source.SOLANA_RPC_URL?.trim() || NETWORKS2[SOLANA_MAINNET_CAIP2].publicRpcUrl,
|
|
47436
|
+
usdc: NETWORKS2[SOLANA_MAINNET_CAIP2].usdc
|
|
47369
47437
|
};
|
|
47370
47438
|
} else {
|
|
47371
47439
|
const existing = config2.networks[ARC_MAINNET_CAIP2];
|
|
47372
47440
|
config2.networks[ARC_MAINNET_CAIP2] = {
|
|
47373
|
-
...existing ?? { usdc:
|
|
47374
|
-
rpcUrl: source.ARC_RPC_URL?.trim() ||
|
|
47441
|
+
...existing ?? { usdc: NETWORKS2[ARC_MAINNET_CAIP2].usdc },
|
|
47442
|
+
rpcUrl: source.ARC_RPC_URL?.trim() || NETWORKS2[ARC_MAINNET_CAIP2].publicRpcUrl
|
|
47375
47443
|
};
|
|
47376
47444
|
}
|
|
47377
47445
|
await writeConfigFile(path, config2);
|
|
@@ -70335,7 +70403,7 @@ function windowsDataProtectionStore(platform2, run, env, installed) {
|
|
|
70335
70403
|
};
|
|
70336
70404
|
}
|
|
70337
70405
|
function libsecretStore(platform2, run, installed) {
|
|
70338
|
-
const
|
|
70406
|
+
const lookup2 = async (name) => {
|
|
70339
70407
|
const result = await run(SECRET_TOOL_BINARY, [
|
|
70340
70408
|
"lookup",
|
|
70341
70409
|
"service",
|
|
@@ -70354,9 +70422,9 @@ function libsecretStore(platform2, run, installed) {
|
|
|
70354
70422
|
available: installed(SECRET_TOOL_BINARY),
|
|
70355
70423
|
platform: platform2,
|
|
70356
70424
|
description: "the libsecret keyring",
|
|
70357
|
-
get:
|
|
70425
|
+
get: lookup2,
|
|
70358
70426
|
async has(name) {
|
|
70359
|
-
return await
|
|
70427
|
+
return await lookup2(name) !== void 0;
|
|
70360
70428
|
},
|
|
70361
70429
|
async set(name, passphrase) {
|
|
70362
70430
|
requirePassphrase(passphrase);
|
|
@@ -70378,7 +70446,7 @@ function libsecretStore(platform2, run, installed) {
|
|
|
70378
70446
|
requireSuccess(result, `store the passphrase of ${name} in the secret service`);
|
|
70379
70447
|
},
|
|
70380
70448
|
async remove(name) {
|
|
70381
|
-
const existed = await
|
|
70449
|
+
const existed = await lookup2(name) !== void 0;
|
|
70382
70450
|
const result = await run(SECRET_TOOL_BINARY, [
|
|
70383
70451
|
"clear",
|
|
70384
70452
|
"service",
|
|
@@ -71441,6 +71509,8 @@ var VAULT_KEY_ACCOUNT = "vault-key";
|
|
|
71441
71509
|
var VAULT_SESSION_ACCOUNT = "vault-session";
|
|
71442
71510
|
var DEVICE_KEY_LENGTH = 32;
|
|
71443
71511
|
var DEFAULT_SESSION_HOURS = 8;
|
|
71512
|
+
var RESTORE_GAP_LIMIT = 5;
|
|
71513
|
+
var MAX_RESTORE_ACCOUNTS = 1e4;
|
|
71444
71514
|
var BASE64_PATTERN = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u;
|
|
71445
71515
|
var deviceKeyOperations = Promise.resolve();
|
|
71446
71516
|
var sessionSchema = external_exports.object({
|
|
@@ -71590,26 +71660,41 @@ async function restoreVault(args) {
|
|
|
71590
71660
|
throw new VaultError("corrupt", "That recovery phrase is not valid.", { cause: error61 });
|
|
71591
71661
|
}
|
|
71592
71662
|
let seed;
|
|
71593
|
-
|
|
71663
|
+
if (args.accountCount !== void 0 && (!Number.isSafeInteger(args.accountCount) || args.accountCount < 1 || args.accountCount > MAX_RESTORE_ACCOUNTS)) {
|
|
71664
|
+
throw new VaultError(
|
|
71665
|
+
"corrupt",
|
|
71666
|
+
`Account count must be a positive integer no greater than ${MAX_RESTORE_ACCOUNTS}.`
|
|
71667
|
+
);
|
|
71668
|
+
}
|
|
71669
|
+
let discoveredAccounts = args.accountCount ?? 0;
|
|
71670
|
+
let scannedAddresses = 0;
|
|
71594
71671
|
try {
|
|
71595
71672
|
seed = phraseToSeed(phrase);
|
|
71596
71673
|
} catch (error61) {
|
|
71597
71674
|
throw asVaultError2(error61, "Unable to derive an account while restoring the vault.");
|
|
71598
71675
|
}
|
|
71599
71676
|
try {
|
|
71600
|
-
for (let index2 = 0; ; index2 += 1) {
|
|
71677
|
+
for (let index2 = 0, emptyRun = 0; args.accountCount === void 0; index2 += 1) {
|
|
71601
71678
|
let address4;
|
|
71602
71679
|
try {
|
|
71603
71680
|
address4 = privateKeyToAccount(deriveEvmPrivateKey(seed, `m/44'/60'/0'/0/${index2}`)).address;
|
|
71604
71681
|
} catch (error61) {
|
|
71605
71682
|
throw asVaultError2(error61, "Unable to derive an account while restoring the vault.");
|
|
71606
71683
|
}
|
|
71607
|
-
|
|
71608
|
-
|
|
71684
|
+
const funded = await args.probe(address4);
|
|
71685
|
+
scannedAddresses += 1;
|
|
71686
|
+
if (funded) {
|
|
71687
|
+
discoveredAccounts = index2 + 1;
|
|
71688
|
+
emptyRun = 0;
|
|
71689
|
+
} else {
|
|
71690
|
+
emptyRun += 1;
|
|
71691
|
+
if (emptyRun === RESTORE_GAP_LIMIT) break;
|
|
71692
|
+
}
|
|
71609
71693
|
}
|
|
71610
71694
|
} finally {
|
|
71611
71695
|
seed.fill(0);
|
|
71612
71696
|
}
|
|
71697
|
+
args.onScanComplete?.(scannedAddresses);
|
|
71613
71698
|
let vault;
|
|
71614
71699
|
try {
|
|
71615
71700
|
vault = await createVault({ path: args.path, key: args.key, phrase, now: args.now });
|
|
@@ -72098,6 +72183,26 @@ var WalletStore = class _WalletStore {
|
|
|
72098
72183
|
}
|
|
72099
72184
|
);
|
|
72100
72185
|
}
|
|
72186
|
+
/** Checks a cached signer's current vault session without decrypting its account again. */
|
|
72187
|
+
async assertSigningAuthority(name) {
|
|
72188
|
+
const stored = await this.readVaultUnlocked();
|
|
72189
|
+
if (!stored?.protected || !stored.accounts.some((account) => account.name === name)) return;
|
|
72190
|
+
try {
|
|
72191
|
+
const key2 = await unlockProtectedVault({
|
|
72192
|
+
path: this.vaultPath,
|
|
72193
|
+
secrets: this.secrets,
|
|
72194
|
+
env: this.environment,
|
|
72195
|
+
now: () => this.now()
|
|
72196
|
+
});
|
|
72197
|
+
key2.fill(0);
|
|
72198
|
+
} catch (error61) {
|
|
72199
|
+
this.dropVaultCache();
|
|
72200
|
+
if (error61 instanceof VaultError && error61.code === "password_required") {
|
|
72201
|
+
throw new KeystoreError(VAULT_LOCKED_MESSAGE, { cause: error61 });
|
|
72202
|
+
}
|
|
72203
|
+
throw error61;
|
|
72204
|
+
}
|
|
72205
|
+
}
|
|
72101
72206
|
/** Returns one wallet's vault signer, migrating its legacy keystore if needed. */
|
|
72102
72207
|
async unlock(name, passphrase) {
|
|
72103
72208
|
const wallet = this.resolve({ name });
|
|
@@ -77484,7 +77589,7 @@ function createRunBudget(args) {
|
|
|
77484
77589
|
import { mkdir as mkdir15, writeFile as writeFile8 } from "node:fs/promises";
|
|
77485
77590
|
import { arch, platform, release } from "node:os";
|
|
77486
77591
|
import { join as join13 } from "node:path";
|
|
77487
|
-
var VAPI_CLIENT_VERSION = "0.9.
|
|
77592
|
+
var VAPI_CLIENT_VERSION = "0.9.4";
|
|
77488
77593
|
async function createSupportReport(options) {
|
|
77489
77594
|
const message = options.message.trim();
|
|
77490
77595
|
if (!message) throw new Error("Support report message must not be empty.");
|
|
@@ -77757,7 +77862,7 @@ async function completeX402Payment(args) {
|
|
|
77757
77862
|
let paidAttempt;
|
|
77758
77863
|
const requestStarted = nowMs();
|
|
77759
77864
|
try {
|
|
77760
|
-
paidAttempt = await args.send(paidRequest);
|
|
77865
|
+
paidAttempt = await args.send(paidRequest, quote);
|
|
77761
77866
|
} catch (error61) {
|
|
77762
77867
|
if (trace) trace.phases.requestMs = elapsed(nowMs, requestStarted);
|
|
77763
77868
|
throw settlementUnknown(
|
|
@@ -77775,7 +77880,7 @@ async function completeX402Payment(args) {
|
|
|
77775
77880
|
const settleStarted = nowMs();
|
|
77776
77881
|
const settlement = parseSettlementResponse(paidResponse.headers);
|
|
77777
77882
|
const settlementOutcome = classifySettlement(settlement);
|
|
77778
|
-
const receiptSettlement =
|
|
77883
|
+
const receiptSettlement = sanitizeReturnedValue(settlement, receiptSecrets);
|
|
77779
77884
|
if (trace) {
|
|
77780
77885
|
const transaction2 = settlementTransaction(receiptSettlement);
|
|
77781
77886
|
const explorerUrl = transaction2 ? explorerTransactionUrl(quote.accepted.network, transaction2) : void 0;
|
|
@@ -77852,6 +77957,7 @@ async function completeX402Payment(args) {
|
|
|
77852
77957
|
trace.phases.requestMs = (trace.phases.requestMs ?? 0) + elapsed(nowMs, bodyStarted);
|
|
77853
77958
|
}
|
|
77854
77959
|
}
|
|
77960
|
+
body = sanitizeReturnedValue(body, receiptSecrets);
|
|
77855
77961
|
}
|
|
77856
77962
|
const result = {
|
|
77857
77963
|
response: paidResponse,
|
|
@@ -77860,7 +77966,11 @@ async function completeX402Payment(args) {
|
|
|
77860
77966
|
quote,
|
|
77861
77967
|
payer,
|
|
77862
77968
|
...payment.paymentId ? { paymentId: payment.paymentId } : {},
|
|
77863
|
-
|
|
77969
|
+
paymentProof: sanitizeReturnedValue(
|
|
77970
|
+
paidResponse.headers.get("x-vapi-payment-proof"),
|
|
77971
|
+
receiptSecrets
|
|
77972
|
+
),
|
|
77973
|
+
settlement: receiptSettlement,
|
|
77864
77974
|
settlementOutcome
|
|
77865
77975
|
};
|
|
77866
77976
|
if (settlementOutcome === "succeeded" && args.ceilingSweep) {
|
|
@@ -77997,19 +78107,70 @@ function sanitizeThrownError(error61, secrets) {
|
|
|
77997
78107
|
}
|
|
77998
78108
|
return new Error(message, cause === void 0 ? void 0 : { cause });
|
|
77999
78109
|
}
|
|
78000
|
-
function
|
|
78110
|
+
function sanitizeReturnedValue(value, secrets) {
|
|
78001
78111
|
if (typeof value === "string") return redactKnownSecrets(value, secrets);
|
|
78002
|
-
if (value
|
|
78003
|
-
|
|
78004
|
-
|
|
78005
|
-
|
|
78112
|
+
if (!isPlainReturnedContainer(value)) return value;
|
|
78113
|
+
const nodes = /* @__PURE__ */ new WeakMap();
|
|
78114
|
+
const ordered = [];
|
|
78115
|
+
const nodeFor = (source) => {
|
|
78116
|
+
const existing = nodes.get(source);
|
|
78117
|
+
if (existing) return existing;
|
|
78118
|
+
const copy = Array.isArray(source) ? new Array(source.length) : Object.create(Object.getPrototypeOf(source));
|
|
78119
|
+
const node2 = { source, copy, parents: /* @__PURE__ */ new Set(), changed: false };
|
|
78120
|
+
nodes.set(source, node2);
|
|
78121
|
+
ordered.push(node2);
|
|
78122
|
+
return node2;
|
|
78123
|
+
};
|
|
78124
|
+
const root = nodeFor(value);
|
|
78125
|
+
for (let index2 = 0; index2 < ordered.length; index2 += 1) {
|
|
78126
|
+
const node2 = ordered[index2];
|
|
78127
|
+
for (const [key2, item] of Object.entries(node2.source)) {
|
|
78128
|
+
const safeKey = Array.isArray(node2.source) ? key2 : redactKnownSecrets(key2, secrets);
|
|
78129
|
+
if (safeKey !== key2) node2.changed = true;
|
|
78130
|
+
if (typeof item === "string") {
|
|
78131
|
+
const safeItem = redactKnownSecrets(item, secrets);
|
|
78132
|
+
defineReturnedProperty(node2.copy, safeKey, safeItem);
|
|
78133
|
+
if (safeItem !== item) node2.changed = true;
|
|
78134
|
+
} else if (isPlainReturnedContainer(item)) {
|
|
78135
|
+
const child = nodeFor(item);
|
|
78136
|
+
child.parents.add(node2);
|
|
78137
|
+
defineReturnedProperty(node2.copy, safeKey, child.copy);
|
|
78138
|
+
} else {
|
|
78139
|
+
defineReturnedProperty(node2.copy, safeKey, item);
|
|
78140
|
+
}
|
|
78141
|
+
}
|
|
78006
78142
|
}
|
|
78007
|
-
|
|
78008
|
-
|
|
78009
|
-
|
|
78010
|
-
|
|
78011
|
-
|
|
78012
|
-
|
|
78143
|
+
const changed = ordered.filter((node2) => node2.changed);
|
|
78144
|
+
for (let index2 = 0; index2 < changed.length; index2 += 1) {
|
|
78145
|
+
for (const parent of changed[index2].parents) {
|
|
78146
|
+
if (parent.changed) continue;
|
|
78147
|
+
parent.changed = true;
|
|
78148
|
+
changed.push(parent);
|
|
78149
|
+
}
|
|
78150
|
+
}
|
|
78151
|
+
for (const node2 of ordered) {
|
|
78152
|
+
for (const [key2, item] of Object.entries(node2.source)) {
|
|
78153
|
+
if (!isPlainReturnedContainer(item)) continue;
|
|
78154
|
+
const safeKey = Array.isArray(node2.source) ? key2 : redactKnownSecrets(key2, secrets);
|
|
78155
|
+
const child = nodes.get(item);
|
|
78156
|
+
defineReturnedProperty(node2.copy, safeKey, child.changed ? child.copy : item);
|
|
78157
|
+
}
|
|
78158
|
+
}
|
|
78159
|
+
return root.changed ? root.copy : value;
|
|
78160
|
+
}
|
|
78161
|
+
function defineReturnedProperty(target, key2, value) {
|
|
78162
|
+
Object.defineProperty(target, key2, {
|
|
78163
|
+
value,
|
|
78164
|
+
enumerable: true,
|
|
78165
|
+
configurable: true,
|
|
78166
|
+
writable: true
|
|
78167
|
+
});
|
|
78168
|
+
}
|
|
78169
|
+
function isPlainReturnedContainer(value) {
|
|
78170
|
+
if (Array.isArray(value)) return true;
|
|
78171
|
+
if (value === null || typeof value !== "object") return false;
|
|
78172
|
+
const prototype = Object.getPrototypeOf(value);
|
|
78173
|
+
return prototype === Object.prototype || prototype === null;
|
|
78013
78174
|
}
|
|
78014
78175
|
function redactKnownSecrets(value, secrets) {
|
|
78015
78176
|
let redacted = value;
|
|
@@ -78044,9 +78205,7 @@ function possibleSettlement(quote, payment, payer, receipt) {
|
|
|
78044
78205
|
payTo: quote.accepted.payTo,
|
|
78045
78206
|
payer,
|
|
78046
78207
|
...payment.paymentId ? { paymentId: payment.paymentId } : {},
|
|
78047
|
-
...isSvmPaymentRequirements(quote.accepted) ? {
|
|
78048
|
-
authorizationTransaction: "transaction" in payment.payload.payload ? payment.payload.payload.transaction : ""
|
|
78049
|
-
} : "authorization" in payment.payload.payload ? {
|
|
78208
|
+
...isSvmPaymentRequirements(quote.accepted) ? {} : "authorization" in payment.payload.payload ? {
|
|
78050
78209
|
authorizationNonce: payment.payload.payload.authorization.nonce,
|
|
78051
78210
|
authorizationExpiresAt: payment.payload.payload.authorization.validBefore
|
|
78052
78211
|
} : {},
|
|
@@ -78424,13 +78583,22 @@ async function sendRouterChat(deps, routerBaseUrl, routerKey, request, keyUsed)
|
|
|
78424
78583
|
}
|
|
78425
78584
|
const body = await responseText(response);
|
|
78426
78585
|
if (!response.ok) {
|
|
78427
|
-
if (
|
|
78586
|
+
if (/budget (?:has been )?exceeded|exceededbudget/iu.test(body)) {
|
|
78428
78587
|
throw new RouterClientError(
|
|
78429
78588
|
"budget_exhausted",
|
|
78430
78589
|
"The Router key has no remaining budget.",
|
|
78431
78590
|
response.status
|
|
78432
78591
|
);
|
|
78433
78592
|
}
|
|
78593
|
+
if (response.status === 429) {
|
|
78594
|
+
const retryAfter = response.headers.get("retry-after")?.trim();
|
|
78595
|
+
const retrySeconds = retryAfter !== void 0 && /^\d+$/u.test(retryAfter) ? Number(retryAfter) : void 0;
|
|
78596
|
+
throw new RouterClientError(
|
|
78597
|
+
"rate_limited",
|
|
78598
|
+
`The vAPI Router is rate limited. ${retrySeconds !== void 0 && Number.isFinite(retrySeconds) ? `Retry after ${retrySeconds} seconds.` : "Wait and retry shortly."}`,
|
|
78599
|
+
response.status
|
|
78600
|
+
);
|
|
78601
|
+
}
|
|
78434
78602
|
if (response.status === 401) {
|
|
78435
78603
|
throw new RouterClientError(
|
|
78436
78604
|
"no_router_key",
|
|
@@ -78997,6 +79165,7 @@ var missingTasksChain = {
|
|
|
78997
79165
|
|
|
78998
79166
|
// ../core/src/tasks/types.ts
|
|
78999
79167
|
var uuidSchema = external_exports.uuid();
|
|
79168
|
+
var profileIdSchema = external_exports.string().min(1).max(64).regex(/^[A-Za-z0-9_-]+$/);
|
|
79000
79169
|
var isoDateTimeSchema = external_exports.iso.datetime();
|
|
79001
79170
|
var addressSchema5 = external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/).transform((value) => value.toLowerCase());
|
|
79002
79171
|
var bytes32Schema = external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/).transform((value) => value.toLowerCase());
|
|
@@ -79334,7 +79503,7 @@ var deliveryResponseSchema = external_exports.looseObject({
|
|
|
79334
79503
|
version: external_exports.number().int().positive(),
|
|
79335
79504
|
manifest: manifestResponseSchema,
|
|
79336
79505
|
manifestHash: bytes32Schema,
|
|
79337
|
-
submittedByProfileId:
|
|
79506
|
+
submittedByProfileId: profileIdSchema,
|
|
79338
79507
|
createdAt: isoDateTimeSchema
|
|
79339
79508
|
});
|
|
79340
79509
|
var orderDeliveryResponseSchema = external_exports.looseObject({
|
|
@@ -79440,7 +79609,7 @@ var reviewResponseSchema = external_exports.looseObject({
|
|
|
79440
79609
|
id: uuidSchema,
|
|
79441
79610
|
workOrderId: uuidSchema,
|
|
79442
79611
|
clientAddress: addressSchema5,
|
|
79443
|
-
vendorProfileId:
|
|
79612
|
+
vendorProfileId: profileIdSchema,
|
|
79444
79613
|
rating: external_exports.number().int().min(1).max(5),
|
|
79445
79614
|
body: external_exports.string(),
|
|
79446
79615
|
subRatings: external_exports.json().nullable(),
|
|
@@ -79983,12 +80152,15 @@ function createTasksClient(options) {
|
|
|
79983
80152
|
const parsed2 = serverErrorSchema.safeParse(errorBody);
|
|
79984
80153
|
const server = parsed2.success ? parsed2.data : void 0;
|
|
79985
80154
|
const nested = typeof server?.error === "object" ? server.error : void 0;
|
|
79986
|
-
const
|
|
80155
|
+
const serverCode = nested?.code ?? server?.code;
|
|
80156
|
+
const serverMessage = (typeof server?.error === "string" ? server.error : nested?.message) || server?.message;
|
|
80157
|
+
const fallback = response.statusText || `HTTP ${response.status}`;
|
|
80158
|
+
const message = response.status === 401 || response.status === 403 ? serverCode ?? fallback : serverMessage || (errorBody === void 0 && raw.trim() ? raw.replace(/\s+/gu, " ").trim().slice(0, 300) : fallback);
|
|
79987
80159
|
throw new TasksClientError(
|
|
79988
80160
|
"http",
|
|
79989
80161
|
message,
|
|
79990
80162
|
response.status,
|
|
79991
|
-
|
|
80163
|
+
serverCode,
|
|
79992
80164
|
response.headers.get("Retry-After") ?? void 0
|
|
79993
80165
|
);
|
|
79994
80166
|
}
|
|
@@ -80391,9 +80563,10 @@ function safeTasksChainError(cause, broadcast, authorizationExposed, txHash) {
|
|
|
80391
80563
|
let message = "Task chain operation failed.";
|
|
80392
80564
|
if (cause instanceof TasksValidationError || cause instanceof TasksChainError)
|
|
80393
80565
|
message = cause.message;
|
|
80394
|
-
else if (cause instanceof TasksClientError)
|
|
80395
|
-
|
|
80396
|
-
|
|
80566
|
+
else if (cause instanceof TasksClientError) {
|
|
80567
|
+
const code = cause.serverCode ?? (cause.status ? `http_${cause.status}` : cause.code);
|
|
80568
|
+
message = cause.status === 401 || cause.status === 403 ? `${code} (status ${cause.status})` : `${code}: ${cause.message}`;
|
|
80569
|
+
} else if (cause instanceof Error) {
|
|
80397
80570
|
const short = "shortMessage" in cause && typeof cause.shortMessage === "string" ? cause.shortMessage : void 0;
|
|
80398
80571
|
let statusCode;
|
|
80399
80572
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -81201,6 +81374,44 @@ function createTasksChain(options) {
|
|
|
81201
81374
|
return idempotencyKey;
|
|
81202
81375
|
});
|
|
81203
81376
|
}
|
|
81377
|
+
async function prepareOrResume(prepare, expected, idempotencyKey, kind, steps, authorizationExposed = false, beforeSign) {
|
|
81378
|
+
let prepared;
|
|
81379
|
+
let resumedFromServer = false;
|
|
81380
|
+
try {
|
|
81381
|
+
prepared = await prepare();
|
|
81382
|
+
} catch (error61) {
|
|
81383
|
+
if (!uncertainPreparation(error61)) throw error61;
|
|
81384
|
+
const fresh = await order(expected.milestone.workOrderId);
|
|
81385
|
+
const matches = fresh.milestones.filter((item) => item.id === expected.milestone.id);
|
|
81386
|
+
if (matches.length !== 1 || matches[0].workOrderId !== fresh.id)
|
|
81387
|
+
throw new TasksValidationError("The task milestone does not match its parent order.");
|
|
81388
|
+
const selected = matches[0];
|
|
81389
|
+
const operation = selected.chainOperation;
|
|
81390
|
+
if (expected.verb === "deliver" && selected.delivery && !operation)
|
|
81391
|
+
throw new TasksValidationError(
|
|
81392
|
+
"The server recorded this delivery but has no chain operation for it; open the task in the console to continue."
|
|
81393
|
+
);
|
|
81394
|
+
if (!operation || operation.kind !== kind || !(typeof steps === "string" ? [steps] : steps).includes(operation.step) || !["prepared", "submitted", "confirmed"].includes(operation.state))
|
|
81395
|
+
throw error61;
|
|
81396
|
+
if (expected.verb === "deliver" && selected.delivery && selected.delivery.manifestHash !== expected.manifestHash)
|
|
81397
|
+
throw new TasksValidationError(
|
|
81398
|
+
"The server recorded a different delivery manifest; refusing to continue."
|
|
81399
|
+
);
|
|
81400
|
+
prepared = {
|
|
81401
|
+
operation,
|
|
81402
|
+
milestone: { id: selected.id, workOrderId: selected.workOrderId }
|
|
81403
|
+
};
|
|
81404
|
+
resumedFromServer = true;
|
|
81405
|
+
}
|
|
81406
|
+
const result = await execute(
|
|
81407
|
+
prepared,
|
|
81408
|
+
expected,
|
|
81409
|
+
idempotencyKey,
|
|
81410
|
+
authorizationExposed,
|
|
81411
|
+
beforeSign
|
|
81412
|
+
);
|
|
81413
|
+
return resumedFromServer ? { ...result, resumedFromServer: true } : result;
|
|
81414
|
+
}
|
|
81204
81415
|
async function verifyReceipt(operation, expected, hash5) {
|
|
81205
81416
|
const rpc = rpcFor(expected.deployment.chainId);
|
|
81206
81417
|
const receipt = await rpc.waitForTransactionReceipt({ hash: hash5, confirmations });
|
|
@@ -81242,6 +81453,7 @@ function createTasksChain(options) {
|
|
|
81242
81453
|
throw new TasksValidationError(
|
|
81243
81454
|
"The RPC transaction input does not match the verified task plan."
|
|
81244
81455
|
);
|
|
81456
|
+
return receipt.blockNumber.toString();
|
|
81245
81457
|
}
|
|
81246
81458
|
async function retryConflict(call2) {
|
|
81247
81459
|
let waited = 0;
|
|
@@ -81269,6 +81481,7 @@ function createTasksChain(options) {
|
|
|
81269
81481
|
current = { ...initial, operation: live };
|
|
81270
81482
|
let broadcast = current.operation.state === "submitted";
|
|
81271
81483
|
let txHash = current.operation.transactionHash ?? void 0;
|
|
81484
|
+
let blockNumber;
|
|
81272
81485
|
const operationId = initial.operation.id;
|
|
81273
81486
|
function checkTransition(previous, next) {
|
|
81274
81487
|
if (previous !== next && !(previous === "approve-usdc" && next === afterApproval))
|
|
@@ -81304,7 +81517,7 @@ function createTasksChain(options) {
|
|
|
81304
81517
|
if (!operation.transactionHash)
|
|
81305
81518
|
throw new TasksValidationError("The confirmed task operation has no transaction hash.");
|
|
81306
81519
|
if (!checkpoint) {
|
|
81307
|
-
await verifyReceipt(operation, expected, operation.transactionHash);
|
|
81520
|
+
blockNumber = await verifyReceipt(operation, expected, operation.transactionHash);
|
|
81308
81521
|
await pending.complete(operation.id, operation.step, current);
|
|
81309
81522
|
}
|
|
81310
81523
|
const fresh = await order(expected.milestone.workOrderId);
|
|
@@ -81313,7 +81526,12 @@ function createTasksChain(options) {
|
|
|
81313
81526
|
);
|
|
81314
81527
|
if (!resultMilestone)
|
|
81315
81528
|
throw new TasksValidationError("The reconciled task milestone is unavailable.");
|
|
81316
|
-
return {
|
|
81529
|
+
return {
|
|
81530
|
+
txHash: operation.transactionHash,
|
|
81531
|
+
operation,
|
|
81532
|
+
milestone: resultMilestone,
|
|
81533
|
+
blockNumber
|
|
81534
|
+
};
|
|
81317
81535
|
}
|
|
81318
81536
|
const rpc = rpcFor(expected.deployment.chainId);
|
|
81319
81537
|
if (operation.state === "prepared") {
|
|
@@ -81509,7 +81727,7 @@ function createTasksChain(options) {
|
|
|
81509
81727
|
}
|
|
81510
81728
|
if (operation.state !== "submitted" || !operation.transactionHash)
|
|
81511
81729
|
throw new TasksValidationError("The task operation has no submitted transaction.");
|
|
81512
|
-
await verifyReceipt(operation, expected, operation.transactionHash);
|
|
81730
|
+
blockNumber = await verifyReceipt(operation, expected, operation.transactionHash);
|
|
81513
81731
|
const reconciled = await retryConflict(
|
|
81514
81732
|
() => client.reconcileOperation(
|
|
81515
81733
|
operation.id,
|
|
@@ -81532,6 +81750,7 @@ function createTasksChain(options) {
|
|
|
81532
81750
|
if (reconciled.operation.state !== "confirmed" && !(operation.step === "approve-usdc" && reconciled.operation.state === "prepared" && reconciled.operation.step === afterApproval))
|
|
81533
81751
|
throw new TasksValidationError("The task transaction was not reconciled.");
|
|
81534
81752
|
await pending.complete(operation.id, operation.step, reconciled);
|
|
81753
|
+
if (reconciled.operation.step !== operation.step) blockNumber = void 0;
|
|
81535
81754
|
current = reconciled;
|
|
81536
81755
|
}
|
|
81537
81756
|
throw new TasksValidationError("The task operation exceeded its allowed step transitions.");
|
|
@@ -81566,14 +81785,16 @@ function createTasksChain(options) {
|
|
|
81566
81785
|
);
|
|
81567
81786
|
const prepareKey = await preparation(input2, verb, { evidenceHash: input2.evidenceHash });
|
|
81568
81787
|
const call2 = verb === "dispute" ? client.disputeEscrow.bind(client) : client.counterEvidenceEscrow.bind(client);
|
|
81569
|
-
return await
|
|
81570
|
-
|
|
81788
|
+
return await prepareOrResume(
|
|
81789
|
+
() => call2(
|
|
81571
81790
|
input2.escrowId,
|
|
81572
81791
|
{ evidenceHash: input2.evidenceHash },
|
|
81573
81792
|
{ idempotencyKey: prepareKey }
|
|
81574
81793
|
),
|
|
81575
81794
|
{ ...expected, evidenceHash: input2.evidenceHash },
|
|
81576
81795
|
prepareKey,
|
|
81796
|
+
verb === "dispute" ? "escrow-dispute" : "escrow-counter-evidence",
|
|
81797
|
+
expected.steps,
|
|
81577
81798
|
exposed,
|
|
81578
81799
|
input2.beforeSign
|
|
81579
81800
|
);
|
|
@@ -81593,11 +81814,34 @@ function createTasksChain(options) {
|
|
|
81593
81814
|
await options.bindings.put(binding);
|
|
81594
81815
|
},
|
|
81595
81816
|
createEscrow: (input2) => safe(async () => {
|
|
81596
|
-
|
|
81817
|
+
let workOrder = await order(input2.orderId);
|
|
81597
81818
|
const ready = await deployment();
|
|
81598
|
-
|
|
81599
|
-
|
|
81600
|
-
|
|
81819
|
+
let prepared;
|
|
81820
|
+
let resumedFromServer = false;
|
|
81821
|
+
try {
|
|
81822
|
+
prepared = await client.createEscrow(input2.orderId, {
|
|
81823
|
+
idempotencyKey: input2.idempotencyKey
|
|
81824
|
+
});
|
|
81825
|
+
} catch (error61) {
|
|
81826
|
+
if (!uncertainPreparation(error61)) throw error61;
|
|
81827
|
+
const fresh = await order(input2.orderId);
|
|
81828
|
+
const candidates = fresh.milestones.filter((item) => {
|
|
81829
|
+
const previous = workOrder.milestones.find((prior) => prior.id === item.id);
|
|
81830
|
+
const operation = item.chainOperation;
|
|
81831
|
+
return item.workOrderId === input2.orderId && previous && operation && operation.kind === "escrow-create" && operation.step === "create-escrow" && (previous.escrowState === null || previous.chainOperation?.id === operation.id);
|
|
81832
|
+
});
|
|
81833
|
+
if (candidates.length !== 1) throw error61;
|
|
81834
|
+
const selected2 = candidates[0];
|
|
81835
|
+
prepared = {
|
|
81836
|
+
operation: selected2.chainOperation,
|
|
81837
|
+
milestone: {
|
|
81838
|
+
id: selected2.id,
|
|
81839
|
+
workOrderId: selected2.workOrderId
|
|
81840
|
+
}
|
|
81841
|
+
};
|
|
81842
|
+
workOrder = fresh;
|
|
81843
|
+
resumedFromServer = true;
|
|
81844
|
+
}
|
|
81601
81845
|
const selected = workOrder.milestones.find((item) => item.id === prepared.milestone.id);
|
|
81602
81846
|
if (!selected || selected.workOrderId !== input2.orderId)
|
|
81603
81847
|
throw new TasksValidationError(
|
|
@@ -81607,11 +81851,12 @@ function createTasksChain(options) {
|
|
|
81607
81851
|
{ escrowId: selected.id, idempotencyKey: input2.idempotencyKey },
|
|
81608
81852
|
"createEscrow"
|
|
81609
81853
|
);
|
|
81610
|
-
|
|
81854
|
+
const result = await execute(
|
|
81611
81855
|
prepared,
|
|
81612
81856
|
await expectation(selected, ready, "createEscrow", ["create-escrow"], input2.counterparty),
|
|
81613
81857
|
prepareKey
|
|
81614
81858
|
);
|
|
81859
|
+
return resumedFromServer ? { ...result, resumedFromServer: true } : result;
|
|
81615
81860
|
}),
|
|
81616
81861
|
async fund(input2) {
|
|
81617
81862
|
let exposed = true;
|
|
@@ -81699,10 +81944,14 @@ function createTasksChain(options) {
|
|
|
81699
81944
|
}
|
|
81700
81945
|
exposed = true;
|
|
81701
81946
|
await pending.markExposure(selected.id);
|
|
81702
|
-
|
|
81703
|
-
idempotencyKey: prepareKey
|
|
81704
|
-
|
|
81705
|
-
|
|
81947
|
+
return await prepareOrResume(
|
|
81948
|
+
() => client.fundEscrow(input2.escrowId, body, { idempotencyKey: prepareKey }),
|
|
81949
|
+
expected,
|
|
81950
|
+
prepareKey,
|
|
81951
|
+
"escrow-funding",
|
|
81952
|
+
expected.steps,
|
|
81953
|
+
exposed
|
|
81954
|
+
);
|
|
81706
81955
|
} catch (cause) {
|
|
81707
81956
|
throw chainError(cause, false, exposed);
|
|
81708
81957
|
}
|
|
@@ -81727,22 +81976,26 @@ function createTasksChain(options) {
|
|
|
81727
81976
|
manifest: frozen.manifest,
|
|
81728
81977
|
note: input2.note
|
|
81729
81978
|
});
|
|
81730
|
-
|
|
81731
|
-
|
|
81732
|
-
|
|
81733
|
-
|
|
81734
|
-
|
|
81735
|
-
|
|
81736
|
-
|
|
81737
|
-
|
|
81738
|
-
|
|
81739
|
-
|
|
81740
|
-
|
|
81979
|
+
return await prepareOrResume(
|
|
81980
|
+
async () => {
|
|
81981
|
+
const prepared = await client.deliverEscrow(
|
|
81982
|
+
input2.escrowId,
|
|
81983
|
+
{ fileIds: frozen.manifest.files.map((file2) => file2.fileId), note: input2.note },
|
|
81984
|
+
{ idempotencyKey: prepareKey }
|
|
81985
|
+
);
|
|
81986
|
+
if (prepared.delivery.manifestHash !== frozen.manifestHash)
|
|
81987
|
+
throw new TasksValidationError(
|
|
81988
|
+
"The server task delivery manifest hash does not match the local manifest."
|
|
81989
|
+
);
|
|
81990
|
+
return prepared;
|
|
81991
|
+
},
|
|
81741
81992
|
{
|
|
81742
81993
|
...expected,
|
|
81743
81994
|
manifestHash: frozen.manifestHash
|
|
81744
81995
|
},
|
|
81745
|
-
prepareKey
|
|
81996
|
+
prepareKey,
|
|
81997
|
+
"escrow-delivery",
|
|
81998
|
+
"submit-delivery"
|
|
81746
81999
|
);
|
|
81747
82000
|
}),
|
|
81748
82001
|
release: (input2) => safe(async () => {
|
|
@@ -81756,10 +82009,12 @@ function createTasksChain(options) {
|
|
|
81756
82009
|
input2.counterparty
|
|
81757
82010
|
);
|
|
81758
82011
|
const prepareKey = await preparation(input2, "release");
|
|
81759
|
-
return await
|
|
81760
|
-
|
|
82012
|
+
return await prepareOrResume(
|
|
82013
|
+
() => client.releaseEscrow(input2.escrowId, { idempotencyKey: prepareKey }),
|
|
81761
82014
|
expected,
|
|
81762
|
-
prepareKey
|
|
82015
|
+
prepareKey,
|
|
82016
|
+
"escrow-release",
|
|
82017
|
+
"release-funds"
|
|
81763
82018
|
);
|
|
81764
82019
|
}),
|
|
81765
82020
|
refund: (input2) => safe(async () => {
|
|
@@ -81773,10 +82028,12 @@ function createTasksChain(options) {
|
|
|
81773
82028
|
input2.counterparty
|
|
81774
82029
|
);
|
|
81775
82030
|
const prepareKey = await preparation(input2, "refund");
|
|
81776
|
-
return await
|
|
81777
|
-
|
|
82031
|
+
return await prepareOrResume(
|
|
82032
|
+
() => client.refundEscrow(input2.escrowId, { idempotencyKey: prepareKey }),
|
|
81778
82033
|
expected,
|
|
81779
|
-
prepareKey
|
|
82034
|
+
prepareKey,
|
|
82035
|
+
"escrow-release",
|
|
82036
|
+
"refund-buyer"
|
|
81780
82037
|
);
|
|
81781
82038
|
}),
|
|
81782
82039
|
disputeFee: (input2) => safe(async () => {
|
|
@@ -81804,16 +82061,21 @@ function createTasksChain(options) {
|
|
|
81804
82061
|
input2.counterparty
|
|
81805
82062
|
);
|
|
81806
82063
|
const prepareKey = await preparation(input2, "resolve-unmatched");
|
|
81807
|
-
return
|
|
81808
|
-
|
|
82064
|
+
return prepareOrResume(
|
|
82065
|
+
() => client.resolveUnmatchedEscrow(input2.escrowId, { idempotencyKey: prepareKey }),
|
|
81809
82066
|
expected,
|
|
81810
|
-
prepareKey
|
|
82067
|
+
prepareKey,
|
|
82068
|
+
"escrow-unmatched-resolution",
|
|
82069
|
+
"resolve-unmatched-dispute"
|
|
81811
82070
|
);
|
|
81812
82071
|
}),
|
|
81813
82072
|
signScopeMessage: (message) => safe(() => account.signMessage({ message }))
|
|
81814
82073
|
};
|
|
81815
82074
|
}
|
|
81816
82075
|
var chainError = safeTasksChainError;
|
|
82076
|
+
function uncertainPreparation(error61) {
|
|
82077
|
+
return error61 instanceof TasksClientError && ((error61.status ?? 0) >= 400 || error61.code === "network" || error61.code === "timeout");
|
|
82078
|
+
}
|
|
81817
82079
|
function retryDelay(header, now) {
|
|
81818
82080
|
if (/^\d+(?:\.\d+)?$/u.test(header.trim())) return Math.max(1, Math.ceil(Number(header) * 1e3));
|
|
81819
82081
|
const date5 = Date.parse(header);
|
|
@@ -81830,6 +82092,60 @@ function alreadySent(error61) {
|
|
|
81830
82092
|
return error61 instanceof Error && /already known|known transaction|nonce (?:is )?too low/iu.test(error61.message);
|
|
81831
82093
|
}
|
|
81832
82094
|
|
|
82095
|
+
// ../core/src/tasks/wait.ts
|
|
82096
|
+
async function waitForMilestone(client, input2) {
|
|
82097
|
+
const timeoutMs = input2.timeoutMs ?? 12e4;
|
|
82098
|
+
const intervalMs = input2.intervalMs ?? 3e3;
|
|
82099
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs < 0)
|
|
82100
|
+
throw new RangeError("The milestone wait timeout must be non-negative and finite.");
|
|
82101
|
+
if (!Number.isFinite(intervalMs) || intervalMs <= 0)
|
|
82102
|
+
throw new RangeError("The milestone wait interval must be positive and finite.");
|
|
82103
|
+
const sleep = input2.sleep ?? ((ms) => new Promise((resolve2) => setTimeout(resolve2, ms)));
|
|
82104
|
+
const now = input2.now ?? (() => /* @__PURE__ */ new Date());
|
|
82105
|
+
const started = now().getTime();
|
|
82106
|
+
const deadline = started + timeoutMs;
|
|
82107
|
+
let polls = 0;
|
|
82108
|
+
let milestone;
|
|
82109
|
+
function result(reached) {
|
|
82110
|
+
return { reached, milestone, polls, elapsedMs: now().getTime() - started };
|
|
82111
|
+
}
|
|
82112
|
+
for (; ; ) {
|
|
82113
|
+
const remaining = deadline - now().getTime();
|
|
82114
|
+
if (remaining <= 0) return result(false);
|
|
82115
|
+
const controller = new AbortController();
|
|
82116
|
+
const timer = setTimeout(() => controller.abort(), remaining);
|
|
82117
|
+
let response;
|
|
82118
|
+
polls++;
|
|
82119
|
+
try {
|
|
82120
|
+
response = await client.getOrder(input2.orderId, { signal: controller.signal });
|
|
82121
|
+
} catch (error61) {
|
|
82122
|
+
if (controller.signal.aborted) return result(false);
|
|
82123
|
+
throw error61;
|
|
82124
|
+
} finally {
|
|
82125
|
+
clearTimeout(timer);
|
|
82126
|
+
}
|
|
82127
|
+
if (controller.signal.aborted || now().getTime() >= deadline) return result(false);
|
|
82128
|
+
const { workOrder } = response;
|
|
82129
|
+
milestone = workOrder.id === input2.orderId && workOrder.version === "work-order-view-v1" ? workOrder.milestones.find(
|
|
82130
|
+
(item) => item.id === input2.milestoneId && item.workOrderId === input2.orderId
|
|
82131
|
+
) : void 0;
|
|
82132
|
+
if (milestone && reachedTarget(milestone, input2.target)) return result(true);
|
|
82133
|
+
await sleep(Math.min(intervalMs, deadline - now().getTime()));
|
|
82134
|
+
}
|
|
82135
|
+
}
|
|
82136
|
+
function reachedTarget(milestone, target) {
|
|
82137
|
+
switch (target) {
|
|
82138
|
+
case "created":
|
|
82139
|
+
return milestone.escrowState !== null;
|
|
82140
|
+
case "locked":
|
|
82141
|
+
return ["locked", "submitted", "disputed", "resolved"].includes(milestone.escrowState ?? "");
|
|
82142
|
+
case "delivered":
|
|
82143
|
+
return ["submitted", "disputed", "resolved"].includes(milestone.escrowState ?? "");
|
|
82144
|
+
case "released":
|
|
82145
|
+
return milestone.escrowState === "resolved";
|
|
82146
|
+
}
|
|
82147
|
+
}
|
|
82148
|
+
|
|
81833
82149
|
// ../core/src/tasks/rpc.ts
|
|
81834
82150
|
function createTasksRpcFor(config2, options = {}) {
|
|
81835
82151
|
const clients = /* @__PURE__ */ new Map();
|
|
@@ -82946,7 +83262,10 @@ async function taskRequest(verb, route, operation, options) {
|
|
|
82946
83262
|
"not_signed_in",
|
|
82947
83263
|
`${verb} needs sign-in. ${options.signInHint}`
|
|
82948
83264
|
);
|
|
82949
|
-
throw new TaskOperationError(
|
|
83265
|
+
throw new TaskOperationError(
|
|
83266
|
+
error61.serverCode ?? (error61.status ? `http_${error61.status}` : error61.code),
|
|
83267
|
+
error61.message
|
|
83268
|
+
);
|
|
82950
83269
|
}
|
|
82951
83270
|
throw error61;
|
|
82952
83271
|
}
|
|
@@ -83067,7 +83386,8 @@ function proposalTerms(id2, address4, deployment, terms) {
|
|
|
83067
83386
|
return {
|
|
83068
83387
|
version: "work-proposal-v1",
|
|
83069
83388
|
workOrderId: id2,
|
|
83070
|
-
|
|
83389
|
+
// The server lowercases addresses before canonicalizing the signed payload.
|
|
83390
|
+
providerAddress: address4.toLowerCase(),
|
|
83071
83391
|
pricingModel: "fixed",
|
|
83072
83392
|
milestones: [
|
|
83073
83393
|
{
|
|
@@ -83454,6 +83774,55 @@ async function showTask(context, input2) {
|
|
|
83454
83774
|
};
|
|
83455
83775
|
}
|
|
83456
83776
|
async function taskStatus(context, input2) {
|
|
83777
|
+
if (input2.signedIn) {
|
|
83778
|
+
const chainState = await taskRequest(
|
|
83779
|
+
"status",
|
|
83780
|
+
"chainState",
|
|
83781
|
+
async () => {
|
|
83782
|
+
try {
|
|
83783
|
+
return await context.client.chainState(input2.id);
|
|
83784
|
+
} catch (error61) {
|
|
83785
|
+
if (error61 instanceof TasksClientError && error61.status === 404) {
|
|
83786
|
+
if (isMissingTaskEntity(error61.serverCode, error61.message))
|
|
83787
|
+
throw new TaskOperationError("not_found", error61.message);
|
|
83788
|
+
throw new TaskOperationError(
|
|
83789
|
+
"not_available",
|
|
83790
|
+
"GET /v1/work-orders/:id/chain-state is not available on this server."
|
|
83791
|
+
);
|
|
83792
|
+
}
|
|
83793
|
+
throw error61;
|
|
83794
|
+
}
|
|
83795
|
+
},
|
|
83796
|
+
context
|
|
83797
|
+
);
|
|
83798
|
+
if (chainState.workOrderId !== input2.id)
|
|
83799
|
+
throw new TaskOperationError("invalid_response", "The response belongs to a different task.");
|
|
83800
|
+
const page = await taskRequest(
|
|
83801
|
+
"status",
|
|
83802
|
+
"events",
|
|
83803
|
+
async () => {
|
|
83804
|
+
try {
|
|
83805
|
+
return await context.client.events(input2.id, { wait: 0 });
|
|
83806
|
+
} catch (error61) {
|
|
83807
|
+
if (error61 instanceof TasksClientError && error61.status === 404) {
|
|
83808
|
+
if (isMissingTaskEntity(error61.serverCode, error61.message)) return null;
|
|
83809
|
+
throw new TaskOperationError(
|
|
83810
|
+
"not_available",
|
|
83811
|
+
"GET /v1/work-orders/:id/events is not available on this server."
|
|
83812
|
+
);
|
|
83813
|
+
}
|
|
83814
|
+
throw error61;
|
|
83815
|
+
}
|
|
83816
|
+
},
|
|
83817
|
+
context
|
|
83818
|
+
);
|
|
83819
|
+
return {
|
|
83820
|
+
task: { id: input2.id },
|
|
83821
|
+
chainState,
|
|
83822
|
+
events: page ? [...page.events].sort((a, b) => a.sequence - b.sequence) : null,
|
|
83823
|
+
nextAfter: page?.nextAfter ?? null
|
|
83824
|
+
};
|
|
83825
|
+
}
|
|
83457
83826
|
const task = await taskRequest(
|
|
83458
83827
|
"status",
|
|
83459
83828
|
"publicTask",
|
|
@@ -83809,6 +84178,7 @@ var searchEventSchema = external_exports.strictObject({
|
|
|
83809
84178
|
source: external_exports.string().min(1),
|
|
83810
84179
|
latencyMs: external_exports.number().nonnegative().finite(),
|
|
83811
84180
|
count: external_exports.number().int().nonnegative(),
|
|
84181
|
+
dropped: external_exports.number().int().nonnegative().optional(),
|
|
83812
84182
|
error: external_exports.string().optional()
|
|
83813
84183
|
})
|
|
83814
84184
|
),
|
|
@@ -86880,7 +87250,7 @@ var memberBundleConfigSchema = external_exports.unknown().refine((value) => !has
|
|
|
86880
87250
|
external_exports.strictObject({ usdc: external_exports.string() })
|
|
86881
87251
|
).refine(
|
|
86882
87252
|
(networks) => Object.entries(networks).every(
|
|
86883
|
-
([id2, network]) => isMemberBundleNetwork(id2) && network.usdc ===
|
|
87253
|
+
([id2, network]) => isMemberBundleNetwork(id2) && network.usdc === NETWORKS2[id2].usdc
|
|
86884
87254
|
),
|
|
86885
87255
|
{ message: "Expected the canonical USDC token of each network." }
|
|
86886
87256
|
).refine((networks) => Object.keys(networks).length === 1, {
|
|
@@ -86919,14 +87289,14 @@ function memberBundleConfig(owner, network) {
|
|
|
86919
87289
|
return {
|
|
86920
87290
|
discoveryUrl,
|
|
86921
87291
|
marketplaceDiscoveryUrl,
|
|
86922
|
-
networks: { [network]: { usdc:
|
|
87292
|
+
networks: { [network]: { usdc: NETWORKS2[network].usdc } }
|
|
86923
87293
|
};
|
|
86924
87294
|
}
|
|
86925
87295
|
function headlessConfigFromBundle(config2) {
|
|
86926
87296
|
const networks = {};
|
|
86927
87297
|
for (const [id2, network] of Object.entries(config2.networks)) {
|
|
86928
87298
|
if (!isMemberBundleNetwork(id2) || network === void 0) continue;
|
|
86929
|
-
networks[id2] = { rpcUrl:
|
|
87299
|
+
networks[id2] = { rpcUrl: NETWORKS2[id2].publicRpcUrl, usdc: network.usdc };
|
|
86930
87300
|
}
|
|
86931
87301
|
return configSchema.parse({
|
|
86932
87302
|
discoveryUrl: config2.discoveryUrl,
|
|
@@ -87019,7 +87389,7 @@ function parseStoredTokens(value) {
|
|
|
87019
87389
|
}
|
|
87020
87390
|
}
|
|
87021
87391
|
function isMemberBundleNetwork(id2) {
|
|
87022
|
-
return Object.hasOwn(
|
|
87392
|
+
return Object.hasOwn(NETWORKS2, id2) && typeof NETWORKS2[id2].publicRpcUrl === "string";
|
|
87023
87393
|
}
|
|
87024
87394
|
function hasForbiddenConfigKey(value) {
|
|
87025
87395
|
if (Array.isArray(value)) return value.some(hasForbiddenConfigKey);
|
|
@@ -87321,11 +87691,28 @@ async function searchMarketplace(input2, config2, fetchImpl, options = {}) {
|
|
|
87321
87691
|
}
|
|
87322
87692
|
}
|
|
87323
87693
|
});
|
|
87324
|
-
const
|
|
87325
|
-
|
|
87694
|
+
const envelope = marketplaceDiscoveryEnvelopeSchema.parse(await response.json());
|
|
87695
|
+
const items = [];
|
|
87696
|
+
let dropped = 0;
|
|
87697
|
+
for (const [index2, rawItem] of envelope.items.entries()) {
|
|
87698
|
+
const parsed = marketplaceHitSchema.safeParse(rawItem);
|
|
87699
|
+
if (parsed.success) {
|
|
87700
|
+
items.push(parsed.data);
|
|
87701
|
+
continue;
|
|
87702
|
+
}
|
|
87703
|
+
dropped += 1;
|
|
87704
|
+
try {
|
|
87705
|
+
options.debug?.(`vAPI marketplace discovery dropped invalid row at index ${index2}.`);
|
|
87706
|
+
} catch {
|
|
87707
|
+
}
|
|
87708
|
+
}
|
|
87709
|
+
mergedCount = items.length;
|
|
87326
87710
|
const attempt = attempts.at(-1);
|
|
87327
|
-
if (attempt)
|
|
87328
|
-
|
|
87711
|
+
if (attempt) {
|
|
87712
|
+
attempt.count = mergedCount;
|
|
87713
|
+
if (dropped > 0) attempt.dropped = dropped;
|
|
87714
|
+
}
|
|
87715
|
+
return { ...envelope, items };
|
|
87329
87716
|
} finally {
|
|
87330
87717
|
if (options.searchesPath) {
|
|
87331
87718
|
await appendSearchEvent(
|
|
@@ -87451,6 +87838,34 @@ var VapiCallError = class extends Error {
|
|
|
87451
87838
|
paymentRejection;
|
|
87452
87839
|
confirmedSettlement;
|
|
87453
87840
|
};
|
|
87841
|
+
var SOLANA_PAYMENTS_UNSUPPORTED_MESSAGE = "Solana payments are not supported in this version of vAPI yet; they arrive in a later release.";
|
|
87842
|
+
function isSolanaCaip2(network) {
|
|
87843
|
+
return network.startsWith("solana:");
|
|
87844
|
+
}
|
|
87845
|
+
function listingPaymentNetwork(endpointNetwork, serviceNetworks) {
|
|
87846
|
+
if (endpointNetwork !== void 0) return endpointNetwork;
|
|
87847
|
+
return serviceNetworks?.length && serviceNetworks.every(isSolanaCaip2) ? serviceNetworks[0] : void 0;
|
|
87848
|
+
}
|
|
87849
|
+
function assertSupportedListingNetwork(network) {
|
|
87850
|
+
if (network !== void 0 && isSolanaCaip2(network)) {
|
|
87851
|
+
throw new VapiCallError(
|
|
87852
|
+
"unsupported_network",
|
|
87853
|
+
`${SOLANA_PAYMENTS_UNSUPPORTED_MESSAGE} This listing pays on ${network}.`
|
|
87854
|
+
);
|
|
87855
|
+
}
|
|
87856
|
+
}
|
|
87857
|
+
function assertSupportedListingResolution(error61) {
|
|
87858
|
+
if (isDiscoveryCatalogError(error61) && error61.code === "ambiguous_default" && error61.paymentNetworks?.length && error61.paymentNetworks.every(isSolanaCaip2)) {
|
|
87859
|
+
assertSupportedListingNetwork(error61.paymentNetworks[0]);
|
|
87860
|
+
}
|
|
87861
|
+
}
|
|
87862
|
+
function payableConfig(config2, account) {
|
|
87863
|
+
if (account.solana !== void 0) return config2;
|
|
87864
|
+
const networks = Object.fromEntries(
|
|
87865
|
+
Object.entries(config2.networks).filter(([network]) => !isSolanaCaip2(network))
|
|
87866
|
+
);
|
|
87867
|
+
return { ...config2, networks };
|
|
87868
|
+
}
|
|
87454
87869
|
var MAX_RESPONSE_BYTES = 1048576;
|
|
87455
87870
|
var BODY_HEADER_NAMES = [
|
|
87456
87871
|
"content-encoding",
|
|
@@ -87460,12 +87875,15 @@ var BODY_HEADER_NAMES = [
|
|
|
87460
87875
|
"content-type"
|
|
87461
87876
|
];
|
|
87462
87877
|
async function callService(args) {
|
|
87878
|
+
validateTimeoutSeconds(args.input.timeoutSeconds);
|
|
87463
87879
|
const trace = createCallTrace(args);
|
|
87464
87880
|
let execution;
|
|
87465
87881
|
try {
|
|
87466
87882
|
execution = await executeCallService(args, trace);
|
|
87467
87883
|
} catch (error61) {
|
|
87468
|
-
|
|
87884
|
+
if (!(error61 instanceof VapiCallError && (error61.code === "unsupported_network" || error61.code === "unsupported_payment"))) {
|
|
87885
|
+
await recordCallError(args, error61, trace).catch(() => void 0);
|
|
87886
|
+
}
|
|
87469
87887
|
throw error61;
|
|
87470
87888
|
}
|
|
87471
87889
|
try {
|
|
@@ -87513,10 +87931,16 @@ async function executeCallService(args, trace) {
|
|
|
87513
87931
|
config2,
|
|
87514
87932
|
fetchImpl
|
|
87515
87933
|
);
|
|
87934
|
+
} catch (error61) {
|
|
87935
|
+
assertSupportedListingResolution(error61);
|
|
87936
|
+
throw error61;
|
|
87516
87937
|
} finally {
|
|
87517
87938
|
trace.phases.discoverMs = elapsed2(trace, discoverStarted);
|
|
87518
87939
|
}
|
|
87519
87940
|
}
|
|
87941
|
+
assertSupportedListingNetwork(
|
|
87942
|
+
listingPaymentNetwork(endpoint?.payment?.network, endpoint?.serviceNetworks)
|
|
87943
|
+
);
|
|
87520
87944
|
const requestedNetwork = normalizeRequiredNetwork(input2.network);
|
|
87521
87945
|
const listingNetwork = endpoint?.payment?.network;
|
|
87522
87946
|
if (requestedNetwork && listingNetwork && !areSamePaymentNetwork(requestedNetwork, listingNetwork)) {
|
|
@@ -87571,6 +87995,8 @@ async function executeCallService(args, trace) {
|
|
|
87571
87995
|
body: method === "GET" || method === "HEAD" ? void 0 : requestBody
|
|
87572
87996
|
});
|
|
87573
87997
|
const request = createRequest(headers);
|
|
87998
|
+
const probeTimeoutMs = input2.timeoutSeconds === void 0 ? args.timeoutMs ?? 3e4 : Math.min(input2.timeoutSeconds, 30) * 1e3;
|
|
87999
|
+
let requestTimeoutMs = probeTimeoutMs;
|
|
87574
88000
|
const fetchWithGuardedRedirects = async (candidateRequest, followRedirects = true) => {
|
|
87575
88001
|
let currentRequest = candidateRequest;
|
|
87576
88002
|
let followedRedirects = 0;
|
|
@@ -87578,7 +88004,7 @@ async function executeCallService(args, trace) {
|
|
|
87578
88004
|
const attempt = await fetchAttempt(
|
|
87579
88005
|
fetchImpl,
|
|
87580
88006
|
new Request(currentRequest.clone(), { redirect: "manual" }),
|
|
87581
|
-
|
|
88007
|
+
requestTimeoutMs
|
|
87582
88008
|
);
|
|
87583
88009
|
const response = attempt.response;
|
|
87584
88010
|
if (!isRedirectStatus2(response.status)) {
|
|
@@ -87732,8 +88158,13 @@ async function executeCallService(args, trace) {
|
|
|
87732
88158
|
challenge: challengeAttempt,
|
|
87733
88159
|
account,
|
|
87734
88160
|
caps: args.spendCaps ?? config2.spendCaps,
|
|
87735
|
-
config: config2,
|
|
87736
|
-
send: async (paidRequest) => {
|
|
88161
|
+
config: payableConfig(config2, account),
|
|
88162
|
+
send: async (paidRequest, quote) => {
|
|
88163
|
+
requestTimeoutMs = paidRequestTimeoutMs(
|
|
88164
|
+
input2.timeoutSeconds,
|
|
88165
|
+
args.timeoutMs,
|
|
88166
|
+
quote.accepted.maxTimeoutSeconds
|
|
88167
|
+
);
|
|
87737
88168
|
paidAttempt = await fetchWithGuardedRedirects(paidRequest, false);
|
|
87738
88169
|
return paidAttempt;
|
|
87739
88170
|
},
|
|
@@ -87772,7 +88203,7 @@ async function executeCallService(args, trace) {
|
|
|
87772
88203
|
asset: completed.quote.accepted.asset,
|
|
87773
88204
|
payTo: completed.quote.accepted.payTo,
|
|
87774
88205
|
settlement: settlementWithExplorer2(completed.settlement, completed.quote.accepted.network),
|
|
87775
|
-
proof: completed.
|
|
88206
|
+
proof: completed.paymentProof
|
|
87776
88207
|
},
|
|
87777
88208
|
...verificationFor(endpoint),
|
|
87778
88209
|
...expectedRequestFor(endpoint, completed.response.status)
|
|
@@ -87982,7 +88413,7 @@ async function resolveCallEndpoint(id2, endpointName, marketplaceHit, config2, f
|
|
|
87982
88413
|
try {
|
|
87983
88414
|
return registeredEndpoint(await resolveServiceListing(id2, config2, fetchImpl, endpointName));
|
|
87984
88415
|
} catch (error61) {
|
|
87985
|
-
if (!(error61
|
|
88416
|
+
if (!isDiscoveryCatalogError(error61) || error61.code !== "service_not_found") {
|
|
87986
88417
|
throw error61;
|
|
87987
88418
|
}
|
|
87988
88419
|
const discovered = await findMarketplaceApiByRef(id2, config2, fetchImpl);
|
|
@@ -88019,9 +88450,18 @@ async function resolveCallEndpoint(id2, endpointName, marketplaceHit, config2, f
|
|
|
88019
88450
|
);
|
|
88020
88451
|
}
|
|
88021
88452
|
function registeredEndpoint(listing, verification) {
|
|
88453
|
+
const { payment, ...endpoint } = listing.endpoint;
|
|
88454
|
+
if (payment && (typeof payment.protocol === "string" || typeof payment.network !== "string")) {
|
|
88455
|
+
throw new VapiCallError(
|
|
88456
|
+
"unsupported_payment",
|
|
88457
|
+
`Payment protocol ${payment.protocol} is not supported. This client pays x402 exact USDC endpoints only.`
|
|
88458
|
+
);
|
|
88459
|
+
}
|
|
88022
88460
|
return {
|
|
88023
|
-
...
|
|
88461
|
+
...endpoint,
|
|
88462
|
+
...payment ? { payment: { network: payment.network, payTo: payment.payTo } } : {},
|
|
88024
88463
|
verification: verification ?? listing.service.verification,
|
|
88464
|
+
serviceNetworks: listing.service.networks,
|
|
88025
88465
|
registered: true,
|
|
88026
88466
|
resolvedListing: true
|
|
88027
88467
|
};
|
|
@@ -88181,7 +88621,7 @@ async function readResponseBody2(response) {
|
|
|
88181
88621
|
async function fetchAttempt(fetchImpl, request, timeoutMs) {
|
|
88182
88622
|
const controller = new AbortController();
|
|
88183
88623
|
let rejectTimeout = null;
|
|
88184
|
-
const timeoutError = new Error(`API request timed out after ${timeoutMs}
|
|
88624
|
+
const timeoutError = new Error(`API request timed out after ${timeoutMs / 1e3} seconds.`);
|
|
88185
88625
|
const timedOut = new Promise((_resolve, reject) => {
|
|
88186
88626
|
rejectTimeout = reject;
|
|
88187
88627
|
});
|
|
@@ -88221,6 +88661,19 @@ async function fetchAttempt(fetchImpl, request, timeoutMs) {
|
|
|
88221
88661
|
throw error61;
|
|
88222
88662
|
}
|
|
88223
88663
|
}
|
|
88664
|
+
function validateTimeoutSeconds(timeoutSeconds) {
|
|
88665
|
+
if (timeoutSeconds !== void 0 && (!Number.isInteger(timeoutSeconds) || timeoutSeconds < 1 || timeoutSeconds > 300)) {
|
|
88666
|
+
throw new Error("call timeoutSeconds must be an integer from 1 to 300 seconds.");
|
|
88667
|
+
}
|
|
88668
|
+
}
|
|
88669
|
+
function paidRequestTimeoutMs(timeoutSeconds, internalTimeoutMs, offerTimeoutSeconds) {
|
|
88670
|
+
const usableOfferTimeout = Number.isInteger(offerTimeoutSeconds) && offerTimeoutSeconds > 0 ? offerTimeoutSeconds : void 0;
|
|
88671
|
+
if (timeoutSeconds !== void 0) {
|
|
88672
|
+
return Math.min(timeoutSeconds, usableOfferTimeout ?? timeoutSeconds) * 1e3;
|
|
88673
|
+
}
|
|
88674
|
+
if (internalTimeoutMs !== void 0) return internalTimeoutMs;
|
|
88675
|
+
return usableOfferTimeout === void 0 ? 12e4 : Math.min(12e4, Math.max(3e4, usableOfferTimeout * 1e3));
|
|
88676
|
+
}
|
|
88224
88677
|
function mapX402PaymentError(error61, resumeId) {
|
|
88225
88678
|
if (!(error61 instanceof X402PaymentError)) return error61;
|
|
88226
88679
|
if (error61.code === "payment_rejected") {
|
|
@@ -88236,9 +88689,10 @@ function mapX402PaymentError(error61, resumeId) {
|
|
|
88236
88689
|
});
|
|
88237
88690
|
}
|
|
88238
88691
|
const resume = resumeId !== void 0 && error61.possibleSettlement?.authorizationNonce ? ` Check whether it settled with \`vapi pay --resume ${resumeId}\` before paying again.` : "";
|
|
88692
|
+
const timeoutDetail = error61.cause instanceof Error && error61.cause.message.startsWith("API request timed out after ") ? `${error61.cause.message} ` : "";
|
|
88239
88693
|
return new VapiCallError(
|
|
88240
88694
|
"settlement_unknown",
|
|
88241
|
-
`${error61.message}${resume}`,
|
|
88695
|
+
`${timeoutDetail}${error61.message}${resume}`,
|
|
88242
88696
|
error61.possibleSettlement,
|
|
88243
88697
|
{ cause: error61.cause }
|
|
88244
88698
|
);
|
|
@@ -88260,14 +88714,17 @@ async function inspectService(input2, config2, fetchImpl) {
|
|
|
88260
88714
|
try {
|
|
88261
88715
|
listing = await resolveServiceListing(input2.id, config2, fetchImpl, input2.endpoint);
|
|
88262
88716
|
} catch (error61) {
|
|
88263
|
-
|
|
88717
|
+
assertSupportedListingResolution(error61);
|
|
88718
|
+
if (input2.endpoint || !isDiscoveryCatalogError(error61) || error61.code !== "service_not_found") {
|
|
88264
88719
|
throw error61;
|
|
88265
88720
|
}
|
|
88266
88721
|
const hit = await findMarketplaceApiByRef(input2.id, config2, fetchImpl);
|
|
88267
88722
|
if (!hit || hit.kind !== "api" || hit.provenance !== "indexed") throw error61;
|
|
88723
|
+
assertSupportedListingNetwork(hit.execution.network);
|
|
88268
88724
|
return inspectIndexedHit(hit);
|
|
88269
88725
|
}
|
|
88270
88726
|
const { endpoint, service } = listing;
|
|
88727
|
+
assertSupportedListingNetwork(listingPaymentNetwork(endpoint.payment?.network, service.networks));
|
|
88271
88728
|
return {
|
|
88272
88729
|
name: endpoint.name,
|
|
88273
88730
|
method: endpoint.method,
|
|
@@ -88367,13 +88824,7 @@ var inspectToolResultSchema = external_exports.object({
|
|
|
88367
88824
|
liveness: listingLivenessSchema.optional(),
|
|
88368
88825
|
conformance: listingConformanceSchema.optional(),
|
|
88369
88826
|
identity: listingIdentitySchema.optional(),
|
|
88370
|
-
payment:
|
|
88371
|
-
scheme: external_exports.literal("exact"),
|
|
88372
|
-
network: external_exports.string(),
|
|
88373
|
-
asset: external_exports.string(),
|
|
88374
|
-
payTo: external_exports.string(),
|
|
88375
|
-
checkedAt: external_exports.string()
|
|
88376
|
-
}).nullable()
|
|
88827
|
+
payment: discoveryEndpointSchema.shape.payment.unwrap().nullable()
|
|
88377
88828
|
});
|
|
88378
88829
|
var callSearchInputSchema = external_exports.object({
|
|
88379
88830
|
query: external_exports.string().trim().max(200).optional().describe("Capability, API, service, or request."),
|
|
@@ -88402,7 +88853,10 @@ var callPayInputSchema = external_exports.object({
|
|
|
88402
88853
|
(value) => /^0x[0-9a-fA-F]{40}$/.test(value) || isSolanaAddress(value),
|
|
88403
88854
|
"Expected an EVM or Solana address."
|
|
88404
88855
|
).optional(),
|
|
88405
|
-
maxPriceUsd: external_exports.union([external_exports.number().nonnegative(), external_exports.string().regex(/^\d+(?:\.\d{1,6})?$/)]).optional()
|
|
88856
|
+
maxPriceUsd: external_exports.union([external_exports.number().nonnegative(), external_exports.string().regex(/^\d+(?:\.\d{1,6})?$/)]).optional(),
|
|
88857
|
+
timeoutSeconds: external_exports.number().int().min(1).max(300).optional().describe(
|
|
88858
|
+
"Seconds to wait for the paid response. Default: the provider's maxTimeoutSeconds, at most 120."
|
|
88859
|
+
)
|
|
88406
88860
|
});
|
|
88407
88861
|
var callSearch = defineAction({
|
|
88408
88862
|
name: "call.search",
|
|
@@ -88665,7 +89119,7 @@ async function readResult(response, signal, secrets = []) {
|
|
|
88665
89119
|
return {
|
|
88666
89120
|
status: response.status,
|
|
88667
89121
|
contentType: contentType === null ? null : redactKnownSecrets2(contentType, secrets),
|
|
88668
|
-
body:
|
|
89122
|
+
body: sanitizeReturnedValue2(await readResponseBody3(response, contentType, signal), secrets)
|
|
88669
89123
|
};
|
|
88670
89124
|
}
|
|
88671
89125
|
async function readResponseBody3(response, contentType, signal) {
|
|
@@ -88710,17 +89164,17 @@ function isJsonContentType2(value) {
|
|
|
88710
89164
|
const mediaType = value?.split(";", 1)[0]?.trim().toLowerCase() ?? "";
|
|
88711
89165
|
return mediaType === "application/json" || mediaType.endsWith("+json");
|
|
88712
89166
|
}
|
|
88713
|
-
function
|
|
89167
|
+
function sanitizeReturnedValue2(value, secrets, depth = 0) {
|
|
88714
89168
|
if (typeof value === "string") return redactKnownSecrets2(value, secrets);
|
|
88715
89169
|
if (value === null || typeof value !== "object") return value;
|
|
88716
89170
|
if (depth >= 16) return "[redacted nested response value]";
|
|
88717
89171
|
if (Array.isArray(value)) {
|
|
88718
|
-
return value.map((item) =>
|
|
89172
|
+
return value.map((item) => sanitizeReturnedValue2(item, secrets, depth + 1));
|
|
88719
89173
|
}
|
|
88720
89174
|
return Object.fromEntries(
|
|
88721
89175
|
Object.entries(value).map(([key2, item]) => [
|
|
88722
89176
|
redactKnownSecrets2(key2, secrets),
|
|
88723
|
-
|
|
89177
|
+
sanitizeReturnedValue2(item, secrets, depth + 1)
|
|
88724
89178
|
])
|
|
88725
89179
|
);
|
|
88726
89180
|
}
|
|
@@ -92037,6 +92491,7 @@ var moneyParticipant = {
|
|
|
92037
92491
|
"Checksummed 0x address of the other party, taken from tasks.show (the poster's clientAddress when you are the worker; the accepted proposal's providerAddress when you are the poster). The human must supply it; it is compared with the signed scope and stored as local consent. Without it tasks.sign refuses and no local party binding is created, so tasks.fund/deliver/release cannot run from this machine."
|
|
92038
92492
|
).optional()
|
|
92039
92493
|
};
|
|
92494
|
+
var waitForIndexer = external_exports.boolean().default(true).describe("Wait up to 60 seconds for vAPI to index the chain result before returning.");
|
|
92040
92495
|
var cursor = external_exports.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
|
|
92041
92496
|
function usdWithinEscrow(value, positive = false) {
|
|
92042
92497
|
try {
|
|
@@ -92083,7 +92538,10 @@ var tasksPostTool = descriptor(
|
|
|
92083
92538
|
deadline: external_exports.string(),
|
|
92084
92539
|
intake: external_exports.enum(["proposals", "submissions"]).optional(),
|
|
92085
92540
|
maxAwards: external_exports.number().int().min(TASK_LIMITS.maxAwardsMin).max(TASK_LIMITS.maxAwardsMax).optional(),
|
|
92086
|
-
webhookUrl: httpsUrl.optional()
|
|
92541
|
+
webhookUrl: httpsUrl.optional(),
|
|
92542
|
+
vendor: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/u).describe(
|
|
92543
|
+
"Optional 0x address of a vendor to invite directly; the task is addressed to that wallet and shows up for them. Anyone may still propose."
|
|
92544
|
+
).optional()
|
|
92087
92545
|
}
|
|
92088
92546
|
);
|
|
92089
92547
|
var tasksProposeTool = descriptor(
|
|
@@ -92108,42 +92566,43 @@ var tasksAwardTool = descriptor(
|
|
|
92108
92566
|
{ ...participant, proposalId: id }
|
|
92109
92567
|
);
|
|
92110
92568
|
var tasksSignTool = descriptor(
|
|
92111
|
-
"
|
|
92112
|
-
moneyParticipant
|
|
92569
|
+
"Signs the user's own task scope locally with the user's vault wallet after the human confirms the money direction via counterparty; a worker may also create the unfunded escrow; nothing is custodial. Does not move money. Waits up to 60 seconds for vAPI to index a created escrow by default.",
|
|
92570
|
+
{ ...moneyParticipant, wait: waitForIndexer }
|
|
92113
92571
|
);
|
|
92114
92572
|
var tasksFundTool = descriptor(
|
|
92115
|
-
"
|
|
92116
|
-
moneyParticipant
|
|
92573
|
+
"Executes the user's own funding of this task from the user's vault wallet, within the spend policy the user configured; nothing is custodial. MCP cannot grant human approval; amounts above the approval threshold are refused with approval:true. Waits up to 60 seconds for vAPI to index the locked escrow by default.",
|
|
92574
|
+
{ ...moneyParticipant, wait: waitForIndexer }
|
|
92117
92575
|
);
|
|
92118
92576
|
var tasksDeliverTool = descriptor(
|
|
92119
|
-
"Does not move money. Upload local delivery files, freeze the manifest and record delivery with the local vault wallet.",
|
|
92577
|
+
"Does not move money. Upload local delivery files, freeze the manifest and record delivery with the local vault wallet. Waits up to 60 seconds for vAPI to index the delivery by default.",
|
|
92120
92578
|
{
|
|
92121
92579
|
...moneyParticipant,
|
|
92580
|
+
wait: waitForIndexer,
|
|
92122
92581
|
files: external_exports.array(localPath).min(TASK_LIMITS.deliveryFilesMin).max(TASK_LIMITS.deliveryFilesMax),
|
|
92123
92582
|
note: external_exports.string().max(TASK_LIMITS.deliveryNoteMax).refine((value) => value.trim().length > 0)
|
|
92124
92583
|
}
|
|
92125
92584
|
);
|
|
92126
92585
|
var tasksReleaseTool = descriptor(
|
|
92127
|
-
"
|
|
92128
|
-
moneyParticipant
|
|
92586
|
+
"Executes the user's own payment to the worker from task escrow with the user's vault wallet; nothing is custodial. Returns gross \xB7 fee \xB7 net using the deployed fee. Waits up to 60 seconds for vAPI to index the release by default.",
|
|
92587
|
+
{ ...moneyParticipant, wait: waitForIndexer }
|
|
92129
92588
|
);
|
|
92130
92589
|
var tasksRefundTool = descriptor(
|
|
92131
|
-
"
|
|
92590
|
+
"Executes the user's own refund of escrowed USDC to the poster with the user's vault wallet; nothing is custodial. Returns gross \xB7 fee \xB7 net using the deployed fee.",
|
|
92132
92591
|
moneyParticipant
|
|
92133
92592
|
);
|
|
92134
92593
|
var tasksDisputeTool = descriptor(
|
|
92135
|
-
"
|
|
92594
|
+
"Executes the user's own approval of the verified dispute fee and raises a dispute with the user's vault wallet; nothing is custodial. Applies task and daily caps; MCP refuses human approval with approval:true. Accepts a precomputed evidence hash.",
|
|
92136
92595
|
{
|
|
92137
92596
|
...moneyParticipant,
|
|
92138
92597
|
evidenceHash: external_exports.string().regex(TASK_LIMITS.disputeEvidenceHash)
|
|
92139
92598
|
}
|
|
92140
92599
|
);
|
|
92141
92600
|
var tasksCounterEvidenceTool = descriptor(
|
|
92142
|
-
"
|
|
92601
|
+
"Executes the user's own counter-evidence submission and approval of the verified dispute fee with the user's vault wallet as the non-opener before the onchain deadline; nothing is custodial. Applies task and daily caps; MCP refuses human approval with approval:true.",
|
|
92143
92602
|
{ ...moneyParticipant, evidenceHash: external_exports.string().regex(TASK_LIMITS.disputeEvidenceHash) }
|
|
92144
92603
|
);
|
|
92145
92604
|
var tasksResolveUnmatchedTool = descriptor(
|
|
92146
|
-
"
|
|
92605
|
+
"Executes the user's own resolution of an unmatched dispute with the user's vault wallet after the onchain counter-evidence deadline when no counter-evidence was submitted; nothing is custodial.",
|
|
92147
92606
|
moneyParticipant
|
|
92148
92607
|
);
|
|
92149
92608
|
var tasksMessageTool = descriptor(
|
|
@@ -92167,8 +92626,8 @@ var tasksWatchTool = descriptor(
|
|
|
92167
92626
|
}
|
|
92168
92627
|
);
|
|
92169
92628
|
var tasksStatusTool = descriptor(
|
|
92170
|
-
"Does not move money. Read the public task card
|
|
92171
|
-
|
|
92629
|
+
"Does not move money. Read signed-in chain state and participant events, or the public task card without sign-in.",
|
|
92630
|
+
participant
|
|
92172
92631
|
);
|
|
92173
92632
|
var signInHint = "Call auth.link for the acting wallet.";
|
|
92174
92633
|
function lazyTasksChain(factory, pending) {
|
|
@@ -92308,6 +92767,22 @@ function createTasksTools(options) {
|
|
|
92308
92767
|
};
|
|
92309
92768
|
};
|
|
92310
92769
|
}
|
|
92770
|
+
async function waitAfterChain(ctx, orderId, milestoneId, target) {
|
|
92771
|
+
return await taskRequest(
|
|
92772
|
+
target,
|
|
92773
|
+
"getOrder",
|
|
92774
|
+
() => waitForMilestone(ctx.client, {
|
|
92775
|
+
orderId,
|
|
92776
|
+
milestoneId,
|
|
92777
|
+
target,
|
|
92778
|
+
timeoutMs: 6e4,
|
|
92779
|
+
intervalMs: 3e3,
|
|
92780
|
+
...options.sleep === void 0 ? {} : { sleep: options.sleep },
|
|
92781
|
+
now
|
|
92782
|
+
}),
|
|
92783
|
+
ctx
|
|
92784
|
+
);
|
|
92785
|
+
}
|
|
92311
92786
|
async function feeAction(verb, input2) {
|
|
92312
92787
|
const ctx = await acting(input2.wallet);
|
|
92313
92788
|
const policy = await taskPolicyForWallet({
|
|
@@ -92350,7 +92825,12 @@ function createTasksTools(options) {
|
|
|
92350
92825
|
throw new TaskInputError("deadline must be at least 10 minutes from now.");
|
|
92351
92826
|
const ctx = await acting(input2.wallet);
|
|
92352
92827
|
const outcome = await postTask(ctx, {
|
|
92353
|
-
order: {
|
|
92828
|
+
order: {
|
|
92829
|
+
title: input2.title,
|
|
92830
|
+
description: input2.brief,
|
|
92831
|
+
policyFamily: "general-digital",
|
|
92832
|
+
...input2.vendor === void 0 ? {} : { invitedProviderAddress: input2.vendor }
|
|
92833
|
+
},
|
|
92354
92834
|
amount: parseUsdToBaseUnits(input2.amountUsd),
|
|
92355
92835
|
deadlineAt: new Date(postedAt.getTime() + deadlineDuration).toISOString(),
|
|
92356
92836
|
...input2.intake === void 0 ? {} : { intake: input2.intake },
|
|
@@ -92408,15 +92888,15 @@ function createTasksTools(options) {
|
|
|
92408
92888
|
const ctx = await acting(input2.wallet);
|
|
92409
92889
|
const signerAddress = (await options.session.addressesFor(ctx.selected.name)).address;
|
|
92410
92890
|
try {
|
|
92411
|
-
|
|
92412
|
-
|
|
92413
|
-
|
|
92414
|
-
|
|
92415
|
-
|
|
92416
|
-
|
|
92417
|
-
|
|
92418
|
-
|
|
92419
|
-
);
|
|
92891
|
+
const outcome = await signTaskScope(ctx, {
|
|
92892
|
+
id: input2.id,
|
|
92893
|
+
counterparty: input2.counterparty,
|
|
92894
|
+
signerAddress,
|
|
92895
|
+
bindings: createScopeBindings(home),
|
|
92896
|
+
signMessage: async (message) => (await unlock(ctx.selected.name)()).signMessage(message)
|
|
92897
|
+
});
|
|
92898
|
+
const wait2 = input2.wait && outcome.escrowCreation ? await waitAfterChain(ctx, input2.id, outcome.escrowCreation.milestone.id, "created") : null;
|
|
92899
|
+
return taskResult({ ...outcome, wait: wait2 });
|
|
92420
92900
|
} catch (error61) {
|
|
92421
92901
|
if (!(error61 instanceof TasksScopeCreationError)) throw error61;
|
|
92422
92902
|
try {
|
|
@@ -92452,28 +92932,31 @@ function createTasksTools(options) {
|
|
|
92452
92932
|
// Stdio has no human approval channel. Model arguments cannot grant approval.
|
|
92453
92933
|
approval: { granted: false }
|
|
92454
92934
|
});
|
|
92455
|
-
|
|
92935
|
+
const wait2 = input2.wait && outcome.ok ? await waitAfterChain(ctx, input2.id, outcome.result.milestone.id, "locked") : null;
|
|
92936
|
+
return taskResult({ ...outcome, wait: wait2 }, !outcome.ok);
|
|
92456
92937
|
},
|
|
92457
92938
|
async deliver(input2) {
|
|
92458
92939
|
const files = (await Promise.all(input2.files.map(readTaskFile))).map(
|
|
92459
92940
|
({ fileName: name, bytes, contentType }) => ({ name, bytes, contentType })
|
|
92460
92941
|
);
|
|
92461
|
-
|
|
92462
|
-
|
|
92463
|
-
|
|
92464
|
-
|
|
92465
|
-
|
|
92466
|
-
|
|
92467
|
-
|
|
92468
|
-
);
|
|
92942
|
+
const ctx = await acting(input2.wallet);
|
|
92943
|
+
const outcome = await deliverTaskOperation(ctx, {
|
|
92944
|
+
id: input2.id,
|
|
92945
|
+
...input2.counterparty === void 0 ? {} : { counterparty: input2.counterparty },
|
|
92946
|
+
files,
|
|
92947
|
+
note: input2.note
|
|
92948
|
+
});
|
|
92949
|
+
const wait2 = input2.wait ? await waitAfterChain(ctx, input2.id, outcome.result.milestone.id, "delivered") : null;
|
|
92950
|
+
return taskResult({ ...outcome, wait: wait2 });
|
|
92469
92951
|
},
|
|
92470
92952
|
async release(input2) {
|
|
92471
|
-
|
|
92472
|
-
|
|
92473
|
-
|
|
92474
|
-
|
|
92475
|
-
|
|
92476
|
-
);
|
|
92953
|
+
const ctx = await acting(input2.wallet);
|
|
92954
|
+
const outcome = await releaseTaskOperation(ctx, {
|
|
92955
|
+
id: input2.id,
|
|
92956
|
+
...input2.counterparty === void 0 ? {} : { counterparty: input2.counterparty }
|
|
92957
|
+
});
|
|
92958
|
+
const wait2 = input2.wait ? await waitAfterChain(ctx, input2.id, outcome.result.milestone.id, "released") : null;
|
|
92959
|
+
return taskResult({ ...outcome, wait: wait2 });
|
|
92477
92960
|
},
|
|
92478
92961
|
async refund(input2) {
|
|
92479
92962
|
return taskResult(
|
|
@@ -92540,7 +93023,11 @@ function createTasksTools(options) {
|
|
|
92540
93023
|
}
|
|
92541
93024
|
},
|
|
92542
93025
|
async status(input2) {
|
|
92543
|
-
|
|
93026
|
+
await options.wallets?.reload();
|
|
93027
|
+
const publicOnly = input2.wallet === void 0 && options.session.activeName === void 0 && options.wallets !== void 0 && options.wallets.names().length === 0;
|
|
93028
|
+
const candidate = await context(input2.wallet, publicOnly);
|
|
93029
|
+
const ctx = candidate.token || publicOnly ? candidate : await context(void 0, true);
|
|
93030
|
+
return taskResult(await taskStatus(ctx, { id: input2.id, signedIn: Boolean(ctx.token) }));
|
|
92544
93031
|
}
|
|
92545
93032
|
};
|
|
92546
93033
|
}
|
|
@@ -93297,6 +93784,11 @@ var statsToolResultSchema = external_exports.object({
|
|
|
93297
93784
|
)
|
|
93298
93785
|
})
|
|
93299
93786
|
});
|
|
93787
|
+
function objectOutputSchema(schema) {
|
|
93788
|
+
if (!schema) return {};
|
|
93789
|
+
const json2 = external_exports.toJSONSchema(schema);
|
|
93790
|
+
return json2.type === "object" ? { outputSchema: json2 } : {};
|
|
93791
|
+
}
|
|
93300
93792
|
var VapiMcpServer = class {
|
|
93301
93793
|
#tools = /* @__PURE__ */ new Map();
|
|
93302
93794
|
#onClose;
|
|
@@ -93320,7 +93812,7 @@ var VapiMcpServer = class {
|
|
|
93320
93812
|
name,
|
|
93321
93813
|
...tool.description ? { description: tool.description } : {},
|
|
93322
93814
|
inputSchema: external_exports.toJSONSchema(tool.inputSchema),
|
|
93323
|
-
...
|
|
93815
|
+
...objectOutputSchema(tool.outputSchema)
|
|
93324
93816
|
}))
|
|
93325
93817
|
};
|
|
93326
93818
|
}
|
|
@@ -94188,7 +94680,13 @@ function toolError(error61) {
|
|
|
94188
94680
|
{
|
|
94189
94681
|
error: error61.message,
|
|
94190
94682
|
code: error61.code,
|
|
94191
|
-
...error61.possibleSettlement ? {
|
|
94683
|
+
...error61.possibleSettlement ? {
|
|
94684
|
+
possibleSettlement: Object.fromEntries(
|
|
94685
|
+
Object.entries(error61.possibleSettlement).filter(
|
|
94686
|
+
([key2]) => key2 !== "authorizationTransaction"
|
|
94687
|
+
)
|
|
94688
|
+
)
|
|
94689
|
+
} : {},
|
|
94192
94690
|
...error61.paymentRejection ? { paymentRejection: error61.paymentRejection } : {},
|
|
94193
94691
|
...error61.confirmedSettlement ? { confirmedSettlement: error61.confirmedSettlement } : {}
|
|
94194
94692
|
},
|
|
@@ -97682,7 +98180,7 @@ async function readProcessStdin() {
|
|
|
97682
98180
|
}
|
|
97683
98181
|
|
|
97684
98182
|
// ../cli/src/version.ts
|
|
97685
|
-
var CLI_VERSION = "0.9.
|
|
98183
|
+
var CLI_VERSION = "0.9.4";
|
|
97686
98184
|
|
|
97687
98185
|
// ../cli/src/status.ts
|
|
97688
98186
|
async function statusCommand(argv, json2, io, dependencies) {
|
|
@@ -101184,7 +101682,7 @@ function createLocalRuntime(options) {
|
|
|
101184
101682
|
const processCommand = options.processCommand ?? defaultProcessCommand;
|
|
101185
101683
|
const ownsProcess = (handle, pid) => processCommand(pid)?.includes(runResultPath(home, handle.runId)) === true;
|
|
101186
101684
|
const closeFd = options.closeFd ?? closeSync2;
|
|
101187
|
-
const
|
|
101685
|
+
const readFile30 = options.readFile ?? nodeReadFile;
|
|
101188
101686
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
101189
101687
|
const openLog = options.openLog ?? ((path) => {
|
|
101190
101688
|
mkdirSync2(runsDirectory(home), { recursive: true, mode: 448 });
|
|
@@ -101239,7 +101737,7 @@ function createLocalRuntime(options) {
|
|
|
101239
101737
|
return handle;
|
|
101240
101738
|
},
|
|
101241
101739
|
async status(handle) {
|
|
101242
|
-
const result = await readResultFile(
|
|
101740
|
+
const result = await readResultFile(readFile30, runResultPath(home, handle.runId));
|
|
101243
101741
|
if (result !== void 0) return result;
|
|
101244
101742
|
const pid = localPid(handle);
|
|
101245
101743
|
if (pid === void 0 || handle.kind !== "local") {
|
|
@@ -101342,10 +101840,10 @@ function childArguments(member, run) {
|
|
|
101342
101840
|
...run.drawUsd ? ["--draw", run.drawUsd] : []
|
|
101343
101841
|
];
|
|
101344
101842
|
}
|
|
101345
|
-
async function readResultFile(
|
|
101843
|
+
async function readResultFile(readFile30, path) {
|
|
101346
101844
|
let text;
|
|
101347
101845
|
try {
|
|
101348
|
-
text = await
|
|
101846
|
+
text = await readFile30(path, "utf8");
|
|
101349
101847
|
} catch (error61) {
|
|
101350
101848
|
if (hasCode3(error61, "ENOENT")) return void 0;
|
|
101351
101849
|
return { state: "failed", detail: "unreadable result file" };
|
|
@@ -102195,7 +102693,7 @@ function isMcpInstallApp(value) {
|
|
|
102195
102693
|
function serverEntry(home, registry2) {
|
|
102196
102694
|
return {
|
|
102197
102695
|
command: "npx",
|
|
102198
|
-
args: ["-y", "vapi-network", "mcp"],
|
|
102696
|
+
args: ["-y", "vapi-network@latest", "mcp"],
|
|
102199
102697
|
env: { VAPI_HOME: home, VAPI_REGISTRY_URL: registry2 }
|
|
102200
102698
|
};
|
|
102201
102699
|
}
|
|
@@ -102244,7 +102742,7 @@ function tomlConfig(existing, entry) {
|
|
|
102244
102742
|
const block = [
|
|
102245
102743
|
"[mcp_servers.vapi]",
|
|
102246
102744
|
'command = "npx"',
|
|
102247
|
-
'args = ["-y", "vapi-network", "mcp"]',
|
|
102745
|
+
'args = ["-y", "vapi-network@latest", "mcp"]',
|
|
102248
102746
|
`env = { VAPI_HOME = "${escapeToml(entry.env.VAPI_HOME)}", VAPI_REGISTRY_URL = "${escapeToml(entry.env.VAPI_REGISTRY_URL)}" }`,
|
|
102249
102747
|
""
|
|
102250
102748
|
].join("\n");
|
|
@@ -102411,13 +102909,13 @@ async function sendConfig(dependencies) {
|
|
|
102411
102909
|
// ../cli/src/setup.ts
|
|
102412
102910
|
import { rm as rm5 } from "node:fs/promises";
|
|
102413
102911
|
import { join as join26 } from "node:path";
|
|
102414
|
-
var SETUP_ARGUMENT_ERROR =
|
|
102912
|
+
var SETUP_ARGUMENT_ERROR = `vapi setup accepts only --no-cloud-backup and --accounts <n> (1-${MAX_RESTORE_ACCOUNTS}); a recovery phrase is typed at the prompt, never passed on the command line.`;
|
|
102415
102913
|
var VAULT_CHOICE = "Create a new vault, or restore one from a recovery phrase? [new/restore] ";
|
|
102416
102914
|
async function setupCommand(argv, json2, io, dependencies) {
|
|
102417
102915
|
let parsed;
|
|
102418
102916
|
try {
|
|
102419
102917
|
parsed = parseArguments(argv, {
|
|
102420
|
-
valueOptions: /* @__PURE__ */ new Set(),
|
|
102918
|
+
valueOptions: /* @__PURE__ */ new Set(["--accounts"]),
|
|
102421
102919
|
booleanOptions: /* @__PURE__ */ new Set(["--no-cloud-backup"]),
|
|
102422
102920
|
maximumPositionals: 0
|
|
102423
102921
|
});
|
|
@@ -102428,6 +102926,7 @@ async function setupCommand(argv, json2, io, dependencies) {
|
|
|
102428
102926
|
const paths = getVapiPaths();
|
|
102429
102927
|
const steps = [];
|
|
102430
102928
|
const humanIo = json2 ? stderrIo(io) : io;
|
|
102929
|
+
const accountCount = parseAccountCount(parsed.one("--accounts"));
|
|
102431
102930
|
if (!await fileExists2(paths.config)) {
|
|
102432
102931
|
await writeDefaultConfig(paths.config, process.env, { networks: ["base"] });
|
|
102433
102932
|
steps.push("config");
|
|
@@ -102438,6 +102937,7 @@ async function setupCommand(argv, json2, io, dependencies) {
|
|
|
102438
102937
|
let changedVault = false;
|
|
102439
102938
|
let changedAccount = false;
|
|
102440
102939
|
let changedLink = false;
|
|
102940
|
+
let scannedAddresses;
|
|
102441
102941
|
if (!await fileExists2(join26(paths.directory, "vault.json"))) {
|
|
102442
102942
|
const choice = await vaultChoice(dependencies);
|
|
102443
102943
|
if (choice === "restore") {
|
|
@@ -102445,12 +102945,14 @@ async function setupCommand(argv, json2, io, dependencies) {
|
|
|
102445
102945
|
throw new Error("Restoring needs a terminal to type the phrase.");
|
|
102446
102946
|
}
|
|
102447
102947
|
const readSecret = dependencies.prompts?.secret ?? promptForSecret;
|
|
102448
|
-
await restoreVaultFromPhrase(
|
|
102948
|
+
const restored = await restoreVaultFromPhrase(
|
|
102449
102949
|
await readSecret("Recovery phrase: "),
|
|
102450
102950
|
config2,
|
|
102451
102951
|
humanIo,
|
|
102452
|
-
dependencies
|
|
102952
|
+
dependencies,
|
|
102953
|
+
accountCount
|
|
102453
102954
|
);
|
|
102955
|
+
scannedAddresses = restored.scannedAddresses;
|
|
102454
102956
|
store = await WalletStore.open(paths.directory, {
|
|
102455
102957
|
secrets: getSecretStore(dependencies),
|
|
102456
102958
|
env: dependencies.env ?? process.env,
|
|
@@ -102503,22 +103005,35 @@ async function setupCommand(argv, json2, io, dependencies) {
|
|
|
102503
103005
|
}
|
|
102504
103006
|
if (json2) {
|
|
102505
103007
|
io.stdout(
|
|
102506
|
-
JSON.stringify({
|
|
103008
|
+
JSON.stringify({
|
|
103009
|
+
vault,
|
|
103010
|
+
account,
|
|
103011
|
+
address: address4,
|
|
103012
|
+
linked,
|
|
103013
|
+
steps,
|
|
103014
|
+
cloudBackup,
|
|
103015
|
+
...scannedAddresses === void 0 ? {} : { scannedAddresses }
|
|
103016
|
+
})
|
|
102507
103017
|
);
|
|
102508
103018
|
}
|
|
102509
103019
|
}
|
|
102510
|
-
async function restoreVaultFromPhrase(phrase, config2, io, dependencies) {
|
|
103020
|
+
async function restoreVaultFromPhrase(phrase, config2, io, dependencies, accountCount) {
|
|
102511
103021
|
const paths = getVapiPaths();
|
|
102512
103022
|
const validatedPhrase = validateRecoveryPhrase(phrase);
|
|
102513
103023
|
const readBalance3 = baseUsdcBalanceReader(config2, dependencies);
|
|
102514
103024
|
const key2 = await loadOrCreateDeviceKey({ secrets: getSecretStore(dependencies) });
|
|
102515
103025
|
let names;
|
|
103026
|
+
let scannedAddresses = 0;
|
|
102516
103027
|
try {
|
|
102517
103028
|
const restored = await restoreVault({
|
|
102518
103029
|
path: join26(paths.directory, "vault.json"),
|
|
102519
103030
|
key: key2,
|
|
102520
103031
|
phrase: validatedPhrase,
|
|
102521
103032
|
probe: async (address4) => await readBalance3(address4) > 0n,
|
|
103033
|
+
...accountCount === void 0 ? {} : { accountCount },
|
|
103034
|
+
onScanComplete: (count) => {
|
|
103035
|
+
scannedAddresses = count;
|
|
103036
|
+
},
|
|
102522
103037
|
...dependencies.now === void 0 ? {} : { now: dependencies.now }
|
|
102523
103038
|
});
|
|
102524
103039
|
names = restored.accounts().map((account) => account.name);
|
|
@@ -102530,8 +103045,25 @@ async function restoreVaultFromPhrase(phrase, config2, io, dependencies) {
|
|
|
102530
103045
|
...names[0] === void 0 ? {} : { wallet: names[0] },
|
|
102531
103046
|
detail: `${names.length} account(s)`
|
|
102532
103047
|
});
|
|
102533
|
-
io.stdout(
|
|
102534
|
-
|
|
103048
|
+
io.stdout(
|
|
103049
|
+
`Vault restored with ${names.length} account(s): ${names.join(", ")}. ${scannedAddresses} address(es) scanned.`
|
|
103050
|
+
);
|
|
103051
|
+
return { names, scannedAddresses };
|
|
103052
|
+
}
|
|
103053
|
+
function parseAccountCount(value) {
|
|
103054
|
+
if (value === void 0) return void 0;
|
|
103055
|
+
if (!/^\d+$/u.test(value)) {
|
|
103056
|
+
throw new UsageError(
|
|
103057
|
+
`--accounts must be a positive integer no greater than ${MAX_RESTORE_ACCOUNTS}.`
|
|
103058
|
+
);
|
|
103059
|
+
}
|
|
103060
|
+
const count = Number(value);
|
|
103061
|
+
if (!Number.isSafeInteger(count) || count < 1 || count > MAX_RESTORE_ACCOUNTS) {
|
|
103062
|
+
throw new UsageError(
|
|
103063
|
+
`--accounts must be a positive integer no greater than ${MAX_RESTORE_ACCOUNTS}.`
|
|
103064
|
+
);
|
|
103065
|
+
}
|
|
103066
|
+
return count;
|
|
102535
103067
|
}
|
|
102536
103068
|
async function vaultChoice(dependencies) {
|
|
102537
103069
|
const answer = dependencies.prompts?.line === void 0 ? isInteractive(dependencies) ? await promptForLine(VAULT_CHOICE) : "" : await dependencies.prompts.line(VAULT_CHOICE);
|
|
@@ -102631,10 +103163,10 @@ var TASK_HELP = `Usage:
|
|
|
102631
103163
|
vapi task propose <id> --price <usd> --duration <duration> --note <text> [--account <name>] [--json]
|
|
102632
103164
|
vapi task submit <id> --proof <https-url> [--proof <https-url>...] [--file <path>...] [--account <name>] [--json]
|
|
102633
103165
|
vapi task award <id> <proposalId> [--account <name>] [--json]
|
|
102634
|
-
vapi task sign <id> [--yes] [--counterparty <0x\u2026>] [--account <name>] [--json]
|
|
102635
|
-
vapi task fund <id> [--yes] [--counterparty <0x\u2026>] [--account <name>] [--json]
|
|
102636
|
-
vapi task deliver <id> --files <path...> --note <text> [--counterparty <0x\u2026>] [--account <name>] [--json]
|
|
102637
|
-
vapi task release <id> [--counterparty <0x\u2026>] [--account <name>] [--json]
|
|
103166
|
+
vapi task sign <id> [--yes] [--no-wait] [--timeout 120s] [--counterparty <0x\u2026>] [--account <name>] [--json]
|
|
103167
|
+
vapi task fund <id> [--yes] [--no-wait] [--timeout 120s] [--counterparty <0x\u2026>] [--account <name>] [--json]
|
|
103168
|
+
vapi task deliver <id> --files <path...> --note <text> [--no-wait] [--timeout 120s] [--counterparty <0x\u2026>] [--account <name>] [--json]
|
|
103169
|
+
vapi task release <id> [--no-wait] [--timeout 120s] [--counterparty <0x\u2026>] [--account <name>] [--json]
|
|
102638
103170
|
vapi task refund <id> [--counterparty <0x\u2026>] [--account <name>] [--json]
|
|
102639
103171
|
vapi task dispute <id> --evidence-hash <0x + 64 hex> [--yes] [--counterparty <0x\u2026>] [--account <name>] [--json]
|
|
102640
103172
|
vapi task counter-evidence <id> --evidence-hash <0x + 64 hex> [--yes] [--counterparty <0x\u2026>] [--account <name>] [--json]
|
|
@@ -102657,23 +103189,25 @@ Exit codes:
|
|
|
102657
103189
|
2 policy refusal only (JSON ok:false with reason policy.perTask or policy.perDay)
|
|
102658
103190
|
3 approval needed in non-interactive mode
|
|
102659
103191
|
|
|
102660
|
-
Fund, deliver, release, refund, dispute, counter-evidence, resolve-unmatched and watch auto-release sign with the local vault wallet. The CLI waits for two confirmations and records pending transactions for recovery. It never retries a chain mutation automatically.`;
|
|
103192
|
+
Fund, deliver, release, refund, dispute, counter-evidence, resolve-unmatched and watch auto-release sign with the local vault wallet. The CLI waits for two confirmations and records pending transactions for recovery. It never retries a chain mutation automatically. Sign, fund, deliver and release wait up to 120s for vAPI to index a confirmed transaction unless --no-wait is set; an indexing timeout keeps exit code 0.`;
|
|
102661
103193
|
var IMPLEMENTED_VERBS = TASKS_CLIENT_VERBS;
|
|
102662
103194
|
var USAGE = `Usage: vapi task <${IMPLEMENTED_VERBS.join("|")}>. Run vapi task --help.`;
|
|
102663
103195
|
var TaskCommandError = class extends Error {
|
|
102664
|
-
constructor(code, message, manifestHash) {
|
|
103196
|
+
constructor(code, message, manifestHash, prefixCode = false) {
|
|
102665
103197
|
super(message);
|
|
102666
103198
|
this.code = code;
|
|
102667
103199
|
this.manifestHash = manifestHash;
|
|
103200
|
+
this.prefixCode = prefixCode;
|
|
102668
103201
|
this.name = "TaskCommandError";
|
|
102669
103202
|
}
|
|
102670
103203
|
code;
|
|
102671
103204
|
manifestHash;
|
|
103205
|
+
prefixCode;
|
|
102672
103206
|
};
|
|
102673
103207
|
function mapTaskError(error61) {
|
|
102674
103208
|
if (error61 instanceof TaskInputError) return new UsageError(error61.message);
|
|
102675
103209
|
if (error61 instanceof TaskOperationError)
|
|
102676
|
-
return new TaskCommandError(error61.code, error61.message, error61.manifestHash);
|
|
103210
|
+
return new TaskCommandError(error61.code, error61.message, error61.manifestHash, true);
|
|
102677
103211
|
return error61;
|
|
102678
103212
|
}
|
|
102679
103213
|
async function mapped(operation) {
|
|
@@ -102892,11 +103426,13 @@ async function taskCommandInner(argv, json2, io, dependencies) {
|
|
|
102892
103426
|
"--intake",
|
|
102893
103427
|
"--max-awards",
|
|
102894
103428
|
"--webhook"
|
|
102895
|
-
] : verb === "propose" ? ["--price", "--duration", "--note"] : verb === "submit" ? ["--proof", "--file"] : verb === "thread" ? ["--after"] : verb === "deliver" ? ["--files", "--note"] : ["dispute", "counter-evidence"].includes(verb) ? ["--evidence-hash"] : verb === "watch" ? ["--until", "--timeout", "--interval"] : []
|
|
103429
|
+
] : verb === "propose" ? ["--price", "--duration", "--note"] : verb === "submit" ? ["--proof", "--file"] : verb === "thread" ? ["--after"] : verb === "deliver" ? ["--files", "--note"] : ["dispute", "counter-evidence"].includes(verb) ? ["--evidence-hash"] : verb === "watch" ? ["--until", "--timeout", "--interval"] : [],
|
|
103430
|
+
...["sign", "fund", "deliver", "release"].includes(verb) ? ["--timeout"] : []
|
|
102896
103431
|
]),
|
|
102897
103432
|
booleanOptions: /* @__PURE__ */ new Set([
|
|
102898
103433
|
...verb === "search" ? ["--open"] : [],
|
|
102899
103434
|
...["sign", "fund", "dispute", "counter-evidence"].includes(verb) ? ["--yes"] : [],
|
|
103435
|
+
...["sign", "fund", "deliver", "release"].includes(verb) ? ["--no-wait"] : [],
|
|
102900
103436
|
...verb === "watch" ? ["--auto-release"] : []
|
|
102901
103437
|
]),
|
|
102902
103438
|
repeatableOptions: /* @__PURE__ */ new Set([
|
|
@@ -103052,7 +103588,7 @@ async function taskCommandInner(argv, json2, io, dependencies) {
|
|
|
103052
103588
|
throw new UsageError("message needs text between 1 and 10000 characters.");
|
|
103053
103589
|
}
|
|
103054
103590
|
if (verb === "thread") cursor2 = optionalInteger(parsed.one("--after"), "--after");
|
|
103055
|
-
const context = await taskContext(parsed, io, dependencies
|
|
103591
|
+
const context = await taskContext(parsed, io, dependencies);
|
|
103056
103592
|
if (verb === "show" || verb === "status") {
|
|
103057
103593
|
if (verb === "show" && context.token) {
|
|
103058
103594
|
const result = await showTask(context, { id: id2, signedIn: true });
|
|
@@ -103062,7 +103598,21 @@ async function taskCommandInner(argv, json2, io, dependencies) {
|
|
|
103062
103598
|
...receipts.map((receipt) => `Receipt (from escrow): ${receipt.receiptUrl}`)
|
|
103063
103599
|
]);
|
|
103064
103600
|
} else {
|
|
103065
|
-
const result = verb === "status" ? await taskStatus(context, { id: id2 }) : await showTask(context, { id: id2, signedIn: false });
|
|
103601
|
+
const result = verb === "status" ? await taskStatus(context, { id: id2, signedIn: Boolean(context.token) }) : await showTask(context, { id: id2, signedIn: false });
|
|
103602
|
+
if ("chainState" in result) {
|
|
103603
|
+
const milestoneLines = result.chainState.milestones.map((milestone) => {
|
|
103604
|
+
const ordinal = "ordinal" in milestone && typeof milestone.ordinal === "number" && Number.isFinite(milestone.ordinal) ? milestone.ordinal : milestone.milestoneId;
|
|
103605
|
+
const state = "state" in milestone.read ? ` ${milestone.read.state}` : "";
|
|
103606
|
+
const explorer = milestone.explorerUrl ? ` ${milestone.explorerUrl}` : "";
|
|
103607
|
+
return `milestone ${ordinal}: ${milestone.read.status}${state}${explorer}`;
|
|
103608
|
+
});
|
|
103609
|
+
const eventLines = (result.events ?? []).slice(-10).map((event) => {
|
|
103610
|
+
const createdAt = "createdAt" in event && typeof event.createdAt === "string" ? event.createdAt : event.at;
|
|
103611
|
+
return `${event.sequence} ${event.type} ${createdAt}`;
|
|
103612
|
+
});
|
|
103613
|
+
taskOutput(io, json2, context, verb, result, [...milestoneLines, ...eventLines]);
|
|
103614
|
+
return;
|
|
103615
|
+
}
|
|
103066
103616
|
const task = result.task;
|
|
103067
103617
|
taskOutput(
|
|
103068
103618
|
io,
|
|
@@ -103106,6 +103656,11 @@ async function taskCommandInner(argv, json2, io, dependencies) {
|
|
|
103106
103656
|
async function escrowTaskCommand(verb, id2, parsed, json2, io, dependencies, now) {
|
|
103107
103657
|
taskCounterparty(parsed);
|
|
103108
103658
|
if (verb === "watch") return await watchTask(id2, parsed, json2, io, dependencies, now);
|
|
103659
|
+
const waitsForIndex = ["sign", "fund", "deliver", "release"].includes(verb);
|
|
103660
|
+
const waitTimeoutText = parsed.one("--timeout") ?? "120s";
|
|
103661
|
+
const waitTimeoutMs = waitsForIndex ? parseTaskDuration2(waitTimeoutText, now) : void 0;
|
|
103662
|
+
if (waitTimeoutMs !== void 0 && waitTimeoutMs <= 0)
|
|
103663
|
+
throw new UsageError("--timeout must be positive.");
|
|
103109
103664
|
const disputeEvidenceHash = ["dispute", "counter-evidence"].includes(verb) ? required3(parsed, "--evidence-hash") : void 0;
|
|
103110
103665
|
const counterparty = taskCounterparty(parsed);
|
|
103111
103666
|
if (disputeEvidenceHash !== void 0 && !TASK_LIMITS.disputeEvidenceHash.test(disputeEvidenceHash))
|
|
@@ -103155,9 +103710,24 @@ async function escrowTaskCommand(verb, id2, parsed, json2, io, dependencies, now
|
|
|
103155
103710
|
return await account.signMessage({ message });
|
|
103156
103711
|
}
|
|
103157
103712
|
});
|
|
103158
|
-
|
|
103713
|
+
if (!json2 && result2.escrowCreation?.resumedFromServer)
|
|
103714
|
+
io.stdout("The server had already prepared escrow creation; resumed from it.");
|
|
103715
|
+
const wait3 = result2.escrowCreation ? await waitForTaskIndex(
|
|
103716
|
+
context,
|
|
103717
|
+
dependencies,
|
|
103718
|
+
parsed,
|
|
103719
|
+
json2,
|
|
103720
|
+
io,
|
|
103721
|
+
id2,
|
|
103722
|
+
result2.escrowCreation,
|
|
103723
|
+
"created",
|
|
103724
|
+
"escrow creation",
|
|
103725
|
+
waitTimeoutText,
|
|
103726
|
+
waitTimeoutMs
|
|
103727
|
+
) : null;
|
|
103728
|
+
taskOutput(io, json2, displayContext, verb, { ...result2, wait: wait3 }, [
|
|
103159
103729
|
`Accepted scope for task ${id2}.`,
|
|
103160
|
-
...result2.escrowCreation
|
|
103730
|
+
...result2.escrowCreation && (wait3 === null || wait3.reached) ? ["escrow created"] : []
|
|
103161
103731
|
]);
|
|
103162
103732
|
return;
|
|
103163
103733
|
} catch (error61) {
|
|
@@ -103191,7 +103761,23 @@ async function escrowTaskCommand(verb, id2, parsed, json2, io, dependencies, now
|
|
|
103191
103761
|
taskOutput(io, false, context, verb, {}, [`Prepared delivery manifest ${manifestHash}.`]);
|
|
103192
103762
|
}
|
|
103193
103763
|
});
|
|
103194
|
-
|
|
103764
|
+
const wait3 = await waitForTaskIndex(
|
|
103765
|
+
context,
|
|
103766
|
+
dependencies,
|
|
103767
|
+
parsed,
|
|
103768
|
+
json2,
|
|
103769
|
+
io,
|
|
103770
|
+
id2,
|
|
103771
|
+
outcome.result,
|
|
103772
|
+
"delivered",
|
|
103773
|
+
"delivery",
|
|
103774
|
+
waitTimeoutText,
|
|
103775
|
+
waitTimeoutMs
|
|
103776
|
+
);
|
|
103777
|
+
taskOutput(io, json2, context, verb, { ...outcome, wait: wait3 }, [
|
|
103778
|
+
...wait3 === null || wait3.reached ? ["delivery recorded"] : [],
|
|
103779
|
+
...outcome.result.resumedFromServer === true ? ["The server had already recorded this delivery; resumed from it."] : []
|
|
103780
|
+
]);
|
|
103195
103781
|
return;
|
|
103196
103782
|
}
|
|
103197
103783
|
const snapshot = await taskMoneySnapshot(context.client, id2, void 0, {
|
|
@@ -103254,15 +103840,82 @@ async function escrowTaskCommand(verb, id2, parsed, json2, io, dependencies, now
|
|
|
103254
103840
|
}
|
|
103255
103841
|
if (!outcome.ok && "declined" in outcome)
|
|
103256
103842
|
throw new TaskCommandError("not_approved", "Not approved; nothing was signed.");
|
|
103257
|
-
|
|
103258
|
-
|
|
103259
|
-
|
|
103843
|
+
if (!json2 && outcome.result.resumedFromServer)
|
|
103844
|
+
io.stdout("The server had already prepared this task operation; resumed from it.");
|
|
103845
|
+
const wait3 = verb === "fund" ? await waitForTaskIndex(
|
|
103846
|
+
context,
|
|
103847
|
+
dependencies,
|
|
103848
|
+
parsed,
|
|
103849
|
+
json2,
|
|
103850
|
+
io,
|
|
103851
|
+
id2,
|
|
103852
|
+
outcome.result,
|
|
103853
|
+
"locked",
|
|
103854
|
+
"funding",
|
|
103855
|
+
waitTimeoutText,
|
|
103856
|
+
waitTimeoutMs
|
|
103857
|
+
) : void 0;
|
|
103858
|
+
taskOutput(
|
|
103859
|
+
io,
|
|
103860
|
+
json2,
|
|
103861
|
+
context,
|
|
103862
|
+
verb,
|
|
103863
|
+
wait3 === void 0 ? outcome : { ...outcome, wait: wait3 },
|
|
103864
|
+
verb === "fund" ? wait3 === null || wait3?.reached ? ["escrow funded"] : [] : [`Completed task ${verb} for ${id2}.`]
|
|
103865
|
+
);
|
|
103260
103866
|
return;
|
|
103261
103867
|
}
|
|
103262
103868
|
if (!json2) io.stdout("Policy: explicit user instruction.");
|
|
103263
103869
|
const settlementInput = { id: id2, snapshot, ...counterparty === void 0 ? {} : { counterparty } };
|
|
103264
103870
|
const result = verb === "release" ? await releaseTaskOperation(context, settlementInput) : verb === "refund" ? await refundTaskOperation(context, settlementInput) : await resolveUnmatchedTaskOperation(context, settlementInput);
|
|
103265
|
-
|
|
103871
|
+
if (!json2 && result.result.resumedFromServer)
|
|
103872
|
+
io.stdout("The server had already prepared this task operation; resumed from it.");
|
|
103873
|
+
const wait2 = verb === "release" ? await waitForTaskIndex(
|
|
103874
|
+
context,
|
|
103875
|
+
dependencies,
|
|
103876
|
+
parsed,
|
|
103877
|
+
json2,
|
|
103878
|
+
io,
|
|
103879
|
+
id2,
|
|
103880
|
+
result.result,
|
|
103881
|
+
"released",
|
|
103882
|
+
"release",
|
|
103883
|
+
waitTimeoutText,
|
|
103884
|
+
waitTimeoutMs
|
|
103885
|
+
) : void 0;
|
|
103886
|
+
taskOutput(
|
|
103887
|
+
io,
|
|
103888
|
+
json2,
|
|
103889
|
+
context,
|
|
103890
|
+
verb,
|
|
103891
|
+
wait2 === void 0 ? result : { ...result, wait: wait2 },
|
|
103892
|
+
verb === "release" ? wait2 === null || wait2?.reached ? ["funds released"] : [] : [`Completed task ${verb} for ${id2}.`]
|
|
103893
|
+
);
|
|
103894
|
+
}
|
|
103895
|
+
async function waitForTaskIndex(context, dependencies, parsed, json2, io, orderId, result, target, description, timeoutText, timeoutMs) {
|
|
103896
|
+
if (parsed.has("--no-wait")) return null;
|
|
103897
|
+
if (!json2)
|
|
103898
|
+
io.stdout(
|
|
103899
|
+
`confirmed on chain${result.blockNumber === void 0 ? "" : ` in block ${result.blockNumber}`}, waiting for vAPI to index\u2026`
|
|
103900
|
+
);
|
|
103901
|
+
const wait2 = await taskRequest2(
|
|
103902
|
+
description,
|
|
103903
|
+
"getOrder",
|
|
103904
|
+
() => waitForMilestone(context.client, {
|
|
103905
|
+
orderId,
|
|
103906
|
+
milestoneId: result.milestone.id,
|
|
103907
|
+
target,
|
|
103908
|
+
timeoutMs,
|
|
103909
|
+
intervalMs: 3e3,
|
|
103910
|
+
sleep: context.sleep,
|
|
103911
|
+
now: dependencies.now ?? (() => /* @__PURE__ */ new Date())
|
|
103912
|
+
})
|
|
103913
|
+
);
|
|
103914
|
+
if (!wait2.reached)
|
|
103915
|
+
io.stderr(
|
|
103916
|
+
`vAPI has not indexed the ${description} yet after ${timeoutText}; run vapi task status ${orderId} later.`
|
|
103917
|
+
);
|
|
103918
|
+
return wait2;
|
|
103266
103919
|
}
|
|
103267
103920
|
var ScopeApprovalNeeded = class extends Error {
|
|
103268
103921
|
constructor(terms) {
|
|
@@ -104518,6 +105171,7 @@ async function referencedSleep(milliseconds, signal) {
|
|
|
104518
105171
|
// ../cli/src/vault.ts
|
|
104519
105172
|
import { join as join27 } from "node:path";
|
|
104520
105173
|
var VAULT_USAGE = "Usage: vapi vault protect|unprotect|lock|unlock|status [--json]";
|
|
105174
|
+
var RESTORE_USAGE = "Usage: vapi restore [--accounts <n> | --from-owner [--owner <0x\u2026>]] [--json]";
|
|
104521
105175
|
var LEGACY_PASSWORD_NOTICE = "VAPI_KEYSTORE_PASSWORD is deprecated for vault passwords; use VAPI_VAULT_PASSWORD instead.";
|
|
104522
105176
|
async function vaultCommand(argv, json2, io, dependencies) {
|
|
104523
105177
|
const subcommand = argv[0];
|
|
@@ -104547,9 +105201,17 @@ async function restoreCommand(argv, json2, io, dependencies) {
|
|
|
104547
105201
|
await restoreFromOwnerCommand(argv, json2, io, dependencies);
|
|
104548
105202
|
return;
|
|
104549
105203
|
}
|
|
104550
|
-
|
|
104551
|
-
|
|
105204
|
+
let parsed;
|
|
105205
|
+
try {
|
|
105206
|
+
parsed = parseArguments(argv, {
|
|
105207
|
+
valueOptions: /* @__PURE__ */ new Set(["--accounts"]),
|
|
105208
|
+
maximumPositionals: 0
|
|
105209
|
+
});
|
|
105210
|
+
} catch (error61) {
|
|
105211
|
+
if (error61 instanceof UsageError) throw new UsageError(RESTORE_USAGE);
|
|
105212
|
+
throw error61;
|
|
104552
105213
|
}
|
|
105214
|
+
const accountCount = parseRestoreAccountCount(parsed.one("--accounts"));
|
|
104553
105215
|
const paths = getVapiPaths();
|
|
104554
105216
|
const path = join27(paths.directory, "vault.json");
|
|
104555
105217
|
if (await fileExists2(path)) {
|
|
@@ -104563,13 +105225,39 @@ async function restoreCommand(argv, json2, io, dependencies) {
|
|
|
104563
105225
|
const config2 = await readConfig(paths.config, json2 ? quietIo(io) : io);
|
|
104564
105226
|
const phrase = isStdinInteractive(dependencies) ? await getPrompts(dependencies).secret("Recovery phrase: ") : await (dependencies.readStdin ?? readProcessStdin3)();
|
|
104565
105227
|
const restoreIo = json2 ? quietIo(io) : io;
|
|
104566
|
-
const { names } = await restoreVaultFromPhrase(
|
|
105228
|
+
const { names, scannedAddresses } = await restoreVaultFromPhrase(
|
|
105229
|
+
phrase.trim(),
|
|
105230
|
+
config2,
|
|
105231
|
+
restoreIo,
|
|
105232
|
+
dependencies,
|
|
105233
|
+
accountCount
|
|
105234
|
+
);
|
|
104567
105235
|
if (json2) {
|
|
104568
|
-
output3(
|
|
105236
|
+
output3(
|
|
105237
|
+
io,
|
|
105238
|
+
true,
|
|
105239
|
+
{ command: "restore", vault: "restored", accounts: names, scannedAddresses },
|
|
105240
|
+
""
|
|
105241
|
+
);
|
|
104569
105242
|
return;
|
|
104570
105243
|
}
|
|
104571
105244
|
io.stdout(`Run vapi setup to link ${names[0]}.`);
|
|
104572
105245
|
}
|
|
105246
|
+
function parseRestoreAccountCount(value) {
|
|
105247
|
+
if (value === void 0) return void 0;
|
|
105248
|
+
if (!/^\d+$/u.test(value)) {
|
|
105249
|
+
throw new UsageError(
|
|
105250
|
+
`--accounts must be a positive integer no greater than ${MAX_RESTORE_ACCOUNTS}.`
|
|
105251
|
+
);
|
|
105252
|
+
}
|
|
105253
|
+
const count = Number(value);
|
|
105254
|
+
if (!Number.isSafeInteger(count) || count < 1 || count > MAX_RESTORE_ACCOUNTS) {
|
|
105255
|
+
throw new UsageError(
|
|
105256
|
+
`--accounts must be a positive integer no greater than ${MAX_RESTORE_ACCOUNTS}.`
|
|
105257
|
+
);
|
|
105258
|
+
}
|
|
105259
|
+
return count;
|
|
105260
|
+
}
|
|
104573
105261
|
async function protectCommand(argv, json2, io, dependencies) {
|
|
104574
105262
|
requireNoArguments(argv);
|
|
104575
105263
|
const env = getEnvironment(dependencies);
|
|
@@ -104699,8 +105387,8 @@ var HELP_HEADING = "vAPI Network";
|
|
|
104699
105387
|
var HELP = `${HELP_HEADING}
|
|
104700
105388
|
|
|
104701
105389
|
Usage:
|
|
104702
|
-
vapi init [--networks <base,arc
|
|
104703
|
-
vapi setup [--no-cloud-backup] [--json]
|
|
105390
|
+
vapi init [--networks <base,arc>] [--json]
|
|
105391
|
+
vapi setup [--no-cloud-backup] [--accounts <n>] [--json]
|
|
104704
105392
|
vapi accounts [--all] [--json]
|
|
104705
105393
|
vapi accounts add <name> [--label <text>] [--no-link] [--json]
|
|
104706
105394
|
vapi accounts import <name> [--keystore <path> | --key-file <path>] [--label <text>] [--json]
|
|
@@ -104730,7 +105418,7 @@ Usage:
|
|
|
104730
105418
|
vapi docs read <url-or-path> [--json]
|
|
104731
105419
|
vapi search [query] [--kind <kind>] [--network <caip2>] [--limit <n>] [--cursor <cursor>] [--include-unverified] [--json]
|
|
104732
105420
|
vapi inspect <id> [--endpoint <name>] [--json]
|
|
104733
|
-
vapi pay <id-or-url> [--method <method>] [--endpoint <name>] [--body <json>] [--content-type <type>] [--network <caip2>] [--expected-pay-to <address>] [--max <amount>] [--account <name>] [--json]
|
|
105421
|
+
vapi pay <id-or-url> [--method <method>] [--endpoint <name>] [--body <json>] [--content-type <type>] [--network <caip2>] [--expected-pay-to <address>] [--max <amount>] [--timeout <seconds>] [--account <name>] [--json]
|
|
104734
105422
|
vapi pay --resume <receipt-id> [--json]
|
|
104735
105423
|
vapi check <url> [--method <method>] [--json]
|
|
104736
105424
|
vapi balance [--account <name>] [--json]
|
|
@@ -104776,8 +105464,8 @@ Usage:
|
|
|
104776
105464
|
vapi task status <id> [--account <name>] [--json]
|
|
104777
105465
|
vapi export-key [--network <caip2>] [--account <name>] [--json]
|
|
104778
105466
|
vapi backup [--account <name>] [--cloud [off]] [--json]
|
|
104779
|
-
vapi restore [--from-owner [--owner <0x\u2026>]] [--json]
|
|
104780
|
-
vapi import (--phrase | --key) [--account <name>] [--networks <base,arc
|
|
105467
|
+
vapi restore [--accounts <n> | --from-owner [--owner <0x\u2026>]] [--json]
|
|
105468
|
+
vapi import (--phrase | --key) [--account <name>] [--networks <base,arc>] [--replace] [--force] [--json]
|
|
104781
105469
|
vapi passphrase [--account <name>] [--json]
|
|
104782
105470
|
vapi vault protect [--json]
|
|
104783
105471
|
vapi vault unprotect [--json]
|
|
@@ -104805,6 +105493,8 @@ Every command that touches a wallet takes \`--account <name>\`, falls back to \`
|
|
|
104805
105493
|
|
|
104806
105494
|
\`vapi search\` answers with vAPI-verified listings plus the mirrored external catalogs. \`--include-unverified\` also returns self-listed APIs that passed vAPI's automated x402 probe but were never reviewed; every result is tagged \`[verified]\`, \`[requested]\`, \`[unverified]\` or \`[external]\`.
|
|
104807
105495
|
|
|
105496
|
+
Solana listings remain searchable; inspect and pay return \`unsupported_network\`. Solana keys are not part of the device vault yet.
|
|
105497
|
+
|
|
104808
105498
|
\`vapi docs\` asks the public vAPI documentation assistant; \`vapi docs search\` searches documentation excerpts and \`vapi docs read\` reads one Markdown page. They need no account, wallet or payment.
|
|
104809
105499
|
|
|
104810
105500
|
\`vapi task --help\` lists task options and availability. Task exit codes: 0 ok, 1 error, 2 policy refusal (JSON ok:false with a policy. reason) or invalid usage (JSON error), 3 approval needed in non-interactive mode. Posting moves no money; the current create-order contract does not store amount, deadline, intake, max awards or webhook yet.
|
|
@@ -104817,7 +105507,7 @@ Every command that touches a wallet takes \`--account <name>\`, falls back to \`
|
|
|
104817
105507
|
|
|
104818
105508
|
\`vapi vault protect\` adds a password to the device vault. \`vapi vault unlock\` opens it on this device for 8 hours; for unattended use, set \`VAPI_VAULT_PASSWORD\`. \`vapi unlock\` and \`vapi lock\` remain aliases for one release.
|
|
104819
105509
|
|
|
104820
|
-
\`vapi backup\` and \`vapi export-key\` print a secret, so they run only on a real terminal, never for an agent, and ask you to type the wallet name first. \`vapi backup --cloud\` keeps an encrypted vault copy that only the owner can approve for recovery. \`vapi restore\` rebuilds the vault from the phrase and re-derives accounts until
|
|
105510
|
+
\`vapi backup\` and \`vapi export-key\` print a secret, so they run only on a real terminal, never for an agent, and ask you to type the wallet name first. \`vapi backup --cloud\` keeps an encrypted vault copy that only the owner can approve for recovery. \`vapi restore\` rebuilds the vault from the phrase and re-derives accounts until five consecutive addresses have no Base USDC, and reports the number scanned. Use \`--accounts <n>\` with restore or setup to recover a fixed count without querying balances. Set \`VAPI_NO_SECRETS=1\` to switch exports off entirely. Every export and every wallet change is logged to ~/.vapi/audit.log.
|
|
104821
105511
|
|
|
104822
105512
|
\`vapi publish <url>\` lists an API you own. vAPI probes the URL \u2014 an origin, one endpoint, or an OpenAPI document \u2014 you choose which endpoints to list, and your wallet signs one line naming where the payouts go. Listing is permissionless: a listing that passed the probe goes live with \`vapi publish activate <slug>\`, and \`vapi publish verify-request <slug>\` asks for the review that puts it in the default search. Deploying the FeeSplitter that receives the payouts is a wallet transaction and stays in the console. A catalog of more than 20 endpoints is listed as several listings of up to 20, with one result line per endpoint; \`--resume\` skips every endpoint this key already lists.
|
|
104823
105513
|
|
|
@@ -105194,6 +105884,7 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
|
|
|
105194
105884
|
error: message,
|
|
105195
105885
|
exitCode: code,
|
|
105196
105886
|
...error61 instanceof RuntimeError ? { code: error61.code } : {},
|
|
105887
|
+
...error61 instanceof VapiCallError ? { code: error61.code } : {},
|
|
105197
105888
|
...error61 instanceof DocsError ? { code: error61.code } : {},
|
|
105198
105889
|
...error61 instanceof RemoteKeyRefusedError ? { code: error61.code } : {},
|
|
105199
105890
|
...error61 instanceof TransferError ? { code: error61.code, moneyMoved: error61.moneyMoved } : {}
|
|
@@ -105201,7 +105892,10 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
|
|
|
105201
105892
|
);
|
|
105202
105893
|
}
|
|
105203
105894
|
} else {
|
|
105204
|
-
|
|
105895
|
+
const errorCode2 = taskInvocation && error61 instanceof TaskCommandError && error61.prefixCode ? errorCodeOf(error61) : void 0;
|
|
105896
|
+
runIo.stderr(
|
|
105897
|
+
errorCode2 !== void 0 && !message.startsWith(`${errorCode2}: `) ? `${errorCode2}: ${message}` : message
|
|
105898
|
+
);
|
|
105205
105899
|
}
|
|
105206
105900
|
if (shouldAutoUploadAfterFailure(argv.filter((argument) => argument !== "--json"))) {
|
|
105207
105901
|
await autoUploadBackup(io, json2, dependencies);
|
|
@@ -105602,7 +106296,7 @@ async function inspectCommand(argv, json2, io, dependencies) {
|
|
|
105602
106296
|
);
|
|
105603
106297
|
output3(io, json2, result, formatInspect(result));
|
|
105604
106298
|
}
|
|
105605
|
-
var PAY_USAGE = "Usage: vapi pay <id-or-url> [--method <method>] [--endpoint <name>] [--body <json>] [--content-type <type>] [--network <caip2>] [--expected-pay-to <address>] [--max <amount>] [--account <name>] [--json]";
|
|
106299
|
+
var PAY_USAGE = "Usage: vapi pay <id-or-url> [--method <method>] [--endpoint <name>] [--body <json>] [--content-type <type>] [--network <caip2>] [--expected-pay-to <address>] [--max <amount>] [--timeout <seconds>] [--account <name>] [--json]";
|
|
105606
106300
|
async function payCommand(argv, json2, io, dependencies) {
|
|
105607
106301
|
if (argv.includes(RESUME_OPTION)) {
|
|
105608
106302
|
await payResumeCommand(argv, json2, io, dependencies);
|
|
@@ -105618,11 +106312,13 @@ async function payCommand(argv, json2, io, dependencies) {
|
|
|
105618
106312
|
"--expected-pay-to",
|
|
105619
106313
|
"--max",
|
|
105620
106314
|
"--max-price-usd",
|
|
106315
|
+
"--timeout",
|
|
105621
106316
|
WALLET_OPTION5
|
|
105622
106317
|
]),
|
|
105623
106318
|
maximumPositionals: 1
|
|
105624
106319
|
});
|
|
105625
106320
|
const target = requiredPositional(parsed.positionals[0], "<id-or-url>", PAY_USAGE);
|
|
106321
|
+
const timeoutSeconds = optionalBoundedInteger(parsed.one("--timeout"), "--timeout", 1, 300);
|
|
105626
106322
|
const paths = getVapiPaths();
|
|
105627
106323
|
const config2 = await readConfig(paths.config, io);
|
|
105628
106324
|
const wallet = await targetWallet(parsed, dependencies);
|
|
@@ -105638,7 +106334,8 @@ async function payCommand(argv, json2, io, dependencies) {
|
|
|
105638
106334
|
...parsed.one("--content-type") ? { contentType: parsed.one("--content-type") } : {},
|
|
105639
106335
|
...parsed.one("--network") ? { network: parsed.one("--network") } : {},
|
|
105640
106336
|
...parsed.one("--expected-pay-to") ? { expectedPayTo: parsed.one("--expected-pay-to") } : {},
|
|
105641
|
-
...maxPriceUsd ? { maxPriceUsd } : {}
|
|
106337
|
+
...maxPriceUsd ? { maxPriceUsd } : {},
|
|
106338
|
+
...timeoutSeconds === void 0 ? {} : { timeoutSeconds }
|
|
105642
106339
|
};
|
|
105643
106340
|
const call2 = createCallPort({
|
|
105644
106341
|
config: config2,
|
|
@@ -107313,7 +108010,7 @@ function buildNextSteps(address4) {
|
|
|
107313
108010
|
formatNextStep("Pay", "vapi pay <ref> --max 0.02"),
|
|
107314
108011
|
formatNextStep(
|
|
107315
108012
|
"Agent",
|
|
107316
|
-
'add {"command":"npx","args":["-y","vapi-network","mcp"]} to your MCP config'
|
|
108013
|
+
'add {"command":"npx","args":["-y","vapi-network@latest","mcp"]} to your MCP config'
|
|
107317
108014
|
)
|
|
107318
108015
|
];
|
|
107319
108016
|
}
|
|
@@ -107494,6 +108191,17 @@ function optionalPositiveInteger(value, option) {
|
|
|
107494
108191
|
if (result === 0) throw new UsageError(`${option} must be a positive integer.`);
|
|
107495
108192
|
return result;
|
|
107496
108193
|
}
|
|
108194
|
+
function optionalBoundedInteger(value, option, minimum, maximum) {
|
|
108195
|
+
if (value === void 0) return void 0;
|
|
108196
|
+
if (!/^\d+$/.test(value)) {
|
|
108197
|
+
throw new UsageError(`${option} must be an integer from ${minimum} to ${maximum}.`);
|
|
108198
|
+
}
|
|
108199
|
+
const parsed = Number(value);
|
|
108200
|
+
if (!Number.isSafeInteger(parsed) || parsed < minimum || parsed > maximum) {
|
|
108201
|
+
throw new UsageError(`${option} must be an integer from ${minimum} to ${maximum}.`);
|
|
108202
|
+
}
|
|
108203
|
+
return parsed;
|
|
108204
|
+
}
|
|
107497
108205
|
function optionalUsdAmount(value, option) {
|
|
107498
108206
|
if (value === void 0) return void 0;
|
|
107499
108207
|
if (!/^\d+(?:\.\d{1,2})?$/.test(value)) {
|
|
@@ -107554,12 +108262,138 @@ function parseInitNetworks(value) {
|
|
|
107554
108262
|
}
|
|
107555
108263
|
for (const network of networks) {
|
|
107556
108264
|
if (network !== "base" && network !== "arc" && network !== "solana") {
|
|
107557
|
-
throw new UsageError("--networks supports base
|
|
108265
|
+
throw new UsageError("--networks supports base and arc; Solana vault setup is unavailable.");
|
|
107558
108266
|
}
|
|
107559
108267
|
}
|
|
107560
108268
|
return networks;
|
|
107561
108269
|
}
|
|
107562
108270
|
|
|
108271
|
+
// ../cli/src/update-check.ts
|
|
108272
|
+
import { lookup } from "node:dns/promises";
|
|
108273
|
+
import { mkdir as mkdir21, readFile as readFile29, writeFile as writeFile12 } from "node:fs/promises";
|
|
108274
|
+
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
108275
|
+
var CHECK_TIMEOUT_MS = 1500;
|
|
108276
|
+
var LATEST_URL = "https://registry.npmjs.org/vapi-network/latest";
|
|
108277
|
+
async function runCliWithUpdateCheck(argv = process.argv.slice(2), io = {
|
|
108278
|
+
stdout: (message) => console.log(message),
|
|
108279
|
+
stderr: (message) => console.error(message)
|
|
108280
|
+
}, dependencies = {}, options = {}) {
|
|
108281
|
+
const notice = checkForUpdate({ ...options, env: options.env ?? dependencies.env, argv });
|
|
108282
|
+
const code = await runCli(argv, io, dependencies);
|
|
108283
|
+
const message = await notice;
|
|
108284
|
+
if (message) io.stderr(message);
|
|
108285
|
+
return code;
|
|
108286
|
+
}
|
|
108287
|
+
async function checkForUpdate(options = {}) {
|
|
108288
|
+
const env = options.env ?? process.env;
|
|
108289
|
+
const argv = options.argv ?? process.argv.slice(2);
|
|
108290
|
+
if (!(options.stderrIsTTY ?? process.stderr.isTTY) || argv.includes("--json") || argv[0] === "mcp" && argv[1] !== "install" || env.VAPI_NO_UPDATE_CHECK === "1" || env.CI !== void 0) {
|
|
108291
|
+
return void 0;
|
|
108292
|
+
}
|
|
108293
|
+
const controller = new AbortController();
|
|
108294
|
+
let timer;
|
|
108295
|
+
try {
|
|
108296
|
+
return await Promise.race([
|
|
108297
|
+
latestNotice(options, env, controller.signal),
|
|
108298
|
+
new Promise((resolve2) => {
|
|
108299
|
+
timer = setTimeout(() => {
|
|
108300
|
+
controller.abort();
|
|
108301
|
+
resolve2(void 0);
|
|
108302
|
+
}, CHECK_TIMEOUT_MS);
|
|
108303
|
+
})
|
|
108304
|
+
]);
|
|
108305
|
+
} catch {
|
|
108306
|
+
return void 0;
|
|
108307
|
+
} finally {
|
|
108308
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
108309
|
+
controller.abort();
|
|
108310
|
+
}
|
|
108311
|
+
}
|
|
108312
|
+
async function latestNotice(options, env, signal) {
|
|
108313
|
+
const paths = getVapiPaths(options.home ?? (env.VAPI_HOME?.trim() || void 0));
|
|
108314
|
+
const now = (options.nowMs ?? Date.now)();
|
|
108315
|
+
let cached2;
|
|
108316
|
+
try {
|
|
108317
|
+
const value = JSON.parse(await readFile29(paths.updateCheck, "utf8"));
|
|
108318
|
+
if (isRecord12(value) && typeof value.checkedAt === "number" && Number.isFinite(value.checkedAt) && typeof value.latest === "string" && parseVersion(value.latest)) {
|
|
108319
|
+
cached2 = { checkedAt: value.checkedAt, latest: value.latest };
|
|
108320
|
+
}
|
|
108321
|
+
} catch {
|
|
108322
|
+
}
|
|
108323
|
+
signal.throwIfAborted();
|
|
108324
|
+
let latest = cached2?.latest ?? CLI_VERSION;
|
|
108325
|
+
if (cached2 === void 0 || now - cached2.checkedAt >= CHECK_INTERVAL_MS || now < cached2.checkedAt) {
|
|
108326
|
+
await mkdir21(paths.directory, { recursive: true });
|
|
108327
|
+
signal.throwIfAborted();
|
|
108328
|
+
await writeFile12(paths.updateCheck, JSON.stringify({ checkedAt: now, latest }), { mode: 384 });
|
|
108329
|
+
signal.throwIfAborted();
|
|
108330
|
+
const fetchImpl = options.fetchImpl ?? createPublicFetch({
|
|
108331
|
+
allowPrivateNetwork: false,
|
|
108332
|
+
lookup: async (hostname3) => {
|
|
108333
|
+
let onAbort;
|
|
108334
|
+
const aborted2 = new Promise((_resolve, reject) => {
|
|
108335
|
+
onAbort = () => reject(signal.reason);
|
|
108336
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
108337
|
+
});
|
|
108338
|
+
try {
|
|
108339
|
+
signal.throwIfAborted();
|
|
108340
|
+
const addresses = await Promise.race([lookup(hostname3, { all: true }), aborted2]);
|
|
108341
|
+
return addresses.map(({ address: address4 }) => address4);
|
|
108342
|
+
} finally {
|
|
108343
|
+
signal.removeEventListener("abort", onAbort);
|
|
108344
|
+
}
|
|
108345
|
+
}
|
|
108346
|
+
});
|
|
108347
|
+
const response = await fetchImpl(LATEST_URL, { signal, redirect: "error" });
|
|
108348
|
+
if (!response.ok) return void 0;
|
|
108349
|
+
const body = await response.json();
|
|
108350
|
+
signal.throwIfAborted();
|
|
108351
|
+
if (!isRecord12(body) || typeof body.version !== "string" || !parseVersion(body.version)) {
|
|
108352
|
+
return void 0;
|
|
108353
|
+
}
|
|
108354
|
+
latest = body.version;
|
|
108355
|
+
await writeFile12(paths.updateCheck, JSON.stringify({ checkedAt: now, latest }), { mode: 384 });
|
|
108356
|
+
}
|
|
108357
|
+
signal.throwIfAborted();
|
|
108358
|
+
return isNewerVersion(latest, CLI_VERSION) ? `vapi-network ${latest} is available (you have ${CLI_VERSION}). Update: npm i -g vapi-network@latest` : void 0;
|
|
108359
|
+
}
|
|
108360
|
+
function isRecord12(value) {
|
|
108361
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
108362
|
+
}
|
|
108363
|
+
function parseVersion(version5) {
|
|
108364
|
+
const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([\da-zA-Z.-]+))?(?:\+[\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*)?$/.exec(
|
|
108365
|
+
version5
|
|
108366
|
+
);
|
|
108367
|
+
if (!match) return void 0;
|
|
108368
|
+
const prerelease = match[4]?.split(".");
|
|
108369
|
+
if (prerelease?.some((part) => part === "" || /^\d+$/.test(part) && /^0\d/.test(part))) {
|
|
108370
|
+
return void 0;
|
|
108371
|
+
}
|
|
108372
|
+
return { core: match.slice(1, 4).map(BigInt), prerelease };
|
|
108373
|
+
}
|
|
108374
|
+
function isNewerVersion(latest, current) {
|
|
108375
|
+
const next = parseVersion(latest);
|
|
108376
|
+
const running = parseVersion(current);
|
|
108377
|
+
for (let index2 = 0; index2 < 3; index2 += 1) {
|
|
108378
|
+
if (next.core[index2] !== running.core[index2]) return next.core[index2] > running.core[index2];
|
|
108379
|
+
}
|
|
108380
|
+
if (running.prerelease === void 0) return false;
|
|
108381
|
+
if (next.prerelease === void 0) return true;
|
|
108382
|
+
for (let index2 = 0; index2 < Math.max(next.prerelease.length, running.prerelease.length); index2 += 1) {
|
|
108383
|
+
const a = next.prerelease[index2];
|
|
108384
|
+
const b = running.prerelease[index2];
|
|
108385
|
+
if (a === b) continue;
|
|
108386
|
+
if (a === void 0) return false;
|
|
108387
|
+
if (b === void 0) return true;
|
|
108388
|
+
const aNumeric = /^\d+$/.test(a);
|
|
108389
|
+
const bNumeric = /^\d+$/.test(b);
|
|
108390
|
+
if (aNumeric && bNumeric) return BigInt(a) > BigInt(b);
|
|
108391
|
+
if (aNumeric !== bNumeric) return !aNumeric;
|
|
108392
|
+
return a > b;
|
|
108393
|
+
}
|
|
108394
|
+
return false;
|
|
108395
|
+
}
|
|
108396
|
+
|
|
107563
108397
|
// src/cli.ts
|
|
107564
|
-
process.exitCode = await
|
|
108398
|
+
process.exitCode = await runCliWithUpdateCheck();
|
|
107565
108399
|
//# sourceMappingURL=cli.js.map
|