big prompt improvement to mcp

This commit is contained in:
southseact-3d
2026-02-20 18:17:36 +00:00
parent d3580b091a
commit dfc4a0d2a9
9 changed files with 1120 additions and 59 deletions

View File

@@ -1429,66 +1429,93 @@ function classifyStatusMessage(msg) {
if (!text) return { userText: '', adminText: '' };
// Mask all OpenCode, provider, and internal error messages with branded message
const internalErrorPatterns = [
/opencode/i,
/openrouter/i,
/mistral/i,
/anthropic/i,
/error:.*\d{3}/i,
/exit code/i,
/stderr/i,
/stdout/i,
/provider.*error/i,
/api.*error/i,
/rate limit/i,
/quota/i,
/insufficient/i,
/unauthorized/i,
/forbidden/i,
/internal server error/i,
/service unavailable/i,
/gateway/i,
/timeout/i,
/connection.*refused/i,
/connection.*lost/i,
/process.*exited/i,
/tool.*call.*format/i,
/malformed/i,
/invalid.*edit/i,
/proper prefixing/i,
/session terminated/i,
/early termination/i,
/model.*not found/i,
/unknown model/i,
/context length/i,
/token limit/i,
];
const isInternalError = internalErrorPatterns.some(pattern => pattern.test(text));
if (isInternalError) {
return {
userText: 'Plugin Compass failed. Please try again.',
adminText: text,
};
}
if (lower.startsWith('no models configured')) {
return {
userText: 'No models are configured. Please contact support.',
userText: 'Plugin Compass failed. Please try again.',
adminText: text,
};
}
if (lower.startsWith('model load failed:')) {
return {
userText: 'Models are currently unavailable. Please contact support.',
userText: 'Plugin Compass failed. Please try again.',
adminText: text,
};
}
if (lower.startsWith('planning failed:')) {
return {
userText: 'Planning is currently unavailable. Please contact support.',
userText: 'Plugin Compass failed. Please try again.',
adminText: text,
};
}
// Surface missing provider API keys to the user with actionable text
if (lower.includes('missing provider api keys') || lower.includes('no configured planning providers')) {
// Try to extract provider list from the message if present
const m = text.match(/Missing provider API keys:\s*([^\n\r]+)/i);
const providers = m ? m[1].trim() : null;
return {
userText: providers
? `Planning unavailable: missing API keys for ${providers}. Please set the environment variables (e.g. GROQ_API_KEY) or configure providers in Admin.`
: 'Planning unavailable: missing provider API keys. Please check server configuration.',
userText: 'Plugin Compass failed. Please try again.',
adminText: text,
};
}
if (lower.includes('openrouter api key') || lower.includes('openrouter request failed')) {
return {
userText: 'Planning is currently unavailable. Please contact support.',
userText: 'Plugin Compass failed. Please try again.',
adminText: text,
};
}
if (lower.startsWith('warning: opencode cli not available')) {
return {
userText: 'Builder service is currently unavailable. Please contact support.',
userText: 'Plugin Compass failed. Please try again.',
adminText: text,
};
}
if (lower.includes('proper prefixing') ||
lower.includes('tool call format') ||
lower.includes('tool call prefix') ||
lower.includes('session terminated') ||
lower.includes('early termination')) {
return {
userText: 'Connection interrupted. Resuming...',
adminText: `Early termination detected: ${text}`,
type: 'warning'
};
}
return { userText: text, adminText: '' };
}
@@ -2152,14 +2179,16 @@ function renderMessages(session) {
const err = document.createElement('div');
err.className = 'body';
err.style.color = 'var(--danger)';
err.textContent = msg.error;
const { userText: maskedError } = classifyStatusMessage(msg.error);
err.textContent = maskedError;
assistantCard.appendChild(err);
}
if ((!msg.reply || !msg.reply.length) && (!msg.partialOutput || !msg.partialOutput.length) && msg.opencodeSummary) {
const summary = document.createElement('div');
summary.className = 'body';
summary.style.color = 'var(--muted)';
summary.textContent = `Opencode output: ${msg.opencodeSummary}`;
const { userText: maskedSummary } = classifyStatusMessage(msg.opencodeSummary);
summary.textContent = maskedSummary;
assistantCard.appendChild(summary);
}
@@ -3161,7 +3190,9 @@ function streamMessage(sessionId, messageId) {
// Update session list (no-op in builder)
renderSessions();
} else if (data.type === 'error') {
message.error = data.error || 'Unknown error';
const rawError = data.error || 'Unknown error';
const { userText: maskedError } = classifyStatusMessage(rawError);
message.error = maskedError;
message.reply = data.content || message.partialOutput || '';
message.status = 'error';
message.finishedAt = data.timestamp;
@@ -3181,7 +3212,7 @@ function streamMessage(sessionId, messageId) {
scrollChatToBottom();
if (!message.isBackgroundContinuation) {
setStatus('Error: ' + (data.error || 'Unknown error'));
setStatus(rawError);
}
stopUsagePolling();