@mandatez/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.
Files changed (54) hide show
  1. package/README.md +95 -0
  2. package/dist/client.d.ts +53 -0
  3. package/dist/client.d.ts.map +1 -0
  4. package/dist/client.js +85 -0
  5. package/dist/client.js.map +1 -0
  6. package/dist/events/index.d.ts +4 -0
  7. package/dist/events/index.d.ts.map +1 -0
  8. package/dist/events/index.js +3 -0
  9. package/dist/events/index.js.map +1 -0
  10. package/dist/events/schema.d.ts +58 -0
  11. package/dist/events/schema.d.ts.map +1 -0
  12. package/dist/events/schema.js +28 -0
  13. package/dist/events/schema.js.map +1 -0
  14. package/dist/events/signing.d.ts +17 -0
  15. package/dist/events/signing.d.ts.map +1 -0
  16. package/dist/events/signing.js +60 -0
  17. package/dist/events/signing.js.map +1 -0
  18. package/dist/identity/index.d.ts +16 -0
  19. package/dist/identity/index.d.ts.map +1 -0
  20. package/dist/identity/index.js +18 -0
  21. package/dist/identity/index.js.map +1 -0
  22. package/dist/index.d.ts +17 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +13 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/integrations/langchain/index.d.ts +46 -0
  27. package/dist/integrations/langchain/index.d.ts.map +1 -0
  28. package/dist/integrations/langchain/index.js +91 -0
  29. package/dist/integrations/langchain/index.js.map +1 -0
  30. package/dist/integrations/n8n/index.d.ts +26 -0
  31. package/dist/integrations/n8n/index.d.ts.map +1 -0
  32. package/dist/integrations/n8n/index.js +39 -0
  33. package/dist/integrations/n8n/index.js.map +1 -0
  34. package/dist/oversight/alerts.d.ts +32 -0
  35. package/dist/oversight/alerts.d.ts.map +1 -0
  36. package/dist/oversight/alerts.js +49 -0
  37. package/dist/oversight/alerts.js.map +1 -0
  38. package/dist/oversight/index.d.ts +58 -0
  39. package/dist/oversight/index.d.ts.map +1 -0
  40. package/dist/oversight/index.js +77 -0
  41. package/dist/oversight/index.js.map +1 -0
  42. package/dist/policy/index.d.ts +68 -0
  43. package/dist/policy/index.d.ts.map +1 -0
  44. package/dist/policy/index.js +82 -0
  45. package/dist/policy/index.js.map +1 -0
  46. package/dist/transport/index.d.ts +3 -0
  47. package/dist/transport/index.d.ts.map +1 -0
  48. package/dist/transport/index.js +2 -0
  49. package/dist/transport/index.js.map +1 -0
  50. package/dist/transport/supabase.d.ts +15 -0
  51. package/dist/transport/supabase.d.ts.map +1 -0
  52. package/dist/transport/supabase.js +31 -0
  53. package/dist/transport/supabase.js.map +1 -0
  54. package/package.json +49 -0
