@lokvis/schema 0.1.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/dist/asset.d.ts +86 -0
- package/dist/asset.d.ts.map +1 -0
- package/dist/asset.js +8 -0
- package/dist/asset.js.map +1 -0
- package/dist/capability.d.ts +91 -0
- package/dist/capability.d.ts.map +1 -0
- package/dist/capability.js +8 -0
- package/dist/capability.js.map +1 -0
- package/dist/event.d.ts +90 -0
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js +7 -0
- package/dist/event.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp.d.ts +43 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +11 -0
- package/dist/mcp.js.map +1 -0
- package/dist/plugin.d.ts +87 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +7 -0
- package/dist/plugin.js.map +1 -0
- package/dist/validators.d.ts +393 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +83 -0
- package/dist/validators.js.map +1 -0
- package/dist/workflow.d.ts +138 -0
- package/dist/workflow.d.ts.map +1 -0
- package/dist/workflow.js +64 -0
- package/dist/workflow.js.map +1 -0
- package/package.json +46 -0
- package/src/asset.ts +88 -0
- package/src/capability.ts +111 -0
- package/src/event.ts +71 -0
- package/src/index.ts +22 -0
- package/src/mcp.ts +45 -0
- package/src/plugin.ts +102 -0
- package/src/validators.ts +94 -0
- package/src/workflow.ts +212 -0
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lokvis Schema Zod Validators
|
|
3
|
+
*
|
|
4
|
+
* 提供 Workflow / Asset / Plugin 的运行时校验。
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
export declare const assetTypeSchema: z.ZodEnum<["image", "video", "audio", "pdf", "text", "data", "unknown"]>;
|
|
8
|
+
export declare const assetMetadataSchema: z.ZodObject<{
|
|
9
|
+
mimeType: z.ZodString;
|
|
10
|
+
size: z.ZodNumber;
|
|
11
|
+
dimensions: z.ZodOptional<z.ZodObject<{
|
|
12
|
+
width: z.ZodNumber;
|
|
13
|
+
height: z.ZodNumber;
|
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
}, {
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
}>>;
|
|
21
|
+
duration: z.ZodOptional<z.ZodNumber>;
|
|
22
|
+
pages: z.ZodOptional<z.ZodNumber>;
|
|
23
|
+
format: z.ZodString;
|
|
24
|
+
}, "strip", z.ZodTypeAny, {
|
|
25
|
+
mimeType: string;
|
|
26
|
+
size: number;
|
|
27
|
+
format: string;
|
|
28
|
+
dimensions?: {
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
} | undefined;
|
|
32
|
+
duration?: number | undefined;
|
|
33
|
+
pages?: number | undefined;
|
|
34
|
+
}, {
|
|
35
|
+
mimeType: string;
|
|
36
|
+
size: number;
|
|
37
|
+
format: string;
|
|
38
|
+
dimensions?: {
|
|
39
|
+
width: number;
|
|
40
|
+
height: number;
|
|
41
|
+
} | undefined;
|
|
42
|
+
duration?: number | undefined;
|
|
43
|
+
pages?: number | undefined;
|
|
44
|
+
}>;
|
|
45
|
+
export declare const workflowNodeSchema: z.ZodEffects<z.ZodObject<{
|
|
46
|
+
id: z.ZodString;
|
|
47
|
+
type: z.ZodEnum<["load", "transform", "export"]>;
|
|
48
|
+
capability: z.ZodOptional<z.ZodString>;
|
|
49
|
+
params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
50
|
+
label: z.ZodOptional<z.ZodString>;
|
|
51
|
+
}, "strip", z.ZodTypeAny, {
|
|
52
|
+
type: "load" | "transform" | "export";
|
|
53
|
+
id: string;
|
|
54
|
+
params?: Record<string, unknown> | undefined;
|
|
55
|
+
capability?: string | undefined;
|
|
56
|
+
label?: string | undefined;
|
|
57
|
+
}, {
|
|
58
|
+
type: "load" | "transform" | "export";
|
|
59
|
+
id: string;
|
|
60
|
+
params?: Record<string, unknown> | undefined;
|
|
61
|
+
capability?: string | undefined;
|
|
62
|
+
label?: string | undefined;
|
|
63
|
+
}>, {
|
|
64
|
+
type: "load" | "transform" | "export";
|
|
65
|
+
id: string;
|
|
66
|
+
params?: Record<string, unknown> | undefined;
|
|
67
|
+
capability?: string | undefined;
|
|
68
|
+
label?: string | undefined;
|
|
69
|
+
}, {
|
|
70
|
+
type: "load" | "transform" | "export";
|
|
71
|
+
id: string;
|
|
72
|
+
params?: Record<string, unknown> | undefined;
|
|
73
|
+
capability?: string | undefined;
|
|
74
|
+
label?: string | undefined;
|
|
75
|
+
}>;
|
|
76
|
+
export declare const workflowEdgeSchema: z.ZodObject<{
|
|
77
|
+
from: z.ZodString;
|
|
78
|
+
to: z.ZodString;
|
|
79
|
+
}, "strip", z.ZodTypeAny, {
|
|
80
|
+
from: string;
|
|
81
|
+
to: string;
|
|
82
|
+
}, {
|
|
83
|
+
from: string;
|
|
84
|
+
to: string;
|
|
85
|
+
}>;
|
|
86
|
+
export declare const workflowSchema: z.ZodObject<{
|
|
87
|
+
$schema: z.ZodOptional<z.ZodString>;
|
|
88
|
+
id: z.ZodString;
|
|
89
|
+
version: z.ZodString;
|
|
90
|
+
name: z.ZodString;
|
|
91
|
+
description: z.ZodString;
|
|
92
|
+
author: z.ZodObject<{
|
|
93
|
+
id: z.ZodString;
|
|
94
|
+
name: z.ZodString;
|
|
95
|
+
}, "strip", z.ZodTypeAny, {
|
|
96
|
+
id: string;
|
|
97
|
+
name: string;
|
|
98
|
+
}, {
|
|
99
|
+
id: string;
|
|
100
|
+
name: string;
|
|
101
|
+
}>;
|
|
102
|
+
category: z.ZodString;
|
|
103
|
+
tags: z.ZodArray<z.ZodString, "many">;
|
|
104
|
+
nodes: z.ZodArray<z.ZodEffects<z.ZodObject<{
|
|
105
|
+
id: z.ZodString;
|
|
106
|
+
type: z.ZodEnum<["load", "transform", "export"]>;
|
|
107
|
+
capability: z.ZodOptional<z.ZodString>;
|
|
108
|
+
params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
109
|
+
label: z.ZodOptional<z.ZodString>;
|
|
110
|
+
}, "strip", z.ZodTypeAny, {
|
|
111
|
+
type: "load" | "transform" | "export";
|
|
112
|
+
id: string;
|
|
113
|
+
params?: Record<string, unknown> | undefined;
|
|
114
|
+
capability?: string | undefined;
|
|
115
|
+
label?: string | undefined;
|
|
116
|
+
}, {
|
|
117
|
+
type: "load" | "transform" | "export";
|
|
118
|
+
id: string;
|
|
119
|
+
params?: Record<string, unknown> | undefined;
|
|
120
|
+
capability?: string | undefined;
|
|
121
|
+
label?: string | undefined;
|
|
122
|
+
}>, {
|
|
123
|
+
type: "load" | "transform" | "export";
|
|
124
|
+
id: string;
|
|
125
|
+
params?: Record<string, unknown> | undefined;
|
|
126
|
+
capability?: string | undefined;
|
|
127
|
+
label?: string | undefined;
|
|
128
|
+
}, {
|
|
129
|
+
type: "load" | "transform" | "export";
|
|
130
|
+
id: string;
|
|
131
|
+
params?: Record<string, unknown> | undefined;
|
|
132
|
+
capability?: string | undefined;
|
|
133
|
+
label?: string | undefined;
|
|
134
|
+
}>, "many">;
|
|
135
|
+
edges: z.ZodArray<z.ZodObject<{
|
|
136
|
+
from: z.ZodString;
|
|
137
|
+
to: z.ZodString;
|
|
138
|
+
}, "strip", z.ZodTypeAny, {
|
|
139
|
+
from: string;
|
|
140
|
+
to: string;
|
|
141
|
+
}, {
|
|
142
|
+
from: string;
|
|
143
|
+
to: string;
|
|
144
|
+
}>, "many">;
|
|
145
|
+
inputs: z.ZodObject<{
|
|
146
|
+
type: z.ZodEnum<["image", "video", "audio", "pdf", "text", "data", "unknown"]>;
|
|
147
|
+
multiple: z.ZodBoolean;
|
|
148
|
+
maxCount: z.ZodOptional<z.ZodNumber>;
|
|
149
|
+
accept: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
150
|
+
}, "strip", z.ZodTypeAny, {
|
|
151
|
+
type: "image" | "video" | "audio" | "pdf" | "text" | "data" | "unknown";
|
|
152
|
+
multiple: boolean;
|
|
153
|
+
maxCount?: number | undefined;
|
|
154
|
+
accept?: string[] | undefined;
|
|
155
|
+
}, {
|
|
156
|
+
type: "image" | "video" | "audio" | "pdf" | "text" | "data" | "unknown";
|
|
157
|
+
multiple: boolean;
|
|
158
|
+
maxCount?: number | undefined;
|
|
159
|
+
accept?: string[] | undefined;
|
|
160
|
+
}>;
|
|
161
|
+
outputs: z.ZodObject<{
|
|
162
|
+
type: z.ZodEnum<["image", "video", "audio", "pdf", "text", "data", "unknown", "archive"]>;
|
|
163
|
+
format: z.ZodOptional<z.ZodString>;
|
|
164
|
+
}, "strip", z.ZodTypeAny, {
|
|
165
|
+
type: "image" | "video" | "audio" | "pdf" | "text" | "data" | "unknown" | "archive";
|
|
166
|
+
format?: string | undefined;
|
|
167
|
+
}, {
|
|
168
|
+
type: "image" | "video" | "audio" | "pdf" | "text" | "data" | "unknown" | "archive";
|
|
169
|
+
format?: string | undefined;
|
|
170
|
+
}>;
|
|
171
|
+
official: z.ZodOptional<z.ZodBoolean>;
|
|
172
|
+
createdAt: z.ZodOptional<z.ZodNumber>;
|
|
173
|
+
updatedAt: z.ZodOptional<z.ZodNumber>;
|
|
174
|
+
}, "strip", z.ZodTypeAny, {
|
|
175
|
+
id: string;
|
|
176
|
+
version: string;
|
|
177
|
+
name: string;
|
|
178
|
+
description: string;
|
|
179
|
+
author: {
|
|
180
|
+
id: string;
|
|
181
|
+
name: string;
|
|
182
|
+
};
|
|
183
|
+
category: string;
|
|
184
|
+
tags: string[];
|
|
185
|
+
nodes: {
|
|
186
|
+
type: "load" | "transform" | "export";
|
|
187
|
+
id: string;
|
|
188
|
+
params?: Record<string, unknown> | undefined;
|
|
189
|
+
capability?: string | undefined;
|
|
190
|
+
label?: string | undefined;
|
|
191
|
+
}[];
|
|
192
|
+
edges: {
|
|
193
|
+
from: string;
|
|
194
|
+
to: string;
|
|
195
|
+
}[];
|
|
196
|
+
inputs: {
|
|
197
|
+
type: "image" | "video" | "audio" | "pdf" | "text" | "data" | "unknown";
|
|
198
|
+
multiple: boolean;
|
|
199
|
+
maxCount?: number | undefined;
|
|
200
|
+
accept?: string[] | undefined;
|
|
201
|
+
};
|
|
202
|
+
outputs: {
|
|
203
|
+
type: "image" | "video" | "audio" | "pdf" | "text" | "data" | "unknown" | "archive";
|
|
204
|
+
format?: string | undefined;
|
|
205
|
+
};
|
|
206
|
+
$schema?: string | undefined;
|
|
207
|
+
official?: boolean | undefined;
|
|
208
|
+
createdAt?: number | undefined;
|
|
209
|
+
updatedAt?: number | undefined;
|
|
210
|
+
}, {
|
|
211
|
+
id: string;
|
|
212
|
+
version: string;
|
|
213
|
+
name: string;
|
|
214
|
+
description: string;
|
|
215
|
+
author: {
|
|
216
|
+
id: string;
|
|
217
|
+
name: string;
|
|
218
|
+
};
|
|
219
|
+
category: string;
|
|
220
|
+
tags: string[];
|
|
221
|
+
nodes: {
|
|
222
|
+
type: "load" | "transform" | "export";
|
|
223
|
+
id: string;
|
|
224
|
+
params?: Record<string, unknown> | undefined;
|
|
225
|
+
capability?: string | undefined;
|
|
226
|
+
label?: string | undefined;
|
|
227
|
+
}[];
|
|
228
|
+
edges: {
|
|
229
|
+
from: string;
|
|
230
|
+
to: string;
|
|
231
|
+
}[];
|
|
232
|
+
inputs: {
|
|
233
|
+
type: "image" | "video" | "audio" | "pdf" | "text" | "data" | "unknown";
|
|
234
|
+
multiple: boolean;
|
|
235
|
+
maxCount?: number | undefined;
|
|
236
|
+
accept?: string[] | undefined;
|
|
237
|
+
};
|
|
238
|
+
outputs: {
|
|
239
|
+
type: "image" | "video" | "audio" | "pdf" | "text" | "data" | "unknown" | "archive";
|
|
240
|
+
format?: string | undefined;
|
|
241
|
+
};
|
|
242
|
+
$schema?: string | undefined;
|
|
243
|
+
official?: boolean | undefined;
|
|
244
|
+
createdAt?: number | undefined;
|
|
245
|
+
updatedAt?: number | undefined;
|
|
246
|
+
}>;
|
|
247
|
+
export declare const pluginManifestSchema: z.ZodObject<{
|
|
248
|
+
name: z.ZodString;
|
|
249
|
+
version: z.ZodString;
|
|
250
|
+
description: z.ZodString;
|
|
251
|
+
author: z.ZodString;
|
|
252
|
+
license: z.ZodString;
|
|
253
|
+
main: z.ZodString;
|
|
254
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
255
|
+
capabilities: z.ZodArray<z.ZodString, "many">;
|
|
256
|
+
engines: z.ZodObject<{
|
|
257
|
+
'lokvis-runtime': z.ZodString;
|
|
258
|
+
}, "strip", z.ZodTypeAny, {
|
|
259
|
+
'lokvis-runtime': string;
|
|
260
|
+
}, {
|
|
261
|
+
'lokvis-runtime': string;
|
|
262
|
+
}>;
|
|
263
|
+
permissions: z.ZodArray<z.ZodString, "many">;
|
|
264
|
+
}, "strip", z.ZodTypeAny, {
|
|
265
|
+
version: string;
|
|
266
|
+
name: string;
|
|
267
|
+
description: string;
|
|
268
|
+
author: string;
|
|
269
|
+
license: string;
|
|
270
|
+
main: string;
|
|
271
|
+
capabilities: string[];
|
|
272
|
+
engines: {
|
|
273
|
+
'lokvis-runtime': string;
|
|
274
|
+
};
|
|
275
|
+
permissions: string[];
|
|
276
|
+
icon?: string | undefined;
|
|
277
|
+
}, {
|
|
278
|
+
version: string;
|
|
279
|
+
name: string;
|
|
280
|
+
description: string;
|
|
281
|
+
author: string;
|
|
282
|
+
license: string;
|
|
283
|
+
main: string;
|
|
284
|
+
capabilities: string[];
|
|
285
|
+
engines: {
|
|
286
|
+
'lokvis-runtime': string;
|
|
287
|
+
};
|
|
288
|
+
permissions: string[];
|
|
289
|
+
icon?: string | undefined;
|
|
290
|
+
}>;
|
|
291
|
+
/** 校验 Workflow JSON */
|
|
292
|
+
export declare function validateWorkflow(data: unknown): z.SafeParseReturnType<{
|
|
293
|
+
id: string;
|
|
294
|
+
version: string;
|
|
295
|
+
name: string;
|
|
296
|
+
description: string;
|
|
297
|
+
author: {
|
|
298
|
+
id: string;
|
|
299
|
+
name: string;
|
|
300
|
+
};
|
|
301
|
+
category: string;
|
|
302
|
+
tags: string[];
|
|
303
|
+
nodes: {
|
|
304
|
+
type: "load" | "transform" | "export";
|
|
305
|
+
id: string;
|
|
306
|
+
params?: Record<string, unknown> | undefined;
|
|
307
|
+
capability?: string | undefined;
|
|
308
|
+
label?: string | undefined;
|
|
309
|
+
}[];
|
|
310
|
+
edges: {
|
|
311
|
+
from: string;
|
|
312
|
+
to: string;
|
|
313
|
+
}[];
|
|
314
|
+
inputs: {
|
|
315
|
+
type: "image" | "video" | "audio" | "pdf" | "text" | "data" | "unknown";
|
|
316
|
+
multiple: boolean;
|
|
317
|
+
maxCount?: number | undefined;
|
|
318
|
+
accept?: string[] | undefined;
|
|
319
|
+
};
|
|
320
|
+
outputs: {
|
|
321
|
+
type: "image" | "video" | "audio" | "pdf" | "text" | "data" | "unknown" | "archive";
|
|
322
|
+
format?: string | undefined;
|
|
323
|
+
};
|
|
324
|
+
$schema?: string | undefined;
|
|
325
|
+
official?: boolean | undefined;
|
|
326
|
+
createdAt?: number | undefined;
|
|
327
|
+
updatedAt?: number | undefined;
|
|
328
|
+
}, {
|
|
329
|
+
id: string;
|
|
330
|
+
version: string;
|
|
331
|
+
name: string;
|
|
332
|
+
description: string;
|
|
333
|
+
author: {
|
|
334
|
+
id: string;
|
|
335
|
+
name: string;
|
|
336
|
+
};
|
|
337
|
+
category: string;
|
|
338
|
+
tags: string[];
|
|
339
|
+
nodes: {
|
|
340
|
+
type: "load" | "transform" | "export";
|
|
341
|
+
id: string;
|
|
342
|
+
params?: Record<string, unknown> | undefined;
|
|
343
|
+
capability?: string | undefined;
|
|
344
|
+
label?: string | undefined;
|
|
345
|
+
}[];
|
|
346
|
+
edges: {
|
|
347
|
+
from: string;
|
|
348
|
+
to: string;
|
|
349
|
+
}[];
|
|
350
|
+
inputs: {
|
|
351
|
+
type: "image" | "video" | "audio" | "pdf" | "text" | "data" | "unknown";
|
|
352
|
+
multiple: boolean;
|
|
353
|
+
maxCount?: number | undefined;
|
|
354
|
+
accept?: string[] | undefined;
|
|
355
|
+
};
|
|
356
|
+
outputs: {
|
|
357
|
+
type: "image" | "video" | "audio" | "pdf" | "text" | "data" | "unknown" | "archive";
|
|
358
|
+
format?: string | undefined;
|
|
359
|
+
};
|
|
360
|
+
$schema?: string | undefined;
|
|
361
|
+
official?: boolean | undefined;
|
|
362
|
+
createdAt?: number | undefined;
|
|
363
|
+
updatedAt?: number | undefined;
|
|
364
|
+
}>;
|
|
365
|
+
/** 校验 Plugin Manifest */
|
|
366
|
+
export declare function validatePluginManifest(data: unknown): z.SafeParseReturnType<{
|
|
367
|
+
version: string;
|
|
368
|
+
name: string;
|
|
369
|
+
description: string;
|
|
370
|
+
author: string;
|
|
371
|
+
license: string;
|
|
372
|
+
main: string;
|
|
373
|
+
capabilities: string[];
|
|
374
|
+
engines: {
|
|
375
|
+
'lokvis-runtime': string;
|
|
376
|
+
};
|
|
377
|
+
permissions: string[];
|
|
378
|
+
icon?: string | undefined;
|
|
379
|
+
}, {
|
|
380
|
+
version: string;
|
|
381
|
+
name: string;
|
|
382
|
+
description: string;
|
|
383
|
+
author: string;
|
|
384
|
+
license: string;
|
|
385
|
+
main: string;
|
|
386
|
+
capabilities: string[];
|
|
387
|
+
engines: {
|
|
388
|
+
'lokvis-runtime': string;
|
|
389
|
+
};
|
|
390
|
+
permissions: string[];
|
|
391
|
+
icon?: string | undefined;
|
|
392
|
+
}>;
|
|
393
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,eAAe,0EAQ1B,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAS9B,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAU9B,CAAC;AAEF,eAAO,MAAM,kBAAkB;;;;;;;;;EAG7B,CAAC;AAEH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwBzB,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAW/B,CAAC;AAEH,uBAAuB;AACvB,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAE7C;AAED,yBAAyB;AACzB,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;GAEnD"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lokvis Schema Zod Validators
|
|
3
|
+
*
|
|
4
|
+
* 提供 Workflow / Asset / Plugin 的运行时校验。
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
export const assetTypeSchema = z.enum([
|
|
8
|
+
'image',
|
|
9
|
+
'video',
|
|
10
|
+
'audio',
|
|
11
|
+
'pdf',
|
|
12
|
+
'text',
|
|
13
|
+
'data',
|
|
14
|
+
'unknown',
|
|
15
|
+
]);
|
|
16
|
+
export const assetMetadataSchema = z.object({
|
|
17
|
+
mimeType: z.string(),
|
|
18
|
+
size: z.number().nonnegative(),
|
|
19
|
+
dimensions: z
|
|
20
|
+
.object({ width: z.number().positive(), height: z.number().positive() })
|
|
21
|
+
.optional(),
|
|
22
|
+
duration: z.number().nonnegative().optional(),
|
|
23
|
+
pages: z.number().int().positive().optional(),
|
|
24
|
+
format: z.string(),
|
|
25
|
+
});
|
|
26
|
+
export const workflowNodeSchema = z.object({
|
|
27
|
+
id: z.string(),
|
|
28
|
+
type: z.enum(['load', 'transform', 'export']),
|
|
29
|
+
// capability 仅 transform 节点必填;load/export 可不填
|
|
30
|
+
capability: z.string().optional(),
|
|
31
|
+
params: z.record(z.unknown()).optional(),
|
|
32
|
+
label: z.string().optional(),
|
|
33
|
+
}).refine((node) => node.type !== 'transform' || (typeof node.capability === 'string' && node.capability.length > 0), { message: 'transform 节点必须指定 capability' });
|
|
34
|
+
export const workflowEdgeSchema = z.object({
|
|
35
|
+
from: z.string(),
|
|
36
|
+
to: z.string(),
|
|
37
|
+
});
|
|
38
|
+
export const workflowSchema = z.object({
|
|
39
|
+
$schema: z.string().optional(),
|
|
40
|
+
id: z.string(),
|
|
41
|
+
version: z.string(),
|
|
42
|
+
name: z.string(),
|
|
43
|
+
description: z.string(),
|
|
44
|
+
author: z.object({ id: z.string(), name: z.string() }),
|
|
45
|
+
category: z.string(),
|
|
46
|
+
tags: z.array(z.string()),
|
|
47
|
+
nodes: z.array(workflowNodeSchema),
|
|
48
|
+
edges: z.array(workflowEdgeSchema),
|
|
49
|
+
inputs: z.object({
|
|
50
|
+
type: assetTypeSchema,
|
|
51
|
+
multiple: z.boolean(),
|
|
52
|
+
maxCount: z.number().int().positive().optional(),
|
|
53
|
+
accept: z.array(z.string()).optional(),
|
|
54
|
+
}),
|
|
55
|
+
outputs: z.object({
|
|
56
|
+
type: z.enum(['image', 'video', 'audio', 'pdf', 'text', 'data', 'unknown', 'archive']),
|
|
57
|
+
format: z.string().optional(),
|
|
58
|
+
}),
|
|
59
|
+
official: z.boolean().optional(),
|
|
60
|
+
createdAt: z.number().optional(),
|
|
61
|
+
updatedAt: z.number().optional(),
|
|
62
|
+
});
|
|
63
|
+
export const pluginManifestSchema = z.object({
|
|
64
|
+
name: z.string(),
|
|
65
|
+
version: z.string(),
|
|
66
|
+
description: z.string(),
|
|
67
|
+
author: z.string(),
|
|
68
|
+
license: z.string(),
|
|
69
|
+
main: z.string(),
|
|
70
|
+
icon: z.string().optional(),
|
|
71
|
+
capabilities: z.array(z.string()),
|
|
72
|
+
engines: z.object({ 'lokvis-runtime': z.string() }),
|
|
73
|
+
permissions: z.array(z.string()),
|
|
74
|
+
});
|
|
75
|
+
/** 校验 Workflow JSON */
|
|
76
|
+
export function validateWorkflow(data) {
|
|
77
|
+
return workflowSchema.safeParse(data);
|
|
78
|
+
}
|
|
79
|
+
/** 校验 Plugin Manifest */
|
|
80
|
+
export function validatePluginManifest(data) {
|
|
81
|
+
return pluginManifestSchema.safeParse(data);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,IAAI,CAAC;IACpC,OAAO;IACP,OAAO;IACP,OAAO;IACP,KAAK;IACL,MAAM;IACN,MAAM;IACN,SAAS;CACV,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,WAAW,EAAE;IAC9B,UAAU,EAAE,CAAC;SACV,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC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C,QAAQ,EAAE;IAChC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACjC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;IACvB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IACjC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;IACnD,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;CACjC,CAAC,CAAC;AAEH,uBAAuB;AACvB,MAAM,UAAU,gBAAgB,CAAC,IAAa;IAC5C,OAAO,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACxC,CAAC;AAED,yBAAyB;AACzB,MAAM,UAAU,sBAAsB,CAAC,IAAa;IAClD,OAAO,oBAAoB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lokvis Workflow Schema
|
|
3
|
+
*
|
|
4
|
+
* 第一年只支持 Linear Workflow(线性工作流)。
|
|
5
|
+
* 不支持:Branch / Loop / Condition / Parallel。
|
|
6
|
+
*/
|
|
7
|
+
import type { AssetType } from './asset.js';
|
|
8
|
+
/** Workflow 节点类型 */
|
|
9
|
+
export type NodeType = 'load' | 'transform' | 'export';
|
|
10
|
+
/** Workflow 节点定义 */
|
|
11
|
+
export interface WorkflowNode {
|
|
12
|
+
/** 节点唯一 ID */
|
|
13
|
+
id: string;
|
|
14
|
+
/** 节点类型 */
|
|
15
|
+
type: NodeType;
|
|
16
|
+
/**
|
|
17
|
+
* 引用的能力名,如 `image.resize`。
|
|
18
|
+
* 仅 `type === 'transform'` 时必填;load/export 节点可不填。
|
|
19
|
+
*/
|
|
20
|
+
capability?: string;
|
|
21
|
+
/** 能力参数 */
|
|
22
|
+
params?: Record<string, unknown>;
|
|
23
|
+
/** 节点标签(UI 显示用) */
|
|
24
|
+
label?: string;
|
|
25
|
+
}
|
|
26
|
+
/** Workflow 边定义(第一年只支持线性链) */
|
|
27
|
+
export interface WorkflowEdge {
|
|
28
|
+
from: string;
|
|
29
|
+
to: string;
|
|
30
|
+
}
|
|
31
|
+
/** Workflow 输入定义 */
|
|
32
|
+
export interface WorkflowInput {
|
|
33
|
+
type: AssetType;
|
|
34
|
+
/** 是否允许多个输入 */
|
|
35
|
+
multiple: boolean;
|
|
36
|
+
/** 最大数量(multiple=true 时生效) */
|
|
37
|
+
maxCount?: number;
|
|
38
|
+
/** 文件类型过滤 */
|
|
39
|
+
accept?: string[];
|
|
40
|
+
}
|
|
41
|
+
/** Workflow 输出定义 */
|
|
42
|
+
export interface WorkflowOutput {
|
|
43
|
+
type: AssetType | 'archive';
|
|
44
|
+
format?: string;
|
|
45
|
+
}
|
|
46
|
+
/** Workflow 作者信息 */
|
|
47
|
+
export interface WorkflowAuthor {
|
|
48
|
+
id: string;
|
|
49
|
+
name: string;
|
|
50
|
+
}
|
|
51
|
+
/** Workflow 语义版本 */
|
|
52
|
+
export interface WorkflowVersion {
|
|
53
|
+
/** semver 版本号 */
|
|
54
|
+
version: string;
|
|
55
|
+
/** Schema 版本 */
|
|
56
|
+
schemaVersion: string;
|
|
57
|
+
/** 兼容的最低 Runtime 版本 */
|
|
58
|
+
runtimeVersion: string;
|
|
59
|
+
changelog: string;
|
|
60
|
+
createdAt: number;
|
|
61
|
+
deprecated?: boolean;
|
|
62
|
+
}
|
|
63
|
+
/** Workflow 分类 */
|
|
64
|
+
export type WorkflowCategory = 'image' | 'video' | 'audio' | 'pdf' | 'ai' | 'data' | 'developer' | 'ecommerce' | 'content-creation' | 'other';
|
|
65
|
+
/** 完整 Workflow 定义 */
|
|
66
|
+
export interface Workflow {
|
|
67
|
+
/** Schema URL */
|
|
68
|
+
$schema?: string;
|
|
69
|
+
/** Workflow 唯一 ID */
|
|
70
|
+
id: string;
|
|
71
|
+
/** 版本号 */
|
|
72
|
+
version: string;
|
|
73
|
+
/** 工作流名称 */
|
|
74
|
+
name: string;
|
|
75
|
+
/** 描述 */
|
|
76
|
+
description: string;
|
|
77
|
+
/** 作者 */
|
|
78
|
+
author: WorkflowAuthor;
|
|
79
|
+
/** 分类 */
|
|
80
|
+
category: WorkflowCategory;
|
|
81
|
+
/** 标签 */
|
|
82
|
+
tags: string[];
|
|
83
|
+
/** 节点列表 */
|
|
84
|
+
nodes: WorkflowNode[];
|
|
85
|
+
/** 边列表(线性链) */
|
|
86
|
+
edges: WorkflowEdge[];
|
|
87
|
+
/** 输入定义 */
|
|
88
|
+
inputs: WorkflowInput;
|
|
89
|
+
/** 输出定义 */
|
|
90
|
+
outputs: WorkflowOutput;
|
|
91
|
+
/** 是否为官方工作流 */
|
|
92
|
+
official?: boolean;
|
|
93
|
+
/** 创建时间 */
|
|
94
|
+
createdAt?: number;
|
|
95
|
+
/** 更新时间 */
|
|
96
|
+
updatedAt?: number;
|
|
97
|
+
}
|
|
98
|
+
/** Workflow 执行结果 */
|
|
99
|
+
export interface WorkflowResult {
|
|
100
|
+
workflowId: string;
|
|
101
|
+
/** 输出 Asset ID 列表 */
|
|
102
|
+
outputs: import('./asset.js').AssetId[];
|
|
103
|
+
/** 执行耗时(毫秒) */
|
|
104
|
+
duration: number;
|
|
105
|
+
/** 执行状态 */
|
|
106
|
+
status: 'completed' | 'cancelled' | 'failed';
|
|
107
|
+
/** 错误信息(status=failed 时) */
|
|
108
|
+
error?: string;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Workflow 的 AI 指令描述(见 docs/AI生态冲击调整方案.md §7.2)。
|
|
112
|
+
* 把 Workflow JSON 转换为 AI Agent 可理解的指令格式,
|
|
113
|
+
* 供 MCP server 在 prompt 模板 / resource 中暴露给 AI 客户端。
|
|
114
|
+
*/
|
|
115
|
+
export interface WorkflowAiInstruction {
|
|
116
|
+
/** 人类可读的指令描述,如 "Execute 2-step workflow: image.resize with {...} → image.compress with {...}" */
|
|
117
|
+
instruction: string;
|
|
118
|
+
/** 涉及的 Lokvis capability 名(去重) */
|
|
119
|
+
capabilities: string[];
|
|
120
|
+
/** 输入参数 JSON Schema(描述 workflow 需要的输入) */
|
|
121
|
+
inputSchema: object;
|
|
122
|
+
/** 示例调用(供 AI 学习调用方式) */
|
|
123
|
+
example: {
|
|
124
|
+
input: Record<string, unknown>;
|
|
125
|
+
expectedOutput: string;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 把 Workflow 转换为 AI 可理解的指令描述。
|
|
130
|
+
*
|
|
131
|
+
* 注意:此函数仅做结构转换,不执行 workflow。
|
|
132
|
+
* AI 生成的 workflow 仍由确定性 Runtime 执行(见方案 §5.3 设计原则)。
|
|
133
|
+
*
|
|
134
|
+
* @param workflow 已定义的 Workflow
|
|
135
|
+
* @returns AI 指令描述,含人类可读指令、依赖能力、输入 schema、示例
|
|
136
|
+
*/
|
|
137
|
+
export declare function workflowToAiInstruction(workflow: Workflow): WorkflowAiInstruction;
|
|
138
|
+
//# sourceMappingURL=workflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../src/workflow.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YA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WAAW,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,0CAA0C;IAC1C,WAAW,EAAE,MAAM,CAAC;IACpB,wBAAwB;IACxB,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/B,cAAc,EAAE,MAAM,CAAC;KACxB,CAAC;CACH;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,QAAQ,GAAG,qBAAqB,CA6BjF"}
|
package/dist/workflow.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lokvis Workflow Schema
|
|
3
|
+
*
|
|
4
|
+
* 第一年只支持 Linear Workflow(线性工作流)。
|
|
5
|
+
* 不支持:Branch / Loop / Condition / Parallel。
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* 把 Workflow 转换为 AI 可理解的指令描述。
|
|
9
|
+
*
|
|
10
|
+
* 注意:此函数仅做结构转换,不执行 workflow。
|
|
11
|
+
* AI 生成的 workflow 仍由确定性 Runtime 执行(见方案 §5.3 设计原则)。
|
|
12
|
+
*
|
|
13
|
+
* @param workflow 已定义的 Workflow
|
|
14
|
+
* @returns AI 指令描述,含人类可读指令、依赖能力、输入 schema、示例
|
|
15
|
+
*/
|
|
16
|
+
export function workflowToAiInstruction(workflow) {
|
|
17
|
+
const steps = workflow.nodes
|
|
18
|
+
.filter((n) => n.capability)
|
|
19
|
+
.map((n) => `${n.capability} with params ${JSON.stringify(n.params ?? {})}`);
|
|
20
|
+
// 从节点中收集依赖的 capability 名(去重,保留顺序)
|
|
21
|
+
const seen = new Set();
|
|
22
|
+
const capabilities = [];
|
|
23
|
+
for (const node of workflow.nodes) {
|
|
24
|
+
if (node.capability && !seen.has(node.capability)) {
|
|
25
|
+
seen.add(node.capability);
|
|
26
|
+
capabilities.push(node.capability);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// 期望输出反映 workflow 实际输出类型/格式(而非硬编码占位),
|
|
30
|
+
// 供 AI 理解调用后的产物。注意:此处仅描述,实际执行由确定性 Runtime 完成。
|
|
31
|
+
const outputFormat = workflow.outputs.format ?? workflow.outputs.type;
|
|
32
|
+
return {
|
|
33
|
+
instruction: `Execute ${workflow.nodes.length}-step workflow "${workflow.name}": ${steps.join(' → ')}`,
|
|
34
|
+
capabilities,
|
|
35
|
+
inputSchema: workflowInputsToJsonSchema(workflow),
|
|
36
|
+
example: {
|
|
37
|
+
input: { input_path: `/path/to/input.${workflow.inputs.type}` },
|
|
38
|
+
expectedOutput: `Processed ${workflow.inputs.type} saved as ${outputFormat}`,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** 把 Workflow 的输入定义转为 JSON Schema(供 AI 理解输入约束) */
|
|
43
|
+
function workflowInputsToJsonSchema(workflow) {
|
|
44
|
+
const inputDef = workflow.inputs;
|
|
45
|
+
const schema = {
|
|
46
|
+
type: 'object',
|
|
47
|
+
properties: {
|
|
48
|
+
input_path: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
description: `Path or asset ID of the input ${inputDef.type} file${inputDef.multiple ? '(s)' : ''}`,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
required: ['input_path'],
|
|
54
|
+
};
|
|
55
|
+
if (inputDef.multiple) {
|
|
56
|
+
schema.properties.input_path = {
|
|
57
|
+
type: 'array',
|
|
58
|
+
items: { type: 'string' },
|
|
59
|
+
description: `List of input ${inputDef.type} file paths${inputDef.maxCount ? ` (max ${inputDef.maxCount})` : ''}`,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return schema;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=workflow.js.map
|