@mikedown/core 0.3.0 → 0.4.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/CHANGELOG.md +12 -1
- package/README.md +1 -1
- package/dist/ai/engines-page.d.ts +11 -4
- package/dist/ai/engines-page.js +5 -4
- package/dist/ai/index.d.ts +1201 -10
- package/dist/ai/index.js +297 -8
- package/dist/{ai-ui-C7ENTWWU.js → ai-ui-QFYFN73D.js} +3165 -138
- package/dist/ai-ui-QFYFN73D.js.map +1 -0
- package/dist/{chunk-QDVY7WW6.js → chunk-APPBNQEY.js} +53 -2
- package/dist/chunk-APPBNQEY.js.map +1 -0
- package/dist/{chunk-7A5HEPLK.js → chunk-DWXGWVA3.js} +850 -12
- package/dist/chunk-DWXGWVA3.js.map +1 -0
- package/dist/{chunk-JZWKEBCI.js → chunk-IWCXWUWW.js} +3260 -201
- package/dist/chunk-IWCXWUWW.js.map +1 -0
- package/dist/{chunk-LXZG7IKN.js → chunk-N4N54LK2.js} +2 -2
- package/dist/chunk-N4N54LK2.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +399 -38
- package/dist/index.js.map +1 -1
- package/dist/schema-DVfssxQX.d.ts +100 -0
- package/dist/styles.css +943 -4
- package/dist/{types-CsVNVSNY.d.ts → types-2TZErbJr.d.ts} +25 -3
- package/dist/{types-CgEeIUhi.d.ts → types-DO8UBybZ.d.ts} +316 -7
- package/package.json +1 -1
- package/dist/ai-ui-C7ENTWWU.js.map +0 -1
- package/dist/chunk-7A5HEPLK.js.map +0 -1
- package/dist/chunk-JZWKEBCI.js.map +0 -1
- package/dist/chunk-LXZG7IKN.js.map +0 -1
- package/dist/chunk-QDVY7WW6.js.map +0 -1
- package/dist/schema-DYzxkuSb.d.ts +0 -46
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Editor } from '@tiptap/core';
|
|
2
|
-
import { M as MikeDownAiHost, A as AiSettings,
|
|
2
|
+
import { M as MikeDownAiHost, b as MikeDownDocsHost, A as AiSettings, ad as AiServedBy, a as AiEngineStatus } from './types-DO8UBybZ.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Toolbar layout model: schema, parse, normalize, migrate and edit helpers.
|
|
@@ -187,12 +187,21 @@ interface MikeDownHost {
|
|
|
187
187
|
/**
|
|
188
188
|
* Open a link. Absent means external links open in a new browser tab and
|
|
189
189
|
* relative links are ignored. `reveal` asks the target document to scroll
|
|
190
|
-
* to a link back to this one (sidebar backlinks)
|
|
190
|
+
* to a link back to this one (sidebar backlinks), or, with `section`, to the
|
|
191
|
+
* heading with that documentation-base slug (chat citations). A chat citation's
|
|
192
|
+
* href is a `file:` URL under a documentation base root.
|
|
191
193
|
*/
|
|
192
194
|
openLink?(href: string, behavior?: LinkOpenBehavior, reveal?: {
|
|
193
195
|
href?: string;
|
|
194
196
|
occurrence?: number;
|
|
197
|
+
section?: string;
|
|
195
198
|
}): void;
|
|
199
|
+
/**
|
|
200
|
+
* The absolute folder of the current document, null while it has none
|
|
201
|
+
* (untitled). Insert from the chat uses it for relative links; absent, it
|
|
202
|
+
* writes plain `file › heading` text.
|
|
203
|
+
*/
|
|
204
|
+
documentFolder?(): string | null;
|
|
196
205
|
/**
|
|
197
206
|
* Persist settings. Absent means changes made in the Settings modal last
|
|
198
207
|
* for the session only. `source: 'slashMenu'` marks the slash menu's
|
|
@@ -249,6 +258,8 @@ interface MikeDownHost {
|
|
|
249
258
|
exportHtml?(html: string): void;
|
|
250
259
|
printDocument?(html: string): void;
|
|
251
260
|
viewInBrowser?(html: string): void;
|
|
261
|
+
/** Offer a save dialog with this suggested name and write the text there (the AI Activity panel). Without it, the panel's Save buttons are hidden. */
|
|
262
|
+
saveTextFile?(name: string, text: string): Promise<void>;
|
|
252
263
|
sidebarPrefs?: MikeDownSidebarPrefs;
|
|
253
264
|
/**
|
|
254
265
|
* Inference through the host. `complete` alone (tier 1) turns the features
|
|
@@ -256,6 +267,11 @@ interface MikeDownHost {
|
|
|
256
267
|
* Types and helpers live in `@mikedown/core/ai`.
|
|
257
268
|
*/
|
|
258
269
|
ai?: MikeDownAiHost;
|
|
270
|
+
/**
|
|
271
|
+
* User-level folders of markdown the AI chat can navigate and answer from.
|
|
272
|
+
* Needs `ai` as well. Types live in `@mikedown/core/ai`.
|
|
273
|
+
*/
|
|
274
|
+
docs?: MikeDownDocsHost;
|
|
259
275
|
}
|
|
260
276
|
/** A host with every optional method absent. `onChange` does nothing. */
|
|
261
277
|
declare class NoopHost implements MikeDownHost {
|
|
@@ -483,7 +499,11 @@ type MikeDownCommand = 'toggleBold' | 'toggleItalic' | 'toggleStrike' | 'toggleH
|
|
|
483
499
|
/** Suggest titles with AI: three candidates; a pick sets `title:`, the H1, or a new H1 (no-op without `host.ai`). */
|
|
484
500
|
| 'aiSuggestTitle'
|
|
485
501
|
/** Suggest properties with AI: the sidebar's Suggest (Properties shown and expanded); chips apply a title, description or tag (no-op without `host.ai`). */
|
|
486
|
-
| 'aiSuggestProperties'
|
|
502
|
+
| 'aiSuggestProperties'
|
|
503
|
+
/** Open the AI chat panel: questions about this document or the documentation bases (no-op without `host.ai`). */
|
|
504
|
+
| 'aiChat'
|
|
505
|
+
/** Ask for an inline suggestion at the caret now, whatever the trigger setting (no-op without `host.ai`). */
|
|
506
|
+
| 'aiSuggestContinuation' | 'copyAsRichText' | 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6' | 'paragraph' | 'openFind' | 'openFindReplace' | 'insertTable' | 'insertLink' | 'insertImage' | 'zoomIn' | 'zoomOut' | 'zoomReset';
|
|
487
507
|
type MikeDownEvent = 'change' | 'focus' | 'blur' | 'ready';
|
|
488
508
|
/**
|
|
489
509
|
* Where the user is in the document: which view is showing, the caret and
|
|
@@ -536,6 +556,8 @@ interface MikeDownEditorHandle {
|
|
|
536
556
|
scrollToAnchor(slug: string): void;
|
|
537
557
|
/** Scroll to and flash the Nth link with this href. */
|
|
538
558
|
revealLink(href: string, occurrence?: number): void;
|
|
559
|
+
/** Scroll to the heading with this documentation-base section slug (`docsSlug`'s rule, not GitHub's). Waits briefly for the document to load. */
|
|
560
|
+
revealSection(slug: string): void;
|
|
539
561
|
/**
|
|
540
562
|
* Select and scroll to a match in the markdown source: 1-based `line`,
|
|
541
563
|
* 1-based `column` in UTF-16 units, `length` of the match. Exact in source
|
|
@@ -126,6 +126,24 @@ interface AiFeatureSetting {
|
|
|
126
126
|
enabled?: boolean;
|
|
127
127
|
/** Task override, e.g. `{ task: 'vision' }`. */
|
|
128
128
|
task?: string;
|
|
129
|
+
/** `ghostText` only (see `AiGhostTextOptions`; read through `ghostTextOptions`). */
|
|
130
|
+
delayMs?: number;
|
|
131
|
+
maxTokens?: number;
|
|
132
|
+
trigger?: AiGhostTrigger;
|
|
133
|
+
localOnly?: boolean;
|
|
134
|
+
}
|
|
135
|
+
/** When Inline suggestions fire: after an idle pause, or only from the shortcut / menu. */
|
|
136
|
+
type AiGhostTrigger = 'auto' | 'manual';
|
|
137
|
+
/** The `features.ghostText` knobs with defaults applied and ranges clamped (`ghostTextOptions`). */
|
|
138
|
+
interface AiGhostTextOptions {
|
|
139
|
+
/** Idle time after a keystroke before a request fires, in ms. Default 400. */
|
|
140
|
+
delayMs: number;
|
|
141
|
+
/** Output budget in tokens. Default 48. */
|
|
142
|
+
maxTokens: number;
|
|
143
|
+
/** Default `auto`. */
|
|
144
|
+
trigger: AiGhostTrigger;
|
|
145
|
+
/** Reject cloud engines for this feature. Default true. */
|
|
146
|
+
localOnly: boolean;
|
|
129
147
|
}
|
|
130
148
|
/** Open map keyed by feature id (see `AI_FEATURES`). */
|
|
131
149
|
type AiFeatureSettings = Record<string, AiFeatureSetting>;
|
|
@@ -142,6 +160,198 @@ interface AiSettings {
|
|
|
142
160
|
localNetworks: string[];
|
|
143
161
|
/** The AI button on the toolbar (hosts with AI support only). Default true. */
|
|
144
162
|
showToolbarButton: boolean;
|
|
163
|
+
/** Record what each AI request sent and received, in memory, and show it in the Activity panel. Default false. */
|
|
164
|
+
activityPanel: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Documentation bases (`mikedown.ai.docBases`). User-level only: a host
|
|
167
|
+
* reads this key from its user settings and never from a workspace, so a
|
|
168
|
+
* repository cannot add or redirect a base. `parseAiSettings` drops invalid
|
|
169
|
+
* entries with a reason (see `parseDocBases`).
|
|
170
|
+
*/
|
|
171
|
+
docBases: AiDocBase[];
|
|
172
|
+
/** Advanced options for chatting with the bases (`mikedown.ai.docs`), user-level only like `docBases`. */
|
|
173
|
+
docs: AiDocsOptions;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* One documentation base: user-level folders of markdown the chat can
|
|
177
|
+
* navigate and answer from. Roots are absolute, normalized folder paths.
|
|
178
|
+
*/
|
|
179
|
+
interface AiDocBase {
|
|
180
|
+
/** Stable, generated once, never shown. The wire and the consent dialog name a base by id; the host maps it to a name from its own settings. */
|
|
181
|
+
id: string;
|
|
182
|
+
name: string;
|
|
183
|
+
/** Absolute normalized folders (`validateDocRoot`). At least one. */
|
|
184
|
+
roots: string[];
|
|
185
|
+
/** Per-base override for the home document's file name, relative to each root (`HOME.md`). Absent: `INDEX.md`, `README.md`, then a map. */
|
|
186
|
+
homeFile?: string;
|
|
187
|
+
/** May pages from this base be sent to a cloud engine. Default false. */
|
|
188
|
+
allowCloud: boolean;
|
|
189
|
+
/** A disabled base is never indexed for or sent with a request. Default true. */
|
|
190
|
+
enabled: boolean;
|
|
191
|
+
}
|
|
192
|
+
type AiDocsNavigateBy = 'section' | 'page';
|
|
193
|
+
declare const AI_DOCS_NAVIGATE_BY: readonly AiDocsNavigateBy[];
|
|
194
|
+
/** The advanced options (`ai.docs`), without the bases. */
|
|
195
|
+
interface AiDocsOptions {
|
|
196
|
+
/** Navigation calls before the answer. Clamped to `AI_DOCS_MAX_HOPS_MIN`..`AI_DOCS_MAX_HOPS_MAX`. Default 3. */
|
|
197
|
+
maxHops: number;
|
|
198
|
+
/** Percent of the route's context the answer's sections may take. Clamped to `AI_DOCS_SOURCE_SHARE_MIN`..`AI_DOCS_SOURCE_SHARE_MAX`. Default 60. */
|
|
199
|
+
sourceShare: number;
|
|
200
|
+
/** Whether the model asks for `page#heading` sections or whole pages. Default `section`. */
|
|
201
|
+
navigateBy: AiDocsNavigateBy;
|
|
202
|
+
}
|
|
203
|
+
/** The options the loop runs with: `ai.docs` plus the bases (`resolveDocsSettings`). */
|
|
204
|
+
interface AiDocsSettings extends AiDocsOptions {
|
|
205
|
+
bases: AiDocBase[];
|
|
206
|
+
}
|
|
207
|
+
declare const AI_DOCS_MAX_HOPS_MIN = 1;
|
|
208
|
+
declare const AI_DOCS_MAX_HOPS_MAX = 5;
|
|
209
|
+
/**
|
|
210
|
+
* The most requests one "Allow once" can admit in a chat turn: a navigation
|
|
211
|
+
* call and its one repair per hop, then the answer. Hosts stop honouring a grant
|
|
212
|
+
* past this, so a webview that never ends its turn cannot keep sending on it.
|
|
213
|
+
* `TURN_GRANT_MAX_USES` in Desktop's `commands/ai.rs` is the same number.
|
|
214
|
+
*/
|
|
215
|
+
declare const AI_TURN_GRANT_MAX_USES: number;
|
|
216
|
+
declare const AI_DOCS_MAX_HOPS_DEFAULT = 3;
|
|
217
|
+
declare const AI_DOCS_SOURCE_SHARE_MIN = 30;
|
|
218
|
+
declare const AI_DOCS_SOURCE_SHARE_MAX = 80;
|
|
219
|
+
declare const AI_DOCS_SOURCE_SHARE_DEFAULT = 60;
|
|
220
|
+
declare const AI_DOCS_NAVIGATE_BY_DEFAULT: AiDocsNavigateBy;
|
|
221
|
+
/** Where a root's home document came from (decision 3). `map` means none was found and core builds an in-memory map. */
|
|
222
|
+
type AiDocHomeKind = 'override' | 'index' | 'readme' | 'map';
|
|
223
|
+
/** One root of a base, as the host last saw it. */
|
|
224
|
+
interface AiDocRootStatus {
|
|
225
|
+
/** The root as configured (absolute). */
|
|
226
|
+
root: string;
|
|
227
|
+
/** The label ids use for this root (the same rule on both hosts; `docs/index.ts`). */
|
|
228
|
+
label: string;
|
|
229
|
+
/** The folder exists and is readable. False: "Root not found"; the root is skipped for requests, never deleted. */
|
|
230
|
+
found: boolean;
|
|
231
|
+
/** Which home precedence step won; `map` is the "No home document" state. Absent when the root is not found. */
|
|
232
|
+
home?: AiDocHomeKind;
|
|
233
|
+
/** The home document's path relative to the root, when `home` is not `map`. */
|
|
234
|
+
homePath?: string;
|
|
235
|
+
/** Markdown files indexed under this root. */
|
|
236
|
+
fileCount: number;
|
|
237
|
+
/** Files over the byte cap, skipped. */
|
|
238
|
+
oversizeSkipped: number;
|
|
239
|
+
/** The file cap was reached; later files were not indexed. */
|
|
240
|
+
capReached: boolean;
|
|
241
|
+
/** Files that are not UTF-8 text (a UTF-16 or UTF-32 byte order mark, or NUL bytes), skipped. */
|
|
242
|
+
notTextSkipped?: number;
|
|
243
|
+
/** The folder cap was reached; later folders were not read. */
|
|
244
|
+
dirCapReached?: boolean;
|
|
245
|
+
/** The build's time budget ran out; the index covers what was read before that. */
|
|
246
|
+
timedOut?: boolean;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* A base plus its health, as `listBases` reports it. Computed when the
|
|
250
|
+
* manager page opens and on Refresh. "Active" means enabled with at least one
|
|
251
|
+
* root found; only active bases are indexed for or sent to a request.
|
|
252
|
+
*/
|
|
253
|
+
interface AiDocBaseStatus {
|
|
254
|
+
base: AiDocBase;
|
|
255
|
+
/** Enabled and at least one root found. */
|
|
256
|
+
active: boolean;
|
|
257
|
+
roots: AiDocRootStatus[];
|
|
258
|
+
/** Sum over roots. */
|
|
259
|
+
fileCount: number;
|
|
260
|
+
oversizeSkipped: number;
|
|
261
|
+
/** Roots not found on disk. */
|
|
262
|
+
rootsMissing: number;
|
|
263
|
+
/** Any root hit the file cap. */
|
|
264
|
+
capReached: boolean;
|
|
265
|
+
/** Files skipped because they are not UTF-8 text, over every root. */
|
|
266
|
+
notTextSkipped?: number;
|
|
267
|
+
/** Any root hit the folder cap. */
|
|
268
|
+
dirCapReached?: boolean;
|
|
269
|
+
/** The build's time budget ran out; the index and the counts cover what was read before that. */
|
|
270
|
+
timedOut?: boolean;
|
|
271
|
+
/** Relative links that leave every root or point at no page. Absent when the host did not compute it. */
|
|
272
|
+
brokenLinks?: number;
|
|
273
|
+
}
|
|
274
|
+
/** A heading in the index (a section starts at each). Bodies are never in the index. */
|
|
275
|
+
interface AiDocsHeading {
|
|
276
|
+
/** The section id: `<page id>#<slug>`. */
|
|
277
|
+
id: string;
|
|
278
|
+
/** 1 to 6. */
|
|
279
|
+
level: number;
|
|
280
|
+
text: string;
|
|
281
|
+
slug: string;
|
|
282
|
+
}
|
|
283
|
+
/** A link as written in a page. Core resolves it (`docs/links.ts`); the host only extracts. */
|
|
284
|
+
interface AiDocsLink {
|
|
285
|
+
/** The target as written: a relative path with an optional `#fragment`, or a wikilink name. */
|
|
286
|
+
target: string;
|
|
287
|
+
/** The link text. */
|
|
288
|
+
text: string;
|
|
289
|
+
kind: 'markdown' | 'wikilink';
|
|
290
|
+
}
|
|
291
|
+
/** One markdown page of a base, without its body. */
|
|
292
|
+
interface AiDocsPage {
|
|
293
|
+
/** `<root label>/<rel path>`, with `/` separators (`docs/index.ts`). The only thing the model names. */
|
|
294
|
+
id: string;
|
|
295
|
+
/** The root's label (the first segment of `id`). */
|
|
296
|
+
root: string;
|
|
297
|
+
/** Path relative to the root, with `/` separators. */
|
|
298
|
+
relPath: string;
|
|
299
|
+
/** Frontmatter title, else the first heading, else the file name. */
|
|
300
|
+
title: string;
|
|
301
|
+
headings: AiDocsHeading[];
|
|
302
|
+
links: AiDocsLink[];
|
|
303
|
+
/** Size of the file in characters (not bytes), for the budget. */
|
|
304
|
+
chars: number;
|
|
305
|
+
}
|
|
306
|
+
/** The home document chosen for a root. */
|
|
307
|
+
interface AiDocsHome {
|
|
308
|
+
/** The root's label. */
|
|
309
|
+
root: string;
|
|
310
|
+
kind: AiDocHomeKind;
|
|
311
|
+
/** The home page's id; null for `map`. */
|
|
312
|
+
pageId: string | null;
|
|
313
|
+
}
|
|
314
|
+
/** A base's index: pages with headings and links, no bodies. Built lazily on the host, in memory. */
|
|
315
|
+
interface AiDocsIndex {
|
|
316
|
+
baseId: string;
|
|
317
|
+
/** Roots that were found, in configured order. */
|
|
318
|
+
roots: Array<{
|
|
319
|
+
label: string;
|
|
320
|
+
}>;
|
|
321
|
+
pages: AiDocsPage[];
|
|
322
|
+
homes: AiDocsHome[];
|
|
323
|
+
/** The file cap cut the walk short. */
|
|
324
|
+
truncated: boolean;
|
|
325
|
+
oversizeSkipped: number;
|
|
326
|
+
/** Unix milliseconds the index was built. */
|
|
327
|
+
builtAt: number;
|
|
328
|
+
}
|
|
329
|
+
/** A section (or whole page) as `readSections` returns it: the only call that carries a body. */
|
|
330
|
+
interface AiDocsSection {
|
|
331
|
+
/** The id that was asked for: `<page id>#<slug>` or a page id. */
|
|
332
|
+
id: string;
|
|
333
|
+
pageId: string;
|
|
334
|
+
/** The page's title. */
|
|
335
|
+
title: string;
|
|
336
|
+
/** Path relative to the root, for the chip and the relative link. */
|
|
337
|
+
relPath: string;
|
|
338
|
+
/** The section's heading text; absent for a whole page. */
|
|
339
|
+
heading?: string;
|
|
340
|
+
/** The markdown, capped at the section byte cap by the host. */
|
|
341
|
+
text: string;
|
|
342
|
+
/** The host cut `text` at the cap. */
|
|
343
|
+
truncated: boolean;
|
|
344
|
+
}
|
|
345
|
+
/** A keyword match: ids and labels only, no text. The loop reads the bodies through `readSections`. */
|
|
346
|
+
interface AiDocsSectionRef {
|
|
347
|
+
/** `<page id>#<slug>`, or a page id for text before the first heading. */
|
|
348
|
+
id: string;
|
|
349
|
+
pageId: string;
|
|
350
|
+
title: string;
|
|
351
|
+
relPath: string;
|
|
352
|
+
heading?: string;
|
|
353
|
+
/** Higher is a better match; the order is `docs/keyword.ts`'s. */
|
|
354
|
+
score: number;
|
|
145
355
|
}
|
|
146
356
|
type AiMessagePart = {
|
|
147
357
|
type: 'text';
|
|
@@ -173,6 +383,23 @@ interface AiCompletionRequest {
|
|
|
173
383
|
* request wins. Tier-1 hosts may ignore them.
|
|
174
384
|
*/
|
|
175
385
|
requestOverrides?: Record<string, unknown>;
|
|
386
|
+
/** Set on every request of a chat turn (`AiRoutePin`); absent on every other request. */
|
|
387
|
+
turn?: AiCompletionTurn;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* What a request of a chat turn says about that turn. A host uses it to find
|
|
391
|
+
* the "Allow once" it holds for the turn, and to word a dialog it has to raise
|
|
392
|
+
* in the middle of one (`sends`, and `baseIds`, which it maps to names from its
|
|
393
|
+
* own settings). It is a claim, not consent: a host admits the request only
|
|
394
|
+
* against a grant it made itself when the user answered, for this panel or
|
|
395
|
+
* window, this turn, this engine and this set of bases.
|
|
396
|
+
*/
|
|
397
|
+
interface AiCompletionTurn {
|
|
398
|
+
id: string;
|
|
399
|
+
sends?: AiSendsScope;
|
|
400
|
+
baseIds?: string[];
|
|
401
|
+
/** The engine's locality when the turn was routed. A host fails the request if it no longer holds. */
|
|
402
|
+
isLocal?: boolean;
|
|
176
403
|
}
|
|
177
404
|
interface AiServedBy {
|
|
178
405
|
engineId?: string;
|
|
@@ -354,6 +581,18 @@ interface MikeDownAiHost {
|
|
|
354
581
|
* dialog can say what is sent (`aiConsentText`).
|
|
355
582
|
*/
|
|
356
583
|
requestCloudConsent?(engineId: string, about?: AiConsentAbout): Promise<AiConsentReply>;
|
|
584
|
+
/**
|
|
585
|
+
* `requestCloudConsent` for a chat turn, where `'once'` means the whole turn:
|
|
586
|
+
* the host holds the grant and admits the turn's requests (`req.turn`) on it.
|
|
587
|
+
* Absent: core asks `requestCloudConsent`.
|
|
588
|
+
*/
|
|
589
|
+
requestTurnConsent?(engineId: string, about: AiTurnConsentAbout): Promise<AiConsentReply>;
|
|
590
|
+
/**
|
|
591
|
+
* The chat turn `turnId` is over (answered, refused, failed or cancelled):
|
|
592
|
+
* forget any "Allow once" held for it. Fire and forget. A host that holds no
|
|
593
|
+
* grant per turn can leave it out.
|
|
594
|
+
*/
|
|
595
|
+
endTurn?(turnId: string): void;
|
|
357
596
|
/**
|
|
358
597
|
* The cloud consents for this workspace or folder, for the Cloud consents
|
|
359
598
|
* list on the AI tab: the stored answers, plus this session's "Don't
|
|
@@ -367,7 +606,7 @@ interface MikeDownAiHost {
|
|
|
367
606
|
/**
|
|
368
607
|
* What `requestCloudConsent` resolves to: `true` allowed for the workspace
|
|
369
608
|
* (remembered), `'once'` allowed for this request only (the next one asks
|
|
370
|
-
* again), `false` declined for this request (a host may also stop asking for
|
|
609
|
+
* again), or for the whole turn from `requestTurnConsent`, `false` declined for this request (a host may also stop asking for
|
|
371
610
|
* the session; it then answers `false` without a dialog), `'never'` a stored
|
|
372
611
|
* refusal from an older version (the host answers it without asking). A host
|
|
373
612
|
* that only knows allow and decline keeps returning booleans.
|
|
@@ -385,14 +624,84 @@ interface AiConsentRecord {
|
|
|
385
624
|
}
|
|
386
625
|
/**
|
|
387
626
|
* What a request sends to the engine, for the privacy copy (`whatIsSent`):
|
|
388
|
-
* the selection with its neighbouring paragraphs, the whole document,
|
|
389
|
-
* document with its frontmatter and the workspace's tag names
|
|
627
|
+
* the selection with its neighbouring paragraphs, the whole document, the
|
|
628
|
+
* document with its frontmatter and the workspace's tag names, pages from
|
|
629
|
+
* the documentation bases the user turned on, or the text around the cursor
|
|
630
|
+
* on every pause (Inline suggestions).
|
|
631
|
+
*/
|
|
632
|
+
type AiSendsScope = 'selection' | 'document' | 'documentAndTags' | 'docsBase' | 'cursor';
|
|
633
|
+
/**
|
|
634
|
+
* The request behind a consent prompt. `sends` overrides the feature's own
|
|
635
|
+
* scope (whole-document Translate; the docs chat sends `docsBase`).
|
|
390
636
|
*/
|
|
391
|
-
type AiSendsScope = 'selection' | 'document' | 'documentAndTags';
|
|
392
|
-
/** The request behind a consent prompt. `sends` overrides the feature's own scope (whole-document Translate). */
|
|
393
637
|
interface AiConsentAbout {
|
|
394
638
|
feature?: string;
|
|
395
639
|
sends?: AiSendsScope;
|
|
640
|
+
/**
|
|
641
|
+
* The documentation bases the request would send pages from, by id. The
|
|
642
|
+
* host maps ids to names from its own user-level settings and drops unknown
|
|
643
|
+
* ids, so a name from the webview never reaches its modal.
|
|
644
|
+
*/
|
|
645
|
+
baseIds?: string[];
|
|
646
|
+
}
|
|
647
|
+
/** A consent prompt from a chat turn (`AiCompletionTurn.id`): an "Allow once" holds for that turn and no other. */
|
|
648
|
+
interface AiTurnConsentAbout extends AiConsentAbout {
|
|
649
|
+
turnId: string;
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* The `docs` group on `MikeDownHost`: documentation bases, read through the
|
|
653
|
+
* host. Absent (npm consumers): the chat's scope picker shows "This document"
|
|
654
|
+
* only. Defined next to `MikeDownAiHost` so hosts reach it through
|
|
655
|
+
* `@mikedown/core/ai`; `host.ts` re-exports it.
|
|
656
|
+
*
|
|
657
|
+
* Containment is the host's job and is code, not prompt (S1, S2, S3, S9):
|
|
658
|
+
*
|
|
659
|
+
* - Every method takes a base id and resolves the roots from the host's own
|
|
660
|
+
* user-level configuration. A root that configuration does not list is
|
|
661
|
+
* refused, so a webview message can never name a folder. A disabled base is
|
|
662
|
+
* refused.
|
|
663
|
+
* - `readSections` looks ids up in the host's own index and refuses anything
|
|
664
|
+
* else. No path is ever built from an id's text.
|
|
665
|
+
* - Reads canonicalize the root and the file, refuse anything outside the
|
|
666
|
+
* root (whole path components), non-markdown, symlinks, non-regular files
|
|
667
|
+
* and oversize files.
|
|
668
|
+
* - The model names ids from core's index and nothing else.
|
|
669
|
+
*/
|
|
670
|
+
interface MikeDownDocsHost {
|
|
671
|
+
/**
|
|
672
|
+
* Every configured base with its health (disabled ones included). The bases
|
|
673
|
+
* themselves (`enabled`, `allowCloud`, names) are read afresh on every call.
|
|
674
|
+
* A plain call is cheap and must not walk a base that already has a usable
|
|
675
|
+
* index: the chat loop calls it once per turn. `refresh: true` forces a walk
|
|
676
|
+
* and fills the health (file counts, broken links); the manager page passes
|
|
677
|
+
* it when its section opens and on Refresh.
|
|
678
|
+
*/
|
|
679
|
+
listBases(opts?: {
|
|
680
|
+
refresh?: boolean;
|
|
681
|
+
}): Promise<AiDocBaseStatus[]>;
|
|
682
|
+
/** The base's index (pages, headings, links, homes; no bodies), built lazily and kept in memory. Rejects for an unknown, disabled or inactive base. */
|
|
683
|
+
index(baseId: string): Promise<AiDocsIndex>;
|
|
684
|
+
/**
|
|
685
|
+
* Bodies for section ids (`<page id>#<slug>`) or page ids, each capped at
|
|
686
|
+
* the section byte cap. Ids the host's index does not know are left out of
|
|
687
|
+
* the result (never an error, never a path); a read that fails a
|
|
688
|
+
* containment check is left out too. Order follows `ids`.
|
|
689
|
+
*/
|
|
690
|
+
readSections(baseId: string, ids: string[]): Promise<AiDocsSection[]>;
|
|
691
|
+
/** Case-folded scan over the base's files, headings weighted, best first, at most 20 (`docs/keyword.ts`). Ids and labels only. */
|
|
692
|
+
keywordSearch(baseId: string, query: string): Promise<AiDocsSectionRef[]>;
|
|
693
|
+
/** Tell core when the base's files change (a watcher per root only). Returns the function that stops watching. */
|
|
694
|
+
watch?(baseId: string, onChange: () => void): () => void;
|
|
695
|
+
/**
|
|
696
|
+
* Save the user's bases. The host re-validates with `parseAiSettings` and
|
|
697
|
+
* writes the user-level setting only, never a workspace one. Rejects when
|
|
698
|
+
* nothing valid is left to write over something valid.
|
|
699
|
+
*/
|
|
700
|
+
saveBases(bases: AiDocBase[]): Promise<void>;
|
|
701
|
+
/** VS Code: offer the open workspace folders (a picker when there are several) and resolve one's absolute path; null when cancelled or none is open. */
|
|
702
|
+
addWorkspaceFolder?(): Promise<string | null>;
|
|
703
|
+
/** Desktop: the native folder picker; resolves the chosen absolute path, null when cancelled. */
|
|
704
|
+
pickFolder?(): Promise<string | null>;
|
|
396
705
|
}
|
|
397
706
|
/** A model as one discovery call reported it, before merging into settings. */
|
|
398
707
|
interface AiDiscoveredModel {
|
|
@@ -428,5 +737,5 @@ interface ProviderAdapter {
|
|
|
428
737
|
embed?(engine: AiEngineConfig, apiKey: string | null, model: AiModelConfig, texts: string[], signal: AbortSignal): Promise<number[][]>;
|
|
429
738
|
}
|
|
430
739
|
|
|
431
|
-
export {
|
|
432
|
-
export type { AiSettings as A,
|
|
740
|
+
export { AI_CAPABILITY_FLAGS as H, AI_DOCS_MAX_HOPS_DEFAULT as I, AI_DOCS_MAX_HOPS_MAX as J, AI_DOCS_MAX_HOPS_MIN as K, AI_DOCS_NAVIGATE_BY as L, AI_DOCS_NAVIGATE_BY_DEFAULT as N, AI_DOCS_SOURCE_SHARE_DEFAULT as O, AI_DOCS_SOURCE_SHARE_MAX as P, AI_DOCS_SOURCE_SHARE_MIN as Q, AI_ENGINE_KINDS as R, AI_ERROR_CODES as S, AI_FALLBACK_MODES as T, AI_HOST_ENGINE_KINDS as U, AI_TURN_GRANT_MAX_USES as V, DEFAULT_CONTEXT_TOKENS as ag };
|
|
741
|
+
export type { AiDocHomeKind as $, AiSettings as A, AiDocBaseStatus as B, AiDocsNavigateBy as C, AiConsentRecord as D, AiLocalServerProbe as E, AiHardwareInfo as F, AiHostEngineProbe as G, MikeDownAiHost as M, AiCapabilitiesSource as W, AiCompletionTurn as X, AiConsentAbout as Y, AiConsentReply as Z, AiDocBase as _, AiEngineStatus as a, AiDocRootStatus as a0, AiDocsHeading as a1, AiDocsSettings as a2, AiEngineStatusModel as a3, AiFallbackMode as a4, AiFeatureSetting as a5, AiGhostTextOptions as a6, AiGhostTrigger as a7, AiKeySource as a8, AiLocalitySetting as a9, AiMessagePart as aa, AiRoute as ab, AiRouting as ac, AiServedBy as ad, AiTiming as ae, AiTurnConsentAbout as af, ProviderAdapter as ah, MikeDownDocsHost as b, AiModelCapabilities as c, AiCapabilityFlag as d, AiSendsScope as e, AiFeatureSettings as f, AiLocality as g, AiEngineConfig as h, AiEngineKind as i, AiModelConfig as j, AiDiscoveredModel as k, AiApiKeyFile as l, AiDocsOptions as m, AiFinishReason as n, AiUsage as o, AiErrorCode as p, AiCompletionResult as q, AiCompletionRequest as r, AiMessage as s, AiError as t, AiDocsLink as u, AiDocsIndex as v, AiDocsPage as w, AiDocsHome as x, AiDocsSectionRef as y, AiDocsSection as z };
|