@neon/skills 1.2.0 → 2.1.0
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/README.md +6 -0
- package/assets/neon-logomark-dark.svg +10 -0
- package/assets/neon-logomark-light.svg +10 -0
- package/package.json +2 -1
- package/plugin.json +27 -2
- package/skills/neon/SKILL.md +201 -217
- package/skills/neon/references/auth.md +12 -0
- package/skills/neon/references/claimable-neon.md +10 -14
- package/skills/neon/references/function-triggers.md +53 -0
- package/skills/neon/references/logs-loki.md +61 -0
- package/skills/neon/references/parse-env.md +32 -0
- package/skills/neon/references/sdk.md +7 -0
- package/skills/neon-ai-gateway/SKILL.md +14 -16
- package/skills/neon-auth/SKILL.md +155 -0
- package/skills/neon-auth/references/managed-auth.md +173 -0
- package/skills/neon-auth/references/self-managed.md +25 -0
- package/skills/neon-functions/SKILL.md +92 -45
- package/skills/neon-functions/references/ai-sdk.md +4 -6
- package/skills/neon-functions/references/function-triggers.md +249 -0
- package/skills/neon-functions/references/mastra-studio.md +1 -1
- package/skills/neon-functions/references/mcp.md +1 -1
- package/skills/neon-functions/references/native-binaries.md +188 -0
- package/skills/neon-functions/references/production-hardening.md +340 -0
- package/skills/neon-object-storage/SKILL.md +10 -11
- package/skills/neon-postgres/SKILL.md +106 -19
- package/skills/neon-postgres/references/lakebase-search-drizzle.md +172 -0
- package/skills/neon-postgres-branches/SKILL.md +3 -3
- package/skills/neon-postgres-egress-optimizer/SKILL.md +1 -1
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# Function Triggers
|
|
2
|
+
|
|
3
|
+
A Function Trigger is a branch-scoped rule that POSTs to a Neon Function so recurring work does not need a separate scheduler. The request is a normal `fetch` invocation: same public URL, same 15-minute time-to-first-byte limit, same injected env (`DATABASE_URL`, …).
|
|
4
|
+
|
|
5
|
+
Same regions as Functions: `aws-us-east-2`, `aws-us-east-1`, `aws-eu-central-1`, and `aws-ap-southeast-1`. Needs Neon CLI 4.21 or newer to declare triggers in `neon.ts`.
|
|
6
|
+
|
|
7
|
+
If `neon deploy` returns 404 `function triggers not available for this project`, the project does not have Function Triggers yet. Deploy the function without applying the trigger (`neon functions deploy <slug> --src <entry>`) and retry `neon deploy` once the project has them.
|
|
8
|
+
|
|
9
|
+
## Supported types
|
|
10
|
+
|
|
11
|
+
`triggers` is a keyed map on `defineConfig`. Types:
|
|
12
|
+
|
|
13
|
+
| `type` | When it fires | `neon.ts` fields | CLI create |
|
|
14
|
+
| ------------------------ | -------------------------------------------------- | ---------------------------------------- | ----------------------------------------------- |
|
|
15
|
+
| `schedule` | On a five-field UTC cron expression | `function`, `cron` | `neon triggers create --cron '…'` |
|
|
16
|
+
| `storage_object_created` | When an object is created in a declared bucket | `function`, `bucket`, optional `prefix` | `neon triggers create --bucket <name>` |
|
|
17
|
+
|
|
18
|
+
`create` takes `--cron` or `--bucket`, not both. `@neon/functions` ≥ 0.11.0: `parseTriggerDelivery` accepts both types; `parseTriggerInvocation` and Hono `parseTrigger(c)` stay schedule-only (`storage_object_created` is `invalid_body` there).
|
|
19
|
+
|
|
20
|
+
## Fields
|
|
21
|
+
|
|
22
|
+
The trigger name is the `neon.ts` map key (CLI `--name`). It must be unique among every trigger visible on the branch, including other functions.
|
|
23
|
+
|
|
24
|
+
| Field | Required | Notes |
|
|
25
|
+
| -------------- | -------- | --------------------------------------------------------------------- |
|
|
26
|
+
| `type` | yes | `"schedule"` or `"storage_object_created"` |
|
|
27
|
+
| `function` | yes | Function slug. REST/MCP: `function_slug` |
|
|
28
|
+
| `cron` | schedule | Five-field UTC expression, e.g. `0 * * * *`, `*/15 * * * *` |
|
|
29
|
+
| `bucket` | storage | Bucket name. REST: `storage_object_created.bucket_name` |
|
|
30
|
+
| `prefix` | no | Object-key prefix filter. REST: `storage_object_created.prefix` |
|
|
31
|
+
| `functionPath` | no | Path on the function. Default `/`. CLI: `--function-path` |
|
|
32
|
+
| `enabled` | no | Default `true`. CLI: `--enabled false` to create disabled |
|
|
33
|
+
|
|
34
|
+
## neon.ts (preferred)
|
|
35
|
+
|
|
36
|
+
Declare `triggers` next to `functions` (and `buckets` when using storage). `neon deploy` applies triggers **after** the functions they target. Triggers that exist remotely but are omitted from `neon.ts` are left alone.
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { defineConfig } from "@neon/config/v1";
|
|
40
|
+
|
|
41
|
+
export default defineConfig({
|
|
42
|
+
functions: {
|
|
43
|
+
ingest: { name: "Object ingest", source: "src/index.ts" },
|
|
44
|
+
cron: { name: "Cron", source: "src/cron.ts" },
|
|
45
|
+
},
|
|
46
|
+
buckets: { assets: { access: "public_read" } },
|
|
47
|
+
triggers: {
|
|
48
|
+
"on-upload": {
|
|
49
|
+
type: "storage_object_created",
|
|
50
|
+
function: "ingest",
|
|
51
|
+
bucket: "assets",
|
|
52
|
+
prefix: "logos/",
|
|
53
|
+
functionPath: "/object",
|
|
54
|
+
},
|
|
55
|
+
"every-minute": {
|
|
56
|
+
type: "schedule",
|
|
57
|
+
function: "cron",
|
|
58
|
+
cron: "* * * * *",
|
|
59
|
+
functionPath: "/cron",
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
neon deploy
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Change the cron string, bucket, or prefix and deploy again to reschedule. Starter: `neon bootstrap --template cron-job`.
|
|
70
|
+
|
|
71
|
+
## CLI
|
|
72
|
+
|
|
73
|
+
Use when you are not applying `neon.ts`, or to list, enable, disable, or delete.
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
neon triggers create --function-slug cron --name hourly --cron '0 * * * *' --function-path /cron
|
|
77
|
+
neon triggers create --function-slug ingest --name on-upload --bucket assets --prefix 'logos/' --function-path /object
|
|
78
|
+
neon triggers list
|
|
79
|
+
neon triggers list --output json
|
|
80
|
+
neon triggers update <id> --branch <branch> --cron '*/30 * * * *'
|
|
81
|
+
neon triggers update <id> --branch <branch> --bucket assets --prefix 'incoming/'
|
|
82
|
+
neon triggers enable <id> --branch <branch>
|
|
83
|
+
neon triggers disable <id> --branch <branch>
|
|
84
|
+
neon triggers delete <id> --branch <branch>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`enable` / `disable` wrap `update --enabled`. Updating the cron recomputes `Next Run At`. Disabling clears `Next Run At`. Alias: `neon trigger`. `--cron` on a storage trigger, or `--bucket` / `--prefix` on a schedule trigger, is rejected.
|
|
88
|
+
|
|
89
|
+
Inspect a trigger with `neon triggers list --output json`. Pass `--branch` on get/update/enable/disable/delete: without it the CLI resolves the trigger id as a branch name.
|
|
90
|
+
|
|
91
|
+
Project and branch otherwise resolve from `--project-id` / `--branch`, then `.neon`, then a single-project auto-detect.
|
|
92
|
+
|
|
93
|
+
## MCP backup
|
|
94
|
+
|
|
95
|
+
The Neon MCP server (`?category=functions`) exposes `list_triggers`, `get_trigger`, `create_trigger`, `update_trigger`, and `delete_trigger`. `branch_id` is a `br-…` id, not a branch name (`list_branches` to resolve). Create a schedule trigger with snake_case:
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"type": "schedule",
|
|
100
|
+
"function_slug": "cron",
|
|
101
|
+
"name": "hourly",
|
|
102
|
+
"function_path": "/cron",
|
|
103
|
+
"schedule": { "cron": "0 * * * *" },
|
|
104
|
+
"enabled": true
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`create_trigger` required fields for schedule: `type`, `function_slug`, `name`, `schedule`. REST is the same payload at `POST /projects/{project_id}/branches/{branch_id}/triggers`. For `storage_object_created`, use CLI or REST with `"type": "storage_object_created"` and `storage_object_created: { "bucket_name": "assets", "prefix": "logos/" }`. CLI docs: https://neon.com/docs/cli/triggers.md.
|
|
109
|
+
|
|
110
|
+
## Delivery payload
|
|
111
|
+
|
|
112
|
+
Neon POSTs JSON. The Functions proxy drops client-supplied `x-neon-*` headers, so a present `x-neon-trigger-invocation-id` is from a trigger delivery. It must match `invocation_id` in the body.
|
|
113
|
+
|
|
114
|
+
A Function that also serves app or public HTTP must not apply JWT or `X-Secret` middleware to the trigger path. Neon trigger POSTs do not send those. Caller shapes: [production-hardening.md](production-hardening.md).
|
|
115
|
+
|
|
116
|
+
Schedule wire JSON (snake_case):
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"version": 1,
|
|
121
|
+
"invocation_id": "…",
|
|
122
|
+
"trigger": {
|
|
123
|
+
"type": "schedule",
|
|
124
|
+
"id": "trigger-…",
|
|
125
|
+
"name": "hourly"
|
|
126
|
+
},
|
|
127
|
+
"data": { "scheduled_at": "2026-09-15T23:35:00Z" }
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Storage-object-created wire JSON:
|
|
132
|
+
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"version": 1,
|
|
136
|
+
"invocation_id": "…",
|
|
137
|
+
"trigger": {
|
|
138
|
+
"type": "storage_object_created",
|
|
139
|
+
"id": "trigger-…",
|
|
140
|
+
"name": "on-upload"
|
|
141
|
+
},
|
|
142
|
+
"data": { "bucket_name": "uploads", "object_key": "smoke.txt" }
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Parsed (`@neon/functions` ≥ 0.11.0) is camelCase. `parseTriggerDelivery` also sets a top-level `type`. Schedule: `data.scheduledAt`. Storage: `data.bucketName`, `data.objectKey`. Narrow on `invocation.type` (or `isScheduleTriggerInvocation` / `isStorageObjectCreatedTriggerInvocation`) before reading `data` — a check on `trigger.type` does not narrow the sibling `data` field.
|
|
147
|
+
|
|
148
|
+
### `parseTriggerDelivery` (both types)
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
import { parseTriggerDelivery } from "@neon/functions/triggers";
|
|
152
|
+
|
|
153
|
+
export default {
|
|
154
|
+
async fetch(request: Request): Promise<Response> {
|
|
155
|
+
const parsed = await parseTriggerDelivery(request);
|
|
156
|
+
if (!parsed.ok) {
|
|
157
|
+
const status = parsed.error === "invalid_body" ? 400 : 401;
|
|
158
|
+
return new Response(parsed.error, { status });
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const invocation = parsed.invocation;
|
|
162
|
+
if (invocation.type === "storage_object_created") {
|
|
163
|
+
return Response.json({
|
|
164
|
+
bucketName: invocation.data.bucketName,
|
|
165
|
+
objectKey: invocation.data.objectKey,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return Response.json({
|
|
170
|
+
scheduledAt: invocation.data.scheduledAt,
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
`parseTriggerDelivery(request)` clones the Request before `json()`, so `request.json()` still works. If you already have the body: `parseTriggerDelivery({ headers, body })` (sync). `parsed.error` is `missing_header`, `invalid_body`, or `invocation_id_mismatch`. Unknown `trigger.type` values fail as `invalid_body`.
|
|
177
|
+
|
|
178
|
+
Hono: `parseTriggerDelivery(c.req.raw)`.
|
|
179
|
+
|
|
180
|
+
### `parseTrigger` (Hono, schedule only)
|
|
181
|
+
|
|
182
|
+
Throws `HTTPException`. `c.req.json()` still works afterwards. Returns `ScheduleTriggerInvocation`. A `storage_object_created` delivery is `invalid_body`.
|
|
183
|
+
|
|
184
|
+
| Failure | Status | Message |
|
|
185
|
+
| ------------------------ | ------ | --------------------------------------------- |
|
|
186
|
+
| missing header | 401 | `Missing x-neon-trigger-invocation-id header` |
|
|
187
|
+
| header ≠ `invocation_id` | 401 | `Invocation id mismatch` |
|
|
188
|
+
| invalid JSON or payload | 400 | `Invalid trigger payload` |
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
import { parseTrigger } from "@neon/functions/hono";
|
|
192
|
+
|
|
193
|
+
app.post("/cron", async (c) => {
|
|
194
|
+
const invocation = await parseTrigger(c);
|
|
195
|
+
return c.json({ ok: true, invocationId: invocation.invocationId });
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### `parseTriggerInvocation` (`fetch`, schedule only)
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
import { parseTriggerInvocation } from "@neon/functions/triggers";
|
|
203
|
+
|
|
204
|
+
export default {
|
|
205
|
+
async fetch(request: Request): Promise<Response> {
|
|
206
|
+
const parsed = await parseTriggerInvocation(request);
|
|
207
|
+
if (!parsed.ok) {
|
|
208
|
+
const status = parsed.error === "invalid_body" ? 400 : 401;
|
|
209
|
+
return new Response(parsed.error, { status });
|
|
210
|
+
}
|
|
211
|
+
return Response.json({
|
|
212
|
+
ok: true,
|
|
213
|
+
invocationId: parsed.invocation.invocationId,
|
|
214
|
+
});
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Local `neon dev`
|
|
220
|
+
|
|
221
|
+
`neon dev` forwards `x-neon-trigger-invocation-id`, so you can simulate a tick:
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
curl -X POST http://localhost:8787/cron \
|
|
225
|
+
-H 'content-type: application/json' \
|
|
226
|
+
-H 'x-neon-trigger-invocation-id: local-dev' \
|
|
227
|
+
-d '{
|
|
228
|
+
"version": 1,
|
|
229
|
+
"invocation_id": "local-dev",
|
|
230
|
+
"trigger": { "type": "schedule", "id": "trigger-local", "name": "hourly" },
|
|
231
|
+
"data": { "scheduled_at": "2026-09-15T00:00:00Z" }
|
|
232
|
+
}'
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
A public POST to the **deployed** function that includes that header still returns 401: the proxy strips client `x-neon-*` headers.
|
|
236
|
+
|
|
237
|
+
## Inheritance
|
|
238
|
+
|
|
239
|
+
Triggers are branch-scoped. A trigger created on a parent is visible on children (`inherited: true`, `source_branch_id` points at the origin) and starts disabled there.
|
|
240
|
+
|
|
241
|
+
`neon deploy` of a `neon.ts` that declares the same trigger (default `enabled: true`) enables that inherited copy on the child. Omit it from `neon.ts` to leave the inherited trigger disabled. Enable without applying `neon.ts` with `neon triggers enable <id> --branch <branch>`.
|
|
242
|
+
|
|
243
|
+
## Logs
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
neon logs query --source function --since 1h
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Pass `--branch` when the function is not on the branch in `.neon`.
|
|
@@ -6,7 +6,7 @@ The shape mirrors any other Node integration (see [sentry.md](sentry.md)): insta
|
|
|
6
6
|
|
|
7
7
|
## 1. Define the agent against the Neon AI Gateway
|
|
8
8
|
|
|
9
|
-
With `@mastra/core` 1.47+, use a `neon/<model>` magic string — Mastra reads `NEON_AI_GATEWAY_BASE_URL` and `NEON_AI_GATEWAY_TOKEN` from the environment (injected by `neon deploy` / `neon env pull` when `
|
|
9
|
+
With `@mastra/core` 1.47+, use a `neon/<model>` magic string — Mastra reads `NEON_AI_GATEWAY_BASE_URL` and `NEON_AI_GATEWAY_TOKEN` from the environment (injected by `neon deploy` / `neon env pull` when `aiGateway` is enabled in `neon.ts`). No manual `url`/`apiKey` or MLflow dialect swap is needed; Mastra routes each model to the correct gateway endpoint.
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
12
|
// src/mastra/agents/pricing.ts
|
|
@@ -89,7 +89,7 @@ Key points:
|
|
|
89
89
|
> [!WARNING]
|
|
90
90
|
> A Neon Function has a **public HTTPS URL — anyone can reach it.** An unauthenticated MCP server hands every caller your tools (and the database behind them). Authenticate at the top of the handler before touching the transport, exactly as for [any client-facing function](../SKILL.md#functions-as-an-agent-backend-nextjs-and-similar-frameworks).
|
|
91
91
|
|
|
92
|
-
[Better Auth](https://better-auth.com)
|
|
92
|
+
[Better Auth](https://better-auth.com) covers both common MCP shapes when you need an OAuth authorization server or API keys. Managed Auth does not. Keep existing app login (Clerk, Managed Auth, or Better Auth) unless the user asked to migrate it. Confirm the **installed** Better Auth version before copying imports: the MCP plugin is moving out of `better-auth/plugins` into `@better-auth/mcp` (`withMcpAuth` → `requireMcpAuth`, `createMcpAuthClient` → `createMcpResourceClient`). Docs: https://better-auth.com/docs/plugins/mcp
|
|
93
93
|
|
|
94
94
|
### Option 1 — OAuth via the Better Auth MCP plugin (best for third-party clients)
|
|
95
95
|
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# Shipping native binaries with a Function
|
|
2
|
+
|
|
3
|
+
The default deploy bundles `source` into a single `index.mjs` with esbuild. A compiled binary cannot be inlined into that file, so it has to ship as a separate file in the deploy archive. There are three ways to put it there. Pick by what the binary is:
|
|
4
|
+
|
|
5
|
+
| The binary is | Use |
|
|
6
|
+
| ------------------------------------------------------------------------------------------ | -------------------------------------------------------------- |
|
|
7
|
+
| An npm package backed by a Node-API addon (`sharp`, most `@napi-rs/*` packages) | [`externalPackages`](#externalpackages-npm-packages-with-a-node-addon) |
|
|
8
|
+
| A file your own build step produces: a `.node` addon, a `.so`, a `.wasm`, model weights | [`bundler: "none"`](#bundler-none-ship-a-prebuilt-directory) or a [custom `bundler`](#custom-bundler-return-the-file-map) |
|
|
9
|
+
| A standalone executable you spawn (`ffmpeg`, a Go or Rust CLI) | A custom `bundler` or `"none"`, plus [a copy to `/run` at startup](#standalone-executables) |
|
|
10
|
+
|
|
11
|
+
The examples use top-level `functions`, which needs `neon` CLI 4.20 or newer and `@neon/config` 1.6 or newer.
|
|
12
|
+
|
|
13
|
+
## The runtime a binary lands on
|
|
14
|
+
|
|
15
|
+
- **linux, arm64, glibc**, Node.js 24. A binary built for macOS or x64 cannot load there.
|
|
16
|
+
- The archive is extracted to `/opt/function`, a read-only filesystem. `import.meta.url` in the root `index.mjs` points there, so `new URL("./bin/tool", import.meta.url)` resolves to `/opt/function/bin/tool`.
|
|
17
|
+
- **Every file arrives with mode `644`.** Unix permission bits in the zip are dropped on extraction, and `chmod` in place fails with `EROFS`. A `.node` or `.so` loads fine (it is `dlopen`ed, not executed). Spawning a file from `/opt/function` fails with `EACCES`.
|
|
18
|
+
- `/tmp` is writable and mounted `noexec`: a copied binary still fails with `EACCES` after `chmod 755`.
|
|
19
|
+
- `/run` is a writable tmpfs that allows exec (about 990 MiB, backed by the function's 2048 MiB of memory).
|
|
20
|
+
|
|
21
|
+
The filesystem layout is observed behavior, not documented by Neon. Re-check it if spawning starts failing.
|
|
22
|
+
|
|
23
|
+
## `externalPackages`: npm packages with a Node addon
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
// neon.ts
|
|
27
|
+
import { defineConfig } from "@neon/config/v1";
|
|
28
|
+
|
|
29
|
+
export default defineConfig({
|
|
30
|
+
functions: {
|
|
31
|
+
resize: {
|
|
32
|
+
name: "Resize",
|
|
33
|
+
source: "./src/resize.ts",
|
|
34
|
+
externalPackages: ["sharp"],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
esbuild leaves `import sharp from "sharp"` unresolved. At deploy, the CLI installs the version of `sharp` from your project with `npm install --cpu=arm64 --os=linux --libc=glibc --ignore-scripts` into a temp directory, traces the files it reaches with `@vercel/nft`, and copies them into the archive under `node_modules/` with the tree layout intact. Only the installed version is read from your `node_modules`; the shipped files come from the temp install, and your `node_modules` is not modified.
|
|
41
|
+
|
|
42
|
+
The deploy fails with a named error when:
|
|
43
|
+
|
|
44
|
+
- the package is not installed in your project (no version to pin)
|
|
45
|
+
- the declared package itself does not install for linux-arm64 glibc (`EBADPLATFORM`)
|
|
46
|
+
- a staged `.node` or `.so` is not an AArch64 ELF binary
|
|
47
|
+
- `npm` is not on `PATH`
|
|
48
|
+
- the archive exceeds the [size limits](#size-limits)
|
|
49
|
+
|
|
50
|
+
It does not fail when a platform-specific optional dependency is silently skipped, or when a package that compiles from source at install time ships no binary (the staging install runs with `--ignore-scripts`). Those deploy and then fail at invoke. Use packages that publish a linux-arm64 glibc prebuild (`sharp` does), and invoke the deployed function once to confirm the addon loads.
|
|
51
|
+
|
|
52
|
+
A deploy and `neon dev` print an advisory warning for any bundled package that carries native code and is not declared. A package with a working JavaScript fallback (`ws` with `bufferutil`) triggers it too and needs no change. Do not silence it with `{ name, includeFiles: false }`: that externalizes the package and ships nothing, so a reached import throws `Cannot find module` on every invoke. `includeFiles: false` is only for an import the function never evaluates.
|
|
53
|
+
|
|
54
|
+
Under `neon dev`, the package is only kept out of the bundle and resolves from your own `node_modules` for your host.
|
|
55
|
+
|
|
56
|
+
Pros: one line in `neon.ts`; the target-platform install, file tracing, arch check, and size check are automatic; local dev uses your host build.
|
|
57
|
+
|
|
58
|
+
Cons: only for npm packages that publish a linux-arm64 glibc prebuild; transitive pins, overrides, and patches from your lockfile are not carried into the staged install; esbuild bundler only (`externalPackages` with `bundler: "none"` or a function fails validation).
|
|
59
|
+
|
|
60
|
+
## `bundler: "none"`: ship a prebuilt directory
|
|
61
|
+
|
|
62
|
+
Run your own build, then point `source` at its output. The directory root must contain `index.mjs` or `index.js`. Everything else in the directory ships as-is:
|
|
63
|
+
|
|
64
|
+
```text
|
|
65
|
+
dist/fn/
|
|
66
|
+
index.mjs # built by your step, reads ./native/addon.node
|
|
67
|
+
native/addon.node
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
// neon.ts
|
|
72
|
+
import { defineConfig } from "@neon/config/v1";
|
|
73
|
+
|
|
74
|
+
export default defineConfig({
|
|
75
|
+
functions: {
|
|
76
|
+
api: { name: "API", source: "./dist/fn", bundler: "none" },
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npm run build:fn && neon deploy --env .env.local
|
|
83
|
+
neon functions deploy api --src dist/fn --no-bundle # same thing, without neon.ts
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`neon deploy` does not run your build step. Run it first, or use a [custom `bundler`](#custom-bundler-return-the-file-map) to keep the build inside `neon deploy`.
|
|
87
|
+
|
|
88
|
+
Pros: works with any build tool or framework output (`.mastra/output` is the common one); full control over the archive layout.
|
|
89
|
+
|
|
90
|
+
Cons: no architecture check, so a binary built for your laptop deploys and then fails at invoke; the build step is yours to keep in sync with `neon deploy`; TypeScript cannot ship unbundled.
|
|
91
|
+
|
|
92
|
+
## Custom `bundler`: return the file map
|
|
93
|
+
|
|
94
|
+
An inline function in `neon.ts` returns archive paths mapped to bytes. `neon deploy` zips the map, and `neon dev` serves the same map locally:
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
// neon.ts
|
|
98
|
+
import { readFile } from "node:fs/promises";
|
|
99
|
+
import { build } from "esbuild";
|
|
100
|
+
import { defineConfig } from "@neon/config/v1";
|
|
101
|
+
|
|
102
|
+
export default defineConfig({
|
|
103
|
+
functions: {
|
|
104
|
+
transcode: {
|
|
105
|
+
name: "Transcode",
|
|
106
|
+
source: "./src/transcode.ts",
|
|
107
|
+
bundler: async (fn) => {
|
|
108
|
+
const out = await build({
|
|
109
|
+
entryPoints: [fn.source],
|
|
110
|
+
bundle: true,
|
|
111
|
+
platform: "node",
|
|
112
|
+
format: "esm",
|
|
113
|
+
write: false,
|
|
114
|
+
outfile: "index.mjs",
|
|
115
|
+
// CommonJS dependencies call require(); ESM output has none in scope.
|
|
116
|
+
banner: {
|
|
117
|
+
js: "import{createRequire}from'module';const require=createRequire(import.meta.url);",
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
return {
|
|
121
|
+
"index.mjs": out.outputFiles[0].contents,
|
|
122
|
+
"bin/ffmpeg": new Uint8Array(
|
|
123
|
+
await readFile(new URL("./vendor/linux-arm64/ffmpeg", import.meta.url)),
|
|
124
|
+
),
|
|
125
|
+
};
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
`esbuild` must be a dependency of your project. The map needs `index.mjs` or `index.js` at the root.
|
|
133
|
+
|
|
134
|
+
Pros: the build lives in `neon.ts`, so `neon deploy` and `neon dev` always build the same thing; any file from anywhere can go in the archive.
|
|
135
|
+
|
|
136
|
+
Cons: no architecture check; `externalPackages` cannot be combined with it, so an npm addon has to be copied into the map by hand, with its `node_modules/` layout.
|
|
137
|
+
|
|
138
|
+
## Standalone executables
|
|
139
|
+
|
|
140
|
+
Ship the executable with a custom `bundler` or `bundler: "none"`, then copy it to `/run` and mark it executable once per isolate:
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
// src/transcode.ts
|
|
144
|
+
import { execFile } from "node:child_process";
|
|
145
|
+
import { chmod, copyFile, mkdir } from "node:fs/promises";
|
|
146
|
+
import { promisify } from "node:util";
|
|
147
|
+
|
|
148
|
+
const run = promisify(execFile);
|
|
149
|
+
|
|
150
|
+
let ffmpeg: Promise<string> | undefined;
|
|
151
|
+
function ffmpegPath(): Promise<string> {
|
|
152
|
+
if (process.env.FFMPEG_PATH) return Promise.resolve(process.env.FFMPEG_PATH);
|
|
153
|
+
ffmpeg ??= (async () => {
|
|
154
|
+
await mkdir("/run/bin", { recursive: true });
|
|
155
|
+
await copyFile(new URL("./bin/ffmpeg", import.meta.url), "/run/bin/ffmpeg");
|
|
156
|
+
await chmod("/run/bin/ffmpeg", 0o755);
|
|
157
|
+
return "/run/bin/ffmpeg";
|
|
158
|
+
})();
|
|
159
|
+
return ffmpeg;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export default {
|
|
163
|
+
async fetch() {
|
|
164
|
+
const { stdout } = await run(await ffmpegPath(), ["-version"]);
|
|
165
|
+
return new Response(stdout);
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
`neon dev` runs this code on your machine, where `/run` may not exist and a linux-arm64 binary cannot execute. Point it at a host install from the shell, and leave `FFMPEG_PATH` out of the function's deployed `env`:
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
FFMPEG_PATH="$(command -v ffmpeg)" neon dev
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
The binary must be statically linked, or its shared libraries must exist in the runtime image. The copy costs memory: `/run` is RAM-backed and counts against the function's 2048 MiB.
|
|
177
|
+
|
|
178
|
+
## Size limits
|
|
179
|
+
|
|
180
|
+
`bundler: "none"`, a custom `bundler`, and `externalPackages` staging check the archive before upload:
|
|
181
|
+
|
|
182
|
+
| Limit | Value |
|
|
183
|
+
| ------------------------ | ------- |
|
|
184
|
+
| Compressed zip | 10 MiB |
|
|
185
|
+
| Total uncompressed bytes | 64 MiB |
|
|
186
|
+
| Files in the archive | 4,096 |
|
|
187
|
+
|
|
188
|
+
Exceeding one fails the deploy. The byte-limit errors list the four largest files. Check an executable's size before building around it: a single static binary can use most of the 64 MiB.
|