@vite-hub/comments 0.0.0 → 0.3.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.
Files changed (77) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +291 -0
  3. package/dist/anchor.d.ts +43 -0
  4. package/dist/anchor.js +133 -0
  5. package/dist/client-diagnostics-CcFpkbAk.js +40 -0
  6. package/dist/client.d.ts +176 -0
  7. package/dist/client.js +738 -0
  8. package/dist/console-h4KlhIik.d.ts +332 -0
  9. package/dist/context-BqIsmYP1.js +61 -0
  10. package/dist/database/postgres.d.ts +1402 -0
  11. package/dist/database/postgres.js +81 -0
  12. package/dist/database-CA1aHKN7.d.ts +1495 -0
  13. package/dist/database.d.ts +12 -0
  14. package/dist/database.js +2 -0
  15. package/dist/define-43mMR39K.js +89 -0
  16. package/dist/define-B3TF9zzn.d.ts +204 -0
  17. package/dist/errors-4gelGVmK.js +57 -0
  18. package/dist/errors-C6qptPoG.js +135 -0
  19. package/dist/errors-CyQyKAvy.d.ts +185 -0
  20. package/dist/fold-name-B7Zb3-MF.js +7 -0
  21. package/dist/identity-CBOzgxSf.js +39 -0
  22. package/dist/index-DNhy69Wt.d.ts +83 -0
  23. package/dist/index.d.ts +7 -0
  24. package/dist/index.js +196 -0
  25. package/dist/install-BcMPgPk_.js +1154 -0
  26. package/dist/install-W9ghhGoh.d.ts +36 -0
  27. package/dist/installed-B-PfERBU.js +30 -0
  28. package/dist/invariant-D8_xBqmZ.js +22 -0
  29. package/dist/migrate-B0k_0swk.d.ts +54 -0
  30. package/dist/migrate-BDQ8xqUs.js +289 -0
  31. package/dist/object-Da1zyPCR.js +11 -0
  32. package/dist/operations-D4A1Fcgf.d.ts +160 -0
  33. package/dist/operations-DMMIfYPW.js +1159 -0
  34. package/dist/operations-GLeOqgMt.d.ts +257 -0
  35. package/dist/operations.d.ts +3 -0
  36. package/dist/operations.js +3 -0
  37. package/dist/overlay/client-DmsSMOzi.js +4 -0
  38. package/dist/overlay/dist-BoHMOFax.js +14 -0
  39. package/dist/overlay/dist-yIZmvSaU.js +1 -0
  40. package/dist/overlay/overlay.js +201 -0
  41. package/dist/page/loader.js +142 -0
  42. package/dist/page-B41ozN63.js +40 -0
  43. package/dist/page-DtbMOEMd.d.ts +22 -0
  44. package/dist/page-tools-shared-NHUjKI8E.js +117 -0
  45. package/dist/path--zk6PEMz.js +18 -0
  46. package/dist/plugin-PS8PMYus.js +74 -0
  47. package/dist/realtime.d.ts +12 -0
  48. package/dist/realtime.js +47 -0
  49. package/dist/rpc-HBcWtg0T.d.ts +17 -0
  50. package/dist/rpc-RKPAusHp.js +153 -0
  51. package/dist/rpc.d.ts +2 -0
  52. package/dist/rpc.js +2 -0
  53. package/dist/runtime/auth.d.ts +8 -0
  54. package/dist/runtime/auth.js +18 -0
  55. package/dist/runtime/connect/node.d.ts +1 -0
  56. package/dist/runtime/connect/node.js +2 -0
  57. package/dist/runtime/connect.d.ts +1 -0
  58. package/dist/runtime/connect.js +2 -0
  59. package/dist/runtime/console.d.ts +5 -0
  60. package/dist/runtime/console.js +64 -0
  61. package/dist/runtime/index.d.ts +270 -0
  62. package/dist/runtime/index.js +1113 -0
  63. package/dist/server-D8k-0GXe.js +72 -0
  64. package/dist/server.d.ts +20 -0
  65. package/dist/server.js +7 -0
  66. package/dist/service-CFVm23k7.d.ts +158 -0
  67. package/dist/service-GHhhyQj4.js +609 -0
  68. package/dist/session-DVx-1Tym.d.ts +14 -0
  69. package/dist/session-EkudzUmm.js +503 -0
  70. package/dist/testing.d.ts +30 -0
  71. package/dist/testing.js +187 -0
  72. package/dist/tokens-DSbwkVSy.js +58 -0
  73. package/dist/types-BIS0hCEl.d.ts +124 -0
  74. package/dist/types-CZujrMFd.d.ts +322 -0
  75. package/dist/vite.d.ts +308 -0
  76. package/dist/vite.js +1660 -0
  77. package/package.json +153 -4
