Enable LLMs to handle webhooks with plaintext files
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

flesh out fetch and express package READMEs with usage

+112 -4
+55 -2
packages/express/README.md
··· 1 1 # `@lure/express` 2 2 3 - Provides an Express-compatible middleware function for handling webhook 4 - requests. 3 + Provides an Express-compatible middleware function for processing webhook 4 + events with Lure. 5 + 6 + ## Usage 7 + 8 + ```ts 9 + import express from 'express'; 10 + import { createLureHandler } from '@lure/express'; 11 + 12 + const app = express(); 13 + 14 + app.use(createLureHandler({ 15 + basePath: '/webhooks', 16 + luresDir: './lures', 17 + callback: async (prompt, config) => { 18 + // Send the prompt to your LLM of choice 19 + }, 20 + })); 21 + ``` 22 + 23 + The middleware calls `next()` for any request that does not match a lure path, 24 + so it can be composed freely with other Express middleware and routes. 25 + 26 + ### With config schema 27 + 28 + ```ts 29 + import express from 'express'; 30 + import { createLureHandler } from '@lure/express'; 31 + import * as v from 'valibot'; 32 + 33 + const app = express(); 34 + 35 + app.use(createLureHandler({ 36 + basePath: '/webhooks', 37 + luresDir: './lures', 38 + configSchema: v.object({ 39 + channel: v.string(), 40 + }), 41 + callback: async (prompt, config) => { 42 + await notify(config.channel, prompt); 43 + }, 44 + })); 45 + ``` 46 + 47 + ### Options 48 + 49 + | Option | Type | Default | Description | 50 + |---|---|---|---| 51 + | `basePath` | `string` | — | URL path prefix for all lure endpoints | 52 + | `luresDir` | `string` | — | Path to the directory containing `.lure` files | 53 + | `callback` | `(prompt: string, config: TConfig) => Promise<void>` | — | Called with the rendered prompt on each verified webhook. `TConfig` is inferred from `configSchema`, or `unknown` if omitted | 54 + | `configSchema` | Standard Schema | — | Schema for validating the `config` frontmatter block. Informs the type of `config` in `callback` | 55 + | `maxAttempts` | `number` | `1` | Number of times to attempt `callback` before dropping the webhook | 56 + | `allowUnverified` | `boolean` | `true` | Whether to allow `.lure` files without a `verify` block | 57 + | `watch` | `boolean` | `false` | Watch `luresDir` for changes and reload lures automatically |
+57 -2
packages/fetch/README.md
··· 1 1 # `@lure/fetch` 2 2 3 - Provides a fetch-compatible `Request -> Response` function for handling 4 - webhooks. 3 + Provides a fetch-compatible request handler for processing webhook events with 4 + Lure. Suitable for use with Deno, Bun, Cloudflare Workers, or any other 5 + runtime that uses the fetch API. 6 + 7 + ## Usage 8 + 9 + ```ts 10 + import { createLureHandler } from '@lure/fetch'; 11 + 12 + const lure = createLureHandler({ 13 + basePath: '/webhooks', 14 + luresDir: './lures', 15 + callback: async (prompt, config) => { 16 + // Send the prompt to your LLM of choice 17 + }, 18 + }); 19 + 20 + Deno.serve((req) => lure(req) ?? new Response(null, { status: 404 })); 21 + ``` 22 + 23 + `createLureHandler` returns `(req: Request) => Response | null`. A `null` 24 + return means the request path did not match any lure, leaving the caller free 25 + to handle it as appropriate. 26 + 27 + ### With config schema 28 + 29 + Pass a [Standard Schema](https://standardschema.dev)-compatible schema to 30 + validate the `config` block in your `.lure` files. Any schema library that 31 + implements the Standard Schema spec (Zod, Valibot, Arktype, etc.) will work. 32 + 33 + ```ts 34 + import { createLureHandler } from '@lure/fetch'; 35 + import * as v from 'valibot'; 36 + 37 + const lure = createLureHandler({ 38 + basePath: '/webhooks', 39 + luresDir: './lures', 40 + configSchema: v.object({ 41 + channel: v.string(), 42 + }), 43 + callback: async (prompt, config) => { 44 + await notify(config.channel, prompt); 45 + }, 46 + }); 47 + ``` 48 + 49 + ### Options 50 + 51 + | Option | Type | Default | Description | 52 + |---|---|---|---| 53 + | `basePath` | `string` | — | URL path prefix for all lure endpoints | 54 + | `luresDir` | `string` | — | Path to the directory containing `.lure` files | 55 + | `callback` | `(prompt: string, config: TConfig) => Promise<void>` | — | Called with the rendered prompt on each verified webhook. `TConfig` is inferred from `configSchema`, or `unknown` if omitted | 56 + | `configSchema` | Standard Schema | — | Schema for validating the `config` frontmatter block. Informs the type of `config` in `callback` | 57 + | `maxAttempts` | `number` | `1` | Number of times to attempt `callback` before dropping the webhook | 58 + | `allowUnverified` | `boolean` | `true` | Whether to allow `.lure` files without a `verify` block | 59 + | `watch` | `boolean` | `false` | Watch `luresDir` for changes and reload lures automatically |