feat: surface codex account runtime notices
This commit is contained in:
@@ -846,6 +846,55 @@ function extractTokenUsageSnapshot(tokenUsage) {
|
||||
};
|
||||
}
|
||||
|
||||
function extractRateLimitWindowSnapshot(window) {
|
||||
if (!window || typeof window !== "object") {
|
||||
return {};
|
||||
}
|
||||
return {
|
||||
usedPercent: extractNumber(window.usedPercent),
|
||||
windowDurationMins: extractNumber(window.windowDurationMins),
|
||||
resetsAt: extractNumber(window.resetsAt),
|
||||
};
|
||||
}
|
||||
|
||||
function extractAccountRateLimitSnapshot(rateLimits) {
|
||||
if (!rateLimits || typeof rateLimits !== "object") {
|
||||
return null;
|
||||
}
|
||||
const primary = extractRateLimitWindowSnapshot(rateLimits.primary);
|
||||
const credits = rateLimits.credits && typeof rateLimits.credits === "object" ? rateLimits.credits : {};
|
||||
const snapshot = Object.fromEntries(Object.entries({
|
||||
limitId: safeProgressText(rateLimits.limitId, 80),
|
||||
limitName: safeProgressText(rateLimits.limitName, 80),
|
||||
planType: safeProgressText(rateLimits.planType, 80),
|
||||
rateLimitReachedType: safeProgressText(rateLimits.rateLimitReachedType, 80),
|
||||
usedPercent: primary.usedPercent,
|
||||
windowDurationMins: primary.windowDurationMins,
|
||||
resetsAt: primary.resetsAt,
|
||||
creditsBalance: safeProgressText(credits.balance, 80),
|
||||
...(typeof credits.hasCredits === "boolean" ? { hasCredits: credits.hasCredits } : {}),
|
||||
...(typeof credits.unlimited === "boolean" ? { unlimitedCredits: credits.unlimited } : {}),
|
||||
}).filter(([, value]) => value !== undefined && value !== ""));
|
||||
return Object.values(snapshot).some((value) => value !== undefined && value !== "") ? snapshot : null;
|
||||
}
|
||||
|
||||
function extractModelVerificationSnapshot(params) {
|
||||
const verifications = asArray(params?.verifications)
|
||||
.map((verification) => safeProgressText(verification, 120))
|
||||
.filter(Boolean)
|
||||
.slice(0, 8);
|
||||
return verifications.length > 0 ? { verifications } : null;
|
||||
}
|
||||
|
||||
function buildNoticeWarningMessage(summary, details) {
|
||||
const cleanSummary = safeProgressText(summary, 140);
|
||||
const cleanDetails = safeProgressText(details, 180);
|
||||
if (!cleanSummary) {
|
||||
return cleanDetails;
|
||||
}
|
||||
return cleanDetails ? `${cleanSummary}:${cleanDetails}` : cleanSummary;
|
||||
}
|
||||
|
||||
function buildServerRequestFallbackResponse(message) {
|
||||
const method = String(message?.method ?? "");
|
||||
if (/commandExecution\/requestApproval|execCommandApproval/i.test(method)) {
|
||||
@@ -1099,6 +1148,8 @@ function createProgressCollector() {
|
||||
let threadGoal;
|
||||
let threadSettings;
|
||||
let compaction;
|
||||
let accountStatus;
|
||||
let modelVerification;
|
||||
|
||||
const upsertArtifact = (artifact) => {
|
||||
if (!artifact || artifacts.some((item) => item.label === artifact.label)) {
|
||||
@@ -1396,6 +1447,66 @@ function createProgressCollector() {
|
||||
};
|
||||
return;
|
||||
}
|
||||
if (message.method === "account/updated") {
|
||||
const authMode = safeProgressText(message.params?.authMode, 80);
|
||||
const planType = safeProgressText(message.params?.planType, 80);
|
||||
accountStatus = {
|
||||
...(accountStatus ?? {}),
|
||||
...(authMode ? { authMode } : {}),
|
||||
...(planType ? { planType } : {}),
|
||||
};
|
||||
return;
|
||||
}
|
||||
if (message.method === "account/rateLimits/updated") {
|
||||
const nextAccountStatus = extractAccountRateLimitSnapshot(message.params?.rateLimits);
|
||||
if (nextAccountStatus) {
|
||||
accountStatus = {
|
||||
...(accountStatus ?? {}),
|
||||
...nextAccountStatus,
|
||||
};
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (message.method === "model/verification") {
|
||||
const nextVerification = extractModelVerificationSnapshot(message.params);
|
||||
if (nextVerification) {
|
||||
modelVerification = nextVerification;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (message.method === "warning") {
|
||||
const warningMessage = safeProgressText(message.params?.message, 180);
|
||||
if (warningMessage) {
|
||||
pushWarning({
|
||||
id: `codex-warning-${warnings.length + 1}`,
|
||||
severity: "warning",
|
||||
message: warningMessage,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (message.method === "configWarning") {
|
||||
const warningMessage = buildNoticeWarningMessage(message.params?.summary, message.params?.details);
|
||||
if (warningMessage) {
|
||||
pushWarning({
|
||||
id: `config-warning-${warnings.length + 1}`,
|
||||
severity: "warning",
|
||||
message: warningMessage,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (message.method === "deprecationNotice") {
|
||||
const warningMessage = buildNoticeWarningMessage(message.params?.summary, message.params?.details);
|
||||
if (warningMessage) {
|
||||
pushWarning({
|
||||
id: `deprecation-notice-${warnings.length + 1}`,
|
||||
severity: "info",
|
||||
message: warningMessage,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (message.method === "thread/started") {
|
||||
upsertAgent(extractAgentFromThreadStarted(message.params));
|
||||
}
|
||||
@@ -1457,6 +1568,12 @@ function createProgressCollector() {
|
||||
if (compaction) {
|
||||
result.compaction = { ...compaction };
|
||||
}
|
||||
if (accountStatus) {
|
||||
result.accountStatus = { ...accountStatus };
|
||||
}
|
||||
if (modelVerification) {
|
||||
result.modelVerification = { ...modelVerification };
|
||||
}
|
||||
return Object.keys(result).length > 0 ? result : undefined;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user