* refactor(ai-core): move the connection presets into their own file draft.rs was 519 lines. The built-in presets and their static model lists are data that changes on a different schedule from the save rules, so they move to draft/presets.rs unchanged. Three mutation cases follow the code. * fix(ai-core,ai-egui): match the upstream contract fixes for required inputs and test-result addresses A model now has to accept every input a tool sends and require no input the tool cannot supply; the picker, binding, app status and planning agree, and a refusal happens before a key is read or anyone is asked to consent. A connection test result is recorded with the address the test started with (ConnectionDraft::set_models(address, models)), so a late answer for an old address is refused and loaded, preset and tested models keep their address through repeated edits. The shared connection panel passes the captured address. docs/CORE-SYNC.md says what this local copy still adds beyond craft-libs, and the mutation group 'ca' covers the ten safety rules. Two mutation anchors that matched twice are fixed. * docs: document the functions this change adds CodeRabbit's docstring check was below its 80% bar. Test functions get a one-line sentence from their name; helpers and session methods get a real description.
4.1 KiB
Suite-wide AI contract for app maintainers
Status: the initial contract crate (craft-ai-core) has landed in storytold/craft-libs. This workspace still carries a local copy with additional consent terms and model folders; its upstream safety fixes are aligned, but the dependency switch has prerequisites in CORE-SYNC.md. No production app adoption is established by the contract merge. See STATUS.md for what is tested and what is open.
Ownership boundary
| Shared crates | Each app or launcher |
|---|---|
| Versioned connection/model/tool declarations, suite defaults and per-app overrides in one shared store | App-specific tool UI, request construction, document changes, display of results |
| Model compatibility, binding resolution, consent and job contract | A suitable registered execution adapter, if the chosen backend is actually supported in that app |
| Shared picker, connection panel and optional reusable widgets | Where/how those widgets appear, and app-specific setup |
A registered tool is a declaration, not installed code. A compatible binding is not evidence that a provider can execute the request. Apps must fail explicitly when the selected adapter is absent, not silently substitute another engine. A separate database should be added only for an identified indexing or coordination need; the current versioned store remains authoritative for these settings.
Declaring and adopting a tool
- Define a
craft_ai_core::Rolewith a stableRoleId, a display label, oneCapabilityId, and a nonempty set ofInputRoles. Choose a suite-wide ID with the other maintainers.ToolDesk::register_tool(role)writes it once to the shared store;ToolDesk::custom_tools()reads registered declarations in any process using that same store. Built-in IDs cannot be replaced. A declaration does not add it to the seven built-in catalogue. - Add or discover a connection and a model advertising that capability and the required inputs.
ToolDesk::choose(&role, &connection_id, &model_id)sets the suite default. The shared update verifies the declared tool contract and model compatibility before persisting the binding. An app can useAiClient::bindfor an explicit per-app override. Removal withToolDesk::remove_tool(&role_id)deletes the declaration and its suite/app bindings together. - An app reads the same store and resolves the role with
AiClient::status,choices,picker,planandstartas appropriate. It may localise the label, but must not reinterpret the same ID's capability or inputs. Mismatched contracts are rejected during resolution, model listing, picker creation and binding. Apps still own their UI, input conversion and actual execution route.
Concrete API examples and regressions: crates/ai-client/tests/custom_tools.rs, crates/ai-core/tests/custom_tools.rs and crates/ai-native/tests/shared_store.rs. The shared store is craft_ai_native::shared::SharedStore; it uses locked atomic updates for registration, binding and removal. Old version-1 JSON files without custom_tools still load with an empty list. Secret values belong in the secret store, never in the shared JSON or a tool declaration.
Deliberate limits and next gate
The current surface does not ship a dynamic adapter registry for arbitrary user code, a general tool executor, app-specific menus, automatic model installation or a complete provider route. Existing native/hosted adapters have separate capability and real-service gates. The executable adoption example the maintainers asked for exists: crates/ai-client/tests/third_party_adoption.rs, walked through in ADOPT-A-TOOL.md. It proves a declared tool, a bound connection and a registered adapter running one request across two independent app clients, with consent per app, cancellation, an app that lacks the adapter (refused at plan, no key read), and a store file from before custom tools existed. Not covered: a real store migration (the schema is still version 1, so there is nothing to migrate yet), a real keychain, and a real hosted service. The apps themselves remain outside this shared-platform task.