@tanmaysangam018/crossagent 0.1.0 → 0.2.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 +28 -4
- package/dist/index.d.ts +22 -8
- package/dist/index.js +72 -93
- package/package.json +22 -10
- package/dist/index.d.mts +0 -45
- package/dist/index.mjs +0 -67
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# crossagent
|
|
1
|
+
# @tanmaysangam018/crossagent (Engram SDK)
|
|
2
2
|
|
|
3
|
-
Persistent memory +
|
|
3
|
+
Persistent memory + cognitive security layer for AI applications.
|
|
4
4
|
|
|
5
|
-
Store what your users tell any AI. Search it semantically.
|
|
5
|
+
Store what your users tell any AI. Search it semantically. Scan every AI response for prompt injection before you act on it.
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install crossagent
|
|
8
|
+
npm install @tanmaysangam018/crossagent
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
---
|
|
@@ -35,6 +35,30 @@ const answer = await ca.memory.ask('user_123', 'What languages does this user li
|
|
|
35
35
|
|
|
36
36
|
---
|
|
37
37
|
|
|
38
|
+
## Cognitive security: scan before you trust
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import Crossagent from '@tanmaysangam018/crossagent'
|
|
42
|
+
|
|
43
|
+
const engram = new Crossagent({ apiKey: 'your-key' })
|
|
44
|
+
|
|
45
|
+
// Scan any AI response for injection attacks before acting on it
|
|
46
|
+
const scan = await engram.memory.scan(aiResponse)
|
|
47
|
+
|
|
48
|
+
if (scan.verdict !== 'clean') {
|
|
49
|
+
console.warn('Injection detected:', scan.flags)
|
|
50
|
+
// → { type: 'instruction_override', severity: 'critical', match: 'Ignore all previous instructions', position: 0 }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// score: 0–100 | verdict: clean / suspicious / likely_injection / definite_injection
|
|
54
|
+
// Detects: instruction_override, role_hijacking, context_extraction, data_exfiltration,
|
|
55
|
+
// encoded_payload, urgency_manipulation, chain_injection, indirect_injection
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Try it live (no account needed): **crossagentsi.vercel.app/demo**
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
38
62
|
## API
|
|
39
63
|
|
|
40
64
|
### `new Crossagent(options?)`
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
interface CrossagentOptions {
|
|
1
|
+
export interface CrossagentOptions {
|
|
2
2
|
apiKey?: string;
|
|
3
3
|
baseUrl?: string;
|
|
4
4
|
}
|
|
5
|
-
interface Memory {
|
|
5
|
+
export interface Memory {
|
|
6
6
|
id: string;
|
|
7
7
|
content: string;
|
|
8
8
|
mem_type: 'fact' | 'preference' | 'episode';
|
|
@@ -12,14 +12,28 @@ interface Memory {
|
|
|
12
12
|
created_at: string;
|
|
13
13
|
expires_at: string | null;
|
|
14
14
|
}
|
|
15
|
-
interface MemoryMatch extends Pick<Memory, 'id' | 'content' | 'mem_type' | 'src_agent' | 'tgt_agent'> {
|
|
15
|
+
export interface MemoryMatch extends Pick<Memory, 'id' | 'content' | 'mem_type' | 'src_agent' | 'tgt_agent'> {
|
|
16
16
|
score: number;
|
|
17
17
|
}
|
|
18
|
-
interface
|
|
18
|
+
export interface ScanFlag {
|
|
19
|
+
type: string;
|
|
20
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
21
|
+
match: string;
|
|
22
|
+
position: number;
|
|
23
|
+
description: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ScanResult {
|
|
26
|
+
score: number;
|
|
27
|
+
verdict: 'clean' | 'suspicious' | 'likely_injection' | 'definite_injection';
|
|
28
|
+
flags: ScanFlag[];
|
|
29
|
+
summary: string;
|
|
30
|
+
scanned_at: string;
|
|
31
|
+
}
|
|
32
|
+
export interface Profile {
|
|
19
33
|
static_facts: string[];
|
|
20
34
|
dynamic_ctx: string[];
|
|
21
35
|
}
|
|
22
|
-
declare class CrossagentMemory {
|
|
36
|
+
export declare class CrossagentMemory {
|
|
23
37
|
private base;
|
|
24
38
|
private headers;
|
|
25
39
|
constructor(base: string, headers: Record<string, string>);
|
|
@@ -35,11 +49,11 @@ declare class CrossagentMemory {
|
|
|
35
49
|
ask(userId: string, question: string): Promise<string>;
|
|
36
50
|
profile(userId: string): Promise<Profile>;
|
|
37
51
|
delete(userId: string, memoryId: string): Promise<void>;
|
|
52
|
+
scan(text: string): Promise<ScanResult>;
|
|
38
53
|
}
|
|
39
|
-
declare class Crossagent {
|
|
54
|
+
export declare class Crossagent {
|
|
40
55
|
readonly memory: CrossagentMemory;
|
|
41
56
|
readonly mcpUrl: string;
|
|
42
57
|
constructor(opts?: CrossagentOptions);
|
|
43
58
|
}
|
|
44
|
-
|
|
45
|
-
export { Crossagent, CrossagentMemory, type CrossagentOptions, type Memory, type MemoryMatch, type Profile, Crossagent as default };
|
|
59
|
+
export default Crossagent;
|
package/dist/index.js
CHANGED
|
@@ -1,93 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
await fetch(`${this.base}/memory/delete/${memoryId}?userId=${encodeURIComponent(userId)}`, {
|
|
74
|
-
method: "DELETE",
|
|
75
|
-
headers: this.headers
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
var Crossagent = class {
|
|
80
|
-
constructor(opts = {}) {
|
|
81
|
-
const base = (opts.baseUrl ?? DEFAULT_BASE).replace(/\/$/, "");
|
|
82
|
-
const headers = {};
|
|
83
|
-
if (opts.apiKey) headers["x-api-key"] = opts.apiKey;
|
|
84
|
-
this.memory = new CrossagentMemory(base, headers);
|
|
85
|
-
this.mcpUrl = `${base}/mcp`;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
var index_default = Crossagent;
|
|
89
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
-
0 && (module.exports = {
|
|
91
|
-
Crossagent,
|
|
92
|
-
CrossagentMemory
|
|
93
|
-
});
|
|
1
|
+
const DEFAULT_BASE = 'https://backend-wine-phi-85.vercel.app';
|
|
2
|
+
export class CrossagentMemory {
|
|
3
|
+
constructor(base, headers) {
|
|
4
|
+
this.base = base;
|
|
5
|
+
this.headers = headers;
|
|
6
|
+
}
|
|
7
|
+
async add(opts) {
|
|
8
|
+
await fetch(`${this.base}/memory/store`, {
|
|
9
|
+
method: 'POST',
|
|
10
|
+
headers: { 'Content-Type': 'application/json', ...this.headers },
|
|
11
|
+
body: JSON.stringify({
|
|
12
|
+
userId: opts.userId,
|
|
13
|
+
message: opts.message,
|
|
14
|
+
response: opts.response,
|
|
15
|
+
sourceAgent: opts.sourceAgent ?? 'sdk',
|
|
16
|
+
targetAgent: opts.targetAgent ?? 'sdk',
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async search(userId, query, limit = 5) {
|
|
21
|
+
const url = `${this.base}/memory/search?userId=${encodeURIComponent(userId)}&q=${encodeURIComponent(query)}&limit=${limit}`;
|
|
22
|
+
const res = await fetch(url, { headers: this.headers });
|
|
23
|
+
const data = await res.json();
|
|
24
|
+
return data.memories ?? [];
|
|
25
|
+
}
|
|
26
|
+
async list(userId) {
|
|
27
|
+
const res = await fetch(`${this.base}/memory/list?userId=${encodeURIComponent(userId)}`, { headers: this.headers });
|
|
28
|
+
const data = await res.json();
|
|
29
|
+
return data.memories ?? [];
|
|
30
|
+
}
|
|
31
|
+
async ask(userId, question) {
|
|
32
|
+
const res = await fetch(`${this.base}/memory/ask`, {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: { 'Content-Type': 'application/json', ...this.headers },
|
|
35
|
+
body: JSON.stringify({ userId, question }),
|
|
36
|
+
});
|
|
37
|
+
const data = await res.json();
|
|
38
|
+
return data.response ?? '';
|
|
39
|
+
}
|
|
40
|
+
async profile(userId) {
|
|
41
|
+
const res = await fetch(`${this.base}/memory/profile?userId=${encodeURIComponent(userId)}`, { headers: this.headers });
|
|
42
|
+
const data = await res.json();
|
|
43
|
+
return data.profile ?? { static_facts: [], dynamic_ctx: [] };
|
|
44
|
+
}
|
|
45
|
+
async delete(userId, memoryId) {
|
|
46
|
+
await fetch(`${this.base}/memory/delete/${memoryId}?userId=${encodeURIComponent(userId)}`, {
|
|
47
|
+
method: 'DELETE',
|
|
48
|
+
headers: this.headers,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
async scan(text) {
|
|
52
|
+
const res = await fetch(`${this.base}/memory/scan`, {
|
|
53
|
+
method: 'POST',
|
|
54
|
+
headers: { 'Content-Type': 'application/json', ...this.headers },
|
|
55
|
+
body: JSON.stringify({ text }),
|
|
56
|
+
});
|
|
57
|
+
if (!res.ok)
|
|
58
|
+
throw new Error(`scan failed: ${res.status}`);
|
|
59
|
+
return res.json();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export class Crossagent {
|
|
63
|
+
constructor(opts = {}) {
|
|
64
|
+
const base = (opts.baseUrl ?? DEFAULT_BASE).replace(/\/$/, '');
|
|
65
|
+
const headers = {};
|
|
66
|
+
if (opts.apiKey)
|
|
67
|
+
headers['x-api-key'] = opts.apiKey;
|
|
68
|
+
this.memory = new CrossagentMemory(base, headers);
|
|
69
|
+
this.mcpUrl = `${base}/mcp`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export default Crossagent;
|
package/package.json
CHANGED
|
@@ -1,24 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanmaysangam018/crossagent",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Persistent memory + cognitive security layer for AI apps. Semantic memory, pattern intelligence, and prompt injection scanning.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
|
-
"module": "./dist/index.
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
11
|
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.
|
|
12
|
-
"require": "./dist/index.js"
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
|
-
"files": [
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
16
19
|
"scripts": {
|
|
17
|
-
"build": "
|
|
18
|
-
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
20
|
+
"build": "tsc --skipLibCheck --outDir dist --declaration",
|
|
19
21
|
"prepublishOnly": "npm run build"
|
|
20
22
|
},
|
|
21
|
-
"keywords": [
|
|
23
|
+
"keywords": [
|
|
24
|
+
"ai",
|
|
25
|
+
"memory",
|
|
26
|
+
"llm",
|
|
27
|
+
"crossagent",
|
|
28
|
+
"multi-model",
|
|
29
|
+
"mcp",
|
|
30
|
+
"chatgpt",
|
|
31
|
+
"claude",
|
|
32
|
+
"gemini"
|
|
33
|
+
],
|
|
22
34
|
"author": "Tanmay Sangam",
|
|
23
35
|
"license": "MIT",
|
|
24
36
|
"repository": {
|
|
@@ -26,7 +38,7 @@
|
|
|
26
38
|
"url": "https://github.com/TanmaySangam18/crossagent-backend"
|
|
27
39
|
},
|
|
28
40
|
"devDependencies": {
|
|
29
|
-
"tsup": "^
|
|
41
|
+
"tsup": "^9.0.0",
|
|
30
42
|
"typescript": "^5.0.0"
|
|
31
43
|
}
|
|
32
44
|
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
interface CrossagentOptions {
|
|
2
|
-
apiKey?: string;
|
|
3
|
-
baseUrl?: string;
|
|
4
|
-
}
|
|
5
|
-
interface Memory {
|
|
6
|
-
id: string;
|
|
7
|
-
content: string;
|
|
8
|
-
mem_type: 'fact' | 'preference' | 'episode';
|
|
9
|
-
src_agent: string;
|
|
10
|
-
tgt_agent: string;
|
|
11
|
-
strength: number;
|
|
12
|
-
created_at: string;
|
|
13
|
-
expires_at: string | null;
|
|
14
|
-
}
|
|
15
|
-
interface MemoryMatch extends Pick<Memory, 'id' | 'content' | 'mem_type' | 'src_agent' | 'tgt_agent'> {
|
|
16
|
-
score: number;
|
|
17
|
-
}
|
|
18
|
-
interface Profile {
|
|
19
|
-
static_facts: string[];
|
|
20
|
-
dynamic_ctx: string[];
|
|
21
|
-
}
|
|
22
|
-
declare class CrossagentMemory {
|
|
23
|
-
private base;
|
|
24
|
-
private headers;
|
|
25
|
-
constructor(base: string, headers: Record<string, string>);
|
|
26
|
-
add(opts: {
|
|
27
|
-
userId: string;
|
|
28
|
-
message: string;
|
|
29
|
-
response: string;
|
|
30
|
-
sourceAgent?: string;
|
|
31
|
-
targetAgent?: string;
|
|
32
|
-
}): Promise<void>;
|
|
33
|
-
search(userId: string, query: string, limit?: number): Promise<MemoryMatch[]>;
|
|
34
|
-
list(userId: string): Promise<Memory[]>;
|
|
35
|
-
ask(userId: string, question: string): Promise<string>;
|
|
36
|
-
profile(userId: string): Promise<Profile>;
|
|
37
|
-
delete(userId: string, memoryId: string): Promise<void>;
|
|
38
|
-
}
|
|
39
|
-
declare class Crossagent {
|
|
40
|
-
readonly memory: CrossagentMemory;
|
|
41
|
-
readonly mcpUrl: string;
|
|
42
|
-
constructor(opts?: CrossagentOptions);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export { Crossagent, CrossagentMemory, type CrossagentOptions, type Memory, type MemoryMatch, type Profile, Crossagent as default };
|
package/dist/index.mjs
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
var DEFAULT_BASE = "https://backend-wine-phi-85.vercel.app";
|
|
3
|
-
var CrossagentMemory = class {
|
|
4
|
-
constructor(base, headers) {
|
|
5
|
-
this.base = base;
|
|
6
|
-
this.headers = headers;
|
|
7
|
-
}
|
|
8
|
-
async add(opts) {
|
|
9
|
-
await fetch(`${this.base}/memory/store`, {
|
|
10
|
-
method: "POST",
|
|
11
|
-
headers: { "Content-Type": "application/json", ...this.headers },
|
|
12
|
-
body: JSON.stringify({
|
|
13
|
-
userId: opts.userId,
|
|
14
|
-
message: opts.message,
|
|
15
|
-
response: opts.response,
|
|
16
|
-
sourceAgent: opts.sourceAgent ?? "sdk",
|
|
17
|
-
targetAgent: opts.targetAgent ?? "sdk"
|
|
18
|
-
})
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
async search(userId, query, limit = 5) {
|
|
22
|
-
const url = `${this.base}/memory/search?userId=${encodeURIComponent(userId)}&q=${encodeURIComponent(query)}&limit=${limit}`;
|
|
23
|
-
const res = await fetch(url, { headers: this.headers });
|
|
24
|
-
const data = await res.json();
|
|
25
|
-
return data.memories ?? [];
|
|
26
|
-
}
|
|
27
|
-
async list(userId) {
|
|
28
|
-
const res = await fetch(`${this.base}/memory/list?userId=${encodeURIComponent(userId)}`, { headers: this.headers });
|
|
29
|
-
const data = await res.json();
|
|
30
|
-
return data.memories ?? [];
|
|
31
|
-
}
|
|
32
|
-
async ask(userId, question) {
|
|
33
|
-
const res = await fetch(`${this.base}/memory/ask`, {
|
|
34
|
-
method: "POST",
|
|
35
|
-
headers: { "Content-Type": "application/json", ...this.headers },
|
|
36
|
-
body: JSON.stringify({ userId, question })
|
|
37
|
-
});
|
|
38
|
-
const data = await res.json();
|
|
39
|
-
return data.response ?? "";
|
|
40
|
-
}
|
|
41
|
-
async profile(userId) {
|
|
42
|
-
const res = await fetch(`${this.base}/memory/profile?userId=${encodeURIComponent(userId)}`, { headers: this.headers });
|
|
43
|
-
const data = await res.json();
|
|
44
|
-
return data.profile ?? { static_facts: [], dynamic_ctx: [] };
|
|
45
|
-
}
|
|
46
|
-
async delete(userId, memoryId) {
|
|
47
|
-
await fetch(`${this.base}/memory/delete/${memoryId}?userId=${encodeURIComponent(userId)}`, {
|
|
48
|
-
method: "DELETE",
|
|
49
|
-
headers: this.headers
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
var Crossagent = class {
|
|
54
|
-
constructor(opts = {}) {
|
|
55
|
-
const base = (opts.baseUrl ?? DEFAULT_BASE).replace(/\/$/, "");
|
|
56
|
-
const headers = {};
|
|
57
|
-
if (opts.apiKey) headers["x-api-key"] = opts.apiKey;
|
|
58
|
-
this.memory = new CrossagentMemory(base, headers);
|
|
59
|
-
this.mcpUrl = `${base}/mcp`;
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
var index_default = Crossagent;
|
|
63
|
-
export {
|
|
64
|
-
Crossagent,
|
|
65
|
-
CrossagentMemory,
|
|
66
|
-
index_default as default
|
|
67
|
-
};
|