@vapi-network/core 0.8.0 → 0.9.2
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 +14 -1
- package/dist/agent-link.d.ts.map +1 -1
- package/dist/agent-link.js +6 -1
- package/dist/agent-link.js.map +1 -1
- package/dist/agent-profile.d.ts +4 -0
- package/dist/agent-profile.d.ts.map +1 -1
- package/dist/api-key.js +47 -0
- package/dist/api-key.js.map +1 -1
- package/dist/backup.d.ts +2 -0
- package/dist/backup.d.ts.map +1 -1
- package/dist/backup.js +65 -0
- package/dist/backup.js.map +1 -1
- package/dist/call-contracts-wire.d.ts +48 -12
- package/dist/call-contracts-wire.d.ts.map +1 -1
- package/dist/call-contracts.d.ts +7 -1
- package/dist/call-contracts.d.ts.map +1 -1
- package/dist/cloud-backup.js +71 -1
- package/dist/cloud-backup.js.map +1 -1
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/docs.d.ts +40 -0
- package/dist/docs.d.ts.map +1 -0
- package/dist/funding-policy.d.ts +29 -0
- package/dist/funding-policy.d.ts.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1521 -795
- package/dist/index.js.map +3 -3
- package/dist/marketplace-contracts.d.ts +22 -10
- package/dist/marketplace-contracts.d.ts.map +1 -1
- package/dist/router-client.js +230 -33
- package/dist/router-client.js.map +2 -2
- package/dist/searches.d.ts +1 -0
- package/dist/searches.d.ts.map +1 -1
- package/dist/secrets.js +29 -1
- package/dist/secrets.js.map +1 -1
- package/dist/spend-policy.d.ts +41 -7
- package/dist/spend-policy.d.ts.map +1 -1
- package/dist/support-report.d.ts +1 -1
- package/dist/tasks/actions.d.ts +152 -0
- package/dist/tasks/actions.d.ts.map +1 -0
- package/dist/tasks/canonical-json.d.ts +6 -0
- package/dist/tasks/canonical-json.d.ts.map +1 -0
- package/dist/tasks/chain-error.d.ts +6 -0
- package/dist/tasks/chain-error.d.ts.map +1 -0
- package/dist/tasks/chain-port.d.ts +90 -0
- package/dist/tasks/chain-port.d.ts.map +1 -0
- package/dist/tasks/chain-verification.d.ts +36 -0
- package/dist/tasks/chain-verification.d.ts.map +1 -0
- package/dist/tasks/chain.d.ts +22 -0
- package/dist/tasks/chain.d.ts.map +1 -0
- package/dist/tasks/client.d.ts +76 -0
- package/dist/tasks/client.d.ts.map +1 -0
- package/dist/tasks/delivery-manifest.d.ts +24 -0
- package/dist/tasks/delivery-manifest.d.ts.map +1 -0
- package/dist/tasks/dispute-fee.d.ts +4 -0
- package/dist/tasks/dispute-fee.d.ts.map +1 -0
- package/dist/tasks/index.d.ts +23 -0
- package/dist/tasks/index.d.ts.map +1 -0
- package/dist/tasks/money.d.ts +17 -0
- package/dist/tasks/money.d.ts.map +1 -0
- package/dist/tasks/operation-support.d.ts +127 -0
- package/dist/tasks/operation-support.d.ts.map +1 -0
- package/dist/tasks/operations.d.ts +777 -0
- package/dist/tasks/operations.d.ts.map +1 -0
- package/dist/tasks/pending-transactions.d.ts +52 -0
- package/dist/tasks/pending-transactions.d.ts.map +1 -0
- package/dist/tasks/plan-guard.d.ts +326 -0
- package/dist/tasks/plan-guard.d.ts.map +1 -0
- package/dist/tasks/rpc.d.ts +8 -0
- package/dist/tasks/rpc.d.ts.map +1 -0
- package/dist/tasks/scope-bindings.d.ts +20 -0
- package/dist/tasks/scope-bindings.d.ts.map +1 -0
- package/dist/tasks/scope-terms.d.ts +75 -0
- package/dist/tasks/scope-terms.d.ts.map +1 -0
- package/dist/tasks/trusted-deployments.d.ts +14 -0
- package/dist/tasks/trusted-deployments.d.ts.map +1 -0
- package/dist/tasks/types.d.ts +4439 -0
- package/dist/tasks/types.d.ts.map +1 -0
- package/dist/tasks/verbs.d.ts +4 -0
- package/dist/tasks/verbs.d.ts.map +1 -0
- package/dist/tasks/wait.d.ts +18 -0
- package/dist/tasks/wait.d.ts.map +1 -0
- package/dist/tasks.js +44108 -0
- package/dist/tasks.js.map +6 -0
- package/dist/transfer.d.ts.map +1 -1
- package/dist/x402-networks.d.ts +1 -0
- package/dist/x402-networks.d.ts.map +1 -1
- package/package.json +5 -1
package/dist/index.js
CHANGED
|
@@ -28912,378 +28912,6 @@ function date4(params) {
|
|
|
28912
28912
|
return _coercedDate(ZodDate, params);
|
|
28913
28913
|
}
|
|
28914
28914
|
|
|
28915
|
-
// src/marketplace-contracts.ts
|
|
28916
|
-
var MARKETPLACE_DISCOVERY_PROTOCOL = "vapi.marketplace.discovery/1";
|
|
28917
|
-
var MARKETPLACE_RANKING_VERSION = "marketplace-ranking-v1";
|
|
28918
|
-
var MARKETPLACE_KINDS = ["api", "service_offer", "open_request"];
|
|
28919
|
-
var MARKETPLACE_EXECUTION_METHODS = [
|
|
28920
|
-
"GET",
|
|
28921
|
-
"HEAD",
|
|
28922
|
-
"POST",
|
|
28923
|
-
"PUT",
|
|
28924
|
-
"PATCH",
|
|
28925
|
-
"DELETE"
|
|
28926
|
-
];
|
|
28927
|
-
var marketplaceExecutionMethodSchema = external_exports.enum(MARKETPLACE_EXECUTION_METHODS);
|
|
28928
|
-
var marketplaceKindSchema = external_exports.enum(MARKETPLACE_KINDS);
|
|
28929
|
-
var EXECUTION_MODES = ["direct", "gateway"];
|
|
28930
|
-
var executionModeSchema = external_exports.enum(EXECUTION_MODES);
|
|
28931
|
-
var PROVENANCES = ["indexed", "self_listed", "partner"];
|
|
28932
|
-
var provenanceSchema = external_exports.enum(PROVENANCES);
|
|
28933
|
-
var FIRST_PARTY_PROVENANCES = ["self_listed", "partner"];
|
|
28934
|
-
var firstPartyProvenanceSchema = external_exports.enum(FIRST_PARTY_PROVENANCES);
|
|
28935
|
-
var LISTING_GROUPS = ["vapi", "added", "partner", "external"];
|
|
28936
|
-
var listingGroupSchema = external_exports.enum(LISTING_GROUPS);
|
|
28937
|
-
var listingFeeSchema = external_exports.looseObject({
|
|
28938
|
-
bps: external_exports.number().int().min(0),
|
|
28939
|
-
label: external_exports.string()
|
|
28940
|
-
});
|
|
28941
|
-
var LISTING_VERIFICATIONS = ["none", "requested", "verified"];
|
|
28942
|
-
var listingVerificationSchema = external_exports.enum(LISTING_VERIFICATIONS);
|
|
28943
|
-
var listingVerificationFieldSchema = listingVerificationSchema.default("none").catch("none");
|
|
28944
|
-
var listingLivenessSchema = external_exports.looseObject({
|
|
28945
|
-
uptime7d: external_exports.number().min(0).max(1),
|
|
28946
|
-
latencyP50Ms: external_exports.number().nonnegative().nullable(),
|
|
28947
|
-
latencyP95Ms: external_exports.number().nonnegative().nullable(),
|
|
28948
|
-
checks7d: external_exports.number().int().nonnegative()
|
|
28949
|
-
});
|
|
28950
|
-
var listingConformanceSchema = external_exports.looseObject({
|
|
28951
|
-
declaredVersion: external_exports.union([external_exports.literal(1), external_exports.literal(2)]).nullable(),
|
|
28952
|
-
versionConformant: external_exports.boolean(),
|
|
28953
|
-
offerTransport: external_exports.enum(["body", "header", "both"]),
|
|
28954
|
-
issues: external_exports.array(external_exports.string())
|
|
28955
|
-
});
|
|
28956
|
-
var listingIdentitySchema = external_exports.looseObject({
|
|
28957
|
-
erc8004Id: external_exports.string().trim().min(1),
|
|
28958
|
-
reputation: external_exports.looseObject({
|
|
28959
|
-
score: external_exports.number().finite(),
|
|
28960
|
-
count: external_exports.number().int().nonnegative()
|
|
28961
|
-
}).optional().catch(void 0)
|
|
28962
|
-
});
|
|
28963
|
-
var listingDisclosureShape = {
|
|
28964
|
-
group: listingGroupSchema.optional(),
|
|
28965
|
-
fee: listingFeeSchema.optional(),
|
|
28966
|
-
verification: listingVerificationFieldSchema,
|
|
28967
|
-
liveness: listingLivenessSchema.optional().catch(void 0),
|
|
28968
|
-
conformance: listingConformanceSchema.optional().catch(void 0),
|
|
28969
|
-
identity: listingIdentitySchema.optional().catch(void 0)
|
|
28970
|
-
};
|
|
28971
|
-
var marketplaceBadgeCodeSchema = external_exports.enum([
|
|
28972
|
-
"live_x402",
|
|
28973
|
-
"partner",
|
|
28974
|
-
"payout_wallet_confirmed",
|
|
28975
|
-
"vapi_verified",
|
|
28976
|
-
"external_catalog",
|
|
28977
|
-
"approved_vendor"
|
|
28978
|
-
]);
|
|
28979
|
-
var marketplaceBadgeSchema = external_exports.looseObject({
|
|
28980
|
-
code: marketplaceBadgeCodeSchema,
|
|
28981
|
-
label: external_exports.string().trim().min(1).max(80)
|
|
28982
|
-
});
|
|
28983
|
-
var marketplacePublicFactSchema = external_exports.looseObject({
|
|
28984
|
-
label: external_exports.string().trim().min(1).max(80),
|
|
28985
|
-
value: external_exports.string().trim().min(1).max(160)
|
|
28986
|
-
});
|
|
28987
|
-
var marketplaceHrefSchema = external_exports.union([
|
|
28988
|
-
external_exports.string().trim().min(1).max(2048).regex(/^\/(?!\/)/),
|
|
28989
|
-
external_exports.url().max(2048).regex(/^https:\/\//)
|
|
28990
|
-
]);
|
|
28991
|
-
var marketplaceCardSchema = external_exports.looseObject({
|
|
28992
|
-
title: external_exports.string().trim().min(1).max(160),
|
|
28993
|
-
summary: external_exports.string().trim().min(1).max(1e3),
|
|
28994
|
-
byline: external_exports.string().trim().min(1).max(160).optional(),
|
|
28995
|
-
bylineHref: marketplaceHrefSchema.optional(),
|
|
28996
|
-
badges: external_exports.array(marketplaceBadgeSchema).max(8),
|
|
28997
|
-
facts: external_exports.array(marketplacePublicFactSchema).max(12)
|
|
28998
|
-
});
|
|
28999
|
-
var marketplaceHitBase = {
|
|
29000
|
-
ref: external_exports.string().trim().min(1).max(512),
|
|
29001
|
-
card: marketplaceCardSchema,
|
|
29002
|
-
...listingDisclosureShape
|
|
29003
|
-
};
|
|
29004
|
-
var invokeApiActionSchema = external_exports.looseObject({
|
|
29005
|
-
type: external_exports.literal("invoke_api"),
|
|
29006
|
-
href: marketplaceHrefSchema
|
|
29007
|
-
});
|
|
29008
|
-
var firstPartyApiMarketplaceHitSchema = external_exports.looseObject({
|
|
29009
|
-
...marketplaceHitBase,
|
|
29010
|
-
kind: external_exports.literal("api"),
|
|
29011
|
-
provenance: firstPartyProvenanceSchema,
|
|
29012
|
-
execution: external_exports.looseObject({
|
|
29013
|
-
mode: executionModeSchema
|
|
29014
|
-
}),
|
|
29015
|
-
action: invokeApiActionSchema
|
|
29016
|
-
});
|
|
29017
|
-
var mirroredApiMarketplaceHitSchema = external_exports.looseObject({
|
|
29018
|
-
...marketplaceHitBase,
|
|
29019
|
-
kind: external_exports.literal("api"),
|
|
29020
|
-
provenance: external_exports.literal("indexed"),
|
|
29021
|
-
execution: external_exports.looseObject({
|
|
29022
|
-
mode: external_exports.literal("direct"),
|
|
29023
|
-
url: external_exports.url().max(2048).regex(/^https:\/\/(?![^/?#]*@)/),
|
|
29024
|
-
method: marketplaceExecutionMethodSchema.nullable(),
|
|
29025
|
-
network: external_exports.string().trim().max(160).regex(/^eip155:[1-9]\d*$/)
|
|
29026
|
-
}),
|
|
29027
|
-
action: invokeApiActionSchema
|
|
29028
|
-
});
|
|
29029
|
-
var apiMarketplaceHitSchema = external_exports.discriminatedUnion("provenance", [
|
|
29030
|
-
firstPartyApiMarketplaceHitSchema,
|
|
29031
|
-
mirroredApiMarketplaceHitSchema
|
|
29032
|
-
]);
|
|
29033
|
-
var serviceOfferMarketplaceHitSchema = external_exports.looseObject({
|
|
29034
|
-
...marketplaceHitBase,
|
|
29035
|
-
kind: external_exports.literal("service_offer"),
|
|
29036
|
-
action: external_exports.looseObject({
|
|
29037
|
-
type: external_exports.literal("start_engagement"),
|
|
29038
|
-
href: marketplaceHrefSchema
|
|
29039
|
-
})
|
|
29040
|
-
});
|
|
29041
|
-
var openRequestMarketplaceHitSchema = external_exports.looseObject({
|
|
29042
|
-
...marketplaceHitBase,
|
|
29043
|
-
kind: external_exports.literal("open_request"),
|
|
29044
|
-
action: external_exports.looseObject({
|
|
29045
|
-
type: external_exports.literal("propose_to_request"),
|
|
29046
|
-
href: marketplaceHrefSchema
|
|
29047
|
-
})
|
|
29048
|
-
});
|
|
29049
|
-
var marketplaceHitSchema = external_exports.union([
|
|
29050
|
-
apiMarketplaceHitSchema,
|
|
29051
|
-
serviceOfferMarketplaceHitSchema,
|
|
29052
|
-
openRequestMarketplaceHitSchema
|
|
29053
|
-
]);
|
|
29054
|
-
var marketplaceDiscoveryInputSchema = external_exports.strictObject({
|
|
29055
|
-
q: external_exports.string().trim().max(200).optional(),
|
|
29056
|
-
kinds: external_exports.array(marketplaceKindSchema).min(1).max(MARKETPLACE_KINDS.length).optional(),
|
|
29057
|
-
network: external_exports.string().trim().min(1).max(160).optional(),
|
|
29058
|
-
cursor: external_exports.string().trim().min(1).max(4096).optional(),
|
|
29059
|
-
limit: external_exports.number().int().min(1).max(50).optional(),
|
|
29060
|
-
includeUnverified: external_exports.boolean().optional()
|
|
29061
|
-
}).superRefine((input2, context) => {
|
|
29062
|
-
if (input2.kinds && new Set(input2.kinds).size !== input2.kinds.length) {
|
|
29063
|
-
context.addIssue({
|
|
29064
|
-
code: "custom",
|
|
29065
|
-
path: ["kinds"],
|
|
29066
|
-
message: "Marketplace kinds must be unique"
|
|
29067
|
-
});
|
|
29068
|
-
}
|
|
29069
|
-
});
|
|
29070
|
-
function isMirroredHit(hit) {
|
|
29071
|
-
return hit.kind === "api" && hit.provenance === "indexed";
|
|
29072
|
-
}
|
|
29073
|
-
var marketplaceDiscoveryPageSchema = external_exports.looseObject({
|
|
29074
|
-
protocol: external_exports.literal(MARKETPLACE_DISCOVERY_PROTOCOL),
|
|
29075
|
-
items: external_exports.array(marketplaceHitSchema),
|
|
29076
|
-
nextCursor: external_exports.string().min(1).max(4096).nullable(),
|
|
29077
|
-
unavailableKinds: external_exports.array(marketplaceKindSchema).max(MARKETPLACE_KINDS.length),
|
|
29078
|
-
rankingVersion: external_exports.literal(MARKETPLACE_RANKING_VERSION)
|
|
29079
|
-
});
|
|
29080
|
-
|
|
29081
|
-
// src/call-contracts-wire.ts
|
|
29082
|
-
var CALLABLE_KIND = "agent";
|
|
29083
|
-
var CALLABLE_CATEGORIES = ["ai", "data", "crypto", "compute", "search"];
|
|
29084
|
-
var callableCategorySchema = external_exports.enum(CALLABLE_CATEGORIES);
|
|
29085
|
-
var DISCOVERY_CATEGORIES = [...CALLABLE_CATEGORIES, "other"];
|
|
29086
|
-
var discoveryCategorySchema = external_exports.enum(DISCOVERY_CATEGORIES);
|
|
29087
|
-
var CALLABLE_CATEGORY_LABELS = {
|
|
29088
|
-
ai: { catalog: "AI / LLM", publish: "AI and models" },
|
|
29089
|
-
data: { catalog: "Data", publish: "Data" },
|
|
29090
|
-
crypto: { catalog: "Crypto", publish: "Crypto" },
|
|
29091
|
-
compute: { catalog: "Compute", publish: "Compute" },
|
|
29092
|
-
search: { catalog: "Search", publish: "Search" }
|
|
29093
|
-
};
|
|
29094
|
-
var CALLABLE_CATEGORY_SET = new Set(CALLABLE_CATEGORIES);
|
|
29095
|
-
function isCallableListing(kind, category) {
|
|
29096
|
-
return kind === CALLABLE_KIND && CALLABLE_CATEGORY_SET.has(category);
|
|
29097
|
-
}
|
|
29098
|
-
var serviceTierSchema = external_exports.enum(["listed", "verified", "partner"]);
|
|
29099
|
-
var discoveryEndpointSchema = external_exports.looseObject({
|
|
29100
|
-
name: external_exports.string(),
|
|
29101
|
-
method: external_exports.string(),
|
|
29102
|
-
url: external_exports.url(),
|
|
29103
|
-
price: external_exports.string(),
|
|
29104
|
-
description: external_exports.string(),
|
|
29105
|
-
operationId: external_exports.string().trim().min(1).optional(),
|
|
29106
|
-
requestContentType: external_exports.string().trim().min(1).optional(),
|
|
29107
|
-
requestSchema: external_exports.json().optional(),
|
|
29108
|
-
responseContentType: external_exports.string().trim().min(1).optional(),
|
|
29109
|
-
pathTemplate: external_exports.string().trim().min(1).optional(),
|
|
29110
|
-
pathParameters: external_exports.array(external_exports.string().trim().min(1)).optional(),
|
|
29111
|
-
payment: external_exports.looseObject({
|
|
29112
|
-
scheme: external_exports.literal("exact"),
|
|
29113
|
-
network: external_exports.string().regex(/^eip155:\d+$/),
|
|
29114
|
-
asset: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
29115
|
-
payTo: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
29116
|
-
checkedAt: external_exports.iso.datetime()
|
|
29117
|
-
}).optional()
|
|
29118
|
-
});
|
|
29119
|
-
var serviceSummarySchema = external_exports.looseObject({
|
|
29120
|
-
id: external_exports.string(),
|
|
29121
|
-
name: external_exports.string(),
|
|
29122
|
-
description: external_exports.string(),
|
|
29123
|
-
category: discoveryCategorySchema,
|
|
29124
|
-
tier: serviceTierSchema,
|
|
29125
|
-
...listingDisclosureShape,
|
|
29126
|
-
verified: external_exports.boolean(),
|
|
29127
|
-
wrapped: external_exports.boolean(),
|
|
29128
|
-
price: external_exports.string(),
|
|
29129
|
-
networks: external_exports.array(external_exports.string()),
|
|
29130
|
-
endpoints: external_exports.array(discoveryEndpointSchema)
|
|
29131
|
-
});
|
|
29132
|
-
var searchServicesResponseSchema = external_exports.looseObject({
|
|
29133
|
-
services: external_exports.array(serviceSummarySchema)
|
|
29134
|
-
});
|
|
29135
|
-
var listServicesResponseSchema = searchServicesResponseSchema;
|
|
29136
|
-
var discoveryServiceSchema = serviceSummarySchema;
|
|
29137
|
-
var discoveryResponseSchema = searchServicesResponseSchema;
|
|
29138
|
-
|
|
29139
|
-
// src/call-contracts.ts
|
|
29140
|
-
var DiscoveryCatalogError = class extends Error {
|
|
29141
|
-
name = "DiscoveryCatalogError";
|
|
29142
|
-
code;
|
|
29143
|
-
serviceId;
|
|
29144
|
-
constructor(code, message, serviceId) {
|
|
29145
|
-
super(message);
|
|
29146
|
-
this.code = code;
|
|
29147
|
-
this.serviceId = serviceId;
|
|
29148
|
-
}
|
|
29149
|
-
};
|
|
29150
|
-
function parseDiscovery(raw) {
|
|
29151
|
-
const parsed = discoveryResponseSchema.safeParse(raw);
|
|
29152
|
-
if (!parsed.success) {
|
|
29153
|
-
const malformedUrl = parsed.error.issues.find(
|
|
29154
|
-
(issue2) => issue2.path.at(-1) === "url" && issue2.path.includes("endpoints")
|
|
29155
|
-
);
|
|
29156
|
-
if (malformedUrl) {
|
|
29157
|
-
const serviceIndex = pathIndexAfter(malformedUrl.path, "services");
|
|
29158
|
-
const serviceId = rawServiceId(raw, serviceIndex);
|
|
29159
|
-
throw new DiscoveryCatalogError(
|
|
29160
|
-
"malformed_url",
|
|
29161
|
-
`Service ${JSON.stringify(serviceId ?? "unknown")} has a malformed endpoint URL.`,
|
|
29162
|
-
serviceId
|
|
29163
|
-
);
|
|
29164
|
-
}
|
|
29165
|
-
throw new DiscoveryCatalogError("invalid_discovery", "Discovery response is malformed.");
|
|
29166
|
-
}
|
|
29167
|
-
for (const service of parsed.data.services) {
|
|
29168
|
-
buildTargets(service);
|
|
29169
|
-
}
|
|
29170
|
-
const resolveListing = (serviceId, endpointName) => {
|
|
29171
|
-
const service = parsed.data.services.find((candidate) => candidate.id === serviceId);
|
|
29172
|
-
if (!service) {
|
|
29173
|
-
throw new DiscoveryCatalogError(
|
|
29174
|
-
"service_not_found",
|
|
29175
|
-
`No payable endpoint found for service ${JSON.stringify(serviceId)}.`,
|
|
29176
|
-
serviceId
|
|
29177
|
-
);
|
|
29178
|
-
}
|
|
29179
|
-
return { service, endpoint: resolveTarget(service, endpointName) };
|
|
29180
|
-
};
|
|
29181
|
-
return {
|
|
29182
|
-
services: parsed.data.services,
|
|
29183
|
-
resolve: (serviceId, endpointName) => resolveListing(serviceId, endpointName).endpoint,
|
|
29184
|
-
resolveListing
|
|
29185
|
-
};
|
|
29186
|
-
}
|
|
29187
|
-
function resolveTarget(service, endpointName) {
|
|
29188
|
-
const { targets, targetsByName } = buildTargets(service);
|
|
29189
|
-
if (endpointName !== void 0) {
|
|
29190
|
-
const selected = targetsByName.get(endpointName.trim());
|
|
29191
|
-
if (!selected) {
|
|
29192
|
-
throw new DiscoveryCatalogError(
|
|
29193
|
-
"endpoint_not_found",
|
|
29194
|
-
`Service ${JSON.stringify(service.id)} has no endpoint ${JSON.stringify(endpointName)}. Available endpoints: ${[...targetsByName.keys()].join(", ")}.`,
|
|
29195
|
-
service.id
|
|
29196
|
-
);
|
|
29197
|
-
}
|
|
29198
|
-
return { ...selected };
|
|
29199
|
-
}
|
|
29200
|
-
if (targets.size !== 1) {
|
|
29201
|
-
throw new DiscoveryCatalogError(
|
|
29202
|
-
"ambiguous_default",
|
|
29203
|
-
`Service ${JSON.stringify(service.id)} has ${targets.size} distinct payable endpoints. Choose one with endpoint: ${[...targetsByName.keys()].join(", ")}.`,
|
|
29204
|
-
service.id
|
|
29205
|
-
);
|
|
29206
|
-
}
|
|
29207
|
-
return targets.values().next().value;
|
|
29208
|
-
}
|
|
29209
|
-
function buildTargets(service) {
|
|
29210
|
-
if (service.endpoints.length === 0) {
|
|
29211
|
-
throw new DiscoveryCatalogError(
|
|
29212
|
-
"no_endpoint",
|
|
29213
|
-
`Service ${JSON.stringify(service.id)} has no payable endpoint.`,
|
|
29214
|
-
service.id
|
|
29215
|
-
);
|
|
29216
|
-
}
|
|
29217
|
-
const namedEndpoints = [...service.endpoints].sort(
|
|
29218
|
-
(left, right) => compareNames(left.name.trim(), right.name.trim())
|
|
29219
|
-
);
|
|
29220
|
-
const names = /* @__PURE__ */ new Set();
|
|
29221
|
-
const targets = /* @__PURE__ */ new Map();
|
|
29222
|
-
const targetsByName = /* @__PURE__ */ new Map();
|
|
29223
|
-
for (const endpoint of namedEndpoints) {
|
|
29224
|
-
const name = endpoint.name.trim();
|
|
29225
|
-
if (!name) {
|
|
29226
|
-
throw new DiscoveryCatalogError(
|
|
29227
|
-
"invalid_endpoint_name",
|
|
29228
|
-
`Service ${JSON.stringify(service.id)} has a blank endpoint name.`,
|
|
29229
|
-
service.id
|
|
29230
|
-
);
|
|
29231
|
-
}
|
|
29232
|
-
if (names.has(name)) {
|
|
29233
|
-
throw new DiscoveryCatalogError(
|
|
29234
|
-
"duplicate_endpoint_name",
|
|
29235
|
-
`Service ${JSON.stringify(service.id)} has duplicate endpoint name ${JSON.stringify(name)}.`,
|
|
29236
|
-
service.id
|
|
29237
|
-
);
|
|
29238
|
-
}
|
|
29239
|
-
names.add(name);
|
|
29240
|
-
const method = endpoint.method.trim().toUpperCase();
|
|
29241
|
-
if (!method) {
|
|
29242
|
-
throw new DiscoveryCatalogError(
|
|
29243
|
-
"blank_method",
|
|
29244
|
-
`Service ${JSON.stringify(service.id)} has a blank endpoint method.`,
|
|
29245
|
-
service.id
|
|
29246
|
-
);
|
|
29247
|
-
}
|
|
29248
|
-
const url2 = new URL(endpoint.url);
|
|
29249
|
-
if (url2.protocol !== "http:" && url2.protocol !== "https:") {
|
|
29250
|
-
throw new DiscoveryCatalogError(
|
|
29251
|
-
"malformed_url",
|
|
29252
|
-
`Service ${JSON.stringify(service.id)} has a non-HTTP endpoint URL.`,
|
|
29253
|
-
service.id
|
|
29254
|
-
);
|
|
29255
|
-
}
|
|
29256
|
-
const transportKey = `${method}\0${endpoint.url}`;
|
|
29257
|
-
const normalized = { ...endpoint, name, method };
|
|
29258
|
-
targetsByName.set(name, normalized);
|
|
29259
|
-
if (!targets.has(transportKey)) targets.set(transportKey, normalized);
|
|
29260
|
-
}
|
|
29261
|
-
return { targets, targetsByName };
|
|
29262
|
-
}
|
|
29263
|
-
function compareNames(left, right) {
|
|
29264
|
-
return left < right ? -1 : left > right ? 1 : 0;
|
|
29265
|
-
}
|
|
29266
|
-
function pathIndexAfter(path, key) {
|
|
29267
|
-
const keyIndex = path.indexOf(key);
|
|
29268
|
-
const candidate = path[keyIndex + 1];
|
|
29269
|
-
return typeof candidate === "number" ? candidate : void 0;
|
|
29270
|
-
}
|
|
29271
|
-
function rawServiceId(raw, serviceIndex) {
|
|
29272
|
-
if (serviceIndex === void 0 || typeof raw !== "object" || raw === null) {
|
|
29273
|
-
return void 0;
|
|
29274
|
-
}
|
|
29275
|
-
const services = Reflect.get(raw, "services");
|
|
29276
|
-
if (!Array.isArray(services)) {
|
|
29277
|
-
return void 0;
|
|
29278
|
-
}
|
|
29279
|
-
const service = services[serviceIndex];
|
|
29280
|
-
if (typeof service !== "object" || service === null) {
|
|
29281
|
-
return void 0;
|
|
29282
|
-
}
|
|
29283
|
-
const id = Reflect.get(service, "id");
|
|
29284
|
-
return typeof id === "string" ? id : void 0;
|
|
29285
|
-
}
|
|
29286
|
-
|
|
29287
28915
|
// ../../node_modules/.pnpm/viem@2.56.1_typescript@6.0.3_zod@4.5.4/node_modules/viem/_esm/utils/getAction.js
|
|
29288
28916
|
function getAction(client, actionFn, name) {
|
|
29289
28917
|
const action_implicit = client[actionFn.name];
|
|
@@ -39074,7 +38702,9 @@ function http(url2, config2 = {}) {
|
|
|
39074
38702
|
// ../../node_modules/.pnpm/viem@2.56.1_typescript@6.0.3_zod@4.5.4/node_modules/viem/_esm/index.js
|
|
39075
38703
|
init_getAddress();
|
|
39076
38704
|
init_isAddress();
|
|
38705
|
+
init_toBytes();
|
|
39077
38706
|
init_toHex();
|
|
38707
|
+
init_keccak256();
|
|
39078
38708
|
|
|
39079
38709
|
// src/x402-networks.ts
|
|
39080
38710
|
var BASE_MAINNET_CAIP2 = "eip155:8453";
|
|
@@ -39082,6 +38712,7 @@ var ARC_MAINNET_CAIP2 = "eip155:5042";
|
|
|
39082
38712
|
var ARC_TESTNET_CAIP2 = "eip155:5042002";
|
|
39083
38713
|
var SOLANA_MAINNET_CAIP2 = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d";
|
|
39084
38714
|
var X402_SOLANA_MAINNET_CAIP2 = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
38715
|
+
var SOLANA_DEVNET_CAIP2 = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
39085
38716
|
var SOLANA_MAINNET_USDC = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
39086
38717
|
function canonicalIdentity(usdc, eip712Domain) {
|
|
39087
38718
|
return Object.freeze({
|
|
@@ -39125,375 +38756,184 @@ var BROWSER_ENABLED_X402_NETWORK_CONFIG = Object.freeze({
|
|
|
39125
38756
|
[ARC_TESTNET_CAIP2]: browserNetwork(arcTestnetUsdc)
|
|
39126
38757
|
});
|
|
39127
38758
|
|
|
39128
|
-
// src/
|
|
39129
|
-
|
|
39130
|
-
|
|
39131
|
-
|
|
39132
|
-
|
|
39133
|
-
|
|
39134
|
-
|
|
39135
|
-
|
|
39136
|
-
|
|
38759
|
+
// src/marketplace-contracts.ts
|
|
38760
|
+
var MARKETPLACE_DISCOVERY_PROTOCOL = "vapi.marketplace.discovery/1";
|
|
38761
|
+
var MARKETPLACE_RANKING_VERSION = "marketplace-ranking-v1";
|
|
38762
|
+
var MARKETPLACE_KINDS = ["api", "service_offer", "open_request"];
|
|
38763
|
+
var MARKETPLACE_EXECUTION_METHODS = [
|
|
38764
|
+
"GET",
|
|
38765
|
+
"HEAD",
|
|
38766
|
+
"POST",
|
|
38767
|
+
"PUT",
|
|
38768
|
+
"PATCH",
|
|
38769
|
+
"DELETE"
|
|
38770
|
+
];
|
|
38771
|
+
var marketplaceExecutionMethodSchema = external_exports.enum(MARKETPLACE_EXECUTION_METHODS);
|
|
38772
|
+
var marketplaceKindSchema = external_exports.enum(MARKETPLACE_KINDS);
|
|
38773
|
+
var EXECUTION_MODES = ["direct", "gateway"];
|
|
38774
|
+
var executionModeSchema = external_exports.enum(EXECUTION_MODES);
|
|
38775
|
+
var PROVENANCES = ["indexed", "self_listed", "partner"];
|
|
38776
|
+
var provenanceSchema = external_exports.enum(PROVENANCES);
|
|
38777
|
+
var FIRST_PARTY_PROVENANCES = ["self_listed", "partner"];
|
|
38778
|
+
var firstPartyProvenanceSchema = external_exports.enum(FIRST_PARTY_PROVENANCES);
|
|
38779
|
+
var LISTING_GROUPS = ["vapi", "added", "partner", "external"];
|
|
38780
|
+
var listingGroupSchema = external_exports.enum(LISTING_GROUPS);
|
|
38781
|
+
var listingFeeSchema = external_exports.looseObject({
|
|
38782
|
+
bps: external_exports.number().int().min(0),
|
|
38783
|
+
label: external_exports.string()
|
|
38784
|
+
});
|
|
38785
|
+
var LISTING_VERIFICATIONS = ["none", "requested", "verified"];
|
|
38786
|
+
var listingVerificationSchema = external_exports.enum(LISTING_VERIFICATIONS);
|
|
38787
|
+
var listingVerificationFieldSchema = listingVerificationSchema.default("none").catch("none");
|
|
38788
|
+
var listingLivenessSchema = external_exports.looseObject({
|
|
38789
|
+
uptime7d: external_exports.number().min(0).max(1),
|
|
38790
|
+
latencyP50Ms: external_exports.number().nonnegative().nullable(),
|
|
38791
|
+
latencyP95Ms: external_exports.number().nonnegative().nullable(),
|
|
38792
|
+
checks7d: external_exports.number().int().nonnegative()
|
|
38793
|
+
});
|
|
38794
|
+
var listingConformanceSchema = external_exports.looseObject({
|
|
38795
|
+
declaredVersion: external_exports.union([external_exports.literal(1), external_exports.literal(2)]).nullable(),
|
|
38796
|
+
versionConformant: external_exports.boolean(),
|
|
38797
|
+
offerTransport: external_exports.enum(["body", "header", "both"]),
|
|
38798
|
+
issues: external_exports.array(external_exports.string())
|
|
38799
|
+
});
|
|
38800
|
+
var listingIdentitySchema = external_exports.looseObject({
|
|
38801
|
+
erc8004Id: external_exports.string().trim().min(1),
|
|
38802
|
+
reputation: external_exports.looseObject({
|
|
38803
|
+
score: external_exports.number().finite(),
|
|
38804
|
+
count: external_exports.number().int().nonnegative()
|
|
38805
|
+
}).optional().catch(void 0)
|
|
38806
|
+
});
|
|
38807
|
+
var listingDisclosureShape = {
|
|
38808
|
+
group: listingGroupSchema.optional(),
|
|
38809
|
+
fee: listingFeeSchema.optional(),
|
|
38810
|
+
verification: listingVerificationFieldSchema,
|
|
38811
|
+
liveness: listingLivenessSchema.optional().catch(void 0),
|
|
38812
|
+
conformance: listingConformanceSchema.optional().catch(void 0),
|
|
38813
|
+
identity: listingIdentitySchema.optional().catch(void 0)
|
|
39137
38814
|
};
|
|
39138
|
-
|
|
39139
|
-
|
|
39140
|
-
|
|
39141
|
-
|
|
39142
|
-
|
|
39143
|
-
|
|
39144
|
-
|
|
39145
|
-
|
|
39146
|
-
|
|
39147
|
-
|
|
39148
|
-
|
|
39149
|
-
|
|
39150
|
-
|
|
39151
|
-
|
|
39152
|
-
|
|
39153
|
-
|
|
39154
|
-
|
|
39155
|
-
|
|
39156
|
-
|
|
39157
|
-
|
|
39158
|
-
|
|
39159
|
-
|
|
39160
|
-
|
|
39161
|
-
|
|
39162
|
-
|
|
39163
|
-
|
|
39164
|
-
|
|
39165
|
-
|
|
39166
|
-
|
|
39167
|
-
|
|
39168
|
-
|
|
39169
|
-
|
|
39170
|
-
}
|
|
39171
|
-
}
|
|
39172
|
-
function createPublicFetch(options) {
|
|
39173
|
-
const lookupFn = options.lookup ?? defaultLookup;
|
|
39174
|
-
return (async (input2, init) => {
|
|
39175
|
-
const url2 = new URL(input2 instanceof Request ? input2.url : input2);
|
|
39176
|
-
await assertPublicUrl(url2, {
|
|
39177
|
-
allowPrivateNetwork: options.allowPrivateNetwork,
|
|
39178
|
-
lookup: lookupFn,
|
|
39179
|
-
timeoutMs: 5e3
|
|
39180
|
-
});
|
|
39181
|
-
const normalized = new Request(input2, init);
|
|
39182
|
-
const bytes = normalized.body ? Buffer.from(await normalized.arrayBuffer()) : null;
|
|
39183
|
-
return await new Promise((resolve2, reject) => {
|
|
39184
|
-
const requestOptions = {
|
|
39185
|
-
method: normalized.method,
|
|
39186
|
-
headers: Object.fromEntries(normalized.headers),
|
|
39187
|
-
signal: normalized.signal,
|
|
39188
|
-
...options.allowPrivateNetwork ? {} : { lookup: pinnedLookup(lookupFn) }
|
|
39189
|
-
};
|
|
39190
|
-
const onResponse = (incoming) => {
|
|
39191
|
-
try {
|
|
39192
|
-
const headers = new Headers();
|
|
39193
|
-
for (const [name, value] of Object.entries(incoming.headers)) {
|
|
39194
|
-
if (Array.isArray(value)) {
|
|
39195
|
-
for (const item of value) headers.append(name, item);
|
|
39196
|
-
} else if (value !== void 0) {
|
|
39197
|
-
headers.set(name, value);
|
|
39198
|
-
}
|
|
39199
|
-
}
|
|
39200
|
-
const status = incoming.statusCode ?? 500;
|
|
39201
|
-
const bodyForbidden = normalized.method === "HEAD" || [204, 205, 304].includes(status);
|
|
39202
|
-
if (bodyForbidden) incoming.resume();
|
|
39203
|
-
const response = new Response(
|
|
39204
|
-
bodyForbidden ? null : Readable.toWeb(incoming),
|
|
39205
|
-
{ status, statusText: incoming.statusMessage, headers }
|
|
39206
|
-
);
|
|
39207
|
-
Object.defineProperty(response, "url", { value: url2.toString() });
|
|
39208
|
-
resolve2(response);
|
|
39209
|
-
} catch (error61) {
|
|
39210
|
-
incoming.destroy();
|
|
39211
|
-
reject(error61);
|
|
39212
|
-
}
|
|
39213
|
-
};
|
|
39214
|
-
const request = url2.protocol === "https:" ? httpsRequest(url2, requestOptions, onResponse) : httpRequest(url2, requestOptions, onResponse);
|
|
39215
|
-
request.on("error", reject);
|
|
39216
|
-
if (bytes) request.write(bytes);
|
|
39217
|
-
request.end();
|
|
39218
|
-
});
|
|
39219
|
-
});
|
|
39220
|
-
}
|
|
39221
|
-
function pinnedLookup(lookup) {
|
|
39222
|
-
return (hostname3, dnsOptions, callback) => {
|
|
39223
|
-
void lookup(normalizeHostname(hostname3)).then((addresses) => {
|
|
39224
|
-
if (addresses.length === 0 || addresses.some(isNonPublicAddress)) {
|
|
39225
|
-
callback(guardError(new URL(`https://${hostname3}`)), "");
|
|
39226
|
-
return;
|
|
39227
|
-
}
|
|
39228
|
-
const address2 = addresses[0];
|
|
39229
|
-
const family = isIP(address2);
|
|
39230
|
-
callback(
|
|
39231
|
-
null,
|
|
39232
|
-
dnsOptions.all ? [{ address: address2, family }] : address2,
|
|
39233
|
-
dnsOptions.all ? void 0 : family
|
|
39234
|
-
);
|
|
39235
|
-
}).catch(
|
|
39236
|
-
(error61) => callback(error61 instanceof Error ? error61 : new Error("DNS lookup failed."), "")
|
|
39237
|
-
);
|
|
39238
|
-
};
|
|
39239
|
-
}
|
|
39240
|
-
async function withTimeout2(operation, timeoutMs) {
|
|
39241
|
-
let timeout;
|
|
39242
|
-
try {
|
|
39243
|
-
return await Promise.race([
|
|
39244
|
-
operation,
|
|
39245
|
-
new Promise((_resolve, reject) => {
|
|
39246
|
-
timeout = setTimeout(() => reject(new Error("DNS lookup timed out.")), timeoutMs);
|
|
39247
|
-
})
|
|
39248
|
-
]);
|
|
39249
|
-
} finally {
|
|
39250
|
-
if (timeout) clearTimeout(timeout);
|
|
39251
|
-
}
|
|
39252
|
-
}
|
|
39253
|
-
function normalizeHostname(hostname3) {
|
|
39254
|
-
const unbracketed = hostname3.startsWith("[") && hostname3.endsWith("]") ? hostname3.slice(1, -1) : hostname3;
|
|
39255
|
-
return unbracketed.endsWith(".") ? unbracketed.slice(0, -1) : unbracketed;
|
|
39256
|
-
}
|
|
39257
|
-
function isNonPublicAddress(address2) {
|
|
39258
|
-
const normalized = normalizeHostname(address2);
|
|
39259
|
-
const version5 = isIP(normalized);
|
|
39260
|
-
if (version5 === 4) {
|
|
39261
|
-
return isNonPublicIpv4(parseIpv4(normalized));
|
|
39262
|
-
}
|
|
39263
|
-
if (version5 === 6) {
|
|
39264
|
-
return isNonPublicIpv6(parseIpv6(normalized));
|
|
39265
|
-
}
|
|
39266
|
-
return true;
|
|
39267
|
-
}
|
|
39268
|
-
function parseIpv4(address2) {
|
|
39269
|
-
const octets = address2.split(".").map(Number);
|
|
39270
|
-
return [octets[0], octets[1], octets[2], octets[3]];
|
|
39271
|
-
}
|
|
39272
|
-
function isNonPublicIpv4([first, second, third]) {
|
|
39273
|
-
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;
|
|
39274
|
-
}
|
|
39275
|
-
function parseIpv6(address2) {
|
|
39276
|
-
let normalized = address2.toLowerCase();
|
|
39277
|
-
const lastColon = normalized.lastIndexOf(":");
|
|
39278
|
-
const dottedTail = normalized.slice(lastColon + 1);
|
|
39279
|
-
if (dottedTail.includes(".")) {
|
|
39280
|
-
const [first, second, third, fourth] = parseIpv4(dottedTail);
|
|
39281
|
-
normalized = `${normalized.slice(0, lastColon + 1)}${(first << 8 | second).toString(16)}:${(third << 8 | fourth).toString(16)}`;
|
|
39282
|
-
}
|
|
39283
|
-
const halves = normalized.split("::");
|
|
39284
|
-
const left = halves[0] ? halves[0].split(":").map(parseHex) : [];
|
|
39285
|
-
const right = halves[1] ? halves[1].split(":").map(parseHex) : [];
|
|
39286
|
-
const omittedCount = 8 - left.length - right.length;
|
|
39287
|
-
return halves.length === 2 ? [...left, ...Array.from({ length: omittedCount }, () => 0), ...right] : left;
|
|
39288
|
-
}
|
|
39289
|
-
function parseHex(value) {
|
|
39290
|
-
return Number.parseInt(value, 16);
|
|
39291
|
-
}
|
|
39292
|
-
function isNonPublicIpv6(hextets) {
|
|
39293
|
-
if (hextets.slice(0, 5).every((hextet) => hextet === 0) && hextets[5] === 65535) {
|
|
39294
|
-
const embeddedIpv4 = [
|
|
39295
|
-
hextets[6] >> 8,
|
|
39296
|
-
hextets[6] & 255,
|
|
39297
|
-
hextets[7] >> 8,
|
|
39298
|
-
hextets[7] & 255
|
|
39299
|
-
];
|
|
39300
|
-
return isNonPublicIpv4(embeddedIpv4);
|
|
39301
|
-
}
|
|
39302
|
-
if (hextets.slice(0, 6).every((hextet) => hextet === 0)) {
|
|
39303
|
-
const compatibleIpv4 = [
|
|
39304
|
-
hextets[6] >> 8,
|
|
39305
|
-
hextets[6] & 255,
|
|
39306
|
-
hextets[7] >> 8,
|
|
39307
|
-
hextets[7] & 255
|
|
39308
|
-
];
|
|
39309
|
-
if (isNonPublicIpv4(compatibleIpv4)) return true;
|
|
39310
|
-
}
|
|
39311
|
-
const isUnspecified = hextets.every((hextet) => hextet === 0);
|
|
39312
|
-
const isLoopback = hextets.slice(0, 7).every((hextet) => hextet === 0) && hextets[7] === 1;
|
|
39313
|
-
const first = hextets[0];
|
|
39314
|
-
const isUniqueLocal = first >= 64512 && first <= 65023;
|
|
39315
|
-
const isLinkLocal = first >= 65152 && first <= 65215;
|
|
39316
|
-
const isSiteLocal = first >= 65216 && first <= 65279;
|
|
39317
|
-
const isMulticast = first >= 65280;
|
|
39318
|
-
const isDocumentation = first === 8193 && hextets[1] === 3512;
|
|
39319
|
-
return isUnspecified || isLoopback || isUniqueLocal || isLinkLocal || isSiteLocal || isMulticast || isDocumentation;
|
|
39320
|
-
}
|
|
39321
|
-
function guardError(url2) {
|
|
39322
|
-
return new Error(
|
|
39323
|
-
`URL hostname ${JSON.stringify(url2.hostname)} is not allowed; private or internal destinations require allowPrivateNetwork true in the vAPI config.`
|
|
39324
|
-
);
|
|
39325
|
-
}
|
|
39326
|
-
|
|
39327
|
-
// src/networks.ts
|
|
39328
|
-
var USDC_DECIMALS = 6;
|
|
39329
|
-
var DEFAULT_ARC_GAS_HEADROOM_ATOMIC = 50000n;
|
|
39330
|
-
var NETWORKS = {
|
|
39331
|
-
[BASE_MAINNET_CAIP2]: {
|
|
39332
|
-
family: "evm",
|
|
39333
|
-
chainId: 8453,
|
|
39334
|
-
name: "Base mainnet",
|
|
39335
|
-
usdc: CANONICAL_X402_USDC_NETWORKS[BASE_MAINNET_CAIP2].usdc,
|
|
39336
|
-
gasToken: "ETH",
|
|
39337
|
-
rpcEnv: "BASE_RPC_URL",
|
|
39338
|
-
publicRpcUrl: "https://mainnet.base.org",
|
|
39339
|
-
explorerUrl: "https://basescan.org"
|
|
39340
|
-
},
|
|
39341
|
-
[ARC_MAINNET_CAIP2]: {
|
|
39342
|
-
family: "evm",
|
|
39343
|
-
chainId: 5042,
|
|
39344
|
-
name: "Arc mainnet",
|
|
39345
|
-
usdc: CANONICAL_X402_USDC_NETWORKS[ARC_MAINNET_CAIP2].usdc,
|
|
39346
|
-
gasToken: "USDC",
|
|
39347
|
-
rpcEnv: "ARC_RPC_URL",
|
|
39348
|
-
publicRpcUrl: "https://rpc.mainnet.arc.io",
|
|
39349
|
-
explorerUrl: "https://explorer.arc.io"
|
|
39350
|
-
},
|
|
39351
|
-
[ARC_TESTNET_CAIP2]: {
|
|
39352
|
-
family: "evm",
|
|
39353
|
-
chainId: 5042002,
|
|
39354
|
-
name: "Arc testnet",
|
|
39355
|
-
usdc: CANONICAL_X402_USDC_NETWORKS[ARC_TESTNET_CAIP2].usdc,
|
|
39356
|
-
gasToken: "USDC",
|
|
39357
|
-
rpcEnv: "ARC_TESTNET_RPC_URL"
|
|
39358
|
-
},
|
|
39359
|
-
[SOLANA_MAINNET_CAIP2]: {
|
|
39360
|
-
family: "svm",
|
|
39361
|
-
name: "Solana mainnet",
|
|
39362
|
-
usdc: SOLANA_MAINNET_USDC,
|
|
39363
|
-
gasToken: "SOL",
|
|
39364
|
-
rpcEnv: "SOLANA_RPC_URL",
|
|
39365
|
-
publicRpcUrl: "https://api.mainnet-beta.solana.com"
|
|
39366
|
-
},
|
|
39367
|
-
[X402_SOLANA_MAINNET_CAIP2]: {
|
|
39368
|
-
family: "svm",
|
|
39369
|
-
name: "Solana mainnet",
|
|
39370
|
-
usdc: SOLANA_MAINNET_USDC,
|
|
39371
|
-
gasToken: "SOL",
|
|
39372
|
-
rpcEnv: "SOLANA_RPC_URL",
|
|
39373
|
-
publicRpcUrl: "https://api.mainnet-beta.solana.com"
|
|
39374
|
-
}
|
|
38815
|
+
var marketplaceBadgeCodeSchema = external_exports.enum([
|
|
38816
|
+
"live_x402",
|
|
38817
|
+
"partner",
|
|
38818
|
+
"payout_wallet_confirmed",
|
|
38819
|
+
"vapi_verified",
|
|
38820
|
+
"external_catalog",
|
|
38821
|
+
"approved_vendor"
|
|
38822
|
+
]);
|
|
38823
|
+
var marketplaceBadgeSchema = external_exports.looseObject({
|
|
38824
|
+
code: marketplaceBadgeCodeSchema,
|
|
38825
|
+
label: external_exports.string().trim().min(1).max(80)
|
|
38826
|
+
});
|
|
38827
|
+
var marketplacePublicFactSchema = external_exports.looseObject({
|
|
38828
|
+
label: external_exports.string().trim().min(1).max(80),
|
|
38829
|
+
value: external_exports.string().trim().min(1).max(160)
|
|
38830
|
+
});
|
|
38831
|
+
var marketplaceHrefSchema = external_exports.union([
|
|
38832
|
+
external_exports.string().trim().min(1).max(2048).regex(/^\/(?!\/)/),
|
|
38833
|
+
external_exports.url().max(2048).regex(/^https:\/\//)
|
|
38834
|
+
]);
|
|
38835
|
+
var marketplaceCardSchema = external_exports.looseObject({
|
|
38836
|
+
title: external_exports.string().trim().min(1).max(160),
|
|
38837
|
+
summary: external_exports.string().trim().min(1).max(1e3),
|
|
38838
|
+
byline: external_exports.string().trim().min(1).max(160).optional(),
|
|
38839
|
+
bylineHref: marketplaceHrefSchema.optional(),
|
|
38840
|
+
badges: external_exports.array(marketplaceBadgeSchema).max(8),
|
|
38841
|
+
facts: external_exports.array(marketplacePublicFactSchema).max(12)
|
|
38842
|
+
});
|
|
38843
|
+
var marketplaceHitBase = {
|
|
38844
|
+
ref: external_exports.string().trim().min(1).max(512),
|
|
38845
|
+
card: marketplaceCardSchema,
|
|
38846
|
+
...listingDisclosureShape
|
|
39375
38847
|
};
|
|
39376
|
-
|
|
39377
|
-
|
|
39378
|
-
|
|
39379
|
-
|
|
39380
|
-
|
|
39381
|
-
|
|
39382
|
-
|
|
39383
|
-
|
|
39384
|
-
|
|
39385
|
-
|
|
39386
|
-
}
|
|
39387
|
-
|
|
39388
|
-
|
|
39389
|
-
|
|
39390
|
-
|
|
39391
|
-
|
|
39392
|
-
|
|
39393
|
-
|
|
39394
|
-
|
|
39395
|
-
|
|
39396
|
-
|
|
39397
|
-
|
|
39398
|
-
|
|
39399
|
-
|
|
39400
|
-
|
|
39401
|
-
|
|
39402
|
-
|
|
39403
|
-
|
|
39404
|
-
|
|
39405
|
-
|
|
39406
|
-
|
|
39407
|
-
|
|
39408
|
-
|
|
39409
|
-
|
|
39410
|
-
|
|
39411
|
-
|
|
39412
|
-
|
|
39413
|
-
|
|
39414
|
-
|
|
39415
|
-
|
|
39416
|
-
|
|
39417
|
-
|
|
39418
|
-
|
|
39419
|
-
|
|
39420
|
-
|
|
39421
|
-
}
|
|
39422
|
-
|
|
39423
|
-
|
|
39424
|
-
|
|
39425
|
-
|
|
39426
|
-
|
|
39427
|
-
|
|
39428
|
-
|
|
39429
|
-
|
|
39430
|
-
|
|
39431
|
-
|
|
39432
|
-
|
|
39433
|
-
|
|
39434
|
-
|
|
39435
|
-
|
|
39436
|
-
|
|
39437
|
-
|
|
39438
|
-
|
|
39439
|
-
|
|
39440
|
-
|
|
39441
|
-
|
|
39442
|
-
|
|
39443
|
-
|
|
39444
|
-
|
|
39445
|
-
|
|
39446
|
-
|
|
39447
|
-
|
|
39448
|
-
|
|
39449
|
-
|
|
39450
|
-
const rpcUrl = envUrl || configured.rpcUrl.trim();
|
|
39451
|
-
if (rpcUrl) {
|
|
39452
|
-
return rpcUrl;
|
|
39453
|
-
}
|
|
39454
|
-
if (network === ARC_TESTNET_CAIP2) {
|
|
39455
|
-
throw new Error(
|
|
39456
|
-
"Arc testnet RPC is required. Set ARC_TESTNET_RPC_URL or add rpcUrl for eip155:5042002 in config.json."
|
|
39457
|
-
);
|
|
39458
|
-
}
|
|
39459
|
-
throw new Error(`RPC URL is required for ${network}.`);
|
|
39460
|
-
}
|
|
39461
|
-
function createChain(network, rpcUrl) {
|
|
39462
|
-
const definition = getNetworkDefinition(network);
|
|
39463
|
-
if (definition.family !== "evm" || definition.chainId === void 0) {
|
|
39464
|
-
throw new Error(`Network ${network} is not an EVM chain.`);
|
|
38848
|
+
var invokeApiActionSchema = external_exports.looseObject({
|
|
38849
|
+
type: external_exports.literal("invoke_api"),
|
|
38850
|
+
href: marketplaceHrefSchema
|
|
38851
|
+
});
|
|
38852
|
+
var firstPartyApiMarketplaceHitSchema = external_exports.looseObject({
|
|
38853
|
+
...marketplaceHitBase,
|
|
38854
|
+
kind: external_exports.literal("api"),
|
|
38855
|
+
provenance: firstPartyProvenanceSchema,
|
|
38856
|
+
execution: external_exports.looseObject({
|
|
38857
|
+
mode: executionModeSchema
|
|
38858
|
+
}),
|
|
38859
|
+
action: invokeApiActionSchema
|
|
38860
|
+
});
|
|
38861
|
+
var mirroredApiMarketplaceHitSchema = external_exports.looseObject({
|
|
38862
|
+
...marketplaceHitBase,
|
|
38863
|
+
kind: external_exports.literal("api"),
|
|
38864
|
+
provenance: external_exports.literal("indexed"),
|
|
38865
|
+
execution: external_exports.looseObject({
|
|
38866
|
+
mode: external_exports.literal("direct"),
|
|
38867
|
+
url: external_exports.url().max(2048).regex(/^https:\/\/(?![^/?#]*@)/),
|
|
38868
|
+
method: marketplaceExecutionMethodSchema.nullable(),
|
|
38869
|
+
network: external_exports.string().trim().max(160).transform((network) => {
|
|
38870
|
+
if (network === "solana") return X402_SOLANA_MAINNET_CAIP2;
|
|
38871
|
+
if (network === "solana-devnet") return SOLANA_DEVNET_CAIP2;
|
|
38872
|
+
return network;
|
|
38873
|
+
}).pipe(
|
|
38874
|
+
external_exports.union([
|
|
38875
|
+
external_exports.string().regex(/^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}$/),
|
|
38876
|
+
// Persisted mainnet configs also use the full genesis hash.
|
|
38877
|
+
external_exports.literal(SOLANA_MAINNET_CAIP2)
|
|
38878
|
+
])
|
|
38879
|
+
)
|
|
38880
|
+
}),
|
|
38881
|
+
action: invokeApiActionSchema
|
|
38882
|
+
});
|
|
38883
|
+
var apiMarketplaceHitSchema = external_exports.discriminatedUnion("provenance", [
|
|
38884
|
+
firstPartyApiMarketplaceHitSchema,
|
|
38885
|
+
mirroredApiMarketplaceHitSchema
|
|
38886
|
+
]);
|
|
38887
|
+
var serviceOfferMarketplaceHitSchema = external_exports.looseObject({
|
|
38888
|
+
...marketplaceHitBase,
|
|
38889
|
+
kind: external_exports.literal("service_offer"),
|
|
38890
|
+
action: external_exports.looseObject({
|
|
38891
|
+
type: external_exports.literal("start_engagement"),
|
|
38892
|
+
href: marketplaceHrefSchema
|
|
38893
|
+
})
|
|
38894
|
+
});
|
|
38895
|
+
var openRequestMarketplaceHitSchema = external_exports.looseObject({
|
|
38896
|
+
...marketplaceHitBase,
|
|
38897
|
+
kind: external_exports.literal("open_request"),
|
|
38898
|
+
action: external_exports.looseObject({
|
|
38899
|
+
type: external_exports.literal("propose_to_request"),
|
|
38900
|
+
href: marketplaceHrefSchema
|
|
38901
|
+
})
|
|
38902
|
+
});
|
|
38903
|
+
var marketplaceHitSchema = external_exports.union([
|
|
38904
|
+
apiMarketplaceHitSchema,
|
|
38905
|
+
serviceOfferMarketplaceHitSchema,
|
|
38906
|
+
openRequestMarketplaceHitSchema
|
|
38907
|
+
]);
|
|
38908
|
+
var marketplaceDiscoveryInputSchema = external_exports.strictObject({
|
|
38909
|
+
q: external_exports.string().trim().max(200).optional(),
|
|
38910
|
+
kinds: external_exports.array(marketplaceKindSchema).min(1).max(MARKETPLACE_KINDS.length).optional(),
|
|
38911
|
+
network: external_exports.string().trim().min(1).max(160).optional(),
|
|
38912
|
+
cursor: external_exports.string().trim().min(1).max(4096).optional(),
|
|
38913
|
+
limit: external_exports.number().int().min(1).max(50).optional(),
|
|
38914
|
+
includeUnverified: external_exports.boolean().optional()
|
|
38915
|
+
}).superRefine((input2, context) => {
|
|
38916
|
+
if (input2.kinds && new Set(input2.kinds).size !== input2.kinds.length) {
|
|
38917
|
+
context.addIssue({
|
|
38918
|
+
code: "custom",
|
|
38919
|
+
path: ["kinds"],
|
|
38920
|
+
message: "Marketplace kinds must be unique"
|
|
38921
|
+
});
|
|
39465
38922
|
}
|
|
39466
|
-
|
|
39467
|
-
|
|
39468
|
-
|
|
39469
|
-
nativeCurrency: definition.gasToken === "USDC" ? { name: "USDC", symbol: "USDC", decimals: USDC_DECIMALS } : { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
39470
|
-
rpcUrls: {
|
|
39471
|
-
default: { http: [rpcUrl] }
|
|
39472
|
-
},
|
|
39473
|
-
...definition.explorerUrl ? {
|
|
39474
|
-
blockExplorers: {
|
|
39475
|
-
default: { name: `${definition.name} explorer`, url: definition.explorerUrl }
|
|
39476
|
-
}
|
|
39477
|
-
} : {}
|
|
39478
|
-
});
|
|
39479
|
-
}
|
|
39480
|
-
function createNetworkPublicClient(network, configured, options = {}) {
|
|
39481
|
-
const rpcUrl = requireRpcUrl(network, configured);
|
|
39482
|
-
return createPublicClient({
|
|
39483
|
-
chain: createChain(network, rpcUrl),
|
|
39484
|
-
transport: createNetworkHttpTransport(rpcUrl, options)
|
|
39485
|
-
});
|
|
39486
|
-
}
|
|
39487
|
-
function createNetworkHttpTransport(rpcUrl, options = {}) {
|
|
39488
|
-
const fetchFn = options.fetch ?? createPublicFetch({
|
|
39489
|
-
allowPrivateNetwork: options.allowPrivateNetwork ?? false,
|
|
39490
|
-
...options.lookup ? { lookup: options.lookup } : {}
|
|
39491
|
-
});
|
|
39492
|
-
return http(rpcUrl, { fetchFn, fetchOptions: { redirect: "manual" } });
|
|
39493
|
-
}
|
|
39494
|
-
function formatUsdc(amountAtomic) {
|
|
39495
|
-
return formatUnits(amountAtomic, USDC_DECIMALS);
|
|
38923
|
+
});
|
|
38924
|
+
function isMirroredHit(hit) {
|
|
38925
|
+
return hit.kind === "api" && hit.provenance === "indexed";
|
|
39496
38926
|
}
|
|
38927
|
+
var marketplaceDiscoveryEnvelopeSchema = external_exports.looseObject({
|
|
38928
|
+
protocol: external_exports.literal(MARKETPLACE_DISCOVERY_PROTOCOL),
|
|
38929
|
+
items: external_exports.array(external_exports.unknown()),
|
|
38930
|
+
nextCursor: external_exports.string().min(1).max(4096).nullable(),
|
|
38931
|
+
unavailableKinds: external_exports.array(marketplaceKindSchema).max(MARKETPLACE_KINDS.length),
|
|
38932
|
+
rankingVersion: external_exports.literal(MARKETPLACE_RANKING_VERSION)
|
|
38933
|
+
});
|
|
38934
|
+
var marketplaceDiscoveryPageSchema = marketplaceDiscoveryEnvelopeSchema.extend({
|
|
38935
|
+
items: external_exports.array(marketplaceHitSchema)
|
|
38936
|
+
});
|
|
39497
38937
|
|
|
39498
38938
|
// ../../node_modules/.pnpm/@solana+errors@5.5.1_typescript@6.0.3/node_modules/@solana/errors/dist/index.node.mjs
|
|
39499
38939
|
var SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED = 1;
|
|
@@ -44475,16 +43915,16 @@ var DEFAULT_COMPUTE_UNIT_PRICE_MICROLAMPORTS = 1;
|
|
|
44475
43915
|
var DEFAULT_COMPUTE_UNIT_LIMIT = 2e4;
|
|
44476
43916
|
var MAX_MEMO_BYTES = 256;
|
|
44477
43917
|
var SOLANA_MAINNET_CAIP22 = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
44478
|
-
var
|
|
43918
|
+
var SOLANA_DEVNET_CAIP22 = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
44479
43919
|
var SOLANA_TESTNET_CAIP2 = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z";
|
|
44480
43920
|
var V1_TO_V2_NETWORK_MAP = {
|
|
44481
43921
|
solana: SOLANA_MAINNET_CAIP22,
|
|
44482
|
-
"solana-devnet":
|
|
43922
|
+
"solana-devnet": SOLANA_DEVNET_CAIP22,
|
|
44483
43923
|
"solana-testnet": SOLANA_TESTNET_CAIP2
|
|
44484
43924
|
};
|
|
44485
43925
|
function normalizeNetwork(network) {
|
|
44486
43926
|
if (network.includes(":")) {
|
|
44487
|
-
const supported = [SOLANA_MAINNET_CAIP22,
|
|
43927
|
+
const supported = [SOLANA_MAINNET_CAIP22, SOLANA_DEVNET_CAIP22, SOLANA_TESTNET_CAIP2];
|
|
44488
43928
|
if (!supported.includes(network)) {
|
|
44489
43929
|
throw new Error(`Unsupported SVM network: ${network}`);
|
|
44490
43930
|
}
|
|
@@ -44532,7 +43972,7 @@ var DEFAULT_ASSETS = {
|
|
|
44532
43972
|
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS2
|
|
44533
43973
|
}
|
|
44534
43974
|
],
|
|
44535
|
-
[
|
|
43975
|
+
[SOLANA_DEVNET_CAIP22]: [
|
|
44536
43976
|
{
|
|
44537
43977
|
asset: USDC_DEVNET_ADDRESS,
|
|
44538
43978
|
decimals: 6,
|
|
@@ -44587,7 +44027,7 @@ var findDefaultAsset = (asset, network) => {
|
|
|
44587
44027
|
function createRpcClient(network, customRpcUrl) {
|
|
44588
44028
|
const caip2Network = normalizeNetwork(network);
|
|
44589
44029
|
switch (caip2Network) {
|
|
44590
|
-
case
|
|
44030
|
+
case SOLANA_DEVNET_CAIP22: {
|
|
44591
44031
|
const url2 = customRpcUrl || DEVNET_RPC_URL;
|
|
44592
44032
|
return createSolanaRpc(devnet(url2));
|
|
44593
44033
|
}
|
|
@@ -44785,6 +44225,376 @@ var ExactSvmScheme = class {
|
|
|
44785
44225
|
var addressEncoder = getAddressEncoder();
|
|
44786
44226
|
var compiledMessageDecoder = getCompiledTransactionMessageDecoder();
|
|
44787
44227
|
|
|
44228
|
+
// src/net-guard.ts
|
|
44229
|
+
import { lookup as dnsLookup } from "node:dns/promises";
|
|
44230
|
+
import { request as httpRequest } from "node:http";
|
|
44231
|
+
import { request as httpsRequest } from "node:https";
|
|
44232
|
+
import { isIP } from "node:net";
|
|
44233
|
+
import { Readable } from "node:stream";
|
|
44234
|
+
var defaultLookup = async (hostname3) => {
|
|
44235
|
+
const addresses = await dnsLookup(hostname3, { all: true });
|
|
44236
|
+
return addresses.map(({ address: address2 }) => address2);
|
|
44237
|
+
};
|
|
44238
|
+
async function assertPublicUrl(url2, options) {
|
|
44239
|
+
if (url2.username || url2.password) {
|
|
44240
|
+
throw guardError(url2);
|
|
44241
|
+
}
|
|
44242
|
+
if (url2.protocol !== "http:" && url2.protocol !== "https:") {
|
|
44243
|
+
throw guardError(url2);
|
|
44244
|
+
}
|
|
44245
|
+
if (options.allowPrivateNetwork) {
|
|
44246
|
+
return;
|
|
44247
|
+
}
|
|
44248
|
+
const hostname3 = normalizeHostname(url2.hostname);
|
|
44249
|
+
const lowercaseHostname = hostname3.toLowerCase();
|
|
44250
|
+
if (!lowercaseHostname || lowercaseHostname === "localhost" || lowercaseHostname.endsWith(".localhost") || lowercaseHostname.endsWith(".local") || lowercaseHostname.endsWith(".internal")) {
|
|
44251
|
+
throw guardError(url2);
|
|
44252
|
+
}
|
|
44253
|
+
if (isIP(hostname3)) {
|
|
44254
|
+
if (isNonPublicAddress(hostname3)) {
|
|
44255
|
+
throw guardError(url2);
|
|
44256
|
+
}
|
|
44257
|
+
return;
|
|
44258
|
+
}
|
|
44259
|
+
let addresses;
|
|
44260
|
+
try {
|
|
44261
|
+
addresses = await withTimeout2(
|
|
44262
|
+
(options.lookup ?? defaultLookup)(hostname3),
|
|
44263
|
+
options.timeoutMs ?? 5e3
|
|
44264
|
+
);
|
|
44265
|
+
} catch {
|
|
44266
|
+
throw guardError(url2);
|
|
44267
|
+
}
|
|
44268
|
+
if (addresses.length === 0 || addresses.some(isNonPublicAddress)) {
|
|
44269
|
+
throw guardError(url2);
|
|
44270
|
+
}
|
|
44271
|
+
}
|
|
44272
|
+
function createPublicFetch(options) {
|
|
44273
|
+
const lookupFn = options.lookup ?? defaultLookup;
|
|
44274
|
+
return (async (input2, init) => {
|
|
44275
|
+
const url2 = new URL(input2 instanceof Request ? input2.url : input2);
|
|
44276
|
+
await assertPublicUrl(url2, {
|
|
44277
|
+
allowPrivateNetwork: options.allowPrivateNetwork,
|
|
44278
|
+
lookup: lookupFn,
|
|
44279
|
+
timeoutMs: 5e3
|
|
44280
|
+
});
|
|
44281
|
+
const normalized = new Request(input2, init);
|
|
44282
|
+
const bytes = normalized.body ? Buffer.from(await normalized.arrayBuffer()) : null;
|
|
44283
|
+
return await new Promise((resolve2, reject) => {
|
|
44284
|
+
const requestOptions = {
|
|
44285
|
+
method: normalized.method,
|
|
44286
|
+
headers: Object.fromEntries(normalized.headers),
|
|
44287
|
+
signal: normalized.signal,
|
|
44288
|
+
...options.allowPrivateNetwork ? {} : { lookup: pinnedLookup(lookupFn) }
|
|
44289
|
+
};
|
|
44290
|
+
const onResponse = (incoming) => {
|
|
44291
|
+
try {
|
|
44292
|
+
const headers = new Headers();
|
|
44293
|
+
for (const [name, value] of Object.entries(incoming.headers)) {
|
|
44294
|
+
if (Array.isArray(value)) {
|
|
44295
|
+
for (const item of value) headers.append(name, item);
|
|
44296
|
+
} else if (value !== void 0) {
|
|
44297
|
+
headers.set(name, value);
|
|
44298
|
+
}
|
|
44299
|
+
}
|
|
44300
|
+
const status = incoming.statusCode ?? 500;
|
|
44301
|
+
const bodyForbidden = normalized.method === "HEAD" || [204, 205, 304].includes(status);
|
|
44302
|
+
if (bodyForbidden) incoming.resume();
|
|
44303
|
+
const response = new Response(
|
|
44304
|
+
bodyForbidden ? null : Readable.toWeb(incoming),
|
|
44305
|
+
{ status, statusText: incoming.statusMessage, headers }
|
|
44306
|
+
);
|
|
44307
|
+
Object.defineProperty(response, "url", { value: url2.toString() });
|
|
44308
|
+
resolve2(response);
|
|
44309
|
+
} catch (error61) {
|
|
44310
|
+
incoming.destroy();
|
|
44311
|
+
reject(error61);
|
|
44312
|
+
}
|
|
44313
|
+
};
|
|
44314
|
+
const request = url2.protocol === "https:" ? httpsRequest(url2, requestOptions, onResponse) : httpRequest(url2, requestOptions, onResponse);
|
|
44315
|
+
request.on("error", reject);
|
|
44316
|
+
if (bytes) request.write(bytes);
|
|
44317
|
+
request.end();
|
|
44318
|
+
});
|
|
44319
|
+
});
|
|
44320
|
+
}
|
|
44321
|
+
function pinnedLookup(lookup) {
|
|
44322
|
+
return (hostname3, dnsOptions, callback) => {
|
|
44323
|
+
void lookup(normalizeHostname(hostname3)).then((addresses) => {
|
|
44324
|
+
if (addresses.length === 0 || addresses.some(isNonPublicAddress)) {
|
|
44325
|
+
callback(guardError(new URL(`https://${hostname3}`)), "");
|
|
44326
|
+
return;
|
|
44327
|
+
}
|
|
44328
|
+
const address2 = addresses[0];
|
|
44329
|
+
const family = isIP(address2);
|
|
44330
|
+
callback(
|
|
44331
|
+
null,
|
|
44332
|
+
dnsOptions.all ? [{ address: address2, family }] : address2,
|
|
44333
|
+
dnsOptions.all ? void 0 : family
|
|
44334
|
+
);
|
|
44335
|
+
}).catch(
|
|
44336
|
+
(error61) => callback(error61 instanceof Error ? error61 : new Error("DNS lookup failed."), "")
|
|
44337
|
+
);
|
|
44338
|
+
};
|
|
44339
|
+
}
|
|
44340
|
+
async function withTimeout2(operation, timeoutMs) {
|
|
44341
|
+
let timeout;
|
|
44342
|
+
try {
|
|
44343
|
+
return await Promise.race([
|
|
44344
|
+
operation,
|
|
44345
|
+
new Promise((_resolve, reject) => {
|
|
44346
|
+
timeout = setTimeout(() => reject(new Error("DNS lookup timed out.")), timeoutMs);
|
|
44347
|
+
})
|
|
44348
|
+
]);
|
|
44349
|
+
} finally {
|
|
44350
|
+
if (timeout) clearTimeout(timeout);
|
|
44351
|
+
}
|
|
44352
|
+
}
|
|
44353
|
+
function normalizeHostname(hostname3) {
|
|
44354
|
+
const unbracketed = hostname3.startsWith("[") && hostname3.endsWith("]") ? hostname3.slice(1, -1) : hostname3;
|
|
44355
|
+
return unbracketed.endsWith(".") ? unbracketed.slice(0, -1) : unbracketed;
|
|
44356
|
+
}
|
|
44357
|
+
function isNonPublicAddress(address2) {
|
|
44358
|
+
const normalized = normalizeHostname(address2);
|
|
44359
|
+
const version5 = isIP(normalized);
|
|
44360
|
+
if (version5 === 4) {
|
|
44361
|
+
return isNonPublicIpv4(parseIpv4(normalized));
|
|
44362
|
+
}
|
|
44363
|
+
if (version5 === 6) {
|
|
44364
|
+
return isNonPublicIpv6(parseIpv6(normalized));
|
|
44365
|
+
}
|
|
44366
|
+
return true;
|
|
44367
|
+
}
|
|
44368
|
+
function parseIpv4(address2) {
|
|
44369
|
+
const octets = address2.split(".").map(Number);
|
|
44370
|
+
return [octets[0], octets[1], octets[2], octets[3]];
|
|
44371
|
+
}
|
|
44372
|
+
function isNonPublicIpv4([first, second, third]) {
|
|
44373
|
+
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;
|
|
44374
|
+
}
|
|
44375
|
+
function parseIpv6(address2) {
|
|
44376
|
+
let normalized = address2.toLowerCase();
|
|
44377
|
+
const lastColon = normalized.lastIndexOf(":");
|
|
44378
|
+
const dottedTail = normalized.slice(lastColon + 1);
|
|
44379
|
+
if (dottedTail.includes(".")) {
|
|
44380
|
+
const [first, second, third, fourth] = parseIpv4(dottedTail);
|
|
44381
|
+
normalized = `${normalized.slice(0, lastColon + 1)}${(first << 8 | second).toString(16)}:${(third << 8 | fourth).toString(16)}`;
|
|
44382
|
+
}
|
|
44383
|
+
const halves = normalized.split("::");
|
|
44384
|
+
const left = halves[0] ? halves[0].split(":").map(parseHex) : [];
|
|
44385
|
+
const right = halves[1] ? halves[1].split(":").map(parseHex) : [];
|
|
44386
|
+
const omittedCount = 8 - left.length - right.length;
|
|
44387
|
+
return halves.length === 2 ? [...left, ...Array.from({ length: omittedCount }, () => 0), ...right] : left;
|
|
44388
|
+
}
|
|
44389
|
+
function parseHex(value) {
|
|
44390
|
+
return Number.parseInt(value, 16);
|
|
44391
|
+
}
|
|
44392
|
+
function isNonPublicIpv6(hextets) {
|
|
44393
|
+
if (hextets.slice(0, 5).every((hextet) => hextet === 0) && hextets[5] === 65535) {
|
|
44394
|
+
const embeddedIpv4 = [
|
|
44395
|
+
hextets[6] >> 8,
|
|
44396
|
+
hextets[6] & 255,
|
|
44397
|
+
hextets[7] >> 8,
|
|
44398
|
+
hextets[7] & 255
|
|
44399
|
+
];
|
|
44400
|
+
return isNonPublicIpv4(embeddedIpv4);
|
|
44401
|
+
}
|
|
44402
|
+
if (hextets.slice(0, 6).every((hextet) => hextet === 0)) {
|
|
44403
|
+
const compatibleIpv4 = [
|
|
44404
|
+
hextets[6] >> 8,
|
|
44405
|
+
hextets[6] & 255,
|
|
44406
|
+
hextets[7] >> 8,
|
|
44407
|
+
hextets[7] & 255
|
|
44408
|
+
];
|
|
44409
|
+
if (isNonPublicIpv4(compatibleIpv4)) return true;
|
|
44410
|
+
}
|
|
44411
|
+
const isUnspecified = hextets.every((hextet) => hextet === 0);
|
|
44412
|
+
const isLoopback = hextets.slice(0, 7).every((hextet) => hextet === 0) && hextets[7] === 1;
|
|
44413
|
+
const first = hextets[0];
|
|
44414
|
+
const isUniqueLocal = first >= 64512 && first <= 65023;
|
|
44415
|
+
const isLinkLocal = first >= 65152 && first <= 65215;
|
|
44416
|
+
const isSiteLocal = first >= 65216 && first <= 65279;
|
|
44417
|
+
const isMulticast = first >= 65280;
|
|
44418
|
+
const isDocumentation = first === 8193 && hextets[1] === 3512;
|
|
44419
|
+
return isUnspecified || isLoopback || isUniqueLocal || isLinkLocal || isSiteLocal || isMulticast || isDocumentation;
|
|
44420
|
+
}
|
|
44421
|
+
function guardError(url2) {
|
|
44422
|
+
return new Error(
|
|
44423
|
+
`URL hostname ${JSON.stringify(url2.hostname)} is not allowed; private or internal destinations require allowPrivateNetwork true in the vAPI config.`
|
|
44424
|
+
);
|
|
44425
|
+
}
|
|
44426
|
+
|
|
44427
|
+
// src/networks.ts
|
|
44428
|
+
var USDC_DECIMALS = 6;
|
|
44429
|
+
var DEFAULT_ARC_GAS_HEADROOM_ATOMIC = 50000n;
|
|
44430
|
+
var NETWORKS2 = {
|
|
44431
|
+
[BASE_MAINNET_CAIP2]: {
|
|
44432
|
+
family: "evm",
|
|
44433
|
+
chainId: 8453,
|
|
44434
|
+
name: "Base mainnet",
|
|
44435
|
+
usdc: CANONICAL_X402_USDC_NETWORKS[BASE_MAINNET_CAIP2].usdc,
|
|
44436
|
+
gasToken: "ETH",
|
|
44437
|
+
rpcEnv: "BASE_RPC_URL",
|
|
44438
|
+
publicRpcUrl: "https://mainnet.base.org",
|
|
44439
|
+
explorerUrl: "https://basescan.org"
|
|
44440
|
+
},
|
|
44441
|
+
[ARC_MAINNET_CAIP2]: {
|
|
44442
|
+
family: "evm",
|
|
44443
|
+
chainId: 5042,
|
|
44444
|
+
name: "Arc mainnet",
|
|
44445
|
+
usdc: CANONICAL_X402_USDC_NETWORKS[ARC_MAINNET_CAIP2].usdc,
|
|
44446
|
+
gasToken: "USDC",
|
|
44447
|
+
rpcEnv: "ARC_RPC_URL",
|
|
44448
|
+
publicRpcUrl: "https://rpc.mainnet.arc.io",
|
|
44449
|
+
explorerUrl: "https://explorer.arc.io"
|
|
44450
|
+
},
|
|
44451
|
+
[ARC_TESTNET_CAIP2]: {
|
|
44452
|
+
family: "evm",
|
|
44453
|
+
chainId: 5042002,
|
|
44454
|
+
name: "Arc testnet",
|
|
44455
|
+
usdc: CANONICAL_X402_USDC_NETWORKS[ARC_TESTNET_CAIP2].usdc,
|
|
44456
|
+
gasToken: "USDC",
|
|
44457
|
+
rpcEnv: "ARC_TESTNET_RPC_URL"
|
|
44458
|
+
},
|
|
44459
|
+
[SOLANA_MAINNET_CAIP2]: {
|
|
44460
|
+
family: "svm",
|
|
44461
|
+
name: "Solana mainnet",
|
|
44462
|
+
usdc: SOLANA_MAINNET_USDC,
|
|
44463
|
+
gasToken: "SOL",
|
|
44464
|
+
rpcEnv: "SOLANA_RPC_URL",
|
|
44465
|
+
publicRpcUrl: "https://api.mainnet-beta.solana.com"
|
|
44466
|
+
},
|
|
44467
|
+
[X402_SOLANA_MAINNET_CAIP2]: {
|
|
44468
|
+
family: "svm",
|
|
44469
|
+
name: "Solana mainnet",
|
|
44470
|
+
usdc: SOLANA_MAINNET_USDC,
|
|
44471
|
+
gasToken: "SOL",
|
|
44472
|
+
rpcEnv: "SOLANA_RPC_URL",
|
|
44473
|
+
publicRpcUrl: "https://api.mainnet-beta.solana.com"
|
|
44474
|
+
}
|
|
44475
|
+
};
|
|
44476
|
+
function parseEip155ChainId(network) {
|
|
44477
|
+
const match = /^eip155:(\d+)$/.exec(network);
|
|
44478
|
+
if (!match) {
|
|
44479
|
+
throw new Error(`Unsupported network ${network}; expected eip155:<chainId>.`);
|
|
44480
|
+
}
|
|
44481
|
+
const chainId = Number(match[1]);
|
|
44482
|
+
if (!Number.isSafeInteger(chainId) || chainId <= 0) {
|
|
44483
|
+
throw new Error(`Invalid EVM chain ID in network ${network}.`);
|
|
44484
|
+
}
|
|
44485
|
+
return chainId;
|
|
44486
|
+
}
|
|
44487
|
+
function isSolanaNetwork(network) {
|
|
44488
|
+
return network === SOLANA_MAINNET_CAIP2 || network === X402_SOLANA_MAINNET_CAIP2;
|
|
44489
|
+
}
|
|
44490
|
+
function usesUsdcGas(network) {
|
|
44491
|
+
try {
|
|
44492
|
+
return getNetworkDefinition(network).gasToken === "USDC";
|
|
44493
|
+
} catch {
|
|
44494
|
+
return false;
|
|
44495
|
+
}
|
|
44496
|
+
}
|
|
44497
|
+
function explorerTransactionUrl(network, hash4) {
|
|
44498
|
+
try {
|
|
44499
|
+
const explorerUrl = getNetworkDefinition(network).explorerUrl;
|
|
44500
|
+
return explorerUrl ? `${explorerUrl}/tx/${hash4}` : void 0;
|
|
44501
|
+
} catch {
|
|
44502
|
+
return void 0;
|
|
44503
|
+
}
|
|
44504
|
+
}
|
|
44505
|
+
function explorerAddressUrl(network, address2) {
|
|
44506
|
+
try {
|
|
44507
|
+
const explorerUrl = getNetworkDefinition(network).explorerUrl;
|
|
44508
|
+
return explorerUrl ? `${explorerUrl}/address/${address2}` : void 0;
|
|
44509
|
+
} catch {
|
|
44510
|
+
return void 0;
|
|
44511
|
+
}
|
|
44512
|
+
}
|
|
44513
|
+
function areSamePaymentNetwork(left, right) {
|
|
44514
|
+
return left === right || isSolanaNetwork(left) && isSolanaNetwork(right);
|
|
44515
|
+
}
|
|
44516
|
+
function isSupportedPaymentNetwork(network) {
|
|
44517
|
+
if (isSolanaNetwork(network)) return true;
|
|
44518
|
+
try {
|
|
44519
|
+
parseEip155ChainId(network);
|
|
44520
|
+
return true;
|
|
44521
|
+
} catch {
|
|
44522
|
+
return false;
|
|
44523
|
+
}
|
|
44524
|
+
}
|
|
44525
|
+
function configuredNetworkFor(networks, network) {
|
|
44526
|
+
const configured = networks[network];
|
|
44527
|
+
if (configured) return configured;
|
|
44528
|
+
if (network === X402_SOLANA_MAINNET_CAIP2) return networks[SOLANA_MAINNET_CAIP2];
|
|
44529
|
+
if (network === SOLANA_MAINNET_CAIP2) return networks[X402_SOLANA_MAINNET_CAIP2];
|
|
44530
|
+
return void 0;
|
|
44531
|
+
}
|
|
44532
|
+
function getNetworkDefinition(network) {
|
|
44533
|
+
const known = NETWORKS2[network];
|
|
44534
|
+
if (known) {
|
|
44535
|
+
return known;
|
|
44536
|
+
}
|
|
44537
|
+
const chainId = parseEip155ChainId(network);
|
|
44538
|
+
return {
|
|
44539
|
+
family: "evm",
|
|
44540
|
+
chainId,
|
|
44541
|
+
name: network,
|
|
44542
|
+
usdc: getAddress("0x0000000000000000000000000000000000000000"),
|
|
44543
|
+
gasToken: "ETH",
|
|
44544
|
+
rpcEnv: ""
|
|
44545
|
+
};
|
|
44546
|
+
}
|
|
44547
|
+
function requireRpcUrl(network, configured) {
|
|
44548
|
+
const definition = getNetworkDefinition(network);
|
|
44549
|
+
const envUrl = definition.rpcEnv ? process.env[definition.rpcEnv]?.trim() : void 0;
|
|
44550
|
+
const rpcUrl = envUrl || configured.rpcUrl.trim();
|
|
44551
|
+
if (rpcUrl) {
|
|
44552
|
+
return rpcUrl;
|
|
44553
|
+
}
|
|
44554
|
+
if (network === ARC_TESTNET_CAIP2) {
|
|
44555
|
+
throw new Error(
|
|
44556
|
+
"Arc testnet RPC is required. Set ARC_TESTNET_RPC_URL or add rpcUrl for eip155:5042002 in config.json."
|
|
44557
|
+
);
|
|
44558
|
+
}
|
|
44559
|
+
throw new Error(`RPC URL is required for ${network}.`);
|
|
44560
|
+
}
|
|
44561
|
+
function createChain(network, rpcUrl) {
|
|
44562
|
+
const definition = getNetworkDefinition(network);
|
|
44563
|
+
if (definition.family !== "evm" || definition.chainId === void 0) {
|
|
44564
|
+
throw new Error(`Network ${network} is not an EVM chain.`);
|
|
44565
|
+
}
|
|
44566
|
+
return defineChain({
|
|
44567
|
+
id: definition.chainId,
|
|
44568
|
+
name: definition.name,
|
|
44569
|
+
nativeCurrency: definition.gasToken === "USDC" ? { name: "USDC", symbol: "USDC", decimals: USDC_DECIMALS } : { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
44570
|
+
rpcUrls: {
|
|
44571
|
+
default: { http: [rpcUrl] }
|
|
44572
|
+
},
|
|
44573
|
+
...definition.explorerUrl ? {
|
|
44574
|
+
blockExplorers: {
|
|
44575
|
+
default: { name: `${definition.name} explorer`, url: definition.explorerUrl }
|
|
44576
|
+
}
|
|
44577
|
+
} : {}
|
|
44578
|
+
});
|
|
44579
|
+
}
|
|
44580
|
+
function createNetworkPublicClient(network, configured, options = {}) {
|
|
44581
|
+
const rpcUrl = requireRpcUrl(network, configured);
|
|
44582
|
+
return createPublicClient({
|
|
44583
|
+
chain: createChain(network, rpcUrl),
|
|
44584
|
+
transport: createNetworkHttpTransport(rpcUrl, options)
|
|
44585
|
+
});
|
|
44586
|
+
}
|
|
44587
|
+
function createNetworkHttpTransport(rpcUrl, options = {}) {
|
|
44588
|
+
const fetchFn = options.fetch ?? createPublicFetch({
|
|
44589
|
+
allowPrivateNetwork: options.allowPrivateNetwork ?? false,
|
|
44590
|
+
...options.lookup ? { lookup: options.lookup } : {}
|
|
44591
|
+
});
|
|
44592
|
+
return http(rpcUrl, { fetchFn, fetchOptions: { redirect: "manual" } });
|
|
44593
|
+
}
|
|
44594
|
+
function formatUsdc(amountAtomic) {
|
|
44595
|
+
return formatUnits(amountAtomic, USDC_DECIMALS);
|
|
44596
|
+
}
|
|
44597
|
+
|
|
44788
44598
|
// src/x402.ts
|
|
44789
44599
|
var MAX_CHALLENGE_BYTES = 1048576;
|
|
44790
44600
|
var MAX_UINT256 = (1n << 256n) - 1n;
|
|
@@ -45644,6 +45454,237 @@ function isRecord2(value) {
|
|
|
45644
45454
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
45645
45455
|
}
|
|
45646
45456
|
|
|
45457
|
+
// src/call-contracts-wire.ts
|
|
45458
|
+
var CALLABLE_KIND = "agent";
|
|
45459
|
+
var CALLABLE_CATEGORIES = ["ai", "data", "crypto", "compute", "search"];
|
|
45460
|
+
var callableCategorySchema = external_exports.enum(CALLABLE_CATEGORIES);
|
|
45461
|
+
var DISCOVERY_CATEGORIES = [...CALLABLE_CATEGORIES, "other"];
|
|
45462
|
+
var discoveryCategorySchema = external_exports.enum(DISCOVERY_CATEGORIES);
|
|
45463
|
+
var CALLABLE_CATEGORY_LABELS = {
|
|
45464
|
+
ai: { catalog: "AI / LLM", publish: "AI and models" },
|
|
45465
|
+
data: { catalog: "Data", publish: "Data" },
|
|
45466
|
+
crypto: { catalog: "Crypto", publish: "Crypto" },
|
|
45467
|
+
compute: { catalog: "Compute", publish: "Compute" },
|
|
45468
|
+
search: { catalog: "Search", publish: "Search" }
|
|
45469
|
+
};
|
|
45470
|
+
var CALLABLE_CATEGORY_SET = new Set(CALLABLE_CATEGORIES);
|
|
45471
|
+
function isCallableListing(kind, category) {
|
|
45472
|
+
return kind === CALLABLE_KIND && CALLABLE_CATEGORY_SET.has(category);
|
|
45473
|
+
}
|
|
45474
|
+
var serviceTierSchema = external_exports.enum(["listed", "verified", "partner"]);
|
|
45475
|
+
var discoveryEndpointSchema = external_exports.looseObject({
|
|
45476
|
+
name: external_exports.string(),
|
|
45477
|
+
method: external_exports.string(),
|
|
45478
|
+
url: external_exports.url(),
|
|
45479
|
+
price: external_exports.string(),
|
|
45480
|
+
description: external_exports.string(),
|
|
45481
|
+
operationId: external_exports.string().trim().min(1).optional(),
|
|
45482
|
+
requestContentType: external_exports.string().trim().min(1).optional(),
|
|
45483
|
+
requestSchema: external_exports.json().optional(),
|
|
45484
|
+
responseContentType: external_exports.string().trim().min(1).optional(),
|
|
45485
|
+
pathTemplate: external_exports.string().trim().min(1).optional(),
|
|
45486
|
+
pathParameters: external_exports.array(external_exports.string().trim().min(1)).optional(),
|
|
45487
|
+
payment: external_exports.union([
|
|
45488
|
+
external_exports.looseObject({
|
|
45489
|
+
scheme: external_exports.literal("exact"),
|
|
45490
|
+
network: external_exports.string().regex(/^eip155:\d+$/),
|
|
45491
|
+
asset: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
45492
|
+
payTo: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
45493
|
+
checkedAt: external_exports.iso.datetime()
|
|
45494
|
+
}),
|
|
45495
|
+
external_exports.looseObject({
|
|
45496
|
+
scheme: external_exports.literal("exact"),
|
|
45497
|
+
network: external_exports.union([
|
|
45498
|
+
external_exports.string().regex(/^solana:[-_a-zA-Z0-9]{1,32}$/),
|
|
45499
|
+
external_exports.literal(SOLANA_MAINNET_CAIP2)
|
|
45500
|
+
]),
|
|
45501
|
+
asset: external_exports.string().refine(isSolanaAddress, "Expected a Solana base58 address."),
|
|
45502
|
+
payTo: external_exports.string().refine(isSolanaAddress, "Expected a Solana base58 address."),
|
|
45503
|
+
checkedAt: external_exports.iso.datetime()
|
|
45504
|
+
})
|
|
45505
|
+
]).optional()
|
|
45506
|
+
});
|
|
45507
|
+
var serviceSummarySchema = external_exports.looseObject({
|
|
45508
|
+
id: external_exports.string(),
|
|
45509
|
+
name: external_exports.string(),
|
|
45510
|
+
description: external_exports.string(),
|
|
45511
|
+
category: discoveryCategorySchema,
|
|
45512
|
+
tier: serviceTierSchema,
|
|
45513
|
+
...listingDisclosureShape,
|
|
45514
|
+
verified: external_exports.boolean(),
|
|
45515
|
+
wrapped: external_exports.boolean(),
|
|
45516
|
+
price: external_exports.string(),
|
|
45517
|
+
networks: external_exports.array(external_exports.string()),
|
|
45518
|
+
endpoints: external_exports.array(discoveryEndpointSchema)
|
|
45519
|
+
});
|
|
45520
|
+
var searchServicesResponseSchema = external_exports.looseObject({
|
|
45521
|
+
services: external_exports.array(serviceSummarySchema)
|
|
45522
|
+
});
|
|
45523
|
+
var listServicesResponseSchema = searchServicesResponseSchema;
|
|
45524
|
+
var discoveryServiceSchema = serviceSummarySchema;
|
|
45525
|
+
var discoveryResponseSchema = searchServicesResponseSchema;
|
|
45526
|
+
|
|
45527
|
+
// src/call-contracts.ts
|
|
45528
|
+
var DiscoveryCatalogError = class extends Error {
|
|
45529
|
+
constructor(code, message, serviceId, paymentNetworks) {
|
|
45530
|
+
super(message);
|
|
45531
|
+
this.paymentNetworks = paymentNetworks;
|
|
45532
|
+
this.code = code;
|
|
45533
|
+
this.serviceId = serviceId;
|
|
45534
|
+
}
|
|
45535
|
+
paymentNetworks;
|
|
45536
|
+
name = "DiscoveryCatalogError";
|
|
45537
|
+
code;
|
|
45538
|
+
serviceId;
|
|
45539
|
+
};
|
|
45540
|
+
function isDiscoveryCatalogError(error61) {
|
|
45541
|
+
if (!(error61 instanceof Error) || error61.name !== "DiscoveryCatalogError" || !("code" in error61) || typeof error61.code !== "string") {
|
|
45542
|
+
return false;
|
|
45543
|
+
}
|
|
45544
|
+
const networks = Reflect.get(error61, "paymentNetworks");
|
|
45545
|
+
return networks === void 0 || Array.isArray(networks) && networks.every((network) => typeof network === "string");
|
|
45546
|
+
}
|
|
45547
|
+
function parseDiscovery(raw) {
|
|
45548
|
+
const parsed = discoveryResponseSchema.safeParse(raw);
|
|
45549
|
+
if (!parsed.success) {
|
|
45550
|
+
const malformedUrl = parsed.error.issues.find(
|
|
45551
|
+
(issue2) => issue2.path.at(-1) === "url" && issue2.path.includes("endpoints")
|
|
45552
|
+
);
|
|
45553
|
+
if (malformedUrl) {
|
|
45554
|
+
const serviceIndex = pathIndexAfter(malformedUrl.path, "services");
|
|
45555
|
+
const serviceId = rawServiceId(raw, serviceIndex);
|
|
45556
|
+
throw new DiscoveryCatalogError(
|
|
45557
|
+
"malformed_url",
|
|
45558
|
+
`Service ${JSON.stringify(serviceId ?? "unknown")} has a malformed endpoint URL.`,
|
|
45559
|
+
serviceId
|
|
45560
|
+
);
|
|
45561
|
+
}
|
|
45562
|
+
throw new DiscoveryCatalogError("invalid_discovery", "Discovery response is malformed.");
|
|
45563
|
+
}
|
|
45564
|
+
for (const service of parsed.data.services) {
|
|
45565
|
+
buildTargets(service);
|
|
45566
|
+
}
|
|
45567
|
+
const resolveListing = (serviceId, endpointName) => {
|
|
45568
|
+
const service = parsed.data.services.find((candidate) => candidate.id === serviceId);
|
|
45569
|
+
if (!service) {
|
|
45570
|
+
throw new DiscoveryCatalogError(
|
|
45571
|
+
"service_not_found",
|
|
45572
|
+
`No payable endpoint found for service ${JSON.stringify(serviceId)}.`,
|
|
45573
|
+
serviceId
|
|
45574
|
+
);
|
|
45575
|
+
}
|
|
45576
|
+
return { service, endpoint: resolveTarget(service, endpointName) };
|
|
45577
|
+
};
|
|
45578
|
+
return {
|
|
45579
|
+
services: parsed.data.services,
|
|
45580
|
+
resolve: (serviceId, endpointName) => resolveListing(serviceId, endpointName).endpoint,
|
|
45581
|
+
resolveListing
|
|
45582
|
+
};
|
|
45583
|
+
}
|
|
45584
|
+
function resolveTarget(service, endpointName) {
|
|
45585
|
+
const { targets, targetsByName } = buildTargets(service);
|
|
45586
|
+
if (endpointName !== void 0) {
|
|
45587
|
+
const selected = targetsByName.get(endpointName.trim());
|
|
45588
|
+
if (!selected) {
|
|
45589
|
+
throw new DiscoveryCatalogError(
|
|
45590
|
+
"endpoint_not_found",
|
|
45591
|
+
`Service ${JSON.stringify(service.id)} has no endpoint ${JSON.stringify(endpointName)}. Available endpoints: ${[...targetsByName.keys()].join(", ")}.`,
|
|
45592
|
+
service.id
|
|
45593
|
+
);
|
|
45594
|
+
}
|
|
45595
|
+
return { ...selected };
|
|
45596
|
+
}
|
|
45597
|
+
if (targets.size !== 1) {
|
|
45598
|
+
const paymentNetworks = service.endpoints.flatMap(
|
|
45599
|
+
(endpoint) => endpoint.payment ? [endpoint.payment.network] : []
|
|
45600
|
+
);
|
|
45601
|
+
throw new DiscoveryCatalogError(
|
|
45602
|
+
"ambiguous_default",
|
|
45603
|
+
`Service ${JSON.stringify(service.id)} has ${targets.size} distinct payable endpoints. Choose one with endpoint: ${[...targetsByName.keys()].join(", ")}.`,
|
|
45604
|
+
service.id,
|
|
45605
|
+
paymentNetworks.length === service.endpoints.length ? paymentNetworks : void 0
|
|
45606
|
+
);
|
|
45607
|
+
}
|
|
45608
|
+
return targets.values().next().value;
|
|
45609
|
+
}
|
|
45610
|
+
function buildTargets(service) {
|
|
45611
|
+
if (service.endpoints.length === 0) {
|
|
45612
|
+
throw new DiscoveryCatalogError(
|
|
45613
|
+
"no_endpoint",
|
|
45614
|
+
`Service ${JSON.stringify(service.id)} has no payable endpoint.`,
|
|
45615
|
+
service.id
|
|
45616
|
+
);
|
|
45617
|
+
}
|
|
45618
|
+
const namedEndpoints = [...service.endpoints].sort(
|
|
45619
|
+
(left, right) => compareNames(left.name.trim(), right.name.trim())
|
|
45620
|
+
);
|
|
45621
|
+
const names = /* @__PURE__ */ new Set();
|
|
45622
|
+
const targets = /* @__PURE__ */ new Map();
|
|
45623
|
+
const targetsByName = /* @__PURE__ */ new Map();
|
|
45624
|
+
for (const endpoint of namedEndpoints) {
|
|
45625
|
+
const name = endpoint.name.trim();
|
|
45626
|
+
if (!name) {
|
|
45627
|
+
throw new DiscoveryCatalogError(
|
|
45628
|
+
"invalid_endpoint_name",
|
|
45629
|
+
`Service ${JSON.stringify(service.id)} has a blank endpoint name.`,
|
|
45630
|
+
service.id
|
|
45631
|
+
);
|
|
45632
|
+
}
|
|
45633
|
+
if (names.has(name)) {
|
|
45634
|
+
throw new DiscoveryCatalogError(
|
|
45635
|
+
"duplicate_endpoint_name",
|
|
45636
|
+
`Service ${JSON.stringify(service.id)} has duplicate endpoint name ${JSON.stringify(name)}.`,
|
|
45637
|
+
service.id
|
|
45638
|
+
);
|
|
45639
|
+
}
|
|
45640
|
+
names.add(name);
|
|
45641
|
+
const method = endpoint.method.trim().toUpperCase();
|
|
45642
|
+
if (!method) {
|
|
45643
|
+
throw new DiscoveryCatalogError(
|
|
45644
|
+
"blank_method",
|
|
45645
|
+
`Service ${JSON.stringify(service.id)} has a blank endpoint method.`,
|
|
45646
|
+
service.id
|
|
45647
|
+
);
|
|
45648
|
+
}
|
|
45649
|
+
const url2 = new URL(endpoint.url);
|
|
45650
|
+
if (url2.protocol !== "http:" && url2.protocol !== "https:") {
|
|
45651
|
+
throw new DiscoveryCatalogError(
|
|
45652
|
+
"malformed_url",
|
|
45653
|
+
`Service ${JSON.stringify(service.id)} has a non-HTTP endpoint URL.`,
|
|
45654
|
+
service.id
|
|
45655
|
+
);
|
|
45656
|
+
}
|
|
45657
|
+
const transportKey = `${method}\0${endpoint.url}`;
|
|
45658
|
+
const normalized = { ...endpoint, name, method };
|
|
45659
|
+
targetsByName.set(name, normalized);
|
|
45660
|
+
if (!targets.has(transportKey)) targets.set(transportKey, normalized);
|
|
45661
|
+
}
|
|
45662
|
+
return { targets, targetsByName };
|
|
45663
|
+
}
|
|
45664
|
+
function compareNames(left, right) {
|
|
45665
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
45666
|
+
}
|
|
45667
|
+
function pathIndexAfter(path, key) {
|
|
45668
|
+
const keyIndex = path.indexOf(key);
|
|
45669
|
+
const candidate = path[keyIndex + 1];
|
|
45670
|
+
return typeof candidate === "number" ? candidate : void 0;
|
|
45671
|
+
}
|
|
45672
|
+
function rawServiceId(raw, serviceIndex) {
|
|
45673
|
+
if (serviceIndex === void 0 || typeof raw !== "object" || raw === null) {
|
|
45674
|
+
return void 0;
|
|
45675
|
+
}
|
|
45676
|
+
const services = Reflect.get(raw, "services");
|
|
45677
|
+
if (!Array.isArray(services)) {
|
|
45678
|
+
return void 0;
|
|
45679
|
+
}
|
|
45680
|
+
const service = services[serviceIndex];
|
|
45681
|
+
if (typeof service !== "object" || service === null) {
|
|
45682
|
+
return void 0;
|
|
45683
|
+
}
|
|
45684
|
+
const id = Reflect.get(service, "id");
|
|
45685
|
+
return typeof id === "string" ? id : void 0;
|
|
45686
|
+
}
|
|
45687
|
+
|
|
45647
45688
|
// src/sweep.ts
|
|
45648
45689
|
var ERC20_ABI = [
|
|
45649
45690
|
{
|
|
@@ -46438,6 +46479,8 @@ var DEFAULT_SPEND_CAPS = {
|
|
|
46438
46479
|
perCallAtomic: "100000",
|
|
46439
46480
|
perDayAtomic: "1000000"
|
|
46440
46481
|
};
|
|
46482
|
+
var DEFAULT_MAX_PER_TASK_USD = 100;
|
|
46483
|
+
var DEFAULT_AUTO_RELEASE_BELOW_USD = 25;
|
|
46441
46484
|
var DEFAULT_CEILING_ATOMIC = 5000000n;
|
|
46442
46485
|
var atomicString = external_exports.string().regex(/^\d+$/, "Expected non-negative atomic units.");
|
|
46443
46486
|
var spendCapsSchema = external_exports.object({
|
|
@@ -46454,6 +46497,14 @@ var configSchema = external_exports.object({
|
|
|
46454
46497
|
})
|
|
46455
46498
|
).optional(),
|
|
46456
46499
|
allowPrivateNetwork: external_exports.boolean().default(false).optional(),
|
|
46500
|
+
tasksEscrowDurationOverrides: external_exports.record(
|
|
46501
|
+
external_exports.string().regex(/^\d+$/),
|
|
46502
|
+
external_exports.object({
|
|
46503
|
+
workDurationSeconds: external_exports.number().int().positive().max(Number.MAX_SAFE_INTEGER).optional(),
|
|
46504
|
+
reviewWindowSeconds: external_exports.number().int().positive().max(Number.MAX_SAFE_INTEGER).optional()
|
|
46505
|
+
}).strict()
|
|
46506
|
+
).optional(),
|
|
46507
|
+
tasksEscrowFactoryOverrides: external_exports.record(external_exports.string().regex(/^\d+$/), external_exports.string()).optional(),
|
|
46457
46508
|
networks: external_exports.record(
|
|
46458
46509
|
external_exports.string().refine((network) => isSupportedPaymentNetwork(network), {
|
|
46459
46510
|
message: "Expected a supported eip155:<chainId> or Solana network identifier."
|
|
@@ -46472,9 +46523,20 @@ var configSchema = external_exports.object({
|
|
|
46472
46523
|
spendCaps: spendCapsSchema,
|
|
46473
46524
|
device: external_exports.string().regex(/^[a-z0-9][a-z0-9-]{0,31}$/).optional()
|
|
46474
46525
|
}).superRefine((config2, context) => {
|
|
46526
|
+
for (const [chainId, factory] of Object.entries(config2.tasksEscrowFactoryOverrides ?? {})) {
|
|
46527
|
+
try {
|
|
46528
|
+
getAddress(factory);
|
|
46529
|
+
} catch {
|
|
46530
|
+
context.addIssue({
|
|
46531
|
+
code: "custom",
|
|
46532
|
+
path: ["tasksEscrowFactoryOverrides", chainId],
|
|
46533
|
+
message: "Expected a valid EVM escrow factory address."
|
|
46534
|
+
});
|
|
46535
|
+
}
|
|
46536
|
+
}
|
|
46475
46537
|
for (const [network, configured] of Object.entries(config2.networks)) {
|
|
46476
46538
|
if (isSolanaNetwork(network)) {
|
|
46477
|
-
if (configured.usdc !==
|
|
46539
|
+
if (configured.usdc !== NETWORKS2[SOLANA_MAINNET_CAIP2].usdc) {
|
|
46478
46540
|
context.addIssue({
|
|
46479
46541
|
code: "custom",
|
|
46480
46542
|
path: ["networks", network, "usdc"],
|
|
@@ -46485,7 +46547,7 @@ var configSchema = external_exports.object({
|
|
|
46485
46547
|
}
|
|
46486
46548
|
try {
|
|
46487
46549
|
const usdc = getAddress(configured.usdc);
|
|
46488
|
-
if ((network === ARC_MAINNET_CAIP2 || network === ARC_TESTNET_CAIP2) && usdc !== getAddress(
|
|
46550
|
+
if ((network === ARC_MAINNET_CAIP2 || network === ARC_TESTNET_CAIP2) && usdc !== getAddress(NETWORKS2[network].usdc)) {
|
|
46489
46551
|
context.addIssue({
|
|
46490
46552
|
code: "custom",
|
|
46491
46553
|
path: ["networks", network, "usdc"],
|
|
@@ -46634,17 +46696,18 @@ function getDefaultConfig(source = process.env, options = {}) {
|
|
|
46634
46696
|
const registry2 = registryEndpoints(source.VAPI_REGISTRY_URL?.trim() || DEFAULT_REGISTRY_URL);
|
|
46635
46697
|
const requested = new Set(options.networks ?? ["base"]);
|
|
46636
46698
|
const networks = {};
|
|
46699
|
+
const tasksEscrowFactoryOverrides = tasksFactoryOverridesFromEnv(source);
|
|
46637
46700
|
if (requested.has("base") || requested.has(BASE_MAINNET_CAIP2)) {
|
|
46638
46701
|
networks[BASE_MAINNET_CAIP2] = {
|
|
46639
|
-
rpcUrl: source.BASE_RPC_URL?.trim() ||
|
|
46640
|
-
usdc:
|
|
46702
|
+
rpcUrl: source.BASE_RPC_URL?.trim() || NETWORKS2[BASE_MAINNET_CAIP2].publicRpcUrl,
|
|
46703
|
+
usdc: NETWORKS2[BASE_MAINNET_CAIP2].usdc
|
|
46641
46704
|
};
|
|
46642
46705
|
}
|
|
46643
46706
|
const arcMainnetRpcUrl = source.ARC_RPC_URL?.trim();
|
|
46644
46707
|
if (arcMainnetRpcUrl || requested.has("arc") || requested.has(ARC_MAINNET_CAIP2)) {
|
|
46645
46708
|
networks[ARC_MAINNET_CAIP2] = {
|
|
46646
|
-
rpcUrl: arcMainnetRpcUrl ||
|
|
46647
|
-
usdc:
|
|
46709
|
+
rpcUrl: arcMainnetRpcUrl || NETWORKS2[ARC_MAINNET_CAIP2].publicRpcUrl,
|
|
46710
|
+
usdc: NETWORKS2[ARC_MAINNET_CAIP2].usdc
|
|
46648
46711
|
};
|
|
46649
46712
|
}
|
|
46650
46713
|
const arcTestnetRpcUrl = source.ARC_TESTNET_RPC_URL?.trim();
|
|
@@ -46656,14 +46719,14 @@ function getDefaultConfig(source = process.env, options = {}) {
|
|
|
46656
46719
|
}
|
|
46657
46720
|
networks[ARC_TESTNET_CAIP2] = {
|
|
46658
46721
|
rpcUrl: arcTestnetRpcUrl,
|
|
46659
|
-
usdc:
|
|
46722
|
+
usdc: NETWORKS2[ARC_TESTNET_CAIP2].usdc
|
|
46660
46723
|
};
|
|
46661
46724
|
}
|
|
46662
46725
|
const solanaRpcUrl = source.SOLANA_RPC_URL?.trim();
|
|
46663
46726
|
if (solanaRpcUrl || requested.has("solana") || requested.has(SOLANA_MAINNET_CAIP2)) {
|
|
46664
46727
|
networks[SOLANA_MAINNET_CAIP2] = {
|
|
46665
|
-
rpcUrl: solanaRpcUrl ||
|
|
46666
|
-
usdc:
|
|
46728
|
+
rpcUrl: solanaRpcUrl || NETWORKS2[SOLANA_MAINNET_CAIP2].publicRpcUrl,
|
|
46729
|
+
usdc: NETWORKS2[SOLANA_MAINNET_CAIP2].usdc
|
|
46667
46730
|
};
|
|
46668
46731
|
}
|
|
46669
46732
|
return {
|
|
@@ -46671,6 +46734,8 @@ function getDefaultConfig(source = process.env, options = {}) {
|
|
|
46671
46734
|
marketplaceDiscoveryUrl: source.VAPI_MARKETPLACE_DISCOVERY_URL?.trim() || registry2.marketplaceDiscoveryUrl,
|
|
46672
46735
|
registryFallbacks: DEFAULT_REGISTRY_FALLBACKS.map((fallback) => ({ ...fallback })),
|
|
46673
46736
|
allowPrivateNetwork: false,
|
|
46737
|
+
tasksEscrowFactoryOverrides,
|
|
46738
|
+
tasksEscrowDurationOverrides: tasksDurationOverridesFromEnv(source),
|
|
46674
46739
|
networks,
|
|
46675
46740
|
spendCaps: { ...DEFAULT_SPEND_CAPS }
|
|
46676
46741
|
};
|
|
@@ -46688,8 +46753,10 @@ async function loadConfig(path = getVapiPaths().config, source = process.env, op
|
|
|
46688
46753
|
}
|
|
46689
46754
|
const parsed = configSchema.parse(JSON.parse(raw));
|
|
46690
46755
|
parsed.registryFallbacks ??= DEFAULT_REGISTRY_FALLBACKS.map((fallback) => ({ ...fallback }));
|
|
46756
|
+
parsed.tasksEscrowFactoryOverrides ??= {};
|
|
46691
46757
|
const migrated = rewriteLegacyRegistryUrls(parsed);
|
|
46692
46758
|
const config2 = migrated.config;
|
|
46759
|
+
config2.tasksEscrowFactoryOverrides ??= {};
|
|
46693
46760
|
if (migrated.changes.length > 0 && options.notice) {
|
|
46694
46761
|
options.notice(
|
|
46695
46762
|
`${formatLegacyRegistryRewrites(migrated.changes)}
|
|
@@ -46703,27 +46770,35 @@ Run vapi init to write the new URLs to ${path}.`
|
|
|
46703
46770
|
const discoveryUrl = source.VAPI_DISCOVERY_URL?.trim();
|
|
46704
46771
|
const marketplaceDiscoveryUrl = source.VAPI_MARKETPLACE_DISCOVERY_URL?.trim();
|
|
46705
46772
|
const registryUrl = source.VAPI_REGISTRY_URL?.trim();
|
|
46773
|
+
Object.assign(config2.tasksEscrowFactoryOverrides, tasksFactoryOverridesFromEnv(source));
|
|
46774
|
+
config2.tasksEscrowDurationOverrides ??= {};
|
|
46775
|
+
for (const [chainId, overrides] of Object.entries(tasksDurationOverridesFromEnv(source))) {
|
|
46776
|
+
config2.tasksEscrowDurationOverrides[chainId] = {
|
|
46777
|
+
...config2.tasksEscrowDurationOverrides[chainId],
|
|
46778
|
+
...overrides
|
|
46779
|
+
};
|
|
46780
|
+
}
|
|
46706
46781
|
if (config2.networks[BASE_MAINNET_CAIP2] && baseRpcUrl) {
|
|
46707
46782
|
config2.networks[BASE_MAINNET_CAIP2].rpcUrl = baseRpcUrl;
|
|
46708
46783
|
}
|
|
46709
46784
|
if (arcMainnetRpcUrl) {
|
|
46710
46785
|
const existing = config2.networks[ARC_MAINNET_CAIP2];
|
|
46711
46786
|
config2.networks[ARC_MAINNET_CAIP2] = {
|
|
46712
|
-
...existing ?? { usdc:
|
|
46787
|
+
...existing ?? { usdc: NETWORKS2[ARC_MAINNET_CAIP2].usdc },
|
|
46713
46788
|
rpcUrl: arcMainnetRpcUrl
|
|
46714
46789
|
};
|
|
46715
46790
|
}
|
|
46716
46791
|
if (arcTestnetRpcUrl) {
|
|
46717
46792
|
const existing = config2.networks[ARC_TESTNET_CAIP2];
|
|
46718
46793
|
config2.networks[ARC_TESTNET_CAIP2] = {
|
|
46719
|
-
...existing ?? { usdc:
|
|
46794
|
+
...existing ?? { usdc: NETWORKS2[ARC_TESTNET_CAIP2].usdc },
|
|
46720
46795
|
rpcUrl: arcTestnetRpcUrl
|
|
46721
46796
|
};
|
|
46722
46797
|
}
|
|
46723
46798
|
if (solanaRpcUrl) {
|
|
46724
46799
|
config2.networks[SOLANA_MAINNET_CAIP2] = {
|
|
46725
46800
|
rpcUrl: solanaRpcUrl,
|
|
46726
|
-
usdc: config2.networks[SOLANA_MAINNET_CAIP2]?.usdc ??
|
|
46801
|
+
usdc: config2.networks[SOLANA_MAINNET_CAIP2]?.usdc ?? NETWORKS2[SOLANA_MAINNET_CAIP2].usdc
|
|
46727
46802
|
};
|
|
46728
46803
|
}
|
|
46729
46804
|
if (registryUrl) {
|
|
@@ -46736,13 +46811,38 @@ Run vapi init to write the new URLs to ${path}.`
|
|
|
46736
46811
|
for (const [network, configured] of Object.entries(config2.networks)) {
|
|
46737
46812
|
configured.rpcUrl = configured.rpcUrl.trim();
|
|
46738
46813
|
configured.usdc = configured.usdc.trim();
|
|
46739
|
-
if (isSolanaNetwork(network) && configured.usdc !==
|
|
46814
|
+
if (isSolanaNetwork(network) && configured.usdc !== NETWORKS2[SOLANA_MAINNET_CAIP2].usdc) {
|
|
46740
46815
|
throw new Error(`Network ${network} must use canonical Solana mainnet USDC.`);
|
|
46741
46816
|
}
|
|
46742
46817
|
if (!configured.rpcUrl) delete config2.networks[network];
|
|
46743
46818
|
}
|
|
46744
46819
|
return config2;
|
|
46745
46820
|
}
|
|
46821
|
+
function tasksDurationOverridesFromEnv(source) {
|
|
46822
|
+
const result = {};
|
|
46823
|
+
for (const [name, raw] of Object.entries(source)) {
|
|
46824
|
+
const match = /^VAPI_TASKS_(WORK_DURATION|REVIEW_WINDOW)_SECONDS_(\d+)$/.exec(name);
|
|
46825
|
+
const value = raw?.trim();
|
|
46826
|
+
if (!match || !value) continue;
|
|
46827
|
+
const seconds = Number(value);
|
|
46828
|
+
if (!/^\d+$/.test(value) || !Number.isSafeInteger(seconds) || seconds <= 0)
|
|
46829
|
+
throw new Error(`Invalid trusted Tasks duration ${name}.`);
|
|
46830
|
+
const entry = result[match[2]] ??= {};
|
|
46831
|
+
if (match[1] === "WORK_DURATION") entry.workDurationSeconds = seconds;
|
|
46832
|
+
else entry.reviewWindowSeconds = seconds;
|
|
46833
|
+
}
|
|
46834
|
+
return result;
|
|
46835
|
+
}
|
|
46836
|
+
function tasksFactoryOverridesFromEnv(source) {
|
|
46837
|
+
const overrides = {};
|
|
46838
|
+
for (const [name, raw] of Object.entries(source)) {
|
|
46839
|
+
const match = /^VAPI_TASKS_ESCROW_FACTORY_(\d+)$/.exec(name);
|
|
46840
|
+
const value = raw?.trim();
|
|
46841
|
+
if (!match || !value) continue;
|
|
46842
|
+
overrides[match[1]] = getAddress(value);
|
|
46843
|
+
}
|
|
46844
|
+
return overrides;
|
|
46845
|
+
}
|
|
46746
46846
|
function registryEndpoints(baseUrl) {
|
|
46747
46847
|
const base = new URL(baseUrl);
|
|
46748
46848
|
base.search = "";
|
|
@@ -46767,14 +46867,14 @@ async function enableDefaultNetwork(network, path = getVapiPaths().config, sourc
|
|
|
46767
46867
|
const config2 = await loadConfig(path, source);
|
|
46768
46868
|
if (network === "solana") {
|
|
46769
46869
|
config2.networks[SOLANA_MAINNET_CAIP2] = {
|
|
46770
|
-
rpcUrl: source.SOLANA_RPC_URL?.trim() ||
|
|
46771
|
-
usdc:
|
|
46870
|
+
rpcUrl: source.SOLANA_RPC_URL?.trim() || NETWORKS2[SOLANA_MAINNET_CAIP2].publicRpcUrl,
|
|
46871
|
+
usdc: NETWORKS2[SOLANA_MAINNET_CAIP2].usdc
|
|
46772
46872
|
};
|
|
46773
46873
|
} else {
|
|
46774
46874
|
const existing = config2.networks[ARC_MAINNET_CAIP2];
|
|
46775
46875
|
config2.networks[ARC_MAINNET_CAIP2] = {
|
|
46776
|
-
...existing ?? { usdc:
|
|
46777
|
-
rpcUrl: source.ARC_RPC_URL?.trim() ||
|
|
46876
|
+
...existing ?? { usdc: NETWORKS2[ARC_MAINNET_CAIP2].usdc },
|
|
46877
|
+
rpcUrl: source.ARC_RPC_URL?.trim() || NETWORKS2[ARC_MAINNET_CAIP2].publicRpcUrl
|
|
46778
46878
|
};
|
|
46779
46879
|
}
|
|
46780
46880
|
await writeConfigFile(path, config2);
|
|
@@ -46999,7 +47099,12 @@ var AgentLinkError = class extends Error {
|
|
|
46999
47099
|
code;
|
|
47000
47100
|
};
|
|
47001
47101
|
var DEFAULT_AGENT_SCOPES = ["mcp:call", "router.use"];
|
|
47002
|
-
var ALLOWED_AGENT_SCOPES = /* @__PURE__ */ new Set([
|
|
47102
|
+
var ALLOWED_AGENT_SCOPES = /* @__PURE__ */ new Set([
|
|
47103
|
+
...DEFAULT_AGENT_SCOPES,
|
|
47104
|
+
"call.publish",
|
|
47105
|
+
"tasks:read",
|
|
47106
|
+
"tasks:write"
|
|
47107
|
+
]);
|
|
47003
47108
|
var publicFetch = createPublicFetch({ allowPrivateNetwork: false });
|
|
47004
47109
|
async function startDeviceLink(args) {
|
|
47005
47110
|
if (args.device !== void 0 && !DEVICE_NAME_PATTERN.test(args.device)) {
|
|
@@ -72953,6 +73058,8 @@ var agentProfileShape = {
|
|
|
72953
73058
|
instructions: external_exports.string().max(2e4),
|
|
72954
73059
|
verifiedOnly: external_exports.boolean().default(true),
|
|
72955
73060
|
approveAboveUsd: external_exports.number().min(0).default(0.5),
|
|
73061
|
+
maxPerTaskUsd: external_exports.number().min(0).default(DEFAULT_MAX_PER_TASK_USD),
|
|
73062
|
+
autoReleaseBelowUsd: external_exports.number().min(0).default(DEFAULT_AUTO_RELEASE_BELOW_USD),
|
|
72956
73063
|
maxSteps: external_exports.number().int().min(1).max(50).default(12),
|
|
72957
73064
|
paused: external_exports.boolean().default(false),
|
|
72958
73065
|
grants: external_exports.array(external_exports.enum(AGENT_GRANTS)).default([]),
|
|
@@ -73113,7 +73220,9 @@ var ledgerSchema = external_exports.object({
|
|
|
73113
73220
|
});
|
|
73114
73221
|
var spendReservationSchema = external_exports.object({
|
|
73115
73222
|
id: external_exports.string().min(1),
|
|
73116
|
-
amountAtomic: external_exports.string().regex(/^\d+$/)
|
|
73223
|
+
amountAtomic: external_exports.string().regex(/^\d+$/),
|
|
73224
|
+
kind: external_exports.enum(["payment", "escrow-funding", "dispute-fee"]).optional(),
|
|
73225
|
+
taskKey: external_exports.string().optional()
|
|
73117
73226
|
});
|
|
73118
73227
|
var ledgerRowSchema = ledgerSchema.extend({
|
|
73119
73228
|
wallet: walletNameSchema.optional(),
|
|
@@ -73139,6 +73248,29 @@ async function readSpendLedger(path = getAgentCashPaths().ledger, now = /* @__PU
|
|
|
73139
73248
|
const row = rows.find((candidate) => candidate.wallet === wallet);
|
|
73140
73249
|
return { date: utcDateKey(now), spentAtomic: row?.spentAtomic ?? "0" };
|
|
73141
73250
|
}
|
|
73251
|
+
async function escrowFundingDayRemainingAtomic(input2) {
|
|
73252
|
+
const perDayAtomic = parseAtomicCap(input2.caps.perDayAtomic, "per-day");
|
|
73253
|
+
const rows = await readStoredSpendLedgerRows(input2.ledgerPath, input2.now);
|
|
73254
|
+
const row = rows.find((candidate) => candidate.wallet === input2.wallet);
|
|
73255
|
+
const reserved = input2.reservationId ? row?.reservations?.find((candidate) => candidate.id === input2.reservationId) : void 0;
|
|
73256
|
+
const remaining = perDayAtomic - BigInt(row?.spentAtomic ?? "0") + BigInt(reserved?.amountAtomic ?? "0");
|
|
73257
|
+
return remaining > 0n ? remaining : 0n;
|
|
73258
|
+
}
|
|
73259
|
+
async function taskReservedAtomic(input2) {
|
|
73260
|
+
const rows = await readStoredSpendLedgerRows(input2.ledgerPath, input2.now, true);
|
|
73261
|
+
return sumTaskReservations(rows, input2.wallet, input2.taskKey, input2.excludeReservationId);
|
|
73262
|
+
}
|
|
73263
|
+
function sumTaskReservations(rows, wallet, taskKey, excludeReservationId) {
|
|
73264
|
+
let total = 0n;
|
|
73265
|
+
for (const row of rows) {
|
|
73266
|
+
if (row.wallet !== wallet) continue;
|
|
73267
|
+
for (const reservation of row.reservations ?? []) {
|
|
73268
|
+
if (reservation.taskKey === taskKey && reservation.id !== excludeReservationId)
|
|
73269
|
+
total += BigInt(reservation.amountAtomic);
|
|
73270
|
+
}
|
|
73271
|
+
}
|
|
73272
|
+
return total;
|
|
73273
|
+
}
|
|
73142
73274
|
async function readSpendLedgerRows(path = getAgentCashPaths().ledger, now = /* @__PURE__ */ new Date()) {
|
|
73143
73275
|
return (await readStoredSpendLedgerRows(path, now)).map(({ date: date5, spentAtomic, wallet }) => ({
|
|
73144
73276
|
date: date5,
|
|
@@ -73146,7 +73278,7 @@ async function readSpendLedgerRows(path = getAgentCashPaths().ledger, now = /* @
|
|
|
73146
73278
|
wallet
|
|
73147
73279
|
}));
|
|
73148
73280
|
}
|
|
73149
|
-
async function readStoredSpendLedgerRows(path, now) {
|
|
73281
|
+
async function readStoredSpendLedgerRows(path, now, allDays = false) {
|
|
73150
73282
|
let raw;
|
|
73151
73283
|
try {
|
|
73152
73284
|
raw = await readFile13(path, "utf8");
|
|
@@ -73157,7 +73289,7 @@ async function readStoredSpendLedgerRows(path, now) {
|
|
|
73157
73289
|
const parsed = ledgerFileSchema.parse(JSON.parse(raw));
|
|
73158
73290
|
const rows = "rows" in parsed ? parsed.rows : [parsed];
|
|
73159
73291
|
const today = utcDateKey(now);
|
|
73160
|
-
return rows.filter((row) => row.date === today).map((row) => ({
|
|
73292
|
+
return rows.filter((row) => allDays || row.date === today).map((row) => ({
|
|
73161
73293
|
date: row.date,
|
|
73162
73294
|
spentAtomic: row.spentAtomic,
|
|
73163
73295
|
wallet: row.wallet ?? DEFAULT_WALLET_NAME,
|
|
@@ -73168,49 +73300,164 @@ async function reserveSpend(amountAtomic, caps, options) {
|
|
|
73168
73300
|
if (amountAtomic < 0n) {
|
|
73169
73301
|
throw new Error("Spend amount cannot be negative.");
|
|
73170
73302
|
}
|
|
73171
|
-
const
|
|
73172
|
-
|
|
73173
|
-
if (
|
|
73174
|
-
|
|
73175
|
-
|
|
73176
|
-
|
|
73177
|
-
|
|
73303
|
+
const kind = options?.kind ?? "payment";
|
|
73304
|
+
let perDayAtomic;
|
|
73305
|
+
if (kind === "escrow-funding" || kind === "dispute-fee") {
|
|
73306
|
+
const maxPerTaskAtomic = options?.maxPerTaskAtomic;
|
|
73307
|
+
if (maxPerTaskAtomic === void 0 || maxPerTaskAtomic < 0n) {
|
|
73308
|
+
throw new Error("Escrow funding requires a non-negative per-task cap.");
|
|
73309
|
+
}
|
|
73310
|
+
if (amountAtomic > maxPerTaskAtomic) {
|
|
73311
|
+
throw new SpendCapError(
|
|
73312
|
+
"per_task_cap_exceeded",
|
|
73313
|
+
`Escrow funding ${amountAtomic} atomic USDC exceeds the per-task cap ${maxPerTaskAtomic}. Refusing to sign.`
|
|
73314
|
+
);
|
|
73315
|
+
}
|
|
73316
|
+
perDayAtomic = parseAtomicCap(caps.perDayAtomic, "per-day");
|
|
73317
|
+
} else {
|
|
73318
|
+
const perCallAtomic = parseAtomicCap(caps.perCallAtomic, "per-call");
|
|
73319
|
+
perDayAtomic = parseAtomicCap(caps.perDayAtomic, "per-day");
|
|
73320
|
+
if (amountAtomic > perCallAtomic) {
|
|
73321
|
+
throw new SpendCapError(
|
|
73322
|
+
"per_call_cap_exceeded",
|
|
73323
|
+
`Payment quote ${amountAtomic} atomic USDC exceeds the per-call cap ${perCallAtomic}. Refusing to sign.`
|
|
73324
|
+
);
|
|
73325
|
+
}
|
|
73178
73326
|
}
|
|
73179
73327
|
const ledgerPath = options?.ledgerPath ?? getAgentCashPaths().ledger;
|
|
73180
73328
|
const now = options?.now ?? /* @__PURE__ */ new Date();
|
|
73181
73329
|
const wallet = options?.wallet ?? DEFAULT_WALLET_NAME;
|
|
73182
73330
|
return await withLedgerLock(ledgerPath, async () => {
|
|
73183
|
-
const rows = await readStoredSpendLedgerRows(ledgerPath, now);
|
|
73184
|
-
const
|
|
73331
|
+
const rows = await readStoredSpendLedgerRows(ledgerPath, now, true);
|
|
73332
|
+
const today = utcDateKey(now);
|
|
73333
|
+
const current = rows.find((row) => row.wallet === wallet && row.date === today);
|
|
73334
|
+
if ((kind === "escrow-funding" || kind === "dispute-fee") && options?.taskKey !== void 0) {
|
|
73335
|
+
const taskTotal = sumTaskReservations(
|
|
73336
|
+
rows,
|
|
73337
|
+
wallet,
|
|
73338
|
+
options.taskKey,
|
|
73339
|
+
options.reuseExistingEscrowReservation || options.resumeEscrowReservation ? options.reservationId : void 0
|
|
73340
|
+
) + amountAtomic;
|
|
73341
|
+
if (taskTotal > options.maxPerTaskAtomic)
|
|
73342
|
+
throw new SpendCapError(
|
|
73343
|
+
"per_task_cap_exceeded",
|
|
73344
|
+
`New spend ${amountAtomic} atomic USDC would raise the running total for task ${options.taskKey} and wallet ${wallet} to ${taskTotal}, above the per-task cap ${options.maxPerTaskAtomic}. Refusing to sign.`
|
|
73345
|
+
);
|
|
73346
|
+
}
|
|
73185
73347
|
if (options?.reservationId !== void 0) {
|
|
73186
|
-
|
|
73348
|
+
const existing = current?.reservations?.find(
|
|
73349
|
+
(reservation) => reservation.id === options.reservationId
|
|
73350
|
+
);
|
|
73351
|
+
if (existing && options.reuseExistingEscrowReservation) {
|
|
73352
|
+
if (kind !== "escrow-funding" && kind !== "dispute-fee" || existing.kind !== kind || existing.amountAtomic !== amountAtomic.toString() || existing.taskKey !== void 0 && existing.taskKey !== options.taskKey)
|
|
73353
|
+
throw new Error(
|
|
73354
|
+
`Spend reservation ${options.reservationId} does not match this funding.`
|
|
73355
|
+
);
|
|
73356
|
+
if (existing.taskKey === void 0 && options.taskKey !== void 0) {
|
|
73357
|
+
existing.taskKey = options.taskKey;
|
|
73358
|
+
await writeLedgerAtomically(ledgerPath, rows);
|
|
73359
|
+
}
|
|
73360
|
+
return {
|
|
73361
|
+
date: current.date,
|
|
73362
|
+
spentAtomic: current.spentAtomic,
|
|
73363
|
+
reservationReused: true
|
|
73364
|
+
};
|
|
73365
|
+
}
|
|
73366
|
+
if (existing) {
|
|
73187
73367
|
throw new Error(`Spend reservation ${options.reservationId} already exists.`);
|
|
73188
73368
|
}
|
|
73369
|
+
if (options.resumeEscrowReservation) {
|
|
73370
|
+
const resumed = options.resumeEscrowReservation;
|
|
73371
|
+
const historical = rows.find((row) => row.wallet === wallet && row.date === resumed.date);
|
|
73372
|
+
const stored = historical?.reservations?.find(
|
|
73373
|
+
(reservation) => reservation.id === resumed.id
|
|
73374
|
+
);
|
|
73375
|
+
if (kind !== "escrow-funding" && kind !== "dispute-fee" || resumed.id !== options.reservationId || resumed.wallet !== wallet || resumed.amountAtomic !== amountAtomic.toString() || resumed.date >= utcDateKey(now) || resumed.exposed !== true || resumed.invalidated === true || stored !== void 0 && (stored.kind !== kind || stored.amountAtomic !== amountAtomic.toString() || stored.taskKey !== void 0 && stored.taskKey !== options.taskKey))
|
|
73376
|
+
throw new Error(
|
|
73377
|
+
`Spend reservation ${options.reservationId} does not match this funding.`
|
|
73378
|
+
);
|
|
73379
|
+
if (stored?.taskKey === void 0 && options.taskKey !== void 0) {
|
|
73380
|
+
if (stored) stored.taskKey = options.taskKey;
|
|
73381
|
+
else {
|
|
73382
|
+
const reservation = {
|
|
73383
|
+
id: resumed.id,
|
|
73384
|
+
amountAtomic: resumed.amountAtomic,
|
|
73385
|
+
kind,
|
|
73386
|
+
taskKey: options.taskKey
|
|
73387
|
+
};
|
|
73388
|
+
if (historical)
|
|
73389
|
+
historical.reservations = [...historical.reservations ?? [], reservation];
|
|
73390
|
+
else
|
|
73391
|
+
rows.push({
|
|
73392
|
+
date: resumed.date,
|
|
73393
|
+
spentAtomic: resumed.amountAtomic,
|
|
73394
|
+
wallet,
|
|
73395
|
+
reservations: [reservation]
|
|
73396
|
+
});
|
|
73397
|
+
}
|
|
73398
|
+
await writeLedgerAtomically(ledgerPath, rows);
|
|
73399
|
+
}
|
|
73400
|
+
return {
|
|
73401
|
+
date: resumed.date,
|
|
73402
|
+
spentAtomic: current?.spentAtomic ?? "0",
|
|
73403
|
+
reservationReused: true
|
|
73404
|
+
};
|
|
73405
|
+
}
|
|
73189
73406
|
}
|
|
73190
73407
|
const spentAtomic = current?.spentAtomic ?? "0";
|
|
73191
73408
|
const nextSpent = BigInt(spentAtomic) + amountAtomic;
|
|
73192
73409
|
if (nextSpent > perDayAtomic) {
|
|
73193
73410
|
throw new SpendCapError(
|
|
73194
73411
|
"per_day_cap_exceeded",
|
|
73195
|
-
|
|
73412
|
+
`${kind === "escrow-funding" ? "Escrow funding" : "Payment quote"} ${amountAtomic} atomic USDC would raise today's spend to ${nextSpent} for wallet ${wallet}, above the per-day cap ${perDayAtomic}. Refusing to sign.`
|
|
73196
73413
|
);
|
|
73197
73414
|
}
|
|
73415
|
+
const reservationId = options?.reservationId ?? (options?.taskKey === void 0 ? void 0 : randomBytes10(16).toString("hex"));
|
|
73198
73416
|
const nextRow = {
|
|
73199
73417
|
date: utcDateKey(now),
|
|
73200
73418
|
spentAtomic: nextSpent.toString(),
|
|
73201
73419
|
wallet,
|
|
73202
|
-
...(current?.reservations?.length ?? 0) === 0 &&
|
|
73420
|
+
...(current?.reservations?.length ?? 0) === 0 && reservationId === void 0 ? {} : {
|
|
73203
73421
|
reservations: [
|
|
73204
73422
|
...current?.reservations ?? [],
|
|
73205
|
-
...
|
|
73423
|
+
...reservationId === void 0 ? [] : [
|
|
73424
|
+
{
|
|
73425
|
+
id: reservationId,
|
|
73426
|
+
amountAtomic: amountAtomic.toString(),
|
|
73427
|
+
...kind !== "payment" ? { kind } : {},
|
|
73428
|
+
...options?.taskKey === void 0 ? {} : { taskKey: options.taskKey }
|
|
73429
|
+
}
|
|
73430
|
+
]
|
|
73206
73431
|
]
|
|
73207
73432
|
}
|
|
73208
73433
|
};
|
|
73209
|
-
const
|
|
73210
|
-
(
|
|
73434
|
+
const otherRows = rows.filter((row) => row.wallet !== wallet || row.date !== today).map((row) => {
|
|
73435
|
+
if (row.wallet !== wallet || !options?.reuseExistingEscrowReservation || options.reservationId === void 0)
|
|
73436
|
+
return row;
|
|
73437
|
+
const previous = row.reservations?.find(
|
|
73438
|
+
(reservation) => reservation.id === options.reservationId
|
|
73439
|
+
);
|
|
73440
|
+
if (!previous) return row;
|
|
73441
|
+
if (kind !== "escrow-funding" && kind !== "dispute-fee" || previous.kind !== kind || previous.amountAtomic !== amountAtomic.toString() || previous.taskKey !== void 0 && previous.taskKey !== options.taskKey)
|
|
73442
|
+
throw new Error(
|
|
73443
|
+
`Spend reservation ${options.reservationId} does not match this funding.`
|
|
73444
|
+
);
|
|
73445
|
+
return {
|
|
73446
|
+
...row,
|
|
73447
|
+
reservations: row.reservations.filter(
|
|
73448
|
+
(reservation) => reservation.id !== options.reservationId
|
|
73449
|
+
)
|
|
73450
|
+
};
|
|
73451
|
+
});
|
|
73452
|
+
const nextRows = [...otherRows, nextRow].sort(
|
|
73453
|
+
(a, b) => a.wallet.localeCompare(b.wallet) || a.date.localeCompare(b.date)
|
|
73211
73454
|
);
|
|
73212
73455
|
await writeLedgerAtomically(ledgerPath, nextRows);
|
|
73213
|
-
return {
|
|
73456
|
+
return {
|
|
73457
|
+
date: nextRow.date,
|
|
73458
|
+
spentAtomic: nextRow.spentAtomic,
|
|
73459
|
+
...options?.reservationId === void 0 && reservationId !== void 0 ? { reservationId } : {}
|
|
73460
|
+
};
|
|
73214
73461
|
});
|
|
73215
73462
|
}
|
|
73216
73463
|
async function releaseSpend(amountAtomic, options) {
|
|
@@ -73222,35 +73469,40 @@ async function releaseSpend(amountAtomic, options) {
|
|
|
73222
73469
|
const wallet = options.wallet ?? DEFAULT_WALLET_NAME;
|
|
73223
73470
|
return await withLedgerLock(ledgerPath, async () => {
|
|
73224
73471
|
const today = utcDateKey(now);
|
|
73225
|
-
const rows = await readStoredSpendLedgerRows(ledgerPath, now);
|
|
73226
|
-
const current = rows.find((row) => row.wallet === wallet);
|
|
73227
|
-
if (options.reservedOn !== today) {
|
|
73472
|
+
const rows = await readStoredSpendLedgerRows(ledgerPath, now, true);
|
|
73473
|
+
const current = rows.find((row) => row.wallet === wallet && row.date === today);
|
|
73474
|
+
if (options.reservedOn !== today && options.reservationId === void 0) {
|
|
73228
73475
|
return { date: today, spentAtomic: current?.spentAtomic ?? "0" };
|
|
73229
73476
|
}
|
|
73230
|
-
const
|
|
73477
|
+
const reserved = rows.find((row) => row.wallet === wallet && row.date === options.reservedOn);
|
|
73478
|
+
const reservation = options.reservationId === void 0 ? void 0 : reserved?.reservations?.find((candidate) => candidate.id === options.reservationId);
|
|
73231
73479
|
if (options.reservationId !== void 0 && reservation === void 0) {
|
|
73232
73480
|
return { date: today, spentAtomic: current?.spentAtomic ?? "0" };
|
|
73233
73481
|
}
|
|
73234
73482
|
if (reservation !== void 0 && reservation.amountAtomic !== amountAtomic.toString()) {
|
|
73235
73483
|
throw new Error(`Spend reservation ${options.reservationId} has a different amount.`);
|
|
73236
73484
|
}
|
|
73237
|
-
const spentAtomic = BigInt(
|
|
73485
|
+
const spentAtomic = BigInt(reserved?.spentAtomic ?? "0");
|
|
73238
73486
|
const releasedAmount = reservation === void 0 ? amountAtomic : BigInt(reservation.amountAtomic);
|
|
73239
73487
|
const nextSpent = spentAtomic > releasedAmount ? spentAtomic - releasedAmount : 0n;
|
|
73240
|
-
const remainingReservations =
|
|
73488
|
+
const remainingReservations = reserved?.reservations?.filter(
|
|
73241
73489
|
(candidate) => candidate.id !== options.reservationId
|
|
73242
73490
|
);
|
|
73243
73491
|
const nextRow = {
|
|
73244
|
-
date:
|
|
73492
|
+
date: options.reservedOn,
|
|
73245
73493
|
spentAtomic: nextSpent.toString(),
|
|
73246
73494
|
wallet,
|
|
73247
73495
|
...remainingReservations === void 0 || remainingReservations.length === 0 ? {} : { reservations: remainingReservations }
|
|
73248
73496
|
};
|
|
73249
|
-
const nextRows = [
|
|
73250
|
-
(
|
|
73251
|
-
|
|
73497
|
+
const nextRows = [
|
|
73498
|
+
...rows.filter((row) => row.wallet !== wallet || row.date !== options.reservedOn),
|
|
73499
|
+
nextRow
|
|
73500
|
+
].sort((a, b) => a.wallet.localeCompare(b.wallet) || a.date.localeCompare(b.date));
|
|
73252
73501
|
await writeLedgerAtomically(ledgerPath, nextRows);
|
|
73253
|
-
return {
|
|
73502
|
+
return {
|
|
73503
|
+
date: today,
|
|
73504
|
+
spentAtomic: options.reservedOn === today ? nextRow.spentAtomic : current?.spentAtomic ?? "0"
|
|
73505
|
+
};
|
|
73254
73506
|
});
|
|
73255
73507
|
}
|
|
73256
73508
|
function parseAtomicCap(value, label) {
|
|
@@ -73547,7 +73799,9 @@ async function transferBetweenAccounts(args) {
|
|
|
73547
73799
|
);
|
|
73548
73800
|
reservedOn = reservation.date;
|
|
73549
73801
|
} catch (error61) {
|
|
73550
|
-
if (error61 instanceof SpendCapError
|
|
73802
|
+
if (error61 instanceof SpendCapError && isTransferErrorCode(error61.code)) {
|
|
73803
|
+
throw transferError(error61.code);
|
|
73804
|
+
}
|
|
73551
73805
|
throw transferError("network_error");
|
|
73552
73806
|
}
|
|
73553
73807
|
}
|
|
@@ -76685,7 +76939,7 @@ function createRunBudget(args) {
|
|
|
76685
76939
|
import { mkdir as mkdir15, writeFile as writeFile8 } from "node:fs/promises";
|
|
76686
76940
|
import { arch, platform, release } from "node:os";
|
|
76687
76941
|
import { join as join13 } from "node:path";
|
|
76688
|
-
var VAPI_CLIENT_VERSION = "0.
|
|
76942
|
+
var VAPI_CLIENT_VERSION = "0.9.2";
|
|
76689
76943
|
async function createSupportReport(options) {
|
|
76690
76944
|
const message = options.message.trim();
|
|
76691
76945
|
if (!message) throw new Error("Support report message must not be empty.");
|
|
@@ -77687,6 +77941,115 @@ async function responseJson(response) {
|
|
|
77687
77941
|
}
|
|
77688
77942
|
}
|
|
77689
77943
|
|
|
77944
|
+
// src/tasks/canonical-json.ts
|
|
77945
|
+
function canonicalizeJson(value) {
|
|
77946
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") {
|
|
77947
|
+
return value;
|
|
77948
|
+
}
|
|
77949
|
+
if (typeof value === "number") {
|
|
77950
|
+
if (!Number.isFinite(value)) {
|
|
77951
|
+
throw new Error("Value is not JSON serializable");
|
|
77952
|
+
}
|
|
77953
|
+
return value;
|
|
77954
|
+
}
|
|
77955
|
+
if (Array.isArray(value)) {
|
|
77956
|
+
return value.map(canonicalizeJson);
|
|
77957
|
+
}
|
|
77958
|
+
if (typeof value === "object") {
|
|
77959
|
+
const prototype = Object.getPrototypeOf(value);
|
|
77960
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
77961
|
+
throw new Error("Value is not JSON serializable");
|
|
77962
|
+
}
|
|
77963
|
+
return Object.fromEntries(
|
|
77964
|
+
Object.entries(value).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(([key, item]) => [key, canonicalizeJson(item)])
|
|
77965
|
+
);
|
|
77966
|
+
}
|
|
77967
|
+
throw new Error("Value is not JSON serializable");
|
|
77968
|
+
}
|
|
77969
|
+
function canonicalJson(value) {
|
|
77970
|
+
return JSON.stringify(canonicalizeJson(value));
|
|
77971
|
+
}
|
|
77972
|
+
|
|
77973
|
+
// src/tasks/delivery-manifest.ts
|
|
77974
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
77975
|
+
var sha256Schema = external_exports.string().regex(/^[0-9a-fA-F]{64}$/).transform((digest) => digest.toLowerCase());
|
|
77976
|
+
var deliveryManifestSchema = external_exports.object({
|
|
77977
|
+
files: external_exports.array(
|
|
77978
|
+
external_exports.object({
|
|
77979
|
+
fileId: external_exports.uuid(),
|
|
77980
|
+
fileName: external_exports.string().min(1).max(255),
|
|
77981
|
+
sha256: sha256Schema,
|
|
77982
|
+
sizeBytes: external_exports.number().int().positive()
|
|
77983
|
+
}).strict()
|
|
77984
|
+
).min(1).max(20),
|
|
77985
|
+
noteSha256: sha256Schema
|
|
77986
|
+
}).strict().superRefine((manifest, context) => {
|
|
77987
|
+
if (new Set(manifest.files.map((file2) => file2.fileId)).size !== manifest.files.length) {
|
|
77988
|
+
context.addIssue({ code: "custom", path: ["files"], message: "File ids must be unique" });
|
|
77989
|
+
}
|
|
77990
|
+
});
|
|
77991
|
+
function freezeDeliveryManifest(input2) {
|
|
77992
|
+
const parsed = deliveryManifestSchema.parse(input2);
|
|
77993
|
+
const manifest = deliveryManifestSchema.parse({
|
|
77994
|
+
...parsed,
|
|
77995
|
+
files: [...parsed.files].sort((left, right) => left.fileId.localeCompare(right.fileId))
|
|
77996
|
+
});
|
|
77997
|
+
return {
|
|
77998
|
+
manifest,
|
|
77999
|
+
manifestHash: keccak256(toBytes(canonicalJson(manifest)))
|
|
78000
|
+
};
|
|
78001
|
+
}
|
|
78002
|
+
async function sha256Hex(bytes) {
|
|
78003
|
+
return createHash2("sha256").update(bytes).digest("hex");
|
|
78004
|
+
}
|
|
78005
|
+
async function prepareDeliveryManifest(files, note) {
|
|
78006
|
+
if (files.length === 0) {
|
|
78007
|
+
throw new Error("Upload at least one delivery file.");
|
|
78008
|
+
}
|
|
78009
|
+
const noteSha256 = await sha256Hex(new TextEncoder().encode(note));
|
|
78010
|
+
return freezeDeliveryManifest({ files, noteSha256 });
|
|
78011
|
+
}
|
|
78012
|
+
|
|
78013
|
+
// src/tasks/verbs.ts
|
|
78014
|
+
var TASKS_CLIENT_VERBS = [
|
|
78015
|
+
"search",
|
|
78016
|
+
"show",
|
|
78017
|
+
"post",
|
|
78018
|
+
"propose",
|
|
78019
|
+
"submit",
|
|
78020
|
+
"award",
|
|
78021
|
+
"sign",
|
|
78022
|
+
"fund",
|
|
78023
|
+
"deliver",
|
|
78024
|
+
"release",
|
|
78025
|
+
"refund",
|
|
78026
|
+
"dispute",
|
|
78027
|
+
"counter-evidence",
|
|
78028
|
+
"resolve-unmatched",
|
|
78029
|
+
"message",
|
|
78030
|
+
"thread",
|
|
78031
|
+
"watch",
|
|
78032
|
+
"status"
|
|
78033
|
+
];
|
|
78034
|
+
|
|
78035
|
+
// src/funding-policy.ts
|
|
78036
|
+
function decideFunding(input2) {
|
|
78037
|
+
validateAmount(input2.amountUsd);
|
|
78038
|
+
if (input2.amountUsd > input2.maxPerTaskUsd) return { ok: false, reason: "policy.perTask" };
|
|
78039
|
+
if (input2.amountUsd > input2.dayRemainingUsd) return { ok: false, reason: "policy.perDay" };
|
|
78040
|
+
if (input2.amountUsd > input2.approveAboveUsd) return { approval: true };
|
|
78041
|
+
return { ok: true };
|
|
78042
|
+
}
|
|
78043
|
+
function decideRelease(input2) {
|
|
78044
|
+
validateAmount(input2.amountUsd);
|
|
78045
|
+
return input2.amountUsd < input2.autoReleaseBelowUsd ? { auto: true } : { approval: true };
|
|
78046
|
+
}
|
|
78047
|
+
function validateAmount(amountUsd) {
|
|
78048
|
+
if (!Number.isFinite(amountUsd) || amountUsd < 0) {
|
|
78049
|
+
throw new Error("Task amount must be a finite, non-negative USD number.");
|
|
78050
|
+
}
|
|
78051
|
+
}
|
|
78052
|
+
|
|
77690
78053
|
// src/searches.ts
|
|
77691
78054
|
import { mkdir as mkdir16, open as open11, readFile as readFile16 } from "node:fs/promises";
|
|
77692
78055
|
import { dirname as dirname10 } from "node:path";
|
|
@@ -77698,6 +78061,7 @@ var searchEventSchema = external_exports.strictObject({
|
|
|
77698
78061
|
source: external_exports.string().min(1),
|
|
77699
78062
|
latencyMs: external_exports.number().nonnegative().finite(),
|
|
77700
78063
|
count: external_exports.number().int().nonnegative(),
|
|
78064
|
+
dropped: external_exports.number().int().nonnegative().optional(),
|
|
77701
78065
|
error: external_exports.string().optional()
|
|
77702
78066
|
})
|
|
77703
78067
|
),
|
|
@@ -77867,6 +78231,351 @@ function dedupeProvenance(values) {
|
|
|
77867
78231
|
});
|
|
77868
78232
|
}
|
|
77869
78233
|
|
|
78234
|
+
// src/docs.ts
|
|
78235
|
+
var DEFAULT_DOCS_ORIGIN = "https://docs.vapinetwork.ai";
|
|
78236
|
+
var DOCS_URL_ENV = "VAPI_DOCS_URL";
|
|
78237
|
+
var DOCS_RESPONSE_MAX_BYTES = 2 * 1024 * 1024;
|
|
78238
|
+
var SEARCH_TIMEOUT_MS = 15e3;
|
|
78239
|
+
var READ_TIMEOUT_MS = 15e3;
|
|
78240
|
+
var ASK_TIMEOUT_MS = 6e4;
|
|
78241
|
+
var MAX_REDIRECTS = 5;
|
|
78242
|
+
var REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
78243
|
+
var DocsError = class extends Error {
|
|
78244
|
+
constructor(code, message, options) {
|
|
78245
|
+
super(message, options);
|
|
78246
|
+
this.code = code;
|
|
78247
|
+
}
|
|
78248
|
+
code;
|
|
78249
|
+
name = "DocsError";
|
|
78250
|
+
};
|
|
78251
|
+
var publicFetch3 = createPublicFetch({ allowPrivateNetwork: false });
|
|
78252
|
+
function resolveDocsOrigin(env = process.env) {
|
|
78253
|
+
const configured = env[DOCS_URL_ENV]?.trim() || DEFAULT_DOCS_ORIGIN;
|
|
78254
|
+
let url2;
|
|
78255
|
+
try {
|
|
78256
|
+
url2 = new URL(configured);
|
|
78257
|
+
} catch (cause) {
|
|
78258
|
+
throw new DocsError("host_not_allowed", `The configured docs origin is invalid.`, { cause });
|
|
78259
|
+
}
|
|
78260
|
+
if (url2.protocol !== "https:" || url2.username || url2.password || url2.pathname !== "/" || url2.search || url2.hash) {
|
|
78261
|
+
throw new DocsError(
|
|
78262
|
+
"host_not_allowed",
|
|
78263
|
+
"The configured docs origin must be an HTTPS origin without credentials, a path, a query, or a fragment."
|
|
78264
|
+
);
|
|
78265
|
+
}
|
|
78266
|
+
return url2.origin;
|
|
78267
|
+
}
|
|
78268
|
+
async function searchDocs(query, options = {}) {
|
|
78269
|
+
const normalized = nonEmpty(query, "Search query");
|
|
78270
|
+
if (options.limit !== void 0 && (!Number.isSafeInteger(options.limit) || options.limit < 1)) {
|
|
78271
|
+
throw new DocsError("invalid_input", "Search limit must be a positive integer.");
|
|
78272
|
+
}
|
|
78273
|
+
const origin = resolveDocsOrigin(options.env);
|
|
78274
|
+
const { text: body } = await requestText(
|
|
78275
|
+
new URL("/~gitbook/mcp", origin),
|
|
78276
|
+
{
|
|
78277
|
+
method: "POST",
|
|
78278
|
+
headers: {
|
|
78279
|
+
"content-type": "application/json",
|
|
78280
|
+
accept: "application/json, text/event-stream"
|
|
78281
|
+
},
|
|
78282
|
+
body: JSON.stringify({
|
|
78283
|
+
jsonrpc: "2.0",
|
|
78284
|
+
id: 1,
|
|
78285
|
+
method: "tools/call",
|
|
78286
|
+
params: { name: "searchDocumentation", arguments: { query: normalized } }
|
|
78287
|
+
})
|
|
78288
|
+
},
|
|
78289
|
+
{
|
|
78290
|
+
operation: "search",
|
|
78291
|
+
origin,
|
|
78292
|
+
timeoutMs: options.timeoutMs ?? SEARCH_TIMEOUT_MS,
|
|
78293
|
+
fetchImpl: options.fetchImpl
|
|
78294
|
+
}
|
|
78295
|
+
);
|
|
78296
|
+
const payload = parseSearchEnvelope(body);
|
|
78297
|
+
const blocks = searchTextBlocks(payload);
|
|
78298
|
+
const results = blocks.flatMap((block) => {
|
|
78299
|
+
const parsed = parseSearchBlock(block);
|
|
78300
|
+
return parsed === void 0 ? [] : [parsed];
|
|
78301
|
+
});
|
|
78302
|
+
return { results: options.limit === void 0 ? results : results.slice(0, options.limit) };
|
|
78303
|
+
}
|
|
78304
|
+
async function readDocs(pageUrlOrPath, options = {}) {
|
|
78305
|
+
const input2 = nonEmpty(pageUrlOrPath, "Documentation page");
|
|
78306
|
+
const origin = resolveDocsOrigin(options.env);
|
|
78307
|
+
const page = docsPagePath(input2, origin);
|
|
78308
|
+
const requestOptions = {
|
|
78309
|
+
operation: "read",
|
|
78310
|
+
origin,
|
|
78311
|
+
timeoutMs: options.timeoutMs ?? READ_TIMEOUT_MS,
|
|
78312
|
+
fetchImpl: options.fetchImpl
|
|
78313
|
+
};
|
|
78314
|
+
const found = await readFirstMarkdown(page, requestOptions);
|
|
78315
|
+
if (found !== void 0) return found;
|
|
78316
|
+
const { url: canonical } = await requestText(
|
|
78317
|
+
page,
|
|
78318
|
+
{ method: "HEAD" },
|
|
78319
|
+
{ ...requestOptions, notFoundOn404: true }
|
|
78320
|
+
);
|
|
78321
|
+
if (canonical.pathname !== page.pathname) {
|
|
78322
|
+
const moved = await readFirstMarkdown(canonical, requestOptions);
|
|
78323
|
+
if (moved !== void 0) return moved;
|
|
78324
|
+
}
|
|
78325
|
+
throw new DocsError("not_found", `Documentation page not found: ${page.href}`);
|
|
78326
|
+
}
|
|
78327
|
+
async function readFirstMarkdown(page, options) {
|
|
78328
|
+
const path = page.pathname.replace(/\/+$/u, "");
|
|
78329
|
+
const candidates = path ? [`${path}.md`, `${path}/readme.md`] : ["/readme.md"];
|
|
78330
|
+
for (const pathname of candidates) {
|
|
78331
|
+
const candidate = new URL(page);
|
|
78332
|
+
candidate.pathname = pathname;
|
|
78333
|
+
try {
|
|
78334
|
+
const { text: markdown, url: url2 } = await requestText(
|
|
78335
|
+
candidate,
|
|
78336
|
+
{ method: "GET", headers: { accept: "text/markdown" } },
|
|
78337
|
+
{ ...options, notFoundOn404: true }
|
|
78338
|
+
);
|
|
78339
|
+
if (!markdown.trimStart().startsWith("# Page Not Found")) {
|
|
78340
|
+
return { url: url2.href, markdown };
|
|
78341
|
+
}
|
|
78342
|
+
} catch (error61) {
|
|
78343
|
+
if (!(error61 instanceof DocsError && error61.code === "not_found")) throw error61;
|
|
78344
|
+
}
|
|
78345
|
+
}
|
|
78346
|
+
return void 0;
|
|
78347
|
+
}
|
|
78348
|
+
async function askDocs(question, options = {}) {
|
|
78349
|
+
const normalized = nonEmpty(question, "Question");
|
|
78350
|
+
const origin = resolveDocsOrigin(options.env);
|
|
78351
|
+
const url2 = new URL("/readme.md", origin);
|
|
78352
|
+
url2.searchParams.set("ask", normalized);
|
|
78353
|
+
const { text: markdown } = await requestText(
|
|
78354
|
+
url2,
|
|
78355
|
+
{ method: "GET", headers: { accept: "text/markdown" } },
|
|
78356
|
+
{
|
|
78357
|
+
operation: "ask",
|
|
78358
|
+
origin,
|
|
78359
|
+
timeoutMs: options.timeoutMs ?? ASK_TIMEOUT_MS,
|
|
78360
|
+
fetchImpl: options.fetchImpl
|
|
78361
|
+
}
|
|
78362
|
+
);
|
|
78363
|
+
return parseAnswer(markdown);
|
|
78364
|
+
}
|
|
78365
|
+
function nonEmpty(value, label) {
|
|
78366
|
+
const normalized = value.trim();
|
|
78367
|
+
if (!normalized) throw new DocsError("invalid_input", `${label} must not be empty.`);
|
|
78368
|
+
return normalized;
|
|
78369
|
+
}
|
|
78370
|
+
function docsPagePath(value, origin) {
|
|
78371
|
+
let url2;
|
|
78372
|
+
try {
|
|
78373
|
+
url2 = new URL(value, `${origin}/`);
|
|
78374
|
+
} catch (cause) {
|
|
78375
|
+
throw new DocsError("invalid_input", "Documentation page must be a docs URL or path.", {
|
|
78376
|
+
cause
|
|
78377
|
+
});
|
|
78378
|
+
}
|
|
78379
|
+
if (url2.origin !== origin || url2.username || url2.password) {
|
|
78380
|
+
throw new DocsError(
|
|
78381
|
+
"host_not_allowed",
|
|
78382
|
+
`Documentation pages must use the configured docs origin ${origin}.`
|
|
78383
|
+
);
|
|
78384
|
+
}
|
|
78385
|
+
url2.search = "";
|
|
78386
|
+
url2.hash = "";
|
|
78387
|
+
url2.pathname = url2.pathname.replace(/\/+$/u, "").replace(/(?:\/readme)?\.md$/iu, "") || "/";
|
|
78388
|
+
return url2;
|
|
78389
|
+
}
|
|
78390
|
+
async function requestText(requestUrl, init, options) {
|
|
78391
|
+
if (!Number.isSafeInteger(options.timeoutMs) || options.timeoutMs < 1) {
|
|
78392
|
+
throw new DocsError("invalid_input", "Documentation request timeout must be positive.");
|
|
78393
|
+
}
|
|
78394
|
+
assertAllowedUrl(requestUrl, options.origin);
|
|
78395
|
+
const controller = new AbortController();
|
|
78396
|
+
const timeoutError = new DocsError(
|
|
78397
|
+
"timeout",
|
|
78398
|
+
`The documentation ${options.operation} request timed out.`
|
|
78399
|
+
);
|
|
78400
|
+
let timer;
|
|
78401
|
+
const timeout = new Promise((_resolve, reject) => {
|
|
78402
|
+
timer = setTimeout(() => {
|
|
78403
|
+
controller.abort(timeoutError);
|
|
78404
|
+
reject(timeoutError);
|
|
78405
|
+
}, options.timeoutMs);
|
|
78406
|
+
});
|
|
78407
|
+
let url2 = requestUrl;
|
|
78408
|
+
try {
|
|
78409
|
+
let response;
|
|
78410
|
+
for (let hops = 0; ; hops += 1) {
|
|
78411
|
+
response = await Promise.race([
|
|
78412
|
+
(options.fetchImpl ?? publicFetch3)(url2, {
|
|
78413
|
+
...init,
|
|
78414
|
+
redirect: "manual",
|
|
78415
|
+
signal: controller.signal
|
|
78416
|
+
}),
|
|
78417
|
+
timeout
|
|
78418
|
+
]);
|
|
78419
|
+
if (response.url) assertAllowedUrl(new URL(response.url), options.origin);
|
|
78420
|
+
const location = response.headers.get("location");
|
|
78421
|
+
if (init.method !== "GET" && init.method !== "HEAD" || !REDIRECT_STATUSES.has(response.status) || !location) {
|
|
78422
|
+
break;
|
|
78423
|
+
}
|
|
78424
|
+
if (hops === MAX_REDIRECTS) {
|
|
78425
|
+
throw new DocsError(
|
|
78426
|
+
"bad_response",
|
|
78427
|
+
`The documentation ${options.operation} request redirected too many times.`
|
|
78428
|
+
);
|
|
78429
|
+
}
|
|
78430
|
+
await response.body?.cancel();
|
|
78431
|
+
const next = new URL(location, url2);
|
|
78432
|
+
assertAllowedUrl(next, options.origin);
|
|
78433
|
+
url2 = next;
|
|
78434
|
+
}
|
|
78435
|
+
if (options.notFoundOn404 && response.status === 404) {
|
|
78436
|
+
throw new DocsError("not_found", `Documentation page not found: ${url2.href}`);
|
|
78437
|
+
}
|
|
78438
|
+
if (!response.ok) {
|
|
78439
|
+
throw new DocsError(
|
|
78440
|
+
"bad_response",
|
|
78441
|
+
`The documentation ${options.operation} request returned HTTP ${response.status}.`
|
|
78442
|
+
);
|
|
78443
|
+
}
|
|
78444
|
+
return { text: await Promise.race([readCappedText(response), timeout]), url: url2 };
|
|
78445
|
+
} catch (error61) {
|
|
78446
|
+
if (error61 instanceof DocsError) throw error61;
|
|
78447
|
+
if (controller.signal.aborted) throw timeoutError;
|
|
78448
|
+
throw new DocsError("bad_response", `The documentation ${options.operation} request failed.`, {
|
|
78449
|
+
cause: error61
|
|
78450
|
+
});
|
|
78451
|
+
} finally {
|
|
78452
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
78453
|
+
}
|
|
78454
|
+
}
|
|
78455
|
+
function assertAllowedUrl(url2, origin) {
|
|
78456
|
+
if (url2.origin !== origin || url2.username || url2.password) {
|
|
78457
|
+
throw new DocsError(
|
|
78458
|
+
"host_not_allowed",
|
|
78459
|
+
`Documentation requests may only contact the configured docs origin ${origin}.`
|
|
78460
|
+
);
|
|
78461
|
+
}
|
|
78462
|
+
}
|
|
78463
|
+
async function readCappedText(response) {
|
|
78464
|
+
const contentLength = response.headers.get("content-length");
|
|
78465
|
+
if (contentLength !== null && Number(contentLength) > DOCS_RESPONSE_MAX_BYTES) {
|
|
78466
|
+
throw responseTooLarge();
|
|
78467
|
+
}
|
|
78468
|
+
if (response.body === null) return "";
|
|
78469
|
+
const reader = response.body.getReader();
|
|
78470
|
+
const chunks = [];
|
|
78471
|
+
let size5 = 0;
|
|
78472
|
+
try {
|
|
78473
|
+
while (true) {
|
|
78474
|
+
const { done, value } = await reader.read();
|
|
78475
|
+
if (done) break;
|
|
78476
|
+
size5 += value.byteLength;
|
|
78477
|
+
if (size5 > DOCS_RESPONSE_MAX_BYTES) {
|
|
78478
|
+
await reader.cancel();
|
|
78479
|
+
throw responseTooLarge();
|
|
78480
|
+
}
|
|
78481
|
+
chunks.push(value);
|
|
78482
|
+
}
|
|
78483
|
+
} finally {
|
|
78484
|
+
reader.releaseLock();
|
|
78485
|
+
}
|
|
78486
|
+
const bytes = new Uint8Array(size5);
|
|
78487
|
+
let offset = 0;
|
|
78488
|
+
for (const chunk of chunks) {
|
|
78489
|
+
bytes.set(chunk, offset);
|
|
78490
|
+
offset += chunk.byteLength;
|
|
78491
|
+
}
|
|
78492
|
+
return new TextDecoder().decode(bytes);
|
|
78493
|
+
}
|
|
78494
|
+
function responseTooLarge() {
|
|
78495
|
+
return new DocsError(
|
|
78496
|
+
"bad_response",
|
|
78497
|
+
`The documentation response exceeded ${DOCS_RESPONSE_MAX_BYTES} bytes.`
|
|
78498
|
+
);
|
|
78499
|
+
}
|
|
78500
|
+
function parseSearchEnvelope(body) {
|
|
78501
|
+
const trimmed = body.trim();
|
|
78502
|
+
if (!trimmed) throw invalidSearchResponse();
|
|
78503
|
+
if (trimmed.startsWith("{")) return parseJson2(trimmed);
|
|
78504
|
+
const records = [];
|
|
78505
|
+
let data = [];
|
|
78506
|
+
for (const line of body.split(/\r?\n/u)) {
|
|
78507
|
+
if (line === "") {
|
|
78508
|
+
if (data.length > 0) records.push(data.join("\n"));
|
|
78509
|
+
data = [];
|
|
78510
|
+
} else if (line.startsWith("data:")) {
|
|
78511
|
+
data.push(line.slice(5).trimStart());
|
|
78512
|
+
}
|
|
78513
|
+
}
|
|
78514
|
+
if (data.length > 0) records.push(data.join("\n"));
|
|
78515
|
+
for (const record2 of records) {
|
|
78516
|
+
try {
|
|
78517
|
+
return JSON.parse(record2);
|
|
78518
|
+
} catch {
|
|
78519
|
+
}
|
|
78520
|
+
}
|
|
78521
|
+
throw invalidSearchResponse();
|
|
78522
|
+
}
|
|
78523
|
+
function parseJson2(value) {
|
|
78524
|
+
try {
|
|
78525
|
+
return JSON.parse(value);
|
|
78526
|
+
} catch (cause) {
|
|
78527
|
+
throw new DocsError("bad_response", "The documentation search response was invalid JSON.", {
|
|
78528
|
+
cause
|
|
78529
|
+
});
|
|
78530
|
+
}
|
|
78531
|
+
}
|
|
78532
|
+
function searchTextBlocks(payload) {
|
|
78533
|
+
const envelope = asRecord(payload);
|
|
78534
|
+
const rpcError = asRecord(envelope?.error);
|
|
78535
|
+
if (rpcError !== void 0) {
|
|
78536
|
+
const message = typeof rpcError.message === "string" ? `: ${rpcError.message}` : "";
|
|
78537
|
+
throw new DocsError("bad_response", `The documentation search returned an error${message}`);
|
|
78538
|
+
}
|
|
78539
|
+
const result = asRecord(envelope?.result);
|
|
78540
|
+
if (!Array.isArray(result?.content)) throw invalidSearchResponse();
|
|
78541
|
+
return result.content.flatMap((item) => {
|
|
78542
|
+
const block = asRecord(item);
|
|
78543
|
+
return block?.type === "text" && typeof block.text === "string" ? [block.text] : [];
|
|
78544
|
+
});
|
|
78545
|
+
}
|
|
78546
|
+
function parseSearchBlock(block) {
|
|
78547
|
+
const match = /^Title:\s*([^\r\n]+)\r?\nLink:\s*([^\r\n]+)\r?\nContent:\s*([\s\S]*)$/u.exec(
|
|
78548
|
+
block.trim()
|
|
78549
|
+
);
|
|
78550
|
+
if (!match) return void 0;
|
|
78551
|
+
const title = match[1].trim();
|
|
78552
|
+
const url2 = match[2].trim();
|
|
78553
|
+
const excerpt = match[3].trim();
|
|
78554
|
+
return title && url2 && excerpt ? { title, url: url2, excerpt } : void 0;
|
|
78555
|
+
}
|
|
78556
|
+
function invalidSearchResponse() {
|
|
78557
|
+
return new DocsError("bad_response", "The documentation search response was invalid.");
|
|
78558
|
+
}
|
|
78559
|
+
function parseAnswer(markdown) {
|
|
78560
|
+
const heading = /^# Sources:\s*$/gmu;
|
|
78561
|
+
const matches = [...markdown.matchAll(heading)];
|
|
78562
|
+
const last = matches.at(-1);
|
|
78563
|
+
if (last?.index === void 0) return { answer: markdown.trimEnd(), sources: [] };
|
|
78564
|
+
const answer = markdown.slice(0, last.index).trimEnd();
|
|
78565
|
+
const sourceText = markdown.slice(last.index + last[0].length).trim();
|
|
78566
|
+
const sources = sourceText.split(/\r?\n/u).flatMap((line) => {
|
|
78567
|
+
const linked = /^\s*(?:[-*]|\d+\.)\s+\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)\s*$/u.exec(line);
|
|
78568
|
+
if (linked) return [{ title: linked[1].trim(), url: linked[2] }];
|
|
78569
|
+
const bare = /^\s*(?:[-*]|\d+\.)\s+(https?:\/\/\S+)\s*$/u.exec(line);
|
|
78570
|
+
if (!bare) return [];
|
|
78571
|
+
return [{ title: bare[1], url: bare[1] }];
|
|
78572
|
+
});
|
|
78573
|
+
return { answer, sources };
|
|
78574
|
+
}
|
|
78575
|
+
function asRecord(value) {
|
|
78576
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
78577
|
+
}
|
|
78578
|
+
|
|
77870
78579
|
// src/distribute.ts
|
|
77871
78580
|
var DistributeError = class extends Error {
|
|
77872
78581
|
constructor(code, message, movementId) {
|
|
@@ -78425,7 +79134,7 @@ function csvCell(value) {
|
|
|
78425
79134
|
}
|
|
78426
79135
|
|
|
78427
79136
|
// src/swarm-capital.ts
|
|
78428
|
-
import { createHash as
|
|
79137
|
+
import { createHash as createHash3, randomBytes as randomBytes15 } from "node:crypto";
|
|
78429
79138
|
import { readFile as readFile17, unlink as unlink12 } from "node:fs/promises";
|
|
78430
79139
|
import { join as join14 } from "node:path";
|
|
78431
79140
|
var movementIdSchema3 = external_exports.string().regex(/^mv_[A-Za-z0-9_-]{8,128}$/u);
|
|
@@ -78497,7 +79206,7 @@ var resumableSwarmReasons = /* @__PURE__ */ new Set([
|
|
|
78497
79206
|
"sweep"
|
|
78498
79207
|
]);
|
|
78499
79208
|
function treasuryRequestMovementId(swarm, requestId) {
|
|
78500
|
-
const digest =
|
|
79209
|
+
const digest = createHash3("sha256").update(`${swarm}
|
|
78501
79210
|
${requestId}`).digest("hex").slice(0, 24);
|
|
78502
79211
|
return movementIdSchema3.parse(`mv_${digest}`);
|
|
78503
79212
|
}
|
|
@@ -80556,9 +81265,12 @@ export {
|
|
|
80556
81265
|
CEILING_SWEEP_TIMEOUT_MS,
|
|
80557
81266
|
DEFAULT_AGENT_TOOLS,
|
|
80558
81267
|
DEFAULT_ARC_GAS_HEADROOM_ATOMIC,
|
|
81268
|
+
DEFAULT_AUTO_RELEASE_BELOW_USD,
|
|
80559
81269
|
DEFAULT_CEILING_ATOMIC,
|
|
80560
81270
|
DEFAULT_DISCOVERY_URL,
|
|
81271
|
+
DEFAULT_DOCS_ORIGIN,
|
|
80561
81272
|
DEFAULT_MARKETPLACE_DISCOVERY_URL,
|
|
81273
|
+
DEFAULT_MAX_PER_TASK_USD,
|
|
80562
81274
|
DEFAULT_REGISTRY_FALLBACKS,
|
|
80563
81275
|
DEFAULT_REGISTRY_URL,
|
|
80564
81276
|
DEFAULT_SPEND_CAPS,
|
|
@@ -80568,6 +81280,7 @@ export {
|
|
|
80568
81280
|
DISCOVERY_CATEGORIES,
|
|
80569
81281
|
DiscoveryCatalogError,
|
|
80570
81282
|
DistributeError,
|
|
81283
|
+
DocsError,
|
|
80571
81284
|
EIP3009_AUTHORIZATION_STATE_ABI,
|
|
80572
81285
|
EIP3009_AUTHORIZATION_TYPES,
|
|
80573
81286
|
ERC20_ABI,
|
|
@@ -80584,7 +81297,7 @@ export {
|
|
|
80584
81297
|
MARKETPLACE_KINDS,
|
|
80585
81298
|
MARKETPLACE_RANKING_VERSION,
|
|
80586
81299
|
MovementError,
|
|
80587
|
-
NETWORKS,
|
|
81300
|
+
NETWORKS2 as NETWORKS,
|
|
80588
81301
|
ONRAMP_FALLBACK_INSTRUCTIONS,
|
|
80589
81302
|
ONRAMP_NETWORK,
|
|
80590
81303
|
PASSPHRASE_ENVIRONMENT_VARIABLE,
|
|
@@ -80599,6 +81312,7 @@ export {
|
|
|
80599
81312
|
SIGN_IN_WITH_X,
|
|
80600
81313
|
SIWxError,
|
|
80601
81314
|
SOLANA_DERIVATION_PATH,
|
|
81315
|
+
SOLANA_DEVNET_CAIP2,
|
|
80602
81316
|
SOLANA_MAINNET_CAIP2,
|
|
80603
81317
|
SOLANA_MAINNET_USDC,
|
|
80604
81318
|
STATS_RANGES,
|
|
@@ -80611,6 +81325,7 @@ export {
|
|
|
80611
81325
|
SpendPolicy,
|
|
80612
81326
|
SwarmError,
|
|
80613
81327
|
SweepGasError,
|
|
81328
|
+
TASKS_CLIENT_VERBS,
|
|
80614
81329
|
TransferError,
|
|
80615
81330
|
USDC_DECIMALS,
|
|
80616
81331
|
VAPI_BUILDER_CODE,
|
|
@@ -80637,6 +81352,7 @@ export {
|
|
|
80637
81352
|
appendReceipt,
|
|
80638
81353
|
appendSearchEvent,
|
|
80639
81354
|
areSamePaymentNetwork,
|
|
81355
|
+
askDocs,
|
|
80640
81356
|
assertMaxPrice,
|
|
80641
81357
|
assertPublicUrl,
|
|
80642
81358
|
assertSIWxChallengeBoundToOrigin,
|
|
@@ -80674,6 +81390,8 @@ export {
|
|
|
80674
81390
|
createRunId,
|
|
80675
81391
|
createSIWxMessage,
|
|
80676
81392
|
createSupportReport,
|
|
81393
|
+
decideFunding,
|
|
81394
|
+
decideRelease,
|
|
80677
81395
|
decodePaymentRequiredHeader,
|
|
80678
81396
|
deleteSwarmFile,
|
|
80679
81397
|
deriveEvmPrivateKey,
|
|
@@ -80694,6 +81412,7 @@ export {
|
|
|
80694
81412
|
encryptPrivateKey,
|
|
80695
81413
|
ensureDeviceName,
|
|
80696
81414
|
entropyToPhrase,
|
|
81415
|
+
escrowFundingDayRemainingAtomic,
|
|
80697
81416
|
executeMovement,
|
|
80698
81417
|
executionModeSchema,
|
|
80699
81418
|
explorerAddressUrl,
|
|
@@ -80717,6 +81436,7 @@ export {
|
|
|
80717
81436
|
getNetworkDefinition,
|
|
80718
81437
|
getVapiPaths,
|
|
80719
81438
|
isCallableListing,
|
|
81439
|
+
isDiscoveryCatalogError,
|
|
80720
81440
|
isEvmPaymentRequirements,
|
|
80721
81441
|
isMirroredHit,
|
|
80722
81442
|
isMissingFile,
|
|
@@ -80749,6 +81469,7 @@ export {
|
|
|
80749
81469
|
lowerAccountCaps,
|
|
80750
81470
|
marketplaceBadgeCodeSchema,
|
|
80751
81471
|
marketplaceBadgeSchema,
|
|
81472
|
+
marketplaceDiscoveryEnvelopeSchema,
|
|
80752
81473
|
marketplaceDiscoveryInputSchema,
|
|
80753
81474
|
marketplaceDiscoveryPageSchema,
|
|
80754
81475
|
marketplaceExecutionMethodSchema,
|
|
@@ -80778,12 +81499,14 @@ export {
|
|
|
80778
81499
|
phraseToSeed,
|
|
80779
81500
|
pinnedLookup,
|
|
80780
81501
|
planAllocation,
|
|
81502
|
+
prepareDeliveryManifest,
|
|
80781
81503
|
promptForSecret,
|
|
80782
81504
|
protectVault,
|
|
80783
81505
|
provenanceSchema,
|
|
80784
81506
|
readAgentProfile,
|
|
80785
81507
|
readAuditLog,
|
|
80786
81508
|
readDelegationRecord,
|
|
81509
|
+
readDocs,
|
|
80787
81510
|
readKeystoreAddress,
|
|
80788
81511
|
readKeystoreVersion,
|
|
80789
81512
|
readMovement,
|
|
@@ -80813,6 +81536,7 @@ export {
|
|
|
80813
81536
|
roleGrants,
|
|
80814
81537
|
runRefSchema,
|
|
80815
81538
|
scheduleCeilingSweep,
|
|
81539
|
+
searchDocs,
|
|
80816
81540
|
searchServicesResponseSchema,
|
|
80817
81541
|
secretStore,
|
|
80818
81542
|
secretsAllowed,
|
|
@@ -80820,6 +81544,7 @@ export {
|
|
|
80820
81544
|
serviceSummarySchema,
|
|
80821
81545
|
serviceTierSchema,
|
|
80822
81546
|
setupSwarm,
|
|
81547
|
+
sha256Hex,
|
|
80823
81548
|
slugifyDeviceName,
|
|
80824
81549
|
spendCapsForWallet,
|
|
80825
81550
|
spendCapsSchema,
|
|
@@ -80838,6 +81563,7 @@ export {
|
|
|
80838
81563
|
sweepBack,
|
|
80839
81564
|
sweepSolanaUsdc,
|
|
80840
81565
|
sweepTarget,
|
|
81566
|
+
taskReservedAtomic,
|
|
80841
81567
|
transferBetweenAccounts,
|
|
80842
81568
|
treasuryRequestMovementId,
|
|
80843
81569
|
unlockKeystore,
|