cyphrex 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # Cyphrex (JavaScript / TypeScript)
2
+
3
+ Official SDK for [Cyphrex](https://cyphrex.io) — call `check()` before every agent action to enforce policies and log violations.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install cyphrex
9
+ ```
10
+
11
+ ## Quick start
12
+
13
+ ```typescript
14
+ import { Cyphrex } from 'cyphrex';
15
+
16
+ const cyphrex = new Cyphrex({
17
+ apiKey: process.env.CYPHREX_API_KEY!,
18
+ agentId: 'your-agent-uuid',
19
+ // apiUrl optional; defaults to production API
20
+ });
21
+
22
+ const result = await cyphrex.check({
23
+ actionType: 'http_call',
24
+ url: 'https://api.example.com/data',
25
+ });
26
+
27
+ if (!result.allowed) {
28
+ console.error(result.reason, result.violations);
29
+ return;
30
+ }
31
+ // proceed with the action
32
+ ```
33
+
34
+ ## Constructor
35
+
36
+ | Option | Required | Description |
37
+ |--------|----------|-------------|
38
+ | `apiKey` | Yes | Account API key from Dashboard → API Keys |
39
+ | `agentId` | Yes | UUID of the agent |
40
+ | `apiUrl` | No | API base URL (default: `https://cyphrexapi-production.up.railway.app`) |
41
+ | `timeoutMs` | No | Request timeout in ms (default: `10000`) |
42
+ | `failOpen` | No | If `true`, allow actions when Cyphrex is unreachable (default: `false`) |
43
+
44
+ ## `check(params)`
45
+
46
+ | Param | Type | Description |
47
+ |-------|------|-------------|
48
+ | `actionType` | `string` | e.g. `http_call`, `llm_input`, `llm_response`, `data_access` |
49
+ | `url` | `string?` | For `http_call` |
50
+ | `payload` | `any?` | Text or object (e.g. LLM prompt snippet) |
51
+ | `metadata` | `object?` | Optional extra context |
52
+
53
+ ### Response (`CheckResponse`)
54
+
55
+ - `allowed: boolean`
56
+ - `reason?: string` — when blocked or error
57
+ - `violations?: string[]` — e.g. severity codes
58
+ - `severity?: string` — `P1` / `P2` / `P3` from API
59
+ - `spend?: { amount, currency }` — reserved for future use
60
+
61
+ ## HTTP
62
+
63
+ Requests use `POST {apiUrl}/v1/check` with:
64
+
65
+ - `Authorization: Bearer <apiKey>`
66
+ - Body: `{ "agentId": "...", "action": { "type": "...", "url"?, "payload"? } }`
67
+
68
+ ## Build from source
69
+
70
+ ```bash
71
+ cd packages/sdk-js && npm install && npm run build
72
+ ```
73
+
74
+ Output: `dist/index.js`, `dist/index.d.ts`.
75
+
76
+ ## License
77
+
78
+ MIT
@@ -0,0 +1,41 @@
1
+ export interface CyphrexOptions {
2
+ apiKey: string;
3
+ agentId: string;
4
+ apiUrl?: string;
5
+ /** Milliseconds before request aborts (default 10000) */
6
+ timeoutMs?: number;
7
+ /** If true, return { allowed: true } on network errors (default false) */
8
+ failOpen?: boolean;
9
+ }
10
+ export interface CheckParams {
11
+ actionType: string;
12
+ url?: string;
13
+ payload?: unknown;
14
+ metadata?: Record<string, unknown>;
15
+ }
16
+ export interface CheckResponse {
17
+ allowed: boolean;
18
+ violations?: string[];
19
+ reason?: string;
20
+ spend?: {
21
+ amount: number;
22
+ currency: string;
23
+ };
24
+ /** API may return severity e.g. P1, P2, P3 */
25
+ severity?: string;
26
+ /** When failOpen allows after network error */
27
+ warning?: string;
28
+ }
29
+ export declare class Cyphrex {
30
+ private readonly apiKey;
31
+ private readonly agentId;
32
+ private readonly apiUrl;
33
+ private readonly timeoutMs;
34
+ private readonly failOpen;
35
+ constructor(options: CyphrexOptions);
36
+ /**
37
+ * Ask Cyphrex whether an agent action is allowed. Call before executing the action.
38
+ */
39
+ check(params: CheckParams): Promise<CheckResponse>;
40
+ }
41
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7C,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAoBD,qBAAa,OAAO;IAClB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;gBAEvB,OAAO,EAAE,cAAc;IAcnC;;OAEG;IACG,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;CAyFzD"}
package/dist/index.js ADDED
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Cyphrex = void 0;
4
+ const DEFAULT_API_URL = 'https://cyphrexapi-production.up.railway.app';
5
+ function normalizeResponse(data) {
6
+ const allowed = data.allowed === true;
7
+ const out = { allowed };
8
+ if (data.reason != null)
9
+ out.reason = String(data.reason);
10
+ if (data.severity != null) {
11
+ out.severity = String(data.severity);
12
+ if (!allowed)
13
+ out.violations = [String(data.severity)];
14
+ }
15
+ return out;
16
+ }
17
+ class Cyphrex {
18
+ constructor(options) {
19
+ if (!options?.apiKey?.trim()) {
20
+ throw new Error('Cyphrex: apiKey is required');
21
+ }
22
+ if (!options?.agentId?.trim()) {
23
+ throw new Error('Cyphrex: agentId is required');
24
+ }
25
+ this.apiKey = options.apiKey.trim();
26
+ this.agentId = options.agentId.trim();
27
+ this.apiUrl = (options.apiUrl || DEFAULT_API_URL).replace(/\/$/, '');
28
+ this.timeoutMs = options.timeoutMs ?? 10000;
29
+ this.failOpen = options.failOpen ?? false;
30
+ }
31
+ /**
32
+ * Ask Cyphrex whether an agent action is allowed. Call before executing the action.
33
+ */
34
+ async check(params) {
35
+ const { actionType, url, payload, metadata } = params;
36
+ if (!actionType?.trim()) {
37
+ return { allowed: false, reason: 'actionType is required', violations: ['validation'] };
38
+ }
39
+ const action = { type: actionType.trim() };
40
+ if (url != null)
41
+ action.url = url;
42
+ if (payload !== undefined)
43
+ action.payload = payload;
44
+ if (metadata != null && Object.keys(metadata).length > 0) {
45
+ action.metadata = metadata;
46
+ }
47
+ const controller = new AbortController();
48
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
49
+ try {
50
+ const res = await fetch(`${this.apiUrl}/v1/check`, {
51
+ method: 'POST',
52
+ headers: {
53
+ 'Content-Type': 'application/json',
54
+ Authorization: `Bearer ${this.apiKey}`,
55
+ },
56
+ body: JSON.stringify({ agentId: this.agentId, action }),
57
+ signal: controller.signal,
58
+ });
59
+ clearTimeout(timer);
60
+ let data;
61
+ try {
62
+ data = (await res.json());
63
+ }
64
+ catch {
65
+ return {
66
+ allowed: false,
67
+ reason: 'Invalid JSON response from Cyphrex',
68
+ violations: ['parse_error'],
69
+ };
70
+ }
71
+ if (res.status === 401) {
72
+ return {
73
+ allowed: false,
74
+ reason: data.error || 'Invalid API key',
75
+ violations: ['unauthorized'],
76
+ };
77
+ }
78
+ if (res.status === 400) {
79
+ return {
80
+ allowed: false,
81
+ reason: data.error || 'Bad request',
82
+ violations: ['bad_request'],
83
+ };
84
+ }
85
+ if (res.status === 404) {
86
+ return {
87
+ allowed: false,
88
+ reason: data.error || 'Agent not found or inactive',
89
+ violations: ['not_found'],
90
+ };
91
+ }
92
+ if (res.status >= 500) {
93
+ if (this.failOpen) {
94
+ return { allowed: true, warning: 'Cyphrex server error — allowed by failOpen' };
95
+ }
96
+ return {
97
+ allowed: false,
98
+ reason: data.error || 'Cyphrex server error',
99
+ violations: ['server_error'],
100
+ };
101
+ }
102
+ return normalizeResponse(data);
103
+ }
104
+ catch (err) {
105
+ clearTimeout(timer);
106
+ const message = err instanceof Error ? err.message : 'Unknown error';
107
+ if (this.failOpen) {
108
+ return { allowed: true, warning: `Cyphrex unreachable (${message}) — allowed by failOpen` };
109
+ }
110
+ return {
111
+ allowed: false,
112
+ reason: `Request failed: ${message}`,
113
+ violations: ['network'],
114
+ };
115
+ }
116
+ }
117
+ }
118
+ exports.Cyphrex = Cyphrex;
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "cyphrex",
3
+ "version": "0.1.0",
4
+ "description": "Security and identity infrastructure for AI agents",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": ["dist"],
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/getcyphrex/platform"
11
+ },
12
+ "keywords": [
13
+ "ai",
14
+ "agents",
15
+ "security",
16
+ "monitoring",
17
+ "langchain",
18
+ "crewai"
19
+ ],
20
+ "author": "Cyphrex",
21
+ "license": "MIT",
22
+ "scripts": {
23
+ "build": "tsc",
24
+ "prepublishOnly": "npm run build"
25
+ },
26
+ "engines": {
27
+ "node": ">=18"
28
+ },
29
+ "devDependencies": {
30
+ "typescript": "^5.3.0"
31
+ }
32
+ }