@lucid-agents/taskmarket 1.18.1 → 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-RHUDL5WA.js";
10
- import "./chunk-3FF6JAMK.js";
11
- import "./chunk-ONYTKAHC.js";
12
- import "./chunk-3LNZ766H.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-LEVAZYR5.js";
17
+ } from "./chunk-MZSOLQZB.js";
18
18
  import {
19
19
  getX402PolicyPath,
20
20
  loadX402Policy,
21
21
  rpcUrlForNetwork
22
- } from "./chunk-5VMWXDNO.js";
22
+ } from "./chunk-NRKTRQEA.js";
23
23
  import {
24
24
  apiUrl,
25
25
  keystoreExists,
26
26
  loadKeystore
27
- } from "./chunk-YB2B5DPR.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