@vibes.diy/prompts 5.5.0 → 5.5.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.
Files changed (2) hide show
  1. package/llms/backend.md +26 -5
  2. package/package.json +4 -4
package/llms/backend.md CHANGED
@@ -15,6 +15,20 @@ all — normal CRUD flows through Fireproof directly. Reach for it only when the
15
15
  app needs a server-side action: accepting a webhook, deriving/aggregating
16
16
  documents in reaction to writes, or periodic work.
17
17
 
18
+ ## When to use which handler — signal words
19
+
20
+ - **`fetch`** — "webhook", "OAuth", "callback", "API endpoint", "receive",
21
+ "form POST", "Stripe/GitHub/Sonos sends us…". Something **external → us**.
22
+ - **`onChange`** — "when X is created", "after a write", "notify", "send an
23
+ email", "aggregate", "moderate", "sync to…". An **internal write → a side
24
+ effect**.
25
+ - **`scheduled`** — "every N minutes", "poll", "check periodically", "cron",
26
+ "cleanup", "digest". **Timer-driven**, no user in the loop.
27
+
28
+ An app can need more than one — a payments app wants `fetch` (webhook receipt)
29
+ **and** `onChange` (email on the new order). If none of these signal words fit
30
+ the request, the app needs no `backend.js` — don't emit one.
31
+
18
32
  ## Output format
19
33
 
20
34
  `backend.js` is a separate file, exactly like `access.js`: one prose line, the
@@ -70,6 +84,7 @@ await ctx.db.put(doc, { db: "notes", id: "optional-id" }); // resolves to the do
70
84
  await ctx.db.delete(docId, { db: "notes" });
71
85
  const docs = await ctx.db.query({ db: "notes" }); // latest non-deleted docs (each with _id)
72
86
  const text = await ctx.callAI("prompt", { model: "openrouter/auto", max_tokens: 500 }); // server-side AI call
87
+ const res = await ctx.fetch("https://api.example.com/x", { headers }); // outbound HTTP — use this, not bare fetch()
73
88
  ```
74
89
 
75
90
  - `{ db }` names the Fireproof database (same names `App.jsx` uses with
@@ -90,10 +105,16 @@ const text = await ctx.callAI("prompt", { model: "openrouter/auto", max_tokens:
90
105
  (`Authorization: Bearer ${ctx.secrets.KEY}` to an admitted API). Never write a
91
106
  value anywhere users can read it (a doc, a response body). Only the owner can
92
107
  set or rotate secrets; handlers see the current values on every invocation.
93
- - **Outbound `fetch()` is policy-gated**: `backend.js` can call external https
94
- APIs that either (a) are CORS-open the platform forwards the request exactly
95
- as a browser on the app's own page could (same preflight rules, same
96
- `Access-Control-Allow-Origin` check, browser-forbidden headers like `Cookie`
108
+ - **Make every outbound HTTP call with `ctx.fetch(...)`, never a bare `fetch(...)`.**
109
+ It takes the same arguments as the web `fetch` and returns a `Response`. Why not
110
+ bare `fetch`: a backend that exports a `fetch` handler creates a module-scoped
111
+ `fetch` binding, so a bare `fetch(url)` anywhere in the file resolves to **your
112
+ own handler** — a `fetch` handler calling out recurses into itself, and a
113
+ `scheduled`/`onChange` call passes the URL where a `Request` is expected. `ctx.fetch`
114
+ always reaches the real HTTP client. **It is policy-gated**: `backend.js` can call
115
+ external https APIs that either (a) are CORS-open — the platform forwards the
116
+ request exactly as a browser on the app's own page could (same preflight rules,
117
+ same `Access-Control-Allow-Origin` check, browser-forbidden headers like `Cookie`
97
118
  are stripped) — or (b) are on the platform's curated list (`api.github.com` is
98
119
  seeded; additions are a PR to the platform repo). A denied call returns
99
120
  `403 {"vibesEgressDenied":true,"gate":"floor"|"owner-blocked"|"cors"|"rate-limit","host":...}` —
@@ -101,7 +122,7 @@ const text = await ctx.callAI("prompt", { model: "openrouter/auto", max_tokens:
101
122
  request a curated-list addition, or ask about owner blessing. Limits: https
102
123
  on port 443 only, 15s per request, 10MB responses, per-vibe rate caps
103
124
  (30/10s, 300/min). Make all outbound calls **before returning** the Response —
104
- a `fetch()` fired while a streamed body is still being pulled after the
125
+ a `ctx.fetch()` fired while a streamed body is still being pulled after the
105
126
  handler returned is unsupported and gets denied. Interactive frontend AI
106
127
  calls stay in `App.jsx` via `callAI`; server-side AI belongs to `ctx.callAI`.
107
128
  - **`ctx.callAI(prompt, options?)` is the server-side AI call.** It resolves to
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibes.diy/prompts",
3
- "version": "5.5.0",
3
+ "version": "5.5.3",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "description": "",
@@ -24,9 +24,9 @@
24
24
  "license": "Apache-2.0",
25
25
  "dependencies": {
26
26
  "@adviser/cement": "~0.5.34",
27
- "@vibes.diy/call-ai-v2": "^5.5.0",
28
- "@vibes.diy/identity": "^5.5.0",
29
- "@vibes.diy/use-vibes-types": "^5.5.0",
27
+ "@vibes.diy/call-ai-v2": "^5.5.3",
28
+ "@vibes.diy/identity": "^5.5.3",
29
+ "@vibes.diy/use-vibes-types": "^5.5.3",
30
30
  "arktype": "~2.2.3",
31
31
  "json-schema-faker": "~0.6.2"
32
32
  },