@crowkis/client 0.5.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/langchain.js ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ // Semantic LLM cache for LangChain.js (and LangGraph.js) — drop-in.
4
+ //
5
+ // const { CrowkisCache } = require("@crowkis/client/langchain");
6
+ // const { OpenAI } = require("@langchain/openai");
7
+ // const llm = new OpenAI({ cache: new CrowkisCache({ tenant: "my-app", ttl: 3600 }) });
8
+ //
9
+ // Unlike LangChain's built-in caches (exact match), Crowkis matches on MEANING,
10
+ // so rephrased prompts hit the cache. Duck-typed (lookup/update) — needs no
11
+ // @langchain/core dependency.
12
+
13
+ const { CrowkisClient } = require("./index.js");
14
+
15
+ class CrowkisCache {
16
+ constructor(options = {}) {
17
+ this.client = options.client || new CrowkisClient(options);
18
+ this.ttl = options.ttl;
19
+ this.threshold = options.threshold;
20
+ }
21
+
22
+ async lookup(prompt, llmKey) {
23
+ const hit = await this.client.cgetHit(prompt, {
24
+ model: llmKey,
25
+ threshold: this.threshold,
26
+ });
27
+ if (!hit) return null;
28
+ const text = hit.text || "";
29
+ try {
30
+ const arr = JSON.parse(text);
31
+ if (Array.isArray(arr)) return arr.map((t) => ({ text: String(t) }));
32
+ } catch (_) {
33
+ // stored as plain text (older value / another writer)
34
+ }
35
+ return [{ text }];
36
+ }
37
+
38
+ async update(prompt, llmKey, value) {
39
+ const texts = Array.isArray(value)
40
+ ? value.map((g) => (g && g.text !== undefined ? g.text : String(g)))
41
+ : [String(value)];
42
+ await this.client.cset(prompt, JSON.stringify(texts), {
43
+ ttl: this.ttl,
44
+ model: llmKey,
45
+ });
46
+ }
47
+
48
+ async clear() {
49
+ if (typeof this.client.cflush === "function") await this.client.cflush();
50
+ }
51
+ }
52
+
53
+ module.exports = { CrowkisCache };
package/memory.js ADDED
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ // Framework-agnostic long-term agent memory backed by Crowkis.
4
+ // Works in LangGraph.js, or any agent loop. No extra dependency.
5
+ //
6
+ // const { CrowkisMemory } = require("@crowkis/client/memory");
7
+ // const mem = new CrowkisMemory("support-bot", { user: "alice", tenant: "demo" });
8
+ // await mem.remember("Alice prefers email over phone");
9
+ // const hits = await mem.recall("how should I contact Alice?");
10
+
11
+ const { CrowkisClient } = require("./index.js");
12
+
13
+ class CrowkisMemory {
14
+ constructor(agent, options = {}) {
15
+ if (!agent) throw new Error("agent must be a non-empty name");
16
+ this.agent = agent;
17
+ this.user = options.user;
18
+ this.client = options.client || new CrowkisClient(options);
19
+ }
20
+
21
+ remember(fact, { ttl } = {}) {
22
+ return this.client.cmemset(this.agent, fact, { user: this.user, ex: ttl });
23
+ }
24
+
25
+ recall(query, { k = 5 } = {}) {
26
+ return this.client.cmemget(this.agent, query, { user: this.user, k });
27
+ }
28
+
29
+ extract(conversation, { ttl } = {}) {
30
+ return this.client.cmemextract(this.agent, conversation, { user: this.user, ex: ttl });
31
+ }
32
+
33
+ history(query, { k = 5 } = {}) {
34
+ return this.client.cmemhistory(this.agent, query, { user: this.user, k });
35
+ }
36
+
37
+ forget({ query, threshold } = {}) {
38
+ return this.client.cmemforget(this.agent, { query, user: this.user, threshold });
39
+ }
40
+
41
+ link(subject, relation, object) {
42
+ return this.client.cmemlink(this.agent, subject, relation, object, { user: this.user });
43
+ }
44
+
45
+ graph(entity, { depth } = {}) {
46
+ return this.client.cmemgraph(this.agent, entity, { user: this.user, depth });
47
+ }
48
+ }
49
+
50
+ module.exports = { CrowkisMemory };
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@crowkis/client",
3
+ "version": "0.5.0",
4
+ "description": "Official Node.js and TypeScript SDK for Crowkis — intelligent, Redis-compatible cache & memory for LLM apps and agents",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "exports": {
8
+ ".": "./index.js",
9
+ "./langchain": "./langchain.js",
10
+ "./memory": "./memory.js"
11
+ },
12
+ "license": "Apache-2.0",
13
+ "author": "Mohit Rohilla",
14
+ "keywords": ["crowkis", "llm", "cache", "semantic-cache", "agent-memory", "langchain", "langgraph", "redis"],
15
+ "homepage": "https://www.crowkis.com",
16
+ "repository": { "type": "git", "url": "https://github.com/crowkis/crowkis-sdk.git" },
17
+ "peerDependencies": {
18
+ "@grpc/grpc-js": ">=1.9.0",
19
+ "@grpc/proto-loader": ">=0.7.0"
20
+ },
21
+ "peerDependenciesMeta": {
22
+ "@grpc/grpc-js": {
23
+ "optional": true
24
+ },
25
+ "@grpc/proto-loader": {
26
+ "optional": true
27
+ }
28
+ },
29
+ "engines": {
30
+ "node": ">=18"
31
+ },
32
+ "files": [
33
+ "index.js",
34
+ "index.d.ts",
35
+ "langchain.js",
36
+ "memory.js",
37
+ "grpc.js",
38
+ "crowkis.proto",
39
+ "README.md"
40
+ ],
41
+ "scripts": {
42
+ "check": "node --check index.js"
43
+ }
44
+ }