MCPcopy Create free account
hub / github.com/msgbyte/tailchat / parsePluginManifest

Function parsePluginManifest

client/web/src/plugin/utils.ts:14–49  ·  view source on GitHub ↗
(json: string)

Source from the content-addressed store, hash-verified

12 * 如果格式不合法则会抛出异常
13 */
14export function parsePluginManifest(json: string): PluginManifest {
15 if (!isValidJson(json)) {
16 throw new Error(t('不是一个合法的JSON字符串'));
17 }
18
19 const obj = JSON.parse(json);
20 const { valid, errors } = new Validator().validate(obj, {
21 type: 'object',
22 properties: {
23 label: { type: 'string' },
24 name: { type: 'string' },
25 url: { type: 'string' },
26 icon: { type: 'string' },
27 version: { type: 'string' },
28 author: { type: 'string' },
29 description: { type: 'string' },
30 requireRestart: { type: 'boolean' },
31 },
32 required: ['label', 'name', 'url', 'version', 'author', 'description'],
33 additionalProperties: true,
34 });
35
36 if (!valid) {
37 console.error(
38 '[PluginManifest validation]:',
39 errors.map((e) => e.message).join(', ')
40 );
41
42 throw new Error(t('不是一个合法的插件配置'));
43 }
44
45 // 后端url策略。根据前端的url在获取时自动变更为当前链接的后端地址
46 obj.url = parseUrlStr(obj.url);
47
48 return obj;
49}
50
51/**
52 * Get manifest field with i18n support,

Callers 2

ManualInstall.tsxFile · 0.90
utils.spec.tsFile · 0.90

Calls 6

isValidJsonFunction · 0.85
parseMethod · 0.80
errorMethod · 0.80
joinMethod · 0.80
tFunction · 0.50
parseUrlStrFunction · 0.50

Tested by

no test coverage detected