@kood/claude-code 0.1.6 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/dist/index.js +109 -216
  2. package/package.json +8 -2
  3. package/templates/hono/CLAUDE.md +59 -328
  4. package/templates/hono/docs/architecture/architecture.md +93 -747
  5. package/templates/hono/docs/deployment/cloudflare.md +59 -513
  6. package/templates/hono/docs/deployment/docker.md +41 -356
  7. package/templates/hono/docs/deployment/index.md +54 -190
  8. package/templates/hono/docs/deployment/railway.md +36 -306
  9. package/templates/hono/docs/deployment/vercel.md +49 -434
  10. package/templates/hono/docs/library/ai-sdk/index.md +53 -290
  11. package/templates/hono/docs/library/ai-sdk/openrouter.md +19 -387
  12. package/templates/hono/docs/library/ai-sdk/providers.md +28 -394
  13. package/templates/hono/docs/library/ai-sdk/streaming.md +52 -353
  14. package/templates/hono/docs/library/ai-sdk/structured-output.md +63 -395
  15. package/templates/hono/docs/library/ai-sdk/tools.md +62 -431
  16. package/templates/hono/docs/library/hono/env-setup.md +24 -313
  17. package/templates/hono/docs/library/hono/error-handling.md +34 -295
  18. package/templates/hono/docs/library/hono/index.md +29 -121
  19. package/templates/hono/docs/library/hono/middleware.md +21 -188
  20. package/templates/hono/docs/library/hono/rpc.md +40 -341
  21. package/templates/hono/docs/library/hono/validation.md +35 -195
  22. package/templates/hono/docs/library/pino/index.md +42 -333
  23. package/templates/hono/docs/library/prisma/cloudflare-d1.md +64 -367
  24. package/templates/hono/docs/library/prisma/config.md +19 -260
  25. package/templates/hono/docs/library/prisma/index.md +67 -320
  26. package/templates/hono/docs/library/zod/index.md +53 -257
  27. package/templates/npx/CLAUDE.md +62 -274
  28. package/templates/npx/docs/references/patterns.md +160 -0
  29. package/templates/tanstack-start/CLAUDE.md +100 -256
  30. package/templates/tanstack-start/docs/architecture/architecture.md +44 -589
  31. package/templates/tanstack-start/docs/deployment/cloudflare.md +37 -424
  32. package/templates/tanstack-start/docs/deployment/index.md +57 -286
  33. package/templates/tanstack-start/docs/deployment/nitro.md +36 -318
  34. package/templates/tanstack-start/docs/deployment/railway.md +40 -409
  35. package/templates/tanstack-start/docs/deployment/vercel.md +43 -465
  36. package/templates/tanstack-start/docs/design/components.md +77 -311
  37. package/templates/tanstack-start/docs/design/index.md +113 -69
  38. package/templates/tanstack-start/docs/design/safe-area.md +51 -250
  39. package/templates/tanstack-start/docs/design/tailwind-setup.md +45 -359
  40. package/templates/tanstack-start/docs/guides/conventions.md +103 -0
  41. package/templates/tanstack-start/docs/guides/env-setup.md +34 -340
  42. package/templates/tanstack-start/docs/guides/getting-started.md +22 -209
  43. package/templates/tanstack-start/docs/guides/hooks.md +166 -0
  44. package/templates/tanstack-start/docs/guides/routes.md +166 -0
  45. package/templates/tanstack-start/docs/guides/services.md +143 -0
  46. package/templates/tanstack-start/docs/library/better-auth/2fa.md +27 -115
  47. package/templates/tanstack-start/docs/library/better-auth/advanced.md +22 -105
  48. package/templates/tanstack-start/docs/library/better-auth/index.md +17 -66
  49. package/templates/tanstack-start/docs/library/better-auth/plugins.md +11 -88
  50. package/templates/tanstack-start/docs/library/better-auth/session.md +12 -92
  51. package/templates/tanstack-start/docs/library/better-auth/setup.md +9 -91
  52. package/templates/tanstack-start/docs/library/prisma/cloudflare-d1.md +30 -358
  53. package/templates/tanstack-start/docs/library/prisma/config.md +27 -327
  54. package/templates/tanstack-start/docs/library/prisma/crud.md +46 -174
  55. package/templates/tanstack-start/docs/library/prisma/index.md +23 -113
  56. package/templates/tanstack-start/docs/library/prisma/relations.md +31 -153
  57. package/templates/tanstack-start/docs/library/prisma/schema.md +40 -217
  58. package/templates/tanstack-start/docs/library/prisma/setup.md +12 -112
  59. package/templates/tanstack-start/docs/library/prisma/transactions.md +20 -110
  60. package/templates/tanstack-start/docs/library/tanstack-query/index.md +26 -97
  61. package/templates/tanstack-start/docs/library/tanstack-query/invalidation.md +28 -107
  62. package/templates/tanstack-start/docs/library/tanstack-query/optimistic-updates.md +44 -146
  63. package/templates/tanstack-start/docs/library/tanstack-query/use-mutation.md +33 -127
  64. package/templates/tanstack-start/docs/library/tanstack-query/use-query.md +49 -149
  65. package/templates/tanstack-start/docs/library/tanstack-start/auth-patterns.md +19 -112
  66. package/templates/tanstack-start/docs/library/tanstack-start/index.md +33 -80
  67. package/templates/tanstack-start/docs/library/tanstack-start/middleware.md +28 -106
  68. package/templates/tanstack-start/docs/library/tanstack-start/routing.md +21 -118
  69. package/templates/tanstack-start/docs/library/tanstack-start/server-functions.md +34 -246
  70. package/templates/tanstack-start/docs/library/tanstack-start/setup.md +6 -39
  71. package/templates/tanstack-start/docs/library/zod/complex-types.md +32 -156
  72. package/templates/tanstack-start/docs/library/zod/index.md +31 -144
  73. package/templates/tanstack-start/docs/library/zod/transforms.md +20 -129
  74. package/templates/tanstack-start/docs/library/zod/validation.md +39 -155
  75. package/templates/hono/docs/commands/git.md +0 -145
  76. package/templates/hono/docs/mcp/context7.md +0 -106
  77. package/templates/hono/docs/mcp/index.md +0 -176
  78. package/templates/hono/docs/mcp/sequential-thinking.md +0 -101
  79. package/templates/hono/docs/mcp/serena.md +0 -269
  80. package/templates/hono/docs/mcp/sgrep.md +0 -105
  81. package/templates/hono/docs/skills/gemini-review/SKILL.md +0 -220
  82. package/templates/hono/docs/skills/gemini-review/references/checklists.md +0 -136
  83. package/templates/hono/docs/skills/gemini-review/references/prompt-templates.md +0 -303
  84. package/templates/npx/docs/commands/git.md +0 -145
  85. package/templates/npx/docs/mcp/index.md +0 -60
  86. package/templates/npx/docs/skills/gemini-review/SKILL.md +0 -220
  87. package/templates/npx/docs/skills/gemini-review/references/checklists.md +0 -134
  88. package/templates/npx/docs/skills/gemini-review/references/prompt-templates.md +0 -301
  89. package/templates/tanstack-start/docs/commands/git.md +0 -145
  90. package/templates/tanstack-start/docs/design/accessibility.md +0 -433
  91. package/templates/tanstack-start/docs/design/color.md +0 -235
  92. package/templates/tanstack-start/docs/design/spacing.md +0 -341
  93. package/templates/tanstack-start/docs/design/typography.md +0 -324
  94. package/templates/tanstack-start/docs/guides/best-practices.md +0 -950
  95. package/templates/tanstack-start/docs/guides/husky-lint-staged.md +0 -303
  96. package/templates/tanstack-start/docs/guides/prettier.md +0 -189
  97. package/templates/tanstack-start/docs/guides/project-templates.md +0 -710
  98. package/templates/tanstack-start/docs/library/tanstack-query/setup.md +0 -107
  99. package/templates/tanstack-start/docs/library/zod/basic-types.md +0 -186
  100. package/templates/tanstack-start/docs/mcp/context7.md +0 -204
  101. package/templates/tanstack-start/docs/mcp/index.md +0 -177
  102. package/templates/tanstack-start/docs/mcp/sequential-thinking.md +0 -180
  103. package/templates/tanstack-start/docs/mcp/serena.md +0 -269
  104. package/templates/tanstack-start/docs/mcp/sgrep.md +0 -174
  105. package/templates/tanstack-start/docs/skills/gemini-review/SKILL.md +0 -220
  106. package/templates/tanstack-start/docs/skills/gemini-review/references/checklists.md +0 -144
  107. package/templates/tanstack-start/docs/skills/gemini-review/references/prompt-templates.md +0 -292
