@mysten-incubation/sui-agent-pass 0.1.31 → 0.1.34
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/dist/chain.js +30 -24
- package/dist/explorer.js +3 -6
- package/dist/plugin.js +4 -2
- package/docs/PLAYBOOK.md +6 -4
- package/package.json +1 -1
- package/skills/agent-pass/SKILL.md +6 -4
- package/web-dist/assets/{index-Elf_o7Cj.js → index-DRKhkH-7.js} +43 -43
- package/web-dist/assets/{mount-wnWN72B8.js → mount-CWWc3NuH.js} +1 -1
- package/web-dist/index.html +1 -1
package/dist/chain.js
CHANGED
|
@@ -523,8 +523,11 @@ export async function readAllowance(client, id, coinType) {
|
|
|
523
523
|
if (normalizeStructTag(object.type) !== normalizeStructTag(allowanceType(coinType)) ||
|
|
524
524
|
object.owner.$kind !== 'Shared')
|
|
525
525
|
throw new Error('Unexpected allowance type or ownership');
|
|
526
|
-
|
|
527
|
-
|
|
526
|
+
return allowanceView(object.content, coinType, await chainTime(client));
|
|
527
|
+
}
|
|
528
|
+
/** An allowance's fields from its content, with `now` for the rate-limit window. */
|
|
529
|
+
function allowanceView(content, coinType, now) {
|
|
530
|
+
const a = allowanceBcs.parse(content), s = a.settings, r = s.rate_limit?.Windowed;
|
|
528
531
|
let rateLimit = null;
|
|
529
532
|
if (r) {
|
|
530
533
|
const periodMs = r.window.PeriodicMs ?? null;
|
|
@@ -572,43 +575,46 @@ export async function readAllowanceCapTarget(client, id) {
|
|
|
572
575
|
*/
|
|
573
576
|
export async function discoverAllowances(client, d, pass) {
|
|
574
577
|
const app = normalizeStructTag(appType(d)), owner = normalizeSuiAddress(pass.owner), agent = normalizeSuiAddress(pass.agent);
|
|
575
|
-
|
|
578
|
+
// The caps come with their content, so each page names its allowances outright; the
|
|
579
|
+
// allowances are then one batched read. Three round trips in all, whatever the wallet holds.
|
|
580
|
+
const capOf = new Map();
|
|
576
581
|
let cursor = null;
|
|
577
582
|
do {
|
|
578
583
|
const page = await client.listOwnedObjects({
|
|
579
584
|
owner,
|
|
580
585
|
cursor,
|
|
581
586
|
limit: 50,
|
|
587
|
+
type: '0x2::allowance::AllowanceCap',
|
|
588
|
+
include: { content: true },
|
|
582
589
|
});
|
|
583
|
-
for (const o of page.objects)
|
|
584
|
-
|
|
585
|
-
if (normalizeSuiAddress(tag.address) === normalizeSuiAddress('0x2') &&
|
|
586
|
-
tag.module === 'allowance' &&
|
|
587
|
-
tag.name === 'AllowanceCap')
|
|
588
|
-
caps.push(o.objectId);
|
|
589
|
-
}
|
|
590
|
+
for (const o of page.objects)
|
|
591
|
+
capOf.set(normalizeSuiAddress(allowanceCapBcs.parse(o.content).allowance), o.objectId);
|
|
590
592
|
cursor = page.hasNextPage ? page.cursor : null;
|
|
591
|
-
} while (cursor &&
|
|
593
|
+
} while (cursor && capOf.size < 1000);
|
|
592
594
|
const allowances = {};
|
|
593
595
|
let gas = null;
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
596
|
+
if (!capOf.size)
|
|
597
|
+
return { allowances, gas };
|
|
598
|
+
const [{ objects }, now] = await Promise.all([
|
|
599
|
+
client.getObjects({ objectIds: [...capOf.keys()], include: { content: true } }),
|
|
600
|
+
chainTime(client),
|
|
601
|
+
]);
|
|
602
|
+
for (const object of objects) {
|
|
603
|
+
// A revoked allowance is deleted while its cap may linger; that entry is an error here.
|
|
604
|
+
if (!('objectId' in object))
|
|
605
|
+
continue;
|
|
606
|
+
const coin = allowanceCoin(object.type);
|
|
602
607
|
if (!coin)
|
|
603
|
-
|
|
604
|
-
const view =
|
|
605
|
-
if (
|
|
606
|
-
|
|
608
|
+
continue;
|
|
609
|
+
const view = allowanceView(object.content, coin, now);
|
|
610
|
+
if (view.funder !== owner || view.spender !== agent)
|
|
611
|
+
continue;
|
|
612
|
+
const target = normalizeSuiAddress(object.objectId), cap = capOf.get(target);
|
|
607
613
|
if (view.app === app)
|
|
608
614
|
allowances[coin] = { allowance: target, revokeCap: cap };
|
|
609
615
|
else if (view.app === null && view.name === AGENT_GAS_NAME && coin === SUI)
|
|
610
616
|
gas = { allowance: target, revokeCap: cap };
|
|
611
|
-
}
|
|
617
|
+
}
|
|
612
618
|
return { allowances, gas };
|
|
613
619
|
}
|
|
614
620
|
/** The pass-bound allowances of an active session, by coin; null where one no longer exists. */
|
package/dist/explorer.js
CHANGED
|
@@ -122,12 +122,9 @@ export async function findPass(client, d, passId) {
|
|
|
122
122
|
* pass-bound ones carry the `PASS` app and the owner as funder, the gas allowance its fixed
|
|
123
123
|
* name. Null once the owner has revoked, because the allowances no longer exist.
|
|
124
124
|
*/
|
|
125
|
-
export async function discoverActive(client, d, pass) {
|
|
126
|
-
const
|
|
127
|
-
const { allowances, gas } = await discoverAllowances(client, d, {
|
|
128
|
-
owner: pass.owner,
|
|
129
|
-
agent: control.agent,
|
|
130
|
-
});
|
|
125
|
+
export async function discoverActive(client, d, pass, control) {
|
|
126
|
+
const { agent } = control ?? (await readControl(client, d, pass.id));
|
|
127
|
+
const { allowances, gas } = await discoverAllowances(client, d, { owner: pass.owner, agent });
|
|
131
128
|
if (!gas || Object.keys(allowances).length === 0)
|
|
132
129
|
return null;
|
|
133
130
|
return {
|
package/dist/plugin.js
CHANGED
|
@@ -28,7 +28,7 @@ import { address, coinBySymbol, coinInfo, connects, DAY_MS, defaultGasDaily, dis
|
|
|
28
28
|
import { findPassByAgent, passIdOf } from './explorer.js';
|
|
29
29
|
import { passEnded, returnGasFloat } from './float.js';
|
|
30
30
|
import { failure, INSTRUCTIONS, keyAlert, MAX_TOOL_INPUT_ELEMENTS, registerDocs, result, serverInfo, sessionInfo, SIGN_ANNOTATIONS, SIGN_DESCRIPTION, } from './mcp.js';
|
|
31
|
-
import { authenticated, body, ownerPageUrl, startServer } from './server.js';
|
|
31
|
+
import { authenticated, body, ownerPageUrl, passPageUrl, startServer } from './server.js';
|
|
32
32
|
import { SessionSigner } from './signer.js';
|
|
33
33
|
import { SessionStore, token } from './storage.js';
|
|
34
34
|
export const defaultRoot = () => join(homedir(), '.sui-agent-pass');
|
|
@@ -762,13 +762,15 @@ export function createPluginMcp(registry) {
|
|
|
762
762
|
throw new Error('No pass for this key is on chain; nothing to resign from');
|
|
763
763
|
// The key's remaining gas goes back to the owner in the same transaction.
|
|
764
764
|
const swept = await returnGasFloat(client, store.directory, sessionAddress, hit.owner, (tx) => resignCall(tx, d, hit.id));
|
|
765
|
+
const { origin } = await registry.server(session);
|
|
765
766
|
return result({
|
|
766
767
|
pass: session.id,
|
|
767
768
|
passId: hit.id,
|
|
768
769
|
digest: swept.digest,
|
|
769
770
|
gasReturned: swept.amount,
|
|
770
771
|
status: 'revoked',
|
|
771
|
-
|
|
772
|
+
passUrl: passPageUrl(d, origin, hit.id),
|
|
773
|
+
next: 'The key can no longer act under the rules and its gas is back with the owner. Send them passUrl and ask them to close the pass there when convenient: that deletes the allowances, including the gas allowance this key could still draw on up to its cap, and refunds the storage deposit. Then call forget_pass to delete this session.',
|
|
772
774
|
});
|
|
773
775
|
}
|
|
774
776
|
catch (error) {
|
package/docs/PLAYBOOK.md
CHANGED
|
@@ -244,10 +244,12 @@ There are two ways a pass ends, and you should know which one you are in.
|
|
|
244
244
|
**You end it.** This is the normal ending. When the work is done and nothing recurring remains,
|
|
245
245
|
or the owner tells you to stop, call `resign_pass`: one transaction from your own key, no owner
|
|
246
246
|
signature. It ends your authority on chain (every later action is refused) and returns the key's
|
|
247
|
-
remaining gas to the owner in the same transaction, so nothing of theirs stays with you.
|
|
248
|
-
|
|
249
|
-
the
|
|
250
|
-
|
|
247
|
+
remaining gas to the owner in the same transaction, so nothing of theirs stays with you. It
|
|
248
|
+
returns `passUrl`: send it to the owner and ask them to close the pass there when convenient.
|
|
249
|
+
That deletes the allowances and refunds the storage deposit, and it matters beyond tidiness: the
|
|
250
|
+
gas allowance has no policy, so until it is deleted the key could still draw on it up to its
|
|
251
|
+
cap. Those are the owner's objects, which only their signature can remove. Resigning is
|
|
252
|
+
irreversible; a new pass needs a new proposal. Then call `forget_pass` for the session, which
|
|
251
253
|
deletes the session directory and its key.
|
|
252
254
|
|
|
253
255
|
**The owner ends it.** When something is wrong on their side, the owner stops or closes the
|
package/package.json
CHANGED
|
@@ -249,10 +249,12 @@ There are two ways a pass ends, and you should know which one you are in.
|
|
|
249
249
|
**You end it.** This is the normal ending. When the work is done and nothing recurring remains,
|
|
250
250
|
or the owner tells you to stop, call `resign_pass`: one transaction from your own key, no owner
|
|
251
251
|
signature. It ends your authority on chain (every later action is refused) and returns the key's
|
|
252
|
-
remaining gas to the owner in the same transaction, so nothing of theirs stays with you.
|
|
253
|
-
|
|
254
|
-
the
|
|
255
|
-
|
|
252
|
+
remaining gas to the owner in the same transaction, so nothing of theirs stays with you. It
|
|
253
|
+
returns `passUrl`: send it to the owner and ask them to close the pass there when convenient.
|
|
254
|
+
That deletes the allowances and refunds the storage deposit, and it matters beyond tidiness: the
|
|
255
|
+
gas allowance has no policy, so until it is deleted the key could still draw on it up to its
|
|
256
|
+
cap. Those are the owner's objects, which only their signature can remove. Resigning is
|
|
257
|
+
irreversible; a new pass needs a new proposal. Then call `forget_pass` for the session, which
|
|
256
258
|
deletes the session directory and its key.
|
|
257
259
|
|
|
258
260
|
**The owner ends it.** When something is wrong on their side, the owner stops or closes the
|