vite-plugin-opencode-assistant 1.0.14 → 1.0.16

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.
Files changed (81) hide show
  1. package/es/client/App.vue.d.ts +6 -0
  2. package/es/client/App.vue.js +300 -0
  3. package/es/client/components/ChromeWarmupError-sfc.css +1 -0
  4. package/es/client/components/ChromeWarmupError.vue.d.ts +11 -0
  5. package/es/client/components/ChromeWarmupError.vue.js +196 -0
  6. package/es/client/components/LoadingContent.vue.d.ts +5 -0
  7. package/es/client/components/LoadingContent.vue.js +39 -0
  8. package/es/client/composables/useContext.d.ts +8 -0
  9. package/es/client/composables/useContext.js +63 -0
  10. package/es/client/composables/useHotkey.d.ts +12 -0
  11. package/es/client/composables/useHotkey.js +41 -0
  12. package/es/client/composables/useSSE.d.ts +20 -0
  13. package/es/client/composables/useSSE.js +61 -0
  14. package/es/client/composables/useSelectedElements.d.ts +19 -0
  15. package/es/client/composables/useSelectedElements.js +43 -0
  16. package/es/client/composables/useServiceStatus.d.ts +13 -0
  17. package/es/client/composables/useServiceStatus.js +53 -0
  18. package/es/client/composables/useSessions.d.ts +26 -0
  19. package/es/client/composables/useSessions.js +127 -0
  20. package/es/client/composables/useTheme.d.ts +12 -0
  21. package/es/client/composables/useTheme.js +42 -0
  22. package/es/client/index.d.ts +1 -1
  23. package/es/client/index.js +5 -675
  24. package/es/client/styles.css +1 -0
  25. package/es/core/api.d.ts +18 -6
  26. package/es/core/api.js +324 -69
  27. package/es/core/proxy-server.d.ts +5 -1
  28. package/es/core/proxy-server.js +201 -70
  29. package/es/core/service.d.ts +9 -2
  30. package/es/core/service.js +80 -44
  31. package/es/endpoints/index.js +1 -1
  32. package/es/endpoints/sse.js +0 -3
  33. package/es/endpoints/start.d.ts +1 -2
  34. package/es/endpoints/start.js +2 -2
  35. package/es/endpoints/types.d.ts +5 -2
  36. package/es/endpoints/warmup.js +15 -3
  37. package/es/index.js +8 -12
  38. package/es/utils/system.d.ts +3 -1
  39. package/es/utils/system.js +39 -10
  40. package/lib/client/App.vue.d.ts +6 -0
  41. package/lib/client/App.vue.js +329 -0
  42. package/lib/client/components/ChromeWarmupError-sfc.css +1 -0
  43. package/lib/client/components/ChromeWarmupError.vue.d.ts +11 -0
  44. package/lib/client/components/ChromeWarmupError.vue.js +215 -0
  45. package/lib/client/components/LoadingContent.vue.d.ts +5 -0
  46. package/lib/client/components/LoadingContent.vue.js +58 -0
  47. package/lib/client/composables/useContext.d.ts +8 -0
  48. package/lib/client/composables/useContext.js +86 -0
  49. package/lib/client/composables/useHotkey.d.ts +12 -0
  50. package/lib/client/composables/useHotkey.js +66 -0
  51. package/lib/client/composables/useSSE.d.ts +20 -0
  52. package/lib/client/composables/useSSE.js +84 -0
  53. package/lib/client/composables/useSelectedElements.d.ts +19 -0
  54. package/lib/client/composables/useSelectedElements.js +66 -0
  55. package/lib/client/composables/useServiceStatus.d.ts +13 -0
  56. package/lib/client/composables/useServiceStatus.js +76 -0
  57. package/lib/client/composables/useSessions.d.ts +26 -0
  58. package/lib/client/composables/useSessions.js +148 -0
  59. package/lib/client/composables/useTheme.d.ts +12 -0
  60. package/lib/client/composables/useTheme.js +65 -0
  61. package/lib/client/index.d.ts +1 -1
  62. package/lib/client/index.js +22 -667
  63. package/lib/client/styles.css +1 -0
  64. package/lib/client.js +2988 -2973
  65. package/lib/core/api.d.ts +18 -6
  66. package/lib/core/api.js +321 -74
  67. package/lib/core/proxy-server.d.ts +5 -1
  68. package/lib/core/proxy-server.js +201 -70
  69. package/lib/core/service.d.ts +9 -2
  70. package/lib/core/service.js +76 -43
  71. package/lib/endpoints/index.js +1 -1
  72. package/lib/endpoints/sse.js +0 -3
  73. package/lib/endpoints/start.d.ts +1 -2
  74. package/lib/endpoints/start.js +2 -2
  75. package/lib/endpoints/types.d.ts +5 -2
  76. package/lib/endpoints/warmup.js +15 -3
  77. package/lib/index.js +8 -12
  78. package/lib/style.css +1 -1
  79. package/lib/utils/system.d.ts +3 -1
  80. package/lib/utils/system.js +39 -5
  81. package/package.json +4 -4
