MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / execute

Method execute

ai/ai.ts:4559–4691  ·  view source on GitHub ↗
(
    msg: Api.Message,
    args: string[],
    _prefixes: string[],
  )

Source from the content-addressed store, hash-verified

4557
4558 async execute(
4559 msg: Api.Message,
4560 args: string[],
4561 _prefixes: string[],
4562 ): Promise<void> {
4563 const prefixes = getPrefixes();
4564 const config = await this.getConfig();
4565
4566 const promptInput = args.slice(1).join(" ").trim();
4567
4568 const replyMsg = await safeGetReplyMessage(msg);
4569 requireUser(!!promptInput || !!replyMsg, "至少需要一条提示");
4570
4571 if (
4572 !config.currentSearchTag ||
4573 !config.currentSearchModel ||
4574 !config.configs[config.currentSearchTag]
4575 ) {
4576 throw new UserError(
4577 `请先配置 API 并设置模型\n使用 ${prefixes[0]}ai config add <tag> <url> <key> [type] 和 ${prefixes[0]}ai model search <tag> <model-path>`,
4578 );
4579 }
4580
4581 await sendProcessing(msg, "search");
4582
4583 const replyToId = replyMsg?.id;
4584
4585 let context = getMessageText(replyMsg);
4586 const imageParts = [
4587 ...(await getMessageImageParts(replyMsg)),
4588 ...(await getMessageImageParts(msg)),
4589 ];
4590
4591 const normalizedPrompt = promptInput.trim();
4592 const normalizedContext = (context || "").trim();
4593
4594 if (
4595 normalizedPrompt &&
4596 normalizedContext &&
4597 normalizedPrompt === normalizedContext
4598 ) {
4599 context = "";
4600 }
4601
4602 const userText = context
4603 ? `上下文:\n${context}\n\n问题:\n${promptInput}`
4604 : promptInput;
4605
4606 const token = this.aiService.createAbortToken();
4607 try {
4608 const { text, sources } = await this.aiService.callSearch(
4609 userText,
4610 imageParts,
4611 token,
4612 );
4613
4614 const sourcesText =
4615 sources && sources.length > 0
4616 ? "\n\n<b>🔗 Sources</b>\n" +

Callers

nothing calls this directly

Calls 15

sendProcessingFunction · 0.85
getMessageImagePartsFunction · 0.85
deleteMessageOrGroupFunction · 0.85
createAbortTokenMethod · 0.80
callSearchMethod · 0.80
getConfigManagerMethod · 0.80
releaseTokenMethod · 0.80
requireUserFunction · 0.70
getMessageTextFunction · 0.70
htmlEscapeFunction · 0.70
getConfigMethod · 0.45
createTelegraphPageMethod · 0.45

Tested by

no test coverage detected