Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,31 @@ POSTHOG_SESSION_REPLAY=

# ─── Support assistant (FlockStack Cloud only) ──────────────────────────────────

# The help chat answers from FlockStack's docs with Cloudflare Workers AI, the Worker's "ai" binding in wrangler.jsonc
# (README, Support assistant). Without the binding it doesn't render. A self-hosted server ignores both.
# Answers a day per Worker, all visitors together. Default 300, which fits Workers AI's free daily allocation.
# The help chat answers from FlockStack's docs with the text AI below (README, Support assistant). Without one it doesn't render.
# A self-hosted server ignores it.
# Answers a day per Worker, all visitors together. Default 300.
SUPPORT_DAILY_LIMIT=
# Where "Email a human" sends a conversation. Default hello@flockstack.io, the address on the legal pages.
SUPPORT_EMAIL=

# ─── AI writing tools ───────────────────────────────────────────────────────────

# The editor's rewrite, subject line, preview text and social post tools run on Cloudflare Workers AI, the Worker's "ai" binding
# in wrangler.jsonc (README, AI writing tools). Without the binding the buttons don't render. On FlockStack Cloud each plan
# ─── Text AI ────────────────────────────────────────────────────────────────────

# The editor's writing tools, the support and account assistants, Reply Rules and reader-requested translations (README, Text AI).
# Your own Anthropic key first, your own Groq key if Anthropic can't answer, Workers AI (the "ai" binding in wrangler.jsonc) when
# neither is set. On FlockStack Cloud neither key is used until AI_PROVIDERS_NOTICE_SENT_ON in lib/legal.js is 30 days old.
# These are not a Briefing's keys: those are each owner's own.
ANTHROPIC_API_KEY=
GROQ_API_KEY=
# Optional model names. Defaults claude-haiku-5-5, claude-sonnet-5-5 and openai/gpt-oss-20b.
AI_MODEL_FAST=
AI_MODEL_STRONG=
AI_MODEL_FALLBACK=
# true sends all of it back to Workers AI.
AI_PROVIDERS_DISABLED=

# Without any of the above the buttons don't render. On FlockStack Cloud each plan
# has its daily requests in lib/plans.js; a self-hosted server has none, unless this is set.
# AI requests a day per account, counted in UTC days. 0 turns the tools off. Empty: no limit.
AI_DAILY_LIMIT=
Expand Down
4 changes: 2 additions & 2 deletions PORT-PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ Customers' own archive domains and shared addresses' DNS, native on Cloudflare.

## Support assistant (branch feat/support-assistant)

A help chat on FlockStack's own pages, FlockStack Cloud only (README, Support assistant), answering from the docs with Workers AI.
A help chat on FlockStack's own pages, FlockStack Cloud only (README, Support assistant), answering from the docs with the text AI (`lib/platform-ai.js`: Anthropic, then Groq, then Workers AI).

- **Pieces.** `lib/marketing/support-corpus.js` reads the docs pages' and legal pages' server components as text (`support-page-text.js`, without react-dom/server), adds one chunk per API endpoint, the prices and the FAQ, and indexes them with BM25 in memory (`support-search.js`). `support-prompt.js` holds the rules and reads the model's answer and citations back; `support-context.js` the signed-in account's few facts; `support-assistant.js` the two routes' handlers, reached through `siteExtensions.supportAssistant` from `app/api/support/chat` and `app/api/support/email`. The UI is `components/marketing/SupportChat.jsx` (renders only with the `AI` binding) and `PanelSupportChat.jsx`.
- **Choices.** Qwen3 30B A3B, then gpt-oss-20b, through the default AI Gateway with logs off. No Vectorize: about 300 chunks, scored in well under a millisecond. Nothing a person types is stored; the legal placeholders for it are filled.
- **Not done.** A real Workers AI call (stub only in tests). Streaming answers. Per-region wording in answers beyond what the docs say. An admin view of how often it says "I don't know" (it would need counting without the text).
- **Not done.** A real model call (stubs only in tests). Streaming answers. Per-region wording in answers beyond what the docs say. An admin view of how often it says "I don't know" (it would need counting without the text).

## Pricing v2 (branch feat/pricing-v2)

