agentcheck-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/README.md +64 -0
- package/dist/client.d.ts +21 -0
- package/dist/client.js +94 -0
- package/dist/errors.d.ts +16 -0
- package/dist/errors.js +39 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +13 -0
- package/dist/types.d.ts +61 -0
- package/dist/types.js +2 -0
- package/dist/webhook.d.ts +12 -0
- package/dist/webhook.js +31 -0
- package/package.json +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# agentcheck-sdk
|
|
2
|
+
|
|
3
|
+
Record what your AI agent is allowed to do.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install agentcheck-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quickstart
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { AgentCheckClient } from "agentcheck-sdk";
|
|
15
|
+
|
|
16
|
+
const client = new AgentCheckClient("ak_live_...");
|
|
17
|
+
|
|
18
|
+
// Create agreement - one call
|
|
19
|
+
const proof = await client.record({
|
|
20
|
+
agent: "factory-bot",
|
|
21
|
+
scope: "order parts under $10K, monitor equipment 24/7",
|
|
22
|
+
authorized_by: "kim@factory.com",
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Kim gets an email, clicks "Approve"
|
|
26
|
+
|
|
27
|
+
// Check status
|
|
28
|
+
const record = await client.get(proof.id);
|
|
29
|
+
console.log(record.status); // "approved"
|
|
30
|
+
|
|
31
|
+
// List all
|
|
32
|
+
const records = await client.list({ status: "approved" });
|
|
33
|
+
|
|
34
|
+
// Revoke immediately
|
|
35
|
+
await client.revoke(proof.id, "Security incident");
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Webhook Verification
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { WebhookHandler } from "agentcheck-sdk";
|
|
42
|
+
|
|
43
|
+
const handler = new WebhookHandler("whsec_...");
|
|
44
|
+
|
|
45
|
+
// In your webhook endpoint
|
|
46
|
+
const event = handler.verifyAndParse(req.body, req.headers["x-agentcheck-signature"]);
|
|
47
|
+
|
|
48
|
+
if (event.type === "record.approved") {
|
|
49
|
+
enableAgent(event.data.agreement_id);
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Sign Up
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { AgentCheckClient } from "agentcheck-sdk";
|
|
57
|
+
|
|
58
|
+
const result = await AgentCheckClient.signup("dev@company.com", "My Company");
|
|
59
|
+
console.log(result.api_key); // Save this - shown once only
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## License
|
|
63
|
+
|
|
64
|
+
MIT
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Agreement, AgreementList, AmendParams, CreateRecordParams, ListParams, SignupResult, WebhookResult } from "./types";
|
|
2
|
+
export declare class AgentCheckClient {
|
|
3
|
+
private apiKey;
|
|
4
|
+
private baseUrl;
|
|
5
|
+
constructor(apiKey: string, baseUrl?: string);
|
|
6
|
+
private request;
|
|
7
|
+
/** Create a new agreement and send approval email. */
|
|
8
|
+
record(params: CreateRecordParams): Promise<Agreement>;
|
|
9
|
+
/** Get agreement details by ID. */
|
|
10
|
+
get(agreementId: string): Promise<Agreement>;
|
|
11
|
+
/** List agreements with optional filters. */
|
|
12
|
+
list(params?: ListParams): Promise<AgreementList>;
|
|
13
|
+
/** Amend an agreement's scope. */
|
|
14
|
+
amend(agreementId: string, params: AmendParams): Promise<Agreement>;
|
|
15
|
+
/** Revoke an agreement immediately. */
|
|
16
|
+
revoke(agreementId: string, reason: string): Promise<Agreement>;
|
|
17
|
+
/** Register a webhook endpoint. */
|
|
18
|
+
registerWebhook(url: string, events: string[]): Promise<WebhookResult>;
|
|
19
|
+
/** Self-service signup. Returns API key (shown once). */
|
|
20
|
+
static signup(email: string, companyName?: string, baseUrl?: string): Promise<SignupResult>;
|
|
21
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentCheckClient = void 0;
|
|
4
|
+
const errors_1 = require("./errors");
|
|
5
|
+
const DEFAULT_BASE_URL = "https://agentcheck.spaceplanning.work";
|
|
6
|
+
class AgentCheckClient {
|
|
7
|
+
constructor(apiKey, baseUrl = DEFAULT_BASE_URL) {
|
|
8
|
+
this.apiKey = apiKey;
|
|
9
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
10
|
+
}
|
|
11
|
+
async request(method, path, body, auth = true) {
|
|
12
|
+
const headers = {
|
|
13
|
+
"Content-Type": "application/json",
|
|
14
|
+
};
|
|
15
|
+
if (auth) {
|
|
16
|
+
headers["X-API-Key"] = this.apiKey;
|
|
17
|
+
}
|
|
18
|
+
const resp = await fetch(`${this.baseUrl}${path}`, {
|
|
19
|
+
method,
|
|
20
|
+
headers,
|
|
21
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
22
|
+
});
|
|
23
|
+
if (resp.status === 401)
|
|
24
|
+
throw new errors_1.AuthenticationError();
|
|
25
|
+
if (resp.status === 404)
|
|
26
|
+
throw new errors_1.NotFoundError();
|
|
27
|
+
if (resp.status === 429)
|
|
28
|
+
throw new errors_1.RateLimitError();
|
|
29
|
+
const data = (await resp.json());
|
|
30
|
+
if (resp.status === 400) {
|
|
31
|
+
throw new errors_1.ValidationError(data.error?.message ?? "Bad request");
|
|
32
|
+
}
|
|
33
|
+
if (!resp.ok) {
|
|
34
|
+
throw new errors_1.AgentCheckError(data.error?.message ?? `HTTP ${resp.status}`, data.error?.code ?? "server_error");
|
|
35
|
+
}
|
|
36
|
+
return data.data;
|
|
37
|
+
}
|
|
38
|
+
/** Create a new agreement and send approval email. */
|
|
39
|
+
async record(params) {
|
|
40
|
+
return this.request("POST", "/api/v1/record", params);
|
|
41
|
+
}
|
|
42
|
+
/** Get agreement details by ID. */
|
|
43
|
+
async get(agreementId) {
|
|
44
|
+
return this.request("GET", `/api/v1/record/${agreementId}`);
|
|
45
|
+
}
|
|
46
|
+
/** List agreements with optional filters. */
|
|
47
|
+
async list(params = {}) {
|
|
48
|
+
const query = new URLSearchParams();
|
|
49
|
+
if (params.status)
|
|
50
|
+
query.set("status", params.status);
|
|
51
|
+
if (params.agent)
|
|
52
|
+
query.set("agent", params.agent);
|
|
53
|
+
if (params.limit)
|
|
54
|
+
query.set("limit", String(params.limit));
|
|
55
|
+
if (params.offset)
|
|
56
|
+
query.set("offset", String(params.offset));
|
|
57
|
+
const qs = query.toString();
|
|
58
|
+
return this.request("GET", `/api/v1/records${qs ? `?${qs}` : ""}`);
|
|
59
|
+
}
|
|
60
|
+
/** Amend an agreement's scope. */
|
|
61
|
+
async amend(agreementId, params) {
|
|
62
|
+
return this.request("POST", `/api/v1/record/${agreementId}/amend`, params);
|
|
63
|
+
}
|
|
64
|
+
/** Revoke an agreement immediately. */
|
|
65
|
+
async revoke(agreementId, reason) {
|
|
66
|
+
return this.request("POST", `/api/v1/record/${agreementId}/revoke`, { reason });
|
|
67
|
+
}
|
|
68
|
+
/** Register a webhook endpoint. */
|
|
69
|
+
async registerWebhook(url, events) {
|
|
70
|
+
return this.request("POST", "/api/v1/webhooks", {
|
|
71
|
+
url,
|
|
72
|
+
events,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/** Self-service signup. Returns API key (shown once). */
|
|
76
|
+
static async signup(email, companyName, baseUrl = DEFAULT_BASE_URL) {
|
|
77
|
+
const body = { email };
|
|
78
|
+
if (companyName)
|
|
79
|
+
body.company_name = companyName;
|
|
80
|
+
const resp = await fetch(`${baseUrl}/api/v1/signup`, {
|
|
81
|
+
method: "POST",
|
|
82
|
+
headers: { "Content-Type": "application/json" },
|
|
83
|
+
body: JSON.stringify(body),
|
|
84
|
+
});
|
|
85
|
+
if (resp.status === 429)
|
|
86
|
+
throw new errors_1.RateLimitError();
|
|
87
|
+
const data = (await resp.json());
|
|
88
|
+
if (!resp.ok) {
|
|
89
|
+
throw new errors_1.AgentCheckError(data.error?.message ?? "Signup failed", data.error?.code ?? "signup_error");
|
|
90
|
+
}
|
|
91
|
+
return data.data;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.AgentCheckClient = AgentCheckClient;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class AgentCheckError extends Error {
|
|
2
|
+
code: string;
|
|
3
|
+
constructor(message: string, code?: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class AuthenticationError extends AgentCheckError {
|
|
6
|
+
constructor(message?: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class NotFoundError extends AgentCheckError {
|
|
9
|
+
constructor(message?: string);
|
|
10
|
+
}
|
|
11
|
+
export declare class ValidationError extends AgentCheckError {
|
|
12
|
+
constructor(message: string);
|
|
13
|
+
}
|
|
14
|
+
export declare class RateLimitError extends AgentCheckError {
|
|
15
|
+
constructor(message?: string);
|
|
16
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RateLimitError = exports.ValidationError = exports.NotFoundError = exports.AuthenticationError = exports.AgentCheckError = void 0;
|
|
4
|
+
class AgentCheckError extends Error {
|
|
5
|
+
constructor(message, code = "unknown") {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "AgentCheckError";
|
|
8
|
+
this.code = code;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.AgentCheckError = AgentCheckError;
|
|
12
|
+
class AuthenticationError extends AgentCheckError {
|
|
13
|
+
constructor(message = "Invalid API key") {
|
|
14
|
+
super(message, "unauthorized");
|
|
15
|
+
this.name = "AuthenticationError";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.AuthenticationError = AuthenticationError;
|
|
19
|
+
class NotFoundError extends AgentCheckError {
|
|
20
|
+
constructor(message = "Resource not found") {
|
|
21
|
+
super(message, "not_found");
|
|
22
|
+
this.name = "NotFoundError";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.NotFoundError = NotFoundError;
|
|
26
|
+
class ValidationError extends AgentCheckError {
|
|
27
|
+
constructor(message) {
|
|
28
|
+
super(message, "bad_request");
|
|
29
|
+
this.name = "ValidationError";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.ValidationError = ValidationError;
|
|
33
|
+
class RateLimitError extends AgentCheckError {
|
|
34
|
+
constructor(message = "Rate limited") {
|
|
35
|
+
super(message, "rate_limited");
|
|
36
|
+
this.name = "RateLimitError";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.RateLimitError = RateLimitError;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { AgentCheckClient } from "./client";
|
|
2
|
+
export { WebhookHandler } from "./webhook";
|
|
3
|
+
export type { WebhookEvent } from "./webhook";
|
|
4
|
+
export { AgentCheckError, AuthenticationError, NotFoundError, ValidationError, RateLimitError, } from "./errors";
|
|
5
|
+
export type { Agreement, AgreementList, SignupResult, WebhookResult, CreateRecordParams, ListParams, AmendParams, } from "./types";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RateLimitError = exports.ValidationError = exports.NotFoundError = exports.AuthenticationError = exports.AgentCheckError = exports.WebhookHandler = exports.AgentCheckClient = void 0;
|
|
4
|
+
var client_1 = require("./client");
|
|
5
|
+
Object.defineProperty(exports, "AgentCheckClient", { enumerable: true, get: function () { return client_1.AgentCheckClient; } });
|
|
6
|
+
var webhook_1 = require("./webhook");
|
|
7
|
+
Object.defineProperty(exports, "WebhookHandler", { enumerable: true, get: function () { return webhook_1.WebhookHandler; } });
|
|
8
|
+
var errors_1 = require("./errors");
|
|
9
|
+
Object.defineProperty(exports, "AgentCheckError", { enumerable: true, get: function () { return errors_1.AgentCheckError; } });
|
|
10
|
+
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_1.AuthenticationError; } });
|
|
11
|
+
Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return errors_1.NotFoundError; } });
|
|
12
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return errors_1.ValidationError; } });
|
|
13
|
+
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_1.RateLimitError; } });
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export interface Agreement {
|
|
2
|
+
id: string;
|
|
3
|
+
status: "pending" | "approved" | "rejected" | "expired" | "revoked";
|
|
4
|
+
agent: string;
|
|
5
|
+
agent_provider?: string;
|
|
6
|
+
scope: string;
|
|
7
|
+
authorized_by: string;
|
|
8
|
+
created_at: string;
|
|
9
|
+
approved_at?: string;
|
|
10
|
+
expires_at?: string;
|
|
11
|
+
verify_url: string;
|
|
12
|
+
signature?: string;
|
|
13
|
+
sig_algorithm: string;
|
|
14
|
+
}
|
|
15
|
+
export interface AgreementList {
|
|
16
|
+
records: Agreement[];
|
|
17
|
+
limit: number;
|
|
18
|
+
offset: number;
|
|
19
|
+
}
|
|
20
|
+
export interface SignupResult {
|
|
21
|
+
api_key: string;
|
|
22
|
+
email: string;
|
|
23
|
+
message: string;
|
|
24
|
+
}
|
|
25
|
+
export interface WebhookResult {
|
|
26
|
+
id: string;
|
|
27
|
+
url: string;
|
|
28
|
+
events: string[];
|
|
29
|
+
secret: string;
|
|
30
|
+
active: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface CreateRecordParams {
|
|
33
|
+
agent: string;
|
|
34
|
+
scope: string;
|
|
35
|
+
authorized_by: string;
|
|
36
|
+
agent_provider?: string;
|
|
37
|
+
expires_in_days?: number;
|
|
38
|
+
metadata?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
export interface ListParams {
|
|
41
|
+
status?: string;
|
|
42
|
+
agent?: string;
|
|
43
|
+
limit?: number;
|
|
44
|
+
offset?: number;
|
|
45
|
+
}
|
|
46
|
+
export interface AmendParams {
|
|
47
|
+
new_scope: string;
|
|
48
|
+
reason?: string;
|
|
49
|
+
require_reauth?: boolean;
|
|
50
|
+
}
|
|
51
|
+
export interface ApiResponse<T> {
|
|
52
|
+
success: boolean;
|
|
53
|
+
data: T;
|
|
54
|
+
}
|
|
55
|
+
export interface ApiError {
|
|
56
|
+
success: false;
|
|
57
|
+
error: {
|
|
58
|
+
code: string;
|
|
59
|
+
message: string;
|
|
60
|
+
};
|
|
61
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface WebhookEvent {
|
|
2
|
+
id: string;
|
|
3
|
+
type: string;
|
|
4
|
+
created_at: string;
|
|
5
|
+
data: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
export declare class WebhookHandler {
|
|
8
|
+
private secret;
|
|
9
|
+
constructor(secret: string);
|
|
10
|
+
/** Verify HMAC signature and parse webhook payload. */
|
|
11
|
+
verifyAndParse(body: string | Buffer, signature: string): WebhookEvent;
|
|
12
|
+
}
|
package/dist/webhook.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebhookHandler = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
|
+
class WebhookHandler {
|
|
7
|
+
constructor(secret) {
|
|
8
|
+
this.secret = secret;
|
|
9
|
+
}
|
|
10
|
+
/** Verify HMAC signature and parse webhook payload. */
|
|
11
|
+
verifyAndParse(body, signature) {
|
|
12
|
+
const bodyStr = typeof body === "string" ? body : body.toString("utf-8");
|
|
13
|
+
const expected = (0, crypto_1.createHmac)("sha256", this.secret)
|
|
14
|
+
.update(bodyStr)
|
|
15
|
+
.digest("hex");
|
|
16
|
+
const sigBuf = Buffer.from(signature, "utf-8");
|
|
17
|
+
const expBuf = Buffer.from(expected, "utf-8");
|
|
18
|
+
if (sigBuf.length !== expBuf.length ||
|
|
19
|
+
!(0, crypto_1.timingSafeEqual)(sigBuf, expBuf)) {
|
|
20
|
+
throw new errors_1.AgentCheckError("Invalid webhook signature", "invalid_signature");
|
|
21
|
+
}
|
|
22
|
+
const payload = JSON.parse(bodyStr);
|
|
23
|
+
return {
|
|
24
|
+
id: payload.id,
|
|
25
|
+
type: payload.type,
|
|
26
|
+
created_at: payload.created_at,
|
|
27
|
+
data: payload.data ?? {},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.WebhookHandler = WebhookHandler;
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "agentcheck-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Record what your AI agent is allowed to do",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"prepublishOnly": "npm run build"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"ai",
|
|
16
|
+
"agent",
|
|
17
|
+
"delegation",
|
|
18
|
+
"trust",
|
|
19
|
+
"authorization"
|
|
20
|
+
],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "^25.5.2",
|
|
24
|
+
"typescript": "^5.0.0"
|
|
25
|
+
}
|
|
26
|
+
}
|