@lucid-agents/taskmarket 1.19.0 → 1.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,73 @@
1
1
  import { createRequire as __tmCreateRequire } from 'node:module'; import { fileURLToPath as __tmFileURLToPath } from 'node:url'; import { dirname as __tmDirname } from 'node:path'; const require = __tmCreateRequire(import.meta.url); const __tmFilename = __tmFileURLToPath(import.meta.url); const __tmDirnameValue = __tmDirname(__tmFilename);
2
2
 
3
+ // src/lib/agent/failure-detail.ts
4
+ var MAX_FAILURE_REASON_CHARS = 160;
5
+ var MAX_REASON_BODY_BYTES = 64 * 1024;
6
+ var REDACTIONS = [
7
+ [/\b[a-z][a-z0-9+.-]*:\/\/\S+/gi, "[url]"],
8
+ [/\b(bearer|basic)\s+\S+/gi, "$1 [redacted]"],
9
+ [
10
+ /\b(authorization|cookie|token|secret|password|passphrase|signature|private[-_ ]?key|api[-_ ]?key)\b(\s*[:=]\s*)\S+/gi,
11
+ "$1$2[redacted]"
12
+ ],
13
+ [/\b0x[0-9a-f]{16,}\b/gi, "[hex]"],
14
+ [/\b[\w.+-]+@[\w-]+(\.[\w-]+)+\b/g, "[email]"],
15
+ [/[A-Za-z0-9+/_=-]{32,}/g, "[redacted]"]
16
+ ];
17
+ function sanitizeFailureReason(text) {
18
+ if (typeof text !== "string") return void 0;
19
+ const line = text.slice(0, 16 * MAX_FAILURE_REASON_CHARS).split(/[\r\n]+/).find((part) => part.trim());
20
+ if (!line) return void 0;
21
+ let reason = line.replace(/[\u0000-\u001f\u007f-\u009f\u200b-\u200f\u2028-\u202e\u2066-\u2069]/g, " ").replace(/\s+/g, " ").trim();
22
+ for (const [pattern, replacement] of REDACTIONS) reason = reason.replace(pattern, replacement);
23
+ if (!reason) return void 0;
24
+ return reason.length > MAX_FAILURE_REASON_CHARS ? `${reason.slice(0, MAX_FAILURE_REASON_CHARS - 3).trimEnd()}...` : reason;
25
+ }
26
+ function failureDetail(value) {
27
+ if (!value || typeof value !== "object") return void 0;
28
+ const { status, reason } = value;
29
+ const detail = {
30
+ ...Number.isInteger(status) && status >= 100 && status <= 599 ? { status } : {}
31
+ };
32
+ const text = sanitizeFailureReason(reason);
33
+ if (text) detail.reason = text;
34
+ return detail.status === void 0 && detail.reason === void 0 ? void 0 : detail;
35
+ }
36
+ function describeFailureDetail(detail) {
37
+ const status = detail.status !== void 0 ? `HTTP ${detail.status}` : "";
38
+ return status && detail.reason ? `${status}: ${detail.reason}` : status || detail.reason || "";
39
+ }
40
+ function responseFailureReason(response) {
41
+ const body = response?.body;
42
+ if (!(body instanceof Uint8Array) || body.byteLength > MAX_REASON_BODY_BYTES) return void 0;
43
+ let value;
44
+ try {
45
+ value = JSON.parse(new TextDecoder().decode(body));
46
+ } catch {
47
+ return void 0;
48
+ }
49
+ const record = value ?? {};
50
+ const error = record.error;
51
+ for (const candidate of [
52
+ typeof error === "string" ? error : error?.message,
53
+ record.message,
54
+ record.detail
55
+ ]) {
56
+ const reason = sanitizeFailureReason(candidate);
57
+ if (reason) return reason;
58
+ }
59
+ return void 0;
60
+ }
61
+ function failureDetailOf(error) {
62
+ return error && typeof error === "object" ? failureDetail(error.detail) : void 0;
63
+ }
64
+ function withFailureDetail(error, detail) {
65
+ if (detail && error && typeof error === "object") {
66
+ error.detail = detail;
67
+ }
68
+ return error;
69
+ }
70
+
3
71
  // src/lib/agent/budget-view.ts
4
72
  var AGENT_VIEW_VERSION = 1;
5
73
  var USDC_DECIMALS = 6;
