Repository navigation
Expand file tree
/
Copy pathoutputSchema.ts
More file actions
164 lines (147 loc) · 4.58 KB
/
Copy pathoutputSchema.ts
File metadata and controls
164 lines (147 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/**
* MCP 도구 outputSchema 생성
*/
import * as z from 'zod';
import type { ToolOutputSchema } from './types.js';
const DEFAULT_OUTPUT_SCHEMA = z.object({}).loose().describe('도구 실행 결과(JSON 객체)');
function createFallbackOutputSchema(toolName: string): ToolOutputSchema {
if (toolName.includes('compare')) {
return {
keyword: z.string().optional(),
services: z.array(z.string()).optional(),
serviceCount: z.number().optional(),
resultCount: z.number().optional(),
bestPrice: z.unknown().optional(),
results: z.array(z.unknown()).optional(),
errors: z.array(z.unknown()).optional(),
note: z.string().optional(),
};
}
if (
toolName.includes('search_products') ||
toolName.includes('searchProducts') ||
toolName.endsWith('_products')
) {
return {
keyword: z.string().optional(),
query: z.string().optional(),
page: z.number().optional(),
pageSize: z.number().optional(),
totalCount: z.number().optional(),
count: z.number().optional(),
products: z.array(z.unknown()).optional(),
note: z.string().optional(),
};
}
if (
toolName.includes('find_stores') ||
toolName.includes('nearby_stores') ||
toolName.includes('search_stores')
) {
return {
keyword: z.string().optional(),
searchParams: z.unknown().optional(),
location: z.unknown().optional(),
totalCount: z.number().optional(),
filteredCount: z.number().optional(),
count: z.number().optional(),
stores: z.array(z.unknown()).optional(),
};
}
if (toolName.includes('places')) {
return {
provider: z.string().optional(),
searchMode: z.string().optional(),
query: z.string().optional(),
category: z.string().optional(),
location: z.string().optional(),
totalCount: z.number().optional(),
count: z.number().optional(),
places: z.array(z.unknown()).optional(),
};
}
if (toolName.includes('inventory')) {
return {
productId: z.string().optional(),
keyword: z.string().optional(),
itemCode: z.string().nullable().optional(),
location: z.unknown().optional(),
product: z.unknown().optional(),
onlineStock: z.number().nullable().optional(),
inventory: z.unknown().optional(),
storeInventory: z.unknown().optional(),
};
}
if (toolName.includes('display_location')) {
return {
productId: z.string().optional(),
storeCode: z.string().optional(),
displayLocation: z.unknown().optional(),
locations: z.array(z.unknown()).optional(),
};
}
if (toolName.includes('price_info')) {
return {
productId: z.string().optional(),
productName: z.string().optional(),
product: z.unknown().optional(),
price: z.number().optional(),
};
}
if (toolName.includes('theater')) {
return {
keyword: z.string().nullable().optional(),
location: z.unknown().optional(),
count: z.number().optional(),
theaters: z.array(z.unknown()).optional(),
};
}
if (toolName.includes('movie') || toolName.includes('now_showing')) {
return {
keyword: z.string().optional(),
playDate: z.string().optional(),
theaterCode: z.string().optional(),
count: z.number().optional(),
movies: z.array(z.unknown()).optional(),
};
}
if (toolName.includes('timetable') || toolName.includes('remaining_seats')) {
return {
playDate: z.string().optional(),
theaterCode: z.string().optional(),
movieCode: z.string().optional(),
count: z.number().optional(),
showtimes: z.array(z.unknown()).optional(),
seats: z.array(z.unknown()).optional(),
};
}
if (toolName.includes('popwords')) {
return {
label: z.string().optional(),
keywords: z.array(z.string()).optional(),
count: z.number().optional(),
};
}
if (toolName.includes('catalog')) {
const section = z.object({ totalCount: z.number(), items: z.array(z.unknown()) });
return {
pages: section.optional(),
issues: section.optional(),
exhibitions: section.optional(),
count: z.number().optional(),
};
}
return {};
}
export function createToolOutputSchema(toolName: string, outputSchema?: ToolOutputSchema) {
const schema = outputSchema || createFallbackOutputSchema(toolName);
if (Object.keys(schema).length === 0) {
return DEFAULT_OUTPUT_SCHEMA;
}
return z
.object({
...schema,
standard: z.unknown().optional().describe('서비스 공통 상품/매장/영화관 정규화 결과'),
})
.loose();
}