fix: use getDiagnostics for cascade IDs + summary fallback + stop poll spam
This commit is contained in:
@@ -281,73 +281,85 @@ function activate(context) {
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
let pollFailCount = 0;
|
||||
async function pollConversations() {
|
||||
if (!lsPort) {
|
||||
return;
|
||||
}
|
||||
if (pollFailCount > 3) {
|
||||
return;
|
||||
} // stop after repeated failures
|
||||
try {
|
||||
// Get trajectory list — returns {trajectories:[{trajectoryId, trajectoryScope, current}]}
|
||||
const result = await lsRPC('GetUserTrajectoryDescriptions');
|
||||
if (!result || !result.trajectories) {
|
||||
// Use getDiagnostics to get cascade-level conversation IDs
|
||||
const diag = await vscode.commands.executeCommand('antigravity.getDiagnostics');
|
||||
if (!diag) {
|
||||
return;
|
||||
}
|
||||
const parsed = typeof diag === 'string' ? JSON.parse(diag) : diag;
|
||||
const trajectories = parsed.recentTrajectories || [];
|
||||
if (!Array.isArray(trajectories) || trajectories.length === 0) {
|
||||
return;
|
||||
}
|
||||
// Debug: log structure on first call
|
||||
const isFirstPoll = Object.keys(lastStepIndex).length === 0;
|
||||
if (isFirstPoll) {
|
||||
console.log(`Gravity Bridge: [LS] trajectories response keys: ${Object.keys(result).join(', ')}`);
|
||||
console.log(`Gravity Bridge: [LS] trajectories sample: ${JSON.stringify(result).substring(0, 600)}`);
|
||||
console.log(`Gravity Bridge: [LS] ${trajectories.length} recent trajectories from getDiagnostics`);
|
||||
const latest = trajectories[trajectories.length - 1];
|
||||
console.log(`Gravity Bridge: [LS] latest: ${JSON.stringify(latest).substring(0, 400)}`);
|
||||
}
|
||||
// Find current (active) trajectory
|
||||
const trajectories = result.trajectories;
|
||||
const current = trajectories.find((t) => t.current === true) || trajectories[0];
|
||||
if (!current?.trajectoryId) {
|
||||
// Check the most recent trajectory for step count changes
|
||||
const latest = trajectories[trajectories.length - 1];
|
||||
const agentId = latest.googleAgentId || '';
|
||||
const trajId = latest.trajectoryId || '';
|
||||
const stepIdx = latest.lastStepIndex ?? 0;
|
||||
if (!agentId && !trajId) {
|
||||
return;
|
||||
}
|
||||
const trajId = current.trajectoryId;
|
||||
// Try multiple RPC methods and field name variants
|
||||
const attempts = [
|
||||
{ method: 'GetCascadeTrajectorySteps', params: { trajectoryId: trajId } },
|
||||
{ method: 'GetCascadeTrajectory', params: { trajectoryId: trajId } },
|
||||
{ method: 'GetCascadeTrajectorySteps', params: { cascadeId: trajId } },
|
||||
{ method: 'GetCascadeTrajectory', params: { cascadeId: trajId } },
|
||||
{ method: 'GetUserTrajectory', params: { trajectoryId: trajId } },
|
||||
];
|
||||
let stepsResult = null;
|
||||
for (const attempt of attempts) {
|
||||
const res = await lsRPC(attempt.method, attempt.params);
|
||||
if (res && !res.code && !res.message?.includes('not found')) {
|
||||
stepsResult = res;
|
||||
if (isFirstPoll) {
|
||||
console.log(`Gravity Bridge: [LS] ✅ ${attempt.method}(${JSON.stringify(attempt.params).substring(0, 50)}) worked!`);
|
||||
console.log(`Gravity Bridge: [LS] steps response keys: ${Object.keys(res).join(', ')}`);
|
||||
console.log(`Gravity Bridge: [LS] steps sample: ${JSON.stringify(res).substring(0, 800)}`);
|
||||
const key = agentId || trajId;
|
||||
const prev = lastStepIndex[key];
|
||||
if (prev === undefined) {
|
||||
// First poll — initialize
|
||||
lastStepIndex[key] = stepIdx;
|
||||
console.log(`Gravity Bridge: [LS] initialized ${key.substring(0, 8)} at step ${stepIdx}`);
|
||||
return;
|
||||
}
|
||||
if (stepIdx > prev) {
|
||||
// New steps detected! Try to fetch them
|
||||
console.log(`Gravity Bridge: [LS] ${key.substring(0, 8)} new steps: ${prev} → ${stepIdx}`);
|
||||
const attempts = [
|
||||
{ method: 'GetCascadeTrajectorySteps', params: { googleAgentId: agentId, trajectoryId: trajId, startStepIndex: prev } },
|
||||
{ method: 'GetCascadeTrajectory', params: { googleAgentId: agentId, trajectoryId: trajId } },
|
||||
{ method: 'GetCascadeTrajectorySteps', params: { conversationId: agentId, trajectoryId: trajId } },
|
||||
];
|
||||
let stepsResult = null;
|
||||
for (const attempt of attempts) {
|
||||
const res = await lsRPC(attempt.method, attempt.params);
|
||||
if (res && !res.code && !res.message?.includes('not found')) {
|
||||
stepsResult = res;
|
||||
console.log(`Gravity Bridge: [LS] ✅ ${attempt.method} worked!`);
|
||||
console.log(`Gravity Bridge: [LS] keys: ${Object.keys(res).join(', ')}`);
|
||||
console.log(`Gravity Bridge: [LS] sample: ${JSON.stringify(res).substring(0, 800)}`);
|
||||
pollFailCount = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (isFirstPoll) {
|
||||
const errMsg = res?.message || res?.code || 'null/empty';
|
||||
console.log(`Gravity Bridge: [LS] ❌ ${attempt.method}(${Object.keys(attempt.params)[0]}): ${errMsg}`);
|
||||
if (stepsResult) {
|
||||
const steps = stepsResult.steps || stepsResult.cortexSteps || stepsResult.cortex_steps || [];
|
||||
if (Array.isArray(steps) && steps.length > 0) {
|
||||
const newSteps = steps.slice(-(stepIdx - prev));
|
||||
extractAndRelaySteps(newSteps);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!stepsResult) {
|
||||
return;
|
||||
}
|
||||
// Count steps — detect new ones
|
||||
const steps = stepsResult.steps || stepsResult.cortexSteps || stepsResult.cortex_steps || [];
|
||||
const stepCount = Array.isArray(steps) ? steps.length : 0;
|
||||
const prevCount = lastStepIndex[trajId] ?? -1;
|
||||
if (prevCount === -1) {
|
||||
// First poll — just record count, don't relay old messages
|
||||
lastStepIndex[trajId] = stepCount;
|
||||
console.log(`Gravity Bridge: [LS] trajectory ${trajId.substring(0, 8)} initialized with ${stepCount} steps`);
|
||||
return;
|
||||
}
|
||||
if (stepCount > prevCount) {
|
||||
console.log(`Gravity Bridge: [LS] ${trajId.substring(0, 8)} new steps: ${prevCount} → ${stepCount}`);
|
||||
// Extract AI text from new steps
|
||||
const newSteps = steps.slice(prevCount);
|
||||
extractAndRelaySteps(newSteps);
|
||||
lastStepIndex[trajId] = stepCount;
|
||||
else {
|
||||
// All attempts failed — try writing the summary as a fallback
|
||||
const summary = latest.summary || '';
|
||||
if (summary && summary !== lastStepIndex[key + '_summary']) {
|
||||
writeChatSnapshot(`[AI 대화 요약]\n\n${summary}\n\n(step ${prev} → ${stepIdx})`);
|
||||
lastStepIndex[key + '_summary'] = summary;
|
||||
console.log(`Gravity Bridge: [LS] relayed summary fallback: ${summary.substring(0, 100)}`);
|
||||
}
|
||||
pollFailCount++;
|
||||
}
|
||||
lastStepIndex[key] = stepIdx;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user