UNPKG

@code-yeongyu/senpi

Version:

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

58 lines • 2.56 kB
import { LOOK_AT_PARAMETERS, normalizeLookAtArgs, prepareLookAtArguments, validateLookAtArgs } from "./arguments.js"; import { registerLookAtCommand } from "./commands.js"; import { resolveVisionModel } from "./model-selector.js"; import { LOOK_AT_DESCRIPTION, LOOK_AT_PROMPT_SNIPPET } from "./prompts.js"; import { renderLookAtCall, renderLookAtResult } from "./render.js"; import { runLookAt } from "./runner.js"; import { createLookAtStore, loadLookAtChain, loadLookAtEnabled } from "./settings.js"; const TOOL_NAME = "look_at"; export default function lookAtExtension(pi) { const store = createLookAtStore(); pi.registerTool({ name: TOOL_NAME, label: "Look At", description: LOOK_AT_DESCRIPTION, promptSnippet: LOOK_AT_PROMPT_SNIPPET, parameters: LOOK_AT_PARAMETERS, prepareArguments: prepareLookAtArguments, async execute(_toolCallId, params, signal, _onUpdate, ctx) { const normalized = normalizeLookAtArgs(params); const validationError = validateLookAtArgs(normalized); if (validationError) throw new Error(validationError); const result = await runLookAt(normalized, signal, ctx, store); return { content: [{ type: "text", text: result.text }], details: { model: result.model, sources: result.sources, mimeTypes: result.mimeTypes }, }; }, renderCall: renderLookAtCall, renderResult: renderLookAtResult, }); function syncToolActivation(ctx) { const active = pi.getActiveTools(); const shouldBeActive = loadLookAtEnabled(ctx, store) && ctx.model !== undefined && !ctx.model.input.includes("image") && resolveVisionModel(loadLookAtChain(ctx, store), ctx.modelRegistry.getAvailable()) !== undefined; const isActive = active.includes(TOOL_NAME); if (shouldBeActive && !isActive) { pi.setActiveTools([...active, TOOL_NAME]); } else if (!shouldBeActive && isActive) { pi.setActiveTools(active.filter((name) => name !== TOOL_NAME)); } } pi.on("session_start", async (_event, ctx) => { syncToolActivation(ctx); }); pi.on("model_select", async (_event, ctx) => { syncToolActivation(ctx); }); registerLookAtCommand(pi, { store, loadChain: (ctx) => loadLookAtChain(ctx, store), resync: (ctx) => syncToolActivation(ctx), }); } //# sourceMappingURL=index.js.map