2025-03-23 16:46:06 +00:00
|
|
|
import {
|
|
|
|
type AIFunctionLike,
|
|
|
|
AIFunctionSet,
|
2025-03-24 09:18:49 +00:00
|
|
|
asAgenticSchema,
|
2025-03-23 16:46:06 +00:00
|
|
|
isZodSchema
|
|
|
|
} from '@agentic/core'
|
|
|
|
import { jsonSchema, tool } from 'ai'
|
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,
|
2025-03-23 16:46:06 +00:00
|
|
|
parameters: isZodSchema(fn.inputSchema)
|
|
|
|
? fn.inputSchema
|
2025-03-24 09:18:49 +00:00
|
|
|
: jsonSchema(asAgenticSchema(fn.inputSchema).jsonSchema),
|
2025-03-20 12:53:48 +00:00
|
|
|
execute: fn.execute
|
2024-06-02 02:04:13 +00:00
|
|
|
})
|
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|