aicommunicator-plugin-check 0.2.0 → 0.2.2
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 +35 -35
- package/dist/bundle.d.ts +10 -3
- package/dist/bundle.js +58 -36
- package/dist/icon.js +11 -11
- package/dist/manifest.d.ts +20 -0
- package/dist/manifest.js +118 -39
- package/dist/messages.js +33 -33
- package/dist/sample.d.ts +5 -2
- package/dist/sample.js +73 -64
- package/dist/state.js +7 -7
- package/package.json +2 -2
package/dist/manifest.js
CHANGED
|
@@ -14,6 +14,68 @@ const FILE_NAME = /^[\w.-]+$/;
|
|
|
14
14
|
const OS_NAMES = ['windows', 'macos', 'linux'];
|
|
15
15
|
const TOOL_KINDS = ['program', 'web', 'mcp'];
|
|
16
16
|
const ACCOUNTS = ['none', 'free', 'paid'];
|
|
17
|
+
/** 연결 이름. 코어의 link/connections.ts 의 CONNECTION_NAME 과 같은 모양이다(이 패키지는 코어를 불러오지 않는다). */
|
|
18
|
+
const CONNECTION_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
19
|
+
/**
|
|
20
|
+
* Windows 가 장치로 읽는 이름. 코어가 메시지 표를 messages/<연결 이름>.json 으로 복사하는데, 첫 점 앞이 이 이름이면 Windows 가 파일이 아니라
|
|
21
|
+
* 장치로 열기 때문이다.
|
|
22
|
+
*/
|
|
23
|
+
const WINDOWS_DEVICE = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\.|$)/i;
|
|
24
|
+
/** connect.url 의 길이 한도(032 44.2절). */
|
|
25
|
+
export const CONNECT_URL_MAX = 500;
|
|
26
|
+
/**
|
|
27
|
+
* connect.url 의 모양(032 44.2절). https 이고, 시험을 위해 http://127.0.0.1 과 http://localhost 는 받는다(032 31.6절과 같다). 사용자 정보(user@)와
|
|
28
|
+
* # 뒤는 받지 않는다. 물음표 뒤는 공개 manifest 에 있으니 비밀이 아니라 받는다. 빈칸, 제어 글자, 역빗금은 URL 이 조용히 고쳐 읽으므로 받지
|
|
29
|
+
* 않는다. 문제가 있으면 "<칸> <까닭>" 의 까닭이고 없으면 null 이다. 코어도 연결을 쓰기 전에 이것으로 다시 본다.
|
|
30
|
+
*/
|
|
31
|
+
export function connectUrlProblem(value) {
|
|
32
|
+
if (typeof value !== 'string' || value === '')
|
|
33
|
+
return 'must be an https address';
|
|
34
|
+
if (chars(value) > CONNECT_URL_MAX)
|
|
35
|
+
return `is over ${CONNECT_URL_MAX} characters (${chars(value)} characters)`;
|
|
36
|
+
if (/[\s\x00-\x1f\x7f\\]/.test(value))
|
|
37
|
+
return 'must not have spaces, control characters or backslashes';
|
|
38
|
+
if (value.includes('#'))
|
|
39
|
+
return 'must not have # (the part after # is not sent to the server)';
|
|
40
|
+
let u;
|
|
41
|
+
try {
|
|
42
|
+
u = new URL(value);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return 'is not an address';
|
|
46
|
+
}
|
|
47
|
+
if (u.username !== '' || u.password !== '' || /^[^:/?]+:\/\/[^/?]*@/.test(value))
|
|
48
|
+
return 'must not have user information (user@)';
|
|
49
|
+
if (u.protocol === 'https:')
|
|
50
|
+
return null;
|
|
51
|
+
if (u.protocol === 'http:' && (u.hostname === '127.0.0.1' || u.hostname === 'localhost'))
|
|
52
|
+
return null;
|
|
53
|
+
return 'must be https (http is accepted only for 127.0.0.1 and localhost, for tests)';
|
|
54
|
+
}
|
|
55
|
+
/** requires.external[].connect 의 모양(032 44.2절). */
|
|
56
|
+
function connectProblem(where, value) {
|
|
57
|
+
const shape = objectProblem(where, value, ['connection', 'url', 'title', 'messages']);
|
|
58
|
+
if (shape)
|
|
59
|
+
return shape;
|
|
60
|
+
const c = value;
|
|
61
|
+
if (typeof c.connection !== 'string' || !CONNECTION_NAME.test(c.connection)) {
|
|
62
|
+
return `${where}.connection must be up to 64 characters of English letters, digits, ., _ and -, starting with a letter or digit`;
|
|
63
|
+
}
|
|
64
|
+
if (WINDOWS_DEVICE.test(c.connection))
|
|
65
|
+
return `${where}.connection ${c.connection} is a name Windows keeps for a device, so it cannot be used`;
|
|
66
|
+
const url = connectUrlProblem(c.url);
|
|
67
|
+
if (url)
|
|
68
|
+
return `${where}.url ${url}`;
|
|
69
|
+
if (c.title !== undefined) {
|
|
70
|
+
const title = textProblem(`${where}.title`, c.title, 100);
|
|
71
|
+
if (title)
|
|
72
|
+
return title;
|
|
73
|
+
}
|
|
74
|
+
if (c.messages !== undefined && (!isPluginPath(c.messages) || !c.messages.endsWith('.json'))) {
|
|
75
|
+
return `${where}.messages ${JSON.stringify(c.messages)} must be a relative path to a message table file (.json) inside the plugin folder (for example link/messages.json)`;
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
17
79
|
/** `계정이름.플러그인이름` 모양인가. 각 부분은 영어 소문자, 숫자, `-` 이고 2자에서 40자다(036 4절). */
|
|
18
80
|
export function isPluginId(id) {
|
|
19
81
|
if (typeof id !== 'string')
|
|
@@ -46,17 +108,17 @@ function chars(s) {
|
|
|
46
108
|
/** 비어 있지 않은 글이고 한도 안인가. 문제가 있으면 그 설명이다. */
|
|
47
109
|
function textProblem(where, value, max) {
|
|
48
110
|
if (typeof value !== 'string' || value.trim() === '')
|
|
49
|
-
return `${where}
|
|
111
|
+
return `${where} must be non-empty text`;
|
|
50
112
|
if (chars(value) > max)
|
|
51
|
-
return `${where}
|
|
113
|
+
return `${where} is over ${max.toLocaleString('en-US')} characters (${chars(value)} characters)`;
|
|
52
114
|
return null;
|
|
53
115
|
}
|
|
54
116
|
/** 칸을 모두 아는 객체인가. 칸 이름을 잘못 적으면 조용히 빠지므로 모르는 칸은 받지 않는다. */
|
|
55
117
|
function objectProblem(where, value, known) {
|
|
56
118
|
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
57
|
-
return `${where}
|
|
119
|
+
return `${where} must be an object`;
|
|
58
120
|
const extra = Object.keys(value).filter((k) => !known.includes(k));
|
|
59
|
-
return extra.length > 0 ? `${where}
|
|
121
|
+
return extra.length > 0 ? `${where} has unknown fields: ${extra.join(', ')}` : null;
|
|
60
122
|
}
|
|
61
123
|
function requiresProblem(value) {
|
|
62
124
|
const problem = objectProblem('requires', value, ['os', 'external']);
|
|
@@ -65,21 +127,24 @@ function requiresProblem(value) {
|
|
|
65
127
|
const r = value;
|
|
66
128
|
if (r.os !== undefined && r.os !== 'any') {
|
|
67
129
|
if (!Array.isArray(r.os) || r.os.length === 0)
|
|
68
|
-
return 'requires.os
|
|
130
|
+
return 'requires.os must be "any" or a list of windows, macos, linux';
|
|
69
131
|
const bad = r.os.filter((o) => typeof o !== 'string' || !OS_NAMES.includes(o));
|
|
70
132
|
if (bad.length > 0)
|
|
71
|
-
return `requires.os
|
|
133
|
+
return `requires.os has an unknown operating system: ${bad.map((o) => JSON.stringify(o)).join(', ')}`;
|
|
72
134
|
if (new Set(r.os).size !== r.os.length)
|
|
73
|
-
return 'requires.os
|
|
135
|
+
return 'requires.os repeats the same operating system';
|
|
74
136
|
}
|
|
75
137
|
if (r.external !== undefined) {
|
|
76
138
|
if (!Array.isArray(r.external))
|
|
77
|
-
return 'requires.external
|
|
139
|
+
return 'requires.external must be a list of external tools';
|
|
78
140
|
if (r.external.length > 10)
|
|
79
|
-
return `requires.external
|
|
141
|
+
return `requires.external can have up to 10 entries (${r.external.length} given)`;
|
|
142
|
+
// 화면은 connectExternal 에 name 을 주고 코어는 connect.connection 으로 연결을 만든다. 둘 다 겹치면 어느 것인지 모른다(032 44.3절)
|
|
143
|
+
const connectNames = new Set();
|
|
144
|
+
const connections = new Set();
|
|
80
145
|
for (const [i, t] of r.external.entries()) {
|
|
81
146
|
const where = `requires.external[${i}]`;
|
|
82
|
-
const shape = objectProblem(where, t, ['name', 'kind', 'account', 'install', 'note']);
|
|
147
|
+
const shape = objectProblem(where, t, ['name', 'kind', 'account', 'install', 'note', 'connect']);
|
|
83
148
|
if (shape)
|
|
84
149
|
return shape;
|
|
85
150
|
const tool = t;
|
|
@@ -87,16 +152,30 @@ function requiresProblem(value) {
|
|
|
87
152
|
if (name)
|
|
88
153
|
return name;
|
|
89
154
|
if (typeof tool.kind !== 'string' || !TOOL_KINDS.includes(tool.kind))
|
|
90
|
-
return `${where}.kind
|
|
155
|
+
return `${where}.kind must be one of program, web, mcp`;
|
|
91
156
|
if (typeof tool.account !== 'string' || !ACCOUNTS.includes(tool.account))
|
|
92
|
-
return `${where}.account
|
|
157
|
+
return `${where}.account must be one of none, free, paid`;
|
|
93
158
|
if (typeof tool.install !== 'boolean')
|
|
94
|
-
return `${where}.install
|
|
159
|
+
return `${where}.install must be true or false`;
|
|
95
160
|
if (tool.note !== undefined) {
|
|
96
161
|
const note = textProblem(`${where}.note`, tool.note, 200);
|
|
97
162
|
if (note)
|
|
98
163
|
return note;
|
|
99
164
|
}
|
|
165
|
+
if (tool.connect !== undefined) {
|
|
166
|
+
if (tool.kind !== 'mcp')
|
|
167
|
+
return `${where}.connect is only for kind "mcp" (an MCP server the core connects to)`;
|
|
168
|
+
const connect = connectProblem(`${where}.connect`, tool.connect);
|
|
169
|
+
if (connect)
|
|
170
|
+
return connect;
|
|
171
|
+
const c = tool.connect;
|
|
172
|
+
if (connectNames.has(tool.name))
|
|
173
|
+
return `requires.external has two entries with connect named ${tool.name}`;
|
|
174
|
+
if (connections.has(c.connection))
|
|
175
|
+
return `requires.external has two entries that make the connection ${c.connection}`;
|
|
176
|
+
connectNames.add(tool.name);
|
|
177
|
+
connections.add(c.connection);
|
|
178
|
+
}
|
|
100
179
|
}
|
|
101
180
|
}
|
|
102
181
|
return null;
|
|
@@ -107,14 +186,14 @@ function requiresProblem(value) {
|
|
|
107
186
|
*/
|
|
108
187
|
function manualProblem(m) {
|
|
109
188
|
if (m.manual !== undefined && (!isPluginPath(m.manual) || !m.manual.endsWith('.md'))) {
|
|
110
|
-
return `manual ${JSON.stringify(m.manual)}
|
|
189
|
+
return `manual ${JSON.stringify(m.manual)} must be a relative path to a Markdown file (.md) inside the plugin folder (for example docs/manual.md)`;
|
|
111
190
|
}
|
|
112
191
|
if (m.samples === undefined)
|
|
113
192
|
return null;
|
|
114
193
|
if (!Array.isArray(m.samples))
|
|
115
|
-
return 'samples
|
|
194
|
+
return 'samples must be a list of { id, title, about, file }';
|
|
116
195
|
if (m.samples.length > MAX_SAMPLES)
|
|
117
|
-
return `samples
|
|
196
|
+
return `samples can have up to 5 entries (${m.samples.length} given)`;
|
|
118
197
|
const ids = new Set();
|
|
119
198
|
const files = new Set();
|
|
120
199
|
for (const [i, s] of m.samples.entries()) {
|
|
@@ -124,16 +203,16 @@ function manualProblem(m) {
|
|
|
124
203
|
return shape;
|
|
125
204
|
const sample = s;
|
|
126
205
|
if (typeof sample.id !== 'string' || !SAMPLE_ID.test(sample.id))
|
|
127
|
-
return `${where}.id
|
|
206
|
+
return `${where}.id must be 1 to 40 characters of lowercase English letters, digits, and -`;
|
|
128
207
|
const text = textProblem(`${where}.title`, sample.title, 100) ?? textProblem(`${where}.about`, sample.about, 300);
|
|
129
208
|
if (text)
|
|
130
209
|
return text;
|
|
131
210
|
if (!isPluginPath(sample.file) || !sample.file.endsWith('.json'))
|
|
132
|
-
return `${where}.file ${JSON.stringify(sample.file)}
|
|
211
|
+
return `${where}.file ${JSON.stringify(sample.file)} must be a relative path to a sample file (.json) inside the plugin folder (for example samples/first.json)`;
|
|
133
212
|
if (ids.has(sample.id))
|
|
134
|
-
return `samples
|
|
213
|
+
return `samples has the id ${sample.id} twice`;
|
|
135
214
|
if (files.has(sample.file))
|
|
136
|
-
return `samples
|
|
215
|
+
return `samples has the file ${sample.file} twice`;
|
|
137
216
|
ids.add(sample.id);
|
|
138
217
|
files.add(sample.file);
|
|
139
218
|
}
|
|
@@ -141,19 +220,19 @@ function manualProblem(m) {
|
|
|
141
220
|
}
|
|
142
221
|
function dependenciesProblem(id, value) {
|
|
143
222
|
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
144
|
-
return 'dependencies
|
|
223
|
+
return 'dependencies must be an object { "<id>": "<version range>" }';
|
|
145
224
|
const entries = Object.entries(value);
|
|
146
225
|
if (entries.length > MAX_DEPENDENCIES)
|
|
147
|
-
return `dependencies
|
|
226
|
+
return `dependencies can have up to ${MAX_DEPENDENCIES} entries (${entries.length} given)`;
|
|
148
227
|
for (const [dep, range] of entries) {
|
|
149
228
|
if (!isPluginId(dep))
|
|
150
|
-
return
|
|
229
|
+
return `${JSON.stringify(dep)} in dependencies is not shaped like a plugin id`;
|
|
151
230
|
if (RESERVED_IDS.includes(dep))
|
|
152
|
-
return `
|
|
231
|
+
return `Do not list ${dep} in dependencies. It is a name built into the core`;
|
|
153
232
|
if (dep === id)
|
|
154
|
-
return '
|
|
233
|
+
return 'Do not list the plugin itself in dependencies';
|
|
155
234
|
if (!isRange(range))
|
|
156
|
-
return
|
|
235
|
+
return `${JSON.stringify(range)} in dependencies.${dep} must have one of the shapes 1.2.3, ^1.2.3, ~1.2.3, >=1.2.3`;
|
|
157
236
|
}
|
|
158
237
|
return null;
|
|
159
238
|
}
|
|
@@ -163,28 +242,28 @@ function dependenciesProblem(id, value) {
|
|
|
163
242
|
*/
|
|
164
243
|
export function checkManifest(manifest) {
|
|
165
244
|
if (typeof manifest !== 'object' || manifest === null || Array.isArray(manifest))
|
|
166
|
-
return 'manifest
|
|
245
|
+
return 'manifest must be an object';
|
|
167
246
|
const m = manifest;
|
|
168
247
|
for (const key of ['id', 'version', 'logic']) {
|
|
169
248
|
if (typeof m[key] !== 'string')
|
|
170
|
-
return `manifest
|
|
249
|
+
return `manifest has no ${key}`;
|
|
171
250
|
}
|
|
172
251
|
const id = m.id;
|
|
173
252
|
if (!isPluginId(id))
|
|
174
|
-
return `id ${JSON.stringify(id)}
|
|
253
|
+
return `id ${JSON.stringify(id)} must look like account.plugin-name. Each part is 2 to 40 characters of lowercase English letters, digits, and -`;
|
|
175
254
|
if (RESERVED_IDS.includes(id))
|
|
176
|
-
return `id ${id}
|
|
255
|
+
return `id ${id} is a name built into the core, so it cannot be used as a plugin id`;
|
|
177
256
|
if (!isVersion(m.version))
|
|
178
|
-
return `version ${JSON.stringify(m.version)}
|
|
257
|
+
return `version ${JSON.stringify(m.version)} must be semver (number.number.number, optionally followed by -prerelease-name)`;
|
|
179
258
|
if (typeof m.dataVersion !== 'number' || !Number.isInteger(m.dataVersion) || m.dataVersion < 1)
|
|
180
|
-
return 'dataVersion
|
|
259
|
+
return 'dataVersion must be an integer of 1 or more';
|
|
181
260
|
if (!isPluginPath(m.logic))
|
|
182
|
-
return `logic ${JSON.stringify(m.logic)}
|
|
261
|
+
return `logic ${JSON.stringify(m.logic)} must be a relative path inside the plugin folder (.. and absolute paths are not accepted)`;
|
|
183
262
|
if (m.ui !== undefined && !isUiPath(m.ui))
|
|
184
|
-
return `ui ${JSON.stringify(m.ui)}
|
|
263
|
+
return `ui ${JSON.stringify(m.ui)} must be a file directly under ui/ (for example ui/index.html)`;
|
|
185
264
|
// 아이콘은 코어가 내보내는 ui/ 의 파일이어야 화면이 읽는다. icon.ts 의 isIconPath 와 같은 모양이다(서로 불러오지 않게 여기에 적는다)
|
|
186
265
|
if (m.icon !== undefined && (!isUiPath(m.icon) || !m.icon.toLowerCase().endsWith('.svg'))) {
|
|
187
|
-
return `icon ${JSON.stringify(m.icon)}
|
|
266
|
+
return `icon ${JSON.stringify(m.icon)} must be an SVG file (.svg) directly under ui/ (for example ui/icon.svg)`;
|
|
188
267
|
}
|
|
189
268
|
if (m.title !== undefined) {
|
|
190
269
|
const problem = textProblem('title', m.title, 100);
|
|
@@ -203,9 +282,9 @@ export function checkManifest(manifest) {
|
|
|
203
282
|
}
|
|
204
283
|
if (m.examples !== undefined) {
|
|
205
284
|
if (!Array.isArray(m.examples))
|
|
206
|
-
return 'examples
|
|
285
|
+
return 'examples must be a list of { ask, does }';
|
|
207
286
|
if (m.examples.length > 5)
|
|
208
|
-
return `examples
|
|
287
|
+
return `examples can have up to 5 entries (${m.examples.length} given)`;
|
|
209
288
|
for (const [i, e] of m.examples.entries()) {
|
|
210
289
|
const where = `examples[${i}]`;
|
|
211
290
|
const problem = objectProblem(where, e, ['ask', 'does']) ??
|
|
@@ -221,7 +300,7 @@ export function checkManifest(manifest) {
|
|
|
221
300
|
return problem;
|
|
222
301
|
}
|
|
223
302
|
if (m.protocol !== undefined && !isProtocolRange(m.protocol)) {
|
|
224
|
-
return `protocol ${JSON.stringify(m.protocol)}
|
|
303
|
+
return `protocol ${JSON.stringify(m.protocol)} must look like 0.<number> (for example "0.1")`;
|
|
225
304
|
}
|
|
226
305
|
if (m.dependencies !== undefined) {
|
|
227
306
|
const problem = dependenciesProblem(id, m.dependencies);
|
|
@@ -240,5 +319,5 @@ export function checkForRegistry(manifest) {
|
|
|
240
319
|
return problem;
|
|
241
320
|
const m = manifest;
|
|
242
321
|
const missing = ['protocol', 'license', 'title', 'about'].filter((k) => m[k] === undefined);
|
|
243
|
-
return missing.length > 0 ?
|
|
322
|
+
return missing.length > 0 ? `To upload to the site, the manifest needs the field(s) ${missing.join(', ')}` : null;
|
|
244
323
|
}
|
package/dist/messages.js
CHANGED
|
@@ -55,7 +55,7 @@ function valueEdgeProblems(text) {
|
|
|
55
55
|
const beforeOk = before === null || VALUE_EDGE.test(before);
|
|
56
56
|
const afterOk = after === null || VALUE_EDGE.test(after) || (after === '.' && (end + 1 >= text.length || text[end + 1] === ' '));
|
|
57
57
|
if (!beforeOk || !afterOk) {
|
|
58
|
-
out.push(`{${m[1]}}
|
|
58
|
+
out.push(`The characters right before and after {${m[1]}} must be a space or punctuation (, ; ! ? ( ) ' "). A period may follow it only at the end of a sentence (followed by a space or the end of the text)`);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
return out;
|
|
@@ -67,33 +67,33 @@ function valueEdgeProblems(text) {
|
|
|
67
67
|
*/
|
|
68
68
|
function textProblems(text, names) {
|
|
69
69
|
if (typeof text !== 'string' || text === '')
|
|
70
|
-
return ['text
|
|
70
|
+
return ['text must be non-empty text'];
|
|
71
71
|
const out = [];
|
|
72
72
|
if (text.length > MESSAGE_TEXT_MAX)
|
|
73
|
-
out.push(
|
|
73
|
+
out.push(`The text is over ${MESSAGE_TEXT_MAX} characters (${text.length} characters)`);
|
|
74
74
|
if ([...text].some((c) => c.charCodeAt(0) < 0x20 || c.charCodeAt(0) > 0x7e))
|
|
75
|
-
out.push('
|
|
75
|
+
out.push('The text may only use visible ASCII (0x20 to 0x7E). Line breaks and non-English characters are not accepted');
|
|
76
76
|
if (!/[A-Za-z]/.test(text))
|
|
77
|
-
out.push('
|
|
77
|
+
out.push('The text must be an English sentence');
|
|
78
78
|
if (hasAddress(text))
|
|
79
|
-
out.push('
|
|
79
|
+
out.push('The text cannot contain addresses (://, www., a period between letters, and @ are not accepted)');
|
|
80
80
|
if (/[<>[\]`\\]/.test(text))
|
|
81
|
-
out.push('
|
|
81
|
+
out.push('The text must not use < > [ ] backticks or backslashes');
|
|
82
82
|
out.push(...valueEdgeProblems(text));
|
|
83
83
|
const used = new Set();
|
|
84
84
|
for (const m of text.matchAll(PLACEHOLDER)) {
|
|
85
85
|
const name = m[1];
|
|
86
86
|
if (!VALUE_NAME.test(name))
|
|
87
|
-
out.push(`{${name}}
|
|
87
|
+
out.push(`{${name}} is not shaped like a value name (starts with a lowercase English letter, up to 32 lowercase letters, digits, and _)`);
|
|
88
88
|
else if (!names.includes(name))
|
|
89
|
-
out.push(`{${name}}
|
|
89
|
+
out.push(`{${name}} is not in values`);
|
|
90
90
|
used.add(name);
|
|
91
91
|
}
|
|
92
92
|
if (/[{}]/.test(text.replace(PLACEHOLDER, '')))
|
|
93
|
-
out.push('
|
|
93
|
+
out.push('There is an unmatched { or }');
|
|
94
94
|
for (const n of names)
|
|
95
95
|
if (!used.has(n))
|
|
96
|
-
out.push(
|
|
96
|
+
out.push(`${n} in values does not appear in the text`);
|
|
97
97
|
return out;
|
|
98
98
|
}
|
|
99
99
|
/** values 의 까닭들. 이름마다 종류 하나이고, enum 은 낱말 목록을 함께 적는다. */
|
|
@@ -101,34 +101,34 @@ function valuesProblems(values) {
|
|
|
101
101
|
if (values === undefined)
|
|
102
102
|
return [];
|
|
103
103
|
if (!isPlainObject(values))
|
|
104
|
-
return ['values
|
|
104
|
+
return ['values must be an object that gives a type for each name'];
|
|
105
105
|
const out = [];
|
|
106
106
|
for (const [name, spec] of Object.entries(values)) {
|
|
107
|
-
const at =
|
|
107
|
+
const at = `value ${name}`;
|
|
108
108
|
if (!VALUE_NAME.test(name))
|
|
109
|
-
out.push(`${at}:
|
|
109
|
+
out.push(`${at}: the name starts with a lowercase English letter and has up to 32 lowercase letters, digits, and _`);
|
|
110
110
|
if (!isPlainObject(spec) || !MESSAGE_VALUE_TYPES.includes(spec.type)) {
|
|
111
|
-
out.push(`${at}: type
|
|
111
|
+
out.push(`${at}: type must be one of ${MESSAGE_VALUE_TYPES.join(', ')}. There is no free text value`);
|
|
112
112
|
continue;
|
|
113
113
|
}
|
|
114
114
|
const extra = Object.keys(spec).filter((k) => k !== 'type' && !(spec.type === 'enum' && k === 'values'));
|
|
115
115
|
if (extra.length)
|
|
116
|
-
out.push(`${at}:
|
|
116
|
+
out.push(`${at}: unknown fields ${extra.join(', ')}`);
|
|
117
117
|
if (spec.type !== 'enum')
|
|
118
118
|
continue;
|
|
119
119
|
const words = spec.values;
|
|
120
120
|
if (!Array.isArray(words) || words.length === 0 || words.length > MESSAGE_ENUM_MAX_VALUES) {
|
|
121
|
-
out.push(`${at}: enum
|
|
121
|
+
out.push(`${at}: the values of an enum must be a list of 1 to ${MESSAGE_ENUM_MAX_VALUES} words`);
|
|
122
122
|
continue;
|
|
123
123
|
}
|
|
124
124
|
for (const w of words) {
|
|
125
125
|
if (typeof w !== 'string' || w.length > MESSAGE_ENUM_WORD_MAX || !ENUM_WORD.test(w)) {
|
|
126
|
-
out.push(`${at}: enum
|
|
126
|
+
out.push(`${at}: an enum word has up to ${MESSAGE_ENUM_WORD_MAX} English letters, digits, spaces, and _-`);
|
|
127
127
|
break;
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
if (new Set(words).size !== words.length)
|
|
131
|
-
out.push(`${at}: enum
|
|
131
|
+
out.push(`${at}: enum words repeat`);
|
|
132
132
|
}
|
|
133
133
|
return out;
|
|
134
134
|
}
|
|
@@ -139,7 +139,7 @@ function valuesProblems(values) {
|
|
|
139
139
|
export function checkMessageTable(data) {
|
|
140
140
|
const bytes = typeof data === 'string' ? new TextEncoder().encode(data) : data;
|
|
141
141
|
if (bytes.byteLength > MESSAGE_TABLE_MAX_BYTES)
|
|
142
|
-
return { ok: false, problems: [
|
|
142
|
+
return { ok: false, problems: [`The table file is over ${MESSAGE_TABLE_MAX_BYTES} bytes (${bytes.byteLength} bytes)`] };
|
|
143
143
|
let raw;
|
|
144
144
|
try {
|
|
145
145
|
const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
@@ -147,38 +147,38 @@ export function checkMessageTable(data) {
|
|
|
147
147
|
}
|
|
148
148
|
catch {
|
|
149
149
|
// 해석기의 글은 파일의 일부를 옮겨 적을 수 있어 까닭은 적지 않는다.
|
|
150
|
-
return { ok: false, problems: ['
|
|
150
|
+
return { ok: false, problems: ['The table file is not UTF-8 JSON'] };
|
|
151
151
|
}
|
|
152
152
|
if (!isPlainObject(raw))
|
|
153
|
-
return { ok: false, problems: ['
|
|
153
|
+
return { ok: false, problems: ['The table must be an object with format, version, and messages'] };
|
|
154
154
|
const problems = [];
|
|
155
155
|
const extra = Object.keys(raw).filter((k) => !['format', 'version', 'messages'].includes(k));
|
|
156
156
|
if (extra.length)
|
|
157
|
-
problems.push(
|
|
157
|
+
problems.push(`Unknown fields: ${extra.join(', ')}`);
|
|
158
158
|
if (raw.format !== MESSAGE_TABLE_FORMAT)
|
|
159
|
-
problems.push(`format
|
|
159
|
+
problems.push(`format must be ${MESSAGE_TABLE_FORMAT}`);
|
|
160
160
|
if (!isVersion(raw.version))
|
|
161
|
-
problems.push('version
|
|
161
|
+
problems.push('version must be semver such as 1.0.0');
|
|
162
162
|
if (!isPlainObject(raw.messages)) {
|
|
163
|
-
problems.push('messages
|
|
163
|
+
problems.push('messages must be an object that gives text for each message id');
|
|
164
164
|
return { ok: false, problems };
|
|
165
165
|
}
|
|
166
166
|
const entries = Object.entries(raw.messages);
|
|
167
167
|
if (entries.length === 0)
|
|
168
|
-
problems.push('messages
|
|
168
|
+
problems.push('messages is empty');
|
|
169
169
|
if (entries.length > MESSAGE_TABLE_MAX_MESSAGES)
|
|
170
|
-
problems.push(
|
|
170
|
+
problems.push(`There are more than ${MESSAGE_TABLE_MAX_MESSAGES} messages (${entries.length})`);
|
|
171
171
|
for (const [id, def] of entries) {
|
|
172
|
-
const at =
|
|
172
|
+
const at = `message ${MESSAGE_ID.test(id) ? id : '(malformed id)'}`;
|
|
173
173
|
if (!MESSAGE_ID.test(id))
|
|
174
|
-
problems.push(`${at}: id
|
|
174
|
+
problems.push(`${at}: the id starts with a lowercase English letter and has up to 64 lowercase letters, digits, and _`);
|
|
175
175
|
if (!isPlainObject(def)) {
|
|
176
|
-
problems.push(`${at}:
|
|
176
|
+
problems.push(`${at}: must be an object with text and values`);
|
|
177
177
|
continue;
|
|
178
178
|
}
|
|
179
179
|
const unknown = Object.keys(def).filter((k) => k !== 'text' && k !== 'values');
|
|
180
180
|
if (unknown.length)
|
|
181
|
-
problems.push(`${at}:
|
|
181
|
+
problems.push(`${at}: unknown fields ${unknown.join(', ')}`);
|
|
182
182
|
const vp = valuesProblems(def.values);
|
|
183
183
|
for (const p of vp)
|
|
184
184
|
problems.push(`${at}: ${p}`);
|
|
@@ -189,7 +189,7 @@ export function checkMessageTable(data) {
|
|
|
189
189
|
if (problems.length > 0) {
|
|
190
190
|
const shown = problems.slice(0, MAX_PROBLEMS);
|
|
191
191
|
if (problems.length > MAX_PROBLEMS)
|
|
192
|
-
shown.push(
|
|
192
|
+
shown.push(`${problems.length - MAX_PROBLEMS} more`);
|
|
193
193
|
return { ok: false, problems: shown };
|
|
194
194
|
}
|
|
195
195
|
return { ok: true, table: raw };
|
package/dist/sample.d.ts
CHANGED
|
@@ -3,7 +3,10 @@ export declare const SAMPLE_FORMAT = "aic-sample/1";
|
|
|
3
3
|
export declare const MANUAL_MAX_CHARS = 50000;
|
|
4
4
|
/** 예제 파일 하나의 한도(글자, 037 7절 4번). */
|
|
5
5
|
export declare const SAMPLE_MAX_CHARS = 200000;
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* 예제를 쓴 참여자. 실제 이름 대신 "Person", "AI" 이고, 같은 종류가 여럿이면 "Person 2" 처럼 번호를 붙인다. 참여자가 없는 revision 은 "Core" 다.
|
|
8
|
+
* 새로 내보내는 파일은 영어로 쓰고, 옛 파일의 "사람", "코어" 도 읽는다(999 4.2절, rawdev 2026-11-30).
|
|
9
|
+
*/
|
|
7
10
|
export declare const SAMPLE_WHO: RegExp;
|
|
8
11
|
/** 예제가 쓴 플러그인 하나. version 은 그 작업에 적힌 가장 높은 버전이다. */
|
|
9
12
|
export interface SamplePlugin {
|
|
@@ -132,7 +135,7 @@ export declare function charCount(s: string): number;
|
|
|
132
135
|
/**
|
|
133
136
|
* 예제 파일(aic-sample/1)의 검사. 문제의 설명이고 없으면 null 이다. 맨 위 층과 revision 과 원인에 모르는 칸이 있으면 거절한다.
|
|
134
137
|
* 예제는 실제 작업을 내보낸 것이어야 하고(037 7절 2번), 내보낼 때 지운 것(참여자 이름, 도구, 시각, 연결 정의)이 다시 들어가지
|
|
135
|
-
* 않게 하려는 것이다. 참여자는 "
|
|
138
|
+
* 않게 하려는 것이다. 참여자는 "Person", "AI", "Core" 로만 적는다(옛 파일의 "사람", "코어" 도 받는다).
|
|
136
139
|
*/
|
|
137
140
|
export declare function checkSample(value: unknown): string | null;
|
|
138
141
|
/** 예제 파일의 글(바이트)을 풀고 검사한다. 맞으면 { ok: true, sample }, 틀리면 까닭이다. 글자 한도도 본다. */
|