50 lines
1.3 KiB
Dart
50 lines
1.3 KiB
Dart
import "../analytics/analytics_service.dart";
|
|
import "analytics_config.dart";
|
|
|
|
abstract class ToolTelemetryClient {
|
|
Future<void> recordToolCall({
|
|
required String toolName,
|
|
required bool success,
|
|
int? durationMs,
|
|
Map<String, Object?> metadata = const <String, Object?>{},
|
|
});
|
|
}
|
|
|
|
class NullToolTelemetryClient implements ToolTelemetryClient {
|
|
const NullToolTelemetryClient();
|
|
|
|
@override
|
|
Future<void> recordToolCall({
|
|
required String toolName,
|
|
required bool success,
|
|
int? durationMs,
|
|
Map<String, Object?> metadata = const <String, Object?>{},
|
|
}) async {}
|
|
}
|
|
|
|
class LocalToolTelemetryClient implements ToolTelemetryClient {
|
|
const LocalToolTelemetryClient();
|
|
|
|
@override
|
|
Future<void> recordToolCall({
|
|
required String toolName,
|
|
required bool success,
|
|
int? durationMs,
|
|
Map<String, Object?> metadata = const <String, Object?>{},
|
|
}) async {
|
|
final eventMetadata = <String, Object?>{
|
|
"tool_name": toolName,
|
|
"success": success,
|
|
if (durationMs != null) "duration_ms": durationMs,
|
|
...metadata,
|
|
};
|
|
logAnalyticsEvent("tool_call", eventMetadata);
|
|
}
|
|
}
|
|
|
|
ToolTelemetryClient createToolTelemetryClient() {
|
|
if (isTelemetryDisabled()) {
|
|
return const NullToolTelemetryClient();
|
|
}
|
|
return const LocalToolTelemetryClient();
|
|
}
|