dsh-tdai-memory 0.2.13 → 0.3.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/LICENSE +21 -21
- package/README.md +15 -13
- package/README.zh.md +9 -7
- package/THIRD-PARTY-NOTICES.md +20 -20
- package/client.js +21 -4
- package/cordis.patch.yml +8 -8
- package/index.js +36 -14
- package/package.json +77 -78
- package/recall-inject.js +86 -86
- 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/adapters/standalone/llm-runner.js +34 -6
- package/vendor/tdai/config.js +3 -0
- 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/seed-runtime.js +4 -0
- 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/tdai-core.js +4 -0
- 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/session-header-fetch.js +88 -0
- package/vendor/tdai/utils/text-utils.js +29 -29
- package/vendor/tdai/utils/time.js +252 -252
|
@@ -21,6 +21,7 @@ import { generateText, tool, stepCountIs, jsonSchema } from "ai";
|
|
|
21
21
|
import { createOpenAI } from "@ai-sdk/openai";
|
|
22
22
|
import { report } from "../../core/report/reporter.js";
|
|
23
23
|
import { createNoThinkFetch } from "../../utils/no-think-fetch.js";
|
|
24
|
+
import { resolvePersistentSessionId, sessionHeaderOf } from "../../utils/session-header-fetch.js";
|
|
24
25
|
const TAG = "[memory-tdai] [standalone-runner]";
|
|
25
26
|
// Max iterations in the tool-call loop to prevent infinite loops
|
|
26
27
|
const MAX_TOOL_ITERATIONS = 20;
|
|
@@ -132,6 +133,7 @@ export class StandaloneLLMRunner {
|
|
|
132
133
|
enableTools;
|
|
133
134
|
logger;
|
|
134
135
|
customFetch;
|
|
136
|
+
sessionIdPromise;
|
|
135
137
|
constructor(opts) {
|
|
136
138
|
this.config = opts.config;
|
|
137
139
|
this.model = opts.model ?? opts.config.model;
|
|
@@ -140,6 +142,37 @@ export class StandaloneLLMRunner {
|
|
|
140
142
|
this.customFetch = opts.config.disableThinking
|
|
141
143
|
? createNoThinkFetch(opts.config.disableThinking)
|
|
142
144
|
: undefined;
|
|
145
|
+
// Resolve the persistent session id lazily (async, cached). Only needed
|
|
146
|
+
// when the session header is enabled and no fixed sessionId is set.
|
|
147
|
+
const { sendSessionHeader, sessionId, dataDir } = opts.config;
|
|
148
|
+
if (sendSessionHeader === false || (sessionId && String(sessionId).trim())) {
|
|
149
|
+
this.sessionIdPromise = Promise.resolve(String(sessionId ?? "").trim());
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
this.sessionIdPromise = resolvePersistentSessionId(dataDir);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
async buildProvider() {
|
|
156
|
+
const providerOptions = {
|
|
157
|
+
baseURL: this.config.baseUrl,
|
|
158
|
+
apiKey: this.config.apiKey,
|
|
159
|
+
compatibility: "compatible",
|
|
160
|
+
...(this.customFetch ? { fetch: this.customFetch } : {}),
|
|
161
|
+
};
|
|
162
|
+
// x-opencode-session: stable per-conversation id header.
|
|
163
|
+
if (this.config.sendSessionHeader !== false) {
|
|
164
|
+
const persistentId = await this.sessionIdPromise;
|
|
165
|
+
const header = sessionHeaderOf({
|
|
166
|
+
send: this.config.sendSessionHeader,
|
|
167
|
+
headerName: this.config.sessionHeaderName,
|
|
168
|
+
sessionId: this.config.sessionId,
|
|
169
|
+
persistentId,
|
|
170
|
+
});
|
|
171
|
+
if (header) {
|
|
172
|
+
providerOptions.headers = { ...(providerOptions.headers ?? {}), ...header };
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return createOpenAI(providerOptions);
|
|
143
176
|
}
|
|
144
177
|
async run(params) {
|
|
145
178
|
const runStartMs = Date.now();
|
|
@@ -151,12 +184,7 @@ export class StandaloneLLMRunner {
|
|
|
151
184
|
// Create OpenAI-compatible provider via AI SDK
|
|
152
185
|
// Use "compatible" mode to call /chat/completions (not Responses API),
|
|
153
186
|
// which works with all OpenAI-compatible backends (DeepSeek, Qwen, etc.)
|
|
154
|
-
const provider =
|
|
155
|
-
baseURL: this.config.baseUrl,
|
|
156
|
-
apiKey: this.config.apiKey,
|
|
157
|
-
compatibility: "compatible",
|
|
158
|
-
...(this.customFetch ? { fetch: this.customFetch } : {}),
|
|
159
|
-
});
|
|
187
|
+
const provider = await this.buildProvider();
|
|
160
188
|
// For pure text tasks like L1 extraction, avoid exposing any tools.
|
|
161
189
|
const tools = this.enableTools
|
|
162
190
|
? createSandboxedTools(workspaceDir, this.logger)
|
package/vendor/tdai/config.js
CHANGED
|
@@ -257,6 +257,9 @@ export function parseConfig(raw) {
|
|
|
257
257
|
maxTokens: num(llmGroup, "maxTokens") ?? 4096,
|
|
258
258
|
timeoutMs: num(llmGroup, "timeoutMs") ?? 120_000,
|
|
259
259
|
disableThinking: normalizeDisableThinking(boolOrStr(llmGroup, "disableThinking")),
|
|
260
|
+
sendSessionHeader: bool(llmGroup, "sendSessionHeader") ?? true,
|
|
261
|
+
sessionHeaderName: str(llmGroup, "sessionHeaderName") ?? "x-opencode-session",
|
|
262
|
+
sessionId: str(llmGroup, "sessionId") ?? "",
|
|
260
263
|
};
|
|
261
264
|
})(),
|
|
262
265
|
offload,
|