project-graph-mcp 2.3.2 → 2.4.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.
- package/package.json +3 -2
- package/src/analysis/analysis-cache.ctx +9 -0
- package/src/analysis/analysis-cache.js +1 -1
- package/src/analysis/complexity.ctx +6 -0
- package/src/analysis/complexity.js +1 -1
- package/src/analysis/custom-rules.ctx +14 -0
- package/src/analysis/custom-rules.js +1 -1
- package/src/analysis/db-analysis.ctx +7 -0
- package/src/analysis/db-analysis.js +1 -1
- package/src/analysis/dead-code.ctx +6 -0
- package/src/analysis/dead-code.js +1 -1
- package/src/analysis/full-analysis.ctx +9 -0
- package/src/analysis/full-analysis.js +1 -1
- package/src/analysis/jsdoc-checker.ctx +10 -0
- package/src/analysis/jsdoc-checker.js +1 -1
- package/src/analysis/jsdoc-generator.ctx +9 -0
- package/src/analysis/jsdoc-generator.js +1 -1
- package/src/analysis/large-files.ctx +6 -0
- package/src/analysis/large-files.js +1 -1
- package/src/analysis/outdated-patterns.ctx +7 -0
- package/src/analysis/outdated-patterns.js +1 -1
- package/src/analysis/similar-functions.ctx +6 -0
- package/src/analysis/similar-functions.js +1 -1
- package/src/analysis/test-annotations.ctx +11 -0
- package/src/analysis/test-annotations.js +1 -1
- package/src/analysis/type-checker.ctx +6 -0
- package/src/analysis/type-checker.js +1 -1
- package/src/analysis/undocumented.ctx +8 -0
- package/src/analysis/undocumented.js +1 -1
- package/src/cli/cli-handlers.ctx +7 -0
- package/src/cli/cli-handlers.js +1 -1
- package/src/cli/cli.ctx +6 -0
- package/src/cli/cli.js +1 -1
- package/src/compact/ai-context.ctx +6 -0
- package/src/compact/ai-context.js +1 -1
- package/src/compact/compact-migrate.ctx +8 -0
- package/src/compact/compact-migrate.js +1 -1
- package/src/compact/compact.ctx +11 -0
- package/src/compact/compact.js +1 -1
- package/src/compact/compress.ctx +7 -0
- package/src/compact/compress.js +1 -1
- package/src/compact/ctx-resolver.ctx +2 -0
- package/src/compact/ctx-resolver.js +1 -1
- package/src/compact/ctx-to-jsdoc.ctx +11 -0
- package/src/compact/ctx-to-jsdoc.js +1 -1
- package/src/compact/doc-dialect.ctx +11 -0
- package/src/compact/doc-dialect.js +2 -2
- package/src/compact/expand.ctx +14 -0
- package/src/compact/expand.js +1 -1
- package/src/compact/framework-references.ctx +7 -0
- package/src/compact/framework-references.js +1 -1
- package/src/compact/instructions.ctx +6 -0
- package/src/compact/instructions.js +1 -1
- package/src/compact/jsdoc-builder.ctx +4 -0
- package/src/compact/jsdoc-builder.js +1 -1
- package/src/compact/mode-config.ctx +8 -0
- package/src/compact/mode-config.js +1 -1
- package/src/compact/split-declarations.ctx +6 -0
- package/src/compact/split-declarations.js +1 -1
- package/src/compact/validate-pipeline.ctx +12 -0
- package/src/compact/validate-pipeline.js +1 -1
- package/src/core/event-bus.ctx +9 -0
- package/src/core/event-bus.js +1 -1
- package/src/core/file-walker.ctx +1 -0
- package/src/core/file-walker.js +1 -1
- package/src/core/filters.ctx +12 -0
- package/src/core/filters.js +1 -1
- package/src/core/graph-builder.ctx +7 -0
- package/src/core/graph-builder.js +1 -1
- package/src/core/parser.ctx +12 -0
- package/src/core/parser.js +1 -1
- package/src/core/utils.ctx +1 -0
- package/src/core/utils.js +1 -1
- package/src/core/workspace.ctx +7 -0
- package/src/core/workspace.js +1 -1
- package/src/lang/lang-go.ctx +8 -0
- package/src/lang/lang-go.js +1 -1
- package/src/lang/lang-python.ctx +5 -0
- package/src/lang/lang-python.js +1 -1
- package/src/lang/lang-sql.ctx +10 -0
- package/src/lang/lang-sql.js +1 -1
- package/src/lang/lang-typescript.ctx +6 -0
- package/src/lang/lang-typescript.js +1 -1
- package/src/lang/lang-utils.ctx +5 -0
- package/src/lang/lang-utils.js +1 -1
- package/src/mcp/mcp-server.ctx +6 -0
- package/src/mcp/mcp-server.js +1 -1
- package/src/mcp/tool-defs.ctx +2 -0
- package/src/mcp/tool-defs.js +1 -1
- package/src/mcp/tools.ctx +13 -0
- package/src/mcp/tools.js +1 -1
- package/src/network/backend-lifecycle.ctx +10 -0
- package/src/network/backend-lifecycle.js +1 -1
- package/src/network/backend.ctx +5 -0
- package/src/network/backend.js +1 -1
- package/src/network/local-gateway.ctx +9 -0
- package/src/network/local-gateway.js +1 -1
- package/src/network/mdns.ctx +6 -0
- package/src/network/mdns.js +1 -1
- package/src/network/server.ctx +2 -0
- package/src/network/server.js +2 -2
- package/src/network/web-server.ctx +17 -0
- package/src/network/web-server.js +2 -2
- package/web/follow-controller.js +94 -25
- package/web/panels/dep-graph.js +207 -21
- package/project-graph-mcp-2.3.0.tgz +0 -0
- package/vendor/symbiote-node/CHANGELOG.md +0 -31
- package/vendor/symbiote-node/LICENSE +0 -21
- package/vendor/symbiote-node/README.md +0 -206
- package/vendor/symbiote-node/canvas/AutoLayout.js +0 -725
- package/vendor/symbiote-node/canvas/Breadcrumb/Breadcrumb.css.js +0 -73
- package/vendor/symbiote-node/canvas/Breadcrumb/Breadcrumb.js +0 -93
- package/vendor/symbiote-node/canvas/Breadcrumb/Breadcrumb.tpl.js +0 -9
- package/vendor/symbiote-node/canvas/CanvasConnectionRenderer.js +0 -962
- package/vendor/symbiote-node/canvas/ConnectionRenderer.js +0 -1468
- package/vendor/symbiote-node/canvas/FlowSimulator.js +0 -323
- package/vendor/symbiote-node/canvas/ForceLayout.js +0 -189
- package/vendor/symbiote-node/canvas/ForceWorker.js +0 -1325
- package/vendor/symbiote-node/canvas/GraphTabs/GraphTabs.css.js +0 -97
- package/vendor/symbiote-node/canvas/GraphTabs/GraphTabs.js +0 -176
- package/vendor/symbiote-node/canvas/GraphTabs/GraphTabs.tpl.js +0 -12
- package/vendor/symbiote-node/canvas/LODManager.js +0 -88
- package/vendor/symbiote-node/canvas/Minimap/Minimap.css.js +0 -71
- package/vendor/symbiote-node/canvas/Minimap/Minimap.js +0 -207
- package/vendor/symbiote-node/canvas/Minimap/Minimap.tpl.js +0 -9
- package/vendor/symbiote-node/canvas/NodeCanvas/NodeCanvas.css.js +0 -261
- package/vendor/symbiote-node/canvas/NodeCanvas/NodeCanvas.js +0 -1840
- package/vendor/symbiote-node/canvas/NodeCanvas/NodeCanvas.tpl.js +0 -22
- package/vendor/symbiote-node/canvas/NodeSearch/NodeSearch.css.js +0 -97
- package/vendor/symbiote-node/canvas/NodeSearch/NodeSearch.js +0 -132
- package/vendor/symbiote-node/canvas/NodeSearch/NodeSearch.tpl.js +0 -21
- package/vendor/symbiote-node/canvas/NodeViewManager.js +0 -584
- package/vendor/symbiote-node/canvas/PinExpansion.js +0 -131
- package/vendor/symbiote-node/canvas/PseudoConnection.js +0 -80
- package/vendor/symbiote-node/canvas/SubgraphManager.js +0 -201
- package/vendor/symbiote-node/canvas/SubgraphRouter.js +0 -443
- package/vendor/symbiote-node/canvas/ViewportActions.js +0 -446
- package/vendor/symbiote-node/core/Connection.js +0 -45
- package/vendor/symbiote-node/core/Editor.js +0 -451
- package/vendor/symbiote-node/core/Frame.js +0 -31
- package/vendor/symbiote-node/core/GraphMermaid.js +0 -348
- package/vendor/symbiote-node/core/GraphText.js +0 -210
- package/vendor/symbiote-node/core/Node.js +0 -143
- package/vendor/symbiote-node/core/Portal.js +0 -104
- package/vendor/symbiote-node/core/Socket.js +0 -185
- package/vendor/symbiote-node/core/SubgraphNode.js +0 -125
- package/vendor/symbiote-node/engine/AgentUICommands.js +0 -100
- package/vendor/symbiote-node/engine/Executor.js +0 -371
- package/vendor/symbiote-node/engine/Graph.js +0 -314
- package/vendor/symbiote-node/engine/GraphServer.js +0 -353
- package/vendor/symbiote-node/engine/HandlerLoader.js +0 -145
- package/vendor/symbiote-node/engine/History.js +0 -83
- package/vendor/symbiote-node/engine/Lifecycle.js +0 -118
- package/vendor/symbiote-node/engine/Persistence.js +0 -84
- package/vendor/symbiote-node/engine/Registry.js +0 -264
- package/vendor/symbiote-node/engine/SocketTypes.js +0 -79
- package/vendor/symbiote-node/engine/cli.js +0 -404
- package/vendor/symbiote-node/engine/index.js +0 -56
- package/vendor/symbiote-node/engine/nanoid.js +0 -28
- package/vendor/symbiote-node/engine/package.json +0 -26
- package/vendor/symbiote-node/engine/packs/ai/beat-detect.handler.js +0 -215
- package/vendor/symbiote-node/engine/packs/ai/content-adapt.handler.js +0 -238
- package/vendor/symbiote-node/engine/packs/ai/face-detect.handler.js +0 -287
- package/vendor/symbiote-node/engine/packs/ai/grok-generate.handler.js +0 -565
- package/vendor/symbiote-node/engine/packs/ai/kling-lipsync.handler.js +0 -414
- package/vendor/symbiote-node/engine/packs/ai/lesson-generate.handler.js +0 -343
- package/vendor/symbiote-node/engine/packs/ai/opencode.handler.js +0 -164
- package/vendor/symbiote-node/engine/packs/ai/replicate-lipsync.handler.js +0 -341
- package/vendor/symbiote-node/engine/packs/ai/tts.handler.js +0 -241
- package/vendor/symbiote-node/engine/packs/ai/whisper.handler.js +0 -191
- package/vendor/symbiote-node/engine/packs/data/db-query.handler.js +0 -67
- package/vendor/symbiote-node/engine/packs/data/news-accumulate.handler.js +0 -281
- package/vendor/symbiote-node/engine/packs/data/personas.handler.js +0 -160
- package/vendor/symbiote-node/engine/packs/data/prompt-loader.handler.js +0 -193
- package/vendor/symbiote-node/engine/packs/data/roles.handler.js +0 -216
- package/vendor/symbiote-node/engine/packs/data/rss-feed.handler.js +0 -244
- package/vendor/symbiote-node/engine/packs/debug/inject.handler.js +0 -52
- package/vendor/symbiote-node/engine/packs/flow/agent.handler.js +0 -73
- package/vendor/symbiote-node/engine/packs/flow/if.handler.js +0 -107
- package/vendor/symbiote-node/engine/packs/flow/loop.handler.js +0 -58
- package/vendor/symbiote-node/engine/packs/flow/merge.handler.js +0 -60
- package/vendor/symbiote-node/engine/packs/flow/retry.handler.js +0 -65
- package/vendor/symbiote-node/engine/packs/flow/switch.handler.js +0 -64
- package/vendor/symbiote-node/engine/packs/flow/wait-all.handler.js +0 -39
- package/vendor/symbiote-node/engine/packs/io/http-request.handler.js +0 -82
- package/vendor/symbiote-node/engine/packs/io/read-file.handler.js +0 -60
- package/vendor/symbiote-node/engine/packs/io/write-file.handler.js +0 -63
- package/vendor/symbiote-node/engine/packs/transform/anchor-match.handler.js +0 -494
- package/vendor/symbiote-node/engine/packs/transform/effects-skeleton.handler.js +0 -417
- package/vendor/symbiote-node/engine/packs/transform/json-parse.handler.js +0 -43
- package/vendor/symbiote-node/engine/packs/transform/lipsync-select.handler.js +0 -339
- package/vendor/symbiote-node/engine/packs/transform/riopla-adapt.handler.js +0 -432
- package/vendor/symbiote-node/engine/packs/transform/set.handler.js +0 -57
- package/vendor/symbiote-node/engine/packs/transform/template-builder.handler.js +0 -134
- package/vendor/symbiote-node/engine/packs/transform/template.handler.js +0 -79
- package/vendor/symbiote-node/engine/packs/transform/timeline-build.handler.js +0 -399
- package/vendor/symbiote-node/engine/packs/util/delay.handler.js +0 -39
- package/vendor/symbiote-node/engine/packs/util/log.handler.js +0 -44
- package/vendor/symbiote-node/engine/packs/video-pack.js +0 -323
- package/vendor/symbiote-node/index.js +0 -103
- package/vendor/symbiote-node/inspector/InspectorPanel/InspectorPanel.css.js +0 -361
- package/vendor/symbiote-node/inspector/InspectorPanel/InspectorPanel.js +0 -332
- package/vendor/symbiote-node/inspector/InspectorPanel/InspectorPanel.tpl.js +0 -96
- package/vendor/symbiote-node/inspector/TemplatePreview/TemplatePreview.css.js +0 -104
- package/vendor/symbiote-node/inspector/TemplatePreview/TemplatePreview.js +0 -133
- package/vendor/symbiote-node/inspector/TemplatePreview/TemplatePreview.tpl.js +0 -33
- package/vendor/symbiote-node/interactions/ConnectFlow.js +0 -307
- package/vendor/symbiote-node/interactions/Drag.js +0 -102
- package/vendor/symbiote-node/interactions/Selector.js +0 -132
- package/vendor/symbiote-node/interactions/SnapGrid.js +0 -65
- package/vendor/symbiote-node/interactions/Zoom.js +0 -140
- package/vendor/symbiote-node/layout/ActionZone/ActionZone.css.js +0 -88
- package/vendor/symbiote-node/layout/ActionZone/ActionZone.js +0 -254
- package/vendor/symbiote-node/layout/ActionZone/ActionZone.tpl.js +0 -11
- package/vendor/symbiote-node/layout/Layout/Layout.css.js +0 -88
- package/vendor/symbiote-node/layout/Layout/Layout.js +0 -622
- package/vendor/symbiote-node/layout/Layout/Layout.tpl.js +0 -25
- package/vendor/symbiote-node/layout/LayoutNode/LayoutNode.css.js +0 -293
- package/vendor/symbiote-node/layout/LayoutNode/LayoutNode.js +0 -467
- package/vendor/symbiote-node/layout/LayoutNode/LayoutNode.tpl.js +0 -33
- package/vendor/symbiote-node/layout/LayoutPreview/LayoutPreview.css.js +0 -46
- package/vendor/symbiote-node/layout/LayoutPreview/LayoutPreview.js +0 -102
- package/vendor/symbiote-node/layout/LayoutPreview/LayoutPreview.tpl.js +0 -6
- package/vendor/symbiote-node/layout/LayoutRouter/LayoutRouter.js +0 -156
- package/vendor/symbiote-node/layout/LayoutRouter/routerSync.js +0 -250
- package/vendor/symbiote-node/layout/LayoutSidebar/LayoutSidebar.css.js +0 -379
- package/vendor/symbiote-node/layout/LayoutSidebar/LayoutSidebar.js +0 -263
- package/vendor/symbiote-node/layout/LayoutSidebar/LayoutSidebar.tpl.js +0 -20
- package/vendor/symbiote-node/layout/LayoutSidebar/SidebarSection.js +0 -183
- package/vendor/symbiote-node/layout/LayoutTree.js +0 -246
- package/vendor/symbiote-node/layout/PanelMenu/PanelMenu.css.js +0 -43
- package/vendor/symbiote-node/layout/PanelMenu/PanelMenu.js +0 -89
- package/vendor/symbiote-node/layout/PanelMenu/PanelMenu.tpl.js +0 -14
- package/vendor/symbiote-node/layout/index.js +0 -16
- package/vendor/symbiote-node/menu/ContextMenu/ContextMenu.css.js +0 -61
- package/vendor/symbiote-node/menu/ContextMenu/ContextMenu.js +0 -79
- package/vendor/symbiote-node/menu/ContextMenu/ContextMenu.tpl.js +0 -19
- package/vendor/symbiote-node/node/CtrlItem/CtrlItem.css.js +0 -41
- package/vendor/symbiote-node/node/CtrlItem/CtrlItem.js +0 -24
- package/vendor/symbiote-node/node/CtrlItem/CtrlItem.tpl.js +0 -16
- package/vendor/symbiote-node/node/GraphFrame/GraphFrame.css.js +0 -65
- package/vendor/symbiote-node/node/GraphFrame/GraphFrame.js +0 -29
- package/vendor/symbiote-node/node/GraphFrame/GraphFrame.tpl.js +0 -13
- package/vendor/symbiote-node/node/GraphNode/GraphNode.css.js +0 -683
- package/vendor/symbiote-node/node/GraphNode/GraphNode.js +0 -92
- package/vendor/symbiote-node/node/GraphNode/GraphNode.tpl.js +0 -17
- package/vendor/symbiote-node/node/NodeSocket/NodeSocket.js +0 -25
- package/vendor/symbiote-node/node/NodeSocket/NodeSocket.tpl.js +0 -7
- package/vendor/symbiote-node/node/PortItem/PortItem.css.js +0 -90
- package/vendor/symbiote-node/node/PortItem/PortItem.js +0 -87
- package/vendor/symbiote-node/node/PortItem/PortItem.tpl.js +0 -10
- package/vendor/symbiote-node/package.json +0 -59
- package/vendor/symbiote-node/palette/PaletteBrowser/PaletteBrowser.css.js +0 -143
- package/vendor/symbiote-node/palette/PaletteBrowser/PaletteBrowser.js +0 -131
- package/vendor/symbiote-node/palette/PaletteBrowser/PaletteBrowser.tpl.js +0 -16
- package/vendor/symbiote-node/plugins/History.js +0 -384
- package/vendor/symbiote-node/plugins/Readonly.js +0 -59
- package/vendor/symbiote-node/shapes/CircleShape.js +0 -80
- package/vendor/symbiote-node/shapes/CommentShape.js +0 -35
- package/vendor/symbiote-node/shapes/DiamondShape.js +0 -115
- package/vendor/symbiote-node/shapes/NodeShape.js +0 -80
- package/vendor/symbiote-node/shapes/PillShape.js +0 -91
- package/vendor/symbiote-node/shapes/RectShape.js +0 -72
- package/vendor/symbiote-node/shapes/SVGShape.js +0 -494
- package/vendor/symbiote-node/shapes/index.js +0 -53
- package/vendor/symbiote-node/themes/Palette.js +0 -32
- package/vendor/symbiote-node/themes/Skin.js +0 -113
- package/vendor/symbiote-node/themes/Theme.js +0 -84
- package/vendor/symbiote-node/themes/carbon.js +0 -137
- package/vendor/symbiote-node/themes/dark.js +0 -137
- package/vendor/symbiote-node/themes/ebook.js +0 -138
- package/vendor/symbiote-node/themes/grey.js +0 -137
- package/vendor/symbiote-node/themes/light.js +0 -137
- package/vendor/symbiote-node/themes/neon.js +0 -138
- package/vendor/symbiote-node/themes/pcb.js +0 -273
- package/vendor/symbiote-node/themes/synthwave.js +0 -137
- package/vendor/symbiote-node/toolbar/QuickToolbar/QuickToolbar.css.js +0 -86
- package/vendor/symbiote-node/toolbar/QuickToolbar/QuickToolbar.js +0 -128
- package/vendor/symbiote-node/toolbar/QuickToolbar/QuickToolbar.tpl.js +0 -29
|
@@ -1,414 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ai/kling-lipsync — Kling API lip-sync animation
|
|
3
|
-
*
|
|
4
|
-
* Adds lip-sync mouth animation to videos via Kling API.
|
|
5
|
-
* JWT authentication with HMAC-SHA256 signing.
|
|
6
|
-
*
|
|
7
|
-
* 3-step pipeline:
|
|
8
|
-
* 1. identify-face: detect faces in video → session_id + face_id
|
|
9
|
-
* 2. advanced-lip-sync: create task with audio + face → task_id
|
|
10
|
-
* 3. poll: wait for completion → download result video
|
|
11
|
-
*
|
|
12
|
-
* Ported from Mr-Computer/modules/ai-music-video/src/services/kling-lipsync.js
|
|
13
|
-
*
|
|
14
|
-
* @module agi-graph/packs/ai/kling-lipsync
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { createHmac } from 'crypto';
|
|
18
|
-
import { readFile, writeFile, mkdir } from 'fs/promises';
|
|
19
|
-
import { existsSync } from 'fs';
|
|
20
|
-
import { execSync } from 'child_process';
|
|
21
|
-
import path from 'path';
|
|
22
|
-
|
|
23
|
-
export default {
|
|
24
|
-
type: 'ai/kling-lipsync',
|
|
25
|
-
category: 'ai',
|
|
26
|
-
icon: 'record_voice_over',
|
|
27
|
-
|
|
28
|
-
driver: {
|
|
29
|
-
description: 'Kling API lip-sync: detect face → animate mouth → download result',
|
|
30
|
-
inputs: [
|
|
31
|
-
{ name: 'videoUrl', type: 'string' },
|
|
32
|
-
{ name: 'audioPath', type: 'string' },
|
|
33
|
-
],
|
|
34
|
-
outputs: [
|
|
35
|
-
{ name: 'result', type: 'any' },
|
|
36
|
-
{ name: 'error', type: 'string' },
|
|
37
|
-
],
|
|
38
|
-
params: {
|
|
39
|
-
operation: { type: 'string', default: 'lipsync', description: 'Operation: identify-face | lipsync | poll | batch' },
|
|
40
|
-
accessKey: { type: 'string', default: '', description: 'Kling API access key' },
|
|
41
|
-
secretKey: { type: 'string', default: '', description: 'Kling API secret key' },
|
|
42
|
-
baseUrl: { type: 'string', default: 'https://api.klingai.com', description: 'Kling API base URL' },
|
|
43
|
-
publicBaseUrl: { type: 'string', default: '', description: 'Public URL for file server (ngrok/cloudflared)' },
|
|
44
|
-
outputDir: { type: 'string', default: '/tmp/kling-lipsync', description: 'Output directory for results' },
|
|
45
|
-
// For poll operation
|
|
46
|
-
taskId: { type: 'string', default: '', description: 'Task ID to poll' },
|
|
47
|
-
maxWaitMs: { type: 'int', default: 300000, description: 'Max poll wait time (ms)' },
|
|
48
|
-
// For lipsync operation
|
|
49
|
-
startTime: { type: 'number', default: 0, description: 'Audio start time (seconds)' },
|
|
50
|
-
endTime: { type: 'number', default: 0, description: 'Audio end time (seconds)' },
|
|
51
|
-
segmentId: { type: 'string', default: '', description: 'Segment identifier' },
|
|
52
|
-
// For batch operation
|
|
53
|
-
segments: { type: 'any', default: null, description: 'Segments array with start/end/promptId' },
|
|
54
|
-
videoMap: { type: 'any', default: null, description: 'Map of promptId → videoPath' },
|
|
55
|
-
concurrency: { type: 'int', default: 2, description: 'Max concurrent batch tasks' },
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
lifecycle: {
|
|
60
|
-
validate: (inputs, params) => {
|
|
61
|
-
if (!params.accessKey || !params.secretKey) return false;
|
|
62
|
-
|
|
63
|
-
const op = params.operation;
|
|
64
|
-
if (op === 'identify-face' && !inputs.videoUrl) return false;
|
|
65
|
-
if (op === 'poll' && !params.taskId) return false;
|
|
66
|
-
if (op === 'lipsync' && (!inputs.videoUrl || !inputs.audioPath)) return false;
|
|
67
|
-
if (op === 'batch' && (!params.segments || !inputs.audioPath)) return false;
|
|
68
|
-
|
|
69
|
-
return true;
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
cacheKey: (inputs, params) => {
|
|
73
|
-
return `kling:${params.operation}:${params.segmentId || params.taskId || inputs.videoUrl || ''}`;
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
execute: async (inputs, params) => {
|
|
77
|
-
try {
|
|
78
|
-
const op = params.operation;
|
|
79
|
-
const token = generateJWT(params.accessKey, params.secretKey);
|
|
80
|
-
|
|
81
|
-
if (op === 'identify-face') {
|
|
82
|
-
const data = await identifyFace(inputs.videoUrl, token, params.baseUrl);
|
|
83
|
-
return { result: data, error: null };
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (op === 'poll') {
|
|
87
|
-
const data = await pollTaskCompletion(params.taskId, token, params);
|
|
88
|
-
return { result: data, error: null };
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (op === 'lipsync') {
|
|
92
|
-
const result = await processSegment(inputs, params);
|
|
93
|
-
return { result, error: null };
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (op === 'batch') {
|
|
97
|
-
const results = await processBatch(inputs, params);
|
|
98
|
-
return { result: { processed: results.size, results: Object.fromEntries(results) }, error: null };
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return { result: null, error: `Unknown operation: ${op}` };
|
|
102
|
-
} catch (err) {
|
|
103
|
-
return { result: null, error: err.message };
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
// --- JWT Authentication ---
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Generate JWT token for Kling API authentication
|
|
113
|
-
* @param {string} accessKey
|
|
114
|
-
* @param {string} secretKey
|
|
115
|
-
* @returns {string}
|
|
116
|
-
*/
|
|
117
|
-
function generateJWT(accessKey, secretKey) {
|
|
118
|
-
const header = { alg: 'HS256', typ: 'JWT' };
|
|
119
|
-
const now = Math.floor(Date.now() / 1000);
|
|
120
|
-
const payload = {
|
|
121
|
-
iss: accessKey,
|
|
122
|
-
exp: now + 1800,
|
|
123
|
-
nbf: now - 5,
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const base64Header = Buffer.from(JSON.stringify(header)).toString('base64url');
|
|
127
|
-
const base64Payload = Buffer.from(JSON.stringify(payload)).toString('base64url');
|
|
128
|
-
|
|
129
|
-
const signature = createHmac('sha256', secretKey)
|
|
130
|
-
.update(`${base64Header}.${base64Payload}`)
|
|
131
|
-
.digest('base64url');
|
|
132
|
-
|
|
133
|
-
return `${base64Header}.${base64Payload}.${signature}`;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// --- API Operations ---
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Step 1: Identify face in video
|
|
140
|
-
* @param {string} videoUrl
|
|
141
|
-
* @param {string} token
|
|
142
|
-
* @param {string} baseUrl
|
|
143
|
-
* @returns {Promise<Object>}
|
|
144
|
-
*/
|
|
145
|
-
async function identifyFace(videoUrl, token, baseUrl) {
|
|
146
|
-
const response = await fetch(`${baseUrl}/v1/videos/identify-face`, {
|
|
147
|
-
method: 'POST',
|
|
148
|
-
headers: {
|
|
149
|
-
'Content-Type': 'application/json',
|
|
150
|
-
'Authorization': `Bearer ${token}`,
|
|
151
|
-
},
|
|
152
|
-
body: JSON.stringify({ video_url: videoUrl }),
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
if (!response.ok) {
|
|
156
|
-
const errorText = await response.text();
|
|
157
|
-
throw new Error(`Kling identify-face error: ${response.status} - ${errorText}`);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const result = await response.json();
|
|
161
|
-
if (result.code !== 0) {
|
|
162
|
-
throw new Error(`Kling API error: ${result.code} - ${result.message}`);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return result.data;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Step 2: Create lip-sync task
|
|
170
|
-
* @param {string} sessionId
|
|
171
|
-
* @param {string} faceId
|
|
172
|
-
* @param {string} soundFile - Base64 audio
|
|
173
|
-
* @param {number} soundDurationMs
|
|
174
|
-
* @param {number} faceStartMs
|
|
175
|
-
* @param {string} token
|
|
176
|
-
* @param {string} baseUrl
|
|
177
|
-
* @returns {Promise<Object>}
|
|
178
|
-
*/
|
|
179
|
-
async function createLipsyncTask(sessionId, faceId, soundFile, soundDurationMs, faceStartMs, token, baseUrl) {
|
|
180
|
-
const response = await fetch(`${baseUrl}/v1/videos/advanced-lip-sync`, {
|
|
181
|
-
method: 'POST',
|
|
182
|
-
headers: {
|
|
183
|
-
'Content-Type': 'application/json',
|
|
184
|
-
'Authorization': `Bearer ${token}`,
|
|
185
|
-
},
|
|
186
|
-
body: JSON.stringify({
|
|
187
|
-
session_id: sessionId,
|
|
188
|
-
face_choose: [{
|
|
189
|
-
face_id: faceId,
|
|
190
|
-
sound_file: soundFile,
|
|
191
|
-
sound_start_time: 0,
|
|
192
|
-
sound_end_time: soundDurationMs,
|
|
193
|
-
sound_insert_time: faceStartMs,
|
|
194
|
-
sound_volume: 1,
|
|
195
|
-
original_audio_volume: 0,
|
|
196
|
-
}],
|
|
197
|
-
}),
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
if (!response.ok) {
|
|
201
|
-
const errorText = await response.text();
|
|
202
|
-
throw new Error(`Kling advanced-lip-sync error: ${response.status} - ${errorText}`);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const result = await response.json();
|
|
206
|
-
if (result.code !== 0) {
|
|
207
|
-
throw new Error(`Kling API error: ${result.code} - ${result.message}`);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return result.data;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Step 3: Poll for task completion
|
|
215
|
-
* @param {string} taskId
|
|
216
|
-
* @param {string} token
|
|
217
|
-
* @param {Object} params
|
|
218
|
-
* @returns {Promise<Object>}
|
|
219
|
-
*/
|
|
220
|
-
async function pollTaskCompletion(taskId, token, params) {
|
|
221
|
-
const startTime = Date.now();
|
|
222
|
-
const maxWaitMs = params.maxWaitMs;
|
|
223
|
-
const pollInterval = 5000;
|
|
224
|
-
|
|
225
|
-
while (Date.now() - startTime < maxWaitMs) {
|
|
226
|
-
// Refresh token for each poll
|
|
227
|
-
const freshToken = generateJWT(params.accessKey, params.secretKey);
|
|
228
|
-
|
|
229
|
-
const response = await fetch(`${params.baseUrl}/v1/videos/advanced-lip-sync/${taskId}`, {
|
|
230
|
-
method: 'GET',
|
|
231
|
-
headers: { 'Authorization': `Bearer ${freshToken}` },
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
if (!response.ok) {
|
|
235
|
-
const errorText = await response.text();
|
|
236
|
-
throw new Error(`Kling poll error: ${response.status} - ${errorText}`);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const result = await response.json();
|
|
240
|
-
if (result.code !== 0) {
|
|
241
|
-
throw new Error(`Kling API error: ${result.code} - ${result.message}`);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
const status = result.data?.task_status;
|
|
245
|
-
|
|
246
|
-
if (status === 'succeed') {
|
|
247
|
-
return result.data;
|
|
248
|
-
}
|
|
249
|
-
if (status === 'failed') {
|
|
250
|
-
throw new Error(`Lipsync task failed: ${result.data?.task_status_msg || 'Unknown error'}`);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
await new Promise(resolve => setTimeout(resolve, pollInterval));
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
throw new Error(`Lipsync task timed out after ${maxWaitMs / 1000}s`);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Download result video
|
|
261
|
-
* @param {string} videoUrl
|
|
262
|
-
* @param {string} outputPath
|
|
263
|
-
* @returns {Promise<string>}
|
|
264
|
-
*/
|
|
265
|
-
async function downloadResult(videoUrl, outputPath) {
|
|
266
|
-
const response = await fetch(videoUrl);
|
|
267
|
-
if (!response.ok) {
|
|
268
|
-
throw new Error(`Failed to download video: ${response.status}`);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
const buffer = await response.arrayBuffer();
|
|
272
|
-
await writeFile(outputPath, Buffer.from(buffer));
|
|
273
|
-
return outputPath;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// --- Audio Utilities ---
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Extract audio clip using FFmpeg
|
|
280
|
-
* @param {string} audioPath
|
|
281
|
-
* @param {number} startTime
|
|
282
|
-
* @param {number} endTime
|
|
283
|
-
* @param {string} outputPath
|
|
284
|
-
* @returns {string}
|
|
285
|
-
*/
|
|
286
|
-
function extractAudioClip(audioPath, startTime, endTime, outputPath) {
|
|
287
|
-
if (existsSync(outputPath)) return outputPath;
|
|
288
|
-
|
|
289
|
-
const duration = endTime - startTime;
|
|
290
|
-
const cmd = `ffmpeg -y -i "${path.resolve(audioPath)}" -ss ${startTime.toFixed(3)} -t ${duration.toFixed(3)} ` +
|
|
291
|
-
`-c:a libmp3lame -q:a 2 "${outputPath}" 2>/dev/null`;
|
|
292
|
-
|
|
293
|
-
execSync(cmd, { stdio: 'pipe' });
|
|
294
|
-
return outputPath;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Convert audio file to base64 data URI
|
|
299
|
-
* @param {string} audioPath
|
|
300
|
-
* @returns {Promise<string>}
|
|
301
|
-
*/
|
|
302
|
-
async function audioToBase64(audioPath) {
|
|
303
|
-
const buffer = await readFile(path.resolve(audioPath));
|
|
304
|
-
return `data:audio/mpeg;base64,${buffer.toString('base64')}`;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// --- High-level pipeline ---
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* Process single segment: extract audio → identify face → create task → poll → download
|
|
311
|
-
* @param {Object} inputs
|
|
312
|
-
* @param {Object} params
|
|
313
|
-
* @returns {Promise<Object>}
|
|
314
|
-
*/
|
|
315
|
-
async function processSegment(inputs, params) {
|
|
316
|
-
const { startTime, endTime, segmentId, outputDir, accessKey, secretKey, baseUrl } = params;
|
|
317
|
-
|
|
318
|
-
const lipsyncDir = path.join(outputDir, 'lipsync-videos');
|
|
319
|
-
const clipsDir = path.join(outputDir, 'audio-clips');
|
|
320
|
-
await mkdir(lipsyncDir, { recursive: true });
|
|
321
|
-
await mkdir(clipsDir, { recursive: true });
|
|
322
|
-
|
|
323
|
-
const outputPath = path.join(lipsyncDir, `${segmentId}.mp4`);
|
|
324
|
-
if (existsSync(outputPath)) {
|
|
325
|
-
return { videoPath: outputPath, cached: true };
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
// 1. Extract audio clip
|
|
329
|
-
const clipPath = path.join(clipsDir, `${segmentId}.mp3`);
|
|
330
|
-
extractAudioClip(inputs.audioPath, startTime, endTime, clipPath);
|
|
331
|
-
const audioDurationMs = Math.round((endTime - startTime) * 1000);
|
|
332
|
-
|
|
333
|
-
// 2. Convert to base64
|
|
334
|
-
const audioBase64 = await audioToBase64(clipPath);
|
|
335
|
-
|
|
336
|
-
// 3. Identify face
|
|
337
|
-
let token = generateJWT(accessKey, secretKey);
|
|
338
|
-
const faceData = await identifyFace(inputs.videoUrl, token, baseUrl);
|
|
339
|
-
|
|
340
|
-
if (!faceData.face_data || faceData.face_data.length === 0) {
|
|
341
|
-
throw new Error('No face detected in video');
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
const face = faceData.face_data[0];
|
|
345
|
-
|
|
346
|
-
// 4. Create task
|
|
347
|
-
token = generateJWT(accessKey, secretKey);
|
|
348
|
-
const task = await createLipsyncTask(
|
|
349
|
-
faceData.session_id,
|
|
350
|
-
face.face_id,
|
|
351
|
-
audioBase64,
|
|
352
|
-
audioDurationMs,
|
|
353
|
-
face.start_time || 0,
|
|
354
|
-
token,
|
|
355
|
-
baseUrl,
|
|
356
|
-
);
|
|
357
|
-
|
|
358
|
-
// 5. Poll
|
|
359
|
-
const result = await pollTaskCompletion(task.task_id, token, params);
|
|
360
|
-
|
|
361
|
-
// 6. Download
|
|
362
|
-
const resultVideoUrl = result.task_result?.videos?.[0]?.url;
|
|
363
|
-
if (!resultVideoUrl) {
|
|
364
|
-
throw new Error('No video URL in task result');
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
await downloadResult(resultVideoUrl, outputPath);
|
|
368
|
-
return { videoPath: outputPath, taskId: task.task_id, cached: false };
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* Process batch of segments with concurrency
|
|
373
|
-
* @param {Object} inputs
|
|
374
|
-
* @param {Object} params
|
|
375
|
-
* @returns {Promise<Map>}
|
|
376
|
-
*/
|
|
377
|
-
async function processBatch(inputs, params) {
|
|
378
|
-
const segments = params.segments;
|
|
379
|
-
const videoMap = params.videoMap || {};
|
|
380
|
-
const concurrency = params.concurrency;
|
|
381
|
-
const results = new Map();
|
|
382
|
-
|
|
383
|
-
for (let i = 0; i < segments.length; i += concurrency) {
|
|
384
|
-
const batch = segments.slice(i, i + concurrency);
|
|
385
|
-
|
|
386
|
-
const batchResults = await Promise.allSettled(
|
|
387
|
-
batch.map(async (segment) => {
|
|
388
|
-
const videoUrl = videoMap[segment.promptId];
|
|
389
|
-
if (!videoUrl) return null;
|
|
390
|
-
|
|
391
|
-
const segParams = {
|
|
392
|
-
...params,
|
|
393
|
-
segmentId: segment.promptId,
|
|
394
|
-
startTime: segment.start,
|
|
395
|
-
endTime: segment.end,
|
|
396
|
-
};
|
|
397
|
-
|
|
398
|
-
const result = await processSegment(
|
|
399
|
-
{ videoUrl, audioPath: inputs.audioPath },
|
|
400
|
-
segParams,
|
|
401
|
-
);
|
|
402
|
-
return { promptId: segment.promptId, ...result };
|
|
403
|
-
})
|
|
404
|
-
);
|
|
405
|
-
|
|
406
|
-
for (const result of batchResults) {
|
|
407
|
-
if (result.status === 'fulfilled' && result.value) {
|
|
408
|
-
results.set(result.value.promptId, result.value.videoPath);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
return results;
|
|
414
|
-
}
|