@lucid-agents/taskmarket 1.45.0 → 1.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-compatibility.json +1 -1
- package/dist/{api-PZVGK3VQ.js → api-ENHCGR7K.js} +2 -2
- package/dist/{channels-LDMZ3OEM.js → channels-LX2DTMKZ.js} +4 -4
- package/dist/{chunk-PRYNO5S7.js → chunk-4MAQWPJ2.js} +1 -1
- package/dist/{chunk-QYXBVFVX.js → chunk-54J54BK7.js} +5 -5
- package/dist/{chunk-THIC75V5.js → chunk-AMT2L4BR.js} +3 -3
- package/dist/{chunk-5NILW5UT.js → chunk-AS6EFS2V.js} +2 -1
- package/dist/{chunk-6YFLKQ4Q.js → chunk-O53R76N3.js} +121 -18
- package/dist/{chunk-QUY6764O.js → chunk-PDVDVVVF.js} +2 -2
- package/dist/{chunk-JPVBWX3Q.js → chunk-PPJNXEWM.js} +3 -3
- package/dist/{chunk-XLJRCGOJ.js → chunk-RO5AHGHC.js} +1 -1
- package/dist/{chunk-KY4JM6NG.js → chunk-TUP4MTW6.js} +31 -13
- package/dist/{chunk-TPCXOWSC.js → chunk-V2BCPGOB.js} +8 -8
- package/dist/{chunk-FHDTYW6C.js → chunk-WOPSQ2GZ.js} +1 -1
- package/dist/{chunk-GIVPCMJ3.js → chunk-XRM455ZG.js} +670 -43
- package/dist/{doctor-HV5QQDGU.js → doctor-PEAKIDKS.js} +8 -8
- package/dist/index.js +345 -62
- package/dist/{launch-56RHQCWT.js → launch-CEJWCOQA.js} +11 -11
- package/dist/pi-extensions/xgate.cjs +7 -1
- package/dist/{read-auth-ZJBQQVGO.js → read-auth-524RVF3G.js} +3 -3
- package/dist/{reconcile-PQXSATCK.js → reconcile-GMYKLZTG.js} +4 -4
- package/dist/{status-EBMZGDFS.js → status-Y6JAL4DR.js} +8 -8
- package/dist/{sync-pull-423LBSPO.js → sync-pull-YFIWHI4H.js} +4 -4
- package/dist/{task-access-grants-KWTKM3NP.js → task-access-grants-GXJ6WOQK.js} +2 -2
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
listWorkerSubmissions,
|
|
15
15
|
submitTaskFiles,
|
|
16
16
|
taskRequirementsOf
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-V2BCPGOB.js";
|
|
18
18
|
import {
|
|
19
19
|
ComputeCreditError,
|
|
20
20
|
applyComputeCreditSetup,
|
|
@@ -36,18 +36,21 @@ import {
|
|
|
36
36
|
refusedPaidWrite,
|
|
37
37
|
releasePendingComputePurchase,
|
|
38
38
|
resolvePendingComputePurchases,
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
withPaymentProtocol,
|
|
40
|
+
x402FeePost,
|
|
41
|
+
x402PaymentProtocol
|
|
42
|
+
} from "./chunk-TUP4MTW6.js";
|
|
41
43
|
import {
|
|
42
44
|
signReadAuth
|
|
43
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-PDVDVVVF.js";
|
|
44
46
|
import {
|
|
45
47
|
saveTaskAccessGrant,
|
|
46
48
|
taskAccessGrantHeaders
|
|
47
|
-
} from "./chunk-
|
|
49
|
+
} from "./chunk-WOPSQ2GZ.js";
|
|
48
50
|
import {
|
|
49
51
|
MPP_TEMPO_DEFAULT_VALIDITY_SECONDS,
|
|
50
52
|
X402PayError,
|
|
53
|
+
X402_PAY_PROTOCOLS,
|
|
51
54
|
X402_POLICY_JSON_SCHEMA,
|
|
52
55
|
addX402PolicyRule,
|
|
53
56
|
getX402JournalPath,
|
|
@@ -62,7 +65,7 @@ import {
|
|
|
62
65
|
setX402PolicyRuleEnabled,
|
|
63
66
|
signSponsoredTempoTransfer,
|
|
64
67
|
signTaskmarketFeePayment
|
|
65
|
-
} from "./chunk-
|
|
68
|
+
} from "./chunk-XRM455ZG.js";
|
|
66
69
|
import {
|
|
67
70
|
ALL_NETWORKS,
|
|
68
71
|
ApiError,
|
|
@@ -102,6 +105,7 @@ import {
|
|
|
102
105
|
loadKeystore,
|
|
103
106
|
networkNameForChain,
|
|
104
107
|
networkToStamp,
|
|
108
|
+
newIdempotencyKey,
|
|
105
109
|
parseTapPrivateKey,
|
|
106
110
|
paymentProtocolOf,
|
|
107
111
|
readFailureBody,
|
|
@@ -126,7 +130,7 @@ import {
|
|
|
126
130
|
withErrorContext,
|
|
127
131
|
withIdempotentWrite,
|
|
128
132
|
withTapSignature
|
|
129
|
-
} from "./chunk-
|
|
133
|
+
} from "./chunk-AS6EFS2V.js";
|
|
130
134
|
import {
|
|
131
135
|
AGENT_AVATAR_MAX_BYTES,
|
|
132
136
|
AGENT_HIRES_ROLES,
|
|
@@ -171,6 +175,7 @@ import {
|
|
|
171
175
|
GRANT_MODE_NAMES,
|
|
172
176
|
HIRE_AGENT_AT_CAPACITY,
|
|
173
177
|
HIRE_AGENT_UNAVAILABLE,
|
|
178
|
+
HIRE_LISTING_HIDDEN,
|
|
174
179
|
HIRE_MAX_ACCEPT_WINDOW_SECS,
|
|
175
180
|
HIRE_MIN_ACCEPT_WINDOW_SECS,
|
|
176
181
|
HIRE_SERVICE_ID_MAX_LENGTH,
|
|
@@ -335,6 +340,7 @@ import {
|
|
|
335
340
|
hiddenChecksResult,
|
|
336
341
|
hireAcceptAtCapacity,
|
|
337
342
|
hireAcceptAtCapacityMessage,
|
|
343
|
+
hireListingHiddenMessage,
|
|
338
344
|
hireSelectAtCapacityMessage,
|
|
339
345
|
hireUnavailableAcknowledgeable,
|
|
340
346
|
hireUnavailableMessage,
|
|
@@ -399,7 +405,7 @@ import {
|
|
|
399
405
|
verifierProviderId,
|
|
400
406
|
verifiersUnsupportedOnChain,
|
|
401
407
|
viemChainFor
|
|
402
|
-
} from "./chunk-
|
|
408
|
+
} from "./chunk-O53R76N3.js";
|
|
403
409
|
import "./chunk-S7SJMJ2I.js";
|
|
404
410
|
|
|
405
411
|
// src/index.ts
|
|
@@ -496,9 +502,23 @@ function printResult(data, options) {
|
|
|
496
502
|
})
|
|
497
503
|
);
|
|
498
504
|
}
|
|
505
|
+
var X402_FAILURE_HINTS = {
|
|
506
|
+
challenge_expired: "The seller's payment challenge ran out before it could be paid. Nothing was signed. Request the resource again for a fresh challenge.",
|
|
507
|
+
no_supported_rail: "No payment option in the 402 can be paid here. The CLI pays x402 exact and upto, and MPP tempo charge. Check --protocol and the seller's advertised methods.",
|
|
508
|
+
insufficient_balance: "Nothing was signed. Fund the CLI wallet (taskmarket address) with the payment token on the payment network, then request again.",
|
|
509
|
+
payment_header_conflict: "Nothing was signed. Remove the header the message names (set through --headers-file or --header-env); the payment credential needs it."
|
|
510
|
+
};
|
|
511
|
+
function rpcConfigurationHint(error) {
|
|
512
|
+
const cause = error.cause instanceof Error ? error.cause.message : void 0;
|
|
513
|
+
if (error.code !== "request_failed" || cause === void 0) return void 0;
|
|
514
|
+
if (!/^(No RPC configuration exists for|RPC environment variable )/.test(cause)) return void 0;
|
|
515
|
+
return `${cause}. Nothing was signed. In the x402 policy file (taskmarket x402 policy path) add "networks": { "<network>": { "rpcUrlEnv": "<ENV_VAR>" } } for the payment's network (eip155:4217 Tempo, eip155:42431 Tempo Moderato) and export that variable as an HTTPS RPC URL.`;
|
|
516
|
+
}
|
|
499
517
|
function x402FailureFields(error) {
|
|
518
|
+
const hint = X402_FAILURE_HINTS[error.code] ?? rpcConfigurationHint(error);
|
|
500
519
|
return {
|
|
501
520
|
code: error.code,
|
|
521
|
+
...hint !== void 0 ? { hint } : {},
|
|
502
522
|
...error.invocationId !== void 0 ? { invocationId: error.invocationId } : {},
|
|
503
523
|
...error.invocation !== void 0 ? {
|
|
504
524
|
invocation: {
|
|
@@ -10023,11 +10043,13 @@ function parseMetricAndDropOptions(opts) {
|
|
|
10023
10043
|
}
|
|
10024
10044
|
return { fields };
|
|
10025
10045
|
}
|
|
10026
|
-
async function hireAvailabilityError(hire) {
|
|
10046
|
+
async function hireAvailabilityError(hire, requester) {
|
|
10027
10047
|
let availability;
|
|
10028
10048
|
try {
|
|
10049
|
+
const query4 = new URLSearchParams({ worker: hire.worker });
|
|
10050
|
+
if (requester) query4.set("requester", requester);
|
|
10029
10051
|
availability = await apiGet(
|
|
10030
|
-
`/api/tasks/hire-availability
|
|
10052
|
+
`/api/tasks/hire-availability?${query4.toString()}`
|
|
10031
10053
|
);
|
|
10032
10054
|
} catch (err) {
|
|
10033
10055
|
if (err instanceof ApiError && err.status === 404) return null;
|
|
@@ -10447,7 +10469,8 @@ async function runCreateTask(input, extra = {}) {
|
|
|
10447
10469
|
if ("error" in hire) return void printError(hire.error);
|
|
10448
10470
|
if (hire.hire) body.hire = hire.hire;
|
|
10449
10471
|
if (hire.hire) {
|
|
10450
|
-
const
|
|
10472
|
+
const requesterAddress = await loadKeystore().then((keystore) => keystore.walletAddress).catch(() => void 0);
|
|
10473
|
+
const refusal = await hireAvailabilityError(hire.hire, requesterAddress);
|
|
10451
10474
|
if (refusal) {
|
|
10452
10475
|
return void renderFailure(new Error(refusal.message), { details: { code: refusal.code } });
|
|
10453
10476
|
}
|
|
@@ -13530,7 +13553,7 @@ async function runAgentCommand(options) {
|
|
|
13530
13553
|
try {
|
|
13531
13554
|
const { assertAgentCompatibility } = await import("./compatibility-636WJOEX.js");
|
|
13532
13555
|
const pi = assertAgentCompatibility();
|
|
13533
|
-
const { runAgent } = await import("./launch-
|
|
13556
|
+
const { runAgent } = await import("./launch-CEJWCOQA.js");
|
|
13534
13557
|
result = await runAgent({
|
|
13535
13558
|
model: options.model,
|
|
13536
13559
|
pi,
|
|
@@ -13964,13 +13987,13 @@ function agentManagementCommands() {
|
|
|
13964
13987
|
const status = new Command58("status").description(
|
|
13965
13988
|
"Show the agent channels (locked, charged, refundable), purchases with an unknown outcome, the sandbox and compute credit. Reads only."
|
|
13966
13989
|
).action(async () => {
|
|
13967
|
-
const { collectAgentStatus } = await import("./status-
|
|
13990
|
+
const { collectAgentStatus } = await import("./status-Y6JAL4DR.js");
|
|
13968
13991
|
await run(() => collectAgentStatus());
|
|
13969
13992
|
});
|
|
13970
13993
|
const doctor = new Command58("doctor").description(
|
|
13971
13994
|
"Check that the agent can start: Node and the bundled runtime, wallet and policy, channels, API, sandbox broker, host keys, xgate and RPC. Reads only."
|
|
13972
13995
|
).action(async () => {
|
|
13973
|
-
const { runDoctor } = await import("./doctor-
|
|
13996
|
+
const { runDoctor } = await import("./doctor-PEAKIDKS.js");
|
|
13974
13997
|
const report = await run(() => runDoctor());
|
|
13975
13998
|
if (report && !report.ok) process.exitCode = 1;
|
|
13976
13999
|
});
|
|
@@ -13981,7 +14004,7 @@ function agentManagementCommands() {
|
|
|
13981
14004
|
"Reconcile the open purchases of this channel, as status lists it; also reaches retired channels"
|
|
13982
14005
|
).action(
|
|
13983
14006
|
async (invocationId, options) => {
|
|
13984
|
-
const { reconcileChannelPurchases, reconcileInvocation } = await import("./reconcile-
|
|
14007
|
+
const { reconcileChannelPurchases, reconcileInvocation } = await import("./reconcile-GMYKLZTG.js");
|
|
13985
14008
|
const choice = { rail: options.rail, channel: options.channel };
|
|
13986
14009
|
if (invocationId !== void 0) {
|
|
13987
14010
|
await run(() => reconcileInvocation(invocationId, { choice }));
|
|
@@ -14013,7 +14036,7 @@ function agentManagementCommands() {
|
|
|
14013
14036
|
`Not a USDC amount: ${options.amount} (digits, at most 6 decimals)`
|
|
14014
14037
|
);
|
|
14015
14038
|
}
|
|
14016
|
-
const { openAgentChannels, requestTopUp, selectRail, withdrawalHatch } = await import("./channels-
|
|
14039
|
+
const { openAgentChannels, requestTopUp, selectRail, withdrawalHatch } = await import("./channels-LX2DTMKZ.js");
|
|
14017
14040
|
const { rails } = await openAgentChannels();
|
|
14018
14041
|
const result = await requestTopUp(selectRail(rails, options.rail), amount);
|
|
14019
14042
|
return {
|
|
@@ -14033,8 +14056,8 @@ function agentManagementCommands() {
|
|
|
14033
14056
|
await run(async () => {
|
|
14034
14057
|
await requireExperimental();
|
|
14035
14058
|
const { AGENT_VIEW_VERSION } = await import("./budget-view-J6L7X6EY.js");
|
|
14036
|
-
const { closeChannel, openAgentChannels, selectChannel } = await import("./channels-
|
|
14037
|
-
const { reconcileLeasedPurchase } = await import("./reconcile-
|
|
14059
|
+
const { closeChannel, openAgentChannels, selectChannel } = await import("./channels-LX2DTMKZ.js");
|
|
14060
|
+
const { reconcileLeasedPurchase } = await import("./reconcile-GMYKLZTG.js");
|
|
14038
14061
|
const opened = await openAgentChannels();
|
|
14039
14062
|
const { rail, retired } = selectChannel(opened, options);
|
|
14040
14063
|
const result = await closeChannel(
|
|
@@ -14088,7 +14111,7 @@ function agentManagementCommands() {
|
|
|
14088
14111
|
async (options) => {
|
|
14089
14112
|
await run(async () => {
|
|
14090
14113
|
await requireExperimental();
|
|
14091
|
-
const { runPull } = await import("./sync-pull-
|
|
14114
|
+
const { runPull } = await import("./sync-pull-YFIWHI4H.js");
|
|
14092
14115
|
const { terminalPrompter } = await import("./prompter-LSICEYSQ.js");
|
|
14093
14116
|
return runPull(options, {
|
|
14094
14117
|
interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY),
|
|
@@ -16390,7 +16413,9 @@ function cachedInboxLookup(lookup, options = {}) {
|
|
|
16390
16413
|
// src/lib/xmtp-cursor.ts
|
|
16391
16414
|
import fs4 from "fs";
|
|
16392
16415
|
import path2 from "path";
|
|
16393
|
-
var MAX_RECENT_IDS_PER_CONVERSATION =
|
|
16416
|
+
var MAX_RECENT_IDS_PER_CONVERSATION = 5e3;
|
|
16417
|
+
var MAX_CURSOR_RECENT_IDS = 2e4;
|
|
16418
|
+
var MAX_CURSOR_CONVERSATIONS = 1e3;
|
|
16394
16419
|
var CURSOR_OVERLAP_NS = 10n * 60n * 1000000000n;
|
|
16395
16420
|
var CURSOR_FLUSH_DELAY_MS = 1e3;
|
|
16396
16421
|
function xmtpCursorPath(dbDir, walletAddress) {
|
|
@@ -16398,40 +16423,95 @@ function xmtpCursorPath(dbDir, walletAddress) {
|
|
|
16398
16423
|
}
|
|
16399
16424
|
function readCursorFile(filePath) {
|
|
16400
16425
|
const conversations = /* @__PURE__ */ new Map();
|
|
16426
|
+
let prunedBeforeNs = 0n;
|
|
16401
16427
|
try {
|
|
16402
16428
|
const parsed = JSON.parse(fs4.readFileSync(filePath, "utf8"));
|
|
16403
16429
|
if (parsed?.version === 2 && parsed.conversations && typeof parsed.conversations === "object") {
|
|
16430
|
+
if (typeof parsed.prunedBeforeNs === "string" && /^\d+$/.test(parsed.prunedBeforeNs)) {
|
|
16431
|
+
prunedBeforeNs = BigInt(parsed.prunedBeforeNs);
|
|
16432
|
+
}
|
|
16404
16433
|
for (const [conversationId, entry] of Object.entries(parsed.conversations)) {
|
|
16405
16434
|
if (!entry || typeof entry.lastSentAtNs !== "string" || !/^\d+$/.test(entry.lastSentAtNs) || !Array.isArray(entry.recentIds)) {
|
|
16406
16435
|
continue;
|
|
16407
16436
|
}
|
|
16408
|
-
const
|
|
16437
|
+
const lastSentAtNs = BigInt(entry.lastSentAtNs);
|
|
16438
|
+
const recentIds = [];
|
|
16439
|
+
const recentAtNs = [];
|
|
16440
|
+
entry.recentIds.forEach((id, index) => {
|
|
16441
|
+
if (typeof id !== "string") return;
|
|
16442
|
+
const at = entry.recentAtNs?.[index];
|
|
16443
|
+
recentIds.push(id);
|
|
16444
|
+
recentAtNs.push(typeof at === "string" && /^\d+$/.test(at) ? BigInt(at) : lastSentAtNs);
|
|
16445
|
+
});
|
|
16446
|
+
const start = Math.max(0, recentIds.length - MAX_RECENT_IDS_PER_CONVERSATION);
|
|
16447
|
+
const ids = recentIds.slice(start);
|
|
16409
16448
|
conversations.set(conversationId, {
|
|
16410
|
-
lastSentAtNs
|
|
16411
|
-
recentIds,
|
|
16412
|
-
|
|
16449
|
+
lastSentAtNs,
|
|
16450
|
+
recentIds: ids,
|
|
16451
|
+
recentAtNs: recentAtNs.slice(start),
|
|
16452
|
+
known: new Set(ids)
|
|
16413
16453
|
});
|
|
16414
16454
|
}
|
|
16415
16455
|
}
|
|
16416
16456
|
} catch {
|
|
16417
16457
|
}
|
|
16418
|
-
return conversations;
|
|
16458
|
+
return { conversations, prunedBeforeNs };
|
|
16459
|
+
}
|
|
16460
|
+
function pruneConversations(state) {
|
|
16461
|
+
const { conversations } = state;
|
|
16462
|
+
if (conversations.size <= MAX_CURSOR_CONVERSATIONS) return;
|
|
16463
|
+
const oldestFirst = [...conversations.entries()].sort(
|
|
16464
|
+
(a, b) => a[1].lastSentAtNs < b[1].lastSentAtNs ? -1 : a[1].lastSentAtNs > b[1].lastSentAtNs ? 1 : 0
|
|
16465
|
+
);
|
|
16466
|
+
for (const [conversationId, entry] of oldestFirst.slice(
|
|
16467
|
+
0,
|
|
16468
|
+
conversations.size - MAX_CURSOR_CONVERSATIONS
|
|
16469
|
+
)) {
|
|
16470
|
+
if (entry.lastSentAtNs > state.prunedBeforeNs) state.prunedBeforeNs = entry.lastSentAtNs;
|
|
16471
|
+
conversations.delete(conversationId);
|
|
16472
|
+
}
|
|
16419
16473
|
}
|
|
16420
|
-
function writeCursorFile(filePath,
|
|
16421
|
-
|
|
16422
|
-
|
|
16474
|
+
function writeCursorFile(filePath, state) {
|
|
16475
|
+
pruneConversations(state);
|
|
16476
|
+
const value = {
|
|
16477
|
+
version: 2,
|
|
16478
|
+
prunedBeforeNs: state.prunedBeforeNs.toString(),
|
|
16479
|
+
conversations: {}
|
|
16480
|
+
};
|
|
16481
|
+
const kept = [];
|
|
16482
|
+
for (const [conversationId, entry] of state.conversations) {
|
|
16483
|
+
const floor = entry.lastSentAtNs - CURSOR_OVERLAP_NS;
|
|
16484
|
+
entry.recentIds.forEach((id, index) => {
|
|
16485
|
+
if (entry.recentAtNs[index] >= floor) {
|
|
16486
|
+
kept.push({ conversationId, id, at: entry.recentAtNs[index] });
|
|
16487
|
+
}
|
|
16488
|
+
});
|
|
16489
|
+
}
|
|
16490
|
+
if (kept.length > MAX_CURSOR_RECENT_IDS) {
|
|
16491
|
+
kept.sort((a, b) => a.at < b.at ? 1 : a.at > b.at ? -1 : 0);
|
|
16492
|
+
kept.length = MAX_CURSOR_RECENT_IDS;
|
|
16493
|
+
}
|
|
16494
|
+
for (const [conversationId, entry] of state.conversations) {
|
|
16423
16495
|
value.conversations[conversationId] = {
|
|
16424
16496
|
lastSentAtNs: entry.lastSentAtNs.toString(),
|
|
16425
|
-
recentIds:
|
|
16497
|
+
recentIds: [],
|
|
16498
|
+
recentAtNs: []
|
|
16426
16499
|
};
|
|
16427
16500
|
}
|
|
16501
|
+
for (const { conversationId, id, at } of kept) {
|
|
16502
|
+
const target = value.conversations[conversationId];
|
|
16503
|
+
target.recentIds.push(id);
|
|
16504
|
+
target.recentAtNs?.push(at.toString());
|
|
16505
|
+
}
|
|
16428
16506
|
fs4.mkdirSync(path2.dirname(filePath), { recursive: true });
|
|
16429
16507
|
const tmpPath = `${filePath}.${process.pid}.tmp`;
|
|
16430
16508
|
fs4.writeFileSync(tmpPath, JSON.stringify(value), { mode: 384 });
|
|
16431
16509
|
fs4.renameSync(tmpPath, filePath);
|
|
16432
16510
|
}
|
|
16433
16511
|
function loadXmtpCursor(filePath, options = {}) {
|
|
16434
|
-
const
|
|
16512
|
+
const state = readCursorFile(filePath);
|
|
16513
|
+
const { conversations } = state;
|
|
16514
|
+
pruneConversations(state);
|
|
16435
16515
|
const flushDelayMs = options.flushDelayMs ?? CURSOR_FLUSH_DELAY_MS;
|
|
16436
16516
|
let dirty = false;
|
|
16437
16517
|
let timer;
|
|
@@ -16445,7 +16525,7 @@ function loadXmtpCursor(filePath, options = {}) {
|
|
|
16445
16525
|
}
|
|
16446
16526
|
dirty = false;
|
|
16447
16527
|
try {
|
|
16448
|
-
writeCursorFile(filePath,
|
|
16528
|
+
writeCursorFile(filePath, state);
|
|
16449
16529
|
} catch (error) {
|
|
16450
16530
|
process.stderr.write(
|
|
16451
16531
|
`xmtp: could not save the listener cursor: ${error instanceof Error ? error.message : String(error)}
|
|
@@ -16457,7 +16537,7 @@ function loadXmtpCursor(filePath, options = {}) {
|
|
|
16457
16537
|
floorFor: (conversationId) => {
|
|
16458
16538
|
const entry = conversations.get(conversationId);
|
|
16459
16539
|
if (!entry) {
|
|
16460
|
-
return void 0;
|
|
16540
|
+
return state.prunedBeforeNs > 0n ? state.prunedBeforeNs : void 0;
|
|
16461
16541
|
}
|
|
16462
16542
|
return entry.lastSentAtNs > CURSOR_OVERLAP_NS ? entry.lastSentAtNs - CURSOR_OVERLAP_NS : 0n;
|
|
16463
16543
|
},
|
|
@@ -16465,7 +16545,7 @@ function loadXmtpCursor(filePath, options = {}) {
|
|
|
16465
16545
|
advance: (message) => {
|
|
16466
16546
|
let entry = conversations.get(message.conversationId);
|
|
16467
16547
|
if (!entry) {
|
|
16468
|
-
entry = { lastSentAtNs: 0n, recentIds: [], known: /* @__PURE__ */ new Set() };
|
|
16548
|
+
entry = { lastSentAtNs: 0n, recentIds: [], recentAtNs: [], known: /* @__PURE__ */ new Set() };
|
|
16469
16549
|
conversations.set(message.conversationId, entry);
|
|
16470
16550
|
}
|
|
16471
16551
|
if (message.sentAtNs > entry.lastSentAtNs) {
|
|
@@ -16474,8 +16554,10 @@ function loadXmtpCursor(filePath, options = {}) {
|
|
|
16474
16554
|
if (!entry.known.has(message.id)) {
|
|
16475
16555
|
entry.known.add(message.id);
|
|
16476
16556
|
entry.recentIds.push(message.id);
|
|
16557
|
+
entry.recentAtNs.push(message.sentAtNs);
|
|
16477
16558
|
while (entry.recentIds.length > MAX_RECENT_IDS_PER_CONVERSATION) {
|
|
16478
16559
|
const dropped = entry.recentIds.shift();
|
|
16560
|
+
entry.recentAtNs.shift();
|
|
16479
16561
|
if (dropped !== void 0) {
|
|
16480
16562
|
entry.known.delete(dropped);
|
|
16481
16563
|
}
|
|
@@ -17299,6 +17381,16 @@ async function createProductionClient(input, env) {
|
|
|
17299
17381
|
return revocable;
|
|
17300
17382
|
},
|
|
17301
17383
|
inboxIdForAddress,
|
|
17384
|
+
signWithInstallationKey(text) {
|
|
17385
|
+
const sign = asObject(client)?.signWithInstallationKey;
|
|
17386
|
+
if (typeof sign !== "function") {
|
|
17387
|
+
throw new XmtpTransportError(
|
|
17388
|
+
"XMTP SDK client cannot sign with its installation key",
|
|
17389
|
+
"non-retryable"
|
|
17390
|
+
);
|
|
17391
|
+
}
|
|
17392
|
+
return Buffer.from(sign.call(client, text)).toString("hex");
|
|
17393
|
+
},
|
|
17302
17394
|
async setConsentState(targetInboxId, state) {
|
|
17303
17395
|
const clientObject = asObject(client);
|
|
17304
17396
|
if (!clientObject) return;
|
|
@@ -17388,6 +17480,59 @@ async function createXmtpClient(input) {
|
|
|
17388
17480
|
}
|
|
17389
17481
|
return createProductionClient(input, env);
|
|
17390
17482
|
}
|
|
17483
|
+
var networkInboxLookups = /* @__PURE__ */ new Map();
|
|
17484
|
+
async function lookupInboxIdOnNetwork(address3) {
|
|
17485
|
+
const env = resolveXmtpEnv();
|
|
17486
|
+
let lookup = networkInboxLookups.get(env);
|
|
17487
|
+
if (!lookup) {
|
|
17488
|
+
lookup = env === "memory" ? memoryInboxLookup() : sdkNetworkInboxLookup(env);
|
|
17489
|
+
networkInboxLookups.set(env, lookup);
|
|
17490
|
+
}
|
|
17491
|
+
return lookup(address3);
|
|
17492
|
+
}
|
|
17493
|
+
function memoryInboxLookup() {
|
|
17494
|
+
return async (address3) => {
|
|
17495
|
+
const busDir = process.env.TASKMARKET_XMTP_MEMORY_DIR?.trim();
|
|
17496
|
+
return devInboxByAddress.get(address3.toLowerCase()) ?? (busDir ? createFileBus(busDir).lookup(address3) : null);
|
|
17497
|
+
};
|
|
17498
|
+
}
|
|
17499
|
+
function sdkNetworkInboxLookup(env) {
|
|
17500
|
+
let backend;
|
|
17501
|
+
return cachedInboxLookup(async (address3) => {
|
|
17502
|
+
assertXmtpSupported();
|
|
17503
|
+
const sdkModule = asObject(
|
|
17504
|
+
await import("@xmtp/node-sdk").catch((error) => {
|
|
17505
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
17506
|
+
throw new XmtpTransportError(
|
|
17507
|
+
`Could not load @xmtp/node-sdk on ${process.platform}-${process.arch}: ${reason}`,
|
|
17508
|
+
"non-retryable",
|
|
17509
|
+
error
|
|
17510
|
+
);
|
|
17511
|
+
})
|
|
17512
|
+
);
|
|
17513
|
+
const createBackend = sdkModule?.createBackend;
|
|
17514
|
+
const getInboxIdForIdentifier = sdkModule?.getInboxIdForIdentifier;
|
|
17515
|
+
if (typeof createBackend !== "function" || typeof getInboxIdForIdentifier !== "function") {
|
|
17516
|
+
throw new XmtpTransportError(
|
|
17517
|
+
"XMTP SDK cannot resolve an address to an inbox without a client",
|
|
17518
|
+
"non-retryable"
|
|
17519
|
+
);
|
|
17520
|
+
}
|
|
17521
|
+
const resolved = await withRetry(async () => {
|
|
17522
|
+
backend ??= createBackend({ env });
|
|
17523
|
+
try {
|
|
17524
|
+
return await getInboxIdForIdentifier(await backend, {
|
|
17525
|
+
identifier: address3,
|
|
17526
|
+
identifierKind: 0
|
|
17527
|
+
});
|
|
17528
|
+
} catch (error) {
|
|
17529
|
+
backend = void 0;
|
|
17530
|
+
throw error;
|
|
17531
|
+
}
|
|
17532
|
+
}, parseRetryAttempts());
|
|
17533
|
+
return resolved ?? null;
|
|
17534
|
+
});
|
|
17535
|
+
}
|
|
17391
17536
|
function sentRequestStoreFor(client) {
|
|
17392
17537
|
return createSentRequestStore(sentRequestsPath(client.dbPath));
|
|
17393
17538
|
}
|
|
@@ -17656,7 +17801,7 @@ function parseJsonPayload(value) {
|
|
|
17656
17801
|
return parsed;
|
|
17657
17802
|
}
|
|
17658
17803
|
async function resolveInboxId(to) {
|
|
17659
|
-
if (
|
|
17804
|
+
if (isRawInboxId(to)) {
|
|
17660
17805
|
return to;
|
|
17661
17806
|
}
|
|
17662
17807
|
const param = isAddress3(to) ? `address=${encodeURIComponent(to)}` : `agentId=${encodeURIComponent(to)}&chainId=${selectedNetwork().chainId}`;
|
|
@@ -17667,6 +17812,29 @@ async function resolveInboxId(to) {
|
|
|
17667
17812
|
}
|
|
17668
17813
|
return result.inboxId;
|
|
17669
17814
|
}
|
|
17815
|
+
function isRawInboxId(value) {
|
|
17816
|
+
return !isAddress3(value) && value.length === 64 && /^[0-9a-f]+$/.test(value);
|
|
17817
|
+
}
|
|
17818
|
+
async function resolvePeerRuleInboxId(to, inboxIdOnNetwork = lookupInboxIdOnNetwork) {
|
|
17819
|
+
if (isRawInboxId(to)) {
|
|
17820
|
+
return to;
|
|
17821
|
+
}
|
|
17822
|
+
let address3 = to;
|
|
17823
|
+
if (!isAddress3(to)) {
|
|
17824
|
+
const result = await apiGet(
|
|
17825
|
+
`/api/xmtp/resolve?agentId=${encodeURIComponent(to)}&chainId=${selectedNetwork().chainId}`
|
|
17826
|
+
);
|
|
17827
|
+
if (!result.address) {
|
|
17828
|
+
throw new Error(`No XMTP inbox found for agent "${to}"`);
|
|
17829
|
+
}
|
|
17830
|
+
address3 = result.address;
|
|
17831
|
+
}
|
|
17832
|
+
const inboxId = await inboxIdOnNetwork(address3);
|
|
17833
|
+
if (!inboxId) {
|
|
17834
|
+
throw new Error(`No XMTP inbox found on the XMTP network for address ${address3}`);
|
|
17835
|
+
}
|
|
17836
|
+
return inboxId;
|
|
17837
|
+
}
|
|
17670
17838
|
function getDefaultQueryTimeoutMs() {
|
|
17671
17839
|
const raw = process.env.TASKMARKET_XMTP_QUERY_TIMEOUT_MS;
|
|
17672
17840
|
if (!raw) {
|
|
@@ -17686,6 +17854,33 @@ function senderInboxIdFor(keystore, client) {
|
|
|
17686
17854
|
}
|
|
17687
17855
|
return client.inboxId;
|
|
17688
17856
|
}
|
|
17857
|
+
async function proveInstallation(keystore, client) {
|
|
17858
|
+
if (!client.signWithInstallationKey || !/^[0-9a-f]{64}$/.test(client.installationId)) {
|
|
17859
|
+
return void 0;
|
|
17860
|
+
}
|
|
17861
|
+
let issued;
|
|
17862
|
+
try {
|
|
17863
|
+
({ data: issued } = await apiPost(
|
|
17864
|
+
"/api/xmtp/challenge",
|
|
17865
|
+
{
|
|
17866
|
+
deviceId: keystore.deviceId,
|
|
17867
|
+
apiToken: keystore.apiToken,
|
|
17868
|
+
installationId: client.installationId
|
|
17869
|
+
},
|
|
17870
|
+
{ idempotencyKey: newIdempotencyKey() }
|
|
17871
|
+
));
|
|
17872
|
+
} catch (error) {
|
|
17873
|
+
if (error?.status !== 404) throw error;
|
|
17874
|
+
process.stderr.write(
|
|
17875
|
+
"XMTP: this backend does not issue installation challenges yet; registering without a proof.\n"
|
|
17876
|
+
);
|
|
17877
|
+
return void 0;
|
|
17878
|
+
}
|
|
17879
|
+
return {
|
|
17880
|
+
challengeId: issued.challengeId,
|
|
17881
|
+
signature: client.signWithInstallationKey(issued.challenge)
|
|
17882
|
+
};
|
|
17883
|
+
}
|
|
17689
17884
|
var xmtpCommand = new Command78("xmtp").description("Manage XMTP messaging for this agent");
|
|
17690
17885
|
xmtpCommand.hook("preAction", () => {
|
|
17691
17886
|
if (resolveXmtpEnv() !== "memory") assertXmtpSupported();
|
|
@@ -17699,13 +17894,15 @@ xmtpCommand.command("init").description("Initialize XMTP client and register ins
|
|
|
17699
17894
|
existingDbPath: keystore.xmtpDbPath,
|
|
17700
17895
|
keystore
|
|
17701
17896
|
});
|
|
17897
|
+
const installationProof = await proveInstallation(keystore, client);
|
|
17702
17898
|
const { data: status, idempotencyKey } = await apiPost("/api/xmtp/bootstrap", {
|
|
17703
17899
|
deviceId: keystore.deviceId,
|
|
17704
17900
|
apiToken: keystore.apiToken,
|
|
17705
17901
|
inboxId: client.inboxId,
|
|
17706
17902
|
installationId: client.installationId,
|
|
17707
17903
|
dbPath: client.dbPath,
|
|
17708
|
-
clientVersion: process.env.npm_package_version ?? "unknown"
|
|
17904
|
+
clientVersion: process.env.npm_package_version ?? "unknown",
|
|
17905
|
+
...installationProof ? { installationProof } : {}
|
|
17709
17906
|
});
|
|
17710
17907
|
await saveKeystore({
|
|
17711
17908
|
...keystore,
|
|
@@ -17854,7 +18051,7 @@ peersCommand.command("set").description("Set messaging policy for a specific pee
|
|
|
17854
18051
|
throw new Error(`--policy must be one of: ${validPolicies.join(", ")}`);
|
|
17855
18052
|
}
|
|
17856
18053
|
const keystore = await loadKeystore();
|
|
17857
|
-
const peerInboxId = await
|
|
18054
|
+
const peerInboxId = await resolvePeerRuleInboxId(options.to);
|
|
17858
18055
|
const { data: result, idempotencyKey } = await apiPost(
|
|
17859
18056
|
"/api/xmtp/peers",
|
|
17860
18057
|
{
|
|
@@ -17877,7 +18074,7 @@ allowlistCommand.command("add").description("Allow messages from a peer inbox (X
|
|
|
17877
18074
|
existingDbPath: keystore.xmtpDbPath,
|
|
17878
18075
|
keystore
|
|
17879
18076
|
});
|
|
17880
|
-
const targetInboxId = await
|
|
18077
|
+
const targetInboxId = await resolvePeerRuleInboxId(options.to);
|
|
17881
18078
|
if (!client.setConsentState) {
|
|
17882
18079
|
throw new Error("setConsentState not available in this XMTP client mode");
|
|
17883
18080
|
}
|
|
@@ -17893,7 +18090,7 @@ allowlistCommand.command("remove").description("Deny messages from a peer inbox
|
|
|
17893
18090
|
existingDbPath: keystore.xmtpDbPath,
|
|
17894
18091
|
keystore
|
|
17895
18092
|
});
|
|
17896
|
-
const targetInboxId = await
|
|
18093
|
+
const targetInboxId = await resolvePeerRuleInboxId(options.to);
|
|
17897
18094
|
if (!client.setConsentState) {
|
|
17898
18095
|
throw new Error("setConsentState not available in this XMTP client mode");
|
|
17899
18096
|
}
|
|
@@ -17909,7 +18106,7 @@ allowlistCommand.command("check").description("Check the XMTP SDK consent state
|
|
|
17909
18106
|
existingDbPath: keystore.xmtpDbPath,
|
|
17910
18107
|
keystore
|
|
17911
18108
|
});
|
|
17912
|
-
const targetInboxId = await
|
|
18109
|
+
const targetInboxId = await resolvePeerRuleInboxId(options.to);
|
|
17913
18110
|
if (!client.getConsentState) {
|
|
17914
18111
|
throw new Error("getConsentState not available in this XMTP client mode");
|
|
17915
18112
|
}
|
|
@@ -18403,7 +18600,7 @@ function emailReceivedLine(email) {
|
|
|
18403
18600
|
to: email.toAddress,
|
|
18404
18601
|
subject: email.subject,
|
|
18405
18602
|
receivedAt: email.receivedAt,
|
|
18406
|
-
verified: senderVerification === "pass",
|
|
18603
|
+
verified: senderVerification === "pass" || senderVerification === "platform",
|
|
18407
18604
|
senderVerification,
|
|
18408
18605
|
isRead: email.isRead,
|
|
18409
18606
|
command: `taskmarket email read ${email.id}`
|
|
@@ -19111,11 +19308,17 @@ var registerCommand = new Command83("register").description(
|
|
|
19111
19308
|
|
|
19112
19309
|
// src/commands/email/inbox.ts
|
|
19113
19310
|
import { Command as Command84 } from "commander";
|
|
19114
|
-
var inboxCommand2 = new Command84("inbox").description("List emails in your inbox").option("--limit <n>", "Number of emails to return", "20").option("--unread", "Show only unread emails").action(async (opts) => {
|
|
19311
|
+
var inboxCommand2 = new Command84("inbox").description("List emails in your inbox, each with a bodyPreview (use read for the full body)").option("--limit <n>", "Number of emails to return", "20").option("--offset <n>", "Skip this many emails, to page past --limit", "0").option("--unread", "Show only unread emails").action(async (opts) => {
|
|
19312
|
+
const offset = Number(opts.offset);
|
|
19313
|
+
if (!Number.isInteger(offset) || offset < 0) {
|
|
19314
|
+
printError("--offset must be a whole number");
|
|
19315
|
+
return;
|
|
19316
|
+
}
|
|
19115
19317
|
const keystore = await loadKeystore();
|
|
19116
19318
|
const params = new URLSearchParams({
|
|
19117
19319
|
deviceId: keystore.deviceId,
|
|
19118
|
-
limit: opts.limit
|
|
19320
|
+
limit: opts.limit,
|
|
19321
|
+
offset: String(offset)
|
|
19119
19322
|
});
|
|
19120
19323
|
if (opts.unread) {
|
|
19121
19324
|
params.set("unread", "true");
|
|
@@ -19128,7 +19331,25 @@ var inboxCommand2 = new Command84("inbox").description("List emails in your inbo
|
|
|
19128
19331
|
|
|
19129
19332
|
// src/commands/email/read.ts
|
|
19130
19333
|
import { Command as Command85 } from "commander";
|
|
19131
|
-
var
|
|
19334
|
+
var EMAIL_READ_BODY_MAX_CHARS = 32768;
|
|
19335
|
+
function capEmailBodies(email, max) {
|
|
19336
|
+
let truncated = false;
|
|
19337
|
+
const capped = {};
|
|
19338
|
+
for (const key of ["bodyText", "bodyHtml"]) {
|
|
19339
|
+
const value = email[key];
|
|
19340
|
+
if (typeof value === "string" && value.length > max) {
|
|
19341
|
+
let end = max;
|
|
19342
|
+
const last = value.charCodeAt(end - 1);
|
|
19343
|
+
if (last >= 55296 && last <= 56319) end -= 1;
|
|
19344
|
+
capped[key] = value.slice(0, end);
|
|
19345
|
+
truncated = true;
|
|
19346
|
+
}
|
|
19347
|
+
}
|
|
19348
|
+
return { ...email, ...capped, truncated };
|
|
19349
|
+
}
|
|
19350
|
+
var readCommand = new Command85("read").description(
|
|
19351
|
+
`Read an email by ID (marks it as read). Each body is cut at ${EMAIL_READ_BODY_MAX_CHARS} characters unless --full`
|
|
19352
|
+
).argument("<id>", "Email ID").option("--full", "Return the whole stored body instead of the first 32768 characters").action(async (id, opts) => {
|
|
19132
19353
|
const keystore = await loadKeystore();
|
|
19133
19354
|
const params = new URLSearchParams({
|
|
19134
19355
|
deviceId: keystore.deviceId,
|
|
@@ -19137,7 +19358,9 @@ var readCommand = new Command85("read").description("Read an email by ID (marks
|
|
|
19137
19358
|
const result = await apiGet(`/api/emails/get?${params.toString()}`, {
|
|
19138
19359
|
headers: { "x-taskmarket-api-token": keystore.apiToken }
|
|
19139
19360
|
});
|
|
19140
|
-
printResult(
|
|
19361
|
+
printResult(
|
|
19362
|
+
opts.full ? { ...result, truncated: false } : capEmailBodies(result, EMAIL_READ_BODY_MAX_CHARS)
|
|
19363
|
+
);
|
|
19141
19364
|
});
|
|
19142
19365
|
|
|
19143
19366
|
// src/commands/email/send.ts
|
|
@@ -19162,7 +19385,22 @@ var sendCommand = new Command86("send").description("Send an email").requiredOpt
|
|
|
19162
19385
|
|
|
19163
19386
|
// src/commands/email/reply.ts
|
|
19164
19387
|
import { Command as Command87 } from "commander";
|
|
19165
|
-
var
|
|
19388
|
+
var VERIFIED_SENDER_VALUES = ["pass", "platform"];
|
|
19389
|
+
function isVerifiedSender(senderVerification) {
|
|
19390
|
+
return senderVerification != null && VERIFIED_SENDER_VALUES.includes(senderVerification);
|
|
19391
|
+
}
|
|
19392
|
+
function domainOf(address3) {
|
|
19393
|
+
return address3.slice(address3.lastIndexOf("@") + 1).trim().toLowerCase();
|
|
19394
|
+
}
|
|
19395
|
+
function replyNeedsVerifiedSender(original) {
|
|
19396
|
+
if (isVerifiedSender(original.senderVerification)) return false;
|
|
19397
|
+
const platformDomain = original.toAddress ? domainOf(original.toAddress) : "";
|
|
19398
|
+
return platformDomain === "" || domainOf(original.fromAddress) !== platformDomain;
|
|
19399
|
+
}
|
|
19400
|
+
var replyCommand = new Command87("reply").description("Reply to an email").argument("<id>", "Email ID to reply to").requiredOption("--body <text>", "Reply body text").option(
|
|
19401
|
+
"--allow-unverified-sender",
|
|
19402
|
+
"Reply even though the sender's address is not verified (it may be forged)"
|
|
19403
|
+
).action(async (id, opts) => {
|
|
19166
19404
|
const keystore = await loadKeystore();
|
|
19167
19405
|
const params = new URLSearchParams({
|
|
19168
19406
|
deviceId: keystore.deviceId,
|
|
@@ -19171,6 +19409,14 @@ var replyCommand = new Command87("reply").description("Reply to an email").argum
|
|
|
19171
19409
|
const original = await apiGet(`/api/emails/get?${params.toString()}`, {
|
|
19172
19410
|
headers: { "x-taskmarket-api-token": keystore.apiToken }
|
|
19173
19411
|
});
|
|
19412
|
+
if (!opts.allowUnverifiedSender && replyNeedsVerifiedSender(original)) {
|
|
19413
|
+
return void renderFailure(
|
|
19414
|
+
new Error(
|
|
19415
|
+
`The sender of this email is not verified (senderVerification: ${original.senderVerification ?? "missing"}) and its From address is outside Taskmarket, so it may be forged and a reply would pay to mail a third party. Nothing was sent. Pass --allow-unverified-sender to reply anyway.`
|
|
19416
|
+
),
|
|
19417
|
+
{ details: { code: "unverified_sender" } }
|
|
19418
|
+
);
|
|
19419
|
+
}
|
|
19174
19420
|
const to = original.fromAddress;
|
|
19175
19421
|
const rawSubject = original.subject ?? "";
|
|
19176
19422
|
const subject = (rawSubject.startsWith("Re: ") ? rawSubject : `Re: ${rawSubject}`).slice(
|
|
@@ -20321,10 +20567,10 @@ var x402PaymentsCommand = new Command108("payments").description(
|
|
|
20321
20567
|
);
|
|
20322
20568
|
x402PaymentsCommand.command("list").description("List current payment records").addOption(new Option5("--state <state>", "Filter by state").choices(PAYMENT_STATES)).action(async (options) => {
|
|
20323
20569
|
const payments = await listX402Payments({ state: options.state }, getX402JournalPath());
|
|
20324
|
-
printResult({ payments });
|
|
20570
|
+
printResult({ payments: payments.map(withPaymentProtocol) });
|
|
20325
20571
|
});
|
|
20326
20572
|
x402PaymentsCommand.command("get").description("Get one payment record").argument("<paymentId>", "Payment id").action(
|
|
20327
|
-
async (paymentId) => printResult(await getX402Payment(paymentId, getX402JournalPath()))
|
|
20573
|
+
async (paymentId) => printResult(withPaymentProtocol(await getX402Payment(paymentId, getX402JournalPath())))
|
|
20328
20574
|
);
|
|
20329
20575
|
x402PaymentsCommand.command("reconcile").description("Reconcile a payment authorization against the configured chain").argument("<paymentId>", "Payment id").action(async (paymentId) => printResult(await reconcileX402PaymentById(paymentId)));
|
|
20330
20576
|
x402PaymentsCommand.command("resolve").description("Manually record an externally verified final amount").argument("<paymentId>", "Payment id").requiredOption("--settled-amount <atomicUnits>", "Final settled amount in atomic units").requiredOption("--note <text>", "Audit note describing the evidence").option("--transaction <hash>", "Settlement transaction hash").action(
|
|
@@ -20339,7 +20585,7 @@ x402PaymentsCommand.command("resolve").description("Manually record an externall
|
|
|
20339
20585
|
},
|
|
20340
20586
|
getX402JournalPath()
|
|
20341
20587
|
);
|
|
20342
|
-
printResult(payment);
|
|
20588
|
+
printResult(withPaymentProtocol(payment));
|
|
20343
20589
|
}
|
|
20344
20590
|
);
|
|
20345
20591
|
|
|
@@ -20414,7 +20660,41 @@ function collect4(value, previous) {
|
|
|
20414
20660
|
function confirm(lines) {
|
|
20415
20661
|
return confirmAtTerminal(lines, "use --non-interactive with policy");
|
|
20416
20662
|
}
|
|
20417
|
-
|
|
20663
|
+
function amountLines(terms, charge) {
|
|
20664
|
+
if (!charge) {
|
|
20665
|
+
return [
|
|
20666
|
+
`${terms.scheme === "upto" ? "Maximum authorization" : "Exact charge"}: ${terms.authorizedAmount} atomic units`
|
|
20667
|
+
];
|
|
20668
|
+
}
|
|
20669
|
+
const recipient = terms.chargeAmount ?? terms.authorizedAmount;
|
|
20670
|
+
const sponsored = terms.feeSponsored === true;
|
|
20671
|
+
return [
|
|
20672
|
+
`Recipient receives: ${recipient} atomic units`,
|
|
20673
|
+
sponsored ? "Network fee: paid by the seller" : `Network fee: paid by your wallet, worst case ${terms.maxFee ?? "unknown"} atomic units of the token`,
|
|
20674
|
+
`Maximum authorized in total: ${terms.authorizedAmount} atomic units`
|
|
20675
|
+
];
|
|
20676
|
+
}
|
|
20677
|
+
function paymentConfirmationLines(terms) {
|
|
20678
|
+
const protocol = x402PaymentProtocol(terms);
|
|
20679
|
+
const charge = protocol === "mpp";
|
|
20680
|
+
return [
|
|
20681
|
+
charge ? "External MPP payment" : "External x402 payment",
|
|
20682
|
+
`Resource: ${terms.method} ${terms.origin}${terms.pathname}`,
|
|
20683
|
+
`Protocol: ${protocol}`,
|
|
20684
|
+
`Scheme: ${terms.scheme}`,
|
|
20685
|
+
`Network: ${terms.network}`,
|
|
20686
|
+
`Token: ${terms.asset}`,
|
|
20687
|
+
`Recipient: ${terms.payTo}`,
|
|
20688
|
+
...amountLines(terms, charge),
|
|
20689
|
+
`Policy: ${terms.policyRuleId ?? "one-time interactive exception"}`
|
|
20690
|
+
];
|
|
20691
|
+
}
|
|
20692
|
+
var x402RequestCommand = new Command110("request").description("Request and pay for a direct x402 HTTP resource (X402 Pay)").argument("<url>", "HTTPS resource URL").addOption(new Option6("--method <method>", "HTTP method").choices(["GET", "POST"]).default("GET")).addOption(
|
|
20693
|
+
new Option6(
|
|
20694
|
+
"--protocol <protocol>",
|
|
20695
|
+
"Payment protocol the 402 may be paid through: auto reads x402 and MPP, x402 or mpp restricts it"
|
|
20696
|
+
).choices([...X402_PAY_PROTOCOLS]).default("auto")
|
|
20697
|
+
).option("--json <json>", "Inline JSON POST body").option("--body-file <path>", "Read JSON POST body from a file").option("--headers-file <path>", "Read request headers from an owner-only JSON file").option(
|
|
20418
20698
|
"--header-env <header=ENV_VAR>",
|
|
20419
20699
|
"Read one request header from an environment variable (repeatable)",
|
|
20420
20700
|
collect4,
|
|
@@ -20431,6 +20711,7 @@ var x402RequestCommand = new Command110("request").description("Request and pay
|
|
|
20431
20711
|
const result = await executeX402PayRequest({
|
|
20432
20712
|
rawUrl: url,
|
|
20433
20713
|
method: options.method,
|
|
20714
|
+
protocol: options.protocol,
|
|
20434
20715
|
json: options.json,
|
|
20435
20716
|
bodyFile: options.bodyFile,
|
|
20436
20717
|
headers,
|
|
@@ -20438,16 +20719,7 @@ var x402RequestCommand = new Command110("request").description("Request and pay
|
|
|
20438
20719
|
nonInteractive: options.nonInteractive,
|
|
20439
20720
|
policyRuleId: options.policy,
|
|
20440
20721
|
invocationId: options.invocationId,
|
|
20441
|
-
confirmPayment: (terms) => confirm(
|
|
20442
|
-
"External x402 payment",
|
|
20443
|
-
`Resource: ${terms.method} ${terms.origin}${terms.pathname}`,
|
|
20444
|
-
`Scheme: ${terms.scheme}`,
|
|
20445
|
-
`Network: ${terms.network}`,
|
|
20446
|
-
`Asset: ${terms.asset}`,
|
|
20447
|
-
`Recipient: ${terms.payTo}`,
|
|
20448
|
-
`${terms.scheme === "upto" ? "Maximum authorization" : "Exact charge"}: ${terms.authorizedAmount} atomic units`,
|
|
20449
|
-
`Policy: ${terms.policyRuleId ?? "one-time interactive exception"}`
|
|
20450
|
-
]),
|
|
20722
|
+
confirmPayment: (terms) => confirm(paymentConfirmationLines(terms)),
|
|
20451
20723
|
confirmDirectApproval: (details) => confirm([
|
|
20452
20724
|
"Permit2 token approval",
|
|
20453
20725
|
`Network: ${details.network}`,
|
|
@@ -29036,7 +29308,7 @@ function prepareListingFile(kind, text) {
|
|
|
29036
29308
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
29037
29309
|
return { valid: false, reason: "The file must hold one JSON object" };
|
|
29038
29310
|
}
|
|
29039
|
-
const hidden = findHiddenCharacters(kind === "
|
|
29311
|
+
const hidden = findHiddenCharacters(parsed) ?? (kind === "hook" ? findHiddenCharacters(text) : null);
|
|
29040
29312
|
if (hidden) {
|
|
29041
29313
|
return {
|
|
29042
29314
|
valid: false,
|
|
@@ -29635,7 +29907,13 @@ async function lookupListedService(worker, serviceId) {
|
|
|
29635
29907
|
if (err instanceof ApiError && err.status === 404) return { service: null };
|
|
29636
29908
|
throw err;
|
|
29637
29909
|
}
|
|
29638
|
-
if (listing?.hidden)
|
|
29910
|
+
if (listing?.hidden) {
|
|
29911
|
+
return {
|
|
29912
|
+
service: null,
|
|
29913
|
+
error: `${HIRE_LISTING_HIDDEN}: ${hireListingHiddenMessage()}`,
|
|
29914
|
+
code: HIRE_LISTING_HIDDEN
|
|
29915
|
+
};
|
|
29916
|
+
}
|
|
29639
29917
|
if (!serviceId) return { service: null };
|
|
29640
29918
|
const service = listing?.services?.find((s2) => s2.id === serviceId);
|
|
29641
29919
|
if (!service || service.hidden) {
|
|
@@ -29674,7 +29952,12 @@ hireCommand.action(async (worker, opts) => {
|
|
|
29674
29952
|
let serviceTitle = null;
|
|
29675
29953
|
if (/^0x[0-9a-fA-F]{40}$/.test(worker)) {
|
|
29676
29954
|
const lookup = await lookupListedService(worker, opts.service);
|
|
29677
|
-
if (lookup.error)
|
|
29955
|
+
if (lookup.error) {
|
|
29956
|
+
if (lookup.code) {
|
|
29957
|
+
return void renderFailure(new Error(lookup.error), { details: { code: lookup.code } });
|
|
29958
|
+
}
|
|
29959
|
+
return void printError(lookup.error);
|
|
29960
|
+
}
|
|
29678
29961
|
if (opts.service) {
|
|
29679
29962
|
if (lookup.service) {
|
|
29680
29963
|
requiresEvaluator ||= Boolean(lookup.service.requiresEvaluator);
|