Skip to content

Commit 41e92c1

Browse files
committed
🧹 修复 Agent 重构遗留的 lint 问题
- 移除未使用的导入(AgentTask、sendMessage、ToolSource、部分 test helpers) - html_extractor.ts: inline import() 类型改为顶部 import type - prettier 格式化修复(with_timeout.ts、web_search.ts 等多处)
1 parent 5c02c25 commit 41e92c1

File tree

17 files changed

+107
-69
lines changed

17 files changed

+107
-69
lines changed

src/app/service/agent/core/providers/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ export interface LLMProvider {
2828
readonly name: string;
2929

3030
/** 构建 fetch 请求所需的 url 与 RequestInit */
31-
buildRequest(
32-
input: ProviderBuildRequestInput
33-
): ProviderBuildRequestOutput | Promise<ProviderBuildRequestOutput>;
31+
buildRequest(input: ProviderBuildRequestInput): ProviderBuildRequestOutput | Promise<ProviderBuildRequestOutput>;
3432

3533
/** 解析 SSE 流式响应,通过 onEvent 推送 ChatStreamEvent */
3634
parseStream(

src/app/service/agent/core/tool_registry.test.ts

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it, expect, vi } from "vitest";
22
import { ToolRegistry } from "./tool_registry";
3-
import type { ToolExecutor, ToolSource } from "./tool_registry";
3+
import type { ToolExecutor } from "./tool_registry";
44
import type { ToolCall, ToolDefinition, ToolResultWithAttachments } from "./types";
55
import type { AgentChatRepo } from "@App/app/repo/agent_chat";
66

@@ -439,13 +439,20 @@ describe("ToolRegistry", () => {
439439
describe("来源追踪 API(register / getSource / listBySource / unregisterBySource)", () => {
440440
it("register 注册工具后 getSource 应返回正确来源", () => {
441441
const registry = new ToolRegistry();
442-
registry.register("mcp", weatherDef, createExecutor(async () => "ok"));
442+
registry.register(
443+
"mcp",
444+
weatherDef,
445+
createExecutor(async () => "ok")
446+
);
443447
expect(registry.getSource("get_weather")).toBe("mcp");
444448
});
445449

446450
it("registerBuiltin 注册的工具来源应为 builtin", () => {
447451
const registry = new ToolRegistry();
448-
registry.registerBuiltin(weatherDef, createExecutor(async () => "ok"));
452+
registry.registerBuiltin(
453+
weatherDef,
454+
createExecutor(async () => "ok")
455+
);
449456
expect(registry.getSource("get_weather")).toBe("builtin");
450457
});
451458

@@ -456,9 +463,21 @@ describe("ToolRegistry", () => {
456463

457464
it("listBySource 应只返回指定来源的工具名", () => {
458465
const registry = new ToolRegistry();
459-
registry.register("builtin", weatherDef, createExecutor(async () => ""));
460-
registry.register("mcp", calcDef, createExecutor(async () => ""));
461-
registry.register("skill", { name: "load_skill", description: "加载 skill", parameters: { type: "object", properties: {} } }, createExecutor(async () => ""));
466+
registry.register(
467+
"builtin",
468+
weatherDef,
469+
createExecutor(async () => "")
470+
);
471+
registry.register(
472+
"mcp",
473+
calcDef,
474+
createExecutor(async () => "")
475+
);
476+
registry.register(
477+
"skill",
478+
{ name: "load_skill", description: "加载 skill", parameters: { type: "object", properties: {} } },
479+
createExecutor(async () => "")
480+
);
462481

463482
expect(registry.listBySource("builtin")).toEqual(["get_weather"]);
464483
expect(registry.listBySource("mcp")).toEqual(["calc"]);
@@ -468,9 +487,21 @@ describe("ToolRegistry", () => {
468487

469488
it("unregisterBySource 应批量删除指定来源的工具并返回名称列表", () => {
470489
const registry = new ToolRegistry();
471-
registry.register("mcp", weatherDef, createExecutor(async () => ""));
472-
registry.register("mcp", calcDef, createExecutor(async () => ""));
473-
registry.register("builtin", { name: "web_fetch", description: "抓取", parameters: { type: "object", properties: {} } }, createExecutor(async () => ""));
490+
registry.register(
491+
"mcp",
492+
weatherDef,
493+
createExecutor(async () => "")
494+
);
495+
registry.register(
496+
"mcp",
497+
calcDef,
498+
createExecutor(async () => "")
499+
);
500+
registry.register(
501+
"builtin",
502+
{ name: "web_fetch", description: "抓取", parameters: { type: "object", properties: {} } },
503+
createExecutor(async () => "")
504+
);
474505

475506
const removed = registry.unregisterBySource("mcp");
476507
expect(removed).toHaveLength(2);
@@ -483,13 +514,21 @@ describe("ToolRegistry", () => {
483514

484515
it("unregisterBySource 无匹配工具时应返回空数组", () => {
485516
const registry = new ToolRegistry();
486-
registry.register("builtin", weatherDef, createExecutor(async () => ""));
517+
registry.register(
518+
"builtin",
519+
weatherDef,
520+
createExecutor(async () => "")
521+
);
487522
expect(registry.unregisterBySource("mcp")).toEqual([]);
488523
});
489524

490525
it("unregister 应按名称删除工具", () => {
491526
const registry = new ToolRegistry();
492-
registry.register("mcp", weatherDef, createExecutor(async () => ""));
527+
registry.register(
528+
"mcp",
529+
weatherDef,
530+
createExecutor(async () => "")
531+
);
493532
expect(registry.unregister("get_weather")).toBe(true);
494533
expect(registry.getDefinitions()).toHaveLength(0);
495534
});
@@ -503,7 +542,11 @@ describe("ToolRegistry", () => {
503542
describe("withScopedTools", () => {
504543
it("fn 正常执行后应清理所有 scoped 工具", async () => {
505544
const registry = new ToolRegistry();
506-
registry.register("builtin", weatherDef, createExecutor(async () => ""));
545+
registry.register(
546+
"builtin",
547+
weatherDef,
548+
createExecutor(async () => "")
549+
);
507550

508551
await registry.withScopedTools(
509552
"skill",
@@ -551,8 +594,16 @@ describe("ToolRegistry", () => {
551594

552595
it("多个 scoped 工具应全部被清理", async () => {
553596
const registry = new ToolRegistry();
554-
const toolA: ToolDefinition = { name: "tool_a", description: "A", parameters: { type: "object", properties: {} } };
555-
const toolB: ToolDefinition = { name: "tool_b", description: "B", parameters: { type: "object", properties: {} } };
597+
const toolA: ToolDefinition = {
598+
name: "tool_a",
599+
description: "A",
600+
parameters: { type: "object", properties: {} },
601+
};
602+
const toolB: ToolDefinition = {
603+
name: "tool_b",
604+
description: "B",
605+
parameters: { type: "object", properties: {} },
606+
};
556607

557608
await registry.withScopedTools(
558609
"skill",

src/app/service/agent/core/tools/web_search.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,7 @@ export class WebSearchExecutor implements ToolExecutor {
8282
let results: Awaited<ReturnType<typeof extractSearchResults>>;
8383
let extractionFailed = false;
8484
try {
85-
results = await withTimeout(
86-
extractSearchResults(this.sender, html),
87-
10_000,
88-
() => new Error("extract timeout")
89-
);
85+
results = await withTimeout(extractSearchResults(this.sender, html), 10_000, () => new Error("extract timeout"));
9086
} catch {
9187
results = [];
9288
extractionFailed = true;
@@ -113,11 +109,7 @@ export class WebSearchExecutor implements ToolExecutor {
113109
let results: Awaited<ReturnType<typeof extractBingResults>>;
114110
let extractionFailed = false;
115111
try {
116-
results = await withTimeout(
117-
extractBingResults(this.sender, html),
118-
10_000,
119-
() => new Error("extract timeout")
120-
);
112+
results = await withTimeout(extractBingResults(this.sender, html), 10_000, () => new Error("extract timeout"));
121113
} catch {
122114
results = [];
123115
extractionFailed = true;
@@ -144,11 +136,7 @@ export class WebSearchExecutor implements ToolExecutor {
144136
let results: Awaited<ReturnType<typeof extractBaiduResults>>;
145137
let extractionFailed = false;
146138
try {
147-
results = await withTimeout(
148-
extractBaiduResults(this.sender, html),
149-
10_000,
150-
() => new Error("extract timeout")
151-
);
139+
results = await withTimeout(extractBaiduResults(this.sender, html), 10_000, () => new Error("extract timeout"));
152140
} catch {
153141
results = [];
154142
extractionFailed = true;

src/app/service/agent/service_worker/agent.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ import type {
1313
SkillRecord,
1414
SkillSummary,
1515
MessageContent,
16-
AgentTask,
1716
AgentTaskApiRequest,
1817
ModelApiRequest,
1918
OPFSApiRequest,
2019
MCPApiRequest,
2120
} from "@App/app/service/agent/core/types";
2221
import { AgentChatRepo } from "@App/app/repo/agent_chat";
23-
import { AgentModelRepo } from "@App/app/repo/agent_model";
24-
import { SkillRepo } from "@App/app/repo/skill_repo";
22+
import type { AgentModelRepo } from "@App/app/repo/agent_model";
23+
import type { SkillRepo } from "@App/app/repo/skill_repo";
2524
import { uuidv4 } from "@App/pkg/utils/uuid";
2625
import { ToolRegistry } from "@App/app/service/agent/core/tool_registry";
2726
import { SKILL_SCRIPT_UUID_PREFIX } from "@App/app/service/agent/core/skill_script_executor";
@@ -36,7 +35,6 @@ import { AgentTaskService } from "./task_service";
3635
import { AgentModelService } from "./model_service";
3736
import { AgentTaskRepo, AgentTaskRunRepo } from "@App/app/repo/agent_task";
3837
import { AgentTaskScheduler } from "@App/app/service/agent/core/task_scheduler";
39-
import { sendMessage } from "@Packages/message/client";
4038
import { WEB_FETCH_DEFINITION, WebFetchExecutor } from "@App/app/service/agent/core/tools/web_fetch";
4139
import { WEB_SEARCH_DEFINITION, WebSearchExecutor } from "@App/app/service/agent/core/tools/web_search";
4240
import { SearchConfigRepo, type SearchEngineConfig } from "@App/app/service/agent/core/tools/search_config";
@@ -52,7 +50,6 @@ import { ChatService } from "./chat_service";
5250
// 保留对外 API(测试文件直接从 "./agent" import 这三个函数)
5351
export { isRetryableError, withRetry, classifyErrorCode } from "./retry_utils";
5452

55-
5653
export class AgentService {
5754
private _repo = new AgentChatRepo();
5855
// 测试兼容性:透传访问 repo,setter 同步更新 compactService

src/app/service/agent/service_worker/autocompact.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2-
import { createTestService, makeSSEResponse, makeTextResponse } from "./test-helpers";
2+
import { createTestService, makeSSEResponse } from "./test-helpers";
33

44
// ---- Compact 功能测试 ----
55

src/app/service/agent/service_worker/background.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2-
import { createTestService, makeSSEResponse, makeTextResponse, createRunningConversation } from "./test-helpers";
2+
import { createTestService, makeTextResponse, createRunningConversation } from "./test-helpers";
33

44
// ---- updateStreamingState 快照状态管理 ----
55

src/app/service/agent/service_worker/chat.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2-
import { createTestService, makeSkillRecord, makeSkillScriptRecord, makeTextResponse, makeSSEResponse } from "./test-helpers";
2+
import { createTestService, makeSkillRecord, makeSkillScriptRecord, makeTextResponse } from "./test-helpers";
33

44
// ---- handleConversationChat skipSaveUserMessage(重新生成 bug 修复验证)----
55

src/app/service/agent/service_worker/chat_service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ import type { SubAgentService } from "./sub_agent_service";
2121
import type { ToolLoopOrchestrator } from "./tool_loop_orchestrator";
2222
import type { SubAgentRunOptions } from "@App/app/service/agent/core/tools/sub_agent";
2323
import { buildSystemPrompt } from "@App/app/service/agent/core/system_prompt";
24-
import { COMPACT_SYSTEM_PROMPT, buildCompactUserPrompt, extractSummary } from "@App/app/service/agent/core/compact_prompt";
24+
import {
25+
COMPACT_SYSTEM_PROMPT,
26+
buildCompactUserPrompt,
27+
extractSummary,
28+
} from "@App/app/service/agent/core/compact_prompt";
2529
import { createTaskTools } from "@App/app/service/agent/core/tools/task_tools";
2630
import { createAskUserTool } from "@App/app/service/agent/core/tools/ask_user";
2731
import { createSubAgentTool } from "@App/app/service/agent/core/tools/sub_agent";

src/app/service/agent/service_worker/compact_service.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import type { AgentChatRepo } from "@App/app/repo/agent_chat";
2-
import type { AgentModelConfig, ChatRequest, ChatStreamEvent, ToolCall, ContentBlock, ToolDefinition } from "@App/app/service/agent/core/types";
2+
import type {
3+
AgentModelConfig,
4+
ChatRequest,
5+
ChatStreamEvent,
6+
ToolCall,
7+
ContentBlock,
8+
ToolDefinition,
9+
} from "@App/app/service/agent/core/types";
310
import {
411
COMPACT_SYSTEM_PROMPT,
512
buildCompactUserPrompt,

src/app/service/agent/service_worker/dom.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,7 @@ describe("AgentDomService", () => {
182182
});
183183

184184
it("应拒绝导航到 chrome:// URL", async () => {
185-
await expect(service.navigate("chrome://settings")).rejects.toThrow(
186-
"Agent DOM operation not allowed for URL:"
187-
);
185+
await expect(service.navigate("chrome://settings")).rejects.toThrow("Agent DOM operation not allowed for URL:");
188186
});
189187

190188
it("应拒绝导航到 chrome-extension:// URL", async () => {

0 commit comments

Comments
 (0)