@lure-hooks/fetch
v1.0.0
Published
Fetch API adapter for Lure — process webhook events into LLM prompts with Deno, Bun, and Cloudflare Workers
Downloads
16
Maintainers
Readme
@lure-hooks/fetch
Provides a fetch-compatible request handler for processing webhook events with Lure. Suitable for use with Deno, Bun, Cloudflare Workers, or any other runtime that uses the fetch API.
Installation
npm install @lure-hooks/fetchUsage
import { createLureHandler } from "@lure-hooks/fetch";
const lure = await createLureHandler({
basePath: "/webhooks",
luresDir: "./lures",
callback: async (prompt, config) => {
// Send the prompt to your LLM of choice
},
});
Deno.serve((req) => lure(req) ?? new Response(null, { status: 404 }));createLureHandler returns Promise<(req: Request) => Promise<Response | null>>. A null
return means the request path did not match any lure, leaving the caller free
to handle it as appropriate.
With config schema
Pass a Standard Schema-compatible schema to
validate the config block in your .lure files. Any schema library that
implements the Standard Schema spec (Zod, Valibot, Arktype, etc.) will work.
import { createLureHandler } from "@lure-hooks/fetch";
import * as v from "valibot";
const lure = await createLureHandler({
basePath: "/webhooks",
luresDir: "./lures",
configSchema: v.object({
channel: v.string(),
}),
callback: async (prompt, config) => {
await notify(config.channel, prompt);
},
});Options
| Option | Type | Default | Description |
| ----------------- | ---------------------------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------- |
| basePath | string | — | URL path prefix for all lure endpoints |
| luresDir | string | — | Path to the directory containing .lure files |
| 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 |
| configSchema | Standard Schema | — | Schema for validating the config frontmatter block. Informs the type of config in callback |
| maxAttempts | number | 1 | Number of times to attempt callback before dropping the webhook |
| allowUnverified | boolean | true | Whether to allow .lure files without a verify block |
| watch | boolean | false | Watch luresDir for changes and reload lures automatically |
