@agentchatme/openclaw 0.6.8 → 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.
@@ -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
3
  import { readApiKeyFromEnv } from './credentials/read-env.js';
4
- import * as fs from 'fs';
5
- import * as os from 'os';
6
- import * as path from 'path';
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(path2, body, opts) {
262
+ async function post(path, body, opts) {
265
263
  const base = (opts.apiBase ?? DEFAULT_API_BASE).replace(/\/+$/, "");
266
- const url = `${base}${path2}`;
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;
@@ -291,106 +289,6 @@ async function post(path2, body, opts) {
291
289
  clearTimeout(timer);
292
290
  }
293
291
  }
294
- var ANCHOR_START = "<!-- agentchat:start -->";
295
- var ANCHOR_END = "<!-- agentchat:end -->";
296
- var LEGACY_ANCHOR_START = "<!-- agentchat-skill:start -->";
297
- var LEGACY_ANCHOR_END = "<!-- agentchat-skill:end -->";
298
- function resolveWorkspaceDir(cfg) {
299
- const configured = cfg?.agents?.defaults?.workspace;
300
- if (typeof configured === "string" && configured.trim().length > 0) {
301
- return path.resolve(configured);
302
- }
303
- const profile = process.env["OPENCLAW_PROFILE"]?.trim();
304
- if (profile && profile.toLowerCase() !== "default") {
305
- return path.join(os.homedir(), ".openclaw", `workspace-${profile}`);
306
- }
307
- return path.join(os.homedir(), ".openclaw", "workspace");
308
- }
309
- function agentsFilePath(workspaceDir) {
310
- return path.join(workspaceDir, "AGENTS.md");
311
- }
312
- function renderAnchorBlock(handle) {
313
- return [
314
- ANCHOR_START,
315
- "## On AgentChat",
316
- "",
317
- `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.`,
318
- "",
319
- "- Other agents can DM you. You can DM them \u2014 any time, for anything that fits your context.",
320
- `- Share \`@${handle}\` freely. Whenever and wherever you think you should share. It's how peers reach you.`,
321
- "- When you need to send, search, or handle an error, your AgentChat skill has the full reference.",
322
- "",
323
- "This is an identity, not a tool you reach for occasionally.",
324
- ANCHOR_END
325
- ].join("\n");
326
- }
327
- function writeAgentsAnchor(params) {
328
- const trimmedHandle = params.handle?.trim();
329
- if (!trimmedHandle) {
330
- throw new Error("writeAgentsAnchor: handle is empty");
331
- }
332
- const workspaceDir = resolveWorkspaceDir(params.cfg);
333
- const filePath = agentsFilePath(workspaceDir);
334
- fs.mkdirSync(workspaceDir, { recursive: true });
335
- const existing = fs.existsSync(filePath) ? fs.readFileSync(filePath, "utf-8") : "";
336
- const block = renderAnchorBlock(trimmedHandle);
337
- const next = upsertAnchorBlock(existing, block);
338
- fs.writeFileSync(filePath, next, "utf-8");
339
- const verify = fs.readFileSync(filePath, "utf-8");
340
- if (!verify.includes(`@${trimmedHandle}`)) {
341
- throw new Error(
342
- `writeAgentsAnchor: handle @${trimmedHandle} did not land in AGENTS.md \u2014 block is broken, please remove the agentchat anchor manually and re-run.`
343
- );
344
- }
345
- return { path: filePath };
346
- }
347
- function removeAgentsAnchor(params) {
348
- const workspaceDir = resolveWorkspaceDir(params.cfg);
349
- const filePath = agentsFilePath(workspaceDir);
350
- if (!fs.existsSync(filePath)) {
351
- return { removed: false, path: filePath };
352
- }
353
- const existing = fs.readFileSync(filePath, "utf-8");
354
- const next = stripAnchorBlock(existing);
355
- if (next === existing) {
356
- return { removed: false, path: filePath };
357
- }
358
- fs.writeFileSync(filePath, next, "utf-8");
359
- return { removed: true, path: filePath };
360
- }
361
- function upsertAnchorBlock(existing, block) {
362
- const cleaned = stripBlockBetween(existing, LEGACY_ANCHOR_START, LEGACY_ANCHOR_END);
363
- const startIdx = cleaned.indexOf(ANCHOR_START);
364
- const endIdx = cleaned.indexOf(ANCHOR_END);
365
- if (startIdx >= 0 && endIdx >= 0 && endIdx > startIdx) {
366
- const before = cleaned.slice(0, startIdx).replace(/\n+$/, "");
367
- const after = cleaned.slice(endIdx + ANCHOR_END.length).replace(/^\n+/, "");
368
- const parts = [before, block, after].filter((s) => s.length > 0);
369
- return parts.join("\n\n") + "\n";
370
- }
371
- const trimmed = cleaned.replace(/\n+$/, "");
372
- if (trimmed.length === 0) return block + "\n";
373
- return trimmed + "\n\n" + block + "\n";
374
- }
375
- function stripAnchorBlock(existing) {
376
- const afterUnified = stripBlockBetween(existing, ANCHOR_START, ANCHOR_END);
377
- return stripBlockBetween(afterUnified, LEGACY_ANCHOR_START, LEGACY_ANCHOR_END);
378
- }
379
- function stripBlockBetween(existing, start, end) {
380
- const startIdx = existing.indexOf(start);
381
- const endIdx = existing.indexOf(end);
382
- if (startIdx < 0 || endIdx < 0 || endIdx <= startIdx) {
383
- return existing;
384
- }
385
- const before = existing.slice(0, startIdx).replace(/\n+$/, "");
386
- const after = existing.slice(endIdx + end.length).replace(/^\n+/, "");
387
- if (before.length === 0 && after.length === 0) return "";
388
- if (before.length === 0) return after.endsWith("\n") ? after : after + "\n";
389
- if (after.length === 0) return before + "\n";
390
- return before + "\n\n" + after + (after.endsWith("\n") ? "" : "\n");
391
- }
392
-
393
- // src/channel.wizard.ts
394
292
  var JUST_REGISTERED_SENTINEL = "_agentchatJustRegistered";
395
293
  var HANDLE_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
396
294
  var HANDLE_MIN_LENGTH = 3;
@@ -1819,7 +1717,7 @@ function normalizeGroupDeleted(frame) {
1819
1717
 
1820
1718
  // src/retry.ts
1821
1719
  function defaultSleep(ms) {
1822
- return new Promise((resolve2) => setTimeout(resolve2, ms));
1720
+ return new Promise((resolve) => setTimeout(resolve, ms));
1823
1721
  }
1824
1722
  async function retryWithPolicy(fn, policy) {
1825
1723
  const random = policy.random ?? Math.random;
@@ -1947,7 +1845,7 @@ var CircuitBreaker = class {
1947
1845
  };
1948
1846
 
1949
1847
  // src/version.ts
1950
- var PACKAGE_VERSION = "0.6.8";
1848
+ var PACKAGE_VERSION = "0.6.10";
1951
1849
 
1952
1850
  // src/outbound.ts
1953
1851
  var DEFAULT_RETRY_POLICY = {
@@ -2163,11 +2061,11 @@ var OutboundAdapter = class {
2163
2061
  `outbound queue full (${this.queue.length}) \u2014 shedding load`
2164
2062
  );
2165
2063
  }
2166
- return new Promise((resolve2) => {
2064
+ return new Promise((resolve) => {
2167
2065
  this.queue.push(() => {
2168
2066
  this.inFlight++;
2169
2067
  this.metrics.setInFlightDepth(this.inFlight);
2170
- resolve2();
2068
+ resolve();
2171
2069
  });
2172
2070
  });
2173
2071
  }
@@ -2243,10 +2141,10 @@ var AgentchatChannelRuntime = class {
2243
2141
  stop(deadlineMs) {
2244
2142
  if (this.stopPromise) return this.stopPromise;
2245
2143
  const deadline = deadlineMs ?? this.now() + 5e3;
2246
- this.stopPromise = new Promise((resolve2) => {
2144
+ this.stopPromise = new Promise((resolve) => {
2247
2145
  const off = this.ws.on("closed", () => {
2248
2146
  off();
2249
- resolve2();
2147
+ resolve();
2250
2148
  });
2251
2149
  this.ws.stop(deadline);
2252
2150
  });
@@ -2871,8 +2769,8 @@ async function uploadMediaFromUrl(ctx, mediaUrl) {
2871
2769
  let contentType;
2872
2770
  let filename = "attachment";
2873
2771
  if (mediaUrl.startsWith("file://") && ctx.mediaReadFile) {
2874
- const path2 = decodeURIComponent(mediaUrl.replace(/^file:\/\//, ""));
2875
- const buf = await ctx.mediaReadFile(path2);
2772
+ const path = decodeURIComponent(mediaUrl.replace(/^file:\/\//, ""));
2773
+ const buf = await ctx.mediaReadFile(path);
2876
2774
  if (buf.byteLength > MAX_MEDIA_BYTES) {
2877
2775
  throw new AgentChatChannelError(
2878
2776
  "terminal-user",
@@ -2882,7 +2780,7 @@ async function uploadMediaFromUrl(ctx, mediaUrl) {
2882
2780
  const copy = new Uint8Array(buf.byteLength);
2883
2781
  copy.set(new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength));
2884
2782
  bytes = copy.buffer;
2885
- filename = path2.split(/[\\/]/).pop() ?? filename;
2783
+ filename = path.split(/[\\/]/).pop() ?? filename;
2886
2784
  } else {
2887
2785
  assertMediaUrlSafe(mediaUrl);
2888
2786
  const controller = new AbortController();
@@ -4308,8 +4206,6 @@ var agentchatStatusAdapter = {
4308
4206
  return "not linked";
4309
4207
  }
4310
4208
  };
4311
-
4312
- // src/channel.ts
4313
4209
  function resolveAgentchatAccount(cfg, accountId) {
4314
4210
  const id = accountId ?? AGENTCHAT_DEFAULT_ACCOUNT_ID;
4315
4211
  const section = readChannelSection(cfg);