forked from lightningpixel/modly
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmockExtensions.ts
More file actions
89 lines (82 loc) · 3.12 KB
/
Copy pathmockExtensions.ts
File metadata and controls
89 lines (82 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import type { ModelExtension, ProcessExtension } from '@shared/stores/extensionsStore'
export type { ParamSchema } from '@shared/types/electron.d'
import type { ParamSchema } from '@shared/types/electron.d'
export interface WorkflowExtension {
id: string // "ext_id/node_id"
extensionId: string // "ext_id" (for IPC calls)
extensionName: string // display name of the parent extension
extensionAuthor: string // author of the parent extension
nodeId: string // "node_id"
name: string
description: string
input: 'image' | 'text' | 'mesh' | 'audio'
inputs?: ('image' | 'text' | 'mesh' | 'audio')[] // multi-input; overrides input when set
inputLabels?: string[] // display labels per input slot
output: 'image' | 'text' | 'mesh' | 'audio'
params: ParamSchema[]
builtin: boolean
type: 'model' | 'process'
}
function applyParamDefaults(
schema: ParamSchema[],
defaults: Record<string, number | string> | undefined,
): ParamSchema[] {
if (!defaults || Object.keys(defaults).length === 0) return schema
return schema.map((p) =>
Object.prototype.hasOwnProperty.call(defaults, p.id)
? { ...p, default: defaults[p.id]! }
: p,
)
}
export function buildAllWorkflowExtensions(
modelExtensions: ModelExtension[],
processExtensions: ProcessExtension[],
): WorkflowExtension[] {
const result: WorkflowExtension[] = []
for (const ext of processExtensions) {
if (ext.corrupted) continue
for (const node of ext.nodes) {
result.push({
id: `${ext.id}/${node.id}`,
extensionId: ext.id,
extensionName: ext.name,
extensionAuthor: ext.author ?? '',
nodeId: node.id,
name: node.name,
description: ext.description ?? '',
input: node.input,
inputs: node.inputs,
inputLabels: node.inputLabels,
output: node.output,
params: applyParamDefaults(node.paramsSchema as ParamSchema[], node.paramDefaults),
builtin: ext.builtin,
type: 'process',
})
}
}
for (const ext of modelExtensions) {
if (ext.corrupted) continue
for (const node of ext.nodes) {
result.push({
id: `${ext.id}/${node.id}`,
extensionId: ext.id,
extensionName: ext.name,
extensionAuthor: ext.author ?? '',
nodeId: node.id,
name: node.name,
description: ext.description ?? '',
input: node.input,
inputs: node.inputs,
inputLabels: node.inputLabels,
output: node.output,
params: applyParamDefaults(node.paramsSchema as ParamSchema[], node.paramDefaults),
builtin: ext.builtin,
type: 'model',
})
}
}
return result
}
export function getWorkflowExtension(id: string, all: WorkflowExtension[]): WorkflowExtension | undefined {
return all.find((e) => e.id === id)
}