vite-plugin-opencode-assistant 1.0.4 → 1.0.5
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/index.d.ts +1 -0
- package/es/client/index.js +328 -0
- package/es/core/api.d.ts +14 -0
- package/es/core/api.js +294 -0
- package/es/core/injector.d.ts +2 -0
- package/es/core/injector.js +11 -0
- package/es/core/service.d.ts +18 -0
- package/es/core/service.js +163 -0
- package/es/endpoints/context.d.ts +3 -0
- package/es/endpoints/context.js +114 -0
- package/es/endpoints/index.d.ts +4 -0
- package/es/endpoints/index.js +16 -0
- package/es/endpoints/sessions.d.ts +3 -0
- package/es/endpoints/sessions.js +79 -0
- package/es/endpoints/sse.d.ts +3 -0
- package/es/endpoints/sse.js +56 -0
- package/es/endpoints/start.d.ts +3 -0
- package/es/endpoints/start.js +35 -0
- package/es/endpoints/types.d.ts +13 -0
- package/es/endpoints/widget.d.ts +3 -0
- package/es/endpoints/widget.js +57 -0
- package/{dist/vite → es}/index.d.ts +1 -1
- package/es/index.js +168 -0
- package/es/utils/paths.d.ts +3 -0
- package/es/utils/paths.js +38 -0
- package/es/utils/system.js +241 -0
- package/lib/client/index.d.ts +1 -0
- package/lib/client/index.js +328 -0
- package/lib/client.js +5597 -0
- package/lib/core/api.d.ts +14 -0
- package/lib/core/api.js +321 -0
- package/lib/core/injector.d.ts +2 -0
- package/lib/core/injector.js +34 -0
- package/lib/core/service.d.ts +18 -0
- package/lib/core/service.js +180 -0
- package/lib/endpoints/context.d.ts +3 -0
- package/lib/endpoints/context.js +137 -0
- package/lib/endpoints/index.d.ts +4 -0
- package/lib/endpoints/index.js +41 -0
- package/lib/endpoints/sessions.d.ts +3 -0
- package/lib/endpoints/sessions.js +102 -0
- package/lib/endpoints/sse.d.ts +3 -0
- package/lib/endpoints/sse.js +79 -0
- package/lib/endpoints/start.d.ts +3 -0
- package/lib/endpoints/start.js +58 -0
- package/lib/endpoints/types.d.ts +13 -0
- package/lib/endpoints/types.js +15 -0
- package/lib/endpoints/widget.d.ts +3 -0
- package/lib/endpoints/widget.js +90 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +190 -0
- package/lib/style.css +1 -0
- package/lib/utils/paths.d.ts +3 -0
- package/lib/utils/paths.js +73 -0
- package/lib/utils/system.d.ts +5 -0
- package/lib/utils/system.js +274 -0
- package/package.json +28 -33
- package/README.md +0 -287
- package/dist/constants.d.ts +0 -74
- package/dist/constants.js +0 -75
- package/dist/constants.js.map +0 -1
- package/dist/logger.d.ts +0 -64
- package/dist/logger.js +0 -311
- package/dist/logger.js.map +0 -1
- package/dist/opencode/plugins/page-context.d.ts +0 -7
- package/dist/opencode/plugins/page-context.js +0 -372
- package/dist/opencode/plugins/page-context.js.map +0 -1
- package/dist/opencode/web.d.ts +0 -3
- package/dist/opencode/web.js +0 -81
- package/dist/opencode/web.js.map +0 -1
- package/dist/types.d.ts +0 -126
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/vite/client.js +0 -2468
- package/dist/vite/client.js.map +0 -1
- package/dist/vite/index.js +0 -697
- package/dist/vite/index.js.map +0 -1
- package/dist/vite/injector.d.ts +0 -2
- package/dist/vite/injector.js +0 -6
- package/dist/vite/injector.js.map +0 -1
- package/dist/vite/utils.js +0 -206
- package/dist/vite/utils.js.map +0 -1
- /package/{dist/vite/client.d.ts → es/endpoints/types.js} +0 -0
- /package/{dist/vite/utils.d.ts → es/utils/system.d.ts} +0 -0
|
@@ -0,0 +1,137 @@
|
|
|
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 __async = (__this, __arguments, generator) => {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
var fulfilled = (value) => {
|
|
21
|
+
try {
|
|
22
|
+
step(generator.next(value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var rejected = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.throw(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
var context_exports = {};
|
|
39
|
+
__export(context_exports, {
|
|
40
|
+
setupContextEndpoint: () => setupContextEndpoint
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(context_exports);
|
|
43
|
+
var import_shared = require("@vite-plugin-opencode-assistant/shared");
|
|
44
|
+
var import_shared2 = require("@vite-plugin-opencode-assistant/shared");
|
|
45
|
+
const log = (0, import_shared2.createLogger)("Endpoints:Context");
|
|
46
|
+
function setupContextEndpoint(server, ctx) {
|
|
47
|
+
server.middlewares.use(import_shared.CONTEXT_API_PATH, (req, res) => __async(null, null, function* () {
|
|
48
|
+
const reqCtx = new import_shared2.RequestContext(req.method || "GET", import_shared.CONTEXT_API_PATH);
|
|
49
|
+
res.setHeader("Content-Type", "application/json");
|
|
50
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
51
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS");
|
|
52
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
|
53
|
+
if (req.method === "OPTIONS") {
|
|
54
|
+
res.writeHead(200);
|
|
55
|
+
res.end();
|
|
56
|
+
reqCtx.end(200);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (req.method === "GET") {
|
|
60
|
+
res.writeHead(200);
|
|
61
|
+
res.end(JSON.stringify(ctx.pageContext));
|
|
62
|
+
reqCtx.end(200);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (req.method === "DELETE") {
|
|
66
|
+
ctx.pageContext.selectedElements = [];
|
|
67
|
+
log.debug("Selected elements cleared", { sseClients: ctx.sseClients.size });
|
|
68
|
+
let sentCount = 0;
|
|
69
|
+
ctx.sseClients.forEach((client) => {
|
|
70
|
+
try {
|
|
71
|
+
client.write(`data: ${JSON.stringify({ type: "CLEAR_ELEMENTS" })}
|
|
72
|
+
|
|
73
|
+
`);
|
|
74
|
+
sentCount++;
|
|
75
|
+
} catch (e) {
|
|
76
|
+
log.debug("Failed to send SSE message", { error: e });
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
log.debug("SSE messages sent", {
|
|
80
|
+
count: sentCount,
|
|
81
|
+
totalClients: ctx.sseClients.size
|
|
82
|
+
});
|
|
83
|
+
res.writeHead(200);
|
|
84
|
+
res.end(JSON.stringify({ success: true }));
|
|
85
|
+
reqCtx.end(200);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (req.method === "POST") {
|
|
89
|
+
let body = "";
|
|
90
|
+
req.on("data", (chunk) => body += chunk);
|
|
91
|
+
req.on("end", () => {
|
|
92
|
+
var _a;
|
|
93
|
+
try {
|
|
94
|
+
const data = JSON.parse(body);
|
|
95
|
+
ctx.pageContext = {
|
|
96
|
+
url: data.url || "",
|
|
97
|
+
title: data.title || "",
|
|
98
|
+
selectedElements: data.selectedElements || []
|
|
99
|
+
};
|
|
100
|
+
log.debug("Context updated", {
|
|
101
|
+
url: ctx.pageContext.url,
|
|
102
|
+
title: ctx.pageContext.title,
|
|
103
|
+
selectedElementsCount: ((_a = ctx.pageContext.selectedElements) == null ? void 0 : _a.length) || 0
|
|
104
|
+
});
|
|
105
|
+
if (ctx.pageContext.selectedElements && ctx.pageContext.selectedElements.length > 0) {
|
|
106
|
+
log.debug("Selected elements details", {
|
|
107
|
+
elements: ctx.pageContext.selectedElements.map((el) => {
|
|
108
|
+
var _a2;
|
|
109
|
+
return {
|
|
110
|
+
filePath: el.filePath,
|
|
111
|
+
line: el.line,
|
|
112
|
+
text: (_a2 = el.innerText) == null ? void 0 : _a2.substring(0, 50)
|
|
113
|
+
};
|
|
114
|
+
})
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
res.writeHead(200);
|
|
118
|
+
res.end(JSON.stringify({ success: true }));
|
|
119
|
+
reqCtx.end(200);
|
|
120
|
+
} catch (e) {
|
|
121
|
+
log.debug("Invalid JSON in request body", { error: e });
|
|
122
|
+
res.writeHead(400);
|
|
123
|
+
res.end(JSON.stringify({ error: "Invalid JSON" }));
|
|
124
|
+
reqCtx.error(e);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
res.writeHead(405);
|
|
130
|
+
res.end(JSON.stringify({ error: "Method not allowed" }));
|
|
131
|
+
reqCtx.end(405);
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
135
|
+
0 && (module.exports = {
|
|
136
|
+
setupContextEndpoint
|
|
137
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var endpoints_exports = {};
|
|
20
|
+
__export(endpoints_exports, {
|
|
21
|
+
setupMiddlewares: () => setupMiddlewares
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(endpoints_exports);
|
|
24
|
+
var import_widget = require("./widget.js");
|
|
25
|
+
var import_context = require("./context.js");
|
|
26
|
+
var import_start = require("./start.js");
|
|
27
|
+
var import_sse = require("./sse.js");
|
|
28
|
+
var import_sessions = require("./sessions.js");
|
|
29
|
+
__reExport(endpoints_exports, require("./types.js"), module.exports);
|
|
30
|
+
function setupMiddlewares(server, ctx) {
|
|
31
|
+
(0, import_widget.setupWidgetEndpoints)(server, ctx);
|
|
32
|
+
(0, import_context.setupContextEndpoint)(server, ctx);
|
|
33
|
+
(0, import_start.setupStartEndpoint)(server, ctx);
|
|
34
|
+
(0, import_sse.setupSseEndpoint)(server, ctx);
|
|
35
|
+
(0, import_sessions.setupSessionsEndpoint)(server, ctx);
|
|
36
|
+
}
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
setupMiddlewares,
|
|
40
|
+
...require("./types.js")
|
|
41
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
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 __async = (__this, __arguments, generator) => {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
var fulfilled = (value) => {
|
|
21
|
+
try {
|
|
22
|
+
step(generator.next(value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var rejected = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.throw(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
var sessions_exports = {};
|
|
39
|
+
__export(sessions_exports, {
|
|
40
|
+
setupSessionsEndpoint: () => setupSessionsEndpoint
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(sessions_exports);
|
|
43
|
+
var import_shared = require("@vite-plugin-opencode-assistant/shared");
|
|
44
|
+
var import_shared2 = require("@vite-plugin-opencode-assistant/shared");
|
|
45
|
+
const log = (0, import_shared2.createLogger)("Endpoints:Sessions");
|
|
46
|
+
function setupSessionsEndpoint(server, ctx) {
|
|
47
|
+
server.middlewares.use(import_shared.SESSIONS_API_PATH, (req, res) => __async(null, null, function* () {
|
|
48
|
+
const reqCtx = new import_shared2.RequestContext(req.method || "GET", import_shared.SESSIONS_API_PATH);
|
|
49
|
+
res.setHeader("Content-Type", "application/json");
|
|
50
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
51
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS");
|
|
52
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
|
53
|
+
if (req.method === "OPTIONS") {
|
|
54
|
+
res.writeHead(200);
|
|
55
|
+
res.end();
|
|
56
|
+
reqCtx.end(200);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
if (req.method === "GET") {
|
|
61
|
+
reqCtx.checkpoint("Fetching sessions");
|
|
62
|
+
const sessions = yield ctx.getSessions();
|
|
63
|
+
res.writeHead(200);
|
|
64
|
+
res.end(JSON.stringify(sessions));
|
|
65
|
+
reqCtx.end(200);
|
|
66
|
+
} else if (req.method === "POST") {
|
|
67
|
+
reqCtx.checkpoint("Creating session");
|
|
68
|
+
const newSession = yield ctx.createSession();
|
|
69
|
+
res.writeHead(200);
|
|
70
|
+
res.end(JSON.stringify(newSession));
|
|
71
|
+
reqCtx.end(200);
|
|
72
|
+
} else if (req.method === "DELETE") {
|
|
73
|
+
const url = new URL(req.url || "", `http://${req.headers.host}`);
|
|
74
|
+
const sessionId = url.searchParams.get("id");
|
|
75
|
+
if (!sessionId) {
|
|
76
|
+
res.writeHead(400);
|
|
77
|
+
res.end(JSON.stringify({ error: "Session ID is required" }));
|
|
78
|
+
reqCtx.end(400);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
reqCtx.checkpoint(`Deleting session: ${sessionId}`);
|
|
82
|
+
yield ctx.deleteSession(sessionId);
|
|
83
|
+
res.writeHead(200);
|
|
84
|
+
res.end(JSON.stringify({ success: true }));
|
|
85
|
+
reqCtx.end(200);
|
|
86
|
+
} else {
|
|
87
|
+
res.writeHead(405);
|
|
88
|
+
res.end(JSON.stringify({ error: "Method not allowed" }));
|
|
89
|
+
reqCtx.end(405);
|
|
90
|
+
}
|
|
91
|
+
} catch (e) {
|
|
92
|
+
log.error("Session API error", { error: e, method: req.method });
|
|
93
|
+
res.writeHead(500);
|
|
94
|
+
res.end(JSON.stringify({ error: String(e) }));
|
|
95
|
+
reqCtx.error(e);
|
|
96
|
+
}
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
+
0 && (module.exports = {
|
|
101
|
+
setupSessionsEndpoint
|
|
102
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
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 __async = (__this, __arguments, generator) => {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
var fulfilled = (value) => {
|
|
21
|
+
try {
|
|
22
|
+
step(generator.next(value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var rejected = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.throw(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
var sse_exports = {};
|
|
39
|
+
__export(sse_exports, {
|
|
40
|
+
setupSseEndpoint: () => setupSseEndpoint
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(sse_exports);
|
|
43
|
+
var import_shared = require("@vite-plugin-opencode-assistant/shared");
|
|
44
|
+
var import_shared2 = require("@vite-plugin-opencode-assistant/shared");
|
|
45
|
+
const log = (0, import_shared2.createLogger)("Endpoints:SSE");
|
|
46
|
+
function setupSseEndpoint(server, ctx) {
|
|
47
|
+
server.middlewares.use(import_shared.SSE_EVENTS_PATH, (req, res) => __async(null, null, function* () {
|
|
48
|
+
const reqCtx = new import_shared2.RequestContext("GET", import_shared.SSE_EVENTS_PATH);
|
|
49
|
+
res.writeHead(200, {
|
|
50
|
+
"Content-Type": "text/event-stream",
|
|
51
|
+
"Cache-Control": "no-cache",
|
|
52
|
+
Connection: "keep-alive",
|
|
53
|
+
"Access-Control-Allow-Origin": "*"
|
|
54
|
+
});
|
|
55
|
+
ctx.sseClients.add(res);
|
|
56
|
+
log.debug("SSE client connected", { totalClients: ctx.sseClients.size });
|
|
57
|
+
res.write(`data: ${JSON.stringify({ type: "CONNECTED" })}
|
|
58
|
+
|
|
59
|
+
`);
|
|
60
|
+
if (ctx.sessionUrl) {
|
|
61
|
+
res.write(
|
|
62
|
+
`data: ${JSON.stringify({ type: "SESSION_READY", sessionUrl: ctx.sessionUrl })}
|
|
63
|
+
|
|
64
|
+
`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
req.on("close", () => {
|
|
68
|
+
ctx.sseClients.delete(res);
|
|
69
|
+
log.debug("SSE client disconnected", {
|
|
70
|
+
totalClients: ctx.sseClients.size
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
reqCtx.end(200);
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
setupSseEndpoint
|
|
79
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
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 __async = (__this, __arguments, generator) => {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
var fulfilled = (value) => {
|
|
21
|
+
try {
|
|
22
|
+
step(generator.next(value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var rejected = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.throw(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
var start_exports = {};
|
|
39
|
+
__export(start_exports, {
|
|
40
|
+
setupStartEndpoint: () => setupStartEndpoint
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(start_exports);
|
|
43
|
+
var import_shared = require("@vite-plugin-opencode-assistant/shared");
|
|
44
|
+
var import_shared2 = require("@vite-plugin-opencode-assistant/shared");
|
|
45
|
+
function setupStartEndpoint(server, ctx) {
|
|
46
|
+
server.middlewares.use(import_shared.START_API_PATH, (_req, res) => __async(null, null, function* () {
|
|
47
|
+
const reqCtx = new import_shared2.RequestContext("GET", import_shared.START_API_PATH);
|
|
48
|
+
res.setHeader("Content-Type", "application/json");
|
|
49
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
50
|
+
res.writeHead(200);
|
|
51
|
+
res.end(JSON.stringify({ success: true, sessionUrl: ctx.sessionUrl }));
|
|
52
|
+
reqCtx.end(200);
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
setupStartEndpoint
|
|
58
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PageContext, SessionInfo } from "@vite-plugin-opencode-assistant/shared";
|
|
2
|
+
import type http from "http";
|
|
3
|
+
export interface EndpointContext {
|
|
4
|
+
get sessionUrl(): string | null;
|
|
5
|
+
get sseClients(): Set<http.ServerResponse>;
|
|
6
|
+
get pageContext(): PageContext;
|
|
7
|
+
set pageContext(ctx: PageContext);
|
|
8
|
+
getSessions: () => Promise<SessionInfo[]>;
|
|
9
|
+
createSession: () => Promise<SessionInfo>;
|
|
10
|
+
deleteSession: (id: string) => Promise<void>;
|
|
11
|
+
resolveWidgetPath: () => string;
|
|
12
|
+
resolveWidgetStylePath: () => string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var types_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var __async = (__this, __arguments, generator) => {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
var fulfilled = (value) => {
|
|
31
|
+
try {
|
|
32
|
+
step(generator.next(value));
|
|
33
|
+
} catch (e) {
|
|
34
|
+
reject(e);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var rejected = (value) => {
|
|
38
|
+
try {
|
|
39
|
+
step(generator.throw(value));
|
|
40
|
+
} catch (e) {
|
|
41
|
+
reject(e);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
45
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
var widget_exports = {};
|
|
49
|
+
__export(widget_exports, {
|
|
50
|
+
setupWidgetEndpoints: () => setupWidgetEndpoints
|
|
51
|
+
});
|
|
52
|
+
module.exports = __toCommonJS(widget_exports);
|
|
53
|
+
var import_fs = __toESM(require("fs"));
|
|
54
|
+
var import_shared = require("@vite-plugin-opencode-assistant/shared");
|
|
55
|
+
var import_shared2 = require("@vite-plugin-opencode-assistant/shared");
|
|
56
|
+
function setupWidgetEndpoints(server, ctx) {
|
|
57
|
+
server.middlewares.use(import_shared.WIDGET_SCRIPT_PATH, (_req, res) => __async(null, null, function* () {
|
|
58
|
+
const reqCtx = new import_shared2.RequestContext("GET", import_shared.WIDGET_SCRIPT_PATH);
|
|
59
|
+
const widgetPath = ctx.resolveWidgetPath();
|
|
60
|
+
if (import_fs.default.existsSync(widgetPath)) {
|
|
61
|
+
res.setHeader("Content-Type", "application/javascript");
|
|
62
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
63
|
+
import_fs.default.createReadStream(widgetPath).pipe(res);
|
|
64
|
+
reqCtx.end(200);
|
|
65
|
+
} else {
|
|
66
|
+
res.writeHead(404);
|
|
67
|
+
res.end("Widget script not found");
|
|
68
|
+
reqCtx.end(404);
|
|
69
|
+
}
|
|
70
|
+
}));
|
|
71
|
+
const WIDGET_STYLE_PATH = "/__opencode_widget__.css";
|
|
72
|
+
server.middlewares.use(WIDGET_STYLE_PATH, (_req, res) => __async(null, null, function* () {
|
|
73
|
+
const reqCtx = new import_shared2.RequestContext("GET", WIDGET_STYLE_PATH);
|
|
74
|
+
const stylePath = ctx.resolveWidgetStylePath();
|
|
75
|
+
if (import_fs.default.existsSync(stylePath)) {
|
|
76
|
+
res.setHeader("Content-Type", "text/css");
|
|
77
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
78
|
+
import_fs.default.createReadStream(stylePath).pipe(res);
|
|
79
|
+
reqCtx.end(200);
|
|
80
|
+
} else {
|
|
81
|
+
res.writeHead(404);
|
|
82
|
+
res.end("Widget style not found");
|
|
83
|
+
reqCtx.end(404);
|
|
84
|
+
}
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
setupWidgetEndpoints
|
|
90
|
+
});
|
package/lib/index.d.ts
ADDED