@blogmcp/sdk 0.3.2 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/client-types.d.ts +7 -1
- package/dist/core/client.d.ts +25 -1
- package/dist/core/client.js +38 -34
- package/dist/core/consultation-adapter.d.ts +90 -0
- package/dist/core/consultation-adapter.js +200 -0
- package/dist/core/consultations.d.ts +108 -0
- package/dist/core/consultations.js +95 -0
- package/dist/core/errors.d.ts +52 -0
- package/dist/core/errors.js +73 -0
- package/dist/core/index.d.ts +7 -1
- package/dist/core/index.js +80 -64
- package/dist/core/queries.d.ts +16 -1
- package/dist/core/queries.js +198 -61
- package/dist/core/review/format.d.ts +30 -0
- package/dist/core/review/format.js +78 -0
- package/dist/core/review/index.d.ts +6 -0
- package/dist/core/review/index.js +9 -0
- package/dist/core/review/types.d.ts +176 -0
- package/dist/core/review/types.js +9 -0
- package/dist/core/server-only.d.ts +12 -0
- package/dist/core/server-only.js +11 -0
- package/dist/core/types.d.ts +295 -0
- package/dist/packages/mdx-render-vue/dist/composables/useGallery.js +12 -11
- package/dist/packages/mdx-render-vue/dist/composables/useTripMap.js +16 -16
- package/dist/packages/mdx-render-vue/dist/edit/TripMapEdit.vue.js +1 -1
- package/dist/packages/mdx-render-vue/dist/registry.js +21 -22
- package/dist/packages/mdx-render-vue/dist/render/alert/Alert.vue2.js +1 -1
- package/dist/packages/mdx-render-vue/dist/render/badge/Badge.vue2.js +1 -1
- package/dist/packages/mdx-render-vue/dist/render/button/Button.vue2.js +1 -1
- package/dist/packages/mdx-render-vue/dist/render/callout/CalloutDefault.vue.js +1 -1
- package/dist/packages/mdx-render-vue/dist/render/callout/CalloutMinimal.vue.js +1 -1
- package/dist/packages/mdx-render-vue/dist/render/tripmap/TripMapDefault.vue.js +2 -2
- package/dist/packages/tripmap-core/dist/attribution.js +121 -6
- package/dist/packages/tripmap-core/dist/css.js +68 -16
- package/dist/packages/tripmap-core/dist/detail.js +10 -9
- package/dist/packages/tripmap-core/dist/engine.js +285 -247
- package/dist/packages/tripmap-core/dist/export.js +48 -46
- package/dist/packages/tripmap-core/dist/filmstrip.js +30 -17
- package/dist/packages/tripmap-core/dist/framing.js +30 -30
- package/dist/packages/tripmap-core/dist/generated/maplibre-worker.bundle.js +1 -1
- package/dist/packages/tripmap-core/dist/heading.js +8 -0
- package/dist/packages/tripmap-core/dist/href.js +18 -0
- package/dist/packages/tripmap-core/dist/index.js +32 -24
- package/dist/packages/tripmap-core/dist/lightbox.js +31 -29
- package/dist/packages/tripmap-core/dist/line.js +6 -6
- package/dist/packages/tripmap-core/dist/markers.js +47 -43
- package/dist/packages/tripmap-core/dist/nodes.js +56 -43
- package/dist/packages/tripmap-core/dist/playback.js +17 -17
- package/dist/packages/tripmap-core/dist/preload.js +14 -14
- package/dist/packages/tripmap-core/dist/theme.js +21 -21
- package/dist/{node_modules → packages/tripmap-core/node_modules}/maplibre-gl/dist/maplibre-gl.js +1890 -1720
- package/dist/{node_modules → packages/tripmap-core/node_modules}/pmtiles/dist/esm/index.js +1 -1
- package/dist/react/KbMdxContent.js +7 -8
- package/dist/vue/components/KbMdxContent.vue2.js +6 -7
- package/package.json +8 -3
- package/src/core/client-types.ts +13 -2
- package/src/core/client.ts +40 -5
- package/src/core/consultation-adapter.ts +408 -0
- package/src/core/consultations.ts +224 -0
- package/src/core/errors.ts +145 -0
- package/src/core/index.ts +68 -0
- package/src/core/queries.ts +167 -3
- package/src/core/review/format.ts +138 -0
- package/src/core/review/index.ts +22 -0
- package/src/core/review/types.ts +168 -0
- package/src/core/server-only.ts +20 -0
- package/src/core/types.ts +337 -0
- package/dist/_virtual/constants.js +0 -4
- package/dist/_virtual/index.js +0 -2
- package/dist/_virtual/index2.js +0 -4
- package/dist/_virtual/index3.js +0 -2
- package/dist/_virtual/re.js +0 -4
- package/dist/node_modules/@braintree/sanitize-url/dist/constants.js +0 -8
- package/dist/node_modules/@braintree/sanitize-url/dist/index.js +0 -60
- package/dist/node_modules/dompurify/dist/purify.es.js +0 -662
- package/dist/node_modules/semver/classes/comparator.js +0 -56
- package/dist/node_modules/semver/classes/range.js +0 -148
- package/dist/node_modules/semver/classes/semver.js +0 -169
- package/dist/node_modules/semver/functions/clean.js +0 -14
- package/dist/node_modules/semver/functions/cmp.js +0 -39
- package/dist/node_modules/semver/functions/coerce.js +0 -33
- package/dist/node_modules/semver/functions/compare-build.js +0 -14
- package/dist/node_modules/semver/functions/compare-loose.js +0 -11
- package/dist/node_modules/semver/functions/compare.js +0 -11
- package/dist/node_modules/semver/functions/diff.js +0 -24
- package/dist/node_modules/semver/functions/eq.js +0 -11
- package/dist/node_modules/semver/functions/gt.js +0 -11
- package/dist/node_modules/semver/functions/gte.js +0 -11
- package/dist/node_modules/semver/functions/inc.js +0 -21
- package/dist/node_modules/semver/functions/lt.js +0 -11
- package/dist/node_modules/semver/functions/lte.js +0 -11
- package/dist/node_modules/semver/functions/major.js +0 -11
- package/dist/node_modules/semver/functions/minor.js +0 -11
- package/dist/node_modules/semver/functions/neq.js +0 -11
- package/dist/node_modules/semver/functions/parse.js +0 -21
- package/dist/node_modules/semver/functions/patch.js +0 -11
- package/dist/node_modules/semver/functions/prerelease.js +0 -14
- package/dist/node_modules/semver/functions/rcompare.js +0 -11
- package/dist/node_modules/semver/functions/rsort.js +0 -11
- package/dist/node_modules/semver/functions/satisfies.js +0 -18
- package/dist/node_modules/semver/functions/sort.js +0 -11
- package/dist/node_modules/semver/functions/valid.js +0 -14
- package/dist/node_modules/semver/index.js +0 -97
- package/dist/node_modules/semver/internal/constants.js +0 -28
- package/dist/node_modules/semver/internal/debug.js +0 -8
- package/dist/node_modules/semver/internal/identifiers.js +0 -18
- package/dist/node_modules/semver/internal/lrucache.js +0 -32
- package/dist/node_modules/semver/internal/parse-options.js +0 -10
- package/dist/node_modules/semver/internal/re.js +0 -32
- package/dist/node_modules/semver/ranges/gtr.js +0 -11
- package/dist/node_modules/semver/ranges/intersects.js +0 -11
- package/dist/node_modules/semver/ranges/ltr.js +0 -11
- package/dist/node_modules/semver/ranges/max-satisfying.js +0 -22
- package/dist/node_modules/semver/ranges/min-satisfying.js +0 -22
- package/dist/node_modules/semver/ranges/min-version.js +0 -42
- package/dist/node_modules/semver/ranges/outside.js +0 -44
- package/dist/node_modules/semver/ranges/simplify.js +0 -24
- package/dist/node_modules/semver/ranges/subset.js +0 -94
- package/dist/node_modules/semver/ranges/to-comparators.js +0 -11
- package/dist/node_modules/semver/ranges/valid.js +0 -17
- package/dist/packages/mdx-schema/dist/composables/useMdxParsing.js +0 -389
- package/dist/packages/mdx-schema/dist/metadata/index.js +0 -526
- package/dist/packages/mdx-schema/dist/prepareProps.js +0 -46
- package/dist/packages/mdx-schema/dist/styles/index.js +0 -141
- package/dist/packages/mdx-schema/dist/tripmap.js +0 -88
- package/dist/packages/mdx-schema/dist/types/index.js +0 -26
- package/dist/packages/sanitize/dist/html.js +0 -89
- /package/dist/{node_modules → packages/tripmap-core/node_modules}/maplibre-gl/dist/maplibre-gl-shared.js +0 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A review round as the text the agent reads — the format the article-review MCP app
|
|
3
|
+
* posts into the chat (packages/mcp-app-article-review: media summary, then "Feedback
|
|
4
|
+
* on article …", then one fenced `visual_feedback` JSON block), so skills that act on
|
|
5
|
+
* that block work unchanged. Used by md-editor's pull tool and by the review page's
|
|
6
|
+
* "Copy for Claude".
|
|
7
|
+
*
|
|
8
|
+
* Two differences from the app, both because a review link's author is whoever holds
|
|
9
|
+
* the link — not the person in the chat:
|
|
10
|
+
* - The reviewer's own words cannot take the shape of the rest. A one-line text is
|
|
11
|
+
* written as is, a longer one line by line behind `> `, and backtick fences inside it
|
|
12
|
+
* are defused, so a note cannot forge a "Selected media:" entry or a second
|
|
13
|
+
* `visual_feedback` block.
|
|
14
|
+
* - A comment without a quote says what it is about (a field, a block, a section, the
|
|
15
|
+
* page) — the app only ever has quoted comments.
|
|
16
|
+
* The `visual_feedback` block holds exactly what the app's does: the comments anchored
|
|
17
|
+
* to at least one block with a rectangle; none, no block.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type { ReviewComment, ReviewMediaSnapshot, StoredReviewRound } from './types'
|
|
21
|
+
|
|
22
|
+
const QUOTE_PREVIEW = 120
|
|
23
|
+
|
|
24
|
+
const LINE_BREAK = /\r\n|[\r\n\u0085\u2028\u2029]/
|
|
25
|
+
const FENCE = /`{3,}/g
|
|
26
|
+
|
|
27
|
+
function truncateQuote(text: string, max: number): string {
|
|
28
|
+
if (text.length <= max) return text
|
|
29
|
+
let end = max
|
|
30
|
+
const code = text.charCodeAt(max - 1)
|
|
31
|
+
if (code >= 0xd800 && code <= 0xdbff) end = max - 1 // would split a surrogate pair
|
|
32
|
+
return text.slice(0, end) + '…'
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** A run of three or more backticks becomes the same number of apostrophes. */
|
|
36
|
+
function defuse(text: string): string {
|
|
37
|
+
return text.replace(FENCE, (run) => "'".repeat(run.length))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Reviewer text squeezed onto one line (quotes, headings, media notes). */
|
|
41
|
+
function oneLine(text: string): string {
|
|
42
|
+
return defuse(text).split(LINE_BREAK).join(' ')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Reviewer text after a lead-in: one line stays inline, more go below, each behind `> `. */
|
|
46
|
+
function reviewerText(lead: string, text: string): string[] {
|
|
47
|
+
const lines = defuse(text).split(LINE_BREAK)
|
|
48
|
+
if (lines.length === 1) return [`${lead} ${lines[0]}`]
|
|
49
|
+
return [lead, ...lines.map((l) => ` > ${l}`)]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** One media line block — the media picker's `formatItem`, plus the reviewer's note. */
|
|
53
|
+
function formatMedia(item: ReviewMediaSnapshot, comment: string | null, anchorNodeId: string | null): string {
|
|
54
|
+
const lines: string[] = [`- ${item.slug} (${item.mediaType})`]
|
|
55
|
+
if (item.url) lines.push(` URL: ${item.url}`)
|
|
56
|
+
const label = item.altText || item.title
|
|
57
|
+
if (label) lines.push(` ${item.altText ? 'Alt' : 'Title'}: "${label}"`)
|
|
58
|
+
if (item.title && item.altText && item.title !== item.altText) lines.push(` Title: "${item.title}"`)
|
|
59
|
+
if (item.description) lines.push(` Description: "${item.description}"`)
|
|
60
|
+
if (item.durationSeconds != null) lines.push(` Duration: ${item.durationSeconds}s`)
|
|
61
|
+
if (anchorNodeId) lines.push(` Place near block: ${anchorNodeId}`)
|
|
62
|
+
if (comment) lines.push(` Reviewer: "${oneLine(comment)}"`)
|
|
63
|
+
return lines.join('\n')
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function where(c: ReviewComment): string {
|
|
67
|
+
if (c.anchorText) return 'On selected passage:'
|
|
68
|
+
if (c.context?.field) return `On the ${c.context.field}:`
|
|
69
|
+
const node = c.nodes?.[0]
|
|
70
|
+
if (node) return `On block ${node.id} (${node.component}):`
|
|
71
|
+
if (c.context?.heading) return `In section "${truncateQuote(oneLine(c.context.heading), 80)}":`
|
|
72
|
+
return 'On the page:'
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The text blocks of one round, in the app's order. */
|
|
76
|
+
export function formatReviewRound(round: StoredReviewRound['payload'], filename: string): string[] {
|
|
77
|
+
const blocks: string[] = []
|
|
78
|
+
if (round.media.length > 0) {
|
|
79
|
+
const header = round.media.length === 1 ? 'Selected media:' : `Selected ${round.media.length} media items:`
|
|
80
|
+
blocks.push(`${header}\n${round.media.map((m) => formatMedia(m.item, m.comment, m.anchorNodeId)).join('\n')}`)
|
|
81
|
+
}
|
|
82
|
+
const note = (round.note ?? '').trim()
|
|
83
|
+
if (round.comments.length > 0 || note) {
|
|
84
|
+
const lines: string[] = [`Feedback on article ${filename}:`, '']
|
|
85
|
+
round.comments.forEach((c, i) => {
|
|
86
|
+
lines.push(`${i + 1}. ${where(c)}`)
|
|
87
|
+
if (c.anchorText) lines.push(`"${truncateQuote(oneLine(c.anchorText), QUOTE_PREVIEW)}"`)
|
|
88
|
+
lines.push(...reviewerText('→', c.body))
|
|
89
|
+
lines.push('')
|
|
90
|
+
})
|
|
91
|
+
if (note) {
|
|
92
|
+
lines.push('General note:')
|
|
93
|
+
lines.push(...defuse(note).split(LINE_BREAK).map((l) => `> ${l}`))
|
|
94
|
+
}
|
|
95
|
+
blocks.push(lines.join('\n').trim())
|
|
96
|
+
|
|
97
|
+
// The app's rule: only comments anchored to a block, with the rectangle they were drawn in.
|
|
98
|
+
const anchored = round.comments.filter((c) => c.rect && (c.nodes ?? []).length > 0)
|
|
99
|
+
if (anchored.length > 0) {
|
|
100
|
+
const payload = {
|
|
101
|
+
type: 'visual_feedback',
|
|
102
|
+
filename,
|
|
103
|
+
comments: anchored.map((c) => ({
|
|
104
|
+
body: c.body,
|
|
105
|
+
anchorText: c.anchorText ?? '',
|
|
106
|
+
nodes: (c.nodes ?? []).map((n) => ({ id: n.id, component: n.component, ...(n.sourceRange ? { sourceRange: n.sourceRange } : {}) })),
|
|
107
|
+
rect: { x: c.rect!.x, y: c.rect!.y, width: c.rect!.width, height: c.rect!.height },
|
|
108
|
+
})),
|
|
109
|
+
}
|
|
110
|
+
// Backticks escaped inside the JSON strings, so nothing in it can close the fence.
|
|
111
|
+
blocks.push('```visual_feedback\n' + JSON.stringify(payload).replace(/`/g, '\\u0060') + '\n```')
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return blocks
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Several rounds for the agent, oldest first, each headed with when it was sent and
|
|
119
|
+
* which article version the reviewer saw (`currentVersionNumber` flags a stale round:
|
|
120
|
+
* its source ranges may not fit the text any more — go by the quotes).
|
|
121
|
+
*/
|
|
122
|
+
export function formatReviewForAgent(
|
|
123
|
+
rounds: StoredReviewRound[],
|
|
124
|
+
opts: { filename: string; currentVersionNumber?: number | null },
|
|
125
|
+
): string {
|
|
126
|
+
return rounds
|
|
127
|
+
.map((r) => {
|
|
128
|
+
const stale =
|
|
129
|
+
r.baseVersionNumber != null && opts.currentVersionNumber != null && r.baseVersionNumber !== opts.currentVersionNumber
|
|
130
|
+
const head =
|
|
131
|
+
`Review round ${r.seq} (sent ${r.submittedAt}` +
|
|
132
|
+
(r.baseVersionNumber != null ? `, on version ${r.baseVersionNumber}` : '') +
|
|
133
|
+
(stale ? `; the article is now at version ${opts.currentVersionNumber} — locate edits by the quoted text, not the source ranges` : '') +
|
|
134
|
+
')'
|
|
135
|
+
return [head, ...formatReviewRound(r.payload, opts.filename)].join('\n\n')
|
|
136
|
+
})
|
|
137
|
+
.join('\n\n---\n\n')
|
|
138
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Review links — review a draft on your own article page (docs: "Add review to your
|
|
3
|
+
* frontend"). Dependency-free; the review layer itself ships as `@blogmcp/review`.
|
|
4
|
+
*/
|
|
5
|
+
export {
|
|
6
|
+
REVIEW_PAGE_PATH,
|
|
7
|
+
REVIEW_ROUTE_PATTERN,
|
|
8
|
+
isReviewTokenFormat,
|
|
9
|
+
type ReviewMediaScope,
|
|
10
|
+
type ReviewMediaItem,
|
|
11
|
+
type ReviewArticle,
|
|
12
|
+
type ReviewRoundInfo,
|
|
13
|
+
type ReviewSession,
|
|
14
|
+
type ReviewState,
|
|
15
|
+
type ReviewNodeRef,
|
|
16
|
+
type ReviewComment,
|
|
17
|
+
type ReviewMediaPick,
|
|
18
|
+
type ReviewSubmissionV1,
|
|
19
|
+
type ReviewMediaSnapshot,
|
|
20
|
+
type StoredReviewRound,
|
|
21
|
+
} from './types'
|
|
22
|
+
export { formatReviewRound, formatReviewForAgent } from './format'
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Review links — wire types of the page API (`/api/review/v1`, docs: "Add review to
|
|
3
|
+
* your frontend"). Dependency-free: shared by the page (through `@blogmcp/review`)
|
|
4
|
+
* and by server code that formats a review for the agent.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** The route a site serves the review page on; `{token}` is the link's token. */
|
|
8
|
+
export const REVIEW_PAGE_PATH = '/preview/review/{token}'
|
|
9
|
+
/** Express-style pattern of the same route. */
|
|
10
|
+
export const REVIEW_ROUTE_PATTERN = '/preview/review/:token'
|
|
11
|
+
|
|
12
|
+
const TOKEN_RE = /^kbrv_[A-Za-z0-9_-]{43}$/
|
|
13
|
+
|
|
14
|
+
/** Shape check only — whether the token is valid is kb-api's call. */
|
|
15
|
+
export function isReviewTokenFormat(value: unknown): value is string {
|
|
16
|
+
return typeof value === 'string' && TOKEN_RE.test(value)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type ReviewMediaScope = 'none' | 'public' | 'all'
|
|
20
|
+
|
|
21
|
+
export interface ReviewMediaItem {
|
|
22
|
+
id: string
|
|
23
|
+
slug: string
|
|
24
|
+
mediaType: string
|
|
25
|
+
mimeType: string
|
|
26
|
+
url: string
|
|
27
|
+
thumbnailUrl: string
|
|
28
|
+
altText: string | null
|
|
29
|
+
title: string | null
|
|
30
|
+
description: string | null
|
|
31
|
+
width: number | null
|
|
32
|
+
height: number | null
|
|
33
|
+
durationSeconds: number | null
|
|
34
|
+
fileSizeBytes: number
|
|
35
|
+
accessLevel: string
|
|
36
|
+
tags: Array<{ id: string; slug: string; name: string; color: string | null }>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The article in the `ArticleWithTranslation` shape — its WORKING copy — plus review metadata. */
|
|
40
|
+
export interface ReviewArticle {
|
|
41
|
+
id: string
|
|
42
|
+
filename: string
|
|
43
|
+
contentType: string
|
|
44
|
+
status: string
|
|
45
|
+
description: string | null
|
|
46
|
+
sourceLanguageCode: string
|
|
47
|
+
createdAt: string
|
|
48
|
+
updatedAt: string
|
|
49
|
+
publishedAt: string | null
|
|
50
|
+
title: string
|
|
51
|
+
content: string
|
|
52
|
+
languageCode: string
|
|
53
|
+
isSource: boolean
|
|
54
|
+
isFallback: false
|
|
55
|
+
featuredImageUrl: string | null
|
|
56
|
+
featuredImageGeo: null
|
|
57
|
+
contentImagesGeo: []
|
|
58
|
+
accessRights: string[]
|
|
59
|
+
tags: string[]
|
|
60
|
+
versionId: string | null
|
|
61
|
+
versionNumber: number | null
|
|
62
|
+
/** sha256 hex of `content`. */
|
|
63
|
+
contentHash: string
|
|
64
|
+
/** Where the body starts after the frontmatter; `sourceRange` values are relative to it. */
|
|
65
|
+
bodyOffset: number
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface ReviewRoundInfo {
|
|
69
|
+
seq: number
|
|
70
|
+
submittedAt: string
|
|
71
|
+
consumedAt: string | null
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface ReviewSession {
|
|
75
|
+
session: {
|
|
76
|
+
id: string
|
|
77
|
+
status: 'open'
|
|
78
|
+
expiresAt: string
|
|
79
|
+
message: string | null
|
|
80
|
+
mediaScope: ReviewMediaScope
|
|
81
|
+
submissionCount: number
|
|
82
|
+
lastSubmission: ReviewRoundInfo | null
|
|
83
|
+
limits: { submissionsPerSession: number; comments: number; media: number }
|
|
84
|
+
}
|
|
85
|
+
article: ReviewArticle
|
|
86
|
+
/** Media the working copy references, keyed by slug (signed URLs for non-public ones). */
|
|
87
|
+
media: Record<string, ReviewMediaItem>
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface ReviewState {
|
|
91
|
+
status: 'open'
|
|
92
|
+
expiresAt: string
|
|
93
|
+
versionId: string | null
|
|
94
|
+
contentHash: string
|
|
95
|
+
submissionCount: number
|
|
96
|
+
lastSubmission: ReviewRoundInfo | null
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// ─────────── what a page sends ───────────
|
|
100
|
+
|
|
101
|
+
export interface ReviewNodeRef {
|
|
102
|
+
/** `data-mdx-node-id` of a rendered block, e.g. `mdx-3`. */
|
|
103
|
+
id: string
|
|
104
|
+
/** `data-mdx-component`, or the HTML tag for markdown blocks. */
|
|
105
|
+
component: string
|
|
106
|
+
/** Offsets in the working copy's body (after the frontmatter). */
|
|
107
|
+
sourceRange?: { start: number; end: number }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface ReviewComment {
|
|
111
|
+
body: string
|
|
112
|
+
/** Verbatim text the comment is anchored to ('' for a whole block or the page). */
|
|
113
|
+
anchorText?: string
|
|
114
|
+
nodes?: ReviewNodeRef[]
|
|
115
|
+
rect?: { x: number; y: number; width: number; height: number } | null
|
|
116
|
+
/** Anchoring help for any renderer (level 0). */
|
|
117
|
+
context?: {
|
|
118
|
+
prefix?: string
|
|
119
|
+
suffix?: string
|
|
120
|
+
heading?: string
|
|
121
|
+
mediaSlug?: string
|
|
122
|
+
field?: 'title' | 'description' | 'featuredImage'
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface ReviewMediaPick {
|
|
127
|
+
slug: string
|
|
128
|
+
comment?: string | null
|
|
129
|
+
/** Block the media belongs next to. */
|
|
130
|
+
anchorNodeId?: string | null
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface ReviewSubmissionV1 {
|
|
134
|
+
v: 1
|
|
135
|
+
baseVersionId?: string | null
|
|
136
|
+
baseContentHash?: string | null
|
|
137
|
+
comments?: ReviewComment[]
|
|
138
|
+
note?: string | null
|
|
139
|
+
media?: ReviewMediaPick[]
|
|
140
|
+
client?: { renderer?: string; sdkVersion?: string; uaFamily?: string; viewport?: { w: number; h: number } }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// ─────────── what the agent receives ───────────
|
|
144
|
+
|
|
145
|
+
/** A media pick as stored: the library's own data, never the page's. */
|
|
146
|
+
export interface ReviewMediaSnapshot {
|
|
147
|
+
id: string
|
|
148
|
+
slug: string
|
|
149
|
+
mediaType: string
|
|
150
|
+
url: string
|
|
151
|
+
altText: string | null
|
|
152
|
+
title: string | null
|
|
153
|
+
description: string | null
|
|
154
|
+
durationSeconds: number | null
|
|
155
|
+
accessLevel: string
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export interface StoredReviewRound {
|
|
159
|
+
seq: number
|
|
160
|
+
submittedAt: string
|
|
161
|
+
baseVersionNumber: number | null
|
|
162
|
+
payload: {
|
|
163
|
+
v: 1
|
|
164
|
+
comments: Array<Required<Pick<ReviewComment, 'body'>> & ReviewComment>
|
|
165
|
+
note: string | null
|
|
166
|
+
media: Array<{ slug: string; comment: string | null; anchorNodeId: string | null; item: ReviewMediaSnapshot }>
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guard for SDK entry points that must never run in page JavaScript: they
|
|
3
|
+
* carry a secret (an adapter key) or a reader's bearer capability (a
|
|
4
|
+
* consultation session or link token).
|
|
5
|
+
*
|
|
6
|
+
* Deliberately broad: any global `window` counts as a browser, including a DOM
|
|
7
|
+
* emulation under test. Server runtimes (Node, Bun, Deno 2, workers) define no
|
|
8
|
+
* `window`.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export function isBrowserRuntime(): boolean {
|
|
12
|
+
return typeof window !== 'undefined'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Throws when called in a browser. `what` names the entry point, `why` says what must not leak. */
|
|
16
|
+
export function assertServerOnly(what: string, why: string): void {
|
|
17
|
+
if (isBrowserRuntime()) {
|
|
18
|
+
throw new Error(`[blogmcp-sdk] ${what} is server-only — ${why}`)
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/core/types.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { KbErrorCode } from './errors'
|
|
2
|
+
|
|
1
3
|
// ==================== Article Types ====================
|
|
2
4
|
|
|
3
5
|
/**
|
|
@@ -258,3 +260,338 @@ export interface PaginatedResponse<T> {
|
|
|
258
260
|
items: T[]
|
|
259
261
|
totalCount: number
|
|
260
262
|
}
|
|
263
|
+
|
|
264
|
+
// ==================== Reader Consultation Types ====================
|
|
265
|
+
//
|
|
266
|
+
// Private reader ↔ team threads (docs/internal/reader-consultations.md §8.1).
|
|
267
|
+
// A reader sees public messages only; internal notes never reach these types.
|
|
268
|
+
|
|
269
|
+
/** Where a consultation stands, as its reader sees it. */
|
|
270
|
+
export type ReaderConsultationStatus = 'OPEN' | 'ANSWERED' | 'CLOSED' | 'ERASURE_REQUESTED'
|
|
271
|
+
|
|
272
|
+
/** Who wrote a message, as the reader sees it. */
|
|
273
|
+
export type ReaderConsultationAuthor = 'READER' | 'TEAM'
|
|
274
|
+
|
|
275
|
+
export interface ReaderConsultationMessage {
|
|
276
|
+
id: string
|
|
277
|
+
author: ReaderConsultationAuthor
|
|
278
|
+
/** The team's display name on TEAM messages (never a person's address); null on READER messages. */
|
|
279
|
+
authorName: string | null
|
|
280
|
+
/** Plain text as the author wrote it. Render it as text, never as HTML or markdown. */
|
|
281
|
+
body: string
|
|
282
|
+
createdAt: string
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export interface ReaderConsultation {
|
|
286
|
+
id: string
|
|
287
|
+
status: ReaderConsultationStatus
|
|
288
|
+
/** False once erasure was requested. */
|
|
289
|
+
canReply: boolean
|
|
290
|
+
/** True only through a session on a thread that was opened by e-mail. */
|
|
291
|
+
canAttachToAccount: boolean
|
|
292
|
+
createdAt: string
|
|
293
|
+
/** The last public message; internal notes never move it. */
|
|
294
|
+
lastActivityAt: string
|
|
295
|
+
messages: ReaderConsultationMessage[]
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export interface ReaderConsultationSummary {
|
|
299
|
+
id: string
|
|
300
|
+
status: ReaderConsultationStatus
|
|
301
|
+
createdAt: string
|
|
302
|
+
lastActivityAt: string
|
|
303
|
+
/** Public messages only. */
|
|
304
|
+
messageCount: number
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Result of a reader write. Domain failures do not throw: `success` is false,
|
|
309
|
+
* `code` is machine-readable and `error` is its constant English message.
|
|
310
|
+
*/
|
|
311
|
+
export interface ReaderConsultationResult {
|
|
312
|
+
success: boolean
|
|
313
|
+
code: KbErrorCode | null
|
|
314
|
+
error: string | null
|
|
315
|
+
/** True when a replay of the same clientRequestId returned the stored write. */
|
|
316
|
+
duplicate: boolean | null
|
|
317
|
+
consultation: ReaderConsultation | null
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** Result of exchanging a magic-link token. Keep `session` server-side (an HttpOnly cookie). */
|
|
321
|
+
export interface ConsultationSessionResult {
|
|
322
|
+
success: boolean
|
|
323
|
+
code: KbErrorCode | null
|
|
324
|
+
error: string | null
|
|
325
|
+
session: string | null
|
|
326
|
+
expiresAt: string | null
|
|
327
|
+
consultation: ReaderConsultation | null
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** A channel's legal regime: an information notice, or explicit consent. */
|
|
331
|
+
export type ConsultationLegalMode = 'notice' | 'consent'
|
|
332
|
+
|
|
333
|
+
export interface ConsultationLegalText {
|
|
334
|
+
purpose: ConsultationLegalMode
|
|
335
|
+
version: string
|
|
336
|
+
locale: string
|
|
337
|
+
body: string
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export interface ConsultationChannelConfig {
|
|
341
|
+
/** Channel slug, e.g. `web`, `contact_form`, `email`. */
|
|
342
|
+
channel: string
|
|
343
|
+
mode: ConsultationLegalMode
|
|
344
|
+
/** The current text to show, or null when the channel shows none (`email`). */
|
|
345
|
+
text: ConsultationLegalText | null
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export interface ConsultationPublicConfig {
|
|
349
|
+
enabled: boolean
|
|
350
|
+
channels: ConsultationChannelConfig[]
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/** The legal text version the reader was shown (from `ConsultationPublicConfig`). */
|
|
354
|
+
export interface ConsultationLegalInput {
|
|
355
|
+
version: string
|
|
356
|
+
locale: string
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* The reader's own consent (`consultations.consent(locale)`). Consent belongs
|
|
361
|
+
* to the person, not to a question: given once, with the first question, it
|
|
362
|
+
* covers every later one until the reader withdraws it
|
|
363
|
+
* (`consultations.withdrawConsent()`) — or until the tenant publishes a
|
|
364
|
+
* consent text that requires everyone to consent again.
|
|
365
|
+
*/
|
|
366
|
+
export interface ReaderConsultationConsent {
|
|
367
|
+
/**
|
|
368
|
+
* The web channel's legal mode for this reader: `consent`, `notice`, or
|
|
369
|
+
* `off` when they cannot open a question there (the module is off, the web
|
|
370
|
+
* channel is not enabled, or their kind of account is not accepted).
|
|
371
|
+
*/
|
|
372
|
+
mode: ConsultationLegalMode | 'off'
|
|
373
|
+
/** They have a consent that has not been withdrawn (reported in every mode: they may still withdraw it). */
|
|
374
|
+
active: boolean
|
|
375
|
+
/** When the active consent was given (ISO), or null. */
|
|
376
|
+
givenAt: string | null
|
|
377
|
+
/** The consent text version the active consent points at, or null. */
|
|
378
|
+
version: string | null
|
|
379
|
+
/** The next question must carry a consent (`CreateMyConsultationInput.consent`). Only ever true in mode `consent`. */
|
|
380
|
+
needsConsent: boolean
|
|
381
|
+
/** The current consent text to show (in the asked locale, falling back to `en`), only when `needsConsent`. */
|
|
382
|
+
text: ConsultationLegalText | null
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/** Result of `consultations.withdrawConsent()`. `code` `NOTHING_TO_DO`: there was no active consent. */
|
|
386
|
+
export interface ConsultationConsentWithdrawalResult {
|
|
387
|
+
success: boolean
|
|
388
|
+
code: KbErrorCode | null
|
|
389
|
+
error: string | null
|
|
390
|
+
/** How many questions closed (they are deleted after the tenant's grace period); null on failure. */
|
|
391
|
+
threadsClosed: number | null
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
export interface CreateMyConsultationInput {
|
|
395
|
+
/** The question, 1..5000 characters. */
|
|
396
|
+
body: string
|
|
397
|
+
/** The reader's language (e.g. `cs`); the tenant's default when omitted. */
|
|
398
|
+
languageCode?: string
|
|
399
|
+
/**
|
|
400
|
+
* The consent the reader gave with this question (the text version they were
|
|
401
|
+
* shown). Needed only in consent mode when the reader has no consent that
|
|
402
|
+
* covers a new question — `consultations.consent(locale).needsConsent`;
|
|
403
|
+
* ignored otherwise (no new record, no error). Missing when needed:
|
|
404
|
+
* CONSENT_REQUIRED; an unknown version: CONSENT_VERSION_UNKNOWN.
|
|
405
|
+
*/
|
|
406
|
+
consent?: ConsultationLegalInput
|
|
407
|
+
/** Required when the web channel is in notice mode. */
|
|
408
|
+
notice?: ConsultationLegalInput
|
|
409
|
+
/**
|
|
410
|
+
* Idempotency key, `[A-Za-z0-9._:-]{1,64}` (a UUID works). Generate it once
|
|
411
|
+
* per user action and reuse it on retries: a replay with the same payload
|
|
412
|
+
* returns the stored thread with `duplicate: true`, a different payload is
|
|
413
|
+
* IDEMPOTENCY_CONFLICT.
|
|
414
|
+
*/
|
|
415
|
+
clientRequestId: string
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** A reader message: its text and its idempotency key (see `CreateMyConsultationInput.clientRequestId`). */
|
|
419
|
+
export interface ConsultationMessageInput {
|
|
420
|
+
body: string
|
|
421
|
+
clientRequestId: string
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// ==================== Consultation Adapter Types ====================
|
|
425
|
+
//
|
|
426
|
+
// The REST contract a tenant adapter (e.g. a shop backend) speaks with a
|
|
427
|
+
// scoped adapter key (docs/internal/reader-consultations.md §8.3).
|
|
428
|
+
|
|
429
|
+
/** Who owns a new thread: a customer known by the tenant's own ref, or an anonymous address. */
|
|
430
|
+
export type ConsultationOwnerRef = { externalRef: string } | { email: string }
|
|
431
|
+
|
|
432
|
+
export interface ConsultationConsentInput extends ConsultationLegalInput {
|
|
433
|
+
/** When the reader gave consent (ISO 8601, not in the future). */
|
|
434
|
+
givenAt: string | Date
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
export interface ConsultationNewThreadInput {
|
|
438
|
+
/** `externalRef` must lie under the adapter key's prefix. */
|
|
439
|
+
owner: ConsultationOwnerRef
|
|
440
|
+
/** As typed in the form; the team sees it, the reader surfaces never echo it. */
|
|
441
|
+
displayName?: string
|
|
442
|
+
/** The adapter's own reference (e.g. a ticket number); unique per channel. */
|
|
443
|
+
externalThreadRef?: string
|
|
444
|
+
legalBasis?: 'contract' | 'legitimate_interest'
|
|
445
|
+
/** Required on a `notice`-mode channel: the notice version the reader was shown. */
|
|
446
|
+
notice?: ConsultationLegalInput
|
|
447
|
+
/** Required on a `consent`-mode channel. */
|
|
448
|
+
consent?: ConsultationConsentInput
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export interface ConsultationIngestInput {
|
|
452
|
+
/** The channel slug; the adapter key needs `consultations:ingest:<channel>`. `web` is always refused. */
|
|
453
|
+
channel: string
|
|
454
|
+
/** Idempotency key of the message within its channel (e.g. the form submission id or a Message-ID). */
|
|
455
|
+
externalMessageId: string
|
|
456
|
+
/** The reader's text, 1..5000 characters. */
|
|
457
|
+
body: string
|
|
458
|
+
languageCode: string
|
|
459
|
+
/** Original time of an imported e-mail (ISO 8601). */
|
|
460
|
+
sentAt?: string | Date
|
|
461
|
+
/** Append to this thread (the `email` channel only). */
|
|
462
|
+
threadId?: string
|
|
463
|
+
/** Required when appending: must match the thread's owner. */
|
|
464
|
+
sender?: { email?: string; externalRef?: string }
|
|
465
|
+
/** Open a new thread (every channel except `email`). */
|
|
466
|
+
newThread?: ConsultationNewThreadInput
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
export interface ConsultationIngestResult {
|
|
470
|
+
/** `created` on the first delivery of a message, `duplicate` on an identical replay. */
|
|
471
|
+
status: 'created' | 'duplicate'
|
|
472
|
+
threadId: string
|
|
473
|
+
messageId: string
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
export type ConsultationDeliveryKind =
|
|
477
|
+
| 'reply_notice'
|
|
478
|
+
| 'access_link'
|
|
479
|
+
| 'operator_new_message'
|
|
480
|
+
| 'operator_flag_due'
|
|
481
|
+
| 'operator_erasure_requested'
|
|
482
|
+
| 'operator_hold_review'
|
|
483
|
+
|
|
484
|
+
export interface ConsultationLeaseInput {
|
|
485
|
+
channel: string
|
|
486
|
+
/** 1..20, default 10. */
|
|
487
|
+
max?: number
|
|
488
|
+
/** 30..900, default 300. */
|
|
489
|
+
leaseSeconds?: number
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* A notice to send. It carries no content: the adapter composes a content-free
|
|
494
|
+
* mail that links to the reader page (or to the admin for operator notices).
|
|
495
|
+
*/
|
|
496
|
+
export interface ConsultationLeasedDelivery {
|
|
497
|
+
deliveryId: string
|
|
498
|
+
leaseId: string
|
|
499
|
+
kind: ConsultationDeliveryKind
|
|
500
|
+
recipient: 'reader' | 'operator'
|
|
501
|
+
/** 1-based attempt number of this lease. */
|
|
502
|
+
attempt: number
|
|
503
|
+
threadId: string
|
|
504
|
+
languageCode: string
|
|
505
|
+
/**
|
|
506
|
+
* Reader notices only: whom to send to. An `externalRef` is looked up in the
|
|
507
|
+
* adapter's own system; an `email` is the address to use. Absent for
|
|
508
|
+
* operator notices (the adapter sends to its own team address).
|
|
509
|
+
*/
|
|
510
|
+
owner?: ConsultationOwnerRef
|
|
511
|
+
/**
|
|
512
|
+
* `email`-owned threads only: a fresh magic-link token. The plaintext exists
|
|
513
|
+
* only in this response — put it in the URL fragment of the link and never
|
|
514
|
+
* store or log it.
|
|
515
|
+
*/
|
|
516
|
+
token?: { value: string; expiresAt: string }
|
|
517
|
+
createdAt: string
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
export interface ConsultationLeaseResult {
|
|
521
|
+
items: ConsultationLeasedDelivery[]
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
export interface ConsultationAckInput {
|
|
525
|
+
leaseId: string
|
|
526
|
+
/** The Message-ID the notice went out with (≤ 255 characters); `threadByNotice` finds it later. */
|
|
527
|
+
providerMessageId: string
|
|
528
|
+
/** Default `email`. */
|
|
529
|
+
channel?: string
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
export interface ConsultationFailInput {
|
|
533
|
+
leaseId: string
|
|
534
|
+
/** A code, `[a-z0-9_]{1,64}`; anything else is stored as `adapter_error`. Never a transport's own error text. */
|
|
535
|
+
errorCode: string
|
|
536
|
+
/** False (or attempts exhausted) marks the notice failed for good. */
|
|
537
|
+
retryable: boolean
|
|
538
|
+
/** Default `email`. */
|
|
539
|
+
channel?: string
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
export interface ConsultationOkResult {
|
|
543
|
+
ok: true
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
export interface ConsultationOutboxStats {
|
|
547
|
+
pending: number
|
|
548
|
+
leased: number
|
|
549
|
+
failed: number
|
|
550
|
+
oldestPendingAt: string | null
|
|
551
|
+
lastErrorCode: string | null
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
export interface ConsultationEraseInput {
|
|
555
|
+
/** A ref under the adapter key's prefix. */
|
|
556
|
+
externalRef: string
|
|
557
|
+
/** Count only, change nothing. */
|
|
558
|
+
dryRun?: boolean
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
export interface ConsultationEraseResult {
|
|
562
|
+
requestId: string
|
|
563
|
+
dryRun: boolean
|
|
564
|
+
/** `partial` when a thread under legal hold was kept (and marked for deletion once released). */
|
|
565
|
+
status: 'done' | 'partial'
|
|
566
|
+
threadsErased: number
|
|
567
|
+
threadsHeld: number
|
|
568
|
+
accountsAnonymised: number
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
export interface ConsultationOwnerRefsInput {
|
|
572
|
+
/** Narrow the scan; must lie under the key's prefix. */
|
|
573
|
+
prefix?: string
|
|
574
|
+
/** Continue after this ref (the previous page's `next`). */
|
|
575
|
+
after?: string
|
|
576
|
+
/** 1..1000, default 500. */
|
|
577
|
+
limit?: number
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
export interface ConsultationOwnerRefsResult {
|
|
581
|
+
refs: string[]
|
|
582
|
+
/** Pass as `after` for the next page; null on the last page. */
|
|
583
|
+
next: string | null
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
export interface ConsultationThreadOwner {
|
|
587
|
+
ownerKind: 'external' | 'kb_user' | 'email'
|
|
588
|
+
externalRef?: string
|
|
589
|
+
email?: string
|
|
590
|
+
emailVerified: boolean
|
|
591
|
+
status: 'open' | 'answered' | 'closed' | 'erasure_requested'
|
|
592
|
+
acceptsMessages: boolean
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
export interface ConsultationThreadByNotice {
|
|
596
|
+
threadId: string
|
|
597
|
+
}
|