Repository navigation
Answer the owner-funded text AI with Anthropic first and Groq as fallback - #39
Merged
Merged
Conversation
…back The writing tools, the support and account assistants, Reply Rules and reader translations go through one module, lib/platform-ai.js: Claude Haiku 5.5 for routine text and classification, Sonnet 5.5 for social post drafts and the account assistant, Groq GPT-OSS-20B when Anthropic can't answer, Workers AI only where neither key may be used. Briefings' own keys stay apart; embeddings and images stay on Workers AI. On FlockStack Cloud both providers wait for the 30 days' sub-processor notice (AI_PROVIDERS_NOTICE_SENT_ON), so nothing changes until the owner sets it. The privacy policy, sub-processors and regions pages say what is true before and after. Per-account provider, model, token and cost counts are kept with no text (AiUsage.spend).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The writing tools (rewrites, subject lines, preview text, social drafts), the support and account assistants, Reply Rules and reader-requested translations now go through one module, `lib/platform-ai.js`.
Order. FlockStack's own Anthropic key (Haiku 5.5 for routine text and classification, Sonnet 5.5 for social drafts and the account assistant), then its own Groq key (GPT-OSS-20B) on an error or timeout, then Workers AI. `AI_MODEL_FAST`, `AI_MODEL_STRONG`, `AI_MODEL_FALLBACK` rename models; `AI_PROVIDERS_DISABLED=true` is a kill switch. Budgets, the once-per-request daily count, schemas, tool permissions and tab-only chat history are unchanged.
Nothing changes until the owner acts. Anthropic and Groq are new sub-processors, so on FlockStack Cloud neither is used until `AI_PROVIDERS_NOTICE_SENT_ON` in `lib/legal.js` is 30 days old (same rule as ElevenLabs). A self-hosted server uses a key as soon as it is set. Keys are Worker secrets, never `vars` (a test checks `wrangler.jsonc`).
Stays as it was. Briefings' bring-your-own-key adapters (never given these keys, never given theirs here), BGE embeddings, image generation (Workers AI), email delivery and regional data routing.
Pages. Privacy policy, `/sub-processors` (Anthropic and Groq added), regions page, consent text in the dashboard, action descriptions, README, `.env.example`, docs and code comments now say what the code does, before and after the notice. Replaces the old "never the Anthropic API" comments.
Attribution. `AiUsage.spend` keeps calls, failures, input and output tokens and a cost estimate per account per day, provider, model and feature, plus a log line with the same fields. No prompt or answer is stored or logged.
Not done / for the owner.
Tests. New: `tests/platform-ai.test.mjs`, `tests/ai-providers-notice.test.mjs`. Full suite run: 4,095 of 4,105 passed on the first pass; the failures were the API-worker target and `contacts` timing out under load, plus stale assertions I updated. Re-run and passing: legal, support, public parity (after `npm run build:public`), contacts, AI suites under `FLOCKSTACK_API_TARGET=worker`, api-worker, router, query budget. Lint has 0 errors; `build:public`, `build:api`, `build:readers`, `build:briefings` succeed. A real Anthropic or Groq call was not made.