@@ -154,24 +222,38 @@ var CHARGED_UNDELIVERED = /* @__PURE__ */ new Set([
154
222
  "invalid_response",
155
223
  "response_hook_failed"
156
224
  ]);
225
+ var REQUEST_FAILED = /* @__PURE__ */ new Set(["request_failed", "request_rejected"]);
157
226
  function purchaseFailureNotice(failure) {
227
+ const detail = failureDetail(failure.detail);
228
+ const cause = detail ? `${failure.code}, ${describeFailureDetail(detail)}` : failure.code;
158
229
  if (failure.pending) {
159
230
  return {
160
231
  level: "warning",
161
- text: uncertainPurchaseMessage(failure.invocationId || "(unknown)")
232
+ text: `${uncertainPurchaseMessage(failure.invocationId || "(unknown)")}${detail ? ` Cause: ${describeFailureDetail(detail)}.` : ""}`
162
233
  };
163
234
  }
164
235
  const charged = failure.payment?.chargedAtomic;
165
236
  if (charged !== void 0 || CHARGED_UNDELIVERED.has(failure.code)) {
166
237
  return {
167
238
  level: "error",
168
- text: `This turn was paid${charged !== void 0 ? ` (${formatUsdc(charged)})` : ""} but its response was lost (${failure.code}). ${LOST_RESPONSE_TEXT}`
239
+ text: `This turn was paid${charged !== void 0 ? ` (${formatUsdc(charged)})` : ""} but its response was lost (${cause}). ${LOST_RESPONSE_TEXT}`
240
+ };
241
+ }
242
+ if (REQUEST_FAILED.has(failure.code)) {
243
+ return {
244
+ level: "error",
245
+ text: `This turn's request to xgate failed (${cause}). It is not retried automatically; send the prompt again to start a new turn.`
169
246
  };
170
247
  }
171
248
  return void 0;
172
249
  }
173
250
 
174
251
  export {
252
+ failureDetail,
253
+ describeFailureDetail,
254
+ responseFailureReason,
255
+ failureDetailOf,
256
+ withFailureDetail,
175
257
  AGENT_VIEW_VERSION,
176
258
  formatUsdc,
177
259
  formatCredits,
@@ -6,7 +6,7 @@ import {
6
6
  findInstalledPackage,
7
7
  nodeVersionSupported,
8
8
  piRuntime
9
- } from "./chunk-OKZ2NRYZ.js";
9
+ } from "./chunk-4ZC6SH7H.js";
10
10
  import "./chunk-YM4S6IE4.js";
11
11
  import "./chunk-S7SJMJ2I.js";
12
12
  export {
@@ -3,31 +3,31 @@ import {
3
3
  AGENT_COMPATIBILITY,
4
4
  assertAgentCompatibility,
5
5
  nodeVersionSupported
6
- } from "./chunk-OKZ2NRYZ.js";
6
+ } from "./chunk-4ZC6SH7H.js";
7
7
  import {
8
8
  listSandboxes
9
- } from "./chunk-U5F3Z2BR.js";
10
- import "./chunk-RKGRXJ5X.js";
11
- import "./chunk-MJR2CZWZ.js";
12
- import "./chunk-6KJ5EFBN.js";
9
+ } from "./chunk-IWZNOYQE.js";
10
+ import "./chunk-OTXEK6VM.js";
11
+ import "./chunk-ATHBKQT4.js";
12
+ import "./chunk-M7WD6A2T.js";
13
13
  import {
14
14
  channelView,
15
15
  loadAgentPolicy,
16
16
  openAgentChannels
17
- } from "./chunk-7Y7IOFKT.js";
17
+ } from "./chunk-MZSOLQZB.js";
18
18
  import {
19
19
  getX402PolicyPath,
20
20
  loadX402Policy,
21
21
  rpcUrlForNetwork
22
- } from "./chunk-VMSV4EYS.js";
22
+ } from "./chunk-NRKTRQEA.js";
23
23
  import {
24
24
  apiUrl,
25
25
  keystoreExists,
26
26
  loadKeystore
27
- } from "./chunk-PGXPZFVY.js";
27
+ } from "./chunk-X7AUWPZV.js";
28
28
  import {
29
29
  AGENT_VIEW_VERSION
30
- } from "./chunk-EB6OJBF5.js";
30
+ } from "./chunk-XJOB4NMV.js";
31
31
  import "./chunk-YM4S6IE4.js";
