@apify/actors-mcp-server 0.10.5-beta.6 → 0.10.5-beta.7
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.
- package/dist/mcp/server.d.ts +0 -2
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +12 -20
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/utils.d.ts +1 -1
- package/dist/mcp/utils.js +1 -1
- package/dist/tools/actor_executor.d.ts +10 -0
- package/dist/tools/actor_executor.d.ts.map +1 -0
- package/dist/tools/actor_executor.js +79 -0
- package/dist/tools/actor_executor.js.map +1 -0
- package/dist/tools/apps/call_actor.d.ts +0 -1
- package/dist/tools/apps/call_actor.d.ts.map +1 -1
- package/dist/tools/apps/call_actor.js +8 -54
- package/dist/tools/apps/call_actor.js.map +1 -1
- package/dist/tools/apps/call_actor_widget.d.ts.map +1 -1
- package/dist/tools/apps/call_actor_widget.js +8 -52
- package/dist/tools/apps/call_actor_widget.js.map +1 -1
- package/dist/tools/apps/get_actor_run_widget.d.ts.map +1 -1
- package/dist/tools/apps/get_actor_run_widget.js +15 -9
- package/dist/tools/apps/get_actor_run_widget.js.map +1 -1
- package/dist/tools/categories.d.ts +6 -0
- package/dist/tools/categories.d.ts.map +1 -1
- package/dist/tools/categories.js +7 -1
- package/dist/tools/categories.js.map +1 -1
- package/dist/tools/core/actor_run_response.d.ts +127 -0
- package/dist/tools/core/actor_run_response.d.ts.map +1 -0
- package/dist/tools/core/actor_run_response.js +551 -0
- package/dist/tools/core/actor_run_response.js.map +1 -0
- package/dist/tools/core/actor_tools_factory.d.ts +8 -3
- package/dist/tools/core/actor_tools_factory.d.ts.map +1 -1
- package/dist/tools/core/actor_tools_factory.js +40 -11
- package/dist/tools/core/actor_tools_factory.js.map +1 -1
- package/dist/tools/core/call_actor_common.d.ts +16 -39
- package/dist/tools/core/call_actor_common.d.ts.map +1 -1
- package/dist/tools/core/call_actor_common.js +171 -140
- package/dist/tools/core/call_actor_common.js.map +1 -1
- package/dist/tools/core/get_actor_run_common.d.ts +10 -49
- package/dist/tools/core/get_actor_run_common.d.ts.map +1 -1
- package/dist/tools/core/get_actor_run_common.js +51 -86
- package/dist/tools/core/get_actor_run_common.js.map +1 -1
- package/dist/tools/default/call_actor.d.ts +0 -2
- package/dist/tools/default/call_actor.d.ts.map +1 -1
- package/dist/tools/default/call_actor.js +5 -85
- package/dist/tools/default/call_actor.js.map +1 -1
- package/dist/tools/default/get_actor_run.d.ts +1 -2
- package/dist/tools/default/get_actor_run.d.ts.map +1 -1
- package/dist/tools/default/get_actor_run.js +12 -6
- package/dist/tools/default/get_actor_run.js.map +1 -1
- package/dist/tools/index.d.ts +1 -2
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +1 -2
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/structured_output_schemas.d.ts +254 -51
- package/dist/tools/structured_output_schemas.d.ts.map +1 -1
- package/dist/tools/structured_output_schemas.js +124 -68
- package/dist/tools/structured_output_schemas.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +20 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/progress.d.ts +1 -0
- package/dist/utils/progress.d.ts.map +1 -1
- package/dist/utils/progress.js +1 -1
- package/dist/utils/progress.js.map +1 -1
- package/dist/utils/server-instructions/index.d.ts.map +1 -1
- package/dist/utils/server-instructions/index.js +6 -7
- package/dist/utils/server-instructions/index.js.map +1 -1
- package/dist/utils/tools_loader.d.ts.map +1 -1
- package/dist/utils/tools_loader.js +9 -3
- package/dist/utils/tools_loader.js.map +1 -1
- package/dist/web/dist/actor-detail-widget.js +3 -0
- package/dist/web/dist/actor-run-widget.js +219 -216
- package/dist/web/dist/search-actors-widget.js +3 -0
- package/package.json +1 -1
- package/dist/tools/apps/actor_executor.d.ts +0 -8
- package/dist/tools/apps/actor_executor.d.ts.map +0 -1
- package/dist/tools/apps/actor_executor.js +0 -29
- package/dist/tools/apps/actor_executor.js.map +0 -1
- package/dist/tools/core/actor_execution.d.ts +0 -39
- package/dist/tools/core/actor_execution.d.ts.map +0 -1
- package/dist/tools/core/actor_execution.js +0 -135
- package/dist/tools/core/actor_execution.js.map +0 -1
- package/dist/tools/core/actor_response.d.ts +0 -37
- package/dist/tools/core/actor_response.d.ts.map +0 -1
- package/dist/tools/core/actor_response.js +0 -94
- package/dist/tools/core/actor_response.js.map +0 -1
- package/dist/tools/default/actor_executor.d.ts +0 -7
- package/dist/tools/default/actor_executor.d.ts.map +0 -1
- package/dist/tools/default/actor_executor.js +0 -31
- package/dist/tools/default/actor_executor.js.map +0 -1
|
@@ -7,11 +7,31 @@ import { actorDefinitionPrunedCache } from '../../state.js';
|
|
|
7
7
|
import { ajv } from '../../utils/ajv.js';
|
|
8
8
|
import { logHttpError } from '../../utils/logging.js';
|
|
9
9
|
import { getActorDefinition } from '../build.js';
|
|
10
|
-
import {
|
|
10
|
+
import { buildEnrichedDirectActorOutputSchema, getActorRunOutputSchema } from '../structured_output_schemas.js';
|
|
11
11
|
import { actorNameToToolName, buildActorInputSchema, fixedAjvCompile, isActorInfoMcpServer } from '../utils.js';
|
|
12
|
+
import { CALL_ACTOR_WAIT_SECS_DEFAULT, WAIT_SECS_MAX } from './actor_run_response.js';
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
14
|
+
* MCP-only opt-in injected next to the Actor's own input fields. Same contract as `call-actor`'s
|
|
15
|
+
* `waitSecs`: default 30, max 45. If the Actor's own input schema happens to declare `waitSecs`,
|
|
16
|
+
* this property overrides it — the field is reserved for the MCP server's wait control.
|
|
17
|
+
*/
|
|
18
|
+
const WAIT_SECS_INPUT_PROPERTY = {
|
|
19
|
+
type: 'integer',
|
|
20
|
+
minimum: 0,
|
|
21
|
+
maximum: WAIT_SECS_MAX,
|
|
22
|
+
default: CALL_ACTOR_WAIT_SECS_DEFAULT,
|
|
23
|
+
description: `Max seconds (0–45, default ${CALL_ACTOR_WAIT_SECS_DEFAULT}) to cap the wait for the Actor run to reach terminal state. `
|
|
24
|
+
+ 'For long-running Actors the response returns at the cap with the current run status; '
|
|
25
|
+
+ `follow \`nextStep\` to poll via ${HelperTools.ACTOR_RUNS_GET}. Set to 0 to fire-and-forget.`,
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* For each direct actor tool with a known historical item schema, replaces the generic
|
|
29
|
+
* `getActorRunOutputSchema` with a per-tool variant that declares
|
|
30
|
+
* `storages.datasets.default.itemsSchema` — letting an LLM plan field projection from
|
|
31
|
+
* `tools/list` alone, before any call.
|
|
32
|
+
*
|
|
33
|
+
* Uses `Promise.allSettled` so a single store failure doesn't block other tools. Individual
|
|
34
|
+
* misses (null / empty properties / thrown errors) leave the tool on the generic schema.
|
|
15
35
|
*/
|
|
16
36
|
export async function enrichActorToolOutputSchemas(tools, actorStore) {
|
|
17
37
|
const enrichPromises = tools
|
|
@@ -21,13 +41,17 @@ export async function enrichActorToolOutputSchemas(tools, actorStore) {
|
|
|
21
41
|
const itemProperties = await actorStore.getActorOutputSchema(tool.actorFullName);
|
|
22
42
|
if (itemProperties && Object.keys(itemProperties).length > 0) {
|
|
23
43
|
// eslint-disable-next-line no-param-reassign
|
|
24
|
-
tool.outputSchema =
|
|
44
|
+
tool.outputSchema = buildEnrichedDirectActorOutputSchema(itemProperties);
|
|
45
|
+
// Stash the raw properties so the executor can mirror them into
|
|
46
|
+
// `structuredContent.storages.datasets.default.itemsSchema` at runtime.
|
|
47
|
+
// eslint-disable-next-line no-param-reassign
|
|
48
|
+
tool.datasetItemsSchema = itemProperties;
|
|
25
49
|
}
|
|
26
50
|
}
|
|
27
51
|
catch (error) {
|
|
28
52
|
log.debug('Failed to enrich output schema for Actor', {
|
|
29
53
|
actorName: tool.actorFullName,
|
|
30
|
-
|
|
54
|
+
errMessage: error instanceof Error ? error.message : String(error),
|
|
31
55
|
});
|
|
32
56
|
}
|
|
33
57
|
});
|
|
@@ -51,11 +75,11 @@ export async function enrichActorToolOutputSchemas(tools, actorStore) {
|
|
|
51
75
|
* 5. Enums are added to descriptions with examples using addEnumsToDescriptionsWithExamples()
|
|
52
76
|
*
|
|
53
77
|
* @param {ActorInfo[]} actorsInfo - An array of ActorInfo objects with webServerMcpPath, definition, and Actor.
|
|
54
|
-
* @param options - Optional settings: mcpSessionId for telemetry correlation, actorStore for
|
|
78
|
+
* @param options - Optional settings: mcpSessionId for telemetry correlation, actorStore for per-Actor itemsSchema enrichment.
|
|
55
79
|
* @returns {Promise<ToolEntry[]>} - A promise that resolves to an array of MCP tools.
|
|
56
80
|
*/
|
|
57
81
|
export async function getNormalActorsAsTools(actorsInfo, options) {
|
|
58
|
-
var _a;
|
|
82
|
+
var _a, _b;
|
|
59
83
|
const { mcpSessionId, actorStore } = options !== null && options !== void 0 ? options : {};
|
|
60
84
|
const tools = [];
|
|
61
85
|
for (const actorInfo of actorsInfo) {
|
|
@@ -64,13 +88,19 @@ export async function getNormalActorsAsTools(actorsInfo, options) {
|
|
|
64
88
|
continue;
|
|
65
89
|
const isRag = definition.actorFullName === RAG_WEB_BROWSER;
|
|
66
90
|
const { inputSchema } = buildActorInputSchema(definition.actorFullName, definition.input, isRag);
|
|
91
|
+
// Inject the MCP-only `waitSecs` opt-in before AJV compile so the LLM can cap the wait.
|
|
92
|
+
const inputSchemaWithWaitSecs = inputSchema;
|
|
93
|
+
inputSchemaWithWaitSecs.properties = {
|
|
94
|
+
...((_a = inputSchemaWithWaitSecs.properties) !== null && _a !== void 0 ? _a : {}),
|
|
95
|
+
waitSecs: WAIT_SECS_INPUT_PROPERTY,
|
|
96
|
+
};
|
|
67
97
|
let description = `This tool calls the Actor "${definition.actorFullName}" and retrieves its output results.
|
|
68
98
|
Use this tool instead of the "${HelperTools.ACTOR_CALL}" if user requests this specific Actor.
|
|
69
99
|
Actor description: ${definition.description}`;
|
|
70
100
|
if (isRag) {
|
|
71
101
|
description += RAG_WEB_BROWSER_ADDITIONAL_DESC;
|
|
72
102
|
}
|
|
73
|
-
const memoryMbytes = Math.min(((
|
|
103
|
+
const memoryMbytes = Math.min(((_b = definition.defaultRunOptions) === null || _b === void 0 ? void 0 : _b.memoryMbytes) || ACTOR_MAX_MEMORY_MBYTES, ACTOR_MAX_MEMORY_MBYTES);
|
|
74
104
|
let ajvValidate;
|
|
75
105
|
try {
|
|
76
106
|
// Unknown properties are silently stripped by AJV's removeAdditional option.
|
|
@@ -93,8 +123,8 @@ Actor description: ${definition.description}`;
|
|
|
93
123
|
actorFullName: definition.actorFullName,
|
|
94
124
|
description,
|
|
95
125
|
inputSchema: inputSchema,
|
|
96
|
-
//
|
|
97
|
-
outputSchema:
|
|
126
|
+
// Canonical RunResponse shape — same as call-actor and get-actor-run.
|
|
127
|
+
outputSchema: getActorRunOutputSchema,
|
|
98
128
|
ajvValidate,
|
|
99
129
|
paymentRequired: true,
|
|
100
130
|
memoryMbytes,
|
|
@@ -113,7 +143,6 @@ Actor description: ${definition.description}`;
|
|
|
113
143
|
},
|
|
114
144
|
});
|
|
115
145
|
}
|
|
116
|
-
// Enrich output schemas with field-level detail if actorStore is available
|
|
117
146
|
if (actorStore) {
|
|
118
147
|
await enrichActorToolOutputSchemas(tools, actorStore);
|
|
119
148
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actor_tools_factory.js","sourceRoot":"","sources":["../../../src/tools/core/actor_tools_factory.ts"],"names":[],"mappings":"AAEA,OAAO,GAAG,MAAM,YAAY,CAAC;AAG7B,OAAO,EACH,uBAAuB,EACvB,WAAW,EACX,eAAe,EACf,+BAA+B,GAClC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,0BAA0B,EAAE,M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/C,CAAC"}
|
|
@@ -11,56 +11,31 @@ export declare const CALL_ACTOR_MCP_SERVER_SECTION = "For MCP server Actors:\n-
|
|
|
11
11
|
export declare const CALL_ACTOR_USAGE_SECTION: string;
|
|
12
12
|
/** Shared examples section — identical in both modes. */
|
|
13
13
|
export declare const CALL_ACTOR_EXAMPLES_SECTION = "EXAMPLES:\n- user_input: Get instagram posts using apify/instagram-scraper";
|
|
14
|
-
type CallActorDescriptionParams = {
|
|
15
|
-
actorGetDetailsTool: HelperTools.ACTOR_GET_DETAILS;
|
|
16
|
-
alwaysAsync: boolean;
|
|
17
|
-
};
|
|
18
|
-
type StartedActorRun = {
|
|
19
|
-
id: string;
|
|
20
|
-
status: string;
|
|
21
|
-
startedAt?: Date;
|
|
22
|
-
};
|
|
23
|
-
type StartAsyncResponseResult = {
|
|
24
|
-
content: {
|
|
25
|
-
type: 'text';
|
|
26
|
-
text: string;
|
|
27
|
-
}[];
|
|
28
|
-
structuredContent: {
|
|
29
|
-
runId: string;
|
|
30
|
-
actorName: string;
|
|
31
|
-
status: string;
|
|
32
|
-
startedAt: string;
|
|
33
|
-
input: Record<string, unknown>;
|
|
34
|
-
};
|
|
35
|
-
_meta?: Record<string, unknown>;
|
|
36
|
-
};
|
|
37
14
|
type CallActorErrorResponseParams = {
|
|
38
15
|
actorName: string;
|
|
39
16
|
error: unknown;
|
|
40
17
|
actorId?: string;
|
|
41
|
-
isAsync: boolean;
|
|
42
18
|
mcpSessionId?: string;
|
|
43
19
|
actorGetDetailsTool: HelperTools.ACTOR_GET_DETAILS;
|
|
44
20
|
};
|
|
45
|
-
export declare function buildCallActorDescription(
|
|
46
|
-
export declare function
|
|
47
|
-
actorName: string;
|
|
48
|
-
actorRun: StartedActorRun;
|
|
49
|
-
input: Record<string, unknown>;
|
|
50
|
-
widget: boolean;
|
|
51
|
-
}): StartAsyncResponseResult;
|
|
21
|
+
export declare function buildCallActorDescription(): string;
|
|
22
|
+
export declare function buildCallActorAppsDescription(): string;
|
|
52
23
|
export declare function isPermissionApprovalError(error: unknown): error is ApifyApiError;
|
|
53
24
|
/** Exported for native actor tool error handling in server.ts — no logging, no telemetry. */
|
|
54
25
|
export declare function buildPermissionApprovalResponse(error: ApifyApiError): ReturnType<typeof buildMCPResponse>;
|
|
55
26
|
export declare function buildCallActorErrorResponse(params: CallActorErrorResponseParams): ReturnType<typeof buildMCPResponse>;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
27
|
+
export declare const callOptionsSchema: z.ZodObject<{
|
|
28
|
+
memory: z.ZodOptional<z.ZodNumber>;
|
|
29
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
30
|
+
build: z.ZodOptional<z.ZodString>;
|
|
31
|
+
maxItems: z.ZodOptional<z.ZodNumber>;
|
|
32
|
+
maxTotalChargeUsd: z.ZodOptional<z.ZodNumber>;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
/** Zod schema for call-actor arguments — shared between default and apps variants. */
|
|
59
35
|
export declare const callActorArgs: z.ZodObject<{
|
|
60
36
|
actor: z.ZodString;
|
|
61
37
|
input: z.ZodObject<{}, z.core.$loose>;
|
|
62
|
-
|
|
63
|
-
previewOutput: z.ZodOptional<z.ZodBoolean>;
|
|
38
|
+
waitSecs: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
64
39
|
callOptions: z.ZodOptional<z.ZodObject<{
|
|
65
40
|
memory: z.ZodOptional<z.ZodNumber>;
|
|
66
41
|
timeout: z.ZodOptional<z.ZodNumber>;
|
|
@@ -69,9 +44,6 @@ export declare const callActorArgs: z.ZodObject<{
|
|
|
69
44
|
maxTotalChargeUsd: z.ZodOptional<z.ZodNumber>;
|
|
70
45
|
}, z.core.$strip>>;
|
|
71
46
|
}, z.core.$strip>;
|
|
72
|
-
/**
|
|
73
|
-
* Compiled AJV input schema — shared between both variants.
|
|
74
|
-
*/
|
|
75
47
|
export declare const callActorInputSchema: ToolInputSchema;
|
|
76
48
|
export declare const callActorAjvValidate: import("ajv").ValidateFunction<unknown>;
|
|
77
49
|
/**
|
|
@@ -134,5 +106,10 @@ export declare function callActorPreExecute(toolArgs: InternalToolArgs, options:
|
|
|
134
106
|
baseActorName: string;
|
|
135
107
|
mcpToolName: string | undefined;
|
|
136
108
|
}>;
|
|
109
|
+
/**
|
|
110
|
+
* Shared start-then-wait flow for call-actor variants (default + apps).
|
|
111
|
+
* `taskMode` is honored — when true, `waitSecs` is ignored and the SDK waits until terminal.
|
|
112
|
+
*/
|
|
113
|
+
export declare function executeCallActor(toolArgs: InternalToolArgs): Promise<object>;
|
|
137
114
|
export {};
|
|
138
115
|
//# sourceMappingURL=call_actor_common.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call_actor_common.d.ts","sourceRoot":"","sources":["../../../src/tools/core/call_actor_common.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,OAAO,EAIH,WAAW,EAEd,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"call_actor_common.d.ts","sourceRoot":"","sources":["../../../src/tools/core/call_actor_common.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,OAAO,EAIH,WAAW,EAEd,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAIxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAKtD,OAAO,EAA2B,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AASrF,eAAO,MAAM,oCAAoC,2JAAuJ,CAAC;AAEzM,gEAAgE;AAChE,eAAO,MAAM,6BAA6B,+MAEmD,CAAC;AAE9F,0EAA0E;AAC1E,eAAO,MAAM,wB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from '../../const.js';
|
|
7
7
|
import { connectMCPClient } from '../../mcp/client.js';
|
|
8
|
-
import { getWidgetConfig, WIDGET_URIS } from '../../resources/widgets.js';
|
|
9
8
|
import { getActorMcpUrlCached } from '../../utils/actor.js';
|
|
10
9
|
import { compileSchema } from '../../utils/ajv.js';
|
|
11
10
|
import { getHttpStatusCode, logHttpError } from '../../utils/logging.js';
|
|
@@ -13,7 +12,9 @@ import { buildMCPResponse } from '../../utils/mcp.js';
|
|
|
13
12
|
import { classifyFailureCategory, extractAjvErrorDetails, getToolStatusFromError } from '../../utils/tool_status.js';
|
|
14
13
|
import { extractActorId } from '../../utils/tools.js';
|
|
15
14
|
import { actorNameToToolName } from '../utils.js';
|
|
15
|
+
import { abortRunOnSignal, buildStartRunResponse, CALL_ACTOR_WAIT_SECS_DEFAULT, fetchActorRunData } from './actor_run_response.js';
|
|
16
16
|
import { fixActorNameInputAndLog, getActorsAsTools } from './actor_tools_factory.js';
|
|
17
|
+
import { buildGetActorRunSuccessResponse } from './get_actor_run_common.js';
|
|
17
18
|
// ---------------------------------------------------------------------------
|
|
18
19
|
// Shared call-actor description building blocks
|
|
19
20
|
// ---------------------------------------------------------------------------
|
|
@@ -34,88 +35,43 @@ USAGE:
|
|
|
34
35
|
/** Shared examples section — identical in both modes. */
|
|
35
36
|
export const CALL_ACTOR_EXAMPLES_SECTION = `EXAMPLES:
|
|
36
37
|
- user_input: Get instagram posts using apify/instagram-scraper`;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
const WIDGET_ADDENDUM = dedent `
|
|
39
|
+
WIDGET ALTERNATIVE (apps mode):
|
|
40
|
+
- If the user explicitly asks to see live progress, call ${HelperTools.ACTOR_CALL_WIDGET} instead — it renders an interactive UI that tracks the run.
|
|
41
|
+
- For silent name resolution before this call, use ${HelperTools.STORE_SEARCH} (not ${HelperTools.STORE_SEARCH_WIDGET}, which renders UI).
|
|
42
|
+
`;
|
|
43
|
+
function buildCallActorDescriptionSections(includeWidget) {
|
|
44
|
+
const sections = [
|
|
45
|
+
'Call any Actor from the Apify Store.',
|
|
46
|
+
dedent `
|
|
47
|
+
WORKFLOW:
|
|
48
|
+
1. Use ${HelperTools.ACTOR_GET_DETAILS} to get the Actor's input schema
|
|
49
|
+
2. Call this tool with the actor name and proper input based on the schema
|
|
45
50
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
sections.push(dedent `
|
|
51
|
+
If the actor name is not in "username/name" format and ${HelperTools.STORE_SEARCH} is available in this session, use it to resolve the correct Actor first.
|
|
52
|
+
`,
|
|
53
|
+
CALL_ACTOR_MCP_SERVER_SECTION,
|
|
54
|
+
dedent `
|
|
51
55
|
IMPORTANT:
|
|
52
|
-
-
|
|
53
|
-
-
|
|
54
|
-
- To check status or wait for completion, poll ${HelperTools.ACTOR_RUNS_GET} with the runId.
|
|
55
|
-
- Once the run completes, use ${HelperTools.ACTOR_OUTPUT_GET} tool with the datasetId to fetch full results.
|
|
56
|
-
- If the Actor name needs resolving first, use ${HelperTools.STORE_SEARCH} (silent). Do NOT use ${HelperTools.STORE_SEARCH_WIDGET} for name resolution.
|
|
56
|
+
- Waits up to waitSecs (default 30s) for completion; returns run status, storage IDs, and field metadata
|
|
57
|
+
- Use ${HelperTools.DATASET_GET_ITEMS} with the datasetId to fetch results; non-terminal runs include a nextStep with polling instructions
|
|
57
58
|
- Use dedicated Actor tools when available for better experience
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
sections.push(CALL_ACTOR_USAGE_SECTION);
|
|
69
|
-
if (!alwaysAsync) {
|
|
70
|
-
sections.push(dedent `
|
|
71
|
-
- This tool supports async execution via the \`async\` parameter:
|
|
72
|
-
- **When \`async: false\` or not provided** (default): Waits for completion and returns results immediately with dataset preview. Use this whenever the user asks for data or results.
|
|
73
|
-
- **When \`async: true\`**: Starts the run and returns immediately with runId. Only use this when the user explicitly asks to run the Actor in the background or does not need immediate results.
|
|
74
|
-
`);
|
|
75
|
-
}
|
|
76
|
-
sections.push(CALL_ACTOR_EXAMPLES_SECTION);
|
|
59
|
+
`,
|
|
60
|
+
CALL_ACTOR_USAGE_SECTION,
|
|
61
|
+
dedent `
|
|
62
|
+
- Use \`waitSecs\` (0–45) to control how long to wait. Default 30s returns results for fast actors. Use \`waitSecs: 0\` to start and return immediately for long-running actors.
|
|
63
|
+
`,
|
|
64
|
+
CALL_ACTOR_EXAMPLES_SECTION,
|
|
65
|
+
];
|
|
66
|
+
if (includeWidget)
|
|
67
|
+
sections.push(WIDGET_ADDENDUM);
|
|
77
68
|
return sections.join('\n\n');
|
|
78
69
|
}
|
|
79
|
-
export function
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
actorName,
|
|
85
|
-
status: actorRun.status,
|
|
86
|
-
startedAt: ((_a = actorRun.startedAt) === null || _a === void 0 ? void 0 : _a.toISOString()) || '',
|
|
87
|
-
input,
|
|
88
|
-
};
|
|
89
|
-
if (!widget) {
|
|
90
|
-
return {
|
|
91
|
-
content: [{
|
|
92
|
-
type: 'text',
|
|
93
|
-
text: `Started Actor "${actorName}" (Run ID: ${actorRun.id}).`,
|
|
94
|
-
}],
|
|
95
|
-
structuredContent,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
const responseText = dedent `
|
|
99
|
-
Started Actor "${actorName}" (Run ID: ${actorRun.id}).
|
|
100
|
-
|
|
101
|
-
A live progress widget has been rendered that automatically tracks this run and refreshes status every few seconds until completion.
|
|
102
|
-
|
|
103
|
-
The widget will update the context with run status and datasetId when the run completes. Once complete (or if the user requests results), use ${HelperTools.ACTOR_OUTPUT_GET} with the datasetId to retrieve the output.
|
|
104
|
-
|
|
105
|
-
Do NOT proactively poll using ${HelperTools.ACTOR_RUNS_GET}. Wait for the widget state update or user instructions. Ask the user what they would like to do next.
|
|
106
|
-
`;
|
|
107
|
-
const widgetConfig = getWidgetConfig(WIDGET_URIS.ACTOR_RUN);
|
|
108
|
-
return {
|
|
109
|
-
content: [{
|
|
110
|
-
type: 'text',
|
|
111
|
-
text: responseText,
|
|
112
|
-
}],
|
|
113
|
-
structuredContent,
|
|
114
|
-
_meta: {
|
|
115
|
-
...widgetConfig === null || widgetConfig === void 0 ? void 0 : widgetConfig.meta,
|
|
116
|
-
'openai/widgetDescription': `Actor run progress for ${actorName}`,
|
|
117
|
-
},
|
|
118
|
-
};
|
|
70
|
+
export function buildCallActorDescription() {
|
|
71
|
+
return buildCallActorDescriptionSections(false);
|
|
72
|
+
}
|
|
73
|
+
export function buildCallActorAppsDescription() {
|
|
74
|
+
return buildCallActorDescriptionSections(true);
|
|
119
75
|
}
|
|
120
76
|
export function isPermissionApprovalError(error) {
|
|
121
77
|
return error instanceof ApifyApiError && error.type === APIFY_ERROR_TYPE_FULL_PERMISSION_NOT_APPROVED;
|
|
@@ -135,10 +91,10 @@ export function buildPermissionApprovalResponse(error) {
|
|
|
135
91
|
isError: true,
|
|
136
92
|
});
|
|
137
93
|
}
|
|
138
|
-
function buildPermissionApprovalErrorResponse(actorName, error, actorId,
|
|
94
|
+
function buildPermissionApprovalErrorResponse(actorName, error, actorId, mcpSessionId) {
|
|
139
95
|
logHttpError(error, 'Failed to call Actor — permission approval required', {
|
|
140
96
|
actorName,
|
|
141
|
-
|
|
97
|
+
mcpSessionId,
|
|
142
98
|
failureCategory: FAILURE_CATEGORY.PERMISSION_APPROVAL_REQUIRED,
|
|
143
99
|
});
|
|
144
100
|
return {
|
|
@@ -153,15 +109,14 @@ function buildPermissionApprovalErrorResponse(actorName, error, actorId, logCont
|
|
|
153
109
|
};
|
|
154
110
|
}
|
|
155
111
|
export function buildCallActorErrorResponse(params) {
|
|
156
|
-
const { actorName, error, actorId,
|
|
112
|
+
const { actorName, error, actorId, mcpSessionId, actorGetDetailsTool, } = params;
|
|
157
113
|
if (error instanceof ApifyApiError && error.type === APIFY_ERROR_TYPE_FULL_PERMISSION_NOT_APPROVED) {
|
|
158
|
-
return buildPermissionApprovalErrorResponse(actorName, error, actorId,
|
|
114
|
+
return buildPermissionApprovalErrorResponse(actorName, error, actorId, mcpSessionId);
|
|
159
115
|
}
|
|
160
116
|
const errMsg = error instanceof Error ? error.message : String(error);
|
|
161
117
|
const failureCategory = classifyFailureCategory(error);
|
|
162
118
|
logHttpError(error, 'Failed to call Actor', {
|
|
163
119
|
actorName,
|
|
164
|
-
async: isAsync,
|
|
165
120
|
mcpSessionId,
|
|
166
121
|
failureCategory,
|
|
167
122
|
});
|
|
@@ -195,9 +150,42 @@ export function buildCallActorErrorResponse(params) {
|
|
|
195
150
|
telemetry,
|
|
196
151
|
});
|
|
197
152
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
153
|
+
export const callOptionsSchema = z.object({
|
|
154
|
+
memory: z.number()
|
|
155
|
+
.min(128, 'Memory must be at least 128 MB')
|
|
156
|
+
.max(32768, 'Memory cannot exceed 32 GB (32768 MB)')
|
|
157
|
+
.optional()
|
|
158
|
+
.describe(dedent `
|
|
159
|
+
Memory per run in MB. Power of 2 from 128 to 32768.
|
|
160
|
+
Apify also caps total memory across all your concurrent runs (account plan limit); if a run is rejected because that quota would be exceeded, retry with a smaller value.
|
|
161
|
+
`),
|
|
162
|
+
timeout: z.number()
|
|
163
|
+
.min(0, 'Timeout must be 0 or greater')
|
|
164
|
+
.optional()
|
|
165
|
+
.describe(dedent `
|
|
166
|
+
Maximum runtime for the Actor in seconds. After this time elapses, the Actor will be automatically terminated.
|
|
167
|
+
Use 0 for infinite timeout (no time limit).
|
|
168
|
+
`),
|
|
169
|
+
build: z.string()
|
|
170
|
+
.optional()
|
|
171
|
+
.describe('Tag or number of the Actor build to run (e.g., "latest", "beta", "1.2.345"). If omitted, the Actor\'s default build is used.'),
|
|
172
|
+
maxItems: z.number()
|
|
173
|
+
.int()
|
|
174
|
+
.positive()
|
|
175
|
+
.optional()
|
|
176
|
+
.describe(dedent `
|
|
177
|
+
Pay-per-result Actors only — ignored otherwise.
|
|
178
|
+
Caps billed dataset items; does NOT limit production. Prefer the Actor's own input fields (e.g. maxResults) to bound work.
|
|
179
|
+
`),
|
|
180
|
+
maxTotalChargeUsd: z.number()
|
|
181
|
+
.positive()
|
|
182
|
+
.optional()
|
|
183
|
+
.describe(dedent `
|
|
184
|
+
Pay-per-event Actors only — ignored otherwise.
|
|
185
|
+
Caps total USD billed; does NOT limit work. Prefer the Actor's own input fields to bound work.
|
|
186
|
+
`),
|
|
187
|
+
});
|
|
188
|
+
/** Zod schema for call-actor arguments — shared between default and apps variants. */
|
|
201
189
|
export const callActorArgs = z.object({
|
|
202
190
|
actor: z.string()
|
|
203
191
|
.describe(dedent `
|
|
@@ -207,62 +195,17 @@ export const callActorArgs = z.object({
|
|
|
207
195
|
`),
|
|
208
196
|
input: z.object({}).passthrough()
|
|
209
197
|
.describe('The input JSON to pass to the Actor. Required.'),
|
|
210
|
-
|
|
211
|
-
.
|
|
212
|
-
.
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
IMPORTANT: use async=true only when the user explicitly asks to run in the background or does not need immediate results.
|
|
216
|
-
`),
|
|
217
|
-
previewOutput: z.boolean()
|
|
198
|
+
waitSecs: z.number()
|
|
199
|
+
.int()
|
|
200
|
+
.min(0, 'waitSecs must be 0 or greater')
|
|
201
|
+
.max(45, 'waitSecs cannot exceed 45')
|
|
202
|
+
.default(CALL_ACTOR_WAIT_SECS_DEFAULT)
|
|
218
203
|
.optional()
|
|
219
|
-
.describe(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
callOptions: z.object({
|
|
223
|
-
memory: z.number()
|
|
224
|
-
.min(128, 'Memory must be at least 128 MB')
|
|
225
|
-
.max(32768, 'Memory cannot exceed 32 GB (32768 MB)')
|
|
226
|
-
.optional()
|
|
227
|
-
.describe(dedent `
|
|
228
|
-
Memory per run in MB. Power of 2 from 128 to 32768.
|
|
229
|
-
Apify also caps total memory across all your concurrent runs (account plan limit); if a run is rejected because that quota would be exceeded, retry with a smaller value.
|
|
230
|
-
`),
|
|
231
|
-
timeout: z.number()
|
|
232
|
-
.min(0, 'Timeout must be 0 or greater')
|
|
233
|
-
.optional()
|
|
234
|
-
.describe(dedent `
|
|
235
|
-
Maximum runtime for the Actor in seconds. After this time elapses, the Actor will be automatically terminated.
|
|
236
|
-
Use 0 for infinite timeout (no time limit). Minimum: 0 seconds (infinite).
|
|
237
|
-
`),
|
|
238
|
-
build: z.string()
|
|
239
|
-
.optional()
|
|
240
|
-
.describe('Tag or number of the Actor build to run (e.g., "latest", "beta", "1.2.345"). If omitted, the Actor\'s default build is used.'),
|
|
241
|
-
maxItems: z.number()
|
|
242
|
-
.int()
|
|
243
|
-
.positive()
|
|
244
|
-
.optional()
|
|
245
|
-
.describe(dedent `
|
|
246
|
-
Pay-per-result Actors ONLY — has no effect on any other pricing model (pay-per-event, pay-per-usage, rental, free).
|
|
247
|
-
Caps the number of dataset items billed for this run; does NOT limit how many items the Actor produces.
|
|
248
|
-
Most Actors also expose their own input field (e.g. "maxResults", "maxPages", "maxItems") to bound how much work they do — prefer those when limiting actual output, since this option only caps billing.
|
|
249
|
-
`),
|
|
250
|
-
maxTotalChargeUsd: z.number()
|
|
251
|
-
.positive()
|
|
252
|
-
.optional()
|
|
253
|
-
.describe(dedent `
|
|
254
|
-
Pay-per-event Actors ONLY — has no effect on any other pricing model (pay-per-result, pay-per-usage, rental, free).
|
|
255
|
-
Caps the total USD billed for this run; does NOT limit how much work the Actor does.
|
|
256
|
-
Most Actors also expose their own input field to bound work — prefer those when limiting actual output, since this option only caps billing.
|
|
257
|
-
`),
|
|
258
|
-
}).optional()
|
|
259
|
-
.describe('Optional call options for the Actor run configuration.'),
|
|
204
|
+
.describe('Seconds to wait for completion (0–45, default 30). Returns with current run status if not terminal within waitSecs.'),
|
|
205
|
+
callOptions: callOptionsSchema.optional()
|
|
206
|
+
.describe('Optional run config: memory (MB), timeout (s), build, maxItems (pay-per-result cap), maxTotalChargeUsd (pay-per-event cap).'),
|
|
260
207
|
});
|
|
261
|
-
/**
|
|
262
|
-
* Compiled AJV input schema — shared between both variants.
|
|
263
|
-
*/
|
|
264
208
|
export const callActorInputSchema = z.toJSONSchema(callActorArgs);
|
|
265
|
-
// Allow additional properties for dynamic Actor input fields passed via the `input` object
|
|
266
209
|
export const callActorAjvValidate = compileSchema({ ...z.toJSONSchema(callActorArgs), additionalProperties: true });
|
|
267
210
|
/**
|
|
268
211
|
* Resolves MCP URL and parses the "actor:tool" format.
|
|
@@ -309,7 +252,25 @@ export async function handleMcpToolCall(params) {
|
|
|
309
252
|
name: mcpToolName,
|
|
310
253
|
arguments: input,
|
|
311
254
|
});
|
|
312
|
-
|
|
255
|
+
// `call-actor` declares `getActorRunOutputSchema`, so MCP SDK ≥ 1.11.4 rejects any response
|
|
256
|
+
// without `structuredContent` (unless `isError: true`) with -32600. The pass-through has no
|
|
257
|
+
// Apify run, so synthesize a sentinel `RunResponse` matching the schema's `required` keys;
|
|
258
|
+
// the remote tool's payload still flows through `content`. Also forward `isError` so a
|
|
259
|
+
// failing remote tool surfaces as a failure here.
|
|
260
|
+
const isErrorFromRemote = result.isError === true;
|
|
261
|
+
return {
|
|
262
|
+
content: result.content,
|
|
263
|
+
isError: isErrorFromRemote,
|
|
264
|
+
structuredContent: {
|
|
265
|
+
runId: 'mcp-passthrough',
|
|
266
|
+
actorId: baseActorName,
|
|
267
|
+
actorName: baseActorName,
|
|
268
|
+
status: isErrorFromRemote ? 'FAILED' : 'SUCCEEDED',
|
|
269
|
+
storages: {},
|
|
270
|
+
summary: `Called MCP tool '${mcpToolName}' on '${baseActorName}'.`,
|
|
271
|
+
nextStep: 'Response content carries the remote MCP tool result; no Apify run was started.',
|
|
272
|
+
},
|
|
273
|
+
};
|
|
313
274
|
}
|
|
314
275
|
catch (error) {
|
|
315
276
|
logHttpError(error, `Failed to call MCP tool '${mcpToolName}' on Actor '${baseActorName}'`, {
|
|
@@ -477,4 +438,74 @@ export async function callActorPreExecute(toolArgs, options) {
|
|
|
477
438
|
}
|
|
478
439
|
return { parsed, baseActorName, mcpToolName };
|
|
479
440
|
}
|
|
441
|
+
/**
|
|
442
|
+
* Shared start-then-wait flow for call-actor variants (default + apps).
|
|
443
|
+
* `taskMode` is honored — when true, `waitSecs` is ignored and the SDK waits until terminal.
|
|
444
|
+
*/
|
|
445
|
+
export async function executeCallActor(toolArgs) {
|
|
446
|
+
const preResult = await callActorPreExecute(toolArgs, { route: HelperTools.ACTOR_CALL });
|
|
447
|
+
if ('earlyResponse' in preResult) {
|
|
448
|
+
return preResult.earlyResponse;
|
|
449
|
+
}
|
|
450
|
+
const { parsed, baseActorName } = preResult;
|
|
451
|
+
const { input, callOptions } = parsed;
|
|
452
|
+
// Task mode waits until terminal (waitSecs=undefined uses SDK default ~999999s); caller's waitSecs is ignored.
|
|
453
|
+
// Non-task mode: pass waitSecs so the SDK blocks up to that many seconds before returning.
|
|
454
|
+
const waitSecs = toolArgs.taskMode ? undefined : parsed.waitSecs;
|
|
455
|
+
let resolvedActorId;
|
|
456
|
+
try {
|
|
457
|
+
const resolution = await resolveAndValidateActor({
|
|
458
|
+
actorName: baseActorName,
|
|
459
|
+
input: input,
|
|
460
|
+
toolArgs,
|
|
461
|
+
});
|
|
462
|
+
if ('error' in resolution) {
|
|
463
|
+
return resolution.error;
|
|
464
|
+
}
|
|
465
|
+
resolvedActorId = extractActorId(resolution.actor);
|
|
466
|
+
const { apifyClient } = toolArgs;
|
|
467
|
+
const abortSignal = toolArgs.extra.signal;
|
|
468
|
+
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)
|
|
469
|
+
return {};
|
|
470
|
+
const actorRun = await apifyClient.actor(baseActorName).start(input, callOptions);
|
|
471
|
+
log.debug('Started Actor run', { actorName: baseActorName, runId: actorRun.id, mcpSessionId: toolArgs.mcpSessionId, waitSecs });
|
|
472
|
+
// Abort can arrive while start() was in flight — abort the newly created run.
|
|
473
|
+
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
|
|
474
|
+
await abortRunOnSignal(actorRun.id, apifyClient);
|
|
475
|
+
return {};
|
|
476
|
+
}
|
|
477
|
+
// waitSecs:0 means "fire and forget" — start() already returned the full run, skip re-fetch.
|
|
478
|
+
if (waitSecs === 0) {
|
|
479
|
+
const response = buildStartRunResponse({ actorName: baseActorName, actorRun });
|
|
480
|
+
return { ...response, toolTelemetry: { actorId: resolvedActorId } };
|
|
481
|
+
}
|
|
482
|
+
const fetchResult = await fetchActorRunData({
|
|
483
|
+
runId: actorRun.id,
|
|
484
|
+
waitSecs,
|
|
485
|
+
actorName: baseActorName,
|
|
486
|
+
client: apifyClient,
|
|
487
|
+
progressTracker: toolArgs.progressTracker,
|
|
488
|
+
abortSignal,
|
|
489
|
+
mcpSessionId: toolArgs.mcpSessionId,
|
|
490
|
+
onAbort: abortRunOnSignal,
|
|
491
|
+
});
|
|
492
|
+
if ('aborted' in fetchResult)
|
|
493
|
+
return {};
|
|
494
|
+
if ('error' in fetchResult)
|
|
495
|
+
return fetchResult.error;
|
|
496
|
+
return {
|
|
497
|
+
...buildGetActorRunSuccessResponse({ ...fetchResult.result, widget: false }),
|
|
498
|
+
toolTelemetry: { actorId: resolvedActorId },
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
catch (error) {
|
|
502
|
+
return buildCallActorErrorResponse({
|
|
503
|
+
actorName: baseActorName,
|
|
504
|
+
error,
|
|
505
|
+
actorId: resolvedActorId,
|
|
506
|
+
mcpSessionId: toolArgs.mcpSessionId,
|
|
507
|
+
actorGetDetailsTool: HelperTools.ACTOR_GET_DETAILS,
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
}
|
|
480
511
|
//# sourceMappingURL=call_actor_common.js.map
|