2024-06-02 02:04:13 +00:00
|
|
|
import { tool } from 'ai'
|
|
|
|
|
2024-07-31 16:12:00 +00:00
|
|
|
import type { AIFunctionLike } from '../types'
|
|
|
|
import { AIFunctionSet } from '../ai-function-set'
|
2024-06-02 02:04:13 +00:00
|
|
|
|
2024-06-02 07:30:50 +00:00
|
|
|
/**
|
|
|
|
* Converts a set of Agentic stdlib AI functions to an object compatible with
|
|
|
|
* the Vercel AI SDK's `tools` parameter.
|
|
|
|
*/
|
2024-06-02 23:31:09 +00:00
|
|
|
export function createAISDKTools(...aiFunctionLikeTools: AIFunctionLike[]) {
|
|
|
|
const fns = new AIFunctionSet(aiFunctionLikeTools)
|
2024-06-02 02:04:13 +00:00
|
|
|
|
|
|
|
return Object.fromEntries(
|
2024-06-02 23:31:09 +00:00
|
|
|
fns.map((fn) => [
|
2024-06-02 02:04:13 +00:00
|
|
|
fn.spec.name,
|
|
|
|
tool({
|
|
|
|
description: fn.spec.description,
|
|
|
|
parameters: fn.inputSchema,
|
|
|
|
execute: fn.impl
|
|
|
|
})
|
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|