@aipanel/provider-opencode 1.2.0-beta.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/es/api.d.ts +16 -0
- package/es/api.js +225 -0
- package/es/bridge-script.d.ts +14 -0
- package/es/bridge-script.js +683 -0
- package/es/constants.d.ts +32 -0
- package/es/constants.js +29 -0
- package/es/index.d.ts +15 -0
- package/es/index.js +24 -0
- package/es/opencode-web.d.ts +4 -0
- package/es/opencode-web.js +276 -0
- package/es/provider.d.ts +49 -0
- package/es/provider.js +257 -0
- package/es/system.d.ts +3 -0
- package/es/system.js +175 -0
- package/es/types.d.ts +160 -0
- package/es/types.js +0 -0
- package/lib/api.cjs +251 -0
- package/lib/api.d.ts +16 -0
- package/lib/bridge-script.cjs +706 -0
- package/lib/bridge-script.d.ts +14 -0
- package/lib/constants.cjs +55 -0
- package/lib/constants.d.ts +32 -0
- package/lib/index.cjs +55 -0
- package/lib/index.d.ts +15 -0
- package/lib/opencode-web.cjs +302 -0
- package/lib/opencode-web.d.ts +4 -0
- package/lib/provider.cjs +289 -0
- package/lib/provider.d.ts +49 -0
- package/lib/system.cjs +200 -0
- package/lib/system.d.ts +3 -0
- package/lib/types.cjs +15 -0
- package/lib/types.d.ts +160 -0
- package/package.json +32 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { OpenCodeLanguage, OpenCodeSettings } from "./types";
|
|
2
|
+
export interface BridgeScriptOptions {
|
|
3
|
+
/** 主题模式 */
|
|
4
|
+
theme?: "light" | "dark" | "auto";
|
|
5
|
+
/** 界面语言 */
|
|
6
|
+
language?: OpenCodeLanguage;
|
|
7
|
+
/** 内部设置 */
|
|
8
|
+
settings?: OpenCodeSettings;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 生成 PostMessage Bridge 脚本
|
|
12
|
+
* 只处理 DOM 操作和主题同步,SSE 监听已迁移到 client 层
|
|
13
|
+
*/
|
|
14
|
+
export declare function generateBridgeScript(options?: BridgeScriptOptions): string;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var constants_exports = {};
|
|
19
|
+
__export(constants_exports, {
|
|
20
|
+
DEFAULT_OPENCODE_PROVIDER_OPTIONS: () => DEFAULT_OPENCODE_PROVIDER_OPTIONS,
|
|
21
|
+
DEFAULT_OPENCODE_SETTINGS: () => DEFAULT_OPENCODE_SETTINGS,
|
|
22
|
+
OPENCODE_CACHE_DIR: () => OPENCODE_CACHE_DIR,
|
|
23
|
+
OPENCODE_STORAGE_KEYS: () => OPENCODE_STORAGE_KEYS
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(constants_exports);
|
|
26
|
+
const OPENCODE_STORAGE_KEYS = {
|
|
27
|
+
/** 设置键 (settings.v3) */
|
|
28
|
+
SETTINGS: "settings.v3",
|
|
29
|
+
/** 配色方案键 */
|
|
30
|
+
COLOR_SCHEME: "opencode-color-scheme",
|
|
31
|
+
/** 主题 ID 键 */
|
|
32
|
+
THEME_ID: "opencode-theme-id"
|
|
33
|
+
};
|
|
34
|
+
const DEFAULT_OPENCODE_SETTINGS = {
|
|
35
|
+
general: {
|
|
36
|
+
showReasoningSummaries: true,
|
|
37
|
+
newLayoutDesigns: true,
|
|
38
|
+
showFileTree: false,
|
|
39
|
+
editToolPartsExpanded: true,
|
|
40
|
+
shellToolPartsExpanded: true
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const OPENCODE_CACHE_DIR = "node_modules/.cache/opencode";
|
|
44
|
+
const DEFAULT_OPENCODE_PROVIDER_OPTIONS = {
|
|
45
|
+
enableLsp: true,
|
|
46
|
+
enableBlockOnError: false,
|
|
47
|
+
enablePrettier: true
|
|
48
|
+
};
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
DEFAULT_OPENCODE_PROVIDER_OPTIONS,
|
|
52
|
+
DEFAULT_OPENCODE_SETTINGS,
|
|
53
|
+
OPENCODE_CACHE_DIR,
|
|
54
|
+
OPENCODE_STORAGE_KEYS
|
|
55
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode Provider 专属常量与默认值
|
|
3
|
+
* 与 OpenCode Web 绑定的常量自包含于此,核心层不感知。
|
|
4
|
+
*/
|
|
5
|
+
import type { OpenCodeProviderOptions } from "./types";
|
|
6
|
+
/** ==================== OpenCode localStorage 键 ==================== */
|
|
7
|
+
/** OpenCode localStorage 配置键 */
|
|
8
|
+
export declare const OPENCODE_STORAGE_KEYS: {
|
|
9
|
+
/** 设置键 (settings.v3) */
|
|
10
|
+
readonly SETTINGS: "settings.v3";
|
|
11
|
+
/** 配色方案键 */
|
|
12
|
+
readonly COLOR_SCHEME: "opencode-color-scheme";
|
|
13
|
+
/** 主题 ID 键 */
|
|
14
|
+
readonly THEME_ID: "opencode-theme-id";
|
|
15
|
+
};
|
|
16
|
+
/** ==================== OpenCode 默认设置 ==================== */
|
|
17
|
+
/** OpenCode 默认设置(与 OpenCode Web localStorage settings.v3 对应) */
|
|
18
|
+
export declare const DEFAULT_OPENCODE_SETTINGS: {
|
|
19
|
+
general: {
|
|
20
|
+
showReasoningSummaries: boolean;
|
|
21
|
+
newLayoutDesigns: boolean;
|
|
22
|
+
showFileTree: boolean;
|
|
23
|
+
editToolPartsExpanded: boolean;
|
|
24
|
+
shellToolPartsExpanded: boolean;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
/** ==================== 运行环境 ==================== */
|
|
28
|
+
/** OpenCode 缓存目录(相对于项目根目录,存放 opencode.json 等运行状态) */
|
|
29
|
+
export declare const OPENCODE_CACHE_DIR = "node_modules/.cache/opencode";
|
|
30
|
+
/** ==================== Provider 专属配置默认值 ==================== */
|
|
31
|
+
/** OpenCode Provider 专属配置默认值(插件组装 config 时使用) */
|
|
32
|
+
export declare const DEFAULT_OPENCODE_PROVIDER_OPTIONS: OpenCodeProviderOptions;
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var lib_exports = {};
|
|
19
|
+
__export(lib_exports, {
|
|
20
|
+
DEFAULT_OPENCODE_PROVIDER_OPTIONS: () => import_constants.DEFAULT_OPENCODE_PROVIDER_OPTIONS,
|
|
21
|
+
OpenCodeAPI: () => import_api.OpenCodeAPI,
|
|
22
|
+
checkOpenCodeInstalled: () => import_system.checkOpenCodeInstalled,
|
|
23
|
+
createProvider: () => createProvider,
|
|
24
|
+
generateBridgeScript: () => import_bridge_script.generateBridgeScript,
|
|
25
|
+
getOpenCodeVersion: () => import_system.getOpenCodeVersion,
|
|
26
|
+
killOrphanOpenCodeProcesses: () => import_system.killOrphanOpenCodeProcesses,
|
|
27
|
+
prepareOpenCodeRuntime: () => import_opencode_web.prepareOpenCodeRuntime,
|
|
28
|
+
startOpenCodeWeb: () => import_opencode_web.startOpenCodeWeb
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(lib_exports);
|
|
31
|
+
var import_provider = require("./provider.cjs");
|
|
32
|
+
var import_api = require("./api.cjs");
|
|
33
|
+
var import_opencode_web = require("./opencode-web.cjs");
|
|
34
|
+
var import_bridge_script = require("./bridge-script.cjs");
|
|
35
|
+
var import_system = require("./system.cjs");
|
|
36
|
+
var import_constants = require("./constants.cjs");
|
|
37
|
+
function createProvider(ctx) {
|
|
38
|
+
return new import_provider.DefaultWebProvider(
|
|
39
|
+
{ hostname: ctx.hostname, chromeDevtoolsPort: ctx.chromeDevtoolsPort },
|
|
40
|
+
{ getWebPort: ctx.getWebPort, getProxyPort: ctx.getProxyPort },
|
|
41
|
+
ctx.options
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
DEFAULT_OPENCODE_PROVIDER_OPTIONS,
|
|
47
|
+
OpenCodeAPI,
|
|
48
|
+
checkOpenCodeInstalled,
|
|
49
|
+
createProvider,
|
|
50
|
+
generateBridgeScript,
|
|
51
|
+
getOpenCodeVersion,
|
|
52
|
+
killOrphanOpenCodeProcesses,
|
|
53
|
+
prepareOpenCodeRuntime,
|
|
54
|
+
startOpenCodeWeb
|
|
55
|
+
});
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode Web Provider
|
|
3
|
+
* 实现 WebProvider 契约:进程管理、REST 会话 API、桥接脚本、CLI 环境检查。
|
|
4
|
+
* 所有 OpenCode 专属类型与常量自包含于此包。
|
|
5
|
+
*/
|
|
6
|
+
import type { ProviderInitContext, WebProvider } from "@aipanel/core";
|
|
7
|
+
/** 约定工厂:核心层动态加载本包后调用,初始化动作完全由 Provider 定义 */
|
|
8
|
+
export declare function createProvider(ctx: ProviderInitContext): WebProvider;
|
|
9
|
+
export { OpenCodeAPI } from "./api";
|
|
10
|
+
export type { DefaultWebProviderConfig, DefaultWebProviderDeps } from "./provider";
|
|
11
|
+
export { prepareOpenCodeRuntime, startOpenCodeWeb } from "./opencode-web";
|
|
12
|
+
export { generateBridgeScript, type BridgeScriptOptions } from "./bridge-script";
|
|
13
|
+
export { checkOpenCodeInstalled, getOpenCodeVersion, killOrphanOpenCodeProcesses } from "./system";
|
|
14
|
+
export { DEFAULT_OPENCODE_PROVIDER_OPTIONS } from "./constants";
|
|
15
|
+
export type { OpenCodeProviderOptions, OpenCodeLanguage, OpenCodeSettings, SessionInfo, WebOptions, } from "./types";
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var opencode_web_exports = {};
|
|
29
|
+
__export(opencode_web_exports, {
|
|
30
|
+
prepareOpenCodeRuntime: () => prepareOpenCodeRuntime,
|
|
31
|
+
startOpenCodeWeb: () => startOpenCodeWeb
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(opencode_web_exports);
|
|
34
|
+
var import_execa = require("execa");
|
|
35
|
+
var import_fs = __toESM(require("fs"));
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
var import_url = require("url");
|
|
38
|
+
var import_constants = require("./constants.cjs");
|
|
39
|
+
var import_node = require("@aipanel/core/node");
|
|
40
|
+
const require2 = (0, import_node.createPackageRequire)();
|
|
41
|
+
const packageDir = (0, import_node.resolvePackageDir)("@aipanel/opencode-plugins");
|
|
42
|
+
const log = (0, import_node.createLogger)("OpenCodeWeb");
|
|
43
|
+
function prepareOpenCodeRuntime(cwd, vitePort, enableLsp, enablePrettier) {
|
|
44
|
+
const cacheDir = import_path.default.join(cwd, import_constants.OPENCODE_CACHE_DIR);
|
|
45
|
+
log.debug("Setting up OpenCode runtime", { cacheDir, enableLsp });
|
|
46
|
+
if (!import_fs.default.existsSync(cacheDir)) {
|
|
47
|
+
import_fs.default.mkdirSync(cacheDir, { recursive: true });
|
|
48
|
+
}
|
|
49
|
+
const sourcePluginsDir = resolveSourcePluginsDir();
|
|
50
|
+
const plugins = resolvePluginEntries(sourcePluginsDir);
|
|
51
|
+
const formatterConfig = buildFormatterConfig(enablePrettier);
|
|
52
|
+
const opencodeConfigPath = import_path.default.join(cacheDir, "opencode.json");
|
|
53
|
+
const config = {
|
|
54
|
+
plugin: plugins,
|
|
55
|
+
formatter: formatterConfig,
|
|
56
|
+
mcp: {
|
|
57
|
+
"chrome-devtools": {
|
|
58
|
+
type: "remote",
|
|
59
|
+
url: `http://localhost:${vitePort}${import_node.MCP_API_PATH}`
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
import_fs.default.writeFileSync(opencodeConfigPath, JSON.stringify(config, null, 2));
|
|
64
|
+
log.debug("OpenCode runtime ready", {
|
|
65
|
+
cacheDir,
|
|
66
|
+
opencodeConfigPath,
|
|
67
|
+
pluginCount: plugins.length
|
|
68
|
+
});
|
|
69
|
+
return cacheDir;
|
|
70
|
+
}
|
|
71
|
+
function startOpenCodeWeb(options) {
|
|
72
|
+
const {
|
|
73
|
+
port,
|
|
74
|
+
hostname,
|
|
75
|
+
cwd,
|
|
76
|
+
configDir,
|
|
77
|
+
corsOrigins,
|
|
78
|
+
contextApiUrl,
|
|
79
|
+
logsApiUrl,
|
|
80
|
+
logFilesJson,
|
|
81
|
+
enableBlockOnError,
|
|
82
|
+
verbose,
|
|
83
|
+
enableLsp,
|
|
84
|
+
vueDevtoolsApiUrl
|
|
85
|
+
} = options;
|
|
86
|
+
const stateDir = createStateDirectory(cwd);
|
|
87
|
+
log.debug("Building process environment", {
|
|
88
|
+
stateDir,
|
|
89
|
+
configDir,
|
|
90
|
+
contextApiUrl,
|
|
91
|
+
logsApiUrl,
|
|
92
|
+
logFilesJson,
|
|
93
|
+
enableBlockOnError,
|
|
94
|
+
verbose,
|
|
95
|
+
enableLsp
|
|
96
|
+
});
|
|
97
|
+
const env = buildProcessEnv(
|
|
98
|
+
stateDir,
|
|
99
|
+
configDir,
|
|
100
|
+
contextApiUrl,
|
|
101
|
+
logsApiUrl,
|
|
102
|
+
logFilesJson,
|
|
103
|
+
enableBlockOnError,
|
|
104
|
+
verbose,
|
|
105
|
+
enableLsp,
|
|
106
|
+
vueDevtoolsApiUrl,
|
|
107
|
+
cwd
|
|
108
|
+
);
|
|
109
|
+
const args = ["serve", "--port", String(port), "--hostname", hostname];
|
|
110
|
+
if (corsOrigins && corsOrigins.length > 0) {
|
|
111
|
+
corsOrigins.forEach((origin) => {
|
|
112
|
+
args.push("--cors", origin);
|
|
113
|
+
});
|
|
114
|
+
log.debug("CORS origins added", { origins: corsOrigins });
|
|
115
|
+
}
|
|
116
|
+
log.debug("Spawning OpenCode process", {
|
|
117
|
+
command: "opencode",
|
|
118
|
+
args: args.join(" "),
|
|
119
|
+
cwd
|
|
120
|
+
});
|
|
121
|
+
const proc = (0, import_execa.execa)("opencode", args, {
|
|
122
|
+
cwd,
|
|
123
|
+
env,
|
|
124
|
+
reject: false,
|
|
125
|
+
cleanup: true,
|
|
126
|
+
shell: true
|
|
127
|
+
});
|
|
128
|
+
proc.stdout?.on("data", (data) => {
|
|
129
|
+
const output = data.toString().trim();
|
|
130
|
+
if (output) {
|
|
131
|
+
log.debug("[OpenCode stdout]", { output });
|
|
132
|
+
(0, import_node.getProcessLogBuffer)().addProviderStdout(output);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
proc.stderr?.on("data", (data) => {
|
|
136
|
+
const output = data.toString().trim();
|
|
137
|
+
if (output) {
|
|
138
|
+
if (output.includes("MaxListenersExceededWarning")) return;
|
|
139
|
+
log.warn("[OpenCode stderr]", { output });
|
|
140
|
+
(0, import_node.getProcessLogBuffer)().addProviderStderr(output);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return proc;
|
|
144
|
+
}
|
|
145
|
+
function createStateDirectory(cwd) {
|
|
146
|
+
const stateDir = import_path.default.join(cwd, import_constants.OPENCODE_CACHE_DIR);
|
|
147
|
+
if (!import_fs.default.existsSync(stateDir)) {
|
|
148
|
+
import_fs.default.mkdirSync(stateDir, { recursive: true });
|
|
149
|
+
log.debug("Created state directory", { stateDir });
|
|
150
|
+
}
|
|
151
|
+
return stateDir;
|
|
152
|
+
}
|
|
153
|
+
function buildFormatterConfig(enablePrettier) {
|
|
154
|
+
if (enablePrettier === false) {
|
|
155
|
+
log.debug("enablePrettier is false, formatter disabled");
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
const bridgePath = resolveFormatBridgePath();
|
|
159
|
+
if (!bridgePath) {
|
|
160
|
+
log.debug("format-bridge not found, using built-in formatters");
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
log.debug("Format bridge configured");
|
|
164
|
+
if (!isFormatServiceRunning()) {
|
|
165
|
+
log.debug("VS Code format service not running, using built-in formatters only");
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
log.debug("VS Code format service detected, enabling bridge");
|
|
169
|
+
log.info("\u5DF2\u8FDE\u63A5 VS Code \u683C\u5F0F\u5316\u670D\u52A1");
|
|
170
|
+
const extensions = [
|
|
171
|
+
".ts",
|
|
172
|
+
".tsx",
|
|
173
|
+
".mts",
|
|
174
|
+
".cts",
|
|
175
|
+
".js",
|
|
176
|
+
".jsx",
|
|
177
|
+
".mjs",
|
|
178
|
+
".cjs",
|
|
179
|
+
".vue",
|
|
180
|
+
".svelte",
|
|
181
|
+
".astro",
|
|
182
|
+
".css",
|
|
183
|
+
".scss",
|
|
184
|
+
".sass",
|
|
185
|
+
".less",
|
|
186
|
+
".pcss",
|
|
187
|
+
".html",
|
|
188
|
+
".htm",
|
|
189
|
+
".xml",
|
|
190
|
+
".svg",
|
|
191
|
+
".json",
|
|
192
|
+
".jsonc",
|
|
193
|
+
".yaml",
|
|
194
|
+
".yml",
|
|
195
|
+
".toml",
|
|
196
|
+
".md",
|
|
197
|
+
".mdx",
|
|
198
|
+
".graphql",
|
|
199
|
+
".gql"
|
|
200
|
+
];
|
|
201
|
+
return {
|
|
202
|
+
format_bridge: {
|
|
203
|
+
command: ["node", bridgePath, "$FILE"],
|
|
204
|
+
extensions
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
let _formatServiceRunning;
|
|
209
|
+
function isFormatServiceRunning() {
|
|
210
|
+
if (_formatServiceRunning !== void 0) return _formatServiceRunning;
|
|
211
|
+
try {
|
|
212
|
+
require2("child_process").execSync(
|
|
213
|
+
`node -e "const h=require('http');h.get('http://127.0.0.1:${import_node.VSCODE_EXTENSION_PORT}/health',r=>{r.resume();process.exit(r.statusCode===200?0:1)}).on('error',()=>process.exit(1))"`,
|
|
214
|
+
{ timeout: 500, stdio: "ignore" }
|
|
215
|
+
);
|
|
216
|
+
_formatServiceRunning = true;
|
|
217
|
+
} catch {
|
|
218
|
+
_formatServiceRunning = false;
|
|
219
|
+
}
|
|
220
|
+
return _formatServiceRunning;
|
|
221
|
+
}
|
|
222
|
+
function resolveFormatBridgePath() {
|
|
223
|
+
const viteEntry = require2.resolve("vite-plugin-aipanel");
|
|
224
|
+
const bridgePath = import_path.default.resolve(import_path.default.dirname(viteEntry), "utils", "format-bridge.cjs");
|
|
225
|
+
if (import_fs.default.existsSync(bridgePath)) return bridgePath;
|
|
226
|
+
return void 0;
|
|
227
|
+
}
|
|
228
|
+
function resolveSourcePluginsDir() {
|
|
229
|
+
const candidatePaths = [import_path.default.join(packageDir, "es", "plugins")];
|
|
230
|
+
for (const candidatePath of candidatePaths) {
|
|
231
|
+
if (import_fs.default.existsSync(candidatePath)) {
|
|
232
|
+
return candidatePath;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return candidatePaths[0];
|
|
236
|
+
}
|
|
237
|
+
const MIGRATED_TO_MCP_PLUGINS = /* @__PURE__ */ new Set(["vue-devtools.js", "vite-logs.js", "service-logs.js"]);
|
|
238
|
+
function resolvePluginEntries(sourceDir) {
|
|
239
|
+
const files = import_fs.default.readdirSync(sourceDir).filter((f) => f.endsWith(".js") && !MIGRATED_TO_MCP_PLUGINS.has(f));
|
|
240
|
+
const entries = files.map((file) => {
|
|
241
|
+
const absolutePath = import_path.default.join(sourceDir, file);
|
|
242
|
+
return (0, import_url.pathToFileURL)(absolutePath).href;
|
|
243
|
+
});
|
|
244
|
+
log.debug("Resolved plugin entries", { count: entries.length, entries });
|
|
245
|
+
return entries;
|
|
246
|
+
}
|
|
247
|
+
function buildProcessEnv(stateDir, configDir, contextApiUrl, logsApiUrl, logFilesJson, enableBlockOnError, verbose, enableLsp, vueDevtoolsApiUrl, workspace) {
|
|
248
|
+
const env = {
|
|
249
|
+
...Object.fromEntries(
|
|
250
|
+
Object.entries(process.env).filter(([, v]) => v !== void 0)
|
|
251
|
+
),
|
|
252
|
+
XDG_STATE_HOME: stateDir,
|
|
253
|
+
// 指向缓存目录,OpenCode 通过 opencode.json 中 plugins 字段加载插件
|
|
254
|
+
OPENCODE_CONFIG_DIR: stateDir
|
|
255
|
+
};
|
|
256
|
+
if (configDir) {
|
|
257
|
+
env.OPENCODE_CONFIG_DIR = configDir;
|
|
258
|
+
log.debug("Set OPENCODE_CONFIG_DIR", { configDir });
|
|
259
|
+
}
|
|
260
|
+
if (contextApiUrl) {
|
|
261
|
+
env.OPENCODE_CONTEXT_API_URL = contextApiUrl;
|
|
262
|
+
log.debug("Set OPENCODE_CONTEXT_API_URL", { contextApiUrl });
|
|
263
|
+
}
|
|
264
|
+
if (logsApiUrl) {
|
|
265
|
+
env.OPENCODE_VITE_LOGS_API_URL = logsApiUrl;
|
|
266
|
+
log.debug("Set OPENCODE_VITE_LOGS_API_URL", { logsApiUrl });
|
|
267
|
+
}
|
|
268
|
+
if (logFilesJson) {
|
|
269
|
+
env.OPENCODE_LOG_FILES_JSON = logFilesJson;
|
|
270
|
+
log.debug("Set OPENCODE_LOG_FILES_JSON", { logFilesJson });
|
|
271
|
+
}
|
|
272
|
+
if (enableBlockOnError) {
|
|
273
|
+
env.OPENCODE_BLOCK_ON_ERROR = "1";
|
|
274
|
+
log.debug("Set OPENCODE_BLOCK_ON_ERROR=1");
|
|
275
|
+
}
|
|
276
|
+
if (verbose) {
|
|
277
|
+
env.OPENCODE_VERBOSE = "1";
|
|
278
|
+
log.debug("Set OPENCODE_VERBOSE=1");
|
|
279
|
+
}
|
|
280
|
+
if (enableLsp) {
|
|
281
|
+
env.OPENCODE_ENABLE_LINT = "1";
|
|
282
|
+
log.debug("Set OPENCODE_ENABLE_LINT=1");
|
|
283
|
+
}
|
|
284
|
+
if (vueDevtoolsApiUrl) {
|
|
285
|
+
env.OPENCODE_VUE_DEVTOOLS_API_URL = vueDevtoolsApiUrl;
|
|
286
|
+
log.debug("Set OPENCODE_VUE_DEVTOOLS_API_URL", { vueDevtoolsApiUrl });
|
|
287
|
+
}
|
|
288
|
+
if (workspace) {
|
|
289
|
+
env.OPENCODE_WORKSPACE = workspace;
|
|
290
|
+
log.debug("Set OPENCODE_WORKSPACE", { workspace });
|
|
291
|
+
}
|
|
292
|
+
if (isFormatServiceRunning()) {
|
|
293
|
+
env[import_node.ENV_VSCODE_PORT] = String(import_node.VSCODE_EXTENSION_PORT);
|
|
294
|
+
log.debug("Set OPENCODE_VSCODE_PORT");
|
|
295
|
+
}
|
|
296
|
+
return env;
|
|
297
|
+
}
|
|
298
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
299
|
+
0 && (module.exports = {
|
|
300
|
+
prepareOpenCodeRuntime,
|
|
301
|
+
startOpenCodeWeb
|
|
302
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ResultPromise } from "execa";
|
|
2
|
+
import type { WebOptions } from "./types";
|
|
3
|
+
export declare function prepareOpenCodeRuntime(cwd: string, vitePort: number, enableLsp?: boolean, enablePrettier?: boolean): string;
|
|
4
|
+
export declare function startOpenCodeWeb(options: WebOptions): ResultPromise;
|