Kling 节点接入官方 4.0 / Flash(文生/图生/Omni)

This commit is contained in:
Jony
2026-11-10 12:50:52 +08:00
parent b4ddd35a6c
commit af300996b9
8 changed files with 974 additions and 179 deletions
+15 -8
View File
@@ -87,18 +87,25 @@ invalid model, duration, resolution, mode, media count, or edit clip length
cannot consume an upload or paid generation request. Saved workflows retain the
`O1keyGrokVideo` ID and are migrated according to [ADR 0006](decisions/0006-grok-video-api-and-workflow-migration.md).
`K3Video` keeps its released node ID and appends a `v4` DynamicCombo branch. The
branch adds a generation-mode selector with text-to-video, keyframes, and Omni
`K3Video` keeps its released node ID and appends `v4` and `v4-flash`
DynamicCombo branches, displayed as `Kling 4.0` and `Kling 4.0 Flash`. The
branches add a generation-mode selector with text-to-video, keyframes, and Omni
reference paths. Existing v3/v2.6/v3-omni branches retain their original
DynamicCombo option order and positional widgets. Kling 4.0 keyframe sockets
and additional Omni reference sockets are appended after the released widget
block, so saved workflows do not shift their values. `clients/kling_video_client.py`
owns the v4 capability checks and builds the proxy-compatible `model_name`,
resolution `mode`, `aspect_ratio`, and `metadata` fields; the node reuses the
existing R2 upload and interruption-aware task lifecycle. Keyframes use
`metadata.first_frame`, `metadata.middle_frames`, and `metadata.last_frame`;
Omni references use `metadata.refer_images` and `metadata.videos`. The shared
video result parser also accepts Kling 4.0's `output.media[].url` envelope.
owns the official 4.0 / Flash capability checks and builds `contents`,
`settings`, and `options` bodies; the model is taken from the path
(`/kling/text-to-video/kling-4.0`, `/kling/image-to-video/kling-4.0`,
`/kling/omni-video/kling-4.0`, or the `kling-4.0-flash` variants) and is never
sent in the request body. Flash accepts only `720p` and 3–20 second durations,
and the frontend clamps a leftover 1080p value when switching from 4.0.
Keyframes omit `settings.aspect_ratio`; text defaults to `16:9` and Omni to
`adaptive`. The node reuses R2 upload and interruption-aware downloads, but
polls the official `{code, message, request_id, data}` envelope, reads
`data.id` as the task id, and takes the result from `data[].outputs[].url`
rather than the 3.0 Omni `video_url` parser. `K3MotionControl` remains a 3.0
motion-control path only.
### Shared utilities
@@ -38,3 +38,14 @@ because the released node has no compatible AUDIO or element-ID sockets.
`tests/test_kling_video.py` covers all three payload shapes, capability limits,
mutual exclusions, endpoint selection, and the Kling 4.0 result envelope.
## Official path update (2026-11-10)
The first integration used a proxy-compatible `model_name` / `metadata`
envelope and `/kling/v1/videos/*` paths. The published O1Key Kling 4.0 / Flash
docs now require official paths, `contents` / `settings` / `options` bodies,
and the `{code, message, request_id, data}` query envelope. The `v4` option is
retained as the stored Kling 4.0 value; `v4-flash` is appended, and both are
shown with Chinese display names. Flash is limited to 720p and 3–20 seconds.
Element and voice management remain outside this integration unless the
caller already has IDs.
+2
View File
@@ -30,6 +30,8 @@ For `O1keyPromptMultiFunction`, keep the original first two widgets unchanged an
For Omni Flash, keep `O1keyOmniFlashVideo` as the sole node ID. Its `execute` validates all modes and media before upload or paid submission, then returns a native `VIDEO`. Ordinary generation hard-codes `omni_flash_10s`; edit mode uses `omni_flash_abra_edit`. If changing the widget schema, keep the migration that removes the former model value at index 2 so saved workflows remain aligned. The button only queues the current node using ComfyUI's native queue. O1Key's JSON `/v1/videos` gateway requires `input_reference` to be a string for one image; send several references as repeated multipart fields, never a JSON array under `input_reference`. Keep provider URLs and credentials out of widgets, workflow metadata, and logs. Use `tests/test_omni_flash.py` and `tests/test_omni_flash_frontend.mjs` for offline regression coverage.
For `K3Video`, keep the released node ID and the existing v3 / v2.6 / v3-omni widget order. Official Kling 4.0 and Kling 4.0 Flash are stored as `v4` and `v4-flash` with frontend display names; accept the `v4` alias so saved workflows keep working. Build official `contents` / `settings` / `options` bodies in `clients/kling_video_client.py`, choose the path by model and generation mode, and never send a `model` field. Use a dedicated 4.0 query parser (`data.id`, `submitted` / `processing` / `succeeded` / `failed`, `data[].outputs[].url`) and do not route 4.0 tasks through the 3.0 Omni `video_url` parser. Flash must reject `1080p` and durations above 20 seconds in both the backend and `web/js/klingV4ParameterGuard.js`. Do not invent a 4.0 motion-control path on `K3MotionControl`. Run `tests/test_kling_video.py` after changing this contract.
- Normalize authentication and base URL selection through `utils/config.py`.
- Use shared retry, interruption, polling, upload, and download helpers before creating provider-local variants.
- Convert provider-specific failures into actionable messages without printing secrets or full payloads.