clawmatrix 0.1.20 → 0.1.22
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/package.json +1 -1
- package/src/cli.ts +12 -6
- package/src/cluster-service.ts +2 -1
- package/src/config.ts +1 -0
- package/src/debug.ts +1 -1
- package/src/index.ts +26 -18
- package/src/knowledge-sync.ts +93 -45
- package/src/model-proxy.ts +442 -210
- package/src/router.ts +10 -0
- package/src/tool-proxy.ts +13 -1
- package/src/tools/cluster-peers.ts +1 -1
- package/src/types.ts +3 -0
package/src/router.ts
CHANGED
|
@@ -299,6 +299,16 @@ export class Router {
|
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
// ── Accessors ──────────────────────────────────────────────────
|
|
302
|
+
/** Get the connectivity status of a peer: "direct", "relay", or "unreachable". */
|
|
303
|
+
getPeerStatus(entry: RouteEntry): "direct" | "relay" | "unreachable" {
|
|
304
|
+
if (entry.connection?.isOpen) return "direct";
|
|
305
|
+
if (entry.reachableVia) {
|
|
306
|
+
const relay = this.connections.get(entry.reachableVia);
|
|
307
|
+
if (relay?.isOpen) return "relay";
|
|
308
|
+
}
|
|
309
|
+
return "unreachable";
|
|
310
|
+
}
|
|
311
|
+
|
|
302
312
|
getAllPeers(): RouteEntry[] {
|
|
303
313
|
return [...this.routes.values()];
|
|
304
314
|
}
|
package/src/tool-proxy.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PeerManager } from "./peer-manager.ts";
|
|
2
2
|
import type { ClawMatrixConfig, ToolProxyConfig } from "./config.ts";
|
|
3
3
|
import type { ToolProxyRequest, ToolProxyResponse } from "./types.ts";
|
|
4
|
+
import type { PluginLogger } from "openclaw/plugin-sdk";
|
|
4
5
|
import { isLocalTool, executeLocally } from "./local-tools.ts";
|
|
5
6
|
|
|
6
7
|
const TOOL_TIMEOUT = 30_000;
|
|
@@ -27,12 +28,14 @@ export class ToolProxy {
|
|
|
27
28
|
private peerManager: PeerManager;
|
|
28
29
|
private pending = new Map<string, PendingToolReq>();
|
|
29
30
|
private gatewayInfo: GatewayInfo;
|
|
31
|
+
private logger: PluginLogger;
|
|
30
32
|
private satelliteHandler: SatelliteToolHandler | null = null;
|
|
31
33
|
|
|
32
|
-
constructor(config: ClawMatrixConfig, peerManager: PeerManager, gatewayInfo: GatewayInfo) {
|
|
34
|
+
constructor(config: ClawMatrixConfig, peerManager: PeerManager, gatewayInfo: GatewayInfo, logger: PluginLogger) {
|
|
33
35
|
this.config = config;
|
|
34
36
|
this.peerManager = peerManager;
|
|
35
37
|
this.gatewayInfo = gatewayInfo;
|
|
38
|
+
this.logger = logger;
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
/** Set the satellite tool handler (called by ClusterRuntime after WebHandler is created). */
|
|
@@ -62,12 +65,14 @@ export class ToolProxy {
|
|
|
62
65
|
if (!route) {
|
|
63
66
|
if (this.satelliteHandler?.isSatelliteNode(node)) {
|
|
64
67
|
const id = crypto.randomUUID();
|
|
68
|
+
this.logger.info(`[clawmatrix] Tool invoke: "${tool}" -> satellite node "${node}" (id=${id})`);
|
|
65
69
|
return this.satelliteHandler.queueToolForSatellite(node, id, tool, params, timeout);
|
|
66
70
|
}
|
|
67
71
|
throw new Error(`Node "${node}" not reachable`);
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
const id = crypto.randomUUID();
|
|
75
|
+
this.logger.info(`[clawmatrix] Tool invoke: "${tool}" -> node "${node}" (id=${id})`);
|
|
71
76
|
const frame: ToolProxyRequest = {
|
|
72
77
|
type: "tool_req",
|
|
73
78
|
id,
|
|
@@ -106,8 +111,10 @@ export class ToolProxy {
|
|
|
106
111
|
this.pending.delete(frame.id);
|
|
107
112
|
|
|
108
113
|
if (frame.payload.success && frame.payload.result) {
|
|
114
|
+
this.logger.info(`[clawmatrix] Tool response: id=${frame.id} from="${frame.from}" success`);
|
|
109
115
|
pending.resolve(frame.payload.result);
|
|
110
116
|
} else {
|
|
117
|
+
this.logger.warn(`[clawmatrix] Tool response: id=${frame.id} from="${frame.from}" failed: ${frame.payload.error}`);
|
|
111
118
|
pending.reject(new Error(frame.payload.error ?? "Remote tool execution failed"));
|
|
112
119
|
}
|
|
113
120
|
}
|
|
@@ -126,6 +133,7 @@ export class ToolProxy {
|
|
|
126
133
|
}
|
|
127
134
|
|
|
128
135
|
if (!this.isToolAllowed(payload.tool, toolProxyConfig)) {
|
|
136
|
+
this.logger.warn(`[clawmatrix] Tool request denied: "${payload.tool}" from="${from}" (not allowed)`);
|
|
129
137
|
this.sendResponse(id, from, {
|
|
130
138
|
success: false,
|
|
131
139
|
error: `Tool "${payload.tool}" not allowed on this node`,
|
|
@@ -133,13 +141,17 @@ export class ToolProxy {
|
|
|
133
141
|
return;
|
|
134
142
|
}
|
|
135
143
|
|
|
144
|
+
this.logger.info(`[clawmatrix] Tool request: "${payload.tool}" from="${from}" (id=${id})`);
|
|
145
|
+
|
|
136
146
|
try {
|
|
137
147
|
const result = isLocalTool(payload.tool)
|
|
138
148
|
? await executeLocally(payload.tool, payload.params)
|
|
139
149
|
: await this.executeViaGateway(payload.tool, payload.params);
|
|
140
150
|
|
|
151
|
+
this.logger.info(`[clawmatrix] Tool executed: "${payload.tool}" id=${id} success`);
|
|
141
152
|
this.sendResponse(id, from, { success: true, result });
|
|
142
153
|
} catch (err) {
|
|
154
|
+
this.logger.error(`[clawmatrix] Tool executed: "${payload.tool}" id=${id} failed: ${err}`);
|
|
143
155
|
this.sendResponse(id, from, {
|
|
144
156
|
success: false,
|
|
145
157
|
error: err instanceof Error ? err.message : String(err),
|
|
@@ -24,7 +24,7 @@ export function createClusterPeersTool(): AnyAgentTool {
|
|
|
24
24
|
models: entry.models.map((m) => m.id),
|
|
25
25
|
tags: entry.tags,
|
|
26
26
|
tools: entry.toolProxy?.enabled ? (entry.toolProxy.allow ?? []) : [],
|
|
27
|
-
status: entry
|
|
27
|
+
status: runtime.peerManager.router.getPeerStatus(entry),
|
|
28
28
|
latencyMs: entry.latencyMs,
|
|
29
29
|
}));
|
|
30
30
|
|
package/src/types.ts
CHANGED
|
@@ -98,6 +98,9 @@ export interface ModelRequest extends ClusterFrame {
|
|
|
98
98
|
provider?: string;
|
|
99
99
|
api?: string;
|
|
100
100
|
messages: unknown[];
|
|
101
|
+
/** Format of `messages`: "chat" = OpenAI chat completions, "responses" = OpenAI Responses API input items.
|
|
102
|
+
* Defaults to "chat" for backward compatibility. */
|
|
103
|
+
inputFormat?: "chat" | "responses";
|
|
101
104
|
temperature?: number;
|
|
102
105
|
maxTokens?: number;
|
|
103
106
|
stream: boolean;
|