vidspotai-shared 1.0.82 → 1.0.84

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 (442) hide show
  1. package/lib/globals/aiModels/enums.d.ts +11 -1
  2. package/lib/globals/aiModels/enums.d.ts.map +1 -1
  3. package/lib/globals/aiModels/enums.js +24 -1
  4. package/lib/globals/aiModels/index.d.ts.map +1 -1
  5. package/lib/globals/aiModels/index.js +2 -0
  6. package/lib/globals/aiModels/providers/anthropic.d.ts +12 -0
  7. package/lib/globals/aiModels/providers/anthropic.d.ts.map +1 -0
  8. package/lib/globals/aiModels/providers/anthropic.js +88 -0
  9. package/lib/globals/aiModels/providers/google.d.ts.map +1 -1
  10. package/lib/globals/aiModels/providers/google.js +82 -0
  11. package/lib/globals/aiModels/providers/openai.d.ts.map +1 -1
  12. package/lib/globals/aiModels/providers/openai.js +63 -4
  13. package/lib/globals/aiModels/tierHelpers.d.ts +12 -0
  14. package/lib/globals/aiModels/tierHelpers.d.ts.map +1 -1
  15. package/lib/globals/aiModels/tierHelpers.js +83 -0
  16. package/lib/globals/aiModels/types.d.ts +19 -0
  17. package/lib/globals/aiModels/types.d.ts.map +1 -1
  18. package/lib/globals/types.d.ts +120 -1
  19. package/lib/globals/types.d.ts.map +1 -1
  20. package/lib/globals/types.js +135 -1
  21. package/lib/models/agent.model.d.ts +41 -1
  22. package/lib/models/agent.model.d.ts.map +1 -1
  23. package/lib/models/index.d.ts +1 -0
  24. package/lib/models/index.d.ts.map +1 -1
  25. package/lib/models/index.js +1 -0
  26. package/lib/models/social.model.d.ts +180 -0
  27. package/lib/models/social.model.d.ts.map +1 -0
  28. package/lib/models/social.model.js +2 -0
  29. package/lib/models/user.model.d.ts +10 -0
  30. package/lib/models/user.model.d.ts.map +1 -1
  31. package/lib/models/video.model.d.ts +6 -0
  32. package/lib/models/video.model.d.ts.map +1 -1
  33. package/lib/schemas/brief.schema.d.ts +46 -0
  34. package/lib/schemas/brief.schema.d.ts.map +1 -1
  35. package/lib/schemas/brief.schema.js +72 -1
  36. package/lib/schemas/index.d.ts +1 -0
  37. package/lib/schemas/index.d.ts.map +1 -1
  38. package/lib/schemas/index.js +1 -0
  39. package/lib/schemas/project.schema.d.ts +67 -0
  40. package/lib/schemas/project.schema.d.ts.map +1 -1
  41. package/lib/schemas/project.schema.js +12 -0
  42. package/lib/schemas/social.schema.d.ts +91 -0
  43. package/lib/schemas/social.schema.d.ts.map +1 -0
  44. package/lib/schemas/social.schema.js +114 -0
  45. package/lib/schemas/videoPlan.schema.d.ts +114 -0
  46. package/lib/schemas/videoPlan.schema.d.ts.map +1 -1
  47. package/lib/schemas/videoPlan.schema.js +141 -1
  48. package/lib/services/agent/chatAgent.d.ts +25 -1
  49. package/lib/services/agent/chatAgent.d.ts.map +1 -1
  50. package/lib/services/agent/chatAgent.js +145 -9
  51. package/lib/services/agent/costPreflight.d.ts +11 -1
  52. package/lib/services/agent/costPreflight.d.ts.map +1 -1
  53. package/lib/services/agent/costPreflight.js +18 -1
  54. package/lib/services/agent/covers/coverPlanner.d.ts +41 -0
  55. package/lib/services/agent/covers/coverPlanner.d.ts.map +1 -0
  56. package/lib/services/agent/covers/coverPlanner.js +278 -0
  57. package/lib/services/agent/covers/covers.schema.d.ts +158 -0
  58. package/lib/services/agent/covers/covers.schema.d.ts.map +1 -0
  59. package/lib/services/agent/covers/covers.schema.js +166 -0
  60. package/lib/services/agent/covers/index.d.ts +3 -0
  61. package/lib/services/agent/covers/index.d.ts.map +1 -0
  62. package/lib/services/agent/covers/index.js +18 -0
  63. package/lib/services/agent/critic.d.ts +10 -0
  64. package/lib/services/agent/critic.d.ts.map +1 -1
  65. package/lib/services/agent/critic.js +37 -1
  66. package/lib/services/agent/editClassifier.d.ts +2 -2
  67. package/lib/services/agent/editClassifier.js +2 -2
  68. package/lib/services/agent/editExisting/editAssembler.d.ts +78 -0
  69. package/lib/services/agent/editExisting/editAssembler.d.ts.map +1 -0
  70. package/lib/services/agent/editExisting/editAssembler.js +172 -0
  71. package/lib/services/agent/editExisting/editExisting.schema.d.ts +119 -0
  72. package/lib/services/agent/editExisting/editExisting.schema.d.ts.map +1 -0
  73. package/lib/services/agent/editExisting/editExisting.schema.js +157 -0
  74. package/lib/services/agent/editExisting/highlightPicker.d.ts +48 -0
  75. package/lib/services/agent/editExisting/highlightPicker.d.ts.map +1 -0
  76. package/lib/services/agent/editExisting/highlightPicker.js +199 -0
  77. package/lib/services/agent/editExisting/index.d.ts +4 -0
  78. package/lib/services/agent/editExisting/index.d.ts.map +1 -0
  79. package/lib/services/agent/editExisting/index.js +19 -0
  80. package/lib/services/agent/eval/seedBriefs.d.ts +4 -3
  81. package/lib/services/agent/eval/seedBriefs.d.ts.map +1 -1
  82. package/lib/services/agent/eval/seedBriefs.js +283 -3
  83. package/lib/services/agent/eval/types.d.ts +10 -0
  84. package/lib/services/agent/eval/types.d.ts.map +1 -1
  85. package/lib/services/agent/executor/core.d.ts +70 -0
  86. package/lib/services/agent/executor/core.d.ts.map +1 -0
  87. package/lib/services/agent/executor/core.js +250 -0
  88. package/lib/services/agent/executor/duration.d.ts +20 -0
  89. package/lib/services/agent/executor/duration.d.ts.map +1 -0
  90. package/lib/services/agent/executor/duration.js +46 -0
  91. package/lib/services/agent/executor/index.d.ts +15 -0
  92. package/lib/services/agent/executor/index.d.ts.map +1 -0
  93. package/lib/services/agent/executor/index.js +32 -0
  94. package/lib/services/agent/executor/types.d.ts +183 -0
  95. package/lib/services/agent/executor/types.d.ts.map +1 -0
  96. package/lib/services/agent/executor/types.js +29 -0
  97. package/lib/services/agent/executor/visual.d.ts +32 -0
  98. package/lib/services/agent/executor/visual.d.ts.map +1 -0
  99. package/lib/services/agent/executor/visual.js +400 -0
  100. package/lib/services/agent/executor/voice.d.ts +17 -0
  101. package/lib/services/agent/executor/voice.d.ts.map +1 -0
  102. package/lib/services/agent/executor/voice.js +119 -0
  103. package/lib/services/agent/extendChain.d.ts +101 -0
  104. package/lib/services/agent/extendChain.d.ts.map +1 -0
  105. package/lib/services/agent/extendChain.js +177 -0
  106. package/lib/services/agent/index.d.ts +11 -1
  107. package/lib/services/agent/index.d.ts.map +1 -1
  108. package/lib/services/agent/index.js +11 -1
  109. package/lib/services/agent/llmCaller.d.ts +7 -8
  110. package/lib/services/agent/llmCaller.d.ts.map +1 -1
  111. package/lib/services/agent/llmCallerAnthropic.d.ts +44 -31
  112. package/lib/services/agent/llmCallerAnthropic.d.ts.map +1 -1
  113. package/lib/services/agent/llmCallerAnthropic.js +135 -60
  114. package/lib/services/agent/llmCallerFactory.d.ts +34 -0
  115. package/lib/services/agent/llmCallerFactory.d.ts.map +1 -0
  116. package/lib/services/agent/llmCallerFactory.js +31 -0
  117. package/lib/services/agent/llmCallerGemini.d.ts +62 -0
  118. package/lib/services/agent/llmCallerGemini.d.ts.map +1 -0
  119. package/lib/services/agent/llmCallerGemini.js +235 -0
  120. package/lib/services/agent/llmCallerOpenai.d.ts +56 -0
  121. package/lib/services/agent/llmCallerOpenai.d.ts.map +1 -0
  122. package/lib/services/agent/llmCallerOpenai.js +230 -0
  123. package/lib/services/agent/llmCallerRegistry.d.ts.map +1 -1
  124. package/lib/services/agent/llmCallerRegistry.js +7 -7
  125. package/lib/services/agent/llmCallerRouting.d.ts +63 -0
  126. package/lib/services/agent/llmCallerRouting.d.ts.map +1 -0
  127. package/lib/services/agent/llmCallerRouting.js +124 -0
  128. package/lib/services/agent/llmModelRegistry.d.ts +59 -0
  129. package/lib/services/agent/llmModelRegistry.d.ts.map +1 -0
  130. package/lib/services/agent/llmModelRegistry.js +168 -0
  131. package/lib/services/agent/llmRetry.d.ts +57 -0
  132. package/lib/services/agent/llmRetry.d.ts.map +1 -0
  133. package/lib/services/agent/llmRetry.js +102 -0
  134. package/lib/services/agent/modelRouter.d.ts +3 -3
  135. package/lib/services/agent/modelRouter.d.ts.map +1 -1
  136. package/lib/services/agent/modelRouter.js +27 -13
  137. package/lib/services/agent/planMutations.d.ts +54 -1
  138. package/lib/services/agent/planMutations.d.ts.map +1 -1
  139. package/lib/services/agent/planMutations.js +78 -0
  140. package/lib/services/agent/planner/Planner.d.ts +0 -17
  141. package/lib/services/agent/planner/Planner.d.ts.map +1 -1
  142. package/lib/services/agent/planner/Planner.js +67 -303
  143. package/lib/services/agent/planner/overlayRegen.d.ts +38 -0
  144. package/lib/services/agent/planner/overlayRegen.d.ts.map +1 -0
  145. package/lib/services/agent/planner/overlayRegen.js +145 -0
  146. package/lib/services/agent/planner/plannerMessages.d.ts +34 -0
  147. package/lib/services/agent/planner/plannerMessages.d.ts.map +1 -0
  148. package/lib/services/agent/planner/plannerMessages.js +185 -0
  149. package/lib/services/agent/planner/promptSections.d.ts +12 -0
  150. package/lib/services/agent/planner/promptSections.d.ts.map +1 -1
  151. package/lib/services/agent/planner/promptSections.js +57 -0
  152. package/lib/services/agent/planner/scriptFirstPlanner.d.ts +35 -0
  153. package/lib/services/agent/planner/scriptFirstPlanner.d.ts.map +1 -0
  154. package/lib/services/agent/planner/scriptFirstPlanner.js +140 -0
  155. package/lib/services/agent/planner/structuralRules.d.ts +10 -0
  156. package/lib/services/agent/planner/structuralRules.d.ts.map +1 -1
  157. package/lib/services/agent/planner/structuralRules.js +92 -9
  158. package/lib/services/agent/planner/validators.d.ts +18 -0
  159. package/lib/services/agent/planner/validators.d.ts.map +1 -1
  160. package/lib/services/agent/planner/validators.js +97 -0
  161. package/lib/services/agent/planner.d.ts +2 -1
  162. package/lib/services/agent/planner.d.ts.map +1 -1
  163. package/lib/services/agent/planner.js +5 -1
  164. package/lib/services/agent/priorProject.d.ts +26 -0
  165. package/lib/services/agent/priorProject.d.ts.map +1 -0
  166. package/lib/services/agent/priorProject.js +51 -0
  167. package/lib/services/agent/providerFallback/chains.d.ts.map +1 -1
  168. package/lib/services/agent/providerFallback/chains.js +27 -15
  169. package/lib/services/agent/repurpose/index.d.ts +3 -0
  170. package/lib/services/agent/repurpose/index.d.ts.map +1 -0
  171. package/lib/services/agent/repurpose/index.js +18 -0
  172. package/lib/services/agent/repurpose/repurpose.schema.d.ts +132 -0
  173. package/lib/services/agent/repurpose/repurpose.schema.d.ts.map +1 -0
  174. package/lib/services/agent/repurpose/repurpose.schema.js +144 -0
  175. package/lib/services/agent/repurpose/shortsPicker.d.ts +25 -0
  176. package/lib/services/agent/repurpose/shortsPicker.d.ts.map +1 -0
  177. package/lib/services/agent/repurpose/shortsPicker.js +218 -0
  178. package/lib/services/agent/runHelpers.d.ts +21 -2
  179. package/lib/services/agent/runHelpers.d.ts.map +1 -1
  180. package/lib/services/agent/runHelpers.js +71 -2
  181. package/lib/services/agent/tools/animateImage.tool.d.ts +1 -0
  182. package/lib/services/agent/tools/animateImage.tool.d.ts.map +1 -1
  183. package/lib/services/agent/tools/animateImage.tool.js +12 -0
  184. package/lib/services/agent/tools/chapterOutline.tool.d.ts +42 -0
  185. package/lib/services/agent/tools/chapterOutline.tool.d.ts.map +1 -0
  186. package/lib/services/agent/tools/chapterOutline.tool.js +115 -0
  187. package/lib/services/agent/tools/composeScene.tool.d.ts +63 -0
  188. package/lib/services/agent/tools/composeScene.tool.d.ts.map +1 -1
  189. package/lib/services/agent/tools/estimateCost.tool.d.ts +27 -0
  190. package/lib/services/agent/tools/estimateCost.tool.d.ts.map +1 -1
  191. package/lib/services/agent/tools/estimateCost.tool.js +55 -7
  192. package/lib/services/agent/tools/extendVideo.tool.d.ts +26 -0
  193. package/lib/services/agent/tools/extendVideo.tool.d.ts.map +1 -0
  194. package/lib/services/agent/tools/extendVideo.tool.js +149 -0
  195. package/lib/services/agent/tools/generateScript.tool.d.ts +184 -0
  196. package/lib/services/agent/tools/generateScript.tool.d.ts.map +1 -0
  197. package/lib/services/agent/tools/generateScript.tool.js +123 -0
  198. package/lib/services/agent/tools/generateVideo.tool.d.ts +1 -0
  199. package/lib/services/agent/tools/generateVideo.tool.d.ts.map +1 -1
  200. package/lib/services/agent/tools/generateVideo.tool.js +20 -1
  201. package/lib/services/agent/tools/index.d.ts +4 -0
  202. package/lib/services/agent/tools/index.d.ts.map +1 -1
  203. package/lib/services/agent/tools/index.js +4 -0
  204. package/lib/services/agent/tools/matchBrollToScript.tool.d.ts +50 -0
  205. package/lib/services/agent/tools/matchBrollToScript.tool.d.ts.map +1 -0
  206. package/lib/services/agent/tools/matchBrollToScript.tool.js +139 -0
  207. package/lib/services/agent/tools/planVideo.tool.d.ts +56 -0
  208. package/lib/services/agent/tools/planVideo.tool.d.ts.map +1 -1
  209. package/lib/services/agent/tools/planVideo.tool.js +3 -3
  210. package/lib/services/agent/tools/render.tool.d.ts +21 -0
  211. package/lib/services/agent/tools/render.tool.d.ts.map +1 -1
  212. package/lib/services/aiGen/aiGenFactory.service.d.ts.map +1 -1
  213. package/lib/services/aiGen/aiGenFactory.service.js +18 -3
  214. package/lib/services/aiGen/providers/anthropic/anthropic.service.d.ts +26 -0
  215. package/lib/services/aiGen/providers/anthropic/anthropic.service.d.ts.map +1 -0
  216. package/lib/services/aiGen/providers/anthropic/anthropic.service.js +95 -0
  217. package/lib/services/aiGen/providers/google/google.service.d.ts +24 -1
  218. package/lib/services/aiGen/providers/google/google.service.d.ts.map +1 -1
  219. package/lib/services/aiGen/providers/google/google.service.js +96 -244
  220. package/lib/services/aiGen/providers/google/googleErrors.d.ts +13 -0
  221. package/lib/services/aiGen/providers/google/googleErrors.d.ts.map +1 -0
  222. package/lib/services/aiGen/providers/google/googleErrors.js +102 -0
  223. package/lib/services/aiGen/providers/google/googleFetch.d.ts +8 -0
  224. package/lib/services/aiGen/providers/google/googleFetch.d.ts.map +1 -0
  225. package/lib/services/aiGen/providers/google/googleFetch.js +96 -0
  226. package/lib/services/aiGen/providers/google/googleMusic.d.ts +15 -0
  227. package/lib/services/aiGen/providers/google/googleMusic.d.ts.map +1 -0
  228. package/lib/services/aiGen/providers/google/googleMusic.js +77 -0
  229. package/lib/services/aiGen/providers/kling/kling.service.d.ts +7 -3
  230. package/lib/services/aiGen/providers/kling/kling.service.d.ts.map +1 -1
  231. package/lib/services/aiGen/providers/kling/kling.service.js +23 -367
  232. package/lib/services/aiGen/providers/kling/klingCredits.d.ts +9 -0
  233. package/lib/services/aiGen/providers/kling/klingCredits.d.ts.map +1 -0
  234. package/lib/services/aiGen/providers/kling/klingCredits.js +63 -0
  235. package/lib/services/aiGen/providers/kling/klingRequests.d.ts +32 -0
  236. package/lib/services/aiGen/providers/kling/klingRequests.d.ts.map +1 -0
  237. package/lib/services/aiGen/providers/kling/klingRequests.js +194 -0
  238. package/lib/services/aiGen/providers/kling/klingStatus.d.ts +16 -0
  239. package/lib/services/aiGen/providers/kling/klingStatus.d.ts.map +1 -0
  240. package/lib/services/aiGen/providers/kling/klingStatus.js +173 -0
  241. package/lib/services/bullmq.service.d.ts +61 -0
  242. package/lib/services/bullmq.service.d.ts.map +1 -1
  243. package/lib/services/bullmq.service.js +101 -1
  244. package/lib/services/crypto/index.d.ts +2 -0
  245. package/lib/services/crypto/index.d.ts.map +1 -0
  246. package/lib/services/crypto/index.js +17 -0
  247. package/lib/services/crypto/tokenVault.d.ts +47 -0
  248. package/lib/services/crypto/tokenVault.d.ts.map +1 -0
  249. package/lib/services/crypto/tokenVault.js +179 -0
  250. package/lib/services/editor/captionStyleHint.d.ts +3 -0
  251. package/lib/services/editor/captionStyleHint.d.ts.map +1 -0
  252. package/lib/services/editor/captionStyleHint.js +112 -0
  253. package/lib/services/editor/planToProject.d.ts +7 -66
  254. package/lib/services/editor/planToProject.d.ts.map +1 -1
  255. package/lib/services/editor/planToProject.helpers.d.ts +40 -0
  256. package/lib/services/editor/planToProject.helpers.d.ts.map +1 -0
  257. package/lib/services/editor/planToProject.helpers.js +177 -0
  258. package/lib/services/editor/planToProject.js +197 -180
  259. package/lib/services/editor/planToProject.types.d.ts +94 -0
  260. package/lib/services/editor/planToProject.types.d.ts.map +1 -0
  261. package/lib/services/editor/planToProject.types.js +2 -0
  262. package/lib/services/firestore.service.d.ts +5 -0
  263. package/lib/services/firestore.service.d.ts.map +1 -1
  264. package/lib/services/firestore.service.js +13 -0
  265. package/lib/services/index.d.ts +12 -0
  266. package/lib/services/index.d.ts.map +1 -1
  267. package/lib/services/index.js +12 -0
  268. package/lib/services/promptEnhancer/index.d.ts +18 -0
  269. package/lib/services/promptEnhancer/index.d.ts.map +1 -0
  270. package/lib/services/promptEnhancer/index.js +33 -0
  271. package/lib/services/promptEnhancer/models.d.ts +54 -0
  272. package/lib/services/promptEnhancer/models.d.ts.map +1 -0
  273. package/lib/services/promptEnhancer/models.js +37 -0
  274. package/lib/services/promptEnhancer/profiles/agent.profile.d.ts +14 -0
  275. package/lib/services/promptEnhancer/profiles/agent.profile.d.ts.map +1 -0
  276. package/lib/services/promptEnhancer/profiles/agent.profile.js +40 -0
  277. package/lib/services/promptEnhancer/profiles/avatar.profile.d.ts +13 -0
  278. package/lib/services/promptEnhancer/profiles/avatar.profile.d.ts.map +1 -0
  279. package/lib/services/promptEnhancer/profiles/avatar.profile.js +40 -0
  280. package/lib/services/promptEnhancer/profiles/base.d.ts +28 -0
  281. package/lib/services/promptEnhancer/profiles/base.d.ts.map +1 -0
  282. package/lib/services/promptEnhancer/profiles/base.js +35 -0
  283. package/lib/services/promptEnhancer/profiles/image.profile.d.ts +11 -0
  284. package/lib/services/promptEnhancer/profiles/image.profile.d.ts.map +1 -0
  285. package/lib/services/promptEnhancer/profiles/image.profile.js +42 -0
  286. package/lib/services/promptEnhancer/profiles/index.d.ts +12 -0
  287. package/lib/services/promptEnhancer/profiles/index.d.ts.map +1 -0
  288. package/lib/services/promptEnhancer/profiles/index.js +33 -0
  289. package/lib/services/promptEnhancer/profiles/video.profile.d.ts +15 -0
  290. package/lib/services/promptEnhancer/profiles/video.profile.d.ts.map +1 -0
  291. package/lib/services/promptEnhancer/profiles/video.profile.js +81 -0
  292. package/lib/services/promptEnhancer/promptEnhancer.service.d.ts +45 -0
  293. package/lib/services/promptEnhancer/promptEnhancer.service.d.ts.map +1 -0
  294. package/lib/services/promptEnhancer/promptEnhancer.service.js +157 -0
  295. package/lib/services/promptEnhancer/schema.d.ts +19 -0
  296. package/lib/services/promptEnhancer/schema.d.ts.map +1 -0
  297. package/lib/services/promptEnhancer/schema.js +43 -0
  298. package/lib/services/promptEnhancer/types.d.ts +112 -0
  299. package/lib/services/promptEnhancer/types.d.ts.map +1 -0
  300. package/lib/services/promptEnhancer/types.js +2 -0
  301. package/lib/services/socialAI/captionGen.d.ts +81 -0
  302. package/lib/services/socialAI/captionGen.d.ts.map +1 -0
  303. package/lib/services/socialAI/captionGen.js +206 -0
  304. package/lib/services/socialAI/hookScore.d.ts +85 -0
  305. package/lib/services/socialAI/hookScore.d.ts.map +1 -0
  306. package/lib/services/socialAI/hookScore.js +170 -0
  307. package/lib/services/socialAI/index.d.ts +3 -0
  308. package/lib/services/socialAI/index.d.ts.map +1 -0
  309. package/lib/services/socialAI/index.js +18 -0
  310. package/lib/services/socialAccounts/index.d.ts +2 -0
  311. package/lib/services/socialAccounts/index.d.ts.map +1 -0
  312. package/lib/services/socialAccounts/index.js +17 -0
  313. package/lib/services/socialAccounts/socialAccountService.d.ts +25 -0
  314. package/lib/services/socialAccounts/socialAccountService.d.ts.map +1 -0
  315. package/lib/services/socialAccounts/socialAccountService.js +105 -0
  316. package/lib/services/socialEngage/factory.d.ts +7 -0
  317. package/lib/services/socialEngage/factory.d.ts.map +1 -0
  318. package/lib/services/socialEngage/factory.js +25 -0
  319. package/lib/services/socialEngage/index.d.ts +6 -0
  320. package/lib/services/socialEngage/index.d.ts.map +1 -0
  321. package/lib/services/socialEngage/index.js +21 -0
  322. package/lib/services/socialEngage/meta.engage.d.ts +17 -0
  323. package/lib/services/socialEngage/meta.engage.d.ts.map +1 -0
  324. package/lib/services/socialEngage/meta.engage.js +128 -0
  325. package/lib/services/socialEngage/metaWebhook.d.ts +50 -0
  326. package/lib/services/socialEngage/metaWebhook.d.ts.map +1 -0
  327. package/lib/services/socialEngage/metaWebhook.js +93 -0
  328. package/lib/services/socialEngage/types.d.ts +72 -0
  329. package/lib/services/socialEngage/types.d.ts.map +1 -0
  330. package/lib/services/socialEngage/types.js +10 -0
  331. package/lib/services/socialEngage/youtube.engage.d.ts +9 -0
  332. package/lib/services/socialEngage/youtube.engage.d.ts.map +1 -0
  333. package/lib/services/socialEngage/youtube.engage.js +87 -0
  334. package/lib/services/socialFormat/aspectGeometry.d.ts +74 -0
  335. package/lib/services/socialFormat/aspectGeometry.d.ts.map +1 -0
  336. package/lib/services/socialFormat/aspectGeometry.js +135 -0
  337. package/lib/services/socialFormat/index.d.ts +2 -0
  338. package/lib/services/socialFormat/index.d.ts.map +1 -0
  339. package/lib/services/socialFormat/index.js +19 -0
  340. package/lib/services/socialInsights/index.d.ts +3 -0
  341. package/lib/services/socialInsights/index.d.ts.map +1 -0
  342. package/lib/services/socialInsights/index.js +18 -0
  343. package/lib/services/socialInsights/recommendations.d.ts +131 -0
  344. package/lib/services/socialInsights/recommendations.d.ts.map +1 -0
  345. package/lib/services/socialInsights/recommendations.js +277 -0
  346. package/lib/services/socialInsights/timeBuckets.d.ts +35 -0
  347. package/lib/services/socialInsights/timeBuckets.d.ts.map +1 -0
  348. package/lib/services/socialInsights/timeBuckets.js +78 -0
  349. package/lib/services/socialMetrics/factory.d.ts +5 -0
  350. package/lib/services/socialMetrics/factory.d.ts.map +1 -0
  351. package/lib/services/socialMetrics/factory.js +24 -0
  352. package/lib/services/socialMetrics/index.d.ts +6 -0
  353. package/lib/services/socialMetrics/index.d.ts.map +1 -0
  354. package/lib/services/socialMetrics/index.js +21 -0
  355. package/lib/services/socialMetrics/meta.metrics.d.ts +22 -0
  356. package/lib/services/socialMetrics/meta.metrics.d.ts.map +1 -0
  357. package/lib/services/socialMetrics/meta.metrics.js +137 -0
  358. package/lib/services/socialMetrics/tiktok.metrics.d.ts +8 -0
  359. package/lib/services/socialMetrics/tiktok.metrics.d.ts.map +1 -0
  360. package/lib/services/socialMetrics/tiktok.metrics.js +43 -0
  361. package/lib/services/socialMetrics/types.d.ts +54 -0
  362. package/lib/services/socialMetrics/types.d.ts.map +1 -0
  363. package/lib/services/socialMetrics/types.js +2 -0
  364. package/lib/services/socialMetrics/youtube.metrics.d.ts +8 -0
  365. package/lib/services/socialMetrics/youtube.metrics.d.ts.map +1 -0
  366. package/lib/services/socialMetrics/youtube.metrics.js +43 -0
  367. package/lib/services/socialOAuth/factory.d.ts +7 -0
  368. package/lib/services/socialOAuth/factory.d.ts.map +1 -0
  369. package/lib/services/socialOAuth/factory.js +42 -0
  370. package/lib/services/socialOAuth/index.d.ts +11 -0
  371. package/lib/services/socialOAuth/index.d.ts.map +1 -0
  372. package/lib/services/socialOAuth/index.js +26 -0
  373. package/lib/services/socialOAuth/linkedin.oauth.d.ts +14 -0
  374. package/lib/services/socialOAuth/linkedin.oauth.d.ts.map +1 -0
  375. package/lib/services/socialOAuth/linkedin.oauth.js +127 -0
  376. package/lib/services/socialOAuth/meta.oauth.d.ts +31 -0
  377. package/lib/services/socialOAuth/meta.oauth.d.ts.map +1 -0
  378. package/lib/services/socialOAuth/meta.oauth.js +214 -0
  379. package/lib/services/socialOAuth/oauthState.d.ts +14 -0
  380. package/lib/services/socialOAuth/oauthState.d.ts.map +1 -0
  381. package/lib/services/socialOAuth/oauthState.js +66 -0
  382. package/lib/services/socialOAuth/pinterest.oauth.d.ts +15 -0
  383. package/lib/services/socialOAuth/pinterest.oauth.d.ts.map +1 -0
  384. package/lib/services/socialOAuth/pinterest.oauth.js +126 -0
  385. package/lib/services/socialOAuth/threads.oauth.d.ts +14 -0
  386. package/lib/services/socialOAuth/threads.oauth.d.ts.map +1 -0
  387. package/lib/services/socialOAuth/threads.oauth.js +129 -0
  388. package/lib/services/socialOAuth/tiktok.oauth.d.ts +15 -0
  389. package/lib/services/socialOAuth/tiktok.oauth.d.ts.map +1 -0
  390. package/lib/services/socialOAuth/tiktok.oauth.js +151 -0
  391. package/lib/services/socialOAuth/types.d.ts +67 -0
  392. package/lib/services/socialOAuth/types.d.ts.map +1 -0
  393. package/lib/services/socialOAuth/types.js +2 -0
  394. package/lib/services/socialOAuth/x.oauth.d.ts +17 -0
  395. package/lib/services/socialOAuth/x.oauth.d.ts.map +1 -0
  396. package/lib/services/socialOAuth/x.oauth.js +134 -0
  397. package/lib/services/socialOAuth/youtube.oauth.d.ts +15 -0
  398. package/lib/services/socialOAuth/youtube.oauth.d.ts.map +1 -0
  399. package/lib/services/socialOAuth/youtube.oauth.js +156 -0
  400. package/lib/services/socialPublish/factory.d.ts +5 -0
  401. package/lib/services/socialPublish/factory.d.ts.map +1 -0
  402. package/lib/services/socialPublish/factory.js +32 -0
  403. package/lib/services/socialPublish/index.d.ts +10 -0
  404. package/lib/services/socialPublish/index.d.ts.map +1 -0
  405. package/lib/services/socialPublish/index.js +25 -0
  406. package/lib/services/socialPublish/linkedin.publish.d.ts +9 -0
  407. package/lib/services/socialPublish/linkedin.publish.d.ts.map +1 -0
  408. package/lib/services/socialPublish/linkedin.publish.js +143 -0
  409. package/lib/services/socialPublish/meta.publish.d.ts +28 -0
  410. package/lib/services/socialPublish/meta.publish.d.ts.map +1 -0
  411. package/lib/services/socialPublish/meta.publish.js +149 -0
  412. package/lib/services/socialPublish/pinterest.publish.d.ts +13 -0
  413. package/lib/services/socialPublish/pinterest.publish.d.ts.map +1 -0
  414. package/lib/services/socialPublish/pinterest.publish.js +130 -0
  415. package/lib/services/socialPublish/threads.publish.d.ts +12 -0
  416. package/lib/services/socialPublish/threads.publish.d.ts.map +1 -0
  417. package/lib/services/socialPublish/threads.publish.js +96 -0
  418. package/lib/services/socialPublish/tiktok.publish.d.ts +13 -0
  419. package/lib/services/socialPublish/tiktok.publish.d.ts.map +1 -0
  420. package/lib/services/socialPublish/tiktok.publish.js +118 -0
  421. package/lib/services/socialPublish/types.d.ts +47 -0
  422. package/lib/services/socialPublish/types.d.ts.map +1 -0
  423. package/lib/services/socialPublish/types.js +2 -0
  424. package/lib/services/socialPublish/x.publish.d.ts +12 -0
  425. package/lib/services/socialPublish/x.publish.d.ts.map +1 -0
  426. package/lib/services/socialPublish/x.publish.js +147 -0
  427. package/lib/services/socialPublish/youtube.publish.d.ts +9 -0
  428. package/lib/services/socialPublish/youtube.publish.d.ts.map +1 -0
  429. package/lib/services/socialPublish/youtube.publish.js +107 -0
  430. package/lib/services/stock/index.d.ts +2 -0
  431. package/lib/services/stock/index.d.ts.map +1 -0
  432. package/lib/services/stock/index.js +17 -0
  433. package/lib/services/stock/realPersonSafety.d.ts +99 -0
  434. package/lib/services/stock/realPersonSafety.d.ts.map +1 -0
  435. package/lib/services/stock/realPersonSafety.js +248 -0
  436. package/lib/utils/index.d.ts +1 -0
  437. package/lib/utils/index.d.ts.map +1 -1
  438. package/lib/utils/index.js +1 -0
  439. package/lib/utils/renderTier.d.ts +26 -0
  440. package/lib/utils/renderTier.d.ts.map +1 -0
  441. package/lib/utils/renderTier.js +34 -0
  442. package/package.json +1 -1
