addAgent method

FakeAgent addAgent({
  1. required String handle,
  2. required String displayName,
  3. String billingMode = 'organization',
  4. String? credentialHolderId,
  5. String? reportedBillingMode,
  6. List<String>? billingModesSupported = const ['organization', 'personal'],
  7. String adapterKind = 'hermes',
  8. String state = 'online',
  9. String keyType = 'api_key',
})

Adds an agent person (through addPerson, kind agent) and its FakeAgent with the given configured and reported values, as if its first heartbeat had just arrived; returns the FakeAgent.

credentialHolderId is stored as given, so a test can build a world that already breaks I1 (10 5.4) and repair it through the API.

Implementation

FakeAgent addAgent({
  required String handle,
  required String displayName,
  String billingMode = 'organization',
  String? credentialHolderId,
  String? reportedBillingMode,
  List<String>? billingModesSupported = const ['organization', 'personal'],
  String adapterKind = 'hermes',
  String state = 'online',
  String keyType = 'api_key',
}) {
  final p = addPerson(
    handle: handle,
    displayName: displayName,
    kind: 'agent',
  );
  final a = FakeAgent(
    id: p.id,
    billingMode: billingMode,
    credentialHolderId: credentialHolderId,
    reportedBillingMode: reportedBillingMode,
    billingModesSupported: billingModesSupported == null
        ? null
        : List.of(billingModesSupported),
    adapterKind: adapterKind,
    state: state,
    keyType: keyType,
  )..lastHeartbeatAt = stamp();
  a.mismatchAtHeartbeat =
      reportedBillingMode != null && reportedBillingMode != billingMode;
  agents[a.id] = a;
  return a;
}