create-wervt 0.2.7 → 0.2.8

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/index.js CHANGED
@@ -25,6 +25,7 @@ const EXAMPLE_FILES = [
25
25
  'server/api/todos.post.ts',
26
26
  'server/api/todos',
27
27
  'server/api/shapes/todos.get.ts',
28
+ 'server/tools',
28
29
  'drizzle',
29
30
  ]
30
31
  const EMPTY_SCHEMA = `// Tables are declared without a schema: on wervt the app's database role only sees
@@ -93,7 +94,7 @@ const main = defineCommand({
93
94
  empty: {
94
95
  type: 'boolean',
95
96
  default: false,
96
- description: 'Without the todo example (no API routes, table or migration)',
97
+ description: 'Without the todo example (no API routes, tools, table or migration)',
97
98
  },
98
99
  },
99
100
  async run({ args }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-wervt",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "Create a new wervt app: Nuxt 5, Postgres with Drizzle, live data with Electric.",
5
5
  "homepage": "https://wervt.app",
6
6
  "license": "MIT",
@@ -8,6 +8,7 @@ Supabase Edge Runtime) with its own Postgres schema and live data through Electr
8
8
 
9
9
  - `app.vue`, `pages/`, `components/`: the Vue app.
10
10
  - `server/api/`: API routes. `server/api/shapes/`: live data routes.
11
+ - `server/tools/`: tools that browser agents can call on the page (WebMCP).
11
12
  - `server/db/schema.ts`: the Drizzle schema. `drizzle/`: generated migrations. Commit both.
12
13
 
13
14
  ## UI
@@ -108,6 +109,12 @@ const { data: todos, isLive } = await useShape<Todo>('/api/shapes/todos')
108
109
  proxyShape(event, { table: 'notes', where: '"ownerId" = $1', params: [userId] })
109
110
  ```
110
111
 
112
+ ## New releases
113
+
114
+ Open tabs notice a new release by themselves and show a reload banner. Don't build your own
115
+ version polling. For a banner in the app's own design, set `wervt: { updates: 'manual' }` and use
116
+ `const { available, reload } = useWervtUpdate()`.
117
+
111
118
  ## Users and sessions
112
119
 
113
120
  - `useWervtUser(event)` (server, from `@wervt/nuxt/server`) and `useWervtUser()` (app,
@@ -167,6 +174,38 @@ wervt: { timezone: 'Europe/Berlin' }, // optional, UTC by default
167
174
  `pnpm exec wervt tasks <app> --run <name>`), e.g. for a backfill.
168
175
  - Every run is logged: `pnpm exec wervt logs <app> 'type:=Task'`.
169
176
 
177
+ ## Browser agents (WebMCP)
178
+
179
+ Tools in `server/tools/` let an agent in the visitor's browser use the app on their behalf
180
+ (through WebMCP, `document.modelContext`). Give the app a tool for each thing a user would ask an
181
+ agent to do in it: list, add, change.
182
+
183
+ ```ts
184
+ // server/tools/add-todo.ts → tool "add-todo" (server/tools/todos/add.ts is "todos.add")
185
+ import { defineTool, useDb } from '@wervt/nuxt/server'
186
+ import * as v from 'valibot'
187
+ import { todos } from '../db/schema'
188
+
189
+ export default defineTool({
190
+ description: 'Add a todo. Returns the new todo.',
191
+ input: { title: v.pipe(v.string(), v.trim(), v.nonEmpty(), v.maxLength(200)) },
192
+ async handler(event, input) {
193
+ const [todo] = await useDb().insert(todos).values(input).returning()
194
+ return todo
195
+ },
196
+ })
197
+ ```
198
+
199
+ - The agent picks tools by their `description`: say what the tool does, what it returns and where
200
+ to get ids from. `input` is a valibot schema or `{ key: schema }` (validated like
201
+ `useValidatedBody`; agents send JSON, so numbers are numbers: no `vh.*`). Omit it for no input.
202
+ - `readOnly: true` for tools that only read. Agents may call those without asking the user.
203
+ - A tool runs as the visitor, like an API route: check `useWervtUser(event)` and ownership in the
204
+ handler exactly as the matching route does. Throw `createError` for errors; the agent sees the
205
+ message.
206
+ - Writes reach the page through live data by themselves; the tool doesn't need to update the UI.
207
+ - Browsers without WebMCP ignore the tools. `wervt: { webmcp: false }` turns them off.
208
+
170
209
  ## Don'ts
171
210
 
172
211
  - No Node-only APIs that Deno lacks (`child_process`, native addons, writing to the filesystem).
@@ -9,13 +9,13 @@
9
9
  "postinstall": "nuxt prepare"
10
10
  },
11
11
  "dependencies": {
12
- "@wervt/nuxt": "^0.2.8",
12
+ "@wervt/nuxt": "^0.2.9",
13
13
  "drizzle-orm": "1.0.0-rc.4",
14
14
  "nuxt": "npm:nuxt-nightly@5x",
15
15
  "valibot": "^1.5.0"
16
16
  },
17
17
  "devDependencies": {
18
- "@wervt/cli": "^0.2.7",
18
+ "@wervt/cli": "^0.2.8",
19
19
  "drizzle-kit": "1.0.0-rc.4",
20
20
  "vite-plus": "^1.0.0"
21
21
  }
@@ -0,0 +1,12 @@
1
+ import { defineTool, useDb } from '@wervt/nuxt/server'
2
+ import * as v from 'valibot'
3
+ import { todos } from '../db/schema'
4
+
5
+ export default defineTool({
6
+ description: 'Add a todo. Returns the new todo.',
7
+ input: { title: v.pipe(v.string(), v.trim(), v.nonEmpty(), v.maxLength(200)) },
8
+ async handler(_event, input) {
9
+ const [todo] = await useDb().insert(todos).values(input).returning()
10
+ return todo
11
+ },
12
+ })
@@ -0,0 +1,10 @@
1
+ import { defineTool, useDb } from '@wervt/nuxt/server'
2
+ import { desc } from 'drizzle-orm'
3
+ import { todos } from '../db/schema'
4
+
5
+ // Browser agents (WebMCP) can call the tools in this folder on the open page, as the visitor.
6
+ export default defineTool({
7
+ description: 'List all todos, newest first, with their id, title and whether they are done.',
8
+ readOnly: true,
9
+ handler: () => useDb().select().from(todos).orderBy(desc(todos.createdAt)),
10
+ })
@@ -0,0 +1,15 @@
1
+ import { defineTool, useDb } from '@wervt/nuxt/server'
2
+ import { eq } from 'drizzle-orm'
3
+ import { createError } from 'nuxt/server'
4
+ import * as v from 'valibot'
5
+ import { todos } from '../db/schema'
6
+
7
+ export default defineTool({
8
+ description: 'Mark a todo as done or not done. Get the id from list-todos.',
9
+ input: { id: v.pipe(v.number(), v.integer()), done: v.boolean() },
10
+ async handler(_event, { id, done }) {
11
+ const [todo] = await useDb().update(todos).set({ done }).where(eq(todos.id, id)).returning()
12
+ if (!todo) throw createError({ status: 404, message: `No todo with id ${id}` })
13
+ return todo
14
+ },
15
+ })