@syncshio/kano-plugin-sdk 0.0.0-stage → 4.0.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/README.md +265 -2
- package/dist/api/contributions.d.ts +140 -0
- package/dist/api/launch-tools.d.ts +136 -0
- package/dist/api/types.d.ts +178 -0
- package/dist/contracts/app-context.d.ts +32 -0
- package/dist/contracts/app-lifecycle.d.ts +119 -0
- package/dist/contracts/app-plugin.d.ts +72 -0
- package/dist/contracts/drop.d.ts +35 -0
- package/dist/contracts/install-recipe.d.ts +140 -0
- package/dist/contracts/launch-pipeline.d.ts +272 -0
- package/dist/contracts/launch.d.ts +137 -0
- package/dist/contracts/model-market.d.ts +112 -0
- package/dist/contracts/models.d.ts +119 -0
- package/dist/contracts/params.d.ts +150 -0
- package/dist/contracts/providers.d.ts +344 -0
- package/dist/contracts/session.d.ts +64 -0
- package/dist/helpers/define-plugin.d.ts +2 -0
- package/dist/helpers/params.d.ts +14 -0
- package/dist/host.d.ts +626 -0
- package/dist/host.js +94 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +629 -0
- package/dist/manifest/plugin-manifest.d.ts +33 -0
- package/dist/manifest/validate.d.ts +12 -0
- package/dist/versions.d.ts +12 -0
- package/package.json +40 -4
- package/src/schemas/plugin-manifest.schema.json +262 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type * from './api/types';
|
|
2
|
+
export type * from './api/launch-tools';
|
|
3
|
+
export type * from './api/contributions';
|
|
4
|
+
export type * from './contracts/drop';
|
|
5
|
+
export type * from './contracts/install-recipe';
|
|
6
|
+
export type * from './contracts/app-lifecycle';
|
|
7
|
+
export type * from './contracts/app-plugin';
|
|
8
|
+
export type * from './contracts/launch';
|
|
9
|
+
export { LAUNCH_CHECK_ACTION_IDS } from './contracts/launch';
|
|
10
|
+
export type * from './contracts/launch-pipeline';
|
|
11
|
+
export type * from './contracts/params';
|
|
12
|
+
export type * from './contracts/providers';
|
|
13
|
+
export type * from './contracts/session';
|
|
14
|
+
export type * from './contracts/model-market';
|
|
15
|
+
export type * from './manifest/plugin-manifest';
|
|
16
|
+
export { definePlugin } from './helpers/define-plugin';
|
|
17
|
+
export { evaluateParamCondition, getManagedCliFlags, isParamSet, validateParamValue, validateParamRules } from './helpers/params';
|
|
18
|
+
export type { ParamIssue } from './helpers/params';
|
|
19
|
+
export type * from './contracts/app-context';
|
|
20
|
+
export type * from './contracts/models';
|
|
21
|
+
export { validateRuntimePluginManifest, asRuntimePluginManifest } from './manifest/validate';
|
|
22
|
+
export { validatePluginEngineCompatibility, satisfiesVersionRange, compareStableVersions } from './versions';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,629 @@
|
|
|
1
|
+
// src/contracts/launch.ts
|
|
2
|
+
var LAUNCH_CHECK_ACTION_IDS = {
|
|
3
|
+
RefreshHostCapabilities: "refresh-host-capabilities",
|
|
4
|
+
OpenPythonSettings: "open-python-settings",
|
|
5
|
+
OpenLaunchSettings: "open-launch-settings",
|
|
6
|
+
OpenVersionManagement: "open-version-management",
|
|
7
|
+
OpenExtensionManagement: "open-extension-management",
|
|
8
|
+
ApplyLaunchParam: "apply-launch-param",
|
|
9
|
+
ApplyBackendSelection: "apply-backend-selection",
|
|
10
|
+
OpenUrl: "open-url"
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// src/helpers/define-plugin.ts
|
|
14
|
+
function definePlugin(plugin) {
|
|
15
|
+
return plugin;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/helpers/params.ts
|
|
19
|
+
function isParamSet(value) {
|
|
20
|
+
return value !== void 0 && value !== null && (typeof value !== "string" || value.trim() !== "");
|
|
21
|
+
}
|
|
22
|
+
function evaluateParamCondition(condition, params) {
|
|
23
|
+
if (!condition) return true;
|
|
24
|
+
if ("and" in condition) return condition.and.every((item) => evaluateParamCondition(item, params));
|
|
25
|
+
if ("or" in condition) return condition.or.some((item) => evaluateParamCondition(item, params));
|
|
26
|
+
if ("not" in condition) return !evaluateParamCondition(condition.not, params);
|
|
27
|
+
const value = params[condition.param];
|
|
28
|
+
if ("equals" in condition) return value === condition.equals;
|
|
29
|
+
if ("notEquals" in condition) return value !== condition.notEquals;
|
|
30
|
+
if ("in" in condition) return condition.in.includes(value);
|
|
31
|
+
if ("set" in condition) return isParamSet(value) === condition.set;
|
|
32
|
+
return Boolean(value) === condition.truthy;
|
|
33
|
+
}
|
|
34
|
+
function getManagedCliFlags(provider) {
|
|
35
|
+
const flags = new Set(provider.ownedArgs);
|
|
36
|
+
const add = (mapping) => {
|
|
37
|
+
for (const item of Array.isArray(mapping) ? mapping : mapping ? [mapping] : []) {
|
|
38
|
+
if (typeof item === "string") flags.add(item);
|
|
39
|
+
else {
|
|
40
|
+
flags.add(item.arg);
|
|
41
|
+
if (item.falseArg) flags.add(item.falseArg);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
for (const param of provider.params ?? []) {
|
|
46
|
+
for (const flag of param.ownedArgs ?? []) flags.add(flag);
|
|
47
|
+
if (typeof param.cli !== "function") add(param.cli);
|
|
48
|
+
for (const option of param.options ?? []) add(option.cli);
|
|
49
|
+
}
|
|
50
|
+
return [...flags];
|
|
51
|
+
}
|
|
52
|
+
function validateParamValue(param, value, ctx) {
|
|
53
|
+
if (!isParamSet(value)) {
|
|
54
|
+
if (param.required) return "\u8BF7\u586B\u5199\u6B64\u9879";
|
|
55
|
+
if (param.optional || !["number", "port", "select", "boolean"].includes(param.type)) return null;
|
|
56
|
+
return "\u8BF7\u586B\u5199\u6709\u6548\u503C";
|
|
57
|
+
}
|
|
58
|
+
if (param.type === "boolean" && typeof value !== "boolean") return "\u8BF7\u4F7F\u7528\u5F00\u5173\u8BBE\u7F6E\u6B64\u9009\u9879";
|
|
59
|
+
if (param.type === "select" && !param.options?.some((option) => option.value === value))
|
|
60
|
+
return "\u8BF7\u9009\u62E9\u6709\u6548\u9009\u9879";
|
|
61
|
+
if (param.type === "number" || param.type === "port") {
|
|
62
|
+
if (typeof value !== "number" && typeof value !== "string") return "\u8BF7\u8F93\u5165\u6570\u503C";
|
|
63
|
+
const number = Number(value);
|
|
64
|
+
if (!Number.isFinite(number)) return "\u8BF7\u8F93\u5165\u6709\u9650\u6570\u503C";
|
|
65
|
+
if ((param.integer || param.type === "port") && !Number.isInteger(number)) return "\u8BF7\u8F93\u5165\u6574\u6570";
|
|
66
|
+
const min = param.min ?? (param.type === "port" ? 1 : void 0);
|
|
67
|
+
const max = param.max ?? (param.type === "port" ? 65535 : void 0);
|
|
68
|
+
if (min !== void 0 && number < min) return `\u4E0D\u80FD\u5C0F\u4E8E ${min}`;
|
|
69
|
+
if (max !== void 0 && number > max) return `\u4E0D\u80FD\u5927\u4E8E ${max}`;
|
|
70
|
+
} else if (["string", "text", "path"].includes(param.type) && typeof value !== "string")
|
|
71
|
+
return "\u8BF7\u8F93\u5165\u6587\u672C";
|
|
72
|
+
return ctx ? param.validate?.(value, ctx) ?? null : null;
|
|
73
|
+
}
|
|
74
|
+
function validateParamRules(provider, params) {
|
|
75
|
+
return (provider.rules ?? []).filter((rule) => evaluateParamCondition(rule.when, params)).map((rule) => ({
|
|
76
|
+
id: rule.id,
|
|
77
|
+
params: rule.params,
|
|
78
|
+
severity: rule.severity ?? "error",
|
|
79
|
+
message: rule.message
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/schemas/plugin-manifest.schema.json
|
|
84
|
+
var plugin_manifest_schema_default = {
|
|
85
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
86
|
+
$id: "https://kano.dev/schemas/plugin-manifest.schema.json",
|
|
87
|
+
title: "Kano Plugin Manifest v2",
|
|
88
|
+
type: "object",
|
|
89
|
+
additionalProperties: false,
|
|
90
|
+
required: ["manifestVersion", "id", "name", "version", "runtime"],
|
|
91
|
+
$defs: {
|
|
92
|
+
condition: {
|
|
93
|
+
anyOf: [
|
|
94
|
+
{
|
|
95
|
+
type: "object",
|
|
96
|
+
required: ["param"],
|
|
97
|
+
minProperties: 2,
|
|
98
|
+
maxProperties: 2,
|
|
99
|
+
additionalProperties: false,
|
|
100
|
+
properties: {
|
|
101
|
+
param: {
|
|
102
|
+
type: "string",
|
|
103
|
+
minLength: 1
|
|
104
|
+
},
|
|
105
|
+
equals: {},
|
|
106
|
+
notEquals: {},
|
|
107
|
+
in: {
|
|
108
|
+
type: "array"
|
|
109
|
+
},
|
|
110
|
+
truthy: {
|
|
111
|
+
type: "boolean"
|
|
112
|
+
},
|
|
113
|
+
set: {
|
|
114
|
+
type: "boolean"
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
type: "object",
|
|
120
|
+
minProperties: 1,
|
|
121
|
+
maxProperties: 1,
|
|
122
|
+
additionalProperties: false,
|
|
123
|
+
properties: {
|
|
124
|
+
and: {
|
|
125
|
+
$ref: "#/$defs/conditionList"
|
|
126
|
+
},
|
|
127
|
+
or: {
|
|
128
|
+
$ref: "#/$defs/conditionList"
|
|
129
|
+
},
|
|
130
|
+
not: {
|
|
131
|
+
$ref: "#/$defs/condition"
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
},
|
|
137
|
+
conditionList: {
|
|
138
|
+
type: "array",
|
|
139
|
+
items: {
|
|
140
|
+
$ref: "#/$defs/condition"
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
properties: {
|
|
145
|
+
manifestVersion: {
|
|
146
|
+
type: "integer",
|
|
147
|
+
const: 2
|
|
148
|
+
},
|
|
149
|
+
id: {
|
|
150
|
+
type: "string",
|
|
151
|
+
pattern: "^[a-z0-9][a-z0-9-]*$"
|
|
152
|
+
},
|
|
153
|
+
name: {
|
|
154
|
+
type: "string",
|
|
155
|
+
minLength: 1
|
|
156
|
+
},
|
|
157
|
+
version: {
|
|
158
|
+
type: "string",
|
|
159
|
+
minLength: 1
|
|
160
|
+
},
|
|
161
|
+
description: {
|
|
162
|
+
type: "string"
|
|
163
|
+
},
|
|
164
|
+
author: {
|
|
165
|
+
type: "string"
|
|
166
|
+
},
|
|
167
|
+
homepage: {
|
|
168
|
+
type: "string"
|
|
169
|
+
},
|
|
170
|
+
keywords: {
|
|
171
|
+
type: "array",
|
|
172
|
+
items: {
|
|
173
|
+
type: "string"
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
settings: {
|
|
177
|
+
type: "array",
|
|
178
|
+
items: {
|
|
179
|
+
type: "object",
|
|
180
|
+
additionalProperties: false,
|
|
181
|
+
required: ["id", "label", "type"],
|
|
182
|
+
properties: {
|
|
183
|
+
id: {
|
|
184
|
+
type: "string",
|
|
185
|
+
minLength: 1
|
|
186
|
+
},
|
|
187
|
+
label: {
|
|
188
|
+
type: "string",
|
|
189
|
+
minLength: 1
|
|
190
|
+
},
|
|
191
|
+
description: {
|
|
192
|
+
type: "string"
|
|
193
|
+
},
|
|
194
|
+
type: {
|
|
195
|
+
enum: ["boolean", "string", "number", "select", "path", "text", "port"]
|
|
196
|
+
},
|
|
197
|
+
default: {},
|
|
198
|
+
required: {
|
|
199
|
+
type: "boolean"
|
|
200
|
+
},
|
|
201
|
+
optional: {
|
|
202
|
+
type: "boolean"
|
|
203
|
+
},
|
|
204
|
+
options: {
|
|
205
|
+
type: "array",
|
|
206
|
+
items: {
|
|
207
|
+
type: "object",
|
|
208
|
+
additionalProperties: false,
|
|
209
|
+
required: ["value", "label"],
|
|
210
|
+
properties: {
|
|
211
|
+
label: {
|
|
212
|
+
type: "string"
|
|
213
|
+
},
|
|
214
|
+
value: {
|
|
215
|
+
anyOf: [
|
|
216
|
+
{
|
|
217
|
+
type: "string"
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
type: "boolean"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
type: "number"
|
|
224
|
+
}
|
|
225
|
+
]
|
|
226
|
+
},
|
|
227
|
+
description: {
|
|
228
|
+
type: "string"
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
pathKind: {
|
|
234
|
+
enum: ["file", "directory"]
|
|
235
|
+
},
|
|
236
|
+
fileFilters: {
|
|
237
|
+
type: "array",
|
|
238
|
+
items: {
|
|
239
|
+
type: "object",
|
|
240
|
+
additionalProperties: false,
|
|
241
|
+
required: ["name", "extensions"],
|
|
242
|
+
properties: {
|
|
243
|
+
name: {
|
|
244
|
+
type: "string"
|
|
245
|
+
},
|
|
246
|
+
extensions: {
|
|
247
|
+
type: "array",
|
|
248
|
+
items: {
|
|
249
|
+
type: "string"
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
min: {
|
|
256
|
+
type: "number"
|
|
257
|
+
},
|
|
258
|
+
max: {
|
|
259
|
+
type: "number"
|
|
260
|
+
},
|
|
261
|
+
step: {
|
|
262
|
+
type: "number"
|
|
263
|
+
},
|
|
264
|
+
integer: {
|
|
265
|
+
type: "boolean"
|
|
266
|
+
},
|
|
267
|
+
order: {
|
|
268
|
+
type: "number"
|
|
269
|
+
},
|
|
270
|
+
placeholder: {
|
|
271
|
+
type: "string"
|
|
272
|
+
},
|
|
273
|
+
warning: {
|
|
274
|
+
type: "string"
|
|
275
|
+
},
|
|
276
|
+
showWhen: {
|
|
277
|
+
$ref: "#/$defs/condition"
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
runtime: {
|
|
283
|
+
type: "object",
|
|
284
|
+
additionalProperties: false,
|
|
285
|
+
required: ["entry"],
|
|
286
|
+
properties: {
|
|
287
|
+
entry: {
|
|
288
|
+
type: "string",
|
|
289
|
+
minLength: 1
|
|
290
|
+
},
|
|
291
|
+
style: {
|
|
292
|
+
type: "string",
|
|
293
|
+
minLength: 1
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
permissions: {
|
|
298
|
+
type: "object",
|
|
299
|
+
additionalProperties: false,
|
|
300
|
+
properties: {
|
|
301
|
+
network: {
|
|
302
|
+
type: "array",
|
|
303
|
+
items: {
|
|
304
|
+
type: "string",
|
|
305
|
+
pattern: "^https://[^/]+$"
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
rpc: {
|
|
309
|
+
type: "array",
|
|
310
|
+
items: {
|
|
311
|
+
type: "string"
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
shell: {
|
|
315
|
+
type: "array",
|
|
316
|
+
items: {
|
|
317
|
+
enum: ["openExternal", "openFolder", "showItemInFolder"]
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
launchPipeline: {
|
|
321
|
+
type: "boolean"
|
|
322
|
+
},
|
|
323
|
+
systemMetrics: {
|
|
324
|
+
type: "boolean",
|
|
325
|
+
description: "\u8BFB\u53D6\u5F53\u524D\u6267\u884C\u7AEF\u7684 CPU\u3001\u5185\u5B58\u4E0E\u663E\u5361\u5B9E\u65F6\u72B6\u6001"
|
|
326
|
+
},
|
|
327
|
+
storage: {
|
|
328
|
+
type: "boolean"
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
engines: {
|
|
333
|
+
type: "object",
|
|
334
|
+
additionalProperties: false,
|
|
335
|
+
properties: {
|
|
336
|
+
kano: {
|
|
337
|
+
type: "string"
|
|
338
|
+
},
|
|
339
|
+
pluginSdk: {
|
|
340
|
+
type: "string"
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
// src/manifest/validate.ts
|
|
348
|
+
var RUNTIME_PLUGIN_MANIFEST_SCHEMA = plugin_manifest_schema_default;
|
|
349
|
+
var TYPE_LABELS = {
|
|
350
|
+
object: "\u5BF9\u8C61",
|
|
351
|
+
string: "\u5B57\u7B26\u4E32",
|
|
352
|
+
integer: "\u6574\u6570",
|
|
353
|
+
number: "\u6570\u503C",
|
|
354
|
+
boolean: "\u5E03\u5C14\u503C",
|
|
355
|
+
array: "\u6570\u7EC4"
|
|
356
|
+
};
|
|
357
|
+
function isPlainRecord(value) {
|
|
358
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
359
|
+
}
|
|
360
|
+
function quotePath(path) {
|
|
361
|
+
return path ? `"${path}"` : "\u6E05\u5355";
|
|
362
|
+
}
|
|
363
|
+
function joinPath(path, key) {
|
|
364
|
+
return path ? `${path}.${key}` : key;
|
|
365
|
+
}
|
|
366
|
+
function getSchemaType(value) {
|
|
367
|
+
if (Array.isArray(value)) {
|
|
368
|
+
return "array";
|
|
369
|
+
}
|
|
370
|
+
if (isPlainRecord(value)) {
|
|
371
|
+
return "object";
|
|
372
|
+
}
|
|
373
|
+
if (typeof value === "string") {
|
|
374
|
+
return "string";
|
|
375
|
+
}
|
|
376
|
+
if (typeof value === "boolean") {
|
|
377
|
+
return "boolean";
|
|
378
|
+
}
|
|
379
|
+
if (Number.isInteger(value)) {
|
|
380
|
+
return "integer";
|
|
381
|
+
}
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
function validateType(value, expectedType, path) {
|
|
385
|
+
const actualType = getSchemaType(value);
|
|
386
|
+
if (actualType === expectedType || expectedType === "number" && typeof value === "number" && Number.isFinite(value)) {
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
if (!path && expectedType === "object") {
|
|
390
|
+
return "\u6E05\u5355\u5FC5\u987B\u662F\u4E00\u4E2A JSON \u5BF9\u8C61";
|
|
391
|
+
}
|
|
392
|
+
return `${quotePath(path)} \u5FC5\u987B\u662F${TYPE_LABELS[expectedType]}`;
|
|
393
|
+
}
|
|
394
|
+
function validateSchemaNode(value, schema, errors, path = "") {
|
|
395
|
+
if (schema.$ref) {
|
|
396
|
+
const target = RUNTIME_PLUGIN_MANIFEST_SCHEMA.$defs?.[schema.$ref.split("/").at(-1)];
|
|
397
|
+
if (!target) throw new Error("\u672A\u77E5\u6E05\u5355 schema \u5F15\u7528 " + schema.$ref);
|
|
398
|
+
validateSchemaNode(value, target, errors, path);
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
if (schema.anyOf && !schema.anyOf.some((option) => {
|
|
402
|
+
const failures = [];
|
|
403
|
+
validateSchemaNode(value, option, failures, path);
|
|
404
|
+
return !failures.length;
|
|
405
|
+
})) {
|
|
406
|
+
errors.push(quotePath(path) + " \u683C\u5F0F\u4E0D\u7B26\u5408\u8981\u6C42");
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
if (schema.const !== void 0 && value !== schema.const) {
|
|
410
|
+
errors.push(`${quotePath(path)} \u5FC5\u987B\u7B49\u4E8E ${String(schema.const)}`);
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
if (schema.type) {
|
|
414
|
+
const typeError = validateType(value, schema.type, path);
|
|
415
|
+
if (typeError) {
|
|
416
|
+
errors.push(typeError);
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
if (schema.enum && !schema.enum.some((item) => Object.is(item, value))) {
|
|
421
|
+
errors.push(`${quotePath(path)} \u53EA\u5141\u8BB8: ${schema.enum.map(String).join(", ")}`);
|
|
422
|
+
}
|
|
423
|
+
if (schema.type === "string" && typeof value === "string") {
|
|
424
|
+
if (schema.minLength !== void 0 && value.length < schema.minLength) {
|
|
425
|
+
errors.push(`${quotePath(path)} \u4E0D\u80FD\u4E3A\u7A7A`);
|
|
426
|
+
}
|
|
427
|
+
if (schema.pattern && !new RegExp(schema.pattern).test(value)) {
|
|
428
|
+
errors.push(`${quotePath(path)} \u683C\u5F0F\u4E0D\u7B26\u5408\u8981\u6C42`);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
if (schema.type === "array" && Array.isArray(value) && schema.items) {
|
|
432
|
+
value.forEach((item, index) => {
|
|
433
|
+
validateSchemaNode(item, schema.items, errors, `${path}[${index}]`);
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
if (schema.type === "object" && isPlainRecord(value)) {
|
|
437
|
+
const properties = schema.properties ?? {};
|
|
438
|
+
const size = Object.keys(value).length;
|
|
439
|
+
if (size < (schema.minProperties ?? 0) || size > (schema.maxProperties ?? Infinity))
|
|
440
|
+
errors.push(quotePath(path) + " \u5B57\u6BB5\u6570\u91CF\u4E0D\u6B63\u786E");
|
|
441
|
+
for (const requiredField of schema.required ?? []) {
|
|
442
|
+
if (!Object.prototype.hasOwnProperty.call(value, requiredField)) {
|
|
443
|
+
errors.push(`\u7F3A\u5C11\u5FC5\u586B\u5B57\u6BB5 "${joinPath(path, requiredField)}"`);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (schema.additionalProperties === false) {
|
|
447
|
+
for (const key of Object.keys(value)) {
|
|
448
|
+
if (!Object.prototype.hasOwnProperty.call(properties, key)) {
|
|
449
|
+
errors.push(`\u5B58\u5728\u4E0D\u652F\u6301\u7684\u5B57\u6BB5 "${joinPath(path, key)}"`);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
for (const [key, childSchema] of Object.entries(properties)) {
|
|
454
|
+
if (!Object.prototype.hasOwnProperty.call(value, key)) {
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
validateSchemaNode(value[key], childSchema, errors, joinPath(path, key));
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
function validateRuntimePluginManifest(manifest) {
|
|
462
|
+
const errors = [];
|
|
463
|
+
validateSchemaNode(manifest, RUNTIME_PLUGIN_MANIFEST_SCHEMA, errors);
|
|
464
|
+
if (!errors.length) {
|
|
465
|
+
const ids = /* @__PURE__ */ new Set();
|
|
466
|
+
for (const field of manifest.settings ?? []) {
|
|
467
|
+
if (ids.has(field.id)) errors.push("\u63D2\u4EF6\u8BBE\u7F6E ID \u91CD\u590D: " + field.id);
|
|
468
|
+
ids.add(field.id);
|
|
469
|
+
if (field.type === "select" && !field.options?.length) errors.push(field.label + " \u7F3A\u5C11\u9009\u9879");
|
|
470
|
+
if (field.default !== void 0) {
|
|
471
|
+
const message = validateParamValue(field, field.default);
|
|
472
|
+
if (message) errors.push(field.label + " \u9ED8\u8BA4\u503C\u65E0\u6548: " + message);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
return { valid: errors.length === 0, errors };
|
|
477
|
+
}
|
|
478
|
+
function asRuntimePluginManifest(data) {
|
|
479
|
+
return data;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// src/versions.ts
|
|
483
|
+
var ANY_RANGES = /* @__PURE__ */ new Set(["", "*", "x", "X"]);
|
|
484
|
+
function parseSemver(version) {
|
|
485
|
+
const normalized = version.trim().replace(/^v/i, "").split("+")[0];
|
|
486
|
+
const [core, prerelease = ""] = normalized.split("-", 2);
|
|
487
|
+
const parts = core.split(".");
|
|
488
|
+
if (!/^\d+(?:\.\d+){0,2}(?:-[0-9A-Za-z.-]+)?$/.test(normalized) || parts.length > 3 || parts.some((part) => part !== "" && !/^\d+$/.test(part))) {
|
|
489
|
+
return null;
|
|
490
|
+
}
|
|
491
|
+
return {
|
|
492
|
+
major: Number(parts[0] ?? 0),
|
|
493
|
+
minor: Number(parts[1] ?? 0),
|
|
494
|
+
patch: Number(parts[2] ?? 0),
|
|
495
|
+
prerelease
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
function compareSemver(left, right) {
|
|
499
|
+
for (const key of ["major", "minor", "patch"]) {
|
|
500
|
+
if (left[key] > right[key]) return 1;
|
|
501
|
+
if (left[key] < right[key]) return -1;
|
|
502
|
+
}
|
|
503
|
+
if (left.prerelease === right.prerelease) return 0;
|
|
504
|
+
if (!left.prerelease) return 1;
|
|
505
|
+
if (!right.prerelease) return -1;
|
|
506
|
+
const a = left.prerelease.split(".");
|
|
507
|
+
const b = right.prerelease.split(".");
|
|
508
|
+
for (let index = 0; index < Math.max(a.length, b.length); index++) {
|
|
509
|
+
if (a[index] === b[index]) continue;
|
|
510
|
+
if (a[index] === void 0) return -1;
|
|
511
|
+
if (b[index] === void 0) return 1;
|
|
512
|
+
const an = /^\d+$/.test(a[index]);
|
|
513
|
+
const bn = /^\d+$/.test(b[index]);
|
|
514
|
+
if (an && bn) return Number(a[index]) - Number(b[index]);
|
|
515
|
+
if (an !== bn) return an ? -1 : 1;
|
|
516
|
+
return a[index] < b[index] ? -1 : 1;
|
|
517
|
+
}
|
|
518
|
+
return 0;
|
|
519
|
+
}
|
|
520
|
+
function incrementMajor(version) {
|
|
521
|
+
return { major: version.major + 1, minor: 0, patch: 0, prerelease: "" };
|
|
522
|
+
}
|
|
523
|
+
function incrementMinor(version) {
|
|
524
|
+
return { major: version.major, minor: version.minor + 1, patch: 0, prerelease: "" };
|
|
525
|
+
}
|
|
526
|
+
function incrementPatch(version) {
|
|
527
|
+
return { major: version.major, minor: version.minor, patch: version.patch + 1, prerelease: "" };
|
|
528
|
+
}
|
|
529
|
+
function satisfiesComparator(version, operator, target) {
|
|
530
|
+
const comparison = compareSemver(version, target);
|
|
531
|
+
switch (operator) {
|
|
532
|
+
case ">":
|
|
533
|
+
return comparison > 0;
|
|
534
|
+
case ">=":
|
|
535
|
+
return comparison >= 0;
|
|
536
|
+
case "<":
|
|
537
|
+
return comparison < 0;
|
|
538
|
+
case "<=":
|
|
539
|
+
return comparison <= 0;
|
|
540
|
+
case "=":
|
|
541
|
+
default:
|
|
542
|
+
return comparison === 0;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
function satisfiesCaretRange(version, target) {
|
|
546
|
+
const upper = target.major > 0 ? incrementMajor(target) : target.minor > 0 ? incrementMinor(target) : incrementPatch(target);
|
|
547
|
+
return compareSemver(version, target) >= 0 && compareSemver(version, upper) < 0;
|
|
548
|
+
}
|
|
549
|
+
function satisfiesTildeRange(version, target) {
|
|
550
|
+
const upper = incrementMinor(target);
|
|
551
|
+
return compareSemver(version, target) >= 0 && compareSemver(version, upper) < 0;
|
|
552
|
+
}
|
|
553
|
+
function satisfiesWildcardRange(version, token) {
|
|
554
|
+
const parts = token.trim().replace(/^v/i, "").split(".");
|
|
555
|
+
const wildcardIndex = parts.findIndex((part) => part === "*" || /^x$/i.test(part));
|
|
556
|
+
if (wildcardIndex === -1) {
|
|
557
|
+
return false;
|
|
558
|
+
}
|
|
559
|
+
const floor = parseSemver(
|
|
560
|
+
parts.map((part) => part === "*" || /^x$/i.test(part) ? "0" : part).join(".")
|
|
561
|
+
);
|
|
562
|
+
if (!floor) {
|
|
563
|
+
return false;
|
|
564
|
+
}
|
|
565
|
+
const upper = wildcardIndex === 0 ? null : wildcardIndex === 1 ? incrementMajor(floor) : incrementMinor(floor);
|
|
566
|
+
return compareSemver(version, floor) >= 0 && (!upper || compareSemver(version, upper) < 0);
|
|
567
|
+
}
|
|
568
|
+
function satisfiesToken(version, token) {
|
|
569
|
+
const trimmed = token.trim();
|
|
570
|
+
if (ANY_RANGES.has(trimmed)) {
|
|
571
|
+
return true;
|
|
572
|
+
}
|
|
573
|
+
if (trimmed.includes("*") || /(^|\.)x(\.|$)/i.test(trimmed)) {
|
|
574
|
+
return satisfiesWildcardRange(version, trimmed);
|
|
575
|
+
}
|
|
576
|
+
const prefixed = trimmed.match(/^(\^|~)(.+)$/);
|
|
577
|
+
if (prefixed) {
|
|
578
|
+
const target2 = parseSemver(prefixed[2]);
|
|
579
|
+
if (!target2) return false;
|
|
580
|
+
return prefixed[1] === "^" ? satisfiesCaretRange(version, target2) : satisfiesTildeRange(version, target2);
|
|
581
|
+
}
|
|
582
|
+
const comparator = trimmed.match(/^(>=|<=|>|<|=)?\s*(.+)$/);
|
|
583
|
+
if (!comparator) {
|
|
584
|
+
return false;
|
|
585
|
+
}
|
|
586
|
+
const target = parseSemver(comparator[2]);
|
|
587
|
+
return target ? satisfiesComparator(version, comparator[1] ?? "=", target) : false;
|
|
588
|
+
}
|
|
589
|
+
function satisfiesVersionRange(versionValue, range) {
|
|
590
|
+
const version = parseSemver(versionValue);
|
|
591
|
+
if (!version) {
|
|
592
|
+
return false;
|
|
593
|
+
}
|
|
594
|
+
return range.split("||").map((part) => part.trim()).some((part) => part.split(/\s+/).every((token) => satisfiesToken(version, token)));
|
|
595
|
+
}
|
|
596
|
+
function validatePluginEngineCompatibility(engines, versions) {
|
|
597
|
+
const errors = [];
|
|
598
|
+
if (engines?.kano && !satisfiesVersionRange(versions.kano, engines.kano)) {
|
|
599
|
+
errors.push(`engines.kano \u8981\u6C42 ${engines.kano}\uFF0C\u5F53\u524D Kano \u7248\u672C\u4E3A ${versions.kano}`);
|
|
600
|
+
}
|
|
601
|
+
if (engines?.pluginSdk && !satisfiesVersionRange(versions.pluginSdk, engines.pluginSdk)) {
|
|
602
|
+
errors.push(
|
|
603
|
+
`engines.pluginSdk \u8981\u6C42 ${engines.pluginSdk}\uFF0C\u5F53\u524D\u63D2\u4EF6 SDK \u7248\u672C\u4E3A ${versions.pluginSdk}`
|
|
604
|
+
);
|
|
605
|
+
}
|
|
606
|
+
return {
|
|
607
|
+
compatible: errors.length === 0,
|
|
608
|
+
errors
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
function compareStableVersions(left, right) {
|
|
612
|
+
if (![left, right].every((value) => /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(value)))
|
|
613
|
+
throw new Error("\u63D2\u4EF6\u5E02\u573A\u4EC5\u63A5\u53D7 major.minor.patch \u7A33\u5B9A\u7248\u672C");
|
|
614
|
+
return compareSemver(parseSemver(left), parseSemver(right));
|
|
615
|
+
}
|
|
616
|
+
export {
|
|
617
|
+
LAUNCH_CHECK_ACTION_IDS,
|
|
618
|
+
asRuntimePluginManifest,
|
|
619
|
+
compareStableVersions,
|
|
620
|
+
definePlugin,
|
|
621
|
+
evaluateParamCondition,
|
|
622
|
+
getManagedCliFlags,
|
|
623
|
+
isParamSet,
|
|
624
|
+
satisfiesVersionRange,
|
|
625
|
+
validateParamRules,
|
|
626
|
+
validateParamValue,
|
|
627
|
+
validatePluginEngineCompatibility,
|
|
628
|
+
validateRuntimePluginManifest
|
|
629
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ParamDefinition } from '../contracts/params';
|
|
2
|
+
export type PluginManifestVersion = 2;
|
|
3
|
+
export interface PluginRuntimeManifest {
|
|
4
|
+
entry: string;
|
|
5
|
+
style?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface PluginPermissionsManifest {
|
|
8
|
+
/** Exact HTTPS origins allowed for model market HTTP requests. */
|
|
9
|
+
network?: string[];
|
|
10
|
+
rpc?: string[];
|
|
11
|
+
shell?: Array<'openExternal' | 'openFolder' | 'showItemInFolder'>;
|
|
12
|
+
storage?: boolean;
|
|
13
|
+
systemMetrics?: boolean;
|
|
14
|
+
launchPipeline?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface PluginEnginesManifest {
|
|
17
|
+
kano?: string;
|
|
18
|
+
pluginSdk?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface PluginManifest {
|
|
21
|
+
manifestVersion: PluginManifestVersion;
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
version: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
author?: string;
|
|
27
|
+
homepage?: string;
|
|
28
|
+
keywords?: string[];
|
|
29
|
+
runtime: PluginRuntimeManifest;
|
|
30
|
+
settings?: ParamDefinition[];
|
|
31
|
+
permissions?: PluginPermissionsManifest;
|
|
32
|
+
engines?: PluginEnginesManifest;
|
|
33
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 插件清单验证器
|
|
3
|
+
*/
|
|
4
|
+
import type { PluginManifest as PluginPackageManifest } from './plugin-manifest';
|
|
5
|
+
/** 验证结果 */
|
|
6
|
+
export interface ValidationResult {
|
|
7
|
+
valid: boolean;
|
|
8
|
+
errors: string[];
|
|
9
|
+
}
|
|
10
|
+
/** 验证标准第三方插件包 manifest(plugin.json + dist/) */
|
|
11
|
+
export declare function validateRuntimePluginManifest(manifest: unknown): ValidationResult;
|
|
12
|
+
export declare function asRuntimePluginManifest(data: unknown): PluginPackageManifest;
|