fix: drop oauth status from session status
This commit is contained in:
@@ -99,6 +99,7 @@ describe("session_status tool", () => {
|
||||
expect(details.ok).toBe(true);
|
||||
expect(details.statusText).toContain("Clawdbot");
|
||||
expect(details.statusText).toContain("🧠 Model:");
|
||||
expect(details.statusText).not.toContain("OAuth/token status");
|
||||
});
|
||||
|
||||
it("errors for unknown session keys", async () => {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Type } from "@sinclair/typebox";
|
||||
import { resolveAgentDir } from "../../agents/agent-scope.js";
|
||||
import { buildAuthHealthSummary, formatRemainingShort } from "../../agents/auth-health.js";
|
||||
import {
|
||||
ensureAuthProfileStore,
|
||||
resolveAuthProfileDisplayLabel,
|
||||
@@ -32,7 +31,6 @@ import {
|
||||
formatUsageWindowSummary,
|
||||
loadProviderUsageSummary,
|
||||
resolveUsageProviderId,
|
||||
type UsageProviderId,
|
||||
} from "../../infra/provider-usage.js";
|
||||
import {
|
||||
buildAgentMainSessionKey,
|
||||
@@ -283,49 +281,33 @@ export function createSessionStatusTool(opts?: {
|
||||
defaultModel: DEFAULT_MODEL,
|
||||
});
|
||||
const providerForCard = resolved.entry.providerOverride?.trim() || configured.provider;
|
||||
const authStore = ensureAuthProfileStore(agentDir, { allowKeychainPrompt: false });
|
||||
const authHealth = buildAuthHealthSummary({
|
||||
store: authStore,
|
||||
cfg,
|
||||
});
|
||||
const oauthProfiles = authHealth.profiles.filter(
|
||||
(profile) => profile.type === "oauth" || profile.type === "token",
|
||||
);
|
||||
|
||||
const usageProviders = Array.from(
|
||||
new Set(
|
||||
oauthProfiles
|
||||
.map((profile) => resolveUsageProviderId(profile.provider))
|
||||
.filter((provider): provider is UsageProviderId => Boolean(provider)),
|
||||
),
|
||||
);
|
||||
const usageByProvider = new Map<string, string>();
|
||||
if (usageProviders.length > 0) {
|
||||
const usageProvider = resolveUsageProviderId(providerForCard);
|
||||
let usageLine: string | undefined;
|
||||
if (usageProvider) {
|
||||
try {
|
||||
const usageSummary = await loadProviderUsageSummary({
|
||||
timeoutMs: 3500,
|
||||
providers: usageProviders,
|
||||
providers: [usageProvider],
|
||||
agentDir,
|
||||
});
|
||||
for (const snapshot of usageSummary.providers) {
|
||||
const snapshot = usageSummary.providers.find(
|
||||
(entry) => entry.provider === usageProvider,
|
||||
);
|
||||
if (snapshot) {
|
||||
const formatted = formatUsageWindowSummary(snapshot, {
|
||||
now: Date.now(),
|
||||
maxWindows: 2,
|
||||
includeResets: true,
|
||||
});
|
||||
if (formatted) usageByProvider.set(snapshot.provider, formatted);
|
||||
if (formatted && !formatted.startsWith("error:")) {
|
||||
usageLine = `📊 Usage: ${formatted}`;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
const usageProvider = resolveUsageProviderId(providerForCard);
|
||||
const usageLine =
|
||||
oauthProfiles.length === 0 && usageProvider && usageByProvider.has(usageProvider)
|
||||
? `📊 Usage: ${usageByProvider.get(usageProvider)}`
|
||||
: undefined;
|
||||
|
||||
const isGroup =
|
||||
resolved.entry.chatType === "group" ||
|
||||
resolved.entry.chatType === "room" ||
|
||||
@@ -371,53 +353,13 @@ export function createSessionStatusTool(opts?: {
|
||||
includeTranscriptUsage: false,
|
||||
});
|
||||
|
||||
const authStatusLines = (() => {
|
||||
if (oauthProfiles.length === 0) return [];
|
||||
const formatStatus = (status: string) => {
|
||||
if (status === "ok") return "ok";
|
||||
if (status === "static") return "static";
|
||||
if (status === "expiring") return "expiring";
|
||||
if (status === "missing") return "unknown";
|
||||
return "expired";
|
||||
};
|
||||
const profilesByProvider = new Map<string, typeof oauthProfiles>();
|
||||
for (const profile of oauthProfiles) {
|
||||
const current = profilesByProvider.get(profile.provider);
|
||||
if (current) current.push(profile);
|
||||
else profilesByProvider.set(profile.provider, [profile]);
|
||||
}
|
||||
const lines: string[] = ["OAuth/token status"];
|
||||
for (const [provider, profiles] of profilesByProvider) {
|
||||
const usageKey = resolveUsageProviderId(provider);
|
||||
const usage = usageKey ? usageByProvider.get(usageKey) : undefined;
|
||||
const usageSuffix = usage ? ` — usage: ${usage}` : "";
|
||||
lines.push(`- ${provider}${usageSuffix}`);
|
||||
for (const profile of profiles) {
|
||||
const labelText = profile.label || profile.profileId;
|
||||
const status = formatStatus(profile.status);
|
||||
const expiry =
|
||||
profile.status === "static"
|
||||
? ""
|
||||
: profile.expiresAt
|
||||
? ` expires in ${formatRemainingShort(profile.remainingMs)}`
|
||||
: " expires unknown";
|
||||
const source = profile.source !== "store" ? ` (${profile.source})` : "";
|
||||
lines.push(` - ${labelText} ${status}${expiry}${source}`);
|
||||
}
|
||||
}
|
||||
return lines;
|
||||
})();
|
||||
|
||||
const fullStatusText =
|
||||
authStatusLines.length > 0 ? `${statusText}\n\n${authStatusLines.join("\n")}` : statusText;
|
||||
|
||||
return {
|
||||
content: [{ type: "text", text: fullStatusText }],
|
||||
content: [{ type: "text", text: statusText }],
|
||||
details: {
|
||||
ok: true,
|
||||
sessionKey: resolved.key,
|
||||
changedModel,
|
||||
statusText: fullStatusText,
|
||||
statusText,
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user