@@ -0,0 +1,153 @@
1
+ import { i as commentsUnansweredError, t as commentsAnswerError } from "./client-diagnostics-CcFpkbAk.js";
2
+ import { n as isRecordOrFunction, t as isRecord } from "./object-Da1zyPCR.js";
3
+ import { createBirpc } from "birpc";
4
+ //#region ../internal/src/operation-rpc.ts
5
+ /** Path of the operation RPC under the app. Dev servers and deployed apps serve it the same way, one birpc call per POST. */
6
+ const operationRpcPath = "/_vitehub/rpc";
7
+ function text(value) {
8
+ return String(value) === value && value ? value : void 0;
9
+ }
10
+ /** Read an untrusted failure body. It keeps only the diagnostic fields, so a stack never passes through. */
11
+ function readOperationRpcError(value) {
12
+ if (!isRecord(value)) return void 0;
13
+ const code = text(value.code);
14
+ const message = text(value.message);
15
+ const status = value.status;
16
+ if (!code || !message || !Number.isInteger(status)) return void 0;
17
+ const failure = {
18
+ code,
19
+ message,
20
+ status: Number(status)
21
+ };
22
+ if (text(value.fix)) failure.fix = text(value.fix);
23
+ if (text(value.docs)) failure.docs = text(value.docs);
24
+ if (isRecord(value.details)) failure.details = value.details;
25
+ return failure;
26
+ }
27
+ /** Read one response message. */
28
+ function readOperationRpcReply(value) {
29
+ if (!isRecord(value) || value.t !== "s") return void 0;
30
+ const id = text(value.i);
31
+ if (Object.hasOwn(value, "e")) {
32
+ const error = readOperationRpcError(value.e);
33
+ return error ? {
34
+ t: "s",
35
+ ...id ? { i: id } : {},
36
+ e: error
37
+ } : void 0;
38
+ }
39
+ return id ? {
40
+ t: "s",
41
+ i: id,
42
+ r: value.r
43
+ } : void 0;
44
+ }
45
+ /**
46
+ * Call one operation with birpc over a request and answer transport, such as one HTTP POST per call. `send` posts the
47
+ * JSON message and returns the parsed answer; its own failures, such as a network error or an abort, reject.
48
+ */
49
+ async function callOperationRpc(name, input, send) {
50
+ let receive;
51
+ let answer;
52
+ const notReply = /* @__PURE__ */ new Error("The answer is not a reply to the operation call.");
53
+ const rpc = createBirpc({}, {
54
+ on: (listener) => {
55
+ receive = listener;
56
+ },
57
+ post: async (message) => {
58
+ answer = await send(JSON.stringify(message));
59
+ const reply = readOperationRpcReply(answer.body);
60
+ if (!reply || reply.i !== void 0 && reply.i !== message.i) throw notReply;
61
+ await receive({
62
+ ...reply,
63
+ i: message.i
64
+ });
65
+ },
66
+ proxify: false,
67
+ timeout: -1
68
+ });
69
+ try {
70
+ return {
71
+ ok: true,
72
+ value: await rpc.$call(name, ...input === void 0 ? [] : [input]),
73
+ answer
74
+ };
75
+ } catch (error) {
76
+ if (!answer) throw error;
77
+ if (error === notReply) return {
78
+ ok: false,
79
+ error: void 0,
80
+ answer
81
+ };
82
+ return {
83
+ ok: false,
84
+ error: readOperationRpcError(error),
85
+ answer
86
+ };
87
+ }
88
+ }
89
+ //#endregion
90
+ //#region src/operations-core/rpc.ts
91
+ /**
92
+ * A transport over the operations RPC at `POST /_vitehub/rpc`, one birpc call for each request, for development only.
93
+ * A browser cannot sign Console calls, so it works on a development server with `console: { auth: false }` or without
94
+ * the `console` option. Pages of a production app use `createRestTransport()` from `@vite-hub/comments/client`. It has
95
+ * no `subscribe`: the client refreshes when the window gets focus.
96
+ */
97
+ function createRpcTransport(options = {}) {
98
+ const base = (options.base ?? "").replace(/\/+$/, "");
99
+ async function call(operation, input) {
100
+ const send = options.fetch ?? globalThis.fetch;
101
+ let outcome;
102
+ try {
103
+ outcome = await callOperationRpc(operation, input, async (body) => {
104
+ const response = await send(`${base}${operationRpcPath}`, {
105
+ body,
106
+ cache: "no-store",
107
+ credentials: "same-origin",
108
+ headers: {
109
+ "content-type": "application/json",
110
+ "x-vitehub-console": "1"
111
+ },
112
+ method: "POST"
113
+ });
114
+ return {
115
+ body: await response.json().catch(() => void 0),
116
+ response
117
+ };
118
+ });
119
+ } catch (cause) {
120
+ throw commentsUnansweredError(0, cause);
121
+ }
122
+ if (outcome.ok) return outcome.value;
123
+ if (outcome.error) {
124
+ const { message, ...failure } = outcome.error;
125
+ throw commentsAnswerError({
126
+ ...failure,
127
+ why: message
128
+ });
129
+ }
130
+ const { body, response } = outcome.answer;
131
+ if (!isRecordOrFunction(body) || typeof body.code !== "string" || typeof body.message !== "string") throw commentsUnansweredError(response.status);
132
+ throw commentsAnswerError({
133
+ code: body.code,
134
+ status: typeof body.status === "number" ? body.status : response.status,
135
+ why: body.message,
136
+ ...typeof body.fix === "string" ? { fix: body.fix } : {},
137
+ ...isRecordOrFunction(body.details) ? { details: body.details } : {}
138
+ });
139
+ }
140
+ return {
141
+ create: (input) => call("comments.create", input),
142
+ delete: (input) => call("comments.delete", input),
143
+ edit: (input) => call("comments.edit", input),
144
+ get: (input) => call("comments.get", input),
145
+ list: (query) => call("comments.list", query),
146
+ reopen: (input) => call("comments.reopen", input),
147
+ reply: (input) => call("comments.reply", input),
148
+ resolve: (input) => call("comments.resolve", input),
149
+ users: (input) => call("comments.users", input)
150
+ };
151
+ }
152
+ //#endregion
153
+ export { createRpcTransport as t };
package/dist/rpc.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { n as createRpcTransport, t as RpcTransportOptions } from "./rpc-HBcWtg0T.js";
2
+ export { RpcTransportOptions, createRpcTransport };
package/dist/rpc.js ADDED
@@ -0,0 +1,2 @@
1
+ import { t as createRpcTransport } from "./rpc-RKPAusHp.js";
2
+ export { createRpcTransport };
@@ -0,0 +1,8 @@
1
+ import { d as CommentsPeople, g as CommentsUser } from "../define-B3TF9zzn.js";
2
+ import { s as CommentsRequestEvent } from "../types-BIS0hCEl.js";
3
+ //#region src/runtime/auth.d.ts
4
+ /** The ViteHub Auth user of a request, or null. Generated Comments files pass it as `session` when the app has Auth. */
5
+ export declare function commentsAuthSession(event: CommentsRequestEvent): Promise<CommentsUser | null>;
6
+ /** The users of ViteHub Auth, for `@` suggestions. Generated Comments files pass it as `users` when the app has Auth. */
7
+ export declare const commentsAuthUsers: CommentsPeople;
8
+ //#endregion
@@ -0,0 +1,18 @@
1
+ import { n as createAuthUsers } from "../server-D8k-0GXe.js";
2
+ import { getStandardContext } from "@vite-hub/runtime/internal/h3";
3
+ //#region src/runtime/auth.ts
4
+ const authServer = () => import("@vite-hub/auth/server");
5
+ /** The ViteHub Auth user of a request, or null. Generated Comments files pass it as `session` when the app has Auth. */
6
+ async function commentsAuthSession(event) {
7
+ const request = getStandardContext(event).req;
8
+ const user = (await (await authServer()).useAuth(event).api.getSession({ headers: request.headers }))?.user;
9
+ if (!user || typeof user !== "object" || !("id" in user) || typeof user.id !== "string") return null;
10
+ return {
11
+ ...user,
12
+ id: user.id
13
+ };
14
+ }
15
+ /** The users of ViteHub Auth, for `@` suggestions. Generated Comments files pass it as `users` when the app has Auth. */
16
+ const commentsAuthUsers = createAuthUsers(async () => (await authServer()).getAuth());
17
+ //#endregion
18
+ export { commentsAuthSession, commentsAuthUsers };
@@ -0,0 +1 @@
1
+ export * from "@vite-hub/database/connect/node";
@@ -0,0 +1,2 @@
1
+ export * from "@vite-hub/database/connect/node";
2
+ export {};
@@ -0,0 +1 @@
1
+ export * from "@vite-hub/database/connect";
@@ -0,0 +1,2 @@
1
+ export * from "@vite-hub/database/connect";
2
+ export {};
@@ -0,0 +1,5 @@
1
+ import { n as ViteHubConsoleRecord } from "../console-h4KlhIik.js";
2
+ //#region src/runtime/console.d.ts
3
+ /** The threads of the app as Console records: open threads first, each group newest activity first. It runs on each Console request. */
4
+ export declare function readCommentsConsoleRecords(): Promise<ViteHubConsoleRecord[]>;
5
+ //#endregion
@@ -0,0 +1,64 @@
1
+ import { n as commentsPageScope } from "../page-B41ozN63.js";
2
+ import { t as describeCommentContext } from "../context-BqIsmYP1.js";
3
+ import { n as installedComments } from "../plugin-PS8PMYus.js";
4
+ //#region src/runtime/console.ts
5
+ function excerpt(text) {
6
+ const line = text.replace(/\s+/g, " ").trim();
7
+ return line.length > 80 ? `${line.slice(0, 79)}…` : line;
8
+ }
9
+ /** The threads of the app as Console records: open threads first, each group newest activity first. It runs on each Console request. */
10
+ async function readCommentsConsoleRecords() {
11
+ const comments = installedComments();
12
+ if (!comments) return [];
13
+ const [error, listed] = await comments.list({
14
+ scope: commentsPageScope,
15
+ subjectKind: "page",
16
+ limit: 500
17
+ });
18
+ if (error) return [];
19
+ const threads = listed.filter((thread) => thread.subject.kind === "page");
20
+ const ordered = [...threads.filter((thread) => thread.status === "open"), ...threads.filter((thread) => thread.status !== "open")];
21
+ const author = (person) => `${person.name ?? person.id}${person.guest ? " (guest)" : ""}`;
22
+ return ordered.map((thread) => {
23
+ const first = thread.messages[0];
24
+ const page = thread.subject.id;
25
+ const { anchor } = thread;
26
+ return {
27
+ id: thread.id,
28
+ cells: {
29
+ comment: first ? excerpt(first.body) : "",
30
+ page: `\`${page}\``,
31
+ author: author(thread.author),
32
+ replies: String(Math.max(0, thread.messages.length - 1)),
33
+ status: thread.status === "open" ? "Open" : "Resolved",
34
+ updated: new Date(thread.updatedAt).toISOString()
35
+ },
36
+ link: {
37
+ href: `${page}?comment=${thread.n}`,
38
+ label: "Open on page"
39
+ },
40
+ activity: thread.messages.map((message) => ({
41
+ author: author(message.author),
42
+ at: new Date(message.createdAt).toISOString(),
43
+ text: message.body
44
+ })),
45
+ fields: [
46
+ {
47
+ label: "Page",
48
+ value: page
49
+ },
50
+ ...anchor.kind === "element" ? [{
51
+ label: "Anchor",
52
+ value: anchor.field ? `Content field ${anchor.field}` : anchor.label ?? anchor.selector
53
+ }] : [],
54
+ ...describeCommentContext(thread.context ?? null),
55
+ ...thread.resolvedBy ? [{
56
+ label: "Resolved by",
57
+ value: author(thread.resolvedBy)
58
+ }] : []
59
+ ]
60
+ };
61
+ });
62
+ }
63
+ //#endregion
64
+ export { readCommentsConsoleRecords };
@@ -0,0 +1,270 @@
1
+ import { s as CommentContext } from "../types-CZujrMFd.js";
2
+ import { g as CommentsUser } from "../define-B3TF9zzn.js";
3
+ import { s as CommentsRequestEvent } from "../types-BIS0hCEl.js";
4
+ import { t as Comments } from "../index-DNhy69Wt.js";
5
+ import { o as CommentsDatabase } from "../service-CFVm23k7.js";
6
+ import { t as CommentsSessionOptions } from "../session-DVx-1Tym.js";
7
+ import { t as InstallCommentsOptions } from "../install-W9ghhGoh.js";
8
+ //#region src/runtime/github-login.d.ts
9
+ /** The Server Env names of the OAuth client that people sign in to Comments with: a GitHub App's, or an OAuth App's. */
10
+ export declare const githubLoginEnv: {
11
+ readonly clientId: "VITEHUB_GITHUB_CLIENT_ID";
12
+ readonly clientSecret: "VITEHUB_GITHUB_CLIENT_SECRET";
13
+ };
14
+ interface CommentsGitHubLogin {
15
+ /** Whether the server has the OAuth client, so the overlay offers **Sign in with GitHub**. */
16
+ configured(): boolean;
17
+ /** The person signed in with GitHub, with what they may do in the repository. Null without a session. */
18
+ user(event: CommentsRequestEvent): Promise<CommentsUser | null>;
19
+ /** The sign-in, callback, and sign-out routes under `/api/_vitehub/comments/auth/`. */
20
+ handle(request: Request & CommentsRequestEvent, path: string): Promise<Response>;
21
+ }
22
+ /**
23
+ * Sign in with GitHub for Comments, with no database: ViteHub Auth's `stateless()` preset keeps the session, and the
24
+ * GitHub token, in encrypted cookies. A person may comment when GitHub says they can push to the repository of the
25
+ * build.
26
+ */
27
+ export declare function createCommentsGitHubLogin(options?: {
28
+ repository?: string;
29
+ apiUrl?: string;
30
+ fetch?: typeof fetch;
31
+ basePath?: string;
32
+ }): CommentsGitHubLogin;
33
+ //#endregion
34
+ //#region src/runtime/handler.d.ts
35
+ /** One field address, as `parseContentField()` from `@vite-hub/content/client` reads it. */
36
+ interface CommentsContentField {
37
+ collection: string;
38
+ id?: string;
39
+ field: string;
40
+ }
41
+ interface ContentDocumentLike {
42
+ id: string;
43
+ data: Record<string, unknown>;
44
+ body?: string;
45
+ digest: string;
46
+ }
47
+ interface ContentCollectionLike {
48
+ readonly name: string;
49
+ readonly kind: "documents" | "singleton";
50
+ readonly id?: string;
51
+ readonly format: string;
52
+ get(id: string, options: {
53
+ ref: "draft";
54
+ }): Promise<ContentDocumentLike | null>;
55
+ save(id: string, input: {
56
+ data: Record<string, unknown>;
57
+ body?: string;
58
+ }, options: {
59
+ ifDigest: string;
60
+ message: string;
61
+ metadata: Record<string, string>;
62
+ }): Promise<ContentDocumentLike>;
63
+ }
64
+ /** The parts of a Content runtime that inline edits use: `content` from `server/content.ts`. */
65
+ interface CommentsContent {
66
+ can(context: {
67
+ user?: Record<string, unknown>;
68
+ collection: string;
69
+ action: "write";
70
+ id?: string;
71
+ }): Promise<boolean>;
72
+ collections(): readonly ContentCollectionLike[];
73
+ }
74
+ interface CommentsHandlerOptions extends CommentsSessionOptions {
75
+ comments: Comments;
76
+ /**
77
+ * Sign in with GitHub, for apps without their own sign-in: people who are not signed in another way see **Sign in
78
+ * with GitHub** in the overlay. It works once the server has a GitHub OAuth client.
79
+ */
80
+ githubLogin?: CommentsGitHubLogin;
81
+ /** Inline edits of Content fields. Omitted when the app has no Content collections. */
82
+ content?: {
83
+ runtime: CommentsContent;
84
+ parseField: (value: string) => CommentsContentField | undefined;
85
+ };
86
+ /** Whether the page presence rooms run, because the host has a Realtime authority. */
87
+ realtime: boolean;
88
+ /** `false` hides the overlay's faces and cursors, for an app that shows its own presence. Threads still update live. */
89
+ presence?: false;
90
+ /** The commit and branch of this build. New threads keep them in `context.build`. */
91
+ build?: NonNullable<CommentContext["build"]>;
92
+ /**
93
+ * The Vue files of the project by component name, relative to the project root. New threads get the files of each
94
+ * component that the overlay names, because production builds keep only the name.
95
+ */
96
+ components?: Readonly<Record<string, readonly string[]>>;
97
+ }
98
+ /**
99
+ * The Comments API at `/api/_vitehub/comments/**`, as a Fetchable: mount it as a Nitro or H3 route, or call
100
+ * `fetch(request)`. The overlay calls it; every route checks the `authorize` policy of `defineComments()` for the user of
101
+ * the request, and inline edits also check `content.can()`.
102
+ */
103
+ export declare function createCommentsHandler(options: CommentsHandlerOptions): {
104
+ fetch(request: Request): Promise<Response>;
105
+ };
106
+ //#endregion
107
+ //#region src/runtime/plugin.d.ts
108
+ interface CommentsPluginOptions extends CommentsSessionOptions {
109
+ comments: Comments;
110
+ /** Offers GitHub sign-in or account switching through the overlay, even before read access is granted. */
111
+ githubLogin?: CommentsGitHubLogin;
112
+ /** The Database of `defineComments({ database })`, or undefined when the app has none. The first Comments call reads it. */
113
+ database: () => CommentsDatabase | undefined | Promise<CommentsDatabase | undefined>;
114
+ /**
115
+ * Path of the overlay script below the app base, such as `/api/_vitehub/comments/assets/overlay.js`. The page tools
116
+ * loader imports it for people that may read comments.
117
+ */
118
+ overlay: string | false;
119
+ /** The app base, such as `/portal/`. The page tools use it for the loader tag of Nitro 3 pages. Default: the root. */
120
+ base?: string;
121
+ /** Vite's serve/build identity, recorded by the generated plugin. Defaults to false. */
122
+ development?: boolean;
123
+ /** What the server log says when `database()` returns nothing. */
124
+ missingDatabase?: string;
125
+ /** The Auth users for `@` suggestions, when the app has Auth. */
126
+ users?: InstallCommentsOptions["users"];
127
+ /** The Blob store for attachments, when the app has Blob. */
128
+ attachments?: InstallCommentsOptions["attachments"];
129
+ /** `checkRateLimit` of ViteHub Rate Limit, when it counts in a KV store that every server process shares. */
130
+ rateLimit?: InstallCommentsOptions["rateLimit"];
131
+ /** Who keeps the tables up to date: `comments` for a Database that `comments()` opens itself. Default `app`. */
132
+ schema?: InstallCommentsOptions["schema"];
133
+ /** The tables of a Postgres Database. Default: the SQLite tables. */
134
+ tables?: InstallCommentsOptions["tables"];
135
+ dialect?: InstallCommentsOptions["dialect"];
136
+ }
137
+ /** The Comments definition that the Nitro plugin installed, for the Console reader. */
138
+ export declare function installedComments(): Comments | undefined;
139
+ /**
140
+ * The Nitro plugin of Comments. It connects the definition to its Database, and registers the overlay as the
141
+ * `comments` page tool: a visitor may load it when `authorize` allows `read` or GitHub sign-in is available.
142
+ */
143
+ export declare function defineCommentsPlugin(options: CommentsPluginOptions): (nitroApp: unknown) => void;
144
+ //#endregion
145
+ //#region src/runtime/database.d.ts
146
+ /** The runtime Database registry of `@vite-hub/database/runtime/registry`, as the generated Nitro plugin passes it. */
147
+ type CommentsDatabaseRegistry = Record<string, {
148
+ db: CommentsDatabase;
149
+ } | undefined>;
150
+ /**
151
+ * The Database that `defineComments({ database })` names, else `default`, else the only one. The plugin calls it when
152
+ * the server starts. On Cloudflare that is before any request, so a D1 Database can't connect yet: its db throws until
153
+ * a request brings the binding. An app without a default Database uses a placeholder that throws
154
+ * `DATABASE_DISABLED` or `DATABASE_NOT_FOUND`. The store reads the db per query, by which time the binding is there.
155
+ */
156
+ export declare function selectCommentsDatabase(databases: CommentsDatabaseRegistry, name?: string): CommentsDatabase | undefined;
157
+ //#endregion
158
+ //#region src/runtime/definition.d.ts
159
+ /**
160
+ * The Comments definition of `server/comments.ts`: its `comments` export, else its default export. Both forms run the
161
+ * same surfaces. The generated files call it, so a file without `defineComments()` fails with `COMMENTS_B0002`.
162
+ */
163
+ export declare function commentsDefinitionOf(module: {
164
+ comments?: unknown;
165
+ default?: unknown;
166
+ }, file: string): Comments;
167
+ //#endregion
168
+ //#region ../internal/src/runtime/mcp-tools.d.ts
169
+ /**
170
+ * The JSON Schema of one argument. A tool lists only these keywords, plus
171
+ * `description` and `title` for the Agent.
172
+ */
173
+ type ViteHubMcpValueSchema = {
174
+ description?: string;
175
+ title?: string;
176
+ enum?: ReadonlyArray<string | number | boolean | null>;
177
+ } & ({
178
+ type?: never;
179
+ } | {
180
+ type: "boolean";
181
+ } | {
182
+ type: "integer" | "number";
183
+ minimum?: number;
184
+ maximum?: number;
185
+ } | {
186
+ type: "string";
187
+ minLength?: number;
188
+ maxLength?: number;
189
+ } | {
190
+ type: "array";
191
+ items?: ViteHubMcpValueSchema;
192
+ } | {
193
+ type: "object";
194
+ properties?: Record<string, ViteHubMcpValueSchema>;
195
+ required?: string[];
196
+ additionalProperties?: boolean;
197
+ });
198
+ /** A JSON Schema object for the arguments of a tool. */
199
+ interface ViteHubMcpInputSchema {
200
+ type: "object";
201
+ properties: Record<string, ViteHubMcpValueSchema>;
202
+ required?: string[];
203
+ additionalProperties?: boolean;
204
+ }
205
+ /** What a tool call returns: text for the Agent, and the same data as JSON. */
206
+ interface ViteHubMcpToolResult {
207
+ text: string;
208
+ structured?: Record<string, unknown>;
209
+ isError?: boolean;
210
+ }
211
+ /** The checked caller of a tool. */
212
+ interface ViteHubMcpToolContext {
213
+ /** The checked user, with every field, or null for a caller without accounts. */
214
+ user: Record<string, unknown> | null;
215
+ /** The request event with its Standard Context, when available, for owners that resolve request identity. */
216
+ event?: {
217
+ readonly "~standard": {
218
+ readonly req: Request;
219
+ };
220
+ };
221
+ }
222
+ /**
223
+ * One tool for an app's own MCP server, such as a Comments tool of `commentsMcpTools()`. ViteHub MCP offers operations
224
+ * instead. The server lists and runs a tool only for a person whose Console access includes the tool's `section`.
225
+ */
226
+ interface ViteHubMcpTool {
227
+ /** Snake case and prefixed with the owner, such as `comments_list_threads`. */
228
+ name: string;
229
+ title?: string;
230
+ description: string;
231
+ inputSchema: ViteHubMcpInputSchema;
232
+ /** Only `readOnlyHint: true` permits a read-only Console grant; other tools require full section access. */
233
+ annotations?: {
234
+ readOnlyHint?: boolean;
235
+ destructiveHint?: boolean;
236
+ idempotentHint?: boolean;
237
+ openWorldHint?: boolean;
238
+ };
239
+ /** The Console section whose access the tool needs, such as `comments`. */
240
+ section: string;
241
+ call(input: Record<string, unknown>, context: ViteHubMcpToolContext): Promise<ViteHubMcpToolResult>;
242
+ }
243
+ //#endregion
244
+ //#region src/runtime/mcp.d.ts
245
+ interface CommentsMcpToolsOptions {
246
+ /**
247
+ * The caller passed the Console access check of the `comments` section, as the comment operations do. `authorize`
248
+ * then gets `console: true`. Without `identify`, the default policy also trusts `context.user`, as it does for the
249
+ * comment operations. Default `false`.
250
+ */
251
+ console?: boolean;
252
+ }
253
+ /**
254
+ * The Comments tools for an app's own MCP server. Each call resolves the Comments identity and checks `authorize`,
255
+ * as the overlay does. The server supplies the checked `context.user`. ViteHub MCP offers the comment operations instead.
256
+ * With `identify` and a request event, `identify` names the user, as in the overlay API. Otherwise the tools use the
257
+ * checked `context.user`. Replies and resolves show that user as the author.
258
+ */
259
+ export declare function commentsMcpTools(comments: Comments, options?: CommentsMcpToolsOptions): ViteHubMcpTool[];
260
+ //#endregion
261
+ //#region ../internal/src/runtime/page-tools.d.ts
262
+ /**
263
+ * The route of `GET /_vitehub/page/session`: a Fetchable (https://fetchable.org). Nitro 3 binds each Request to its
264
+ * app in `installViteHubPageTools()`, so the route finds the tools of that app.
265
+ */
266
+ export declare const viteHubPageSessionHandler: {
267
+ fetch(request: Request): Promise<Response>;
268
+ };
269
+ //#endregion
270
+ export type { CommentsContent, CommentsContentField, CommentsDatabaseRegistry, CommentsGitHubLogin, CommentsHandlerOptions, CommentsMcpToolsOptions, CommentsPluginOptions };