agentJson method

JsonMap agentJson(
  1. FakeAgent a
)

The API Agent of a: its person's handle, name and status, the configured policy (credential_holder_id only with personal) and the presence (AgentRuntimeStatus) with the reported values, billing_evidence, billing_mode_matches (only with a reported mode) and the agentWarnings.

Implementation

JsonMap agentJson(FakeAgent a) {
  final p = people[a.id]!;
  final reported = a.reportedBillingMode;
  return {
    'id': a.id,
    'handle': p.handle,
    'display_name': p.displayName,
    'status': switch (p.status) {
      'active' => 'active',
      'deleted' => 'deleted',
      _ => 'disabled',
    },
    'adapter_kind': a.adapterKind,
    'description': a.description,
    'billing_mode': a.billingMode,
    if (a.billingMode == 'personal')
      'credential_holder_id': ?a.credentialHolderId,
    'billing_mode_changed_at': ?a.billingModeChangedAt,
    'tool_class': a.toolClass,
    'presence': {
      'state': a.state,
      'reported_billing_mode': ?reported,
      'last_heartbeat_at': ?a.lastHeartbeatAt,
      if (a.billingModesSupported case final modes?)
        'billing_modes_supported': List.of(modes),
      if (reported != null) 'billing_mode_matches': reported == a.billingMode,
      'billing_evidence': {
        'provider': 'anthropic',
        'key_type': a.keyType,
        'method': ?a.evidenceMethod,
      },
      'warnings': agentWarnings(a),
    },
    'operator_config': <String, Object?>{},
    'version': a.version,
  };
}