@fave1/create-app 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -84,7 +84,7 @@ interface Ui {
84
84
  stack(children: Block[]): Block;
85
85
  }
86
86
 
87
- type Permission = 'page.text' | 'page.selection' | 'page' | 'storage' | 'pub' | 'clipboard';
87
+ type Permission = 'page.text' | 'page.selection' | 'page' | 'storage' | 'pub' | 'clipboard' | 'ai' | 'camera' | 'mic';
88
88
 
89
89
  /** `err.code` on anything `ctx` rejects with. */
90
90
  type Fave1ErrorCode =
@@ -97,6 +97,18 @@ type Fave1ErrorCode =
97
97
  | 'conflict' // shared.set() with a stale base — err.current is the row now; merge and set() again
98
98
  | 'not-found' // shared.access() · delete() on a link that isn't yours or is gone · room.direct() to a sid that isn't in the room
99
99
  | 'declined' // room.direct(): their app doesn't take direct lines (no room.on('direct') and no direct() back within 3 s)
100
+ | 'no-key' // ctx.ai: no AI key and no Fave1 credits (`err.reason` 'none' | 'credits-empty') — Fave1 already told them where to add one
101
+ | 'key-broken' // ctx.ai: their provider turned the key down — Fave1 already told them
102
+ | 'limit' // ctx.ai: this month's limit (`err.scope` 'app' | 'all', `err.resetAt`) — don't retry before then
103
+ | 'too-big' // ctx.ai: too much text for one call
104
+ | 'provider' // ctx.ai: the AI service failed (`err.reason` 'busy' | 'refused' | …, `err.retryable`)
105
+ | 'aborted' // ctx.ai: stopped — your signal, the tab went to the background, or the app closed
106
+ | 'no-voice' // ctx.ai.speak(): no way to pay for that voice — no key for its company and no Fave1 credits (Fave1 already told them)
107
+ | 'blocked' // ctx.camera · ctx.mic: this site doesn't allow a camera / microphone
108
+ | 'unavailable' // ctx.camera · ctx.mic: none here, or the page isn't https
109
+ | 'busy' // ctx.camera · ctx.mic: another tab or app is using it
110
+ | 'credits' // ctx.purchases.buy(): not enough Fave1 credits (`err.balance`, `err.needed`) — Fave1 already showed Get credits
111
+ | 'not-yet' // ctx.purchases: in-app purchases aren't open to your app yet
100
112
  | 'unreachable' | 'timeout' | 'server';
101
113
 
102
114
  /** What `ctx` rejects with — an `Error` carrying a `code`. `catch (err) { const e = err as Fave1Error; … }` */
@@ -110,9 +122,28 @@ interface Fave1Error extends Error {
110
122
  * (more on paid plans): it won't clear today, so tell them. From `files.get()`: `'read'` — 600 reads in a minute, all apps
111
123
  * together: back off, it clears within the minute.
112
124
  * An older runtime may leave it out; read `quota` as `'account'`, `rate` from `put()` as `'hour'` and from `get()` as `'read'`. */
113
- scope?: 'app' | 'account' | 'hour' | 'month' | 'read' | 'shared';
125
+ scope?: 'app' | 'account' | 'hour' | 'month' | 'read' | 'shared' | 'stickers' | 'all';
126
+ /** ctx.ai: more about why — `denied` 'undeclared' | 'off-in-settings' | 'paused' | 'not-now', `no-key` 'none' | 'credits-empty' | 'fave1-only' (your app is a voice app — it runs on Fave1 AI only), `provider` 'busy' (overloaded — try again) | 'rate' (the person's key hit its per-minute limit — wait a minute) | 'billing' (their key's account has no credit) | 'quota' (their key hit its daily or free-plan limit) | 'refused' | 'model' | 'bad' | 'json' | 'length' — Fave1 tells the person about billing and quota, so don't offer a retry for those, `invalid` 'messages' | 'image' | 'json' | 'tools'. */
127
+ reason?: string;
128
+ /** ctx.ai `limit`: when it resets (ISO time — the 1st of next month, UTC). */
129
+ resetAt?: string;
130
+ /** ctx.ai `rate`: seconds to wait. */
131
+ retryAfter?: number;
132
+ /** ctx.ai: worth trying the same call again a bit later. */
133
+ retryable?: boolean;
134
+ /** ctx.ai: which AI said no — 'anthropic' | 'openai' | 'google' | 'xai' (on `key-broken` and `provider`). `err.message` already names it in plain words. */
135
+ by?: string;
136
+ /** ctx.ai: the person can fix this themselves (replace their key, switch to Fave1 AI, get credits, raise a limit) — show `err.message` and a button that calls `ctx.ai.setup()`. */
137
+ fixable?: boolean;
138
+ /** ctx.ai: Fave1 already showed the person a card about this with their options — keep your message short and don't stack another popup. */
139
+ shown?: boolean;
114
140
  /** On `conflict` from `shared.set()`: the row as it is now (its `v` is the base to use next). */
115
141
  current?: Shared;
142
+ /** ctx.purchases `credits`: their balance (when Fave1 may tell you — at home, or on a site your app is allowed on) and the item's price. */
143
+ balance?: number;
144
+ needed?: number;
145
+ /** ctx.purchases `cancelled`: `true` when they chose Not now (rather than the panel closing). */
146
+ declined?: boolean;
116
147
  }
