agentdev 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{BasicAgent-UDSHJE5H.js → BasicAgent-QWEYCLV5.js} +3 -3
- package/dist/{ExplorerAgent-BITN4IBW.js → ExplorerAgent-4IT22VB7.js} +3 -3
- package/dist/{chunk-XCJOXCJ4.js → chunk-F3PR7UTL.js} +2 -2
- package/dist/{chunk-VYY63N2T.js → chunk-LLV3W326.js} +24 -4
- package/dist/{chunk-VYY63N2T.js.map → chunk-LLV3W326.js.map} +1 -1
- package/dist/{chunk-XE5IEUPW.js → chunk-LQTEETML.js} +2 -2
- package/dist/{chunk-4FBF65TC.js → chunk-OBOU27DM.js} +245 -239
- package/dist/chunk-OBOU27DM.js.map +1 -0
- package/dist/cli/server.js +1 -1
- package/dist/cli/viewer.js +1 -1
- package/dist/index.d.ts +45 -1
- package/dist/index.js +20 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-4FBF65TC.js.map +0 -1
- /package/dist/{BasicAgent-UDSHJE5H.js.map → BasicAgent-QWEYCLV5.js.map} +0 -0
- /package/dist/{ExplorerAgent-BITN4IBW.js.map → ExplorerAgent-4IT22VB7.js.map} +0 -0
- /package/dist/{chunk-XCJOXCJ4.js.map → chunk-F3PR7UTL.js.map} +0 -0
- /package/dist/{chunk-XE5IEUPW.js.map → chunk-LQTEETML.js.map} +0 -0
package/dist/cli/server.js
CHANGED
package/dist/cli/viewer.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -493,6 +493,9 @@ interface Logger {
|
|
|
493
493
|
namespace?: string;
|
|
494
494
|
}): Logger;
|
|
495
495
|
}
|
|
496
|
+
declare function installConsoleBridge(): void;
|
|
497
|
+
declare function runWithLogScope<T>(scope: LogContextRef, fn: () => T): T;
|
|
498
|
+
declare function createLogger(namespace: string, bindings?: LoggerBindings): Logger;
|
|
496
499
|
|
|
497
500
|
/**
|
|
498
501
|
* Feature 上下文值类型
|
|
@@ -1643,6 +1646,47 @@ declare class SkillFeature implements AgentFeature {
|
|
|
1643
1646
|
* 返回 void(仅做处理,不控制流程)
|
|
1644
1647
|
*/
|
|
1645
1648
|
declare const CallStart: (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
1649
|
+
/**
|
|
1650
|
+
* Call 结束装饰器
|
|
1651
|
+
*
|
|
1652
|
+
* 标记在 Call 结束时执行的方法
|
|
1653
|
+
* 返回 void(仅做处理,不控制流程)
|
|
1654
|
+
*/
|
|
1655
|
+
declare const CallFinish: (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
1656
|
+
/**
|
|
1657
|
+
* Step 开始装饰器
|
|
1658
|
+
*
|
|
1659
|
+
* 标记在 Step 开始时执行的方法
|
|
1660
|
+
* 返回 void(仅做处理,不控制流程)
|
|
1661
|
+
*/
|
|
1662
|
+
declare const StepStart: (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
1663
|
+
/**
|
|
1664
|
+
* Step 结束装饰器
|
|
1665
|
+
*
|
|
1666
|
+
* 标记在 Step 结束时执行的方法
|
|
1667
|
+
* 返回 DecisionResult(有流程控制能力)
|
|
1668
|
+
* - Decision.Approve: 继续循环(即使无工具调用)
|
|
1669
|
+
* - Decision.Deny: 结束循环
|
|
1670
|
+
* - Decision.Continue: 使用默认行为
|
|
1671
|
+
*/
|
|
1672
|
+
declare const StepFinish: (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
1673
|
+
/**
|
|
1674
|
+
* 工具使用装饰器
|
|
1675
|
+
*
|
|
1676
|
+
* 标记在工具使用前执行的方法
|
|
1677
|
+
* 返回 DecisionResult(有流程控制能力)
|
|
1678
|
+
* - Decision.Approve: 允许工具执行
|
|
1679
|
+
* - Decision.Deny: 阻止工具执行(返回错误)
|
|
1680
|
+
* - Decision.Continue: 使用默认行为(允许执行)
|
|
1681
|
+
*/
|
|
1682
|
+
declare const ToolUse: (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
1683
|
+
/**
|
|
1684
|
+
* 工具完成装饰器
|
|
1685
|
+
*
|
|
1686
|
+
* 标记在工具执行完成后执行的方法
|
|
1687
|
+
* 返回 void(仅做处理,不控制流程)
|
|
1688
|
+
*/
|
|
1689
|
+
declare const ToolFinished: (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
1646
1690
|
|
|
1647
1691
|
/**
|
|
1648
1692
|
* AgentPool - 子代理管理核心
|
|
@@ -3096,4 +3140,4 @@ declare function renderMCPToolCall(serverName: string, toolName: string, args: R
|
|
|
3096
3140
|
*/
|
|
3097
3141
|
declare function renderMCPToolResult(result: any, success?: boolean): string;
|
|
3098
3142
|
|
|
3099
|
-
export { AgentBase as Agent, AgentConfig, type AgentConfigFile, type AgentFeature, AgentInfo, type AgentInitiateContext, AgentPool, AgentSession, type AgentSessionSnapshot, AnthropicLLM, BasicAgent, type BasicAgentConfig, CallStart, type CallStartContext, Context, type ContextInjector, DataSourceRegistry, type DataSourceRenderer, type DebugCapabilities, DebugHub, ExampleFeature, type ExampleFeatureConfig, type ExampleFeatureRuntimeState, type ExampleFeatureSnapshot, ExplorerAgent, type ExplorerAgentConfig, type SystemContext as ExplorerSystemContext, type FeatureContext, type FeatureInitContext, type FeatureStateSnapshot, FileSessionStore, type HookResult, InlineRenderTemplate, LLMClient, LLMResponse, type LoadAllMCPConfigsOptions, MCPClient, type MCPClientConfig, type MCPConfig, type MCPConfigMountOptions, type MCPConnectionInfo, MCPConnectionManager, MCPConnectionState, type MCPDiscoveredTool, type MCPDiscoveredToolSet, MCPFeature, type MCPFeatureOptions, type MCPHTTPConfig, type MCPMountedConfigResult, type MCPMountedToolSet, type MCPSSEConfig, type MCPServerConfig, type MCPSstdioConfig, type MCPStatistics, MCPToolAdapter, type MCPToolAdapterConfig, type MCPToolCreationOptions, type MCPToolDiscoveryOptions, type MCPToolManagementOptions, type MCPToolPatch, type MCPToolResult, MCP_RENDER_TEMPLATES, Message, MessageRole, type ModelConfig, OpenAILLM, OpencodeBasicFeature, type PackageInfo, PlaceholderContext, PlaceholderResolver, type SessionStore, SkillFeature, type SkillFeatureConfig, type SkillMetadata, type SkillsOptions, SubAgentFeature, type SystemContext$1 as SystemContext, type TaskStatus, TemplateLoader, TemplateSource, TodoFeature, type TodoFeatureConfig, type TodoTask, type TodoTaskSummary, Tool, ToolCall, type ToolContext, type ToolContextValue, ToolRegistry, ToolRenderConfig, type ToolResult, UserInputFeature, type UserInputFeatureConfig, ViewerWorker, assistant, compileContextForAnthropic, createAnthropicLLM, createDefaultMCPToolName, createLLM, createListRenderer, createMCPTool, createMCPToolAdapters, createMCPToolsFromClient, createManagedMCPToolsFromClient, createMessage, createOpenAILLM, createTool, discover, discoverMCPTools, discoverManagedMCPTools, getClawRuntimeUrl, getDebugCapabilities, getDefaultMCPConfigDir, getDefaultSessionStore, getMCPRenderTemplate, getPackageInfoFromSource, listConfigs, loadAllMCPConfigs, loadConfig, loadConfigSync, loadMCPConfigFromInput, mountMCPToolsFromConfig, renderMCPToolCall, renderMCPToolResult, resolveDebugTransportMode, system, toolResult, user };
|
|
3143
|
+
export { AgentBase as Agent, AgentConfig, type AgentConfigFile, type AgentFeature, AgentInfo, type AgentInitiateContext, AgentPool, AgentSession, type AgentSessionSnapshot, AnthropicLLM, BasicAgent, type BasicAgentConfig, CallFinish, type CallFinishContext, CallStart, type CallStartContext, Context, type ContextInjector, DataSourceRegistry, type DataSourceRenderer, type DebugCapabilities, DebugHub, Decision, type DecisionResult, ExampleFeature, type ExampleFeatureConfig, type ExampleFeatureRuntimeState, type ExampleFeatureSnapshot, ExplorerAgent, type ExplorerAgentConfig, type SystemContext as ExplorerSystemContext, type FeatureContext, type FeatureInitContext, type FeatureStateSnapshot, FileSessionStore, type HookResult, InlineRenderTemplate, LLMClient, LLMResponse, type LoadAllMCPConfigsOptions, type Logger, type LoggerBindings, MCPClient, type MCPClientConfig, type MCPConfig, type MCPConfigMountOptions, type MCPConnectionInfo, MCPConnectionManager, MCPConnectionState, type MCPDiscoveredTool, type MCPDiscoveredToolSet, MCPFeature, type MCPFeatureOptions, type MCPHTTPConfig, type MCPMountedConfigResult, type MCPMountedToolSet, type MCPSSEConfig, type MCPServerConfig, type MCPSstdioConfig, type MCPStatistics, MCPToolAdapter, type MCPToolAdapterConfig, type MCPToolCreationOptions, type MCPToolDiscoveryOptions, type MCPToolManagementOptions, type MCPToolPatch, type MCPToolResult, MCP_RENDER_TEMPLATES, Message, MessageRole, type ModelConfig, OpenAILLM, OpencodeBasicFeature, type PackageInfo, PlaceholderContext, PlaceholderResolver, type SessionStore, SkillFeature, type SkillFeatureConfig, type SkillMetadata, type SkillsOptions, StepFinish, type StepFinishedContext, StepStart, type StepStartContext, SubAgentFeature, type SystemContext$1 as SystemContext, type TaskStatus, TemplateLoader, TemplateSource, TodoFeature, type TodoFeatureConfig, type TodoTask, type TodoTaskSummary, Tool, ToolCall, type ToolContext, type ToolContextValue, ToolFinished, ToolRegistry, ToolRenderConfig, type ToolResult, ToolUse, UserInputFeature, type UserInputFeatureConfig, ViewerWorker, assistant, compileContextForAnthropic, createAnthropicLLM, createDefaultMCPToolName, createLLM, createListRenderer, createLogger, createMCPTool, createMCPToolAdapters, createMCPToolsFromClient, createManagedMCPToolsFromClient, createMessage, createOpenAILLM, createTool, discover, discoverMCPTools, discoverManagedMCPTools, getClawRuntimeUrl, getDebugCapabilities, getDefaultMCPConfigDir, getDefaultSessionStore, getMCPRenderTemplate, getPackageInfoFromSource, installConsoleBridge, listConfigs, loadAllMCPConfigs, loadConfig, loadConfigSync, loadMCPConfigFromInput, mountMCPToolsFromConfig, renderMCPToolCall, renderMCPToolResult, resolveDebugTransportMode, runWithLogScope, system, toolResult, user };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BasicAgent
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-LQTEETML.js";
|
|
4
4
|
import {
|
|
5
5
|
ExplorerAgent
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-F3PR7UTL.js";
|
|
7
7
|
import {
|
|
8
8
|
AgentBase,
|
|
9
9
|
AgentPool,
|
|
10
10
|
AnthropicLLM,
|
|
11
|
+
CallFinish,
|
|
11
12
|
CallStart,
|
|
12
13
|
Context,
|
|
13
14
|
DataSourceRegistry,
|
|
@@ -21,11 +22,15 @@ import {
|
|
|
21
22
|
OpenAILLM,
|
|
22
23
|
OpencodeBasicFeature,
|
|
23
24
|
SkillFeature,
|
|
25
|
+
StepFinish,
|
|
26
|
+
StepStart,
|
|
24
27
|
SubAgentFeature,
|
|
25
28
|
TemplateComposer,
|
|
26
29
|
TemplateLoader,
|
|
27
30
|
TodoFeature,
|
|
31
|
+
ToolFinished,
|
|
28
32
|
ToolRegistry,
|
|
33
|
+
ToolUse,
|
|
29
34
|
UserInputFeature,
|
|
30
35
|
assistant,
|
|
31
36
|
compileContextForAnthropic,
|
|
@@ -33,6 +38,7 @@ import {
|
|
|
33
38
|
createDefaultMCPToolName,
|
|
34
39
|
createLLM,
|
|
35
40
|
createListRenderer,
|
|
41
|
+
createLogger,
|
|
36
42
|
createMCPTool,
|
|
37
43
|
createMCPToolAdapters,
|
|
38
44
|
createMCPToolsFromClient,
|
|
@@ -46,16 +52,18 @@ import {
|
|
|
46
52
|
getDefaultMCPConfigDir,
|
|
47
53
|
getDefaultSessionStore,
|
|
48
54
|
getPackageInfoFromSource,
|
|
55
|
+
installConsoleBridge,
|
|
49
56
|
listConfigs,
|
|
50
57
|
loadAllMCPConfigs,
|
|
51
58
|
loadConfig,
|
|
52
59
|
loadConfigSync,
|
|
53
60
|
loadMCPConfigFromInput,
|
|
54
61
|
mountMCPToolsFromConfig,
|
|
62
|
+
runWithLogScope,
|
|
55
63
|
system,
|
|
56
64
|
toolResult,
|
|
57
65
|
user
|
|
58
|
-
} from "./chunk-
|
|
66
|
+
} from "./chunk-OBOU27DM.js";
|
|
59
67
|
import {
|
|
60
68
|
PlaceholderResolver
|
|
61
69
|
} from "./chunk-BVF7RUXV.js";
|
|
@@ -67,7 +75,7 @@ import {
|
|
|
67
75
|
} from "./chunk-3BPSNNK3.js";
|
|
68
76
|
import {
|
|
69
77
|
ViewerWorker
|
|
70
|
-
} from "./chunk-
|
|
78
|
+
} from "./chunk-LLV3W326.js";
|
|
71
79
|
import {
|
|
72
80
|
getDefaultUDSPath
|
|
73
81
|
} from "./chunk-TSASFMRF.js";
|
|
@@ -209,6 +217,7 @@ export {
|
|
|
209
217
|
AgentPool,
|
|
210
218
|
AnthropicLLM,
|
|
211
219
|
BasicAgent,
|
|
220
|
+
CallFinish,
|
|
212
221
|
CallStart,
|
|
213
222
|
Context,
|
|
214
223
|
DataSourceRegistry,
|
|
@@ -226,12 +235,16 @@ export {
|
|
|
226
235
|
OpencodeBasicFeature,
|
|
227
236
|
PlaceholderResolver,
|
|
228
237
|
SkillFeature,
|
|
238
|
+
StepFinish,
|
|
239
|
+
StepStart,
|
|
229
240
|
SubAgentFeature,
|
|
230
241
|
TemplateComposer,
|
|
231
242
|
TemplateError,
|
|
232
243
|
TemplateLoader,
|
|
233
244
|
TodoFeature,
|
|
245
|
+
ToolFinished,
|
|
234
246
|
ToolRegistry,
|
|
247
|
+
ToolUse,
|
|
235
248
|
UserInputFeature,
|
|
236
249
|
ViewerWorker,
|
|
237
250
|
assistant,
|
|
@@ -240,6 +253,7 @@ export {
|
|
|
240
253
|
createDefaultMCPToolName,
|
|
241
254
|
createLLM,
|
|
242
255
|
createListRenderer,
|
|
256
|
+
createLogger,
|
|
243
257
|
createMCPTool,
|
|
244
258
|
createMCPToolAdapters,
|
|
245
259
|
createMCPToolsFromClient,
|
|
@@ -257,6 +271,7 @@ export {
|
|
|
257
271
|
getDefaultUDSPath,
|
|
258
272
|
getMCPRenderTemplate,
|
|
259
273
|
getPackageInfoFromSource,
|
|
274
|
+
installConsoleBridge,
|
|
260
275
|
listConfigs,
|
|
261
276
|
loadAllMCPConfigs,
|
|
262
277
|
loadConfig,
|
|
@@ -266,6 +281,7 @@ export {
|
|
|
266
281
|
renderMCPToolCall,
|
|
267
282
|
renderMCPToolResult,
|
|
268
283
|
resolveDebugTransportMode,
|
|
284
|
+
runWithLogScope,
|
|
269
285
|
system,
|
|
270
286
|
toolResult,
|
|
271
287
|
user
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/template/types.ts","../src/mcp/render.ts"],"sourcesContent":["/**\n * 提示词模板系统 - 核心类型定义\n */\n\n/**\n * 模板源\n * - string: 硬编码字符串\n * - { file: string }: 文件路径\n * - [dataSourceName: string]: 数据源名称(如 skills, tasks 等)\n * - TemplateComposer: 组合模板\n *\n * @example\n * ```typescript\n * // 静态字符串\n * 'Hello {{name}}'\n *\n * // 文件\n * { file: 'prompts/system.md' }\n *\n * // 数据源(列表渲染)\n * { skills: '- **{{name}}**: {{description}}' }\n * { tasks: '- [{{title}}](#{{id}}) ({{priority}})' }\n *\n * // 条件渲染\n * { conditional: { part: { file: 'advanced.md' }, condition: (ctx) => ctx.advanced } }\n * ```\n */\nexport type TemplateSource =\n | string\n | { file: string }\n | { conditional: ConditionalSource }\n | { [dataSourceName: string]: string } // 数据源 -> 模板\n | import('./composer.js').TemplateComposer;\n\n/**\n * 条件源配置\n */\nexport interface ConditionalSource {\n /** 条件模板源 */\n part: TemplateSource;\n /** 条件函数(true 时渲染) */\n condition: (context: PlaceholderContext) => boolean;\n}\n\n/**\n * 占位符上下文 - 变量替换的键值对\n * 支持原始类型和复杂对象(用于数据源渲染)\n */\nexport type PlaceholderContext = Record<string, string | number | boolean | undefined | object>;\n\n/**\n * 模板渲染结果\n */\nexport interface TemplateResult {\n /** 渲染后的内容 */\n content: string;\n /** 使用的源文件列表(用于调试) */\n sources: string[];\n}\n\n/**\n * 模板加载器配置\n */\nexport interface TemplateLoaderOptions {\n /** 缓存启用状态,默认 true */\n cacheEnabled?: boolean;\n /** 模板搜索目录(相对于项目根目录) */\n searchDirs?: string[];\n /** 项目根目录(自动检测) */\n projectRoot?: string;\n}\n\n/**\n * 缓存统计\n */\nexport interface CacheStats {\n size: number; // 缓存条目数\n hits: number; // 命中次数\n misses: number; // 未命中次数\n hitRate: number; // 命中率\n}\n\n/**\n * 模板相关错误\n */\nexport class TemplateError extends Error {\n constructor(\n message: string,\n public code:\n | 'FILE_NOT_FOUND'\n | 'INVALID_PATH'\n | 'READ_ERROR'\n | 'UNSUPPORTED_FORMAT',\n public path?: string\n ) {\n super(message);\n this.name = 'TemplateError';\n }\n}\n","/**\n * MCP 工具渲染模板\n *\n * 定义 MCP 工具在 DebugHub 中的显示样式\n */\n\n/**\n * 转义 HTML\n */\nfunction escapeHtml(text: any): string {\n const str = String(text);\n const map: Record<string, string> = {\n '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": ''',\n };\n return str.replace(/[&<>\"']/g, m => map[m]);\n}\n\n/**\n * MCP 工具渲染模板\n */\nexport const MCP_RENDER_TEMPLATES = {\n /**\n * MCP 工具调用显示\n */\n 'mcp-tool': {\n call: (args: any) => {\n const server = args._server || 'unknown';\n const name = args._name || 'unknown';\n return `\n <div class=\"bash-command\" style=\"\n border-left: 3px solid #ff6b6b;\n padding-left: 8px;\n margin: 4px 0;\n \">\n <span style=\"\n color: #ff6b6b;\n font-weight: bold;\n font-size: 11px;\n text-transform: uppercase;\n \">MCP</span>\n <span class=\"file-path\" style=\"color: #c068ff;\">${escapeHtml(server)}</span>\n <span style=\"color: #888;\">::</span>\n <span style=\"color: #fff;\">${escapeHtml(name)}</span>\n </div>\n `.trim();\n },\n result: (data: any, success = true) => {\n if (!success || data.error) {\n return `\n <div class=\"bash-output\" style=\"\n border-left: 3px solid #ff4444;\n padding-left: 8px;\n color: #ff6b6b;\n \">\n <div style=\"font-weight: bold; margin-bottom: 4px;\">MCP Error</div>\n <pre style=\"margin: 0; white-space: pre-wrap;\">${escapeHtml(data.error || 'Unknown error')}</pre>\n </div>\n `.trim();\n }\n\n let content = '';\n\n // 文本内容\n if (data.content) {\n content += `<pre class=\"bash-output\" style=\"max-height: 400px; overflow: auto;\">${escapeHtml(data.content)}</pre>`;\n }\n\n // 结构化数据\n if (data.structuredContent) {\n content += `<details style=\"margin-top: 8px;\">\n <summary style=\"cursor: pointer; color: var(--accent-color);\">Structured Data</summary>\n <pre style=\"margin: 4px 0; padding: 8px; background: var(--bg-secondary);\">${escapeHtml(JSON.stringify(data.structuredContent, null, 2))}</pre>\n </details>`;\n }\n\n // 图像\n if (data.images && data.images.length > 0) {\n content += `<div style=\"margin-top: 8px;\">`;\n data.images.forEach((img: any) => {\n content += `<img src=\"data:${img.mimeType};base64,${img.data}\" style=\"max-width: 100%; border-radius: 4px;\" />`;\n });\n content += `</div>`;\n }\n\n // 资源\n if (data.resources && data.resources.length > 0) {\n content += `<div style=\"margin-top: 8px;\">\n <div style=\"font-weight: bold; margin-bottom: 4px;\">Resources:</div>`;\n data.resources.forEach((res: any) => {\n content += `<div style=\"padding: 4px; background: var(--bg-secondary); margin: 4px 0;\">\n <div style=\"font-size: 11px; color: var(--text-secondary);\">${escapeHtml(res.uri)}</div>\n ${res.text ? `<pre style=\"margin: 4px 0 0 0;\">${escapeHtml(res.text)}</pre>` : ''}\n </div>`;\n });\n content += `</div>`;\n }\n\n // 元数据\n const meta = `\n <div style=\"\n font-size: 11px;\n opacity: 0.6;\n margin-top: 8px;\n display: flex;\n gap: 12px;\n \">\n <span>Server: ${escapeHtml(data.server)}</span>\n <span>Duration: ${data.duration}ms</span>\n </div>\n `;\n\n return content + meta;\n },\n },\n\n /**\n * MCP 结果 (简化版)\n */\n 'mcp-result': {\n call: () => '<div class=\"bash-command\">MCP Tool Call</div>',\n result: (data: any, success = true) => {\n return MCP_RENDER_TEMPLATES['mcp-tool'].result(data, success);\n },\n },\n} as const;\n\n/**\n * 获取 MCP 渲染模板\n */\nexport function getMCPRenderTemplate(toolName: string): string {\n return 'mcp-tool';\n}\n\n/**\n * 渲染 MCP 工具调用\n */\nexport function renderMCPToolCall(\n serverName: string,\n toolName: string,\n args: Record<string, any>\n): string {\n const template = MCP_RENDER_TEMPLATES['mcp-tool'].call;\n if (typeof template === 'function') {\n return template({ _server: serverName, _name: toolName, ...args });\n }\n return template;\n}\n\n/**\n * 渲染 MCP 工具结果\n */\nexport function renderMCPToolResult(\n result: any,\n success = true\n): string {\n const template = MCP_RENDER_TEMPLATES['mcp-tool'].result;\n if (typeof template === 'function') {\n return template(result, success);\n }\n return template;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/template/types.ts","../src/mcp/render.ts"],"sourcesContent":["/**\n * 提示词模板系统 - 核心类型定义\n */\n\n/**\n * 模板源\n * - string: 硬编码字符串\n * - { file: string }: 文件路径\n * - [dataSourceName: string]: 数据源名称(如 skills, tasks 等)\n * - TemplateComposer: 组合模板\n *\n * @example\n * ```typescript\n * // 静态字符串\n * 'Hello {{name}}'\n *\n * // 文件\n * { file: 'prompts/system.md' }\n *\n * // 数据源(列表渲染)\n * { skills: '- **{{name}}**: {{description}}' }\n * { tasks: '- [{{title}}](#{{id}}) ({{priority}})' }\n *\n * // 条件渲染\n * { conditional: { part: { file: 'advanced.md' }, condition: (ctx) => ctx.advanced } }\n * ```\n */\nexport type TemplateSource =\n | string\n | { file: string }\n | { conditional: ConditionalSource }\n | { [dataSourceName: string]: string } // 数据源 -> 模板\n | import('./composer.js').TemplateComposer;\n\n/**\n * 条件源配置\n */\nexport interface ConditionalSource {\n /** 条件模板源 */\n part: TemplateSource;\n /** 条件函数(true 时渲染) */\n condition: (context: PlaceholderContext) => boolean;\n}\n\n/**\n * 占位符上下文 - 变量替换的键值对\n * 支持原始类型和复杂对象(用于数据源渲染)\n */\nexport type PlaceholderContext = Record<string, string | number | boolean | undefined | object>;\n\n/**\n * 模板渲染结果\n */\nexport interface TemplateResult {\n /** 渲染后的内容 */\n content: string;\n /** 使用的源文件列表(用于调试) */\n sources: string[];\n}\n\n/**\n * 模板加载器配置\n */\nexport interface TemplateLoaderOptions {\n /** 缓存启用状态,默认 true */\n cacheEnabled?: boolean;\n /** 模板搜索目录(相对于项目根目录) */\n searchDirs?: string[];\n /** 项目根目录(自动检测) */\n projectRoot?: string;\n}\n\n/**\n * 缓存统计\n */\nexport interface CacheStats {\n size: number; // 缓存条目数\n hits: number; // 命中次数\n misses: number; // 未命中次数\n hitRate: number; // 命中率\n}\n\n/**\n * 模板相关错误\n */\nexport class TemplateError extends Error {\n constructor(\n message: string,\n public code:\n | 'FILE_NOT_FOUND'\n | 'INVALID_PATH'\n | 'READ_ERROR'\n | 'UNSUPPORTED_FORMAT',\n public path?: string\n ) {\n super(message);\n this.name = 'TemplateError';\n }\n}\n","/**\n * MCP 工具渲染模板\n *\n * 定义 MCP 工具在 DebugHub 中的显示样式\n */\n\n/**\n * 转义 HTML\n */\nfunction escapeHtml(text: any): string {\n const str = String(text);\n const map: Record<string, string> = {\n '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": ''',\n };\n return str.replace(/[&<>\"']/g, m => map[m]);\n}\n\n/**\n * MCP 工具渲染模板\n */\nexport const MCP_RENDER_TEMPLATES = {\n /**\n * MCP 工具调用显示\n */\n 'mcp-tool': {\n call: (args: any) => {\n const server = args._server || 'unknown';\n const name = args._name || 'unknown';\n return `\n <div class=\"bash-command\" style=\"\n border-left: 3px solid #ff6b6b;\n padding-left: 8px;\n margin: 4px 0;\n \">\n <span style=\"\n color: #ff6b6b;\n font-weight: bold;\n font-size: 11px;\n text-transform: uppercase;\n \">MCP</span>\n <span class=\"file-path\" style=\"color: #c068ff;\">${escapeHtml(server)}</span>\n <span style=\"color: #888;\">::</span>\n <span style=\"color: #fff;\">${escapeHtml(name)}</span>\n </div>\n `.trim();\n },\n result: (data: any, success = true) => {\n if (!success || data.error) {\n return `\n <div class=\"bash-output\" style=\"\n border-left: 3px solid #ff4444;\n padding-left: 8px;\n color: #ff6b6b;\n \">\n <div style=\"font-weight: bold; margin-bottom: 4px;\">MCP Error</div>\n <pre style=\"margin: 0; white-space: pre-wrap;\">${escapeHtml(data.error || 'Unknown error')}</pre>\n </div>\n `.trim();\n }\n\n let content = '';\n\n // 文本内容\n if (data.content) {\n content += `<pre class=\"bash-output\" style=\"max-height: 400px; overflow: auto;\">${escapeHtml(data.content)}</pre>`;\n }\n\n // 结构化数据\n if (data.structuredContent) {\n content += `<details style=\"margin-top: 8px;\">\n <summary style=\"cursor: pointer; color: var(--accent-color);\">Structured Data</summary>\n <pre style=\"margin: 4px 0; padding: 8px; background: var(--bg-secondary);\">${escapeHtml(JSON.stringify(data.structuredContent, null, 2))}</pre>\n </details>`;\n }\n\n // 图像\n if (data.images && data.images.length > 0) {\n content += `<div style=\"margin-top: 8px;\">`;\n data.images.forEach((img: any) => {\n content += `<img src=\"data:${img.mimeType};base64,${img.data}\" style=\"max-width: 100%; border-radius: 4px;\" />`;\n });\n content += `</div>`;\n }\n\n // 资源\n if (data.resources && data.resources.length > 0) {\n content += `<div style=\"margin-top: 8px;\">\n <div style=\"font-weight: bold; margin-bottom: 4px;\">Resources:</div>`;\n data.resources.forEach((res: any) => {\n content += `<div style=\"padding: 4px; background: var(--bg-secondary); margin: 4px 0;\">\n <div style=\"font-size: 11px; color: var(--text-secondary);\">${escapeHtml(res.uri)}</div>\n ${res.text ? `<pre style=\"margin: 4px 0 0 0;\">${escapeHtml(res.text)}</pre>` : ''}\n </div>`;\n });\n content += `</div>`;\n }\n\n // 元数据\n const meta = `\n <div style=\"\n font-size: 11px;\n opacity: 0.6;\n margin-top: 8px;\n display: flex;\n gap: 12px;\n \">\n <span>Server: ${escapeHtml(data.server)}</span>\n <span>Duration: ${data.duration}ms</span>\n </div>\n `;\n\n return content + meta;\n },\n },\n\n /**\n * MCP 结果 (简化版)\n */\n 'mcp-result': {\n call: () => '<div class=\"bash-command\">MCP Tool Call</div>',\n result: (data: any, success = true) => {\n return MCP_RENDER_TEMPLATES['mcp-tool'].result(data, success);\n },\n },\n} as const;\n\n/**\n * 获取 MCP 渲染模板\n */\nexport function getMCPRenderTemplate(toolName: string): string {\n return 'mcp-tool';\n}\n\n/**\n * 渲染 MCP 工具调用\n */\nexport function renderMCPToolCall(\n serverName: string,\n toolName: string,\n args: Record<string, any>\n): string {\n const template = MCP_RENDER_TEMPLATES['mcp-tool'].call;\n if (typeof template === 'function') {\n return template({ _server: serverName, _name: toolName, ...args });\n }\n return template;\n}\n\n/**\n * 渲染 MCP 工具结果\n */\nexport function renderMCPToolResult(\n result: any,\n success = true\n): string {\n const template = MCP_RENDER_TEMPLATES['mcp-tool'].result;\n if (typeof template === 'function') {\n return template(result, success);\n }\n return template;\n}\n"],"mappings":"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","names":[]}
|