@kood/claude-code 0.2.4 → 0.3.0

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 (130) hide show
  1. package/dist/index.js +13 -8
  2. package/package.json +1 -1
  3. package/templates/.claude/agents/code-reviewer.md +371 -19
  4. package/templates/.claude/agents/dependency-manager.md +197 -0
  5. package/templates/.claude/agents/deployment-validator.md +136 -0
  6. package/templates/.claude/agents/git-operator.md +147 -0
  7. package/templates/.claude/agents/implementation-executor.md +202 -0
  8. package/templates/.claude/agents/lint-fixer.md +155 -0
  9. package/templates/.claude/agents/refactor-advisor.md +339 -29
  10. package/templates/.claude/commands/agent-creator.md +355 -0
  11. package/templates/.claude/commands/docs-creator.md +404 -163
  12. package/templates/.claude/commands/docs-refactor.md +400 -113
  13. package/templates/.claude/commands/execute.md +357 -185
  14. package/templates/.claude/commands/git-all.md +16 -70
  15. package/templates/.claude/commands/git-session.md +36 -68
  16. package/templates/.claude/commands/git.md +20 -69
  17. package/templates/.claude/commands/lint-fix.md +164 -107
  18. package/templates/.claude/commands/lint-init.md +142 -168
  19. package/templates/.claude/commands/plan.md +300 -84
  20. package/templates/.claude/commands/prd.md +613 -0
  21. package/templates/.claude/commands/pre-deploy.md +242 -0
  22. package/templates/.claude/commands/subagent-creator.md +118 -0
  23. package/templates/.claude/commands/version-update.md +45 -57
  24. package/templates/hono/CLAUDE.md +99 -54
  25. package/templates/hono/docs/guides/conventions.md +352 -0
  26. package/templates/hono/docs/guides/env-setup.md +347 -0
  27. package/templates/hono/docs/guides/getting-started.md +239 -0
  28. package/templates/hono/docs/library/hono/error-handling.md +20 -29
  29. package/templates/hono/docs/library/hono/index.md +25 -52
  30. package/templates/hono/docs/library/hono/middleware.md +16 -75
  31. package/templates/hono/docs/library/hono/rpc.md +7 -35
  32. package/templates/hono/docs/library/hono/validation.md +25 -45
  33. package/templates/hono/docs/library/t3-env/index.md +374 -0
  34. package/templates/npx/CLAUDE.md +165 -65
  35. package/templates/npx/docs/library/commander/index.md +10 -73
  36. package/templates/npx/docs/library/fs-extra/index.md +21 -113
  37. package/templates/npx/docs/library/prompts/index.md +30 -176
  38. package/templates/npx/docs/references/patterns.md +75 -48
  39. package/templates/tanstack-start/CLAUDE.md +101 -77
  40. package/templates/tanstack-start/docs/architecture.md +427 -0
  41. package/templates/tanstack-start/docs/design.md +558 -0
  42. package/templates/tanstack-start/docs/guides/conventions.md +132 -32
  43. package/templates/tanstack-start/docs/guides/env-setup.md +127 -62
  44. package/templates/tanstack-start/docs/guides/getting-started.md +81 -20
  45. package/templates/tanstack-start/docs/guides/hooks.md +241 -36
  46. package/templates/tanstack-start/docs/guides/routes.md +213 -61
  47. package/templates/tanstack-start/docs/guides/services.md +260 -24
  48. package/templates/tanstack-start/docs/library/better-auth/index.md +469 -16
  49. package/templates/tanstack-start/docs/library/t3-env/index.md +307 -0
  50. package/templates/tanstack-start/docs/library/tanstack-query/index.md +12 -21
  51. package/templates/tanstack-start/docs/library/tanstack-query/invalidation.md +22 -35
  52. package/templates/tanstack-start/docs/library/tanstack-query/optimistic-updates.md +7 -24
  53. package/templates/tanstack-start/docs/library/tanstack-query/use-mutation.md +26 -39
  54. package/templates/tanstack-start/docs/library/tanstack-query/use-query.md +23 -26
  55. package/templates/tanstack-start/docs/library/tanstack-router/error-handling.md +32 -147
  56. package/templates/tanstack-start/docs/library/tanstack-router/hooks.md +25 -167
  57. package/templates/tanstack-start/docs/library/tanstack-router/index.md +39 -74
  58. package/templates/tanstack-start/docs/library/tanstack-router/navigation.md +46 -116
  59. package/templates/tanstack-start/docs/library/tanstack-router/route-context.md +35 -154
  60. package/templates/tanstack-start/docs/library/tanstack-router/search-params.md +32 -171
  61. package/templates/tanstack-start/docs/library/tanstack-start/auth-patterns.md +7 -15
  62. package/templates/tanstack-start/docs/library/tanstack-start/routing.md +16 -23
  63. package/templates/tanstack-start/docs/library/zod/complex-types.md +12 -31
  64. package/templates/tanstack-start/docs/library/zod/index.md +18 -35
  65. package/templates/tanstack-start/docs/library/zod/transforms.md +11 -25
  66. package/templates/tanstack-start/docs/library/zod/validation.md +12 -34
  67. package/templates/.claude/agents/debug-detective.md +0 -37
  68. package/templates/.claude/agents/test-writer.md +0 -41
  69. package/templates/.claude/commands/feedback.md +0 -199
  70. package/templates/.claude/commands/ts-fix.md +0 -176
  71. package/templates/.claude/skills/command-creator/LICENSE.txt +0 -202
  72. package/templates/.claude/skills/command-creator/SKILL.md +0 -245
  73. package/templates/.claude/skills/command-creator/scripts/init_command.py +0 -244
  74. package/templates/.claude/skills/command-creator/scripts/package_command.py +0 -125
  75. package/templates/.claude/skills/command-creator/scripts/quick_validate.py +0 -143
  76. package/templates/.claude/skills/frontend-design/SKILL.md +0 -310
  77. package/templates/.claude/skills/frontend-design/references/animation-patterns.md +0 -446
  78. package/templates/.claude/skills/frontend-design/references/colors-2026.md +0 -244
  79. package/templates/.claude/skills/frontend-design/references/typography-2026.md +0 -302
  80. package/templates/.claude/skills/gemini-review/SKILL.md +0 -118
  81. package/templates/.claude/skills/gemini-review/references/checklists.md +0 -129
  82. package/templates/.claude/skills/gemini-review/references/prompt-templates.md +0 -274
  83. package/templates/.claude/skills/skill-creator/LICENSE.txt +0 -202
  84. package/templates/.claude/skills/skill-creator/SKILL.md +0 -184
  85. package/templates/.claude/skills/skill-creator/scripts/init_skill.py +0 -303
  86. package/templates/.claude/skills/skill-creator/scripts/package_skill.py +0 -110
  87. package/templates/.claude/skills/skill-creator/scripts/quick_validate.py +0 -65
  88. package/templates/hono/docs/library/ai-sdk/index.md +0 -190
  89. package/templates/hono/docs/library/ai-sdk/openrouter.md +0 -111
  90. package/templates/hono/docs/library/ai-sdk/providers.md +0 -102
  91. package/templates/hono/docs/library/ai-sdk/streaming.md +0 -146
  92. package/templates/hono/docs/library/ai-sdk/structured-output.md +0 -161
  93. package/templates/hono/docs/library/ai-sdk/tools.md +0 -144
  94. package/templates/hono/docs/library/drizzle/cloudflare-d1.md +0 -247
  95. package/templates/hono/docs/library/drizzle/config.md +0 -167
  96. package/templates/hono/docs/library/drizzle/index.md +0 -259
  97. package/templates/hono/docs/library/hono/env-setup.md +0 -169
  98. package/templates/hono/docs/library/pino/index.md +0 -146
  99. package/templates/tanstack-start/docs/architecture/architecture.md +0 -243
  100. package/templates/tanstack-start/docs/deployment/cloudflare.md +0 -132
  101. package/templates/tanstack-start/docs/deployment/index.md +0 -163
  102. package/templates/tanstack-start/docs/deployment/nitro.md +0 -110
  103. package/templates/tanstack-start/docs/deployment/railway.md +0 -147
  104. package/templates/tanstack-start/docs/deployment/vercel.md +0 -135
  105. package/templates/tanstack-start/docs/design/components.md +0 -175
  106. package/templates/tanstack-start/docs/design/index.md +0 -151
  107. package/templates/tanstack-start/docs/design/safe-area.md +0 -118
  108. package/templates/tanstack-start/docs/design/tailwind-setup.md +0 -156
  109. package/templates/tanstack-start/docs/library/ai-sdk/hooks.md +0 -472
  110. package/templates/tanstack-start/docs/library/ai-sdk/index.md +0 -264
  111. package/templates/tanstack-start/docs/library/ai-sdk/openrouter.md +0 -371
  112. package/templates/tanstack-start/docs/library/ai-sdk/providers.md +0 -403
  113. package/templates/tanstack-start/docs/library/ai-sdk/streaming.md +0 -320
  114. package/templates/tanstack-start/docs/library/ai-sdk/structured-output.md +0 -454
  115. package/templates/tanstack-start/docs/library/ai-sdk/tools.md +0 -473
  116. package/templates/tanstack-start/docs/library/better-auth/2fa.md +0 -48
  117. package/templates/tanstack-start/docs/library/better-auth/advanced.md +0 -55
  118. package/templates/tanstack-start/docs/library/better-auth/plugins.md +0 -34
  119. package/templates/tanstack-start/docs/library/better-auth/session.md +0 -47
  120. package/templates/tanstack-start/docs/library/better-auth/setup.md +0 -41
  121. package/templates/tanstack-start/docs/library/drizzle/cloudflare-d1.md +0 -147
  122. package/templates/tanstack-start/docs/library/drizzle/config.md +0 -118
  123. package/templates/tanstack-start/docs/library/drizzle/crud.md +0 -205
  124. package/templates/tanstack-start/docs/library/drizzle/index.md +0 -79
  125. package/templates/tanstack-start/docs/library/drizzle/relations.md +0 -202
  126. package/templates/tanstack-start/docs/library/drizzle/schema.md +0 -154
  127. package/templates/tanstack-start/docs/library/drizzle/setup.md +0 -96
  128. package/templates/tanstack-start/docs/library/drizzle/transactions.md +0 -127
  129. package/templates/tanstack-start/docs/library/pino/index.md +0 -320
  130. /package/templates/hono/docs/{architecture/architecture.md → architecture.md} +0 -0
