@@ -4,6 +4,7 @@ import { dirname, join, resolve } from "node:path";
|
||||
import { build } from "esbuild";
|
||||
|
||||
const outputPath = join(tmpdir(), "pi-browser-smoke.js");
|
||||
const agentTreeshakeOutputPath = join(tmpdir(), "pi-agent-treeshake-smoke.js");
|
||||
const errorLogPath = join(tmpdir(), "pi-browser-smoke-errors.log");
|
||||
const generatedCatalogDataDir = join(process.cwd(), "packages/ai/src/providers/data");
|
||||
|
||||
@@ -23,6 +24,22 @@ const generatedCatalogDataPlugin = {
|
||||
},
|
||||
};
|
||||
|
||||
function normalizePath(path) {
|
||||
return path.replaceAll("\\", "/");
|
||||
}
|
||||
|
||||
function findInput(inputs, suffix) {
|
||||
return Object.keys(inputs).find((input) => {
|
||||
const normalized = normalizePath(input);
|
||||
return normalized === suffix || normalized.endsWith(`/${suffix}`);
|
||||
});
|
||||
}
|
||||
|
||||
function includesNodePackage(inputs, packageName) {
|
||||
const marker = `node_modules/${packageName}/`;
|
||||
return Object.keys(inputs).some((input) => normalizePath(input).includes(marker));
|
||||
}
|
||||
|
||||
try {
|
||||
await build({
|
||||
entryPoints: ["scripts/browser-smoke-entry.ts"],
|
||||
@@ -33,6 +50,47 @@ try {
|
||||
outfile: outputPath,
|
||||
plugins: [generatedCatalogDataPlugin],
|
||||
});
|
||||
|
||||
const agentTreeshakeBuild = await build({
|
||||
entryPoints: ["scripts/agent-treeshake-smoke-entry.ts"],
|
||||
bundle: true,
|
||||
platform: "browser",
|
||||
format: "esm",
|
||||
logLevel: "silent",
|
||||
metafile: true,
|
||||
outfile: agentTreeshakeOutputPath,
|
||||
plugins: [generatedCatalogDataPlugin],
|
||||
write: false,
|
||||
});
|
||||
const inputs = agentTreeshakeBuild.metafile.inputs;
|
||||
for (const forbiddenInput of [
|
||||
"packages/ai/src/compat.ts",
|
||||
"packages/ai/src/models.generated.ts",
|
||||
"packages/ai/src/providers/all.ts",
|
||||
]) {
|
||||
const includedInput = findInput(inputs, forbiddenInput);
|
||||
if (includedInput) {
|
||||
throw new Error(`Agent selective-provider bundle unexpectedly includes ${includedInput}`);
|
||||
}
|
||||
}
|
||||
|
||||
const aiSdkPackages = [
|
||||
"@anthropic-ai/sdk",
|
||||
"@aws-sdk/client-bedrock-runtime",
|
||||
"@google/genai",
|
||||
"@mistralai/mistralai",
|
||||
"openai",
|
||||
];
|
||||
const includedAiSdkPackages = aiSdkPackages.filter((packageName) => includesNodePackage(inputs, packageName));
|
||||
if (
|
||||
includedAiSdkPackages.length !== 1 ||
|
||||
includedAiSdkPackages[0] !== "@anthropic-ai/sdk"
|
||||
) {
|
||||
throw new Error(
|
||||
`Agent selective-provider bundle SDKs: expected only @anthropic-ai/sdk, found ${includedAiSdkPackages.join(", ") || "none"}`,
|
||||
);
|
||||
}
|
||||
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
let detailedErrors = "";
|
||||
|
||||
Reference in New Issue
Block a user