[codex] fix empty stream success handling and unknown usage logs (#343)
* fix: preserve repeated short responses deltas * fix empty stream success handling and unknown usage logs * fix proxy usage metadata typing * fix stream bookkeeping and explicit zero usage source * fix sticky fast path and usage placeholder detection
This commit is contained in:
Vendored
+3
@@ -1,8 +1,11 @@
|
||||
export type ProxyLogUsageSource = 'upstream' | 'self-log' | 'unknown' | null;
|
||||
|
||||
export type ParsedProxyLogMetadata = {
|
||||
clientKind: string | null;
|
||||
sessionId: string | null;
|
||||
downstreamPath: string | null;
|
||||
upstreamPath: string | null;
|
||||
usageSource: ProxyLogUsageSource;
|
||||
messageText: string;
|
||||
};
|
||||
|
||||
|
||||
@@ -3,8 +3,9 @@ export function parseProxyLogMetadata(rawMessage) {
|
||||
const sessionMatch = rawMessage.match(/\[session:([^\]]+)\]/i);
|
||||
const downstreamMatch = rawMessage.match(/\[downstream:([^\]]+)\]/i);
|
||||
const upstreamMatch = rawMessage.match(/\[upstream:([^\]]+)\]/i);
|
||||
const usageMatch = rawMessage.match(/\[usage:([^\]]+)\]/i);
|
||||
const messageText = rawMessage.replace(
|
||||
/^\s*(?:\[(?:client|session|downstream|upstream):[^\]]+\]\s*)+/i,
|
||||
/^\s*(?:\[(?:client|session|downstream|upstream|usage):[^\]]+\]\s*)+/i,
|
||||
'',
|
||||
).trim();
|
||||
|
||||
@@ -13,6 +14,7 @@ export function parseProxyLogMetadata(rawMessage) {
|
||||
sessionId: sessionMatch?.[1]?.trim() || null,
|
||||
downstreamPath: downstreamMatch?.[1]?.trim() || null,
|
||||
upstreamPath: upstreamMatch?.[1]?.trim() || null,
|
||||
usageSource: usageMatch?.[1]?.trim() || null,
|
||||
messageText,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,12 +5,13 @@ import { parseProxyLogMetadata } from './proxyLogMeta.js';
|
||||
describe('proxyLogMeta', () => {
|
||||
it('parses all supported proxy log prefixes', () => {
|
||||
expect(parseProxyLogMetadata(
|
||||
'[client:codex] [session:turn-1] [downstream:/v1/responses] [upstream:/responses] boom',
|
||||
'[client:codex] [session:turn-1] [downstream:/v1/responses] [upstream:/responses] [usage:self-log] boom',
|
||||
)).toEqual({
|
||||
clientKind: 'codex',
|
||||
sessionId: 'turn-1',
|
||||
downstreamPath: '/v1/responses',
|
||||
upstreamPath: '/responses',
|
||||
usageSource: 'self-log',
|
||||
messageText: 'boom',
|
||||
});
|
||||
});
|
||||
@@ -21,6 +22,7 @@ describe('proxyLogMeta', () => {
|
||||
sessionId: null,
|
||||
downstreamPath: null,
|
||||
upstreamPath: null,
|
||||
usageSource: null,
|
||||
messageText: 'network timeout',
|
||||
});
|
||||
});
|
||||
@@ -31,6 +33,7 @@ describe('proxyLogMeta', () => {
|
||||
sessionId: 'turn-1',
|
||||
downstreamPath: null,
|
||||
upstreamPath: null,
|
||||
usageSource: null,
|
||||
messageText: 'boom',
|
||||
});
|
||||
|
||||
@@ -39,6 +42,7 @@ describe('proxyLogMeta', () => {
|
||||
sessionId: null,
|
||||
downstreamPath: null,
|
||||
upstreamPath: null,
|
||||
usageSource: null,
|
||||
messageText: 'boom',
|
||||
});
|
||||
|
||||
@@ -47,6 +51,7 @@ describe('proxyLogMeta', () => {
|
||||
sessionId: '1',
|
||||
downstreamPath: null,
|
||||
upstreamPath: '/x',
|
||||
usageSource: null,
|
||||
messageText: 'msg',
|
||||
});
|
||||
|
||||
@@ -55,6 +60,7 @@ describe('proxyLogMeta', () => {
|
||||
sessionId: null,
|
||||
downstreamPath: null,
|
||||
upstreamPath: null,
|
||||
usageSource: null,
|
||||
messageText: '',
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user