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.ok).toBe(true);
|
||||||
expect(details.statusText).toContain("Clawdbot");
|
expect(details.statusText).toContain("Clawdbot");
|
||||||
expect(details.statusText).toContain("🧠 Model:");
|
expect(details.statusText).toContain("🧠 Model:");
|
||||||
|
expect(details.statusText).not.toContain("OAuth/token status");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("errors for unknown session keys", async () => {
|
it("errors for unknown session keys", async () => {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { Type } from "@sinclair/typebox";
|
import { Type } from "@sinclair/typebox";
|
||||||
import { resolveAgentDir } from "../../agents/agent-scope.js";
|
import { resolveAgentDir } from "../../agents/agent-scope.js";
|
||||||
import { buildAuthHealthSummary, formatRemainingShort } from "../../agents/auth-health.js";
|
|
||||||
import {
|
import {
|
||||||
ensureAuthProfileStore,
|
ensureAuthProfileStore,
|
||||||
resolveAuthProfileDisplayLabel,
|
resolveAuthProfileDisplayLabel,
|
||||||
@@ -32,7 +31,6 @@ import {
|
|||||||
formatUsageWindowSummary,
|
formatUsageWindowSummary,
|
||||||
loadProviderUsageSummary,
|
loadProviderUsageSummary,
|
||||||
resolveUsageProviderId,
|
resolveUsageProviderId,
|
||||||
type UsageProviderId,
|
|
||||||
} from "../../infra/provider-usage.js";
|
} from "../../infra/provider-usage.js";
|
||||||
import {
|
import {
|
||||||
buildAgentMainSessionKey,
|
buildAgentMainSessionKey,
|
||||||
@@ -283,49 +281,33 @@ export function createSessionStatusTool(opts?: {
|
|||||||
defaultModel: DEFAULT_MODEL,
|
defaultModel: DEFAULT_MODEL,
|
||||||
});
|
});
|
||||||
const providerForCard = resolved.entry.providerOverride?.trim() || configured.provider;
|
const providerForCard = resolved.entry.providerOverride?.trim() || configured.provider;
|
||||||
const authStore = ensureAuthProfileStore(agentDir, { allowKeychainPrompt: false });
|
const usageProvider = resolveUsageProviderId(providerForCard);
|
||||||
const authHealth = buildAuthHealthSummary({
|
let usageLine: string | undefined;
|
||||||
store: authStore,
|
if (usageProvider) {
|
||||||
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) {
|
|
||||||
try {
|
try {
|
||||||
const usageSummary = await loadProviderUsageSummary({
|
const usageSummary = await loadProviderUsageSummary({
|
||||||
timeoutMs: 3500,
|
timeoutMs: 3500,
|
||||||
providers: usageProviders,
|
providers: [usageProvider],
|
||||||
agentDir,
|
agentDir,
|
||||||
});
|
});
|
||||||
for (const snapshot of usageSummary.providers) {
|
const snapshot = usageSummary.providers.find(
|
||||||
|
(entry) => entry.provider === usageProvider,
|
||||||
|
);
|
||||||
|
if (snapshot) {
|
||||||
const formatted = formatUsageWindowSummary(snapshot, {
|
const formatted = formatUsageWindowSummary(snapshot, {
|
||||||
now: Date.now(),
|
now: Date.now(),
|
||||||
maxWindows: 2,
|
maxWindows: 2,
|
||||||
includeResets: true,
|
includeResets: true,
|
||||||
});
|
});
|
||||||
if (formatted) usageByProvider.set(snapshot.provider, formatted);
|
if (formatted && !formatted.startsWith("error:")) {
|
||||||
|
usageLine = `📊 Usage: ${formatted}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const usageProvider = resolveUsageProviderId(providerForCard);
|
|
||||||
const usageLine =
|
|
||||||
oauthProfiles.length === 0 && usageProvider && usageByProvider.has(usageProvider)
|
|
||||||
? `📊 Usage: ${usageByProvider.get(usageProvider)}`
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
const isGroup =
|
const isGroup =
|
||||||
resolved.entry.chatType === "group" ||
|
resolved.entry.chatType === "group" ||
|
||||||
resolved.entry.chatType === "room" ||
|
resolved.entry.chatType === "room" ||
|
||||||
@@ -371,53 +353,13 @@ export function createSessionStatusTool(opts?: {
|
|||||||
includeTranscriptUsage: false,
|
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 {
|
return {
|
||||||
content: [{ type: "text", text: fullStatusText }],
|
content: [{ type: "text", text: statusText }],
|
||||||
details: {
|
details: {
|
||||||
ok: true,
|
ok: true,
|
||||||
sessionKey: resolved.key,
|
sessionKey: resolved.key,
|
||||||
changedModel,
|
changedModel,
|
||||||
statusText: fullStatusText,
|
statusText,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user