@@ -0,0 +1,91 @@
1
+ /**
2
+ * MandateZ callback handler for LangChain.
3
+ *
4
+ * Implements the LangChain BaseCallbackHandler interface structurally —
5
+ * no @langchain/core dependency required. Pass this to any LangChain
6
+ * chain, agent, or LLM via the `callbacks` option.
7
+ *
8
+ * Tracked events:
9
+ * - handleLLMStart → action_type: 'call', resource: 'langchain/llm:{model}'
10
+ * - handleToolStart → action_type: 'call', resource: 'langchain/tool:{name}'
11
+ * - handleToolEnd → action_type: 'call', resource: 'langchain/tool:{name}'
12
+ * - handleChainError → action_type: 'call', resource: 'langchain/chain'
13
+ */
14
+ export class MandateZLangChainCallback {
15
+ name = 'MandateZLangChainCallback';
16
+ client;
17
+ events = [];
18
+ constructor(client) {
19
+ this.client = client;
20
+ }
21
+ /** Returns all events tracked during this callback's lifetime. */
22
+ getEvents() {
23
+ return [...this.events];
24
+ }
25
+ /**
26
+ * Called when an LLM starts processing.
27
+ */
28
+ async handleLLMStart(llm, prompts) {
29
+ const model = llm.name ?? llm.id?.join('/') ?? 'unknown';
30
+ const event = await this.client.track({
31
+ action_type: 'call',
32
+ resource: `langchain/llm:${model}`,
33
+ outcome: 'allowed',
34
+ metadata: {
35
+ hook: 'llm_start',
36
+ model,
37
+ prompt_count: prompts.length,
38
+ },
39
+ });
40
+ this.events.push(event);
41
+ }
42
+ /**
43
+ * Called when a tool starts executing.
44
+ */
45
+ async handleToolStart(tool, input) {
46
+ const toolName = tool.name ?? tool.id ?? 'unknown';
47
+ const event = await this.client.track({
48
+ action_type: 'call',
49
+ resource: `langchain/tool:${toolName}`,
50
+ outcome: 'pending_approval',
51
+ metadata: {
52
+ hook: 'tool_start',
53
+ tool: toolName,
54
+ input_length: input.length,
55
+ },
56
+ });
57
+ this.events.push(event);
58
+ }
59
+ /**
60
+ * Called when a tool finishes executing.
61
+ */
62
+ async handleToolEnd(output) {
63
+ const event = await this.client.track({
64
+ action_type: 'call',
65
+ resource: 'langchain/tool',
66
+ outcome: 'allowed',
67
+ metadata: {
68
+ hook: 'tool_end',
69
+ output_length: output.length,
70
+ },
71
+ });
72
+ this.events.push(event);
73
+ }
74
+ /**
75
+ * Called when a chain encounters an error.
76
+ */
77
+ async handleChainError(error) {
78
+ const message = error instanceof Error ? error.message : String(error);
79
+ const event = await this.client.track({
80
+ action_type: 'call',
81
+ resource: 'langchain/chain',
82
+ outcome: 'flagged',
83
+ metadata: {
84
+ hook: 'chain_error',
85
+ error: message,
86
+ },
87
+ });
88
+ this.events.push(event);
89
+ }
90
+ }
91
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/integrations/langchain/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,yBAAyB;IACpC,IAAI,GAAG,2BAA2B,CAAC;IAE3B,MAAM,CAAiB;IACvB,MAAM,GAAiB,EAAE,CAAC;IAElC,YAAY,MAAsB;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,kEAAkE;IAClE,SAAS;QACP,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,cAAc,CAClB,GAAqC,EACrC,OAAiB;QAEjB,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,EAAE,EAAE,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,CAAC,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,gBAAgB,CAAC,KAAc;QACnC,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;YACpC,WAAW,EAAE,MAAM;YACnB,QAAQ,EAAE,iBAAiB;YAC3B,OAAO,EAAE,SAAS;YAClB,QAAQ,EAAE;gBACR,IAAI,EAAE,aAAa;gBACnB,KAAK,EAAE,OAAO;aACf;SACF,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;CACF"}
@@ -0,0 +1,26 @@
1
+ import { MandateZClient } from '../../client.js';
2
+ import type { AgentEvent } from '../../events/schema.js';
3
+ export interface N8nExecutionContext {
4
+ workflowId: string;
5
+ nodeName: string;
6
+ }
7
+ /**
8
+ * MandateZ hook for n8n workflows.
9
+ *
10
+ * Drop this into any n8n custom node or credential hook to get
11
+ * cryptographically signed audit logs for every workflow execution.
12
+ */
13
+ export declare class MandateZN8nHook {
14
+ private client;
15
+ constructor(client: MandateZClient);
16
+ /**
17
+ * Call before a node executes. Logs a 'call' action with 'pending_approval'.
18
+ */
19
+ beforeExecution(workflowId: string, nodeName: string, inputData: Record<string, unknown>): Promise<AgentEvent>;
20
+ /**
21
+ * Call after a node executes. Logs a 'call' action with
22
+ * 'allowed' on success or 'flagged' on failure.
23
+ */
24
+ afterExecution(workflowId: string, nodeName: string, outputData: Record<string, unknown>, success: boolean): Promise<AgentEvent>;
25
+ }
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/integrations/n8n/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAMD;;;;;GAKG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAiB;gBAEnB,MAAM,EAAE,cAAc;IAIlC;;OAEG;IACG,eAAe,CACnB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,OAAO,CAAC,UAAU,CAAC;IAStB;;;OAGG;IACG,cAAc,CAClB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,UAAU,CAAC;CAQvB"}
@@ -0,0 +1,39 @@
1
+ function formatResource(ctx) {
2
+ return `n8n/workflow:${ctx.workflowId}/node:${ctx.nodeName}`;
3
+ }
4
+ /**
5
+ * MandateZ hook for n8n workflows.
6
+ *
7
+ * Drop this into any n8n custom node or credential hook to get
8
+ * cryptographically signed audit logs for every workflow execution.
9
+ */
10
+ export class MandateZN8nHook {
11
+ client;
12
+ constructor(client) {
13
+ this.client = client;
14
+ }
15
+ /**
16
+ * Call before a node executes. Logs a 'call' action with 'pending_approval'.
17
+ */
18
+ async beforeExecution(workflowId, nodeName, inputData) {
19
+ return this.client.track({
20
+ action_type: 'call',
21
+ resource: formatResource({ workflowId, nodeName }),
22
+ outcome: 'pending_approval',
23
+ metadata: { direction: 'before', inputData },
24
+ });
25
+ }
26
+ /**
27
+ * Call after a node executes. Logs a 'call' action with
28
+ * 'allowed' on success or 'flagged' on failure.
29
+ */
30
+ async afterExecution(workflowId, nodeName, outputData, success) {
31
+ return this.client.track({
32
+ action_type: 'call',
33
+ resource: formatResource({ workflowId, nodeName }),
34
+ outcome: success ? 'allowed' : 'flagged',
35
+ metadata: { direction: 'after', outputData, success },
36
+ });
37
+ }
38
+ }
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/integrations/n8n/index.ts"],"names":[],"mappings":"AAQA,SAAS,cAAc,CAAC,GAAwB;IAC9C,OAAO,gBAAgB,GAAG,CAAC,UAAU,SAAS,GAAG,CAAC,QAAQ,EAAE,CAAC;AAC/D,CAAC;AAED;;;;;GAKG;AACH,MAAM,OAAO,eAAe;IAClB,MAAM,CAAiB;IAE/B,YAAY,MAAsB;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,eAAe,CACnB,UAAkB,EAClB,QAAgB,EAChB,SAAkC;QAElC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;YACvB,WAAW,EAAE,MAAM;YACnB,QAAQ,EAAE,cAAc,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;YAClD,OAAO,EAAE,kBAAkB;YAC3B,QAAQ,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE;SAC7C,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,cAAc,CAClB,UAAkB,EAClB,QAAgB,EAChB,UAAmC,EACnC,OAAgB;QAEhB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;YACvB,WAAW,EAAE,MAAM;YACnB,QAAQ,EAAE,cAAc,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;YAClD,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;YACxC,QAAQ,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE;SACtD,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,32 @@
1
+ export interface OversightAlert {
2
+ agent_id: string;
3
+ action_type: string;
4
+ resource: string;
5
+ metadata: Record<string, unknown>;
6
+ timestamp: string;
7
+ requires_approval: boolean;
8
+ }
9
+ /**
10
+ * Alert channel interface — implement this to add new notification targets.
11
+ */
12
+ export interface AlertChannel {
13
+ send(alert: OversightAlert): Promise<void>;
14
+ }
15
+ /**
16
+ * Sends alerts to a Slack webhook URL.
17
+ */
18
+ export declare class SlackAlertChannel implements AlertChannel {
19
+ private webhookUrl;
20
+ constructor(webhookUrl: string);
21
+ send(alert: OversightAlert): Promise<void>;
22
+ }
23
+ /**
24
+ * Sends alerts to an arbitrary webhook URL as JSON POST.
25
+ */
26
+ export declare class WebhookAlertChannel implements AlertChannel {
27
+ private url;
28
+ private headers;
29
+ constructor(url: string, headers?: Record<string, string>);
30
+ send(alert: OversightAlert): Promise<void>;
31
+ }
32
+ //# sourceMappingURL=alerts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alerts.d.ts","sourceRoot":"","sources":["../../src/oversight/alerts.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5C;AAED;;GAEG;AACH,qBAAa,iBAAkB,YAAW,YAAY;IACpD,OAAO,CAAC,UAAU,CAAS;gBAEf,UAAU,EAAE,MAAM;IAIxB,IAAI,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAoBjD;AAED;;GAEG;AACH,qBAAa,mBAAoB,YAAW,YAAY;IACtD,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,OAAO,CAAyB;gBAE5B,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM;IAKvD,IAAI,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAWjD"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Sends alerts to a Slack webhook URL.
3
+ */
4
+ export class SlackAlertChannel {
5
+ webhookUrl;
6
+ constructor(webhookUrl) {
7
+ this.webhookUrl = webhookUrl;
8
+ }
9
+ async send(alert) {
10
+ const emoji = alert.requires_approval ? ':rotating_light:' : ':warning:';
11
+ const text = [
12
+ `${emoji} *MandateZ Oversight Alert*`,
13
+ `*Agent:* \`${alert.agent_id}\``,
14
+ `*Action:* ${alert.action_type} on \`${alert.resource}\``,
15
+ `*Requires Approval:* ${alert.requires_approval ? 'Yes' : 'No'}`,
16
+ `*Time:* ${alert.timestamp}`,
17
+ ].join('\n');
18
+ const response = await fetch(this.webhookUrl, {
19
+ method: 'POST',
20
+ headers: { 'Content-Type': 'application/json' },
21
+ body: JSON.stringify({ text }),
22
+ });
23
+ if (!response.ok) {
24
+ throw new Error(`Slack alert failed: ${response.status} ${response.statusText}`);
25
+ }
26
+ }
27
+ }
28
+ /**
29
+ * Sends alerts to an arbitrary webhook URL as JSON POST.
30
+ */
31
+ export class WebhookAlertChannel {
32
+ url;
33
+ headers;
34
+ constructor(url, headers = {}) {
35
+ this.url = url;
36
+ this.headers = headers;
37
+ }
38
+ async send(alert) {
39
+ const response = await fetch(this.url, {
40
+ method: 'POST',
41
+ headers: { 'Content-Type': 'application/json', ...this.headers },
42
+ body: JSON.stringify(alert),
43
+ });
44
+ if (!response.ok) {
45
+ throw new Error(`Webhook alert failed: ${response.status} ${response.statusText}`);
46
+ }
47
+ }
48
+ }
49
+ //# sourceMappingURL=alerts.js.map
@@ -0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C;QACf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,KAAqB;QAC9B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;YACrC,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE;YAChE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;SAC5B,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;QACrF,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,58 @@
1
+ import type { AgentEventInput } from '../events/schema.js';
2
+ import type { AlertChannel, OversightAlert } from './alerts.js';
3
+ export type { AlertChannel, OversightAlert } from './alerts.js';
4
+ export { SlackAlertChannel, WebhookAlertChannel } from './alerts.js';
5
+ export type TimeoutAction = 'block' | 'allow';
6
+ export interface OversightConfig {
7
+ /** Action types that require human approval before proceeding */
8
+ require_human_approval: AgentEventInput['action_type'][];
9
+ /** Alert channels to notify when approval is needed */
10
+ channels: AlertChannel[];
11
+ /** Seconds to wait for human response before timeout_action kicks in */
12
+ timeout_seconds: number;
13
+ /** What to do if no human responds in time */
14
+ timeout_action: TimeoutAction;
15
+ }
16
+ export type ApprovalDecision = 'approved' | 'rejected' | 'timeout';
17
+ export interface OversightResult {
18
+ decision: ApprovalDecision;
19
+ outcome: 'allowed' | 'blocked';
20
+ timed_out: boolean;
21
+ }
22
+ /**
23
+ * Human oversight gate.
24
+ *
25
+ * When an agent attempts a flagged action type, execution pauses,
26
+ * alerts fire, and we wait for a human decision or timeout.
27
+ *
28
+ * The approval callback is injected by the caller — this keeps the gate
29
+ * transport-agnostic (could be a webhook, a Supabase realtime subscription,
30
+ * a CLI prompt, etc).
31
+ */
32
+ export declare class OversightGate {
33
+ private config;
34
+ constructor(config: OversightConfig);
35
+ /**
36
+ * Does this action type require human approval?
37
+ */
38
+ requiresApproval(actionType: AgentEventInput['action_type']): boolean;
39
+ /**
40
+ * Fire alerts on all configured channels.
41
+ * Errors on individual channels are collected, not thrown,
42
+ * so one failing channel doesn't block the others.
43
+ */
44
+ sendAlerts(alert: OversightAlert): Promise<{
45
+ errors: Error[];
46
+ }>;
47
+ /**
48
+ * Request human approval. Fires alerts, then races the approval
49
+ * callback against the timeout.
50
+ *
51
+ * @param alert - The alert payload describing the action
52
+ * @param waitForApproval - Async function that resolves when a human
53
+ * responds. Should return true for approved, false for rejected.
54
+ * If not provided, the gate immediately applies timeout_action.
55
+ */
56
+ requestApproval(alert: OversightAlert, waitForApproval?: () => Promise<boolean>): Promise<OversightResult>;
57
+ }
58
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/oversight/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEhE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAErE,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,OAAO,CAAC;AAE9C,MAAM,WAAW,eAAe;IAC9B,iEAAiE;IACjE,sBAAsB,EAAE,eAAe,CAAC,aAAa,CAAC,EAAE,CAAC;IACzD,uDAAuD;IACvD,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,wEAAwE;IACxE,eAAe,EAAE,MAAM,CAAC;IACxB,8CAA8C;IAC9C,cAAc,EAAE,aAAa,CAAC;CAC/B;AAED,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,CAAC;AAEnE,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,OAAO,EAAE,SAAS,GAAG,SAAS,CAAC;IAC/B,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAkB;gBAEpB,MAAM,EAAE,eAAe;IAInC;;OAEG;IACH,gBAAgB,CAAC,UAAU,EAAE,eAAe,CAAC,aAAa,CAAC,GAAG,OAAO;IAIrE;;;;OAIG;IACG,UAAU,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,KAAK,EAAE,CAAA;KAAE,CAAC;IAgBrE;;;;;;;;OAQG;IACG,eAAe,CACnB,KAAK,EAAE,cAAc,EACrB,eAAe,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GACvC,OAAO,CAAC,eAAe,CAAC;CAiC5B"}
@@ -0,0 +1,77 @@
1
+ export { SlackAlertChannel, WebhookAlertChannel } from './alerts.js';
2
+ /**
3
+ * Human oversight gate.
4
+ *
5
+ * When an agent attempts a flagged action type, execution pauses,
6
+ * alerts fire, and we wait for a human decision or timeout.
7
+ *
8
+ * The approval callback is injected by the caller — this keeps the gate
9
+ * transport-agnostic (could be a webhook, a Supabase realtime subscription,
10
+ * a CLI prompt, etc).
11
+ */
12
+ export class OversightGate {
13
+ config;
14
+ constructor(config) {
15
+ this.config = config;
16
+ }
17
+ /**
18
+ * Does this action type require human approval?
19
+ */
20
+ requiresApproval(actionType) {
21
+ return this.config.require_human_approval.includes(actionType);
22
+ }
23
+ /**
24
+ * Fire alerts on all configured channels.
25
+ * Errors on individual channels are collected, not thrown,
26
+ * so one failing channel doesn't block the others.
27
+ */
28
+ async sendAlerts(alert) {
29
+ const errors = [];
30
+ await Promise.all(this.config.channels.map(async (channel) => {
31
+ try {
32
+ await channel.send(alert);
33
+ }
34
+ catch (err) {
35
+ errors.push(err instanceof Error ? err : new Error(String(err)));
36
+ }
37
+ }));
38
+ return { errors };
39
+ }
40
+ /**
41
+ * Request human approval. Fires alerts, then races the approval
42
+ * callback against the timeout.
43
+ *
44
+ * @param alert - The alert payload describing the action
45
+ * @param waitForApproval - Async function that resolves when a human
46
+ * responds. Should return true for approved, false for rejected.
47
+ * If not provided, the gate immediately applies timeout_action.
48
+ */
49
+ async requestApproval(alert, waitForApproval) {
50
+ // Fire alerts (non-blocking on individual channel failures)
51
+ await this.sendAlerts(alert);
52
+ // If no approval callback, immediately apply timeout action
53
+ if (!waitForApproval) {
54
+ return {
55
+ decision: 'timeout',
56
+ outcome: this.config.timeout_action === 'block' ? 'blocked' : 'allowed',
57
+ timed_out: true,
58
+ };
59
+ }
60
+ // Race: human response vs timeout
61
+ const timeoutMs = this.config.timeout_seconds * 1000;
62
+ const result = await Promise.race([
63
+ waitForApproval().then((approved) => ({
64
+ decision: approved ? 'approved' : 'rejected',
65
+ outcome: approved ? 'allowed' : 'blocked',
66
+ timed_out: false,
67
+ })),
68
+ new Promise((resolve) => setTimeout(() => resolve({
69
+ decision: 'timeout',
70
+ outcome: this.config.timeout_action === 'block' ? 'blocked' : 'allowed',
71
+ timed_out: true,
72
+ }), timeoutMs)),
73
+ ]);
74
+ return result;
75
+ }
76
+ }
77
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/oversight/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAuBrE;;;;;;;;;GASG;AACH,MAAM,OAAO,aAAa;IAChB,MAAM,CAAkB;IAEhC,YAAY,MAAuB;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,gBAAgB,CAAC,UAA0C;QACzD,OAAO,IAAI,CAAC,MAAM,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Q,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU;gBAC5C,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;gBACzC,SAAS,EAAE,KAAK;aACjB,CAAC,CAAC;YACH,IAAI,OAAO,CAAkB,CAAC,OAAO,EAAE,EAAE,CACvC,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC;gBACvB,QAAQ,EAAE,SAAS;gBACnB,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,cAAc,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;gBACvE,SAAS,EAAE,IAAI;aAChB,CAAC,EAAE,SAAS,CAAC,CACf;SACF,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -0,0 +1,68 @@
1
+ import { z } from 'zod';
2
+ import type { AgentEventInput } from '../events/schema.js';
3
+ export declare const PolicyRuleSchema: z.ZodObject<{
4
+ id: z.ZodString;
5
+ action_types: z.ZodArray<z.ZodEnum<{
6
+ read: "read";
7
+ write: "write";
8
+ export: "export";
9
+ delete: "delete";
10
+ call: "call";
11
+ payment: "payment";
12
+ "*": "*";
13
+ }>>;
14
+ resource_pattern: z.ZodString;
15
+ effect: z.ZodEnum<{
16
+ allow: "allow";
17
+ block: "block";
18
+ flag: "flag";
19
+ }>;
20
+ }, z.core.$strip>;
21
+ export type PolicyRule = z.infer<typeof PolicyRuleSchema>;
22
+ export declare const PolicySchema: z.ZodObject<{
23
+ id: z.ZodString;
24
+ owner_id: z.ZodString;
25
+ name: z.ZodString;
26
+ rules: z.ZodArray<z.ZodObject<{
27
+ id: z.ZodString;
28
+ action_types: z.ZodArray<z.ZodEnum<{
29
+ read: "read";
30
+ write: "write";
31
+ export: "export";
32
+ delete: "delete";
33
+ call: "call";
34
+ payment: "payment";
35
+ "*": "*";
36
+ }>>;
37
+ resource_pattern: z.ZodString;
38
+ effect: z.ZodEnum<{
39
+ allow: "allow";
40
+ block: "block";
41
+ flag: "flag";
42
+ }>;
43
+ }, z.core.$strip>>;
44
+ }, z.core.$strip>;
45
+ export type Policy = z.infer<typeof PolicySchema>;
46
+ export type PolicyOutcome = 'allowed' | 'blocked' | 'flagged';
47
+ export interface PolicyEvaluation {
48
+ outcome: PolicyOutcome;
49
+ matched_rule: PolicyRule | null;
50
+ policy_id: string | null;
51
+ }
52
+ /**
53
+ * Policy engine — evaluates rules against an action.
54
+ *
55
+ * Rules are evaluated in order. First match wins.
56
+ * If no rule matches, the default outcome is 'allowed'.
57
+ */
58
+ export declare class PolicyEngine {
59
+ private policies;
60
+ addPolicy(policy: Policy): void;
61
+ removePolicy(policyId: string): void;
62
+ /**
63
+ * Evaluate all policies against an action.
64
+ * First matching rule across all policies wins.
65
+ */
66
+ evaluate(actionType: AgentEventInput['action_type'], resource: string): PolicyEvaluation;
67
+ }
68
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/policy/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;iBAQ3B,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;iBAKvB,CAAC;AAEH,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAElD,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAE9D,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,aAAa,CAAC;IACvB,YAAY,EAAE,UAAU,GAAG,IAAI,CAAC;IAChC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAiCD;;;;;GAKG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAgB;IAEhC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK/B,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAIpC;;;OAGG;IACH,QAAQ,CACN,UAAU,EAAE,eAAe,CAAC,aAAa,CAAC,EAC1C,QAAQ,EAAE,MAAM,GACf,gBAAgB;CAmBpB"}
@@ -0,0 +1,82 @@
1
+ import { z } from 'zod';
2
+ export const PolicyRuleSchema = z.object({
3
+ id: z.string().min(1),
4
+ /** Which action types this rule applies to. '*' means all. */
5
+ action_types: z.array(z.enum(['read', 'write', 'export', 'delete', 'call', 'payment', '*'])),
6
+ /** Glob-like resource pattern. '*' matches everything. */
7
+ resource_pattern: z.string().min(1),
8
+ /** The effect when this rule matches */
9
+ effect: z.enum(['allow', 'block', 'flag']),
10
+ });
11
+ export const PolicySchema = z.object({
12
+ id: z.string().min(1),
13
+ owner_id: z.string().min(1),
14
+ name: z.string().min(1),
15
+ rules: z.array(PolicyRuleSchema),
16
+ });
17
+ /**
18
+ * Matches a resource string against a pattern.
19
+ * Supports '*' as a wildcard segment and '**' as a recursive wildcard.
20
+ *
21
+ * 'emails' matches 'emails'
22
+ * 'api/*' matches 'api/stripe', 'api/slack'
23
+ * 'api/**' matches 'api/stripe', 'api/stripe/charges'
24
+ * '*' matches everything
25
+ */
26
+ function matchResource(pattern, resource) {
27
+ if (pattern === '*')
28
+ return true;
29
+ const patternParts = pattern.split('/');
30
+ const resourceParts = resource.split('/');
31
+ let pi = 0;
32
+ let ri = 0;
33
+ while (pi < patternParts.length && ri < resourceParts.length) {
34
+ if (patternParts[pi] === '**')
35
+ return true;
36
+ if (patternParts[pi] === '*' || patternParts[pi] === resourceParts[ri]) {
37
+ pi++;
38
+ ri++;
39
+ }
40
+ else {
41
+ return false;
42
+ }
43
+ }
44
+ return pi === patternParts.length && ri === resourceParts.length;
45
+ }
46
+ /**
47
+ * Policy engine — evaluates rules against an action.
48
+ *
49
+ * Rules are evaluated in order. First match wins.
50
+ * If no rule matches, the default outcome is 'allowed'.
51
+ */
52
+ export class PolicyEngine {
53
+ policies = [];
54
+ addPolicy(policy) {
55
+ PolicySchema.parse(policy);
56
+ this.policies.push(policy);
57
+ }
58
+ removePolicy(policyId) {
59
+ this.policies = this.policies.filter((p) => p.id !== policyId);
60
+ }
61
+ /**
62
+ * Evaluate all policies against an action.
63
+ * First matching rule across all policies wins.
64
+ */
65
+ evaluate(actionType, resource) {
66
+ for (const policy of this.policies) {
67
+ for (const rule of policy.rules) {
68
+ const actionMatch = rule.action_types.includes('*') || rule.action_types.includes(actionType);
69
+ const resourceMatch = matchResource(rule.resource_pattern, resource);
70
+ if (actionMatch && resourceMatch) {
71
+ return {
72
+ outcome: rule.effect === 'allow' ? 'allowed' : rule.effect === 'block' ? 'blocked' : 'flagged',
73
+ matched_rule: rule,
74
+ policy_id: policy.id,
75
+ };
76
+ }
77
+ }
78
+ }
79
+ return { outcome: 'allowed', matched_rule: null, policy_id: null };
80
+ }
81
+ }
82
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/policy/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACrB,8DAA8D;IAC9D,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC,CAA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AAE;qBACrB,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACrE,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export { SupabaseTransport } from './supabase.js';
2
+ export type { SupabaseTransportConfig } from './supabase.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,YAAY,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { SupabaseTransport } from './supabase.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { AgentEvent } from '../events/schema.js';
2
+ export interface SupabaseTransportConfig {
3
+ supabaseUrl: string;
4
+ supabaseAnonKey: string;
5
+ }
6
+ export declare class SupabaseTransport {
7
+ private client;
8
+ constructor(config: SupabaseTransportConfig);
9
+ /**
10
+ * Inserts a signed AgentEvent into the agent_events table.
11
+ * Throws on Supabase errors so callers can handle failures.
12
+ */
13
+ emitEvent(event: AgentEvent): Promise<AgentEvent>;
14
+ }
15
+ //# sourceMappingURL=supabase.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,31 @@
1
+ import { createClient } from '@supabase/supabase-js';
2
+ export class SupabaseTransport {
3
+ client;
4
+ constructor(config) {
5
+ this.client = createClient(config.supabaseUrl, config.supabaseAnonKey);
6
+ }
7
+ /**
8
+ * Inserts a signed AgentEvent into the agent_events table.
9
+ * Throws on Supabase errors so callers can handle failures.
10
+ */
11
+ async emitEvent(event) {
12
+ const { error } = await this.client.from('agent_events').insert({
13
+ id: event.event_id,
14
+ agent_id: event.agent_id,
15
+ owner_id: event.owner_id,
16
+ timestamp: event.timestamp,
17
+ action_type: event.action_type,
18
+ resource: event.resource,
19
+ outcome: event.outcome,
20
+ policy_id: event.policy_id,
21
+ metadata: event.metadata,
22
+ signature: event.signature,
23
+ public_key: event.public_key,
24
+ });
25
+ if (error) {
26
+ throw new Error(`Failed to emit event: ${error.message}`);
27
+ }
28
+ return event;
29
+ }
30
+ }
31
+ //# sourceMappingURL=supabase.js.map
@@ -0,0 +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;YACxB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,UAAU,EAAE,KAAK,CAAC,UAAU;SAC7B,CAAC,CAAC;QAEH,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,yBAAyB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}