bada-terminal / src /openwork /cli-inference-diagnostics.js
VanyaJ's picture
Release BADA Terminal v2.1.0 (Enterprise Ontology, NVIDIA auto-ontology, Release Preflight)
d739b1b verified
Raw History Blame Contribute Delete
4.02 kB
// ์„ค๋ช… ๋ฌธ์„œ: docs/specs/openwork-cli-provider.md (v2.0.0)
// DLP ์‹คํŒจ ์œ„์น˜๋งŒ ๊ด€์ธกํ•œ๋‹ค. ์›๋ฌธยทpreviewยทํ•ด์‹œยท์‚ฌ์šฉ์ž ์ •์˜ ํ‚ค๋Š” ๋กœ๊ทธ์— ๋„ฃ์ง€ ์•Š๋Š”๋‹ค.
const scanner = require('../utils/secret-scanner');
const LIMIT = 32;
function findings(text, pointer) {
if (typeof text !== 'string') return [];
const result = scanner.scan(text), records = [];
const category = (token, index) => /https?:$/.test(text.slice(Math.max(0, index - 6), index)) ? 'url'
: token.startsWith('/') || /^[A-Za-z]:[\\/]/.test(token) ? 'path' : 'token';
for (const finding of result.findings) {
if (finding.type === 'high-entropy-token') {
for (const match of text.matchAll(/[A-Za-z0-9+/_-]{24,}/g)) {
if (scanner.shannonEntropy(match[0]) < 4) continue;
records.push({ pointer, findingType: finding.type, length: match[0].length, category: category(match[0], match.index) });
if (records.length >= LIMIT) return records;
}
} else {
const signature = scanner.SIGNATURES.find(item => item.name === finding.type), match = signature?.re.exec(text);
const token = match?.[1] || match?.[0];
records.push({ pointer, findingType: finding.type, length: token ? token.length : null,
category: token ? category(token, match.index) : 'token' });
}
}
return records.slice(0, LIMIT);
}
function inspect(request, prompt, originalRequest = request) {
if (scanner.scan(prompt).clean) return [];
const result = [], add = (value, pointer) => {
if (result.length < LIMIT) result.push(...findings(value, pointer).slice(0, LIMIT - result.length));
};
// ๊ฒฝ๋กœ๋Š” ์„œ๋ฒ„๊ฐ€ ์ •ํ•œ ๊ณ ์ • ๊ตฌ์กฐ์™€ ๋ฐฐ์—ด ์ธ๋ฑ์Šค๋งŒ ์‚ฌ์šฉํ•œ๋‹ค. ์Šคํ‚ค๋งˆ ๋‚ด๋ถ€ ํ‚ค๋Š” ๊ณต๊ฐœํ•˜์ง€ ์•Š๋Š”๋‹ค.
request.messages.forEach((message, index) => {
const first = result.length;
add(message.content, `/messages/${index}/content`);
if (['system', 'developer'].includes(message.role) && result.length > first) {
const original = originalRequest.messages[index]?.content;
const tokens = new Set(String(message.content).match(/[A-Za-z0-9+/_-]{24,}/g) || []);
const publicStaticIds = [['openwork-cloud_execute_capability', 'public_cloud_execute'], ['openwork-cloud_search_capabilities', 'public_cloud_search']]
.filter(([token]) => tokens.has(token)).map(([, id]) => id);
const sectionPresence = require('./cli-system-steering').inspectSteering(typeof original === 'string' ? original : '');
for (let offset = first; offset < result.length; offset++) Object.assign(result[offset], { publicStaticIds, sectionPresence });
}
message.tool_calls?.forEach((call, callIndex) => {
add(call.id, `/messages/${index}/tool_calls/${callIndex}/id`);
add(call.function.name, `/messages/${index}/tool_calls/${callIndex}/function/name`);
add(call.function.arguments, `/messages/${index}/tool_calls/${callIndex}/function/arguments`);
});
add(message.tool_call_id, `/messages/${index}/tool_call_id`);
});
request.tools.forEach((tool, index) => {
add(tool.function.name, `/tools/${index}/function/name`);
add(tool.function.description, `/tools/${index}/function/description`);
add(JSON.stringify(tool.function.parameters), `/tools/${index}/function/parameters`);
});
add(JSON.stringify(request.pathAliases || []), '/pathAliases');
// ์ง๋ ฌํ™” ๊ฒฝ๊ณ„/์ถœ๋ ฅ ๊ณ„์•ฝ ์ง€์นจ์—์„œ๋งŒ ์žฌํ˜„๋˜๋Š” ์‹คํŒจ๋„ ์‚ฌ์šฉ์ž ์›๋ฌธ ์—†์ด ๊ตฌ๋ถ„ํ•œ๋‹ค.
if (!result.length) add(prompt, '/');
return result;
}
function record(request, prompt, log = value => require('../utils/debug-log').writeDebugLog(value), originalRequest = request) {
try {
for (const detail of inspect(request, prompt, originalRequest)) {
Promise.resolve(log('[OpenWork CLI DLP] ' + JSON.stringify({ stage: 'projection_prompt', ...detail }))).catch(() => {});
}
} catch { /* ์ง„๋‹จ ์‹คํŒจ๊ฐ€ ๊ธฐ์กด DLP ํŒ์ •์ด๋‚˜ ์ •์‚ฐ ํ๋ฆ„์„ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๋Š”๋‹ค. */ }
}
module.exports = { inspect, record };