@vini-ds/agent 0.1.0-alpha.13 → 0.1.0-alpha.15

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/mcp.mjs CHANGED
@@ -18,6 +18,7 @@ const exampleFileMaxBytes = 128 * 1024;
18
18
  // Resource content (including JSON quoting of its text) must fit this bound.
19
19
  // Unusually large metadata fails closed instead of returning partial details.
20
20
  const exampleResourceMaxBytes = 4000;
21
+ const resourceResponseBytes = resource => Buffer.byteLength(JSON.stringify({ jsonrpc: '2.0', id: 99999999, result: { contents: [resource] } }), 'utf8');
21
22
  const sha256 = (bytes) => `sha256:${createHash('sha256').update(bytes).digest('hex')}`;
22
23
  const protocols = ['2025-06-18', '2025-03-26', '2024-11-05', '2026-07-28'];
23
24
  const annotations = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false };
@@ -54,7 +55,20 @@ async function loadOptionalCatalog(metadata, countKey, file, kind) {
54
55
  const announced = own(metadata, countKey);
55
56
  if (announced && (!Number.isSafeInteger(metadata[countKey]) || metadata[countKey] < 0)) throw new Error(`Invalid ${countKey}`);
56
57
  let entries;
57
- try { entries = await load(file); }
58
+ try {
59
+ if (kind === 'example' && own(metadata, 'exampleShards')) {
60
+ const shards = metadata.exampleShards;
61
+ if (!announced || !Array.isArray(shards) || new Set(shards).size !== shards.length || shards.some(name => typeof name !== 'string' || !/^context\/examples\/[a-z0-9-]+\.json$/u.test(name))) throw new Error('Invalid example shards');
62
+ const arrays = await Promise.all(shards.map(async name => {
63
+ const { bytes } = await boundedBytes(path.join(root, name));
64
+ if (bytes.length > 2 * 1024 * 1024) throw new Error('Example shard exceeds 2 MiB');
65
+ const value = JSON.parse(bytes.toString('utf8'));
66
+ if (!Array.isArray(value)) throw new Error('Invalid example shard');
67
+ return value;
68
+ }));
69
+ entries = arrays.flat();
70
+ } else entries = await load(file);
71
+ }
58
72
  catch (error) { if (!announced && error.code === 'ENOENT') return []; throw error; }
59
73
  if (!Array.isArray(entries) || (announced && entries.length !== metadata[countKey])) throw new Error(`Invalid ${kind} catalog or count`);
60
74
  const ids = new Set();
@@ -68,9 +82,12 @@ async function loadOptionalCatalog(metadata, countKey, file, kind) {
68
82
  if (!validText(entry.title) || !validText(entry.description) || !textArray(entry.componentIds) || !textArray(entry.patternIds) || !textArray(entry.limitations) || !Array.isArray(entry.files) || !entry.files.length) throw new Error('Invalid example');
69
83
  const names = new Set();
70
84
  for (const file of entry.files) {
71
- if (!file || typeof file !== 'object' || Array.isArray(file) || !validText(file.name) || !/^[A-Za-z0-9][A-Za-z0-9.-]*\.(?:jsx|tsx|css)$/u.test(file.name) || names.has(file.name) || !validText(file.language) || !validText(file.source)) throw new Error('Invalid example');
72
- const bytes = Buffer.from(file.source, 'utf8');
73
- if (bytes.length > exampleFileMaxBytes || bytes.toString('utf8') !== file.source) throw new Error('Invalid example file encoding or size');
85
+ const sharded = own(metadata, 'exampleShards');
86
+ const safePath = file && typeof file.name === 'string' && file.name.split('/').every(segment => /^[A-Za-z0-9_@+-][A-Za-z0-9._@+-]*$/u.test(segment) && segment !== '.' && segment !== '..');
87
+ if (!file || typeof file !== 'object' || Array.isArray(file) || !validText(file.name) || !(sharded ? safePath : /^[A-Za-z0-9][A-Za-z0-9.-]*\.(?:jsx|tsx|css)$/u.test(file.name)) || names.has(file.name) || !validText(file.language) || typeof file.source !== 'string' || (!sharded && !validText(file.source))) throw new Error('Invalid example');
88
+ if (file.encoding !== undefined && (!sharded || file.encoding !== 'base64')) throw new Error('Invalid example file encoding');
89
+ const bytes = Buffer.from(file.source, file.encoding === 'base64' ? 'base64' : 'utf8');
90
+ if (bytes.length > (sharded ? 1024 * 1024 : exampleFileMaxBytes) || (file.encoding === 'base64' ? bytes.toString('base64') !== file.source : bytes.toString('utf8') !== file.source)) throw new Error('Invalid example file encoding or size');
74
91
  names.add(file.name);
75
92
  }
76
93
  }
@@ -121,7 +138,7 @@ export async function createPublicService() {
121
138
  const examplesById = new Map(examples.map((example) => [example.id, example]));
122
139
  // Compute hashes from the immutable in-memory snapshot, not mutable paths.
123
140
  const exampleFilesById = new Map(examples.map((example) => [example.id, new Map(example.files.map((file) => {
124
- const bytes = Buffer.from(file.source, 'utf8');
141
+ const bytes = Buffer.from(file.source, file.encoding === 'base64' ? 'base64' : 'utf8');
125
142
  return [file.name, { name: file.name, language: file.language, bytes, sha256: sha256(bytes), partCount: Math.ceil(bytes.length / examplePartBytes) }];
126
143
  }))]));
127
144
  const byId = new Map(components.map((component) => [component.id, component]));
@@ -142,6 +159,26 @@ export async function createPublicService() {
142
159
  { uri: 'vini://examples', name: 'VINi public examples', mimeType: 'application/json' },
143
160
  ];
144
161
  const envelope = (data) => ({ packageVersion: metadata.version, baseline: metadata.baseline, ...data });
162
+ const shardedExamples = own(metadata, 'exampleShards');
163
+ // Keep each page below the existing client-safe response limit, including the
164
+ // JSON encoding of resource text in a JSON-RPC response. Fail closed if even
165
+ // a single entry cannot be represented rather than silently losing it.
166
+ function paginate(items, render, uri) {
167
+ const pages = [[]];
168
+ for (const item of items) {
169
+ const page = pages[pages.length - 1];
170
+ page.push(item);
171
+ if (resourceResponseBytes({ uri, mimeType: 'application/json', text: JSON.stringify(render(page)) }) > 3500) {
172
+ page.pop();
173
+ if (!page.length) throw new Error('Example page entry exceeds bounded response size');
174
+ pages.push([item]);
175
+ if (resourceResponseBytes({ uri, mimeType: 'application/json', text: JSON.stringify(render([item])) }) > 3500) throw new Error('Example page entry exceeds bounded response size');
176
+ }
177
+ }
178
+ return pages;
179
+ }
180
+ const exampleSummaries = examples.map(({ id, title, description, componentIds, patternIds, files }) => ({ id, title, description, componentIds, patternIds, fileCount: files.length }));
181
+ const examplePages = shardedExamples ? paginate(exampleSummaries, page => envelope({ examples: page, page: 999999, pageCount: 999999, total: examples.length, next: 'vini://examples/pages/999999' }), 'vini://examples/pages/999999') : [];
145
182
  function contract(id, platform) {
146
183
  requiredString(id, 'id');
147
184
  if (platform !== undefined && platform !== 'web') throw new Error('Only the public React DOM/web profile is available');
@@ -161,14 +198,17 @@ export async function createPublicService() {
161
198
  }
162
199
  function exampleManifest(id) {
163
200
  const { title, componentIds, patternIds } = exampleById(id);
164
- return envelope({ example: { id, title, componentIds, patternIds, files: [...exampleFilesById.get(id).values()].map(({ name, language, bytes, sha256: hash, partCount }) => ({
201
+ const files = [...exampleFilesById.get(id).values()].map(({ name, language, bytes, sha256: hash, partCount }, index) => ({
165
202
  name, language, byteLength: bytes.length, sha256: hash, encoding: 'base64', partBytes: examplePartBytes, partCount,
166
- partUriTemplate: `vini://examples/${id}/files/${name}/parts/{index}`,
167
- })) } });
203
+ partUriTemplate: shardedExamples ? `vini://examples/${id}/file-index/${index}/parts/{index}` : `vini://examples/${id}/files/${name}/parts/{index}`,
204
+ }));
205
+ if (!shardedExamples) return envelope({ example: { id, title, componentIds, patternIds, files } });
206
+ const pages = paginate(files, page => envelope({ exampleId: id, files: page, page: 999999, pageCount: 999999, total: files.length, next: `vini://examples/${id}/files/pages/999999` }), `vini://examples/${id}/files/pages/999999`);
207
+ return envelope({ example: { id, title, componentIds, patternIds, fileCount: files.length, filePageCount: pages.length, filePageUriTemplate: `vini://examples/${id}/files/pages/{index}` } });
168
208
  }
169
209
  function exampleDetails(id) {
170
210
  const example = exampleById(id);
171
- const fields = ['id', 'title', 'description', 'componentIds', 'patternIds', 'limitations', 'sourceCorrespondence'];
211
+ const fields = ['id', 'title', 'description', 'componentIds', 'patternIds', 'limitations', 'sourceCorrespondence', 'dependencies', 'sourceFiles', 'atlas'];
172
212
  return envelope({ example: Object.fromEntries(fields.filter((field) => own(example, field)).map((field) => [field, example[field]])) });
173
213
  }
174
214
  function exampleFilePart(id, name, indexText) {
@@ -182,6 +222,24 @@ export async function createPublicService() {
182
222
  return envelope({ exampleId: id, file: { name: file.name, language: file.language, encoding: 'base64', byteLength: file.bytes.length, sha256: file.sha256,
183
223
  partBytes: examplePartBytes, partCount: file.partCount, index, partByteLength: bytes.length, partSha256: sha256(bytes), content: bytes.toString('base64') } });
184
224
  }
225
+ function pageIndex(value, length) {
226
+ if (!/^(?:0|[1-9][0-9]*)$/u.test(value) || !Number.isSafeInteger(Number(value)) || Number(value) >= length) throw new Error('Example page index out of range');
227
+ return Number(value);
228
+ }
229
+ function exampleFilePage(id, indexText) {
230
+ const manifest = exampleManifest(id).example;
231
+ const files = [...exampleFilesById.get(id).values()].map(({ name, language, bytes, sha256: hash, partCount }, index) => ({ name, language, byteLength: bytes.length, sha256: hash, encoding: 'base64', partBytes: examplePartBytes, partCount, partUriTemplate: `vini://examples/${id}/file-index/${index}/parts/{index}` }));
232
+ const pages = paginate(files, page => envelope({ exampleId: id, files: page, page: 999999, pageCount: 999999, total: files.length, next: `vini://examples/${id}/files/pages/999999` }), `vini://examples/${id}/files/pages/999999`);
233
+ const page = pageIndex(indexText, pages.length);
234
+ return envelope({ exampleId: id, files: pages[page], page, pageCount: pages.length, total: manifest.fileCount, next: page + 1 < pages.length ? `vini://examples/${id}/files/pages/${page + 1}` : null });
235
+ }
236
+ function exampleDetailsPart(id, indexText) {
237
+ const bytes = Buffer.from(JSON.stringify(exampleDetails(id)), 'utf8');
238
+ const partCount = Math.ceil(bytes.length / examplePartBytes);
239
+ const index = pageIndex(indexText, partCount);
240
+ const part = bytes.subarray(index * examplePartBytes, (index + 1) * examplePartBytes);
241
+ return envelope({ exampleId: id, details: { encoding: 'base64', byteLength: bytes.length, sha256: sha256(bytes), partBytes: examplePartBytes, partCount, index, partByteLength: part.length, partSha256: sha256(part), content: part.toString('base64') } });
242
+ }
185
243
  async function call(name, args = {}, signal) {
186
244
  const definition = toolDefinitions.find((tool) => tool.name === name);
187
245
  if (!definition) throw new Error(`Unknown tool ${name}`);
@@ -219,20 +277,52 @@ export async function createPublicService() {
219
277
  else if (uri === 'vini://components') data = components.map(({ id, displayName, exports }) => ({ id, displayName, exports }));
220
278
  else if (uri === 'vini://packages/react-dom-reference') data = profile;
221
279
  else if (uri === 'vini://patterns') data = envelope({ patterns: patterns.map(({ id, displayName }) => ({ id, displayName })) });
222
- else if (uri === 'vini://examples') data = envelope({ examples: examples.map(({ id, title, description, componentIds, patternIds, limitations }) => ({ id, title, description, componentIds, patternIds, limitations })) });
280
+ else if (uri === 'vini://examples') {
281
+ if (shardedExamples) { data = envelope({ paginated: true, total: examples.length, pageCount: examplePages.length, pageUriTemplate: 'vini://examples/pages/{index}', firstPage: 'vini://examples/pages/0' }); boundedExampleResource = true; }
282
+ else data = envelope({ examples: examples.map(({ id, title, description, componentIds, patternIds, limitations }) => ({ id, title, description, componentIds, patternIds, limitations })) });
283
+ }
284
+ else if (shardedExamples && /^vini:\/\/examples\/pages\/(?:0|[1-9][0-9]*)$/u.test(uri)) {
285
+ const page = pageIndex(uri.slice('vini://examples/pages/'.length), examplePages.length);
286
+ data = envelope({ examples: examplePages[page], page, pageCount: examplePages.length, total: examples.length, next: page + 1 < examplePages.length ? `vini://examples/pages/${page + 1}` : null }); boundedExampleResource = true;
287
+ }
223
288
  else if (/^vini:\/\/patterns\/[a-z0-9-]+$/u.test(uri)) data = envelope({ pattern: patternContract(uri.slice('vini://patterns/'.length)) });
224
289
  else if (/^vini:\/\/examples\/[a-z0-9-]+\/manifest$/u.test(uri)) { data = exampleManifest(uri.slice('vini://examples/'.length, -'/manifest'.length)); boundedExampleResource = true; }
225
- else if (/^vini:\/\/examples\/[a-z0-9-]+\/details$/u.test(uri)) { data = exampleDetails(uri.slice('vini://examples/'.length, -'/details'.length)); boundedExampleResource = true; }
290
+ else if (/^vini:\/\/examples\/[a-z0-9-]+\/details$/u.test(uri)) {
291
+ const id = uri.slice('vini://examples/'.length, -'/details'.length);
292
+ data = exampleDetails(id); boundedExampleResource = true;
293
+ const resource = { uri, mimeType: 'application/json', text: JSON.stringify(data) };
294
+ if (shardedExamples && resourceResponseBytes(resource) > exampleResourceMaxBytes) {
295
+ const bytes = Buffer.from(JSON.stringify(data), 'utf8');
296
+ data = envelope({ exampleId: id, paginated: true, details: { encoding: 'base64-json', byteLength: bytes.length, sha256: sha256(bytes), partBytes: examplePartBytes, partCount: Math.ceil(bytes.length / examplePartBytes), partUriTemplate: `vini://examples/${id}/details/parts/{index}` } });
297
+ }
298
+ }
299
+ else if (shardedExamples && /^vini:\/\/examples\/[a-z0-9-]+\/details\/parts\/(?:0|[1-9][0-9]*)$/u.test(uri)) {
300
+ const [, id, index] = /^vini:\/\/examples\/([a-z0-9-]+)\/details\/parts\/(0|[1-9][0-9]*)$/u.exec(uri);
301
+ data = exampleDetailsPart(id, index); boundedExampleResource = true;
302
+ }
303
+ else if (shardedExamples && /^vini:\/\/examples\/[a-z0-9-]+\/files\/pages\/(?:0|[1-9][0-9]*)$/u.test(uri)) {
304
+ const [, id, index] = /^vini:\/\/examples\/([a-z0-9-]+)\/files\/pages\/(0|[1-9][0-9]*)$/u.exec(uri);
305
+ data = exampleFilePage(id, index); boundedExampleResource = true;
306
+ }
307
+ else if (shardedExamples && /^vini:\/\/examples\/[a-z0-9-]+\/file-index\/(?:0|[1-9][0-9]*)\/parts\/(?:0|[1-9][0-9]*)$/u.test(uri)) {
308
+ const [, id, fileIndex, partIndex] = /^vini:\/\/examples\/([a-z0-9-]+)\/file-index\/(0|[1-9][0-9]*)\/parts\/(0|[1-9][0-9]*)$/u.exec(uri);
309
+ const files = [...exampleFilesById.get(exampleById(id).id).values()];
310
+ data = exampleFilePart(id, files[pageIndex(fileIndex, files.length)].name, partIndex); boundedExampleResource = true;
311
+ }
226
312
  else if (/^vini:\/\/examples\/[a-z0-9-]+\/files\/[A-Za-z0-9][A-Za-z0-9.-]*\.(?:jsx|tsx|css)\/parts\/(?:0|[1-9][0-9]*)$/u.test(uri)) {
227
313
  const [, id, name, index] = /^vini:\/\/examples\/([a-z0-9-]+)\/files\/([A-Za-z0-9][A-Za-z0-9.-]*\.(?:jsx|tsx|css))\/parts\/(0|[1-9][0-9]*)$/u.exec(uri);
228
314
  data = exampleFilePart(id, name, index);
229
315
  boundedExampleResource = true;
230
316
  }
231
- else if (/^vini:\/\/examples\/[a-z0-9-]+$/u.test(uri)) data = envelope({ example: exampleById(uri.slice('vini://examples/'.length)) });
317
+ else if (/^vini:\/\/examples\/[a-z0-9-]+$/u.test(uri)) {
318
+ data = envelope({ example: exampleById(uri.slice('vini://examples/'.length)) });
319
+ const resource = { uri, mimeType: 'application/json', text: JSON.stringify(data) };
320
+ if (shardedExamples && resourceResponseBytes(resource) > exampleResourceMaxBytes) throw new Error('Example is too large; use its manifest and file pages');
321
+ }
232
322
  else if (/^vini:\/\/components\/[a-z0-9-]+$/u.test(uri)) data = contract(uri.slice('vini://components/'.length));
233
323
  else throw new Error(`Unknown resource ${uri}`);
234
324
  const resource = { uri, mimeType: 'application/json', text: JSON.stringify(data) };
235
- if (boundedExampleResource && Buffer.byteLength(JSON.stringify({ contents: [resource] }), 'utf8') > exampleResourceMaxBytes) throw new Error('Example resource exceeds bounded response size');
325
+ if (boundedExampleResource && resourceResponseBytes(resource) > exampleResourceMaxBytes) throw new Error('Example resource exceeds bounded response size');
236
326
  return resource;
237
327
  }
238
328
  const resourceTemplates = [
@@ -242,6 +332,12 @@ export async function createPublicService() {
242
332
  { uriTemplate: 'vini://examples/{id}/manifest', name: 'VINi example file manifest', mimeType: 'application/json' },
243
333
  { uriTemplate: 'vini://examples/{id}/details', name: 'VINi example details and limitations', mimeType: 'application/json' },
244
334
  { uriTemplate: 'vini://examples/{id}/files/{filename}/parts/{index}', name: 'VINi example file part (base64 UTF-8 bytes)', mimeType: 'application/json' },
335
+ ...(shardedExamples ? [
336
+ { uriTemplate: 'vini://examples/pages/{index}', name: 'VINi example inventory page', mimeType: 'application/json' },
337
+ { uriTemplate: 'vini://examples/{id}/files/pages/{index}', name: 'VINi example file manifest page', mimeType: 'application/json' },
338
+ { uriTemplate: 'vini://examples/{id}/file-index/{fileIndex}/parts/{index}', name: 'VINi example file part by index', mimeType: 'application/json' },
339
+ { uriTemplate: 'vini://examples/{id}/details/parts/{index}', name: 'VINi example details part', mimeType: 'application/json' },
340
+ ] : []),
245
341
  ];
246
342
  return { current, call, readResource, resources, resourceTemplates };
247
343
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vini-ds/agent",
3
- "version": "0.1.0-alpha.13",
3
+ "version": "0.1.0-alpha.15",
4
4
  "description": "Public VINi React DOM component and token context with a local read-only MCP server",
5
5
  "type": "module",
6
6
  "engines": {
@@ -27,24 +27,27 @@
27
27
  "viniRelease": {
28
28
  "atlas": {
29
29
  "url": "https://vini-atlas.twc1.net/",
30
- "archiveSha256": "sha256:035848c083a2bc32850377df27f3d5e2d2a3cc3b1ee1c2edb75a789526bb8297",
31
- "siteRelease": "source-snapshot-20261115-card-align-e43b0d3",
32
- "commit": "e43b0d3237825bcb09ebc0760a0a9544891b3353"
30
+ "siteRelease": "source-snapshot-20261124-alpha15-b2ada18b",
31
+ "commit": "b2ada18b372f6fd4ec9e4dd6ee6a407a1a3ef945",
32
+ "archiveSha256": "sha256:87214bdcfcb766ed7f32e323b66bbaa75258cb34e120526b11943bbab655b91f"
33
33
  },
34
34
  "delivery": {
35
- "id": "candidate-aeb9566ccd8ab46b",
36
- "manifestSha256": "sha256:7a506ceb8d42a7e04f4d0e4fb7dfaec442b29b0f221a0483625bd8af899d4dea",
37
- "packageManifestSha256": "sha256:f2431364911438a5ac24f4f76cf73bc4246535ced70fb530754af64e1d69125e"
35
+ "id": "candidate-de4974498efaa22b",
36
+ "manifestSha256": "sha256:b1cc452a7dee3024393dc45fbaebdaffac0a628dc2374d0e89831e5349549f49",
37
+ "packageManifestSha256": "sha256:655778b7ba357a7dc381fb1d05e8adf9c7d6737e67ade55e851a2153b661d15c"
38
38
  },
39
39
  "changes": {
40
- "fromVersion": "0.1.0-alpha.11",
41
- "summary": "Поддержка React 18 и 19; Blue и генератор бренда; NativeSelect, Slider, исправление прокрутки Select; агент сообщает об обновлениях при начале работы. Atlas показывает примеры в натуральном размере без скачка при загрузке. В Card заголовок и действие выравниваются по вертикали, когда они единственные прямые элементы заголовка; при дополнительном содержимом действие остаётся сверху. В примерах Collapsible используется компактная кнопка.",
40
+ "fromVersion": "0.1.0-alpha.14",
41
+ "summary": "Добавлен PromptComposer. Обновлены Button, сортируемые заголовки Table, аватары Item, IconContainer, подсветка поиска и оформление Application Shell.",
42
42
  "components": [
43
- "NativeSelect",
44
- "Slider",
45
- "Select",
46
- "Card",
47
- "Collapsible"
43
+ "PromptComposer",
44
+ "Button",
45
+ "ButtonGroup",
46
+ "Table",
47
+ "Item",
48
+ "IconContainer",
49
+ "Text",
50
+ "Sidebar"
48
51
  ]
49
52
  }
50
53
  },