@xiashe/cli 0.1.50 → 0.1.51

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/bin/xiashe.mjs CHANGED
@@ -1942,8 +1942,24 @@ async function main() {
1942
1942
  const client = new XiasheClient(loaded.profile, { profileName: loaded.profileName, timeoutMs: global.timeoutMs });
1943
1943
  const options = { origin: global.actionsUrl, profile: loaded.profile, guest: tail.includes('--guest'),
1944
1944
  hasSavedAccount: !!loaded.config.profiles[loaded.profileName]?.session?.userId,
1945
+ resolveAccountNumber: value => client.resolveSkillNumber(value, { account: true }),
1945
1946
  acquire: (value, requestToken) => client.acquireSkillNumber(value, requestToken) };
1946
- const result = await runAccountAwareUse(number, options);
1947
+ const use = async (settings) => {
1948
+ const result = await runAccountAwareUse(number, settings);
1949
+ if (result.stage !== 'runtime_active' || COMMAND_NAME !== 'xiashe') return result;
1950
+ // Inspect the existing capability without issuing claims, reserving payment or downloading.
1951
+ const checked = await syncNumber(number, { mode: 'check', origin: settings.origin, mcpCall, decode: decodeMcpToolResult });
1952
+ const steps = {
1953
+ deliver: '已可使用。沿同一会话获取完整包,无需付款。',
1954
+ recover_order: '已有订单需要核对。停在这里,询问是否查看原订单;不要发起结算或获取新的支付资料。',
1955
+ confirm_checkout: '当前身份尚未购买。询问用户是否查看报价,等用户选择后才继续结算。',
1956
+ unavailable: '作品暂不可用。停止获取和结算。'
1957
+ };
1958
+ const decision = checked.metadata.buyerNextStep;
1959
+ if (!Object.hasOwn(steps, decision)) throw Error('SKILL_ACCESS_STATUS_UNAVAILABLE');
1960
+ return { ...result, buyerNextStep: decision, next: steps[decision] };
1961
+ };
1962
+ const result = await use(options);
1947
1963
  if (!global.json && result.stage === 'purchase_choice') {
1948
1964
  const price = Number.isSafeInteger(result.priceCents) ? ` · ${result.currency} ${(result.priceCents / 100).toFixed(2)}` : '';
1949
1965
  const title = String(result.name || number).replace(/[\x00-\x1f\x7f-\x9f\u202a-\u202e\u2066-\u2069]/g, '');
@@ -1953,7 +1969,7 @@ async function main() {
1953
1969
  let choice;
1954
1970
  try { choice = (await prompt.question('请选择 1、2 或 3:')).trim(); }
1955
1971
  finally { prompt.close(); }
1956
- if (choice === '1') return print(await runAccountAwareUse(number, { ...options, guest: true }), global);
1972
+ if (choice === '1') return print(await use({ ...options, guest: true }), global);
1957
1973
  if (choice === '2') console.log(result.continueUrl);
1958
1974
  else if (choice !== '3') fail('请输入 1、2 或 3', EXIT_USAGE);
1959
1975
  } else {
@@ -15,7 +15,7 @@ export function expandUseNumber(argv, { brand = 'xiashe' } = {}) {
15
15
  return ['number', number, '--start', '--actions-url', origin, ...flags.filter(flag => flag !== '--staging')];
16
16
  }
17
17
 
18
- export async function runAccountAwareUse(number, { origin, profile, acquire, root, hasSavedAccount = false, guest = false, fetchImpl = fetch }) {
18
+ export async function runAccountAwareUse(number, { origin, profile, acquire, resolveAccountNumber, root, hasSavedAccount = false, guest = false, fetchImpl = fetch }) {
19
19
  const site = new Map([['https://actions.xiashe.chat','https://xiashe.chat'],['https://actions.projectphenix.site','https://projectphenix.site'],['https://agentpie.app','https://agentpie.app'],['https://staging.agentpie.app','https://staging.agentpie.app']]).get(origin);
20
20
  if (!site || !/^[1-9]\d{5,8}$/.test(number)) throw Error('NUMBER_ENVIRONMENT_INVALID');
21
21
  const continueUrl = `${site}/app/?number=${number}`;
@@ -61,7 +61,10 @@ export async function runAccountAwareUse(number, { origin, profile, acquire, roo
61
61
  if (currentOrigin !== origin) throw Error('NUMBER_ACCOUNT_ENVIRONMENT_MISMATCH');
62
62
  // The SDK additionally validates the exact backend/actions/market pair.
63
63
  // Never fall back to an anonymous purchase after any authenticated failure.
64
- const resolved = recovery.resolved ?? await resolveSkillNumber(number, { origin, fetchImpl });
64
+ const resolved = recovery.resolved ?? (resolveAccountNumber
65
+ ? await resolveAccountNumber(number)
66
+ : await resolveSkillNumber(number, { origin, fetchImpl }));
67
+ if (!resolved?.ok || resolved.number !== number || !resolved.publicSkillId) throw Error('NUMBER_UNAVAILABLE');
65
68
  if (resolved.accountUserId && resolved.accountUserId !== session.userId) throw Error('ACCESS_ACCOUNT_MISMATCH');
66
69
  const identity = { ...resolved, accountUserId: session.userId };
67
70
  await recovery.onResolved(identity);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiashe/cli",
3
- "version": "0.1.50",
3
+ "version": "0.1.51",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "xiashe": "bin/xiashe.mjs"
@@ -12,7 +12,7 @@
12
12
  "lib"
13
13
  ],
14
14
  "dependencies": {
15
- "@xiashe/sdk": "0.1.50"
15
+ "@xiashe/sdk": "0.1.51"
16
16
  },
17
17
  "engines": {
18
18
  "node": ">=20"