@@ -1,25 +1,16 @@
1
- # AI SDK - Tool Calling (Hono)
1
+ # AI SDK - Tool Calling
2
2
 
3
- > **상위 문서**: [AI SDK](./index.md)
4
-
5
- ---
6
-
7
- ## 개요
8
-
9
- AI SDK의 도구(Tool)를 Hono에서 사용하면 AI 모델이 외부 함수를 호출할 수 있습니다. 날씨 조회, 데이터베이스 검색, API 호출 등 다양한 작업을 수행할 수 있습니다.
3
+ > AI 모델이 외부 함수를 호출
10
4
 
11
5
  ---
12
6
 
13
7
  ## 기본 도구 정의
14
8
 
15
9
  ```typescript
16
- import { Hono } from 'hono'
17
10
  import { streamText, tool, convertToModelMessages } from 'ai'
18
11
  import { openai } from '@ai-sdk/openai'
19
12
  import { z } from 'zod'
20
13
 
21
- const app = new Hono()
22
-
23
14
  app.post('/api/chat', async (c) => {
24
15
  const { messages } = await c.req.json()
25
16
 
@@ -33,12 +24,7 @@ app.post('/api/chat', async (c) => {
33
24
  location: z.string().describe('The city name'),
34
25
  }),
35
26
  execute: async ({ location }) => {
36
- // 실제 날씨 API 호출
37
- return {
38
- location,
39
- temperature: 22,
40
- condition: 'Sunny',
41
- }
27
+ return { location, temperature: 22, condition: 'Sunny' }
42
28
  },
43
29
  }),
44
30
  },
@@ -50,26 +36,21 @@ app.post('/api/chat', async (c) => {
50
36
 
51
37
  ---
52
38
 
53
- ## tool() 함수 구조
39
+ ## tool() 구조
54
40
 
55
41
  ```typescript
