diff --git a/ts/packages/azure-ai-foundry/package.json b/ts/packages/azure-ai-foundry/package.json index 715f4f393..ebcca99ff 100644 --- a/ts/packages/azure-ai-foundry/package.json +++ b/ts/packages/azure-ai-foundry/package.json @@ -22,6 +22,7 @@ ], "scripts": { "build": "npm run tsc", + "postbuild": "copyfiles -f ../../examples/websiteAliases/cache/phrases.json dist", "clean": "rimraf --glob dist *.tsbuildinfo *.done.build.log", "prettier": "prettier --check . --ignore-path ../../.prettierignore", "prettier:fix": "prettier --write . --ignore-path ../../prettierignore", @@ -46,6 +47,7 @@ "@types/async": "^3.2.24", "@types/debug": "^4.1.12", "@types/jest": "^29.5.7", + "copyfiles": "^2.4.1", "dotenv": "^16.3.1", "jest": "^29.7.0", "rimraf": "^6.0.1", diff --git a/ts/packages/azure-ai-foundry/src/urlResolver.ts b/ts/packages/azure-ai-foundry/src/urlResolver.ts index ea68a5905..c549df6b2 100644 --- a/ts/packages/azure-ai-foundry/src/urlResolver.ts +++ b/ts/packages/azure-ai-foundry/src/urlResolver.ts @@ -14,7 +14,9 @@ import { } from "@azure/ai-agents"; import registerDebug from "debug"; import { ChatModelWithStreaming, CompletionSettings, openai } from "aiclient"; -import { readFileSync } from "fs"; +import { readFileSync } from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; import { Result } from "typechat"; import * as wikipediaSchemas from "./wikipediaSchemas.js"; import * as wikipedia from "./wikipedia.js"; @@ -469,6 +471,11 @@ export async function resolveURLWithWikipedia( */ export let keyWordsToSites: Record | undefined; +// Build will copy the file from ../../examples/websiteAliases/cache/phrases.json +const phrasesFile = path.join( + path.dirname(fileURLToPath(import.meta.url)), + "phrases.json", +); /** * Resolves a URL by keyword using the URL resolver agent. * @param keyword The keyword to resolve. @@ -478,12 +485,7 @@ export function resolveURLByKeyword( keyword: string, ): string[] | undefined | null { if (!keyWordsToSites) { - const phrasesToSites = JSON.parse( - readFileSync( - "../../examples/websiteAliases/cache/phrases.json", - "utf-8", - ), - ); + const phrasesToSites = JSON.parse(readFileSync(phrasesFile, "utf-8")); keyWordsToSites = phrasesToSites; } diff --git a/ts/pnpm-lock.yaml b/ts/pnpm-lock.yaml index a0a96e81a..5e4f62a49 100644 --- a/ts/pnpm-lock.yaml +++ b/ts/pnpm-lock.yaml @@ -2473,6 +2473,9 @@ importers: '@types/jest': specifier: ^29.5.7 version: 29.5.14 + copyfiles: + specifier: ^2.4.1 + version: 2.4.1 dotenv: specifier: ^16.3.1 version: 16.5.0