* feat(canvas): 参考素材 - 增加移除按钮并删除对应连线 * feat(canvas): 完善节点面板交互与拖拽反馈 * fix(canvas): 画布交互与小地图 - 统一浮层层级并完善节点识别 * feat(prompt-optimizer): 增加 AI 提示词优化器及宿主接入 * feat(canvas): 画布 - 增加自动整理节点按钮并补充文档 * chore(web): 前端 - 修正提示词优化器格式 * chore(backend): 后端 - 修正 Go 格式检查 * feat(workspace): 完善诊断导出与本地排障支持 * chore(web): 格式化诊断导出文件 * fix(web-test): 兼容 Bun 测试运行时 * fix(web-test): 对齐模型目录协议断言
36 lines
1.8 KiB
TypeScript
36 lines
1.8 KiB
TypeScript
import { requestToolResponse, type ResponseFunctionTool, type ResponseInputMessage, type ToolChoice } from "@/services/api/image";
|
|
import { pluginStorageFor } from "@/lib/plugins/plugin-storage";
|
|
import type { AiConfig } from "@/stores/use-config-store";
|
|
import type { PluginHostContext, PluginInstallation, PluginTextRequest, RegisteredPlugin } from "@/lib/plugins/plugin-types";
|
|
|
|
export function createPluginHostContext(plugin: RegisteredPlugin, installation: PluginInstallation, aiConfig: AiConfig): PluginHostContext {
|
|
const permissions = new Set(plugin.manifest.permissions);
|
|
return {
|
|
manifest: plugin.manifest,
|
|
permissions,
|
|
storage: pluginStorageFor(plugin.manifest.id),
|
|
config: installation.config,
|
|
services: {
|
|
ai: {
|
|
text: {
|
|
requestToolResponse: async (request: PluginTextRequest) => {
|
|
if (!permissions.has("ai.text")) throw new Error("插件没有调用文本模型的权限");
|
|
const response = await requestToolResponse(
|
|
{ ...aiConfig, model: request.model?.trim() || aiConfig.textModel },
|
|
request.messages as ResponseInputMessage[],
|
|
(request.tools || []) as ResponseFunctionTool[],
|
|
(request.toolChoice || "auto") as ToolChoice,
|
|
request.onDelta,
|
|
{ signal: request.signal },
|
|
);
|
|
return {
|
|
content: response.content,
|
|
toolCalls: response.toolCalls.map((call) => ({ name: call.function.name, arguments: call.function.arguments })),
|
|
};
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
}
|