@nodaro/shared 3.65.0 → 3.67.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 (144) hide show
  1. package/dist/{chunk-GJ3D5X4X.cjs → chunk-23IKLMRL.cjs} +41 -41
  2. package/dist/{chunk-GJ3D5X4X.cjs.map → chunk-23IKLMRL.cjs.map} +1 -1
  3. package/dist/{chunk-E66HSC2E.cjs → chunk-37ZSFS6A.cjs} +9 -9
  4. package/dist/{chunk-E66HSC2E.cjs.map → chunk-37ZSFS6A.cjs.map} +1 -1
  5. package/dist/{chunk-K6RIN3LW.cjs → chunk-3L7GMQ4M.cjs} +47 -47
  6. package/dist/chunk-3L7GMQ4M.cjs.map +1 -0
  7. package/dist/{chunk-YMZUE2IX.js → chunk-3QJ3UR5Z.js} +9 -9
  8. package/dist/{chunk-YMZUE2IX.js.map → chunk-3QJ3UR5Z.js.map} +1 -1
  9. package/dist/{chunk-Q4YOLT4M.js → chunk-3YWZ5SOZ.js} +5 -5
  10. package/dist/{chunk-Q4YOLT4M.js.map → chunk-3YWZ5SOZ.js.map} +1 -1
  11. package/dist/{chunk-2NKF476Z.js → chunk-5GG4CG4Y.js} +3 -3
  12. package/dist/{chunk-2NKF476Z.js.map → chunk-5GG4CG4Y.js.map} +1 -1
  13. package/dist/{chunk-ZSRXY5YT.js → chunk-5IZHECUP.js} +3 -3
  14. package/dist/{chunk-ZSRXY5YT.js.map → chunk-5IZHECUP.js.map} +1 -1
  15. package/dist/{chunk-D5Y3EYRM.js → chunk-5J2LIQYU.js} +5 -5
  16. package/dist/{chunk-D5Y3EYRM.js.map → chunk-5J2LIQYU.js.map} +1 -1
  17. package/dist/{chunk-BSTAAGLY.js → chunk-5LWYX4GV.js} +3 -3
  18. package/dist/{chunk-BSTAAGLY.js.map → chunk-5LWYX4GV.js.map} +1 -1
  19. package/dist/{chunk-JYU5EIRM.cjs → chunk-66QSUUB4.cjs} +12 -12
  20. package/dist/{chunk-JYU5EIRM.cjs.map → chunk-66QSUUB4.cjs.map} +1 -1
  21. package/dist/{chunk-7BN4EDIC.cjs → chunk-BMDOPJBP.cjs} +17 -17
  22. package/dist/{chunk-7BN4EDIC.cjs.map → chunk-BMDOPJBP.cjs.map} +1 -1
  23. package/dist/{chunk-222QM7CO.js → chunk-BNR5FKL5.js} +3 -3
  24. package/dist/{chunk-222QM7CO.js.map → chunk-BNR5FKL5.js.map} +1 -1
  25. package/dist/{chunk-FGBGKBML.js → chunk-CFTXW3ZL.js} +70 -3
  26. package/dist/chunk-CFTXW3ZL.js.map +1 -0
  27. package/dist/{chunk-FI3HJZWM.cjs → chunk-E62W5I6A.cjs} +6 -2
  28. package/dist/chunk-E62W5I6A.cjs.map +1 -0
  29. package/dist/{chunk-MIT2USTS.cjs → chunk-EFYWV2V5.cjs} +61 -61
  30. package/dist/{chunk-MIT2USTS.cjs.map → chunk-EFYWV2V5.cjs.map} +1 -1
  31. package/dist/{chunk-RP4KQUNU.cjs → chunk-F6XIH3TZ.cjs} +9 -9
  32. package/dist/{chunk-RP4KQUNU.cjs.map → chunk-F6XIH3TZ.cjs.map} +1 -1
  33. package/dist/{chunk-KTCEKGBJ.cjs → chunk-G2G7XGFU.cjs} +7 -7
  34. package/dist/{chunk-KTCEKGBJ.cjs.map → chunk-G2G7XGFU.cjs.map} +1 -1
  35. package/dist/{chunk-HAH2F7LT.js → chunk-GF7ZA26H.js} +4 -4
  36. package/dist/{chunk-HAH2F7LT.js.map → chunk-GF7ZA26H.js.map} +1 -1
  37. package/dist/{chunk-FJZTQTF4.cjs → chunk-GNLA5NTT.cjs} +4 -4
  38. package/dist/{chunk-FJZTQTF4.cjs.map → chunk-GNLA5NTT.cjs.map} +1 -1
  39. package/dist/{chunk-ST7OBB5J.js → chunk-GTBW2KAY.js} +4 -4
  40. package/dist/{chunk-ST7OBB5J.js.map → chunk-GTBW2KAY.js.map} +1 -1
  41. package/dist/{chunk-R5ILCNCC.cjs → chunk-HTDKEYMY.cjs} +75 -75
  42. package/dist/{chunk-R5ILCNCC.cjs.map → chunk-HTDKEYMY.cjs.map} +1 -1
  43. package/dist/{chunk-DQ2PARNH.cjs → chunk-IWUW3YPM.cjs} +5 -5
  44. package/dist/{chunk-DQ2PARNH.cjs.map → chunk-IWUW3YPM.cjs.map} +1 -1
  45. package/dist/{chunk-6OSIOVF7.cjs → chunk-JTYCJ5OL.cjs} +16 -16
  46. package/dist/{chunk-6OSIOVF7.cjs.map → chunk-JTYCJ5OL.cjs.map} +1 -1
  47. package/dist/{chunk-JQMFJAYU.cjs → chunk-M5QY464F.cjs} +21 -21
  48. package/dist/{chunk-JQMFJAYU.cjs.map → chunk-M5QY464F.cjs.map} +1 -1
  49. package/dist/{chunk-CW6MMQNO.js → chunk-MVXZP6VB.js} +6 -2
  50. package/dist/chunk-MVXZP6VB.js.map +1 -0
  51. package/dist/{chunk-H745DQ6V.js → chunk-OFQ6CU6S.js} +3 -3
  52. package/dist/{chunk-H745DQ6V.js.map → chunk-OFQ6CU6S.js.map} +1 -1
  53. package/dist/{chunk-XJANKTIL.js → chunk-OXBU5AGH.js} +3 -3
  54. package/dist/{chunk-XJANKTIL.js.map → chunk-OXBU5AGH.js.map} +1 -1
  55. package/dist/{chunk-SPU7MUWE.cjs → chunk-OXTF4Y3P.cjs} +6 -6
  56. package/dist/{chunk-SPU7MUWE.cjs.map → chunk-OXTF4Y3P.cjs.map} +1 -1
  57. package/dist/{chunk-5SSMPYE5.js → chunk-PAUWEWTY.js} +5 -5
  58. package/dist/chunk-PAUWEWTY.js.map +1 -0
  59. package/dist/{chunk-KWYS4IIM.cjs → chunk-PJAJCFLP.cjs} +49 -38
  60. package/dist/chunk-PJAJCFLP.cjs.map +1 -0
  61. package/dist/{chunk-7OWXHW7Z.js → chunk-RVQW623D.js} +6 -6
  62. package/dist/{chunk-7OWXHW7Z.js.map → chunk-RVQW623D.js.map} +1 -1
  63. package/dist/{chunk-V5NLQ4L5.js → chunk-SCDE676D.js} +5 -5
  64. package/dist/{chunk-V5NLQ4L5.js.map → chunk-SCDE676D.js.map} +1 -1
  65. package/dist/{chunk-3AU52TSW.js → chunk-SW5ZD7BO.js} +3 -3
  66. package/dist/{chunk-3AU52TSW.js.map → chunk-SW5ZD7BO.js.map} +1 -1
  67. package/dist/{chunk-WQMPIURW.cjs → chunk-T4GIHHXY.cjs} +6 -6
  68. package/dist/{chunk-WQMPIURW.cjs.map → chunk-T4GIHHXY.cjs.map} +1 -1
  69. package/dist/{chunk-PL7AQQV7.js → chunk-VBP4DH37.js} +18 -10
  70. package/dist/chunk-VBP4DH37.js.map +1 -0
  71. package/dist/{chunk-YD4XY74W.cjs → chunk-X2YHKP4D.cjs} +8 -8
  72. package/dist/{chunk-YD4XY74W.cjs.map → chunk-X2YHKP4D.cjs.map} +1 -1
  73. package/dist/{chunk-6X5PBAC4.js → chunk-XEPKONJC.js} +3 -3
  74. package/dist/{chunk-6X5PBAC4.js.map → chunk-XEPKONJC.js.map} +1 -1
  75. package/dist/{chunk-NYZQOIXJ.cjs → chunk-ZQ2BHOFH.cjs} +89 -2
  76. package/dist/chunk-ZQ2BHOFH.cjs.map +1 -0
  77. package/dist/entries/apps.cjs +42 -42
  78. package/dist/entries/apps.js +7 -7
  79. package/dist/entries/credits.cjs +217 -217
  80. package/dist/entries/credits.d.cts +2 -2
  81. package/dist/entries/credits.d.ts +2 -2
  82. package/dist/entries/credits.js +9 -9
  83. package/dist/entries/llm-models.d.cts +2 -2
  84. package/dist/entries/llm-models.d.ts +2 -2
  85. package/dist/entries/media.cjs +147 -67
  86. package/dist/entries/media.d.cts +102 -1
  87. package/dist/entries/media.d.ts +102 -1
  88. package/dist/entries/media.js +1 -1
  89. package/dist/entries/model-catalog.cjs +133 -133
  90. package/dist/entries/model-catalog.d.cts +3 -3
  91. package/dist/entries/model-catalog.d.ts +3 -3
  92. package/dist/entries/model-catalog.js +4 -4
  93. package/dist/entries/models.cjs +403 -391
  94. package/dist/entries/models.d.cts +5 -5
  95. package/dist/entries/models.d.ts +5 -5
  96. package/dist/entries/models.js +5 -5
  97. package/dist/entries/nodes.cjs +212 -212
  98. package/dist/entries/nodes.d.cts +1 -1
  99. package/dist/entries/nodes.d.ts +1 -1
  100. package/dist/entries/nodes.js +8 -8
  101. package/dist/entries/pipeline.cjs +153 -153
  102. package/dist/entries/pipeline.d.cts +2 -2
  103. package/dist/entries/pipeline.d.ts +2 -2
  104. package/dist/entries/pipeline.js +3 -3
  105. package/dist/entries/ugc.cjs +71 -71
  106. package/dist/entries/ugc.js +4 -4
  107. package/dist/entries/video.cjs +152 -152
  108. package/dist/entries/video.d.cts +15 -10
  109. package/dist/entries/video.d.ts +15 -10
  110. package/dist/entries/video.js +6 -6
  111. package/dist/entries/workflow.d.cts +1 -1
  112. package/dist/entries/workflow.d.ts +1 -1
  113. package/dist/index.cjs +1502 -1410
  114. package/dist/index.d.cts +4 -4
  115. package/dist/index.d.ts +4 -4
  116. package/dist/index.js +19 -19
  117. package/dist/{model-catalog-BoUKGFNl.d.ts → model-catalog-B-aQnUS8.d.cts} +19 -1
  118. package/dist/{model-catalog-BoUKGFNl.d.cts → model-catalog-B-aQnUS8.d.ts} +19 -1
  119. package/dist/{model-constants-CpQz1bGa.d.cts → model-constants-BstsUup6.d.cts} +52 -2
  120. package/dist/{model-constants-BElS3AeE.d.ts → model-constants-DZ3tPGFO.d.ts} +52 -2
  121. package/dist/{tts-capabilities-BtnDWK9K.d.ts → tts-capabilities-BJ4N8MIB.d.ts} +1 -1
  122. package/dist/{tts-capabilities-C52UccTI.d.cts → tts-capabilities-Cf_4nu1Z.d.cts} +1 -1
  123. package/package.json +1 -1
  124. package/src/__tests__/flux-3-klein.test.ts +51 -3
  125. package/src/__tests__/freecut-ai-panel.test.ts +149 -0
  126. package/src/__tests__/image-run-limit.test.ts +96 -0
  127. package/src/__tests__/kling4-catalog.test.ts +1 -1
  128. package/src/__tests__/seedream-5-5.test.ts +17 -0
  129. package/src/__tests__/video-subjects.test.ts +33 -16
  130. package/src/entries/media.ts +1 -0
  131. package/src/entries/models.ts +4 -0
  132. package/src/freecut-ai-panel.ts +172 -0
  133. package/src/freecut-protocol.ts +13 -0
  134. package/src/model-catalog.ts +24 -2
  135. package/src/model-constants.ts +72 -6
  136. package/src/video-character-refs.ts +15 -10
  137. package/dist/chunk-5SSMPYE5.js.map +0 -1
  138. package/dist/chunk-CW6MMQNO.js.map +0 -1
  139. package/dist/chunk-FGBGKBML.js.map +0 -1
  140. package/dist/chunk-FI3HJZWM.cjs.map +0 -1
  141. package/dist/chunk-K6RIN3LW.cjs.map +0 -1
  142. package/dist/chunk-KWYS4IIM.cjs.map +0 -1
  143. package/dist/chunk-NYZQOIXJ.cjs.map +0 -1
  144. package/dist/chunk-PL7AQQV7.js.map +0 -1
