@dexto/tools-filesystem 1.6.20 → 1.6.22
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/filesystem-service.cjs +62 -1
- package/dist/filesystem-service.d.ts +5 -1
- package/dist/filesystem-service.d.ts.map +1 -1
- package/dist/filesystem-service.js +62 -1
- package/dist/filesystem-service.test.cjs +123 -7
- package/dist/filesystem-service.test.js +123 -7
- package/dist/index.cjs +3 -0
- package/dist/index.d.cts +33 -4
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/mime-utils.cjs +170 -0
- package/dist/mime-utils.d.ts +6 -0
- package/dist/mime-utils.d.ts.map +1 -0
- package/dist/mime-utils.js +133 -0
- package/dist/read-file-tool.cjs +1 -1
- package/dist/read-file-tool.js +1 -1
- package/dist/read-media-file-tool.cjs +87 -0
- package/dist/read-media-file-tool.d.ts +18 -0
- package/dist/read-media-file-tool.d.ts.map +1 -0
- package/dist/read-media-file-tool.js +63 -0
- package/dist/read-media-file-tool.test.cjs +150 -0
- package/dist/read-media-file-tool.test.d.ts +2 -0
- package/dist/read-media-file-tool.test.d.ts.map +1 -0
- package/dist/read-media-file-tool.test.js +127 -0
- package/dist/tool-factory-config.cjs +1 -0
- package/dist/tool-factory-config.d.ts +4 -4
- package/dist/tool-factory-config.d.ts.map +1 -1
- package/dist/tool-factory-config.js +1 -0
- package/dist/tool-factory.cjs +3 -1
- package/dist/tool-factory.d.ts.map +1 -1
- package/dist/tool-factory.js +3 -1
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var mime_utils_exports = {};
|
|
30
|
+
__export(mime_utils_exports, {
|
|
31
|
+
detectMimeType: () => detectMimeType,
|
|
32
|
+
getMediaFileKind: () => getMediaFileKind,
|
|
33
|
+
isLikelyBinary: () => isLikelyBinary,
|
|
34
|
+
isTextMimeType: () => isTextMimeType
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(mime_utils_exports);
|
|
37
|
+
var path = __toESM(require("node:path"), 1);
|
|
38
|
+
const MIME_BY_EXTENSION = {
|
|
39
|
+
".txt": "text/plain",
|
|
40
|
+
".md": "text/markdown",
|
|
41
|
+
".markdown": "text/markdown",
|
|
42
|
+
".html": "text/html",
|
|
43
|
+
".htm": "text/html",
|
|
44
|
+
".css": "text/css",
|
|
45
|
+
".js": "text/javascript",
|
|
46
|
+
".mjs": "text/javascript",
|
|
47
|
+
".cjs": "text/javascript",
|
|
48
|
+
".jsx": "text/javascript",
|
|
49
|
+
".ts": "text/typescript",
|
|
50
|
+
".mts": "text/typescript",
|
|
51
|
+
".cts": "text/typescript",
|
|
52
|
+
".tsx": "text/typescript",
|
|
53
|
+
".vue": "text/x-vue",
|
|
54
|
+
".json": "application/json",
|
|
55
|
+
".jsonc": "application/json",
|
|
56
|
+
".xml": "application/xml",
|
|
57
|
+
".yaml": "application/yaml",
|
|
58
|
+
".yml": "application/yaml",
|
|
59
|
+
".toml": "application/toml",
|
|
60
|
+
".ini": "text/plain",
|
|
61
|
+
".cfg": "text/plain",
|
|
62
|
+
".conf": "text/plain",
|
|
63
|
+
".csv": "text/csv",
|
|
64
|
+
".log": "text/plain",
|
|
65
|
+
".py": "text/x-python",
|
|
66
|
+
".rb": "text/x-ruby",
|
|
67
|
+
".php": "text/x-php",
|
|
68
|
+
".java": "text/x-java-source",
|
|
69
|
+
".kt": "text/x-kotlin",
|
|
70
|
+
".swift": "text/x-swift",
|
|
71
|
+
".go": "text/x-go",
|
|
72
|
+
".rs": "text/x-rust",
|
|
73
|
+
".cpp": "text/x-c++src",
|
|
74
|
+
".c": "text/x-csrc",
|
|
75
|
+
".h": "text/x-chdr",
|
|
76
|
+
".hpp": "text/x-c++hdr",
|
|
77
|
+
".sh": "text/x-shellscript",
|
|
78
|
+
".bash": "text/x-shellscript",
|
|
79
|
+
".zsh": "text/x-shellscript",
|
|
80
|
+
".fish": "text/x-shellscript",
|
|
81
|
+
".sql": "text/x-sql",
|
|
82
|
+
".rst": "text/x-rst",
|
|
83
|
+
".tex": "text/x-tex",
|
|
84
|
+
".dockerfile": "text/x-dockerfile",
|
|
85
|
+
".pdf": "application/pdf",
|
|
86
|
+
".doc": "application/msword",
|
|
87
|
+
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
88
|
+
".ppt": "application/vnd.ms-powerpoint",
|
|
89
|
+
".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
90
|
+
".xls": "application/vnd.ms-excel",
|
|
91
|
+
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
92
|
+
".jpg": "image/jpeg",
|
|
93
|
+
".jpeg": "image/jpeg",
|
|
94
|
+
".png": "image/png",
|
|
95
|
+
".gif": "image/gif",
|
|
96
|
+
".bmp": "image/bmp",
|
|
97
|
+
".ico": "image/x-icon",
|
|
98
|
+
".tif": "image/tiff",
|
|
99
|
+
".tiff": "image/tiff",
|
|
100
|
+
".webp": "image/webp",
|
|
101
|
+
".svg": "image/svg+xml",
|
|
102
|
+
".avif": "image/avif",
|
|
103
|
+
".mp3": "audio/mpeg",
|
|
104
|
+
".wav": "audio/wav",
|
|
105
|
+
".ogg": "audio/ogg",
|
|
106
|
+
".oga": "audio/ogg",
|
|
107
|
+
".m4a": "audio/mp4",
|
|
108
|
+
".aac": "audio/aac",
|
|
109
|
+
".flac": "audio/flac",
|
|
110
|
+
".weba": "audio/webm",
|
|
111
|
+
".mp4": "video/mp4",
|
|
112
|
+
".m4v": "video/mp4",
|
|
113
|
+
".webm": "video/webm",
|
|
114
|
+
".mov": "video/quicktime",
|
|
115
|
+
".avi": "video/x-msvideo",
|
|
116
|
+
".mkv": "video/x-matroska",
|
|
117
|
+
".ogv": "video/ogg"
|
|
118
|
+
};
|
|
119
|
+
const MIME_BY_BASENAME = {
|
|
120
|
+
dockerfile: "text/x-dockerfile",
|
|
121
|
+
makefile: "text/plain",
|
|
122
|
+
readme: "text/plain",
|
|
123
|
+
license: "text/plain"
|
|
124
|
+
};
|
|
125
|
+
const EXTRA_TEXT_MIME_TYPES = /* @__PURE__ */ new Set([
|
|
126
|
+
"application/json",
|
|
127
|
+
"application/xml",
|
|
128
|
+
"application/yaml",
|
|
129
|
+
"application/toml",
|
|
130
|
+
"application/javascript"
|
|
131
|
+
]);
|
|
132
|
+
function detectMimeType(filePath, rawContent) {
|
|
133
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
134
|
+
if (ext && MIME_BY_EXTENSION[ext]) {
|
|
135
|
+
return MIME_BY_EXTENSION[ext];
|
|
136
|
+
}
|
|
137
|
+
const base = path.basename(filePath).toLowerCase();
|
|
138
|
+
if (MIME_BY_BASENAME[base]) {
|
|
139
|
+
return MIME_BY_BASENAME[base];
|
|
140
|
+
}
|
|
141
|
+
if (rawContent && !isLikelyBinary(rawContent)) {
|
|
142
|
+
return "text/plain";
|
|
143
|
+
}
|
|
144
|
+
return "application/octet-stream";
|
|
145
|
+
}
|
|
146
|
+
function isTextMimeType(mimeType) {
|
|
147
|
+
return mimeType.startsWith("text/") || EXTRA_TEXT_MIME_TYPES.has(mimeType);
|
|
148
|
+
}
|
|
149
|
+
function getMediaFileKind(mimeType) {
|
|
150
|
+
if (mimeType.startsWith("image/")) return "image";
|
|
151
|
+
if (mimeType.startsWith("audio/")) return "audio";
|
|
152
|
+
if (mimeType.startsWith("video/")) return "video";
|
|
153
|
+
return "file";
|
|
154
|
+
}
|
|
155
|
+
function isLikelyBinary(rawContent) {
|
|
156
|
+
const sample = rawContent.subarray(0, Math.min(rawContent.length, 8e3));
|
|
157
|
+
for (const byte of sample) {
|
|
158
|
+
if (byte === 0) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
165
|
+
0 && (module.exports = {
|
|
166
|
+
detectMimeType,
|
|
167
|
+
getMediaFileKind,
|
|
168
|
+
isLikelyBinary,
|
|
169
|
+
isTextMimeType
|
|
170
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type MediaFileKind = 'image' | 'audio' | 'video' | 'file';
|
|
2
|
+
export declare function detectMimeType(filePath: string, rawContent?: Buffer): string;
|
|
3
|
+
export declare function isTextMimeType(mimeType: string): boolean;
|
|
4
|
+
export declare function getMediaFileKind(mimeType: string): MediaFileKind;
|
|
5
|
+
export declare function isLikelyBinary(rawContent: Buffer): boolean;
|
|
6
|
+
//# sourceMappingURL=mime-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mime-utils.d.ts","sourceRoot":"","sources":["../src/mime-utils.ts"],"names":[],"mappings":"AAmGA,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;AAEjE,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAgB5E;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAExD;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,CAKhE;AAED,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAQ1D"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
const MIME_BY_EXTENSION = {
|
|
3
|
+
".txt": "text/plain",
|
|
4
|
+
".md": "text/markdown",
|
|
5
|
+
".markdown": "text/markdown",
|
|
6
|
+
".html": "text/html",
|
|
7
|
+
".htm": "text/html",
|
|
8
|
+
".css": "text/css",
|
|
9
|
+
".js": "text/javascript",
|
|
10
|
+
".mjs": "text/javascript",
|
|
11
|
+
".cjs": "text/javascript",
|
|
12
|
+
".jsx": "text/javascript",
|
|
13
|
+
".ts": "text/typescript",
|
|
14
|
+
".mts": "text/typescript",
|
|
15
|
+
".cts": "text/typescript",
|
|
16
|
+
".tsx": "text/typescript",
|
|
17
|
+
".vue": "text/x-vue",
|
|
18
|
+
".json": "application/json",
|
|
19
|
+
".jsonc": "application/json",
|
|
20
|
+
".xml": "application/xml",
|
|
21
|
+
".yaml": "application/yaml",
|
|
22
|
+
".yml": "application/yaml",
|
|
23
|
+
".toml": "application/toml",
|
|
24
|
+
".ini": "text/plain",
|
|
25
|
+
".cfg": "text/plain",
|
|
26
|
+
".conf": "text/plain",
|
|
27
|
+
".csv": "text/csv",
|
|
28
|
+
".log": "text/plain",
|
|
29
|
+
".py": "text/x-python",
|
|
30
|
+
".rb": "text/x-ruby",
|
|
31
|
+
".php": "text/x-php",
|
|
32
|
+
".java": "text/x-java-source",
|
|
33
|
+
".kt": "text/x-kotlin",
|
|
34
|
+
".swift": "text/x-swift",
|
|
35
|
+
".go": "text/x-go",
|
|
36
|
+
".rs": "text/x-rust",
|
|
37
|
+
".cpp": "text/x-c++src",
|
|
38
|
+
".c": "text/x-csrc",
|
|
39
|
+
".h": "text/x-chdr",
|
|
40
|
+
".hpp": "text/x-c++hdr",
|
|
41
|
+
".sh": "text/x-shellscript",
|
|
42
|
+
".bash": "text/x-shellscript",
|
|
43
|
+
".zsh": "text/x-shellscript",
|
|
44
|
+
".fish": "text/x-shellscript",
|
|
45
|
+
".sql": "text/x-sql",
|
|
46
|
+
".rst": "text/x-rst",
|
|
47
|
+
".tex": "text/x-tex",
|
|
48
|
+
".dockerfile": "text/x-dockerfile",
|
|
49
|
+
".pdf": "application/pdf",
|
|
50
|
+
".doc": "application/msword",
|
|
51
|
+
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
52
|
+
".ppt": "application/vnd.ms-powerpoint",
|
|
53
|
+
".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
54
|
+
".xls": "application/vnd.ms-excel",
|
|
55
|
+
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
56
|
+
".jpg": "image/jpeg",
|
|
57
|
+
".jpeg": "image/jpeg",
|
|
58
|
+
".png": "image/png",
|
|
59
|
+
".gif": "image/gif",
|
|
60
|
+
".bmp": "image/bmp",
|
|
61
|
+
".ico": "image/x-icon",
|
|
62
|
+
".tif": "image/tiff",
|
|
63
|
+
".tiff": "image/tiff",
|
|
64
|
+
".webp": "image/webp",
|
|
65
|
+
".svg": "image/svg+xml",
|
|
66
|
+
".avif": "image/avif",
|
|
67
|
+
".mp3": "audio/mpeg",
|
|
68
|
+
".wav": "audio/wav",
|
|
69
|
+
".ogg": "audio/ogg",
|
|
70
|
+
".oga": "audio/ogg",
|
|
71
|
+
".m4a": "audio/mp4",
|
|
72
|
+
".aac": "audio/aac",
|
|
73
|
+
".flac": "audio/flac",
|
|
74
|
+
".weba": "audio/webm",
|
|
75
|
+
".mp4": "video/mp4",
|
|
76
|
+
".m4v": "video/mp4",
|
|
77
|
+
".webm": "video/webm",
|
|
78
|
+
".mov": "video/quicktime",
|
|
79
|
+
".avi": "video/x-msvideo",
|
|
80
|
+
".mkv": "video/x-matroska",
|
|
81
|
+
".ogv": "video/ogg"
|
|
82
|
+
};
|
|
83
|
+
const MIME_BY_BASENAME = {
|
|
84
|
+
dockerfile: "text/x-dockerfile",
|
|
85
|
+
makefile: "text/plain",
|
|
86
|
+
readme: "text/plain",
|
|
87
|
+
license: "text/plain"
|
|
88
|
+
};
|
|
89
|
+
const EXTRA_TEXT_MIME_TYPES = /* @__PURE__ */ new Set([
|
|
90
|
+
"application/json",
|
|
91
|
+
"application/xml",
|
|
92
|
+
"application/yaml",
|
|
93
|
+
"application/toml",
|
|
94
|
+
"application/javascript"
|
|
95
|
+
]);
|
|
96
|
+
function detectMimeType(filePath, rawContent) {
|
|
97
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
98
|
+
if (ext && MIME_BY_EXTENSION[ext]) {
|
|
99
|
+
return MIME_BY_EXTENSION[ext];
|
|
100
|
+
}
|
|
101
|
+
const base = path.basename(filePath).toLowerCase();
|
|
102
|
+
if (MIME_BY_BASENAME[base]) {
|
|
103
|
+
return MIME_BY_BASENAME[base];
|
|
104
|
+
}
|
|
105
|
+
if (rawContent && !isLikelyBinary(rawContent)) {
|
|
106
|
+
return "text/plain";
|
|
107
|
+
}
|
|
108
|
+
return "application/octet-stream";
|
|
109
|
+
}
|
|
110
|
+
function isTextMimeType(mimeType) {
|
|
111
|
+
return mimeType.startsWith("text/") || EXTRA_TEXT_MIME_TYPES.has(mimeType);
|
|
112
|
+
}
|
|
113
|
+
function getMediaFileKind(mimeType) {
|
|
114
|
+
if (mimeType.startsWith("image/")) return "image";
|
|
115
|
+
if (mimeType.startsWith("audio/")) return "audio";
|
|
116
|
+
if (mimeType.startsWith("video/")) return "video";
|
|
117
|
+
return "file";
|
|
118
|
+
}
|
|
119
|
+
function isLikelyBinary(rawContent) {
|
|
120
|
+
const sample = rawContent.subarray(0, Math.min(rawContent.length, 8e3));
|
|
121
|
+
for (const byte of sample) {
|
|
122
|
+
if (byte === 0) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
export {
|
|
129
|
+
detectMimeType,
|
|
130
|
+
getMediaFileKind,
|
|
131
|
+
isLikelyBinary,
|
|
132
|
+
isTextMimeType
|
|
133
|
+
};
|
package/dist/read-file-tool.cjs
CHANGED
|
@@ -33,7 +33,7 @@ function createReadFileTool(getFileSystemService) {
|
|
|
33
33
|
return (0, import_core.defineTool)({
|
|
34
34
|
id: "read_file",
|
|
35
35
|
aliases: ["read"],
|
|
36
|
-
description: "Read the contents of a file with optional pagination. Returns file content, line count, encoding, and whether the output was truncated. Use limit and offset parameters for large files to read specific sections.
|
|
36
|
+
description: "Read the UTF-8 text contents of a file with optional pagination. Returns file content, line count, encoding, MIME type, and whether the output was truncated. Use limit and offset parameters for large files to read specific sections. Use read_media_file for image, audio, video, PDF, and other binary files.",
|
|
37
37
|
inputSchema: ReadFileInputSchema,
|
|
38
38
|
presentation: {
|
|
39
39
|
describeHeader: (input) => (0, import_core.createLocalToolCallHeader)({
|
package/dist/read-file-tool.js
CHANGED
|
@@ -10,7 +10,7 @@ function createReadFileTool(getFileSystemService) {
|
|
|
10
10
|
return defineTool({
|
|
11
11
|
id: "read_file",
|
|
12
12
|
aliases: ["read"],
|
|
13
|
-
description: "Read the contents of a file with optional pagination. Returns file content, line count, encoding, and whether the output was truncated. Use limit and offset parameters for large files to read specific sections.
|
|
13
|
+
description: "Read the UTF-8 text contents of a file with optional pagination. Returns file content, line count, encoding, MIME type, and whether the output was truncated. Use limit and offset parameters for large files to read specific sections. Use read_media_file for image, audio, video, PDF, and other binary files.",
|
|
14
14
|
inputSchema: ReadFileInputSchema,
|
|
15
15
|
presentation: {
|
|
16
16
|
describeHeader: (input) => createLocalToolCallHeader({
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var read_media_file_tool_exports = {};
|
|
20
|
+
__export(read_media_file_tool_exports, {
|
|
21
|
+
createReadMediaFileTool: () => createReadMediaFileTool
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(read_media_file_tool_exports);
|
|
24
|
+
var import_zod = require("zod");
|
|
25
|
+
var import_core = require("@dexto/core");
|
|
26
|
+
var import_directory_approval = require("./directory-approval.js");
|
|
27
|
+
const ReadMediaFileInputSchema = import_zod.z.object({
|
|
28
|
+
file_path: import_zod.z.string().min(1).describe("Absolute path to the image, audio, video, PDF, or binary file to read")
|
|
29
|
+
}).strict();
|
|
30
|
+
function createReadMediaFileTool(getFileSystemService) {
|
|
31
|
+
return (0, import_core.defineTool)({
|
|
32
|
+
id: "read_media_file",
|
|
33
|
+
aliases: ["read_media"],
|
|
34
|
+
description: "Read an image, audio, video, PDF, or other binary file. Returns MIME-aware base64 data using media/file shapes that multimodal UIs can render directly. Use read_file for UTF-8 text files.",
|
|
35
|
+
inputSchema: ReadMediaFileInputSchema,
|
|
36
|
+
presentation: {
|
|
37
|
+
describeHeader: (input) => (0, import_core.createLocalToolCallHeader)({
|
|
38
|
+
title: "Read Media",
|
|
39
|
+
argsText: (0, import_core.truncateForHeader)(input.file_path, 140)
|
|
40
|
+
})
|
|
41
|
+
},
|
|
42
|
+
...(0, import_directory_approval.createDirectoryAccessApprovalHandlers)({
|
|
43
|
+
toolName: "read_media_file",
|
|
44
|
+
operation: "read",
|
|
45
|
+
inputSchema: ReadMediaFileInputSchema,
|
|
46
|
+
getFileSystemService,
|
|
47
|
+
resolvePaths: (input, fileSystemService) => (0, import_directory_approval.resolveFilePath)(fileSystemService.getWorkingDirectory(), input.file_path)
|
|
48
|
+
}),
|
|
49
|
+
async execute(input, context) {
|
|
50
|
+
const resolvedFileSystemService = await getFileSystemService(context);
|
|
51
|
+
const { file_path } = input;
|
|
52
|
+
const { path: resolvedPath } = (0, import_directory_approval.resolveFilePath)(
|
|
53
|
+
resolvedFileSystemService.getWorkingDirectory(),
|
|
54
|
+
file_path
|
|
55
|
+
);
|
|
56
|
+
const result = await resolvedFileSystemService.readMediaFile(resolvedPath);
|
|
57
|
+
const _display = {
|
|
58
|
+
type: "file",
|
|
59
|
+
path: resolvedPath,
|
|
60
|
+
operation: "read",
|
|
61
|
+
size: result.size
|
|
62
|
+
};
|
|
63
|
+
const item = result.kind === "image" ? {
|
|
64
|
+
type: "image",
|
|
65
|
+
data: result.data,
|
|
66
|
+
mimeType: result.mimeType,
|
|
67
|
+
filename: result.filename
|
|
68
|
+
} : {
|
|
69
|
+
type: "file",
|
|
70
|
+
data: result.data,
|
|
71
|
+
mimeType: result.mimeType,
|
|
72
|
+
filename: result.filename
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
content: [item],
|
|
76
|
+
mimeType: result.mimeType,
|
|
77
|
+
filename: result.filename,
|
|
78
|
+
size: result.size,
|
|
79
|
+
_display
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
+
0 && (module.exports = {
|
|
86
|
+
createReadMediaFileTool
|
|
87
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read Media File Tool
|
|
3
|
+
*
|
|
4
|
+
* Internal tool for reading media or binary files as base64 with MIME metadata.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import type { Tool } from '@dexto/core';
|
|
8
|
+
import type { FileSystemServiceGetter } from './file-tool-types.js';
|
|
9
|
+
declare const ReadMediaFileInputSchema: z.ZodObject<{
|
|
10
|
+
file_path: z.ZodString;
|
|
11
|
+
}, "strict", z.ZodTypeAny, {
|
|
12
|
+
file_path: string;
|
|
13
|
+
}, {
|
|
14
|
+
file_path: string;
|
|
15
|
+
}>;
|
|
16
|
+
export declare function createReadMediaFileTool(getFileSystemService: FileSystemServiceGetter): Tool<typeof ReadMediaFileInputSchema>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=read-media-file-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-media-file-tool.d.ts","sourceRoot":"","sources":["../src/read-media-file-tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAmB,IAAI,EAAwB,MAAM,aAAa,CAAC;AAC/E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAGpE,QAAA,MAAM,wBAAwB;;;;;;EAOjB,CAAC;AAEd,wBAAgB,uBAAuB,CACnC,oBAAoB,EAAE,uBAAuB,GAC9C,IAAI,CAAC,OAAO,wBAAwB,CAAC,CAkEvC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { createLocalToolCallHeader, defineTool, truncateForHeader } from "@dexto/core";
|
|
3
|
+
import { createDirectoryAccessApprovalHandlers, resolveFilePath } from "./directory-approval.js";
|
|
4
|
+
const ReadMediaFileInputSchema = z.object({
|
|
5
|
+
file_path: z.string().min(1).describe("Absolute path to the image, audio, video, PDF, or binary file to read")
|
|
6
|
+
}).strict();
|
|
7
|
+
function createReadMediaFileTool(getFileSystemService) {
|
|
8
|
+
return defineTool({
|
|
9
|
+
id: "read_media_file",
|
|
10
|
+
aliases: ["read_media"],
|
|
11
|
+
description: "Read an image, audio, video, PDF, or other binary file. Returns MIME-aware base64 data using media/file shapes that multimodal UIs can render directly. Use read_file for UTF-8 text files.",
|
|
12
|
+
inputSchema: ReadMediaFileInputSchema,
|
|
13
|
+
presentation: {
|
|
14
|
+
describeHeader: (input) => createLocalToolCallHeader({
|
|
15
|
+
title: "Read Media",
|
|
16
|
+
argsText: truncateForHeader(input.file_path, 140)
|
|
17
|
+
})
|
|
18
|
+
},
|
|
19
|
+
...createDirectoryAccessApprovalHandlers({
|
|
20
|
+
toolName: "read_media_file",
|
|
21
|
+
operation: "read",
|
|
22
|
+
inputSchema: ReadMediaFileInputSchema,
|
|
23
|
+
getFileSystemService,
|
|
24
|
+
resolvePaths: (input, fileSystemService) => resolveFilePath(fileSystemService.getWorkingDirectory(), input.file_path)
|
|
25
|
+
}),
|
|
26
|
+
async execute(input, context) {
|
|
27
|
+
const resolvedFileSystemService = await getFileSystemService(context);
|
|
28
|
+
const { file_path } = input;
|
|
29
|
+
const { path: resolvedPath } = resolveFilePath(
|
|
30
|
+
resolvedFileSystemService.getWorkingDirectory(),
|
|
31
|
+
file_path
|
|
32
|
+
);
|
|
33
|
+
const result = await resolvedFileSystemService.readMediaFile(resolvedPath);
|
|
34
|
+
const _display = {
|
|
35
|
+
type: "file",
|
|
36
|
+
path: resolvedPath,
|
|
37
|
+
operation: "read",
|
|
38
|
+
size: result.size
|
|
39
|
+
};
|
|
40
|
+
const item = result.kind === "image" ? {
|
|
41
|
+
type: "image",
|
|
42
|
+
data: result.data,
|
|
43
|
+
mimeType: result.mimeType,
|
|
44
|
+
filename: result.filename
|
|
45
|
+
} : {
|
|
46
|
+
type: "file",
|
|
47
|
+
data: result.data,
|
|
48
|
+
mimeType: result.mimeType,
|
|
49
|
+
filename: result.filename
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
content: [item],
|
|
53
|
+
mimeType: result.mimeType,
|
|
54
|
+
filename: result.filename,
|
|
55
|
+
size: result.size,
|
|
56
|
+
_display
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
export {
|
|
62
|
+
createReadMediaFileTool
|
|
63
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var import_vitest = require("vitest");
|
|
25
|
+
var path = __toESM(require("node:path"), 1);
|
|
26
|
+
var fs = __toESM(require("node:fs/promises"), 1);
|
|
27
|
+
var os = __toESM(require("node:os"), 1);
|
|
28
|
+
var import_filesystem_service = require("./filesystem-service.js");
|
|
29
|
+
var import_read_media_file_tool = require("./read-media-file-tool.js");
|
|
30
|
+
const createMockLogger = () => {
|
|
31
|
+
const logger = {
|
|
32
|
+
debug: import_vitest.vi.fn(),
|
|
33
|
+
silly: import_vitest.vi.fn(),
|
|
34
|
+
info: import_vitest.vi.fn(),
|
|
35
|
+
warn: import_vitest.vi.fn(),
|
|
36
|
+
error: import_vitest.vi.fn(),
|
|
37
|
+
trackException: import_vitest.vi.fn(),
|
|
38
|
+
createChild: import_vitest.vi.fn(() => logger),
|
|
39
|
+
createFileOnlyChild: import_vitest.vi.fn(() => logger),
|
|
40
|
+
setLevel: import_vitest.vi.fn(),
|
|
41
|
+
getLevel: import_vitest.vi.fn(() => "debug"),
|
|
42
|
+
getLogFilePath: import_vitest.vi.fn(() => null),
|
|
43
|
+
destroy: import_vitest.vi.fn(async () => void 0)
|
|
44
|
+
};
|
|
45
|
+
return logger;
|
|
46
|
+
};
|
|
47
|
+
function createToolContext(logger) {
|
|
48
|
+
return { logger };
|
|
49
|
+
}
|
|
50
|
+
(0, import_vitest.describe)("read_media_file tool", () => {
|
|
51
|
+
let mockLogger;
|
|
52
|
+
let tempDir;
|
|
53
|
+
let fileSystemService;
|
|
54
|
+
(0, import_vitest.beforeEach)(async () => {
|
|
55
|
+
mockLogger = createMockLogger();
|
|
56
|
+
const rawTempDir = await fs.mkdtemp(path.join(os.tmpdir(), "dexto-read-media-test-"));
|
|
57
|
+
tempDir = await fs.realpath(rawTempDir);
|
|
58
|
+
fileSystemService = new import_filesystem_service.FileSystemService(
|
|
59
|
+
{
|
|
60
|
+
allowedPaths: [tempDir],
|
|
61
|
+
blockedPaths: [],
|
|
62
|
+
blockedExtensions: [],
|
|
63
|
+
maxFileSize: 10 * 1024 * 1024,
|
|
64
|
+
workingDirectory: tempDir,
|
|
65
|
+
enableBackups: false,
|
|
66
|
+
backupRetentionDays: 7
|
|
67
|
+
},
|
|
68
|
+
mockLogger
|
|
69
|
+
);
|
|
70
|
+
await fileSystemService.initialize();
|
|
71
|
+
});
|
|
72
|
+
(0, import_vitest.afterEach)(async () => {
|
|
73
|
+
try {
|
|
74
|
+
await fs.rm(tempDir, { recursive: true, force: true });
|
|
75
|
+
} catch {
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
(0, import_vitest.it)("returns image content items for images", async () => {
|
|
79
|
+
const tool = (0, import_read_media_file_tool.createReadMediaFileTool)(async () => fileSystemService);
|
|
80
|
+
const filePath = path.join(tempDir, "poster.png");
|
|
81
|
+
const buffer = Buffer.from([137, 80, 78, 71, 0, 1]);
|
|
82
|
+
await fs.writeFile(filePath, buffer);
|
|
83
|
+
const result = await tool.execute(
|
|
84
|
+
{ file_path: filePath },
|
|
85
|
+
createToolContext(mockLogger)
|
|
86
|
+
);
|
|
87
|
+
(0, import_vitest.expect)(result.mimeType).toBe("image/png");
|
|
88
|
+
(0, import_vitest.expect)(result.content).toEqual([
|
|
89
|
+
{
|
|
90
|
+
type: "image",
|
|
91
|
+
data: buffer.toString("base64"),
|
|
92
|
+
mimeType: "image/png",
|
|
93
|
+
filename: "poster.png"
|
|
94
|
+
}
|
|
95
|
+
]);
|
|
96
|
+
});
|
|
97
|
+
(0, import_vitest.it)("returns file content items for audio, video, and document media", async () => {
|
|
98
|
+
const tool = (0, import_read_media_file_tool.createReadMediaFileTool)(async () => fileSystemService);
|
|
99
|
+
const cases = [
|
|
100
|
+
{
|
|
101
|
+
filename: "voice.mp3",
|
|
102
|
+
bytes: Buffer.from([73, 68, 51, 0]),
|
|
103
|
+
mimeType: "audio/mpeg"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
filename: "demo.mp4",
|
|
107
|
+
bytes: Buffer.from([0, 0, 0, 24, 102, 116, 121, 112]),
|
|
108
|
+
mimeType: "video/mp4"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
filename: "guide.pdf",
|
|
112
|
+
bytes: Buffer.from("%PDF-1.7"),
|
|
113
|
+
mimeType: "application/pdf"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
filename: "slides.pptx",
|
|
117
|
+
bytes: Buffer.from([80, 75, 3, 4]),
|
|
118
|
+
mimeType: "application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
filename: "sheet.xlsx",
|
|
122
|
+
bytes: Buffer.from([80, 75, 3, 4]),
|
|
123
|
+
mimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
filename: "report.docx",
|
|
127
|
+
bytes: Buffer.from([80, 75, 3, 4]),
|
|
128
|
+
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
|
129
|
+
}
|
|
130
|
+
];
|
|
131
|
+
for (const testCase of cases) {
|
|
132
|
+
const filePath = path.join(tempDir, testCase.filename);
|
|
133
|
+
await fs.writeFile(filePath, testCase.bytes);
|
|
134
|
+
const result = await tool.execute(
|
|
135
|
+
{ file_path: filePath },
|
|
136
|
+
createToolContext(mockLogger)
|
|
137
|
+
);
|
|
138
|
+
(0, import_vitest.expect)(result.mimeType).toBe(testCase.mimeType);
|
|
139
|
+
(0, import_vitest.expect)(result.filename).toBe(testCase.filename);
|
|
140
|
+
(0, import_vitest.expect)(result.content).toEqual([
|
|
141
|
+
{
|
|
142
|
+
type: "file",
|
|
143
|
+
data: testCase.bytes.toString("base64"),
|
|
144
|
+
mimeType: testCase.mimeType,
|
|
145
|
+
filename: testCase.filename
|
|
146
|
+
}
|
|
147
|
+
]);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-media-file-tool.test.d.ts","sourceRoot":"","sources":["../src/read-media-file-tool.test.ts"],"names":[],"mappings":""}
|