post-engineer-mcp 1.42.0 → 1.44.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 (50) hide show
  1. package/README.md +10 -5
  2. package/dist/client-batch.d.ts +6 -0
  3. package/dist/client-batch.js +4 -0
  4. package/dist/client-batch.js.map +1 -0
  5. package/dist/client-experiments.d.ts +15 -0
  6. package/dist/client-experiments.js +11 -0
  7. package/dist/client-experiments.js.map +1 -0
  8. package/dist/client-posts.d.ts +4 -0
  9. package/dist/client-posts.js +7 -0
  10. package/dist/client-posts.js.map +1 -1
  11. package/dist/client-types.d.ts +9 -2
  12. package/dist/client.d.ts +1 -1
  13. package/dist/client.js +7 -6
  14. package/dist/client.js.map +1 -1
  15. package/dist/index.js +12 -4
  16. package/dist/index.js.map +1 -1
  17. package/dist/limits.d.ts +30 -0
  18. package/dist/limits.js +30 -0
  19. package/dist/limits.js.map +1 -1
  20. package/dist/persona-update.d.ts +84 -0
  21. package/dist/persona-update.js +37 -0
  22. package/dist/persona-update.js.map +1 -0
  23. package/dist/recipe-session.d.ts +4 -0
  24. package/dist/recipe-session.js +2 -1
  25. package/dist/recipe-session.js.map +1 -1
  26. package/dist/schedule-shapes.d.ts +18 -2
  27. package/dist/schedule-shapes.js +12 -6
  28. package/dist/schedule-shapes.js.map +1 -1
  29. package/dist/script-segments.d.ts +4 -2
  30. package/dist/script-segments.js +19 -7
  31. package/dist/script-segments.js.map +1 -1
  32. package/dist/single-video-shape.d.ts +62 -8
  33. package/dist/single-video-shape.js +16 -1
  34. package/dist/single-video-shape.js.map +1 -1
  35. package/dist/tools-batch.d.ts +755 -0
  36. package/dist/tools-batch.js +141 -0
  37. package/dist/tools-batch.js.map +1 -0
  38. package/dist/tools-experiments.d.ts +724 -0
  39. package/dist/tools-experiments.js +165 -0
  40. package/dist/tools-experiments.js.map +1 -0
  41. package/dist/tools-posts.d.ts +1 -0
  42. package/dist/tools-posts.js +17 -1
  43. package/dist/tools-posts.js.map +1 -1
  44. package/dist/tools-single-video.d.ts +9 -0
  45. package/dist/tools-single-video.js +31 -13
  46. package/dist/tools-single-video.js.map +1 -1
  47. package/dist/tools.d.ts +17 -92
  48. package/dist/tools.js +6 -27
  49. package/dist/tools.js.map +1 -1
  50. package/package.json +1 -1
