Skip to content

Commit 101ffb8

Browse files
authored
chore(release): 修复工作流 (#25)
* chore: 修复lint * chore: 修复lint
1 parent 1148735 commit 101ffb8

5 files changed

Lines changed: 43 additions & 62 deletions

File tree

.github/workflows/auto-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: macos-latest
1010
if: startsWith(github.event.head_commit.message , 'chore(release):')
1111
env:
12-
NODE_OPTIONS: "--max-old-space-size=8192"
12+
NODE_OPTIONS: '--max-old-space-size=8192'
1313
steps:
1414
- uses: actions/checkout@v3
1515
with:

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ jobs:
2222
- name: Run Continuous Integration
2323
run: |
2424
npm install
25+
npm run lint
2526
npm run build
2627
npx vitest --watch=false

__tests__/tools/query_antv_document.json

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,7 @@
77
"properties": {
88
"library": {
99
"type": "string",
10-
"enum": [
11-
"g2",
12-
"g6",
13-
"l7",
14-
"x6",
15-
"f2",
16-
"s2",
17-
"g",
18-
"ava",
19-
"adc"
20-
],
10+
"enum": ["g2", "g6", "l7", "x6", "f2", "s2", "g", "ava", "adc"],
2111
"description": "Specified AntV library type, intelligently identified based on user query"
2212
},
2313
"query": {
@@ -58,28 +48,17 @@
5848
"description": "Subtask topic"
5949
}
6050
},
61-
"required": [
62-
"query",
63-
"topic"
64-
]
51+
"required": ["query", "topic"]
6552
},
6653
"description": "Decomposed subtask list for complex tasks, supports batch processing"
6754
},
6855
"channel": {
6956
"default": "Context7",
7057
"description": "Controls the trade-off between search speed and retrieval accuracy. Use \"Context7\" (Default) for quick, interactive responses (~2s latency). Use \"DeepWiki\" ONLY when the user explicitly requests \"deep research\", \"high accuracy\", \"comprehensive analysis\", or when the query is critical and requires verification, despite the slower speed (~20s latency).",
71-
"enum": [
72-
"Context7",
73-
"DeepWiki"
74-
],
58+
"enum": ["Context7", "DeepWiki"],
7559
"type": "string"
7660
}
7761
},
78-
"required": [
79-
"library",
80-
"query",
81-
"topic",
82-
"intent"
83-
]
62+
"required": ["library", "query", "topic", "intent"]
8463
}
8564
}

src/tools/query_antv_document.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,32 +57,27 @@ const QueryAntVDocumentInputSchema = z.object({
5757
.default('Context7')
5858
.describe(
5959
'Controls the trade-off between search speed and retrieval accuracy. ' +
60-
'Use "Context7" (Default) for quick, interactive responses (~2s latency). ' +
61-
'Use "DeepWiki" ONLY when the user explicitly requests "deep research", "high accuracy", "comprehensive analysis", or when the query is critical and requires verification, despite the slower speed (~20s latency).'
60+
'Use "Context7" (Default) for quick, interactive responses (~2s latency). ' +
61+
'Use "DeepWiki" ONLY when the user explicitly requests "deep research", "high accuracy", "comprehensive analysis", or when the query is critical and requires verification, despite the slower speed (~20s latency).',
6262
),
6363
});
6464

6565
type QueryAntVDocumentArgs = z.infer<typeof QueryAntVDocumentInputSchema>;
6666

6767
export async function queryDocRouter(params: {
6868
args: QueryAntVDocumentArgs;
69-
libraryId: string,
70-
topic: string,
71-
tokens?: number
69+
libraryId: string;
70+
topic: string;
71+
tokens?: number;
7272
}) {
7373
const { args, libraryId, topic, tokens } = params;
7474
if (args.channel === 'DeepWiki') {
7575
return await adaptedQueryDeepWiki({
7676
repoName: args.library,
7777
question: topic,
7878
});
79-
8079
} else {
81-
return await fetchLibraryDocumentation(
82-
libraryId,
83-
topic,
84-
tokens,
85-
);
80+
return await fetchLibraryDocumentation(libraryId, topic, tokens);
8681
}
8782
}
8883

src/utils/deepwiki.ts

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2-
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
3-
import EventSource from "eventsource";
1+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
2+
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
3+
import EventSource from 'eventsource';
44
import { logger } from './logger';
55
import { AntVLibrary } from '../types';
66

