vite-plugin-opencode-assistant 1.0.16 → 1.0.17
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/client/App.vue.js +30 -13
- package/es/core/api.js +46 -45
- package/es/core/proxy-server.js +139 -0
- package/lib/client/App.vue.js +28 -13
- package/lib/client.js +2537 -2381
- package/lib/core/api.js +46 -45
- package/lib/core/proxy-server.js +139 -0
- package/lib/style.css +1 -1
- package/package.json +4 -4
package/es/client/App.vue.js
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1
20
|
var __async = (__this, __arguments, generator) => {
|
|
2
21
|
return new Promise((resolve, reject) => {
|
|
3
22
|
var fulfilled = (value) => {
|
|
@@ -52,9 +71,9 @@ const __vue_sfc__ = /* @__PURE__ */ _defineComponent({
|
|
|
52
71
|
} = props.config;
|
|
53
72
|
const widgetPosition = position;
|
|
54
73
|
const widgetTheme = initialTheme;
|
|
55
|
-
const showNotification = (msg) => {
|
|
74
|
+
const showNotification = (msg, options) => {
|
|
56
75
|
var _a, _b;
|
|
57
|
-
(_b = (_a = widgetRef.value) == null ? void 0 : _a.showNotification) == null ? void 0 : _b.call(_a, msg);
|
|
76
|
+
(_b = (_a = widgetRef.value) == null ? void 0 : _a.showNotification) == null ? void 0 : _b.call(_a, msg, options);
|
|
58
77
|
};
|
|
59
78
|
const {
|
|
60
79
|
serviceStatus,
|
|
@@ -69,7 +88,6 @@ const __vue_sfc__ = /* @__PURE__ */ _defineComponent({
|
|
|
69
88
|
} = useServiceStatus();
|
|
70
89
|
const {
|
|
71
90
|
selectedElements,
|
|
72
|
-
addElement,
|
|
73
91
|
removeElement,
|
|
74
92
|
clearElements
|
|
75
93
|
} = useSelectedElements();
|
|
@@ -204,13 +222,13 @@ const __vue_sfc__ = /* @__PURE__ */ _defineComponent({
|
|
|
204
222
|
}
|
|
205
223
|
});
|
|
206
224
|
const handleSelectNode = (element) => {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
}
|
|
225
|
+
var _a;
|
|
226
|
+
const elementWithContext = __spreadProps(__spreadValues({}, element), {
|
|
227
|
+
previewPageUrl: window.location.href,
|
|
228
|
+
previewPageTitle: document.title
|
|
229
|
+
});
|
|
230
|
+
(_a = widgetRef.value) == null ? void 0 : _a.sendMessageToIframe("OPENCODE_INSERT_FILE_PART", { element: elementWithContext });
|
|
231
|
+
showNotification(`\u8282\u70B9\u5DF2\u6DFB\u52A0\u5230\u5BF9\u8BDD\u6846`, { mode: "page" });
|
|
214
232
|
};
|
|
215
233
|
const handleClearSelected = () => {
|
|
216
234
|
clearElements();
|
|
@@ -236,7 +254,7 @@ const __vue_sfc__ = /* @__PURE__ */ _defineComponent({
|
|
|
236
254
|
const handleFrameLoaded = () => {
|
|
237
255
|
iframeLoading.value = false;
|
|
238
256
|
};
|
|
239
|
-
const __returned__ = { props, open, selectMode, sessionListCollapsed, loading, widgetRef, retryingWarmup, position, initialTheme, autoOpen, hotkey, widgetPosition, widgetTheme, showNotification, serviceStatus, chromeMcpFailed, chromeMcpErrorType, chromeMcpErrorMessage, thinking, loadingText, updateStatusFromTask, setStarting, setThinking, selectedElements,
|
|
257
|
+
const __returned__ = { props, open, selectMode, sessionListCollapsed, loading, widgetRef, retryingWarmup, position, initialTheme, autoOpen, hotkey, widgetPosition, widgetTheme, showNotification, serviceStatus, chromeMcpFailed, chromeMcpErrorType, chromeMcpErrorMessage, thinking, loadingText, updateStatusFromTask, setStarting, setThinking, selectedElements, removeElement, clearElements, theme, sendThemeToIframe, sessions, loadingSessionList, currentSessionId, iframeSrc, iframeLoading, loadSessions, createSession, deleteSession, selectSession, updateContext, showSessionListSkeleton, computedLoading, retryWarmup, setupSSE, ensureServicesStarted, handleToggle, handleSelectNode, handleClearSelected, handleSelectModeChange, handleSessionListCollapsedChange, handleThemeChange, handleRemoveSelectedNode, handleFrameLoaded, get OpenCodeWidget() {
|
|
240
258
|
return OpenCodeWidget;
|
|
241
259
|
}, LoadingContent, ChromeWarmupError };
|
|
242
260
|
Object.defineProperty(__returned__, "__isScriptSetup", { enumerable: false, value: true });
|
|
@@ -260,7 +278,6 @@ function __vue_render__(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
260
278
|
"current-session-id": $setup.currentSessionId,
|
|
261
279
|
sessions: $setup.sessions,
|
|
262
280
|
"session-key": "id",
|
|
263
|
-
"selected-elements": $setup.selectedElements,
|
|
264
281
|
"hotkey-label": $setup.hotkey,
|
|
265
282
|
thinking: $setup.thinking,
|
|
266
283
|
"onUpdate:open": $setup.handleToggle,
|
|
@@ -291,7 +308,7 @@ function __vue_render__(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
291
308
|
]),
|
|
292
309
|
_: 1
|
|
293
310
|
/* STABLE */
|
|
294
|
-
}, 8, ["position", "theme", "open", "select-mode", "session-list-collapsed", "frame-loading", "loading-session-list", "show-session-list-skeleton", "show-error", "iframe-src", "current-session-id", "sessions", "
|
|
311
|
+
}, 8, ["position", "theme", "open", "select-mode", "session-list-collapsed", "frame-loading", "loading-session-list", "show-session-list-skeleton", "show-error", "iframe-src", "current-session-id", "sessions", "hotkey-label", "thinking", "onCreateSession", "onDeleteSession", "onSelectSession", "onEmptyAction"]);
|
|
295
312
|
}
|
|
296
313
|
__vue_sfc__.render = __vue_render__;
|
|
297
314
|
var App_vue_default = __vue_sfc__;
|
package/es/core/api.js
CHANGED
|
@@ -205,6 +205,7 @@ class OpenCodeAPI {
|
|
|
205
205
|
const connectedProviders = new Set(response.connected);
|
|
206
206
|
const allModels = [];
|
|
207
207
|
for (const provider of response.all) {
|
|
208
|
+
if (provider.id === "opencode") continue;
|
|
208
209
|
if (!connectedProviders.has(provider.id)) {
|
|
209
210
|
log.debug("Skipping not connected provider", { providerID: provider.id });
|
|
210
211
|
continue;
|
|
@@ -214,7 +215,8 @@ class OpenCodeAPI {
|
|
|
214
215
|
providerID: provider.id,
|
|
215
216
|
modelID,
|
|
216
217
|
name: model.name,
|
|
217
|
-
inputCost: (_b = (_a = model.cost) == null ? void 0 : _a.input) != null ? _b : 0
|
|
218
|
+
inputCost: (_b = (_a = model.cost) == null ? void 0 : _a.input) != null ? _b : 0,
|
|
219
|
+
releaseDate: model.release_date
|
|
218
220
|
});
|
|
219
221
|
}
|
|
220
222
|
}
|
|
@@ -235,6 +237,7 @@ class OpenCodeAPI {
|
|
|
235
237
|
modelID: availableModel.modelID,
|
|
236
238
|
name: availableModel.name,
|
|
237
239
|
inputCost: availableModel.inputCost,
|
|
240
|
+
releaseDate: availableModel.releaseDate,
|
|
238
241
|
totalModels: allModels.length,
|
|
239
242
|
failedModels: this.failedFreeModels.size,
|
|
240
243
|
connectedProviders: response.connected
|
|
@@ -347,15 +350,6 @@ class OpenCodeAPI {
|
|
|
347
350
|
"__chrome_mcp_warmup__"
|
|
348
351
|
);
|
|
349
352
|
warmupSessionId = warmupSession.id;
|
|
350
|
-
const prompt = [
|
|
351
|
-
"Call the browser tool list_pages immediately to establish the Chrome DevTools MCP connection.",
|
|
352
|
-
viteOrigin ? `If there are no pages, call new_page with ${viteOrigin}.` : "If there are no pages, call new_page with about:blank.",
|
|
353
|
-
"Do not read or modify project files.",
|
|
354
|
-
"Do not use any non-browser tools.",
|
|
355
|
-
"After the tool call is complete, reply with exactly: ready",
|
|
356
|
-
"If the tool call fails, reply with exactly: fail"
|
|
357
|
-
].join(" ");
|
|
358
|
-
const WARMUP_TIMEOUT = 6e4;
|
|
359
353
|
freeModel = yield this.getCheapestModel();
|
|
360
354
|
if (freeModel) {
|
|
361
355
|
log.debug("Using cheapest model for warmup", {
|
|
@@ -365,6 +359,7 @@ class OpenCodeAPI {
|
|
|
365
359
|
} else {
|
|
366
360
|
log.debug("No model available, using default model");
|
|
367
361
|
}
|
|
362
|
+
const WARMUP_TIMEOUT = 6e4;
|
|
368
363
|
const data = yield this.createHttpRequest(
|
|
369
364
|
{
|
|
370
365
|
hostname: this.hostname,
|
|
@@ -374,8 +369,12 @@ class OpenCodeAPI {
|
|
|
374
369
|
headers: { "Content-Type": "application/json" }
|
|
375
370
|
},
|
|
376
371
|
JSON.stringify(__spreadValues({
|
|
377
|
-
|
|
378
|
-
|
|
372
|
+
parts: [
|
|
373
|
+
{
|
|
374
|
+
type: "text",
|
|
375
|
+
text: "Test if the chrome-devtools_list_pages tool is available. If available, reply with: ready. If not available, explain why."
|
|
376
|
+
}
|
|
377
|
+
]
|
|
379
378
|
}, freeModel && {
|
|
380
379
|
model: {
|
|
381
380
|
providerID: freeModel.providerID,
|
|
@@ -393,13 +392,6 @@ class OpenCodeAPI {
|
|
|
393
392
|
);
|
|
394
393
|
}
|
|
395
394
|
const lowerResponse = responseText.toLowerCase();
|
|
396
|
-
if (lowerResponse.includes("fail")) {
|
|
397
|
-
throw new ChromeMcpWarmupError(
|
|
398
|
-
ChromeMcpWarmupErrorType.CHROME_NOT_CONNECTED,
|
|
399
|
-
"Chrome DevTools MCP is not connected",
|
|
400
|
-
"AI reported that browser tools are not available. This should not happen if Chrome DevTools check passed."
|
|
401
|
-
);
|
|
402
|
-
}
|
|
403
395
|
if (!lowerResponse.includes("ready")) {
|
|
404
396
|
throw new ChromeMcpWarmupError(
|
|
405
397
|
ChromeMcpWarmupErrorType.AI_RESPONSE_ERROR,
|
|
@@ -413,10 +405,12 @@ class OpenCodeAPI {
|
|
|
413
405
|
if (e.type === ChromeMcpWarmupErrorType.SESSION_ERROR) {
|
|
414
406
|
timer.end("Session creation failed");
|
|
415
407
|
}
|
|
416
|
-
log.warn(`Chrome MCP warmup failed: ${e.type}`, {
|
|
408
|
+
log.warn(`Chrome MCP warmup failed: ${e.type}`, __spreadValues({
|
|
417
409
|
message: e.message,
|
|
418
410
|
details: e.details
|
|
419
|
-
}
|
|
411
|
+
}, freeModel && {
|
|
412
|
+
model: `${freeModel.providerID}/${freeModel.modelID}`
|
|
413
|
+
}));
|
|
420
414
|
timer.end(`Chrome MCP warmup failed: ${e.type}`);
|
|
421
415
|
throw e;
|
|
422
416
|
}
|
|
@@ -435,7 +429,11 @@ class OpenCodeAPI {
|
|
|
435
429
|
"AI response timeout",
|
|
436
430
|
"AI did not respond within 30 seconds. Please check if the OpenCode AI model is properly configured and available."
|
|
437
431
|
);
|
|
438
|
-
log.warn("Chrome MCP warmup timeout", {
|
|
432
|
+
log.warn("Chrome MCP warmup timeout", __spreadValues({
|
|
433
|
+
error: errorMessage
|
|
434
|
+
}, freeModel && {
|
|
435
|
+
model: `${freeModel.providerID}/${freeModel.modelID}`
|
|
436
|
+
}));
|
|
439
437
|
timer.end("Chrome MCP warmup timeout");
|
|
440
438
|
throw error2;
|
|
441
439
|
}
|
|
@@ -444,7 +442,11 @@ class OpenCodeAPI {
|
|
|
444
442
|
"Unknown error during Chrome MCP warmup",
|
|
445
443
|
errorMessage
|
|
446
444
|
);
|
|
447
|
-
log.warn("Chrome MCP warmup failed with unknown error", {
|
|
445
|
+
log.warn("Chrome MCP warmup failed with unknown error", __spreadValues({
|
|
446
|
+
error: errorMessage
|
|
447
|
+
}, freeModel && {
|
|
448
|
+
model: `${freeModel.providerID}/${freeModel.modelID}`
|
|
449
|
+
}));
|
|
448
450
|
timer.end("Chrome MCP warmup failed");
|
|
449
451
|
throw error;
|
|
450
452
|
} finally {
|
|
@@ -509,15 +511,6 @@ class OpenCodeAPI {
|
|
|
509
511
|
"__chrome_mcp_warmup__"
|
|
510
512
|
);
|
|
511
513
|
warmupSessionId = warmupSession.id;
|
|
512
|
-
const prompt = [
|
|
513
|
-
"Call the browser tool list_pages immediately to establish the Chrome DevTools MCP connection.",
|
|
514
|
-
viteOrigin ? `If there are no pages, call new_page with ${viteOrigin}.` : "If there are no pages, call new_page with about:blank.",
|
|
515
|
-
"Do not read or modify project files.",
|
|
516
|
-
"Do not use any non-browser tools.",
|
|
517
|
-
"After the tool call is complete, reply with exactly: ready",
|
|
518
|
-
"If the tool call fails, reply with exactly: fail"
|
|
519
|
-
].join(" ");
|
|
520
|
-
const WARMUP_TIMEOUT = 6e4;
|
|
521
514
|
freeModel = yield this.getCheapestModel();
|
|
522
515
|
if (freeModel) {
|
|
523
516
|
log.debug("Using cheapest model for retry warmup", {
|
|
@@ -527,6 +520,7 @@ class OpenCodeAPI {
|
|
|
527
520
|
} else {
|
|
528
521
|
log.debug("No model available for retry, using default model");
|
|
529
522
|
}
|
|
523
|
+
const WARMUP_TIMEOUT = 6e4;
|
|
530
524
|
const data = yield this.createHttpRequest(
|
|
531
525
|
{
|
|
532
526
|
hostname: this.hostname,
|
|
@@ -536,8 +530,12 @@ class OpenCodeAPI {
|
|
|
536
530
|
headers: { "Content-Type": "application/json" }
|
|
537
531
|
},
|
|
538
532
|
JSON.stringify(__spreadValues({
|
|
539
|
-
|
|
540
|
-
|
|
533
|
+
parts: [
|
|
534
|
+
{
|
|
535
|
+
type: "text",
|
|
536
|
+
text: "Test if the chrome-devtools_list_pages tool is available. If available, reply with: ready. If not available, explain why."
|
|
537
|
+
}
|
|
538
|
+
]
|
|
541
539
|
}, freeModel && {
|
|
542
540
|
model: {
|
|
543
541
|
providerID: freeModel.providerID,
|
|
@@ -556,13 +554,6 @@ class OpenCodeAPI {
|
|
|
556
554
|
);
|
|
557
555
|
}
|
|
558
556
|
const lowerResponse = responseText.toLowerCase();
|
|
559
|
-
if (lowerResponse.includes("fail")) {
|
|
560
|
-
throw new ChromeMcpWarmupError(
|
|
561
|
-
ChromeMcpWarmupErrorType.CHROME_NOT_CONNECTED,
|
|
562
|
-
"Chrome DevTools MCP is not connected",
|
|
563
|
-
"AI reported that browser tools are not available. This should not happen if Chrome DevTools check passed."
|
|
564
|
-
);
|
|
565
|
-
}
|
|
566
557
|
if (!lowerResponse.includes("ready")) {
|
|
567
558
|
throw new ChromeMcpWarmupError(
|
|
568
559
|
ChromeMcpWarmupErrorType.AI_RESPONSE_ERROR,
|
|
@@ -577,10 +568,12 @@ class OpenCodeAPI {
|
|
|
577
568
|
if (e.type === ChromeMcpWarmupErrorType.SESSION_ERROR) {
|
|
578
569
|
timer.end("Session creation failed");
|
|
579
570
|
}
|
|
580
|
-
log.warn(`Chrome MCP warmup retry failed: ${e.type}`, {
|
|
571
|
+
log.warn(`Chrome MCP warmup retry failed: ${e.type}`, __spreadValues({
|
|
581
572
|
message: e.message,
|
|
582
573
|
details: e.details
|
|
583
|
-
}
|
|
574
|
+
}, freeModel && {
|
|
575
|
+
model: `${freeModel.providerID}/${freeModel.modelID}`
|
|
576
|
+
}));
|
|
584
577
|
timer.end(`Chrome MCP warmup retry failed: ${e.type}`);
|
|
585
578
|
return { success: false, error: e };
|
|
586
579
|
}
|
|
@@ -599,7 +592,11 @@ class OpenCodeAPI {
|
|
|
599
592
|
"AI response timeout",
|
|
600
593
|
"AI did not respond within 60 seconds. Please check if the OpenCode AI model is properly configured and available."
|
|
601
594
|
);
|
|
602
|
-
log.warn("Chrome MCP warmup retry timeout", {
|
|
595
|
+
log.warn("Chrome MCP warmup retry timeout", __spreadValues({
|
|
596
|
+
error: errorMessage
|
|
597
|
+
}, freeModel && {
|
|
598
|
+
model: `${freeModel.providerID}/${freeModel.modelID}`
|
|
599
|
+
}));
|
|
603
600
|
timer.end("Chrome MCP warmup retry timeout");
|
|
604
601
|
return { success: false, error: error2 };
|
|
605
602
|
}
|
|
@@ -608,7 +605,11 @@ class OpenCodeAPI {
|
|
|
608
605
|
"Unknown error during Chrome MCP warmup retry",
|
|
609
606
|
errorMessage
|
|
610
607
|
);
|
|
611
|
-
log.warn("Chrome MCP warmup retry failed with unknown error", {
|
|
608
|
+
log.warn("Chrome MCP warmup retry failed with unknown error", __spreadValues({
|
|
609
|
+
error: errorMessage
|
|
610
|
+
}, freeModel && {
|
|
611
|
+
model: `${freeModel.providerID}/${freeModel.modelID}`
|
|
612
|
+
}));
|
|
612
613
|
timer.end("Chrome MCP warmup retry failed");
|
|
613
614
|
return { success: false, error };
|
|
614
615
|
} finally {
|
package/es/core/proxy-server.js
CHANGED
|
@@ -102,8 +102,137 @@ function generateBridgeScript(options) {
|
|
|
102
102
|
if (event.data && event.data.type === "OPENCODE_SET_THEME") {
|
|
103
103
|
setTheme(event.data.theme);
|
|
104
104
|
}
|
|
105
|
+
|
|
106
|
+
if (event.data && event.data.type === "OPENCODE_INSERT_FILE_PART") {
|
|
107
|
+
insertFilePart(event.data.element);
|
|
108
|
+
}
|
|
105
109
|
});
|
|
106
110
|
|
|
111
|
+
// === \u4FDD\u5B58\u8F93\u5165\u6846\u5149\u6807\u4F4D\u7F6E ===
|
|
112
|
+
let savedRange = null;
|
|
113
|
+
|
|
114
|
+
function setupPromptInputListener() {
|
|
115
|
+
const promptInput = document.querySelector('[data-component="prompt-input"]');
|
|
116
|
+
if (!promptInput) return;
|
|
117
|
+
|
|
118
|
+
promptInput.addEventListener('blur', function() {
|
|
119
|
+
const selection = window.getSelection();
|
|
120
|
+
if (selection && selection.rangeCount > 0) {
|
|
121
|
+
const range = selection.getRangeAt(0);
|
|
122
|
+
if (promptInput.contains(range.commonAncestorContainer)) {
|
|
123
|
+
savedRange = range.cloneRange();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
promptInput.addEventListener('focus', function() {
|
|
129
|
+
savedRange = null;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// === \u63D2\u5165 File Part \u5230\u8F93\u5165\u6846 ===
|
|
134
|
+
function insertFilePart(element) {
|
|
135
|
+
const promptInput = document.querySelector('[data-component="prompt-input"]');
|
|
136
|
+
if (!promptInput) {
|
|
137
|
+
console.warn('[OpenCode Bridge] Prompt input not found');
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const { filePath, line, column, description, innerText, previewPageUrl, previewPageTitle } = element;
|
|
142
|
+
|
|
143
|
+
const selector = description || 'element';
|
|
144
|
+
let textPreview = '';
|
|
145
|
+
if (innerText && innerText.trim()) {
|
|
146
|
+
const trimmed = innerText.trim();
|
|
147
|
+
textPreview = trimmed.length > 5 ? trimmed.substring(0, 5) + '...' : trimmed;
|
|
148
|
+
}
|
|
149
|
+
const displayText = '@' + selector + (textPreview ? '(' + textPreview + ')' : '');
|
|
150
|
+
|
|
151
|
+
const jsonStr = JSON.stringify({
|
|
152
|
+
pageContext: {
|
|
153
|
+
url: previewPageUrl || '',
|
|
154
|
+
title: previewPageTitle || '',
|
|
155
|
+
},
|
|
156
|
+
nodeContext: {
|
|
157
|
+
filePath,
|
|
158
|
+
line,
|
|
159
|
+
column,
|
|
160
|
+
description,
|
|
161
|
+
innerText: innerText ? innerText.substring(0, 500) : ''
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const span = document.createElement('span');
|
|
166
|
+
span.setAttribute('data-type', 'file');
|
|
167
|
+
span.setAttribute('data-path', jsonStr);
|
|
168
|
+
span.setAttribute('contenteditable', 'false');
|
|
169
|
+
|
|
170
|
+
span.textContent = displayText;
|
|
171
|
+
|
|
172
|
+
if (savedRange) {
|
|
173
|
+
const range = savedRange;
|
|
174
|
+
range.collapse(false);
|
|
175
|
+
range.insertNode(span);
|
|
176
|
+
|
|
177
|
+
const space = document.createTextNode('\\u00A0');
|
|
178
|
+
span.parentNode.insertBefore(space, span.nextSibling);
|
|
179
|
+
|
|
180
|
+
const newRange = document.createRange();
|
|
181
|
+
newRange.setStartAfter(space);
|
|
182
|
+
newRange.collapse(true);
|
|
183
|
+
|
|
184
|
+
promptInput.focus();
|
|
185
|
+
|
|
186
|
+
const selection = window.getSelection();
|
|
187
|
+
if (selection) {
|
|
188
|
+
selection.removeAllRanges();
|
|
189
|
+
selection.addRange(newRange);
|
|
190
|
+
}
|
|
191
|
+
savedRange = null;
|
|
192
|
+
|
|
193
|
+
promptInput.dispatchEvent(new Event('input', { bubbles: true }));
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const selection = window.getSelection();
|
|
198
|
+
if (selection && selection.rangeCount > 0) {
|
|
199
|
+
const range = selection.getRangeAt(0);
|
|
200
|
+
|
|
201
|
+
if (promptInput.contains(range.commonAncestorContainer)) {
|
|
202
|
+
range.collapse(false);
|
|
203
|
+
range.insertNode(span);
|
|
204
|
+
|
|
205
|
+
const space = document.createTextNode('\\u00A0');
|
|
206
|
+
span.parentNode.insertBefore(space, span.nextSibling);
|
|
207
|
+
|
|
208
|
+
const newRange = document.createRange();
|
|
209
|
+
newRange.setStartAfter(space);
|
|
210
|
+
newRange.collapse(true);
|
|
211
|
+
selection.removeAllRanges();
|
|
212
|
+
selection.addRange(newRange);
|
|
213
|
+
|
|
214
|
+
promptInput.dispatchEvent(new Event('input', { bubbles: true }));
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
promptInput.appendChild(span);
|
|
220
|
+
const space = document.createTextNode('\\u00A0');
|
|
221
|
+
promptInput.appendChild(space);
|
|
222
|
+
|
|
223
|
+
const newRange = document.createRange();
|
|
224
|
+
newRange.setStartAfter(space);
|
|
225
|
+
newRange.collapse(true);
|
|
226
|
+
const newSelection = window.getSelection();
|
|
227
|
+
if (newSelection) {
|
|
228
|
+
newSelection.removeAllRanges();
|
|
229
|
+
newSelection.addRange(newRange);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
promptInput.dispatchEvent(new Event('input', { bubbles: true }));
|
|
233
|
+
promptInput.focus();
|
|
234
|
+
}
|
|
235
|
+
|
|
107
236
|
// === \u601D\u8003\u72B6\u6001\u76D1\u542C (\u5B8C\u5168\u590D\u523B OpenCode Web \u5B9E\u73B0) ===
|
|
108
237
|
// OpenCode Web \u6838\u5FC3\u903B\u8F91:
|
|
109
238
|
// working = !!pending() || sessionStatus().type !== "idle"
|
|
@@ -212,6 +341,16 @@ function generateBridgeScript(options) {
|
|
|
212
341
|
window.parent.postMessage({ type: "OPENCODE_READY" }, "*");
|
|
213
342
|
}
|
|
214
343
|
setupThinkingListener();
|
|
344
|
+
setupPromptInputListener();
|
|
345
|
+
|
|
346
|
+
const observer = new MutationObserver(function(mutations) {
|
|
347
|
+
const promptInput = document.querySelector('[data-component="prompt-input"]');
|
|
348
|
+
if (promptInput && !promptInput._opencodeListenerAttached) {
|
|
349
|
+
setupPromptInputListener();
|
|
350
|
+
promptInput._opencodeListenerAttached = true;
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
215
354
|
}
|
|
216
355
|
|
|
217
356
|
if (document.readyState === 'loading') {
|
package/lib/client/App.vue.js
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
7
24
|
var __export = (target, all) => {
|
|
8
25
|
for (var name in all)
|
|
9
26
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -85,9 +102,9 @@ const __vue_sfc__ = /* @__PURE__ */ (0, import_vue.defineComponent)({
|
|
|
85
102
|
} = props.config;
|
|
86
103
|
const widgetPosition = position;
|
|
87
104
|
const widgetTheme = initialTheme;
|
|
88
|
-
const showNotification = (msg) => {
|
|
105
|
+
const showNotification = (msg, options) => {
|
|
89
106
|
var _a, _b;
|
|
90
|
-
(_b = (_a = widgetRef.value) == null ? void 0 : _a.showNotification) == null ? void 0 : _b.call(_a, msg);
|
|
107
|
+
(_b = (_a = widgetRef.value) == null ? void 0 : _a.showNotification) == null ? void 0 : _b.call(_a, msg, options);
|
|
91
108
|
};
|
|
92
109
|
const {
|
|
93
110
|
serviceStatus,
|
|
@@ -102,7 +119,6 @@ const __vue_sfc__ = /* @__PURE__ */ (0, import_vue.defineComponent)({
|
|
|
102
119
|
} = (0, import_useServiceStatus.useServiceStatus)();
|
|
103
120
|
const {
|
|
104
121
|
selectedElements,
|
|
105
|
-
addElement,
|
|
106
122
|
removeElement,
|
|
107
123
|
clearElements
|
|
108
124
|
} = (0, import_useSelectedElements.useSelectedElements)();
|
|
@@ -237,13 +253,13 @@ const __vue_sfc__ = /* @__PURE__ */ (0, import_vue.defineComponent)({
|
|
|
237
253
|
}
|
|
238
254
|
});
|
|
239
255
|
const handleSelectNode = (element) => {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
}
|
|
256
|
+
var _a;
|
|
257
|
+
const elementWithContext = __spreadProps(__spreadValues({}, element), {
|
|
258
|
+
previewPageUrl: window.location.href,
|
|
259
|
+
previewPageTitle: document.title
|
|
260
|
+
});
|
|
261
|
+
(_a = widgetRef.value) == null ? void 0 : _a.sendMessageToIframe("OPENCODE_INSERT_FILE_PART", { element: elementWithContext });
|
|
262
|
+
showNotification(`\u8282\u70B9\u5DF2\u6DFB\u52A0\u5230\u5BF9\u8BDD\u6846`, { mode: "page" });
|
|
247
263
|
};
|
|
248
264
|
const handleClearSelected = () => {
|
|
249
265
|
clearElements();
|
|
@@ -269,7 +285,7 @@ const __vue_sfc__ = /* @__PURE__ */ (0, import_vue.defineComponent)({
|
|
|
269
285
|
const handleFrameLoaded = () => {
|
|
270
286
|
iframeLoading.value = false;
|
|
271
287
|
};
|
|
272
|
-
const __returned__ = { props, open, selectMode, sessionListCollapsed, loading, widgetRef, retryingWarmup, position, initialTheme, autoOpen, hotkey, widgetPosition, widgetTheme, showNotification, serviceStatus, chromeMcpFailed, chromeMcpErrorType, chromeMcpErrorMessage, thinking, loadingText, updateStatusFromTask, setStarting, setThinking, selectedElements,
|
|
288
|
+
const __returned__ = { props, open, selectMode, sessionListCollapsed, loading, widgetRef, retryingWarmup, position, initialTheme, autoOpen, hotkey, widgetPosition, widgetTheme, showNotification, serviceStatus, chromeMcpFailed, chromeMcpErrorType, chromeMcpErrorMessage, thinking, loadingText, updateStatusFromTask, setStarting, setThinking, selectedElements, removeElement, clearElements, theme, sendThemeToIframe, sessions, loadingSessionList, currentSessionId, iframeSrc, iframeLoading, loadSessions, createSession, deleteSession, selectSession, updateContext, showSessionListSkeleton, computedLoading, retryWarmup, setupSSE, ensureServicesStarted, handleToggle, handleSelectNode, handleClearSelected, handleSelectModeChange, handleSessionListCollapsedChange, handleThemeChange, handleRemoveSelectedNode, handleFrameLoaded, get OpenCodeWidget() {
|
|
273
289
|
return import_components.OpenCodeWidget;
|
|
274
290
|
}, LoadingContent: import_LoadingContent_vue.default, ChromeWarmupError: import_ChromeWarmupError_vue.default };
|
|
275
291
|
Object.defineProperty(__returned__, "__isScriptSetup", { enumerable: false, value: true });
|
|
@@ -292,7 +308,6 @@ function __vue_render__(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
292
308
|
"current-session-id": $setup.currentSessionId,
|
|
293
309
|
sessions: $setup.sessions,
|
|
294
310
|
"session-key": "id",
|
|
295
|
-
"selected-elements": $setup.selectedElements,
|
|
296
311
|
"hotkey-label": $setup.hotkey,
|
|
297
312
|
thinking: $setup.thinking,
|
|
298
313
|
"onUpdate:open": $setup.handleToggle,
|
|
@@ -323,7 +338,7 @@ function __vue_render__(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
323
338
|
]),
|
|
324
339
|
_: 1
|
|
325
340
|
/* STABLE */
|
|
326
|
-
}, 8, ["position", "theme", "open", "select-mode", "session-list-collapsed", "frame-loading", "loading-session-list", "show-session-list-skeleton", "show-error", "iframe-src", "current-session-id", "sessions", "
|
|
341
|
+
}, 8, ["position", "theme", "open", "select-mode", "session-list-collapsed", "frame-loading", "loading-session-list", "show-session-list-skeleton", "show-error", "iframe-src", "current-session-id", "sessions", "hotkey-label", "thinking", "onCreateSession", "onDeleteSession", "onSelectSession", "onEmptyAction"]);
|
|
327
342
|
}
|
|
328
343
|
__vue_sfc__.render = __vue_render__;
|
|
329
344
|
var App_vue_default = __vue_sfc__;
|