@trigguard/agent-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 +83 -0
- package/dist/client.d.ts +17 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +60 -0
- package/dist/decision.d.ts +34 -0
- package/dist/decision.d.ts.map +1 -0
- package/dist/decision.js +74 -0
- package/dist/extractDecision.d.ts +8 -0
- package/dist/extractDecision.d.ts.map +1 -0
- package/dist/extractDecision.js +52 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/types.d.ts +32 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +58 -0
package/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# @trigguard/agent-sdk
|
|
2
|
+
|
|
3
|
+
**Canonical TrigGuard agent integration layer.**
|
|
4
|
+
|
|
5
|
+
Wraps [`@trigguard/execution-sdk`](../trigguard-execution-sdk) — all authority decisions come from production `POST /execute`. No duplicate policy logic. No parallel authority systems.
|
|
6
|
+
|
|
7
|
+
## Quick start
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { createTrigGuardAgent } from "@trigguard/agent-sdk";
|
|
11
|
+
|
|
12
|
+
const trigguard = createTrigGuardAgent({
|
|
13
|
+
gatewayUrl: process.env.TRIGGUARD_GATEWAY_URL ?? "https://api.trigguardai.com",
|
|
14
|
+
apiKey: process.env.TRIGGUARD_API_KEY,
|
|
15
|
+
defaultActorId: "my-agent",
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const decision = await trigguard.authorize({
|
|
19
|
+
surface: "deploy.release",
|
|
20
|
+
context: { repository: "TrigGuard-AI/example", environment: "staging" },
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (decision.permit()) {
|
|
24
|
+
await runProtectedAction();
|
|
25
|
+
} else if (decision.deny()) {
|
|
26
|
+
stop("Authority denied");
|
|
27
|
+
} else if (decision.silence()) {
|
|
28
|
+
await requestHumanReview();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const verified = await decision.verifyOffline();
|
|
32
|
+
console.log(decision.executionId, decision.label(), verified.ok);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Authority flow
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
Agent intent
|
|
39
|
+
↓
|
|
40
|
+
trigguard.authorize({ surface, context })
|
|
41
|
+
↓
|
|
42
|
+
POST /execute (via @trigguard/execution-sdk)
|
|
43
|
+
↓
|
|
44
|
+
PERMIT | DENY | SILENCE + signed receipt
|
|
45
|
+
↓
|
|
46
|
+
AgentDecision.permit() | deny() | silence()
|
|
47
|
+
↓
|
|
48
|
+
Optional: verifyOffline() or verifyRemote()
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## When to use this vs execution-sdk
|
|
52
|
+
|
|
53
|
+
| Package | Use when |
|
|
54
|
+
|---|---|
|
|
55
|
+
| `@trigguard/agent-sdk` | Building agents (Cursor, Claude Code, MCP hosts, custom bots) |
|
|
56
|
+
| `@trigguard/execution-sdk` | CI pipelines, low-level HTTP control, `withExecute` fail-closed |
|
|
57
|
+
|
|
58
|
+
Agent SDK adds typed `AgentDecision`, receipt-first decision extraction, and verify helpers.
|
|
59
|
+
|
|
60
|
+
## Examples
|
|
61
|
+
|
|
62
|
+
- [`examples/cursor-governed-agent`](../../examples/cursor-governed-agent/) — Cursor-style tool governance (mock actions)
|
|
63
|
+
- [`examples/claude-code-governed-agent`](../../examples/claude-code-governed-agent/) — Claude Code-style repo mutations (mock actions)
|
|
64
|
+
|
|
65
|
+
## Design partner guide
|
|
66
|
+
|
|
67
|
+
See [`docs/integrations/FIRST_DESIGN_PARTNER_GUIDE.md`](../../docs/integrations/FIRST_DESIGN_PARTNER_GUIDE.md).
|
|
68
|
+
|
|
69
|
+
## MCP integration
|
|
70
|
+
|
|
71
|
+
Production MCP server: [`@trigguard/mcp-server`](../trigguard-mcp-server/) — stdio transport, tools `authorize_action`, `verify_receipt`, `get_surface`, `get_policy`.
|
|
72
|
+
|
|
73
|
+
- Quickstart: [`docs/adoption/MCP_CURSOR_QUICKSTART.md`](../../docs/adoption/MCP_CURSOR_QUICKSTART.md)
|
|
74
|
+
- Tool reference: [`docs/adoption/MCP_TOOL_REFERENCE.md`](../../docs/adoption/MCP_TOOL_REFERENCE.md)
|
|
75
|
+
- Architecture: [`docs/architecture/TRIGGUARD_MCP_ARCHITECTURE.md`](../../docs/architecture/TRIGGUARD_MCP_ARCHITECTURE.md)
|
|
76
|
+
|
|
77
|
+
MCP calls this SDK internally — do not duplicate authority logic in MCP handlers.
|
|
78
|
+
|
|
79
|
+
## Non-goals
|
|
80
|
+
|
|
81
|
+
- No client-side policy evaluation
|
|
82
|
+
- No `/decide` rail (receipt-less)
|
|
83
|
+
- No console UI changes
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AgentDecision } from "./decision.js";
|
|
2
|
+
import type { AgentAuthorizeParams, TrigGuardAgentOptions } from "./types.js";
|
|
3
|
+
export type TrigGuardAgent = {
|
|
4
|
+
readonly authorize: (params: AgentAuthorizeParams) => Promise<AgentDecision>;
|
|
5
|
+
readonly verifyExecution: (executionId: string) => Promise<{
|
|
6
|
+
valid: boolean;
|
|
7
|
+
receipt?: unknown;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Create the canonical TrigGuard agent client.
|
|
12
|
+
* Wraps @trigguard/execution-sdk — all authority from production execute rail.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createTrigGuardAgent(options: TrigGuardAgentOptions): TrigGuardAgent;
|
|
15
|
+
/** Ergonomic one-shot authorize (same as createTrigGuardAgent(...).authorize). */
|
|
16
|
+
export declare function authorizeAgent(options: TrigGuardAgentOptions, params: AgentAuthorizeParams): Promise<AgentDecision>;
|
|
17
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAuB,MAAM,eAAe,CAAC;AAEnE,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAQ9E,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;IAC7E,QAAQ,CAAC,eAAe,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CACnG,CAAC;AAEF;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,cAAc,CAqEnF;AAED,kFAAkF;AAClF,wBAAsB,cAAc,CAClC,OAAO,EAAE,qBAAqB,EAC9B,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,aAAa,CAAC,CAExB"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createExecutionClient } from "@trigguard/execution-sdk";
|
|
2
|
+
import { AgentDecision, TrigGuardAgentError } from "./decision.js";
|
|
3
|
+
import { extractAgentReceipt, extractAuthorityDecision } from "./extractDecision.js";
|
|
4
|
+
function joinUrl(base, path) {
|
|
5
|
+
const b = base.replace(/\/$/, "");
|
|
6
|
+
const p = path.startsWith("/") ? path : `/${path}`;
|
|
7
|
+
return `${b}${p}`;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Create the canonical TrigGuard agent client.
|
|
11
|
+
* Wraps @trigguard/execution-sdk — all authority from production execute rail.
|
|
12
|
+
*/
|
|
13
|
+
export function createTrigGuardAgent(options) {
|
|
14
|
+
const defaultActorId = options.defaultActorId ?? "trigguard-agent";
|
|
15
|
+
async function authorize(params) {
|
|
16
|
+
const client = createExecutionClient({
|
|
17
|
+
gatewayUrl: options.gatewayUrl,
|
|
18
|
+
apiKey: options.apiKey,
|
|
19
|
+
getBearerToken: options.getBearerToken,
|
|
20
|
+
fetchImpl: options.fetchImpl,
|
|
21
|
+
timeoutMs: options.timeoutMs,
|
|
22
|
+
});
|
|
23
|
+
const result = await client.authorize({
|
|
24
|
+
surface: params.surface,
|
|
25
|
+
actorId: params.actorId ?? defaultActorId,
|
|
26
|
+
subjectDigest: params.subjectDigest,
|
|
27
|
+
context: params.context,
|
|
28
|
+
sessionId: params.sessionId,
|
|
29
|
+
});
|
|
30
|
+
if (!result.ok) {
|
|
31
|
+
throw new TrigGuardAgentError(`TrigGuard execute failed: HTTP ${result.status}`);
|
|
32
|
+
}
|
|
33
|
+
const value = extractAuthorityDecision(result);
|
|
34
|
+
if (!value) {
|
|
35
|
+
throw new TrigGuardAgentError("TrigGuard returned no authoritative PERMIT/DENY/SILENCE decision");
|
|
36
|
+
}
|
|
37
|
+
const receipt = extractAgentReceipt(result.receipt);
|
|
38
|
+
const executionId = receipt?.executionId ??
|
|
39
|
+
result.executionId ??
|
|
40
|
+
undefined;
|
|
41
|
+
return new AgentDecision(value, executionId, receipt, result, options.gatewayUrl, options.getBearerToken, options.apiKey, options.fetchImpl);
|
|
42
|
+
}
|
|
43
|
+
async function verifyExecution(executionId) {
|
|
44
|
+
const base = options.gatewayUrl.replace(/\/$/, "");
|
|
45
|
+
const url = joinUrl(base, `/verify/${encodeURIComponent(executionId)}`);
|
|
46
|
+
const headers = { Accept: "application/json" };
|
|
47
|
+
const token = options.apiKey ?? (await options.getBearerToken?.());
|
|
48
|
+
if (token)
|
|
49
|
+
headers.Authorization = `Bearer ${token}`;
|
|
50
|
+
const fetchFn = options.fetchImpl ?? globalThis.fetch;
|
|
51
|
+
const res = await fetchFn(url, { headers });
|
|
52
|
+
const body = (await res.json().catch(() => ({})));
|
|
53
|
+
return { valid: Boolean(body.valid), receipt: body.receipt };
|
|
54
|
+
}
|
|
55
|
+
return { authorize, verifyExecution };
|
|
56
|
+
}
|
|
57
|
+
/** Ergonomic one-shot authorize (same as createTrigGuardAgent(...).authorize). */
|
|
58
|
+
export async function authorizeAgent(options, params) {
|
|
59
|
+
return createTrigGuardAgent(options).authorize(params);
|
|
60
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type VerifyReceiptDetailedResult } from "@trigguard/execution-sdk";
|
|
2
|
+
import type { AgentReceipt, AgentAuthorizeRaw, AuthorityDecisionValue } from "./types.js";
|
|
3
|
+
export declare class TrigGuardAgentError extends Error {
|
|
4
|
+
constructor(message: string);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Typed authority outcome from a governed execute.
|
|
8
|
+
* All decisions originate from TrigGuard — no client-side policy evaluation.
|
|
9
|
+
*/
|
|
10
|
+
export declare class AgentDecision {
|
|
11
|
+
private readonly gatewayUrl;
|
|
12
|
+
private readonly getBearerToken?;
|
|
13
|
+
private readonly apiKey?;
|
|
14
|
+
private readonly fetchImpl?;
|
|
15
|
+
readonly value: AuthorityDecisionValue;
|
|
16
|
+
readonly executionId: string | undefined;
|
|
17
|
+
readonly receipt: AgentReceipt | undefined;
|
|
18
|
+
readonly raw: AgentAuthorizeRaw;
|
|
19
|
+
constructor(value: AuthorityDecisionValue, executionId: string | undefined, receipt: AgentReceipt | undefined, raw: AgentAuthorizeRaw, gatewayUrl: string, getBearerToken?: (() => Promise<string | undefined>) | undefined, apiKey?: string | undefined, fetchImpl?: typeof fetch | undefined);
|
|
20
|
+
permit(): boolean;
|
|
21
|
+
deny(): boolean;
|
|
22
|
+
silence(): boolean;
|
|
23
|
+
/** Human-readable decision for logs and agent UX. */
|
|
24
|
+
label(): AuthorityDecisionValue;
|
|
25
|
+
verifyUrl(): string | undefined;
|
|
26
|
+
/** Offline Ed25519 verify using gateway JWKS (same trust model as CI). */
|
|
27
|
+
verifyOffline(): Promise<VerifyReceiptDetailedResult>;
|
|
28
|
+
/** Gateway GET /verify/:executionId lookup. */
|
|
29
|
+
verifyRemote(): Promise<{
|
|
30
|
+
valid: boolean;
|
|
31
|
+
receipt?: unknown;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=decision.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decision.d.ts","sourceRoot":"","sources":["../src/decision.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,2BAA2B,EACjC,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAE1F,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,OAAO,EAAE,MAAM;CAI5B;AAED;;;GAGG;AACH,qBAAa,aAAa;IAWtB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IACxB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;IAb7B,QAAQ,CAAC,KAAK,EAAE,sBAAsB,CAAC;IACvC,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS,CAAC;IAC3C,QAAQ,CAAC,GAAG,EAAE,iBAAiB,CAAC;gBAG9B,KAAK,EAAE,sBAAsB,EAC7B,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,OAAO,EAAE,YAAY,GAAG,SAAS,EACjC,GAAG,EAAE,iBAAiB,EACL,UAAU,EAAE,MAAM,EAClB,cAAc,CAAC,GAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,aAAA,EAClD,MAAM,CAAC,EAAE,MAAM,YAAA,EACf,SAAS,CAAC,EAAE,OAAO,KAAK,YAAA;IAQ3C,MAAM,IAAI,OAAO;IAIjB,IAAI,IAAI,OAAO;IAIf,OAAO,IAAI,OAAO;IAIlB,qDAAqD;IACrD,KAAK,IAAI,sBAAsB;IAI/B,SAAS,IAAI,MAAM,GAAG,SAAS;IAM/B,0EAA0E;IACpE,aAAa,IAAI,OAAO,CAAC,2BAA2B,CAAC;IAY3D,+CAA+C;IACzC,YAAY,IAAI,OAAO,CAAC;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CAiBrE"}
|
package/dist/decision.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { fetchPublicKeys, verifyReceiptSignatureDetailed, } from "@trigguard/execution-sdk";
|
|
2
|
+
export class TrigGuardAgentError extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "TrigGuardAgentError";
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Typed authority outcome from a governed execute.
|
|
10
|
+
* All decisions originate from TrigGuard — no client-side policy evaluation.
|
|
11
|
+
*/
|
|
12
|
+
export class AgentDecision {
|
|
13
|
+
gatewayUrl;
|
|
14
|
+
getBearerToken;
|
|
15
|
+
apiKey;
|
|
16
|
+
fetchImpl;
|
|
17
|
+
value;
|
|
18
|
+
executionId;
|
|
19
|
+
receipt;
|
|
20
|
+
raw;
|
|
21
|
+
constructor(value, executionId, receipt, raw, gatewayUrl, getBearerToken, apiKey, fetchImpl) {
|
|
22
|
+
this.gatewayUrl = gatewayUrl;
|
|
23
|
+
this.getBearerToken = getBearerToken;
|
|
24
|
+
this.apiKey = apiKey;
|
|
25
|
+
this.fetchImpl = fetchImpl;
|
|
26
|
+
this.value = value;
|
|
27
|
+
this.executionId = executionId;
|
|
28
|
+
this.receipt = receipt;
|
|
29
|
+
this.raw = raw;
|
|
30
|
+
}
|
|
31
|
+
permit() {
|
|
32
|
+
return this.value === "PERMIT";
|
|
33
|
+
}
|
|
34
|
+
deny() {
|
|
35
|
+
return this.value === "DENY";
|
|
36
|
+
}
|
|
37
|
+
silence() {
|
|
38
|
+
return this.value === "SILENCE";
|
|
39
|
+
}
|
|
40
|
+
/** Human-readable decision for logs and agent UX. */
|
|
41
|
+
label() {
|
|
42
|
+
return this.value;
|
|
43
|
+
}
|
|
44
|
+
verifyUrl() {
|
|
45
|
+
if (!this.executionId)
|
|
46
|
+
return undefined;
|
|
47
|
+
const base = this.gatewayUrl.replace(/\/$/, "");
|
|
48
|
+
return `${base}/verify/${encodeURIComponent(this.executionId)}`;
|
|
49
|
+
}
|
|
50
|
+
/** Offline Ed25519 verify using gateway JWKS (same trust model as CI). */
|
|
51
|
+
async verifyOffline() {
|
|
52
|
+
if (!this.receipt?.receiptHash || !this.receipt.authoritySignature) {
|
|
53
|
+
return { ok: false, reason: "unsigned" };
|
|
54
|
+
}
|
|
55
|
+
const keys = await fetchPublicKeys(this.gatewayUrl, this.apiKey ? async () => this.apiKey : this.getBearerToken, this.fetchImpl);
|
|
56
|
+
return verifyReceiptSignatureDetailed(this.receipt, keys);
|
|
57
|
+
}
|
|
58
|
+
/** Gateway GET /verify/:executionId lookup. */
|
|
59
|
+
async verifyRemote() {
|
|
60
|
+
if (!this.executionId) {
|
|
61
|
+
throw new TrigGuardAgentError("No executionId — cannot verify remotely");
|
|
62
|
+
}
|
|
63
|
+
const base = this.gatewayUrl.replace(/\/$/, "");
|
|
64
|
+
const url = `${base}/verify/${encodeURIComponent(this.executionId)}`;
|
|
65
|
+
const headers = { Accept: "application/json" };
|
|
66
|
+
const token = this.apiKey ?? (await this.getBearerToken?.());
|
|
67
|
+
if (token)
|
|
68
|
+
headers.Authorization = `Bearer ${token}`;
|
|
69
|
+
const fetchFn = this.fetchImpl ?? globalThis.fetch;
|
|
70
|
+
const res = await fetchFn(url, { headers });
|
|
71
|
+
const body = (await res.json().catch(() => ({})));
|
|
72
|
+
return { valid: Boolean(body.valid), receipt: body.receipt };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AuthorizeResult } from "@trigguard/execution-sdk";
|
|
2
|
+
import type { AgentReceipt, AuthorityDecisionValue } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Trust receipt.decision over top-level JSON (matches CI authority gate).
|
|
5
|
+
*/
|
|
6
|
+
export declare function extractAuthorityDecision(result: AuthorizeResult): AuthorityDecisionValue | null;
|
|
7
|
+
export declare function extractAgentReceipt(receipt: unknown): AgentReceipt | undefined;
|
|
8
|
+
//# sourceMappingURL=extractDecision.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractDecision.d.ts","sourceRoot":"","sources":["../src/extractDecision.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAQvE;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,eAAe,GAAG,sBAAsB,GAAG,IAAI,CAQ/F;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,YAAY,GAAG,SAAS,CAsC9E"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
function receiptDecision(receipt) {
|
|
2
|
+
if (!receipt || typeof receipt !== "object")
|
|
3
|
+
return undefined;
|
|
4
|
+
const r = receipt;
|
|
5
|
+
return typeof r.decision === "string" ? r.decision : undefined;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Trust receipt.decision over top-level JSON (matches CI authority gate).
|
|
9
|
+
*/
|
|
10
|
+
export function extractAuthorityDecision(result) {
|
|
11
|
+
const fromReceipt = receiptDecision(result.receipt);
|
|
12
|
+
const raw = (fromReceipt ?? result.decision ?? "").trim().toUpperCase();
|
|
13
|
+
if (raw === "PERMIT" || raw === "DENY" || raw === "SILENCE") {
|
|
14
|
+
return raw;
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
export function extractAgentReceipt(receipt) {
|
|
19
|
+
if (!receipt || typeof receipt !== "object")
|
|
20
|
+
return undefined;
|
|
21
|
+
const r = receipt;
|
|
22
|
+
return {
|
|
23
|
+
executionId: typeof r.executionId === "string"
|
|
24
|
+
? r.executionId
|
|
25
|
+
: typeof r.execution_id === "string"
|
|
26
|
+
? r.execution_id
|
|
27
|
+
: undefined,
|
|
28
|
+
decision: typeof r.decision === "string" ? r.decision : undefined,
|
|
29
|
+
surface: typeof r.surface === "string" ? r.surface : undefined,
|
|
30
|
+
receiptHash: typeof r.receiptHash === "string"
|
|
31
|
+
? r.receiptHash
|
|
32
|
+
: typeof r.receipt_hash === "string"
|
|
33
|
+
? r.receipt_hash
|
|
34
|
+
: undefined,
|
|
35
|
+
authoritySignature: typeof r.authoritySignature === "string"
|
|
36
|
+
? r.authoritySignature
|
|
37
|
+
: typeof r.authority_signature === "string"
|
|
38
|
+
? r.authority_signature
|
|
39
|
+
: undefined,
|
|
40
|
+
authorityKeyId: typeof r.authorityKeyId === "string"
|
|
41
|
+
? r.authorityKeyId
|
|
42
|
+
: typeof r.authority_key_id === "string"
|
|
43
|
+
? r.authority_key_id
|
|
44
|
+
: undefined,
|
|
45
|
+
policyId: typeof r.policyId === "string"
|
|
46
|
+
? r.policyId
|
|
47
|
+
: typeof r.policy_id === "string"
|
|
48
|
+
? r.policy_id
|
|
49
|
+
: undefined,
|
|
50
|
+
timestamp: typeof r.timestamp === "string" ? r.timestamp : undefined,
|
|
51
|
+
};
|
|
52
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createTrigGuardAgent, authorizeAgent, type TrigGuardAgent, } from "./client.js";
|
|
2
|
+
export { AgentDecision, TrigGuardAgentError } from "./decision.js";
|
|
3
|
+
export { extractAuthorityDecision, extractAgentReceipt } from "./extractDecision.js";
|
|
4
|
+
export type { AgentAuthorizeParams, AgentAuthorizeRaw, AgentReceipt, AuthorityDecisionValue, TrigGuardAgentOptions, } from "./types.js";
|
|
5
|
+
export { ExecutionNotPermittedError, withExecute, attemptExecute, fetchPublicKeys, verifyReceiptSignature, verifyReceiptSignatureDetailed, TrigGuardSdkError, } from "@trigguard/execution-sdk";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,KAAK,cAAc,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AACrF,YAAY,EACV,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,EACZ,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,0BAA0B,EAC1B,WAAW,EACX,cAAc,EACd,eAAe,EACf,sBAAsB,EACtB,8BAA8B,EAC9B,iBAAiB,GAClB,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createTrigGuardAgent, authorizeAgent, } from "./client.js";
|
|
2
|
+
export { AgentDecision, TrigGuardAgentError } from "./decision.js";
|
|
3
|
+
export { extractAuthorityDecision, extractAgentReceipt } from "./extractDecision.js";
|
|
4
|
+
// Re-export execution-sdk helpers agents commonly need (no duplicate implementations).
|
|
5
|
+
export { ExecutionNotPermittedError, withExecute, attemptExecute, fetchPublicKeys, verifyReceiptSignature, verifyReceiptSignatureDetailed, TrigGuardSdkError, } from "@trigguard/execution-sdk";
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AuthorizeResult, ExecutionContext } from "@trigguard/execution-sdk";
|
|
2
|
+
/** Authoritative gateway decision values (production-proven). */
|
|
3
|
+
export type AuthorityDecisionValue = "PERMIT" | "DENY" | "SILENCE";
|
|
4
|
+
/** Minimal receipt fields agents need for verify and audit. */
|
|
5
|
+
export type AgentReceipt = {
|
|
6
|
+
readonly executionId?: string;
|
|
7
|
+
readonly decision?: string;
|
|
8
|
+
readonly surface?: string;
|
|
9
|
+
readonly receiptHash?: string;
|
|
10
|
+
readonly authoritySignature?: string;
|
|
11
|
+
readonly authorityKeyId?: string;
|
|
12
|
+
readonly policyId?: string;
|
|
13
|
+
readonly timestamp?: string;
|
|
14
|
+
};
|
|
15
|
+
export type AgentAuthorizeParams = {
|
|
16
|
+
readonly surface: string;
|
|
17
|
+
readonly actorId?: string;
|
|
18
|
+
readonly subjectDigest?: string;
|
|
19
|
+
readonly context?: ExecutionContext;
|
|
20
|
+
readonly sessionId?: string;
|
|
21
|
+
};
|
|
22
|
+
export type TrigGuardAgentOptions = {
|
|
23
|
+
readonly gatewayUrl: string;
|
|
24
|
+
readonly apiKey?: string;
|
|
25
|
+
readonly getBearerToken?: () => Promise<string | undefined>;
|
|
26
|
+
readonly fetchImpl?: typeof fetch;
|
|
27
|
+
readonly timeoutMs?: number;
|
|
28
|
+
/** Default actor id when authorize() omits actorId. */
|
|
29
|
+
readonly defaultActorId?: string;
|
|
30
|
+
};
|
|
31
|
+
export type AgentAuthorizeRaw = AuthorizeResult;
|
|
32
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAElF,iEAAiE;AACjE,MAAM,MAAM,sBAAsB,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;AAEnE,+DAA+D;AAC/D,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IACpC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC5D,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IAClC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,uDAAuD;IACvD,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,eAAe,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@trigguard/agent-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Canonical TrigGuard agent integration SDK — authorize, decide PERMIT/DENY/SILENCE, verify receipts. Wraps @trigguard/execution-sdk; no duplicate policy logic.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc -p tsconfig.json",
|
|
18
|
+
"pretest": "npm run build",
|
|
19
|
+
"test": "node --test test/*.test.mjs",
|
|
20
|
+
"prepublishOnly": "npm run build"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"trigguard",
|
|
24
|
+
"agent",
|
|
25
|
+
"authorization",
|
|
26
|
+
"governance",
|
|
27
|
+
"mcp",
|
|
28
|
+
"cursor",
|
|
29
|
+
"claude"
|
|
30
|
+
],
|
|
31
|
+
"license": "Apache-2.0",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/TrigGuard-AI/TrigGuard.git",
|
|
35
|
+
"directory": "packages/trigguard-agent-sdk"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/TrigGuard-AI/TrigGuard/tree/main/packages/trigguard-agent-sdk#readme",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/TrigGuard-AI/TrigGuard/issues"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=20"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@trigguard/execution-sdk": "^0.1.1"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/node": "^22.0.0",
|
|
49
|
+
"typescript": "^5.6.0"
|
|
50
|
+
},
|
|
51
|
+
"files": [
|
|
52
|
+
"dist",
|
|
53
|
+
"README.md"
|
|
54
|
+
],
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
}
|
|
58
|
+
}
|