post-engineer-mcp 1.31.0 → 1.33.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 +51 -9
  2. package/dist/analytics.d.ts +1 -0
  3. package/dist/analytics.js +23 -1
  4. package/dist/analytics.js.map +1 -1
  5. package/dist/client-posts.d.ts +10 -0
  6. package/dist/client-posts.js +15 -0
  7. package/dist/client-posts.js.map +1 -0
  8. package/dist/client-publishing-accounts.d.ts +3 -0
  9. package/dist/client-publishing-accounts.js +18 -0
  10. package/dist/client-publishing-accounts.js.map +1 -0
  11. package/dist/client-types.d.ts +140 -0
  12. package/dist/client-types.js +2 -0
  13. package/dist/client-types.js.map +1 -0
  14. package/dist/client-user-media.d.ts +29 -0
  15. package/dist/client-user-media.js +135 -0
  16. package/dist/client-user-media.js.map +1 -0
  17. package/dist/client-video-task.d.ts +2 -0
  18. package/dist/client-video-task.js +9 -0
  19. package/dist/client-video-task.js.map +1 -0
  20. package/dist/client.d.ts +11 -134
  21. package/dist/client.js +32 -40
  22. package/dist/client.js.map +1 -1
  23. package/dist/cloned-voice-client.d.ts +11 -0
  24. package/dist/cloned-voice-client.js +134 -0
  25. package/dist/cloned-voice-client.js.map +1 -0
  26. package/dist/cloned-voice-tools.d.ts +70 -0
  27. package/dist/cloned-voice-tools.js +60 -0
  28. package/dist/cloned-voice-tools.js.map +1 -0
  29. package/dist/http-auth.d.ts +27 -0
  30. package/dist/http-auth.js +148 -0
  31. package/dist/http-auth.js.map +1 -0
  32. package/dist/http-rate-limit.d.ts +14 -0
  33. package/dist/http-rate-limit.js +28 -0
  34. package/dist/http-rate-limit.js.map +1 -0
  35. package/dist/http-transport.d.ts +13 -0
  36. package/dist/http-transport.js +311 -0
  37. package/dist/http-transport.js.map +1 -0
  38. package/dist/image-guards.d.ts +6 -0
  39. package/dist/image-guards.js +30 -0
  40. package/dist/image-guards.js.map +1 -0
  41. package/dist/index.js +69 -29
  42. package/dist/index.js.map +1 -1
  43. package/dist/language.d.ts +11 -0
  44. package/dist/language.js +19 -0
  45. package/dist/language.js.map +1 -0
  46. package/dist/limits.d.ts +39 -0
  47. package/dist/limits.js +39 -0
  48. package/dist/limits.js.map +1 -1
  49. package/dist/prompts.d.ts +9 -0
  50. package/dist/prompts.js +125 -0
  51. package/dist/prompts.js.map +1 -0
  52. package/dist/require-title.d.ts +1 -0
  53. package/dist/require-title.js +12 -0
  54. package/dist/require-title.js.map +1 -0
  55. package/dist/schedule-shapes.d.ts +70 -0
  56. package/dist/schedule-shapes.js +98 -0
  57. package/dist/schedule-shapes.js.map +1 -0
  58. package/dist/script-segments.d.ts +49 -0
  59. package/dist/script-segments.js +222 -0
  60. package/dist/script-segments.js.map +1 -0
  61. package/dist/single-video-shape.d.ts +340 -0
  62. package/dist/single-video-shape.js +74 -0
  63. package/dist/single-video-shape.js.map +1 -0
  64. package/dist/tools-call.d.ts +4 -0
  65. package/dist/tools-call.js +25 -0
  66. package/dist/tools-call.js.map +1 -0
  67. package/dist/tools-posts.d.ts +41 -0
  68. package/dist/tools-posts.js +45 -0
  69. package/dist/tools-posts.js.map +1 -0
  70. package/dist/tools-publishing-accounts.d.ts +29 -0
  71. package/dist/tools-publishing-accounts.js +38 -0
  72. package/dist/tools-publishing-accounts.js.map +1 -0
  73. package/dist/tools-single-video.d.ts +10 -0
  74. package/dist/tools-single-video.js +143 -0
  75. package/dist/tools-single-video.js.map +1 -0
  76. package/dist/tools-user-media.d.ts +27 -0
  77. package/dist/tools-user-media.js +38 -0
  78. package/dist/tools-user-media.js.map +1 -0
  79. package/dist/tools.d.ts +32 -230
  80. package/dist/tools.js +42 -295
  81. package/dist/tools.js.map +1 -1
  82. package/dist/video-task-tools.d.ts +14 -0
  83. package/dist/video-task-tools.js +20 -0
  84. package/dist/video-task-tools.js.map +1 -0
  85. package/dist/voice-filters.d.ts +21 -0
  86. package/dist/voice-filters.js +76 -0
  87. package/dist/voice-filters.js.map +1 -0
  88. package/package.json +6 -2
