From e709e773dd5327985aa006e5af2c360a03a85121 Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 15 Jan 2025 09:41:54 -0300 Subject: [PATCH 1/6] Added Zip Tests --- README.md | 7 +- scripts/build_tools.ts | 328 +----------------- scripts/build_tools/index.ts | 13 + scripts/build_tools/interfaces.ts | 64 ++++ scripts/build_tools/save_tools.ts | 299 ++++++++++++++++ scripts/build_tools/upload.ts | 51 +++ scripts/run_node.sh | 2 +- scripts/zip.test.ts | 42 +++ .../coinbase-call-faucet/.tool-dump.test.json | 1 + tools/coinbase-call-faucet/index.test.ts | 2 +- .../.tool-dump.test.json | 1 + .../coinbase-get-balance/.tool-dump.test.json | 1 + tools/coinbase-get-balance/index.test.ts | 8 +- .../.tool-dump.test.json | 1 + tools/coinbase-get-my-address/index.test.ts | 8 +- .../.tool-dump.test.json | 1 + tools/coinbase-get-transactions/index.test.ts | 8 +- tools/coinbase-send-tx/.tool-dump.test.json | 1 + tools/coinbase-send-tx/index.test.ts | 8 +- tools/download-page/.tool-dump.test.json | 1 + tools/duckduckgo-search/.tool-dump.test.json | 1 + tools/email-imap-fetcher/.tool-dump.test.json | 1 + tools/email-responder/.tool-dump.test.json | 1 + tools/email-responder/metadata.json | 1 + tools/email-sender/.tool-dump.test.json | 1 + tools/file-read/.tool-dump.test.json | 1 + tools/file-read/metadata.json | 1 + tools/file-update/.tool-dump.test.json | 1 + tools/file-update/metadata.json | 1 + tools/file-write/.tool-dump.test.json | 1 + tools/file-write/metadata.json | 1 + tools/google-search/.tool-dump.test.json | 1 + tools/google-search/metadata.json | 1 + tools/math-exp/.tool-dump.test.json | 1 + tools/math-exp/index.test.ts | 4 +- tools/math-exp/metadata.json | 1 + tools/memory/.tool-dump.test.json | 1 + tools/memory/metadata.json | 1 + tools/perplexity-api/.tool-dump.test.json | 1 + tools/perplexity-api/index.test.ts | 4 +- tools/perplexity-api/metadata.json | 1 + tools/perplexity/.tool-dump.test.json | 1 + tools/perplexity/index.test.ts | 39 +-- tools/perplexity/metadata.json | 1 + tools/smart-search/.tool-dump.test.json | 1 + tools/smart-search/metadata.json | 1 + tools/youtube-summary/.tool-dump.test.json | 1 + tools/youtube-summary/index.test.ts | 38 +- 48 files changed, 567 insertions(+), 389 deletions(-) create mode 100644 scripts/build_tools/index.ts create mode 100644 scripts/build_tools/interfaces.ts create mode 100644 scripts/build_tools/save_tools.ts create mode 100644 scripts/build_tools/upload.ts create mode 100644 scripts/zip.test.ts create mode 100644 tools/coinbase-call-faucet/.tool-dump.test.json create mode 100644 tools/coinbase-create-wallet/.tool-dump.test.json create mode 100644 tools/coinbase-get-balance/.tool-dump.test.json create mode 100644 tools/coinbase-get-my-address/.tool-dump.test.json create mode 100644 tools/coinbase-get-transactions/.tool-dump.test.json create mode 100644 tools/coinbase-send-tx/.tool-dump.test.json create mode 100644 tools/download-page/.tool-dump.test.json create mode 100644 tools/duckduckgo-search/.tool-dump.test.json create mode 100644 tools/email-imap-fetcher/.tool-dump.test.json create mode 100644 tools/email-responder/.tool-dump.test.json create mode 100644 tools/email-sender/.tool-dump.test.json create mode 100644 tools/file-read/.tool-dump.test.json create mode 100644 tools/file-update/.tool-dump.test.json create mode 100644 tools/file-write/.tool-dump.test.json create mode 100644 tools/google-search/.tool-dump.test.json create mode 100644 tools/math-exp/.tool-dump.test.json create mode 100644 tools/memory/.tool-dump.test.json create mode 100644 tools/perplexity-api/.tool-dump.test.json create mode 100644 tools/perplexity/.tool-dump.test.json create mode 100644 tools/smart-search/.tool-dump.test.json create mode 100644 tools/youtube-summary/.tool-dump.test.json diff --git a/README.md b/README.md index f5dc395..d2d3ec5 100644 --- a/README.md +++ b/README.md @@ -36,4 +36,9 @@ tools/ ├── packages/ │ ├── tool.zip # Zipped contents of the tool. │ └── directory.json # A listing of the available tools. -``` \ No newline at end of file +``` + +## Run Tests +``` +BEARER_TOKEN=debug SHINKAI_NODE_ADDR="http://0.0.0.0:9550" deno test scripts/ --allow-all +``` diff --git a/scripts/build_tools.ts b/scripts/build_tools.ts index 25fe036..d6cc087 100644 --- a/scripts/build_tools.ts +++ b/scripts/build_tools.ts @@ -1,327 +1,3 @@ -import { join } from "https://deno.land/std/path/mod.ts"; -import { exists } from "https://deno.land/std/fs/mod.ts"; -import { encode } from "https://deno.land/std/encoding/base64.ts"; +import { start } from "./build_tools/index.ts"; -interface Metadata { - id: string; - name: string; - description: string; - author: string; - version: string; - keywords: string[]; - configurations?: { - properties: Record; - required: string[]; - }; - parameters: { - properties: Record; - }; - result: Record; - price_usd?: number; // to-do: add to metadata.json - stripeProductId?: string; // to-do: add to metadata.json - categoryId?: string; // to-do: add to metadata.json -} - -interface DirectoryEntry { - default?: boolean; - name: string; - author: string; - keywords: string[]; - type: "Tool" | "Agent" | "Scheduled Task"; - toolLanguage?: string; - version: string; - description: string; - routerKey: string; - hash: string; - file: string; - agent_id?: string; - price_usd?: number; - stripeProductId?: string; - categoryId?: string; -} - -async function getToolType(file: string): Promise { - return file.endsWith(".ts") ? "Deno" : "Python"; -} - -async function calculateBlake3Hash(filePath: string): Promise { - const command = new Deno.Command("b3sum", { - args: [filePath], - }); - const { stdout } = await command.output(); - const output = new TextDecoder().decode(stdout); - return output.split(" ")[0]; -} - -async function buildToolJson(toolContent: string, metadata: Metadata, toolType: string) { - const content = [{ - activated: false, - assets: null, - file_inbox: null, - oauth: null, - output_arg: { json: "" }, - author: metadata.author || "Unknown", - config: metadata.configurations?.properties ? - Object.entries(metadata.configurations.properties).map(([key, value]) => ({ - BasicConfig: { - key_name: key, - description: value.description || "", - required: metadata.configurations?.required?.includes(key) || false, - key_value: null - } - })) : [], - description: metadata.description || "No description provided.", - input_args: metadata.parameters || [], - keywords: metadata.keywords || [], - name: metadata.name || "Unknown", - result: metadata.result || {}, - sql_queries: [], - sql_tables: [], - toolkit_name: metadata.id || "Unknown", - tools: metadata.tools || [], - version: metadata.version || "1.0.0", - [toolType === "Python" ? "py_code" : "js_code"]: toolContent - }, false]; - - return { content, type: toolType }; -} - -async function processToolsDirectory() { - const tools: DirectoryEntry[] = []; - - // Process tools - for await (const entry of Deno.readDir("tools")) { - if (!entry.isDirectory) continue; - - const toolDir = join("tools", entry.name); - const toolName = entry.name; - - console.log(`Processing ${toolName}...`); - - // Find tool file - let toolFile = ""; - if (await exists(join(toolDir, "tool.ts"))) { - toolFile = join(toolDir, "tool.ts"); - } else if (await exists(join(toolDir, "tool.py"))) { - toolFile = join(toolDir, "tool.py"); - } - - if (!toolFile || !await exists(join(toolDir, "metadata.json"))) { - console.error(`Error: Missing required files in ${toolDir}`); - continue; - } - - // Read files - const metadata: Metadata = JSON.parse(await Deno.readTextFile(join(toolDir, "metadata.json"))); - const toolContent = await Deno.readTextFile(toolFile); - const toolType = await getToolType(toolFile); - - // Build tool JSON - const toolJson = await buildToolJson(toolContent, metadata, toolType); - - // Send to Shinkai node - const response = await fetch(`${Deno.env.get("SHINKAI_NODE_ADDR")}/v2/add_shinkai_tool`, { - method: "POST", - headers: { - "Authorization": `Bearer ${Deno.env.get("BEARER_TOKEN")}`, - "Content-Type": "application/json", - }, - body: JSON.stringify(toolJson), - }); - - if (!response.ok) { - console.error(`Failed to upload tool to Shinkai node. HTTP status: ${response.status}`); - console.error(`Response: ${await response.text()}`); - continue; - } - - const uploadedTool = await response.json(); - const toolRouterKey = uploadedTool.message.replace(/.*key: /, ""); - - // Get tool zip - const zipResponse = await fetch( - `${Deno.env.get("SHINKAI_NODE_ADDR")}/v2/export_tool?tool_key_path=${toolRouterKey}`, - { - headers: { - "Authorization": `Bearer ${Deno.env.get("BEARER_TOKEN")}`, - }, - } - ); - - if (!zipResponse.ok) { - console.error(`Failed to download zip for ${toolName}`); - continue; - } - - // Save zip file - const zipPath = join("packages", `${toolName}.zip`); - await Deno.writeFile(zipPath, new Uint8Array(await zipResponse.arrayBuffer())); - - // Validate zip - try { - const validateZip = new Deno.Command("unzip", { - args: ["-t", zipPath], - }); - await validateZip.output(); - } catch { - console.error(`Error: Invalid zip file downloaded for ${toolName}`); - await Deno.remove(zipPath); - continue; - } - - // Calculate hash - const blake3Hash = await calculateBlake3Hash(zipPath); - - // Check for .default file - const hasDefault = await exists(join(toolDir, ".default")); - - tools.push({ - // default: hasDefault, - name: toolName, - author: metadata.author || "Unknown", - keywords: metadata.keywords || ["tool"], - type: "Tool", - toolLanguage: toolType, - version: metadata.version || "0.0.0", - description: metadata.description || "No description provided.", - routerKey: toolRouterKey, - hash: blake3Hash, - file: `${Deno.env.get("DOWNLOAD_PREFIX")}/${toolName}.zip`, - price_usd: metadata.price_usd || 0.00, - stripeProductId: "prod_P000000000000", - // categoryId: "cat_P000000000000", // to-do: categories not implemented yet. - }); - } - - return tools; -} - -async function processAgentsDirectory() { - const agents: DirectoryEntry[] = []; - - // Process agents - for await (const entry of Deno.readDir("agents")) { - if (!entry.isFile || !entry.name.endsWith(".json")) continue; - - console.log(`Processing agent ${entry.name}...`); - - const agentContent = JSON.parse(await Deno.readTextFile(join("agents", entry.name))); - const agentId = agentContent.agent_id; - - // Create zip - const zipPath = join("packages", `${agentId}.zip`); - const zip = new Deno.Command("zip", { - args: ["-j", zipPath, join("agents", entry.name)], - }); - await zip.output(); - - const blake3Hash = await calculateBlake3Hash(zipPath); - - agents.push({ - name: agentContent.name, - author: agentContent.author || "Unknown", - keywords: agentContent.keywords || ["agent"], - type: "Agent", - version: agentContent.version || "0.0.0", - description: agentContent.ui_description, - hash: blake3Hash, - file: `${Deno.env.get("DOWNLOAD_PREFIX")}/${agentId}.zip`, - agent_id: agentId, - routerKey: 'not-implemented-yet', - }); - } - - return agents; -} - -async function processCronsDirectory() { - const crons: DirectoryEntry[] = []; - - // Process crons - for await (const entry of Deno.readDir("crons")) { - if (!entry.isFile || !entry.name.endsWith(".json")) continue; - - console.log(`Processing cron ${entry.name}...`); - - const cronContent = JSON.parse(await Deno.readTextFile(join("crons", entry.name))); - const cronId = entry.name.replace(".json", ""); - - // Create zip - const zipPath = join("packages", `${cronId}.zip`); - const zip = new Deno.Command("zip", { - args: ["-j", zipPath, join("crons", entry.name)], - }); - await zip.output(); - - const blake3Hash = await calculateBlake3Hash(zipPath); - - crons.push({ - name: cronContent.name, - author: cronContent.author || "Unknown", - keywords: cronContent.keywords || ["cron"], - type: "Scheduled Task", - version: cronContent.version || "0.0.0", - description: cronContent.description, - hash: blake3Hash, - file: `${Deno.env.get("DOWNLOAD_PREFIX")}/${cronId}.zip`, - routerKey: 'not-implemented-yet', - }); - } - - return crons; -} - -async function processProducts() { - // Create packages directory - await Deno.mkdir("packages", { recursive: true }); - - // Initialize empty directory.json - await Deno.writeTextFile("packages/directory.json", "[]"); - - // Process all directories in parallel - const [tools] = await Promise.all([ - processToolsDirectory(), - // processAgentsDirectory(), - // processCronsDirectory() - ]); - - // Write final directory.json - const directory = [...tools]; - await Deno.writeTextFile("packages/directory.json", JSON.stringify(directory, null, 2)); - - // Upload directory.json to Shinkai Store - for (const entry of directory) { - let response = await fetch(`${Deno.env.get("SHINKAI_STORE_ADDR")}/store/products`, { - method: "POST", - headers: { - "Authorization": `Bearer ${Deno.env.get("SHINKAI_STORE_TOKEN")}`, - "Content-Type": "application/json", - }, - body: JSON.stringify(entry), - }); - - if (response.status === 409) { - const responseBody = await response.text(); - if (responseBody.includes("already exists")) { - // Product exists, use PUT endpoint instead - const putResponse = await fetch(`${Deno.env.get("SHINKAI_STORE_ADDR")}/store/products/${entry.router_key}`, { - method: "PUT", - headers: { - "Authorization": `Bearer ${Deno.env.get("SHINKAI_STORE_TOKEN")}`, - "Content-Type": "application/json", - }, - body: JSON.stringify(entry), - }); - response = putResponse; - } - } - - console.log(`Upload to Store Response (${response.status}): ${await response.text()}`); - if (response.status !== 200) console.log(`Request body failed: ${JSON.stringify(entry, null, 2)}`); - } -} - -// Run the script -if (import.meta.main) { - await processProducts(); -} +start(); diff --git a/scripts/build_tools/index.ts b/scripts/build_tools/index.ts new file mode 100644 index 0000000..7e92b90 --- /dev/null +++ b/scripts/build_tools/index.ts @@ -0,0 +1,13 @@ +import { processToolsDirectory, saveToolsInNode } from "./save_tools.ts"; +import { uploadTools } from "./upload.ts"; + +export async function start() { + // Run the script + const tools_raw = await processToolsDirectory(); + const tools_saved = await saveToolsInNode(tools_raw); + await uploadTools(tools_saved); +} + +if (import.meta.main) { + start(); +} diff --git a/scripts/build_tools/interfaces.ts b/scripts/build_tools/interfaces.ts new file mode 100644 index 0000000..ccdc627 --- /dev/null +++ b/scripts/build_tools/interfaces.ts @@ -0,0 +1,64 @@ +interface ConfigurationBasicType { + type: 'string' | 'number' | 'boolean' | 'date' | 'datetime'; + description: string; + default?: string; +} + +interface ConfigurationArray { + type: 'array'; + items: Configuration; + description?: string; +} + +interface ConfigurationObject { + type: 'object'; + properties: Record; + required: string[]; + description?: string; +} + +type Configuration = ConfigurationBasicType | ConfigurationArray | ConfigurationObject; + +export interface Metadata { + id: string; + name: string; + description: string; + author: string; + version: string; + keywords: string[]; + configurations: ConfigurationObject; + parameters: ConfigurationObject; + result: ConfigurationObject; + price_usd?: number; // to-do: add to metadata.json + stripeProductId?: string; // to-do: add to metadata.json + categoryId?: string; // to-do: add to metadata.json + tools: string[]; + sqlTables: { + name: string; + definition: string; + }[]; + sqlQueries: { + name: string; + query: string; + }[]; +} + +export interface DirectoryEntry { + dir: string; + default?: boolean; + name: string; + author: string; + keywords: string[]; + type: "Tool" | "Agent" | "Scheduled Task"; + toolLanguage?: string; + version: string; + description: string; + routerKey: string; + hash: string; + toolFile: string; + file: string; + agent_id?: string; + price_usd?: number; + stripeProductId?: string; + categoryId?: string; +} diff --git a/scripts/build_tools/save_tools.ts b/scripts/build_tools/save_tools.ts new file mode 100644 index 0000000..22e2896 --- /dev/null +++ b/scripts/build_tools/save_tools.ts @@ -0,0 +1,299 @@ +import { DirectoryEntry, Metadata } from "./interfaces.ts"; + +import { join } from "https://deno.land/std/path/mod.ts"; +import { exists } from "https://deno.land/std/fs/mod.ts"; + +// deno-lint-ignore require-await +async function getToolType(file: string): Promise { + return file.endsWith(".ts") ? "Deno" : "Python"; +} + +async function calculateBlake3Hash(filePath: string): Promise { + const command = new Deno.Command("b3sum", { + args: [filePath], + }); + const { stdout } = await command.output(); + const output = new TextDecoder().decode(stdout); + return output.split(" ")[0]; +} + +// deno-lint-ignore require-await +async function buildToolJson(toolContent: string, metadata: Metadata, toolType: string) { + // Set GENERATE_RANDOM_NAME to true to generate a random name for the tool + // So multiple tools with the same name can be uploaded into the node. + const generate_random_name = !!Deno.env.get("GENERATE_RANDOM_NAME"); + let name = metadata.name; + if (generate_random_name) { + name = name + '_' + new Date().getTime(); + } + + const content = [{ + activated: false, + assets: null, + file_inbox: null, + oauth: null, + output_arg: { json: "" }, + author: metadata.author, + config: metadata.configurations?.properties ? + Object.entries(metadata.configurations.properties).map(([key, value]) => ({ + BasicConfig: { + key_name: key, + description: value.description ?? "", + required: metadata.configurations?.required?.includes(key) ?? false, + key_value: null + } + })) : [], + description: metadata.description, + input_args: metadata.parameters, + keywords: metadata.keywords, + name: name, + result: metadata.result, + sql_queries: metadata.sqlQueries, + sql_tables: metadata.sqlTables, + toolkit_name: metadata.id, + tools: metadata.tools, + version: metadata.version, + [toolType === "Python" ? "py_code" : "js_code"]: toolContent + }, false]; + + return { content, type: toolType }; +} + +// deno-lint-ignore no-unused-vars +async function processAgentsDirectory() { + const agents: DirectoryEntry[] = []; + + // Process agents + for await (const entry of Deno.readDir("agents")) { + if (!entry.isFile || !entry.name.endsWith(".json")) continue; + + console.log(`Processing agent ${entry.name}...`); + + const agentContent = JSON.parse(await Deno.readTextFile(join("agents", entry.name))); + const agentId = agentContent.agent_id; + + // Create zip + const zipPath = join("packages", `${agentId}.zip`); + const zip = new Deno.Command("zip", { + args: ["-j", zipPath, join("agents", entry.name)], + }); + await zip.output(); + + const blake3Hash = await calculateBlake3Hash(zipPath); + + agents.push({ + toolFile: join("agents", entry.name), + dir: join("agents"), + name: agentContent.name, + author: agentContent.author, + keywords: agentContent.keywords, + type: "Agent", + version: agentContent.version, + description: agentContent.ui_description, + hash: blake3Hash, + file: `${Deno.env.get("DOWNLOAD_PREFIX")}/${agentId}.zip`, + agent_id: agentId, + routerKey: 'not-implemented-yet', + }); + } + + return agents; +} + +// deno-lint-ignore no-unused-vars +async function processCronsDirectory() { + const crons: DirectoryEntry[] = []; + + // Process crons + for await (const entry of Deno.readDir("crons")) { + if (!entry.isFile || !entry.name.endsWith(".json")) continue; + + console.log(`Processing cron ${entry.name}...`); + + const cronContent = JSON.parse(await Deno.readTextFile(join("crons", entry.name))); + const cronId = entry.name.replace(".json", ""); + + // Create zip + const zipPath = join("packages", `${cronId}.zip`); + const zip = new Deno.Command("zip", { + args: ["-j", zipPath, join("crons", entry.name)], + }); + await zip.output(); + + const blake3Hash = await calculateBlake3Hash(zipPath); + + crons.push({ + toolFile: join("crons", entry.name), + dir: join("crons"), + name: cronContent.name, + author: cronContent.author, + keywords: cronContent.keywords, + type: "Scheduled Task", + version: cronContent.version, + description: cronContent.description, + hash: blake3Hash, + file: `${Deno.env.get("DOWNLOAD_PREFIX")}/${cronId}.zip`, + routerKey: 'not-implemented-yet', + }); + } + + return crons; +} + +export async function processToolsDirectory(): Promise { + const tools: DirectoryEntry[] = []; + + // Process tools + for await (const entry of Deno.readDir("tools")) { + if (!entry.isDirectory) continue; + + const toolDir = join("tools", entry.name); + const toolName = entry.name; + + console.log(`Processing ${toolName}...`); + + // Find tool file + let toolFile = ""; + if (await exists(join(toolDir, "tool.ts"))) { + toolFile = join(toolDir, "tool.ts"); + } else if (await exists(join(toolDir, "tool.py"))) { + toolFile = join(toolDir, "tool.py"); + } + + if (!toolFile || !await exists(join(toolDir, "metadata.json"))) { + console.error(`Error: Missing required files in ${toolDir}`); + continue; + } + + // Read files + const metadata: Metadata = JSON.parse(await Deno.readTextFile(join(toolDir, "metadata.json"))); + const toolType = await getToolType(toolFile); + + if (!metadata.author) { + throw(`Error: Missing author in metadata for ${toolName}`); + } + if (!metadata.keywords) { + throw(`Error: Missing keywords in metadata for ${toolName}`); + } + if (!metadata.description) { + throw(`Error: Missing description in metadata for ${toolName}`); + } + if (!metadata.version) { + throw(`Error: Missing version in metadata for ${toolName}`); + } + + // Toolkit name is required for the tool to be uploaded into the node. + if (!metadata.id) { + throw(`Error: Missing id (toolkit_name) in metadata for ${toolName}`); + } + + tools.push({ + // default: hasDefault, + dir: toolDir, + name: toolName, + author: metadata.author, + keywords: metadata.keywords, + type: "Tool", + toolLanguage: toolType, + version: metadata.version, + description: metadata.description, + routerKey: '', + hash: '', + toolFile, + file: `${Deno.env.get("DOWNLOAD_PREFIX")}/${toolName}.zip`, + price_usd: metadata.price_usd || 0.00, + stripeProductId: "prod_P000000000000", + // categoryId: "cat_P000000000000", // to-do: categories not implemented yet. + }); + } + + return tools; +} + +export async function saveToolsInNode(toolsOriginal: DirectoryEntry[]): Promise { + const tools = JSON.parse(JSON.stringify(toolsOriginal)); + const toolsSaved: DirectoryEntry[] = []; + for (const tool of tools) { + + // Read files + const metadata: Metadata = JSON.parse(await Deno.readTextFile(join(tool.dir, "metadata.json"))); + const toolContent = await Deno.readTextFile(tool.toolFile); + const toolType = await getToolType(tool.toolFile); + + // Build tool JSON + const toolJson = await buildToolJson(toolContent, metadata, toolType); + + // Send to Shinkai node + const response = await fetch(`${Deno.env.get("SHINKAI_NODE_ADDR")}/v2/add_shinkai_tool`, { + method: "POST", + headers: { + "Authorization": `Bearer ${Deno.env.get("BEARER_TOKEN")}`, + "Content-Type": "application/json", + }, + body: JSON.stringify(toolJson), + }); + + if (!response.ok) { + console.error(`Failed to upload tool to Shinkai node. HTTP status: ${response.status}`); + console.error(`Response: ${await response.text()}`); + continue; + } + + const uploadedTool = await response.json(); + tool.routerKey = uploadedTool.message.replace(/.*key: /, ""); + + // Get tool zip + const zipResponse = await fetch( + `${Deno.env.get("SHINKAI_NODE_ADDR")}/v2/export_tool?tool_key_path=${tool.routerKey}`, + { + headers: { + "Authorization": `Bearer ${Deno.env.get("BEARER_TOKEN")}`, + }, + } + ); + + if (!zipResponse.ok) { + console.error(`Failed to download zip for ${tool.name}`); + continue; + } + + // Save zip filex + const zipPath = join("packages", `${tool.name}.zip`); + await Deno.writeFile(zipPath, new Uint8Array(await zipResponse.arrayBuffer())); + + // Validate zip + try { + const validateZip = new Deno.Command("unzip", { + args: ["-t", zipPath], + }); + await validateZip.output(); + + const zipPathFiles = join("packages", `${tool.name}`); + const unzip = new Deno.Command("unzip", { + args: [zipPath, '-d', zipPathFiles], + }); + await unzip.output(); + + // Enable flag to update reference files + // copy the unzipped __tool.json to the tool directory as .tool-dump.test.json + if (Deno.env.get("UPDATE_DUMP_FILES")) { + await Deno.copyFile(join(zipPathFiles, "__tool.json"), join(tool.dir, ".tool-dump.test.json")); + } + + } catch { + console.error(`Error: Invalid zip file downloaded for ${tool.name}`); + await Deno.remove(zipPath); + continue; + } + + // Calculate hash + tool.hash = await calculateBlake3Hash(zipPath); + + // Check for .default file + tool.default = await exists(join(tool.dir, ".default")); + + toolsSaved.push(tool); + } + + return toolsSaved; + } \ No newline at end of file diff --git a/scripts/build_tools/upload.ts b/scripts/build_tools/upload.ts new file mode 100644 index 0000000..180b094 --- /dev/null +++ b/scripts/build_tools/upload.ts @@ -0,0 +1,51 @@ +import { DirectoryEntry } from "./interfaces.ts"; + +export async function uploadTools(tools: DirectoryEntry[]) { + const store_addr = Deno.env.get("SHINKAI_STORE_ADDR"); + const store_token = Deno.env.get("SHINKAI_STORE_TOKEN"); + if (!store_addr || !store_token) { + console.error("SHINKAI_STORE_ADDR or SHINKAI_STORE_TOKEN is not set"); + return; + } + // Create packages directory + await Deno.mkdir("packages", { recursive: true }); + + // Initialize empty directory.json + await Deno.writeTextFile("packages/directory.json", "[]"); + + // Write final directory.json + const directory = [...tools]; + await Deno.writeTextFile("packages/directory.json", JSON.stringify(directory, null, 2)); + + // Upload directory.json to Shinkai Store + for (const entry of directory) { + let response = await fetch(`${store_addr}/store/products`, { + method: "POST", + headers: { + "Authorization": `Bearer ${store_token}`, + "Content-Type": "application/json", + }, + body: JSON.stringify(entry), + }); + + if (response.status === 409) { + const responseBody = await response.text(); + if (responseBody.includes("already exists")) { + // Product exists, use PUT endpoint instead + const putResponse = await fetch(`${store_addr}/store/products/${entry.routerKey}`, { + method: "PUT", + headers: { + "Authorization": `Bearer ${store_token}`, + "Content-Type": "application/json", + }, + body: JSON.stringify(entry), + }); + response = putResponse; + } + } + + console.log(`Upload to Store Response (${response.status}): ${await response.text()}`); + if (response.status !== 200) console.log(`Request body failed: ${JSON.stringify(entry, null, 2)}`); + } + } + \ No newline at end of file diff --git a/scripts/run_node.sh b/scripts/run_node.sh index 66c7fd1..7fb54b7 100755 --- a/scripts/run_node.sh +++ b/scripts/run_node.sh @@ -20,7 +20,7 @@ export PROXY_IDENTITY="@@relayer_pub_01.arb-sep-shinkai" export SHINKAI_TOOLS_RUNNER_DENO_BINARY_PATH="./shinkai-tools-runner-resources/deno" export SHINKAI_TOOLS_RUNNER_UV_BINARY_PATH="./shinkai-tools-runner-resources/uv" export SHINKAI_VERSION="0.9.5" - +# export SKIP_IMPORT_FROM_DIRECTORY="true" # Add these lines to enable all log options export LOG_ALL=1 diff --git a/scripts/zip.test.ts b/scripts/zip.test.ts new file mode 100644 index 0000000..66ba5ac --- /dev/null +++ b/scripts/zip.test.ts @@ -0,0 +1,42 @@ +import { assertEquals } from "jsr:@std/assert"; +import { processToolsDirectory, saveToolsInNode } from "./build_tools/save_tools.ts"; +import { join } from "https://deno.land/std/path/mod.ts"; +import { exists } from "https://deno.land/std/fs/mod.ts"; + +Deno.test("Compare shinkai-node generated ZIP __tool.json vs .tool-dump.test.json", async () => { + const tools_raw = await processToolsDirectory(); + const tools_saved = await saveToolsInNode(tools_raw); + + // Expect the number of tools saved to be the same as the number of tools raw + assertEquals(tools_saved.map(tool => tool.name).sort(), tools_raw.map(tool => tool.name).sort()); + + // Search for tools with .tool-dump.test.json + for await (const entry of Deno.readDir("tools")) { + if (!entry.isDirectory) continue; + + const toolDir = join("tools", entry.name); + const toolDump = await exists(join(toolDir, ".tool-dump.test.json")); + if (!toolDump) { + console.log(`[SKIPING] Tool ${entry.name} does not have a .tool-dump.test.json`); + continue; + } + + // Search for tool downloaded and extracted data + const zipDir = join("packages", `${entry.name}`); + const zipDirExists = await exists(zipDir); + assertEquals(zipDirExists, true); + const zipTool = await exists(join(zipDir, "__tool.json")); + assertEquals(zipTool, true); + + // read zipTool and toolDump and compare + const zipToolData = JSON.parse(await Deno.readTextFile(join(zipDir, "__tool.json"))); + const toolDumpData = JSON.parse(await Deno.readTextFile(join(toolDir, ".tool-dump.test.json"))); + // Embeddings might change. + zipToolData.content[0].embedding = []; + toolDumpData.content[0].embedding = []; + assertEquals(zipToolData, toolDumpData); + } + +}); + + diff --git a/tools/coinbase-call-faucet/.tool-dump.test.json b/tools/coinbase-call-faucet/.tool-dump.test.json new file mode 100644 index 0000000..1f0ac5e --- /dev/null +++ b/tools/coinbase-call-faucet/.tool-dump.test.json @@ -0,0 +1 @@ +{"type":"Deno","content":[{"toolkit_name":"coinbase-call-faucet","name":"Coinbase Faucet Caller","author":"Shinkai","version":"1.0.0","js_code":"import { Coinbase, CoinbaseOptions } from 'npm:@coinbase/coinbase-sdk@0.0.16';\n\ntype Configurations = {\n name: string;\n privateKey: string;\n walletId?: string;\n};\ntype Parameters = {};\ntype Result = {\n data: string;\n};\nexport type Run, I extends Record, R extends Record> = (config: C, inputs: I) => Promise;\n\nexport const run: Run = async (\n configurations,\n _params,\n): Promise => {\n const coinbaseOptions: CoinbaseOptions = {\n apiKeyName: configurations.name,\n privateKey: configurations.privateKey,\n };\n const coinbase = new Coinbase(coinbaseOptions);\n console.log(`Coinbase configured: `, coinbase);\n const user = await coinbase.getDefaultUser();\n console.log(`User: `, user);\n\n // Use walletId from Config only\n const walletId = configurations.walletId;\n\n let wallet;\n if (walletId) {\n // Retrieve existing Wallet using walletId\n wallet = await user.getWallet(walletId);\n console.log(`Wallet retrieved: `, wallet.toString());\n } else {\n // Create a new Wallet for the User\n wallet = await user.createWallet({\n networkId: Coinbase.networks.BaseSepolia,\n });\n console.log(`Wallet successfully created: `, wallet.toString());\n }\n\n const faucetTransaction = await wallet.faucet();\n console.log(\n `Faucet transaction completed successfully: `,\n faucetTransaction.toString(),\n );\n\n return {\n data: `Faucet transaction completed successfully: ${faucetTransaction.toString()} for wallet: ${wallet.getDefaultAddress()}`,\n };\n};\n\n","tools":[],"config":[{"BasicConfig":{"key_name":"name","description":"","required":true,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"privateKey","description":"","required":true,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"walletId","description":"","required":false,"type":null,"key_value":null}}],"description":"Tool for calling a faucet on Coinbase","keywords":["coinbase","faucet","shinkai"],"input_args":{"type":"object","properties":{},"required":[]},"output_arg":{"json":""},"activated":false,"embedding":[-0.99122494,0.50806594,-0.18137962,-0.41493967,-0.23193666,-0.46692222,0.0687634,0.43874425,-0.27778542,-0.017959813,-0.8661224,0.07842385,0.17415565,0.059652843,0.3853139,-0.53799176,0.011051909,-0.6348554,-1.2048376,0.28303137,0.50286824,0.9636021,0.029742166,0.2970993,-0.093243614,0.1579739,-0.29110375,0.12320799,-1.1625351,-2.4252186,0.5984823,1.1908039,-0.6606316,-0.2709986,-0.63542795,-0.34321687,0.12860778,-0.26192757,-0.15083013,-0.029253855,-0.03655629,0.2297895,-0.5603324,-0.050662898,-0.13666894,-0.70836246,0.48023468,0.19298565,0.53484815,0.7338745,0.5589467,-0.36540076,0.25469062,-0.5136771,-0.3332828,-0.12868685,0.22334099,-0.7157119,0.19501099,0.31472236,0.22343026,0.40181735,-3.8011842,-0.047244344,1.2716331,-0.6118786,-0.11626663,-0.11116794,-0.33865005,0.4694708,-0.037501752,-0.19524391,-0.4614096,0.3223101,0.29280674,0.037641026,0.7293865,-0.35483155,0.567163,0.12906854,0.13266593,0.6007808,0.12596978,0.43191862,-0.25101435,0.4072931,0.21287161,-0.52972436,0.29522818,0.6254314,-0.4135732,0.12478796,-0.078617595,0.07535772,0.000089384615,0.5190583,0.10056962,0.24503843,0.017940115,3.1678724,0.6107782,0.14412847,0.31150937,-0.9736704,0.5321445,-0.13874264,-0.30686077,-0.35969603,0.23723474,0.10950215,0.79324293,-0.023657102,0.6210422,0.19991389,0.34732723,-0.1934203,-0.13354202,0.36694792,-0.6958847,0.9096159,-0.48663473,0.664064,-1.2650294,-0.29368094,0.4261583,-0.076165274,-0.32999966,0.3633916,0.00080637634,0.13501783,0.9418749,-0.82700145,-0.76627177,-0.07468449,-0.28829494,0.434925,0.07580288,-0.6897222,-0.68812186,-0.40245715,0.18199688,-2.1058512,1.224085,-0.19669126,0.44360998,-0.17754836,0.4740172,0.1371968,-0.7740964,0.2550662,-0.17048314,0.36711055,0.42428753,-0.23090535,0.28756404,0.14982949,-0.35205346,0.062007338,-0.01289238,0.44881707,-0.42916048,0.2266951,0.28846586,0.23304105,0.5841187,-0.67397416,0.6724802,0.16376093,-0.3693137,-0.123955846,0.6306007,-0.07195953,-0.2700342,0.22918184,-1.4100586,-0.1133481,-0.27751988,0.05546531,0.30617833,-0.78547466,-0.46278316,0.99444,-0.53480095,-0.73826486,-0.08605997,0.055162385,0.06365322,0.22701722,0.21728194,0.5684299,-0.9437571,1.0672885,-0.35899705,-0.04806394,-0.29208297,0.21088497,-0.17880356,0.1196495,-0.049828578,-0.036527902,-0.27911696,-0.52558833,-0.34787142,0.22506356,-0.25697565,-0.13310519,1.3069135,0.49249384,0.12590644,-0.8827312,0.44646263,-0.06894559,0.42643484,0.7206083,0.8160076,-0.44844735,0.16804968,0.019308368,0.16603923,0.26426148,1.0348673,0.5334502,-0.954048,-0.39132386,-0.81579703,0.08473987,0.17618689,0.4596308,-0.5402172,0.21049465,0.31503275,0.7458434,0.6645061,0.84952253,0.8682018,0.7328625,-0.0679008,0.33489862,0.22054482,-0.12859799,-0.005194355,0.2583303,-0.6760137,0.5455183,0.2866763,-0.0079629645,0.42053515,-0.9807938,0.3063334,1.6347826,0.21526441,-0.5904196,0.11962591,-0.062463757,-0.050052047,-0.20544973,-1.1212342,0.5382988,-0.6786197,0.1453031,-0.40478265,-0.1791695,0.37327555,0.026863594,-0.25588816,-0.20552187,-0.37325567,0.1906169,0.117457904,-0.062925085,0.10161585,0.8090012,0.629976,-0.18731183,-0.12044861,0.19006206,0.31053948,0.17830685,-0.3020076,-0.5735512,-0.020475678,-0.16555937,0.6612981,-0.10536747,0.182735,-0.6303363,-0.5657179,0.18669339,-0.8254714,-0.26674804,-0.10148545,-0.34947407,-0.20487763,0.21583214,2.2093656,0.7205735,-0.16089511,0.3484195,0.35745317,0.91434324,0.17402184,-0.0005370714,-0.525771,0.16789791,-1.0236385,0.0937128,0.34643108,-0.49626967,-0.1790568,-0.32317,-0.37175724,0.30956614,-0.014280874,0.106248505,-0.20281261,-0.42128444,0.21055475,0.45975873,-0.2581095,-2.0881133,-0.26736298,0.31235436,-0.6298407,-0.12596682,0.24670933,0.6193566,0.19237164,0.60334843,-0.22912377,1.361868,0.35932636,-0.4044572,-0.9850079,0.4134363,0.5290532,0.45526838,0.1147489,-0.3668976,-0.42578667,0.3019122,-0.13172133,1.3124754,-0.020972705,0.30414128,-0.41859457,-0.37522227,-0.014403075,-1.7559369,0.020438597,0.16517067,-0.49357662,0.31749943,-0.03856969,-0.6470938,0.5298628,0.80309176,-0.2739704,-0.12535317,-0.0002693422,0.57529545,0.32525396,0.051337495,-0.58472085,-0.19945246,0.20148355,-0.051555976,0.31528756,0.27569154,0.088488206,0.26962948,-0.63993686,-0.3265281,0.13676783,-0.2961794,0.8000029,0.56923926,-0.22789086,-0.08803365,0.67435783,0.011274636,-0.16963835,0.25483674,-0.7386935,0.30054727],"result":{"type":"object","properties":{"data":{"type":"string"}},"required":["data"]},"sql_tables":null,"sql_queries":null,"file_inbox":null,"oauth":null,"assets":null},false]} \ No newline at end of file diff --git a/tools/coinbase-call-faucet/index.test.ts b/tools/coinbase-call-faucet/index.test.ts index bb47a2b..9f0b212 100644 --- a/tools/coinbase-call-faucet/index.test.ts +++ b/tools/coinbase-call-faucet/index.test.ts @@ -1,4 +1,4 @@ -import { run } from './index.ts'; +import { run } from './tool.ts'; import { expect } from 'jsr:@std/expect'; // Deno.test('echo', async () => { diff --git a/tools/coinbase-create-wallet/.tool-dump.test.json b/tools/coinbase-create-wallet/.tool-dump.test.json new file mode 100644 index 0000000..ac75c20 --- /dev/null +++ b/tools/coinbase-create-wallet/.tool-dump.test.json @@ -0,0 +1 @@ +{"type":"Deno","content":[{"toolkit_name":"coinbase-create-wallet","name":"Coinbase Wallet Creator","author":"Shinkai","version":"1.0.0","js_code":"import { Coinbase, CoinbaseOptions } from 'npm:@coinbase/coinbase-sdk@0.0.16';\n\ntype Configurations = {\n name: string;\n privateKey: string;\n useServerSigner?: string;\n};\ntype Parameters = {}; // Params type is now empty\ntype Result = {\n walletId?: string;\n seed?: string;\n address?: string;\n};\nexport type Run, I extends Record, R extends Record> = (config: C, inputs: I) => Promise;\n\nexport const run: Run = async (\n configurations: Configurations,\n _parameters: Parameters,\n): Promise => {\n const coinbaseOptions: CoinbaseOptions = {\n apiKeyName: configurations.name,\n privateKey: configurations.privateKey,\n useServerSigner: configurations.useServerSigner === 'true',\n };\n const coinbase = new Coinbase(coinbaseOptions);\n console.log(`Coinbase configured: `, coinbase);\n const user = await coinbase.getDefaultUser();\n console.log(`User: `, user);\n\n // Create a new Wallet for the User\n const wallet = await user.createWallet({\n networkId: Coinbase.networks.BaseSepolia,\n });\n console.log(`Wallet successfully created: `, wallet.toString());\n\n let exportedWallet;\n if (!configurations.useServerSigner) {\n exportedWallet = await wallet.export();\n }\n\n const address = await wallet.getDefaultAddress();\n\n return {\n ...exportedWallet,\n walletId: wallet.getId(),\n address: address?.getId(),\n };\n};\n","tools":[],"config":[{"BasicConfig":{"key_name":"name","description":"","required":true,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"privateKey","description":"","required":true,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"useServerSigner","description":"","required":false,"type":null,"key_value":null}}],"description":"Tool for creating a Coinbase wallet","keywords":["coinbase","wallet","creator","shinkai"],"input_args":{"type":"object","properties":{},"required":[]},"output_arg":{"json":""},"activated":false,"embedding":[0.106608376,0.41127837,-0.25463364,-0.32248706,-0.104817785,0.121706314,-0.03151182,0.31224874,-0.2831944,-0.0034338525,-0.19127713,-0.008223534,0.22638485,-0.09930447,-0.28486118,-0.63315773,-0.09636158,-0.61439145,-1.1654487,0.38228172,-0.17458896,0.8497766,-0.43269163,0.15335917,-0.28330773,-0.2640039,0.0034893155,-0.5224032,-1.484486,-2.4849114,0.8048678,1.0833544,-0.5426029,-0.5558562,-0.05434633,-0.31097323,-0.17190091,0.5118817,-0.42390314,-0.31034046,0.35211498,0.27447006,-0.65473056,0.023174979,-0.058990005,-0.44352376,0.54819924,-0.39887503,0.26282844,0.40640676,-0.0002581142,-0.47739455,0.6547748,-0.03268323,-0.35610425,0.12967776,-0.26997164,-0.3305793,0.10562223,0.4433401,-0.040558998,0.330962,-3.8495562,0.22852053,1.3840722,0.042035088,0.50890285,-0.054913018,-0.3909843,0.62089247,-0.010075815,-0.11408972,-0.54617864,0.043472372,0.38645452,-0.1113597,0.75728303,-0.10065475,0.62765956,0.011410739,0.06718382,0.77804315,0.2650589,-0.18410273,-0.42870727,0.22244582,-0.1088205,-0.53857994,0.04582644,0.0972573,0.08662674,0.45195132,0.2139351,-0.111990795,-0.47918832,-0.25548273,0.016256634,0.9064493,0.47019023,2.697148,0.24152085,0.2536752,0.34584814,-1.0840755,0.79801327,-0.23469439,0.08639613,-0.4534926,0.16087207,-0.2777297,0.9485559,-0.2849575,0.1207515,0.256539,0.35246587,0.32869238,-0.04498246,0.14251262,-0.4105745,0.4183277,-0.26015264,0.2240419,-1.085044,-0.045694605,-0.14072339,-0.07030669,-0.4911205,0.2826326,-0.3474514,-0.5368858,0.21524921,-0.41232717,-0.43492627,0.008838819,-0.040434144,0.6099907,0.01878146,-0.66687995,-0.43180692,-0.02428811,0.30693483,-0.7558724,0.5635787,-0.18748997,0.08487825,-0.37317407,0.3038798,-0.035463236,-0.51118016,-0.600597,-0.010352377,-0.0957617,0.6385061,-0.30879894,0.64587414,-0.53867763,0.020915512,-0.5058636,-0.46977317,-0.086883,-0.22218241,-0.23072702,0.25326255,1.0340672,0.7886596,-0.31496307,0.48080894,0.27734283,0.5118715,-0.70576495,0.2801963,-0.117037974,0.4662382,0.15260935,-0.5982343,0.050490092,-0.41207424,-0.026747614,0.35468322,-0.36062858,-0.7574638,0.34588605,-0.93115747,-1.0822469,-0.7088281,0.3006152,0.4463941,0.22230771,0.10920119,0.72157216,-0.46959072,1.7862909,-0.026602164,-0.046276525,-0.101544656,0.14876622,-0.2731639,0.37518954,0.24139847,-0.28620204,-0.2476773,-0.30634525,-0.19084437,0.22665034,-0.20038769,-0.4942695,0.4065581,0.8478193,-0.1943736,-0.07214823,0.09502381,0.1875737,0.83186984,0.91354287,1.1263794,-0.18895322,0.5766026,-0.037720766,1.3292009,0.14854592,0.63262135,0.24933234,-0.77803963,-0.33052447,-0.7650778,-0.37940335,0.5418016,0.051896956,-0.3578351,0.0016623922,0.6015654,0.628299,0.61673456,0.4733826,1.2288805,0.5030629,-0.010545418,0.03804444,0.17318018,-1.260278,-0.14013255,0.27815554,-0.54101306,-0.7199203,-0.16819221,-0.7132447,0.21671882,-0.6276087,0.088249184,2.020304,0.36894408,-0.14315441,0.38600516,-0.21624562,-0.038657956,-0.18285182,-1.4090341,0.3883453,-0.4969522,0.4531218,-0.09483522,0.1403723,-0.12007758,0.21613769,-0.33294532,-0.4450294,-0.9099992,-0.23876816,-0.11038546,-0.38953996,0.057502277,1.1098955,0.6361157,0.4614854,-0.09154616,-0.015582925,0.70769066,0.46275842,-0.40131098,-0.046300434,0.111293405,-0.08412773,0.76974195,0.3433804,0.35255334,-0.5403275,-0.28918272,0.06919776,-0.79234564,-0.15432379,-0.087078966,-0.38518324,-0.5070818,0.6790647,1.6665665,1.2250792,1.1262922,0.41495696,-0.09596672,0.31750906,-0.13302247,0.5684142,0.096760765,0.17608225,-1.3890605,-0.37464488,0.40351182,-0.61909026,0.044795968,0.110169545,0.26001665,0.50215644,-0.0068575554,0.39997515,0.019612342,-0.45005175,-0.20951176,0.5002105,-0.27554086,-2.350778,-0.23506549,-0.13005003,-0.4562121,0.024141207,0.19423743,0.7284635,0.27046913,0.091427475,-0.27290818,2.4457474,0.35267624,-0.14124544,-0.3587356,0.6354651,0.44762415,0.5347106,0.1576927,-0.07035433,-0.62669516,-0.5964982,0.022721335,0.8997787,-0.088240206,-0.22340164,0.113081306,-0.093459226,-0.3731728,-1.0652199,0.15207438,-0.08235215,-0.38412276,-0.12380577,0.16916335,-0.37506893,0.9809917,0.505852,-0.27879626,-0.1356077,-0.87216944,1.4884256,-0.089887686,-0.35735047,-0.18952346,-0.058308598,-0.11398005,-0.80062836,0.46958363,-0.010470718,0.21347134,-0.19876844,0.04650094,-0.75897115,0.24202266,0.17335476,0.5694237,-0.1755247,0.046171527,0.4265713,0.5958072,0.27597517,-0.091395356,-0.13192715,-0.6837542,-0.10110636],"result":{"type":"object","properties":{"address":{"nullable":true,"type":"string"},"seed":{"nullable":true,"type":"string"},"walletId":{"nullable":true,"type":"string"}},"required":[]},"sql_tables":null,"sql_queries":null,"file_inbox":null,"oauth":null,"assets":null},false]} \ No newline at end of file diff --git a/tools/coinbase-get-balance/.tool-dump.test.json b/tools/coinbase-get-balance/.tool-dump.test.json new file mode 100644 index 0000000..1185f10 --- /dev/null +++ b/tools/coinbase-get-balance/.tool-dump.test.json @@ -0,0 +1 @@ +{"type":"Deno","content":[{"toolkit_name":"coinbase-get-balance","name":"Coinbase Balance Getter","author":"Shinkai","version":"1.0.0","js_code":"import { Coinbase, CoinbaseOptions } from 'npm:@coinbase/coinbase-sdk@0.0.16';\n\ntype WalletBalances = { [key: string]: number };\n\ntype Configurations = {\n name: string;\n privateKey: string;\n walletId?: string;\n useServerSigner?: string;\n};\ntype Parameters = {\n walletId?: string;\n};\ntype Result = {\n message: string;\n balances: WalletBalances | null;\n};\nexport type Run, I extends Record, R extends Record> = (config: C, inputs: I) => Promise;\n\nexport const run: Run = async (\n configurations,\n params,\n): Promise => {\n const coinbaseOptions: CoinbaseOptions = {\n apiKeyName: configurations.name,\n privateKey: configurations.privateKey,\n useServerSigner: configurations.useServerSigner === 'true',\n debugging: true,\n };\n const coinbase = new Coinbase(coinbaseOptions);\n const user = await coinbase.getDefaultUser();\n\n // Prioritize walletId from Params over Config\n const walletId = params.walletId || configurations.walletId;\n\n // Throw an error if walletId is not defined\n if (!walletId) {\n throw new Error('walletId must be defined in either params or config');\n }\n\n const wallet = await user.getWallet(walletId);\n console.log(`Wallet retrieved: `, wallet.toString());\n\n // Retrieve the list of balances for the wallet\n const balances = await wallet.listBalances();\n console.log(`Balances: `, balances);\n\n // Convert balances to WalletBalances\n const balanceMap: WalletBalances = {};\n for (const [currency, amount] of balances) {\n balanceMap[currency] = amount.toNumber();\n }\n\n return {\n message: `Balances: ${JSON.stringify(balanceMap)}`,\n balances: balanceMap,\n };\n};\n","tools":[],"config":[{"BasicConfig":{"key_name":"name","description":"The name of the Coinbase wallet","required":true,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"privateKey","description":"The private key of the Coinbase wallet","required":true,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"walletId","description":"Optional wallet ID for specific wallet selection","required":false,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"useServerSigner","description":"Optional server signer configuration","required":false,"type":null,"key_value":null}}],"description":"Tool for getting the balance of a Coinbase wallet after restoring it","keywords":["coinbase","balance","shinkai"],"input_args":{"type":"object","properties":{"walletId":{"type":"string","description":"Optional wallet ID to get balance for a specific wallet"}},"required":[]},"output_arg":{"json":""},"activated":false,"embedding":[-0.1122051,0.21792355,-0.019444812,-0.32676318,0.017230723,-0.042694233,0.12454068,0.23506877,-0.049858324,-0.39198625,-0.2356008,0.14091831,0.025426041,-0.14607342,0.2663238,-0.17875119,0.13934344,-0.46660352,-1.2717104,-0.044658728,0.22778314,0.56215423,-0.6181404,0.37758034,-0.56418365,-0.14707409,-0.48298508,-0.003713008,-1.6355104,-2.3401878,0.020875055,1.0987378,-0.068168,-0.25705624,-0.6406843,-0.05842889,0.046699405,0.30345416,-0.596434,-0.41274422,0.08122185,0.43440035,-0.5265702,0.0362359,-0.0654276,0.017466605,0.5859141,-0.49892268,-0.07515541,0.6399467,0.13092819,-0.02034505,0.58803767,-0.49216923,0.0382146,0.038736127,0.13882983,-0.6310905,0.26340827,0.32647747,0.024176609,0.10194284,-4.3208013,-0.040059604,0.69316846,-0.21621847,0.4555591,0.21492131,-0.28525597,0.19751486,-0.4944448,-0.21758324,-0.2561371,0.35391644,0.4861079,0.069663204,0.7510352,-0.108434245,0.4958588,-0.23860747,-0.17986467,0.8263099,0.31614143,0.0266728,-0.4415525,0.32278436,-0.059656236,-0.72129464,0.35087603,0.118561104,0.072357774,0.25650117,0.0114029525,-0.050457455,-0.36058816,-0.029316857,0.05345415,0.91371477,0.099857435,3.0752783,0.68999904,0.4103311,0.50830394,-0.4709496,0.8439158,-0.7339027,0.27937278,-0.42391467,0.64193827,-0.010285383,0.6696393,-0.16732915,0.38181823,0.46825826,0.44639584,-0.04503636,-0.7767281,-0.027618747,-0.45242998,0.5186432,-0.60994107,0.1560903,-0.70730853,-0.086867385,-0.33560067,-0.31328416,-0.4761167,0.35943118,-0.16717035,0.28757736,0.7505316,-0.4674905,-0.94920105,-0.24537762,-0.22457483,0.68390805,-0.055820018,-0.5679477,-0.5199877,-0.3298007,-0.23557621,-1.0684874,0.70712435,-0.6234385,0.17502213,-0.0074590556,0.5305823,-0.23091885,-0.26135948,-0.26235065,-0.42848885,0.3799429,0.3621992,0.20847175,0.74951464,-0.04785835,0.103263736,-0.074650764,-0.48663232,-0.04685007,0.003893502,-0.21457385,0.5851617,0.7577644,0.9477838,-0.39980376,0.5123923,0.17587909,0.40257978,-0.6337289,0.48085725,0.22692579,-0.1308599,-0.17204627,-0.3260076,-0.0532555,-0.034859188,0.14537829,0.38741913,-0.3559643,-1.2954301,0.65634984,-0.73787755,-0.6614718,-0.16321383,0.27331,0.39565712,-0.21289161,0.7244392,0.60400033,-0.63224274,1.6804485,-0.421256,-0.06698799,-0.49296844,-0.043947622,-0.2732744,0.22410235,0.609065,-0.17217714,-0.46537006,0.043895226,0.034387194,0.47640026,-0.6910904,-0.14865017,0.26914796,0.022420472,-0.07786381,-0.211391,0.5306046,0.14311999,0.014625061,0.6163252,0.38819557,-0.27364784,0.32498214,0.05358205,1.027975,0.20983253,0.2098367,0.15997908,-0.8947806,-0.6818938,-0.6106497,0.011262834,0.34579194,0.024799298,0.21171358,0.41551903,0.41326112,0.23885198,0.30851015,0.051665213,1.3319033,0.27679336,-0.063311286,0.10576472,-0.008384563,-0.8188471,0.11795208,0.05702358,-0.69708276,-0.1623407,-0.25308907,-0.5819838,0.5912054,-0.34703276,0.28800455,1.8632154,0.52673703,-0.31558284,0.41940686,0.034290798,0.10077952,0.35029146,-1.1312464,0.110920474,-0.52502084,0.26309755,0.07871712,-0.1673185,-0.2582632,0.16581045,0.07132866,-0.4274863,-0.77864736,0.62542224,0.29736987,-0.48618934,0.21518765,1.3097459,0.804146,-0.019944578,-0.20996451,-0.25136352,0.3375256,0.33029765,-0.31664985,0.23771079,0.5451549,-0.15576157,0.52026814,0.15959534,0.397811,-0.08771992,-0.30593848,-0.015177786,-0.9437044,-0.13004494,-0.0895731,-0.102244705,-0.58599967,0.7524687,1.7816204,0.73901916,0.8541392,0.30481288,-0.05781647,0.6458275,-0.3604158,0.74742454,-0.40308708,0.39093086,-1.0534573,-0.5323918,0.4550317,-0.63979226,-0.043461435,-0.24512357,-0.037757806,0.47987717,0.23262349,0.48169845,0.14022627,-0.667673,-0.7440694,0.26770002,-0.055000126,-2.257101,0.15032548,-0.59528404,-0.44336444,-0.0726046,-0.17490539,0.35630667,0.1335873,0.29353437,-0.25075904,1.7107471,0.16393793,-0.32271257,-0.70558083,0.018164277,0.875983,0.59886837,0.23601161,0.06945345,-0.7084349,0.008139738,-0.13749018,0.7753262,0.03842848,0.14583483,-0.14556053,0.008987986,-0.33083373,-0.889037,0.27736363,-0.32143906,-0.058217615,-0.044049975,0.2679112,-0.5327888,1.3052187,0.3804539,-0.33331263,0.07149097,-0.3488194,1.4735043,-0.11365883,-0.19220917,-0.47264743,-0.23412628,-0.087442644,-0.09439272,0.17180006,-0.43823156,-0.20659213,0.3114082,-0.102425635,-0.34236217,0.1895842,0.28456134,0.6217086,0.6311034,0.21342117,0.42619845,0.3926774,-0.1294566,0.02903571,-0.30436456,-0.9850829,0.3401345],"result":{"type":"object","properties":{"balances":{"additionalProperties":{"description":"Balance amount for a specific token","type":"number"},"description":"Map of token symbols to their respective balances","required":[],"type":"object"},"message":{"description":"Status message about the balance retrieval operation","type":"string"}},"required":["message","balances"]},"sql_tables":null,"sql_queries":null,"file_inbox":null,"oauth":null,"assets":null},false]} \ No newline at end of file diff --git a/tools/coinbase-get-balance/index.test.ts b/tools/coinbase-get-balance/index.test.ts index d02cc67..4f423f7 100644 --- a/tools/coinbase-get-balance/index.test.ts +++ b/tools/coinbase-get-balance/index.test.ts @@ -1,6 +1,6 @@ import { expect } from 'jsr:@std/expect/expect'; -import { definition } from './index.ts'; +import { run } from './tool.ts'; -Deno.test('exists definition', () => { - expect(definition).toBeInstanceOf(Object); -}); +// Deno.test('exists definition', () => { +// expect(definition).toBeInstanceOf(Object); +// }); diff --git a/tools/coinbase-get-my-address/.tool-dump.test.json b/tools/coinbase-get-my-address/.tool-dump.test.json new file mode 100644 index 0000000..0adeafb --- /dev/null +++ b/tools/coinbase-get-my-address/.tool-dump.test.json @@ -0,0 +1 @@ +{"type":"Deno","content":[{"toolkit_name":"coinbase-get-my-address","name":"Coinbase My Address Getter","author":"Shinkai","version":"1.0.0","js_code":"import { Coinbase, CoinbaseOptions } from 'npm:@coinbase/coinbase-sdk@0.0.16';\n\ntype Configurations = {\n name: string;\n privateKey: string;\n walletId?: string;\n useServerSigner?: string;\n};\ntype Parameters = {\n walletId?: string;\n};\ntype Result = {\n address: string;\n};\nexport type Run, I extends Record, R extends Record> = (config: C, inputs: I) => Promise;\n\nexport const run: Run = async (\n configurations: Configurations,\n params: Parameters,\n): Promise => {\n const coinbaseOptions: CoinbaseOptions = {\n apiKeyName: configurations.name,\n privateKey: configurations.privateKey,\n useServerSigner: configurations.useServerSigner === 'true',\n };\n const coinbase = new Coinbase(coinbaseOptions);\n const user = await coinbase.getDefaultUser();\n\n // Prioritize walletId from Params over Config\n const walletId = params.walletId || configurations.walletId;\n\n // Throw an error if walletId is not defined\n if (!walletId) {\n throw new Error('walletId must be defined in either params or config');\n }\n\n const wallet = await user.getWallet(walletId);\n console.log(`Wallet retrieved: `, wallet.toString());\n\n // Retrieve the list of balances for the wallet\n const address = await wallet.getDefaultAddress();\n console.log(`Default Address: `, address);\n\n return {\n address: address?.getId() || '',\n };\n};\n","tools":[],"config":[{"BasicConfig":{"key_name":"name","description":"The name of the Coinbase wallet","required":true,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"privateKey","description":"The private key of the Coinbase wallet","required":true,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"walletId","description":"Optional wallet ID for specific wallet selection","required":false,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"useServerSigner","description":"Optional server signer configuration","required":false,"type":null,"key_value":null}}],"description":"Tool for getting the default address of a Coinbase wallet","keywords":["coinbase","address","shinkai"],"input_args":{"type":"object","properties":{"walletId":{"type":"string","description":"The ID of the Coinbase wallet to get the address from"}},"required":[]},"output_arg":{"json":""},"activated":false,"embedding":[-0.17932753,0.15964293,-0.41342285,-0.35331523,-0.10128805,-0.103858195,0.0112680495,0.82166934,0.03933646,-0.08853404,-0.3104675,0.008514911,0.17749289,0.06472419,0.15668456,-0.57975745,0.119621426,-0.7146136,-0.67832845,0.34949583,0.24846318,1.2754143,-0.4169299,-0.045812353,-0.2568414,-0.29605535,-0.22251318,-0.39910167,-1.4526182,-2.3240116,0.22368193,1.2659607,-0.10700137,0.04635729,-0.7943327,0.056435622,0.11881925,0.37792012,-0.5881921,-0.67314845,0.22995919,0.22469546,-0.25196442,-0.2977796,-0.2808156,0.16371796,0.5224911,-0.17036061,0.08240048,0.55401254,0.5550245,-0.06726978,0.37150687,-1.0110029,-0.19860011,0.3690119,0.062547445,-0.32751927,-0.13983053,0.65957195,-0.11019101,0.28199273,-4.1167026,-0.010445392,1.1536654,-0.044021882,-0.19383013,-0.20445186,-0.45228192,0.3846407,-0.28967196,-0.3215696,-0.50890607,0.55178374,0.6466307,0.50096804,0.40960896,-0.015315123,0.9545287,-0.082977295,-0.013413724,0.64457166,0.17772853,0.32607895,0.028716639,0.20834231,-0.280965,0.022425786,0.06716788,0.67692375,-0.039648425,-0.1904221,-0.42792153,0.3081607,-0.34659982,-0.07910152,-0.13672504,0.87124807,0.25957933,2.7408013,0.82253426,0.33271676,0.3830495,-1.0432297,1.0111794,-0.3639133,-0.27953902,-0.38907802,0.5439809,-0.1665577,0.2764875,-0.3984063,0.5602261,0.39349622,0.06076364,0.14092079,-0.33769405,-0.4078202,-0.24881178,0.5352551,-0.41751012,-0.06376307,-0.91029376,-0.3063765,-0.229336,-0.03493604,0.036654722,0.3033824,-0.12646031,0.16920257,0.8081108,-0.68709177,-0.87597513,-0.20345353,0.05654283,0.5672903,0.25627428,-0.47784224,-0.48938382,-0.23010993,0.033031926,-1.432347,0.8707811,-0.11786066,0.53551245,-0.18216951,0.56844187,-0.45306367,-0.871271,0.06953817,-0.01883347,0.10133599,0.8850505,0.3210193,0.5014882,-0.68166435,0.067953594,-0.26241648,-0.09095915,0.04191948,-0.085172355,-0.29178366,0.49644402,1.0346931,0.49191988,-0.21278837,0.1552579,0.42457995,0.37517163,-0.6189191,0.65872675,0.2103756,0.4102558,0.28160647,-0.45155466,-0.2631366,-0.13053115,-0.17375982,0.34568825,-0.3599729,-1.2549177,0.38902745,-0.564535,-0.63555527,0.17842765,-0.086037025,0.6811883,0.0031095045,0.45187286,0.16761576,-0.6281824,1.3175262,-0.2932405,-0.11214225,-0.59985596,-0.12824976,-0.2609207,0.34946337,0.73185855,0.10807916,-0.6177121,-0.3831613,0.05921615,0.53959525,-0.6342268,-0.07955518,0.3043292,0.6878448,-0.46822035,0.06468081,0.76058364,-0.7113683,0.29584336,0.44136515,0.69938636,-0.22730197,0.3251933,0.11502963,0.77010596,-0.032495484,0.1063212,-0.19553521,-1.0336113,-0.5114762,-1.0078665,-0.18042813,0.49700218,0.45784438,-0.23957342,0.4018757,-0.06607162,0.15405571,0.6597649,0.2194557,0.95349145,0.806748,-0.1722436,-0.027636163,-0.032721918,-0.8663484,0.033776123,0.081975594,-0.49234384,-0.37394935,0.35717422,-0.77462137,0.7966627,-0.15514413,0.08736948,1.6222768,0.55413777,-0.029605638,-0.007258404,0.22146,0.1714007,-0.025337152,-1.3562571,0.0052703926,-0.028748669,0.99206585,0.04683815,-0.0476064,-0.037525747,0.4543084,0.00021454127,-0.5230759,-0.7134363,-0.0066314265,0.24200809,-0.4915258,0.03015158,1.1206086,0.92073715,-0.08053277,-0.5278128,-0.32479218,0.17775685,0.36103645,-0.32219997,0.053983346,0.2498126,-0.120526075,0.90176004,0.105171755,0.18076822,-0.14823234,-0.035519555,0.15436316,-1.0244967,-0.06540312,-0.09376261,-0.6566599,-0.28878072,1.0337374,1.6364617,0.88323754,0.49055243,0.27557373,0.022975512,0.92566395,-0.13089591,0.46502104,-0.4719314,0.30416837,-0.93894005,-0.5786668,0.47886258,-0.5090064,-0.3169286,-0.115220055,0.22271526,0.7059446,0.26687512,0.37598094,-0.2801255,-0.5246223,-0.7853387,0.13136622,-0.29093853,-2.1983619,-0.061054446,-0.6261363,-0.60235673,-0.32901666,-0.36539868,0.47864866,0.0012961347,0.29893708,-0.119530365,1.6799016,0.31920388,-0.53568,-0.44493467,0.2224508,0.7926569,0.6158743,0.31482908,0.18538722,-0.78197426,-0.07565202,0.048063297,1.2009664,0.1422099,0.052135646,-0.17165433,-0.039600164,-0.4821769,-1.4015799,-0.07014266,-0.11032796,-0.20598231,-0.18786888,-0.19679819,-0.29310876,1.2269748,0.7410622,-0.7246054,-0.43472102,-0.3305997,1.2603365,0.12693687,-0.09097959,-0.48109823,-0.9074406,0.096925765,0.067318454,0.22055043,0.2542562,0.24284221,-0.23175079,0.007990668,-0.15167749,0.2416907,0.010765458,0.41447288,0.30766064,0.110257745,0.2081362,0.66511655,-0.21753985,0.26317722,-0.09763156,-0.93785083,0.6041742],"result":{"type":"object","properties":{"address":{"description":"The Ethereum address of the Coinbase wallet","type":"string"}},"required":["address"]},"sql_tables":null,"sql_queries":null,"file_inbox":null,"oauth":null,"assets":null},false]} \ No newline at end of file diff --git a/tools/coinbase-get-my-address/index.test.ts b/tools/coinbase-get-my-address/index.test.ts index d02cc67..4f423f7 100644 --- a/tools/coinbase-get-my-address/index.test.ts +++ b/tools/coinbase-get-my-address/index.test.ts @@ -1,6 +1,6 @@ import { expect } from 'jsr:@std/expect/expect'; -import { definition } from './index.ts'; +import { run } from './tool.ts'; -Deno.test('exists definition', () => { - expect(definition).toBeInstanceOf(Object); -}); +// Deno.test('exists definition', () => { +// expect(definition).toBeInstanceOf(Object); +// }); diff --git a/tools/coinbase-get-transactions/.tool-dump.test.json b/tools/coinbase-get-transactions/.tool-dump.test.json new file mode 100644 index 0000000..965e0d8 --- /dev/null +++ b/tools/coinbase-get-transactions/.tool-dump.test.json @@ -0,0 +1 @@ +{"type":"Deno","content":[{"toolkit_name":"coinbase-get-transactions","name":"Coinbase Transactions Getter","author":"Shinkai","version":"1.0.0","js_code":"import { Coinbase, CoinbaseOptions } from 'npm:@coinbase/coinbase-sdk@0.0.16';\n\ntype Configurations = {\n name: string;\n privateKey: string;\n walletId: string;\n};\ntype Parameters = {};\ntype Result = { tableCsv: string; rowsCount: number; columnsCount: number };\nexport type Run, I extends Record, R extends Record> = (config: C, inputs: I) => Promise;\n\nexport const run: Run = async (\n configurations: Configurations,\n _parameters: Parameters,\n): Promise => {\n const coinbaseOptions: CoinbaseOptions = {\n apiKeyName: configurations.name,\n privateKey: configurations.privateKey,\n };\n const coinbase = new Coinbase(coinbaseOptions);\n const user = await coinbase.getDefaultUser();\n\n // Prioritize walletId from Params over Config\n const walletId = configurations.walletId;\n\n const wallet = await user.getWallet(walletId);\n console.log(`Wallet retrieved: `, wallet.toString());\n\n // Retrieve the list of balances for the wallet\n const address = await wallet.getDefaultAddress();\n const transactions = (await address?.listTransfers()) ?? [];\n\n // Convert transactions to CSV format\n const headers = [\n 'transferId',\n 'networkId',\n 'fromAddressId',\n 'destinationAddressId',\n 'assetId',\n 'amount',\n 'transactionHash',\n 'transactionLink',\n 'status',\n ];\n const rows = transactions.map((tx) => [\n tx.getId(),\n tx.getNetworkId(),\n tx.getFromAddressId(),\n tx.getDestinationAddressId(),\n tx.getAssetId(),\n tx.getAmount().toString(),\n tx.getTransactionHash(),\n tx.getTransactionLink(),\n tx.getStatus(),\n ]);\n const tableCsv = [headers, ...rows].map((row) => row.join(';')).join('\\n');\n\n return Promise.resolve({\n tableCsv,\n rowsCount: transactions.length,\n columnsCount: headers.length,\n });\n};\n","tools":[],"config":[{"BasicConfig":{"key_name":"name","description":"","required":true,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"privateKey","description":"","required":true,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"walletId","description":"","required":true,"type":null,"key_value":null}}],"description":"Tool for getting the transactions of a Coinbase wallet after restoring it","keywords":["coinbase","balance","shinkai"],"input_args":{"type":"object","properties":{},"required":[]},"output_arg":{"json":""},"activated":false,"embedding":[0.16925259,0.19336475,-0.3109297,-0.039204508,-0.13054809,-0.34281373,0.042999133,0.55347544,-0.1557864,-0.19078992,-0.24169588,0.16050482,-0.07783348,0.03402864,0.27587122,-0.4300525,0.06291229,-0.31605762,-1.3911097,0.30489752,0.4740519,0.83545697,-0.59563756,0.302229,-0.5362712,-0.19890837,-0.36951882,-0.042009443,-1.4895351,-2.2981503,0.1976608,1.2256205,-0.3871849,-0.20203742,-0.4412474,-0.24111533,0.06941593,0.33441943,-0.55429214,-0.49527937,0.058845058,0.46884236,-0.684995,-0.0112426225,0.04067769,-0.24195337,0.5260498,-0.48140416,0.2484336,0.6262324,0.0061545745,0.13629545,0.594229,-0.6498375,-0.06213381,-0.024935724,-0.08060902,-0.37224773,0.13439868,0.31999916,-0.03608239,0.0027501956,-4.02535,0.056213092,0.7044405,-0.15491644,0.36956802,0.44447035,-0.573741,0.5601373,-0.4608069,-0.32819134,-0.51722616,0.21799603,0.51517683,-0.15655679,0.7445531,0.36054525,0.39726555,-0.1972068,-0.055746485,0.948037,0.06723908,0.051220223,-0.5470468,0.39737868,-0.14596295,-0.46307644,0.24408227,0.2250982,0.21850787,0.23179495,0.07397965,-0.20215729,-0.26786885,-0.058684975,0.100640446,1.1255865,0.37955603,3.003583,0.6364159,0.70454,0.3449511,-0.783787,0.7464417,-0.5484832,-0.11802791,-0.23625429,0.46603435,-0.15890005,0.7391749,-0.3760193,0.7570015,0.28463024,0.1649248,0.10714777,-0.79222786,-0.034782384,-0.13381101,0.35152757,-0.46387595,0.27746758,-0.5403326,-0.14051175,-0.49187753,-0.27269116,-0.07913071,0.30645147,-0.15724663,-0.03861757,0.6580126,-0.6525049,-0.9734173,-0.007423454,0.0057444684,0.33180004,-0.15739943,-0.6685441,-0.62532794,-0.5481901,-0.07224342,-1.1472703,1.0721201,-0.1827153,0.15122741,-0.3352298,0.46748245,-0.3385545,-0.26504517,-0.10017018,-0.15581384,0.13035673,0.16592658,-0.11092252,0.5865137,-0.2662667,0.07384996,-0.28651136,-0.7367664,0.24822763,-0.21085498,-0.11118903,0.73593247,0.85091907,0.9836215,-0.7230869,0.5753839,0.20492187,0.31841344,-0.4341326,0.45453894,0.031533338,-0.107394956,0.021345347,-0.5059574,-0.05648998,-0.015153021,-0.26773927,0.01916881,-0.28712988,-0.9005168,0.562127,-0.6722366,-0.7458022,-0.03604183,0.16324425,0.24371967,-0.07625256,0.54241717,0.49677145,-0.72900534,1.8670322,-0.479501,0.11911194,-0.34157392,-0.22788636,-0.032269422,0.29448202,0.36847284,0.1312088,-0.2405462,0.113498315,-0.1389235,0.40899345,-0.6186118,-0.17319115,0.25173354,0.36724806,-0.3623917,-0.4949983,0.30823615,0.087303035,0.47603455,0.5068521,0.44679856,-0.14118029,0.5918366,-0.09932922,0.82454556,-0.023810968,0.7300393,0.37037715,-0.56222284,-0.54878527,-0.61380464,-0.19734882,0.49692428,0.5359911,0.062600285,0.109496295,0.017320544,0.47013986,0.50148237,0.38402793,1.4785789,0.29964286,-0.38948953,-0.06508373,0.11701274,-0.84249365,0.20711926,0.3408258,-0.3878427,-0.4466251,-0.20268774,-0.49308315,0.73473155,0.12266129,0.31830004,1.8686404,0.47210944,-0.22385243,0.6687528,-0.35555094,0.27971923,-0.13979477,-1.4279561,-0.06260148,-0.21564257,0.27409208,0.23448211,-0.14771119,0.17397054,0.28156644,0.2049909,-0.451668,-0.8093298,0.65968525,0.33277026,-0.2324273,0.06474328,1.376619,1.0473466,0.22885406,-0.53884,-0.19854085,0.3424329,0.1060681,-0.36822245,0.25285268,0.42234084,-0.34062836,0.89859575,0.3273117,0.43744135,-0.1265469,-0.056891445,0.22342396,-0.98753196,-0.2396236,-0.100594625,-0.77528757,-0.8034485,0.8871108,2.1022525,0.58989704,0.4520424,0.36766866,0.115321025,0.3877527,-0.31387237,0.82794565,-0.29245496,0.48306432,-1.0535579,-0.72926724,0.6384178,-0.63804954,-0.20296723,-0.13029386,0.09505867,0.55600166,0.23006043,0.41020006,0.15756688,-0.5267177,-0.52579707,0.39963287,-0.43876588,-2.097354,0.16948931,-0.65887713,-0.54331464,-0.24390483,0.0118664745,0.3423066,-0.2960305,0.25839934,-0.2573114,1.6646926,0.07939121,-0.9080276,-0.95527864,-0.12138058,1.0430968,0.32054827,0.15474294,-0.021429494,-0.39041814,0.001073323,-0.2588204,0.8949996,0.054565392,0.2298509,-0.28955892,-0.04975786,-0.40022087,-0.95158064,0.021978501,-0.48953414,-0.20269717,-0.2161554,0.2604083,-0.24258533,1.2542185,0.41163054,-0.4763426,-0.27171656,-0.43820408,1.1436303,0.090385795,-0.7019678,-0.45494652,-0.4181419,-0.07761314,-0.14312065,0.23557039,-0.3436189,-0.29927588,0.23723227,-0.021425545,-0.597897,0.0766636,-0.05515675,0.92934424,0.6106546,-0.013847895,0.6391535,0.6345254,-0.049954813,0.25116992,0.05438469,-0.701619,0.19964059],"result":{"type":"object","properties":{"columnsCount":{"type":"number"},"rowsCount":{"type":"number"},"tableCsv":{"type":"string"}},"required":["tableCsv","rowsCount","columnsCount"]},"sql_tables":null,"sql_queries":null,"file_inbox":null,"oauth":null,"assets":null},false]} \ No newline at end of file diff --git a/tools/coinbase-get-transactions/index.test.ts b/tools/coinbase-get-transactions/index.test.ts index d02cc67..4f423f7 100644 --- a/tools/coinbase-get-transactions/index.test.ts +++ b/tools/coinbase-get-transactions/index.test.ts @@ -1,6 +1,6 @@ import { expect } from 'jsr:@std/expect/expect'; -import { definition } from './index.ts'; +import { run } from './tool.ts'; -Deno.test('exists definition', () => { - expect(definition).toBeInstanceOf(Object); -}); +// Deno.test('exists definition', () => { +// expect(definition).toBeInstanceOf(Object); +// }); diff --git a/tools/coinbase-send-tx/.tool-dump.test.json b/tools/coinbase-send-tx/.tool-dump.test.json new file mode 100644 index 0000000..ffeb23d --- /dev/null +++ b/tools/coinbase-send-tx/.tool-dump.test.json @@ -0,0 +1 @@ +{"type":"Deno","content":[{"toolkit_name":"coinbase-send-tx","name":"Coinbase Transaction Sender","author":"Shinkai","version":"1.0.0","js_code":"import { Coinbase, CoinbaseOptions, Transfer } from 'npm:@coinbase/coinbase-sdk@0.0.16';\n\ntype Configurations = {\n name: string;\n privateKey: string;\n walletId?: string;\n seed?: string;\n useServerSigner?: string;\n};\ntype Parameters = {\n recipient_address: string;\n assetId: string;\n amount: string;\n};\ntype Result = {\n transactionHash: string;\n transactionLink: string;\n status: string;\n};\nexport type Run, I extends Record, R extends Record> = (config: C, inputs: I) => Promise;\n\nexport const run: Run = async (\n configurations: Configurations,\n params: Parameters,\n): Promise => {\n const coinbaseOptions: CoinbaseOptions = {\n apiKeyName: configurations.name,\n privateKey: configurations.privateKey,\n useServerSigner: configurations.useServerSigner === 'true',\n debugging: true,\n };\n const coinbase = new Coinbase(coinbaseOptions);\n console.log(`Coinbase configured: `, coinbase);\n const user = await coinbase.getDefaultUser();\n console.log(`User: `, user);\n\n // Check if seed exists or useServerSigner is true, but not both\n if (!configurations.seed && configurations.useServerSigner !== 'true') {\n throw new Error(\n 'Either seed must be provided or useServerSigner must be true',\n );\n }\n if (configurations.seed && configurations.useServerSigner === 'true') {\n throw new Error(\n 'Both seed and useServerSigner cannot be true at the same time',\n );\n }\n\n // Prioritize walletId from Params over Config\n const walletId = configurations.walletId;\n let wallet;\n\n if (configurations.useServerSigner === 'true') {\n // Use getWallet if useServerSigner is true\n if (!walletId) {\n throw new Error('walletId must be provided when useServerSigner is true');\n }\n wallet = await user.getWallet(walletId);\n console.log(`Wallet retrieved using server signer: `, wallet.toString());\n } else {\n if (walletId) {\n // Retrieve existing Wallet using walletId\n wallet = await user.importWallet({\n walletId,\n // it's not going to be empty but to quiet the type error\n seed: configurations.seed || '',\n });\n console.log(`Wallet retrieved: `, wallet.toString());\n } else {\n // Create a new Wallet for the User\n wallet = await user.createWallet({\n networkId: Coinbase.networks.BaseSepolia,\n });\n console.log(`Wallet successfully created: `, wallet.toString());\n }\n }\n\n // Retrieve the list of balances for the wallet\n let balances = await wallet.listBalances();\n console.log(`Balances: `, balances);\n\n // If no balances, call the faucet and then list balances again\n if (balances.size === 0) {\n const faucetTransaction = await wallet.faucet();\n console.log(\n `Faucet transaction completed successfully: `,\n faucetTransaction.toString(),\n );\n\n // Retrieve the list of balances again\n balances = await wallet.listBalances();\n console.log(`Balances after faucet: `, balances);\n }\n\n // Convert amount from string to number\n const amount = parseFloat(params.amount);\n if (isNaN(amount)) {\n throw new Error('Invalid amount provided');\n }\n\n // Convert assetId to have only the first letter capitalized\n const formattedAssetId = params.assetId.toLowerCase();\n\n // Create and send the transfer\n let transfer: Transfer;\n try {\n transfer = await wallet.createTransfer({\n amount,\n assetId: Coinbase.toAssetId(formattedAssetId),\n destination: params.recipient_address,\n // gasless: true,\n });\n console.log(`Transfer successfully completed: `, transfer.toString());\n } catch (error) {\n if (error instanceof Error) {\n console.error('Error during transfer:', error);\n throw new Error(`Transfer failed: ${error.message}`);\n } else {\n console.error('Unknown error during transfer:', error);\n throw new Error('Transfer failed due to an unknown error');\n }\n }\n\n return {\n transactionHash: transfer.getTransactionHash() || '',\n transactionLink: transfer.getTransactionLink() || '',\n status: transfer.getStatus() || '',\n };\n};\n","tools":[],"config":[{"BasicConfig":{"key_name":"name","description":"The name of the Coinbase wallet","required":true,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"privateKey","description":"The private key of the Coinbase wallet","required":true,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"walletId","description":"Optional wallet ID for specific wallet selection","required":false,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"seed","description":"Optional seed phrase for wallet recovery","required":false,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"useServerSigner","description":"Optional flag to use server-side signing","required":false,"type":null,"key_value":null}}],"description":"Tool for restoring a Coinbase wallet and sending a transaction","keywords":["coinbase","transaction","shinkai"],"input_args":{"type":"object","properties":{"assetId":{"type":"string","description":"The ID of the asset/token to send"},"amount":{"type":"string","description":"The amount of tokens to send"},"recipient_address":{"type":"string","description":"The destination address for the transaction"}},"required":["recipient_address","assetId","amount"]},"output_arg":{"json":""},"activated":false,"embedding":[-0.106319636,0.31205156,-0.2096603,-0.19719692,-0.28273338,-0.14202121,0.18417066,0.60535425,0.00690127,-0.23620136,-0.21505071,0.06602907,-0.088175476,0.33536273,0.05256945,-0.86206126,0.19151443,-0.54276013,-1.4287505,0.26882884,0.0708569,0.7486346,-0.6611768,0.32861298,-0.3728812,-0.09207104,0.04998352,-0.2763205,-1.333079,-2.5482292,0.22387576,1.3726783,-0.7585384,-0.26376712,0.025733612,-0.15745492,0.19394219,0.593534,-0.8159452,-0.44008702,0.3563952,-0.21258529,-0.7844923,0.124880366,-0.07409738,-0.5271723,0.36903447,-0.42957762,0.3134218,0.4883917,-0.2020213,0.14483216,0.46553084,-0.047665067,-0.111451976,-0.044509906,-0.08733132,-0.40066934,0.06434033,0.3733164,-0.293132,0.20150483,-3.8115027,0.24865933,1.1510297,-0.3543125,0.35783124,0.32005996,-0.39655927,0.40630358,-0.045970157,-0.27967253,-0.48354727,0.34714818,0.7759413,-0.38806108,0.63937473,0.44929722,0.4184423,-0.0729208,-0.029760893,0.96891737,0.058310762,0.15554212,-0.7846201,0.35090122,0.08179099,-0.35870063,0.051579237,0.14201005,0.08009988,0.25758868,0.29499155,-0.4330181,-0.3238939,-0.18471333,0.117309704,1.0828972,0.1328495,2.9924862,0.29244542,0.50451684,0.3039102,-0.8704654,0.56029063,-0.48561347,-0.20821774,-0.6675199,0.04772557,-0.25343218,0.8753932,-0.24772224,0.7375722,0.035266988,0.15117314,0.2445937,-0.48004895,-0.11649853,-0.32646132,0.5968574,-0.62031114,0.52304274,-0.69007695,0.17846313,-0.63072526,0.15102962,-0.089749,0.3209211,-0.14823742,0.07369484,0.54133445,-0.530794,-0.3999868,-0.24814607,0.043303434,0.049214497,0.12623493,-0.78092873,-0.7339603,-0.48771712,0.1794333,-1.0176585,0.79200983,0.01837975,0.3957201,-0.54312027,0.3235268,-0.40791082,-0.50969106,-0.29312357,-0.14239588,0.20893365,0.2662453,-0.10120833,0.5750339,-0.46133214,0.1798554,-0.38039607,-0.48585644,0.036907766,-0.36652613,-0.08511738,0.63444984,0.89382094,0.8901227,-0.8050844,0.6994938,0.0123586,0.18269068,-0.40832767,0.11853309,0.1912536,-0.14122368,-0.04778941,-0.75293714,-0.1393147,0.054124102,-0.21229088,0.2619867,-0.2647065,-0.63148475,0.85280114,-0.50435466,-1.0095026,-0.12192024,-0.090682335,0.40719396,-0.123172365,0.7986703,0.21540427,-1.104802,1.6523108,-0.27415657,0.25675067,-0.16937165,-0.16839859,-0.21261618,0.30302346,0.31810614,-0.22322589,-0.046299256,0.082044676,-0.040538155,0.43901375,-0.80888283,-0.3664593,0.33287886,0.93493414,-0.42351758,-0.3562507,0.32817766,0.13194305,0.6079518,0.43245247,0.70973945,-0.31156963,0.027720783,0.224726,0.8100068,0.17518067,0.91164434,0.4028381,-0.56213707,-0.5242609,-1.0292093,-0.08641134,0.28308165,0.5490896,0.272359,-0.31936932,0.44191438,0.6909545,0.71451,0.57300156,1.097641,0.15925455,-0.35124952,0.38270426,0.4674692,-0.88227296,0.2725635,0.24843952,-0.38515097,-0.39499766,-0.24151191,-0.47258165,0.57409716,-0.14568847,0.23501325,1.6490529,0.43645898,-0.101771325,0.55578846,-0.42271692,0.048194475,0.056533612,-1.1753882,-0.017923908,-0.6188673,0.4690291,-0.058250416,0.16988099,0.5696467,0.3446186,0.023119954,-0.44391754,-0.95120186,0.70694304,0.06270256,0.08723345,-0.18577608,1.251207,1.0461584,0.30868933,-0.4723414,-0.32835403,0.6856889,-0.0077596605,-0.21682182,0.028126894,0.06890623,-0.36906666,0.9070788,0.3056916,0.27010542,-0.58907425,0.3101983,-0.1592471,-0.9035942,-0.18071091,0.06908009,-0.6531145,-0.8078276,1.0737388,2.1424773,1.0647805,0.33722395,0.11633416,0.11753804,0.21967594,-0.3430045,0.6152516,-0.28068334,0.26910335,-1.0009212,-0.36102232,0.56341475,-0.9529137,-0.016958185,0.013770863,0.29206944,0.81195056,-0.058750723,0.48228157,-0.098716445,-0.5557401,-0.52051324,0.17213158,-0.2620815,-2.109348,0.25924936,-0.6977289,-0.58637965,-0.061080694,-0.07705728,0.48117584,-0.13202915,0.17610185,-0.2206501,1.6440735,0.18204856,-0.83501613,-0.52405536,0.0888707,0.72232306,0.2007674,0.07317701,-0.17537504,-0.6994032,-0.049573306,0.06113236,0.9161394,-0.15229407,-0.02947848,-0.32688338,0.17974004,-0.31114912,-1.0302745,-0.036051065,-0.71463513,-0.15097177,-0.08844641,0.2537528,0.07762608,1.0497032,0.45714328,-0.6347897,-0.21594654,-0.3940131,1.3175266,0.13751975,-0.32426295,-0.591051,-0.3732628,-0.09022183,-0.16863732,0.24147172,-0.28523022,-0.3441074,0.37252167,0.11444038,-0.40720177,0.4096767,0.029408429,0.7332353,0.32466182,-0.08863347,0.59267664,1.0361903,0.51285005,0.082389854,0.2780655,-0.60138935,0.15563059],"result":{"type":"object","properties":{"status":{"description":"The status of the transaction (e.g., 'success', 'pending', 'failed')","type":"string"},"transactionHash":{"description":"The hash of the completed transaction","type":"string"},"transactionLink":{"description":"A link to view the transaction on a block explorer","type":"string"}},"required":["transactionHash","transactionLink","status"]},"sql_tables":null,"sql_queries":null,"file_inbox":null,"oauth":null,"assets":null},false]} \ No newline at end of file diff --git a/tools/coinbase-send-tx/index.test.ts b/tools/coinbase-send-tx/index.test.ts index d02cc67..4f423f7 100644 --- a/tools/coinbase-send-tx/index.test.ts +++ b/tools/coinbase-send-tx/index.test.ts @@ -1,6 +1,6 @@ import { expect } from 'jsr:@std/expect/expect'; -import { definition } from './index.ts'; +import { run } from './tool.ts'; -Deno.test('exists definition', () => { - expect(definition).toBeInstanceOf(Object); -}); +// Deno.test('exists definition', () => { +// expect(definition).toBeInstanceOf(Object); +// }); diff --git a/tools/download-page/.tool-dump.test.json b/tools/download-page/.tool-dump.test.json new file mode 100644 index 0000000..ca2d695 --- /dev/null +++ b/tools/download-page/.tool-dump.test.json @@ -0,0 +1 @@ +{"type":"Deno","content":[{"toolkit_name":"download-pages","name":"Download Pages","author":"Shinkai","version":"1.0.0","js_code":"import TurndownService from 'npm:turndown@7.2.0';\nimport axios from 'npm:axios@1.7.7';\n\ntype Configurations = {};\ntype Parameters = {\n url: string;\n};\n\ntype Result = { markdown: string };\nexport type Run, I extends Record, R extends Record> = (config: C, inputs: I) => Promise;\n\nexport const run: Run = async (\n _configurations: Configurations,\n parameters: Parameters,\n): Promise => {\n try {\n const response = await axios.get(parameters.url);\n const turndownService = new TurndownService();\n const markdown = turndownService.turndown(response.data);\n return Promise.resolve({ markdown });\n } catch (error) {\n console.log('error', error);\n return Promise.resolve({ markdown: '' });\n }\n};\n","tools":[],"config":[],"description":"Downloads a URL and converts its HTML content to Markdown","keywords":["HTML to Markdown","web page downloader","content conversion","URL to Markdown"],"input_args":{"type":"object","properties":{"url":{"type":"string","description":"A URL of a web page to download"}},"required":["url"]},"output_arg":{"json":""},"activated":false,"embedding":[-0.022859422,0.34394914,-0.26828787,-0.2738084,-0.63775945,-0.07745881,-1.0741392,0.1560609,0.37143725,0.019180652,0.20704071,0.27364534,-0.0067869863,0.52876467,0.6414323,-0.33678514,0.050067496,-0.93635535,-1.4170387,-0.11435936,-0.23238567,1.0892224,0.2120105,0.5584683,0.12247756,-0.064977966,0.14893794,-0.5124398,-0.96074337,-2.0346339,0.73753834,0.45415106,-0.08883569,-0.7438674,0.48413786,-0.58480775,0.05941936,-0.5025951,-0.18222712,-0.3229596,0.09404269,-0.6394208,-0.13328093,-0.35516846,0.26403305,0.2549522,0.011935851,-0.10359208,0.7161654,0.2805506,-0.3459439,-0.7086845,-0.3280931,-0.16880323,-0.38078505,-0.05401938,-0.40572488,0.0827634,0.102821976,0.112446666,-0.2216977,0.31631678,-4.125646,0.27062064,0.5810081,0.39316595,-0.09006638,-0.13725893,-0.23155731,0.06299147,0.22843449,-0.21436238,-0.16343841,-0.28368253,-0.07376786,-0.7834173,0.62592435,-0.18950966,-0.071794435,-0.8110028,0.026290458,0.8741538,0.0618044,0.5859047,-0.556113,0.3412014,0.046755597,-0.41176373,0.313688,-0.0122999,0.368527,-0.90580493,-0.079653844,0.5979872,-0.4543758,0.042234086,-0.10474573,0.24580964,0.1175344,3.1755562,0.80056226,-0.023514325,0.79566926,-0.7410976,-0.0014581755,-0.31112045,-0.039167665,0.100143805,0.5764502,0.1579162,0.65378535,-0.5400134,-0.020097598,0.018258024,0.35735926,-0.64368653,-0.84609747,-0.22342974,0.7505621,0.82978624,-0.4969715,0.5932594,-0.00894372,-0.20878446,0.1974807,0.16078371,-0.15507145,0.3443752,0.18211538,0.038514256,0.48453322,-0.36101848,-0.5905768,0.3267346,0.702126,0.23804805,0.14942536,-0.78500104,0.34118044,-0.7625391,0.2017467,-1.0103437,0.11651488,0.5579052,0.3436056,0.52296245,0.08520118,0.64077246,-0.4686281,-0.30036545,0.123490244,0.44900888,-0.48335668,-0.42536774,0.74946654,-0.068822786,-0.40755105,-0.24519834,-0.1692692,0.52134687,-0.45200285,-0.60263264,0.27810538,0.7042316,0.18795288,-0.3493522,0.046734825,0.22792357,0.6453644,0.451598,0.4749537,-0.23558003,-0.091785856,-0.3761208,0.19023523,-0.013168387,-0.27135915,-0.5617338,-0.0695993,-0.65293926,0.3943035,0.48974362,-0.5824184,-0.4601611,-0.002162248,0.28777352,0.3323654,0.29203975,0.8401477,0.75948477,-0.2863765,1.5633736,-1.0324217,-0.43823823,-0.39899313,-0.14089474,0.17630441,0.6572716,0.3455184,0.090465,0.023112308,-0.39716557,0.4068057,-0.13822418,-0.35577852,-0.021364532,0.4544103,0.026246114,0.18069449,-0.44668064,0.2769035,-0.73281,1.1664879,0.2932155,0.4086936,-0.35218203,-0.25461483,0.409438,0.24547005,0.5120449,0.1091405,0.28187823,-0.19503851,-0.47988772,-0.4020756,0.26754946,0.1451346,0.028484786,-0.5201925,-0.12774691,0.6918011,0.4549158,0.03442505,1.0406747,1.0184767,0.19375554,-0.2703382,0.8375021,0.20192006,-0.63289624,0.19444388,-0.16417834,-0.13579649,-0.2540757,-0.23970604,-1.1852467,-0.13074327,0.33187962,0.46423656,1.7475896,0.77317226,0.50678706,0.6598569,0.04874261,0.2757128,0.064221054,-2.202051,-0.26725778,-0.23615283,1.212763,-0.17240548,0.4422012,0.12729892,0.022317126,-0.2723784,-0.37636,-0.43468815,-1.0617322,-0.35068285,0.31613588,-0.35614374,0.45097005,0.30068332,-0.043214343,0.01916102,0.5010773,0.62649405,-0.31871548,-0.7229701,-0.6690801,0.32861578,-0.17093404,0.5118524,0.00037259609,-0.11062399,-0.35906035,0.13406049,0.44416454,-0.068312965,0.27592757,0.051042564,-0.49447364,-0.063102454,0.8905604,1.6143283,-0.1856372,-0.05961505,-0.35624927,-0.5815494,-0.21133251,-0.23919454,0.3232051,-0.13867204,-0.22855097,-0.93279076,-0.29881087,0.47200906,-0.49601215,-0.15198481,0.017862234,-0.32360247,-0.07765387,0.09425101,-0.24398094,0.6091076,-0.5912474,-0.2593696,0.047237284,-0.20522922,-1.7102749,-0.5065819,0.004834657,0.13834465,-0.19261189,-0.6813854,0.93593514,-0.1833483,-0.16403382,-0.21518946,1.5840325,0.62321234,-0.6040731,-0.65227884,0.421814,0.659497,-0.17027326,-0.077558756,-0.46503827,-0.67175186,0.034123674,0.9178276,1.7945781,0.045439854,0.014577113,0.19752969,0.25004318,-0.85095567,-1.5589556,-0.16364035,-0.26558465,-0.16827886,0.29318962,-0.6095997,-0.1322887,0.52664423,0.69676834,-0.31061935,-0.06737543,-0.7940618,2.265823,0.15195686,0.057539836,-0.032563098,-0.12275851,-0.060634516,0.18676114,0.72584385,-0.5401763,-0.56609005,-0.29295185,0.26685232,-0.19534579,0.35730702,0.4106815,0.62266856,0.33912587,0.23005708,0.6000891,0.2057446,0.54149806,0.43303984,0.21790418,-0.47692624,0.19675124],"result":{"type":"object","properties":{"markdown":{"description":"The Markdown content converted from the web page","type":"string"}},"required":["markdown"]},"sql_tables":null,"sql_queries":null,"file_inbox":null,"oauth":null,"assets":null},false]} \ No newline at end of file diff --git a/tools/duckduckgo-search/.tool-dump.test.json b/tools/duckduckgo-search/.tool-dump.test.json new file mode 100644 index 0000000..1b94daa --- /dev/null +++ b/tools/duckduckgo-search/.tool-dump.test.json @@ -0,0 +1 @@ +{"type":"Deno","content":[{"toolkit_name":"duckduckgo-search","name":"DuckDuckGo Search","author":"Shinkai","version":"1.0.0","js_code":"import { URL } from 'npm:whatwg-url@14.0.0';\nimport axios from 'npm:axios@1.7.7';\nimport process from 'node:process';\n\ntype Configurations = {};\ntype Parameters = {\n message: string;\n};\ntype Result = { message: string };\n\ninterface SearchResult {\n title: string;\n description: string;\n url: string;\n}\n\n// Custom function to build query string\nfunction buildQueryString(params: Record): string {\n return Object.keys(params)\n .map(\n (key) => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`,\n )\n .join('&');\n}\n\nconst getVQD = async (keywords: string): Promise => {\n const body = buildQueryString({ q: keywords });\n await process.nextTick(() => {});\n const response = await axios.post('https://duckduckgo.com', body, {\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n });\n const text = response.data;\n // console.log('DuckDuckGo response HTML:', text);\n\n // Extract vqd token using a regular expression\n const vqdMatch = text.match(/vqd=\\\\?\"([^\\\\\"]+)\\\\?\"/);\n // console.log('vqdMatch: ', vqdMatch);\n if (!vqdMatch || vqdMatch.length < 2) {\n throw new Error('Failed to retrieve vqd token');\n }\n const vqd = vqdMatch[1];\n // console.log('vqd: ', vqd);\n return vqd;\n};\n\nconst parseDuckDuckGoResponse = (response: string): SearchResult[] => {\n // Regex to extract the JSON content\n const jsonPattern = /DDG\\.pageLayout\\.load\\('d',(\\[\\{\\\"a\\\".*?\\}\\])\\);/;\n const match = response.match(jsonPattern);\n\n if (!match) {\n throw new Error('JSON content not found in the response.');\n }\n\n // Extracted JSON content as string\n const jsonString = match[1];\n\n // Parse JSON string\n const jsonData = JSON.parse(jsonString);\n\n // Extract search results\n const results: SearchResult[] = jsonData\n .map((item: any) => ({\n title: item.t,\n description: item.a,\n url: item.u,\n }))\n .filter(\n (result: SearchResult) =>\n result.title && result.description && result.url,\n );\n\n // console.log('results: ', results);\n // Convert to JSON string\n return results;\n};\n\nconst textSearch = async (keywords: string): Promise => {\n console.log('textSearch: ', keywords);\n const vqd = await getVQD(keywords);\n console.log('vqd: ', vqd);\n const url = new URL('https://links.duckduckgo.com/d.js');\n console.log('before url.searchParams.append');\n url.searchParams.append('q', keywords);\n url.searchParams.append('vqd', vqd);\n url.searchParams.append('kl', 'wt-wt');\n url.searchParams.append('l', 'wt-wt');\n url.searchParams.append('p', '');\n url.searchParams.append('s', '0');\n url.searchParams.append('df', '');\n url.searchParams.append('ex', '-1');\n\n console.log('before urlString');\n const urlString = url.toString();\n console.log('urlString: ', urlString);\n\n await process.nextTick(() => {});\n const response = await axios.get(url.toString(), {\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n console.log('response: ', response);\n const text = response.data;\n console.log('DuckDuckGo search response:', text);\n\n // Parse the response using the custom parser\n const results = parseDuckDuckGoResponse(text);\n if (results.length === 0) {\n throw new Error('Failed to extract search results');\n }\n\n return results;\n};\nexport type Run, I extends Record, R extends Record> = (config: C, inputs: I) => Promise;\n\nexport const run: Run = async (\n _configurations: Configurations,\n params: Parameters,\n): Promise => {\n console.log('run duckduckgo search from js', 4);\n console.log('second message', 4);\n console.log('params: ', params);\n try {\n const results = await textSearch(params.message);\n console.log('results: ', results);\n return { message: JSON.stringify(results) };\n } catch (error) {\n let errorMessage = 'An unknown error occurred';\n if (error instanceof Error) {\n errorMessage = error.message;\n }\n return { message: `Error: ${errorMessage}` };\n }\n};\n","tools":[],"config":[],"description":"Searches the DuckDuckGo search engine. Example result: [{\"title\": \"IMDb Top 250 Movies\", \"description\": \"Find out which movies are rated as the best of all time by IMDb users. See the list of 250 titles sorted by ranking, genre, year, and rating, and learn how the list is determined.\", \"url\": \"https://www.imdb.com/chart/top/\"}]","keywords":["duckduckgo","search","shinkai"],"input_args":{"type":"object","properties":{"message":{"type":"string","description":"The search query to send to DuckDuckGo"}},"required":["message"]},"output_arg":{"json":""},"activated":false,"embedding":[0.16100998,-0.2972865,0.28343144,-0.28365922,0.18388914,-0.10808957,-0.8465683,-0.3023304,-0.06627547,0.29369032,0.3792466,-0.026051588,0.9681844,0.26845336,0.087322995,0.3903487,0.19291508,-0.01427158,-1.4823675,0.34444538,-0.22677879,0.6350529,0.5179565,0.16200225,0.14319092,-0.4128651,-0.5530627,-0.2230467,-1.4606562,-1.9088771,0.08900065,0.7296856,-0.3763809,-0.3156501,-0.09912226,-0.37506193,-0.07656356,-0.29206514,-0.81782377,-0.36994267,-0.9311228,0.4442602,0.32343307,-0.23644,-0.7575461,-0.2733088,0.8816913,-0.74153614,0.92402446,0.5694767,-0.66190016,-0.32893935,-0.44491023,-0.3451094,-0.5399374,1.2048315,-0.2909421,0.09793821,-0.15910481,-0.020140955,0.52650577,0.37241346,-3.2526927,0.31358433,1.1328849,0.6933904,0.68959427,0.091064654,0.1752654,-0.17398101,-0.18825978,-0.95673066,0.08014356,0.5557213,-0.7291533,-0.4783758,-0.12110171,0.17002639,0.38462222,-0.4842066,-0.19895557,-0.40634358,-0.2235034,0.11947982,-0.019322712,0.09932092,-0.3561139,-0.50609237,0.23464955,0.2506013,-0.61640763,-0.342651,-0.15674643,-0.22247696,-0.4245773,0.2267943,-0.3672269,0.2471618,0.3100941,3.5156467,0.34841216,0.1691641,0.4347128,-0.6274498,0.32555953,-0.20060848,-0.10614532,0.0679254,-0.13983274,0.50158745,-0.41802564,-0.24861914,0.36218542,0.14241442,-0.09090933,0.2561499,-0.26644385,0.2048601,0.12794764,0.15674706,-0.6449895,0.20134896,0.22811231,-0.15089744,-0.25931486,-0.1079388,-0.06875345,0.7953877,0.8425982,-0.11068615,0.35999143,-0.06753436,-1.3181609,0.6654049,0.0924684,0.24928874,-0.21873577,-0.66857755,0.46082357,-0.9986448,-0.7352612,-2.201773,1.1708877,0.47718638,0.76848406,-0.19161728,0.5031302,0.1496108,-0.6871553,0.17788763,0.41312823,-0.27841973,-0.44984117,0.18768121,0.62232244,-0.27507222,-0.28421694,0.6173232,-0.3947987,0.33405873,-1.0166829,0.3498147,0.5643429,0.6584611,-0.26877767,-0.29665112,-0.06166935,-0.16454384,0.48936158,-0.16242494,0.03428185,-0.24469805,0.523948,0.15534118,-0.4980276,0.28629124,0.13548969,0.18829426,-0.34546155,-1.1742584,0.26293284,0.6188773,0.12168458,-0.9323635,-0.26437372,-0.5892253,0.87057513,-0.6930339,0.50639945,0.80643785,0.0721452,0.8741952,-0.3274488,-0.42315227,-0.028165666,-0.592457,0.5175379,-0.059659854,0.12053746,-0.34061345,-0.6350129,0.16020003,0.15547402,-0.25673482,-0.7515326,-0.18881358,0.67522943,-0.6291586,0.5432324,-0.42265645,-0.3676717,-0.22558251,0.48577705,0.57183105,0.5349101,-0.3302961,0.6377336,-0.06351334,0.07104214,0.20489165,-1.014705,-0.3050776,-0.17635067,-0.8968951,0.29497743,-0.09858127,-0.45740026,-0.4069575,-0.5764778,-0.1508638,0.36897415,0.76126826,0.6924632,0.70853436,0.9247515,-0.17850634,-0.7721554,0.39465597,0.5619705,-0.8520909,0.74479973,-0.35380796,-0.039454237,0.013987482,1.0746634,-0.9367546,-0.02619151,0.23540804,-0.39120156,1.4433355,1.1657283,0.03284259,0.49836537,0.039773144,0.37719935,0.46682304,-1.6488383,0.21773447,-0.028232016,-0.22527152,-0.274859,-0.3425998,0.08941034,0.16945142,0.32578465,0.12483849,-0.41204578,-0.15444897,-0.691932,-0.15048423,0.54621094,0.991256,0.064518765,-0.025952421,0.3010644,1.0258135,-0.5665125,0.36733598,-0.45978212,-0.1464995,-0.41809174,0.44612837,0.26964265,0.8931821,-0.64659214,-0.009961138,-0.035986423,0.7815215,0.043738656,0.8328073,-0.25942641,-0.19111067,-0.18388048,0.20066437,1.144121,0.2505986,0.10948497,0.53195864,0.21859469,0.45678484,-0.4809166,-0.68843496,0.4476377,-0.006927535,-0.06847776,-0.40996197,0.61482847,-0.47733283,-0.11494335,-0.2483201,-1.1314368,-0.32275876,0.66809225,-0.5196115,1.6186441,-0.63046914,0.7337374,-0.070139706,0.46422538,-1.3247093,-0.13143204,0.19517592,-0.16072859,0.0046488047,0.2975949,0.2100708,0.20840794,-0.13572873,-0.54246527,1.3882924,0.36270496,0.23885682,-0.5642762,0.28673038,0.38420507,0.0007627439,0.9563615,-0.12331989,-0.60005033,0.6672105,0.6659407,1.0922046,0.9381502,0.25429425,0.18985675,0.3571467,-1.126372,-1.1870406,0.2297789,0.03585553,0.14784983,0.5716978,-0.16998038,-0.116081126,0.9463949,0.37174714,-0.89691967,0.09882557,-0.5518772,0.6476752,-0.13004614,0.49607557,-0.2541792,-0.17316863,1.0959044,0.48697007,0.60795015,-0.23220503,0.13188173,-0.76364,-0.30256245,-0.21257344,0.05254751,0.051760208,0.09228458,0.35372865,-0.12407258,0.81559,-0.052715406,-0.14442651,-0.08288829,-0.38582665,-0.44459823,-0.31732184],"result":{"type":"object","properties":{"message":{"description":"The search results from DuckDuckGo in JSON format, containing title, description, and URL for each result","type":"string"}},"required":["message"]},"sql_tables":null,"sql_queries":null,"file_inbox":null,"oauth":null,"assets":null},false]} \ No newline at end of file diff --git a/tools/email-imap-fetcher/.tool-dump.test.json b/tools/email-imap-fetcher/.tool-dump.test.json new file mode 100644 index 0000000..88aa246 --- /dev/null +++ b/tools/email-imap-fetcher/.tool-dump.test.json @@ -0,0 +1 @@ +{"type":"Python","content":[{"toolkit_name":"email-imap-fetcher","version":"1.0.0","name":"Email Fetcher","author":"Shinkai","py_code":"from typing import Any, Optional, List, Dict\nimport imaplib\nimport email\nfrom datetime import datetime\n\nclass CONFIG:\n imap_server: str\n username: str\n password: str\n port: int = 143 # Default port for IMAPS\n ssl: bool = True # New flag to specify SSL usage\n\nclass INPUTS:\n from_date: Optional[str]\n to_date: Optional[str]\n\nclass OUTPUT:\n emails: List[Dict[str, Any]]\n login_status: str\n\nclass Email:\n subject: str\n date: datetime\n sender: str\n text: str\n\nasync def run(config: CONFIG, inputs: INPUTS) -> OUTPUT:\n output = OUTPUT()\n output.login_status = \"N/A\"\n output.emails = []\n try:\n # Use SSL if the ssl flag is set to True\n if config.ssl:\n imap = imaplib.IMAP4_SSL(config.imap_server, config.port)\n else:\n imap = imaplib.IMAP4(config.imap_server, config.port) # Use config port\n except Exception as ee:\n output.login_status = 'IMAP4 INIT FAILED - ' + str(ee)\n return output\n\n try:\n login_status, login_response = imap.login(config.username, config.password)\n if login_status == \"OK\":\n print(\"Login successful\")\n else:\n raise Exception(\"Login failed\")\n\n imap.select(\"INBOX\")\n\n # Construct the search criteria\n search_criteria = 'ALL'\n if inputs.from_date and inputs.to_date:\n search_criteria = f'SINCE \"{inputs.from_date}\" BEFORE \"{inputs.to_date}\"'\n elif inputs.from_date:\n search_criteria = f'SINCE \"{inputs.from_date}\"'\n elif inputs.to_date:\n search_criteria = f'BEFORE \"{inputs.to_date}\"'\n\n _, data = imap.search(None, search_criteria)\n mail_ids = data[0].split()\n\n for mail_id in mail_ids:\n _, data = imap.fetch(mail_id, '(RFC822)')\n raw_email = data[0][1]\n email_message = email.message_from_bytes(raw_email)\n\n email_obj = Email()\n email_obj.subject = email_message.get('Subject', '')\n email_obj.sender = email_message.get('From', '')\n try:\n email_obj.date = datetime.strptime(email_message['Date'], '%a, %d %b %Y %H:%M:%S %z') # Example format, adjust as needed\n except ValueError:\n email_obj.date = None # Handle parsing error\n\n email_obj.text = \"\"\n if email_message.is_multipart():\n for part in email_message.walk():\n content_type = part.get_content_type()\n content_disposition = str(part.get(\"Content-Disposition\"))\n try:\n body = part.get_payload(decode=True).decode()\n if content_type == \"text/plain\" and \"attachment\" not in content_disposition:\n email_obj.text += body\n except Exception as e:\n print(f\"Error decoding email part: {e}\")\n else:\n try:\n email_obj.text = email_message.get_payload(decode=True).decode()\n except Exception as e:\n print(f\"Error decoding email payload: {e}\")\n\n output.emails.append(email_obj.__dict__) # Append as dictionary to match OUTPUT type\n\n imap.close()\n imap.logout()\n\n except Exception as e:\n output.login_status = str(e)\n print(f\"An error occurred: {e}\")\n\n return output","tools":[],"config":[{"BasicConfig":{"key_name":"imap_server","description":"The IMAP server address","required":true,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"username","description":"The username for the IMAP account","required":true,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"password","description":"The password for the IMAP account","required":true,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"port","description":"The port number for the IMAP server (defaults to 993 for IMAPS)","required":false,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"ssl","description":"Whether to use SSL for the IMAP connection (defaults to true)","required":false,"type":null,"key_value":null}}],"description":"Fetches emails from an IMAP server and returns their subject, date, sender, and text content.","keywords":["email","imap","fetch","parser"],"input_args":{"type":"object","properties":{"from_date":{"type":"string","description":"The start date for the email search (optional)"},"to_date":{"type":"string","description":"The end date for the email search (optional)"}},"required":[]},"output_arg":{"json":""},"activated":false,"embedding":[0.5479309,0.7763235,0.026674157,-0.16738741,0.5364636,-0.41592622,-0.18910207,-0.05454345,-0.29638964,0.2862875,-0.47343403,0.36381552,-0.028221607,-0.044476815,0.4598937,0.18612349,0.7828154,-0.7714744,-1.6326721,-0.8778204,-0.048063386,1.1291318,0.7664015,-0.29742765,-0.07895305,-0.11800984,-0.015257135,-0.5918412,-1.2382919,-1.5990069,0.13624647,0.613811,-0.075190045,0.06293893,-0.11953545,-0.27149397,-0.048563834,0.12580146,-0.75142956,-0.08895335,0.37151906,0.11853383,-0.17709689,0.009899925,-0.10987698,0.010610655,-0.3739504,-0.05800452,0.44720182,1.234952,0.26136097,-0.17966335,-0.002988577,0.61995935,-0.24467465,-0.06542288,-0.10929164,-0.25247148,-0.34462184,-0.04372844,0.30536994,0.06352043,-3.4439888,0.7174165,0.21700993,-0.74596703,-0.02436735,-0.1965301,-0.11611959,-0.6180924,0.18903497,-0.044823177,-0.78377825,0.9992074,0.7204637,-1.018795,0.24259819,0.26241738,0.71519196,-0.056704037,0.3214574,1.0126419,-0.3816996,0.19416338,-1.0504618,0.5837887,-0.45761284,-0.041342944,0.044106256,0.09262079,0.13525055,-0.5482912,-0.00019433163,-0.11295105,-0.39098027,-0.5777057,-0.5481062,0.21999045,-0.15936601,2.8422408,0.80019397,0.2077642,-0.3285482,-1.0237343,-0.31722015,-0.8532467,-0.3007262,-0.5583755,-0.5497531,-0.047561213,-0.108288676,0.24658099,0.16036676,0.22223756,0.5257036,-0.4537774,-0.575389,0.0774444,0.37592137,0.91921204,0.009767443,-0.060128514,-0.18703139,-0.27910328,-0.2958559,0.1515292,0.08438231,0.4104749,-0.064257696,-0.63763505,0.9386971,-0.89508957,-0.9638947,0.14572594,-0.06920652,0.14926244,0.050837606,-0.565508,-0.118247874,-0.44556957,-0.34451056,-1.8896232,0.85709465,0.5051772,0.5639328,0.96063703,-0.10398855,-0.1424489,-0.36340132,0.54609245,-0.12384151,0.21497999,-0.45669198,0.52929,0.4223799,-0.11460344,-0.122996174,-0.166623,0.087036274,-0.18353695,-0.35434458,0.113860786,0.65662843,0.23493981,-0.2713947,-0.4281857,0.3266951,0.7084959,-0.024459317,-0.07877298,0.7143753,0.14731333,-0.48049852,0.7254837,0.24513422,-0.054967947,0.01897259,0.10359511,0.29968926,-0.76801276,0.79415053,0.809134,-0.15827884,-0.6663613,0.17736472,0.63871837,0.1946787,-0.33553472,1.2522476,0.4795199,-0.49924162,1.6452429,-0.8945019,-1.4492631,0.095773175,-0.23259237,-0.28094348,0.63784915,0.683028,-0.042965755,-0.7615802,-0.21412589,-0.051427986,-0.09559578,0.42753083,0.039896064,0.15724176,-0.5159093,0.07113676,-0.64087176,0.1296175,-0.25358164,-0.12318501,0.06855747,0.60574794,-0.116952226,-0.19015035,-0.08382109,-0.16316505,0.28837523,-0.07065154,-0.020715445,-0.15442558,-0.6647575,-0.22111298,0.5690165,-0.9429492,0.29109824,-0.21969135,-0.26837555,1.0582712,1.1552417,0.44249675,0.70338833,1.2416098,-0.17338353,-0.8948746,1.0502487,0.42448974,-0.017904958,0.43834543,-0.039606214,-0.20880365,0.27866495,-0.17466074,0.18515173,0.23095343,-0.030884564,0.08141043,1.4430072,1.1376486,0.53613025,-0.2366021,0.34702548,0.030587671,-0.44374648,-1.2675188,-0.11138431,-0.339154,0.60913414,0.50010306,-0.31321654,1.0176988,0.5499899,0.080315925,-0.3171413,-0.8770165,-0.63169575,-0.18153813,-0.00763759,-0.86662555,0.22710544,-0.6306354,-0.34014967,-0.2009951,-0.24473186,0.29777953,0.4450379,-0.41532865,-0.38763383,-0.1695514,0.11756535,0.6374901,0.1111707,-0.2927736,-0.95100373,-0.085079,-0.76878,-0.5930545,0.3108728,0.19680336,-0.83715355,-0.6372137,-0.0524932,1.5352126,0.37868422,0.21009241,0.3811208,0.2817881,0.5902789,0.00004694611,0.090835646,-0.32211965,-0.40693212,-0.8613461,-0.44002575,0.20879349,-0.25120696,-0.27142256,0.32465765,-0.48586708,0.11979771,0.32263827,-0.45627564,0.54997385,-0.4462748,0.65437293,0.5738947,0.3156873,-1.9321,0.02173773,-0.13883269,0.4723531,-0.047878757,-1.1881952,0.379251,-0.55044246,-0.594921,-0.6036093,0.8095113,0.033107758,-0.19005199,0.21288945,-0.4164763,0.60610926,0.48504293,0.040338136,-0.41419882,-0.84944075,-0.07099132,0.4641935,2.054265,0.0036511272,0.17068133,0.22921714,0.4635803,-0.6021989,-1.7566532,0.36086866,-0.13427743,-0.119817354,0.7721548,0.33452892,0.24904981,0.2719462,1.1957556,-0.48627308,-0.2760353,-0.9714952,1.423162,0.22687478,0.25706276,-0.5673453,-0.30074564,0.03861826,0.46557784,0.71225953,-0.040022623,-0.18835677,-0.012464032,-0.13759041,0.31895515,0.4125949,0.5486704,0.15159258,0.14480522,0.27187392,0.35092625,0.8843945,0.6669177,0.5371572,1.1669174,-0.2080658,0.19059417],"result":{"type":"object","properties":{"emails":{"description":"A list of email objects","items":{"properties":{"date":{"description":"The date and time the email was sent","format":"date-time","type":"string"},"sender":{"description":"The sender of the email","type":"string"},"subject":{"description":"The subject of the email","type":"string"},"text":{"description":"The text content of the email","type":"string"}},"required":["subject","date","sender","text"],"type":"object"},"type":"array"},"login_status":{"description":"Indicates if login was successful or not","type":"string"}},"required":["emails","login_status"]},"sql_tables":[],"sql_queries":[],"file_inbox":null,"oauth":null,"assets":null},false]} \ No newline at end of file diff --git a/tools/email-responder/.tool-dump.test.json b/tools/email-responder/.tool-dump.test.json new file mode 100644 index 0000000..e41e0fb --- /dev/null +++ b/tools/email-responder/.tool-dump.test.json @@ -0,0 +1 @@ +{"type":"Deno","content":[{"toolkit_name":"email-answerer","name":"Email Answerer","author":"Shinkai","version":"1.0.0","js_code":"import {\n emailFetcher,\n sendEmail,\n shinkaiLlmPromptProcessor,\n shinkaiSqliteQueryExecutor,\n} from './shinkai-local-tools.ts';\n\ntype EMAIL = {\n date: string;\n sender: string;\n subject: string;\n text: string;\n}\n\ntype ANSWERED_EMAIL_REGISTER = {\n email_unique_id: string;\n subject: string;\n email: string;\n response: string;\n received_date: string;\n response_date: string;\n}\n\nasync function generateEmailUniqueId(email: EMAIL): Promise {\n const encoder = new TextEncoder();\n if (!email.subject && !email.sender && !email.date) {\n throw new Error('Email is empty subject, sender, and date, cannot generate unique id');\n }\n const data = encoder.encode((email.subject ?? '') + (email.sender ?? '') + (email.date ?? ''));\n const hashBuffer = await crypto.subtle.digest('SHA-256', data);\n const hashArray = Array.from(new Uint8Array(hashBuffer));\n return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');\n}\n\ntype CONFIG = {\n response_context: string;\n};\n\ntype INPUTS = {\n from_date?: string;\n to_date?: string;\n};\n\ntype OUTPUT = {\n table_created: boolean;\n mail_ids: (string | number)[];\n skipped: string[];\n login_status: string;\n};\n\n// Helper function to escape user input\nfunction escapeSqlString(str: string): string {\n return `'${str.replace(/'/g, \"''\").replace('--', '').replace(';', '')}'`; // Replaces single quotes with two single quotes\n}\n\nexport async function run(config: CONFIG, inputs: INPUTS): Promise {\n const tableName = 'answered_emails';\n\n const createTableQuery = `\n CREATE TABLE IF NOT EXISTS ${tableName} (\n email_unique_id TEXT UNIQUE PRIMARY KEY,\n subject TEXT NOT NULL,\n email TEXT NOT NULL,\n response TEXT NOT NULL,\n received_date DATETIME NOT NULL,\n response_date DATETIME DEFAULT CURRENT_TIMESTAMP\n );\n `;\n\n await shinkaiSqliteQueryExecutor({ query: createTableQuery });\n // Ensure the connection is closed or cleaned up if necessary\n // Verify table creation was successful\n const tableCheck = await shinkaiSqliteQueryExecutor({\n query: `SELECT name FROM sqlite_master WHERE type='table' AND name=?;`,\n params: [tableName]\n });\n const tableCreated = (tableCheck?.result?.length ?? 0) > 0;\n let { emails, login_status } = await emailFetcher({\n from_date: inputs.from_date || '',\n to_date: inputs.to_date || '',\n });\n inputs.from_date = undefined;\n inputs.to_date = undefined;\n const answeredEmailsQuery = await shinkaiSqliteQueryExecutor({\n query: `SELECT * FROM ${tableName}`,\n });\n if (!answeredEmailsQuery?.result) {\n throw new Error('Failed to query answered emails');\n }\n const answeredEmails: ANSWERED_EMAIL_REGISTER[] = (answeredEmailsQuery.result as ANSWERED_EMAIL_REGISTER[]) ?? [];\n const mailIds: string[] = [];\n const minDate = inputs.from_date ? new Date(inputs.from_date) : new Date('1970-01-01T00:00:00.000Z');\n emails = emails\n .filter((e: EMAIL) => (e.date && e.sender && e.subject))\n .filter((e: EMAIL) => e.date > ((minDate && minDate.toISOString()) || '1970-01-01T00:00:00.000Z'))\n \n const insertMailIdQuery = (\n emailUniqueId: string,\n subject: string,\n email: string,\n response: string,\n received_date: Date,\n ) => `\n INSERT INTO ${tableName} (email_unique_id, subject, email, response, received_date) \n VALUES (${emailUniqueId}, ${subject}, ${email}, ${response}, ${Math.floor(received_date.getTime() / 1000)});\n `;\n\n const skipped: string[] = [];\n try {\n for (const email of emails as EMAIL[]) {\n const emailUniqueId = await generateEmailUniqueId(email);\n const answeredEmail = answeredEmails.find(answeredEmail => answeredEmail.email_unique_id === emailUniqueId);\n if (answeredEmail) {\n skipped.push(answeredEmail.email_unique_id)\n console.log(`🐸 Skipping email with subject ${answeredEmail.subject}`)\n continue;\n }\n\n let response;\n try {\n response = await shinkaiLlmPromptProcessor({\n format: 'text',\n prompt: `You are a helpful email answering system.\n Please respond to a following email but only in the manner of the following context:\n \n ${config.response_context}\n \n This is the email you need to respond to:\n \n ${email.subject}\n ${email.sender}\n ${email.date}\n ${email.text}\n \n\n You'll be generating only the response to the email, no other text or markdown like html its neccesary.\n `,\n });\n } catch (error) {\n console.error(`Failed to process email: ${error}`);\n continue; // Skip this email if processing fails\n }\n \n await sendEmail({\n recipient_email: email.sender,\n subject: 'RE:' + email.subject,\n body: response.message\n });\n \n const insertEmail = insertMailIdQuery(\n escapeSqlString(emailUniqueId),\n escapeSqlString(email.subject),\n escapeSqlString(email.sender),\n escapeSqlString(response.message),\n new Date(email.date)\n );\n await shinkaiSqliteQueryExecutor({ query: insertEmail })\n const mailId = emailUniqueId;\n mailIds.push(mailId);\n }\n } catch (error) {\n console.error(`Failed to process emails: ${error}`);\n throw error; // Rethrow the error after rollback\n }\n return {\n table_created: tableCreated,\n mail_ids: mailIds,\n login_status,\n skipped,\n };\n}\n","tools":["local:::rust_toolkit:::shinkai_sqlite_query_executor","local:::email_imap_fetcher:::email_fetcher","local:::email_sender_shinkai:::send_email","local:::rust_toolkit:::shinkai_llm_prompt_processor"],"config":[{"BasicConfig":{"key_name":"response_context","description":"The context to use when answering emails.","required":true,"type":null,"key_value":null}}],"description":"Tool for automatically answering emails by processing their content and responding to them.","keywords":["email","answer","processor","shinkai"],"input_args":{"type":"object","properties":{"from_date":{"type":"string","description":"The date from which to start processing emails (inclusive)."},"to_date":{"type":"string","description":"The date until which to process emails (exclusive)."}},"required":[]},"output_arg":{"json":""},"activated":false,"embedding":[-0.09985851,0.41992223,-0.12004921,-0.65672076,0.39591885,0.03171113,-0.07226634,0.13418892,0.37773234,0.095823616,-0.27842966,0.5737561,-0.14799337,-0.32679847,0.26278412,-0.27252376,0.023710428,-0.73856074,-1.7764609,-0.024215154,-0.071724065,0.51910317,0.41663653,0.27744022,-0.18640056,-0.1412967,-0.26539823,-0.29159713,-1.0645298,-1.5616181,0.7318345,0.4630917,-0.09768544,0.18475255,-0.31483483,-0.8806548,0.045418985,0.7320302,-0.5062949,-0.5591957,0.6621704,0.47486767,-0.5485827,-0.38923874,0.027039038,-0.3208995,0.18409902,-0.19852482,0.62323356,1.1423376,-0.29865226,-0.32728508,0.06757504,0.011682838,-0.30320862,0.22403404,-0.08006736,-0.23536871,-0.25722864,-0.14303279,0.07184484,0.059820488,-4.103936,0.026317094,0.32570758,-0.19826949,0.24358116,-0.203736,0.20447327,-0.14635731,0.17733417,0.22320257,-0.92686474,0.66302633,0.47925895,-0.5205876,-0.2055311,-0.32124284,0.69573456,-0.53343475,0.36255255,0.75530005,-0.019595308,0.053144563,-0.9027147,0.16557506,-0.31666303,-0.59595895,0.087919936,0.1706427,-0.3849518,-0.6034928,-0.008018697,-0.15535697,-0.14670011,0.16725639,-0.33451593,0.31433433,0.2513728,3.0496314,0.5148341,-0.14858198,0.33689693,-1.1889803,0.30593,-0.45296368,-0.44431898,-0.89669794,0.018077554,0.05960524,-0.14916553,-0.00020011887,-0.23338673,0.25307718,-0.14570162,-0.064205796,-0.20404162,0.6621008,-0.40003547,0.92348033,0.0039137304,0.48920617,-0.3967268,-0.14902142,-0.25922528,0.45340368,-0.06646332,0.34597403,0.246404,0.35795265,0.8073371,-0.73999,-1.3352734,-0.416408,-0.35875425,0.22857976,0.87159437,-0.27707416,0.46655366,-0.45533603,0.18971612,-1.3398782,0.95085275,0.45074913,0.7840571,0.38695052,-0.041590944,0.17936872,-0.37343398,-0.021297518,-0.10988118,0.7074091,-0.31377855,-0.20488518,0.5531475,0.35868225,-0.20583926,-0.5925287,-0.33645293,-0.010709219,-0.21971744,-0.02493093,0.32378396,0.56636673,0.27111152,-0.6108487,-0.009705529,-0.24498448,0.034020167,-0.31361794,0.3016987,0.121328324,-0.14855805,0.3490593,-0.71588063,-0.26339504,0.10573955,0.25633395,0.3710813,-0.9818953,0.8665151,0.80591035,-0.34483325,-0.428555,0.14673492,0.56727344,-0.051773667,0.00081272796,1.03209,0.83792174,-0.7451982,1.5228243,-0.40058577,-0.6200303,0.16965763,0.20172136,-0.27264586,0.35060263,0.77300495,-0.08666761,-0.6251472,-0.4829298,-0.10457234,0.58370256,-0.31508803,-0.27231908,-0.109491244,0.23013608,0.31288865,-0.768549,0.010679377,-0.36449796,0.31897122,0.5963579,0.63829565,0.14162746,-0.012096845,-0.0585918,-0.033005834,0.6231268,0.7877326,-0.08274295,-0.5439343,-0.5455469,-0.5212696,0.6198795,-0.5812921,0.15766957,-0.078437164,-0.20421016,0.44780773,1.0819429,0.42778358,0.99357295,0.53544074,0.36107627,-0.45699495,0.8482958,0.6293901,-0.29527885,0.35279608,-0.481279,-0.36175683,0.410199,0.0707047,-0.40803975,0.51825434,-0.1351583,0.19316107,1.143534,0.21820083,0.5560332,0.19531396,0.39858308,-0.2606566,-0.14008945,-1.1986159,0.4774295,-0.70564175,0.85032564,0.111924194,-0.33325583,0.92645276,0.55054927,-0.08150864,-0.12028319,-0.64827335,-0.83630574,-0.33341813,0.086112894,-0.35005444,0.36340836,-0.27054167,-0.08749605,-0.28763008,-0.07928019,0.4501998,0.44531772,-0.35976437,-0.807098,-0.01792501,-0.025507998,0.24706668,-0.09043433,-0.81316817,-0.113369234,-0.26769114,-0.47778618,-0.5550028,0.94598913,-0.12513545,-0.739502,-0.43858352,0.41866902,2.119558,0.8783374,0.1405863,0.5250694,0.26140442,0.435696,0.025377937,0.36144233,-0.4267802,-0.66928786,-0.7562486,-0.5695229,0.48990077,-0.14522375,-0.41317055,-0.21128955,-0.54286426,0.19401544,-0.14524706,0.42075133,0.7353583,-0.28700352,1.0308704,0.027792431,-0.08629088,-2.3009906,0.013498096,0.4897199,0.1434111,-0.098885186,-0.27055186,0.14219065,-0.10567584,-0.06458485,-0.52829903,0.78343916,0.31948823,-0.4972912,0.182031,-0.068416424,0.6322392,0.28617698,0.015289301,-0.5621281,-1.0010431,-0.20688461,0.47176483,2.0685585,0.09178205,-0.02966639,0.060745124,0.3316962,-0.3634292,-1.6005789,0.0755179,0.06307718,-0.33131552,1.0656507,-0.044327427,-0.56029916,0.24818929,0.8565493,-0.37231588,-0.22803673,-0.7573291,1.5341315,-0.12744786,-0.07526349,-0.82769096,0.2538394,-0.26462355,0.17901422,1.0399874,-0.35634437,-0.19371632,0.40741196,0.1992828,-0.14409436,0.54181623,0.023502825,0.27126762,0.23331052,-0.10381478,0.67352355,0.4075753,0.6132025,0.13684294,0.3471062,-0.34013706,0.4969532],"result":{"type":"object","properties":{"login_status":{"description":"The status of the login process on the imap fetcher.","type":"string"},"mail_ids":{"description":"The IDs of the emails that were processed and answered.","items":{"type":"string"},"type":"array"},"skipped":{"description":"The IDs of the emails that were skipped.","items":{"type":"string"},"type":"array"},"table_created":{"description":"Whether the table was created successfully.","type":"boolean"}},"required":["table_created","mail_ids","login_status","skipped"]},"sql_tables":[{"name":"answered_emails","definition":"CREATE TABLE IF NOT EXISTS answered_emails (email_unique_id TEXT UNIQUE PRIMARY KEY, subject TEXT NOT NULL, email TEXT NOT NULL, response TEXT NOT NULL, received_date DATETIME NOT NULL, response_date DATETIME DEFAULT CURRENT_TIMESTAMP)"}],"sql_queries":[{"name":"Get emails","query":"SELECT * FROM answered_emails"},{"name":"Get email by unique ID","query":"SELECT * FROM answered_emails WHERE email_unique_id = :emailUniqueId"}],"file_inbox":null,"oauth":null,"assets":null},false]} \ No newline at end of file diff --git a/tools/email-responder/metadata.json b/tools/email-responder/metadata.json index 906e5fd..c8d6c44 100644 --- a/tools/email-responder/metadata.json +++ b/tools/email-responder/metadata.json @@ -1,4 +1,5 @@ { + "id": "email-answerer", "name": "Email Answerer", "description": "Tool for automatically answering emails by processing their content and responding to them.", "author": "Shinkai", diff --git a/tools/email-sender/.tool-dump.test.json b/tools/email-sender/.tool-dump.test.json new file mode 100644 index 0000000..b1efcae --- /dev/null +++ b/tools/email-sender/.tool-dump.test.json @@ -0,0 +1 @@ +{"type":"Python","content":[{"toolkit_name":"email-sender-shinkai","version":"1.0.0","name":"Send Email","author":"Shinkai","py_code":"from typing import Any, Optional, List, Dict\nimport smtplib\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\nfrom datetime import datetime\nimport logging\n\n# Configure logging\nlogging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s')\n\nclass CONFIG:\n smtp_server: str\n port: int = 465 # Default port for SMTP\n sender_email: str\n sender_password: str\n ssl: bool = True # New flag to specify SSL usage for SMTP\n\nclass INPUTS:\n recipient_email: str\n subject: str\n body: str\n\nclass OUTPUT:\n status: str\n message: str\n\n\nasync def run(config: CONFIG, inputs: INPUTS) -> OUTPUT:\n output = OUTPUT()\n output.status = \"failed\"\n output.message = \"\"\n\n msg = MIMEMultipart()\n msg['From'] = config.sender_email\n msg['To'] = inputs.recipient_email\n msg['Subject'] = inputs.subject\n msg['Date'] = datetime.now().strftime('%a, %d %b %Y %H:%M:%S %z')\n\n msg.attach(MIMEText(inputs.body, 'plain'))\n\n try:\n # Use SSL if the ssl flag is set to True\n if config.ssl:\n with smtplib.SMTP_SSL(config.smtp_server, config.port) as server:\n server.login(config.sender_email, config.sender_password)\n server.send_message(msg)\n else:\n with smtplib.SMTP(config.smtp_server, config.port) as server:\n try:\n server.starttls() # Upgrade to a secure connection\n except Exception as e:\n logging.error(f\"Failed to upgrade to a secure connection: {e}\")\n # Attempt to login and send the message regardless of starttls success\n server.login(config.sender_email, config.sender_password)\n server.send_message(msg)\n\n output.status = \"success\"\n output.message = \"Email sent successfully\"\n except Exception as e:\n output.message = f\"An error occurred: {e}\"\n\n return output","tools":[],"config":[{"BasicConfig":{"key_name":"smtp_server","description":"The SMTP server address","required":true,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"port","description":"The SMTP server port","required":false,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"sender_email","description":"The sender's email address","required":true,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"sender_password","description":"The sender's email password","required":true,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"ssl","description":"Whether to use SSL for the SMTP connection (defaults to true)","required":false,"type":null,"key_value":null}}],"description":"Sends an email using SMTP.","keywords":["email","smtp","send","notification"],"input_args":{"type":"object","properties":{"subject":{"type":"string","description":"The email subject"},"recipient_email":{"type":"string","description":"The recipient's email address"},"body":{"type":"string","description":"The email body"}},"required":["recipient_email","subject","body"]},"output_arg":{"json":""},"activated":false,"embedding":[-0.16863883,0.36951548,0.0710708,-0.36373425,-0.14536303,0.2146287,-0.50722194,0.1676828,0.2184625,-0.04377217,-0.085600205,0.34219766,-0.36027485,-0.18785664,0.55667514,-0.691538,0.2247413,-0.8311942,-1.5291927,-0.047287576,-0.6570787,0.70218843,0.47352836,0.18740639,-0.17268768,0.29156917,0.6691437,-0.07875953,-1.2676071,-1.8487979,-0.081507675,1.0741738,-0.56719506,0.19950143,0.16902098,-0.33455634,-0.26199192,-0.09675157,-0.47350892,-0.37621498,0.17657778,-0.88388574,-0.61456853,0.14724383,0.0047138403,-0.07347565,0.18744619,-0.009305887,0.48106268,0.6018966,-0.39029375,-0.52880675,-0.04798488,0.3419745,-0.5091409,0.012889862,0.24974045,-0.07357307,0.08554194,0.07949574,-0.16837044,0.3805329,-4.0146613,0.44082963,0.19260548,-0.05207956,0.013428052,-0.056233037,-0.08819136,-0.5272552,0.47180402,-0.060578555,-0.7489064,1.1056236,0.5340901,-0.6931602,-0.31226557,-0.03932616,0.5956225,0.09799042,0.30966645,0.8742893,-0.17315604,0.75597227,-0.9725792,0.6906055,-0.1251234,-0.1491244,0.42240295,0.3407192,-0.44704607,-0.40117118,0.1866251,-0.06991961,-0.19835445,-0.20955215,-0.26118103,0.12725456,0.22721684,2.7749872,0.5122516,-0.015306573,0.60036194,-1.0183859,-0.014407955,-0.2569119,-0.47032169,-0.886011,-0.30298057,-0.7121273,-0.0036273357,0.12116812,0.10482912,-0.24737927,0.46679825,-0.045558598,-0.35440093,0.36716238,-0.065571554,1.0201825,-0.24053283,0.1286274,-0.5494258,-0.35711333,0.12258132,0.15131353,-0.32479504,0.105600774,-0.13950256,0.27332562,0.65994203,-0.780461,-0.21348491,-0.20567286,0.23244157,0.11215775,0.40510517,-0.52354896,0.06681162,-0.41453093,0.59581953,-2.140505,1.3061415,0.75075674,0.672057,-0.10104084,0.10604617,-0.1125272,-0.42605418,-0.07585393,-0.33421445,0.093503065,0.20071425,0.42282313,0.75608283,-0.15237688,-0.121898524,0.5767451,-0.09775403,0.007833563,-0.13465671,0.14342043,-0.09603147,0.28792357,0.030869912,-1.0182501,-0.090522915,0.38259473,-0.30252847,-0.07191988,0.25874224,-0.30134445,-0.30062976,0.3386175,-0.184572,-0.13463037,0.21865469,0.14952739,0.44614434,-0.5275878,0.44001737,0.48307657,-0.20029795,-0.20540681,0.009874843,0.62023115,0.29343334,-0.26610968,1.1866063,0.20866166,-0.86935693,1.194493,-0.70958436,-0.67053705,0.16449386,0.15501787,-0.2732337,0.5001677,0.40268838,0.05267391,-0.28818738,-0.25627786,0.3237739,0.20661367,-0.114382796,-0.3155887,0.036046203,0.09303906,0.045092113,-0.38759232,0.16511068,-0.2412476,0.20692427,-0.00802502,0.3642635,0.5850683,-0.76512456,0.46202484,-0.28010985,0.5700413,0.4096586,0.3902241,-0.42495793,-0.43494877,-0.30588314,0.48026097,-0.12984975,0.49075717,-0.29071864,-0.42085195,0.30260554,0.8222282,0.19941153,1.315254,0.30886918,0.17627637,-0.24155778,0.49255127,0.6639385,-0.1827571,0.02121464,0.09293347,0.13839658,0.035679504,0.73405087,-0.6335372,0.5251611,0.31011373,-0.091499746,1.8595266,0.7143397,0.5168366,0.03708881,0.507861,0.18957117,0.1983318,-1.0314994,-0.33044,-0.82924306,0.99074227,0.2815774,-0.07468645,0.74307996,0.36426264,-0.22649744,-0.05202507,-0.6921822,-0.802549,-0.31213802,-0.084367484,-0.5192693,0.41364402,-0.29686666,0.43975556,-0.17650422,-0.6930386,0.47838062,0.33172914,-0.058259707,-0.7303181,-0.099644355,0.015148858,0.5009095,-0.14864665,-0.14669248,-0.6800788,0.20073141,-0.40443534,-0.14989856,0.3386585,0.045613185,-0.7879523,-0.5424034,0.5760776,2.0714297,0.2327904,0.22501259,0.56382495,0.12127443,0.39556783,0.14754608,-0.019769825,-0.5407266,-0.3219013,-0.83585715,-0.34718287,0.026048623,-0.7465372,-0.07637849,-0.033146467,0.01799985,-0.18363564,0.2644258,0.12561584,0.59224236,0.30794838,-0.24934794,0.04864285,0.03341459,-2.4325747,0.01822721,0.2530063,-0.18837038,-0.44696414,-0.8883713,0.09524957,-0.016613895,0.104276374,-0.38413656,1.4529321,-0.11070707,-0.43041483,0.35400572,0.08043813,0.8491075,-0.1862826,0.22454764,-0.31269205,-0.97372025,-0.42027125,1.1249119,2.2466652,0.0023729801,-0.026027378,-0.16045304,-0.1841715,-0.3728962,-1.1865739,0.40547544,-0.17469762,-0.17986779,0.22225553,-0.09583995,-0.24011159,-0.623016,0.5858946,-0.058788326,-0.21884863,-0.63768953,1.4557298,0.05939327,0.680458,-0.681359,-0.2196953,-0.097733356,-0.13278785,0.22399272,-0.040767163,-0.50004923,0.57334274,0.268478,0.117074646,0.31567943,0.21000771,0.35896412,0.3529358,-0.12819107,0.7792076,1.001332,0.45549732,0.33468097,0.6633587,-0.7268323,0.1314122],"result":{"type":"object","properties":{"message":{"description":"A message indicating the result of the operation","type":"string"},"status":{"description":"The status of the email sending operation ('success' or 'failed')","type":"string"}},"required":["status","message"]},"sql_tables":[],"sql_queries":[],"file_inbox":null,"oauth":null,"assets":null},false]} \ No newline at end of file diff --git a/tools/file-read/.tool-dump.test.json b/tools/file-read/.tool-dump.test.json new file mode 100644 index 0000000..d498af0 --- /dev/null +++ b/tools/file-read/.tool-dump.test.json @@ -0,0 +1 @@ +{"type":"Deno","content":[{"toolkit_name":"file-reader","name":"Read File Contents","author":"Shinkai","version":"1.0.0","js_code":"type CONFIG = {};\ntype INPUTS = { path: string };\ntype OUTPUT = { content: string };\n\nexport async function run(config: CONFIG, inputs: INPUTS): Promise {\n const { path } = inputs;\n const content = await Deno.readTextFile(path);\n return { content };\n}","tools":[],"config":[],"description":"Reads the text contents of a file from the given path.","keywords":["file","read","content","text"],"input_args":{"type":"object","properties":{"path":{"type":"string","description":"The path of the file to read."}},"required":["path"]},"output_arg":{"json":""},"activated":false,"embedding":[0.12859492,0.12596734,0.010835137,-0.15759677,0.08992459,-0.06392758,-1.4077084,0.8902618,0.32812726,-0.09717176,-0.040325865,0.93691605,0.007549899,-0.51253396,0.2567432,-0.4170107,-0.3970057,-0.58185434,-1.0538585,-0.28348687,0.15490325,0.8829895,-0.014019832,-0.17916541,0.027874865,0.046194345,-0.39674753,-0.4991902,-1.0936495,-2.2655258,0.28712308,0.3062436,-0.07864686,0.2525275,0.10321572,-0.086163834,0.26947227,-0.17715436,-0.6861206,-0.3886912,-0.05326306,0.058443986,-0.5777914,0.15437311,0.19049811,0.25289434,0.1809145,-0.9324337,1.3157676,1.1605527,-0.77865005,-0.54476464,-0.25389823,-0.7968005,-0.18135706,-0.32752505,0.47686017,-0.06893139,-0.3669963,-0.3656043,-0.24349539,-0.038294002,-3.8615422,-0.21388562,0.549955,0.23996615,0.27268782,0.010611329,0.2233977,-0.54284453,-0.38535947,0.1361036,0.2554217,0.299286,0.30582452,-0.96808624,-0.047579106,-0.008844443,0.53406525,-0.40323326,-0.4771782,1.0571189,-0.25730595,0.22049019,-0.8480378,0.62866956,-0.3508037,-0.57431704,0.35690808,0.058529556,0.41120374,-0.37303326,0.22492631,0.27541775,0.021659356,-0.32826716,-0.19713931,0.60175943,0.56584424,2.7791252,1.0450399,0.594266,0.20650783,-0.61168516,0.2008933,-0.4747657,0.024587486,-0.01762429,0.010493876,-0.62326825,0.3704437,-0.47063246,-0.14854854,0.24279964,-0.12406143,-0.30222398,-0.48557103,-0.08278459,0.63487,0.67132777,-0.99932593,-0.08010429,-0.6655833,-0.4096786,0.06130149,-0.34929386,0.55783796,0.19386198,0.19404489,-0.33255413,0.8587968,-0.2075023,-0.66796803,0.13709542,-0.060420133,0.4835882,0.3852095,-0.9448407,0.36258578,-0.66567135,-0.15313038,-1.3003845,0.69442594,0.19294913,0.38094082,0.13808331,-0.10014426,0.30711347,-0.35933435,0.12892267,0.42373046,0.15688801,-0.09071456,0.23043248,0.42913413,0.41824204,-0.18021575,0.11129397,-0.33085412,0.32014716,-0.71196103,-0.17633112,-0.19455895,0.5147253,0.32320574,0.042989697,-0.048838228,0.1935009,0.16269538,0.032192305,1.1123198,-0.84431124,-0.67001206,0.29565674,-0.4992154,-0.020182084,-0.49168688,0.3178972,-0.20264104,-0.036908656,0.15182772,0.4023808,-0.6536689,-0.15701845,-0.41465968,0.43057722,0.6848841,0.30100897,1.6196972,1.1918077,-0.37824315,2.4926894,-1.3363681,-0.59464365,0.027451769,0.08557453,0.03887879,-0.026824325,-0.10933608,-0.11641621,0.7005088,-0.011468995,0.3816275,-0.16541559,-0.20133889,-0.7128427,0.61280257,0.035759382,-0.24480699,-1.11442,0.49035117,-0.2760281,0.190466,0.5364733,0.6639886,0.25680214,-0.31205228,0.24600632,-0.10684079,0.64871716,-0.7363786,0.4419547,0.17056711,-0.36390266,-0.6615776,0.9569794,0.53285533,0.3697747,-0.3690424,-0.5845392,0.0757478,0.8685907,1.551799,0.77571744,0.7099622,0.62299573,-0.047043465,0.6500958,-0.010198675,-0.22083391,-0.090329014,-0.027690284,0.2020743,-0.34220135,-0.13239811,-0.74922097,0.34367022,0.4056856,-0.2654303,1.3016803,0.4247997,0.26406908,-0.27320027,0.31540078,0.32827455,0.12793702,-1.9450389,-0.38419828,0.075002335,0.15604155,0.1467857,-0.45322528,0.2651813,0.24101184,0.4704963,-0.21165113,-0.77044237,-0.7644199,0.06674867,0.29760006,-0.6619981,0.43155158,-0.18134195,-0.2950378,0.08561646,-0.21715693,0.4669162,0.5292284,-0.24674854,0.06567959,0.28479904,0.02634546,0.3878179,-0.45681316,-0.15824303,0.08249477,-0.085056454,-0.31129003,0.1623993,0.36038527,-0.35157487,-1.3610289,-0.7839526,0.30959064,1.7284135,-0.094772324,0.11379894,0.41203946,0.045135368,0.20834355,0.3884402,-0.104922004,-0.6168906,1.0942903,-0.048844784,-0.18529612,-0.0014815256,0.05581587,0.04074034,0.26128578,-0.84257406,-0.028878443,0.16798304,-0.14255713,0.3751877,-0.15724911,0.47445253,-0.20793211,-0.42448515,-1.8821567,-0.46138513,-0.05275587,0.19684908,-0.0017875135,-0.3411157,0.9906085,-0.6099685,-0.10422182,-0.2852644,1.0378195,0.73284316,-0.25559312,-0.38850874,-0.11635728,0.4252638,0.52667606,-0.056361556,-0.08761079,-0.22849727,0.07162489,0.5779581,1.3472354,0.24429214,0.7627983,0.8608464,0.11962003,-0.52168983,-1.3894522,-0.21532476,-0.41268677,-0.51807946,0.5023647,0.1996884,-0.17716783,-0.35021126,0.61440194,0.0011843555,0.10789876,-1.0063789,2.3573909,-0.23840012,0.39342797,-0.3351542,-0.12421349,0.1322378,-0.22049274,0.42365342,-0.29355833,-0.25301337,0.03335283,0.35332134,-0.1319727,-0.017306782,0.2564673,0.88989186,0.58354783,0.16554339,0.42174625,-0.111497805,0.37349415,0.51318854,0.077761844,-0.7079764,-0.31325018],"result":{"type":"object","properties":{"content":{"description":"The content of the file.","type":"string"}},"required":["content"]},"sql_tables":[],"sql_queries":[],"file_inbox":null,"oauth":null,"assets":null},false]} \ No newline at end of file diff --git a/tools/file-read/metadata.json b/tools/file-read/metadata.json index 9fe3d67..e4f5658 100644 --- a/tools/file-read/metadata.json +++ b/tools/file-read/metadata.json @@ -1,4 +1,5 @@ { + "id": "file-reader", "name": "Read File Contents", "version": "1.0.0", "description": "Reads the text contents of a file from the given path.", diff --git a/tools/file-update/.tool-dump.test.json b/tools/file-update/.tool-dump.test.json new file mode 100644 index 0000000..c363990 --- /dev/null +++ b/tools/file-update/.tool-dump.test.json @@ -0,0 +1 @@ +{"type":"Deno","content":[{"toolkit_name":"file-update","name":"Update File with Prompt","author":"Shinkai","version":"1.0.0","js_code":"import { shinkaiLlmPromptProcessor } from './shinkai-local-tools.ts';\n\ntype CONFIG = {};\ntype INPUTS = { path: string, prompt: string };\ntype OUTPUT = { new_file_content: string, message: string };\n\nexport async function run(config: CONFIG, inputs: INPUTS): Promise {\n const file_content = await Deno.readTextFile(inputs.path);\n const prompt = `\n<${inputs.path}>\n${file_content}\n\n\n\n * Only respond with the new file content, from the start of the file to the end.\n * Do not include any other text or comments.\n * Apply the following instructions in the tag to \"${inputs.path}\"\n\n\n\n ${inputs.prompt}\n \n`;\n const update = await shinkaiLlmPromptProcessor({ prompt });\n await Deno.writeTextFile(inputs.path, update.message);\n\n return { \n new_file_content: update.message, \n message: \"File updated\"\n }; \n}","tools":["local:::rust_toolkit:::shinkai_llm_prompt_processor"],"config":[],"description":"Applies a prompt to the file contents.","keywords":["file","update","prompt","text"],"input_args":{"type":"object","properties":{"path":{"type":"string","description":"The path of the file to update."},"prompt":{"type":"string","description":"The prompt to apply to the file contents."}},"required":["path","prompt"]},"output_arg":{"json":""},"activated":false,"embedding":[-0.039903395,0.1478697,-0.37138444,-0.2536462,0.42034775,0.19308072,-0.73079115,0.79844755,0.5390755,-0.2896065,-0.162473,0.70904064,-0.32502642,-0.18482137,-0.09624794,-0.2651251,-0.609646,-0.81935316,-0.88271856,-0.01937908,-0.10085076,0.55340976,0.37698966,0.39858586,0.53191835,0.6502075,0.09632544,0.211497,-1.5360123,-2.6435096,0.19663453,0.44426164,0.23009388,0.0703166,0.9099579,-0.48099,-0.036563464,0.00794445,-0.46558335,-0.39092416,0.610461,0.19468907,0.038887687,-0.3964421,-0.10741798,-0.14740476,0.40959883,-0.53380513,1.2657025,0.2965763,-0.9813956,-0.43001893,-0.54247403,-0.007885814,0.09385339,-0.0095655285,-0.022299696,-0.16926739,-0.43881342,0.21310613,-0.5904309,0.44975644,-3.9330294,0.003366638,0.2304686,0.41677976,-0.40793145,0.24047405,0.2959547,-0.55440354,-0.59958905,0.31358656,-0.42083263,0.5289503,0.15836212,-1.471573,-0.09732093,-0.021677233,0.3981617,-0.58984214,-0.06760834,0.75852627,-0.30363005,-0.4435111,-0.82126266,0.62332565,-0.19124517,0.17386177,0.24707484,0.16973849,0.2766788,0.36825925,0.68306947,0.034848794,0.20050102,-0.08022639,0.28803945,-0.08378753,0.15303749,2.8060524,0.46759516,0.47084996,0.59963673,-0.14851823,0.3826089,-0.14490002,-0.30825695,-0.49160218,-0.26169422,-0.5537072,0.29882553,-0.41973025,-0.33127865,-0.08648269,0.64579785,-0.38195258,-1.1662104,0.14285554,-0.08915171,1.1903292,-0.2657309,-0.29888767,-0.8791976,-0.052203894,-0.24990591,0.25232184,0.39312047,0.112233624,0.20348947,-0.12953644,0.53399,-0.04749395,-0.5620714,-0.7673449,0.35613254,0.6470855,0.6655971,-0.33039773,0.49075794,-1.0007432,0.07129872,-0.8365802,0.83558166,-0.24609178,0.30504823,-0.2184625,-0.7150377,-0.03675293,-0.4239329,-0.83338344,-0.30540553,0.31882566,0.44099975,-0.033006478,0.44189107,0.1351082,-0.017860558,0.4303109,-0.4026429,0.46499673,0.23424427,0.021554373,0.24941018,0.6592791,0.53289306,-0.52218735,0.06256876,0.011257041,-0.42429513,-0.0031392332,0.02167125,-0.6984439,-0.039923962,0.14456223,-0.4790928,0.38158292,-0.09277673,0.1220977,0.50893325,-0.43329892,0.052438244,0.4842253,-1.397022,-0.4553201,-0.10356268,0.3240641,0.067737706,0.18493679,0.5851721,1.0497124,-1.0224062,1.8358845,-1.4865811,-0.4442987,-0.2588486,0.46076733,-0.052975863,0.39531308,-0.42411664,0.19004482,0.28026456,0.05875508,0.47741306,-0.038415417,-0.32223785,-0.7042106,0.5208464,0.8885053,-0.40057737,-0.3352108,-0.03342961,-0.07285142,0.759855,0.27799243,1.1157476,0.15175332,-0.13291155,0.29058608,-0.16938427,0.8717817,-0.41137427,0.8388778,-0.47184545,-0.2556157,-0.5926424,0.2109636,-0.10387155,-0.029345576,-0.2337321,-0.36045682,0.6727238,1.0322102,0.85615,0.4178601,0.060016125,0.4152884,-0.18892214,0.48241818,0.20748389,-0.42650983,-0.42875284,-0.1383827,0.416398,-0.26945934,0.26700795,-0.8047602,-0.045017943,0.038441703,-0.15906563,1.1843193,0.6012529,0.088855594,0.55948305,-0.2843043,0.06701256,-0.0033614188,-1.5874362,-0.48762953,-0.26017806,0.096587494,0.22007397,-0.31763422,0.28027433,0.393404,0.09217901,-0.6059741,-0.4499374,-0.041973565,0.34829432,0.3226861,0.01581041,0.20072733,0.047392674,-0.26573905,-0.23842724,-0.06447384,0.51573956,0.5406328,-0.31117725,-0.45689532,-0.41448826,-0.2663731,-0.49987212,-0.44064802,-0.19571939,-0.51080966,-0.27360648,-0.19680703,0.00872729,0.8080794,-0.19187385,-0.49985233,-0.64229125,0.50071347,2.379929,0.045338828,0.6211416,0.85915077,-0.3084452,0.05690112,0.42632666,0.10319888,-0.34689292,0.5453186,-0.5494945,-0.029376745,-0.27340746,-0.105934694,0.118975565,0.64662135,0.14513269,-0.08858763,-0.5285297,-0.2954827,0.5633896,-0.47422564,0.49663198,0.5022613,-0.036011487,-1.8981999,-0.7474049,-0.14800891,-0.23608637,0.03129068,-0.28215757,0.5260432,0.44269934,0.8593093,0.0017987639,1.2411449,0.61670935,-0.5042192,-0.27931187,-0.09320265,0.6017174,-0.17417188,-0.021029899,-0.063922755,0.08209244,-0.19690697,1.0260704,1.8778706,0.28716427,0.5454953,0.22317907,0.50895196,-0.21493927,-1.5025272,-0.199907,0.17876531,-0.73794264,0.6096667,-0.11621555,-0.4040492,-0.15010911,0.5291127,0.43814874,-0.14281955,-0.5761751,1.7517116,-0.037796408,-0.5165784,-0.2904388,0.28494275,0.40139303,-0.2760628,0.3002559,-0.3823212,-0.9122817,-0.284226,0.08467552,-0.14658695,-0.17697525,0.40925556,0.39127195,0.8325679,0.11660272,0.49203834,0.35033125,0.31263828,0.20281029,0.52836424,-0.66714835,-0.07887113],"result":{"type":"object","properties":{"message":{"description":"The message returned from the tool.","type":"string"},"new_file_content":{"description":"The path of the file that was updated.","type":"string"}},"required":["message"]},"sql_tables":[],"sql_queries":[],"file_inbox":null,"oauth":null,"assets":null},false]} \ No newline at end of file diff --git a/tools/file-update/metadata.json b/tools/file-update/metadata.json index 18d2d5d..a3e85d0 100644 --- a/tools/file-update/metadata.json +++ b/tools/file-update/metadata.json @@ -1,4 +1,5 @@ { + "id": "file-update", "name": "Update File with Prompt", "version": "1.0.0", "description": "Applies a prompt to the file contents.", diff --git a/tools/file-write/.tool-dump.test.json b/tools/file-write/.tool-dump.test.json new file mode 100644 index 0000000..20fbd52 --- /dev/null +++ b/tools/file-write/.tool-dump.test.json @@ -0,0 +1 @@ +{"type":"Deno","content":[{"toolkit_name":"file-writer","name":"Write File Contents","author":"Shinkai","version":"1.0.0","js_code":"\ntype CONFIG = {};\ntype INPUTS = { path: string, content: string };\ntype OUTPUT = { message: string };\n\nexport async function run(config: CONFIG, inputs: INPUTS): Promise {\n try {\n await Deno.writeTextFile(inputs.path, inputs.content);\n return {\n message: \"File written\"\n }; \n } catch (error) {\n return {\n message: \"Failed to write file \" + error.message,\n }; \n }\n}","tools":[],"config":[],"description":"Writes the text contents of a file to the given path.","keywords":["file","write","save","content","text"],"input_args":{"type":"object","properties":{"path":{"type":"string","description":"The path of the file to write to."},"content":{"type":"string","description":"The content to write to the file."}},"required":["path","content"]},"output_arg":{"json":""},"activated":false,"embedding":[-0.014549136,0.3306045,0.010623809,0.34710795,0.17257398,0.06644237,-1.4433259,0.79340667,0.3200154,0.14200212,-0.013457694,1.1742105,-0.05998533,-0.27217516,0.30608752,-0.53545934,-1.1113505,-0.4852112,-1.28673,-0.52062255,-0.045713667,1.0082848,0.1051455,-0.280425,0.4606821,0.040276006,0.4114635,-0.24108294,-1.0731835,-2.4765906,0.08310933,0.45401487,-0.21076798,-0.006898947,0.45140323,-0.095220305,0.21838978,0.029122759,-0.42895025,-0.44942367,0.06679413,-0.24396394,-0.2146438,-0.19280109,-0.10422532,0.48197737,0.13546635,-0.6760576,1.1726547,0.8601404,-0.66012675,-0.29620454,-0.8183398,-0.72856545,-0.24246916,-0.27076128,0.03431056,-0.031293496,-0.15109776,-0.017892722,-0.20798804,0.39865324,-3.9953966,0.0006713234,0.7178922,0.18328021,0.33092046,0.3336682,-0.26151973,-0.32545686,-0.49092036,0.40152624,-0.052238654,0.87046874,0.54039514,-1.1568112,-0.0207678,-0.18181716,0.57120806,-0.69160694,-0.17649092,0.9864096,-0.22806545,0.5767491,-0.8603246,0.6574369,0.014650822,-0.10360512,0.3105017,-0.2222869,-0.06558968,-0.42926064,0.20834538,0.011756942,-0.22573015,-0.13948719,-0.38368568,0.5166678,0.7128568,2.7727962,0.7776012,0.22696115,0.46952018,-0.8915465,-0.033291057,-0.45063156,-0.35056576,0.042245828,-0.4374227,-0.89509064,0.3355586,-0.24818873,0.039706945,-0.32526097,0.5800467,0.08923647,-0.52462393,0.10765308,0.23816544,0.7645004,-0.78018534,-0.070886716,-0.8608689,-0.08300616,-0.22955745,0.19226775,0.5603884,0.16824265,0.25708127,-0.33594754,0.51311,-0.33226657,-0.15299347,0.34936494,-0.2556605,0.6391561,0.13773233,-0.92406696,0.54077995,-0.22816184,0.8931076,-1.1649122,0.99441516,0.37736514,0.5239982,-0.038703598,-0.5050386,-0.110050656,-0.6058962,-0.21717086,-0.16982521,0.28685325,-0.28068703,0.118647784,0.704295,-0.10715413,-0.09661652,0.3075416,-0.35882607,0.2968553,-0.3788554,-0.1638914,-0.07119171,0.75048673,0.18922323,-0.092549145,-0.08562735,-0.10826003,-0.14149918,0.023589768,0.6068331,-0.9169399,-0.449064,0.22993019,-0.7784011,0.14004722,-0.19789673,0.4141601,0.07210271,0.43419883,0.58937657,0.30005506,-0.5529813,-0.4282561,0.057661355,-0.018719653,0.40104038,0.27569667,1.1413771,1.1122822,-0.8609533,2.174323,-1.3083888,-0.16884467,0.12011647,0.28775114,0.14208685,-0.04532428,-0.17684196,-0.5879013,0.8283146,0.13116159,0.05748804,0.12706596,0.23129657,-0.80002236,0.026521016,0.5577789,-0.19492598,-0.78969574,0.58088875,-0.71387744,0.5685177,0.66645646,1.0259598,0.06320852,-0.5522171,0.66180646,0.26632988,0.20901069,-0.45640618,0.43380922,0.27643025,-0.40231875,-0.5272685,0.58058095,0.55033726,0.3938542,-0.10604507,-0.92763895,0.572325,1.0389303,1.3557471,0.7059471,0.6976317,0.22795168,0.21427763,0.49157652,-0.21424726,-0.51271,0.036108606,0.17231429,0.384692,-0.46531135,-0.5072291,-0.8673363,0.27809343,0.4017111,-0.08000428,1.6100259,0.21671647,0.40271592,-0.22550207,-0.081755266,0.45057532,0.55846816,-2.002303,-0.27432284,-0.6414228,0.28061464,0.3093992,-0.107880086,0.21025568,0.2429951,0.14653276,-0.6666288,-0.35030785,-0.6874968,-0.061106198,-0.013156585,-0.7392308,0.112501286,-0.02235203,0.107314825,0.29493564,-0.26220566,0.35689977,0.33182338,0.050738946,0.0029906612,0.23711354,-0.20861107,0.29840007,-0.34016418,-0.34782887,-0.2183025,0.10393673,-0.4915806,0.59145266,0.3148432,0.0968147,-1.1266612,-0.7889908,0.618552,2.0173414,0.4167422,0.4806697,0.044930957,0.05904943,-0.32249916,0.29608616,0.05759141,-0.31402722,0.74100035,-0.2828127,-0.3926125,-0.3492974,-0.25274813,0.21653771,0.40253896,-0.1648409,-0.03159745,0.035394523,-0.26036087,0.1953007,0.2856652,0.2797497,-0.22072849,-0.44991183,-1.522079,-0.008879771,-0.21769571,-0.01930108,0.008666411,-0.24933182,1.0830514,0.09082381,0.2020956,-0.056170292,0.6714194,0.566682,-0.69803435,-0.29342037,0.11870221,0.36008102,0.058972415,0.15174335,-0.18342644,-0.056950834,-0.56210285,0.69107586,1.0892509,-0.05280915,0.43005684,0.67724687,0.013258614,-0.4174863,-1.4324603,0.043559954,-0.69770515,-0.84633875,0.173196,-0.041902635,-0.08934089,-0.38253176,0.33225664,-0.08871407,0.06342561,-1.1730163,2.3047776,-0.30448312,0.43343067,0.11150242,-0.056016203,0.009526557,-0.3027591,0.5032218,-0.58914036,-0.28574032,-0.30649444,0.49732503,0.0952326,-0.005971417,0.39200407,0.9712191,0.05951012,-0.07585195,0.43632075,0.045046944,0.4728228,0.3124175,0.01903171,-0.64349025,-0.45729995],"result":{"type":"object","properties":{"message":{"description":"The message returned from the operation.","type":"string"}},"required":["message"]},"sql_tables":[],"sql_queries":[],"file_inbox":null,"oauth":null,"assets":null},false]} \ No newline at end of file diff --git a/tools/file-write/metadata.json b/tools/file-write/metadata.json index 092fa0f..766f784 100644 --- a/tools/file-write/metadata.json +++ b/tools/file-write/metadata.json @@ -1,4 +1,5 @@ { + "id": "file-writer", "name": "Write File Contents", "version": "1.0.0", "description": "Writes the text contents of a file to the given path.", diff --git a/tools/google-search/.tool-dump.test.json b/tools/google-search/.tool-dump.test.json new file mode 100644 index 0000000..e9180b9 --- /dev/null +++ b/tools/google-search/.tool-dump.test.json @@ -0,0 +1 @@ +{"type":"Python","content":[{"toolkit_name":"google-search-shinkai","version":"1.0.0","name":"Google Search","author":"Shinkai","py_code":"# /// script\n# dependencies = [\n# \"googlesearch-python\"\n# ]\n# ///\nfrom googlesearch import search, SearchResult\nfrom typing import List\nfrom dataclasses import dataclass\nimport json\n\nclass CONFIG:\n pass\n\nclass INPUTS:\n query: str\n num_results: int = 10\n\nclass OUTPUT:\n results: List[SearchResult]\n query: str\n\nasync def run(c: CONFIG, p: INPUTS) -> OUTPUT:\n query = p.query\n if not query:\n raise ValueError(\"No search query provided\")\n\n results = []\n try:\n results = search(query, num_results=p.num_results, advanced=True)\n except Exception as e:\n raise RuntimeError(f\"Search failed: {str(e)}\")\n\n output = OUTPUT()\n output.results = results\n output.query = query\n return output","tools":[],"config":[],"description":"This function takes a question as input and returns a comprehensive answer, along with the sources and statements used to generate the answer.","keywords":["search","answer generation","fact extraction","wikipedia","google"],"input_args":{"type":"object","properties":{"query":{"type":"string","description":"The search query to look up"}},"required":["query"]},"output_arg":{"json":""},"activated":false,"embedding":[0.74037224,0.1523448,0.12250063,-0.2330956,-0.0732149,-0.49121237,-0.7105934,0.26602554,-0.31485674,0.32427734,-0.39323238,0.7821352,0.20446597,-0.41919872,0.67798615,0.209939,0.29757926,-0.29446813,-1.6610041,-0.031176,0.78383785,0.008370239,0.25008854,-0.19770642,-0.37513775,-0.14639914,0.38888413,-0.30902037,-1.0635359,-1.5362298,0.90626204,0.7395651,-0.22855942,-0.2196196,-0.6552673,-0.38012552,-0.16014673,-0.25391504,0.018916853,-0.016465046,-0.24382688,0.05679094,-0.54244953,0.39270037,-0.2572619,-0.008627504,0.44547108,-0.057402875,0.90210915,0.88670576,-0.19960696,-0.40889594,-0.19300205,0.32754079,-0.41249725,0.20653987,-0.18449533,-0.7727064,0.06246579,-0.5266049,0.4453819,0.28019792,-4.33095,-0.010926982,0.6433091,0.18808162,0.22580339,-0.61157745,0.18193504,0.10960609,0.0867686,0.1546536,0.3066386,0.27415034,0.00094724447,-0.22532904,-0.3923833,0.025509944,0.40191758,-0.5102701,0.07003463,0.056470983,0.060049966,0.27349964,-0.38567942,0.48457092,0.1265299,-0.383452,0.36558148,-0.0033628326,-0.66018665,-0.033859618,-0.31141108,-0.13672534,-0.6319758,-0.3046636,0.28244495,0.11184969,0.42252427,3.1190393,0.2897966,-0.40488464,0.4237477,-1.1255531,0.8605757,-0.145872,0.4461098,-0.37404382,0.7425561,0.15921599,0.2937993,-0.032813367,-0.22705385,0.51221126,-0.36465305,0.20450036,-0.24083848,0.123129666,0.3802647,0.8089271,0.07132991,0.232473,-0.4389687,-0.59644294,0.057721782,0.39618132,-0.3334279,0.33608884,0.5573402,0.34885535,0.70442456,-0.39812747,-1.1715777,-0.12136582,0.13247031,0.30338153,0.3793379,-0.78292507,0.6928125,-0.5691386,0.27588916,-1.6528674,0.54117787,-0.10768123,0.59654546,-0.054497033,-0.72086287,-0.037624903,-0.413778,-0.68734956,0.10164196,0.21509701,0.3415778,0.014826264,0.7090687,0.52430075,-0.26726043,0.04955519,-0.38586935,0.17126185,-0.3468741,0.46524423,0.63281727,0.18143305,0.52894264,-0.637046,0.44291666,0.4520656,-0.19375655,-0.41542503,0.47489196,-0.4161822,-0.24842288,0.45850873,-0.04690706,-0.5877953,0.048230067,-0.14095941,0.29211515,-0.69963264,-0.33471602,0.8007372,-0.65457326,-0.4604039,-0.45024818,0.47310352,0.045648046,0.14077257,0.80203354,1.3165474,-0.57164836,1.6299654,-0.40857363,-0.60397077,-0.27461904,-0.12910345,-0.18700455,0.43255436,0.549191,0.10527582,-0.83985114,-0.12148626,0.07743675,-0.40446636,-0.16725326,-0.43537217,0.08425541,-0.123337895,-0.29343027,-0.70511866,0.28347248,-0.66800463,0.6264798,0.29570436,0.4059022,-0.080531366,-0.039702266,0.2654012,-0.7448296,0.7567029,-0.004951909,-0.038217224,-0.66041446,-0.60762405,-0.45770466,0.14596814,0.11970285,0.07908257,-0.1553611,-0.035996567,0.8584984,1.055522,-0.010617681,1.3047324,0.8748694,0.42517588,-0.10457472,0.27154553,-0.3464195,-0.35959387,0.2783715,-0.24053133,-0.3509732,-0.26509744,0.24651207,-0.65943944,0.2800332,-0.11088933,-0.009066327,1.3665054,0.9938594,0.2110039,0.21169847,0.6469496,-0.12677836,0.01716204,-1.9237192,0.019135464,-0.3490658,0.39400783,-0.22484699,-0.08604026,0.5508134,0.09623649,-0.23745012,-0.7042359,-0.075872876,-1.0612733,0.009017386,0.028394379,0.14629984,0.52394146,-0.21165091,0.11670326,0.42965937,0.23219067,-0.22103347,0.5378713,-0.7077015,-0.4177954,0.5645298,-0.027265925,-0.19830701,0.189426,-0.08153864,-0.23689003,-0.33448055,-0.046354167,0.076794356,0.20690316,-0.6722652,-0.52268887,-0.30469036,0.33876172,1.5162745,-0.03604217,0.029588792,1.017168,-0.086855166,-0.051238023,0.3323765,0.6857262,0.07683526,-0.19591287,0.0044383705,-0.77895075,0.59338504,-0.18997079,-0.26441965,0.20731027,-0.7421641,-0.09967218,0.05133872,-0.41912264,0.14718735,-0.6373423,0.49263602,0.58286464,0.29755393,-2.0216033,-0.007959459,0.40863988,-0.2722516,-0.056280687,-0.492824,0.3854516,-0.37532952,0.4678018,-0.7883893,1.9486378,0.5012205,-0.36526364,-0.46191347,0.09727245,0.674515,-0.69980514,-0.24710421,-0.10073779,-0.15110654,0.2634647,0.54191643,1.5983393,0.5812038,0.00916383,0.12389828,0.1053821,-0.377112,-1.3136234,-0.4055855,0.3349371,-0.30854625,0.43692365,-0.28489202,-0.5596402,0.46159178,1.0071299,0.531482,0.50845766,0.37580737,1.7201524,0.24967028,-0.21856175,-0.3468639,-0.7028712,-0.47778672,0.37018847,0.3560745,-0.5624895,0.423697,-0.23882222,-0.10672356,-0.33050084,0.28650072,0.29336917,0.31674817,0.65916663,0.39147034,0.81462157,0.037891425,-0.063155815,0.42848307,0.10547708,-0.5769465,-0.5225401],"result":{"type":"object","properties":{"query":{"type":"string"},"results":{"items":{"properties":{"description":{"type":"string"},"title":{"type":"string"},"url":{"type":"string"}},"required":["title","url","description"],"type":"object"},"type":"array"}},"required":["query","results"]},"sql_tables":[],"sql_queries":[],"file_inbox":null,"oauth":null,"assets":null},false]} \ No newline at end of file diff --git a/tools/google-search/metadata.json b/tools/google-search/metadata.json index 0f015e3..757d4cb 100644 --- a/tools/google-search/metadata.json +++ b/tools/google-search/metadata.json @@ -3,6 +3,7 @@ "name": "Google Search", "description": "This function takes a question as input and returns a comprehensive answer, along with the sources and statements used to generate the answer.", "author": "Shinkai", + "version": "1.0.0", "keywords": [ "search", "answer generation", diff --git a/tools/math-exp/.tool-dump.test.json b/tools/math-exp/.tool-dump.test.json new file mode 100644 index 0000000..4d86a42 --- /dev/null +++ b/tools/math-exp/.tool-dump.test.json @@ -0,0 +1 @@ +{"type":"Deno","content":[{"toolkit_name":"math-exp","name":"Math Expression Evaluator","author":"Shinkai","version":"1.0.0","js_code":"import { Parser } from 'npm:expr-eval@2.0.2';\n\ntype Configurations = {};\ntype Parameters = {\n expression: string;\n};\ntype Result = { result: string };\nexport type Run, I extends Record, R extends Record> = (config: C, inputs: I) => Promise;\n\nexport const run: Run = (\n _configurations,\n params,\n): Promise => {\n try {\n const parser = new Parser();\n const expr = parser.parse(params.expression);\n const result = expr.evaluate();\n return Promise.resolve({ ...result });\n } catch (error: unknown) {\n console.error('Error evaluating expression:', error);\n\n let errorMessage =\n 'An unknown error occurred while evaluating the expression';\n\n if (error instanceof Error) {\n errorMessage = error.message;\n } else if (typeof error === 'string') {\n errorMessage = error;\n }\n\n throw new Error(`Failed to evaluate expression: ${errorMessage}`);\n }\n};\n","tools":[],"config":[],"description":"Parses and evaluates mathematical expressions. It’s a safer and more math-oriented alternative to using JavaScript’s eval function for mathematical expressions.","keywords":["math","expr-eval","shinkai"],"input_args":{"type":"object","properties":{"expression":{"type":"string","description":"The mathematical expression to evaluate (e.g., '2 + 2 * 3')"}},"required":["expression"]},"output_arg":{"json":""},"activated":false,"embedding":[0.36967367,0.13820489,-0.18018691,-0.06061746,0.053862732,0.21220618,-0.22877245,-0.3107823,0.5681798,-0.10842194,-0.18641677,1.0145801,0.09758824,-0.46871328,0.44288108,-0.8003854,-0.27547854,0.029806692,-2.351401,-0.40808445,0.16066542,0.19848609,0.3527466,0.43821186,0.18010595,0.1713535,0.33997545,-0.33316314,-1.4285688,-1.6645143,0.18303299,0.5108868,-0.67435217,-0.15233773,-0.026045978,-0.21808416,0.0013305669,-0.00858137,-0.5878841,-0.6889627,-0.17357582,0.1827068,-0.4159857,-0.45987532,0.5200226,0.28148398,0.5548943,-0.2109483,0.71041495,0.17807344,-0.5695672,-0.3324992,0.51071566,0.21442385,0.098044075,-0.07878122,-0.29550236,-0.8045347,0.035856985,0.1700454,-0.29152042,0.48329982,-3.8031995,0.140291,1.0017263,0.37491223,0.21230449,0.12248981,-0.15960693,0.9140658,0.08892634,0.41345903,-0.2567477,0.13144514,0.52695376,-0.9829095,-0.087622836,0.10801749,0.8494919,-0.028191768,0.4844833,-0.123704284,-0.149269,0.49964926,-0.36645904,0.7687101,-0.17327076,-0.21860676,0.2667747,-0.32258928,-0.66398025,-0.39145353,-0.039533325,0.1479331,-0.65678895,0.36573893,0.34485385,0.108419515,0.61689764,2.9928799,0.4950359,-0.19744644,0.047998685,-1.2511368,0.43045107,-0.22639002,-0.28925052,0.17166206,0.5936987,0.032554977,0.2987402,-0.4508573,-0.3053726,0.29118514,0.27165344,0.62433386,-0.22101647,0.39120042,0.22517507,0.4003595,0.33603022,0.35778207,-0.4440238,0.1436653,-0.14749385,0.3546014,-0.7918863,0.43876657,-0.055472717,-0.017968806,0.6531599,0.03704976,-0.95477337,0.2029008,0.21212804,-0.3637649,0.4170754,-0.5314295,0.9451271,-0.06270531,0.4981871,-1.4777926,1.0789618,-0.27389845,1.0942268,0.15545376,-0.36948922,-0.06654019,-0.27083135,-0.21063285,-0.37044904,0.38381377,-0.084031776,0.29063785,1.0776656,0.6249772,-0.5797476,-0.3145232,0.25582728,0.22303936,0.08337048,0.10433025,0.3118384,0.682416,0.20981771,-0.7630354,0.42949808,0.28173724,-0.055977806,0.028277978,0.07644211,-0.1500487,-0.21876055,0.63717824,-0.24336761,-0.392952,0.7478404,-0.0045279264,0.2781953,-0.28795373,-0.07181533,0.50455433,-0.66905963,-0.49503186,0.11323649,0.32155833,0.41603893,0.36239958,0.19338244,0.48429978,-0.4667752,1.3982738,-0.80857515,-0.5337214,-0.32826,-0.05005458,-0.020430543,0.71022844,0.4500097,0.58962274,-0.47933018,-1.2188488,-0.039289623,-0.07938965,-0.27716693,-0.950839,0.51714313,-0.48108435,0.29074702,-0.42495376,-0.22212024,0.24877706,1.1656115,0.07707703,-0.021515436,0.17418396,-0.049847133,-0.21339005,-0.63622856,0.34684995,0.470005,-0.0014811605,-0.323857,-0.7038424,-0.39702195,0.65460336,-0.34012085,0.58842134,-0.60192543,-0.31443992,0.14376505,0.8322249,0.6937234,1.423618,0.2878114,-0.16883424,0.16429164,0.6032804,0.18053511,-0.04685873,0.26696566,-0.3231273,-0.6927969,0.30437207,-0.32643548,0.05459039,0.057466283,-1.0489061,-0.5959848,1.6899302,0.9979789,-0.3295823,0.13252099,0.51117814,-0.662587,-0.66738385,-2.0389743,-0.1492581,-0.8409445,0.22102407,-0.9486347,-1.1587538,0.9875838,0.76368,-0.6034394,0.079189554,-0.04153853,-0.7219739,-0.12851311,0.3494278,-0.15630601,0.28968954,-0.049051583,-0.34130186,-0.48374012,0.06986832,0.27204108,-0.039116576,-0.76302004,-0.2314945,0.28012154,0.51277715,-0.13342395,0.38889462,-0.3559021,-0.32951733,0.06259091,0.42546517,0.3081396,0.579204,-0.8814852,-0.104001544,-0.6395018,0.3358991,0.85187197,0.98876977,-0.345068,0.48206925,-0.6907707,-0.17400067,-0.8074576,0.26242837,0.17852136,-0.5406647,-0.2205798,-0.09535846,0.7594191,-0.39958072,-1.0405165,-0.24997479,-0.39850602,0.3604246,0.6563322,-0.05293411,0.7517185,-0.4574319,0.91073626,0.40672532,-0.19313775,-1.4429543,-0.48297805,0.45363176,-0.443804,-0.9323735,-0.6854489,0.4151727,-0.019103779,0.002061028,-0.46029502,1.4152046,0.6069861,0.24967723,-0.63946867,0.12329558,1.2102864,-0.6938691,0.06031894,0.04400401,0.070920385,-0.07568397,0.8633082,1.2616405,0.15856035,0.57713014,-0.12644015,0.22147396,-0.23180798,-1.1246669,-0.006440513,-0.21734972,-0.41508818,1.2805828,0.2694194,0.26632312,-0.0282857,0.5457553,0.4101187,0.12649411,-0.55052865,2.0240014,-0.13674003,-0.4983088,-0.49487492,-0.5951213,0.20916791,0.1301647,0.5942216,-0.60187054,-0.064847246,0.8937914,0.3362784,-0.39291066,0.2612105,-0.22315742,0.5770974,0.30526137,-0.18634716,0.40400478,-0.022974372,0.104909,0.12522572,-0.10052472,-0.6474921,-0.29402596],"result":{"type":"object","properties":{"result":{"description":"The evaluated result of the mathematical expression","type":"string"}},"required":["result"]},"sql_tables":null,"sql_queries":null,"file_inbox":null,"oauth":null,"assets":null},false]} \ No newline at end of file diff --git a/tools/math-exp/index.test.ts b/tools/math-exp/index.test.ts index d02cc67..24c5d8c 100644 --- a/tools/math-exp/index.test.ts +++ b/tools/math-exp/index.test.ts @@ -1,6 +1,6 @@ import { expect } from 'jsr:@std/expect/expect'; -import { definition } from './index.ts'; +import { run } from './tool.ts'; Deno.test('exists definition', () => { - expect(definition).toBeInstanceOf(Object); + expect(run).toBeInstanceOf(Function); }); diff --git a/tools/math-exp/metadata.json b/tools/math-exp/metadata.json index 599602e..081a9e8 100644 --- a/tools/math-exp/metadata.json +++ b/tools/math-exp/metadata.json @@ -8,6 +8,7 @@ "expr-eval", "shinkai" ], + "version": "1.0.0", "configurations": { "type": "object", "properties": {}, diff --git a/tools/memory/.tool-dump.test.json b/tools/memory/.tool-dump.test.json new file mode 100644 index 0000000..54c830d --- /dev/null +++ b/tools/memory/.tool-dump.test.json @@ -0,0 +1 @@ +{"type":"Deno","content":[{"toolkit_name":"memory-management","name":"Memory Management","author":"Shinkai","version":"1.0.0","js_code":"import { shinkaiSqliteQueryExecutor } from './shinkai-local-tools.ts';\nimport { shinkaiLlmPromptProcessor } from './shinkai-local-tools.ts';\n\ntype CONFIG = {};\ntype INPUTS = {\n data: string;\n general_prompt?: string;\n specific_prompt?: string;\n key?: string;\n};\ntype OUTPUT = {\n generalMemory: string;\n specificMemory: string;\n};\n\nconst createTable = async (): Promise => {\n // Create table if not exists\n const createTableQuery = `\n CREATE TABLE IF NOT EXISTS memory_table (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n date DATETIME DEFAULT CURRENT_TIMESTAMP,\n key TEXT,\n memory TEXT\n );\n `;\n await shinkaiSqliteQueryExecutor({ query: createTableQuery });\n}\n\nconst getGeneralMemory = async (): Promise => {\n const fetchGeneralMemoryQuery = `\n SELECT id, key, memory \n FROM memory_table \n where key is null\n `;\n const fetchGeneralMemory = await shinkaiSqliteQueryExecutor({ query: fetchGeneralMemoryQuery });\n\n if (fetchGeneralMemory.result.length) {\n return fetchGeneralMemory.result[0];\n }\n return null;\n}\n\nconst getSpecificMemory = async (key: string): Promise => {\n const fetchSpecificMemoryQuery = `\n SELECT id, key, memory \n FROM memory_table \n where key = ?\n `;\n const fetchSpecificMemory = await shinkaiSqliteQueryExecutor({ query: fetchSpecificMemoryQuery, params: [key] });\n\n if (fetchSpecificMemory.result.length) {\n return fetchSpecificMemory.result[0];\n }\n return null;\n}\n\nconst generatePrompt = async (\n previousMemory: null | {id: number, key: string, memory: string}, \n general_prompt: string, \n data: string): Promise => {\n let generalPrompt = `\nYou must generate memories, so we can recall new and past interactions.\nBased on the rules, you must generate the output.\nWe should merge new and past interactions into a single memory.\nKeep the most important information only.\n\nThese are some sections you must understand: \n * rules tag: has the rules you must follow to generate the output.\\n`;\n if (previousMemory) generalPrompt += `. * previous_interactions tag: has entire previous interaction memory\\n`;\n generalPrompt += `. * input tag: has the new data to for creating newa memories.\n \n\n ${general_prompt}\n\n `\n if (previousMemory) \n generalPrompt += `\n\n ${previousMemory.memory}\n\n `;\n \n generalPrompt += `\n\n ${data}\n\n `;\n return generalPrompt;\n}\n\nexport async function run(config: CONFIG, inputs: INPUTS): Promise {\n const { \n data, \n general_prompt = 'Important information to remember from this interaction', \n specific_prompt = 'Important information to remember from this interaction', \n key\n } = inputs;\n\n await createTable();\n\n let generalMemory = '';\n let specificMemory = '';\n\n // Update General Memory\n if (data) {\n const previousGeneralMemory = await getGeneralMemory();\n const generalPrompt = await generatePrompt(previousGeneralMemory, general_prompt, data);\n const generalResponse = await shinkaiLlmPromptProcessor({ format: 'text', prompt: generalPrompt });\n generalMemory = generalResponse.message;\n \n if (previousGeneralMemory) {\n const generalUpdateQuery = `\n UPDATE memory_table SET memory = ?\n WHERE id = ?\n `;\n await shinkaiSqliteQueryExecutor({ \n query: generalUpdateQuery, params: [generalMemory, \"\"+ previousGeneralMemory.id]});\n \n } else {\n const generalInsertQuery = `\n INSERT INTO memory_table (memory)\n VALUES (?);\n `;\n await shinkaiSqliteQueryExecutor({ query: generalInsertQuery, params: [generalMemory]});\n }\n }\n \n // Update specific memory\n if (key && data) {\n const previousSpecificMemory = await getSpecificMemory(key);\n const specificPrompt = await generatePrompt(previousSpecificMemory, specific_prompt, data);\n const specificResponse = await shinkaiLlmPromptProcessor({ format: 'text', prompt: specificPrompt });\n specificMemory = specificResponse.message;\n\n if (previousSpecificMemory) {\n const specificUpdateQuery = `\n UPDATE memory_table SET memory = ?\n WHERE id = ?\n `;\n await shinkaiSqliteQueryExecutor({ \n query: specificUpdateQuery, \n params: [specificMemory, \"\"+previousSpecificMemory.id]\n });\n } else {\n const specificInsertQuery = `\n INSERT INTO memory_table (key, memory) \n VALUES (?, ?);\n `;\n await shinkaiSqliteQueryExecutor({ \n query: specificInsertQuery, \n params: [key, specificMemory]\n });\n }\n }\n \n return {generalMemory, specificMemory};\n}","tools":["local:::rust_toolkit:::shinkai_sqlite_query_executor","local:::rust_toolkit:::shinkai_llm_prompt_processor"],"config":[],"description":"Handles memory storage and retrieval using a SQLite database.","keywords":["memory","remember","management","recall","smart","agent"],"input_args":{"type":"object","properties":{"key":{"type":"string","description":"The key for specific memory retrieval"},"specific_prompt":{"type":"string","description":"The specific prompt for generating memories"},"general_prompt":{"type":"string","description":"The general prompt for generating memories"},"data":{"type":"string","description":"The data to process for memory management"}},"required":["data"]},"output_arg":{"json":""},"activated":false,"embedding":[0.111937836,0.74089676,-0.12515827,-0.4942115,-0.25368002,-0.056685545,-0.809049,0.13576964,0.24071948,-0.02976514,-0.47945547,0.99631506,-0.08526395,-0.08666597,0.4112748,-0.34366244,0.28832552,0.8723968,-1.8125455,-0.06927829,0.3785739,0.44344294,0.07779312,-0.13623443,-0.198864,0.104956515,0.07281388,-0.64128476,-0.8674953,-2.212524,0.23000515,0.8036334,-0.32317746,0.08531259,0.06165708,-0.5280139,-0.27165845,0.2298748,-1.0989754,-0.4352798,0.060814954,0.20959929,-0.6922089,0.14129707,0.3951045,-0.2094253,0.28318685,0.03080573,0.6607957,0.44034725,-0.3435076,-0.6636055,-0.49609208,0.031462383,-0.46229592,-0.11738148,-0.2673628,-0.12942854,-0.13213739,-0.56978685,-0.49050757,-0.033710778,-3.0540113,-0.35828966,0.4477928,0.11795497,0.6029618,0.03019675,-0.13932246,-0.116601504,-0.5129008,0.22289489,0.001567632,0.43084416,0.010488745,-0.65866005,0.5444606,-0.16649291,0.5965793,-0.56898767,0.5876942,0.68564534,0.057885304,-0.11264849,-0.36528912,0.22000486,-0.5172195,-0.034327753,0.20772007,0.10029636,-0.11128229,-0.35220385,0.042001657,-0.09486667,-0.49064255,0.5016759,0.5429697,0.53100413,0.67431355,2.9295228,0.6061498,-0.0052450076,1.1123242,-0.5553272,0.58578116,-0.396771,-0.0043778606,-0.2641139,-0.18956795,-0.04787702,0.5651373,0.04069993,0.10868324,0.3633739,0.31594813,-0.14918776,-0.90317976,0.014140373,0.09339001,0.4759403,-1.2680333,0.15725,-0.8017013,-0.072784826,-0.2027275,-0.248173,-0.47450486,0.35822383,0.089721486,-0.8434949,0.17163289,-0.60608387,-1.5258477,-0.092011675,0.15190832,0.029228859,0.09951277,-1.0531722,-0.8432071,-1.2045652,0.22168328,-1.8012422,1.257536,0.3710498,0.82652575,1.064956,-0.07364569,-0.08260139,-0.32399875,-0.2577161,0.35024714,0.3111611,0.20929018,-0.17805251,0.8778527,-0.086034104,0.20599265,0.22164212,-0.5891931,-0.16454726,-0.681477,-0.039246723,0.36468878,0.25415224,0.87371546,-1.1239837,-0.07615483,-0.40367773,0.4243997,-0.22388089,-0.036021143,0.070409395,0.051366255,0.23837432,0.1067911,-0.5528012,0.23844612,0.0024840161,-0.080963686,-0.751668,-0.0518061,0.65869457,-0.27564827,-0.7393524,-0.30968362,-0.65195227,0.98374283,-0.09401393,0.04650405,0.98091817,-0.44676092,1.0435079,-0.8741324,0.5287304,-0.24334532,-0.3493321,-0.09778318,0.6641216,0.6423144,-0.56234205,-0.34151262,-0.6116001,-0.15467788,0.09333934,0.65145075,-0.36601484,-0.3339522,0.050637126,0.41447765,-0.524192,-0.22862165,-0.5204915,0.31959406,0.34199706,0.31173804,0.29922813,0.04193517,0.65267223,0.23422848,0.9934678,0.8802714,-0.06621673,0.4821114,-0.5185084,-0.2266081,-0.7151844,-0.047955215,-0.44060528,-0.43365583,-0.5805751,0.23047966,0.8946043,0.8859454,0.15834664,0.5712067,0.035358794,0.26624507,0.36157402,0.4208076,-0.784662,0.5708339,0.2283394,-0.415547,-0.34696782,0.041988354,-0.25026345,0.35980847,0.3587914,0.43452892,1.2345545,0.8542529,0.43813187,-0.117733255,0.3318603,0.37991884,0.049697533,-1.7096437,0.12233965,-0.33652085,0.3047968,0.4880944,0.005683899,0.48125106,1.0229537,0.42820078,0.1880018,-0.9280594,0.3796176,0.1298208,-0.008567318,-0.70267904,1.1864583,-0.43549532,-0.4198141,-0.07940441,-0.76350194,0.7171461,-0.42064208,-0.34265658,-0.36742902,0.12565221,0.12214184,0.9031202,-0.023328215,-0.048132613,-0.167081,-0.33202252,0.27307153,0.20823562,0.9203475,-0.19106463,-0.35383615,-0.7042749,0.85880107,1.4127065,1.3556606,0.24954379,0.52383125,0.82653356,-0.12702428,0.067642696,0.41572976,-0.33709046,0.09285276,-0.18625477,0.002191268,0.55797386,0.38143012,-0.35884345,0.2095905,-1.2938337,0.13288312,0.13235816,-0.22439846,0.3647071,-0.53730625,0.47953555,1.4558412,-0.17408374,-2.000823,-0.6611798,0.23612174,-0.14356868,-0.20251471,-0.13713701,0.20885682,-0.7435712,0.25030732,0.543007,1.3142625,0.44838735,-0.8564536,-0.75826186,-0.43299165,0.9422145,0.4068938,0.554768,-0.13111398,-0.42246768,-0.07616982,0.5571903,1.2492561,0.48375618,0.051635597,-0.21371765,0.35021627,-0.5410304,-1.1716174,0.5095912,-0.62912905,-0.37279865,0.41224012,0.59948826,-0.3992,0.7356437,1.1001694,0.24999188,0.24701267,-1.1759105,1.4969252,-0.020239882,-0.31295842,-0.93301684,0.77810735,-0.3480711,-0.41037232,0.65593684,-0.14069337,-0.28005433,-0.22853693,-0.022693757,-0.26941186,0.16493139,0.45033836,0.60703117,0.5285942,0.12087938,0.25766528,-0.34744433,0.104460105,1.0776262,0.4048118,-1.3009826,-0.40838832],"result":{"type":"object","properties":{"generalMemory":{"description":"The updated general memory","nullable":true,"type":"string"},"specificMemory":{"description":"The updated specific memory","nullable":true,"type":"string"}},"required":[]},"sql_tables":[{"name":"memory_table","definition":"CREATE TABLE IF NOT EXISTS memory_table (id INTEGER PRIMARY KEY AUTOINCREMENT, date DATETIME DEFAULT CURRENT_TIMESTAMP, key TEXT, memory TEXT)"}],"sql_queries":[{"name":"Get general memory","query":"SELECT id, key, memory FROM memory_table WHERE key IS NULL"},{"name":"Get specific memory","query":"SELECT id, key, memory FROM memory_table WHERE key = ?"},{"name":"Update memory","query":"UPDATE memory_table SET memory = ? WHERE id = ?"}],"file_inbox":null,"oauth":null,"assets":null},false]} \ No newline at end of file diff --git a/tools/memory/metadata.json b/tools/memory/metadata.json index cb5bb9e..21865ce 100644 --- a/tools/memory/metadata.json +++ b/tools/memory/metadata.json @@ -1,4 +1,5 @@ { + "id": "memory-management", "name": "Memory Management", "description": "Handles memory storage and retrieval using a SQLite database.", "author": "Shinkai", diff --git a/tools/perplexity-api/.tool-dump.test.json b/tools/perplexity-api/.tool-dump.test.json new file mode 100644 index 0000000..22a0f6d --- /dev/null +++ b/tools/perplexity-api/.tool-dump.test.json @@ -0,0 +1 @@ +{"type":"Deno","content":[{"toolkit_name":"perplexity-api","name":"Perplexity API","author":"Shinkai","version":"1.0.0","js_code":"type Configurations = {\n apiKey: string;\n};\ntype Parameters = {\n query: string;\n};\n\ntype Result = {\n response: string;\n};\n\ninterface PerplexityResponse {\n choices: Array<{\n message: {\n content: string;\n };\n }>;\n}\nexport type Run, I extends Record, R extends Record> = (config: C, inputs: I) => Promise;\n\nexport const run: Run = async (\n configurations,\n parameters,\n): Promise => {\n const response = await fetch('https://api.perplexity.ai/chat/completions', {\n method: 'POST',\n headers: {\n accept: 'application/json',\n authorization: `Bearer ${configurations.apiKey}`,\n 'content-type': 'application/json',\n },\n body: JSON.stringify({\n model: 'llama-3.1-sonar-small-128k-online',\n messages: [\n { role: 'system', content: 'Be precise and concise.' },\n { role: 'user', content: parameters.query },\n ],\n }),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch data from Perplexity API, status: ${response.status}`,\n );\n }\n\n const data = (await response.json()) as PerplexityResponse;\n const responseContent =\n data.choices[0]?.message?.content || 'No information available';\n\n return { response: responseContent };\n};\n","tools":[],"config":[{"BasicConfig":{"key_name":"apiKey","description":"API key for accessing the Perplexity API","required":true,"type":null,"key_value":null}}],"description":"Searches the web using Perplexity API (limited)","keywords":["perplexity","api","shinkai"],"input_args":{"type":"object","properties":{"query":{"type":"string","description":"The search query to send to Perplexity API"}},"required":["query"]},"output_arg":{"json":""},"activated":false,"embedding":[0.11645089,0.3802397,-0.09272365,-0.67411584,-0.7537766,-0.032171614,-0.45825568,-0.49803934,-0.07670201,-0.057288826,-0.54977757,1.0430512,0.6679656,-0.1604064,0.4738902,0.50352037,0.21564056,-0.6655856,-1.5949762,0.22694373,0.5342862,0.7357455,0.50433016,0.28663254,-0.02867283,-0.031037897,-0.5205588,-0.041651927,-1.3853055,-2.3032627,0.8839041,0.30389038,-0.14362933,-0.2686656,-0.059750296,-0.5206286,-0.2615851,0.036210623,-0.6085326,0.055579424,0.29047012,0.47797203,-0.7003521,0.032415316,-0.29938808,-0.27016744,0.29302964,-0.19847909,0.53113383,0.3267147,-0.27189824,-0.04888197,0.18237285,0.34493575,-0.49145225,0.12325862,-0.092084035,-0.307699,-0.21803373,0.13233665,0.5443668,0.8112723,-3.989468,0.15532626,-0.15926404,0.3642894,-0.15024883,-0.41265762,0.10903634,0.7352435,0.11528505,-0.24735595,-0.21702892,0.22264877,0.064511694,-0.38259807,0.00055605546,0.14024082,0.14670368,-0.39417234,0.41306466,0.5847184,-0.3451556,-0.12406353,-0.032791402,0.43859747,-0.15003729,0.02542606,0.33477247,0.16663855,-0.703967,-0.1934891,0.03318881,-0.27462703,-0.733422,0.0606576,0.19128543,0.636479,0.5873402,3.5084991,0.45497346,-0.4058737,0.17792565,-0.29604372,0.6499731,-0.2301283,0.10245432,-0.1421148,-0.04591573,-0.06489993,-0.0492054,-0.06698479,0.45488554,0.41171885,-0.30030915,-0.59429204,0.1879906,0.30220774,0.20928462,0.5431731,-0.8490738,0.4382806,-0.37295023,-0.21139148,0.038392637,0.08154917,-1.0377465,0.27984643,0.43633434,-0.13672704,0.4028079,-0.26608434,-0.6147281,0.21044709,-0.124731585,0.09012708,0.35903013,-0.45551512,0.23613182,-0.6970096,0.3138734,-1.2784092,1.0144013,0.5601748,0.5553081,0.85539246,-0.3101067,-0.018381156,-0.36182493,0.2906356,-0.38740358,0.27574438,-0.106455676,-0.5253885,0.3617983,-0.27406377,0.10209672,0.05118013,-0.62402046,0.31799307,-0.22534356,0.17344433,0.50287616,0.8384853,0.4648925,-0.49320915,0.23515385,-0.04215353,0.12130138,-0.36237866,0.33668444,0.13787805,-0.029066041,0.44245827,-0.5305936,0.27351266,-0.771116,0.13033041,-0.08559129,-1.0153216,0.23239507,0.96706855,-0.021236736,-0.75734127,-0.15587541,0.28624126,0.2334207,-0.13497245,0.52321583,0.31058794,-0.5444632,2.087078,-0.7947092,-0.47221297,0.041387036,-0.19452813,-0.5043615,0.49735773,-0.17028435,-0.34137905,-0.3128182,-0.7499987,-0.018927649,0.07509248,0.14645281,-0.72122896,0.6193227,-0.55968297,0.42440146,-0.60465604,-0.0012502596,-0.20697278,0.017538324,0.0798682,0.5066283,-0.120684266,0.2885825,0.11684653,0.1198242,0.38593853,0.12598982,-0.18813714,-0.4122072,-0.492496,-0.4052348,-0.25425065,-0.477075,0.06350674,-0.28631818,-0.07108346,0.55995566,0.49807364,0.65559477,0.89627963,0.8168491,-0.20774716,-0.42542398,0.7693567,0.33275378,-0.45456913,0.5645004,-0.13026272,-0.2622282,-0.3358931,0.5276109,-1.1812775,0.015307136,0.06622091,-0.5011313,2.07899,1.0236517,-0.02029689,0.29381785,-0.032027494,-0.22639114,-0.13027939,-1.6197495,-0.047988273,-0.6458405,0.58243275,-0.38908395,-0.17550264,0.35894585,-0.07727822,0.19970895,0.0067867376,-0.86764807,-0.5372001,0.03185998,-0.25801203,-0.110302955,0.67893493,-0.098150775,0.44518924,0.2846071,-0.06250328,0.57811636,-0.017079383,-0.8492406,0.11247228,0.2989498,0.34395933,0.7322431,-0.013522863,-0.3790063,-0.38699606,-0.4408811,0.6623414,-0.55028033,0.08520629,-0.5261909,0.18402901,-0.5693831,-0.25149646,1.8593986,0.45961162,0.61170405,0.21321318,0.070005484,0.3738091,-0.23829171,0.064711,0.49576297,0.14187577,-0.13750578,-0.08783659,0.58597755,-0.34088972,-0.49333525,-0.19943738,-0.1679697,0.21279567,0.056609992,-0.6321387,0.46428663,-0.41508734,0.14146604,0.52955735,0.07605636,-1.9218364,-0.30150202,0.42497358,-0.006485235,-0.44263524,-0.28049743,0.42112368,-0.3480398,0.09213908,0.22300623,1.6682819,0.59545535,-0.45685238,-0.4643534,-0.48270938,0.72018564,-0.39325646,-0.14966555,-0.3658264,-0.7589981,-0.1770872,0.51835907,1.179172,0.6406662,0.6497778,-0.081445806,0.27046713,-0.32926446,-1.228502,0.09208644,0.33586162,-0.47407374,0.7246797,-0.029335575,-0.55128133,1.0291284,0.737099,0.37892345,-0.120127216,-0.25902197,1.7916461,0.08593016,-0.014039258,-0.3299547,0.38398552,0.101137094,0.56588775,-0.17234516,-0.2501452,-0.13663173,-0.09309722,-0.19804183,-0.6805411,0.29109603,0.1611939,0.041646678,0.4484455,0.07696198,0.41209462,0.37516358,0.34763062,-0.32356164,0.09036073,-0.6707306,0.41546535],"result":{"type":"object","properties":{"response":{"description":"The search results and analysis from Perplexity API","type":"string"}},"required":["response"]},"sql_tables":null,"sql_queries":null,"file_inbox":null,"oauth":null,"assets":null},false]} \ No newline at end of file diff --git a/tools/perplexity-api/index.test.ts b/tools/perplexity-api/index.test.ts index d02cc67..24c5d8c 100644 --- a/tools/perplexity-api/index.test.ts +++ b/tools/perplexity-api/index.test.ts @@ -1,6 +1,6 @@ import { expect } from 'jsr:@std/expect/expect'; -import { definition } from './index.ts'; +import { run } from './tool.ts'; Deno.test('exists definition', () => { - expect(definition).toBeInstanceOf(Object); + expect(run).toBeInstanceOf(Function); }); diff --git a/tools/perplexity-api/metadata.json b/tools/perplexity-api/metadata.json index 76cc38f..242d9f4 100644 --- a/tools/perplexity-api/metadata.json +++ b/tools/perplexity-api/metadata.json @@ -3,6 +3,7 @@ "name": "Perplexity API", "description": "Searches the web using Perplexity API (limited)", "author": "Shinkai", + "version": "1.0.0", "keywords": [ "perplexity", "api", diff --git a/tools/perplexity/.tool-dump.test.json b/tools/perplexity/.tool-dump.test.json new file mode 100644 index 0000000..2dd6b85 --- /dev/null +++ b/tools/perplexity/.tool-dump.test.json @@ -0,0 +1 @@ +{"type":"Deno","content":[{"toolkit_name":"perplexity","name":"Perplexity","author":"Shinkai","version":"1.0.0","js_code":"import * as playwright from 'npm:playwright@1.48.2';\nimport chromePaths from 'npm:chrome-paths@1.0.1';\nimport TurndownService from 'npm:turndown@7.2.0';\nimport { defineConfig } from 'npm:playwright@1.48.2/test';\n\ntype Configurations = {\n chromePath?: string;\n};\ntype Parameters = {\n query: string;\n};\ntype Result = { response: string };\nexport type Run, I extends Record, R extends Record> = (config: C, inputs: I) => Promise;\n\nexport const run: Run = async (\n configurations,\n params,\n): Promise => {\n defineConfig({\n use: {\n actionTimeout: 60 * 1000,\n navigationTimeout: 60 * 1000,\n },\n });\n const chromePath =\n configurations?.chromePath ||\n Deno.env.get('CHROME_PATH') ||\n chromePaths.chrome ||\n chromePaths.chromium;\n const browser = await playwright['chromium'].launch({\n executablePath: chromePath,\n });\n const context = await browser.newContext({\n viewport: { width: 1280, height: 800 }, // Set viewport size\n userAgent:\n 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36', // Set Mac user agent\n });\n const page = await context.newPage();\n\n console.log(\"Navigating to Perplexity's website...\");\n await page.goto('https://www.perplexity.ai/');\n\n console.log('Waiting for the page to load...');\n await page.waitForTimeout(2500);\n\n console.log('Filling textarea with query:', params.query);\n await page.fill('textarea', params.query);\n\n try {\n console.log('trying to click app popup');\n await page.click('button:has(svg[data-icon=\"xmark\"])', { timeout: 2000 });\n } catch (_) {\n console.log('unable to find the x button to close the popup');\n /*\n We do nothing, so we have two cases:\n - the code continue and fails later because we are not able to click the \"submit\" button\n - the code continue and it just works because the app was changed and the popup doesn't exists\n */\n }\n\n console.log('Clicking the button with the specified SVG...');\n await page.click('button:has(svg[data-icon=\"arrow-right\"])');\n\n console.log('Waiting for the button with the specified SVG to be visible...');\n await page.waitForSelector('button:has(svg[data-icon=\"arrow-right\"])');\n\n console.log('Waiting for results to load...');\n await page.waitForSelector('div:has-text(\"Related\")');\n\n console.log('Extracting HTML content...');\n const htmlContent = await page.evaluate(() => {\n const resultElements = document.querySelectorAll('div[dir=\"auto\"]');\n return Array.from(resultElements)\n .map((element) => element.innerHTML)\n .join('\\n\\n');\n });\n\n console.log('Closing browser...');\n await browser.close();\n\n console.log('Converting HTML to Markdown...');\n const turndownService = new TurndownService();\n turndownService.addRule('preserveLinks', {\n filter: 'a',\n replacement: function (_content: string, node: Element) {\n const element = node as Element;\n const href = element.getAttribute('href');\n return `[${href}](${href})`;\n },\n });\n const markdown = turndownService.turndown(htmlContent);\n\n const result: Result = {\n response: markdown,\n };\n\n console.log('Returning result:', result);\n return Promise.resolve({ ...result });\n};\n","tools":[],"config":[{"BasicConfig":{"key_name":"chromePath","description":"Optional path to Chrome executable for browser automation","required":false,"type":null,"key_value":null}}],"description":"Searches the internet using Perplexity","keywords":["perplexity","shinkai"],"input_args":{"type":"object","properties":{"query":{"type":"string","description":"The search query to send to Perplexity"}},"required":["query"]},"output_arg":{"json":""},"activated":false,"embedding":[0.110977024,0.45141035,-0.22621103,-0.73839366,-0.66569847,-0.31065282,-0.46436575,-0.7566426,0.1667947,-0.1629707,-0.4797544,1.1697905,0.52487624,-0.32671282,0.41614112,0.2732951,0.1568219,-0.31578588,-1.1693568,0.539343,0.44237193,0.95825374,0.49016786,0.059257735,0.4595508,-0.1266626,-0.21971467,0.09240231,-0.9244625,-1.95901,0.8332707,-0.035402037,-0.66910744,-0.19510643,0.1861836,-0.74896175,-0.35335997,-0.07804075,-0.58601236,-0.17889635,0.5337802,0.27349943,-0.7119388,0.17112043,-0.16353837,-0.57286483,0.09144518,0.040901445,0.8881004,0.2469415,-0.46033227,-0.22207537,0.101119384,0.5036361,-0.53512615,0.07257283,0.095575824,-0.4892627,-0.45294943,0.26567355,0.3056356,0.7391675,-4.124245,-0.01896253,-0.073930755,0.16979778,0.17980833,-0.37738553,-0.06460192,0.55790734,0.1866517,-0.053921215,-0.24112093,0.3796582,0.12659699,-0.29600048,-0.09610622,-0.071760796,0.05149146,-0.4111525,0.5461365,0.031101018,-0.022535065,-0.018076565,0.12750974,0.22313613,-0.1957128,0.0038962662,0.13298415,0.16826509,-0.16611812,-0.13953725,0.07203346,-0.16827995,-0.3837615,0.061622147,0.45724794,0.40976992,0.54124093,3.4934232,0.5210436,-0.27958888,0.37268105,0.040759567,0.45173663,-0.0924283,-0.10492885,-0.16183156,-0.17369998,-0.076129496,-0.06847698,-0.19875674,0.09101013,0.5059889,-0.29385746,-0.0088841915,0.094699666,0.40071553,0.40991813,0.11015464,-0.76521057,0.6529254,-0.242373,-0.20075738,-0.17936552,0.07580075,-1.1185092,0.27016765,0.44116879,-0.019928018,0.37141103,0.0018014051,-0.53716743,0.32028934,-0.017729454,0.26877978,0.16377993,-0.469709,0.12641262,-0.82514167,0.18262884,-1.1703655,0.8664657,0.11342133,0.8947825,0.7961433,-0.17412767,-0.071389996,-0.5180277,-0.028393395,-0.3576064,0.63728005,-0.046309672,-0.6841276,0.527785,-0.34813526,0.07180974,0.43599373,-0.3724407,0.49021587,-0.34073755,-0.087408625,0.57178354,0.9395102,0.6860182,-0.061857704,0.21753679,-0.2272897,0.37726143,-0.4223989,0.31156868,-0.021819092,-0.27533802,0.5426756,-0.46329278,0.116780296,-0.32852674,0.45712313,-0.03879409,-0.99532163,-0.17527305,0.7517308,-0.12523344,-0.7820304,0.027986802,0.20813407,0.13434884,-0.13795245,0.5918208,0.51871544,-0.6702558,1.6690733,-0.6676787,-0.3809836,0.030475017,0.011550121,-0.20073879,0.31808943,0.115490794,-0.33595,0.057966836,-0.5639761,0.045757085,0.21266335,-0.04119896,-0.69224423,0.7007585,-0.432434,0.5445157,-0.54269814,0.016974775,0.11220923,-0.024178773,0.19408104,0.43770552,-0.07191335,-0.017497398,0.17782195,0.10322357,0.5189725,-0.09310021,-0.072219215,-0.11473365,-0.5251292,-0.701344,-0.20285986,-0.4204037,-0.14125952,-0.16444397,-0.2067886,0.34788606,0.079939,1.1590862,0.5584607,0.89061195,-0.038665645,-0.3988015,0.74298346,0.24514607,-0.906924,0.7279031,-0.108730376,-0.5052251,-0.48092008,0.4195812,-1.0718536,0.17381667,-0.014733531,-0.24340673,1.9078574,0.97720516,-0.05337442,0.3462506,-0.10808912,-0.09447292,0.38402006,-1.4023371,0.03120788,-0.519497,0.58436084,-0.40587917,-0.4480681,0.2578387,-0.306957,0.20576254,0.17248659,-0.68005055,-0.7617563,-0.10644278,-0.49746716,-0.028531365,0.66250485,-0.30359608,0.4068188,0.6908709,-0.0040249396,0.50787115,0.026117712,-0.5721714,-0.049632005,0.25709268,0.28320572,0.739039,-0.089835346,-0.26498985,-0.3371122,-0.40288514,0.08845858,-0.04875935,0.21212035,-0.5365946,0.1202167,-0.28503323,0.06540573,2.3434439,0.52442706,0.9950618,0.35708734,-0.024971133,0.24164142,-0.0024675503,-0.24290478,0.3384783,0.15465873,-0.24039613,-0.3583358,0.48492467,-0.37566948,-0.5859746,-0.7427742,-0.033714246,-0.15926056,0.030271929,-0.2851397,0.51082003,-0.69576013,0.10975328,0.32911056,0.07521139,-2.2029974,-0.32307673,0.6154103,0.3786558,-0.43247128,-0.08517668,0.5010204,-0.30798858,0.38705644,0.18583356,1.8067048,0.5006732,-0.3077378,-0.451505,-0.47177285,0.8022604,-0.4174476,0.051823355,-0.41506773,-0.9942333,-0.28698784,0.33536983,1.4645271,0.535335,0.66993743,-0.09726632,0.18442869,-0.29600212,-1.6375569,0.19774191,0.41653043,-0.39089012,0.5119712,0.060523115,-0.60206085,0.7337946,0.57138455,0.067463085,-0.12759255,-0.1821385,1.439113,0.26482844,-0.1934892,-0.35052425,0.32630876,0.04205793,0.19897152,-0.1018547,-0.63383335,-0.48477942,0.08910653,-0.2049768,-0.38078272,0.25531286,-0.052223798,0.18022618,-0.054611653,0.3274193,0.5763793,-0.15635633,0.49286222,-0.29581112,-0.05556007,-0.7662319,0.22995831],"result":{"type":"object","properties":{"response":{"description":"The search results and analysis from Perplexity","type":"string"}},"required":["response"]},"sql_tables":null,"sql_queries":null,"file_inbox":null,"oauth":null,"assets":null},false]} \ No newline at end of file diff --git a/tools/perplexity/index.test.ts b/tools/perplexity/index.test.ts index a10116e..7966c68 100644 --- a/tools/perplexity/index.test.ts +++ b/tools/perplexity/index.test.ts @@ -1,23 +1,20 @@ -import { expect } from 'jsr:@std/expect/expect'; -import { definition, run } from './index.ts'; +// import { expect } from 'jsr:@std/expect/expect'; +// import { run } from './tool.ts'; -Deno.test('exists definition', () => { - expect(definition).toBeInstanceOf(Object); -}); -Deno.test({ - name: 'run', - // Perplexity web scrapping is not working in CI (need to figure out why) - ignore: Deno.env.get('CI') === 'true', - fn: async () => { - const run_result = await run( - { - chromePath: Deno.env.get('CHROME_PATH'), - }, - { - query: 'What is the meaning of life?', - }, - ); - expect(run_result.response).toEqual(expect.any(String)); - }, -}); +// Deno.test({ +// name: 'run', +// // Perplexity web scrapping is not working in CI (need to figure out why) +// ignore: Deno.env.get('CI') === 'true', +// fn: async () => { +// const run_result = await run( +// { +// chromePath: Deno.env.get('CHROME_PATH'), +// }, +// { +// query: 'What is the meaning of life?', +// }, +// ); +// expect(run_result.response).toEqual(expect.any(String)); +// }, +// }); diff --git a/tools/perplexity/metadata.json b/tools/perplexity/metadata.json index a524f76..cc49133 100644 --- a/tools/perplexity/metadata.json +++ b/tools/perplexity/metadata.json @@ -3,6 +3,7 @@ "name": "Perplexity", "description": "Searches the internet using Perplexity", "author": "Shinkai", + "version": "1.0.0", "keywords": [ "perplexity", "shinkai" diff --git a/tools/smart-search/.tool-dump.test.json b/tools/smart-search/.tool-dump.test.json new file mode 100644 index 0000000..4492895 --- /dev/null +++ b/tools/smart-search/.tool-dump.test.json @@ -0,0 +1 @@ +{"type":"Deno","content":[{"toolkit_name":"smart-search-shinkai","name":"Smart Search Engine","author":"Shinkai","version":"1.0.0","js_code":"import { googleSearch, shinkaiLlmPromptProcessor, shinkaiDownloadPages } from './shinkai-local-tools.ts';\n\ntype CONFIG = {\n searchEngineApiKey?: string;\n searchEngine?: SearchEngine;\n maxSources?: number;\n}\ntype INPUTS = {\n question: string;\n};\ntype OUTPUT = {\n response: string;\n sources: SmartSearchSourcePage[];\n statements: SmartSearchStatement[];\n}\ntype PREFFERED_SOURCES = 'WIKIPEDIA'|'WOLFRAMALPHA'|'OTHER';\n\ntype SearchQueryConversion = {\n \"origin_question\": string;\n \"preferred_sources\": PREFFERED_SOURCES[];\n \"search_query\": string\n}\n\ntype SearchResult = {\n title: string;\n description: string;\n url: string;\n}\n\ntype SmartSearchSource = SearchResult | string;\ntype SearchEngine = 'DUCKDUCKGO' | 'GOOGLE' | 'BRAVE';\n\nexport interface SmartSearchSourcePage {\n id: number;\n url: string;\n markdown?: string;\n title: string;\n}\n\nexport interface SmartSearchStatement {\n sourceId: number;\n sourceTitle: string;\n extractedFacts: {\n statement: string;\n relevance: 'DIRECT_ANSWER' | 'HIGHLY_RELEVANT' | 'SOMEWHAT_RELEVANT' | 'TANGENTIAL' | 'NOT_RELEVANT';\n }[];\n}\nexport interface SmartSearchGenerationContext {\n originalQuestion: string;\n statements: SmartSearchStatement[];\n sources: SmartSearchSourcePage[];\n}\n\nconst answerGenerator = (context: SmartSearchGenerationContext): string => `\n# Smart Search Answer Generation Instructions\nYou are a sophisticated scientific communication assistant specialized in transforming extracted research statements into comprehensive, accessible, and precisely cited explanations.Your primary objective is to synthesize complex information from multiple sources into a clear, authoritative answer that maintains absolute fidelity to the source material. Think of yourself as an academic translator - your role is to take fragmented scientific statements and weave them into a coherent narrative that is both intellectually rigorous and engaging, ensuring that every substantive claim is meticulously attributed to its original source. Approach each question as an opportunity to provide a deep, nuanced understanding that goes beyond surface-level explanation, while maintaining strict scholarly integrity.\n## Input JSON Interfaces and Definitions\n\n\\`\\`\\`typescript\n// Source Page Interface\nexport interface SmartSearchSourcePage {\n id: number; // Unique identifier for the source\n url: string; // Full URL of the source\n markdown: string; // Full text content of the source page\n title: string; // Title of the source page\n}\n\n// Statement Interface with Detailed Relevance Levels\nexport interface SmartSearchStatement {\n sourceId: number; // ID of the source this statement comes from\n sourceTitle: string; // Title of the source\n extractedFacts: {\n statement: string; // Exact verbatim text from the source\n relevance: 'DIRECT_ANSWER' \n | 'HIGHLY_RELEVANT' \n | 'SOMEWHAT_RELEVANT' \n | 'TANGENTIAL' \n | 'NOT_RELEVANT'; // Relevance classification\n }[];\n}\n\n// Complete Input JSON Structure\ninterface AnswerGenerationContext {\n originalQuestion: string;\n statements: SmartSearchStatement[];\n sources: SmartSearchSourcePage[];\n}\n\\`\\`\\`\n\n## Relevance Level Interpretation\n- \\`DIRECT_ANSWER\\`: Prioritize these statements first\n- \\`HIGHLY_RELEVANT\\`: Strong secondary focus\n- \\`SOMEWHAT_RELEVANT\\`: Use for additional context\n- \\`TANGENTIAL\\`: Optional supplementary information\n- \\`NOT_RELEVANT\\`: Ignore completely\n\n## Answer Generation Guidelines\n\n### Content Construction Rules:\n1. Use ONLY information from the provided statements\n2. Prioritize statements with 'DIRECT_ANSWER' and 'HIGHLY_RELEVANT' relevance\n3. Create a comprehensive, informative answer\n4. Maintain scientific accuracy and depth\n\n### Citation Methodology:\n- Place citations IMMEDIATELY after relevant statements\n- Use SQUARE BRACKETS with NUMERIC source IDs\n- Format: \\`Statement of fact.[1][2]\\`\n- Cite EVERY substantive statement\n- Match citations exactly to source IDs\n\n### Structural Requirements:\n1. Detailed Main Answer\n - Comprehensive explanation\n - Technical depth\n - Precise scientific language\n - Full source citations\n\n2. Follow-Up Questions Section\n - Generate 3-4 thought-provoking questions\n - Encourage deeper exploration\n - Based on answer content\n - Formatted as a bulleted list\n\n3. Sources Section\n - List all cited sources\n - Include source titles and URLs\n - Order based on first citation appearance\n\n## Output Example Structure:\n\\`\\`\\`\n[Comprehensive, cited answer with source IDs in brackets]\n\nFollow-up Questions:\n- Question about deeper aspect of the topic\n- Question exploring related concepts\n- Question encouraging further research\n\nSources:\n[1] Source Title (URL)\n[2] Another Source Title (URL)\n...\n\\`\\`\\`\n\n## Critical Constraints:\n- NEVER introduce information not in the statements\n- Preserve exact factual content\n- Ensure grammatical and logical coherence\n- Provide a complete, informative answer\n- Maintain academic rigor\n\n## Processing Instructions:\n- Analyze statements systematically\n- Synthesize information coherently\n- Break down complex concepts\n- Provide scientific context\n- Explain underlying mechanisms\n\n\nThis is the input context:\n${JSON.stringify(context)}\n\n`;\n\nconst searchEngineQueryGenerator = (query: string) => {\n return `\n# Search Query and Source Selection Prompt\n\nYou are an expert at transforming natural language questions into precise search queries and selecting the most appropriate information source.\n\n## Source Selection Guidelines:\n- WIKIPEDIA: Best for general knowledge, scientific explanations, historical information\n- WOLFRAMALPHA: Ideal for mathematical, statistical, computational queries, scientific calculations\n- OTHER: General web search for current events, recent developments, practical information\n\n## Output Requirements:\n- Provide a JSON response with three key fields\n- Do NOT use code block backticks\n- Ensure \"preferred_sources\" is an array\n- Make search query concise and targeted\n\n## Examples:\n\n### Example 1\n- User Query: \"What is the speed of light?\"\n- Output:\n{\n\"origin_question\": \"What is the speed of light?\",\n\"preferred_sources\": [\"WOLFRAMALPHA\"],\n\"search_query\": \"speed of light exact value meters per second\"\n}\n\n### Example 2\n- User Query: \"Who was Marie Curie?\"\n- Output:\n{\n\"origin_question\": \"Who was Marie Curie?\",\n\"preferred_sources\": [\"WIKIPEDIA\"],\n\"search_query\": \"Marie Curie biography scientific achievements\"\n}\n\n### Example 3\n- User Query: \"Best restaurants in New York City\"\n- Output:\n{\n\"origin_question\": \"Best restaurants in New York City\",\n\"preferred_sources\": [\"OTHER\"],\n\"search_query\": \"top rated restaurants NYC 2024 dining\"\n}\n\n### Example 4\n- User Query: \"How do solar panels work?\"\n- Output:\n{\n\"origin_question\": \"How do solar panels work?\",\n\"preferred_sources\": [\"WIKIPEDIA\", \"OTHER\"],\n\"search_query\": \"solar panel photovoltaic technology mechanism\"\n}\n\n## Instructions:\n- Carefully analyze the user's query\n- Select the MOST APPROPRIATE source(s)\n- Create a targeted search query\n- Return ONLY the JSON without additional text\n\nUser Query: ${query}\n`\n\n}\n\nconst statementExtract = (originalQuestion: string, source: SmartSearchSourcePage): string => `\n\n# Fact Extraction Instructions\n\n## Input JSON Structure\n\\`\\`\\`json\n{\n \"originalQuestion\": \"string - The user's original question\",\n \"source\": {\n \"id\": \"number - Unique identifier for the source\",\n \"url\": \"string - URL of the source page\",\n \"title\": \"string - Title of the source page\",\n \"markdown\": \"string - Full text content of the source page\"\n }\n}\n\\`\\`\\`\n\n## Output JSON Structure\n\\`\\`\\`json\n{\n \"sourceId\": \"number - ID of the source\",\n \"sourceTitle\": \"string - Title of the source\",\n \"extractedFacts\": [\n {\n \"statement\": \"string - Verbatim text from the source\",\n \"relevance\": \"string - One of ['DIRECT_ANSWER', 'HIGHLY_RELEVANT', 'SOMEWHAT_RELEVANT', 'TANGENTIAL', 'NOT_RELEVANT']\"\n }\n ]\n}\n\\`\\`\\`\n\n## Relevance Classification Guide:\n- \\`DIRECT_ANSWER\\`: \n - Completely and precisely addresses the original question\n - Contains the core information needed to fully respond\n - Minimal to no additional context required\n\n- \\`HIGHLY_RELEVANT\\`: \n - Provides substantial information directly related to the question\n - Offers critical context or partial solution\n - Significantly contributes to understanding\n\n- \\`SOMEWHAT_RELEVANT\\`: \n - Provides partial or indirect information\n - Offers peripheral insights\n - Requires additional context to be fully meaningful\n\n- \\`TANGENTIAL\\`: \n - Loosely connected to the topic\n - Provides background or related information\n - Not directly addressing the core question\n\n- \\`NOT_RELEVANT\\`: \n - No meaningful connection to the original question\n - Completely unrelated information\n\n\n ## Extraction Guidelines:\n 1. Read the entire source document carefully\n 2. Extract EXACT quotes that:\n - Are actually helpful answering the provided question\n - Are stated verbatim from the source or are rephrased in such a way that doesn't distort the meaning in the original source\n - Represent complete thoughts or meaningful segments\n 3. Classify each extracted fact with its relevance level\n 4. Preserve original context and nuance\n\n## Critical Rules:\n- try NOT to paraphrase or modify the original text\n- Avoid any text in the \"statement\" field that is not helpful answering the provided question like javascript, URLs, HTML, and other non-textual content\n- Extract statements as they appear in the source and ONLY if they are helpful answering the provided question\n- Include full sentences or meaningful text segments\n- Preserve original formatting and punctuation\n- Sort extracted facts by relevance (DIRECT_ANSWER first)\n- Output JSON without \\`\\`\\`json\\`\\`\\` tags, or without any escape characters or any text that is not JSON or my system will crash.\n\n## Processing Instructions:\n- Analyze the entire document systematically\n- Be comprehensive in fact extraction\n- Err on the side of inclusion when in doubt\n- Focus on factual, informative statements\n\n==BEGIN INPUT==\nOriginal Question: ${originalQuestion}\n\nSource:\n${JSON.stringify(source)}\n==END INPUT==\n\n`\nconst debug = []\nfunction tryToExtractJSON(text: string): string {\n const regex = /```(?:json)?\\n([\\s\\S]+?)\\n```/;\n const match = text.match(regex);\n if (match) return match[1];\n else return text;\n}\n\nconst ProcessQuestionError = (step: string, error: Error): string =>\n `Failed to process question at ${step}: ${error.message}`;\n\nasync function conversionToSearchQuery(question: string): Promise {\n const prompt = searchEngineQueryGenerator(question);\n const optimizedQueryResult = await shinkaiLlmPromptProcessor({ format: 'text' , prompt });\n try {\n const result = JSON.parse(optimizedQueryResult.message.trim()) as SearchQueryConversion;\n return result;\n } catch (error) {\n throw new Error(ProcessQuestionError('question processing in optimizequery', new Error(String(error))));\n }\n}\n\n\nasync function extractSourcesFromSearchEngine(\n searchQuery: string,\n engine: SearchEngine,\n apiKey?: string,\n): Promise {\n switch (engine) {\n\t\tcase 'GOOGLE' : {\n\t\t\tconst results = await googleSearch({ query: searchQuery });\n\t\t\treturn results.results;\n\t\t}\n case 'DUCKDUCKGO':\n throw new Error('DuckDuckGo is not supported yet');\n case 'BRAVE': \n throw new Error('Brave is not supported yet');\n default:\n throw new Error('Invalid or unsupperted search engine');\n }\n}\n\nexport async function run(\n config: CONFIG,\n inputs: INPUTS\n): Promise {\n const { question } = inputs;\n if (!question) {\n throw new Error('Question is required in inputs');\n }\n\n try {\n // Step 1: Generate optimized search query\n const searchQuery = await conversionToSearchQuery(question);\n // Step 2: Perform search with optimized query\n const sources: SmartSearchSource[] = []\n for (const preferred_source of searchQuery.preferred_sources) {\n switch (preferred_source) {\n case 'WIKIPEDIA':{\n const searchEngineQuery = searchQuery.search_query+' site:wikipedia.org';\n const searchEngine = config.searchEngine || 'GOOGLE';\n const sourcesSearchResults: SearchResult[] = await extractSourcesFromSearchEngine(searchEngineQuery, searchEngine, config.searchEngineApiKey);\n try {\n const maxSources = config.maxSources ?? 3;\n sources.push(...(sourcesSearchResults.slice(0, Number(maxSources)) as SearchResult[]));\n } catch (error) {\n console.error('Failed to process search results', error);\n throw new Error('Failed to process search results');\n }\n break;\n }\n case 'WOLFRAMALPHA':\n throw new Error('WOLFRAMALPHA is not supported yet');\n case 'OTHER':\n break;\n default:\n throw new Error('Invalid source');\n }\n }\n const smartSearchSouces: SmartSearchSourcePage[] = []\n let id = 1;\n for (const source of sources) {\n if (typeof source === 'string') throw new Error('Invalid source');\n const searchResult = await shinkaiDownloadPages({ urls: [source.url] });\n smartSearchSouces.push({\n id: id++, url: source.url, title: source.title,\n markdown: searchResult.markdowns.join('\\n'),\n });\n }\n const statements: SmartSearchStatement[] = []\n // Step 3: Extract statements from sources\n for (const smartSearchSource of smartSearchSouces) {\n const statementString = await shinkaiLlmPromptProcessor({ format: 'text', prompt: statementExtract(question, smartSearchSource) });\n const cleanStatementString = tryToExtractJSON(statementString.message)\n try { \n const statement = JSON.parse(cleanStatementString) as SmartSearchStatement;\n statements.push(statement);\n } catch (error) {\n console.error('Failed to process statement', smartSearchSource.url, error);\n console.error(cleanStatementString)\n }\n }\n // clean markdown from sources for lighter input\n smartSearchSouces.forEach(source => delete source.markdown);\n const generationContext: SmartSearchGenerationContext = {\n originalQuestion: question,\n statements,\n sources: smartSearchSouces,\n }\n // Step 4: Generate answer\n const answerPrompt = answerGenerator(generationContext);\n\t\tconst response = await shinkaiLlmPromptProcessor({ format: 'text', prompt: answerPrompt });\n return {\n statements,\n sources: smartSearchSouces,\n response: response.message,\n };\n } catch (error) {\n throw new Error(ProcessQuestionError('question processing in answer generation', new Error(String(error))));\n }\n}\n","tools":["local:::google_search_shinkai:::google_search:::1.0.0","local:::rust_toolkit:::shinkai_llm_prompt_processor:::1.0.0","local:::shinkai_tool_download_pages:::shinkai__download_pages:::1.0.0"],"config":[{"BasicConfig":{"key_name":"searchEngine","description":"The search engine to use","required":false,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"searchEngineApiKey","description":"The API key for the search engine","required":false,"type":null,"key_value":null}},{"BasicConfig":{"key_name":"maxSources","description":"The maximum number of sources to return","required":false,"type":null,"key_value":null}}],"description":"This function takes a question as input and returns a comprehensive answer, along with the sources and statements used to generate the answer.","keywords":["search","answer generation","fact extraction","wikipedia","google"],"input_args":{"type":"object","properties":{"question":{"type":"string","description":"The question to answer"}},"required":["question"]},"output_arg":{"json":""},"activated":false,"embedding":[0.44519925,0.011538006,-0.110713586,-0.22075558,-0.14790598,-0.29269773,-0.4754676,0.44221854,-0.121888064,0.39252597,-0.3006528,1.0143435,0.36214498,-0.31270468,0.6776067,0.25015622,0.35587713,-0.23176439,-1.9852347,0.016676497,0.5186351,0.13615943,0.34565818,0.11482762,-0.014134172,0.29590514,0.31907755,-0.3896206,-1.2329955,-1.6192199,0.85829604,0.62480825,-0.6851429,-0.4065035,-0.57009935,-0.44622755,-0.018254763,-0.29652905,0.06502104,0.08794068,0.123337545,-0.2962008,-0.7889936,-0.2309857,-0.30533978,0.00014958903,-0.100521065,-0.17255962,0.65703535,0.59996736,-0.34312758,-0.3323959,-0.2751081,0.054695282,-0.6813821,-0.16973025,-0.34893867,-0.60133564,-0.1950637,-0.30053732,0.61119884,0.13490543,-4.0774403,-0.1405774,0.52335876,0.2547453,0.10967965,-0.37900138,0.33353627,-0.0860852,0.06344949,0.27401373,0.35607475,0.3472401,0.20127875,-0.2749816,-0.1676489,-0.3010119,0.40944278,-0.60488445,-0.33455145,0.036982603,0.1607093,0.18134978,-0.50376195,0.4321913,0.21538696,-0.3986729,0.1924279,-0.07740533,-0.5905008,-0.32293463,-0.33489698,0.08675105,-0.38169703,0.20435761,0.1692553,0.48983234,0.4500325,3.2424073,0.30719528,-0.3322998,0.36166048,-1.097402,0.9221763,-0.3271866,0.15179256,-0.7435132,0.7849906,-0.076523826,0.4214928,-0.20277414,-0.008337051,0.84142566,-0.14813311,0.10049243,-0.48139656,0.091330424,0.08260442,0.73960954,-0.13112147,0.17086662,-0.43677095,-0.3310505,-0.25675213,0.6580711,-0.3097783,0.3686354,0.40853876,0.52439237,0.45975456,-0.5577316,-1.1559865,-0.028603502,0.3412104,0.350788,0.30436534,-0.84187645,0.6342305,-0.7242338,0.30563703,-1.3071945,0.56033385,-0.11213897,0.7491704,-0.037651196,-0.66392916,-0.22443774,-0.40022716,-0.4695392,0.12346482,0.42506516,-0.008828731,-0.036567945,0.7910692,0.4870108,-0.10458979,-0.0010068789,-0.19713187,0.18817124,-0.34421226,0.43161416,0.35337302,0.45155972,0.31935665,-0.38856277,0.14921239,0.46791223,-0.19556057,-0.1643018,0.4380207,-0.46539715,-0.2832293,0.81312156,-0.052545656,-0.29040393,0.1400195,-0.12654832,0.41849804,-0.882607,-0.13826783,0.77245986,-0.5711882,-0.27059942,-0.19140518,0.4529812,0.0826526,-0.367387,0.64419246,1.1117058,-0.47169876,1.4447793,-0.2390542,-0.19558607,0.1427455,-0.21482131,0.104871795,0.2707702,0.38783553,0.1292122,-1.0809127,-0.0846922,-0.039507207,-0.3097255,-0.29537687,-0.65163094,0.19342569,-0.32778674,-0.08130689,-0.64830554,0.12468888,-0.5193145,1.1083255,-0.010225475,0.6004076,-0.14024194,0.058595452,0.4302386,-0.47035223,0.8164973,0.21753985,-0.013964482,-0.6944066,-0.62527126,-0.82455045,-0.112839624,0.14301777,0.12782156,-0.2723977,0.008159652,0.5853714,0.9211197,0.4646956,1.390659,0.76697886,0.523064,-0.12873787,0.25171667,0.17022641,-0.30911857,0.31879586,-0.1103535,-0.33922687,-0.32489824,0.3671196,-0.54260576,-0.010865424,-0.16758339,0.06505124,1.4560661,0.7549216,0.18457569,-0.04554111,0.9045233,-0.14435571,0.16820474,-1.6039296,0.078886904,-0.30494863,0.45922333,-0.011344843,-0.3130207,0.39990506,0.3539346,-0.6010364,-0.8332309,-0.37220326,-0.80922806,-0.17530465,-0.06533443,-0.109381296,0.35899848,-0.47536635,-0.042883083,0.5028103,0.15244354,0.3528542,0.5739549,-0.58191675,-0.13802925,0.4039406,0.15418546,0.10369478,0.24870338,-0.14724898,-0.1899396,-0.4523422,-0.067849,-0.45093012,0.7759565,-0.47772875,-0.5009712,-0.63364625,0.32183337,1.6104475,0.31228143,-0.2737522,0.8513892,-0.10785564,-0.083213486,0.3272493,0.34409443,-0.102422476,0.14750528,-0.21719596,-0.7646839,0.7050644,-0.43036377,-0.34817296,-0.07673599,-0.8938274,-0.259611,0.085467875,-0.35622948,0.17879769,-0.4371638,0.84722894,0.42178243,0.47265047,-2.0367239,-0.28862223,0.2279939,0.023028731,0.03350927,-0.84622985,0.6191283,-0.36584458,0.52736944,-0.8522264,1.7012173,0.623458,-0.34564644,-0.29220566,0.22257191,1.008989,-0.5586227,-0.100436315,-0.20206258,-0.14138165,0.29932487,0.3574607,1.777014,0.44976053,0.1803996,0.17181638,0.11031827,-0.18544856,-1.3960699,0.18656585,0.43533033,-0.32739973,0.56046206,-0.08367232,-0.45680672,0.45554873,1.0323718,0.2787497,0.19714256,-0.0057662483,2.0173283,0.14193904,-0.33267602,-0.4824432,-0.44496542,-0.44327742,0.33923206,0.24754228,-0.22856423,0.23647808,-0.4234256,-0.11778459,-0.19414693,0.28126818,-0.0637252,0.28323674,0.4969948,-0.15884419,0.684458,0.3888534,-0.17290172,0.74648315,0.03662668,-1.0852582,-0.24843164],"result":{"type":"object","properties":{"response":{"description":"The generated answer","type":"string"},"sources":{"description":"The sources used to generate the answer","items":{"properties":{"id":{"type":"number"},"title":{"type":"string"},"url":{"type":"string"}},"type":"object"},"type":"array"},"statements":{"description":"The statements extracted from the sources","items":{"properties":{"extractedFacts":{"items":{"properties":{"relevance":{"type":"string"},"statement":{"type":"string"}},"type":"object"},"type":"array"},"sourceId":{"type":"number"},"sourceTitle":{"type":"string"}},"type":"object"},"type":"array"}},"required":["response","sources","statements"]},"sql_tables":[],"sql_queries":[],"file_inbox":null,"oauth":null,"assets":null},false]} \ No newline at end of file diff --git a/tools/smart-search/metadata.json b/tools/smart-search/metadata.json index b1c1ff8..b3381c3 100644 --- a/tools/smart-search/metadata.json +++ b/tools/smart-search/metadata.json @@ -3,6 +3,7 @@ "name": "Smart Search Engine", "description": "This function takes a question as input and returns a comprehensive answer, along with the sources and statements used to generate the answer.", "author": "Shinkai", + "version": "1.0.0", "keywords": [ "search", "answer generation", diff --git a/tools/youtube-summary/.tool-dump.test.json b/tools/youtube-summary/.tool-dump.test.json new file mode 100644 index 0000000..a68de51 --- /dev/null +++ b/tools/youtube-summary/.tool-dump.test.json @@ -0,0 +1 @@ +{"type":"Deno","content":[{"toolkit_name":"youtube-summary","name":"Youtube Transcript Summarizer","author":"@@eduardosotomontaner.arb-sep-shinkai","version":"1.0.0","js_code":"import { YoutubeTranscript } from 'npm:youtube-transcript@1.2.1';\nimport { shinkaiLlmPromptProcessor } from './shinkai-local-tools.ts'\n\n// Tool does not need any configuration\ntype CONFIG = Record;\n\ntype INPUTS = {\n url: string;\n lang?: string;\n};\n\ntype OUTPUT = { summary: string };\n\nexport const run: Run = async (\n _configurations,\n parameters,\n): Promise => {\n console.log(`transcripting ${parameters.url}`);\n\n // Get transcription\n const transcript = await YoutubeTranscript.fetchTranscript(parameters.url, {\n lang: parameters.lang || 'en',\n });\n\n // Send to LLM to build a formatted response\n const message = `\n According to this transcription of a youtube video (which is in csv separated by ':::'):\n\n offset;text\n ${transcript.map((v) => `${Math.floor(v.offset)}:::${v.text}`).join('\\n')}\n ---------------\n\n The video URL is ${parameters.url}\n\n ---------------\n\n Write a detailed summary divided in sections along the video.\n Format the answer using markdown.\n Add markdown links referencing every section using this format https://www.youtube.com/watch?v={video_id}&t={offset} where 'offset' is a number and can be obtained from the transcription in csv format to generate the URL\n `;\n const response = await shinkaiLlmPromptProcessor({ format: 'text', prompt: message })\n return { summary: response.message }\n};\n","tools":["local:::rust_toolkit:::shinkai_llm_prompt_processor"],"config":[],"description":"Fetches the transcript of a YouTube video and generates a formatted summary using an LLM.","keywords":["youtube","transcript","summary","video","LLM"],"input_args":{"type":"object","properties":{"lang":{"type":"string","description":"The language for the transcript (optional)"},"url":{"type":"string","description":"The URL of the YouTube video"}},"required":["url"]},"output_arg":{"json":""},"activated":false,"embedding":[0.24397473,0.19737607,0.10249484,0.07853881,-0.52260065,-0.07264366,-1.4292128,0.5816098,-0.0569295,0.467394,-0.2629992,1.546936,0.030428365,0.18555912,0.5241776,0.40233222,-0.10415818,-0.7092806,-1.297857,-0.664604,0.52484876,0.5144266,-0.0060532093,-0.0029968247,0.13401021,-0.13712981,0.09876527,-0.22174498,-1.0573201,-1.9738672,0.70428807,0.54259884,-0.16001034,-0.37234327,-0.43517393,-1.3643596,0.25747937,0.46092734,-0.292954,0.4579779,-0.09054327,0.13232066,-0.7888382,0.40833142,-0.043910377,-0.19611594,0.36788312,-0.09296358,1.4296865,0.44269896,-0.40729654,-0.19846602,-0.10134886,0.49915153,-0.17917651,-0.61800796,-0.39331928,-0.5531162,0.93573284,0.3125194,-0.032507822,-0.024462327,-3.7117436,-0.23966308,-0.082733504,-0.00083688647,-0.2638889,-0.079310715,-0.04274538,0.38685042,-1.0061314,-0.09795482,-0.595692,0.8140711,-0.52223,-0.5010422,0.48327318,-0.30269998,0.26365638,-0.53166157,0.06926101,0.061586447,0.22167054,-0.38880783,-0.53398055,0.90134996,-0.47085276,-0.24938089,-0.13700266,0.26321328,-0.9187829,-0.030944848,0.6005912,0.34225106,-0.54002047,-0.3963846,0.6813786,-0.4724697,0.072636716,2.6400874,1.0521492,0.014715459,0.1956683,-1.1673645,0.4569034,-0.70678335,0.47124594,-0.42230985,0.31645888,0.0359073,0.78643477,-0.17552736,0.15710464,0.549718,0.51373,0.37795103,-0.81747603,0.024700543,0.03176478,0.36899906,-0.272966,-0.12973304,-0.39982963,-0.18365073,-0.46064875,0.14623581,-0.1908139,0.15239067,0.5717435,-0.7718099,-0.041600056,-0.055492602,-0.6733642,0.6702037,0.025288485,0.30686027,0.40308362,-0.8706652,0.31286785,-0.81772375,-0.18790466,-2.0614433,0.6394961,-0.018431015,0.34960693,-0.007028464,-0.61032754,0.37297478,-0.29247496,-0.465864,0.36508018,0.6427132,0.22788927,-0.08449084,0.88174784,-0.13330701,-0.72458035,-0.55865467,-0.20877361,0.050680257,-0.38116446,-0.07186862,0.624656,-0.3708253,0.2717578,-0.5983692,0.77082396,0.16514742,0.39356315,0.32194296,0.28758615,0.11886267,0.01459287,0.7468215,-0.025611265,-0.89384717,-0.4739496,-0.301784,-0.0015290305,0.29546043,0.48127237,0.2063696,-0.409744,-0.04899437,-0.23912765,0.6469834,0.09129079,0.24771339,0.96164113,0.7420727,-0.33983496,1.6778651,-1.1015447,-0.17468059,-0.111047395,0.09020809,-0.3394488,0.3813395,0.30324456,0.06054409,-0.9422036,-0.21234436,0.25479048,0.0029522553,-0.33134744,-0.64197415,-0.31880897,0.73515236,-0.370654,-0.61103266,0.49827653,-0.9070959,0.5150069,0.54918575,-0.0791596,-0.26136273,-0.038667,0.20681158,-0.7998123,0.15697767,0.31832293,-0.30024567,-0.13398749,-0.5464064,0.078004286,0.5013751,-0.5964775,0.7934169,0.18798716,-0.102526814,0.7516279,1.3288732,0.38466543,1.1970915,0.70729077,0.16436699,-0.4109063,0.31046456,-0.09760972,-0.2675225,0.18276238,0.25188726,0.069069535,0.28543174,0.2071175,-0.08041818,-0.6181666,0.043410942,-0.29807296,1.7043421,0.43463537,0.4075363,0.59444076,0.82585335,0.6737303,-0.36265337,-1.4637611,-0.29978368,-0.20907988,0.33043876,-0.750395,0.6137083,0.19155118,0.2934378,-0.5209952,-0.36604527,-0.69852865,-0.4371357,0.028415933,0.18738863,-0.30432528,0.49997562,-0.11741397,0.042816848,-0.4490757,0.4281727,0.18414852,0.42120722,-0.44500935,-0.9356021,0.004114732,-0.098933734,0.20038745,0.31341612,-0.7175617,-0.13790105,-0.078082725,-0.30331305,0.016176544,0.5784527,0.09730462,-0.46089923,-0.9954212,0.2812389,1.5212535,0.25866175,0.15545672,0.5862159,0.3469371,0.09966384,-0.93005514,0.027373465,-0.14089948,-0.49164492,-0.18993902,-0.6721664,0.91621786,-0.31503543,-0.43121752,0.4722464,-0.42334154,0.41654542,0.2577617,-0.2962021,0.46720228,-0.3402864,0.3280484,0.9959594,-0.17491736,-1.8942695,-0.035868153,-0.29466665,-0.25931674,-0.27141005,0.24185471,1.0774001,-0.64388967,0.6423959,0.24093969,1.5087445,0.11422682,-0.10210596,-0.35378647,0.08158391,0.7351494,-0.47266462,-0.18411069,-0.30488995,-0.7604541,-0.2951124,0.32563996,1.0398327,0.033854738,1.0128971,0.04701845,-0.2543579,-0.3876006,-1.0073549,0.6400236,-0.24982655,-0.3674008,0.75311905,-0.40171337,-0.31875148,0.7237389,0.8828592,0.5095583,-0.050843228,0.3896459,1.7165403,0.49974895,-0.35941413,0.277945,0.12831461,0.41759193,0.11227698,0.021763999,-0.5772322,0.04317443,-0.34799072,0.57283884,-0.45722812,0.7255814,0.7775589,0.109948486,0.2851043,0.6291014,0.62423563,0.36268318,-0.022946805,-0.10817164,-0.037535723,-0.21269107,-0.74232906],"result":{"type":"object","properties":{"summary":{"description":"The generated summary of the video","type":"string"}},"required":["summary"]},"sql_tables":[],"sql_queries":[],"file_inbox":null,"oauth":null,"assets":null},false]} \ No newline at end of file diff --git a/tools/youtube-summary/index.test.ts b/tools/youtube-summary/index.test.ts index f6340a4..cd47b62 100644 --- a/tools/youtube-summary/index.test.ts +++ b/tools/youtube-summary/index.test.ts @@ -1,20 +1,20 @@ -import { expect } from 'jsr:@std/expect/expect'; -import { run } from './tool.ts'; +// import { expect } from 'jsr:@std/expect/expect'; +// import { run } from './tool.ts'; -Deno.test({ - name: 'transcript video', - ignore: Deno.env.get('CI') === 'true', - fn: async () => { - const result = await run( - { - // No configuration needed - }, - { - url: 'https://www.youtube.com/watch?v=SUj34OWkjXU', - lang: 'en', - }, - ); - expect(result.summary.length).toBeGreaterThan(0); - console.log(result.summary); - }, -}); +// Deno.test({ +// name: 'transcript video', +// ignore: Deno.env.get('CI') === 'true', +// fn: async () => { +// const result = await run( +// { +// // No configuration needed +// }, +// { +// url: 'https://www.youtube.com/watch?v=SUj34OWkjXU', +// lang: 'en', +// }, +// ); +// expect(result.summary.length).toBeGreaterThan(0); +// console.log(result.summary); +// }, +// }); From d90669f4bfe9b260ad4748d0a6bf6fa80f406302 Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 15 Jan 2025 09:52:12 -0300 Subject: [PATCH 2/6] revert file --- tools/youtube-summary/index.test.ts | 38 ++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/tools/youtube-summary/index.test.ts b/tools/youtube-summary/index.test.ts index cd47b62..f6340a4 100644 --- a/tools/youtube-summary/index.test.ts +++ b/tools/youtube-summary/index.test.ts @@ -1,20 +1,20 @@ -// import { expect } from 'jsr:@std/expect/expect'; -// import { run } from './tool.ts'; +import { expect } from 'jsr:@std/expect/expect'; +import { run } from './tool.ts'; -// Deno.test({ -// name: 'transcript video', -// ignore: Deno.env.get('CI') === 'true', -// fn: async () => { -// const result = await run( -// { -// // No configuration needed -// }, -// { -// url: 'https://www.youtube.com/watch?v=SUj34OWkjXU', -// lang: 'en', -// }, -// ); -// expect(result.summary.length).toBeGreaterThan(0); -// console.log(result.summary); -// }, -// }); +Deno.test({ + name: 'transcript video', + ignore: Deno.env.get('CI') === 'true', + fn: async () => { + const result = await run( + { + // No configuration needed + }, + { + url: 'https://www.youtube.com/watch?v=SUj34OWkjXU', + lang: 'en', + }, + ); + expect(result.summary.length).toBeGreaterThan(0); + console.log(result.summary); + }, +}); From 1c2b6f1538b989b984dae9894f465252a3b12c66 Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 15 Jan 2025 09:52:32 -0300 Subject: [PATCH 3/6] revert file --- tools/perplexity/index.test.ts | 36 +++++++++++++++++----------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tools/perplexity/index.test.ts b/tools/perplexity/index.test.ts index 7966c68..87c788e 100644 --- a/tools/perplexity/index.test.ts +++ b/tools/perplexity/index.test.ts @@ -1,20 +1,20 @@ -// import { expect } from 'jsr:@std/expect/expect'; -// import { run } from './tool.ts'; +import { expect } from 'jsr:@std/expect/expect'; +import { run } from './tool.ts'; -// Deno.test({ -// name: 'run', -// // Perplexity web scrapping is not working in CI (need to figure out why) -// ignore: Deno.env.get('CI') === 'true', -// fn: async () => { -// const run_result = await run( -// { -// chromePath: Deno.env.get('CHROME_PATH'), -// }, -// { -// query: 'What is the meaning of life?', -// }, -// ); -// expect(run_result.response).toEqual(expect.any(String)); -// }, -// }); +Deno.test({ + name: 'run', + // Perplexity web scrapping is not working in CI (need to figure out why) + ignore: Deno.env.get('CI') === 'true', + fn: async () => { + const run_result = await run( + { + chromePath: Deno.env.get('CHROME_PATH'), + }, + { + query: 'What is the meaning of life?', + }, + ); + expect(run_result.response).toEqual(expect.any(String)); + }, +}); From b895f96a719c449e1730bcda43ce9b24e99d1b8a Mon Sep 17 00:00:00 2001 From: Guillermo Valin Date: Wed, 15 Jan 2025 08:50:38 -0500 Subject: [PATCH 4/6] FIX: Update build tool workflow to include tests --- .github/workflows/build_tools.yaml | 56 +++++++++++++++++++++++++++--- scripts/build_tools/interfaces.ts | 4 +-- scripts/build_tools/save_tools.ts | 2 +- scripts/build_tools/upload.ts | 7 ++-- scripts/run_node.sh | 3 +- 5 files changed, 61 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build_tools.yaml b/.github/workflows/build_tools.yaml index 5334717..50e4e0a 100644 --- a/.github/workflows/build_tools.yaml +++ b/.github/workflows/build_tools.yaml @@ -7,7 +7,59 @@ on: workflow_dispatch: jobs: + run_tests: + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - uses: actions/checkout@v3 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + + - name: Install b3sum + run: cargo install b3sum + + - name: Setup Deno + uses: denoland/setup-deno@v2 + with: + deno-version: v2.x + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y curl jq zip unzip coreutils + + - name: Run node in background + id: run_node + env: + INITIAL_AGENT_NAMES: ${{ secrets.INITIAL_AGENT_NAMES }} + INITIAL_AGENT_URLS: ${{ secrets.INITIAL_AGENT_URLS }} + INITIAL_AGENT_MODELS: ${{ secrets.INITIAL_AGENT_MODELS }} + INITIAL_AGENT_API_KEYS: ${{ secrets.INITIAL_AGENT_API_KEYS }} + API_V2_KEY: ${{ secrets.API_V2_KEY }} + EMBEDDINGS_SERVER_URL: ${{ secrets.EMBEDDINGS_SERVER_URL }} + SHINKAI_NODE_ADDR: "http://localhost:9550" + BEARER_TOKEN: ${{ secrets.API_V2_KEY }} + INITIALIZATION_DATA: ${{ secrets.INITIALIZATION_DATA }} + DOWNLOAD_PREFIX: "https://download.shinkai.com/tools" + SKIP_IMPORT_FROM_DIRECTORY: true + SHINKAI_STORE_ADDR: "https://shinkai-store-302883622007.us-central1.run.app" + SHINKAI_STORE_TOKEN: ${{ secrets.SHINKAI_STORE_TOKEN }} + run: | + ./scripts/run_node.sh & + timeout 60 bash -c 'until curl -s --location "$SHINKAI_NODE_ADDR/v2/health_check" | jq -e ".status == \"ok\"" > /dev/null; do sleep 1; done' + curl --location "$SHINKAI_NODE_ADDR/v2/initial_registration" \ + --header 'Content-Type: application/json; charset=utf-8' \ + --data "$INITIALIZATION_DATA" + deno test --allow-read --allow-write --allow-env --allow-net --allow-run scripts/ + rm -rf ./shinkai-node/storage build_tools: + needs: run_tests runs-on: ubuntu-latest permissions: contents: write @@ -57,10 +109,6 @@ jobs: --header 'Content-Type: application/json; charset=utf-8' \ --data "$INITIALIZATION_DATA" deno run --allow-read --allow-write --allow-env --allow-net --allow-run scripts/build_tools.ts - if jq -e '.[] | select(.description == "")' packages/directory.json > /dev/null; then - echo "Error: Empty descriptions found in packages/directory.json" - exit 1 - fi - name: Upload to Cloudflare R2 if: steps.run_node.outcome == 'success' diff --git a/scripts/build_tools/interfaces.ts b/scripts/build_tools/interfaces.ts index ccdc627..ea11650 100644 --- a/scripts/build_tools/interfaces.ts +++ b/scripts/build_tools/interfaces.ts @@ -1,7 +1,7 @@ interface ConfigurationBasicType { type: 'string' | 'number' | 'boolean' | 'date' | 'datetime'; description: string; - default?: string; + isDefault?: string; } interface ConfigurationArray { @@ -45,7 +45,7 @@ export interface Metadata { export interface DirectoryEntry { dir: string; - default?: boolean; + isDefault?: boolean; name: string; author: string; keywords: string[]; diff --git a/scripts/build_tools/save_tools.ts b/scripts/build_tools/save_tools.ts index 22e2896..584fe49 100644 --- a/scripts/build_tools/save_tools.ts +++ b/scripts/build_tools/save_tools.ts @@ -290,7 +290,7 @@ export async function saveToolsInNode(toolsOriginal: DirectoryEntry[]): Promise< tool.hash = await calculateBlake3Hash(zipPath); // Check for .default file - tool.default = await exists(join(tool.dir, ".default")); + tool.isDefault = await exists(join(tool.dir, ".default")); toolsSaved.push(tool); } diff --git a/scripts/build_tools/upload.ts b/scripts/build_tools/upload.ts index 180b094..08c4cf1 100644 --- a/scripts/build_tools/upload.ts +++ b/scripts/build_tools/upload.ts @@ -19,13 +19,14 @@ export async function uploadTools(tools: DirectoryEntry[]) { // Upload directory.json to Shinkai Store for (const entry of directory) { + let { dir, toolFile, isDefault, ...store_entry } = entry; let response = await fetch(`${store_addr}/store/products`, { method: "POST", headers: { "Authorization": `Bearer ${store_token}`, "Content-Type": "application/json", }, - body: JSON.stringify(entry), + body: JSON.stringify(store_entry), }); if (response.status === 409) { @@ -38,14 +39,14 @@ export async function uploadTools(tools: DirectoryEntry[]) { "Authorization": `Bearer ${store_token}`, "Content-Type": "application/json", }, - body: JSON.stringify(entry), + body: JSON.stringify(store_entry), }); response = putResponse; } } console.log(`Upload to Store Response (${response.status}): ${await response.text()}`); - if (response.status !== 200) console.log(`Request body failed: ${JSON.stringify(entry, null, 2)}`); + if (response.status !== 200) console.log(`Request body failed: ${JSON.stringify(store_entry, null, 2)}`); } } \ No newline at end of file diff --git a/scripts/run_node.sh b/scripts/run_node.sh index 7fb54b7..6b77ea7 100755 --- a/scripts/run_node.sh +++ b/scripts/run_node.sh @@ -20,7 +20,8 @@ export PROXY_IDENTITY="@@relayer_pub_01.arb-sep-shinkai" export SHINKAI_TOOLS_RUNNER_DENO_BINARY_PATH="./shinkai-tools-runner-resources/deno" export SHINKAI_TOOLS_RUNNER_UV_BINARY_PATH="./shinkai-tools-runner-resources/uv" export SHINKAI_VERSION="0.9.5" -# export SKIP_IMPORT_FROM_DIRECTORY="true" +export SKIP_IMPORT_FROM_DIRECTORY="true" + # Add these lines to enable all log options export LOG_ALL=1 From 4317e92694ddf3a0a65f5193abff4a1848379d39 Mon Sep 17 00:00:00 2001 From: Guillermo Valin Date: Wed, 15 Jan 2025 09:01:42 -0500 Subject: [PATCH 5/6] Creates packages dir if not exists. --- .github/workflows/build_tools.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build_tools.yaml b/.github/workflows/build_tools.yaml index 50e4e0a..2f6c56f 100644 --- a/.github/workflows/build_tools.yaml +++ b/.github/workflows/build_tools.yaml @@ -56,6 +56,7 @@ jobs: curl --location "$SHINKAI_NODE_ADDR/v2/initial_registration" \ --header 'Content-Type: application/json; charset=utf-8' \ --data "$INITIALIZATION_DATA" + mkdir -p ./packages deno test --allow-read --allow-write --allow-env --allow-net --allow-run scripts/ rm -rf ./shinkai-node/storage build_tools: From 1ce0343e905ce15b82150dbc7c961dbd2c7f85c8 Mon Sep 17 00:00:00 2001 From: Guillermo Valin Date: Wed, 15 Jan 2025 09:04:36 -0500 Subject: [PATCH 6/6] Create packages directory to build tools. --- .github/workflows/build_tools.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build_tools.yaml b/.github/workflows/build_tools.yaml index 2f6c56f..1e2c398 100644 --- a/.github/workflows/build_tools.yaml +++ b/.github/workflows/build_tools.yaml @@ -109,6 +109,7 @@ jobs: curl --location "$SHINKAI_NODE_ADDR/v2/initial_registration" \ --header 'Content-Type: application/json; charset=utf-8' \ --data "$INITIALIZATION_DATA" + mkdir -p ./packages deno run --allow-read --allow-write --allow-env --allow-net --allow-run scripts/build_tools.ts - name: Upload to Cloudflare R2