@agentkarma/sdk 0.1.0
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/LICENSE +21 -0
- package/README.md +216 -0
- package/dist/client.d.ts +64 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +323 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +64 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +78 -0
- package/dist/errors.js.map +1 -0
- package/dist/feedback.d.ts +31 -0
- package/dist/feedback.d.ts.map +1 -0
- package/dist/feedback.js +35 -0
- package/dist/feedback.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/policy.d.ts +105 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +150 -0
- package/dist/policy.js.map +1 -0
- package/dist/types.d.ts +347 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -0
- package/src/client.ts +519 -0
- package/src/errors.ts +87 -0
- package/src/feedback.ts +51 -0
- package/src/index.ts +84 -0
- package/src/policy.ts +286 -0
- package/src/types.ts +406 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for the AgentKarma SDK.
|
|
3
|
+
*
|
|
4
|
+
* Response shapes mirror what `agentkarma.io/api/v2/*` returns today. The
|
|
5
|
+
* server promises stability under added keys, so SDK consumers can rely on
|
|
6
|
+
* the documented fields and treat extra keys as forward-compatible additions.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// ─── Primitives ───────────────────────────────────────────────────────────────
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Chains AgentKarma indexes. Bonds and successions span all of them, so the
|
|
13
|
+
* chain-aware methods take this explicitly rather than inferring it from the
|
|
14
|
+
* address (NEVER auto-detect an EVM chain from an address — see the project
|
|
15
|
+
* multi-chain invariant). Solana keeps its base58 validation; the other chains
|
|
16
|
+
* are passed through to the server, which keys by the composite (chain,address).
|
|
17
|
+
*/
|
|
18
|
+
export type Chain = 'solana' | 'celo' | 'stellar' | 'arc';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Faces of karma. A wallet always carries both, queried independently or together.
|
|
22
|
+
* provider — "If I pay this agent, will it deliver?"
|
|
23
|
+
* consumer — "If I take work from this agent, will it pay me cleanly?"
|
|
24
|
+
*/
|
|
25
|
+
export type KarmaFace = 'provider' | 'consumer';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Confidence badge attached to every score. Indicates how the score was derived.
|
|
29
|
+
* receipt-backed — Tier 1 receipts dominate (strongest)
|
|
30
|
+
* behavior-inferred — Tier 2 behavior dominates
|
|
31
|
+
* declared — Tier 3 declarations only (weakest)
|
|
32
|
+
*/
|
|
33
|
+
export type ConfidenceBadge = 'receipt-backed' | 'behavior-inferred' | 'declared';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Trust tier ladder. Computed from raw score; useful for coarse-grained
|
|
37
|
+
* display when the numeric score isn't needed.
|
|
38
|
+
*/
|
|
39
|
+
export type TrustTier = 'Unrated' | 'Poor' | 'Fair' | 'Good' | 'Very Good' | 'Excellent';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Autonomy Confidence label (RFC v0.3 §5.5). Orthogonal to karma — describes
|
|
43
|
+
* whether a wallet behaves like a human, an agent, or a mix.
|
|
44
|
+
*/
|
|
45
|
+
export type AutonomyLabel = 'agent-like' | 'mixed' | 'human-like';
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Four-tier signal spectrum. Returned per face as `tierAggregates`.
|
|
49
|
+
* 1 — receipt-gated attestation
|
|
50
|
+
* 2 — behavioral evidence
|
|
51
|
+
* 3 — declared identity + third-party attestation
|
|
52
|
+
* 4 — social + derivative signals
|
|
53
|
+
*/
|
|
54
|
+
export type SignalTier = 1 | 2 | 3 | 4;
|
|
55
|
+
|
|
56
|
+
// ─── /api/v2/score/{wallet} ───────────────────────────────────────────────────
|
|
57
|
+
|
|
58
|
+
export interface KarmaIdentity {
|
|
59
|
+
claimed: boolean;
|
|
60
|
+
displayName?: string | null;
|
|
61
|
+
description?: string | null;
|
|
62
|
+
website?: string | null;
|
|
63
|
+
category?: string | null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface KarmaFaceData {
|
|
67
|
+
/** 0–100 integer (server rounds before serializing). */
|
|
68
|
+
score: number;
|
|
69
|
+
trustTier: TrustTier | null;
|
|
70
|
+
confidenceBadge: ConfidenceBadge | null;
|
|
71
|
+
/** Per-face metric breakdown (success_rate, diversity, etc.). Shape evolves over time; treat as opaque map. */
|
|
72
|
+
metrics: Record<string, number> | null;
|
|
73
|
+
/** Per-tier aggregate values. `null` keys mean the tier had no signal for this face. */
|
|
74
|
+
tierAggregates: Partial<Record<`tier${SignalTier}`, number | null>> | null;
|
|
75
|
+
/** Whether this face actually has signal worth reading. False = the wallet has no evidence on this face. */
|
|
76
|
+
hasSignal: boolean;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface AutonomyData {
|
|
80
|
+
/** 0–100. null when no transactions exist to compute from. */
|
|
81
|
+
score: number | null;
|
|
82
|
+
label: AutonomyLabel | null;
|
|
83
|
+
/** Per-signal contribution map. */
|
|
84
|
+
signals: Record<string, number> | null;
|
|
85
|
+
/** Per-signal weight after redistribution. */
|
|
86
|
+
effectiveWeights: Record<string, number> | null;
|
|
87
|
+
txCount: number;
|
|
88
|
+
/** ISO 8601 timestamp. */
|
|
89
|
+
lastUpdated: string | null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* `GET /api/v2/score/{wallet}` response.
|
|
94
|
+
*
|
|
95
|
+
* `provider` and `consumer` are present according to the `face` query param.
|
|
96
|
+
* `autonomy` ALWAYS appears (RFC invariant) regardless of which face was requested.
|
|
97
|
+
*/
|
|
98
|
+
export interface KarmaSnapshot {
|
|
99
|
+
/** Wallet address as queried (case-preserved on Solana, lowercased on EVM). */
|
|
100
|
+
address: string;
|
|
101
|
+
/** Face requested. `'both'` means both faces are present in the response. */
|
|
102
|
+
face: KarmaFace | 'both';
|
|
103
|
+
identity: KarmaIdentity;
|
|
104
|
+
/** Number of indexed transactions for this wallet. */
|
|
105
|
+
txCount: number;
|
|
106
|
+
/** ISO 8601 timestamp of most recent activity, or null when never observed. */
|
|
107
|
+
lastActive: string | null;
|
|
108
|
+
/** Present when face === 'provider' or 'both'. */
|
|
109
|
+
provider?: KarmaFaceData;
|
|
110
|
+
/** Present when face === 'consumer' or 'both'. */
|
|
111
|
+
consumer?: KarmaFaceData;
|
|
112
|
+
autonomy: AutonomyData;
|
|
113
|
+
/**
|
|
114
|
+
* Additive Dead Man's Switch block. Present only when the wallet has declared
|
|
115
|
+
* a succession plan; omitted otherwise. OBSERVE-ONLY — does not lift the
|
|
116
|
+
* trust ceiling. The pure `evaluateTrust()` reads it for liveness gates.
|
|
117
|
+
*/
|
|
118
|
+
succession?: SuccessionView;
|
|
119
|
+
/**
|
|
120
|
+
* Additive bonding block — bonds taken out ON this agent. Present only when
|
|
121
|
+
* the wallet has bonds; omitted otherwise. A bond lifts confidence + Tier
|
|
122
|
+
* presence ONLY, never the evidence-gated ceiling.
|
|
123
|
+
*/
|
|
124
|
+
bond?: BondBlock;
|
|
125
|
+
/**
|
|
126
|
+
* Additive orthogonal Surety Karma — this wallet's own underwriting record.
|
|
127
|
+
* Present only when the wallet underwrites bonds; omitted otherwise. Never
|
|
128
|
+
* folded into Provider/Consumer karma.
|
|
129
|
+
*/
|
|
130
|
+
surety?: SuretyView;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ─── /api/v2/celo/{agentId} ───────────────────────────────────────────────────
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Agent registration JSON parsed from the agent's `agentURI`. Shape mirrors
|
|
137
|
+
* ERC-8004 v1 registration-v1 schema. All fields optional in practice.
|
|
138
|
+
*/
|
|
139
|
+
export interface CeloAgentRegistration {
|
|
140
|
+
type?: string;
|
|
141
|
+
name?: string;
|
|
142
|
+
description?: string;
|
|
143
|
+
image?: string;
|
|
144
|
+
x402Support?: boolean;
|
|
145
|
+
active?: boolean;
|
|
146
|
+
supportedTrust?: string[];
|
|
147
|
+
services?: Array<{ name: string; endpoint: string; version?: string }>;
|
|
148
|
+
registrations?: Array<{ agentId: number; agentRegistry: string }>;
|
|
149
|
+
[key: string]: unknown;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface CeloFeedbackRecord {
|
|
153
|
+
client: string;
|
|
154
|
+
value: number;
|
|
155
|
+
tag1: string;
|
|
156
|
+
tag2: string;
|
|
157
|
+
revoked: boolean;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface CeloAgentReputation {
|
|
161
|
+
count: number;
|
|
162
|
+
/** Mean of unrevoked feedback values, null when count === 0. */
|
|
163
|
+
average: number | null;
|
|
164
|
+
records: CeloFeedbackRecord[];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface CeloAgentSnapshot {
|
|
168
|
+
chain: 'celo';
|
|
169
|
+
agentId: number;
|
|
170
|
+
/** ERC-721 owner = the registry NFT owner. */
|
|
171
|
+
owner: string;
|
|
172
|
+
/** Operational wallet (may equal `owner` unless `setAgentWallet` was used). */
|
|
173
|
+
agentWallet: string;
|
|
174
|
+
/** Raw `tokenURI` as stored on-chain. May be `https://…`, `data:…`, `ipfs://…`. */
|
|
175
|
+
tokenURI: string;
|
|
176
|
+
registration: CeloAgentRegistration | null;
|
|
177
|
+
/** Set when registration JSON could not be fetched or parsed. */
|
|
178
|
+
registrationError?: string;
|
|
179
|
+
reputation: CeloAgentReputation | null;
|
|
180
|
+
explorer: {
|
|
181
|
+
celoscan: string;
|
|
182
|
+
eightthousandfourscan: string;
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// ─── Dead Man's Switch (succession) + Agent Bonding + Surety ───────────────────
|
|
187
|
+
//
|
|
188
|
+
// These mirror the OBSERVE-ONLY projections served by
|
|
189
|
+
// `/api/v2/succession/{chain}/{wallet}` and `/api/v2/bond/{chain}/{wallet}`, and
|
|
190
|
+
// are also embedded additively on `/api/v2/score/{wallet}`.
|
|
191
|
+
//
|
|
192
|
+
// AgentKarma never holds funds, never operates an escrow, never executes a will,
|
|
193
|
+
// never proxies calls. None of these fields imply custody. A bond or a declared
|
|
194
|
+
// will lifts an agent's confidence badge + Tier presence ONLY — it MUST NOT lift
|
|
195
|
+
// the evidence-gated trust ceiling. Surety Karma is an ORTHOGONAL axis and is
|
|
196
|
+
// never folded into Provider/Consumer karma.
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Lifecycle of a declared succession plan.
|
|
200
|
+
* declared — will registered, heartbeat not yet evaluated
|
|
201
|
+
* live — heartbeat within interval, agent healthy
|
|
202
|
+
* lapsing — approaching the deadline (warning band)
|
|
203
|
+
* lapsed — interval exceeded, succession conditions met
|
|
204
|
+
* executed — inheritance transfer observed on-chain
|
|
205
|
+
* revoked — owner cancelled the will
|
|
206
|
+
*/
|
|
207
|
+
export type SuccessionStatus =
|
|
208
|
+
| 'declared'
|
|
209
|
+
| 'live'
|
|
210
|
+
| 'lapsing'
|
|
211
|
+
| 'lapsed'
|
|
212
|
+
| 'executed'
|
|
213
|
+
| 'revoked';
|
|
214
|
+
|
|
215
|
+
/** Lifecycle of an agent bond. */
|
|
216
|
+
export type BondStatus = 'open' | 'resolved_success' | 'resolved_failure' | 'expired';
|
|
217
|
+
|
|
218
|
+
/** Surety Karma coarse label (orthogonal axis). */
|
|
219
|
+
export type SuretyLabel = 'reliable' | 'mixed' | 'unproven';
|
|
220
|
+
|
|
221
|
+
/** A single heir in a declared will. */
|
|
222
|
+
export interface SuccessionHeir {
|
|
223
|
+
address: string;
|
|
224
|
+
chain: Chain;
|
|
225
|
+
/** Optional split weight. */
|
|
226
|
+
share?: number | null;
|
|
227
|
+
label?: string | null;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* `GET /api/v2/succession/{chain}/{wallet}` → `.succession`, also embedded as
|
|
232
|
+
* `KarmaSnapshot.succession`. AK's OBSERVED heartbeat is `lastHeartbeatAt` (the
|
|
233
|
+
* last meaningful tx) — AK never receives a real heartbeat ping.
|
|
234
|
+
*/
|
|
235
|
+
export interface SuccessionView {
|
|
236
|
+
/** Live derived status (liveness overrides the stored value). */
|
|
237
|
+
status: SuccessionStatus;
|
|
238
|
+
/** Stored status straight from the row (terminal facts vs derived liveness). */
|
|
239
|
+
declaredStatus: SuccessionStatus;
|
|
240
|
+
sourceType: string;
|
|
241
|
+
intervalSeconds: number;
|
|
242
|
+
heirCount: number;
|
|
243
|
+
heirs: SuccessionHeir[];
|
|
244
|
+
/** Witness anchor for a future on-chain will; null in the no-contract MVP. */
|
|
245
|
+
willHash: string | null;
|
|
246
|
+
declaredAt: string;
|
|
247
|
+
/** AK's OBSERVED heartbeat (last meaningful tx), null when none seen. */
|
|
248
|
+
lastHeartbeatAt: string | null;
|
|
249
|
+
secondsSinceHeartbeat: number | null;
|
|
250
|
+
/** lastHeartbeat + interval — when the agent next reads lapsing. */
|
|
251
|
+
deadlineAt: string | null;
|
|
252
|
+
lapsedAt: string | null;
|
|
253
|
+
executedAt: string | null;
|
|
254
|
+
revokedAt: string | null;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** `GET /api/v2/succession/{chain}/{wallet}` full response. */
|
|
258
|
+
export interface SuccessionResponse {
|
|
259
|
+
chain: Chain;
|
|
260
|
+
address: string;
|
|
261
|
+
succession: SuccessionView;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** A single bond taken out ON an agent. `isDemo` rows are seeded — UI MUST label them. */
|
|
265
|
+
export interface BondView {
|
|
266
|
+
id: string;
|
|
267
|
+
beneficiary: string;
|
|
268
|
+
taskRef: string | null;
|
|
269
|
+
amount: number;
|
|
270
|
+
currency: string;
|
|
271
|
+
status: BondStatus;
|
|
272
|
+
escrowRef: string;
|
|
273
|
+
resolutionProofTx: string | null;
|
|
274
|
+
/** Seeded/demo row — not a real on-chain bond. */
|
|
275
|
+
isDemo: boolean;
|
|
276
|
+
openedAt: string;
|
|
277
|
+
resolvedAt: string | null;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** Bonds taken out ON an agent, split open vs resolved. */
|
|
281
|
+
export interface BondBlock {
|
|
282
|
+
open: BondView[];
|
|
283
|
+
resolved: BondView[];
|
|
284
|
+
/** Sum of `amount` across USDC-denominated bonds only. */
|
|
285
|
+
totalBondedUsdc: number;
|
|
286
|
+
/** True when any bond in this block is a seeded demo. */
|
|
287
|
+
hasDemo: boolean;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Orthogonal Surety Karma for a wallet that underwrites OTHER agents' bonds. */
|
|
291
|
+
export interface SuretyView {
|
|
292
|
+
score: number;
|
|
293
|
+
label: SuretyLabel;
|
|
294
|
+
settledCount: number;
|
|
295
|
+
successCount: number;
|
|
296
|
+
inFlightCount: number;
|
|
297
|
+
totalCount: number;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** `GET /api/v2/bond/{chain}/{wallet}` full response. */
|
|
301
|
+
export interface BondResponse {
|
|
302
|
+
chain: Chain;
|
|
303
|
+
address: string;
|
|
304
|
+
/** Bonds taken out on this agent. */
|
|
305
|
+
bonds: BondBlock;
|
|
306
|
+
/** This wallet's underwriting activity + orthogonal Surety Karma (null if none). */
|
|
307
|
+
surety: SuretyView | null;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// ─── /api/search ──────────────────────────────────────────────────────────────
|
|
311
|
+
|
|
312
|
+
export interface SearchResult {
|
|
313
|
+
address: string;
|
|
314
|
+
score: number;
|
|
315
|
+
trustTier: TrustTier;
|
|
316
|
+
txCount: number;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export interface SearchResponse {
|
|
320
|
+
results: SearchResult[];
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// ─── /api/agent/{wallet}/history ──────────────────────────────────────────────
|
|
324
|
+
|
|
325
|
+
export interface AgentHistoryTransaction {
|
|
326
|
+
id: string;
|
|
327
|
+
facilitator: string;
|
|
328
|
+
amount: number;
|
|
329
|
+
timestamp: string;
|
|
330
|
+
success: boolean;
|
|
331
|
+
txSignature: string;
|
|
332
|
+
/** Consumer-submitted feedback for this tx, or null. */
|
|
333
|
+
feedback: 'delivered' | 'failed' | null;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export interface AgentHistoryResponse {
|
|
337
|
+
address: string;
|
|
338
|
+
total: number;
|
|
339
|
+
limit: number;
|
|
340
|
+
offset: number;
|
|
341
|
+
transactions: AgentHistoryTransaction[];
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// ─── /api/feedback ────────────────────────────────────────────────────────────
|
|
345
|
+
|
|
346
|
+
export interface FeedbackSummary {
|
|
347
|
+
total: number;
|
|
348
|
+
delivered: number;
|
|
349
|
+
failed: number;
|
|
350
|
+
/** Float in [0, 1]. 0 when total === 0. */
|
|
351
|
+
deliveryRate: number;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export type FeedbackRating = 'delivered' | 'failed';
|
|
355
|
+
|
|
356
|
+
export interface FeedbackSubmission {
|
|
357
|
+
agentWallet: string;
|
|
358
|
+
rating: FeedbackRating;
|
|
359
|
+
txSignature: string;
|
|
360
|
+
/** Base58-encoded Ed25519 signature from the consumer's Solana wallet. */
|
|
361
|
+
signature: string;
|
|
362
|
+
/** The exact message that was signed. Build via `buildFeedbackMessage()`. */
|
|
363
|
+
message: string;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export interface FeedbackSubmissionResponse {
|
|
367
|
+
success: true;
|
|
368
|
+
agentWallet: string;
|
|
369
|
+
consumerWallet: string;
|
|
370
|
+
rating: FeedbackRating;
|
|
371
|
+
txSignature: string;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// ─── Client config ────────────────────────────────────────────────────────────
|
|
375
|
+
|
|
376
|
+
export interface RequestOptions {
|
|
377
|
+
/** Per-request abort signal, composed with the client's default timeout. */
|
|
378
|
+
signal?: AbortSignal;
|
|
379
|
+
/** Per-request timeout override (ms). Overrides client-level timeout. */
|
|
380
|
+
timeout?: number;
|
|
381
|
+
/** Extra headers to merge into this single request. */
|
|
382
|
+
headers?: Record<string, string>;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Minimal `fetch` shape the SDK relies on. Looser than `typeof fetch` so any
|
|
387
|
+
* function returning a `Promise<Response>` can be passed in — useful for
|
|
388
|
+
* tests, proxies, retries, edge runtimes where `preconnect` etc. don't exist.
|
|
389
|
+
*/
|
|
390
|
+
export type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
391
|
+
|
|
392
|
+
export interface ClientConfig {
|
|
393
|
+
/** Base URL for the AgentKarma API. Defaults to https://agentkarma.io. */
|
|
394
|
+
baseUrl?: string;
|
|
395
|
+
/** Custom fetch implementation (testing, proxies, retries). Defaults to global `fetch`. */
|
|
396
|
+
fetch?: FetchLike;
|
|
397
|
+
/** Default request timeout in milliseconds. Defaults to 10000. */
|
|
398
|
+
timeout?: number;
|
|
399
|
+
/** Default headers merged into every request. */
|
|
400
|
+
headers?: Record<string, string>;
|
|
401
|
+
/**
|
|
402
|
+
* Custom user-agent. Defaults to `@agentkarma/sdk/{version}`. Set this to
|
|
403
|
+
* identify your application in AgentKarma's request logs.
|
|
404
|
+
*/
|
|
405
|
+
userAgent?: string;
|
|
406
|
+
}
|