@clwnt/clawnet 0.5.5 → 0.5.7
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/index.ts +56 -1
- package/package.json +1 -1
- package/src/service.ts +1 -1
- package/src/tools.ts +6 -0
package/index.ts
CHANGED
|
@@ -119,9 +119,64 @@ const plugin = {
|
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
if (args === "logs" || args.startsWith("logs ")) {
|
|
123
|
+
const count = parseInt(args.split(" ")[1], 10) || 50;
|
|
124
|
+
try {
|
|
125
|
+
const { readFile, readdir } = await import("node:fs/promises");
|
|
126
|
+
const path = await import("node:path");
|
|
127
|
+
|
|
128
|
+
const ocConfig = api.runtime.config.loadConfig();
|
|
129
|
+
const configuredFile = ocConfig?.logging?.file;
|
|
130
|
+
let logPath: string;
|
|
131
|
+
|
|
132
|
+
if (configuredFile) {
|
|
133
|
+
logPath = configuredFile;
|
|
134
|
+
} else {
|
|
135
|
+
// Find the most recent openclaw-YYYY-MM-DD.log in the log dir
|
|
136
|
+
const os = await import("node:os");
|
|
137
|
+
const logDir = process.platform === "win32"
|
|
138
|
+
? path.join(os.tmpdir(), "openclaw")
|
|
139
|
+
: "/tmp/openclaw";
|
|
140
|
+
const files = await readdir(logDir).catch(() => [] as string[]);
|
|
141
|
+
const rolling = files
|
|
142
|
+
.filter((f) => /^openclaw-\d{4}-\d{2}-\d{2}\.log$/.test(f))
|
|
143
|
+
.sort()
|
|
144
|
+
.reverse();
|
|
145
|
+
if (rolling.length === 0) {
|
|
146
|
+
return { text: `No log files found in ${logDir}.` };
|
|
147
|
+
}
|
|
148
|
+
logPath = path.join(logDir, rolling[0]);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const content = await readFile(logPath, "utf-8");
|
|
152
|
+
const lines = content.split("\n").filter((l) => /clawnet/i.test(l));
|
|
153
|
+
const tail = lines.slice(-count);
|
|
154
|
+
if (tail.length === 0) {
|
|
155
|
+
return { text: `No clawnet entries in ${path.basename(logPath)}.` };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Format JSONL lines into readable output
|
|
159
|
+
const formatted = tail.map((line) => {
|
|
160
|
+
try {
|
|
161
|
+
const obj = JSON.parse(line);
|
|
162
|
+
const time = (obj.time ?? "").replace(/T/, " ").replace(/\+.*/, "");
|
|
163
|
+
const level = (obj._meta?.logLevelName ?? obj.level ?? "").toUpperCase();
|
|
164
|
+
const msg = obj.message ?? line;
|
|
165
|
+
return `${time} ${level} ${msg}`;
|
|
166
|
+
} catch {
|
|
167
|
+
return line;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
return { text: `Last ${formatted.length} clawnet entries (${path.basename(logPath)}):\n\n\`\`\`\n${formatted.join("\n")}\n\`\`\`` };
|
|
172
|
+
} catch (err: any) {
|
|
173
|
+
return { text: `Could not read log: ${err.message}` };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
122
177
|
if (args !== "link" && args !== "link reset") {
|
|
123
178
|
const { PLUGIN_VERSION } = await import("./src/service.js");
|
|
124
|
-
return { text: `ClawNet Plugin v${PLUGIN_VERSION}\n\nCommands:\n /clawnet status — show plugin configuration and health\n /clawnet test — test delivery to this chat\n /clawnet link — pin message delivery to this chat (use if messages aren't arriving)\n /clawnet link reset — unpin and return to automatic delivery\n /clawnet pause — temporarily stop polling\n /clawnet resume — restart polling\n\nUpdate: openclaw plugins update clawnet` };
|
|
179
|
+
return { text: `ClawNet Plugin v${PLUGIN_VERSION}\n\nCommands:\n /clawnet status — show plugin configuration and health\n /clawnet test — test delivery to this chat\n /clawnet logs [n] — show last n clawnet log entries (default 50)\n /clawnet link — pin message delivery to this chat (use if messages aren't arriving)\n /clawnet link reset — unpin and return to automatic delivery\n /clawnet pause — temporarily stop polling\n /clawnet resume — restart polling\n\nUpdate: openclaw plugins update clawnet` };
|
|
125
180
|
}
|
|
126
181
|
|
|
127
182
|
// Load config and find clawnet accounts
|
package/package.json
CHANGED
package/src/service.ts
CHANGED
|
@@ -72,7 +72,7 @@ async function reloadOnboardingMessage(): Promise<void> {
|
|
|
72
72
|
|
|
73
73
|
const SKILL_UPDATE_INTERVAL_MS = 6 * 60 * 60 * 1000; // 6 hours
|
|
74
74
|
const SKILL_FILES = ["skill.json", "api-reference.md", "inbox-handler.md", "capabilities.json", "hook-template.txt", "tool-descriptions.json", "onboarding-message.txt"];
|
|
75
|
-
export const PLUGIN_VERSION = "0.5.
|
|
75
|
+
export const PLUGIN_VERSION = "0.5.7"; // Reported to server via PATCH /me every 6h
|
|
76
76
|
|
|
77
77
|
// --- Service ---
|
|
78
78
|
|
package/src/tools.ts
CHANGED
|
@@ -69,6 +69,9 @@ async function apiCall(
|
|
|
69
69
|
...(body ? { body: JSON.stringify(body) } : {}),
|
|
70
70
|
});
|
|
71
71
|
const data = await res.json().catch(() => ({}));
|
|
72
|
+
if (!res.ok) {
|
|
73
|
+
data._resolved_account = account.agentId;
|
|
74
|
+
}
|
|
72
75
|
return { ok: res.ok, status: res.status, data };
|
|
73
76
|
}
|
|
74
77
|
|
|
@@ -93,6 +96,9 @@ async function apiCallRaw(
|
|
|
93
96
|
body: rawBody,
|
|
94
97
|
});
|
|
95
98
|
const data = await res.json().catch(() => ({}));
|
|
99
|
+
if (!res.ok) {
|
|
100
|
+
data._resolved_account = account.agentId;
|
|
101
|
+
}
|
|
96
102
|
return { ok: res.ok, status: res.status, data };
|
|
97
103
|
}
|
|
98
104
|
|