@agenttrust-sdk/mcp 0.3.1 → 0.3.3
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 +25 -3
- package/dist/chain.js +4 -2
- package/dist/chain.js.map +1 -1
- package/dist/config.d.ts +22 -2
- package/dist/config.js +165 -15
- package/dist/config.js.map +1 -1
- package/dist/embedded-docs/mcp/hosted-endpoint.mdx +1 -1
- package/dist/embedded-docs/mcp/install.mdx +12 -3
- package/dist/embedded-docs/mcp/tools.mdx +2 -2
- package/dist/embedded-docs/quickstart.mdx +83 -0
- package/dist/errors.d.ts +79 -0
- package/dist/errors.js +277 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.js +13 -6
- package/dist/index.js.map +1 -1
- package/dist/server.js +19 -16
- package/dist/server.js.map +1 -1
- package/dist/tools/discovery/docs.d.ts +6 -0
- package/dist/tools/discovery/docs.js +13 -1
- package/dist/tools/discovery/docs.js.map +1 -1
- package/dist/tools/discovery/facilitator-walkthrough.d.ts +5 -0
- package/dist/tools/discovery/facilitator-walkthrough.js +13 -2
- package/dist/tools/discovery/facilitator-walkthrough.js.map +1 -1
- package/dist/tools/index.js +2 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/read/get-quantu-reputation.d.ts +23 -3
- package/dist/tools/read/get-quantu-reputation.js +32 -7
- package/dist/tools/read/get-quantu-reputation.js.map +1 -1
- package/dist/tools/read/simulate-payment.js +13 -13
- package/dist/tools/read/simulate-payment.js.map +1 -1
- package/dist/tools/write/emit-feedback.d.ts +4 -4
- package/dist/tools/write/emit-feedback.js +55 -12
- package/dist/tools/write/emit-feedback.js.map +1 -1
- package/dist/tools/write/init-authority.d.ts +43 -0
- package/dist/tools/write/init-authority.js +92 -0
- package/dist/tools/write/init-authority.js.map +1 -0
- package/dist/tools/write/init-policy.d.ts +23 -3
- package/dist/tools/write/init-policy.js +92 -15
- package/dist/tools/write/init-policy.js.map +1 -1
- package/dist/tools/write/request-validation.js +6 -2
- package/dist/tools/write/request-validation.js.map +1 -1
- package/dist/tools/write/respond-to-validation.d.ts +3 -2
- package/dist/tools/write/respond-to-validation.js +10 -7
- package/dist/tools/write/respond-to-validation.js.map +1 -1
- package/dist/tools/write/set-killswitch.d.ts +10 -0
- package/dist/tools/write/set-killswitch.js +63 -14
- package/dist/tools/write/set-killswitch.js.map +1 -1
- package/package.json +15 -16
- package/scripts/install-claude-desktop.sh +0 -0
- package/dist/embedded-docs/getting-started/architecture-overview.mdx +0 -85
- package/dist/embedded-docs/reference/formal-verification.mdx +0 -19
- package/dist/embedded-docs/sdk/atomic-tx-invariant.mdx +0 -37
|
@@ -33,6 +33,19 @@ declare const InputSchema: z.ZodObject<{
|
|
|
33
33
|
agent_asset: string;
|
|
34
34
|
}>;
|
|
35
35
|
type Input = z.infer<typeof InputSchema>;
|
|
36
|
+
/**
|
|
37
|
+
* Stable, machine-parseable error codes the LLM can branch on when the
|
|
38
|
+
* atom_stats fetch / decode misses. The string `error` field stays for
|
|
39
|
+
* human readability; new callers should prefer `errorCode`.
|
|
40
|
+
*
|
|
41
|
+
* - "wrong_owner" — account exists but owner != Quantu atom_engine
|
|
42
|
+
* (e.g., user pointed at a non-Quantu PDA).
|
|
43
|
+
* - "size_mismatch" — account exists but data.len() != ATOM_STATS_SIZE
|
|
44
|
+
* (Quantu schema drift or wrong account).
|
|
45
|
+
* - "schema_mismatch" — schema_version byte != expected (1) OR a
|
|
46
|
+
* tier-range canary failed (>ATOM_TIER_MAX).
|
|
47
|
+
*/
|
|
48
|
+
export type QuantuReputationErrorCode = "wrong_owner" | "size_mismatch" | "schema_mismatch";
|
|
36
49
|
interface Output {
|
|
37
50
|
pda: string;
|
|
38
51
|
explorerUrl: string;
|
|
@@ -44,6 +57,9 @@ interface Output {
|
|
|
44
57
|
rawByteLen: number;
|
|
45
58
|
/** Set when the schema-version canary fails or the account is undersized. */
|
|
46
59
|
error?: string;
|
|
60
|
+
/** Machine-parseable companion to `error` — LLM agents should branch on this
|
|
61
|
+
* rather than grep `error`. Only set when `error` is set. */
|
|
62
|
+
errorCode?: QuantuReputationErrorCode;
|
|
47
63
|
reputation?: {
|
|
48
64
|
/** v1 fast-path tier (0..=4). The CounterpartyTier policy reads
|
|
49
65
|
* this in v1 demo mode. */
|
|
@@ -68,11 +84,15 @@ export declare const ATOM_STATS_CONFIDENCE_OFFSET = 557;
|
|
|
68
84
|
export declare const ATOM_STATS_SCHEMA_VERSION_OFFSET = 560;
|
|
69
85
|
export declare const ATOM_STATS_SCHEMA_VERSION_EXPECTED = 1;
|
|
70
86
|
export declare const ATOM_TIER_MAX = 4;
|
|
71
|
-
/** Pure-fn bytes → reputation. Returns `{ error }` when the buffer
|
|
72
|
-
* canary (size, schema_version, tier-range). Mirrors the on-chain
|
|
73
|
-
* fail-loud semantics — caller surfaces the error.
|
|
87
|
+
/** Pure-fn bytes → reputation. Returns `{ error, errorCode }` when the buffer
|
|
88
|
+
* fails any canary (size, schema_version, tier-range). Mirrors the on-chain
|
|
89
|
+
* parser's fail-loud semantics — caller surfaces the error.
|
|
90
|
+
*
|
|
91
|
+
* `errorCode` is machine-parseable: `"size_mismatch"` for length canary,
|
|
92
|
+
* `"schema_mismatch"` for schema_version byte or tier-range canary. */
|
|
74
93
|
export declare function decodeAtomStatsBytes(data: Buffer | Uint8Array): NonNullable<Output["reputation"]> | {
|
|
75
94
|
error: string;
|
|
95
|
+
errorCode: QuantuReputationErrorCode;
|
|
76
96
|
};
|
|
77
97
|
export declare const getQuantuReputationTool: Tool<Input, Output>;
|
|
78
98
|
export {};
|
|
@@ -53,27 +53,42 @@ exports.ATOM_STATS_CONFIDENCE_OFFSET = 557;
|
|
|
53
53
|
exports.ATOM_STATS_SCHEMA_VERSION_OFFSET = 560;
|
|
54
54
|
exports.ATOM_STATS_SCHEMA_VERSION_EXPECTED = 1;
|
|
55
55
|
exports.ATOM_TIER_MAX = 4;
|
|
56
|
-
/** Pure-fn bytes → reputation. Returns `{ error }` when the buffer
|
|
57
|
-
* canary (size, schema_version, tier-range). Mirrors the on-chain
|
|
58
|
-
* fail-loud semantics — caller surfaces the error.
|
|
56
|
+
/** Pure-fn bytes → reputation. Returns `{ error, errorCode }` when the buffer
|
|
57
|
+
* fails any canary (size, schema_version, tier-range). Mirrors the on-chain
|
|
58
|
+
* parser's fail-loud semantics — caller surfaces the error.
|
|
59
|
+
*
|
|
60
|
+
* `errorCode` is machine-parseable: `"size_mismatch"` for length canary,
|
|
61
|
+
* `"schema_mismatch"` for schema_version byte or tier-range canary. */
|
|
59
62
|
function decodeAtomStatsBytes(data) {
|
|
60
63
|
if (data.length !== exports.ATOM_STATS_SIZE) {
|
|
61
|
-
return {
|
|
64
|
+
return {
|
|
65
|
+
error: `account size ${data.length} != expected ${exports.ATOM_STATS_SIZE}`,
|
|
66
|
+
errorCode: "size_mismatch",
|
|
67
|
+
};
|
|
62
68
|
}
|
|
63
69
|
const buf = data instanceof Buffer ? data : Buffer.from(data);
|
|
64
70
|
const schemaVersion = buf.readUInt8(exports.ATOM_STATS_SCHEMA_VERSION_OFFSET);
|
|
65
71
|
if (schemaVersion !== exports.ATOM_STATS_SCHEMA_VERSION_EXPECTED) {
|
|
66
|
-
return {
|
|
72
|
+
return {
|
|
73
|
+
error: `schema_version ${schemaVersion} != expected ${exports.ATOM_STATS_SCHEMA_VERSION_EXPECTED}`,
|
|
74
|
+
errorCode: "schema_mismatch",
|
|
75
|
+
};
|
|
67
76
|
}
|
|
68
77
|
const tierImmediate = buf.readUInt8(exports.ATOM_STATS_TIER_IMMEDIATE_OFFSET);
|
|
69
78
|
const tierConfirmed = buf.readUInt8(exports.ATOM_STATS_TIER_CONFIRMED_OFFSET);
|
|
70
79
|
const riskScore = buf.readUInt8(exports.ATOM_STATS_RISK_SCORE_OFFSET);
|
|
71
80
|
const confidence = buf.readUInt16LE(exports.ATOM_STATS_CONFIDENCE_OFFSET);
|
|
72
81
|
if (tierImmediate > exports.ATOM_TIER_MAX) {
|
|
73
|
-
return {
|
|
82
|
+
return {
|
|
83
|
+
error: `tier_immediate ${tierImmediate} > ATOM_TIER_MAX ${exports.ATOM_TIER_MAX}`,
|
|
84
|
+
errorCode: "schema_mismatch",
|
|
85
|
+
};
|
|
74
86
|
}
|
|
75
87
|
if (tierConfirmed > exports.ATOM_TIER_MAX) {
|
|
76
|
-
return {
|
|
88
|
+
return {
|
|
89
|
+
error: `tier_confirmed ${tierConfirmed} > ATOM_TIER_MAX ${exports.ATOM_TIER_MAX}`,
|
|
90
|
+
errorCode: "schema_mismatch",
|
|
91
|
+
};
|
|
77
92
|
}
|
|
78
93
|
return { tierImmediate, tierConfirmed, riskScore, confidence, schemaVersion };
|
|
79
94
|
}
|
|
@@ -102,9 +117,19 @@ exports.getQuantuReputationTool = {
|
|
|
102
117
|
};
|
|
103
118
|
if (!accountInfo)
|
|
104
119
|
return out;
|
|
120
|
+
// Owner check is a separate canary from the decode below — surface
|
|
121
|
+
// it with its own errorCode so an LLM can branch ("wrong_owner"
|
|
122
|
+
// typically means the user passed a pubkey that doesn't belong to
|
|
123
|
+
// Quantu, vs. "schema_mismatch" which means the Quantu IDL drifted).
|
|
124
|
+
if (!out.ownerMatches) {
|
|
125
|
+
out.error = `atom_stats decode failed: owner ${out.ownerProgram ?? "(null)"} != expected ${out.ownerExpected}`;
|
|
126
|
+
out.errorCode = "wrong_owner";
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
105
129
|
const decoded = decodeAtomStatsBytes(accountInfo.data);
|
|
106
130
|
if ("error" in decoded) {
|
|
107
131
|
out.error = `atom_stats decode failed: ${decoded.error}`;
|
|
132
|
+
out.errorCode = decoded.errorCode;
|
|
108
133
|
return out;
|
|
109
134
|
}
|
|
110
135
|
out.reputation = decoded;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-quantu-reputation.js","sourceRoot":"","sources":["../../../src/tools/read/get-quantu-reputation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;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,GAAG,CAAC,KAAK,GAAO,6BAA6B,OAAO,CAAC,KAAK,EAAE,CAAC;YAC7D,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;YAClC,OAAO,GAAG,CAAC;QACb,CAAC;QACD,GAAG,CAAC,UAAU,GAAG,OAAO,CAAC;QACzB,OAAO,GAAG,CAAC;IACb,CAAC;CACF,CAAC"}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.simulatePaymentTool = void 0;
|
|
11
11
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
12
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
12
13
|
const zod_1 = require("zod");
|
|
13
14
|
const chain_1 = require("../../chain");
|
|
14
15
|
const common_1 = require("../common");
|
|
@@ -30,21 +31,20 @@ exports.simulatePaymentTool = {
|
|
|
30
31
|
inputSchema: InputSchema,
|
|
31
32
|
async handler(input, ctx) {
|
|
32
33
|
const policyVault = await ctx.chain.policyVault();
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
34
|
+
// F-024: the SDK's simulateGatePayment threads the gate_payment ix
|
|
35
|
+
// through `simulateTransaction({ replaceRecentBlockhash: true,
|
|
36
|
+
// sigVerify: false })` — the RPC fills in a fresh blockhash and the
|
|
37
|
+
// signature check is skipped, so the fee-payer doesn't need to be
|
|
38
|
+
// funded for simulation to succeed. We pick the caller in priority
|
|
39
|
+
// order:
|
|
40
|
+
// 1. explicit input.caller arg (lets the user pin a known funded
|
|
41
|
+
// pubkey when they're auditing a specific deployment)
|
|
42
|
+
// 2. configured KEYPAIR_B58 signer pubkey (matches their identity)
|
|
43
|
+
// 3. an ephemeral throwaway pubkey — safe because sigVerify=false
|
|
44
|
+
// means the fee-payer never has to sign and is never debited.
|
|
45
45
|
const callerPubkey = input.caller
|
|
46
46
|
? (0, common_1.parsePubkey)(input.caller, "caller")
|
|
47
|
-
: ctx.chain.signerPubkey();
|
|
47
|
+
: (ctx.chain.signerPubkey() ?? web3_js_1.Keypair.generate().publicKey);
|
|
48
48
|
const decision = await (0, chain_1.simulateGatePayment)({
|
|
49
49
|
policyVault,
|
|
50
50
|
programIds: ctx.chain.cfg.programs,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simulate-payment.js","sourceRoot":"","sources":["../../../src/tools/read/simulate-payment.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,8CAAuC;AACvC,6BAAwB;AAExB,uCAAkD;AAClD,sCAAkE;AAGlE,MAAM,WAAW,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3B,WAAW,EAAE,qBAAY,CAAC,QAAQ,CAAC,0BAA0B,CAAC;IAC9D,WAAW,EAAE,qBAAY,CAAC,QAAQ,CAAC,0BAA0B,CAAC;IAC9D,MAAM,EAAO,OAAC,CAAC,KAAK,CAAC,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;SAChE,QAAQ,CAAC,6DAA6D,CAAC;IACxF,IAAI,EAAS,qBAAY,CAAC,QAAQ,CAAC,+BAA+B,CAAC;IACnE,SAAS,EAAI,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,uBAAuB,CAAC;IACtF,MAAM,EAAO,qBAAY,CAAC,QAAQ,EAAE;SACnB,QAAQ,CAAC,0FAA0F,CAAC;CACtH,CAAC,CAAC;AAQU,QAAA,mBAAmB,GAAgC;IAC9D,IAAI,EAAS,6BAA6B;IAC1C,WAAW,EACT,sEAAs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M,EAAE,UAAU,EAAE,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,QAAQ,CAAC,UAAU,EAAE,CAAC;QAC5F,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,IAAA,mBAAU,EAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;IAC/F,CAAC;CACF,CAAC"}
|
|
@@ -18,25 +18,25 @@ declare const InputSchema: z.ZodObject<{
|
|
|
18
18
|
payee_asset: z.ZodEffects<z.ZodString, string, string>;
|
|
19
19
|
base_collection: z.ZodEffects<z.ZodString, string, string>;
|
|
20
20
|
score: z.ZodNumber;
|
|
21
|
-
value: z.
|
|
22
|
-
value_decimals: z.
|
|
21
|
+
value: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
22
|
+
value_decimals: z.ZodOptional<z.ZodNumber>;
|
|
23
23
|
tag1: z.ZodDefault<z.ZodString>;
|
|
24
24
|
tag2: z.ZodDefault<z.ZodString>;
|
|
25
25
|
endpoint: z.ZodDefault<z.ZodString>;
|
|
26
26
|
feedback_uri: z.ZodDefault<z.ZodString>;
|
|
27
27
|
atom_enabled: z.ZodDefault<z.ZodBoolean>;
|
|
28
28
|
}, "strip", z.ZodTypeAny, {
|
|
29
|
-
value: string | number;
|
|
30
29
|
payment_id_hash_hex: string;
|
|
31
30
|
payee_asset: string;
|
|
32
31
|
base_collection: string;
|
|
33
32
|
score: number;
|
|
34
|
-
value_decimals: number;
|
|
35
33
|
tag1: string;
|
|
36
34
|
tag2: string;
|
|
37
35
|
endpoint: string;
|
|
38
36
|
feedback_uri: string;
|
|
39
37
|
atom_enabled: boolean;
|
|
38
|
+
value?: string | number | undefined;
|
|
39
|
+
value_decimals?: number | undefined;
|
|
40
40
|
}, {
|
|
41
41
|
payment_id_hash_hex: string;
|
|
42
42
|
payee_asset: string;
|
|
@@ -20,22 +20,47 @@ const zod_1 = require("zod");
|
|
|
20
20
|
const trustgate_1 = require("@agenttrust-sdk/trustgate");
|
|
21
21
|
const config_1 = require("../../config");
|
|
22
22
|
const common_1 = require("../common");
|
|
23
|
+
// Module-level guard so the warning fires once per process even if the
|
|
24
|
+
// tool is invoked many times (matches the F-051-style warn pattern used
|
|
25
|
+
// elsewhere in the package).
|
|
26
|
+
let warnedDefaults = false;
|
|
27
|
+
function warnDefaultsOnce() {
|
|
28
|
+
if (warnedDefaults)
|
|
29
|
+
return;
|
|
30
|
+
warnedDefaults = true;
|
|
31
|
+
process.stderr.write("[agenttrust] WARN agenttrust_emit_feedback: value and value_decimals " +
|
|
32
|
+
"defaulted to USDC (1_000_000 / 6 decimals). For non-USDC mints, pass " +
|
|
33
|
+
"explicit value and value_decimals. Otherwise Quantu quality_score " +
|
|
34
|
+
"accrues at the wrong magnitude.\n");
|
|
35
|
+
}
|
|
36
|
+
const DEFAULT_VALUE = "1000000";
|
|
37
|
+
const DEFAULT_VALUE_DECIMALS = 6;
|
|
23
38
|
const InputSchema = zod_1.z.object({
|
|
24
39
|
payment_id_hash_hex: common_1.HexHashSchema.describe("32-byte SHA-256 of the payment_id"),
|
|
25
40
|
payee_asset: common_1.PubkeySchema.describe("Quantu agent asset receiving feedback"),
|
|
26
|
-
base_collection: common_1.PubkeySchema.describe("Metaplex Core collection that owns the agent assets.
|
|
27
|
-
"agenttrust_demo_state.programs.base_collection.
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
41
|
+
base_collection: common_1.PubkeySchema.describe("Metaplex Core collection that owns the agent assets. Discovery paths. " +
|
|
42
|
+
"(1) demo runs use agenttrust_demo_state.programs.base_collection. " +
|
|
43
|
+
"(2) production reads the `collection` field on the agent's on-chain " +
|
|
44
|
+
"agent_account PDA at `[b\"agent\", asset]` under the Quantu " +
|
|
45
|
+
"agent_registry program (see agenttrust_get_quantu_reputation output " +
|
|
46
|
+
"for the agent's PDA + ownerProgram), or uses the value passed to " +
|
|
47
|
+
"agent_registry::register_agent when the agent was minted."),
|
|
31
48
|
score: zod_1.z.number().int().min(0).max(100),
|
|
32
49
|
// `value` + `value_decimals` are forwarded to Quantu's give_feedback so
|
|
33
50
|
// `quality_score` can accrue (otherwise tier_immediate stays pinned at 0).
|
|
34
51
|
// Default of 1_000_000 @ 6 decimals = $1 USDC equivalent, a sensible
|
|
35
52
|
// representative value when the caller doesn't have the real amount handy.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
53
|
+
// When the defaults fire (caller omitted both fields) the handler emits a
|
|
54
|
+
// one-time stderr warning so non-USDC integrations notice the magnitude
|
|
55
|
+
// mismatch — see warnDefaultsOnce() below.
|
|
56
|
+
value: zod_1.z.union([zod_1.z.string(), zod_1.z.number()]).optional().describe("Raw payment amount in base token units (u64). Forwarded to Quantu's " +
|
|
57
|
+
"give_feedback for quality_score accrual. When omitted, defaults to " +
|
|
58
|
+
"1_000_000 ($1 USDC) AND the tool logs a one-time stderr warning. " +
|
|
59
|
+
"For non-USDC mints, pass the explicit value to keep quality_score " +
|
|
60
|
+
"accrual at the right magnitude."),
|
|
61
|
+
value_decimals: zod_1.z.number().int().min(0).max(18).optional().describe("Decimal exponent of the mint backing `value`. When omitted, defaults " +
|
|
62
|
+
"to 6 (USDC) AND the tool logs a one-time stderr warning. Pass the " +
|
|
63
|
+
"real mint decimals for non-USDC integrations."),
|
|
39
64
|
tag1: zod_1.z.string().max(32).default(""),
|
|
40
65
|
tag2: zod_1.z.string().max(32).default(""),
|
|
41
66
|
endpoint: zod_1.z.string().max(64).default(""),
|
|
@@ -45,9 +70,13 @@ const InputSchema = zod_1.z.object({
|
|
|
45
70
|
exports.emitFeedbackTool = {
|
|
46
71
|
name: "agenttrust_emit_feedback",
|
|
47
72
|
description: "Emit ERC-8004 feedback for a confirmed payment. Facilitator-only: " +
|
|
48
|
-
"KEYPAIR_B58
|
|
73
|
+
"requires a signer (KEYPAIR_B58 / KEYPAIR_PATH / Solana CLI default) " +
|
|
74
|
+
"whose pubkey must equal the facilitator wallet whose TrustGateAuthority " +
|
|
49
75
|
"PDA is being signed. Threads Quantu agent_account/atom_stats accounts " +
|
|
50
|
-
"through remaining_accounts. Idempotent on payment_id_hash."
|
|
76
|
+
"through remaining_accounts. Idempotent on payment_id_hash. When `value` " +
|
|
77
|
+
"and `value_decimals` are both omitted the tool falls back to USDC " +
|
|
78
|
+
"defaults (1_000_000 / 6) and logs a one-time stderr warning. Pass " +
|
|
79
|
+
"explicit values for non-USDC mints.",
|
|
51
80
|
inputSchema: InputSchema,
|
|
52
81
|
async handler(input, ctx) {
|
|
53
82
|
const facilitator = ctx.chain.requireSigner();
|
|
@@ -75,9 +104,23 @@ exports.emitFeedbackTool = {
|
|
|
75
104
|
}
|
|
76
105
|
// Forward `value` + `value_decimals` so Quantu's give_feedback can
|
|
77
106
|
// accrue quality_score (drives tier_immediate promotion).
|
|
78
|
-
|
|
107
|
+
//
|
|
108
|
+
// When the caller omits BOTH fields we fall back to the USDC default
|
|
109
|
+
// (1_000_000 @ 6 decimals) AND emit a one-time stderr warning so
|
|
110
|
+
// non-USDC integrations notice the magnitude mismatch. Keeping the
|
|
111
|
+
// defaults non-breaking — callers that explicitly pass value or
|
|
112
|
+
// value_decimals get the literal values they asked for and no warn.
|
|
113
|
+
const valueOmitted = input.value === undefined;
|
|
114
|
+
const decimalsOmitted = input.value_decimals === undefined;
|
|
115
|
+
if (valueOmitted && decimalsOmitted)
|
|
116
|
+
warnDefaultsOnce();
|
|
117
|
+
const valueStr = input.value === undefined
|
|
118
|
+
? DEFAULT_VALUE
|
|
119
|
+
: (typeof input.value === "string" ? input.value : input.value.toString());
|
|
120
|
+
const valueDecimals = input.value_decimals ?? DEFAULT_VALUE_DECIMALS;
|
|
121
|
+
const valueBn = new anchor_1.BN(valueStr);
|
|
79
122
|
const txSignature = await trustgate.methods
|
|
80
|
-
.emitFeedback(Array.from(paymentIdHash), facilitator.publicKey, payeeAsset, input.score, valueBn,
|
|
123
|
+
.emitFeedback(Array.from(paymentIdHash), facilitator.publicKey, payeeAsset, input.score, valueBn, valueDecimals, input.tag1, input.tag2, input.endpoint, input.feedback_uri)
|
|
81
124
|
.accounts({
|
|
82
125
|
payer: facilitator.publicKey,
|
|
83
126
|
authority: authorityPda,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit-feedback.js","sourceRoot":"","sources":["../../../src/tools/write/emit-feedback.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAEH,8CAAuC;AACvC,6CAA2D;AAC3D,6BAAwB;AAExB,yDAOmC;AAEnC,yCAA2C;AAC3C,sCAAiF;AAGjF,MAAM,WAAW,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3B,mBAAmB,EAAE,sBAAa,CAAC,QAAQ,CAAC,mCAAmC,CAAC;IAChF,WAAW,EAAU,qBAAY,CAAC,QAAQ,CAAC,uCAAuC,CAAC;IACnF,eAAe,EAAM,qBAAY,CAAC,QAAQ,CACxC,
|
|
1
|
+
{"version":3,"file":"emit-feedback.js","sourceRoot":"","sources":["../../../src/tools/write/emit-feedback.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAEH,8CAAuC;AACvC,6CAA2D;AAC3D,6BAAwB;AAExB,yDAOmC;AAEnC,yCAA2C;AAC3C,sCAAiF;AAGjF,uEAAuE;AACvE,wEAAwE;AACxE,6BAA6B;AAC7B,IAAI,cAAc,GAAG,KAAK,CAAC;AAC3B,SAAS,gBAAgB;IACvB,IAAI,cAAc;QAAE,OAAO;IAC3B,cAAc,GAAG,IAAI,CAAC;IACtB,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,uEAAuE;QACvE,uEAAuE;QACvE,oEAAoE;QACpE,mCAAmC,CACpC,CAAC;AACJ,CAAC;AAED,MAAM,aAAa,GAAY,SAAS,CAAC;AACzC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAEjC,MAAM,WAAW,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3B,mBAAmB,EAAE,sBAAa,CAAC,QAAQ,CA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AAC,KAAK,CAAC,GAAG,EAAE,IAAI,EAAO,WAAW,CAAC;YACvE,cAAc,EAAO,cAAc,CAAC,QAAQ,EAAE;YAC9C,mBAAmB,EAAE,IAAA,oBAAW,EAAC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,cAAc,CAAC,QAAQ,EAAE,CAAC;SACtF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `agenttrust_init_authority` — create the `PolicyAuthority` PDA for an
|
|
3
|
+
* agent asset. Prerequisite for `init_policy` and `set_killswitch`.
|
|
4
|
+
*
|
|
5
|
+
* Defaults are tuned for the zero-friction first-use flow: omit
|
|
6
|
+
* `members` and `threshold` and the tool initialises a single-member
|
|
7
|
+
* authority with the signer as the sole member (threshold = 1). Pass
|
|
8
|
+
* explicit `members` + `threshold` to bootstrap a multisig.
|
|
9
|
+
*
|
|
10
|
+
* Idempotent: if the PolicyAuthority PDA already exists this tool
|
|
11
|
+
* returns the existing on-chain config rather than failing or
|
|
12
|
+
* overwriting. The existing account is the source of truth — callers
|
|
13
|
+
* that wanted different membership should burn it down via the
|
|
14
|
+
* appropriate (future) instruction rather than expect this tool to
|
|
15
|
+
* silently re-init.
|
|
16
|
+
*/
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
import type { Tool } from "../types";
|
|
19
|
+
declare const InputSchema: z.ZodObject<{
|
|
20
|
+
agent_asset: z.ZodEffects<z.ZodString, string, string>;
|
|
21
|
+
members: z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodString, string, string>, "many">>;
|
|
22
|
+
threshold: z.ZodOptional<z.ZodNumber>;
|
|
23
|
+
}, "strip", z.ZodTypeAny, {
|
|
24
|
+
agent_asset: string;
|
|
25
|
+
members?: string[] | undefined;
|
|
26
|
+
threshold?: number | undefined;
|
|
27
|
+
}, {
|
|
28
|
+
agent_asset: string;
|
|
29
|
+
members?: string[] | undefined;
|
|
30
|
+
threshold?: number | undefined;
|
|
31
|
+
}>;
|
|
32
|
+
type Input = z.infer<typeof InputSchema>;
|
|
33
|
+
interface Output {
|
|
34
|
+
txSignature: string | null;
|
|
35
|
+
explorerTxUrl: string | null;
|
|
36
|
+
authorityPda: string;
|
|
37
|
+
authorityExplorer: string;
|
|
38
|
+
members: string[];
|
|
39
|
+
threshold: number;
|
|
40
|
+
alreadyInitialized: boolean;
|
|
41
|
+
}
|
|
42
|
+
export declare const initAuthorityTool: Tool<Input, Output>;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `agenttrust_init_authority` — create the `PolicyAuthority` PDA for an
|
|
4
|
+
* agent asset. Prerequisite for `init_policy` and `set_killswitch`.
|
|
5
|
+
*
|
|
6
|
+
* Defaults are tuned for the zero-friction first-use flow: omit
|
|
7
|
+
* `members` and `threshold` and the tool initialises a single-member
|
|
8
|
+
* authority with the signer as the sole member (threshold = 1). Pass
|
|
9
|
+
* explicit `members` + `threshold` to bootstrap a multisig.
|
|
10
|
+
*
|
|
11
|
+
* Idempotent: if the PolicyAuthority PDA already exists this tool
|
|
12
|
+
* returns the existing on-chain config rather than failing or
|
|
13
|
+
* overwriting. The existing account is the source of truth — callers
|
|
14
|
+
* that wanted different membership should burn it down via the
|
|
15
|
+
* appropriate (future) instruction rather than expect this tool to
|
|
16
|
+
* silently re-init.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.initAuthorityTool = void 0;
|
|
20
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
21
|
+
const zod_1 = require("zod");
|
|
22
|
+
const config_1 = require("../../config");
|
|
23
|
+
const common_1 = require("../common");
|
|
24
|
+
const POLICY_AUTHORITY_PREFIX = Buffer.from("policy_authority");
|
|
25
|
+
const InputSchema = zod_1.z.object({
|
|
26
|
+
agent_asset: common_1.PubkeySchema.describe("Quantu agent asset the PolicyAuthority is being created for"),
|
|
27
|
+
members: zod_1.z.array(common_1.PubkeySchema).min(1).max(7).optional().describe("Authority members (1..=7 base58 pubkeys). Defaults to [<signer>] " +
|
|
28
|
+
"when omitted. The caller MUST be a member or init_policy is unreachable."),
|
|
29
|
+
threshold: zod_1.z.number().int().min(1).max(7).optional().describe("Signers required to authorise a multisig action (1..=members.length). " +
|
|
30
|
+
"Defaults to 1."),
|
|
31
|
+
});
|
|
32
|
+
exports.initAuthorityTool = {
|
|
33
|
+
name: "agenttrust_init_authority",
|
|
34
|
+
description: "Create the PolicyAuthority PDA for an agent. Required before " +
|
|
35
|
+
"init_policy or set_killswitch can succeed. Defaults to a single-member " +
|
|
36
|
+
"authority with the signer as sole member (threshold 1) for fastest " +
|
|
37
|
+
"bootstrap. Idempotent: a no-op if the PDA already exists, returning the " +
|
|
38
|
+
"current on-chain members + threshold.",
|
|
39
|
+
inputSchema: InputSchema,
|
|
40
|
+
async handler(input, ctx) {
|
|
41
|
+
const signer = ctx.chain.requireSigner();
|
|
42
|
+
const agent = (0, common_1.parsePubkey)(input.agent_asset, "agent_asset");
|
|
43
|
+
const policyVault = await ctx.chain.policyVault();
|
|
44
|
+
const members = (input.members ?? [signer.publicKey.toBase58()]).map((m, i) => (0, common_1.parsePubkey)(m, `members[${i}]`));
|
|
45
|
+
const threshold = input.threshold ?? 1;
|
|
46
|
+
if (threshold > members.length) {
|
|
47
|
+
throw new Error(`threshold (${threshold}) exceeds members.length (${members.length}).`);
|
|
48
|
+
}
|
|
49
|
+
if (!members.some((m) => m.equals(signer.publicKey))) {
|
|
50
|
+
throw new Error(`signer ${signer.publicKey.toBase58()} must be in members[] or ` +
|
|
51
|
+
`init_policy becomes unreachable for this agent.`);
|
|
52
|
+
}
|
|
53
|
+
const authorityPda = web3_js_1.PublicKey.findProgramAddressSync([POLICY_AUTHORITY_PREFIX, agent.toBuffer()], ctx.chain.cfg.programs.policyVault)[0];
|
|
54
|
+
// Idempotency: if the PDA already exists, return its on-chain state
|
|
55
|
+
// and skip the init. The existing account is the source of truth.
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
|
+
const existing = await policyVault.account.policyAuthority.fetchNullable(authorityPda);
|
|
58
|
+
if (existing) {
|
|
59
|
+
const onChainMembers = existing.members
|
|
60
|
+
.slice(0, Number(existing.memberCount ?? existing.member_count ?? members.length))
|
|
61
|
+
.map((m) => m.toBase58());
|
|
62
|
+
return {
|
|
63
|
+
txSignature: null,
|
|
64
|
+
explorerTxUrl: null,
|
|
65
|
+
authorityPda: authorityPda.toBase58(),
|
|
66
|
+
authorityExplorer: (0, config_1.explorerUrl)(ctx.chain.cfg, "address", authorityPda.toBase58()),
|
|
67
|
+
members: onChainMembers,
|
|
68
|
+
threshold: Number(existing.threshold ?? 0),
|
|
69
|
+
alreadyInitialized: true,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const txSignature = await policyVault.methods
|
|
73
|
+
.initAuthority(agent, members, threshold)
|
|
74
|
+
.accounts({
|
|
75
|
+
payer: signer.publicKey,
|
|
76
|
+
policyAuthority: authorityPda,
|
|
77
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
+
})
|
|
80
|
+
.rpc();
|
|
81
|
+
return {
|
|
82
|
+
txSignature,
|
|
83
|
+
explorerTxUrl: (0, config_1.explorerUrl)(ctx.chain.cfg, "tx", txSignature),
|
|
84
|
+
authorityPda: authorityPda.toBase58(),
|
|
85
|
+
authorityExplorer: (0, config_1.explorerUrl)(ctx.chain.cfg, "address", authorityPda.toBase58()),
|
|
86
|
+
members: members.map((m) => m.toBase58()),
|
|
87
|
+
threshold,
|
|
88
|
+
alreadyInitialized: false,
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=init-authority.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-authority.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-
* for the caller's `(agent_asset, policy_id)` pair.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* for the caller's `(agent_asset, policy_id)` pair.
|
|
4
|
+
*
|
|
5
|
+
* Self-healing: if the agent's `PolicyAuthority` PDA does not yet
|
|
6
|
+
* exist, the tool transparently prepends an `init_authority` instruction
|
|
7
|
+
* (single-member = signer, threshold = 1) and submits both in a single
|
|
8
|
+
* atomic transaction. The user never has to learn about Anchor 3012
|
|
9
|
+
* (AccountNotInitialized) or run a bootstrap script.
|
|
10
|
+
*
|
|
11
|
+
* Cap defaults: when the caller specifies ANY spending cap, unspecified
|
|
12
|
+
* peers default to the MAX of the specified caps rather than 0.
|
|
13
|
+
* Rationale: v1 policies are immutable post-init, so 0 (literal hard
|
|
14
|
+
* cap) is hostile — every gated payment fails with
|
|
15
|
+
* `SpendingPerTxExceeded`. The MAX-of-peers default keeps the explicit
|
|
16
|
+
* cap binding and leaves the others permissive.
|
|
6
17
|
*
|
|
7
18
|
* The full per-kind config is exposed as JSON; sane defaults zero every
|
|
8
19
|
* field so callers can incrementally enable kinds via the bitmask.
|
|
@@ -128,6 +139,15 @@ interface Output {
|
|
|
128
139
|
policyExplorer: string;
|
|
129
140
|
velocityPda: string;
|
|
130
141
|
velocityExplorer: string;
|
|
142
|
+
/** Effective spending caps actually written on-chain (after max-of-peers default-fill). */
|
|
143
|
+
effectiveSpending: {
|
|
144
|
+
perTxMax: string;
|
|
145
|
+
dailyMax: string;
|
|
146
|
+
weeklyMax: string;
|
|
147
|
+
};
|
|
148
|
+
/** True when the tool transparently bootstrapped PolicyAuthority in the same tx. */
|
|
149
|
+
selfHealed: boolean;
|
|
150
|
+
healedSteps: string[];
|
|
131
151
|
}
|
|
132
152
|
export declare const initPolicyTool: Tool<Input, Output>;
|
|
133
153
|
export {};
|