@@ -3,11 +3,105 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.defineTool = defineTool;
6
7
  exports.runChatTurn = runChatTurn;
7
8
  const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
9
+ const zod_1 = require("zod");
8
10
  const logger_1 = require("../../utils/logger");
11
+ /** Strip JSON-Schema keys Anthropic's tool `input_schema` doesn't want. */
12
+ function toAnthropicInputSchema(schema) {
13
+ const json = zod_1.z.toJSONSchema(schema);
14
+ // Anthropic's input_schema is a plain object schema; the `$schema` dialect
15
+ // marker is noise (and the top-level `description` is redundant with the
16
+ // tool's own description). Drop both; keep everything else verbatim.
17
+ delete json.$schema;
18
+ delete json.description;
19
+ return json;
20
+ }
21
+ function defineTool(spec) {
22
+ return {
23
+ name: spec.name,
24
+ description: spec.description,
25
+ inputSchema: toAnthropicInputSchema(spec.schema),
26
+ schema: spec.schema,
27
+ run: spec.run,
28
+ };
29
+ }
9
30
  const DEFAULT_MAX_ROUNDS = 6;
10
31
  const DEFAULT_MAX_TOKENS = 4096;
32
+ // ─────────────────── context compaction ───────────────────
33
+ //
34
+ // A multi-round tool-use turn accumulates every tool_result into the running
35
+ // `convo`. Some results are large (a full-plan get_project_state, a 30-item
36
+ // list_user_assets), and six rounds of them can crowd the model's context
37
+ // window — degrading or eventually erroring the next round. We bound the
38
+ // tool-result transcript with two structure-preserving levers (we only ever
39
+ // shrink the *content string* of a tool_result, never drop the block, so every
40
+ // tool_use keeps its matching tool_result and the request stays well-formed):
41
+ //
42
+ // 1. Hard-cap each individual tool_result (head+tail kept, middle elided).
43
+ // 2. If the transcript still exceeds budget, elide the OLDEST results to a
44
+ // stub (oldest-first), always preserving the newest few verbatim — by the
45
+ // time we're several rounds deep the model rarely needs round-1 output.
46
+ //
47
+ // Chars (not tokens) are the unit: cheap to measure, ~4 chars/token, and the
48
+ // caps are deliberately generous so this only fires on genuinely large turns.
49
+ const DEFAULT_MAX_RESULT_CHARS = 12000; // per single tool_result
50
+ const DEFAULT_MAX_TRANSCRIPT_CHARS = 90000; // ~22k tokens across all tool_results
51
+ const DEFAULT_KEEP_RECENT_RESULTS = 2; // newest N never elided past the per-result cap
52
+ function isToolResultBlock(b) {
53
+ return b.type === "tool_result";
54
+ }
55
+ /** Keep the head and tail, elide the middle with a byte-count marker. */
56
+ function elideMiddle(s, cap) {
57
+ if (s.length <= cap)
58
+ return s;
59
+ const head = Math.ceil(cap * 0.6);
60
+ const tail = Math.max(0, Math.floor(cap * 0.25));
61
+ const removed = s.length - head - tail;
62
+ return `${s.slice(0, head)}\n…[${removed} chars elided to save context]…\n${s.slice(s.length - tail)}`;
63
+ }
64
+ /**
65
+ * Bound the running tool-result transcript in place. Mutates the `content` of
66
+ * `tool_result` blocks within `convo` (never removes a block) and reports how
67
+ * many characters were shed so the caller can log when compaction fired.
68
+ */
69
+ function compactConversation(convo, opts) {
70
+ // Collect every string-bodied tool_result, in chronological order.
71
+ const results = [];
72
+ for (const msg of convo) {
73
+ if (!Array.isArray(msg.content))
74
+ continue;
75
+ for (const block of msg.content) {
76
+ if (isToolResultBlock(block) && typeof block.content === "string") {
77
+ results.push(block);
78
+ }
79
+ }
80
+ }
81
+ let removed = 0;
82
+ // Pass 1 — hard-cap each result so one pathological payload can't dominate.
83
+ for (const block of results) {
84
+ const content = block.content;
85
+ if (content.length > opts.maxResultChars) {
86
+ const next = elideMiddle(content, opts.maxResultChars);
87
+ removed += content.length - next.length;
88
+ block.content = next;
89
+ }
90
+ }
91
+ const transcriptChars = () => results.reduce((n, b) => n + (typeof b.content === "string" ? b.content.length : 0), 0);
92
+ // Pass 2 — if still over budget, stub the oldest results, preserving newest K.
93
+ const elidable = results.slice(0, Math.max(0, results.length - opts.keepRecentResults));
94
+ for (let i = 0; i < elidable.length && transcriptChars() > opts.maxTranscriptChars; i++) {
95
+ const block = elidable[i];
96
+ const content = block.content;
97
+ const stub = `[earlier tool result elided to save context — was ${content.length} chars]`;
98
+ if (content.length > stub.length) {
99
+ removed += content.length - stub.length;
100
+ block.content = stub;
101
+ }
102
+ }
103
+ return { compacted: removed > 0, removedChars: removed };
104
+ }
11
105
  /**
12
106
  * Drive one chat turn. Yields events as they happen so the caller can
13
107
  * forward straight to SSE; the final event is always `final` (success)
@@ -30,6 +124,19 @@ async function* runChatTurn(req) {
30
124
  ];
31
125
  const maxRounds = req.maxRounds ?? DEFAULT_MAX_ROUNDS;
32
126
  for (let round = 0; round < maxRounds; round++) {
127
+ // Bound the tool-result transcript before each round so a long, tool-heavy
128
+ // turn can't overflow the context window. No-op on round 0 (no results yet).
129
+ const compaction = compactConversation(convo, {
130
+ maxResultChars: DEFAULT_MAX_RESULT_CHARS,
131
+ maxTranscriptChars: DEFAULT_MAX_TRANSCRIPT_CHARS,
132
+ keepRecentResults: DEFAULT_KEEP_RECENT_RESULTS,
133
+ });
134
+ if (compaction.compacted) {
135
+ logger_1.logger.info("chatAgent: compacted tool-result transcript", {
136
+ round,
137
+ removedChars: compaction.removedChars,
138
+ });
139
+ }
33
140
  yield { kind: "status", phase: "thinking" };
34
141
  // Per-round stream. We accumulate text and tool_use blocks; if the
35
142
  // stop_reason is tool_use we execute and loop, else we yield the
@@ -108,16 +215,45 @@ async function* runChatTurn(req) {
108
215
  result = { error: `unknown tool: ${use.name}` };
109
216
  }
110
217
  else {
111
- try {
112
- result = await tool.run(use.input);
218
+ // Validate the model's raw args against the tool's Zod schema (when it
219
+ // has one) BEFORE dispatch. On failure we hand the model a structured
220
+ // error rather than letting bad input reach `run` or hard-failing the
221
+ // turn — it can correct itself on the next round. On success `run`
222
+ // receives the parsed, typed value (unknown keys stripped).
223
+ let input = use.input;
224
+ let valid = true;
225
+ if (tool.schema) {
226
+ const parsed = tool.schema.safeParse(use.input);
227
+ if (parsed.success) {
228
+ input = parsed.data;
229
+ }
230
+ else {
231
+ valid = false;
232
+ result = {
233
+ error: "invalid tool arguments",
234
+ issues: parsed.error.issues.map((i) => ({
235
+ path: i.path.join(".") || "(root)",
236
+ message: i.message,
237
+ })),
238
+ };
239
+ logger_1.logger.warn("chatAgent: tool args failed schema validation", {
240
+ tool: use.name,
241
+ toolUseId: use.id,
242
+ });
243
+ }
113
244
  }
114
- catch (err) {
115
- logger_1.logger.error("chatAgent: tool execution failed", {
116
- tool: use.name,
117
- toolUseId: use.id,
118
- err: err instanceof Error ? err.stack ?? err.message : String(err),
119
- });
120
- result = { error: err.message };
245
+ if (valid) {
246
+ try {
247
+ result = await tool.run(input);
248
+ }
249
+ catch (err) {
250
+ logger_1.logger.error("chatAgent: tool execution failed", {
251
+ tool: use.name,
252
+ toolUseId: use.id,
253
+ err: err instanceof Error ? err.stack ?? err.message : String(err),
254
+ });
255
+ result = { error: err.message };
256
+ }
121
257
  }
122
258
  }
123
259
  yield { kind: "tool_result", id: use.id, result };
@@ -31,7 +31,7 @@ export declare function estimateSceneCredits(scene: {
31
31
  * spent (no refund delta), so we don't have to track per-call actuals.
32
32
  *
33
33
  * Pass `bibleBuilt: false` for cache hits to skip the bible charge. Pass
34
- * `usedWebResearch: false` when the planner ran the gateway path (no
34
+ * `usedWebResearch: false` when the planner ran the non-research path (no
35
35
  * Anthropic web_search). `usedThinking` mirrors T3 premium briefs.
36
36
  */