@@ -41,28 +41,28 @@ async function getMcpClient(): Promise<Client> {
4141
// 开始初始化连接
4242
_connectingPromise = (async () => {
4343
try {
44-
logger.info("DeepWiki MCP: 初始化连接...");
44+
logger.info('DeepWiki MCP: 初始化连接...');
4545

4646
const transport = new SSEClientTransport(
47-
new URL("https://mcp.deepwiki.com/sse")
47+
new URL('https://mcp.deepwiki.com/sse'),
4848
);
4949

5050
const client = new Client(
5151
{
52-
name: "deepwiki-node-client",
53-
version: "1.0.0",
52+
name: 'deepwiki-node-client',
53+
version: '1.0.0',
5454
},
55-
{ capabilities: {} }
55+
{ capabilities: {} },
5656
);
5757

5858
// 错误处理:监听传输层关闭或错误,以便下次重连
5959
transport.onerror = (err) => {
60-
logger.error("DeepWiki MCP Transport Error:", err);
60+
logger.error('DeepWiki MCP Transport Error:', err);
6161
resetClient(); // 出错时重置,下次调用会触发重连
6262
};
6363

6464
transport.onclose = () => {
65-
logger.info("DeepWiki MCP Connection Closed");
65+
logger.info('DeepWiki MCP Connection Closed');
6666
resetClient();
6767
};
6868

@@ -71,11 +71,11 @@ async function getMcpClient(): Promise<Client> {
7171
// 连接成功,赋值给模块级变量
7272
_client = client;
7373
_transport = transport;
74-
logger.info("DeepWiki MCP: 连接成功");
74+
logger.info('DeepWiki MCP: 连接成功');
7575

7676
return client;
7777
} catch (error) {
78-
logger.error("DeepWiki MCP: 连接失败", error);
78+
logger.error('DeepWiki MCP: 连接失败', error);
7979
resetClient();
8080
throw error;
8181
} finally {
@@ -103,7 +103,10 @@ function resetClient() {
103103
* 查询 DeepWiki
104104
* 外部调用就像调用普通函数一样,无需关心连接管理
105105
*/
106-
export async function queryDeepWiki(_params: {repoName: string, question: string}): Promise<string> {
106+
export async function queryDeepWiki(_params: {
107+
repoName: string;
108+
question: string;
109+
}): Promise<string> {
107110
try {
108111
const params = {
109112
..._params,
@@ -117,7 +120,7 @@ export async function queryDeepWiki(_params: {repoName: string, question: string
117120

118121
// 调用工具
119122
const result: any = await client.callTool({
120-
name: "ask_question",
123+
name: 'ask_question',
121124
arguments: params,
122125
});
123126

@@ -127,27 +130,27 @@ export async function queryDeepWiki(_params: {repoName: string, question: string
127130
// result.content 是一个数组,可能包含 text, image 等
128131
// 这里我们使用 reduce 提取所有 text 类型的内容并拼接
129132
let answer = result.content
130-
.filter((item: any) => item.type === "text")
133+
.filter((item: any) => item.type === 'text')
131134
.map((item: any) => item.text)
132-
.join("\n"); // 如果有多段文本,用换行符拼接
135+
.join('\n'); // 如果有多段文本,用换行符拼接
133136

134-
const regex = /Wiki pages you might want to explore:|View this search on DeepWiki:/i;
137+
const regex =
138+
/Wiki pages you might want to explore:|View this search on DeepWiki:/i;
135139
const splitIndex = answer.search(regex);
136140
// 如果找到了标记 (splitIndex !== -1)
137141
if (splitIndex !== -1) {
138142
// 截取从开头到标记之前的部分,并清理末尾的空白
139-
answer = answer.slice(0, splitIndex).trimEnd();
143+
answer = answer.slice(0, splitIndex).trimEnd();
140144
}
141145

142146
if (!answer || answer.startsWith('Error')) {
143147
// 防御性编程:如果返回内容为空
144-
throw new Error("DeepWiki return Empty/Error Answer, Answer = " + answer);
148+
throw new Error('DeepWiki return Empty/Error Answer, Answer = ' + answer);
145149
}
146150

147151
return answer;
148-
149152
} catch (error) {
150-
logger.error("DeepWiki Query Error:", error);
153+
logger.error('DeepWiki Query Error:', error);
151154
// 根据业务需求,这里可以选择抛出错误,或者返回空字符串/错误提示字符串
152155
// 如果是网络断开等错误,resetClient 会在下一次调用时触发重连
153156
if (_client) {
@@ -159,15 +162,18 @@ export async function queryDeepWiki(_params: {repoName: string, question: string
159162
}
160163
}
161164

162-
export async function adaptedQueryDeepWiki(_params: { repoName: string, question: string }) {
165+
export async function adaptedQueryDeepWiki(_params: {
166+
repoName: string;
167+
question: string;
168+
}) {
163169
try {
164170
const answer = await queryDeepWiki(_params);
165-
return { documentation: answer }
171+
return { documentation: answer };
166172
} catch (error) {
167173
return {
168174
documentation: null,
169175
error: error instanceof Error ? error.message : String(error),
170-
}
176+
};
171177
}
172178
}
173179

@@ -177,7 +183,7 @@ export async function adaptedQueryDeepWiki(_params: { repoName: string, question
177183
*/
178184
export async function closeDeepWikiConnection() {
179185
if (_transport) {
180-
logger.info("DeepWiki MCP: 关闭连接...");
186+
logger.info('DeepWiki MCP: 关闭连接...');
181187
// SDK 目前可能没有直接暴露 close 方法,通常关闭 transport 即可
182188
// SSEClientTransport 内部并没有显式的 close 方法暴露出来,
183189
// 但我们可以将引用置空,让 GC 回收,或者依赖进程退出

0 commit comments

Comments
 (0)