@@ -0,0 +1,141 @@
1
+ import { z } from 'zod';
2
+ import { applyBatchDiscount } from './client-batch.js';
3
+ import { ApiError, getErrorMessage } from './errors.js';
4
+ import { BATCH_FREE_EVERY, BATCH_KEY_MAX_LENGTH, BATCH_WINDOW_MINUTES, BATCH_KEY_PATTERN, MAX_BATCH_VIDEOS } from './limits.js';
5
+ import { GeneratePersonaVideoShape } from './single-video-shape.js';
6
+ import { sanitizeEngineError } from './tools.js';
7
+ import { generatePersonaVideoOutcome } from './tools-single-video.js';
8
+ //---------------
9
+ // generate_persona_video_batch — the batch discount of issue #487.
10
+ //
11
+ // Creates every video of the batch with generate-and-schedule, one after
12
+ // the other, so the engine receives them back to back and renders them in
13
+ // one warm Modal container. Each video is charged its normal price at
14
+ // creation; then POST /api/videos/batch-discount groups them and credits
15
+ // back the cheapest face video of every BATCH_FREE_EVERY. The server owns
16
+ // every discount rule; this tool only reports what it answered.
17
+ //
18
+ // Idempotent: video N uses the key `batch-<batchKey>-v<N>`, so calling the
19
+ // tool again with the same batchKey and the same videos in the same order
20
+ // replays the videos already created (no second charge), creates the
21
+ // missing ones and retries the discount.
22
+ //---------------
23
+ export const BatchVideoSchema = z
24
+ .object(GeneratePersonaVideoShape)
25
+ .omit({ idempotencyKey: true, experiment: true, recipe: true })
26
+ .strict();
27
+ export const GeneratePersonaVideoBatchShape = {
28
+ batchKey: z
29
+ .string()
30
+ .min(1)
31
+ .max(BATCH_KEY_MAX_LENGTH)
32
+ .regex(BATCH_KEY_PATTERN, 'batchKey may only contain letters, digits, "-" and "_".')
33
+ .describe('A name for this batch, unique per batch (e.g. "launch-week-1"). Reuse it with the same videos in the same order to retry: created videos replay instead of being charged again.'),
34
+ videos: z
35
+ .array(BatchVideoSchema)
36
+ .min(2, 'A batch needs at least 2 videos')
37
+ .max(MAX_BATCH_VIDEOS, `A batch holds at most ${MAX_BATCH_VIDEOS} videos`)
38
+ .describe(`The videos, each with the same fields as generate_persona_video (no idempotencyKey, experiment or recipe). Up to ${MAX_BATCH_VIDEOS}.`),
39
+ };
40
+ export const GeneratePersonaVideoBatchSchema = z.object(GeneratePersonaVideoBatchShape);
41
+ export const GeneratePersonaVideoBatchDescription = `Generate and schedule a BATCH of persona videos in one call (2-${MAX_BATCH_VIDEOS}), cheaper than one by one: for every ${BATCH_FREE_EVERY} videos with the persona face in the batch, the cheapest one is free (its tokens are credited back right after creation). Faceless videos can be in the batch but pay full price, do not count toward the ${BATCH_FREE_EVERY} and are never free. Each video takes the same fields as generate_persona_video and is created and dispatched right away, one after the other, so the batch renders together. All videos must be created within ${BATCH_WINDOW_MINUTES} minutes of the first. Cancelling a video of a discounted batch (cancel_schedule) gives back the discount the batch no longer earns: it is withheld from that video's refund. If a video fails validation or creation, the videos before it stay created and discounted; fix the error and call again with the same batchKey and the same videos in the same order — created videos replay without a new charge.`;
42
+ function discountFailureText(error) {
43
+ const message = sanitizeEngineError(getErrorMessage(error));
44
+ const code = error instanceof ApiError ? error.code : null;
45
+ const next = PERMANENT_DISCOUNT_CODES.has(code ?? '')
46
+ ? ' This batch cannot earn the discount; use a new batchKey for future videos.'
47
+ : ' Call generate_persona_video_batch again with the same arguments to retry the discount (created videos replay without a new charge).';
48
+ return `The batch discount could not be applied: ${message}. The videos are created and charged at full price.${next}`;
49
+ }
50
+ function textOf(response) {
51
+ return response.content.map((part) => (part.type === 'text' ? part.text : '')).join('\n');
52
+ }
53
+ /** Codes a retry of the same videos can never clear. */
54
+ const PERMANENT_DISCOUNT_CODES = new Set(['BATCH_WINDOW_EXCEEDED', 'BATCH_CONFLICT', 'BATCH_TOO_LARGE']);
55
+ function narrowDiscount(result) {
56
+ if (typeof result !== 'object' || result === null)
57
+ return null;
58
+ const record = result;
59
+ if (record.success !== true)
60
+ return null;
61
+ const numbers = ['faceVideos', 'earnedFreeVideos', 'discountTokens', 'chargedTokens'];
62
+ for (const key of numbers) {
63
+ if (typeof record[key] !== 'number')
64
+ return null;
65
+ }
66
+ if (!Array.isArray(record.freeVideos))
67
+ return null;
68
+ const warnings = Array.isArray(record.warnings)
69
+ ? record.warnings.filter((warning) => typeof warning === 'string')
70
+ : [];
71
+ const videos = typeof record.videos === 'number' ? record.videos : record.faceVideos;
72
+ return {
73
+ videos,
74
+ faceVideos: record.faceVideos,
75
+ earnedFreeVideos: record.earnedFreeVideos,
76
+ freeVideos: record.freeVideos.length,
77
+ discountTokens: record.discountTokens,
78
+ chargedTokens: record.chargedTokens,
79
+ warnings,
80
+ };
81
+ }
82
+ function describeDiscount(summary) {
83
+ const lines = [
84
+ `Batch: ${summary.faceVideos} face video(s); ${summary.freeVideos} free (${summary.discountTokens} token(s) credited back); ${summary.chargedTokens} token(s) charged in total.`,
85
+ ];
86
+ const missing = BATCH_FREE_EVERY - (summary.faceVideos % BATCH_FREE_EVERY);
87
+ // The cap is on every video in the batch, faceless included.
88
+ if (summary.videos + missing <= MAX_BATCH_VIDEOS) {
89
+ lines.push(`${missing} more face video(s) in this batch would make one more video free.`);
90
+ }
91
+ if (summary.warnings.length > 0) {
92
+ lines.push(`The discount was not fully applied (${summary.warnings.join(', ')}). Call generate_persona_video_batch again with the same arguments to retry it.`);
93
+ }
94
+ return lines.join('\n');
95
+ }
96
+ export async function handleGeneratePersonaVideoBatch(client, args) {
97
+ const scheduleIds = [];
98
+ const parts = [];
99
+ let stoppedAt = null;
100
+ for (const [index, video] of args.videos.entries()) {
101
+ const { response, failedSlotIds, scheduleId } = await generatePersonaVideoOutcome(client, {
102
+ ...video,
103
+ idempotencyKey: `batch-${args.batchKey}-v${index + 1}`,
104
+ });
105
+ if (response.isError === true) {
106
+ stoppedAt = `Video ${index + 1} of ${args.videos.length} was not created: ${textOf(response)}`;
107
+ break;
108
+ }
109
+ if (scheduleId !== null)
110
+ scheduleIds.push(scheduleId);
111
+ const failed = failedSlotIds.length > 0 ? ' (its generation failed; its tokens are refunded)' : '';
112
+ parts.push(`Video ${index + 1}${failed}:\n${textOf(response)}`);
113
+ }
114
+ let discountText = 'No video was created, so no batch discount applies.';
115
+ let discountFailed = false;
116
+ if (scheduleIds.length > 0) {
117
+ try {
118
+ const summary = narrowDiscount(await applyBatchDiscount(client, { batchKey: args.batchKey, scheduleIds }));
119
+ if (summary === null) {
120
+ discountFailed = true;
121
+ discountText = 'The batch discount answer could not be read. Call generate_persona_video_batch again with the same arguments to retry it.';
122
+ }
123
+ else {
124
+ discountFailed = summary.warnings.length > 0;
125
+ discountText = describeDiscount(summary);
126
+ }
127
+ }
128
+ catch (error) {
129
+ discountFailed = true;
130
+ discountText = discountFailureText(error);
131
+ }
132
+ }
133
+ const header = stoppedAt === null
134
+ ? `Created ${scheduleIds.length} video(s) in batch ${args.batchKey}.`
135
+ : `Batch ${args.batchKey} stopped: ${scheduleIds.length} of ${args.videos.length} video(s) created.\n${stoppedAt}\nFix the error and call generate_persona_video_batch again with the same batchKey and the same videos in the same order: created videos replay without a new charge.`;
136
+ return {
137
+ content: [{ type: 'text', text: [header, discountText, ...parts].join('\n\n') }],
138
+ ...(stoppedAt !== null || discountFailed ? { isError: true } : {}),
139
+ };
140
+ }
141
+ //# sourceMappingURL=tools-batch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools-batch.js","sourceRoot":"","sources":["../src/tools-batch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAA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