fix: support both string and object worker formats in parser
Handle NEEDLE's aligned format (worker as flat string) alongside legacy format (worker as nested object) for backwards compatibility. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
94030c55c2
commit
7ccfc96603
1 changed files with 9 additions and 5 deletions
|
|
@ -107,12 +107,14 @@ function isNeedleFormat(parsed: unknown): parsed is NeedleLogEntry {
|
|||
if (typeof parsed !== 'object' || parsed === null) return false;
|
||||
const obj = parsed as Record<string, unknown>;
|
||||
|
||||
// NEEDLE format has: ts (string), event (string), worker (object)
|
||||
// NEEDLE format has: ts (string), event (string), worker (object or string)
|
||||
// Worker can be either:
|
||||
// - Object: {runner, provider, model, identifier} (legacy)
|
||||
// - String: "runner-provider-model-identifier" (aligned format)
|
||||
return (
|
||||
typeof obj.ts === 'string' &&
|
||||
typeof obj.event === 'string' &&
|
||||
typeof obj.worker === 'object' &&
|
||||
obj.worker !== null
|
||||
(typeof obj.worker === 'object' || typeof obj.worker === 'string')
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -123,8 +125,10 @@ function parseNeedleFormat(entry: NeedleLogEntry): LogEvent {
|
|||
// Convert ISO timestamp to Unix milliseconds
|
||||
const ts = new Date(entry.ts).getTime();
|
||||
|
||||
// Flatten worker object: ${runner}-${identifier}
|
||||
const worker = `${entry.worker.runner}-${entry.worker.identifier}`;
|
||||
// Handle worker as string (aligned format) or object (legacy)
|
||||
const worker = typeof entry.worker === 'string'
|
||||
? entry.worker
|
||||
: `${entry.worker.runner}-${entry.worker.identifier}`;
|
||||
|
||||
// Use event as message
|
||||
const msg = entry.event;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue