wechat-clawbot 0.9.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/LICENSE +21 -0
- package/NOTICE +32 -0
- package/README.md +324 -0
- package/README.zh.md +192 -0
- package/cordis.patch.yml +23 -0
- package/lib/approvals.d.ts +29 -0
- package/lib/approvals.d.ts.map +1 -0
- package/lib/approvals.js +86 -0
- package/lib/approvals.js.map +1 -0
- package/lib/bridge.d.ts +281 -0
- package/lib/bridge.d.ts.map +1 -0
- package/lib/bridge.js +827 -0
- package/lib/bridge.js.map +1 -0
- package/lib/claude-peer.d.ts +44 -0
- package/lib/claude-peer.d.ts.map +1 -0
- package/lib/claude-peer.js +515 -0
- package/lib/claude-peer.js.map +1 -0
- package/lib/cli.d.ts +3 -0
- package/lib/cli.d.ts.map +1 -0
- package/lib/cli.js +128 -0
- package/lib/cli.js.map +1 -0
- package/lib/client.js +597 -0
- package/lib/config.d.ts +160 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +187 -0
- package/lib/config.js.map +1 -0
- package/lib/emoji.d.ts +26 -0
- package/lib/emoji.d.ts.map +1 -0
- package/lib/emoji.js +54 -0
- package/lib/emoji.js.map +1 -0
- package/lib/ilink/api/api.d.ts +134 -0
- package/lib/ilink/api/api.d.ts.map +1 -0
- package/lib/ilink/api/api.js +507 -0
- package/lib/ilink/api/api.js.map +1 -0
- package/lib/ilink/api/session-guard.d.ts +16 -0
- package/lib/ilink/api/session-guard.d.ts.map +1 -0
- package/lib/ilink/api/session-guard.js +49 -0
- package/lib/ilink/api/session-guard.js.map +1 -0
- package/lib/ilink/api/types.d.ts +251 -0
- package/lib/ilink/api/types.d.ts.map +1 -0
- package/lib/ilink/api/types.js +37 -0
- package/lib/ilink/api/types.js.map +1 -0
- package/lib/ilink/auth/accounts.d.ts +67 -0
- package/lib/ilink/auth/accounts.d.ts.map +1 -0
- package/lib/ilink/auth/accounts.js +190 -0
- package/lib/ilink/auth/accounts.js.map +1 -0
- package/lib/ilink/auth/login-qr.d.ts +43 -0
- package/lib/ilink/auth/login-qr.d.ts.map +1 -0
- package/lib/ilink/auth/login-qr.js +333 -0
- package/lib/ilink/auth/login-qr.js.map +1 -0
- package/lib/ilink/cdn/aes-ecb.d.ts +7 -0
- package/lib/ilink/cdn/aes-ecb.d.ts.map +1 -0
- package/lib/ilink/cdn/aes-ecb.js +19 -0
- package/lib/ilink/cdn/aes-ecb.js.map +1 -0
- package/lib/ilink/cdn/cdn-upload.d.ts +18 -0
- package/lib/ilink/cdn/cdn-upload.d.ts.map +1 -0
- package/lib/ilink/cdn/cdn-upload.js +90 -0
- package/lib/ilink/cdn/cdn-upload.js.map +1 -0
- package/lib/ilink/cdn/cdn-url.d.ts +14 -0
- package/lib/ilink/cdn/cdn-url.d.ts.map +1 -0
- package/lib/ilink/cdn/cdn-url.js +14 -0
- package/lib/ilink/cdn/cdn-url.js.map +1 -0
- package/lib/ilink/cdn/pic-decrypt.d.ts +10 -0
- package/lib/ilink/cdn/pic-decrypt.d.ts.map +1 -0
- package/lib/ilink/cdn/pic-decrypt.js +89 -0
- package/lib/ilink/cdn/pic-decrypt.js.map +1 -0
- package/lib/ilink/cdn/upload.d.ts +43 -0
- package/lib/ilink/cdn/upload.d.ts.map +1 -0
- package/lib/ilink/cdn/upload.js +115 -0
- package/lib/ilink/cdn/upload.js.map +1 -0
- package/lib/ilink/media/mime.d.ts +7 -0
- package/lib/ilink/media/mime.d.ts.map +1 -0
- package/lib/ilink/media/mime.js +73 -0
- package/lib/ilink/media/mime.js.map +1 -0
- package/lib/ilink/messaging/send-media.d.ts +23 -0
- package/lib/ilink/messaging/send-media.d.ts.map +1 -0
- package/lib/ilink/messaging/send-media.js +71 -0
- package/lib/ilink/messaging/send-media.js.map +1 -0
- package/lib/ilink/messaging/send.d.ts +55 -0
- package/lib/ilink/messaging/send.d.ts.map +1 -0
- package/lib/ilink/messaging/send.js +182 -0
- package/lib/ilink/messaging/send.js.map +1 -0
- package/lib/ilink/storage/state-dir.d.ts +14 -0
- package/lib/ilink/storage/state-dir.d.ts.map +1 -0
- package/lib/ilink/storage/state-dir.js +22 -0
- package/lib/ilink/storage/state-dir.js.map +1 -0
- package/lib/ilink/storage/sync-buf.d.ts +21 -0
- package/lib/ilink/storage/sync-buf.d.ts.map +1 -0
- package/lib/ilink/storage/sync-buf.js +64 -0
- package/lib/ilink/storage/sync-buf.js.map +1 -0
- package/lib/ilink/util/logger.d.ts +20 -0
- package/lib/ilink/util/logger.d.ts.map +1 -0
- package/lib/ilink/util/logger.js +73 -0
- package/lib/ilink/util/logger.js.map +1 -0
- package/lib/ilink/util/random.d.ts +11 -0
- package/lib/ilink/util/random.d.ts.map +1 -0
- package/lib/ilink/util/random.js +16 -0
- package/lib/ilink/util/random.js.map +1 -0
- package/lib/ilink/util/redact.d.ts +21 -0
- package/lib/ilink/util/redact.d.ts.map +1 -0
- package/lib/ilink/util/redact.js +54 -0
- package/lib/ilink/util/redact.js.map +1 -0
- package/lib/image-compress.d.ts +38 -0
- package/lib/image-compress.d.ts.map +1 -0
- package/lib/image-compress.js +184 -0
- package/lib/image-compress.js.map +1 -0
- package/lib/inbound-media.d.ts +17 -0
- package/lib/inbound-media.d.ts.map +1 -0
- package/lib/inbound-media.js +96 -0
- package/lib/inbound-media.js.map +1 -0
- package/lib/inbound.d.ts +28 -0
- package/lib/inbound.d.ts.map +1 -0
- package/lib/inbound.js +265 -0
- package/lib/inbound.js.map +1 -0
- package/lib/index.d.ts +23 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +321 -0
- package/lib/index.js.map +1 -0
- package/lib/mcp-route.d.ts +33 -0
- package/lib/mcp-route.d.ts.map +1 -0
- package/lib/mcp-route.js +422 -0
- package/lib/mcp-route.js.map +1 -0
- package/lib/memory-auto.d.ts +22 -0
- package/lib/memory-auto.d.ts.map +1 -0
- package/lib/memory-auto.js +144 -0
- package/lib/memory-auto.js.map +1 -0
- package/lib/memory.d.ts +26 -0
- package/lib/memory.d.ts.map +1 -0
- package/lib/memory.js +168 -0
- package/lib/memory.js.map +1 -0
- package/lib/models-route.d.ts +24 -0
- package/lib/models-route.d.ts.map +1 -0
- package/lib/models-route.js +84 -0
- package/lib/models-route.js.map +1 -0
- package/lib/monitor.d.ts +13 -0
- package/lib/monitor.d.ts.map +1 -0
- package/lib/monitor.js +116 -0
- package/lib/monitor.js.map +1 -0
- package/lib/pending.d.ts +23 -0
- package/lib/pending.d.ts.map +1 -0
- package/lib/pending.js +38 -0
- package/lib/pending.js.map +1 -0
- package/lib/prompt.d.ts +36 -0
- package/lib/prompt.d.ts.map +1 -0
- package/lib/prompt.js +246 -0
- package/lib/prompt.js.map +1 -0
- package/lib/questions.d.ts +21 -0
- package/lib/questions.d.ts.map +1 -0
- package/lib/questions.js +116 -0
- package/lib/questions.js.map +1 -0
- package/lib/quote-history.d.ts +18 -0
- package/lib/quote-history.d.ts.map +1 -0
- package/lib/quote-history.js +96 -0
- package/lib/quote-history.js.map +1 -0
- package/lib/state.d.ts +27 -0
- package/lib/state.d.ts.map +1 -0
- package/lib/state.js +154 -0
- package/lib/state.js.map +1 -0
- package/lib/subagent-model.d.ts +26 -0
- package/lib/subagent-model.d.ts.map +1 -0
- package/lib/subagent-model.js +30 -0
- package/lib/subagent-model.js.map +1 -0
- package/lib/tool.d.ts +14 -0
- package/lib/tool.d.ts.map +1 -0
- package/lib/tool.js +518 -0
- package/lib/tool.js.map +1 -0
- package/package.json +94 -0
package/lib/state.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State persistence helpers for the DSH plugin side (context tokens, session
|
|
3
|
+
* marker, file watching). Credentials and sync buffers live in the vendored
|
|
4
|
+
* `ilink/storage` layer under the same state directory.
|
|
5
|
+
*/
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { resolveStateDir } from "./ilink/storage/state-dir.js";
|
|
9
|
+
import { logger } from "./ilink/util/logger.js";
|
|
10
|
+
/** Directory holding per-account runtime data (context tokens etc.). */
|
|
11
|
+
export function accountsRuntimeDir(accountId) {
|
|
12
|
+
return path.join(resolveStateDir(), "accounts");
|
|
13
|
+
}
|
|
14
|
+
export function contextTokensPath(accountId) {
|
|
15
|
+
return path.join(accountsRuntimeDir(accountId), `${accountId}.context-tokens.json`);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Normalize peer ids for context-token keys: OpenClaw (and the iLink server)
|
|
19
|
+
* can supply the same peer id with mixed case, so lookups must be
|
|
20
|
+
* case-insensitive (sync from openclaw-weixin 3.1.0).
|
|
21
|
+
*/
|
|
22
|
+
function tokenKey(userId) {
|
|
23
|
+
return userId.toLowerCase();
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Read the stored context token for a sender (empty string when absent).
|
|
27
|
+
* Falls back to a case-insensitive scan so tokens persisted by pre-3.1.0
|
|
28
|
+
* builds (mixed-case keys) keep working after the normalization upgrade.
|
|
29
|
+
*/
|
|
30
|
+
export function loadContextToken(accountId, userId) {
|
|
31
|
+
try {
|
|
32
|
+
const raw = fs.readFileSync(contextTokensPath(accountId), "utf-8");
|
|
33
|
+
const data = JSON.parse(raw);
|
|
34
|
+
const tokens = data.tokens ?? {};
|
|
35
|
+
const hit = tokens[tokenKey(userId)];
|
|
36
|
+
if (hit)
|
|
37
|
+
return hit;
|
|
38
|
+
const lower = userId.toLowerCase();
|
|
39
|
+
for (const key of Object.keys(tokens)) {
|
|
40
|
+
if (key.toLowerCase() === lower)
|
|
41
|
+
return tokens[key];
|
|
42
|
+
}
|
|
43
|
+
return "";
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return "";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Persist a sender's latest context token. */
|
|
50
|
+
export function saveContextToken(accountId, userId, token) {
|
|
51
|
+
if (!token)
|
|
52
|
+
return;
|
|
53
|
+
try {
|
|
54
|
+
let data = {};
|
|
55
|
+
try {
|
|
56
|
+
data = JSON.parse(fs.readFileSync(contextTokensPath(accountId), "utf-8"));
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// fresh file
|
|
60
|
+
}
|
|
61
|
+
data.tokens = { ...(data.tokens ?? {}), [tokenKey(userId)]: token };
|
|
62
|
+
fs.mkdirSync(accountsRuntimeDir(accountId), { recursive: true });
|
|
63
|
+
const tmp = `${contextTokensPath(accountId)}.tmp`;
|
|
64
|
+
fs.writeFileSync(tmp, JSON.stringify(data, null, 2), "utf-8");
|
|
65
|
+
fs.renameSync(tmp, contextTokensPath(accountId));
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
logger.warn(`saveContextToken: failed userId=${userId} err=${String(err)}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** Path of the marker recording that we created the WeChat session. */
|
|
72
|
+
export function sessionMarkerPath(sessionId) {
|
|
73
|
+
return path.join(resolveStateDir(), "sessions", `${sessionId}.json`);
|
|
74
|
+
}
|
|
75
|
+
/** Whether the WeChat session was previously created by this plugin. */
|
|
76
|
+
export function wasSessionCreated(sessionId) {
|
|
77
|
+
try {
|
|
78
|
+
return fs.existsSync(sessionMarkerPath(sessionId));
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** Record that the WeChat session was created by this plugin. */
|
|
85
|
+
export function markSessionCreated(sessionId) {
|
|
86
|
+
try {
|
|
87
|
+
const p = sessionMarkerPath(sessionId);
|
|
88
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
89
|
+
fs.writeFileSync(p, JSON.stringify({ created: true, at: new Date().toISOString() }, null, 2), "utf-8");
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
logger.warn(`markSessionCreated: failed sessionId=${sessionId} err=${String(err)}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Watch the ClawBot state directory for account credential changes made by
|
|
97
|
+
* the `clawbot` CLI while the profile is running (login/logout). Callbacks
|
|
98
|
+
* are debounced to collapse rename-then-write sequences.
|
|
99
|
+
*/
|
|
100
|
+
export function watchAccountStore(onChange) {
|
|
101
|
+
const dir = resolveStateDir();
|
|
102
|
+
const accountsDir = path.join(dir, "accounts");
|
|
103
|
+
try {
|
|
104
|
+
fs.mkdirSync(accountsDir, { recursive: true });
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// ignore
|
|
108
|
+
}
|
|
109
|
+
let timer;
|
|
110
|
+
const schedule = () => {
|
|
111
|
+
if (timer !== undefined)
|
|
112
|
+
clearTimeout(timer);
|
|
113
|
+
timer = setTimeout(() => {
|
|
114
|
+
timer = undefined;
|
|
115
|
+
try {
|
|
116
|
+
onChange();
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
logger.warn(`watchAccountStore: onChange failed err=${String(err)}`);
|
|
120
|
+
}
|
|
121
|
+
}, 500);
|
|
122
|
+
};
|
|
123
|
+
const watchers = [];
|
|
124
|
+
for (const target of [dir, accountsDir]) {
|
|
125
|
+
try {
|
|
126
|
+
const w = fs.watch(target, (_event, filename) => {
|
|
127
|
+
if (!filename)
|
|
128
|
+
return;
|
|
129
|
+
const name = String(filename);
|
|
130
|
+
if (name.endsWith(".json"))
|
|
131
|
+
schedule();
|
|
132
|
+
});
|
|
133
|
+
watchers.push(w);
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
logger.warn(`watchAccountStore: cannot watch ${target} err=${String(err)}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
close() {
|
|
141
|
+
if (timer !== undefined)
|
|
142
|
+
clearTimeout(timer);
|
|
143
|
+
for (const w of watchers) {
|
|
144
|
+
try {
|
|
145
|
+
w.close();
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
// ignore
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=state.js.map
|
package/lib/state.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,wEAAwE;AACxE,MAAM,UAAU,kBAAkB,CAAC,SAAiB;IAClD,OAAO,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,EAAE,UAAU,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,SAAiB;IACjD,OAAO,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,EAAE,GAAG,SAAS,sBAAsB,CAAC,CAAC;AACtF,CAAC;AAOD;;;;GAIG;AACH,SAAS,QAAQ,CAAC,MAAc;IAC9B,OAAO,MAAM,CAAC,WAAW,EAAE,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAiB,EAAE,MAAc;IAChE,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,iBAAiB,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,CAAC;QACnE,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAsB,CAAC;QAClD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;QACjC,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;QACrC,IAAI,GAAG;YAAE,OAAO,GAAG,CAAC;QACpB,MAAM,KAAK,GAAG,MAAM,CAAC,WAA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;QAC9E,CAAC;IACH,CAAC;IACD,OAAO;QACL,KAAK;YACH,IAAI,KAAK,KAAK,SAAS;gBAAE,YAAY,CAAC,KAAK,CAAC,CAAC;YAC7C,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;gBACzB,IAAI,CAAC;oBACH,CAAC,CAAC,KAAK,EAAE,CAAC;gBACZ,CAAC;gBAAC,MAAM,CAAC;oBACP,SAAS;gBACX,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subagent model policy for the WeChat agent: every subagent delegated from
|
|
3
|
+
* the WeChat session (directly or transitively) runs with max thinking
|
|
4
|
+
* (reasoningEffort=max) on deepseek-v4-flash, so that complex/deep tasks the
|
|
5
|
+
* user delegates still get full reasoning even though the main WeChat
|
|
6
|
+
* conversation runs with reasoningEffort=off for fast replies.
|
|
7
|
+
*
|
|
8
|
+
* Implementation: `agent/created` is emitted for every live agent (children
|
|
9
|
+
* included); each child's session header carries `parentSession`, so we can
|
|
10
|
+
* tell whether it descends from the WeChat session. For those children we
|
|
11
|
+
* install a model selection (provider/model/reasoningEffort=max) via
|
|
12
|
+
* `installModelSelection`, which couples prompt assembly and request routing
|
|
13
|
+
* on the child's scope.
|
|
14
|
+
*/
|
|
15
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
16
|
+
export type SubagentModelPolicy = {
|
|
17
|
+
/** The WeChat session id whose subagents get the policy. */
|
|
18
|
+
sessionId: string;
|
|
19
|
+
provider: string;
|
|
20
|
+
model: string;
|
|
21
|
+
/** "max" = full thinking (deepseek v4 flash supports off|high|max). */
|
|
22
|
+
reasoningEffort: string;
|
|
23
|
+
};
|
|
24
|
+
/** Install the policy: listen for child agents of the WeChat session. */
|
|
25
|
+
export declare function registerSubagentModelPolicy(ctx: Context, policy: SubagentModelPolicy): void;
|
|
26
|
+
//# sourceMappingURL=subagent-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subagent-model.d.ts","sourceRoot":"","sources":["../src/subagent-model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAMnD,MAAM,MAAM,mBAAmB,GAAG;IAChC,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,yEAAyE;AACzE,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,mBAAmB,GAAG,IAAI,CAwB3F"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { installModelSelection } from "@deepseek-ai/dsh-agent";
|
|
2
|
+
import { ReasoningEffortId } from "@deepseek-ai/dsh-llm";
|
|
3
|
+
import { logger } from "./ilink/util/logger.js";
|
|
4
|
+
/** Install the policy: listen for child agents of the WeChat session. */
|
|
5
|
+
export function registerSubagentModelPolicy(ctx, policy) {
|
|
6
|
+
ctx.on("agent/created", ({ agent }) => {
|
|
7
|
+
try {
|
|
8
|
+
const parentSession = agent.session?.header?.parentSession;
|
|
9
|
+
if (String(parentSession) !== String(policy.sessionId))
|
|
10
|
+
return;
|
|
11
|
+
// Only children created at or below this session; if a descendant of
|
|
12
|
+
// the child exists it inherits this selection through its own
|
|
13
|
+
// parentSession chain anyway (each level is its own agent/created).
|
|
14
|
+
const selection = {
|
|
15
|
+
current: {
|
|
16
|
+
provider: policy.provider,
|
|
17
|
+
model: policy.model,
|
|
18
|
+
reasoningEffort: ReasoningEffortId(policy.reasoningEffort),
|
|
19
|
+
},
|
|
20
|
+
assembled: undefined,
|
|
21
|
+
};
|
|
22
|
+
installModelSelection(agent.ctx, selection);
|
|
23
|
+
logger.info(`subagent-model: wechat subagent ${String(agent.id)} -> ${policy.provider}/${policy.model} reasoningEffort=${policy.reasoningEffort}`);
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
logger.warn(`subagent-model: install failed: ${String(err)}`);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=subagent-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subagent-model.js","sourceRoot":"","sources":["../src/subagent-model.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAWhD,yEAAyE;AACzE,MAAM,UAAU,2BAA2B,CAAC,GAAY,EAAE,MAA2B;IACnF,GAAG,CAAC,EAAE,CAAC,eAAe,EAAE,CAAC,EAAE,KAAK,EAAiG,EAAE,EAAE;QACnI,IAAI,CAAC;YACH,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC;YAC3D,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;gBAAE,OAAO;YAC/D,qEAAqE;YACrE,8DAA8D;YAC9D,oEAAoE;YACpE,MAAM,SAAS,GAAG;gBAChB,OAAO,EAAE;oBACP,QAAQ,EAAE,MAAM,CAAC,QAAQ;oBACzB,KAAK,EAAE,MAAM,CAAC,KAAK;oBACnB,eAAe,EAAE,iBAAiB,CAAC,MAAM,CAAC,eAAe,CAAC;iBAC3D;gBACD,SAAS,EAAE,SAAS;aACrB,CAAC;YACF,qBAAqB,CAAC,KAAK,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;YAC5C,MAAM,CAAC,IAAI,CACT,mCAAmC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,KAAK,oBAAoB,MAAM,CAAC,eAAe,EAAE,CACtI,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,CAAC,IAAI,CAAC,mCAAmC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChE,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/lib/tool.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { ClawbotConfig } from "./config.js";
|
|
3
|
+
import type { WechatBridge } from "./bridge.js";
|
|
4
|
+
import type { ResolvedWeixinAccount } from "./ilink/auth/accounts.js";
|
|
5
|
+
export type SendFileToolDeps = {
|
|
6
|
+
/** The live bridge (sender routing), or null while the monitor is down. */
|
|
7
|
+
getBridge: () => WechatBridge | null;
|
|
8
|
+
/** The bound account (API credentials), or null before first login. */
|
|
9
|
+
getAccount: () => ResolvedWeixinAccount | null;
|
|
10
|
+
config: ClawbotConfig;
|
|
11
|
+
};
|
|
12
|
+
/** Register the tool into one agent's scoped world (call from setup). */
|
|
13
|
+
export declare function registerSendFileTool(agentCtx: Context, deps: SendFileToolDeps): void;
|
|
14
|
+
//# sourceMappingURL=tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../src/tool.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAGnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAUtE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,2EAA2E;IAC3E,SAAS,EAAE,MAAM,YAAY,GAAG,IAAI,CAAC;IACrC,uEAAuE;IACvE,UAAU,EAAE,MAAM,qBAAqB,GAAG,IAAI,CAAC;IAC/C,MAAM,EAAE,aAAa,CAAC;CACvB,CAAC;AA2JF,yEAAyE;AACzE,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,gBAAgB,GAAG,IAAI,CA4LpF"}
|