resolvePath static method

ZorphyLens<AgentMessage, Object?>? resolvePath(
  1. String pointer
)

Resolves a JSON Pointer into a ZorphyLens over AgentMessage.

One switch step per segment, so a pointer costs O(depth) — no regex, no mirrors, no reflective lookup.

A pointer this node does not carry answers null.

Implementation

static ZorphyLens<AgentMessage, Object?>? resolvePath(String pointer) {
  return switch (pointer) {
    '/role' => ZorphyLens<AgentMessage, Object?>(
      path: '/role',
      get: (root) => root.role,
      set: (root, value) => root.copyWith(role: value as AgentMessageRole),
    ),
    '/text' => ZorphyLens<AgentMessage, Object?>(
      path: '/text',
      get: (root) => root.text,
      set: (root, value) => root.copyWith(text: value as String),
    ),
    '/turn' => ZorphyLens<AgentMessage, Object?>(
      path: '/turn',
      get: (root) => root.turn,
      set: (root, value) => root.copyWith(turn: value as int),
    ),
    _ => null,
  };
}