@vite-hub/comments 0.3.1 → 0.5.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 +37 -15
- package/dist/anchor.d.ts +2 -2
- package/dist/{client-diagnostics-CcFpkbAk.js → client-diagnostics-Bubm7Shd.js} +20 -5
- package/dist/client-files-CJZl5Kc4.js +53 -0
- package/dist/client.d.ts +567 -13
- package/dist/client.js +1209 -34
- package/dist/{console-h4KlhIik.d.ts → console-D1lwNMZn.d.ts} +2 -0
- package/dist/{migrate-BDQ8xqUs.js → database-6hXRnqDE.js} +47 -2
- package/dist/database-CTo7mx6t.d.ts +575 -0
- package/dist/database.d.ts +2 -1
- package/dist/database.js +2 -2
- package/dist/{define-43mMR39K.js → define-BMBSVbD9.js} +1 -1
- package/dist/{define-B3TF9zzn.d.ts → define-CmIFU96x.d.ts} +8 -4
- package/dist/{errors-4gelGVmK.js → errors-BJTZ9iyv.js} +24 -0
- package/dist/{errors-C6qptPoG.js → errors-Dq4AHjza.js} +23 -3
- package/dist/index-RiHzmV16.d.ts +194 -0
- package/dist/index.d.ts +6 -7
- package/dist/index.js +57 -9
- package/dist/{install-W9ghhGoh.d.ts → install-BGGQKbQ4.d.ts} +9 -3
- package/dist/{install-BcMPgPk_.js → install-DrAse1Fa.js} +912 -60
- package/dist/{installed-B-PfERBU.js → installed-C3EoqJEY.js} +7 -6
- package/dist/{operations-GLeOqgMt.d.ts → operations-BKhUWYkb.d.ts} +10 -5
- package/dist/{operations-D4A1Fcgf.d.ts → operations-VyyNZusz.d.ts} +13 -2
- package/dist/{operations-DMMIfYPW.js → operations-lsVKE0GH.js} +312 -219
- package/dist/operations.d.ts +2 -2
- package/dist/operations.js +2 -2
- package/dist/overlay/client-DBmJ4C1M.js +4 -0
- package/dist/overlay/overlay.js +41 -65
- package/dist/page/loader.js +39 -47
- package/dist/{page-DtbMOEMd.d.ts → page-Bzj0CszG.d.ts} +1 -10
- package/dist/{page-B41ozN63.js → page-DRz_sDY4.js} +1 -1
- package/dist/{page-tools-shared-NHUjKI8E.js → page-tools-shared-BNnuPK93.js} +6 -3
- package/dist/{plugin-PS8PMYus.js → plugin-DRsNaJaK.js} +34 -8
- package/dist/realtime.d.ts +2 -2
- package/dist/realtime.js +2 -2
- package/dist/reply-id-P_bSuEng.js +12 -0
- package/dist/request-log-Dj9Vw7qG.js +105 -0
- package/dist/request-origin-CFU0TQ7E.js +49 -0
- package/dist/{rpc-RKPAusHp.js → rpc-BQqYx8kb.js} +23 -7
- package/dist/{rpc-HBcWtg0T.d.ts → rpc-CuJ5GLIz.d.ts} +1 -1
- package/dist/rpc.d.ts +1 -1
- package/dist/rpc.js +1 -1
- package/dist/runtime/auth.d.ts +2 -2
- package/dist/runtime/auth.js +2 -2
- package/dist/runtime/console.d.ts +1 -1
- package/dist/runtime/console.js +3 -3
- package/dist/runtime/index.d.ts +42 -13
- package/dist/runtime/index.js +224 -22
- package/dist/{server-D8k-0GXe.js → server-Yk610niJ.js} +1 -1
- package/dist/server.d.ts +6 -5
- package/dist/server.js +6 -6
- package/dist/service-Bj-Mg63c.d.ts +73 -0
- package/dist/{service-GHhhyQj4.js → service-DA5BwfPQ.js} +71 -14
- package/dist/{session-DVx-1Tym.d.ts → session-DUcEor2W.d.ts} +3 -3
- package/dist/{session-EkudzUmm.js → session-X_g9dnU5.js} +27 -30
- package/dist/{service-CFVm23k7.d.ts → store-CsUNfC1w.d.ts} +11 -72
- package/dist/table-names-B9LlRC0B.js +16 -0
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +38 -5
- package/dist/{types-CZujrMFd.d.ts → types-BLaYh0_f.d.ts} +48 -4
- package/dist/{types-BIS0hCEl.d.ts → types-C35INXIs.d.ts} +88 -4
- package/dist/vite.d.ts +24 -7
- package/dist/vite.js +322 -173
- package/package.json +9 -9
- package/dist/errors-CyQyKAvy.d.ts +0 -185
- package/dist/index-DNhy69Wt.d.ts +0 -83
- package/dist/overlay/client-DmsSMOzi.js +0 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { D as CommentUser, T as CommentThread, b as CommentMetadata, n as CommentActor, w as CommentSubject, y as CommentMessage } from "./types-BLaYh0_f.js";
|
|
2
2
|
//#region src/operations-core/define.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* - `read`: see threads, join the presence room of a page, and get `@` suggestions.
|
|
@@ -49,6 +49,12 @@ interface CommentsAuthorizeContext {
|
|
|
49
49
|
* `authorize: ({ console, user }) => console === true || user?.role === "editor"`.
|
|
50
50
|
*/
|
|
51
51
|
console?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* The app runs on the development server: Vite's serve command, which the generated plugin records. It never comes
|
|
54
|
+
* from `NODE_ENV`. Pass `{ development }` to `defaultPolicy()` for the dev, GitHub, and Site access checks.
|
|
55
|
+
* The full context is not the default gate: with `identify`, Console admission does not grant the app user access.
|
|
56
|
+
*/
|
|
57
|
+
development?: boolean;
|
|
52
58
|
}
|
|
53
59
|
/** Decides whether a person or an Agent may take an action. Return `true` to allow. */
|
|
54
60
|
type CommentsAuthorize = (context: CommentsAuthorizeContext) => boolean | Promise<boolean>;
|
|
@@ -173,8 +179,6 @@ interface CommentsDefinition {
|
|
|
173
179
|
declare function validateCommentsDefinition(value: unknown, file: string): CommentsDefinition;
|
|
174
180
|
/** A subject kind of your own, such as `drop`. */
|
|
175
181
|
declare function defineCommentSubject(subject: CommentSubjectDefinition): CommentSubjectDefinition;
|
|
176
|
-
/** Subjects that exist without a definition. */
|
|
177
|
-
declare const builtinCommentSubjects: readonly CommentSubjectDefinition[];
|
|
178
182
|
/** What the server checked about a request before the policy runs. */
|
|
179
183
|
interface CommentsPolicyGate {
|
|
180
184
|
/** Vite's serve command. The generated Nitro plugin records it; it never comes from `NODE_ENV`. */
|
|
@@ -201,4 +205,4 @@ declare function commentsRoleAllows(user: CommentsUser | null, action: CommentAc
|
|
|
201
205
|
*/
|
|
202
206
|
declare function defaultPolicy(user: CommentsUser | null, gate?: CommentsPolicyGate, action?: CommentAction): boolean;
|
|
203
207
|
//#endregion
|
|
204
|
-
export {
|
|
208
|
+
export { commentsRoleAllows as _, CommentsAttachmentFile as a, validateCommentsDefinition as b, CommentsCanMentionContext as c, CommentsPeople as d, CommentsPolicyGate as f, CommentsUser as g, CommentsStoreAttachmentContext as h, CommentSubjectDefinition as i, CommentsDefinition as l, CommentsReadAttachmentContext as m, CommentMentionEvent as n, CommentsAuthorize as o, CommentsRateLimit as p, CommentMessageEvent as r, CommentsAuthorizeContext as s, CommentAction as t, CommentsGitHubAccess as u, defaultPolicy as v, defineCommentSubject as y };
|
|
@@ -50,6 +50,30 @@ const commentsErrors = /*#__PURE__*/ defineErrors({
|
|
|
50
50
|
COMMENTS_FIELD_LOCKED: {
|
|
51
51
|
why: ({ holder }) => `${holder} holds the edit lease of this document in the Console.`,
|
|
52
52
|
fix: "Wait until they close the document, or edit it together with them in the Console."
|
|
53
|
+
},
|
|
54
|
+
COMMENTS_SEND_CODE_EXPIRED: {
|
|
55
|
+
why: "The setup code of Send is older than 10 minutes, or it does not exist.",
|
|
56
|
+
fix: "Press Send in the comment pill again. It copies a setup prompt with a new code."
|
|
57
|
+
},
|
|
58
|
+
COMMENTS_SEND_CODE_REFUSED: {
|
|
59
|
+
why: ({ reason }) => `Send did not pair the agent. ${reason}`,
|
|
60
|
+
fix: "Pair with the `webhookUrl` that T3 Code's `schedule_task` returns, on `relay.t3.codes`, or add the host to `defineComments({ send: { hosts } })`. Then press Copy again for a new code."
|
|
61
|
+
},
|
|
62
|
+
COMMENTS_SEND_CODE_USED: {
|
|
63
|
+
why: "An agent already used this setup code. A code pairs one agent, once.",
|
|
64
|
+
fix: "Press Send in the comment pill again for a new code."
|
|
65
|
+
},
|
|
66
|
+
COMMENTS_SEND_GRANT_INVALID: {
|
|
67
|
+
why: "The read token does not open this send: it is wrong, older than 24 hours, or the app turned read tokens off.",
|
|
68
|
+
fix: "Use the `read.token` of the same delivery within 24 hours. With `send: { grant: false }`, read the threads through the app's MCP tools instead."
|
|
69
|
+
},
|
|
70
|
+
COMMENTS_SEND_INSECURE: {
|
|
71
|
+
why: ({ origin }) => `Send answers with a setup code and a signing secret, and builds links that carry read tokens, so it does not run over plain http. The request came from ${origin}.`,
|
|
72
|
+
fix: "Open the site over https. In development, use `localhost`, `*.localhost`, or `127.0.0.1`. With `wrangler dev`, pass `--infer-origin-from-routes=false`, so the request keeps the local origin instead of the production host."
|
|
73
|
+
},
|
|
74
|
+
COMMENTS_SEND_OFF: {
|
|
75
|
+
why: "Send is off: `defineComments()` has no `send` option, or the app has no Webhooks.",
|
|
76
|
+
fix: "Set `defineComments({ send: true })` in `server/comments.ts`, in a ViteHub app with `vitehub({ database: true })`."
|
|
53
77
|
}
|
|
54
78
|
}
|
|
55
79
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as commentsClientCodes } from "./client-diagnostics-
|
|
1
|
+
import { n as commentsClientCodes } from "./client-diagnostics-Bubm7Shd.js";
|
|
2
2
|
import { defineDiagnostics } from "nostics";
|
|
3
3
|
//#region src/operations-core/errors.ts
|
|
4
4
|
const commentsErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
@@ -78,8 +78,8 @@ const commentsErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
78
78
|
fix: "Pass readAttachment to defineComments(), next to storeAttachment, and return the file of the key as a Blob."
|
|
79
79
|
},
|
|
80
80
|
COMMENTS_R0022: {
|
|
81
|
-
why: "Another comment thread of this scope already uses this requestId: it has another author or another subject, or you may not read it.",
|
|
82
|
-
fix: "Send a new requestId, such as crypto.randomUUID(), for each new comment. Send the same requestId again only to retry the same
|
|
81
|
+
why: "Another comment thread of this scope, or another reply in this thread, already uses this requestId: it has another author or another subject, or you may not read it.",
|
|
82
|
+
fix: "Send a new requestId, such as crypto.randomUUID(), for each new comment or reply. Send the same requestId again only to retry the same one."
|
|
83
83
|
},
|
|
84
84
|
COMMENTS_B0001: {
|
|
85
85
|
why: ({ file }) => `${file} needs a Database, but the Database is off for this app.`,
|
|
@@ -97,6 +97,10 @@ const commentsErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
97
97
|
why: ({ file }) => `The \`database\` option of defineComments() in ${file} is not a string literal. The build reads it without running the file, so Comments would use the default Database.`,
|
|
98
98
|
fix: "Write the Database name as a string literal, such as `defineComments({ database: \"content\" })`, and put no spread after it. Remove the option to use the default or only Database."
|
|
99
99
|
},
|
|
100
|
+
COMMENTS_DATABASE_TOKEN_IN_BUILD: {
|
|
101
|
+
why: "The `database` option of `comments()` has an `authToken` in its URL, so the token ends up in the build output.",
|
|
102
|
+
fix: "Put the URL with its token in a variable, and pass the variable: `comments({ database: \"env:COMMENTS_DATABASE_URL\" })`."
|
|
103
|
+
},
|
|
100
104
|
COMMENTS_GITHUB_CREDENTIALS_MISSING: {
|
|
101
105
|
why: "Comments needs GitHub credentials to post to pull requests: VITEHUB_GITHUB_APP_ID with VITEHUB_GITHUB_PRIVATE_KEY, or VITEHUB_GITHUB_TOKEN.",
|
|
102
106
|
fix: "Set `VITEHUB_GITHUB_APP_ID` and `VITEHUB_GITHUB_PRIVATE_KEY` of a GitHub App that is installed on the repository, or set `VITEHUB_GITHUB_TOKEN`."
|
|
@@ -125,9 +129,25 @@ const commentsErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
125
129
|
why: ({ issue }) => `defineComments(): ${issue}`,
|
|
126
130
|
fix: "Pass rateLimit as { limit, window }, such as { limit: 5, window: \"1m\" }, or remove it to let guests write without a limit."
|
|
127
131
|
},
|
|
132
|
+
COMMENTS_RESOLVE_INTERRUPTED: {
|
|
133
|
+
why: ({ completed, threadId, replied }) => `Resolution stopped at ${JSON.stringify(threadId)}${replied ? " after its reply was saved" : ""}. Completed threads: ${completed.map((id) => JSON.stringify(id)).join(", ") || "none"}.`,
|
|
134
|
+
fix: "Read the affected thread again and resolve the remaining threads."
|
|
135
|
+
},
|
|
128
136
|
COMMENTS_SECRET_TOO_SHORT: {
|
|
129
137
|
why: ({ minimum }) => `[vitehub] VITEHUB_SECRET must be at least ${minimum} characters. Generate one with \`openssl rand -base64 32\`.`,
|
|
130
138
|
fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters."
|
|
139
|
+
},
|
|
140
|
+
COMMENTS_SEND_POSTGRES: {
|
|
141
|
+
why: "`defineComments({ send })` keeps its sends in SQLite tables, and this app keeps comments in Postgres.",
|
|
142
|
+
fix: "Keep comments in a SQLite, libSQL, or D1 Database, or remove `send` from `defineComments()`."
|
|
143
|
+
},
|
|
144
|
+
COMMENTS_SEND_TABLES_MISSING: {
|
|
145
|
+
why: ({ missing }) => `\`defineComments({ send })\` needs the tables ${missing}, and the Database does not have them yet.`,
|
|
146
|
+
fix: "Run `vitehub database generate` and `vitehub database migrate`. `vite dev` applies the migration for you."
|
|
147
|
+
},
|
|
148
|
+
COMMENTS_SEND_WEBHOOKS_OFF: {
|
|
149
|
+
why: ({ file }) => `${file} turns on Send, and Send delivers through the member endpoints of Webhooks, which this app does not have.`,
|
|
150
|
+
fix: "Use Comments through `vitehub()`, which adds Webhooks, and install `@vite-hub/webhooks` when you use the packages one by one. `comments()` without `vite-hub` has no Send."
|
|
131
151
|
}
|
|
132
152
|
}
|
|
133
153
|
});
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { D as CommentUser, T as CommentThread, n as CommentActor, s as CommentContext, w as CommentSubject, y as CommentMessage } from "./types-BLaYh0_f.js";
|
|
2
|
+
import { f as CommentsPolicyGate, g as CommentsUser, t as CommentAction } from "./define-CmIFU96x.js";
|
|
3
|
+
import { _ as ListCommentThreadsOptions, g as FindCommentThreadInput, h as EditCommentInput, m as DefineCommentsOptions, o as CommentsErrorCode, p as CreateCommentThreadInput, v as ReplyInput, y as ReplyOptions } from "./types-C35INXIs.js";
|
|
4
|
+
import { n as commentSends, t as CommentSendState } from "./database-CTo7mx6t.js";
|
|
5
|
+
import "./store-CsUNfC1w.js";
|
|
6
|
+
import { Result } from "@vite-hub/runtime";
|
|
7
|
+
//#region src/send/store.d.ts
|
|
8
|
+
type SendRow = typeof commentSends.$inferSelect;
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/send/service.d.ts
|
|
11
|
+
interface EndpointLike {
|
|
12
|
+
id: string;
|
|
13
|
+
kind: "url" | "inbox";
|
|
14
|
+
agent: string | null;
|
|
15
|
+
host: string | null;
|
|
16
|
+
disabledAt: number | null;
|
|
17
|
+
}
|
|
18
|
+
interface PairingLike {
|
|
19
|
+
state: "waiting" | "paired" | "used" | "refused";
|
|
20
|
+
agent: string | null;
|
|
21
|
+
host: string | null;
|
|
22
|
+
address: string | null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The parts of `@vite-hub/webhooks` that Send uses: member pairing and member endpoints. The generated plugin imports the
|
|
26
|
+
* package only when `send` is on.
|
|
27
|
+
*/
|
|
28
|
+
interface CommentSendWebhooks {
|
|
29
|
+
startMemberPairing: (owner: string) => Promise<Result<{
|
|
30
|
+
code: string;
|
|
31
|
+
secret: string;
|
|
32
|
+
expiresAt: number;
|
|
33
|
+
}, string>>;
|
|
34
|
+
pairMemberEndpoint: (input: unknown, options?: {
|
|
35
|
+
hosts?: readonly string[];
|
|
36
|
+
}) => Promise<Result<{
|
|
37
|
+
status: "paired";
|
|
38
|
+
pairing: PairingLike;
|
|
39
|
+
} | {
|
|
40
|
+
status: "expired" | "used";
|
|
41
|
+
} | {
|
|
42
|
+
status: "refused";
|
|
43
|
+
reason: string;
|
|
44
|
+
}, string>>;
|
|
45
|
+
refuseMemberPairing: (code: string) => Promise<Result<boolean, string>>;
|
|
46
|
+
getMemberPairing: (owner: string, code: string) => Promise<Result<PairingLike | null, string>>;
|
|
47
|
+
cancelMemberPairing: (owner: string, code: string) => Promise<Result<void, string>>;
|
|
48
|
+
allowMemberPairing: (owner: string, code: string, options: {
|
|
49
|
+
name: string | ((pairing: PairingLike) => string);
|
|
50
|
+
ownerName?: string;
|
|
51
|
+
ownerEmail?: string;
|
|
52
|
+
hosts?: readonly string[];
|
|
53
|
+
}) => Promise<Result<{
|
|
54
|
+
status: "allowed";
|
|
55
|
+
endpoint: EndpointLike;
|
|
56
|
+
pairing: PairingLike;
|
|
57
|
+
} | {
|
|
58
|
+
status: "expired" | "not-owner";
|
|
59
|
+
}, string>>;
|
|
60
|
+
getMemberEndpoint: (owner: string, options?: {
|
|
61
|
+
address?: string;
|
|
62
|
+
endpointId?: string;
|
|
63
|
+
}) => Promise<Result<EndpointLike | null, string>>;
|
|
64
|
+
getMemberDeliveryState: (id: string) => Promise<"pending" | "sending" | "sent" | "dead" | "cancelled" | undefined>;
|
|
65
|
+
sendToMemberEndpoint: (owner: string, body: unknown, options: {
|
|
66
|
+
event: string;
|
|
67
|
+
key: string;
|
|
68
|
+
endpointId: string;
|
|
69
|
+
deliveryId: string;
|
|
70
|
+
sealBody: boolean;
|
|
71
|
+
hosts?: readonly string[];
|
|
72
|
+
}) => Promise<Result<{
|
|
73
|
+
id: string;
|
|
74
|
+
status: "sent" | "inbox" | "pending" | "failed";
|
|
75
|
+
}, string>>;
|
|
76
|
+
}
|
|
77
|
+
/** A thread of a send as its reader gets it: the thread, and whether it is the sender's ask or a quote. */
|
|
78
|
+
type CommentSendThread = CommentThread & {
|
|
79
|
+
role: "ask" | "quote";
|
|
80
|
+
};
|
|
81
|
+
/** What a read token, or `comments_get_send`, opens: the send and exactly its threads, as the sender may read them. */
|
|
82
|
+
interface CommentSendView {
|
|
83
|
+
send: {
|
|
84
|
+
id: string;
|
|
85
|
+
page: string;
|
|
86
|
+
subject: CommentSubject;
|
|
87
|
+
state: SendRow["state"];
|
|
88
|
+
createdAt: number;
|
|
89
|
+
};
|
|
90
|
+
threads: CommentSendThread[];
|
|
91
|
+
}
|
|
92
|
+
/** What the server checked before a read, as `comments.can()` takes it. */
|
|
93
|
+
interface CommentSendPolicy {
|
|
94
|
+
gate?: CommentsPolicyGate;
|
|
95
|
+
console?: boolean;
|
|
96
|
+
}
|
|
97
|
+
/** Which sends `listOwn` returns. Default: the sent and working ones, at most 20. */
|
|
98
|
+
interface CommentSendListOptions extends CommentSendPolicy {
|
|
99
|
+
states?: readonly Extract<CommentSendState, "sent" | "working" | "done">[];
|
|
100
|
+
limit?: number;
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/context.d.ts
|
|
104
|
+
/**
|
|
105
|
+
* The context of a thread as label and value pairs, in the order a person reads them: page, element, components,
|
|
106
|
+
* browser, build. The Console and Agent tools show these.
|
|
107
|
+
*/
|
|
108
|
+
declare function describeCommentContext(context: CommentContext | null): Array<{
|
|
109
|
+
label: string;
|
|
110
|
+
value: string;
|
|
111
|
+
}>;
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/index.d.ts
|
|
114
|
+
type Codes<T extends CommentsErrorCode> = T;
|
|
115
|
+
/** The Comments runtime of an app: the export of `server/comments.ts`. */
|
|
116
|
+
interface Comments {
|
|
117
|
+
readonly options: DefineCommentsOptions;
|
|
118
|
+
/** Threads with their messages, newest activity first. */
|
|
119
|
+
list(options?: ListCommentThreadsOptions): Promise<Result<CommentThread[], Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_INVALID_INPUT">>>;
|
|
120
|
+
get(id: string): Promise<Result<CommentThread, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND">>>;
|
|
121
|
+
/** The thread that holds a message, for a route that has only the message id. */
|
|
122
|
+
getByMessage(messageId: string): Promise<Result<CommentThread, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND">>>;
|
|
123
|
+
/** Thread `#n` of a numbering scope, such as `site`. */
|
|
124
|
+
getByNumber(scope: string, n: number): Promise<Result<CommentThread, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND">>>;
|
|
125
|
+
/**
|
|
126
|
+
* The thread that a `create` with this `requestId` stored in the scope of the subject, else `null`. Check it before
|
|
127
|
+
* work that a retry must not do twice, such as storing files. It does not compare authors: `create` does.
|
|
128
|
+
*/
|
|
129
|
+
findThread(input: FindCommentThreadInput): Promise<Result<CommentThread | null, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_INVALID_INPUT">>>;
|
|
130
|
+
/** The message that a `reply` with this `requestId` stored in the thread, else `null`. */
|
|
131
|
+
findReply(threadId: string, requestId: string): Promise<Result<CommentMessage | null, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND" | "COMMENTS_INVALID_INPUT">>>;
|
|
132
|
+
/** Starts a thread with its first message, numbered next in the scope of its subject. Runs `onComment`. */
|
|
133
|
+
create(input: CreateCommentThreadInput): Promise<Result<CommentThread, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_INVALID_INPUT">>>;
|
|
134
|
+
/** Adds a message to an open thread. Runs `onComment`. */
|
|
135
|
+
reply(threadId: string, input: ReplyInput, options?: ReplyOptions): Promise<Result<CommentMessage, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND" | "COMMENTS_INVALID_INPUT" | "COMMENTS_RESOLVED">>>;
|
|
136
|
+
/** `actor`: the agent that resolves it for `by`, as on `reply`. */
|
|
137
|
+
resolve(threadId: string, options: {
|
|
138
|
+
by: CommentUser;
|
|
139
|
+
actor?: CommentActor;
|
|
140
|
+
}): Promise<Result<CommentThread, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND">>>;
|
|
141
|
+
/** With `send`, it can restore a done inbox send or make the thread available to send again to a webhook agent. */
|
|
142
|
+
reopen(threadId: string): Promise<Result<CommentThread, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND">>>;
|
|
143
|
+
/** Deletes a thread and all its messages. */
|
|
144
|
+
remove(threadId: string): Promise<Result<void, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND">>>;
|
|
145
|
+
/** Deletes one message. Deleting the first message deletes the thread. */
|
|
146
|
+
removeMessage(messageId: string): Promise<Result<void, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND">>>;
|
|
147
|
+
/** Changes the text of a message and sets `editedAt`. */
|
|
148
|
+
edit(messageId: string, input: EditCommentInput): Promise<Result<CommentMessage, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND" | "COMMENTS_INVALID_INPUT">>>;
|
|
149
|
+
/** Deletes every thread of a numbering scope, such as when app code deletes the document that the scope names. */
|
|
150
|
+
removeScope(scope: string): Promise<Result<{
|
|
151
|
+
removed: number;
|
|
152
|
+
}, Codes<"COMMENTS_NOT_INSTALLED">>>;
|
|
153
|
+
/**
|
|
154
|
+
* Whether the `authorize` policy allows an action. Without a policy, see `defaultPolicy()`. `gate` says what your
|
|
155
|
+
* server checked before, such as Console section access; a route of your own usually passes nothing.
|
|
156
|
+
*/
|
|
157
|
+
can(context: {
|
|
158
|
+
user: CommentsUser | null;
|
|
159
|
+
action: CommentAction;
|
|
160
|
+
thread?: CommentThread;
|
|
161
|
+
subject?: CommentSubject;
|
|
162
|
+
console?: boolean;
|
|
163
|
+
}, gate?: CommentsPolicyGate): Promise<boolean>;
|
|
164
|
+
/** People that `@` suggests to `user`, at most 20: `people`, else Auth, else the authors of threads that `user` may read. */
|
|
165
|
+
people(context: {
|
|
166
|
+
query: string;
|
|
167
|
+
user: CommentsUser | null;
|
|
168
|
+
thread?: CommentThread;
|
|
169
|
+
subject?: CommentSubject;
|
|
170
|
+
limit?: number;
|
|
171
|
+
gate?: CommentsPolicyGate;
|
|
172
|
+
}): Promise<Result<CommentUser[], Codes<"COMMENTS_NOT_INSTALLED">>>;
|
|
173
|
+
/**
|
|
174
|
+
* With `send`: the sends of `user`, newest first, with the threads that `user` may still read. Default: the ones that
|
|
175
|
+
* reached the agent and that it has not finished, at most 20. As it scans, it marks finished sends as done.
|
|
176
|
+
*/
|
|
177
|
+
listSends(user: CommentsUser, options?: CommentSendListOptions): Promise<Result<CommentSendView[], Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_SEND_OFF">>>;
|
|
178
|
+
/**
|
|
179
|
+
* With `send`: a send of `user` with the threads that `user` may still read, as `comments_get_send` opens it. A send
|
|
180
|
+
* that reached the agent becomes `working`.
|
|
181
|
+
*/
|
|
182
|
+
readSend(user: CommentsUser, id: string, policy?: CommentSendPolicy): Promise<Result<CommentSendView, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND" | "COMMENTS_SEND_OFF">>>;
|
|
183
|
+
/**
|
|
184
|
+
* With `forge`: brings the thread's pull request comments in line with the thread now, and posts what failed
|
|
185
|
+
* before. Every change starts this on its own; `flush()` waits for it.
|
|
186
|
+
*/
|
|
187
|
+
sync(threadId: string): Promise<void>;
|
|
188
|
+
/** Waits for the pull request syncs and `onMention` calls that earlier changes started. On Cloudflare, pass it to `waitUntil`. */
|
|
189
|
+
flush(): Promise<void>;
|
|
190
|
+
}
|
|
191
|
+
/** Defines Comments for the app: the access policy, the people, the hooks, and the trusted server API. */
|
|
192
|
+
declare function defineComments(options?: DefineCommentsOptions): Comments;
|
|
193
|
+
//#endregion
|
|
194
|
+
export { CommentSendPolicy as a, CommentSendWebhooks as c, CommentSendListOptions as i, defineComments as n, CommentSendThread as o, describeCommentContext as r, CommentSendView as s, Comments as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import { _ as
|
|
3
|
-
import { a as
|
|
4
|
-
import { t as
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
export { type AreaAnchor, type CommentAction, type CommentActor, type CommentAnchor, type CommentAttachment, type CommentBuild, type CommentComponent, type CommentContext, type CommentCreateInput, type CommentDeleteInput, type CommentEditInput, type CommentEvent, type CommentForgeLink, type CommentGetInput, type CommentListCursor, type CommentListQuery, type CommentMentionEvent, type CommentMessage, type CommentMessageEvent, type CommentMetadata, type CommentReplyInput, type CommentStatus, type CommentStatusInput, type CommentSubject, type CommentSubjectDefinition, type CommentThread, type CommentUploadInput, type CommentUser, type CommentUsersInput, Comments, type CommentsAttachmentFile, type CommentsAuthorize, type CommentsAuthorizeContext, type CommentsCanMentionContext, type CommentsDefinition, type CommentsErrorCode, type CommentsForgeOptions, type CommentsForgeTarget, type CommentsGitHubAccess, type CommentsIdentifyContext, type CommentsPageContext, type CommentsPageSubject, type CommentsPeople, type CommentsPolicyGate, type CommentsRateLimit, type CommentsReadAttachmentContext, type CommentsRequestEvent, type CommentsStoreAttachmentContext, type CommentsTransport, type CommentsUser, type CreateCommentThreadInput, type DefineCommentsOptions, type EditCommentInput, type ElementAnchor, type ImageAnchor, type ListCommentThreadsOptions, type PageAnchor, type ReplyInput, type ReplyOptions, type TextAnchor, builtinCommentSubjects, commentRoom, commentsErrorDiagnostics, commentsPageScope, commentsRealtimeDefinition, commentsRoleAllows, commentsRoute, commentsRuntimeOf, defaultPolicy, defineCommentSubject, defineComments, describeCommentContext, normalizeCommentPage, resolveCommentsRuntime };
|
|
1
|
+
import { A as ElementAnchor, C as CommentStatusInput, D as CommentUser, E as CommentUploadInput, M as PageAnchor, N as TextAnchor, O as CommentUsersInput, S as CommentStatus, T as CommentThread, _ as CommentListCursor, a as CommentBuild, b as CommentMetadata, c as CommentCreateInput, d as CommentDeliveryError, f as CommentEditInput, g as CommentGetInput, h as CommentForgeLink, i as CommentAttachment, j as ImageAnchor, k as CommentsTransport, l as CommentDeleteInput, m as CommentFiles, n as CommentActor, o as CommentComponent, p as CommentEvent, r as CommentAnchor, s as CommentContext, t as AreaAnchor, u as CommentDelivery, v as CommentListQuery, w as CommentSubject, x as CommentReplyInput, y as CommentMessage } from "./types-BLaYh0_f.js";
|
|
2
|
+
import { _ as commentsRoleAllows, a as CommentsAttachmentFile, c as CommentsCanMentionContext, d as CommentsPeople, f as CommentsPolicyGate, g as CommentsUser, h as CommentsStoreAttachmentContext, i as CommentSubjectDefinition, l as CommentsDefinition, m as CommentsReadAttachmentContext, n as CommentMentionEvent, o as CommentsAuthorize, p as CommentsRateLimit, r as CommentMessageEvent, s as CommentsAuthorizeContext, t as CommentAction, u as CommentsGitHubAccess, v as defaultPolicy, y as defineCommentSubject } from "./define-CmIFU96x.js";
|
|
3
|
+
import { _ as ListCommentThreadsOptions, a as CommentSendPromptContext, c as CommentsForgeTarget, d as CommentsPageSubject, f as CommentsRequestEvent, g as FindCommentThreadInput, h as EditCommentInput, i as CommentSendPayloadContext, l as CommentsIdentifyContext, m as DefineCommentsOptions, n as CommentSendData, o as CommentsErrorCode, p as CreateCommentThreadInput, r as CommentSendOptions, s as CommentsForgeOptions, t as CommentSendAddressContext, u as CommentsPageContext, v as ReplyInput, y as ReplyOptions } from "./types-C35INXIs.js";
|
|
4
|
+
import { a as CommentSendPolicy, i as CommentSendListOptions, n as defineComments, o as CommentSendThread, r as describeCommentContext, s as CommentSendView, t as Comments } from "./index-RiHzmV16.js";
|
|
5
|
+
import { r as normalizeCommentPage, t as commentRoom } from "./page-Bzj0CszG.js";
|
|
6
|
+
export { type AreaAnchor, type CommentAction, type CommentActor, type CommentAnchor, type CommentAttachment, type CommentBuild, type CommentComponent, type CommentContext, type CommentCreateInput, type CommentDeleteInput, type CommentDelivery, type CommentDeliveryError, type CommentEditInput, type CommentEvent, type CommentFiles, type CommentForgeLink, type CommentGetInput, type CommentListCursor, type CommentListQuery, type CommentMentionEvent, type CommentMessage, type CommentMessageEvent, type CommentMetadata, type CommentReplyInput, type CommentSendAddressContext, type CommentSendData, type CommentSendListOptions, type CommentSendOptions, type CommentSendPayloadContext, type CommentSendPolicy, type CommentSendPromptContext, type CommentSendThread, type CommentSendView, type CommentStatus, type CommentStatusInput, type CommentSubject, type CommentSubjectDefinition, type CommentThread, type CommentUploadInput, type CommentUser, type CommentUsersInput, Comments, type CommentsAttachmentFile, type CommentsAuthorize, type CommentsAuthorizeContext, type CommentsCanMentionContext, type CommentsDefinition, type CommentsErrorCode, type CommentsForgeOptions, type CommentsForgeTarget, type CommentsGitHubAccess, type CommentsIdentifyContext, type CommentsPageContext, type CommentsPageSubject, type CommentsPeople, type CommentsPolicyGate, type CommentsRateLimit, type CommentsReadAttachmentContext, type CommentsRequestEvent, type CommentsStoreAttachmentContext, type CommentsTransport, type CommentsUser, type CreateCommentThreadInput, type DefineCommentsOptions, type EditCommentInput, type ElementAnchor, type FindCommentThreadInput, type ImageAnchor, type ListCommentThreadsOptions, type PageAnchor, type ReplyInput, type ReplyOptions, type TextAnchor, commentRoom, commentsRoleAllows, defaultPolicy, defineCommentSubject, defineComments, describeCommentContext, normalizeCommentPage };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { t as commentsErrorDiagnostics } from "./errors-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { t as commentsErrorDiagnostics } from "./errors-Dq4AHjza.js";
|
|
2
|
+
import { o as normalizeCommentPage, t as commentRoom } from "./page-DRz_sDY4.js";
|
|
3
|
+
import { S as suggest, a as createThread, b as scopeOf, c as earlierThread, g as replyToThread, l as editMessage, r as can, s as earlierReply, w as clientRateLimitIssue } from "./service-DA5BwfPQ.js";
|
|
4
4
|
import { t as describeCommentContext } from "./context-BqIsmYP1.js";
|
|
5
|
-
import { a as defineCommentSubject, i as defaultPolicy, n as commentsRoleAllows, s as markCommentsDefinition
|
|
6
|
-
import {
|
|
7
|
-
import { t as
|
|
5
|
+
import { a as defineCommentSubject, i as defaultPolicy, n as commentsRoleAllows, s as markCommentsDefinition } from "./define-BMBSVbD9.js";
|
|
6
|
+
import { t as commentsErrors } from "./errors-BJTZ9iyv.js";
|
|
7
|
+
import { a as runtimeOf, n as pendingKey, o as runtimes, t as commentSendOf } from "./installed-C3EoqJEY.js";
|
|
8
8
|
//#region src/index.ts
|
|
9
9
|
/** A thread that someone deleted during the change: the store reads it again and finds nothing. */
|
|
10
10
|
function gone(error) {
|
|
@@ -16,6 +16,11 @@ function resultError(error, id) {
|
|
|
16
16
|
const code = error instanceof Error ? Reflect.get(error, "code") : void 0;
|
|
17
17
|
if (code === "COMMENTS_R0002" || code === "COMMENTS_R0003") return commentsErrors.COMMENTS_NOT_FOUND({ id });
|
|
18
18
|
if (code === "COMMENTS_R0016") return commentsErrors.COMMENTS_RESOLVED();
|
|
19
|
+
return invalidInput(error);
|
|
20
|
+
}
|
|
21
|
+
/** A diagnostic of the shared core about the input, as `COMMENTS_INVALID_INPUT`. Any other error is thrown again. */
|
|
22
|
+
function invalidInput(error) {
|
|
23
|
+
const code = error instanceof Error ? Reflect.get(error, "code") : void 0;
|
|
19
24
|
if (typeof code === "string" && [
|
|
20
25
|
"COMMENTS_R0005",
|
|
21
26
|
"COMMENTS_R0007",
|
|
@@ -77,6 +82,35 @@ function defineComments(options = {}) {
|
|
|
77
82
|
if (!current) return notInstalled();
|
|
78
83
|
return one(current, await current.store.getByNumber(scope, n), `${scope}#${n}`);
|
|
79
84
|
},
|
|
85
|
+
async findThread({ page, subject, requestId }) {
|
|
86
|
+
const current = await runtime();
|
|
87
|
+
if (!current) return notInstalled();
|
|
88
|
+
const target = subject ?? (page === void 0 ? void 0 : {
|
|
89
|
+
id: normalizeCommentPage(page),
|
|
90
|
+
kind: "page"
|
|
91
|
+
});
|
|
92
|
+
if (!target) return [commentsErrors.COMMENTS_INVALID_INPUT({ issue: "subject: Give a subject, or a page." }), void 0];
|
|
93
|
+
try {
|
|
94
|
+
const found = await earlierThread(current, {
|
|
95
|
+
requestId,
|
|
96
|
+
subject: target
|
|
97
|
+
});
|
|
98
|
+
return [void 0, found ? (await withForge(current, [found]))[0] : null];
|
|
99
|
+
} catch (error) {
|
|
100
|
+
return [invalidInput(error), void 0];
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
async findReply(threadId, requestId) {
|
|
104
|
+
const current = await runtime();
|
|
105
|
+
if (!current) return notInstalled();
|
|
106
|
+
const found = await current.store.getById(threadId);
|
|
107
|
+
if (!found) return notFound(threadId);
|
|
108
|
+
try {
|
|
109
|
+
return [void 0, await earlierReply(found, requestId) ?? null];
|
|
110
|
+
} catch (error) {
|
|
111
|
+
return [invalidInput(error), void 0];
|
|
112
|
+
}
|
|
113
|
+
},
|
|
80
114
|
async create({ page, subject, ...input }) {
|
|
81
115
|
const current = await runtime();
|
|
82
116
|
if (!current) return notInstalled();
|
|
@@ -107,11 +141,11 @@ function defineComments(options = {}) {
|
|
|
107
141
|
return [resultError(error, threadId), void 0];
|
|
108
142
|
}
|
|
109
143
|
},
|
|
110
|
-
async resolve(threadId, { by }) {
|
|
144
|
+
async resolve(threadId, { by, actor }) {
|
|
111
145
|
const current = await runtime();
|
|
112
146
|
if (!current) return notInstalled();
|
|
113
147
|
if (!await current.store.getById(threadId)) return notFound(threadId);
|
|
114
|
-
const thread = await current.store.setStatus(threadId, "resolved", by, Date.now()).catch(gone);
|
|
148
|
+
const thread = await current.store.setStatus(threadId, "resolved", by, Date.now(), actor).catch(gone);
|
|
115
149
|
if (!thread) return notFound(threadId);
|
|
116
150
|
current.forge?.changed(threadId);
|
|
117
151
|
return [void 0, thread];
|
|
@@ -123,6 +157,7 @@ function defineComments(options = {}) {
|
|
|
123
157
|
const thread = await current.store.setStatus(threadId, "open", { id: "" }, Date.now()).catch(gone);
|
|
124
158
|
if (!thread) return notFound(threadId);
|
|
125
159
|
current.forge?.changed(threadId);
|
|
160
|
+
await current.reopened?.(thread);
|
|
126
161
|
return [void 0, thread];
|
|
127
162
|
},
|
|
128
163
|
async remove(threadId) {
|
|
@@ -181,6 +216,19 @@ function defineComments(options = {}) {
|
|
|
181
216
|
...subject ? { subject } : {}
|
|
182
217
|
})];
|
|
183
218
|
},
|
|
219
|
+
async listSends(user, listOptions) {
|
|
220
|
+
if (!await runtime()) return notInstalled();
|
|
221
|
+
const service = await commentSendOf(comments);
|
|
222
|
+
if (!service) return [commentsErrors.COMMENTS_SEND_OFF(), void 0];
|
|
223
|
+
return [void 0, await service.listOwn(user, listOptions)];
|
|
224
|
+
},
|
|
225
|
+
async readSend(user, id, policy) {
|
|
226
|
+
if (!await runtime()) return notInstalled();
|
|
227
|
+
const service = await commentSendOf(comments);
|
|
228
|
+
if (!service) return [commentsErrors.COMMENTS_SEND_OFF(), void 0];
|
|
229
|
+
const opened = await service.readOwn(user, id, policy);
|
|
230
|
+
return opened ? [void 0, opened] : notFound(id);
|
|
231
|
+
},
|
|
184
232
|
async sync(threadId) {
|
|
185
233
|
await runtime();
|
|
186
234
|
await runtimes.get(comments)?.sync?.(threadId);
|
|
@@ -193,4 +241,4 @@ function defineComments(options = {}) {
|
|
|
193
241
|
return Object.freeze(markCommentsDefinition(comments));
|
|
194
242
|
}
|
|
195
243
|
//#endregion
|
|
196
|
-
export {
|
|
244
|
+
export { commentRoom, commentsRoleAllows, defaultPolicy, defineCommentSubject, defineComments, describeCommentContext, normalizeCommentPage };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { d as CommentsPeople } from "./define-
|
|
1
|
+
import { d as CommentsPeople } from "./define-CmIFU96x.js";
|
|
2
2
|
import { a as commentsSchema } from "./database-CA1aHKN7.js";
|
|
3
3
|
import { r as CommentsSchemaOwner } from "./migrate-B0k_0swk.js";
|
|
4
|
-
import { t as
|
|
5
|
-
import { c as
|
|
4
|
+
import { r as CommentsTables, t as CommentsDatabase } from "./store-CsUNfC1w.js";
|
|
5
|
+
import { c as CommentSendWebhooks, t as Comments } from "./index-RiHzmV16.js";
|
|
6
|
+
import { i as CommentsRuntime, n as CommentsAttachmentStore, o as SharedRateLimit } from "./service-Bj-Mg63c.js";
|
|
6
7
|
//#region src/install.d.ts
|
|
7
8
|
interface InstallCommentsOptions {
|
|
8
9
|
database: CommentsDatabase;
|
|
@@ -26,6 +27,11 @@ interface InstallCommentsOptions {
|
|
|
26
27
|
schema?: CommentsSchemaOwner;
|
|
27
28
|
/** The SQL dialect of `database`. Default `sqlite`: SQLite, libSQL, and D1. */
|
|
28
29
|
dialect?: "sqlite" | "postgresql";
|
|
30
|
+
/**
|
|
31
|
+
* Loads `@vite-hub/webhooks`, for `defineComments({ send })`. The generated plugin passes it when `send` is on.
|
|
32
|
+
* Without it, the Send routes answer `COMMENTS_SEND_OFF`.
|
|
33
|
+
*/
|
|
34
|
+
webhooks?: () => Promise<CommentSendWebhooks>;
|
|
29
35
|
}
|
|
30
36
|
/**
|
|
31
37
|
* Connects a Comments definition to its Database, for the server API, the overlay API, and the comment operations.
|