Skip to content

Commit 34df70d

Browse files
committed
🔧 prettier 自动格式化
1 parent cb0ebff commit 34df70d

19 files changed

Lines changed: 362 additions & 308 deletions

example/tests/unwrap_test.js

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,49 +18,44 @@ var test_global_injection = "success";
1818
// User can access the variable "test_global_injection" directly in DevTools
1919

2020
(function () {
21-
const results = {
22-
GM: {
23-
expected: "undefined",
24-
actual: typeof GM,
25-
},
26-
GM_setValue: {
27-
expected: "undefined",
28-
actual: typeof GM_setValue,
29-
},
30-
jQuery: {
31-
expected: "function",
32-
actual: typeof jQuery,
33-
},
21+
const results = {
22+
GM: {
23+
expected: "undefined",
24+
actual: typeof GM,
25+
},
26+
GM_setValue: {
27+
expected: "undefined",
28+
actual: typeof GM_setValue,
29+
},
30+
jQuery: {
31+
expected: "function",
32+
actual: typeof jQuery,
33+
},
34+
};
35+
36+
console.group("%c@unwrap Test", "color:#0aa;font-weight:bold");
37+
38+
const table = {};
39+
let allPass = true;
40+
41+
for (const key in results) {
42+
const { expected, actual } = results[key];
43+
const pass = expected === actual;
44+
allPass &&= pass;
45+
46+
table[key] = {
47+
Expected: expected,
48+
Actual: actual,
49+
Result: pass ? "✅ PASS" : "❌ FAIL",
3450
};
51+
}
3552

36-
console.group(
37-
"%c@unwrap Test",
38-
"color:#0aa;font-weight:bold"
39-
);
53+
console.table(table);
4054

41-
const table = {};
42-
let allPass = true;
55+
console.log(
56+
allPass ? "%cAll tests passed ✔" : "%cSome tests failed ✘",
57+
`font-weight:bold;color:${allPass ? "green" : "red"}`
58+
);
4359

44-
for (const key in results) {
45-
const { expected, actual } = results[key];
46-
const pass = expected === actual;
47-
allPass &&= pass;
48-
49-
table[key] = {
50-
Expected: expected,
51-
Actual: actual,
52-
Result: pass ? "✅ PASS" : "❌ FAIL",
53-
};
54-
}
55-
56-
console.table(table);
57-
58-
console.log(
59-
allPass
60-
? "%cAll tests passed ✔"
61-
: "%cSome tests failed ✘",
62-
`font-weight:bold;color:${allPass ? "green" : "red"}`
63-
);
64-
65-
console.groupEnd();
60+
console.groupEnd();
6661
})();

src/app/repo/agent_chat.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,5 +179,4 @@ export class AgentChatRepo extends OPFSRepo {
179179
const tasksDir = await this.getChildDir(TASKS_DIR);
180180
await this.deleteFile(`${conversationId}.json`, tasksDir);
181181
}
182-
183182
}

src/app/service/agent/sub_agent_types.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,14 @@ export interface SubAgentTypeConfig {
1111
}
1212

1313
// 所有子代理类型都默认可用的工具(task 工具用于与主 agent 共享任务进度)
14-
const ALWAYS_ALLOWED_TOOLS = [
15-
"create_task",
16-
"update_task",
17-
"get_task",
18-
"list_tasks",
19-
"delete_task",
20-
];
14+
const ALWAYS_ALLOWED_TOOLS = ["create_task", "update_task", "get_task", "list_tasks", "delete_task"];
2115

