hyperclaw 5.2.7 → 5.2.9

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.
Files changed (207) hide show
  1. package/dist/a2ui-protocol-DEsfqO7h.js +75 -0
  2. package/dist/agents-routing-Cee7wrfi.js +398 -0
  3. package/dist/agents-routing-ChorJKFL.js +6 -0
  4. package/dist/agents-routing-Cpg20-1e.js +398 -0
  5. package/dist/agents-routing-uNzqjgOr.js +6 -0
  6. package/dist/api-key-validation-DgOBmp8Y.js +64 -0
  7. package/dist/api-key-validation-DydlUth1.js +64 -0
  8. package/dist/api-keys-guide--73Bq0Ey.js +149 -0
  9. package/dist/api-keys-guide-DqRGa4x7.js +149 -0
  10. package/dist/audit-CX5poVMR.js +445 -0
  11. package/dist/audit-Dntx9fG9.js +445 -0
  12. package/dist/banner-B_rR7FPO.js +7 -0
  13. package/dist/banner-Bb7CderS.js +143 -0
  14. package/dist/bounty-tools-BoU1NN5N.js +211 -0
  15. package/dist/bounty-tools-Dn9Yq7V1.js +211 -0
  16. package/dist/browser-tools-CJ9M9o22.js +179 -0
  17. package/dist/browser-tools-CXxWxA1c.js +5 -0
  18. package/dist/chat-C07wF0mM.js +494 -0
  19. package/dist/chat-D1Zc73I5.js +513 -0
  20. package/dist/claw-tasks-BLqd1a0Q.js +80 -0
  21. package/dist/claw-tasks-ChqkHdFs.js +80 -0
  22. package/dist/config-BlLlJ6Er.js +7 -0
  23. package/dist/config-Bzues-G2.js +7 -0
  24. package/dist/config-DGAAJ49A.js +261 -0
  25. package/dist/config-SgDxKyfV.js +261 -0
  26. package/dist/connector-1efnZgQN.js +566 -0
  27. package/dist/connector-B5q1_srT.js +286 -0
  28. package/dist/connector-BMFLJ4fr.js +508 -0
  29. package/dist/connector-BZYv9siY.js +189 -0
  30. package/dist/connector-B_XkXm-j.js +218 -0
  31. package/dist/connector-BkY1I6gf.js +189 -0
  32. package/dist/connector-C2Z3RN1z.js +350 -0
  33. package/dist/connector-C7aYvVzU.js +225 -0
  34. package/dist/connector-CXXYOyHw.js +164 -0
  35. package/dist/connector-Ca1J23HX.js +167 -0
  36. package/dist/connector-Cjqc656I.js +181 -0
  37. package/dist/connector-CluRienN.js +425 -0
  38. package/dist/connector-CuNz2eP-.js +305 -0
  39. package/dist/connector-DHL_oeHy.js +552 -0
  40. package/dist/connector-DJ79rd1L.js +173 -0
  41. package/dist/connector-DcLE6xCZ.js +239 -0
  42. package/dist/connector-DcyQTJnJ.js +162 -0
  43. package/dist/connector-DgyX9qSc.js +192 -0
  44. package/dist/connector-DnDXXZ7L.js +182 -0
  45. package/dist/connector-DqUslg-X.js +213 -0
  46. package/dist/connector-Duc-HmRZ.js +85 -0
  47. package/dist/connector-IV0QFer8.js +498 -0
  48. package/dist/connector-OnsLxE8G.js +194 -0
  49. package/dist/connector-UYu_TS0X.js +204 -0
  50. package/dist/connector-cCA5ffmp.js +340 -0
  51. package/dist/connector-fbNfx4_L.js +568 -0
  52. package/dist/connector-fi2vlwbO.js +276 -0
  53. package/dist/connector-l3LD8IDN.js +419 -0
  54. package/dist/cost-tracker-CgEXyEtz.js +103 -0
  55. package/dist/cost-tracker-DCXDUzBI.js +103 -0
  56. package/dist/credentials-store-1LDtNReY.js +89 -0
  57. package/dist/credentials-store-BFxEJR00.js +7 -0
  58. package/dist/credentials-store-Bmm9e1SS.js +7 -0
  59. package/dist/credentials-store-D8ERbGR2.js +89 -0
  60. package/dist/cron-tasks-1E6wKpTv.js +85 -0
  61. package/dist/cron-tasks-OQbgmenS.js +85 -0
  62. package/dist/daemon-B13UIqvL.js +7 -0
  63. package/dist/daemon-CzOW-1PS.js +421 -0
  64. package/dist/daemon-aVX-WGz1.js +421 -0
  65. package/dist/daemon-iFmVBPXN.js +7 -0
  66. package/dist/delivery-B8YGmrq5.js +4 -0
  67. package/dist/delivery-DWsU6gx-.js +95 -0
  68. package/dist/delivery-Pko6sSkt.js +4 -0
  69. package/dist/delivery-hMHFRZwy.js +95 -0
  70. package/dist/destructive-gate-C2TrWsp2.js +101 -0
  71. package/dist/destructive-gate-bnkroJWG.js +101 -0
  72. package/dist/developer-keys-BWXHaWxY.js +127 -0
  73. package/dist/developer-keys-CzDxVczE.js +8 -0
  74. package/dist/device-auth-store-C1bCwXO2.js +7 -0
  75. package/dist/device-auth-store-DIZTOz4V.js +88 -0
  76. package/dist/doctor-C6nAGdH8.js +233 -0
  77. package/dist/doctor-mgWumA25.js +6 -0
  78. package/dist/engine-BGRTi0fo.js +327 -0
  79. package/dist/engine-BvCEhaUn.js +7 -0
  80. package/dist/engine-ByQ-0sWM.js +7 -0
  81. package/dist/engine-gnMjO743.js +327 -0
  82. package/dist/env-resolve-BdagnXhK.js +151 -0
  83. package/dist/env-resolve-CHxjGo8u.js +151 -0
  84. package/dist/env-resolve-NEtsGacw.js +10 -0
  85. package/dist/env-resolve-pIETNTpQ.js +10 -0
  86. package/dist/extraction-tools-BE6z_Yw5.js +91 -0
  87. package/dist/extraction-tools-CJsdyBST.js +5 -0
  88. package/dist/form_data-B2_0EoWj.js +8657 -0
  89. package/dist/gmail-watch-setup-1RGIHNdu.js +42 -0
  90. package/dist/gmail-watch-setup-Brkj94Sy.js +42 -0
  91. package/dist/health-BMUmUNoe.js +152 -0
  92. package/dist/health-C8n9RH5O.js +6 -0
  93. package/dist/heartbeat-engine-D6oSpgxx.js +89 -0
  94. package/dist/heartbeat-engine-aRbab8a5.js +89 -0
  95. package/dist/hub-BJM2KXLO.js +6 -0
  96. package/dist/hub-Bb_dYECE.js +512 -0
  97. package/dist/hyperclawbot-CgrV46DA.js +516 -0
  98. package/dist/hyperclawbot-DzP_v3iA.js +516 -0
  99. package/dist/inference-BHJFPEKL.js +8 -0
  100. package/dist/inference-CFBkvLpE.js +2854 -0
  101. package/dist/inference-G4MbdErG.js +8 -0
  102. package/dist/inference-vweXyh27.js +2854 -0
  103. package/dist/knowledge-graph-9UNrsiIY.js +134 -0
  104. package/dist/knowledge-graph-yeMPBPP8.js +134 -0
  105. package/dist/loader-BXYJl25e.js +6 -0
  106. package/dist/loader-DIPs649t.js +410 -0
  107. package/dist/loader-Dq_cDlOW.js +6 -0
  108. package/dist/loader-gTdKBwiI.js +410 -0
  109. package/dist/logger-C3ZCDSkc.js +86 -0
  110. package/dist/logger-CG38Idq4.js +86 -0
  111. package/dist/manager--wG9JdFW.js +120 -0
  112. package/dist/manager-BI3izlRG.js +120 -0
  113. package/dist/manager-BNc21xgG.js +6 -0
  114. package/dist/manager-CQ3MWNHY.js +250 -0
  115. package/dist/manager-DWJ7WZcY.js +250 -0
  116. package/dist/manager-DYfzqckn.js +35 -0
  117. package/dist/mcp-CklaYr_6.js +142 -0
  118. package/dist/mcp-SsMEvl28.js +142 -0
  119. package/dist/mcp-loader-9v8eUsNI.js +93 -0
  120. package/dist/mcp-loader-DLrp_oZJ.js +93 -0
  121. package/dist/memory-BCYvdqwo.js +273 -0
  122. package/dist/memory-BGgCBSx1.js +6 -0
  123. package/dist/memory-auto-Bh52cQJP.js +5 -0
  124. package/dist/memory-auto-Bow9u_L7.js +306 -0
  125. package/dist/memory-auto-BupvVwNd.js +306 -0
  126. package/dist/memory-auto-CgBAI8mm.js +5 -0
  127. package/dist/memory-integration-4oGqX6rr.js +91 -0
  128. package/dist/memory-integration-CveUEI3V.js +91 -0
  129. package/dist/moltbook-B3DNdh40.js +81 -0
  130. package/dist/moltbook-xP7VXKlX.js +81 -0
  131. package/dist/node-C4esBfbX.js +226 -0
  132. package/dist/node-urDjajMt.js +226 -0
  133. package/dist/nodes-registry-Cd4eWw80.js +52 -0
  134. package/dist/nodes-registry-DLUZhEMS.js +52 -0
  135. package/dist/oauth-flow-BbLQTzZk.js +148 -0
  136. package/dist/oauth-flow-Bt-LaRHV.js +148 -0
  137. package/dist/oauth-provider-CVTKgj35.js +111 -0
  138. package/dist/oauth-provider-UZyG84s7.js +111 -0
  139. package/dist/observability-BtLyuxcz.js +89 -0
  140. package/dist/observability-lwYm4aoB.js +89 -0
  141. package/dist/onboard-B3drurt-.js +3812 -0
  142. package/dist/onboard-BV5Poocl.js +13 -0
  143. package/dist/onboard-DEwuHrMj.js +14 -0
  144. package/dist/onboard-UiynbNQy.js +3909 -0
  145. package/dist/orchestrator-BXyIgAeH.js +189 -0
  146. package/dist/orchestrator-DMZkAVa5.js +189 -0
  147. package/dist/orchestrator-MLTc4NYu.js +6 -0
  148. package/dist/orchestrator-rVGu7yYr.js +6 -0
  149. package/dist/osint-Bsf6RGPv.js +283 -0
  150. package/dist/osint-chat-Ark94iFc.js +789 -0
  151. package/dist/osint-chat-Hn8qpsC1.js +836 -0
  152. package/dist/osint-f9DeXT6j.js +283 -0
  153. package/dist/pairing-2vAiDBjN.js +6 -0
  154. package/dist/pairing-B4NoBvyE.js +207 -0
  155. package/dist/pc-access-BLnc-DYp.js +858 -0
  156. package/dist/pc-access-CTNtG2LD.js +8 -0
  157. package/dist/pending-approval-C4ZaHHWl.js +22 -0
  158. package/dist/pending-approval-CHUZ_qT6.js +22 -0
  159. package/dist/reminders-store-BixTWL1h.js +58 -0
  160. package/dist/renderer-B1ToXngl.js +228 -0
  161. package/dist/rules-Cqen1Mpt.js +106 -0
  162. package/dist/run-main.js +98 -94
  163. package/dist/runner-B9xANekJ.js +1274 -0
  164. package/dist/runner-Cr1_mwnU.js +1274 -0
  165. package/dist/security--17Fxo5Z.js +4 -0
  166. package/dist/security-B4vH02lO.js +4 -0
  167. package/dist/security-DP1qtJfL.js +90 -0
  168. package/dist/security-HOOGCw5z.js +90 -0
  169. package/dist/server-CRhXiGI9.js +4 -0
  170. package/dist/server-DUDXqJSo.js +1365 -0
  171. package/dist/server-De4H45Ju.js +1365 -0
  172. package/dist/server-ha59nA8a.js +4 -0
  173. package/dist/session-store-7sEPyV16.js +5 -0
  174. package/dist/session-store-Ce2QMSL_.js +141 -0
  175. package/dist/sessions-tools-CWr_pDtp.js +5 -0
  176. package/dist/sessions-tools-DKVu9aIN.js +95 -0
  177. package/dist/skill-loader-DK19Jm4e.js +7 -0
  178. package/dist/skill-loader-Dfs9VNM-.js +160 -0
  179. package/dist/skill-runtime-BRp2D8Jb.js +5 -0
  180. package/dist/skill-runtime-BeKh2rD_.js +5 -0
  181. package/dist/skill-runtime-C8bNwKwz.js +104 -0
  182. package/dist/skill-runtime-CcpC2Zfc.js +104 -0
  183. package/dist/src-B8LzGLSY.js +63 -0
  184. package/dist/src-BxmkZ9RH.js +63 -0
  185. package/dist/src-DUoc6_kn.js +458 -0
  186. package/dist/src-DjTtmSRg.js +20 -0
  187. package/dist/src-n_46LPDi.js +458 -0
  188. package/dist/sub-agent-tools-CldaMfd5.js +39 -0
  189. package/dist/sub-agent-tools-q5JqEze_.js +39 -0
  190. package/dist/tool-policy-DtGf3Ifq.js +189 -0
  191. package/dist/tool-policy-QXF3MMxu.js +189 -0
  192. package/dist/tts-elevenlabs-1zWD3QJw.js +64 -0
  193. package/dist/tts-elevenlabs-y6HGWWDS.js +64 -0
  194. package/dist/update-check-C4te7JmY.js +6 -0
  195. package/dist/update-check-GDue_it1.js +98 -0
  196. package/dist/vision-DV2ubVjr.js +167 -0
  197. package/dist/vision-tools-Cb86uMdh.js +5 -0
  198. package/dist/vision-tools-CbVfyTZT.js +5 -0
  199. package/dist/vision-tools-DieVQp6s.js +51 -0
  200. package/dist/vision-tools-DlnxaZjg.js +51 -0
  201. package/dist/vision-u4kMThdo.js +167 -0
  202. package/dist/voice-transcription-BolTT_HG.js +170 -0
  203. package/dist/voice-transcription-DgON5qaF.js +170 -0
  204. package/dist/website-watch-tools-B8L_NgwT.js +5 -0
  205. package/dist/website-watch-tools-Drm5HjIX.js +176 -0
  206. package/package.json +4 -1
  207. package/static/chat.html +9 -3
