@spotpatch/vite 1.1.0 → 1.2.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 +6 -0
- package/dist/index.cjs +44 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +45 -11
- package/dist/index.js.map +1 -1
- package/dist/runtime-client.js +85 -32
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -42,6 +42,12 @@ SPOTPATCH_AI_API_KEY=<your-key>
|
|
|
42
42
|
default) or `x-api-key`. Partial environment configuration fails fast without
|
|
43
43
|
printing credential values. API keys must never use a `VITE_` prefix.
|
|
44
44
|
|
|
45
|
+
Source actions auto-detect Cursor or VS Code and open the selected file at its
|
|
46
|
+
exact line and column. Set `editor: "cursor"` or `editor: "vscode"` only when an
|
|
47
|
+
explicit preference is required. The workbench also links to the
|
|
48
|
+
[SpotPatch GitHub repository](https://github.com/huanglvjing/spotpatch) for docs,
|
|
49
|
+
issues, and project updates.
|
|
50
|
+
|
|
45
51
|
Non-secret URL and model values can instead use the concise API:
|
|
46
52
|
|
|
47
53
|
```ts
|
package/dist/index.cjs
CHANGED
|
@@ -126,7 +126,7 @@ var DEFAULT_OPTIONS = Object.freeze({
|
|
|
126
126
|
enabled: true,
|
|
127
127
|
include: DEFAULT_INCLUDE,
|
|
128
128
|
exclude: DEFAULT_EXCLUDE,
|
|
129
|
-
editor: "
|
|
129
|
+
editor: "auto",
|
|
130
130
|
redact: true,
|
|
131
131
|
budget: DEFAULT_BUDGET,
|
|
132
132
|
shortcut: "Mod+Shift+S",
|
|
@@ -434,9 +434,13 @@ function resolveOptions(options = {}, environmentAi) {
|
|
|
434
434
|
assertPositiveBudget(budget);
|
|
435
435
|
const maxTargets = options.maxTargets ?? DEFAULT_OPTIONS.maxTargets;
|
|
436
436
|
const locale = options.locale ?? DEFAULT_OPTIONS.locale;
|
|
437
|
+
const editor = options.editor ?? DEFAULT_OPTIONS.editor;
|
|
437
438
|
if (!import_shared.SPOTPATCH_LOCALE_PREFERENCES.includes(locale)) {
|
|
438
439
|
throw new RangeError("SpotPatch locale must be auto, en-US, or zh-CN.");
|
|
439
440
|
}
|
|
441
|
+
if (!import_shared.SPOTPATCH_EDITOR_PREFERENCES.includes(editor)) {
|
|
442
|
+
throw new RangeError("SpotPatch editor must be auto, vscode, or cursor.");
|
|
443
|
+
}
|
|
440
444
|
if (!Number.isSafeInteger(maxTargets) || maxTargets < 1 || maxTargets > import_shared.MAX_ANNOTATION_TARGETS) {
|
|
441
445
|
throw new RangeError(
|
|
442
446
|
`SpotPatch maxTargets must be an integer between 1 and ${String(import_shared.MAX_ANNOTATION_TARGETS)}.`
|
|
@@ -446,7 +450,7 @@ function resolveOptions(options = {}, environmentAi) {
|
|
|
446
450
|
enabled: options.enabled ?? DEFAULT_OPTIONS.enabled,
|
|
447
451
|
include: Object.freeze([...options.include ?? DEFAULT_OPTIONS.include]),
|
|
448
452
|
exclude: Object.freeze([...options.exclude ?? DEFAULT_OPTIONS.exclude]),
|
|
449
|
-
editor
|
|
453
|
+
editor,
|
|
450
454
|
redact: options.redact ?? DEFAULT_OPTIONS.redact,
|
|
451
455
|
budget,
|
|
452
456
|
shortcut: options.shortcut ?? DEFAULT_OPTIONS.shortcut,
|
|
@@ -511,7 +515,7 @@ var import_node_path2 = __toESM(require("path"), 1);
|
|
|
511
515
|
// package.json
|
|
512
516
|
var package_default = {
|
|
513
517
|
name: "@spotpatch/vite",
|
|
514
|
-
version: "1.
|
|
518
|
+
version: "1.2.0",
|
|
515
519
|
description: "Vite development plugin for SpotPatch.",
|
|
516
520
|
license: "MIT",
|
|
517
521
|
repository: {
|
|
@@ -608,6 +612,7 @@ function createClientModule(input, clientBundle, viteVersion) {
|
|
|
608
612
|
ai: createRuntimeAiConfig(options.ai),
|
|
609
613
|
budget: options.budget,
|
|
610
614
|
debug: options.debug,
|
|
615
|
+
editor: options.editor,
|
|
611
616
|
locale: options.locale,
|
|
612
617
|
maxTargets: options.maxTargets,
|
|
613
618
|
redact: options.redact,
|
|
@@ -1816,9 +1821,36 @@ async function handleAgentRequest(request, response, options, route, writeSucces
|
|
|
1816
1821
|
|
|
1817
1822
|
// src/server/editor.ts
|
|
1818
1823
|
var import_launch_editor = __toESM(require("launch-editor"), 1);
|
|
1819
|
-
var
|
|
1820
|
-
|
|
1821
|
-
|
|
1824
|
+
var EDITOR_STARTUP_GRACE_MS = 150;
|
|
1825
|
+
function editorCommand(editor) {
|
|
1826
|
+
if (editor === "vscode") {
|
|
1827
|
+
return "code";
|
|
1828
|
+
}
|
|
1829
|
+
if (editor === "cursor") {
|
|
1830
|
+
return "cursor";
|
|
1831
|
+
}
|
|
1832
|
+
return void 0;
|
|
1833
|
+
}
|
|
1834
|
+
var launchConfiguredEditor = (target, editor) => new Promise((resolve, reject) => {
|
|
1835
|
+
let settled = false;
|
|
1836
|
+
const startupTimer = setTimeout(() => {
|
|
1837
|
+
settled = true;
|
|
1838
|
+
resolve();
|
|
1839
|
+
}, EDITOR_STARTUP_GRACE_MS);
|
|
1840
|
+
const rejectStartup = () => {
|
|
1841
|
+
if (settled) {
|
|
1842
|
+
return;
|
|
1843
|
+
}
|
|
1844
|
+
settled = true;
|
|
1845
|
+
clearTimeout(startupTimer);
|
|
1846
|
+
reject(new Error("The configured editor could not be started."));
|
|
1847
|
+
};
|
|
1848
|
+
try {
|
|
1849
|
+
(0, import_launch_editor.default)(target, editorCommand(editor), rejectStartup);
|
|
1850
|
+
} catch {
|
|
1851
|
+
rejectStartup();
|
|
1852
|
+
}
|
|
1853
|
+
});
|
|
1822
1854
|
|
|
1823
1855
|
// src/server/request-security.ts
|
|
1824
1856
|
var import_node_crypto3 = require("crypto");
|
|
@@ -1999,17 +2031,18 @@ async function handleOpenEditor(request, options) {
|
|
|
1999
2031
|
root: options.root
|
|
2000
2032
|
});
|
|
2001
2033
|
const target = `${sourcePath}:${String(body.line)}:${String(body.column)}`;
|
|
2002
|
-
const editorLauncher = options.editorLauncher ??
|
|
2034
|
+
const editorLauncher = options.editorLauncher ?? launchConfiguredEditor;
|
|
2003
2035
|
try {
|
|
2004
|
-
editorLauncher(target,
|
|
2005
|
-
options.logger?.warn("[spotpatch:server] VS Code rejected an editor request.");
|
|
2006
|
-
});
|
|
2036
|
+
await editorLauncher(target, options.options.editor);
|
|
2007
2037
|
} catch (error) {
|
|
2038
|
+
options.logger?.warn(
|
|
2039
|
+
`[spotpatch:server] ${options.options.editor === "auto" ? "The detected editor" : options.options.editor} rejected an editor request.`
|
|
2040
|
+
);
|
|
2008
2041
|
throw new import_shared9.SpotPatchError(import_shared9.ERROR_CODES.EDITOR_OPEN_FAILED, void 0, {
|
|
2009
2042
|
cause: error
|
|
2010
2043
|
});
|
|
2011
2044
|
}
|
|
2012
|
-
return Object.freeze({});
|
|
2045
|
+
return Object.freeze({ editor: options.options.editor });
|
|
2013
2046
|
}
|
|
2014
2047
|
function createSpotPatchMiddleware(options) {
|
|
2015
2048
|
return (request, response, next) => {
|