ahok-skill 1.3.1

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 (141) hide show
  1. package/.prettierrc +8 -0
  2. package/Dockerfile +59 -0
  3. package/RAW_SKILL.md +219 -0
  4. package/README.md +277 -0
  5. package/SKILL.md +58 -0
  6. package/bin/opm.js +268 -0
  7. package/data/openmemory.sqlite +0 -0
  8. package/data/openmemory.sqlite-shm +0 -0
  9. package/data/openmemory.sqlite-wal +0 -0
  10. package/dist/ai/graph.js +293 -0
  11. package/dist/ai/mcp.js +397 -0
  12. package/dist/cli.js +78 -0
  13. package/dist/core/cfg.js +87 -0
  14. package/dist/core/db.js +636 -0
  15. package/dist/core/memory.js +116 -0
  16. package/dist/core/migrate.js +227 -0
  17. package/dist/core/models.js +105 -0
  18. package/dist/core/telemetry.js +57 -0
  19. package/dist/core/types.js +2 -0
  20. package/dist/core/vector/postgres.js +52 -0
  21. package/dist/core/vector/valkey.js +246 -0
  22. package/dist/core/vector_store.js +2 -0
  23. package/dist/index.js +44 -0
  24. package/dist/memory/decay.js +301 -0
  25. package/dist/memory/embed.js +675 -0
  26. package/dist/memory/hsg.js +959 -0
  27. package/dist/memory/reflect.js +131 -0
  28. package/dist/memory/user_summary.js +99 -0
  29. package/dist/migrate.js +9 -0
  30. package/dist/ops/compress.js +255 -0
  31. package/dist/ops/dynamics.js +189 -0
  32. package/dist/ops/extract.js +333 -0
  33. package/dist/ops/ingest.js +214 -0
  34. package/dist/server/index.js +109 -0
  35. package/dist/server/middleware/auth.js +137 -0
  36. package/dist/server/routes/auth.js +186 -0
  37. package/dist/server/routes/compression.js +108 -0
  38. package/dist/server/routes/dashboard.js +399 -0
  39. package/dist/server/routes/docs.js +241 -0
  40. package/dist/server/routes/dynamics.js +312 -0
  41. package/dist/server/routes/ide.js +280 -0
  42. package/dist/server/routes/index.js +33 -0
  43. package/dist/server/routes/keys.js +132 -0
  44. package/dist/server/routes/langgraph.js +61 -0
  45. package/dist/server/routes/memory.js +213 -0
  46. package/dist/server/routes/sources.js +140 -0
  47. package/dist/server/routes/system.js +63 -0
  48. package/dist/server/routes/temporal.js +293 -0
  49. package/dist/server/routes/users.js +101 -0
  50. package/dist/server/routes/vercel.js +57 -0
  51. package/dist/server/server.js +211 -0
  52. package/dist/server.js +3 -0
  53. package/dist/sources/base.js +223 -0
  54. package/dist/sources/github.js +171 -0
  55. package/dist/sources/google_drive.js +166 -0
  56. package/dist/sources/google_sheets.js +112 -0
  57. package/dist/sources/google_slides.js +139 -0
  58. package/dist/sources/index.js +34 -0
  59. package/dist/sources/notion.js +165 -0
  60. package/dist/sources/onedrive.js +143 -0
  61. package/dist/sources/web_crawler.js +166 -0
  62. package/dist/temporal_graph/index.js +20 -0
  63. package/dist/temporal_graph/query.js +240 -0
  64. package/dist/temporal_graph/store.js +116 -0
  65. package/dist/temporal_graph/timeline.js +241 -0
  66. package/dist/temporal_graph/types.js +2 -0
  67. package/dist/utils/chunking.js +60 -0
  68. package/dist/utils/index.js +31 -0
  69. package/dist/utils/keyword.js +94 -0
  70. package/dist/utils/text.js +120 -0
  71. package/nodemon.json +7 -0
  72. package/package.json +50 -0
  73. package/references/api_reference.md +66 -0
  74. package/references/examples.md +45 -0
  75. package/src/ai/graph.ts +363 -0
  76. package/src/ai/mcp.ts +494 -0
  77. package/src/cli.ts +94 -0
  78. package/src/core/cfg.ts +110 -0
  79. package/src/core/db.ts +1052 -0
  80. package/src/core/memory.ts +99 -0
  81. package/src/core/migrate.ts +302 -0
  82. package/src/core/models.ts +107 -0
  83. package/src/core/telemetry.ts +47 -0
  84. package/src/core/types.ts +130 -0
  85. package/src/core/vector/postgres.ts +61 -0
  86. package/src/core/vector/valkey.ts +261 -0
  87. package/src/core/vector_store.ts +9 -0
  88. package/src/index.ts +5 -0
  89. package/src/memory/decay.ts +427 -0
  90. package/src/memory/embed.ts +707 -0
  91. package/src/memory/hsg.ts +1245 -0
  92. package/src/memory/reflect.ts +158 -0
  93. package/src/memory/user_summary.ts +110 -0
  94. package/src/migrate.ts +8 -0
  95. package/src/ops/compress.ts +296 -0
  96. package/src/ops/dynamics.ts +272 -0
  97. package/src/ops/extract.ts +360 -0
  98. package/src/ops/ingest.ts +286 -0
  99. package/src/server/index.ts +159 -0
  100. package/src/server/middleware/auth.ts +156 -0
  101. package/src/server/routes/auth.ts +223 -0
  102. package/src/server/routes/compression.ts +106 -0
  103. package/src/server/routes/dashboard.ts +420 -0
  104. package/src/server/routes/docs.ts +380 -0
  105. package/src/server/routes/dynamics.ts +516 -0
  106. package/src/server/routes/ide.ts +283 -0
  107. package/src/server/routes/index.ts +32 -0
  108. package/src/server/routes/keys.ts +131 -0
  109. package/src/server/routes/langgraph.ts +71 -0
  110. package/src/server/routes/memory.ts +440 -0
  111. package/src/server/routes/sources.ts +111 -0
  112. package/src/server/routes/system.ts +68 -0
  113. package/src/server/routes/temporal.ts +335 -0
  114. package/src/server/routes/users.ts +111 -0
  115. package/src/server/routes/vercel.ts +55 -0
  116. package/src/server/server.js +215 -0
  117. package/src/server.ts +1 -0
  118. package/src/sources/base.ts +257 -0
  119. package/src/sources/github.ts +156 -0
  120. package/src/sources/google_drive.ts +144 -0
  121. package/src/sources/google_sheets.ts +85 -0
  122. package/src/sources/google_slides.ts +115 -0
  123. package/src/sources/index.ts +19 -0
  124. package/src/sources/notion.ts +148 -0
  125. package/src/sources/onedrive.ts +131 -0
  126. package/src/sources/web_crawler.ts +161 -0
  127. package/src/temporal_graph/index.ts +4 -0
  128. package/src/temporal_graph/query.ts +299 -0
  129. package/src/temporal_graph/store.ts +156 -0
  130. package/src/temporal_graph/timeline.ts +319 -0
  131. package/src/temporal_graph/types.ts +41 -0
  132. package/src/utils/chunking.ts +66 -0
  133. package/src/utils/index.ts +25 -0
  134. package/src/utils/keyword.ts +137 -0
  135. package/src/utils/text.ts +115 -0
  136. package/tests/test_api_workspace_management.ts +413 -0
  137. package/tests/test_bulk_delete.ts +267 -0
  138. package/tests/test_omnibus.ts +166 -0
  139. package/tests/test_workspace_management.ts +278 -0
  140. package/tests/verify.ts +104 -0
  141. package/tsconfig.json +15 -0
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extract_keywords = extract_keywords;
4
+ exports.compute_keyword_overlap = compute_keyword_overlap;
5
+ exports.exact_phrase_match = exact_phrase_match;
6
+ exports.compute_bm25_score = compute_bm25_score;
7
+ exports.keyword_filter_memories = keyword_filter_memories;
8
+ const text_1 = require("./text");
9
+ const cfg_1 = require("../core/cfg");
10
+ function extract_keywords(text, min_length = 3) {
11
+ const tokens = (0, text_1.canonical_tokens_from_text)(text);
12
+ const keywords = new Set();
13
+ for (const token of tokens) {
14
+ if (token.length >= min_length) {
15
+ keywords.add(token);
16
+ if (token.length >= 3) {
17
+ for (let i = 0; i <= token.length - 3; i++) {
18
+ keywords.add(token.slice(i, i + 3));
19
+ }
20
+ }
21
+ }
22
+ }
23
+ for (let i = 0; i < tokens.length - 1; i++) {
24
+ const bigram = `${tokens[i]}_${tokens[i + 1]}`;
25
+ if (bigram.length >= min_length) {
26
+ keywords.add(bigram);
27
+ }
28
+ }
29
+ for (let i = 0; i < tokens.length - 2; i++) {
30
+ const trigram = `${tokens[i]}_${tokens[i + 1]}_${tokens[i + 2]}`;
31
+ keywords.add(trigram);
32
+ }
33
+ return keywords;
34
+ }
35
+ function compute_keyword_overlap(query_keywords, content_keywords) {
36
+ let matches = 0;
37
+ let total_weight = 0;
38
+ for (const qk of query_keywords) {
39
+ if (content_keywords.has(qk)) {
40
+ const weight = qk.includes("_") ? 2.0 : 1.0;
41
+ matches += weight;
42
+ }
43
+ total_weight += qk.includes("_") ? 2.0 : 1.0;
44
+ }
45
+ if (total_weight === 0)
46
+ return 0;
47
+ return matches / total_weight;
48
+ }
49
+ function exact_phrase_match(query, content) {
50
+ const q_norm = query.toLowerCase().trim();
51
+ const c_norm = content.toLowerCase();
52
+ return c_norm.includes(q_norm);
53
+ }
54
+ function compute_bm25_score(query_terms, content_terms, corpus_size = 10000, avg_doc_length = 100) {
55
+ const k1 = 1.5;
56
+ const b = 0.75;
57
+ const term_freq = new Map();
58
+ for (const term of content_terms) {
59
+ term_freq.set(term, (term_freq.get(term) || 0) + 1);
60
+ }
61
+ const doc_length = content_terms.length;
62
+ let score = 0;
63
+ for (const q_term of query_terms) {
64
+ const tf = term_freq.get(q_term) || 0;
65
+ if (tf === 0)
66
+ continue;
67
+ const idf = Math.log((corpus_size + 1) / (tf + 0.5));
68
+ const numerator = tf * (k1 + 1);
69
+ const denominator = tf + k1 * (1 - b + b * (doc_length / avg_doc_length));
70
+ score += idf * (numerator / denominator);
71
+ }
72
+ return score;
73
+ }
74
+ async function keyword_filter_memories(query, all_memories, threshold = 0.1) {
75
+ const query_keywords = extract_keywords(query, cfg_1.env.keyword_min_length);
76
+ const query_terms = (0, text_1.canonical_tokens_from_text)(query);
77
+ const scores = new Map();
78
+ for (const mem of all_memories) {
79
+ let total_score = 0;
80
+ if (exact_phrase_match(query, mem.content)) {
81
+ total_score += 1.0;
82
+ }
83
+ const content_keywords = extract_keywords(mem.content, cfg_1.env.keyword_min_length);
84
+ const keyword_score = compute_keyword_overlap(query_keywords, content_keywords);
85
+ total_score += keyword_score * 0.8;
86
+ const content_terms = (0, text_1.canonical_tokens_from_text)(mem.content);
87
+ const bm25_score = compute_bm25_score(query_terms, content_terms);
88
+ total_score += Math.min(1.0, bm25_score / 10) * 0.5;
89
+ if (total_score > threshold) {
90
+ scores.set(mem.id, total_score);
91
+ }
92
+ }
93
+ return scores;
94
+ }
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.add_synonym_tokens = exports.canonical_token_set = exports.build_fts_query = exports.build_search_doc = exports.synonyms_for = exports.canonical_tokens_from_text = exports.canonicalize_token = exports.tokenize = void 0;
4
+ const syn_grps = [
5
+ ["prefer", "like", "love", "enjoy", "favor"],
6
+ ["theme", "mode", "style", "layout"],
7
+ ["meeting", "meet", "session", "call", "sync"],
8
+ ["dark", "night", "black"],
9
+ ["light", "bright", "day"],
10
+ ["user", "person", "people", "customer"],
11
+ ["task", "todo", "job"],
12
+ ["note", "memo", "reminder"],
13
+ ["time", "schedule", "when", "date"],
14
+ ["project", "initiative", "plan"],
15
+ ["issue", "problem", "bug"],
16
+ ["document", "doc", "file"],
17
+ ["question", "query", "ask"],
18
+ ];
19
+ const cmap = new Map();
20
+ const slook = new Map();
21
+ for (const grp of syn_grps) {
22
+ const can = grp[0];
23
+ const sset = new Set(grp);
24
+ for (const w of grp) {
25
+ cmap.set(w, can);
26
+ slook.set(can, sset);
27
+ }
28
+ }
29
+ const stem_rules = [
30
+ [/ies$/, "y"],
31
+ [/ing$/, ""],
32
+ [/ers?$/, "er"],
33
+ [/ed$/, ""],
34
+ [/s$/, ""],
35
+ ];
36
+ const tok_pat = /[a-z0-9]+/gi;
37
+ const tokenize = (text) => {
38
+ const toks = [];
39
+ let m;
40
+ while ((m = tok_pat.exec(text))) {
41
+ toks.push(m[0].toLowerCase());
42
+ }
43
+ return toks;
44
+ };
45
+ exports.tokenize = tokenize;
46
+ const stem = (tok) => {
47
+ if (tok.length <= 3)
48
+ return tok;
49
+ for (const [pat, rep] of stem_rules) {
50
+ if (pat.test(tok)) {
51
+ const st = tok.replace(pat, rep);
52
+ if (st.length >= 3)
53
+ return st;
54
+ }
55
+ }
56
+ return tok;
57
+ };
58
+ const canonicalize_token = (tok) => {
59
+ if (!tok)
60
+ return "";
61
+ const low = tok.toLowerCase();
62
+ if (cmap.has(low))
63
+ return cmap.get(low);
64
+ const st = stem(low);
65
+ return cmap.get(st) || st;
66
+ };
67
+ exports.canonicalize_token = canonicalize_token;
68
+ const canonical_tokens_from_text = (text) => {
69
+ const res = [];
70
+ for (const tok of (0, exports.tokenize)(text)) {
71
+ const can = (0, exports.canonicalize_token)(tok);
72
+ if (can && can.length > 1) {
73
+ res.push(can);
74
+ }
75
+ }
76
+ return res;
77
+ };
78
+ exports.canonical_tokens_from_text = canonical_tokens_from_text;
79
+ const synonyms_for = (tok) => {
80
+ const can = (0, exports.canonicalize_token)(tok);
81
+ return slook.get(can) || new Set([can]);
82
+ };
83
+ exports.synonyms_for = synonyms_for;
84
+ const build_search_doc = (text) => {
85
+ const can = (0, exports.canonical_tokens_from_text)(text);
86
+ const exp = new Set();
87
+ for (const tok of can) {
88
+ exp.add(tok);
89
+ const syns = slook.get(tok);
90
+ if (syns) {
91
+ syns.forEach((s) => exp.add(s));
92
+ }
93
+ }
94
+ return Array.from(exp).join(" ");
95
+ };
96
+ exports.build_search_doc = build_search_doc;
97
+ const build_fts_query = (text) => {
98
+ const can = (0, exports.canonical_tokens_from_text)(text);
99
+ if (!can.length)
100
+ return "";
101
+ const uniq = Array.from(new Set(can.filter((t) => t.length > 1)));
102
+ return uniq.map((t) => `"${t}"`).join(" OR ");
103
+ };
104
+ exports.build_fts_query = build_fts_query;
105
+ const canonical_token_set = (text) => {
106
+ return new Set((0, exports.canonical_tokens_from_text)(text));
107
+ };
108
+ exports.canonical_token_set = canonical_token_set;
109
+ const add_synonym_tokens = (toks) => {
110
+ const res = new Set();
111
+ for (const tok of toks) {
112
+ res.add(tok);
113
+ const syns = slook.get(tok);
114
+ if (syns) {
115
+ syns.forEach((s) => res.add((0, exports.canonicalize_token)(s)));
116
+ }
117
+ }
118
+ return res;
119
+ };
120
+ exports.add_synonym_tokens = add_synonym_tokens;
package/nodemon.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "watch": [
3
+ "src"
4
+ ],
5
+ "ext": "ts",
6
+ "exec": "tsx src/server/index.ts"
7
+ }
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "ahok-skill",
3
+ "version": "1.3.1",
4
+ "author": "nullure",
5
+ "bin": {
6
+ "opm": "./bin/opm.js",
7
+ "openmemory-js": "./bin/opm.js"
8
+ },
9
+ "main": "dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "scripts": {
12
+ "dev": "nodemon src/server/index.ts",
13
+ "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
14
+ "build": "tsc -p tsconfig.json",
15
+ "start": "node dist/server/index.js",
16
+ "migrate": "tsx src/migrate.ts"
17
+ },
18
+ "dependencies": {
19
+ "@aws-sdk/client-bedrock-runtime": "^3.932.0",
20
+ "@azure/msal-node": "^2.0.0",
21
+ "@clerk/backend": "^2.29.5",
22
+ "@modelcontextprotocol/sdk": "^1.22.0",
23
+ "@notionhq/client": "^2.2.0",
24
+ "@octokit/rest": "^21.0.0",
25
+ "cheerio": "^1.0.0",
26
+ "dotenv": "^16.6.1",
27
+ "fluent-ffmpeg": "^2.1.3",
28
+ "googleapis": "^140.0.0",
29
+ "ioredis": "^5.8.2",
30
+ "mammoth": "^1.11.0",
31
+ "openai": "^4.73.0",
32
+ "pdf-parse": "^2.4.5",
33
+ "pg": "^8.16.3",
34
+ "sqlite3": "^5.1.7",
35
+ "stripe": "^20.2.0",
36
+ "turndown": "^7.2.2",
37
+ "ws": "^8.18.3",
38
+ "zod": "^3.25.76"
39
+ },
40
+ "devDependencies": {
41
+ "@types/cheerio": "^0.22.35",
42
+ "@types/fluent-ffmpeg": "^2.1.26",
43
+ "@types/node": "^20.19.25",
44
+ "@types/pg": "^8.15.6",
45
+ "nodemon": "^3.1.11",
46
+ "prettier": "^3.6.2",
47
+ "tsx": "^4.21.0",
48
+ "typescript": "^5.9.3"
49
+ }
50
+ }
@@ -0,0 +1,66 @@
1
+ # Ahok Memory Cloud API Reference
2
+
3
+ ## Authentication
4
+ All requests require an API key in the `x-api-key` header.
5
+ Get your key from: https://your-dashboard-url/dashboard
6
+
7
+ ## Endpoints
8
+
9
+ ### POST /memory/add
10
+ Store a new memory.
11
+
12
+ **Request Body:**
13
+ ```json
14
+ {
15
+ "content": "The information to remember",
16
+ "user_id": "optional-user-identifier",
17
+ "tags": ["optional", "tags"],
18
+ "metadata": {"any": "json object"},
19
+ "memory_key_id": "optional-workspace-uuid"
20
+ }
21
+ ```
22
+
23
+ **Response:**
24
+ ```json
25
+ {
26
+ "id": "uuid",
27
+ "primary_sector": "semantic|procedural|episodic",
28
+ "sectors": ["semantic"],
29
+ "chunks": 1
30
+ }
31
+ ```
32
+
33
+ ### POST /query
34
+ Search memories semantically.
35
+
36
+ **Request Body:**
37
+ ```json
38
+ {
39
+ "query": "natural language search",
40
+ "k": 5,
41
+ "user_id": "optional-filter"
42
+ }
43
+ ```
44
+
45
+ **Response:**
46
+ ```json
47
+ {
48
+ "query": "natural language search",
49
+ "result": "Formatted memory results as text",
50
+ "matches": [
51
+ {"id": "uuid", "content": "...", "score": 0.95}
52
+ ]
53
+ }
54
+ ```
55
+
56
+ ### GET /memory/all
57
+ List all memories with pagination.
58
+
59
+ **Query Parameters:**
60
+ - `user_id`: Filter by user
61
+ - `l`: Limit (default 50)
62
+ - `u`: Offset (default 0)
63
+ - `key_id`: Filter by workspace
64
+
65
+ ### DELETE /memory/{id}
66
+ Delete a specific memory.
@@ -0,0 +1,45 @@
1
+ # Ahok Memory Cloud Integration Examples
2
+
3
+ ## Python Integration
4
+ ```python
5
+ import requests
6
+
7
+ API_KEY = "your-api-key"
8
+ BASE_URL = "https://zqmt62peqz.us-east-1.awsapprunner.com"
9
+
10
+ def remember(content, user_id=None):
11
+ return requests.post(f"{BASE_URL}/memory/add",
12
+ headers={"x-api-key": API_KEY},
13
+ json={"content": content, "user_id": user_id}
14
+ ).json()
15
+
16
+ def recall(query, k=5):
17
+ return requests.post(f"{BASE_URL}/query",
18
+ headers={"x-api-key": API_KEY},
19
+ json={"query": query, "k": k}
20
+ ).json()
21
+ ```
22
+
23
+ ## TypeScript Integration
24
+ ```typescript
25
+ const API_KEY = "your-api-key";
26
+ const BASE_URL = "https://zqmt62peqz.us-east-1.awsapprunner.com";
27
+
28
+ async function remember(content: string, userId?: string) {
29
+ const res = await fetch(`${BASE_URL}/memory/add`, {
30
+ method: "POST",
31
+ headers: { "Content-Type": "application/json", "x-api-key": API_KEY },
32
+ body: JSON.stringify({ content, user_id: userId })
33
+ });
34
+ return res.json();
35
+ }
36
+
37
+ async function recall(query: string, k = 5) {
38
+ const res = await fetch(`${BASE_URL}/query`, {
39
+ method: "POST",
40
+ headers: { "Content-Type": "application/json", "x-api-key": API_KEY },
41
+ body: JSON.stringify({ query, k })
42
+ });
43
+ return res.json();
44
+ }
45
+ ```