@acedatacloud/sdk 2026.718.0 → 2026.722.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/index.d.mts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * When the API returns `402 Payment Required`, the transport calls the
5
5
  * configured `PaymentHandler` to produce the extra headers (typically
6
- * `X-Payment`) to attach to the retry. This keeps the SDK free of any
6
+ * `PAYMENT-SIGNATURE`) to attach to the retry. This keeps the SDK free of any
7
7
  * chain-specific signing logic, and lets callers plug in a real x402
8
8
  * implementation such as `@acedatacloud/x402-client`.
9
9
  */
@@ -11,7 +11,9 @@
11
11
  interface PaymentRequirement {
12
12
  scheme: string;
13
13
  network: string;
14
- maxAmountRequired: string;
14
+ amount?: string;
15
+ /** @deprecated Legacy challenge field. */
16
+ maxAmountRequired?: string;
15
17
  maxTimeoutSeconds?: number;
16
18
  resource?: string;
17
19
  description?: string;
@@ -34,7 +36,7 @@ interface PaymentHandlerContext {
34
36
  }
35
37
  /** Result a payment handler must return. */
36
38
  interface PaymentHandlerResult {
37
- /** Extra headers to attach to the retry (must include `X-Payment`). */
39
+ /** Extra headers to attach to the retry (normally `PAYMENT-SIGNATURE`). */
38
40
  headers: Record<string, string>;
39
41
  }
40
42
  /** A callable that signs/settles a payment and returns retry headers. */
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * When the API returns `402 Payment Required`, the transport calls the
5
5
  * configured `PaymentHandler` to produce the extra headers (typically
6
- * `X-Payment`) to attach to the retry. This keeps the SDK free of any
6
+ * `PAYMENT-SIGNATURE`) to attach to the retry. This keeps the SDK free of any
7
7
  * chain-specific signing logic, and lets callers plug in a real x402
8
8
  * implementation such as `@acedatacloud/x402-client`.
9
9
  */
@@ -11,7 +11,9 @@
11
11
  interface PaymentRequirement {
12
12
  scheme: string;
13
13
  network: string;
14
- maxAmountRequired: string;
14
+ amount?: string;
15
+ /** @deprecated Legacy challenge field. */
16
+ maxAmountRequired?: string;
15
17
  maxTimeoutSeconds?: number;
16
18
  resource?: string;
17
19
  description?: string;
@@ -34,7 +36,7 @@ interface PaymentHandlerContext {
34
36
  }
35
37
  /** Result a payment handler must return. */
36
38
  interface PaymentHandlerResult {
37
- /** Extra headers to attach to the retry (must include `X-Payment`). */
39
+ /** Extra headers to attach to the retry (normally `PAYMENT-SIGNATURE`). */
38
40
  headers: Record<string, string>;
39
41
  }
40
42
  /** A callable that signs/settles a payment and returns retry headers. */
package/dist/index.js CHANGED
@@ -123,6 +123,23 @@ var TimeoutError = class extends APIError {
123
123
  };
124
124
 
125
125
  // src/runtime/transport.ts
126
+ function parsePaymentRequired(resp, text) {
127
+ const encoded = resp.headers.get("PAYMENT-REQUIRED");
128
+ if (encoded) {
129
+ try {
130
+ return JSON.parse(atob(encoded));
131
+ } catch {
132
+ throw mapError(402, {
133
+ error: { code: "invalid_402", message: "Invalid PAYMENT-REQUIRED header" }
134
+ });
135
+ }
136
+ }
137
+ try {
138
+ return JSON.parse(text);
139
+ } catch {
140
+ throw mapError(402, { error: { code: "invalid_402", message: text } });
141
+ }
142
+ }
126
143
  var ERROR_CODE_MAP = {
127
144
  invalid_token: AuthenticationError,
128
145
  token_expired: AuthenticationError,
@@ -231,12 +248,7 @@ var Transport = class {
231
248
  clearTimeout(timer);
232
249
  if (resp.status === 402 && this.paymentHandler && !paymentAttempted) {
233
250
  const text = await resp.text();
234
- let body;
235
- try {
236
- body = JSON.parse(text);
237
- } catch {
238
- throw mapError(402, { error: { code: "invalid_402", message: text } });
239
- }
251
+ const body = parsePaymentRequired(resp, text);
240
252
  if (!body || typeof body !== "object" || !Array.isArray(body.accepts) || !body.accepts.length || !body.accepts.every(
241
253
  (requirement) => requirement !== null && typeof requirement === "object"
242
254
  )) {
@@ -312,12 +324,7 @@ var Transport = class {
312
324
  }
313
325
  if (resp.status === 402 && this.paymentHandler && !paymentAttempted) {
314
326
  const text = await resp.text();
315
- let body;
316
- try {
317
- body = JSON.parse(text);
318
- } catch {
319
- throw mapError(402, { error: { code: "invalid_402", message: text } });
320
- }
327
+ const body = parsePaymentRequired(resp, text);
321
328
  if (!body || typeof body !== "object" || !Array.isArray(body.accepts) || !body.accepts.length || !body.accepts.every(
322
329
  (requirement) => requirement !== null && typeof requirement === "object"
323
330
  )) {
@@ -484,6 +491,16 @@ var Chat = class {
484
491
  };
485
492
 
486
493
  // src/runtime/tasks.ts
494
+ function taskStatus(state) {
495
+ const response = state.response ?? state;
496
+ if (response.status === "succeeded" || response.status === "failed") return response.status;
497
+ if (response.status !== void 0 && response.status !== null) return "";
498
+ const finished = response.finished_at !== void 0 && response.finished_at !== null || state.finished_at !== void 0 && state.finished_at !== null;
499
+ if (!finished) return "";
500
+ if (response.success === true) return "succeeded";
501
+ if (response.success === false) return "failed";
502
+ return "";
503
+ }
487
504
  var TaskHandle = class {
488
505
  id;
489
506
  pollEndpoint;
@@ -501,8 +518,7 @@ var TaskHandle = class {
501
518
  }
502
519
  async isCompleted() {
503
520
  const state = await this.get();
504
- const response = state.response ?? state;
505
- const status = response.status;
521
+ const status = taskStatus(state);
506
522
  return status === "succeeded" || status === "failed";
507
523
  }
508
524
  async wait(opts = {}) {
@@ -511,8 +527,7 @@ var TaskHandle = class {
511
527
  const start = Date.now();
512
528
  while (Date.now() - start < maxWait) {
513
529
  const state = await this.get();
514
- const response = state.response ?? state;
515
- const status = response.status;
530
+ const status = taskStatus(state);
516
531
  if (status === "succeeded" || status === "failed") {
517
532
  this._result = state;
518
533
  return state;