@skaldapp/milkdown-copilot 0.0.22 → 1.0.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/dist/index.d.ts +1 -1
- package/dist/index.js +48 -8
- package/package.json +4 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Ctx } from "@milkdown/kit/ctx";
|
|
2
|
-
export declare const apiKeySlice: import("@milkdown/ctx").SliceType<string, "apiKey">, filenameSlice: import("@milkdown/ctx").SliceType<string, "filename">;
|
|
2
|
+
export declare const apiKeySlice: import("@milkdown/ctx").SliceType<string, "apiKey">, baseURLSlice: import("@milkdown/ctx").SliceType<string, "baseURL">, endpointSlice: import("@milkdown/ctx").SliceType<string, "endpoint">, filenameSlice: import("@milkdown/ctx").SliceType<string, "filename">, modelSlice: import("@milkdown/ctx").SliceType<string, "model">;
|
|
3
3
|
export declare const copilotPlugin: (((ctx: Ctx) => () => undefined) | import("@milkdown/utils").$Prose)[];
|
package/dist/index.js
CHANGED
|
@@ -5,26 +5,66 @@ import { DOMParser, DOMSerializer } from "@milkdown/kit/prose/model";
|
|
|
5
5
|
import { Plugin, PluginKey } from "@milkdown/kit/prose/state";
|
|
6
6
|
import { Decoration, DecorationSet } from "@milkdown/kit/prose/view";
|
|
7
7
|
import { $prose } from "@milkdown/kit/utils";
|
|
8
|
+
import { DEFAULT_COPILOT_MAX_TOKENS as max_tokens, DEFAULT_COPILOT_STOP_SEQUENCE as stop, DEFAULT_COPILOT_STREAM as stream, DEFAULT_COPILOT_TEMPERATURE as temperature, DEFAULT_COPILOT_TOP_P as top_p, } from "@monacopilot/core";
|
|
8
9
|
import { CompletionCopilot } from "monacopilot";
|
|
9
10
|
import { debounce } from "quasar";
|
|
10
|
-
const BR_TAG_REGEX = /^<br \/>|<br \/>$/g, column = NaN, lineNumber = NaN, cursorPosition = { column, lineNumber }, deco = DecorationSet.empty, name = "MilkdownCopilot", key = new PluginKey(name), language = "markdown", message = "",
|
|
11
|
+
const BR_TAG_REGEX = /^<br \/>|<br \/>$/g, column = NaN, lineNumber = NaN, cursorPosition = { column, lineNumber }, deco = DecorationSet.empty, name = "MilkdownCopilot", key = new PluginKey(name), language = "markdown", message = "", method = "POST", relatedFiles = undefined, second = 1000, technologies = ["vue", "tailwindcss", "comark"];
|
|
11
12
|
const init = () => ({ deco, message });
|
|
12
|
-
export const apiKeySlice = createSlice("", "apiKey"), filenameSlice = createSlice("", "filename");
|
|
13
|
+
export const apiKeySlice = createSlice("", "apiKey"), baseURLSlice = createSlice("", "baseURL"), endpointSlice = createSlice("", "endpoint"), filenameSlice = createSlice("", "filename"), modelSlice = createSlice("", "model");
|
|
13
14
|
export const copilotPlugin = [
|
|
14
15
|
(ctx) => {
|
|
15
16
|
ctx.inject(apiKeySlice);
|
|
16
17
|
ctx.inject(filenameSlice);
|
|
18
|
+
ctx.inject(modelSlice);
|
|
19
|
+
ctx.inject(baseURLSlice);
|
|
20
|
+
ctx.inject(endpointSlice);
|
|
17
21
|
return () => undefined;
|
|
18
22
|
},
|
|
19
23
|
$prose((ctx) => {
|
|
20
|
-
let copilot, localApiKey = "";
|
|
24
|
+
let copilot, localApiKey = "", localBaseURL = "", localEndpoint = "", localModel = "";
|
|
21
25
|
const getHint = debounce(async (view) => {
|
|
22
|
-
const apiKey = ctx.get(apiKeySlice), filename = ctx.get(filenameSlice);
|
|
23
|
-
if (localApiKey !== apiKey
|
|
26
|
+
const apiKey = ctx.get(apiKeySlice), baseURL = ctx.get(baseURLSlice), endpoint = ctx.get(endpointSlice), filename = ctx.get(filenameSlice), model = ctx.get(modelSlice);
|
|
27
|
+
if (localApiKey !== apiKey ||
|
|
28
|
+
localBaseURL !== baseURL ||
|
|
29
|
+
localEndpoint !== endpoint ||
|
|
30
|
+
localModel !== model) {
|
|
24
31
|
localApiKey = apiKey;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
localBaseURL = baseURL;
|
|
33
|
+
localEndpoint = endpoint;
|
|
34
|
+
localModel = model;
|
|
35
|
+
copilot =
|
|
36
|
+
apiKey && baseURL && model
|
|
37
|
+
? new CompletionCopilot(undefined, {
|
|
38
|
+
model: async ({ context, fileContent, instruction }) => {
|
|
39
|
+
const [prefix = "", suffix = ""] = fileContent.split("<|developer_cursor_is_here|>"), Authorization = `Bearer ${apiKey}`, prompt = `${context}\n${instruction}\n${prefix}`;
|
|
40
|
+
let text = null;
|
|
41
|
+
try {
|
|
42
|
+
const { choices: [{ message: { content }, },], } = await (await fetch(`${baseURL}/${endpoint || "completions"}`, {
|
|
43
|
+
body: JSON.stringify({
|
|
44
|
+
max_tokens,
|
|
45
|
+
model,
|
|
46
|
+
prompt,
|
|
47
|
+
stop,
|
|
48
|
+
stream,
|
|
49
|
+
...(endpoint && { suffix }),
|
|
50
|
+
temperature,
|
|
51
|
+
top_p,
|
|
52
|
+
}),
|
|
53
|
+
headers: {
|
|
54
|
+
Authorization,
|
|
55
|
+
"Content-Type": "application/json",
|
|
56
|
+
},
|
|
57
|
+
method,
|
|
58
|
+
})).json();
|
|
59
|
+
text = content;
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
console.log(err);
|
|
63
|
+
}
|
|
64
|
+
return { text };
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
: undefined;
|
|
28
68
|
}
|
|
29
69
|
if (copilot && filename) {
|
|
30
70
|
const { dispatch, state: { schema: { topNodeType }, tr: { doc, selection: { from }, }, }, } = view, { content: after } = doc.slice(from), textAfterCursor = ctx
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://www.schemastore.org/package",
|
|
3
3
|
"name": "@skaldapp/milkdown-copilot",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "1.0.0",
|
|
5
5
|
"description": "A Milkdown plugin that provides AI-powered code completions using Mistral AI’s Codestral model with debounced requests and tab-to-accept functionality.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"milkdown",
|
|
@@ -39,12 +39,13 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@milkdown/ctx": "^7.21.1",
|
|
41
41
|
"@milkdown/kit": "^7.21.1",
|
|
42
|
+
"@monacopilot/core": "^1.2.12",
|
|
42
43
|
"monacopilot": "^1.2.12",
|
|
43
44
|
"quasar": "^2.19.3"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
|
-
"@skaldapp/configs": "^1.2.
|
|
47
|
-
"@types/node": "^25.9.
|
|
47
|
+
"@skaldapp/configs": "^1.2.109",
|
|
48
|
+
"@types/node": "^25.9.1",
|
|
48
49
|
"eslint": "^10.4.0"
|
|
49
50
|
}
|
|
50
51
|
}
|