@nodetool-ai/integration-nodes 0.8.1
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/README.md +68 -0
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/nodes/comfy-cloud.d.ts +55 -0
- package/dist/nodes/comfy-cloud.d.ts.map +1 -0
- package/dist/nodes/comfy-cloud.js +147 -0
- package/dist/nodes/comfy-cloud.js.map +1 -0
- package/dist/nodes/comfy-sdk.d.ts +158 -0
- package/dist/nodes/comfy-sdk.d.ts.map +1 -0
- package/dist/nodes/comfy-sdk.js +441 -0
- package/dist/nodes/comfy-sdk.js.map +1 -0
- package/dist/nodes/comfy.d.ts +140 -0
- package/dist/nodes/comfy.d.ts.map +1 -0
- package/dist/nodes/comfy.js +723 -0
- package/dist/nodes/comfy.js.map +1 -0
- package/dist/nodes/kie-dynamic.d.ts +28 -0
- package/dist/nodes/kie-dynamic.d.ts.map +1 -0
- package/dist/nodes/kie-dynamic.js +777 -0
- package/dist/nodes/kie-dynamic.js.map +1 -0
- package/dist/nodes/messaging.d.ts +165 -0
- package/dist/nodes/messaging.d.ts.map +1 -0
- package/dist/nodes/messaging.js +208 -0
- package/dist/nodes/messaging.js.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +1,777 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Dynamic Kie.ai node that creates inputs/outputs from pasted API documentation.
|
|
9
|
+
*/
|
|
10
|
+
import * as yaml from "js-yaml";
|
|
11
|
+
import { BaseNode, prop } from "@nodetool-ai/node-sdk";
|
|
12
|
+
import { getApiKey, isRefSet, kieExecuteTask, kieExecuteOmniDirect, kieImageRef, reportKieProviderCost, uploadAudioInput, uploadImageInput, uploadVideoInput, buildVideoClipsFromRefs } from "@nodetool-ai/kie-nodes";
|
|
13
|
+
import { tagAsServer } from "@nodetool-ai/nodes-utils";
|
|
14
|
+
const OMNI_VIDEO_SUPPLEMENTS = [
|
|
15
|
+
{
|
|
16
|
+
name: "duration",
|
|
17
|
+
type: "string",
|
|
18
|
+
required: true,
|
|
19
|
+
description: "Generated video duration in seconds (4, 6, 8, or 10).",
|
|
20
|
+
default: "8",
|
|
21
|
+
options: ["4", "6", "8", "10"],
|
|
22
|
+
isFileUrl: false,
|
|
23
|
+
isFileUrlArray: false,
|
|
24
|
+
isVideoClipList: false,
|
|
25
|
+
acceptedFileTypes: []
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: "audio_ids",
|
|
29
|
+
type: "array",
|
|
30
|
+
required: false,
|
|
31
|
+
description: "Audio IDs from gemini-omni-audio for narration or dialogue.",
|
|
32
|
+
isFileUrl: false,
|
|
33
|
+
isFileUrlArray: false,
|
|
34
|
+
isVideoClipList: false,
|
|
35
|
+
acceptedFileTypes: []
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "character_ids",
|
|
39
|
+
type: "array",
|
|
40
|
+
required: false,
|
|
41
|
+
description: "Character IDs from gemini-omni-character.",
|
|
42
|
+
isFileUrl: false,
|
|
43
|
+
isFileUrlArray: false,
|
|
44
|
+
isVideoClipList: false,
|
|
45
|
+
acceptedFileTypes: []
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "video_list",
|
|
49
|
+
type: "array",
|
|
50
|
+
required: false,
|
|
51
|
+
description: "Source video clips with trim ranges for video editing.",
|
|
52
|
+
isFileUrl: false,
|
|
53
|
+
isFileUrlArray: true,
|
|
54
|
+
isVideoClipList: true,
|
|
55
|
+
acceptedFileTypes: []
|
|
56
|
+
}
|
|
57
|
+
];
|
|
58
|
+
const HIDDEN_PARAMS = new Set(["upload_method", "callBackUrl", "callback_url"]);
|
|
59
|
+
function asRecord(value) {
|
|
60
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
61
|
+
? value
|
|
62
|
+
: undefined;
|
|
63
|
+
}
|
|
64
|
+
function asStringArray(value) {
|
|
65
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string")
|
|
66
|
+
? value
|
|
67
|
+
: undefined;
|
|
68
|
+
}
|
|
69
|
+
function cleanDescription(value) {
|
|
70
|
+
if (typeof value !== "string") {
|
|
71
|
+
return "";
|
|
72
|
+
}
|
|
73
|
+
return value.replace(/\s+/g, " ").trim();
|
|
74
|
+
}
|
|
75
|
+
function extractModelId(text) {
|
|
76
|
+
let m = text.match(/\*\*Format\*\*\s*\|\s*`([^`]+)`/);
|
|
77
|
+
if (m)
|
|
78
|
+
return m[1].trim();
|
|
79
|
+
m = text.match(/[Mm]odel\s+name,?\s*format:\s*`([^`]+)`/);
|
|
80
|
+
if (m)
|
|
81
|
+
return m[1].trim();
|
|
82
|
+
m = text.match(/"model"\s*:\s*"([^"]+)"/);
|
|
83
|
+
if (m)
|
|
84
|
+
return m[1].trim();
|
|
85
|
+
const openApiModel = extractOpenApiModelId(text);
|
|
86
|
+
if (openApiModel)
|
|
87
|
+
return openApiModel;
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
function extractOpenApiModelId(text) {
|
|
91
|
+
const openApi = extractOpenApi(text);
|
|
92
|
+
if (!openApi)
|
|
93
|
+
return null;
|
|
94
|
+
const paths = asRecord(openApi.paths);
|
|
95
|
+
const createTask = asRecord(paths?.["/api/v1/jobs/createTask"]);
|
|
96
|
+
const post = asRecord(createTask?.post);
|
|
97
|
+
const requestBody = asRecord(post?.requestBody);
|
|
98
|
+
const content = asRecord(requestBody?.content);
|
|
99
|
+
const json = asRecord(content?.["application/json"]);
|
|
100
|
+
const schema = asRecord(json?.schema);
|
|
101
|
+
const properties = asRecord(schema?.properties);
|
|
102
|
+
const model = asRecord(properties?.model);
|
|
103
|
+
const enumValues = asStringArray(model?.enum);
|
|
104
|
+
if (enumValues?.[0])
|
|
105
|
+
return enumValues[0];
|
|
106
|
+
return typeof model?.default === "string" ? model.default : null;
|
|
107
|
+
}
|
|
108
|
+
function extractOpenApi(text) {
|
|
109
|
+
const match = text.match(/```ya?ml\s*([\s\S]*?)```/i);
|
|
110
|
+
if (!match)
|
|
111
|
+
return null;
|
|
112
|
+
const parsed = yaml.load(match[1]);
|
|
113
|
+
return asRecord(parsed) ?? null;
|
|
114
|
+
}
|
|
115
|
+
function isVideoClipSchema(schema) {
|
|
116
|
+
const items = asRecord(schema.items);
|
|
117
|
+
if (items?.type !== "object")
|
|
118
|
+
return false;
|
|
119
|
+
const props = asRecord(items.properties);
|
|
120
|
+
return Boolean(props?.url);
|
|
121
|
+
}
|
|
122
|
+
function inferOutputType(modelId, _text) {
|
|
123
|
+
if (modelId === "gemini-omni-audio" || modelId === "gemini-omni-character") {
|
|
124
|
+
return "text";
|
|
125
|
+
}
|
|
126
|
+
const lower = modelId.toLowerCase();
|
|
127
|
+
const videoKws = [
|
|
128
|
+
"video",
|
|
129
|
+
"storyboard",
|
|
130
|
+
"avatar",
|
|
131
|
+
"seedance",
|
|
132
|
+
"kling",
|
|
133
|
+
"hailuo",
|
|
134
|
+
"sora",
|
|
135
|
+
"wan",
|
|
136
|
+
"infinitalk",
|
|
137
|
+
"omni-video"
|
|
138
|
+
];
|
|
139
|
+
if (videoKws.some((kw) => lower.includes(kw)))
|
|
140
|
+
return "video";
|
|
141
|
+
const audioKws = ["music", "suno", "speech", "tts"];
|
|
142
|
+
if (audioKws.some((kw) => lower.includes(kw)))
|
|
143
|
+
return "audio";
|
|
144
|
+
if (lower.includes("audio") && !lower.includes("omni-audio"))
|
|
145
|
+
return "audio";
|
|
146
|
+
return "image";
|
|
147
|
+
}
|
|
148
|
+
function resolveExecutionConfig(modelId) {
|
|
149
|
+
if (modelId === "gemini-omni-audio") {
|
|
150
|
+
return {
|
|
151
|
+
mode: "omniDirect",
|
|
152
|
+
submitEndpoint: "/api/v1/omni/audio/create",
|
|
153
|
+
responseIdKey: "audioId"
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
if (modelId === "gemini-omni-character") {
|
|
157
|
+
return {
|
|
158
|
+
mode: "omniDirect",
|
|
159
|
+
submitEndpoint: "/api/v1/omni/character/create",
|
|
160
|
+
responseIdKey: "characterId"
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
return { mode: "createTask" };
|
|
164
|
+
}
|
|
165
|
+
function supplementOmniParams(modelId, params) {
|
|
166
|
+
if (modelId !== "gemini-omni-video") {
|
|
167
|
+
return params;
|
|
168
|
+
}
|
|
169
|
+
const existing = new Set(params.map((p) => p.name));
|
|
170
|
+
const extras = OMNI_VIDEO_SUPPLEMENTS.filter((p) => !existing.has(p.name));
|
|
171
|
+
return extras.length ? [...params, ...extras] : params;
|
|
172
|
+
}
|
|
173
|
+
function normalizeStringList(value) {
|
|
174
|
+
if (Array.isArray(value)) {
|
|
175
|
+
return value.map(String).filter((item) => item.trim().length > 0);
|
|
176
|
+
}
|
|
177
|
+
if (typeof value === "string" && value.trim()) {
|
|
178
|
+
return [value.trim()];
|
|
179
|
+
}
|
|
180
|
+
return [];
|
|
181
|
+
}
|
|
182
|
+
function parseInputParams(text) {
|
|
183
|
+
const sectionMatch = text.match(/###\s*input\s+Object\s+Parameters(.*?)(?=\n##\s|\n---|$)/is);
|
|
184
|
+
if (!sectionMatch)
|
|
185
|
+
return [];
|
|
186
|
+
const section = sectionMatch[1];
|
|
187
|
+
const blocks = section.split(/\n####\s+/);
|
|
188
|
+
const params = [];
|
|
189
|
+
for (const block of blocks) {
|
|
190
|
+
const trimmed = block.trim();
|
|
191
|
+
if (!trimmed)
|
|
192
|
+
continue;
|
|
193
|
+
const nameMatch = trimmed.match(/^(\w+)/);
|
|
194
|
+
if (!nameMatch)
|
|
195
|
+
continue;
|
|
196
|
+
const name = nameMatch[1];
|
|
197
|
+
if (HIDDEN_PARAMS.has(name))
|
|
198
|
+
continue;
|
|
199
|
+
const typeMatch = trimmed.match(/\*\*Type\*\*:\s*`([^`]+)`/);
|
|
200
|
+
const paramType = typeMatch ? typeMatch[1].trim() : "string";
|
|
201
|
+
const reqMatch = trimmed.match(/\*\*Required\*\*:\s*(Yes|No)/i);
|
|
202
|
+
const required = reqMatch ? reqMatch[1].toLowerCase() === "yes" : false;
|
|
203
|
+
const descMatch = trimmed.match(/\*\*Description\*\*:\s*(.+?)(?=\n\s*-\s*\*\*|$)/s);
|
|
204
|
+
const description = descMatch ? descMatch[1].trim() : "";
|
|
205
|
+
let defaultVal = undefined;
|
|
206
|
+
const defMatch = trimmed.match(/\*\*Default Value\*\*:\s*`([^`]*)`/);
|
|
207
|
+
if (defMatch)
|
|
208
|
+
defaultVal = coerceDefault(defMatch[1], paramType);
|
|
209
|
+
let options;
|
|
210
|
+
const optMatch = trimmed.match(/\*\*Options\*\*:\s*\n((?:\s*-\s*`[^`]+`.*\n?)+)/);
|
|
211
|
+
if (optMatch) {
|
|
212
|
+
options = [...optMatch[1].matchAll(/`([^`]+)`/g)].map((m) => m[1]);
|
|
213
|
+
}
|
|
214
|
+
const bounds = parseBounds(trimmed);
|
|
215
|
+
const minVal = bounds.min;
|
|
216
|
+
const maxVal = bounds.max;
|
|
217
|
+
let isFileUrl = false;
|
|
218
|
+
let isFileUrlArray = false;
|
|
219
|
+
let isVideoClipList = false;
|
|
220
|
+
const acceptedFileTypes = [];
|
|
221
|
+
const ftMatch = trimmed.match(/\*\*Accepted File Types\*\*:\s*(.+)/);
|
|
222
|
+
if (ftMatch)
|
|
223
|
+
acceptedFileTypes.push(...ftMatch[1].split(",").map((t) => t.trim()));
|
|
224
|
+
if (name.endsWith("_ids") && paramType === "array") {
|
|
225
|
+
isFileUrl = false;
|
|
226
|
+
isFileUrlArray = false;
|
|
227
|
+
}
|
|
228
|
+
else if (name === "video_list" && paramType === "array") {
|
|
229
|
+
isFileUrlArray = true;
|
|
230
|
+
isVideoClipList = true;
|
|
231
|
+
}
|
|
232
|
+
else if (acceptedFileTypes.length ||
|
|
233
|
+
description.includes("Upload") ||
|
|
234
|
+
description.includes("URL")) {
|
|
235
|
+
if (paramType === "array")
|
|
236
|
+
isFileUrlArray = true;
|
|
237
|
+
else
|
|
238
|
+
isFileUrl = true;
|
|
239
|
+
}
|
|
240
|
+
if (name.endsWith("_url") && paramType === "string")
|
|
241
|
+
isFileUrl = true;
|
|
242
|
+
if (name.endsWith("_urls") && paramType === "array")
|
|
243
|
+
isFileUrlArray = true;
|
|
244
|
+
params.push({
|
|
245
|
+
name,
|
|
246
|
+
type: paramType,
|
|
247
|
+
required,
|
|
248
|
+
description,
|
|
249
|
+
default: defaultVal,
|
|
250
|
+
options,
|
|
251
|
+
minVal,
|
|
252
|
+
maxVal,
|
|
253
|
+
isFileUrl,
|
|
254
|
+
isFileUrlArray,
|
|
255
|
+
isVideoClipList,
|
|
256
|
+
acceptedFileTypes
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
return params;
|
|
260
|
+
}
|
|
261
|
+
function openApiPropertyToParam(name, schema, required) {
|
|
262
|
+
if (HIDDEN_PARAMS.has(name))
|
|
263
|
+
return null;
|
|
264
|
+
const schemaType = String(schema.type ?? "string");
|
|
265
|
+
const description = cleanDescription(schema.description);
|
|
266
|
+
const enumValues = asStringArray(schema.enum);
|
|
267
|
+
const isArray = schemaType === "array";
|
|
268
|
+
const itemSchema = asRecord(schema.items) ?? {};
|
|
269
|
+
const isUrlArray = isArray &&
|
|
270
|
+
(name.endsWith("_urls") ||
|
|
271
|
+
itemSchema.format === "uri" ||
|
|
272
|
+
description.includes("asset://"));
|
|
273
|
+
const isUrl = schemaType === "string" &&
|
|
274
|
+
(name.endsWith("_url") || schema.format === "uri");
|
|
275
|
+
const isVideoClipList = name === "video_list" || (isArray && isVideoClipSchema(schema));
|
|
276
|
+
const isIdArray = isArray && name.endsWith("_ids");
|
|
277
|
+
const mediaKind = isUrl || isUrlArray || isVideoClipList
|
|
278
|
+
? detectMediaKindFromText(`${name} ${description} ${String(itemSchema.description ?? "")}`)
|
|
279
|
+
: null;
|
|
280
|
+
let paramType = schemaType;
|
|
281
|
+
if (isArray)
|
|
282
|
+
paramType = "array";
|
|
283
|
+
// SAFETY: `schema` is a JSON-decoded OpenAPI schema, so its `default` is a
|
|
284
|
+
// JSON value.
|
|
285
|
+
let defaultVal = schema.default;
|
|
286
|
+
if (defaultVal === undefined && enumValues?.length) {
|
|
287
|
+
defaultVal = enumValues[0];
|
|
288
|
+
}
|
|
289
|
+
let options = enumValues;
|
|
290
|
+
if (isArray && asStringArray(itemSchema.enum)?.length) {
|
|
291
|
+
options = asStringArray(itemSchema.enum);
|
|
292
|
+
}
|
|
293
|
+
const bounds = parseBounds(description);
|
|
294
|
+
let isFileUrl = false;
|
|
295
|
+
let isFileUrlArray = false;
|
|
296
|
+
if (isIdArray) {
|
|
297
|
+
isFileUrl = false;
|
|
298
|
+
isFileUrlArray = false;
|
|
299
|
+
}
|
|
300
|
+
else if (isVideoClipList) {
|
|
301
|
+
isFileUrlArray = true;
|
|
302
|
+
}
|
|
303
|
+
else if (mediaKind && isUrlArray) {
|
|
304
|
+
isFileUrlArray = true;
|
|
305
|
+
}
|
|
306
|
+
else if (mediaKind && isUrl) {
|
|
307
|
+
isFileUrl = true;
|
|
308
|
+
}
|
|
309
|
+
else if (isArray &&
|
|
310
|
+
(name.endsWith("_urls") ||
|
|
311
|
+
description.includes("Upload") ||
|
|
312
|
+
/\bURL\b/i.test(description))) {
|
|
313
|
+
isFileUrlArray = true;
|
|
314
|
+
}
|
|
315
|
+
else if (schemaType === "string" &&
|
|
316
|
+
(name.endsWith("_url") ||
|
|
317
|
+
description.includes("Upload") ||
|
|
318
|
+
/\bURL\b/i.test(description))) {
|
|
319
|
+
isFileUrl = true;
|
|
320
|
+
}
|
|
321
|
+
return {
|
|
322
|
+
name,
|
|
323
|
+
type: paramType,
|
|
324
|
+
required,
|
|
325
|
+
description,
|
|
326
|
+
default: defaultVal,
|
|
327
|
+
options,
|
|
328
|
+
minVal: bounds.min,
|
|
329
|
+
maxVal: bounds.max,
|
|
330
|
+
isFileUrl,
|
|
331
|
+
isFileUrlArray,
|
|
332
|
+
isVideoClipList,
|
|
333
|
+
acceptedFileTypes: []
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
function parseFlatOpenApiParams(text, path) {
|
|
337
|
+
const openApi = extractOpenApi(text);
|
|
338
|
+
if (!openApi)
|
|
339
|
+
return [];
|
|
340
|
+
const paths = asRecord(openApi.paths);
|
|
341
|
+
const post = asRecord(asRecord(paths?.[path])?.post);
|
|
342
|
+
if (!post)
|
|
343
|
+
return [];
|
|
344
|
+
const requestBody = asRecord(post.requestBody);
|
|
345
|
+
const content = asRecord(requestBody?.content);
|
|
346
|
+
const json = asRecord(content?.["application/json"]);
|
|
347
|
+
const schema = asRecord(json?.schema);
|
|
348
|
+
const properties = asRecord(schema?.properties);
|
|
349
|
+
if (!properties)
|
|
350
|
+
return [];
|
|
351
|
+
const requiredFields = new Set(asStringArray(schema?.required) ?? []);
|
|
352
|
+
const params = [];
|
|
353
|
+
for (const [name, rawSchema] of Object.entries(properties)) {
|
|
354
|
+
const param = openApiPropertyToParam(name, asRecord(rawSchema) ?? {}, requiredFields.has(name));
|
|
355
|
+
if (param)
|
|
356
|
+
params.push(param);
|
|
357
|
+
}
|
|
358
|
+
return params;
|
|
359
|
+
}
|
|
360
|
+
function parseOpenApiInputParams(text, modelId) {
|
|
361
|
+
if (modelId === "gemini-omni-audio") {
|
|
362
|
+
const omni = parseFlatOpenApiParams(text, "/api/v1/omni/audio/create");
|
|
363
|
+
if (omni.length)
|
|
364
|
+
return omni;
|
|
365
|
+
}
|
|
366
|
+
if (modelId === "gemini-omni-character") {
|
|
367
|
+
const omni = parseFlatOpenApiParams(text, "/api/v1/omni/character/create");
|
|
368
|
+
if (omni.length)
|
|
369
|
+
return omni;
|
|
370
|
+
}
|
|
371
|
+
const openApi = extractOpenApi(text);
|
|
372
|
+
if (!openApi)
|
|
373
|
+
return [];
|
|
374
|
+
const paths = asRecord(openApi.paths);
|
|
375
|
+
const createTask = asRecord(paths?.["/api/v1/jobs/createTask"]);
|
|
376
|
+
const post = asRecord(createTask?.post);
|
|
377
|
+
if (!post)
|
|
378
|
+
return [];
|
|
379
|
+
const requestBody = asRecord(post.requestBody);
|
|
380
|
+
const content = asRecord(requestBody?.content);
|
|
381
|
+
const json = asRecord(content?.["application/json"]);
|
|
382
|
+
const schema = asRecord(json?.schema);
|
|
383
|
+
const properties = asRecord(schema?.properties);
|
|
384
|
+
const inputSchema = asRecord(properties?.input);
|
|
385
|
+
const inputProperties = asRecord(inputSchema?.properties);
|
|
386
|
+
if (!inputProperties)
|
|
387
|
+
return [];
|
|
388
|
+
const requiredFields = new Set(asStringArray(inputSchema?.required) ?? []);
|
|
389
|
+
const params = [];
|
|
390
|
+
for (const [name, rawSchema] of Object.entries(inputProperties)) {
|
|
391
|
+
const param = openApiPropertyToParam(name, asRecord(rawSchema) ?? {}, requiredFields.has(name));
|
|
392
|
+
if (param)
|
|
393
|
+
params.push(param);
|
|
394
|
+
}
|
|
395
|
+
return params;
|
|
396
|
+
}
|
|
397
|
+
function mergeKieParams(markdownParams, openApiParams) {
|
|
398
|
+
const merged = new Map();
|
|
399
|
+
for (const param of openApiParams) {
|
|
400
|
+
merged.set(param.name, param);
|
|
401
|
+
}
|
|
402
|
+
for (const param of markdownParams) {
|
|
403
|
+
const existing = merged.get(param.name);
|
|
404
|
+
if (!existing) {
|
|
405
|
+
merged.set(param.name, param);
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
merged.set(param.name, {
|
|
409
|
+
...existing,
|
|
410
|
+
...param,
|
|
411
|
+
description: param.description || existing.description,
|
|
412
|
+
options: param.options?.length ? param.options : existing.options,
|
|
413
|
+
acceptedFileTypes: param.acceptedFileTypes.length
|
|
414
|
+
? param.acceptedFileTypes
|
|
415
|
+
: existing.acceptedFileTypes,
|
|
416
|
+
isVideoClipList: param.isVideoClipList || existing.isVideoClipList,
|
|
417
|
+
isFileUrlArray: param.isFileUrlArray || existing.isFileUrlArray,
|
|
418
|
+
isFileUrl: param.isFileUrl || existing.isFileUrl
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
return [...merged.values()];
|
|
422
|
+
}
|
|
423
|
+
function coerceDefault(raw, paramType) {
|
|
424
|
+
if (paramType === "integer") {
|
|
425
|
+
const n = parseInt(raw, 10);
|
|
426
|
+
return isNaN(n) ? raw : n;
|
|
427
|
+
}
|
|
428
|
+
if (paramType === "number") {
|
|
429
|
+
const n = parseFloat(raw);
|
|
430
|
+
return isNaN(n) ? raw : n;
|
|
431
|
+
}
|
|
432
|
+
if (paramType === "boolean")
|
|
433
|
+
return ["true", "1", "yes"].includes(raw.toLowerCase());
|
|
434
|
+
try {
|
|
435
|
+
return JSON.parse(raw);
|
|
436
|
+
}
|
|
437
|
+
catch {
|
|
438
|
+
return raw;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
function parseBounds(text) {
|
|
442
|
+
const rangeMatch = text.match(/\*\*Range\*\*:\s*`?(-?\d+(?:\.\d+)?)`?\s*(?:to|-|~)\s*`?(-?\d+(?:\.\d+)?)`?/i);
|
|
443
|
+
if (rangeMatch) {
|
|
444
|
+
return { min: Number(rangeMatch[1]), max: Number(rangeMatch[2]) };
|
|
445
|
+
}
|
|
446
|
+
const minLengthMatch = text.match(/\*\*Min(?:imum)? Length\*\*:\s*`?(-?\d+(?:\.\d+)?)`?/i);
|
|
447
|
+
const maxLengthMatch = text.match(/\*\*Max(?:imum)? Length\*\*:\s*`?(-?\d+(?:\.\d+)?)`?/i);
|
|
448
|
+
const minMatch = text.match(/\bMinimum:\s*(-?\d+(?:\.\d+)?)/i);
|
|
449
|
+
const maxMatch = text.match(/\bMaximum:\s*(-?\d+(?:\.\d+)?)/i);
|
|
450
|
+
const bounds = {};
|
|
451
|
+
if (minLengthMatch || minMatch) {
|
|
452
|
+
bounds.min = Number((minLengthMatch ?? minMatch)[1]);
|
|
453
|
+
}
|
|
454
|
+
if (maxLengthMatch || maxMatch) {
|
|
455
|
+
bounds.max = Number((maxLengthMatch ?? maxMatch)[1]);
|
|
456
|
+
}
|
|
457
|
+
return bounds;
|
|
458
|
+
}
|
|
459
|
+
function detectMediaKindFromText(text) {
|
|
460
|
+
const firstToken = text.split(/\s+/)[0]?.toLowerCase() ?? "";
|
|
461
|
+
if (/^image_urls?$|^images?$/.test(firstToken))
|
|
462
|
+
return "image";
|
|
463
|
+
if (/^video_urls?$|^video_list$/.test(firstToken))
|
|
464
|
+
return "video";
|
|
465
|
+
if (/^audio_urls?$/.test(firstToken))
|
|
466
|
+
return "audio";
|
|
467
|
+
const joined = text.toLowerCase();
|
|
468
|
+
if (joined.includes("image/"))
|
|
469
|
+
return "image";
|
|
470
|
+
if (joined.includes("audio/"))
|
|
471
|
+
return "audio";
|
|
472
|
+
if (joined.includes("video/"))
|
|
473
|
+
return "video";
|
|
474
|
+
if (/\bimage\b|jpeg|jpg|png|webp|gif|bmp/.test(joined))
|
|
475
|
+
return "image";
|
|
476
|
+
if (/\baudio\b|mp3|wav|aac|ogg|mpeg/.test(joined))
|
|
477
|
+
return "audio";
|
|
478
|
+
if (/\bvideo\b|mp4|mov|quicktime|matroska|mkv/.test(joined))
|
|
479
|
+
return "video";
|
|
480
|
+
return null;
|
|
481
|
+
}
|
|
482
|
+
function detectMediaKind(param) {
|
|
483
|
+
if (param.isVideoClipList)
|
|
484
|
+
return "video";
|
|
485
|
+
return detectMediaKindFromText(`${param.name} ${param.description} ${param.acceptedFileTypes.join(",")}`);
|
|
486
|
+
}
|
|
487
|
+
function fieldNameForParam(param) {
|
|
488
|
+
const kind = detectMediaKind(param) ?? "image";
|
|
489
|
+
if (param.isVideoClipList) {
|
|
490
|
+
return param.name;
|
|
491
|
+
}
|
|
492
|
+
if (param.isFileUrlArray) {
|
|
493
|
+
if (param.name === "input_urls")
|
|
494
|
+
return `${kind}s`;
|
|
495
|
+
if (param.name.endsWith(`_${kind}_urls`)) {
|
|
496
|
+
return `${param.name.slice(0, -`${kind}_urls`.length)}${kind}s`;
|
|
497
|
+
}
|
|
498
|
+
if (param.name === `${kind}_urls`)
|
|
499
|
+
return `${kind}s`;
|
|
500
|
+
return param.name.replace(/_urls$/, "s");
|
|
501
|
+
}
|
|
502
|
+
if (param.isFileUrl) {
|
|
503
|
+
return param.name.replace(/_url$/, "");
|
|
504
|
+
}
|
|
505
|
+
return param.name;
|
|
506
|
+
}
|
|
507
|
+
function mapParamType(param) {
|
|
508
|
+
if (param.isVideoClipList) {
|
|
509
|
+
const listType = {
|
|
510
|
+
type: "list",
|
|
511
|
+
type_args: [{ type: "video", type_args: [] }]
|
|
512
|
+
};
|
|
513
|
+
if (param.minVal !== undefined) {
|
|
514
|
+
listType.min = param.minVal;
|
|
515
|
+
}
|
|
516
|
+
if (param.maxVal !== undefined) {
|
|
517
|
+
listType.max = param.maxVal;
|
|
518
|
+
}
|
|
519
|
+
return listType;
|
|
520
|
+
}
|
|
521
|
+
if (param.name.endsWith("_ids") && param.type === "array") {
|
|
522
|
+
return { type: "list", type_args: [{ type: "str", type_args: [] }] };
|
|
523
|
+
}
|
|
524
|
+
if (param.isFileUrlArray) {
|
|
525
|
+
const kind = detectMediaKind(param) ?? "image";
|
|
526
|
+
return { type: "list", type_args: [{ type: kind, type_args: [] }] };
|
|
527
|
+
}
|
|
528
|
+
if (param.isFileUrl) {
|
|
529
|
+
const kind = detectMediaKind(param) ?? "image";
|
|
530
|
+
return { type: kind, type_args: [] };
|
|
531
|
+
}
|
|
532
|
+
switch (param.type) {
|
|
533
|
+
case "string": {
|
|
534
|
+
const strType = { type: "str", type_args: [] };
|
|
535
|
+
if (param.options?.length) {
|
|
536
|
+
strType.values = param.options;
|
|
537
|
+
}
|
|
538
|
+
return strType;
|
|
539
|
+
}
|
|
540
|
+
case "boolean":
|
|
541
|
+
return { type: "bool", type_args: [] };
|
|
542
|
+
case "integer":
|
|
543
|
+
return { type: "int", type_args: [] };
|
|
544
|
+
case "number":
|
|
545
|
+
return { type: "float", type_args: [] };
|
|
546
|
+
case "array":
|
|
547
|
+
return {
|
|
548
|
+
type: "list",
|
|
549
|
+
type_args: [{ type: "str", type_args: [] }]
|
|
550
|
+
};
|
|
551
|
+
default:
|
|
552
|
+
return { type: "any", type_args: [] };
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
function defaultRefForKind(kind) {
|
|
556
|
+
if (kind === "audio") {
|
|
557
|
+
return {
|
|
558
|
+
type: "audio",
|
|
559
|
+
uri: "",
|
|
560
|
+
asset_id: null,
|
|
561
|
+
data: null,
|
|
562
|
+
metadata: null
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
if (kind === "video") {
|
|
566
|
+
return {
|
|
567
|
+
type: "video",
|
|
568
|
+
uri: "",
|
|
569
|
+
asset_id: null,
|
|
570
|
+
data: null,
|
|
571
|
+
metadata: null,
|
|
572
|
+
duration: null,
|
|
573
|
+
format: null
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
return { type: "image", uri: "", asset_id: null, data: null, metadata: null };
|
|
577
|
+
}
|
|
578
|
+
function defaultDynamicValue(param) {
|
|
579
|
+
if (param.isVideoClipList || param.isFileUrlArray) {
|
|
580
|
+
return [];
|
|
581
|
+
}
|
|
582
|
+
if (param.isFileUrl) {
|
|
583
|
+
return defaultRefForKind(detectMediaKind(param) ?? "image");
|
|
584
|
+
}
|
|
585
|
+
if (param.default !== undefined) {
|
|
586
|
+
return param.default;
|
|
587
|
+
}
|
|
588
|
+
if (param.type === "array") {
|
|
589
|
+
return [];
|
|
590
|
+
}
|
|
591
|
+
if (param.type === "string") {
|
|
592
|
+
return "";
|
|
593
|
+
}
|
|
594
|
+
if (param.type === "boolean") {
|
|
595
|
+
return false;
|
|
596
|
+
}
|
|
597
|
+
return null;
|
|
598
|
+
}
|
|
599
|
+
function mapOutputType(outputType) {
|
|
600
|
+
if (outputType === "text") {
|
|
601
|
+
return { type: "str", type_args: [], optional: false };
|
|
602
|
+
}
|
|
603
|
+
if (outputType === "video") {
|
|
604
|
+
return { type: "video", type_args: [], optional: false };
|
|
605
|
+
}
|
|
606
|
+
if (outputType === "audio") {
|
|
607
|
+
return { type: "audio", type_args: [], optional: false };
|
|
608
|
+
}
|
|
609
|
+
return { type: "image", type_args: [], optional: false };
|
|
610
|
+
}
|
|
611
|
+
function parseKieDocs(text) {
|
|
612
|
+
const modelId = extractModelId(text);
|
|
613
|
+
if (!modelId)
|
|
614
|
+
throw new Error("Could not find model ID in documentation");
|
|
615
|
+
const params = supplementOmniParams(modelId, mergeKieParams(parseInputParams(text), parseOpenApiInputParams(text, modelId)));
|
|
616
|
+
return {
|
|
617
|
+
modelId,
|
|
618
|
+
params,
|
|
619
|
+
outputType: inferOutputType(modelId, text),
|
|
620
|
+
execution: resolveExecutionConfig(modelId)
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
export function resolveKieDynamicSchema(modelInfo) {
|
|
624
|
+
const bundle = parseKieDocs(modelInfo);
|
|
625
|
+
const dynamic_properties = {};
|
|
626
|
+
const dynamic_inputs = {};
|
|
627
|
+
for (const param of bundle.params) {
|
|
628
|
+
const fieldName = fieldNameForParam(param);
|
|
629
|
+
dynamic_properties[fieldName] = defaultDynamicValue(param);
|
|
630
|
+
const slot = {
|
|
631
|
+
...mapParamType(param),
|
|
632
|
+
optional: !param.required
|
|
633
|
+
};
|
|
634
|
+
if (param.description) {
|
|
635
|
+
slot.description = param.description;
|
|
636
|
+
}
|
|
637
|
+
if (param.minVal !== undefined) {
|
|
638
|
+
slot.min = param.minVal;
|
|
639
|
+
}
|
|
640
|
+
if (param.maxVal !== undefined) {
|
|
641
|
+
slot.max = param.maxVal;
|
|
642
|
+
}
|
|
643
|
+
if (param.default !== undefined &&
|
|
644
|
+
!param.isFileUrl &&
|
|
645
|
+
!param.isFileUrlArray) {
|
|
646
|
+
slot.default = param.default;
|
|
647
|
+
}
|
|
648
|
+
dynamic_inputs[fieldName] = slot;
|
|
649
|
+
}
|
|
650
|
+
const outputName = bundle.outputType === "video"
|
|
651
|
+
? "video"
|
|
652
|
+
: bundle.outputType === "audio"
|
|
653
|
+
? "audio"
|
|
654
|
+
: bundle.outputType === "text"
|
|
655
|
+
? "output"
|
|
656
|
+
: "image";
|
|
657
|
+
return {
|
|
658
|
+
model_id: bundle.modelId,
|
|
659
|
+
dynamic_properties,
|
|
660
|
+
dynamic_inputs,
|
|
661
|
+
dynamic_outputs: {
|
|
662
|
+
[outputName]: mapOutputType(bundle.outputType)
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
export class KieAINode extends BaseNode {
|
|
667
|
+
static nodeType = "kie.dynamic_schema.KieAI";
|
|
668
|
+
static title = "Kie AI";
|
|
669
|
+
static description = "Dynamic Kie.ai node for running any kie.ai model.\n kie, dynamic, schema, api, inference, runtime, model\n\n Use cases:\n - Call any kie.ai model without a dedicated Python node\n - Prototype workflows with new models as they appear\n - Run models by pasting their API documentation\n - Access the full kie.ai catalog dynamically";
|
|
670
|
+
static inlineFields = ["model_info"];
|
|
671
|
+
static inputFields = [];
|
|
672
|
+
static requiredSettings = ["KIE_API_KEY"];
|
|
673
|
+
static supportsDynamicInputs = true;
|
|
674
|
+
static supportsDynamicOutputs = true;
|
|
675
|
+
async process(context) {
|
|
676
|
+
const modelInfo = this.model_info.trim();
|
|
677
|
+
if (!modelInfo)
|
|
678
|
+
throw new Error("model_info is empty. Paste kie.ai API documentation.");
|
|
679
|
+
const apiKey = getApiKey(this._secrets);
|
|
680
|
+
const bundle = parseKieDocs(modelInfo);
|
|
681
|
+
const apiInput = {};
|
|
682
|
+
// Parameter names come from the pasted kie.ai docs, so which property
|
|
683
|
+
// matches is only known at runtime. This reads the instance itself, not
|
|
684
|
+
// `serialize()`: serialize only emits *declared* properties, and the
|
|
685
|
+
// values assign() puts on a node for an undeclared doc parameter are not
|
|
686
|
+
// among them — routing through it drops every such parameter.
|
|
687
|
+
const self = this;
|
|
688
|
+
for (const p of bundle.params) {
|
|
689
|
+
const fieldName = fieldNameForParam(p);
|
|
690
|
+
const val = this.getDynamic(fieldName) ??
|
|
691
|
+
self[fieldName] ??
|
|
692
|
+
this.getDynamic(p.name) ??
|
|
693
|
+
self[p.name];
|
|
694
|
+
if (val === undefined || val === null) {
|
|
695
|
+
if (p.required)
|
|
696
|
+
throw new Error(`Missing required input: ${fieldName}`);
|
|
697
|
+
continue;
|
|
698
|
+
}
|
|
699
|
+
if (p.isVideoClipList) {
|
|
700
|
+
const clips = await buildVideoClipsFromRefs((ref) => uploadVideoInput(apiKey, ref, context), val);
|
|
701
|
+
if (clips.length)
|
|
702
|
+
apiInput[p.name] = clips;
|
|
703
|
+
}
|
|
704
|
+
else if (p.isFileUrlArray) {
|
|
705
|
+
const kind = detectMediaKind(p) ?? "image";
|
|
706
|
+
const uploadFn = kind === "audio"
|
|
707
|
+
? uploadAudioInput
|
|
708
|
+
: kind === "video"
|
|
709
|
+
? uploadVideoInput
|
|
710
|
+
: uploadImageInput;
|
|
711
|
+
const items = Array.isArray(val) ? val : [];
|
|
712
|
+
const urls = [];
|
|
713
|
+
for (const item of items) {
|
|
714
|
+
if (isRefSet(item)) {
|
|
715
|
+
urls.push(await uploadFn(apiKey, item, context));
|
|
716
|
+
}
|
|
717
|
+
else if (typeof item === "string" && item) {
|
|
718
|
+
urls.push(item);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
if (urls.length)
|
|
722
|
+
apiInput[p.name] = urls;
|
|
723
|
+
}
|
|
724
|
+
else if (p.name.endsWith("_ids") && p.type === "array") {
|
|
725
|
+
const list = normalizeStringList(val);
|
|
726
|
+
if (list.length)
|
|
727
|
+
apiInput[p.name] = list;
|
|
728
|
+
}
|
|
729
|
+
else if (p.isFileUrl) {
|
|
730
|
+
const kind = detectMediaKind(p) ?? "image";
|
|
731
|
+
const uploadFn = kind === "audio"
|
|
732
|
+
? uploadAudioInput
|
|
733
|
+
: kind === "video"
|
|
734
|
+
? uploadVideoInput
|
|
735
|
+
: uploadImageInput;
|
|
736
|
+
if (isRefSet(val)) {
|
|
737
|
+
apiInput[p.name] = await uploadFn(apiKey, val, context);
|
|
738
|
+
}
|
|
739
|
+
else if (typeof val === "string" && val) {
|
|
740
|
+
apiInput[p.name] = val;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
else {
|
|
744
|
+
apiInput[p.name] = val;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
let result;
|
|
748
|
+
if (bundle.execution.mode === "omniDirect") {
|
|
749
|
+
if (!bundle.execution.submitEndpoint || !bundle.execution.responseIdKey) {
|
|
750
|
+
throw new Error(`Omni model ${bundle.modelId} is missing direct endpoint config`);
|
|
751
|
+
}
|
|
752
|
+
result = await kieExecuteOmniDirect(apiKey, bundle.execution.submitEndpoint, apiInput, bundle.execution.responseIdKey, context?.signal);
|
|
753
|
+
}
|
|
754
|
+
else {
|
|
755
|
+
result = await kieExecuteTask(apiKey, bundle.modelId, apiInput, 2000, 300, undefined, undefined, undefined, context?.signal);
|
|
756
|
+
}
|
|
757
|
+
reportKieProviderCost(context, result.creditsConsumed);
|
|
758
|
+
if (bundle.outputType === "text") {
|
|
759
|
+
return { output: result.data };
|
|
760
|
+
}
|
|
761
|
+
if (bundle.outputType === "video")
|
|
762
|
+
return { video: { type: "video", uri: "", data: result.data } };
|
|
763
|
+
if (bundle.outputType === "audio")
|
|
764
|
+
return { audio: { type: "audio", uri: "", data: result.data } };
|
|
765
|
+
return { image: await kieImageRef(result.data) };
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
__decorate([
|
|
769
|
+
prop({
|
|
770
|
+
type: "str",
|
|
771
|
+
default: "",
|
|
772
|
+
title: "Model Info",
|
|
773
|
+
description: "Paste the full API documentation from the kie.ai model page."
|
|
774
|
+
})
|
|
775
|
+
], KieAINode.prototype, "model_info", void 0);
|
|
776
|
+
export const KIE_DYNAMIC_NODES = tagAsServer([KieAINode]);
|
|
777
|
+
//# sourceMappingURL=kie-dynamic.js.map
|