vite-plugin-opencode-assistant 1.0.73 → 1.0.75
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/core/injector.mjs +6 -2
- package/es/core/proxy-server.mjs +19 -13
- package/es/endpoints/index.d.ts +1 -1
- package/es/endpoints/index.mjs +3 -2
- package/es/endpoints/logs.d.ts +0 -2
- package/es/endpoints/logs.mjs +4 -4
- package/es/endpoints/start.d.ts +2 -1
- package/es/endpoints/start.mjs +6 -2
- package/es/endpoints/types.d.ts +2 -0
- package/es/endpoints/warmup.mjs +2 -2
- package/es/endpoints/widget.mjs +1 -2
- package/es/env.d.ts +1 -0
- package/es/index.mjs +7 -1
- package/lib/client.js +3473 -3274
- package/lib/core/injector.cjs +1 -1
- package/lib/core/proxy-server.cjs +16 -12
- package/lib/endpoints/index.cjs +3 -2
- package/lib/endpoints/index.d.ts +1 -1
- package/lib/endpoints/logs.cjs +2 -5
- package/lib/endpoints/logs.d.ts +0 -2
- package/lib/endpoints/start.cjs +6 -2
- package/lib/endpoints/start.d.ts +2 -1
- package/lib/endpoints/types.d.ts +2 -0
- package/lib/endpoints/warmup.cjs +1 -1
- package/lib/endpoints/widget.cjs +2 -3
- package/lib/env.d.ts +1 -0
- package/lib/index.cjs +7 -1
- package/lib/style.css +1 -1
- package/package.json +8 -4
- package/es/client/App.vue.d.ts +0 -6
- package/es/client/App.vue.mjs +0 -394
- package/es/client/components/ChromeWarmupError-sfc.css +0 -1
- package/es/client/components/ChromeWarmupError.vue.d.ts +0 -19
- package/es/client/components/ChromeWarmupError.vue.mjs +0 -337
- package/es/client/components/LoadingContent.vue.d.ts +0 -5
- package/es/client/components/LoadingContent.vue.mjs +0 -39
- package/es/client/composables/index.d.ts +0 -10
- package/es/client/composables/index.mjs +0 -22
- package/es/client/composables/useContext.d.ts +0 -8
- package/es/client/composables/useContext.mjs +0 -63
- package/es/client/composables/useHotkey.d.ts +0 -12
- package/es/client/composables/useHotkey.mjs +0 -41
- package/es/client/composables/useOpencodeSSE.d.ts +0 -64
- package/es/client/composables/useOpencodeSSE.mjs +0 -29
- package/es/client/composables/useOpencodeSessionSSE.d.ts +0 -66
- package/es/client/composables/useOpencodeSessionSSE.mjs +0 -168
- package/es/client/composables/useSSE.d.ts +0 -87
- package/es/client/composables/useSSE.mjs +0 -118
- package/es/client/composables/useSelectedElements.d.ts +0 -19
- package/es/client/composables/useSelectedElements.mjs +0 -43
- package/es/client/composables/useServerSSE.d.ts +0 -53
- package/es/client/composables/useServerSSE.mjs +0 -36
- package/es/client/composables/useServiceStatus.d.ts +0 -11
- package/es/client/composables/useServiceStatus.mjs +0 -47
- package/es/client/composables/useSessions.d.ts +0 -45
- package/es/client/composables/useSessions.mjs +0 -147
- package/es/client/composables/useTheme.d.ts +0 -12
- package/es/client/composables/useTheme.mjs +0 -42
- package/es/client/index.d.ts +0 -1
- package/es/client/index.mjs +0 -32
- package/es/client/styles.css +0 -1
- package/lib/client/App.vue.cjs +0 -421
- package/lib/client/App.vue.d.ts +0 -6
- package/lib/client/components/ChromeWarmupError-sfc.css +0 -1
- package/lib/client/components/ChromeWarmupError.vue.cjs +0 -356
- package/lib/client/components/ChromeWarmupError.vue.d.ts +0 -19
- package/lib/client/components/LoadingContent.vue.cjs +0 -58
- package/lib/client/components/LoadingContent.vue.d.ts +0 -5
- package/lib/client/composables/index.cjs +0 -54
- package/lib/client/composables/index.d.ts +0 -10
- package/lib/client/composables/useContext.cjs +0 -86
- package/lib/client/composables/useContext.d.ts +0 -8
- package/lib/client/composables/useHotkey.cjs +0 -66
- package/lib/client/composables/useHotkey.d.ts +0 -12
- package/lib/client/composables/useOpencodeSSE.cjs +0 -52
- package/lib/client/composables/useOpencodeSSE.d.ts +0 -64
- package/lib/client/composables/useOpencodeSessionSSE.cjs +0 -187
- package/lib/client/composables/useOpencodeSessionSSE.d.ts +0 -66
- package/lib/client/composables/useSSE.cjs +0 -141
- package/lib/client/composables/useSSE.d.ts +0 -87
- package/lib/client/composables/useSelectedElements.cjs +0 -66
- package/lib/client/composables/useSelectedElements.d.ts +0 -19
- package/lib/client/composables/useServerSSE.cjs +0 -59
- package/lib/client/composables/useServerSSE.d.ts +0 -53
- package/lib/client/composables/useServiceStatus.cjs +0 -70
- package/lib/client/composables/useServiceStatus.d.ts +0 -11
- package/lib/client/composables/useSessions.cjs +0 -168
- package/lib/client/composables/useSessions.d.ts +0 -45
- package/lib/client/composables/useTheme.cjs +0 -65
- package/lib/client/composables/useTheme.d.ts +0 -12
- package/lib/client/index.cjs +0 -54
- package/lib/client/index.d.ts +0 -1
- package/lib/client/styles.css +0 -1
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { type Ref, type ComputedRef } from "vue";
|
|
2
|
-
/**
|
|
3
|
-
* Session 状态类型
|
|
4
|
-
*/
|
|
5
|
-
export type OpencodeSessionStatusType = "idle" | "running" | "streaming" | "completed";
|
|
6
|
-
/**
|
|
7
|
-
* Session 思考状态
|
|
8
|
-
*/
|
|
9
|
-
export interface OpencodeSessionThinkingState {
|
|
10
|
-
thinking: boolean;
|
|
11
|
-
statusType: OpencodeSessionStatusType;
|
|
12
|
-
hasPending: boolean;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Session 更新事件数据
|
|
16
|
-
*/
|
|
17
|
-
export interface OpencodeSessionUpdateData {
|
|
18
|
-
id: string;
|
|
19
|
-
title?: string;
|
|
20
|
-
time?: {
|
|
21
|
-
created?: number;
|
|
22
|
-
updated?: number;
|
|
23
|
-
archived?: number;
|
|
24
|
-
compacting?: number;
|
|
25
|
-
};
|
|
26
|
-
summary?: {
|
|
27
|
-
additions?: number;
|
|
28
|
-
deletions?: number;
|
|
29
|
-
files?: number;
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* OpenCode Session SSE 配置选项
|
|
34
|
-
*/
|
|
35
|
-
export interface OpencodeSessionSSEOptions {
|
|
36
|
-
/** OpenCode proxy 基础 URL */
|
|
37
|
-
proxyBaseUrl: string;
|
|
38
|
-
/** 当前 session ID (响应式) */
|
|
39
|
-
currentSessionId: Ref<string | null>;
|
|
40
|
-
/** 是否启用 */
|
|
41
|
-
enabled?: Ref<boolean>;
|
|
42
|
-
/** 连接成功回调 */
|
|
43
|
-
onConnected?: () => void;
|
|
44
|
-
/** Session 更新回调 (包括标题变化) */
|
|
45
|
-
onSessionUpdate?: (session: OpencodeSessionUpdateData) => void;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* 监听 OpenCode Session SSE 事件
|
|
49
|
-
* 专注于 session thinking 状态管理和标题更新
|
|
50
|
-
*/
|
|
51
|
-
export declare function useOpencodeSessionSSE(options: OpencodeSessionSSEOptions): {
|
|
52
|
-
status: Ref<import("./useSSE").SSEConnectionStatus, import("./useSSE").SSEConnectionStatus>;
|
|
53
|
-
isConnected: ComputedRef<boolean>;
|
|
54
|
-
sessionStates: Ref<Record<string, OpencodeSessionThinkingState>, Record<string, OpencodeSessionThinkingState>>;
|
|
55
|
-
currentThinking: ComputedRef<boolean>;
|
|
56
|
-
currentSessionState: ComputedRef<OpencodeSessionThinkingState | null>;
|
|
57
|
-
hasAnyThinking: ComputedRef<boolean>;
|
|
58
|
-
thinkingSessionCount: ComputedRef<number>;
|
|
59
|
-
connect: () => void;
|
|
60
|
-
disconnect: () => void;
|
|
61
|
-
clearSessionState: (sessionID: string) => void;
|
|
62
|
-
clearAllSessionStates: () => void;
|
|
63
|
-
getSessionState: (sessionID: string) => OpencodeSessionThinkingState | undefined;
|
|
64
|
-
isSessionThinking: (sessionID: string) => boolean;
|
|
65
|
-
getSessionsThinking: (sessionIds: string[]) => Record<string, boolean>;
|
|
66
|
-
};
|
|
@@ -1,168 +0,0 @@
|
|
|
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));
|
|
20
|
-
import { ref, computed } from "vue";
|
|
21
|
-
import {
|
|
22
|
-
useOpencodeSSE
|
|
23
|
-
} from "./useOpencodeSSE.mjs";
|
|
24
|
-
function useOpencodeSessionSSE(options) {
|
|
25
|
-
const { proxyBaseUrl, currentSessionId, enabled, onConnected, onSessionUpdate } = options;
|
|
26
|
-
const sessionStates = ref({});
|
|
27
|
-
function isPendingMessage(info) {
|
|
28
|
-
var _a;
|
|
29
|
-
return (info == null ? void 0 : info.role) === "assistant" && typeof ((_a = info == null ? void 0 : info.time) == null ? void 0 : _a.completed) !== "number";
|
|
30
|
-
}
|
|
31
|
-
function updateThinkingState(sessionID) {
|
|
32
|
-
const state = sessionStates.value[sessionID];
|
|
33
|
-
const isThinking = (state == null ? void 0 : state.hasPending) || (state == null ? void 0 : state.statusType) !== "idle";
|
|
34
|
-
sessionStates.value[sessionID] = {
|
|
35
|
-
thinking: isThinking,
|
|
36
|
-
statusType: (state == null ? void 0 : state.statusType) || "idle",
|
|
37
|
-
hasPending: (state == null ? void 0 : state.hasPending) || false
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
function handleEvent(payload) {
|
|
41
|
-
var _a;
|
|
42
|
-
const type = payload.type;
|
|
43
|
-
const props = payload.properties;
|
|
44
|
-
switch (type) {
|
|
45
|
-
case "session.updated": {
|
|
46
|
-
const info = props.info;
|
|
47
|
-
if (!(info == null ? void 0 : info.id)) return;
|
|
48
|
-
onSessionUpdate == null ? void 0 : onSessionUpdate({
|
|
49
|
-
id: info.id,
|
|
50
|
-
title: info.title,
|
|
51
|
-
time: info.time,
|
|
52
|
-
summary: info.summary
|
|
53
|
-
});
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
case "session.status": {
|
|
57
|
-
const sessionID = props.sessionID;
|
|
58
|
-
if (!sessionID) return;
|
|
59
|
-
const statusType = ((_a = props.status) == null ? void 0 : _a.type) || "idle";
|
|
60
|
-
sessionStates.value[sessionID] = {
|
|
61
|
-
thinking: statusType !== "idle",
|
|
62
|
-
statusType,
|
|
63
|
-
hasPending: false
|
|
64
|
-
};
|
|
65
|
-
updateThinkingState(sessionID);
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
case "message.updated": {
|
|
69
|
-
const info = props.info;
|
|
70
|
-
if (!(info == null ? void 0 : info.sessionID)) return;
|
|
71
|
-
const sessionID = info.sessionID;
|
|
72
|
-
if (info.role === "assistant") {
|
|
73
|
-
const hasPending = isPendingMessage(info);
|
|
74
|
-
const current = sessionStates.value[sessionID] || {
|
|
75
|
-
thinking: false,
|
|
76
|
-
statusType: "idle",
|
|
77
|
-
hasPending: false
|
|
78
|
-
};
|
|
79
|
-
sessionStates.value[sessionID] = __spreadProps(__spreadValues({}, current), {
|
|
80
|
-
hasPending
|
|
81
|
-
});
|
|
82
|
-
updateThinkingState(sessionID);
|
|
83
|
-
}
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
case "message.part.delta": {
|
|
87
|
-
const sessionID = props.sessionID;
|
|
88
|
-
if (!sessionID) return;
|
|
89
|
-
const current = sessionStates.value[sessionID];
|
|
90
|
-
if (!(current == null ? void 0 : current.hasPending)) {
|
|
91
|
-
sessionStates.value[sessionID] = {
|
|
92
|
-
thinking: true,
|
|
93
|
-
statusType: (current == null ? void 0 : current.statusType) || "idle",
|
|
94
|
-
hasPending: true
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
const sse = useOpencodeSSE({
|
|
102
|
-
proxyBaseUrl,
|
|
103
|
-
enabled,
|
|
104
|
-
onEvent: handleEvent,
|
|
105
|
-
onConnected
|
|
106
|
-
});
|
|
107
|
-
const currentThinking = computed(() => {
|
|
108
|
-
var _a, _b;
|
|
109
|
-
const id = currentSessionId.value;
|
|
110
|
-
if (!id) return false;
|
|
111
|
-
return (_b = (_a = sessionStates.value[id]) == null ? void 0 : _a.thinking) != null ? _b : false;
|
|
112
|
-
});
|
|
113
|
-
const currentSessionState = computed(() => {
|
|
114
|
-
const id = currentSessionId.value;
|
|
115
|
-
if (!id) return null;
|
|
116
|
-
return sessionStates.value[id] || null;
|
|
117
|
-
});
|
|
118
|
-
const hasAnyThinking = computed(() => {
|
|
119
|
-
return Object.values(sessionStates.value).some((state) => state.thinking);
|
|
120
|
-
});
|
|
121
|
-
const thinkingSessionCount = computed(() => {
|
|
122
|
-
return Object.values(sessionStates.value).filter((state) => state.thinking).length;
|
|
123
|
-
});
|
|
124
|
-
function clearSessionState(sessionID) {
|
|
125
|
-
delete sessionStates.value[sessionID];
|
|
126
|
-
}
|
|
127
|
-
function clearAllSessionStates() {
|
|
128
|
-
sessionStates.value = {};
|
|
129
|
-
}
|
|
130
|
-
function getSessionState(sessionID) {
|
|
131
|
-
return sessionStates.value[sessionID];
|
|
132
|
-
}
|
|
133
|
-
function isSessionThinking(sessionID) {
|
|
134
|
-
var _a, _b;
|
|
135
|
-
return (_b = (_a = sessionStates.value[sessionID]) == null ? void 0 : _a.thinking) != null ? _b : false;
|
|
136
|
-
}
|
|
137
|
-
function getSessionsThinking(sessionIds) {
|
|
138
|
-
return sessionIds.reduce(
|
|
139
|
-
(acc, id) => {
|
|
140
|
-
acc[id] = isSessionThinking(id);
|
|
141
|
-
return acc;
|
|
142
|
-
},
|
|
143
|
-
{}
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
return {
|
|
147
|
-
// SSE 基础状态
|
|
148
|
-
status: sse.status,
|
|
149
|
-
isConnected: sse.isConnected,
|
|
150
|
-
// session 状态
|
|
151
|
-
sessionStates,
|
|
152
|
-
currentThinking,
|
|
153
|
-
currentSessionState,
|
|
154
|
-
hasAnyThinking,
|
|
155
|
-
thinkingSessionCount,
|
|
156
|
-
// 方法
|
|
157
|
-
connect: sse.connect,
|
|
158
|
-
disconnect: sse.disconnect,
|
|
159
|
-
clearSessionState,
|
|
160
|
-
clearAllSessionStates,
|
|
161
|
-
getSessionState,
|
|
162
|
-
isSessionThinking,
|
|
163
|
-
getSessionsThinking
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
export {
|
|
167
|
-
useOpencodeSessionSSE
|
|
168
|
-
};
|
|
@@ -1,87 +0,0 @@
|
|
|
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;
|
|
28
|
-
}
|
|
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;
|
|
87
|
-
};
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { ref, computed, onUnmounted } from "vue";
|
|
2
|
-
const DEFAULT_MAX_RETRIES = 10;
|
|
3
|
-
const DEFAULT_RETRY_DELAY = 1e3;
|
|
4
|
-
function useSSE(options) {
|
|
5
|
-
const {
|
|
6
|
-
endpoint,
|
|
7
|
-
autoConnect = true,
|
|
8
|
-
enabled,
|
|
9
|
-
maxRetries = DEFAULT_MAX_RETRIES,
|
|
10
|
-
retryDelay = DEFAULT_RETRY_DELAY,
|
|
11
|
-
onConnected,
|
|
12
|
-
onDisconnected,
|
|
13
|
-
onError,
|
|
14
|
-
onMessage
|
|
15
|
-
} = options;
|
|
16
|
-
const connection = ref(null);
|
|
17
|
-
const status = ref("idle");
|
|
18
|
-
const retryCount = ref(0);
|
|
19
|
-
function handleMessage(event) {
|
|
20
|
-
try {
|
|
21
|
-
const data = JSON.parse(event.data);
|
|
22
|
-
onMessage == null ? void 0 : onMessage(data);
|
|
23
|
-
} catch (e) {
|
|
24
|
-
onMessage == null ? void 0 : onMessage(event.data);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function connect() {
|
|
28
|
-
if (connection.value || status.value === "connecting") {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if ((enabled == null ? void 0 : enabled.value) === false) {
|
|
32
|
-
status.value = "idle";
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
status.value = "connecting";
|
|
36
|
-
retryCount.value = 0;
|
|
37
|
-
try {
|
|
38
|
-
connection.value = new EventSource(endpoint);
|
|
39
|
-
connection.value.onopen = () => {
|
|
40
|
-
status.value = "connected";
|
|
41
|
-
retryCount.value = 0;
|
|
42
|
-
onConnected == null ? void 0 : onConnected();
|
|
43
|
-
};
|
|
44
|
-
connection.value.onmessage = handleMessage;
|
|
45
|
-
connection.value.onerror = () => {
|
|
46
|
-
var _a;
|
|
47
|
-
const wasConnected = status.value === "connected";
|
|
48
|
-
status.value = "error";
|
|
49
|
-
(_a = connection.value) == null ? void 0 : _a.close();
|
|
50
|
-
connection.value = null;
|
|
51
|
-
const error = new Error(`SSE connection error: ${endpoint}`);
|
|
52
|
-
onError == null ? void 0 : onError(error);
|
|
53
|
-
if (retryCount.value < maxRetries) {
|
|
54
|
-
retryCount.value++;
|
|
55
|
-
const delay = retryDelay * retryCount.value;
|
|
56
|
-
setTimeout(() => {
|
|
57
|
-
if ((enabled == null ? void 0 : enabled.value) !== false && !connection.value) {
|
|
58
|
-
connect();
|
|
59
|
-
}
|
|
60
|
-
}, delay);
|
|
61
|
-
} else if (wasConnected) {
|
|
62
|
-
onDisconnected == null ? void 0 : onDisconnected();
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
} catch (e) {
|
|
66
|
-
status.value = "error";
|
|
67
|
-
const error = e instanceof Error ? e : new Error(String(e));
|
|
68
|
-
onError == null ? void 0 : onError(error);
|
|
69
|
-
if (retryCount.value < maxRetries) {
|
|
70
|
-
retryCount.value++;
|
|
71
|
-
const delay = retryDelay * retryCount.value;
|
|
72
|
-
setTimeout(() => {
|
|
73
|
-
if (!connection.value) {
|
|
74
|
-
connect();
|
|
75
|
-
}
|
|
76
|
-
}, delay);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
function disconnect() {
|
|
81
|
-
if (connection.value) {
|
|
82
|
-
connection.value.close();
|
|
83
|
-
connection.value = null;
|
|
84
|
-
status.value = "disconnected";
|
|
85
|
-
retryCount.value = 0;
|
|
86
|
-
onDisconnected == null ? void 0 : onDisconnected();
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
function reconnect() {
|
|
90
|
-
disconnect();
|
|
91
|
-
connect();
|
|
92
|
-
}
|
|
93
|
-
function resetRetryCount() {
|
|
94
|
-
retryCount.value = 0;
|
|
95
|
-
}
|
|
96
|
-
if (autoConnect && (enabled == null ? void 0 : enabled.value) !== false) {
|
|
97
|
-
connect();
|
|
98
|
-
}
|
|
99
|
-
onUnmounted(() => {
|
|
100
|
-
disconnect();
|
|
101
|
-
});
|
|
102
|
-
return {
|
|
103
|
-
// 状态
|
|
104
|
-
connection,
|
|
105
|
-
status,
|
|
106
|
-
retryCount,
|
|
107
|
-
isConnected: computed(() => status.value === "connected"),
|
|
108
|
-
isConnecting: computed(() => status.value === "connecting"),
|
|
109
|
-
// 方法
|
|
110
|
-
connect,
|
|
111
|
-
disconnect,
|
|
112
|
-
reconnect,
|
|
113
|
-
resetRetryCount
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
export {
|
|
117
|
-
useSSE
|
|
118
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { OpenCodeSelectedElement } from "@vite-plugin-opencode-assistant/shared";
|
|
2
|
-
export declare function useSelectedElements(): {
|
|
3
|
-
selectedElements: import("vue").Ref<{
|
|
4
|
-
filePath: string | null;
|
|
5
|
-
line: number | null;
|
|
6
|
-
column: number | null;
|
|
7
|
-
innerText: string;
|
|
8
|
-
description?: string | undefined;
|
|
9
|
-
}[], OpenCodeSelectedElement[] | {
|
|
10
|
-
filePath: string | null;
|
|
11
|
-
line: number | null;
|
|
12
|
-
column: number | null;
|
|
13
|
-
innerText: string;
|
|
14
|
-
description?: string | undefined;
|
|
15
|
-
}[]>;
|
|
16
|
-
addElement: (element: OpenCodeSelectedElement) => boolean;
|
|
17
|
-
removeElement: (index: number) => void;
|
|
18
|
-
clearElements: () => void;
|
|
19
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { ref, watch } from "vue";
|
|
2
|
-
function useSelectedElements() {
|
|
3
|
-
const selectedElements = ref([]);
|
|
4
|
-
try {
|
|
5
|
-
const stored = sessionStorage.getItem("__opencode_selected_elements__");
|
|
6
|
-
if (stored) {
|
|
7
|
-
selectedElements.value = JSON.parse(stored);
|
|
8
|
-
}
|
|
9
|
-
} catch (e) {
|
|
10
|
-
}
|
|
11
|
-
watch(
|
|
12
|
-
selectedElements,
|
|
13
|
-
(val) => {
|
|
14
|
-
sessionStorage.setItem("__opencode_selected_elements__", JSON.stringify(val));
|
|
15
|
-
},
|
|
16
|
-
{ deep: true }
|
|
17
|
-
);
|
|
18
|
-
const addElement = (element) => {
|
|
19
|
-
const exists = selectedElements.value.some(
|
|
20
|
-
(el) => el.filePath === element.filePath && el.line === element.line
|
|
21
|
-
);
|
|
22
|
-
if (!exists) {
|
|
23
|
-
selectedElements.value.push(element);
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
return false;
|
|
27
|
-
};
|
|
28
|
-
const removeElement = (index) => {
|
|
29
|
-
selectedElements.value.splice(index, 1);
|
|
30
|
-
};
|
|
31
|
-
const clearElements = () => {
|
|
32
|
-
selectedElements.value = [];
|
|
33
|
-
};
|
|
34
|
-
return {
|
|
35
|
-
selectedElements,
|
|
36
|
-
addElement,
|
|
37
|
-
removeElement,
|
|
38
|
-
clearElements
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
export {
|
|
42
|
-
useSelectedElements
|
|
43
|
-
};
|
|
@@ -1,53 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { useSSE } from "./useSSE.mjs";
|
|
2
|
-
function useServerSSE(options = {}) {
|
|
3
|
-
const { onStatusSync, onTaskUpdate, onClearElements, onConnected } = options;
|
|
4
|
-
const { status, isConnected, connect, disconnect } = useSSE({
|
|
5
|
-
endpoint: "/__opencode_events__",
|
|
6
|
-
autoConnect: false,
|
|
7
|
-
onMessage: (data) => {
|
|
8
|
-
const message = data;
|
|
9
|
-
switch (message.type) {
|
|
10
|
-
case "CONNECTED":
|
|
11
|
-
onConnected == null ? void 0 : onConnected();
|
|
12
|
-
break;
|
|
13
|
-
case "STATUS_SYNC":
|
|
14
|
-
onStatusSync == null ? void 0 : onStatusSync(message);
|
|
15
|
-
break;
|
|
16
|
-
case "TASK_UPDATE":
|
|
17
|
-
onTaskUpdate == null ? void 0 : onTaskUpdate(message);
|
|
18
|
-
break;
|
|
19
|
-
case "CLEAR_ELEMENTS":
|
|
20
|
-
onClearElements == null ? void 0 : onClearElements();
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
return {
|
|
26
|
-
// 状态
|
|
27
|
-
status,
|
|
28
|
-
isConnected,
|
|
29
|
-
// 方法
|
|
30
|
-
connect,
|
|
31
|
-
disconnect
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
export {
|
|
35
|
-
useServerSSE
|
|
36
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { ServiceStartupTask, ServiceStatus } from "@vite-plugin-opencode-assistant/shared";
|
|
2
|
-
export declare function useServiceStatus(): {
|
|
3
|
-
currentTask: import("vue").Ref<"" | ServiceStartupTask, "" | ServiceStartupTask>;
|
|
4
|
-
serviceStatus: import("vue").Ref<ServiceStatus, ServiceStatus>;
|
|
5
|
-
chromeMcpFailed: import("vue").Ref<boolean, boolean>;
|
|
6
|
-
chromeMcpErrorType: import("vue").Ref<string | undefined, string | undefined>;
|
|
7
|
-
chromeMcpErrorMessage: import("vue").Ref<string | undefined, string | undefined>;
|
|
8
|
-
loadingText: import("vue").ComputedRef<string>;
|
|
9
|
-
updateStatusFromTask: (task: ServiceStartupTask | "", errorType?: string, errorMessage?: string) => void;
|
|
10
|
-
setStarting: () => void;
|
|
11
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { ref, computed } from "vue";
|
|
2
|
-
import { SERVICE_STARTUP_TASKS } from "@vite-plugin-opencode-assistant/shared";
|
|
3
|
-
function useServiceStatus() {
|
|
4
|
-
const currentTask = ref("");
|
|
5
|
-
const serviceStatus = ref("idle");
|
|
6
|
-
const chromeMcpFailed = ref(false);
|
|
7
|
-
const chromeMcpErrorType = ref(void 0);
|
|
8
|
-
const chromeMcpErrorMessage = ref(void 0);
|
|
9
|
-
const loadingText = computed(() => {
|
|
10
|
-
if (!currentTask.value) return "\u52A0\u8F7D\u4E2D...";
|
|
11
|
-
return SERVICE_STARTUP_TASKS[currentTask.value] || "\u52A0\u8F7D\u4E2D...";
|
|
12
|
-
});
|
|
13
|
-
const updateStatusFromTask = (task, errorType, errorMessage) => {
|
|
14
|
-
currentTask.value = task;
|
|
15
|
-
if (task === "ready") {
|
|
16
|
-
serviceStatus.value = "ready";
|
|
17
|
-
chromeMcpFailed.value = false;
|
|
18
|
-
chromeMcpErrorType.value = void 0;
|
|
19
|
-
chromeMcpErrorMessage.value = void 0;
|
|
20
|
-
} else if (task === "chrome_mcp_failed") {
|
|
21
|
-
serviceStatus.value = "partial";
|
|
22
|
-
chromeMcpFailed.value = true;
|
|
23
|
-
chromeMcpErrorType.value = errorType;
|
|
24
|
-
chromeMcpErrorMessage.value = errorMessage;
|
|
25
|
-
} else if (task === "session_creation_failed" || task === "opencode_not_installed" || task === "web_start_timeout") {
|
|
26
|
-
serviceStatus.value = "failed";
|
|
27
|
-
} else if (serviceStatus.value === "idle" && task) {
|
|
28
|
-
serviceStatus.value = "starting";
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
const setStarting = () => {
|
|
32
|
-
serviceStatus.value = "starting";
|
|
33
|
-
};
|
|
34
|
-
return {
|
|
35
|
-
currentTask,
|
|
36
|
-
serviceStatus,
|
|
37
|
-
chromeMcpFailed,
|
|
38
|
-
chromeMcpErrorType,
|
|
39
|
-
chromeMcpErrorMessage,
|
|
40
|
-
loadingText,
|
|
41
|
-
updateStatusFromTask,
|
|
42
|
-
setStarting
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
export {
|
|
46
|
-
useServiceStatus
|
|
47
|
-
};
|