feat: upgrade ai package to version six and the corresponding @ai-sdk/* packages to compatible versions (#18172)
Used the migration guide to carry out this upgrade: https://ai-sdk.dev/docs/migration-guides/migration-guide-6-0 I have not been able to test locally due to credits. <img width="220" height="450" alt="image" src="https://github.com/user-attachments/assets/050b34b9-3239-4010-8c47-b43d44571994" /> --------- Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
+1
-1
@@ -230,7 +230,7 @@ export class ToolExecutorService {
|
||||
);
|
||||
}
|
||||
|
||||
// The tool's execute expects (args, ToolCallOptions). Pass args with
|
||||
// The tool's execute expects (args, ToolExecutionOptions). Pass args with
|
||||
// a dummy loadingMessage since the tool's internal strip is harmless.
|
||||
return tool.execute(
|
||||
{ loadingMessage: '', ...args },
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||
|
||||
import { type ToolCallOptions, type ToolSet, jsonSchema } from 'ai';
|
||||
import { type ToolExecutionOptions, type ToolSet, jsonSchema } from 'ai';
|
||||
|
||||
import {
|
||||
type NativeToolProvider,
|
||||
@@ -219,7 +219,7 @@ export class ToolRegistryService {
|
||||
toolName: string,
|
||||
args: Record<string, unknown>,
|
||||
context: ToolContext,
|
||||
_options: ToolCallOptions,
|
||||
_options: ToolExecutionOptions,
|
||||
): Promise<ExecuteToolResult> {
|
||||
try {
|
||||
const fullContext = this.buildContextFromToolContext(context);
|
||||
|
||||
+27
-4
@@ -1,4 +1,5 @@
|
||||
import { type ToolCallOptions, type ToolSet } from 'ai';
|
||||
import { jsonSchema, type ToolExecutionOptions, type ToolSet } from 'ai';
|
||||
import { type JSONSchema7 } from 'json-schema';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { type ToolRegistryService } from 'src/engine/core-modules/tool-provider/services/tool-registry.service';
|
||||
@@ -6,7 +7,7 @@ import { type ToolContext } from 'src/engine/core-modules/tool-provider/types/to
|
||||
|
||||
export const EXECUTE_TOOL_TOOL_NAME = 'execute_tool';
|
||||
|
||||
export const executeToolInputSchema = z.object({
|
||||
const executeToolInputZodSchema = z.object({
|
||||
toolName: z
|
||||
.string()
|
||||
.describe('Exact tool name from get_tool_catalog. Do not guess.'),
|
||||
@@ -15,7 +16,29 @@ export const executeToolInputSchema = z.object({
|
||||
.describe('Arguments matching the schema returned by learn_tools.'),
|
||||
});
|
||||
|
||||
export type ExecuteToolInput = z.infer<typeof executeToolInputSchema>;
|
||||
export type ExecuteToolInput = z.infer<typeof executeToolInputZodSchema>;
|
||||
|
||||
export const executeToolInputSchema = jsonSchema<ExecuteToolInput>(
|
||||
() => {
|
||||
const schema = z.toJSONSchema(executeToolInputZodSchema, {
|
||||
target: 'draft-7',
|
||||
io: 'input',
|
||||
}) as JSONSchema7;
|
||||
|
||||
schema.additionalProperties = false;
|
||||
|
||||
return schema;
|
||||
},
|
||||
{
|
||||
validate: async (value) => {
|
||||
const result = await z.safeParseAsync(executeToolInputZodSchema, value);
|
||||
|
||||
return result.success
|
||||
? { success: true, value: result.data }
|
||||
: { success: false, error: result.error };
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
export type ExecuteToolResult = {
|
||||
toolName: string;
|
||||
@@ -37,7 +60,7 @@ export const createExecuteToolTool = (
|
||||
inputSchema: executeToolInputSchema,
|
||||
execute: async (
|
||||
parameters: ExecuteToolInput,
|
||||
options: ToolCallOptions,
|
||||
options: ToolExecutionOptions,
|
||||
): Promise<ExecuteToolResult> => {
|
||||
const { toolName, arguments: args } = parameters;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user