@itpay/cli 0.1.1 → 0.1.2
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/itp
CHANGED
|
@@ -838,6 +838,7 @@ async function buyer(command, rest, flags) {
|
|
|
838
838
|
if (subcommand === "grants") {
|
|
839
839
|
const action = rest[1] && !String(rest[1]).startsWith("--") ? rest[1] : "list";
|
|
840
840
|
if (action === "list") {
|
|
841
|
+
await ensureBuyerSessionForVaultAccess(flags);
|
|
841
842
|
const grants = await listBuyerAgentReadGrants(flags);
|
|
842
843
|
output(buyerRunOutput({
|
|
843
844
|
status: "agent_read_grants",
|
|
@@ -849,6 +850,7 @@ async function buyer(command, rest, flags) {
|
|
|
849
850
|
if (action === "read" || action === "show") {
|
|
850
851
|
const grantID = flags.grant || flags.grant_id || flags.agent_read_grant_id || positional(rest, 2);
|
|
851
852
|
if (!grantID) throw new Error("agent_read_grant_id is required");
|
|
853
|
+
await ensureBuyerSessionForVaultAccess(flags);
|
|
852
854
|
const view = await readBuyerAgentReadGrant(grantID, flags);
|
|
853
855
|
output(buyerRunOutput({
|
|
854
856
|
status: "agent_read_grant_view",
|
|
@@ -859,6 +861,7 @@ async function buyer(command, rest, flags) {
|
|
|
859
861
|
}
|
|
860
862
|
}
|
|
861
863
|
if (subcommand === "read") {
|
|
864
|
+
await ensureBuyerSessionForVaultAccess(flags);
|
|
862
865
|
const view = await readBuyerVaultArtifactGrant(flags);
|
|
863
866
|
output(buyerRunOutput({
|
|
864
867
|
status: "agent_read_grant_view",
|
|
@@ -1325,6 +1328,35 @@ async function maybeClaimBuyerSessionForCheckout(checkout, flags = {}) {
|
|
|
1325
1328
|
return await maybeClaimBuyerSessionFromAuthAction(action, flags);
|
|
1326
1329
|
}
|
|
1327
1330
|
|
|
1331
|
+
async function ensureBuyerSessionForVaultAccess(flags = {}) {
|
|
1332
|
+
if (readSessionToken()) return null;
|
|
1333
|
+
const checkoutID =
|
|
1334
|
+
flags.checkout ||
|
|
1335
|
+
flags.checkout_id ||
|
|
1336
|
+
readState().last_core_checkout_id ||
|
|
1337
|
+
readState().last_core_auth_checkout_id;
|
|
1338
|
+
if (checkoutID) {
|
|
1339
|
+
try {
|
|
1340
|
+
const checkout = await getBuyerCheckout(checkoutID, flags);
|
|
1341
|
+
rememberCoreAuthAction(checkout.checkout_id || checkoutID, checkout.human_action);
|
|
1342
|
+
const claimed = await maybeClaimBuyerSessionForCheckout(checkout, { ...flags, quiet: true });
|
|
1343
|
+
if (claimed || readSessionToken()) return claimed;
|
|
1344
|
+
} catch {
|
|
1345
|
+
// Continue with the locally remembered auth action below.
|
|
1346
|
+
}
|
|
1347
|
+
const action = readCoreAuthAction(checkoutID);
|
|
1348
|
+
const claimed = await maybeClaimBuyerSessionFromAuthAction(action, { ...flags, quiet: true });
|
|
1349
|
+
if (claimed || readSessionToken()) return claimed;
|
|
1350
|
+
}
|
|
1351
|
+
const state = readState();
|
|
1352
|
+
const entries = Object.entries(state.core_auth_actions || {});
|
|
1353
|
+
for (const [, action] of entries.reverse()) {
|
|
1354
|
+
const claimed = await maybeClaimBuyerSessionFromAuthAction(action, { ...flags, quiet: true });
|
|
1355
|
+
if (claimed || readSessionToken()) return claimed;
|
|
1356
|
+
}
|
|
1357
|
+
return null;
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1328
1360
|
function parseBuyerAuthActionURL(action) {
|
|
1329
1361
|
const rawURL = action?.url || action?.auth_url || "";
|
|
1330
1362
|
if (!rawURL) return {};
|
|
@@ -30,12 +30,13 @@
|
|
|
30
30
|
"The claim link is short-lived and single-use.",
|
|
31
31
|
"The agent may explain that ItPay intentionally separates agent operations from raw secret access.",
|
|
32
32
|
"If the human wants the agent to analyze or use the delivered result, ask them to click 'Give to Agent / 一键给 Agent' in the ItPay page and confirm with Passkey.",
|
|
33
|
-
"After the human grants access, the agent should discover the grant with `itp buyer vault grants list
|
|
33
|
+
"After the human grants access, the agent should discover the grant with `itp buyer vault grants list --checkout <checkout_id> --json`; do not ask the human to paste the grant id. The CLI restores the buyer agent session from the checkout auth handoff when possible.",
|
|
34
34
|
"If the human later wants the agent to install or use something, wait for an explicit human-granted install/capability flow."
|
|
35
35
|
],
|
|
36
36
|
"forbidden": [
|
|
37
37
|
"Do not ask the human to paste the claim link or key into chat.",
|
|
38
38
|
"Do not fetch the claim page with CLI, curl, browser automation, or an agent tool.",
|
|
39
|
+
"Do not ask the human for auth session IDs, display tokens, buyer session tokens, or portal tokens.",
|
|
39
40
|
"Do not store raw content in local run files."
|
|
40
41
|
],
|
|
41
42
|
"next_docs": [
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"A checkout/order has delivered a vault artifact and the human granted agent-readable access."
|
|
11
11
|
],
|
|
12
12
|
"required_state": {
|
|
13
|
-
"needs": ["authenticated buyer account session", "current agent device binding", "order_id or checkout_id or vault_artifact_id"],
|
|
13
|
+
"needs": ["checkout_id or authenticated buyer account session", "current agent device binding", "order_id or checkout_id or vault_artifact_id"],
|
|
14
14
|
"must_not_need": ["human portal token", "claim token", "passkey credential", "raw protected payload", "grant id copied by the human"]
|
|
15
15
|
},
|
|
16
16
|
"commands": [
|
|
@@ -37,14 +37,16 @@
|
|
|
37
37
|
],
|
|
38
38
|
"agent_rules": [
|
|
39
39
|
"Only read through `buyer vault` commands after the human has explicitly approved the agent grant in the ItPay portal.",
|
|
40
|
+
"Prefer `itp buyer vault grants list --checkout <checkout_id> --json`; the CLI can automatically restore the buyer agent session from the checkout auth handoff when possible.",
|
|
40
41
|
"Do not ask the human to copy or paste `agent_read_grant_id`; discover it with `buyer vault grants list`.",
|
|
41
42
|
"If no grant is returned, tell the human to open their ItPay account portal, reveal with Passkey, choose fields, and confirm one-key agent authorization.",
|
|
42
43
|
"Use only fields returned in the grant view. Do not infer that unreturned fields are accessible.",
|
|
43
|
-
"If the command returns 401 or buyer_session_invalid
|
|
44
|
+
"If the command still returns 401 or buyer_session_invalid after using `--checkout`, run `itp buyer checkout status <checkout_id> --json`, then retry `itp buyer vault grants list --checkout <checkout_id> --json`. Ask the human to reauthorize only if the checkout/auth handoff has expired."
|
|
44
45
|
],
|
|
45
46
|
"forbidden": [
|
|
47
|
+
"Do not open, click through, scrape, or automate the human web UI yourself.",
|
|
46
48
|
"Do not open, scrape, or screenshot the human portal to obtain protected content.",
|
|
47
|
-
"Do not request passkey credentials, portal tokens, claim links, claim tokens, storage refs, provider AppCode, provider keys, or raw payloads.",
|
|
49
|
+
"Do not request passkey credentials, portal tokens, claim links, claim tokens, auth session IDs, display tokens, session tokens, storage refs, provider AppCode, provider keys, or raw payloads.",
|
|
48
50
|
"Do not use another agent's grant id. Grants are scoped to the exact buyer account session and agent device.",
|
|
49
51
|
"Do not cache selected fields beyond the task context unless the user explicitly asks you to create a local artifact."
|
|
50
52
|
],
|
package/package.json
CHANGED
|
@@ -126,9 +126,11 @@ registered name or run fuzzy search first.
|
|
|
126
126
|
`delivery_claimable`, `check_email`, and `claim_link_sent`, but must not
|
|
127
127
|
fetch or reveal protected content.
|
|
128
128
|
11. If the human uses Passkey to authorize agent-readable vault access, do not
|
|
129
|
-
ask them to paste content, portal text, claim links,
|
|
129
|
+
ask them to paste content, portal text, claim links, session tokens, auth
|
|
130
|
+
session IDs, display tokens, or grant IDs. Run
|
|
130
131
|
`itp buyer vault grants list ...` and then `itp buyer vault read ...`.
|
|
131
|
-
|
|
132
|
+
The CLI automatically restores the buyer agent session from the checkout
|
|
133
|
+
auth handoff when possible. Use only the fields returned by that command.
|
|
132
134
|
12. If the user asks you to analyze, compare, summarize, install, or otherwise
|
|
133
135
|
use a delivered result, you may ask them to open the ItPay claim/account
|
|
134
136
|
page, click "Give to Agent / 一键给 Agent", choose fields, and confirm with
|
|
@@ -140,6 +142,10 @@ registered name or run fuzzy search first.
|
|
|
140
142
|
broad keyword. For enterprise precise lookup, `company_name_or_credit_no`
|
|
141
143
|
must be exact; otherwise warn the user that the query may waste the paid
|
|
142
144
|
lookup.
|
|
145
|
+
15. Do not operate ItPay by opening the human web UI yourself. Use the CLI for
|
|
146
|
+
catalog, cart, checkout, payment wait, delivery status, grant discovery,
|
|
147
|
+
and vault reads. Browser/UI pages are for the human to scan, pay, claim,
|
|
148
|
+
reveal, and approve.
|
|
143
149
|
|
|
144
150
|
## Docs Directory
|
|
145
151
|
|