| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- // Use the existing VOC MCP directly; no digital-human delegation or new login.
- // One collection call per invocation, no retries and no automatic alternatives.
- if (process.argv[2] === 'call') require('../server/industry-collection-guard.cjs').assertPaidCollectionAllowed();
- const fs = require('node:fs');
- const path = require('node:path');
- const crypto = require('node:crypto');
- const { createRequire } = require('node:module');
- const pluginRoot = 'C:/Users/JSHY/AppData/Roaming/npm/node_modules/@vocmarket/voc-skill';
- const req = createRequire(path.join(pluginRoot, 'mcp/src/server.js'));
- const { Client } = req('@modelcontextprotocol/sdk/client/index.js');
- const { StdioClientTransport } = req('@modelcontextprotocol/sdk/client/stdio.js');
- const { readCredentialContext } = req('./core/credentials.js');
- const credentials = readCredentialContext({});
- const [mode, label, family, itemId, pageArg = '1'] = process.argv.slice(2);
- const base = path.resolve('work/product-reviews/live-r1');
- const out = path.join(base, label || 'docs');
- function save(file, value) {
- fs.mkdirSync(path.dirname(file), { recursive: true });
- let raw = JSON.stringify(value, null, 2);
- for (const secret of [credentials.newApiToken, credentials.sessionToken]) {
- if (secret) raw = raw.split(secret).join('[REDACTED]');
- }
- fs.writeFileSync(file, raw + '\n', { flag: 'wx' });
- }
- const transport = new StdioClientTransport({ command: process.execPath,
- args: [path.join(pluginRoot, 'mcp/src/server.js')], cwd: pluginRoot, stderr: 'pipe',
- env: { ...process.env, VOC_SKILL_NO_UPDATE_CHECK: '1' } });
- transport.stderr?.on('data', () => {});
- const client = new Client({ name: 'ksf-direct-review-sampling', version: '1.0.0' });
- async function call(name, args, file, timeout = 30000) {
- const result = await client.callTool({ name, arguments: args }, undefined, { timeout });
- save(file, { request: { name, arguments: args }, response: result });
- return result.structuredContent || result;
- }
- (async () => {
- try {
- await client.connect(transport, { timeout: 15000 });
- if (mode === 'docs') {
- for (const id of ['jd.get_item_comments_v1', 'taobao.get_item_comment_v3']) {
- const result = await call('voc_api_doc', { id }, path.join(out, id + '.json'));
- console.log(JSON.stringify({ endpoint: id, status: result.status,
- params: result.data?.endpoint?.params, responseHint: result.data?.endpoint?.responseHint }));
- }
- return;
- }
- if (mode === 'usage') {
- const reservation = JSON.parse(fs.readFileSync(path.join(out, 'reservation.json'), 'utf8'));
- const result = await call('voc_usage_report', { usageTraceId: reservation.usageTraceId,
- groupBy: ['usageTraceId', 'module', 'endpoint'], limit: 1000, pageSize: 200, refresh: true },
- path.join(out, 'usage-' + Date.now() + '.json'));
- console.log(JSON.stringify({ status: result.status, summary: result.summary, data: result.data }));
- return;
- }
- if (mode !== 'call' || !/^[a-z0-9-]+$/.test(label || '') || !['jd', 'taobao'].includes(family)
- || !/^\d+$/.test(itemId || '') || !/^\d+$/.test(pageArg)) throw Error('INVALID_ARGUMENTS');
- if (!credentials.newApiToken || credentials.sessionToken) throw Error('EXPECTED_EXISTING_SINGLE_AUTH_NO_FALLBACK');
- if (fs.existsSync(out)) throw Error('OUTPUT_EXISTS_CHECK_STATUS_DO_NOT_REPEAT');
- const reservations = fs.existsSync(base) ? fs.readdirSync(base)
- .filter(n => fs.existsSync(path.join(base, n, 'reservation.json'))) : [];
- // Operational cap for this limited sample; it does not reset the shared ¥50.
- if (reservations.length >= 10) throw Error('TEN_CALL_OPERATIONAL_CAP');
- const usageTraceId = 'usage_ksf_reviews_20261106_' + crypto.randomUUID();
- const endpoint = family === 'jd' ? 'jd.get_item_comments_v1' : 'taobao.get_item_comment_v3';
- const catalog = JSON.parse(fs.readFileSync(path.resolve('work/product-reviews/current/catalog.json'), 'utf8'));
- const product = catalog.records.find(r => r.record_id === family + ':' + itemId);
- if (!product || product.relatedCounts?.reviews) throw Error('EXPECTED_PRODUCT_WITHOUT_STORED_REVIEWS');
- const historical = JSON.parse(fs.readFileSync(path.resolve('work/product-reviews/volume-evidence-r1.json'), 'utf8'));
- if (!historical[family + ':' + itemId]?.countText) throw Error('REVIEW_VOLUME_EVIDENCE_REQUIRED');
- const params = { itemId, page: family === 'jd' ? pageArg : Number(pageArg) };
- if (family === 'taobao') params.orderType = 'general'; // Documented general order, not a likes sort.
- for (const previous of reservations) {
- const prior = JSON.parse(fs.readFileSync(path.join(base, previous, 'reservation.json'), 'utf8'));
- if (prior.endpoint === endpoint && prior.params.itemId === itemId && String(prior.params.page) === pageArg) {
- throw Error('REQUEST_ALREADY_RESERVED_OR_EXECUTED_CHECK_RECEIPT_DO_NOT_REPEAT');
- }
- }
- const reservation = { endpoint, params, usageTraceId, maxNewCostCny: 0.30,
- maxGatewayRequests: 1, retries: 0, automaticFallback: false,
- timestamp: new Date().toISOString(), scope: 'limited_missing_high_volume_product_reviews',
- sharedPriorBudgetCny: 50, priorUnreconciledCostsRetained: true,
- catalogGeneration: catalog.generation, historicalCountDisplay: historical[family + ':' + itemId].countText };
- save(path.join(out, 'reservation.json'), reservation);
- console.log(JSON.stringify({ started: true, endpoint, itemId, page: params.page, maxNewCostCny: 0.30, usageTraceId }));
- const result = await call('voc_api_call', { id: endpoint, params, retries: 0, usageTraceId,
- skillId: 'ksf-review-gap-sampling', outputDir: path.join(out, 'tool-output') },
- path.join(out, 'mcp-result.json'), 600000);
- console.log(JSON.stringify({ status: result.status, summary: result.summary,
- dataKeys: Object.keys(result.data || {}), errors: result.errors }));
- } finally {
- await client.close();
- await transport.close();
- }
- })().catch(error => {
- // Do not echo URLs, headers or credential-bearing error messages.
- console.log(JSON.stringify({ ok: false, error: error.name, resultMayBeUncertain: mode === 'call' }));
- process.exitCode = 1;
- });
|