mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 21:51:24 +00:00
Providers: skip context1m beta for Anthropic OAuth tokens (#24620)
* Providers: skip context1m beta for Anthropic OAuth tokens * Tests: cover OAuth context1m beta skip behavior * Docs: note context1m OAuth incompatibility * Agents: add context1m-aware context token resolver * Agents: cover context1m context-token resolver * Commands: apply context1m-aware context tokens in session store * Commands: apply context1m-aware context tokens in status summary * Status: resolve context tokens with context1m model params * Status: test context1m status context display
This commit is contained in:
@@ -120,6 +120,36 @@ describe("buildStatusMessage", () => {
|
||||
expect(normalized).toContain("channel override");
|
||||
});
|
||||
|
||||
it("shows 1M context window when anthropic context1m is enabled", () => {
|
||||
const text = buildStatusMessage({
|
||||
config: {
|
||||
agents: {
|
||||
defaults: {
|
||||
model: "anthropic/claude-opus-4-6",
|
||||
models: {
|
||||
"anthropic/claude-opus-4-6": {
|
||||
params: { context1m: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig,
|
||||
agent: {
|
||||
model: "anthropic/claude-opus-4-6",
|
||||
},
|
||||
sessionEntry: {
|
||||
sessionId: "ctx1m",
|
||||
updatedAt: 0,
|
||||
totalTokens: 200_000,
|
||||
},
|
||||
sessionKey: "agent:main:main",
|
||||
sessionScope: "per-sender",
|
||||
queue: { mode: "collect", depth: 0 },
|
||||
});
|
||||
|
||||
expect(normalizeTestText(text)).toContain("Context: 200k/1.0m");
|
||||
});
|
||||
|
||||
it("uses per-agent sandbox config when config and session key are provided", () => {
|
||||
const text = buildStatusMessage({
|
||||
config: {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import fs from "node:fs";
|
||||
import { lookupContextTokens } from "../agents/context.js";
|
||||
import { resolveContextTokensForModel } from "../agents/context.js";
|
||||
import { DEFAULT_CONTEXT_TOKENS, DEFAULT_MODEL, DEFAULT_PROVIDER } from "../agents/defaults.js";
|
||||
import { resolveModelAuthMode } from "../agents/model-auth.js";
|
||||
import {
|
||||
@@ -398,12 +398,29 @@ const formatVoiceModeLine = (
|
||||
export function buildStatusMessage(args: StatusArgs): string {
|
||||
const now = args.now ?? Date.now();
|
||||
const entry = args.sessionEntry;
|
||||
const selectionConfig = {
|
||||
agents: {
|
||||
defaults: args.agent ?? {},
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const contextConfig = args.config
|
||||
? ({
|
||||
...args.config,
|
||||
agents: {
|
||||
...args.config.agents,
|
||||
defaults: {
|
||||
...args.config.agents?.defaults,
|
||||
...args.agent,
|
||||
},
|
||||
},
|
||||
} as OpenClawConfig)
|
||||
: ({
|
||||
agents: {
|
||||
defaults: args.agent ?? {},
|
||||
},
|
||||
} as OpenClawConfig);
|
||||
const resolved = resolveConfiguredModelRef({
|
||||
cfg: {
|
||||
agents: {
|
||||
defaults: args.agent ?? {},
|
||||
},
|
||||
} as OpenClawConfig,
|
||||
cfg: selectionConfig,
|
||||
defaultProvider: DEFAULT_PROVIDER,
|
||||
defaultModel: DEFAULT_MODEL,
|
||||
});
|
||||
@@ -417,10 +434,13 @@ export function buildStatusMessage(args: StatusArgs): string {
|
||||
let activeProvider = modelRefs.active.provider;
|
||||
let activeModel = modelRefs.active.model;
|
||||
let contextTokens =
|
||||
entry?.contextTokens ??
|
||||
args.agent?.contextTokens ??
|
||||
lookupContextTokens(activeModel) ??
|
||||
DEFAULT_CONTEXT_TOKENS;
|
||||
resolveContextTokensForModel({
|
||||
cfg: contextConfig,
|
||||
provider: activeProvider,
|
||||
model: activeModel,
|
||||
contextTokensOverride: entry?.contextTokens ?? args.agent?.contextTokens,
|
||||
fallbackContextTokens: DEFAULT_CONTEXT_TOKENS,
|
||||
}) ?? DEFAULT_CONTEXT_TOKENS;
|
||||
|
||||
let inputTokens = entry?.inputTokens;
|
||||
let outputTokens = entry?.outputTokens;
|
||||
@@ -457,7 +477,12 @@ export function buildStatusMessage(args: StatusArgs): string {
|
||||
}
|
||||
}
|
||||
if (!contextTokens && logUsage.model) {
|
||||
contextTokens = lookupContextTokens(logUsage.model) ?? contextTokens;
|
||||
contextTokens =
|
||||
resolveContextTokensForModel({
|
||||
cfg: contextConfig,
|
||||
model: logUsage.model,
|
||||
fallbackContextTokens: contextTokens ?? undefined,
|
||||
}) ?? contextTokens;
|
||||
}
|
||||
if (!inputTokens || inputTokens === 0) {
|
||||
inputTokens = logUsage.input;
|
||||
|
||||
Reference in New Issue
Block a user