@apify/actors-mcp-server 0.18.4-beta.4 → 0.18.5-beta.0

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.
Files changed (88) hide show
  1. package/README.md +5 -2
  2. package/dist/const.d.ts +7 -4
  3. package/dist/const.d.ts.map +1 -1
  4. package/dist/const.js +8 -4
  5. package/dist/const.js.map +1 -1
  6. package/dist/index_internals.d.ts +2 -0
  7. package/dist/index_internals.d.ts.map +1 -1
  8. package/dist/test_kit/cases/versions.cases.d.ts +3 -0
  9. package/dist/test_kit/cases/versions.cases.d.ts.map +1 -0
  10. package/dist/test_kit/cases/versions.cases.js +509 -0
  11. package/dist/test_kit/cases/versions.cases.js.map +1 -0
  12. package/dist/test_kit/helpers.d.ts +1 -1
  13. package/dist/test_kit/helpers.d.ts.map +1 -1
  14. package/dist/test_kit/helpers.js +1 -1
  15. package/dist/test_kit/helpers.js.map +1 -1
  16. package/dist/test_kit/index.d.ts +1 -0
  17. package/dist/test_kit/index.d.ts.map +1 -1
  18. package/dist/test_kit/index.js +3 -0
  19. package/dist/test_kit/index.js.map +1 -1
  20. package/dist/test_kit/tsconfig.tsbuildinfo +1 -1
  21. package/dist/tools/builds/build_actor.d.ts.map +1 -1
  22. package/dist/tools/builds/build_actor.js +9 -4
  23. package/dist/tools/builds/build_actor.js.map +1 -1
  24. package/dist/tools/builds/get_actor_build_list.d.ts.map +1 -1
  25. package/dist/tools/builds/get_actor_build_list.js +5 -3
  26. package/dist/tools/builds/get_actor_build_list.js.map +1 -1
  27. package/dist/tools/registry.d.ts +1 -1
  28. package/dist/tools/registry.d.ts.map +1 -1
  29. package/dist/tools/registry.js +4 -2
  30. package/dist/tools/registry.js.map +1 -1
  31. package/dist/tools/runs/get_actor_run_list.d.ts.map +1 -1
  32. package/dist/tools/runs/get_actor_run_list.js +5 -3
  33. package/dist/tools/runs/get_actor_run_list.js.map +1 -1
  34. package/dist/tools/schedules/schedule_helpers.d.ts.map +1 -1
  35. package/dist/tools/schedules/schedule_helpers.js +2 -1
  36. package/dist/tools/schedules/schedule_helpers.js.map +1 -1
  37. package/dist/tools/schedules/update_schedule.js +1 -1
  38. package/dist/tools/schedules/update_schedule.js.map +1 -1
  39. package/dist/tools/structured_output_schemas.d.ts +180 -0
  40. package/dist/tools/structured_output_schemas.d.ts.map +1 -1
  41. package/dist/tools/structured_output_schemas.js +59 -0
  42. package/dist/tools/structured_output_schemas.js.map +1 -1
  43. package/dist/tools/tasks/create_actor_task.d.ts.map +1 -1
  44. package/dist/tools/tasks/create_actor_task.js +2 -1
  45. package/dist/tools/tasks/create_actor_task.js.map +1 -1
  46. package/dist/tools/tasks/task_helpers.d.ts +0 -16
  47. package/dist/tools/tasks/task_helpers.d.ts.map +1 -1
  48. package/dist/tools/tasks/task_helpers.js +1 -31
  49. package/dist/tools/tasks/task_helpers.js.map +1 -1
  50. package/dist/tools/tasks/update_actor_task.d.ts.map +1 -1
  51. package/dist/tools/tasks/update_actor_task.js +2 -1
  52. package/dist/tools/tasks/update_actor_task.js.map +1 -1
  53. package/dist/tools/versions/create_actor.d.ts +11 -0
  54. package/dist/tools/versions/create_actor.d.ts.map +1 -0
  55. package/dist/tools/versions/create_actor.js +171 -0
  56. package/dist/tools/versions/create_actor.js.map +1 -0
  57. package/dist/tools/versions/get_actor_version.d.ts.map +1 -0
  58. package/dist/tools/{source → versions}/get_actor_version.js +5 -88
  59. package/dist/tools/versions/get_actor_version.js.map +1 -0
  60. package/dist/tools/{source → versions}/source_files.d.ts +6 -2
  61. package/dist/tools/versions/source_files.d.ts.map +1 -0
  62. package/dist/tools/{source → versions}/source_files.js +7 -7
  63. package/dist/tools/versions/source_files.js.map +1 -0
  64. package/dist/tools/versions/source_helpers.d.ts +107 -0
  65. package/dist/tools/versions/source_helpers.d.ts.map +1 -0
  66. package/dist/tools/versions/source_helpers.js +350 -0
  67. package/dist/tools/versions/source_helpers.js.map +1 -0
  68. package/dist/tools/versions/update_actor_version.d.ts +15 -0
  69. package/dist/tools/versions/update_actor_version.d.ts.map +1 -0
  70. package/dist/tools/versions/update_actor_version.js +447 -0
  71. package/dist/tools/versions/update_actor_version.js.map +1 -0
  72. package/dist/tsconfig.tsbuildinfo +1 -1
  73. package/dist/utils/apify_resource_id.d.ts +18 -0
  74. package/dist/utils/apify_resource_id.d.ts.map +1 -0
  75. package/dist/utils/apify_resource_id.js +33 -0
  76. package/dist/utils/apify_resource_id.js.map +1 -0
  77. package/dist/utils/tools_loader.d.ts +2 -1
  78. package/dist/utils/tools_loader.d.ts.map +1 -1
  79. package/dist/utils/tools_loader.js +3 -2
  80. package/dist/utils/tools_loader.js.map +1 -1
  81. package/manifest.json +1 -1
  82. package/package.json +1 -1
  83. package/server.json +1 -1
  84. package/dist/tools/source/get_actor_version.d.ts.map +0 -1
  85. package/dist/tools/source/get_actor_version.js.map +0 -1
  86. package/dist/tools/source/source_files.d.ts.map +0 -1
  87. package/dist/tools/source/source_files.js.map +0 -1
  88. /package/dist/tools/{source → versions}/get_actor_version.d.ts +0 -0
