tarsk 0.2.5 → 0.3.0

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.
Files changed (119) hide show
  1. package/README.md +1 -7
  2. package/dist/index.d.ts +3 -0
  3. package/dist/index.js +92 -32
  4. package/dist/lib/response-builder.d.ts +50 -0
  5. package/dist/lib/response-builder.js +56 -0
  6. package/dist/lib/stream-helper.d.ts +39 -0
  7. package/dist/lib/stream-helper.js +43 -0
  8. package/dist/managers/ConversationManager.d.ts +83 -0
  9. package/dist/managers/ConversationManager.js +129 -0
  10. package/dist/managers/GitManager.d.ts +133 -0
  11. package/dist/managers/GitManager.js +330 -0
  12. package/dist/managers/MetadataManager.d.ts +139 -0
  13. package/dist/managers/MetadataManager.js +309 -0
  14. package/dist/managers/ModelManager.d.ts +57 -0
  15. package/dist/managers/ModelManager.js +129 -0
  16. package/dist/managers/NeovateExecutor.d.ts +40 -0
  17. package/dist/managers/NeovateExecutor.js +138 -0
  18. package/dist/managers/ProjectManager.d.ts +162 -0
  19. package/dist/managers/ProjectManager.js +353 -0
  20. package/dist/managers/ThreadManager.d.ts +181 -0
  21. package/dist/managers/ThreadManager.js +325 -0
  22. package/dist/managers/conversation-manager.d.ts +83 -0
  23. package/dist/managers/conversation-manager.js +129 -0
  24. package/dist/managers/git-manager.d.ts +133 -0
  25. package/dist/managers/git-manager.js +330 -0
  26. package/dist/managers/metadata-manager.d.ts +139 -0
  27. package/dist/managers/metadata-manager.js +305 -0
  28. package/dist/managers/model-manager.d.ts +59 -0
  29. package/dist/managers/model-manager.js +144 -0
  30. package/dist/managers/neovate-executor.d.ts +43 -0
  31. package/dist/managers/neovate-executor.js +205 -0
  32. package/dist/managers/processing-state-manager.d.ts +40 -0
  33. package/dist/managers/processing-state-manager.js +27 -0
  34. package/dist/managers/project-manager.d.ts +199 -0
  35. package/dist/managers/project-manager.js +465 -0
  36. package/dist/managers/thread-manager.d.ts +193 -0
  37. package/dist/managers/thread-manager.js +368 -0
  38. package/dist/model-info-aihubmix.d.ts +25 -0
  39. package/dist/model-info-aihubmix.js +117 -0
  40. package/dist/model-info-openai.d.ts +17 -0
  41. package/dist/model-info-openai.js +59 -0
  42. package/dist/model-info-openrouter.d.ts +25 -0
  43. package/dist/model-info-openrouter.js +101 -0
  44. package/dist/model-info.d.ts +37 -0
  45. package/dist/model-info.js +39 -0
  46. package/dist/provider-data.d.ts +101 -0
  47. package/dist/provider-data.js +471 -0
  48. package/dist/provider.d.ts +10 -0
  49. package/dist/provider.js +192 -0
  50. package/dist/public/android-chrome-192x192.png +0 -0
  51. package/dist/public/android-chrome-512x512.png +0 -0
  52. package/dist/public/apple-touch-icon.png +0 -0
  53. package/dist/public/assets/index-B443aj9k.js +8506 -0
  54. package/dist/public/assets/index-CjXGVbI7.css +1 -0
  55. package/dist/public/assets/index-DJC-p914.js +8506 -0
  56. package/dist/public/favicon-16x16.png +0 -0
  57. package/dist/public/favicon-32x32.png +0 -0
  58. package/dist/public/favicon.ico +0 -0
  59. package/dist/public/index.html +28 -0
  60. package/dist/public/manifest.json +82 -0
  61. package/dist/public/placeholder-logo.svg +1 -0
  62. package/dist/public/placeholder.svg +1 -0
  63. package/dist/public/snpro.woff2 +0 -0
  64. package/dist/public/tarsk-color.svg +12 -0
  65. package/dist/public/tarsk.png +0 -0
  66. package/dist/public/tarsk.svg +12 -0
  67. package/dist/public/zalando-sans.woff2 +0 -0
  68. package/dist/routes/chat-old.d.ts +21 -0
  69. package/dist/routes/chat-old.js +251 -0
  70. package/dist/routes/chat.d.ts +21 -0
  71. package/dist/routes/chat.js +217 -0
  72. package/dist/routes/git.d.ts +4 -0
  73. package/dist/routes/git.js +668 -0
  74. package/dist/routes/models.d.ts +18 -0
  75. package/dist/routes/models.js +128 -0
  76. package/dist/routes/projects-old.d.ts +20 -0
  77. package/dist/routes/projects-old.js +297 -0
  78. package/dist/routes/projects.d.ts +20 -0
  79. package/dist/routes/projects.js +365 -0
  80. package/dist/routes/providers.d.ts +15 -0
  81. package/dist/routes/providers.js +130 -0
  82. package/dist/routes/threads-old.d.ts +14 -0
  83. package/dist/routes/threads-old.js +393 -0
  84. package/dist/routes/threads.d.ts +14 -0
  85. package/dist/routes/threads.js +352 -0
  86. package/dist/types/models.d.ts +315 -0
  87. package/dist/types/models.js +11 -0
  88. package/dist/utils/env-manager.d.ts +3 -0
  89. package/dist/utils/env-manager.js +60 -0
  90. package/dist/utils/open-router-models.d.ts +45 -0
  91. package/dist/utils/open-router-models.js +103 -0
  92. package/dist/utils/openai-models.d.ts +63 -0
  93. package/dist/utils/openai-models.js +152 -0
  94. package/dist/utils/openai-pricing-scraper.d.ts +17 -0
  95. package/dist/utils/openai-pricing-scraper.js +185 -0
  96. package/dist/utils/validation.d.ts +10 -0
  97. package/dist/utils/validation.js +20 -0
  98. package/dist/utils.d.ts +10 -0
  99. package/dist/utils.js +12 -0
  100. package/package.json +36 -22
  101. package/LICENSE.md +0 -7
  102. package/dist/agent/agent.js +0 -131
  103. package/dist/agent/interfaces.js +0 -1
  104. package/dist/api/encryption.js +0 -41
  105. package/dist/api/models.js +0 -169
  106. package/dist/api/prompt.js +0 -12
  107. package/dist/api/settings.js +0 -43
  108. package/dist/api/test.js +0 -29
  109. package/dist/api/tools.js +0 -287
  110. package/dist/api/utils.js +0 -18
  111. package/dist/interfaces/meta.js +0 -1
  112. package/dist/interfaces/model.js +0 -1
  113. package/dist/interfaces/settings.js +0 -1
  114. package/dist/log/log.js +0 -33
  115. package/dist/prompt.js +0 -49
  116. package/dist/tools.js +0 -84
  117. package/dist/utils/files.js +0 -14
  118. package/dist/utils/json-file.js +0 -28
  119. package/dist/utils/strip-markdown.js +0 -5
