@clipwright/core 0.61.0 → 0.63.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/dist/ad-guide.d.ts +27 -0
  2. package/dist/ad-guide.js +7 -0
  3. package/dist/ad-ids.d.ts +3 -0
  4. package/dist/ad-ids.js +4 -0
  5. package/dist/ads.d.ts +222 -0
  6. package/dist/ads.js +57 -0
  7. package/dist/api-failure.d.ts +6 -0
  8. package/dist/api-failure.js +16 -5
  9. package/dist/cut-ids.d.ts +3 -0
  10. package/dist/cut-ids.js +4 -0
  11. package/dist/cuts.d.ts +221 -0
  12. package/dist/cuts.js +51 -0
  13. package/dist/diy-next.d.ts +18 -0
  14. package/dist/diy-next.js +13 -0
  15. package/dist/edit-music.d.ts +397 -0
  16. package/dist/edit-music.js +77 -0
  17. package/dist/endpoints.js +14 -0
  18. package/dist/errors.d.ts +29 -1
  19. package/dist/errors.js +23 -0
  20. package/dist/faceless-direction-summary.d.ts +3 -0
  21. package/dist/faceless-direction-summary.js +3 -0
  22. package/dist/faceless-public-plan.js +4 -4
  23. package/dist/faceless-storyboard.js +8 -9
  24. package/dist/film-cut.d.ts +851 -0
  25. package/dist/film-cut.js +168 -0
  26. package/dist/film-guide.d.ts +27 -0
  27. package/dist/film-guide.js +10 -0
  28. package/dist/generations.d.ts +2 -1
  29. package/dist/generations.js +9 -1
  30. package/dist/idempotency.js +2 -1
  31. package/dist/index.d.ts +6 -0
  32. package/dist/index.js +6 -0
  33. package/dist/openapi.js +11 -0
  34. package/dist/own-agent-price.d.ts +41 -5
  35. package/dist/own-agent-price.js +53 -14
  36. package/dist/own-agent-runs.d.ts +320 -2
  37. package/dist/own-agent-runs.js +119 -14
  38. package/dist/prices.d.ts +1 -0
  39. package/dist/prices.js +22 -2
  40. package/dist/runs.d.ts +1 -0
  41. package/dist/runs.js +3 -0
  42. package/dist/speech-words.d.ts +4 -0
  43. package/dist/speech-words.js +30 -0
  44. package/dist/templates/sounds.d.ts +24 -0
  45. package/dist/templates/sounds.js +2 -0
  46. package/dist/trend-niches.d.ts +57 -0
  47. package/dist/trend-niches.js +59 -4
  48. package/dist/trend-search.d.ts +1 -0
  49. package/dist/trend-search.js +3 -1
  50. package/package.json +1 -1
package/dist/prices.js CHANGED
@@ -11,7 +11,8 @@ import { REFERENCE_ANALYSIS_CREDITS, REFERENCE_DATA_CREDITS } from "./reference-
11
11
  import { CREATOR_PROFILE_CREDITS, CREATOR_PROFILE_VIDEOS } from "./creator-profile.js";
12
12
  import { TREND_FREE_PAGES_PER_DAY, TREND_FREE_SEARCHES_PER_MONTH, TREND_PAGE_PAID_CREDITS, TREND_PAGE_WINDOW_SECONDS, TREND_SEARCH_CREDITS, TREND_SEARCH_MAX_PAGES, TREND_SEARCH_REELS, } from "./trend-search.js";
13
13
  import { isMusicEnabled, MUSIC_BED_CREDITS } from "./music.js";
