UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

55 lines • 2.18 kB
import { existsSync } from "node:fs"; import { dirname } from "node:path"; import { fileURLToPath } from "node:url"; import { imageGenAvailability } from "./auth.js"; import { imagegenSkillPath } from "./skill-path.js"; import { imageGenRegistryOverride } from "./state.js"; import { generateImageTool } from "./tool.js"; const IMAGEGEN_BASE_DIR = dirname(fileURLToPath(import.meta.url)); let loggedMissingSkill = false; async function isImageGenActive(ctx) { const availability = await imageGenAvailability({ modelRegistry: imageGenRegistryOverride() ?? ctx.modelRegistry }); return availability.kind !== "none"; } /** * The compiled binary and the release bundle both rewrite this import into the absolute path of the * shipped asset, and the bundle runs on Node as well as Bun. Unbundled Node rejects the attribute, * but there the copied skill beside this module already answered. */ async function embeddedSkillPath() { try { const module = await import("./skill/SKILL.md", { with: { type: "file" } }); return module.default; } catch { return undefined; } } async function bundledSkillPath(baseDir) { const skillPath = imagegenSkillPath(baseDir); if (existsSync(skillPath)) return skillPath; if (baseDir === IMAGEGEN_BASE_DIR) { const embeddedPath = await embeddedSkillPath(); if (embeddedPath !== undefined && existsSync(embeddedPath)) return embeddedPath; } if (!loggedMissingSkill) { loggedMissingSkill = true; console.error(`[imagegen] bundled skill not found at ${skillPath}; skipping contribution`); } return undefined; } export function registerImageGenExtension(pi, baseDir = IMAGEGEN_BASE_DIR) { pi.registerTool(generateImageTool); pi.on("resources_discover", async (_event, ctx) => { if (!(await isImageGenActive(ctx))) return undefined; const skillPath = await bundledSkillPath(baseDir); return skillPath === undefined ? undefined : { skillPaths: [skillPath] }; }); } export default function imageGenExtension(pi) { registerImageGenExtension(pi); } //# sourceMappingURL=index.js.map