package/dist/api/tools.js DELETED
@@ -1,287 +0,0 @@
1
- import { existsSync, mkdirSync, promises, readdirSync, writeFileSync, } from "fs";
2
- import { extname, join } from "path";
3
- import { extensionLess, isEmpty, tarskFolder } from "./utils.js";
4
- import { logError, logWrite } from "../log/log.js";
5
- import tsBlankSpace from "ts-blank-space";
6
- import { loadTools } from "../tools.js";
7
- import { callFunction } from "../agent/agent.js";
8
- import { readAsJSONIfExists } from "../utils/files.js";
9
- import ts, { SyntaxKind } from "typescript";
10
- import { createTest } from "./test.js";
11
- export async function api_run_tool(c) {
12
- const tool = await c.req.json();
13
- logWrite({ type: "api_run_tool", args: { toolName: tool.name } });
14
- if (!tool.code) {
15
- return c.json({ error: "Tool not found" }, 404);
16
- }
17
- try {
18
- const toolToRun = await getTool(tool.name);
19
- const tools = await loadTools(toolJavascriptFilenames(true));
20
- const d = tools.find((t) => t.name == toolToRun.name + '.test');
21
- const functionName = 'test';
22
- if (!d) {
23
- throw new Error(`${tool.name} not found`);
24
- }
25
- if (!d.functionNames.includes(functionName)) {
26
- throw new Error(`${tool.name} function "${functionName}" not found (reload?)`);
27
- }
28
- const output = await callFunction(d.functionMap[functionName]);
29
- return c.json({ output, js: 'test();' });
30
- }
31
- catch (e) {
32
- return c.json({ output: `${e}`, js: '' });
33
- }
34
- }
35
- export async function api_save_tool(c) {
36
- const tool = await c.req.json();
37
- if (tool.name == "") {
38
- tool.name = tool.title;
39
- }
40
- const title = tool.title;
41
- const code = tool.code;
42
- let test = tool.test ?? "";
43
- const name = tool.name.toLowerCase().replaceAll(" ", "_");
44
- if (!title || !code || !name) {
45
- return c.json({ error: "Title and code are required" }, 400);
46
- }
47
- const meta = { title, name };
48
- const jsCode = tsBlankSpace(tool.code ?? "", (e) => {
49
- logError({ type: "failed_ts_to_js_code", args: e });
50
- });
51
- const testCode = tsBlankSpace(tool.test ?? "", (e) => {
52
- logError({ type: "failed_ts_to_js_test", args: e });
53
- });
54
- const filename = name.replace(/\s+/g, "_").toLowerCase();
55
- const srcPath = join(toolsSrcFolder(), `${filename}.ts`);
56
- const jsCodePath = join(toolsJSFolder(), `${filename}.js`);
57
- const defPath = join(toolsJSFolder(), `${filename}.js.definition.json`);
58
- const testPath = join(toolsSrcFolder(), `${filename}.test.ts`);
59
- const jsTestPath = join(toolsJSFolder(), `${filename}.test.js`);
60
- const metaPath = join(toolsSrcFolder(), `${filename}.json`);
61
- const currentMeta = readAsJSONIfExists(metaPath);
62
- if (currentMeta) {
63
- meta.revision = (currentMeta.revision ?? 1) + 1;
64
- }
65
- const missingData = {
66
- missingParameters: [],
67
- missingFunctions: []
68
- };
69
- const definition = await inspectCode(srcPath, missingData);
70
- logWrite({ type: "api_save_tool_check_test", args: { test } });
71
- if (isEmpty(test)) {
72
- test = await createTest(definition, `${filename}.js`, code);
73
- }
74
- writeFileSync(srcPath, code, "utf-8");
75
- writeFileSync(metaPath, JSON.stringify(meta, null, 2), "utf-8");
76
- writeFileSync(defPath, JSON.stringify(definition, null, 2), "utf-8");
77
- writeFileSync(testPath, test, "utf-8");
78
- writeFileSync(jsCodePath, jsCode, "utf-8");
79
- writeFileSync(jsTestPath, testCode, "utf-8");
80
- logWrite({ type: "api_save_tool", args: { test: testPath, code: srcPath, meta: metaPath } });
81
- return c.json({
82
- message: `Tool saved successfully (${jsCodePath})`,
83
- missingParameters: missingData.missingParameters,
84
- missingFunctions: missingData.missingFunctions,
85
- });
86
- }
87
- export async function api_get_tool(c) {
88
- const toolName = c.req.param("tool");
89
- const tool = await getTool(toolName);
90
- console.log(`api_get_tool ${toolName}`);
91
- return c.json(tool);
92
- }
93
- export async function api_delete_tool(c) {
94
- const toolName = c.req.param("tool");
95
- await deleteTool(toolName);
96
- return c.json({});
97
- }
98
- async function deleteTool(name) {
99
- console.log(`Deleting tool ${name}`);
100
- const toolsFolder = toolsSrcFolder();
101
- await promises.rm(join(toolsFolder, `${name}.ts`));
102
- await promises.rm(join(toolsFolder, `${name}.test.ts`));
103
- await promises.rm(join(toolsFolder, `${name}.json`));
104
- await promises.rm(join(toolsJSFolder(), `${name}.js`));
105
- await promises.rm(join(toolsJSFolder(), `${name}.test.js`));
106
- }
107
- export async function api_get_tools(c) {
108
- const fileList = await toolFilenames();
109
- const result = [];
110
- for (const file of fileList) {
111
- const tool = await getTool(file);
112
- tool.code = undefined;
113
- result.push(tool);
114
- }
115
- return c.json(result);
116
- }
117
- async function toolFilenames() {
118
- const toolsFolder = toolsSrcFolder();
119
- const files = await promises.readdir(toolsFolder);
120
- return files
121
- .filter((f) => extname(f) === ".ts" && !f.endsWith(".test.ts"))
122
- .map((f) => extensionLess(f));
123
- }
124
- function toolsJSFolder() {
125
- const folderPath = join(tarskFolder(), ".tools");
126
- if (!existsSync(folderPath)) {
127
- mkdirSync(folderPath, { recursive: true });
128
- }
129
- return folderPath;
130
- }
131
- export function toolJavascriptFilenames(includeTests) {
132
- const files = readdirSync(toolsJSFolder());
133
- if (includeTests) {
134
- return files
135
- .filter((f) => extname(f) === ".js")
136
- .map((f) => join(tarskFolder(), ".tools", f));
137
- }
138
- else {
139
- return files
140
- .filter((f) => extname(f) === ".js" && !f.endsWith(".test.js"))
141
- .map((f) => join(tarskFolder(), ".tools", f));
142
- }
143
- }
144
- export async function getTool(name) {
145
- const toolsFolder = toolsSrcFolder();
146
- const code = await readOrEmpty(join(toolsFolder, `${name}.ts`));
147
- const test = await readOrEmpty(join(toolsFolder, `${name}.test.ts`));
148
- const meta = await readOrEmpty(join(toolsFolder, `${name}.json`));
149
- try {
150
- const json = meta == '' ? { tile: '', name: '' } : JSON.parse(meta);
151
- return { code, title: json.title, name: json.name, test };
152
- }
153
- catch (e) {
154
- console.error(`Failed to parse ${name}.json`, e);
155
- return { code, title: "", name, test };
156
- }
157
- }
158
- function toolsSrcFolder() {
159
- const folderPath = join(tarskFolder(), "tools");
160
- if (!existsSync(folderPath)) {
161
- mkdirSync(folderPath, { recursive: true });
162
- }
163
- return folderPath;
164
- }
165
- async function readOrEmpty(filename) {
166
- if (!existsSync(filename)) {
167
- return "";
168
- }
169
- return await promises.readFile(filename, "utf-8");
170
- }
171
- export async function inspectCode(filename, missingData) {
172
- const code = await readOrEmpty(filename);
173
- const tools = [];
174
- const sourceFile = ts.createSourceFile('temp.ts', code, ts.ScriptTarget.Latest, true);
175
- function visit(node) {
176
- if ((ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node)) && node.name) {
177
- const parsed = parseJSDoc(node);
178
- console.log("Parsed function", parsed);
179
- const properties = {};
180
- const required = [];
181
- node.parameters.forEach(param => {
182
- const isOptional = !!param.questionToken || !!param.initializer;
183
- if (!isOptional) {
184
- required.push(param.name.getText());
185
- }
186
- let type = typeName(param.type?.getText());
187
- if (param.type?.kind == SyntaxKind.TypeReference) {
188
- type = 'object';
189
- }
190
- parsed.params;
191
- const hasDescription = Object.keys(parsed.params).includes(param.name.getText());
192
- const description = hasDescription ? parsed.params[param.name.getText()] : '';
193
- if (!hasDescription) {
194
- missingData.missingParameters.push(param.name.escapedText);
195
- }
196
- properties[param.name.getText()] = {
197
- type,
198
- description
199
- };
200
- if (type == 'array') {
201
- properties[param.name.getText()].items = {
202
- type: arrayType(param.type?.getText()),
203
- };
204
- }
205
- });
206
- const functionDescription = parsed.description;
207
- if (isEmpty(functionDescription)) {
208
- missingData.missingFunctions.push(node.name.getText());
209
- }
210
- tools.push({
211
- type: 'function',
212
- function: {
213
- name: node.name?.text ?? '',
214
- description: functionDescription,
215
- parameters: {
216
- type: 'object',
217
- properties,
218
- required,
219
- }
220
- }
221
- });
222
- }
223
- ts.forEachChild(node, visit);
224
- }
225
- visit(sourceFile);
226
- return tools;
227
- }
228
- function parseJSDoc(node) {
229
- const functionName = node.name?.getText();
230
- const jsDoc = ts.getJSDocCommentsAndTags(node);
231
- const parsed = {
232
- functionName,
233
- description: "",
234
- params: {},
235
- };
236
- let info = '';
237
- for (const doc of jsDoc) {
238
- if (ts.isJSDoc(doc)) {
239
- if (doc.comment) {
240
- parsed.description = doc.comment.toString();
241
- }
242
- if (doc.tags) {
243
- for (const tag of doc.tags) {
244
- info += ' ' + tag.comment;
245
- if (tag.kind == SyntaxKind.JSDocTag && tag.comment) {
246
- let txt = tag.comment ? tag.comment.toString() : "";
247
- const lines = txt.split(' ');
248
- const paramName = lines[0];
249
- if (txt.startsWith(paramName)) {
250
- txt = txt.substring(paramName.length).trim();
251
- }
252
- if (txt.startsWith('-')) {
253
- txt = txt.substring(1).trim();
254
- }
255
- parsed.params[paramName] = txt;
256
- }
257
- if (tag.kind == SyntaxKind.JSDocFunctionType ||
258
- tag.kind == SyntaxKind.JSDocParameterTag) {
259
- let txt = tag.comment ? tag.comment.toString() : "";
260
- let paramName = tag.name?.escapedText;
261
- if (txt.startsWith(paramName)) {
262
- txt = txt.substring(paramName.length).trim();
263
- }
264
- if (txt.startsWith('-')) {
265
- txt = txt.substring(1).trim();
266
- }
267
- parsed.params[paramName] = txt;
268
- }
269
- }
270
- }
271
- }
272
- }
273
- return parsed;
274
- }
275
- function typeName(name) {
276
- if (!name)
277
- return 'any';
278
- if (name.endsWith('[]')) {
279
- return 'array';
280
- }
281
- return name;
282
- }
283
- function arrayType(name) {
284
- if (!name)
285
- return 'any';
286
- return name.replace('[]', '');
287
- }
package/dist/api/utils.js DELETED
@@ -1,18 +0,0 @@
1
- import { HTTPException } from "hono/http-exception";
2
- import { homedir } from "os";
3
- import { extname, join } from "path";
4
- export function extensionLess(filename) {
5
- return filename.substring(0, filename.length - extname(filename).length);
6
- }
7
- export function tarskFolder() {
8
- return join(homedir(), ".tarsk");
9
- }
10
- export function httpValidationErrror(message) {
11
- throw new HTTPException(406, { message });
12
- }
13
- export function isEmpty(v) {
14
- if (v == undefined || v == null || v == "" || v.trim() == "") {
15
- return true;
16
- }
17
- return false;
18
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
package/dist/log/log.js DELETED
@@ -1,33 +0,0 @@
1
- let logLevel = "debug";
2
- export function logWrite(l, additionalMessage) {
3
- if (logLevel == "none")
4
- return;
5
- let msg = l.type;
6
- if (l.message) {
7
- msg += `: ${l.message}`;
8
- }
9
- if (l.args) {
10
- msg += ` ${JSON.stringify(l.args)}`;
11
- }
12
- l.id = id();
13
- console.log(msg);
14
- }
15
- export function logStart(l, additionalMessage) {
16
- if (logLevel === "none")
17
- return;
18
- console.time(l.type);
19
- logWrite(l, additionalMessage);
20
- }
21
- export function logEnd(label) {
22
- if (logLevel === "none")
23
- return;
24
- console.timeEnd(label);
25
- }
26
- export function logError(l) {
27
- if (logLevel === "none")
28
- return;
29
- console.error(l);
30
- }
31
- function id() {
32
- return Math.random().toString().replace(".", "");
33
- }
package/dist/prompt.js DELETED
@@ -1,49 +0,0 @@
1
- import { completion } from "./agent/agent.js";
2
- import { loadTools } from "./tools.js";
3
- import { defaultModel, getSettings } from "./api/settings.js";
4
- import { toolJavascriptFilenames } from "./api/tools.js";
5
- import { isEmpty } from "./api/utils.js";
6
- import { logWrite, logEnd, logStart } from "./log/log.js";
7
- export async function prompt(content, promptOptions) {
8
- const settings = await getSettings();
9
- let apiKey = settings.tarskApiKey;
10
- const options = {
11
- baseUrl: isEmpty(settings.apiURL) ? "https://api.tarsk.io/api/v1" : settings.apiURL,
12
- apiKey,
13
- };
14
- const messages = [];
15
- if (promptOptions?.firstMessage) {
16
- messages.push(promptOptions.firstMessage);
17
- }
18
- messages.push({ role: "user", content });
19
- const model = isEmpty(settings.defaultModel)
20
- ? defaultModel
21
- : settings.defaultModel;
22
- logWrite({ type: "prompt", args: content }, `The model is ${model}`);
23
- const filenames = toolJavascriptFilenames(false);
24
- let tools = [];
25
- if (!promptOptions?.ignoreTools) {
26
- logStart({ type: "load_tools", args: filenames });
27
- tools = await loadTools(filenames);
28
- logEnd("load_tools");
29
- }
30
- const request = { model, tools, messages };
31
- try {
32
- const response = await completion(request, options);
33
- logWrite({ type: "completion_response", args: response });
34
- logWrite({ type: "message", args: response?.choices[0].message });
35
- return response?.choices[0].message.content;
36
- }
37
- catch (e) {
38
- return friendlyError(`${e}`, settings);
39
- }
40
- }
41
- function friendlyError(e, settings) {
42
- if (e.startsWith("Error: No endpoints found that support tool use")) {
43
- return `The model "${settings.defaultModel}" does not support tool use. Please select a different model (A good default is ${defaultModel}).`;
44
- }
45
- if (e.startsWith("Error: No auth credentials found")) {
46
- return `The API key is invalid. Please check your account and get a new key.`;
47
- }
48
- return e;
49
- }
package/dist/tools.js DELETED
@@ -1,84 +0,0 @@
1
- import { logWrite, logEnd, logError, logStart } from "./log/log.js";
2
- import { getPathWithoutExtension, readAsJSONIfExists } from "./utils/files.js";
3
- export async function loadTools(modulePaths) {
4
- const tools = [];
5
- logWrite({
6
- type: "load_tools",
7
- args: modulePaths,
8
- }, `modulePaths is "${modulePaths.join(", ")}"`);
9
- for (const modulePath of modulePaths) {
10
- logWrite({ type: "getTool", args: modulePath });
11
- if (modulePath == "") {
12
- logError({ type: "getTool", args: "Empty modulePath" });
13
- continue;
14
- }
15
- else {
16
- const tool = await inspectTool(modulePath);
17
- tools.push(tool);
18
- }
19
- }
20
- return tools;
21
- }
22
- function findMetaData(modulePath) {
23
- let metaPath = (getPathWithoutExtension(modulePath) + ".json").replace('.tools', 'tools');
24
- const meta = readAsJSONIfExists(metaPath);
25
- if (meta)
26
- return meta;
27
- metaPath = metaPath.replace('.test', '');
28
- const meta2 = readAsJSONIfExists(metaPath);
29
- if (meta2)
30
- meta2.name = meta2.name + '.test';
31
- if (meta2)
32
- return meta2;
33
- }
34
- async function inspectTool(modulePath) {
35
- const result = {
36
- functionNames: [],
37
- functionMap: undefined,
38
- definition: undefined,
39
- name: undefined,
40
- path: modulePath,
41
- revision: undefined
42
- };
43
- logStart({ type: "load_tool", args: { modulePath } }, `The modulePath is "${modulePath}"`);
44
- try {
45
- const meta = findMetaData(modulePath);
46
- result.revision = meta?.revision;
47
- result.name = meta?.name;
48
- const isTest = modulePath.endsWith(".test.js");
49
- const query = isTest ? `?${Math.random()}` : `?${result.revision}`;
50
- const myModule = await import(modulePath + query);
51
- try {
52
- result.functionNames = Object.keys(myModule);
53
- result.functionMap = {};
54
- for (const func of result.functionNames) {
55
- logWrite({ type: "load_tool_function", args: { foundFunction: func } });
56
- result.functionMap[func] = myModule[func];
57
- }
58
- }
59
- catch (e) {
60
- throw new Error(`Error loading Map from ${modulePath}: ${e}`);
61
- }
62
- try {
63
- if (!isTest) {
64
- result.definition = getDefinition(modulePath);
65
- }
66
- }
67
- catch (e) {
68
- throw new Error(`Error loading the agent map from ${modulePath}: ${e}`);
69
- }
70
- return result;
71
- }
72
- catch (e) {
73
- logError({ type: "load_tool_error", args: e });
74
- throw new Error(`load_tool_error ${modulePath}: ${e}`);
75
- }
76
- finally {
77
- logEnd("load_tool");
78
- logWrite({ type: 'load_tool', args: { result } });
79
- }
80
- }
81
- function getDefinition(modulePath) {
82
- const filename = modulePath + '.definition.json';
83
- return readAsJSONIfExists(filename);
84
- }
@@ -1,14 +0,0 @@
1
- import { existsSync, readFileSync } from "fs";
2
- export function getPathWithoutExtension(path) {
3
- const lastDotIndex = path.lastIndexOf(".");
4
- if (lastDotIndex === -1) {
5
- return path;
6
- }
7
- return path.slice(0, lastDotIndex);
8
- }
9
- export function readAsJSONIfExists(path) {
10
- if (existsSync(path)) {
11
- const data = readFileSync(path, "utf-8");
12
- return JSON.parse(data);
13
- }
14
- }
@@ -1,28 +0,0 @@
1
- import { join } from "path";
2
- import { tarskFolder } from "../api/utils.js";
3
- import { existsSync, mkdir, mkdirSync, readFileSync, writeFileSync } from "fs";
4
- import { decryptString, encryptString } from "../api/encryption.js";
5
- export function getJSON(name, defaultValue) {
6
- const filename = join(tarskFolder(), name + '.json');
7
- if (!existsSync(filename)) {
8
- if (!existsSync(tarskFolder())) {
9
- mkdirSync(tarskFolder(), { recursive: true });
10
- }
11
- setJSON(name, defaultValue);
12
- return defaultValue;
13
- }
14
- else {
15
- try {
16
- const data = readFileSync(filename, 'utf-8');
17
- return JSON.parse(decryptString(data));
18
- }
19
- catch (e) {
20
- setJSON(name, defaultValue);
21
- return defaultValue;
22
- }
23
- }
24
- }
25
- export function setJSON(name, value) {
26
- const filename = join(tarskFolder(), name + '.json');
27
- writeFileSync(filename, encryptString(JSON.stringify(value)));
28
- }
@@ -1,5 +0,0 @@
1
- export function stripMarkdown(markdown) {
2
- const lines = markdown.split("\n");
3
- const strippedLines = lines.filter(line => !line.startsWith("```"));
4
- return strippedLines.join("\n").trim();
5
- }