@@ -0,0 +1,75 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+
3
+ //#region src/canvas/a2ui-protocol.ts
4
+ /** Map HyperClaw component type to A2UI-compatible type. */
5
+ function toA2UIType(t) {
6
+ const map = {
7
+ chart: "chart",
8
+ table: "table",
9
+ form: "form",
10
+ markdown: "markdown",
11
+ image: "image",
12
+ custom: "custom",
13
+ script: "script"
14
+ };
15
+ return map[t] || "custom";
16
+ }
17
+ /** Convert a CanvasComponent to A2UI surface. */
18
+ function componentToSurface(c) {
19
+ return {
20
+ id: c.id,
21
+ type: toA2UIType(c.type),
22
+ props: {
23
+ title: c.title,
24
+ width: c.width || "half"
25
+ },
26
+ data: c.data
27
+ };
28
+ }
29
+ /** Generate beginRendering from canvas state (full sync). */
30
+ function toBeginRendering(canvas) {
31
+ const surfaces = canvas.components.map(componentToSurface);
32
+ const dataModel = {};
33
+ for (const c of canvas.components) if (c.data != null) dataModel[c.id] = c.data;
34
+ return {
35
+ type: "beginRendering",
36
+ surfaceId: canvas.id,
37
+ surfaces,
38
+ dataModel: Object.keys(dataModel).length ? dataModel : void 0
39
+ };
40
+ }
41
+ /** Generate surfaceUpdate for newly added component. */
42
+ function toSurfaceUpdate(canvasId, component) {
43
+ return {
44
+ type: "surfaceUpdate",
45
+ surfaceId: canvasId,
46
+ surfaces: [componentToSurface(component)]
47
+ };
48
+ }
49
+ /** Generate dataModelUpdate when component data changes. */
50
+ function toDataModelUpdate(canvasId, componentId, data) {
51
+ return {
52
+ type: "dataModelUpdate",
53
+ surfaceId: canvasId,
54
+ updates: { [componentId]: data }
55
+ };
56
+ }
57
+ /** Generate deleteSurface for removed components. */
58
+ function toDeleteSurface(canvasId, componentIds) {
59
+ return {
60
+ type: "deleteSurface",
61
+ surfaceId: canvasId,
62
+ surfaceIds: componentIds
63
+ };
64
+ }
65
+ /** Serialize A2UI messages to JSONL (one message per line). */
66
+ function toJSONL(messages) {
67
+ return messages.map((m) => JSON.stringify(m)).join("\n");
68
+ }
69
+
70
+ //#endregion
71
+ exports.toBeginRendering = toBeginRendering;
72
+ exports.toDataModelUpdate = toDataModelUpdate;
73
+ exports.toDeleteSurface = toDeleteSurface;
74
+ exports.toJSONL = toJSONL;
75
+ exports.toSurfaceUpdate = toSurfaceUpdate;
@@ -0,0 +1,398 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const require_paths = require('./paths-AIyBxIzm.js');
3
+ const require_paths$1 = require('./paths-DPovhojT.js');
4
+ const chalk = require_chunk.__toESM(require("chalk"));
5
+ const inquirer = require_chunk.__toESM(require("inquirer"));
6
+ const fs_extra = require_chunk.__toESM(require("fs-extra"));
7
+ const path = require_chunk.__toESM(require("path"));
8
+
9
+ //#region src/routing/session-key.ts
10
+ /**
11
+
12
+ * Compute the canonical session key for an inbound message context.
13
+
14
+ */
15
+ function computeSessionKey(ctx) {
16
+ const { agentId, channel, peerKind, peerId, threadId, topicId, dmScope } = ctx;
17
+ if (peerKind === "dm") {
18
+ if (dmScope === "main" || dmScope === void 0) return `agent:${agentId}:main`;
19
+ return `agent:${agentId}:${channel}:dm:${peerId}`;
20
+ }
21
+ if (peerKind === "group") {
22
+ let key$1 = `agent:${agentId}:${channel}:group:${peerId}`;
23
+ if (topicId) key$1 += `:topic:${topicId}`;
24
+ if (threadId) key$1 += `:thread:${threadId}`;
25
+ return key$1;
26
+ }
27
+ let key = `agent:${agentId}:${channel}:channel:${peerId}`;
28
+ if (threadId) key += `:thread:${threadId}`;
29
+ return key;
30
+ }
31
+
32
+ //#endregion
33
+ //#region src/routing/agents-routing.ts
34
+ require_paths$1.init_paths();
35
+ function defaultAgent() {
36
+ const hcDir = require_paths.getHyperClawDir();
37
+ return {
38
+ id: "main",
39
+ name: "main",
40
+ workspace: path.default.join(hcDir, "workspace"),
41
+ default: true
42
+ };
43
+ }
44
+ var AgentRouter = class {
45
+ config;
46
+ constructor(config) {
47
+ this.config = config ?? this._loadConfig();
48
+ }
49
+ _loadConfig() {
50
+ const cfgPath = require_paths.getConfigPath();
51
+ const hcDir = require_paths.getHyperClawDir();
52
+ const routingFile = path.default.join(hcDir, "routing.json");
53
+ const legacyBindingsFile = path.default.join(hcDir, "agent-bindings.json");
54
+ let fromMain = false;
55
+ try {
56
+ const mainCfg = fs_extra.default.readJsonSync(cfgPath);
57
+ const bindings = mainCfg?.bindings;
58
+ const agentsList = mainCfg?.agents?.list;
59
+ if (Array.isArray(bindings) || Array.isArray(agentsList)) {
60
+ fromMain = true;
61
+ return {
62
+ agents: { list: agentsList && agentsList.length > 0 ? agentsList : [defaultAgent()] },
63
+ bindings: Array.isArray(bindings) ? bindings : [],
64
+ session: mainCfg?.session || { dmScope: "main" },
65
+ broadcast: mainCfg?.broadcast,
66
+ channels: mainCfg?.channels
67
+ };
68
+ }
69
+ } catch {}
70
+ try {
71
+ const legacy = fs_extra.default.readJsonSync(routingFile);
72
+ if (legacy?.bindings?.length || legacy?.agents?.list?.length) return this._migrateToMain(legacy, cfgPath);
73
+ } catch {}
74
+ try {
75
+ const arr = fs_extra.default.readJsonSync(legacyBindingsFile);
76
+ if (Array.isArray(arr) && arr.length > 0) {
77
+ const bindings = arr.map((b) => ({
78
+ match: { channel: b.channelId },
79
+ agentId: b.agentName,
80
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
81
+ }));
82
+ const migrated = {
83
+ agents: { list: [defaultAgent()] },
84
+ bindings,
85
+ session: { dmScope: "main" }
86
+ };
87
+ return this._migrateToMain(migrated, cfgPath);
88
+ }
89
+ } catch {}
90
+ return {
91
+ agents: { list: [defaultAgent()] },
92
+ bindings: [],
93
+ session: { dmScope: "main" }
94
+ };
95
+ }
96
+ _migrateToMain(legacy, cfgPath) {
97
+ try {
98
+ let current = {};
99
+ if (fs_extra.default.existsSync(cfgPath)) current = fs_extra.default.readJsonSync(cfgPath);
100
+ const next = {
101
+ ...current,
102
+ bindings: legacy.bindings ?? [],
103
+ agents: {
104
+ ...current?.agents,
105
+ list: legacy.agents?.list ?? [defaultAgent()]
106
+ },
107
+ ...legacy.broadcast ? { broadcast: legacy.broadcast } : {},
108
+ ...legacy.session ? { session: legacy.session } : {}
109
+ };
110
+ fs_extra.default.ensureDirSync(path.default.dirname(cfgPath));
111
+ fs_extra.default.writeJsonSync(cfgPath, next, { spaces: 2 });
112
+ } catch (e) {
113
+ console.warn("[agents-routing] Migration write failed:", e.message);
114
+ }
115
+ return legacy;
116
+ }
117
+ async _saveConfig() {
118
+ const { ConfigStore } = await Promise.resolve().then(() => require("./config-BlLlJ6Er.js"));
119
+ const store = new ConfigStore();
120
+ const current = await store.load();
121
+ await store.patch({
122
+ bindings: this.config.bindings ?? [],
123
+ agents: {
124
+ ...current?.agents,
125
+ list: this.config.agents?.list ?? [defaultAgent()]
126
+ },
127
+ ...this.config.broadcast ? { broadcast: this.config.broadcast } : {},
128
+ ...this.config.session ? { session: this.config.session } : {}
129
+ });
130
+ }
131
+ route(msg) {
132
+ const agents = this.config.agents?.list ?? [defaultAgent()];
133
+ const bindings = this.config.bindings ?? [];
134
+ const broadcastAgents = this._resolveBroadcast(msg);
135
+ const matched = this._matchBinding(msg, bindings, agents);
136
+ const agentDef = matched.agentDef;
137
+ const sessionKey = this._computeKey(msg, agentDef.id);
138
+ const skipLastRoute = msg.isDM ? this._shouldSkipLastRoute(msg) : false;
139
+ return {
140
+ agentId: agentDef.id,
141
+ agentDef,
142
+ sessionKey,
143
+ matchedBy: matched.matchedBy,
144
+ ...broadcastAgents.length > 1 ? { broadcast: broadcastAgents } : {},
145
+ ...skipLastRoute ? { skipLastRoute: true } : {}
146
+ };
147
+ }
148
+ _matchBinding(msg, bindings, agents) {
149
+ const find = (id) => agents.find((a) => a.id === id) ?? defaultAgent();
150
+ for (const b of bindings) {
151
+ if (!this._matchesFilter(msg, b.match)) continue;
152
+ return {
153
+ agentDef: find(b.agentId),
154
+ matchedBy: this._describeMatch(b.match)
155
+ };
156
+ }
157
+ const def = agents.find((a) => a.default) ?? agents[0] ?? defaultAgent();
158
+ return {
159
+ agentDef: def,
160
+ matchedBy: "default"
161
+ };
162
+ }
163
+ _matchesFilter(msg, match) {
164
+ if (match.channel && match.channel !== msg.channel) return false;
165
+ if (match.accountId && match.accountId !== "*" && match.accountId !== msg.accountId) return false;
166
+ if (match.peer) {
167
+ if (match.peer.kind !== msg.peer.kind) return false;
168
+ if (match.peer.id !== msg.peer.id) return false;
169
+ }
170
+ if (match.guildId && match.guildId !== msg.guildId) return false;
171
+ if (match.roles?.length) {
172
+ const senderRoles = msg.roles ?? [];
173
+ if (!match.roles.every((r) => senderRoles.includes(r))) return false;
174
+ }
175
+ if (match.teamId && match.teamId !== msg.teamId) return false;
176
+ return true;
177
+ }
178
+ _describeMatch(m) {
179
+ const parts = [];
180
+ if (m.channel) parts.push(`channel=${m.channel}`);
181
+ if (m.peer) parts.push(`peer=${m.peer.kind}:${m.peer.id}`);
182
+ if (m.guildId) parts.push(`guild=${m.guildId}`);
183
+ if (m.teamId) parts.push(`team=${m.teamId}`);
184
+ if (m.accountId) parts.push(`account=${m.accountId}`);
185
+ return parts.join(" ") || "channel-match";
186
+ }
187
+ _computeKey(msg, agentId) {
188
+ const dmScope = this.config.session?.dmScope ?? "main";
189
+ const ctx = {
190
+ agentId,
191
+ channel: msg.channel,
192
+ peerKind: msg.isDM ? "dm" : msg.peer.kind,
193
+ peerId: msg.peer.id,
194
+ threadId: msg.threadId,
195
+ topicId: msg.topicId,
196
+ dmScope: msg.isDM ? dmScope : void 0
197
+ };
198
+ return computeSessionKey(ctx);
199
+ }
200
+ _resolveBroadcast(msg) {
201
+ const bc = this.config.broadcast;
202
+ if (!bc) return [];
203
+ const agentIds = bc[msg.peer.id] ?? bc[msg.senderId];
204
+ if (Array.isArray(agentIds)) return agentIds;
205
+ return [];
206
+ }
207
+ /**
208
+ * Returns true when the inbound DM sender is not the pinned owner.
209
+ * Pinned owner = the single non-wildcard allowFrom entry for this channel.
210
+ */
211
+ _shouldSkipLastRoute(msg) {
212
+ const chanCfg = this.config.channels?.[msg.channel];
213
+ if (!chanCfg?.allowFrom) return false;
214
+ const nonWild = chanCfg.allowFrom.filter((id) => id !== "*" && id !== "**");
215
+ if (nonWild.length !== 1) return false;
216
+ const pinnedOwner = nonWild[0];
217
+ return msg.senderId !== pinnedOwner;
218
+ }
219
+ resolveDefaultAccount(channelId) {
220
+ return this.config.channels?.[channelId]?.defaultAccount;
221
+ }
222
+ listBindings() {
223
+ const agents = this.config.agents?.list ?? [];
224
+ const bindings = this.config.bindings ?? [];
225
+ console.log(chalk.default.bold.cyan("\n 🦅 AGENT BINDINGS\n"));
226
+ if (agents.length === 0) {
227
+ console.log(chalk.default.gray(" No agents configured.\n"));
228
+ return;
229
+ }
230
+ for (const a of agents) {
231
+ const def = a.default ? chalk.default.green(" [default]") : "";
232
+ const model = a.model ? chalk.default.gray(` model:${a.model}`) : "";
233
+ console.log(` ${chalk.default.bold(a.id)}${def} ${chalk.default.gray(a.workspace)}${model}`);
234
+ }
235
+ console.log();
236
+ if (bindings.length === 0) {
237
+ console.log(chalk.default.gray(" No explicit bindings — all traffic → default agent.\n"));
238
+ return;
239
+ }
240
+ console.log(chalk.default.bold(" Bindings:\n"));
241
+ for (const b of bindings) {
242
+ const m = b.match;
243
+ const parts = [];
244
+ if (m.channel) parts.push(chalk.default.cyan(m.channel));
245
+ if (m.peer) parts.push(`peer:${m.peer.kind}/${chalk.default.white(m.peer.id)}`);
246
+ if (m.guildId) parts.push(`guild:${chalk.default.white(m.guildId)}`);
247
+ if (m.teamId) parts.push(`team:${chalk.default.white(m.teamId)}`);
248
+ if (m.roles?.length) parts.push(`roles:[${m.roles.join(",")}]`);
249
+ if (m.accountId) parts.push(`account:${m.accountId}`);
250
+ console.log(` ${parts.join(" ")} ${chalk.default.gray("→")} ${chalk.default.bold(b.agentId)}`);
251
+ }
252
+ const bc = this.config.broadcast;
253
+ if (bc) {
254
+ console.log(chalk.default.bold("\n Broadcast groups:\n"));
255
+ const strat = bc.strategy ?? "parallel";
256
+ for (const [peerId, agents$1] of Object.entries(bc)) {
257
+ if (peerId === "strategy") continue;
258
+ if (Array.isArray(agents$1)) console.log(` ${chalk.default.white(peerId)} ${chalk.default.gray(`→ [${agents$1.join(", ")}]`)} ${chalk.default.gray(`(${strat})`)}`);
259
+ }
260
+ }
261
+ console.log();
262
+ }
263
+ async bind() {
264
+ console.log(chalk.default.cyan("\n Bind a channel/peer to an agent\n"));
265
+ const { channel, matchType } = await inquirer.default.prompt([{
266
+ type: "input",
267
+ name: "channel",
268
+ message: "Channel ID (e.g. telegram, discord, slack, whatsapp):",
269
+ validate: (v) => v.trim().length > 0 || "Required"
270
+ }, {
271
+ type: "list",
272
+ name: "matchType",
273
+ message: "Match by:",
274
+ choices: [
275
+ {
276
+ name: "Any message on this channel",
277
+ value: "channel"
278
+ },
279
+ {
280
+ name: "Specific peer (group ID, user ID, channel ID)",
281
+ value: "peer"
282
+ },
283
+ {
284
+ name: "Discord guild",
285
+ value: "guild"
286
+ },
287
+ {
288
+ name: "Slack team",
289
+ value: "team"
290
+ },
291
+ {
292
+ name: "Account ID",
293
+ value: "account"
294
+ }
295
+ ]
296
+ }]);
297
+ const match = { channel };
298
+ if (matchType === "peer") {
299
+ const { kind, peerId } = await inquirer.default.prompt([{
300
+ type: "list",
301
+ name: "kind",
302
+ message: "Peer type:",
303
+ choices: [
304
+ "group",
305
+ "channel",
306
+ "dm",
307
+ "room"
308
+ ]
309
+ }, {
310
+ type: "input",
311
+ name: "peerId",
312
+ message: "Peer ID:",
313
+ validate: (v) => v.trim().length > 0 || "Required"
314
+ }]);
315
+ match.peer = {
316
+ kind,
317
+ id: peerId
318
+ };
319
+ } else if (matchType === "guild") {
320
+ const { guildId } = await inquirer.default.prompt([{
321
+ type: "input",
322
+ name: "guildId",
323
+ message: "Discord guild ID:",
324
+ validate: (v) => v.trim().length > 0 || "Required"
325
+ }]);
326
+ match.guildId = guildId;
327
+ } else if (matchType === "team") {
328
+ const { teamId } = await inquirer.default.prompt([{
329
+ type: "input",
330
+ name: "teamId",
331
+ message: "Slack team ID:",
332
+ validate: (v) => v.trim().length > 0 || "Required"
333
+ }]);
334
+ match.teamId = teamId;
335
+ } else if (matchType === "account") {
336
+ const { accountId } = await inquirer.default.prompt([{
337
+ type: "input",
338
+ name: "accountId",
339
+ message: "Account ID:",
340
+ validate: (v) => v.trim().length > 0 || "Required"
341
+ }]);
342
+ match.accountId = accountId;
343
+ }
344
+ const agentIds = (this.config.agents?.list ?? []).map((a) => a.id);
345
+ const { agentId } = await inquirer.default.prompt([{
346
+ type: agentIds.length > 1 ? "list" : "input",
347
+ name: "agentId",
348
+ message: "Route to agent ID:",
349
+ choices: agentIds.length > 1 ? agentIds : void 0,
350
+ default: agentIds[0] ?? "main"
351
+ }]);
352
+ if (!this.config.bindings) this.config.bindings = [];
353
+ this.config.bindings.unshift({
354
+ match,
355
+ agentId,
356
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
357
+ });
358
+ await this._saveConfig();
359
+ console.log(chalk.default.green(`\n ✔ Binding added: ${channel}/${matchType} → ${agentId}\n`));
360
+ }
361
+ async unbind() {
362
+ const bindings = this.config.bindings ?? [];
363
+ if (bindings.length === 0) {
364
+ console.log(chalk.default.gray("\n No bindings to remove.\n"));
365
+ return;
366
+ }
367
+ const { toRemove } = await inquirer.default.prompt([{
368
+ type: "checkbox",
369
+ name: "toRemove",
370
+ message: "Select bindings to remove:",
371
+ choices: bindings.map((b, i) => ({
372
+ name: `${this._describeMatch(b.match)} → ${b.agentId}`,
373
+ value: i
374
+ }))
375
+ }]);
376
+ for (const idx of toRemove.sort((a, b) => b - a)) bindings.splice(idx, 1);
377
+ this.config.bindings = bindings;
378
+ await this._saveConfig();
379
+ console.log(chalk.default.green(`\n ✔ Removed ${toRemove.length} binding(s)\n`));
380
+ }
381
+ getConfig() {
382
+ return this.config;
383
+ }
384
+ getAgents() {
385
+ return this.config.agents?.list ?? [defaultAgent()];
386
+ }
387
+ getBindings() {
388
+ return this.config.bindings ?? [];
389
+ }
390
+ };
391
+
392
+ //#endregion
393
+ Object.defineProperty(exports, 'AgentRouter', {
394
+ enumerable: true,
395
+ get: function () {
396
+ return AgentRouter;
397
+ }
398
+ });
@@ -0,0 +1,6 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ require('./paths-AIyBxIzm.js');
3
+ require('./paths-DPovhojT.js');
4
+ const require_agents_routing = require('./agents-routing-Cpg20-1e.js');
5
+
6
+ exports.AgentRouter = require_agents_routing.AgentRouter;