Merge pull request #227 from cita-777/codex/openclaw-user-agent-v2

fix: detect openclaw user-agent in proxy logs
This commit is contained in:
Cita
2026-03-21 13:56:14 +08:00
committed by GitHub
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;
}