Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
- uses: oven-sh/setup-bun@v2
- run: bun install --frozen-lockfile
- run: bun run lint
- run: tsc --noEmit
- run: bunx tsc --noEmit
- run: bun run test
- run: bun run build
39 changes: 21 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![npm version](https://img.shields.io/npm/v/@agent-score/sdk.svg)](https://www.npmjs.com/package/@agent-score/sdk)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)

TypeScript/Node.js client for the [AgentScore](https://agentscore.sh) trust and reputation API. Score, verify, and assess AI agent wallets in the [x402](https://github.com/coinbase/x402) payment ecosystem and [ERC-8004](https://eips.ethereum.org/EIPS/eip-8004) agent registry.
TypeScript/Node.js client for the [AgentScore](https://agentscore.sh) trust and reputation API.

## Install

Expand All @@ -18,31 +18,36 @@ bun add @agent-score/sdk
```typescript
import { AgentScore } from "@agent-score/sdk";

const client = new AgentScore({ apiKey: "ask_..." });
const client = new AgentScore({ apiKey: "as_live_..." });

// Free reputation summary
const summary = await client.getReputation("0x1234...");
console.log(summary.score, summary.grade);
// Look up cached reputation (free)
const rep = await client.getReputation("0x1234...");
console.log(rep.score.value, rep.score.grade);

// Trust decision with policy
const result = await client.getDecision("0x1234...", {
min_grade: "C",
min_transactions: 5,
// Filter to a specific chain
const baseRep = await client.getReputation("0x1234...", { chain: "base" });
console.log(baseRep.agents); // only Base agents

// On-the-fly assessment with policy (paid)
const result = await client.assess("0x1234...", {
policy: { min_grade: "B", min_score: 35 },
});
console.log(result.decision.allow, result.decision.reasons);
console.log(result.decision, result.decision_reasons);

// Browse agents
const agents = await client.getAgents({ chain: "base", limit: 10 });
console.log(agents.items.length, agents.count);

// Batch lookup
const batch = await client.batchReputation(
["0x1234...", "0x5678..."],
{ view: "full", policy: { min_grade: "B" } }
);
// Ecosystem stats
const stats = await client.getStats();
console.log(stats.erc8004?.known_agents);
```

## Configuration

| Option | Type | Default | Description |
| --------- | -------- | --------------------------- | ------------------------ |
| `apiKey` | `string` | | API key from [agentscore.sh](https://agentscore.sh) |
| `apiKey` | `string` | --- | API key from [agentscore.sh](https://agentscore.sh) |
| `baseUrl` | `string` | `https://api.agentscore.sh` | API base URL |
| `timeout` | `number` | `10000` | Request timeout in ms |

Expand All @@ -63,8 +68,6 @@ try {
## Documentation

- [API Reference](https://docs.agentscore.sh)
- [ERC-8004 Standard](https://eips.ethereum.org/EIPS/eip-8004)
- [x402 Protocol](https://github.com/coinbase/x402)

## License

Expand Down
106 changes: 87 additions & 19 deletions bun.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@agent-score/sdk",
"version": "1.0.4",
"version": "1.1.0",
"description": "TypeScript client for the AgentScore trust and reputation API",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
Expand Down Expand Up @@ -55,8 +55,8 @@
"eslint-plugin-import": "^2.32.0",
"eslint-plugin-unused-imports": "^4.4.1",
"tsup": "^8.5.1",
"typescript": "^5.9.3",
"typescript-eslint": "^8.57.1",
"vitest": "^4.1.0"
"typescript": "^6.0.2",
"typescript-eslint": "^8.57.2",
"vitest": "^4.1.2"
}
}
28 changes: 17 additions & 11 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,10 @@ export interface Score {
version: string;
}

export interface ERC8004Identity {
chain: string;
token_id: number;
registry_contract: string | null;
name: string | null;
description: string | null;
metadata_quality: string | null;
endpoint_count: number;
}

export interface Identity {
ens_name: string | null;
website_url: string | null;
github_url: string | null;
erc8004: ERC8004Identity | null;
}

export interface Activity {
Expand All @@ -66,6 +55,21 @@ export interface Activity {
last_verified_tx_at: string | null;
}

export interface OperatorScore {
score: number;
grade: Grade;
agent_count: number;
chains_active: string[];
}

export interface AgentSummary {
token_id: number;
chain: string;
name: string | null;
score: number;
grade: Grade;
}

export interface ReputationResponse {
subject: Subject;
classification: Classification;
Expand All @@ -76,6 +80,8 @@ export interface ReputationResponse {
data_semantics: string;
caveats: string[];
updated_at: string | null;
operator_score?: OperatorScore;
agents?: AgentSummary[];
}

export interface DecisionPolicy {
Expand Down
16 changes: 13 additions & 3 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,22 @@ describe('AgentScore.getReputation()', () => {
);
});

it('appends chain query param when provided', async () => {
it('does not send chain param when not provided', async () => {
mockFetchOk(REPUTATION_RESPONSE);
const client = new AgentScore({ apiKey: API_KEY });
await client.getReputation(WALLET, { chain: 'ethereum' });
await client.getReputation(WALLET);
expect(global.fetch).toHaveBeenCalledWith(
`https://api.agentscore.sh/v1/reputation/${WALLET}`,
expect.anything(),
);
});

it('sends chain query param when provided', async () => {
mockFetchOk(REPUTATION_RESPONSE);
const client = new AgentScore({ apiKey: API_KEY });
await client.getReputation(WALLET, { chain: 'base' });
expect(global.fetch).toHaveBeenCalledWith(
expect.stringContaining('chain=ethereum'),
expect.stringContaining('chain=base'),
expect.anything(),
);
});
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"ignoreDeprecations": "6.0",
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
Expand Down
Loading