@apify/actors-mcp-server 0.15.1-beta.0 → 0.15.1-beta.1
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/README.md +6 -0
- package/dist/const.d.ts +6 -0
- package/dist/const.d.ts.map +1 -1
- package/dist/const.js +6 -0
- package/dist/const.js.map +1 -1
- package/dist/index_internals.d.ts +5 -0
- package/dist/index_internals.d.ts.map +1 -1
- package/dist/test_kit/tsconfig.tsbuildinfo +1 -1
- package/dist/tools/registry.d.ts +1 -0
- package/dist/tools/registry.d.ts.map +1 -1
- package/dist/tools/registry.js +6 -0
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/structured_output_schemas.d.ts +64 -0
- package/dist/tools/structured_output_schemas.d.ts.map +1 -1
- package/dist/tools/structured_output_schemas.js +34 -0
- package/dist/tools/structured_output_schemas.js.map +1 -1
- package/dist/tools/tasks/create_actor_task.d.ts +6 -0
- package/dist/tools/tasks/create_actor_task.d.ts.map +1 -0
- package/dist/tools/tasks/create_actor_task.js +86 -0
- package/dist/tools/tasks/create_actor_task.js.map +1 -0
- package/dist/tools/tasks/get_actor_task.d.ts +6 -0
- package/dist/tools/tasks/get_actor_task.d.ts.map +1 -0
- package/dist/tools/tasks/get_actor_task.js +59 -0
- package/dist/tools/tasks/get_actor_task.js.map +1 -0
- package/dist/tools/tasks/publish_actor_task.d.ts +6 -0
- package/dist/tools/tasks/publish_actor_task.d.ts.map +1 -0
- package/dist/tools/tasks/publish_actor_task.js +63 -0
- package/dist/tools/tasks/publish_actor_task.js.map +1 -0
- package/dist/tools/tasks/task_helpers.d.ts +50 -0
- package/dist/tools/tasks/task_helpers.d.ts.map +1 -0
- package/dist/tools/tasks/task_helpers.js +105 -0
- package/dist/tools/tasks/task_helpers.js.map +1 -0
- package/dist/tools/tasks/unpublish_actor_task.d.ts +6 -0
- package/dist/tools/tasks/unpublish_actor_task.d.ts.map +1 -0
- package/dist/tools/tasks/unpublish_actor_task.js +56 -0
- package/dist/tools/tasks/unpublish_actor_task.js.map +1 -0
- package/dist/tools/tasks/update_actor_task.d.ts +6 -0
- package/dist/tools/tasks/update_actor_task.d.ts.map +1 -0
- package/dist/tools/tasks/update_actor_task.js +100 -0
- package/dist/tools/tasks/update_actor_task.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/apify_errors.d.ts +2 -0
- package/dist/utils/apify_errors.d.ts.map +1 -1
- package/dist/utils/apify_errors.js +5 -1
- package/dist/utils/apify_errors.js.map +1 -1
- package/dist/utils/mcp.d.ts.map +1 -1
- package/dist/utils/mcp.js +7 -1
- package/dist/utils/mcp.js.map +1 -1
- package/dist/utils/server-instructions/index.d.ts.map +1 -1
- package/dist/utils/server-instructions/index.js +7 -0
- package/dist/utils/server-instructions/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { toIsoString } from '../actors/actor_run_response.js';
|
|
3
|
+
const PUBLIC_CONFIG_FIELDS = [
|
|
4
|
+
'seoTitle',
|
|
5
|
+
'seoDescription',
|
|
6
|
+
'inputSchemaFields',
|
|
7
|
+
'datasetName',
|
|
8
|
+
'datasetView',
|
|
9
|
+
];
|
|
10
|
+
/** Apify resource IDs are exactly 17 alphanumeric characters. */
|
|
11
|
+
const APIFY_ID_REGEX = /^[a-zA-Z0-9]{17}$/;
|
|
12
|
+
/**
|
|
13
|
+
* The API reads an unqualified id as an ID, so a bare resource name has to be prefixed with `~` to be
|
|
14
|
+
* resolved against the authenticated user's own resources. Ids that already carry a username, in either
|
|
15
|
+
* the `username/name` or `username~name` format, and ids that are already IDs, are returned unchanged.
|
|
16
|
+
*
|
|
17
|
+
* Applies to both tasks and the Actor a task is created for, which the API resolves the same way.
|
|
18
|
+
*/
|
|
19
|
+
export function toSafeResourceId(idOrName) {
|
|
20
|
+
const trimmed = idOrName.trim();
|
|
21
|
+
if (trimmed.includes('/') || trimmed.includes('~'))
|
|
22
|
+
return trimmed;
|
|
23
|
+
return APIFY_ID_REGEX.test(trimmed) ? trimmed : `~${trimmed}`;
|
|
24
|
+
}
|
|
25
|
+
/** A bare 17-alnum value is shape-identical to an ID and to a legal task name. */
|
|
26
|
+
export function isAmbiguousResourceId(idOrName) {
|
|
27
|
+
const trimmed = idOrName.trim();
|
|
28
|
+
return !trimmed.includes('/') && !trimmed.includes('~') && APIFY_ID_REGEX.test(trimmed);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Fetches a task by ID, name, or `username/name`. An ambiguous value cannot be resolved by
|
|
32
|
+
* inspection, so it is read as an ID first and, on a miss, retried as the caller's own task name.
|
|
33
|
+
*/
|
|
34
|
+
export async function getTaskByIdOrName(client, idOrName) {
|
|
35
|
+
const task = await client.task(toSafeResourceId(idOrName)).get();
|
|
36
|
+
if (task || !isAmbiguousResourceId(idOrName))
|
|
37
|
+
return task;
|
|
38
|
+
return client.task(`~${idOrName.trim()}`).get();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Task names must be DNS-safe and 3-63 characters, as the API enforces. Validated here so the
|
|
42
|
+
* caller gets a usable message instead of a 400.
|
|
43
|
+
*/
|
|
44
|
+
const TASK_NAME_REGEX = /^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])$/;
|
|
45
|
+
export const taskNameSchema = z
|
|
46
|
+
.string()
|
|
47
|
+
.min(3)
|
|
48
|
+
.max(63)
|
|
49
|
+
.regex(TASK_NAME_REGEX, 'Task name may contain only letters, digits and dashes, and cannot start or end with a dash');
|
|
50
|
+
/** Writable public display configuration, shared by the create and update tools. */
|
|
51
|
+
export const publicConfigSchema = z.object({
|
|
52
|
+
seoTitle: z.string().optional().describe('Title shown on the public landing page and in search results.'),
|
|
53
|
+
seoDescription: z.string().optional().describe('Description shown on the public landing page.'),
|
|
54
|
+
inputSchemaFields: z
|
|
55
|
+
.array(z.string())
|
|
56
|
+
.optional()
|
|
57
|
+
.describe('Names of the input fields to display on the public page. At least one valid field is required to publish; the names must exist in the task input.'),
|
|
58
|
+
datasetName: z.string().optional().describe('Name of the dataset whose schema provides the views.'),
|
|
59
|
+
datasetView: z
|
|
60
|
+
.string()
|
|
61
|
+
.optional()
|
|
62
|
+
.describe("View key from the Actor's dataset schema. Required to publish; ask the user, no tool lists dataset views."),
|
|
63
|
+
});
|
|
64
|
+
/**
|
|
65
|
+
* The task subset returned by every task tool: identity, publication state, and the display
|
|
66
|
+
* config. Input *values* are deliberately omitted — they may hold secrets — but the field names
|
|
67
|
+
* are included because `publicConfig.inputSchemaFields` must reference them.
|
|
68
|
+
*/
|
|
69
|
+
export function taskResult(task) {
|
|
70
|
+
var _a, _b, _c, _d;
|
|
71
|
+
const publicConfig = task.publicConfig
|
|
72
|
+
? Object.fromEntries(PUBLIC_CONFIG_FIELDS.filter((field) => { var _a; return ((_a = task.publicConfig) === null || _a === void 0 ? void 0 : _a[field]) !== undefined; }).map((field) => {
|
|
73
|
+
var _a;
|
|
74
|
+
return [
|
|
75
|
+
field,
|
|
76
|
+
(_a = task.publicConfig) === null || _a === void 0 ? void 0 : _a[field],
|
|
77
|
+
];
|
|
78
|
+
}))
|
|
79
|
+
: null;
|
|
80
|
+
return {
|
|
81
|
+
taskId: task.id,
|
|
82
|
+
actorId: task.actId,
|
|
83
|
+
name: task.name,
|
|
84
|
+
title: (_a = task.title) !== null && _a !== void 0 ? _a : null,
|
|
85
|
+
description: (_b = task.description) !== null && _b !== void 0 ? _b : null,
|
|
86
|
+
// Normalized because the client parses this into a `Date` while the raw publication call
|
|
87
|
+
// returns a string; the declared output schema promises a string either way.
|
|
88
|
+
publishedAt: (_d = toIsoString((_c = task.publicConfig) === null || _c === void 0 ? void 0 : _c.publishedAt)) !== null && _d !== void 0 ? _d : null,
|
|
89
|
+
publicConfig,
|
|
90
|
+
inputFields: task.input && !Array.isArray(task.input) ? Object.keys(task.input) : [],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Setting the publication state the task already has is a no-op, so both directions are safe
|
|
95
|
+
* to repeat.
|
|
96
|
+
*/
|
|
97
|
+
export async function setTaskPublication(client, taskId, isPublic) {
|
|
98
|
+
var _a;
|
|
99
|
+
// An ambiguous value is resolved to the real ID by lookup; on a miss it falls through to the
|
|
100
|
+
// ID reading so the publish call raises the API's own not-found error.
|
|
101
|
+
const resolvedId = isAmbiguousResourceId(taskId) ? (_a = (await getTaskByIdOrName(client, taskId))) === null || _a === void 0 ? void 0 : _a.id : undefined;
|
|
102
|
+
const taskClient = client.task(resolvedId !== null && resolvedId !== void 0 ? resolvedId : toSafeResourceId(taskId));
|
|
103
|
+
return isPublic ? taskClient.publish() : taskClient.unpublish();
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=task_helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task_helpers.js","sourceRoot":"","sources":["../../../src/tools/tasks/task_helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,MAAM,oBAAoB,GAAG;IACzB,UAAU;IACV,gBAAgB;IAChB,mBAAmB;IACnB,aAAa;IACb,aAAa;CACmD,CAAC;AAErE,iEAAiE;AACjE,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAE3C;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC7C,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;IAChC,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,OAAO,CAAC;IACnE,OAAO,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,EAAE,CAAC;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CAAC,CAAC,CAAC,CAAC,EAAE;KACvF,CAAC;AACN,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,MAAmB,EAAE,MAAc,EAAE,QAAiB;;IAC3F,6FAA6F;IAC7F,uEAAuE;IACvE,MAAM,UAAU,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAA,CAAC,MAAM,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,0CAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7G,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;IACvE,OAAO,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unpublish_actor_task.d.ts","sourceRoot":"","sources":["../../../src/tools/tasks/unpublish_actor_task.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAA4C,SAAS,EAAmB,MAAM,gBAAgB,CAAC;AA+B3G;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,SAyBtB,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { HELPER_TOOLS } from '../../const.js';
|
|
3
|
+
import { ALL_TOOLS_PRESENT, TOOL_TYPE } from '../../types.js';
|
|
4
|
+
import { compileSchema } from '../../utils/ajv.js';
|
|
5
|
+
import { respondOk } from '../../utils/mcp.js';
|
|
6
|
+
import { actorTaskOutputSchema } from '../structured_output_schemas.js';
|
|
7
|
+
import { setTaskPublication, taskResult } from './task_helpers.js';
|
|
8
|
+
const unpublishActorTaskArgs = z.object({
|
|
9
|
+
taskId: z
|
|
10
|
+
.string()
|
|
11
|
+
.min(1)
|
|
12
|
+
.describe('The task to unpublish: its ID, its name (resolved against your own tasks), or "username/task-name" for a task owned by someone else.'),
|
|
13
|
+
});
|
|
14
|
+
function buildDescription({ hasTool }) {
|
|
15
|
+
return `Unpublish a task from its public landing page.
|
|
16
|
+
The public display configuration is preserved, so the task can be published again \
|
|
17
|
+
later${hasTool(HELPER_TOOLS.ACTOR_TASK_PUBLISH) ? ` with ${HELPER_TOOLS.ACTOR_TASK_PUBLISH}` : ''}. Unpublishing a task
|
|
18
|
+
that is not published does nothing.
|
|
19
|
+
Requires write access to both the task and its Actor.
|
|
20
|
+
|
|
21
|
+
USAGE:
|
|
22
|
+
- Use when the user wants to take down a task's public landing page.
|
|
23
|
+
|
|
24
|
+
USAGE EXAMPLES:
|
|
25
|
+
- user_input: Unpublish my task my-task
|
|
26
|
+
- user_input: Unpublish task E2jjCZBezvAZnX8Rb`;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* https://docs.apify.com/api/v2/actor-task-put
|
|
30
|
+
*/
|
|
31
|
+
export const unpublishActorTask = Object.freeze({
|
|
32
|
+
type: TOOL_TYPE.INTERNAL,
|
|
33
|
+
name: HELPER_TOOLS.ACTOR_TASK_UNPUBLISH,
|
|
34
|
+
title: 'Unpublish Actor task',
|
|
35
|
+
description: buildDescription(ALL_TOOLS_PRESENT),
|
|
36
|
+
buildDescription,
|
|
37
|
+
inputSchema: z.toJSONSchema(unpublishActorTaskArgs),
|
|
38
|
+
outputSchema: actorTaskOutputSchema,
|
|
39
|
+
ajvValidate: compileSchema(z.toJSONSchema(unpublishActorTaskArgs)),
|
|
40
|
+
annotations: {
|
|
41
|
+
title: 'Unpublish Actor task',
|
|
42
|
+
readOnlyHint: false,
|
|
43
|
+
destructiveHint: false,
|
|
44
|
+
idempotentHint: true,
|
|
45
|
+
openWorldHint: false,
|
|
46
|
+
},
|
|
47
|
+
call: async (toolArgs) => {
|
|
48
|
+
const { args, apifyClient: client } = toolArgs;
|
|
49
|
+
const parsed = unpublishActorTaskArgs.parse(args);
|
|
50
|
+
const task = await setTaskPublication(client, parsed.taskId, false);
|
|
51
|
+
const result = taskResult(task);
|
|
52
|
+
const summary = `Task "${task.name}" (ID: ${task.id}) is no longer published.`;
|
|
53
|
+
return respondOk([JSON.stringify(result), summary], { structuredContent: result });
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=unpublish_actor_task.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unpublish_actor_task.js","sourceRoot":"","sources":["../../../src/tools/tasks/unpublish_actor_task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEnE,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,MAAM,EAAE,CAAC;SACJ,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,QAAQ,CACL,sIAAsI,CACzI;CACR,CAAC,CAAC;AAEH,SAAS,gBAAgB,CAAC,EAAE,OAAO,EAA0B;IACzD,OAAO;;OAEJ,OAAO,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS,YAAY,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,EAAE;;;;;;;;;+CASlD,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAc,MAAM,CAAC,MA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AmB,MAAM,gBAAgB,CAAC;AAyD3G;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,SA2DnB,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { HELPER_TOOLS } from '../../const.js';
|
|
3
|
+
import { ALL_TOOLS_PRESENT, TOOL_TYPE } from '../../types.js';
|
|
4
|
+
import { compileSchema } from '../../utils/ajv.js';
|
|
5
|
+
import { respondOk, respondUserError } from '../../utils/mcp.js';
|
|
6
|
+
import { actorTaskOutputSchema } from '../structured_output_schemas.js';
|
|
7
|
+
import { getTaskByIdOrName, isAmbiguousResourceId, publicConfigSchema, taskNameSchema, taskResult, toSafeResourceId, } from './task_helpers.js';
|
|
8
|
+
const updateActorTaskArgs = z.object({
|
|
9
|
+
taskId: z
|
|
10
|
+
.string()
|
|
11
|
+
.min(1)
|
|
12
|
+
.describe('The task to update: its ID, its name (resolved against your own tasks), or "username/task-name" for a task owned by someone else.'),
|
|
13
|
+
name: taskNameSchema.optional().describe('New name of the task: 3-63 characters, letters, digits and dashes only.'),
|
|
14
|
+
title: z.string().optional().describe('New human-readable title of the task.'),
|
|
15
|
+
description: z.string().optional().describe('New short description of the task.'),
|
|
16
|
+
input: z
|
|
17
|
+
.object({})
|
|
18
|
+
.passthrough()
|
|
19
|
+
.optional()
|
|
20
|
+
.describe('Replacement input JSON for the task. Replaces the stored input, it is not merged into it.'),
|
|
21
|
+
build: z.string().optional().describe('Actor build tag or number to run, e.g. "latest".'),
|
|
22
|
+
timeoutSecs: z.number().int().min(0).optional().describe('Run timeout in seconds; 0 means no timeout.'),
|
|
23
|
+
memoryMbytes: z.number().int().positive().optional().describe('Memory limit for the run in megabytes.'),
|
|
24
|
+
publicConfig: publicConfigSchema
|
|
25
|
+
.optional()
|
|
26
|
+
.describe('Public display configuration of the task landing page. Provided fields are merged into the stored configuration; the publication state itself is not changed here.'),
|
|
27
|
+
});
|
|
28
|
+
function buildDescription({ hasTool }) {
|
|
29
|
+
const publicationTools = [HELPER_TOOLS.ACTOR_TASK_PUBLISH, HELPER_TOOLS.ACTOR_TASK_UNPUBLISH].filter((name) => hasTool(name));
|
|
30
|
+
return `Update a saved Actor task: its input, run options, or the public display configuration (\`publicConfig\`) of its landing page.
|
|
31
|
+
This does not publish or unpublish the task${publicationTools.length ? ` — use ${publicationTools.join(' and ')} for that` : ''}.
|
|
32
|
+
To publish a task, \`publicConfig.inputSchemaFields\` (at least one field name from the task input) and
|
|
33
|
+
\`publicConfig.datasetView\` must be set here first. Updating \`publicConfig\` requires write access to the task's Actor.
|
|
34
|
+
|
|
35
|
+
USAGE:
|
|
36
|
+
- Use to change a task's input or run options.
|
|
37
|
+
- Use to fill in the public display configuration before publishing a task.
|
|
38
|
+
|
|
39
|
+
USAGE EXAMPLES:
|
|
40
|
+
- user_input: Change my task my-task to use the beta build
|
|
41
|
+
- user_input: Set up my-task for publishing with the overview dataset view`;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* https://docs.apify.com/api/v2/actor-task-put
|
|
45
|
+
*/
|
|
46
|
+
export const updateActorTask = Object.freeze({
|
|
47
|
+
type: TOOL_TYPE.INTERNAL,
|
|
48
|
+
name: HELPER_TOOLS.ACTOR_TASK_UPDATE,
|
|
49
|
+
title: 'Update Actor task',
|
|
50
|
+
description: buildDescription(ALL_TOOLS_PRESENT),
|
|
51
|
+
buildDescription,
|
|
52
|
+
inputSchema: z.toJSONSchema(updateActorTaskArgs),
|
|
53
|
+
outputSchema: actorTaskOutputSchema,
|
|
54
|
+
ajvValidate: compileSchema(z.toJSONSchema(updateActorTaskArgs)),
|
|
55
|
+
annotations: {
|
|
56
|
+
title: 'Update Actor task',
|
|
57
|
+
readOnlyHint: false,
|
|
58
|
+
destructiveHint: false,
|
|
59
|
+
idempotentHint: true,
|
|
60
|
+
openWorldHint: false,
|
|
61
|
+
},
|
|
62
|
+
call: async (toolArgs) => {
|
|
63
|
+
const { args, apifyClient: client } = toolArgs;
|
|
64
|
+
const { taskId, name, title, description, input, build, timeoutSecs, memoryMbytes, publicConfig } = updateActorTaskArgs.parse(args);
|
|
65
|
+
const optionsUpdate = {
|
|
66
|
+
...(build !== undefined && { build }),
|
|
67
|
+
...(timeoutSecs !== undefined && { timeoutSecs }),
|
|
68
|
+
...(memoryMbytes !== undefined && { memoryMbytes }),
|
|
69
|
+
};
|
|
70
|
+
const hasOptions = Object.keys(optionsUpdate).length > 0;
|
|
71
|
+
// The pre-read serves two cases: the API completely replaces `options` (unlike
|
|
72
|
+
// `publicConfig`, which it merges), so an options update must merge with the stored value;
|
|
73
|
+
// and an ambiguous taskId (an ID-shaped name) must be resolved to the real ID by lookup.
|
|
74
|
+
let resolvedTaskId = toSafeResourceId(taskId);
|
|
75
|
+
let storedOptions;
|
|
76
|
+
if (hasOptions || isAmbiguousResourceId(taskId)) {
|
|
77
|
+
const storedTask = await getTaskByIdOrName(client, taskId);
|
|
78
|
+
// Report the missing task from this read rather than letting the update fail later with
|
|
79
|
+
// a rawer error.
|
|
80
|
+
if (!storedTask) {
|
|
81
|
+
return respondUserError(`Task ${taskId} was not found.`);
|
|
82
|
+
}
|
|
83
|
+
resolvedTaskId = storedTask.id;
|
|
84
|
+
storedOptions = storedTask.options;
|
|
85
|
+
}
|
|
86
|
+
const update = {
|
|
87
|
+
...(name && { name }),
|
|
88
|
+
...(title !== undefined && { title }),
|
|
89
|
+
...(description !== undefined && { description }),
|
|
90
|
+
...(input && { input }),
|
|
91
|
+
...(hasOptions && { options: { ...storedOptions, ...optionsUpdate } }),
|
|
92
|
+
...(publicConfig && { publicConfig }),
|
|
93
|
+
};
|
|
94
|
+
const task = await client.task(resolvedTaskId).update(update);
|
|
95
|
+
const result = taskResult(task);
|
|
96
|
+
const summary = `Updated task "${result.name}" (ID: ${result.taskId}).`;
|
|
97
|
+
return respondOk([JSON.stringify(result), summary], { structuredContent: result });
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
//# sourceMappingURL=update_actor_task.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