Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

feat(funnel): der Cloud-Schalter wird auch pro Konto gezaehlt

Davidef2701a107a7
diff --git a/src/api/__tests__/funnel.test.ts b/src/api/__tests__/funnel.test.ts
index 6a10b239..25f64fa7 100644
--- a/src/api/__tests__/funnel.test.ts
+++ b/src/api/__tests__/funnel.test.ts
@@ -11,12 +11,18 @@ const backendCall = vi.fn()
vi.mock('../backend', () => ({
backendCall: (...a: unknown[]) => backendCall(...a),
}))
+const cloudFetch = vi.fn()
+vi.mock('../cloud/client', () => ({
+ cloudFetch: (...a: unknown[]) => cloudFetch(...a),
+}))
import { funnelEventFor, reportCloudSwitch } from '../funnel'
beforeEach(() => {
backendCall.mockReset()
backendCall.mockResolvedValue(undefined)
+ cloudFetch.mockReset()
+ cloudFetch.mockResolvedValue(new Response(null, { status: 204 }))
})
describe('the Cloud switch counter', () => {
@@ -33,6 +39,24 @@ describe('the Cloud switch counter', () => {
expect(backendCall).toHaveBeenCalledWith('funnel_ping', { event: 'cloud_switch_enter' })
})
+ it('reports the same press once more per account, with the bearer path', () => {
+ reportCloudSwitch('open-gate')
+ expect(cloudFetch).toHaveBeenCalledTimes(1)
+ const [path, init] = cloudFetch.mock.calls[0] as [string, RequestInit]
+ expect(path).toBe('/api/funnel/switch')
+ expect(init.method).toBe('POST')
+ expect(JSON.parse(String(init.body))).toEqual({ event: 'cloud_switch_gate' })
+ })
+
+ it('stays anonymous when there is no session and never throws on a dead network', async () => {
+ cloudFetch.mockImplementation(() => { throw new Error('no session') })
+ expect(() => reportCloudSwitch('arm')).not.toThrow()
+ cloudFetch.mockRejectedValue(new Error('offline'))
+ expect(() => reportCloudSwitch('enter-cloud')).not.toThrow()
+ await new Promise((r) => setTimeout(r, 0))
+ expect(backendCall).toHaveBeenCalledTimes(2)
+ })
+
it('never lets a failing bridge reach the switch', async () => {
backendCall.mockRejectedValue(new Error('offline'))
expect(() => reportCloudSwitch('arm')).not.toThrow()
diff --git a/src/api/funnel.ts b/src/api/funnel.ts
index 388d7c44..dc2ecd92 100644
--- a/src/api/funnel.ts
+++ b/src/api/funnel.ts
@@ -10,6 +10,7 @@
* is down all cost the press nothing.
*/
import { backendCall } from './backend'
+import { cloudFetch } from './cloud/client'
import type { CloudSwitchAction } from '../lib/cloud-switch-guard'
export type FunnelEvent =
@@ -28,9 +29,31 @@ export function funnelEventFor(action: CloudSwitchAction): FunnelEvent {
}
export function reportCloudSwitch(action: CloudSwitchAction): void {
+ const event = funnelEventFor(action)
try {
- void backendCall('funnel_ping', { event: funnelEventFor(action) }).catch(() => {})
+ void backendCall('funnel_ping', { event }).catch(() => {})
} catch {
/* no bridge (web build): the press is simply not counted */
}
+ reportCloudSwitchForAccount(event)
+}
+
+/**
+ * The same press once more, per account (David, 2026-09-07: split the
+ * presses into subscribers and the rest, and see how often one person
+ * presses). Signed in only: cloudFetch has no token for a signed-out
+ * session and throws, and that press stays anonymous by design. Fire and
+ * forget like the anonymous counter; a dead network costs the press nothing.
+ */
+export function reportCloudSwitchForAccount(event: FunnelEvent): void {
+ try {
+ void cloudFetch('/api/funnel/switch', {
+ method: 'POST',
+ headers: { 'content-type': 'application/json' },
+ body: JSON.stringify({ event }),
+ timeoutMs: 5_000,
+ }).catch(() => {})
+ } catch {
+ /* nothing to count without a session */
+ }
}