37
37
  export declare function estimatePlanOverheadCredits(opts: {
@@ -58,4 +58,14 @@ export declare function estimateProjectCost(project: Project): CostBreakdown;
58
58
  * when a scene omits its own estimate.
59
59
  */
60
60
  export declare function estimatePlanCost(plan: VideoPlan): CostBreakdown;
61
+ /**
62
+ * Stream L (L-6) — credit↔USD conversion. The whole codebase prices 1 credit
63
+ * at $0.10 (see TTS / overhead comments above); this is the single source for
64
+ * that rate so the long-form budget guard and any UI USD display agree.
65
+ */
66
+ export declare const CREDIT_USD_RATE = 0.1;
67
+ /** Convert a credit amount to USD at the platform rate. */
68
+ export declare function creditsToUsd(credits: number): number;
69
+ /** Convert a USD amount to credits at the platform rate. */
70
+ export declare function usdToCredits(usd: number): number;
61
71
  //# sourceMappingURL=costPreflight.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"costPreflight.d.ts","sourceRoot":"","sources":["../../../src/services/agent/costPreflight.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,OAAO,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAmD3D;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE;IAC1C,IAAI,EAAE,IAAI,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,GAAG,MAAM,CAOT;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE;IAChD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,GAAG,MAAM,CAQT;AAED,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC7B,OAAO,EAAE,KAAK,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,IAAI,CAAC;QACZ,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,OAAO,CAAC;KACpB,CAAC,CAAC;CACJ;AAKD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,aAAa,CAuBnE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,GAAG,aAAa,CAoB/D"}
1
+ {"version":3,"file":"costPreflight.d.ts","sourceRoot":"","sources":["../../../src/services/agent/costPreflight.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,OAAO,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAmD3D;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE;IAC1C,IAAI,EAAE,IAAI,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,GAAG,MAAM,CAOT;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE;IAChD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,GAAG,MAAM,CAQT;AAED,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC7B,OAAO,EAAE,KAAK,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,IAAI,CAAC;QACZ,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,OAAO,CAAC;KACpB,CAAC,CAAC;CACJ;AAKD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,aAAa,CAuBnE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,GAAG,aAAa,CAoB/D;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,MAAM,CAAC;AAEnC,2DAA2D;AAC3D,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,4DAA4D;AAC5D,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD"}
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CREDIT_USD_RATE = void 0;
3
4
  exports.estimateSceneCredits = estimateSceneCredits;
4
5
  exports.estimatePlanOverheadCredits = estimatePlanOverheadCredits;
5
6
  exports.estimateProjectCost = estimateProjectCost;
6
7
  exports.estimatePlanCost = estimatePlanCost;
8
+ exports.creditsToUsd = creditsToUsd;
9
+ exports.usdToCredits = usdToCredits;
7
10
  /**
8
11
  * Cost preflight — sums credits over a Project JSON's clips by their
9
12
  * provenance.creditsSpent. For clips not yet generated, falls back to a
@@ -81,7 +84,7 @@ function estimateSceneCredits(scene) {
81
84
  * spent (no refund delta), so we don't have to track per-call actuals.
82
85
  *
83
86
  * Pass `bibleBuilt: false` for cache hits to skip the bible charge. Pass
84
- * `usedWebResearch: false` when the planner ran the gateway path (no
87
+ * `usedWebResearch: false` when the planner ran the non-research path (no
85
88
  * Anthropic web_search). `usedThinking` mirrors T3 premium briefs.
86
89
  */
87
90
  function estimatePlanOverheadCredits(opts) {
@@ -141,3 +144,17 @@ function estimatePlanCost(plan) {
141
144
  const totalCredits = perClip.reduce((s, x) => s + x.credits, 0);
142
145
  return { totalCredits, byTier, perClip };
143
146
  }
147
+ /**
148
+ * Stream L (L-6) — credit↔USD conversion. The whole codebase prices 1 credit
149
+ * at $0.10 (see TTS / overhead comments above); this is the single source for
150
+ * that rate so the long-form budget guard and any UI USD display agree.
151
+ */
152
+ exports.CREDIT_USD_RATE = 0.1;
153
+ /** Convert a credit amount to USD at the platform rate. */
154
+ function creditsToUsd(credits) {
155
+ return credits * exports.CREDIT_USD_RATE;
156
+ }
157
+ /** Convert a USD amount to credits at the platform rate. */
158
+ function usdToCredits(usd) {
159
+ return usd / exports.CREDIT_USD_RATE;
160
+ }
@@ -0,0 +1,41 @@
1
+ import { LlmCaller } from "../llmCaller";
2
+ import { TranscriptForPicking } from "../editExisting/highlightPicker";
3
+ import { CoverCandidate, CoverRequest, CoverVisionReport, CoverVisionVerdict } from "./covers.schema";
4
+ export declare function clampCovers(covers: CoverCandidate[], sourceDurationMs: number): CoverCandidate[];
5
+ /**
6
+ * Pass 1 — pick cover moments + copy from a transcript. Retries up to
7
+ * `maxRetries`, feeding the model its previous problems. Throws only if every
8
+ * attempt yields zero usable covers.
9
+ */
10
+ export declare function planCoversCore(llm: LlmCaller, args: {
11
+ request: CoverRequest;
12
+ transcript: TranscriptForPicking;
13
+ maxRetries?: number;
14
+ }): Promise<{
15
+ covers: CoverCandidate[];
16
+ summary?: string;
17
+ }>;
18
+ /**
19
+ * Pass 2 — VISION re-score. Shows the model the extracted candidate frames (in
20
+ * candidate order) and asks how good each looks as a thumbnail still. Returns a
21
+ * verdict per frame index. No retry/repair loop: this pass is best-effort
22
+ * polish on top of the planner's picks, so the worker treats a thrown error as
23
+ * "skip vision, keep planner scores" rather than a job failure.
24
+ */
25
+ export declare function rankCoversCore(llm: LlmCaller, args: {
26
+ request: CoverRequest;
27
+ frames: Array<{
28
+ index: number;
29
+ imageUrl: string;
30
+ headline: string;
31
+ angle: string;
32
+ }>;
33
+ }): Promise<CoverVisionReport>;
34
+ /**
35
+ * Pure score blend used by the worker: combine the planner's click-through
36
+ * prediction with the vision frame-quality score. A frame flagged `isPoor` is
37
+ * penalised hard (it can sink an otherwise-clickable concept). When no vision
38
+ * verdict exists, the planner score stands. Returns 0–100 (rounded).
39
+ */
40
+ export declare function blendCoverScore(plannerScore: number, verdict?: CoverVisionVerdict): number;
41
+ //# sourceMappingURL=coverPlanner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coverPlanner.d.ts","sourceRoot":"","sources":["../../../../src/services/agent/covers/coverPlanner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,SAAS,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,EAEL,oBAAoB,EACrB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAML,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAEnB,MAAM,iBAAiB,CAAC;AAuHzB,wBAAgB,WAAW,CACzB,MAAM,EAAE,cAAc,EAAE,EACxB,gBAAgB,EAAE,MAAM,GACvB,cAAc,EAAE,CAoBlB;AAsCD;;;;GAIG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,SAAS,EACd,IAAI,EAAE;IACJ,OAAO,EAAE,YAAY,CAAC;IACtB,UAAU,EAAE,oBAAoB,CAAC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACA,OAAO,CAAC;IAAE,MAAM,EAAE,cAAc,EAAE,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAyDzD;AAgBD;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,SAAS,EACd,IAAI,EAAE;IACJ,OAAO,EAAE,YAAY,CAAC;IACtB,MAAM,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACrF,GACA,OAAO,CAAC,iBAAiB,CAAC,CA4C5B;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,MAAM,CAKR"}
@@ -0,0 +1,278 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.clampCovers = clampCovers;
4
+ exports.planCoversCore = planCoversCore;
5
+ exports.rankCoversCore = rankCoversCore;
6
+ exports.blendCoverScore = blendCoverScore;
7
+ const zod_1 = require("zod");
8
+ const logger_1 = require("../../../utils/logger");
9
+ const modelRouter_1 = require("../modelRouter");
10
+ const highlightPicker_1 = require("../editExisting/highlightPicker");
11
+ const covers_schema_1 = require("./covers.schema");
12
+ /**
13
+ * X8 Social Suite · Phase 6 · E2 — cover planner. The reasoning core of the
14
+ * AI-covers pipeline. Two pure passes, both driven by an injected LlmCaller so
15
+ * the worker, scripts, and a no-spend eval can all drive them:
16
+ *
17
+ * 1. planCoversCore (TEXT, planner role) — read the ASR transcript and pick N
18
+ * cover MOMENTS spread across distinct A/B angles, each with overlay copy +
19
+ * a predicted click-through score.
20
+ * 2. rankCoversCore (VISION, critic role) — actually LOOK at the extracted
21
+ * frames and re-score them on FRAME quality (sharp / well-framed / a face),
22
+ * flagging blurry or transition-smear stills the transcript couldn't catch.
23
+ *
24
+ * Reuses E3/L-5's transcript shape + `buildTranscriptLines`. The worker blends
25
+ * the two scores; the vision pass is best-effort (a vision outage falls back to
26
+ * planner scores), so the feature still ships covers if pass 2 fails.
27
+ */
28
+ /**
29
+ * The raw planner output. Looser than CoverCandidateSchema (no max) on purpose —
30
+ * we clamp/repair afterwards so a slightly-off model answer is fixed, not rejected.
31
+ */
32
+ const LlmCoversSchema = zod_1.z.object({
33
+ covers: zod_1.z
34
+ .array(zod_1.z.object({
35
+ atMs: zod_1.z.number(),
36
+ headline: zod_1.z.string(),
37
+ subtext: zod_1.z.string().optional(),
38
+ angle: zod_1.z.string(),
39
+ reason: zod_1.z.string(),
40
+ score: zod_1.z.number(),
41
+ }))
42
+ .min(1),
43
+ summary: zod_1.z.string().optional(),
44
+ });
45
+ /** Loose vision output (clamped after). */
46
+ const LlmVisionSchema = zod_1.z.object({
47
+ verdicts: zod_1.z
48
+ .array(zod_1.z.object({
49
+ index: zod_1.z.number(),
50
+ visualScore: zod_1.z.number(),
51
+ isPoor: zod_1.z.boolean().optional(),
52
+ note: zod_1.z.string().optional(),
53
+ }))
54
+ .min(0),
55
+ });
56
+ function fmtTs(ms) {
57
+ const totalSec = Math.floor(ms / 1000);
58
+ const m = Math.floor(totalSec / 60);
59
+ const s = totalSec % 60;
60
+ return `${m}:${String(s).padStart(2, "0")}`;
61
+ }
62
+ function buildPlannerMessages(request, transcript, feedback) {
63
+ const maxCovers = request.maxCovers ?? covers_schema_1.DEFAULT_MAX_COVERS;
64
+ const system = [
65
+ "You are a thumbnail / cover strategist for short-form video (the person",
66
+ "who decides the frame + the few words of overlay text that win the click).",
67
+ "You are given a timestamped transcript of a source video and must choose",
68
+ "the strongest STILL MOMENTS to use as cover images, and write the overlay",
69
+ "copy for each. Use millisecond timestamps taken from the bracketed times.",
70
+ "",
71
+ "Pick distinct moments that would make a compelling freeze-frame: a reveal,",
72
+ "a peak-emotion beat, a result/payoff, a surprising visual. Spread your picks",
73
+ "across DIFFERENT A/B ANGLES so the set is a real test, not variations of one",
74
+ `idea. Prefer these angles where they fit: ${covers_schema_1.COVER_ANGLES.join(", ")}.`,
75
+ "",
76
+ "For each cover write:",
77
+ `- \`atMs\`: the source timestamp to grab the still from (within [0, ${transcript.audioDurationMs}] ms).`,
78
+ `- \`headline\`: the big overlay text — punchy, ≤ ~8 words, ≤ ${covers_schema_1.COVER_HEADLINE_MAX} chars.`,
79
+ `- \`subtext\`: optional smaller supporting line (≤ ${covers_schema_1.COVER_SUBTEXT_MAX} chars). Omit if the headline stands alone.`,
80
+ "- `angle`: which A/B angle this variant tests.",
81
+ "- `reason`: why this frame + copy earns the click.",
82
+ "- `score`: 0–100 predicted click-through; reserve 80+ for genuinely strong picks.",
83
+ "Pick QUALITY over quantity, and never invent moments that aren't in the transcript.",
84
+ ].join("\n");
85
+ const langLine = request.language
86
+ ? `Write the headline and subtext in this language (BCP-47 "${request.language}").`
87
+ : "Write the headline and subtext in the same language the transcript is spoken in.";
88
+ const toneLine = request.tone ? `Tone for the copy: ${request.tone}.` : "";
89
+ const user = [
90
+ `GOAL: produce up to ${maxCovers} cover variants for A/B testing this video.`,
91
+ langLine,
92
+ toneLine,
93
+ request.instructions ? `ADDITIONAL INSTRUCTIONS: ${request.instructions}` : "",
94
+ feedback ? `\nYOUR PREVIOUS ANSWER HAD PROBLEMS — FIX THESE:\n${feedback}` : "",
95
+ "",
96
+ `TRANSCRIPT (total ${fmtTs(transcript.audioDurationMs)}):`,
97
+ (0, highlightPicker_1.buildTranscriptLines)(transcript),
98
+ ]
99
+ .filter(Boolean)
100
+ .join("\n");
101
+ return [
102
+ { role: "system", content: system },
103
+ { role: "user", content: user },
104
+ ];
105
+ }
106
+ /**
107
+ * Clamp covers into the source bounds, clamp copy lengths + score, de-duplicate
108
+ * near-identical timestamps (within DEDUPE_WINDOW_MS — two covers from the same
109
+ * frame add no A/B value), and sort by score desc. Pure + idempotent.
110
+ */
111
+ const DEDUPE_WINDOW_MS = 1000;
112
+ function clampCovers(covers, sourceDurationMs) {
113
+ const bounded = covers
114
+ .map((c) => ({
115
+ atMs: Math.max(0, Math.min(c.atMs, Math.max(0, sourceDurationMs - 1))),
116
+ headline: (c.headline ?? "").slice(0, covers_schema_1.COVER_HEADLINE_MAX),
117
+ angle: (c.angle ?? "").slice(0, covers_schema_1.COVER_ANGLE_MAX) || "curiosity",
118
+ reason: (c.reason ?? "").slice(0, covers_schema_1.COVER_REASON_MAX),
119
+ score: Math.max(0, Math.min(100, Number.isFinite(c.score) ? c.score : 0)),
120
+ ...(c.subtext ? { subtext: c.subtext.slice(0, covers_schema_1.COVER_SUBTEXT_MAX) } : {}),
121
+ }))
122
+ .filter((c) => c.headline.trim().length > 0)
123
+ .sort((a, b) => b.score - a.score);
124
+ // Drop later picks that land on essentially the same frame as a kept one.
125
+ const out = [];
126
+ for (const c of bounded) {
127
+ if (out.some((k) => Math.abs(k.atMs - c.atMs) < DEDUPE_WINDOW_MS))
128
+ continue;
129
+ out.push(c);
130
+ }
131
+ return out;
132
+ }
133
+ function validatePlan(raw, request, audioDurationMs) {
134
+ const problems = [];
135
+ const maxCovers = request.maxCovers ?? covers_schema_1.DEFAULT_MAX_COVERS;
136
+ const mapped = raw.covers.map((c) => ({
137
+ atMs: c.atMs,
138
+ headline: c.headline ?? "",
139
+ angle: c.angle ?? "curiosity",
140
+ reason: c.reason ?? "",
141
+ score: c.score ?? 0,
142
+ ...(c.subtext ? { subtext: c.subtext } : {}),
143
+ }));
144
+ const outOfBounds = mapped.filter((c) => c.atMs < 0 || c.atMs > audioDurationMs + 250);
145
+ if (outOfBounds.length > 0) {
146
+ problems.push(`${outOfBounds.length} cover(s) had a timestamp outside the video (${audioDurationMs}ms). Keep every atMs inside [0, ${audioDurationMs}].`);
147
+ }
148
+ const empties = mapped.filter((c) => !c.headline.trim());
149
+ if (empties.length > 0) {
150
+ problems.push(`${empties.length} cover(s) had an empty headline. Every cover needs overlay text.`);
151
+ }
152
+ let cleaned = clampCovers(mapped, audioDurationMs);
153
+ if (cleaned.length > maxCovers)
154
+ cleaned = cleaned.slice(0, maxCovers);
155
+ return { covers: cleaned, problems };
156
+ }
157
+ /**
158
+ * Pass 1 — pick cover moments + copy from a transcript. Retries up to
159
+ * `maxRetries`, feeding the model its previous problems. Throws only if every
160
+ * attempt yields zero usable covers.
161
+ */
162
+ async function planCoversCore(llm, args) {
163
+ const router = new modelRouter_1.ModelRouter();
164
+ const maxRetries = args.maxRetries ?? 2;
165
+ const { request, transcript } = args;
166
+ let feedback;
167
+ let lastProblems = [];
168
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
169
+ const res = await llm.structured({
170
+ model: router.pickFor("planner"),
171
+ fallbackModel: router.fallbackFor("planner"),
172
+ schema: LlmCoversSchema,
173
+ schemaName: "CoverPlan",
174
+ messages: buildPlannerMessages(request, transcript, feedback),
175
+ temperature: 0.5,
176
+ maxTokens: 6000,
177
+ });
178
+ const { covers, problems } = validatePlan(res.data, request, transcript.audioDurationMs);
179
+ lastProblems = problems;
180
+ if (covers.length > 0 && problems.length === 0) {
181
+ logger_1.logger.info("covers.planner: plan accepted", {
182
+ attempt,
183
+ covers: covers.length,
184
+ audioDurationMs: transcript.audioDurationMs,
185
+ });
186
+ return { covers, ...(res.data.summary ? { summary: res.data.summary } : {}) };
187
+ }
188
+ // Usable-but-imperfect on the final attempt: accept rather than throw.
189
+ if (covers.length > 0 && attempt === maxRetries) {
190
+ logger_1.logger.warn("covers.planner: accepting imperfect plan on last attempt", {
191
+ covers: covers.length,
192
+ problems,
193
+ });
194
+ return { covers, ...(res.data.summary ? { summary: res.data.summary } : {}) };
195
+ }
196
+ feedback =
197
+ problems.join("\n") ||
198
+ "Your previous answer returned no usable covers. Pick at least one strong still moment with overlay copy and a valid timestamp.";
199
+ logger_1.logger.warn("covers.planner: retrying", {
200
+ attempt,
201
+ problems,
202
+ durationMs: transcript.audioDurationMs,
203
+ });
204
+ }
205
+ throw new Error(`covers.planner: no usable covers after ${maxRetries + 1} attempts (${lastProblems.join("; ")})`);
206
+ }
207
+ function clampVerdicts(raw, frameCount) {
208
+ return raw.verdicts
209
+ .filter((v) => Number.isInteger(v.index) && v.index >= 0 && v.index < frameCount)
210
+ .map((v) => ({
211
+ index: v.index,
212
+ visualScore: Math.max(0, Math.min(100, Number.isFinite(v.visualScore) ? v.visualScore : 0)),
213
+ isPoor: Boolean(v.isPoor),
214
+ ...(v.note ? { note: v.note.slice(0, 200) } : {}),
215
+ }));
216
+ }
217
+ /**
218
+ * Pass 2 — VISION re-score. Shows the model the extracted candidate frames (in
219
+ * candidate order) and asks how good each looks as a thumbnail still. Returns a
220
+ * verdict per frame index. No retry/repair loop: this pass is best-effort
221
+ * polish on top of the planner's picks, so the worker treats a thrown error as
222
+ * "skip vision, keep planner scores" rather than a job failure.
223
+ */
224
+ async function rankCoversCore(llm, args) {
225
+ const router = new modelRouter_1.ModelRouter();
226
+ const { frames } = args;
227
+ if (frames.length === 0)
228
+ return { verdicts: [] };
229
+ const system = [
230
+ "You are a thumbnail-quality judge. You are shown candidate still frames",
231
+ "grabbed from a video to use as social covers, in order. For EACH frame,",
232
+ "judge ONLY how good it looks as a still thumbnail — not the wording:",
233
+ "- High score: sharp, well-composed, a clear subject or expressive face,",
234
+ " good contrast, leaves room for overlay text.",
235
+ "- Low score / isPoor=true: blurry, motion-smear, mid-blink, a transition",
236
+ " frame, near-blank, or too busy to read.",
237
+ "Return one verdict per frame, referencing it by its 0-based `index` in the",
238
+ "order shown. Be decisive; reserve 80+ for genuinely strong stills.",
239
+ ].join("\n");
240
+ const ordered = [...frames].sort((a, b) => a.index - b.index);
241
+ const manifest = ordered
242
+ .map((f, i) => `Frame ${i}: angle="${f.angle}", overlay="${f.headline}"`)
243
+ .join("\n");
244
+ const res = await llm.structured({
245
+ model: router.pickFor("critic"),
246
+ fallbackModel: router.fallbackFor("critic"),
247
+ schema: LlmVisionSchema,
248
+ schemaName: "CoverVisionReport",
249
+ temperature: 0.2,
250
+ maxTokens: 2000,
251
+ messages: [
252
+ { role: "system", content: system },
253
+ {
254
+ role: "user",
255
+ content: [
256
+ `Judge these ${ordered.length} candidate cover frames as stills.`,
257
+ "They are attached in this order:",
258
+ manifest,
259
+ ].join("\n"),
260
+ imageUrls: ordered.map((f) => f.imageUrl),
261
+ },
262
+ ],
263
+ });
264
+ return { verdicts: clampVerdicts(res.data, ordered.length) };
265
+ }
266
+ /**
267
+ * Pure score blend used by the worker: combine the planner's click-through
268
+ * prediction with the vision frame-quality score. A frame flagged `isPoor` is
269
+ * penalised hard (it can sink an otherwise-clickable concept). When no vision
270
+ * verdict exists, the planner score stands. Returns 0–100 (rounded).
271
+ */
272
+ function blendCoverScore(plannerScore, verdict) {
273
+ if (!verdict)
274
+ return Math.round(plannerScore);
275
+ const base = 0.5 * plannerScore + 0.5 * verdict.visualScore;
276
+ const penalised = verdict.isPoor ? base * 0.4 : base;
277
+ return Math.round(Math.max(0, Math.min(100, penalised)));
278
+ }