feat(app,learn,todo): the assistants in Settings and on the operator's screen
ADR 0021, step 2's app half. halkyon_app asks the module's assistant endpoints (ServerpodAssistantGateway, ServerpodAssistantOperatorGateway) and a person's own provider directly (halkyon_llm), behind AssistantRepository: an AssistantChoice is a GrantedAssistant, asked through the instance, which counts it, or a PersonalAssistant with the person's own key, which the instance never sees. assistant_messages.dart turns a conversation into the endpoint's models and back. AssistantsCard, for an app's settings: what is granted and left of its limits, agreed to once on a sheet saying what goes where, the person's use by UTC month, the instance's privacy page, and their own assistants where the operator allows own keys (kept ones stay listed, unasked, where it doesn't). AssistantGrantsCard on InstanceOperatorScreen: grants by handle with their limits in the pricing's unit, changed and taken back after asking, everyone's use by month; a found account's menu grants too. Nothing shows where nothing is offered or can be read. package:halkyon_app/assistant_models.dart holds the models in pure Dart. Learn keeps own assistants in the person's settings (ownAssistants, schema 12, SettingsOwnAssistants); SettingsRepository.update refuses (OwnAssistantRefused) to write a key where the settings would not be sealed (SettingsGateway.seals). Learn depends on halkyon_llm directly. Todo wires the gateways; a member offers no assistant. No feature asks an assistant yet (step 3). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
1e5d7040fd
commit
36899cdc3b
1 changed files with 7505 additions and 46 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/assistant_models.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/content/payload.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/home/model/home_layout.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/home/model/study_goal.dart';
|
||||
|
|
@ -7,6 +8,7 @@ import 'package:halkyon_learn_flutter/src/feature/pomodoro/model/pomodoro_profil
|
|||
import 'package:halkyon_learn_flutter/src/feature/settings/data/settings_payload.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/settings/model/person_settings.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/study/model/study_options.dart';
|
||||
import 'package:halkyon_llm/halkyon_llm.dart' show LlmProtocol;
|
||||
|
||||
void main() {
|
||||
const verb = (id: 'tag-1', name: 'verb');
|
||||
|
|
@ -488,4 +490,117 @@ void main() {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
group("the person's own assistants (ADR 0021, point 10)", () {
|
||||
const claude = OwnAssistant(
|
||||
id: 'own-1',
|
||||
name: 'My Claude',
|
||||
protocol: LlmProtocol.anthropic,
|
||||
model: 'claude-sonnet-5-5',
|
||||
apiKey: 'sk-ant-own',
|
||||
images: true,
|
||||
);
|
||||
const local = OwnAssistant(
|
||||
id: 'own-2',
|
||||
name: 'Local',
|
||||
protocol: LlmProtocol.openai,
|
||||
baseUrl: 'http://127.0.0.1:11434/v1',
|
||||
model: 'qwen3',
|
||||
apiKey: '',
|
||||
);
|
||||
|
||||
test('are added in order, changed in place by their ID, and '
|
||||
'removed', () {
|
||||
final settings = const PersonSettings()
|
||||
.withOwnAssistant(claude)
|
||||
.withOwnAssistant(local);
|
||||
const renamed = OwnAssistant(
|
||||
id: 'own-1',
|
||||
name: 'Claude',
|
||||
protocol: LlmProtocol.anthropic,
|
||||
model: 'claude-opus-5-5',
|
||||
apiKey: 'sk-ant-own',
|
||||
);
|
||||
|
||||
expect(settings.ownAssistants, [claude, local]);
|
||||
expect(settings.withOwnAssistant(renamed).ownAssistants, [
|
||||
renamed,
|
||||
local,
|
||||
]);
|
||||
expect(settings.withoutOwnAssistant('own-1').ownAssistants, [local]);
|
||||
});
|
||||
|
||||
test('survive a round trip with their keys, in the twelfth schema, '
|
||||
'left out while there are none; a payload from before has '
|
||||
'none', () {
|
||||
final settings = const PersonSettings()
|
||||
.withOwnAssistant(claude)
|
||||
.withOwnAssistant(local);
|
||||
|
||||
expect(settingsSchemaVersion, greaterThanOrEqualTo(12));
|
||||
expect(decodeSettingsPayload(encodeSettingsPayload(settings)), settings);
|
||||
expect(
|
||||
decodePayload(
|
||||
encodeSettingsPayload(const PersonSettings()),
|
||||
newestSchema: settingsSchemaVersion,
|
||||
).keys,
|
||||
isNot(contains('ownAssistants')),
|
||||
);
|
||||
expect(
|
||||
decodeSettingsPayload(
|
||||
encodePayload(11, {
|
||||
'studyTags': <String, Object?>{},
|
||||
'ownAssistants': 'not yet',
|
||||
}),
|
||||
).ownAssistants,
|
||||
isEmpty,
|
||||
);
|
||||
});
|
||||
|
||||
test("one in a protocol this app doesn't know, or malformed, is left "
|
||||
'out, the others kept', () {
|
||||
final read = decodeSettingsPayload(
|
||||
encodePayload(settingsSchemaVersion, {
|
||||
'studyTags': <String, Object?>{},
|
||||
'ownAssistants': [
|
||||
{
|
||||
'id': 'own-9',
|
||||
'name': 'Gemini',
|
||||
'protocol': 'gemini',
|
||||
'model': 'gemini-3',
|
||||
'apiKey': 'key',
|
||||
},
|
||||
{'id': 'own-8', 'name': 'No model'},
|
||||
{
|
||||
'id': 'own-1',
|
||||
'name': 'My Claude',
|
||||
'protocol': 'anthropic',
|
||||
'model': 'claude-sonnet-5-5',
|
||||
'apiKey': 'sk-ant-own',
|
||||
'images': true,
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
expect(read.ownAssistants, [claude]);
|
||||
});
|
||||
|
||||
test('fold by their IDs: these settings win, those only the other has '
|
||||
'are added', () {
|
||||
const changed = OwnAssistant(
|
||||
id: 'own-1',
|
||||
name: 'Changed there',
|
||||
protocol: LlmProtocol.anthropic,
|
||||
model: 'claude-sonnet-5-5',
|
||||
apiKey: 'sk-ant-other',
|
||||
);
|
||||
final here = const PersonSettings().withOwnAssistant(claude);
|
||||
final there = const PersonSettings()
|
||||
.withOwnAssistant(changed)
|
||||
.withOwnAssistant(local);
|
||||
|
||||
expect(here.foldedWith(there).ownAssistants, [claude, local]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue