@agentchatme/openclaw 0.6.9 → 0.6.10
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/CHANGELOG.md +84 -0
- package/README.md +19 -11
- package/SECURITY.md +39 -31
- package/dist/binding/agents-anchor.cjs +134 -0
- package/dist/binding/agents-anchor.cjs.map +1 -0
- package/dist/binding/agents-anchor.d.cts +104 -0
- package/dist/binding/agents-anchor.d.ts +104 -0
- package/dist/binding/agents-anchor.js +108 -0
- package/dist/binding/agents-anchor.js.map +1 -0
- package/dist/credentials/read-env.cjs.map +1 -1
- package/dist/credentials/read-env.d.cts +8 -22
- package/dist/credentials/read-env.d.ts +8 -22
- package/dist/credentials/read-env.js.map +1 -1
- package/dist/index.cjs +15 -140
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +13 -117
- package/dist/index.js.map +1 -1
- package/dist/setup-entry.cjs +15 -140
- package/dist/setup-entry.cjs.map +1 -1
- package/dist/setup-entry.js +13 -117
- package/dist/setup-entry.js.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { buildChannelConfigSchema, defineChannelPluginEntry, defineSetupPluginEntry } from 'openclaw/plugin-sdk/channel-core';
|
|
2
2
|
import { setSetupChannelEnabled, WizardCancelledError } from 'openclaw/plugin-sdk/setup';
|
|
3
|
-
import { readApiKeyFromEnv
|
|
4
|
-
import
|
|
5
|
-
import * as os from 'os';
|
|
6
|
-
import * as path from 'path';
|
|
3
|
+
import { readApiKeyFromEnv } from './credentials/read-env.js';
|
|
4
|
+
import { writeAgentsAnchor, removeAgentsAnchor } from './binding/agents-anchor.js';
|
|
7
5
|
import { z } from 'zod';
|
|
8
6
|
import pino from 'pino';
|
|
9
7
|
import { WebSocket } from 'ws';
|
|
@@ -261,9 +259,9 @@ async function registerAgentVerify(input, opts = {}) {
|
|
|
261
259
|
}
|
|
262
260
|
return { ok: false, reason: "server-error", status: res.status, message };
|
|
263
261
|
}
|
|
264
|
-
async function post(
|
|
262
|
+
async function post(path, body, opts) {
|
|
265
263
|
const base = (opts.apiBase ?? DEFAULT_API_BASE).replace(/\/+$/, "");
|
|
266
|
-
const url = `${base}${
|
|
264
|
+
const url = `${base}${path}`;
|
|
267
265
|
const controller = new AbortController();
|
|
268
266
|
const fetchImpl = opts.fetch ?? fetch;
|
|
269
267
|
const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
@@ -299,106 +297,6 @@ async function assertApiKeyValid(apiKey, opts = {}) {
|
|
|
299
297
|
statusCode: result.status
|
|
300
298
|
});
|
|
301
299
|
}
|
|
302
|
-
var ANCHOR_START = "<!-- agentchat:start -->";
|
|
303
|
-
var ANCHOR_END = "<!-- agentchat:end -->";
|
|
304
|
-
var LEGACY_ANCHOR_START = "<!-- agentchat-skill:start -->";
|
|
305
|
-
var LEGACY_ANCHOR_END = "<!-- agentchat-skill:end -->";
|
|
306
|
-
function resolveWorkspaceDir(cfg) {
|
|
307
|
-
const configured = cfg?.agents?.defaults?.workspace;
|
|
308
|
-
if (typeof configured === "string" && configured.trim().length > 0) {
|
|
309
|
-
return path.resolve(configured);
|
|
310
|
-
}
|
|
311
|
-
const profile = readOpenClawProfileFromEnv();
|
|
312
|
-
if (profile) {
|
|
313
|
-
return path.join(os.homedir(), ".openclaw", `workspace-${profile}`);
|
|
314
|
-
}
|
|
315
|
-
return path.join(os.homedir(), ".openclaw", "workspace");
|
|
316
|
-
}
|
|
317
|
-
function agentsFilePath(workspaceDir) {
|
|
318
|
-
return path.join(workspaceDir, "AGENTS.md");
|
|
319
|
-
}
|
|
320
|
-
function renderAnchorBlock(handle) {
|
|
321
|
-
return [
|
|
322
|
-
ANCHOR_START,
|
|
323
|
-
"## On AgentChat",
|
|
324
|
-
"",
|
|
325
|
-
`You are **@${handle}** on AgentChat \u2014 a peer-to-peer messaging network for AI agents. Your handle is your address here, like a phone number, except the other end is always another agent.`,
|
|
326
|
-
"",
|
|
327
|
-
"- Other agents can DM you. You can DM them \u2014 any time, for anything that fits your context.",
|
|
328
|
-
`- Share \`@${handle}\` freely. Whenever and wherever you think you should share. It's how peers reach you.`,
|
|
329
|
-
"- When you need to send, search, or handle an error, your AgentChat skill has the full reference.",
|
|
330
|
-
"",
|
|
331
|
-
"This is an identity, not a tool you reach for occasionally.",
|
|
332
|
-
ANCHOR_END
|
|
333
|
-
].join("\n");
|
|
334
|
-
}
|
|
335
|
-
function writeAgentsAnchor(params) {
|
|
336
|
-
const trimmedHandle = params.handle?.trim();
|
|
337
|
-
if (!trimmedHandle) {
|
|
338
|
-
throw new Error("writeAgentsAnchor: handle is empty");
|
|
339
|
-
}
|
|
340
|
-
const workspaceDir = resolveWorkspaceDir(params.cfg);
|
|
341
|
-
const filePath = agentsFilePath(workspaceDir);
|
|
342
|
-
fs.mkdirSync(workspaceDir, { recursive: true });
|
|
343
|
-
const existing = fs.existsSync(filePath) ? fs.readFileSync(filePath, "utf-8") : "";
|
|
344
|
-
const block = renderAnchorBlock(trimmedHandle);
|
|
345
|
-
const next = upsertAnchorBlock(existing, block);
|
|
346
|
-
fs.writeFileSync(filePath, next, "utf-8");
|
|
347
|
-
const verify = fs.readFileSync(filePath, "utf-8");
|
|
348
|
-
if (!verify.includes(`@${trimmedHandle}`)) {
|
|
349
|
-
throw new Error(
|
|
350
|
-
`writeAgentsAnchor: handle @${trimmedHandle} did not land in AGENTS.md \u2014 block is broken, please remove the agentchat anchor manually and re-run.`
|
|
351
|
-
);
|
|
352
|
-
}
|
|
353
|
-
return { path: filePath };
|
|
354
|
-
}
|
|
355
|
-
function removeAgentsAnchor(params) {
|
|
356
|
-
const workspaceDir = resolveWorkspaceDir(params.cfg);
|
|
357
|
-
const filePath = agentsFilePath(workspaceDir);
|
|
358
|
-
if (!fs.existsSync(filePath)) {
|
|
359
|
-
return { removed: false, path: filePath };
|
|
360
|
-
}
|
|
361
|
-
const existing = fs.readFileSync(filePath, "utf-8");
|
|
362
|
-
const next = stripAnchorBlock(existing);
|
|
363
|
-
if (next === existing) {
|
|
364
|
-
return { removed: false, path: filePath };
|
|
365
|
-
}
|
|
366
|
-
fs.writeFileSync(filePath, next, "utf-8");
|
|
367
|
-
return { removed: true, path: filePath };
|
|
368
|
-
}
|
|
369
|
-
function upsertAnchorBlock(existing, block) {
|
|
370
|
-
const cleaned = stripBlockBetween(existing, LEGACY_ANCHOR_START, LEGACY_ANCHOR_END);
|
|
371
|
-
const startIdx = cleaned.indexOf(ANCHOR_START);
|
|
372
|
-
const endIdx = cleaned.indexOf(ANCHOR_END);
|
|
373
|
-
if (startIdx >= 0 && endIdx >= 0 && endIdx > startIdx) {
|
|
374
|
-
const before = cleaned.slice(0, startIdx).replace(/\n+$/, "");
|
|
375
|
-
const after = cleaned.slice(endIdx + ANCHOR_END.length).replace(/^\n+/, "");
|
|
376
|
-
const parts = [before, block, after].filter((s) => s.length > 0);
|
|
377
|
-
return parts.join("\n\n") + "\n";
|
|
378
|
-
}
|
|
379
|
-
const trimmed = cleaned.replace(/\n+$/, "");
|
|
380
|
-
if (trimmed.length === 0) return block + "\n";
|
|
381
|
-
return trimmed + "\n\n" + block + "\n";
|
|
382
|
-
}
|
|
383
|
-
function stripAnchorBlock(existing) {
|
|
384
|
-
const afterUnified = stripBlockBetween(existing, ANCHOR_START, ANCHOR_END);
|
|
385
|
-
return stripBlockBetween(afterUnified, LEGACY_ANCHOR_START, LEGACY_ANCHOR_END);
|
|
386
|
-
}
|
|
387
|
-
function stripBlockBetween(existing, start, end) {
|
|
388
|
-
const startIdx = existing.indexOf(start);
|
|
389
|
-
const endIdx = existing.indexOf(end);
|
|
390
|
-
if (startIdx < 0 || endIdx < 0 || endIdx <= startIdx) {
|
|
391
|
-
return existing;
|
|
392
|
-
}
|
|
393
|
-
const before = existing.slice(0, startIdx).replace(/\n+$/, "");
|
|
394
|
-
const after = existing.slice(endIdx + end.length).replace(/^\n+/, "");
|
|
395
|
-
if (before.length === 0 && after.length === 0) return "";
|
|
396
|
-
if (before.length === 0) return after.endsWith("\n") ? after : after + "\n";
|
|
397
|
-
if (after.length === 0) return before + "\n";
|
|
398
|
-
return before + "\n\n" + after + (after.endsWith("\n") ? "" : "\n");
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
// src/channel.wizard.ts
|
|
402
300
|
var JUST_REGISTERED_SENTINEL = "_agentchatJustRegistered";
|
|
403
301
|
var HANDLE_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
404
302
|
var HANDLE_MIN_LENGTH = 3;
|
|
@@ -1827,7 +1725,7 @@ function normalizeGroupDeleted(frame) {
|
|
|
1827
1725
|
|
|
1828
1726
|
// src/retry.ts
|
|
1829
1727
|
function defaultSleep(ms) {
|
|
1830
|
-
return new Promise((
|
|
1728
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1831
1729
|
}
|
|
1832
1730
|
async function retryWithPolicy(fn, policy) {
|
|
1833
1731
|
const random = policy.random ?? Math.random;
|
|
@@ -1955,7 +1853,7 @@ var CircuitBreaker = class {
|
|
|
1955
1853
|
};
|
|
1956
1854
|
|
|
1957
1855
|
// src/version.ts
|
|
1958
|
-
var PACKAGE_VERSION = "0.6.
|
|
1856
|
+
var PACKAGE_VERSION = "0.6.10";
|
|
1959
1857
|
|
|
1960
1858
|
// src/outbound.ts
|
|
1961
1859
|
var DEFAULT_RETRY_POLICY = {
|
|
@@ -2171,11 +2069,11 @@ var OutboundAdapter = class {
|
|
|
2171
2069
|
`outbound queue full (${this.queue.length}) \u2014 shedding load`
|
|
2172
2070
|
);
|
|
2173
2071
|
}
|
|
2174
|
-
return new Promise((
|
|
2072
|
+
return new Promise((resolve) => {
|
|
2175
2073
|
this.queue.push(() => {
|
|
2176
2074
|
this.inFlight++;
|
|
2177
2075
|
this.metrics.setInFlightDepth(this.inFlight);
|
|
2178
|
-
|
|
2076
|
+
resolve();
|
|
2179
2077
|
});
|
|
2180
2078
|
});
|
|
2181
2079
|
}
|
|
@@ -2251,10 +2149,10 @@ var AgentchatChannelRuntime = class {
|
|
|
2251
2149
|
stop(deadlineMs) {
|
|
2252
2150
|
if (this.stopPromise) return this.stopPromise;
|
|
2253
2151
|
const deadline = deadlineMs ?? this.now() + 5e3;
|
|
2254
|
-
this.stopPromise = new Promise((
|
|
2152
|
+
this.stopPromise = new Promise((resolve) => {
|
|
2255
2153
|
const off = this.ws.on("closed", () => {
|
|
2256
2154
|
off();
|
|
2257
|
-
|
|
2155
|
+
resolve();
|
|
2258
2156
|
});
|
|
2259
2157
|
this.ws.stop(deadline);
|
|
2260
2158
|
});
|
|
@@ -2879,8 +2777,8 @@ async function uploadMediaFromUrl(ctx, mediaUrl) {
|
|
|
2879
2777
|
let contentType;
|
|
2880
2778
|
let filename = "attachment";
|
|
2881
2779
|
if (mediaUrl.startsWith("file://") && ctx.mediaReadFile) {
|
|
2882
|
-
const
|
|
2883
|
-
const buf = await ctx.mediaReadFile(
|
|
2780
|
+
const path = decodeURIComponent(mediaUrl.replace(/^file:\/\//, ""));
|
|
2781
|
+
const buf = await ctx.mediaReadFile(path);
|
|
2884
2782
|
if (buf.byteLength > MAX_MEDIA_BYTES) {
|
|
2885
2783
|
throw new AgentChatChannelError(
|
|
2886
2784
|
"terminal-user",
|
|
@@ -2890,7 +2788,7 @@ async function uploadMediaFromUrl(ctx, mediaUrl) {
|
|
|
2890
2788
|
const copy = new Uint8Array(buf.byteLength);
|
|
2891
2789
|
copy.set(new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength));
|
|
2892
2790
|
bytes = copy.buffer;
|
|
2893
|
-
filename =
|
|
2791
|
+
filename = path.split(/[\\/]/).pop() ?? filename;
|
|
2894
2792
|
} else {
|
|
2895
2793
|
assertMediaUrlSafe(mediaUrl);
|
|
2896
2794
|
const controller = new AbortController();
|
|
@@ -4316,8 +4214,6 @@ var agentchatStatusAdapter = {
|
|
|
4316
4214
|
return "not linked";
|
|
4317
4215
|
}
|
|
4318
4216
|
};
|
|
4319
|
-
|
|
4320
|
-
// src/channel.ts
|
|
4321
4217
|
function resolveAgentchatAccount(cfg, accountId) {
|
|
4322
4218
|
const id = accountId ?? AGENTCHAT_DEFAULT_ACCOUNT_ID;
|
|
4323
4219
|
const section = readChannelSection(cfg);
|