@zeyiy/openclaw-channel 0.3.4 → 0.3.5
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/portal.js +48 -21
- package/dist/types.d.ts +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/dist/portal.js
CHANGED
|
@@ -207,26 +207,24 @@ async function handleAgentsFilesList(api, params) {
|
|
|
207
207
|
for (const name of AGENT_FILE_NAMES) {
|
|
208
208
|
const filePath = join(workspaceDir, name);
|
|
209
209
|
const meta = await statFileSafely(filePath);
|
|
210
|
-
if (meta)
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
catch {
|
|
216
|
-
// skip unreadable files
|
|
217
|
-
}
|
|
218
|
-
files.push({
|
|
219
|
-
name,
|
|
220
|
-
path: filePath,
|
|
221
|
-
missing: false,
|
|
222
|
-
size: meta.size,
|
|
223
|
-
updatedAtMs: meta.updatedAtMs,
|
|
224
|
-
content,
|
|
225
|
-
});
|
|
210
|
+
if (!meta)
|
|
211
|
+
continue;
|
|
212
|
+
let content;
|
|
213
|
+
try {
|
|
214
|
+
content = await readFile(filePath, "utf-8");
|
|
226
215
|
}
|
|
227
|
-
|
|
228
|
-
|
|
216
|
+
catch {
|
|
217
|
+
// skip unreadable files
|
|
218
|
+
continue;
|
|
229
219
|
}
|
|
220
|
+
files.push({
|
|
221
|
+
name,
|
|
222
|
+
path: filePath,
|
|
223
|
+
missing: false,
|
|
224
|
+
size: meta.size,
|
|
225
|
+
updatedAtMs: meta.updatedAtMs,
|
|
226
|
+
content,
|
|
227
|
+
});
|
|
230
228
|
}
|
|
231
229
|
portalLog(api, "info", `agents.files.list: agentId=${agentId} workspace=${workspaceDir} found=${files.filter(f => !f.missing).length}`);
|
|
232
230
|
return { agentId, workspace: workspaceDir, files };
|
|
@@ -350,15 +348,44 @@ async function handleAgentsCreate(api, params) {
|
|
|
350
348
|
portalLog(api, "info", `agents.create: agentId=${agentId} name=${rawName} workspace=${workspaceDir}`);
|
|
351
349
|
return { ok: true, agentId, name: rawName, workspace: workspaceDir };
|
|
352
350
|
}
|
|
351
|
+
/**
|
|
352
|
+
* bot.agent.get — resolve the agentId bound to the current bot connection.
|
|
353
|
+
*
|
|
354
|
+
* Lookup order:
|
|
355
|
+
* 1. Config bindings: match channel=openim + accountId
|
|
356
|
+
* 2. Fallback to default agent
|
|
357
|
+
*/
|
|
358
|
+
function handleBotAgentGet(api, accountId) {
|
|
359
|
+
const cfg = getConfig(api);
|
|
360
|
+
const agents = Array.isArray(cfg.agents?.list) ? cfg.agents.list : [];
|
|
361
|
+
// 1. Check bindings
|
|
362
|
+
const bindings = Array.isArray(cfg.bindings) ? cfg.bindings : [];
|
|
363
|
+
for (const b of bindings) {
|
|
364
|
+
if (b?.match?.channel === "openim" &&
|
|
365
|
+
b?.match?.accountId === accountId &&
|
|
366
|
+
b?.agentId) {
|
|
367
|
+
const agentId = normalizeAgentId(b.agentId);
|
|
368
|
+
const entry = agents.find((a) => a?.id && normalizeAgentId(a.id) === agentId);
|
|
369
|
+
return { agentId, ...(entry?.name ? { name: entry.name } : {}) };
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
// 2. Fallback to default agent
|
|
373
|
+
const defaultId = resolveDefaultAgentId(cfg);
|
|
374
|
+
const defaultEntry = agents.find((a) => a?.id && normalizeAgentId(a.id) === defaultId);
|
|
375
|
+
return { agentId: defaultId, ...(defaultEntry?.name ? { name: defaultEntry.name } : {}) };
|
|
376
|
+
}
|
|
353
377
|
// ---------------------------------------------------------------------------
|
|
354
378
|
// Request dispatch
|
|
355
379
|
// ---------------------------------------------------------------------------
|
|
356
|
-
async function handlePortalRequest(api, request) {
|
|
380
|
+
async function handlePortalRequest(api, accountId, request) {
|
|
357
381
|
const { id, method, params } = request;
|
|
358
|
-
portalLog(api, "info", `request received: id=${id} method=${method} params=${JSON.stringify(params)}`);
|
|
382
|
+
portalLog(api, "info", `request received: id=${id} method=${method} params=${JSON.stringify(params)} accountId=${accountId}`);
|
|
359
383
|
try {
|
|
360
384
|
let result;
|
|
361
385
|
switch (method) {
|
|
386
|
+
case "bot.agent.get":
|
|
387
|
+
result = handleBotAgentGet(api, accountId);
|
|
388
|
+
break;
|
|
362
389
|
case "models.list":
|
|
363
390
|
result = handleModelsList(api, params ?? {});
|
|
364
391
|
break;
|
|
@@ -451,7 +478,7 @@ function connectPortal(api, bridge) {
|
|
|
451
478
|
portalLog(api, "warn", `malformed request from portal: missing id or method`);
|
|
452
479
|
return;
|
|
453
480
|
}
|
|
454
|
-
const response = await handlePortalRequest(api, request);
|
|
481
|
+
const response = await handlePortalRequest(api, bridge.accountId, request);
|
|
455
482
|
sendResponse(ws, response);
|
|
456
483
|
portalLog(api, "debug", `response sent: id=${request.id} method=${request.method} ok=${!response.error}`);
|
|
457
484
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export interface InboundBodyResult {
|
|
|
39
39
|
kind: "text" | "image" | "video" | "file" | "mixed" | "unknown";
|
|
40
40
|
media?: InboundMediaItem[];
|
|
41
41
|
}
|
|
42
|
-
export type PortalMethod = "models.list" | "agents.list" | "agents.files.list" | "agents.files.get" | "agents.files.set" | "agents.create" | "ping";
|
|
42
|
+
export type PortalMethod = "bot.agent.get" | "models.list" | "agents.list" | "agents.files.list" | "agents.files.get" | "agents.files.set" | "agents.create" | "ping";
|
|
43
43
|
export interface PortalRequest {
|
|
44
44
|
id: string;
|
|
45
45
|
method: PortalMethod;
|
package/openclaw.plugin.json
CHANGED