UNPKG

agents

Version:

A home for your AI agents

62 lines (61 loc) • 2.21 kB
import babel from "@rolldown/plugin-babel"; //#region src/vite.ts const TURNDOWN_STUB_ID = "\0agents:turndown-stub"; const TURNDOWN_STUB_MESSAGE = "The Agents Vite plugin stubbed the 'turndown' package to keep Workers bundles compatible with just-bash. If your app uses turndown directly, configure the plugin with agents({ stubTurndown: false })."; function turndownStubPlugin() { return { name: "agents-turndown-stub", enforce: "pre", resolveId(source) { if (source === "turndown") return TURNDOWN_STUB_ID; return null; }, load(id) { if (id !== TURNDOWN_STUB_ID) return null; return `const message = ${JSON.stringify(TURNDOWN_STUB_MESSAGE)}; class TurndownService { constructor() {} use() { return this; } addRule() { return this; } keep() { return this; } remove() { return this; } turndown() { throw new Error(message); } } export default TurndownService; `; } }; } const REMOVED_SKILLS_IMPORT_MESSAGE = "The \"agents:skills\" import has been removed. Skills are now files: store them in a Computer Workspace and return skills.workspace(this.workspace) from getSkills(), or load them with skills.r2(bucket) or skills.manifest({ id, skills }). See https://developers.cloudflare.com/agents/skills/"; function removedSkillsImportPlugin() { return { name: "agents-removed-skills-import", enforce: "pre", resolveId(source) { if (source === "agents:skills" || source.startsWith("agents:skills/")) this.error(REMOVED_SKILLS_IMPORT_MESSAGE); return null; } }; } /** * Vite plugin for Agents SDK projects. * * Handles TC39 decorator transforms (Oxc doesn't support them yet, oxc#9170) so * `@callable()` works at runtime, and stubs `turndown` to keep Workers * deploys clean. Will grow to cover other * Agents-specific build concerns as needed. */ function agents(options = {}) { const { stubTurndown = true } = options; return [ ...stubTurndown ? [turndownStubPlugin()] : [], removedSkillsImportPlugin(), babel({ presets: [{ preset: () => ({ plugins: [["@babel/plugin-proposal-decorators", { version: "2023-11" }]] }), rolldown: { filter: { code: "@" } } }] }) ]; } //#endregion export { agents as default }; //# sourceMappingURL=vite.js.map