32
32
  import "./chunk-S7SJMJ2I.js";
33
33
 
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  signReadAuth,
15
15
  submitTaskFiles,
16
16
  taskAccessGrantHeaders
17
- } from "./chunk-F2SZG7TC.js";
17
+ } from "./chunk-ICT56PNO.js";
18
18
  import {
19
19
  ComputeCreditError,
20
20
  applyComputeCreditSetup,
@@ -36,7 +36,7 @@ import {
36
36
  refusedPaidWrite,
37
37
  releasePendingComputePurchase,
38
38
  resolvePendingComputePurchases
39
- } from "./chunk-6KJ5EFBN.js";
39
+ } from "./chunk-M7WD6A2T.js";
40
40
  import {
41
41
  MPP_TEMPO_DEFAULT_VALIDITY_SECONDS,
42
42
  X402PayError,
@@ -58,7 +58,7 @@ import {
58
58
  signSponsoredTempoTransfer,
59
59
  signTaskmarketFeePayment,
60
60
  signTypedData
61
- } from "./chunk-VMSV4EYS.js";
61
+ } from "./chunk-NRKTRQEA.js";
62
62
  import {
63
63
  AgentMessageEnvelopeSchema,
64
64
  ApiError,
@@ -161,10 +161,10 @@ import {
161
161
  usdcToBaseUnits,
162
162
  withErrorContext,
163
163
  withIdempotentWrite
164
- } from "./chunk-PGXPZFVY.js";
164
+ } from "./chunk-X7AUWPZV.js";
165
165
  import {
166
166
  channelLines
167
- } from "./chunk-EB6OJBF5.js";
167
+ } from "./chunk-XJOB4NMV.js";
168
168
  import "./chunk-S7SJMJ2I.js";
169
169
 
170
170
  // src/index.ts
