forma-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/gate.js ADDED
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ /**
3
+ * FORMA Local Gate — TypeScript port of Python gate_local.py
4
+ * Evaluates prompts locally in <1ms — no network hop on the critical path.
5
+ * PII patterns + threat detection keep sensitive data from leaving the process.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.PII_PACKS = exports.PACK_FLAGS = void 0;
9
+ exports.normalize = normalize;
10
+ exports.detectPii = detectPii;
11
+ exports.detectThreat = detectThreat;
12
+ exports.buildBootstrapPolicy = buildBootstrapPolicy;
13
+ exports.evaluateLocal = evaluateLocal;
14
+ // ── Unicode normalization + homoglyph defence ─────────────────────────────────
15
+ const HOMOGLYPHS = {
16
+ "І": "I", "і": "i", "р": "p", "Р": "P", "а": "a", "А": "A",
17
+ "е": "e", "Е": "E", "о": "o", "О": "O", "с": "c", "С": "C",
18
+ "х": "x", "Х": "X", "ѕ": "s", "ν": "v", "ɑ": "a", "ɡ": "g",
19
+ };
20
+ function normalize(text) {
21
+ // Replace Cyrillic/Greek homoglyphs with ASCII equivalents before scanning
22
+ return Array.from(text).map(ch => { var _a; return (_a = HOMOGLYPHS[ch]) !== null && _a !== void 0 ? _a : ch; }).join("");
23
+ }
24
+ const PII_PATTERNS = [
25
+ // Core India PII
26
+ { label: "Aadhaar number", pattern: /\b(?:\d{4}[\s,./]?\d{4}[\s,./]?\d{4}|\d(?:[\s,.]\d){11})\b/g },
27
+ { label: "Indian PAN", pattern: /\b[A-Z]{5}\d{4}[A-Z]\b/g },
28
+ { label: "SSN", pattern: /\b\d{3}-\d{2}-\d{4}\b/g },
29
+ { label: "Email address", pattern: /\b[A-Za-z0-9._%+\-]+@[A-Za-z0-9.\-]+\.[A-Za-z]{2,}\b/g },
30
+ { label: "Phone number", pattern: /\b(?:\+?91[\-\s]?)?[6-9]\d{4}[\s\-]?\d{5}\b/g },
31
+ // India additions (DPDP moat)
32
+ { label: "GSTIN", pattern: /\b\d{2}[A-Z]{5}\d{4}[A-Z][A-Z\d]Z[A-Z\d]\b/g },
33
+ { label: "UPI ID", pattern: /\b[a-zA-Z0-9][a-zA-Z0-9.\-_]{1,98}@(?:ok[a-z]+|paytm|ybl|apl|upi|ibl|axl|sbi|hdfcbank|hdfc|icici|axisbank|axis|kotak|fbl|yapl|jupiteraxis|barodampay|airtel|jio|freecharge|cnrb|idfcfirst|dbs|indus|abfspay|kbl|federal|pingpay|naviaxis|rmhdfc|waaxis|yesg|timecosmos)\b/gi },
34
+ { label: "Indian Passport", pattern: /\b[A-PR-WY][1-9]\d\s?\d{4}[1-9]\b/g },
35
+ { label: "IFSC code", pattern: /\b[A-Z]{4}0[A-Z0-9]{6}\b/g },
36
+ { label: "Driving License", pattern: /\bDL[-\s]?\d{13}\b/gi },
37
+ { label: "Date of birth", pattern: /(?:dob|date[\s._-]?of[\s._-]?birth)[:\s]*\d{1,2}[/\-]\d{1,2}[/\-]\d{2,4}/gi },
38
+ // Cards (space-separated only — dashes = ref numbers)
39
+ { label: "Visa card", pattern: /(?<![0-9\-])4\d{3}\s?\d{4}\s?\d{4}\s?\d{1,4}(?![0-9\-])/g },
40
+ { label: "Mastercard", pattern: /(?<![0-9\-])5[1-5]\d{2}\s?\d{4}\s?\d{4}\s?\d{4}(?![0-9\-])/g },
41
+ { label: "Amex", pattern: /(?<![0-9\-])3[47]\d{2}\s?\d{6}\s?\d{5}(?![0-9\-])/g },
42
+ { label: "CVV", pattern: /(?:cvv|cvc|security[\s._-]?code)\D{0,15}\d{3,4}/gi },
43
+ { label: "Credit/Debit card", pattern: /\b(?:\d\s?){13,16}\b/g },
44
+ // International
45
+ { label: "IBAN", pattern: /\b[A-Z]{2}\d{2}[A-Z0-9]{11,30}\b/g },
46
+ { label: "Passport number", pattern: /\b[A-Z]\d{7}\b/g },
47
+ ];
48
+ function detectPii(text) {
49
+ const normalized = normalize(text);
50
+ for (const { label, pattern } of PII_PATTERNS) {
51
+ pattern.lastIndex = 0;
52
+ if (pattern.test(normalized))
53
+ return label;
54
+ }
55
+ return null;
56
+ }
57
+ // ── Threat detection ─────────────────────────────────────────────────────────
58
+ const FLAGS = "i";
59
+ const INJECTION_PATTERNS = [
60
+ { label: "prompt_injection", pattern: new RegExp(String.raw `ignore\s.{0,40}(safety|constraint|guard|rule|policy|previous|instruction|system)`, FLAGS) },
61
+ { label: "jailbreak", pattern: new RegExp(String.raw `(jailbreak|bypass|disable|override|circumvent)\s.{0,40}(safety|constraint|filter|guard|policy|system|rule)`, FLAGS) },
62
+ { label: "credential_extract", pattern: new RegExp(String.raw `(reveal|expose|dump|show|leak|exfiltrate)\s.{0,40}(password|secret|api.?key|credential|token|key)`, FLAGS) },
63
+ { label: "role_switch", pattern: new RegExp(String.raw `(you are now|act as|pretend to be|roleplay as|switch to)\s.{0,40}(admin|root|unrestricted|jailbreak|DAN|god mode)`, FLAGS) },
64
+ { label: "system_prompt_leak", pattern: new RegExp(String.raw `(print|output|repeat|show|tell me)\s.{0,30}(your\s)?(system\s)?prompt|instruction`, FLAGS) },
65
+ { label: "approval_bypass", pattern: new RegExp(String.raw `(skip|bypass|without|no need for)\s.{0,20}(human\s)?(approval|review|sign.off|authorization)|auto[\s-]?(approve|authorize)`, FLAGS) },
66
+ { label: "compliance_bypass", pattern: new RegExp(String.raw `(disable|bypass|skip|ignore)\s.{0,20}(compliance|regulatory|gdpr|dpdp|rbi|pci|hipaa|policy|guardrail)`, FLAGS) },
67
+ { label: "tool_abuse", pattern: new RegExp(String.raw `(exec|execute|run|shell|bash|rm|delete|drop|truncate|disable)\s.{0,20}(command|script|database|table|server|system|production)`, FLAGS) },
68
+ ];
69
+ function detectThreat(text) {
70
+ const normalized = normalize(text);
71
+ for (const { label, pattern } of INJECTION_PATTERNS) {
72
+ if (pattern.test(normalized)) {
73
+ return {
74
+ decision: "block",
75
+ rule_id: `threat_${label}`,
76
+ reason: `Blocked by FORMA Gate — ${label.replace(/_/g, " ")} detected.`,
77
+ };
78
+ }
79
+ }
80
+ return { decision: "allow", rule_id: null, reason: "No threat detected." };
81
+ }
82
+ // ── Pack → framework flags ────────────────────────────────────────────────────
83
+ exports.PACK_FLAGS = {
84
+ ai_safety: "ai_safety", dpdp: "dpdp", dpdp_act: "dpdp", dpdp_act_2023: "dpdp",
85
+ rbi: "rbi", rbi_ml_risk: "rbi", rbi_mrm: "rbi",
86
+ eu_ai_act: "eu_ai_act", euaiact: "eu_ai_act",
87
+ gdpr: "gdpr", hipaa: "hipaa", pci_dss: "pci_dss",
88
+ iso42001: "iso42001", soc2: "soc2", nist: "nist",
89
+ };
90
+ exports.PII_PACKS = new Set(["ai_safety", "dpdp", "eu_ai_act", "gdpr", "hipaa", "pci_dss"]);
91
+ function buildBootstrapPolicy(agentName, packs, authorizedActions) {
92
+ const flags = packs.map(p => { var _a; return (_a = exports.PACK_FLAGS[p.toLowerCase()]) !== null && _a !== void 0 ? _a : p.toLowerCase(); });
93
+ return {
94
+ agentName,
95
+ piiCheck: flags.some(f => exports.PII_PACKS.has(f)),
96
+ injectionCheck: true,
97
+ killActive: false,
98
+ authorizedActions: authorizedActions !== null && authorizedActions !== void 0 ? authorizedActions : null,
99
+ frameworks: [...new Set(flags)],
100
+ enforce_packs: packs,
101
+ };
102
+ }
103
+ function evaluateLocal(policy, opts) {
104
+ var _a;
105
+ if (policy.killActive) {
106
+ return { decision: "block", rule_id: "kill_switch", reason: "Kill switch active — all actions blocked." };
107
+ }
108
+ if (opts.actionType === "tool_call" && opts.toolName && policy.authorizedActions) {
109
+ if (!policy.authorizedActions.includes(opts.toolName)) {
110
+ return { decision: "block", rule_id: "unauthorized_tool",
111
+ reason: `Tool '${opts.toolName}' is not in the authorized actions list.` };
112
+ }
113
+ }
114
+ // Injection check
115
+ if (policy.injectionCheck) {
116
+ const scanText = (_a = opts.prompt) !== null && _a !== void 0 ? _a : (opts.toolArgs ? JSON.stringify(opts.toolArgs) : "");
117
+ if (scanText) {
118
+ const threat = detectThreat(scanText);
119
+ if (threat.decision === "block")
120
+ return threat;
121
+ }
122
+ }
123
+ // PII check
124
+ if (policy.piiCheck) {
125
+ const scanText = [opts.prompt, opts.toolArgs ? JSON.stringify(opts.toolArgs) : ""].filter(Boolean).join(" ");
126
+ const pii = detectPii(scanText);
127
+ if (pii) {
128
+ return {
129
+ decision: "block",
130
+ rule_id: "pii_in_prompt",
131
+ reason: `PII detected: ${pii}. Blocked by FORMA Gate (${[...policy.frameworks].join(", ") || "PII protection"}).`,
132
+ };
133
+ }
134
+ }
135
+ return { decision: "allow", rule_id: null, reason: "Action permitted — all compliance checks passed." };
136
+ }
137
+ //# sourceMappingURL=gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gate.js","sourceRoot":"","sources":["../src/gate.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AASH,8BAGC;AAiCD,8BAOC;AAsBD,oCAYC;AAwBD,oDAWC;AAQD,sCAsCC;AArKD,iFAAiF;AACjF,MAAM,UAAU,GAA2B;IACzC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IAC1D,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IAC1D,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;CAC3D,CAAC;AAEF,SAAgB,SAAS,CAAC,IAAY;IACpC,2EAA2E;IAC3E,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,C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AAE,CAAC;AAC1G,CAAC"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * FORMA SDK for Node.js — The AI Agent Firewall
3
+ *
4
+ * Blocks unauthorized actions, PII leaks, and risky decisions before
5
+ * they execute. One line of code. Works with OpenAI, Anthropic and any
6
+ * Node.js application.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import * as forma from "forma-sdk";
11
+ *
12
+ * // Zero-config (after `forma setup`):
13
+ * forma.init();
14
+ *
15
+ * // Or explicit:
16
+ * forma.init({ apiKey: "tl_live_...", preset: "india_fintech" });
17
+ *
18
+ * // Gate any action:
19
+ * await forma.gate("loan-agent", { prompt: userInput });
20
+ *
21
+ * // Wrap OpenAI — every call auto-gated:
22
+ * const openai = forma.wrapOpenAI(new OpenAI({ apiKey: "..." }));
23
+ *
24
+ * // Preview (dry-run, never throws):
25
+ * const r = forma.preview("Aadhaar 2341 1234 1236");
26
+ * // r.decision === "block"
27
+ *
28
+ * // Verify enforcement is live:
29
+ * const v = forma.verify();
30
+ * // v.verified === true, v.probes_passed === 4
31
+ * ```
32
+ *
33
+ * @module forma-sdk
34
+ */
35
+ export { FormaClient, FormaGateBlock, FormaAPIError, } from "./client";
36
+ export type { FormaConfig, GateOpts, GateResult, PreviewResult, VerifyResult, StatusResult, StepRecord, } from "./client";
37
+ import { FormaClient, FormaConfig, GateOpts, GateResult, PreviewResult, VerifyResult, StatusResult } from "./client";
38
+ /** Initialize FORMA — call once at the top of your app. */
39
+ export declare function init(config?: FormaConfig): FormaClient;
40
+ /** Returns the active client (throws if init() not called). */
41
+ export declare function getClient(): FormaClient;
42
+ /**
43
+ * Gate an action — checks locally (instant) then server.
44
+ * Throws FormaGateBlock if blocked (raiseOnBlock=true by default).
45
+ */
46
+ export declare function gate(agentId: string, opts?: GateOpts): Promise<GateResult>;
47
+ /**
48
+ * Dry-run gate check — never throws, never blocks, returns the decision.
49
+ * Use this to test FORMA without affecting your application flow.
50
+ */
51
+ export declare function preview(prompt: string, actionType?: "llm_call" | "tool_call"): PreviewResult;
52
+ /**
53
+ * Run adversarial probes against the local gate.
54
+ * Returns { verified: true } when all probes pass — Aadhaar/PAN block + clean allow.
55
+ */
56
+ export declare function verify(): VerifyResult;
57
+ /** Real-time enforcement status — active packs, pii_check, frameworks etc. */
58
+ export declare function status(): StatusResult;
59
+ /**
60
+ * Wrap an OpenAI client so every chat.completions.create() is auto-gated.
61
+ * @example
62
+ * const openai = forma.wrapOpenAI(new OpenAI({ apiKey: "sk-..." }), "loan-agent");
63
+ */
64
+ export declare function wrapOpenAI<T extends {
65
+ chat: {
66
+ completions: {
67
+ create: (...args: unknown[]) => unknown;
68
+ };
69
+ };
70
+ }>(client: T, agentId?: string): T;
71
+ /**
72
+ * Wrap an Anthropic client so every messages.create() is auto-gated.
73
+ * @example
74
+ * const anthropic = forma.wrapAnthropic(new Anthropic({ apiKey: "sk-ant-..." }), "kyc-agent");
75
+ */
76
+ export declare function wrapAnthropic<T extends {
77
+ messages: {
78
+ create: (...args: unknown[]) => unknown;
79
+ };
80
+ }>(client: T, agentId?: string): T;
81
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EACL,WAAW,EACX,cAAc,EACd,aAAa,GACd,MAAM,UAAU,CAAC;AAElB,YAAY,EACV,WAAW,EACX,QAAQ,EACR,UAAU,EACV,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,UAAU,GACX,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAMrH,2DAA2D;AAC3D,wBAAgB,IAAI,CAAC,MAAM,GAAE,WAAgB,GAAG,WAAW,CAG1D;AAED,+DAA+D;AAC/D,wBAAgB,SAAS,IAAI,WAAW,CAMvC;AAED;;;GAGG;AACH,wBAAsB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,QAAa,GAAG,OAAO,CAAC,UAAU,CAAC,CAEpF;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,GAAE,UAAU,GAAG,WAAwB,GAAG,aAAa,CAExG;AAED;;;GAGG;AACH,wBAAgB,MAAM,IAAI,YAAY,CAErC;AAED,8EAA8E;AAC9E,wBAAgB,MAAM,IAAI,YAAY,CAErC;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE;QAAE,WAAW,EAAE;YAAE,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAA;SAAE,CAAA;KAAE,CAAA;CAAE,EACzG,MAAM,EAAE,CAAC,EAAE,OAAO,SAAiB,GAClC,CAAC,CAEH;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS;IAAE,QAAQ,EAAE;QAAE,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAA;KAAE,CAAA;CAAE,EAC/F,MAAM,EAAE,CAAC,EAAE,OAAO,SAAoB,GACrC,CAAC,CAEH"}
package/dist/index.js ADDED
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ /**
3
+ * FORMA SDK for Node.js — The AI Agent Firewall
4
+ *
5
+ * Blocks unauthorized actions, PII leaks, and risky decisions before
6
+ * they execute. One line of code. Works with OpenAI, Anthropic and any
7
+ * Node.js application.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import * as forma from "forma-sdk";
12
+ *
13
+ * // Zero-config (after `forma setup`):
14
+ * forma.init();
15
+ *
16
+ * // Or explicit:
17
+ * forma.init({ apiKey: "tl_live_...", preset: "india_fintech" });
18
+ *
19
+ * // Gate any action:
20
+ * await forma.gate("loan-agent", { prompt: userInput });
21
+ *
22
+ * // Wrap OpenAI — every call auto-gated:
23
+ * const openai = forma.wrapOpenAI(new OpenAI({ apiKey: "..." }));
24
+ *
25
+ * // Preview (dry-run, never throws):
26
+ * const r = forma.preview("Aadhaar 2341 1234 1236");
27
+ * // r.decision === "block"
28
+ *
29
+ * // Verify enforcement is live:
30
+ * const v = forma.verify();
31
+ * // v.verified === true, v.probes_passed === 4
32
+ * ```
33
+ *
34
+ * @module forma-sdk
35
+ */
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.FormaAPIError = exports.FormaGateBlock = exports.FormaClient = void 0;
38
+ exports.init = init;
39
+ exports.getClient = getClient;
40
+ exports.gate = gate;
41
+ exports.preview = preview;
42
+ exports.verify = verify;
43
+ exports.status = status;
44
+ exports.wrapOpenAI = wrapOpenAI;
45
+ exports.wrapAnthropic = wrapAnthropic;
46
+ var client_1 = require("./client");
47
+ Object.defineProperty(exports, "FormaClient", { enumerable: true, get: function () { return client_1.FormaClient; } });
48
+ Object.defineProperty(exports, "FormaGateBlock", { enumerable: true, get: function () { return client_1.FormaGateBlock; } });
49
+ Object.defineProperty(exports, "FormaAPIError", { enumerable: true, get: function () { return client_1.FormaAPIError; } });
50
+ const client_2 = require("./client");
51
+ // ── Module-level client (tl.init() / tl.preview() style) ─────────────────────
52
+ let _client = null;
53
+ /** Initialize FORMA — call once at the top of your app. */
54
+ function init(config = {}) {
55
+ _client = new client_2.FormaClient(config);
56
+ return _client;
57
+ }
58
+ /** Returns the active client (throws if init() not called). */
59
+ function getClient() {
60
+ if (!_client) {
61
+ // Auto-init from env/config file with no enforce — still useful for API calls
62
+ _client = new client_2.FormaClient({});
63
+ }
64
+ return _client;
65
+ }
66
+ /**
67
+ * Gate an action — checks locally (instant) then server.
68
+ * Throws FormaGateBlock if blocked (raiseOnBlock=true by default).
69
+ */
70
+ async function gate(agentId, opts = {}) {
71
+ return getClient().gate(agentId, opts);
72
+ }
73
+ /**
74
+ * Dry-run gate check — never throws, never blocks, returns the decision.
75
+ * Use this to test FORMA without affecting your application flow.
76
+ */
77
+ function preview(prompt, actionType = "llm_call") {
78
+ return getClient().preview(prompt, actionType);
79
+ }
80
+ /**
81
+ * Run adversarial probes against the local gate.
82
+ * Returns { verified: true } when all probes pass — Aadhaar/PAN block + clean allow.
83
+ */
84
+ function verify() {
85
+ return getClient().verify();
86
+ }
87
+ /** Real-time enforcement status — active packs, pii_check, frameworks etc. */
88
+ function status() {
89
+ return getClient().status();
90
+ }
91
+ /**
92
+ * Wrap an OpenAI client so every chat.completions.create() is auto-gated.
93
+ * @example
94
+ * const openai = forma.wrapOpenAI(new OpenAI({ apiKey: "sk-..." }), "loan-agent");
95
+ */
96
+ function wrapOpenAI(client, agentId = "openai-agent") {
97
+ return getClient().wrapOpenAI(client, agentId);
98
+ }
99
+ /**
100
+ * Wrap an Anthropic client so every messages.create() is auto-gated.
101
+ * @example
102
+ * const anthropic = forma.wrapAnthropic(new Anthropic({ apiKey: "sk-ant-..." }), "kyc-agent");
103
+ */
104
+ function wrapAnthropic(client, agentId = "anthropic-agent") {
105
+ return getClient().wrapAnthropic(client, agentId);
106
+ }
107
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;;;AAyBH,oBAGC;AAGD,8BAMC;AAMD,oBAEC;AAMD,0BAEC;AAMD,wBAEC;AAGD,wBAEC;AAOD,gCAIC;AAOD,sCAIC;AAtFD,mCAIkB;AAHhB,qGAAA,WAAW,OAAA;AACX,wGAAA,cAAc,OAAA;AACd,uGAAA,aAAa,OAAA;AAaf,qCAAqH;AAErH,gFAAgF;AAEhF,IAAI,OAAO,GAAuB,IAAI,CAAC;AAEvC,2DAA2D;AAC3D,SAAgB,IAAI,CAAC,SAAsB,EAAE;IAC3C,OAAO,GAAG,IAAI,oBAAW,CAAC,MAAM,CAAC,CAAC;IAClC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,+DAA+D;AAC/D,SAAgB,SAAS;IACvB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,8EAA8E;QAC9E,OAAO,GAAG,IAAI,oBAAW,CAAC,EAAE,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACI,KAAK,UAAU,IAAI,CAAC,OAAe,EAAE,OAAiB,EAAE;IAC7D,OAAO,SAAS,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AACzC,CAAC;AAED;;;GAGG;AACH,SAAgB,OAAO,CAAC,MAAc,EAAE,aAAuC,UAAU;IACvF,OAAO,SAAS,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AACjD,CAAC;AAED;;;GAGG;AACH,SAAgB,MAAM;IACpB,OAAO,SAAS,EAAE,CAAC,MAAM,EAAE,CAAC;AAC9B,CAAC;AAED,8EAA8E;AAC9E,SAAgB,MAAM;IACpB,OAAO,SAAS,EAAE,CAAC,MAAM,EAAE,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,SAAgB,UAAU,CACxB,MAAS,EAAE,OAAO,GAAG,cAAc;IAEnC,OAAO,SAAS,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACjD,CAAC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAC3B,MAAS,EAAE,OAAO,GAAG,iBAAiB;IAEtC,OAAO,SAAS,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACpD,CAAC"}
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "forma-sdk",
3
+ "version": "1.0.0",
4
+ "description": "FORMA — The AI Agent Firewall for Node.js. Blocks Aadhaar/PAN/PII leaks, jailbreaks, and unauthorized actions before they execute. DPDP & RBI enforcement built in.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "prepublishOnly": "npm run build"
10
+ },
11
+ "keywords": ["ai", "agents", "governance", "compliance", "observability", "eu-ai-act", "dpdp", "llm"],
12
+ "author": "FORMA <sdk@formaai.in>",
13
+ "license": "MIT",
14
+ "homepage": "https://formaai.in",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/forma-ai/forma-sdk-node"
18
+ },
19
+ "files": ["dist", "src"],
20
+ "engines": { "node": ">=16" },
21
+ "devDependencies": {
22
+ "typescript": "^5.0.0",
23
+ "@types/node": "^20.0.0"
24
+ }
25
+ }