import { Type } from "typebox"; import { getConfigPath } from "../config"; export function makeConfigureTool(store) { return { name: "alchemyst_configure", label: "Alchemyst Configure", description: "Set or update the Alchemyst API key and optionally override connection settings. Required before using any other alchemyst_* tools. All values are saved to ~/.config/pi-alchemyst/config.json and persist across sessions. Environment variables ALCHEMYST_BASE_URL, ALCHEMYST_DEFAULT_SCOPE, and ALCHEMYST_GROUP_NAME take priority over saved values if set.", parameters: Type.Object({ apiKey: Type.String({ description: "The Alchemyst API JWT bearer token from your AlchemystAI account" }), baseUrl: Type.Optional(Type.String()), defaultScope: Type.Optional( Type.Union([Type.Literal("internal"), Type.Literal("external")]) ), groupName: Type.Optional(Type.Array(Type.String())), }), async execute(_toolCallId, args, signal, onUpdate, ctx) { const confirmed = await ctx.ui.confirm( "Configure Alchemyst", `Save Alchemyst configuration to ${getConfigPath()}?`, ); if (!confirmed) { return { content: [ { type: "text", text: "Permission denied. Alchemyst API configuration was not saved." }, ], details: {}, }; } const overrides = {}; if (args.baseUrl) overrides.baseUrl = args.baseUrl; if (args.defaultScope) overrides.defaultScope = args.defaultScope; if (args.groupName) overrides.groupName = args.groupName; store.setApiKey(args.apiKey, overrides); return { content: [ { type: "text", text: "Alchemyst API configured successfully. All alchemyst_* tools are now active." }, ], details: { configured: true }, }; }, }; }