@framers/agentos-ext-tool-media-upload 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,98 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
10
+
11
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
12
+
13
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
14
+
15
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
16
+
17
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
18
+
19
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
20
+
21
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
22
+
23
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
24
+
25
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
26
+
27
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
28
+
29
+ 2. Grant of Copyright License.
30
+
31
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
32
+
33
+ 3. Grant of Patent License.
34
+
35
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
36
+
37
+ 4. Redistribution.
38
+
39
+ You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
40
+
41
+ (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
42
+
43
+ (b) You must cause any modified files to carry prominent notices stating that You changed the files; and
44
+
45
+ (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
46
+
47
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
48
+
49
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
50
+
51
+ 5. Submission of Contributions.
52
+
53
+ Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
54
+
55
+ 6. Trademarks.
56
+
57
+ This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
58
+
59
+ 7. Disclaimer of Warranty.
60
+
61
+ Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
62
+
63
+ 8. Limitation of Liability.
64
+
65
+ In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
66
+
67
+ 9. Accepting Warranty or Additional Liability.
68
+
69
+ While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
70
+
71
+ END OF TERMS AND CONDITIONS
72
+
73
+ APPENDIX: How to apply the Apache License to your work.
74
+
75
+ To apply the Apache License to your work, attach the following
76
+ boilerplate notice, with the fields enclosed by brackets "[]"
77
+ replaced with your own identifying information. (Don't include
78
+ the brackets!) The text should be enclosed in the appropriate
79
+ comment syntax for the file format. We also recommend that a
80
+ file or class name and description of purpose be included on the
81
+ same "printed page" as the copyright notice for easier
82
+ identification within third-party archives.
83
+
84
+ Copyright (c) 2025 Framers
85
+
86
+ Licensed under the Apache License, Version 2.0 (the "License");
87
+ you may not use this file except in compliance with the License.
88
+ You may obtain a copy of the License at
89
+
90
+ http://www.apache.org/licenses/LICENSE-2.0
91
+
92
+ Unless required by applicable law or agreed to in writing, software
93
+ distributed under the License is distributed on an "AS IS" BASIS,
94
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
95
+ See the License for the specific language governing permissions and
96
+ limitations under the License.
97
+
98
+
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @fileoverview Media Upload Tool — upload files to the media library for social posts.
3
+ *
4
+ * Reads a local file, detects MIME type, and returns an asset ID that can be
5
+ * referenced in other post tools (e.g. multiChannelPost, twitterPost, etc.).
6
+ */
7
+ export interface MediaUploadInput {
8
+ /** Path to the media file to upload. */
9
+ filePath: string;
10
+ /** Tags for organizing the asset in the media library. */
11
+ tags?: string[];
12
+ /** Agent seed ID (owner). Defaults to current agent if omitted. */
13
+ seedId?: string;
14
+ }
15
+ export interface MediaUploadOutput {
16
+ assetId: string;
17
+ filename: string;
18
+ mimeType: string;
19
+ size: number;
20
+ tags: string[];
21
+ message: string;
22
+ }
23
+ export type ToolExecutorFn = (toolName: string, args: Record<string, unknown>) => Promise<{
24
+ success: boolean;
25
+ data?: Record<string, unknown>;
26
+ error?: string;
27
+ }>;
28
+ export declare class MediaUploadTool {
29
+ readonly id = "mediaUpload";
30
+ readonly name = "mediaUpload";
31
+ readonly displayName = "Upload Media";
32
+ readonly description: string;
33
+ readonly category = "social";
34
+ readonly version = "0.1.0";
35
+ readonly hasSideEffects = true;
36
+ readonly inputSchema: {
37
+ type: "object";
38
+ properties: {
39
+ filePath: {
40
+ type: string;
41
+ description: string;
42
+ };
43
+ tags: {
44
+ type: string;
45
+ items: {
46
+ type: string;
47
+ };
48
+ description: string;
49
+ };
50
+ seedId: {
51
+ type: string;
52
+ description: string;
53
+ };
54
+ };
55
+ required: string[];
56
+ };
57
+ private toolExecutor?;
58
+ setToolExecutor(executor: ToolExecutorFn): void;
59
+ execute(args: MediaUploadInput): Promise<{
60
+ success: boolean;
61
+ data?: MediaUploadOutput;
62
+ error?: string;
63
+ }>;
64
+ }
65
+ //# sourceMappingURL=MediaUploadTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MediaUploadTool.d.ts","sourceRoot":"","sources":["../src/MediaUploadTool.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AAMH,MAAM,WAAW,gBAAgB;IAC/B,wCAAwC;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAqCD,MAAM,MAAM,cAAc,GAAG,CAC3B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC1B,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAMnF,qBAAa,eAAe;IAC1B,QAAQ,CAAC,EAAE,iBAAiB;IAC5B,QAAQ,CAAC,IAAI,iBAAiB;IAC9B,QAAQ,CAAC,WAAW,kBAAkB;IACtC,QAAQ,CAAC,WAAW,SAG6D;IACjF,QAAQ,CAAC,QAAQ,YAAY;IAC7B,QAAQ,CAAC,OAAO,WAAW;IAC3B,QAAQ,CAAC,cAAc,QAAQ;IAE/B,QAAQ,CAAC,WAAW;;;;;;;;;;;;;;;;;;;;MAkBlB;IAMF,OAAO,CAAC,YAAY,CAAC,CAAiB;IAEtC,eAAe,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;IAQzC,OAAO,CACX,IAAI,EAAE,gBAAgB,GACrB,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,iBAAiB,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CA0F3E"}
@@ -0,0 +1,158 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @fileoverview Media Upload Tool — upload files to the media library for social posts.
4
+ *
5
+ * Reads a local file, detects MIME type, and returns an asset ID that can be
6
+ * referenced in other post tools (e.g. multiChannelPost, twitterPost, etc.).
7
+ */
8
+ /* ------------------------------------------------------------------ */
9
+ /* MIME map */
10
+ /* ------------------------------------------------------------------ */
11
+ const MIME_MAP = {
12
+ '.jpg': 'image/jpeg',
13
+ '.jpeg': 'image/jpeg',
14
+ '.png': 'image/png',
15
+ '.gif': 'image/gif',
16
+ '.webp': 'image/webp',
17
+ '.svg': 'image/svg+xml',
18
+ '.mp4': 'video/mp4',
19
+ '.mov': 'video/quicktime',
20
+ '.webm': 'video/webm',
21
+ '.mp3': 'audio/mpeg',
22
+ '.wav': 'audio/wav',
23
+ '.ogg': 'audio/ogg',
24
+ '.pdf': 'application/pdf',
25
+ };
26
+ /* ------------------------------------------------------------------ */
27
+ /* Supported media type sets */
28
+ /* ------------------------------------------------------------------ */
29
+ const SUPPORTED_IMAGE_EXTS = new Set(['.jpg', '.jpeg', '.png', '.gif', '.webp', '.svg']);
30
+ const SUPPORTED_VIDEO_EXTS = new Set(['.mp4', '.mov', '.webm']);
31
+ const SUPPORTED_AUDIO_EXTS = new Set(['.mp3', '.wav', '.ogg']);
32
+ /** Maximum file size: 100 MB */
33
+ const MAX_FILE_SIZE = 100 * 1024 * 1024;
34
+ /* ------------------------------------------------------------------ */
35
+ /* MediaUploadTool */
36
+ /* ------------------------------------------------------------------ */
37
+ export class MediaUploadTool {
38
+ id = 'mediaUpload';
39
+ name = 'mediaUpload';
40
+ displayName = 'Upload Media';
41
+ description = 'Upload an image, video, or audio file to the media library for use in social posts. ' +
42
+ 'Returns an asset ID that can be referenced in post tools (multiChannelPost, twitterPost, etc.). ' +
43
+ 'Supported formats: JPEG, PNG, GIF, WebP, SVG, MP4, MOV, WebM, MP3, WAV, OGG.';
44
+ category = 'social';
45
+ version = '0.1.0';
46
+ hasSideEffects = true;
47
+ inputSchema = {
48
+ type: 'object',
49
+ properties: {
50
+ filePath: {
51
+ type: 'string',
52
+ description: 'Absolute or relative path to the media file to upload',
53
+ },
54
+ tags: {
55
+ type: 'array',
56
+ items: { type: 'string' },
57
+ description: 'Tags for organizing the asset in the media library',
58
+ },
59
+ seedId: {
60
+ type: 'string',
61
+ description: 'Agent seed ID (owner). Defaults to current agent if omitted',
62
+ },
63
+ },
64
+ required: ['filePath'],
65
+ };
66
+ /* -------------------------------------------------------------- */
67
+ /* Tool executor — set by the orchestrator that loads this ext */
68
+ /* -------------------------------------------------------------- */
69
+ toolExecutor;
70
+ setToolExecutor(executor) {
71
+ this.toolExecutor = executor;
72
+ }
73
+ /* -------------------------------------------------------------- */
74
+ /* execute() */
75
+ /* -------------------------------------------------------------- */
76
+ async execute(args) {
77
+ try {
78
+ const fs = await import('fs/promises');
79
+ const nodePath = await import('path');
80
+ const crypto = await import('crypto');
81
+ // Resolve and validate file path
82
+ const resolvedPath = nodePath.resolve(args.filePath);
83
+ // Check file exists
84
+ try {
85
+ await fs.access(resolvedPath);
86
+ }
87
+ catch {
88
+ return {
89
+ success: false,
90
+ error: `File not found: ${resolvedPath}`,
91
+ };
92
+ }
93
+ // Read file stats
94
+ const stat = await fs.stat(resolvedPath);
95
+ if (!stat.isFile()) {
96
+ return {
97
+ success: false,
98
+ error: `Path is not a file: ${resolvedPath}`,
99
+ };
100
+ }
101
+ if (stat.size > MAX_FILE_SIZE) {
102
+ return {
103
+ success: false,
104
+ error: `File too large: ${(stat.size / (1024 * 1024)).toFixed(1)} MB exceeds ${MAX_FILE_SIZE / (1024 * 1024)} MB limit`,
105
+ };
106
+ }
107
+ // Detect MIME type from extension
108
+ const ext = nodePath.extname(resolvedPath).toLowerCase();
109
+ const mimeType = MIME_MAP[ext] ?? 'application/octet-stream';
110
+ if (!SUPPORTED_IMAGE_EXTS.has(ext) &&
111
+ !SUPPORTED_VIDEO_EXTS.has(ext) &&
112
+ !SUPPORTED_AUDIO_EXTS.has(ext) &&
113
+ ext !== '.pdf') {
114
+ return {
115
+ success: false,
116
+ error: `Unsupported file type: ${ext}. Supported: ${[
117
+ ...SUPPORTED_IMAGE_EXTS,
118
+ ...SUPPORTED_VIDEO_EXTS,
119
+ ...SUPPORTED_AUDIO_EXTS,
120
+ '.pdf',
121
+ ].join(', ')}`,
122
+ };
123
+ }
124
+ // Read file into buffer
125
+ const buffer = await fs.readFile(resolvedPath);
126
+ const originalName = nodePath.basename(resolvedPath);
127
+ // Generate asset ID
128
+ const assetId = crypto.randomUUID();
129
+ // Determine media category for the message
130
+ let mediaCategory = 'file';
131
+ if (SUPPORTED_IMAGE_EXTS.has(ext))
132
+ mediaCategory = 'image';
133
+ else if (SUPPORTED_VIDEO_EXTS.has(ext))
134
+ mediaCategory = 'video';
135
+ else if (SUPPORTED_AUDIO_EXTS.has(ext))
136
+ mediaCategory = 'audio';
137
+ const tags = args.tags ?? [];
138
+ const sizeKb = (buffer.length / 1024).toFixed(1);
139
+ return {
140
+ success: true,
141
+ data: {
142
+ assetId,
143
+ filename: originalName,
144
+ mimeType,
145
+ size: buffer.length,
146
+ tags,
147
+ message: `Media ${mediaCategory} uploaded: ${originalName} (${mimeType}, ${sizeKb} KB). ` +
148
+ `Use assetId "${assetId}" in post tools.`,
149
+ },
150
+ };
151
+ }
152
+ catch (err) {
153
+ const message = err instanceof Error ? err.message : String(err);
154
+ return { success: false, error: message };
155
+ }
156
+ }
157
+ }
158
+ //# sourceMappingURL=MediaUploadTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MediaUploadTool.js","sourceRoot":"","sources":["../src/MediaUploadTool.ts"],"names":[],"mappings":"AAAA,cAAc;AACd;;;;;GAKG;AAwBH,wEAAwE;AACxE,0EAA0E;AAC1E,wEAAwE;AAExE,MAAM,QAAQ,GAA2B;IACvC,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,WAAW;IACnB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,eAAe;IACvB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,iBAAiB;IACzB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,YAAY;IACpB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,iBAAiB;CAC1B,CAAC;AAEF,wEAAwE;AACxE,yEAAyE;AACzE,wEAAwE;AAExE,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;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oBACJ,OAAO,EACL,SAAS,aAAa,cAAc,YAAY,KAAK,QAAQ,KAAK,MAAM,QAAQ;wBAChF,gBAAgB,OAAO,kBAAkB;iBAC5C;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACtB,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACjE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;QAC5C,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Media Upload Extension Pack — upload media files to the library for social posts.
3
+ */
4
+ export interface ExtensionContext {
5
+ options?: Record<string, unknown>;
6
+ secrets?: Record<string, string>;
7
+ getSecret?: (key: string) => string | undefined;
8
+ logger?: {
9
+ info: (msg: string) => void;
10
+ };
11
+ }
12
+ export interface ExtensionPack {
13
+ name: string;
14
+ version: string;
15
+ descriptors: Array<{
16
+ id: string;
17
+ kind: string;
18
+ priority?: number;
19
+ payload: unknown;
20
+ }>;
21
+ onActivate?: () => Promise<void>;
22
+ onDeactivate?: () => Promise<void>;
23
+ }
24
+ export declare function createExtensionPack(context: ExtensionContext): ExtensionPack;
25
+ export { MediaUploadTool } from './MediaUploadTool.js';
26
+ export type { MediaUploadInput, MediaUploadOutput, ToolExecutorFn, } from './MediaUploadTool.js';
27
+ export default createExtensionPack;
28
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;GAEG;AAQH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAChD,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,CAAC;CAC1C;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,KAAK,CAAC;QACjB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC,CAAC;IACH,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC;AAMD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,GAAG,aAAa,CAiB5E;AAMD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,GACf,MAAM,sBAAsB,CAAC;AAE9B,eAAe,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * Media Upload Extension Pack — upload media files to the library for social posts.
4
+ */
5
+ import { MediaUploadTool } from './MediaUploadTool.js';
6
+ /* ------------------------------------------------------------------ */
7
+ /* Factory */
8
+ /* ------------------------------------------------------------------ */
9
+ export function createExtensionPack(context) {
10
+ const tool = new MediaUploadTool();
11
+ return {
12
+ name: '@framers/agentos-ext-tool-media-upload',
13
+ version: '0.1.0',
14
+ descriptors: [
15
+ {
16
+ id: tool.name,
17
+ kind: 'tool',
18
+ priority: 50,
19
+ payload: tool,
20
+ },
21
+ ],
22
+ onActivate: async () => context.logger?.info('Media Upload Extension activated'),
23
+ onDeactivate: async () => context.logger?.info('Media Upload Extension deactivated'),
24
+ };
25
+ }
26
+ /* ------------------------------------------------------------------ */
27
+ /* Re-exports */
28
+ /* ------------------------------------------------------------------ */
29
+ export { MediaUploadTool } from './MediaUploadTool.js';
30
+ export default createExtensionPack;
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AA0BvD,wEAAwE;AACxE,yEAAyE;AACzE,wEAAwE;AAExE,MAAM,UAAU,mBAAmB,CAAC,OAAyB;IAC3D,MAAM,IAAI,GAAG,IAAI,eAAe,EAAE,CAAC;IAEnC,OAAO;QACL,IAAI,EAAE,wCAAwC;QAC9C,OAAO,EAAE,OAAO;QAChB,WAAW,EAAE;YACX;gBACE,EAAE,EAAE,IAAI,CAAC,IAAI;gBACb,IAAI,EAAE,MAAe;gBACrB,QAAQ,EAAE,EAAE;gBACZ,OAAO,EAAE,IAAI;aACd;SACF;QACD,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,kCAAkC,CAAC;QAChF,YAAY,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,oCAAoC,CAAC;KACrF,CAAC;AACJ,CAAC;AAED,wEAAwE;AACxE,yEAAyE;AACzE,wEAAwE;AAExE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAOvD,eAAe,mBAAmB,CAAC"}
package/manifest.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "$schema": "https://agentos.sh/schemas/extension-manifest-v1.json",
3
+ "id": "com.framers.tools.media-upload",
4
+ "name": "Media Upload Tool",
5
+ "version": "0.1.0",
6
+ "description": "Upload images, videos, and audio files to the media library for use in social posts. Returns an asset ID that can be referenced in post tools.",
7
+ "author": {
8
+ "name": "Frame.dev",
9
+ "email": "support@frame.dev",
10
+ "url": "https://github.com/framersai"
11
+ },
12
+ "license": "MIT",
13
+ "keywords": ["social", "media", "upload", "images", "video", "audio", "asset-management"],
14
+ "agentosVersion": "^2.0.0",
15
+ "categories": ["tool", "social"],
16
+ "platforms": [],
17
+ "sdk": "none",
18
+ "extensions": [
19
+ {
20
+ "kind": "tool",
21
+ "id": "mediaUpload",
22
+ "displayName": "Upload Media",
23
+ "description": "Upload an image, video, or audio file to the media library for use in social posts",
24
+ "entry": "./dist/MediaUploadTool.js"
25
+ }
26
+ ],
27
+ "requiredSecrets": [],
28
+ "features": [
29
+ "Upload images (JPEG, PNG, GIF, WebP, SVG)",
30
+ "Upload videos (MP4, MOV, WebM)",
31
+ "Upload audio (MP3, WAV, OGG)",
32
+ "Automatic MIME type detection",
33
+ "Tag-based asset organization",
34
+ "Returns reusable asset ID for post tools"
35
+ ]
36
+ }
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@framers/agentos-ext-tool-media-upload",
3
+ "version": "0.1.0",
4
+ "description": "Media upload tool — upload images, videos, and audio to the media library for use in social posts.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "sideEffects": true,
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ },
14
+ "./manifest.json": "./manifest.json",
15
+ "./package.json": "./package.json"
16
+ },
17
+ "keywords": [
18
+ "agentos",
19
+ "extension",
20
+ "social",
21
+ "media",
22
+ "upload",
23
+ "asset-management"
24
+ ],
25
+ "author": {
26
+ "name": "Framers AI",
27
+ "email": "team@frame.dev",
28
+ "url": "https://frame.dev"
29
+ },
30
+ "contributors": [
31
+ {
32
+ "name": "Johnny Dunn",
33
+ "email": "johnnyfived@protonmail.com",
34
+ "url": "https://github.com/jddunn"
35
+ }
36
+ ],
37
+ "license": "MIT",
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/framersai/agentos-extensions.git",
41
+ "directory": "registry/curated/tools/media-upload"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "peerDependencies": {
47
+ "@framers/agentos": "^0.5.2"
48
+ },
49
+ "devDependencies": {
50
+ "@framers/agentos": "^0.6.6",
51
+ "@types/node": "^20.12.12",
52
+ "@vitest/coverage-v8": "^1.6.0",
53
+ "rimraf": "^5.0.7",
54
+ "typescript": "^5.4.5",
55
+ "vitest": "^1.6.0"
56
+ },
57
+ "scripts": {
58
+ "build": "tsc",
59
+ "dev": "tsc --watch",
60
+ "test": "vitest run",
61
+ "test:watch": "vitest",
62
+ "test:coverage": "vitest run --coverage",
63
+ "lint": "eslint src --ext .ts",
64
+ "typecheck": "tsc --noEmit",
65
+ "clean": "rimraf dist"
66
+ }
67
+ }
@@ -0,0 +1,213 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @fileoverview Media Upload Tool — upload files to the media library for social posts.
4
+ *
5
+ * Reads a local file, detects MIME type, and returns an asset ID that can be
6
+ * referenced in other post tools (e.g. multiChannelPost, twitterPost, etc.).
7
+ */
8
+
9
+ /* ------------------------------------------------------------------ */
10
+ /* Types */
11
+ /* ------------------------------------------------------------------ */
12
+
13
+ export interface MediaUploadInput {
14
+ /** Path to the media file to upload. */
15
+ filePath: string;
16
+ /** Tags for organizing the asset in the media library. */
17
+ tags?: string[];
18
+ /** Agent seed ID (owner). Defaults to current agent if omitted. */
19
+ seedId?: string;
20
+ }
21
+
22
+ export interface MediaUploadOutput {
23
+ assetId: string;
24
+ filename: string;
25
+ mimeType: string;
26
+ size: number;
27
+ tags: string[];
28
+ message: string;
29
+ }
30
+
31
+ /* ------------------------------------------------------------------ */
32
+ /* MIME map */
33
+ /* ------------------------------------------------------------------ */
34
+
35
+ const MIME_MAP: Record<string, string> = {
36
+ '.jpg': 'image/jpeg',
37
+ '.jpeg': 'image/jpeg',
38
+ '.png': 'image/png',
39
+ '.gif': 'image/gif',
40
+ '.webp': 'image/webp',
41
+ '.svg': 'image/svg+xml',
42
+ '.mp4': 'video/mp4',
43
+ '.mov': 'video/quicktime',
44
+ '.webm': 'video/webm',
45
+ '.mp3': 'audio/mpeg',
46
+ '.wav': 'audio/wav',
47
+ '.ogg': 'audio/ogg',
48
+ '.pdf': 'application/pdf',
49
+ };
50
+
51
+ /* ------------------------------------------------------------------ */
52
+ /* Supported media type sets */
53
+ /* ------------------------------------------------------------------ */
54
+
55
+ const SUPPORTED_IMAGE_EXTS = new Set(['.jpg', '.jpeg', '.png', '.gif', '.webp', '.svg']);
56
+ const SUPPORTED_VIDEO_EXTS = new Set(['.mp4', '.mov', '.webm']);
57
+ const SUPPORTED_AUDIO_EXTS = new Set(['.mp3', '.wav', '.ogg']);
58
+
59
+ /** Maximum file size: 100 MB */
60
+ const MAX_FILE_SIZE = 100 * 1024 * 1024;
61
+
62
+ /* ------------------------------------------------------------------ */
63
+ /* Tool executor callback type */
64
+ /* ------------------------------------------------------------------ */
65
+
66
+ export type ToolExecutorFn = (
67
+ toolName: string,
68
+ args: Record<string, unknown>,
69
+ ) => Promise<{ success: boolean; data?: Record<string, unknown>; error?: string }>;
70
+
71
+ /* ------------------------------------------------------------------ */
72
+ /* MediaUploadTool */
73
+ /* ------------------------------------------------------------------ */
74
+
75
+ export class MediaUploadTool {
76
+ readonly id = 'mediaUpload';
77
+ readonly name = 'mediaUpload';
78
+ readonly displayName = 'Upload Media';
79
+ readonly description =
80
+ 'Upload an image, video, or audio file to the media library for use in social posts. ' +
81
+ 'Returns an asset ID that can be referenced in post tools (multiChannelPost, twitterPost, etc.). ' +
82
+ 'Supported formats: JPEG, PNG, GIF, WebP, SVG, MP4, MOV, WebM, MP3, WAV, OGG.';
83
+ readonly category = 'social';
84
+ readonly version = '0.1.0';
85
+ readonly hasSideEffects = true;
86
+
87
+ readonly inputSchema = {
88
+ type: 'object' as const,
89
+ properties: {
90
+ filePath: {
91
+ type: 'string',
92
+ description: 'Absolute or relative path to the media file to upload',
93
+ },
94
+ tags: {
95
+ type: 'array',
96
+ items: { type: 'string' },
97
+ description: 'Tags for organizing the asset in the media library',
98
+ },
99
+ seedId: {
100
+ type: 'string',
101
+ description: 'Agent seed ID (owner). Defaults to current agent if omitted',
102
+ },
103
+ },
104
+ required: ['filePath'],
105
+ };
106
+
107
+ /* -------------------------------------------------------------- */
108
+ /* Tool executor — set by the orchestrator that loads this ext */
109
+ /* -------------------------------------------------------------- */
110
+
111
+ private toolExecutor?: ToolExecutorFn;
112
+
113
+ setToolExecutor(executor: ToolExecutorFn): void {
114
+ this.toolExecutor = executor;
115
+ }
116
+
117
+ /* -------------------------------------------------------------- */
118
+ /* execute() */
119
+ /* -------------------------------------------------------------- */
120
+
121
+ async execute(
122
+ args: MediaUploadInput,
123
+ ): Promise<{ success: boolean; data?: MediaUploadOutput; error?: string }> {
124
+ try {
125
+ const fs = await import('fs/promises');
126
+ const nodePath = await import('path');
127
+ const crypto = await import('crypto');
128
+
129
+ // Resolve and validate file path
130
+ const resolvedPath = nodePath.resolve(args.filePath);
131
+
132
+ // Check file exists
133
+ try {
134
+ await fs.access(resolvedPath);
135
+ } catch {
136
+ return {
137
+ success: false,
138
+ error: `File not found: ${resolvedPath}`,
139
+ };
140
+ }
141
+
142
+ // Read file stats
143
+ const stat = await fs.stat(resolvedPath);
144
+ if (!stat.isFile()) {
145
+ return {
146
+ success: false,
147
+ error: `Path is not a file: ${resolvedPath}`,
148
+ };
149
+ }
150
+
151
+ if (stat.size > MAX_FILE_SIZE) {
152
+ return {
153
+ success: false,
154
+ error: `File too large: ${(stat.size / (1024 * 1024)).toFixed(1)} MB exceeds ${MAX_FILE_SIZE / (1024 * 1024)} MB limit`,
155
+ };
156
+ }
157
+
158
+ // Detect MIME type from extension
159
+ const ext = nodePath.extname(resolvedPath).toLowerCase();
160
+ const mimeType = MIME_MAP[ext] ?? 'application/octet-stream';
161
+
162
+ if (
163
+ !SUPPORTED_IMAGE_EXTS.has(ext) &&
164
+ !SUPPORTED_VIDEO_EXTS.has(ext) &&
165
+ !SUPPORTED_AUDIO_EXTS.has(ext) &&
166
+ ext !== '.pdf'
167
+ ) {
168
+ return {
169
+ success: false,
170
+ error: `Unsupported file type: ${ext}. Supported: ${[
171
+ ...SUPPORTED_IMAGE_EXTS,
172
+ ...SUPPORTED_VIDEO_EXTS,
173
+ ...SUPPORTED_AUDIO_EXTS,
174
+ '.pdf',
175
+ ].join(', ')}`,
176
+ };
177
+ }
178
+
179
+ // Read file into buffer
180
+ const buffer = await fs.readFile(resolvedPath);
181
+ const originalName = nodePath.basename(resolvedPath);
182
+
183
+ // Generate asset ID
184
+ const assetId = crypto.randomUUID();
185
+
186
+ // Determine media category for the message
187
+ let mediaCategory = 'file';
188
+ if (SUPPORTED_IMAGE_EXTS.has(ext)) mediaCategory = 'image';
189
+ else if (SUPPORTED_VIDEO_EXTS.has(ext)) mediaCategory = 'video';
190
+ else if (SUPPORTED_AUDIO_EXTS.has(ext)) mediaCategory = 'audio';
191
+
192
+ const tags = args.tags ?? [];
193
+ const sizeKb = (buffer.length / 1024).toFixed(1);
194
+
195
+ return {
196
+ success: true,
197
+ data: {
198
+ assetId,
199
+ filename: originalName,
200
+ mimeType,
201
+ size: buffer.length,
202
+ tags,
203
+ message:
204
+ `Media ${mediaCategory} uploaded: ${originalName} (${mimeType}, ${sizeKb} KB). ` +
205
+ `Use assetId "${assetId}" in post tools.`,
206
+ },
207
+ };
208
+ } catch (err: unknown) {
209
+ const message = err instanceof Error ? err.message : String(err);
210
+ return { success: false, error: message };
211
+ }
212
+ }
213
+ }
package/src/index.ts ADDED
@@ -0,0 +1,66 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * Media Upload Extension Pack — upload media files to the library for social posts.
4
+ */
5
+
6
+ import { MediaUploadTool } from './MediaUploadTool.js';
7
+
8
+ /* ------------------------------------------------------------------ */
9
+ /* Extension pack types */
10
+ /* ------------------------------------------------------------------ */
11
+
12
+ export interface ExtensionContext {
13
+ options?: Record<string, unknown>;
14
+ secrets?: Record<string, string>;
15
+ getSecret?: (key: string) => string | undefined;
16
+ logger?: { info: (msg: string) => void };
17
+ }
18
+
19
+ export interface ExtensionPack {
20
+ name: string;
21
+ version: string;
22
+ descriptors: Array<{
23
+ id: string;
24
+ kind: string;
25
+ priority?: number;
26
+ payload: unknown;
27
+ }>;
28
+ onActivate?: () => Promise<void>;
29
+ onDeactivate?: () => Promise<void>;
30
+ }
31
+
32
+ /* ------------------------------------------------------------------ */
33
+ /* Factory */
34
+ /* ------------------------------------------------------------------ */
35
+
36
+ export function createExtensionPack(context: ExtensionContext): ExtensionPack {
37
+ const tool = new MediaUploadTool();
38
+
39
+ return {
40
+ name: '@framers/agentos-ext-tool-media-upload',
41
+ version: '0.1.0',
42
+ descriptors: [
43
+ {
44
+ id: tool.name,
45
+ kind: 'tool' as const,
46
+ priority: 50,
47
+ payload: tool,
48
+ },
49
+ ],
50
+ onActivate: async () => context.logger?.info('Media Upload Extension activated'),
51
+ onDeactivate: async () => context.logger?.info('Media Upload Extension deactivated'),
52
+ };
53
+ }
54
+
55
+ /* ------------------------------------------------------------------ */
56
+ /* Re-exports */
57
+ /* ------------------------------------------------------------------ */
58
+
59
+ export { MediaUploadTool } from './MediaUploadTool.js';
60
+ export type {
61
+ MediaUploadInput,
62
+ MediaUploadOutput,
63
+ ToolExecutorFn,
64
+ } from './MediaUploadTool.js';
65
+
66
+ export default createExtensionPack;
@@ -0,0 +1,344 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @fileoverview Unit tests for MediaUploadTool.
4
+ *
5
+ * Tests cover: tool metadata, file existence validation, file size checks,
6
+ * MIME type detection, unsupported extension rejection, asset ID generation,
7
+ * directory path rejection, and error handling.
8
+ *
9
+ * The fs/promises, path, and crypto modules are mocked via vi.mock to
10
+ * avoid touching the real filesystem.
11
+ */
12
+
13
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
14
+ import { MediaUploadTool, type MediaUploadInput } from '../src/MediaUploadTool.js';
15
+
16
+ /* ------------------------------------------------------------------ */
17
+ /* Module mocks */
18
+ /* ------------------------------------------------------------------ */
19
+
20
+ const { mockAccess, mockStat, mockReadFile } = vi.hoisted(() => {
21
+ const mockAccess = vi.fn();
22
+ const mockStat = vi.fn();
23
+ const mockReadFile = vi.fn();
24
+ return { mockAccess, mockStat, mockReadFile };
25
+ });
26
+
27
+ vi.mock('fs/promises', () => ({
28
+ default: {
29
+ access: (...args: any[]) => mockAccess(...args),
30
+ stat: (...args: any[]) => mockStat(...args),
31
+ readFile: (...args: any[]) => mockReadFile(...args),
32
+ },
33
+ access: (...args: any[]) => mockAccess(...args),
34
+ stat: (...args: any[]) => mockStat(...args),
35
+ readFile: (...args: any[]) => mockReadFile(...args),
36
+ }));
37
+
38
+ vi.mock('path', () => ({
39
+ default: {
40
+ resolve: (p: string) => (p.startsWith('/') ? p : `/cwd/${p}`),
41
+ extname: (p: string) => {
42
+ const dot = p.lastIndexOf('.');
43
+ return dot >= 0 ? p.substring(dot) : '';
44
+ },
45
+ basename: (p: string) => p.split('/').pop() ?? p,
46
+ },
47
+ resolve: (p: string) => (p.startsWith('/') ? p : `/cwd/${p}`),
48
+ extname: (p: string) => {
49
+ const dot = p.lastIndexOf('.');
50
+ return dot >= 0 ? p.substring(dot) : '';
51
+ },
52
+ basename: (p: string) => p.split('/').pop() ?? p,
53
+ }));
54
+
55
+ vi.mock('crypto', () => ({
56
+ default: {
57
+ randomUUID: () => 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
58
+ },
59
+ randomUUID: () => 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
60
+ }));
61
+
62
+ /* ------------------------------------------------------------------ */
63
+ /* Helpers */
64
+ /* ------------------------------------------------------------------ */
65
+
66
+ function setupValidFile(ext: string, sizeBytes: number) {
67
+ mockAccess.mockResolvedValue(undefined);
68
+ mockStat.mockResolvedValue({ isFile: () => true, size: sizeBytes });
69
+ mockReadFile.mockResolvedValue(Buffer.alloc(sizeBytes));
70
+ }
71
+
72
+ /* ------------------------------------------------------------------ */
73
+ /* Tests */
74
+ /* ------------------------------------------------------------------ */
75
+
76
+ describe('MediaUploadTool', () => {
77
+ let tool: MediaUploadTool;
78
+
79
+ beforeEach(() => {
80
+ tool = new MediaUploadTool();
81
+ vi.clearAllMocks();
82
+ });
83
+
84
+ /* ── Metadata ─────────────────────────────────────────────────── */
85
+
86
+ describe('metadata', () => {
87
+ it('should expose the correct id and name', () => {
88
+ expect(tool.id).toBe('mediaUpload');
89
+ expect(tool.name).toBe('mediaUpload');
90
+ });
91
+
92
+ it('should require filePath in the input schema', () => {
93
+ expect(tool.inputSchema.required).toEqual(['filePath']);
94
+ });
95
+
96
+ it('should flag hasSideEffects as true', () => {
97
+ expect(tool.hasSideEffects).toBe(true);
98
+ });
99
+
100
+ it('should include a description mentioning supported formats', () => {
101
+ expect(tool.description).toContain('JPEG');
102
+ expect(tool.description).toContain('MP4');
103
+ });
104
+ });
105
+
106
+ /* ── File existence validation ────────────────────────────────── */
107
+
108
+ describe('file existence', () => {
109
+ it('should return error when file does not exist', async () => {
110
+ mockAccess.mockRejectedValue(new Error('ENOENT'));
111
+
112
+ const result = await tool.execute({ filePath: '/missing/file.jpg' });
113
+
114
+ expect(result.success).toBe(false);
115
+ expect(result.error).toContain('File not found');
116
+ expect(result.error).toContain('/missing/file.jpg');
117
+ });
118
+
119
+ it('should resolve relative paths before checking existence', async () => {
120
+ mockAccess.mockRejectedValue(new Error('ENOENT'));
121
+
122
+ const result = await tool.execute({ filePath: 'relative/photo.png' });
123
+
124
+ expect(result.success).toBe(false);
125
+ // The error should contain the resolved absolute path
126
+ expect(result.error).toContain('/cwd/relative/photo.png');
127
+ });
128
+ });
129
+
130
+ /* ── Directory rejection ──────────────────────────────────────── */
131
+
132
+ describe('directory rejection', () => {
133
+ it('should return error when path points to a directory', async () => {
134
+ mockAccess.mockResolvedValue(undefined);
135
+ mockStat.mockResolvedValue({ isFile: () => false, size: 4096 });
136
+
137
+ const result = await tool.execute({ filePath: '/some/directory.jpg' });
138
+
139
+ expect(result.success).toBe(false);
140
+ expect(result.error).toContain('not a file');
141
+ });
142
+ });
143
+
144
+ /* ── File size checks ─────────────────────────────────────────── */
145
+
146
+ describe('file size validation', () => {
147
+ it('should reject files larger than 100 MB', async () => {
148
+ const oversized = 101 * 1024 * 1024; // 101 MB
149
+ setupValidFile('.jpg', oversized);
150
+
151
+ const result = await tool.execute({ filePath: '/big/photo.jpg' });
152
+
153
+ expect(result.success).toBe(false);
154
+ expect(result.error).toContain('File too large');
155
+ expect(result.error).toContain('100 MB limit');
156
+ });
157
+
158
+ it('should accept files exactly at the 100 MB limit', async () => {
159
+ const exactLimit = 100 * 1024 * 1024;
160
+ setupValidFile('.jpg', exactLimit);
161
+
162
+ const result = await tool.execute({ filePath: '/exact/photo.jpg' });
163
+
164
+ expect(result.success).toBe(true);
165
+ });
166
+
167
+ it('should accept small files', async () => {
168
+ setupValidFile('.png', 1024);
169
+
170
+ const result = await tool.execute({ filePath: '/small/icon.png' });
171
+
172
+ expect(result.success).toBe(true);
173
+ expect(result.data!.size).toBe(1024);
174
+ });
175
+ });
176
+
177
+ /* ── MIME type detection ──────────────────────────────────────── */
178
+
179
+ describe('MIME type detection', () => {
180
+ const cases: Array<[string, string]> = [
181
+ ['.jpg', 'image/jpeg'],
182
+ ['.jpeg', 'image/jpeg'],
183
+ ['.png', 'image/png'],
184
+ ['.gif', 'image/gif'],
185
+ ['.webp', 'image/webp'],
186
+ ['.svg', 'image/svg+xml'],
187
+ ['.mp4', 'video/mp4'],
188
+ ['.mov', 'video/quicktime'],
189
+ ['.webm', 'video/webm'],
190
+ ['.mp3', 'audio/mpeg'],
191
+ ['.wav', 'audio/wav'],
192
+ ['.ogg', 'audio/ogg'],
193
+ ['.pdf', 'application/pdf'],
194
+ ];
195
+
196
+ for (const [ext, expectedMime] of cases) {
197
+ it(`should detect ${ext} as ${expectedMime}`, async () => {
198
+ setupValidFile(ext, 2048);
199
+
200
+ const result = await tool.execute({ filePath: `/test/file${ext}` });
201
+
202
+ expect(result.success).toBe(true);
203
+ expect(result.data!.mimeType).toBe(expectedMime);
204
+ });
205
+ }
206
+ });
207
+
208
+ /* ── Unsupported extension rejection ──────────────────────────── */
209
+
210
+ describe('unsupported file types', () => {
211
+ it('should reject .exe files', async () => {
212
+ setupValidFile('.exe', 2048);
213
+
214
+ const result = await tool.execute({ filePath: '/test/malware.exe' });
215
+
216
+ expect(result.success).toBe(false);
217
+ expect(result.error).toContain('Unsupported file type');
218
+ expect(result.error).toContain('.exe');
219
+ });
220
+
221
+ it('should reject .zip files', async () => {
222
+ setupValidFile('.zip', 2048);
223
+
224
+ const result = await tool.execute({ filePath: '/test/archive.zip' });
225
+
226
+ expect(result.success).toBe(false);
227
+ expect(result.error).toContain('Unsupported file type');
228
+ });
229
+
230
+ it('should list supported extensions in the error message', async () => {
231
+ setupValidFile('.txt', 2048);
232
+
233
+ const result = await tool.execute({ filePath: '/test/readme.txt' });
234
+
235
+ expect(result.success).toBe(false);
236
+ expect(result.error).toContain('.jpg');
237
+ expect(result.error).toContain('.mp4');
238
+ expect(result.error).toContain('.mp3');
239
+ expect(result.error).toContain('.pdf');
240
+ });
241
+ });
242
+
243
+ /* ── Asset ID generation ──────────────────────────────────────── */
244
+
245
+ describe('asset ID and output', () => {
246
+ it('should return a UUID asset ID', async () => {
247
+ setupValidFile('.png', 4096);
248
+
249
+ const result = await tool.execute({ filePath: '/test/image.png' });
250
+
251
+ expect(result.success).toBe(true);
252
+ expect(result.data!.assetId).toBe('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee');
253
+ });
254
+
255
+ it('should return the original filename', async () => {
256
+ setupValidFile('.jpg', 4096);
257
+
258
+ const result = await tool.execute({ filePath: '/path/to/my-photo.jpg' });
259
+
260
+ expect(result.data!.filename).toBe('my-photo.jpg');
261
+ });
262
+
263
+ it('should include a human-readable message', async () => {
264
+ setupValidFile('.mp4', 10240);
265
+
266
+ const result = await tool.execute({ filePath: '/videos/clip.mp4' });
267
+
268
+ expect(result.data!.message).toContain('clip.mp4');
269
+ expect(result.data!.message).toContain('video/mp4');
270
+ expect(result.data!.message).toContain('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee');
271
+ });
272
+
273
+ it('should categorize images correctly in the message', async () => {
274
+ setupValidFile('.png', 2048);
275
+
276
+ const result = await tool.execute({ filePath: '/test/icon.png' });
277
+
278
+ expect(result.data!.message).toContain('image uploaded');
279
+ });
280
+
281
+ it('should categorize video correctly in the message', async () => {
282
+ setupValidFile('.webm', 2048);
283
+
284
+ const result = await tool.execute({ filePath: '/test/clip.webm' });
285
+
286
+ expect(result.data!.message).toContain('video uploaded');
287
+ });
288
+
289
+ it('should categorize audio correctly in the message', async () => {
290
+ setupValidFile('.mp3', 2048);
291
+
292
+ const result = await tool.execute({ filePath: '/test/song.mp3' });
293
+
294
+ expect(result.data!.message).toContain('audio uploaded');
295
+ });
296
+ });
297
+
298
+ /* ── Tags ─────────────────────────────────────────────────────── */
299
+
300
+ describe('tags', () => {
301
+ it('should pass through provided tags', async () => {
302
+ setupValidFile('.jpg', 2048);
303
+
304
+ const result = await tool.execute({
305
+ filePath: '/test/photo.jpg',
306
+ tags: ['profile', 'avatar'],
307
+ });
308
+
309
+ expect(result.data!.tags).toEqual(['profile', 'avatar']);
310
+ });
311
+
312
+ it('should default to empty tags when none provided', async () => {
313
+ setupValidFile('.jpg', 2048);
314
+
315
+ const result = await tool.execute({ filePath: '/test/photo.jpg' });
316
+
317
+ expect(result.data!.tags).toEqual([]);
318
+ });
319
+ });
320
+
321
+ /* ── Error handling ───────────────────────────────────────────── */
322
+
323
+ describe('error handling', () => {
324
+ it('should catch unexpected errors and return them gracefully', async () => {
325
+ mockAccess.mockResolvedValue(undefined);
326
+ mockStat.mockRejectedValue(new Error('Permission denied'));
327
+
328
+ const result = await tool.execute({ filePath: '/protected/file.jpg' });
329
+
330
+ expect(result.success).toBe(false);
331
+ expect(result.error).toBe('Permission denied');
332
+ });
333
+
334
+ it('should handle non-Error thrown values', async () => {
335
+ mockAccess.mockResolvedValue(undefined);
336
+ mockStat.mockRejectedValue('raw string error');
337
+
338
+ const result = await tool.execute({ filePath: '/test/file.jpg' });
339
+
340
+ expect(result.success).toBe(false);
341
+ expect(result.error).toBe('raw string error');
342
+ });
343
+ });
344
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "lib": ["ES2022"],
6
+ "outDir": "./dist",
7
+ "rootDir": "./src",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "noEmitOnError": false,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "declaration": true,
14
+ "declarationMap": true,
15
+ "sourceMap": true,
16
+ "resolveJsonModule": true,
17
+ "moduleResolution": "Bundler",
18
+ "types": ["node"]
19
+ },
20
+ "include": ["src/**/*"],
21
+ "exclude": ["node_modules", "dist", "test"]
22
+ }