feat: surface codex thread config progress
This commit is contained in:
@@ -763,6 +763,67 @@ function normalizeThreadStatusSnapshot(status) {
|
||||
};
|
||||
}
|
||||
|
||||
function extractThreadGoalSnapshot(goal) {
|
||||
if (!goal || typeof goal !== "object") {
|
||||
return null;
|
||||
}
|
||||
const status = safeProgressText(goal.status, 40);
|
||||
const objective = safeProgressText(goal.objective, 240);
|
||||
if (!status && !objective) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
...(objective ? { objective } : {}),
|
||||
status: status || "active",
|
||||
...(extractNumber(goal.tokenBudget) !== undefined ? { tokenBudget: extractNumber(goal.tokenBudget) } : {}),
|
||||
...(extractNumber(goal.tokensUsed) !== undefined ? { tokensUsed: extractNumber(goal.tokensUsed) } : {}),
|
||||
...(extractNumber(goal.timeUsedSeconds) !== undefined
|
||||
? { timeUsedSeconds: extractNumber(goal.timeUsedSeconds) }
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
function extractSandboxPolicyName(sandboxPolicy) {
|
||||
if (typeof sandboxPolicy === "string") {
|
||||
return sandboxPolicy;
|
||||
}
|
||||
if (sandboxPolicy && typeof sandboxPolicy === "object") {
|
||||
return sandboxPolicy.type;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function extractCollaborationModeName(collaborationMode) {
|
||||
if (typeof collaborationMode === "string") {
|
||||
return collaborationMode;
|
||||
}
|
||||
if (collaborationMode && typeof collaborationMode === "object") {
|
||||
return collaborationMode.mode;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function extractThreadSettingsSnapshot(settings) {
|
||||
if (!settings || typeof settings !== "object") {
|
||||
return null;
|
||||
}
|
||||
const snapshot = {
|
||||
model: safeProgressText(settings.model, 80) || undefined,
|
||||
modelProvider: safeProgressText(settings.modelProvider, 80) || undefined,
|
||||
approvalPolicy:
|
||||
safeProgressText(typeof settings.approvalPolicy === "string" ? settings.approvalPolicy : "", 80) || undefined,
|
||||
approvalsReviewer: safeProgressText(settings.approvalsReviewer, 80) || undefined,
|
||||
sandboxPolicy: safeProgressText(extractSandboxPolicyName(settings.sandboxPolicy), 80) || undefined,
|
||||
permissionProfile: safeProgressText(settings.activePermissionProfile?.id, 80) || undefined,
|
||||
serviceTier: safeProgressText(settings.serviceTier, 80) || undefined,
|
||||
effort: safeProgressText(settings.effort, 80) || undefined,
|
||||
summary: safeProgressText(settings.summary, 80) || undefined,
|
||||
collaborationMode: safeProgressText(extractCollaborationModeName(settings.collaborationMode), 80) || undefined,
|
||||
personality: safeProgressText(settings.personality, 80) || undefined,
|
||||
};
|
||||
return Object.values(snapshot).some(Boolean) ? snapshot : null;
|
||||
}
|
||||
|
||||
function extractTokenUsageSnapshot(tokenUsage) {
|
||||
const total = tokenUsage?.total && typeof tokenUsage.total === "object" ? tokenUsage.total : {};
|
||||
const totalTokens = extractNumber(total.totalTokens);
|
||||
@@ -1035,6 +1096,9 @@ function createProgressCollector() {
|
||||
let tokenUsage;
|
||||
const mcpServers = [];
|
||||
let remoteControl;
|
||||
let threadGoal;
|
||||
let threadSettings;
|
||||
let compaction;
|
||||
|
||||
const upsertArtifact = (artifact) => {
|
||||
if (!artifact || artifacts.some((item) => item.label === artifact.label)) {
|
||||
@@ -1305,6 +1369,33 @@ function createProgressCollector() {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (message.method === "thread/goal/updated") {
|
||||
const nextGoal = extractThreadGoalSnapshot(message.params?.goal);
|
||||
if (nextGoal) {
|
||||
threadGoal = nextGoal;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (message.method === "thread/goal/cleared") {
|
||||
threadGoal = {
|
||||
status: "cleared",
|
||||
};
|
||||
return;
|
||||
}
|
||||
if (message.method === "thread/settings/updated") {
|
||||
const nextSettings = extractThreadSettingsSnapshot(message.params?.threadSettings);
|
||||
if (nextSettings) {
|
||||
threadSettings = nextSettings;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (message.method === "thread/compacted") {
|
||||
compaction = {
|
||||
status: "completed",
|
||||
message: "上下文已压缩",
|
||||
};
|
||||
return;
|
||||
}
|
||||
if (message.method === "thread/started") {
|
||||
upsertAgent(extractAgentFromThreadStarted(message.params));
|
||||
}
|
||||
@@ -1357,6 +1448,15 @@ function createProgressCollector() {
|
||||
if (remoteControl) {
|
||||
result.remoteControl = { ...remoteControl };
|
||||
}
|
||||
if (threadGoal) {
|
||||
result.threadGoal = { ...threadGoal };
|
||||
}
|
||||
if (threadSettings) {
|
||||
result.threadSettings = { ...threadSettings };
|
||||
}
|
||||
if (compaction) {
|
||||
result.compaction = { ...compaction };
|
||||
}
|
||||
return Object.keys(result).length > 0 ? result : undefined;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user