@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.
- package/LICENSE +201 -0
- package/README.md +291 -0
- package/dist/anchor.d.ts +43 -0
- package/dist/anchor.js +133 -0
- package/dist/client-diagnostics-CcFpkbAk.js +40 -0
- package/dist/client.d.ts +176 -0
- package/dist/client.js +738 -0
- package/dist/console-h4KlhIik.d.ts +332 -0
- package/dist/context-BqIsmYP1.js +61 -0
- package/dist/database/postgres.d.ts +1402 -0
- package/dist/database/postgres.js +81 -0
- package/dist/database-CA1aHKN7.d.ts +1495 -0
- package/dist/database.d.ts +12 -0
- package/dist/database.js +2 -0
- package/dist/define-43mMR39K.js +89 -0
- package/dist/define-B3TF9zzn.d.ts +204 -0
- package/dist/errors-4gelGVmK.js +57 -0
- package/dist/errors-C6qptPoG.js +135 -0
- package/dist/errors-CyQyKAvy.d.ts +185 -0
- package/dist/fold-name-B7Zb3-MF.js +7 -0
- package/dist/identity-CBOzgxSf.js +39 -0
- package/dist/index-DNhy69Wt.d.ts +83 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +196 -0
- package/dist/install-BcMPgPk_.js +1154 -0
- package/dist/install-W9ghhGoh.d.ts +36 -0
- package/dist/installed-B-PfERBU.js +30 -0
- package/dist/invariant-D8_xBqmZ.js +22 -0
- package/dist/migrate-B0k_0swk.d.ts +54 -0
- package/dist/migrate-BDQ8xqUs.js +289 -0
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/operations-D4A1Fcgf.d.ts +160 -0
- package/dist/operations-DMMIfYPW.js +1159 -0
- package/dist/operations-GLeOqgMt.d.ts +257 -0
- package/dist/operations.d.ts +3 -0
- package/dist/operations.js +3 -0
- package/dist/overlay/client-DmsSMOzi.js +4 -0
- package/dist/overlay/dist-BoHMOFax.js +14 -0
- package/dist/overlay/dist-yIZmvSaU.js +1 -0
- package/dist/overlay/overlay.js +201 -0
- package/dist/page/loader.js +142 -0
- package/dist/page-B41ozN63.js +40 -0
- package/dist/page-DtbMOEMd.d.ts +22 -0
- package/dist/page-tools-shared-NHUjKI8E.js +117 -0
- package/dist/path--zk6PEMz.js +18 -0
- package/dist/plugin-PS8PMYus.js +74 -0
- package/dist/realtime.d.ts +12 -0
- package/dist/realtime.js +47 -0
- package/dist/rpc-HBcWtg0T.d.ts +17 -0
- package/dist/rpc-RKPAusHp.js +153 -0
- package/dist/rpc.d.ts +2 -0
- package/dist/rpc.js +2 -0
- package/dist/runtime/auth.d.ts +8 -0
- package/dist/runtime/auth.js +18 -0
- package/dist/runtime/connect/node.d.ts +1 -0
- package/dist/runtime/connect/node.js +2 -0
- package/dist/runtime/connect.d.ts +1 -0
- package/dist/runtime/connect.js +2 -0
- package/dist/runtime/console.d.ts +5 -0
- package/dist/runtime/console.js +64 -0
- package/dist/runtime/index.d.ts +270 -0
- package/dist/runtime/index.js +1113 -0
- package/dist/server-D8k-0GXe.js +72 -0
- package/dist/server.d.ts +20 -0
- package/dist/server.js +7 -0
- package/dist/service-CFVm23k7.d.ts +158 -0
- package/dist/service-GHhhyQj4.js +609 -0
- package/dist/session-DVx-1Tym.d.ts +14 -0
- package/dist/session-EkudzUmm.js +503 -0
- package/dist/testing.d.ts +30 -0
- package/dist/testing.js +187 -0
- package/dist/tokens-DSbwkVSy.js +58 -0
- package/dist/types-BIS0hCEl.d.ts +124 -0
- package/dist/types-CZujrMFd.d.ts +322 -0
- package/dist/vite.d.ts +308 -0
- package/dist/vite.js +1660 -0
- package/package.json +153 -4
|
@@ -0,0 +1,1159 @@
|
|
|
1
|
+
import { t as commentsErrorDiagnostics } from "./errors-C6qptPoG.js";
|
|
2
|
+
import { n as pagePathOf, t as isPagePath } from "./path--zk6PEMz.js";
|
|
3
|
+
import { n as isRecordOrFunction } from "./object-Da1zyPCR.js";
|
|
4
|
+
import { S as createClientRateLimit, a as deniedError, b as clientAddressKey, c as fail, f as personOf, g as retried, h as requestIdSchema, i as createThread, l as maximumAttachmentBytes, m as replyToThread, n as can, o as earlierThread, p as readAttachment, s as editMessage, t as attachmentThread, u as maximumCommentBodyLength, v as storeAttachment, y as suggest } from "./service-GHhhyQj4.js";
|
|
5
|
+
import { n as guestFromHeaders, t as authorOf } from "./identity-CBOzgxSf.js";
|
|
6
|
+
import { t as describeCommentContext } from "./context-BqIsmYP1.js";
|
|
7
|
+
import { t as commentsRuntime } from "./server-D8k-0GXe.js";
|
|
8
|
+
import { defineDiagnostics } from "nostics";
|
|
9
|
+
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
10
|
+
import { getStandardContext } from "@vite-hub/runtime/internal/h3";
|
|
11
|
+
import * as v from "valibot";
|
|
12
|
+
//#region ../internal/src/error-diagnostics.ts
|
|
13
|
+
const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
|
|
14
|
+
const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
15
|
+
docsBase: "https://vitehub.dev/docs/development/diagnostics",
|
|
16
|
+
codes: {
|
|
17
|
+
INTERNAL_R0012: {
|
|
18
|
+
...dynamicError,
|
|
19
|
+
fix: "Check the URL, the headers, and the credentials of the HTTP request. `error.status` holds the status that the server sent."
|
|
20
|
+
},
|
|
21
|
+
INTERNAL_R0013: {
|
|
22
|
+
...dynamicError,
|
|
23
|
+
fix: "Check that the provider token can manage the resource in the path that the message names. `error.kind` and `error.codes` hold the provider failure."
|
|
24
|
+
},
|
|
25
|
+
INTERNAL_R0014: {
|
|
26
|
+
why: ({ path }) => `Cannot read Provision State from "${path}".`,
|
|
27
|
+
fix: "Check file access and restore valid JSON while preserving existing resource IDs."
|
|
28
|
+
},
|
|
29
|
+
INTERNAL_R0020: {
|
|
30
|
+
fix: "Give the operation a name like `content.publish`, a description, a section, a kind, an input schema, and a run function.",
|
|
31
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
32
|
+
},
|
|
33
|
+
INTERNAL_R0021: {
|
|
34
|
+
fix: "Run `vitehub inspect definitions --kind operation` to list the operations of this app.",
|
|
35
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
36
|
+
},
|
|
37
|
+
INTERNAL_R0022: {
|
|
38
|
+
fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields.",
|
|
39
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
40
|
+
},
|
|
41
|
+
INTERNAL_R0024: {
|
|
42
|
+
fix: "Start the dev server with `vite dev`, or pass `--url <origin>` of a deployed app and set VITEHUB_CONSOLE_PRIVATE_KEY_<NAME> to a private key whose public key the app has in VITEHUB_CONSOLE_KEY_<NAME>.",
|
|
43
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
44
|
+
},
|
|
45
|
+
INTERNAL_R0023: {
|
|
46
|
+
fix: "Ask for access to the section of this operation.",
|
|
47
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
48
|
+
},
|
|
49
|
+
INTERNAL_B0001: {
|
|
50
|
+
...dynamicError,
|
|
51
|
+
fix: "Give the resource that the message names another name or binding in the `vitehub()` options of its feature, so that two different Cloudflare resources do not share one name."
|
|
52
|
+
},
|
|
53
|
+
INTERNAL_B0015: {
|
|
54
|
+
...dynamicError,
|
|
55
|
+
fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`."
|
|
56
|
+
},
|
|
57
|
+
INTERNAL_B0016: {
|
|
58
|
+
...dynamicError,
|
|
59
|
+
fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
|
|
60
|
+
},
|
|
61
|
+
INTERNAL_B0017: {
|
|
62
|
+
...dynamicError,
|
|
63
|
+
fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
|
|
64
|
+
},
|
|
65
|
+
INTERNAL_B0018: {
|
|
66
|
+
...dynamicError,
|
|
67
|
+
fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
|
|
68
|
+
},
|
|
69
|
+
INTERNAL_B0019: {
|
|
70
|
+
...dynamicError,
|
|
71
|
+
fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
|
|
72
|
+
},
|
|
73
|
+
INTERNAL_B0020: {
|
|
74
|
+
...dynamicError,
|
|
75
|
+
fix: "Correct the field that the message names in the `package.json` of a runtime dependency of the app, such as a workspace package, or run `pnpm install` again to restore an installed package."
|
|
76
|
+
},
|
|
77
|
+
INTERNAL_B0021: {
|
|
78
|
+
...dynamicError,
|
|
79
|
+
fix: "Install the package that the message names in the app, for example with `pnpm add <name>`, then build again."
|
|
80
|
+
},
|
|
81
|
+
INTERNAL_B0022: {
|
|
82
|
+
...dynamicError,
|
|
83
|
+
fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`."
|
|
84
|
+
},
|
|
85
|
+
INTERNAL_B0025: {
|
|
86
|
+
...dynamicError,
|
|
87
|
+
fix: "Replace the `new URL(\"./...\", import.meta.url)` in the project-root `main.ts`, or in a Schedule file of `server/schedules/` and the files it imports, with a static `import` of that file."
|
|
88
|
+
},
|
|
89
|
+
INTERNAL_B0026: {
|
|
90
|
+
...dynamicError,
|
|
91
|
+
fix: "Replace the computed `import()` in the project-root `main.ts`, or in a Schedule file of `server/schedules/` and the files it imports, with a static `import` or with `import(\"<literal path>\")`."
|
|
92
|
+
},
|
|
93
|
+
INTERNAL_B0027: {
|
|
94
|
+
...dynamicError,
|
|
95
|
+
fix: "Replace the computed `require()` in the project-root `main.ts`, or in a Schedule file of `server/schedules/` and the files it imports, with a static `import`."
|
|
96
|
+
},
|
|
97
|
+
INTERNAL_B0028: {
|
|
98
|
+
...dynamicError,
|
|
99
|
+
fix: "Wait for the other build of this app to finish, or stop the process that the message names, then build again."
|
|
100
|
+
},
|
|
101
|
+
INTERNAL_B0029: {
|
|
102
|
+
...dynamicError,
|
|
103
|
+
fix: "Stop the other builds that write the same Deno output folder, delete the `.vitehub-lock` folder next to that output folder, such as `.output.vitehub-lock`, then build again."
|
|
104
|
+
},
|
|
105
|
+
INTERNAL_B0031: {
|
|
106
|
+
...dynamicError,
|
|
107
|
+
fix: "Import `./schedule/deno-cron.mjs` at the top level of the project-root `main.ts`, for example with `await import(new URL(\"./schedule/deno-cron.mjs\", import.meta.url).href)` outside any condition."
|
|
108
|
+
},
|
|
109
|
+
INTERNAL_B0032: {
|
|
110
|
+
...dynamicError,
|
|
111
|
+
fix: "Import `./server/index.mjs` at the top level of the project-root `main.ts`, for example with `await import(new URL(\"./server/index.mjs\", import.meta.url).href)` outside any condition."
|
|
112
|
+
},
|
|
113
|
+
INTERNAL_B0035: {
|
|
114
|
+
...dynamicError,
|
|
115
|
+
fix: "Delete the provider output folder that holds the file that the message names, such as `dist/<app>` for Cloudflare, and build again."
|
|
116
|
+
},
|
|
117
|
+
INTERNAL_B0039: {
|
|
118
|
+
...dynamicError,
|
|
119
|
+
fix: "Fix the build error that ViteHub showed before this one. ViteHub stops writing the provider output when another part of the build fails."
|
|
120
|
+
},
|
|
121
|
+
INTERNAL_B0040: {
|
|
122
|
+
...dynamicError,
|
|
123
|
+
fix: "Remove the custom Nitro `output.serverDir`, so that the Nitro preset of the host writes the server entry that the message names."
|
|
124
|
+
},
|
|
125
|
+
INTERNAL_B0043: {
|
|
126
|
+
...dynamicError,
|
|
127
|
+
fix: "Delete the build output folder, such as `.output` or `.vercel/output`, and build again."
|
|
128
|
+
},
|
|
129
|
+
INTERNAL_B0046: {
|
|
130
|
+
...dynamicError,
|
|
131
|
+
fix: "Install the package that the message names in the app, for example with `pnpm add <name>`, then build again."
|
|
132
|
+
},
|
|
133
|
+
INTERNAL_B0047: {
|
|
134
|
+
...dynamicError,
|
|
135
|
+
fix: "Correct the `package.json` file that the message names so that it holds one JSON object, or run `pnpm install` again to restore an installed package."
|
|
136
|
+
},
|
|
137
|
+
INTERNAL_B0048: {
|
|
138
|
+
fix: "Rename one of the two operations. A name is `<section>.<verb>` and is unique in the app.",
|
|
139
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
140
|
+
},
|
|
141
|
+
INTERNAL_B0049: {
|
|
142
|
+
fix: "Set `cli: { namespace, command }` on one of the two operations.",
|
|
143
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
144
|
+
},
|
|
145
|
+
INTERNAL_B0050: {
|
|
146
|
+
fix: "Rename one of the two operations, or set `mcp: false` on it. MCP tool names replace every character outside letters, digits, `_`, and `-` with `_`.",
|
|
147
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
148
|
+
},
|
|
149
|
+
INTERNAL_B0051: {
|
|
150
|
+
why: ({ field, generated, name, path, project, scope }) => `The Cloudflare ${path} entry "${name}"${scope} is written by ViteHub and by the project's Wrangler config with a different ${field}: ${generated} and ${project}.`,
|
|
151
|
+
fix: "Remove the entry from the project's Wrangler config, since ViteHub writes it, or give one of them another name."
|
|
152
|
+
},
|
|
153
|
+
INTERNAL_B0052: {
|
|
154
|
+
why: ({ column, section }) => `The column "${column}" of the Console section "${section}" needs both \`format: "switch"\` and a \`switch\` operation name such as "skills.set".`,
|
|
155
|
+
fix: "Give a switch column `format: \"switch\"` and `switch: { operation, input }` with a registered operation name, or remove both."
|
|
156
|
+
},
|
|
157
|
+
INTERNAL_R0025: {
|
|
158
|
+
fix: "Start `vite dev` in the project that you run the command from, or pass `--url` of that server.",
|
|
159
|
+
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
160
|
+
},
|
|
161
|
+
INTERNAL_R0026: {
|
|
162
|
+
why: "The server parsed a destructive operation that the CLI did not confirm.",
|
|
163
|
+
fix: "Review the operation, then run it again with --yes to confirm the change."
|
|
164
|
+
},
|
|
165
|
+
INTERNAL_C0001: {
|
|
166
|
+
...dynamicError,
|
|
167
|
+
fix: "Rename or remove one of the two files that the message lists. ViteHub takes the Definition name from the file path."
|
|
168
|
+
},
|
|
169
|
+
INTERNAL_C0002: {
|
|
170
|
+
...dynamicError,
|
|
171
|
+
fix: "Rename or remove one of the two files that the message lists. ViteHub takes the Definition name from the file path."
|
|
172
|
+
},
|
|
173
|
+
INTERNAL_R0001: {
|
|
174
|
+
...dynamicError,
|
|
175
|
+
fix: "Set `host` in `vitehub()`, or in the `vitehub` options of `nuxt.config.ts`, to `cloudflare`, `deno`, `netlify`, `node`, or `vercel`. Or remove `host` so that ViteHub finds the host from the environment."
|
|
176
|
+
},
|
|
177
|
+
INTERNAL_R0002: {
|
|
178
|
+
...dynamicError,
|
|
179
|
+
fix: "Stop using the feature that the message names, or set `host` in `vitehub()` to a host that provides it. For Blob, you can also set `blob: { driver: \"s3\" }` with a remote store."
|
|
180
|
+
},
|
|
181
|
+
INTERNAL_R0004: {
|
|
182
|
+
...dynamicError,
|
|
183
|
+
fix: "Set a larger `maxResponseBytes` on the HTTP request, such as the `fetch()` Source options, or ask the server for a smaller response."
|
|
184
|
+
},
|
|
185
|
+
INTERNAL_R0005: {
|
|
186
|
+
...dynamicError,
|
|
187
|
+
fix: "Set `method` of the HTTP request to `GET`, `HEAD`, or `POST`."
|
|
188
|
+
},
|
|
189
|
+
INTERNAL_R0006: {
|
|
190
|
+
...dynamicError,
|
|
191
|
+
fix: "Set `timeout` of the HTTP request to a number of milliseconds from 1 to 2147483647, or remove it to use the default."
|
|
192
|
+
},
|
|
193
|
+
INTERNAL_R0007: {
|
|
194
|
+
...dynamicError,
|
|
195
|
+
fix: "Set `maxResponseBytes` of the HTTP request to a positive integer no greater than the limit that the message names, or remove it to use the default."
|
|
196
|
+
},
|
|
197
|
+
INTERNAL_R0008: {
|
|
198
|
+
...dynamicError,
|
|
199
|
+
fix: "Make the value that the message names match its schema: the input, query, or body that you send, or the response schema that you declare for the request."
|
|
200
|
+
},
|
|
201
|
+
INTERNAL_R0009: {
|
|
202
|
+
...dynamicError,
|
|
203
|
+
fix: "Use a Standard Schema whose `validate()` returns `{ value }` or `{ issues }` for the value that the message names."
|
|
204
|
+
},
|
|
205
|
+
INTERNAL_R0010: {
|
|
206
|
+
...dynamicError,
|
|
207
|
+
fix: "Run the command again. If the error stays, check the Cloudflare API status, because Cloudflare sent a response that ViteHub cannot read."
|
|
208
|
+
},
|
|
209
|
+
INTERNAL_R0011: {
|
|
210
|
+
...dynamicError,
|
|
211
|
+
fix: "Pass an h3 app, an object with a `fetch(request)` method, or a fetch function as `app`."
|
|
212
|
+
},
|
|
213
|
+
INTERNAL_CONSOLE_KEY_NAME_INVALID: {
|
|
214
|
+
why: ({ name }) => `[vitehub] The Console key name ${JSON.stringify(name)} must be 1 to 64 of A-Z, 0-9, and _.`,
|
|
215
|
+
fix: "Name the Console key with 1 to 64 characters from A-Z, 0-9, and _, such as `CI`. The app reads its public key from `VITEHUB_CONSOLE_KEY_<NAME>`."
|
|
216
|
+
},
|
|
217
|
+
INTERNAL_CONSOLE_PRIVATE_KEY_INVALID: {
|
|
218
|
+
why: "[vitehub] A Console private key is the 32-byte Ed25519 seed as base64url (43 characters). `vitehub secret console-key` makes one.",
|
|
219
|
+
fix: "Run `vitehub secret console-key` and use the 43-character private key that it prints, without spaces or quotes."
|
|
220
|
+
},
|
|
221
|
+
INTERNAL_CONSOLE_PRIVATE_KEY_VARIABLES_MULTIPLE: {
|
|
222
|
+
why: ({ prefix, variables }) => `[vitehub] Set one ${prefix}<NAME> variable. This environment has ${variables}.`,
|
|
223
|
+
fix: "Keep one `VITEHUB_CONSOLE_PRIVATE_KEY_<NAME>` variable in the environment of the command, and unset the others that the message names."
|
|
224
|
+
},
|
|
225
|
+
INTERNAL_CONSOLE_PRIVATE_KEY_VARIABLE_INVALID: {
|
|
226
|
+
why: ({ variable }) => `[vitehub] ${variable} must be the 43-character private key that \`vitehub secret console-key\` prints, and its name 1 to 64 of A-Z, 0-9, and _.`,
|
|
227
|
+
fix: "Set the variable that the message names to the private key that `vitehub secret console-key` prints, and name it `VITEHUB_CONSOLE_PRIVATE_KEY_<NAME>` with A-Z, 0-9, and _ in `<NAME>`."
|
|
228
|
+
},
|
|
229
|
+
INTERNAL_FORGE_NOT_INSTALLED: {
|
|
230
|
+
why: ({ feature }) => `${feature} needs @vite-hub/forge, and the app did not install it.`,
|
|
231
|
+
fix: "Install Forge in your app with `pnpm add @vite-hub/forge`, then build again."
|
|
232
|
+
},
|
|
233
|
+
INTERNAL_MCP_ARGUMENTS_INVALID: {
|
|
234
|
+
why: ({ detail }) => detail,
|
|
235
|
+
fix: "Pass the prompt or resource the arguments that `prompts/list` or `resources/templates/list` describes for it."
|
|
236
|
+
},
|
|
237
|
+
INTERNAL_MCP_METHOD_FAILED: {
|
|
238
|
+
why: ({ name }) => `${name} failed on the server.`,
|
|
239
|
+
fix: "Read the server log for the error of the MCP prompt or resource that the message names, and fix its handler."
|
|
240
|
+
},
|
|
241
|
+
INTERNAL_MCP_RESOURCE_NOT_FOUND: {
|
|
242
|
+
why: ({ uri }) => `Resource not found: ${uri}. Call resources/list or resources/templates/list for the resources of this server.`,
|
|
243
|
+
fix: "Call `resources/list` or `resources/templates/list`, and read a URI that one of them returns."
|
|
244
|
+
},
|
|
245
|
+
INTERNAL_PRESET_OPTION_UNKNOWN: {
|
|
246
|
+
why: ({ key, label }) => `[vitehub] Unknown ${label} option "${key}".`,
|
|
247
|
+
fix: "Remove the option that the message names from the preset options, or correct its spelling to an option that the preset declares."
|
|
248
|
+
},
|
|
249
|
+
INTERNAL_PRESET_TUPLE_INVALID: {
|
|
250
|
+
why: ({ owner }) => `[vitehub] ${owner} extends tuple requires [preset, options] with an options object.`,
|
|
251
|
+
fix: "Set `extends` to a preset, or to a two-item tuple `[preset, { ...options }]` whose second item is a plain object."
|
|
252
|
+
},
|
|
253
|
+
INTERNAL_SECRET_PURPOSE_MISSING: {
|
|
254
|
+
why: "[vitehub] A derived secret requires a purpose.",
|
|
255
|
+
fix: "Pass a non-empty purpose to `deriveSecret()`, such as `deriveSecret(\"my-module:session\")`."
|
|
256
|
+
},
|
|
257
|
+
INTERNAL_SECRET_TOO_SHORT: {
|
|
258
|
+
why: ({ minimum }) => `[vitehub] VITEHUB_SECRET must be at least ${minimum} characters. Generate one with \`openssl rand -base64 32\`.`,
|
|
259
|
+
fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters."
|
|
260
|
+
},
|
|
261
|
+
INTERNAL_SQLITE_ARGUMENT_INVALID: {
|
|
262
|
+
why: ({ value }) => value === "undefined" ? "undefined cannot be passed as argument to the database" : "Only finite numbers (not Infinity or NaN) can be passed as arguments",
|
|
263
|
+
fix: "Pass query arguments as finite numbers, strings, booleans, bigints, dates, byte arrays, or null. Replace undefined with null, and check numbers with `Number.isFinite()` before the query."
|
|
264
|
+
},
|
|
265
|
+
INTERNAL_SQLITE_INTEGER_UNSAFE: {
|
|
266
|
+
why: "Received integer which cannot be safely represented as a JavaScript number",
|
|
267
|
+
fix: "Create the client with `intMode: \"bigint\"` or `intMode: \"string\"`, or read the column with `CAST(column AS TEXT)` in the query."
|
|
268
|
+
},
|
|
269
|
+
INTERNAL_VALIBOT_JSON_SCHEMA_TARGET_UNSUPPORTED: {
|
|
270
|
+
why: ({ target }) => `[vitehub] Valibot cannot convert a schema to the ${target} JSON Schema target.`,
|
|
271
|
+
fix: "Ask for the `draft-07`, `draft-2020-12`, or `openapi-3.0` JSON Schema target, or pass one of them as `withValibotJsonSchema(schema, { target })`."
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region ../internal/src/standard-schema.ts
|
|
277
|
+
function readOwn(value, key) {
|
|
278
|
+
if (value === null || Object(value) !== value) return;
|
|
279
|
+
try {
|
|
280
|
+
return Reflect.get(Object(value), key);
|
|
281
|
+
} catch {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Read a Standard JSON Schema projection without throwing.
|
|
287
|
+
*
|
|
288
|
+
* Returns `undefined` when the schema has no `~standard.jsonSchema`, when the library cannot represent the type
|
|
289
|
+
* (Zod throws for `Date`), or when the projection is not an object. Callers decide how to fall back.
|
|
290
|
+
*/
|
|
291
|
+
function standardJsonSchema(schema, direction, target = "draft-2020-12", libraryOptions) {
|
|
292
|
+
const jsonSchema = readOwn(readOwn(schema, "~standard"), "jsonSchema");
|
|
293
|
+
const project = readOwn(jsonSchema, direction);
|
|
294
|
+
if (typeof project !== "function") return;
|
|
295
|
+
try {
|
|
296
|
+
const result = project.call(jsonSchema, libraryOptions ? {
|
|
297
|
+
target,
|
|
298
|
+
libraryOptions
|
|
299
|
+
} : { target });
|
|
300
|
+
return isRecordOrFunction(result) ? result : void 0;
|
|
301
|
+
} catch {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
//#endregion
|
|
306
|
+
//#region ../internal/src/valibot.ts
|
|
307
|
+
const valibotTargets = /* @__PURE__ */ new Set([
|
|
308
|
+
"draft-07",
|
|
309
|
+
"draft-2020-12",
|
|
310
|
+
"openapi-3.0"
|
|
311
|
+
]);
|
|
312
|
+
function isValibotTarget(value) {
|
|
313
|
+
return valibotTargets.has(String(value));
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Add Standard JSON Schema conversion to a plain Valibot schema. Valibot schemas validate as Standard Schema but carry
|
|
317
|
+
* no JSON Schema, so forms, tools, and model providers would get no shape for them. Other schemas, Valibot schemas that
|
|
318
|
+
* already convert, and async Valibot schemas return unchanged. The copy keeps every Valibot property, so validation
|
|
319
|
+
* does not change.
|
|
320
|
+
*
|
|
321
|
+
* `target` fixes the JSON Schema dialect. Without it, each conversion uses the dialect that the caller asks for.
|
|
322
|
+
*/
|
|
323
|
+
function withValibotJsonSchema(schema, options = {}) {
|
|
324
|
+
const standard = schema["~standard"];
|
|
325
|
+
if (standard.vendor !== "valibot" || Reflect.get(schema, "async") === true) return schema;
|
|
326
|
+
if (Object.hasOwn(standard, "jsonSchema") && standard.jsonSchema) return schema;
|
|
327
|
+
const convert = (typeMode) => (request) => {
|
|
328
|
+
const target = options.target ?? request.target;
|
|
329
|
+
if (!isValibotTarget(target)) throw internalErrorDiagnostics.INTERNAL_VALIBOT_JSON_SCHEMA_TARGET_UNSUPPORTED({ target: String(target) });
|
|
330
|
+
return toJsonSchema(schema, {
|
|
331
|
+
target,
|
|
332
|
+
typeMode,
|
|
333
|
+
errorMode: "ignore"
|
|
334
|
+
});
|
|
335
|
+
};
|
|
336
|
+
return {
|
|
337
|
+
...schema,
|
|
338
|
+
"~standard": {
|
|
339
|
+
...standard,
|
|
340
|
+
jsonSchema: {
|
|
341
|
+
input: convert("input"),
|
|
342
|
+
output: convert("output")
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
//#endregion
|
|
348
|
+
//#region ../internal/src/operation-definition.ts
|
|
349
|
+
const nameFormat = /^[a-z][a-z0-9-]*\.[a-z][a-z0-9-]*$/;
|
|
350
|
+
const kinds = /* @__PURE__ */ new Set([
|
|
351
|
+
"read",
|
|
352
|
+
"write",
|
|
353
|
+
"destructive"
|
|
354
|
+
]);
|
|
355
|
+
function invalidDefinition(name, reason) {
|
|
356
|
+
return internalErrorDiagnostics.INTERNAL_R0020({ message: `[vitehub] Operation ${JSON.stringify(name)} is invalid: ${reason}` });
|
|
357
|
+
}
|
|
358
|
+
function checkDefinition(definition) {
|
|
359
|
+
if (!isRecordOrFunction(definition)) throw invalidDefinition(void 0, "defineOperation() takes an object.");
|
|
360
|
+
const { name } = definition;
|
|
361
|
+
if (String(name) !== name || !nameFormat.test(name)) throw invalidDefinition(name, "the name must look like `section.verb`, in lower case.");
|
|
362
|
+
if (String(definition.description) !== definition.description || !definition.description) throw invalidDefinition(name, "add a one sentence description.");
|
|
363
|
+
const { section } = definition;
|
|
364
|
+
if (section !== false && !(section instanceof Function) && !isSectionId(section)) throw invalidDefinition(name, "section must be a Console section id, a function, or false; section ids cannot contain ':'.");
|
|
365
|
+
if (definition.scope !== void 0 && (!(definition.scope instanceof Function) || String(section) !== section)) throw invalidDefinition(name, "scope must be a function, and it needs a section id.");
|
|
366
|
+
if (!kinds.has(String(definition.kind))) throw invalidDefinition(name, "kind must be \"read\", \"write\", or \"destructive\".");
|
|
367
|
+
const input = definition.input;
|
|
368
|
+
if (!isRecordOrFunction(input) || !isRecordOrFunction(input["~standard"]) || !(input["~standard"].validate instanceof Function)) throw invalidDefinition(name, "input must be a Standard Schema, such as a valibot object.");
|
|
369
|
+
if (!(definition.run instanceof Function)) throw invalidDefinition(name, "run must be a function.");
|
|
370
|
+
const { maxRequestBytes } = definition;
|
|
371
|
+
if (maxRequestBytes !== void 0 && (!Number.isInteger(maxRequestBytes) || Number(maxRequestBytes) < 65536)) throw invalidDefinition(name, `maxRequestBytes can only raise the limit above ${defaultRequestBytes} bytes (64 KiB).`);
|
|
372
|
+
if (definition.readOnlyWhen !== void 0 && !(definition.readOnlyWhen instanceof Function)) throw invalidDefinition(name, "readOnlyWhen must be a function.");
|
|
373
|
+
const { mcp } = definition;
|
|
374
|
+
if (mcp !== void 0 && mcp !== false && (!isRecordOrFunction(mcp) || mcp.title !== void 0 && (String(mcp.title) !== mcp.title || !mcp.title) || mcp.format !== void 0 && !(mcp.format instanceof Function))) throw invalidDefinition(name, "mcp must be false, or an object with a title string and a format function.");
|
|
375
|
+
}
|
|
376
|
+
/** The default limit of a call, in bytes. */
|
|
377
|
+
const defaultRequestBytes = 65536;
|
|
378
|
+
/** Input keys that the generated CLI commands read themselves. */
|
|
379
|
+
const reservedOperationFlags = [
|
|
380
|
+
"input",
|
|
381
|
+
"json",
|
|
382
|
+
"timeout",
|
|
383
|
+
"url",
|
|
384
|
+
"yes"
|
|
385
|
+
];
|
|
386
|
+
/**
|
|
387
|
+
* Define one operation. The Console, the CLI, MCP, and agent tools call the same definition. Contribute it with
|
|
388
|
+
* `vitehub: { operations: [{ module, export }] }` on a Vite plugin.
|
|
389
|
+
*/
|
|
390
|
+
function defineOperation(definition) {
|
|
391
|
+
checkDefinition(definition);
|
|
392
|
+
const defined = {
|
|
393
|
+
...definition,
|
|
394
|
+
input: withValibotJsonSchema(definition.input)
|
|
395
|
+
};
|
|
396
|
+
const properties = operationInputJsonSchema(defined).properties;
|
|
397
|
+
const clashes = isRecordOrFunction(properties) ? Object.keys(properties).filter((key) => reservedOperationFlags.includes(key)) : [];
|
|
398
|
+
if (clashes.length) throw invalidDefinition(definition.name, `the input key ${clashes.map((key) => JSON.stringify(key)).join(", ")} is a CLI flag of every command (${reservedOperationFlags.join(", ")}). Rename it.`);
|
|
399
|
+
return defined;
|
|
400
|
+
}
|
|
401
|
+
function isSectionId(section) {
|
|
402
|
+
return typeof section === "string" && section !== "" && !section.includes(":");
|
|
403
|
+
}
|
|
404
|
+
/** JSON Schema of the input, for CLI flags and MCP tool schemas. Falls back to an open object. */
|
|
405
|
+
function operationInputJsonSchema(operation) {
|
|
406
|
+
return standardJsonSchema(operation.input, "input") ?? { type: "object" };
|
|
407
|
+
}
|
|
408
|
+
/** `"blob:media"` → `["blob:media", "blob"]`: a grant of the section covers each of its scopes. */
|
|
409
|
+
function grantsFor(section) {
|
|
410
|
+
const separator = section.indexOf(":");
|
|
411
|
+
return separator === -1 ? [section] : [section, section.slice(0, separator)];
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Whether the checked access covers the section. Without `call`, a read-only grant (`"kv:read"`) counts, so the answer
|
|
415
|
+
* is whether the section is visible. With `call`, a read-only grant allows only a `read` operation or a call that only
|
|
416
|
+
* reads. Every surface (RPC, CLI, agents, MCP) checks access here.
|
|
417
|
+
*/
|
|
418
|
+
function operationAccessAllows(access, section, call) {
|
|
419
|
+
if (section === void 0) return false;
|
|
420
|
+
if (section === false || access.sections === "all") return true;
|
|
421
|
+
const { sections } = access;
|
|
422
|
+
const grants = grantsFor(section);
|
|
423
|
+
if (grants.some((grant) => sections.includes(grant))) return true;
|
|
424
|
+
if (!grants.some((grant) => sections.includes(`${grant}:read`))) return false;
|
|
425
|
+
return call === void 0 || call.kind === "read" || call.readOnly === true;
|
|
426
|
+
}
|
|
427
|
+
//#endregion
|
|
428
|
+
//#region src/thread-text.ts
|
|
429
|
+
function commentPersonName(person) {
|
|
430
|
+
return `${person.name ?? person.id}${person.guest ? " (guest)" : ""}`;
|
|
431
|
+
}
|
|
432
|
+
/** Thousandths of an element box as a percentage, such as `97.3%`. */
|
|
433
|
+
const share = (value) => `${Number((value / 10).toFixed(1))}%`;
|
|
434
|
+
/** What the comment points at, in words: the element, the quoted text, or the part of the element box it marked. */
|
|
435
|
+
function describeAnchor(anchor) {
|
|
436
|
+
switch (anchor.kind) {
|
|
437
|
+
case "page": return "Anchor: the whole page";
|
|
438
|
+
case "element": return `Anchor: ${anchor.field ? `Content field ${anchor.field}` : anchor.label ?? anchor.selector} (${anchor.selector})`;
|
|
439
|
+
case "text": return `Anchor: the text ${JSON.stringify(anchor.exact)} in ${anchor.selector}`;
|
|
440
|
+
case "area": return `Anchor: an area of ${anchor.selector}, ${share(anchor.width)} wide and ${share(anchor.height)} high, from ${share(anchor.x)} left and ${share(anchor.y)} top of its box`;
|
|
441
|
+
case "image": return anchor.width && anchor.height ? `Anchor: an area of the image ${anchor.selector}, ${share(anchor.width)} wide and ${share(anchor.height)} high, from ${share(anchor.x)} left and ${share(anchor.y)} top` : `Anchor: a point on the image ${anchor.selector}, ${share(anchor.x)} from the left and ${share(anchor.y)} from the top`;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
/** One thread as text an Agent reads: where it is, what the person saw, and the conversation with its attachments. */
|
|
445
|
+
function describeCommentThread(thread) {
|
|
446
|
+
const lines = [
|
|
447
|
+
`Thread #${thread.n} ${thread.id} (${thread.status}) on ${thread.subject.id}`,
|
|
448
|
+
describeAnchor(thread.anchor),
|
|
449
|
+
...describeCommentContext(thread.context ?? null).map((field) => `${field.label}: ${field.value}`),
|
|
450
|
+
"",
|
|
451
|
+
...thread.messages.flatMap((message) => [`${commentPersonName(message.author)}, ${new Date(message.createdAt).toISOString()}: ${message.body}`, ...message.attachments.length ? [`Attachments: ${message.attachments.join(", ")}`] : []])
|
|
452
|
+
];
|
|
453
|
+
if (thread.resolvedBy) lines.push("", `Resolved by ${commentPersonName(thread.resolvedBy)} at ${new Date(thread.resolvedAt ?? thread.updatedAt).toISOString()}`);
|
|
454
|
+
return lines.join("\n");
|
|
455
|
+
}
|
|
456
|
+
/** At most `max` characters of `value`, flattened to one line and cut at a word, with `…` when cut. */
|
|
457
|
+
function clip(value, max) {
|
|
458
|
+
const flat = value.replace(/\s+/g, " ").trim();
|
|
459
|
+
if (flat.length <= max) return flat;
|
|
460
|
+
const head = flat.slice(0, max - 1);
|
|
461
|
+
const space = head.lastIndexOf(" ");
|
|
462
|
+
return `${(space > max / 2 ? head.slice(0, space) : head).trimEnd()}…`;
|
|
463
|
+
}
|
|
464
|
+
/** What the comment points at, in a few words: the element label, the quoted text, or the selector. */
|
|
465
|
+
function commentAnchorLabel(anchor) {
|
|
466
|
+
switch (anchor.kind) {
|
|
467
|
+
case "page": return "the whole page";
|
|
468
|
+
case "element": return anchor.field ? `Content field ${anchor.field}` : anchor.label ? JSON.stringify(clip(anchor.label, 60)) : clip(anchor.selector, 60);
|
|
469
|
+
case "text": return `the text ${JSON.stringify(clip(anchor.exact, 60))}`;
|
|
470
|
+
case "area": return `an area of ${clip(anchor.selector, 60)}`;
|
|
471
|
+
case "image": return `the image ${clip(anchor.selector, 60)}`;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
function commentThreadSummary(thread) {
|
|
475
|
+
return {
|
|
476
|
+
id: thread.id,
|
|
477
|
+
n: thread.n,
|
|
478
|
+
page: thread.subject.id,
|
|
479
|
+
status: thread.status,
|
|
480
|
+
anchor: commentAnchorLabel(thread.anchor),
|
|
481
|
+
comment: thread.messages[0]?.body ?? "",
|
|
482
|
+
author: thread.author.name ?? thread.author.id,
|
|
483
|
+
replies: Math.max(0, thread.messages.length - 1),
|
|
484
|
+
components: thread.context?.components?.map((component) => component.name) ?? [],
|
|
485
|
+
updatedAt: thread.updatedAt
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
/** A time to the minute in UTC, in ISO 8601, such as `2026-11-17T09:22Z`. */
|
|
489
|
+
function minute(time) {
|
|
490
|
+
return `${new Date(time).toISOString().slice(0, 16)}Z`;
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* One line per thread in a list: number, id, page, anchor, last activity, the start of the first comment, author,
|
|
494
|
+
* replies, and the innermost Vue component. Outer components, such as the layout, repeat on every thread of a page;
|
|
495
|
+
* comments_get_thread and comments.get give the whole chain with its files.
|
|
496
|
+
*/
|
|
497
|
+
function commentThreadLine(thread) {
|
|
498
|
+
const component = thread.components.at(-1);
|
|
499
|
+
return `- #${thread.n} ${thread.id} ${thread.page} on ${thread.anchor}, updated ${minute(thread.updatedAt)}: ${clip(thread.comment, 120)} (${thread.author}, ${thread.replies} replies${component ? `, in ${component}` : ""})`;
|
|
500
|
+
}
|
|
501
|
+
/** One sentence that says how many threads the policy hid from a list, and what likely hid them. Empty for none. */
|
|
502
|
+
function hiddenThreadsNote(hidden, reason) {
|
|
503
|
+
if (!hidden) return "";
|
|
504
|
+
const policy = reason.authorize ? "`authorize`" : "The default policy";
|
|
505
|
+
const count = `${hidden} thread${hidden === 1 ? "" : "s"}`;
|
|
506
|
+
if (reason.identify && !reason.user && reason.console) return `${policy} hid ${count} from this caller. With \`identify\`, a Console call has no app user: allow Console callers in \`authorize\` with \`({ console }) => console\`.`;
|
|
507
|
+
if (reason.identify && !reason.user) return `${policy} hid ${count} from this caller, because \`identify\` found no user for this call.`;
|
|
508
|
+
if (!reason.authorize) return `The default policy hid ${count} from this caller. Allow them with \`authorize\` in server/comments.ts.`;
|
|
509
|
+
return `\`authorize\` hid ${count} from this caller.`;
|
|
510
|
+
}
|
|
511
|
+
/** The text of a list of threads, with a note when the policy hid some. */
|
|
512
|
+
function commentThreadsText(threads, status, note) {
|
|
513
|
+
if (!threads.length) return note ? `No ${status} threads that this caller may read. ${note}` : `No ${status} threads.`;
|
|
514
|
+
return [...threads.map(commentThreadLine), ...note ? ["", note] : []].join("\n");
|
|
515
|
+
}
|
|
516
|
+
//#endregion
|
|
517
|
+
//#region src/operations-core/operations.ts
|
|
518
|
+
const defaultLimit = 200;
|
|
519
|
+
const maximumLimit = 500;
|
|
520
|
+
const maximumSuggestions = 10;
|
|
521
|
+
const minimumQuery = 2;
|
|
522
|
+
/** Threads that `authorize` checks at once. */
|
|
523
|
+
const authorizeConcurrency = 16;
|
|
524
|
+
const thousandths = v.pipe(v.number(), v.minValue(0), v.maxValue(1e3));
|
|
525
|
+
const selector = v.pipe(v.string(), v.minLength(1), v.maxLength(2048));
|
|
526
|
+
const quote = v.pipe(v.string(), v.maxLength(2e3));
|
|
527
|
+
const anchor = v.union([
|
|
528
|
+
v.strictObject({ kind: v.literal("page") }),
|
|
529
|
+
v.strictObject({
|
|
530
|
+
field: v.optional(v.pipe(v.string(), v.maxLength(512))),
|
|
531
|
+
kind: v.literal("element"),
|
|
532
|
+
label: v.optional(v.pipe(v.string(), v.maxLength(200))),
|
|
533
|
+
page: v.optional(v.strictObject({
|
|
534
|
+
x: thousandths,
|
|
535
|
+
y: v.pipe(v.number(), v.minValue(0), v.maxValue(1e6))
|
|
536
|
+
})),
|
|
537
|
+
selector,
|
|
538
|
+
viewport: v.optional(v.strictObject({ width: v.pipe(v.number(), v.minValue(0), v.maxValue(1e5)) })),
|
|
539
|
+
x: thousandths,
|
|
540
|
+
y: thousandths
|
|
541
|
+
}),
|
|
542
|
+
v.strictObject({
|
|
543
|
+
exact: v.pipe(v.string(), v.minLength(1), v.maxLength(2e3)),
|
|
544
|
+
kind: v.literal("text"),
|
|
545
|
+
prefix: quote,
|
|
546
|
+
selector,
|
|
547
|
+
suffix: quote
|
|
548
|
+
}),
|
|
549
|
+
v.pipe(v.strictObject({
|
|
550
|
+
height: v.pipe(v.number(), v.minValue(1), v.maxValue(1e3)),
|
|
551
|
+
kind: v.literal("area"),
|
|
552
|
+
selector,
|
|
553
|
+
width: v.pipe(v.number(), v.minValue(1), v.maxValue(1e3)),
|
|
554
|
+
x: thousandths,
|
|
555
|
+
y: thousandths
|
|
556
|
+
}), v.check((area) => area.x + area.width <= 1e3 && area.y + area.height <= 1e3, "An area must stay inside the element box: x + width and y + height are at most 1000.")),
|
|
557
|
+
v.pipe(v.strictObject({
|
|
558
|
+
height: v.optional(v.pipe(v.number(), v.minValue(1), v.maxValue(1e3))),
|
|
559
|
+
kind: v.literal("image"),
|
|
560
|
+
selector,
|
|
561
|
+
width: v.optional(v.pipe(v.number(), v.minValue(1), v.maxValue(1e3))),
|
|
562
|
+
x: thousandths,
|
|
563
|
+
y: thousandths
|
|
564
|
+
}), v.check((area) => area.width === void 0 === (area.height === void 0), "An image area needs width and height together."), v.check((area) => area.x + (area.width ?? 0) <= 1e3 && area.y + (area.height ?? 0) <= 1e3, "An image area must stay inside the element box."))
|
|
565
|
+
]);
|
|
566
|
+
/** The anchor that `comments.create` takes, for the overlay API, which reads its input itself. */
|
|
567
|
+
const commentAnchorSchema = anchor;
|
|
568
|
+
const subjectKind = v.pipe(v.string(), v.minLength(1), v.maxLength(40));
|
|
569
|
+
const subject = v.strictObject({
|
|
570
|
+
id: v.pipe(v.string(), v.minLength(1), v.maxLength(500)),
|
|
571
|
+
kind: subjectKind
|
|
572
|
+
});
|
|
573
|
+
const page = v.pipe(v.string(), v.description("A path such as /pricing, or a full URL of the page."), v.transform(pagePathOf), v.check(isPagePath, "A page is an app path that starts with one \"/\", such as \"/pricing\", without \"?\" or \"#\", or a full http(s) URL of the page."), v.transform((path) => path.length > 1 ? path.replace(/\/+$/, "") : path));
|
|
574
|
+
const cursor = v.strictObject({
|
|
575
|
+
id: v.pipe(v.string(), v.minLength(1), v.maxLength(100)),
|
|
576
|
+
updatedAt: v.number()
|
|
577
|
+
});
|
|
578
|
+
const text = v.pipe(v.string(), v.maxLength(maximumCommentBodyLength));
|
|
579
|
+
const id = v.pipe(v.string(), v.minLength(1), v.maxLength(100));
|
|
580
|
+
const mentions = v.optional(v.pipe(v.array(id), v.maxLength(20)));
|
|
581
|
+
const attachments = v.optional(v.pipe(v.array(v.pipe(v.string(), v.minLength(1), v.maxLength(500))), v.maxLength(10)));
|
|
582
|
+
const metadata = v.optional(v.record(v.string(), v.union([
|
|
583
|
+
v.string(),
|
|
584
|
+
v.number(),
|
|
585
|
+
v.boolean(),
|
|
586
|
+
v.null()
|
|
587
|
+
])));
|
|
588
|
+
const revision = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
589
|
+
const threadId = v.strictObject({ threadId: id });
|
|
590
|
+
function actorOf(actor) {
|
|
591
|
+
return actor ? {
|
|
592
|
+
id: actor.id,
|
|
593
|
+
...actor.label ? { name: actor.label } : {}
|
|
594
|
+
} : void 0;
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Operations run only after the Console admitted the call to the `comments` section, so `authorize` gets
|
|
598
|
+
* `console: true`. With `identify`, the app names the user from the request of the call, as in the overlay API, and
|
|
599
|
+
* `authorize` decides; a call without a request, such as an agent's, has no user. Without `identify`, the user is the
|
|
600
|
+
* Console's, and the default policy trusts it.
|
|
601
|
+
*/
|
|
602
|
+
async function caller(context) {
|
|
603
|
+
const runtime = await commentsRuntime();
|
|
604
|
+
const actor = actorOf(context.actor);
|
|
605
|
+
const development = runtime.development ?? context.development === true;
|
|
606
|
+
return {
|
|
607
|
+
...runtime.identify ? {
|
|
608
|
+
gate: { development },
|
|
609
|
+
user: context.event === void 0 ? null : await runtime.identify(context.event)
|
|
610
|
+
} : {
|
|
611
|
+
gate: {
|
|
612
|
+
console: true,
|
|
613
|
+
development
|
|
614
|
+
},
|
|
615
|
+
user: context.user
|
|
616
|
+
},
|
|
617
|
+
console: true,
|
|
618
|
+
runtime,
|
|
619
|
+
...actor ? { actor } : {},
|
|
620
|
+
...context.request ? { request: context.request } : {},
|
|
621
|
+
...context.waitUntil ? { waitUntil: context.waitUntil } : {}
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
/** Asks the policy, with the thread and its subject, or the subject a thread would start on. */
|
|
625
|
+
async function permitted(who, action, target = {}) {
|
|
626
|
+
return can(who.runtime, {
|
|
627
|
+
action,
|
|
628
|
+
user: who.user,
|
|
629
|
+
...who.actor ? { actor: who.actor } : {},
|
|
630
|
+
...who.console ? { console: true } : {},
|
|
631
|
+
...target
|
|
632
|
+
}, who.gate);
|
|
633
|
+
}
|
|
634
|
+
async function allow(who, action, target) {
|
|
635
|
+
if (!await permitted(who, action, target)) throw deniedError(who.runtime, action, who.user, who.gate);
|
|
636
|
+
}
|
|
637
|
+
/** The signed-in user, else the guest of the request, which only a policy that lets anonymous people write gets this far. */
|
|
638
|
+
function author(who) {
|
|
639
|
+
if (who.user) return personOf(authorOf(who.user));
|
|
640
|
+
const guest = who.request ? guestFromHeaders(who.request.headers) : void 0;
|
|
641
|
+
if (!guest) throw fail(commentsErrorDiagnostics.COMMENTS_R0012(), 401);
|
|
642
|
+
return guest;
|
|
643
|
+
}
|
|
644
|
+
const guestLimits = /* @__PURE__ */ new WeakMap();
|
|
645
|
+
/**
|
|
646
|
+
* Counts one write of a guest against `defineComments({ rateLimit })`, by the address of the request. Signed-in people
|
|
647
|
+
* and Agents are not limited. Call it after the policy allowed the write, so a refused write uses no budget.
|
|
648
|
+
*/
|
|
649
|
+
async function limitGuest(who) {
|
|
650
|
+
const policy = who.runtime.definition.rateLimit;
|
|
651
|
+
if (!policy || !who.request || who.actor || who.user && who.user.guest !== true) return;
|
|
652
|
+
let limit = guestLimits.get(who.runtime);
|
|
653
|
+
if (!limit) {
|
|
654
|
+
limit = createClientRateLimit({
|
|
655
|
+
name: "comments",
|
|
656
|
+
unavailable: "Comments could not count this guest comment in Rate Limit",
|
|
657
|
+
...who.runtime.rateLimit ? { shared: who.runtime.rateLimit } : {}
|
|
658
|
+
});
|
|
659
|
+
guestLimits.set(who.runtime, limit);
|
|
660
|
+
}
|
|
661
|
+
const decision = await limit(who.request, `guest:${clientAddressKey(who.request, getStandardContext(who.request))}`, policy);
|
|
662
|
+
if (decision.allowed) return;
|
|
663
|
+
const { retryAfter } = decision;
|
|
664
|
+
throw Object.assign(fail(commentsErrorDiagnostics.COMMENTS_GUEST_RATE_LIMITED({ retryAfter }), 429), { retryAfter });
|
|
665
|
+
}
|
|
666
|
+
function writeOptions(who) {
|
|
667
|
+
return {
|
|
668
|
+
console: who.console,
|
|
669
|
+
gate: who.gate,
|
|
670
|
+
user: who.user,
|
|
671
|
+
...who.waitUntil ? { waitUntil: who.waitUntil } : {}
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
/** A thread that does not exist and one that the caller may not read look the same: not found. */
|
|
675
|
+
async function load(who, threadIdValue) {
|
|
676
|
+
const found = await who.runtime.store.getById(threadIdValue);
|
|
677
|
+
if (!found || !await permitted(who, "read", { thread: found })) throw fail(commentsErrorDiagnostics.COMMENTS_R0002({ id: threadIdValue }), 404);
|
|
678
|
+
return found;
|
|
679
|
+
}
|
|
680
|
+
async function mapLimit(items, limit, run) {
|
|
681
|
+
const results = Array.from({ length: items.length });
|
|
682
|
+
let next = 0;
|
|
683
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
684
|
+
while (next < items.length) {
|
|
685
|
+
const index = next++;
|
|
686
|
+
results[index] = await run(items[index]);
|
|
687
|
+
}
|
|
688
|
+
}));
|
|
689
|
+
return results;
|
|
690
|
+
}
|
|
691
|
+
function cursorOf(thread) {
|
|
692
|
+
return {
|
|
693
|
+
id: thread.id,
|
|
694
|
+
updatedAt: thread.updatedAt
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
async function withForge(who, threads) {
|
|
698
|
+
return who.runtime.forge ? await who.runtime.forge.attach(threads) : threads;
|
|
699
|
+
}
|
|
700
|
+
const threadsInput = v.strictObject({
|
|
701
|
+
limit: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(100))),
|
|
702
|
+
page: v.optional(page),
|
|
703
|
+
search: v.optional(v.pipe(v.string(), v.maxLength(200))),
|
|
704
|
+
status: v.optional(v.picklist(["open", "resolved"]))
|
|
705
|
+
});
|
|
706
|
+
const listInput = v.strictObject({
|
|
707
|
+
before: v.optional(cursor),
|
|
708
|
+
limit: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(maximumLimit))),
|
|
709
|
+
mentions: v.optional(v.boolean()),
|
|
710
|
+
mine: v.optional(v.boolean()),
|
|
711
|
+
page: v.optional(page),
|
|
712
|
+
revision: v.optional(v.strictObject({ lte: revision })),
|
|
713
|
+
status: v.optional(v.picklist(["open", "resolved"])),
|
|
714
|
+
subject: v.optional(subject),
|
|
715
|
+
subjectKind: v.optional(subjectKind)
|
|
716
|
+
});
|
|
717
|
+
const getInput = v.union([v.strictObject({ id }), v.strictObject({
|
|
718
|
+
n: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
719
|
+
scope: v.pipe(v.string(), v.minLength(1), v.maxLength(200))
|
|
720
|
+
})]);
|
|
721
|
+
const createInput = v.strictObject({
|
|
722
|
+
anchor,
|
|
723
|
+
attachments,
|
|
724
|
+
body: text,
|
|
725
|
+
mentions,
|
|
726
|
+
metadata,
|
|
727
|
+
requestId: v.optional(requestIdSchema),
|
|
728
|
+
revision: v.optional(revision),
|
|
729
|
+
subject
|
|
730
|
+
});
|
|
731
|
+
const replyInput = v.strictObject({
|
|
732
|
+
attachments,
|
|
733
|
+
body: text,
|
|
734
|
+
mentions,
|
|
735
|
+
threadId: id
|
|
736
|
+
});
|
|
737
|
+
const editInput = v.strictObject({
|
|
738
|
+
body: text,
|
|
739
|
+
mentions,
|
|
740
|
+
messageId: id,
|
|
741
|
+
threadId: id
|
|
742
|
+
});
|
|
743
|
+
const deleteInput = v.strictObject({
|
|
744
|
+
messageId: v.optional(id),
|
|
745
|
+
threadId: id
|
|
746
|
+
});
|
|
747
|
+
const usersInput = v.strictObject({
|
|
748
|
+
limit: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(maximumSuggestions))),
|
|
749
|
+
query: v.pipe(v.string(), v.maxLength(100)),
|
|
750
|
+
subject: v.optional(subject),
|
|
751
|
+
threadId: v.optional(id)
|
|
752
|
+
});
|
|
753
|
+
const uploadInput = v.strictObject({
|
|
754
|
+
data: v.pipe(v.string(), v.minLength(1)),
|
|
755
|
+
name: v.pipe(v.string(), v.minLength(1), v.maxLength(200)),
|
|
756
|
+
subject: v.optional(subject),
|
|
757
|
+
type: v.pipe(v.string(), v.minLength(1), v.maxLength(100))
|
|
758
|
+
});
|
|
759
|
+
const attachmentInput = v.strictObject({ key: v.pipe(v.string(), v.minLength(1), v.maxLength(500)) });
|
|
760
|
+
/** The inputs of the comment actions, for transports that read their input themselves, such as the overlay API. */
|
|
761
|
+
const commentInputSchemas = {
|
|
762
|
+
attachment: attachmentInput,
|
|
763
|
+
create: createInput,
|
|
764
|
+
delete: deleteInput,
|
|
765
|
+
edit: editInput,
|
|
766
|
+
get: getInput,
|
|
767
|
+
list: listInput,
|
|
768
|
+
reply: replyInput,
|
|
769
|
+
status: threadId,
|
|
770
|
+
upload: uploadInput,
|
|
771
|
+
users: usersInput
|
|
772
|
+
};
|
|
773
|
+
/**
|
|
774
|
+
* The threads of a list that the caller may read, and how many threads the policy left out on the way. Threads the
|
|
775
|
+
* caller may not read are left out, so it asks again after them until the page is full or the threads end.
|
|
776
|
+
*/
|
|
777
|
+
async function readableThreads(input, who) {
|
|
778
|
+
const limit = input.limit ?? defaultLimit;
|
|
779
|
+
const readable = [];
|
|
780
|
+
let hidden = 0;
|
|
781
|
+
let before = input.before;
|
|
782
|
+
while (readable.length < limit) {
|
|
783
|
+
const threads = await who.runtime.store.list({
|
|
784
|
+
...input,
|
|
785
|
+
limit,
|
|
786
|
+
...before ? { before } : {},
|
|
787
|
+
...who.user ? { userId: who.user.id } : {}
|
|
788
|
+
});
|
|
789
|
+
const allowed = await mapLimit(threads, authorizeConcurrency, (thread) => permitted(who, "read", { thread }).catch(() => false));
|
|
790
|
+
for (const [index, thread] of threads.entries()) {
|
|
791
|
+
if (readable.length === limit) break;
|
|
792
|
+
if (allowed[index]) readable.push(thread);
|
|
793
|
+
else hidden++;
|
|
794
|
+
}
|
|
795
|
+
if (threads.length < limit) break;
|
|
796
|
+
before = cursorOf(threads.at(-1));
|
|
797
|
+
}
|
|
798
|
+
return {
|
|
799
|
+
threads: await withForge(who, readable),
|
|
800
|
+
hidden
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* The comment actions behind every surface. The operations (RPC, CLI, MCP) and the overlay API call the same
|
|
805
|
+
* functions, so one policy, one set of checks, and one set of errors serve them all. Each one checks `authorize` for
|
|
806
|
+
* its caller; the input must have passed `commentInputSchemas`.
|
|
807
|
+
*/
|
|
808
|
+
const commentActions = {
|
|
809
|
+
async list(input, who) {
|
|
810
|
+
return (await readableThreads(input, who)).threads;
|
|
811
|
+
},
|
|
812
|
+
async get(input, who) {
|
|
813
|
+
const found = "id" in input ? await who.runtime.store.getById(input.id) : await who.runtime.store.getByNumber(input.scope, input.n);
|
|
814
|
+
if (!found || !await permitted(who, "read", { thread: found })) return null;
|
|
815
|
+
return (await withForge(who, [found]))[0];
|
|
816
|
+
},
|
|
817
|
+
/** `context` is the page context that the overlay read and its transport checked. */
|
|
818
|
+
async create(input, who) {
|
|
819
|
+
const canRead = (thread) => permitted(who, "read", { thread });
|
|
820
|
+
const earlier = await earlierThread(who.runtime, input);
|
|
821
|
+
if (earlier) return retried(earlier, {
|
|
822
|
+
author: author(who),
|
|
823
|
+
subject: input.subject
|
|
824
|
+
}, canRead);
|
|
825
|
+
await allow(who, "read", { subject: input.subject });
|
|
826
|
+
await allow(who, "write", { subject: input.subject });
|
|
827
|
+
await limitGuest(who);
|
|
828
|
+
return createThread(who.runtime, {
|
|
829
|
+
...input,
|
|
830
|
+
author: author(who),
|
|
831
|
+
...who.actor ? { actor: who.actor } : {}
|
|
832
|
+
}, {
|
|
833
|
+
...writeOptions(who),
|
|
834
|
+
canRead
|
|
835
|
+
});
|
|
836
|
+
},
|
|
837
|
+
/** `allowResolved`: the operations keep a reply box on resolved threads, and a reply keeps the thread resolved. */
|
|
838
|
+
async reply(input, who, options = {}) {
|
|
839
|
+
const found = await load(who, input.threadId);
|
|
840
|
+
await allow(who, "write", { thread: found });
|
|
841
|
+
await limitGuest(who);
|
|
842
|
+
return replyToThread(who.runtime, found, {
|
|
843
|
+
body: input.body,
|
|
844
|
+
author: author(who),
|
|
845
|
+
...input.mentions ? { mentions: input.mentions } : {},
|
|
846
|
+
...input.attachments ? { attachments: input.attachments } : {},
|
|
847
|
+
...who.actor ? { actor: who.actor } : {}
|
|
848
|
+
}, {
|
|
849
|
+
allowResolved: options.allowResolved === true,
|
|
850
|
+
...writeOptions(who)
|
|
851
|
+
});
|
|
852
|
+
},
|
|
853
|
+
async edit(input, who) {
|
|
854
|
+
const found = await load(who, input.threadId);
|
|
855
|
+
if (who.actor) await allow(who, "write", { thread: found });
|
|
856
|
+
const target = found.messages.find((entry) => entry.id === input.messageId);
|
|
857
|
+
if (!target) throw fail(commentsErrorDiagnostics.COMMENTS_R0003({ messageId: input.messageId }), 404);
|
|
858
|
+
if (!who.user || who.user.guest === true || target.author.guest || target.author.id !== who.user.id) throw fail(commentsErrorDiagnostics.COMMENTS_R0004(), 403);
|
|
859
|
+
return editMessage(who.runtime, found, target.id, {
|
|
860
|
+
body: input.body,
|
|
861
|
+
...input.mentions ? { mentions: input.mentions } : {}
|
|
862
|
+
}, writeOptions(who));
|
|
863
|
+
},
|
|
864
|
+
async delete(input, who) {
|
|
865
|
+
const found = await load(who, input.threadId);
|
|
866
|
+
const target = input.messageId === void 0 ? void 0 : found.messages.find((entry) => entry.id === input.messageId);
|
|
867
|
+
if (input.messageId !== void 0 && !target) throw fail(commentsErrorDiagnostics.COMMENTS_R0003({ messageId: input.messageId }), 404);
|
|
868
|
+
const deletesThread = !target || target.id === found.messages[0]?.id;
|
|
869
|
+
const ownerId = who.user && !who.actor && who.user.guest !== true ? who.user.id : void 0;
|
|
870
|
+
const owns = ownerId !== void 0 && (deletesThread ? found.messages.every((entry) => !entry.author.guest && entry.author.id === ownerId) : !target.author.guest && target.author.id === ownerId);
|
|
871
|
+
if (owns) await allow(who, "write", { thread: found });
|
|
872
|
+
else {
|
|
873
|
+
await allow(who, "delete", { thread: found });
|
|
874
|
+
if (!who.user || who.user.guest === true) throw fail(commentsErrorDiagnostics.COMMENTS_R0009({ action: "delete" }), 403);
|
|
875
|
+
}
|
|
876
|
+
if (deletesThread) {
|
|
877
|
+
if (await who.runtime.store.deleteThread(found.id, owns ? ownerId : void 0) === false) throw fail(commentsErrorDiagnostics.COMMENTS_R0009({ action: "delete" }), 403);
|
|
878
|
+
who.runtime.forge?.changed(found.id);
|
|
879
|
+
return null;
|
|
880
|
+
}
|
|
881
|
+
const next = await who.runtime.store.deleteMessage(found.id, target.id, Date.now());
|
|
882
|
+
who.runtime.forge?.changed(found.id);
|
|
883
|
+
return next;
|
|
884
|
+
},
|
|
885
|
+
async setStatus(input, who, status) {
|
|
886
|
+
const found = await load(who, input.threadId);
|
|
887
|
+
await allow(who, "resolve", { thread: found });
|
|
888
|
+
const next = await who.runtime.store.setStatus(found.id, status, author(who), Date.now());
|
|
889
|
+
who.runtime.forge?.changed(found.id);
|
|
890
|
+
return next;
|
|
891
|
+
},
|
|
892
|
+
/** `minimum`: the shortest query that gets suggestions. The operations ask for two characters. */
|
|
893
|
+
async users(input, who, options = {}) {
|
|
894
|
+
const thread = input.threadId === void 0 ? void 0 : await load(who, input.threadId);
|
|
895
|
+
const target = thread ? { thread } : input.subject ? { subject: input.subject } : {};
|
|
896
|
+
await allow(who, "read", target);
|
|
897
|
+
await allow(who, "write", target);
|
|
898
|
+
const query = input.query.trim();
|
|
899
|
+
if (query.length < (options.minimum ?? minimumQuery)) return [];
|
|
900
|
+
return suggest(who.runtime, {
|
|
901
|
+
console: who.console,
|
|
902
|
+
gate: who.gate,
|
|
903
|
+
limit: Math.min(input.limit ?? 5, maximumSuggestions),
|
|
904
|
+
query,
|
|
905
|
+
user: who.user,
|
|
906
|
+
...target
|
|
907
|
+
});
|
|
908
|
+
},
|
|
909
|
+
async upload(input, who) {
|
|
910
|
+
const target = input.subject ? { subject: input.subject } : {};
|
|
911
|
+
await allow(who, "read", target);
|
|
912
|
+
await allow(who, "write", target);
|
|
913
|
+
author(who);
|
|
914
|
+
await limitGuest(who);
|
|
915
|
+
return storeAttachment(who.runtime, input, who.user);
|
|
916
|
+
},
|
|
917
|
+
/** The file of an attachment key, for a caller who may read a thread whose messages list it. */
|
|
918
|
+
async attachment(input, who) {
|
|
919
|
+
const thread = await attachmentThread(who.runtime, input.key, (candidate) => permitted(who, "read", { thread: candidate }));
|
|
920
|
+
return readAttachment(who.runtime, input.key, {
|
|
921
|
+
thread,
|
|
922
|
+
user: who.user
|
|
923
|
+
});
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
function base64(bytes) {
|
|
927
|
+
let binary = "";
|
|
928
|
+
for (let index = 0; index < bytes.length; index += 32768) binary += String.fromCharCode(...bytes.subarray(index, index + 32768));
|
|
929
|
+
return btoa(binary);
|
|
930
|
+
}
|
|
931
|
+
const list = defineOperation({
|
|
932
|
+
description: "ViteHub Comments: list threads on any subject, such as the app's pages where people comment with the Comments toolbar, newest first, as full threads. Filter by subject, page, status, author, mention, or subject revision. Pass the last thread as `before` for the next page. For a short list of page threads, use comments.threads.",
|
|
933
|
+
input: listInput,
|
|
934
|
+
kind: "read",
|
|
935
|
+
name: "comments.list",
|
|
936
|
+
run: async (input, context) => commentActions.list(input, await caller(context)),
|
|
937
|
+
section: "comments"
|
|
938
|
+
});
|
|
939
|
+
/** Threads that one search reads from the store at a time. */
|
|
940
|
+
const searchBatch = maximumLimit;
|
|
941
|
+
const threads = defineOperation({
|
|
942
|
+
description: "ViteHub Comments: threads people left with the Comments toolbar on the app's pages, newest activity first. Each has the page, what the comment points at, the time, the first comment, and the Vue components. `hidden` counts the threads that `authorize` hid from you. Read one with comments.get. After you change the code, reply with comments.reply and resolve it with comments.resolve.",
|
|
943
|
+
input: threadsInput,
|
|
944
|
+
kind: "read",
|
|
945
|
+
name: "comments.threads",
|
|
946
|
+
run: async (input, context) => {
|
|
947
|
+
const who = await caller(context);
|
|
948
|
+
const status = input.status ?? "open";
|
|
949
|
+
const limit = input.limit ?? 25;
|
|
950
|
+
const search = input.search?.toLowerCase();
|
|
951
|
+
const batch = search ? searchBatch : limit;
|
|
952
|
+
const found = [];
|
|
953
|
+
let hidden = 0;
|
|
954
|
+
let before;
|
|
955
|
+
while (found.length < limit) {
|
|
956
|
+
const listed = await readableThreads({
|
|
957
|
+
limit: batch,
|
|
958
|
+
status,
|
|
959
|
+
subjectKind: "page",
|
|
960
|
+
...input.page ? { page: input.page } : {},
|
|
961
|
+
...before ? { before } : {}
|
|
962
|
+
}, who);
|
|
963
|
+
hidden += listed.hidden;
|
|
964
|
+
for (const thread of listed.threads) {
|
|
965
|
+
if (!search || thread.messages.some((message) => message.body.toLowerCase().includes(search))) found.push(thread);
|
|
966
|
+
if (found.length === limit) break;
|
|
967
|
+
}
|
|
968
|
+
if (listed.threads.length < batch) break;
|
|
969
|
+
before = cursorOf(listed.threads.at(-1));
|
|
970
|
+
}
|
|
971
|
+
const note = hiddenThreadsNote(hidden, {
|
|
972
|
+
authorize: Boolean(who.runtime.definition.authorize),
|
|
973
|
+
identify: Boolean(who.runtime.identify),
|
|
974
|
+
user: who.user !== null,
|
|
975
|
+
console: who.console === true
|
|
976
|
+
});
|
|
977
|
+
return {
|
|
978
|
+
status,
|
|
979
|
+
threads: found.map(commentThreadSummary),
|
|
980
|
+
hidden,
|
|
981
|
+
...note ? { note } : {}
|
|
982
|
+
};
|
|
983
|
+
},
|
|
984
|
+
mcp: {
|
|
985
|
+
format: ({ status, threads, note }) => commentThreadsText(threads, status, note ?? ""),
|
|
986
|
+
title: "List ViteHub Comments threads"
|
|
987
|
+
},
|
|
988
|
+
section: "comments"
|
|
989
|
+
});
|
|
990
|
+
const get = defineOperation({
|
|
991
|
+
description: "Read one comment thread by id, or by number inside its scope: its page, the element and Vue components with their source files, the browser and build, and every comment. A thread that does not exist or that you may not read is null.",
|
|
992
|
+
input: getInput,
|
|
993
|
+
kind: "read",
|
|
994
|
+
name: "comments.get",
|
|
995
|
+
run: async (input, context) => commentActions.get(input, await caller(context)),
|
|
996
|
+
mcp: {
|
|
997
|
+
format: (thread) => thread ? describeCommentThread(thread) : "No thread with this id that you may read.",
|
|
998
|
+
title: "Read a comment thread"
|
|
999
|
+
},
|
|
1000
|
+
section: "comments"
|
|
1001
|
+
});
|
|
1002
|
+
const create = defineOperation({
|
|
1003
|
+
description: "Start a comment thread on a subject, such as a page, with an anchor and a first message. Send the same `requestId` again to retry: you get the first thread, not a second one.",
|
|
1004
|
+
input: createInput,
|
|
1005
|
+
kind: "write",
|
|
1006
|
+
name: "comments.create",
|
|
1007
|
+
run: async (input, context) => commentActions.create(input, await caller(context)),
|
|
1008
|
+
section: "comments"
|
|
1009
|
+
});
|
|
1010
|
+
const reply = defineOperation({
|
|
1011
|
+
description: "Add a message to a comment thread, for example to say what you changed. A resolved thread stays resolved.",
|
|
1012
|
+
input: replyInput,
|
|
1013
|
+
kind: "write",
|
|
1014
|
+
name: "comments.reply",
|
|
1015
|
+
run: async (input, context) => (await commentActions.reply(input, await caller(context), { allowResolved: true })).thread,
|
|
1016
|
+
mcp: {
|
|
1017
|
+
format: (thread) => `Replied to thread ${thread.id}.`,
|
|
1018
|
+
title: "Reply to a comment thread"
|
|
1019
|
+
},
|
|
1020
|
+
section: "comments"
|
|
1021
|
+
});
|
|
1022
|
+
const edit = defineOperation({
|
|
1023
|
+
description: "Change the text of your own message.",
|
|
1024
|
+
input: editInput,
|
|
1025
|
+
kind: "write",
|
|
1026
|
+
name: "comments.edit",
|
|
1027
|
+
run: async (input, context) => commentActions.edit(input, await caller(context)),
|
|
1028
|
+
section: "comments"
|
|
1029
|
+
});
|
|
1030
|
+
const remove = defineOperation({
|
|
1031
|
+
description: "Delete a message, or the whole thread. Deleting the first message deletes the thread.",
|
|
1032
|
+
input: deleteInput,
|
|
1033
|
+
kind: "destructive",
|
|
1034
|
+
name: "comments.delete",
|
|
1035
|
+
run: async (input, context) => commentActions.delete(input, await caller(context)),
|
|
1036
|
+
section: "comments"
|
|
1037
|
+
});
|
|
1038
|
+
function statusOperation(name, status, description, title) {
|
|
1039
|
+
return defineOperation({
|
|
1040
|
+
description,
|
|
1041
|
+
input: threadId,
|
|
1042
|
+
kind: "write",
|
|
1043
|
+
mcp: {
|
|
1044
|
+
format: (thread) => `Thread ${thread.id} is ${thread.status}.`,
|
|
1045
|
+
title
|
|
1046
|
+
},
|
|
1047
|
+
name,
|
|
1048
|
+
run: async (input, context) => commentActions.setStatus(input, await caller(context), status),
|
|
1049
|
+
section: "comments"
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
1052
|
+
const users = defineOperation({
|
|
1053
|
+
description: "Find people to mention by name. Needs at least two characters, and the right to write.",
|
|
1054
|
+
input: usersInput,
|
|
1055
|
+
kind: "read",
|
|
1056
|
+
name: "comments.users",
|
|
1057
|
+
run: async (input, context) => commentActions.users(input, await caller(context)),
|
|
1058
|
+
section: "comments"
|
|
1059
|
+
});
|
|
1060
|
+
const upload = defineOperation({
|
|
1061
|
+
description: "Store a file to attach to a comment. Pass the returned key in `attachments` of comments.create or comments.reply.",
|
|
1062
|
+
input: uploadInput,
|
|
1063
|
+
kind: "write",
|
|
1064
|
+
maxRequestBytes: Math.ceil(maximumAttachmentBytes / 3) * 4 + 4096,
|
|
1065
|
+
mcp: false,
|
|
1066
|
+
name: "comments.upload",
|
|
1067
|
+
run: async (input, context) => commentActions.upload(input, await caller(context)),
|
|
1068
|
+
section: "comments"
|
|
1069
|
+
});
|
|
1070
|
+
const attachment = defineOperation({
|
|
1071
|
+
description: "Read the file of an attachment key, Base64-encoded, from a thread that you may read.",
|
|
1072
|
+
input: attachmentInput,
|
|
1073
|
+
kind: "read",
|
|
1074
|
+
mcp: false,
|
|
1075
|
+
name: "comments.attachment",
|
|
1076
|
+
run: async (input, context) => {
|
|
1077
|
+
const file = await commentActions.attachment(input, await caller(context));
|
|
1078
|
+
return {
|
|
1079
|
+
data: base64(new Uint8Array(await file.data.arrayBuffer())),
|
|
1080
|
+
inline: file.inline,
|
|
1081
|
+
key: file.key,
|
|
1082
|
+
name: file.name,
|
|
1083
|
+
size: file.size,
|
|
1084
|
+
type: file.type
|
|
1085
|
+
};
|
|
1086
|
+
},
|
|
1087
|
+
section: "comments"
|
|
1088
|
+
});
|
|
1089
|
+
const session = defineOperation({
|
|
1090
|
+
description: "Tell the comments overlay who is signed in and what that person may do. Nothing else leaves the server.",
|
|
1091
|
+
input: v.strictObject({
|
|
1092
|
+
subject: v.optional(subject),
|
|
1093
|
+
threadId: v.optional(id)
|
|
1094
|
+
}),
|
|
1095
|
+
kind: "read",
|
|
1096
|
+
name: "comments.session",
|
|
1097
|
+
run: async (input, context) => {
|
|
1098
|
+
const who = await caller(context);
|
|
1099
|
+
if (!who.user) return {
|
|
1100
|
+
canRead: false,
|
|
1101
|
+
canWrite: false,
|
|
1102
|
+
user: null
|
|
1103
|
+
};
|
|
1104
|
+
if (input.threadId) {
|
|
1105
|
+
const found = await load(who, input.threadId);
|
|
1106
|
+
const can = (action) => permitted(who, action, { thread: found }).catch(() => false);
|
|
1107
|
+
const [write, resolve, remove] = await Promise.all([
|
|
1108
|
+
can("write"),
|
|
1109
|
+
can("resolve"),
|
|
1110
|
+
can("delete")
|
|
1111
|
+
]);
|
|
1112
|
+
const writes = operationAccessAllows(context.access, "comments", { kind: "write" });
|
|
1113
|
+
const deletes = operationAccessAllows(context.access, "comments", { kind: "destructive" });
|
|
1114
|
+
const signedIn = who.user.guest !== true;
|
|
1115
|
+
const userId = who.user.id;
|
|
1116
|
+
const owns = (message) => signedIn && !who.actor && !message.author.guest && message.author.id === userId;
|
|
1117
|
+
const ownsThread = found.messages.every(owns);
|
|
1118
|
+
const deleteThread = signedIn && deletes && (ownsThread ? write : remove);
|
|
1119
|
+
return {
|
|
1120
|
+
canRead: true,
|
|
1121
|
+
canWrite: writes && write,
|
|
1122
|
+
capabilities: {
|
|
1123
|
+
delete: found.messages.filter((message, index) => index === 0 ? deleteThread : signedIn && deletes && (owns(message) ? write : remove)).map((message) => message.id),
|
|
1124
|
+
deleteThread,
|
|
1125
|
+
edit: signedIn && writes && (!who.actor || write) ? found.messages.filter((message) => !message.author.guest && message.author.id === userId).map((message) => message.id) : [],
|
|
1126
|
+
reply: writes && write,
|
|
1127
|
+
resolve: writes && resolve
|
|
1128
|
+
},
|
|
1129
|
+
user: personOf(who.user)
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
const allowed = (action) => permitted(who, action, input.subject ? { subject: input.subject } : {}).catch(() => false);
|
|
1133
|
+
const [canRead, canWrite] = await Promise.all([allowed("read"), allowed("write")]);
|
|
1134
|
+
return {
|
|
1135
|
+
canRead,
|
|
1136
|
+
canWrite: canRead && canWrite && operationAccessAllows(context.access, "comments", { kind: "write" }),
|
|
1137
|
+
user: personOf(who.user)
|
|
1138
|
+
};
|
|
1139
|
+
},
|
|
1140
|
+
section: "comments"
|
|
1141
|
+
});
|
|
1142
|
+
/** The comment operations. The Console, the CLI, MCP, and the comments client call them. */
|
|
1143
|
+
const commentsOperations = [
|
|
1144
|
+
threads,
|
|
1145
|
+
list,
|
|
1146
|
+
get,
|
|
1147
|
+
create,
|
|
1148
|
+
reply,
|
|
1149
|
+
edit,
|
|
1150
|
+
remove,
|
|
1151
|
+
statusOperation("comments.resolve", "resolved", "Mark a comment thread as resolved, after the change it asks for is done. Resolved threads leave the page.", "Resolve a comment thread"),
|
|
1152
|
+
statusOperation("comments.reopen", "open", "Open a resolved comment thread again.", "Reopen a comment thread"),
|
|
1153
|
+
users,
|
|
1154
|
+
upload,
|
|
1155
|
+
attachment,
|
|
1156
|
+
session
|
|
1157
|
+
];
|
|
1158
|
+
//#endregion
|
|
1159
|
+
export { commentThreadSummary as a, hiddenThreadsNote as c, commentsOperations as i, commentAnchorSchema as n, commentThreadsText as o, commentInputSchemas as r, describeCommentThread as s, commentActions as t };
|