opencode-graphiti 0.0.0-development

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 (179) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +358 -0
  3. package/esm/_dnt.polyfills.d.ts +166 -0
  4. package/esm/_dnt.polyfills.d.ts.map +1 -0
  5. package/esm/_dnt.polyfills.js +177 -0
  6. package/esm/_dnt.shims.d.ts +6 -0
  7. package/esm/_dnt.shims.d.ts.map +1 -0
  8. package/esm/_dnt.shims.js +61 -0
  9. package/esm/deno.d.ts +45 -0
  10. package/esm/deno.d.ts.map +1 -0
  11. package/esm/deno.js +39 -0
  12. package/esm/mod.d.ts +3 -0
  13. package/esm/mod.d.ts.map +1 -0
  14. package/esm/mod.js +2 -0
  15. package/esm/package.json +3 -0
  16. package/esm/src/config.d.ts +20 -0
  17. package/esm/src/config.d.ts.map +1 -0
  18. package/esm/src/config.js +246 -0
  19. package/esm/src/handlers/chat.d.ts +14 -0
  20. package/esm/src/handlers/chat.d.ts.map +1 -0
  21. package/esm/src/handlers/chat.js +60 -0
  22. package/esm/src/handlers/compacting.d.ts +9 -0
  23. package/esm/src/handlers/compacting.d.ts.map +1 -0
  24. package/esm/src/handlers/compacting.js +30 -0
  25. package/esm/src/handlers/event.d.ts +22 -0
  26. package/esm/src/handlers/event.d.ts.map +1 -0
  27. package/esm/src/handlers/event.js +287 -0
  28. package/esm/src/handlers/messages.d.ts +9 -0
  29. package/esm/src/handlers/messages.d.ts.map +1 -0
  30. package/esm/src/handlers/messages.js +93 -0
  31. package/esm/src/index.d.ts +5 -0
  32. package/esm/src/index.d.ts.map +1 -0
  33. package/esm/src/index.js +153 -0
  34. package/esm/src/services/batch-drain.d.ts +23 -0
  35. package/esm/src/services/batch-drain.d.ts.map +1 -0
  36. package/esm/src/services/batch-drain.js +217 -0
  37. package/esm/src/services/connection-manager.d.ts +104 -0
  38. package/esm/src/services/connection-manager.d.ts.map +1 -0
  39. package/esm/src/services/connection-manager.js +621 -0
  40. package/esm/src/services/constants.d.ts +7 -0
  41. package/esm/src/services/constants.d.ts.map +1 -0
  42. package/esm/src/services/constants.js +6 -0
  43. package/esm/src/services/context-limit.d.ts +3 -0
  44. package/esm/src/services/context-limit.d.ts.map +1 -0
  45. package/esm/src/services/context-limit.js +44 -0
  46. package/esm/src/services/event-extractor.d.ts +29 -0
  47. package/esm/src/services/event-extractor.d.ts.map +1 -0
  48. package/esm/src/services/event-extractor.js +659 -0
  49. package/esm/src/services/graphiti-async.d.ts +22 -0
  50. package/esm/src/services/graphiti-async.d.ts.map +1 -0
  51. package/esm/src/services/graphiti-async.js +219 -0
  52. package/esm/src/services/graphiti-mcp.d.ts +57 -0
  53. package/esm/src/services/graphiti-mcp.d.ts.map +1 -0
  54. package/esm/src/services/graphiti-mcp.js +194 -0
  55. package/esm/src/services/logger.d.ts +9 -0
  56. package/esm/src/services/logger.d.ts.map +1 -0
  57. package/esm/src/services/logger.js +104 -0
  58. package/esm/src/services/opencode-warning.d.ts +8 -0
  59. package/esm/src/services/opencode-warning.d.ts.map +1 -0
  60. package/esm/src/services/opencode-warning.js +104 -0
  61. package/esm/src/services/redis-cache.d.ts +27 -0
  62. package/esm/src/services/redis-cache.d.ts.map +1 -0
  63. package/esm/src/services/redis-cache.js +215 -0
  64. package/esm/src/services/redis-client.d.ts +89 -0
  65. package/esm/src/services/redis-client.d.ts.map +1 -0
  66. package/esm/src/services/redis-client.js +906 -0
  67. package/esm/src/services/redis-events.d.ts +46 -0
  68. package/esm/src/services/redis-events.d.ts.map +1 -0
  69. package/esm/src/services/redis-events.js +517 -0
  70. package/esm/src/services/redis-snapshot.d.ts +16 -0
  71. package/esm/src/services/redis-snapshot.d.ts.map +1 -0
  72. package/esm/src/services/redis-snapshot.js +184 -0
  73. package/esm/src/services/render-utils.d.ts +23 -0
  74. package/esm/src/services/render-utils.d.ts.map +1 -0
  75. package/esm/src/services/render-utils.js +149 -0
  76. package/esm/src/services/runtime-teardown.d.ts +23 -0
  77. package/esm/src/services/runtime-teardown.d.ts.map +1 -0
  78. package/esm/src/services/runtime-teardown.js +119 -0
  79. package/esm/src/services/sdk-normalize.d.ts +55 -0
  80. package/esm/src/services/sdk-normalize.d.ts.map +1 -0
  81. package/esm/src/services/sdk-normalize.js +61 -0
  82. package/esm/src/session.d.ts +74 -0
  83. package/esm/src/session.d.ts.map +1 -0
  84. package/esm/src/session.js +694 -0
  85. package/esm/src/types/index.d.ts +120 -0
  86. package/esm/src/types/index.d.ts.map +1 -0
  87. package/esm/src/types/index.js +28 -0
  88. package/esm/src/utils.d.ts +27 -0
  89. package/esm/src/utils.d.ts.map +1 -0
  90. package/esm/src/utils.js +76 -0
  91. package/package.json +59 -0
  92. package/script/_dnt.polyfills.d.ts +166 -0
  93. package/script/_dnt.polyfills.d.ts.map +1 -0
  94. package/script/_dnt.polyfills.js +180 -0
  95. package/script/_dnt.shims.d.ts +6 -0
  96. package/script/_dnt.shims.d.ts.map +1 -0
  97. package/script/_dnt.shims.js +65 -0
  98. package/script/deno.d.ts +45 -0
  99. package/script/deno.d.ts.map +1 -0
  100. package/script/deno.js +41 -0
  101. package/script/mod.d.ts +3 -0
  102. package/script/mod.d.ts.map +1 -0
  103. package/script/mod.js +6 -0
  104. package/script/package.json +3 -0
  105. package/script/src/config.d.ts +20 -0
  106. package/script/src/config.d.ts.map +1 -0
  107. package/script/src/config.js +256 -0
  108. package/script/src/handlers/chat.d.ts +14 -0
  109. package/script/src/handlers/chat.d.ts.map +1 -0
  110. package/script/src/handlers/chat.js +63 -0
  111. package/script/src/handlers/compacting.d.ts +9 -0
  112. package/script/src/handlers/compacting.d.ts.map +1 -0
  113. package/script/src/handlers/compacting.js +33 -0
  114. package/script/src/handlers/event.d.ts +22 -0
  115. package/script/src/handlers/event.d.ts.map +1 -0
  116. package/script/src/handlers/event.js +290 -0
  117. package/script/src/handlers/messages.d.ts +9 -0
  118. package/script/src/handlers/messages.d.ts.map +1 -0
  119. package/script/src/handlers/messages.js +96 -0
  120. package/script/src/index.d.ts +5 -0
  121. package/script/src/index.d.ts.map +1 -0
  122. package/script/src/index.js +159 -0
  123. package/script/src/services/batch-drain.d.ts +23 -0
  124. package/script/src/services/batch-drain.d.ts.map +1 -0
  125. package/script/src/services/batch-drain.js +221 -0
  126. package/script/src/services/connection-manager.d.ts +104 -0
  127. package/script/src/services/connection-manager.d.ts.map +1 -0
  128. package/script/src/services/connection-manager.js +635 -0
  129. package/script/src/services/constants.d.ts +7 -0
  130. package/script/src/services/constants.d.ts.map +1 -0
  131. package/script/src/services/constants.js +9 -0
  132. package/script/src/services/context-limit.d.ts +3 -0
  133. package/script/src/services/context-limit.d.ts.map +1 -0
  134. package/script/src/services/context-limit.js +47 -0
  135. package/script/src/services/event-extractor.d.ts +29 -0
  136. package/script/src/services/event-extractor.d.ts.map +1 -0
  137. package/script/src/services/event-extractor.js +669 -0
  138. package/script/src/services/graphiti-async.d.ts +22 -0
  139. package/script/src/services/graphiti-async.d.ts.map +1 -0
  140. package/script/src/services/graphiti-async.js +223 -0
  141. package/script/src/services/graphiti-mcp.d.ts +57 -0
  142. package/script/src/services/graphiti-mcp.d.ts.map +1 -0
  143. package/script/src/services/graphiti-mcp.js +198 -0
  144. package/script/src/services/logger.d.ts +9 -0
  145. package/script/src/services/logger.d.ts.map +1 -0
  146. package/script/src/services/logger.js +142 -0
  147. package/script/src/services/opencode-warning.d.ts +8 -0
  148. package/script/src/services/opencode-warning.d.ts.map +1 -0
  149. package/script/src/services/opencode-warning.js +114 -0
  150. package/script/src/services/redis-cache.d.ts +27 -0
  151. package/script/src/services/redis-cache.d.ts.map +1 -0
  152. package/script/src/services/redis-cache.js +219 -0
  153. package/script/src/services/redis-client.d.ts +89 -0
  154. package/script/src/services/redis-client.d.ts.map +1 -0
  155. package/script/src/services/redis-client.js +943 -0
  156. package/script/src/services/redis-events.d.ts +46 -0
  157. package/script/src/services/redis-events.d.ts.map +1 -0
  158. package/script/src/services/redis-events.js +535 -0
  159. package/script/src/services/redis-snapshot.d.ts +16 -0
  160. package/script/src/services/redis-snapshot.d.ts.map +1 -0
  161. package/script/src/services/redis-snapshot.js +189 -0
  162. package/script/src/services/render-utils.d.ts +23 -0
  163. package/script/src/services/render-utils.d.ts.map +1 -0
  164. package/script/src/services/render-utils.js +165 -0
  165. package/script/src/services/runtime-teardown.d.ts +23 -0
  166. package/script/src/services/runtime-teardown.d.ts.map +1 -0
  167. package/script/src/services/runtime-teardown.js +155 -0
  168. package/script/src/services/sdk-normalize.d.ts +55 -0
  169. package/script/src/services/sdk-normalize.d.ts.map +1 -0
  170. package/script/src/services/sdk-normalize.js +67 -0
  171. package/script/src/session.d.ts +74 -0
  172. package/script/src/session.d.ts.map +1 -0
  173. package/script/src/session.js +698 -0
  174. package/script/src/types/index.d.ts +120 -0
  175. package/script/src/types/index.d.ts.map +1 -0
  176. package/script/src/types/index.js +33 -0
  177. package/script/src/utils.d.ts +27 -0
  178. package/script/src/utils.d.ts.map +1 -0
  179. package/script/src/utils.js +87 -0