14
- import { isOwnAgentEnabled, OWN_FILM_EXTRA_SECOND_CREDITS, OWN_FILM_INCLUDED_SECONDS, OWN_FILM_RENDER_CREDITS, OWN_HERO_POSE_CREDITS, OWN_HERO_POSES, OWN_FREE_STILLS, OWN_FREE_STILLS_WINDOW_HOURS, OWN_STILL_CREDITS, OWN_STILLS_MAX_PER_CALL, OWN_VOICE_CREDITS_PER_SECOND, OWN_EDIT_CREDITS, OWN_EDIT_MAX_SECONDS, OWN_TAKE_CHECK_CREDITS } from "./own-agent-price.js";
14
+ import { isOwnAgentEnabled, OWN_FILM_EXTRA_SECOND_CREDITS, OWN_FILM_INCLUDED_SECONDS, OWN_FILM_RENDER_CREDITS, OWN_HERO_POSE_CREDITS, OWN_HERO_POSES, OWN_FREE_STILLS, OWN_FREE_STILLS_WINDOW_HOURS, OWN_STILL_CREDITS, OWN_STILLS_MAX_PER_CALL, OWN_VOICE_CREDITS_PER_SECOND, OWN_EDIT_CREDITS, OWN_EDIT_MAX_SECONDS, OWN_TAKE_CHECK_CREDITS, OWN_CUT_BED_CREDITS, OWN_CUT_CREDITS, OWN_CUT_EXTRA_SECOND_CREDITS, OWN_CUT_INCLUDED_SECONDS, OWN_CUT_MAX_NEW_SOUNDS, OWN_CUT_MAX_SECONDS, OWN_CUT_MIN_SECONDS, OWN_CUT_TAKE_SOUND_CREDITS_PER_SECOND, OWN_TAKE_CHECK_PICTURE_CREDITS } from "./own-agent-price.js";
15
+ import { CUT_PREVIEW_MAX_STILLS } from "./film-cut.js";
15
16
  export const PRICES_PATH = "/v1/public/prices";
16
17
  export const PRICE_UNITS = ["call", "second", "face_second", "image", "clip", "clip_second", "still", "scene", "track"];
17
18
  export const priceEntryLine = z.strictObject({
@@ -123,11 +124,30 @@ export const AD_DIY_PRICES = Object.freeze([
123
124
  "delivered cut; an edit that fails costs nothing." }),
124
125
  paid({ tool: "check_take", route: "POST /v1/take-checks", quote_tool: "quote_take_check", unit: "call", credits: OWN_TAKE_CHECK_CREDITS,
125
126
  notes: "One of your clips judged frame by frame against the prompt it was made with: each defect with its seconds and how to repair " +
126
- "it, and the clean windows. Charged only for a delivered verdict; a check that fails costs nothing." }),
127
+ "it, and the clean windows. Charged only for a delivered verdict; a check that delivers no verdict costs nothing." }),
127
128
  { action: "take_frames", tool: "take_frames", route: "POST /v1/take-frames", variant: null, lines: [{ label: null, unit: "call", credits: 0 }],
128
129
  formula: null, minimum_credits: null, quote_tool: null,
129
130
  notes: "Free: one of your clips as contact sheets, each frame labelled with its second, up to 96 frames a call." },
130
131
  ]);
