vite-plugin-opencode-assistant 1.0.27 → 1.0.28
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 +64 -36
- package/es/client/composables/index.d.ts +10 -0
- package/es/client/composables/index.js +22 -0
- package/es/client/composables/useOpencodeSSE.d.ts +64 -0
- package/es/client/composables/useOpencodeSSE.js +29 -0
- package/es/client/composables/useOpencodeSessionSSE.d.ts +66 -0
- package/es/client/composables/useOpencodeSessionSSE.js +168 -0
- package/es/client/composables/useSSE.d.ts +85 -18
- package/es/client/composables/useSSE.js +101 -44
- package/es/client/composables/useServerSSE.d.ts +53 -0
- package/es/client/composables/useServerSSE.js +36 -0
- package/es/client/composables/useServiceStatus.d.ts +0 -2
- package/es/client/composables/useServiceStatus.js +1 -7
- package/es/client/composables/useSessions.d.ts +24 -5
- package/es/client/composables/useSessions.js +16 -2
- package/es/core/proxy-server.js +38 -148
- package/es/index.js +3 -1
- package/lib/client/App.vue.js +63 -35
- package/lib/client/composables/index.d.ts +10 -0
- package/lib/client/composables/index.js +54 -0
- package/lib/client/composables/useOpencodeSSE.d.ts +64 -0
- package/lib/client/composables/useOpencodeSSE.js +52 -0
- package/lib/client/composables/useOpencodeSessionSSE.d.ts +66 -0
- package/lib/client/composables/useOpencodeSessionSSE.js +187 -0
- package/lib/client/composables/useSSE.d.ts +85 -18
- package/lib/client/composables/useSSE.js +100 -43
- package/lib/client/composables/useServerSSE.d.ts +53 -0
- package/lib/client/composables/useServerSSE.js +59 -0
- package/lib/client/composables/useServiceStatus.d.ts +0 -2
- package/lib/client/composables/useServiceStatus.js +1 -7
- package/lib/client/composables/useSessions.d.ts +24 -5
- package/lib/client/composables/useSessions.js +16 -2
- package/lib/client.js +2823 -2566
- package/lib/core/proxy-server.js +38 -148
- package/lib/index.js +3 -1
- package/lib/style.css +1 -1
- package/package.json +4 -4
|
@@ -1,20 +1,87 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { type Ref } from "vue";
|
|
2
|
+
/**
|
|
3
|
+
* SSE 连接状态
|
|
4
|
+
*/
|
|
5
|
+
export type SSEConnectionStatus = "idle" | "connecting" | "connected" | "disconnected" | "error";
|
|
6
|
+
/**
|
|
7
|
+
* SSE 配置选项
|
|
8
|
+
*/
|
|
9
|
+
export interface SSEOptions {
|
|
10
|
+
/** SSE 端点 URL */
|
|
11
|
+
endpoint: string;
|
|
12
|
+
/** 是否自动连接 */
|
|
13
|
+
autoConnect?: boolean;
|
|
14
|
+
/** 是否启用 (响应式) */
|
|
15
|
+
enabled?: Ref<boolean>;
|
|
16
|
+
/** 最大重试次数 */
|
|
17
|
+
maxRetries?: number;
|
|
18
|
+
/** 重试延迟基数 (ms) */
|
|
19
|
+
retryDelay?: number;
|
|
20
|
+
/** 连接成功回调 */
|
|
21
|
+
onConnected?: () => void;
|
|
22
|
+
/** 连接断开回调 */
|
|
23
|
+
onDisconnected?: () => void;
|
|
24
|
+
/** 连接错误回调 */
|
|
25
|
+
onError?: (error: Error) => void;
|
|
26
|
+
/** 消息处理回调 */
|
|
27
|
+
onMessage?: (data: unknown) => void;
|
|
8
28
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
29
|
+
/**
|
|
30
|
+
* 通用 SSE 连接管理
|
|
31
|
+
* 提供基础的连接、重连、状态管理功能
|
|
32
|
+
*/
|
|
33
|
+
export declare function useSSE(options: SSEOptions): {
|
|
34
|
+
connection: Ref<{
|
|
35
|
+
onerror: ((this: EventSource, ev: Event) => any) | null;
|
|
36
|
+
onmessage: ((this: EventSource, ev: MessageEvent) => any) | null;
|
|
37
|
+
onopen: ((this: EventSource, ev: Event) => any) | null;
|
|
38
|
+
readonly readyState: number;
|
|
39
|
+
readonly url: string;
|
|
40
|
+
readonly withCredentials: boolean;
|
|
41
|
+
close: () => void;
|
|
42
|
+
readonly CONNECTING: 0;
|
|
43
|
+
readonly OPEN: 1;
|
|
44
|
+
readonly CLOSED: 2;
|
|
45
|
+
addEventListener: {
|
|
46
|
+
<K extends keyof EventSourceEventMap>(type: K, listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
47
|
+
(type: string, listener: (this: EventSource, event: MessageEvent) => any, options?: boolean | AddEventListenerOptions): void;
|
|
48
|
+
(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
49
|
+
};
|
|
50
|
+
removeEventListener: {
|
|
51
|
+
<K extends keyof EventSourceEventMap>(type: K, listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
|
|
52
|
+
(type: string, listener: (this: EventSource, event: MessageEvent) => any, options?: boolean | EventListenerOptions): void;
|
|
53
|
+
(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
|
|
54
|
+
};
|
|
55
|
+
dispatchEvent: (event: Event) => boolean;
|
|
56
|
+
} | null, EventSource | {
|
|
57
|
+
onerror: ((this: EventSource, ev: Event) => any) | null;
|
|
58
|
+
onmessage: ((this: EventSource, ev: MessageEvent) => any) | null;
|
|
59
|
+
onopen: ((this: EventSource, ev: Event) => any) | null;
|
|
60
|
+
readonly readyState: number;
|
|
61
|
+
readonly url: string;
|
|
62
|
+
readonly withCredentials: boolean;
|
|
63
|
+
close: () => void;
|
|
64
|
+
readonly CONNECTING: 0;
|
|
65
|
+
readonly OPEN: 1;
|
|
66
|
+
readonly CLOSED: 2;
|
|
67
|
+
addEventListener: {
|
|
68
|
+
<K extends keyof EventSourceEventMap>(type: K, listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
69
|
+
(type: string, listener: (this: EventSource, event: MessageEvent) => any, options?: boolean | AddEventListenerOptions): void;
|
|
70
|
+
(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
71
|
+
};
|
|
72
|
+
removeEventListener: {
|
|
73
|
+
<K extends keyof EventSourceEventMap>(type: K, listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
|
|
74
|
+
(type: string, listener: (this: EventSource, event: MessageEvent) => any, options?: boolean | EventListenerOptions): void;
|
|
75
|
+
(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
|
|
76
|
+
};
|
|
77
|
+
dispatchEvent: (event: Event) => boolean;
|
|
78
|
+
} | null>;
|
|
79
|
+
status: Ref<SSEConnectionStatus, SSEConnectionStatus>;
|
|
80
|
+
retryCount: Ref<number, number>;
|
|
81
|
+
isConnected: import("vue").ComputedRef<boolean>;
|
|
82
|
+
isConnecting: import("vue").ComputedRef<boolean>;
|
|
83
|
+
connect: () => void;
|
|
84
|
+
disconnect: () => void;
|
|
85
|
+
reconnect: () => void;
|
|
86
|
+
resetRetryCount: () => void;
|
|
19
87
|
};
|
|
20
|
-
export {};
|
|
@@ -21,61 +21,118 @@ __export(useSSE_exports, {
|
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(useSSE_exports);
|
|
23
23
|
var import_vue = require("vue");
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
function useSSE(
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
const DEFAULT_MAX_RETRIES = 10;
|
|
25
|
+
const DEFAULT_RETRY_DELAY = 1e3;
|
|
26
|
+
function useSSE(options) {
|
|
27
|
+
const {
|
|
28
|
+
endpoint,
|
|
29
|
+
autoConnect = true,
|
|
30
|
+
enabled,
|
|
31
|
+
maxRetries = DEFAULT_MAX_RETRIES,
|
|
32
|
+
retryDelay = DEFAULT_RETRY_DELAY,
|
|
33
|
+
onConnected,
|
|
34
|
+
onDisconnected,
|
|
35
|
+
onError,
|
|
36
|
+
onMessage
|
|
37
|
+
} = options;
|
|
38
|
+
const connection = (0, import_vue.ref)(null);
|
|
39
|
+
const status = (0, import_vue.ref)("idle");
|
|
40
|
+
const retryCount = (0, import_vue.ref)(0);
|
|
41
|
+
function handleMessage(event) {
|
|
31
42
|
try {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
const data = JSON.parse(event.data);
|
|
44
|
+
onMessage == null ? void 0 : onMessage(data);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
onMessage == null ? void 0 : onMessage(event.data);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function connect() {
|
|
50
|
+
if (connection.value || status.value === "connecting") {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if ((enabled == null ? void 0 : enabled.value) === false) {
|
|
54
|
+
status.value = "idle";
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
status.value = "connecting";
|
|
58
|
+
retryCount.value = 0;
|
|
59
|
+
try {
|
|
60
|
+
connection.value = new EventSource(endpoint);
|
|
61
|
+
connection.value.onopen = () => {
|
|
62
|
+
status.value = "connected";
|
|
63
|
+
retryCount.value = 0;
|
|
64
|
+
onConnected == null ? void 0 : onConnected();
|
|
48
65
|
};
|
|
49
|
-
|
|
66
|
+
connection.value.onmessage = handleMessage;
|
|
67
|
+
connection.value.onerror = () => {
|
|
50
68
|
var _a;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
69
|
+
const wasConnected = status.value === "connected";
|
|
70
|
+
status.value = "error";
|
|
71
|
+
(_a = connection.value) == null ? void 0 : _a.close();
|
|
72
|
+
connection.value = null;
|
|
73
|
+
const error = new Error(`SSE connection error: ${endpoint}`);
|
|
74
|
+
onError == null ? void 0 : onError(error);
|
|
75
|
+
if (retryCount.value < maxRetries) {
|
|
76
|
+
retryCount.value++;
|
|
77
|
+
const delay = retryDelay * retryCount.value;
|
|
78
|
+
setTimeout(() => {
|
|
79
|
+
if ((enabled == null ? void 0 : enabled.value) !== false && !connection.value) {
|
|
80
|
+
connect();
|
|
81
|
+
}
|
|
82
|
+
}, delay);
|
|
83
|
+
} else if (wasConnected) {
|
|
84
|
+
onDisconnected == null ? void 0 : onDisconnected();
|
|
56
85
|
}
|
|
57
86
|
};
|
|
58
87
|
} catch (e) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
88
|
+
status.value = "error";
|
|
89
|
+
const error = e instanceof Error ? e : new Error(String(e));
|
|
90
|
+
onError == null ? void 0 : onError(error);
|
|
91
|
+
if (retryCount.value < maxRetries) {
|
|
92
|
+
retryCount.value++;
|
|
93
|
+
const delay = retryDelay * retryCount.value;
|
|
94
|
+
setTimeout(() => {
|
|
95
|
+
if (!connection.value) {
|
|
96
|
+
connect();
|
|
97
|
+
}
|
|
98
|
+
}, delay);
|
|
63
99
|
}
|
|
64
100
|
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
101
|
+
}
|
|
102
|
+
function disconnect() {
|
|
103
|
+
if (connection.value) {
|
|
104
|
+
connection.value.close();
|
|
105
|
+
connection.value = null;
|
|
106
|
+
status.value = "disconnected";
|
|
107
|
+
retryCount.value = 0;
|
|
108
|
+
onDisconnected == null ? void 0 : onDisconnected();
|
|
70
109
|
}
|
|
71
|
-
}
|
|
110
|
+
}
|
|
111
|
+
function reconnect() {
|
|
112
|
+
disconnect();
|
|
113
|
+
connect();
|
|
114
|
+
}
|
|
115
|
+
function resetRetryCount() {
|
|
116
|
+
retryCount.value = 0;
|
|
117
|
+
}
|
|
118
|
+
if (autoConnect && (enabled == null ? void 0 : enabled.value) !== false) {
|
|
119
|
+
connect();
|
|
120
|
+
}
|
|
72
121
|
(0, import_vue.onUnmounted)(() => {
|
|
73
|
-
|
|
122
|
+
disconnect();
|
|
74
123
|
});
|
|
75
124
|
return {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
125
|
+
// 状态
|
|
126
|
+
connection,
|
|
127
|
+
status,
|
|
128
|
+
retryCount,
|
|
129
|
+
isConnected: (0, import_vue.computed)(() => status.value === "connected"),
|
|
130
|
+
isConnecting: (0, import_vue.computed)(() => status.value === "connecting"),
|
|
131
|
+
// 方法
|
|
132
|
+
connect,
|
|
133
|
+
disconnect,
|
|
134
|
+
reconnect,
|
|
135
|
+
resetRetryCount
|
|
79
136
|
};
|
|
80
137
|
}
|
|
81
138
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ServiceStartupTask } from "@vite-plugin-opencode-assistant/shared";
|
|
2
|
+
/**
|
|
3
|
+
* Server SSE 状态同步数据
|
|
4
|
+
*/
|
|
5
|
+
export interface ServerSSEStatusSyncData {
|
|
6
|
+
type: "STATUS_SYNC";
|
|
7
|
+
isStarted?: boolean;
|
|
8
|
+
task: ServiceStartupTask;
|
|
9
|
+
errorType?: string;
|
|
10
|
+
errorMessage?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Server SSE 任务更新数据
|
|
14
|
+
*/
|
|
15
|
+
export interface ServerSSETaskUpdateData {
|
|
16
|
+
type: "TASK_UPDATE";
|
|
17
|
+
task: ServiceStartupTask;
|
|
18
|
+
errorType?: string;
|
|
19
|
+
errorMessage?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Server SSE 消息类型
|
|
23
|
+
*/
|
|
24
|
+
export type ServerSSEMessage = {
|
|
25
|
+
type: "CONNECTED";
|
|
26
|
+
} | ServerSSEStatusSyncData | ServerSSETaskUpdateData | {
|
|
27
|
+
type: "CLEAR_ELEMENTS";
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Server SSE 配置选项
|
|
31
|
+
*/
|
|
32
|
+
export interface ServerSSEOptions {
|
|
33
|
+
/** 状态同步回调 */
|
|
34
|
+
onStatusSync?: (data: ServerSSEStatusSyncData) => void;
|
|
35
|
+
/** 任务更新回调 */
|
|
36
|
+
onTaskUpdate?: (data: ServerSSETaskUpdateData) => void;
|
|
37
|
+
/** 清除元素回调 */
|
|
38
|
+
onClearElements?: () => void;
|
|
39
|
+
/** 连接成功回调 */
|
|
40
|
+
onConnected?: () => void;
|
|
41
|
+
/** 是否启用 */
|
|
42
|
+
enabled?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 监听 Vite Server SSE 事件
|
|
46
|
+
* 端点: /__opencode_events__
|
|
47
|
+
*/
|
|
48
|
+
export declare function useServerSSE(options?: ServerSSEOptions): {
|
|
49
|
+
status: import("vue").Ref<import("./useSSE").SSEConnectionStatus, import("./useSSE").SSEConnectionStatus>;
|
|
50
|
+
isConnected: import("vue").ComputedRef<boolean>;
|
|
51
|
+
connect: () => void;
|
|
52
|
+
disconnect: () => void;
|
|
53
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
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 useServerSSE_exports = {};
|
|
19
|
+
__export(useServerSSE_exports, {
|
|
20
|
+
useServerSSE: () => useServerSSE
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(useServerSSE_exports);
|
|
23
|
+
var import_useSSE = require("./useSSE");
|
|
24
|
+
function useServerSSE(options = {}) {
|
|
25
|
+
const { onStatusSync, onTaskUpdate, onClearElements, onConnected } = options;
|
|
26
|
+
const { status, isConnected, connect, disconnect } = (0, import_useSSE.useSSE)({
|
|
27
|
+
endpoint: "/__opencode_events__",
|
|
28
|
+
autoConnect: false,
|
|
29
|
+
onMessage: (data) => {
|
|
30
|
+
const message = data;
|
|
31
|
+
switch (message.type) {
|
|
32
|
+
case "CONNECTED":
|
|
33
|
+
onConnected == null ? void 0 : onConnected();
|
|
34
|
+
break;
|
|
35
|
+
case "STATUS_SYNC":
|
|
36
|
+
onStatusSync == null ? void 0 : onStatusSync(message);
|
|
37
|
+
break;
|
|
38
|
+
case "TASK_UPDATE":
|
|
39
|
+
onTaskUpdate == null ? void 0 : onTaskUpdate(message);
|
|
40
|
+
break;
|
|
41
|
+
case "CLEAR_ELEMENTS":
|
|
42
|
+
onClearElements == null ? void 0 : onClearElements();
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
// 状态
|
|
49
|
+
status,
|
|
50
|
+
isConnected,
|
|
51
|
+
// 方法
|
|
52
|
+
connect,
|
|
53
|
+
disconnect
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
useServerSSE
|
|
59
|
+
});
|
|
@@ -5,9 +5,7 @@ export declare function useServiceStatus(): {
|
|
|
5
5
|
chromeMcpFailed: import("vue").Ref<boolean, boolean>;
|
|
6
6
|
chromeMcpErrorType: import("vue").Ref<string | undefined, string | undefined>;
|
|
7
7
|
chromeMcpErrorMessage: import("vue").Ref<string | undefined, string | undefined>;
|
|
8
|
-
thinking: import("vue").Ref<boolean, boolean>;
|
|
9
8
|
loadingText: import("vue").ComputedRef<string>;
|
|
10
9
|
updateStatusFromTask: (task: ServiceStartupTask | "", errorType?: string, errorMessage?: string) => void;
|
|
11
10
|
setStarting: () => void;
|
|
12
|
-
setThinking: (value: boolean) => void;
|
|
13
11
|
};
|
|
@@ -28,7 +28,6 @@ function useServiceStatus() {
|
|
|
28
28
|
const chromeMcpFailed = (0, import_vue.ref)(false);
|
|
29
29
|
const chromeMcpErrorType = (0, import_vue.ref)(void 0);
|
|
30
30
|
const chromeMcpErrorMessage = (0, import_vue.ref)(void 0);
|
|
31
|
-
const thinking = (0, import_vue.ref)(false);
|
|
32
31
|
const loadingText = (0, import_vue.computed)(() => {
|
|
33
32
|
if (!currentTask.value) return "\u52A0\u8F7D\u4E2D...";
|
|
34
33
|
return import_shared.SERVICE_STARTUP_TASKS[currentTask.value] || "\u52A0\u8F7D\u4E2D...";
|
|
@@ -54,20 +53,15 @@ function useServiceStatus() {
|
|
|
54
53
|
const setStarting = () => {
|
|
55
54
|
serviceStatus.value = "starting";
|
|
56
55
|
};
|
|
57
|
-
const setThinking = (value) => {
|
|
58
|
-
thinking.value = value;
|
|
59
|
-
};
|
|
60
56
|
return {
|
|
61
57
|
currentTask,
|
|
62
58
|
serviceStatus,
|
|
63
59
|
chromeMcpFailed,
|
|
64
60
|
chromeMcpErrorType,
|
|
65
61
|
chromeMcpErrorMessage,
|
|
66
|
-
thinking,
|
|
67
62
|
loadingText,
|
|
68
63
|
updateStatusFromTask,
|
|
69
|
-
setStarting
|
|
70
|
-
setThinking
|
|
64
|
+
setStarting
|
|
71
65
|
};
|
|
72
66
|
}
|
|
73
67
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,6 +1,18 @@
|
|
|
1
|
+
import { type Ref } from "vue";
|
|
1
2
|
import type { OpenCodeWidgetSession } from "@vite-plugin-opencode-assistant/shared";
|
|
2
|
-
export
|
|
3
|
-
|
|
3
|
+
export interface UseSessionsOptions {
|
|
4
|
+
showNotification: (msg: string) => void;
|
|
5
|
+
/** Session 更新回调 (从 SSE 事件接收) */
|
|
6
|
+
onSessionUpdate?: Ref<((session: {
|
|
7
|
+
id: string;
|
|
8
|
+
title?: string;
|
|
9
|
+
time?: {
|
|
10
|
+
updated?: number;
|
|
11
|
+
};
|
|
12
|
+
}) => void) | undefined>;
|
|
13
|
+
}
|
|
14
|
+
export declare function useSessions(options: UseSessionsOptions): {
|
|
15
|
+
sessions: Ref<{
|
|
4
16
|
id: string;
|
|
5
17
|
title?: string | undefined;
|
|
6
18
|
updatedAt?: (string | number | Date) | undefined;
|
|
@@ -15,12 +27,19 @@ export declare function useSessions(showNotification: (msg: string) => void): {
|
|
|
15
27
|
directory?: string | undefined;
|
|
16
28
|
url?: string | undefined;
|
|
17
29
|
}[]>;
|
|
18
|
-
loadingSessionList:
|
|
19
|
-
currentSessionId:
|
|
30
|
+
loadingSessionList: Ref<boolean | undefined, boolean | undefined>;
|
|
31
|
+
currentSessionId: Ref<string | null, string | null>;
|
|
20
32
|
iframeSrc: import("vue").ComputedRef<string>;
|
|
21
|
-
iframeLoading:
|
|
33
|
+
iframeLoading: Ref<boolean, boolean>;
|
|
22
34
|
loadSessions: () => Promise<void>;
|
|
23
35
|
createSession: () => Promise<void>;
|
|
24
36
|
deleteSession: (session: OpenCodeWidgetSession) => Promise<void>;
|
|
25
37
|
selectSession: (session: OpenCodeWidgetSession) => void;
|
|
38
|
+
updateSessionInfo: (sessionUpdate: {
|
|
39
|
+
id: string;
|
|
40
|
+
title?: string;
|
|
41
|
+
time?: {
|
|
42
|
+
updated?: number;
|
|
43
|
+
};
|
|
44
|
+
}) => void;
|
|
26
45
|
};
|
|
@@ -59,7 +59,8 @@ __export(useSessions_exports, {
|
|
|
59
59
|
module.exports = __toCommonJS(useSessions_exports);
|
|
60
60
|
var import_vue = require("vue");
|
|
61
61
|
var import_shared = require("@vite-plugin-opencode-assistant/shared");
|
|
62
|
-
function useSessions(
|
|
62
|
+
function useSessions(options) {
|
|
63
|
+
const { showNotification } = options;
|
|
63
64
|
const sessions = (0, import_vue.ref)([]);
|
|
64
65
|
const loadingSessionList = (0, import_vue.ref)(void 0);
|
|
65
66
|
const currentSessionId = (0, import_vue.ref)(null);
|
|
@@ -90,6 +91,18 @@ function useSessions(showNotification) {
|
|
|
90
91
|
loadingSessionList.value = false;
|
|
91
92
|
}
|
|
92
93
|
});
|
|
94
|
+
const updateSessionInfo = (sessionUpdate) => {
|
|
95
|
+
var _a;
|
|
96
|
+
const index = sessions.value.findIndex((s) => s.id === sessionUpdate.id);
|
|
97
|
+
if (index === -1) return;
|
|
98
|
+
const session = sessions.value[index];
|
|
99
|
+
if (sessionUpdate.title && sessionUpdate.title !== session.title) {
|
|
100
|
+
sessions.value[index] = __spreadProps(__spreadValues({}, session), {
|
|
101
|
+
title: sessionUpdate.title,
|
|
102
|
+
updatedAt: ((_a = sessionUpdate.time) == null ? void 0 : _a.updated) || Date.now()
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
};
|
|
93
106
|
const createSession = () => __async(null, null, function* () {
|
|
94
107
|
try {
|
|
95
108
|
const response = yield fetch(import_shared.SESSIONS_API_PATH, { method: "POST" });
|
|
@@ -139,7 +152,8 @@ function useSessions(showNotification) {
|
|
|
139
152
|
loadSessions,
|
|
140
153
|
createSession,
|
|
141
154
|
deleteSession,
|
|
142
|
-
selectSession
|
|
155
|
+
selectSession,
|
|
156
|
+
updateSessionInfo
|
|
143
157
|
};
|
|
144
158
|
}
|
|
145
159
|
// Annotate the CommonJS export names for ESM import in node:
|