@spotpatch/vite 1.1.0 → 1.2.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/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 +64 -41
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
-
import { ContextBudget, SpotPatchLocalePreference, ResolvedAiOptions, AiProviderProtocol, AiProviderAuthentication, AiExecutionOptions, AiOptions } from '@spotpatch/shared';
|
|
3
|
-
export { AgentApplyMode, AgentCheckDefinition, AgentLimits, AiExecutionOptions, AiModelProfile, AiOptions, AiProviderAuthentication, AiProviderProtocol, ContextBudget, DEFAULT_AGENT_LIMITS, OpenAICompatibleProviderOptions } from '@spotpatch/shared';
|
|
2
|
+
import { SpotPatchEditorPreference, ContextBudget, SpotPatchLocalePreference, ResolvedAiOptions, AiProviderProtocol, AiProviderAuthentication, AiExecutionOptions, AiOptions } from '@spotpatch/shared';
|
|
3
|
+
export { AgentApplyMode, AgentCheckDefinition, AgentLimits, AiExecutionOptions, AiModelProfile, AiOptions, AiProviderAuthentication, AiProviderProtocol, ContextBudget, DEFAULT_AGENT_LIMITS, OpenAICompatibleProviderOptions, SpotPatchEditorPreference } from '@spotpatch/shared';
|
|
4
4
|
|
|
5
5
|
type FilterEntry = string | RegExp;
|
|
6
6
|
interface SimpleAiOptions {
|
|
@@ -18,7 +18,7 @@ interface SpotPatchOptions {
|
|
|
18
18
|
readonly enabled?: boolean;
|
|
19
19
|
readonly include?: readonly FilterEntry[];
|
|
20
20
|
readonly exclude?: readonly FilterEntry[];
|
|
21
|
-
readonly editor?:
|
|
21
|
+
readonly editor?: SpotPatchEditorPreference;
|
|
22
22
|
readonly redact?: boolean;
|
|
23
23
|
readonly budget?: Partial<ContextBudget>;
|
|
24
24
|
readonly shortcut?: string;
|
|
@@ -32,7 +32,7 @@ interface ResolvedSpotPatchOptions {
|
|
|
32
32
|
readonly enabled: boolean;
|
|
33
33
|
readonly include: readonly FilterEntry[];
|
|
34
34
|
readonly exclude: readonly FilterEntry[];
|
|
35
|
-
readonly editor:
|
|
35
|
+
readonly editor: SpotPatchEditorPreference;
|
|
36
36
|
readonly redact: boolean;
|
|
37
37
|
readonly budget: Readonly<ContextBudget>;
|
|
38
38
|
readonly shortcut: string;
|
|
@@ -46,7 +46,7 @@ declare const DEFAULT_OPTIONS: Readonly<{
|
|
|
46
46
|
enabled: true;
|
|
47
47
|
include: readonly RegExp[];
|
|
48
48
|
exclude: readonly RegExp[];
|
|
49
|
-
editor: "
|
|
49
|
+
editor: "auto";
|
|
50
50
|
redact: true;
|
|
51
51
|
budget: Readonly<{
|
|
52
52
|
totalCharacters: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
-
import { ContextBudget, SpotPatchLocalePreference, ResolvedAiOptions, AiProviderProtocol, AiProviderAuthentication, AiExecutionOptions, AiOptions } from '@spotpatch/shared';
|
|
3
|
-
export { AgentApplyMode, AgentCheckDefinition, AgentLimits, AiExecutionOptions, AiModelProfile, AiOptions, AiProviderAuthentication, AiProviderProtocol, ContextBudget, DEFAULT_AGENT_LIMITS, OpenAICompatibleProviderOptions } from '@spotpatch/shared';
|
|
2
|
+
import { SpotPatchEditorPreference, ContextBudget, SpotPatchLocalePreference, ResolvedAiOptions, AiProviderProtocol, AiProviderAuthentication, AiExecutionOptions, AiOptions } from '@spotpatch/shared';
|
|
3
|
+
export { AgentApplyMode, AgentCheckDefinition, AgentLimits, AiExecutionOptions, AiModelProfile, AiOptions, AiProviderAuthentication, AiProviderProtocol, ContextBudget, DEFAULT_AGENT_LIMITS, OpenAICompatibleProviderOptions, SpotPatchEditorPreference } from '@spotpatch/shared';
|
|
4
4
|
|
|
5
5
|
type FilterEntry = string | RegExp;
|
|
6
6
|
interface SimpleAiOptions {
|
|
@@ -18,7 +18,7 @@ interface SpotPatchOptions {
|
|
|
18
18
|
readonly enabled?: boolean;
|
|
19
19
|
readonly include?: readonly FilterEntry[];
|
|
20
20
|
readonly exclude?: readonly FilterEntry[];
|
|
21
|
-
readonly editor?:
|
|
21
|
+
readonly editor?: SpotPatchEditorPreference;
|
|
22
22
|
readonly redact?: boolean;
|
|
23
23
|
readonly budget?: Partial<ContextBudget>;
|
|
24
24
|
readonly shortcut?: string;
|
|
@@ -32,7 +32,7 @@ interface ResolvedSpotPatchOptions {
|
|
|
32
32
|
readonly enabled: boolean;
|
|
33
33
|
readonly include: readonly FilterEntry[];
|
|
34
34
|
readonly exclude: readonly FilterEntry[];
|
|
35
|
-
readonly editor:
|
|
35
|
+
readonly editor: SpotPatchEditorPreference;
|
|
36
36
|
readonly redact: boolean;
|
|
37
37
|
readonly budget: Readonly<ContextBudget>;
|
|
38
38
|
readonly shortcut: string;
|
|
@@ -46,7 +46,7 @@ declare const DEFAULT_OPTIONS: Readonly<{
|
|
|
46
46
|
enabled: true;
|
|
47
47
|
include: readonly RegExp[];
|
|
48
48
|
exclude: readonly RegExp[];
|
|
49
|
-
editor: "
|
|
49
|
+
editor: "auto";
|
|
50
50
|
redact: true;
|
|
51
51
|
budget: Readonly<{
|
|
52
52
|
totalCharacters: number;
|
package/dist/index.js
CHANGED
|
@@ -67,6 +67,7 @@ function resolveEnvironmentAiConfiguration(environment) {
|
|
|
67
67
|
import {
|
|
68
68
|
DEFAULT_AGENT_LIMITS,
|
|
69
69
|
MAX_ANNOTATION_TARGETS,
|
|
70
|
+
SPOTPATCH_EDITOR_PREFERENCES,
|
|
70
71
|
SPOTPATCH_LOCALE_PREFERENCES
|
|
71
72
|
} from "@spotpatch/shared";
|
|
72
73
|
import { z } from "zod";
|
|
@@ -91,7 +92,7 @@ var DEFAULT_OPTIONS = Object.freeze({
|
|
|
91
92
|
enabled: true,
|
|
92
93
|
include: DEFAULT_INCLUDE,
|
|
93
94
|
exclude: DEFAULT_EXCLUDE,
|
|
94
|
-
editor: "
|
|
95
|
+
editor: "auto",
|
|
95
96
|
redact: true,
|
|
96
97
|
budget: DEFAULT_BUDGET,
|
|
97
98
|
shortcut: "Mod+Shift+S",
|
|
@@ -399,9 +400,13 @@ function resolveOptions(options = {}, environmentAi) {
|
|
|
399
400
|
assertPositiveBudget(budget);
|
|
400
401
|
const maxTargets = options.maxTargets ?? DEFAULT_OPTIONS.maxTargets;
|
|
401
402
|
const locale = options.locale ?? DEFAULT_OPTIONS.locale;
|
|
403
|
+
const editor = options.editor ?? DEFAULT_OPTIONS.editor;
|
|
402
404
|
if (!SPOTPATCH_LOCALE_PREFERENCES.includes(locale)) {
|
|
403
405
|
throw new RangeError("SpotPatch locale must be auto, en-US, or zh-CN.");
|
|
404
406
|
}
|
|
407
|
+
if (!SPOTPATCH_EDITOR_PREFERENCES.includes(editor)) {
|
|
408
|
+
throw new RangeError("SpotPatch editor must be auto, vscode, or cursor.");
|
|
409
|
+
}
|
|
405
410
|
if (!Number.isSafeInteger(maxTargets) || maxTargets < 1 || maxTargets > MAX_ANNOTATION_TARGETS) {
|
|
406
411
|
throw new RangeError(
|
|
407
412
|
`SpotPatch maxTargets must be an integer between 1 and ${String(MAX_ANNOTATION_TARGETS)}.`
|
|
@@ -411,7 +416,7 @@ function resolveOptions(options = {}, environmentAi) {
|
|
|
411
416
|
enabled: options.enabled ?? DEFAULT_OPTIONS.enabled,
|
|
412
417
|
include: Object.freeze([...options.include ?? DEFAULT_OPTIONS.include]),
|
|
413
418
|
exclude: Object.freeze([...options.exclude ?? DEFAULT_OPTIONS.exclude]),
|
|
414
|
-
editor
|
|
419
|
+
editor,
|
|
415
420
|
redact: options.redact ?? DEFAULT_OPTIONS.redact,
|
|
416
421
|
budget,
|
|
417
422
|
shortcut: options.shortcut ?? DEFAULT_OPTIONS.shortcut,
|
|
@@ -476,7 +481,7 @@ import path2 from "path";
|
|
|
476
481
|
// package.json
|
|
477
482
|
var package_default = {
|
|
478
483
|
name: "@spotpatch/vite",
|
|
479
|
-
version: "1.1
|
|
484
|
+
version: "1.2.1",
|
|
480
485
|
description: "Vite development plugin for SpotPatch.",
|
|
481
486
|
license: "MIT",
|
|
482
487
|
repository: {
|
|
@@ -573,6 +578,7 @@ function createClientModule(input, clientBundle, viteVersion) {
|
|
|
573
578
|
ai: createRuntimeAiConfig(options.ai),
|
|
574
579
|
budget: options.budget,
|
|
575
580
|
debug: options.debug,
|
|
581
|
+
editor: options.editor,
|
|
576
582
|
locale: options.locale,
|
|
577
583
|
maxTargets: options.maxTargets,
|
|
578
584
|
redact: options.redact,
|
|
@@ -1813,9 +1819,36 @@ async function handleAgentRequest(request, response, options, route, writeSucces
|
|
|
1813
1819
|
|
|
1814
1820
|
// src/server/editor.ts
|
|
1815
1821
|
import launchEditor from "launch-editor";
|
|
1816
|
-
var
|
|
1817
|
-
|
|
1818
|
-
|
|
1822
|
+
var EDITOR_STARTUP_GRACE_MS = 150;
|
|
1823
|
+
function editorCommand(editor) {
|
|
1824
|
+
if (editor === "vscode") {
|
|
1825
|
+
return "code";
|
|
1826
|
+
}
|
|
1827
|
+
if (editor === "cursor") {
|
|
1828
|
+
return "cursor";
|
|
1829
|
+
}
|
|
1830
|
+
return void 0;
|
|
1831
|
+
}
|
|
1832
|
+
var launchConfiguredEditor = (target, editor) => new Promise((resolve, reject) => {
|
|
1833
|
+
let settled = false;
|
|
1834
|
+
const startupTimer = setTimeout(() => {
|
|
1835
|
+
settled = true;
|
|
1836
|
+
resolve();
|
|
1837
|
+
}, EDITOR_STARTUP_GRACE_MS);
|
|
1838
|
+
const rejectStartup = () => {
|
|
1839
|
+
if (settled) {
|
|
1840
|
+
return;
|
|
1841
|
+
}
|
|
1842
|
+
settled = true;
|
|
1843
|
+
clearTimeout(startupTimer);
|
|
1844
|
+
reject(new Error("The configured editor could not be started."));
|
|
1845
|
+
};
|
|
1846
|
+
try {
|
|
1847
|
+
launchEditor(target, editorCommand(editor), rejectStartup);
|
|
1848
|
+
} catch {
|
|
1849
|
+
rejectStartup();
|
|
1850
|
+
}
|
|
1851
|
+
});
|
|
1819
1852
|
|
|
1820
1853
|
// src/server/request-security.ts
|
|
1821
1854
|
import { timingSafeEqual } from "crypto";
|
|
@@ -1996,17 +2029,18 @@ async function handleOpenEditor(request, options) {
|
|
|
1996
2029
|
root: options.root
|
|
1997
2030
|
});
|
|
1998
2031
|
const target = `${sourcePath}:${String(body.line)}:${String(body.column)}`;
|
|
1999
|
-
const editorLauncher = options.editorLauncher ??
|
|
2032
|
+
const editorLauncher = options.editorLauncher ?? launchConfiguredEditor;
|
|
2000
2033
|
try {
|
|
2001
|
-
editorLauncher(target,
|
|
2002
|
-
options.logger?.warn("[spotpatch:server] VS Code rejected an editor request.");
|
|
2003
|
-
});
|
|
2034
|
+
await editorLauncher(target, options.options.editor);
|
|
2004
2035
|
} catch (error) {
|
|
2036
|
+
options.logger?.warn(
|
|
2037
|
+
`[spotpatch:server] ${options.options.editor === "auto" ? "The detected editor" : options.options.editor} rejected an editor request.`
|
|
2038
|
+
);
|
|
2005
2039
|
throw new SpotPatchError8(ERROR_CODES8.EDITOR_OPEN_FAILED, void 0, {
|
|
2006
2040
|
cause: error
|
|
2007
2041
|
});
|
|
2008
2042
|
}
|
|
2009
|
-
return Object.freeze({});
|
|
2043
|
+
return Object.freeze({ editor: options.options.editor });
|
|
2010
2044
|
}
|
|
2011
2045
|
function createSpotPatchMiddleware(options) {
|
|
2012
2046
|
return (request, response, next) => {
|