@vite-plugin-opencode-assistant/shared 1.0.13 → 1.0.15

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/constants.d.ts CHANGED
@@ -6,9 +6,9 @@ import type { OpenCodeLanguage, OpenCodeSettings } from "./types.js";
6
6
  /** 默认主机名 */
7
7
  export declare const DEFAULT_HOSTNAME = "127.0.0.1";
8
8
  /** 默认 Web 服务端口 */
9
- export declare const DEFAULT_WEB_PORT = 4097;
9
+ export declare const DEFAULT_WEB_PORT = 5097;
10
10
  /** 默认代理服务端口 */
11
- export declare const DEFAULT_PROXY_PORT = 4098;
11
+ export declare const DEFAULT_PROXY_PORT = 6097;
12
12
  /** 服务器启动超时时间(毫秒) */
13
13
  export declare const SERVER_START_TIMEOUT = 300000;
14
14
  /** 服务器检查间隔(毫秒) */
@@ -78,6 +78,10 @@ export declare const DEFAULT_OPENCODE_SETTINGS: {
78
78
  export declare const MAX_TEXT_LENGTH = 100;
79
79
  /** 元素上下文标记 */
80
80
  export declare const CONTEXT_MARKER = "[\u5143\u7D20\u4E0A\u4E0B\u6587]";
81
+ /** 页面上下文内部标记(用于插件) */
82
+ export declare const PAGE_CONTEXT_MARKER = "__OPENCODE_CONTEXT__";
83
+ /** 页面上下文文本最大长度 */
84
+ export declare const PAGE_CONTEXT_MAX_TEXT_LENGTH = 10000;
81
85
  /** ==================== 默认配置 ==================== */
82
86
  /** 默认插件配置 */
83
87
  export declare const DEFAULT_CONFIG: {
package/es/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const DEFAULT_HOSTNAME = "127.0.0.1";
2
- const DEFAULT_WEB_PORT = 4097;
3
- const DEFAULT_PROXY_PORT = 4098;
2
+ const DEFAULT_WEB_PORT = 5097;
3
+ const DEFAULT_PROXY_PORT = 6097;
4
4
  const SERVER_START_TIMEOUT = 3e5;
5
5
  const SERVER_CHECK_INTERVAL = 100;
6
6
  const DEFAULT_RETRIES = 5;
@@ -37,6 +37,8 @@ const DEFAULT_OPENCODE_SETTINGS = {
37
37
  };
38
38
  const MAX_TEXT_LENGTH = 100;
39
39
  const CONTEXT_MARKER = "[\u5143\u7D20\u4E0A\u4E0B\u6587]";
40
+ const PAGE_CONTEXT_MARKER = "__OPENCODE_CONTEXT__";
41
+ const PAGE_CONTEXT_MAX_TEXT_LENGTH = 1e4;
40
42
  const DEFAULT_CONFIG = {
41
43
  enabled: true,
42
44
  webPort: DEFAULT_WEB_PORT,
@@ -71,6 +73,8 @@ export {
71
73
  MAX_TEXT_LENGTH,
72
74
  NOTIFICATION_DURATION,
73
75
  OPENCODE_STORAGE_KEYS,
76
+ PAGE_CONTEXT_MARKER,
77
+ PAGE_CONTEXT_MAX_TEXT_LENGTH,
74
78
  RETRY_DELAY,
75
79
  SELECTED_ELEMENTS_KEY,
76
80
  SERVER_CHECK_INTERVAL,
package/es/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./constants.js";
2
2
  export * from "./logger.js";
3
3
  export * from "./types.js";
4
+ export * from "./utils.js";
package/es/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./constants.js";
2
2
  export * from "./logger.js";
3
3
  export * from "./types.js";
4
+ export * from "./utils.js";
package/es/logger.js CHANGED
@@ -184,6 +184,17 @@ function log(level, message, context, ...args) {
184
184
  if (formattedArgs) {
185
185
  parts.push(formattedArgs);
186
186
  }
187
+ if (context == null ? void 0 : context.error) {
188
+ const err = context.error;
189
+ if (err instanceof Error) {
190
+ parts.push(`${COLORS.red}Error: ${err.message}${COLORS.reset}`);
191
+ if (level >= 3 /* ERROR */ && globalConfig.showTrace && err.stack) {
192
+ console.error(`${COLORS.dim}${err.stack}${COLORS.reset}`);
193
+ }
194
+ } else {
195
+ parts.push(`${COLORS.red}Error: ${formatValue(err)}${COLORS.reset}`);
196
+ }
197
+ }
187
198
  const output = parts.join(" ");
188
199
  if (level >= 3 /* ERROR */) {
189
200
  console.error(output);
@@ -192,12 +203,6 @@ function log(level, message, context, ...args) {
192
203
  } else {
193
204
  console.log(output);
194
205
  }
195
- if ((context == null ? void 0 : context.error) && level >= 3 /* ERROR */ && globalConfig.showTrace) {
196
- const err = context.error;
197
- if (err instanceof Error && err.stack) {
198
- console.error(`${COLORS.dim}${err.stack}${COLORS.reset}`);
199
- }
200
- }
201
206
  }
202
207
  const logger = {
203
208
  debug(message, context, ...args) {
package/es/types.d.ts CHANGED
@@ -195,3 +195,124 @@ export interface PageContext {
195
195
  /** 选中的元素列表 */
196
196
  selectedElements?: SelectedElement[];
197
197
  }
198
+ /**
199
+ * 服务启动任务状态
200
+ */
201
+ export type ServiceStartupTask = "checking_opencode" | "allocating_port" | "preparing_runtime" | "starting_web" | "waiting_web_ready" | "starting_proxy" | "warming_up_chrome" | "creating_session" | "opencode_not_installed" | "web_start_timeout" | "session_creation_failed" | "chrome_mcp_failed" | "ready";
202
+ /**
203
+ * 服务启动任务状态映射
204
+ */
205
+ export declare const SERVICE_STARTUP_TASKS: Record<ServiceStartupTask, string>;
206
+ /**
207
+ * 挂件位置选项
208
+ */
209
+ export type OpenCodeWidgetPosition = "bottom-right" | "bottom-left" | "top-right" | "top-left";
210
+ /**
211
+ * 挂件主题选项
212
+ */
213
+ export type OpenCodeWidgetTheme = "light" | "dark" | "auto";
214
+ /**
215
+ * 服务状态
216
+ */
217
+ export type ServiceStatus = "idle" | "starting" | "ready" | "partial" | "failed";
218
+ /**
219
+ * 挂件会话信息
220
+ */
221
+ export interface OpenCodeWidgetSession {
222
+ id: string;
223
+ title?: string;
224
+ updatedAt?: string | number | Date;
225
+ meta?: string;
226
+ directory?: string;
227
+ }
228
+ /**
229
+ * 挂件选中的元素
230
+ */
231
+ export interface OpenCodeSelectedElement {
232
+ filePath: string | null;
233
+ line: number | null;
234
+ column: number | null;
235
+ innerText: string;
236
+ description?: string;
237
+ }
238
+ /**
239
+ * 删除选中节点的载荷
240
+ */
241
+ export interface OpenCodeRemoveSelectedPayload {
242
+ element: OpenCodeSelectedElement;
243
+ index: number;
244
+ source: "panel" | "bubble";
245
+ }
246
+ /**
247
+ * 挂件会话列表项
248
+ */
249
+ export interface OpenCodeWidgetSessionItem {
250
+ key: string;
251
+ id: string;
252
+ title: string;
253
+ meta: string;
254
+ active: boolean;
255
+ session: OpenCodeWidgetSession;
256
+ [key: string]: any;
257
+ }
258
+ /**
259
+ * 选中元素列表项
260
+ */
261
+ export interface OpenCodeSelectedElementItem {
262
+ key: string;
263
+ description: string;
264
+ bubbleFileText: string;
265
+ panelFileText: string;
266
+ element: OpenCodeSelectedElement;
267
+ }
268
+ /**
269
+ * 挂件组件 Props
270
+ */
271
+ export interface OpenCodeWidgetProps {
272
+ position?: OpenCodeWidgetPosition;
273
+ open?: boolean;
274
+ theme?: OpenCodeWidgetTheme;
275
+ title?: string;
276
+ hotkeyLabel?: string;
277
+ selectShortcutLabel?: string;
278
+ selectMode?: boolean;
279
+ sessionListCollapsed?: boolean;
280
+ sessionKey?: string;
281
+ frameLoading?: boolean;
282
+ loadingSessionList?: boolean;
283
+ showSessionListSkeleton?: boolean;
284
+ showEmptyState?: boolean;
285
+ showError?: boolean;
286
+ emptyStateText?: string;
287
+ emptyStateActionText?: string;
288
+ iframeSrc?: string;
289
+ sessions?: OpenCodeWidgetSession[];
290
+ currentSessionId?: string | null;
291
+ selectedElements?: OpenCodeSelectedElement[];
292
+ showClearAll?: boolean;
293
+ selectEnabled?: boolean;
294
+ }
295
+ /**
296
+ * 挂件组件事件
297
+ */
298
+ export type OpenCodeWidgetEmits = {
299
+ (e: "update:open", value: boolean): void;
300
+ (e: "update:selectMode", value: boolean): void;
301
+ (e: "update:sessionListCollapsed", value: boolean): void;
302
+ (e: "update:currentSessionId", value: string | null): void;
303
+ (e: "update:selectedElements", value: OpenCodeSelectedElement[]): void;
304
+ (e: "update:theme", value: OpenCodeWidgetTheme): void;
305
+ (e: "toggle", value: boolean): void;
306
+ (e: "close"): void;
307
+ (e: "toggle-session-list", value: boolean): void;
308
+ (e: "toggle-select-mode", value: boolean): void;
309
+ (e: "toggle-theme", value: OpenCodeWidgetTheme): void;
310
+ (e: "create-session"): void;
311
+ (e: "select-session", session: OpenCodeWidgetSession): void;
312
+ (e: "delete-session", session: OpenCodeWidgetSession): void;
313
+ (e: "click-selected-node", element: OpenCodeSelectedElement): void;
314
+ (e: "remove-selected-node", payload: OpenCodeRemoveSelectedPayload): void;
315
+ (e: "clear-selected-nodes"): void;
316
+ (e: "empty-action"): void;
317
+ (e: "frame-loaded"): void;
318
+ };
package/es/types.js CHANGED
@@ -0,0 +1,18 @@
1
+ const SERVICE_STARTUP_TASKS = {
2
+ checking_opencode: "\u68C0\u67E5 OpenCode \u5B89\u88C5",
3
+ allocating_port: "\u5206\u914D\u670D\u52A1\u7AEF\u53E3",
4
+ preparing_runtime: "\u51C6\u5907\u8FD0\u884C\u73AF\u5883",
5
+ starting_web: "\u542F\u52A8 OpenCode Web",
6
+ waiting_web_ready: "\u7B49\u5F85\u670D\u52A1\u5C31\u7EEA",
7
+ starting_proxy: "\u542F\u52A8\u4EE3\u7406\u670D\u52A1",
8
+ warming_up_chrome: "\u9884\u70ED Chrome DevTools",
9
+ creating_session: "\u521B\u5EFA\u4F1A\u8BDD",
10
+ opencode_not_installed: "OpenCode \u672A\u5B89\u88C5",
11
+ web_start_timeout: "\u670D\u52A1\u542F\u52A8\u8D85\u65F6",
12
+ session_creation_failed: "\u4F1A\u8BDD\u521B\u5EFA\u5931\u8D25",
13
+ chrome_mcp_failed: "Chrome DevTools \u8FDE\u63A5\u5931\u8D25",
14
+ ready: "\u51C6\u5907\u5B8C\u6210"
15
+ };
16
+ export {
17
+ SERVICE_STARTUP_TASKS
18
+ };
package/es/utils.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @fileoverview 通用工具函数
3
+ */
4
+ /**
5
+ * 截断字符串到指定长度
6
+ * @param value - 要截断的字符串
7
+ * @param maxLength - 最大长度
8
+ * @returns 截断后的字符串,如果超出长度则添加省略号
9
+ */
10
+ export declare function truncate(value: string, maxLength: number): string;
11
+ /**
12
+ * 延迟指定时间
13
+ * @param ms - 毫秒数
14
+ * @returns Promise
15
+ */
16
+ export declare function sleep(ms: number): Promise<void>;
17
+ /**
18
+ * 将字符串编码为 Base64
19
+ * @param str - 要编码的字符串
20
+ * @returns Base64 编码的字符串
21
+ */
22
+ export declare function base64Encode(str: string): string;
23
+ /**
24
+ * 将 Base64 解码为字符串
25
+ * @param base64 - Base64 编码的字符串
26
+ * @returns 解码后的字符串
27
+ */
28
+ export declare function base64Decode(base64: string): string;
29
+ /**
30
+ * 从响应数据中提取文本内容
31
+ * 支持多种常见响应格式
32
+ */
33
+ export declare function extractTextFromResponse(data: unknown): string | null;
package/es/utils.js ADDED
@@ -0,0 +1,53 @@
1
+ function truncate(value, maxLength) {
2
+ if (value.length <= maxLength) {
3
+ return value;
4
+ }
5
+ return `${value.slice(0, maxLength)}...`;
6
+ }
7
+ function sleep(ms) {
8
+ return new Promise((resolve) => setTimeout(resolve, ms));
9
+ }
10
+ function base64Encode(str) {
11
+ if (typeof Buffer !== "undefined") {
12
+ return Buffer.from(str).toString("base64");
13
+ }
14
+ const bytes = new TextEncoder().encode(str);
15
+ const binString = Array.from(bytes, (byte) => String.fromCodePoint(byte)).join("");
16
+ return btoa(binString);
17
+ }
18
+ function base64Decode(base64) {
19
+ if (typeof Buffer !== "undefined") {
20
+ return Buffer.from(base64, "base64").toString("utf-8");
21
+ }
22
+ const binString = atob(base64);
23
+ const bytes = Uint8Array.from(binString, (c) => c.charCodeAt(0));
24
+ return new TextDecoder().decode(bytes);
25
+ }
26
+ function extractTextFromResponse(data) {
27
+ if (!data || typeof data !== "object") return null;
28
+ const obj = data;
29
+ if (obj.parts && Array.isArray(obj.parts)) {
30
+ const textParts = obj.parts.filter((p) => p && typeof p === "object" && p.type === "text").map((p) => p.text).filter(Boolean);
31
+ if (textParts.length > 0) return textParts.join("");
32
+ }
33
+ if (obj.text && typeof obj.text === "string") {
34
+ return obj.text;
35
+ }
36
+ if (obj.content && typeof obj.content === "string") {
37
+ return obj.content;
38
+ }
39
+ if (obj.message && typeof obj.message === "string") {
40
+ return obj.message;
41
+ }
42
+ if (typeof data === "string") {
43
+ return data;
44
+ }
45
+ return null;
46
+ }
47
+ export {
48
+ base64Decode,
49
+ base64Encode,
50
+ extractTextFromResponse,
51
+ sleep,
52
+ truncate
53
+ };
@@ -6,9 +6,9 @@ import type { OpenCodeLanguage, OpenCodeSettings } from "./types.js";
6
6
  /** 默认主机名 */
7
7
  export declare const DEFAULT_HOSTNAME = "127.0.0.1";
8
8
  /** 默认 Web 服务端口 */
9
- export declare const DEFAULT_WEB_PORT = 4097;
9
+ export declare const DEFAULT_WEB_PORT = 5097;
10
10
  /** 默认代理服务端口 */
11
- export declare const DEFAULT_PROXY_PORT = 4098;
11
+ export declare const DEFAULT_PROXY_PORT = 6097;
12
12
  /** 服务器启动超时时间(毫秒) */
13
13
  export declare const SERVER_START_TIMEOUT = 300000;
14
14
  /** 服务器检查间隔(毫秒) */
@@ -78,6 +78,10 @@ export declare const DEFAULT_OPENCODE_SETTINGS: {
78
78
  export declare const MAX_TEXT_LENGTH = 100;
79
79
  /** 元素上下文标记 */
80
80
  export declare const CONTEXT_MARKER = "[\u5143\u7D20\u4E0A\u4E0B\u6587]";
81
+ /** 页面上下文内部标记(用于插件) */
82
+ export declare const PAGE_CONTEXT_MARKER = "__OPENCODE_CONTEXT__";
83
+ /** 页面上下文文本最大长度 */
84
+ export declare const PAGE_CONTEXT_MAX_TEXT_LENGTH = 10000;
81
85
  /** ==================== 默认配置 ==================== */
82
86
  /** 默认插件配置 */
83
87
  export declare const DEFAULT_CONFIG: {
package/lib/constants.js CHANGED
@@ -35,6 +35,8 @@ __export(constants_exports, {
35
35
  MAX_TEXT_LENGTH: () => MAX_TEXT_LENGTH,
36
36
  NOTIFICATION_DURATION: () => NOTIFICATION_DURATION,
37
37
  OPENCODE_STORAGE_KEYS: () => OPENCODE_STORAGE_KEYS,
38
+ PAGE_CONTEXT_MARKER: () => PAGE_CONTEXT_MARKER,
39
+ PAGE_CONTEXT_MAX_TEXT_LENGTH: () => PAGE_CONTEXT_MAX_TEXT_LENGTH,
38
40
  RETRY_DELAY: () => RETRY_DELAY,
39
41
  SELECTED_ELEMENTS_KEY: () => SELECTED_ELEMENTS_KEY,
40
42
  SERVER_CHECK_INTERVAL: () => SERVER_CHECK_INTERVAL,
@@ -49,8 +51,8 @@ __export(constants_exports, {
49
51
  });
50
52
  module.exports = __toCommonJS(constants_exports);
51
53
  const DEFAULT_HOSTNAME = "127.0.0.1";
52
- const DEFAULT_WEB_PORT = 4097;
53
- const DEFAULT_PROXY_PORT = 4098;
54
+ const DEFAULT_WEB_PORT = 5097;
55
+ const DEFAULT_PROXY_PORT = 6097;
54
56
  const SERVER_START_TIMEOUT = 3e5;
55
57
  const SERVER_CHECK_INTERVAL = 100;
56
58
  const DEFAULT_RETRIES = 5;
@@ -87,6 +89,8 @@ const DEFAULT_OPENCODE_SETTINGS = {
87
89
  };
88
90
  const MAX_TEXT_LENGTH = 100;
89
91
  const CONTEXT_MARKER = "[\u5143\u7D20\u4E0A\u4E0B\u6587]";
92
+ const PAGE_CONTEXT_MARKER = "__OPENCODE_CONTEXT__";
93
+ const PAGE_CONTEXT_MAX_TEXT_LENGTH = 1e4;
90
94
  const DEFAULT_CONFIG = {
91
95
  enabled: true,
92
96
  webPort: DEFAULT_WEB_PORT,
@@ -122,6 +126,8 @@ const DEFAULT_CONFIG = {
122
126
  MAX_TEXT_LENGTH,
123
127
  NOTIFICATION_DURATION,
124
128
  OPENCODE_STORAGE_KEYS,
129
+ PAGE_CONTEXT_MARKER,
130
+ PAGE_CONTEXT_MAX_TEXT_LENGTH,
125
131
  RETRY_DELAY,
126
132
  SELECTED_ELEMENTS_KEY,
127
133
  SERVER_CHECK_INTERVAL,
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./constants.js";
2
2
  export * from "./logger.js";
3
3
  export * from "./types.js";
4
+ export * from "./utils.js";
package/lib/index.js CHANGED
@@ -17,9 +17,11 @@ module.exports = __toCommonJS(lib_exports);
17
17
  __reExport(lib_exports, require("./constants.js"), module.exports);
18
18
  __reExport(lib_exports, require("./logger.js"), module.exports);
19
19
  __reExport(lib_exports, require("./types.js"), module.exports);
20
+ __reExport(lib_exports, require("./utils.js"), module.exports);
20
21
  // Annotate the CommonJS export names for ESM import in node:
21
22
  0 && (module.exports = {
22
23
  ...require("./constants.js"),
23
24
  ...require("./logger.js"),
24
- ...require("./types.js")
25
+ ...require("./types.js"),
26
+ ...require("./utils.js")
25
27
  });
package/lib/logger.js CHANGED
@@ -214,6 +214,17 @@ function log(level, message, context, ...args) {
214
214
  if (formattedArgs) {
215
215
  parts.push(formattedArgs);
216
216
  }
217
+ if (context == null ? void 0 : context.error) {
218
+ const err = context.error;
219
+ if (err instanceof Error) {
220
+ parts.push(`${COLORS.red}Error: ${err.message}${COLORS.reset}`);
221
+ if (level >= 3 /* ERROR */ && globalConfig.showTrace && err.stack) {
222
+ console.error(`${COLORS.dim}${err.stack}${COLORS.reset}`);
223
+ }
224
+ } else {
225
+ parts.push(`${COLORS.red}Error: ${formatValue(err)}${COLORS.reset}`);
226
+ }
227
+ }
217
228
  const output = parts.join(" ");
218
229
  if (level >= 3 /* ERROR */) {
219
230
  console.error(output);
@@ -222,12 +233,6 @@ function log(level, message, context, ...args) {
222
233
  } else {
223
234
  console.log(output);
224
235
  }
225
- if ((context == null ? void 0 : context.error) && level >= 3 /* ERROR */ && globalConfig.showTrace) {
226
- const err = context.error;
227
- if (err instanceof Error && err.stack) {
228
- console.error(`${COLORS.dim}${err.stack}${COLORS.reset}`);
229
- }
230
- }
231
236
  }
232
237
  const logger = {
233
238
  debug(message, context, ...args) {
package/lib/types.d.ts CHANGED
@@ -195,3 +195,124 @@ export interface PageContext {
195
195
  /** 选中的元素列表 */
196
196
  selectedElements?: SelectedElement[];
197
197
  }
198
+ /**
199
+ * 服务启动任务状态
200
+ */
201
+ export type ServiceStartupTask = "checking_opencode" | "allocating_port" | "preparing_runtime" | "starting_web" | "waiting_web_ready" | "starting_proxy" | "warming_up_chrome" | "creating_session" | "opencode_not_installed" | "web_start_timeout" | "session_creation_failed" | "chrome_mcp_failed" | "ready";
202
+ /**
203
+ * 服务启动任务状态映射
204
+ */
205
+ export declare const SERVICE_STARTUP_TASKS: Record<ServiceStartupTask, string>;
206
+ /**
207
+ * 挂件位置选项
208
+ */
209
+ export type OpenCodeWidgetPosition = "bottom-right" | "bottom-left" | "top-right" | "top-left";
210
+ /**
211
+ * 挂件主题选项
212
+ */
213
+ export type OpenCodeWidgetTheme = "light" | "dark" | "auto";
214
+ /**
215
+ * 服务状态
216
+ */
217
+ export type ServiceStatus = "idle" | "starting" | "ready" | "partial" | "failed";
218
+ /**
219
+ * 挂件会话信息
220
+ */
221
+ export interface OpenCodeWidgetSession {
222
+ id: string;
223
+ title?: string;
224
+ updatedAt?: string | number | Date;
225
+ meta?: string;
226
+ directory?: string;
227
+ }
228
+ /**
229
+ * 挂件选中的元素
230
+ */
231
+ export interface OpenCodeSelectedElement {
232
+ filePath: string | null;
233
+ line: number | null;
234
+ column: number | null;
235
+ innerText: string;
236
+ description?: string;
237
+ }
238
+ /**
239
+ * 删除选中节点的载荷
240
+ */
241
+ export interface OpenCodeRemoveSelectedPayload {
242
+ element: OpenCodeSelectedElement;
243
+ index: number;
244
+ source: "panel" | "bubble";
245
+ }
246
+ /**
247
+ * 挂件会话列表项
248
+ */
249
+ export interface OpenCodeWidgetSessionItem {
250
+ key: string;
251
+ id: string;
252
+ title: string;
253
+ meta: string;
254
+ active: boolean;
255
+ session: OpenCodeWidgetSession;
256
+ [key: string]: any;
257
+ }
258
+ /**
259
+ * 选中元素列表项
260
+ */
261
+ export interface OpenCodeSelectedElementItem {
262
+ key: string;
263
+ description: string;
264
+ bubbleFileText: string;
265
+ panelFileText: string;
266
+ element: OpenCodeSelectedElement;
267
+ }
268
+ /**
269
+ * 挂件组件 Props
270
+ */
271
+ export interface OpenCodeWidgetProps {
272
+ position?: OpenCodeWidgetPosition;
273
+ open?: boolean;
274
+ theme?: OpenCodeWidgetTheme;
275
+ title?: string;
276
+ hotkeyLabel?: string;
277
+ selectShortcutLabel?: string;
278
+ selectMode?: boolean;
279
+ sessionListCollapsed?: boolean;
280
+ sessionKey?: string;
281
+ frameLoading?: boolean;
282
+ loadingSessionList?: boolean;
283
+ showSessionListSkeleton?: boolean;
284
+ showEmptyState?: boolean;
285
+ showError?: boolean;
286
+ emptyStateText?: string;
287
+ emptyStateActionText?: string;
288
+ iframeSrc?: string;
289
+ sessions?: OpenCodeWidgetSession[];
290
+ currentSessionId?: string | null;
291
+ selectedElements?: OpenCodeSelectedElement[];
292
+ showClearAll?: boolean;
293
+ selectEnabled?: boolean;
294
+ }
295
+ /**
296
+ * 挂件组件事件
297
+ */
298
+ export type OpenCodeWidgetEmits = {
299
+ (e: "update:open", value: boolean): void;
300
+ (e: "update:selectMode", value: boolean): void;
301
+ (e: "update:sessionListCollapsed", value: boolean): void;
302
+ (e: "update:currentSessionId", value: string | null): void;
303
+ (e: "update:selectedElements", value: OpenCodeSelectedElement[]): void;
304
+ (e: "update:theme", value: OpenCodeWidgetTheme): void;
305
+ (e: "toggle", value: boolean): void;
306
+ (e: "close"): void;
307
+ (e: "toggle-session-list", value: boolean): void;
308
+ (e: "toggle-select-mode", value: boolean): void;
309
+ (e: "toggle-theme", value: OpenCodeWidgetTheme): void;
310
+ (e: "create-session"): void;
311
+ (e: "select-session", session: OpenCodeWidgetSession): void;
312
+ (e: "delete-session", session: OpenCodeWidgetSession): void;
313
+ (e: "click-selected-node", element: OpenCodeSelectedElement): void;
314
+ (e: "remove-selected-node", payload: OpenCodeRemoveSelectedPayload): void;
315
+ (e: "clear-selected-nodes"): void;
316
+ (e: "empty-action"): void;
317
+ (e: "frame-loaded"): void;
318
+ };
package/lib/types.js CHANGED
@@ -2,6 +2,10 @@ var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
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
+ };
5
9
  var __copyProps = (to, from, except, desc) => {
6
10
  if (from && typeof from === "object" || typeof from === "function") {
7
11
  for (let key of __getOwnPropNames(from))
@@ -12,4 +16,26 @@ var __copyProps = (to, from, except, desc) => {
12
16
  };
13
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
18
  var types_exports = {};
19
+ __export(types_exports, {
20
+ SERVICE_STARTUP_TASKS: () => SERVICE_STARTUP_TASKS
21
+ });
15
22
  module.exports = __toCommonJS(types_exports);
23
+ const SERVICE_STARTUP_TASKS = {
24
+ checking_opencode: "\u68C0\u67E5 OpenCode \u5B89\u88C5",
25
+ allocating_port: "\u5206\u914D\u670D\u52A1\u7AEF\u53E3",
26
+ preparing_runtime: "\u51C6\u5907\u8FD0\u884C\u73AF\u5883",
27
+ starting_web: "\u542F\u52A8 OpenCode Web",
28
+ waiting_web_ready: "\u7B49\u5F85\u670D\u52A1\u5C31\u7EEA",
29
+ starting_proxy: "\u542F\u52A8\u4EE3\u7406\u670D\u52A1",
30
+ warming_up_chrome: "\u9884\u70ED Chrome DevTools",
31
+ creating_session: "\u521B\u5EFA\u4F1A\u8BDD",
32
+ opencode_not_installed: "OpenCode \u672A\u5B89\u88C5",
33
+ web_start_timeout: "\u670D\u52A1\u542F\u52A8\u8D85\u65F6",
34
+ session_creation_failed: "\u4F1A\u8BDD\u521B\u5EFA\u5931\u8D25",
35
+ chrome_mcp_failed: "Chrome DevTools \u8FDE\u63A5\u5931\u8D25",
36
+ ready: "\u51C6\u5907\u5B8C\u6210"
37
+ };
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ SERVICE_STARTUP_TASKS
41
+ });
package/lib/utils.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @fileoverview 通用工具函数
3
+ */
4
+ /**
5
+ * 截断字符串到指定长度
6
+ * @param value - 要截断的字符串
7
+ * @param maxLength - 最大长度
8
+ * @returns 截断后的字符串,如果超出长度则添加省略号
9
+ */
10
+ export declare function truncate(value: string, maxLength: number): string;
11
+ /**
12
+ * 延迟指定时间
13
+ * @param ms - 毫秒数
14
+ * @returns Promise
15
+ */
16
+ export declare function sleep(ms: number): Promise<void>;
17
+ /**
18
+ * 将字符串编码为 Base64
19
+ * @param str - 要编码的字符串
20
+ * @returns Base64 编码的字符串
21
+ */
22
+ export declare function base64Encode(str: string): string;
23
+ /**
24
+ * 将 Base64 解码为字符串
25
+ * @param base64 - Base64 编码的字符串
26
+ * @returns 解码后的字符串
27
+ */
28
+ export declare function base64Decode(base64: string): string;
29
+ /**
30
+ * 从响应数据中提取文本内容
31
+ * 支持多种常见响应格式
32
+ */
33
+ export declare function extractTextFromResponse(data: unknown): string | null;
package/lib/utils.js ADDED
@@ -0,0 +1,80 @@
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 utils_exports = {};
19
+ __export(utils_exports, {
20
+ base64Decode: () => base64Decode,
21
+ base64Encode: () => base64Encode,
22
+ extractTextFromResponse: () => extractTextFromResponse,
23
+ sleep: () => sleep,
24
+ truncate: () => truncate
25
+ });
26
+ module.exports = __toCommonJS(utils_exports);
27
+ function truncate(value, maxLength) {
28
+ if (value.length <= maxLength) {
29
+ return value;
30
+ }
31
+ return `${value.slice(0, maxLength)}...`;
32
+ }
33
+ function sleep(ms) {
34
+ return new Promise((resolve) => setTimeout(resolve, ms));
35
+ }
36
+ function base64Encode(str) {
37
+ if (typeof Buffer !== "undefined") {
38
+ return Buffer.from(str).toString("base64");
39
+ }
40
+ const bytes = new TextEncoder().encode(str);
41
+ const binString = Array.from(bytes, (byte) => String.fromCodePoint(byte)).join("");
42
+ return btoa(binString);
43
+ }
44
+ function base64Decode(base64) {
45
+ if (typeof Buffer !== "undefined") {
46
+ return Buffer.from(base64, "base64").toString("utf-8");
47
+ }
48
+ const binString = atob(base64);
49
+ const bytes = Uint8Array.from(binString, (c) => c.charCodeAt(0));
50
+ return new TextDecoder().decode(bytes);
51
+ }
52
+ function extractTextFromResponse(data) {
53
+ if (!data || typeof data !== "object") return null;
54
+ const obj = data;
55
+ if (obj.parts && Array.isArray(obj.parts)) {
56
+ const textParts = obj.parts.filter((p) => p && typeof p === "object" && p.type === "text").map((p) => p.text).filter(Boolean);
57
+ if (textParts.length > 0) return textParts.join("");
58
+ }
59
+ if (obj.text && typeof obj.text === "string") {
60
+ return obj.text;
61
+ }
62
+ if (obj.content && typeof obj.content === "string") {
63
+ return obj.content;
64
+ }
65
+ if (obj.message && typeof obj.message === "string") {
66
+ return obj.message;
67
+ }
68
+ if (typeof data === "string") {
69
+ return data;
70
+ }
71
+ return null;
72
+ }
73
+ // Annotate the CommonJS export names for ESM import in node:
74
+ 0 && (module.exports = {
75
+ base64Decode,
76
+ base64Encode,
77
+ extractTextFromResponse,
78
+ sleep,
79
+ truncate
80
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-plugin-opencode-assistant/shared",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -22,6 +22,6 @@
22
22
  },
23
23
  "scripts": {
24
24
  "build": "pagoda-cli build",
25
- "typecheck": "tsc -p tsconfig.json --noEmit"
25
+ "typecheck": "tsc -p tsconfig.declaration.json --noEmit"
26
26
  }
27
27
  }