@vite-hub/comments 0.5.0 → 0.6.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 +7 -1
- package/dist/anchor.d.ts +3 -5
- package/dist/anchor.js +1 -2
- package/dist/{client-diagnostics-Bubm7Shd.js → client-diagnostics-CvfTW5d4.js} +1 -2
- package/dist/{client-files-CJZl5Kc4.js → client-files-lC6X7XyS.js} +1 -2
- package/dist/client.d.ts +44 -25
- package/dist/client.js +64 -43
- package/dist/{console-D1lwNMZn.d.ts → console-CCLX_eIk.d.ts} +1 -5
- package/dist/{context-BqIsmYP1.js → context-DbkBjITZ.js} +1 -2
- package/dist/database/postgres.d.ts +1 -3
- package/dist/database/postgres.js +1 -2
- package/dist/{database-6hXRnqDE.js → database-BkPoOdZr.js} +73 -61
- package/dist/{database-CTo7mx6t.d.ts → database-CPua6Q6_.d.ts} +0 -2
- package/dist/{database-CA1aHKN7.d.ts → database-DUs3c2al.d.ts} +625 -73
- package/dist/database.d.ts +4 -6
- package/dist/database.js +1 -2
- package/dist/{define-CmIFU96x.d.ts → define-B1jLSPe9.d.ts} +1 -3
- package/dist/{define-BMBSVbD9.js → define-BCxNaSZv.js} +3 -4
- package/dist/{errors-BJTZ9iyv.js → errors-C0VwRHiy.js} +1 -2
- package/dist/{errors-Dq4AHjza.js → errors-DFNiJg67.js} +10 -3
- package/dist/{fold-name-B7Zb3-MF.js → fold-name-g-xg0mQk.js} +1 -2
- package/dist/hosted/hosted-comments/client-B3dlmmQd.js +4 -0
- package/dist/{overlay/dist-BoHMOFax.js → hosted/hosted-comments/dist-DyVmH21U.js} +1 -1
- package/dist/hosted/hosted-comments/frame.js +1 -0
- package/dist/hosted/hosted-comments/overlay-CFuq5QAH.js +182 -0
- package/dist/hosted/hosted-comments/protocol-BHvtQKte.js +1 -0
- package/dist/hosted/hosted-comments/rest-transport-D-9_pNqZ.js +1 -0
- package/dist/hosted/hosted-comments/tools-Bz--joZw.js +126 -0
- package/dist/hosted/hosted-comments.js +9 -0
- package/dist/{identity-CBOzgxSf.js → identity-CT7-UGmS.js} +1 -2
- package/dist/{index-RiHzmV16.d.ts → index-D1T7RJ4R.d.ts} +10 -15
- package/dist/index.d.ts +5 -5
- package/dist/index.js +8 -9
- package/dist/{install-BGGQKbQ4.d.ts → install-NehuMNhG.d.ts} +19 -8
- package/dist/{install-DrAse1Fa.js → install-w6CCgGFV.js} +158 -45
- package/dist/{installed-C3EoqJEY.js → installed-C9SkldMi.js} +2 -3
- package/dist/{invariant-D8_xBqmZ.js → invariant-CmdvZ3vp.js} +1 -2
- package/dist/{migrate-B0k_0swk.d.ts → migrate-XjFeQppf.d.ts} +2 -2
- package/dist/{object-Da1zyPCR.js → object-CAK6UYR5.js} +1 -2
- package/dist/{operations-VyyNZusz.d.ts → operations-8hqTi0DH.d.ts} +0 -2
- package/dist/{operations-lsVKE0GH.js → operations-B8IMhRmY.js} +18 -20
- package/dist/{operations-BKhUWYkb.d.ts → operations-Cic9A9e_.d.ts} +4 -6
- package/dist/operations.d.ts +2 -2
- package/dist/operations.js +2 -2
- package/dist/overlay/{client-DBmJ4C1M.js → client-CerbVjTz.js} +3 -3
- package/dist/overlay/dist-DyVmH21U.js +14 -0
- package/dist/overlay/overlay.js +28 -16
- package/dist/page/loader.js +22 -21
- package/dist/{page-Bzj0CszG.d.ts → page-DE71P_gQ.d.ts} +0 -2
- package/dist/{page-tools-shared-BNnuPK93.js → page-tools-shared-fvmJQCrP.js} +2 -2
- package/dist/{page-DRz_sDY4.js → page-xzgZ6DGm.js} +2 -3
- package/dist/{path--zk6PEMz.js → path-8yqMd8zR.js} +0 -1
- package/dist/{plugin-DRsNaJaK.js → plugin-DbCYT7Ac.js} +14 -11
- package/dist/realtime.d.ts +3 -5
- package/dist/realtime.js +4 -5
- package/dist/{reply-id-P_bSuEng.js → reply-id-Cm9FGOBs.js} +1 -2
- package/dist/{request-log-Dj9Vw7qG.js → request-log-DllKQXj7.js} +1 -2
- package/dist/{request-origin-CFU0TQ7E.js → request-origin-YPzfE2eh.js} +1 -2
- package/dist/{rpc-BQqYx8kb.js → rpc-BKY7XRlR.js} +5 -7
- package/dist/{rpc-CuJ5GLIz.d.ts → rpc-D-eqtyfh.d.ts} +1 -3
- package/dist/rpc.d.ts +1 -1
- package/dist/rpc.js +1 -2
- package/dist/runtime/auth.d.ts +3 -5
- package/dist/runtime/auth.js +2 -3
- package/dist/runtime/console.d.ts +2 -4
- package/dist/runtime/console.js +4 -5
- package/dist/runtime/index.d.ts +45 -32
- package/dist/runtime/index.js +27 -26
- package/dist/{server-Yk610niJ.js → server-BGbD7H5s.js} +2 -3
- package/dist/server.d.ts +6 -8
- package/dist/server.js +6 -6
- package/dist/{service-Bj-Mg63c.d.ts → service-CPiWPoiY.d.ts} +3 -7
- package/dist/{service-DA5BwfPQ.js → service-DUh2uGd2.js} +9 -11
- package/dist/{session-DUcEor2W.d.ts → session-CN4irEqf.d.ts} +3 -5
- package/dist/{session-X_g9dnU5.js → session-_1GY5gaG.js} +30 -18
- package/dist/{store-CsUNfC1w.d.ts → store-DvNTDNgn.d.ts} +2 -4
- package/dist/{table-names-B9LlRC0B.js → table-names-BIHjuEFK.js} +1 -2
- package/dist/testing.d.ts +2 -4
- package/dist/testing.js +3 -4
- package/dist/{tokens-DSbwkVSy.js → tokens-Bx4lZ0yt.js} +3 -6
- package/dist/{types-BLaYh0_f.d.ts → types-BX3vH18p.d.ts} +0 -2
- package/dist/{types-C35INXIs.d.ts → types-l6GOb_yc.d.ts} +2 -4
- package/dist/vite.d.ts +22 -22
- package/dist/vite.js +40 -45
- package/package.json +19 -19
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// ../internal/src/runtime/request-origin.ts
|
|
2
2
|
function firstHeaderValue(headers, name) {
|
|
3
3
|
return headers.get(name)?.split(",", 1)[0]?.trim() || void 0;
|
|
4
4
|
}
|
|
@@ -45,5 +45,4 @@ function isSecureOrigin(origin) {
|
|
|
45
45
|
if (protocol !== "http:") return false;
|
|
46
46
|
return isLoopbackHostname(hostname) || hostname.endsWith(".localhost");
|
|
47
47
|
}
|
|
48
|
-
//#endregion
|
|
49
48
|
export { isSecureOrigin as n, matchesPublicOrigin as r, forwardedRequestOrigin as t };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as
|
|
3
|
-
import { n as
|
|
1
|
+
import { n as isRecordOrFunction, t as isRecord } from "./object-CAK6UYR5.js";
|
|
2
|
+
import { i as commentsUnansweredError, t as commentsAnswerError } from "./client-diagnostics-CvfTW5d4.js";
|
|
3
|
+
import { i as withCommentFiles, n as outboxAccountHeader, r as retryAfterOf } from "./client-files-lC6X7XyS.js";
|
|
4
4
|
import { createBirpc } from "birpc";
|
|
5
|
-
|
|
5
|
+
// ../internal/src/operation-rpc.ts
|
|
6
6
|
/** Path of the operation RPC under the app. Dev servers and deployed apps serve it the same way, one birpc call per POST. */
|
|
7
7
|
const operationRpcPath = "/_vitehub/rpc";
|
|
8
8
|
function text(value) {
|
|
@@ -87,8 +87,7 @@ async function callOperationRpc(name, input, send) {
|
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
|
|
91
|
-
//#region src/operations-core/rpc.ts
|
|
90
|
+
// src/operations-core/rpc.ts
|
|
92
91
|
/**
|
|
93
92
|
* A transport over the operations RPC at `POST /_vitehub/rpc`, one birpc call for each request, for development only.
|
|
94
93
|
* A browser cannot sign Console calls, so it works on a development server with `console: { auth: false }` or without
|
|
@@ -165,5 +164,4 @@ function createRpcTransport(options = {}) {
|
|
|
165
164
|
users: (input) => call("comments.users", input)
|
|
166
165
|
};
|
|
167
166
|
}
|
|
168
|
-
//#endregion
|
|
169
167
|
export { createRpcTransport as t };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { k as CommentsTransport } from "./types-
|
|
2
|
-
//#region src/operations-core/rpc.d.ts
|
|
1
|
+
import { k as CommentsTransport } from "./types-BX3vH18p.js";
|
|
3
2
|
interface RpcTransportOptions {
|
|
4
3
|
/** The app origin and mount, such as `https://app.example.com` or `/portal`. Defaults to the page origin. */
|
|
5
4
|
base?: string;
|
|
@@ -13,5 +12,4 @@ interface RpcTransportOptions {
|
|
|
13
12
|
* no `subscribe`: the client refreshes when the window gets focus.
|
|
14
13
|
*/
|
|
15
14
|
declare function createRpcTransport(options?: RpcTransportOptions): CommentsTransport;
|
|
16
|
-
//#endregion
|
|
17
15
|
export { createRpcTransport as n, RpcTransportOptions as t };
|
package/dist/rpc.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as createRpcTransport, t as RpcTransportOptions } from "./rpc-
|
|
1
|
+
import { n as createRpcTransport, t as RpcTransportOptions } from "./rpc-D-eqtyfh.js";
|
|
2
2
|
export { RpcTransportOptions, createRpcTransport };
|
package/dist/rpc.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { createRpcTransport };
|
|
1
|
+
export { t as createRpcTransport } from "./rpc-BKY7XRlR.js";
|
package/dist/runtime/auth.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { d as CommentsPeople, g as CommentsUser } from "../define-
|
|
2
|
-
import { f as CommentsRequestEvent } from "../types-
|
|
3
|
-
//#region src/runtime/auth.d.ts
|
|
1
|
+
import { d as CommentsPeople, g as CommentsUser } from "../define-B1jLSPe9.js";
|
|
2
|
+
import { f as CommentsRequestEvent } from "../types-l6GOb_yc.js";
|
|
4
3
|
/** The ViteHub Auth user of a request, or null. Generated Comments files pass it as `session` when the app has Auth. */
|
|
5
4
|
export declare function commentsAuthSession(event: CommentsRequestEvent): Promise<CommentsUser | null>;
|
|
6
5
|
/** 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
|
|
6
|
+
export declare const commentsAuthUsers: CommentsPeople;
|
package/dist/runtime/auth.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as createAuthUsers } from "../server-
|
|
1
|
+
import { n as createAuthUsers } from "../server-BGbD7H5s.js";
|
|
2
2
|
import { getStandardContext } from "@vite-hub/runtime/internal/h3";
|
|
3
|
-
|
|
3
|
+
// src/runtime/auth.ts
|
|
4
4
|
const authServer = () => import("@vite-hub/auth/internal/server");
|
|
5
5
|
/** The ViteHub Auth user of a request, or null. Generated Comments files pass it as `session` when the app has Auth. */
|
|
6
6
|
async function commentsAuthSession(event) {
|
|
@@ -14,5 +14,4 @@ async function commentsAuthSession(event) {
|
|
|
14
14
|
}
|
|
15
15
|
/** The users of ViteHub Auth, for `@` suggestions. Generated Comments files pass it as `users` when the app has Auth. */
|
|
16
16
|
const commentsAuthUsers = createAuthUsers(async () => (await authServer()).getAuth());
|
|
17
|
-
//#endregion
|
|
18
17
|
export { commentsAuthSession, commentsAuthUsers };
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { n as ViteHubConsoleRecord } from "../console-
|
|
2
|
-
//#region src/runtime/console.d.ts
|
|
1
|
+
import { n as ViteHubConsoleRecord } from "../console-CCLX_eIk.js";
|
|
3
2
|
/** 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
|
|
3
|
+
export declare function readCommentsConsoleRecords(): Promise<ViteHubConsoleRecord[]>;
|
package/dist/runtime/console.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { n as installedComments } from "../plugin-
|
|
4
|
-
|
|
1
|
+
import { t as describeCommentContext } from "../context-DbkBjITZ.js";
|
|
2
|
+
import { n as commentsPageScope } from "../page-xzgZ6DGm.js";
|
|
3
|
+
import { n as installedComments } from "../plugin-DbCYT7Ac.js";
|
|
4
|
+
// src/runtime/console.ts
|
|
5
5
|
function excerpt(text) {
|
|
6
6
|
const line = text.replace(/\s+/g, " ").trim();
|
|
7
7
|
return line.length > 80 ? `${line.slice(0, 79)}…` : line;
|
|
@@ -60,5 +60,4 @@ async function readCommentsConsoleRecords() {
|
|
|
60
60
|
};
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
-
//#endregion
|
|
64
63
|
export { readCommentsConsoleRecords };
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,11 +1,41 @@
|
|
|
1
|
-
import { s as CommentContext } from "../types-
|
|
2
|
-
import { g as CommentsUser } from "../define-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { t as
|
|
6
|
-
import { t as
|
|
7
|
-
import { t as
|
|
8
|
-
|
|
1
|
+
import { s as CommentContext } from "../types-BX3vH18p.js";
|
|
2
|
+
import { g as CommentsUser } from "../define-B1jLSPe9.js";
|
|
3
|
+
import { t as Comments } from "../index-D1T7RJ4R.js";
|
|
4
|
+
import { f as CommentsRequestEvent } from "../types-l6GOb_yc.js";
|
|
5
|
+
import { t as CommentsSessionOptions } from "../session-CN4irEqf.js";
|
|
6
|
+
import { t as InstallCommentsOptions } from "../install-NehuMNhG.js";
|
|
7
|
+
import { t as CommentsDatabase } from "../store-DvNTDNgn.js";
|
|
8
|
+
/**
|
|
9
|
+
* A person that Site access in the ViteHub Console signed in to the app: a Console member, or a guest, with their roles,
|
|
10
|
+
* such as `console` and `comments-write`. The Console signs them in a Site access token, which the app keeps in its
|
|
11
|
+
* site cookie.
|
|
12
|
+
*/
|
|
13
|
+
interface ViteHubSiteVisitor {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
email?: string;
|
|
17
|
+
image?: string;
|
|
18
|
+
roles: string[];
|
|
19
|
+
/** `member` for a member of the Console team, who has the `console` role. `guest` for an invited guest. */
|
|
20
|
+
kind: "member" | "guest";
|
|
21
|
+
commentsAgent?: {
|
|
22
|
+
project: {
|
|
23
|
+
id: string;
|
|
24
|
+
teamId: string;
|
|
25
|
+
url: string;
|
|
26
|
+
};
|
|
27
|
+
resolve: boolean;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Reads the Site access person of a request. It returns undefined without a valid cookie of this app. */
|
|
31
|
+
type ViteHubSiteVisitorReader = (request: Request) => Promise<ViteHubSiteVisitor | undefined>;
|
|
32
|
+
/**
|
|
33
|
+
* The route of `GET /_vitehub/page/tools`: a Fetchable (https://fetchable.org). `installViteHubPageTools()` binds
|
|
34
|
+
* each Request to its app in Nitro's `request` hook, so the route finds the tools of that app.
|
|
35
|
+
*/
|
|
36
|
+
export declare const viteHubPageSessionHandler: {
|
|
37
|
+
fetch(request: Request): Promise<Response>;
|
|
38
|
+
};
|
|
9
39
|
/** 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
40
|
export declare const githubLoginEnv: {
|
|
11
41
|
readonly clientId: "VITEHUB_GITHUB_CLIENT_ID";
|
|
@@ -30,8 +60,6 @@ export declare function createCommentsGitHubLogin(options?: {
|
|
|
30
60
|
fetch?: typeof fetch;
|
|
31
61
|
basePath?: string;
|
|
32
62
|
}): CommentsGitHubLogin;
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region src/runtime/handler.d.ts
|
|
35
63
|
/** One field address, as `parseContentField()` from `@vite-hub/content/client` reads it. */
|
|
36
64
|
interface CommentsContentField {
|
|
37
65
|
collection: string;
|
|
@@ -85,6 +113,7 @@ interface CommentsHandlerOptions extends CommentsSessionOptions {
|
|
|
85
113
|
};
|
|
86
114
|
/** Whether the page presence rooms run, because the host has a Realtime authority. */
|
|
87
115
|
realtime: boolean;
|
|
116
|
+
attachments?: false;
|
|
88
117
|
/** `false` hides the overlay's faces and cursors, for an app that shows its own presence. Threads still update live. */
|
|
89
118
|
presence?: false;
|
|
90
119
|
/** The commit and branch of this build. New threads keep them in `context.build`. */
|
|
@@ -103,9 +132,8 @@ interface CommentsHandlerOptions extends CommentsSessionOptions {
|
|
|
103
132
|
export declare function createCommentsHandler(options: CommentsHandlerOptions): {
|
|
104
133
|
fetch(request: Request): Promise<Response>;
|
|
105
134
|
};
|
|
106
|
-
//#endregion
|
|
107
|
-
//#region src/runtime/plugin.d.ts
|
|
108
135
|
interface CommentsPluginOptions extends CommentsSessionOptions {
|
|
136
|
+
siteVisitor?: ViteHubSiteVisitorReader;
|
|
109
137
|
comments: Comments;
|
|
110
138
|
/** Offers GitHub sign-in or account switching through the overlay, even before read access is granted. */
|
|
111
139
|
githubLogin?: CommentsGitHubLogin;
|
|
@@ -135,6 +163,11 @@ interface CommentsPluginOptions extends CommentsSessionOptions {
|
|
|
135
163
|
dialect?: InstallCommentsOptions["dialect"];
|
|
136
164
|
/** Loads `@vite-hub/webhooks`, when `defineComments({ send })` is on. */
|
|
137
165
|
webhooks?: InstallCommentsOptions["webhooks"];
|
|
166
|
+
/** Install more segments of the pill, such as the **Console** segment of `vite-hub`. Only with the overlay on. */
|
|
167
|
+
pillSegments?: ReadonlyArray<(nitroApp: unknown, context: {
|
|
168
|
+
base?: string;
|
|
169
|
+
development: boolean;
|
|
170
|
+
}) => void>;
|
|
138
171
|
}
|
|
139
172
|
/** The Comments definition that the Nitro plugin installed, for the Console reader. */
|
|
140
173
|
export declare function installedComments(): Comments | undefined;
|
|
@@ -143,8 +176,6 @@ export declare function installedComments(): Comments | undefined;
|
|
|
143
176
|
* `comments` page tool: a visitor may load it when `authorize` allows `read` or GitHub sign-in is available.
|
|
144
177
|
*/
|
|
145
178
|
export declare function defineCommentsPlugin(options: CommentsPluginOptions): (nitroApp: unknown) => void;
|
|
146
|
-
//#endregion
|
|
147
|
-
//#region src/runtime/database.d.ts
|
|
148
179
|
/** The runtime Database registry of `@vite-hub/database/runtime/registry`, as the generated Nitro plugin passes it. */
|
|
149
180
|
type CommentsDatabaseRegistry = Record<string, {
|
|
150
181
|
db: CommentsDatabase;
|
|
@@ -156,8 +187,6 @@ type CommentsDatabaseRegistry = Record<string, {
|
|
|
156
187
|
* `DATABASE_DISABLED` or `DATABASE_NOT_FOUND`. The store reads the db per query, by which time the binding is there.
|
|
157
188
|
*/
|
|
158
189
|
export declare function selectCommentsDatabase(databases: CommentsDatabaseRegistry, name?: string): CommentsDatabase | undefined;
|
|
159
|
-
//#endregion
|
|
160
|
-
//#region src/runtime/definition.d.ts
|
|
161
190
|
/**
|
|
162
191
|
* The Comments definition of `server/comments.ts`: its `comments` export, else its default export. Both forms run the
|
|
163
192
|
* same surfaces. The generated files call it, so a file without `defineComments()` fails with `COMMENTS_B0002`.
|
|
@@ -166,8 +195,6 @@ export declare function commentsDefinitionOf(module: {
|
|
|
166
195
|
comments?: unknown;
|
|
167
196
|
default?: unknown;
|
|
168
197
|
}, file: string): Comments;
|
|
169
|
-
//#endregion
|
|
170
|
-
//#region ../internal/src/runtime/mcp-tools.d.ts
|
|
171
198
|
/**
|
|
172
199
|
* The JSON Schema of one argument. A tool lists only these keywords, plus
|
|
173
200
|
* `description` and `title` for the Agent.
|
|
@@ -253,8 +280,6 @@ interface ViteHubMcpTool {
|
|
|
253
280
|
section: string;
|
|
254
281
|
call(input: Record<string, unknown>, context: ViteHubMcpToolContext): Promise<ViteHubMcpToolResult>;
|
|
255
282
|
}
|
|
256
|
-
//#endregion
|
|
257
|
-
//#region src/runtime/mcp.d.ts
|
|
258
283
|
interface CommentsMcpToolsOptions {
|
|
259
284
|
/**
|
|
260
285
|
* The caller passed the Console access check of the `comments` section, as the comment operations do. `authorize`
|
|
@@ -270,8 +295,6 @@ interface CommentsMcpToolsOptions {
|
|
|
270
295
|
* checked `context.user`. Replies and resolves show that user as the author.
|
|
271
296
|
*/
|
|
272
297
|
export declare function commentsMcpTools(comments: Comments, options?: CommentsMcpToolsOptions): ViteHubMcpTool[];
|
|
273
|
-
//#endregion
|
|
274
|
-
//#region ../internal/src/runtime/mcp-server.d.ts
|
|
275
298
|
type ToolResultContent = ({
|
|
276
299
|
type: "text";
|
|
277
300
|
text: string;
|
|
@@ -286,14 +309,4 @@ export declare function mcpToolResult(result: ViteHubMcpToolResult): {
|
|
|
286
309
|
structuredContent?: Record<string, unknown>;
|
|
287
310
|
isError: boolean;
|
|
288
311
|
};
|
|
289
|
-
//#endregion
|
|
290
|
-
//#region ../internal/src/runtime/page-tools.d.ts
|
|
291
|
-
/**
|
|
292
|
-
* The route of `GET /_vitehub/page/tools`: a Fetchable (https://fetchable.org). `installViteHubPageTools()` binds
|
|
293
|
-
* each Request to its app in Nitro's `request` hook, so the route finds the tools of that app.
|
|
294
|
-
*/
|
|
295
|
-
export declare const viteHubPageSessionHandler: {
|
|
296
|
-
fetch(request: Request): Promise<Response>;
|
|
297
|
-
};
|
|
298
|
-
//#endregion
|
|
299
312
|
export type { CommentsContent, CommentsContentField, CommentsDatabaseRegistry, CommentsGitHubLogin, CommentsHandlerOptions, CommentsMcpToolsOptions, CommentsPluginOptions };
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import { t as
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { t as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { c as validateCommentsDefinition, o as deniedForMissingPolicy } from "../define-
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { t as
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
1
|
+
import { a as runWithActiveCloudflareEnv, i as getActiveCloudflareBinding, r as rememberGitHubToken, t as forgetGitHubToken } from "../tokens-Bx4lZ0yt.js";
|
|
2
|
+
import { t as forwardedRequestOrigin } from "../request-origin-YPzfE2eh.js";
|
|
3
|
+
import "../client-files-lC6X7XyS.js";
|
|
4
|
+
import { t as commentsErrors } from "../errors-C0VwRHiy.js";
|
|
5
|
+
import { i as text, n as guestFromHeaders, t as authorOf } from "../identity-CT7-UGmS.js";
|
|
6
|
+
import { a as runtimeOf, r as resolveCommentsRuntime, t as commentSendOf } from "../installed-C9SkldMi.js";
|
|
7
|
+
import { a as commentThreadSummary, c as hiddenThreadsNote, n as commentAnchorSchema, o as commentThreadsText, r as commentInputSchemas, s as describeCommentThread, t as commentActions } from "../operations-B8IMhRmY.js";
|
|
8
|
+
import { c as validateCommentsDefinition, o as deniedForMissingPolicy } from "../define-BCxNaSZv.js";
|
|
9
|
+
import { h as readAttachment, i as contextSchema, n as base64, o as deniedError, p as mentionedPeople, r as can } from "../service-DUh2uGd2.js";
|
|
10
|
+
import { i as commentsRoute, n as commentsPageScope, o as normalizeCommentPage } from "../page-xzgZ6DGm.js";
|
|
11
|
+
import { n as resolveCommentsPage, o as viteHubPageSessionHandler, t as resolveCommentsIdentity } from "../session-_1GY5gaG.js";
|
|
12
|
+
import { n as installedComments, t as defineCommentsPlugin } from "../plugin-DbCYT7Ac.js";
|
|
13
|
+
import { t as invariant } from "../invariant-CmdvZ3vp.js";
|
|
14
|
+
import { t as commentsErrorDiagnostics } from "../errors-DFNiJg67.js";
|
|
15
15
|
import { getStandardContext, installRequestStandardContext } from "@vite-hub/runtime/internal/h3";
|
|
16
16
|
import * as v from "valibot";
|
|
17
|
+
import { configuredConsoleOrigin } from "@vite-hub/runtime/internal/console";
|
|
17
18
|
import { defineGrant } from "@vite-hub/runtime/internal/grant";
|
|
18
19
|
import { hkdfSync } from "node:crypto";
|
|
19
20
|
import { defineAuth } from "@vite-hub/auth";
|
|
20
21
|
import { stateless } from "@vite-hub/auth/presets";
|
|
21
|
-
|
|
22
|
+
// src/runtime/handler.ts
|
|
22
23
|
const fieldEditGrant = defineGrant("vitehub.comments.field-edit", (input) => input);
|
|
23
24
|
const pageSchema = v.pipe(v.string(), v.startsWith("/", "A page starts with `/`."), v.maxLength(1024));
|
|
24
25
|
/** `POST /threads`: the input of `comments.create`, or a `page` instead of the subject, and the page context of the overlay. */
|
|
@@ -282,6 +283,10 @@ function createCommentsHandler(options) {
|
|
|
282
283
|
} : void 0;
|
|
283
284
|
const signOut = user && user.github && github ? `${route}/auth/sign-out` : void 0;
|
|
284
285
|
const send = Boolean(comments.options.send && user && !user.guest && comment && await commentSendOf(comments));
|
|
286
|
+
const agent = identity.commentsAgent && read ? {
|
|
287
|
+
...identity.commentsAgent,
|
|
288
|
+
mcp: `${configuredConsoleOrigin()}/mcp/account`
|
|
289
|
+
} : void 0;
|
|
285
290
|
return json({ data: {
|
|
286
291
|
user: user ? authorOf(user) : null,
|
|
287
292
|
...user && user.github ? { github: user.github } : {},
|
|
@@ -294,9 +299,11 @@ function createCommentsHandler(options) {
|
|
|
294
299
|
...signIn ? { signIn } : {},
|
|
295
300
|
...signOut ? { signOut } : {},
|
|
296
301
|
realtime: options.realtime,
|
|
302
|
+
...options.attachments === false ? { attachments: false } : {},
|
|
297
303
|
...options.presence === false ? { presence: false } : {},
|
|
298
304
|
content: Boolean(options.content),
|
|
299
305
|
...send ? { send: true } : {},
|
|
306
|
+
...agent ? { agent } : {},
|
|
300
307
|
...subject ? { subject } : {},
|
|
301
308
|
...revision === void 0 ? {} : { revision }
|
|
302
309
|
} });
|
|
@@ -697,8 +704,7 @@ function createCommentsHandler(options) {
|
|
|
697
704
|
} }, { status: 404 });
|
|
698
705
|
}
|
|
699
706
|
}
|
|
700
|
-
|
|
701
|
-
//#region src/runtime/database.ts
|
|
707
|
+
// src/runtime/database.ts
|
|
702
708
|
/**
|
|
703
709
|
* The Database that `defineComments({ database })` names, else `default`, else the only one. The plugin calls it when
|
|
704
710
|
* the server starts. On Cloudflare that is before any request, so a D1 Database can't connect yet: its db throws until
|
|
@@ -721,8 +727,7 @@ function isPlaceholder(db) {
|
|
|
721
727
|
return code === "DATABASE_DISABLED" || code === "DATABASE_NOT_FOUND";
|
|
722
728
|
}
|
|
723
729
|
}
|
|
724
|
-
|
|
725
|
-
//#region src/runtime/definition.ts
|
|
730
|
+
// src/runtime/definition.ts
|
|
726
731
|
/**
|
|
727
732
|
* The Comments definition of `server/comments.ts`: its `comments` export, else its default export. Both forms run the
|
|
728
733
|
* same surfaces. The generated files call it, so a file without `defineComments()` fails with `COMMENTS_B0002`.
|
|
@@ -730,8 +735,7 @@ function isPlaceholder(db) {
|
|
|
730
735
|
function commentsDefinitionOf(module, file) {
|
|
731
736
|
return validateCommentsDefinition(module.comments ?? module.default, file);
|
|
732
737
|
}
|
|
733
|
-
|
|
734
|
-
//#region src/runtime/mcp.ts
|
|
738
|
+
// src/runtime/mcp.ts
|
|
735
739
|
/** A user supplied by an app's own MCP server. Missing identities remain anonymous. */
|
|
736
740
|
function commentsUser(user) {
|
|
737
741
|
const id = text(user?.id) ?? text(user?.email);
|
|
@@ -1103,8 +1107,7 @@ function commentsMcpTools(comments, options = {}) {
|
|
|
1103
1107
|
});
|
|
1104
1108
|
return tools;
|
|
1105
1109
|
}
|
|
1106
|
-
|
|
1107
|
-
//#region ../internal/src/runtime/mcp-server.ts
|
|
1110
|
+
// ../internal/src/runtime/mcp-server.ts
|
|
1108
1111
|
/** The MCP result of a `ViteHubMcpTool` call: a text block, then one image block for each image. */
|
|
1109
1112
|
function mcpToolResult(result) {
|
|
1110
1113
|
const content = [{
|
|
@@ -1131,8 +1134,7 @@ function readViteHubSecret(env) {
|
|
|
1131
1134
|
return typeof value === "string" && value ? value : void 0;
|
|
1132
1135
|
}
|
|
1133
1136
|
Object.freeze({ prefix: "sha256=" });
|
|
1134
|
-
|
|
1135
|
-
//#region src/runtime/github-login.ts
|
|
1137
|
+
// src/runtime/github-login.ts
|
|
1136
1138
|
/** The Server Env names of the OAuth client that people sign in to Comments with: a GitHub App's, or an OAuth App's. */
|
|
1137
1139
|
const githubLoginEnv = {
|
|
1138
1140
|
clientId: "VITEHUB_GITHUB_CLIENT_ID",
|
|
@@ -1311,5 +1313,4 @@ function createCommentsGitHubLogin(options = {}) {
|
|
|
1311
1313
|
}
|
|
1312
1314
|
};
|
|
1313
1315
|
}
|
|
1314
|
-
//#endregion
|
|
1315
1316
|
export { commentsDefinitionOf, commentsMcpTools, createCommentsGitHubLogin, createCommentsHandler, defineCommentsPlugin, githubLoginEnv, installedComments, mcpToolResult, selectCommentsDatabase, viteHubPageSessionHandler };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as commentsErrorDiagnostics } from "./errors-
|
|
2
|
-
|
|
1
|
+
import { t as commentsErrorDiagnostics } from "./errors-DFNiJg67.js";
|
|
2
|
+
// src/operations-core/server.ts
|
|
3
3
|
const key = Symbol.for("vitehub.comments.runtime");
|
|
4
4
|
const scope = globalThis;
|
|
5
5
|
/**
|
|
@@ -68,5 +68,4 @@ function createAuthUsers(getAuth) {
|
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
-
//#endregion
|
|
72
71
|
export { installCommentsRuntime as i, createAuthUsers as n, hasCommentsRuntime as r, commentsRuntime as t };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { b as validateCommentsDefinition, d as CommentsPeople } from "./define-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { a as commentsOperations, i as commentInputSchemas, n as commentActions, r as commentAnchorSchema, t as CommentsCaller } from "./operations-
|
|
5
|
-
import { n as createRpcTransport, t as RpcTransportOptions } from "./rpc-
|
|
6
|
-
import { n as installComments, t as InstallCommentsOptions } from "./install-
|
|
7
|
-
//#region src/operations-core/server.d.ts
|
|
1
|
+
import { b as validateCommentsDefinition, d as CommentsPeople } from "./define-B1jLSPe9.js";
|
|
2
|
+
import { a as maximumCommentBodyLength, i as CommentsRuntime, n as CommentsAttachmentStore, r as CommentsForgeHooks } from "./service-CPiWPoiY.js";
|
|
3
|
+
import { i as createCommentsStore, n as CommentsStore, r as CommentsTables, t as CommentsDatabase } from "./store-DvNTDNgn.js";
|
|
4
|
+
import { a as commentsOperations, i as commentInputSchemas, n as commentActions, r as commentAnchorSchema, t as CommentsCaller } from "./operations-Cic9A9e_.js";
|
|
5
|
+
import { n as createRpcTransport, t as RpcTransportOptions } from "./rpc-D-eqtyfh.js";
|
|
6
|
+
import { n as installComments, t as InstallCommentsOptions } from "./install-NehuMNhG.js";
|
|
8
7
|
/** Where mentions find people. The same shape as `defineComments({ people })`. */
|
|
9
8
|
export type CommentsUsers = CommentsPeople;
|
|
10
9
|
/**
|
|
@@ -17,5 +16,4 @@ export declare function commentsRuntime(): Promise<CommentsRuntime>;
|
|
|
17
16
|
export declare function hasCommentsRuntime(): boolean;
|
|
18
17
|
/** People from a Better Auth instance, through its internal adapter. The generated Nitro plugin passes it when the app has Auth. */
|
|
19
18
|
export declare function createAuthUsers(getAuth: () => object | Promise<object>): CommentsPeople;
|
|
20
|
-
//#endregion
|
|
21
19
|
export { type CommentsAttachmentStore, CommentsCaller, type CommentsDatabase, type CommentsForgeHooks, type CommentsRuntime, type CommentsStore, type CommentsTables, type InstallCommentsOptions, RpcTransportOptions, commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, createCommentsStore, createRpcTransport, installComments, maximumCommentBodyLength, validateCommentsDefinition };
|
package/dist/server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { r as
|
|
2
|
-
import { i as commentsOperations, n as commentAnchorSchema, r as commentInputSchemas, t as commentActions } from "./operations-
|
|
3
|
-
import { t as createRpcTransport } from "./rpc-
|
|
4
|
-
import { f as maximumCommentBodyLength } from "./service-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { i as installCommentsRuntime, n as createAuthUsers, r as hasCommentsRuntime, t as commentsRuntime } from "./server-BGbD7H5s.js";
|
|
2
|
+
import { i as commentsOperations, n as commentAnchorSchema, r as commentInputSchemas, t as commentActions } from "./operations-B8IMhRmY.js";
|
|
3
|
+
import { t as createRpcTransport } from "./rpc-BKY7XRlR.js";
|
|
4
|
+
import { f as maximumCommentBodyLength } from "./service-DUh2uGd2.js";
|
|
5
|
+
import { r as createCommentsStore, t as installComments } from "./install-w6CCgGFV.js";
|
|
6
|
+
import { c as validateCommentsDefinition } from "./define-BCxNaSZv.js";
|
|
7
7
|
export { commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, commentsRuntime, createAuthUsers, createCommentsStore, createRpcTransport, hasCommentsRuntime, installComments, installCommentsRuntime, maximumCommentBodyLength, validateCommentsDefinition };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { d as CommentsPeople, g as CommentsUser, l as CommentsDefinition } from "./define-B1jLSPe9.js";
|
|
2
|
+
import { n as CommentsStore } from "./store-DvNTDNgn.js";
|
|
3
|
+
import { T as CommentThread } from "./types-BX3vH18p.js";
|
|
4
4
|
import "valibot";
|
|
5
|
-
//#region ../internal/src/runtime/client-rate-limit.d.ts
|
|
6
5
|
/** The part of `checkRateLimit()` from `vite-hub/rate-limit` that a public write calls. */
|
|
7
6
|
type SharedRateLimit = (request: Request, name: string, options: {
|
|
8
7
|
key: string;
|
|
@@ -14,8 +13,6 @@ type SharedRateLimit = (request: Request, name: string, options: {
|
|
|
14
13
|
retryAfter?: number;
|
|
15
14
|
cause?: unknown;
|
|
16
15
|
} | undefined]>;
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region src/operations-core/service.d.ts
|
|
19
16
|
/** Longest message, in characters. */
|
|
20
17
|
declare const maximumCommentBodyLength = 10000;
|
|
21
18
|
/** The parts of a Blob store that attachments use: `blob` of `@vite-hub/blob`. */
|
|
@@ -69,5 +66,4 @@ interface CommentsRuntime {
|
|
|
69
66
|
/** Runs after someone opens a thread again. With Send, it puts back the sends that carried the thread. */
|
|
70
67
|
reopened?: (thread: CommentThread) => Promise<unknown>;
|
|
71
68
|
}
|
|
72
|
-
//#endregion
|
|
73
69
|
export { maximumCommentBodyLength as a, CommentsRuntime as i, CommentsAttachmentStore as n, SharedRateLimit as o, CommentsForgeHooks as r, CommentsAttachmentBody as t };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { t as replyMessageId } from "./reply-id-
|
|
2
|
-
import { t as commentsErrorDiagnostics } from "./errors-
|
|
3
|
-
import { t as isPagePath } from "./path
|
|
4
|
-
import { t as foldName } from "./fold-name-
|
|
5
|
-
import { r as guestIdPrefix } from "./identity-
|
|
6
|
-
import { i as defaultPolicy, o as deniedForMissingPolicy, t as builtinCommentSubjects } from "./define-
|
|
7
|
-
import { t as logFailure } from "./request-log-
|
|
1
|
+
import { t as replyMessageId } from "./reply-id-Cm9FGOBs.js";
|
|
2
|
+
import { t as commentsErrorDiagnostics } from "./errors-DFNiJg67.js";
|
|
3
|
+
import { t as isPagePath } from "./path-8yqMd8zR.js";
|
|
4
|
+
import { t as foldName } from "./fold-name-g-xg0mQk.js";
|
|
5
|
+
import { r as guestIdPrefix } from "./identity-CT7-UGmS.js";
|
|
6
|
+
import { i as defaultPolicy, o as deniedForMissingPolicy, t as builtinCommentSubjects } from "./define-BCxNaSZv.js";
|
|
7
|
+
import { t as logFailure } from "./request-log-DllKQXj7.js";
|
|
8
8
|
import * as v from "valibot";
|
|
9
|
-
|
|
9
|
+
// ../internal/src/runtime/client-rate-limit.ts
|
|
10
10
|
const windowPattern = /^(\d+)(ms|s|m|h|d)$/;
|
|
11
11
|
const units = {
|
|
12
12
|
ms: 1,
|
|
@@ -90,8 +90,7 @@ function createClientRateLimit(options) {
|
|
|
90
90
|
return memory(key, policy);
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
-
|
|
94
|
-
//#region src/operations-core/service.ts
|
|
93
|
+
// src/operations-core/service.ts
|
|
95
94
|
/** Longest message, in characters. */
|
|
96
95
|
const maximumCommentBodyLength = 1e4;
|
|
97
96
|
/** Largest attachment, in bytes. */
|
|
@@ -662,5 +661,4 @@ async function readAttachment(runtime, key, context) {
|
|
|
662
661
|
type
|
|
663
662
|
};
|
|
664
663
|
}
|
|
665
|
-
//#endregion
|
|
666
664
|
export { clientAddressKey as C, suggest as S, createClientRateLimit as T, requestIdSchema as _, createThread as a, scopeOf as b, earlierThread as c, maximumAttachmentBytes as d, maximumCommentBodyLength as f, replyToThread as g, readAttachment as h, contextSchema as i, editMessage as l, personOf as m, base64 as n, deniedError as o, mentionedPeople as p, can as r, earlierReply as s, attachmentThread as t, fail as u, retried as v, clientRateLimitIssue as w, storeAttachment as x, retriedReply as y };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import "./
|
|
4
|
-
//#region src/runtime/session.d.ts
|
|
1
|
+
import "./index-D1T7RJ4R.js";
|
|
2
|
+
import { g as CommentsUser } from "./define-B1jLSPe9.js";
|
|
3
|
+
import { f as CommentsRequestEvent } from "./types-l6GOb_yc.js";
|
|
5
4
|
interface CommentsSessionOptions {
|
|
6
5
|
/** Reads the ViteHub Auth user only when no custom `identify` is configured. */
|
|
7
6
|
session?: (event: CommentsRequestEvent) => Promise<CommentsUser | null | undefined>;
|
|
@@ -10,5 +9,4 @@ interface CommentsSessionOptions {
|
|
|
10
9
|
user: (event: CommentsRequestEvent) => Promise<CommentsUser | null>;
|
|
11
10
|
};
|
|
12
11
|
}
|
|
13
|
-
//#endregion
|
|
14
12
|
export { CommentsSessionOptions as t };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { o as
|
|
2
|
-
import { r as matchesPublicOrigin, t as forwardedRequestOrigin } from "./request-origin-
|
|
3
|
-
import {
|
|
1
|
+
import { f as viteHubPageToolsWanted, l as viteHubPageToolsLoader, n as viteHubBasePath, o as viteHubPageToolsHintCookie, p as withViteHubBase, r as viteHubPageSessionPath, s as viteHubPageToolsInlineScript, t as readViteHubPageAccount, u as viteHubPageToolsMarker } from "./page-tools-shared-fvmJQCrP.js";
|
|
2
|
+
import { r as matchesPublicOrigin, t as forwardedRequestOrigin } from "./request-origin-YPzfE2eh.js";
|
|
3
|
+
import { o as normalizeCommentPage } from "./page-xzgZ6DGm.js";
|
|
4
4
|
import { getStandardContext } from "@vite-hub/runtime/internal/h3";
|
|
5
|
-
|
|
5
|
+
// ../internal/src/runtime/page-tools-html.ts
|
|
6
6
|
/** The effective script-element directive is shared by HTTP and HTML meta policies. */
|
|
7
7
|
function scriptPolicyNonce(policy) {
|
|
8
8
|
const directives = policy.split(";").map((part) => part.trim());
|
|
@@ -144,7 +144,7 @@ function pageToolsHtmlTransform(loader) {
|
|
|
144
144
|
}
|
|
145
145
|
if (!closing && name && /^(script|style|textarea|title|xmp|iframe|noembed|noframes|noscript|plaintext)$/.test(name)) {
|
|
146
146
|
rawText = name;
|
|
147
|
-
if (!templates && token.replace(/ nonce="[\w+/=-]+"/, "") ===
|
|
147
|
+
if (!templates && token.replace(/ nonce="[\w+/=-]+"/, "") === "<script type=\"module\" data-vitehub-page-tools>") {
|
|
148
148
|
inline = token;
|
|
149
149
|
present = true;
|
|
150
150
|
continue;
|
|
@@ -163,8 +163,7 @@ function pageToolsHtmlTransform(loader) {
|
|
|
163
163
|
}
|
|
164
164
|
});
|
|
165
165
|
}
|
|
166
|
-
|
|
167
|
-
//#region ../internal/src/runtime/page-tools.ts
|
|
166
|
+
// ../internal/src/runtime/page-tools.ts
|
|
168
167
|
const stateKey = Symbol.for("vitehub.page-tools");
|
|
169
168
|
const scope = globalThis;
|
|
170
169
|
function state() {
|
|
@@ -199,6 +198,13 @@ async function readAccount(nitroApp, request) {
|
|
|
199
198
|
return;
|
|
200
199
|
}
|
|
201
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Installs the reader of the Site access cookie. The Console installs it when the server starts, so page tools, such as
|
|
203
|
+
* Comments, know the person without depending on the Console.
|
|
204
|
+
*/
|
|
205
|
+
function installViteHubSiteVisitor(reader) {
|
|
206
|
+
state().siteVisitor = reader;
|
|
207
|
+
}
|
|
202
208
|
/** The reader of the Site access cookie, or undefined in an app where the Console did not install one. */
|
|
203
209
|
function viteHubSiteVisitorReader() {
|
|
204
210
|
return state().siteVisitor;
|
|
@@ -433,10 +439,9 @@ function installViteHubPageTools(nitroApp, options = {}) {
|
|
|
433
439
|
return;
|
|
434
440
|
}
|
|
435
441
|
}
|
|
436
|
-
|
|
437
|
-
//#region src/runtime/session.ts
|
|
442
|
+
// src/runtime/session.ts
|
|
438
443
|
/**
|
|
439
|
-
* The person that Site access in the Console signed in to
|
|
444
|
+
* The person that Site access in the ViteHub Console signed in to the app, with their roles in `role`, as
|
|
440
445
|
* `commentsRoleAllows()` reads them. A Console member has `comments-*` roles, a guest the roles of the invite.
|
|
441
446
|
*/
|
|
442
447
|
async function siteUser(event) {
|
|
@@ -444,17 +449,23 @@ async function siteUser(event) {
|
|
|
444
449
|
if (!read) return null;
|
|
445
450
|
const visitor = await read(getStandardContext(event).req).catch(() => void 0);
|
|
446
451
|
if (!visitor) return null;
|
|
447
|
-
const { roles, ...person } = visitor;
|
|
448
452
|
return {
|
|
449
|
-
|
|
450
|
-
|
|
453
|
+
user: {
|
|
454
|
+
id: visitor.id,
|
|
455
|
+
name: visitor.name,
|
|
456
|
+
...visitor.email ? { email: visitor.email } : {},
|
|
457
|
+
...visitor.image ? { image: visitor.image } : {},
|
|
458
|
+
role: visitor.roles.join(",")
|
|
459
|
+
},
|
|
460
|
+
gate: {},
|
|
461
|
+
...visitor.kind === "member" && visitor.commentsAgent ? { commentsAgent: visitor.commentsAgent } : {}
|
|
451
462
|
};
|
|
452
463
|
}
|
|
453
464
|
/**
|
|
454
465
|
* The user of a request, shared by the overlay API, Realtime presence, the MCP tools, and the comment operations.
|
|
455
466
|
* With `identify`, the app decides: `identify` names the user, `null` is anonymous, and `authorize` decides what they may do. Without
|
|
456
|
-
* `identify`, it is the
|
|
457
|
-
*
|
|
467
|
+
* `identify`, it is the person of the Site access cookie. Then, when there is none, the user of `session`, the ViteHub
|
|
468
|
+
* Auth user, and last the person signed in with GitHub.
|
|
458
469
|
*/
|
|
459
470
|
async function resolveCommentsIdentity(comments, event, options = {}) {
|
|
460
471
|
if (comments.options.identify) {
|
|
@@ -464,8 +475,10 @@ async function resolveCommentsIdentity(comments, event, options = {}) {
|
|
|
464
475
|
gate: {}
|
|
465
476
|
};
|
|
466
477
|
}
|
|
478
|
+
const site = await siteUser(event);
|
|
479
|
+
if (site) return site;
|
|
467
480
|
return {
|
|
468
|
-
user: await options.session?.(event).catch(() => null) ?? await
|
|
481
|
+
user: await options.session?.(event).catch(() => null) ?? await options.githubLogin?.user(event).catch(() => null) ?? null,
|
|
469
482
|
gate: {}
|
|
470
483
|
};
|
|
471
484
|
}
|
|
@@ -496,5 +509,4 @@ async function resolveCommentsPage(comments, event, request, path) {
|
|
|
496
509
|
...mapped.revision === void 0 ? {} : { revision: mapped.revision }
|
|
497
510
|
};
|
|
498
511
|
}
|
|
499
|
-
|
|
500
|
-
export { viteHubPageSessionHandler as a, registerViteHubPageTool as i, resolveCommentsPage as n, installViteHubPageTools as r, resolveCommentsIdentity as t };
|
|
512
|
+
export { registerViteHubPageTool as a, installViteHubSiteVisitor as i, resolveCommentsPage as n, viteHubPageSessionHandler as o, installViteHubPageTools as r, resolveCommentsIdentity as t };
|