@itpay/cli 0.2.8 → 0.2.10

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/README.md CHANGED
@@ -239,9 +239,9 @@ Payment QR rules:
239
239
  - Otherwise render the ItPay-hosted `qr_png_url` / `preferred_qr_url`.
240
240
  - Use `mobile_wallet_url` only as a human mobile fallback.
241
241
  - Do not generate your own QR from payment URLs.
242
- - In agent app clients, execute `render_plan.selected` first. Send its media, text/markdown, real links, and native buttons when the adapter supports them.
243
- - In OpenClaw Telegram, send `render_plan.selected.openclaw_message` with OpenClaw `message send --media ... --presentation ...`; do not put legacy inline media directives inside human prose.
244
- - Do not rewrite `render_plan.selected` into a custom table or omit the real URL.
242
+ - If you know the current chat channel and `render_plan.platforms.<channel>` exists, use that branch before `render_plan.selected`.
243
+ - In OpenClaw Telegram, send `render_plan.platforms.telegram.openclaw_message.command_args` with `openclaw message send`; its `presentation.blocks[].buttons[]` uses native `text/url/callback_data`.
244
+ - If the channel is unsupported, use `render_plan.selected.fallback` / plain chat. Do not rewrite the chosen plan into a custom table or omit the real URL.
245
245
  - If status is `payment_handoff_required`, `next` is the human reply step, not payment wait.
246
246
  - Treat only `payment_intent.verified` as payment success.
247
247
 
@@ -41,11 +41,12 @@
41
41
  "Payment QR display requires both a valid/saved buyer session and payment_intent_id. If payment_intent_id appears before buyer_session is saved, run buyer checkout resume/status instead of showing payment QR.",
42
42
  "Do not stop after showing auth_qr unless the human explicitly asks you to pause. Keep waiting/resuming the same checkout so the post-auth payment handoff can continue.",
43
43
  "Do not describe auth_qr as payment success or payment proof. Only payment_intent.verified proves payment.",
44
- "If response.render_plan.selected exists, treat it as the final UI render plan for the current host. Execute selected before reading other platform branches.",
45
- "Do not rewrite response.render_plan.selected into a custom table. Use selected.text/markdown, selected.media, selected.links, and selected.buttons as provided.",
44
+ "If you know the current chat channel and response.render_plan.platforms.<channel> exists, use that channel branch before response.render_plan.selected.",
45
+ "If response.render_plan.selected.platform is current_channel_required, choose the branch matching the current channel; selected.fallback is only for unsupported plain chat clients.",
46
+ "Do not rewrite the chosen render plan into a custom table. Use its text/markdown, media, links, and buttons as provided.",
46
47
  "If selected.links exists, include the real URL. Do not only show the link label.",
47
48
  "If selected.buttons exists but the current adapter cannot render native buttons, degrade to selected.links plus short text; do not fake payment success or skip the status check.",
48
- "In OpenClaw Telegram, prefer selected.openclaw_message: send its message/media/presentation through OpenClaw message send. Do not place legacy inline media directives inside prose; that fallback cannot render inline buttons.",
49
+ "In OpenClaw Telegram, prefer response.render_plan.platforms.telegram.openclaw_message.command_args with openclaw message send. Its presentation.blocks[].buttons[] uses native text/url/callback_data; do not simulate buttons in normal prose.",
49
50
  "In Codex or Claude Code app clients, send response.human_visible_markdown or response.render_plan.platforms.codex_app.markdown to the human first. Do not start a hidden long wait before the human-visible message is sent.",
50
51
  "For Telegram-style message clients, use response.render_plan.platforms.telegram: send photo media first, include links, and expose native buttons for refresh/status when the adapter supports them.",
51
52
  "For plain chat clients, show response.human_visible_markdown and stop unless the human asks you to check status or returns with a payment question.",
@@ -35,7 +35,7 @@
35
35
  }
36
36
  ],
37
37
  "agent_rules": [
38
- "If payment wait returns payment_handoff_required, render response.render_plan.selected to the human before running any later status check.",
38
+ "If payment wait returns payment_handoff_required, render response.render_plan.platforms.<current channel> when available; otherwise use response.render_plan.selected/fallback before running any later status check.",
39
39
  "Start payment status checks only after the QR image/link has already been sent to the human or the human asks to check status.",
40
40
  "If you run payment wait without a short timeout while payment is still pending, CLI returns payment_handoff_required and human_visible_markdown instead of long-polling.",
41
41
  "Payment wait/status check is a recovery loop around the same payment_intent_id, not a one-shot command.",
@@ -68,7 +68,7 @@
68
68
  "Show the returned payment QR exactly as provided before starting payment wait.",
69
69
  "Payment truth comes only from payment_intent.verified.",
70
70
  "Secure delivery goes to the human first; report redacted delivery status only.",
71
- "When a response includes render_plan.selected, execute that selected plan first; do not make the model choose a different platform branch or rewrite the payment/auth UI. In OpenClaw Telegram, use selected.openclaw_message instead of handwritten legacy media directive prose."
71
+ "When a response includes render_plan, first use render_plan.platforms.<current channel> if it exists. If selected.platform is current_channel_required, selected.fallback is only for unsupported plain chat. In OpenClaw Telegram, pass render_plan.platforms.telegram.openclaw_message.command_args to openclaw message send instead of handwritten prose."
72
72
  ],
