check-voc.cjs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /* Local tool execution and credential availability only; no collection or business writes. */
  2. const fs = require('node:fs');
  3. const path = require('node:path');
  4. const {createRequire} = require('node:module');
  5. const root = path.resolve(process.argv[2]);
  6. const load = createRequire(path.join(root, 'package.json'));
  7. process.env.VOC_SKILL_NO_UPDATE_CHECK = '1';
  8. const timer = setTimeout(() => { console.error('{"ok":false,"error":{"code":"VOC_CHECK_TIMEOUT"}}'); process.exit(1); }, 30000);
  9. async function main() {
  10. const {Client} = load('@modelcontextprotocol/sdk/client/index.js');
  11. const {InMemoryTransport} = load('@modelcontextprotocol/sdk/inMemory.js');
  12. const {createServer} = load('./mcp/src/server.js');
  13. const {searchVocApis, getVocApiDoc} = load('./mcp/src/tools/voc-api-catalog-run.js');
  14. const manifest = JSON.parse(fs.readFileSync(path.join(root, 'skill-package-manifest.json')));
  15. if (manifest.version !== '0.3.44') throw Error('VERSION');
  16. const client = new Client({name: 'ksf-enterprise-voc-check', version: '1.0.0'});
  17. const server = createServer();
  18. const [a,b] = InMemoryTransport.createLinkedPair();
  19. try {
  20. await server.connect(b); await client.connect(a);
  21. const names = (await client.listTools()).tools.map(t => t.name).sort();
  22. if (!manifest.mcpTools.every(n => names.includes(n)) || !['voc_api_search','voc_api_doc','voc_api_call'].every(n => names.includes(n))) throw Error('TOOLS');
  23. const found = await searchVocApis({platform: 'jd', limit: 5});
  24. if (found.status !== 'ok' || !found.data?.endpoints?.length) throw Error('SEARCH');
  25. const doc = await getVocApiDoc({id: found.data.endpoints[0].id});
  26. if (doc.status !== 'ok' || !doc.data?.callTemplate) throw Error('DOC');
  27. for (const name of manifest.skills) if (!fs.statSync(path.join(root,'skills',name,'SKILL.md')).isFile()) throw Error('SUBSKILL');
  28. const context = load('./mcp/src/core/credentials.js').readCredentialContext({});
  29. console.log(JSON.stringify({ok: true, version: manifest.version, tools: names, subskills: manifest.skills.length,
  30. localParameterDocumentRead: true, catalogSearchPassed: true,
  31. credentialAvailable: Boolean(context.newApiToken || context.sessionToken),
  32. hostRegistrationVerified: false, liveAccessVerified: false, collectionRequests: 0, databaseWrites: 0}));
  33. } finally { await client.close(); await server.close(); clearTimeout(timer); }
  34. }
  35. main().catch(() => { clearTimeout(timer); console.error('{"ok":false,"error":{"code":"VOC_LOCAL_RUNTIME_CHECK_FAILED"}}'); process.exitCode=1; });