InferUITool — 단일 도구의 타입 추론

InferUITool — 단일 도구의 타입 추론

InferUITool은 도구(tool)의 입력·출력 타입을 추론하는 타입 헬퍼예요. UIMessage 안에서 개별 도구를 다룰 때 도구 입력·출력의 타입 안전성을 보장하기 위해 유용해요.

출처: 문서

본문

도구의 입력·출력 타입을 추론해요.

이 타입 헬퍼는 UIMessage에서 도구 입력·출력의 타입 안전성을 보장하면서 개별 도구를 다룰 때 유용해요.

Import

import { InferUITool } from 'ai';

API 시그니처

타입 파라미터

  • TOOL: Tool — 타입을 추론할 도구.

반환값

도구의 추론된 입력·출력 타입을 담은 타입을 반환해요. 결과 타입의 형태는:

{
  input: InferToolInput<TOOL>;
  output: InferToolOutput<TOOL>;
}

예시

기본 사용

import { InferUITool } from 'ai';
import { z } from 'zod';

const weatherTool = {
  description: 'Get the current weather',
  inputSchema: z.object({
    location: z.string().describe('The city and state'),
  }),
  execute: async ({ location }) => {
    return `The weather in ${location} is sunny.`;
  },
};

// 도구에서 타입 추론
type WeatherUITool = InferUITool<typeof weatherTool>;
// 이렇게 타입이 만들어져요:
// {
//   input: { location: string };
//   output: string;
// }

관련 항목

더 알아보기 (Learn more)