@mandatez/sdk 0.1.1 → 0.1.8
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 +193 -95
- package/dist/attestations/index.d.ts +50 -0
- package/dist/attestations/index.d.ts.map +1 -0
- package/dist/attestations/index.js +30 -0
- package/dist/attestations/index.js.map +1 -0
- package/dist/client.d.ts +183 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +256 -3
- package/dist/client.js.map +1 -1
- package/dist/exporters/datadog.d.ts +34 -0
- package/dist/exporters/datadog.d.ts.map +1 -0
- package/dist/exporters/datadog.js +69 -0
- package/dist/exporters/datadog.js.map +1 -0
- package/dist/exporters/index.d.ts +26 -0
- package/dist/exporters/index.d.ts.map +1 -0
- package/dist/exporters/index.js +5 -0
- package/dist/exporters/index.js.map +1 -0
- package/dist/exporters/otel.d.ts +38 -0
- package/dist/exporters/otel.d.ts.map +1 -0
- package/dist/exporters/otel.js +115 -0
- package/dist/exporters/otel.js.map +1 -0
- package/dist/exporters/splunk.d.ts +33 -0
- package/dist/exporters/splunk.d.ts.map +1 -0
- package/dist/exporters/splunk.js +62 -0
- package/dist/exporters/splunk.js.map +1 -0
- package/dist/exporters/webhook.d.ts +33 -0
- package/dist/exporters/webhook.d.ts.map +1 -0
- package/dist/exporters/webhook.js +52 -0
- package/dist/exporters/webhook.js.map +1 -0
- package/dist/identity/hibp.d.ts +39 -0
- package/dist/identity/hibp.d.ts.map +1 -0
- package/dist/identity/hibp.js +85 -0
- package/dist/identity/hibp.js.map +1 -0
- package/dist/index.d.ts +16 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/integrations/langchain/decorator.d.ts +31 -0
- package/dist/integrations/langchain/decorator.d.ts.map +1 -0
- package/dist/integrations/langchain/decorator.js +36 -0
- package/dist/integrations/langchain/decorator.js.map +1 -0
- package/dist/policies/templates.d.ts +223 -0
- package/dist/policies/templates.d.ts.map +1 -0
- package/dist/policies/templates.js +102 -0
- package/dist/policies/templates.js.map +1 -0
- package/dist/risk/index.d.ts +58 -0
- package/dist/risk/index.d.ts.map +1 -0
- package/dist/risk/index.js +45 -0
- package/dist/risk/index.js.map +1 -0
- package/dist/transport/supabase.d.ts +29 -0
- package/dist/transport/supabase.d.ts.map +1 -1
- package/dist/transport/supabase.js +81 -0
- package/dist/transport/supabase.js.map +1 -1
- package/dist/trust/posture.d.ts +24 -0
- package/dist/trust/posture.d.ts.map +1 -0
- package/dist/trust/posture.js +79 -0
- package/dist/trust/posture.js.map +1 -0
- package/dist/wrapper/index.d.ts +26 -0
- package/dist/wrapper/index.d.ts.map +1 -0
- package/dist/wrapper/index.js +162 -0
- package/dist/wrapper/index.js.map +1 -0
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -1,95 +1,193 @@
|
|
|
1
|
-
# MandateZ
|
|
2
|
-
|
|
3
|
-
**Every agent needs a mandate.**
|
|
4
|
-
|
|
5
|
-
MandateZ is the open, cross-vendor trust infrastructure for AI agents. Cryptographic identity, policy enforcement, human oversight, and tamper-proof audit logs — for any agent framework.
|
|
6
|
-
|
|
7
|
-
##
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
1
|
+
# MandateZ
|
|
2
|
+
|
|
3
|
+
**Every agent needs a mandate.**
|
|
4
|
+
|
|
5
|
+
MandateZ is the open, cross-vendor trust infrastructure for AI agents. Cryptographic identity, policy enforcement, human oversight, and tamper-proof audit logs — for any agent framework.
|
|
6
|
+
|
|
7
|
+
## Quickstart (30 seconds)
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @mandatez/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { MandateZAgent } from '@mandatez/sdk';
|
|
15
|
+
|
|
16
|
+
const myAgent = MandateZAgent(yourAgentFunction, {
|
|
17
|
+
agentId: 'ag_...',
|
|
18
|
+
ownerId: 'your_owner_id',
|
|
19
|
+
privateKey: process.env.AGENT_PRIVATE_KEY!,
|
|
20
|
+
supabaseUrl: process.env.SUPABASE_URL!,
|
|
21
|
+
supabaseAnonKey: process.env.SUPABASE_ANON_KEY!,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Your agent is now governed. That's it.
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
One import. One wrap. Every call is policy-checked, optionally identity-screened, and logged as a signed `AgentEvent`. Same function signature in, same function signature out.
|
|
28
|
+
|
|
29
|
+
## The Problem
|
|
30
|
+
|
|
31
|
+
AI agents act autonomously. There is no standard way to prove what they did, enforce what they can do, or produce compliance audit trails. MandateZ solves all three.
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install @mandatez/sdk
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Configuration
|
|
40
|
+
|
|
41
|
+
MandateZ supports two configuration modes. Pick one.
|
|
42
|
+
|
|
43
|
+
### Enterprise mode — `apiKey` (recommended)
|
|
44
|
+
|
|
45
|
+
Generate a key at `/keys` in the MandateZ dashboard. One revocable string replaces the raw Supabase credentials your agents used to carry:
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { MandateZClient } from '@mandatez/sdk';
|
|
49
|
+
|
|
50
|
+
const client = new MandateZClient({
|
|
51
|
+
apiKey: process.env.MANDATEZ_API_KEY!, // "mz_live_..."
|
|
52
|
+
agentId: 'ag_...',
|
|
53
|
+
ownerId: 'your_org_id',
|
|
54
|
+
privateKey: process.env.AGENT_PRIVATE_KEY!,
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Why enterprise customers prefer this:
|
|
59
|
+
- **Revocable** — rotate a compromised key from the dashboard in one click without touching Supabase.
|
|
60
|
+
- **Auditable** — every key has a name, creation time, and `last_used_at` timestamp.
|
|
61
|
+
- **Scoped** — keys are bound to an `owner_id`; they cannot reach another tenant's data.
|
|
62
|
+
- **One string, one secret** — no pasting Supabase URLs into a Vercel env var.
|
|
63
|
+
|
|
64
|
+
### Legacy mode — raw Supabase credentials (still supported)
|
|
65
|
+
|
|
66
|
+
The original configuration still works for local dev, one-off integrations, and anyone already shipping on it:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { generateAgentIdentity, MandateZClient } from '@mandatez/sdk';
|
|
70
|
+
|
|
71
|
+
const identity = await generateAgentIdentity();
|
|
72
|
+
const client = new MandateZClient({
|
|
73
|
+
agentId: identity.agent_id,
|
|
74
|
+
ownerId: 'your_org_id',
|
|
75
|
+
privateKey: identity.private_key,
|
|
76
|
+
supabaseUrl: process.env.SUPABASE_URL!,
|
|
77
|
+
supabaseAnonKey: process.env.SUPABASE_ANON_KEY!,
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Usage
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
const event = await client.track({
|
|
85
|
+
action_type: 'read',
|
|
86
|
+
resource: 'emails',
|
|
87
|
+
});
|
|
88
|
+
// → signed, validated, emitted to your event stream
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## What You Get
|
|
92
|
+
|
|
93
|
+
- **Agent Identity** — Ed25519 keypair per agent, unique `ag_` prefixed IDs
|
|
94
|
+
- **Signed Events** — every action produces a cryptographically signed, tamper-proof event
|
|
95
|
+
- **Policy Engine** — allow/block/flag rules with wildcard resource matching
|
|
96
|
+
- **Human Oversight** — pause execution, alert via Slack/webhook, auto-block on timeout
|
|
97
|
+
- **Compliance Reports** — JSON + PDF audit trail export
|
|
98
|
+
- **Framework Integrations** — LangChain, n8n, with more coming
|
|
99
|
+
|
|
100
|
+
## Observability Exporters
|
|
101
|
+
|
|
102
|
+
Fan MandateZ events out to your existing observability or SIEM stack — Datadog, Splunk, any OpenTelemetry collector, or an arbitrary webhook. Exporters are fire-and-forget: they run in parallel after every `track()` and never block or throw on the hot path.
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import {
|
|
106
|
+
MandateZClient,
|
|
107
|
+
DatadogExporter,
|
|
108
|
+
WebhookExporter,
|
|
109
|
+
} from '@mandatez/sdk';
|
|
110
|
+
|
|
111
|
+
const client = new MandateZClient({
|
|
112
|
+
agentId: '...',
|
|
113
|
+
ownerId: '...',
|
|
114
|
+
privateKey: '...',
|
|
115
|
+
supabaseUrl: '...',
|
|
116
|
+
supabaseAnonKey: '...',
|
|
117
|
+
exporters: [
|
|
118
|
+
new DatadogExporter({
|
|
119
|
+
apiKey: process.env.DD_API_KEY!,
|
|
120
|
+
site: 'datadoghq.com',
|
|
121
|
+
}),
|
|
122
|
+
new WebhookExporter({
|
|
123
|
+
url: 'https://your-siem.com/mandatez',
|
|
124
|
+
}),
|
|
125
|
+
],
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Every tracked event now flows to Datadog and your webhook.
|
|
129
|
+
await client.track({ action_type: 'read', resource: 'emails' });
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Built-in exporters:
|
|
133
|
+
|
|
134
|
+
| Exporter | Destination | Import |
|
|
135
|
+
|---|---|---|
|
|
136
|
+
| `DatadogExporter` | Datadog Logs v2 HTTP intake | `@mandatez/sdk` |
|
|
137
|
+
| `SplunkExporter` | Splunk HTTP Event Collector | `@mandatez/sdk` |
|
|
138
|
+
| `OpenTelemetryExporter` | Any OTLP/HTTP collector (Grafana Tempo, Honeycomb, New Relic, etc.) | `@mandatez/sdk` |
|
|
139
|
+
| `WebhookExporter` | Any HTTPS URL (generic fan-out) | `@mandatez/sdk` |
|
|
140
|
+
|
|
141
|
+
Custom exporters implement the `EventExporter` interface — `{ name: string; export(event: AgentEvent): Promise<void> }` — and drop into the same `exporters: [...]` array.
|
|
142
|
+
|
|
143
|
+
Full setup instructions and payload shapes: [Exporters docs](https://mandatez.mintlify.app/exporters).
|
|
144
|
+
|
|
145
|
+
## Integrations
|
|
146
|
+
|
|
147
|
+
### LangChain
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
import { MandateZLangChainCallback } from '@mandatez/sdk';
|
|
151
|
+
|
|
152
|
+
const callback = new MandateZLangChainCallback(client);
|
|
153
|
+
const chain = new ChatOpenAI({ callbacks: [callback] });
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### n8n
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
import { MandateZN8nHook } from '@mandatez/sdk';
|
|
160
|
+
|
|
161
|
+
const hook = new MandateZN8nHook(client);
|
|
162
|
+
await hook.beforeExecution('wf_123', 'HTTP Request', inputData);
|
|
163
|
+
await hook.afterExecution('wf_123', 'HTTP Request', outputData, true);
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Architecture
|
|
167
|
+
|
|
168
|
+
Everything flows from one spine: the **Agent Event Stream**.
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
Agent Action → Policy Engine → Oversight Gate → Sign (Ed25519) → Emit to Stream
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Every surface — SDK, dashboard, compliance engine, directory — reads the same stream. One data layer. No duplication.
|
|
175
|
+
|
|
176
|
+
## Documentation
|
|
177
|
+
|
|
178
|
+
- [Quickstart](https://mandatez.mintlify.app/quickstart)
|
|
179
|
+
- [SDK Reference](https://mandatez.mintlify.app/sdk/track)
|
|
180
|
+
- [Protocol Specification](./protocol/SPEC.md)
|
|
181
|
+
|
|
182
|
+
## Project Structure
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
packages/sdk/ → @mandatez/sdk (open source, free forever)
|
|
186
|
+
apps/dashboard/ → Next.js event monitoring dashboard
|
|
187
|
+
protocol/ → Open protocol specification
|
|
188
|
+
docs/ → Documentation (Mintlify)
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## License
|
|
192
|
+
|
|
193
|
+
MIT
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export type Verdict = 'clean' | 'flagged' | 'violations_detected';
|
|
2
|
+
export interface AttestationViolation {
|
|
3
|
+
event_id: string;
|
|
4
|
+
timestamp: string;
|
|
5
|
+
action_type: string;
|
|
6
|
+
resource: string;
|
|
7
|
+
outcome: 'blocked' | 'flagged';
|
|
8
|
+
}
|
|
9
|
+
export interface AttestationRecord {
|
|
10
|
+
id: string;
|
|
11
|
+
agent_id: string;
|
|
12
|
+
owner_id: string;
|
|
13
|
+
window_start: string;
|
|
14
|
+
window_end: string;
|
|
15
|
+
event_count: number;
|
|
16
|
+
events_hash: string;
|
|
17
|
+
verdict: Verdict;
|
|
18
|
+
violations: AttestationViolation[];
|
|
19
|
+
platform_signature: string;
|
|
20
|
+
platform_public_key: string;
|
|
21
|
+
metadata: Record<string, unknown>;
|
|
22
|
+
created_at: string;
|
|
23
|
+
}
|
|
24
|
+
export interface VerifyAttestationResponse {
|
|
25
|
+
valid: boolean;
|
|
26
|
+
attestation: AttestationRecord;
|
|
27
|
+
verified_at: string;
|
|
28
|
+
}
|
|
29
|
+
export interface VerifyAttestationOptions {
|
|
30
|
+
/**
|
|
31
|
+
* Base URL of the MandateZ dashboard hosting the verify endpoint.
|
|
32
|
+
* Defaults to the public production deployment.
|
|
33
|
+
*/
|
|
34
|
+
apiUrl?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Fetches and verifies a MandateZ attestation by its id.
|
|
38
|
+
*
|
|
39
|
+
* Public by design: an attestation link is the distribution primitive.
|
|
40
|
+
* The endpoint re-derives the canonical payload and checks the platform
|
|
41
|
+
* signature server-side, so a `valid: true` response from a trusted
|
|
42
|
+
* MandateZ host is sufficient proof that the row is unmodified.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* const result = await verifyAttestation('att_abc123');
|
|
46
|
+
* if (!result.valid) throw new Error('Attestation tampered');
|
|
47
|
+
* console.log(result.attestation.verdict);
|
|
48
|
+
*/
|
|
49
|
+
export declare function verifyAttestation(attestationId: string, options?: VerifyAttestationOptions): Promise<VerifyAttestationResponse>;
|
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/attestations/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,qBAAqB,CAAC;AAElE,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,SAAS,GAAG,SAAS,CAAC;CAChC;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,oBAAoB,EAAE,CAAC;IACnC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,iBAAiB,CAAC;IAC/B,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAKD;;;;;;;;;;;;GAYG;AACH,wBAAsB,iBAAiB,CACrC,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,yBAAyB,CAAC,CAkBpC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const DEFAULT_API_URL = 'https://dashboard.mandatez.com';
|
|
2
|
+
const ATTESTATION_ID_RE = /^att_[A-Za-z0-9_-]+$/;
|
|
3
|
+
/**
|
|
4
|
+
* Fetches and verifies a MandateZ attestation by its id.
|
|
5
|
+
*
|
|
6
|
+
* Public by design: an attestation link is the distribution primitive.
|
|
7
|
+
* The endpoint re-derives the canonical payload and checks the platform
|
|
8
|
+
* signature server-side, so a `valid: true` response from a trusted
|
|
9
|
+
* MandateZ host is sufficient proof that the row is unmodified.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const result = await verifyAttestation('att_abc123');
|
|
13
|
+
* if (!result.valid) throw new Error('Attestation tampered');
|
|
14
|
+
* console.log(result.attestation.verdict);
|
|
15
|
+
*/
|
|
16
|
+
export async function verifyAttestation(attestationId, options = {}) {
|
|
17
|
+
if (!ATTESTATION_ID_RE.test(attestationId)) {
|
|
18
|
+
throw new Error('verifyAttestation: attestationId must start with att_');
|
|
19
|
+
}
|
|
20
|
+
const base = (options.apiUrl ?? DEFAULT_API_URL).replace(/\/+$/, '');
|
|
21
|
+
const res = await fetch(`${base}/api/attestations/${attestationId}/verify`);
|
|
22
|
+
if (!res.ok) {
|
|
23
|
+
const err = (await res.json().catch(() => ({})));
|
|
24
|
+
throw new Error(err.error
|
|
25
|
+
? `verifyAttestation failed: ${err.error}`
|
|
26
|
+
: `verifyAttestation failed: HTTP ${res.status}`);
|
|
27
|
+
}
|
|
28
|
+
return (await res.json());
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/attestations/index.ts"],"names":[],"mappings":"AAwCA,MAAM,eAAe,GAAG,gCAAgC,CAAC;AACzD,MAAM,iBAAiB,GAAG,sBAAsB,CAAC;AAEjD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,aAAqB,EACrB,UAAoC,EAAE;IAEtC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAC3E,CAAC;IAED,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,eAAe,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACrE,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,qBAAqB,aAAa,SAAS,CAAC,CAAC;IAE5E,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAuB,CAAC;QACvE,MAAM,IAAI,KAAK,CACb,GAAG,CAAC,KAAK;YACP,CAAC,CAAC,6BAA6B,GAAG,CAAC,KAAK,EAAE;YAC1C,CAAC,CAAC,kCAAkC,GAAG,CAAC,MAAM,EAAE,CACnD,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAA8B,CAAC;AACzD,CAAC"}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import type { AgentTrustProfile } from './trust/posture.js';
|
|
1
2
|
import type { AgentEvent, AgentEventInput } from './events/schema.js';
|
|
2
3
|
import type { Policy } from './policy/index.js';
|
|
3
4
|
import type { OversightConfig } from './oversight/index.js';
|
|
5
|
+
import type { IdentityCheckResult } from './identity/hibp.js';
|
|
6
|
+
import type { EventExporter } from './exporters/index.js';
|
|
7
|
+
import type { RiskScoreRecord } from './risk/index.js';
|
|
4
8
|
/** The action fields a developer passes to track() */
|
|
5
9
|
export interface TrackInput {
|
|
6
10
|
action_type: AgentEventInput['action_type'];
|
|
@@ -12,6 +16,36 @@ export interface TrackInput {
|
|
|
12
16
|
* and this is not provided, timeout_action applies immediately. */
|
|
13
17
|
waitForApproval?: () => Promise<boolean>;
|
|
14
18
|
}
|
|
19
|
+
/** Minimal input for a batched event. Each is signed locally before upload. */
|
|
20
|
+
export interface TrackBatchInput {
|
|
21
|
+
action_type: AgentEventInput['action_type'];
|
|
22
|
+
resource: string;
|
|
23
|
+
outcome?: AgentEventInput['outcome'];
|
|
24
|
+
policy_id?: string | null;
|
|
25
|
+
metadata?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
export interface TrackBatchResult {
|
|
28
|
+
accepted: number;
|
|
29
|
+
rejected: number;
|
|
30
|
+
errors?: Array<{
|
|
31
|
+
index: number;
|
|
32
|
+
event_id?: string;
|
|
33
|
+
reason: string;
|
|
34
|
+
detail?: string;
|
|
35
|
+
}>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Internal buffering config. When enabled, track() returns immediately
|
|
39
|
+
* after signing and queues the event — a background flush posts batches
|
|
40
|
+
* to /api/events/batch when the buffer hits maxSize or maxWaitMs elapses.
|
|
41
|
+
*/
|
|
42
|
+
export interface BatchConfig {
|
|
43
|
+
enabled: boolean;
|
|
44
|
+
/** Flush when the buffer reaches this many events. */
|
|
45
|
+
maxSize: number;
|
|
46
|
+
/** Flush after this many milliseconds since the first queued event. */
|
|
47
|
+
maxWaitMs: number;
|
|
48
|
+
}
|
|
15
49
|
export interface MandateZClientConfig {
|
|
16
50
|
agentId: string;
|
|
17
51
|
ownerId: string;
|
|
@@ -22,6 +56,78 @@ export interface MandateZClientConfig {
|
|
|
22
56
|
policies?: Policy[];
|
|
23
57
|
/** Optional oversight config — if provided, flagged actions pause for human approval */
|
|
24
58
|
oversight?: OversightConfig;
|
|
59
|
+
/** HaveIBeenPwned API key — required for checkIdentity() */
|
|
60
|
+
hibpApiKey?: string;
|
|
61
|
+
/** MandateZ directory base URL used by verifyAgent(). Defaults to https://core-directory.vercel.app */
|
|
62
|
+
directoryUrl?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Optional list of downstream exporters. After each track() call the
|
|
65
|
+
* signed event is fanned out to every configured exporter in parallel
|
|
66
|
+
* (fire-and-forget — exporter failures never block or throw from track()).
|
|
67
|
+
*/
|
|
68
|
+
exporters?: EventExporter[];
|
|
69
|
+
/**
|
|
70
|
+
* Dashboard API base URL. Required for trackBatch() and for track()
|
|
71
|
+
* buffering mode. Example: 'https://dashboard.mandatez.com'.
|
|
72
|
+
*/
|
|
73
|
+
apiUrl?: string;
|
|
74
|
+
/** Optional API key ("mz_live_...") sent to dashboard endpoints. */
|
|
75
|
+
apiKey?: string;
|
|
76
|
+
/** Enable internal batching on track() calls. Off by default. */
|
|
77
|
+
batchConfig?: BatchConfig;
|
|
78
|
+
}
|
|
79
|
+
export interface CheckIdentityInput {
|
|
80
|
+
email: string;
|
|
81
|
+
/** Override the client's default agentId for this check */
|
|
82
|
+
agentId?: string;
|
|
83
|
+
/** What to do when an identity comes back flagged. Defaults to 'restrict'. */
|
|
84
|
+
onFlagged?: 'restrict' | 'block' | 'allow';
|
|
85
|
+
}
|
|
86
|
+
export interface CheckIdentityOutput extends IdentityCheckResult {
|
|
87
|
+
/** Effective action to take based on status + onFlagged policy */
|
|
88
|
+
recommendation: 'allow' | 'restrict' | 'block';
|
|
89
|
+
}
|
|
90
|
+
export type AgentTrustGrade = 'unverified' | 'low' | 'medium' | 'high' | 'verified';
|
|
91
|
+
export interface VerifyAgentInput {
|
|
92
|
+
requestingAgentId: string;
|
|
93
|
+
targetAgentId: string;
|
|
94
|
+
/** Minimum trust score the target must meet. Default 60. */
|
|
95
|
+
requiredMinScore?: number;
|
|
96
|
+
/** Minimum trust grade the target must meet. Default "medium". */
|
|
97
|
+
requiredMinGrade?: AgentTrustGrade;
|
|
98
|
+
}
|
|
99
|
+
export interface VerifyAgentOutput {
|
|
100
|
+
verified: boolean;
|
|
101
|
+
targetTrustScore: number;
|
|
102
|
+
targetTrustGrade: AgentTrustGrade;
|
|
103
|
+
targetPublicKey: string;
|
|
104
|
+
verificationId: string;
|
|
105
|
+
/** Raw response from the directory for callers that need the full payload */
|
|
106
|
+
raw: VerifyAgentRawResponse;
|
|
107
|
+
}
|
|
108
|
+
export interface VerifyAgentRawResponse {
|
|
109
|
+
verified: boolean;
|
|
110
|
+
requesting_agent: {
|
|
111
|
+
id: string;
|
|
112
|
+
name: string;
|
|
113
|
+
trust_score: number;
|
|
114
|
+
trust_grade: AgentTrustGrade;
|
|
115
|
+
};
|
|
116
|
+
target_agent: {
|
|
117
|
+
id: string;
|
|
118
|
+
name: string;
|
|
119
|
+
trust_score: number;
|
|
120
|
+
trust_grade: AgentTrustGrade;
|
|
121
|
+
public_key: string;
|
|
122
|
+
};
|
|
123
|
+
verification: {
|
|
124
|
+
score_met: boolean;
|
|
125
|
+
grade_met: boolean;
|
|
126
|
+
required_min_score: number;
|
|
127
|
+
required_min_grade: AgentTrustGrade;
|
|
128
|
+
timestamp: string;
|
|
129
|
+
verification_id: string;
|
|
130
|
+
};
|
|
25
131
|
}
|
|
26
132
|
/**
|
|
27
133
|
* Main SDK surface for developers.
|
|
@@ -36,6 +142,15 @@ export declare class MandateZClient {
|
|
|
36
142
|
private transport;
|
|
37
143
|
private policyEngine;
|
|
38
144
|
private oversightGate;
|
|
145
|
+
private trustProfile;
|
|
146
|
+
private hibpApiKey;
|
|
147
|
+
private directoryUrl;
|
|
148
|
+
private exporters;
|
|
149
|
+
private apiUrl;
|
|
150
|
+
private apiKey;
|
|
151
|
+
private batchConfig;
|
|
152
|
+
private buffer;
|
|
153
|
+
private bufferFlushTimer;
|
|
39
154
|
constructor(config: MandateZClientConfig);
|
|
40
155
|
/**
|
|
41
156
|
* Track an agent action.
|
|
@@ -49,5 +164,73 @@ export declare class MandateZClient {
|
|
|
49
164
|
* 4. Sign event, emit to Supabase, return
|
|
50
165
|
*/
|
|
51
166
|
track(input: TrackInput): Promise<AgentEvent>;
|
|
167
|
+
/**
|
|
168
|
+
* Signs each input event locally and posts the batch to /api/events/batch.
|
|
169
|
+
*
|
|
170
|
+
* Requires `apiUrl` in config. The endpoint rejects the entire batch if
|
|
171
|
+
* any signature or schema check fails, so a returned `rejected` count is
|
|
172
|
+
* either 0 (all accepted) or equal to the input length (nothing inserted).
|
|
173
|
+
*/
|
|
174
|
+
trackBatch(events: TrackBatchInput[]): Promise<TrackBatchResult>;
|
|
175
|
+
/**
|
|
176
|
+
* Flushes any buffered events immediately. Callers should invoke this
|
|
177
|
+
* during graceful shutdown to avoid dropping queued events.
|
|
178
|
+
*/
|
|
179
|
+
flush(): Promise<TrackBatchResult>;
|
|
180
|
+
private enqueue;
|
|
181
|
+
private postBatch;
|
|
182
|
+
private fanOutToExporters;
|
|
183
|
+
/**
|
|
184
|
+
* Fetches all events for this agent from Supabase, recomputes
|
|
185
|
+
* the trust score, and updates the agents table.
|
|
186
|
+
*/
|
|
187
|
+
recomputeTrustScore(): Promise<AgentTrustProfile>;
|
|
188
|
+
/**
|
|
189
|
+
* Returns the last computed trust profile, or null if not yet computed.
|
|
190
|
+
*/
|
|
191
|
+
getTrustProfile(): AgentTrustProfile | null;
|
|
192
|
+
/**
|
|
193
|
+
* Checks an email against HaveIBeenPwned, stores the result in
|
|
194
|
+
* Supabase (identity_checks table), and returns a recommendation.
|
|
195
|
+
*
|
|
196
|
+
* Recommendation logic:
|
|
197
|
+
* - status=clean → allow
|
|
198
|
+
* - status=flagged → onFlagged (default: 'restrict')
|
|
199
|
+
* - status=blocked → block (cannot be overridden)
|
|
200
|
+
*/
|
|
201
|
+
checkIdentity(input: CheckIdentityInput): Promise<CheckIdentityOutput>;
|
|
202
|
+
/**
|
|
203
|
+
* Verify another agent's MandateZ credentials before transacting with it.
|
|
204
|
+
*
|
|
205
|
+
* Calls the MandateZ directory's /api/agents/verify endpoint and returns
|
|
206
|
+
* whether the target agent meets the minimum trust score and grade you
|
|
207
|
+
* specified. Use this at the edge of any cross-agent interaction.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* const result = await client.verifyAgent({
|
|
211
|
+
* requestingAgentId: 'ag_my_agent',
|
|
212
|
+
* targetAgentId: 'ag_partner_agent',
|
|
213
|
+
* requiredMinScore: 70,
|
|
214
|
+
* });
|
|
215
|
+
* if (!result.verified) {
|
|
216
|
+
* throw new Error('Partner agent failed MandateZ verification');
|
|
217
|
+
* }
|
|
218
|
+
*/
|
|
219
|
+
verifyAgent(input: VerifyAgentInput): Promise<VerifyAgentOutput>;
|
|
220
|
+
/**
|
|
221
|
+
* Fetch the most recent risk score for an agent from the MandateZ
|
|
222
|
+
* dashboard. The server auto-computes a fresh score if none exists yet,
|
|
223
|
+
* so this never returns null.
|
|
224
|
+
*
|
|
225
|
+
* Requires `apiUrl` and `apiKey` in the client config.
|
|
226
|
+
*/
|
|
227
|
+
getRiskScore(agentId: string): Promise<RiskScoreRecord>;
|
|
228
|
+
/**
|
|
229
|
+
* Trigger a fresh risk-score recomputation for an agent. The returned
|
|
230
|
+
* record is the newly persisted snapshot.
|
|
231
|
+
*
|
|
232
|
+
* Requires `apiUrl` and `apiKey` in the client config.
|
|
233
|
+
*/
|
|
234
|
+
computeRiskScore(agentId: string, windowDays?: number): Promise<RiskScoreRecord>;
|
|
52
235
|
}
|
|
53
236
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD,sDAAsD;AACtD,MAAM,WAAW,UAAU;IACzB,W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