@kalenkevich/agent_007 0.0.1
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/agent/agent.d.ts +17 -0
- package/dist/agent/agent.js +6 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/agent_event.d.ts +108 -0
- package/dist/agent/agent_event.js +56 -0
- package/dist/agent/agent_event.js.map +1 -0
- package/dist/agent/agent_event_utils.d.ts +5 -0
- package/dist/agent/agent_event_utils.js +66 -0
- package/dist/agent/agent_event_utils.js.map +1 -0
- package/dist/agent/cli_agent/cli_agent.d.ts +41 -0
- package/dist/agent/cli_agent/cli_agent.js +324 -0
- package/dist/agent/cli_agent/cli_agent.js.map +1 -0
- package/dist/agent/cli_agent/system_prompt.d.ts +1 -0
- package/dist/agent/cli_agent/system_prompt.js +58 -0
- package/dist/agent/cli_agent/system_prompt.js.map +1 -0
- package/dist/agent/cli_agent.d.ts +34 -0
- package/dist/agent/cli_agent.js +91 -0
- package/dist/agent/cli_agent.js.map +1 -0
- package/dist/agent/planner_agent/planner_agent.d.ts +28 -0
- package/dist/agent/planner_agent/planner_agent.js +102 -0
- package/dist/agent/planner_agent/planner_agent.js.map +1 -0
- package/dist/agent/request_processor/basic_request_processor.d.ts +17 -0
- package/dist/agent/request_processor/basic_request_processor.js +28 -0
- package/dist/agent/request_processor/basic_request_processor.js.map +1 -0
- package/dist/agent/request_processor/compaction_processor.d.ts +17 -0
- package/dist/agent/request_processor/compaction_processor.js +118 -0
- package/dist/agent/request_processor/compaction_processor.js.map +1 -0
- package/dist/agent/request_processor/request_processor.d.ts +11 -0
- package/dist/agent/request_processor/request_processor.js +2 -0
- package/dist/agent/request_processor/request_processor.js.map +1 -0
- package/dist/cli/init_project_command_handler.d.ts +3 -0
- package/dist/cli/init_project_command_handler.js +58 -0
- package/dist/cli/init_project_command_handler.js.map +1 -0
- package/dist/cli/loader.d.ts +6 -0
- package/dist/cli/loader.js +27 -0
- package/dist/cli/loader.js.map +1 -0
- package/dist/cli/prompt_utils.d.ts +11 -0
- package/dist/cli/prompt_utils.js +18 -0
- package/dist/cli/prompt_utils.js.map +1 -0
- package/dist/cli/run_command.d.ts +6 -0
- package/dist/cli/run_command.js +72 -0
- package/dist/cli/run_command.js.map +1 -0
- package/dist/cli/run_interactive_command.d.ts +6 -0
- package/dist/cli/run_interactive_command.js +282 -0
- package/dist/cli/run_interactive_command.js.map +1 -0
- package/dist/cli/run_noninteractive_command.d.ts +6 -0
- package/dist/cli/run_noninteractive_command.js +60 -0
- package/dist/cli/run_noninteractive_command.js.map +1 -0
- package/dist/cli_entrypoint.d.ts +2 -0
- package/dist/cli_entrypoint.js +110 -0
- package/dist/cli_entrypoint.js.map +1 -0
- package/dist/command/commnad_handler.d.ts +3 -0
- package/dist/command/commnad_handler.js +2 -0
- package/dist/command/commnad_handler.js.map +1 -0
- package/dist/command/init_project_command_handler.d.ts +4 -0
- package/dist/command/init_project_command_handler.js +58 -0
- package/dist/command/init_project_command_handler.js.map +1 -0
- package/dist/config/app_dir.d.ts +1 -0
- package/dist/config/app_dir.js +4 -0
- package/dist/config/app_dir.js.map +1 -0
- package/dist/config/config.d.ts +21 -0
- package/dist/config/config.js +2 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/config_loader.d.ts +2 -0
- package/dist/config/config_loader.js +47 -0
- package/dist/config/config_loader.js.map +1 -0
- package/dist/config/config_store.d.ts +10 -0
- package/dist/config/config_store.js +44 -0
- package/dist/config/config_store.js.map +1 -0
- package/dist/content.d.ts +51 -0
- package/dist/content.js +16 -0
- package/dist/content.js.map +1 -0
- package/dist/core/functions.d.ts +1 -0
- package/dist/core/functions.js +6 -0
- package/dist/core/functions.js.map +1 -0
- package/dist/core/loop.d.ts +20 -0
- package/dist/core/loop.js +121 -0
- package/dist/core/loop.js.map +1 -0
- package/dist/core/project_service.d.ts +11 -0
- package/dist/core/project_service.js +26 -0
- package/dist/core/project_service.js.map +1 -0
- package/dist/core/run.d.ts +6 -0
- package/dist/core/run.js +25 -0
- package/dist/core/run.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +27 -0
- package/dist/logger.js +98 -0
- package/dist/logger.js.map +1 -0
- package/dist/model/adaptive_model.d.ts +16 -0
- package/dist/model/adaptive_model.js +57 -0
- package/dist/model/adaptive_model.js.map +1 -0
- package/dist/model/google/gemini_model.d.ts +15 -0
- package/dist/model/google/gemini_model.js +131 -0
- package/dist/model/google/gemini_model.js.map +1 -0
- package/dist/model/google/gemini_response_utils.d.ts +3 -0
- package/dist/model/google/gemini_response_utils.js +36 -0
- package/dist/model/google/gemini_response_utils.js.map +1 -0
- package/dist/model/google/gemini_streaming_utils.d.ts +28 -0
- package/dist/model/google/gemini_streaming_utils.js +235 -0
- package/dist/model/google/gemini_streaming_utils.js.map +1 -0
- package/dist/model/google/gen_ai_convert_utils.d.ts +6 -0
- package/dist/model/google/gen_ai_convert_utils.js +117 -0
- package/dist/model/google/gen_ai_convert_utils.js.map +1 -0
- package/dist/model/model.d.ts +11 -0
- package/dist/model/model.js +2 -0
- package/dist/model/model.js.map +1 -0
- package/dist/model/registry.d.ts +19 -0
- package/dist/model/registry.js +47 -0
- package/dist/model/registry.js.map +1 -0
- package/dist/model/request.d.ts +13 -0
- package/dist/model/request.js +2 -0
- package/dist/model/request.js.map +1 -0
- package/dist/model/request_builder_utils.d.ts +19 -0
- package/dist/model/request_builder_utils.js +43 -0
- package/dist/model/request_builder_utils.js.map +1 -0
- package/dist/model/response.d.ts +60 -0
- package/dist/model/response.js +2 -0
- package/dist/model/response.js.map +1 -0
- package/dist/model/util_llm.d.ts +10 -0
- package/dist/model/util_llm.js +149 -0
- package/dist/model/util_llm.js.map +1 -0
- package/dist/session/session.d.ts +14 -0
- package/dist/session/session.js +2 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/session_file_service.d.ts +23 -0
- package/dist/session/session_file_service.js +147 -0
- package/dist/session/session_file_service.js.map +1 -0
- package/dist/skills/skill.d.ts +23 -0
- package/dist/skills/skill.js +12 -0
- package/dist/skills/skill.js.map +1 -0
- package/dist/tools/build_in/find.d.ts +3 -0
- package/dist/tools/build_in/find.js +71 -0
- package/dist/tools/build_in/find.js.map +1 -0
- package/dist/tools/build_in/grep.d.ts +3 -0
- package/dist/tools/build_in/grep.js +97 -0
- package/dist/tools/build_in/grep.js.map +1 -0
- package/dist/tools/build_in/index.d.ts +1 -0
- package/dist/tools/build_in/index.js +13 -0
- package/dist/tools/build_in/index.js.map +1 -0
- package/dist/tools/build_in/list_dir.d.ts +3 -0
- package/dist/tools/build_in/list_dir.js +46 -0
- package/dist/tools/build_in/list_dir.js.map +1 -0
- package/dist/tools/build_in/view_file.d.ts +3 -0
- package/dist/tools/build_in/view_file.js +44 -0
- package/dist/tools/build_in/view_file.js.map +1 -0
- package/dist/tools/build_in/write_file.d.ts +3 -0
- package/dist/tools/build_in/write_file.js +50 -0
- package/dist/tools/build_in/write_file.js.map +1 -0
- package/dist/tools/functional_tool.d.ts +18 -0
- package/dist/tools/functional_tool.js +20 -0
- package/dist/tools/functional_tool.js.map +1 -0
- package/dist/tools/schema.d.ts +86 -0
- package/dist/tools/schema.js +37 -0
- package/dist/tools/schema.js.map +1 -0
- package/dist/tools/tool.d.ts +30 -0
- package/dist/tools/tool.js +9 -0
- package/dist/tools/tool.js.map +1 -0
- package/dist/tools/tool_call_policy.d.ts +4 -0
- package/dist/tools/tool_call_policy.js +4 -0
- package/dist/tools/tool_call_policy.js.map +1 -0
- package/dist/tools/tool_policy.d.ts +4 -0
- package/dist/tools/tool_policy.js +4 -0
- package/dist/tools/tool_policy.js.map +1 -0
- package/dist/ui/ui.d.ts +1 -0
- package/dist/ui/ui.js +2 -0
- package/dist/ui/ui.js.map +1 -0
- package/dist/user_input.d.ts +20 -0
- package/dist/user_input.js +21 -0
- package/dist/user_input.js.map +1 -0
- package/package.json +44 -0
- package/src/agent/agent.ts +18 -0
- package/src/agent/agent_event.ts +171 -0
- package/src/agent/agent_event_utils.ts +87 -0
- package/src/agent/cli_agent/cli_agent.ts +418 -0
- package/src/agent/cli_agent/system_prompt.ts +57 -0
- package/src/agent/planner_agent/planner_agent.ts +136 -0
- package/src/agent/request_processor/basic_request_processor.ts +46 -0
- package/src/agent/request_processor/compaction_processor.ts +164 -0
- package/src/agent/request_processor/request_processor.ts +13 -0
- package/src/cli/loader.ts +27 -0
- package/src/cli/prompt_utils.ts +19 -0
- package/src/cli/run_interactive_command.ts +337 -0
- package/src/cli/run_noninteractive_command.ts +74 -0
- package/src/cli_entrypoint.ts +128 -0
- package/src/command/commnad_handler.ts +3 -0
- package/src/command/init_project_command_handler.ts +66 -0
- package/src/config/app_dir.ts +4 -0
- package/src/config/config.ts +24 -0
- package/src/config/config_loader.ts +57 -0
- package/src/config/config_store.ts +50 -0
- package/src/content.ts +87 -0
- package/src/core/functions.ts +7 -0
- package/src/core/loop.ts +165 -0
- package/src/core/project_service.ts +38 -0
- package/src/core/run.ts +36 -0
- package/src/index.ts +1 -0
- package/src/logger.ts +128 -0
- package/src/model/adaptive_model.ts +77 -0
- package/src/model/google/gemini_model.ts +194 -0
- package/src/model/google/gemini_response_utils.ts +46 -0
- package/src/model/google/gemini_streaming_utils.ts +294 -0
- package/src/model/google/gen_ai_convert_utils.ts +149 -0
- package/src/model/model.ts +18 -0
- package/src/model/registry.ts +61 -0
- package/src/model/request.ts +15 -0
- package/src/model/request_builder_utils.ts +79 -0
- package/src/model/response.ts +66 -0
- package/src/model/util_llm.ts +167 -0
- package/src/session/session.ts +16 -0
- package/src/session/session_file_service.ts +207 -0
- package/src/skills/skill.ts +38 -0
- package/src/tools/build_in/find.ts +80 -0
- package/src/tools/build_in/grep.ts +101 -0
- package/src/tools/build_in/index.ts +13 -0
- package/src/tools/build_in/list_dir.ts +50 -0
- package/src/tools/build_in/view_file.ts +47 -0
- package/src/tools/build_in/write_file.ts +53 -0
- package/src/tools/functional_tool.ts +59 -0
- package/src/tools/schema.ts +87 -0
- package/src/tools/tool.ts +68 -0
- package/src/tools/tool_call_policy.ts +7 -0
- package/src/ui/ui.ts +0 -0
- package/src/user_input.ts +51 -0
- package/tests/integration/util_llm_test.ts +42 -0
- package/tests/unit/adaptive_model_test.ts +122 -0
- package/tests/unit/agent/request_processor/compaction_processor_test.ts +121 -0
- package/tests/unit/cli/prompt_utils_test.ts +47 -0
- package/tests/unit/cli_agent_test.ts +476 -0
- package/tests/unit/content_test.ts +56 -0
- package/tests/unit/logger_test.ts +109 -0
- package/tests/unit/loop_test.ts +141 -0
- package/tests/unit/model/gemini_model_test.ts +111 -0
- package/tests/unit/planner_agent_test.ts +52 -0
- package/tests/unit/project_service_test.ts +102 -0
- package/tests/unit/session_file_service_test.ts +160 -0
- package/tests/unit/tools/find_test.ts +40 -0
- package/tests/unit/tools/grep_test.ts +43 -0
- package/tests/unit/tools/list_dir_test.ts +32 -0
- package/tests/unit/tools/view_file_test.ts +32 -0
- package/tests/unit/tools/write_file_test.ts +44 -0
- package/tests/unit/user_input_test.ts +55 -0
- package/tests/unit/util_llm_test.ts +61 -0
- package/todo.md +29 -0
- package/tsconfig.json +33 -0
- package/vitest.config.ts +33 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import {} from "../agent/agent_event.js";
|
|
3
|
+
import { APP_FILE_DIR } from "../config/app_dir.js";
|
|
4
|
+
import * as fs from "node:fs/promises";
|
|
5
|
+
import * as path from "node:path";
|
|
6
|
+
export class SessionFileService {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.initialized = false;
|
|
9
|
+
this.locks = new Map();
|
|
10
|
+
this.rootDir = path.join(APP_FILE_DIR, "sessions");
|
|
11
|
+
}
|
|
12
|
+
async init() {
|
|
13
|
+
if (this.initialized) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
await fs.mkdir(this.rootDir, { recursive: true });
|
|
17
|
+
}
|
|
18
|
+
async lock(sessionId) {
|
|
19
|
+
let unlock = () => { };
|
|
20
|
+
const previous = this.locks.get(sessionId) || Promise.resolve();
|
|
21
|
+
const current = new Promise((r) => {
|
|
22
|
+
unlock = r;
|
|
23
|
+
});
|
|
24
|
+
this.locks.set(sessionId, previous.then(() => current));
|
|
25
|
+
await previous;
|
|
26
|
+
return unlock;
|
|
27
|
+
}
|
|
28
|
+
async getSession(sessionId) {
|
|
29
|
+
const sessionFilePath = getSessionFileName(this.rootDir, sessionId);
|
|
30
|
+
const metaFilePath = getSessionMetadataFileName(this.rootDir, sessionId);
|
|
31
|
+
const session = await loadFileData(sessionFilePath);
|
|
32
|
+
const sessionMeta = await loadFileData(metaFilePath);
|
|
33
|
+
if (!session || !sessionMeta) {
|
|
34
|
+
throw new Error(`Session ${sessionId} not found`);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
...session,
|
|
38
|
+
...sessionMeta,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async getSessionMetadata(sessionId) {
|
|
42
|
+
const metaFilePath = getSessionMetadataFileName(this.rootDir, sessionId);
|
|
43
|
+
const sessionMeta = await loadFileData(metaFilePath);
|
|
44
|
+
return sessionMeta;
|
|
45
|
+
}
|
|
46
|
+
async createSession(agentName, events) {
|
|
47
|
+
await this.init();
|
|
48
|
+
const session = {
|
|
49
|
+
id: randomUUID(),
|
|
50
|
+
agentName: agentName,
|
|
51
|
+
events: events,
|
|
52
|
+
timestamp: new Date().toISOString(),
|
|
53
|
+
};
|
|
54
|
+
const sessionDir = path.join(this.rootDir, session.id);
|
|
55
|
+
await fs.mkdir(sessionDir, { recursive: true });
|
|
56
|
+
await saveToFile(getSessionMetadataFileName(this.rootDir, session.id), {
|
|
57
|
+
title: session.title,
|
|
58
|
+
agentName: session.agentName,
|
|
59
|
+
timestamp: session.timestamp,
|
|
60
|
+
});
|
|
61
|
+
await saveToFile(getSessionFileName(this.rootDir, session.id), session);
|
|
62
|
+
return session;
|
|
63
|
+
}
|
|
64
|
+
async updateSession(sessionId, { title }) {
|
|
65
|
+
await this.init();
|
|
66
|
+
const unlock = await this.lock(sessionId);
|
|
67
|
+
try {
|
|
68
|
+
const metaFilePath = getSessionMetadataFileName(this.rootDir, sessionId);
|
|
69
|
+
const sessionMeta = (await loadFileData(metaFilePath));
|
|
70
|
+
if (!sessionMeta) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
sessionMeta.title = title;
|
|
74
|
+
await saveToFile(metaFilePath, sessionMeta);
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
unlock();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async appendEvent(sessionId, agentEvent) {
|
|
81
|
+
await this.init();
|
|
82
|
+
const unlock = await this.lock(sessionId);
|
|
83
|
+
try {
|
|
84
|
+
const sessionFilePath = getSessionFileName(this.rootDir, sessionId);
|
|
85
|
+
const session = (await loadFileData(sessionFilePath));
|
|
86
|
+
if (!session) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
session.events.push(agentEvent);
|
|
90
|
+
await saveToFile(sessionFilePath, session);
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
unlock();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async listSessions() {
|
|
97
|
+
await this.init();
|
|
98
|
+
const folders = await listFiles(this.rootDir);
|
|
99
|
+
const result = await Promise.all(folders.map(async (f) => {
|
|
100
|
+
try {
|
|
101
|
+
return await loadFileData(path.join(this.rootDir, f, "metadata.json"));
|
|
102
|
+
}
|
|
103
|
+
catch (e) {
|
|
104
|
+
console.warn(`Failed to load metadata for session in folder ${f}:`, e);
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
}));
|
|
108
|
+
return result.filter((f) => !!f);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
export async function listFiles(folderPath) {
|
|
112
|
+
try {
|
|
113
|
+
return await fs.readdir(folderPath);
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
console.error(`Failed to list files in folder ${folderPath}`, e);
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export function getSessionFileName(rootDir, sessionId) {
|
|
121
|
+
return path.join(rootDir, sessionId, "session.json");
|
|
122
|
+
}
|
|
123
|
+
export function getSessionMetadataFileName(rootDir, sessionId) {
|
|
124
|
+
return path.join(rootDir, sessionId, "metadata.json");
|
|
125
|
+
}
|
|
126
|
+
export async function saveToFile(filePath, data) {
|
|
127
|
+
try {
|
|
128
|
+
await fs.writeFile(filePath, typeof data === "string" ? data : JSON.stringify(data, null, 2), { encoding: "utf-8" });
|
|
129
|
+
}
|
|
130
|
+
catch (e) {
|
|
131
|
+
console.error(`Failed to write file ${filePath}:`, e);
|
|
132
|
+
throw e;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
export async function loadFileData(filePath) {
|
|
136
|
+
try {
|
|
137
|
+
return JSON.parse(await fs.readFile(filePath, { encoding: "utf-8" }));
|
|
138
|
+
}
|
|
139
|
+
catch (e) {
|
|
140
|
+
if (e.code === "ENOENT") {
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
console.error(`Failed to read or parse file ${filePath}:`, e);
|
|
144
|
+
throw e;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=session_file_service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session_file_service.js","sourceRoot":"","sources":["../../src/session/session_file_service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAmB,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,MAAM,OAAO,kBAAkB;IAK7B;QAHQ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AAC,SAAS,CAChB,QAAQ,EACR,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAC/D,EAAE,QAAQ,EAAE,OAAO,EAAE,CACtB,CAAC;IACJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,wBAAwB,QAAQ,GAAG,EAAE,CAAC,CAAC,CAAC;QAEtD,MAAM,CAAC,CAAC;IACV,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,QAAgB;IAEhB,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAM,CAAC;IAC7E,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACxB,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,gCAAgC,QAAQ,GAAG,EAAE,CAAC,CAAC,CAAC;QAE9D,MAAM,CAAC,CAAC;IACV,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { FunctionDeclaration } from "../tools/tool.js";
|
|
2
|
+
export interface SkillFrontmatter {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
license?: string;
|
|
6
|
+
compatibility?: string;
|
|
7
|
+
allowedTools?: string;
|
|
8
|
+
metadata?: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
export interface Script {
|
|
11
|
+
src: string;
|
|
12
|
+
}
|
|
13
|
+
export interface Resources {
|
|
14
|
+
references?: Record<string, string | Buffer>;
|
|
15
|
+
assets?: Record<string, string | Buffer>;
|
|
16
|
+
scripts?: Record<string, Script>;
|
|
17
|
+
}
|
|
18
|
+
export interface Skill {
|
|
19
|
+
frontmatter: SkillFrontmatter;
|
|
20
|
+
instructions: string;
|
|
21
|
+
resources?: Resources;
|
|
22
|
+
}
|
|
23
|
+
export declare function toFunctionDeclaration(skill: Skill): FunctionDeclaration;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Type } from "../tools/schema.js";
|
|
2
|
+
export function toFunctionDeclaration(skill) {
|
|
3
|
+
return {
|
|
4
|
+
name: `${skill.frontmatter.name}_skill`,
|
|
5
|
+
description: skill.frontmatter.description,
|
|
6
|
+
parameters: {
|
|
7
|
+
type: Type.OBJECT,
|
|
8
|
+
properties: {},
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=skill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skill.js","sourceRoot":"","sources":["../../src/skills/skill.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AA2B1C,MAAM,UAAU,qBAAqB,CAAC,KAAY;IAChD,OAAO;QACL,IAAI,EAAE,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,QAAQ;QACvC,WAAW,EAAE,KAAK,CAAC,WAAW,CAAC,WAAW;QAC1C,UAAU,EAAE;YACV,IAAI,EAAE,IAAI,CAAC,MAAM;YACjB,UAAU,EAAE,EAAE;SACf;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { FunctionalTool } from "../functional_tool.js";
|
|
2
|
+
import { Type } from "../schema.js";
|
|
3
|
+
import * as fs from "node:fs/promises";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
export const FIND_TOOL = new FunctionalTool({
|
|
6
|
+
name: "find",
|
|
7
|
+
description: "Finds files matching a pattern.",
|
|
8
|
+
params: {
|
|
9
|
+
type: Type.OBJECT,
|
|
10
|
+
properties: {
|
|
11
|
+
pattern: {
|
|
12
|
+
type: Type.STRING,
|
|
13
|
+
description: "The regular expression pattern to match against file names.",
|
|
14
|
+
},
|
|
15
|
+
path: {
|
|
16
|
+
type: Type.STRING,
|
|
17
|
+
description: "The path to search in. Defaults to '.' if not specified.",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
required: ["pattern"],
|
|
21
|
+
},
|
|
22
|
+
output: {
|
|
23
|
+
type: Type.OBJECT,
|
|
24
|
+
properties: {
|
|
25
|
+
files: {
|
|
26
|
+
type: Type.ARRAY,
|
|
27
|
+
items: {
|
|
28
|
+
type: Type.STRING,
|
|
29
|
+
},
|
|
30
|
+
description: "List of matching file paths",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
execute: async (input) => {
|
|
35
|
+
const typedInput = input;
|
|
36
|
+
const patternStr = typedInput.pattern;
|
|
37
|
+
const searchPath = typedInput.path || ".";
|
|
38
|
+
const resolvedPath = path.resolve(searchPath);
|
|
39
|
+
const cwd = process.cwd();
|
|
40
|
+
if (!resolvedPath.startsWith(cwd)) {
|
|
41
|
+
throw new Error(`Access denied: Path ${resolvedPath} is outside the project directory.`);
|
|
42
|
+
}
|
|
43
|
+
const regex = new RegExp(patternStr);
|
|
44
|
+
const files = [];
|
|
45
|
+
async function searchDir(dir) {
|
|
46
|
+
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
47
|
+
for (const entry of entries) {
|
|
48
|
+
const fullPath = path.join(dir, entry.name);
|
|
49
|
+
// Match against the file/directory name
|
|
50
|
+
if (regex.test(entry.name)) {
|
|
51
|
+
files.push(path.relative(cwd, fullPath));
|
|
52
|
+
}
|
|
53
|
+
if (entry.isDirectory()) {
|
|
54
|
+
if (entry.name === ".git" || entry.name === "node_modules") {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
await searchDir(fullPath);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const stats = await fs.stat(resolvedPath);
|
|
62
|
+
if (stats.isDirectory()) {
|
|
63
|
+
await searchDir(resolvedPath);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
throw new Error(`Path ${resolvedPath} is not a directory.`);
|
|
67
|
+
}
|
|
68
|
+
return { files };
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
//# sourceMappingURL=find.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find.js","sourceRoot":"","sources":["../../../src/tools/build_in/find.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAe,IAAI,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,cAAc,CAAC;IAC1C,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,iCAAiC;IAC9C,MAAM,EAAE;QACN,IAAI,EAAE,IAAI,CAAC,MAAM;QACjB,UAAU,EAAE;YACV,OAAO,EAAE;gBACP,IAAI,EAAE,IAAI,CAAC,MAAM;gBACjB,WAAW,EACT,6DAA6D;aAChE;YACD,IAAI,EAAE;gBACJ,IAAI,EAAE,IAAI,CAAC,MAAM;gBACjB,WAAW,EAAE,0DAA0D;aACxE;SACF;QACD,QAAQ,EAAE,CAAC,SAAS,CAAC;KACZ;IACX,MAAM,EAAE;QACN,IAAI,EAAE,IAAI,CAAC,MAAM;QACjB,UAAU,EAAE;YACV,KAAK,EAAE;gBACL,IAAI,EAAE,IAAI,CAAC,KAAK;gBAChB,KAAK,EAAE;oBACL,IAAI,EAAE,IAAI,CAAC,MAAM;iBAClB;gBACD,WAAW,EAAE,6BAA6B;aAC3C;SACF;KACQ;IACX,OAAO,EAAE,KAAK,EAAE,KAAc,EAAE,EAAE;QAChC,MAAM,UAAU,GAAG,KAA2C,CAAC;QAC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AE,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC1C,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;YACxB,MAAM,SAAS,CAAC,YAAY,CAAC,CAAC;QAChC,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,QAAQ,YAAY,sBAAsB,CAAC,CAAC;QAC9D,CAAC;QAED,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { FunctionalTool } from "../functional_tool.js";
|
|
2
|
+
import { Type } from "../schema.js";
|
|
3
|
+
import * as fs from "node:fs/promises";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
export const GREP_TOOL = new FunctionalTool({
|
|
6
|
+
name: "grep",
|
|
7
|
+
description: "Searches for a regular expression pattern in files.",
|
|
8
|
+
params: {
|
|
9
|
+
type: Type.OBJECT,
|
|
10
|
+
properties: {
|
|
11
|
+
pattern: {
|
|
12
|
+
type: Type.STRING,
|
|
13
|
+
description: "The regular expression pattern to search for.",
|
|
14
|
+
},
|
|
15
|
+
path: {
|
|
16
|
+
type: Type.STRING,
|
|
17
|
+
description: "The path to search in. Defaults to '.' if not specified.",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
required: ["pattern"],
|
|
21
|
+
},
|
|
22
|
+
output: {
|
|
23
|
+
type: Type.OBJECT,
|
|
24
|
+
properties: {
|
|
25
|
+
matches: {
|
|
26
|
+
type: Type.ARRAY,
|
|
27
|
+
items: {
|
|
28
|
+
type: Type.OBJECT,
|
|
29
|
+
properties: {
|
|
30
|
+
file: { type: Type.STRING },
|
|
31
|
+
line: { type: Type.INTEGER },
|
|
32
|
+
content: { type: Type.STRING },
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
description: "List of matches found",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
execute: async (input) => {
|
|
40
|
+
const typedInput = input;
|
|
41
|
+
const patternStr = typedInput.pattern;
|
|
42
|
+
const searchPath = typedInput.path || ".";
|
|
43
|
+
const resolvedPath = path.resolve(searchPath);
|
|
44
|
+
const cwd = process.cwd();
|
|
45
|
+
if (!resolvedPath.startsWith(cwd)) {
|
|
46
|
+
throw new Error(`Access denied: Path ${resolvedPath} is outside the project directory.`);
|
|
47
|
+
}
|
|
48
|
+
const regex = new RegExp(patternStr);
|
|
49
|
+
const matches = [];
|
|
50
|
+
async function searchDir(dir) {
|
|
51
|
+
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
52
|
+
for (const entry of entries) {
|
|
53
|
+
const fullPath = path.join(dir, entry.name);
|
|
54
|
+
if (entry.isDirectory()) {
|
|
55
|
+
if (entry.name === ".git" || entry.name === "node_modules") {
|
|
56
|
+
continue; // Skip these by default for sanity
|
|
57
|
+
}
|
|
58
|
+
await searchDir(fullPath);
|
|
59
|
+
}
|
|
60
|
+
else if (entry.isFile()) {
|
|
61
|
+
await searchFile(fullPath);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function searchFile(filePath) {
|
|
66
|
+
try {
|
|
67
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
68
|
+
const lines = content.split("\n");
|
|
69
|
+
for (let i = 0; i < lines.length; i++) {
|
|
70
|
+
if (regex.test(lines[i])) {
|
|
71
|
+
matches.push({
|
|
72
|
+
file: path.relative(cwd, filePath),
|
|
73
|
+
line: i + 1,
|
|
74
|
+
content: lines[i],
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
// Ignore files that cannot be read as text or other errors
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Check if resolvedPath is a file or directory
|
|
84
|
+
const stats = await fs.stat(resolvedPath);
|
|
85
|
+
if (stats.isFile()) {
|
|
86
|
+
await searchFile(resolvedPath);
|
|
87
|
+
}
|
|
88
|
+
else if (stats.isDirectory()) {
|
|
89
|
+
await searchDir(resolvedPath);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
throw new Error(`Path ${resolvedPath} is neither a file nor a directory.`);
|
|
93
|
+
}
|
|
94
|
+
return { matches };
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
//# sourceMappingURL=grep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grep.js","sourceRoot":"","sources":["../../../src/tools/build_in/grep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAe,IAAI,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,cAAc,CAAC;IAC1C,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,qDAAqD;IAClE,MAAM,EAAE;QACN,IAAI,EAAE,IAAI,CAAC,MAAM;QACjB,UAAU,EAAE;YACV,OAAO,EAAE;gBACP,IAAI,EAAE,IAAI,CAAC,MAAM;gBACjB,WAAW,EAAE,+CAA+C;aAC7D;YACD,IAAI,EAAE;gBACJ,IAAI,EAAE,IAAI,CAAC,MAAM;gBACjB,WAAW,EAAE,0DAA0D;aACxE;SACF;QACD,QAAQ,EAAE,CAAC,SAAS,CAAC;KACZ;IACX,MAAM,EAAE;QACN,IAAI,EAAE,IAAI,CAAC,MAAM;QACjB,UAAU,EAAE;YACV,OAAO,EAAE;gBACP,IAAI,EAAE,IAAI,CAAC,KAAK;gBAChB,KAAK,EAAE;oBACL,IAAI,EAAE,IAAI,CAAC,MAAM;oBACjB,UAAU,EAAE;wBACV,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;wBAC3B,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,EA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CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const BUILD_IN_TOOLS: import("../functional_tool.js").FunctionalTool<import("../schema.js").Schema, import("../schema.js").Schema>[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { LIST_DIR_TOOL } from "./list_dir.js";
|
|
2
|
+
import { VIEW_FILE_TOOL } from "./view_file.js";
|
|
3
|
+
import { WRITE_FILE_TOOL } from "./write_file.js";
|
|
4
|
+
import { GREP_TOOL } from "./grep.js";
|
|
5
|
+
import { FIND_TOOL } from "./find.js";
|
|
6
|
+
export const BUILD_IN_TOOLS = [
|
|
7
|
+
LIST_DIR_TOOL,
|
|
8
|
+
VIEW_FILE_TOOL,
|
|
9
|
+
WRITE_FILE_TOOL,
|
|
10
|
+
GREP_TOOL,
|
|
11
|
+
FIND_TOOL,
|
|
12
|
+
];
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/build_in/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,aAAa;IACb,cAAc;IACd,eAAe;IACf,SAAS;IACT,SAAS;CACV,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { FunctionalTool } from "../functional_tool.js";
|
|
2
|
+
import { Type } from "../schema.js";
|
|
3
|
+
import * as fs from "node:fs/promises";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
export const LIST_DIR_TOOL = new FunctionalTool({
|
|
6
|
+
name: "list_dir",
|
|
7
|
+
description: "Lists the contents of a directory.",
|
|
8
|
+
params: {
|
|
9
|
+
type: Type.OBJECT,
|
|
10
|
+
properties: {
|
|
11
|
+
path: {
|
|
12
|
+
type: Type.STRING,
|
|
13
|
+
description: "The directory path to list. Defaults to '.' if not specified.",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
output: {
|
|
18
|
+
type: Type.OBJECT,
|
|
19
|
+
properties: {
|
|
20
|
+
files: {
|
|
21
|
+
type: Type.ARRAY,
|
|
22
|
+
items: {
|
|
23
|
+
type: Type.STRING,
|
|
24
|
+
},
|
|
25
|
+
description: "List of file and directory names",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
execute: async (input) => {
|
|
30
|
+
const typedInput = input;
|
|
31
|
+
const dirPath = typedInput.path || ".";
|
|
32
|
+
const resolvedPath = path.resolve(dirPath);
|
|
33
|
+
const cwd = process.cwd();
|
|
34
|
+
if (!resolvedPath.startsWith(cwd)) {
|
|
35
|
+
throw new Error(`Access denied: Path ${resolvedPath} is outside the project directory.`);
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const files = await fs.readdir(resolvedPath);
|
|
39
|
+
return { files };
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
throw new Error(`Failed to list directory: ${error.message}`);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=list_dir.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list_dir.js","sourceRoot":"","sources":["../../../src/tools/build_in/list_dir.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAe,IAAI,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAA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
|
+
import { FunctionalTool } from "../functional_tool.js";
|
|
2
|
+
import { Type } from "../schema.js";
|
|
3
|
+
import * as fs from "node:fs/promises";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
export const VIEW_FILE_TOOL = new FunctionalTool({
|
|
6
|
+
name: "view_file",
|
|
7
|
+
description: "Reads the content of a file.",
|
|
8
|
+
params: {
|
|
9
|
+
type: Type.OBJECT,
|
|
10
|
+
properties: {
|
|
11
|
+
path: {
|
|
12
|
+
type: Type.STRING,
|
|
13
|
+
description: "The path to the file to read.",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
required: ["path"],
|
|
17
|
+
},
|
|
18
|
+
output: {
|
|
19
|
+
type: Type.OBJECT,
|
|
20
|
+
properties: {
|
|
21
|
+
content: {
|
|
22
|
+
type: Type.STRING,
|
|
23
|
+
description: "The content of the file",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
execute: async (input) => {
|
|
28
|
+
const typedInput = input;
|
|
29
|
+
const filePath = typedInput.path;
|
|
30
|
+
const resolvedPath = path.resolve(filePath);
|
|
31
|
+
const cwd = process.cwd();
|
|
32
|
+
if (!resolvedPath.startsWith(cwd)) {
|
|
33
|
+
throw new Error(`Access denied: Path ${resolvedPath} is outside the project directory.`);
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const content = await fs.readFile(resolvedPath, "utf-8");
|
|
37
|
+
return { content };
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw new Error(`Failed to read file: ${error.message}`);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=view_file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view_file.js","sourceRoot":"","sources":["../../../src/tools/build_in/view_file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAe,IAAI,EA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AAC,CAAC;QAC3D,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { FunctionalTool } from "../functional_tool.js";
|
|
2
|
+
import { Type } from "../schema.js";
|
|
3
|
+
import * as fs from "node:fs/promises";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
export const WRITE_FILE_TOOL = new FunctionalTool({
|
|
6
|
+
name: "write_file",
|
|
7
|
+
description: "Writes content to a file.",
|
|
8
|
+
params: {
|
|
9
|
+
type: Type.OBJECT,
|
|
10
|
+
properties: {
|
|
11
|
+
path: {
|
|
12
|
+
type: Type.STRING,
|
|
13
|
+
description: "The path to the file to write.",
|
|
14
|
+
},
|
|
15
|
+
content: {
|
|
16
|
+
type: Type.STRING,
|
|
17
|
+
description: "The content to write to the file.",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
required: ["path", "content"],
|
|
21
|
+
},
|
|
22
|
+
output: {
|
|
23
|
+
type: Type.OBJECT,
|
|
24
|
+
properties: {
|
|
25
|
+
success: {
|
|
26
|
+
type: Type.BOOLEAN,
|
|
27
|
+
description: "Whether the operation was successful",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
execute: async (input) => {
|
|
32
|
+
const typedInput = input;
|
|
33
|
+
const filePath = typedInput.path;
|
|
34
|
+
const content = typedInput.content;
|
|
35
|
+
const resolvedPath = path.resolve(filePath);
|
|
36
|
+
const cwd = process.cwd();
|
|
37
|
+
if (!resolvedPath.startsWith(cwd)) {
|
|
38
|
+
throw new Error(`Access denied: Path ${resolvedPath} is outside the project directory.`);
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
await fs.mkdir(path.dirname(resolvedPath), { recursive: true });
|
|
42
|
+
await fs.writeFile(resolvedPath, content, "utf-8");
|
|
43
|
+
return { success: true };
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
throw new Error(`Failed to write file: ${error.message}`);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=write_file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write_file.js","sourceRoot":"","sources":["../../../src/tools/build_in/write_file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAe,IAAI,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,cAAc,CAAC;IAChD,IAAI,EAAE,YAAY;IAClB,WAAW,EAAE,2BAA2B;IACxC,MAAM,EAAE;QACN,IAAI,EAAE,IAAI,CAAC,MAAM;QACjB,UAAU,EAAE;YACV,IAAI,EAAE;gBACJ,IAAI,EAAE,IAAI,CAAC,MAAM;gBACjB,WAAW,EAAE,gCAAgC;aAC9C;YACD,OAAO,EAAE;gBACP,IAAI,EAAE,IAAI,CAAC,MAAM;gBACjB,WAAW,EAAE,mCAAmC;aACjD;SACF;QACD,QAAQ,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC;KACpB;IACX,MAAM,EAAE;QACN,IAAI,EAAE,IAAI,CAAC,MAAM;QACjB,UAAU,EAAE;YACV,OAAO,EAAE;gBACP,IAAI,EAAE,IAAI,CAAC,OAAO;gBAClB,WAAW,EAAE,sCAAsC;aACpD;SACF;KACQ;IACX,OAAO,EAAE,KAAK,EAAE,KAAc,EAAE,EAAE;QAChC,MAAM,UAAU,GAAG,KAA0C,CAAC;QAC9D,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC;QACjC,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;QACnC,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC5C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QAE1B,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAClC,MAAM,IAAI,KAAK,CACb,uBAAuB,YAAY,oCAAoC,CACxE,CAAC;QACJ,CAAC;QAED,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAChE,MAAM,EAAE,CAAC,SAAS,CAAC,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,yBAAyB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5D,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Tool, FunctionDeclaration, ToolInputSchema, ToolOutputSchema, ToolInput, ToolOutput } from "./tool.js";
|
|
2
|
+
export interface FunctionalToolParams<TInputParameters extends ToolInputSchema = ToolInputSchema, TOutputParameters extends ToolOutputSchema = ToolOutputSchema> {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
params: TInputParameters;
|
|
6
|
+
output: TOutputParameters;
|
|
7
|
+
execute: (input: ToolInput<TInputParameters>) => Promise<ToolOutput<TOutputParameters>> | ToolOutput<TOutputParameters>;
|
|
8
|
+
}
|
|
9
|
+
export declare class FunctionalTool<TInputParameters extends ToolInputSchema = ToolInputSchema, TOutputParameters extends ToolOutputSchema = ToolOutputSchema> implements Tool<TInputParameters, TOutputParameters> {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly description: string;
|
|
12
|
+
readonly params: TInputParameters;
|
|
13
|
+
readonly output: TOutputParameters;
|
|
14
|
+
private readonly executeFn;
|
|
15
|
+
constructor(params: FunctionalToolParams<TInputParameters, TOutputParameters>);
|
|
16
|
+
execute(input: ToolInput<TInputParameters>): Promise<ToolOutput<TOutputParameters>>;
|
|
17
|
+
toFunctionDeclaration(): FunctionDeclaration;
|
|
18
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export class FunctionalTool {
|
|
2
|
+
constructor(params) {
|
|
3
|
+
this.name = params.name;
|
|
4
|
+
this.description = params.description;
|
|
5
|
+
this.params = params.params;
|
|
6
|
+
this.output = params.output;
|
|
7
|
+
this.executeFn = params.execute;
|
|
8
|
+
}
|
|
9
|
+
async execute(input) {
|
|
10
|
+
return this.executeFn(input);
|
|
11
|
+
}
|
|
12
|
+
toFunctionDeclaration() {
|
|
13
|
+
return {
|
|
14
|
+
name: this.name,
|
|
15
|
+
description: this.description,
|
|
16
|
+
parameters: this.params,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=functional_tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functional_tool.js","sourceRoot":"","sources":["../../src/tools/functional_tool.ts"],"names":[],"mappings":"AAuBA,MAAM,OAAO,cAAc;IAYzB,YACE,MAAiE;QAEjE,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,OAAO,CACX,KAAkC;QAElC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,qBAAqB;QACnB,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,UAAU,EAAE,IAAI,CAAC,MAA2B;SAC7C,CAAC;IACJ,CAAC;CACF"}
|