MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / resolvePayload

Function resolvePayload

packages/agent-core/src/logging/logger.ts:356–388  ·  view source on GitHub ↗
(
  payload: LogPayload,
)

Source from the content-addressed store, hash-verified

354}
355
356function resolvePayload(
357 payload: LogPayload,
358): { ctx: LogContext | undefined; error: LogEntry['error'] } {
359 if (payload === undefined || payload === null) {
360 return { ctx: undefined, error: undefined };
361 }
362 if (payload instanceof Error) {
363 return { ctx: undefined, error: extractError(payload) };
364 }
365 if (typeof payload === 'object') {
366 // bunyan-style: a `{ error: Error }` field is hoisted out, stack extracted.
367 const obj = payload as Record<string, unknown>;
368 if (obj['error'] instanceof Error) {
369 const { error: errValue, ...rest } = obj;
370 return { ctx: rest as LogContext, error: extractError(errValue) };
371 }
372 return { ctx: obj as LogContext, error: undefined };
373 }
374 if (
375 typeof payload === 'string' ||
376 typeof payload === 'number' ||
377 typeof payload === 'boolean' ||
378 typeof payload === 'bigint' ||
379 typeof payload === 'symbol'
380 ) {
381 return { ctx: { reason: String(payload) }, error: undefined };
382 }
383 if (typeof payload === 'function') {
384 const reason = payload.name === '' ? '[Function]' : `[Function: ${payload.name}]`;
385 return { ctx: { reason }, error: undefined };
386 }
387 return { ctx: { reason: Object.prototype.toString.call(payload) }, error: undefined };
388}
389
390function mergeCtx(
391 payloadCtx: LogContext | undefined,

Callers 1

emitAtMethod · 0.85

Calls 1

extractErrorFunction · 0.90

Tested by

no test coverage detected