openmagic 0.17.1 → 0.19.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 CHANGED
@@ -912,35 +912,79 @@ 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) parts.selectedElement = context.selectedElement.outerHTML;
915
+ if (context.selectedElement) {
916
+ const el = context.selectedElement;
917
+ const elementData = {
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
+ };
927
+ if (el.parentStyles && Object.keys(el.parentStyles).length) {
928
+ elementData.parentContainerStyles = el.parentStyles;
929
+ }
930
+ if (el.siblings?.length) {
931
+ elementData.siblings = el.siblings;
932
+ }
933
+ if (el.matchedCssRules?.length) {
934
+ elementData.matchedCssRules = el.matchedCssRules;
935
+ }
936
+ if (el.viewport) {
937
+ elementData.viewport = el.viewport;
938
+ }
939
+ if (el.ariaAttributes && Object.keys(el.ariaAttributes).length) {
940
+ elementData.ariaAttributes = el.ariaAttributes;
941
+ }
942
+ if (el.eventHandlers?.length) {
943
+ elementData.eventHandlers = el.eventHandlers;
944
+ }
945
+ if (el.reactProps) {
946
+ elementData.reactProps = el.reactProps;
947
+ }
948
+ parts.selectedElement = JSON.stringify(elementData, null, 2);
949
+ }
916
950
  if (context.files?.length) {
917
- parts.filePath = context.files[0].path;
918
- parts.fileContent = context.files[0].content;
951
+ parts.files = context.files;
919
952
  }
920
953
  if (context.projectTree) parts.projectTree = context.projectTree;
954
+ if (context.pageUrl) parts.pageUrl = context.pageUrl;
955
+ if (context.pageTitle) parts.pageTitle = context.pageTitle;
921
956
  if (context.networkLogs) parts.networkLogs = context.networkLogs.map((l) => `${l.method} ${l.url} \u2192 ${l.status || "pending"}`).join("\n");
922
957
  if (context.consoleLogs) parts.consoleLogs = context.consoleLogs.map((l) => `[${l.level}] ${l.args.join(" ")}`).join("\n");
923
958
  return parts;
924
959
  }
925
960
  function buildUserMessage(userPrompt, context) {
926
961
  const parts = [];
962
+ if (context.pageUrl || context.pageTitle) {
963
+ parts.push(`## Page Context
964
+ URL: ${context.pageUrl || "unknown"}
965
+ Title: ${context.pageTitle || "unknown"}`);
966
+ }
927
967
  if (context.projectTree) {
928
968
  parts.push(`## Project Structure
929
969
  \`\`\`
930
970
  ${context.projectTree}
931
971
  \`\`\``);
932
972
  }
933
- if (context.filePath && context.fileContent) {
934
- parts.push(
935
- `## Source File: ${context.filePath}
973
+ if (context.files?.length) {
974
+ parts.push(`## Grounded Source Files
975
+ ${context.files.map((f) => `### ${f.path}
976
+ \`\`\`
977
+ ${f.content}
978
+ \`\`\``).join("\n\n")}`);
979
+ } else if (context.filePath && context.fileContent) {
980
+ parts.push(`## Source File: ${context.filePath}
936
981
  \`\`\`
937
982
  ${context.fileContent}
938
- \`\`\``
939
- );
983
+ \`\`\``);
940
984
  }
941
985
  if (context.selectedElement) {
942
- parts.push(`## Selected Element (DOM)
943
- \`\`\`html
986
+ parts.push(`## Selected Element
987
+ \`\`\`json
944
988
  ${context.selectedElement}
945
989
  \`\`\``);
946
990
  }
@@ -1356,7 +1400,7 @@ async function handleLlmChat(params, onChunk, onDone, onError) {
1356
1400
  }
1357
1401
 
1358
1402
  // src/server.ts
1359
- var VERSION = "0.17.1";
1403
+ var VERSION = "0.19.0";
1360
1404
  var __dirname = dirname2(fileURLToPath(import.meta.url));
1361
1405
  function attachOpenMagic(httpServer, roots) {
1362
1406
  function handleRequest(req, res) {
@@ -1889,7 +1933,7 @@ process.on("uncaughtException", (err) => {
1889
1933
  process.exit(1);
1890
1934
  });
1891
1935
  var childProcesses = [];
1892
- var VERSION2 = "0.17.1";
1936
+ var VERSION2 = "0.19.0";
1893
1937
  function ask(question) {
1894
1938
  const rl = createInterface({ input: process.stdin, output: process.stdout });
1895
1939
  return new Promise((resolve3) => {