@markusylisiurunen/tau 0.3.80 → 0.3.81
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/code_mode/command.js +4 -16
- package/dist/code_mode/command.js.map +1 -1
- package/dist/code_mode/images.js +5 -6
- package/dist/code_mode/images.js.map +1 -1
- package/dist/code_mode/index.d.ts +1 -3
- package/dist/code_mode/index.js +1 -2
- package/dist/code_mode/index.js.map +1 -1
- package/dist/code_mode/runtime.d.ts +8 -4
- package/dist/code_mode/runtime.js +52 -63
- package/dist/code_mode/runtime.js.map +1 -1
- package/dist/core/code_mode/bash.js +269 -0
- package/dist/core/code_mode/bash.js.map +1 -0
- package/dist/core/code_mode/capability.js +2 -0
- package/dist/core/code_mode/capability.js.map +1 -0
- package/dist/core/code_mode/history.js +62 -0
- package/dist/core/code_mode/history.js.map +1 -0
- package/dist/core/code_mode/mcp.js +121 -0
- package/dist/core/code_mode/mcp.js.map +1 -0
- package/dist/core/code_mode/models.js +256 -0
- package/dist/core/code_mode/models.js.map +1 -0
- package/dist/core/{tools → code_mode}/nook.js +13 -77
- package/dist/core/code_mode/nook.js.map +1 -0
- package/dist/core/code_mode/sdk.js +97 -0
- package/dist/core/code_mode/sdk.js.map +1 -0
- package/dist/core/{tools → code_mode}/web.js +31 -90
- package/dist/core/code_mode/web.js.map +1 -0
- package/dist/core/config/content_loader.js +3 -1
- package/dist/core/config/content_loader.js.map +1 -1
- package/dist/core/debug.js +1 -1
- package/dist/core/debug.js.map +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/models/openrouter.js +171 -0
- package/dist/core/models/openrouter.js.map +1 -0
- package/dist/core/{tool → models}/openrouter_decisions.js +6 -7
- package/dist/core/models/openrouter_decisions.js.map +1 -0
- package/dist/core/models/openrouter_media.js +128 -0
- package/dist/core/models/openrouter_media.js.map +1 -0
- package/dist/core/personas.js +2 -1
- package/dist/core/personas.js.map +1 -1
- package/dist/core/session/compaction.js +5 -3
- package/dist/core/session/compaction.js.map +1 -1
- package/dist/core/static/code_mode/history/documentation.md +95 -167
- package/dist/core/static/code_mode/mcp/documentation.md +144 -67
- package/dist/core/static/code_mode/nook/documentation.md +108 -169
- package/dist/core/static/code_mode/sandbox_runner.mjs +37 -20
- package/dist/core/static/code_mode/web/documentation.md +115 -213
- package/dist/core/static/tau_docs/client-tools.md +3 -3
- package/dist/core/static/tau_docs/history.md +2 -2
- package/dist/core/static/tau_docs/node-sdk.md +5 -3
- package/dist/core/static/tau_docs/nook.md +2 -2
- package/dist/core/static/tau_docs/personas.md +2 -2
- package/dist/core/static/tau_docs/security.md +3 -3
- package/dist/core/static/tau_docs/sessions.md +2 -0
- package/dist/core/static/tau_docs/subagents.md +2 -1
- package/dist/core/static/tau_docs/tools.md +36 -33
- package/dist/core/static/tau_docs/tui.md +5 -3
- package/dist/core/subagents/registry.js +2 -1
- package/dist/core/subagents/registry.js.map +1 -1
- package/dist/core/subagents/types.js +2 -1
- package/dist/core/subagents/types.js.map +1 -1
- package/dist/core/tool/image_generate.js +2 -1
- package/dist/core/tool/image_generate.js.map +1 -1
- package/dist/core/tool/media.js +1 -49
- package/dist/core/tool/media.js.map +1 -1
- package/dist/core/tool/openrouter.js +24 -156
- package/dist/core/tool/openrouter.js.map +1 -1
- package/dist/core/tool/openrouter_input.js +77 -0
- package/dist/core/tool/openrouter_input.js.map +1 -0
- package/dist/core/tool/speech_generate.js +2 -1
- package/dist/core/tool/speech_generate.js.map +1 -1
- package/dist/core/tools/bash.js +2 -1
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/bash_jobs.js +34 -5
- package/dist/core/tools/bash_jobs.js.map +1 -1
- package/dist/core/tools/catalog.js +18 -33
- package/dist/core/tools/catalog.js.map +1 -1
- package/dist/core/tools/code.js +100 -0
- package/dist/core/tools/code.js.map +1 -0
- package/dist/core/tools/code_mode.js +9 -30
- package/dist/core/tools/code_mode.js.map +1 -1
- package/dist/core/tools/code_mode_worker.js +2 -2
- package/dist/core/tools/presentation.js +2 -1
- package/dist/core/tools/presentation.js.map +1 -1
- package/dist/core/tools/tool_names.js +5 -1
- package/dist/core/tools/tool_names.js.map +1 -1
- package/dist/core/utils/gemini_transcription.js +14 -15
- package/dist/core/utils/gemini_transcription.js.map +1 -1
- package/dist/core/utils/media_validation.js +50 -0
- package/dist/core/utils/media_validation.js.map +1 -0
- package/dist/core/version.js +1 -1
- package/dist/nook/README.md +1 -1
- package/dist/sdk/code_mode.js +11 -17
- package/dist/sdk/code_mode.js.map +1 -1
- package/dist/sdk/index.d.ts +1 -1
- package/dist/sdk/index.js +1 -1
- package/dist/sdk/index.js.map +1 -1
- package/dist/tui/session_chat_controller.js +95 -55
- package/dist/tui/session_chat_controller.js.map +1 -1
- package/package.json +4 -4
- package/dist/code_mode/files.d.ts +0 -47
- package/dist/code_mode/files.js +0 -296
- package/dist/code_mode/files.js.map +0 -1
- package/dist/core/tool/openrouter_decisions.js.map +0 -1
- package/dist/core/tool/openrouter_media.js +0 -180
- package/dist/core/tool/openrouter_media.js.map +0 -1
- package/dist/core/tools/history.js +0 -118
- package/dist/core/tools/history.js.map +0 -1
- package/dist/core/tools/mcp.js +0 -167
- package/dist/core/tools/mcp.js.map +0 -1
- package/dist/core/tools/nook.js.map +0 -1
- package/dist/core/tools/web.js.map +0 -1
package/dist/code_mode/files.js
DELETED
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
import { CODE_MODE_MAX_BRIDGE_PAYLOAD_BYTES } from "../core/tools/code_mode_worker.js";
|
|
2
|
-
export const TAU_CODE_MODE_MAX_FILES = 128;
|
|
3
|
-
export const TAU_CODE_MODE_MAX_TOTAL_FILE_BYTES = 64 * 1024 * 1024;
|
|
4
|
-
const FILE_COMMAND_MAX_CAPTURE_BYTES = 8 * 1024 * 1024;
|
|
5
|
-
export function createTauCodeModeFilesApi(options) {
|
|
6
|
-
if (!options.agentId)
|
|
7
|
-
throw new Error("code-mode files agentId must not be empty");
|
|
8
|
-
let operationQueue = Promise.resolve();
|
|
9
|
-
const execute = (request, signal) => {
|
|
10
|
-
const operation = operationQueue.then(() => executeScratchFileRequest(options.adapter, request, signal));
|
|
11
|
-
operationQueue = operation.then(() => undefined, () => undefined);
|
|
12
|
-
return operation;
|
|
13
|
-
};
|
|
14
|
-
return {
|
|
15
|
-
read: async (args, context) => {
|
|
16
|
-
const [name] = parseArguments(args, ["string"], "files.read");
|
|
17
|
-
return await execute({ operation: "read", agentId: options.agentId, name }, context.signal);
|
|
18
|
-
},
|
|
19
|
-
write: async (args, context) => {
|
|
20
|
-
const [name, content] = parseArguments(args, ["string", "string"], "files.write");
|
|
21
|
-
return await execute({
|
|
22
|
-
operation: "write",
|
|
23
|
-
agentId: options.agentId,
|
|
24
|
-
name,
|
|
25
|
-
content,
|
|
26
|
-
}, context.signal);
|
|
27
|
-
},
|
|
28
|
-
list: async (args, context) => {
|
|
29
|
-
parseArguments(args, [], "files.list");
|
|
30
|
-
return await execute({ operation: "list", agentId: options.agentId }, context.signal);
|
|
31
|
-
},
|
|
32
|
-
remove: async (args, context) => {
|
|
33
|
-
const [name] = parseArguments(args, ["string"], "files.remove");
|
|
34
|
-
return await execute({
|
|
35
|
-
operation: "remove",
|
|
36
|
-
agentId: options.agentId,
|
|
37
|
-
name,
|
|
38
|
-
}, context.signal);
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function parseArguments(args, types, method) {
|
|
43
|
-
if (args.length !== types.length || args.some((value) => typeof value !== "string")) {
|
|
44
|
-
const signature = types.map((type, index) => `${index === 0 ? "name" : "content"}: ${type}`);
|
|
45
|
-
throw new TypeError(`${method} expects (${signature.join(", ")})`);
|
|
46
|
-
}
|
|
47
|
-
return args;
|
|
48
|
-
}
|
|
49
|
-
async function executeScratchFileRequest(adapter, request, signal) {
|
|
50
|
-
const result = await adapter.runNodeScript(SCRATCH_FILE_SCRIPT, {
|
|
51
|
-
input: JSON.stringify(request),
|
|
52
|
-
signal,
|
|
53
|
-
maxCaptureBytes: FILE_COMMAND_MAX_CAPTURE_BYTES,
|
|
54
|
-
});
|
|
55
|
-
if (result.exitCode !== 0) {
|
|
56
|
-
throw new Error(result.stderr.trim() || "code-mode scratch file operation failed");
|
|
57
|
-
}
|
|
58
|
-
let response;
|
|
59
|
-
try {
|
|
60
|
-
response = JSON.parse(result.stdout);
|
|
61
|
-
}
|
|
62
|
-
catch {
|
|
63
|
-
throw new Error("code-mode scratch file operation returned invalid JSON");
|
|
64
|
-
}
|
|
65
|
-
if (!isScratchFileResponse(response)) {
|
|
66
|
-
throw new Error("code-mode scratch file operation returned an invalid response");
|
|
67
|
-
}
|
|
68
|
-
if (!response.ok) {
|
|
69
|
-
const error = new Error(response.error.message);
|
|
70
|
-
error.name = response.error.name;
|
|
71
|
-
throw error;
|
|
72
|
-
}
|
|
73
|
-
return response.value;
|
|
74
|
-
}
|
|
75
|
-
function isScratchFileResponse(value) {
|
|
76
|
-
if (typeof value !== "object" || value === null || !("ok" in value))
|
|
77
|
-
return false;
|
|
78
|
-
const response = value;
|
|
79
|
-
if (response.ok === true)
|
|
80
|
-
return "value" in response;
|
|
81
|
-
if (response.ok !== false || typeof response.error !== "object" || response.error === null) {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
const error = response.error;
|
|
85
|
-
return typeof error.name === "string" && typeof error.message === "string";
|
|
86
|
-
}
|
|
87
|
-
const SCRATCH_FILE_SCRIPT = String.raw `
|
|
88
|
-
const {
|
|
89
|
-
closeSync,
|
|
90
|
-
constants,
|
|
91
|
-
fstatSync,
|
|
92
|
-
fsyncSync,
|
|
93
|
-
lstatSync,
|
|
94
|
-
mkdirSync,
|
|
95
|
-
openSync,
|
|
96
|
-
readFileSync,
|
|
97
|
-
readdirSync,
|
|
98
|
-
renameSync,
|
|
99
|
-
unlinkSync,
|
|
100
|
-
writeFileSync,
|
|
101
|
-
} = require("node:fs");
|
|
102
|
-
const { createHash, randomUUID } = require("node:crypto");
|
|
103
|
-
const { tmpdir } = require("node:os");
|
|
104
|
-
const { join } = require("node:path");
|
|
105
|
-
const { TextDecoder } = require("node:util");
|
|
106
|
-
|
|
107
|
-
const MAX_NAME_BYTES = 255;
|
|
108
|
-
const MAX_OPERATION_BYTES = ${CODE_MODE_MAX_BRIDGE_PAYLOAD_BYTES};
|
|
109
|
-
const MAX_FILES = ${TAU_CODE_MODE_MAX_FILES};
|
|
110
|
-
const MAX_TOTAL_BYTES = ${TAU_CODE_MODE_MAX_TOTAL_FILE_BYTES};
|
|
111
|
-
|
|
112
|
-
function fail(message) {
|
|
113
|
-
throw new Error(message);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function validateName(name) {
|
|
117
|
-
const bytes = Buffer.byteLength(name, "utf8");
|
|
118
|
-
if (
|
|
119
|
-
bytes === 0 ||
|
|
120
|
-
bytes > MAX_NAME_BYTES ||
|
|
121
|
-
name === "." ||
|
|
122
|
-
name === ".." ||
|
|
123
|
-
name.includes("/") ||
|
|
124
|
-
name.includes("\\") ||
|
|
125
|
-
name.includes("\0")
|
|
126
|
-
) {
|
|
127
|
-
fail("scratch file name must be a UTF-8 basename between 1 and 255 bytes");
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function ensureOwnedDirectory(path, label) {
|
|
132
|
-
try {
|
|
133
|
-
mkdirSync(path, { mode: 0o700 });
|
|
134
|
-
} catch (error) {
|
|
135
|
-
if (error?.code !== "EEXIST") throw error;
|
|
136
|
-
}
|
|
137
|
-
const stats = lstatSync(path);
|
|
138
|
-
if (stats.isSymbolicLink() || !stats.isDirectory()) {
|
|
139
|
-
fail(label + " path is not a directory");
|
|
140
|
-
}
|
|
141
|
-
if (typeof process.getuid !== "function" || stats.uid !== process.getuid()) {
|
|
142
|
-
fail(label + " directory is not owned by the current user");
|
|
143
|
-
}
|
|
144
|
-
if ((stats.mode & 0o077) !== 0) {
|
|
145
|
-
fail(label + " directory permissions must not allow group or other access");
|
|
146
|
-
}
|
|
147
|
-
return path;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function getRoot(agentId) {
|
|
151
|
-
if (typeof agentId !== "string" || agentId.length === 0) fail("agentId must not be empty");
|
|
152
|
-
const scope = createHash("sha256").update(agentId).digest("hex").slice(0, 32);
|
|
153
|
-
return ensureOwnedDirectory(join(tmpdir(), "tau-code-mode-files-" + scope), "code-mode scratch");
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function getStagingRoot(root) {
|
|
157
|
-
return ensureOwnedDirectory(root + "-staging", "code-mode scratch staging");
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function getFilePath(root, name) {
|
|
161
|
-
validateName(name);
|
|
162
|
-
return join(root, name);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function getExistingFile(path) {
|
|
166
|
-
let stats;
|
|
167
|
-
try {
|
|
168
|
-
stats = lstatSync(path);
|
|
169
|
-
} catch (error) {
|
|
170
|
-
if (error?.code === "ENOENT") return undefined;
|
|
171
|
-
throw error;
|
|
172
|
-
}
|
|
173
|
-
if (stats.isSymbolicLink() || !stats.isFile()) fail("scratch path is not a regular file");
|
|
174
|
-
return stats;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function listFiles(root) {
|
|
178
|
-
const files = [];
|
|
179
|
-
for (const name of readdirSync(root)) {
|
|
180
|
-
const path = join(root, name);
|
|
181
|
-
const stats = lstatSync(path);
|
|
182
|
-
if (stats.isSymbolicLink() || !stats.isFile()) continue;
|
|
183
|
-
files.push({ name, path, bytes: stats.size });
|
|
184
|
-
}
|
|
185
|
-
files.sort((left, right) => left.name.localeCompare(right.name));
|
|
186
|
-
return files;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function read(root, name) {
|
|
190
|
-
const path = getFilePath(root, name);
|
|
191
|
-
const descriptor = openSync(
|
|
192
|
-
path,
|
|
193
|
-
constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK,
|
|
194
|
-
);
|
|
195
|
-
try {
|
|
196
|
-
const stats = fstatSync(descriptor);
|
|
197
|
-
if (!stats.isFile()) fail("scratch path is not a regular file");
|
|
198
|
-
if (stats.size > MAX_OPERATION_BYTES) {
|
|
199
|
-
fail("scratch file exceeds the 1 MiB read limit");
|
|
200
|
-
}
|
|
201
|
-
const content = readFileSync(descriptor);
|
|
202
|
-
return new TextDecoder("utf-8", { fatal: true }).decode(content);
|
|
203
|
-
} finally {
|
|
204
|
-
closeSync(descriptor);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function write(root, name, content) {
|
|
209
|
-
if (typeof content !== "string") fail("scratch file content must be a string");
|
|
210
|
-
const bytes = Buffer.byteLength(content, "utf8");
|
|
211
|
-
if (bytes > MAX_OPERATION_BYTES) fail("scratch file exceeds the 1 MiB write limit");
|
|
212
|
-
|
|
213
|
-
const path = getFilePath(root, name);
|
|
214
|
-
const existing = getExistingFile(path);
|
|
215
|
-
const files = listFiles(root);
|
|
216
|
-
const totalBytes = files.reduce((total, file) => total + file.bytes, 0);
|
|
217
|
-
const resultingFiles = files.length + (existing ? 0 : 1);
|
|
218
|
-
const resultingBytes = totalBytes - (existing?.size ?? 0) + bytes;
|
|
219
|
-
if (resultingFiles > MAX_FILES) fail("scratch directory exceeds the 128-file limit");
|
|
220
|
-
if (resultingBytes > MAX_TOTAL_BYTES) fail("scratch directory exceeds the 64 MiB total limit");
|
|
221
|
-
|
|
222
|
-
const temporaryPath = join(getStagingRoot(root), ".tau-write-" + randomUUID());
|
|
223
|
-
let descriptor;
|
|
224
|
-
try {
|
|
225
|
-
descriptor = openSync(
|
|
226
|
-
temporaryPath,
|
|
227
|
-
constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW,
|
|
228
|
-
0o600,
|
|
229
|
-
);
|
|
230
|
-
writeFileSync(descriptor, content, "utf8");
|
|
231
|
-
fsyncSync(descriptor);
|
|
232
|
-
closeSync(descriptor);
|
|
233
|
-
descriptor = undefined;
|
|
234
|
-
renameSync(temporaryPath, path);
|
|
235
|
-
} finally {
|
|
236
|
-
if (descriptor !== undefined) closeSync(descriptor);
|
|
237
|
-
try {
|
|
238
|
-
unlinkSync(temporaryPath);
|
|
239
|
-
} catch (error) {
|
|
240
|
-
if (error?.code !== "ENOENT") throw error;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return { path, bytes };
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function list(root) {
|
|
247
|
-
const allFiles = listFiles(root);
|
|
248
|
-
return {
|
|
249
|
-
files: allFiles,
|
|
250
|
-
totalFiles: allFiles.length,
|
|
251
|
-
totalBytes: allFiles.reduce((total, file) => total + file.bytes, 0),
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function remove(root, name) {
|
|
256
|
-
const path = getFilePath(root, name);
|
|
257
|
-
if (!getExistingFile(path)) fail("scratch file does not exist");
|
|
258
|
-
unlinkSync(path);
|
|
259
|
-
return { path };
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
function execute(request) {
|
|
263
|
-
if (typeof request !== "object" || request === null || typeof request.operation !== "string") {
|
|
264
|
-
fail("invalid scratch file request");
|
|
265
|
-
}
|
|
266
|
-
const root = getRoot(request.agentId);
|
|
267
|
-
switch (request.operation) {
|
|
268
|
-
case "read":
|
|
269
|
-
return read(root, request.name);
|
|
270
|
-
case "write":
|
|
271
|
-
return write(root, request.name, request.content);
|
|
272
|
-
case "list":
|
|
273
|
-
return list(root);
|
|
274
|
-
case "remove":
|
|
275
|
-
return remove(root, request.name);
|
|
276
|
-
default:
|
|
277
|
-
fail("unsupported scratch file operation");
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
try {
|
|
282
|
-
const request = JSON.parse(readFileSync(0, "utf8"));
|
|
283
|
-
process.stdout.write(JSON.stringify({ ok: true, value: execute(request) }));
|
|
284
|
-
} catch (error) {
|
|
285
|
-
process.stdout.write(
|
|
286
|
-
JSON.stringify({
|
|
287
|
-
ok: false,
|
|
288
|
-
error: {
|
|
289
|
-
name: error instanceof Error ? error.name : "Error",
|
|
290
|
-
message: error instanceof Error ? error.message : String(error),
|
|
291
|
-
},
|
|
292
|
-
}),
|
|
293
|
-
);
|
|
294
|
-
}
|
|
295
|
-
`;
|
|
296
|
-
//# sourceMappingURL=files.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../src/code_mode/files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kCAAkC,EAAE,MAAM,mCAAmC,CAAC;AAEvF,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAC3C,MAAM,CAAC,MAAM,kCAAkC,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAEnE,MAAM,8BAA8B,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AA8CvD,MAAM,UAAU,yBAAyB,CAAC,OAAgC;IACxE,IAAI,CAAC,OAAO,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAEnF,IAAI,cAAc,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IACvC,MAAM,OAAO,GAAG,CAAI,OAA2B,EAAE,MAAmB,EAAc,EAAE;QAClF,MAAM,SAAS,GAAG,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,CACzC,yBAAyB,CAAI,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAC/D,CAAC;QACF,cAAc,GAAG,SAAS,CAAC,IAAI,CAC7B,GAAG,EAAE,CAAC,SAAS,EACf,GAAG,EAAE,CAAC,SAAS,CAChB,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,KAAK,EAAE,IAAe,EAAE,OAAgC,EAAE,EAAE;YAChE,MAAM,CAAC,IAAI,CAAC,GAAG,cAAc,CAA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yD,CAAC,CAAC;YACpF,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { constants } from "node:fs";
|
|
2
|
-
import { mkdtemp, open, rm, writeFile } from "node:fs/promises";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { fileTypeFromBuffer } from "file-type";
|
|
6
|
-
import sharp from "sharp";
|
|
7
|
-
import { z } from "zod";
|
|
8
|
-
import { ToolCliError } from "./errors.js";
|
|
9
|
-
import { parseMediaJson } from "./media.js";
|
|
10
|
-
export const OPENROUTER_TEXT_BYTES = 1_000_000;
|
|
11
|
-
export const OPENROUTER_REQUEST_BYTES = 20_000_000;
|
|
12
|
-
async function readBounded(stream, limit) {
|
|
13
|
-
const chunks = [];
|
|
14
|
-
let size = 0;
|
|
15
|
-
for await (const chunk of stream) {
|
|
16
|
-
const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
17
|
-
size += bytes.length;
|
|
18
|
-
if (size > limit)
|
|
19
|
-
throw new ToolCliError(`input exceeds ${limit} bytes; reduce its size`);
|
|
20
|
-
chunks.push(bytes);
|
|
21
|
-
}
|
|
22
|
-
return Buffer.concat(chunks);
|
|
23
|
-
}
|
|
24
|
-
export async function readOpenRouterFile(path, limit) {
|
|
25
|
-
const file = await open(path, constants.O_RDONLY | constants.O_NONBLOCK);
|
|
26
|
-
try {
|
|
27
|
-
const stat = await file.stat();
|
|
28
|
-
if (!stat.isFile())
|
|
29
|
-
throw new ToolCliError(`expected a regular local file: ${path}`);
|
|
30
|
-
if (stat.size > limit)
|
|
31
|
-
throw new ToolCliError(`input exceeds ${limit} bytes: ${path}`);
|
|
32
|
-
return await readBounded(file.createReadStream({ autoClose: false }), limit);
|
|
33
|
-
}
|
|
34
|
-
finally {
|
|
35
|
-
await file.close();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
export async function readOpenRouterStdin(stdin) {
|
|
39
|
-
if (stdin.isTTY)
|
|
40
|
-
throw new ToolCliError("--input - requires piped or redirected JSON, not a terminal");
|
|
41
|
-
const timer = setTimeout(() => stdin.destroy(new ToolCliError("stdin did not reach EOF within 30 seconds")), 30_000);
|
|
42
|
-
try {
|
|
43
|
-
return await readBounded(stdin, OPENROUTER_TEXT_BYTES);
|
|
44
|
-
}
|
|
45
|
-
finally {
|
|
46
|
-
clearTimeout(timer);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
export function decodeOpenRouterText(bytes) {
|
|
50
|
-
try {
|
|
51
|
-
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
throw new ToolCliError("input must be valid UTF-8");
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const mediaProbe = z.object({
|
|
58
|
-
format: z.object({ duration: z.string().transform(Number).pipe(z.number().positive().max(600)) }),
|
|
59
|
-
streams: z
|
|
60
|
-
.array(z.object({
|
|
61
|
-
codec_type: z.string(),
|
|
62
|
-
codec_name: z.string(),
|
|
63
|
-
width: z.number().optional(),
|
|
64
|
-
height: z.number().optional(),
|
|
65
|
-
}))
|
|
66
|
-
.min(1),
|
|
67
|
-
});
|
|
68
|
-
async function probeMedia(bytes, kind, format, spawnImpl) {
|
|
69
|
-
const directory = await mkdtemp(join(tmpdir(), "tau-openrouter-"));
|
|
70
|
-
try {
|
|
71
|
-
const path = join(directory, "input");
|
|
72
|
-
await writeFile(path, bytes, { mode: 0o600 });
|
|
73
|
-
const result = await spawnImpl("ffprobe", [
|
|
74
|
-
"-v",
|
|
75
|
-
"error",
|
|
76
|
-
"-protocol_whitelist",
|
|
77
|
-
"file",
|
|
78
|
-
"-f",
|
|
79
|
-
format,
|
|
80
|
-
"-show_entries",
|
|
81
|
-
"format=duration:stream=codec_type,codec_name,width,height",
|
|
82
|
-
"-of",
|
|
83
|
-
"json",
|
|
84
|
-
path,
|
|
85
|
-
], { timeoutMs: 15_000, maxCaptureBytes: 1_000_000, detached: true, killProcessGroup: true });
|
|
86
|
-
if (result.exitCode !== 0 || result.timedOut || result.captureLimitExceeded || result.aborted) {
|
|
87
|
-
throw new ToolCliError("ffprobe could not validate media; use a valid WAV, MP3, or MP4 file");
|
|
88
|
-
}
|
|
89
|
-
const parsed = mediaProbe.safeParse(parseMediaJson(result.stdout, "ffprobe output"));
|
|
90
|
-
if (!parsed.success)
|
|
91
|
-
throw new ToolCliError("media must have a known duration of at most 600 seconds");
|
|
92
|
-
const { streams, format: metadata } = parsed.data;
|
|
93
|
-
if (kind === "audio") {
|
|
94
|
-
if (streams.length !== 1 ||
|
|
95
|
-
streams.some((stream) => stream.codec_type !== "audio" ||
|
|
96
|
-
stream.codec_name !== (format === "wav" ? "pcm_s16le" : "mp3"))) {
|
|
97
|
-
throw new ToolCliError("audio requires a single PCM 16-bit WAV or MP3 audio stream");
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
else if (!streams.some((stream) => stream.codec_type === "video") ||
|
|
101
|
-
streams.some((stream) => {
|
|
102
|
-
if (stream.codec_type === "audio")
|
|
103
|
-
return stream.codec_name !== "aac";
|
|
104
|
-
return (stream.codec_type !== "video" ||
|
|
105
|
-
stream.codec_name !== "h264" ||
|
|
106
|
-
!stream.width ||
|
|
107
|
-
!stream.height ||
|
|
108
|
-
stream.width > 3840 ||
|
|
109
|
-
stream.height > 2160);
|
|
110
|
-
})) {
|
|
111
|
-
throw new ToolCliError("video requires H.264 MP4 up to 3840x2160, with optional AAC audio");
|
|
112
|
-
}
|
|
113
|
-
return metadata.duration;
|
|
114
|
-
}
|
|
115
|
-
catch (error) {
|
|
116
|
-
if (error.code === "ENOENT") {
|
|
117
|
-
throw new ToolCliError("ffprobe not found; install FFmpeg (brew install ffmpeg or apt install ffmpeg) and ensure ffprobe is on PATH");
|
|
118
|
-
}
|
|
119
|
-
throw error;
|
|
120
|
-
}
|
|
121
|
-
finally {
|
|
122
|
-
await rm(directory, { recursive: true, force: true });
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
export async function prepareOpenRouterAttachments(attachments, spawnImpl) {
|
|
126
|
-
if (attachments.length > 16 ||
|
|
127
|
-
attachments.filter((item) => item.kind === "audio").length > 4 ||
|
|
128
|
-
attachments.filter((item) => item.kind === "video").length > 1) {
|
|
129
|
-
throw new ToolCliError("at most 16 attachments, including at most 4 audio files and 1 video, are supported");
|
|
130
|
-
}
|
|
131
|
-
const parts = [];
|
|
132
|
-
let duration = 0;
|
|
133
|
-
let encodedBytes = 0;
|
|
134
|
-
for (const { kind, path } of attachments) {
|
|
135
|
-
const bytes = await readOpenRouterFile(path, kind === "image" ? 5_000_000 : 12_000_000);
|
|
136
|
-
encodedBytes += 4 * Math.ceil(bytes.length / 3);
|
|
137
|
-
if (encodedBytes > OPENROUTER_REQUEST_BYTES)
|
|
138
|
-
throw new ToolCliError("attachments exceed the 20 MB encoded request limit");
|
|
139
|
-
const type = await fileTypeFromBuffer(bytes);
|
|
140
|
-
if (kind === "image") {
|
|
141
|
-
if (!type || !["image/png", "image/jpeg", "image/webp"].includes(type.mime)) {
|
|
142
|
-
throw new ToolCliError(`unsupported image: ${path}; use PNG, JPEG, or WebP`);
|
|
143
|
-
}
|
|
144
|
-
const image = sharp(bytes, { limitInputPixels: 32_000_000 });
|
|
145
|
-
const metadata = await image.metadata();
|
|
146
|
-
if (!metadata.width ||
|
|
147
|
-
!metadata.height ||
|
|
148
|
-
metadata.width > 8000 ||
|
|
149
|
-
metadata.height > 8000 ||
|
|
150
|
-
(metadata.pages ?? 1) > 1) {
|
|
151
|
-
throw new ToolCliError("images must be single-frame, at most 8000 pixels per edge and 32 megapixels");
|
|
152
|
-
}
|
|
153
|
-
await image.stats();
|
|
154
|
-
parts.push({
|
|
155
|
-
type: "image_url",
|
|
156
|
-
image_url: { url: `data:${type.mime};base64,${bytes.toString("base64")}` },
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
const format = kind === "audio"
|
|
161
|
-
? { "audio/wav": "wav", "audio/mpeg": "mp3" }[type?.mime ?? ""]
|
|
162
|
-
: type?.mime === "video/mp4"
|
|
163
|
-
? "mov"
|
|
164
|
-
: undefined;
|
|
165
|
-
if (!format)
|
|
166
|
-
throw new ToolCliError(`unsupported ${kind}: ${path}; use WAV/MP3 audio or MP4 video`);
|
|
167
|
-
duration += await probeMedia(bytes, kind, format, spawnImpl);
|
|
168
|
-
if (duration > 600)
|
|
169
|
-
throw new ToolCliError("combined audio/video duration exceeds 600 seconds");
|
|
170
|
-
parts.push(kind === "audio"
|
|
171
|
-
? { type: "input_audio", input_audio: { data: bytes.toString("base64"), format } }
|
|
172
|
-
: {
|
|
173
|
-
type: "video_url",
|
|
174
|
-
video_url: { url: `data:video/mp4;base64,${bytes.toString("base64")}` },
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return parts;
|
|
179
|
-
}
|
|
180
|
-
//# sourceMappingURL=openrouter_media.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openrouter_media.js","sourceRoot":"","sources":["../../../src/core/tool/openrouter_media.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,CAAC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CAAkC,CAAC,CAAC;YACzF,QAAQ,IAAI,MAAM,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;YAC7D,IAAI,QAAQ,GAAG,GAAG;gBAChB,MAAM,IAAI,YAAY,CAAC,mDAAmD,CAAC,CAAC;YAC9E,KAAK,CAAC,IAAI,CACR,IAAI,KAAK,OAAO;gBACd,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,EAAE;gBAClF,CAAC,CAAC;oBACE,IAAI,EAAE,WAAW;oBACjB,SAAS,EAAE,EAAE,GAAG,EAAE,yBAAyB,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE;iBACxE,CACN,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { Type } from "typebox";
|
|
3
|
-
import { z } from "zod";
|
|
4
|
-
import { formatZodError } from "../utils/zod.js";
|
|
5
|
-
import { buildCodeModeToolDescription, createCodeModeToolDefinition, executeInternalCodeMode, } from "./code_mode.js";
|
|
6
|
-
import { TOOL_NAME_HISTORY } from "./tool_names.js";
|
|
7
|
-
const HISTORY_CODE_MODE_TIMEOUT_MS = 60_000;
|
|
8
|
-
const HISTORY_DESCRIPTION = buildCodeModeToolDescription({
|
|
9
|
-
sdkGlobal: "history",
|
|
10
|
-
introduction: [
|
|
11
|
-
"Run a one-shot JavaScript program to search and read durable transcripts from the configured history collection.",
|
|
12
|
-
"Use this tool only when the user or other active instructions directly ask you to reference, search, or read historical transcripts; do not invoke it merely because prior sessions might be relevant.",
|
|
13
|
-
"For a known historical session without a clear lookup key, a bounded chronological overview is one way to identify entries worth inspecting in detail.",
|
|
14
|
-
"When a remote session descriptor includes webUrl, return it when the user asks for a conversation link.",
|
|
15
|
-
"The tool is read-only and has global visibility across repositories and execution environments.",
|
|
16
|
-
],
|
|
17
|
-
});
|
|
18
|
-
export const HISTORY_TOOL = {
|
|
19
|
-
name: TOOL_NAME_HISTORY,
|
|
20
|
-
description: HISTORY_DESCRIPTION,
|
|
21
|
-
parameters: Type.Object({
|
|
22
|
-
code: Type.String({
|
|
23
|
-
description: "JavaScript source to execute. Use console output for text and await image(block) to return images.",
|
|
24
|
-
}),
|
|
25
|
-
}, { additionalProperties: false }),
|
|
26
|
-
};
|
|
27
|
-
const historyArgsSchema = z
|
|
28
|
-
.object({ code: z.string().trim().min(1, "must not be empty.") })
|
|
29
|
-
.strict();
|
|
30
|
-
const attributeFilterSchema = z.union([
|
|
31
|
-
z.string().max(1_024),
|
|
32
|
-
z.object({ contains: z.string().min(1).max(1_024) }).strict(),
|
|
33
|
-
]);
|
|
34
|
-
const attributeFiltersSchema = z
|
|
35
|
-
.record(z.string().min(1).max(64), attributeFilterSchema)
|
|
36
|
-
.refine((attributes) => Object.keys(attributes).length <= 32);
|
|
37
|
-
const searchInputSchema = z
|
|
38
|
-
.object({
|
|
39
|
-
query: z.string().trim().min(1).max(1_000).optional(),
|
|
40
|
-
attributes: attributeFiltersSchema.optional(),
|
|
41
|
-
limit: z.number().int().min(1).max(75).default(10),
|
|
42
|
-
cursor: z.string().min(1).max(2_048).optional(),
|
|
43
|
-
})
|
|
44
|
-
.strict();
|
|
45
|
-
const readInputSchema = z
|
|
46
|
-
.object({
|
|
47
|
-
sessionId: z.string().trim().min(1).max(256),
|
|
48
|
-
limit: z.number().int().min(1).max(100).default(50),
|
|
49
|
-
cursor: z.string().min(1).max(2_048).optional(),
|
|
50
|
-
})
|
|
51
|
-
.strict();
|
|
52
|
-
const documentation = readFileSync(new URL("../static/code_mode/history/documentation.md", import.meta.url), "utf8");
|
|
53
|
-
function parseHistoryArguments(raw) {
|
|
54
|
-
const rawCode = typeof raw === "object" && raw !== null && typeof raw.code === "string"
|
|
55
|
-
? raw.code
|
|
56
|
-
: "";
|
|
57
|
-
const subject = rawCode
|
|
58
|
-
.split(/\r?\n/)
|
|
59
|
-
.map((line) => line.trim())
|
|
60
|
-
.find(Boolean) ?? "(invalid code)";
|
|
61
|
-
const parsed = historyArgsSchema.safeParse(raw);
|
|
62
|
-
if (!parsed.success) {
|
|
63
|
-
return {
|
|
64
|
-
ok: false,
|
|
65
|
-
error: formatZodError(parsed.error),
|
|
66
|
-
code: rawCode,
|
|
67
|
-
subject,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
return {
|
|
71
|
-
ok: true,
|
|
72
|
-
args: parsed.data,
|
|
73
|
-
code: parsed.data.code,
|
|
74
|
-
subject,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
async function handleHistoryRequest(method, args, history, signal) {
|
|
78
|
-
if (args.length !== 1) {
|
|
79
|
-
throw new Error(`history.${method} expects one options object`);
|
|
80
|
-
}
|
|
81
|
-
if (method === "search") {
|
|
82
|
-
const parsed = searchInputSchema.safeParse(args[0] ?? {});
|
|
83
|
-
if (!parsed.success) {
|
|
84
|
-
throw new Error(`Invalid history.search options: ${formatZodError(parsed.error)}`);
|
|
85
|
-
}
|
|
86
|
-
return await history.search(parsed.data, signal);
|
|
87
|
-
}
|
|
88
|
-
if (method === "read") {
|
|
89
|
-
const parsed = readInputSchema.safeParse(args[0]);
|
|
90
|
-
if (!parsed.success) {
|
|
91
|
-
throw new Error(`Invalid history.read options: ${formatZodError(parsed.error)}`);
|
|
92
|
-
}
|
|
93
|
-
return await history.read(parsed.data, signal);
|
|
94
|
-
}
|
|
95
|
-
throw new Error(`unsupported history method '${method}'`);
|
|
96
|
-
}
|
|
97
|
-
export function createHistoryToolDefinition(backend, history) {
|
|
98
|
-
const implementation = {
|
|
99
|
-
schema: HISTORY_TOOL,
|
|
100
|
-
timeoutMs: HISTORY_CODE_MODE_TIMEOUT_MS,
|
|
101
|
-
parseArguments: parseHistoryArguments,
|
|
102
|
-
execute: async ({ code, agentId, signal, backend: executionBackend }) => executeInternalCodeMode({
|
|
103
|
-
name: TOOL_NAME_HISTORY,
|
|
104
|
-
documentation,
|
|
105
|
-
api: {
|
|
106
|
-
search: (args, context) => handleHistoryRequest("search", args, history, context.signal),
|
|
107
|
-
read: (args, context) => handleHistoryRequest("read", args, history, context.signal),
|
|
108
|
-
},
|
|
109
|
-
code,
|
|
110
|
-
agentId,
|
|
111
|
-
backend: executionBackend,
|
|
112
|
-
signal,
|
|
113
|
-
timeoutMs: HISTORY_CODE_MODE_TIMEOUT_MS,
|
|
114
|
-
}),
|
|
115
|
-
};
|
|
116
|
-
return createCodeModeToolDefinition(backend, implementation);
|
|
117
|
-
}
|
|
118
|
-
//# sourceMappingURL=history.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../../src/core/tools/history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,4BAA4B,EAE5B,4BAA4B,EAC5B,uBAAuB,GAExB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,4BAA4B,GAAG,MAAM,CAAC;AAE5C,MAAM,mBAAmB,GAAG,4BAA4B,CAAC;IACvD,SAAS,EAAE,SAAS;IACpB,YAAY,EAAE;QACZ,kHAAkH;QAClH,wMAAwM;QACxM,wJAAwJ;QACxJ,yGAAyG;QACzG,iGAAiG;KAClG;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAS;IAChC,IAAI,EAAE,iBAAiB;IACvB,WAAW,EAAE,mBAAmB;IA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