@xiashe/sdk 0.1.13 → 0.1.15

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/alipayWallet.mjs CHANGED
@@ -8,7 +8,7 @@ const DEFAULT_TIMEOUT_MS = 8 * 60 * 1000;
8
8
  const RESOURCE_FETCH_TIMEOUT_MS = 20 * 1000;
9
9
  const MAX_OUTPUT_BYTES = 32 * 1024;
10
10
  const SENSITIVE_OUTPUT = /payment[-_ ]?proof|payment[-_ ]?needed|seller_signature|runtimeToken|authorization\s*:/i;
11
- const SENSITIVE_USER_OUTPUT = /payment[-_ ]?proof|payment[-_ ]?needed|seller_signature|runtimeToken|authorization\s*:|trade[_ -]?no|交易(?:流水)?号|out[_ -]?shake|client[_ -]?session/i;
11
+ const SENSITIVE_USER_OUTPUT = /payment[-_ ]?proof|payment[-_ ]?needed|seller_signature|runtimeToken|authorization\s*:|trade[_ -]?no|交易(?:流水)?号|out[_ -]?shake|client[_ -]?session|payguard|validateclientparent|agentfamily/i;
12
12
  const DEFAULT_STATE_DIR = path.join(os.homedir(), '.xiashe', 'alipay-402');
13
13
 
