dsh-tdai-memory 0.4.4 → 0.4.6
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/LICENSE +21 -21
- package/README.en.md +56 -0
- package/README.md +38 -159
- package/README.zh.md +3 -118
- package/THIRD-PARTY-NOTICES.md +20 -20
- package/cordis.patch.yml +8 -8
- package/package.json +110 -103
- package/vendor/tdai/adapters/index.js +15 -15
- package/vendor/tdai/adapters/openclaw/host-adapter.js +83 -83
- package/vendor/tdai/adapters/openclaw/index.js +5 -5
- package/vendor/tdai/adapters/openclaw/llm-runner.js +69 -69
- package/vendor/tdai/adapters/standalone/host-adapter.js +58 -58
- package/vendor/tdai/adapters/standalone/index.js +5 -5
- package/vendor/tdai/core/conversation/l0-recorder.js +420 -420
- package/vendor/tdai/core/hooks/auto-capture.js +236 -236
- package/vendor/tdai/core/hooks/auto-recall.js +640 -640
- package/vendor/tdai/core/index.js +8 -8
- package/vendor/tdai/core/persona/persona-generator.js +184 -184
- package/vendor/tdai/core/persona/persona-trigger.js +94 -94
- package/vendor/tdai/core/profile/profile-sync.js +200 -200
- package/vendor/tdai/core/prompts/l1-dedup.js +72 -72
- package/vendor/tdai/core/prompts/l1-extraction.js +34 -34
- package/vendor/tdai/core/prompts/persona-generation.js +35 -35
- package/vendor/tdai/core/prompts/scene-extraction.js +45 -45
- package/vendor/tdai/core/record/l1-dedup.js +318 -318
- package/vendor/tdai/core/record/l1-extractor.js +379 -379
- package/vendor/tdai/core/record/l1-reader.js +178 -178
- package/vendor/tdai/core/record/l1-writer.js +141 -141
- package/vendor/tdai/core/report/reporter.js +86 -86
- package/vendor/tdai/core/scene/filename-normalizer.js +161 -161
- package/vendor/tdai/core/scene/scene-extractor.js +410 -410
- package/vendor/tdai/core/scene/scene-format.js +53 -53
- package/vendor/tdai/core/scene/scene-index.js +82 -82
- package/vendor/tdai/core/scene/scene-navigation.js +57 -57
- package/vendor/tdai/core/seed/input.js +404 -404
- package/vendor/tdai/core/seed/types.js +9 -9
- package/vendor/tdai/core/store/bm25-client.js +117 -117
- package/vendor/tdai/core/store/bm25-local.js +68 -68
- package/vendor/tdai/core/store/embedding.js +632 -632
- package/vendor/tdai/core/store/factory.js +95 -95
- package/vendor/tdai/core/store/search-utils.js +54 -54
- package/vendor/tdai/core/store/sqlite.js +1632 -1632
- package/vendor/tdai/core/store/tcvdb-client.js +221 -221
- package/vendor/tdai/core/store/tcvdb.js +1047 -1047
- package/vendor/tdai/core/store/types.js +17 -17
- package/vendor/tdai/core/tools/conversation-search.js +199 -199
- package/vendor/tdai/core/tools/memory-search.js +207 -207
- package/vendor/tdai/core/types.js +12 -12
- package/vendor/tdai/utils/backup.js +189 -189
- package/vendor/tdai/utils/checkpoint.js +360 -360
- package/vendor/tdai/utils/clean-context-runner.js +472 -472
- package/vendor/tdai/utils/ensure-hook-policy.js +213 -213
- package/vendor/tdai/utils/env.js +13 -13
- package/vendor/tdai/utils/managed-timer.js +127 -127
- package/vendor/tdai/utils/manifest.js +91 -91
- package/vendor/tdai/utils/memory-cleaner.js +300 -300
- package/vendor/tdai/utils/no-think-fetch.js +109 -109
- package/vendor/tdai/utils/openclaw-state-dir.js +26 -26
- package/vendor/tdai/utils/pipeline-factory.js +517 -517
- package/vendor/tdai/utils/pipeline-manager.js +892 -892
- package/vendor/tdai/utils/sanitize.js +360 -360
- package/vendor/tdai/utils/serial-queue.js +103 -103
- package/vendor/tdai/utils/session-filter.js +88 -88
- package/vendor/tdai/utils/text-utils.js +29 -29
- package/vendor/tdai/utils/time.js +252 -252
package/package.json
CHANGED
|
@@ -1,103 +1,110 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-tdai-memory",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"description": "DeepSeek Harness 的 TencentDB Agent Memory 移植:L0 对话捕获 → L1 结构化记忆提取 → L2 场景/L3 画像,自动召回注入 + 记忆/对话搜索工具;复用现有 ~/.memory-tencentdb/memory-tdai 数据;附 Web UI 设置栏。",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "index.js",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": "./index.js",
|
|
9
|
-
"./client": "./client.js",
|
|
10
|
-
"./package.json": "./package.json",
|
|
11
|
-
"./locale/*.json": "./locale/*.json"
|
|
12
|
-
},
|
|
13
|
-
"dsh": {
|
|
14
|
-
"bundle": {
|
|
15
|
-
"patch": "./cordis.patch.yml"
|
|
16
|
-
},
|
|
17
|
-
"client": {
|
|
18
|
-
"platform": "web"
|
|
19
|
-
},
|
|
20
|
-
"compatibility": {
|
|
21
|
-
"dsh": ">=0.2.0-rc.2 <0.3.0 || 0.2.1-rc.1 || 0.2.1-rc.2",
|
|
22
|
-
"dshReleases": {
|
|
23
|
-
"0.1.5-rc.2": "incompatible",
|
|
24
|
-
"0.1.5-rc.3": "incompatible",
|
|
25
|
-
"0.1.6-alpha.1": "unknown",
|
|
26
|
-
"0.1.6-alpha.2": "unknown",
|
|
27
|
-
"0.1.7-alpha.1": "unknown",
|
|
28
|
-
"0.1.7-alpha.2": "unknown",
|
|
29
|
-
"0.1.7-rc.1": "incompatible",
|
|
30
|
-
"0.1.7-rc.2": "incompatible",
|
|
31
|
-
"0.2.0-rc.2": "compatible",
|
|
32
|
-
"0.2.1-rc.1": "compatible",
|
|
33
|
-
"0.2.1-rc.2": "compatible"
|
|
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
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
"url": "https://github.com/Scorp1o117/dsh-tdai-memory
|
|
78
|
-
},
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
"@
|
|
84
|
-
"ai": "^
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
"
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
"
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-tdai-memory",
|
|
3
|
+
"version": "0.4.6",
|
|
4
|
+
"description": "DeepSeek Harness 的 TencentDB Agent Memory 移植:L0 对话捕获 → L1 结构化记忆提取 → L2 场景/L3 画像,自动召回注入 + 记忆/对话搜索工具;复用现有 ~/.memory-tencentdb/memory-tdai 数据;附 Web UI 设置栏。",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.js",
|
|
9
|
+
"./client": "./client.js",
|
|
10
|
+
"./package.json": "./package.json",
|
|
11
|
+
"./locale/*.json": "./locale/*.json"
|
|
12
|
+
},
|
|
13
|
+
"dsh": {
|
|
14
|
+
"bundle": {
|
|
15
|
+
"patch": "./cordis.patch.yml"
|
|
16
|
+
},
|
|
17
|
+
"client": {
|
|
18
|
+
"platform": "web"
|
|
19
|
+
},
|
|
20
|
+
"compatibility": {
|
|
21
|
+
"dsh": ">=0.2.0-rc.2 <0.3.0 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5",
|
|
22
|
+
"dshReleases": {
|
|
23
|
+
"0.1.5-rc.2": "incompatible",
|
|
24
|
+
"0.1.5-rc.3": "incompatible",
|
|
25
|
+
"0.1.6-alpha.1": "unknown",
|
|
26
|
+
"0.1.6-alpha.2": "unknown",
|
|
27
|
+
"0.1.7-alpha.1": "unknown",
|
|
28
|
+
"0.1.7-alpha.2": "unknown",
|
|
29
|
+
"0.1.7-rc.1": "incompatible",
|
|
30
|
+
"0.1.7-rc.2": "incompatible",
|
|
31
|
+
"0.2.0-rc.2": "compatible",
|
|
32
|
+
"0.2.1-rc.1": "compatible",
|
|
33
|
+
"0.2.1-rc.2": "compatible",
|
|
34
|
+
"0.2.1-rc.3": "compatible",
|
|
35
|
+
"0.2.1-rc.4": "compatible",
|
|
36
|
+
"0.2.1-rc.5": "compatible"
|
|
37
|
+
},
|
|
38
|
+
"node": ">=22.18",
|
|
39
|
+
"profiles": [
|
|
40
|
+
"web",
|
|
41
|
+
"desktop"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/Scorp1o117/dsh-tdai-memory",
|
|
46
|
+
"files": [
|
|
47
|
+
"locale",
|
|
48
|
+
"index.js",
|
|
49
|
+
"recall-inject.js",
|
|
50
|
+
"recall-runtime.js",
|
|
51
|
+
"client.js",
|
|
52
|
+
"cordis.patch.yml",
|
|
53
|
+
"vendor",
|
|
54
|
+
"README.md",
|
|
55
|
+
"README.zh.md",
|
|
56
|
+
"LICENSE",
|
|
57
|
+
"THIRD-PARTY-NOTICES.md"
|
|
58
|
+
],
|
|
59
|
+
"keywords": [
|
|
60
|
+
"dsh",
|
|
61
|
+
"dsh-plugin",
|
|
62
|
+
"deepseek-harness",
|
|
63
|
+
"memory",
|
|
64
|
+
"tencentdb",
|
|
65
|
+
"agent-memory",
|
|
66
|
+
"rag",
|
|
67
|
+
"vector-search",
|
|
68
|
+
"persona"
|
|
69
|
+
],
|
|
70
|
+
"license": "MIT",
|
|
71
|
+
"engines": {
|
|
72
|
+
"node": ">=22.18",
|
|
73
|
+
"dsh": ">=0.2.0-rc.2 <0.3.0 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5"
|
|
74
|
+
},
|
|
75
|
+
"repository": {
|
|
76
|
+
"type": "git",
|
|
77
|
+
"url": "git+https://github.com/Scorp1o117/dsh-tdai-memory.git"
|
|
78
|
+
},
|
|
79
|
+
"bugs": {
|
|
80
|
+
"url": "https://github.com/Scorp1o117/dsh-tdai-memory/issues"
|
|
81
|
+
},
|
|
82
|
+
"dependencies": {
|
|
83
|
+
"@ai-sdk/openai": "^3.0.53",
|
|
84
|
+
"@deepseek-ai/schemastery": "^3.18.4",
|
|
85
|
+
"@node-rs/jieba": "^2.0.1",
|
|
86
|
+
"@tencentdb-agent-memory/tcvdb-text": "^0.1.1",
|
|
87
|
+
"ai": "^6.0.164",
|
|
88
|
+
"json5": "^2.2.3",
|
|
89
|
+
"sqlite-vec": "0.1.7-alpha.2",
|
|
90
|
+
"undici": "^8.1.0"
|
|
91
|
+
},
|
|
92
|
+
"devDependencies": {
|
|
93
|
+
"@deepseek-ai/dsh-settings": "0.2.1-rc.5",
|
|
94
|
+
"@deepseek-ai/dsh-tools": "0.2.1-rc.5"
|
|
95
|
+
},
|
|
96
|
+
"peerDependencies": {
|
|
97
|
+
"react": "^18.2.0",
|
|
98
|
+
"@deepseek-ai/dsh-tools": ">=0.2.0-rc.2 <0.3.0 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5",
|
|
99
|
+
"@deepseek-ai/dsh-settings": ">=0.2.0-rc.2 <0.3.0 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5",
|
|
100
|
+
"node-llama-cpp": "^3.19.1"
|
|
101
|
+
},
|
|
102
|
+
"peerDependenciesMeta": {
|
|
103
|
+
"node-llama-cpp": {
|
|
104
|
+
"optional": true
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"scripts": {
|
|
108
|
+
"test": "node tests/settings-scope-compat.test.mjs && node tests/install-contract.test.mjs && node --test tests/plugin-page.test.mjs tests/client-write-flow.test.mjs tests/tools-registration.test.mjs tests/recall-runtime.test.mjs && node --test tests/locale.test.mjs"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TDAI Adapters — barrel re-export for all host adapter implementations.
|
|
3
|
-
*
|
|
4
|
-
* Each adapter translates a specific host environment's API into
|
|
5
|
-
* the host-neutral HostAdapter interface consumed by TdaiCore.
|
|
6
|
-
*
|
|
7
|
-
* Directory structure:
|
|
8
|
-
* adapters/
|
|
9
|
-
* ├── openclaw/ — OpenClaw plugin host (in-process, runEmbeddedPiAgent)
|
|
10
|
-
* └── standalone/ — Gateway / Hermes sidecar (HTTP, OpenAI-compatible API)
|
|
11
|
-
*/
|
|
12
|
-
// OpenClaw adapter
|
|
13
|
-
export { OpenClawHostAdapter, OpenClawLLMRunner, OpenClawLLMRunnerFactory } from "./openclaw/index.js";
|
|
14
|
-
// Standalone adapter
|
|
15
|
-
export { StandaloneHostAdapter, StandaloneLLMRunner, StandaloneLLMRunnerFactory } from "./standalone/index.js";
|
|
1
|
+
/**
|
|
2
|
+
* TDAI Adapters — barrel re-export for all host adapter implementations.
|
|
3
|
+
*
|
|
4
|
+
* Each adapter translates a specific host environment's API into
|
|
5
|
+
* the host-neutral HostAdapter interface consumed by TdaiCore.
|
|
6
|
+
*
|
|
7
|
+
* Directory structure:
|
|
8
|
+
* adapters/
|
|
9
|
+
* ├── openclaw/ — OpenClaw plugin host (in-process, runEmbeddedPiAgent)
|
|
10
|
+
* └── standalone/ — Gateway / Hermes sidecar (HTTP, OpenAI-compatible API)
|
|
11
|
+
*/
|
|
12
|
+
// OpenClaw adapter
|
|
13
|
+
export { OpenClawHostAdapter, OpenClawLLMRunner, OpenClawLLMRunnerFactory } from "./openclaw/index.js";
|
|
14
|
+
// Standalone adapter
|
|
15
|
+
export { StandaloneHostAdapter, StandaloneLLMRunner, StandaloneLLMRunnerFactory } from "./standalone/index.js";
|
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenClawHostAdapter — translates OpenClaw's plugin API into TDAI Core's
|
|
3
|
-
* unified HostAdapter interface.
|
|
4
|
-
*
|
|
5
|
-
* This is the "thin shell" that keeps OpenClaw-specific dependencies
|
|
6
|
-
* (OpenClawPluginApi, pluginConfig, resolveStateDir, event system)
|
|
7
|
-
* confined to the adapter layer while TDAI Core remains host-neutral.
|
|
8
|
-
*
|
|
9
|
-
* Usage (in index.ts):
|
|
10
|
-
* const adapter = new OpenClawHostAdapter({ api, pluginDataDir, config });
|
|
11
|
-
* const core = new TdaiCore({ hostAdapter: adapter, config: parsedConfig });
|
|
12
|
-
*/
|
|
13
|
-
import { OpenClawLLMRunnerFactory } from "./llm-runner.js";
|
|
14
|
-
// ============================
|
|
15
|
-
// OpenClawHostAdapter
|
|
16
|
-
// ============================
|
|
17
|
-
export class OpenClawHostAdapter {
|
|
18
|
-
hostType = "openclaw";
|
|
19
|
-
api;
|
|
20
|
-
pluginDataDir;
|
|
21
|
-
openclawConfig;
|
|
22
|
-
runnerFactory;
|
|
23
|
-
constructor(opts) {
|
|
24
|
-
this.api = opts.api;
|
|
25
|
-
this.pluginDataDir = opts.pluginDataDir;
|
|
26
|
-
this.openclawConfig = opts.openclawConfig;
|
|
27
|
-
this.runnerFactory = new OpenClawLLMRunnerFactory({
|
|
28
|
-
config: opts.openclawConfig,
|
|
29
|
-
agentRuntime: opts.api.runtime.agent,
|
|
30
|
-
logger: opts.api.logger,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Build a RuntimeContext from the current OpenClaw session.
|
|
35
|
-
*
|
|
36
|
-
* In OpenClaw, sessionKey and sessionId come from the event/ctx objects
|
|
37
|
-
* passed to hooks. This method returns a context with sensible defaults;
|
|
38
|
-
* callers can override sessionKey/sessionId per-hook invocation using
|
|
39
|
-
* `buildRuntimeContextForSession()`.
|
|
40
|
-
*/
|
|
41
|
-
getRuntimeContext() {
|
|
42
|
-
return {
|
|
43
|
-
userId: "default_user",
|
|
44
|
-
sessionId: "",
|
|
45
|
-
sessionKey: "",
|
|
46
|
-
platform: "openclaw",
|
|
47
|
-
workspaceDir: process.cwd(),
|
|
48
|
-
dataDir: this.pluginDataDir,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Build a RuntimeContext for a specific session (used per-hook).
|
|
53
|
-
*
|
|
54
|
-
* This is an OpenClaw-specific convenience that merges session-level
|
|
55
|
-
* identifiers from hook ctx into the base context.
|
|
56
|
-
*/
|
|
57
|
-
buildRuntimeContextForSession(sessionKey, sessionId) {
|
|
58
|
-
return {
|
|
59
|
-
...this.getRuntimeContext(),
|
|
60
|
-
sessionKey,
|
|
61
|
-
sessionId: sessionId ?? "",
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
getLogger() {
|
|
65
|
-
return this.api.logger;
|
|
66
|
-
}
|
|
67
|
-
getLLMRunnerFactory() {
|
|
68
|
-
return this.runnerFactory;
|
|
69
|
-
}
|
|
70
|
-
// -- OpenClaw-specific accessors (for index.ts bridge) --------------------
|
|
71
|
-
/** Get the raw OpenClaw plugin API (for legacy callers during migration). */
|
|
72
|
-
getPluginApi() {
|
|
73
|
-
return this.api;
|
|
74
|
-
}
|
|
75
|
-
/** Get the OpenClaw config object (for legacy callers during migration). */
|
|
76
|
-
getOpenClawConfig() {
|
|
77
|
-
return this.openclawConfig;
|
|
78
|
-
}
|
|
79
|
-
/** Get the resolved plugin data directory. */
|
|
80
|
-
getPluginDataDir() {
|
|
81
|
-
return this.pluginDataDir;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* OpenClawHostAdapter — translates OpenClaw's plugin API into TDAI Core's
|
|
3
|
+
* unified HostAdapter interface.
|
|
4
|
+
*
|
|
5
|
+
* This is the "thin shell" that keeps OpenClaw-specific dependencies
|
|
6
|
+
* (OpenClawPluginApi, pluginConfig, resolveStateDir, event system)
|
|
7
|
+
* confined to the adapter layer while TDAI Core remains host-neutral.
|
|
8
|
+
*
|
|
9
|
+
* Usage (in index.ts):
|
|
10
|
+
* const adapter = new OpenClawHostAdapter({ api, pluginDataDir, config });
|
|
11
|
+
* const core = new TdaiCore({ hostAdapter: adapter, config: parsedConfig });
|
|
12
|
+
*/
|
|
13
|
+
import { OpenClawLLMRunnerFactory } from "./llm-runner.js";
|
|
14
|
+
// ============================
|
|
15
|
+
// OpenClawHostAdapter
|
|
16
|
+
// ============================
|
|
17
|
+
export class OpenClawHostAdapter {
|
|
18
|
+
hostType = "openclaw";
|
|
19
|
+
api;
|
|
20
|
+
pluginDataDir;
|
|
21
|
+
openclawConfig;
|
|
22
|
+
runnerFactory;
|
|
23
|
+
constructor(opts) {
|
|
24
|
+
this.api = opts.api;
|
|
25
|
+
this.pluginDataDir = opts.pluginDataDir;
|
|
26
|
+
this.openclawConfig = opts.openclawConfig;
|
|
27
|
+
this.runnerFactory = new OpenClawLLMRunnerFactory({
|
|
28
|
+
config: opts.openclawConfig,
|
|
29
|
+
agentRuntime: opts.api.runtime.agent,
|
|
30
|
+
logger: opts.api.logger,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Build a RuntimeContext from the current OpenClaw session.
|
|
35
|
+
*
|
|
36
|
+
* In OpenClaw, sessionKey and sessionId come from the event/ctx objects
|
|
37
|
+
* passed to hooks. This method returns a context with sensible defaults;
|
|
38
|
+
* callers can override sessionKey/sessionId per-hook invocation using
|
|
39
|
+
* `buildRuntimeContextForSession()`.
|
|
40
|
+
*/
|
|
41
|
+
getRuntimeContext() {
|
|
42
|
+
return {
|
|
43
|
+
userId: "default_user",
|
|
44
|
+
sessionId: "",
|
|
45
|
+
sessionKey: "",
|
|
46
|
+
platform: "openclaw",
|
|
47
|
+
workspaceDir: process.cwd(),
|
|
48
|
+
dataDir: this.pluginDataDir,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Build a RuntimeContext for a specific session (used per-hook).
|
|
53
|
+
*
|
|
54
|
+
* This is an OpenClaw-specific convenience that merges session-level
|
|
55
|
+
* identifiers from hook ctx into the base context.
|
|
56
|
+
*/
|
|
57
|
+
buildRuntimeContextForSession(sessionKey, sessionId) {
|
|
58
|
+
return {
|
|
59
|
+
...this.getRuntimeContext(),
|
|
60
|
+
sessionKey,
|
|
61
|
+
sessionId: sessionId ?? "",
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
getLogger() {
|
|
65
|
+
return this.api.logger;
|
|
66
|
+
}
|
|
67
|
+
getLLMRunnerFactory() {
|
|
68
|
+
return this.runnerFactory;
|
|
69
|
+
}
|
|
70
|
+
// -- OpenClaw-specific accessors (for index.ts bridge) --------------------
|
|
71
|
+
/** Get the raw OpenClaw plugin API (for legacy callers during migration). */
|
|
72
|
+
getPluginApi() {
|
|
73
|
+
return this.api;
|
|
74
|
+
}
|
|
75
|
+
/** Get the OpenClaw config object (for legacy callers during migration). */
|
|
76
|
+
getOpenClawConfig() {
|
|
77
|
+
return this.openclawConfig;
|
|
78
|
+
}
|
|
79
|
+
/** Get the resolved plugin data directory. */
|
|
80
|
+
getPluginDataDir() {
|
|
81
|
+
return this.pluginDataDir;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenClaw adapter — barrel exports.
|
|
3
|
-
*/
|
|
4
|
-
export { OpenClawHostAdapter } from "./host-adapter.js";
|
|
5
|
-
export { OpenClawLLMRunner, OpenClawLLMRunnerFactory } from "./llm-runner.js";
|
|
1
|
+
/**
|
|
2
|
+
* OpenClaw adapter — barrel exports.
|
|
3
|
+
*/
|
|
4
|
+
export { OpenClawHostAdapter } from "./host-adapter.js";
|
|
5
|
+
export { OpenClawLLMRunner, OpenClawLLMRunnerFactory } from "./llm-runner.js";
|
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenClawLLMRunner — wraps the existing CleanContextRunner as a host-neutral LLMRunner.
|
|
3
|
-
*
|
|
4
|
-
* This is a compatibility bridge: TDAI Core modules (L1 extractor, L2 scene extractor,
|
|
5
|
-
* L3 persona generator, L1 dedup) can depend on the `LLMRunner` interface, while
|
|
6
|
-
* OpenClaw continues to use its native `runEmbeddedPiAgent` mechanism under the hood.
|
|
7
|
-
*
|
|
8
|
-
* Usage:
|
|
9
|
-
* const factory = new OpenClawLLMRunnerFactory({ config, agentRuntime, logger });
|
|
10
|
-
* const runner = factory.createRunner({ modelRef: "openai/gpt-4o", enableTools: true });
|
|
11
|
-
* const result = await runner.run({ prompt: "...", taskId: "l1-extraction" });
|
|
12
|
-
*/
|
|
13
|
-
import { CleanContextRunner } from "../../utils/clean-context-runner.js";
|
|
14
|
-
const TAG = "[memory-tdai] [openclaw-runner]";
|
|
15
|
-
// ============================
|
|
16
|
-
// OpenClawLLMRunner
|
|
17
|
-
// ============================
|
|
18
|
-
/**
|
|
19
|
-
* LLMRunner implementation backed by CleanContextRunner.
|
|
20
|
-
*
|
|
21
|
-
* Each instance is configured with a fixed model + tools setting.
|
|
22
|
-
* Create via `OpenClawLLMRunnerFactory.createRunner()`.
|
|
23
|
-
*/
|
|
24
|
-
export class OpenClawLLMRunner {
|
|
25
|
-
runner;
|
|
26
|
-
constructor(runner) {
|
|
27
|
-
this.runner = runner;
|
|
28
|
-
}
|
|
29
|
-
async run(params) {
|
|
30
|
-
return this.runner.run({
|
|
31
|
-
prompt: params.prompt,
|
|
32
|
-
systemPrompt: params.systemPrompt,
|
|
33
|
-
taskId: params.taskId,
|
|
34
|
-
timeoutMs: params.timeoutMs,
|
|
35
|
-
maxTokens: params.maxTokens,
|
|
36
|
-
workspaceDir: params.workspaceDir,
|
|
37
|
-
instanceId: params.instanceId,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Factory that creates OpenClawLLMRunner instances.
|
|
43
|
-
*
|
|
44
|
-
* Encapsulates the OpenClaw-specific dependencies (config, agentRuntime)
|
|
45
|
-
* so that callers only need to specify model + tools.
|
|
46
|
-
*/
|
|
47
|
-
export class OpenClawLLMRunnerFactory {
|
|
48
|
-
config;
|
|
49
|
-
agentRuntime;
|
|
50
|
-
logger;
|
|
51
|
-
constructor(opts) {
|
|
52
|
-
this.config = opts.config;
|
|
53
|
-
this.agentRuntime = opts.agentRuntime;
|
|
54
|
-
this.logger = opts.logger;
|
|
55
|
-
}
|
|
56
|
-
createRunner(opts) {
|
|
57
|
-
const enableTools = opts?.enableTools ?? false;
|
|
58
|
-
const modelRef = opts?.modelRef;
|
|
59
|
-
this.logger?.debug?.(`${TAG} Creating OpenClawLLMRunner: model=${modelRef ?? "(default)"}, tools=${enableTools}`);
|
|
60
|
-
const cleanRunner = new CleanContextRunner({
|
|
61
|
-
config: this.config,
|
|
62
|
-
modelRef,
|
|
63
|
-
enableTools,
|
|
64
|
-
agentRuntime: this.agentRuntime,
|
|
65
|
-
logger: this.logger,
|
|
66
|
-
});
|
|
67
|
-
return new OpenClawLLMRunner(cleanRunner);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* OpenClawLLMRunner — wraps the existing CleanContextRunner as a host-neutral LLMRunner.
|
|
3
|
+
*
|
|
4
|
+
* This is a compatibility bridge: TDAI Core modules (L1 extractor, L2 scene extractor,
|
|
5
|
+
* L3 persona generator, L1 dedup) can depend on the `LLMRunner` interface, while
|
|
6
|
+
* OpenClaw continues to use its native `runEmbeddedPiAgent` mechanism under the hood.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* const factory = new OpenClawLLMRunnerFactory({ config, agentRuntime, logger });
|
|
10
|
+
* const runner = factory.createRunner({ modelRef: "openai/gpt-4o", enableTools: true });
|
|
11
|
+
* const result = await runner.run({ prompt: "...", taskId: "l1-extraction" });
|
|
12
|
+
*/
|
|
13
|
+
import { CleanContextRunner } from "../../utils/clean-context-runner.js";
|
|
14
|
+
const TAG = "[memory-tdai] [openclaw-runner]";
|
|
15
|
+
// ============================
|
|
16
|
+
// OpenClawLLMRunner
|
|
17
|
+
// ============================
|
|
18
|
+
/**
|
|
19
|
+
* LLMRunner implementation backed by CleanContextRunner.
|
|
20
|
+
*
|
|
21
|
+
* Each instance is configured with a fixed model + tools setting.
|
|
22
|
+
* Create via `OpenClawLLMRunnerFactory.createRunner()`.
|
|
23
|
+
*/
|
|
24
|
+
export class OpenClawLLMRunner {
|
|
25
|
+
runner;
|
|
26
|
+
constructor(runner) {
|
|
27
|
+
this.runner = runner;
|
|
28
|
+
}
|
|
29
|
+
async run(params) {
|
|
30
|
+
return this.runner.run({
|
|
31
|
+
prompt: params.prompt,
|
|
32
|
+
systemPrompt: params.systemPrompt,
|
|
33
|
+
taskId: params.taskId,
|
|
34
|
+
timeoutMs: params.timeoutMs,
|
|
35
|
+
maxTokens: params.maxTokens,
|
|
36
|
+
workspaceDir: params.workspaceDir,
|
|
37
|
+
instanceId: params.instanceId,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Factory that creates OpenClawLLMRunner instances.
|
|
43
|
+
*
|
|
44
|
+
* Encapsulates the OpenClaw-specific dependencies (config, agentRuntime)
|
|
45
|
+
* so that callers only need to specify model + tools.
|
|
46
|
+
*/
|
|
47
|
+
export class OpenClawLLMRunnerFactory {
|
|
48
|
+
config;
|
|
49
|
+
agentRuntime;
|
|
50
|
+
logger;
|
|
51
|
+
constructor(opts) {
|
|
52
|
+
this.config = opts.config;
|
|
53
|
+
this.agentRuntime = opts.agentRuntime;
|
|
54
|
+
this.logger = opts.logger;
|
|
55
|
+
}
|
|
56
|
+
createRunner(opts) {
|
|
57
|
+
const enableTools = opts?.enableTools ?? false;
|
|
58
|
+
const modelRef = opts?.modelRef;
|
|
59
|
+
this.logger?.debug?.(`${TAG} Creating OpenClawLLMRunner: model=${modelRef ?? "(default)"}, tools=${enableTools}`);
|
|
60
|
+
const cleanRunner = new CleanContextRunner({
|
|
61
|
+
config: this.config,
|
|
62
|
+
modelRef,
|
|
63
|
+
enableTools,
|
|
64
|
+
agentRuntime: this.agentRuntime,
|
|
65
|
+
logger: this.logger,
|
|
66
|
+
});
|
|
67
|
+
return new OpenClawLLMRunner(cleanRunner);
|
|
68
|
+
}
|
|
69
|
+
}
|