@fave1/create-app 0.1.1 → 0.1.3
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.
- package/dist/reserved-ids.js +1 -1
- package/package.json +1 -1
- package/templates/break/README.md +13 -4
- package/templates/break/locales/en.json +10 -0
- package/templates/break/src/index.ts +6 -6
- package/templates/break/types/fave1.d.ts +331 -2
- package/templates/minimal/README.md +13 -4
- package/templates/minimal/locales/en.json +3 -0
- package/templates/minimal/src/index.ts +2 -1
- package/templates/minimal/types/fave1.d.ts +331 -2
- package/templates/panel/README.md +13 -4
- package/templates/panel/locales/en.json +6 -0
- package/templates/panel/src/index.ts +4 -3
- package/templates/panel/types/fave1.d.ts +331 -2
- package/templates/storage/README.md +13 -4
- package/templates/storage/locales/en.json +11 -0
- package/templates/storage/src/index.ts +9 -9
- package/templates/storage/types/fave1.d.ts +331 -2
|
@@ -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';
|
|
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: this site doesn't allow a camera
|
|
108
|
+
| 'unavailable' // ctx.camera: no camera here, or the page isn't https
|
|
109
|
+
| 'busy' // ctx.camera: 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,22 @@ 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', `provider` 'busy' | 'refused' | 'billing' | 'model' | 'bad' | 'json' | 'length', `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;
|
|
114
134
|
/** On `conflict` from `shared.set()`: the row as it is now (its `v` is the base to use next). */
|
|
115
135
|
current?: Shared;
|
|
136
|
+
/** 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. */
|
|
137
|
+
balance?: number;
|
|
138
|
+
needed?: number;
|
|
139
|
+
/** ctx.purchases `cancelled`: `true` when they chose Not now (rather than the panel closing). */
|
|
140
|
+
declined?: boolean;
|
|
116
141
|
}
|
|
117
142
|
|
|
118
143
|
/** One person's public value, as `pub.list()` returns it. */
|
|
@@ -323,6 +348,8 @@ interface Files {
|
|
|
323
348
|
interface PageInfo {
|
|
324
349
|
url: string;
|
|
325
350
|
title: string;
|
|
351
|
+
/** The page's own language (`<html lang>`), or `null` if it doesn't say. Always there — no permission needed. `null` at home. */
|
|
352
|
+
lang: string | null;
|
|
326
353
|
/** All visible text — only when `page.text` is declared. The `page` permission doesn't fill it; read `document.body.innerText`. */
|
|
327
354
|
text?: string;
|
|
328
355
|
/** What's highlighted — or, if nothing is now, what was highlighted when they opened Fave1 (`page.selection` or `page`). */
|
|
@@ -408,11 +435,285 @@ interface SharedApi {
|
|
|
408
435
|
delete(idOrRef: string): Promise<void>;
|
|
409
436
|
}
|
|
410
437
|
|
|
438
|
+
/** A sticker your app gave this person, as `stickers.give()` and `stickers.list()` return it. */
|
|
439
|
+
interface StickerInfo {
|
|
440
|
+
/** Your id for it — the same `id` you gave. */
|
|
441
|
+
id: string;
|
|
442
|
+
/** What people see under it in My Fave1. */
|
|
443
|
+
name: string;
|
|
444
|
+
/** 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. */
|
|
445
|
+
file: string;
|
|
446
|
+
/** ISO times it was first given and last changed. */
|
|
447
|
+
createdAt: string;
|
|
448
|
+
updatedAt: string;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/** `stickers` — give this person a sticker for their My Fave1 home: a trophy, a badge, their cat. It lands in Decorate › Stickers ›
|
|
452
|
+
* 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`:
|
|
453
|
+
* 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,
|
|
454
|
+
* so it counts toward their Fave1 storage. **Give it when they earned something** — a level, a win, a streak — not on every visit. */
|
|
455
|
+
interface StickersApi {
|
|
456
|
+
/** 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
|
|
457
|
+
* see-through edges looks best). Giving the same `id` again swaps the picture and name and keeps it where they stuck it.
|
|
458
|
+
* `id` is up to 32 lowercase letters, digits and dashes; `name` 1 to 40 characters (`invalid` otherwise). Up to 24 stickers per person
|
|
459
|
+
* 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`). */
|
|
460
|
+
give(sticker: { id: string; name: string; image: Blob | HTMLCanvasElement | ImageBitmap }): Promise<StickerInfo>;
|
|
461
|
+
/** What your app gave this person, newest first. */
|
|
462
|
+
list(): Promise<StickerInfo[]>;
|
|
463
|
+
/** Take one back — it comes off their home too. Resolves even if it was already gone. */
|
|
464
|
+
delete(id: string): Promise<void>;
|
|
465
|
+
/** Open My Fave1's Decorate › Stickers in a new tab — where they stick what you gave. */
|
|
466
|
+
open(): void;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/** `ctx.ai` — ask an AI model on this person's own key (Claude · OpenAI · Gemini · Grok) or their Fave1 credits.
|
|
470
|
+
* **You never see the key, and you never pay.** Fave1 holds it on its server, calls the model for you and hands back only
|
|
471
|
+
* the answer. The first call asks the person ("Let <your app> use your AI key?"); after that each call goes straight
|
|
472
|
+
* through until their monthly limit for your app. Declare `"ai"` in manifest.json.
|
|
473
|
+
* Beyond text: pictures (`{ type: 'image', image }`), answers in a shape you choose (`json` → `data`) and tools the model can
|
|
474
|
+
* call (`tools` → `calls`, or let `ctx.ai.run()` call them for you until it's done). */
|
|
475
|
+
/** A slice of JSON Schema — `type` (one, or one plus `'null'`), `properties`, `required`, `items`, `enum`, `description`, and the
|
|
476
|
+
* checks `minimum` · `maximum` · `minLength` · `maxLength` · `minItems` · `maxItems`. Up to 6 levels deep. Objects never get extra keys. */
|
|
477
|
+
interface AiSchema {
|
|
478
|
+
type: 'object' | 'array' | 'string' | 'number' | 'integer' | 'boolean' | ['object' | 'array' | 'string' | 'number' | 'integer' | 'boolean', 'null'];
|
|
479
|
+
description?: string;
|
|
480
|
+
properties?: Record<string, AiSchema>;
|
|
481
|
+
required?: string[];
|
|
482
|
+
items?: AiSchema;
|
|
483
|
+
enum?: (string | number | boolean | null)[];
|
|
484
|
+
minimum?: number; maximum?: number; minLength?: number; maxLength?: number; minItems?: number; maxItems?: number;
|
|
485
|
+
}
|
|
486
|
+
type AiPart =
|
|
487
|
+
| { type: 'text'; text: string }
|
|
488
|
+
/** A picture — a Blob, an <img>, a canvas, an ImageBitmap, ImageData or an image URL. Fave1 shrinks it (1,568px on the long side)
|
|
489
|
+
* and sends a JPEG. Up to 8 per call. Pictures from other sites are fetched without cookies, like `ctx.page.fetchImage`. */
|
|
490
|
+
| { type: 'image'; image: Blob | HTMLImageElement | HTMLCanvasElement | ImageBitmap | ImageData | string }
|
|
491
|
+
/** In an `assistant` turn — a tool the model called. You get these in `result.message`; keep them as they are. */
|
|
492
|
+
| { type: 'tool-call'; id: string; name: string; input: Record<string, unknown> }
|
|
493
|
+
/** 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.
|
|
494
|
+
* `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. */
|
|
495
|
+
| { type: 'tool-result'; id: string; content: unknown; error?: boolean; images?: (Blob | HTMLImageElement | HTMLCanvasElement | ImageBitmap | ImageData | string)[] }
|
|
496
|
+
/** In an `assistant` turn — what the model needs back next time (its reasoning, sealed). Opaque — keep it exactly as `result.message` gave it. */
|
|
497
|
+
| { type: 'state'; state: string };
|
|
498
|
+
/** A plain string is shorthand for one text part. */
|
|
499
|
+
interface AiMessage { role: 'user' | 'assistant'; content: string | (AiPart | string)[] }
|
|
500
|
+
interface AiTool {
|
|
501
|
+
/** Letters, digits, `_` and `-`, up to 64 — unique in the call. */
|
|
502
|
+
name: string;
|
|
503
|
+
/** When to call it — the model reads this to decide. */
|
|
504
|
+
description: string;
|
|
505
|
+
/** What it takes — an object schema. */
|
|
506
|
+
input: AiSchema;
|
|
507
|
+
}
|
|
508
|
+
interface AiOptions {
|
|
509
|
+
/** One string is one user turn. Otherwise turns alternate, first and last are `'user'`. Up to 100 turns, 120,000 characters with `system`. */
|
|
510
|
+
messages: string | AiMessage[];
|
|
511
|
+
/** Instructions for the model — up to 20,000 characters. */
|
|
512
|
+
system?: string;
|
|
513
|
+
/** `'fast'` (default) — quick and cheap, right for most features. `'smart'` — slower, for harder thinking. Fave1 picks the
|
|
514
|
+
* model on whichever provider the person uses; you don't name one. */
|
|
515
|
+
model?: 'fast' | 'smart';
|
|
516
|
+
/** Cap on the answer's length in tokens — 1 to 4,096 (default 1,024). Lower is cheaper for them. */
|
|
517
|
+
maxTokens?: number;
|
|
518
|
+
/** Answer in this shape — `result.data` is the parsed value, already checked against the schema. */
|
|
519
|
+
json?: AiSchema;
|
|
520
|
+
/** Tools the model may call — up to 32. With `chat()` you get `result.calls` and run them yourself; `run()` does it for you. */
|
|
521
|
+
tools?: AiTool[];
|
|
522
|
+
/** 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
|
|
523
|
+
* 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.
|
|
524
|
+
* `run()` turns it on for you. `result.usage.cached` shows what came from the cache. */
|
|
525
|
+
cache?: boolean;
|
|
526
|
+
/** Which of their AIs answers — an `id` from `ctx.ai.choices()`. Leave it out for the AI they picked in Fave1 Settings.
|
|
527
|
+
* Use another one only when the person picks it in your UI: it goes on a different bill. Same monthly limit either way.
|
|
528
|
+
* 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. */
|
|
529
|
+
ai?: string;
|
|
530
|
+
/** Stop the call — the promise rejects with `aborted`, and nothing more is charged. */
|
|
531
|
+
signal?: AbortSignal;
|
|
532
|
+
}
|
|
533
|
+
interface AiToolCall { id: string; name: string; input: Record<string, unknown> }
|
|
534
|
+
interface AiResult {
|
|
535
|
+
text: string;
|
|
536
|
+
/** With `json` — the answer as a value, checked against your schema (a mismatch rejects with `provider`, `err.reason` `'json'`). */
|
|
537
|
+
data?: unknown;
|
|
538
|
+
/** Tools the model called this turn (empty when it just answered). */
|
|
539
|
+
calls: AiToolCall[];
|
|
540
|
+
/** `'done'` — it answered · `'tool'` — it wants tool results (see `calls`) · `'length'` — it hit `maxTokens`. */
|
|
541
|
+
stop: 'done' | 'tool' | 'length';
|
|
542
|
+
/** This turn as an `assistant` message — push it onto `messages` to keep the conversation going (tool calls and state included). */
|
|
543
|
+
message: AiMessage;
|
|
544
|
+
/** Tokens — `cached` is the part of `input` read from the provider's cache (cheaper). */
|
|
545
|
+
usage: { input: number; output: number; cached: number };
|
|
546
|
+
/** `'anthropic' | 'openai' | 'google' | 'xai'`, or `'mock'` in a DEV build without a key. */
|
|
547
|
+
provider: string;
|
|
548
|
+
model: string;
|
|
549
|
+
/** True for the stand-in answer a DEV build gets when you have no key or credits — the whole flow runs, nothing is charged.
|
|
550
|
+
* With `tools` it calls your first tool once; with `json` it returns the smallest value that fits. */
|
|
551
|
+
mock: boolean;
|
|
552
|
+
}
|
|
553
|
+
interface AiStream extends AsyncIterable<{ text: string }> {
|
|
554
|
+
/** The whole answer once the stream has ended (`null` before that). */
|
|
555
|
+
result(): AiResult | null;
|
|
556
|
+
}
|
|
557
|
+
interface AiRunTool extends AiTool {
|
|
558
|
+
/** Does it — gets the model's input (already checked against `input`) and returns anything; throw to report a failure to the model.
|
|
559
|
+
* Return a picture (Blob, <img>, canvas, ImageBitmap, ImageData) — or an array of strings and pictures — and the model gets to look at it. */
|
|
560
|
+
run(input: any, info: { id: string; signal?: AbortSignal }): unknown | Promise<unknown>;
|
|
561
|
+
}
|
|
562
|
+
interface AiRunOptions extends Omit<AiOptions, 'tools'> {
|
|
563
|
+
tools: AiRunTool[];
|
|
564
|
+
/** On by default here — every step resends the conversation so far. `false` turns it off. */
|
|
565
|
+
cache?: boolean;
|
|
566
|
+
/** Calls to the model at most — 1 to 10 (default 6). Each step is one call and counts against their limit. */
|
|
567
|
+
maxSteps?: number;
|
|
568
|
+
/** After each round of tool calls. */
|
|
569
|
+
onStep?(step: { step: number; calls: AiToolCall[]; results: AiPart[]; text: string }): void;
|
|
570
|
+
}
|
|
571
|
+
interface AiRunResult extends AiResult {
|
|
572
|
+
/** How many calls it took. */
|
|
573
|
+
steps: number;
|
|
574
|
+
/** The whole conversation, ending with the model's last turn — pass it back as `messages` to ask a follow-up. */
|
|
575
|
+
messages: AiMessage[];
|
|
576
|
+
}
|
|
577
|
+
/** What `ctx.ai.status()` resolves — check it to fold or explain the feature before anyone presses a button.
|
|
578
|
+
* `ready` · `ask` (the first call will ask) · `no-key` · `key-broken` · `off` (they said Not now, turned it off, or AI is
|
|
579
|
+
* paused for your app) · `limit` (this month's limit is reached) · `signed-out` · `not-installed`. */
|
|
580
|
+
type AiStatus = 'ready' | 'ask' | 'no-key' | 'key-broken' | 'off' | 'limit' | 'signed-out' | 'not-installed';
|
|
581
|
+
/** What `ctx.ai.usage()` resolves — this person's spending on your app this month (UTC), in US dollars. */
|
|
582
|
+
interface AiUsage {
|
|
583
|
+
/** Spent on your app so far this month. */
|
|
584
|
+
spent: number;
|
|
585
|
+
/** Their limit for your app, or `null` for no limit. */
|
|
586
|
+
limit: number | null;
|
|
587
|
+
/** What your app can still spend this month — the smallest of your app's limit, their overall limit and their Fave1 credits.
|
|
588
|
+
* `null` when nothing limits it. */
|
|
589
|
+
left: number | null;
|
|
590
|
+
/** Calls to the model this month. */
|
|
591
|
+
requests: number;
|
|
592
|
+
/** When it starts over (ISO time — the 1st of next month, UTC). */
|
|
593
|
+
resetAt: string | null;
|
|
594
|
+
/** True in a DEV build without a key — the numbers are zero. */
|
|
595
|
+
mock: boolean;
|
|
596
|
+
}
|
|
597
|
+
interface Ai {
|
|
598
|
+
/** One answer. A string is shorthand for one user message: `ctx.ai.chat('Say hi')`.
|
|
599
|
+
* Rejects with a `Fave1Error` — codes in `Fave1ErrorCode`; `err.message` is a sentence you can show as is. */
|
|
600
|
+
chat(options: AiOptions | string): Promise<AiResult>;
|
|
601
|
+
/** The same call, piece by piece: `for await (const part of ctx.ai.stream({ … })) out.textContent += part.text`. */
|
|
602
|
+
stream(options: AiOptions | string): AiStream;
|
|
603
|
+
/** A conversation with tools, start to finish — when the model calls a tool, Fave1 runs yours, sends the result back and asks
|
|
604
|
+
* 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`. */
|
|
605
|
+
run(options: AiRunOptions): Promise<AiRunResult>;
|
|
606
|
+
status(): Promise<AiStatus>;
|
|
607
|
+
/** Opens what fixes the current state — the one-time OK, or Fave1 Settings › AI (add a key, raise the limit, turn it back on).
|
|
608
|
+
* Resolves `true` when AI is ready now. Only the person can turn it on. */
|
|
609
|
+
setup(): Promise<boolean>;
|
|
610
|
+
/** 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.
|
|
611
|
+
* `null` where AI can't be used right now (check `status()` for why). Only your app's numbers — never their other apps'. */
|
|
612
|
+
usage(): Promise<AiUsage | null>;
|
|
613
|
+
/** The AIs this person can answer with right now. `current` is the one they picked in Fave1 Settings (what a plain `chat()` uses);
|
|
614
|
+
* `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
|
|
615
|
+
* 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).
|
|
616
|
+
* Where AI can't be used right now, `current` is `null`. In the sandbox you get two mock AIs to build with. */
|
|
617
|
+
choices(options?: { ask?: boolean }): Promise<AiChoices>;
|
|
618
|
+
/** 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
|
|
619
|
+
* added one, otherwise on their Fave1 credits — so it works for people on Claude or Fave1 AI too. Same Allow, limit and rules as
|
|
620
|
+
* `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')`. */
|
|
621
|
+
speak(text: string | AiSpeakOptions, options?: Omit<AiSpeakOptions, 'text'>): Promise<AiSpeech>;
|
|
622
|
+
/** The eighteen voices — six tones each from OpenAI, Gemini and Grok — and whether each can speak for this person right now.
|
|
623
|
+
* Show them, let the person pick, pass the `id` to `speak()`. Where AI can't be used yet every voice is `ready: false`;
|
|
624
|
+
* call `speak()` anyway and Fave1 asks the person. In the sandbox they're all ready. */
|
|
625
|
+
voices(): Promise<AiVoice[]>;
|
|
626
|
+
}
|
|
627
|
+
/** A feel, when you don't care which company speaks: Fave1 picks one the person can pay for. */
|
|
628
|
+
type AiVoiceTone = 'bright' | 'warm' | 'deep' | 'calm' | 'bold' | 'smooth';
|
|
629
|
+
interface AiVoice {
|
|
630
|
+
/** Pass this to `speak({ voice })` — `nova`, `fenrir`, `rex`… */
|
|
631
|
+
id: string;
|
|
632
|
+
/** Its name, for your picker. */
|
|
633
|
+
name: string;
|
|
634
|
+
/** Who makes it — `OpenAI` · `Gemini` · `Grok`. */
|
|
635
|
+
by: string;
|
|
636
|
+
tone: AiVoiceTone;
|
|
637
|
+
/** Would speak right now. */
|
|
638
|
+
ready: boolean;
|
|
639
|
+
/** Who pays: `key` — their own key for that company (the company bills them) · `credits` — their Fave1 credits · `null` — not ready. */
|
|
640
|
+
pays: 'key' | 'credits' | null;
|
|
641
|
+
/** On credits: about how many Fave1 credits 1,000 characters cost. `null` on their own key. */
|
|
642
|
+
credits: number | null;
|
|
643
|
+
}
|
|
644
|
+
interface AiSpeakOptions {
|
|
645
|
+
text: string;
|
|
646
|
+
/** A voice `id` from `voices()`, or a tone (`'bold'`) to let Fave1 pick the company. Default `'bright'`. */
|
|
647
|
+
voice?: string;
|
|
648
|
+
/** How to say it, up to 300 characters — "rap it on the beat, hype". Never a real person's voice. */
|
|
649
|
+
style?: string;
|
|
650
|
+
/** 0.5 – 2, default 1. */
|
|
651
|
+
speed?: number;
|
|
652
|
+
/** With a tone: which company to use — `openai` · `google` · `xai`. A voice `id` already names its company. */
|
|
653
|
+
ai?: string;
|
|
654
|
+
signal?: AbortSignal;
|
|
655
|
+
}
|
|
656
|
+
interface AiSpeech {
|
|
657
|
+
audio: Blob;
|
|
658
|
+
type: 'audio/mpeg' | 'audio/wav';
|
|
659
|
+
/** About how long it runs — decode the audio for the exact length. */
|
|
660
|
+
seconds: number;
|
|
661
|
+
/** The voice `id` that spoke — when you passed a tone, the one Fave1 picked. */
|
|
662
|
+
voice: string;
|
|
663
|
+
/** Which company spoke it — `openai` · `google` · `xai`, `mock` in the sandbox. */
|
|
664
|
+
provider: string | null;
|
|
665
|
+
/** Who paid — their own `key`, or their Fave1 `credits`. `null` in the sandbox. */
|
|
666
|
+
paid: 'key' | 'credits' | null;
|
|
667
|
+
/** True in the sandbox — a short tone the length of your text. */
|
|
668
|
+
mock: boolean;
|
|
669
|
+
}
|
|
670
|
+
/** `ctx.camera.open()` — a camera that's on. */
|
|
671
|
+
interface CameraFeed {
|
|
672
|
+
/** Already playing and muted (`playsinline`) — put it in your panel or draw it on a canvas each frame. */
|
|
673
|
+
video: HTMLVideoElement;
|
|
674
|
+
stream: MediaStream;
|
|
675
|
+
facing: 'user' | 'environment';
|
|
676
|
+
stop(): void;
|
|
677
|
+
}
|
|
678
|
+
interface Camera {
|
|
679
|
+
/** Turns their camera on — Fave1 asks first (once each time your app opens), then the browser asks for that site. Video only.
|
|
680
|
+
* Rejects `denied` · `blocked` · `unavailable` · `busy`. Call it from a tap, not at launch. */
|
|
681
|
+
open(options?: { facing?: 'user' | 'environment'; width?: number; height?: number }): Promise<CameraFeed>;
|
|
682
|
+
/** Every camera your app opened goes off. Closing your app does this too. */
|
|
683
|
+
close(): void;
|
|
684
|
+
readonly active: boolean;
|
|
685
|
+
}
|
|
686
|
+
/** One of the person's AIs. `id` is stable (`anthropic` · `openai` · `google` · `xai` · `fave1` · `mock`); `name` is what to show ("Claude", "Fave1 AI"). */
|
|
687
|
+
interface AiChoice { id: string; name: string }
|
|
688
|
+
interface AiChoices { current: AiChoice | null; others: AiChoice[]; locked: boolean }
|
|
689
|
+
|
|
690
|
+
/** One thing your app sells, as Fave1 keeps it — you name the `id`; the name, amount and price are on Fave1's side. */
|
|
691
|
+
interface PurchaseItem { id: string; name: string; qty: number; credits: number }
|
|
692
|
+
/** What `buy()` and `pending()` give back. `id` is the receipt — write it next to the thing you deliver. */
|
|
693
|
+
interface PurchaseReceipt { id: string; item: string; name: string; qty: number; credits: number }
|
|
694
|
+
interface Purchases {
|
|
695
|
+
/** Your items, in your order, and their credit balance — `null` when signed out, or on a site your app isn't allowed on yet. */
|
|
696
|
+
items(): Promise<{ items: PurchaseItem[]; balance: number | null }>;
|
|
697
|
+
/** Shows Fave1's confirm line — the Buy button is Fave1's, with Fave1's price on it. Resolves with a receipt once the credits
|
|
698
|
+
* are taken. Put the thing in your storage **with the receipt id in the same write**, then `finish()`. */
|
|
699
|
+
buy(item: string): Promise<PurchaseReceipt>;
|
|
700
|
+
/** Commits a receipt after you delivered. `'returned'` — 7 days passed without `finish()`, Fave1 already gave the credits back. */
|
|
701
|
+
finish(receipt: string): Promise<'done' | 'returned'>;
|
|
702
|
+
/** Receipts paid for but not finished — call on open, deliver what your storage doesn't show yet, then `finish()`. */
|
|
703
|
+
pending(): Promise<PurchaseReceipt[]>;
|
|
704
|
+
}
|
|
705
|
+
|
|
411
706
|
interface Ctx {
|
|
412
707
|
ui: Ui;
|
|
413
708
|
/** Where you're running: `'page'` — on someone's site, opened from the bookmarklet;
|
|
414
709
|
* `'app'` — at your own `<id>.fave1.app`, opened from My Fave1. Same bundle, split screens. */
|
|
415
710
|
surface: 'page' | 'app';
|
|
711
|
+
/** The language this person uses — `'en'`, `'ko'`, `'pt-BR'`… (what they picked in Fave1 Settings, else their browser's).
|
|
712
|
+
* Not the page's language — that's `page.lang`. */
|
|
713
|
+
readonly locale: string;
|
|
714
|
+
/** Your app's text in their language, from `locales/<language>.json` (shipped by `npm run submit`). `{name}` fills from `vars`;
|
|
715
|
+
* pass `{ count }` to pick `key_one` · `key_other` …. Falls back to their base language, then `en.json`, then the key itself. */
|
|
716
|
+
t(key: string, vars?: Record<string, string | number>): string;
|
|
416
717
|
/** `storage` — private JSON on this person's Fave1 account, per key. Nobody else reads it — not other apps, not other people,
|
|
417
718
|
* 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
719
|
* 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 +736,21 @@ interface Ctx {
|
|
|
435
736
|
* don't hard-code). Files don't count here: they go to their Fave1 storage (`quota` with `scope: 'account'`, `files.manage()`).
|
|
436
737
|
* 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
738
|
usage(): Promise<{ bytes: number; limit: number }>;
|
|
739
|
+
/** 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
|
|
740
|
+
* `{ at, site, item }` rows: `at` is the server's time (ISO), `site` the host of the page it was added on (set by Fave1 —
|
|
741
|
+
* your code can't change it), `null` at home. Read it with `get(key)`; trim or edit it with `set` · `delete` like any value.
|
|
742
|
+
* 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
|
|
743
|
+
* something that isn't a list, `invalid`. Because it only adds and can't read, it asks once for your app — not once per
|
|
744
|
+
* site: "Keep your <what> in <app>?" (`opts.what`, a few words, default `history`). `cancelled` if they say not now.
|
|
745
|
+
* Never asks at home. */
|
|
746
|
+
append(key: string, item: unknown, opts?: { what?: string }): Promise<void>;
|
|
747
|
+
/** Forget the once-for-every-site OK that `append()` asked for — the next `append()` on a site asks again (call it when
|
|
748
|
+
* someone turns your history off). Keeps the data. */
|
|
749
|
+
forgetAppend(): Promise<void>;
|
|
750
|
+
/** Ask for that OK now, while they're looking — when your panel opens, not the moment they click something that opens
|
|
751
|
+
* another window (the question would land behind it). `true` if it's already given (or at home), or they say yes; `false`
|
|
752
|
+
* if they say not now. Rejects `cancelled` if your panel closed before they answered. */
|
|
753
|
+
askAppend(opts?: { what?: string }): Promise<boolean>;
|
|
438
754
|
/** 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
755
|
* 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
756
|
* 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 +765,18 @@ interface Ctx {
|
|
|
449
765
|
};
|
|
450
766
|
/** Files on the account — declared with `storage`, like the JSON above. */
|
|
451
767
|
files: Files;
|
|
768
|
+
/** Stickers you give for their My Fave1 home — declared with `storage` too. */
|
|
769
|
+
stickers: StickersApi;
|
|
452
770
|
/** Values shared by link — declared with `storage` too. */
|
|
453
771
|
shared: SharedApi;
|
|
454
772
|
pub: Pub;
|
|
455
773
|
/** Live rooms — the same table, edited by several people at once (uses `pub`). */
|
|
456
774
|
live: Live;
|
|
775
|
+
/** AI on the person's own key or Fave1 credits — declared with `ai`. */
|
|
776
|
+
ai: Ai;
|
|
777
|
+
/** In-app purchases paid with Fave1 credits — declared with `storage`. **Not open to your app yet**: every call rejects with
|
|
778
|
+
* `not-yet` until Fave1 opens it (see /docs/ctx-purchases). */
|
|
779
|
+
purchases: Purchases;
|
|
457
780
|
/** Is this permission live right now? `pub` also needs a signed-in person who hasn't switched it off. */
|
|
458
781
|
can(permission: Permission): boolean;
|
|
459
782
|
/** Opens this app's permission screen in Fave1 settings. Only the person can turn things on. */
|
|
@@ -467,6 +790,8 @@ interface Ctx {
|
|
|
467
790
|
* tap (the browser counts a tap for a few seconds) copies at once — the tap was the yes; later it asks first.
|
|
468
791
|
* Resolves `true` once it's copied, `false` if they say no. */
|
|
469
792
|
clipboard: { read(): Promise<string | null>; write(text: string): Promise<boolean> };
|
|
793
|
+
/** Their camera, live, while your app is open — `camera` permission. The video stays on their page. */
|
|
794
|
+
camera: Camera;
|
|
470
795
|
/** Your app's settings, edited in the developer console (Config tab) and loaded before `onLaunch` — a plain JSON object.
|
|
471
796
|
* It ships without review, so it holds **values, not code** and nothing secret: every person who opens the app receives it.
|
|
472
797
|
* While you build, `fave1 dev` serves the `config.json` next to your manifest. Missing or unreachable → `{}`. */
|
|
@@ -482,6 +807,10 @@ interface Ctx {
|
|
|
482
807
|
* With Data set to "My account" in the DEV panel both work as they will live — the id belongs to your DEV slot. */
|
|
483
808
|
user: {
|
|
484
809
|
readonly signedIn: boolean;
|
|
810
|
+
/** Fave1 Plus — 'plus' (they have Plus or Ultra) · 'free' (they don't). Signed out is 'free'. */
|
|
811
|
+
readonly plus?: 'plus' | 'free';
|
|
812
|
+
/** 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. */
|
|
813
|
+
readonly tier?: 'free' | 'basic' | 'plus' | 'ultra' | null;
|
|
485
814
|
readonly id?: string;
|
|
486
815
|
readonly granted?: boolean;
|
|
487
816
|
load(): Promise<{ readonly signedIn: boolean; readonly id?: string; readonly granted?: boolean }>;
|
|
@@ -16,12 +16,13 @@ npm run dev # serves your app at http://localhost:7300 — leave it runnin
|
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
Open Fave1 from your bookmarks bar on any shop or article, hold the Fave1 logo,
|
|
19
|
-
paste `http://localhost:7300` and
|
|
19
|
+
paste `http://localhost:7300` and Add. Your app shows up first with a DEV badge.
|
|
20
20
|
Chrome asks once per site to allow local network access — allow it, and press
|
|
21
|
-
|
|
21
|
+
Add again if the panel already said it found nothing. Save a file, reopen the
|
|
22
22
|
app, and it's the new build. Changed
|
|
23
23
|
`manifest.json`? Close Fave1 and click it in your bookmarks bar again — reopening
|
|
24
|
-
the app isn't enough.
|
|
24
|
+
the app isn't enough. Building another app at the same time? Its `npm run dev` takes the
|
|
25
|
+
next free port (7301, 7302…) — add that address too, and they all show up.
|
|
25
26
|
Leave that terminal running and type everything else — `npm run submit` too — in a
|
|
26
27
|
second one; a command typed where the dev server runs does nothing.
|
|
27
28
|
|
|
@@ -30,6 +31,14 @@ and other sites, set **Data** to **My account** in the same panel — saves go t
|
|
|
30
31
|
DEV slot on your Fave1 account, kept apart from the live app. Clear it in Fave1
|
|
31
32
|
settings › Storage.
|
|
32
33
|
|
|
34
|
+
## Other languages
|
|
35
|
+
|
|
36
|
+
The words people see live in `locales/en.json`, and `ctx.t('key')` reads them. To add a language, copy it to
|
|
37
|
+
`locales/ko.json`, `locales/es.json` … and translate the values — keep the keys. Each person gets their own
|
|
38
|
+
language; any key a file is missing falls back to English. `{name}` fills from `ctx.t('key', { name })`, and
|
|
39
|
+
`{ count }` picks `key_one` or `key_other`. `npm run submit` uploads the files with your build and tells you
|
|
40
|
+
about missing keys. To try a language: `?locale=ko` on your app's home page, or the language picker in the DEV panel.
|
|
41
|
+
|
|
33
42
|
## Ship it
|
|
34
43
|
|
|
35
44
|
Once, in the console: **Create app** at
|
|
@@ -54,7 +63,7 @@ npm run submit -- --whats-new "Remembers your place" # with a line for the sto
|
|
|
54
63
|
|
|
55
64
|
It prints a **Test** link — your app on its own home (`{{id}}.fave1.app`), in any
|
|
56
65
|
browser, for 12 hours. That's how you see the home screen (`ctx.surface === 'app'`)
|
|
57
|
-
on a phone or in Safari. On your laptop,
|
|
66
|
+
on a phone or in Safari. On your laptop, every build you added as a DEV source also
|
|
58
67
|
shows up in [My Fave1](https://www.fave1.com/myapps) — open it there to try its home
|
|
59
68
|
in a window.
|
|
60
69
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"savingOff": "Saving is switched off for {{name}}.",
|
|
3
|
+
"signIn": "Sign in to Fave1 to keep pages here.",
|
|
4
|
+
"turnOn": "Turn it on in settings",
|
|
5
|
+
"already": "Already kept",
|
|
6
|
+
"failed": "Couldn’t keep it — try again",
|
|
7
|
+
"kept": "Kept",
|
|
8
|
+
"homeHow": "On any page, click Fave1 in your bookmarks bar, pick {{name}} and press Keep this page.",
|
|
9
|
+
"keep": "Keep this page",
|
|
10
|
+
"empty": "Nothing kept yet"
|
|
11
|
+
}
|
|
@@ -14,9 +14,9 @@ Fave1.defineApp({
|
|
|
14
14
|
ui.render([
|
|
15
15
|
ui.heading('{{name}}'),
|
|
16
16
|
ctx.user.signedIn
|
|
17
|
-
? ui.empty('📄',
|
|
18
|
-
: ui.empty('📄',
|
|
19
|
-
...(ctx.user.signedIn ? [ui.button('
|
|
17
|
+
? ui.empty('📄', ctx.t('savingOff'))
|
|
18
|
+
: ui.empty('📄', ctx.t('signIn')),
|
|
19
|
+
...(ctx.user.signedIn ? [ui.button(ctx.t('turnOn'), { variant: 'ghost', onClick: () => ctx.perms.open() })] : []),
|
|
20
20
|
]);
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
@@ -32,32 +32,32 @@ Fave1.defineApp({
|
|
|
32
32
|
|
|
33
33
|
const keep = async () => {
|
|
34
34
|
const page: Kept = { title: ctx.page.title || ctx.page.url, url: ctx.page.url };
|
|
35
|
-
if (saved.some((p) => p.url === page.url)) { ui.toast('
|
|
35
|
+
if (saved.some((p) => p.url === page.url)) { ui.toast(ctx.t('already'), 'info'); return; }
|
|
36
36
|
const next = [page, ...saved].slice(0, 20);
|
|
37
37
|
try {
|
|
38
38
|
await ctx.storage.set('pages', next);
|
|
39
39
|
} catch {
|
|
40
|
-
ui.toast(
|
|
40
|
+
ui.toast(ctx.t('failed'), 'error');
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
43
|
saved = next;
|
|
44
44
|
draw();
|
|
45
|
-
ui.toast('
|
|
45
|
+
ui.toast(ctx.t('kept'), 'success');
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
const draw = () => {
|
|
49
49
|
ui.render([
|
|
50
50
|
ui.heading('{{name}}'),
|
|
51
51
|
home
|
|
52
|
-
? ui.muted(
|
|
53
|
-
: ui.button('
|
|
52
|
+
? ui.muted(ctx.t('homeHow'))
|
|
53
|
+
: ui.button(ctx.t('keep'), { variant: 'purple', onClick: keep }),
|
|
54
54
|
ui.divider(),
|
|
55
55
|
saved.length
|
|
56
56
|
? ui.list(saved.map((p) => ui.item(p.title, {
|
|
57
57
|
sub: new URL(p.url).hostname,
|
|
58
58
|
onClick: () => window.open(p.url, '_blank', 'noopener'),
|
|
59
59
|
})))
|
|
60
|
-
: ui.empty('📄', '
|
|
60
|
+
: ui.empty('📄', ctx.t('empty')),
|
|
61
61
|
]);
|
|
62
62
|
};
|
|
63
63
|
|