forked from lioensky/VCPToolBox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoolExecutor.js
More file actions
604 lines (534 loc) · 23 KB
/
Copy pathtoolExecutor.js
File metadata and controls
604 lines (534 loc) · 23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
// modules/vcpLoop/toolExecutor.js
const fs = require('fs').promises;
const path = require('path');
const crypto = require('crypto');
const { pathToFileURL } = require('url');
const { getEmbeddingsBatch, cosineSimilarity } = require('../../EmbeddingUtils');
const toolCallRecordStore = require('../toolCallRecordStore');
const VCP_TIMED_CONTACTS_DIR = path.join(__dirname, '..', '..', 'VCPTimedContacts');
/**
* 提取消息的纯文本字符串
*/
function getMessageTextContent(msg) {
if (!msg) return '';
if (typeof msg.content === 'string') return msg.content;
if (Array.isArray(msg.content)) {
return msg.content
.filter(part => part.type === 'text')
.map(part => part.text)
.join('\n');
}
return '';
}
/**
* 将多模态消息对象规范化为纯文本消息对象(保留 role 等元数据)
* 复用 getMessageTextContent 提取文本
*/
function extractTextFromMessage(msg) {
if (typeof msg.content === 'string') return msg;
if (Array.isArray(msg.content)) {
return { ...msg, content: getMessageTextContent(msg) };
}
return msg;
}
class ToolExecutor {
constructor(options) {
this.pluginManager = options.pluginManager;
this.webSocketServer = options.webSocketServer;
this.debugMode = options.debugMode;
this.vcpToolCode = options.vcpToolCode;
this.getRealAuthCode = options.getRealAuthCode;
}
/**
* 构建 VRef 上下文向量 — 将当前对话上下文压缩为一个加权平均向量,
* 用于后续在知识库中进行语义检索。
*
* 设计要点:
* - 仅使用 RAGDiaryPlugin 已缓存的向量(_getEmbeddingFromCacheOnly),
* 绝不触发新的 Embedding API 调用,保证 vref 是零额外成本的旁路操作。
* - 权重分配复用 RAG 主搜索权重(默认 user:0.7 / ai:0.3),
* 确保 vref 检索方向与 RAG 检索方向一致。
*
* @param {Array} contextMessages - 当前对话的完整消息数组
* @returns {Promise<Float32Array|null>} 加权上下文向量,或 null(缓存未命中/不可用时)
*/
async _buildVRefContextVector(contextMessages = []) {
// 依赖 RAGDiaryPlugin 的三个内部方法:清洗、缓存查询、加权平均
const ragPlugin = this.pluginManager?.messagePreprocessors?.get('RAGDiaryPlugin');
if (
!ragPlugin ||
typeof ragPlugin.sanitizeForEmbedding !== 'function' ||
typeof ragPlugin._getEmbeddingFromCacheOnly !== 'function' ||
typeof ragPlugin._getWeightedAverageVector !== 'function'
) {
console.warn('[VRef] RAGDiaryPlugin 不可用,跳过 vref 向量构建。');
return null;
}
// 定位最后一条"真实"用户消息(排除工具回包和系统注入)
const lastUserIndex = contextMessages.findLastIndex(msg => {
if (msg.role !== 'user') return false;
const content = getMessageTextContent(msg);
return !content.startsWith('<!-- VCP_TOOL_PAYLOAD -->') &&
!content.startsWith('[系统提示:]') &&
!content.startsWith('[系统邀请指令:]');
});
if (lastUserIndex === -1) {
console.warn('[VRef] 未找到可用的 user 消息,跳过 vref。');
return null;
}
const rawUserContent = getMessageTextContent(contextMessages[lastUserIndex]);
// 向前搜索最近一条 AI 回复,作为上下文的另一半
let rawAiContent = '';
for (let i = lastUserIndex - 1; i >= 0; i--) {
if (contextMessages[i].role === 'assistant') {
rawAiContent = getMessageTextContent(contextMessages[i]);
break;
}
}
// 清洗文本(去除 RAG 块、系统标记等噪声)
const userContent = ragPlugin.sanitizeForEmbedding(rawUserContent, 'user');
const aiContent = rawAiContent
? ragPlugin.sanitizeForEmbedding(rawAiContent, 'assistant')
: '';
// 仅从缓存获取向量 — 如果本轮 RAG 已执行过,这些向量必然已在缓存中
const userVector = userContent
? ragPlugin._getEmbeddingFromCacheOnly(userContent)
: null;
const aiVector = aiContent
? ragPlugin._getEmbeddingFromCacheOnly(aiContent)
: null;
if (!userVector && !aiVector) {
console.warn('[VRef] 上下文向量未命中缓存,为避免额外 API 调用,跳过 vref。');
return null;
}
// 复用 RAG 主搜索的 user/ai 权重配比(默认 0.7/0.3)
const mainWeights = ragPlugin.ragParams?.RAGDiaryPlugin?.mainSearchWeights || [0.7, 0.3];
return ragPlugin._getWeightedAverageVector([userVector, aiVector], mainWeights);
}
/**
* 解析 vref 参数,返回与当前上下文语义最相关的 N 个日记文件 URL。
*
* 算法流程:
* 1. 构建上下文向量(复用 RAG 缓存,零额外 API 调用)
* 2. 在所有知识库分区(diary_name)中并行检索 Top-N
* 3. 按文件路径去重(同一文件多个 chunk 只保留最高分)
* 4. 全局排序取 Top-N,转换为 file:// URL 供插件读取
*
* @param {string} vrefValue - vref 参数值,应为正整数字符串(如 "3"、"5"),
* 表示返回的最大文件数。解析失败时默认为 3。
* @param {Array} contextMessages - 当前对话的完整消息数组
* @returns {Promise<string[]>} file:// URL 数组(长度 ≤ N)
*/
async _resolveVRefFiles(vrefValue, contextMessages = []) {
const kbManager = this.pluginManager?.vectorDBManager;
if (!kbManager || !kbManager.db) {
console.warn('[VRef] VectorDBManager 不可用,跳过 vref。');
return [];
}
// Step 1: 构建上下文向量
const contextVector = await this._buildVRefContextVector(contextMessages);
if (!contextVector) return [];
// 从 AI 传入的 vref 值解析返回数量(如 vref:「始」5「末」→ n=5)
const parsedN = parseInt(vrefValue, 10);
const n = Number.isFinite(parsedN) && parsedN > 0 ? parsedN : 3;
// Step 2: 获取所有知识库分区名,在每个分区中并行检索
const diaryRows = kbManager.db.prepare('SELECT DISTINCT diary_name FROM files').all();
if (!Array.isArray(diaryRows) || diaryRows.length === 0) {
return [];
}
const resultGroups = await Promise.all(
diaryRows.map(({ diary_name }) => kbManager.search(diary_name, contextVector, n))
);
// Step 3: 按文件路径去重 — 同一文件可能有多个 chunk 命中,只保留最高分
const bestByFile = new Map();
for (const result of resultGroups.flat()) {
const relativePath = result?.fullPath || result?.sourceFile;
if (!relativePath) continue;
const previous = bestByFile.get(relativePath);
if (!previous || (result.score ?? -Infinity) > (previous.score ?? -Infinity)) {
bestByFile.set(relativePath, result);
}
}
const dailyNoteRoot = kbManager.config?.rootPath || path.resolve(process.cwd(), 'dailynote');
// Step 4: 全局排序取 Top-N,转换为 file:// URL
return Array.from(bestByFile.values())
.sort((a, b) => (b.score ?? 0) - (a.score ?? 0))
.slice(0, n)
.map(result => {
const filePath = result.fullPath || result.sourceFile;
const absolutePath = path.isAbsolute(filePath)
? filePath
: path.resolve(dailyNoteRoot, filePath);
return pathToFileURL(absolutePath).href;
});
}
/**
* 执行单个工具调用
* @returns {Promise<{success: boolean, content: Array, error?: string, raw?: any}>}
*/
async execute(toolCall, clientIp, contextMessages = []) {
const { name, args, river, vref, archeryNoReply } = toolCall;
// === river 上下文注入 ===
// river 协议允许 AI 在工具调用时携带对话上下文,支持四种模式:
// full — 原始多模态消息(含图片等),完整深拷贝
// text — 多模态转纯文本,减少传输体积
// last:N — 仅取最后 N 条消息(纯文本)
// semantic:N — 语义折叠,用工具参数作为 query 检索最相关的 N 条消息
if (this.debugMode) console.log(`[ToolExecutor] Processing tool: ${name}, river mode: ${river}`);
if (river === 'full') {
args.river_context = JSON.parse(JSON.stringify(contextMessages));
} else if (river === 'text') {
args.river_context = contextMessages.map(msg => extractTextFromMessage(msg));
}
// === last:N 模式 — 取最后 N 条消息(纯文本) ===
else if (river && river.startsWith('last:')) {
const n = parseInt(river.split(':')[1]) || 10;
const textOnly = contextMessages.map(msg => extractTextFromMessage(msg));
args.river_context = textOnly.slice(-n);
}
// === semantic:N 模式 — 语义折叠取 Top-N 最相关消息 ===
else if (river && river.startsWith('semantic:')) {
const n = parseInt(river.split(':')[1]) || 5;
// 1. 构建查询文本:用工具调用的参数拼接
const queryParts = [];
for (const [key, value] of Object.entries(args)) {
if (key === 'river_context') continue;
if (typeof value === 'string' && value.length > 0) {
queryParts.push(value);
}
}
const queryText = queryParts.join(' ').slice(0, 2000);
// 2. 提取每条消息的纯文本
const textMessages = contextMessages.map((msg, idx) => ({
index: idx,
role: msg.role,
text: getMessageTextContent(msg),
original: msg
})).filter(m => m.text.length > 10);
// 3. 尝试语义检索,失败则优雅回退到 last:N(保证工具调用不会因向量化失败而中断)
try {
// 优先走 RAGDiaryPlugin 缓存通道:本轮对话的消息向量大概率已被 RAG 流程缓存,
// 复用缓存可避免重复 API 调用。仅当 ragPlugin 不可用时回退到 EmbeddingUtils 独立通道。
const ragPlugin = this.pluginManager?.messagePreprocessors?.get('RAGDiaryPlugin');
let queryVec = null;
let messageVectors = [];
if (ragPlugin && typeof ragPlugin.getBatchEmbeddingsCached === 'function') {
// 走 RAGDiaryPlugin 缓存通道:逐条查缓存,未命中的批量发 API
const allTexts = [
queryText.slice(0, 1000),
...textMessages.map(m => m.text.slice(0, 1000))
];
const allVectors = await ragPlugin.getBatchEmbeddingsCached(allTexts);
queryVec = allVectors[0];
messageVectors = allVectors.slice(1);
} else {
// 回退:ragPlugin 不可用时,走 EmbeddingUtils 独立通道
const embeddingConfig = {
apiKey: process.env.API_KEY,
apiUrl: process.env.API_URL,
model: process.env.WhitelistEmbeddingModel || 'google/gemini-embedding-001'
};
const allTexts = [
queryText.slice(0, 1000),
...textMessages.map(m => m.text.slice(0, 1000))
];
const allVectors = await getEmbeddingsBatch(allTexts, embeddingConfig);
queryVec = allVectors[0];
messageVectors = allVectors.slice(1);
}
if (!queryVec) {
throw new Error('Query embedding returned null');
}
// 4. 计算余弦相似度并排序
const scored = textMessages.map((m, i) => ({
...m,
score: messageVectors[i] ? cosineSimilarity(queryVec, messageVectors[i]) : 0
}));
scored.sort((a, b) => b.score - a.score);
// 5. 取 Top-N,按原始顺序排列
const topN = scored.slice(0, n);
topN.sort((a, b) => a.index - b.index);
args.river_context = topN.map(m => ({
role: m.role,
content: m.text,
_river_score: m.score,
_river_index: m.index
}));
if (this.debugMode) {
console.log(`[ToolExecutor] Semantic river: selected ${topN.length} messages from ${textMessages.length} candidates (via ${ragPlugin ? 'RAGDiaryPlugin cache' : 'EmbeddingUtils'})`);
}
} catch (err) {
console.warn(`[River] Semantic mode failed, falling back to last:${n}:`, err.message);
// 回退到 last:N
const textOnly = contextMessages.map(msg => extractTextFromMessage(msg));
args.river_context = textOnly.slice(-n);
}
}
if (this.debugMode && args.river_context) {
console.log(`[ToolExecutor] river_context injected: ${args.river_context.length} messages`);
}
// === vref 虚拟引用解析 ===
// vref 允许 AI 在工具调用时自动附加语义相关的知识库文件引用,
// 插件通过 args.vref_files(file:// URL 数组)获取这些引用。
if (vref) {
try {
args.vref_files = await this._resolveVRefFiles(vref, contextMessages);
if (this.debugMode) {
console.log(`[VRef] Resolved ${args.vref_files.length} references for vref:${vref}`);
}
} catch (err) {
args.vref_files = [];
console.warn('[VRef] Failed to resolve references:', err.message);
}
}
const recordHandle = toolCallRecordStore.beginRecord({
toolName: name,
args,
requestIp: clientIp,
sourceNode: 'post'
});
// 通用未来任务拦截:
// 任意工具只要携带 timely_contact,就先写入 VCPTimedContacts 由任务调度器到点执行。
// 到点执行时由 TaskScheduler 注入 __vcp_timed_call 标准元信息;
// 插件可基于该字段判断原始发起时间、计划触发时间与实际触发时间。
if (args && Object.prototype.hasOwnProperty.call(args, 'timely_contact')) {
const scheduledResult = await this._scheduleTimedToolCall(toolCall);
toolCallRecordStore.finishRecord(recordHandle, {
success: scheduledResult.success,
result: scheduledResult.raw || scheduledResult.content,
error: scheduledResult.success ? null : scheduledResult.error
});
return this._attachRecordIdToResult(scheduledResult, recordHandle);
}
// 验证码校验
if (this.vcpToolCode) {
const authResult = await this._verifyAuth(args);
if (!authResult.valid) {
const errorResult = this._createErrorResult(name, authResult.message);
toolCallRecordStore.finishRecord(recordHandle, {
success: false,
result: errorResult.content,
error: authResult.message
});
return this._attachRecordIdToResult(errorResult, recordHandle);
}
}
// 检查插件是否存在
if (!this.pluginManager.getPlugin(name)) {
const message = `未找到名为 "${name}" 的插件`;
const errorResult = this._createErrorResult(name, message);
toolCallRecordStore.finishRecord(recordHandle, {
success: false,
result: errorResult.content,
error: message
});
return this._attachRecordIdToResult(errorResult, recordHandle);
}
// 执行插件
try {
if (this.debugMode) console.log(`[ToolExecutor] Calling processToolCall for ${name} with args keys: ${Object.keys(args).join(', ')}`);
const result = await this.pluginManager.processToolCall(name, args, clientIp, 'post', {
archeryNoReply: !!archeryNoReply,
toolCallRecordHandle: recordHandle
});
const processedResult = this._processResult(name, result);
toolCallRecordStore.finishRecord(recordHandle, {
success: true,
result
});
return this._attachRecordIdToResult(processedResult, recordHandle);
} catch (error) {
const errorResult = this._createErrorResult(name, `执行错误: ${error.message}`);
toolCallRecordStore.finishRecord(recordHandle, {
success: false,
result: errorResult.content,
error
});
return this._attachRecordIdToResult(errorResult, recordHandle);
}
}
/**
* 批量执行工具调用
*/
async executeAll(toolCalls, clientIp, contextMessages = []) {
return Promise.all(
toolCalls.map(tc => this.execute(tc, clientIp, contextMessages))
);
}
_attachRecordIdToResult(result, recordHandle) {
if (!recordHandle || !recordHandle.id || !result || typeof result !== 'object') {
return result;
}
result.recordId = recordHandle.id;
if (result.raw && typeof result.raw === 'object' && !result.raw.tool_call_record_id) {
result.raw.tool_call_record_id = recordHandle.id;
}
return result;
}
_processResult(toolName, result) {
const formatted = this._formatResult(result);
// WebSocket广播:即使是 archery no-reply 静默结果,也保留 VCPLog 可见性。
this._broadcast(toolName, 'success', formatted.text);
// archery no-reply 的“静默”只表示不回灌给 AI / 不触发二次 loop;
// 用户侧仍应通过 VCPInfo WS 看到工具已被接收,后续真实进度由插件自己的 VCPLog/VCPInfo 继续推送。
if (result && typeof result === 'object' && result.__vcpArcheryNoReplySilent) {
try {
const vcpLogFunctions = this.pluginManager?.getVCPLogFunctions?.();
if (vcpLogFunctions && typeof vcpLogFunctions.pushVcpInfo === 'function') {
vcpLogFunctions.pushVcpInfo({
type: 'TOOL_NO_REPLY_ACCEPTED',
toolName,
status: 'success',
noReply: true,
message: result.message || `Async no-reply tool "${toolName}" accepted silently.`,
timestamp: new Date().toISOString()
});
}
} catch (broadcastError) {
if (this.debugMode) {
console.warn(`[ToolExecutor] Failed to broadcast no-reply VCPInfo for ${toolName}: ${broadcastError.message}`);
}
}
}
return {
success: true,
content: formatted.content,
raw: result
};
}
_formatResult(result) {
if (result === undefined || result === null) {
return { text: '(无返回内容)', content: [{ type: 'text', text: '(无返回内容)' }] };
}
// 检查是否为富内容格式
if (typeof result === 'object') {
const richContent = result.data?.content || result.content;
if (Array.isArray(richContent)) {
const textPart = richContent.find(p => p.type === 'text');
return {
text: textPart?.text || '[Rich Content]',
content: richContent
};
}
}
const text = typeof result === 'object'
? JSON.stringify(result, null, 2)
: String(result);
return {
text,
content: [{ type: 'text', text }]
};
}
_createErrorResult(toolName, message) {
this._broadcast(toolName, 'error', message);
return {
success: false,
error: message,
content: [{ type: 'text', text: `[错误] ${message}` }]
};
}
_broadcast(toolName, status, content) {
this.webSocketServer.broadcast({
type: 'vcp_log',
data: { tool_name: toolName, status, content }
}, 'VCPLog');
}
async _scheduleTimedToolCall(toolCall) {
const { name, args } = toolCall;
const timelyContact = args?.timely_contact;
const targetDate = this._parseAndValidateTimedContact(timelyContact);
if (!targetDate) {
return this._createErrorResult(name, `无效的 'timely_contact' 时间格式: '${timelyContact}'。请使用 YYYY-MM-DD-HH:mm 格式,或可被 Date 解析的未来时间。`);
}
if (targetDate === 'past') {
return this._createErrorResult(name, `无效的 'timely_contact' 时间: '${timelyContact}'。不能设置为过去或当前时间。`);
}
if (!this.pluginManager.getPlugin(name)) {
return this._createErrorResult(name, `未找到名为 "${name}" 的插件`);
}
const scheduledArgs = JSON.parse(JSON.stringify(args || {}));
const requestedAt = this._formatToLocalDateTimeWithOffset(new Date());
const taskId = `task-${targetDate.getTime()}-${crypto.randomUUID ? crypto.randomUUID() : crypto.randomBytes(16).toString('hex')}`;
const taskData = {
taskId,
createdAt: requestedAt,
scheduledLocalTime: this._formatToLocalDateTimeWithOffset(targetDate),
tool_call: {
tool_name: name,
arguments: scheduledArgs
},
requestor: `ToolExecutor: ${name}`
};
try {
await fs.mkdir(VCP_TIMED_CONTACTS_DIR, { recursive: true });
const taskFilePath = path.join(VCP_TIMED_CONTACTS_DIR, `${taskId}.json`);
await fs.writeFile(taskFilePath, JSON.stringify(taskData, null, 2), 'utf-8');
const receipt = `任务已成功调度。\n工具: ${name}\n任务ID: ${taskId}\n发起时间: ${requestedAt}\n计划时间: ${taskData.scheduledLocalTime}\n到点执行时系统会注入 __vcp_timed_call 标准元信息。`;
this._broadcast(name, 'success', receipt);
return {
success: true,
content: [{ type: 'text', text: receipt }],
raw: {
status: 'success',
scheduled: true,
taskId,
tool_name: name,
requestedAt,
scheduledTime: taskData.scheduledLocalTime
}
};
} catch (error) {
return this._createErrorResult(name, `创建定时任务失败: ${error.message}`);
}
}
_parseAndValidateTimedContact(value) {
if (!value) return null;
const raw = String(value).trim();
const standardized = raw.replace(/[\/\.]/g, '-');
const compactMatch = standardized.match(/^(\d{4})-(\d{1,2})-(\d{1,2})-(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?$/);
let date;
if (compactMatch) {
const [, yearRaw, monthRaw, dayRaw, hourRaw, minuteRaw, secondRaw] = compactMatch;
const year = Number(yearRaw);
const month = Number(monthRaw);
const day = Number(dayRaw);
const hour = Number(hourRaw);
const minute = Number(minuteRaw);
const second = secondRaw === undefined ? 0 : Number(secondRaw);
date = new Date(year, month - 1, day, hour, minute, second);
if (
date.getFullYear() !== year ||
date.getMonth() !== month - 1 ||
date.getDate() !== day ||
date.getHours() !== hour ||
date.getMinutes() !== minute ||
date.getSeconds() !== second
) {
return null;
}
} else {
date = new Date(raw);
if (Number.isNaN(date.getTime())) return null;
}
if (date.getTime() <= Date.now()) return 'past';
return date;
}
_formatToLocalDateTimeWithOffset(date) {
const pad = (value, length = 2) => String(value).padStart(length, '0');
const timezoneOffsetMinutes = date.getTimezoneOffset();
const offsetSign = timezoneOffsetMinutes > 0 ? '-' : '+';
const offsetHours = pad(Math.floor(Math.abs(timezoneOffsetMinutes) / 60));
const offsetMinutes = pad(Math.abs(timezoneOffsetMinutes) % 60);
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}${offsetSign}${offsetHours}:${offsetMinutes}`;
}
async _verifyAuth(args) {
const realCode = await this.getRealAuthCode(this.debugMode);
const provided = args.tool_password;
delete args.tool_password;
if (!realCode || provided !== realCode) {
return { valid: false, message: 'tool_password 验证失败' };
}
return { valid: true };
}
}
module.exports = ToolExecutor;