@@ -1,111 +0,0 @@
1
- # AI SDK - OpenRouter
2
-
3
- > 수백 개 모델을 단일 API로
4
-
5
- ---
6
-
7
- ## 설치
8
-
9
- ```bash
10
- npm install @openrouter/ai-sdk-provider
11
- ```
12
-
13
- ---
14
-
15
- ## 기본 사용
16
-
17
- ```typescript
18
- import { Hono } from 'hono'
19
- import { streamText, convertToModelMessages } from 'ai'
20
- import { createOpenRouter } from '@openrouter/ai-sdk-provider'
21
-
22
- const openrouter = createOpenRouter({
23
- apiKey: process.env.OPENROUTER_API_KEY,
24
- })
25
-
26
- app.post('/api/chat', async (c) => {
27
- const { messages } = await c.req.json()
28
-
29
- const result = streamText({
30
- model: openrouter.chat('anthropic/claude-3.5-sonnet'),
31
- messages: convertToModelMessages(messages),
32
- })
33
-
34
- return result.toUIMessageStreamResponse()
35
- })
36
- ```
37
-
38
- ---
39
-
40
- ## 동적 모델 선택
41
-
42
- ```typescript
43
- import { HTTPException } from 'hono/http-exception'
44
-
45
- const ALLOWED_MODELS = [
46
- 'anthropic/claude-3.5-sonnet',
47
- 'openai/gpt-4o',
48
- 'google/gemini-pro-1.5',
49
- 'meta-llama/llama-3.1-70b-instruct',
50
- ]
51
-
52
- app.post('/api/chat', async (c) => {
53
- const { messages, model } = await c.req.json()
54
-
55
- if (!ALLOWED_MODELS.includes(model)) {
56
- throw new HTTPException(400, { message: 'Invalid model' })
57
- }
58
-
59
- const result = streamText({
60
- model: openrouter.chat(model),
61
- messages: convertToModelMessages(messages),
62
- })
63
-
64
- return result.toUIMessageStreamResponse()
65
- })
66
- ```
67
-
68
- ---
69
-
70
- ## Cloudflare Workers
71
-
72
- ```typescript
73
- import { createOpenRouter } from '@openrouter/ai-sdk-provider'
74
-
75
- type Bindings = { OPENROUTER_API_KEY: string }
76
-
77
- const app = new Hono<{ Bindings: Bindings }>()
78
-
79
- app.post('/api/chat', async (c) => {
80
- const openrouter = createOpenRouter({
81
- apiKey: c.env.OPENROUTER_API_KEY,
82
- })
83
-
84
- const { messages, model } = await c.req.json()
85
-
86
- const result = streamText({
87
- model: openrouter.chat(model ?? 'anthropic/claude-3.5-sonnet'),
88
- messages: convertToModelMessages(messages),
89
- })
90
-
91
- return result.toUIMessageStreamResponse()
92
- })
93
- ```
94
-
95
- ---
96
-
97
- ## 주요 모델
98
-
99
- | 프로바이더 | 모델 |
100
- |-----------|------|
101
- | Anthropic | `anthropic/claude-3.5-sonnet`, `anthropic/claude-3-opus` |
102
- | OpenAI | `openai/gpt-4o`, `openai/gpt-4-turbo` |
103
- | Google | `google/gemini-pro-1.5` |
104
- | Meta | `meta-llama/llama-3.1-70b-instruct` |
105
-
106
- ---
107
-
108
- ## 관련 문서
109
-
110
- - [AI SDK 개요](./index.md)
111
- - [프로바이더](./providers.md)
@@ -1,102 +0,0 @@
1
- # AI SDK - 프로바이더
2
-
3
- > 다양한 AI 프로바이더 설정
4
-
5
- ---
6
-
7
- ## 설치
8
-
9
- ```bash
10
- npm install @ai-sdk/openai # OpenAI
11
- npm install @ai-sdk/anthropic # Claude
12
- npm install @ai-sdk/google # Gemini
13
- npm install @ai-sdk/mistral # Mistral
14
- npm install @ai-sdk/groq # Groq
15
- ```
16
-
17
- ---
18
-
19
- ## OpenAI
20
-
21
- ```typescript
22
- import { openai } from '@ai-sdk/openai'
23
-
24
- const result = streamText({
25
- model: openai('gpt-4o'),
26
- messages,
27
- })
28
- ```
29
-
30
- ### Cloudflare Workers
31
-
32
- ```typescript
33
- import { createOpenAI } from '@ai-sdk/openai'
34
-
35
- type Bindings = { OPENAI_API_KEY: string }
36
- const app = new Hono<{ Bindings: Bindings }>()
37
-
38
- app.post('/api/chat', async (c) => {
39
- const openai = createOpenAI({ apiKey: c.env.OPENAI_API_KEY })
40
- const result = streamText({ model: openai('gpt-4o'), messages })
41
- return result.toUIMessageStreamResponse()
42
- })
43
- ```
44
-
45
- ### 모델
46
-
47
- | 모델 | 설명 |
48
- |------|------|
49
- | `gpt-4o` | GPT-4 Omni |
50
- | `gpt-4o-mini` | 경량 GPT-4o |
51
- | `o1` | 추론 최적화 |
52
-
53
- ---
54
-
55
- ## Anthropic (Claude)
56
-
57
- ```typescript
58
- import { anthropic } from '@ai-sdk/anthropic'
59
-
60
- const result = streamText({
61
- model: anthropic('claude-3-5-sonnet-latest'),
62
- messages,
63
- })
64
- ```
65
-
66
- ### 모델
67
-
68
- | 모델 | 설명 |
69
- |------|------|
70
- | `claude-3-5-sonnet-latest` | Claude 3.5 Sonnet |
71
- | `claude-3-opus-latest` | Claude 3 Opus |
72
- | `claude-3-haiku-latest` | 경량 모델 |
73
-
74
- ---
75
-
76
- ## Google (Gemini)
77
-
78
- ```typescript
79
- import { google } from '@ai-sdk/google'
80
-
81
- const result = streamText({
82
- model: google('gemini-1.5-pro'),
83
- messages,
84
- })
85
- ```
86
-
87
- ---
88
-
89
- ## 환경 변수
90
-
91
- ```bash
92
- OPENAI_API_KEY=sk-...
93
- ANTHROPIC_API_KEY=sk-ant-...
94
- GOOGLE_GENERATIVE_AI_API_KEY=...
95
- ```
96
-
97
- ---
98
-
99
- ## 관련 문서
100
-
101
- - [AI SDK 개요](./index.md)
102
- - [OpenRouter](./openrouter.md)
@@ -1,146 +0,0 @@
1
- # AI SDK - 텍스트 생성 & 스트리밍
2
-
3
- > generateText, streamText 사용법
4
-
5
- ---
6
-
7
- ## generateText
8
-
9
- 한 번에 텍스트 생성 (비스트리밍).
10
-
11
- ```typescript
12
- import { generateText } from 'ai'
13
- import { openai } from '@ai-sdk/openai'
14
-
15
- app.post('/api/generate', async (c) => {
16
- const { prompt } = await c.req.json()
17
-
18
- const { text, usage, finishReason } = await generateText({
19
- model: openai('gpt-4o'),
20
- prompt,
21
- })
22
-
23
- return c.json({ text, usage, finishReason })
24
- })
25
- ```
26
-
27
- ### 시스템 프롬프트
28
-
29
- ```typescript
30
- const { text } = await generateText({
31
- model: openai('gpt-4o'),
32
- system: 'You are a helpful coding assistant.',
33
- prompt,
34
- })
35
- ```
36
-
37
- ### 메시지 형식
38
-
39
- ```typescript
40
- const { text } = await generateText({
41
- model: openai('gpt-4o'),
42
- messages: [
43
- { role: 'user', content: 'Hello!' },
44
- { role: 'assistant', content: 'Hi!' },
45
- { role: 'user', content: 'How are you?' },
46
- ],
47
- })
48
- ```
49
-
50
- ---
51
-
52
- ## streamText
53
-
54
- 실시간 텍스트 스트리밍.
55
-
56
- ```typescript
57
- import { streamText } from 'ai'
58
-
59
- app.post('/api/stream', async (c) => {
60
- const { prompt } = await c.req.json()
61
-
62
- const result = streamText({
63
- model: openai('gpt-4o'),
64
- prompt,
65
- })
66
-
67
- return result.toUIMessageStreamResponse()
68
- })
69
- ```
70
-
71
- ### 스트림 응답 타입
72
-
73
- ```typescript
74
- // UI 메시지 스트림 (프론트엔드용)
75
- return result.toUIMessageStreamResponse()
76
-
77
- // 텍스트 스트림 (SSE)
78
- return result.toTextStreamResponse()
79
-
80
- // Data 스트림
81
- return result.toDataStreamResponse()
82
- ```
83
-
84
- ### 커스텀 스트림 처리
85
-
86
- ```typescript
87
- import { stream } from 'hono/streaming'
88
-
89
- app.post('/api/custom-stream', async (c) => {
90
- const { prompt } = await c.req.json()
91
-
92
- const result = streamText({
93
- model: openai('gpt-4o'),
94
- prompt,
95
- })
96
-
97
- return stream(c, async (stream) => {
98
- for await (const chunk of result.textStream) {
99
- await stream.write(chunk)
100
- }
101
- })
102
- })
103
- ```
104
-
105
- ---
106
-
107
- ## 옵션
108
-
109
- ```typescript
110
- const result = streamText({
111
- model: openai('gpt-4o'),
112
- prompt,
113
- temperature: 0.7, // 창의성 (0-2)
114
- maxTokens: 1000, // 최대 토큰
115
- topP: 0.9, // 누적 확률
116
- frequencyPenalty: 0, // 반복 페널티
117
- presencePenalty: 0, // 존재 페널티
118
- stopSequences: ['---'], // 중단 시퀀스
119
- })
120
- ```
121
-
122
- ---
123
-
124
- ## 스트림 이벤트
125
-
126
- ```typescript
127
- const result = streamText({
128
- model: openai('gpt-4o'),
129
- prompt,
130
- onChunk: ({ chunk }) => {
131
- console.log('Chunk:', chunk)
132
- },
133
- onFinish: ({ text, usage, finishReason }) => {
134
- console.log('Finished:', text)
135
- console.log('Usage:', usage)
136
- },
137
- })
138
- ```
139
-
140
- ---
141
-
142
- ## 관련 문서
143
-
144
- - [AI SDK 개요](./index.md)
145
- - [도구](./tools.md)
146
- - [구조화된 출력](./structured-output.md)
@@ -1,161 +0,0 @@
1
- # AI SDK - 구조화된 출력
2
-
3
- > Zod 스키마로 타입 안전한 객체 생성
4
-
5
- ---
6
-
7
- ## generateObject
8
-
9
- ```typescript
10
- import { generateObject } from 'ai'
11
- import { openai } from '@ai-sdk/openai'
12
- import { z } from 'zod'
13
-
14
- const userSchema = z.object({
15
- name: z.string(),
16
- age: z.number(),
17
- email: z.email(),
18
- })
19
-
20
- app.post('/api/generate-user', async (c) => {
21
- const { prompt } = await c.req.json()
22
-
23
- const { object } = await generateObject({
24
- model: openai('gpt-4o'),
25
- schema: userSchema,
26
- prompt,
27
- })
28
-
29
- // object: { name: string, age: number, email: string }
30
- return c.json(object)
31
- })
32
- ```
33
-
34
- ---
35
-
36
- ## 복잡한 스키마
37
-
38
- ```typescript
39
- const recipeSchema = z.object({
40
- name: z.string().describe('Recipe name'),
41
- ingredients: z.array(
42
- z.object({
43
- name: z.string(),
44
- amount: z.string(),
45
- unit: z.string().optional(),
46
- })
47
- ),
48
- steps: z.array(z.string()),
49
- prepTime: z.number().describe('Prep time in minutes'),
50
- cookTime: z.number().describe('Cook time in minutes'),
51
- difficulty: z.enum(['easy', 'medium', 'hard']),
52
- })
53
-
54
- app.post('/api/recipe', async (c) => {
55
- const { dish } = await c.req.json()
56
-
57
- const { object } = await generateObject({
58
- model: openai('gpt-4o'),
59
- schema: recipeSchema,
60
- prompt: `Generate a recipe for ${dish}.`,
61
- })
62
-
63
- return c.json(object)
64
- })
65
- ```
66
-
67
- ---
68
-
69
- ## streamObject
70
-
71
- 스트리밍으로 객체 생성.
72
-
73
- ```typescript
74
- import { streamObject } from 'ai'
75
-
76
- app.post('/api/stream-user', async (c) => {
77
- const { prompt } = await c.req.json()
78
-
79
- const result = streamObject({
80
- model: openai('gpt-4o'),
81
- schema: userSchema,
82
- prompt,
83
- })
84
-
85
- return result.toTextStreamResponse()
86
- })
87
- ```
88
-
89
- ### 부분 객체 수신
90
-
91
- ```typescript
92
- const result = streamObject({
93
- model: openai('gpt-4o'),
94
- schema: userSchema,
95
- prompt,
96
- })
97
-
98
- for await (const partialObject of result.partialObjectStream) {
99
- console.log('Partial:', partialObject)
100
- // { name: 'Jo' }
101
- // { name: 'John', age: 25 }
102
- // { name: 'John', age: 25, email: 'john@...' }
103
- }
104
- ```
105
-
106
- ---
107
-
108
- ## 출력 모드
109
-
110
- ```typescript
111
- // Array 모드
112
- const { object } = await generateObject({
113
- model: openai('gpt-4o'),
114
- output: 'array',
115
- schema: z.object({ name: z.string(), role: z.string() }),
116
- prompt: 'List 5 team members.',
117
- })
118
- // object: [{ name: 'Alice', role: 'Engineer' }, ...]
119
-
120
- // Enum 모드
121
- const { object } = await generateObject({
122
- model: openai('gpt-4o'),
123
- output: 'enum',
124
- enum: ['positive', 'negative', 'neutral'],
125
- prompt: 'Classify the sentiment: "I love this product!"',
126
- })
127
- // object: 'positive'
128
- ```
129
-
130
- ---
131
-
132
- ## 에러 처리
133
-
134
- ```typescript
135
- import { NoObjectGeneratedError, InvalidResponseDataError } from 'ai'
136
-
137
- try {
138
- const { object } = await generateObject({
139
- model: openai('gpt-4o'),
140
- schema: userSchema,
141
- prompt,
142
- })
143
- return c.json(object)
144
- } catch (error) {
145
- if (error instanceof NoObjectGeneratedError) {
146
- return c.json({ error: 'Failed to generate object' }, 500)
147
- }
148
- if (error instanceof InvalidResponseDataError) {
149
- return c.json({ error: 'Invalid response format' }, 500)
150
- }
151
- throw error
152
- }
153
- ```
154
-
155
- ---
156
-
157
- ## 관련 문서
158
-
159
- - [AI SDK 개요](./index.md)
160
- - [스트리밍](./streaming.md)
161
- - [도구](./tools.md)
@@ -1,144 +0,0 @@
1
- # AI SDK - Tool Calling
2
-
3
- > AI 모델이 외부 함수를 호출
4
-
5
- ---
6
-
7
- ## 기본 도구 정의
8
-
9
- ```typescript
10
- import { streamText, tool, convertToModelMessages } from 'ai'
11
- import { openai } from '@ai-sdk/openai'
12
- import { z } from 'zod'
13
-
14
- app.post('/api/chat', async (c) => {
15
- const { messages } = await c.req.json()
16
-
17
- const result = streamText({
18
- model: openai('gpt-4o'),
19
- messages: convertToModelMessages(messages),
20
- tools: {
21
- getWeather: tool({
22
- description: 'Get the weather for a location',
23
- inputSchema: z.object({
24
- location: z.string().describe('The city name'),
25
- }),
26
- execute: async ({ location }) => {
27
- return { location, temperature: 22, condition: 'Sunny' }
28
- },
29
- }),
30
- },
31
- })
32
-
33
- return result.toUIMessageStreamResponse()
34
- })
35
- ```
36
-
37
- ---
38
-
39
- ## tool() 구조
40
-
41
- ```typescript
42
- import { tool } from 'ai'
43
- import { z } from 'zod'
44
-
45
- const myTool = tool({
46
- description: 'Tool description for the AI',
47
- inputSchema: z.object({
48
- param1: z.string().describe('Parameter description'),
49
- param2: z.number().optional(),
50
- }),
51
- execute: async (args, context) => {
52
- // args: 스키마에 맞는 입력값
53
- // context: { toolCallId, messages }
54
- return { result: 'success' }
55
- },
56
- })
57
- ```
58
-
59
- ---
60
-
61
- ## 여러 도구
62
-
63
- ```typescript
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(),
88
- }),
89
- execute: async (args) => {
90
- return { sent: true }
91
- },
92
- }),
93
- },
94
- })
95
- ```
96
-
97
- ---
98
-
99
- ## 다단계 도구 호출
100
-
101
- ```typescript
102
- import { generateText } from 'ai'
103
-
104
- const { text, steps } = await generateText({
105
- model: openai('gpt-4o'),
106
- messages: convertToModelMessages(messages),
107
- tools: { ... },
108
- maxSteps: 5, // 최대 도구 호출 횟수
109
- })
110
-
111
- // steps: 각 단계의 도구 호출 정보
112
- ```
113
-
114
- ---
115
-
116
- ## 도구 선택 제어
117
-
118
- ```typescript
119
- const result = streamText({
120
- model: openai('gpt-4o'),
121
- messages,
122
- tools: { ... },
123
-
124
- // 도구 사용 강제
125
- toolChoice: 'required',
126
-
127
- // 특정 도구만
128
- toolChoice: { type: 'tool', toolName: 'getWeather' },
129
-
130
- // 도구 사용 금지
131
- toolChoice: 'none',
132
-
133
- // 자동 (기본)
134
- toolChoice: 'auto',
135
- })
136
- ```
137
-
138
- ---
139
-
140
- ## 관련 문서
141
-
142
- - [AI SDK 개요](./index.md)
143
- - [스트리밍](./streaming.md)
144
- - [구조화된 출력](./structured-output.md)