14
14
  export class AlipayWalletError extends Error {
@@ -196,10 +196,12 @@ function userVisibleWalletOutput(stdout, stderr) {
196
196
 
197
197
  function walletFailureCode(stdout, stderr, exitCode) {
198
198
  const output = `${stdout}\n${stderr}`;
199
+ if (/TRADE_PROGRESS_FAILED/i.test(output)) return 'wallet_trade_progress_failed';
199
200
  if (/余额不足|insufficient\s+balance/i.test(output)) return 'insufficient_balance';
200
201
  if (/已过期|过期|expired/i.test(output)) return 'payment_expired';
201
202
  if (/钱包.*(?:未开启|未授权)|wallet.*(?:not\s+enabled|not\s+authorized)/i.test(output)) return 'wallet_not_ready';
202
203
  if (/买家.*(?:不匹配|校验失败)|buyer.*(?:mismatch|identity)/i.test(output)) return 'buyer_identity_rejected';
204
+ if (/payguard|validateclientparent|agentfamily=unknown|agent\s*family.*unknown/i.test(output)) return 'wallet_runtime_not_supported';
203
205
  if (/账单.*(?:无效|签名)|签名.*(?:无效|失败)|bill.*(?:invalid|signature)/i.test(output)) return 'payment_needed_rejected';
204
206
  if (/network|网络|timeout|超时/i.test(output)) return 'wallet_network_error';
205
207
  return Number.isInteger(exitCode) && exitCode !== 0 ? 'official_cli_nonzero_exit' : 'official_cli_unclassified';
@@ -212,6 +214,16 @@ function paymentMessage(status) {
212
214
  return '支付宝官方钱包已被调用,但尚未返回可确认的付款状态;请运行 status 查询,或重新发起付款。';
213
215
  }
214
216
 
217
+ function paymentFailureMessage(failureCode) {
218
+ if (failureCode === 'wallet_trade_progress_failed') {
219
+ return '支付宝钱包未能创建可确认的交易;未授予付费 Skill 权益。请在重新加载后的受支持 Agent 环境中重试。';
220
+ }
221
+ if (failureCode === 'wallet_runtime_not_supported') {
222
+ return '当前 Agent 运行环境不支持支付宝 AI付;未授予付费 Skill 权益。';
223
+ }
224
+ return '支付宝官方钱包没有生成可确认的付款状态;未授予付费 Skill 权益。';
225
+ }
226
+
215
227
  async function fetchPaymentNeeded(resourceUrl, options = {}) {
216
228
  const fetchFn = options.fetch || globalThis.fetch;
217
229
  const controller = new AbortController();
@@ -245,18 +257,18 @@ async function fetchPaymentNeeded(resourceUrl, options = {}) {
245
257
 
246
258
  function publicPaymentResult(state, status, diagnostic, options = {}) {
247
259
  const commandFailed = options.commandFailed === true;
260
+ const failureCode = options.failureCode || 'official_cli_nonzero_exit';
261
+ const failed = status === 'failed' || status === 'wallet_command_failed';
248
262
  return {
249
- ok: status !== 'failed' && status !== 'wallet_command_failed',
263
+ ok: !failed,
250
264
  status,
251
265
  provider: 'alipay-agent-payment',
252
266
  attemptId: `alipay-402:${state.resourceDigest.slice(0, 16)}`,
253
267
  walletInvoked: true,
254
- message: status === 'wallet_command_failed'
255
- ? '支付宝官方钱包没有生成可确认的付款状态;未授予付费 Skill 权益。'
256
- : paymentMessage(status),
268
+ message: failed ? paymentFailureMessage(failureCode) : paymentMessage(status),
257
269
  diagnostic,
258
270
  ...(options.userVisible ? { userVisible: options.userVisible } : {}),
259
- ...(commandFailed ? { failureCode: options.failureCode || 'official_cli_nonzero_exit' } : {})
271
+ ...(commandFailed ? { failureCode } : {})
260
272
  };
261
273
  }
262
274
 
@@ -342,10 +354,11 @@ export async function payAlipay402Resource(input, options = {}) {
342
354
  state.updatedAt = new Date().toISOString();
343
355
  await writePaymentState(state, options);
344
356
  if (status === 'completed') await rm(paths.paymentNeededPath, { force: true });
357
+ const failed = commandFailed || status === 'failed';
345
358
  return publicPaymentResult(state, status, result.diagnostic, {
346
- commandFailed,
347
- failureCode: commandFailed ? walletFailureCode(walletInvocation.stdout, walletInvocation.stderr, walletInvocation.exitCode) : undefined,
348
- userVisible: ['pending_confirmation', 'completed', 'failed'].includes(status)
359
+ commandFailed: failed,
360
+ failureCode: failed ? walletFailureCode(walletInvocation.stdout, walletInvocation.stderr, walletInvocation.exitCode) : undefined,
361
+ userVisible: ['pending_confirmation', 'completed'].includes(status)
349
362
  ? userVisibleWalletOutput(walletInvocation.stdout, walletInvocation.stderr)
350
363
  : null
351
364
  });
@@ -384,10 +397,11 @@ export async function queryAlipay402Resource(input, options = {}) {
384
397
  const { paymentNeededPath } = statePaths(resourceUrl, options);
385
398
  await rm(paymentNeededPath, { force: true });
386
399
  }
400
+ const failed = commandFailed || status === 'failed';
387
401
  return publicPaymentResult(state, status, result.diagnostic, {
388
- commandFailed,
389
- failureCode: commandFailed ? walletFailureCode(walletInvocation.stdout, walletInvocation.stderr, walletInvocation.exitCode) : undefined,
390
- userVisible: ['pending_confirmation', 'completed', 'failed'].includes(status)
402
+ commandFailed: failed,
403
+ failureCode: failed ? walletFailureCode(walletInvocation.stdout, walletInvocation.stderr, walletInvocation.exitCode) : undefined,
404
+ userVisible: ['pending_confirmation', 'completed'].includes(status)
391
405
  ? userVisibleWalletOutput(walletInvocation.stdout, walletInvocation.stderr)
392
406
  : null
393
407
  });
package/index.mjs CHANGED
@@ -6,7 +6,7 @@ import path from 'node:path';
6
6
  import { ConvexHttpClient } from 'convex/browser';
7
7
  import { anyApi as api } from 'convex/server';
8
8
 
9
- export const VERSION = '0.1.13';
9
+ export const VERSION = '0.1.15';
10
10
 
11
11
  export const DEFAULTS = {
12
12
  cn: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiashe/sdk",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "type": "module",
5
5
  "main": "index.mjs",
6
6
  "exports": {