73
73
  "forbidden": [
74
74
  "Do not call ops commands from the buyer path.",
@@ -324,17 +324,19 @@ function buildHumanActionRenderPlan(action = {}, intent = {}, flags = {}) {
324
324
  print_links: true
325
325
  }
326
326
  });
327
- const selectedPlatform = selectedRenderPlatform(host);
328
- const selected = {
329
- platform: selectedPlatform,
330
- ...platforms[selectedPlatform]
331
- };
327
+ const selected = selectedRenderPlan(host, platforms);
332
328
  return compactObject({
333
329
  kind,
334
330
  proof_rule: kind === "payment_qr"
335
331
  ? "Only payment_intent.verified proves payment."
336
332
  : "This human action is not payment proof.",
337
333
  host: host || undefined,
334
+ platform_selection: {
335
+ rule: host
336
+ ? "selected was chosen from the detected host. If your actual channel has a more specific branch in platforms, use that branch."
337
+ : "CLI could not detect the chat channel. If your current channel appears in platforms, use that branch; selected.fallback is only for unsupported plain chat.",
338
+ telegram: "For Telegram/OpenClaw, use platforms.telegram.openclaw_message instead of selected.fallback."
339
+ },
338
340
  required_outputs: requiredOutputs,
339
341
  selected,
340
342
  platforms,
@@ -387,16 +389,16 @@ function openclawTelegramMessage({ action = {}, media = [], links = [], buttons
387
389
  const text = action.kind === "payment_qr"
388
390
  ? "请扫码或点击链接完成支付。付款完成后点“我已付款,查询状态”,或直接回复“我已付款”。"
389
391
  : "请打开 ItPay 授权入口,完成后回到当前对话。";
390
- const presentationButtons = links.map((link) => ({ label: link.label, url: link.url }));
392
+ const presentationButtons = links.map((link) => openclawURLButton(link.label, link.url));
391
393
  if (action.kind === "payment_qr") {
392
394
  presentationButtons.push(
393
- { label: "支付遇到问题 / 刷新", action: { type: "command", command: "刷新付款二维码" } },
394
- { label: "我已付款,查询状态", action: { type: "command", command: "我已付款,查询状态" } }
395
+ openclawCallbackButton("支付遇到问题 / 刷新", "refresh_payment_qr", action),
396
+ openclawCallbackButton("我已付款,查询状态", "check_payment_status", action)
395
397
  );
396
398
  } else {
397
399
  for (const button of buttons) {
398
400
  if (button.url && !presentationButtons.some((item) => item.url === button.url)) {
399
- presentationButtons.push({ label: button.text || "打开链接", url: button.url });
401
+ presentationButtons.push(openclawURLButton(button.text || "打开链接", button.url));
400
402
  }
401
403
  }
402
404
  }
@@ -417,17 +419,45 @@ function openclawTelegramMessage({ action = {}, media = [], links = [], buttons
417
419
  message: text,
418
420
  media: mediaURL || undefined,
419
421
  presentation
420
- })
422
+ }),
423
+ callbacks: action.kind === "payment_qr" ? {
424
+ refresh_payment_qr: "收到 callback_data 后刷新或重新发送同一个 payment_intent 的付款入口。",
425
+ check_payment_status: "收到 callback_data 后运行 buyer payment wait/status,只信 payment_intent.verified。"
426
+ } : undefined
421
427
  });
422
428
  }
423
429
 
430
+ function openclawURLButton(text, url) {
431
+ return compactObject({ text, url });
432
+ }
433
+
434
+ function openclawCallbackButton(text, intent, action = {}) {
435
+ const id = action.payment_intent_id || action.id || "current";
436
+ return { text, callback_data: `itp:${intent}:${id}` };
437
+ }
438
+
424
439
  function selectedRenderPlatform(host = "") {
425
440
  const normalized = String(host || "").toLowerCase().replaceAll("-", "_");
426
441
  if (["codex", "codex_app", "codex_cli"].includes(normalized)) return "codex_app";
427
442
  if (["claude", "claude_code", "claudecode"].includes(normalized)) return "claude_code";
428
443
  if (["telegram", "tg"].includes(normalized)) return "telegram";
429
444
  if (terminalQRHostAliases().has(normalized)) return "terminal";
430
- return "plain_chat";
445
+ return "";
446
+ }
447
+
448
+ function selectedRenderPlan(host = "", platforms = {}) {
449
+ const selectedPlatform = selectedRenderPlatform(host);
450
+ if (selectedPlatform && platforms[selectedPlatform]) {
451
+ return { platform: selectedPlatform, ...platforms[selectedPlatform] };
452
+ }
453
+ return compactObject({
454
+ platform: "current_channel_required",
455
+ rule: "Use render_plan.platforms.<current channel> when available; fallback is only for unsupported plain chat clients.",
456
+ telegram: platforms.telegram,
457
+ codex_app: platforms.codex_app,
458
+ claude_code: platforms.claude_code,
459
+ fallback: platforms.plain_chat
460
+ });
431
461
  }
