@vite-hub/webhooks 0.0.0-stage → 0.3.1

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.
@@ -0,0 +1,171 @@
1
+ import { t as webhooksErrors } from "./errors-DtL3aUWW.js";
2
+ import { t as webhooksTableNames } from "./table-names-DVvicXhh.js";
3
+ import { and, asc, desc, eq, lt, or, sql } from "drizzle-orm";
4
+ import { index, integer, sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core";
5
+ /**
6
+ * One row for each delivery. A debounced webhook keeps one `pending` row for each `(webhook, key)`: each send replaces
7
+ * its `body`, raises `revision` and `count`, and moves `due_at`. Times are milliseconds since the epoch.
8
+ */
9
+ const webhookDeliveries = sqliteTable("vitehub_webhook_deliveries", {
10
+ id: text("id").primaryKey(),
11
+ webhook: text("webhook").notNull(),
12
+ /** The debounce key. `null` for a webhook without a debounce and for a redelivery: those rows never collapse. */
13
+ key: text("key"),
14
+ event: text("event").notNull(),
15
+ /** The JSON text that the receiver gets, byte for byte. */
16
+ body: text("body").notNull(),
17
+ revision: integer("revision").notNull(),
18
+ /** How many sends this delivery collapses. The receiver gets it in `x-vitehub-events`. */
19
+ count: integer("count").notNull(),
20
+ state: text("state", { enum: [
21
+ "pending",
22
+ "sending",
23
+ "sent",
24
+ "dead",
25
+ "cancelled"
26
+ ] }).notNull(),
27
+ attempts: integer("attempts").notNull(),
28
+ lastStatus: integer("last_status"),
29
+ lastError: text("last_error"),
30
+ dueAt: integer("due_at").notNull(),
31
+ createdAt: integer("created_at").notNull(),
32
+ updatedAt: integer("updated_at").notNull(),
33
+ sentAt: integer("sent_at")
34
+ }, (table) => [
35
+ uniqueIndex("vitehub_webhook_deliveries_pending").on(table.webhook, table.key).where(sql`state = 'pending'`),
36
+ index("vitehub_webhook_deliveries_webhook").on(table.webhook, table.createdAt),
37
+ index("vitehub_webhook_deliveries_state").on(table.state, table.dueAt)
38
+ ]);
39
+ /** The table of Webhooks, for `defineDatabase({ schema })` or a Database contribution. */
40
+ const webhooksSchema = { webhookDeliveries };
41
+ /** `webhooksSchema` as SQLite statements that are safe to run on every start. */
42
+ const webhooksTables = [
43
+ "CREATE TABLE IF NOT EXISTS `vitehub_webhook_deliveries` (`id` text PRIMARY KEY NOT NULL, `webhook` text NOT NULL, `key` text, `event` text NOT NULL, `body` text NOT NULL, `revision` integer NOT NULL, `count` integer NOT NULL, `state` text NOT NULL, `attempts` integer NOT NULL, `last_status` integer, `last_error` text, `due_at` integer NOT NULL, `created_at` integer NOT NULL, `updated_at` integer NOT NULL, `sent_at` integer)",
44
+ "CREATE UNIQUE INDEX IF NOT EXISTS `vitehub_webhook_deliveries_pending` ON `vitehub_webhook_deliveries` (`webhook`,`key`) WHERE state = 'pending'",
45
+ "CREATE INDEX IF NOT EXISTS `vitehub_webhook_deliveries_webhook` ON `vitehub_webhook_deliveries` (`webhook`,`created_at`)",
46
+ "CREATE INDEX IF NOT EXISTS `vitehub_webhook_deliveries_state` ON `vitehub_webhook_deliveries` (`state`,`due_at`)"
47
+ ];
48
+ function toDelivery(row) {
49
+ return {
50
+ ...row,
51
+ body: JSON.parse(row.body)
52
+ };
53
+ }
54
+ async function guarded(action, run) {
55
+ try {
56
+ return await run();
57
+ } catch (cause) {
58
+ if (webhooksErrors.is(cause)) throw cause;
59
+ throw webhooksErrors.WEBHOOKS_STORE_FAILED({
60
+ action,
61
+ cause
62
+ });
63
+ }
64
+ }
65
+ /**
66
+ * Deliveries in a Drizzle SQLite Database. Pass a function when the Database connects per request, as D1 does on
67
+ * Cloudflare.
68
+ */
69
+ function createDrizzleWebhookStore(database) {
70
+ const db = typeof database === "function" ? database : () => database;
71
+ const t = webhookDeliveries;
72
+ return {
73
+ record: (send) => guarded("store a delivery", async () => {
74
+ const insert = db().insert(t).values({
75
+ id: send.id,
76
+ webhook: send.webhook,
77
+ key: send.key,
78
+ event: send.event,
79
+ body: send.body,
80
+ revision: 1,
81
+ count: send.count ?? 1,
82
+ state: "pending",
83
+ attempts: 0,
84
+ dueAt: send.dueAt,
85
+ createdAt: send.now,
86
+ updatedAt: send.now
87
+ });
88
+ const [row] = send.key === null ? await insert.returning({
89
+ id: t.id,
90
+ revision: t.revision,
91
+ count: t.count
92
+ }) : await insert.onConflictDoUpdate({
93
+ target: [t.webhook, t.key],
94
+ targetWhere: sql`state = 'pending'`,
95
+ set: {
96
+ body: sql`excluded.body`,
97
+ event: sql`excluded.event`,
98
+ dueAt: sql`excluded.due_at`,
99
+ updatedAt: sql`excluded.updated_at`,
100
+ revision: sql`${t.revision} + 1`,
101
+ count: sql`${t.count} + 1`,
102
+ attempts: 0
103
+ }
104
+ }).returning({
105
+ id: t.id,
106
+ revision: t.revision,
107
+ count: t.count
108
+ });
109
+ if (!row) throw webhooksErrors.WEBHOOKS_STORE_FAILED({ action: "store a delivery" });
110
+ return row;
111
+ }),
112
+ get: (id) => guarded("read a delivery", async () => {
113
+ const [row] = await db().select().from(t).where(eq(t.id, id)).limit(1);
114
+ return row ? toDelivery(row) : void 0;
115
+ }),
116
+ list: (options = {}) => guarded("list deliveries", async () => {
117
+ const limit = Math.min(Math.max(options.limit ?? 100, 1), 500);
118
+ const { before } = options;
119
+ const where = and(options.webhook ? eq(t.webhook, options.webhook) : void 0, options.state ? eq(t.state, options.state) : void 0, before ? or(lt(t.createdAt, before.createdAt), and(eq(t.createdAt, before.createdAt), lt(t.id, before.id))) : void 0);
120
+ return (await db().select().from(t).where(where).orderBy(desc(t.createdAt), desc(t.id)).limit(limit)).map(toDelivery);
121
+ }),
122
+ pending: (options = {}) => guarded("list pending deliveries", async () => {
123
+ const limit = Math.min(Math.max(options.limit ?? 100, 1), 500);
124
+ return (await db().select().from(t).where(and(eq(t.state, "pending"), options.webhook ? eq(t.webhook, options.webhook) : void 0)).orderBy(asc(t.dueAt), asc(t.id)).limit(limit)).map(toDelivery);
125
+ }),
126
+ claim: (id, revision, now, staleBefore) => guarded("claim a delivery", async () => {
127
+ const [row] = await db().update(t).set({
128
+ state: "sending",
129
+ attempts: sql`${t.attempts} + 1`,
130
+ updatedAt: now
131
+ }).where(and(eq(t.id, id), eq(t.revision, revision), or(eq(t.state, "pending"), and(eq(t.state, "sending"), lt(t.updatedAt, staleBefore))))).returning();
132
+ return row ? toDelivery(row) : void 0;
133
+ }),
134
+ sent: (claim, result, now) => guarded("mark a delivery sent", async () => {
135
+ await db().update(t).set({
136
+ state: "sent",
137
+ lastStatus: result.status,
138
+ lastError: null,
139
+ sentAt: now,
140
+ updatedAt: now
141
+ }).where(and(eq(t.id, claim.id), eq(t.state, "sending"), eq(t.attempts, claim.attempts)));
142
+ }),
143
+ failed: (claim, result, now, dead) => guarded("mark a failed attempt", async () => {
144
+ const next = dead ? sql`'dead'` : sql`CASE WHEN ${t.key} IS NOT NULL AND EXISTS (SELECT 1 FROM vitehub_webhook_deliveries AS newer WHERE newer.webhook = ${t.webhook} AND newer.key = ${t.key} AND newer.state = 'pending') THEN 'cancelled' ELSE 'pending' END`;
145
+ const [row] = await db().update(t).set({
146
+ state: next,
147
+ lastStatus: result.status,
148
+ lastError: result.error,
149
+ updatedAt: now
150
+ }).where(and(eq(t.id, claim.id), eq(t.state, "sending"), eq(t.attempts, claim.attempts))).returning({ state: t.state });
151
+ if (row?.state === "cancelled") await db().update(t).set({ count: sql`${t.count} + ${claim.count}` }).where(and(eq(t.webhook, claim.webhook), eq(t.key, claim.key ?? ""), eq(t.state, "pending")));
152
+ return row?.state;
153
+ }),
154
+ due: (id, now) => guarded("flush a delivery", async () => {
155
+ const [row] = await db().update(t).set({
156
+ dueAt: now,
157
+ updatedAt: now
158
+ }).where(and(eq(t.id, id), eq(t.state, "pending"))).returning();
159
+ return row ? toDelivery(row) : void 0;
160
+ }),
161
+ cancel: (id, now) => guarded("cancel a delivery", async () => {
162
+ const [row] = await db().update(t).set({
163
+ state: "cancelled",
164
+ updatedAt: now
165
+ }).where(and(eq(t.id, id), eq(t.state, "pending"))).returning();
166
+ return row ? toDelivery(row) : void 0;
167
+ })
168
+ };
169
+ }
170
+ //#endregion
171
+ export { createDrizzleWebhookStore, webhookDeliveries, webhooksSchema, webhooksTableNames, webhooksTables };
@@ -0,0 +1,81 @@
1
+ import { defineErrors } from "@vite-hub/runtime";
2
+ //#region src/errors.ts
3
+ const webhooksErrors = /*#__PURE__*/ defineErrors({
4
+ docs: "https://vitehub.dev/docs/webhooks/diagnostics",
5
+ codes: {
6
+ WEBHOOKS_DATABASE_OFF: {
7
+ why: ({ files }) => `Webhooks keeps each delivery in the Database, but the app has no Database. These files define webhooks: ${files}.`,
8
+ fix: "Turn on `database` in `vitehub()`, or remove the files of `server/webhooks/`."
9
+ },
10
+ WEBHOOKS_DEBOUNCE_TOO_LONG: {
11
+ why: ({ debounce }) => `The debounce ${debounce} is longer than 24 hours. Cloudflare Queues delays a message at most 24 hours, and a webhook must work on every host.`,
12
+ fix: "Set `debounce` to 24 hours or less, such as `\"30 minutes\"`."
13
+ },
14
+ WEBHOOKS_DEFINITION_INVALID: {
15
+ why: ({ message }) => message,
16
+ fix: "Default-export `defineWebhook({ url: \"T3_WEBHOOK_URL\", secret: \"T3_WEBHOOK_SECRET\" })` from each file of `server/webhooks/`. `url` and `secret` are names of server variables, `signature` is `\"github\"` or `\"stripe\"`, and `debounce` is a duration such as `\"30 minutes\"`."
17
+ },
18
+ WEBHOOKS_FILE_INVALID: {
19
+ why: ({ message }) => message,
20
+ fix: "Name each file of `server/webhooks/` with lowercase letters, digits, and dashes, such as `t3.ts` or `slack-alerts.ts`, and keep one file for each webhook name."
21
+ },
22
+ WEBHOOKS_NOT_FOUND: {
23
+ why: ({ name }) => `No webhook is named ${name}.`,
24
+ fix: "Add `server/webhooks/<name>.ts` with `export default defineWebhook({ ... })`, or pass the name of a file that exists. The generated types list every name."
25
+ },
26
+ WEBHOOKS_NOT_INSTALLED: {
27
+ why: "Webhooks is not running in this server. The app has no `server/webhooks/` files, or the code runs outside the ViteHub server.",
28
+ fix: "Add `server/webhooks/<name>.ts` with `defineWebhook()`, turn on `queue` and `database` in `vitehub()`, and call `sendWebhook()` from server code. In a test, call `installWebhooks()` from `@vite-hub/webhooks/runtime` first."
29
+ },
30
+ WEBHOOKS_QUEUE_OFF: {
31
+ why: ({ files }) => `Webhooks sends each delivery through the Queue, but the app has no Queue. These files define webhooks: ${files}.`,
32
+ fix: "Turn on `queue` in `vitehub()`, or remove the files of `server/webhooks/`."
33
+ },
34
+ WEBHOOKS_BODY_INVALID: {
35
+ why: ({ webhook }) => `The body for the webhook ${webhook} is not JSON data.`,
36
+ fix: "Pass a plain object, an array, a string, a number, a boolean, or `null`. Convert a `Date` to an ISO string and a `bigint` to a string first."
37
+ },
38
+ WEBHOOKS_DATABASE_MISSING: {
39
+ why: "Webhooks has no Database in this server.",
40
+ fix: "Turn on `database` in `vitehub()` and add the Default Database."
41
+ },
42
+ WEBHOOKS_DELIVERY_ACTIVE: {
43
+ why: ({ id, state }) => `The delivery ${id} is ${state}, so it cannot be delivered again yet.`,
44
+ fix: "Wait until the delivery is sent, dead, or cancelled. To send a pending delivery now, flush it."
45
+ },
46
+ WEBHOOKS_DELIVERY_FAILED: {
47
+ why: ({ reason, webhook }) => `The webhook ${webhook} was not delivered: ${reason}.`,
48
+ fix: "Check that the receiver is up and answers with a 2xx status within 10 seconds. The Queue tries the delivery again, and `last_error` of the delivery shows the last failure."
49
+ },
50
+ WEBHOOKS_DELIVERY_NOT_FOUND: {
51
+ why: ({ id }) => `No webhook delivery has the id ${id}.`,
52
+ fix: "Pass the id of a delivery that `listWebhookDeliveries()` returns."
53
+ },
54
+ WEBHOOKS_DELIVERY_NOT_PENDING: {
55
+ why: ({ id, state }) => `The delivery ${id} is ${state}, not pending.`,
56
+ fix: "Flush or cancel only a pending delivery. To send a sent, dead, or cancelled delivery again, redeliver it."
57
+ },
58
+ WEBHOOKS_SECRET_UNSET: {
59
+ why: ({ name, webhook }) => `The webhook ${webhook} signs each delivery with the secret in \`${name}\`, but this server has no value for it.`,
60
+ fix: "Set the variable to the signing secret that the receiver checks: in `.env` for `vite dev`, and as a secret on the host for production."
61
+ },
62
+ WEBHOOKS_STORE_FAILED: {
63
+ why: ({ action }) => `Webhooks could not ${action} in the Database.`,
64
+ fix: "Apply the Webhooks table with `vitehub database generate` and `vitehub database migrate`. `error.cause` holds the Database error."
65
+ },
66
+ WEBHOOKS_URL_INVALID: {
67
+ why: ({ name, webhook }) => `The webhook ${webhook} reads its URL from \`${name}\`, but the value is not an http or https URL.`,
68
+ fix: "Set the variable to the full URL of the receiver, such as `https://example.com/hooks/vitehub`."
69
+ },
70
+ WEBHOOKS_URL_UNSET: {
71
+ why: ({ name, webhook }) => `The webhook ${webhook} reads its URL from \`${name}\`, but this server has no value for it.`,
72
+ fix: "Set the variable to the URL of the receiver: in `.env` for `vite dev`, and as a secret on the host for production. Keep it secret when the URL holds a token."
73
+ },
74
+ WEBHOOKS_WAKE_FAILED: {
75
+ why: ({ webhook }) => `The delivery of the webhook ${webhook} is stored, but the Queue did not accept its job.`,
76
+ fix: "Read `error.cause` for the Queue error. Flush the pending delivery when the Queue is available again."
77
+ }
78
+ }
79
+ });
80
+ //#endregion
81
+ export { webhooksErrors as t };
@@ -0,0 +1,35 @@
1
+ import { C as WebhookDefinition, D as SendWebhookErrorCode, E as defineWebhook, O as WebhookDeliveryErrorCode, T as WebhookSignature, r as SendWebhookResult, w as WebhookOptions } from "./runtime-B6NDYh0C.js";
2
+ import { Result } from "@vite-hub/runtime";
3
+ //#region src/index.d.ts
4
+ /** The webhooks of `server/webhooks/`. The generated `.vitehub/webhooks.d.ts` adds one key for each file. */
5
+ export interface WebhookRegistry {}
6
+ /** The name of a webhook of `server/webhooks/`. */
7
+ export type WebhookName = Extract<keyof WebhookRegistry, string>;
8
+ /** Options of `sendWebhook()`. */
9
+ export interface SendWebhookOptions {
10
+ /** A label for the receiver, sent as `x-vitehub-event`, such as `"comments.comment"`. */
11
+ event: string;
12
+ /**
13
+ * Sends with the same key collapse into one delivery while the debounce waits. Default: the webhook name, so all sends
14
+ * of the webhook collapse. A webhook without `debounce` ignores it.
15
+ */
16
+ key?: string;
17
+ }
18
+ /**
19
+ * Sends `body` as JSON to the webhook `name` of `server/webhooks/<name>.ts`, signed with its secret, and returns
20
+ * `[error, { id, status }]`. The delivery waits in the Database and goes out through the Queue, so it survives a restart
21
+ * and the Queue retries it. With `debounce`, it waits until no send came for that long, then delivers the last body
22
+ * once, with `x-vitehub-events` set to the number of sends.
23
+ *
24
+ * A missing variable, a body that is not JSON, or a Database or Queue failure comes back as the error. An unknown name
25
+ * throws.
26
+ *
27
+ * ```ts
28
+ * import { sendWebhook } from "@vite-hub/webhooks"
29
+ *
30
+ * const [error] = await sendWebhook("t3", { thread: thread.id }, { event: "comments.comment" })
31
+ * ```
32
+ */
33
+ export declare function sendWebhook<TName extends WebhookName>(name: TName, body: unknown, options: SendWebhookOptions): Promise<Result<SendWebhookResult, SendWebhookErrorCode>>;
34
+ //#endregion
35
+ export { type SendWebhookErrorCode, type SendWebhookResult, type WebhookDefinition, type WebhookDeliveryErrorCode, type WebhookOptions, type WebhookSignature, defineWebhook };
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ import { _ as defineWebhook, f as sendDynamicWebhook } from "./runtime-BHBBgm1D.js";
2
+ //#region src/index.ts
3
+ /**
4
+ * Sends `body` as JSON to the webhook `name` of `server/webhooks/<name>.ts`, signed with its secret, and returns
5
+ * `[error, { id, status }]`. The delivery waits in the Database and goes out through the Queue, so it survives a restart
6
+ * and the Queue retries it. With `debounce`, it waits until no send came for that long, then delivers the last body
7
+ * once, with `x-vitehub-events` set to the number of sends.
8
+ *
9
+ * A missing variable, a body that is not JSON, or a Database or Queue failure comes back as the error. An unknown name
10
+ * throws.
11
+ *
12
+ * ```ts
13
+ * import { sendWebhook } from "@vite-hub/webhooks"
14
+ *
15
+ * const [error] = await sendWebhook("t3", { thread: thread.id }, { event: "comments.comment" })
16
+ * ```
17
+ */
18
+ function sendWebhook(name, body, options) {
19
+ return sendDynamicWebhook(name, body, options);
20
+ }
21
+ //#endregion
22
+ export { defineWebhook, sendWebhook };
@@ -0,0 +1,7 @@
1
+ //#region ../internal/src/object.ts
2
+ /** A non-null object or a function that is not an array. */
3
+ function isRecordOrFunction(value) {
4
+ return Object(value) === value && !Array.isArray(value);
5
+ }
6
+ //#endregion
7
+ export { isRecordOrFunction as t };
@@ -0,0 +1,160 @@
1
+ import { StandardSchemaV1 } from "@standard-schema/spec";
2
+ //#region ../internal/src/operation-definition.d.ts
3
+ /** `read` never changes state. `write` changes state. `destructive` deletes or publishes. */
4
+ type OperationKind = "read" | "write" | "destructive";
5
+ /** The signed-in user of a call. */
6
+ interface OperationUser {
7
+ id: string;
8
+ name?: string;
9
+ email?: string;
10
+ image?: string;
11
+ [key: string]: unknown;
12
+ }
13
+ /** The Agent Actor when an agent calls through a capability or MCP on behalf of a user. */
14
+ interface OperationActor {
15
+ id: string;
16
+ kind?: string;
17
+ label?: string;
18
+ meta?: object;
19
+ }
20
+ /** The checked Console access of a call. `vite-hub` issues it. `ConsoleAccess` has this shape. */
21
+ interface OperationAccess {
22
+ readonly mode: string;
23
+ /**
24
+ * The sections that the call may use. `"all"` when no section filter applies. An entry is a section id (`"kv"`, every
25
+ * operation of the section), `"<section>:read"` (only the operations that read), or `"<section>:<scope>"` (only the
26
+ * calls of a scoped operation for that scope, such as `"blob:media"` for one Blob store). `"<section>:<scope>:read"`
27
+ * allows only the reads of that scope.
28
+ */
29
+ readonly sections: "all" | readonly string[];
30
+ readonly user?: OperationUser;
31
+ }
32
+ interface OperationContext {
33
+ /** The checked Console access of the call. */
34
+ access: OperationAccess;
35
+ /** The signed-in user, or null. */
36
+ user: OperationUser | null;
37
+ /** The Agent Actor when an agent calls on behalf of `user`. */
38
+ actor?: OperationActor;
39
+ surface: "console" | "cli" | "mcp" | "agent";
40
+ /** Set by the host from generated build identity, never from request input or runtime NODE_ENV. */
41
+ development?: boolean;
42
+ env?: Record<string, unknown>;
43
+ waitUntil?: (task: Promise<unknown>) => void;
44
+ request?: Request;
45
+ /**
46
+ * The request event of the HTTP request that carries the call, when there is one: the Request of the Console route,
47
+ * with its Standard Context. Operations hand it to app hooks that read the request's own session, such as `identify`
48
+ * of Comments.
49
+ */
50
+ event?: unknown;
51
+ /** Operations set a success status here, such as 202 for an accepted call. */
52
+ response?: {
53
+ status?: number;
54
+ };
55
+ /**
56
+ * An agent or an MCP client may pass `lease: "override"` to `content.save`, `content.remove`, and `content.restore`
57
+ * only when the developer allowed it. Defaults to false, so a model cannot take over a document that a person is editing.
58
+ */
59
+ overrideLeases?: boolean;
60
+ /**
61
+ * What an Agent may read of the Channel conversations, set by `operations({ conversations })`. `participant`: only the
62
+ * threads that the Actor takes part in. `all`: every thread. Unset: none.
63
+ */
64
+ conversations?: "all" | "participant";
65
+ }
66
+ interface OperationDefinition<Input, Output> {
67
+ /** `<section>.<verb>`, such as `content.publish`. Unique per app. */
68
+ name: string;
69
+ /** One sentence. Becomes the CLI help line and the MCP tool description. */
70
+ description: string;
71
+ /**
72
+ * Console section that grants access, such as `content`. `false`: any Console user. A function reads the section
73
+ * from the input, for operations that serve several sections. Section ids cannot contain `:`; it is reserved for
74
+ * scope and read-only grants. A function that returns an invalid id denies the call.
75
+ */
76
+ section: string | false | ((input: Input) => string | undefined);
77
+ /**
78
+ * The part of a string `section` that one call uses, such as the Blob store that the input names. The call then needs
79
+ * the section (every scope) or `"<section>:<scope>"` (only this scope). A scope that is empty, is `read`, or has a
80
+ * `:` needs the whole section.
81
+ */
82
+ scope?: (input: Input) => string | undefined;
83
+ /** `read` never changes state. `write` changes state. `destructive` deletes or publishes; the CLI asks for `--yes`, MCP marks `destructiveHint`, agents require approval by default. */
84
+ kind: OperationKind;
85
+ /** Standard Schema (valibot in this repo). Its Standard JSON Schema builds CLI flags and the MCP input schema. */
86
+ input: StandardSchemaV1<unknown, Input>;
87
+ output?: StandardSchemaV1<unknown, Output>;
88
+ cli?: {
89
+ /** Defaults: namespace = section, command = verb. */
90
+ namespace?: string;
91
+ /** A space groups commands: `jobs list` and `jobs show` run as `vitehub <namespace> jobs list` and `jobs show`. */
92
+ command?: string;
93
+ /** Input keys read from positional arguments, in order. */
94
+ positional?: string[];
95
+ /** Human output, written verbatim. Without it the CLI prints JSON. `--json` always prints JSON. */
96
+ format?: (output: Output) => string;
97
+ /** `vitehub <namespace>` runs this command when no command is named. */
98
+ default?: boolean;
99
+ };
100
+ /** Largest request body in bytes. It can raise the 64 KiB default but not lower it. */
101
+ maxRequestBytes?: number;
102
+ /**
103
+ * Returns true when this call only reads, such as a dry run of a `destructive` operation. The CLI then skips the
104
+ * confirmation, and agents run it without approval. Without it, every call of a `destructive` operation asks.
105
+ */
106
+ readOnlyWhen?: (input: Input) => boolean;
107
+ /**
108
+ * How MCP offers the operation as a tool. `false`: MCP does not offer it, such as an editor transport that only the
109
+ * Console uses. `title`: the short title that clients show, instead of the name in words. `format`: the text of a
110
+ * result for the Agent, such as a list of lines. The result stays the structured content. Without `format`, the text
111
+ * is the result as JSON.
112
+ */
113
+ mcp?: false | {
114
+ title?: string;
115
+ format?: (output: NoInfer<Output>) => string;
116
+ };
117
+ /** `false`: the operation never reads `context.user`, so the Console skips the session lookup for it. */
118
+ user?: false;
119
+ /**
120
+ * The operation runs code of the app, such as a workflow, a job, a task, or a schedule. The Console registers it only
121
+ * when `console.invoke` is on, which is the default in development and off in a production build.
122
+ */
123
+ invoke?: true;
124
+ run: (input: Input, context: OperationContext) => Output | Promise<Output>;
125
+ }
126
+ /** An operation of any input and output, as a registry holds it. */
127
+ interface AnyOperation extends Omit<OperationDefinition<unknown, unknown>, "cli" | "input" | "mcp" | "output" | "readOnlyWhen" | "run" | "scope" | "section"> {
128
+ readOnlyWhen?: (input: never) => boolean;
129
+ cli?: {
130
+ namespace?: string;
131
+ command?: string;
132
+ default?: boolean;
133
+ positional?: string[];
134
+ format?: (output: never) => string;
135
+ };
136
+ mcp?: false | {
137
+ title?: string;
138
+ format?: (output: never) => string;
139
+ };
140
+ input: StandardSchemaV1;
141
+ output?: StandardSchemaV1;
142
+ run: (input: never, context: OperationContext) => unknown;
143
+ scope?: (input: never) => string | undefined;
144
+ section: string | false | ((input: never) => string | undefined);
145
+ }
146
+ /** The contribution of one plugin: operations, or a module that exports them. */
147
+ interface OperationContributionEntry {
148
+ /** The absolute path of the module that generated code imports, such as `ownModule(import.meta.url, "operations")`. */
149
+ module: string;
150
+ /** Named export that holds an operation or an array of operations. Defaults to `default`. */
151
+ export?: string;
152
+ /** Loads the export in the tool process, for a module that the tool cannot resolve by name. */
153
+ load?: () => Promise<unknown>;
154
+ /** `false`: the app already has these operations at runtime. Only tools such as the CLI and `vitehub inspect` read the entry. */
155
+ runtime?: false;
156
+ }
157
+ /** The contribution of a plugin: a list, or a function that returns it, for a plugin that reads the project first. */
158
+ type OperationContributions = readonly OperationContributionEntry[] | (() => readonly OperationContributionEntry[] | Promise<readonly OperationContributionEntry[]>);
159
+ //#endregion
160
+ export { OperationContributions as n, AnyOperation as t };
@@ -0,0 +1,8 @@
1
+ import { t as AnyOperation } from "./operations-D4A1Fcgf.js";
2
+ //#region src/operations.d.ts
3
+ /**
4
+ * The `webhooks.*` operations. The Console, `vitehub webhooks`, and MCP run them on the app's operation RPC, `POST
5
+ * /_vitehub/rpc`.
6
+ */
7
+ export declare const webhooksOperations: readonly AnyOperation[];
8
+ //#endregion