agentcheck-sdk 0.2.0 → 0.4.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/dist/dashboard.d.ts +36 -0
- package/dist/dashboard.js +101 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7 -1
- package/dist/quickstart.d.ts +29 -0
- package/dist/quickstart.js +40 -0
- package/dist/templates.d.ts +33 -0
- package/dist/templates.js +40 -0
- package/package.json +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AgentCheckClient } from "./client";
|
|
2
|
+
export interface DashboardConfig {
|
|
3
|
+
/** Title shown at the top */
|
|
4
|
+
title?: string;
|
|
5
|
+
/** Auto-refresh interval in seconds (0 = off) */
|
|
6
|
+
refreshInterval?: number;
|
|
7
|
+
/** Max records to show */
|
|
8
|
+
limit?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* DelegationDashboard - Embeddable HTML widget for agent delegation status.
|
|
12
|
+
*
|
|
13
|
+
* Generates a self-contained HTML snippet that shows:
|
|
14
|
+
* - Active delegations with status badges
|
|
15
|
+
* - Recent execution logs
|
|
16
|
+
* - Quick actions (revoke)
|
|
17
|
+
*
|
|
18
|
+
* Usage (Express):
|
|
19
|
+
* app.get('/admin/delegations', async (req, res) => {
|
|
20
|
+
* const html = await dashboard.render();
|
|
21
|
+
* res.send(html);
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* Usage (embed in existing page):
|
|
25
|
+
* const html = await dashboard.renderWidget();
|
|
26
|
+
* // Insert into your page's <div id="delegation-widget">
|
|
27
|
+
*/
|
|
28
|
+
export declare class DelegationDashboard {
|
|
29
|
+
private client;
|
|
30
|
+
private config;
|
|
31
|
+
constructor(client: AgentCheckClient, config?: DashboardConfig);
|
|
32
|
+
/** Render full HTML page with dashboard. */
|
|
33
|
+
render(): Promise<string>;
|
|
34
|
+
/** Render widget HTML (for embedding in existing pages). */
|
|
35
|
+
renderWidget(): Promise<string>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DelegationDashboard = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* DelegationDashboard - Embeddable HTML widget for agent delegation status.
|
|
6
|
+
*
|
|
7
|
+
* Generates a self-contained HTML snippet that shows:
|
|
8
|
+
* - Active delegations with status badges
|
|
9
|
+
* - Recent execution logs
|
|
10
|
+
* - Quick actions (revoke)
|
|
11
|
+
*
|
|
12
|
+
* Usage (Express):
|
|
13
|
+
* app.get('/admin/delegations', async (req, res) => {
|
|
14
|
+
* const html = await dashboard.render();
|
|
15
|
+
* res.send(html);
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* Usage (embed in existing page):
|
|
19
|
+
* const html = await dashboard.renderWidget();
|
|
20
|
+
* // Insert into your page's <div id="delegation-widget">
|
|
21
|
+
*/
|
|
22
|
+
class DelegationDashboard {
|
|
23
|
+
constructor(client, config = {}) {
|
|
24
|
+
this.client = client;
|
|
25
|
+
this.config = {
|
|
26
|
+
title: config.title ?? "Agent Delegations",
|
|
27
|
+
refreshInterval: config.refreshInterval ?? 30,
|
|
28
|
+
limit: config.limit ?? 20,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Render full HTML page with dashboard. */
|
|
32
|
+
async render() {
|
|
33
|
+
const widget = await this.renderWidget();
|
|
34
|
+
const refresh = this.config.refreshInterval > 0
|
|
35
|
+
? `<meta http-equiv="refresh" content="${this.config.refreshInterval}">`
|
|
36
|
+
: "";
|
|
37
|
+
return `<!DOCTYPE html>
|
|
38
|
+
<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
39
|
+
${refresh}
|
|
40
|
+
<title>${this.config.title}</title>
|
|
41
|
+
<style>${DASHBOARD_CSS}</style>
|
|
42
|
+
</head><body>${widget}</body></html>`;
|
|
43
|
+
}
|
|
44
|
+
/** Render widget HTML (for embedding in existing pages). */
|
|
45
|
+
async renderWidget() {
|
|
46
|
+
const list = await this.client.list({ limit: this.config.limit });
|
|
47
|
+
const records = list.records;
|
|
48
|
+
const statusCounts = {};
|
|
49
|
+
for (const r of records) {
|
|
50
|
+
statusCounts[r.status] = (statusCounts[r.status] || 0) + 1;
|
|
51
|
+
}
|
|
52
|
+
const summaryCards = Object.entries(statusCounts)
|
|
53
|
+
.map(([status, count]) => `<div class="ac-card"><div class="ac-card-num">${count}</div><div class="ac-card-label">${status}</div></div>`).join("\n");
|
|
54
|
+
const rows = records
|
|
55
|
+
.map((r) => {
|
|
56
|
+
const statusClass = r.status === "approved" ? "ac-approved"
|
|
57
|
+
: r.status === "revoked" ? "ac-revoked"
|
|
58
|
+
: r.status === "expired" ? "ac-expired"
|
|
59
|
+
: "ac-pending";
|
|
60
|
+
return `<tr>
|
|
61
|
+
<td><span class="ac-badge ${statusClass}">${r.status}</span></td>
|
|
62
|
+
<td>${r.agent}</td>
|
|
63
|
+
<td title="${r.scope}">${r.scope.length > 60 ? r.scope.slice(0, 60) + "..." : r.scope}</td>
|
|
64
|
+
<td>${r.authorized_by}</td>
|
|
65
|
+
<td>${new Date(r.created_at).toLocaleDateString()}</td>
|
|
66
|
+
<td><a href="${r.verify_url}" target="_blank">Verify</a></td>
|
|
67
|
+
</tr>`;
|
|
68
|
+
}).join("\n");
|
|
69
|
+
return `<div class="ac-dashboard">
|
|
70
|
+
<h2 class="ac-title">${this.config.title}</h2>
|
|
71
|
+
<div class="ac-cards">${summaryCards}</div>
|
|
72
|
+
<table class="ac-table">
|
|
73
|
+
<thead><tr>
|
|
74
|
+
<th>Status</th><th>Agent</th><th>Scope</th><th>Authorized by</th><th>Created</th><th>Verify</th>
|
|
75
|
+
</tr></thead>
|
|
76
|
+
<tbody>${rows}</tbody>
|
|
77
|
+
</table>
|
|
78
|
+
<div class="ac-footer">${records.length} delegation(s) | ${this.config.refreshInterval > 0 ? `Auto-refresh: ${this.config.refreshInterval}s` : "Manual refresh"}</div>
|
|
79
|
+
</div>
|
|
80
|
+
<style>${DASHBOARD_CSS}</style>`;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.DelegationDashboard = DelegationDashboard;
|
|
84
|
+
const DASHBOARD_CSS = `
|
|
85
|
+
.ac-dashboard{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;max-width:960px;margin:0 auto;padding:24px;}
|
|
86
|
+
.ac-title{font-size:20px;font-weight:700;margin:0 0 20px;color:#1e293b;}
|
|
87
|
+
.ac-cards{display:flex;gap:12px;margin-bottom:20px;flex-wrap:wrap;}
|
|
88
|
+
.ac-card{background:#fff;border:1px solid #e5e7eb;border-radius:10px;padding:16px 20px;min-width:100px;text-align:center;}
|
|
89
|
+
.ac-card-num{font-size:28px;font-weight:800;color:#1e293b;}
|
|
90
|
+
.ac-card-label{font-size:12px;color:#64748b;text-transform:uppercase;letter-spacing:.5px;margin-top:4px;}
|
|
91
|
+
.ac-table{width:100%;border-collapse:collapse;background:#fff;border-radius:10px;overflow:hidden;border:1px solid #e5e7eb;}
|
|
92
|
+
.ac-table th{padding:10px 14px;text-align:left;font-size:12px;font-weight:700;color:#475569;background:#f8fafc;border-bottom:2px solid #e5e7eb;}
|
|
93
|
+
.ac-table td{padding:10px 14px;font-size:13px;color:#555;border-bottom:1px solid #f0f0f0;}
|
|
94
|
+
.ac-table a{color:#2563eb;font-size:12px;}
|
|
95
|
+
.ac-badge{display:inline-block;padding:2px 10px;border-radius:9999px;font-size:11px;font-weight:700;color:#fff;}
|
|
96
|
+
.ac-approved{background:#16a34a;}
|
|
97
|
+
.ac-pending{background:#ca8a04;}
|
|
98
|
+
.ac-revoked{background:#dc2626;}
|
|
99
|
+
.ac-expired{background:#6b7280;}
|
|
100
|
+
.ac-footer{text-align:center;color:#94a3b8;font-size:12px;margin-top:16px;}
|
|
101
|
+
`;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ export { WebhookHandler } from "./webhook";
|
|
|
3
3
|
export { DelegationProvider } from "./provider";
|
|
4
4
|
export { delegationGuard } from "./guard";
|
|
5
5
|
export { AgentToolChecker } from "./langchain";
|
|
6
|
+
export { DelegationDashboard } from "./dashboard";
|
|
7
|
+
export { quickStart } from "./quickstart";
|
|
8
|
+
export { templates } from "./templates";
|
|
6
9
|
export type { WebhookEvent } from "./webhook";
|
|
7
10
|
export type { ScopeVerifier, DelegationProviderConfig } from "./provider";
|
|
8
11
|
export type { GuardConfig } from "./guard";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RateLimitError = exports.ValidationError = exports.NotFoundError = exports.AuthenticationError = exports.AgentCheckError = exports.AgentToolChecker = exports.delegationGuard = exports.DelegationProvider = exports.WebhookHandler = exports.AgentCheckClient = void 0;
|
|
3
|
+
exports.RateLimitError = exports.ValidationError = exports.NotFoundError = exports.AuthenticationError = exports.AgentCheckError = exports.templates = exports.quickStart = exports.DelegationDashboard = exports.AgentToolChecker = exports.delegationGuard = exports.DelegationProvider = exports.WebhookHandler = exports.AgentCheckClient = void 0;
|
|
4
4
|
// Individual commands (basic menu)
|
|
5
5
|
var client_1 = require("./client");
|
|
6
6
|
Object.defineProperty(exports, "AgentCheckClient", { enumerable: true, get: function () { return client_1.AgentCheckClient; } });
|
|
@@ -13,6 +13,12 @@ var guard_1 = require("./guard");
|
|
|
13
13
|
Object.defineProperty(exports, "delegationGuard", { enumerable: true, get: function () { return guard_1.delegationGuard; } });
|
|
14
14
|
var langchain_1 = require("./langchain");
|
|
15
15
|
Object.defineProperty(exports, "AgentToolChecker", { enumerable: true, get: function () { return langchain_1.AgentToolChecker; } });
|
|
16
|
+
var dashboard_1 = require("./dashboard");
|
|
17
|
+
Object.defineProperty(exports, "DelegationDashboard", { enumerable: true, get: function () { return dashboard_1.DelegationDashboard; } });
|
|
18
|
+
var quickstart_1 = require("./quickstart");
|
|
19
|
+
Object.defineProperty(exports, "quickStart", { enumerable: true, get: function () { return quickstart_1.quickStart; } });
|
|
20
|
+
var templates_1 = require("./templates");
|
|
21
|
+
Object.defineProperty(exports, "templates", { enumerable: true, get: function () { return templates_1.templates; } });
|
|
16
22
|
var errors_1 = require("./errors");
|
|
17
23
|
Object.defineProperty(exports, "AgentCheckError", { enumerable: true, get: function () { return errors_1.AgentCheckError; } });
|
|
18
24
|
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_1.AuthenticationError; } });
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AgentCheckClient } from "./client";
|
|
2
|
+
import { DelegationDashboard } from "./dashboard";
|
|
3
|
+
import { AgentToolChecker } from "./langchain";
|
|
4
|
+
import { DelegationProvider, ScopeVerifier } from "./provider";
|
|
5
|
+
export interface QuickStartConfig {
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
verifyScope?: ScopeVerifier;
|
|
9
|
+
}
|
|
10
|
+
export interface AgentCheckBundle {
|
|
11
|
+
client: AgentCheckClient;
|
|
12
|
+
provider: DelegationProvider;
|
|
13
|
+
dashboard: DelegationDashboard;
|
|
14
|
+
checker: (agentName: string) => AgentToolChecker;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Setup everything in one call.
|
|
18
|
+
*
|
|
19
|
+
* Usage:
|
|
20
|
+
* const ac = quickStart({ apiKey: "ak_live_..." });
|
|
21
|
+
* // or reads from AGENTCHECK_API_KEY env var
|
|
22
|
+
* const ac = quickStart();
|
|
23
|
+
*
|
|
24
|
+
* ac.provider.canAct("bot", "action");
|
|
25
|
+
* ac.client.record({ ... });
|
|
26
|
+
* ac.dashboard.render();
|
|
27
|
+
* const safe = ac.checker("bot").wrap("tool", fn);
|
|
28
|
+
*/
|
|
29
|
+
export declare function quickStart(config?: QuickStartConfig): AgentCheckBundle;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.quickStart = quickStart;
|
|
4
|
+
const client_1 = require("./client");
|
|
5
|
+
const dashboard_1 = require("./dashboard");
|
|
6
|
+
const langchain_1 = require("./langchain");
|
|
7
|
+
const provider_1 = require("./provider");
|
|
8
|
+
/**
|
|
9
|
+
* Setup everything in one call.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* const ac = quickStart({ apiKey: "ak_live_..." });
|
|
13
|
+
* // or reads from AGENTCHECK_API_KEY env var
|
|
14
|
+
* const ac = quickStart();
|
|
15
|
+
*
|
|
16
|
+
* ac.provider.canAct("bot", "action");
|
|
17
|
+
* ac.client.record({ ... });
|
|
18
|
+
* ac.dashboard.render();
|
|
19
|
+
* const safe = ac.checker("bot").wrap("tool", fn);
|
|
20
|
+
*/
|
|
21
|
+
function quickStart(config = {}) {
|
|
22
|
+
const apiKey = config.apiKey || process.env.AGENTCHECK_API_KEY || "";
|
|
23
|
+
const baseUrl = config.baseUrl ||
|
|
24
|
+
process.env.AGENTCHECK_BASE_URL ||
|
|
25
|
+
"https://agentcheck.spaceplanning.work";
|
|
26
|
+
if (!apiKey) {
|
|
27
|
+
throw new Error("Provide apiKey or set AGENTCHECK_API_KEY environment variable");
|
|
28
|
+
}
|
|
29
|
+
const client = new client_1.AgentCheckClient(apiKey, baseUrl);
|
|
30
|
+
const provider = new provider_1.DelegationProvider(client, {
|
|
31
|
+
verifyScope: config.verifyScope,
|
|
32
|
+
});
|
|
33
|
+
const dashboard = new dashboard_1.DelegationDashboard(client);
|
|
34
|
+
return {
|
|
35
|
+
client,
|
|
36
|
+
provider,
|
|
37
|
+
dashboard,
|
|
38
|
+
checker: (agentName) => new langchain_1.AgentToolChecker(provider, agentName),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scope Templates - Pre-built scope definitions for common use cases.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* import { templates } from "agentcheck-sdk";
|
|
6
|
+
* client.record({
|
|
7
|
+
* agent: "maintenance-bot",
|
|
8
|
+
* scope: templates.manufacturing({ maxOrderAmount: 10000 }),
|
|
9
|
+
* authorized_by: "manager@company.com",
|
|
10
|
+
* });
|
|
11
|
+
*/
|
|
12
|
+
export declare const templates: {
|
|
13
|
+
manufacturing(opts?: {
|
|
14
|
+
maxOrderAmount?: number;
|
|
15
|
+
currency?: string;
|
|
16
|
+
}): string;
|
|
17
|
+
customerSupport(opts?: {
|
|
18
|
+
maxRefund?: number;
|
|
19
|
+
currency?: string;
|
|
20
|
+
}): string;
|
|
21
|
+
devops(opts?: {
|
|
22
|
+
environments?: string[];
|
|
23
|
+
}): string;
|
|
24
|
+
finance(opts?: {
|
|
25
|
+
maxTransaction?: number;
|
|
26
|
+
currency?: string;
|
|
27
|
+
assetClasses?: string[];
|
|
28
|
+
}): string;
|
|
29
|
+
dataPipeline(opts?: {
|
|
30
|
+
databases?: string[];
|
|
31
|
+
}): string;
|
|
32
|
+
general(actions: string[]): string;
|
|
33
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Scope Templates - Pre-built scope definitions for common use cases.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* import { templates } from "agentcheck-sdk";
|
|
7
|
+
* client.record({
|
|
8
|
+
* agent: "maintenance-bot",
|
|
9
|
+
* scope: templates.manufacturing({ maxOrderAmount: 10000 }),
|
|
10
|
+
* authorized_by: "manager@company.com",
|
|
11
|
+
* });
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.templates = void 0;
|
|
15
|
+
exports.templates = {
|
|
16
|
+
manufacturing(opts = {}) {
|
|
17
|
+
const { maxOrderAmount = 10000, currency = "USD" } = opts;
|
|
18
|
+
return `Monitor equipment 24/7. Order replacement parts up to ${currency} ${maxOrderAmount.toLocaleString()}. Generate maintenance reports. Alert on anomalies.`;
|
|
19
|
+
},
|
|
20
|
+
customerSupport(opts = {}) {
|
|
21
|
+
const { maxRefund = 500, currency = "USD" } = opts;
|
|
22
|
+
return `Access customer profiles (read-only). Issue refunds up to ${currency} ${maxRefund.toLocaleString()}. Create support tickets. Escalate to human agent for amounts over ${currency} ${maxRefund.toLocaleString()}.`;
|
|
23
|
+
},
|
|
24
|
+
devops(opts = {}) {
|
|
25
|
+
const envs = (opts.environments || ["staging"]).join(", ");
|
|
26
|
+
return `Deploy to ${envs}. Rollback on failure. Monitor server health. Restart services on crash. Cannot modify production database directly.`;
|
|
27
|
+
},
|
|
28
|
+
finance(opts = {}) {
|
|
29
|
+
const { maxTransaction = 10000, currency = "USD" } = opts;
|
|
30
|
+
const assets = (opts.assetClasses || ["stocks", "bonds"]).join(", ");
|
|
31
|
+
return `Execute trades up to ${currency} ${maxTransaction.toLocaleString()} per transaction. Asset classes: ${assets}. Generate daily P&L reports. Cannot withdraw funds.`;
|
|
32
|
+
},
|
|
33
|
+
dataPipeline(opts = {}) {
|
|
34
|
+
const dbs = (opts.databases || ["analytics"]).join(", ");
|
|
35
|
+
return `Read from production database. Write to ${dbs} database(s). Run ETL jobs on schedule. Cannot modify production schema. Cannot delete records.`;
|
|
36
|
+
},
|
|
37
|
+
general(actions) {
|
|
38
|
+
return `Allowed actions: ${actions.join(", ")}.`;
|
|
39
|
+
},
|
|
40
|
+
};
|