From 47c898333240361d7bffc9be46b2040335acb8bf Mon Sep 17 00:00:00 2001 From: Swapnil M Mane Date: Tue, 2 Dec 2025 13:59:00 +0530 Subject: [PATCH 1/3] feat: implementing AI image tagging Added the background task that will be trigger on file upload --- packages/api-file-manager/package.json | 1 + packages/api-file-manager/src/index.ts | 28 ++++++++++++++++--- .../src/tasks/createFileTaggingTask.ts | 28 +++++++++++++++++++ yarn.lock | 1 + 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 packages/api-file-manager/src/tasks/createFileTaggingTask.ts diff --git a/packages/api-file-manager/package.json b/packages/api-file-manager/package.json index 9067feca2fc..6f87b5e406a 100644 --- a/packages/api-file-manager/package.json +++ b/packages/api-file-manager/package.json @@ -22,6 +22,7 @@ "@webiny/api": "0.0.0", "@webiny/api-core": "0.0.0", "@webiny/api-headless-cms": "0.0.0", + "@webiny/api-websockets": "0.0.0", "@webiny/aws-sdk": "0.0.0", "@webiny/build-tools": "0.0.0", "@webiny/error": "0.0.0", diff --git a/packages/api-file-manager/src/index.ts b/packages/api-file-manager/src/index.ts index 425349e3a46..8e029d8a348 100644 --- a/packages/api-file-manager/src/index.ts +++ b/packages/api-file-manager/src/index.ts @@ -7,6 +7,7 @@ import { createGraphQLSchemaPlugin } from "./graphql/index.js"; import { applyThreatScanning } from "./enterprise/applyThreatScanning.js"; import type { FileManagerConfig } from "./createFileManager/types.js"; import { FileManagerFeature } from "~/features/FileManagerFeature.js"; +import { createFileTaggingTask } from "./tasks/createFileTaggingTask.js"; export * from "./modelModifier/CmsModelModifier.js"; export * from "./plugins/index.js"; @@ -15,7 +16,7 @@ export * from "./delivery/index.js"; export const createFileManagerContext = ({ storageOperations }: Pick) => { - const plugin = new ContextPlugin(async context => { + const fmContextPlugin = new ContextPlugin(async context => { const fmContext = new FileManagerContextSetup(context); context.fileManager = await fmContext.setupContext(storageOperations); @@ -26,9 +27,28 @@ export const createFileManagerContext = ({ FileManagerFeature.register(context.container); }); - plugin.name = "file-manager.createContext"; - - return plugin; + fmContextPlugin.name = "file-manager.createContext"; + + return [ + // Main context plugin + fmContextPlugin, + + // Background task + createFileTaggingTask(), + + // Trigger background task + new ContextPlugin(context => { + context.fileManager.onFileAfterCreate.subscribe(({ file }) => { + context.tasks.trigger({ + definition: "fmAiImageTagging", + input: { + file: file + }, + name: "AI Image Tagging Task" + }); + }); + }) + ]; }; export const createFileManagerGraphQL = () => { diff --git a/packages/api-file-manager/src/tasks/createFileTaggingTask.ts b/packages/api-file-manager/src/tasks/createFileTaggingTask.ts new file mode 100644 index 00000000000..6ce60f0f854 --- /dev/null +++ b/packages/api-file-manager/src/tasks/createFileTaggingTask.ts @@ -0,0 +1,28 @@ +import { createTaskDefinition } from "@webiny/tasks"; +import { FileManagerContext } from "~/types"; +import { Context as WebsocketsContext } from "@webiny/api-websockets"; + +export const createFileTaggingTask = () => { + return createTaskDefinition({ + id: "fmAiImageTagging", + title: "File Upload Background task", + isPrivate: true, + async run(params) { + const { input, response, context } = params; + + // TODO: Get tag information from AI + + // TODO: Update File Tags + await context.fileManager.updateFile(input.fileId, { + // tags: ["tag1", "tag2", "tag3"] + }); + + // TODO: send message to WebSocket + + return response.done( + "successfully ran the fmAiImageTagging background task", + input.fileId + ); + } + }); +}; diff --git a/yarn.lock b/yarn.lock index 306bb4de904..9d27b9e5725 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14278,6 +14278,7 @@ __metadata: "@webiny/api": "npm:0.0.0" "@webiny/api-core": "npm:0.0.0" "@webiny/api-headless-cms": "npm:0.0.0" + "@webiny/api-websockets": "npm:0.0.0" "@webiny/aws-sdk": "npm:0.0.0" "@webiny/build-tools": "npm:0.0.0" "@webiny/error": "npm:0.0.0" From 22a792cc2a7228f145190b6ebb455cc1a7ea2316 Mon Sep 17 00:00:00 2001 From: Swapnil M Mane Date: Tue, 2 Dec 2025 14:02:05 +0530 Subject: [PATCH 2/3] feat: added websocket api package to file manager We will need it AI Image Tagging --- packages/api-file-manager/tsconfig.build.json | 3 +++ packages/api-file-manager/tsconfig.json | 3 +++ 2 files changed, 6 insertions(+) diff --git a/packages/api-file-manager/tsconfig.build.json b/packages/api-file-manager/tsconfig.build.json index 354b188a5dd..b348e05ff43 100644 --- a/packages/api-file-manager/tsconfig.build.json +++ b/packages/api-file-manager/tsconfig.build.json @@ -5,6 +5,7 @@ { "path": "../api/tsconfig.build.json" }, { "path": "../api-core/tsconfig.build.json" }, { "path": "../api-headless-cms/tsconfig.build.json" }, + { "path": "../api-websockets/tsconfig.build.json" }, { "path": "../aws-sdk/tsconfig.build.json" }, { "path": "../error/tsconfig.build.json" }, { "path": "../feature/tsconfig.build.json" }, @@ -154,6 +155,8 @@ "@webiny/api-core": ["../api-core/src"], "@webiny/api-headless-cms/*": ["../api-headless-cms/src/*"], "@webiny/api-headless-cms": ["../api-headless-cms/src"], + "@webiny/api-websockets/*": ["../api-websockets/src/*"], + "@webiny/api-websockets": ["../api-websockets/src"], "@webiny/aws-sdk/*": ["../aws-sdk/src/*"], "@webiny/aws-sdk": ["../aws-sdk/src"], "@webiny/error/*": ["../error/src/*"], diff --git a/packages/api-file-manager/tsconfig.json b/packages/api-file-manager/tsconfig.json index ebea88e95a9..f869a6b5e8e 100644 --- a/packages/api-file-manager/tsconfig.json +++ b/packages/api-file-manager/tsconfig.json @@ -5,6 +5,7 @@ { "path": "../api" }, { "path": "../api-core" }, { "path": "../api-headless-cms" }, + { "path": "../api-websockets" }, { "path": "../aws-sdk" }, { "path": "../error" }, { "path": "../feature" }, @@ -154,6 +155,8 @@ "@webiny/api-core": ["../api-core/src"], "@webiny/api-headless-cms/*": ["../api-headless-cms/src/*"], "@webiny/api-headless-cms": ["../api-headless-cms/src"], + "@webiny/api-websockets/*": ["../api-websockets/src/*"], + "@webiny/api-websockets": ["../api-websockets/src"], "@webiny/aws-sdk/*": ["../aws-sdk/src/*"], "@webiny/aws-sdk": ["../aws-sdk/src"], "@webiny/error/*": ["../error/src/*"], From 0816b2d5439d25bf872c2ab3d3fb9e8f24121941 Mon Sep 17 00:00:00 2001 From: Swapnil M Mane Date: Mon, 8 Dec 2025 09:38:01 +0530 Subject: [PATCH 3/3] fix: type import --- packages/api-file-manager/src/tasks/createFileTaggingTask.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/api-file-manager/src/tasks/createFileTaggingTask.ts b/packages/api-file-manager/src/tasks/createFileTaggingTask.ts index 6ce60f0f854..52579bdb49a 100644 --- a/packages/api-file-manager/src/tasks/createFileTaggingTask.ts +++ b/packages/api-file-manager/src/tasks/createFileTaggingTask.ts @@ -1,5 +1,5 @@ import { createTaskDefinition } from "@webiny/tasks"; -import { FileManagerContext } from "~/types"; +import type { FileManagerContext } from "~/types.js"; import { Context as WebsocketsContext } from "@webiny/api-websockets"; export const createFileTaggingTask = () => {