@xiashe/cli 0.1.50 → 0.1.52

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
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { createInterface } from 'node:readline/promises';
3
3
  import { syncNumber } from '../lib/skill-sync.mjs';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { resolveUseShareCode } from '../lib/share-code.mjs';
4
6
  import { expandUseNumber, runAccountAwareUse } from '../lib/use-number.mjs';
5
7
  import { deliverNumber } from '../lib/delivery.mjs';
6
8
  import { runAccessCommand } from '../skills/xiashe/scripts/runtime-state.mjs';
@@ -1896,7 +1898,7 @@ function osPlatform() {
1896
1898
  async function main() {
1897
1899
  const shortUse = process.argv[2] === 'use';
1898
1900
  let argv;
1899
- try { argv = expandUseNumber(process.argv.slice(2), { brand: COMMAND_NAME }); }
1901
+ try { argv = expandUseNumber(await resolveUseShareCode(process.argv.slice(2), { brand: COMMAND_NAME }), { brand: COMMAND_NAME }); }
1900
1902
  catch (error) { fail(error.message, EXIT_USAGE); }
1901
1903
  const parsed = parseGlobal(argv);
1902
1904
  const [command, sub, ...args] = parsed.argv;
@@ -1942,8 +1944,24 @@ async function main() {
1942
1944
  const client = new XiasheClient(loaded.profile, { profileName: loaded.profileName, timeoutMs: global.timeoutMs });
1943
1945
  const options = { origin: global.actionsUrl, profile: loaded.profile, guest: tail.includes('--guest'),
1944
1946
  hasSavedAccount: !!loaded.config.profiles[loaded.profileName]?.session?.userId,
1947
+ resolveAccountNumber: value => client.resolveSkillNumber(value, { account: true }),
1945
1948
  acquire: (value, requestToken) => client.acquireSkillNumber(value, requestToken) };
1946
- const result = await runAccountAwareUse(number, options);
1949
+ const use = async (settings) => {
1950
+ const result = await runAccountAwareUse(number, settings);
1951
+ if (result.stage !== 'runtime_active' || COMMAND_NAME !== 'xiashe') return result;
1952
+ // Inspect the existing capability without issuing claims, reserving payment or downloading.
1953
+ const checked = await syncNumber(number, { mode: 'check', origin: settings.origin, mcpCall, decode: decodeMcpToolResult });
1954
+ const steps = {
1955
+ deliver: '已可使用。沿同一会话获取完整包,无需付款。',
1956
+ recover_order: '已有订单需要核对。停在这里,询问是否查看原订单;不要发起结算或获取新的支付资料。',
1957
+ confirm_checkout: '当前身份尚未购买。询问用户是否查看报价,等用户选择后才继续结算。',
1958
+ unavailable: '作品暂不可用。停止获取和结算。'
1959
+ };
1960
+ const decision = checked.metadata.buyerNextStep;
1961
+ if (!Object.hasOwn(steps, decision)) throw Error('SKILL_ACCESS_STATUS_UNAVAILABLE');
1962
+ return { ...result, buyerNextStep: decision, next: steps[decision], officialProtocolFile: fileURLToPath(new URL('../skills/xiashe/SKILL.md', import.meta.url)) };
1963
+ };
1964
+ const result = await use(options);
1947
1965
  if (!global.json && result.stage === 'purchase_choice') {
1948
1966
  const price = Number.isSafeInteger(result.priceCents) ? ` · ${result.currency} ${(result.priceCents / 100).toFixed(2)}` : '';
1949
1967
  const title = String(result.name || number).replace(/[\x00-\x1f\x7f-\x9f\u202a-\u202e\u2066-\u2069]/g, '');
@@ -1953,7 +1971,7 @@ async function main() {
1953
1971
  let choice;
1954
1972
  try { choice = (await prompt.question('请选择 1、2 或 3:')).trim(); }
1955
1973
  finally { prompt.close(); }
1956
- if (choice === '1') return print(await runAccountAwareUse(number, { ...options, guest: true }), global);
1974
+ if (choice === '1') return print(await use({ ...options, guest: true }), global);
1957
1975
  if (choice === '2') console.log(result.continueUrl);
1958
1976
  else if (choice !== '3') fail('请输入 1、2 或 3', EXIT_USAGE);
1959
1977
  } else {
@@ -0,0 +1,16 @@
1
+ import { protocolJsonRequest } from '../skills/xiashe/scripts/http.mjs';
2
+
3
+ // Resolve to the canonical number before opening any local state or account session.
4
+ export async function resolveUseShareCode(argv, { brand, fetchImpl = fetch }) {
5
+ if (brand !== 'xiashe' || argv[0] !== 'use' || !argv[1]?.startsWith('XS')) return argv;
6
+ const [, code, ...flags] = argv;
7
+ const match = /^XS1([PS])\d{2}-[0-9a-f]{40}$/.exec(code);
8
+ if (!match || flags.some(flag => !['--staging', '--guest', '--json'].includes(flag))) throw Error('SKILL_SHARE_CODE_INVALID');
9
+ const staging = match[1] === 'S';
10
+ if (!staging && flags.includes('--staging')) throw Error('SKILL_SHARE_ENVIRONMENT_MISMATCH');
11
+ const origin = staging ? 'https://actions.projectphenix.site' : 'https://actions.xiashe.chat';
12
+ const result = await protocolJsonRequest(origin + '/public/skill-share-codes/' + code, undefined, { method: 'GET', fetchImpl, maxResponseBytes: 2048 });
13
+ if (result.ok !== true || typeof result.number !== 'string' || !/^[1-9]\d{5,8}$/.test(result.number) ||
14
+ result.environment !== (staging ? 'staging' : 'production')) throw Error('SKILL_SHARE_CODE_INVALID');
15
+ return ['use', result.number, ...flags, ...(staging && !flags.includes('--staging') ? ['--staging'] : [])];
16
+ }
@@ -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.52",
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.52"
16
16
  },
17
17
  "engines": {
18
18
  "node": ">=20"