@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.
Files changed (62) hide show
  1. package/README.md +193 -95
  2. package/dist/attestations/index.d.ts +50 -0
  3. package/dist/attestations/index.d.ts.map +1 -0
  4. package/dist/attestations/index.js +30 -0
  5. package/dist/attestations/index.js.map +1 -0
  6. package/dist/client.d.ts +183 -0
  7. package/dist/client.d.ts.map +1 -1
  8. package/dist/client.js +256 -3
  9. package/dist/client.js.map +1 -1
  10. package/dist/exporters/datadog.d.ts +34 -0
  11. package/dist/exporters/datadog.d.ts.map +1 -0
  12. package/dist/exporters/datadog.js +69 -0
  13. package/dist/exporters/datadog.js.map +1 -0
  14. package/dist/exporters/index.d.ts +26 -0
  15. package/dist/exporters/index.d.ts.map +1 -0
  16. package/dist/exporters/index.js +5 -0
  17. package/dist/exporters/index.js.map +1 -0
  18. package/dist/exporters/otel.d.ts +38 -0
  19. package/dist/exporters/otel.d.ts.map +1 -0
  20. package/dist/exporters/otel.js +115 -0
  21. package/dist/exporters/otel.js.map +1 -0
  22. package/dist/exporters/splunk.d.ts +33 -0
  23. package/dist/exporters/splunk.d.ts.map +1 -0
  24. package/dist/exporters/splunk.js +62 -0
  25. package/dist/exporters/splunk.js.map +1 -0
  26. package/dist/exporters/webhook.d.ts +33 -0
  27. package/dist/exporters/webhook.d.ts.map +1 -0
  28. package/dist/exporters/webhook.js +52 -0
  29. package/dist/exporters/webhook.js.map +1 -0
  30. package/dist/identity/hibp.d.ts +39 -0
  31. package/dist/identity/hibp.d.ts.map +1 -0
  32. package/dist/identity/hibp.js +85 -0
  33. package/dist/identity/hibp.js.map +1 -0
  34. package/dist/index.d.ts +16 -1
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +8 -0
  37. package/dist/index.js.map +1 -1
  38. package/dist/integrations/langchain/decorator.d.ts +31 -0
  39. package/dist/integrations/langchain/decorator.d.ts.map +1 -0
  40. package/dist/integrations/langchain/decorator.js +36 -0
  41. package/dist/integrations/langchain/decorator.js.map +1 -0
  42. package/dist/policies/templates.d.ts +223 -0
  43. package/dist/policies/templates.d.ts.map +1 -0
  44. package/dist/policies/templates.js +102 -0
  45. package/dist/policies/templates.js.map +1 -0
  46. package/dist/risk/index.d.ts +58 -0
  47. package/dist/risk/index.d.ts.map +1 -0
  48. package/dist/risk/index.js +45 -0
  49. package/dist/risk/index.js.map +1 -0
  50. package/dist/transport/supabase.d.ts +29 -0
  51. package/dist/transport/supabase.d.ts.map +1 -1
  52. package/dist/transport/supabase.js +81 -0
  53. package/dist/transport/supabase.js.map +1 -1
  54. package/dist/trust/posture.d.ts +24 -0
  55. package/dist/trust/posture.d.ts.map +1 -0
  56. package/dist/trust/posture.js +79 -0
  57. package/dist/trust/posture.js.map +1 -0
  58. package/dist/wrapper/index.d.ts +26 -0
  59. package/dist/wrapper/index.d.ts.map +1 -0
  60. package/dist/wrapper/index.js +162 -0
  61. package/dist/wrapper/index.js.map +1 -0
  62. package/package.json +8 -8
