project-graph-mcp 2.3.1 → 2.3.2
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 +1 -1
- package/vendor/symbiote-node/engine/AgentUICommands.js +100 -0
- package/vendor/symbiote-node/engine/Executor.js +371 -0
- package/vendor/symbiote-node/engine/Graph.js +314 -0
- package/vendor/symbiote-node/engine/GraphServer.js +353 -0
- package/vendor/symbiote-node/engine/HandlerLoader.js +145 -0
- package/vendor/symbiote-node/engine/History.js +83 -0
- package/vendor/symbiote-node/engine/Lifecycle.js +118 -0
- package/vendor/symbiote-node/engine/Persistence.js +84 -0
- package/vendor/symbiote-node/engine/Registry.js +264 -0
- package/vendor/symbiote-node/engine/SocketTypes.js +79 -0
- package/vendor/symbiote-node/engine/cli.js +404 -0
- package/vendor/symbiote-node/engine/index.js +56 -0
- package/vendor/symbiote-node/engine/nanoid.js +28 -0
- package/vendor/symbiote-node/engine/package.json +26 -0
- package/vendor/symbiote-node/engine/packs/ai/beat-detect.handler.js +215 -0
- package/vendor/symbiote-node/engine/packs/ai/content-adapt.handler.js +238 -0
- package/vendor/symbiote-node/engine/packs/ai/face-detect.handler.js +287 -0
- package/vendor/symbiote-node/engine/packs/ai/grok-generate.handler.js +565 -0
- package/vendor/symbiote-node/engine/packs/ai/kling-lipsync.handler.js +414 -0
- package/vendor/symbiote-node/engine/packs/ai/lesson-generate.handler.js +343 -0
- package/vendor/symbiote-node/engine/packs/ai/opencode.handler.js +164 -0
- package/vendor/symbiote-node/engine/packs/ai/replicate-lipsync.handler.js +341 -0
- package/vendor/symbiote-node/engine/packs/ai/tts.handler.js +241 -0
- package/vendor/symbiote-node/engine/packs/ai/whisper.handler.js +191 -0
- package/vendor/symbiote-node/engine/packs/data/db-query.handler.js +67 -0
- package/vendor/symbiote-node/engine/packs/data/news-accumulate.handler.js +281 -0
- package/vendor/symbiote-node/engine/packs/data/personas.handler.js +160 -0
- package/vendor/symbiote-node/engine/packs/data/prompt-loader.handler.js +193 -0
- package/vendor/symbiote-node/engine/packs/data/roles.handler.js +216 -0
- package/vendor/symbiote-node/engine/packs/data/rss-feed.handler.js +244 -0
- package/vendor/symbiote-node/engine/packs/debug/inject.handler.js +52 -0
- package/vendor/symbiote-node/engine/packs/flow/agent.handler.js +73 -0
- package/vendor/symbiote-node/engine/packs/flow/if.handler.js +107 -0
- package/vendor/symbiote-node/engine/packs/flow/loop.handler.js +58 -0
- package/vendor/symbiote-node/engine/packs/flow/merge.handler.js +60 -0
- package/vendor/symbiote-node/engine/packs/flow/retry.handler.js +65 -0
- package/vendor/symbiote-node/engine/packs/flow/switch.handler.js +64 -0
- package/vendor/symbiote-node/engine/packs/flow/wait-all.handler.js +39 -0
- package/vendor/symbiote-node/engine/packs/io/http-request.handler.js +82 -0
- package/vendor/symbiote-node/engine/packs/io/read-file.handler.js +60 -0
- package/vendor/symbiote-node/engine/packs/io/write-file.handler.js +63 -0
- package/vendor/symbiote-node/engine/packs/transform/anchor-match.handler.js +494 -0
- package/vendor/symbiote-node/engine/packs/transform/effects-skeleton.handler.js +417 -0
- package/vendor/symbiote-node/engine/packs/transform/json-parse.handler.js +43 -0
- package/vendor/symbiote-node/engine/packs/transform/lipsync-select.handler.js +339 -0
- package/vendor/symbiote-node/engine/packs/transform/riopla-adapt.handler.js +432 -0
- package/vendor/symbiote-node/engine/packs/transform/set.handler.js +57 -0
- package/vendor/symbiote-node/engine/packs/transform/template-builder.handler.js +134 -0
- package/vendor/symbiote-node/engine/packs/transform/template.handler.js +79 -0
- package/vendor/symbiote-node/engine/packs/transform/timeline-build.handler.js +399 -0
- package/vendor/symbiote-node/engine/packs/util/delay.handler.js +39 -0
- package/vendor/symbiote-node/engine/packs/util/log.handler.js +44 -0
- package/vendor/symbiote-node/engine/packs/video-pack.js +323 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* transform/lipsync-select — AI-based segment selection + face detection validation
|
|
3
|
+
*
|
|
4
|
+
* Analyzes segments to determine which need lip-sync animation:
|
|
5
|
+
* - AI analysis: evaluates lyrics sections for lipsync importance
|
|
6
|
+
* - Face validation: checks face coverage in source video metadata
|
|
7
|
+
* - Mouth positions: extracts mouth coordinates for speech bubbles
|
|
8
|
+
*
|
|
9
|
+
* Ported from Mr-Computer/modules/ai-music-video/src/services/lipsync-selector.js
|
|
10
|
+
*
|
|
11
|
+
* @module agi-graph/packs/transform/lipsync-select
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
type: 'transform/lipsync-select',
|
|
16
|
+
category: 'transform',
|
|
17
|
+
icon: 'face_retouching_natural',
|
|
18
|
+
|
|
19
|
+
driver: {
|
|
20
|
+
description: 'AI-based lipsync segment selection + face detection validation',
|
|
21
|
+
inputs: [
|
|
22
|
+
{ name: 'segments', type: 'any' },
|
|
23
|
+
{ name: 'lyrics', type: 'string' },
|
|
24
|
+
],
|
|
25
|
+
outputs: [
|
|
26
|
+
{ name: 'result', type: 'any' },
|
|
27
|
+
{ name: 'stats', type: 'any' },
|
|
28
|
+
{ name: 'error', type: 'string' },
|
|
29
|
+
],
|
|
30
|
+
params: {
|
|
31
|
+
operation: { type: 'string', default: 'select', description: 'Operation: select | analyze | apply | mouth-positions' },
|
|
32
|
+
apiKey: { type: 'string', default: '', description: 'OpenRouter API key' },
|
|
33
|
+
model: { type: 'string', default: 'deepseek/deepseek-v3.2', description: 'AI model' },
|
|
34
|
+
apiBaseUrl: { type: 'string', default: 'https://openrouter.ai/api/v1', description: 'API base URL' },
|
|
35
|
+
minFaceCoverage: { type: 'number', default: 8, description: 'Minimum face coverage % for lipsync' },
|
|
36
|
+
selectedSegments: { type: 'any', default: null, description: 'For apply: selected segments array' },
|
|
37
|
+
mouthPositions: { type: 'any', default: null, description: 'For apply: mouth positions map' },
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
lifecycle: {
|
|
42
|
+
validate: (inputs) => {
|
|
43
|
+
if (!inputs.segments || !Array.isArray(inputs.segments)) return false;
|
|
44
|
+
return true;
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
cacheKey: (inputs, params) => {
|
|
48
|
+
return `lipsync-sel:${params.operation}:${inputs.segments.length}`;
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
execute: async (inputs, params) => {
|
|
52
|
+
try {
|
|
53
|
+
const op = params.operation;
|
|
54
|
+
const segments = inputs.segments;
|
|
55
|
+
|
|
56
|
+
if (op === 'analyze') {
|
|
57
|
+
if (!params.apiKey) {
|
|
58
|
+
return { result: null, stats: null, error: 'apiKey is required for AI analysis' };
|
|
59
|
+
}
|
|
60
|
+
const analyzed = await analyzeWithAI(segments, inputs.lyrics, params);
|
|
61
|
+
const lipsyncCount = analyzed.filter(s => s.isLipSync).length;
|
|
62
|
+
return {
|
|
63
|
+
result: analyzed,
|
|
64
|
+
stats: { total: segments.length, lipsyncMarked: lipsyncCount },
|
|
65
|
+
error: null,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (op === 'select') {
|
|
70
|
+
const { selectedSegments, stats } = selectLipsyncSegments(segments, params);
|
|
71
|
+
return { result: selectedSegments, stats, error: null };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (op === 'apply') {
|
|
75
|
+
const selected = params.selectedSegments || [];
|
|
76
|
+
const mouthPos = params.mouthPositions || {};
|
|
77
|
+
const applied = applySelection(segments, selected, mouthPos);
|
|
78
|
+
return {
|
|
79
|
+
result: applied,
|
|
80
|
+
stats: { total: applied.length, lipsync: applied.filter(s => s.isLipSync).length },
|
|
81
|
+
error: null,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return { result: null, stats: null, error: `Unknown operation: ${op}` };
|
|
86
|
+
} catch (err) {
|
|
87
|
+
return { result: null, stats: null, error: err.message };
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// --- Core selection logic (ported from lipsync-selector.js) ---
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Select lipsync segments based on face detection metadata
|
|
97
|
+
* Takes ONLY segments already marked isLipSync=true, removes those failing face detection
|
|
98
|
+
* @param {Array} segments
|
|
99
|
+
* @param {Object} params
|
|
100
|
+
* @returns {{selectedSegments: Array, stats: Object}}
|
|
101
|
+
*/
|
|
102
|
+
function selectLipsyncSegments(segments, params) {
|
|
103
|
+
const minFaceCoverage = params.minFaceCoverage;
|
|
104
|
+
|
|
105
|
+
const stats = {
|
|
106
|
+
total: segments.length,
|
|
107
|
+
markedForLipsync: 0,
|
|
108
|
+
filteredByFace: 0,
|
|
109
|
+
selected: 0,
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const lipsyncMarked = segments.filter(seg => seg.isLipSync === true);
|
|
113
|
+
stats.markedForLipsync = lipsyncMarked.length;
|
|
114
|
+
|
|
115
|
+
if (lipsyncMarked.length === 0) {
|
|
116
|
+
return { selectedSegments: [], stats };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const selected = [];
|
|
120
|
+
|
|
121
|
+
for (const seg of lipsyncMarked) {
|
|
122
|
+
let hasFace = false;
|
|
123
|
+
let faceCoverage = 0;
|
|
124
|
+
|
|
125
|
+
// Check faceTracking data in segment or source metadata
|
|
126
|
+
const faceTracking = seg.faceTracking || seg.sourceMetadata?.faceTracking;
|
|
127
|
+
|
|
128
|
+
if (faceTracking) {
|
|
129
|
+
if (faceTracking.maxCoverage) {
|
|
130
|
+
faceCoverage = faceTracking.maxCoverage;
|
|
131
|
+
hasFace = faceCoverage >= minFaceCoverage;
|
|
132
|
+
} else if (faceTracking.positions?.length > 0) {
|
|
133
|
+
let maxCov = 0;
|
|
134
|
+
for (const frame of faceTracking.positions) {
|
|
135
|
+
if (frame.faces?.length > 0) {
|
|
136
|
+
for (const face of frame.faces) {
|
|
137
|
+
if (face.bboxRel) {
|
|
138
|
+
const coverage = (face.bboxRel.width || 0) * 100;
|
|
139
|
+
if (coverage > maxCov) maxCov = coverage;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
faceCoverage = Math.round(maxCov);
|
|
145
|
+
hasFace = faceCoverage >= minFaceCoverage;
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
// No face tracking data — include anyway
|
|
149
|
+
hasFace = true;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (hasFace) {
|
|
153
|
+
selected.push({
|
|
154
|
+
...seg,
|
|
155
|
+
faceStats: { maxCoverage: faceCoverage, avgCoverage: faceCoverage },
|
|
156
|
+
});
|
|
157
|
+
} else {
|
|
158
|
+
stats.filteredByFace++;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
stats.selected = selected.length;
|
|
163
|
+
return { selectedSegments: selected, stats };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Apply lipsync selection to segments — sets isLipSync + useBubble flags
|
|
168
|
+
* @param {Array} segments
|
|
169
|
+
* @param {Array} selectedSegments
|
|
170
|
+
* @param {Object} mouthPositions - {promptId: {mouthPosition: {x,y}}}
|
|
171
|
+
* @returns {Array}
|
|
172
|
+
*/
|
|
173
|
+
function applySelection(segments, selectedSegments, mouthPositions = {}) {
|
|
174
|
+
const selectedIds = new Set(selectedSegments.map(s => s.promptId || s.id));
|
|
175
|
+
|
|
176
|
+
return segments.map(seg => {
|
|
177
|
+
const id = seg.promptId || seg.id;
|
|
178
|
+
const isLipSync = selectedIds.has(id);
|
|
179
|
+
const mouthData = mouthPositions[id];
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
...seg,
|
|
183
|
+
isLipSync,
|
|
184
|
+
wasOriginallyLipSync: seg.isLipSync,
|
|
185
|
+
useBubble: !isLipSync && !!mouthData,
|
|
186
|
+
mouthPosition: mouthData?.mouthPosition || null,
|
|
187
|
+
};
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Analyze segments with AI to determine lipsync importance
|
|
193
|
+
* @param {Array} segments
|
|
194
|
+
* @param {string} lyrics
|
|
195
|
+
* @param {Object} params
|
|
196
|
+
* @returns {Promise<Array>}
|
|
197
|
+
*/
|
|
198
|
+
async function analyzeWithAI(segments, lyrics, params) {
|
|
199
|
+
const segmentSummary = segments.map((seg, idx) => ({
|
|
200
|
+
idx,
|
|
201
|
+
id: seg.id || seg.promptId,
|
|
202
|
+
text: seg.text || '',
|
|
203
|
+
section: seg.section || 'Unknown',
|
|
204
|
+
start: seg.start?.toFixed(1) || '?',
|
|
205
|
+
end: seg.end?.toFixed(1) || '?',
|
|
206
|
+
}));
|
|
207
|
+
|
|
208
|
+
const prompt = buildAnalysisPrompt(lyrics, segmentSummary);
|
|
209
|
+
const response = await callAI(prompt, params);
|
|
210
|
+
return parseAIResponse(response, segments);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Build AI prompt for lipsync analysis
|
|
215
|
+
* @param {string} lyrics
|
|
216
|
+
* @param {Array} segmentSummary
|
|
217
|
+
* @returns {string}
|
|
218
|
+
*/
|
|
219
|
+
function buildAnalysisPrompt(lyrics, segmentSummary) {
|
|
220
|
+
const segmentsList = segmentSummary.map(s =>
|
|
221
|
+
`[${s.idx}] ${s.id} | ${s.section} | ${s.start}-${s.end}s | "${s.text.substring(0, 60)}${s.text.length > 60 ? '...' : ''}"`
|
|
222
|
+
).join('\n');
|
|
223
|
+
|
|
224
|
+
return `You are a music video director analyzing which segments need LIPSYNC (mouth animation synced to vocals).
|
|
225
|
+
|
|
226
|
+
## Original Song Lyrics:
|
|
227
|
+
\`\`\`
|
|
228
|
+
${lyrics}
|
|
229
|
+
\`\`\`
|
|
230
|
+
|
|
231
|
+
## Segments to analyze:
|
|
232
|
+
\`\`\`
|
|
233
|
+
${segmentsList}
|
|
234
|
+
\`\`\`
|
|
235
|
+
|
|
236
|
+
## Your Task:
|
|
237
|
+
Analyze each segment and decide if it needs LIPSYNC based on:
|
|
238
|
+
|
|
239
|
+
1. **LIPSYNC = TRUE** for:
|
|
240
|
+
- Main vocal verses (actual singing with words)
|
|
241
|
+
- Choruses with clear articulated words
|
|
242
|
+
- Bridges with lyrics
|
|
243
|
+
- Any segment where mouth movement matches specific words
|
|
244
|
+
|
|
245
|
+
2. **LIPSYNC = FALSE** for:
|
|
246
|
+
- Sound effects (Oo-ee-ee-ah, WUB WUB, etc.)
|
|
247
|
+
- Vocalizations without clear words
|
|
248
|
+
- Instrumental sections
|
|
249
|
+
- Stage directions in parentheses like (Deep Voice), (Spin!)
|
|
250
|
+
- Short exclamations like "¡Miau!", "Meow!"
|
|
251
|
+
- Repetitive hooks that are more sound than lyrics
|
|
252
|
+
|
|
253
|
+
## Output Format (JSON):
|
|
254
|
+
{
|
|
255
|
+
"analysis": [
|
|
256
|
+
{"idx": 0, "lipsync": true, "reason": "Main verse with clear lyrics"},
|
|
257
|
+
{"idx": 1, "lipsync": false, "reason": "Vocalization, not words"},
|
|
258
|
+
...
|
|
259
|
+
]
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
Return ONLY valid JSON. Include ALL ${segmentSummary.length} segments.`;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Call OpenRouter AI API
|
|
267
|
+
* @param {string} prompt
|
|
268
|
+
* @param {Object} params
|
|
269
|
+
* @returns {Promise<string>}
|
|
270
|
+
*/
|
|
271
|
+
async function callAI(prompt, params) {
|
|
272
|
+
const controller = new AbortController();
|
|
273
|
+
const timeoutId = setTimeout(() => controller.abort(), 60000);
|
|
274
|
+
|
|
275
|
+
try {
|
|
276
|
+
const response = await fetch(`${params.apiBaseUrl}/chat/completions`, {
|
|
277
|
+
method: 'POST',
|
|
278
|
+
headers: {
|
|
279
|
+
'Content-Type': 'application/json',
|
|
280
|
+
'Authorization': `Bearer ${params.apiKey}`,
|
|
281
|
+
'HTTP-Referer': 'https://symbiote-video.local',
|
|
282
|
+
'X-Title': 'Symbiote Video - Lipsync Selector',
|
|
283
|
+
},
|
|
284
|
+
body: JSON.stringify({
|
|
285
|
+
model: params.model,
|
|
286
|
+
messages: [{ role: 'user', content: prompt }],
|
|
287
|
+
temperature: 0,
|
|
288
|
+
max_tokens: 8192,
|
|
289
|
+
}),
|
|
290
|
+
signal: controller.signal,
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
clearTimeout(timeoutId);
|
|
294
|
+
|
|
295
|
+
if (!response.ok) {
|
|
296
|
+
const error = await response.text();
|
|
297
|
+
throw new Error(`API error ${response.status}: ${error}`);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const data = await response.json();
|
|
301
|
+
return data.choices[0].message.content;
|
|
302
|
+
} catch (error) {
|
|
303
|
+
clearTimeout(timeoutId);
|
|
304
|
+
throw error;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Parse AI response and apply to segments
|
|
310
|
+
* @param {string} response
|
|
311
|
+
* @param {Array} segments
|
|
312
|
+
* @returns {Array}
|
|
313
|
+
*/
|
|
314
|
+
function parseAIResponse(response, segments) {
|
|
315
|
+
const jsonMatch = response.match(/\{[\s\S]*\}/);
|
|
316
|
+
if (!jsonMatch) {
|
|
317
|
+
throw new Error('No JSON found in AI response');
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const parsed = JSON.parse(jsonMatch[0]);
|
|
321
|
+
const analysis = parsed.analysis || [];
|
|
322
|
+
|
|
323
|
+
const lipsyncMap = new Map();
|
|
324
|
+
for (const item of analysis) {
|
|
325
|
+
lipsyncMap.set(item.idx, {
|
|
326
|
+
isLipSync: item.lipsync === true,
|
|
327
|
+
lipsyncReason: item.reason || '',
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return segments.map((seg, idx) => {
|
|
332
|
+
const aiDecision = lipsyncMap.get(idx);
|
|
333
|
+
return {
|
|
334
|
+
...seg,
|
|
335
|
+
isLipSync: aiDecision?.isLipSync ?? false,
|
|
336
|
+
lipsyncReason: aiDecision?.lipsyncReason || 'Not analyzed',
|
|
337
|
+
};
|
|
338
|
+
});
|
|
339
|
+
}
|