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

Function toAppEvent

apps/kimi-web/src/api/daemon/mappers.ts:476–704  ·  view source on GitHub ↗
(wire: WireEvent)

Source from the content-addressed store, hash-verified

474 * - Truly unknown events are also { type: 'unknown', raw } but raw._noop is absent.
475 */
476export function toAppEvent(wire: WireEvent): AppEvent {
477 // TypeScript cannot narrow the WireEvent union through specific `case` arms
478 // because the catch-all `WireEventUnknown` member has `type: string` (broad)
479 // and `payload: unknown`, which prevents discriminated-union narrowing.
480 // We cast to `any` once here; individual cases are still logically type-safe
481 // because the union member types document the actual payload shapes.
482 // eslint-disable-next-line @typescript-eslint/no-explicit-any
483 const w = wire as any;
484 switch ((wire as { type: string }).type) {
485 // ----- Session lifecycle -----
486 case 'event.session.created':
487 return { type: 'sessionCreated', session: toAppSession(w.payload.session) };
488
489 case 'event.session.updated':
490 return {
491 type: 'sessionUpdated',
492 session: toAppSession(w.payload.session),
493 changedFields: w.payload.changed_fields,
494 };
495
496 case 'event.session.deleted':
497 return { type: 'sessionDeleted', sessionId: w.session_id };
498
499 // ----- Workspace lifecycle -----
500 case 'event.workspace.created':
501 return { type: 'workspaceCreated', workspace: toAppWorkspace(w.payload.workspace) };
502
503 case 'event.workspace.updated':
504 return { type: 'workspaceUpdated', workspace: toAppWorkspace(w.payload.workspace) };
505
506 case 'event.workspace.deleted':
507 return {
508 type: 'workspaceDeleted',
509 workspaceId: w.payload.workspace_id,
510 root: w.payload.root,
511 };
512
513 case 'event.session.status_changed':
514 return {
515 type: 'sessionStatusChanged',
516 sessionId: w.session_id,
517 status: toAppSessionStatus(w.payload.status),
518 previousStatus: toAppSessionStatus(w.payload.previous_status),
519 currentPromptId: w.payload.current_prompt_id,
520 };
521
522 case 'event.session.usage_updated':
523 return {
524 type: 'sessionUsageUpdated',
525 sessionId: w.session_id,
526 usage: toAppSessionUsage(w.payload.usage),
527 };
528
529 case 'event.session.history_compacted':
530 return {
531 type: 'historyCompacted',
532 sessionId: w.session_id,
533 beforeSeq: w.payload.before_seq,

Callers 1

connectEventsMethod · 0.90

Calls 10

toAppSessionFunction · 0.85
toAppWorkspaceFunction · 0.85
toAppSessionStatusFunction · 0.85
toAppSessionUsageFunction · 0.85
toAppGoalFunction · 0.85
toAppMessageFunction · 0.85
toAppApprovalRequestFunction · 0.85
toAppQuestionRequestFunction · 0.85
toAppTaskFunction · 0.85
toAppConfigFunction · 0.85

Tested by

no test coverage detected