@t0ken.ai/memoryx-openclaw-plugin 2.2.57 → 2.2.59
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/dist/index.d.ts.map +1 -1
- package/dist/index.js +46 -20
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAuDH,UAAU,YAAY;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mCAAmC;IACnC,aAAa,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,UAAU,YAAY;IAClB,QAAQ,EAAE,KAAK,CAAC;QACZ,EAAE,EAAE,MAAM,CAAC;QACX,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC;IACH,eAAe,EAAE,KAAK,CAAC;QACnB,EAAE,EAAE,MAAM,CAAC;QACX,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC;IACH,SAAS,EAAE,OAAO,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAqDD,cAAM,aAAa;IACf,OAAO,CAAC,YAAY,CAA2B;IAC/C,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,aAAa,CAAkB;gBAE3B,YAAY,CAAC,EAAE,YAAY;IAIjC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;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iBAAiB,YAAY,GAAG,IAAI;;AANzD,wBA65BE;AAEF,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -27,7 +27,7 @@ import * as path from "path";
|
|
|
27
27
|
import * as os from "os";
|
|
28
28
|
import * as http from "http";
|
|
29
29
|
// 插件版本号 - 由 prebuild 脚本自动从 package.json 同步
|
|
30
|
-
const PLUGIN_VERSION = "2.2.
|
|
30
|
+
const PLUGIN_VERSION = "2.2.59";
|
|
31
31
|
const DEFAULT_API_BASE = "https://t0ken.ai/api";
|
|
32
32
|
const PLUGIN_DIR = path.join(os.homedir(), ".openclaw", "extensions", "memoryx-openclaw-plugin");
|
|
33
33
|
let logStream = null;
|
|
@@ -37,32 +37,41 @@ function ensureDir() {
|
|
|
37
37
|
fs.mkdirSync(PLUGIN_DIR, { recursive: true });
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
+
const LOG_FILE = path.join(PLUGIN_DIR, "plugin.log");
|
|
40
41
|
/**
|
|
41
42
|
* 分层日志系统
|
|
42
|
-
* -
|
|
43
|
+
* - 所有日志都写入文件(先尝试 stream,未就绪时同步 append 确保不丢)
|
|
43
44
|
* - console=true 时同时写入控制台(用于重要/引导性信息)
|
|
44
|
-
* - console=false 时只写文件(用于调试信息)
|
|
45
45
|
*/
|
|
46
46
|
function log(message, options = {}) {
|
|
47
47
|
const { console: toConsole = false } = options;
|
|
48
|
-
|
|
48
|
+
const line = `[${new Date().toISOString()}] ${message}\n`;
|
|
49
49
|
if (toConsole) {
|
|
50
50
|
console.log(`[MemoryX] ${message}`);
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
setImmediate(() => {
|
|
52
|
+
const writeToFile = () => {
|
|
54
53
|
try {
|
|
55
54
|
if (!logStreamReady) {
|
|
56
55
|
ensureDir();
|
|
57
|
-
logStream = fs.createWriteStream(
|
|
56
|
+
logStream = fs.createWriteStream(LOG_FILE, { flags: "a" });
|
|
58
57
|
logStreamReady = true;
|
|
59
58
|
}
|
|
60
|
-
logStream?.write(
|
|
59
|
+
logStream?.write(line, (err) => { if (err) {
|
|
60
|
+
try {
|
|
61
|
+
fs.appendFileSync(LOG_FILE, line);
|
|
62
|
+
}
|
|
63
|
+
catch (_) { }
|
|
64
|
+
} });
|
|
61
65
|
}
|
|
62
66
|
catch (e) {
|
|
63
|
-
|
|
67
|
+
try {
|
|
68
|
+
ensureDir();
|
|
69
|
+
fs.appendFileSync(LOG_FILE, line);
|
|
70
|
+
}
|
|
71
|
+
catch (_) { }
|
|
64
72
|
}
|
|
65
|
-
}
|
|
73
|
+
};
|
|
74
|
+
setImmediate(writeToFile);
|
|
66
75
|
}
|
|
67
76
|
// Lazy-loaded SDK instance
|
|
68
77
|
let sdkInstance = null;
|
|
@@ -296,6 +305,7 @@ export default {
|
|
|
296
305
|
description: "Real-time memory capture and recall for OpenClaw (powered by @t0ken.ai/memoryx-sdk)",
|
|
297
306
|
register(api, pluginConfig) {
|
|
298
307
|
api.logger.info("[MemoryX] Plugin registering...");
|
|
308
|
+
api.logger.info(`[MemoryX] Plugin log file: ${LOG_FILE}`);
|
|
299
309
|
if (pluginConfig?.apiBaseUrl) {
|
|
300
310
|
api.logger.info(`[MemoryX] API Base: \`${pluginConfig.apiBaseUrl}\``);
|
|
301
311
|
}
|
|
@@ -661,11 +671,8 @@ export default {
|
|
|
661
671
|
// IMPORTANT: 对话流走的是 before_agent_start 事件,不是 message_received!
|
|
662
672
|
// message_received 只在 auto-reply 功能中触发
|
|
663
673
|
api.on("before_agent_start", async (event, ctx) => {
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
const provider = event?.provider ?? event?.resolvedProvider ?? 'undefined';
|
|
667
|
-
api.logger.info(`[MemoryX] 📋 [after resolve? before_agent_start] event keys: ${keys} | model: ${model} | provider: ${provider}`);
|
|
668
|
-
log(`[before_agent_start] model=${model} provider=${provider}`);
|
|
674
|
+
// 每次对话前重新把各 provider 的 baseUrl 指到 Sidecar,确保本次请求走代理(quiet 避免每次刷屏)
|
|
675
|
+
applySidecarRedirect({ quiet: true });
|
|
669
676
|
const { prompt } = event;
|
|
670
677
|
if (!prompt || prompt.length < 2 || !plugin)
|
|
671
678
|
return;
|
|
@@ -851,6 +858,7 @@ export default {
|
|
|
851
858
|
});
|
|
852
859
|
this.server.listen(SIDECAR_PORT, () => {
|
|
853
860
|
log(`[Sidecar] Started on port ${SIDECAR_PORT}`);
|
|
861
|
+
api.logger.info(`[MemoryX] Plugin log file: ${LOG_FILE}`);
|
|
854
862
|
resolve();
|
|
855
863
|
});
|
|
856
864
|
});
|
|
@@ -896,7 +904,7 @@ export default {
|
|
|
896
904
|
}
|
|
897
905
|
try {
|
|
898
906
|
log(`\n${'='.repeat(60)}`);
|
|
899
|
-
log(`[${requestId}
|
|
907
|
+
log(`[Sidecar] ${requestId} received POST /v1/chat/completions`, { console: true });
|
|
900
908
|
// 读取请求体
|
|
901
909
|
const body = await this.readBody(req);
|
|
902
910
|
let openaiRequest;
|
|
@@ -927,6 +935,7 @@ export default {
|
|
|
927
935
|
model = creds.models?.[0]?.id || creds.models?.[0]?.name || this.defaultProvider.model;
|
|
928
936
|
}
|
|
929
937
|
log(`[${requestId}] Model: ${openaiRequest.model}, Stream: ${openaiRequest.stream} → proxy provider=${provider}, model=${model}`);
|
|
938
|
+
log(`[Sidecar] ${requestId} → ${provider}/${model} (X-MemoryX-Real-Provider: ${rawProvider || 'from body'})`, { console: true });
|
|
930
939
|
// 获取 SDK 信息(API Key 和 agent_id)
|
|
931
940
|
const sdk = await getSDK(pluginConfig);
|
|
932
941
|
const accountInfo = await sdk.getAccountInfo();
|
|
@@ -962,6 +971,7 @@ export default {
|
|
|
962
971
|
agent_id: agentId
|
|
963
972
|
};
|
|
964
973
|
log(`[${requestId}] Forwarding to ${PROXY_URL} (${provider}/${model})`);
|
|
974
|
+
log(`[Sidecar] ${requestId} forwarding to MemoryX proxy...`, { console: true });
|
|
965
975
|
// 发送到 MemoryX 服务端代理
|
|
966
976
|
const proxyResponse = await fetch(PROXY_URL, {
|
|
967
977
|
method: 'POST',
|
|
@@ -972,6 +982,7 @@ export default {
|
|
|
972
982
|
body: JSON.stringify(proxyRequestBody)
|
|
973
983
|
});
|
|
974
984
|
log(`[${requestId}] Response status: ${proxyResponse.status}`);
|
|
985
|
+
log(`[Sidecar] ${requestId} proxy response ${proxyResponse.status}`, { console: true });
|
|
975
986
|
// 转发响应
|
|
976
987
|
res.writeHead(proxyResponse.status, {
|
|
977
988
|
'Content-Type': proxyResponse.headers.get('content-type') || 'application/json'
|
|
@@ -1000,10 +1011,12 @@ export default {
|
|
|
1000
1011
|
res.end(responseText);
|
|
1001
1012
|
}
|
|
1002
1013
|
log(`[${requestId}] ✅ Completed`);
|
|
1014
|
+
log(`[Sidecar] ${requestId} done`, { console: true });
|
|
1003
1015
|
log(`${'='.repeat(60)}\n`);
|
|
1004
1016
|
}
|
|
1005
1017
|
catch (error) {
|
|
1006
1018
|
log(`[${requestId}] ❌ Error: ${error.message}`);
|
|
1019
|
+
log(`[Sidecar] ${requestId} error: ${error.message}`, { console: true });
|
|
1007
1020
|
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
1008
1021
|
res.end(JSON.stringify({ error: error.message }));
|
|
1009
1022
|
}
|
|
@@ -1038,12 +1051,20 @@ export default {
|
|
|
1038
1051
|
// =========================================================================
|
|
1039
1052
|
// 不改虚拟模型:把用户已配置的 provider 的 baseUrl 改成本地 Sidecar,请求头带上真实 provider
|
|
1040
1053
|
// 用户继续用 zai/glm-5 等,请求会发到 Sidecar,Sidecar 根据 X-MemoryX-Real-Provider 转发
|
|
1054
|
+
// 在 register 和 before_agent_start 都会执行,确保网关在发请求时用的是被改过的 config
|
|
1041
1055
|
// =========================================================================
|
|
1042
1056
|
const sidecarBase = `http://localhost:${SIDECAR_PORT}/v1`;
|
|
1043
1057
|
const realProviderHeader = 'X-MemoryX-Real-Provider';
|
|
1044
|
-
|
|
1058
|
+
const applySidecarRedirect = (opts) => {
|
|
1059
|
+
const creds = extractProviderCredentials(api.config);
|
|
1060
|
+
if (!api.config?.models?.providers || creds.size === 0) {
|
|
1061
|
+
if (!opts?.quiet)
|
|
1062
|
+
log(`[Proxy] No providers to redirect (providers exists: ${!!api.config?.models?.providers}, creds: ${creds.size})`, { console: true });
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1045
1065
|
const providers = api.config.models.providers;
|
|
1046
|
-
|
|
1066
|
+
let n = 0;
|
|
1067
|
+
for (const providerId of creds.keys()) {
|
|
1047
1068
|
if (providerId === 'memoryx-proxy')
|
|
1048
1069
|
continue;
|
|
1049
1070
|
const p = providers[providerId];
|
|
@@ -1053,10 +1074,15 @@ export default {
|
|
|
1053
1074
|
if (!p.headers)
|
|
1054
1075
|
p.headers = {};
|
|
1055
1076
|
p.headers[realProviderHeader] = providerId;
|
|
1077
|
+
n++;
|
|
1056
1078
|
log(`[Proxy] Redirected provider "${providerId}" baseUrl → Sidecar, header ${realProviderHeader}=${providerId}`);
|
|
1057
1079
|
}
|
|
1058
|
-
|
|
1059
|
-
|
|
1080
|
+
if (n > 0 && !opts?.quiet) {
|
|
1081
|
+
api.logger.info(`[MemoryX] ✅ Sidecar redirect applied for ${n} provider(s). Use your configured model (e.g. zai/glm-5).`);
|
|
1082
|
+
log(`[Proxy] Sidecar redirect applied for ${n} provider(s)`, { console: true });
|
|
1083
|
+
}
|
|
1084
|
+
};
|
|
1085
|
+
applySidecarRedirect();
|
|
1060
1086
|
api.logger.info(`[MemoryX] ✅ Plugin v${PLUGIN_VERSION} ready! Requests go through MemoryX proxy with your configured model.`);
|
|
1061
1087
|
// Async check and show portal link after SDK initializes
|
|
1062
1088
|
setImmediate(async () => {
|
package/openclaw.plugin.json
CHANGED
package/package.json
CHANGED