@supermemory/tools
Advanced tools
+41
-1
| import { SupermemoryToolsConfig } from "./types-CNqWluJ2.js"; | ||
| import Supermemory from "supermemory"; | ||
| import * as ai0 from "ai"; | ||
| import { LanguageModelV2 } from "@ai-sdk/provider"; | ||
| //#region src/vercel/index.d.ts | ||
| /** | ||
| * Wraps a language model with supermemory middleware to automatically inject relevant memories | ||
| * into the system prompt based on the user's message content. | ||
| * | ||
| * This middleware searches the supermemory API for relevant memories using the container tag | ||
| * and user message, then either appends memories to an existing system prompt or creates | ||
| * a new system prompt with the memories. | ||
| * | ||
| * @param model - The language model to wrap with supermemory capabilities | ||
| * @param containerTag - The container tag/identifier for memory search (e.g., user ID, project ID) | ||
| * @param options - Optional configuration options for the middleware | ||
| * @param options.verbose - Optional flag to enable detailed logging of memory search and injection process (default: false) | ||
| * @param options.mode - Optional mode for memory search: "profile" (default), "query", or "full" | ||
| * | ||
| * @returns A wrapped language model that automatically includes relevant memories in prompts | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { withSupermemory } from "@supermemory/tools/ai-sdk" | ||
| * import { openai } from "@ai-sdk/openai" | ||
| * | ||
| * const modelWithMemory = withSupermemory(openai("gpt-4"), "user-123") | ||
| * | ||
| * const result = await generateText({ | ||
| * model: modelWithMemory, | ||
| * messages: [{ role: "user", content: "What's my favorite programming language?" }] | ||
| * }) | ||
| * ``` | ||
| * | ||
| * @throws {Error} When SUPERMEMORY_API_KEY environment variable is not set | ||
| * @throws {Error} When supermemory API request fails | ||
| */ | ||
| declare const wrapVercelLanguageModel: (model: LanguageModelV2, containerTag: string, options?: { | ||
| verbose?: boolean; | ||
| mode?: "profile" | "query" | "full"; | ||
| }) => LanguageModelV2; | ||
| //#endregion | ||
| //#region src/ai-sdk.d.ts | ||
@@ -64,2 +104,2 @@ declare const searchMemoriesTool: (apiKey: string, config?: SupermemoryToolsConfig) => ai0.Tool<{ | ||
| //#endregion | ||
| export { addMemoryTool, searchMemoriesTool, supermemoryTools }; | ||
| export { addMemoryTool, searchMemoriesTool, supermemoryTools, wrapVercelLanguageModel as withSupermemory }; |
+6
-1
@@ -1,1 +0,6 @@ | ||
| import{DEFAULT_VALUES as e,PARAMETER_DESCRIPTIONS as t,TOOL_DESCRIPTIONS as n,getContainerTags as r}from"./shared-CttEw8ws.js";import i from"supermemory";import{tool as a}from"ai";import{z as o}from"zod";const s=(s,c)=>{let l=new i({apiKey:s,...c?.baseUrl?{baseURL:c.baseUrl}:{}}),u=r(c);return a({description:n.searchMemories,inputSchema:o.object({informationToGet:o.string().describe(t.informationToGet),includeFullDocs:o.boolean().optional().default(e.includeFullDocs).describe(t.includeFullDocs),limit:o.number().optional().default(e.limit).describe(t.limit)}),execute:async({informationToGet:t,includeFullDocs:n=e.includeFullDocs,limit:r=e.limit})=>{try{let i=await l.search.execute({q:t,containerTags:u,limit:r,chunkThreshold:e.chunkThreshold,includeFullDocs:n});return{success:!0,results:i.results,count:i.results?.length||0}}catch(e){return{success:!1,error:e instanceof Error?e.message:`Unknown error`}}}})},c=(e,s)=>{let c=new i({apiKey:e,...s?.baseUrl?{baseURL:s.baseUrl}:{}}),l=r(s);return a({description:n.addMemory,inputSchema:o.object({memory:o.string().describe(t.memory)}),execute:async({memory:e})=>{try{let t={},n=await c.memories.add({content:e,containerTags:l,...Object.keys(t).length>0&&{metadata:t}});return{success:!0,memory:n}}catch(e){return{success:!1,error:e instanceof Error?e.message:`Unknown error`}}}})};function l(e,t){return{searchMemories:s(e,t),addMemory:c(e,t)}}export{c as addMemoryTool,s as searchMemoriesTool,l as supermemoryTools}; | ||
| import{DEFAULT_VALUES as e,PARAMETER_DESCRIPTIONS as t,TOOL_DESCRIPTIONS as n,getContainerTags as r}from"./shared-CttEw8ws.js";import i from"supermemory";import{tool as a,wrapLanguageModel as o}from"ai";import{z as s}from"zod";const c=e=>e?{debug:(e,t)=>{console.log(`[supermemory] ${e}`,t?JSON.stringify(t,null,2):``)},info:(e,t)=>{console.log(`[supermemory] ${e}`,t?JSON.stringify(t,null,2):``)},warn:(e,t)=>{console.warn(`[supermemory] ${e}`,t?JSON.stringify(t,null,2):``)},error:(e,t)=>{console.error(`[supermemory] ${e}`,t?JSON.stringify(t,null,2):``)}}:{debug:()=>{},info:()=>{},warn:()=>{},error:()=>{}};function l(e){let t=[];return e.profile.static&&e.profile.static.length>0&&(t.push(`## Static Profile`),t.push(e.profile.static.map(e=>`- ${e}`).join(` | ||
| `))),e.profile.dynamic&&e.profile.dynamic.length>0&&(t.push(`## Dynamic Profile`),t.push(e.profile.dynamic.map(e=>`- ${e}`).join(` | ||
| `))),t.join(` | ||
| `)}const u=e=>e.prompt.reverse().find(e=>e.role===`user`)?.content.filter(e=>e.type===`text`).map(e=>e.text).join(` `),d=async(e,t)=>{let n=process.env.SUPERMEMORY_API_KEY;if(!n)throw Error(`SUPERMEMORY_API_KEY is not set`);let r=t?JSON.stringify({q:t,containerTag:e}):JSON.stringify({containerTag:e});try{let e=await fetch(`https://api.supermemory.ai/v4/profile`,{method:`POST`,headers:{"Content-Type":`application/json`,Authorization:`Bearer ${n}`},body:r});if(!e.ok){let t=await e.text().catch(()=>`Unknown error`);throw Error(`Supermemory profile search failed: ${e.status} ${e.statusText}. ${t}`)}return await e.json()}catch(e){throw e instanceof Error?e:Error(`Supermemory API request failed: ${e}`)}},f=async(e,t,n,r)=>{let i=e.prompt.some(e=>e.role===`system`),a=r===`profile`?``:e.prompt.reverse().find(e=>e.role===`user`)?.content?.filter(e=>e.type===`text`)?.map(e=>e.type===`text`?e.text:``)?.join(` `)||``,o=await d(t,a),s=o.profile.static?.length||0,c=o.profile.dynamic?.length||0;n.info(`Memory search completed`,{containerTag:t,memoryCountStatic:s,memoryCountDynamic:c,queryText:a.substring(0,100)+(a.length>100?`...`:``),mode:r});let u=r===`query`?``:l(o),f=r===`profile`?``:`Search results for user's recent message: \n${o.searchResults.results.map(e=>`- ${e.memory}`).join(` | ||
| `)}`,p=`${u}\n${f}`.trim();return p&&n.debug(`Memory content preview`,{content:p.substring(0,200),fullLength:p.length}),i?(n.debug(`Appending memories to existing system prompt`),{...e,prompt:e.prompt.map(e=>e.role===`system`?{...e,content:`${e.content} \n ${p}`}:e)}):(n.debug(`System prompt does not exist, creating system prompt with memories`),{...e,prompt:[{role:`system`,content:p},...e.prompt]})},p=(e,t=!1,n=`profile`)=>{let r=c(t);return{transformParams:async({params:t})=>n!==`profile`&&!u(t)?(r.debug(`No user message found, skipping memory search`),t):(r.info(`Starting memory search`,{containerTag:e,mode:n}),await f(t,e,r,n))}},m=(e,t,n)=>{if(!process.env.SUPERMEMORY_API_KEY)throw Error(`SUPERMEMORY_API_KEY is not set`);let r=n?.verbose??!1,i=n?.mode??`profile`;return o({model:e,middleware:p(t,r,i)})},h=(o,c)=>{let l=new i({apiKey:o,...c?.baseUrl?{baseURL:c.baseUrl}:{}}),u=r(c);return a({description:n.searchMemories,inputSchema:s.object({informationToGet:s.string().describe(t.informationToGet),includeFullDocs:s.boolean().optional().default(e.includeFullDocs).describe(t.includeFullDocs),limit:s.number().optional().default(e.limit).describe(t.limit)}),execute:async({informationToGet:t,includeFullDocs:n=e.includeFullDocs,limit:r=e.limit})=>{try{let i=await l.search.execute({q:t,containerTags:u,limit:r,chunkThreshold:e.chunkThreshold,includeFullDocs:n});return{success:!0,results:i.results,count:i.results?.length||0}}catch(e){return{success:!1,error:e instanceof Error?e.message:`Unknown error`}}}})},g=(e,o)=>{let c=new i({apiKey:e,...o?.baseUrl?{baseURL:o.baseUrl}:{}}),l=r(o);return a({description:n.addMemory,inputSchema:s.object({memory:s.string().describe(t.memory)}),execute:async({memory:e})=>{try{let t={};return{success:!0,memory:await c.memories.add({content:e,containerTags:l,...Object.keys(t).length>0&&{metadata:t}})}}catch(e){return{success:!1,error:e instanceof Error?e.message:`Unknown error`}}}})};function _(e,t){return{searchMemories:h(e,t),addMemory:g(e,t)}}export{g as addMemoryTool,h as searchMemoriesTool,_ as supermemoryTools,m as withSupermemory}; |
+10
-10
@@ -1,11 +0,11 @@ | ||
| import{getContainerTags as e}from"./shared-CttEw8ws.js";import t from"supermemory";var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,c=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),l=(e,t,n,o)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=a(t),l=0,u=c.length,d;l<u;l++)d=c[l],!s.call(e,d)&&d!==n&&r(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(o=i(t,d))||o.enumerable});return e},u=(e,t,i)=>(i=e==null?{}:n(o(e)),l(t||!e||!e.__esModule?r(i,`default`,{value:e,enumerable:!0}):i,e)),d=c(((exports,t)=>{function n(e){"@babel/helpers - typeof";return t.exports=n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},t.exports.__esModule=!0,t.exports.default=t.exports,n(e)}t.exports=n,t.exports.__esModule=!0,t.exports.default=t.exports})),f=c(((exports,t)=>{var n=d().default;function r(e,t){if(n(e)!=`object`||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var i=r.call(e,t||`default`);if(n(i)!=`object`)return i;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}t.exports=r,t.exports.__esModule=!0,t.exports.default=t.exports})),p=c(((exports,t)=>{var n=d().default,r=f();function i(e){var t=r(e,`string`);return n(t)==`symbol`?t:t+``}t.exports=i,t.exports.__esModule=!0,t.exports.default=t.exports})),m=c(((exports,t)=>{var n=p();function r(e,t,r){return(t=n(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}t.exports=r,t.exports.__esModule=!0,t.exports.default=t.exports})),h=u(m(),1),g=class{normalizePathToCustomId(e){return e.replace(/\//g,`--`)}customIdToPath(e){return e.replace(/--/g,`/`)}constructor(n,r){(0,h.default)(this,`client`,void 0),(0,h.default)(this,`containerTags`,void 0),(0,h.default)(this,`memoryContainerPrefix`,void 0),this.client=new t({apiKey:n,...r?.baseUrl&&{baseURL:r.baseUrl}}),this.memoryContainerPrefix=r?.memoryContainerTag||`claude_memory`;let i=e(r);this.containerTags=[...i,this.memoryContainerPrefix]}async handleCommand(e){try{if(!this.isValidPath(e.path))return{success:!1,error:`Invalid path: ${e.path}. All paths must start with /memories/`};switch(e.command){case`view`:return await this.view(e.path,e.view_range);case`create`:return e.file_text?await this.create(e.path,e.file_text):{success:!1,error:`file_text is required for create command`};case`str_replace`:return!e.old_str||!e.new_str?{success:!1,error:`old_str and new_str are required for str_replace command`}:await this.strReplace(e.path,e.old_str,e.new_str);case`insert`:return e.insert_line===void 0||!e.insert_text?{success:!1,error:`insert_line and insert_text are required for insert command`}:await this.insert(e.path,e.insert_line,e.insert_text);case`delete`:return await this.delete(e.path);case`rename`:return e.new_path?await this.rename(e.path,e.new_path):{success:!1,error:`new_path is required for rename command`};default:return{success:!1,error:`Unknown command: ${e.command}`}}}catch(e){return{success:!1,error:e instanceof Error?e.message:`Unknown error`}}}async handleCommandForToolResult(e,t){let n=await this.handleCommand(e);return{type:`tool_result`,tool_use_id:t,content:n.success?n.content||`Operation completed successfully`:`Error: ${n.error}`,is_error:!n.success}}async view(e,t){if(e.endsWith(`/`)||e===`/memories`){let t=e.endsWith(`/`)?e:e+`/`;return await this.listDirectory(t)}return await this.readFile(e,t)}async listDirectory(e){try{let t=await this.client.search.execute({q:`*`,containerTags:this.containerTags,limit:100,includeFullDocs:!1});if(!t.results)return{success:!0,content:`Directory: ${e}\n(empty)`};let n=[],r=new Set;for(let i of t.results){let t=i.metadata?.file_path;if(!t||!t.startsWith(e))continue;let a=t.substring(e.length);if(!a)continue;let o=a.indexOf(`/`);o>0?r.add(a.substring(0,o)+`/`):a!==``&&n.push(a)}let i=[...Array.from(r).sort(),...n.sort()];return i.length===0?{success:!0,content:`Directory: ${e}\n(empty)`}:{success:!0,content:`Directory: ${e}\n${i.map(e=>`- ${e}`).join(` | ||
| `)}`}}catch(e){return{success:!1,error:`Failed to list directory: ${e instanceof Error?e.message:`Unknown error`}`}}}async readFile(e,t){try{let n=this.normalizePathToCustomId(e),r=await this.client.search.execute({q:n,containerTags:this.containerTags,limit:1,includeFullDocs:!0}),i=r.results?.find(e=>e.documentId===n),a=i||r.results?.[0];if(!a)return{success:!1,error:`File not found: ${e}`};let o=a.content||``;if(t){let e=o.split(` | ||
| `),[n,r]=t,i=e.slice(n-1,r),a=i.map((e,t)=>{let r=n+t;return`${r.toString().padStart(4)}\t${e}`});o=a.join(` | ||
| `)}else{let e=o.split(` | ||
| `),t=e.map((e,t)=>{let n=t+1;return`${n.toString().padStart(4)}\t${e}`});o=t.join(` | ||
| `)}return{success:!0,content:o}}catch(e){return{success:!1,error:`Failed to read file: ${e instanceof Error?e.message:`Unknown error`}`}}}async create(e,t){try{let n=this.normalizePathToCustomId(e);return await this.client.memories.add({content:t,customId:n,containerTags:this.containerTags,metadata:{claude_memory_type:`file`,file_path:e,line_count:t.split(` | ||
| import{getContainerTags as e}from"./shared-CttEw8ws.js";import t from"supermemory";function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(n(e)!=`object`||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var i=r.call(e,t||`default`);if(n(i)!=`object`)return i;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function i(e){var t=r(e,`string`);return n(t)==`symbol`?t:t+``}function a(e,t,n){return(t=i(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var o=class{normalizePathToCustomId(e){return e.replace(/\//g,`--`)}customIdToPath(e){return e.replace(/--/g,`/`)}constructor(n,r){a(this,`client`,void 0),a(this,`containerTags`,void 0),a(this,`memoryContainerPrefix`,void 0),this.client=new t({apiKey:n,...r?.baseUrl&&{baseURL:r.baseUrl}}),this.memoryContainerPrefix=r?.memoryContainerTag||`claude_memory`,this.containerTags=[...e(r),this.memoryContainerPrefix]}async handleCommand(e){try{if(!this.isValidPath(e.path))return{success:!1,error:`Invalid path: ${e.path}. All paths must start with /memories/`};switch(e.command){case`view`:return await this.view(e.path,e.view_range);case`create`:return e.file_text?await this.create(e.path,e.file_text):{success:!1,error:`file_text is required for create command`};case`str_replace`:return!e.old_str||!e.new_str?{success:!1,error:`old_str and new_str are required for str_replace command`}:await this.strReplace(e.path,e.old_str,e.new_str);case`insert`:return e.insert_line===void 0||!e.insert_text?{success:!1,error:`insert_line and insert_text are required for insert command`}:await this.insert(e.path,e.insert_line,e.insert_text);case`delete`:return await this.delete(e.path);case`rename`:return e.new_path?await this.rename(e.path,e.new_path):{success:!1,error:`new_path is required for rename command`};default:return{success:!1,error:`Unknown command: ${e.command}`}}}catch(e){return{success:!1,error:e instanceof Error?e.message:`Unknown error`}}}async handleCommandForToolResult(e,t){let n=await this.handleCommand(e);return{type:`tool_result`,tool_use_id:t,content:n.success?n.content||`Operation completed successfully`:`Error: ${n.error}`,is_error:!n.success}}async view(e,t){if(e.endsWith(`/`)||e===`/memories`){let t=e.endsWith(`/`)?e:e+`/`;return await this.listDirectory(t)}return await this.readFile(e,t)}async listDirectory(e){try{let t=await this.client.search.execute({q:`*`,containerTags:this.containerTags,limit:100,includeFullDocs:!1});if(!t.results)return{success:!0,content:`Directory: ${e}\n(empty)`};let n=[],r=new Set;for(let i of t.results){let t=i.metadata?.file_path;if(!t||!t.startsWith(e))continue;let a=t.substring(e.length);if(!a)continue;let o=a.indexOf(`/`);o>0?r.add(a.substring(0,o)+`/`):a!==``&&n.push(a)}let i=[...Array.from(r).sort(),...n.sort()];return i.length===0?{success:!0,content:`Directory: ${e}\n(empty)`}:{success:!0,content:`Directory: ${e}\n${i.map(e=>`- ${e}`).join(` | ||
| `)}`}}catch(e){return{success:!1,error:`Failed to list directory: ${e instanceof Error?e.message:`Unknown error`}`}}}async readFile(e,t){try{let n=this.normalizePathToCustomId(e),r=await this.client.search.execute({q:n,containerTags:this.containerTags,limit:1,includeFullDocs:!0}),i=r.results?.find(e=>e.documentId===n)||r.results?.[0];if(!i)return{success:!1,error:`File not found: ${e}`};let a=i.content||``;if(t){let e=a.split(` | ||
| `),[n,r]=t;a=e.slice(n-1,r).map((e,t)=>`${(n+t).toString().padStart(4)}\t${e}`).join(` | ||
| `)}else a=a.split(` | ||
| `).map((e,t)=>`${(t+1).toString().padStart(4)}\t${e}`).join(` | ||
| `);return{success:!0,content:a}}catch(e){return{success:!1,error:`Failed to read file: ${e instanceof Error?e.message:`Unknown error`}`}}}async create(e,t){try{let n=this.normalizePathToCustomId(e);return await this.client.memories.add({content:t,customId:n,containerTags:this.containerTags,metadata:{claude_memory_type:`file`,file_path:e,line_count:t.split(` | ||
| `).length,created_by:`claude_memory_tool`,last_modified:new Date().toISOString()}}),{success:!0,content:`File created: ${e}`}}catch(e){return{success:!1,error:`Failed to create file: ${e instanceof Error?e.message:`Unknown error`}`}}}async strReplace(e,t,n){try{let r=await this.getFileDocument(e);if(!r.success||!r.document)return{success:!1,error:r.error||`File not found`};let i=r.document.raw||r.document.content||``;if(!i.includes(t))return{success:!1,error:`String not found in file: "${t}"`};let a=i.replace(t,n),o=this.normalizePathToCustomId(e);return await this.client.memories.add({content:a,customId:o,containerTags:this.containerTags,metadata:{...r.document.metadata,line_count:a.split(` | ||
| `).length,last_modified:new Date().toISOString()}}),{success:!0,content:`String replaced in file: ${e}`}}catch(e){return{success:!1,error:`Failed to replace string: ${e instanceof Error?e.message:`Unknown error`}`}}}async insert(e,t,n){try{let r=await this.getFileDocument(e);if(!r.success||!r.document)return{success:!1,error:r.error||`File not found`};let i=r.document.raw||r.document.content||``,a=i.split(` | ||
| `);if(t<1||t>a.length+1)return{success:!1,error:`Invalid line number: ${t}. File has ${a.length} lines.`};a.splice(t-1,0,n);let o=a.join(` | ||
| `),s=this.normalizePathToCustomId(e);return await this.client.memories.add({content:o,customId:s,containerTags:this.containerTags,metadata:{...r.document.metadata,line_count:o.split(` | ||
| `).length,last_modified:new Date().toISOString()}}),{success:!0,content:`Text inserted at line ${t} in file: ${e}`}}catch(e){return{success:!1,error:`Failed to insert text: ${e instanceof Error?e.message:`Unknown error`}`}}}async delete(e){try{let t=await this.getFileDocument(e);return!t.success||!t.document?{success:!1,error:t.error||`File not found`}:{success:!0,content:`File deleted: ${e}`}}catch(e){return{success:!1,error:`Failed to delete file: ${e instanceof Error?e.message:`Unknown error`}`}}}async rename(e,t){try{if(!this.isValidPath(t))return{success:!1,error:`Invalid new path: ${t}. All paths must start with /memories/`};let n=await this.getFileDocument(e);if(!n.success||!n.document)return{success:!1,error:n.error||`File not found`};let r=n.document.raw||n.document.content||``,i=this.normalizePathToCustomId(t);return await this.client.memories.add({content:r,customId:i,containerTags:this.containerTags,metadata:{...n.document.metadata,file_path:t,last_modified:new Date().toISOString()}}),{success:!0,content:`File renamed from ${e} to ${t}`}}catch(e){return{success:!1,error:`Failed to rename file: ${e instanceof Error?e.message:`Unknown error`}`}}}async getFileDocument(e){try{let t=this.normalizePathToCustomId(e),n=await this.client.search.execute({q:t,containerTags:this.containerTags,limit:5,includeFullDocs:!0}),r=n.results?.find(e=>e.documentId===t),i=r||n.results?.[0];return i?{success:!0,document:i}:{success:!1,error:`File not found: ${e}`}}catch(e){return{success:!1,error:e instanceof Error?e.message:`Unknown error`}}}isValidPath(e){return(e.startsWith(`/memories/`)||e===`/memories`)&&!e.includes(`../`)&&!e.includes(`..\\`)}};function _(e,t){return new g(e,t)}export{g as ClaudeMemoryTool,_ as createClaudeMemoryTool}; | ||
| `).length,last_modified:new Date().toISOString()}}),{success:!0,content:`String replaced in file: ${e}`}}catch(e){return{success:!1,error:`Failed to replace string: ${e instanceof Error?e.message:`Unknown error`}`}}}async insert(e,t,n){try{let r=await this.getFileDocument(e);if(!r.success||!r.document)return{success:!1,error:r.error||`File not found`};let i=(r.document.raw||r.document.content||``).split(` | ||
| `);if(t<1||t>i.length+1)return{success:!1,error:`Invalid line number: ${t}. File has ${i.length} lines.`};i.splice(t-1,0,n);let a=i.join(` | ||
| `),o=this.normalizePathToCustomId(e);return await this.client.memories.add({content:a,customId:o,containerTags:this.containerTags,metadata:{...r.document.metadata,line_count:a.split(` | ||
| `).length,last_modified:new Date().toISOString()}}),{success:!0,content:`Text inserted at line ${t} in file: ${e}`}}catch(e){return{success:!1,error:`Failed to insert text: ${e instanceof Error?e.message:`Unknown error`}`}}}async delete(e){try{let t=await this.getFileDocument(e);return!t.success||!t.document?{success:!1,error:t.error||`File not found`}:{success:!0,content:`File deleted: ${e}`}}catch(e){return{success:!1,error:`Failed to delete file: ${e instanceof Error?e.message:`Unknown error`}`}}}async rename(e,t){try{if(!this.isValidPath(t))return{success:!1,error:`Invalid new path: ${t}. All paths must start with /memories/`};let n=await this.getFileDocument(e);if(!n.success||!n.document)return{success:!1,error:n.error||`File not found`};let r=n.document.raw||n.document.content||``,i=this.normalizePathToCustomId(t);return await this.client.memories.add({content:r,customId:i,containerTags:this.containerTags,metadata:{...n.document.metadata,file_path:t,last_modified:new Date().toISOString()}}),{success:!0,content:`File renamed from ${e} to ${t}`}}catch(e){return{success:!1,error:`Failed to rename file: ${e instanceof Error?e.message:`Unknown error`}`}}}async getFileDocument(e){try{let t=this.normalizePathToCustomId(e),n=await this.client.search.execute({q:t,containerTags:this.containerTags,limit:5,includeFullDocs:!0}),r=n.results?.find(e=>e.documentId===t)||n.results?.[0];return r?{success:!0,document:r}:{success:!1,error:`File not found: ${e}`}}catch(e){return{success:!1,error:e instanceof Error?e.message:`Unknown error`}}}isValidPath(e){return(e.startsWith(`/memories/`)||e===`/memories`)&&!e.includes(`../`)&&!e.includes(`..\\`)}};function s(e,t){return new o(e,t)}export{o as ClaudeMemoryTool,s as createClaudeMemoryTool}; |
+1
-1
@@ -1,1 +0,1 @@ | ||
| import{DEFAULT_VALUES as e,PARAMETER_DESCRIPTIONS as t,TOOL_DESCRIPTIONS as n,getContainerTags as r}from"./shared-CttEw8ws.js";import i from"supermemory";const a={searchMemories:{name:`searchMemories`,description:n.searchMemories,parameters:{type:`object`,properties:{informationToGet:{type:`string`,description:t.informationToGet},includeFullDocs:{type:`boolean`,description:t.includeFullDocs,default:e.includeFullDocs},limit:{type:`number`,description:t.limit,default:e.limit}},required:[`informationToGet`]}},addMemory:{name:`addMemory`,description:n.addMemory,parameters:{type:`object`,properties:{memory:{type:`string`,description:t.memory}},required:[`memory`]}}};function o(e,t){let n=new i({apiKey:e,...t?.baseUrl&&{baseURL:t.baseUrl}}),a=r(t);return{client:n,containerTags:a}}function s(t,n){let{client:r,containerTags:i}=o(t,n);return async function({informationToGet:t,includeFullDocs:n=e.includeFullDocs,limit:a=e.limit}){try{let o=await r.search.execute({q:t,containerTags:i,limit:a,chunkThreshold:e.chunkThreshold,includeFullDocs:n});return{success:!0,results:o.results,count:o.results?.length||0}}catch(e){return{success:!1,error:e instanceof Error?e.message:`Unknown error`}}}}function c(e,t){let{client:n,containerTags:r}=o(e,t);return async function({memory:e}){try{let t={},i=await n.memories.add({content:e,containerTags:r,...Object.keys(t).length>0&&{metadata:t}});return{success:!0,memory:i}}catch(e){return{success:!1,error:e instanceof Error?e.message:`Unknown error`}}}}function l(e,t){let n=s(e,t),r=c(e,t);return{searchMemories:n,addMemory:r}}function u(){return[{type:`function`,function:a.searchMemories},{type:`function`,function:a.addMemory}]}function d(e,t){let n=l(e,t);return async function(e){let t=e.function.name,r=JSON.parse(e.function.arguments);switch(t){case`searchMemories`:return JSON.stringify(await n.searchMemories(r));case`addMemory`:return JSON.stringify(await n.addMemory(r));default:return JSON.stringify({success:!1,error:`Unknown function: ${t}`})}}}function f(e,t){let n=d(e,t);return async function(e){let t=await Promise.all(e.map(async e=>{let t=await n(e);return{tool_call_id:e.id,role:`tool`,content:t}}));return t}}function p(e,t){let n=s(e,t);return{definition:{type:`function`,function:a.searchMemories},execute:n}}function m(e,t){let n=c(e,t);return{definition:{type:`function`,function:a.addMemory},execute:n}}export{c as createAddMemoryFunction,m as createAddMemoryTool,s as createSearchMemoriesFunction,p as createSearchMemoriesTool,d as createToolCallExecutor,f as createToolCallsExecutor,u as getToolDefinitions,a as memoryToolSchemas,l as supermemoryTools}; | ||
| import{DEFAULT_VALUES as e,PARAMETER_DESCRIPTIONS as t,TOOL_DESCRIPTIONS as n,getContainerTags as r}from"./shared-CttEw8ws.js";import i from"supermemory";const a={searchMemories:{name:`searchMemories`,description:n.searchMemories,parameters:{type:`object`,properties:{informationToGet:{type:`string`,description:t.informationToGet},includeFullDocs:{type:`boolean`,description:t.includeFullDocs,default:e.includeFullDocs},limit:{type:`number`,description:t.limit,default:e.limit}},required:[`informationToGet`]}},addMemory:{name:`addMemory`,description:n.addMemory,parameters:{type:`object`,properties:{memory:{type:`string`,description:t.memory}},required:[`memory`]}}};function o(e,t){let n=new i({apiKey:e,...t?.baseUrl&&{baseURL:t.baseUrl}}),a=r(t);return{client:n,containerTags:a}}function s(t,n){let{client:r,containerTags:i}=o(t,n);return async function({informationToGet:t,includeFullDocs:n=e.includeFullDocs,limit:a=e.limit}){try{let o=await r.search.execute({q:t,containerTags:i,limit:a,chunkThreshold:e.chunkThreshold,includeFullDocs:n});return{success:!0,results:o.results,count:o.results?.length||0}}catch(e){return{success:!1,error:e instanceof Error?e.message:`Unknown error`}}}}function c(e,t){let{client:n,containerTags:r}=o(e,t);return async function({memory:e}){try{let t={};return{success:!0,memory:await n.memories.add({content:e,containerTags:r,...Object.keys(t).length>0&&{metadata:t}})}}catch(e){return{success:!1,error:e instanceof Error?e.message:`Unknown error`}}}}function l(e,t){let n=s(e,t),r=c(e,t);return{searchMemories:n,addMemory:r}}function u(){return[{type:`function`,function:a.searchMemories},{type:`function`,function:a.addMemory}]}function d(e,t){let n=l(e,t);return async function(e){let t=e.function.name,r=JSON.parse(e.function.arguments);switch(t){case`searchMemories`:return JSON.stringify(await n.searchMemories(r));case`addMemory`:return JSON.stringify(await n.addMemory(r));default:return JSON.stringify({success:!1,error:`Unknown function: ${t}`})}}}function f(e,t){let n=d(e,t);return async function(e){return await Promise.all(e.map(async e=>{let t=await n(e);return{tool_call_id:e.id,role:`tool`,content:t}}))}}function p(e,t){let n=s(e,t);return{definition:{type:`function`,function:a.searchMemories},execute:n}}function m(e,t){let n=c(e,t);return{definition:{type:`function`,function:a.addMemory},execute:n}}export{c as createAddMemoryFunction,m as createAddMemoryTool,s as createSearchMemoriesFunction,p as createSearchMemoriesTool,d as createToolCallExecutor,f as createToolCallsExecutor,u as getToolDefinitions,a as memoryToolSchemas,l as supermemoryTools}; |
+1
-1
| { | ||
| "name": "@supermemory/tools", | ||
| "type": "module", | ||
| "version": "1.2.0", | ||
| "version": "1.2.1", | ||
| "description": "Memory tools for AI SDK and OpenAI function calling with supermemory", | ||
@@ -6,0 +6,0 @@ "scripts": { |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
39393
9.81%426
11.81%5
400%1
Infinity%