2216
// 内置子代理类型
2317
export const SUB_AGENT_TYPES: Record<string, SubAgentTypeConfig> = {
2418
researcher: {
2519
name: "researcher",
2620
description: "Web search/fetch, data analysis, no tab interaction",
27-
allowedTools: [
28-
"web_fetch",
29-
"web_search",
30-
"opfs_read",
31-
"opfs_write",
32-
"opfs_list",
33-
"opfs_delete",
34-
"execute_script",
35-
],
21+
allowedTools: ["web_fetch", "web_search", "opfs_read", "opfs_write", "opfs_list", "opfs_delete", "execute_script"],
3622
maxIterations: 20,
3723
timeoutMs: 600_000,
3824
systemPromptAddition: `## Role: Researcher

src/app/service/agent/system_prompt.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { describe, expect, it } from "vitest";
22

3-
import {
4-
buildSystemPrompt,
5-
buildSubAgentSystemPrompt,
6-
_BUILTIN_SYSTEM_PROMPT_FOR_TEST,
7-
} from "./system_prompt";
3+
import { buildSystemPrompt, buildSubAgentSystemPrompt, _BUILTIN_SYSTEM_PROMPT_FOR_TEST } from "./system_prompt";
84
import { SUB_AGENT_TYPES } from "./sub_agent_types";
95

106
describe("buildSystemPrompt", () => {

src/app/service/agent/system_prompt.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,7 @@ export function buildSystemPrompt(options: BuildSystemPromptOptions): string {
355355
/**
356356
* 组装子代理的 system prompt:子代理专用基础提示词 + 类型角色说明 + 动态工具指南 + 条件 OPFS 段
357357
*/
358-
export function buildSubAgentSystemPrompt(
359-
typeConfig: SubAgentTypeConfig,
360-
availableToolNames: string[]
361-
): string {
358+
export function buildSubAgentSystemPrompt(typeConfig: SubAgentTypeConfig, availableToolNames: string[]): string {
362359
const nameSet = new Set(availableToolNames);
363360
const hasOpfs = nameSet.has("opfs_read") || nameSet.has("opfs_write");
364361
const hasTabTools = nameSet.has("get_tab_content");

src/app/service/agent/tool_call_guard.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,19 @@ describe("detectToolCallIssues", () => {
8888
it("中间穿插其他工具但 execute_script 仍然连续 null 时触发", () => {
8989
const history: ToolCallRecord[] = [
9090
{ name: "execute_script", args: '{"code":"a()"}', result: '{"result":null}', iteration: 1 },
91-
{ name: "get_tab_content", args: '{"tab_id":1,"prompt":"find buttons"}', result: "page content...", iteration: 2 },
91+
{
92+
name: "get_tab_content",
93+
args: '{"tab_id":1,"prompt":"find buttons"}',
94+
result: "page content...",
95+
iteration: 2,
96+
},
9297
{ name: "execute_script", args: '{"code":"b()"}', result: '{"result":null}', iteration: 3 },
93-
{ name: "get_tab_content", args: '{"tab_id":1,"prompt":"check state"}', result: "page content...", iteration: 4 },
98+
{
99+
name: "get_tab_content",
100+
args: '{"tab_id":1,"prompt":"check state"}',
101+
result: "page content...",
102+
iteration: 4,
103+
},
94104
{ name: "execute_script", args: '{"code":"c()"}', result: '{"result":null}', iteration: 5 },
95105
];
96106
const warning = detectToolCallIssues(history);

src/app/service/agent/tools/execute_script.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T> {
3838
}
3939

4040
export type ExecuteScriptDeps = {
41-
executeInPage: (
42-
code: string,
43-
options?: { tabId?: number }
44-
) => Promise<{ result: unknown; tabId: number }>;
41+
executeInPage: (code: string, options?: { tabId?: number }) => Promise<{ result: unknown; tabId: number }>;
4542
executeInSandbox: (code: string) => Promise<unknown>;
4643
timeoutMs?: number; // 可选超时(ms),默认 30s,测试用
4744
};

src/app/service/agent/tools/tab_tools.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ const GET_TAB_CONTENT_DEFINITION: ToolDefinition = {
1818
tab_id: { type: "number", description: "Target tab ID (use list_tabs to find)" },
1919
prompt: {
2020
type: "string",
21-
description: "Describe what information to extract/summarize from the page content. Required for efficient context usage.",
21+
description:
22+
"Describe what information to extract/summarize from the page content. Required for efficient context usage.",
2223
},
2324
selector: {
2425
type: "string",

src/app/service/agent/tools/web_fetch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export const WEB_FETCH_DEFINITION: ToolDefinition = {
1414
url: { type: "string", description: "The URL to fetch (http/https)" },
1515
prompt: {
1616
type: "string",
17-
description: "Describe what information to extract/summarize from the fetched content. Required for efficient context usage.",
17+
description:
18+
"Describe what information to extract/summarize from the fetched content. Required for efficient context usage.",
1819
},
1920
max_length: { type: "number", description: "Max characters to return (no limit by default)" },
2021
},

src/app/service/content/gm_api/cat_agent.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,12 @@ export class ConversationInstance {
529529
const result = await handler(args);
530530
results.push({ id: tc.id, result: typeof result === "string" ? result : JSON.stringify(result) });
531531
} catch (e: any) {
532-
const errorMsg = e instanceof Error ? e.message || e.toString() : typeof e === "string" ? e : String(e) || "Tool execution failed";
532+
const errorMsg =
533+
e instanceof Error
534+
? e.message || e.toString()
535+
: typeof e === "string"
536+
? e
537+
: String(e) || "Tool execution failed";
533538
results.push({ id: tc.id, result: JSON.stringify({ error: errorMsg }) });
534539
}
535540
}

0 commit comments

Comments
 (0)