Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m47s
Gitea CI / Check code and tests (push) Successful in 7m15s
Gitea CI / Build Android APK (push) Successful in 4m6s
Gitea CI / Build Windows x64 app (push) Successful in 3m34s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m29s
Gitea CI / Gitea CI passed (push) Successful in 1s
Gitea Release / Prepare draft Release (push) Failing after 8s
Gitea Release / Upload Android to draft Release (push) Skipped
Gitea Release / Upload Windows to draft Release (push) Skipped
Gitea Release / Verify and publish Release (push) Skipped
99 lines
3.5 KiB
Dart
99 lines
3.5 KiB
Dart
import '../../integrations/agent/agent_models.dart';
|
|
|
|
import 'package:drift/drift.dart' hide JsonKey;
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
|
import '../app_database.dart';
|
|
|
|
part 'agent_settings_repository.g.dart';
|
|
|
|
@Riverpod(keepAlive: true)
|
|
AgentSettingsRepository agentSettingsRepository(Ref ref) =>
|
|
DriftAgentSettingsRepository(ref.watch(appDatabaseProvider));
|
|
|
|
class DriftAgentSettingsRepository implements AgentSettingsRepository {
|
|
DriftAgentSettingsRepository(this._database);
|
|
|
|
final AppDatabase _database;
|
|
|
|
@override
|
|
Future<AgentSettingsState> load() async {
|
|
final configuration = await (_database.select(
|
|
_database.agentConfigurations,
|
|
)..where((table) => table.id.equals(0))).getSingleOrNull();
|
|
final providerRows = await (_database.select(
|
|
_database.agentProviders,
|
|
)..orderBy([(table) => OrderingTerm.asc(table.name)])).get();
|
|
final modelRows = await (_database.select(
|
|
_database.agentModels,
|
|
)..orderBy([(table) => OrderingTerm.asc(table.modelId)])).get();
|
|
return AgentSettingsState(
|
|
enabled: configuration?.enabled ?? false,
|
|
selectedProviderId: configuration?.selectedProviderId,
|
|
selectedModelId: configuration?.selectedModelId,
|
|
revision: configuration?.revision ?? 0,
|
|
providers: [
|
|
for (final provider in providerRows)
|
|
AgentProviderSettings(
|
|
id: provider.id,
|
|
enabled: provider.enabled,
|
|
name: provider.name,
|
|
apiType: provider.apiType,
|
|
baseUrl: provider.baseUrl,
|
|
credentialId: provider.credentialId,
|
|
models: [
|
|
for (final model in modelRows)
|
|
if (model.providerId == provider.id)
|
|
AgentModelSettings(
|
|
id: model.modelId,
|
|
contextWindow: model.contextWindow,
|
|
maxOutputTokens: model.maxOutputTokens,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
@override
|
|
Future<void> save(AgentSettingsState settings) =>
|
|
_database.transaction(() async {
|
|
await _database.delete(_database.agentModels).go();
|
|
await _database.delete(_database.agentProviders).go();
|
|
await _database.batch((batch) {
|
|
batch.insertAll(_database.agentProviders, [
|
|
for (final provider in settings.providers)
|
|
AgentProvidersCompanion.insert(
|
|
id: provider.id,
|
|
enabled: Value(provider.enabled),
|
|
name: provider.name,
|
|
apiType: provider.apiType,
|
|
baseUrl: provider.baseUrl,
|
|
credentialId: Value(provider.credentialId),
|
|
),
|
|
]);
|
|
batch.insertAll(_database.agentModels, [
|
|
for (final provider in settings.providers)
|
|
for (final model in provider.models)
|
|
AgentModelsCompanion.insert(
|
|
providerId: provider.id,
|
|
modelId: model.id,
|
|
contextWindow: Value(model.contextWindow),
|
|
maxOutputTokens: Value(model.maxOutputTokens),
|
|
),
|
|
]);
|
|
});
|
|
await _database
|
|
.into(_database.agentConfigurations)
|
|
.insertOnConflictUpdate(
|
|
AgentConfigurationsCompanion.insert(
|
|
id: const Value(0),
|
|
enabled: settings.enabled,
|
|
selectedProviderId: Value(settings.selectedProviderId),
|
|
selectedModelId: Value(settings.selectedModelId),
|
|
revision: settings.revision,
|
|
),
|
|
);
|
|
});
|
|
}
|