-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathvercel.ts
More file actions
30 lines (26 loc) · 901 Bytes
/
vercel.ts
File metadata and controls
30 lines (26 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import type { Action } from "@polkadot-agent-kit/llm"
import type { Tool } from "ai"
import { tool, type ToolSet } from "ai"
import type { z } from "zod"
import type { PolkadotAgentKit } from "./api"
/**
* Get Vercel AI SDK tools from an PolkadotAgentKit instance
*
* @param polkadotAgentKit - The PolkadotAgentKit instance
* @returns An object containing Vercel AI SDK tools keyed by tool name
*/
export function getVercelAITools(polkadotAgentKit: PolkadotAgentKit): ToolSet {
const actions: Action[] = polkadotAgentKit.getActions()
const toolSet: Record<string, Tool> = {}
for (const action of actions) {
toolSet[action.name] = tool({
description: action.description,
parameters: action.schema,
execute: async (args: z.infer<typeof action.schema>) => {
const result = await action.invoke(args)
return result
}
})
}
return toolSet
}