@@ -0,0 +1,223 @@
1
+ import type { PolicyRule } from '../policy/index.js';
2
+ export interface PolicyTemplate {
3
+ /** Stable template identifier. Used as the `preset_id` on saved policies. */
4
+ id: string;
5
+ /** Display name shown in onboarding and dashboard galleries. */
6
+ name: string;
7
+ /** Human summary — shown next to the template in pickers. */
8
+ description: string;
9
+ /** Ordered rules for the PolicyEngine. First match wins, so the trailing
10
+ * catch-all block only fires on actions no prior rule matched. */
11
+ rules: readonly PolicyRule[];
12
+ }
13
+ export declare const POLICY_TEMPLATES: {
14
+ readonly hipaa_healthcare: {
15
+ readonly id: "tpl_hipaa";
16
+ readonly name: "HIPAA Healthcare Agent";
17
+ readonly description: "For agents handling PHI. Blocks export, requires approval for writes, logs all reads.";
18
+ readonly rules: readonly [{
19
+ readonly id: "r1";
20
+ readonly action_types: ["export"];
21
+ readonly resource_pattern: "*";
22
+ readonly effect: "block";
23
+ }, {
24
+ readonly id: "r2";
25
+ readonly action_types: ["delete"];
26
+ readonly resource_pattern: "*";
27
+ readonly effect: "block";
28
+ }, {
29
+ readonly id: "r3";
30
+ readonly action_types: ["write"];
31
+ readonly resource_pattern: "phi/*";
32
+ readonly effect: "flag";
33
+ }, {
34
+ readonly id: "r4";
35
+ readonly action_types: ["read"];
36
+ readonly resource_pattern: "phi/*";
37
+ readonly effect: "allow";
38
+ }, {
39
+ readonly id: "r5";
40
+ readonly action_types: ("read" | "write" | "export" | "delete" | "call" | "payment" | "*")[];
41
+ readonly resource_pattern: "*";
42
+ readonly effect: "block";
43
+ }];
44
+ };
45
+ readonly fintech_payments: {
46
+ readonly id: "tpl_fintech";
47
+ readonly name: "Fintech Payments Agent";
48
+ readonly description: "For agents processing payments. All payment actions require human approval.";
49
+ readonly rules: readonly [{
50
+ readonly id: "r1";
51
+ readonly action_types: ["payment"];
52
+ readonly resource_pattern: "*";
53
+ readonly effect: "flag";
54
+ }, {
55
+ readonly id: "r2";
56
+ readonly action_types: ["delete"];
57
+ readonly resource_pattern: "*";
58
+ readonly effect: "block";
59
+ }, {
60
+ readonly id: "r3";
61
+ readonly action_types: ["export"];
62
+ readonly resource_pattern: "customer/*";
63
+ readonly effect: "flag";
64
+ }, {
65
+ readonly id: "r4";
66
+ readonly action_types: ["read"];
67
+ readonly resource_pattern: "customer/*";
68
+ readonly effect: "allow";
69
+ }, {
70
+ readonly id: "r5";
71
+ readonly action_types: ("read" | "write" | "export" | "delete" | "call" | "payment" | "*")[];
72
+ readonly resource_pattern: "*";
73
+ readonly effect: "block";
74
+ }];
75
+ };
76
+ readonly customer_support: {
77
+ readonly id: "tpl_support";
78
+ readonly name: "Customer Support Agent";
79
+ readonly description: "For agents responding to customer tickets. Read-only on customer data, write to tickets only.";
80
+ readonly rules: readonly [{
81
+ readonly id: "r1";
82
+ readonly action_types: ["read"];
83
+ readonly resource_pattern: "customers/*";
84
+ readonly effect: "allow";
85
+ }, {
86
+ readonly id: "r2";
87
+ readonly action_types: ["read"];
88
+ readonly resource_pattern: "tickets/*";
89
+ readonly effect: "allow";
90
+ }, {
91
+ readonly id: "r3";
92
+ readonly action_types: ["write"];
93
+ readonly resource_pattern: "tickets/*";
94
+ readonly effect: "allow";
95
+ }, {
96
+ readonly id: "r4";
97
+ readonly action_types: ["delete"];
98
+ readonly resource_pattern: "*";
99
+ readonly effect: "block";
100
+ }, {
101
+ readonly id: "r5";
102
+ readonly action_types: ["export"];
103
+ readonly resource_pattern: "*";
104
+ readonly effect: "block";
105
+ }, {
106
+ readonly id: "r6";
107
+ readonly action_types: ("read" | "write" | "export" | "delete" | "call" | "payment" | "*")[];
108
+ readonly resource_pattern: "*";
109
+ readonly effect: "block";
110
+ }];
111
+ };
112
+ readonly code_assistant: {
113
+ readonly id: "tpl_code";
114
+ readonly name: "Code Assistant Agent";
115
+ readonly description: "For agents that review or generate code. Read code, open PRs, no direct deploys.";
116
+ readonly rules: readonly [{
117
+ readonly id: "r1";
118
+ readonly action_types: ["read"];
119
+ readonly resource_pattern: "repo/*";
120
+ readonly effect: "allow";
121
+ }, {
122
+ readonly id: "r2";
123
+ readonly action_types: ["write"];
124
+ readonly resource_pattern: "repo/pull-requests/*";
125
+ readonly effect: "allow";
126
+ }, {
127
+ readonly id: "r3";
128
+ readonly action_types: ["call"];
129
+ readonly resource_pattern: "github/*";
130
+ readonly effect: "allow";
131
+ }, {
132
+ readonly id: "r4";
133
+ readonly action_types: ["call"];
134
+ readonly resource_pattern: "deploy/*";
135
+ readonly effect: "flag";
136
+ }, {
137
+ readonly id: "r5";
138
+ readonly action_types: ["delete"];
139
+ readonly resource_pattern: "*";
140
+ readonly effect: "block";
141
+ }, {
142
+ readonly id: "r6";
143
+ readonly action_types: ("read" | "write" | "export" | "delete" | "call" | "payment" | "*")[];
144
+ readonly resource_pattern: "*";
145
+ readonly effect: "block";
146
+ }];
147
+ };
148
+ readonly data_analyst: {
149
+ readonly id: "tpl_analyst";
150
+ readonly name: "Data Analyst Agent";
151
+ readonly description: "For agents running queries on data warehouses. Read-only, no writes or exports without approval.";
152
+ readonly rules: readonly [{
153
+ readonly id: "r1";
154
+ readonly action_types: ["read"];
155
+ readonly resource_pattern: "warehouse/*";
156
+ readonly effect: "allow";
157
+ }, {
158
+ readonly id: "r2";
159
+ readonly action_types: ["call"];
160
+ readonly resource_pattern: "warehouse/query/*";
161
+ readonly effect: "allow";
162
+ }, {
163
+ readonly id: "r3";
164
+ readonly action_types: ["export"];
165
+ readonly resource_pattern: "*";
166
+ readonly effect: "flag";
167
+ }, {
168
+ readonly id: "r4";
169
+ readonly action_types: ["write", "delete"];
170
+ readonly resource_pattern: "*";
171
+ readonly effect: "block";
172
+ }, {
173
+ readonly id: "r5";
174
+ readonly action_types: ("read" | "write" | "export" | "delete" | "call" | "payment" | "*")[];
175
+ readonly resource_pattern: "*";
176
+ readonly effect: "block";
177
+ }];
178
+ };
179
+ readonly sales_outbound: {
180
+ readonly id: "tpl_sales";
181
+ readonly name: "Sales Outbound Agent";
182
+ readonly description: "For agents running cold outreach. Write to CRM, send emails with approval, no exports.";
183
+ readonly rules: readonly [{
184
+ readonly id: "r1";
185
+ readonly action_types: ["read"];
186
+ readonly resource_pattern: "crm/*";
187
+ readonly effect: "allow";
188
+ }, {
189
+ readonly id: "r2";
190
+ readonly action_types: ["write"];
191
+ readonly resource_pattern: "crm/contacts/*";
192
+ readonly effect: "allow";
193
+ }, {
194
+ readonly id: "r3";
195
+ readonly action_types: ["call"];
196
+ readonly resource_pattern: "email/send";
197
+ readonly effect: "flag";
198
+ }, {
199
+ readonly id: "r4";
200
+ readonly action_types: ["export"];
201
+ readonly resource_pattern: "*";
202
+ readonly effect: "block";
203
+ }, {
204
+ readonly id: "r5";
205
+ readonly action_types: ["delete"];
206
+ readonly resource_pattern: "*";
207
+ readonly effect: "block";
208
+ }, {
209
+ readonly id: "r6";
210
+ readonly action_types: ("read" | "write" | "export" | "delete" | "call" | "payment" | "*")[];
211
+ readonly resource_pattern: "*";
212
+ readonly effect: "block";
213
+ }];
214
+ };
215
+ };
216
+ export type PolicyTemplateKey = keyof typeof POLICY_TEMPLATES;
217
+ /** Find a template by its key (e.g. `hipaa_healthcare`) or id (e.g. `tpl_hipaa`). */
218
+ export declare function findTemplate(keyOrId: string): PolicyTemplate | undefined;
219
+ /** Array form for UI rendering — preserves insertion order. */
220
+ export declare const POLICY_TEMPLATE_LIST: readonly (PolicyTemplate & {
221
+ key: PolicyTemplateKey;
222
+ })[];
223
+ //# sourceMappingURL=templates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/policies/templates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,WAAW,cAAc;IAC7B,6EAA6E;IAC7E,EAAE,EAAE,MAAM,CAAC;IACX,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,WAAW,EAAE,MAAM,CAAC;IACpB;uEACmE;IACnE,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;CAC9B;AAWD,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkFsB,CAAC;AAEpD,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,gBAAgB,CAAC;AAE9D,qFAAqF;AACrF,wBAAgB,YAAY,CAC1B,OAAO,EAAE,MAAM,GACd,cAAc,GAAG,SAAS,CAQ5B;AAED,+DAA+D;AAC/D,eAAO,MAAM,oBAAoB,EAAE,SAAS,CAAC,cAAc,GAAG;IAAE,GAAG,EAAE,iBAAiB,CAAA;CAAE,CAAC,EAIpF,CAAC"}
@@ -0,0 +1,102 @@
1
+ const ALL_ACTION_TYPES = [
2
+ 'read',
3
+ 'write',
4
+ 'delete',
5
+ 'export',
6
+ 'call',
7
+ 'payment',
8
+ ];
9
+ export const POLICY_TEMPLATES = {
10
+ hipaa_healthcare: {
11
+ id: 'tpl_hipaa',
12
+ name: 'HIPAA Healthcare Agent',
13
+ description: 'For agents handling PHI. Blocks export, requires approval for writes, logs all reads.',
14
+ rules: [
15
+ { id: 'r1', action_types: ['export'], resource_pattern: '*', effect: 'block' },
16
+ { id: 'r2', action_types: ['delete'], resource_pattern: '*', effect: 'block' },
17
+ { id: 'r3', action_types: ['write'], resource_pattern: 'phi/*', effect: 'flag' },
18
+ { id: 'r4', action_types: ['read'], resource_pattern: 'phi/*', effect: 'allow' },
19
+ { id: 'r5', action_types: ALL_ACTION_TYPES, resource_pattern: '*', effect: 'block' },
20
+ ],
21
+ },
22
+ fintech_payments: {
23
+ id: 'tpl_fintech',
24
+ name: 'Fintech Payments Agent',
25
+ description: 'For agents processing payments. All payment actions require human approval.',
26
+ rules: [
27
+ { id: 'r1', action_types: ['payment'], resource_pattern: '*', effect: 'flag' },
28
+ { id: 'r2', action_types: ['delete'], resource_pattern: '*', effect: 'block' },
29
+ { id: 'r3', action_types: ['export'], resource_pattern: 'customer/*', effect: 'flag' },
30
+ { id: 'r4', action_types: ['read'], resource_pattern: 'customer/*', effect: 'allow' },
31
+ { id: 'r5', action_types: ALL_ACTION_TYPES, resource_pattern: '*', effect: 'block' },
32
+ ],
33
+ },
34
+ customer_support: {
35
+ id: 'tpl_support',
36
+ name: 'Customer Support Agent',
37
+ description: 'For agents responding to customer tickets. Read-only on customer data, write to tickets only.',
38
+ rules: [
39
+ { id: 'r1', action_types: ['read'], resource_pattern: 'customers/*', effect: 'allow' },
40
+ { id: 'r2', action_types: ['read'], resource_pattern: 'tickets/*', effect: 'allow' },
41
+ { id: 'r3', action_types: ['write'], resource_pattern: 'tickets/*', effect: 'allow' },
42
+ { id: 'r4', action_types: ['delete'], resource_pattern: '*', effect: 'block' },
43
+ { id: 'r5', action_types: ['export'], resource_pattern: '*', effect: 'block' },
44
+ { id: 'r6', action_types: ALL_ACTION_TYPES, resource_pattern: '*', effect: 'block' },
45
+ ],
46
+ },
47
+ code_assistant: {
48
+ id: 'tpl_code',
49
+ name: 'Code Assistant Agent',
50
+ description: 'For agents that review or generate code. Read code, open PRs, no direct deploys.',
51
+ rules: [
52
+ { id: 'r1', action_types: ['read'], resource_pattern: 'repo/*', effect: 'allow' },
53
+ { id: 'r2', action_types: ['write'], resource_pattern: 'repo/pull-requests/*', effect: 'allow' },
54
+ { id: 'r3', action_types: ['call'], resource_pattern: 'github/*', effect: 'allow' },
55
+ { id: 'r4', action_types: ['call'], resource_pattern: 'deploy/*', effect: 'flag' },
56
+ { id: 'r5', action_types: ['delete'], resource_pattern: '*', effect: 'block' },
57
+ { id: 'r6', action_types: ALL_ACTION_TYPES, resource_pattern: '*', effect: 'block' },
58
+ ],
59
+ },
60
+ data_analyst: {
61
+ id: 'tpl_analyst',
62
+ name: 'Data Analyst Agent',
63
+ description: 'For agents running queries on data warehouses. Read-only, no writes or exports without approval.',
64
+ rules: [
65
+ { id: 'r1', action_types: ['read'], resource_pattern: 'warehouse/*', effect: 'allow' },
66
+ { id: 'r2', action_types: ['call'], resource_pattern: 'warehouse/query/*', effect: 'allow' },
67
+ { id: 'r3', action_types: ['export'], resource_pattern: '*', effect: 'flag' },
68
+ { id: 'r4', action_types: ['write', 'delete'], resource_pattern: '*', effect: 'block' },
69
+ { id: 'r5', action_types: ALL_ACTION_TYPES, resource_pattern: '*', effect: 'block' },
70
+ ],
71
+ },
72
+ sales_outbound: {
73
+ id: 'tpl_sales',
74
+ name: 'Sales Outbound Agent',
75
+ description: 'For agents running cold outreach. Write to CRM, send emails with approval, no exports.',
76
+ rules: [
77
+ { id: 'r1', action_types: ['read'], resource_pattern: 'crm/*', effect: 'allow' },
78
+ { id: 'r2', action_types: ['write'], resource_pattern: 'crm/contacts/*', effect: 'allow' },
79
+ { id: 'r3', action_types: ['call'], resource_pattern: 'email/send', effect: 'flag' },
80
+ { id: 'r4', action_types: ['export'], resource_pattern: '*', effect: 'block' },
81
+ { id: 'r5', action_types: ['delete'], resource_pattern: '*', effect: 'block' },
82
+ { id: 'r6', action_types: ALL_ACTION_TYPES, resource_pattern: '*', effect: 'block' },
83
+ ],
84
+ },
85
+ };
86
+ /** Find a template by its key (e.g. `hipaa_healthcare`) or id (e.g. `tpl_hipaa`). */
87
+ export function findTemplate(keyOrId) {
88
+ if (keyOrId in POLICY_TEMPLATES) {
89
+ return POLICY_TEMPLATES[keyOrId];
90
+ }
91
+ for (const template of Object.values(POLICY_TEMPLATES)) {
92
+ if (template.id === keyOrId)
93
+ return template;
94
+ }
95
+ return undefined;
96
+ }
97
+ /** Array form for UI rendering — preserves insertion order. */
98
+ export const POLICY_TEMPLATE_LIST = Object.keys(POLICY_TEMPLATES).map((key) => ({
99
+ key,
100
+ ...POLICY_TEMPLATES[key],
101
+ }));
102
+ //# sourceMappingURL=templates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../src/policies/templates.ts"],"names":[],"mappings":"AAcA,MAAM,gBAAgB,GAA+B;IACnD,MAAM;IACN,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,SAAS;CACV,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,gBAAgB,EAAE;QAChB,EAAE,EAAE,WAAW;QACf,IAAI,EAAE,wBAAwB;QAC9B,WAAW,EACT,uFAAuF;QACzF,KAAK,EAAE;YACL,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,QAAQ,CAAC,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE;YAC9E,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,QAAQ,CAAC,EAAE,gBAAgB,EAAE,GAA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AAG,EAAE,EAAE,CAAC,CAAC;IACnE,GAAG;IACH,GAAG,gBAAgB,CAAC,GAAG,CAAC;CACzB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,58 @@
1
+ export type RiskGrade = 'A+' | 'A' | 'B' | 'C' | 'D' | 'F';
2
+ export type RiskDomain = 'financial' | 'communication' | 'database' | 'external_api' | 'storage' | 'other';
3
+ export type RiskActionType = 'read' | 'write' | 'export' | 'delete' | 'call' | 'payment';
4
+ export interface RiskSeverityBucket {
5
+ events: number;
6
+ blocked: number;
7
+ flagged: number;
8
+ deduction: number;
9
+ }
10
+ export interface RiskIncidentPatterns {
11
+ hourly_spikes: Array<{
12
+ hour: string;
13
+ count: number;
14
+ ratio_over_average: number;
15
+ }>;
16
+ repeated_blocks: Array<{
17
+ resource: string;
18
+ blocked_count: number;
19
+ }>;
20
+ escalations: Array<{
21
+ resource: string;
22
+ chain: RiskActionType[];
23
+ started_at: string;
24
+ ended_at: string;
25
+ }>;
26
+ }
27
+ export interface RiskScoreRecord {
28
+ id?: string;
29
+ agent_id: string;
30
+ owner_id: string;
31
+ overall_score: number;
32
+ grade: RiskGrade;
33
+ severity_breakdown: Record<RiskActionType, RiskSeverityBucket>;
34
+ domain_classification: Record<RiskDomain, number>;
35
+ incident_patterns: RiskIncidentPatterns;
36
+ blocked_ratio: number;
37
+ flagged_ratio: number;
38
+ event_count: number;
39
+ window_days: number;
40
+ computed_at: string;
41
+ }
42
+ export interface RiskClientConfig {
43
+ /** Dashboard API base URL, e.g. 'https://dashboard.mandatez.com'. */
44
+ apiUrl: string;
45
+ /** Bearer API key ("mz_live_..."). */
46
+ apiKey: string;
47
+ }
48
+ /**
49
+ * Fetch the most recent risk score for an agent. The dashboard auto-computes
50
+ * a fresh score if none exists yet, so this never returns null.
51
+ */
52
+ export declare function getRiskScore(agentId: string, config: RiskClientConfig): Promise<RiskScoreRecord>;
53
+ /**
54
+ * Trigger a fresh risk score computation for an agent and return the new record.
55
+ * `windowDays` defaults to the dashboard's server-side default (30) when omitted.
56
+ */
57
+ export declare function computeRiskScore(agentId: string, config: RiskClientConfig, windowDays?: number): Promise<RiskScoreRecord>;
58
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/risk/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAC3D,MAAM,MAAM,UAAU,GAClB,WAAW,GACX,eAAe,GACf,UAAU,GACV,cAAc,GACd,SAAS,GACT,OAAO,CAAC;AAEZ,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;AAEzF,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,kBAAkB,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAClF,eAAe,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACpE,WAAW,EAAE,KAAK,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,cAAc,EAAE,CAAC;QACxB,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC,CAAC;CACJ;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,SAAS,CAAC;IACjB,kBAAkB,EAAE,MAAM,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;IAC/D,qBAAqB,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAClD,iBAAiB,EAAE,oBAAoB,CAAC;IACxC,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC/B,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;CAChB;AAeD;;;GAGG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,eAAe,CAAC,CAa1B;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,gBAAgB,EACxB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,eAAe,CAAC,CAiB1B"}
@@ -0,0 +1,45 @@
1
+ function normalizeUrl(url) {
2
+ return url.replace(/\/+$/, '');
3
+ }
4
+ async function readError(res, fallback) {
5
+ try {
6
+ const body = (await res.json());
7
+ return body.error ?? fallback;
8
+ }
9
+ catch {
10
+ return fallback;
11
+ }
12
+ }
13
+ /**
14
+ * Fetch the most recent risk score for an agent. The dashboard auto-computes
15
+ * a fresh score if none exists yet, so this never returns null.
16
+ */
17
+ export async function getRiskScore(agentId, config) {
18
+ const res = await fetch(`${normalizeUrl(config.apiUrl)}/api/risk/${agentId}`, {
19
+ method: 'GET',
20
+ headers: { Authorization: `Bearer ${config.apiKey}` },
21
+ });
22
+ if (!res.ok) {
23
+ throw new Error(`MandateZ getRiskScore failed: ${await readError(res, `HTTP ${res.status}`)}`);
24
+ }
25
+ return (await res.json());
26
+ }
27
+ /**
28
+ * Trigger a fresh risk score computation for an agent and return the new record.
29
+ * `windowDays` defaults to the dashboard's server-side default (30) when omitted.
30
+ */
31
+ export async function computeRiskScore(agentId, config, windowDays) {
32
+ const res = await fetch(`${normalizeUrl(config.apiUrl)}/api/risk/compute/${agentId}`, {
33
+ method: 'POST',
34
+ headers: {
35
+ Authorization: `Bearer ${config.apiKey}`,
36
+ 'Content-Type': 'application/json',
37
+ },
38
+ body: JSON.stringify(windowDays != null ? { window_days: windowDays } : {}),
39
+ });
40
+ if (!res.ok) {
41
+ throw new Error(`MandateZ computeRiskScore failed: ${await readError(res, `HTTP ${res.status}`)}`);
42
+ }
43
+ return (await res.json());
44
+ }
45
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/risk/index.ts"],"names":[],"mappings":"AAoDA,SAAS,YAAY,CAAC,GAAW;IAC/B,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACjC,CAAC;AAED,KAAK,UAAU,SAAS,CAAC,GAAa,EAAE,QAAgB;IACtD,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAuB,CAAC;QACtD,OAAO,IAAI,CAAC,KAAK,IAAI,QAAQ,CAAC;IAChC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,QAAQ,CAAC;IAClB,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,OAAe,EACf,MAAwB;IAExB,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,OAAO,EAAE,EAAE;QAC5E,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,MAAM,CAAC,MAAM,EAAE,EAAE;KACtD,CAAC,CAAC;IAEH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,iCAAiC,MAAM,SAAS,CAAC,GAAG,EAAE,QAAQ,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,CAC9E,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAoB,CAAC;AAC/C,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAe,EACf,MAAwB,EACxB,UAAmB;IAEnB,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,qBAAqB,OAAO,EAAE,EAAE;QACpF,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,aAAa,EAAE,UAAU,MAAM,CAAC,MAAM,EAAE;YACxC,cAAc,EAAE,kBAAkB;SACnC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC5E,CAAC,CAAC;IAEH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,qCAAqC,MAAM,SAAS,CAAC,GAAG,EAAE,QAAQ,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,CAClF,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAoB,CAAC;AAC/C,CAAC"}
@@ -1,4 +1,6 @@
1
1
  import type { AgentEvent } from '../events/schema.js';
