UNPKG

@suiware/ai-tools

Version:

Pluggable tools for Vercel AI SDK which allow AI assistants to interact with Sui Network and perform various actions.

1 lines 2.38 kB
{"version":3,"sources":["../src/ai/tools/suiSwapTool.ts"],"names":[],"mappings":";;;;;AAKO,IAAM,cAAc,IAAK,CAAA;AAAA,EAC9B,WAAa,EAAA,YAAA;AAAA,EACb,UAAA,EAAY,EAAE,MAAO,CAAA;AAAA,IACnB,MAAQ,EAAA,CAAA,CAAE,MAAO,EAAA,CAAE,SAAS,mCAAmC,CAAA;AAAA,IAC/D,UAAA,EAAY,CACT,CAAA,MAAA,EACA,CAAA,MAAA,CAAO,CAAC,GAAgB,KAAA,WAAA,CAAY,eAAgB,CAAA,GAAG,CAAG,EAAA;AAAA,MACzD,OAAS,EAAA;AAAA,KACV,CACA,CAAA,QAAA,CAAS,iBAAiB,CAAA;AAAA,IAC7B,UAAA,EAAY,CACT,CAAA,MAAA,EACA,CAAA,MAAA,CAAO,CAAC,GAAgB,KAAA,WAAA,CAAY,eAAgB,CAAA,GAAG,CAAG,EAAA;AAAA,MACzD,OAAS,EAAA;AAAA,KACV,CACA,CAAA,QAAA,CAAS,iBAAiB;AAAA,GAC9B,CAAA;AAAA,EACD,OAAA,EAAS,CAAO,EAAA,KAAuC,OAAvC,CAAA,IAAA,EAAA,CAAA,EAAA,CAAA,EAAuC,WAAvC,EAAE,MAAA,EAAQ,UAAY,EAAA,UAAA,EAAiB,EAAA;AAGrD,IAAA,MAAM,qBAAqB,iBAAkB,EAAA;AAE7C,IAAM,MAAA,WAAA,GAAc,IAAI,WAAY,EAAA;AAEpC,IAAM,MAAA,iBAAA,GAAoB,MAAM,WAAY,CAAA,IAAA;AAAA,MAC1C,UAAA;AAAA,MACA,UAAA;AAAA,MACA;AAAA,KACF;AAGA,IAAA,gBAAA,CAAiB,kBAAkB,CAAA;AAEnC,IAAO,OAAA;AAAA,MACL,QAAQ,iBAAkB,CAAA;AAAA,KAC5B;AAAA,GACF;AACF,CAAC","file":"chunk-75WAM73K.mjs","sourcesContent":["import { tool } from 'ai'\nimport z from 'zod'\nimport { disableConsoleLog, enableConsoleLog } from '../../core/utils/utils'\nimport { NaviService } from '../../services/NaviService'\n\nexport const suiSwapTool = tool({\n description: 'Swap coins',\n parameters: z.object({\n amount: z.number().describe('The amount of source coin to swap'),\n sourceCoin: z\n .string()\n .refine((arg: string) => NaviService.isSupportedCoin(arg), {\n message: 'The source coin not supported',\n })\n .describe('The source coin'),\n targetCoin: z\n .string()\n .refine((arg: string) => NaviService.isSupportedCoin(arg), {\n message: 'The target coin not supported',\n })\n .describe('The target coin'),\n }),\n execute: async ({ amount, sourceCoin, targetCoin }) => {\n // We need to suppress the Navi's console log messages to prevent polluting the output.\n // See https://github.com/naviprotocol/navi-sdk/issues/82\n const originalConsoleLog = disableConsoleLog()\n\n const naviService = new NaviService()\n\n const transactionResult = await naviService.swap(\n sourceCoin,\n targetCoin,\n amount\n )\n\n // Get the logs back.\n enableConsoleLog(originalConsoleLog)\n\n return {\n digest: transactionResult.digest,\n }\n },\n})\n"]}