Skip to content

Commit e3af744

Browse files
committed
fix: implement code review feedback
1 parent 04f4ac2 commit e3af744

File tree

4 files changed

+19
-25
lines changed

4 files changed

+19
-25
lines changed

src/stdio.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ Note: Tools that enable you to search Actors from the Apify Store and get their
8383
.option('full-actor-schema', {
8484
type: 'boolean',
8585
default: false,
86-
describe: 'Enable full Actor schema for all Actors.',
86+
describe: 'Default behavior keeps tools simple: advanced inputs are grouped under "advancedInput" and their schema is not expanded in the tools list. '
87+
+ 'This reduces context size and makes tools easier to use. Use the "get-actor-details" tool to view the complete input schema and documentation. '
88+
+ 'Enable this option to disable the simplification and expose the full Actor input schema with all parameters at the top level.',
8789
})
8890
.help('help')
8991
.alias('h', 'help')

src/tools/actor.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { ApifyClient } from '../apify-client.js';
1010
import {
1111
ACTOR_ADDITIONAL_INSTRUCTIONS,
1212
ACTOR_MAX_MEMORY_MBYTES,
13-
ACTOR_README_MAX_LENGTH,
1413
ADVANCED_INPUT_KEY,
1514
HelperTools,
1615
} from '../const.js';
@@ -62,6 +61,7 @@ export async function callActorGetDataset(
6261
progressTracker?: ProgressTracker | null,
6362
): Promise<CallActorGetDatasetResult> {
6463
let input = simplifiedInput;
64+
// Moves the advances input properties into the root object
6565
if (input[ADVANCED_INPUT_KEY]) {
6666
const { [ADVANCED_INPUT_KEY]: advancedInput, ...rest } = input;
6767
input = { ...advancedInput, ...rest };
@@ -220,28 +220,24 @@ export async function getActorsAsTools(
220220

221221
const actorsInfo: (ActorInfo | null)[] = await Promise.all(
222222
actorIdsOrNames.map(async (actorIdOrName) => {
223-
// Always cache the full schema version under a stable key
224-
const cacheKey = actorIdOrName;
225-
let actorDefinition = actorDefinitionPrunedCache.get(cacheKey);
226-
if (!actorDefinition) {
227-
actorDefinition = await getActorDefinition(
228-
actorIdOrName,
229-
apifyToken,
230-
ACTOR_README_MAX_LENGTH,
231-
);
223+
const actorDefinitionPrunedCached = actorDefinitionPrunedCache.get(actorIdOrName);
224+
if (actorDefinitionPrunedCached) {
225+
return {
226+
actorDefinitionPruned: actorDefinitionPrunedCached,
227+
webServerMcpPath: getActorMCPServerPath(actorDefinitionPrunedCached),
228+
229+
} as ActorInfo;
232230
}
233231

234232
const actorDefinitionPruned = await getActorDefinition(actorIdOrName, apifyToken);
235233
if (!actorDefinitionPruned) {
236234
log.error('Actor not found or definition is not available', { actorName: actorIdOrName });
237235
return null;
238236
}
239-
240-
// Cache canonical full schema without mutation
241-
actorDefinitionPrunedCache.set(cacheKey, actorDefinitionPruned);
242-
237+
// Cache the pruned Actor definition
238+
actorDefinitionPrunedCache.set(actorIdOrName, actorDefinitionPruned);
243239
return {
244-
actorDefinitionPruned: actorDefinition,
240+
actorDefinitionPruned,
245241
webServerMcpPath: getActorMCPServerPath(actorDefinitionPruned),
246242
} as ActorInfo;
247243
}),

src/types.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,6 @@ export type ToolEntry =
164164
tool: ActorMcpTool;
165165
};
166166

167-
/**
168-
* Type discriminator for tools - indicates whether a tool is internal or Actor-based.
169-
*/
170-
export type ToolType = ToolEntry['type'];
171-
172167
/**
173168
* Price for a single event in a specific tier.
174169
*/

src/utils/tools.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ export function getToolPublicFieldOnly(tool: ToolBase) {
99
return {
1010
name: tool.name,
1111
description: tool.description,
12-
inputSchema: simplifiedSchema(tool.inputSchema as IActorInputSchema),
12+
inputSchema: clearAdvancedInputProperties(tool.inputSchema as IActorInputSchema),
1313
};
1414
}
1515

16-
function simplifiedSchema(schema: IActorInputSchema): IActorInputSchema {
17-
if (schema.properties && 'advancedInputs' in schema.properties) {
16+
/** Removes properties under ADVANCED_INPUT_KEY from the schema */
17+
function clearAdvancedInputProperties(schema: IActorInputSchema): IActorInputSchema {
18+
if (schema.properties && ADVANCED_INPUT_KEY in schema.properties) {
1819
return {
1920
...schema,
2021
properties: {
2122
...schema.properties,
2223
[ADVANCED_INPUT_KEY]: {
23-
...schema.properties.advancedInputs,
24+
...schema.properties[ADVANCED_INPUT_KEY],
2425
properties: {},
2526
additionalProperties: true,
2627
},

0 commit comments

Comments
 (0)