(rawType: string, payload: unknown)
| 1367 | * 3) genuine protocol "event.*" events: event.message.created, event.session.*, … |
| 1368 | */ |
| 1369 | export function classifyFrame(rawType: string, payload: unknown): FrameRoute { |
| 1370 | if (CONTROL_FRAME_TYPES.has(rawType)) return { route: 'ignore' }; |
| 1371 | |
| 1372 | const hasPrefix = rawType.startsWith('event.'); |
| 1373 | const name = hasPrefix ? rawType.slice('event.'.length) : rawType; |
| 1374 | |
| 1375 | // Ambiguous delta events: disambiguate by payload shape regardless of prefix. |
| 1376 | if (AMBIGUOUS_DELTA_NAMES.has(name)) { |
| 1377 | if (deltaIsRawAgentCore(payload)) return { route: 'agent', agentType: name }; |
| 1378 | // Object delta or protocol-shaped payload → projected protocol event. |
| 1379 | return { route: 'protocol' }; |
| 1380 | } |
| 1381 | |
| 1382 | // Unprefixed frames are raw agent-core (real daemon) when we know the name. |
| 1383 | if (!hasPrefix) { |
| 1384 | if (KNOWN_AGENT_CORE_TYPES.has(name)) return { route: 'agent', agentType: name }; |
| 1385 | // Unknown unprefixed name with no protocol meaning → still try the projector |
| 1386 | // (it safely no-ops on unknown types and advances nothing). |
| 1387 | return { route: 'agent', agentType: name }; |
| 1388 | } |
| 1389 | |
| 1390 | // Prefixed frames: genuine protocol events take priority. |
| 1391 | if (PROTOCOL_EVENT_NAMES.has(name)) return { route: 'protocol' }; |
| 1392 | // Prefixed agent-core event (e.g. event.turn.started) → strip + project. |
| 1393 | if (KNOWN_AGENT_CORE_TYPES.has(name)) return { route: 'agent', agentType: name }; |
| 1394 | // Unknown "event.*" → let toAppEvent() record it as an unknown protocol event. |
| 1395 | return { route: 'protocol' }; |
| 1396 | } |
| 1397 | |
| 1398 | /** |
| 1399 | * True when an assistant.delta / thinking.delta payload is in the RAW agent-core |
no test coverage detected