@@ -0,0 +1,148 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
+ var __export = (target, all) => {
23
+ for (var name in all)
24
+ __defProp(target, name, { get: all[name], enumerable: true });
25
+ };
26
+ var __copyProps = (to, from, except, desc) => {
27
+ if (from && typeof from === "object" || typeof from === "function") {
28
+ for (let key of __getOwnPropNames(from))
29
+ if (!__hasOwnProp.call(to, key) && key !== except)
30
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
+ }
32
+ return to;
33
+ };
34
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
+ var __async = (__this, __arguments, generator) => {
36
+ return new Promise((resolve, reject) => {
37
+ var fulfilled = (value) => {
38
+ try {
39
+ step(generator.next(value));
40
+ } catch (e) {
41
+ reject(e);
42
+ }
43
+ };
44
+ var rejected = (value) => {
45
+ try {
46
+ step(generator.throw(value));
47
+ } catch (e) {
48
+ reject(e);
49
+ }
50
+ };
51
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
52
+ step((generator = generator.apply(__this, __arguments)).next());
53
+ });
54
+ };
55
+ var useSessions_exports = {};
56
+ __export(useSessions_exports, {
57
+ useSessions: () => useSessions
58
+ });
59
+ module.exports = __toCommonJS(useSessions_exports);
60
+ var import_vue = require("vue");
61
+ var import_shared = require("@vite-plugin-opencode-assistant/shared");
62
+ function useSessions(showNotification) {
63
+ const sessions = (0, import_vue.ref)([]);
64
+ const loadingSessionList = (0, import_vue.ref)(void 0);
65
+ const currentSessionId = (0, import_vue.ref)(null);
66
+ const iframeLoading = (0, import_vue.ref)(false);
67
+ const iframeSrc = (0, import_vue.computed)(() => {
68
+ var _a;
69
+ return currentSessionId.value ? ((_a = sessions.value.find((s) => s.id === currentSessionId.value)) == null ? void 0 : _a.url) || "" : "";
70
+ });
71
+ const loadSessions = () => __async(null, null, function* () {
72
+ var _a;
73
+ loadingSessionList.value = true;
74
+ try {
75
+ const response = yield fetch(import_shared.SESSIONS_API_PATH);
76
+ const data = yield response.json();
77
+ sessions.value = data.filter((s) => s.title !== "__chrome_mcp_warmup__").map((s) => {
78
+ var _a2;
79
+ return __spreadProps(__spreadValues({}, s), {
80
+ updatedAt: ((_a2 = s.time) == null ? void 0 : _a2.updated) || Date.now()
81
+ });
82
+ });
83
+ if (!sessions.value.length) {
84
+ createSession();
85
+ }
86
+ currentSessionId.value = ((_a = sessions.value[0]) == null ? void 0 : _a.id) || null;
87
+ } catch (e) {
88
+ console.error("[OpenCode] Failed to load sessions:", e);
89
+ } finally {
90
+ loadingSessionList.value = false;
91
+ }
92
+ });
93
+ const createSession = () => __async(null, null, function* () {
94
+ try {
95
+ const response = yield fetch(import_shared.SESSIONS_API_PATH, { method: "POST" });
96
+ const newSession = yield response.json();
97
+ sessions.value.unshift({
98
+ id: newSession.id,
99
+ title: "\u65B0\u4F1A\u8BDD",
100
+ updatedAt: Date.now(),
101
+ url: newSession.url
102
+ });
103
+ currentSessionId.value = newSession.id;
104
+ iframeLoading.value = true;
105
+ loadSessions();
106
+ } catch (e) {
107
+ showNotification("\u521B\u5EFA\u4F1A\u8BDD\u5931\u8D25");
108
+ }
109
+ });
110
+ const deleteSession = (session) => __async(null, null, function* () {
111
+ try {
112
+ yield fetch(`${import_shared.SESSIONS_API_PATH}?id=${session.id}`, { method: "DELETE" });
113
+ yield loadSessions();
114
+ showNotification("\u4F1A\u8BDD\u5DF2\u5220\u9664");
115
+ if (currentSessionId.value === session.id) {
116
+ if (sessions.value.length > 0) {
117
+ const nextSession = sessions.value[0];
118
+ currentSessionId.value = nextSession.id;
119
+ iframeLoading.value = true;
120
+ } else {
121
+ currentSessionId.value = null;
122
+ }
123
+ }
124
+ } catch (e) {
125
+ showNotification("\u5220\u9664\u4F1A\u8BDD\u5931\u8D25");
126
+ }
127
+ });
128
+ const selectSession = (session) => {
129
+ if (currentSessionId.value === session.id) return;
130
+ currentSessionId.value = session.id;
131
+ iframeLoading.value = true;
132
+ };
133
+ return {
134
+ sessions,
135
+ loadingSessionList,
136
+ currentSessionId,
137
+ iframeSrc,
138
+ iframeLoading,
139
+ loadSessions,
140
+ createSession,
141
+ deleteSession,
142
+ selectSession
143
+ };
144
+ }
145
+ // Annotate the CommonJS export names for ESM import in node:
146
+ 0 && (module.exports = {
147
+ useSessions
148
+ });
@@ -0,0 +1,12 @@
1
+ import type { OpenCodeWidgetTheme } from "@vite-plugin-opencode-assistant/shared";
2
+ interface WidgetRef {
3
+ sendMessageToIframe: (type: string, data?: Record<string, unknown>) => void;
4
+ }
5
+ export declare function useTheme(initialTheme: OpenCodeWidgetTheme, widgetRef: {
6
+ value: WidgetRef | null;
7
+ }): {
8
+ theme: import("vue").Ref<OpenCodeWidgetTheme, OpenCodeWidgetTheme>;
9
+ resolvedTheme: import("vue").ComputedRef<"light" | "dark">;
10
+ sendThemeToIframe: () => void;
11
+ };
12
+ export {};
@@ -0,0 +1,65 @@
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 useTheme_exports = {};
19
+ __export(useTheme_exports, {
20
+ useTheme: () => useTheme
21
+ });
22
+ module.exports = __toCommonJS(useTheme_exports);
23
+ var import_vue = require("vue");
24
+ function useTheme(initialTheme, widgetRef) {
25
+ const theme = (0, import_vue.ref)(initialTheme);
26
+ const resolvedTheme = (0, import_vue.computed)(() => {
27
+ if (theme.value === "auto") {
28
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
29
+ }
30
+ return theme.value;
31
+ });
32
+ const sendThemeToIframe = () => {
33
+ var _a;
34
+ (_a = widgetRef.value) == null ? void 0 : _a.sendMessageToIframe("OPENCODE_SET_THEME", {
35
+ theme: resolvedTheme.value
36
+ });
37
+ };
38
+ let mediaQuery = null;
39
+ const handleSystemThemeChange = () => {
40
+ if (theme.value === "auto") {
41
+ sendThemeToIframe();
42
+ }
43
+ };
44
+ (0, import_vue.onMounted)(() => {
45
+ mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
46
+ mediaQuery.addEventListener("change", handleSystemThemeChange);
47
+ (0, import_vue.watch)(resolvedTheme, () => {
48
+ sendThemeToIframe();
49
+ });
50
+ });
51
+ (0, import_vue.onUnmounted)(() => {
52
+ if (mediaQuery) {
53
+ mediaQuery.removeEventListener("change", handleSystemThemeChange);
54
+ }
55
+ });
56
+ return {
57
+ theme,
58
+ resolvedTheme,
59
+ sendThemeToIframe
60
+ };
61
+ }
62
+ // Annotate the CommonJS export names for ESM import in node:
63
+ 0 && (module.exports = {
64
+ useTheme
65
+ });
@@ -1 +1 @@
1
- import "@vite-plugin-opencode-assistant/components/style.css";
1
+ import "./styles.css";