fix: detect openclaw user-agent in proxy logs

This commit is contained in:
ciat-777
2026-03-21 13:53:02 +08:00
parent 7c9bdc51c7
commit 272b88c6c8
2 changed files with 25 additions and 0 deletions
@@ -125,6 +125,21 @@ describe('detectDownstreamClientContext', () => {
});
});
it('treats explicit OpenClaw user-agent headers as self-reported app names', () => {
expect(detectDownstreamClientContext({
downstreamPath: '/v1/responses',
headers: {
'openai-beta': 'responses-2025-03-11',
'user-agent': 'OpenClaw/1.0',
},
})).toEqual({
clientKind: 'codex',
clientAppId: 'openclaw',
clientAppName: 'OpenClaw',
clientConfidence: 'exact',
});
});
it('recognizes Claude Code requests from metadata.user_id without mutating the body', () => {
const body = {
model: 'claude-opus-4-6',
@@ -263,6 +263,16 @@ function detectExplicitClientSelfReport(headers: NormalizedClientHeaders): Downs
};
}
for (const value of headers['user-agent'] || []) {
const normalized = value.trim().toLowerCase();
if (!normalized.startsWith('openclaw/')) continue;
return {
clientAppId: 'openclaw',
clientAppName: 'OpenClaw',
clientConfidence: 'exact',
};
}
return null;
}