openmagic 0.17.0 → 0.18.0
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/dist/cli.js +54 -18
- package/dist/cli.js.map +1 -1
- package/dist/toolbar/index.global.js +18 -18
- package/dist/toolbar/index.global.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -912,35 +912,57 @@ You MUST respond with valid JSON in this exact format:
|
|
|
912
912
|
8. If you cannot make the requested change, set modifications to an empty array and explain why`;
|
|
913
913
|
function buildContextParts(context) {
|
|
914
914
|
const parts = {};
|
|
915
|
-
if (context.selectedElement)
|
|
915
|
+
if (context.selectedElement) {
|
|
916
|
+
const el = context.selectedElement;
|
|
917
|
+
parts.selectedElement = JSON.stringify({
|
|
918
|
+
cssSelector: el.cssSelector,
|
|
919
|
+
tagName: el.tagName,
|
|
920
|
+
id: el.id,
|
|
921
|
+
className: el.className,
|
|
922
|
+
outerHTML: el.outerHTML,
|
|
923
|
+
computedStyles: el.computedStyles,
|
|
924
|
+
ancestry: el.ancestry,
|
|
925
|
+
componentHint: el.componentHint
|
|
926
|
+
}, null, 2);
|
|
927
|
+
}
|
|
916
928
|
if (context.files?.length) {
|
|
917
|
-
parts.
|
|
918
|
-
parts.fileContent = context.files[0].content;
|
|
929
|
+
parts.files = context.files;
|
|
919
930
|
}
|
|
920
931
|
if (context.projectTree) parts.projectTree = context.projectTree;
|
|
932
|
+
if (context.pageUrl) parts.pageUrl = context.pageUrl;
|
|
933
|
+
if (context.pageTitle) parts.pageTitle = context.pageTitle;
|
|
921
934
|
if (context.networkLogs) parts.networkLogs = context.networkLogs.map((l) => `${l.method} ${l.url} \u2192 ${l.status || "pending"}`).join("\n");
|
|
922
935
|
if (context.consoleLogs) parts.consoleLogs = context.consoleLogs.map((l) => `[${l.level}] ${l.args.join(" ")}`).join("\n");
|
|
923
936
|
return parts;
|
|
924
937
|
}
|
|
925
938
|
function buildUserMessage(userPrompt, context) {
|
|
926
939
|
const parts = [];
|
|
940
|
+
if (context.pageUrl || context.pageTitle) {
|
|
941
|
+
parts.push(`## Page Context
|
|
942
|
+
URL: ${context.pageUrl || "unknown"}
|
|
943
|
+
Title: ${context.pageTitle || "unknown"}`);
|
|
944
|
+
}
|
|
927
945
|
if (context.projectTree) {
|
|
928
946
|
parts.push(`## Project Structure
|
|
929
947
|
\`\`\`
|
|
930
948
|
${context.projectTree}
|
|
931
949
|
\`\`\``);
|
|
932
950
|
}
|
|
933
|
-
if (context.
|
|
934
|
-
parts.push(
|
|
935
|
-
|
|
951
|
+
if (context.files?.length) {
|
|
952
|
+
parts.push(`## Grounded Source Files
|
|
953
|
+
${context.files.map((f) => `### ${f.path}
|
|
954
|
+
\`\`\`
|
|
955
|
+
${f.content}
|
|
956
|
+
\`\`\``).join("\n\n")}`);
|
|
957
|
+
} else if (context.filePath && context.fileContent) {
|
|
958
|
+
parts.push(`## Source File: ${context.filePath}
|
|
936
959
|
\`\`\`
|
|
937
960
|
${context.fileContent}
|
|
938
|
-
\`\`\``
|
|
939
|
-
);
|
|
961
|
+
\`\`\``);
|
|
940
962
|
}
|
|
941
963
|
if (context.selectedElement) {
|
|
942
|
-
parts.push(`## Selected Element
|
|
943
|
-
\`\`\`
|
|
964
|
+
parts.push(`## Selected Element
|
|
965
|
+
\`\`\`json
|
|
944
966
|
${context.selectedElement}
|
|
945
967
|
\`\`\``);
|
|
946
968
|
}
|
|
@@ -1356,7 +1378,7 @@ async function handleLlmChat(params, onChunk, onDone, onError) {
|
|
|
1356
1378
|
}
|
|
1357
1379
|
|
|
1358
1380
|
// src/server.ts
|
|
1359
|
-
var VERSION = "0.
|
|
1381
|
+
var VERSION = "0.18.0";
|
|
1360
1382
|
var __dirname = dirname2(fileURLToPath(import.meta.url));
|
|
1361
1383
|
function attachOpenMagic(httpServer, roots) {
|
|
1362
1384
|
function handleRequest(req, res) {
|
|
@@ -1376,10 +1398,7 @@ function attachOpenMagic(httpServer, roots) {
|
|
|
1376
1398
|
}
|
|
1377
1399
|
return false;
|
|
1378
1400
|
}
|
|
1379
|
-
const wss = new WebSocketServer({
|
|
1380
|
-
server: httpServer,
|
|
1381
|
-
path: "/__openmagic__/ws"
|
|
1382
|
-
});
|
|
1401
|
+
const wss = new WebSocketServer({ noServer: true });
|
|
1383
1402
|
const clientStates = /* @__PURE__ */ new WeakMap();
|
|
1384
1403
|
wss.on("connection", (ws, req) => {
|
|
1385
1404
|
const origin = req.headers.origin || "";
|
|
@@ -1411,7 +1430,17 @@ function attachOpenMagic(httpServer, roots) {
|
|
|
1411
1430
|
clientStates.delete(ws);
|
|
1412
1431
|
});
|
|
1413
1432
|
});
|
|
1414
|
-
|
|
1433
|
+
function handleUpgrade(req, socket, head) {
|
|
1434
|
+
const urlPath = (req.url || "").split("?")[0];
|
|
1435
|
+
if (urlPath === "/__openmagic__/ws") {
|
|
1436
|
+
wss.handleUpgrade(req, socket, head, (ws) => {
|
|
1437
|
+
wss.emit("connection", ws, req);
|
|
1438
|
+
});
|
|
1439
|
+
return true;
|
|
1440
|
+
}
|
|
1441
|
+
return false;
|
|
1442
|
+
}
|
|
1443
|
+
return { wss, handleRequest, handleUpgrade };
|
|
1415
1444
|
}
|
|
1416
1445
|
async function handleMessage(ws, msg, state, roots) {
|
|
1417
1446
|
switch (msg.type) {
|
|
@@ -1670,17 +1699,24 @@ ${toolbarScript}
|
|
|
1670
1699
|
${toolbarScript}
|
|
1671
1700
|
</body></html>`
|
|
1672
1701
|
);
|
|
1702
|
+
} else if (res && typeof res.destroy === "function") {
|
|
1703
|
+
try {
|
|
1704
|
+
res.destroy();
|
|
1705
|
+
} catch {
|
|
1706
|
+
}
|
|
1673
1707
|
}
|
|
1674
1708
|
});
|
|
1675
1709
|
let omHandle = null;
|
|
1710
|
+
let omUpgrade = null;
|
|
1676
1711
|
const server = http.createServer((req, res) => {
|
|
1677
1712
|
if (omHandle && omHandle(req, res)) return;
|
|
1678
1713
|
proxy.web(req, res);
|
|
1679
1714
|
});
|
|
1680
1715
|
const om = attachOpenMagic(server, roots);
|
|
1681
1716
|
omHandle = om.handleRequest;
|
|
1717
|
+
omUpgrade = om.handleUpgrade;
|
|
1682
1718
|
server.on("upgrade", (req, socket, head) => {
|
|
1683
|
-
if (req
|
|
1719
|
+
if (omUpgrade && omUpgrade(req, socket, head)) return;
|
|
1684
1720
|
proxy.ws(req, socket, head);
|
|
1685
1721
|
});
|
|
1686
1722
|
return server;
|
|
@@ -1875,7 +1911,7 @@ process.on("uncaughtException", (err) => {
|
|
|
1875
1911
|
process.exit(1);
|
|
1876
1912
|
});
|
|
1877
1913
|
var childProcesses = [];
|
|
1878
|
-
var VERSION2 = "0.
|
|
1914
|
+
var VERSION2 = "0.18.0";
|
|
1879
1915
|
function ask(question) {
|
|
1880
1916
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
1881
1917
|
return new Promise((resolve3) => {
|