package/README.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  Public MCP (Model Context Protocol) server for [Post Engineer](https://post-engineer.com/). It lets AI agents (Claude, Cursor, Codex, and OpenCode) create personas, generate videos, check generation status, and schedule posts directly on your Post Engineer account.
4
4
 
5
+ Post Engineer is open source under the Apache License, Version 2.0 (see
6
+ [LICENSE](../../LICENSE) in the repo root). You can self-host the whole
7
+ platform on your own VPS (see
8
+ [docs/SELF_HOSTING.md](../../docs/SELF_HOSTING.md)) instead of using the
9
+ hosted platform — lip sync (LongCat) runs on Modal.com, whose Starter plan
10
+ includes $30/month in compute credits (see
11
+ [modal.com/pricing](https://modal.com/pricing)). We are not Modal: this
12
+ free-credit offer is theirs and can end at any time; usage beyond the
13
+ credits is billed by Modal.
14
+
5
15
  ## What is https://post-engineer.com/?
6
16
 
7
17
  [https://post-engineer.com/](https://post-engineer.com/) is the Post Engineer web platform. You use it to:
@@ -90,41 +100,54 @@ The `Authorization: Bearer` API key header is sent to the configured base URL, s
90
100
  ## Tools
91
101
 
92
102
  - `list_personas`: list existing personas.
93
- - `list_voices`: list available persona voices (live catalog from the platform, not hardcoded).
103
+ - `list_voices`: list available persona voices (live catalog: 65 English house voices with `gender`/`accent`/`kind`, plus your ready clones). Each voice has a `description` of how it sounds. Optional filters: `gender` (`female`|`male`), `origin` (`us`|`gb`|`character`), `search` (words matched in name/description, e.g. `"deep calm"`).
104
+ - `list_cloned_voices`: list your per-user Chatterbox voice clones (status and `voice_id` when ready).
105
+ - `create_cloned_voice`: register a voice clone from a short HTTPS audio URL (requires `consent: true` and `denoise`: `true` cleans background noise first, `false` keeps the original).
106
+ - `get_cloned_voice`: get one voice clone by id — poll its `status` after `create_cloned_voice` until `ready` (then `voice_id` is set) or `failed`.
107
+ - `delete_cloned_voice`: delete a voice clone by id.
108
+ - `preview_cloned_voice`: synthesize a short MP3 preview for a ready clone (returns base64 audio). Optional `text` (1-300 chars, English) makes the clone speak your words instead of the fixed sample; previews are free and limited to 10 per user per day.
94
109
  - `list_faces`: list default/stock persona faces (live catalog from `/api/persona/faces`). Each item has `id`, `url`, `name`, `gender`, `age` (single number, e.g. 23), `ethnicity`, `hair`, and `description` (English) so agents can choose without the photo; pass a face `url` as `avatarUrl` on `create_persona`.
95
- - `create_persona`: create an AI persona (avatar, voice, language, niche). `avatarUrl` is REQUIRED — every persona has a face; "no face" is a per-video choice (`options.faceless` on `generate_persona_videos`).
110
+ - `create_persona`: create an AI persona (avatar, voice, language, niche). `avatarUrl` is REQUIRED — every persona has a face; "no face" is a per-video choice (`options.faceless` on `generate_persona_video`).
96
111
  - `update_persona`: update an existing persona (only the provided fields change).
97
112
  - `get_token_balance`: get the prepaid token wallet balance. Check before generating videos, which cost tokens.
98
- - `generate_persona_videos`: generate and schedule 1-10 persona videos in ONE operation — generation is always tied to publishing (one call = generate + schedule + auto-publish; no orphan videos, no separate schedule step). `personaId` is optional: omit it for a faceless post with no persona, in which case set `options.faceless` and `options.voiceId` (or `options.audioUrl`), plus `options.scriptPrompt` / `videoAspect` / `language` / `niche` as needed — a persona is not only a face, it is where voice, script, aspect and niche come from. With a persona, `options.faceless: true` drops only the face and the persona still supplies the rest. `topics` is one topic per video; the server assigns publish slots across `startAt` + `times` (daily `HH:MM` publish times in `timezone`). Set `mode: 'asap'` to publish each video the moment its generation finishes instead of scheduling it — `startAt` and `times` must NOT be set then. Pass `providers` plus per-provider account IDs (see the account ID table below). Every slot must be 3h–30d ahead. `idempotencyKey` is generated automatically; reuse it to retry without generating twice (`replayed: true`). Poll each slot's `taskId` with `get_video_task_progress`.
113
+ - `validate_script`: validate a segments script mechanically, without spending tokens — hook first, CTA last, exactly one of each, word limits (total 60-200, body at least 30, CTA 5-20, hook 15-40 words before TTS). Returns the word counts and the hook window (8-12 seconds spoken). Measured hook duration is pending a hook-only TTS endpoint and is reported as pending, never invented.
114
+ - `upload_media`: upload a local image for a video segment and get a `mediaId` to use in a segment's `media` field. JPG/JPEG, PNG, or WebP, max 8MB (the engine photo limit, not the 10MB library limit); the real content type is validated, not the extension. The file is stored as a temporary engine asset (1 hour TTL): upload shortly before generating, since a scheduled slot far in the future may outlive the asset and the segment then renders without it. Returns only the `mediaId`.
115
+ - `check_media`: mechanically check one public image URL for a segment, without an LLM and without judging relevance (the agent, who sees the image, decides relevance). Returns exactly one code: `ok`, `blocked_403`, `not_image`, `too_small`, `too_large`, `timeout`, or `face_detected`. No fake User-Agent or Referer is sent to bypass hotlink blocks, and private addresses are never fetched.
116
+ - `generate_persona_video`: generate and schedule ONE persona video from a complete script — generation is always tied to publishing (one call = generate + schedule + auto-publish; no orphan videos, no separate schedule step). Send the full script as `segments` (first `hook`, then body segments, last `cta`; 60-200 words total, body at least 30, CTA 5-20, hook 15-40 words ending with terminal punctuation) — no LLM expands it. `title` is the slot label for this video. `personaId` is optional: omit it for a faceless post with no persona, in which case set `options.faceless` and `options.voiceId` (or `options.audioUrl`), plus `videoAspect` / `language` / `niche` as needed. Pass `providers` plus per-provider account IDs (see the account ID table below), `startAt` + `times` in `timezone` (or `mode: 'asap'` with no `startAt`/`times`). The slot must be 3h–30d ahead. `idempotencyKey` is generated automatically; reuse it to retry without generating twice (`replayed: true`). Poll the slot's `taskId` with `get_video_task_progress`.
99
117
  - `get_video_status`: check generation status and get the final video URL.
100
- - `get_video_task_progress`: poll one video task for machine-readable progress: returns `{task_id, state, progress, stage, error}`. `error` is the engine failure reason when `state` is `-1` (failed), `null` otherwise. Use per-video (1/6, 2/6, ...) after `generate_persona_videos`; prefer this over `get_video_status` when only progress matters.
101
- - `list_persona_images`: list a persona's image library (id, tag, description, is_primary). Use the ids with `generate_persona_videos` `options.imageId` to force a specific image for every video in one call.
118
+ - `get_video_task_progress`: poll one video task for machine-readable progress: returns `{task_id, state, progress, stage, error}`. `error` is the engine failure reason when `state` is `-1` (failed), `null` otherwise. Use per-video after `generate_persona_video`; prefer this over `get_video_status` when only progress matters.
119
+ - `cancel_video_task`: cancel/remove one of your video tasks on the engine by `taskId` (from `get_video_status`, `get_video_task_progress`, `get_post` or `list_posts`). Only your own task can be cancelled; a persona-scoped API key can only cancel tasks belonging to its personas. Unknown or already-finished tasks return an error; no token refund is issued by this call.
120
+ - `list_persona_images`: list a persona's image library (id, tag, description, is_primary). Use the ids with `generate_persona_video` `options.imageId` to force a specific image for every video in one call.
102
121
  - `add_persona_image`: add an image to a persona image library from a local file path (JPG/JPEG, PNG, or WebP, max 9MB). Optional tag and description drive the deterministic per-video image selection.
103
122
  - `update_persona_image`: update a persona library image tag, description, or primary flag.
104
123
  - `remove_persona_image`: remove an image from a persona image library.
105
124
  - `publish_video_direct`: publish a ready-made video file directly to social accounts — no generation, no schedule (local .mp4/.mov, max 2GB; YouTube needs title, description, tags, privacyStatus; others need caption).
106
125
  - `list_social_accounts`: list connected social accounts with the account IDs needed for scheduling.
126
+ - `get_persona_publishing_accounts`: list a persona's default publishing accounts per provider. `generate_persona_video` falls back to these when no account IDs are passed; explicit IDs always win.
127
+ - `set_persona_publishing_accounts`: replace a persona's default publishing accounts per provider (account IDs from `list_social_accounts`; providers mapped to `[]` keep no defaults).
107
128
  - `connect_account`: connect a social account. For youtube/instagram/linkedin: returns an authorization URL — the user must open it in a browser and authorize, then the account connects automatically (verify with `list_social_accounts`). For bluesky: connects directly with handle + app password.
108
129
  - `list_schedules`: list automation schedules.
109
130
  - `list_posts`: list upcoming (scheduled) and past (published/failed) posts across all connected accounts.
110
131
  - `cancel_schedule`: cancel a schedule by its ID.
111
- - `get_slot`: get one scheduled post's full detail by slot ID (status, topic, scheduled time, progress, schedule, persona).
112
- - `update_slot_topic`: edit the topic of a scheduled post that has not started generating yet.
132
+ - `get_slot`: get one scheduled post's full detail by slot ID (status, title, scheduled time, progress, schedule, persona).
133
+ - `update_slot_title`: edit the title of a scheduled post that has not started generating yet.
113
134
  - `delete_slot`: delete one scheduled post slot (only pending/awaiting or failed slots; never the schedule's last slot).
114
135
  - `list_video_generations`: list the video generation history, newest first (status, error code, token refunds).
115
136
  - `get_video_generation`: get one video generation's detail by generation ID.
137
+ - `get_post`: get one post's full detail by id, whether the id is a slot id or a generation id (the server resolves it; the response says `kind: "slot"` or `kind: "generation"`). Both kinds carry live generation progress.
138
+ - `get_post_metrics`: per-video performance snapshots (views, likes, comments, saves) for a `window` of `24h` or `7d`, newest first. Optional exact-match filters: `persona` (uuid, or `^@none` for posts without a persona), `account`, `provider`, `angle` (or `^@none`). Returns `rows` and `truncated`.
116
139
  - `list_token_transactions`: list the token ledger — every credit and debit (purchases, generation spends, refunds), newest first.
117
140
  - `get_persona_delete_preview`: preview what deleting a persona would remove (counts + per-video download links). Read-only.
118
141
  - `delete_persona`: DESTRUCTIVE — delete a persona with all its schedules, slots, videos, and image library. No token refunds.
119
142
  - `disconnect_account`: disconnect a social account by provider and account ID.
120
143
 
121
- ### Social account IDs for `generate_persona_videos`
144
+ ### Social account IDs for `generate_persona_video`
122
145
 
123
146
  Each provider's `*AccountIds` field expects the provider's account identifier
124
147
  from `list_social_accounts` — **not** the `recordId` (that is the internal
125
148
  database row id and is rejected):
126
149
 
127
- | Provider | `generate_persona_videos` field | Use this `list_social_accounts` field |
150
+ | Provider | `generate_persona_video` field | Use this `list_social_accounts` field |
128
151
  |---|---|---|
129
152
  | YouTube | `youtubeAccountIds` | `channelId` |
130
153
  | Instagram | `instagramAccountIds` | `igUserId` |
@@ -133,7 +156,26 @@ database row id and is rejected):
133
156
 
134
157
  Passing a `recordId` fails fast with an error naming the right field.
135
158
 
159
+ ## Prompts (slash commands)
160
+
161
+ The server serves the prompts hub from the Post Engineer web platform over
162
+ the MCP [prompts capability](https://modelcontextprotocol.io/docs/concepts/prompts),
163
+ so MCP clients (Cursor, Claude) list them as slash commands. Each prompt is
164
+ zero-arg; placeholders (`[PERSONA_ID]`, `[STORY_TITLE]`, …) stay in the text
165
+ for you to fill in when you run it. The copy is kept in sync with the web
166
+ hub by a sync test (`prompts-sync.test.ts`).
167
+
168
+ - `/daily-news`: Daily news becomes a video — turn one top GNews story of the day into one persona video, validated before any token is spent.
169
+ - `/github-prs`: GitHub PRs become videos — turn a GitHub pull request into one persona video.
170
+ - `/full-setup`: Full setup becomes videos — connect accounts, create a persona, validate the script, and publish your first video without skipping a step.
171
+
172
+ Add a new prompt to the web hub (`apps/web/app/recipes/prompts.ts` + its
173
+ i18n title/description), then copy the same slug, title, description, and
174
+ exact prompt text into `src/prompts.ts`; `pnpm test` fails if the copies
175
+ drift.
176
+
136
177
  ## Links
137
178
 
138
179
  - Platform: https://post-engineer.com/
139
180
  - API keys: https://post-engineer.com/api-keys
181
+ - Recipes: [docs/recipes/daily-news.md](../../docs/recipes/daily-news.md) (daily news becomes a video)
@@ -1,3 +1,4 @@
1
1
  export declare const DEFAULT_POSTHOG_HOST = "https://eu.i.posthog.com";
2
2
  export declare function trackEvent(eventName: string, properties?: Record<string, unknown>): void;
3
3
  export declare function resetAnalyticsForTesting(): void;
4
+ export declare function withTracking<TArgs extends Record<string, unknown>, TResult>(toolName: string, handler: (args: TArgs) => Promise<TResult>): (args: TArgs) => Promise<TResult>;
package/dist/analytics.js CHANGED
@@ -91,7 +91,10 @@ export function trackEvent(eventName, properties) {
91
91
  posthog.capture({
92
92
  distinctId: 'post-engineer-mcp',
93
93
  event: eventName,
94
- properties: props,
94
+ // Origin tags: ours win over caller-supplied values — the origin
95
+ // of an event is a pipeline fact, not caller input, so it can
96
+ // never be spoofed away.
97
+ properties: { ...props, source: 'mcp', environment: getEnvironment() },
95
98
  });
96
99
  }
97
100
  catch {
@@ -104,6 +107,14 @@ export function trackEvent(eventName, properties) {
104
107
  }
105
108
  }
106
109
  //---------------
110
+ // Deployment tag for PostHog: 'production' only when NODE_ENV says so.
111
+ // The MCP is a local stdio tool; NODE_ENV is unset in normal use, so
112
+ // MCP events report 'development' — which is what they are.
113
+ //---------------
114
+ function getEnvironment() {
115
+ return process.env['NODE_ENV'] === 'production' ? 'production' : 'development';
116
+ }
117
+ //---------------
107
118
  // Test seam: reset the cached client between tests.
108
119
  // Not used in production code.
109
120
  //---------------
@@ -112,4 +123,15 @@ export function resetAnalyticsForTesting() {
112
123
  warned = false;
113
124
  clientPromise = null;
114
125
  }
126
+ //---------------
127
+ // Wrap a tool handler so every invocation is tracked (never throws,
128
+ // never blocks): the PostHog event carries only the tool name.
129
+ // Moved here from index.ts so that file stays under the 500-line cap.
130
+ //---------------
131
+ export function withTracking(toolName, handler) {
132
+ return async (args) => {
133
+ trackEvent('mcp_tool_called', { toolName });
134
+ return handler(args);
135
+ };
136
+ }
115
137
  //# sourceMappingURL=analytics.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"analytics.js","sourceRoot":"","sources":["../src/analytics.ts"],"names":[],"mappings":"AAAA,iBAAiB;AACjB,6EAA6E;AAC7E,EAAE;AACF,2EAA2E;AAC3E,6DAA6D;AAC7D,EAAE;AACF,yEAAyE;AACzE,yEAAyE;AACzE,iDAAiD;AACjD,EAAE;AACF,gBAAgB;AAChB,6DAA6D;AAC7D,kEAAkE;AAClE,8DAA8D;AAC9D,qEAAqE;AACrE,0EAA0E;AAC1E,iBAAiB;AAEjB,mEAAmE;AACnE,sEAAsE;AACtE,0DAA0D;AAC1D,MAAM,kBAAkB,GACtB,0GAA0G,CAAC;AAE7G,MAAM,QAAQ,GAAG,YAAY,CAAC;AAE9B,SAAS,YAAY,CAAC,UAAmC;IACvD,MAAM,QAAQ,GAA4B,EAAE,CAAC;IAC7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACtD,QAAQ,CAAC,GAAG,CAAC,GAAG,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;IAClE,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,iBAAiB;AACjB,qEAAqE;AACrE,mEAAmE;AACnE,mEAAmE;AACnE,8CAA8C;AAC9C,sDAAsD;AAC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MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,EAAE;iBACvE,CAAC,CAAC;YACL,CAAC;YAAC,MAAM,CAAC;gBACP,6CAA6C;YAC/C,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,6CAA6C;IAC/C,CAAC;AACH,CAAC;AAED,iBAAiB;AACjB,uEAAuE;AACvE,qEAAqE;AACrE,4DAA4D;AAC5D,iBAAiB;AAEjB,SAAS,cAAc;IACrB,OAAO,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,aAAa,CAAC;AACjF,CAAC;AAED,iBAAiB;AACjB,oDAAoD;AACpD,+BAA+B;AAC/B,iBAAiB;AAEjB,MAAM,UAAU,wBAAwB;IACtC,MAAM,GAAG,IAAI,CAAC;IACd,MAAM,GAAG,KAAK,CAAC;IACf,aAAa,GAAG,IAAI,CAAC;AACvB,CAAC;AAED,iBAAiB;AACjB,oEAAoE;AACpE,+DAA+D;AAC/D,sEAAsE;AACtE,iBAAiB;AAEjB,MAAM,UAAU,YAAY,CAAiD,QAAgB,EAAE,OAA0C;IACvI,OAAO,KAAK,EAAE,IAAW,EAAoB,EAAE;QAC7C,UAAU,CAAC,iBAAiB,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC5C,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { PostEngineerClient } from './client.js';
2
+ export interface PostMetricsQuery {
3
+ window: '24h' | '7d';
4
+ persona?: string;
5
+ account?: string;
6
+ provider?: string;
7
+ angle?: string;
8
+ }
9
+ export declare function getPost(client: PostEngineerClient, id: string): Promise<unknown>;
10
+ export declare function getPostMetrics(client: PostEngineerClient, query: PostMetricsQuery): Promise<unknown>;
@@ -0,0 +1,15 @@
1
+ export async function getPost(client, id) {
2
+ return client.request(`/api/posts/${encodeURIComponent(id)}`, { method: 'GET', headers: client.getHeaders() }, 'get post');
3
+ }
4
+ export async function getPostMetrics(client, query) {
5
+ // Same parameter names as the route's parseMetricsQuery; omitted filters
6
+ // are not sent (the route rejects empty parameters).
7
+ const params = new URLSearchParams({ window: query.window });
8
+ for (const key of ['persona', 'account', 'provider', 'angle']) {
9
+ const value = query[key];
10
+ if (value !== undefined)
11
+ params.set(key, value);
12
+ }
13
+ return client.request(`/api/metrics?${params.toString()}`, { method: 'GET', headers: client.getHeaders() }, 'get post metrics');
14
+ }
15
+ //# sourceMappingURL=client-posts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-posts.js","sourceRoot":"","sources":["../src/client-posts.ts"],"names":[],"mappings":"AAkBA,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,MAA0B,EAAE,EAAU;IAClE,OAAO,MAAM,CAAC,OAAO,CACnB,cAAc,kBAAkB,CAAC,EAAE,CAAC,EAAE,EACtC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,UAAU,EAAE,EAAE,EAC/C,UAAU,CACX,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAA0B,EAC1B,KAAuB;IAEvB,yEAAyE;IACzE,qDAAqD;IACrD,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IAC7D,KAAK,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,CAAU,EAAE,CAAC;QACvE,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,KAAK,KAAK,SAAS;YAAE,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,MAAM,CAAC,OAAO,CACnB,gBAAgB,MAAM,CAAC,QAAQ,EAAE,EAAE,EACnC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,UAAU,EAAE,EAAE,EAC/C,kBAAkB,CACnB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { PostEngineerClient } from './client.js';
2
+ export declare function getPersonaPublishingAccounts(client: PostEngineerClient, personaId: string): Promise<unknown>;
3
+ export declare function setPersonaPublishingAccounts(client: PostEngineerClient, personaId: string, accounts: Record<string, string[]>): Promise<unknown>;
@@ -0,0 +1,18 @@
1
+ //---------------
2
+ // Per-persona default publishing accounts (issue #212) — HTTP calls.
3
+ //
4
+ // Extracted from client.ts so the client module stays under the file-size
5
+ // ratchet. These are standalone functions (not methods) because the client
6
+ // class is grandfathered over the 500-line cap and may not grow.
7
+ //---------------
8
+ export async function getPersonaPublishingAccounts(client, personaId) {
9
+ return client.request(`/api/persona/publishing-accounts?personaId=${encodeURIComponent(personaId)}`, { method: 'GET', headers: client.getHeaders() }, 'get persona publishing accounts');
10
+ }
11
+ export async function setPersonaPublishingAccounts(client, personaId, accounts) {
12
+ return client.request(`/api/persona/publishing-accounts?personaId=${encodeURIComponent(personaId)}`, {
13
+ method: 'PUT',
14
+ headers: client.getHeaders(),
15
+ body: JSON.stringify({ accounts }),
16
+ }, 'set persona publishing accounts');
17
+ }
18
+ //# sourceMappingURL=client-publishing-accounts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-publishing-accounts.js","sourceRoot":"","sources":["../src/client-publishing-accounts.ts"],"names":[],"mappings":"AAEA,iBAAiB;AACjB,qEAAqE;AACrE,EAAE;AACF,0EAA0E;AAC1E,2EAA2E;AAC3E,iEAAiE;AACjE,iBAAiB;AAEjB,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAChD,MAA0B,EAC1B,SAAiB;IAEjB,OAAO,MAAM,CAAC,OAAO,CACnB,8CAA8C,kBAAkB,CAAC,SAAS,CAAC,EAAE,EAC7E,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,UAAU,EAAE,EAAE,EAC/C,iCAAiC,CAClC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAChD,MAA0B,EAC1B,SAAiB,EACjB,QAAkC;IAElC,OAAO,MAAM,CAAC,OAAO,CACnB,8CAA8C,kBAAkB,CAAC,SAAS,CAAC,EAAE,EAC7E;QACE,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,MAAM,CAAC,UAAU,EAAE;QAC5B,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;KACnC,EACD,iCAAiC,CAClC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,140 @@
1
+ import { VIDEO_LAYOUTS } from './limits.js';
2
+ export interface PostEngineerClientOptions {
3
+ apiKey?: string;
4
+ baseUrl?: string;
5
+ /** Clock override used by schedule validation (tests); defaults to the real clock. */
6
+ now?: () => Date;
7
+ }
8
+ /** One image for a persona's image library, read from a local file. */
9
+ export interface PersonaLibraryImageInput {
10
+ /** Local file path (JPG/JPEG, PNG, or WebP, max 10MB). */
11
+ path: string;
12
+ /** Short tag for deterministic per-video matching (e.g. casual, formal). */
13
+ tag?: string;
14
+ /** Description of the photo for keyword matching. */
15
+ description?: string;
16
+ }
17
+ /**
18
+ * How the persona hook is composed with the video material. Mirrors the server's
19
+ * accepted values so an unknown layout is a compile error here rather than
20
+ * a 400 from the API.
21
+ */
22
+ export type VideoLayout = (typeof VIDEO_LAYOUTS)[number];
23
+ export interface CreatePersonaInput {
24
+ name: string;
25
+ /** REQUIRED — every persona has a face. */
26
+ avatarUrl: string;
27
+ voiceId: string;
28
+ language?: string;
29
+ videoAspect?: '9:16' | '16:9';
30
+ videoLayout?: VideoLayout;
31
+ scriptPrompt?: string;
32
+ paragraphNumber?: number;
33
+ niche?: string;
34
+ faceQuality?: 'ok' | 'very_good';
35
+ /** Up to 10 local images of the same person for the image library. */
36
+ images?: PersonaLibraryImageInput[];
37
+ /** Index into images[] marking the primary library image. */
38
+ imagePrimaryIndex?: number;
39
+ }
40
+ export interface GeneratePersonaVideoInput {
41
+ /**
42
+ * Optional. Omit it for a faceless post defined entirely by `options` —
43
+ * the persona is then not just a face: it is where the voice, the
44
+ * aspect ratio and the niche come from. A post without one
45
+ * MUST set options.faceless and one of options.voiceId / options.audioUrl.
46
+ */
47
+ personaId?: string;
48
+ /** The slot label for the single video. */
49
+ title: string;
50
+ providers: ('youtube' | 'instagram' | 'linkedin' | 'bluesky')[];
51
+ youtubeAccountIds?: string[];
52
+ instagramAccountIds?: string[];
53
+ linkedinAccountIds?: string[];
54
+ blueskyAccountIds?: string[];
55
+ /**
56
+ * Publish mode. 'scheduled' (default) slots the video at startAt + times;
57
+ * 'asap' publishes it the moment generation finishes, with no scheduled
58
+ * time. In 'asap' mode startAt/times must not be set.
59
+ */
60
+ mode?: 'scheduled' | 'asap';
61
+ /** ISO datetime when the publish slot may start; naive values are wall-clock in timezone. Required unless mode is 'asap'. */
62
+ startAt?: string;
63
+ /** Daily publish times (HH:MM, 24h). Required unless mode is 'asap'. */
64
+ times?: string[];
65
+ /** IANA timezone for a naive startAt and the times (display-only in 'asap' mode). Defaults to UTC. */
66
+ timezone?: string;
67
+ options?: {
68
+ faceless?: boolean;
69
+ /** Stock footage only ('broll') or drawn illustrations only ('svg'), with or without a face. */
70
+ facelessMaterial?: 'broll' | 'svg';
71
+ audioUrl?: string;
72
+ imageId?: string;
73
+ voiceId?: string;
74
+ webhookUrl?: string;
75
+ videoAspect?: '9:16' | '16:9';
76
+ videoLayout?: VideoLayout;
77
+ paragraphNumber?: number;
78
+ language?: string;
79
+ niche?: string;
80
+ /** Segments script (MCP first, Phase 1): first hook, body segments, last CTA. Validated by the web route before any token debit. */
81
+ segments?: Array<{
82
+ kind: 'hook' | 'body' | 'cta';
83
+ text: string;
84
+ media?: {
85
+ mediaId?: string;
86
+ url?: string;
87
+ };
88
+ terms?: string[];
89
+ }>;
90
+ };
91
+ /** Omitted: a UUID is generated per call, so a retry cannot double-generate. */
92
+ idempotencyKey?: string;
93
+ }
94
+ export interface UpdatePersonaInput {
95
+ personaId: string;
96
+ name?: string;
97
+ avatarUrl?: string;
98
+ voiceId?: string;
99
+ language?: string;
100
+ videoAspect?: '9:16' | '16:9';
101
+ videoLayout?: VideoLayout;
102
+ scriptPrompt?: string;
103
+ paragraphNumber?: number;
104
+ niche?: string;
105
+ }
106
+ /** Input for publishing a user-provided video directly, without generation. */
107
+ export interface PublishVideoDirectInput {
108
+ provider: 'youtube' | 'instagram' | 'linkedin' | 'bluesky';
109
+ /** Local path to the video file (.mp4 or .mov, max 2GB). */
110
+ videoPath: string;
111
+ /** Target accounts (channel IDs / IG user IDs / DIDs / LinkedIn member IDs or org URNs). */
112
+ accountIds: string[];
113
+ /** YouTube only: required. */
114
+ title?: string;
115
+ /** YouTube only: required. */
116
+ description?: string;
117
+ /** YouTube only: required, at least one tag. */
118
+ tags?: string[];
119
+ /** YouTube only: required. */
120
+ privacyStatus?: 'public' | 'private' | 'unlisted';
121
+ /** Instagram/Bluesky/LinkedIn: required. */
122
+ caption?: string;
123
+ }
124
+ /** One per-account outcome from a direct-publish upload. */
125
+ export interface DirectPublishAccountResult {
126
+ accountId: string;
127
+ success: boolean;
128
+ videoId?: string;
129
+ videoUrl?: string;
130
+ postId?: string;
131
+ error?: string;
132
+ }
133
+ /** Narrowed POST /api/upload-content response. */
134
+ export interface DirectPublishResult {
135
+ success: boolean;
136
+ provider: string;
137
+ results: DirectPublishAccountResult[];
138
+ successCount: number;
139
+ logId: string;
140
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=client-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-types.js","sourceRoot":"","sources":["../src/client-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,29 @@
1
+ import type { PostEngineerClient } from './client.js';
2
+ export declare const CHECK_MEDIA_CODES: readonly ["ok", "blocked_403", "not_image", "too_small", "too_large", "timeout", "face_detected"];
3
+ export type CheckMediaCode = (typeof CHECK_MEDIA_CODES)[number];
4
+ /**
5
+ * Real image type from magic bytes — the extension is never trusted.
6
+ * Only the types the engine temp_assets flow accepts by suffix (JPG,
7
+ * PNG, WebP): the web route re-validates authoritatively with its own
8
+ * magic-byte check, so a drift here can only fail fast, never smuggle
9
+ * a bad file through.
10
+ */
11
+ export declare function detectSegmentImageMimeType(buffer: Buffer): string | null;
12
+ /**
13
+ * Upload one local image for a segment and return its mediaId.
14
+ * Reads run the same stat-before-read, size-guard-before-and-after-read
15
+ * pattern as the persona library uploads, with the 8MB engine photo
16
+ * limit instead of the 10MB library limit. Only the mediaId reaches
17
+ * tool output: the local path and the temp asset URL never do.
18
+ */
19
+ export declare function uploadSegmentMedia(client: PostEngineerClient, path: string): Promise<{
20
+ mediaId: string;
21
+ }>;
22
+ /**
23
+ * Mechanically check one image URL through the engine (no LLM, no
24
+ * relevance judgement): the agent, who sees the image, decides
25
+ * relevance. Returns exactly one code; the URL never reaches output.
26
+ */
27
+ export declare function checkSegmentMedia(client: PostEngineerClient, url: string): Promise<{
28
+ code: CheckMediaCode;
29
+ }>;
@@ -0,0 +1,135 @@
1
+ import { readFile, stat } from 'node:fs/promises';
2
+ import { basename } from 'node:path';
3
+ import { MAX_SEGMENT_MEDIA_BYTES, MAX_SEGMENT_MEDIA_MB } from './limits.js';
4
+ //---------------
5
+ // Segment media client calls (Phase 2, user media per segment).
6
+ // Standalone functions (not client methods) because client.ts is
7
+ // grandfathered over the 500-line cap and may not grow — the same
8
+ // pattern as client-video-task.ts.
9
+ //---------------
10
+ // Multipart uploads can legitimately exceed the client's default budget;
11
+ // mirrors UPLOAD_TIMEOUT_MS in client.ts (kept as a literal here so
12
+ // client.ts stays untouched).
13
+ const UPLOAD_TIMEOUT_MS = 120_000;
14
+ export const CHECK_MEDIA_CODES = [
15
+ 'ok',
16
+ 'blocked_403',
17
+ 'not_image',
18
+ 'too_small',
19
+ 'too_large',
20
+ 'timeout',
21
+ 'face_detected',
22
+ ];
23
+ /**
24
+ * Real image type from magic bytes — the extension is never trusted.
25
+ * Only the types the engine temp_assets flow accepts by suffix (JPG,
26
+ * PNG, WebP): the web route re-validates authoritatively with its own
27
+ * magic-byte check, so a drift here can only fail fast, never smuggle
28
+ * a bad file through.
29
+ */
30
+ export function detectSegmentImageMimeType(buffer) {
31
+ if (buffer.length < 12)
32
+ return null;
33
+ if (buffer[0] === 0xff && buffer[1] === 0xd8 && buffer[2] === 0xff)
34
+ return 'image/jpeg';
35
+ if (buffer[0] === 0x89 && buffer[1] === 0x50 && buffer[2] === 0x4e && buffer[3] === 0x47) {
36
+ return 'image/png';
37
+ }
38
+ if (buffer.subarray(0, 4).toString('ascii') === 'RIFF' && buffer.subarray(8, 12).toString('ascii') === 'WEBP') {
39
+ return 'image/webp';
40
+ }
41
+ return null;
42
+ }
43
+ function assertSegmentMediaSize(sizeBytes, path) {
44
+ if (sizeBytes > MAX_SEGMENT_MEDIA_BYTES) {
45
+ throw new Error(`Image "${basename(path)}" is too large (${sizeBytes} bytes; max ${MAX_SEGMENT_MEDIA_MB}MB).`);
46
+ }
47
+ }
48
+ /**
49
+ * Upload one local image for a segment and return its mediaId.
50
+ * Reads run the same stat-before-read, size-guard-before-and-after-read
51
+ * pattern as the persona library uploads, with the 8MB engine photo
52
+ * limit instead of the 10MB library limit. Only the mediaId reaches
53
+ * tool output: the local path and the temp asset URL never do.
54
+ */
55
+ export async function uploadSegmentMedia(client, path) {
56
+ let fileStat;
57
+ try {
58
+ fileStat = await stat(path);
59
+ }
60
+ catch {
61
+ throw new Error(`Failed to read image "${basename(path)}".`);
62
+ }
63
+ assertSegmentMediaSize(fileStat.size, path);
64
+ let buffer;
65
+ try {
66
+ buffer = await readFile(path);
67
+ }
68
+ catch {
69
+ throw new Error(`Failed to read image "${basename(path)}".`);
70
+ }
71
+ if (buffer.length === 0) {
72
+ throw new Error(`Image "${basename(path)}" is empty.`);
73
+ }
74
+ assertSegmentMediaSize(buffer.length, path);
75
+ const mimeType = detectSegmentImageMimeType(buffer);
76
+ if (mimeType === null) {
77
+ throw new Error(`Image "${basename(path)}" is not a JPG, PNG, or WebP image (real content, not extension).`);
78
+ }
79
+ const formData = new FormData();
80
+ formData.append('file', new Blob([buffer], { type: mimeType }), basename(path));
81
+ const result = await client.request('/api/media/upload', {
82
+ method: 'POST',
83
+ // No JSON content type: fetch sets the multipart boundary itself.
84
+ headers: client.getHeaders(false),
85
+ body: formData,
86
+ }, 'upload segment media', UPLOAD_TIMEOUT_MS);
87
+ return narrowUploadResult(result);
88
+ }
89
+ function narrowUploadResult(result) {
90
+ if (typeof result !== 'object' || result === null) {
91
+ throw new Error('The media upload endpoint returned an unexpected response.');
92
+ }
93
+ const record = result;
94
+ if (record.success !== true || typeof record.mediaId !== 'string' || record.mediaId.length === 0) {
95
+ throw new Error('The media upload endpoint returned an unexpected response.');
96
+ }
97
+ return { mediaId: record.mediaId };
98
+ }
99
+ /**
100
+ * Mechanically check one image URL through the engine (no LLM, no
101
+ * relevance judgement): the agent, who sees the image, decides
102
+ * relevance. Returns exactly one code; the URL never reaches output.
103
+ */
104
+ export async function checkSegmentMedia(client, url) {
105
+ let parsed;
106
+ try {
107
+ parsed = new URL(url);
108
+ }
109
+ catch {
110
+ throw new Error('url must be an http(s) URL.');
111
+ }
112
+ if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
113
+ throw new Error('url must be an http(s) URL.');
114
+ }
115
+ const result = await client.request('/api/media/check', {
116
+ method: 'POST',
117
+ headers: client.getHeaders(),
118
+ body: JSON.stringify({ url }),
119
+ }, 'check segment media');
120
+ return narrowCheckResult(result);
121
+ }
122
+ function narrowCheckResult(result) {
123
+ if (typeof result !== 'object' || result === null) {
124
+ throw new Error('The media check endpoint returned an unexpected response.');
125
+ }
126
+ const record = result;
127
+ if (record.success !== true || typeof record.code !== 'string') {
128
+ throw new Error('The media check endpoint returned an unexpected response.');
129
+ }
130
+ if (!CHECK_MEDIA_CODES.includes(record.code)) {
131
+ throw new Error('The media check endpoint returned an unknown code.');
132
+ }
133
+ return { code: record.code };
134
+ }
135
+ //# sourceMappingURL=client-user-media.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-user-media.js","sourceRoot":"","sources":["../src/client-user-media.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE5E,iBAAiB;AACjB,gEAAgE;AAChE,iEAAiE;AACjE,kEAAkE;AAClE,mCAAmC;AACnC,iBAAiB;AAEjB,yEAAyE;AACzE,oEAAoE;AACpE,8BAA8B;AAC9B,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAElC,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI;IACJ,aAAa;IACb,WAAW;IACX,WAAW;IACX,WAAW;IACX,SAAS;IACT,eAAe;CACP,CAAC;AAIX;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CAAC,MAAc;IACvD,IAAI,MAAM,CAAC,MAAM,GAAG,EAAE;QAAE,OAAO,IAAI,CAAC;IACpC,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI;QAAE,OAAO,YAAY,CAAC;IACxF,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QACzF,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ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
@@ -0,0 +1,2 @@
1
+ import type { PostEngineerClient } from './client.js';
2
+ export declare function cancelVideoTask(client: PostEngineerClient, taskId: string): Promise<unknown>;
@@ -0,0 +1,9 @@
1
+ //---------------
2
+ // DELETE /api/persona/video-task/[taskId] — cancel/remove an engine task.
3
+ // Standalone function (not a client method) because client.ts is
4
+ // grandfathered over the 500-line cap and may not grow.
5
+ //---------------
6
+ export async function cancelVideoTask(client, taskId) {
7
+ return client.request(`/api/persona/video-task/${encodeURIComponent(taskId)}`, { method: 'DELETE', headers: client.getHeaders() }, 'cancel video task');
8
+ }
9
+ //# sourceMappingURL=client-video-task.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-video-task.js","sourceRoot":"","sources":["../src/client-video-task.ts"],"names":[],"mappings":"AAEA,iBAAiB;AACjB,0EAA0E;AAC1E,iEAAiE;AACjE,wDAAwD;AACxD,iBAAiB;AAEjB,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAA0B,EAC1B,MAAc;IAEd,OAAO,MAAM,CAAC,OAAO,CACnB,2BAA2B,kBAAkB,CAAC,MAAM,CAAC,EAAE,EACvD,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,UAAU,EAAE,EAAE,EAClD,mBAAmB,CACpB,CAAC;AACJ,CAAC"}