@@ -815,14 +815,16 @@ identityCommand.command("feedback").description(
815
815
  // src/commands/whoami.ts
816
816
  import { Command as Command5 } from "commander";
817
817
  var NOT_LINKED_YET = "not linked yet (links on your next accept or cancel)";
818
- var LINK_UNAVAILABLE = "unavailable (this chain does not report requester links yet)";
818
+ var LINK_READ_FAILED_REASON = "Requester links could not be read from the chain right now (RPC error); try again";
819
819
  function siblingNetworks(selected) {
820
820
  return NETWORK_NAMES.map((name) => NETWORKS[name]).filter(
821
821
  (network) => network.available && network.apiUrl === selected.apiUrl
822
822
  );
823
823
  }
824
824
  function describeReputationLink(link) {
825
- if (!link || !link.linkAvailable) return LINK_UNAVAILABLE;
825
+ if (!link) return `unavailable: ${LINK_READ_FAILED_REASON}`;
826
+ if (!link.linkAvailable)
827
+ return `unavailable: ${link.linkUnavailableReason ?? LINK_READ_FAILED_REASON}`;
826
828
  return link.linkedAgentId ? `linked to agent #${link.linkedAgentId}` : NOT_LINKED_YET;
827
829
  }
828
830
  var whoamiCommand = new Command5("whoami").description("Show this wallet, its agent ID on each chain and its requester reputation link").action(async () => {
@@ -3432,9 +3434,9 @@ async function runAgentCommand(options) {
3432
3434
  const { AgentLaunchError } = await import("./errors-2L357HGA.js");
3433
3435
  let result;
3434
3436
  try {
3435
- const { assertAgentCompatibility } = await import("./compatibility-KUYGZSUC.js");
3437
+ const { assertAgentCompatibility } = await import("./compatibility-636WJOEX.js");
3436
3438
  const pi = assertAgentCompatibility();
3437
- const { runAgent } = await import("./launch-I3NCB5FV.js");
3439
+ const { runAgent } = await import("./launch-ZSZURLR6.js");
3438
3440
  result = await runAgent({
3439
3441
  model: options.model,
3440
3442
  pi,
@@ -3493,13 +3495,13 @@ function agentManagementCommands() {
3493
3495
  const status = new Command48("status").description(
3494
3496
  "Show the agent channels (locked, charged, refundable), purchases with an unknown outcome, the sandbox and compute credit. Reads only."
3495
3497
  ).option("--json", "Print the versioned JSON envelope").action(async (options) => {
3496
- const { collectAgentStatus, statusLines } = await import("./status-GNY7YXPE.js");
3498
+ const { collectAgentStatus, statusLines } = await import("./status-BXL2F4LY.js");
3497
3499
  await run(options, () => collectAgentStatus(), statusLines);
3498
3500
  });
3499
3501
  const doctor = new Command48("doctor").description(
3500
3502
  "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."
3501
3503
  ).option("--json", "Print the versioned JSON envelope").action(async (options) => {
3502
- const { runDoctor, doctorLines } = await import("./doctor-LDSADHSQ.js");
3504
+ const { runDoctor, doctorLines } = await import("./doctor-MBM7WQHI.js");
3503
3505
  const report = await run(options, () => runDoctor(), doctorLines);
3504
3506
  if (report && !report.ok) process.exitCode = 1;
3505
3507
  });
@@ -3510,7 +3512,7 @@ function agentManagementCommands() {
3510
3512
  "Reconcile the open purchases of this channel, as status lists it; also reaches retired channels"
3511
3513
  ).option("--json", "Print the versioned JSON envelope").action(
3512
3514
  async (invocationId, options) => {
3513
- const { reconcileChannelPurchases, reconcileInvocation } = await import("./reconcile-UHDI4QCY.js");
3515
+ const { reconcileChannelPurchases, reconcileInvocation } = await import("./reconcile-4HIIA426.js");
3514
3516
  const choice = { rail: options.rail, channel: options.channel };
3515
3517
  if (invocationId !== void 0) {
3516
3518
  await run(
@@ -3559,7 +3561,7 @@ function agentManagementCommands() {
3559
3561
  options,
3560
3562
  async () => {
3561
3563
  await requireExperimental();
3562
- const { usdcToAtomic, AGENT_VIEW_VERSION } = await import("./budget-view-JPZ7HWR2.js");
3564
+ const { usdcToAtomic, AGENT_VIEW_VERSION } = await import("./budget-view-J6L7X6EY.js");
3563
3565
  const { AgentLaunchError } = await import("./errors-2L357HGA.js");
3564
3566
  const amount = usdcToAtomic(options.amount);
3565
3567
  if (amount === void 0 || amount === "0") {
@@ -3568,7 +3570,7 @@ function agentManagementCommands() {
3568
3570
  `Not a USDC amount: ${options.amount} (digits, at most 6 decimals)`
3569
3571
  );
3570
3572
  }
3571
- const { openAgentChannels, requestTopUp, selectRail, withdrawalHatch } = await import("./channels-ZMYXFZ72.js");
3573
+ const { openAgentChannels, requestTopUp, selectRail, withdrawalHatch } = await import("./channels-7DEGKHO5.js");
3572
3574
  const { rails } = await openAgentChannels();
3573
3575
  const result = await requestTopUp(selectRail(rails, options.rail), amount);
3574
3576
  return {
@@ -3591,9 +3593,9 @@ function agentManagementCommands() {
3591
3593
  options,
3592
3594
  async () => {
3593
3595
  await requireExperimental();
3594
- const { AGENT_VIEW_VERSION } = await import("./budget-view-JPZ7HWR2.js");
3595
- const { closeChannel, openAgentChannels, selectChannel } = await import("./channels-ZMYXFZ72.js");
3596
- const { reconcileLeasedPurchase } = await import("./reconcile-UHDI4QCY.js");
3596
+ const { AGENT_VIEW_VERSION } = await import("./budget-view-J6L7X6EY.js");
3597
+ const { closeChannel, openAgentChannels, selectChannel } = await import("./channels-7DEGKHO5.js");
3598
+ const { reconcileLeasedPurchase } = await import("./reconcile-4HIIA426.js");
3597
3599
  const opened = await openAgentChannels();
3598
3600
  const { rail, retired } = selectChannel(opened, options);
3599
3601
  const result = await closeChannel(
@@ -3664,7 +3666,7 @@ function agentManagementCommands() {
3664
3666
  options,
3665
3667
  async () => {
3666
3668
  await requireExperimental();
3667
- const { runPull } = await import("./sync-pull-6PWR6CJS.js");
3669
+ const { runPull } = await import("./sync-pull-HL2YS3EL.js");
3668
3670
  const { terminalPrompter } = await import("./prompter-LSICEYSQ.js");
3669
3671
  return runPull(options, {
3670
3672
  interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY) && !options.json,