From be641197b53913c400e97f59087789aa882591c8 Mon Sep 17 00:00:00 2001 From: Kirigaya <1193466151@qq.com> Date: Fri, 20 Jun 2025 18:19:20 +0800 Subject: [PATCH] add prompt reader --- .../main-panel/chat/core/task-loop.ts | 10 ++++++ resources/openmcp-sdk-release/task-loop.d.ts | 36 ++++++++++++------- service/src/hook/adapter.ts | 24 +++++++++---- service/task-loop.d.ts | 10 ++++++ 4 files changed, 61 insertions(+), 19 deletions(-) diff --git a/renderer/src/components/main-panel/chat/core/task-loop.ts b/renderer/src/components/main-panel/chat/core/task-loop.ts index 7138532..a2048dc 100644 --- a/renderer/src/components/main-panel/chat/core/task-loop.ts +++ b/renderer/src/components/main-panel/chat/core/task-loop.ts @@ -783,4 +783,14 @@ export class TaskLoop { settings: _settings } } + + public async getPrompt(promptId: string, args: Record) { + const prompt = await mcpClientAdapter.readPromptTemplate(promptId, args); + return prompt; + } + + public async getResource(resourceUri: string) { + const resource = await mcpClientAdapter.readResource(resourceUri); + return resource; + } } \ No newline at end of file diff --git a/resources/openmcp-sdk-release/task-loop.d.ts b/resources/openmcp-sdk-release/task-loop.d.ts index 03f07b6..e66729c 100644 --- a/resources/openmcp-sdk-release/task-loop.d.ts +++ b/resources/openmcp-sdk-release/task-loop.d.ts @@ -5,25 +5,25 @@ export type ChatCompletionChunk = OpenAI.Chat.Completions.ChatCompletionChunk; export type ChatCompletionCreateParamsBase = OpenAI.Chat.Completions.ChatCompletionCreateParams & { id?: string }; interface SchemaProperty { - title: string; - type: string; - description?: string; + title: string; + type: string; + description?: string; } interface InputSchema { - type: string; - properties: Record; - required?: string[]; - title?: string; - $defs?: any; + type: string; + properties: Record; + required?: string[]; + title?: string; + $defs?: any; } interface ToolItem { - name: string; - description: string; - inputSchema: InputSchema; + name: string; + description: string; + inputSchema: InputSchema; enabled: boolean; - anyOf?: any; + anyOf?: any; } interface IExtraInfo { @@ -87,7 +87,7 @@ export interface ToolCall { export interface ToolCallContent { type: string; text: string; - [key: string]: any; + [key: string]: any; } export interface ToolCallResult { @@ -290,6 +290,16 @@ export class TaskLoop { * @description Create single conversation context */ createStorage(settings?: ChatSetting): Promise; + + /** + * @description Get prompt template from mcp server + */ + getPrompt(promptId: string, args: Record): Promise; + + /** + * @description Get resource template from mcp server + */ + getResource(resourceUri: string): Promise; } export declare const getToolSchema: any; diff --git a/service/src/hook/adapter.ts b/service/src/hook/adapter.ts index 7c0e957..234645a 100644 --- a/service/src/hook/adapter.ts +++ b/service/src/hook/adapter.ts @@ -164,7 +164,8 @@ interface StdioMCPConfig { [key: string]: string; }; description?: string; - prompt?: string; + prompts?: string[]; + resources?: string[]; } interface HttpMCPConfig { @@ -174,7 +175,8 @@ interface HttpMCPConfig { [key: string]: string; }; description?: string; - prompt?: string; + prompts?: string[]; + resources?: string[]; } export interface OmAgentConfiguration { @@ -255,8 +257,7 @@ export class OmAgent { * "OPENMEMORY_API_KEY": "YOUR_API_KEY", * "CLIENT_NAME": "openmemory" * }, - * "description": "A MCP for long-term memory support", - * "prompt": "You are a helpful assistant." + * "description": "A MCP for long-term memory support" * } * }, * "defaultLLM": { @@ -287,7 +288,6 @@ export class OmAgent { connectionType: 'STDIO', env: mcpConfig.env, description: mcpConfig.description, - prompt: mcpConfig.prompt, }); } else { const connectionType: ConnectionType = mcpConfig.type === 'http' ? 'STREAMABLE_HTTP' : 'SSE'; @@ -296,12 +296,18 @@ export class OmAgent { env: mcpConfig.env, connectionType, description: mcpConfig.description, - prompt: mcpConfig.prompt, }); } } } + /** + * @description Add MCP server + */ + public addMcpServer(connectionArgs: IConnectionArgs) { + this._adapter.addMcp(connectionArgs); + } + private async getLoop(loopOption?: TaskLoopOptions) { if (this._loop) { return this._loop; @@ -324,6 +330,12 @@ export class OmAgent { this._defaultLLM = option; } + public async getPrompt(promptId: string, args: Record) { + const loop = await this.getLoop(); + const prompt = await loop.getPrompt(promptId, args); + return prompt; + } + /** * @description Asynchronous invoking agent by string or messages * @param messages Chat message or string diff --git a/service/task-loop.d.ts b/service/task-loop.d.ts index 03f07b6..06af785 100644 --- a/service/task-loop.d.ts +++ b/service/task-loop.d.ts @@ -290,6 +290,16 @@ export class TaskLoop { * @description Create single conversation context */ createStorage(settings?: ChatSetting): Promise; + + /** + * @description Get prompt template from mcp server + */ + getPrompt(promptId: string, args: Record): Promise; + + /** + * @description Get resource template from mcp server + */ + getResource(resourceUri: string): Promise; } export declare const getToolSchema: any;