@@ -0,0 +1,447 @@
1
+ import { posix } from 'node:path';
2
+ import { ActorSourceType, ApifyApiError } from 'apify-client';
3
+ import dedent from 'dedent';
4
+ import { z } from 'zod';
5
+ import { HELPER_TOOLS } from '../../const.js';
6
+ import { UserInputError } from '../../errors.js';
7
+ import { TOOL_TYPE } from '../../types.js';
8
+ import { compileSchema, fixZodSchemaRequired } from '../../utils/ajv.js';
9
+ import { getApifyErrorType } from '../../utils/apify_errors.js';
10
+ import { getHttpStatusCode, logHttpError } from '../../utils/logging.js';
11
+ import { respondAborted, respondServerError, respondUserError } from '../../utils/mcp.js';
12
+ import { respondWithBuild } from '../builds/build_helpers.js';
13
+ import { updateActorVersionToolOutputSchema } from '../structured_output_schemas.js';
14
+ import { buildFilesManifest, buildFilesRevision, buildInlineSourceFile, compareSourcePaths, isFolderEntry, } from './source_files.js';
15
+ import { buildEmptyFilesWarnings, buildSourceFileEntry, extractSourceFiles, fetchActor, redactSourceToolArgs, resolveVersion, respondAfterWrite, respondToSourceToolError, SourcePathIndex, validateFileContent, validateFilePath, validatePathCharacters, } from './source_helpers.js';
16
+ /** Why an operation or the revision check failed; the caller reads the code to decide how to recover. */
17
+ const PRECONDITION_REASON = {
18
+ FILE_EXISTS: 'FILE_EXISTS',
19
+ FILE_NOT_FOUND: 'FILE_NOT_FOUND',
20
+ HASH_MISMATCH: 'HASH_MISMATCH',
21
+ NO_MATCH: 'NO_MATCH',
22
+ MULTIPLE_MATCHES: 'MULTIPLE_MATCHES',
23
+ NOT_TEXT: 'NOT_TEXT',
24
+ REVISION_MISMATCH: 'REVISION_MISMATCH',
25
+ };
26
+ // Each edit searches the whole text of its file, which is at most MAX_EDITED_TEXT_LENGTH long, and blocks the event loop
27
+ // meanwhile: up to about 20 ms for an oldText over 250 characters, so 20 edits take up to about 0.4 s. Writes and deletes
28
+ // never search a stored file.
29
+ const MAX_OPERATIONS_PER_CALL = 100;
30
+ const MAX_EDITS_PER_CALL = 20;
31
+ // In UTF-16 code units, which a string's length gives at no cost and the search time grows with. The platform refuses
32
+ // a version whose stored file contents pass 3 MiB in total, in UTF-8 bytes (MAX_MULTIFILE_BYTES in @apify/consts), but
33
+ // checks that only at the PUT, after the edits ran. UTF-8 takes at least one byte per code unit, so no file the platform
34
+ // stored is longer than this; a file within it can still be over the platform's limit, which the PUT then refuses.
35
+ const MAX_EDITED_TEXT_LENGTH = 3 * 1024 * 1024;
36
+ // One flat object with an explicit `type`: AJV's `removeAdditional` drops the fields of all but one branch of a
37
+ // union, so the field each type needs is checked in code.
38
+ const operationArgs = z.object({
39
+ type: z
40
+ .enum(['write', 'edit', 'delete'])
41
+ .describe('write creates or replaces a file, edit replaces text in one, delete removes one.'),
42
+ path: z.string().min(1).describe('The file, relative to the Actor root, for example src/main.js.'),
43
+ content: z.string().optional().describe('write: the whole new content.'),
44
+ encoding: z
45
+ .enum(['utf8', 'base64'])
46
+ .optional()
47
+ .describe('write: utf8 for text, base64 for binary files. Defaults to base64 for binary extensions such as .png and to utf8 otherwise.'),
48
+ expectedHash: z
49
+ .string()
50
+ .optional()
51
+ .describe("write over an existing file, and delete: the file's hash from the version listing. Leave it out to create a new file. An edit checks it when given."),
52
+ edits: z
53
+ .array(z.object({
54
+ oldText: z.string().min(1).describe('The exact current text to replace, copied from the file content.'),
55
+ newText: z.string().describe('The text to put in its place; empty to remove oldText.'),
56
+ }))
57
+ .min(1)
58
+ .optional()
59
+ .describe('edit: replacements applied in order, each to the text the previous ones left.'),
60
+ });
61
+ const updateActorVersionArgs = z.object({
62
+ actor: z
63
+ .string()
64
+ .min(1)
65
+ .describe('The Actor to change: its ID, its name (resolved against your own Actors), or its full name as username/name or username~name.'),
66
+ versionNumber: z
67
+ .string()
68
+ .optional()
69
+ .describe('Version to change in MAJOR.MINOR form, for example 0.1. Defaults to the only version when the Actor has exactly one.'),
70
+ operations: z
71
+ .array(operationArgs)
72
+ .max(MAX_OPERATIONS_PER_CALL)
73
+ .describe('File changes, applied in order to the current files. They are saved together, or none is saved when any fails.'),
74
+ expectedRevision: z
75
+ .string()
76
+ .optional()
77
+ .describe('The revision of the version when you read it; the call fails if any file changed since. ' +
78
+ 'Pass it so that a retried call fails instead of applying its edits twice.'),
79
+ autoBuild: z
80
+ .boolean()
81
+ .default(false)
82
+ .describe('Start a build of the version after the write, and return without waiting for it. Default: false.'),
83
+ });
84
+ /** `label` names the operation, or expectedRevision. */
85
+ function buildPreconditionError(label, reason, detail) {
86
+ return new UserInputError(`Nothing was written: ${label} failed with ${reason}. ${detail}`);
87
+ }
88
+ /** Throws FILE_NOT_FOUND when there is no file at `path`. */
89
+ function findFile(files, path, label) {
90
+ const file = files.get(path);
91
+ if (!file)
92
+ throw buildPreconditionError(label, PRECONDITION_REASON.FILE_NOT_FOUND, `There is no file at ${path}.`);
93
+ return file;
94
+ }
95
+ function validateHash(file, expectedHash, label) {
96
+ if (expectedHash.toLowerCase() === file.hash)
97
+ return;
98
+ const detail = `${file.path} has hash ${file.hash}, not ${expectedHash}.`;
99
+ throw buildPreconditionError(label, PRECONDITION_REASON.HASH_MISMATCH, detail);
100
+ }
101
+ /** Every line break is CRLF; a file with mixed line endings gets no conversion. */
102
+ function hasOnlyCrlfLineBreaks(text) {
103
+ return text.includes('\r\n') && !/(?<!\r)\n/.test(text);
104
+ }
105
+ function convertToCrlf(text) {
106
+ return text.replace(/(?<!\r)\n/g, '\r\n');
107
+ }
108
+ /** The LFs convertToCrlf turns into CRLF: those without a CR before them. */
109
+ function countLoneLineFeeds(text) {
110
+ let count = 0;
111
+ for (let offset = text.indexOf('\n'); offset !== -1; offset = text.indexOf('\n', offset + 1)) {
112
+ if (text[offset - 1] !== '\r')
113
+ count++;
114
+ }
115
+ return count;
116
+ }
117
+ // V8's indexOf keeps its Boyer-Moore shift tables for the last 250 characters of a pattern (kBMMaxShift in
118
+ // https://github.com/v8/v8/blob/main/src/strings/string-search.h). For a longer pattern its time grows with the text
119
+ // length times the pattern length: over 4 s for a 10,001-character pattern in 3 MiB.
120
+ const MAX_INDEX_OF_PATTERN_LENGTH = 250;
121
+ /**
122
+ * The offsets of the first two matches of `pattern` in `text`, counting two matches that overlap as two. A pattern
123
+ * longer than MAX_INDEX_OF_PATTERN_LENGTH is searched with Knuth-Morris-Pratt, which reads each text character once:
124
+ * https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm
125
+ */
126
+ function findMatchOffsets(text, pattern) {
127
+ if (pattern.length <= MAX_INDEX_OF_PATTERN_LENGTH) {
128
+ const offset = text.indexOf(pattern);
129
+ if (offset === -1)
130
+ return [];
131
+ // From the next character, so two matches that overlap count as two.
132
+ const nextOffset = text.indexOf(pattern, offset + 1);
133
+ return nextOffset === -1 ? [offset] : [offset, nextOffset];
134
+ }
135
+ // fallback[i]: the length of the longest proper prefix of pattern[0..i] that is also its suffix.
136
+ const fallback = new Int32Array(pattern.length);
137
+ for (let i = 1, matched = 0; i < pattern.length; i++) {
138
+ while (matched > 0 && pattern.charCodeAt(i) !== pattern.charCodeAt(matched))
139
+ matched = fallback[matched - 1];
140
+ if (pattern.charCodeAt(i) === pattern.charCodeAt(matched))
141
+ matched++;
142
+ fallback[i] = matched;
143
+ }
144
+ let firstOffset;
145
+ for (let i = 0, matched = 0; i < text.length; i++) {
146
+ const charCode = text.charCodeAt(i);
147
+ while (matched > 0 && charCode !== pattern.charCodeAt(matched))
148
+ matched = fallback[matched - 1];
149
+ if (charCode === pattern.charCodeAt(matched))
150
+ matched++;
151
+ if (matched === pattern.length) {
152
+ const offset = i - matched + 1;
153
+ if (firstOffset !== undefined)
154
+ return [firstOffset, offset];
155
+ firstOffset = offset;
156
+ matched = fallback[matched - 1];
157
+ }
158
+ }
159
+ return firstOffset === undefined ? [] : [firstOffset];
160
+ }
161
+ /**
162
+ * The text after the edits, each applied to the text the previous ones left. Each oldText must match exactly once,
163
+ * byte for byte. The one exception: in a file with only CRLF line breaks, LF in oldText and newText is taken as CRLF,
164
+ * since models write LF. Matched as given, such an LF could split a CRLF, and inserted, it would mix line endings.
165
+ */
166
+ function applyTextEdits(originalText, edits, label) {
167
+ const isCrlfFile = hasOnlyCrlfLineBreaks(originalText);
168
+ let text = originalText;
169
+ for (const [editIndex, edit] of edits.entries()) {
170
+ // A lone surrogate can match half of a character, and UTF-8 stores it as U+FFFD.
171
+ if (!edit.oldText.isWellFormed() || !edit.newText.isWellFormed()) {
172
+ throw new UserInputError(`${label} has a lone UTF-16 surrogate in edits[${editIndex}], which UTF-8 cannot store.`);
173
+ }
174
+ // An upper bound of the length after this edit, taken before the CRLF conversion and the search: converting only
175
+ // lengthens oldText, and lengthens newText by one code unit for each LF it turns into CRLF.
176
+ const newTextLength = edit.newText.length + (isCrlfFile ? countLoneLineFeeds(edit.newText) : 0);
177
+ if (text.length - edit.oldText.length + newTextLength > MAX_EDITED_TEXT_LENGTH) {
178
+ throw new UserInputError(`Nothing was written: edits[${editIndex}] of ${label} can make the file longer than ${MAX_EDITED_TEXT_LENGTH} UTF-16 code units, the limit for an edited file.`);
179
+ }
180
+ const oldText = isCrlfFile ? convertToCrlf(edit.oldText) : edit.oldText;
181
+ const newText = isCrlfFile ? convertToCrlf(edit.newText) : edit.newText;
182
+ const [offset, nextOffset] = findMatchOffsets(text, oldText);
183
+ if (offset === undefined) {
184
+ const detail = `oldText of edits[${editIndex}] is not in the file.`;
185
+ throw buildPreconditionError(label, PRECONDITION_REASON.NO_MATCH, detail);
186
+ }
187
+ if (nextOffset !== undefined) {
188
+ const detail = `oldText of edits[${editIndex}] matches more than once; surrounding lines in oldText can narrow it to one match.`;
189
+ throw buildPreconditionError(label, PRECONDITION_REASON.MULTIPLE_MATCHES, detail);
190
+ }
191
+ text = text.slice(0, offset) + newText + text.slice(offset + oldText.length);
192
+ }
193
+ return text;
194
+ }
195
+ /** Writes the file at `target.path` into `version.files`; throws `UserInputError` when it cannot. */
196
+ function applyWrite(version, target, { content, encoding }) {
197
+ const { files, pathIndex } = version;
198
+ const { path, expectedHash, label } = target;
199
+ if (content === undefined)
200
+ throw new UserInputError(`${label} needs content.`);
201
+ // Only a write is checked, so a stored file at such a path can still be edited or deleted.
202
+ validateFilePath(path, label);
203
+ const existing = files.get(path);
204
+ if (existing && expectedHash === undefined) {
205
+ const detail = `${path} exists with hash ${existing.hash}; a write with that hash as expectedHash replaces it.`;
206
+ throw buildPreconditionError(label, PRECONDITION_REASON.FILE_EXISTS, detail);
207
+ }
208
+ if (expectedHash !== undefined)
209
+ validateHash(findFile(files, path, label), expectedHash, label);
210
+ if (!existing)
211
+ pathIndex.validateNewFilePath(path, label);
212
+ const entry = buildSourceFileEntry({ path, content, encoding });
213
+ validateFileContent(entry, label);
214
+ files.set(path, buildInlineSourceFile(entry));
215
+ pathIndex.addFile(path);
216
+ }
217
+ /** Applies `edits` to the file at `target.path` in `files`; throws `UserInputError` when they cannot apply. */
218
+ function applyEdit(files, target, edits) {
219
+ const { path, expectedHash, label } = target;
220
+ if (edits === undefined)
221
+ throw new UserInputError(`${label} needs edits.`);
222
+ const existing = findFile(files, path, label);
223
+ if (expectedHash !== undefined)
224
+ validateHash(existing, expectedHash, label);
225
+ // The same rule get-actor-version returns text by, so a file it returned as utf8 can be edited.
226
+ if (existing.encoding !== 'utf8') {
227
+ const detail = `${path} is not UTF-8 text; only a write can replace it.`;
228
+ throw buildPreconditionError(label, PRECONDITION_REASON.NOT_TEXT, detail);
229
+ }
230
+ const text = applyTextEdits(existing.content, edits, label);
231
+ // A UTF-8 file that `apify push` stored as BASE64 stays BASE64.
232
+ const isBase64 = existing.entry.format === 'BASE64';
233
+ const newContent = isBase64 ? Buffer.from(text).toString('base64') : text;
234
+ files.set(path, buildInlineSourceFile({ name: path, format: isBase64 ? 'BASE64' : 'TEXT', content: newContent }));
235
+ }
236
+ /** Deletes the file at `target.path` from `version.files`; throws `UserInputError` when it cannot. */
237
+ function applyDelete(version, target) {
238
+ const { files, pathIndex } = version;
239
+ const { path, expectedHash, label } = target;
240
+ if (expectedHash === undefined)
241
+ throw new UserInputError(`${label} needs expectedHash.`);
242
+ validateHash(findFile(files, path, label), expectedHash, label);
243
+ files.delete(path);
244
+ pathIndex.deleteFile(path);
245
+ }
246
+ /**
247
+ * The files after the operations, each applied to the files the previous ones left; throws `UserInputError` for the
248
+ * first operation that cannot apply, before anything is written.
249
+ */
250
+ function applyOperations(version, operations) {
251
+ const files = new Map(version.files);
252
+ const pathIndex = new SourcePathIndex(files.keys(), version.folderPaths);
253
+ for (const [index, operation] of operations.entries()) {
254
+ const { type } = operation;
255
+ const target = {
256
+ // Normalized the way get-actor-version lists paths, so a listed path always matches.
257
+ path: posix.normalize(operation.path),
258
+ // AJV turns a null expectedHash into an empty string, which no file has, so it counts as not given.
259
+ expectedHash: operation.expectedHash || undefined,
260
+ label: `operations[${index}] (${type} ${operation.path})`,
261
+ };
262
+ if (type === 'write')
263
+ applyWrite({ files, pathIndex }, target, operation);
264
+ if (type === 'edit')
265
+ applyEdit(files, target, operation.edits);
266
+ if (type === 'delete')
267
+ applyDelete({ files, pathIndex }, target);
268
+ }
269
+ return files;
270
+ }
271
+ /** One entry per file the operations created, updated, or deleted, sorted by path. */
272
+ function buildFileChanges(before, after) {
273
+ const paths = [...new Set([...before.keys(), ...after.keys()])].sort(compareSourcePaths);
274
+ return paths.flatMap((path) => {
275
+ var _a;
276
+ const file = after.get(path);
277
+ if (!file)
278
+ return [{ path, action: 'deleted' }];
279
+ const previousHash = (_a = before.get(path)) === null || _a === void 0 ? void 0 : _a.hash;
280
+ if (previousHash === file.hash)
281
+ return [];
282
+ return [{ path, action: previousHash === undefined ? 'created' : 'updated', hash: file.hash }];
283
+ });
284
+ }
285
+ /**
286
+ * The response to a version PUT that failed with a 5xx, without an HTTP response, such as on a timeout, or on an attempt
287
+ * after the first, whatever its status: the platform may have saved the files of that attempt, or of an earlier one
288
+ * apify-client retried, so the reply gives the revisions that show whether it did. Any other error, such as a 4xx on
289
+ * the first attempt, is rethrown.
290
+ */
291
+ function respondToUnconfirmedSave(error, params) {
292
+ const { target, previousRevision, revision, autoBuild, loadedToolNames } = params;
293
+ const httpStatus = getHttpStatusCode(error);
294
+ const isRetried = error instanceof ApifyApiError && error.attempt > 1;
295
+ if (!isRetried && httpStatus !== undefined && httpStatus < 500)
296
+ throw error;
297
+ logHttpError(error, 'Failed to save the files of an Actor version', {
298
+ actorId: target.actorId,
299
+ versionNumber: target.versionNumber,
300
+ });
301
+ const message = error instanceof Error ? error.message : String(error);
302
+ const apiErrorType = getApifyErrorType(error);
303
+ const failure = httpStatus === undefined
304
+ ? `without an HTTP response: ${message}`
305
+ : `with HTTP ${httpStatus}: ${message}${apiErrorType ? ` (API error type: ${apiErrorType})` : ''}`;
306
+ const readTool = loadedToolNames.includes(HELPER_TOOLS.ACTOR_VERSION_GET)
307
+ ? `; ${HELPER_TOOLS.ACTOR_VERSION_GET} reads the revision`
308
+ : '';
309
+ // autoBuild starts a build only after a confirmed save, so runs keep the previous build either way.
310
+ const buildNote = autoBuild ? ' No build was started.' : '';
311
+ return respondServerError(`Saving version ${target.versionNumber} of ${target.fullName} failed ${failure}. ` +
312
+ 'The platform may still have saved the change. ' +
313
+ `If the version's revision is ${revision}, this call saved it, and if it is ${previousRevision}, ` +
314
+ `it saved nothing${readTool}.${buildNote}`,
315
+ // The status, category, and detail the tool-call engine records for a thrown error.
316
+ { error, detail: message.slice(0, 200) });
317
+ }
318
+ /**
319
+ * https://docs.apify.com/api/v2/actor-get
320
+ * /v2/actors/{actorId}
321
+ * https://docs.apify.com/api/v2/actor-version-put
322
+ * /v2/actors/{actorId}/versions/{versionNumber}
323
+ *
324
+ * The operations apply to the version as read in this call, and the result is stored with one version PUT that
325
+ * carries only the source keys, never envVars or buildTag. Conflicts are caught by each operation's check and by
326
+ * expectedRevision. A save from Apify Console, `apify push`, or another MCP server that lands between this call's read
327
+ * and its PUT is not detected: the platform's version PUT takes no precondition, and this stays so until it gets a
328
+ * conditional one.
329
+ */
330
+ export const updateActorVersion = Object.freeze({
331
+ type: TOOL_TYPE.INTERNAL,
332
+ name: HELPER_TOOLS.ACTOR_VERSION_UPDATE,
333
+ title: 'Update Actor version',
334
+ description: dedent `
335
+ Change files of an Actor version in one call: write, edit, or delete them. Files the call does not mention stay as they are.
336
+ The operations apply in order to a fresh read of the version and are saved together; when any of them fails, nothing is saved.
337
+ - write {path, content, encoding?}: creates a file, or replaces one given its expectedHash.
338
+ - edit {path, edits: [{oldText, newText}], expectedHash?}: replaces text in a UTF-8 file. Each oldText must match exactly once, byte for byte.
339
+ - delete {path, expectedHash}: removes a file. To rename a file, delete it and write it at the new path.
340
+ A call takes at most ${MAX_OPERATIONS_PER_CALL} operations and at most ${MAX_EDITS_PER_CALL} edits in total across its edit operations.
341
+ expectedHash and expectedRevision take the hash and revision from the version listing. A failed check names the operation, the file, and one of FILE_EXISTS, FILE_NOT_FOUND, HASH_MISMATCH, NO_MATCH, MULTIPLE_MATCHES, NOT_TEXT, or REVISION_MISMATCH.
342
+ Binary files take base64 content with encoding base64; files with a binary extension such as .png default to it.
343
+ Only versions stored as files can be changed. Env vars and the build tag are never changed.
344
+ autoBuild starts a build after the write and returns without waiting. Without it, runs keep using the previous build.
345
+
346
+ USAGE:
347
+ - Use to fix a bug or add a feature in an Actor's code, a few files at a time.
348
+
349
+ USAGE EXAMPLES:
350
+ - user_input: Fix the typo in src/main.js of my Actor john/my-scraper
351
+ - user_input: Add a README to my Actor and rebuild it`,
352
+ // `fixZodSchemaRequired` strips `autoBuild` from `required` because it has a default.
353
+ inputSchema: fixZodSchemaRequired(z.toJSONSchema(updateActorVersionArgs)),
354
+ outputSchema: updateActorVersionToolOutputSchema,
355
+ ajvValidate: compileSchema(z.toJSONSchema(updateActorVersionArgs)),
356
+ annotations: {
357
+ title: 'Update Actor version',
358
+ readOnlyHint: false,
359
+ // Writes and deletes overwrite files.
360
+ destructiveHint: true,
361
+ idempotentHint: false,
362
+ // autoBuild starts a build, like build-actor.
363
+ openWorldHint: true,
364
+ },
365
+ redactArgs: (args) => redactSourceToolArgs(args, {
366
+ keys: ['actor', 'versionNumber', 'expectedRevision', 'autoBuild'],
367
+ listKey: 'operations',
368
+ entryKeys: ['type', 'path', 'encoding', 'expectedHash'],
369
+ }),
370
+ call: async (toolArgs) => {
371
+ const { args, apifyClient: client, signal, loadedToolNames } = toolArgs;
372
+ const parsed = updateActorVersionArgs.parse(args);
373
+ const editCount = parsed.operations
374
+ .filter(({ type }) => type === 'edit')
375
+ .reduce((count, { edits = [] }) => count + edits.length, 0);
376
+ if (editCount > MAX_EDITS_PER_CALL) {
377
+ return respondUserError(`Nothing was written: the operations have ${editCount} edits in total, and one call takes at most ${MAX_EDITS_PER_CALL}.`);
378
+ }
379
+ try {
380
+ for (const [index, { path }] of parsed.operations.entries()) {
381
+ validatePathCharacters(path, `operations[${index}]`);
382
+ }
383
+ // TODO: The Apify API has no way to read or change single files of an Actor's source, so even a one-line
384
+ // edit reads the whole version here and writes all its files back with the PUT below. That read and write
385
+ // is also what leaves a save landing between them undetected. Once the API can apply atomic changes to an
386
+ // Actor's source, send only the changed files instead.
387
+ const { actor, fullName } = await fetchActor(client, parsed.actor);
388
+ const version = resolveVersion(actor, parsed.versionNumber, parsed.actor);
389
+ const { versionNumber } = version;
390
+ const storedEntries = extractSourceFiles(version, `Version ${versionNumber} of ${fullName}`);
391
+ const before = new Map(buildFilesManifest(storedEntries).map((file) => [file.path, file]));
392
+ const previousRevision = buildFilesRevision([...before.values()]);
393
+ // AJV turns a null expectedRevision into an empty string, which no version has, so it counts as not given.
394
+ if (parsed.expectedRevision && parsed.expectedRevision.toLowerCase() !== previousRevision) {
395
+ const detail = `The version's revision is ${previousRevision}, not ${parsed.expectedRevision}.`;
396
+ throw buildPreconditionError('expectedRevision', PRECONDITION_REASON.REVISION_MISMATCH, detail);
397
+ }
398
+ const folderPaths = storedEntries.filter(isFolderEntry).map(({ name }) => posix.normalize(name));
399
+ const after = applyOperations({ files: before, folderPaths }, parsed.operations);
400
+ const revision = buildFilesRevision([...after.values()]);
401
+ // A cancel during the read writes nothing; per the MCP spec the cancelled request gets no response.
402
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted)
403
+ return respondAborted();
404
+ // Nothing to write, so autoBuild starts no build; the stored files may already be in the build runs use.
405
+ if (revision === previousRevision) {
406
+ return respondWithBuild({
407
+ structuredContent: { revision, changed: false, changes: [] },
408
+ summary: `Nothing changed in version ${versionNumber} of ${fullName}, so nothing was written.`,
409
+ nextStep: 'No build was started.',
410
+ });
411
+ }
412
+ // Console keeps an empty folder as an entry of its own, which goes back as it was.
413
+ const sourceFiles = [
414
+ ...storedEntries.filter(isFolderEntry),
415
+ ...[...after.values()].map(({ entry }) => entry),
416
+ ];
417
+ try {
418
+ await client
419
+ .actor(actor.id)
420
+ .version(versionNumber)
421
+ .update({ sourceType: ActorSourceType.SourceFiles, sourceFiles });
422
+ }
423
+ catch (error) {
424
+ return respondToUnconfirmedSave(error, {
425
+ target: { actorId: actor.id, versionNumber, fullName },
426
+ previousRevision,
427
+ revision,
428
+ autoBuild: parsed.autoBuild,
429
+ loadedToolNames,
430
+ });
431
+ }
432
+ const changes = buildFileChanges(before, after);
433
+ const emptyPaths = changes.flatMap(({ path }) => { var _a; return (((_a = after.get(path)) === null || _a === void 0 ? void 0 : _a.sizeBytes) === 0 ? [path] : []); });
434
+ return await respondAfterWrite({
435
+ toolArgs,
436
+ autoBuild: parsed.autoBuild,
437
+ target: { actorId: actor.id, versionNumber },
438
+ structuredContent: { revision, changed: true, changes, ...buildEmptyFilesWarnings(emptyPaths) },
439
+ summary: `Updated version ${versionNumber} of ${fullName}.`,
440
+ });
441
+ }
442
+ catch (error) {
443
+ return respondToSourceToolError(error);
444
+ }
445
+ },
446
+ });
447
+ //# sourceMappingURL=update_actor_version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update_actor_version.js","sourceRoot":"","sources":["../../../src/tools/versions/update_actor_version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEzE,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC1F,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AA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