@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,706 @@
|
|
|
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 bridge_script_exports = {};
|
|
19
|
+
__export(bridge_script_exports, {
|
|
20
|
+
generateBridgeScript: () => generateBridgeScript
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(bridge_script_exports);
|
|
23
|
+
var import_constants = require("./constants.cjs");
|
|
24
|
+
var import_core = require("@aipanel/core");
|
|
25
|
+
function mergeSettings(defaultSettings, userSettings) {
|
|
26
|
+
if (!userSettings) return defaultSettings;
|
|
27
|
+
const result = { ...defaultSettings };
|
|
28
|
+
if (userSettings.general) {
|
|
29
|
+
result.general = { ...defaultSettings.general, ...userSettings.general };
|
|
30
|
+
}
|
|
31
|
+
if (userSettings.appearance) {
|
|
32
|
+
result.appearance = userSettings.appearance;
|
|
33
|
+
}
|
|
34
|
+
if (userSettings.permissions) {
|
|
35
|
+
result.permissions = userSettings.permissions;
|
|
36
|
+
}
|
|
37
|
+
if (userSettings.notifications) {
|
|
38
|
+
result.notifications = userSettings.notifications;
|
|
39
|
+
}
|
|
40
|
+
if (userSettings.sounds) {
|
|
41
|
+
result.sounds = userSettings.sounds;
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
function generateBridgeScript(options = {}) {
|
|
46
|
+
const { theme = "auto", language, settings } = options;
|
|
47
|
+
const mergedSettings = mergeSettings(import_constants.DEFAULT_OPENCODE_SETTINGS, settings);
|
|
48
|
+
return `
|
|
49
|
+
(function() {
|
|
50
|
+
// \u7ACB\u5373\u6E05\u7406\u6B8B\u7559\u7684 session tabs \u5B58\u50A8\uFF0C\u5FC5\u987B\u5728 DOMContentLoaded \u4E4B\u524D\u6267\u884C
|
|
51
|
+
// \u5426\u5219 Web UI \u6A21\u5757\u811A\u672C\u4F1A\u5148\u8BFB\u53D6 localStorage \u5E76\u53D1\u51FA 404 \u8BF7\u6C42
|
|
52
|
+
(function cleanupTabsStorage() {
|
|
53
|
+
try {
|
|
54
|
+
var keysToRemove = [];
|
|
55
|
+
for (var i = 0; i < localStorage.length; i++) {
|
|
56
|
+
var key = localStorage.key(i);
|
|
57
|
+
if (key && (key.indexOf('opencode.window') === 0 || key.indexOf('opencode.workspace') === 0)) {
|
|
58
|
+
keysToRemove.push(key);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
for (var j = 0; j < keysToRemove.length; j++) {
|
|
62
|
+
localStorage.removeItem(keysToRemove[j]);
|
|
63
|
+
}
|
|
64
|
+
} catch (e) {
|
|
65
|
+
// localStorage \u4E0D\u53EF\u7528\u65F6\u5FFD\u7565
|
|
66
|
+
}
|
|
67
|
+
})();
|
|
68
|
+
|
|
69
|
+
// === \u52AB\u6301 matchMedia\uFF0C\u5F3A\u5236\u684C\u9762\u7AEF\u5E03\u5C40\u4EE5\u6E32\u67D3\u5BA1\u67E5\u9762\u677F ===
|
|
70
|
+
// \u53EA\u52AB\u6301 opencode \u5224\u65AD\u684C\u9762\u7AEF\u7684\u5A92\u4F53\u67E5\u8BE2 (min-width: 768px)\uFF0C\u4E0D\u5F71\u54CD\u5176\u4ED6\u67E5\u8BE2
|
|
71
|
+
(function() {
|
|
72
|
+
var _origMatchMedia = window.matchMedia.bind(window);
|
|
73
|
+
var DESKTOP_QUERY = '(min-width: 768px)';
|
|
74
|
+
window.matchMedia = function(query) {
|
|
75
|
+
var result = _origMatchMedia(query);
|
|
76
|
+
if (query === DESKTOP_QUERY) {
|
|
77
|
+
return {
|
|
78
|
+
get matches() { return true; },
|
|
79
|
+
get media() { return result.media; },
|
|
80
|
+
onchange: null,
|
|
81
|
+
addListener: function(cb) { result.addListener(cb); },
|
|
82
|
+
removeListener: function(cb) { result.removeListener(cb); },
|
|
83
|
+
addEventListener: function(t, cb) { result.addEventListener(t, cb); },
|
|
84
|
+
removeEventListener: function(t, cb) { result.removeEventListener(t, cb); },
|
|
85
|
+
dispatchEvent: function(e) { return result.dispatchEvent(e); }
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
};
|
|
90
|
+
})();
|
|
91
|
+
|
|
92
|
+
const STORAGE_KEYS = ${JSON.stringify(import_constants.OPENCODE_STORAGE_KEYS)};
|
|
93
|
+
const THEME_KEY = STORAGE_KEYS.COLOR_SCHEME;
|
|
94
|
+
const SETTINGS_KEY = STORAGE_KEYS.SETTINGS;
|
|
95
|
+
|
|
96
|
+
// === \u521D\u59CB\u5316\u914D\u7F6E ===
|
|
97
|
+
const initialConfig = {
|
|
98
|
+
theme: ${JSON.stringify(theme)},
|
|
99
|
+
language: ${JSON.stringify(language || null)},
|
|
100
|
+
settings: ${JSON.stringify(mergedSettings)}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// \u521D\u59CB\u5316\u4E3B\u9898
|
|
104
|
+
if (initialConfig.theme && initialConfig.theme !== "auto") {
|
|
105
|
+
localStorage.setItem(THEME_KEY, initialConfig.theme);
|
|
106
|
+
document.documentElement.setAttribute("data-color-scheme", initialConfig.theme);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// \u521D\u59CB\u5316\u8BBE\u7F6E
|
|
110
|
+
// \u6DF1\u5EA6\u5408\u5E76 initialConfig.settings \u5230\u5DF2\u6709\u914D\u7F6E\uFF1A\u53EA\u8986\u76D6\u63D2\u4EF6\u58F0\u660E\u7684\u5B57\u6BB5\uFF0C
|
|
111
|
+
// web \u81EA\u5DF1\u7BA1\u7406\u7684\u5176\u4ED6\u914D\u7F6E\u4E0D\u53D7\u5F71\u54CD
|
|
112
|
+
function deepMerge(target, source) {
|
|
113
|
+
for (var key in source) {
|
|
114
|
+
if (!{}.hasOwnProperty.call(source, key)) continue;
|
|
115
|
+
if (source[key] && typeof source[key] === "object" && !Array.isArray(source[key])) {
|
|
116
|
+
if (!target[key] || typeof target[key] !== "object") target[key] = {};
|
|
117
|
+
deepMerge(target[key], source[key]);
|
|
118
|
+
} else {
|
|
119
|
+
target[key] = source[key];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return target;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
var existing = JSON.parse(localStorage.getItem(SETTINGS_KEY) || "{}");
|
|
127
|
+
localStorage.setItem(SETTINGS_KEY, JSON.stringify(deepMerge(existing, initialConfig.settings)));
|
|
128
|
+
} catch {
|
|
129
|
+
localStorage.setItem(SETTINGS_KEY, JSON.stringify(initialConfig.settings));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// === \u4E3B\u9898\u540C\u6B65\u51FD\u6570 ===
|
|
133
|
+
function getTheme() {
|
|
134
|
+
try {
|
|
135
|
+
return localStorage.getItem(THEME_KEY) || "system";
|
|
136
|
+
} catch {
|
|
137
|
+
return "system";
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function setTheme(theme) {
|
|
142
|
+
try {
|
|
143
|
+
const oldTheme = localStorage.getItem(THEME_KEY);
|
|
144
|
+
localStorage.setItem(THEME_KEY, theme);
|
|
145
|
+
document.documentElement.setAttribute('data-color-scheme', theme);
|
|
146
|
+
|
|
147
|
+
if (oldTheme !== theme) {
|
|
148
|
+
window.dispatchEvent(new StorageEvent('storage', {
|
|
149
|
+
key: THEME_KEY,
|
|
150
|
+
oldValue: oldTheme,
|
|
151
|
+
newValue: theme,
|
|
152
|
+
url: window.location.href
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
} catch {
|
|
156
|
+
// ignore
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// === \u9009\u62E9\u6A21\u5F0F\u72B6\u6001 ===
|
|
161
|
+
let isInSelectMode = false;
|
|
162
|
+
|
|
163
|
+
function handleSelectModeChange(selectMode) {
|
|
164
|
+
isInSelectMode = selectMode;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// === \u6D88\u606F\u76D1\u542C ===
|
|
168
|
+
window.addEventListener("message", function(event) {
|
|
169
|
+
if (event.data && event.data.type === ${JSON.stringify(import_core.WIDGET_MSG.SET_THEME)}) {
|
|
170
|
+
setTheme(event.data.theme);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (event.data && event.data.type === ${JSON.stringify(import_core.WIDGET_MSG.INSERT_FILE_PART)}) {
|
|
174
|
+
insertFilePart(event.data.element);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (event.data && event.data.type === ${JSON.stringify(import_core.WIDGET_MSG.MINIMIZE_STATE)}) {
|
|
178
|
+
handleMinimizeStateChange(event.data.minimized);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (event.data && event.data.type === ${JSON.stringify(import_core.WIDGET_MSG.PROMPT_DOCK_VISIBILITY)}) {
|
|
182
|
+
handlePromptDockVisibilityChange(event.data.visible);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (event.data && event.data.type === ${JSON.stringify(import_core.WIDGET_MSG.SELECT_MODE_CHANGE)}) {
|
|
186
|
+
handleSelectModeChange(event.data.selectMode);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (event.data && event.data.type === ${JSON.stringify(import_core.WIDGET_MSG.REVIEW_PANEL_TOGGLE)}) {
|
|
190
|
+
handleReviewPanelToggle(event.data.visible);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// === \u952E\u76D8\u4E8B\u4EF6\u8F6C\u53D1\uFF08\u7528\u4E8E\u9000\u51FA\u9009\u62E9\u6A21\u5F0F\uFF09 ===
|
|
195
|
+
window.addEventListener("keydown", function(event) {
|
|
196
|
+
if (event.key === "Escape" || (event.ctrlKey && event.key.toLowerCase() === "p")) {
|
|
197
|
+
// \u9009\u62E9\u6A21\u5F0F\u5F00\u542F\u65F6\uFF0C\u4F18\u5148\u9000\u51FA\u9009\u62E9\u6A21\u5F0F\uFF0C\u963B\u6B62 iframe \u5185\u7684\u5176\u4ED6 ESC \u5904\u7406\uFF08\u5982\u4E2D\u6B62\u4F1A\u8BDD\uFF09
|
|
198
|
+
if (isInSelectMode) {
|
|
199
|
+
event.preventDefault();
|
|
200
|
+
event.stopPropagation();
|
|
201
|
+
if (window.parent !== window) {
|
|
202
|
+
window.parent.postMessage({
|
|
203
|
+
type: ${JSON.stringify(import_core.WIDGET_MSG.KEYDOWN)},
|
|
204
|
+
key: event.key,
|
|
205
|
+
ctrlKey: event.ctrlKey,
|
|
206
|
+
metaKey: event.metaKey,
|
|
207
|
+
shiftKey: event.shiftKey,
|
|
208
|
+
altKey: event.altKey
|
|
209
|
+
}, "*");
|
|
210
|
+
}
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
if (window.parent !== window) {
|
|
216
|
+
window.parent.postMessage({
|
|
217
|
+
type: ${JSON.stringify(import_core.WIDGET_MSG.KEYDOWN)},
|
|
218
|
+
key: event.key,
|
|
219
|
+
ctrlKey: event.ctrlKey,
|
|
220
|
+
metaKey: event.metaKey,
|
|
221
|
+
shiftKey: event.shiftKey,
|
|
222
|
+
altKey: event.altKey
|
|
223
|
+
}, "*");
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}, true);
|
|
227
|
+
|
|
228
|
+
// === \u6700\u5C0F\u5316\u72B6\u6001\u6837\u5F0F ===
|
|
229
|
+
const minimizeStyles = \`
|
|
230
|
+
#root header {
|
|
231
|
+
display: none !important;
|
|
232
|
+
}
|
|
233
|
+
.opencode-minimized [data-dock-surface="tray"]:not([data-slot="permission-footer"]) {
|
|
234
|
+
display: none !important;
|
|
235
|
+
}
|
|
236
|
+
.opencode-minimized [data-slot="session-turn-list"] {
|
|
237
|
+
padding-bottom: 10px !important;
|
|
238
|
+
}
|
|
239
|
+
.opencode-prompt-dock-hidden [data-component="session-prompt-dock"]:not(:has([data-kind="permission"])) {
|
|
240
|
+
display: none !important;
|
|
241
|
+
}
|
|
242
|
+
button[data-slot="dropdown-menu-trigger"][icon="dot-grid"] {
|
|
243
|
+
display: none !important;
|
|
244
|
+
}
|
|
245
|
+
[data-component="icon-button-v2"][aria-label="\u66F4\u591A\u9009\u9879"],
|
|
246
|
+
[data-component="icon-button-v2"][aria-label="More options"] {
|
|
247
|
+
display: none !important;
|
|
248
|
+
}
|
|
249
|
+
\`;
|
|
250
|
+
|
|
251
|
+
// === \u901A\u7528\u6837\u5F0F ===
|
|
252
|
+
const generalStyles = \`
|
|
253
|
+
/* \u9690\u85CF\u4F1A\u8BDD\u9762\u677F\u6807\u9898\u53F3\u4FA7\u6309\u94AE\u533A */
|
|
254
|
+
[data-session-title] .shrink-0 {
|
|
255
|
+
display: none !important;
|
|
256
|
+
}
|
|
257
|
+
\`;
|
|
258
|
+
|
|
259
|
+
// === \u5BA1\u67E5\u9762\u677F\u8986\u76D6\u6837\u5F0F ===
|
|
260
|
+
// \u5BA1\u67E5\u9762\u677F\u5168\u5C4F\uFF0C\u4F1A\u8BDD\u9762\u677F\u6D6E\u5728\u53F3\u4E0B\u89D2\uFF08\u7C7B\u4F3C\u63D2\u4EF6\u6700\u5C0F\u5316\u72B6\u6001\uFF09
|
|
261
|
+
const reviewPanelStyles = \`
|
|
262
|
+
.opencode-review-panel-overlay [data-ref="panel-row"] {
|
|
263
|
+
flex-direction: column !important;
|
|
264
|
+
gap: 8px !important;
|
|
265
|
+
padding: 8px !important;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/* \u5BA1\u67E5\u9762\u677F\u5360\u6EE1\u5269\u4F59\u7A7A\u95F4 */
|
|
269
|
+
.opencode-review-panel-overlay [data-ref="side-panel-container"] {
|
|
270
|
+
flex: 1 !important;
|
|
271
|
+
width: 100% !important;
|
|
272
|
+
transition: none !important;
|
|
273
|
+
min-height: 0 !important;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/* \u4F1A\u8BDD\u9762\u677F\u6D6E\u5728\u53F3\u4E0B\u89D2 */
|
|
277
|
+
.opencode-review-panel-overlay [data-ref="session-panel"] {
|
|
278
|
+
position: fixed !important;
|
|
279
|
+
bottom: 16px !important;
|
|
280
|
+
right: 16px !important;
|
|
281
|
+
width: 380px !important;
|
|
282
|
+
max-height: 70vh !important;
|
|
283
|
+
display: flex !important;
|
|
284
|
+
flex-direction: column !important;
|
|
285
|
+
z-index: 600 !important;
|
|
286
|
+
border-radius: 12px !important;
|
|
287
|
+
box-shadow:
|
|
288
|
+
0 0 0 1px rgba(0, 0, 0, 0.04),
|
|
289
|
+
0 2px 4px rgba(0, 0, 0, 0.04),
|
|
290
|
+
0 8px 16px rgba(0, 0, 0, 0.08),
|
|
291
|
+
0 16px 40px rgba(0, 0, 0, 0.12) !important;
|
|
292
|
+
overflow: hidden !important;
|
|
293
|
+
transition: none;
|
|
294
|
+
}
|
|
295
|
+
.opencode-review-panel-overlay [data-ref="session-panel"] * {
|
|
296
|
+
max-width: none !important;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/* \u4F1A\u8BDD\u6D6E\u7A97\u5185\u5C42\u80CC\u666F\u62AC\u9AD8\uFF0C\u4E0E\u5BA1\u67E5\u9762\u677F\u5E95\u8272\u5F62\u6210\u5C42\u6B21 */
|
|
300
|
+
.opencode-review-panel-overlay [data-ref="session-panel"] [class*="bg-v2-background-bg-base"] {
|
|
301
|
+
background: color-mix(in srgb, var(--v2-background-bg-base, #1e1e1e) 96%, #fff) !important;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/* \u9690\u85CF\u4F1A\u8BDD\u9762\u677F\u5185\u7684\u6807\u9898 */
|
|
305
|
+
.opencode-review-panel-overlay [data-ref="session-panel"] [data-session-title] {
|
|
306
|
+
display: none !important;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
/* \u9690\u85CF\u6D6E\u52A8\u4F1A\u8BDD\uFF08\u7528 visibility+opacity \u907F\u514D\u5207\u6362\u95EA\u70C1\uFF09 */
|
|
312
|
+
.opencode-review-panel-overlay.hide-chat [data-ref="session-panel"] {
|
|
313
|
+
visibility: hidden !important;
|
|
314
|
+
opacity: 0 !important;
|
|
315
|
+
pointer-events: none !important;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/* \u5BA1\u67E5\u9762\u677F\u53F3\u4E0A\u89D2\u60AC\u6D6E\u5207\u6362\u6309\u94AE */
|
|
319
|
+
.opencode-chat-toggle-btn {
|
|
320
|
+
position: fixed !important;
|
|
321
|
+
top: 16px !important;
|
|
322
|
+
right: 16px !important;
|
|
323
|
+
z-index: 700 !important;
|
|
324
|
+
width: 36px !important;
|
|
325
|
+
height: 36px !important;
|
|
326
|
+
border-radius: 8px !important;
|
|
327
|
+
border: none !important;
|
|
328
|
+
background: var(--v2-background-bg-base, #1e1e1e) !important;
|
|
329
|
+
color: var(--v2-icon-icon-base, #ccc) !important;
|
|
330
|
+
cursor: pointer !important;
|
|
331
|
+
display: flex !important;
|
|
332
|
+
align-items: center !important;
|
|
333
|
+
justify-content: center !important;
|
|
334
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
|
|
335
|
+
transition: background 0.15s !important;
|
|
336
|
+
}
|
|
337
|
+
.opencode-chat-toggle-btn:hover {
|
|
338
|
+
background: var(--v2-overlay-simple-overlay-hover, #333) !important;
|
|
339
|
+
}
|
|
340
|
+
.opencode-chat-toggle-btn.active {
|
|
341
|
+
background: var(--v2-overlay-simple-overlay-pressed, #444) !important;
|
|
342
|
+
}
|
|
343
|
+
\`;
|
|
344
|
+
|
|
345
|
+
function injectMinimizeStyles() {
|
|
346
|
+
if (document.getElementById('opencode-minimize-styles')) return;
|
|
347
|
+
const style = document.createElement('style');
|
|
348
|
+
style.id = 'opencode-minimize-styles';
|
|
349
|
+
style.textContent = minimizeStyles;
|
|
350
|
+
document.head.appendChild(style);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function injectReviewPanelStyles() {
|
|
354
|
+
if (document.getElementById('opencode-review-panel-styles')) return;
|
|
355
|
+
const style = document.createElement('style');
|
|
356
|
+
style.id = 'opencode-review-panel-styles';
|
|
357
|
+
style.textContent = reviewPanelStyles;
|
|
358
|
+
document.head.appendChild(style);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function injectGeneralStyles() {
|
|
362
|
+
if (document.getElementById('opencode-general-styles')) return;
|
|
363
|
+
const style = document.createElement('style');
|
|
364
|
+
style.id = 'opencode-general-styles';
|
|
365
|
+
style.textContent = generalStyles;
|
|
366
|
+
document.head.appendChild(style);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// === \u6700\u5C0F\u5316\u72B6\u6001\u5904\u7406 ===
|
|
370
|
+
let savedMinimizedState = null;
|
|
371
|
+
let savedPromptDockVisibleState = null;
|
|
372
|
+
let savedReviewPanelState = null;
|
|
373
|
+
|
|
374
|
+
function handleMinimizeStateChange(minimized) {
|
|
375
|
+
savedMinimizedState = minimized;
|
|
376
|
+
if (minimized) {
|
|
377
|
+
document.documentElement.classList.add('opencode-minimized');
|
|
378
|
+
} else {
|
|
379
|
+
document.documentElement.classList.remove('opencode-minimized');
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// === \u5BF9\u8BDD\u6846\u663E\u793A\u72B6\u6001\u5904\u7406 ===
|
|
384
|
+
function handlePromptDockVisibilityChange(visible) {
|
|
385
|
+
savedPromptDockVisibleState = visible;
|
|
386
|
+
if (!visible) {
|
|
387
|
+
document.documentElement.classList.add('opencode-prompt-dock-hidden');
|
|
388
|
+
} else {
|
|
389
|
+
document.documentElement.classList.remove('opencode-prompt-dock-hidden');
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// === \u5BA1\u67E5\u9762\u677F\u8986\u76D6\u72B6\u6001\u5904\u7406 ===
|
|
394
|
+
// \u7B56\u7565\uFF1A\u7EAF CSS class \u63A7\u5236\u3002\u9996\u6B21\u6253\u5F00\u65F6\u7ED9\u5173\u952E\u5143\u7D20\u6253 data-ref \u6807\u8BB0\uFF0C
|
|
395
|
+
// \u540E\u7EED\u53EA\u9700 toggle class\u3002\u5173\u95ED\u65F6\u79FB\u9664 class\uFF0CCSS \u89C4\u5219\u81EA\u52A8\u6062\u590D\u539F\u59CB\u5E03\u5C40\u3002
|
|
396
|
+
// \u4E0D\u4FEE\u6539\u4EFB\u4F55 inline style\uFF0C\u907F\u514D\u4FDD\u5B58/\u6062\u590D\u7684\u65F6\u673A\u548C DOM \u5F15\u7528\u95EE\u9898\u3002
|
|
397
|
+
|
|
398
|
+
function ensureReviewPanelRefs() {
|
|
399
|
+
var reviewPanel = document.querySelector('[data-component="session-review-v2"]')
|
|
400
|
+
|| document.querySelector('[data-component="session-review"]');
|
|
401
|
+
if (!reviewPanel) return false;
|
|
402
|
+
|
|
403
|
+
// \u5411\u4E0A\u904D\u5386\u627E\u5230 panelRow
|
|
404
|
+
var panelRow = reviewPanel.parentElement;
|
|
405
|
+
while (panelRow) {
|
|
406
|
+
var cls = panelRow.className || '';
|
|
407
|
+
if (cls.indexOf('flex-col') !== -1 && cls.indexOf('md:flex-row') !== -1) break;
|
|
408
|
+
panelRow = panelRow.parentElement;
|
|
409
|
+
}
|
|
410
|
+
if (!panelRow) return false;
|
|
411
|
+
panelRow.setAttribute('data-ref', 'panel-row');
|
|
412
|
+
|
|
413
|
+
// \u627E\u5230\u4F1A\u8BDD\u9762\u677F\u548C\u4FA7\u8FB9\u9762\u677F\u5BB9\u5668
|
|
414
|
+
for (var i = 0; i < panelRow.children.length; i++) {
|
|
415
|
+
var child = panelRow.children[i];
|
|
416
|
+
if (child.nodeType !== 1) continue;
|
|
417
|
+
var c = child.className || '';
|
|
418
|
+
if (c.indexOf('@container') !== -1) {
|
|
419
|
+
child.setAttribute('data-ref', 'session-panel');
|
|
420
|
+
} else if (c.indexOf('min-w-0') !== -1 && c.indexOf('flex-col') !== -1) {
|
|
421
|
+
child.setAttribute('data-ref', 'side-panel-container');
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function injectChatToggleBtn() {
|
|
429
|
+
if (document.getElementById('opencode-chat-toggle-btn')) return;
|
|
430
|
+
var btn = document.createElement('button');
|
|
431
|
+
btn.id = 'opencode-chat-toggle-btn';
|
|
432
|
+
btn.className = 'opencode-chat-toggle-btn';
|
|
433
|
+
btn.innerHTML = '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>';
|
|
434
|
+
btn.title = '\u5C55\u5F00\u804A\u5929\u9762\u677F';
|
|
435
|
+
// \u4ECE localStorage \u6062\u590D\u4E0A\u6B21\u7684\u5C55\u5F00/\u6536\u8D77\u72B6\u6001\uFF0C\u9ED8\u8BA4\u6536\u8D77
|
|
436
|
+
var chatVisible = localStorage.getItem('opencode-review-chat-visible');
|
|
437
|
+
if (chatVisible === 'true') {
|
|
438
|
+
document.documentElement.classList.remove('hide-chat');
|
|
439
|
+
btn.classList.add('active');
|
|
440
|
+
btn.title = '\u9690\u85CF\u804A\u5929\u9762\u677F';
|
|
441
|
+
} else {
|
|
442
|
+
document.documentElement.classList.add('hide-chat');
|
|
443
|
+
}
|
|
444
|
+
btn.onclick = function() {
|
|
445
|
+
document.documentElement.classList.toggle('hide-chat');
|
|
446
|
+
btn.classList.toggle('active');
|
|
447
|
+
var isVisible = btn.classList.contains('active');
|
|
448
|
+
btn.title = isVisible ? '\u9690\u85CF\u804A\u5929\u9762\u677F' : '\u5C55\u5F00\u804A\u5929\u9762\u677F';
|
|
449
|
+
localStorage.setItem('opencode-review-chat-visible', isVisible ? 'true' : 'false');
|
|
450
|
+
};
|
|
451
|
+
document.body.appendChild(btn);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function removeChatToggleBtn() {
|
|
455
|
+
var btn = document.getElementById('opencode-chat-toggle-btn');
|
|
456
|
+
if (btn) btn.remove();
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function handleReviewPanelToggle(visible) {
|
|
460
|
+
// \u5982\u679C\u72B6\u6001\u6CA1\u6709\u53D8\u5316\uFF0C\u8DF3\u8FC7\uFF08\u907F\u514D MutationObserver \u91CD\u590D\u89E6\u53D1\uFF09
|
|
461
|
+
if (savedReviewPanelState === visible) return;
|
|
462
|
+
savedReviewPanelState = visible;
|
|
463
|
+
|
|
464
|
+
if (visible) {
|
|
465
|
+
// \u5148\u70B9\u51FB\u539F\u751F\u6309\u94AE\u6253\u5F00\u9762\u677F\uFF0C\u8BA9 DOM \u6E32\u67D3\u51FA\u6765
|
|
466
|
+
var reviewBtn = document.querySelector('[aria-controls="review-panel"]');
|
|
467
|
+
if (reviewBtn && reviewBtn.getAttribute('aria-expanded') !== 'true') {
|
|
468
|
+
reviewBtn.click();
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// \u7B49 DOM \u5C31\u7EEA\u540E\u6253\u6807\u8BB0\u5E76\u5E94\u7528 CSS
|
|
472
|
+
var attempts = 0;
|
|
473
|
+
function tryApply() {
|
|
474
|
+
if (ensureReviewPanelRefs()) {
|
|
475
|
+
document.documentElement.classList.add('opencode-review-panel-overlay');
|
|
476
|
+
injectChatToggleBtn();
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
attempts++;
|
|
480
|
+
if (attempts < 20) requestAnimationFrame(tryApply);
|
|
481
|
+
}
|
|
482
|
+
requestAnimationFrame(tryApply);
|
|
483
|
+
} else {
|
|
484
|
+
// \u5173\u95ED\u524D\u5148\u5C06\u4F1A\u8BDD\u9762\u677F\u5BBD\u5EA6\u8BBE\u4E3A 100%\uFF0C\u907F\u514D SolidJS \u5F02\u6B65\u6E32\u67D3\u7684\u5BBD\u5EA6\u8DF3\u53D8
|
|
485
|
+
var sessionPanel = document.querySelector('[data-ref="session-panel"]');
|
|
486
|
+
if (sessionPanel) sessionPanel.style.width = '100%';
|
|
487
|
+
document.body.offsetHeight; // \u5F3A\u5236\u56DE\u6D41
|
|
488
|
+
|
|
489
|
+
document.documentElement.classList.remove('opencode-review-panel-overlay');
|
|
490
|
+
document.documentElement.classList.remove('hide-chat');
|
|
491
|
+
removeChatToggleBtn();
|
|
492
|
+
|
|
493
|
+
// \u7B49\u4E00\u5E27\u8BA9 CSS \u5E03\u5C40\u53D8\u5316\u5148\u6E32\u67D3\uFF0C\u518D\u5173\u95ED\u539F\u751F\u9762\u677F
|
|
494
|
+
// \u907F\u514D SolidJS \u5F02\u6B65 DOM \u53D8\u5316\u548C CSS \u5E03\u5C40\u53D8\u5316\u53D1\u751F\u5728\u540C\u4E00\u5E27\u5BFC\u81F4\u89C6\u89C9\u8DF3\u52A8
|
|
495
|
+
requestAnimationFrame(function() {
|
|
496
|
+
var reviewBtn = document.querySelector('[aria-controls="review-panel"]');
|
|
497
|
+
if (reviewBtn && reviewBtn.getAttribute('aria-expanded') === 'true') {
|
|
498
|
+
reviewBtn.click();
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// === \u5E94\u7528\u4FDD\u5B58\u7684\u72B6\u6001 ===
|
|
505
|
+
function applySavedStates() {
|
|
506
|
+
if (savedMinimizedState !== null) {
|
|
507
|
+
handleMinimizeStateChange(savedMinimizedState);
|
|
508
|
+
}
|
|
509
|
+
if (savedPromptDockVisibleState !== null) {
|
|
510
|
+
handlePromptDockVisibilityChange(savedPromptDockVisibleState);
|
|
511
|
+
}
|
|
512
|
+
if (savedReviewPanelState !== null) {
|
|
513
|
+
handleReviewPanelToggle(savedReviewPanelState);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// === \u4FDD\u5B58\u8F93\u5165\u6846\u5149\u6807\u4F4D\u7F6E ===
|
|
518
|
+
let savedRange = null;
|
|
519
|
+
|
|
520
|
+
function setupPromptInputListener() {
|
|
521
|
+
const promptInput = document.querySelector('[data-component="prompt-input"]');
|
|
522
|
+
if (!promptInput) return;
|
|
523
|
+
|
|
524
|
+
promptInput.addEventListener('blur', function() {
|
|
525
|
+
const selection = window.getSelection();
|
|
526
|
+
if (selection && selection.rangeCount > 0) {
|
|
527
|
+
const range = selection.getRangeAt(0);
|
|
528
|
+
if (promptInput.contains(range.commonAncestorContainer)) {
|
|
529
|
+
savedRange = range.cloneRange();
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
promptInput.addEventListener('focus', function() {
|
|
535
|
+
savedRange = null;
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// === \u63D2\u5165 File Part \u5230\u8F93\u5165\u6846 ===
|
|
540
|
+
function insertFilePart(element) {
|
|
541
|
+
const promptInput = document.querySelector('[data-component="prompt-input"]');
|
|
542
|
+
if (!promptInput) {
|
|
543
|
+
console.warn('Prompt input not found');
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
const { filePath, line, column, description, innerText, previewPageUrl, previewPageTitle } = element;
|
|
548
|
+
|
|
549
|
+
const selector = description || 'element';
|
|
550
|
+
let textPreview = '';
|
|
551
|
+
if (innerText && innerText.trim()) {
|
|
552
|
+
const trimmed = innerText.trim();
|
|
553
|
+
textPreview = trimmed.length > 5 ? trimmed.substring(0, 5) + '...' : trimmed;
|
|
554
|
+
}
|
|
555
|
+
const displayText = '@' + selector + (textPreview ? '(' + textPreview + ')' : '');
|
|
556
|
+
|
|
557
|
+
const jsonStr = JSON.stringify({
|
|
558
|
+
nodeContext: {
|
|
559
|
+
"filePath": {
|
|
560
|
+
"value": filePath ?? '\u672A\u77E5',
|
|
561
|
+
"desc": "\u6E90\u7801\u6587\u4EF6\u8DEF\u5F84"
|
|
562
|
+
},
|
|
563
|
+
"line": {
|
|
564
|
+
"value": line ?? '\u672A\u77E5',
|
|
565
|
+
"desc": "\u4EE3\u7801\u6240\u5728\u884C\u53F7"
|
|
566
|
+
},
|
|
567
|
+
"column": {
|
|
568
|
+
"value": column ?? '\u672A\u77E5',
|
|
569
|
+
"desc": "\u4EE3\u7801\u6240\u5728\u5217\u53F7"
|
|
570
|
+
},
|
|
571
|
+
"description": {
|
|
572
|
+
"value": description ?? '\u672A\u77E5',
|
|
573
|
+
"desc": "DOM \u5143\u7D20\u9009\u62E9\u5668"
|
|
574
|
+
},
|
|
575
|
+
"innerText": {
|
|
576
|
+
"value": innerText ? innerText.substring(0, 500) : '',
|
|
577
|
+
"desc": "DOM \u5143\u7D20\u5185\u90E8\u6587\u672C"
|
|
578
|
+
},
|
|
579
|
+
"selectAt": {
|
|
580
|
+
"value": previewPageUrl || '\u672A\u77E5',
|
|
581
|
+
"desc": "\u7528\u6237\u9009\u4E2D\u8282\u70B9\u65F6\u7684\u9875\u9762 URL"
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
const span = document.createElement('span');
|
|
587
|
+
span.setAttribute('data-mention', 'file');
|
|
588
|
+
span.setAttribute('data-path', jsonStr);
|
|
589
|
+
span.setAttribute('contenteditable', 'false');
|
|
590
|
+
|
|
591
|
+
span.textContent = displayText;
|
|
592
|
+
|
|
593
|
+
if (savedRange) {
|
|
594
|
+
const range = savedRange;
|
|
595
|
+
range.collapse(false);
|
|
596
|
+
range.insertNode(span);
|
|
597
|
+
|
|
598
|
+
const space = document.createTextNode('\\u00A0');
|
|
599
|
+
span.parentNode.insertBefore(space, span.nextSibling);
|
|
600
|
+
|
|
601
|
+
const newRange = document.createRange();
|
|
602
|
+
newRange.setStartAfter(space);
|
|
603
|
+
newRange.collapse(true);
|
|
604
|
+
|
|
605
|
+
promptInput.focus();
|
|
606
|
+
|
|
607
|
+
const selection = window.getSelection();
|
|
608
|
+
if (selection) {
|
|
609
|
+
selection.removeAllRanges();
|
|
610
|
+
selection.addRange(newRange);
|
|
611
|
+
}
|
|
612
|
+
savedRange = null;
|
|
613
|
+
|
|
614
|
+
promptInput.dispatchEvent(new Event('input', { bubbles: true }));
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
const selection = window.getSelection();
|
|
619
|
+
if (selection && selection.rangeCount > 0) {
|
|
620
|
+
const range = selection.getRangeAt(0);
|
|
621
|
+
|
|
622
|
+
if (promptInput.contains(range.commonAncestorContainer)) {
|
|
623
|
+
range.collapse(false);
|
|
624
|
+
range.insertNode(span);
|
|
625
|
+
|
|
626
|
+
const space = document.createTextNode('\\u00A0');
|
|
627
|
+
span.parentNode.insertBefore(space, span.nextSibling);
|
|
628
|
+
|
|
629
|
+
const newRange = document.createRange();
|
|
630
|
+
newRange.setStartAfter(space);
|
|
631
|
+
newRange.collapse(true);
|
|
632
|
+
selection.removeAllRanges();
|
|
633
|
+
selection.addRange(newRange);
|
|
634
|
+
|
|
635
|
+
promptInput.dispatchEvent(new Event('input', { bubbles: true }));
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
promptInput.appendChild(span);
|
|
641
|
+
const space = document.createTextNode('\\u00A0');
|
|
642
|
+
promptInput.appendChild(space);
|
|
643
|
+
|
|
644
|
+
const newRange = document.createRange();
|
|
645
|
+
newRange.setStartAfter(space);
|
|
646
|
+
newRange.collapse(true);
|
|
647
|
+
const newSelection = window.getSelection();
|
|
648
|
+
if (newSelection) {
|
|
649
|
+
newSelection.removeAllRanges();
|
|
650
|
+
newSelection.addRange(newRange);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
promptInput.dispatchEvent(new Event('input', { bubbles: true }));
|
|
654
|
+
promptInput.focus();
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// === \u5C31\u7EEA\u901A\u77E5 ===
|
|
658
|
+
function init() {
|
|
659
|
+
injectMinimizeStyles();
|
|
660
|
+
injectReviewPanelStyles();
|
|
661
|
+
injectGeneralStyles();
|
|
662
|
+
setupPromptInputListener();
|
|
663
|
+
applySavedStates();
|
|
664
|
+
|
|
665
|
+
let readySent = false;
|
|
666
|
+
function trySendReady() {
|
|
667
|
+
if (readySent) return;
|
|
668
|
+
const promptInput = document.querySelector('[data-component="prompt-input"]');
|
|
669
|
+
if (promptInput && window.parent !== window) {
|
|
670
|
+
window.parent.postMessage({ type: ${JSON.stringify(import_core.WIDGET_MSG.READY)} }, "*");
|
|
671
|
+
readySent = true;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
trySendReady();
|
|
675
|
+
|
|
676
|
+
const observer = new MutationObserver(function(mutations) {
|
|
677
|
+
trySendReady();
|
|
678
|
+
|
|
679
|
+
const promptInput = document.querySelector('[data-component="prompt-input"]');
|
|
680
|
+
if (promptInput && !promptInput._aipanelListenerAttached) {
|
|
681
|
+
setupPromptInputListener();
|
|
682
|
+
promptInput._aipanelListenerAttached = true;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// \u5F53\u76EE\u6807\u5143\u7D20\u51FA\u73B0\u65F6\u5E94\u7528\u4FDD\u5B58\u7684\u72B6\u6001
|
|
686
|
+
const promptDock = document.querySelector('[data-component="session-prompt-dock"]');
|
|
687
|
+
const dockSurface = document.querySelector('[data-dock-surface="tray"]');
|
|
688
|
+
if (promptDock || dockSurface) {
|
|
689
|
+
applySavedStates();
|
|
690
|
+
}
|
|
691
|
+
});
|
|
692
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
if (document.readyState === 'loading') {
|
|
696
|
+
document.addEventListener('DOMContentLoaded', init);
|
|
697
|
+
} else {
|
|
698
|
+
init();
|
|
699
|
+
}
|
|
700
|
+
})();
|
|
701
|
+
`;
|
|
702
|
+
}
|
|
703
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
704
|
+
0 && (module.exports = {
|
|
705
|
+
generateBridgeScript
|
|
706
|
+
});
|