@agent-fuel/sdk 0.1.0 → 0.1.1
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/CHANGELOG.md +6 -0
- package/README.md +15 -2
- package/dist/idl/reputation.cjs +128 -1
- package/dist/idl/reputation.cjs.map +1 -1
- package/dist/idl/reputation.d.cts +128 -1
- package/dist/idl/reputation.d.ts +128 -1
- package/dist/idl/reputation.js +128 -1
- package/dist/idl/reputation.js.map +1 -1
- package/dist/index.cjs +258 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +52 -1
- package/dist/index.d.ts +52 -1
- package/dist/index.js +250 -2
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
package/dist/index.d.cts
CHANGED
|
@@ -108,6 +108,9 @@ declare class AgentFuel {
|
|
|
108
108
|
getPolicy(ref?: VaultRef): Promise<SpendPolicyAccount>;
|
|
109
109
|
checkService(serviceAuthority: Pubkeyish): Promise<ServiceRegistryAccount>;
|
|
110
110
|
spend(args: SpendArgs): Promise<SpendResult>;
|
|
111
|
+
computeScore(): Promise<{
|
|
112
|
+
signature: string;
|
|
113
|
+
}>;
|
|
111
114
|
onEvent(callback: (frame: LiveEventFrame) => void, options?: OnEventOptions): Subscription;
|
|
112
115
|
}
|
|
113
116
|
|
|
@@ -125,6 +128,16 @@ declare function createAssociatedTokenAccountIdempotentInstruction(payer: Public
|
|
|
125
128
|
declare function vaultPda(owner: Pubkeyish, agent: Pubkeyish): PublicKey;
|
|
126
129
|
declare function policyPda(vault: Pubkeyish): PublicKey;
|
|
127
130
|
declare function serviceRegistryPda(serviceAuthority: Pubkeyish): PublicKey;
|
|
131
|
+
declare function agentProfilePda(agent: Pubkeyish): PublicKey;
|
|
132
|
+
/** PDA used by `record_payment` to track the agent ↔ service pair. The seeds
|
|
133
|
+
* are the *PDAs* of the agent profile and service registry, not the raw
|
|
134
|
+
* authority pubkeys — match the on-chain Anchor account constraint. */
|
|
135
|
+
declare function agentServiceLinkPda(agentProfile: Pubkeyish, serviceRegistry: Pubkeyish): PublicKey;
|
|
136
|
+
/** Existence-as-signal: a `ReceiptUsed` PDA at `[b"receipt", hash]` proves
|
|
137
|
+
* the receipt has been recorded. `record_payment`'s `init` constraint (not
|
|
138
|
+
* `init_if_needed`) means a duplicate hash fails with `AccountAlreadyInUse`,
|
|
139
|
+
* which is the chain-side replay defence. */
|
|
140
|
+
declare function receiptUsedPda(receiptHash: Uint8Array): PublicKey;
|
|
128
141
|
|
|
129
142
|
declare class AgentFuelError extends Error {
|
|
130
143
|
constructor(message: string);
|
|
@@ -172,6 +185,44 @@ declare class NotWhitelistedError extends SpendPolicyError {
|
|
|
172
185
|
readonly service: string;
|
|
173
186
|
constructor(service: string);
|
|
174
187
|
}
|
|
188
|
+
declare class RecordPaymentError extends AgentFuelError {
|
|
189
|
+
constructor(message: string);
|
|
190
|
+
}
|
|
191
|
+
declare class ReceiptAlreadyRecordedError extends RecordPaymentError {
|
|
192
|
+
readonly receiptHash: Uint8Array;
|
|
193
|
+
constructor(receiptHash: Uint8Array);
|
|
194
|
+
}
|
|
195
|
+
declare class ServiceInactiveError extends RecordPaymentError {
|
|
196
|
+
readonly service: string;
|
|
197
|
+
constructor(service: string);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
type RecordPaymentArgs = {
|
|
201
|
+
/** Service authority keypair. Signs the tx and pays the fee. Must match
|
|
202
|
+
* the same keypair that was registered on chain as the service authority. */
|
|
203
|
+
service: Keypair;
|
|
204
|
+
/** Agent identity pubkey (NOT the AgentProfile PDA — we derive that). */
|
|
205
|
+
agent: Pubkeyish;
|
|
206
|
+
/** Amount in micro-USDC (1_000_000 = 1 USDC). */
|
|
207
|
+
amountUsdc: number;
|
|
208
|
+
/** 32-byte hash that uniquely identifies this payment. Common choice:
|
|
209
|
+
* `sha256(spendTxSignature)` — the spend signature is unique on chain,
|
|
210
|
+
* so its hash is too. The chain enforces single-use via `init` on the
|
|
211
|
+
* ReceiptUsed PDA; resubmitting the same hash fails with AccountAlreadyInUse. */
|
|
212
|
+
receiptHash: Uint8Array;
|
|
213
|
+
connection: Connection;
|
|
214
|
+
};
|
|
215
|
+
type RecordPaymentResult = {
|
|
216
|
+
signature: string;
|
|
217
|
+
};
|
|
218
|
+
declare function recordPayment(args: RecordPaymentArgs): Promise<RecordPaymentResult>;
|
|
219
|
+
|
|
220
|
+
type SubscribeOptions = {
|
|
221
|
+
onFrame: (frame: LiveEventFrame) => void;
|
|
222
|
+
onStatus?: (status: LiveStatus) => void;
|
|
223
|
+
};
|
|
224
|
+
declare function subscribeService(apiBase: string, servicePubkey: string, opts: SubscribeOptions): Subscription;
|
|
225
|
+
declare function subscribeVault(apiBase: string, vaultPubkey: string, opts: SubscribeOptions): Subscription;
|
|
175
226
|
|
|
176
227
|
type PaymentRequirement = {
|
|
177
228
|
recipient: string;
|
|
@@ -190,4 +241,4 @@ declare class PaymentParseError extends AgentFuelError {
|
|
|
190
241
|
}
|
|
191
242
|
declare function paymentRequired(fuel: AgentFuel, opts?: PaymentRequiredOptions): FetchLike;
|
|
192
243
|
|
|
193
|
-
export { ASSOCIATED_TOKEN_PROGRAM_ID, AccountNotFoundError, AgentFuel, AgentFuelError, type AgentFuelOptions, type Cluster, type CreditVaultAccount, type FetchLike, HourlyLimitExceededError, HttpError, LifetimeLimitExceededError, type LiveEventFrame, type LiveStatus, NotWhitelistedError, type OnEventOptions, OwnerNotConfiguredError, PROGRAM_IDS, PaymentParseError, type PaymentRequiredOptions, type PaymentRequirement, PerTxLimitExceededError, type Pubkeyish, type ReputationLookup, SLOTS_PER_HOUR, type ServiceCategory, type ServiceRegistryAccount, type SpendArgs, type SpendPolicyAccount, SpendPolicyError, type SpendResult, type Subscription, TOKEN_PROGRAM_ID, VaultFrozenError, type VaultRef, ZeroAmountError, createAssociatedTokenAccountIdempotentInstruction, getAssociatedTokenAddress, paymentRequired, policyPda, serviceRegistryPda, vaultPda };
|
|
244
|
+
export { ASSOCIATED_TOKEN_PROGRAM_ID, AccountNotFoundError, AgentFuel, AgentFuelError, type AgentFuelOptions, type Cluster, type CreditVaultAccount, type FetchLike, HourlyLimitExceededError, HttpError, LifetimeLimitExceededError, type LiveEventFrame, type LiveStatus, NotWhitelistedError, type OnEventOptions, OwnerNotConfiguredError, PROGRAM_IDS, PaymentParseError, type PaymentRequiredOptions, type PaymentRequirement, PerTxLimitExceededError, type Pubkeyish, ReceiptAlreadyRecordedError, type RecordPaymentArgs, RecordPaymentError, type RecordPaymentResult, type ReputationLookup, SLOTS_PER_HOUR, type ServiceCategory, ServiceInactiveError, type ServiceRegistryAccount, type SpendArgs, type SpendPolicyAccount, SpendPolicyError, type SpendResult, type SubscribeOptions, type Subscription, TOKEN_PROGRAM_ID, VaultFrozenError, type VaultRef, ZeroAmountError, agentProfilePda, agentServiceLinkPda, createAssociatedTokenAccountIdempotentInstruction, getAssociatedTokenAddress, paymentRequired, policyPda, receiptUsedPda, recordPayment, serviceRegistryPda, subscribeService, subscribeVault, vaultPda };
|
package/dist/index.d.ts
CHANGED
|
@@ -108,6 +108,9 @@ declare class AgentFuel {
|
|
|
108
108
|
getPolicy(ref?: VaultRef): Promise<SpendPolicyAccount>;
|
|
109
109
|
checkService(serviceAuthority: Pubkeyish): Promise<ServiceRegistryAccount>;
|
|
110
110
|
spend(args: SpendArgs): Promise<SpendResult>;
|
|
111
|
+
computeScore(): Promise<{
|
|
112
|
+
signature: string;
|
|
113
|
+
}>;
|
|
111
114
|
onEvent(callback: (frame: LiveEventFrame) => void, options?: OnEventOptions): Subscription;
|
|
112
115
|
}
|
|
113
116
|
|
|
@@ -125,6 +128,16 @@ declare function createAssociatedTokenAccountIdempotentInstruction(payer: Public
|
|
|
125
128
|
declare function vaultPda(owner: Pubkeyish, agent: Pubkeyish): PublicKey;
|
|
126
129
|
declare function policyPda(vault: Pubkeyish): PublicKey;
|
|
127
130
|
declare function serviceRegistryPda(serviceAuthority: Pubkeyish): PublicKey;
|
|
131
|
+
declare function agentProfilePda(agent: Pubkeyish): PublicKey;
|
|
132
|
+
/** PDA used by `record_payment` to track the agent ↔ service pair. The seeds
|
|
133
|
+
* are the *PDAs* of the agent profile and service registry, not the raw
|
|
134
|
+
* authority pubkeys — match the on-chain Anchor account constraint. */
|
|
135
|
+
declare function agentServiceLinkPda(agentProfile: Pubkeyish, serviceRegistry: Pubkeyish): PublicKey;
|
|
136
|
+
/** Existence-as-signal: a `ReceiptUsed` PDA at `[b"receipt", hash]` proves
|
|
137
|
+
* the receipt has been recorded. `record_payment`'s `init` constraint (not
|
|
138
|
+
* `init_if_needed`) means a duplicate hash fails with `AccountAlreadyInUse`,
|
|
139
|
+
* which is the chain-side replay defence. */
|
|
140
|
+
declare function receiptUsedPda(receiptHash: Uint8Array): PublicKey;
|
|
128
141
|
|
|
129
142
|
declare class AgentFuelError extends Error {
|
|
130
143
|
constructor(message: string);
|
|
@@ -172,6 +185,44 @@ declare class NotWhitelistedError extends SpendPolicyError {
|
|
|
172
185
|
readonly service: string;
|
|
173
186
|
constructor(service: string);
|
|
174
187
|
}
|
|
188
|
+
declare class RecordPaymentError extends AgentFuelError {
|
|
189
|
+
constructor(message: string);
|
|
190
|
+
}
|
|
191
|
+
declare class ReceiptAlreadyRecordedError extends RecordPaymentError {
|
|
192
|
+
readonly receiptHash: Uint8Array;
|
|
193
|
+
constructor(receiptHash: Uint8Array);
|
|
194
|
+
}
|
|
195
|
+
declare class ServiceInactiveError extends RecordPaymentError {
|
|
196
|
+
readonly service: string;
|
|
197
|
+
constructor(service: string);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
type RecordPaymentArgs = {
|
|
201
|
+
/** Service authority keypair. Signs the tx and pays the fee. Must match
|
|
202
|
+
* the same keypair that was registered on chain as the service authority. */
|
|
203
|
+
service: Keypair;
|
|
204
|
+
/** Agent identity pubkey (NOT the AgentProfile PDA — we derive that). */
|
|
205
|
+
agent: Pubkeyish;
|
|
206
|
+
/** Amount in micro-USDC (1_000_000 = 1 USDC). */
|
|
207
|
+
amountUsdc: number;
|
|
208
|
+
/** 32-byte hash that uniquely identifies this payment. Common choice:
|
|
209
|
+
* `sha256(spendTxSignature)` — the spend signature is unique on chain,
|
|
210
|
+
* so its hash is too. The chain enforces single-use via `init` on the
|
|
211
|
+
* ReceiptUsed PDA; resubmitting the same hash fails with AccountAlreadyInUse. */
|
|
212
|
+
receiptHash: Uint8Array;
|
|
213
|
+
connection: Connection;
|
|
214
|
+
};
|
|
215
|
+
type RecordPaymentResult = {
|
|
216
|
+
signature: string;
|
|
217
|
+
};
|
|
218
|
+
declare function recordPayment(args: RecordPaymentArgs): Promise<RecordPaymentResult>;
|
|
219
|
+
|
|
220
|
+
type SubscribeOptions = {
|
|
221
|
+
onFrame: (frame: LiveEventFrame) => void;
|
|
222
|
+
onStatus?: (status: LiveStatus) => void;
|
|
223
|
+
};
|
|
224
|
+
declare function subscribeService(apiBase: string, servicePubkey: string, opts: SubscribeOptions): Subscription;
|
|
225
|
+
declare function subscribeVault(apiBase: string, vaultPubkey: string, opts: SubscribeOptions): Subscription;
|
|
175
226
|
|
|
176
227
|
type PaymentRequirement = {
|
|
177
228
|
recipient: string;
|
|
@@ -190,4 +241,4 @@ declare class PaymentParseError extends AgentFuelError {
|
|
|
190
241
|
}
|
|
191
242
|
declare function paymentRequired(fuel: AgentFuel, opts?: PaymentRequiredOptions): FetchLike;
|
|
192
243
|
|
|
193
|
-
export { ASSOCIATED_TOKEN_PROGRAM_ID, AccountNotFoundError, AgentFuel, AgentFuelError, type AgentFuelOptions, type Cluster, type CreditVaultAccount, type FetchLike, HourlyLimitExceededError, HttpError, LifetimeLimitExceededError, type LiveEventFrame, type LiveStatus, NotWhitelistedError, type OnEventOptions, OwnerNotConfiguredError, PROGRAM_IDS, PaymentParseError, type PaymentRequiredOptions, type PaymentRequirement, PerTxLimitExceededError, type Pubkeyish, type ReputationLookup, SLOTS_PER_HOUR, type ServiceCategory, type ServiceRegistryAccount, type SpendArgs, type SpendPolicyAccount, SpendPolicyError, type SpendResult, type Subscription, TOKEN_PROGRAM_ID, VaultFrozenError, type VaultRef, ZeroAmountError, createAssociatedTokenAccountIdempotentInstruction, getAssociatedTokenAddress, paymentRequired, policyPda, serviceRegistryPda, vaultPda };
|
|
244
|
+
export { ASSOCIATED_TOKEN_PROGRAM_ID, AccountNotFoundError, AgentFuel, AgentFuelError, type AgentFuelOptions, type Cluster, type CreditVaultAccount, type FetchLike, HourlyLimitExceededError, HttpError, LifetimeLimitExceededError, type LiveEventFrame, type LiveStatus, NotWhitelistedError, type OnEventOptions, OwnerNotConfiguredError, PROGRAM_IDS, PaymentParseError, type PaymentRequiredOptions, type PaymentRequirement, PerTxLimitExceededError, type Pubkeyish, ReceiptAlreadyRecordedError, type RecordPaymentArgs, RecordPaymentError, type RecordPaymentResult, type ReputationLookup, SLOTS_PER_HOUR, type ServiceCategory, ServiceInactiveError, type ServiceRegistryAccount, type SpendArgs, type SpendPolicyAccount, SpendPolicyError, type SpendResult, type SubscribeOptions, type Subscription, TOKEN_PROGRAM_ID, VaultFrozenError, type VaultRef, ZeroAmountError, agentProfilePda, agentServiceLinkPda, createAssociatedTokenAccountIdempotentInstruction, getAssociatedTokenAddress, paymentRequired, policyPda, receiptUsedPda, recordPayment, serviceRegistryPda, subscribeService, subscribeVault, vaultPda };
|
package/dist/index.js
CHANGED
|
@@ -185,6 +185,28 @@ var NotWhitelistedError = class extends SpendPolicyError {
|
|
|
185
185
|
this.service = service;
|
|
186
186
|
}
|
|
187
187
|
};
|
|
188
|
+
var RecordPaymentError = class extends AgentFuelError {
|
|
189
|
+
constructor(message) {
|
|
190
|
+
super(message);
|
|
191
|
+
this.name = "RecordPaymentError";
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
var ReceiptAlreadyRecordedError = class extends RecordPaymentError {
|
|
195
|
+
receiptHash;
|
|
196
|
+
constructor(receiptHash) {
|
|
197
|
+
super("payment receipt was already recorded on chain");
|
|
198
|
+
this.name = "ReceiptAlreadyRecordedError";
|
|
199
|
+
this.receiptHash = receiptHash;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
var ServiceInactiveError = class extends RecordPaymentError {
|
|
203
|
+
service;
|
|
204
|
+
constructor(service) {
|
|
205
|
+
super(`service ${service} is paused; record_payment rejected`);
|
|
206
|
+
this.name = "ServiceInactiveError";
|
|
207
|
+
this.service = service;
|
|
208
|
+
}
|
|
209
|
+
};
|
|
188
210
|
|
|
189
211
|
// src/guardrails.ts
|
|
190
212
|
function guardSpend(args) {
|
|
@@ -292,6 +314,12 @@ function wsUrl(apiBase, path) {
|
|
|
292
314
|
if (apiBase.startsWith("http://")) return apiBase.replace(/^http/, "ws") + path;
|
|
293
315
|
return apiBase + path;
|
|
294
316
|
}
|
|
317
|
+
function subscribeService(apiBase, servicePubkey, opts) {
|
|
318
|
+
return subscribe(wsUrl(apiBase, `/ws/services/${servicePubkey}`), opts);
|
|
319
|
+
}
|
|
320
|
+
function subscribeVault(apiBase, vaultPubkey, opts) {
|
|
321
|
+
return subscribe(wsUrl(apiBase, `/ws/vaults/${vaultPubkey}`), opts);
|
|
322
|
+
}
|
|
295
323
|
|
|
296
324
|
// src/idl/reputation.json
|
|
297
325
|
var reputation_default = {
|
|
@@ -847,10 +875,14 @@ var reputation_default = {
|
|
|
847
875
|
],
|
|
848
876
|
accounts: [
|
|
849
877
|
{
|
|
850
|
-
name: "
|
|
878
|
+
name: "sponsor",
|
|
851
879
|
writable: true,
|
|
852
880
|
signer: true
|
|
853
881
|
},
|
|
882
|
+
{
|
|
883
|
+
name: "service",
|
|
884
|
+
signer: true
|
|
885
|
+
},
|
|
854
886
|
{
|
|
855
887
|
name: "service_registry",
|
|
856
888
|
writable: true,
|
|
@@ -897,6 +929,15 @@ var reputation_default = {
|
|
|
897
929
|
name: "ServiceCategory"
|
|
898
930
|
}
|
|
899
931
|
}
|
|
932
|
+
},
|
|
933
|
+
{
|
|
934
|
+
name: "service_uri",
|
|
935
|
+
type: {
|
|
936
|
+
array: [
|
|
937
|
+
"u8",
|
|
938
|
+
128
|
|
939
|
+
]
|
|
940
|
+
}
|
|
900
941
|
}
|
|
901
942
|
]
|
|
902
943
|
},
|
|
@@ -1012,6 +1053,61 @@ var reputation_default = {
|
|
|
1012
1053
|
}
|
|
1013
1054
|
}
|
|
1014
1055
|
]
|
|
1056
|
+
},
|
|
1057
|
+
{
|
|
1058
|
+
name: "set_service_active",
|
|
1059
|
+
discriminator: [
|
|
1060
|
+
221,
|
|
1061
|
+
172,
|
|
1062
|
+
149,
|
|
1063
|
+
49,
|
|
1064
|
+
212,
|
|
1065
|
+
184,
|
|
1066
|
+
77,
|
|
1067
|
+
101
|
|
1068
|
+
],
|
|
1069
|
+
accounts: [
|
|
1070
|
+
{
|
|
1071
|
+
name: "service",
|
|
1072
|
+
signer: true
|
|
1073
|
+
},
|
|
1074
|
+
{
|
|
1075
|
+
name: "service_registry",
|
|
1076
|
+
writable: true,
|
|
1077
|
+
pda: {
|
|
1078
|
+
seeds: [
|
|
1079
|
+
{
|
|
1080
|
+
kind: "const",
|
|
1081
|
+
value: [
|
|
1082
|
+
115,
|
|
1083
|
+
101,
|
|
1084
|
+
114,
|
|
1085
|
+
118,
|
|
1086
|
+
105,
|
|
1087
|
+
99,
|
|
1088
|
+
101
|
|
1089
|
+
]
|
|
1090
|
+
},
|
|
1091
|
+
{
|
|
1092
|
+
kind: "account",
|
|
1093
|
+
path: "service"
|
|
1094
|
+
}
|
|
1095
|
+
]
|
|
1096
|
+
}
|
|
1097
|
+
},
|
|
1098
|
+
{
|
|
1099
|
+
name: "authority",
|
|
1100
|
+
relations: [
|
|
1101
|
+
"service_registry"
|
|
1102
|
+
]
|
|
1103
|
+
}
|
|
1104
|
+
],
|
|
1105
|
+
args: [
|
|
1106
|
+
{
|
|
1107
|
+
name: "active",
|
|
1108
|
+
type: "bool"
|
|
1109
|
+
}
|
|
1110
|
+
]
|
|
1015
1111
|
}
|
|
1016
1112
|
],
|
|
1017
1113
|
accounts: [
|
|
@@ -1160,6 +1256,19 @@ var reputation_default = {
|
|
|
1160
1256
|
109
|
|
1161
1257
|
]
|
|
1162
1258
|
},
|
|
1259
|
+
{
|
|
1260
|
+
name: "ServiceActiveSet",
|
|
1261
|
+
discriminator: [
|
|
1262
|
+
151,
|
|
1263
|
+
122,
|
|
1264
|
+
7,
|
|
1265
|
+
40,
|
|
1266
|
+
191,
|
|
1267
|
+
139,
|
|
1268
|
+
237,
|
|
1269
|
+
52
|
|
1270
|
+
]
|
|
1271
|
+
},
|
|
1163
1272
|
{
|
|
1164
1273
|
name: "ServiceRegistered",
|
|
1165
1274
|
discriminator: [
|
|
@@ -1224,6 +1333,11 @@ var reputation_default = {
|
|
|
1224
1333
|
code: 6009,
|
|
1225
1334
|
name: "FeedbackRateLimited",
|
|
1226
1335
|
msg: "Feedback rate limit not yet expired for this (service, agent) pair"
|
|
1336
|
+
},
|
|
1337
|
+
{
|
|
1338
|
+
code: 6010,
|
|
1339
|
+
name: "UnauthorizedService",
|
|
1340
|
+
msg: "Only the service authority may perform this action"
|
|
1227
1341
|
}
|
|
1228
1342
|
],
|
|
1229
1343
|
types: [
|
|
@@ -1664,6 +1778,26 @@ var reputation_default = {
|
|
|
1664
1778
|
]
|
|
1665
1779
|
}
|
|
1666
1780
|
},
|
|
1781
|
+
{
|
|
1782
|
+
name: "ServiceActiveSet",
|
|
1783
|
+
type: {
|
|
1784
|
+
kind: "struct",
|
|
1785
|
+
fields: [
|
|
1786
|
+
{
|
|
1787
|
+
name: "service",
|
|
1788
|
+
type: "pubkey"
|
|
1789
|
+
},
|
|
1790
|
+
{
|
|
1791
|
+
name: "active",
|
|
1792
|
+
type: "bool"
|
|
1793
|
+
},
|
|
1794
|
+
{
|
|
1795
|
+
name: "slot",
|
|
1796
|
+
type: "u64"
|
|
1797
|
+
}
|
|
1798
|
+
]
|
|
1799
|
+
}
|
|
1800
|
+
},
|
|
1667
1801
|
{
|
|
1668
1802
|
name: "ServiceCategory",
|
|
1669
1803
|
type: {
|
|
@@ -1696,6 +1830,14 @@ var reputation_default = {
|
|
|
1696
1830
|
name: "service",
|
|
1697
1831
|
type: "pubkey"
|
|
1698
1832
|
},
|
|
1833
|
+
{
|
|
1834
|
+
name: "sponsor",
|
|
1835
|
+
docs: [
|
|
1836
|
+
'Wallet that paid rent. Lets us answer "who registered this service?"',
|
|
1837
|
+
"without an extra column on the on-chain account."
|
|
1838
|
+
],
|
|
1839
|
+
type: "pubkey"
|
|
1840
|
+
},
|
|
1699
1841
|
{
|
|
1700
1842
|
name: "name",
|
|
1701
1843
|
type: {
|
|
@@ -1738,6 +1880,19 @@ var reputation_default = {
|
|
|
1738
1880
|
]
|
|
1739
1881
|
}
|
|
1740
1882
|
},
|
|
1883
|
+
{
|
|
1884
|
+
name: "service_uri",
|
|
1885
|
+
docs: [
|
|
1886
|
+
"Off-chain metadata URI (pricing, docs, endpoint, logo). Padded to 128 bytes;",
|
|
1887
|
+
"trailing NULs are trimmed when read. Mirrors `AgentProfile::agent_uri`."
|
|
1888
|
+
],
|
|
1889
|
+
type: {
|
|
1890
|
+
array: [
|
|
1891
|
+
"u8",
|
|
1892
|
+
128
|
|
1893
|
+
]
|
|
1894
|
+
}
|
|
1895
|
+
},
|
|
1741
1896
|
{
|
|
1742
1897
|
name: "category",
|
|
1743
1898
|
type: {
|
|
@@ -3094,6 +3249,34 @@ function serviceRegistryPda(serviceAuthority) {
|
|
|
3094
3249
|
);
|
|
3095
3250
|
return pda;
|
|
3096
3251
|
}
|
|
3252
|
+
function agentProfilePda(agent) {
|
|
3253
|
+
const [pda] = PublicKey.findProgramAddressSync(
|
|
3254
|
+
[Buffer.from("agent"), toPubkey(agent).toBuffer()],
|
|
3255
|
+
PROGRAM_IDS.reputation
|
|
3256
|
+
);
|
|
3257
|
+
return pda;
|
|
3258
|
+
}
|
|
3259
|
+
function agentServiceLinkPda(agentProfile, serviceRegistry) {
|
|
3260
|
+
const [pda] = PublicKey.findProgramAddressSync(
|
|
3261
|
+
[
|
|
3262
|
+
Buffer.from("link"),
|
|
3263
|
+
toPubkey(agentProfile).toBuffer(),
|
|
3264
|
+
toPubkey(serviceRegistry).toBuffer()
|
|
3265
|
+
],
|
|
3266
|
+
PROGRAM_IDS.reputation
|
|
3267
|
+
);
|
|
3268
|
+
return pda;
|
|
3269
|
+
}
|
|
3270
|
+
function receiptUsedPda(receiptHash) {
|
|
3271
|
+
if (receiptHash.length !== 32) {
|
|
3272
|
+
throw new Error(`receiptUsedPda expects a 32-byte hash, got ${receiptHash.length}`);
|
|
3273
|
+
}
|
|
3274
|
+
const [pda] = PublicKey.findProgramAddressSync(
|
|
3275
|
+
[Buffer.from("receipt"), Buffer.from(receiptHash)],
|
|
3276
|
+
PROGRAM_IDS.reputation
|
|
3277
|
+
);
|
|
3278
|
+
return pda;
|
|
3279
|
+
}
|
|
3097
3280
|
function buildProvider(connection, keypair) {
|
|
3098
3281
|
return new AnchorProvider(connection, new Wallet(keypair), AnchorProvider.defaultOptions());
|
|
3099
3282
|
}
|
|
@@ -3202,6 +3385,21 @@ var AgentFuel = class {
|
|
|
3202
3385
|
throw mapSpendError(err, { service, amountUsdc, vault, policy });
|
|
3203
3386
|
}
|
|
3204
3387
|
}
|
|
3388
|
+
/// Triggers an on-chain recomputation of the agent's reputation score.
|
|
3389
|
+
/// Permissionless — any signer can call it; we use the agent itself since
|
|
3390
|
+
/// the SDK already has its keypair available and it already pays tx fees
|
|
3391
|
+
/// for spends. The instruction reads the agent's already-public counters
|
|
3392
|
+
/// (volume, diversity, streak, tenure, feedback), recalculates the score
|
|
3393
|
+
/// to a single u16 ≤ 1000, and emits a `ScoreComputed` event. The webhook
|
|
3394
|
+
/// picks that up; the next `getScore()` returns the fresh value.
|
|
3395
|
+
async computeScore() {
|
|
3396
|
+
const profile = agentProfilePda(this.agentPubkey);
|
|
3397
|
+
const signature = await this.reputation.methods.computeScore().accounts({
|
|
3398
|
+
caller: this.agentPubkey,
|
|
3399
|
+
agentProfile: profile
|
|
3400
|
+
}).signers([this.agent]).rpc();
|
|
3401
|
+
return { signature };
|
|
3402
|
+
}
|
|
3205
3403
|
onEvent(callback, options) {
|
|
3206
3404
|
const target = options?.agent ? toPubkey(options.agent) : this.agentPubkey;
|
|
3207
3405
|
const url = wsUrl(this.apiBase, `/ws/agents/${target.toBase58()}`);
|
|
@@ -3246,6 +3444,56 @@ async function safeText(res) {
|
|
|
3246
3444
|
return void 0;
|
|
3247
3445
|
}
|
|
3248
3446
|
}
|
|
3447
|
+
async function recordPayment(args) {
|
|
3448
|
+
const { service, connection, amountUsdc } = args;
|
|
3449
|
+
const agentPubkey = toPubkey(args.agent);
|
|
3450
|
+
if (amountUsdc <= 0) {
|
|
3451
|
+
throw new Error("recordPayment: amountUsdc must be > 0");
|
|
3452
|
+
}
|
|
3453
|
+
if (args.receiptHash.length !== 32) {
|
|
3454
|
+
throw new Error(
|
|
3455
|
+
`recordPayment: receiptHash must be 32 bytes, got ${args.receiptHash.length}`
|
|
3456
|
+
);
|
|
3457
|
+
}
|
|
3458
|
+
const provider = buildProvider(connection, service);
|
|
3459
|
+
const program = reputationProgram(provider);
|
|
3460
|
+
const agentProfile = agentProfilePda(agentPubkey);
|
|
3461
|
+
const serviceRegistry = serviceRegistryPda(service.publicKey);
|
|
3462
|
+
const link = agentServiceLinkPda(agentProfile, serviceRegistry);
|
|
3463
|
+
const receipt = receiptUsedPda(args.receiptHash);
|
|
3464
|
+
try {
|
|
3465
|
+
const signature = await program.methods.recordPayment(new BN(amountUsdc), args.receiptHash).accounts({
|
|
3466
|
+
service: service.publicKey,
|
|
3467
|
+
agentProfile,
|
|
3468
|
+
serviceRegistry,
|
|
3469
|
+
agentServiceLink: link,
|
|
3470
|
+
receiptUsed: receipt,
|
|
3471
|
+
systemProgram: SystemProgram.programId
|
|
3472
|
+
}).signers([service]).rpc();
|
|
3473
|
+
return { signature };
|
|
3474
|
+
} catch (err) {
|
|
3475
|
+
throw mapRecordPaymentError(err, args.receiptHash);
|
|
3476
|
+
}
|
|
3477
|
+
}
|
|
3478
|
+
function mapRecordPaymentError(err, receiptHash) {
|
|
3479
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
3480
|
+
if (/already in use/i.test(message)) {
|
|
3481
|
+
return new ReceiptAlreadyRecordedError(receiptHash);
|
|
3482
|
+
}
|
|
3483
|
+
if (!(err instanceof AnchorError)) return err;
|
|
3484
|
+
switch (err.error.errorCode.number) {
|
|
3485
|
+
case 6e3:
|
|
3486
|
+
return new RecordPaymentError("counter overflow on chain");
|
|
3487
|
+
case 6001:
|
|
3488
|
+
return new ServiceInactiveError(
|
|
3489
|
+
err.error.origin?.toString() ?? "<unknown service>"
|
|
3490
|
+
);
|
|
3491
|
+
case 6002:
|
|
3492
|
+
return new ZeroAmountError();
|
|
3493
|
+
default:
|
|
3494
|
+
return err;
|
|
3495
|
+
}
|
|
3496
|
+
}
|
|
3249
3497
|
|
|
3250
3498
|
// src/x402.ts
|
|
3251
3499
|
var HEADER = "X-Payment-Required";
|
|
@@ -3332,6 +3580,6 @@ function truncate(s) {
|
|
|
3332
3580
|
return s.length > 80 ? `${s.slice(0, 80)}\u2026` : s;
|
|
3333
3581
|
}
|
|
3334
3582
|
|
|
3335
|
-
export { ASSOCIATED_TOKEN_PROGRAM_ID, AccountNotFoundError, AgentFuel, AgentFuelError, HourlyLimitExceededError, HttpError, LifetimeLimitExceededError, NotWhitelistedError, OwnerNotConfiguredError, PROGRAM_IDS, PaymentParseError, PerTxLimitExceededError, SLOTS_PER_HOUR, SpendPolicyError, TOKEN_PROGRAM_ID, VaultFrozenError, ZeroAmountError, createAssociatedTokenAccountIdempotentInstruction, getAssociatedTokenAddress, paymentRequired, policyPda, serviceRegistryPda, vaultPda };
|
|
3583
|
+
export { ASSOCIATED_TOKEN_PROGRAM_ID, AccountNotFoundError, AgentFuel, AgentFuelError, HourlyLimitExceededError, HttpError, LifetimeLimitExceededError, NotWhitelistedError, OwnerNotConfiguredError, PROGRAM_IDS, PaymentParseError, PerTxLimitExceededError, ReceiptAlreadyRecordedError, RecordPaymentError, SLOTS_PER_HOUR, ServiceInactiveError, SpendPolicyError, TOKEN_PROGRAM_ID, VaultFrozenError, ZeroAmountError, agentProfilePda, agentServiceLinkPda, createAssociatedTokenAccountIdempotentInstruction, getAssociatedTokenAddress, paymentRequired, policyPda, receiptUsedPda, recordPayment, serviceRegistryPda, subscribeService, subscribeVault, vaultPda };
|
|
3336
3584
|
//# sourceMappingURL=index.js.map
|
|
3337
3585
|
//# sourceMappingURL=index.js.map
|