2
+ import type { AgentTrustProfile } from '../trust/posture.js';
3
+ import type { IdentityCheckResult } from '../identity/hibp.js';
2
4
  export interface SupabaseTransportConfig {
3
5
  supabaseUrl: string;
4
6
  supabaseAnonKey: string;
@@ -6,10 +8,37 @@ export interface SupabaseTransportConfig {
6
8
  export declare class SupabaseTransport {
7
9
  private client;
8
10
  constructor(config: SupabaseTransportConfig);
11
+ /**
12
+ * Upserts an agent row. Idempotent — safe to call on every client startup.
13
+ */
14
+ upsertAgent(params: {
15
+ agentId: string;
16
+ ownerId: string;
17
+ name: string;
18
+ publicKey: string;
19
+ metadata?: Record<string, unknown>;
20
+ }): Promise<void>;
9
21
  /**
10
22
  * Inserts a signed AgentEvent into the agent_events table.
11
23
  * Throws on Supabase errors so callers can handle failures.
12
24
  */
13
25
  emitEvent(event: AgentEvent): Promise<AgentEvent>;
26
+ /**
27
+ * Fetches all events for an agent, ordered by timestamp.
28
+ */
29
+ fetchAgentEvents(agentId: string): Promise<AgentEvent[]>;
30
+ /**
31
+ * Inserts an identity check result into the identity_checks table.
32
+ */
33
+ insertIdentityCheck(params: {
34
+ ownerId: string;
35
+ agentId: string;
36
+ email: string;
37
+ result: IdentityCheckResult;
38
+ }): Promise<void>;
39
+ /**
40
+ * Updates the agent's trust profile columns in the agents table.
41
+ */
42
+ updateAgentTrust(agentId: string, profile: AgentTrustProfile): Promise<void>;
14
43
  }
15
44
  //# sourceMappingURL=supabase.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../../src/transport/supabase.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,WAAW,uBAAuB;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAiB;gBAEnB,MAAM,EAAE,uBAAuB;IAI3C;;;OAGG;IACG,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;CAqBxD"}
1
+ {"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../../src/transport/supabase.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE/D,MAAM,WAAW,uBAAuB;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAiB;gBAEnB,MAAM,EAAE,uBAAuB;IAI3C;;OAEG;IACG,WAAW,CAAC,MAAM,EAAE;QACxB,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACpC,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBjB;;;OAGG;IACG,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAsBvD;;OAEG;IACG,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IA0B9D;;OAEG;IACG,mBAAmB,CAAC,MAAM,EAAE;QAChC,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,mBAAmB,CAAC;KAC7B,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBjB;;OAEG;IACG,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;CAqBnF"}
@@ -4,6 +4,21 @@ export class SupabaseTransport {
4
4
  constructor(config) {
5
5
  this.client = createClient(config.supabaseUrl, config.supabaseAnonKey);
6
6
  }
7
+ /**
8
+ * Upserts an agent row. Idempotent — safe to call on every client startup.
9
+ */
10
+ async upsertAgent(params) {
11
+ const { error } = await this.client.from('agents').upsert({
12
+ id: params.agentId,
13
+ owner_id: params.ownerId,
14
+ name: params.name,
15
+ public_key: params.publicKey,
16
+ metadata: params.metadata ?? {},
17
+ }, { onConflict: 'id' });
18
+ if (error) {
19
+ throw new Error(`Failed to upsert agent: ${error.message}`);
20
+ }
21
+ }
7
22
  /**
8
23
  * Inserts a signed AgentEvent into the agent_events table.
9
24
  * Throws on Supabase errors so callers can handle failures.
@@ -27,5 +42,71 @@ export class SupabaseTransport {
27
42
  }
28
43
  return event;
29
44
  }
45
+ /**
46
+ * Fetches all events for an agent, ordered by timestamp.
47
+ */
48
+ async fetchAgentEvents(agentId) {
49
+ const { data, error } = await this.client
50
+ .from('agent_events')
51
+ .select('*')
52
+ .eq('agent_id', agentId)
53
+ .order('timestamp', { ascending: true });
54
+ if (error) {
55
+ throw new Error(`Failed to fetch agent events: ${error.message}`);
56
+ }
57
+ return (data ?? []).map((row) => ({
58
+ event_id: row.id,
59
+ agent_id: row.agent_id,
60
+ owner_id: row.owner_id,
61
+ timestamp: row.timestamp,
62
+ action_type: row.action_type,
63
+ resource: row.resource,
64
+ outcome: row.outcome,
65
+ policy_id: row.policy_id ?? null,
66
+ metadata: row.metadata ?? {},
67
+ signature: row.signature,
68
+ public_key: row.public_key,
69
+ }));
70
+ }
71
+ /**
72
+ * Inserts an identity check result into the identity_checks table.
73
+ */
74
+ async insertIdentityCheck(params) {
75
+ const { error } = await this.client.from('identity_checks').insert({
76
+ owner_id: params.ownerId,
77
+ agent_id: params.agentId,
78
+ email: params.email,
79
+ risk_score: params.result.risk_score,
80
+ breach_count: params.result.breach_count,
81
+ breaches: params.result.breaches,
82
+ status: params.result.status,
83
+ });
84
+ if (error) {
85
+ throw new Error(`Failed to insert identity check: ${error.message}`);
86
+ }
87
+ }
88
+ /**
89
+ * Updates the agent's trust profile columns in the agents table.
90
+ */
91
+ async updateAgentTrust(agentId, profile) {
92
+ const { error } = await this.client
93
+ .from('agents')
94
+ .update({
95
+ trust_score: profile.trust_score,
96
+ trust_grade: profile.trust_grade,
97
+ total_events: profile.total_events,
98
+ allowed_ratio: profile.allowed_ratio,
99
+ flagged_ratio: profile.flagged_ratio,
100
+ blocked_ratio: profile.blocked_ratio,
101
+ human_approvals: profile.human_approvals,
102
+ human_rejections: profile.human_rejections,
103
+ first_seen: profile.first_seen,
104
+ last_active: profile.last_active,
105
+ })
106
+ .eq('id', agentId);
107
+ if (error) {
108
+ throw new Error(`Failed to update agent trust: ${error.message}`);
109
+ }
110
+ }
30
111
  }
31
112
  //# sourceMappingURL=supabase.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"supabase.js","sourceRoot":"","sources":["../../src/transport/supabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAkB,MAAM,uBAAuB,CAAC;AAQrE,MAAM,OAAO,iBAAiB;IACpB,MAAM,CAAiB;IAE/B,YAAY,MAA+B;QACzC,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,eAAe,CAAC,CAAC;IACzE,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,SAAS,CAAC,KAAiB;QAC/B,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC;YAC9D,EAAE,EAAE,KAAK,CAAC,QAAQ;YAClB,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,QAAQ,EAAE,KAAK,CAAC,QAAQ;Y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;YAClC,aAAa,EAAE,OAAO,CAAC,aAAa;YACpC,aAAa,EAAE,OAAO,CAAC,aAAa;YACpC,aAAa,EAAE,OAAO,CAAC,aAAa;YACpC,eAAe,EAAE,OAAO,CAAC,eAAe;YACxC,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;YAC1C,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,WAAW,EAAE,OAAO,CAAC,WAAW;SACjC,CAAC;aACD,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAErB,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,iCAAiC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,24 @@
1
+ import type { AgentEvent } from '../events/schema.js';
2
+ export interface AgentTrustProfile {
3
+ trust_score: number;
4
+ trust_grade: 'unverified' | 'low' | 'medium' | 'high' | 'verified';
5
+ total_events: number;
6
+ allowed_ratio: number;
7
+ flagged_ratio: number;
8
+ blocked_ratio: number;
9
+ human_approvals: number;
10
+ human_rejections: number;
11
+ first_seen: string | null;
12
+ last_active: string | null;
13
+ }
14
+ /**
15
+ * Computes a trust score (0–100) and profile from an agent's event history.
16
+ *
17
+ * Scoring model:
18
+ * - Behavioral history 40pts: (allowed / total) * 40
19
+ * - Longevity 20pts: min(days_active / 90, 1) * 20
20
+ * - Human oversight 25pts: (approvals / (approvals + rejections + 1)) * 25
21
+ * - Policy compliance 15pts: (1 - blocked_ratio - flagged_ratio * 0.5) * 15
22
+ */
23
+ export declare function computeTrustScore(events: AgentEvent[]): AgentTrustProfile;
24
+ //# sourceMappingURL=posture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"posture.d.ts","sourceRoot":"","sources":["../../src/trust/posture.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,YAAY,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;IACnE,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAUD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,iBAAiB,CA8DzE"}