agentcheck-sdk 0.3.0 → 0.5.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/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/telemetry.d.ts +30 -0
- package/dist/telemetry.js +78 -0
- package/dist/templates.d.ts +33 -0
- package/dist/templates.js +40 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,9 @@ export { DelegationProvider } from "./provider";
|
|
|
4
4
|
export { delegationGuard } from "./guard";
|
|
5
5
|
export { AgentToolChecker } from "./langchain";
|
|
6
6
|
export { DelegationDashboard } from "./dashboard";
|
|
7
|
+
export { quickStart } from "./quickstart";
|
|
8
|
+
export { templates } from "./templates";
|
|
9
|
+
export { TelemetryPlugin } from "./telemetry";
|
|
7
10
|
export type { WebhookEvent } from "./webhook";
|
|
8
11
|
export type { ScopeVerifier, DelegationProviderConfig } from "./provider";
|
|
9
12
|
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.DelegationDashboard = exports.AgentToolChecker = exports.delegationGuard = exports.DelegationProvider = exports.WebhookHandler = exports.AgentCheckClient = void 0;
|
|
3
|
+
exports.RateLimitError = exports.ValidationError = exports.NotFoundError = exports.AuthenticationError = exports.AgentCheckError = exports.TelemetryPlugin = 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; } });
|
|
@@ -15,6 +15,12 @@ var langchain_1 = require("./langchain");
|
|
|
15
15
|
Object.defineProperty(exports, "AgentToolChecker", { enumerable: true, get: function () { return langchain_1.AgentToolChecker; } });
|
|
16
16
|
var dashboard_1 = require("./dashboard");
|
|
17
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; } });
|
|
22
|
+
var telemetry_1 = require("./telemetry");
|
|
23
|
+
Object.defineProperty(exports, "TelemetryPlugin", { enumerable: true, get: function () { return telemetry_1.TelemetryPlugin; } });
|
|
18
24
|
var errors_1 = require("./errors");
|
|
19
25
|
Object.defineProperty(exports, "AgentCheckError", { enumerable: true, get: function () { return errors_1.AgentCheckError; } });
|
|
20
26
|
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,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telemetry Plugin - Opt-in usage tracking.
|
|
3
|
+
*
|
|
4
|
+
* NOT enabled by default. You must explicitly enable it.
|
|
5
|
+
*
|
|
6
|
+
* What it tracks:
|
|
7
|
+
* - Which SDK features are used (record, list, revoke, etc.)
|
|
8
|
+
* - SDK language and version
|
|
9
|
+
* - Agent names (for your own analytics)
|
|
10
|
+
*
|
|
11
|
+
* What it does NOT track:
|
|
12
|
+
* - Scope content, email addresses, API keys, payloads
|
|
13
|
+
*/
|
|
14
|
+
export declare class TelemetryPlugin {
|
|
15
|
+
private static instance;
|
|
16
|
+
private apiKey;
|
|
17
|
+
private baseUrl;
|
|
18
|
+
private buffer;
|
|
19
|
+
private enabled;
|
|
20
|
+
private timer;
|
|
21
|
+
private flushInterval;
|
|
22
|
+
constructor(apiKey: string, baseUrl?: string, flushInterval?: number);
|
|
23
|
+
/** Start collecting telemetry (opt-in). */
|
|
24
|
+
enable(): void;
|
|
25
|
+
/** Stop collecting telemetry. */
|
|
26
|
+
disable(): void;
|
|
27
|
+
/** Record a telemetry event (no-op if not enabled). */
|
|
28
|
+
static track(event: string, feature?: string, agentName?: string, metadata?: Record<string, unknown>): void;
|
|
29
|
+
private flush;
|
|
30
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Telemetry Plugin - Opt-in usage tracking.
|
|
4
|
+
*
|
|
5
|
+
* NOT enabled by default. You must explicitly enable it.
|
|
6
|
+
*
|
|
7
|
+
* What it tracks:
|
|
8
|
+
* - Which SDK features are used (record, list, revoke, etc.)
|
|
9
|
+
* - SDK language and version
|
|
10
|
+
* - Agent names (for your own analytics)
|
|
11
|
+
*
|
|
12
|
+
* What it does NOT track:
|
|
13
|
+
* - Scope content, email addresses, API keys, payloads
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.TelemetryPlugin = void 0;
|
|
17
|
+
class TelemetryPlugin {
|
|
18
|
+
constructor(apiKey, baseUrl = "https://agentcheck.spaceplanning.work", flushInterval = 60000) {
|
|
19
|
+
this.buffer = [];
|
|
20
|
+
this.enabled = false;
|
|
21
|
+
this.timer = null;
|
|
22
|
+
this.apiKey = apiKey;
|
|
23
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
24
|
+
this.flushInterval = flushInterval;
|
|
25
|
+
}
|
|
26
|
+
/** Start collecting telemetry (opt-in). */
|
|
27
|
+
enable() {
|
|
28
|
+
this.enabled = true;
|
|
29
|
+
TelemetryPlugin.instance = this;
|
|
30
|
+
this.timer = setInterval(() => this.flush(), this.flushInterval);
|
|
31
|
+
}
|
|
32
|
+
/** Stop collecting telemetry. */
|
|
33
|
+
disable() {
|
|
34
|
+
this.enabled = false;
|
|
35
|
+
TelemetryPlugin.instance = null;
|
|
36
|
+
if (this.timer)
|
|
37
|
+
clearInterval(this.timer);
|
|
38
|
+
this.flush();
|
|
39
|
+
}
|
|
40
|
+
/** Record a telemetry event (no-op if not enabled). */
|
|
41
|
+
static track(event, feature, agentName, metadata) {
|
|
42
|
+
const instance = TelemetryPlugin.instance;
|
|
43
|
+
if (!instance || !instance.enabled)
|
|
44
|
+
return;
|
|
45
|
+
instance.buffer.push({
|
|
46
|
+
event,
|
|
47
|
+
sdk_language: "typescript",
|
|
48
|
+
sdk_version: "0.4.0",
|
|
49
|
+
feature,
|
|
50
|
+
agent_name: agentName,
|
|
51
|
+
metadata,
|
|
52
|
+
});
|
|
53
|
+
if (instance.buffer.length >= 50) {
|
|
54
|
+
instance.flush();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async flush() {
|
|
58
|
+
if (!this.buffer.length)
|
|
59
|
+
return;
|
|
60
|
+
const events = [...this.buffer];
|
|
61
|
+
this.buffer = [];
|
|
62
|
+
try {
|
|
63
|
+
await fetch(`${this.baseUrl}/api/v1/telemetry`, {
|
|
64
|
+
method: "POST",
|
|
65
|
+
headers: {
|
|
66
|
+
"Content-Type": "application/json",
|
|
67
|
+
"X-API-Key": this.apiKey,
|
|
68
|
+
},
|
|
69
|
+
body: JSON.stringify({ events }),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// Telemetry should never break the app
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.TelemetryPlugin = TelemetryPlugin;
|
|
78
|
+
TelemetryPlugin.instance = null;
|
|
@@ -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
|
+
};
|