needware-cli 1.5.13 → 1.5.17
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/README.md +49 -1
- package/dist/commands/agent.d.ts +12 -0
- package/dist/commands/agent.d.ts.map +1 -1
- package/dist/commands/agent.js +133 -7
- package/dist/commands/agent.js.map +1 -1
- package/dist/commands/index.d.ts +1 -1
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +1 -1
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/skill.d.ts +34 -0
- package/dist/commands/skill.d.ts.map +1 -0
- package/dist/commands/skill.js +307 -0
- package/dist/commands/skill.js.map +1 -0
- package/dist/commands/system-prompt.d.ts.map +1 -1
- package/dist/commands/system-prompt.js +287 -43
- package/dist/commands/system-prompt.js.map +1 -1
- package/dist/core/cli.d.ts.map +1 -1
- package/dist/core/cli.js +8 -1
- package/dist/core/cli.js.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/sdk/firecrawl-sdk.d.ts +85 -0
- package/dist/sdk/firecrawl-sdk.d.ts.map +1 -0
- package/dist/sdk/firecrawl-sdk.js +207 -0
- package/dist/sdk/firecrawl-sdk.js.map +1 -0
- package/dist/tools/ai-gateway-enable-tool.d.ts +12 -0
- package/dist/tools/ai-gateway-enable-tool.d.ts.map +1 -0
- package/dist/tools/ai-gateway-enable-tool.js +33 -0
- package/dist/tools/ai-gateway-enable-tool.js.map +1 -0
- package/dist/tools/base-tool.d.ts +76 -0
- package/dist/tools/base-tool.d.ts.map +1 -0
- package/dist/tools/base-tool.js +119 -0
- package/dist/tools/base-tool.js.map +1 -0
- package/dist/tools/example-tool.d.ts +16 -0
- package/dist/tools/example-tool.d.ts.map +1 -0
- package/dist/tools/example-tool.js +67 -0
- package/dist/tools/example-tool.js.map +1 -0
- package/dist/tools/index.d.ts +9 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +9 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/supabase-deploy-functions-tool.d.ts +18 -0
- package/dist/tools/supabase-deploy-functions-tool.d.ts.map +1 -0
- package/dist/tools/supabase-deploy-functions-tool.js +127 -0
- package/dist/tools/supabase-deploy-functions-tool.js.map +1 -0
- package/dist/tools/supabase-enable-tool.d.ts +12 -0
- package/dist/tools/supabase-enable-tool.d.ts.map +1 -0
- package/dist/tools/supabase-enable-tool.js +89 -0
- package/dist/tools/supabase-enable-tool.js.map +1 -0
- package/dist/tools/tool-registry.d.ts +51 -0
- package/dist/tools/tool-registry.d.ts.map +1 -0
- package/dist/tools/tool-registry.js +81 -0
- package/dist/tools/tool-registry.js.map +1 -0
- package/dist/tools/user-registration-tool.d.ts +17 -0
- package/dist/tools/user-registration-tool.d.ts.map +1 -0
- package/dist/tools/user-registration-tool.js +63 -0
- package/dist/tools/user-registration-tool.js.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/tool.d.ts +60 -0
- package/dist/types/tool.d.ts.map +1 -0
- package/dist/types/tool.js +5 -0
- package/dist/types/tool.js.map +1 -0
- package/examples/gateway-config-usage.sh +71 -0
- package/examples/tool-usage-example.sh +44 -0
- package/package.json +2 -2
- package/CHANGELOG_DB_CONFIG.md +0 -142
- package/IMPLEMENTATION_SUMMARY.md +0 -303
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firecrawl SDK - 网站抓取服务
|
|
3
|
+
*
|
|
4
|
+
* 用于获取网站截图和 HTML 内容,供 AI 克隆应用使用
|
|
5
|
+
*/
|
|
6
|
+
import axios from 'axios';
|
|
7
|
+
import * as fs from 'fs';
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
/**
|
|
10
|
+
* Firecrawl SDK 类
|
|
11
|
+
*/
|
|
12
|
+
export class FirecrawlSDK {
|
|
13
|
+
apiKey;
|
|
14
|
+
baseUrl;
|
|
15
|
+
constructor(config) {
|
|
16
|
+
this.apiKey = config.apiKey;
|
|
17
|
+
this.baseUrl = config.baseUrl || 'https://api.firecrawl.dev/v1';
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 抓取单个网页
|
|
21
|
+
*/
|
|
22
|
+
async scrapeUrl(url, options = {}) {
|
|
23
|
+
const defaultFormats = ['markdown', 'html', 'screenshot', 'links'];
|
|
24
|
+
const requestBody = {
|
|
25
|
+
url,
|
|
26
|
+
formats: options.formats || defaultFormats,
|
|
27
|
+
onlyMainContent: options.onlyMainContent ?? true,
|
|
28
|
+
includeTags: options.includeTags,
|
|
29
|
+
excludeTags: options.excludeTags,
|
|
30
|
+
waitFor: options.waitFor || 3000,
|
|
31
|
+
timeout: options.timeout || 30000,
|
|
32
|
+
};
|
|
33
|
+
try {
|
|
34
|
+
const response = await axios.post(`${this.baseUrl}/scrape`, requestBody, {
|
|
35
|
+
headers: {
|
|
36
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
37
|
+
'Content-Type': 'application/json',
|
|
38
|
+
},
|
|
39
|
+
timeout: 60000, // 60 seconds timeout for the entire request
|
|
40
|
+
});
|
|
41
|
+
if (!response.data.success) {
|
|
42
|
+
throw new Error(response.data.error || 'Scraping failed');
|
|
43
|
+
}
|
|
44
|
+
const data = response.data.data;
|
|
45
|
+
return {
|
|
46
|
+
url,
|
|
47
|
+
title: data.metadata?.title,
|
|
48
|
+
description: data.metadata?.description,
|
|
49
|
+
html: data.html,
|
|
50
|
+
markdown: data.markdown,
|
|
51
|
+
screenshot: data.screenshot, // base64 screenshot
|
|
52
|
+
links: data.links,
|
|
53
|
+
metadata: data.metadata,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (axios.isAxiosError(error)) {
|
|
58
|
+
const message = error.response?.data?.error || error.message;
|
|
59
|
+
throw new Error(`Firecrawl API error: ${message}`);
|
|
60
|
+
}
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 抓取网站用于克隆(获取截图和 HTML)
|
|
66
|
+
*/
|
|
67
|
+
async scrapeForClone(url) {
|
|
68
|
+
return this.scrapeUrl(url, {
|
|
69
|
+
formats: ['html', 'screenshot', 'markdown'],
|
|
70
|
+
onlyMainContent: false, // 获取完整页面内容
|
|
71
|
+
waitFor: 5000, // 等待页面完全加载
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 仅获取网站截图
|
|
76
|
+
*/
|
|
77
|
+
async getScreenshot(url) {
|
|
78
|
+
const result = await this.scrapeUrl(url, {
|
|
79
|
+
formats: ['screenshot'],
|
|
80
|
+
waitFor: 5000,
|
|
81
|
+
});
|
|
82
|
+
if (!result.screenshot) {
|
|
83
|
+
throw new Error('Failed to capture screenshot');
|
|
84
|
+
}
|
|
85
|
+
return result.screenshot;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 仅获取网站 HTML
|
|
89
|
+
*/
|
|
90
|
+
async getHtml(url) {
|
|
91
|
+
const result = await this.scrapeUrl(url, {
|
|
92
|
+
formats: ['html'],
|
|
93
|
+
onlyMainContent: false,
|
|
94
|
+
});
|
|
95
|
+
if (!result.html) {
|
|
96
|
+
throw new Error('Failed to get HTML content');
|
|
97
|
+
}
|
|
98
|
+
return result.html;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 将截图保存到本地文件
|
|
102
|
+
*/
|
|
103
|
+
async saveScreenshotToFile(base64Screenshot, outputPath) {
|
|
104
|
+
const dir = path.dirname(outputPath);
|
|
105
|
+
if (!fs.existsSync(dir)) {
|
|
106
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
107
|
+
}
|
|
108
|
+
// 移除 base64 前缀(如果有)
|
|
109
|
+
const base64Data = base64Screenshot.replace(/^data:image\/\w+;base64,/, '');
|
|
110
|
+
const buffer = Buffer.from(base64Data, 'base64');
|
|
111
|
+
fs.writeFileSync(outputPath, buffer);
|
|
112
|
+
return outputPath;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* 创建 Firecrawl SDK 实例
|
|
117
|
+
*/
|
|
118
|
+
export function createFirecrawlSDK(apiKeyOrConfig) {
|
|
119
|
+
let config;
|
|
120
|
+
if (typeof apiKeyOrConfig === 'string') {
|
|
121
|
+
config = { apiKey: apiKeyOrConfig };
|
|
122
|
+
}
|
|
123
|
+
else if (apiKeyOrConfig) {
|
|
124
|
+
config = apiKeyOrConfig;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
// 从环境变量获取
|
|
128
|
+
const apiKey = process.env.FIRECRAWL_API_KEY;
|
|
129
|
+
if (!apiKey) {
|
|
130
|
+
throw new Error('Firecrawl API key not provided. ' +
|
|
131
|
+
'Please set FIRECRAWL_API_KEY environment variable or pass it as a parameter.');
|
|
132
|
+
}
|
|
133
|
+
config = {
|
|
134
|
+
apiKey,
|
|
135
|
+
baseUrl: process.env.FIRECRAWL_BASE_URL,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
return new FirecrawlSDK(config);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* 格式化网站数据为 Agent 可用的上下文
|
|
142
|
+
*/
|
|
143
|
+
export function formatWebsiteDataForAgent(data) {
|
|
144
|
+
// 构建文本内容
|
|
145
|
+
const textParts = [
|
|
146
|
+
`## 目标网站信息`,
|
|
147
|
+
``,
|
|
148
|
+
`**URL**: ${data.url}`,
|
|
149
|
+
];
|
|
150
|
+
if (data.title) {
|
|
151
|
+
textParts.push(`**标题**: ${data.title}`);
|
|
152
|
+
}
|
|
153
|
+
if (data.description) {
|
|
154
|
+
textParts.push(`**描述**: ${data.description}`);
|
|
155
|
+
}
|
|
156
|
+
textParts.push('');
|
|
157
|
+
textParts.push('---');
|
|
158
|
+
textParts.push('');
|
|
159
|
+
// 添加 HTML 内容(如果存在且不太长)
|
|
160
|
+
if (data.html) {
|
|
161
|
+
const htmlContent = data.html.length > 50000
|
|
162
|
+
? data.html.substring(0, 50000) + '\n\n... [HTML 内容已截断,仅显示前 50000 字符]'
|
|
163
|
+
: data.html;
|
|
164
|
+
textParts.push('### 网站 HTML 结构');
|
|
165
|
+
textParts.push('```html');
|
|
166
|
+
textParts.push(htmlContent);
|
|
167
|
+
textParts.push('```');
|
|
168
|
+
textParts.push('');
|
|
169
|
+
}
|
|
170
|
+
// 添加 Markdown 内容(如果存在)
|
|
171
|
+
if (data.markdown) {
|
|
172
|
+
const markdownContent = data.markdown.length > 20000
|
|
173
|
+
? data.markdown.substring(0, 20000) + '\n\n... [Markdown 内容已截断]'
|
|
174
|
+
: data.markdown;
|
|
175
|
+
textParts.push('### 网站文本内容(Markdown 格式)');
|
|
176
|
+
textParts.push(markdownContent);
|
|
177
|
+
textParts.push('');
|
|
178
|
+
}
|
|
179
|
+
const result = {
|
|
180
|
+
textContent: textParts.join('\n'),
|
|
181
|
+
};
|
|
182
|
+
// 添加截图(如果存在)
|
|
183
|
+
if (data.screenshot) {
|
|
184
|
+
// 处理 base64 数据
|
|
185
|
+
let base64Data = data.screenshot;
|
|
186
|
+
let mediaType = 'image/png';
|
|
187
|
+
// 检查并移除 data URL 前缀
|
|
188
|
+
if (base64Data.startsWith('data:image/')) {
|
|
189
|
+
const match = base64Data.match(/^data:image\/(png|jpeg|jpg);base64,(.+)$/);
|
|
190
|
+
if (match) {
|
|
191
|
+
mediaType = match[1] === 'jpg' ? 'image/jpeg' : `image/${match[1]}`;
|
|
192
|
+
base64Data = match[2];
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
result.imageContent = {
|
|
196
|
+
type: 'image',
|
|
197
|
+
source: {
|
|
198
|
+
type: 'base64',
|
|
199
|
+
media_type: mediaType,
|
|
200
|
+
data: base64Data,
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
export default Firecrawl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AAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;YAC3E,IAAI,KAAK,EAAE,CAAC;gBACV,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,CAAC,EAAgC,CAAC;gBAClG,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;QAED,MAAM,CAAC,YAAY,GAAG;YACpB,IAAI,EAAE,OAAO;YACb,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE,SAAS;gBACrB,IAAI,EAAE,UAAU;aACjB;SACF,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Gateway Enable Tool
|
|
3
|
+
* Tool for enabling AI Gateway integration
|
|
4
|
+
*/
|
|
5
|
+
import { BaseTool } from './base-tool.js';
|
|
6
|
+
import { ToolDefinition, ToolResult } from '../types/tool.js';
|
|
7
|
+
export declare class AiGatewayEnableTool extends BaseTool {
|
|
8
|
+
definition: ToolDefinition;
|
|
9
|
+
getZodSchema(): {};
|
|
10
|
+
execute(input: Record<string, any>): Promise<ToolResult>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=ai-gateway-enable-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-gateway-enable-tool.d.ts","sourceRoot":"","sources":["../../src/tools/ai-gateway-enable-tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAI9D,qBAAa,mBAAoB,SAAQ,QAAQ;IAC/C,UAAU,EAAE,cAAc,CAQxB;IAEF,YAAY;IAIN,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;CAa/D"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Gateway Enable Tool
|
|
3
|
+
* Tool for enabling AI Gateway integration
|
|
4
|
+
*/
|
|
5
|
+
import { BaseTool } from './base-tool.js';
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
export class AiGatewayEnableTool extends BaseTool {
|
|
8
|
+
definition = {
|
|
9
|
+
name: 'ai_gateway--enable_ai_gateway',
|
|
10
|
+
description: 'Enable AI Gateway integration',
|
|
11
|
+
input_schema: {
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {},
|
|
14
|
+
required: [],
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
getZodSchema() {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
async execute(input) {
|
|
21
|
+
try {
|
|
22
|
+
console.log(chalk.blue('\n🔧 Enabling AI Gateway integration...\n'));
|
|
23
|
+
console.log(chalk.green('\n✓ AI Gateway integration enabled'));
|
|
24
|
+
return this.successWithContent('AI Gateway integration enabled successfully');
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
const message = error instanceof Error ? error.message : 'Failed to enable AI Gateway';
|
|
28
|
+
console.log(chalk.red(`\n✖ ${message}\n`));
|
|
29
|
+
return this.errorWithContent(message);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=ai-gateway-enable-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-gateway-enable-tool.js","sourceRoot":"","sources":["../../src/tools/ai-gateway-enable-tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,MAAM,OAAO,mBAAoB,SAAQ,QAAQ;IAC/C,UAAU,GAAmB;QAC3B,IAAI,EAAE,+BAA+B;QACrC,WAAW,EAAE,+BAA+B;QAC5C,YAAY,EAAE;YACZ,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,EAAE;YACd,QAAQ,EAAE,EAAE;SACb;KACF,CAAC;IAEF,YAAY;QACV,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,KAA0B;QACtC,IAAI,CAAC;YACH,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,2CAA2C,CAAC,CAAC,CAAC;YAErE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC,CAAC;YAE/D,OAAO,IAAI,CAAC,kBAAkB,CAAC,6CAA6C,CAAC,CAAC;QAChF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,6BAA6B,CAAC;YACvF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,OAAO,IAAI,CAAC,CAAC,CAAC;YAC3C,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 基础 Tool 类
|
|
3
|
+
*/
|
|
4
|
+
import { Tool, ToolDefinition, ToolResult } from '../types/tool.js';
|
|
5
|
+
export interface BaseToolConfig {
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
chatId?: string;
|
|
8
|
+
workspaceId?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare abstract class BaseTool implements Tool {
|
|
11
|
+
abstract definition: ToolDefinition;
|
|
12
|
+
protected apiKey?: string;
|
|
13
|
+
protected chatId?: string;
|
|
14
|
+
protected workspaceId?: string;
|
|
15
|
+
constructor(config?: BaseToolConfig);
|
|
16
|
+
/**
|
|
17
|
+
* 获取 Gateway 配置,优先使用构造函数传入的配置,如果没有则从环境变量读取
|
|
18
|
+
*/
|
|
19
|
+
protected getGatewayConfig(): {
|
|
20
|
+
apiKey?: string;
|
|
21
|
+
chatId?: string;
|
|
22
|
+
workspaceId?: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* 验证 Gateway 配置是否完整
|
|
26
|
+
*/
|
|
27
|
+
protected validateGatewayConfig(): void;
|
|
28
|
+
/**
|
|
29
|
+
* 获取 Zod schema(子类可以覆盖)
|
|
30
|
+
*/
|
|
31
|
+
getZodSchema(): Record<string, any>;
|
|
32
|
+
/**
|
|
33
|
+
* 转换为 SDK tool
|
|
34
|
+
*/
|
|
35
|
+
toSdkTool(): {
|
|
36
|
+
name: string;
|
|
37
|
+
description: string;
|
|
38
|
+
inputSchema: Record<string, any>;
|
|
39
|
+
handler: (args: {
|
|
40
|
+
[x: string]: any;
|
|
41
|
+
}, extra: unknown) => Promise<CallToolResult>;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* 执行 Tool
|
|
45
|
+
* @param input Tool 的输入参数
|
|
46
|
+
*/
|
|
47
|
+
abstract execute(input: Record<string, any>): Promise<ToolResult>;
|
|
48
|
+
/**
|
|
49
|
+
* 验证输入参数
|
|
50
|
+
* @param input 输入参数
|
|
51
|
+
* @param required 必需参数列表
|
|
52
|
+
*/
|
|
53
|
+
protected validateInput(input: Record<string, any>, required?: string[]): void;
|
|
54
|
+
/**
|
|
55
|
+
* 创建成功结果
|
|
56
|
+
* @param data 返回数据
|
|
57
|
+
* @param message 消息
|
|
58
|
+
*/
|
|
59
|
+
protected success(data?: any, message?: string): ToolResult;
|
|
60
|
+
/**
|
|
61
|
+
* 创建 SDK 格式的成功结果
|
|
62
|
+
* @param text 文本内容
|
|
63
|
+
*/
|
|
64
|
+
protected successWithContent(text: string): ToolResult;
|
|
65
|
+
/**
|
|
66
|
+
* 创建错误结果
|
|
67
|
+
* @param error 错误信息
|
|
68
|
+
*/
|
|
69
|
+
protected error(error: string): ToolResult;
|
|
70
|
+
/**
|
|
71
|
+
* 创建 SDK 格式的错误结果
|
|
72
|
+
* @param error 错误信息
|
|
73
|
+
*/
|
|
74
|
+
protected errorWithContent(error: string): ToolResult;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=base-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-tool.d.ts","sourceRoot":"","sources":["../../src/tools/base-tool.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAIpE,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,8BAAsB,QAAS,YAAW,IAAI;IAC5C,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC;IAGpC,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;gBAEnB,MAAM,CAAC,EAAE,cAAc;IAMnC;;OAEG;IACH,SAAS,CAAC,gBAAgB,IAAI;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE;IAQxF;;OAEG;IACH,SAAS,CAAC,qBAAqB,IAAI,IAAI;IAWvC;;OAEG;IACH,YAAY,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAInC;;OAEG;IACH,SAAS;;;;;;;;IAwBT;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;IAEjE;;;;OAIG;IACH,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI;IAW9E;;;;OAIG;IACH,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU;IAQ3D;;;OAGG;IACH,SAAS,CAAC,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU;IAOtD;;;OAGG;IACH,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU;IAO1C;;;OAGG;IACH,SAAS,CAAC,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU;CAOtD"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 基础 Tool 类
|
|
3
|
+
*/
|
|
4
|
+
import { tool } from '@anthropic-ai/claude-agent-sdk';
|
|
5
|
+
export class BaseTool {
|
|
6
|
+
// Gateway 配置
|
|
7
|
+
apiKey;
|
|
8
|
+
chatId;
|
|
9
|
+
workspaceId;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.apiKey = config?.apiKey;
|
|
12
|
+
this.chatId = config?.chatId;
|
|
13
|
+
this.workspaceId = config?.workspaceId;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 获取 Gateway 配置,优先使用构造函数传入的配置,如果没有则从环境变量读取
|
|
17
|
+
*/
|
|
18
|
+
getGatewayConfig() {
|
|
19
|
+
return {
|
|
20
|
+
apiKey: this.apiKey || process.env.GATEWAY_API_KEY,
|
|
21
|
+
chatId: this.chatId || process.env.GATEWAY_CHAT_ID,
|
|
22
|
+
workspaceId: this.workspaceId || process.env.GATEWAY_WORKSPACE_ID,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 验证 Gateway 配置是否完整
|
|
27
|
+
*/
|
|
28
|
+
validateGatewayConfig() {
|
|
29
|
+
const config = this.getGatewayConfig();
|
|
30
|
+
if (!config.apiKey || !config.chatId || !config.workspaceId) {
|
|
31
|
+
throw new Error('Missing required Gateway configuration: apiKey, chatId, or workspaceId. ' +
|
|
32
|
+
'Please provide them via command arguments (--gateway-api-key, --gateway-chat-id, --gateway-workspace-id) ' +
|
|
33
|
+
'or environment variables (GATEWAY_API_KEY, GATEWAY_CHAT_ID, GATEWAY_WORKSPACE_ID).');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 获取 Zod schema(子类可以覆盖)
|
|
38
|
+
*/
|
|
39
|
+
getZodSchema() {
|
|
40
|
+
return {}; // 默认空 schema
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 转换为 SDK tool
|
|
44
|
+
*/
|
|
45
|
+
toSdkTool() {
|
|
46
|
+
return tool(this.definition.name, this.definition.description, this.getZodSchema(), async (args) => {
|
|
47
|
+
const result = await this.execute(args);
|
|
48
|
+
// 如果结果已经是 SDK 格式,直接返回
|
|
49
|
+
if (result.content) {
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
// 否则转换为 SDK 格式
|
|
53
|
+
return {
|
|
54
|
+
content: [{
|
|
55
|
+
type: 'text',
|
|
56
|
+
text: JSON.stringify(result, null, 2)
|
|
57
|
+
}],
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 验证输入参数
|
|
63
|
+
* @param input 输入参数
|
|
64
|
+
* @param required 必需参数列表
|
|
65
|
+
*/
|
|
66
|
+
validateInput(input, required) {
|
|
67
|
+
if (!required || required.length === 0) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const missing = required.filter((key) => !(key in input));
|
|
71
|
+
if (missing.length > 0) {
|
|
72
|
+
throw new Error(`Missing required parameters: ${missing.join(', ')}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 创建成功结果
|
|
77
|
+
* @param data 返回数据
|
|
78
|
+
* @param message 消息
|
|
79
|
+
*/
|
|
80
|
+
success(data, message) {
|
|
81
|
+
return {
|
|
82
|
+
success: true,
|
|
83
|
+
data,
|
|
84
|
+
message,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 创建 SDK 格式的成功结果
|
|
89
|
+
* @param text 文本内容
|
|
90
|
+
*/
|
|
91
|
+
successWithContent(text) {
|
|
92
|
+
return {
|
|
93
|
+
success: true,
|
|
94
|
+
content: [{ type: 'text', text }],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* 创建错误结果
|
|
99
|
+
* @param error 错误信息
|
|
100
|
+
*/
|
|
101
|
+
error(error) {
|
|
102
|
+
return {
|
|
103
|
+
success: false,
|
|
104
|
+
error,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* 创建 SDK 格式的错误结果
|
|
109
|
+
* @param error 错误信息
|
|
110
|
+
*/
|
|
111
|
+
errorWithContent(error) {
|
|
112
|
+
return {
|
|
113
|
+
success: false,
|
|
114
|
+
error,
|
|
115
|
+
content: [{ type: 'text', text: `Error: ${error}` }],
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=base-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-tool.js","sourceRoot":"","sources":["../../src/tools/base-tool.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,gCAAgC,CAAC;AAStD,MAAM,OAAgB,QAAQ;IAG5B,aAAa;IACH,MAAM,CAAU;IAChB,MAAM,CAAU;IAChB,WAAW,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F"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example Tool
|
|
3
|
+
* 示例工具,展示如何创建自定义工具
|
|
4
|
+
*/
|
|
5
|
+
import { BaseTool } from './base-tool.js';
|
|
6
|
+
import { ToolDefinition, ToolResult } from '../types/tool.js';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
export declare class ExampleTool extends BaseTool {
|
|
9
|
+
definition: ToolDefinition;
|
|
10
|
+
getZodSchema(): {
|
|
11
|
+
message: z.ZodString;
|
|
12
|
+
action: z.ZodOptional<z.ZodEnum<["echo", "uppercase", "lowercase"]>>;
|
|
13
|
+
};
|
|
14
|
+
execute(input: Record<string, any>): Promise<ToolResult>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=example-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"example-tool.d.ts","sourceRoot":"","sources":["../../src/tools/example-tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,qBAAa,WAAY,SAAQ,QAAQ;IACvC,UAAU,EAAE,cAAc,CAoBxB;IAEF,YAAY;;;;IAON,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;CAkC/D"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example Tool
|
|
3
|
+
* 示例工具,展示如何创建自定义工具
|
|
4
|
+
*/
|
|
5
|
+
import { BaseTool } from './base-tool.js';
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
export class ExampleTool extends BaseTool {
|
|
9
|
+
definition = {
|
|
10
|
+
name: 'example-tool',
|
|
11
|
+
description: 'Example tool to demonstrate how to create custom tools',
|
|
12
|
+
input_schema: {
|
|
13
|
+
type: 'object',
|
|
14
|
+
properties: {
|
|
15
|
+
message: {
|
|
16
|
+
type: 'string',
|
|
17
|
+
description: 'Message to process',
|
|
18
|
+
required: true,
|
|
19
|
+
},
|
|
20
|
+
action: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
description: 'Action to perform',
|
|
23
|
+
required: false,
|
|
24
|
+
enum: ['echo', 'uppercase', 'lowercase'],
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
required: ['message'],
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
getZodSchema() {
|
|
31
|
+
return {
|
|
32
|
+
message: z.string().describe('Message to process'),
|
|
33
|
+
action: z.enum(['echo', 'uppercase', 'lowercase']).optional().describe('Action to perform'),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
async execute(input) {
|
|
37
|
+
try {
|
|
38
|
+
// Validate required parameters
|
|
39
|
+
this.validateInput(input, this.definition.input_schema.required);
|
|
40
|
+
const { message, action = 'echo' } = input;
|
|
41
|
+
console.log(chalk.blue('\n🔧 Executing example tool...\n'));
|
|
42
|
+
console.log(chalk.gray(`Message: ${message}`));
|
|
43
|
+
console.log(chalk.gray(`Action: ${action}`));
|
|
44
|
+
let result;
|
|
45
|
+
switch (action) {
|
|
46
|
+
case 'uppercase':
|
|
47
|
+
result = message.toUpperCase();
|
|
48
|
+
break;
|
|
49
|
+
case 'lowercase':
|
|
50
|
+
result = message.toLowerCase();
|
|
51
|
+
break;
|
|
52
|
+
case 'echo':
|
|
53
|
+
default:
|
|
54
|
+
result = message;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
console.log(chalk.green(`\n✓ Result: ${result}\n`));
|
|
58
|
+
return this.success({ result }, 'Example tool executed successfully');
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
const message = error instanceof Error ? error.message : 'Failed to execute example tool';
|
|
62
|
+
console.log(chalk.red(`\n✖ ${message}\n`));
|
|
63
|
+
return this.error(message);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=example-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"example-tool.js","sourceRoot":"","sources":["../../src/tools/example-tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,OAAO,WAAY,SAAQ,QAAQ;IACvC,UAAU,GAAmB;QAC3B,IAAI,EAAE,cAAc;QACpB,WAAW,EAAE,wDAAwD;QACrE,YAAY,EAAE;YACZ,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,OAAO,EAAE;oBACP,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,oBAAoB;oBACjC,QAAQ,EAAE,IAAI;iBACf;gBACD,MAAM,EAAE;oBACN,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,mBAAmB;oBAChC,QAAQ,EAAE,KAAK;oBACf,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,WAAW,CAAC;iBACzC;aACF;YACD,QAAQ,EAAE,CAAC,SAAS,CAAC;SACtB;KACF,CAAC;IAEF,YAAY;QACV,OAAO;YACL,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,oBAAoB,CAAC;YAClD,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC;SAC5F,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,KAA0B;QACtC,IAAI,CAAC;YACH,+B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,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tools 入口文件
|
|
3
|
+
*/
|
|
4
|
+
export { BaseTool, BaseToolConfig } from './base-tool.js';
|
|
5
|
+
export { SupabaseEnableTool } from './supabase-enable-tool.js';
|
|
6
|
+
export { SupabaseDeployFunctionsTool } from './supabase-deploy-functions-tool.js';
|
|
7
|
+
export { AiGatewayEnableTool } from './ai-gateway-enable-tool.js';
|
|
8
|
+
export { ToolRegistry, ToolConfig } from './tool-registry.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tools 入口文件
|
|
3
|
+
*/
|
|
4
|
+
export { BaseTool } from './base-tool.js';
|
|
5
|
+
export { SupabaseEnableTool } from './supabase-enable-tool.js';
|
|
6
|
+
export { SupabaseDeployFunctionsTool } from './supabase-deploy-functions-tool.js';
|
|
7
|
+
export { AiGatewayEnableTool } from './ai-gateway-enable-tool.js';
|
|
8
|
+
export { ToolRegistry } from './tool-registry.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAkB,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAc,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supabase Deploy Functions Tool
|
|
3
|
+
* Tool for deploying Supabase Edge Functions
|
|
4
|
+
*/
|
|
5
|
+
import { BaseTool } from './base-tool.js';
|
|
6
|
+
import { ToolDefinition, ToolResult } from '../types/tool.js';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
export declare class SupabaseDeployFunctionsTool extends BaseTool {
|
|
9
|
+
definition: ToolDefinition;
|
|
10
|
+
getZodSchema(): {
|
|
11
|
+
functionName: z.ZodOptional<z.ZodString>;
|
|
12
|
+
functionPath: z.ZodOptional<z.ZodString>;
|
|
13
|
+
noVerifyJwt: z.ZodOptional<z.ZodBoolean>;
|
|
14
|
+
importMap: z.ZodOptional<z.ZodString>;
|
|
15
|
+
};
|
|
16
|
+
execute(input: Record<string, any>): Promise<ToolResult>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=supabase-deploy-functions-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supabase-deploy-functions-tool.d.ts","sourceRoot":"","sources":["../../src/tools/supabase-deploy-functions-tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA8BxB,qBAAa,2BAA4B,SAAQ,QAAQ;IACvD,UAAU,EAAE,cAAc,CAyBxB;IAEF,YAAY;;;;;;IASN,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;CAkG/D"}
|