@skaldapp/milkdown-copilot 1.0.0 → 1.0.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/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  import type { Ctx } from "@milkdown/kit/ctx";
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">;
2
+ import type { TOpenAI } from "@skaldapp/shared";
3
+ import { CompletionCopilot } from "monacopilot";
4
+ export declare const apiKeySlice: import("@milkdown/ctx").SliceType<string, "apiKey">, baseURLSlice: import("@milkdown/ctx").SliceType<string, "baseURL">, createCompletionCopilot: ({ apiKey, baseURL, endpoint, model, }: { [K in keyof TOpenAI]: NonNullable<TOpenAI[K]>; }) => CompletionCopilot, endpointSlice: import("@milkdown/ctx").SliceType<string, "endpoint">, filenameSlice: import("@milkdown/ctx").SliceType<string, "filename">, modelSlice: import("@milkdown/ctx").SliceType<string, "model">;
3
5
  export declare const copilotPlugin: (((ctx: Ctx) => () => undefined) | import("@milkdown/utils").$Prose)[];
package/dist/index.js CHANGED
@@ -10,7 +10,36 @@ import { CompletionCopilot } from "monacopilot";
10
10
  import { debounce } from "quasar";
11
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"];
12
12
  const init = () => ({ deco, message });
13
- export const apiKeySlice = createSlice("", "apiKey"), baseURLSlice = createSlice("", "baseURL"), endpointSlice = createSlice("", "endpoint"), filenameSlice = createSlice("", "filename"), modelSlice = createSlice("", "model");
13
+ export const apiKeySlice = createSlice("", "apiKey"), baseURLSlice = createSlice("", "baseURL"), createCompletionCopilot = ({ apiKey, baseURL, endpoint, model, }) => new CompletionCopilot(undefined, {
14
+ model: async ({ context, fileContent, instruction }) => {
15
+ const [prefix = "", suffix = ""] = fileContent.split("<|developer_cursor_is_here|>"), Authorization = `Bearer ${apiKey}`, prompt = `${context}\n${instruction}\n${prefix}`;
16
+ let text = null;
17
+ try {
18
+ const { choices: [{ message: { content }, },], } = await (await fetch(`${baseURL}/${endpoint || "completions"}`, {
19
+ body: JSON.stringify({
20
+ max_tokens,
21
+ model,
22
+ prompt,
23
+ stop,
24
+ stream,
25
+ ...(endpoint && { suffix }),
26
+ temperature,
27
+ top_p,
28
+ }),
29
+ headers: {
30
+ Authorization,
31
+ "Content-Type": "application/json",
32
+ },
33
+ method,
34
+ })).json();
35
+ text = content;
36
+ }
37
+ catch (err) {
38
+ console.log(err);
39
+ }
40
+ return { text };
41
+ },
42
+ }), endpointSlice = createSlice("", "endpoint"), filenameSlice = createSlice("", "filename"), modelSlice = createSlice("", "model");
14
43
  export const copilotPlugin = [
15
44
  (ctx) => {
16
45
  ctx.inject(apiKeySlice);
@@ -34,36 +63,7 @@ export const copilotPlugin = [
34
63
  localModel = model;
35
64
  copilot =
36
65
  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
- })
66
+ ? createCompletionCopilot({ apiKey, baseURL, endpoint, model })
67
67
  : undefined;
68
68
  }
69
69
  if (copilot && filename) {
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": "1.0.0",
4
+ "version": "1.0.1",
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",
@@ -45,6 +45,7 @@
45
45
  },
46
46
  "devDependencies": {
47
47
  "@skaldapp/configs": "^1.2.109",
48
+ "@skaldapp/shared": "^1.2.80",
48
49
  "@types/node": "^25.9.1",
49
50
  "eslint": "^10.4.0"
50
51
  }