// SPDX-License-Identifier: AGPL-3.0-or-later /// // AI follow-ups (ADR-15): // // - ai_usage: tokens a workspace used per calendar month (UTC), so workspace // admins can cap their spending and superadmins can cap what each // workspace spends through the server's providers (instance_tokens). // The cap itself lives in workspaces.ai_settings and in the "ai" key of // instance_settings. // - ai_profiles.transcribe_model: the speech-to-text model of an // OpenAI-compatible profile, for audio attachments (E2). migrate( (app) => { const workspaces = app.findCollectionByNameOrId("workspaces"); app.save( new Collection({ type: "base", name: "ai_usage", fields: [ { name: "workspace", type: "relation", collectionId: workspaces.id, maxSelect: 1, required: true, cascadeDelete: true }, { name: "month", type: "text", required: true, max: 7 }, { name: "requests", type: "number" }, { name: "input_tokens", type: "number" }, { name: "output_tokens", type: "number" }, { name: "instance_tokens", type: "number" }, { name: "created", type: "autodate", onCreate: true, onUpdate: false }, { name: "updated", type: "autodate", onCreate: true, onUpdate: true }, ], indexes: ["CREATE UNIQUE INDEX idx_ai_usage_month ON ai_usage (workspace, month)"], }), ); const profiles = app.findCollectionByNameOrId("ai_profiles"); profiles.fields.add(new TextField({ name: "transcribe_model", max: 200 })); app.save(profiles); }, (app) => { app.delete(app.findCollectionByNameOrId("ai_usage")); const profiles = app.findCollectionByNameOrId("ai_profiles"); profiles.fields.removeByName("transcribe_model"); app.save(profiles); }, );