From 588645507c7a400aebd6661315fe863278c3f040 Mon Sep 17 00:00:00 2001 From: Piotr Karwatka Date: Thu, 12 Dec 2024 15:49:08 +0100 Subject: [PATCH] fix: __dirname should not be used in ES Module (#104) ... instead of a relative image path (which didn't work with `create-fabrice-ai` cloned example) --------- Co-authored-by: Mike Grabowski --- example/src/ecommerce_product_description.ts | 4 ++-- example/src/library_photo_to_website.ts | 2 +- packages/create-fabrice-ai/src/utils.ts | 7 +------ packages/tools/README.md | 2 +- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/example/src/ecommerce_product_description.ts b/example/src/ecommerce_product_description.ts index 524d9d8..e0405ee 100644 --- a/example/src/ecommerce_product_description.ts +++ b/example/src/ecommerce_product_description.ts @@ -3,6 +3,7 @@ import { agent } from 'fabrice-ai/agent' import { teamwork } from 'fabrice-ai/teamwork' import { logger } from 'fabrice-ai/telemetry' import { solution, workflow } from 'fabrice-ai/workflow' +import path from 'path' const techExpert = agent({ role: 'Technical expert', @@ -27,7 +28,7 @@ const marketingManager = agent({ const productDescriptionWorkflow = workflow({ members: [techExpert, marketingManager], description: ` - Based on the picture './example/assets/example-sneakers.jpg' make the eCommerce product to + Based on the picture '${path.resolve(import.meta.dirname, '../assets/example-sneakers.jpg')}' make the eCommerce product to list this product on the website. Focus: @@ -44,7 +45,6 @@ const productDescriptionWorkflow = workflow({ `, snapshot: logger, }) - const result = await teamwork(productDescriptionWorkflow) console.log(solution(result)) diff --git a/example/src/library_photo_to_website.ts b/example/src/library_photo_to_website.ts index 3939f9e..652f0a1 100644 --- a/example/src/library_photo_to_website.ts +++ b/example/src/library_photo_to_website.ts @@ -6,7 +6,7 @@ import { logger } from 'fabrice-ai/telemetry' import { solution, workflow } from 'fabrice-ai/workflow' import path from 'path' -const workingDir = path.resolve(__dirname, '../assets/') +const workingDir = path.resolve(import.meta.dirname, '../assets/') const { saveFile, readFile, listFilesFromDirectory } = createFileSystemTools({ workingDir, diff --git a/packages/create-fabrice-ai/src/utils.ts b/packages/create-fabrice-ai/src/utils.ts index 6d17452..8c41d34 100644 --- a/packages/create-fabrice-ai/src/utils.ts +++ b/packages/create-fabrice-ai/src/utils.ts @@ -1,12 +1,7 @@ import { execSync } from 'node:child_process' import { tmpdir } from 'node:os' import path from 'node:path' -import { dirname } from 'node:path' import { promises as Stream, Readable } from 'node:stream' -import { fileURLToPath } from 'node:url' - -const __filename = fileURLToPath(import.meta.url) -const __dirname = dirname(__filename) import { extract } from 'tar' @@ -58,6 +53,6 @@ export async function copyAdditionalTemplateFiles(root: string) { ] for (const file of files) { - execSync(`cp ${path.join(__dirname, file.src)} ${path.join(root, file.dest)}`) + execSync(`cp ${path.join(import.meta.dirname, file.src)} ${path.join(root, file.dest)}`) } } diff --git a/packages/tools/README.md b/packages/tools/README.md index 1c66026..6204699 100644 --- a/packages/tools/README.md +++ b/packages/tools/README.md @@ -173,7 +173,7 @@ File system tools for reading, writing and listing files. The tools are sandboxe ```typescript import { createFileSystemTools } from '@fabrice-ai/tools/filesystem' -const workingDir = path.resolve(__dirname, '../assets/') +const workingDir = path.resolve(import.meta.dirname, '../assets/') const { saveFile, readFile, listFilesFromDirectory } = createFileSystemTools({ workingDir,