-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathstructured_output_schemas.ts
More file actions
338 lines (322 loc) · 14.4 KB
/
structured_output_schemas.ts
File metadata and controls
338 lines (322 loc) · 14.4 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/**
* Shared JSON schema definitions for structured output across tools.
* These schemas define the format of structured data returned by various tools.
*/
/**
* Schema for developer information
*/
const developerSchema = {
type: 'object' as const, // Literal type required for MCP SDK type compatibility
properties: {
username: { type: 'string', description: 'Developer username' },
isOfficialApify: { type: 'boolean', description: 'Whether the actor is developed by Apify' },
url: { type: 'string', description: 'Developer profile URL' },
},
required: ['username', 'isOfficialApify', 'url'],
};
/**
* Schema for tiered pricing within an event
*/
const eventTieredPricingSchema = {
type: 'array' as const, // Literal type required for MCP SDK type compatibility
items: {
type: 'object' as const, // Literal type required for MCP SDK type compatibility
properties: {
tier: { type: 'string' },
priceUsd: { type: 'number' },
},
},
};
/**
* Schema for pricing events (PAY_PER_EVENT model)
*/
const pricingEventsSchema = {
type: 'array' as const, // Literal type required for MCP SDK type compatibility
items: {
type: 'object' as const, // Literal type required for MCP SDK type compatibility
properties: {
title: { type: 'string', description: 'Event title' },
description: { type: 'string', description: 'Event description' },
priceUsd: { type: 'number', description: 'Price in USD' },
tieredPricing: eventTieredPricingSchema,
},
},
description: 'Event-based pricing information',
};
/**
* Schema for tiered pricing (general)
*/
const tieredPricingSchema = {
type: 'array' as const, // Literal type required for MCP SDK type compatibility
items: {
type: 'object' as const, // Literal type required for MCP SDK type compatibility
properties: {
tier: { type: 'string', description: 'Tier name' },
pricePerUnit: { type: 'number', description: 'Price per unit for this tier' },
},
},
description: 'Tiered pricing information',
};
/**
* Schema for pricing information
*/
export const pricingSchema = {
type: 'object' as const, // Literal type required for MCP SDK type compatibility
properties: {
model: {
type: 'string',
description: 'Pricing model (FREE, PRICE_PER_DATASET_ITEM, FLAT_PRICE_PER_MONTH, PAY_PER_EVENT)',
},
userTier: {
type: 'string',
enum: ['FREE', 'BRONZE', 'SILVER', 'GOLD', 'PLATINUM', 'DIAMOND'],
description: "The user's plan tier used to resolve pricing (always the user's tier, even if a different tier was used as fallback)",
},
pricePerUnit: { type: 'number', description: 'Price per unit (for non-free models)' },
unitName: { type: 'string', description: 'Unit name for pricing' },
trialMinutes: { type: 'number', description: 'Trial period in minutes' },
tieredPricing: tieredPricingSchema,
events: pricingEventsSchema,
pricingNote: { type: 'string', description: 'Note about additional pricing tiers available via fetch-actor-details' },
eventDescriptionsOmitted: {
type: 'boolean',
description: 'Whether event descriptions were omitted because the actor has many pricing events',
},
eventDescriptionsNote: {
type: 'string',
description: 'Note explaining that event descriptions were omitted and full details are available via fetch-actor-details',
},
},
required: ['model'],
};
/**
* Schema for Actor statistics
*/
export const statsSchema = {
type: 'object' as const, // Literal type required for MCP SDK type compatibility
properties: {
totalUsers: { type: 'number', description: 'Total users' },
monthlyUsers: { type: 'number', description: 'Monthly active users' },
successRate: { type: 'number', description: 'Success rate percentage' },
bookmarks: { type: 'number', description: 'Number of bookmarks' },
},
};
/**
* Schema for Actor information (card)
* Used in both search results and detailed Actor info
*/
export const actorInfoSchema = {
type: 'object' as const, // Literal type required for MCP SDK type compatibility
properties: {
title: { type: 'string', description: 'Actor title' },
url: { type: 'string', description: 'Actor URL' },
id: { type: 'string', description: 'Actor ID' },
fullName: { type: 'string', description: 'Full Actor name (username/name)' },
developer: developerSchema,
description: { type: 'string', description: 'Actor description' },
categories: {
type: 'array' as const, // Literal type required for MCP SDK type compatibility
items: { type: 'string' },
description: 'Actor categories',
},
pricing: pricingSchema,
stats: statsSchema,
rating: {
type: 'object' as const, // Literal type required for MCP SDK type compatibility
properties: {
average: { type: 'number', description: 'Average rating' },
count: { type: 'number', description: 'Number of ratings' },
},
},
modifiedAt: { type: 'string', description: 'Last modification date' },
isDeprecated: { type: 'boolean', description: 'Whether the Actor is deprecated' },
},
required: ['url', 'id', 'fullName', 'developer', 'description', 'categories', 'pricing', 'isDeprecated'],
};
/**
* Schema for Actor details output (fetch-actor-details tool)
* All fields are optional since the tool supports selective output via the 'output' parameter
*
* NOTE on `readme`: This field contains the abridged README summary when the Actor has one,
* falling back to the full README otherwise. The field is named `readme` (not `readmeSummary`)
* to stay consistent with the widget UI contract. Most Actors should have a summary defined,
* so the full README fallback is only expected in niche cases.
*/
export const actorDetailsOutputSchema = {
type: 'object' as const, // Literal type required for MCP SDK type compatibility
properties: {
actorInfo: actorInfoSchema,
readme: { type: 'string', description: 'Actor README summary when available, otherwise the full README documentation.' },
inputSchema: { type: 'object' as const, description: 'Actor input schema.' }, // Literal type required for MCP SDK type compatibility
outputSchema: { type: 'object' as const, description: 'Output schema inferred from successful runs.' },
},
};
/**
* Schema for search results output (store-search tool)
*/
export const actorSearchOutputSchema = {
type: 'object' as const, // Literal type required for MCP SDK type compatibility
properties: {
actors: {
type: 'array' as const, // Literal type required for MCP SDK type compatibility
items: actorInfoSchema,
description: 'List of Actor cards matching the search query',
},
query: { type: 'string', description: 'The search query used' },
count: { type: 'number', description: 'Number of Actors returned' },
instructions: { type: 'string', description: 'Additional instructions for the LLM to follow when processing the search results.' },
},
required: ['actors', 'query', 'count'],
};
/**
* Schema for internal search results (search-actors-internal tool)
*/
export const actorSearchInternalOutputSchema = {
type: 'object' as const,
properties: {
actors: {
type: 'array' as const,
items: {
type: 'object' as const,
properties: {
fullName: { type: 'string', description: 'Full Actor name (username/name)' },
title: { type: 'string', description: 'Actor title' },
description: { type: 'string', description: 'Actor description' },
},
required: ['fullName'],
},
},
query: { type: 'string', description: 'The search query used' },
count: { type: 'number', description: 'Number of Actors returned' },
},
required: ['actors', 'query', 'count'],
};
export const searchApifyDocsToolOutputSchema = {
type: 'object' as const, // Literal type required for MCP SDK type compatibility
properties: {
results: {
type: 'array' as const, // Literal type required for MCP SDK type compatibility
items: {
type: 'object' as const, // Literal type required for MCP SDK type compatibility
properties: {
url: { type: 'string', description: 'URL of the documentation page, may include anchor (e.g., #section-name).' },
content: { type: 'string', description: 'A limited piece of content that matches the search query.' },
},
required: ['url'],
},
},
instructions: { type: 'string', description: 'Additional instructions for the LLM to follow when processing the search results.' },
},
required: ['results'],
};
export const fetchApifyDocsToolOutputSchema = {
type: 'object' as const, // Literal type required for MCP SDK type compatibility
properties: {
url: { type: 'string', description: 'The documentation URL that was fetched' },
content: { type: 'string', description: 'The full markdown content of the documentation page' },
},
required: ['url', 'content'],
};
/**
* Schema for call-actor and direct actor tool outputs.
* Contains Actor run metadata and dataset items (sync mode only).
* In async mode, only runId is present.
*/
export const callActorOutputSchema = {
type: 'object' as const,
properties: {
runId: { type: 'string', description: 'Actor run ID' },
actorName: { type: 'string', description: 'Name of the Actor (only in async mode)' },
status: { type: 'string', description: 'Run status (only in async mode) - READY, RUNNING, SUCCEEDED, FAILED, ABORTING, ABORTED, TIMED-OUT' },
startedAt: { type: 'string', description: 'ISO timestamp when the run started (only in async mode)' },
input: { type: 'object' as const, description: 'Input parameters passed to the Actor (only in async mode)' },
datasetId: { type: 'string', description: 'Dataset ID containing the full results (sync mode only)' },
totalItemCount: { type: 'number', description: 'Total number of items in the dataset (sync mode only)' },
items: {
type: 'array' as const,
items: { type: 'object' as const },
description: 'Dataset items from the Actor run (sync mode only, may be truncated due to size limits)',
},
instructions: { type: 'string', description: 'Instructions for the LLM on how to process or retrieve additional data' },
},
required: ['runId'],
};
/**
* Schema for get-actor-run tool output.
* Contains full run information including status, timestamps, stats, and dataset preview.
*/
export const getActorRunOutputSchema = {
type: 'object' as const,
properties: {
runId: { type: 'string', description: 'Actor run ID' },
actorName: { type: 'string', description: 'Name of the Actor' },
status: { type: 'string', description: 'Run status (READY, RUNNING, SUCCEEDED, FAILED, ABORTING, ABORTED, TIMED-OUT)' },
startedAt: { type: 'string', description: 'ISO timestamp when the run started' },
finishedAt: { type: 'string', description: 'ISO timestamp when the run finished (only for completed runs)' },
stats: {
type: 'object' as const,
description: 'Run statistics (compute units, memory, duration, etc.)',
},
dataset: {
type: 'object' as const,
description: 'Dataset information (only for completed runs with results)',
properties: {
datasetId: { type: 'string', description: 'Default dataset ID' },
totalItemCount: { type: 'number', description: 'Total number of items in dataset' },
previewItemCount: { type: 'number', description: 'Number of preview items returned' },
schema: { type: 'object' as const, description: 'Auto-generated JSON schema from dataset items' },
previewItems: {
type: 'array' as const,
items: { type: 'object' as const },
description: 'Preview of first 5 dataset items',
},
},
required: ['datasetId', 'totalItemCount', 'previewItemCount', 'schema', 'previewItems'],
},
},
required: ['runId', 'status', 'startedAt'],
};
/**
* Schema for dataset items retrieval tools (get-actor-output, get-dataset-items).
* Contains dataset items with pagination and count information.
*/
export const datasetItemsOutputSchema = {
type: 'object' as const,
properties: {
datasetId: { type: 'string', description: 'Dataset ID' },
items: { type: 'array' as const,
items: { type: 'object' as const },
description: 'Dataset items' },
itemCount: { type: 'number', description: 'Number of items returned' },
totalItemCount: { type: 'number', description: 'Total items in dataset' },
offset: { type: 'number', description: 'Offset used for pagination' },
limit: { type: 'number', description: 'Limit used for pagination' },
},
required: ['datasetId', 'items', 'itemCount'],
};
/**
* Creates an enriched version of callActorOutputSchema where the `items` field
* contains actual property definitions inferred from Actor run history.
*
* @param itemProperties - JSON Schema properties object describing dataset item fields
* (e.g., `{ url: { type: 'string' }, price: { type: 'number' } }`)
* @returns A copy of callActorOutputSchema with enriched items schema
*/
export function buildEnrichedCallActorOutputSchema(
itemProperties: Record<string, unknown>,
): typeof callActorOutputSchema {
return {
...callActorOutputSchema,
properties: {
...callActorOutputSchema.properties,
items: {
type: 'array' as const,
items: {
type: 'object' as const,
properties: itemProperties,
} as unknown as { type: 'object' },
description: callActorOutputSchema.properties.items.description,
},
},
};
}