432
462
 
433
463
  function compactObject(value = {}) {
@@ -535,7 +565,16 @@ function shouldReturnAfterAgentTextQR(flags = {}) {
535
565
  }
536
566
 
537
567
  function agentHost(flags = {}) {
538
- const explicit = String(process.env.ITP_HOST || flags.host || "").toLowerCase();
568
+ const explicit = String(
569
+ process.env.ITP_HOST ||
570
+ flags.host ||
571
+ flags.channel ||
572
+ process.env.OPENCLAW_CURRENT_CHANNEL_PROVIDER ||
573
+ process.env.OPENCLAW_CHANNEL ||
574
+ process.env.CURRENT_CHANNEL_PROVIDER ||
575
+ process.env.AGENT_CHANNEL ||
576
+ ""
577
+ ).toLowerCase();
539
578
  if (explicit) return explicit;
540
579
  if (process.env.CODEX_THREAD_ID || process.env.CODEX_SHELL || process.env.CODEX_CI) return "codex";
541
580
  if (process.env.CLAUDECODE || process.env.CLAUDE_CODE || process.env.CLAUDECODE_SESSION_ID) return "claude-code";
package/lib/runtime.js CHANGED
@@ -11,7 +11,7 @@ import { accountOverviewStatus, nextActionForAuthStatus, outputAccountStatus, re
11
11
  import {
12
12
  CREDENTIALS_PATH, CONFIG_DIR, RUNS_DIR, VERSION, apiBase, apiTimeoutMs, appendURLQuery, booleanFlag, cliCommand, commandExists,
13
13
  cryptoRandom, csvValues, currentExecutable, deleteGrantCredential, deleteSessionCredential, detectNativeCredentialStore,
14
- escapeTomlString, fileMode, intFlag, listRuns, maskSecret, mergeRun, output, parseFlags, positional, prepareSetupRun,
14
+ escapeTomlString, fileMode, intFlag, listRuns, maskSecret, mergeRun, normalizePurchaseFlags, output, parseFlags, positional, prepareSetupRun,
15
15
  queryString, quoteShell, readConfig, readCredentials, readGrantCredential, readJSON, readRun, readSessionToken, readState,
16
16
  readText, replaceManagedBlock, safeErrorMessage, sanitizeAuthResponse, shellQuote, sleep, storeGrantCredential,
17
17
  updateCurrentRun, updateRun, withStateLock, writeConfig, writeCredentials, writeJSONWithBackup, writeRun,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itpay/cli",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "description": "ItPay CLI, buyer skill, and agent-readable docs for agent-native commerce.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -211,13 +211,14 @@ itp buy <variant_id> --email <buyer_email> --phone <buyer_phone> --display agent
211
211
 
212
212
  This keeps JSON output machine-readable while allowing the CLI to prepare a
213
213
  local QR image path for clients that cannot render remote SVG reliably. In
214
- Codex or Claude Code app clients, prefer `--no-wait-payment`: execute
215
- `render_plan.selected` first. If `selected.markdown` exists, send it exactly to
216
- the human. If `selected.media` exists, attach the listed image before saying the
217
- human can scan it. If `selected.links` exists, include the real URL, not just
218
- the label. If `selected.buttons` exists and the current adapter supports native
219
- buttons, render them; otherwise fall back to the real URL plus short text. Do
220
- not invent a table or rewrite the UI plan.
214
+ agent/chat clients, prefer `--no-wait-payment`: if you know the current channel
215
+ and `render_plan.platforms.<channel>` exists, use that branch first. In Codex
216
+ or Claude Code app clients, send the platform markdown exactly. In OpenClaw
217
+ Telegram, pass `render_plan.platforms.telegram.openclaw_message.command_args`
218
+ to `openclaw message send` so media and native `text/url/callback_data` buttons
219
+ are sent through the adapter. If `selected.platform` is
220
+ `current_channel_required`, `selected.fallback` is only for unsupported plain
221
+ chat clients. Do not invent a table or rewrite the UI plan.
221
222
 
222
223
  If a response has `status=payment_handoff_required`, `next` is the user-visible
223
224
  reply step, not payment wait. Do not run `buyer payment wait` until the human