UNPKG

permamind

Version:

An MCP server that provides an immortal memory layer for AI agents and clients

55 lines (54 loc) 2.06 kB
import { z } from "zod"; import { event } from "../../../relay.js"; import { MEMORY_KINDS } from "../../../services/aiMemoryService.js"; import { CommonSchemas, ToolCommand, } from "../../core/index.js"; export class SaveAddressMappingCommand extends ToolCommand { context; metadata = { description: "Save a contact name to address mapping for future use", name: "saveAddressMapping", openWorldHint: false, readOnlyHint: false, title: "Save Address Mapping", }; parametersSchema = z.object({ address: CommonSchemas.address.describe("Wallet address"), name: z.string().describe("Contact name"), }); constructor(context) { super(); this.context = context; } async execute(args) { try { // Use dedicated contact mapping kind for better filtering const tags = [ { name: "Kind", value: MEMORY_KINDS.CONTACT_MAPPING }, { name: "Content", value: `Contact mapping: name: ${args.name}, address: ${args.address}`, }, { name: "p", value: this.context.publicKey }, { name: "contact_name", value: args.name }, { name: "contact_address", value: args.address }, { name: "domain", value: "address-book" }, ]; const result = await event(this.context.keyPair, this.context.hubId, tags); return JSON.stringify({ mapping: { address: args.address, name: args.name, }, message: `Contact mapping saved: ${args.name} -> ${args.address}`, success: true, tags: result, }); } catch (error) { return JSON.stringify({ error: `Failed to save contact mapping: ${error instanceof Error ? error.message : "Unknown error"}`, success: false, }); } } }