palz-connector 1.6.8 → 1.7.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/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/src/channel.js +13 -10
- package/src/control-server.js +33 -10
package/openclaw.plugin.json
CHANGED
package/package.json
CHANGED
package/src/channel.js
CHANGED
|
@@ -72,11 +72,10 @@ export const palzPlugin = {
|
|
|
72
72
|
gateway: {
|
|
73
73
|
startAccount: async (ctx) => {
|
|
74
74
|
const log = typeof ctx.runtime?.log === "function" ? ctx.runtime.log : console.log;
|
|
75
|
-
const logInfo = typeof ctx.log?.info === "function" ? ctx.log.info.bind(ctx.log) : log;
|
|
76
75
|
const error = typeof ctx.runtime?.error === "function" ? ctx.runtime.error : console.error;
|
|
77
|
-
|
|
76
|
+
log("palz-gateway: [startAccount] 输入: accountId=" + JSON.stringify(ctx.accountId));
|
|
78
77
|
if (ctx.accountId !== PALZ_MANAGER_ACCOUNT_ID) {
|
|
79
|
-
|
|
78
|
+
log("palz-gateway: [startAccount] non-manager account " + JSON.stringify(ctx.accountId) + ", returning abort-pending promise");
|
|
80
79
|
return new Promise((resolve) => {
|
|
81
80
|
if (ctx.abortSignal?.aborted) {
|
|
82
81
|
resolve();
|
|
@@ -88,15 +87,17 @@ export const palzPlugin = {
|
|
|
88
87
|
const baseConfig = resolvePalzConfig(ctx.cfg);
|
|
89
88
|
if (!baseConfig.streamUrl || !baseConfig.apiBaseUrl) {
|
|
90
89
|
const errMsg = "Palz manager not configured (missing streamUrl/apiBaseUrl)";
|
|
91
|
-
|
|
90
|
+
log("palz-gateway: [startAccount] 失败: " + errMsg);
|
|
92
91
|
throw new Error(errMsg);
|
|
93
92
|
}
|
|
94
|
-
|
|
93
|
+
log("palz-gateway: [startAccount] 启动 manager, streamUrl=" + baseConfig.streamUrl);
|
|
95
94
|
const manager = new ConnectionManager({
|
|
96
95
|
cfg: ctx.cfg,
|
|
97
96
|
baseConfig,
|
|
98
97
|
runtime: ctx.runtime,
|
|
99
|
-
log
|
|
98
|
+
// 用 runtime.log(写文件),而非仅 stdout 的 ctx.log.info,
|
|
99
|
+
// 使连接生命周期日志(reconcile/add/remove/shutdown)落入 palz-*.log。
|
|
100
|
+
log,
|
|
100
101
|
error,
|
|
101
102
|
});
|
|
102
103
|
const scanner = startUserDirScanner({
|
|
@@ -105,7 +106,7 @@ export const palzPlugin = {
|
|
|
105
106
|
error("palz-gateway: reconcile error: " + String(err));
|
|
106
107
|
});
|
|
107
108
|
},
|
|
108
|
-
log
|
|
109
|
+
log,
|
|
109
110
|
error,
|
|
110
111
|
});
|
|
111
112
|
// Stop service: disconnect all WS connections and prevent scanner-triggered reconnects.
|
|
@@ -115,7 +116,7 @@ export const palzPlugin = {
|
|
|
115
116
|
if (stopped)
|
|
116
117
|
return;
|
|
117
118
|
stopped = true;
|
|
118
|
-
|
|
119
|
+
log("palz-gateway: [doStop] stopping service, shutting down scanner + manager");
|
|
119
120
|
scanner.stop();
|
|
120
121
|
manager.shutdown();
|
|
121
122
|
};
|
|
@@ -133,13 +134,15 @@ export const palzPlugin = {
|
|
|
133
134
|
},
|
|
134
135
|
cfg: ctx.cfg,
|
|
135
136
|
runtime: ctx.runtime,
|
|
136
|
-
log
|
|
137
|
+
// 用 runtime.log(写入 palz-*.log 文件),而非 ctx.log.info(仅 stdout),
|
|
138
|
+
// 使 control-server 的回调日志与消息链路日志落到同一文件,便于排查。
|
|
139
|
+
log,
|
|
137
140
|
error,
|
|
138
141
|
});
|
|
139
142
|
}
|
|
140
143
|
return new Promise((resolve) => {
|
|
141
144
|
const onAbort = () => {
|
|
142
|
-
|
|
145
|
+
log("palz-gateway: [startAccount] abort received, shutting down manager");
|
|
143
146
|
controlServer?.close();
|
|
144
147
|
doStop();
|
|
145
148
|
resolve();
|
package/src/control-server.js
CHANGED
|
@@ -74,6 +74,9 @@ export function startControlServer(opts) {
|
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
76
|
if (path === "/admin/kb-ingest/callback") {
|
|
77
|
+
const contentType = String(req.headers["content-type"] || "");
|
|
78
|
+
const contentLength = String(req.headers["content-length"] || "?");
|
|
79
|
+
log(`palz-kb-callback: [recv] method=${method} contentType=${contentType} contentLength=${contentLength} remote=${req.socket.remoteAddress ?? "?"}`);
|
|
77
80
|
if (method !== "POST") {
|
|
78
81
|
sendJson(res, { code: 405, err_message: "method not allowed", data: {} });
|
|
79
82
|
return;
|
|
@@ -83,19 +86,39 @@ export function startControlServer(opts) {
|
|
|
83
86
|
return;
|
|
84
87
|
}
|
|
85
88
|
const rawBody = await readRequestBody(req);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
error
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
log(`palz-kb-callback: [recv body] len=${rawBody.length} preview=${JSON.stringify(rawBody.slice(0, 500))}`);
|
|
90
|
+
let body;
|
|
91
|
+
try {
|
|
92
|
+
body = parseCallbackBody(req, rawBody);
|
|
93
|
+
}
|
|
94
|
+
catch (parseErr) {
|
|
95
|
+
error(`palz-kb-callback: [recv] body parse failed: ${parseErr?.message ?? parseErr}`);
|
|
96
|
+
sendJson(res, { code: 400, err_message: `invalid callback body: ${String(parseErr?.message ?? parseErr)}`, data: {} });
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
let result;
|
|
100
|
+
try {
|
|
101
|
+
result = await handleKbTaskCallback({
|
|
102
|
+
cfg: opts.cfg,
|
|
103
|
+
runtime: opts.runtime,
|
|
104
|
+
body,
|
|
105
|
+
log,
|
|
106
|
+
error,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
catch (dispatchErr) {
|
|
110
|
+
const resp = { code: 500, err_message: String(dispatchErr?.message ?? dispatchErr), data: {} };
|
|
111
|
+
error(`palz-kb-callback: [resp] handle failed, response=${JSON.stringify(resp)}`);
|
|
112
|
+
sendJson(res, resp);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const resp = {
|
|
95
116
|
code: result.handled ? 0 : 404,
|
|
96
117
|
err_message: result.handled ? "" : (result.reason ?? "not handled"),
|
|
97
118
|
data: result,
|
|
98
|
-
}
|
|
119
|
+
};
|
|
120
|
+
log(`palz-kb-callback: [resp] handled=${result.handled} response=${JSON.stringify(resp)}`);
|
|
121
|
+
sendJson(res, resp);
|
|
99
122
|
return;
|
|
100
123
|
}
|
|
101
124
|
sendJson(res, { code: 404, err_message: "not found", data: {} });
|