mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-10-21 05:13:53 +00:00
* refactor: migrate baseten provider to AI SDK * refactor(baseten): migrate to native @ai-sdk/baseten package Replace OpenAICompatibleHandler with dedicated @ai-sdk/baseten package, following the same pattern used by other native AI SDK providers (groq, deepseek, etc.). This uses createBaseten() for provider initialization and extends BaseProvider directly instead of the generic OpenAI-compatible handler.
152 lines
4 KiB
JavaScript
152 lines
4 KiB
JavaScript
import * as esbuild from "esbuild"
|
|
import * as fs from "fs"
|
|
import * as path from "path"
|
|
import { fileURLToPath } from "url"
|
|
import process from "node:process"
|
|
import * as console from "node:console"
|
|
|
|
import { copyPaths, copyWasms, copyLocales, setupLocaleWatcher } from "@roo-code/build"
|
|
|
|
const __filename = fileURLToPath(import.meta.url)
|
|
const __dirname = path.dirname(__filename)
|
|
|
|
async function main() {
|
|
const name = "extension"
|
|
const production = process.argv.includes("--production")
|
|
const watch = process.argv.includes("--watch")
|
|
const minify = production
|
|
const sourcemap = true // Always generate source maps for error handling.
|
|
|
|
/**
|
|
* @type {import('esbuild').BuildOptions}
|
|
*/
|
|
const buildOptions = {
|
|
bundle: true,
|
|
minify,
|
|
sourcemap,
|
|
logLevel: "silent",
|
|
format: "cjs",
|
|
sourcesContent: false,
|
|
platform: "node",
|
|
}
|
|
|
|
const srcDir = __dirname
|
|
const buildDir = __dirname
|
|
const distDir = path.join(buildDir, "dist")
|
|
|
|
if (fs.existsSync(distDir)) {
|
|
console.log(`[${name}] Cleaning dist directory: ${distDir}`)
|
|
fs.rmSync(distDir, { recursive: true, force: true })
|
|
}
|
|
|
|
/**
|
|
* @type {import('esbuild').Plugin[]}
|
|
*/
|
|
const plugins = [
|
|
{
|
|
// Stub out @basetenlabs/performance-client which contains native .node
|
|
// binaries that esbuild cannot bundle. This module is only used by
|
|
// @ai-sdk/baseten for embedding models, not for chat completions.
|
|
name: "stub-baseten-native",
|
|
setup(build) {
|
|
build.onResolve({ filter: /^@basetenlabs\/performance-client/ }, (args) => ({
|
|
path: args.path,
|
|
namespace: "stub-baseten-native",
|
|
}))
|
|
build.onLoad({ filter: /.*/, namespace: "stub-baseten-native" }, () => ({
|
|
contents: "module.exports = { PerformanceClient: class PerformanceClient {} };",
|
|
loader: "js",
|
|
}))
|
|
},
|
|
},
|
|
{
|
|
name: "copyFiles",
|
|
setup(build) {
|
|
build.onEnd(() => {
|
|
copyPaths(
|
|
[
|
|
["../README.md", "README.md"],
|
|
["../CHANGELOG.md", "CHANGELOG.md"],
|
|
["../LICENSE", "LICENSE"],
|
|
["../.env", ".env", { optional: true }],
|
|
["node_modules/vscode-material-icons/generated", "assets/vscode-material-icons"],
|
|
["../webview-ui/audio", "webview-ui/audio"],
|
|
],
|
|
srcDir,
|
|
buildDir,
|
|
)
|
|
})
|
|
},
|
|
},
|
|
{
|
|
name: "copyWasms",
|
|
setup(build) {
|
|
build.onEnd(() => copyWasms(srcDir, distDir))
|
|
},
|
|
},
|
|
{
|
|
name: "copyLocales",
|
|
setup(build) {
|
|
build.onEnd(() => copyLocales(srcDir, distDir))
|
|
},
|
|
},
|
|
{
|
|
name: "esbuild-problem-matcher",
|
|
setup(build) {
|
|
build.onStart(() => console.log("[esbuild-problem-matcher#onStart]"))
|
|
build.onEnd((result) => {
|
|
result.errors.forEach(({ text, location }) => {
|
|
console.error(`✘ [ERROR] ${text}`)
|
|
if (location && location.file) {
|
|
console.error(` ${location.file}:${location.line}:${location.column}:`)
|
|
}
|
|
})
|
|
|
|
console.log("[esbuild-problem-matcher#onEnd]")
|
|
})
|
|
},
|
|
},
|
|
]
|
|
|
|
/**
|
|
* @type {import('esbuild').BuildOptions}
|
|
*/
|
|
const extensionConfig = {
|
|
...buildOptions,
|
|
plugins,
|
|
entryPoints: ["extension.ts"],
|
|
outfile: "dist/extension.js",
|
|
// global-agent must be external because it dynamically patches Node.js http/https modules
|
|
// which breaks when bundled. It needs access to the actual Node.js module instances.
|
|
// undici must be bundled because our VSIX is packaged with `--no-dependencies`.
|
|
external: ["vscode", "esbuild", "global-agent"],
|
|
}
|
|
|
|
/**
|
|
* @type {import('esbuild').BuildOptions}
|
|
*/
|
|
const workerConfig = {
|
|
...buildOptions,
|
|
entryPoints: ["workers/countTokens.ts"],
|
|
outdir: "dist/workers",
|
|
}
|
|
|
|
const [extensionCtx, workerCtx] = await Promise.all([
|
|
esbuild.context(extensionConfig),
|
|
esbuild.context(workerConfig),
|
|
])
|
|
|
|
if (watch) {
|
|
await Promise.all([extensionCtx.watch(), workerCtx.watch()])
|
|
copyLocales(srcDir, distDir)
|
|
setupLocaleWatcher(srcDir, distDir)
|
|
} else {
|
|
await Promise.all([extensionCtx.rebuild(), workerCtx.rebuild()])
|
|
await Promise.all([extensionCtx.dispose(), workerCtx.dispose()])
|
|
}
|
|
}
|
|
|
|
main().catch((e) => {
|
|
console.error(e)
|
|
process.exit(1)
|
|
})
|