Repository navigation
Description
Goal
An embedding application can register its own AI provider kinds through Wiring. Users can store, list, edit, activate and delete provider configs of those kinds like the built-in ones, and connecting builds the provider through the registered kind. Community registers none and behaves exactly as before.
Context
ProviderTypeis a closed enum (crates/core/src/ai/types.rs:40) whose values are tied to aCHECKconstraint onai_provider_configs.provider_type(crates/persistence-sqlite/migrations/0002_ai_provider_configs.sql). Later columns: 0005 (extra_headers,attestation_url), 0013 (max_tokens_override), 0019 (web_research_enabled). The newest migration is 0030.credential_refisNOT NULL, andbuild_ai_provider_from_config[_async](crates/app-logic/src/ai_provider_factory.rs:152/:183) always reads a key from the credential store first.build_ai_provider(:52) is a closedmatchonProviderType.Wiring::ai_provider_decorators(crates/app-shell/src/wiring.rs) can only wrap a built provider. There is no way to add a kind.Wiring::ai_providersis unused (ADR 0035).- Commands:
crates/app-shell/src/commands/ai_providers.rs(list/add/update/delete/set_active,discover_models,test_ai_provider_credentials,fetch_attestation_info). DTOs:crates/app-logic/src/dto/ai_provider.rs. Store:crates/persistence-sqlite/src/ai_provider_store.rs. - The text-only tool fallback (
crates/ai-providers/src/fallback.rs) is used inside the built-in providers whensupports_native_tool_callingis false. - Specs 0006, 0007, 0038 (§2 extension points). ADR 0035.
Requirements
- A new trait in
app-logic(name chosen by the coder, e.g.AiProviderKind) with:id(), matching^[a-z][a-z0-9_]{0,63}$needs_credential()validate_settings(&serde_json::Value), returning a user-facing errorbuild(...), which returnsBox<dyn AiProvider>or an error. Its input holds the validated settings, the model string, the credential if one is needed, and the purpose of the build (chat connect, notes, second opinion, credential test) as the factory knows it today.- an optional
test(...)for the "test connection" button. The default reports "not supported".
Wiringgets a list of these kinds. Community registers none. A duplicate or invalid id makes startup fail, like duplicate UI preference keys.ProviderTypegets one new valueextension(serde/DB"extension"). The kind id and the settings live in two new columns,extension_kind TEXTandextension_settings TEXT(JSON). Both are NULL for built-in kinds and required forextension.credential_refbecomes nullable, and is NULL only for anextensionconfig whose kind needs no credential.- A migration (0031 or the next free number) rebuilds
ai_provider_configsso that the CHECK constraint allowsextension. It keeps all rows, columns, indexes and the single-active index. - The factory reads a credential only when one is needed. For
extensionit looks up the kind and callsbuild, then applies the decorators as for every other provider. If the kind is not registered orbuildfails, connecting fails with a clear error. There is no fallback to another provider. - An extension kind can say it has no native tool calling. The provider it builds can then use the core's existing text-action fallback (system-prompt section plus parsing of the action markers,
fallback.rs) without copying it. How it is exposed (a wrapper or a public helper) is the coder's choice. - The commands accept
extensionwith a kind id and settings, validate through the kind and reject unknown kinds.listmarks configs whose kind is not registered as unavailable and still returns them, so they can be deleted.discover_models,fetch_attestation_infoand the credential test go through the kind or answer "not supported". They never call an HTTP endpoint for an extension config. - Backup export/import (
crates/app-logic/src/backup/) carries extension configs including their settings. Import of an unknown kind keeps the row, marked unavailable. - Spec 0006 or 0007 (section on provider configs) and Spec 0038 §2 describe the new extension point, and
docs/codemap.mdlists the new module.
Acceptance Criteria
- With no kind registered, all existing provider tests pass unchanged and a test asserts that the Community
Wiringregisters no kind. - Migration test: a database with rows of all four built-in kinds migrates with every value unchanged. Afterwards an
extensionrow with a NULLcredential_refcan be inserted, and a row with an unknownprovider_typeis still rejected. - A test kind registered in a test
Wiringcan be added, listed, updated, activated and deleted through the commands. Invalid settings are rejected with the kind's message. - Connecting with an extension config builds the provider through the kind and runs the registered decorators. A kind with
needs_credential() == falsecauses no credential-store read (asserted with a counting store). - An extension config whose kind is not registered is listed as unavailable, can be deleted, and connecting with it fails with a clear error and builds no other provider.
- A provider of a test kind without native tool calling produces
ActionProposedfrom the text action markers through the shared fallback (test). -
discover_modelsand the credential test for an extension config make no HTTP request. - Backup round trip keeps extension configs and their settings.
- A startup test: duplicate or invalid kind ids make the app fail at startup.
- Relevant automated tests pass (
cargo testfor the touched crates, frontend type check after regenerating IPC types).
Technical Notes
- Data model change: migration on
ai_provider_configs. Follow the table-rebuild pattern of earlier migrations and keep foreign keys and indexes. ProviderTypestaysCopy. The kind id lives on the config, not in the enum. Places that storeProviderType(usage records, budget guard identity) keep working withextension. The budget identity for extension configs is the coder's choice and is documented.- Security: a kind cannot touch
FilterEngine::evaluate(), the confirmation path or redaction. It only builds anAiProvider, which receives theRedactedContextlike every provider. Settings are not secret storage (doc comment on the trait). - The frontend part (settings dialog) is a separate issue. This issue only regenerates
generated/ipc.tsfor the new DTO fields.
Files: crates/core/src/ai/types.rs, crates/persistence-sqlite/migrations/, crates/persistence-sqlite/src/ai_provider_store.rs, crates/app-logic/src/ai_provider_factory.rs, crates/app-logic/src/ (new kind module), crates/app-logic/src/dto/ai_provider.rs, crates/app-logic/src/backup/, crates/app-shell/src/wiring.rs, crates/app-shell/src/commands/ai_providers.rs, crates/app-shell/src/commands/connect/, crates/ai-providers/src/fallback.rs, apps/smart-ssh-community/frontend/src/generated/ipc.ts, docs/specs/0006-ai-provider-trait.md, docs/specs/0038-repository-app-shell-ci.md, docs/codemap.md
Spec impact: update 0006, update 0038
Open questions
- How to expose the text fallback to extension providers: (a) a public wrapper
TextActionFallback<P>around a provider that only streams text, (b) public parse and prompt helpers. Recommendation: (a), because one wrapper keeps the prompt and the parsing in one place.
Related Work
- Epic: Epic: AI provider kinds contributed by the embedding application #1636
- Blocked by MCP extension point: additional tools and a handle for approved commands #1632 (both change
crates/app-shell/src/wiring.rsand Spec 0038)
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
feat(app-logic): AI provider kinds contributed through Wiring (#1637)
smart-ssh-coder commentedon Dec 4, 2026
Implementation handoff
PR: #1658, head 8b4b686
Done (one commit, compiles with
cargo check --workspace --tests --all-features; no new tests run yet):ProviderType::Extension("extension");RedactedContext::with_system_text_appended/without_available_actions0031_ai_provider_extension_kinds.sql(table rebuild, saves/restoreschat_sessions.ai_provider_idthrough a temp table because FKON DELETE SET NULLfires inside sqlx's transaction; table CHECK ties extension fields toprovider_type);AiProviderConfig/Updategetextension_kind,extension_settings(JSON),credential_ref: Option<_>; backupAiProviderRow(manual struct, new fields skipped when None so old rows serialize unchanged)TextActionFallback<P>(public wrapper, option (a) from the issue),discover_modelsrefusesExtensionbefore any requestai_provider_kind.rs(traitAiProviderKind,AiProviderBuildInput/Purpose,AiProviderKindTestOutcome,AiProviderKindRegistry::newvalidates ids,is_valid_kind_id),ai_provider_management.rs(list/add/update/delete +validate_input, testable without Tauri), factory takeskinds+purposeand returnsAiProviderBuildError(+build_error_to_command),AppState::ai_provider_kinds, DTO fieldsextension_kind,extension_settings,available, backup validateWiring::ai_provider_kinds,wiring::startup_ai_provider_kinds(panics on invalid/duplicate), commands are thin wrappers; extension credential test goes throughtest_extension_credentials(kind.test, "not supported" →AI_PROVIDER_TEST_UNSUPPORTED);fetch_attestation_inforefuses extension;model_discovery_supportedRemaining (in this order):
cargo test -p persistence-sqlite -p ai-providers -p app-logic -p app-shelland fix fallout (existing tests were only adjusted mechanically).Wiringregisters no kind: alreadywiring.rs:test_community_registers_no_ai_provider_kinds.crates/persistence-sqlite/src/tests_ai_provider_extension.rs, declare inlib.rslike the othertests_*modules): database migrated to version 30 (pattern:chat_session_store.rsdatabase_at_0022), rows of all four built-in kinds + a chat session referencing a provider, run the full migrator, values unchanged, chat reference kept, extension row with NULLcredential_refinsertable, unknownprovider_typerejected, builtin row with NULL credential rejected.ai_provider_management::*, invalid settings rejected with the kind's message, unavailable kind listed withavailable=falseand deletable) in app-logic tests.needs_credential()==false⇒ counting store (InMemoryCredentialStore::get_calls) shows 0 reads; unregistered kind ⇒UnknownKind, no provider built.TextActionFallbacktest infallback.rs(inner stub provider streams text with<!--ACTION-->block ⇒ActionProposed; Refused never proposes).ProviderType::Extension; app-shell test oftest_extension_credentials(NotSupported default) andmodel_discovery_supported.backup/tests.rs;validate.rscases (inconsistent extension fields).#[should_panic]for duplicate/invalid ids viawiring::startup_ai_provider_kinds.cd apps/smart-ssh-community/frontend && npm run gen:ipc(ts-rs;extension_settingshasts(type = "unknown | null")), thennpx tsc -bandnpm run lint(check-commands etc.); add frontenderrorCodes.tsentries if the lint requires it for the new codesAI_PROVIDER_KIND_UNKNOWN,AI_PROVIDER_SETTINGS_INVALID,AI_PROVIDER_EXTENSION_INVALID,AI_PROVIDER_BUILD_FAILED,AI_PROVIDER_TEST_UNSUPPORTED.docs/codemap.md(new modulesai_provider_kind.rs,ai_provider_management.rs), a changelog fragment only if user-visible (probably none: Community registers no kind; say so in the PR), ADR for the budget identity of extension configs (kind id as endpoint + hash of credential or settings JSON) and the rule that an extension config may not carry base URL / attestation URL / extra headers;THREAT-MODEL.mdcheck (crates/app-logic/src/orchestrationnot touched; new trust boundary = kinds build providers; probably add a short note, elseThreat model: no change – …with reason).cargo clippy --workspace --all-targets,scripts/check-file-sizelimits (npm run lintin frontend runs it;ai_provider_factory.rsandai_providers.rsgrew), fix, push, PR body per section 4,wait-ci 1658.Next step: run step 1 (
cargo test -p persistence-sqlite -p ai-providers -p app-logic -p app-shell).Relevant files: crates/app-logic/src/ai_provider_kind.rs, ai_provider_management.rs, ai_provider_factory.rs:150-420; crates/app-shell/src/commands/ai_providers.rs; crates/app-shell/src/wiring.rs; crates/persistence-sqlite/migrations/0031_ai_provider_extension_kinds.sql; crates/ai-providers/src/fallback.rs.
Decisions and assumptions so far:
TextActionFallback<P>(the issue's recommendation); the kind getssupports_native_tool_callingin its build input and decides whether to wrap.discover_models/fetch_attestation_infocan never find an endpoint); a config cannot change between built-in and extension, nor to a kind needing a credential when it has none (credential_ref never changes after creation).build_ai_providerwithExtensionreturns a provider that fails every request (no panic, no HTTP).base_url = "extension:<kind>"for extension configs.AI_MODEL_DISCOVERY_UNSUPPORTED).Pitfalls: PRAGMA foreign_keys=OFF is a no-op inside sqlx migrations, hence the temp-table restore;
CommandErrorhas a blanketFrom<E: Display>, so conversions use plain functions;dyn CredentialStoreis notSync, management functions take&(dyn CredentialStore + Sync).test(persistence-sqlite): migration 0031 keeps providers and chat ref…
test(app-logic): management and factory tests for extension kinds (#1637
6 remaining items
fix: clippy expectations and lock guard in tests (#1637)
docs: AI provider kinds from the embedding app, ADR 0165 (#1637)
chore(app-shell): keep lib.rs under the size limit (#1637)
smart-ssh-coder commentedon Dec 4, 2026
Implementation ready for review. PR #1658. AI provider kinds contributed through Wiring (provider type extension, migration 0031, registry, management, factory, backup, IPC types), with tests, specs 0006/0038, ADR 0165 and threat-model note. Clippy and touched-crate tests green locally; CI green on the pushed head.
smart-ssh-reviewer commentedon Dec 4, 2026
Review: 1. crates/ai-providers/src/fallback.rs:148: TextActionFallback sends ActionProposed when the inner stream ends with TextTruncated, before TextTruncated arrives. The chat turn then asks the user to confirm that action, which Spec 0065 §3 forbids for an answer cut off by the length limit. Reproduced: [TextDelta(), TextTruncated] -> ActionProposed(ls). Never send the action on TextTruncated, and add a regression test. 2. AC 2: migration_0031_keeps_rows_and_chat_references does not prove that every value is unchanged. provider_type, display_name, model, base_url, extra_headers, attestation_url, max_tokens_override, web_research_enabled and the timestamps are not checked, and most rows use defaults. The test stayed green with display_name/model and base_url/attestation_url swapped in the migration. Seed every column with a distinct, non-default value and compare full rows. 3. AC 4: the no-credential-read test uses a config without a credential_ref, so it stayed green with credential_needed() forced to true. Add a test where the config has a credential_ref but the kind's needs_credential() is false, and assert 0 reads (sync and async builder). 4. Spec 0006 says a config of an unknown kind can be created ('lässt sich anlegen'), but add/update reject it. Align the text: kept, listed as unavailable, deletable, but cannot be created, edited, connected or tested. 5. ADR 0165 and Spec 0038 say the budget identity hashes the credential and the settings, so changing either gives a fresh budget. The code hashes the credential or, only without one, the settings. Make code and docs agree (hashing both matches the rationale), and add a test.
fix(ai-providers): address review of extension provider kinds (#1637)
smart-ssh-coder commentedon Dec 4, 2026
Implementation ready for review. PR #1658. Addressed all five review points (no action after TextTruncated, full-column migration test, no-read test with credential_ref, Spec 0006 wording, budget identity hashes credential and settings, each with a test). CI green on the pushed head.
smart-ssh-reviewer commentedon Dec 4, 2026
Review passed – moving on to merge. All five findings from the previous review are fixed in 94d4a69. Each fix has a regression test, and each test was checked by reverting the fix locally: red without the fix, green with it. The fixes: the text fallback no longer proposes an action from a truncated answer; the migration test now compares every column; a new test checks that a config with a credential reference whose kind needs no credential causes no credential read; Spec 0006 now describes unknown-kind configs correctly; the budget identity hashes both the credential and the settings, as ADR 0165 and Spec 0038 say. Touched-crate tests pass locally and CI is green. Two non-blocking follow-ups from the previous review are still open: the fallback's ordering of buffered text and errors, and backup validation of extension rows that carry URLs or headers.
feat(app-shell): register AI provider kinds through Wiring (#1658)
smart-ssh-coordinator commentedon Dec 4, 2026
Merged and branch deleted: PR #1658 (squash) in develop
smart-ssh-planner commentedon Dec 4, 2026
Follow-ups filed: #1673 Flush buffered text (markers stripped, no action) before an inner error in TextActionFallback; #1674 Backup import: reject extension AI providers carrying base URL, attestation URL or extra headers. Not filed: the style note about the duplicated cfg(test) and the Wiring-to-AppState test gap (accepted in review), and the test-assertion remark on the credential-read test (test is meaningful as is).