@vibes.diy/prompts 4.0.4 → 4.0.6
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/json-docs.d.ts +1 -0
- package/json-docs.js.map +1 -1
- package/llms/backend.d.ts +2 -0
- package/llms/backend.js +6 -0
- package/llms/backend.js.map +1 -0
- package/llms/backend.md +157 -0
- package/llms/index.d.ts +2 -1
- package/llms/index.js +3 -0
- package/llms/index.js.map +1 -1
- package/package.json +4 -4
package/json-docs.d.ts
CHANGED
package/json-docs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-docs.js","sourceRoot":"","sources":["../jsr/json-docs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"json-docs.js","sourceRoot":"","sources":["../jsr/json-docs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AA0B7C,MAAM,UAAU,kBAAkB;IAChC,OAAO,aAAa,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAChF,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,OAAO,eAAe,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,OAAO,WAAW,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;QACjC,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,IAAuB,EAAE;IAC5D,MAAM,CAAC,GAAa,EAAc,CAAC;IAGnC,KAAK,MAAM,MAAM,IAAI,UAAU,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,GAAG,MAAM,CAAC,IAAI,OAAO,CAAC;QACvC,CAAC,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;IAChD,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC,CAAC,CAAC"}
|
package/llms/backend.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const backendConfig = {
|
|
2
|
+
name: "backend",
|
|
3
|
+
label: "backend-js",
|
|
4
|
+
description: "server-side backend.js file: answer HTTP/webhook requests at the app's /_api URL, react to committed data changes, and run scheduled jobs — its writes go through the app's own access rules",
|
|
5
|
+
};
|
|
6
|
+
//# sourceMappingURL=backend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend.js","sourceRoot":"","sources":["../../jsr/llms/backend.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,aAAa,GAAc;IACtC,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,YAAY;IACnB,WAAW,EACT,8LAA8L;CACjM,CAAC"}
|
package/llms/backend.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# backend.js — the app's server-side backend
|
|
2
|
+
|
|
3
|
+
`backend.js` is an optional **server-side** file, a sibling of `access.js`. It
|
|
4
|
+
runs on the platform's servers — never in the browser — and gives the app three
|
|
5
|
+
server superpowers, each an exported function:
|
|
6
|
+
|
|
7
|
+
- **`fetch(request, ctx)`** — answer HTTP requests at the app's `/_api/...` URL
|
|
8
|
+
(webhooks from outside, or `fetch("/_api/…")` from the app itself).
|
|
9
|
+
- **`onChange(event, ctx)`** — react after a document write commits (derive,
|
|
10
|
+
aggregate, moderate, fan out).
|
|
11
|
+
- **`scheduled(event, ctx)`** — run periodically (cleanup, digests, timers).
|
|
12
|
+
|
|
13
|
+
Export only the handlers the app needs. Most apps need **no** `backend.js` at
|
|
14
|
+
all — normal CRUD flows through Fireproof directly. Reach for it only when the
|
|
15
|
+
app needs a server-side action: accepting a webhook, deriving/aggregating
|
|
16
|
+
documents in reaction to writes, or periodic work.
|
|
17
|
+
|
|
18
|
+
## Output format
|
|
19
|
+
|
|
20
|
+
`backend.js` is a separate file, exactly like `access.js`: one prose line, the
|
|
21
|
+
filename `backend.js` on its own line, then one **complete** fenced block (the
|
|
22
|
+
whole file — don't use SEARCH/REPLACE for it; re-emit the full file to change
|
|
23
|
+
it). **Never put backend code inside an `App.jsx` block**, and never import
|
|
24
|
+
`backend.js` from `App.jsx` — the browser can't run it.
|
|
25
|
+
|
|
26
|
+
## Writes go through the access function
|
|
27
|
+
|
|
28
|
+
Every `ctx.db.put`/`ctx.db.delete` is enforced by the app's own `access.js` —
|
|
29
|
+
the exact gate user writes pass through — acting as the **trigger's identity**:
|
|
30
|
+
|
|
31
|
+
| Handler | Writes act as… |
|
|
32
|
+
| ----------- | ----------------------------------------------------------------- |
|
|
33
|
+
| `onChange` | the user whose write triggered the event |
|
|
34
|
+
| `fetch` | the signed-in caller when verifiable — treat as possibly anonymous |
|
|
35
|
+
| `scheduled` | the app owner |
|
|
36
|
+
|
|
37
|
+
So the permission model stays in `access.js`, and `backend.js` writes must be
|
|
38
|
+
allowed by it for the acting identity. If a `fetch` handler writes, make sure
|
|
39
|
+
the access function permits that write for an anonymous caller (or design the
|
|
40
|
+
write to happen in `onChange`/`scheduled`, which carry stronger identities).
|
|
41
|
+
|
|
42
|
+
The flip side: the access function **cannot tell** a backend write from a user
|
|
43
|
+
write — that's the invariant. An `onChange` write acts as the triggering user,
|
|
44
|
+
so anything it may write, that user's own client could write too. `onChange` is
|
|
45
|
+
for **derivation and convenience**, never privilege escalation. For documents
|
|
46
|
+
only the server should control, use `scheduled` — it acts as the **owner**, an
|
|
47
|
+
identity `access.js` can genuinely restrict a database to.
|
|
48
|
+
|
|
49
|
+
## ctx — what a handler gets
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
ctx.appInfo; // { ownerHandle, appSlug } — this app's identity
|
|
53
|
+
ctx.userInfo; // { userHandle } or null — who the handler is acting as
|
|
54
|
+
await ctx.db.put(doc, { db: "notes", id: "optional-id" }); // resolves to the doc id AFTER commit
|
|
55
|
+
await ctx.db.delete(docId, { db: "notes" });
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
- `{ db }` names the Fireproof database (same names `App.jsx` uses with
|
|
59
|
+
`useFireproof`). It is **required** — except inside `onChange`, where the
|
|
60
|
+
database that triggered the event is the default.
|
|
61
|
+
- Always `await` db calls; they resolve only after the write commits (or throw
|
|
62
|
+
when the access function denies it).
|
|
63
|
+
- **No outside network access**: `fetch()` to external URLs is refused inside
|
|
64
|
+
`backend.js`, and there are no secrets/API keys yet. Don't call third-party
|
|
65
|
+
APIs from the backend; AI calls stay in `App.jsx` via `callAI`.
|
|
66
|
+
|
|
67
|
+
## fetch — the app's HTTP endpoint
|
|
68
|
+
|
|
69
|
+
Runs for requests to the app's `/_api` route. The request path is rooted after
|
|
70
|
+
`/_api`: a call to `https://slug--owner.host/_api/webhooks/pay` arrives with
|
|
71
|
+
pathname `/webhooks/pay`. Return a standard `Response`.
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
export async function fetch(request, ctx) {
|
|
75
|
+
const url = new URL(request.url);
|
|
76
|
+
if (url.pathname === "/rsvp" && request.method === "POST") {
|
|
77
|
+
const body = await request.json();
|
|
78
|
+
const id = await ctx.db.put({ kind: "rsvp", name: body.name, at: Date.now() }, { db: "rsvps" });
|
|
79
|
+
return new Response(JSON.stringify({ ok: true, id }), {
|
|
80
|
+
headers: { "content-type": "application/json" },
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return new Response("not found", { status: 404 });
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
From `App.jsx`, call it with a relative fetch — no host needed:
|
|
88
|
+
|
|
89
|
+
```js
|
|
90
|
+
const res = await fetch("/_api/rsvp", { method: "POST", body: JSON.stringify({ name }) });
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## onChange — react to committed writes
|
|
94
|
+
|
|
95
|
+
Runs after any document write to the app's databases commits (user writes and
|
|
96
|
+
backend writes alike). The event:
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
export async function onChange(event, ctx) {
|
|
100
|
+
// event: { dbName, docId, doc, oldDoc, seq, deleted }
|
|
101
|
+
if (event.dbName !== "votes" || event.deleted) return;
|
|
102
|
+
// Maintain a server-authoritative tally the UI reads but users can't forge.
|
|
103
|
+
await ctx.db.put({ _id: "tally-" + event.doc.pollId, kind: "tally", bump: event.seq }, { db: "tallies" });
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Two rules keep change-reactions sane:
|
|
108
|
+
|
|
109
|
+
1. **Guard on `event.dbName` first.** The handler fires for every database, so
|
|
110
|
+
an unguarded write-back loops on itself.
|
|
111
|
+
2. **Write derived docs to a different database** than the one that triggered
|
|
112
|
+
the event. A backend write triggers `onChange` again (one generation deeper);
|
|
113
|
+
the platform caps runaway chains after a few generations, but a tight
|
|
114
|
+
same-database ping-pong is still wasted work. Different db + dbName guard
|
|
115
|
+
makes loops structurally impossible.
|
|
116
|
+
|
|
117
|
+
## scheduled — periodic work
|
|
118
|
+
|
|
119
|
+
Requires a `config` export with a **static string-literal** interval between
|
|
120
|
+
`"5s"` and `"1h"` (e.g. `"30s"`, `"5m"`, `"1h"` — computed values are rejected):
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
export const config = { scheduled: { interval: "15m" } };
|
|
124
|
+
|
|
125
|
+
export async function scheduled(event, ctx) {
|
|
126
|
+
// event: { scheduledTime } — ISO timestamp of this tick
|
|
127
|
+
await ctx.db.put({ kind: "heartbeat", at: event.scheduledTime }, { db: "status" });
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Runs as the app owner. Use it for cleanup, digests, and time-based state — not
|
|
132
|
+
for anything that needs a user in the loop.
|
|
133
|
+
|
|
134
|
+
## A complete example — activity feed + owner-only digest
|
|
135
|
+
|
|
136
|
+
Users write `note` docs from `App.jsx`. The backend does two jobs: `onChange`
|
|
137
|
+
mirrors each note into a per-author `activity` entry (acting as that author —
|
|
138
|
+
same privilege, just automated), and a `scheduled` sweep maintains one `digest`
|
|
139
|
+
doc that `access.js` restricts to the **owner**, so no user can forge it.
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
export const config = { scheduled: { interval: "15m" } };
|
|
143
|
+
|
|
144
|
+
export async function onChange(event, ctx) {
|
|
145
|
+
if (event.dbName !== "notes" || event.deleted) return;
|
|
146
|
+
await ctx.db.put(
|
|
147
|
+
{ _id: "act-" + event.docId, kind: "activity", srcId: event.docId, by: ctx.userInfo, at: event.seq },
|
|
148
|
+
{ db: "activity" }
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export async function scheduled(event, ctx) {
|
|
153
|
+
// Acts as the app owner — access.js allows `digest` docs for the owner only,
|
|
154
|
+
// making this document genuinely server-controlled.
|
|
155
|
+
await ctx.db.put({ _id: "digest", kind: "digest", updatedAt: event.scheduledTime }, { db: "digest" });
|
|
156
|
+
}
|
|
157
|
+
```
|
package/llms/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { backendConfig } from "./backend.js";
|
|
1
2
|
export { callaiConfig } from "./callai.js";
|
|
2
3
|
export { fireproofConfig } from "./fireproof.js";
|
|
3
4
|
export { imageGenConfig } from "./image-gen.js";
|
|
@@ -9,4 +10,4 @@ export { useViewerConfig } from "./use-viewer.js";
|
|
|
9
10
|
export { useVibeConfig } from "./use-vibe.js";
|
|
10
11
|
export { createVibeConfig } from "./create-vibe.js";
|
|
11
12
|
export type { LlmConfig } from "./types.js";
|
|
12
|
-
export declare const allConfigs: readonly [import("./types.js").LlmConfig, import("./types.js").LlmConfig, import("./types.js").LlmConfig, import("./types.js").LlmConfig, import("./types.js").LlmConfig, import("./types.js").LlmConfig, import("./types.js").LlmConfig, import("./types.js").LlmConfig, import("./types.js").LlmConfig, import("./types.js").LlmConfig];
|
|
13
|
+
export declare const allConfigs: readonly [import("./types.js").LlmConfig, import("./types.js").LlmConfig, import("./types.js").LlmConfig, import("./types.js").LlmConfig, import("./types.js").LlmConfig, import("./types.js").LlmConfig, import("./types.js").LlmConfig, import("./types.js").LlmConfig, import("./types.js").LlmConfig, import("./types.js").LlmConfig, import("./types.js").LlmConfig];
|
package/llms/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { backendConfig } from "./backend.js";
|
|
1
2
|
import { callaiConfig } from "./callai.js";
|
|
2
3
|
import { fireproofConfig } from "./fireproof.js";
|
|
3
4
|
import { imageGenConfig } from "./image-gen.js";
|
|
@@ -8,6 +9,7 @@ import { webxrConfig } from "./webxr.js";
|
|
|
8
9
|
import { useViewerConfig } from "./use-viewer.js";
|
|
9
10
|
import { useVibeConfig } from "./use-vibe.js";
|
|
10
11
|
import { createVibeConfig } from "./create-vibe.js";
|
|
12
|
+
export { backendConfig } from "./backend.js";
|
|
11
13
|
export { callaiConfig } from "./callai.js";
|
|
12
14
|
export { fireproofConfig } from "./fireproof.js";
|
|
13
15
|
export { imageGenConfig } from "./image-gen.js";
|
|
@@ -29,5 +31,6 @@ export const allConfigs = [
|
|
|
29
31
|
useViewerConfig,
|
|
30
32
|
useVibeConfig,
|
|
31
33
|
createVibeConfig,
|
|
34
|
+
backendConfig,
|
|
32
35
|
];
|
|
33
36
|
//# sourceMappingURL=index.js.map
|
package/llms/index.js.map
CHANGED
|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ACxB,YAAY;IACZ,cAAc;IACd,cAAc;IACd,QAAQ;IACR,aAAa;IACb,eAAe;IACf,WAAW;IACX,eAAe;IACf,aAAa;IACb,gBAAgB;IAChB,aAAa;CACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibes.diy/prompts",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.6",
|
|
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": "^4.0.
|
|
28
|
-
"@vibes.diy/identity": "^4.0.
|
|
29
|
-
"@vibes.diy/use-vibes-types": "^4.0.
|
|
27
|
+
"@vibes.diy/call-ai-v2": "^4.0.6",
|
|
28
|
+
"@vibes.diy/identity": "^4.0.6",
|
|
29
|
+
"@vibes.diy/use-vibes-types": "^4.0.6",
|
|
30
30
|
"arktype": "~2.2.1",
|
|
31
31
|
"json-schema-faker": "~0.6.2"
|
|
32
32
|
},
|