@@ -19,10 +19,11 @@ import type { ConnectedReference } from "../types.js"
19
19
 
20
20
  /**
21
21
  * Video subjects on Kling 4.0 / Kling 4.0 Flash (decided 2026-11-13): a
22
- * character made from a short clip of itself. KIE takes at most 3 of them,
23
- * counts them with the reference videos (5 in all) and bills their seconds as
24
- * reference-video seconds — so the clip is SEATED among the reference videos,
25
- * and every reference-video seam measures and prices it.
22
+ * character made from a short clip of itself. KIE takes at most 3 of them and
23
+ * counts them with the reference videos (5 in all, one total length) — so the
24
+ * clip is SEATED among the reference videos, and every reference-video seam
25
+ * measures and caps it. Neither model bills it as a reference video (decided
26
+ * 2026-11-14), so the price leaves it out (`pricedReferenceVideoUrls`).
26
27
  */
27
28
  const clip = (n: number) => `https://cdn.example/clip-${n}.mp4`
28
29
  const ref = (n: number) => `https://cdn.example/ref-${n}.mp4`
@@ -47,27 +48,43 @@ describe("which models take video subjects (data)", () => {
47
48
  })
48
49
  })
49
50
 
50
- // Decided 2026-11-14, from a measured run: Kling 4.0 Flash bills a video subject
51
- // like an image subject; Kling 4.0 keeps pricing it as a reference video.
51
+ // Decided 2026-11-14, from measured runs: Kling 4.0 and Kling 4.0 Flash both
52
+ // bill a video subject like an image subject. The flag stays, unset, for a
53
+ // model whose provider bills the clip as reference video.
52
54
  describe("how a video subject is priced, per model (data)", () => {
53
- it("Kling 4.0 bills it as reference video; Kling 4.0 Flash does not", () => {
54
- expect(videoCharacterClipsBilledAsReferenceVideo("kling-4")).toBe(true)
55
+ it("no model bills it as reference video today: Kling 4.0 and Kling 4.0 Flash price it like an image subject", () => {
56
+ expect(videoCharacterClipsBilledAsReferenceVideo("kling-4")).toBe(false)
55
57
  expect(videoCharacterClipsBilledAsReferenceVideo("kling-4-flash")).toBe(false)
56
58
  expect(videoCharacterClipsBilledAsReferenceVideo(undefined)).toBe(false)
59
+ for (const [id, limits] of Object.entries(VIDEO_REF_LIMITS_BY_PROVIDER)) {
60
+ expect(limits?.videoCharactersBillAsReferenceVideo, id).toBeUndefined()
61
+ }
57
62
  })
58
63
 
59
- it("pricedReferenceVideoUrls: a character's clip leaves the priced list on Flash only; plain reference videos stay", () => {
64
+ it("pricedReferenceVideoUrls: a character's clip leaves the priced list on both Kling 4.0 ids; plain reference videos stay", () => {
60
65
  const seated = [ref(1), clip(1)]
61
66
  const characters = [character(clip(1)), character()]
62
- expect(pricedReferenceVideoUrls({ provider: "kling-4-flash", referenceVideoUrls: seated, characterReferences: characters })).toEqual([ref(1)])
63
- expect(pricedReferenceVideoUrls({ provider: "kling-4-flash", referenceVideoUrls: [clip(1)], characterReferences: characters })).toEqual([])
64
- const asSent = pricedReferenceVideoUrls({ provider: "kling-4", referenceVideoUrls: seated, characterReferences: characters })
65
- expect(asSent).toBe(seated)
66
- // Nothing to leave out: the same value.
67
- const plain = [ref(1)]
68
- expect(pricedReferenceVideoUrls({ provider: "kling-4-flash", referenceVideoUrls: plain, characterReferences: characters })).toBe(plain)
67
+ for (const provider of ["kling-4", "kling-4-flash"]) {
68
+ expect(pricedReferenceVideoUrls({ provider, referenceVideoUrls: seated, characterReferences: characters }), provider).toEqual([ref(1)])
69
+ expect(pricedReferenceVideoUrls({ provider, referenceVideoUrls: [clip(1)], characterReferences: characters }), provider).toEqual([])
70
+ // Nothing to leave out: the same value.
71
+ const plain = [ref(1)]
72
+ expect(pricedReferenceVideoUrls({ provider, referenceVideoUrls: plain, characterReferences: characters }), provider).toBe(plain)
73
+ }
69
74
  expect(pricedReferenceVideoUrls({ provider: "kling-4-flash", referenceVideoUrls: undefined, characterReferences: undefined })).toBeUndefined()
70
75
  })
76
+
77
+ it("a model that declares the flag keeps the clip in the priced list, as sent", () => {
78
+ const row = VIDEO_REF_LIMITS_BY_PROVIDER["kling-4"]!
79
+ VIDEO_REF_LIMITS_BY_PROVIDER["kling-4"] = { ...row, videoCharactersBillAsReferenceVideo: true }
80
+ try {
81
+ expect(videoCharacterClipsBilledAsReferenceVideo("kling-4")).toBe(true)
82
+ const seated = [ref(1), clip(1)]
83
+ expect(pricedReferenceVideoUrls({ provider: "kling-4", referenceVideoUrls: seated, characterReferences: [character(clip(1))] })).toBe(seated)
84
+ } finally {
85
+ VIDEO_REF_LIMITS_BY_PROVIDER["kling-4"] = row
86
+ }
87
+ })
71
88
  })
72
89
 
73
90
  describe("seatCharacterVideos — a character's clip rides as one more reference video", () => {
@@ -6,6 +6,7 @@
6
6
  * `@nodaro/shared`.
7
7
  */
8
8
  export * from "../freecut-protocol.js"
9
+ export * from "../freecut-ai-panel.js"
9
10
  export { describeMaskRegion } from "../inpaint-region.js"
10
11
  export type { MaskRegionDescriptor, PixelBox } from "../inpaint-region.js"
11
12
  export * from "../priced-clip-seconds.js"
@@ -52,6 +52,9 @@ export {
52
52
  DEFAULT_REQUEST_IMAGE_LIMIT,
53
53
  MAX_REQUEST_IMAGE_LIMIT,
54
54
  requestImageLimit,
55
+ hasOwnRequestImageLimit,
56
+ refusesImagesOverLimit,
57
+ refusesImagesOverLimitOn,
55
58
  VARIABLE_PRICING_MODELS,
56
59
  HIGH_QUALITY_PROVIDERS,
57
60
  TWO_K_RESOLUTION_PROVIDERS,
@@ -276,6 +279,7 @@ export {
276
279
  PRICING_DEFAULT_RESOLUTION,
277
280
  } from "../model-constants.js"
278
281
  export type { VideoStartFrameOnlyProblem } from "../model-constants.js"
282
+ export type { ImageRunKind } from "../model-constants.js"
279
283
  export {
280
284
  CAST_SWAP_POST_PROMPT_MAX,
281
285
  TREND_PROMPT_LIMITS,
@@ -0,0 +1,172 @@
1
+ // Edit with AI in a frame: the platform serves its panel at AI_PANEL_PATH, and a
2
+ // product that embeds the editor (FreeCut) frames it beside the editor. The
3
+ // editor takes commands only from the page that frames it, so that page carries
4
+ // the panel's edit requests to the editor and the editor's answers back
5
+ // (`routeAiPanelMessage`). The panel's own words to its host are below; it signs
6
+ // in through the platform's embed session handoff (`nodaro:embedReady`).
7
+ import {
8
+ FREECUT_OPS_RESULT,
9
+ FREECUT_TIMELINE,
10
+ FREECUT_UNDO_RESULT,
11
+ NODARO_APPLY_OPS,
12
+ NODARO_GET_TIMELINE,
13
+ NODARO_IMPORT_FILES,
14
+ NODARO_PLAYBACK,
15
+ NODARO_PRESENCE,
16
+ NODARO_UNDO_EDIT,
17
+ type FreecutImportFile,
18
+ } from "./freecut-protocol.js"
19
+
20
+ /** Where the platform serves the panel, under its app origin. */
21
+ export const AI_PANEL_PATH = "/embed/edit-with-ai"
22
+ export const AI_PANEL_PROTOCOL_VERSION = 1
23
+
24
+ // The panel (frame) -> its host
25
+ /** The panel is loaded and listening; repeated until the host answers with INIT. */
26
+ export const NODARO_AI_PANEL_READY = "NODARO_AI_PANEL_READY"
27
+ /** The person closed the panel. */
28
+ export const NODARO_AI_PANEL_CLOSE = "NODARO_AI_PANEL_CLOSE"
29
+ /** The panel asks for the whole editor area (`wide: true`, to show the original video) or its side column. */
30
+ export const NODARO_AI_PANEL_LAYOUT = "NODARO_AI_PANEL_LAYOUT"
31
+
32
+ // The host -> the panel
33
+ /** What the panel works on; sent again whenever it changes (a video imported, the editor ready). */
34
+ export const NODARO_AI_PANEL_INIT = "NODARO_AI_PANEL_INIT"
35
+
36
+ /** What the editor must say it can do (its FREECUT_READY `capabilities`) for the panel to be offered. */
37
+ export const AI_PANEL_EDITOR_CAPABILITIES = ["edit-ops", "timeline-read", "playback", "presence"] as const
38
+
39
+ /** The editor's requests a host carries from the panel to the editor. */
40
+ export const AI_PANEL_EDITOR_REQUESTS: readonly string[] = [
41
+ NODARO_GET_TIMELINE,
42
+ NODARO_APPLY_OPS,
43
+ NODARO_UNDO_EDIT,
44
+ NODARO_IMPORT_FILES,
45
+ NODARO_PLAYBACK,
46
+ NODARO_PRESENCE,
47
+ ]
48
+
49
+ /** The editor's answers a host carries back to the panel: only to a request the panel made. */
50
+ export const AI_PANEL_EDITOR_ANSWERS: readonly string[] = [FREECUT_TIMELINE, FREECUT_OPS_RESULT, FREECUT_UNDO_RESULT]
51
+
52
+ /** A video the host can give an address for, by the file name the editor shows for it. */
53
+ export interface AiPanelVideo {
54
+ readonly url: string
55
+ readonly name: string
56
+ }
57
+
58
+ export interface AiPanelInitPayload {
59
+ readonly version: number
60
+ /** The editor's FREECUT_READY `capabilities`; empty until the editor is ready. */
61
+ readonly capabilities: readonly string[]
62
+ /** The videos the host knows an address for. The panel never edits one it cannot listen to. */
63
+ readonly videos: readonly AiPanelVideo[]
64
+ /** The video the editor was opened on, when there is one (its `url`). */
65
+ readonly openedVideoUrl?: string
66
+ /**
67
+ * Which project the editor holds. The host changes it when it starts a fresh
68
+ * one, and the panel then forgets what it did in the old one.
69
+ */
70
+ readonly project?: number
71
+ }
72
+
73
+ export interface AiPanelLayoutPayload {
74
+ readonly wide: boolean
75
+ }
76
+
77
+ /** Whether an editor with these capabilities can be edited by the panel. */
78
+ export function aiPanelOffered(capabilities: readonly string[]): boolean {
79
+ return AI_PANEL_EDITOR_CAPABILITIES.every((c) => capabilities.includes(c))
80
+ }
81
+
82
+ /** The parts of a `MessageEvent` the route reads. */
83
+ export interface AiPanelRelayEvent {
84
+ readonly data: unknown
85
+ readonly origin: string
86
+ readonly source: unknown
87
+ }
88
+
89
+ export interface AiPanelRelayContext {
90
+ readonly panel: unknown
91
+ readonly panelOrigin: string
92
+ readonly editor: unknown
93
+ readonly editorOrigin: string
94
+ /** The request ids the panel asked and the editor has not answered yet. Updated in place by `routeAiPanelMessage`. */
95
+ readonly asked: Set<string>
96
+ }
97
+
98
+ /** Where a message goes, and the buffers to hand over with it. */
99
+ export interface AiPanelRoute {
100
+ readonly to: "editor" | "panel"
101
+ readonly message: { readonly type: string; readonly payload: Record<string, unknown> }
102
+ readonly transfer: ArrayBuffer[]
103
+ }
104
+
105
+ const isRecord = (value: unknown): value is Record<string, unknown> =>
106
+ typeof value === "object" && value !== null && !Array.isArray(value)
107
+
108
+ /**
109
+ * Where a host passes one message, or null when it is not the panel's to pass.
110
+ * From the panel's own frame on its origin: one of the editor's requests, to the
111
+ * editor (an import hands its buffers over again). From the editor's frame on
112
+ * its origin: an answer to a request the panel made, back to the panel, once.
113
+ * Everything else (the host's own traffic, other frames) is left alone.
114
+ */
115
+ export function routeAiPanelMessage(event: AiPanelRelayEvent, ctx: AiPanelRelayContext): AiPanelRoute | null {
116
+ const data = event.data
117
+ if (!isRecord(data) || typeof data.type !== "string") return null
118
+ const payload = isRecord(data.payload) ? data.payload : {}
119
+ if (event.source === ctx.panel && ctx.panel != null && event.origin === ctx.panelOrigin) {
120
+ if (!AI_PANEL_EDITOR_REQUESTS.includes(data.type)) return null
121
+ if (typeof payload.requestId === "string") ctx.asked.add(payload.requestId)
122
+ const files = data.type === NODARO_IMPORT_FILES && Array.isArray(payload.files) ? (payload.files as Partial<FreecutImportFile>[]) : []
123
+ const transfer = files.map((f) => f.buffer).filter((b): b is ArrayBuffer => b instanceof ArrayBuffer)
124
+ return { to: "editor", message: { type: data.type, payload }, transfer }
125
+ }
126
+ if (event.source === ctx.editor && ctx.editor != null && event.origin === ctx.editorOrigin) {
127
+ if (!AI_PANEL_EDITOR_ANSWERS.includes(data.type)) return null
128
+ const requestId = payload.requestId
129
+ if (typeof requestId !== "string" || !ctx.asked.delete(requestId)) return null
130
+ return { to: "panel", message: { type: data.type, payload }, transfer: [] }
131
+ }
132
+ return null
133
+ }
134
+
135
+ /** A window a relay can listen on and post to (the host's own `window`). */
136
+ interface RelayWindow {
137
+ addEventListener(type: "message", listener: (event: MessageEvent) => void): void
138
+ removeEventListener(type: "message", listener: (event: MessageEvent) => void): void
139
+ }
140
+
141
+ interface PostTarget {
142
+ postMessage(message: unknown, targetOrigin: string, transfer?: Transferable[]): void
143
+ }
144
+
145
+ export interface AiPanelRelayOptions {
146
+ /** The host page's window, which both frames post to. */
147
+ readonly host: RelayWindow
148
+ readonly panel: () => PostTarget | null | undefined
149
+ readonly panelOrigin: string
150
+ readonly editor: () => PostTarget | null | undefined
151
+ readonly editorOrigin: string
152
+ }
153
+
154
+ /** Carry the panel's edit requests to the editor and the answers back, until disposed. */
155
+ export function createAiPanelRelay(options: AiPanelRelayOptions): { dispose(): void } {
156
+ const asked = new Set<string>()
157
+ const onMessage = (event: MessageEvent) => {
158
+ const panel = options.panel()
159
+ const editor = options.editor()
160
+ const route = routeAiPanelMessage(event, { panel, panelOrigin: options.panelOrigin, editor, editorOrigin: options.editorOrigin, asked })
161
+ if (!route) return
162
+ const target = route.to === "editor" ? editor : panel
163
+ target?.postMessage(route.message, route.to === "editor" ? options.editorOrigin : options.panelOrigin, route.transfer)
164
+ }
165
+ options.host.addEventListener("message", onMessage)
166
+ return {
167
+ dispose: () => {
168
+ options.host.removeEventListener("message", onMessage)
169
+ asked.clear()
170
+ },
171
+ }
172
+ }
@@ -18,6 +18,19 @@ export const FREECUT_EXPORT_COMPLETE = "FREECUT_EXPORT_COMPLETE"
18
18
  export const FREECUT_EXPORT_PROGRESS = "FREECUT_EXPORT_PROGRESS" // reserved; fork emits it, v1 parents ignore it
19
19
  export const FREECUT_REQUEST_IMPORT = "FREECUT_REQUEST_IMPORT"
20
20
 
21
+ // Editing the open project from the parent. An editor that can says so in its
22
+ // FREECUT_READY `capabilities` ("edit-ops", "timeline-read", "playback",
23
+ // "presence"). A request that is answered carries a `requestId`, and its answer
24
+ // repeats it in its payload; PLAYBACK and PRESENCE are never answered.
25
+ export const NODARO_GET_TIMELINE = "NODARO_GET_TIMELINE"
26
+ export const NODARO_APPLY_OPS = "NODARO_APPLY_OPS"
27
+ export const NODARO_UNDO_EDIT = "NODARO_UNDO_EDIT"
28
+ export const NODARO_PLAYBACK = "NODARO_PLAYBACK"
29
+ export const NODARO_PRESENCE = "NODARO_PRESENCE"
30
+ export const FREECUT_TIMELINE = "FREECUT_TIMELINE"
31
+ export const FREECUT_OPS_RESULT = "FREECUT_OPS_RESULT"
32
+ export const FREECUT_UNDO_RESULT = "FREECUT_UNDO_RESULT"
33
+
21
34
  export interface FreecutImportFile {
22
35
  readonly name: string
23
36
  readonly type: string
@@ -34,7 +34,7 @@ import { MINIMAX_H3_IMAGE_DEFAULT_RESOLUTION, MINIMAX_H3_IMAGE_RESOLUTIONS } fro
34
34
  import { isAutoVideoDuration } from "./video-duration-auto.js"
35
35
  import type { DeclaredSeedanceTaskType } from "./seedance-task-type.js"
36
36
  import { SEEDREAM_5_5_DEFAULT_RESOLUTION, SEEDREAM_5_5_RESOLUTIONS } from "./seedream-5-5.js"
37
- import { FLUX_3_KLEIN_RESOLUTIONS } from "./flux-3-klein.js"
37
+ import { FLUX_3_KLEIN_DEFAULT_RESOLUTION, FLUX_3_KLEIN_RESOLUTIONS } from "./flux-3-klein.js"
38
38
  import {
39
39
  GEMINI_3_1_DEFAULT_VOICE,
40
40
  GEMINI_3_1_TTS_ACCENTS,
@@ -416,6 +416,23 @@ export interface ModelCatalogEntryFields {
416
416
  * `audio_to_video` task). The node's Audio Refs input then takes one clip.
417
417
  */
418
418
  features?: readonly string[]
419
+ /**
420
+ * A WORKFLOW run that would send this image model more input images than
421
+ * `requestImageLimit` allows, the source or base image counted, is refused
422
+ * before anything is reserved, with a message saying how many to remove
423
+ * (`refusesImagesOverLimit`), as a request is. Nothing trims it first: the
424
+ * prompt assembler sends every image a run attaches, so the count refused
425
+ * is the count the run would send. Set on FLUX 3 Klein, text to image and
426
+ * edit alike (decided 2026-11-12: an 11th image is refused, never left out).
427
+ *
428
+ * Without it, a model with a request image limit of its own (Seedream 5.5,
429
+ * GPT Image 2.6 Flare and Sunburst, MiniMax H3 Image) refuses a request
430
+ * over its limit but a workflow run sends its first images up to it
431
+ * (`refusesImagesOverLimitOn`, decided 2026-11-14), and every other model
432
+ * has its structured references trimmed past its reference limit, as it
433
+ * always has.
434
+ */
435
+ refusesImagesOverLimit?: true
419
436
  /**
420
437
  * How this video model's provider addresses its images in the prompt, by
421
438
  * array order — the syntax its frame / identity binding sentences are written
@@ -485,7 +502,8 @@ export interface ModelCatalogEntryFields {
485
502
  */
486
503
  resolutionsByAspectRatio?: Readonly<Record<string, readonly string[]>>
487
504
  /** The resolution a caller who names none lands on when it is not the
488
- * cheapest entry (see `defaultResolutionFor`). */
505
+ * cheapest entry (see `defaultResolutionFor`). `GET /v1/models` and MCP
506
+ * `list_models` serve it as declared, on the models that declare it. */
489
507
  defaultResolution?: string
490
508
  /**
491
509
  * What this model actually RENDERS for a resolution outside `resolutions`.
@@ -1104,9 +1122,11 @@ const IMAGE_MODELS: Record<string, ModelCatalogEntry> = {
1104
1122
  description: "FLUX 3 Klein - the light model of FLUX 3: fast and low cost, at 1K by default, 2K or 4K, in nine shapes, PNG or JPEG. Add images and it edits from up to 10 references, at the same price.",
1105
1123
  useCases: ["fast", "drafts", "iteration", "realistic"],
1106
1124
  features: ["reference-image"],
1125
+ refusesImagesOverLimit: true,
1107
1126
  aspectRatios: FLUX_3_KLEIN_RATIOS,
1108
1127
  strictAspectRatios: true,
1109
1128
  resolutions: FLUX_3_KLEIN_RESOLUTIONS,
1129
+ defaultResolution: FLUX_3_KLEIN_DEFAULT_RESOLUTION,
1110
1130
  outputFormats: FLUX_3_KLEIN_FORMATS,
1111
1131
  pricing: [
1112
1132
  { identifier: "flux-3-klein", credits: 4, note: "1K default" },
@@ -1126,9 +1146,11 @@ const IMAGE_MODELS: Record<string, ModelCatalogEntry> = {
1126
1146
  description: "FLUX 3 Klein edits - fast, low-cost changes from 1 to 10 reference images, which cost nothing extra. 1K by default, 2K or 4K, PNG or JPEG; auto keeps the first image's shape.",
1127
1147
  useCases: ["edit", "iteration", "multi-reference", "fast"],
1128
1148
  features: ["reference-image"],
1149
+ refusesImagesOverLimit: true,
1129
1150
  aspectRatios: FLUX_3_KLEIN_I2I_RATIOS,
1130
1151
  strictAspectRatios: true,
1131
1152
  resolutions: FLUX_3_KLEIN_RESOLUTIONS,
1153
+ defaultResolution: FLUX_3_KLEIN_DEFAULT_RESOLUTION,
1132
1154
  outputFormats: FLUX_3_KLEIN_FORMATS,
1133
1155
  pricing: [
1134
1156
  { identifier: "flux-3-klein-i2i", credits: 4, note: "1K default" },
@@ -854,6 +854,13 @@ export const DEFAULT_REQUEST_IMAGE_LIMIT = 14
854
854
  * 2.6 takes more; a model whose provider takes fewer (Seedream 5.5 and FLUX 3
855
855
  * Klein: 10) is held to its own, so a request is refused before it is
856
856
  * reserved instead of failing at the provider.
857
+ *
858
+ * A row here is also what makes a request over the limit refused rather than
859
+ * trimmed ({@link hasOwnRequestImageLimit}, decided 2026-11-14): the routes,
860
+ * MCP and the editor's Run send every image such a request names, and the
861
+ * route says how many to remove. A workflow run on such a model still sends
862
+ * its first images up to the limit, unless its catalog entry also refuses
863
+ * there ({@link refusesImagesOverLimit}).
857
864
  */
858
865
  const REQUEST_IMAGE_LIMITS: Record<string, number> = {
859
866
  "gpt-image-2-6-flare-i2i": 16,
@@ -875,6 +882,62 @@ export function requestImageLimit(provider: string | undefined): number {
875
882
  return (effective !== undefined ? REQUEST_IMAGE_LIMITS[effective] : undefined) ?? DEFAULT_REQUEST_IMAGE_LIMIT
876
883
  }
877
884
 
885
+ /**
886
+ * True for a model with a request image limit of its own: a row in the table
887
+ * above, read through a text-to-image id's edit sibling as
888
+ * {@link requestImageLimit} reads it (GPT Image 2.6 Flare and Sunburst,
889
+ * MiniMax H3 Image, Seedream 5.5, FLUX 3 Klein). False for a model held to
890
+ * {@link DEFAULT_REQUEST_IMAGE_LIMIT}.
891
+ */
892
+ export function hasOwnRequestImageLimit(provider: string | undefined): boolean {
893
+ if (provider === undefined) return false
894
+ return Object.hasOwn(REQUEST_IMAGE_LIMITS, T2I_TO_I2I_VARIANT[provider] ?? provider)
895
+ }
896
+
897
+ /**
898
+ * True for a model that refuses a WORKFLOW run sending more input images than
899
+ * {@link requestImageLimit} allows, the source or base image counted, instead
900
+ * of having some left out (its catalog entry's `refusesImagesOverLimit`:
901
+ * FLUX 3 Klein). A request is refused on more models
902
+ * ({@link refusesImagesOverLimitOn}). The prompt assembler never trims such a
903
+ * model's references, so every place that refuses counts the images the run
904
+ * would really send. False for every other model, whose workflow runs still
905
+ * trim structured references to its reference limit
906
+ * ({@link imageReferenceLimit}).
907
+ */
908
+ export function refusesImagesOverLimit(provider: string | undefined): boolean {
909
+ return provider !== undefined && MODEL_CATALOG[provider]?.refusesImagesOverLimit === true
910
+ }
911
+
912
+ /**
913
+ * How a run was asked for, which decides what happens to images past a
914
+ * model's limit: `"request"` is one call to a route (the API, an MCP tool,
915
+ * the editor's Run of one node), `"workflow"` a node of a workflow run.
916
+ */
917
+ export type ImageRunKind = "request" | "workflow"
918
+
919
+ /**
920
+ * True when a run of this kind that would send `provider` more input images
921
+ * than {@link requestImageLimit} allows is refused before anything is
922
+ * reserved, saying how many to remove, rather than having the images past the
923
+ * limit left out (decided 2026-11-14):
924
+ *
925
+ * - a request, on every model with a request image limit of its own
926
+ * ({@link hasOwnRequestImageLimit}): nothing trims it first, so the count
927
+ * refused is the count the request names;
928
+ * - a workflow run, only on a model whose catalog entry carries
929
+ * `refusesImagesOverLimit` (FLUX 3 Klein). Every other model's workflow run
930
+ * keeps its rule: its first images up to the limit are sent, so a saved
931
+ * graph keeps running.
932
+ *
933
+ * False on a model held to {@link DEFAULT_REQUEST_IMAGE_LIMIT} (Nano Banana
934
+ * Pro, Flux 2 Pro): its structured references are trimmed to its reference
935
+ * limit on every kind of run, as before.
936
+ */
937
+ export function refusesImagesOverLimitOn(provider: string | undefined, run: ImageRunKind): boolean {
938
+ return refusesImagesOverLimit(provider) || (run === "request" && hasOwnRequestImageLimit(provider))
939
+ }
940
+
878
941
  // Variable pricing: which setting type affects cost per provider
879
942
  export const VARIABLE_PRICING_MODELS: Record<string, "quality" | "resolution" | "rendering-speed"> = {
880
943
  "gpt-image": "quality",
@@ -3217,6 +3280,11 @@ export const VIDEO_REF_LIMITS_BY_PROVIDER: Record<
3217
3280
  * and does not move the run onto the reference-video rate (its clip still
3218
3281
  * counts toward the `videos` cap and the reference videos' total length).
3219
3282
  * Read through `videoCharacterClipsBilledAsReferenceVideo`.
3283
+ *
3284
+ * No model sets it today: Kling 4.0 and Kling 4.0 Flash, both measured,
3285
+ * bill a video subject like an image subject (decided 2026-11-14). It stays
3286
+ * for a model whose provider bills the clip, so that model declares it here
3287
+ * and every price path follows.
3220
3288
  */
3221
3289
  videoCharactersBillAsReferenceVideo?: true
3222
3290
  } | undefined
@@ -3265,10 +3333,9 @@ export const VIDEO_REF_LIMITS_BY_PROVIDER: Record<
3265
3333
  // preset personas, which Kling does not take.
3266
3334
  // Of the 7 subjects, at most 3 may be video subjects (a 3-8 s clip each), and
3267
3335
  // reference videos plus video subjects are at most 5. A video subject is
3268
- // priced as a reference video here until a measured run confirms how Kling
3269
- // 4.0 bills one (decided 2026-11-14): Flash, measured, bills it as an image
3270
- // subject (no flag below).
3271
- "kling-4": { images: 10, videos: 5, audio: 3, characters: 7, materials: 15, videoCharacters: 3, videoCharactersBillAsReferenceVideo: true },
3336
+ // billed like an image subject (measured, decided 2026-11-14), as on Flash:
3337
+ // no `videoCharactersBillAsReferenceVideo`.
3338
+ "kling-4": { images: 10, videos: 5, audio: 3, characters: 7, materials: 15, videoCharacters: 3 },
3272
3339
  // Kling 4.0 Keyframes — the Image References are the in-between frames
3273
3340
  // (`keyframe_urls`, max 8; the clip's duration lowers the cap, see
3274
3341
  // kling4KeyframeFrameCap). No reference videos or audio.
@@ -3279,8 +3346,7 @@ export const VIDEO_REF_LIMITS_BY_PROVIDER: Record<
3279
3346
  // (`voice_url`) when that character is a subject (2-4 images), so at most one
3280
3347
  // per character (7) and none takes a material seat. A wired start frame takes one of the 10 image slots when it
3281
3348
  // runs on this endpoint. A video subject is billed like an image subject
3282
- // (measured on a staging run, decided 2026-11-14): no
3283
- // `videoCharactersBillAsReferenceVideo`.
3349
+ // (measured, decided 2026-11-14): no `videoCharactersBillAsReferenceVideo`.
3284
3350
  "kling-4-flash": { images: 10, videos: 5, audio: 7, characters: 7, materials: 15, audioBindsToCharacters: true, videoCharacters: 3 },
3285
3351
  "grok-i2v": { images: 7 }, // backend kie/models.ts maxRefImages: 7
3286
3352
  "happyhorse-ref2v": { images: 9 }, // backend kie/models.ts maxRefImages: 9
@@ -53,9 +53,10 @@ export interface VideoCharacterReference {
53
53
  * positive `videoCharacters` cap (Kling 4.0, Kling 4.0 Flash) the character
54
54
  * becomes a VIDEO subject made from this clip instead of an image subject.
55
55
  * The clip rides as one more reference video ({@link seatCharacterVideos}),
56
- * so it is measured, capped and priced exactly as a reference video is; its
57
- * own length must fit `VIDEO_CHARACTER_CLIP_DURATION_LIMITS`. Any other model
58
- * refuses it.
56
+ * so it is measured and capped as a reference video is; its own length must
57
+ * fit `VIDEO_CHARACTER_CLIP_DURATION_LIMITS`. It is priced like an image
58
+ * subject unless the model bills it as reference video
59
+ * ({@link pricedReferenceVideoUrls}). Any other model refuses it.
59
60
  */
60
61
  videoUrl?: string
61
62
  }
@@ -109,9 +110,10 @@ export function characterVideoUrls(
109
110
 
110
111
  /**
111
112
  * Whether the provider bills a character's video subject as reference-video
112
- * seconds (`videoCharactersBillAsReferenceVideo`: Kling 4.0). On any other
113
- * model that takes video subjects (Kling 4.0 Flash, measured, decided
114
- * 2026-11-14) the subject is priced like an image subject.
113
+ * seconds (`videoCharactersBillAsReferenceVideo`). False on every model today:
114
+ * Kling 4.0 and Kling 4.0 Flash, both measured, price a video subject like an
115
+ * image subject (decided 2026-11-14). A model that bills the clip declares the
116
+ * flag on its `VIDEO_REF_LIMITS_BY_PROVIDER` row.
115
117
  */
116
118
  export function videoCharacterClipsBilledAsReferenceVideo(provider: string | undefined): boolean {
117
119
  return provider ? VIDEO_REF_LIMITS_BY_PROVIDER[provider]?.videoCharactersBillAsReferenceVideo === true : false
@@ -148,10 +150,13 @@ export interface CharacterVideoSeatProblem {
148
150
  * The reference-video list a run sends once its characters' clips are seated
149
151
  * in it — the ONE rule both video routes (a precheck, before the duration
150
152
  * check, the quote and any reservation) and the workflow run (the payload
151
- * builder) apply, so a video subject's clip is measured, capped, priced, held
152
- * and settled exactly as a reference video is (KIE bills video subjects as
153
- * reference-video seconds, summed). The provider runner then takes the seat
154
- * back out of the reference videos and sends it as the character's subject.
153
+ * builder) apply, so a video subject's clip is measured and capped exactly as
154
+ * a reference video is (the provider counts both in one cap and one total
155
+ * length). The price reads the seated list through
156
+ * {@link pricedReferenceVideoUrls}, which leaves the clip out on a model that
157
+ * bills a video subject like an image subject. The provider runner then takes
158
+ * the seat back out of the reference videos and sends it as the character's
159
+ * subject.
155
160
  *
156
161
  * - No clip: the list as it came (the same value).
157
162
  * - A clip already in the list (also wired as a plain reference video) keeps