@cherrystudio/ai-core
Version:
Cherry Studio AI Core - Unified AI Provider Interface Based on Vercel AI SDK
41 lines (40 loc) • 4.42 kB
text/typescript
import { S as WebSearchPluginConfig, h as ToolCapability, x as OpenRouterSearchConfig } from "../../index-CCQe5Cuy.mjs";
import { n as AiPlugin, o as StreamTextParams, r as AiRequestContext, s as StreamTextResult } from "../../index-C18YloeF.mjs";
import { ToolSet } from "ai";
//#region src/core/plugins/built-in/providerToolPlugin.d.ts
declare const providerToolPlugin: (capability: ToolCapability, config?: Record<string, any>) => AiPlugin<any, unknown>;
//#endregion
//#region src/core/plugins/built-in/toolUsePlugin/type.d.ts
/**
* 解析结果类型
* 表示从AI响应中解析出的工具使用意图
*/
interface ToolUseResult {
id: string;
toolName: string;
arguments: any;
status: 'pending' | 'invoking' | 'done' | 'error';
}
interface BaseToolUsePluginConfig {
enabled?: boolean;
}
interface PromptToolUseConfig extends BaseToolUsePluginConfig {
buildSystemPrompt?: (userSystemPrompt: string, tools: ToolSet) => string;
parseToolUse?: (content: string, tools: ToolSet) => {
results: ToolUseResult[];
content: string;
};
mcpMode?: string;
}
/**
* 扩展的 AI 请求上下文,支持 MCP 工具存储
*/
interface ToolUseRequestContext extends AiRequestContext {
mcpTools: ToolSet;
}
//#endregion
//#region src/core/plugins/built-in/toolUsePlugin/promptToolUsePlugin.d.ts
declare const DEFAULT_SYSTEM_PROMPT = "In this environment you have access to a set of tools you can use to answer the user's question. You can use one or more tools per message, and will receive the result of that tool use in the user's response. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use.\n\n## Tool Use Formatting\n\nTool use is formatted using XML-style tags. The tool name is enclosed in opening and closing tags, and each parameter is similarly enclosed within its own set of tags. Here's the structure:\n\n<tool_use>\n <name>{tool_name}</name>\n <arguments>{json_arguments}</arguments>\n</tool_use>\n\nThe tool name should be the exact name of the tool you are using, and the arguments should be a JSON object containing the parameters required by that tool. IMPORTANT: When writing JSON inside the <arguments> tag, any double quotes inside string values must be escaped with a backslash (\"). For example:\n<tool_use>\n <name>search</name>\n <arguments>{ \"query\": \"browser,fetch\" }</arguments>\n</tool_use>\n\n<tool_use>\n <name>exec</name>\n <arguments>{ \"code\": \"const page = await CherryBrowser_fetch({ url: \\\"https://example.com\\\" })\nreturn page\" }</arguments>\n</tool_use>\n\n\nThe user will respond with the result of the tool use, which should be formatted as follows:\n\n<tool_use_result>\n <name>{tool_name}</name>\n <result>{result}</result>\n</tool_use_result>\n\nThe result should be a string, which can represent a file or any other output type. You can use this result as input for the next action.\nFor example, if the result of the tool use is an image file, you can use it in the next action like this:\n\n<tool_use>\n <name>image_transformer</name>\n <arguments>{\"image\": \"image_1.jpg\"}</arguments>\n</tool_use>\n\nAlways adhere to this format for the tool use to ensure proper parsing and execution.\n\n## Tool Use Rules\nHere are the rules you should always follow to solve your task:\n1. Always use the right arguments for the tools. Never use variable names as the action arguments, use the value instead.\n2. Call a tool only when needed: do not call the search agent if you do not need information, try to solve the task yourself.\n3. If no tool call is needed, just answer the question directly.\n4. Never re-do a tool call that you previously did with the exact same parameters.\n5. For tool use, MAKE SURE use XML tag format as shown in the examples above. Do not use any other format.\n\n{{ TOOLS_INFO }}\n\n## Response rules\n\nRespond in the language of the user's query, unless the user instructions specify additional requirements for the language to be used.\n\n# User Instructions\n{{ USER_SYSTEM_PROMPT }}\n";
declare const createPromptToolUsePlugin: (config?: PromptToolUseConfig) => AiPlugin<StreamTextParams, StreamTextResult>;
//#endregion
export { BaseToolUsePluginConfig, DEFAULT_SYSTEM_PROMPT, OpenRouterSearchConfig, PromptToolUseConfig, ToolUseRequestContext, ToolUseResult, WebSearchPluginConfig, createPromptToolUsePlugin, providerToolPlugin };