@openclaw/clickclack 2026.10.10 → 2026.11.5-beta.1
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/.setup/{channel-CaLQ1zSw.mjs → channel-ByAANbh8.mjs} +363 -504
- package/dist/.setup/{resolve-C2XmZanM.mjs → resolve-CRj6QjdF.mjs} +27 -41
- package/dist/.setup/{rolldown-runtime-nwUcYXjP.mjs → rolldown-runtime-782esTHO.mjs} +0 -1
- package/dist/.setup/{runtime-api-HO9-jJAP.mjs → runtime-api-BsRK-sfA.mjs} +324 -368
- package/dist/.setup/{setup-claim-D50o9egr.mjs → setup-claim-BAKxfObl.mjs} +4 -9
- package/dist/.setup/{setup-plugin-api-COv8knUv.mjs → setup-plugin-api-BTqE973B.mjs} +1 -1
- package/dist/.setup/setup-plugin-api-CfuhJJvK.mjs +1 -0
- package/dist/.setup/{setup-surface-BuNtdRQY.mjs → setup-surface-5wSYr6p2.mjs} +5 -5
- package/dist/.setup/{setup-verify-CSI-GwUA.mjs → setup-verify-IayKkFWq.mjs} +12 -24
- package/dist/.source-module-urls/aa673c321fe9be084b8926cbe5388ff5e2a41371389e19ca60a1983f2b634030.json +1 -1
- package/dist/api.js +3 -3
- package/dist/channel-plugin-api.js +1 -1
- package/dist/doctor-contract-api.js +1 -1
- package/dist/index.js +1 -1
- package/dist/runtime-api.js +4 -4
- package/dist/setup-entry.js +1 -1
- package/dist/setup-plugin-api.js +1 -1
- package/node_modules/zod/package.json +1 -1
- package/node_modules/zod/src/v4/classic/tests/array.test.ts +27 -0
- package/node_modules/zod/src/v4/classic/tests/map.test.ts +7 -0
- package/node_modules/zod/src/v4/classic/tests/set.test.ts +6 -0
- package/node_modules/zod/src/v4/core/compile.ts +9 -0
- package/node_modules/zod/src/v4/core/schemas.ts +35 -1
- package/node_modules/zod/src/v4/core/util.ts +13 -0
- package/node_modules/zod/src/v4/core/versions.ts +1 -1
- package/node_modules/zod/v4/core/compile.cjs +8 -0
- package/node_modules/zod/v4/core/compile.js +8 -0
- package/node_modules/zod/v4/core/schemas.cjs +30 -0
- package/node_modules/zod/v4/core/schemas.d.cts +3 -1
- package/node_modules/zod/v4/core/schemas.d.ts +3 -1
- package/node_modules/zod/v4/core/schemas.js +30 -0
- package/node_modules/zod/v4/core/util.cjs +15 -0
- package/node_modules/zod/v4/core/util.d.cts +2 -0
- package/node_modules/zod/v4/core/util.d.ts +2 -0
- package/node_modules/zod/v4/core/util.js +14 -0
- package/node_modules/zod/v4/core/versions.cjs +1 -1
- package/node_modules/zod/v4/core/versions.js +1 -1
- package/package.json +5 -7
- package/dist/.setup/setup-plugin-api-wzfSSaGz.mjs +0 -1
- package/node_modules/ws/LICENSE +0 -20
- package/node_modules/ws/README.md +0 -548
- package/node_modules/ws/browser.js +0 -8
- package/node_modules/ws/index.js +0 -22
- package/node_modules/ws/lib/buffer-util.js +0 -131
- package/node_modules/ws/lib/constants.js +0 -19
- package/node_modules/ws/lib/event-target.js +0 -292
- package/node_modules/ws/lib/extension.js +0 -203
- package/node_modules/ws/lib/limiter.js +0 -55
- package/node_modules/ws/lib/permessage-deflate.js +0 -530
- package/node_modules/ws/lib/receiver.js +0 -743
- package/node_modules/ws/lib/sender.js +0 -607
- package/node_modules/ws/lib/stream.js +0 -161
- package/node_modules/ws/lib/subprotocol.js +0 -62
- package/node_modules/ws/lib/validation.js +0 -152
- package/node_modules/ws/lib/websocket-server.js +0 -562
- package/node_modules/ws/lib/websocket.js +0 -1421
- package/node_modules/ws/package.json +0 -74
- package/node_modules/ws/wrapper.mjs +0 -21
|
@@ -1,28 +1,32 @@
|
|
|
1
|
-
import { n as __reExport, t as __exportAll } from "./rolldown-runtime-
|
|
2
|
-
import { c as CLICKCLACK_CHANNEL_ID, d as DEFAULT_ACCOUNT_ID, f as isClickClackAccountCurrent, g as resolveClickClackAccountConfig, h as resolveClickClackAccount, l as clickClackConfigAdapter, m as listEnabledClickClackAccounts, n as clickClackSetupContract, s as clickClackConfigSchema, t as clickClackSetupWizard, u as clickClackMeta } from "./setup-surface-
|
|
3
|
-
import { a as createClickClackClient, i as ClickClackHttpError, n as resolveChannelId, r as resolveWorkspaceId, s as normalizeClickClackCorrelationId } from "./resolve-
|
|
1
|
+
import { n as __reExport, t as __exportAll } from "./rolldown-runtime-782esTHO.mjs";
|
|
2
|
+
import { c as CLICKCLACK_CHANNEL_ID, d as DEFAULT_ACCOUNT_ID, f as isClickClackAccountCurrent, g as resolveClickClackAccountConfig, h as resolveClickClackAccount, l as clickClackConfigAdapter, m as listEnabledClickClackAccounts, n as clickClackSetupContract, s as clickClackConfigSchema, t as clickClackSetupWizard, u as clickClackMeta } from "./setup-surface-5wSYr6p2.mjs";
|
|
3
|
+
import { a as createClickClackClient, i as ClickClackHttpError, n as resolveChannelId, r as resolveWorkspaceId, s as normalizeClickClackCorrelationId } from "./resolve-CRj6QjdF.mjs";
|
|
4
4
|
import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries } from "./secret-contract-Dj8nibUr.mjs";
|
|
5
5
|
import { resolveChannelMediaMaxBytes } from "openclaw/plugin-sdk/account-helpers";
|
|
6
6
|
import { parseDateStringTimestampMs } from "openclaw/plugin-sdk/number-runtime";
|
|
7
7
|
import { mergePairLoopGuardConfig } from "openclaw/plugin-sdk/pair-loop-guard-runtime";
|
|
8
8
|
import { normalizeTrimmedStringList, readStringField } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
9
9
|
import { buildChannelOutboundSessionRoute, buildThreadAwareOutboundSessionRoute, createChatChannelPlugin } from "openclaw/plugin-sdk/channel-core";
|
|
10
|
-
import { buildChannelProgressDraftLine, createChannelMessageReplyPipeline, createMessageReceiptFromOutboundResults, defineChannelMessageAdapter, deriveDurableFinalDeliveryRequirements, formatChannelProgressDraftLineForEntry, isCompleteAgentPreamble } from "openclaw/plugin-sdk/channel-outbound";
|
|
10
|
+
import { buildChannelProgressDraftLine, createChannelMessageAdapterFromOutbound, createChannelMessageReplyPipeline, createMessageReceiptFromOutboundResults, defineChannelMessageAdapter, deriveDurableFinalDeliveryRequirements, formatChannelProgressDraftLineForEntry, isCompleteAgentPreamble } from "openclaw/plugin-sdk/channel-outbound";
|
|
11
11
|
import { createComputedAccountStatusAdapter, createDefaultChannelRuntimeState } from "openclaw/plugin-sdk/status-helpers";
|
|
12
12
|
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
|
|
13
13
|
import { channelReadyPatch, channelStoppedPatch } from "openclaw/plugin-sdk/gateway-runtime";
|
|
14
|
+
import { listNativeCommandSpecsForConfig } from "openclaw/plugin-sdk/native-command-registry";
|
|
14
15
|
import { sleepWithAbort } from "openclaw/plugin-sdk/runtime-env";
|
|
16
|
+
import { safeParseJson, truncateCodePoints } from "openclaw/plugin-sdk/text-utility-runtime";
|
|
15
17
|
import { rawDataToString } from "openclaw/plugin-sdk/webhook-ingress";
|
|
18
|
+
import { startWebSocketKeepalive } from "openclaw/plugin-sdk/websocket-runtime";
|
|
16
19
|
import { isDeepStrictEqual } from "node:util";
|
|
17
20
|
import { parseAccessGroupAllowFromEntry } from "openclaw/plugin-sdk/access-groups";
|
|
18
21
|
import { formatNormalizedAllowFromEntries, resolveAllowlistMatchByCandidates } from "openclaw/plugin-sdk/allow-from";
|
|
19
22
|
import { normalizeAgentId } from "openclaw/plugin-sdk/routing";
|
|
20
|
-
import {
|
|
23
|
+
import { randomUUID } from "node:crypto";
|
|
21
24
|
import { createAsyncLock } from "openclaw/plugin-sdk/async-lock-runtime";
|
|
22
25
|
import { assertPluginStateReadAvailable, preparePluginStateRead } from "openclaw/plugin-sdk/plugin-state-runtime";
|
|
23
|
-
import {
|
|
26
|
+
import { sha256Hex } from "openclaw/plugin-sdk/node-crypto-runtime";
|
|
27
|
+
import { resolveSessionAgentIdStrict } from "openclaw/plugin-sdk/agent-scope-runtime";
|
|
28
|
+
import { captureSessionEntryCurrentCheckAsync } from "openclaw/plugin-sdk/session-binding-runtime";
|
|
24
29
|
import { createPluginRuntimeStore } from "openclaw/plugin-sdk/runtime-store";
|
|
25
|
-
import { listNativeCommandSpecsForConfig } from "openclaw/plugin-sdk/native-command-registry";
|
|
26
30
|
import { buildChannelInboundEventContext, createChannelInboundEnvelopeBuilderAsync, createChannelPartialDeliveryError, recordChannelBotPairLoopAndCheckSuppression } from "openclaw/plugin-sdk/channel-inbound";
|
|
27
31
|
import { extensionForMime } from "openclaw/plugin-sdk/media-mime";
|
|
28
32
|
import { loadOutboundMediaFromUrl } from "openclaw/plugin-sdk/outbound-media";
|
|
@@ -98,7 +102,7 @@ function reserveDiscussionBindingGeneration(params) {
|
|
|
98
102
|
},
|
|
99
103
|
result: existing.generation
|
|
100
104
|
};
|
|
101
|
-
generation ??=
|
|
105
|
+
generation ??= randomUUID();
|
|
102
106
|
return {
|
|
103
107
|
value: {
|
|
104
108
|
accountId: params.accountId,
|
|
@@ -171,6 +175,7 @@ async function hasPendingDiscussionOpenForDestination(params) {
|
|
|
171
175
|
return (await listPendingDiscussionOpens(params.runtime)).some((pending) => pending.serverBaseUrl === serverBaseUrl && pending.workspaceId === params.workspaceId);
|
|
172
176
|
}
|
|
173
177
|
// extensions/clickclack/src/discussions/binding-store.ts
|
|
178
|
+
/** Retained for the shipped synchronous ScopedSessionAccessProvider contract. */
|
|
174
179
|
function bindingMatchesActiveSessionIncarnation(runtime, sessionKey, binding) {
|
|
175
180
|
const entry = runtime.agent.session.getSessionEntry({
|
|
176
181
|
sessionKey,
|
|
@@ -199,10 +204,7 @@ async function attachBindingToCurrentActiveSession(params) {
|
|
|
199
204
|
...retained,
|
|
200
205
|
sessionId: entry.sessionId
|
|
201
206
|
};
|
|
202
|
-
return await params.store.setIfCurrent(params.sessionKey, params.binding, attached
|
|
203
|
-
const current = params.store.get(params.sessionKey);
|
|
204
|
-
if (!current || current.externalRef !== params.binding.externalRef || current.serverBaseUrl !== params.binding.serverBaseUrl || current.channelId !== params.binding.channelId || !bindingMatchesActiveSessionIncarnation(params.runtime, params.sessionKey, attached)) throw new Error("ClickClack discussion session changed before attachment committed");
|
|
205
|
-
} }) ? attached : void 0;
|
|
207
|
+
return await params.store.setIfCurrent(params.sessionKey, params.binding, attached) ? attached : void 0;
|
|
206
208
|
}
|
|
207
209
|
const DISCUSSION_BINDINGS_NAMESPACE = "discussion-bindings";
|
|
208
210
|
const MAX_DISCUSSION_BINDINGS = 1e4;
|
|
@@ -211,7 +213,6 @@ const BINDING_STORE_OPTIONS = {
|
|
|
211
213
|
maxEntries: MAX_DISCUSSION_BINDINGS,
|
|
212
214
|
overflowPolicy: "reject-new"
|
|
213
215
|
};
|
|
214
|
-
const MAX_RETAINED_DETACHED_DISCUSSION_BINDINGS = 1e3;
|
|
215
216
|
const storesByRuntime$1 = /* @__PURE__ */ new WeakMap();
|
|
216
217
|
function channelKey(serverBaseUrl, channelId) {
|
|
217
218
|
return `${serverBaseUrl.replace(/\/+$/u, "")}\0${channelId}`;
|
|
@@ -227,7 +228,6 @@ var ClickClackDiscussionBindingStore = class {
|
|
|
227
228
|
#withMutation = createAsyncLock();
|
|
228
229
|
#prepared = false;
|
|
229
230
|
#preparing;
|
|
230
|
-
#changedDuringPreparation = /* @__PURE__ */ new Set();
|
|
231
231
|
constructor(runtime) {
|
|
232
232
|
this.#runtime = runtime;
|
|
233
233
|
}
|
|
@@ -295,36 +295,19 @@ var ClickClackDiscussionBindingStore = class {
|
|
|
295
295
|
this.#publish(sessionKey, observed.value);
|
|
296
296
|
return false;
|
|
297
297
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
operation: "update",
|
|
309
|
-
action: "set",
|
|
310
|
-
value: next
|
|
311
|
-
} : {
|
|
312
|
-
operation: "delete",
|
|
313
|
-
action: "delete"
|
|
314
|
-
});
|
|
315
|
-
this.#publish(sessionKey, result.status === "conflict" ? result.current.value : next);
|
|
316
|
-
return result.status === "applied";
|
|
317
|
-
} catch (error) {
|
|
318
|
-
if (!authorityRejected) throw error;
|
|
319
|
-
const current = await worker.observe(sessionKey);
|
|
320
|
-
if (current.comparison === observed.comparison) throw error;
|
|
321
|
-
this.#publish(sessionKey, current.value);
|
|
322
|
-
return false;
|
|
323
|
-
}
|
|
298
|
+
const result = await (options?.assertCurrent ? this.#runtime.state.openKeyedStoreV2(BINDING_STORE_OPTIONS, { assertCurrent: options.assertCurrent }) : worker).compareAndApply(sessionKey, observed.comparison, next ? {
|
|
299
|
+
operation: "update",
|
|
300
|
+
action: "set",
|
|
301
|
+
value: next
|
|
302
|
+
} : {
|
|
303
|
+
operation: "delete",
|
|
304
|
+
action: "delete"
|
|
305
|
+
});
|
|
306
|
+
this.#publish(sessionKey, result.status === "conflict" ? result.current.value : next);
|
|
307
|
+
return result.status === "applied";
|
|
324
308
|
});
|
|
325
309
|
}
|
|
326
310
|
#publish(sessionKey, binding) {
|
|
327
|
-
if (!this.#prepared) this.#changedDuringPreparation.add(sessionKey);
|
|
328
311
|
this.#unindex(sessionKey);
|
|
329
312
|
if (binding) this.#index(sessionKey, binding);
|
|
330
313
|
}
|
|
@@ -334,10 +317,10 @@ var ClickClackDiscussionBindingStore = class {
|
|
|
334
317
|
binding: entry.value
|
|
335
318
|
}));
|
|
336
319
|
if (this.#prepared) return await load();
|
|
337
|
-
this.#preparing ??=
|
|
338
|
-
|
|
320
|
+
this.#preparing ??= this.#withMutation(async () => {
|
|
321
|
+
const entries = await load();
|
|
322
|
+
for (const { sessionKey, binding } of entries) this.#index(sessionKey, binding);
|
|
339
323
|
this.#prepared = true;
|
|
340
|
-
this.#changedDuringPreparation.clear();
|
|
341
324
|
return entries;
|
|
342
325
|
}).finally(() => {
|
|
343
326
|
this.#preparing = void 0;
|
|
@@ -393,7 +376,7 @@ function getClickClackDiscussionBindingStore(runtime) {
|
|
|
393
376
|
}
|
|
394
377
|
// extensions/clickclack/src/discussions/naming.ts
|
|
395
378
|
function shortSessionHash(sessionKey) {
|
|
396
|
-
return
|
|
379
|
+
return sha256Hex(sessionKey).slice(0, 32);
|
|
397
380
|
}
|
|
398
381
|
function slugifyLabel(label) {
|
|
399
382
|
return label.normalize("NFKD").replace(/[\u0300-\u036f]/gu, "").toLowerCase().replace(/[^a-z0-9]+/gu, "-").replace(/^-+|-+$/gu, "").slice(0, 80).replace(/-+$/gu, "");
|
|
@@ -413,13 +396,13 @@ function slugifyDiscussionLabel(label, sessionKey) {
|
|
|
413
396
|
return slugifyLabel(label) || fallbackDiscussionLabel(sessionKey);
|
|
414
397
|
}
|
|
415
398
|
function discussionSessionPeerId(identity) {
|
|
416
|
-
return `disc-${
|
|
399
|
+
return `disc-${sha256Hex([
|
|
417
400
|
identity.mainSessionKey,
|
|
418
401
|
identity.sessionId,
|
|
419
402
|
identity.serverBaseUrl,
|
|
420
403
|
identity.channelId,
|
|
421
404
|
identity.externalRef
|
|
422
|
-
].join("\0")).
|
|
405
|
+
].join("\0")).slice(0, 32)}`;
|
|
423
406
|
}
|
|
424
407
|
function isDiscussionSessionKey(sessionKey) {
|
|
425
408
|
return sessionKey.includes(":clickclack:") && /:channel:disc-[0-9a-f]{32}$/u.test(sessionKey);
|
|
@@ -432,7 +415,7 @@ function discussionExternalRef(installationId, mainSessionKey, destinationIdenti
|
|
|
432
415
|
].join("\0"))}`;
|
|
433
416
|
}
|
|
434
417
|
function discussionCredentialFingerprint(token) {
|
|
435
|
-
return
|
|
418
|
+
return sha256Hex(token);
|
|
436
419
|
}
|
|
437
420
|
function discussionSessionKey(params) {
|
|
438
421
|
return params.runtime.channel.routing.buildAgentSessionKey({
|
|
@@ -455,8 +438,7 @@ function normalizedServerBaseUrl(account) {
|
|
|
455
438
|
/** Resolves the sole live account and rejects bindings pinned to an older destination. */
|
|
456
439
|
function resolveDiscussionBindingAccount(cfg, binding) {
|
|
457
440
|
const accounts = discussionAccounts(cfg);
|
|
458
|
-
|
|
459
|
-
const account = accounts[0];
|
|
441
|
+
const account = accounts.length === 1 ? accounts[0] : void 0;
|
|
460
442
|
if (!account) return { state: "unavailable" };
|
|
461
443
|
if (account.accountId !== binding.accountId || normalizedServerBaseUrl(account) !== binding.serverBaseUrl || account.discussions.workspace !== binding.workspaceRef || binding.credentialFingerprint !== void 0 && discussionCredentialFingerprint(account.token) !== binding.credentialFingerprint) return {
|
|
462
444
|
state: "stale",
|
|
@@ -573,6 +555,22 @@ async function isClickClackDiscussionChannelRevokedAsync(params) {
|
|
|
573
555
|
function revocationApplies(revoked, binding) {
|
|
574
556
|
return Boolean(revoked && (!binding || !revoked.binding || isDeepStrictEqual(revoked.binding, binding)));
|
|
575
557
|
}
|
|
558
|
+
// extensions/clickclack/src/discussions/session-authority.ts
|
|
559
|
+
/** Retain the session owner's receipt-backed facts until the external effect completes. */
|
|
560
|
+
async function prepareDiscussionSessionEntry(runtime, sessionKey) {
|
|
561
|
+
const config = runtime.config.current();
|
|
562
|
+
const agentId = resolveSessionAgentIdStrict({
|
|
563
|
+
config,
|
|
564
|
+
sessionKey
|
|
565
|
+
});
|
|
566
|
+
return await captureSessionEntryCurrentCheckAsync({
|
|
567
|
+
agentId,
|
|
568
|
+
sessionKey,
|
|
569
|
+
storePath: runtime.agent.session.resolveStorePath(config.session?.store, { agentId }),
|
|
570
|
+
matchGeneration: false,
|
|
571
|
+
fields: ["sessionId", "archivedAt"]
|
|
572
|
+
});
|
|
573
|
+
}
|
|
576
574
|
// extensions/clickclack/src/discussions/routing.ts
|
|
577
575
|
async function resolveClickClackDiscussionRoute(params) {
|
|
578
576
|
const store = getClickClackDiscussionBindingStore(params.runtime);
|
|
@@ -585,6 +583,7 @@ async function resolveClickClackDiscussionRoute(params) {
|
|
|
585
583
|
}
|
|
586
584
|
let revocation;
|
|
587
585
|
let bindingFacts;
|
|
586
|
+
let session;
|
|
588
587
|
try {
|
|
589
588
|
revocation = await prepareClickClackDiscussionChannelRevocation(params);
|
|
590
589
|
if (revocation.isRevoked(matched?.binding)) return { state: "revoked" };
|
|
@@ -609,8 +608,10 @@ async function resolveClickClackDiscussionRoute(params) {
|
|
|
609
608
|
return { state: "revoked" };
|
|
610
609
|
}
|
|
611
610
|
if (!binding) return { state: "revoked" };
|
|
611
|
+
session = await prepareDiscussionSessionEntry(params.runtime, matched.sessionKey);
|
|
612
|
+
session.source();
|
|
612
613
|
const current = bindingFacts.read();
|
|
613
|
-
if (!current || current.externalRef !== binding.externalRef || current.channelId !== binding.channelId || revocation.isRevoked(current) ||
|
|
614
|
+
if (!current || current.externalRef !== binding.externalRef || current.channelId !== binding.channelId || revocation.isRevoked(current) || session.entry?.sessionId !== binding.sessionId || session.entry.archivedAt !== void 0 || resolveDiscussionBindingAccount(params.runtime.config.current(), binding).state !== "active") return { state: "revoked" };
|
|
614
615
|
const sessionKey = discussionSessionKey({
|
|
615
616
|
runtime: params.runtime,
|
|
616
617
|
agentId: binding.agentId,
|
|
@@ -639,6 +640,7 @@ async function resolveClickClackDiscussionRoute(params) {
|
|
|
639
640
|
} catch {
|
|
640
641
|
return { state: "revoked" };
|
|
641
642
|
} finally {
|
|
643
|
+
session?.release();
|
|
642
644
|
bindingFacts?.release();
|
|
643
645
|
revocation?.release();
|
|
644
646
|
}
|
|
@@ -658,65 +660,7 @@ function resolveClickClackGroupPolicy(params) {
|
|
|
658
660
|
botLoopProtection: mergePairLoopGuardConfig(account.botLoopProtection, wildcard?.botLoopProtection, exact?.botLoopProtection)
|
|
659
661
|
};
|
|
660
662
|
}
|
|
661
|
-
// extensions/clickclack/src/mention-facts.ts
|
|
662
|
-
const CLICKCLACK_MENTION_PATTERN = /(?:^|[^a-z0-9_@-])@([a-z0-9][a-z0-9_-]{1,31})(?![a-z0-9_-])/giu;
|
|
663
|
-
function buildLocalMentionRegexes(params) {
|
|
664
|
-
if (params.mentionPatterns.length === 0) return [];
|
|
665
|
-
const cfg = params.cfg;
|
|
666
|
-
const syntheticCfg = {
|
|
667
|
-
...cfg,
|
|
668
|
-
messages: {
|
|
669
|
-
...cfg?.messages,
|
|
670
|
-
groupChat: {
|
|
671
|
-
...cfg?.messages?.groupChat,
|
|
672
|
-
mentionPatterns: params.mentionPatterns
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
};
|
|
676
|
-
return (0, channel_mention_gating_exports.buildMentionRegexes)(syntheticCfg, void 0, {
|
|
677
|
-
provider: "clickclack",
|
|
678
|
-
conversationId: params.channelId
|
|
679
|
-
});
|
|
680
|
-
}
|
|
681
|
-
function resolveMentionHandles(body) {
|
|
682
|
-
return [...body.matchAll(CLICKCLACK_MENTION_PATTERN)].map((match) => match[1]?.toLowerCase()).filter((handle) => Boolean(handle));
|
|
683
|
-
}
|
|
684
|
-
function resolveClickClackMentionFacts(params) {
|
|
685
|
-
const { isDirect, body, mentionPatterns, botHandle, cfg, agentId, channelId } = params;
|
|
686
|
-
if (isDirect) return {
|
|
687
|
-
canDetectMention: false,
|
|
688
|
-
wasMentioned: false
|
|
689
|
-
};
|
|
690
|
-
if (!body) return {
|
|
691
|
-
canDetectMention: true,
|
|
692
|
-
wasMentioned: false,
|
|
693
|
-
hasAnyMention: false
|
|
694
|
-
};
|
|
695
|
-
const sharedMentionRegexes = (0, channel_mention_gating_exports.buildMentionRegexes)(cfg, agentId, {
|
|
696
|
-
provider: "clickclack",
|
|
697
|
-
conversationId: channelId
|
|
698
|
-
});
|
|
699
|
-
const localMentionRegexes = buildLocalMentionRegexes({
|
|
700
|
-
cfg,
|
|
701
|
-
mentionPatterns,
|
|
702
|
-
channelId
|
|
703
|
-
});
|
|
704
|
-
const mentionRegexes = [...sharedMentionRegexes, ...localMentionRegexes];
|
|
705
|
-
const bodyForRegex = (0, channel_mention_gating_exports.normalizeMentionText)(body);
|
|
706
|
-
const hasConfiguredMention = mentionRegexes.some((regex) => regex.test(bodyForRegex));
|
|
707
|
-
const mentionHandles = resolveMentionHandles(body);
|
|
708
|
-
const normalizedBotHandle = botHandle?.replace(/^@/u, "").trim().toLowerCase();
|
|
709
|
-
return {
|
|
710
|
-
canDetectMention: true,
|
|
711
|
-
wasMentioned: (normalizedBotHandle ? mentionHandles.includes(normalizedBotHandle) : false) || hasConfiguredMention,
|
|
712
|
-
hasAnyMention: mentionHandles.length > 0 || hasConfiguredMention
|
|
713
|
-
};
|
|
714
|
-
}
|
|
715
663
|
// extensions/clickclack/src/runtime.ts
|
|
716
|
-
/**
|
|
717
|
-
* Runtime store for host-provided OpenClaw services used by the ClickClack
|
|
718
|
-
* bundled plugin.
|
|
719
|
-
*/
|
|
720
664
|
const { setRuntime: setClickClackRuntime, getRuntime: getClickClackRuntime } = createPluginRuntimeStore({
|
|
721
665
|
pluginId: "clickclack",
|
|
722
666
|
errorMessage: "ClickClack runtime not initialized"
|
|
@@ -755,14 +699,9 @@ function parseClickClackTarget(raw) {
|
|
|
755
699
|
function buildClickClackTarget(target) {
|
|
756
700
|
return `${target.kind}:${target.id}`;
|
|
757
701
|
}
|
|
758
|
-
function normalizeClickClackTarget(raw) {
|
|
759
|
-
return buildClickClackTarget(parseClickClackTarget(raw));
|
|
760
|
-
}
|
|
761
|
-
function looksLikeClickClackTarget(raw) {
|
|
762
|
-
return raw.trim().length > 0;
|
|
763
|
-
}
|
|
764
702
|
// extensions/clickclack/src/access.ts
|
|
765
703
|
const CHANNEL_ID$2 = "clickclack";
|
|
704
|
+
const CLICKCLACK_MENTION_PATTERN = /(?:^|[^a-z0-9_@-])@([a-z0-9][a-z0-9_-]{1,31})(?![a-z0-9_-])/giu;
|
|
766
705
|
function normalizeClickClackUserId(value) {
|
|
767
706
|
const trimmed = value.trim();
|
|
768
707
|
if (!trimmed) return null;
|
|
@@ -789,77 +728,83 @@ async function isClickClackBotOwnedThread(params) {
|
|
|
789
728
|
return false;
|
|
790
729
|
}
|
|
791
730
|
}
|
|
792
|
-
function
|
|
793
|
-
if (params.message.parent_message_id && params.message.thread_root_id) return params.message.thread_root_id;
|
|
794
|
-
return params.isDirect ? params.message.direct_conversation_id ?? params.message.author_id : params.message.channel_id ?? params.message.thread_root_id ?? params.message.author_id;
|
|
795
|
-
}
|
|
796
|
-
function resolveAccountAgentRoute(params) {
|
|
731
|
+
async function resolveClickClackInboundAccess(params) {
|
|
797
732
|
const runtime = getClickClackRuntime();
|
|
798
|
-
const
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
};
|
|
802
|
-
const
|
|
803
|
-
cfg:
|
|
804
|
-
|
|
805
|
-
accountId: params.account.accountId,
|
|
806
|
-
peer
|
|
807
|
-
});
|
|
808
|
-
const agentId = normalizeAgentId(params.account.agentId ?? route.agentId);
|
|
809
|
-
if (agentId === route.agentId) return route;
|
|
810
|
-
const dmScope = params.cfg.session?.dmScope ?? "main";
|
|
811
|
-
const sessionKey = runtime.channel.routing.buildAgentSessionKey({
|
|
812
|
-
agentId,
|
|
813
|
-
mainKey: params.cfg.session?.mainKey,
|
|
814
|
-
channel: CHANNEL_ID$2,
|
|
815
|
-
accountId: params.account.accountId,
|
|
816
|
-
peer,
|
|
817
|
-
dmScope,
|
|
818
|
-
identityLinks: params.cfg.session?.identityLinks
|
|
819
|
-
});
|
|
820
|
-
const mainSessionKey = runtime.channel.routing.buildAgentSessionKey({
|
|
821
|
-
agentId,
|
|
822
|
-
mainKey: params.cfg.session?.mainKey,
|
|
823
|
-
channel: CHANNEL_ID$2,
|
|
824
|
-
accountId: params.account.accountId,
|
|
825
|
-
dmScope: "main"
|
|
733
|
+
const rootPolicyConfigured = resolveClickClackGroupPolicy({
|
|
734
|
+
account: params.account,
|
|
735
|
+
channelId: params.message.channel_id
|
|
736
|
+
}).requireMentionInBotThreads !== void 0;
|
|
737
|
+
const isCurrent = () => isClickClackAccountCurrent({
|
|
738
|
+
cfg: runtime.config.current(),
|
|
739
|
+
account: params.account
|
|
826
740
|
});
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
741
|
+
const isBotOwnedThread = rootPolicyConfigured && await isClickClackBotOwnedThread(params);
|
|
742
|
+
const routeConfig = rootPolicyConfigured ? runtime.config.current() : params.config;
|
|
743
|
+
const routeAccountConfig = rootPolicyConfigured ? resolveClickClackAccountConfig(routeConfig, params.account.accountId) : params.account;
|
|
744
|
+
const routingMessage = params.message;
|
|
745
|
+
const routingAccount = {
|
|
746
|
+
...params.account,
|
|
747
|
+
agentId: routeAccountConfig.agentId
|
|
834
748
|
};
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
const runtime = getClickClackRuntime();
|
|
838
|
-
const isDirect = Boolean(params.message.direct_conversation_id);
|
|
749
|
+
const routeRuntime = getClickClackRuntime();
|
|
750
|
+
const isDirect = Boolean(routingMessage.direct_conversation_id);
|
|
839
751
|
const target = buildClickClackTarget(isDirect ? {
|
|
840
752
|
chatType: "direct",
|
|
841
753
|
kind: "dm",
|
|
842
|
-
id:
|
|
754
|
+
id: routingMessage.author_id
|
|
843
755
|
} : {
|
|
844
756
|
chatType: "group",
|
|
845
757
|
kind: "channel",
|
|
846
|
-
id:
|
|
758
|
+
id: routingMessage.channel_id ?? ""
|
|
847
759
|
});
|
|
848
|
-
const
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
target
|
|
852
|
-
|
|
760
|
+
const routingConfig = routeConfig;
|
|
761
|
+
const peer = {
|
|
762
|
+
kind: isDirect ? "direct" : "channel",
|
|
763
|
+
id: target
|
|
764
|
+
};
|
|
765
|
+
let accountRoute = routeRuntime.channel.routing.resolveAgentRoute({
|
|
766
|
+
cfg: routingConfig,
|
|
767
|
+
channel: CHANNEL_ID$2,
|
|
768
|
+
accountId: routingAccount.accountId,
|
|
769
|
+
peer
|
|
853
770
|
});
|
|
854
|
-
const
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
771
|
+
const agentId = normalizeAgentId(routingAccount.agentId ?? accountRoute.agentId);
|
|
772
|
+
if (agentId !== accountRoute.agentId) {
|
|
773
|
+
const dmScope = routingConfig.session?.dmScope ?? "main";
|
|
774
|
+
const sessionKey = routeRuntime.channel.routing.buildAgentSessionKey({
|
|
775
|
+
agentId,
|
|
776
|
+
mainKey: routingConfig.session?.mainKey,
|
|
777
|
+
channel: CHANNEL_ID$2,
|
|
778
|
+
accountId: routingAccount.accountId,
|
|
779
|
+
peer,
|
|
780
|
+
dmScope,
|
|
781
|
+
identityLinks: routingConfig.session?.identityLinks
|
|
782
|
+
});
|
|
783
|
+
const mainSessionKey = routeRuntime.channel.routing.buildAgentSessionKey({
|
|
784
|
+
agentId,
|
|
785
|
+
mainKey: routingConfig.session?.mainKey,
|
|
786
|
+
channel: CHANNEL_ID$2,
|
|
787
|
+
accountId: routingAccount.accountId,
|
|
788
|
+
dmScope: "main"
|
|
789
|
+
});
|
|
790
|
+
accountRoute = {
|
|
791
|
+
...accountRoute,
|
|
792
|
+
agentId,
|
|
793
|
+
dmScope,
|
|
794
|
+
sessionKey,
|
|
795
|
+
mainSessionKey,
|
|
796
|
+
lastRoutePolicy: sessionKey === mainSessionKey ? "main" : "session"
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
const discussionResolution = await (!isDirect && routingMessage.channel_id ? resolveClickClackDiscussionRoute({
|
|
800
|
+
runtime: routeRuntime,
|
|
801
|
+
accountId: routingAccount.accountId,
|
|
802
|
+
serverBaseUrl: routingAccount.baseUrl,
|
|
803
|
+
workspaceId: routingMessage.workspace_id,
|
|
804
|
+
channelId: routingMessage.channel_id
|
|
805
|
+
}) : { state: "unbound" });
|
|
861
806
|
const discussionRoute = discussionResolution.state === "active" ? discussionResolution.route : void 0;
|
|
862
|
-
|
|
807
|
+
const preparedRoute = {
|
|
863
808
|
isDirect,
|
|
864
809
|
target,
|
|
865
810
|
route: discussionRoute ? {
|
|
@@ -871,28 +816,44 @@ async function resolvePreparedInboundRoute(params) {
|
|
|
871
816
|
discussionRoute,
|
|
872
817
|
revoked: discussionResolution.state === "revoked"
|
|
873
818
|
};
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
819
|
+
const resolveMentionFacts = (mentionConfig, mentionPatterns) => {
|
|
820
|
+
if (preparedRoute.isDirect) return {
|
|
821
|
+
canDetectMention: false,
|
|
822
|
+
wasMentioned: false
|
|
823
|
+
};
|
|
824
|
+
const body = params.message.body;
|
|
825
|
+
if (!body) return {
|
|
826
|
+
canDetectMention: true,
|
|
827
|
+
wasMentioned: false,
|
|
828
|
+
hasAnyMention: false
|
|
829
|
+
};
|
|
830
|
+
const sharedMentionRegexes = (0, channel_mention_gating_exports.buildMentionRegexes)(mentionConfig, preparedRoute.route.agentId, {
|
|
831
|
+
provider: CHANNEL_ID$2,
|
|
832
|
+
conversationId: params.message.channel_id
|
|
833
|
+
});
|
|
834
|
+
const localMentionRegexes = mentionPatterns.length ? (0, channel_mention_gating_exports.buildMentionRegexes)({
|
|
835
|
+
...mentionConfig,
|
|
836
|
+
messages: {
|
|
837
|
+
...mentionConfig.messages,
|
|
838
|
+
groupChat: {
|
|
839
|
+
...mentionConfig.messages?.groupChat,
|
|
840
|
+
mentionPatterns
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
}, void 0, {
|
|
844
|
+
provider: CHANNEL_ID$2,
|
|
845
|
+
conversationId: params.message.channel_id
|
|
846
|
+
}) : [];
|
|
847
|
+
const bodyForRegex = (0, channel_mention_gating_exports.normalizeMentionText)(body);
|
|
848
|
+
const hasConfiguredMention = [...sharedMentionRegexes, ...localMentionRegexes].some((regex) => regex.test(bodyForRegex));
|
|
849
|
+
const mentionHandles = [...body.matchAll(CLICKCLACK_MENTION_PATTERN)].map((match) => match[1]?.toLowerCase()).filter((handle) => Boolean(handle));
|
|
850
|
+
const botHandle = params.account.botHandle?.replace(/^@/u, "").trim().toLowerCase();
|
|
851
|
+
return {
|
|
852
|
+
canDetectMention: true,
|
|
853
|
+
wasMentioned: (botHandle ? mentionHandles.includes(botHandle) : false) || hasConfiguredMention,
|
|
854
|
+
hasAnyMention: mentionHandles.length > 0 || hasConfiguredMention
|
|
855
|
+
};
|
|
856
|
+
};
|
|
896
857
|
const cfg = rootPolicyConfigured ? runtime.config.current() : params.config;
|
|
897
858
|
const accountPolicy = rootPolicyConfigured ? resolveClickClackAccountConfig(cfg, params.account.accountId) : params.account;
|
|
898
859
|
const effectiveGroupPolicy = resolveClickClackGroupPolicy({
|
|
@@ -905,16 +866,10 @@ async function resolveClickClackInboundAccess(params) {
|
|
|
905
866
|
requireMention: effectiveGroupPolicy.requireMention
|
|
906
867
|
});
|
|
907
868
|
const shouldCheckCommand = runtime.channel.commands.shouldComputeCommandAuthorized(params.message.body, cfg);
|
|
908
|
-
const mentionFacts =
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
botHandle: params.account.botHandle,
|
|
913
|
-
cfg,
|
|
914
|
-
agentId: preparedRoute.route.agentId,
|
|
915
|
-
channelId: params.message.channel_id
|
|
916
|
-
});
|
|
917
|
-
if (!isCurrent() || params.message.kind !== void 0 && params.message.kind !== "message") return {
|
|
869
|
+
const mentionFacts = resolveMentionFacts(cfg, effectiveGroupPolicy.mentionPatterns);
|
|
870
|
+
const isBotAuthor = params.message.author?.kind === "bot";
|
|
871
|
+
const botMentionAllowed = !isBotAuthor || effectiveGroupPolicy.allowBots === true || effectiveGroupPolicy.allowBots === "mentions" && (preparedRoute.isDirect || mentionFacts.wasMentioned);
|
|
872
|
+
if (!isCurrent() || params.message.kind !== void 0 && params.message.kind !== "message" || !botMentionAllowed) return {
|
|
918
873
|
shouldDispatch: false,
|
|
919
874
|
isCurrent,
|
|
920
875
|
commandAuthorized: false,
|
|
@@ -922,24 +877,12 @@ async function resolveClickClackInboundAccess(params) {
|
|
|
922
877
|
mentionFacts,
|
|
923
878
|
preparedRoute
|
|
924
879
|
};
|
|
925
|
-
const isBotAuthor = params.message.author?.kind === "bot";
|
|
926
880
|
const allowFrom = accountPolicy.allowFrom ?? ["*"];
|
|
927
881
|
const ingressAllowFrom = isBotAuthor ? allowFrom.filter((entry) => normalizeClickClackUserId(entry) !== "*") : allowFrom;
|
|
928
|
-
if (!(!isBotAuthor || effectiveGroupPolicy.allowBots === true || effectiveGroupPolicy.allowBots === "mentions" && (preparedRoute.isDirect || mentionFacts.wasMentioned))) return {
|
|
929
|
-
shouldDispatch: false,
|
|
930
|
-
isCurrent,
|
|
931
|
-
commandAuthorized: false,
|
|
932
|
-
requireMention: threadMentionPolicy.requireMention,
|
|
933
|
-
mentionFacts,
|
|
934
|
-
preparedRoute
|
|
935
|
-
};
|
|
936
882
|
const botLoopNowMs = parseDateStringTimestampMs(params.message.created_at);
|
|
937
883
|
const botLoopProtection = isBotAuthor && params.message.author_id !== params.account.botUserId && params.account.botUserId ? {
|
|
938
884
|
scopeId: params.account.workspace,
|
|
939
|
-
conversationId:
|
|
940
|
-
message: params.message,
|
|
941
|
-
isDirect: preparedRoute.isDirect
|
|
942
|
-
}),
|
|
885
|
+
conversationId: params.message.parent_message_id && params.message.thread_root_id ? params.message.thread_root_id : preparedRoute.isDirect ? params.message.direct_conversation_id ?? params.message.author_id : params.message.channel_id ?? params.message.thread_root_id ?? params.message.author_id,
|
|
943
886
|
senderId: params.message.author_id,
|
|
944
887
|
receiverId: params.account.botUserId,
|
|
945
888
|
eventId: params.message.id,
|
|
@@ -980,7 +923,8 @@ async function resolveClickClackInboundAccess(params) {
|
|
|
980
923
|
} },
|
|
981
924
|
command: shouldCheckCommand ? {
|
|
982
925
|
cfg,
|
|
983
|
-
modeWhenAccessGroupsOff: "configured"
|
|
926
|
+
modeWhenAccessGroupsOff: "configured",
|
|
927
|
+
hasControlCommand: runtime.channel.text.hasControlCommand(params.message.body, cfg)
|
|
984
928
|
} : false
|
|
985
929
|
});
|
|
986
930
|
const isAdmissionCurrent = () => {
|
|
@@ -1010,15 +954,7 @@ async function resolveClickClackInboundAccess(params) {
|
|
|
1010
954
|
return group?.type === "message.senders" && resolved.state.allowlists[preparedRoute.isDirect ? "dm" : "group"].accessGroups.matched.includes(name) && isDeepStrictEqual(group, cfg.accessGroups?.[name]);
|
|
1011
955
|
});
|
|
1012
956
|
if (!directSenderAllowed && !staticGroupAllowed) return false;
|
|
1013
|
-
const currentMentionFacts =
|
|
1014
|
-
isDirect: preparedRoute.isDirect,
|
|
1015
|
-
body: params.message.body,
|
|
1016
|
-
mentionPatterns: currentGroupPolicy.mentionPatterns,
|
|
1017
|
-
botHandle: params.account.botHandle,
|
|
1018
|
-
cfg: currentCfg,
|
|
1019
|
-
agentId: preparedRoute.route.agentId,
|
|
1020
|
-
channelId: params.message.channel_id
|
|
1021
|
-
});
|
|
957
|
+
const currentMentionFacts = resolveMentionFacts(currentCfg, currentGroupPolicy.mentionPatterns);
|
|
1022
958
|
if (isBotAuthor && currentGroupPolicy.allowBots !== true && !(currentGroupPolicy.allowBots === "mentions" && (preparedRoute.isDirect || currentMentionFacts.wasMentioned))) return false;
|
|
1023
959
|
const currentThreadPolicy = resolveBotThreadMentionPolicy({
|
|
1024
960
|
isBotOwnedThread,
|
|
@@ -1035,7 +971,7 @@ async function resolveClickClackInboundAccess(params) {
|
|
|
1035
971
|
surface: CHANNEL_ID$2,
|
|
1036
972
|
commandSource: "text"
|
|
1037
973
|
}),
|
|
1038
|
-
hasControlCommand: shouldCheckCommand && runtime.channel.
|
|
974
|
+
hasControlCommand: shouldCheckCommand && runtime.channel.text.hasControlCommand(params.message.body, currentCfg),
|
|
1039
975
|
commandAuthorized: resolved.commandAccess.authorized
|
|
1040
976
|
}
|
|
1041
977
|
}).shouldSkip;
|
|
@@ -1051,61 +987,6 @@ async function resolveClickClackInboundAccess(params) {
|
|
|
1051
987
|
channelIngress: resolved
|
|
1052
988
|
};
|
|
1053
989
|
}
|
|
1054
|
-
// extensions/clickclack/src/command-menu.ts
|
|
1055
|
-
const CLICKCLACK_COMMAND_PATTERN = /^[a-z0-9_-]{1,32}$/u;
|
|
1056
|
-
const CLICKCLACK_MAX_COMMANDS = 100;
|
|
1057
|
-
const CLICKCLACK_MAX_DESCRIPTION_LENGTH = 100;
|
|
1058
|
-
const CLICKCLACK_MAX_ARGS_HINT_LENGTH = 100;
|
|
1059
|
-
function commandArgsHint(spec) {
|
|
1060
|
-
if (spec.args?.length) return truncateCodePoints(spec.args.map((arg) => arg.required ? `<${arg.name}>` : `[${arg.name}]`).join(" "), CLICKCLACK_MAX_ARGS_HINT_LENGTH);
|
|
1061
|
-
return spec.acceptsArgs ? "[args]" : "";
|
|
1062
|
-
}
|
|
1063
|
-
function errorStatus(error) {
|
|
1064
|
-
if (!error || typeof error !== "object" || !("status" in error)) return;
|
|
1065
|
-
const status = error.status;
|
|
1066
|
-
return typeof status === "number" ? status : void 0;
|
|
1067
|
-
}
|
|
1068
|
-
function mapNativeCommandSpecsToClickClackMenu(specs, log) {
|
|
1069
|
-
const commands = [];
|
|
1070
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1071
|
-
const invalidNames = /* @__PURE__ */ new Set();
|
|
1072
|
-
for (const spec of specs) {
|
|
1073
|
-
if (spec.isAlias) continue;
|
|
1074
|
-
const command = spec.name.trim().toLowerCase();
|
|
1075
|
-
if (!CLICKCLACK_COMMAND_PATTERN.test(command)) {
|
|
1076
|
-
invalidNames.add(spec.name.trim() || "<empty>");
|
|
1077
|
-
continue;
|
|
1078
|
-
}
|
|
1079
|
-
if (seen.has(command)) continue;
|
|
1080
|
-
seen.add(command);
|
|
1081
|
-
const description = spec.description.trim() || command;
|
|
1082
|
-
commands.push({
|
|
1083
|
-
command,
|
|
1084
|
-
description: truncateCodePoints(description, CLICKCLACK_MAX_DESCRIPTION_LENGTH),
|
|
1085
|
-
args_hint: commandArgsHint(spec)
|
|
1086
|
-
});
|
|
1087
|
-
}
|
|
1088
|
-
if (invalidNames.size > 0) log?.warn?.(`ClickClack command menu skipped invalid native command names: ${[...invalidNames].map((name) => JSON.stringify(name)).join(", ")}`);
|
|
1089
|
-
return commands.slice(0, CLICKCLACK_MAX_COMMANDS);
|
|
1090
|
-
}
|
|
1091
|
-
async function syncClickClackCommandMenu(params) {
|
|
1092
|
-
try {
|
|
1093
|
-
const commands = mapNativeCommandSpecsToClickClackMenu(listNativeCommandSpecsForConfig(params.cfg, { provider: "clickclack" }), params.log);
|
|
1094
|
-
await params.client.setBotCommands(commands);
|
|
1095
|
-
} catch (error) {
|
|
1096
|
-
const status = errorStatus(error);
|
|
1097
|
-
const messagePrefix = `[${params.accountId}] ClickClack command menu sync`;
|
|
1098
|
-
if (status === 403) {
|
|
1099
|
-
params.log?.warn?.(`${messagePrefix} skipped: ${formatErrorMessage(error)}; verify token/workspace command permissions or set commandMenu: false if menus are not needed`);
|
|
1100
|
-
return;
|
|
1101
|
-
}
|
|
1102
|
-
if (status === 404) {
|
|
1103
|
-
params.log?.debug?.(`${messagePrefix} skipped: server does not support /api/bots/self/commands`);
|
|
1104
|
-
return;
|
|
1105
|
-
}
|
|
1106
|
-
params.log?.warn?.(`${messagePrefix} failed: ${formatErrorMessage(error)}`);
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
990
|
// extensions/clickclack/src/activity.ts
|
|
1110
991
|
const CLICKCLACK_COMMENTARY_FLUSH_MS = 700;
|
|
1111
992
|
/** Item kinds rendered as agent_tool rows; everything else is commentary. */
|
|
@@ -1135,31 +1016,11 @@ const THINKING_ITEM_KINDS = /* @__PURE__ */ new Set([
|
|
|
1135
1016
|
function normalizedItemKind(payload) {
|
|
1136
1017
|
return payload.kind?.trim().toLowerCase() ?? "";
|
|
1137
1018
|
}
|
|
1138
|
-
function commentaryBody(payload) {
|
|
1139
|
-
const text = payload.progressText?.trim() || payload.summary?.trim() || payload.meta?.trim() || "";
|
|
1140
|
-
if (!text) return "";
|
|
1141
|
-
const kind = normalizedItemKind(payload);
|
|
1142
|
-
if (THINKING_ITEM_KINDS.has(kind)) return `**Thinking**\n\n${text}`;
|
|
1143
|
-
return text;
|
|
1144
|
-
}
|
|
1145
|
-
function activityBody(payload) {
|
|
1146
|
-
const line = formatChannelProgressDraftLineForEntry(void 0, {
|
|
1147
|
-
...payload,
|
|
1148
|
-
event: "item",
|
|
1149
|
-
itemKind: payload.kind
|
|
1150
|
-
})?.trim();
|
|
1151
|
-
if (line) return line;
|
|
1152
|
-
const head = payload.name?.trim() || payload.title?.trim();
|
|
1153
|
-
const text = payload.progressText?.trim() || payload.summary?.trim();
|
|
1154
|
-
if (head && text) return `**${head}**\n\n${text}`;
|
|
1155
|
-
return text || head || payload.status?.trim() || payload.kind?.trim() || "";
|
|
1156
|
-
}
|
|
1157
1019
|
/**
|
|
1158
1020
|
* Creates a per-turn activity publisher. Publishing is best-effort: transport
|
|
1159
1021
|
* failures are reported through `onError` and never interrupt the reply turn.
|
|
1160
1022
|
*/
|
|
1161
1023
|
function createClickClackActivityPublisher(params) {
|
|
1162
|
-
const flushMs = params.flushMs ?? CLICKCLACK_COMMENTARY_FLUSH_MS;
|
|
1163
1024
|
const commentaryByItem = /* @__PURE__ */ new Map();
|
|
1164
1025
|
const toolRows = /* @__PURE__ */ new Map();
|
|
1165
1026
|
let provenance;
|
|
@@ -1181,10 +1042,8 @@ function createClickClackActivityPublisher(params) {
|
|
|
1181
1042
|
const flushCommentary = (segmentKey) => {
|
|
1182
1043
|
const segment = commentaryByItem.get(segmentKey);
|
|
1183
1044
|
if (!segment) return Promise.resolve();
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
segment.timer = void 0;
|
|
1187
|
-
}
|
|
1045
|
+
clearTimeout(segment.timer);
|
|
1046
|
+
segment.timer = void 0;
|
|
1188
1047
|
if (!segment.dirty || !segment.body) return Promise.resolve();
|
|
1189
1048
|
segment.dirty = false;
|
|
1190
1049
|
const body = segment.body;
|
|
@@ -1202,7 +1061,8 @@ function createClickClackActivityPublisher(params) {
|
|
|
1202
1061
|
return Promise.all(flushes).then(() => void 0);
|
|
1203
1062
|
};
|
|
1204
1063
|
const handleCommentary = (payload) => {
|
|
1205
|
-
const
|
|
1064
|
+
const text = payload.progressText?.trim() || payload.summary?.trim() || payload.meta?.trim() || "";
|
|
1065
|
+
const body = text && THINKING_ITEM_KINDS.has(normalizedItemKind(payload)) ? `**Thinking**\n\n${text}` : text;
|
|
1206
1066
|
const key = payload.itemId?.trim() || "turn";
|
|
1207
1067
|
let segment = commentaryByItem.get(key);
|
|
1208
1068
|
if (!body) {
|
|
@@ -1229,13 +1089,22 @@ function createClickClackActivityPublisher(params) {
|
|
|
1229
1089
|
if (!segment.timer) segment.timer = setTimeout(() => {
|
|
1230
1090
|
segment.timer = void 0;
|
|
1231
1091
|
flushCommentary(key);
|
|
1232
|
-
},
|
|
1092
|
+
}, CLICKCLACK_COMMENTARY_FLUSH_MS);
|
|
1233
1093
|
};
|
|
1234
1094
|
const toolRowKey = (payload) => {
|
|
1235
1095
|
return payload.itemId?.trim() || payload.toolCallId?.trim() || "";
|
|
1236
1096
|
};
|
|
1237
1097
|
const handleDiscreteItem = (payload) => {
|
|
1238
|
-
|
|
1098
|
+
let body = formatChannelProgressDraftLineForEntry(void 0, {
|
|
1099
|
+
...payload,
|
|
1100
|
+
event: "item",
|
|
1101
|
+
itemKind: payload.kind
|
|
1102
|
+
});
|
|
1103
|
+
if (!body) {
|
|
1104
|
+
const head = payload.name?.trim() || payload.title?.trim();
|
|
1105
|
+
const text = payload.progressText?.trim() || payload.summary?.trim();
|
|
1106
|
+
body = head && text ? `**${head}**\n\n${text}` : text || head || payload.status?.trim() || payload.kind?.trim() || "";
|
|
1107
|
+
}
|
|
1239
1108
|
if (!body) return;
|
|
1240
1109
|
const kind = TOOL_ITEM_KINDS.has(normalizedItemKind(payload)) ? "agent_tool" : "agent_commentary";
|
|
1241
1110
|
flushAllCommentary();
|
|
@@ -1246,9 +1115,10 @@ function createClickClackActivityPublisher(params) {
|
|
|
1246
1115
|
const row = { body };
|
|
1247
1116
|
if (itemKey) toolRows.set(key, row);
|
|
1248
1117
|
enqueue(async () => {
|
|
1249
|
-
const
|
|
1118
|
+
const submittedBody = row.body;
|
|
1119
|
+
const posted = await postRow(kind, submittedBody);
|
|
1250
1120
|
row.messageId = posted.id;
|
|
1251
|
-
row.sentBody =
|
|
1121
|
+
row.sentBody = submittedBody;
|
|
1252
1122
|
});
|
|
1253
1123
|
return;
|
|
1254
1124
|
}
|
|
@@ -1256,8 +1126,9 @@ function createClickClackActivityPublisher(params) {
|
|
|
1256
1126
|
existing.body = body;
|
|
1257
1127
|
enqueue(async () => {
|
|
1258
1128
|
if (existing.messageId && existing.body !== existing.sentBody) {
|
|
1259
|
-
|
|
1260
|
-
existing.
|
|
1129
|
+
const submittedBody = existing.body;
|
|
1130
|
+
await params.client.updateMessageBody(existing.messageId, submittedBody);
|
|
1131
|
+
existing.sentBody = submittedBody;
|
|
1261
1132
|
}
|
|
1262
1133
|
});
|
|
1263
1134
|
};
|
|
@@ -1331,7 +1202,7 @@ async function createTargetMessage(params) {
|
|
|
1331
1202
|
function durableDeliveryDigest(params) {
|
|
1332
1203
|
if (!params.deliveryQueueId) return;
|
|
1333
1204
|
if (!Number.isSafeInteger(params.deliveryPartIndex) || (params.deliveryPartIndex ?? -1) < 0) throw new Error("ClickClack durable delivery requires a stable delivery part index");
|
|
1334
|
-
return
|
|
1205
|
+
return sha256Hex(`${params.deliveryQueueId}\n${params.deliveryPartIndex}`);
|
|
1335
1206
|
}
|
|
1336
1207
|
function mediaDeliveryNonces(params) {
|
|
1337
1208
|
const digest = durableDeliveryDigest(params);
|
|
@@ -1578,7 +1449,7 @@ function progressText(payload) {
|
|
|
1578
1449
|
...payload,
|
|
1579
1450
|
event: "item",
|
|
1580
1451
|
itemKind: payload.kind
|
|
1581
|
-
})?.text
|
|
1452
|
+
})?.text;
|
|
1582
1453
|
if (line) return line;
|
|
1583
1454
|
return payload.progressText?.trim() || payload.summary?.trim() || payload.title?.trim() || payload.name?.trim() || payload.meta?.trim() || payload.status?.trim() || "Working";
|
|
1584
1455
|
}
|
|
@@ -1623,25 +1494,18 @@ function createClickClackAgentProgressPublisher(params) {
|
|
|
1623
1494
|
const drain = () => {
|
|
1624
1495
|
if (drainPromise) return drainPromise;
|
|
1625
1496
|
drainPromise = (async () => {
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
}
|
|
1639
|
-
});
|
|
1640
|
-
} catch (error) {
|
|
1641
|
-
try {
|
|
1642
|
-
params.onError?.(error);
|
|
1643
|
-
} catch {}
|
|
1644
|
-
}
|
|
1497
|
+
for (let frame = queue.shift(); frame; frame = queue.shift()) try {
|
|
1498
|
+
await params.client.publishEphemeral({
|
|
1499
|
+
...params.target,
|
|
1500
|
+
type: "agent.progress",
|
|
1501
|
+
payload: {
|
|
1502
|
+
turn_id: params.turnId,
|
|
1503
|
+
seq: ++sequence,
|
|
1504
|
+
...frame.payload
|
|
1505
|
+
}
|
|
1506
|
+
});
|
|
1507
|
+
} catch (error) {
|
|
1508
|
+
params.onError?.(error);
|
|
1645
1509
|
}
|
|
1646
1510
|
})().finally(() => {
|
|
1647
1511
|
drainPromise = void 0;
|
|
@@ -1707,25 +1571,26 @@ function createClickClackAgentProgressPublisher(params) {
|
|
|
1707
1571
|
if (!started || cleared) return false;
|
|
1708
1572
|
if (payload.suppressChannelProgress || payload.kind === "preamble" && !isCompleteAgentPreamble(payload)) return false;
|
|
1709
1573
|
const id = resolveLineId(payload);
|
|
1710
|
-
|
|
1574
|
+
const kind = normalizedKind(payload);
|
|
1575
|
+
const hidesLine = payload.hideFromChannelProgress || payload.kind === "model-wait" && payload.phase === "end";
|
|
1576
|
+
const retractsExistingCommentary = kind === "commentary" && seenLines.has(id) && payload.progressText !== void 0 && payload.progressText.trim() === "";
|
|
1577
|
+
if ((hidesLine || retractsExistingCommentary) && queuedLines.get(id)?.payload.op === "append") {
|
|
1578
|
+
queuedLines.delete(id);
|
|
1579
|
+
seenLines.delete(id);
|
|
1580
|
+
return false;
|
|
1581
|
+
}
|
|
1582
|
+
if (hidesLine) {
|
|
1711
1583
|
if (seenLines.delete(id)) enqueueLine(id, {
|
|
1712
1584
|
op: "update",
|
|
1713
1585
|
line: {
|
|
1714
1586
|
id,
|
|
1715
|
-
kind
|
|
1587
|
+
kind,
|
|
1716
1588
|
text: ""
|
|
1717
1589
|
}
|
|
1718
1590
|
});
|
|
1719
1591
|
return false;
|
|
1720
1592
|
}
|
|
1721
1593
|
const final = isFinal(payload);
|
|
1722
|
-
const kind = normalizedKind(payload);
|
|
1723
|
-
const retractsExistingCommentary = kind === "commentary" && seenLines.has(id) && payload.progressText !== void 0 && payload.progressText.trim() === "";
|
|
1724
|
-
if (retractsExistingCommentary && queuedLines.get(id)?.payload.op === "append") {
|
|
1725
|
-
queuedLines.delete(id);
|
|
1726
|
-
seenLines.delete(id);
|
|
1727
|
-
return false;
|
|
1728
|
-
}
|
|
1729
1594
|
const line = {
|
|
1730
1595
|
id,
|
|
1731
1596
|
kind,
|
|
@@ -1762,49 +1627,6 @@ function hasClickClackReplyMedia(payload) {
|
|
|
1762
1627
|
function resolveClickClackAgentRunId(messageId) {
|
|
1763
1628
|
return CLICKCLACK_MESSAGE_ID_PATTERN.test(messageId) ? `${CHANNEL_ID$1}:${messageId}` : void 0;
|
|
1764
1629
|
}
|
|
1765
|
-
async function dispatchModelReply(params) {
|
|
1766
|
-
const runtime = getClickClackRuntime();
|
|
1767
|
-
const result = await runtime.llm.complete({
|
|
1768
|
-
agentId: params.route.agentId,
|
|
1769
|
-
model: params.account.model,
|
|
1770
|
-
purpose: "clickclack bot reply",
|
|
1771
|
-
systemPrompt: params.account.systemPrompt,
|
|
1772
|
-
messages: [{
|
|
1773
|
-
role: "user",
|
|
1774
|
-
content: params.message.body
|
|
1775
|
-
}]
|
|
1776
|
-
});
|
|
1777
|
-
const completion = result.text.trim();
|
|
1778
|
-
if (!completion) {
|
|
1779
|
-
runtime.logging.getChildLogger({
|
|
1780
|
-
plugin: "clickclack",
|
|
1781
|
-
feature: "model-reply"
|
|
1782
|
-
}).warn(`[${params.account.accountId}] ClickClack model reply produced no sendable text`);
|
|
1783
|
-
return;
|
|
1784
|
-
}
|
|
1785
|
-
const replyPipeline = createChannelMessageReplyPipeline({
|
|
1786
|
-
cfg: params.cfg,
|
|
1787
|
-
agentId: params.route.agentId,
|
|
1788
|
-
channel: CHANNEL_ID$1,
|
|
1789
|
-
accountId: params.account.accountId
|
|
1790
|
-
});
|
|
1791
|
-
replyPipeline.onModelSelected?.({
|
|
1792
|
-
provider: result.provider,
|
|
1793
|
-
model: result.model,
|
|
1794
|
-
thinkLevel: void 0
|
|
1795
|
-
});
|
|
1796
|
-
const responsePrefix = replyPipeline.resolveResponsePrefix?.();
|
|
1797
|
-
const text = responsePrefix && !completion.startsWith(responsePrefix) ? `${responsePrefix} ${completion}` : completion;
|
|
1798
|
-
await sendClickClackText({
|
|
1799
|
-
cfg: params.cfg,
|
|
1800
|
-
accountId: params.account.accountId,
|
|
1801
|
-
to: params.target,
|
|
1802
|
-
text,
|
|
1803
|
-
threadId: params.message.parent_message_id ? params.message.thread_root_id : void 0,
|
|
1804
|
-
replyToId: params.message.id,
|
|
1805
|
-
correlationId: params.correlationId
|
|
1806
|
-
});
|
|
1807
|
-
}
|
|
1808
1630
|
async function handleClickClackInbound(params) {
|
|
1809
1631
|
const runtime = getClickClackRuntime();
|
|
1810
1632
|
const message = params.message;
|
|
@@ -1831,7 +1653,7 @@ async function handleClickClackInbound(params) {
|
|
|
1831
1653
|
conversationId
|
|
1832
1654
|
},
|
|
1833
1655
|
turnId: message.id,
|
|
1834
|
-
agentLabel: params.account.name
|
|
1656
|
+
agentLabel: params.account.name || params.account.botHandle?.trim() || params.account.agentId || params.account.accountId,
|
|
1835
1657
|
onError: (error) => {
|
|
1836
1658
|
runtime.logging.getChildLogger({
|
|
1837
1659
|
plugin: "clickclack",
|
|
@@ -1852,13 +1674,49 @@ async function handleClickClackInbound(params) {
|
|
|
1852
1674
|
}
|
|
1853
1675
|
progress?.start();
|
|
1854
1676
|
try {
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1677
|
+
const modelAccount = params.account;
|
|
1678
|
+
const modelConfig = params.config;
|
|
1679
|
+
const correlationId = params.correlationId;
|
|
1680
|
+
const modelRuntime = getClickClackRuntime();
|
|
1681
|
+
const result = await modelRuntime.llm.complete({
|
|
1682
|
+
agentId: route.agentId,
|
|
1683
|
+
model: modelAccount.model,
|
|
1684
|
+
purpose: "clickclack bot reply",
|
|
1685
|
+
systemPrompt: modelAccount.systemPrompt,
|
|
1686
|
+
messages: [{
|
|
1687
|
+
role: "user",
|
|
1688
|
+
content: message.body
|
|
1689
|
+
}]
|
|
1690
|
+
});
|
|
1691
|
+
const completion = result.text.trim();
|
|
1692
|
+
if (!completion) {
|
|
1693
|
+
modelRuntime.logging.getChildLogger({
|
|
1694
|
+
plugin: "clickclack",
|
|
1695
|
+
feature: "model-reply"
|
|
1696
|
+
}).warn(`[${modelAccount.accountId}] ClickClack model reply produced no sendable text`);
|
|
1697
|
+
return;
|
|
1698
|
+
}
|
|
1699
|
+
const replyPipeline = createChannelMessageReplyPipeline({
|
|
1700
|
+
cfg: modelConfig,
|
|
1701
|
+
agentId: route.agentId,
|
|
1702
|
+
channel: CHANNEL_ID$1,
|
|
1703
|
+
accountId: modelAccount.accountId
|
|
1704
|
+
});
|
|
1705
|
+
replyPipeline.onModelSelected?.({
|
|
1706
|
+
provider: result.provider,
|
|
1707
|
+
model: result.model,
|
|
1708
|
+
thinkLevel: void 0
|
|
1709
|
+
});
|
|
1710
|
+
const responsePrefix = replyPipeline.resolveResponsePrefix?.();
|
|
1711
|
+
const text = responsePrefix && !completion.startsWith(responsePrefix) ? `${responsePrefix} ${completion}` : completion;
|
|
1712
|
+
await sendClickClackText({
|
|
1713
|
+
cfg: modelConfig,
|
|
1714
|
+
accountId: modelAccount.accountId,
|
|
1715
|
+
to: target,
|
|
1716
|
+
text,
|
|
1717
|
+
threadId: message.parent_message_id ? message.thread_root_id : void 0,
|
|
1718
|
+
replyToId: message.id,
|
|
1719
|
+
correlationId
|
|
1862
1720
|
});
|
|
1863
1721
|
} finally {
|
|
1864
1722
|
await progress?.finalize();
|
|
@@ -2025,6 +1883,37 @@ async function handleClickClackInbound(params) {
|
|
|
2025
1883
|
}
|
|
2026
1884
|
// extensions/clickclack/src/gateway.ts
|
|
2027
1885
|
const CLICKCLACK_EVENT_PAGE_LIMIT = 500;
|
|
1886
|
+
const CLICKCLACK_COMMAND_PATTERN = /^[a-z0-9_-]{1,32}$/u;
|
|
1887
|
+
const CLICKCLACK_MAX_COMMANDS = 100;
|
|
1888
|
+
const CLICKCLACK_MAX_DESCRIPTION_LENGTH = 100;
|
|
1889
|
+
const CLICKCLACK_MAX_ARGS_HINT_LENGTH = 100;
|
|
1890
|
+
function commandArgsHint(spec) {
|
|
1891
|
+
if (spec.args?.length) return truncateCodePoints(spec.args.map((arg) => arg.required ? `<${arg.name}>` : `[${arg.name}]`).join(" "), CLICKCLACK_MAX_ARGS_HINT_LENGTH);
|
|
1892
|
+
return spec.acceptsArgs ? "[args]" : "";
|
|
1893
|
+
}
|
|
1894
|
+
function mapNativeCommandSpecsToClickClackMenu(specs, log) {
|
|
1895
|
+
const commands = [];
|
|
1896
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1897
|
+
const invalidNames = /* @__PURE__ */ new Set();
|
|
1898
|
+
for (const spec of specs) {
|
|
1899
|
+
if (spec.isAlias) continue;
|
|
1900
|
+
const command = spec.name.trim().toLowerCase();
|
|
1901
|
+
if (!CLICKCLACK_COMMAND_PATTERN.test(command)) {
|
|
1902
|
+
invalidNames.add(spec.name.trim() || "<empty>");
|
|
1903
|
+
continue;
|
|
1904
|
+
}
|
|
1905
|
+
if (seen.has(command)) continue;
|
|
1906
|
+
seen.add(command);
|
|
1907
|
+
const description = spec.description.trim() || command;
|
|
1908
|
+
commands.push({
|
|
1909
|
+
command,
|
|
1910
|
+
description: truncateCodePoints(description, CLICKCLACK_MAX_DESCRIPTION_LENGTH),
|
|
1911
|
+
args_hint: commandArgsHint(spec)
|
|
1912
|
+
});
|
|
1913
|
+
}
|
|
1914
|
+
if (invalidNames.size > 0) log?.warn?.(`ClickClack command menu skipped invalid native command names: ${[...invalidNames].map((name) => JSON.stringify(name)).join(", ")}`);
|
|
1915
|
+
return commands.slice(0, CLICKCLACK_MAX_COMMANDS);
|
|
1916
|
+
}
|
|
2028
1917
|
function payloadString(event, key) {
|
|
2029
1918
|
return readStringField(event.payload, key) ?? "";
|
|
2030
1919
|
}
|
|
@@ -2038,66 +1927,6 @@ async function resolveEventMessage(params) {
|
|
|
2038
1927
|
throw error;
|
|
2039
1928
|
}
|
|
2040
1929
|
}
|
|
2041
|
-
function parseSocketEvent(data) {
|
|
2042
|
-
try {
|
|
2043
|
-
return JSON.parse(rawDataToString(data));
|
|
2044
|
-
} catch {
|
|
2045
|
-
return null;
|
|
2046
|
-
}
|
|
2047
|
-
}
|
|
2048
|
-
async function processEvent(params) {
|
|
2049
|
-
if (params.event.type !== "message.created" && params.event.type !== "thread.reply_created") return;
|
|
2050
|
-
if (params.abortSignal.aborted || payloadString(params.event, "author_id") === params.botUserId) return;
|
|
2051
|
-
const correlationId = normalizeClickClackCorrelationId(params.event.payload?.correlation_id);
|
|
2052
|
-
const message = await resolveEventMessage({
|
|
2053
|
-
client: correlationId ? createClickClackClient({
|
|
2054
|
-
baseUrl: params.account.apiEndpoint,
|
|
2055
|
-
token: params.account.token,
|
|
2056
|
-
correlationId
|
|
2057
|
-
}) : params.client,
|
|
2058
|
-
event: params.event
|
|
2059
|
-
});
|
|
2060
|
-
if (!message) {
|
|
2061
|
-
params.log?.warn?.(`[${params.account.accountId}] skipped unreadable ClickClack message before agent dispatch: type=${params.event.type} messageId=${payloadString(params.event, "message_id") || "unknown"}`);
|
|
2062
|
-
return;
|
|
2063
|
-
}
|
|
2064
|
-
if (params.abortSignal.aborted || message.author_id === params.botUserId) return;
|
|
2065
|
-
const access = await resolveClickClackInboundAccess({
|
|
2066
|
-
account: params.account,
|
|
2067
|
-
config: params.config,
|
|
2068
|
-
message
|
|
2069
|
-
});
|
|
2070
|
-
if (params.abortSignal.aborted) return;
|
|
2071
|
-
if (!access.shouldDispatch) {
|
|
2072
|
-
params.log?.info(`[${params.account.accountId}] skipped ClickClack message before agent dispatch: kind=${message.direct_conversation_id ? "dm" : "group"} requireMention=${access.requireMention ?? "unknown"} wasMentioned=${access.mentionFacts.wasMentioned} hasAnyMention=${access.mentionFacts.hasAnyMention ?? "unknown"} commandAuthorized=${access.commandAuthorized}`);
|
|
2073
|
-
return;
|
|
2074
|
-
}
|
|
2075
|
-
await handleClickClackInbound({
|
|
2076
|
-
account: params.account,
|
|
2077
|
-
config: params.config,
|
|
2078
|
-
message,
|
|
2079
|
-
access,
|
|
2080
|
-
buildContext: params.buildContext,
|
|
2081
|
-
...correlationId ? { correlationId } : {}
|
|
2082
|
-
});
|
|
2083
|
-
}
|
|
2084
|
-
async function drainEventBacklog(params) {
|
|
2085
|
-
let afterCursor = params.afterCursor;
|
|
2086
|
-
while (!params.abortSignal.aborted) {
|
|
2087
|
-
const page = await params.client.eventPage(params.workspaceId, {
|
|
2088
|
-
afterCursor,
|
|
2089
|
-
limit: CLICKCLACK_EVENT_PAGE_LIMIT
|
|
2090
|
-
});
|
|
2091
|
-
for (const event of page.events) {
|
|
2092
|
-
if (params.abortSignal.aborted) return afterCursor;
|
|
2093
|
-
if (!event.cursor || event.cursor === afterCursor) throw new Error("ClickClack event backlog returned a non-advancing cursor");
|
|
2094
|
-
await params.onEvent(event);
|
|
2095
|
-
afterCursor = event.cursor;
|
|
2096
|
-
}
|
|
2097
|
-
if (page.events.length === 0) return afterCursor;
|
|
2098
|
-
}
|
|
2099
|
-
return afterCursor;
|
|
2100
|
-
}
|
|
2101
1930
|
async function startClickClackGatewayAccount(ctx) {
|
|
2102
1931
|
const configuredAccount = resolveClickClackAccount({
|
|
2103
1932
|
cfg: ctx.cfg,
|
|
@@ -2116,22 +1945,55 @@ async function startClickClackGatewayAccount(ctx) {
|
|
|
2116
1945
|
botUserId: configuredAccount.botUserId ?? me.id,
|
|
2117
1946
|
botHandle: me.handle
|
|
2118
1947
|
};
|
|
2119
|
-
const processIncomingEvent = (event) =>
|
|
2120
|
-
abortSignal: ctx
|
|
2121
|
-
account
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
event,
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
1948
|
+
const processIncomingEvent = async (event) => {
|
|
1949
|
+
const { abortSignal, cfg: config, log } = ctx;
|
|
1950
|
+
const botUserId = account.botUserId;
|
|
1951
|
+
const buildContext = ctx.channelRuntime?.inbound.buildContext;
|
|
1952
|
+
if (event.type !== "message.created" && event.type !== "thread.reply_created") return;
|
|
1953
|
+
if (abortSignal.aborted || payloadString(event, "author_id") === botUserId) return;
|
|
1954
|
+
const correlationId = normalizeClickClackCorrelationId(event.payload?.correlation_id);
|
|
1955
|
+
const message = await resolveEventMessage({
|
|
1956
|
+
client: correlationId ? createClickClackClient({
|
|
1957
|
+
baseUrl: account.apiEndpoint,
|
|
1958
|
+
token: account.token,
|
|
1959
|
+
correlationId
|
|
1960
|
+
}) : client,
|
|
1961
|
+
event
|
|
1962
|
+
});
|
|
1963
|
+
if (!message) {
|
|
1964
|
+
log?.warn?.(`[${account.accountId}] skipped unreadable ClickClack message before agent dispatch: type=${event.type} messageId=${payloadString(event, "message_id") || "unknown"}`);
|
|
1965
|
+
return;
|
|
1966
|
+
}
|
|
1967
|
+
if (abortSignal.aborted || message.author_id === botUserId) return;
|
|
1968
|
+
const access = await resolveClickClackInboundAccess({
|
|
1969
|
+
account,
|
|
1970
|
+
config,
|
|
1971
|
+
message
|
|
1972
|
+
});
|
|
1973
|
+
if (abortSignal.aborted) return;
|
|
1974
|
+
if (!access.shouldDispatch) {
|
|
1975
|
+
log?.info(`[${account.accountId}] skipped ClickClack message before agent dispatch: kind=${message.direct_conversation_id ? "dm" : "group"} requireMention=${access.requireMention ?? "unknown"} wasMentioned=${access.mentionFacts.wasMentioned} hasAnyMention=${access.mentionFacts.hasAnyMention ?? "unknown"} commandAuthorized=${access.commandAuthorized}`);
|
|
1976
|
+
return;
|
|
1977
|
+
}
|
|
1978
|
+
await handleClickClackInbound({
|
|
1979
|
+
account,
|
|
1980
|
+
config,
|
|
1981
|
+
message,
|
|
1982
|
+
access,
|
|
1983
|
+
buildContext,
|
|
1984
|
+
...correlationId ? { correlationId } : {}
|
|
1985
|
+
});
|
|
1986
|
+
};
|
|
1987
|
+
if (account.commandMenu) try {
|
|
1988
|
+
const commands = mapNativeCommandSpecsToClickClackMenu(listNativeCommandSpecsForConfig(ctx.cfg, { provider: "clickclack" }), ctx.log);
|
|
1989
|
+
await client.setBotCommands(commands);
|
|
1990
|
+
} catch (error) {
|
|
1991
|
+
const status = error instanceof ClickClackHttpError ? error.status : void 0;
|
|
1992
|
+
const messagePrefix = `[${account.accountId}] ClickClack command menu sync`;
|
|
1993
|
+
if (status === 403) ctx.log?.warn?.(`${messagePrefix} skipped: ${formatErrorMessage(error)}; verify token/workspace command permissions or set commandMenu: false if menus are not needed`);
|
|
1994
|
+
else if (status === 404) ctx.log?.debug?.(`${messagePrefix} skipped: server does not support /api/bots/self/commands`);
|
|
1995
|
+
else ctx.log?.warn?.(`${messagePrefix} failed: ${formatErrorMessage(error)}`);
|
|
1996
|
+
}
|
|
2135
1997
|
ctx.setStatus({
|
|
2136
1998
|
accountId: account.accountId,
|
|
2137
1999
|
running: true,
|
|
@@ -2149,13 +2011,19 @@ async function startClickClackGatewayAccount(ctx) {
|
|
|
2149
2011
|
if (page.tailCursor !== void 0) afterCursor = page.tailCursor;
|
|
2150
2012
|
else for (const event of page.events) afterCursor = event.cursor || afterCursor;
|
|
2151
2013
|
initialized = true;
|
|
2152
|
-
} else
|
|
2153
|
-
client,
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2014
|
+
} else while (!ctx.abortSignal.aborted) {
|
|
2015
|
+
const page = await client.eventPage(workspaceId, {
|
|
2016
|
+
afterCursor,
|
|
2017
|
+
limit: CLICKCLACK_EVENT_PAGE_LIMIT
|
|
2018
|
+
});
|
|
2019
|
+
for (const event of page.events) {
|
|
2020
|
+
if (ctx.abortSignal.aborted) break;
|
|
2021
|
+
if (!event.cursor || event.cursor === afterCursor) throw new Error("ClickClack event backlog returned a non-advancing cursor");
|
|
2022
|
+
await processIncomingEvent(event);
|
|
2023
|
+
afterCursor = event.cursor;
|
|
2024
|
+
}
|
|
2025
|
+
if (page.events.length === 0) break;
|
|
2026
|
+
}
|
|
2159
2027
|
if (ctx.abortSignal.aborted) break;
|
|
2160
2028
|
const socket = client.websocket(workspaceId, afterCursor);
|
|
2161
2029
|
await new Promise((resolve) => {
|
|
@@ -2164,9 +2032,11 @@ async function startClickClackGatewayAccount(ctx) {
|
|
|
2164
2032
|
let loggedMessageFailure = false;
|
|
2165
2033
|
let messageQueue = Promise.resolve();
|
|
2166
2034
|
let removeAbortListener;
|
|
2035
|
+
let stopKeepalive;
|
|
2167
2036
|
const finishSocketCycle = () => {
|
|
2168
2037
|
if (settled) return;
|
|
2169
2038
|
settled = true;
|
|
2039
|
+
stopKeepalive?.();
|
|
2170
2040
|
removeAbortListener?.();
|
|
2171
2041
|
removeAbortListener = void 0;
|
|
2172
2042
|
resolve();
|
|
@@ -2193,12 +2063,16 @@ async function startClickClackGatewayAccount(ctx) {
|
|
|
2193
2063
|
removeAbortListener = () => ctx.abortSignal.removeEventListener("abort", abort);
|
|
2194
2064
|
socket.on("open", () => {
|
|
2195
2065
|
ctx.setStatus(channelReadyPatch({ accountId: account.accountId }));
|
|
2066
|
+
stopKeepalive = startWebSocketKeepalive(socket, () => {
|
|
2067
|
+
ctx.log?.warn?.(`[${account.accountId}] ClickClack websocket heartbeat timed out; reconnecting`);
|
|
2068
|
+
socket.terminate();
|
|
2069
|
+
});
|
|
2196
2070
|
});
|
|
2197
2071
|
socket.on("message", (data) => {
|
|
2198
2072
|
if (closing || settled) return;
|
|
2199
2073
|
messageQueue = messageQueue.then(async () => {
|
|
2200
2074
|
if (ctx.abortSignal.aborted) return;
|
|
2201
|
-
const event =
|
|
2075
|
+
const event = safeParseJson(rawDataToString(data));
|
|
2202
2076
|
if (!event) {
|
|
2203
2077
|
ctx.log?.warn?.(`[${account.accountId}] skipped malformed ClickClack websocket event`);
|
|
2204
2078
|
return;
|
|
@@ -2246,6 +2120,10 @@ async function startClickClackGatewayAccount(ctx) {
|
|
|
2246
2120
|
}
|
|
2247
2121
|
// extensions/clickclack/src/channel.ts
|
|
2248
2122
|
const CHANNEL_ID = CLICKCLACK_CHANNEL_ID;
|
|
2123
|
+
const clickClackTextMessageAdapter = createChannelMessageAdapterFromOutbound({ outbound: { sendText: async (ctx) => ({
|
|
2124
|
+
channel: CHANNEL_ID,
|
|
2125
|
+
...await sendClickClackText(ctx)
|
|
2126
|
+
}) } });
|
|
2249
2127
|
const clickClackMessageAdapter = defineChannelMessageAdapter({
|
|
2250
2128
|
id: CHANNEL_ID,
|
|
2251
2129
|
durableFinal: {
|
|
@@ -2264,26 +2142,7 @@ const clickClackMessageAdapter = defineChannelMessageAdapter({
|
|
|
2264
2142
|
reconcileUnknownSend: reconcileClickClackUnknownSend
|
|
2265
2143
|
},
|
|
2266
2144
|
send: {
|
|
2267
|
-
|
|
2268
|
-
const result = await sendClickClackText({
|
|
2269
|
-
...ctx,
|
|
2270
|
-
cfg: ctx.cfg
|
|
2271
|
-
});
|
|
2272
|
-
const threadId = ctx.threadId == null ? void 0 : String(ctx.threadId);
|
|
2273
|
-
const replyToId = ctx.replyToId ?? void 0;
|
|
2274
|
-
return {
|
|
2275
|
-
...result,
|
|
2276
|
-
receipt: createMessageReceiptFromOutboundResults({
|
|
2277
|
-
results: "messageId" in result ? [{
|
|
2278
|
-
channel: CHANNEL_ID,
|
|
2279
|
-
messageId: result.messageId
|
|
2280
|
-
}] : [],
|
|
2281
|
-
threadId,
|
|
2282
|
-
replyToId,
|
|
2283
|
-
kind: "text"
|
|
2284
|
-
})
|
|
2285
|
-
};
|
|
2286
|
-
},
|
|
2145
|
+
...clickClackTextMessageAdapter.send,
|
|
2287
2146
|
media: async (ctx) => {
|
|
2288
2147
|
const messageId = await sendClickClackMedia({
|
|
2289
2148
|
...ctx,
|
|
@@ -2327,10 +2186,10 @@ const clickClackPlugin = createChatChannelPlugin({
|
|
|
2327
2186
|
},
|
|
2328
2187
|
messaging: {
|
|
2329
2188
|
targetPrefixes: ["clickclack", "cc"],
|
|
2330
|
-
normalizeTarget:
|
|
2189
|
+
normalizeTarget: (raw) => buildClickClackTarget(parseClickClackTarget(raw)),
|
|
2331
2190
|
inferTargetChatType: ({ to }) => parseClickClackTarget(to).chatType,
|
|
2332
2191
|
targetResolver: {
|
|
2333
|
-
looksLikeId:
|
|
2192
|
+
looksLikeId: (raw) => raw.trim().length > 0,
|
|
2334
2193
|
hint: "<channel:name|dm:usr_id|thread:msg_id>"
|
|
2335
2194
|
},
|
|
2336
2195
|
resolveOutboundSessionRoute: ({ cfg, agentId, accountId, target, replyToId, threadId, currentSessionKey }) => {
|
|
@@ -2419,4 +2278,4 @@ const clickClackPlugin = createChatChannelPlugin({
|
|
|
2419
2278
|
}
|
|
2420
2279
|
}
|
|
2421
2280
|
});
|
|
2422
|
-
export { clearPendingDiscussionOpen as A,
|
|
2281
|
+
export { clearPendingDiscussionOpen as A, slugifyDiscussionLabel as C, getClickClackDiscussionBindingStore as D, bindingMatchesActiveSessionIncarnation as E, listPendingDiscussionOpens as M, recordPendingDiscussionOpen as N, readDiscussionSessionEntry as O, reserveDiscussionBindingGeneration as P, resolveDiscussionLabel as S, attachBindingToCurrentActiveSession as T, discussionCredentialFingerprint as _, setClickClackRuntime as a, fallbackDiscussionLabel as b, isClickClackDiscussionChannelRevoked as c, markClickClackDiscussionChannelRevoked as d, prepareClickClackDiscussionChannelRevocation as f, resolveDiscussionBindingAccount as g, normalizedServerBaseUrl as h, getClickClackRuntime as i, getPendingDiscussionOpen as j, clearDiscussionBindingGeneration as k, isClickClackDiscussionChannelRevokedAsync as l, discussionInfoForBinding as m, buildClickClackTarget as n, prepareDiscussionSessionEntry as o, discussionAccounts as p, parseClickClackTarget as r, clearClickClackDiscussionChannelRevoked as s, clickClackPlugin as t, markClickClackDiscussionChannelIdentityRevoked as u, discussionExternalRef as v, truncateDiscussionDisplayTitle as w, isDiscussionSessionKey as x, discussionSessionKey as y };
|