@@ -0,0 +1,177 @@
1
+ function findLastIndex(self, callbackfn, that) {
2
+ const boundFunc = that === undefined ? callbackfn : callbackfn.bind(that);
3
+ let index = self.length - 1;
4
+ while (index >= 0) {
5
+ const result = boundFunc(self[index], index, self);
6
+ if (result) {
7
+ return index;
8
+ }
9
+ index--;
10
+ }
11
+ return -1;
12
+ }
13
+ function findLast(self, callbackfn, that) {
14
+ const index = self.findLastIndex(callbackfn, that);
15
+ return index === -1 ? undefined : self[index];
16
+ }
17
+ if (!Array.prototype.findLastIndex) {
18
+ Array.prototype.findLastIndex = function (callbackfn, that) {
19
+ return findLastIndex(this, callbackfn, that);
20
+ };
21
+ }
22
+ if (!Array.prototype.findLast) {
23
+ Array.prototype.findLast = function (callbackfn, that) {
24
+ return findLast(this, callbackfn, that);
25
+ };
26
+ }
27
+ if (!Uint8Array.prototype.findLastIndex) {
28
+ Uint8Array.prototype.findLastIndex = function (callbackfn, that) {
29
+ return findLastIndex(this, callbackfn, that);
30
+ };
31
+ }
32
+ if (!Uint8Array.prototype.findLast) {
33
+ Uint8Array.prototype.findLast = function (callbackfn, that) {
34
+ return findLast(this, callbackfn, that);
35
+ };
36
+ }
37
+ // https://github.com/tc39/proposal-accessible-object-hasownproperty/blob/main/polyfill.js
38
+ if (!Object.hasOwn) {
39
+ Object.defineProperty(Object, "hasOwn", {
40
+ value: function (object, property) {
41
+ if (object == null) {
42
+ throw new TypeError("Cannot convert undefined or null to object");
43
+ }
44
+ return Object.prototype.hasOwnProperty.call(Object(object), property);
45
+ },
46
+ configurable: true,
47
+ enumerable: false,
48
+ writable: true,
49
+ });
50
+ }
51
+ /**
52
+ * Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
53
+ * but instead of using npm to install additional dependencies,
54
+ * this approach manually consolidates cjs/mjs/d.ts into a single file.
55
+ *
56
+ * Note that this code might be imported multiple times
57
+ * (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
58
+ * or Node.js might dynamically clear the cache and then force a require).
59
+ * Therefore, it's important to avoid redundant writes to global objects.
60
+ * Additionally, consider that commonjs is used alongside esm,
61
+ * so the two ponyfill functions are stored independently in two separate global objects.
62
+ */
63
+ //@ts-ignore
64
+ import { createRequire } from "node:module";
65
+ //@ts-ignore
66
+ import { fileURLToPath, pathToFileURL } from "node:url";
67
+ //@ts-ignore
68
+ import { dirname } from "node:path";
69
+ const defineGlobalPonyfill = (symbolFor, fn) => {
70
+ if (!Reflect.has(globalThis, Symbol.for(symbolFor))) {
71
+ Object.defineProperty(globalThis, Symbol.for(symbolFor), {
72
+ configurable: true,
73
+ get() {
74
+ return fn;
75
+ },
76
+ });
77
+ }
78
+ };
79
+ export let import_meta_ponyfill_commonjs = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-commonjs")) ??
80
+ (() => {
81
+ const moduleImportMetaWM = new WeakMap();
82
+ return (require, module) => {
83
+ let importMetaCache = moduleImportMetaWM.get(module);
84
+ if (importMetaCache == null) {
85
+ const importMeta = Object.assign(Object.create(null), {
86
+ url: pathToFileURL(module.filename).href,
87
+ main: require.main == module,
88
+ resolve: (specifier, parentURL = importMeta.url) => {
89
+ return pathToFileURL((importMeta.url === parentURL
90
+ ? require
91
+ : createRequire(parentURL))
92
+ .resolve(specifier)).href;
93
+ },
94
+ filename: module.filename,
95
+ dirname: module.path,
96
+ });
97
+ moduleImportMetaWM.set(module, importMeta);
98
+ importMetaCache = importMeta;
99
+ }
100
+ return importMetaCache;
101
+ };
102
+ })());
103
+ defineGlobalPonyfill("import-meta-ponyfill-commonjs", import_meta_ponyfill_commonjs);
104
+ export let import_meta_ponyfill_esmodule = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-esmodule")) ??
105
+ ((importMeta) => {
106
+ const resolveFunStr = String(importMeta.resolve);
107
+ const shimWs = new WeakSet();
108
+ //@ts-ignore
109
+ const mainUrl = ("file:///" + process.argv[1].replace(/\\/g, "/"))
110
+ .replace(/\/{3,}/, "///");
111
+ const commonShim = (importMeta) => {
112
+ if (typeof importMeta.main !== "boolean") {
113
+ importMeta.main = importMeta.url === mainUrl;
114
+ }
115
+ if (typeof importMeta.filename !== "string") {
116
+ importMeta.filename = fileURLToPath(importMeta.url);
117
+ importMeta.dirname = dirname(importMeta.filename);
118
+ }
119
+ };
120
+ if (
121
+ // v16.2.0+, v14.18.0+: Add support for WHATWG URL object to parentURL parameter.
122
+ resolveFunStr === "undefined" ||
123
+ // v20.0.0+, v18.19.0+"" This API now returns a string synchronously instead of a Promise.
124
+ resolveFunStr.startsWith("async")
125
+ // enable by --experimental-import-meta-resolve flag
126
+ ) {
127
+ import_meta_ponyfill_esmodule = (importMeta) => {
128
+ if (!shimWs.has(importMeta)) {
129
+ shimWs.add(importMeta);
130
+ const importMetaUrlRequire = {
131
+ url: importMeta.url,
132
+ require: createRequire(importMeta.url),
133
+ };
134
+ importMeta.resolve = function resolve(specifier, parentURL = importMeta.url) {
135
+ return pathToFileURL((importMetaUrlRequire.url === parentURL
136
+ ? importMetaUrlRequire.require
137
+ : createRequire(parentURL)).resolve(specifier)).href;
138
+ };
139
+ commonShim(importMeta);
140
+ }
141
+ return importMeta;
142
+ };
143
+ }
144
+ else {
145
+ /// native support
146
+ import_meta_ponyfill_esmodule = (importMeta) => {
147
+ if (!shimWs.has(importMeta)) {
148
+ shimWs.add(importMeta);
149
+ commonShim(importMeta);
150
+ }
151
+ return importMeta;
152
+ };
153
+ }
154
+ return import_meta_ponyfill_esmodule(importMeta);
155
+ }));
156
+ defineGlobalPonyfill("import-meta-ponyfill-esmodule", import_meta_ponyfill_esmodule);
157
+ export let import_meta_ponyfill = ((...args) => {
158
+ const _MODULE = (() => {
159
+ if (typeof require === "function" && typeof module === "object") {
160
+ return "commonjs";
161
+ }
162
+ else {
163
+ // eval("typeof import.meta");
164
+ return "esmodule";
165
+ }
166
+ })();
167
+ if (_MODULE === "commonjs") {
168
+ //@ts-ignore
169
+ import_meta_ponyfill = (r, m) => import_meta_ponyfill_commonjs(r, m);
170
+ }
171
+ else {
172
+ //@ts-ignore
173
+ import_meta_ponyfill = (im) => import_meta_ponyfill_esmodule(im);
174
+ }
175
+ //@ts-ignore
176
+ return import_meta_ponyfill(...args);
177
+ });
@@ -0,0 +1,6 @@
1
+ import { Deno } from "@deno/shim-deno";
2
+ export { Deno } from "@deno/shim-deno";
3
+ export declare const dntGlobalThis: Omit<typeof globalThis, "Deno"> & {
4
+ Deno: typeof Deno;
5
+ };
6
+ //# sourceMappingURL=_dnt.shims.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAKvC,eAAO,MAAM,aAAa;;CAA2C,CAAC"}
@@ -0,0 +1,61 @@
1
+ import { Deno } from "@deno/shim-deno";
2
+ export { Deno } from "@deno/shim-deno";
3
+ const dntGlobals = {
4
+ Deno,
5
+ };
6
+ export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
7
+ function createMergeProxy(baseObj, extObj) {
8
+ return new Proxy(baseObj, {
9
+ get(_target, prop, _receiver) {
10
+ if (prop in extObj) {
11
+ return extObj[prop];
12
+ }
13
+ else {
14
+ return baseObj[prop];
15
+ }
16
+ },
17
+ set(_target, prop, value) {
18
+ if (prop in extObj) {
19
+ delete extObj[prop];
20
+ }
21
+ baseObj[prop] = value;
22
+ return true;
23
+ },
24
+ deleteProperty(_target, prop) {
25
+ let success = false;
26
+ if (prop in extObj) {
27
+ delete extObj[prop];
28
+ success = true;
29
+ }
30
+ if (prop in baseObj) {
31
+ delete baseObj[prop];
32
+ success = true;
33
+ }
34
+ return success;
35
+ },
36
+ ownKeys(_target) {
37
+ const baseKeys = Reflect.ownKeys(baseObj);
38
+ const extKeys = Reflect.ownKeys(extObj);
39
+ const extKeysSet = new Set(extKeys);
40
+ return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
41
+ },
42
+ defineProperty(_target, prop, desc) {
43
+ if (prop in extObj) {
44
+ delete extObj[prop];
45
+ }
46
+ Reflect.defineProperty(baseObj, prop, desc);
47
+ return true;
48
+ },
49
+ getOwnPropertyDescriptor(_target, prop) {
50
+ if (prop in extObj) {
51
+ return Reflect.getOwnPropertyDescriptor(extObj, prop);
52
+ }
53
+ else {
54
+ return Reflect.getOwnPropertyDescriptor(baseObj, prop);
55
+ }
56
+ },
57
+ has(_target, prop) {
58
+ return prop in extObj || prop in baseObj;
59
+ },
60
+ });
61
+ }
package/esm/deno.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ declare namespace _default {
2
+ export let name: string;
3
+ export let description: string;
4
+ export let version: string;
5
+ export let license: string;
6
+ export namespace tasks {
7
+ let build: string;
8
+ let check: string;
9
+ let deploy: string;
10
+ let dev: string;
11
+ let lint: string;
12
+ let fmt: string;
13
+ }
14
+ export namespace lint_1 {
15
+ let exclude: string[];
16
+ namespace rules {
17
+ let exclude_1: string[];
18
+ export { exclude_1 as exclude };
19
+ }
20
+ }
21
+ export { lint_1 as lint };
22
+ export namespace fmt_1 {
23
+ let exclude_2: string[];
24
+ export { exclude_2 as exclude };
25
+ }
26
+ export { fmt_1 as fmt };
27
+ export namespace compilerOptions {
28
+ let strict: boolean;
29
+ let lib: string[];
30
+ }
31
+ export let nodeModulesDir: string;
32
+ export let imports: {
33
+ "@modelcontextprotocol/sdk": string;
34
+ "@opencode-ai/plugin": string;
35
+ "@opencode-ai/sdk": string;
36
+ cosmiconfig: string;
37
+ ioredis: string;
38
+ zod: string;
39
+ };
40
+ export let exports: {
41
+ ".": string;
42
+ };
43
+ }
44
+ export default _default;
45
+ //# sourceMappingURL=deno.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deno.d.ts","sourceRoot":"","sources":["../src/deno.js"],"names":[],"mappings":""}
package/esm/deno.js ADDED
@@ -0,0 +1,39 @@
1
+ export default {
2
+ "name": "opencode-graphiti",
3
+ "description": "OpenCode plugin for persistent memory via Graphiti knowledge graph",
4
+ "version": "0.0.0-development",
5
+ "license": "MIT",
6
+ "tasks": {
7
+ "build": "deno run -A dnt.ts",
8
+ "check": "deno check src/index.ts",
9
+ "deploy": "deno eval \"throw new Error('Manual publish is disabled. Use the GitHub Actions publish workflow for releases.')\"",
10
+ "dev": "deno run --allow-all src/index.ts",
11
+ "lint": "deno lint",
12
+ "fmt": "deno fmt"
13
+ },
14
+ "lint": {
15
+ "exclude": ["dist/"],
16
+ "rules": {
17
+ "exclude": ["no-import-prefix"]
18
+ }
19
+ },
20
+ "fmt": {
21
+ "exclude": ["dist/"]
22
+ },
23
+ "compilerOptions": {
24
+ "strict": true,
25
+ "lib": ["deno.ns", "dom", "esnext"]
26
+ },
27
+ "nodeModulesDir": "auto",
28
+ "imports": {
29
+ "@modelcontextprotocol/sdk": "npm:@modelcontextprotocol/sdk@^1.25.2",
30
+ "@opencode-ai/plugin": "npm:@opencode-ai/plugin@1.2.26",
31
+ "@opencode-ai/sdk": "npm:@opencode-ai/sdk@1.2.26",
32
+ "cosmiconfig": "npm:cosmiconfig@9.0.0",
33
+ "ioredis": "npm:ioredis@^5.7.0",
34
+ "zod": "npm:zod@4.3.6"
35
+ },
36
+ "exports": {
37
+ ".": "./mod.ts"
38
+ }
39
+ };
package/esm/mod.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import "./_dnt.polyfills.js";
2
+ export { graphiti } from "./src/index.js";
3
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC"}
package/esm/mod.js ADDED
@@ -0,0 +1,2 @@
1
+ import "./_dnt.polyfills.js";
2
+ export { graphiti } from "./src/index.js";
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,20 @@
1
+ import type { GraphitiConfig } from "./types/index.js";
2
+ type ConfigLoadResult = {
3
+ config: unknown;
4
+ } | null;
5
+ export declare class ConfigLoadError extends Error {
6
+ cause: unknown;
7
+ constructor(message: string, options?: {
8
+ cause?: unknown;
9
+ });
10
+ }
11
+ export interface ConfigExplorerAdapter {
12
+ search(from?: string): ConfigLoadResult;
13
+ load(filePath: string): ConfigLoadResult;
14
+ }
15
+ type ConfigExplorerFactory = () => ConfigExplorerAdapter;
16
+ export declare const setConfigExplorerAdapterForTesting: (factory: ConfigExplorerFactory) => void;
17
+ export declare const resetConfigExplorerAdapterForTesting: () => void;
18
+ export declare function loadConfig(directory?: string): GraphitiConfig;
19
+ export {};
20
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/src/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AA8BvD,KAAK,gBAAgB,GAAG;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAAC;AAMnD,qBAAa,eAAgB,SAAQ,KAAK;IAC/B,KAAK,EAAE,OAAO,CAAC;gBAEZ,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAK3D;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAAC;IACxC,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAAC;CAC1C;AAED,KAAK,qBAAqB,GAAG,MAAM,qBAAqB,CAAC;AAmNzD,eAAO,MAAM,kCAAkC,GAC7C,SAAS,qBAAqB,KAC7B,IAEF,CAAC;AAEF,eAAO,MAAM,oCAAoC,QAAO,IAEvD,CAAC;AAuEF,wBAAgB,UAAU,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,cAAc,CAO7D"}
@@ -0,0 +1,246 @@
1
+ import os from "node:os";
2
+ import { createRequire } from "node:module";
3
+ import { join } from "node:path";
4
+ const DEFAULT_CONFIG = {
5
+ redis: {
6
+ endpoint: "redis://localhost:6379",
7
+ batchSize: 20,
8
+ batchMaxBytes: 51_200,
9
+ sessionTtlSeconds: 86_400,
10
+ cacheTtlSeconds: 600,
11
+ drainRetryMax: 3,
12
+ },
13
+ graphiti: {
14
+ endpoint: "http://localhost:8000/mcp",
15
+ groupIdPrefix: "opencode",
16
+ driftThreshold: 0.5,
17
+ },
18
+ endpoint: "http://localhost:8000/mcp",
19
+ groupIdPrefix: "opencode",
20
+ driftThreshold: 0.5,
21
+ };
22
+ export class ConfigLoadError extends Error {
23
+ constructor(message, options) {
24
+ super(message);
25
+ Object.defineProperty(this, "cause", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: void 0
30
+ });
31
+ this.name = "ConfigLoadError";
32
+ this.cause = options?.cause;
33
+ }
34
+ }
35
+ const require = createRequire(globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).url);
36
+ const isRecord = (value) => !!value && typeof value === "object" && !Array.isArray(value);
37
+ const readString = (value, key) => typeof value[key] === "string" ? value[key] : undefined;
38
+ const readNumber = (value, key) => typeof value[key] === "number" ? value[key] : undefined;
39
+ const normalizeConfig = (value) => {
40
+ if (!isRecord(value))
41
+ return {};
42
+ const compact = (input) => Object.fromEntries(Object.entries(input).filter(([_, entry]) => entry !== undefined));
43
+ const config = {
44
+ endpoint: readString(value, "endpoint"),
45
+ groupIdPrefix: readString(value, "groupIdPrefix"),
46
+ driftThreshold: readNumber(value, "driftThreshold"),
47
+ };
48
+ if (isRecord(value.redis)) {
49
+ config.redis = compact({
50
+ endpoint: readString(value.redis, "endpoint"),
51
+ batchSize: readNumber(value.redis, "batchSize"),
52
+ batchMaxBytes: readNumber(value.redis, "batchMaxBytes"),
53
+ sessionTtlSeconds: readNumber(value.redis, "sessionTtlSeconds"),
54
+ cacheTtlSeconds: readNumber(value.redis, "cacheTtlSeconds"),
55
+ drainRetryMax: readNumber(value.redis, "drainRetryMax"),
56
+ });
57
+ }
58
+ if (isRecord(value.falkordb)) {
59
+ config.falkordb = compact({
60
+ redisEndpoint: readString(value.falkordb, "redisEndpoint"),
61
+ batchSize: readNumber(value.falkordb, "batchSize"),
62
+ batchMaxBytes: readNumber(value.falkordb, "batchMaxBytes"),
63
+ sessionTtlSeconds: readNumber(value.falkordb, "sessionTtlSeconds"),
64
+ cacheTtlSeconds: readNumber(value.falkordb, "cacheTtlSeconds"),
65
+ drainRetryMax: readNumber(value.falkordb, "drainRetryMax"),
66
+ });
67
+ }
68
+ if (isRecord(value.graphiti)) {
69
+ config.graphiti = compact({
70
+ endpoint: readString(value.graphiti, "endpoint"),
71
+ groupIdPrefix: readString(value.graphiti, "groupIdPrefix"),
72
+ driftThreshold: readNumber(value.graphiti, "driftThreshold"),
73
+ });
74
+ }
75
+ return config;
76
+ };
77
+ const isPositiveInteger = (value) => typeof value === "number" && Number.isInteger(value) && value > 0;
78
+ const isUnitInterval = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 &&
79
+ value <= 1;
80
+ const isValidUrlString = (value) => {
81
+ if (!value?.trim())
82
+ return false;
83
+ try {
84
+ new URL(value);
85
+ return true;
86
+ }
87
+ catch {
88
+ return false;
89
+ }
90
+ };
91
+ const assertExplicitUrl = (value, fieldName) => {
92
+ if (value === undefined)
93
+ return;
94
+ if (isValidUrlString(value))
95
+ return;
96
+ throw new ConfigLoadError(`Invalid Graphiti config value for ${fieldName}: expected a valid URL`);
97
+ };
98
+ const validateExplicitConfig = (value) => {
99
+ if (!value)
100
+ return;
101
+ assertExplicitUrl(value.endpoint, "endpoint");
102
+ assertExplicitUrl(value.graphiti?.endpoint, "graphiti.endpoint");
103
+ assertExplicitUrl(value.redis?.endpoint, "redis.endpoint");
104
+ assertExplicitUrl(value.falkordb?.redisEndpoint, "falkordb.redisEndpoint");
105
+ };
106
+ const resolveNumber = (...candidates) => candidates.find((value) => value !== undefined);
107
+ const resolveConfig = (value) => {
108
+ const raw = value ?? {};
109
+ const resolvedRedisEndpoint = raw.redis?.endpoint ??
110
+ raw.falkordb?.redisEndpoint ??
111
+ DEFAULT_CONFIG.redis.endpoint;
112
+ const resolvedBatchSize = resolveNumber(raw.redis?.batchSize, raw.falkordb?.batchSize);
113
+ const resolvedBatchMaxBytes = resolveNumber(raw.redis?.batchMaxBytes, raw.falkordb?.batchMaxBytes);
114
+ const resolvedSessionTtlSeconds = resolveNumber(raw.redis?.sessionTtlSeconds, raw.falkordb?.sessionTtlSeconds);
115
+ const resolvedCacheTtlSeconds = resolveNumber(raw.redis?.cacheTtlSeconds, raw.falkordb?.cacheTtlSeconds);
116
+ const resolvedDrainRetryMax = resolveNumber(raw.redis?.drainRetryMax, raw.falkordb?.drainRetryMax);
117
+ const requestedGraphitiEndpoint = raw.graphiti?.endpoint ?? raw.endpoint;
118
+ const resolvedGraphitiEndpoint = isValidUrlString(requestedGraphitiEndpoint)
119
+ ? requestedGraphitiEndpoint
120
+ : DEFAULT_CONFIG.graphiti.endpoint;
121
+ const resolvedGroupIdPrefix = raw.graphiti?.groupIdPrefix ??
122
+ raw.groupIdPrefix ??
123
+ DEFAULT_CONFIG.graphiti.groupIdPrefix;
124
+ const resolvedDriftThreshold = resolveNumber(raw.graphiti?.driftThreshold, raw.driftThreshold);
125
+ const redis = {
126
+ endpoint: resolvedRedisEndpoint,
127
+ batchSize: isPositiveInteger(resolvedBatchSize)
128
+ ? resolvedBatchSize
129
+ : DEFAULT_CONFIG.redis.batchSize,
130
+ batchMaxBytes: isPositiveInteger(resolvedBatchMaxBytes)
131
+ ? resolvedBatchMaxBytes
132
+ : DEFAULT_CONFIG.redis.batchMaxBytes,
133
+ sessionTtlSeconds: isPositiveInteger(resolvedSessionTtlSeconds)
134
+ ? resolvedSessionTtlSeconds
135
+ : DEFAULT_CONFIG.redis.sessionTtlSeconds,
136
+ cacheTtlSeconds: isPositiveInteger(resolvedCacheTtlSeconds)
137
+ ? resolvedCacheTtlSeconds
138
+ : DEFAULT_CONFIG.redis.cacheTtlSeconds,
139
+ drainRetryMax: isPositiveInteger(resolvedDrainRetryMax)
140
+ ? resolvedDrainRetryMax
141
+ : DEFAULT_CONFIG.redis.drainRetryMax,
142
+ };
143
+ const falkordb = {
144
+ redisEndpoint: redis.endpoint,
145
+ batchSize: redis.batchSize,
146
+ batchMaxBytes: redis.batchMaxBytes,
147
+ sessionTtlSeconds: redis.sessionTtlSeconds,
148
+ cacheTtlSeconds: redis.cacheTtlSeconds,
149
+ drainRetryMax: redis.drainRetryMax,
150
+ };
151
+ const graphiti = {
152
+ endpoint: resolvedGraphitiEndpoint,
153
+ groupIdPrefix: resolvedGroupIdPrefix,
154
+ driftThreshold: isUnitInterval(resolvedDriftThreshold)
155
+ ? resolvedDriftThreshold
156
+ : DEFAULT_CONFIG.graphiti.driftThreshold,
157
+ };
158
+ return {
159
+ redis,
160
+ falkordb,
161
+ graphiti,
162
+ endpoint: graphiti.endpoint,
163
+ groupIdPrefix: graphiti.groupIdPrefix,
164
+ driftThreshold: graphiti.driftThreshold,
165
+ };
166
+ };
167
+ const createCosmiconfigAdapter = () => {
168
+ const { cosmiconfigSync } = require("cosmiconfig");
169
+ const explorer = cosmiconfigSync("graphiti", { searchStrategy: "global" });
170
+ return {
171
+ search(from) {
172
+ return explorer.search(from);
173
+ },
174
+ load(filePath) {
175
+ return explorer.load(filePath);
176
+ },
177
+ };
178
+ };
179
+ let configExplorerFactory = createCosmiconfigAdapter;
180
+ export const setConfigExplorerAdapterForTesting = (factory) => {
181
+ configExplorerFactory = factory;
182
+ };
183
+ export const resetConfigExplorerAdapterForTesting = () => {
184
+ configExplorerFactory = createCosmiconfigAdapter;
185
+ };
186
+ const getConfigExplorerAdapter = () => {
187
+ try {
188
+ return configExplorerFactory();
189
+ }
190
+ catch (err) {
191
+ throw new ConfigLoadError("Unable to initialize Graphiti config discovery", { cause: err });
192
+ }
193
+ };
194
+ const loadConfigFile = (adapter, filePath) => {
195
+ try {
196
+ const loaded = adapter?.load(filePath);
197
+ const normalized = loaded ? normalizeConfig(loaded.config) : null;
198
+ validateExplicitConfig(normalized);
199
+ return normalized;
200
+ }
201
+ catch (err) {
202
+ if (err instanceof ConfigLoadError)
203
+ throw err;
204
+ throw new ConfigLoadError(`Unable to load Graphiti config file: ${filePath}`, { cause: err });
205
+ }
206
+ };
207
+ const getHomeDir = () => {
208
+ try {
209
+ return os.homedir();
210
+ }
211
+ catch {
212
+ return undefined;
213
+ }
214
+ };
215
+ const searchConfig = (adapter, directory) => {
216
+ try {
217
+ const loaded = adapter.search(directory);
218
+ const normalized = loaded ? normalizeConfig(loaded.config) : null;
219
+ validateExplicitConfig(normalized);
220
+ return {
221
+ ok: true,
222
+ config: normalized,
223
+ };
224
+ }
225
+ catch (err) {
226
+ if (err instanceof ConfigLoadError)
227
+ throw err;
228
+ throw new ConfigLoadError("Unable to discover Graphiti config", {
229
+ cause: err,
230
+ });
231
+ }
232
+ };
233
+ const loadLegacyConfig = (adapter) => {
234
+ const homeDir = getHomeDir();
235
+ if (!homeDir)
236
+ return null;
237
+ return loadConfigFile(adapter, join(homeDir, ".config", "opencode", ".graphitirc"));
238
+ };
239
+ export function loadConfig(directory) {
240
+ const adapter = getConfigExplorerAdapter();
241
+ const searched = searchConfig(adapter, directory);
242
+ const loaded = searched.ok ? searched.config : null;
243
+ const resolved = loaded ?? loadLegacyConfig(adapter);
244
+ validateExplicitConfig(resolved);
245
+ return resolveConfig(resolved);
246
+ }
@@ -0,0 +1,14 @@
1
+ import type { Hooks } from "@opencode-ai/plugin";
2
+ import type { GraphitiAsyncService } from "../services/graphiti-async.js";
3
+ import type { RedisEventsService } from "../services/redis-events.js";
4
+ import type { SessionManager } from "../session.js";
5
+ type ChatMessageHook = NonNullable<Hooks["chat.message"]>;
6
+ export interface ChatHandlerDeps {
7
+ sessionManager: SessionManager;
8
+ redisEvents: RedisEventsService;
9
+ graphitiAsync: GraphitiAsyncService;
10
+ drainTriggerSize: number;
11
+ }
12
+ export declare function createChatHandler(deps: ChatHandlerDeps): ChatMessageHook;
13
+ export {};
14
+ //# sourceMappingURL=chat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../../src/src/handlers/chat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAE1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAGtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpD,KAAK,eAAe,GAAG,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;AAI1D,MAAM,WAAW,eAAe;IAC9B,cAAc,EAAE,cAAc,CAAC;IAC/B,WAAW,EAAE,kBAAkB,CAAC;IAChC,aAAa,EAAE,oBAAoB,CAAC;IACpC,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,eAAe,GAAG,eAAe,CAmExE"}