@amodalai/runtime 0.3.47 → 0.3.49
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/src/session/session-builder.js +30 -4
- package/dist/src/session/session-builder.js.map +1 -1
- package/dist/src/tools/custom-tool-adapter.d.ts +1 -0
- package/dist/src/tools/custom-tool-adapter.js +1 -0
- package/dist/src/tools/custom-tool-adapter.js.map +1 -1
- package/dist/src/tools/fs/http.d.ts +37 -0
- package/dist/src/tools/fs/http.js +88 -0
- package/dist/src/tools/fs/http.js.map +1 -0
- package/dist/src/tools/fs/index.d.ts +35 -0
- package/dist/src/tools/fs/index.js +17 -0
- package/dist/src/tools/fs/index.js.map +1 -0
- package/dist/src/tools/fs/local.d.ts +19 -0
- package/dist/src/tools/fs/local.js +124 -0
- package/dist/src/tools/fs/local.js.map +1 -0
- package/dist/src/tools/http-file-tools.d.ts +13 -0
- package/dist/src/tools/http-file-tools.js +146 -0
- package/dist/src/tools/http-file-tools.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Amodal Labs, Inc.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* HTTP-backed file tools — same tool names and schemas as the local file-tools,
|
|
8
|
+
* but reads/writes go through a remote runtime's workspace API via HttpFsBackend.
|
|
9
|
+
*
|
|
10
|
+
* Used when the admin agent runs on a different machine than the main agent
|
|
11
|
+
* (Cloud mode). Set WORKSPACE_API_URL to activate.
|
|
12
|
+
*/
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
export function registerHttpFileTools(registry, opts) {
|
|
15
|
+
const { fs, logger } = opts;
|
|
16
|
+
registry.register('read_repo_file', {
|
|
17
|
+
description: 'Read a file from the agent repository.',
|
|
18
|
+
parameters: z.object({
|
|
19
|
+
path: z.string().describe('Relative path to the file within the repo'),
|
|
20
|
+
offset: z.number().optional().describe('Line offset to start reading from'),
|
|
21
|
+
limit: z.number().optional().describe('Max number of lines to return'),
|
|
22
|
+
}),
|
|
23
|
+
readOnly: true,
|
|
24
|
+
metadata: { category: 'system' },
|
|
25
|
+
async execute(params) {
|
|
26
|
+
try {
|
|
27
|
+
logger.debug('file_tool_call', { tool: 'read_repo_file', path: params.path });
|
|
28
|
+
let content = await fs.readRepoFile(params.path);
|
|
29
|
+
if (params.offset !== undefined || params.limit !== undefined) {
|
|
30
|
+
const lines = content.split('\n');
|
|
31
|
+
const start = params.offset ?? 0;
|
|
32
|
+
const end = params.limit !== undefined ? start + params.limit : lines.length;
|
|
33
|
+
content = lines.slice(start, end).join('\n');
|
|
34
|
+
}
|
|
35
|
+
return content;
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
return { error: err instanceof Error ? err.message : String(err) };
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
registry.register('write_repo_file', {
|
|
43
|
+
description: 'Write content to a file in the agent repository. Creates parent directories as needed.',
|
|
44
|
+
parameters: z.object({
|
|
45
|
+
path: z.string().describe('Relative path to the file within the repo'),
|
|
46
|
+
content: z.string().describe('The content to write to the file'),
|
|
47
|
+
}),
|
|
48
|
+
readOnly: false,
|
|
49
|
+
metadata: { category: 'system' },
|
|
50
|
+
async execute(params) {
|
|
51
|
+
try {
|
|
52
|
+
logger.debug('file_tool_call', { tool: 'write_repo_file', path: params.path });
|
|
53
|
+
await fs.writeRepoFile(params.path, params.content);
|
|
54
|
+
return { ok: true, path: params.path };
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
return { error: err instanceof Error ? err.message : String(err) };
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
registry.register('edit_repo_file', {
|
|
62
|
+
description: 'Edit a file by replacing a specific string. Use for targeted changes.',
|
|
63
|
+
parameters: z.object({
|
|
64
|
+
path: z.string().describe('Relative path to the file'),
|
|
65
|
+
old_string: z.string().describe('The exact text to find'),
|
|
66
|
+
new_string: z.string().describe('The replacement text'),
|
|
67
|
+
}),
|
|
68
|
+
readOnly: false,
|
|
69
|
+
metadata: { category: 'system' },
|
|
70
|
+
async execute(params) {
|
|
71
|
+
try {
|
|
72
|
+
logger.debug('file_tool_call', { tool: 'edit_repo_file', path: params.path });
|
|
73
|
+
const content = await fs.readRepoFile(params.path);
|
|
74
|
+
if (!content.includes(params.old_string)) {
|
|
75
|
+
return { error: `String not found in ${params.path}` };
|
|
76
|
+
}
|
|
77
|
+
const updated = content.replace(params.old_string, params.new_string);
|
|
78
|
+
await fs.writeRepoFile(params.path, updated);
|
|
79
|
+
return { ok: true, path: params.path };
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
return { error: err instanceof Error ? err.message : String(err) };
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
registry.register('delete_repo_file', {
|
|
87
|
+
description: 'Delete a file from the agent repository.',
|
|
88
|
+
parameters: z.object({
|
|
89
|
+
path: z.string().describe('Relative path to the file'),
|
|
90
|
+
}),
|
|
91
|
+
readOnly: false,
|
|
92
|
+
metadata: { category: 'system' },
|
|
93
|
+
async execute(params) {
|
|
94
|
+
try {
|
|
95
|
+
logger.debug('file_tool_call', { tool: 'delete_repo_file', path: params.path });
|
|
96
|
+
await fs.deleteRepoFile(params.path);
|
|
97
|
+
return { ok: true, path: params.path };
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
return { error: err instanceof Error ? err.message : String(err) };
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
registry.register('list_repo_files', {
|
|
105
|
+
description: 'List files and directories at a path in the agent repository.',
|
|
106
|
+
parameters: z.object({
|
|
107
|
+
dir: z.string().optional().describe('Directory to list (default: repo root)'),
|
|
108
|
+
}),
|
|
109
|
+
readOnly: true,
|
|
110
|
+
metadata: { category: 'system' },
|
|
111
|
+
async execute(params) {
|
|
112
|
+
try {
|
|
113
|
+
logger.debug('file_tool_call', { tool: 'list_repo_files', dir: params.dir });
|
|
114
|
+
const listing = await fs.listRepoFiles(params.dir ?? '.');
|
|
115
|
+
const entries = [
|
|
116
|
+
...listing.directories.map((d) => `${d}/`),
|
|
117
|
+
...listing.files,
|
|
118
|
+
];
|
|
119
|
+
return entries.join('\n') || '(empty directory)';
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
return { error: err instanceof Error ? err.message : String(err) };
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
registry.register('read_many_repo_files', {
|
|
127
|
+
description: 'Read multiple files at once. Missing files are silently skipped.',
|
|
128
|
+
parameters: z.object({
|
|
129
|
+
paths: z.array(z.string()).describe('Array of relative file paths'),
|
|
130
|
+
}),
|
|
131
|
+
readOnly: true,
|
|
132
|
+
metadata: { category: 'system' },
|
|
133
|
+
async execute(params) {
|
|
134
|
+
try {
|
|
135
|
+
logger.debug('file_tool_call', { tool: 'read_many_repo_files', count: params.paths.length });
|
|
136
|
+
const files = await fs.readManyRepoFiles(params.paths);
|
|
137
|
+
return files.map((f) => `--- ${f.path} ---\n${f.content}`).join('\n\n');
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
return { error: err instanceof Error ? err.message : String(err) };
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
logger.debug('http_file_tools_registered', { tools: 6 });
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=http-file-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-file-tools.js","sourceRoot":"","sources":["../../../src/tools/http-file-tools.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;GAMG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAUtB,MAAM,UAAU,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