56
42
  import { tool } from 'ai'
57
43
  import { z } from 'zod'
58
44
 
59
45
  const myTool = tool({
60
- // 도구 설명 (모델이 언제 사용할지 결정하는데 사용)
61
- description: 'Tool description for the AI model',
62
-
63
- // 입력 스키마 (Zod로 정의)
46
+ description: 'Tool description for the AI',
64
47
  inputSchema: z.object({
65
48
  param1: z.string().describe('Parameter description'),
66
49
  param2: z.number().optional(),
67
50
  }),
68
-
69
- // 실행 함수
70
51
  execute: async (args, context) => {
71
- // args: 스키마에 맞는 입력 값
72
- // context: { toolCallId, messages } 등 컨텍스트 정보
52
+ // args: 스키마에 맞는 입력값
53
+ // context: { toolCallId, messages }
73
54
  return { result: 'success' }
74
55
  },
75
56
  })
@@ -77,437 +58,87 @@ const myTool = tool({
77
58
 
78
59
  ---
79
60
 
80
- ## 여러 도구 정의
61
+ ## 여러 도구
81
62
 
82
63
  ```typescript
83
- import { Hono } from 'hono'
84
- import { streamText, tool, convertToModelMessages } from 'ai'
85
- import { openai } from '@ai-sdk/openai'
86
- import { z } from 'zod'
87
-
88
- const app = new Hono()
89
-
90
- app.post('/api/assistant', async (c) => {
91
- const { messages } = await c.req.json()
92
-
93
- const result = streamText({
94
- model: openai('gpt-4o'),
95
- messages: convertToModelMessages(messages),
96
- tools: {
97
- getWeather: tool({
98
- description: 'Get the weather for a location',
99
- inputSchema: z.object({
100
- location: z.string(),
101
- }),
102
- execute: async ({ location }) => ({
103
- temperature: 22,
104
- condition: 'Sunny',
105
- }),
106
- }),
107
-
108
- getAttractions: tool({
109
- description: 'Get tourist attractions for a city',
110
- inputSchema: z.object({
111
- city: z.string(),
112
- }),
113
- execute: async ({ city }) => ({
114
- attractions: [
115
- 'Gyeongbokgung Palace',
116
- 'N Seoul Tower',
117
- 'Bukchon Hanok Village',
118
- ],
119
- }),
120
- }),
121
-
122
- searchDatabase: tool({
123
- description: 'Search the database for information',
124
- inputSchema: z.object({
125
- query: z.string(),
126
- limit: z.number().optional().default(10),
127
- }),
128
- execute: async ({ query, limit }) => {
129
- // 데이터베이스 검색 로직
130
- return { results: [], total: 0 }
131
- },
132
- }),
133
- },
134
- })
135
-
136
- return result.toUIMessageStreamResponse()
137
- })
138
- ```
139
-
140
- ---
141
-
142
- ## 도구와 외부 서비스 연동
143
-
144
- ### 데이터베이스 연동
145
-
146
- ```typescript
147
- import { Hono } from 'hono'
148
- import { streamText, tool, convertToModelMessages } from 'ai'
149
- import { openai } from '@ai-sdk/openai'
150
- import { z } from 'zod'
151
- import { prisma } from '@/database/prisma'
152
-
153
- const app = new Hono()
154
-
155
- app.post('/api/chat', async (c) => {
156
- const { messages } = await c.req.json()
157
-
158
- const result = streamText({
159
- model: openai('gpt-4o'),
160
- messages: convertToModelMessages(messages),
161
- tools: {
162
- searchProducts: tool({
163
- description: 'Search for products in the database',
164
- inputSchema: z.object({
165
- query: z.string().describe('Search query'),
166
- category: z.string().optional().describe('Product category'),
167
- maxPrice: z.number().optional().describe('Maximum price'),
168
- }),
169
- execute: async ({ query, category, maxPrice }) => {
170
- const products = await prisma.product.findMany({
171
- where: {
172
- name: { contains: query },
173
- ...(category && { category }),
174
- ...(maxPrice && { price: { lte: maxPrice } }),
175
- },
176
- take: 10,
177
- })
178
- return { products }
179
- },
180
- }),
181
-
182
- getOrderStatus: tool({
183
- description: 'Get the status of an order',
184
- inputSchema: z.object({
185
- orderId: z.string().describe('The order ID'),
186
- }),
187
- execute: async ({ orderId }) => {
188
- const order = await prisma.order.findUnique({
189
- where: { id: orderId },
190
- include: { items: true },
191
- })
192
- return order ?? { error: 'Order not found' }
193
- },
194
- }),
195
- },
196
- })
197
-
198
- return result.toUIMessageStreamResponse()
199
- })
200
- ```
201
-
202
- ### 외부 API 연동
203
-
204
- ```typescript
205
- import { Hono } from 'hono'
206
- import { streamText, tool, convertToModelMessages } from 'ai'
207
- import { openai } from '@ai-sdk/openai'
208
- import { z } from 'zod'
209
-
210
- type Bindings = {
211
- WEATHER_API_KEY: string
212
- }
213
-
214
- const app = new Hono<{ Bindings: Bindings }>()
215
-
216
- app.post('/api/chat', async (c) => {
217
- const { messages } = await c.req.json()
218
-
219
- const result = streamText({
220
- model: openai('gpt-4o'),
221
- messages: convertToModelMessages(messages),
222
- tools: {
223
- getWeather: tool({
224
- description: 'Get real-time weather data',
225
- inputSchema: z.object({
226
- city: z.string(),
227
- }),
228
- execute: async ({ city }) => {
229
- const response = await fetch(
230
- `https://api.weather.com/v1/current?city=${city}&key=${c.env.WEATHER_API_KEY}`
231
- )
232
- return response.json()
233
- },
234
- }),
235
-
236
- translateText: tool({
237
- description: 'Translate text to another language',
238
- inputSchema: z.object({
239
- text: z.string(),
240
- targetLanguage: z.string(),
241
- }),
242
- execute: async ({ text, targetLanguage }) => {
243
- // 번역 API 호출
244
- const response = await fetch('https://api.translate.com/v1/translate', {
245
- method: 'POST',
246
- headers: { 'Content-Type': 'application/json' },
247
- body: JSON.stringify({ text, target: targetLanguage }),
248
- })
249
- return response.json()
250
- },
251
- }),
252
- },
253
- })
254
-
255
- return result.toUIMessageStreamResponse()
256
- })
257
- ```
258
-
259
- ---
260
-
261
- ## 다중 단계 실행
262
-
263
- AI가 여러 도구를 순차적으로 호출하도록 허용:
264
-
265
- ```typescript
266
- import { Hono } from 'hono'
267
- import { generateText, tool, stepCountIs } from 'ai'
268
- import { openai } from '@ai-sdk/openai'
269
- import { z } from 'zod'
270
-
271
- const app = new Hono()
272
-
273
- app.post('/api/plan-trip', async (c) => {
274
- const { destination } = await c.req.json()
275
-
276
- const result = await generateText({
277
- model: openai('gpt-4o'),
278
- prompt: `Plan a trip to ${destination}`,
279
- tools: {
280
- getWeather: tool({
281
- description: 'Get weather forecast',
282
- inputSchema: z.object({ location: z.string() }),
283
- execute: async ({ location }) => ({ forecast: 'Sunny, 22°C' }),
284
- }),
285
- getFlights: tool({
286
- description: 'Search for flights',
287
- inputSchema: z.object({ destination: z.string() }),
288
- execute: async ({ destination }) => ({ flights: ['Flight A', 'Flight B'] }),
289
- }),
290
- getHotels: tool({
291
- description: 'Search for hotels',
292
- inputSchema: z.object({ location: z.string() }),
293
- execute: async ({ location }) => ({ hotels: ['Hotel A', 'Hotel B'] }),
64
+ const result = streamText({
65
+ model: openai('gpt-4o'),
66
+ messages: convertToModelMessages(messages),
67
+ tools: {
68
+ getWeather: tool({
69
+ description: 'Get weather',
70
+ inputSchema: z.object({ location: z.string() }),
71
+ execute: async ({ location }) => {
72
+ return { temperature: 22, condition: 'Sunny' }
73
+ },
74
+ }),
75
+ searchDatabase: tool({
76
+ description: 'Search the database',
77
+ inputSchema: z.object({ query: z.string() }),
78
+ execute: async ({ query }) => {
79
+ return { results: [] }
80
+ },
81
+ }),
82
+ sendEmail: tool({
83
+ description: 'Send an email',
84
+ inputSchema: z.object({
85
+ to: z.email(),
86
+ subject: z.string(),
87
+ body: z.string(),
294
88
  }),
295
- },
296
- stopWhen: stepCountIs(5), // 최대 5단계
297
- })
298
-
299
- return c.json({
300
- plan: result.text,
301
- steps: result.steps.map((step) => ({
302
- toolCalls: step.toolCalls,
303
- toolResults: step.toolResults,
304
- })),
305
- })
89
+ execute: async (args) => {
90
+ return { sent: true }
91
+ },
92
+ }),
93
+ },
306
94
  })
307
95
  ```
308
96
 
309
97
  ---
310
98
 
311
- ## 도구 컨텍스트 활용
99
+ ## 다단계 도구 호출
312
100
 
313
101
  ```typescript
314
- app.post('/api/chat', async (c) => {
315
- const { messages } = await c.req.json()
102
+ import { generateText } from 'ai'
316
103
 
317
- const result = streamText({
318
- model: openai('gpt-4o'),
319
- messages: convertToModelMessages(messages),
320
- tools: {
321
- processRequest: tool({
322
- description: 'Process a user request',
323
- inputSchema: z.object({ request: z.string() }),
324
- execute: async (args, context) => {
325
- // 도구 호출 ID
326
- console.log('Tool call ID:', context.toolCallId)
327
-
328
- // 전체 메시지 히스토리 접근
329
- console.log('Messages:', context.messages)
330
-
331
- return { processed: true }
332
- },
333
- }),
334
- },
335
- })
336
-
337
- return result.toUIMessageStreamResponse()
104
+ const { text, steps } = await generateText({
105
+ model: openai('gpt-4o'),
106
+ messages: convertToModelMessages(messages),
107
+ tools: { ... },
108
+ maxSteps: 5, // 최대 도구 호출 횟수
338
109
  })
339
- ```
340
-
341
- ---
342
-
343
- ## 도구 결과 스트리밍
344
-
345
- ```typescript
346
- import { Hono } from 'hono'
347
- import { streamText, tool } from 'ai'
348
- import { openai } from '@ai-sdk/openai'
349
- import { z } from 'zod'
350
- import { stream } from 'hono/streaming'
351
110
 
352
- const app = new Hono()
353
-
354
- app.post('/api/chat', async (c) => {
355
- const { messages } = await c.req.json()
356
-
357
- const result = streamText({
358
- model: openai('gpt-4o'),
359
- messages,
360
- tools: {
361
- getWeather: tool({
362
- description: 'Get weather',
363
- inputSchema: z.object({ location: z.string() }),
364
- execute: async ({ location }) => ({ temp: 22 }),
365
- }),
366
- },
367
- })
368
-
369
- return stream(c, async (stream) => {
370
- for await (const event of result.fullStream) {
371
- switch (event.type) {
372
- case 'text-delta':
373
- await stream.write(
374
- JSON.stringify({ type: 'text', content: event.textDelta }) + '\n'
375
- )
376
- break
377
- case 'tool-call':
378
- await stream.write(
379
- JSON.stringify({
380
- type: 'tool-call',
381
- name: event.toolName,
382
- args: event.args,
383
- }) + '\n'
384
- )
385
- break
386
- case 'tool-result':
387
- await stream.write(
388
- JSON.stringify({
389
- type: 'tool-result',
390
- name: event.toolName,
391
- result: event.result,
392
- }) + '\n'
393
- )
394
- break
395
- }
396
- }
397
- })
398
- })
111
+ // steps: 단계의 도구 호출 정보
399
112
  ```
400
113
 
401
114
  ---
402
115
 
403
- ## 타입 안전한 도구
116
+ ## 도구 선택 제어
404
117
 
405
118
  ```typescript
406
- import { tool, TypedToolCall, TypedToolResult } from 'ai'
407
- import { z } from 'zod'
408
-
409
- const myToolSet = {
410
- greet: tool({
411
- description: 'Greet a user',
412
- inputSchema: z.object({ name: z.string() }),
413
- execute: async ({ name }) => `Hello, ${name}!`,
414
- }),
415
- calculate: tool({
416
- description: 'Calculate sum',
417
- inputSchema: z.object({
418
- a: z.number(),
419
- b: z.number(),
420
- }),
421
- execute: async ({ a, b }) => a + b,
422
- }),
423
- }
424
-
425
- // 타입 추출
426
- type MyToolCall = TypedToolCall<typeof myToolSet>
427
- type MyToolResult = TypedToolResult<typeof myToolSet>
428
-
429
- // Hono 라우트에서 사용
430
- app.post('/api/typed-chat', async (c) => {
431
- const { messages } = await c.req.json()
432
-
433
- const result = await generateText({
434
- model: openai('gpt-4o'),
435
- tools: myToolSet,
436
- messages,
437
- })
119
+ const result = streamText({
120
+ model: openai('gpt-4o'),
121
+ messages,
122
+ tools: { ... },
438
123
 
439
- // 타입 안전한 접근
440
- const toolCalls: MyToolCall[] = result.toolCalls
441
- const toolResults: MyToolResult[] = result.toolResults
124
+ // 도구 사용 강제
125
+ toolChoice: 'required',
442
126
 
443
- return c.json({ toolCalls, toolResults })
444
- })
445
- ```
446
-
447
- ---
127
+ // 특정 도구만
128
+ toolChoice: { type: 'tool', toolName: 'getWeather' },
448
129
 
449
- ## 도구 에러 처리
130
+ // 도구 사용 금지
131
+ toolChoice: 'none',
450
132
 
451
- ```typescript
452
- app.post('/api/chat', async (c) => {
453
- const { messages } = await c.req.json()
454
-
455
- const result = streamText({
456
- model: openai('gpt-4o'),
457
- messages: convertToModelMessages(messages),
458
- tools: {
459
- riskyOperation: tool({
460
- description: 'Perform a risky operation',
461
- inputSchema: z.object({ data: z.string() }),
462
- execute: async ({ data }) => {
463
- try {
464
- // 위험한 작업 수행
465
- const result = await performRiskyTask(data)
466
- return { success: true, result }
467
- } catch (error) {
468
- // 에러를 AI가 이해할 수 있는 형태로 반환
469
- return {
470
- success: false,
471
- error: error instanceof Error ? error.message : 'Unknown error',
472
- }
473
- }
474
- },
475
- }),
476
- },
477
- })
478
-
479
- return result.toUIMessageStreamResponse()
133
+ // 자동 (기본)
134
+ toolChoice: 'auto',
480
135
  })
481
136
  ```
482
137
 
483
138
  ---
484
139
 
485
- ## 도구 정의 팁
486
-
487
- 1. **명확한 설명**: 모델이 언제 도구를 사용할지 이해하도록 상세히 작성
488
- 2. **스키마 설명**: 각 파라미터에 `.describe()` 추가
489
- 3. **에러 처리**: execute 함수에서 적절한 에러 처리
490
- 4. **반환값**: 모델이 이해할 수 있는 구조화된 데이터 반환
140
+ ## 관련 문서
491
141
 
492
- ```typescript
493
- const goodTool = tool({
494
- description: `
495
- Search for products in the database.
496
- Use this when the user asks about available products,
497
- product prices, or product availability.
498
- `,
499
- inputSchema: z.object({
500
- query: z.string().describe('Search query for product name or category'),
501
- maxResults: z.number().default(10).describe('Maximum number of results'),
502
- category: z.string().optional().describe('Filter by category'),
503
- }),
504
- execute: async ({ query, maxResults, category }) => {
505
- try {
506
- const results = await db.products.search({ query, maxResults, category })
507
- return { success: true, products: results }
508
- } catch (error) {
509
- return { success: false, error: 'Failed to search products' }
510
- }
511
- },
512
- })
513
- ```
142
+ - [AI SDK 개요](./index.md)
143
+ - [스트리밍](./streaming.md)
144
+ - [구조화된 출력](./structured-output.md)