132
+ export const FACELESS_DIY_PRICES = Object.freeze([
133
+ paid({ tool: "render_cut", route: "POST /v1/film-cuts", quote_tool: "quote_cut", lines: [
134
+ { label: `the cut, up to ${OWN_CUT_INCLUDED_SECONDS} s`, unit: "call", credits: OWN_CUT_CREDITS },
135
+ { label: `each second over ${OWN_CUT_INCLUDED_SECONDS}`, unit: "second", credits: OWN_CUT_EXTRA_SECOND_CREDITS },
136
+ { label: "a described bed, once per cut", unit: "call", credits: OWN_CUT_BED_CREDITS },
137
+ { label: "a take's own sound, each second of the whole take", unit: "second", credits: OWN_CUT_TAKE_SOUND_CREDITS_PER_SECOND },
138
+ { label: "music", unit: "track", credits: MUSIC_BED_CREDITS }
139
+ ],
140
+ notes: `One faceless video of ${OWN_CUT_MIN_SECONDS} to ${OWN_CUT_MAX_SECONDS} s from your checked cut sheet, vertical 720p in stereo, with up ` +
141
+ `to ${OWN_CUT_MAX_NEW_SOUNDS} described sounds made. Charged only for a delivered video and only for the parts it carries; a cut that ` +
142
+ "fails costs nothing." }),
143
+ paid({ tool: "check_take", variant: "against a picture", route: "POST /v1/take-checks", quote_tool: "quote_take_check", unit: "call",
144
+ credits: OWN_TAKE_CHECK_PICTURE_CREDITS,
145
+ notes: "One take of your cut record judged against the picture it was made from: each defect with its seconds, the clean windows, the " +
146
+ "second its action shows and where its subject stands. Charged only for a delivered verdict; a check that delivers no verdict costs nothing." }),
147
+ paid({ tool: "preview_cut", route: "POST /v1/cut-previews", quote_tool: "quote_cut_preview", unit: "still", credits: OWN_STILL_CREDITS,
148
+ notes: `Up to ${CUT_PREVIEW_MAX_STILLS} frames of your checked cut sheet as the video draws them, on the words you name. The first ` +
149
+ `${OWN_FREE_STILLS} preview stills of an account in any ${OWN_FREE_STILLS_WINDOW_HOURS} h are free; a preview that fails costs nothing.` }),
150
+ ]);
131
151
  function buildPriceList(liveShots, scenes, facelessShots = false, facelessScenes = false, music = false, explainer = false, ownAgent = false) {
132
152
  const unit = EDIT_UNIT_PRICES;
133
153
  const parts = PARTS_FACE_TARIFF;
package/dist/runs.d.ts CHANGED
@@ -33,6 +33,7 @@ export declare const AI_DISCLOSURE_TEXT = "This video was generated with AI: the
33
33
  export declare const FACELESS_AI_DISCLOSURE_TEXT = "This video was generated with AI: the voice, the opening clip and the images are synthetic.";
34
34
  export declare const FACELESS_EXPLAINER_AI_DISCLOSURE_TEXT = "This video was generated with AI: the voice, the animation and the images in it are synthetic.";
35
35
  export declare const FACELESS_OWN_IMAGES_AI_DISCLOSURE_TEXT: string;
36
+ export declare const FILM_CUT_AI_DISCLOSURE_TEXT = "This video was generated with AI: the voice is synthetic, and so is every picture and clip its author did not supply.";
36
37
  export declare function aiDisclosureText(skill: string, input: unknown): string;
37
38
  export declare function facelessOwnImages(input: unknown): boolean;
38
39
  export declare const AI_DISCLOSURE_EMBEDDED_METADATA_KEY = "ai-disclosure-embedded";
package/dist/runs.js CHANGED
@@ -40,7 +40,10 @@ export const FACELESS_AI_DISCLOSURE_TEXT = "This video was generated with AI: th
40
40
  export const FACELESS_EXPLAINER_AI_DISCLOSURE_TEXT = "This video was generated with AI: the voice, the animation and the images in it are synthetic.";
41
41
  export const FACELESS_OWN_IMAGES_AI_DISCLOSURE_TEXT = "This video was generated with AI: the voice and the opening clip are synthetic, " +
42
42
  "and so is every image its author did not supply.";
43
+ export const FILM_CUT_AI_DISCLOSURE_TEXT = "This video was generated with AI: the voice is synthetic, and so is every picture and clip its author did not supply.";
43
44
  export function aiDisclosureText(skill, input) {
45
+ if (skill === "film_cut" || skill === "film_cut_preview")
46
+ return FILM_CUT_AI_DISCLOSURE_TEXT;
44
47
  if (skill === "revise_long_form")
45
48
  return AI_DISCLOSURE_TEXT;
46
49
  if (skill !== "make_faceless")
@@ -0,0 +1,4 @@
1
+ import type { WordTiming } from "./tts-backend.js";
2
+ export declare const LEXICAL_WORD: RegExp;
3
+ export declare function lexicalWords(text: string): string[];
4
+ export declare function lexicalWordTimings(words: readonly WordTiming[]): WordTiming[];
@@ -0,0 +1,30 @@
1
+ export const LEXICAL_WORD = /[\p{L}\p{N}\p{M}]+(?:['’][\p{L}\p{N}\p{M}]+)*/gu;
2
+ export function lexicalWords(text) {
3
+ return text.normalize("NFKC").match(LEXICAL_WORD) ?? [];
4
+ }
5
+ export function lexicalWordTimings(words) {
6
+ const out = [];
7
+ let lead = "";
8
+ for (const timed of words) {
9
+ const text = timed.word.normalize("NFKC"), matches = [...text.matchAll(LEXICAL_WORD)];
10
+ if (!matches.length) {
11
+ const last = out.at(-1);
12
+ if (last)
13
+ last.word += text;
14
+ else
15
+ lead += text;
16
+ continue;
17
+ }
18
+ const letters = matches.reduce((sum, match) => sum + match[0].length, 0), span = timed.endSec - timed.startSec;
19
+ let before = 0;
20
+ matches.forEach((match, at) => {
21
+ const from = at === 0 ? 0 : match.index, to = matches[at + 1]?.index ?? text.length, after = before + match[0].length;
22
+ out.push({ word: (at === 0 ? lead : "") + text.slice(from, to),
23
+ startSec: at === 0 ? timed.startSec : timed.startSec + span * before / letters,
24
+ endSec: at === matches.length - 1 ? timed.endSec : timed.startSec + span * after / letters });
25
+ before = after;
26
+ });
27
+ lead = "";
28
+ }
29
+ return out;
30
+ }
@@ -1095,6 +1095,30 @@ export declare const templateSoundsList: z.ZodObject<{
1095
1095
  names: z.ZodArray<z.ZodString>;
1096
1096
  plays: z.ZodString;
1097
1097
  }, z.core.$strict>>;
1098
+ music_beds: z.ZodDefault<z.ZodArray<z.ZodObject<{
1099
+ id: z.ZodString;
1100
+ genre: z.ZodEnum<{
1101
+ acoustic: "acoustic";
1102
+ ambient: "ambient";
1103
+ beauty: "beauty";
1104
+ cinematic: "cinematic";
1105
+ corporate: "corporate";
1106
+ fashion: "fashion";
1107
+ food: "food";
1108
+ hiphop_light: "hiphop_light";
1109
+ lofi: "lofi";
1110
+ playful: "playful";
1111
+ sport: "sport";
1112
+ tech: "tech";
1113
+ }>;
1114
+ energy: z.ZodEnum<{
1115
+ calm: "calm";
1116
+ driving: "driving";
1117
+ medium: "medium";
1118
+ }>;
1119
+ bpm: z.ZodNumber;
1120
+ seconds: z.ZodNumber;
1121
+ }, z.core.$strict>>>;
1098
1122
  contract_version: z.ZodString;
1099
1123
  }, z.core.$strict>;
1100
1124
  export type TemplateSoundsList = z.infer<typeof templateSoundsList>;
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { editMusicBed } from "../edit-music.js";
2
3
  export const TEMPLATE_SOUND_BEATS = ["click", "toggle", "ring", "answer", "notify", "step", "whoosh", "flash", "pop", "hangup", "money", "edit"];
3
4
  export const TEMPLATE_SOUNDS = {
4
5
  click: { default: "click_mouse", names: ["click_mouse", "click_soft", "click_crisp", "click_light", "tick_soft", "click_sharp", "key"],
@@ -96,6 +97,7 @@ export const TEMPLATE_SOUNDS_PATH = "/v1/template-sounds";
96
97
  export const templateSoundsList = z.strictObject({
97
98
  beats: z.array(z.strictObject({ beat: z.enum(TEMPLATE_SOUND_BEATS), default: z.string().min(1), names: z.array(z.string().min(1)).min(1),
98
99
  plays: z.string().min(1) })),
100
+ music_beds: z.array(editMusicBed).default([]),
99
101
  contract_version: z.string().min(1),
100
102
  });
101
103
  export function listTemplateSounds() {
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { type CreatorPlatform } from "./creator-profile.js";
2
3
  import { type FindTrendsRequest, type TrendReel } from "./trend-search.js";
3
4
  export declare const TREND_NICHES_PATH = "/v1/trend-niches";
4
5
  export declare const TREND_NICHES_MAX = 3;
@@ -41,6 +42,25 @@ export declare const trendNiche: z.ZodObject<{
41
42
  primary: z.ZodBoolean;
42
43
  }, z.core.$strict>;
43
44
  export type TrendNiche = z.infer<typeof trendNiche>;
45
+ export declare const TREND_NICHE_SUGGESTIONS_MAX = 3;
46
+ export declare const trendNicheSuggestion: z.ZodObject<{
47
+ keywords: z.ZodString;
48
+ platform: z.ZodEnum<{
49
+ instagram: "instagram";
50
+ mix: "mix";
51
+ tiktok: "tiktok";
52
+ }>;
53
+ from: z.ZodObject<{
54
+ platform: z.ZodEnum<{
55
+ instagram: "instagram";
56
+ tiktok: "tiktok";
57
+ }>;
58
+ handle: z.ZodString;
59
+ }, z.core.$strict>;
60
+ videos: z.ZodNumber;
61
+ took_off: z.ZodNumber;
62
+ }, z.core.$strict>;
63
+ export type TrendNicheSuggestion = z.infer<typeof trendNicheSuggestion>;
44
64
  export declare const trendNiches: z.ZodObject<{
45
65
  niches: z.ZodArray<z.ZodObject<{
46
66
  keywords: z.ZodString;
@@ -54,6 +74,23 @@ export declare const trendNiches: z.ZodObject<{
54
74
  }, z.core.$strict>>;
55
75
  max_niches: z.ZodNumber;
56
76
  updated_at: z.ZodNullable<z.ZodString>;
77
+ suggested: z.ZodOptional<z.ZodArray<z.ZodObject<{
78
+ keywords: z.ZodString;
79
+ platform: z.ZodEnum<{
80
+ instagram: "instagram";
81
+ mix: "mix";
82
+ tiktok: "tiktok";
83
+ }>;
84
+ from: z.ZodObject<{
85
+ platform: z.ZodEnum<{
86
+ instagram: "instagram";
87
+ tiktok: "tiktok";
88
+ }>;
89
+ handle: z.ZodString;
90
+ }, z.core.$strict>;
91
+ videos: z.ZodNumber;
92
+ took_off: z.ZodNumber;
93
+ }, z.core.$strict>>>;
57
94
  }, z.core.$strict>;
58
95
  export type TrendNiches = z.infer<typeof trendNiches>;
59
96
  export declare const trendNichesRead: z.ZodObject<{
@@ -65,8 +102,28 @@ export declare const trendNichesRead: z.ZodObject<{
65
102
  }, z.core.$strip>>;
66
103
  max_niches: z.ZodNumber;
67
104
  updated_at: z.ZodNullable<z.ZodString>;
105
+ suggested: z.ZodOptional<z.ZodArray<z.ZodObject<{
106
+ keywords: z.ZodString;
107
+ platform: z.ZodString;
108
+ from: z.ZodObject<{
109
+ platform: z.ZodString;
110
+ handle: z.ZodString;
111
+ }, z.core.$strip>;
112
+ videos: z.ZodNumber;
113
+ took_off: z.ZodNumber;
114
+ }, z.core.$strip>>>;
68
115
  }, z.core.$strip>;
69
116
  export type TrendNichesRead = z.infer<typeof trendNichesRead>;
117
+ export declare function suggestTrendNiches(profiles: readonly {
118
+ platform: CreatorPlatform;
119
+ handle: string;
120
+ videos: readonly {
121
+ caption: string | null;
122
+ tookOff: boolean;
123
+ }[];
124
+ }[], saved: readonly {
125
+ keywords: string;
126
+ }[]): TrendNicheSuggestion[];
70
127
  export declare const findTrendsInput: z.ZodObject<{
71
128
  keywords: z.ZodOptional<z.ZodString>;
72
129
  platform: z.ZodOptional<z.ZodEnum<{
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
- import { findTrendsRequest, TREND_FREE_PAGES_PER_DAY, TREND_PAGE_PAID_CREDITS, TREND_PAGE_WINDOW_SECONDS, TREND_PLATFORMS, TREND_SEARCH_DEFAULT_DAYS, TREND_SEARCH_MAX_DAYS, TREND_SEARCH_MAX_PAGES, TREND_SEARCH_MIN_DAYS, trendPage, trendSearchId, } from "./trend-search.js";
2
+ import { CREATOR_PLATFORMS } from "./creator-profile.js";
3
+ import { findTrendsRequest, TREND_FREE_PAGES_PER_DAY, TREND_LANGUAGE_DESCRIPTION, TREND_PAGE_PAID_CREDITS, TREND_PAGE_WINDOW_SECONDS, TREND_PLATFORMS, TREND_SEARCH_DEFAULT_DAYS, TREND_SEARCH_MAX_DAYS, TREND_SEARCH_MAX_PAGES, TREND_SEARCH_MIN_DAYS, trendPage, trendSearchId, } from "./trend-search.js";
3
4
  import { maxCreditsField } from "./max-credits.js";
4
5
  export const TREND_NICHES_PATH = "/v1/trend-niches";
5
6
  export const TREND_NICHES_MAX = 3;
@@ -8,7 +9,7 @@ const language = z.string().regex(/^[a-z]{2}$/);
8
9
  export const trendNicheInput = z.strictObject({
9
10
  keywords: keywords.describe("The niche's topic in a few words, as you would search it."),
10
11
  platform: z.enum(TREND_PLATFORMS).default("mix").describe("mix (default): TikTok and Instagram together; or one of them."),
11
- language: language.optional().describe("ISO 639-1; filters TikTok only."),
12
+ language: language.optional().describe(TREND_LANGUAGE_DESCRIPTION),
12
13
  });
13
14
  const wordsOf = (value) => value.trim().toLowerCase().replace(/\s+/g, " ");
14
15
  export const trendNicheKey = (niche) => `${niche.platform}:${niche.language ?? "*"}:${wordsOf(niche.keywords)}`;
@@ -23,20 +24,72 @@ export const trendNiche = z.strictObject({
23
24
  language: z.string().nullable(),
24
25
  primary: z.boolean().describe("True for the first: a trend search with no keywords searches it."),
25
26
  });
27
+ export const TREND_NICHE_SUGGESTIONS_MAX = 3;
28
+ export const trendNicheSuggestion = z.strictObject({
29
+ keywords: keywords.describe("The niche's words, read from a hashtag."),
30
+ platform: z.enum(TREND_PLATFORMS).describe("mix: a suggestion searches TikTok and Instagram together."),
31
+ from: z.strictObject({ platform: z.enum(CREATOR_PLATFORMS), handle: z.string().min(1).max(64) }).describe("The analysed creator whose captions carry it."),
32
+ videos: z.number().int().nonnegative().describe("How many of that creator's analysed captions carry the hashtag."),
33
+ took_off: z.number().int().nonnegative().describe("How many of those videos took off."),
34
+ });
26
35
  export const trendNiches = z.strictObject({
27
36
  niches: z.array(trendNiche).max(TREND_NICHES_MAX).describe("The saved niches, the primary first."),
28
37
  max_niches: z.number().int().positive(),
29
38
  updated_at: z.string().datetime().nullable().describe("When the list was last saved; null when it never was."),
39
+ suggested: z.array(trendNicheSuggestion).max(TREND_NICHE_SUGGESTIONS_MAX).optional().describe(`Up to ${TREND_NICHE_SUGGESTIONS_MAX} niches read ` +
40
+ "for free from the hashtags of the creators this account analysed; GET only. Third-party words: show them and save only what the user confirms."),
30
41
  });
31
42
  export const trendNichesRead = z.object({
32
43
  niches: z.array(z.object({ keywords: z.string(), platform: z.string(), language: z.string().nullable(), primary: z.boolean() })),
33
44
  max_niches: z.number().int(),
34
45
  updated_at: z.string().nullable(),
46
+ suggested: z.array(z.object({ keywords: z.string(), platform: z.string(), from: z.object({ platform: z.string(), handle: z.string() }),
47
+ videos: z.number().int(), took_off: z.number().int() })).optional(),
35
48
  });
49
+ const GENERIC_TAGS = new Set(["fyp", "foryou", "foryoupage", "foryourpage", "fy", "fypシ", "fypage", "viral", "viralvideo", "viralvideos", "viralreels",
50
+ "trending", "trend", "trends", "explore", "explorepage", "reels", "reel", "reelsinstagram", "reelsvideo", "reelitfeelit", "instagram", "instagood",
51
+ "instareels", "insta", "tiktok", "tiktokviral", "parati", "paratii", "xyzbca", "capcut", "shorts", "short", "love", "like", "likes", "like4like",
52
+ "follow", "followme", "follow4follow", "ad", "ads", "sponsored", "collab", "gifted", "ugc", "ugccreator", "video", "videos", "photooftheday",
53
+ "duet", "stitch", "greenscreen"]);
54
+ const HASHTAG = /#[\p{L}\p{N}_]{2,40}/gu;
55
+ const SUGGESTION_MIN_CAPTIONS = 2;
56
+ const tagWords = (tag) => tag.slice(1).replace(/(?<=[\p{Ll}\p{N}])(?=\p{Lu})/gu, " ").replace(/_+/g, " ").trim()
57
+ .toLowerCase().replace(/\s+/g, " ");
58
+ export function suggestTrendNiches(profiles, saved) {
59
+ const joined = (words) => wordsOf(words).replace(/[\s_]+/g, "");
60
+ const savedWords = new Set(saved.map((niche) => joined(niche.keywords)));
61
+ const best = new Map();
62
+ for (const profile of profiles) {
63
+ const tags = new Map();
64
+ for (const video of profile.videos) {
65
+ const better = (tag, held) => (held === undefined || tag !== tag.toLowerCase() && held === held.toLowerCase() ? tag : held);
66
+ const inCaption = new Map();
67
+ for (const tag of video.caption?.match(HASHTAG) ?? [])
68
+ inCaption.set(tag.toLowerCase(), better(tag, inCaption.get(tag.toLowerCase())));
69
+ for (const [key, tag] of inCaption) {
70
+ const held = tags.get(key);
71
+ tags.set(key, { videos: (held?.videos ?? 0) + 1, tookOff: (held?.tookOff ?? 0) + (video.tookOff ? 1 : 0), spelled: better(tag, held?.spelled) });
72
+ }
73
+ }
74
+ for (const [key, tag] of tags) {
75
+ const words = tagWords(tag.spelled);
76
+ if (tag.videos < SUGGESTION_MIN_CAPTIONS || GENERIC_TAGS.has(joined(key.slice(1))) || savedWords.has(joined(words))
77
+ || !keywords.safeParse(words).success)
78
+ continue;
79
+ const weight = tag.videos + 2 * tag.tookOff, held = best.get(joined(words));
80
+ if (held !== undefined && held.weight >= weight)
81
+ continue;
82
+ best.set(joined(words), { weight, suggestion: { keywords: words, platform: "mix", from: { platform: profile.platform, handle: profile.handle },
83
+ videos: tag.videos, took_off: tag.tookOff } });
84
+ }
85
+ }
86
+ return [...best.values()].sort((a, b) => b.weight - a.weight || a.suggestion.keywords.localeCompare(b.suggestion.keywords))
87
+ .slice(0, TREND_NICHE_SUGGESTIONS_MAX).map((entry) => entry.suggestion);
88
+ }
36
89
  export const findTrendsInput = z.strictObject({
37
90
  keywords: keywords.optional().describe("The topic in a few words; absent: the primary saved niche (trend_niches) with its platform and language."),
38
91
  platform: z.enum(TREND_PLATFORMS).optional().describe("mix (default): TikTok and Instagram ranked together; or one of them."),
39
- language: language.optional().describe("ISO 639-1; filters TikTok only."),
92
+ language: language.optional().describe(TREND_LANGUAGE_DESCRIPTION),
40
93
  posted_within_days: z.number().int().min(TREND_SEARCH_MIN_DAYS).max(TREND_SEARCH_MAX_DAYS).optional()
41
94
  .describe(`Reels posted within this many days: ${TREND_SEARCH_MIN_DAYS} is the last 24 hours, ${TREND_SEARCH_DEFAULT_DAYS} by default, ` +
42
95
  `at most ${TREND_SEARCH_MAX_DAYS}.`),
@@ -75,4 +128,6 @@ export const TREND_NICHE_REFRESH_DAYS = 7;
75
128
  export const TREND_DIGEST_REELS = 5;
76
129
  export const digestReels = (reels) => reels.filter((reel) => reel.top || reel.takeoff !== null).slice(0, TREND_DIGEST_REELS);
77
130
  export const TREND_NICHES_DESCRIPTION = "Free. With no niches: the account's saved niches, the first the primary. niches: save the user's confirmed list " +
78
- `(at most ${TREND_NICHES_MAX}, it replaces the saved one; [] clears it). find_trends and quote_trends with no keywords search the primary niche.`;
131
+ `(at most ${TREND_NICHES_MAX}, it replaces the saved one; [] clears it). find_trends and quote_trends with no keywords search the primary niche. ` +
132
+ `The read also answers suggested: up to ${TREND_NICHE_SUGGESTIONS_MAX} niches from the hashtags of creators this account analysed. Show them; ` +
133
+ "a niche is saved only once the user confirms it. With no suggestions, you may propose two or three wordings from the about that extract_brand returned.";
@@ -81,6 +81,7 @@ export declare const findTrendsPayload: z.ZodObject<{
81
81
  page: z.ZodOptional<z.ZodNumber>;
82
82
  }, z.core.$strict>;
83
83
  export type FindTrendsPayload = z.infer<typeof findTrendsPayload>;
84
+ export declare const TREND_LANGUAGE_DESCRIPTION: string;
84
85
  export declare const findTrendsRequest: z.ZodObject<{
85
86
  keywords: z.ZodString;
86
87
  platform: z.ZodDefault<z.ZodEnum<{
@@ -79,11 +79,13 @@ export const TREND_SEARCH_ERROR_MESSAGES = {
79
79
  no_more_places: "no new reel with a known x_median was found past the places already shown; nothing was charged; start a new search with other words",
80
80
  };
81
81
  export const findTrendsPayload = z.strictObject({ searchId: trendSearchId, accountId: z.string().min(1), page: trendPage.optional() });
82
+ export const TREND_LANGUAGE_DESCRIPTION = "ISO 639-1: keeps reels in this language, read from the platform's label or the caption; " +
83
+ "a reel whose language cannot be told is kept.";
82
84
  export const findTrendsRequest = z.strictObject({
83
85
  keywords: z.string().min(2).max(100).refine((value) => value.trim().length >= 2, "keywords needs at least 2 characters besides spaces")
84
86
  .describe("The topic in a few words."),
85
87
  platform: z.enum(TREND_PLATFORMS).default("mix"),
86
- language: z.string().regex(/^[a-z]{2}$/).optional().describe("ISO 639-1; filters TikTok only."),
88
+ language: z.string().regex(/^[a-z]{2}$/).optional().describe(TREND_LANGUAGE_DESCRIPTION),
87
89
  posted_within_days: z.number().int().min(TREND_SEARCH_MIN_DAYS).max(TREND_SEARCH_MAX_DAYS).default(TREND_SEARCH_DEFAULT_DAYS)
88
90
  .describe(`Reels posted within this many days: ${TREND_SEARCH_MIN_DAYS} is the last 24 hours, ${TREND_SEARCH_DEFAULT_DAYS} by default, ` +
89
91
  `at most ${TREND_SEARCH_MAX_DAYS}.`),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clipwright/core",
3
- "version": "0.61.0",
3
+ "version": "0.63.0",
4
4
  "description": "Zod schemas and the shared request/response contract of the Clipwright UGC video API",
5
5
  "repository": {
6
6
  "type": "git",