117
148
 
118
149
  /** One person's public value, as `pub.list()` returns it. */
@@ -306,7 +337,7 @@ interface Files {
306
337
  * A `File` keeps its own name unless `opts.name` gives one. Empty files and HTML reject with `invalid`, over 25 MB with `too-large`.
307
338
  * Uploads have two limits, all apps together: 600 an hour and 3,000 in 30 days on Free (more on paid plans); deleting a file
308
339
  * doesn't give the upload back. Past either, `rate` with `err.scope` `'hour'` or `'month'` — stop, keep your place, carry on later. */
309
- put(blob: Blob, opts?: { name?: string }): Promise<FileInfo>;
340
+ put(blob: Blob, opts?: { name?: string; onProgress?(sent: number): void }): Promise<FileInfo>;
310
341
  /** The file, or `null` if it's gone. Never throws for a missing file. A file has no link of its own — to show it, make an object
311
342
  * URL, set it as an `<img>` src, and `URL.revokeObjectURL()` it on load or error. Don't keep the URL; make a new one to draw again.
312
343
  * Get files as they come into view: past 600 reads a minute (all apps together), `rate` with `err.scope` `'read'`. */
@@ -323,6 +354,8 @@ interface Files {
323
354
  interface PageInfo {
324
355
  url: string;
325
356
  title: string;
357
+ /** The page's own language (`<html lang>`), or `null` if it doesn't say. Always there — no permission needed. `null` at home. */
358
+ lang: string | null;
326
359
  /** All visible text — only when `page.text` is declared. The `page` permission doesn't fill it; read `document.body.innerText`. */
327
360
  text?: string;
328
361
  /** What's highlighted — or, if nothing is now, what was highlighted when they opened Fave1 (`page.selection` or `page`). */
@@ -408,11 +441,305 @@ interface SharedApi {
408
441
  delete(idOrRef: string): Promise<void>;
409
442
  }
410
443
 
444
+ /** A sticker your app gave this person, as `stickers.give()` and `stickers.list()` return it. */
445
+ interface StickerInfo {
446
+ /** Your id for it — the same `id` you gave. */
447
+ id: string;
448
+ /** What people see under it in My Fave1. */
449
+ name: string;
450
+ /** The picture's file id — it's one of your `files` too (`files.list()` shows it as `Sticker · <name>`). Deleting that file takes the sticker back. */
451
+ file: string;
452
+ /** ISO times it was first given and last changed. */
453
+ createdAt: string;
454
+ updatedAt: string;
455
+ }
456
+
457
+ /** `stickers` — give this person a sticker for their My Fave1 home: a trophy, a badge, their cat. It lands in Decorate › Stickers ›
458
+ * From your apps with your app's icon on it; they choose where it goes. Declared with `storage` (no new permission) — same rules as `files`:
459
+ * needs a signed-in person, asks once on a new site, never at home; a DEV build keeps them in this browser. The picture is one of your files,
460
+ * so it counts toward their Fave1 storage. **Give it when they earned something** — a level, a win, a streak — not on every visit. */
461
+ interface StickersApi {
462
+ /** Give a sticker. `image` is a Blob, a canvas or an ImageBitmap — Fave1 fits it in 512 × 512 and keeps it transparent (a PNG with
463
+ * see-through edges looks best). Giving the same `id` again swaps the picture and name and keeps it where they stuck it.
464
+ * `id` is up to 32 lowercase letters, digits and dashes; `name` 1 to 40 characters (`invalid` otherwise). Up to 24 stickers per person
465
+ * from your app — past that, `quota` with `err.scope` `'stickers'`. A canvas with another site's picture drawn on it can't be read (`invalid`). */
466
+ give(sticker: { id: string; name: string; image: Blob | HTMLCanvasElement | ImageBitmap }): Promise<StickerInfo>;
467
+ /** What your app gave this person, newest first. */
468
+ list(): Promise<StickerInfo[]>;
469
+ /** Take one back — it comes off their home too. Resolves even if it was already gone. */
470
+ delete(id: string): Promise<void>;
471
+ /** Open My Fave1's Decorate › Stickers in a new tab — where they stick what you gave. */
472
+ open(): void;
473
+ }
474
+
475
+ /** `ctx.ai` — ask an AI model on this person's own key (Claude · OpenAI · Gemini · Grok) or their Fave1 credits.
476
+ * **You never see the key, and you never pay.** Fave1 holds it on its server, calls the model for you and hands back only
477
+ * the answer. The first call asks the person ("Let <your app> use your AI key?"); after that each call goes straight
478
+ * through until their monthly limit for your app. Declare `"ai"` in manifest.json.
479
+ * Beyond text: pictures (`{ type: 'image', image }`), answers in a shape you choose (`json` → `data`) and tools the model can
480
+ * call (`tools` → `calls`, or let `ctx.ai.run()` call them for you until it's done). */
481
+ /** A slice of JSON Schema — `type` (one, or one plus `'null'`), `properties`, `required`, `items`, `enum`, `description`, and the
482
+ * checks `minimum` · `maximum` · `minLength` · `maxLength` · `minItems` · `maxItems`. Up to 6 levels deep. Objects never get extra keys. */
483
+ interface AiSchema {
484
+ type: 'object' | 'array' | 'string' | 'number' | 'integer' | 'boolean' | ['object' | 'array' | 'string' | 'number' | 'integer' | 'boolean', 'null'];
485
+ description?: string;
486
+ properties?: Record<string, AiSchema>;
487
+ required?: string[];
488
+ items?: AiSchema;
489
+ enum?: (string | number | boolean | null)[];
490
+ minimum?: number; maximum?: number; minLength?: number; maxLength?: number; minItems?: number; maxItems?: number;
491
+ }
492
+ type AiPart =
493
+ | { type: 'text'; text: string }
494
+ /** A picture — a Blob, an <img>, a canvas, an ImageBitmap, ImageData or an image URL. Fave1 shrinks it (1,568px on the long side)
495
+ * and sends a JPEG. Up to 8 per call. Pictures from other sites are fetched without cookies, like `ctx.page.fetchImage`. */
496
+ | { type: 'image'; image: Blob | HTMLImageElement | HTMLCanvasElement | ImageBitmap | ImageData | string }
497
+ /** In an `assistant` turn — a tool the model called. You get these in `result.message`; keep them as they are. */
498
+ | { type: 'tool-call'; id: string; name: string; input: Record<string, unknown> }
499
+ /** In a `user` turn — your answer to a tool call (same `id`). Anything not a string is sent as JSON. `error: true` says it failed.
500
+ * `images` — pictures the tool hands back (a crop of the page, a chart it drew), same kinds as an image part; they count toward the 8 per call. */
501
+ | { type: 'tool-result'; id: string; content: unknown; error?: boolean; images?: (Blob | HTMLImageElement | HTMLCanvasElement | ImageBitmap | ImageData | string)[] }
502
+ /** In an `assistant` turn — what the model needs back next time (its reasoning, sealed). Opaque — keep it exactly as `result.message` gave it. */
503
+ | { type: 'state'; state: string };
504
+ /** A plain string is shorthand for one text part. */
505
+ interface AiMessage { role: 'user' | 'assistant'; content: string | (AiPart | string)[] }
506
+ interface AiTool {
507
+ /** Letters, digits, `_` and `-`, up to 64 — unique in the call. */
508
+ name: string;
509
+ /** When to call it — the model reads this to decide. */
510
+ description: string;
511
+ /** What it takes — an object schema. */
512
+ input: AiSchema;
513
+ }
514
+ interface AiOptions {
515
+ /** One string is one user turn. Otherwise turns alternate, first and last are `'user'`. Up to 100 turns, 120,000 characters with `system`. */
516
+ messages: string | AiMessage[];
517
+ /** Instructions for the model — up to 20,000 characters. */
518
+ system?: string;
519
+ /** `'fast'` (default) — quick and cheap, right for most features. `'smart'` — slower, for harder thinking. Fave1 picks the
520
+ * model on whichever provider the person uses; you don't name one. */
521
+ model?: 'fast' | 'smart';
522
+ /** Cap on the answer's length in tokens — 1 to 4,096 (default 1,024). Lower is cheaper for them. */
523
+ maxTokens?: number;
524
+ /** Answer in this shape — `result.data` is the parsed value, already checked against the schema. */
525
+ json?: AiSchema;
526
+ /** Tools the model may call — up to 32. With `chat()` you get `result.calls` and run them yourself; `run()` does it for you. */
527
+ tools?: AiTool[];
528
+ /** You'll ask again with the same start (a chat that keeps going, the same long `system`) — the next call reads that start from the
529
+ * provider's cache for a fraction of the price. Costs a little more on a call nobody follows up, so leave it off for one-off questions.
530
+ * `run()` turns it on for you. `result.usage.cached` shows what came from the cache. */
531
+ cache?: boolean;
532
+ /** Which of their AIs answers — an `id` from `ctx.ai.choices()`. Leave it out for the AI they picked in Fave1 Settings.
533
+ * Use another one only when the person picks it in your UI: it goes on a different bill. Same monthly limit either way.
534
+ * The first time, Fave1 asks them once if your app may ask their other AIs. Don't carry `state` parts from one AI to another. */
535
+ ai?: string;
536
+ /** Stop the call — the promise rejects with `aborted`, and nothing more is charged. */
537
+ signal?: AbortSignal;
538
+ }
539
+ interface AiToolCall { id: string; name: string; input: Record<string, unknown> }
540
+ interface AiResult {
541
+ text: string;
542
+ /** With `json` — the answer as a value, checked against your schema (a mismatch rejects with `provider`, `err.reason` `'json'`). */
543
+ data?: unknown;
544
+ /** Tools the model called this turn (empty when it just answered). */
545
+ calls: AiToolCall[];
546
+ /** `'done'` — it answered · `'tool'` — it wants tool results (see `calls`) · `'length'` — it hit `maxTokens`. */
547
+ stop: 'done' | 'tool' | 'length';
548
+ /** This turn as an `assistant` message — push it onto `messages` to keep the conversation going (tool calls and state included). */
549
+ message: AiMessage;
550
+ /** Tokens — `cached` is the part of `input` read from the provider's cache (cheaper). */
551
+ usage: { input: number; output: number; cached: number };
552
+ /** `'anthropic' | 'openai' | 'google' | 'xai'`, or `'mock'` in a DEV build without a key. */
553
+ provider: string;
554
+ model: string;
555
+ /** True for the stand-in answer a DEV build gets when you have no key or credits — the whole flow runs, nothing is charged.
556
+ * With `tools` it calls your first tool once; with `json` it returns the smallest value that fits. */
557
+ mock: boolean;
558
+ }
559
+ interface AiStream extends AsyncIterable<{ text: string }> {
560
+ /** The whole answer once the stream has ended (`null` before that). */
561
+ result(): AiResult | null;
562
+ }
563
+ interface AiRunTool extends AiTool {
564
+ /** Does it — gets the model's input (already checked against `input`) and returns anything; throw to report a failure to the model.
565
+ * Return a picture (Blob, <img>, canvas, ImageBitmap, ImageData) — or an array of strings and pictures — and the model gets to look at it. */
566
+ run(input: any, info: { id: string; signal?: AbortSignal }): unknown | Promise<unknown>;
567
+ }
568
+ interface AiRunOptions extends Omit<AiOptions, 'tools'> {
569
+ tools: AiRunTool[];
570
+ /** On by default here — every step resends the conversation so far. `false` turns it off. */
571
+ cache?: boolean;
572
+ /** Calls to the model at most — 1 to 10 (default 6). Each step is one call and counts against their limit. */
573
+ maxSteps?: number;
574
+ /** After each round of tool calls. */
575
+ onStep?(step: { step: number; calls: AiToolCall[]; results: AiPart[]; text: string }): void;
576
+ }
577
+ interface AiRunResult extends AiResult {
578
+ /** How many calls it took. */
579
+ steps: number;
580
+ /** The whole conversation, ending with the model's last turn — pass it back as `messages` to ask a follow-up. */
581
+ messages: AiMessage[];
582
+ }
583
+ /** What `ctx.ai.status()` resolves — check it to fold or explain the feature before anyone presses a button.
584
+ * `ready` · `ask` (the first call will ask) · `no-key` · `key-broken` · `off` (they said Not now, turned it off, or AI is
585
+ * paused for your app) · `limit` (this month's limit is reached) · `signed-out` · `not-installed`. */
586
+ type AiStatus = 'ready' | 'ask' | 'no-key' | 'key-broken' | 'off' | 'limit' | 'signed-out' | 'not-installed';
587
+ /** What `ctx.ai.usage()` resolves — this person's spending on your app this month (UTC), in US dollars. */
588
+ interface AiUsage {
589
+ /** Spent on your app so far this month. */
590
+ spent: number;
591
+ /** Their limit for your app, or `null` for no limit. */
592
+ limit: number | null;
593
+ /** What your app can still spend this month — the smallest of your app's limit, their overall limit and their Fave1 credits.
594
+ * `null` when nothing limits it. */
595
+ left: number | null;
596
+ /** Calls to the model this month. */
597
+ requests: number;
598
+ /** When it starts over (ISO time — the 1st of next month, UTC). */
599
+ resetAt: string | null;
600
+ /** True in a DEV build without a key — the numbers are zero. */
601
+ mock: boolean;
602
+ }
603
+ interface Ai {
604
+ /** One answer. A string is shorthand for one user message: `ctx.ai.chat('Say hi')`.
605
+ * Rejects with a `Fave1Error` — codes in `Fave1ErrorCode`; `err.message` is a sentence you can show as is. */
606
+ chat(options: AiOptions | string): Promise<AiResult>;
607
+ /** The same call, piece by piece: `for await (const part of ctx.ai.stream({ … })) out.textContent += part.text`. */
608
+ stream(options: AiOptions | string): AiStream;
609
+ /** A conversation with tools, start to finish — when the model calls a tool, Fave1 runs yours, sends the result back and asks
610
+ * again, until it answers (or `maxSteps`). Input that doesn't fit a tool's schema goes back to the model as an error, not to `run`. */
611
+ run(options: AiRunOptions): Promise<AiRunResult>;
612
+ status(): Promise<AiStatus>;
613
+ /** Opens what fixes the current state — the one-time OK, or Fave1 Settings › AI (add a key, raise the limit, turn it back on).
614
+ * Resolves `true` when AI is ready now. Only the person can turn it on. */
615
+ setup(): Promise<boolean>;
616
+ /** How much this person has spent on your app this month and how much is left — show it, or go easy as it runs low.
617
+ * `null` where AI can't be used right now (check `status()` for why). Only your app's numbers — never their other apps'. */
618
+ usage(): Promise<AiUsage | null>;
619
+ /** The AIs this person can answer with right now. `current` is the one they picked in Fave1 Settings (what a plain `chat()` uses);
620
+ * `others` are their other keys and Fave1 AI — pass an `id` as `ai` to ask that one. `locked` means they have others but haven't
621
+ * let your app use them yet: `choices({ ask: true })` shows Fave1's one-time OK and resolves with the list (unchanged if they say no).
622
+ * Where AI can't be used right now, `current` is `null`. In the sandbox you get two mock AIs to build with. */
623
+ choices(options?: { ask?: boolean }): Promise<AiChoices>;
624
+ /** Text to a voice. Pick a voice from `voices()` and that voice's company speaks it: on the person's own key for that company if they
625
+ * added one, otherwise on their Fave1 credits — so it works for people on Claude or Fave1 AI too. Same Allow, limit and rules as
626
+ * `chat()`. Up to 1,200 characters; speak a song or a story line by line. A string is the text: `ctx.ai.speak('Hey you')`. */
627
+ speak(text: string | AiSpeakOptions, options?: Omit<AiSpeakOptions, 'text'>): Promise<AiSpeech>;
628
+ /** The eighteen voices — six tones each from OpenAI, Gemini and Grok — and whether each can speak for this person right now.
629
+ * Show them, let the person pick, pass the `id` to `speak()`. Where AI can't be used yet every voice is `ready: false`;
630
+ * call `speak()` anyway and Fave1 asks the person. In the sandbox they're all ready. */
631
+ voices(): Promise<AiVoice[]>;
632
+ }
633
+ /** A feel, when you don't care which company speaks: Fave1 picks one the person can pay for. */
634
+ type AiVoiceTone = 'bright' | 'warm' | 'deep' | 'calm' | 'bold' | 'smooth';
635
+ interface AiVoice {
636
+ /** Pass this to `speak({ voice })` — `nova`, `fenrir`, `rex`… */
637
+ id: string;
638
+ /** Its name, for your picker. */
639
+ name: string;
640
+ /** Who makes it — `OpenAI` · `Gemini` · `Grok`. */
641
+ by: string;
642
+ tone: AiVoiceTone;
643
+ /** Would speak right now. */
644
+ ready: boolean;
645
+ /** Who pays: `key` — their own key for that company (the company bills them) · `credits` — their Fave1 credits · `null` — not ready. */
646
+ pays: 'key' | 'credits' | null;
647
+ /** On credits: about how many Fave1 credits 1,000 characters cost. `null` on their own key. */
648
+ credits: number | null;
649
+ }
650
+ interface AiSpeakOptions {
651
+ text: string;
652
+ /** A voice `id` from `voices()`, or a tone (`'bold'`) to let Fave1 pick the company. Default `'bright'`. */
653
+ voice?: string;
654
+ /** How to say it, up to 300 characters — "rap it on the beat, hype". Never a real person's voice. */
655
+ style?: string;
656
+ /** 0.5 – 2, default 1. */
657
+ speed?: number;
658
+ /** With a tone: which company to use — `openai` · `google` · `xai`. A voice `id` already names its company. */
659
+ ai?: string;
660
+ signal?: AbortSignal;
661
+ }
662
+ interface AiSpeech {
663
+ audio: Blob;
664
+ type: 'audio/mpeg' | 'audio/wav';
665
+ /** About how long it runs — decode the audio for the exact length. */
666
+ seconds: number;
667
+ /** The voice `id` that spoke — when you passed a tone, the one Fave1 picked. */
668
+ voice: string;
669
+ /** Which company spoke it — `openai` · `google` · `xai`, `mock` in the sandbox. */
670
+ provider: string | null;
671
+ /** Who paid — their own `key`, or their Fave1 `credits`. `null` in the sandbox. */
672
+ paid: 'key' | 'credits' | null;
673
+ /** True in the sandbox — a short tone the length of your text. */
674
+ mock: boolean;
675
+ }
676
+ /** `ctx.camera.open()` — a camera that's on. */
677
+ interface CameraFeed {
678
+ /** Already playing and muted (`playsinline`) — put it in your panel or draw it on a canvas each frame. */
679
+ video: HTMLVideoElement;
680
+ stream: MediaStream;
681
+ facing: 'user' | 'environment';
682
+ stop(): void;
683
+ }
684
+ interface Camera {
685
+ /** Turns their camera on — Fave1 asks first (once each time your app opens), then the browser asks for that site. Video only.
686
+ * Rejects `denied` · `blocked` · `unavailable` · `busy`. Call it from a tap, not at launch. */
687
+ open(options?: { facing?: 'user' | 'environment'; width?: number; height?: number }): Promise<CameraFeed>;
688
+ /** Every camera your app opened goes off. Closing your app does this too. */
689
+ close(): void;
690
+ readonly active: boolean;
691
+ }
692
+ /** `ctx.mic.open()` — a microphone that's on. */
693
+ interface MicFeed {
694
+ /** One audio track, no video — for `MediaRecorder` or `AudioContext.createMediaStreamSource`. Nothing plays through the speakers unless you do it. */
695
+ stream: MediaStream;
696
+ track: MediaStreamTrack | null;
697
+ /** What the browser actually applied. */
698
+ echo: boolean; noise: boolean; gain: boolean;
699
+ /** Input delay the device reports, in seconds — 0 when it doesn't say. */
700
+ latency: number;
701
+ stop(): void;
702
+ }
703
+ interface Mic {
704
+ /** Turns their microphone on — Fave1 asks first (once each time your app opens), then the browser asks for that site. Sound only.
705
+ * `echo` · `noise` · `gain` (all default true) are the browser's echo cancelling, noise suppression and automatic level — turn them off for
706
+ * someone on earphones. Rejects `denied` · `blocked` · `unavailable` · `busy`. Call it from a tap, not at launch. */
707
+ open(options?: { echo?: boolean; noise?: boolean; gain?: boolean }): Promise<MicFeed>;
708
+ /** Every microphone your app opened goes off. Closing your app does this too. */
709
+ close(): void;
710
+ readonly active: boolean;
711
+ }
712
+ /** One of the person's AIs. `id` is stable (`anthropic` · `openai` · `google` · `xai` · `fave1` · `mock`); `name` is what to show ("Claude", "Fave1 AI"). */
713
+ interface AiChoice { id: string; name: string }
714
+ interface AiChoices { current: AiChoice | null; others: AiChoice[]; locked: boolean }
715
+
716
+ /** One thing your app sells, as Fave1 keeps it — you name the `id`; the name, amount and price are on Fave1's side. */
717
+ interface PurchaseItem { id: string; name: string; qty: number; credits: number }
718
+ /** What `buy()` and `pending()` give back. `id` is the receipt — write it next to the thing you deliver. */
719
+ interface PurchaseReceipt { id: string; item: string; name: string; qty: number; credits: number }
720
+ interface Purchases {
721
+ /** Your items, in your order, and their credit balance — `null` when signed out, or on a site your app isn't allowed on yet. */
722
+ items(): Promise<{ items: PurchaseItem[]; balance: number | null }>;
723
+ /** Shows Fave1's confirm line — the Buy button is Fave1's, with Fave1's price on it. Resolves with a receipt once the credits
724
+ * are taken. Put the thing in your storage **with the receipt id in the same write**, then `finish()`. */
725
+ buy(item: string): Promise<PurchaseReceipt>;
726
+ /** Commits a receipt after you delivered. `'returned'` — 7 days passed without `finish()`, Fave1 already gave the credits back. */
727
+ finish(receipt: string): Promise<'done' | 'returned'>;
728
+ /** Receipts paid for but not finished — call on open, deliver what your storage doesn't show yet, then `finish()`. */
729
+ pending(): Promise<PurchaseReceipt[]>;
730
+ }
731
+
411
732
  interface Ctx {
412
733
  ui: Ui;
413
734
  /** Where you're running: `'page'` — on someone's site, opened from the bookmarklet;
414
735
  * `'app'` — at your own `<id>.fave1.app`, opened from My Fave1. Same bundle, split screens. */
415
736
  surface: 'page' | 'app';
737
+ /** The language this person uses — `'en'`, `'ko'`, `'pt-BR'`… (what they picked in Fave1 Settings, else their browser's).
738
+ * Not the page's language — that's `page.lang`. */
739
+ readonly locale: string;
740
+ /** Your app's text in their language, from `locales/<language>.json` (shipped by `npm run submit`). `{name}` fills from `vars`;
741
+ * pass `{ count }` to pick `key_one` · `key_other` …. Falls back to their base language, then `en.json`, then the key itself. */
742
+ t(key: string, vars?: Record<string, string | number>): string;
416
743
  /** `storage` — private JSON on this person's Fave1 account, per key. Nobody else reads it — not other apps, not other people,
417
744
  * not you. Values up to 64 KB (`too-large`); 1 MB per app on Free, 10 MB on paid plans (`usage()` tells you theirs) —
418
745
  * design for 1 MB; every app's data together up to 25 MB on Free (250 MB on paid plans); and it all counts toward their Fave1
@@ -435,6 +762,21 @@ interface Ctx {
435
762
  * don't hard-code). Files don't count here: they go to their Fave1 storage (`quota` with `scope: 'account'`, `files.manage()`).
436
763
  * Same rules as `list()`: needs a signed-in person, asks once on a new site, never at home. A DEV build's sandbox reports itself and 1 MB. */
437
764
  usage(): Promise<{ bytes: number; limit: number }>;
765
+ /** Add one item to the end of the list at `key` — for a history or a log you fill from many sites. The list holds
766
+ * `{ at, site, item }` rows: `at` is the server's time (ISO), `site` the host of the page it was added on (set by Fave1 —
767
+ * your code can't change it), `null` at home. Read it with `get(key)`; trim or edit it with `set` · `delete` like any value.
768
+ * An item is JSON up to 4 KB (`too-large`); when the list passes 64 KB the oldest rows drop off. If `key` already holds
769
+ * something that isn't a list, `invalid`. Because it only adds and can't read, it asks once for your app — not once per
770
+ * site: "Keep your <what> in <app>?" (`opts.what`, a few words, default `history`). `cancelled` if they say not now.
771
+ * Never asks at home. */
772
+ append(key: string, item: unknown, opts?: { what?: string }): Promise<void>;
773
+ /** Forget the once-for-every-site OK that `append()` asked for — the next `append()` on a site asks again (call it when
774
+ * someone turns your history off). Keeps the data. */
775
+ forgetAppend(): Promise<void>;
776
+ /** Ask for that OK now, while they're looking — when your panel opens, not the moment they click something that opens
777
+ * another window (the question would land behind it). `true` if it's already given (or at home), or they say yes; `false`
778
+ * if they say not now. Rejects `cancelled` if your panel closed before they answered. */
779
+ askAppend(opts?: { what?: string }): Promise<boolean>;
438
780
  /** One small settings object for this app — a pen color, a switch, the last tab. **No one-time OK, ever**: it opens on any
439
781
  * site, even one that never said yes, so your app can open with the person's own settings everywhere. The price is that any
440
782
  * page your app opens on can read and change it — **never put anything private here.** Up to 2 KB as JSON (`too-large`),
@@ -449,11 +791,18 @@ interface Ctx {
449
791
  };
450
792
  /** Files on the account — declared with `storage`, like the JSON above. */
451
793
  files: Files;
794
+ /** Stickers you give for their My Fave1 home — declared with `storage` too. */
795
+ stickers: StickersApi;
452
796
  /** Values shared by link — declared with `storage` too. */
453
797
  shared: SharedApi;
454
798
  pub: Pub;
455
799
  /** Live rooms — the same table, edited by several people at once (uses `pub`). */
456
800
  live: Live;
801
+ /** AI on the person's own key or Fave1 credits — declared with `ai`. */
802
+ ai: Ai;
803
+ /** In-app purchases paid with Fave1 credits — declared with `storage`. **Not open to your app yet**: every call rejects with
804
+ * `not-yet` until Fave1 opens it (see /docs/ctx-purchases). */
805
+ purchases: Purchases;
457
806
  /** Is this permission live right now? `pub` also needs a signed-in person who hasn't switched it off. */
458
807
  can(permission: Permission): boolean;
459
808
  /** Opens this app's permission screen in Fave1 settings. Only the person can turn things on. */
@@ -467,6 +816,10 @@ interface Ctx {
467
816
  * tap (the browser counts a tap for a few seconds) copies at once — the tap was the yes; later it asks first.
468
817
  * Resolves `true` once it's copied, `false` if they say no. */
469
818
  clipboard: { read(): Promise<string | null>; write(text: string): Promise<boolean> };
819
+ /** Their camera, live, while your app is open — `camera` permission. The video stays on their page. */
820
+ camera: Camera;
821
+ /** Their microphone, live, while your app is open — `mic` permission, separate from the camera. The sound stays on their page. */
822
+ mic: Mic;
470
823
  /** Your app's settings, edited in the developer console (Config tab) and loaded before `onLaunch` — a plain JSON object.
471
824
  * It ships without review, so it holds **values, not code** and nothing secret: every person who opens the app receives it.
472
825
  * While you build, `fave1 dev` serves the `config.json` next to your manifest. Missing or unreachable → `{}`. */
@@ -482,6 +835,10 @@ interface Ctx {
482
835
  * With Data set to "My account" in the DEV panel both work as they will live — the id belongs to your DEV slot. */
483
836
  user: {
484
837
  readonly signedIn: boolean;
838
+ /** Fave1 Plus — 'plus' (they have Plus or Ultra) · 'free' (they don't). Signed out is 'free'. */
839
+ readonly plus?: 'plus' | 'free';
840
+ /** Their plan by name — 'free' · 'basic' · 'plus' · 'ultra'. Null when signed out or not known yet (await load()). Use plus to open ✦ extras; use tier only for something one plan gets, like an Ultra extra. */
841
+ readonly tier?: 'free' | 'basic' | 'plus' | 'ultra' | null;
485
842
  readonly id?: string;
486
843
  readonly granted?: boolean;
487
844
  load(): Promise<{ readonly signedIn: boolean; readonly id?: string; readonly granted?: boolean }>;