Expand Down
34 changes: 26 additions & 8 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions app/(app)/campaigns/[id]/collaborate/page.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { listCustomFields } from "@/lib/custom-fields";
import { getNewsletterTiers } from "@/lib/tier-rules";
import { getAiBinding } from "@/lib/ai";
import { isTextAiAvailable } from "@/lib/platform-ai";
import { getGiphyKey } from "@/lib/giphy";
import { getUnsplashKey } from "@/lib/unsplash";
import Link from "next/link";
Expand All @@ -18,6 +18,6 @@ export default async function CollaborativeCampaignPage({ params }) {
if (campaign.failure) return <LayoutNarrow><p role="alert">{campaign.failure.message}</p></LayoutNarrow>;
openNewsletter(context, campaign.output.newsletterId, `/campaigns/${id}/collaborate`);
if (process.env.COLLABORATION_ENABLED !== "true" || campaign.output.status !== "draft" || campaign.output.format !== "rich") return <LayoutNarrow><HeaderPage title="Edit together" /><p>Realtime editing needs a rich-text draft and the optional collaboration Worker enabled on this server.</p><Link href={`/campaigns/${id}`}>Return to issue</Link></LayoutNarrow>;
const [collaborators, snippets, fields, ai] = await Promise.all([runDashboardAction("list_editor_collaborators", { id }), runDashboardAction("list_snippets", { newsletter: campaign.output.newsletterId }), listCustomFields(context.account, campaign.output.newsletterId), getAiBinding()]);
const [collaborators, snippets, fields, ai] = await Promise.all([runDashboardAction("list_editor_collaborators", { id }), runDashboardAction("list_snippets", { newsletter: campaign.output.newsletterId }), listCustomFields(context.account, campaign.output.newsletterId), isTextAiAvailable()]);
return <div className="mx-auto w-full max-w-7xl"><HeaderPage title="Edit together" /><CollaborativeCampaign viewerId={String(context.user.id)} id={id} newsletterId={campaign.output.newsletterId} collaborators={collaborators.output?.collaborators ?? []} editorOptions={{ fields: fields.map(({ key, label, type }) => ({ key, label, type })), snippets: (snippets.output?.snippets ?? []).map(({ name, content }) => ({ name, content })), tiers: getNewsletterTiers(context.selected), isAiEnabled: Boolean(ai), hasStockPhotos: Boolean(getUnsplashKey()), hasGifs: Boolean(getGiphyKey()) }} /></div>;
}
4 changes: 2 additions & 2 deletions app/(app)/campaigns/[id]/edit/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { notFound, redirect } from "next/navigation";
import FormPublishedIssue from "@/components/FormPublishedIssue";
import { scoped } from "@/lib/account-scope";
import { runAction } from "@/lib/actions/run-action";
import { getAiBinding } from "@/lib/ai";
import { isTextAiAvailable } from "@/lib/platform-ai";
import { hasActiveSubscription } from "@/lib/account-state";
import { getArchiveUrls } from "@/lib/archive-hosts";
import { listCustomFields } from "@/lib/custom-fields";
Expand Down Expand Up @@ -31,7 +31,7 @@ export default async function EditPublishedPage({ params }) {
if (!newsletter) notFound();

const [ai, fields, { snippets }] = await Promise.all([
getAiBinding(),
isTextAiAvailable(),
listCustomFields(account, newsletter._id),
runAction("list_snippets", { account, user, via: "dashboard", input: { newsletter: String(newsletter._id) } }),
]);
Expand Down
4 changes: 2 additions & 2 deletions app/(app)/campaigns/[id]/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import FormCampaign from "@/components/FormCampaign";
import FormShortPost from "@/components/FormShortPost";
import { htmlToMarkdown } from "@/lib/html-to-markdown";
import { scoped } from "@/lib/account-scope";
import { getAiBinding } from "@/lib/ai";
import { isTextAiAvailable } from "@/lib/platform-ai";
import { getAccountSendProblem, hasActiveSubscription, isBlocked } from "@/lib/account-state";
import { getArchiveUrls } from "@/lib/archive-hosts";
import { runAction } from "@/lib/actions/run-action";
Expand Down Expand Up @@ -55,7 +55,7 @@ export default async function CampaignPage({ params }) {
// The previews and the checks show the address its emails print.
const newsletter = { ...stored, postalAddress: getPostalAddress(stored, siteExtensions.defaultPostalAddress) };
if (campaign.kind === "note") return <FormShortPost campaign={{ id: String(campaign._id), status: campaign.status, scheduledAt: campaign.status === "scheduled" ? new Date(campaign.scheduledAt).toISOString() : null, webViews: campaign.webViews ?? 0 }} body={campaign.format === "markdown" ? campaign.markdown : htmlToMarkdown(campaign.html ?? "")} archiveUrl={newsletter.archiveEnabled && campaign.archiveSlug ? getArchiveUrls(newsletter).absolutePost(campaign.archiveSlug) : null} />;
const [plan, ai] = await Promise.all([getPlanState(account), getAiBinding()]);
const [plan, ai] = await Promise.all([getPlanState(account), isTextAiAvailable()]);
const isAiEnabled = Boolean(ai) && hasActiveSubscription(account);
const audioProps = await getAudioCardProps({ account, user, campaign, newsletter });
const authorControl = ["draft", "scheduled", "sent"].includes(campaign.status) ? <div className="flex flex-col gap-4"><FormIssueAuthor campaign={String(campaign._id)} selected={campaign.authorId ?? "default"} authors={[{ ...getArchiveAuthor(newsletter), id: "default" }, ...(newsletter.authors ?? [])]} /><FormReaderPreview campaign={String(campaign._id)} /><CardIssueLinks campaign={String(campaign._id)} newsletter={String(newsletter._id)} /></div> : null;
Expand Down
11 changes: 8 additions & 3 deletions app/(site)/privacy/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
TERMS_CHANGE_NOTICE,
TRANSFER_SAFEGUARDS,
getElevenLabsStatus,
getAiProvidersStatus,
TEXT_AI_DESTINATION,
isLegalPublished,
} from "@/lib/legal";
import { REGION_NAMES } from "@/lib/region";
Expand Down Expand Up @@ -122,12 +124,15 @@ export default function PrivacyPage() {
</li>
<li>
<Strong>The support assistant:</Strong> FlockStack&apos;s own assistant answers from our docs and from what you type to it. It runs
on Cloudflare Workers AI, which runs on Cloudflare&apos;s global network, so what you type may be processed outside your region.
on the text AI ({TEXT_AI_DESTINATION}), so what you type may be processed outside your region.
Stored: {SUPPORT_CHAT_STORED}. How long: {SUPPORT_CHAT_RETENTION} {SUPPORT_AI_PROVIDER_NOTE}
</li>
<li>
<Strong>The text AI providers:</Strong> {getAiProvidersStatus()} Anthropic and Groq are listed on the sub-processors page.
</li>
<li>
<Strong>The AI writing tools:</Strong> in the editor you can ask for a rewrite of the text you selected, subject lines, preview
text and drafts of social posts. They run on Cloudflare Workers AI, which runs on Cloudflare&apos;s global network, so what you
text and drafts of social posts. They run on the text AI ({TEXT_AI_DESTINATION}), so what you
send may be processed outside your region. Stored: {AI_WRITING_STORED}. How long: {AI_WRITING_RETENTION}
</li>
<li>
Expand All @@ -139,7 +144,7 @@ export default function PrivacyPage() {
</li>
<li>
<Strong>Reader-requested translations:</Strong> Stored and sent: {READER_TRANSLATIONS_STORED}. How long: {READER_TRANSLATIONS_RETENTION}.
Workers AI runs on Cloudflare&apos;s global network, so this text may be processed outside your region.
The text AI ({TEXT_AI_DESTINATION}) may process this text outside your region.
</li>
<li>
<Strong>Audio versions:</Strong> Stored and sent: {AUDIO_VERSIONS_STORED}. How long: {AUDIO_VERSIONS_RETENTION}. {getElevenLabsStatus()}
Expand Down
2 changes: 1 addition & 1 deletion components/EditorRich.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { IMAGE_TYPES, getDisplaySize, prepareImage, uploadAttachment, uploadImag
const MIN_HEIGHT = "min-h-[560px]";

// newsletterId and campaignId: where a poll made in this editor belongs. Without a newsletter, there's no poll block.
// isAiEnabled: the selection's AI menu (rewrite, shorten, tone, translate), only where the server has Workers AI.
// isAiEnabled: the selection's AI menu (rewrite, shorten, tone, translate), only where the server has a text AI.
// hasStockPhotos: the image picker also searches Unsplash, only where the server has an Unsplash key; hasGifs: and GIPHY, with a GIPHY key.
export default function EditorRich({ collaboration = null, content, onChange, fields = [], snippets = [], newsletterId = null, campaignId = null, tiers = [], isAiEnabled = false, hasStockPhotos = false, hasGifs = false }) {
const [isEditingLink, setIsEditingLink] = useState(false);
Expand Down
2 changes: 1 addition & 1 deletion components/FormReaderSettings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import { useActionState } from "react";
import { saveReaderSettings } from "@/app/(app)/reader-settings/actions";
export default function FormReaderSettings({ settings }) {
const [state, action, pending] = useActionState(saveReaderSettings, null);
return <form action={action} onSubmit={submitKeepingFields(action)} className="flex max-w-lg flex-col gap-4"><input type="hidden" name="newsletter" value={settings.newsletterId} /><label className="flex flex-col gap-2">Reader language<select className="rounded-md border bg-background p-2" name="language" defaultValue={settings.language}>{Object.entries({ en: "English", es: "Español", fr: "Français", de: "Deutsch", it: "Italiano", pt: "Português" }).map(([code, label]) => <option key={code} value={code}>{label}</option>)}</select></label><p className="text-sm text-muted-foreground">Applies to reader controls and built-in subscription messages. Your issue copy and custom emails keep their own words.</p><label className="flex flex-col gap-2">Free paid issues per month<input type="number" min="0" max="20" name="meteredReadsPerMonth" defaultValue={settings.meteredReadsPerMonth ?? 0} className="rounded-md border bg-background p-2" /></label><p className="text-sm text-muted-foreground">0 turns metered reading off. Signed-in free readers explicitly claim up to this many paid web issues each UTC calendar month. Issues restricted to a specific tier, email, audio and perks stay paid-only. Turning this off revokes the current month’s free access. Each reader’s claimed issue IDs are kept until seven days after the month ends.</p><label className="flex gap-2"><input type="checkbox" name="readerTranslations" defaultChecked={settings.readerTranslations} disabled={!settings.translationsAvailable} />Let signed-in subscribers translate issues</label><p className="text-sm text-muted-foreground">Each new translation uses one of your daily AI requests. Cached translations are kept for seven days. Only text the reader can access is sent to Cloudflare Workers AI; processing may occur outside your storage region. The original is unchanged. Issues up to 12,000 characters are supported.</p>{!settings.translationsAvailable && <p className="text-sm text-muted-foreground">Workers AI must be configured first.</p>}<label className="flex gap-2"><input type="checkbox" name="replyInbox" defaultChecked={settings.replyInbox} disabled={!settings.repliesAvailable} />Capture replies to new campaign emails</label>{!settings.repliesAvailable && <p className="text-sm text-muted-foreground">The server owner must configure the inbound domain and Email Worker first.</p>}<p className="text-sm text-muted-foreground">Replies are plain text, without attachments, kept for 90 days. Turning capture off stops accepting replies at these addresses. It never sends an automatic answer.</p>{state?.error && <p role="alert">{state.error}</p>}{state?.ok && <p role="status">Saved.</p>}<button className="rounded-md border px-3 py-2" disabled={pending}>Save</button></form>;
return <form action={action} onSubmit={submitKeepingFields(action)} className="flex max-w-lg flex-col gap-4"><input type="hidden" name="newsletter" value={settings.newsletterId} /><label className="flex flex-col gap-2">Reader language<select className="rounded-md border bg-background p-2" name="language" defaultValue={settings.language}>{Object.entries({ en: "English", es: "Español", fr: "Français", de: "Deutsch", it: "Italiano", pt: "Português" }).map(([code, label]) => <option key={code} value={code}>{label}</option>)}</select></label><p className="text-sm text-muted-foreground">Applies to reader controls and built-in subscription messages. Your issue copy and custom emails keep their own words.</p><label className="flex flex-col gap-2">Free paid issues per month<input type="number" min="0" max="20" name="meteredReadsPerMonth" defaultValue={settings.meteredReadsPerMonth ?? 0} className="rounded-md border bg-background p-2" /></label><p className="text-sm text-muted-foreground">0 turns metered reading off. Signed-in free readers explicitly claim up to this many paid web issues each UTC calendar month. Issues restricted to a specific tier, email, audio and perks stay paid-only. Turning this off revokes the current month’s free access. Each reader’s claimed issue IDs are kept until seven days after the month ends.</p><label className="flex gap-2"><input type="checkbox" name="readerTranslations" defaultChecked={settings.readerTranslations} disabled={!settings.translationsAvailable} />Let signed-in subscribers translate issues</label><p className="text-sm text-muted-foreground">Each new translation uses one of your daily AI requests. Cached translations are kept for seven days. Only text the reader can access is sent to FlockStack&apos;s text AI (Anthropic, Groq, or Cloudflare Workers AI until Anthropic and Groq may be used); processing may occur outside your storage region. The original is unchanged. Issues up to 12,000 characters are supported.</p>{!settings.translationsAvailable && <p className="text-sm text-muted-foreground">Workers AI must be configured first.</p>}<label className="flex gap-2"><input type="checkbox" name="replyInbox" defaultChecked={settings.replyInbox} disabled={!settings.repliesAvailable} />Capture replies to new campaign emails</label>{!settings.repliesAvailable && <p className="text-sm text-muted-foreground">The server owner must configure the inbound domain and Email Worker first.</p>}<p className="text-sm text-muted-foreground">Replies are plain text, without attachments, kept for 90 days. Turning capture off stops accepting replies at these addresses. It never sends an automatic answer.</p>{state?.error && <p role="alert">{state.error}</p>}{state?.ok && <p role="status">Saved.</p>}<button className="rounded-md border px-3 py-2" disabled={pending}>Save</button></form>;
}
Loading
Loading