@krmxd/onegpt 0.2.4-beta → 0.2.5-beta
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/package.json +1 -1
- package/src/tools.js +49 -0
package/package.json
CHANGED
package/src/tools.js
CHANGED
|
@@ -891,6 +891,55 @@ const IMPLEMENTATIONS = {
|
|
|
891
891
|
return new ToolResult(`Deleted ${kind}: ${p}`);
|
|
892
892
|
},
|
|
893
893
|
|
|
894
|
+
create_project(args) {
|
|
895
|
+
const raw = String(args.path || args.name || "").trim();
|
|
896
|
+
if (!raw) return new ToolResult("", "Empty path", false);
|
|
897
|
+
const p = path.resolve(raw.replace(/^~(?=$|\/)/, os.homedir()));
|
|
898
|
+
const template = String(args.template || "web").toLowerCase();
|
|
899
|
+
if (fs.existsSync(p) && fs.readdirSync(p).length) {
|
|
900
|
+
return new ToolResult("", `Folder not empty: ${p} - pick a new project name.`, false);
|
|
901
|
+
}
|
|
902
|
+
fs.mkdirSync(p, { recursive: true });
|
|
903
|
+
const wf = (rel, content) => {
|
|
904
|
+
const f = path.join(p, rel);
|
|
905
|
+
fs.mkdirSync(path.dirname(f), { recursive: true });
|
|
906
|
+
fs.writeFileSync(f, content, "utf-8");
|
|
907
|
+
return rel;
|
|
908
|
+
};
|
|
909
|
+
const made = [];
|
|
910
|
+
const title = path.basename(p).replace(/[-_]/g, " ");
|
|
911
|
+
if (template === "flask") {
|
|
912
|
+
made.push(wf("app.py",
|
|
913
|
+
"from flask import Flask, render_template\n\n" +
|
|
914
|
+
"app = Flask(__name__)\n\n\n" +
|
|
915
|
+
"@app.route(\"/\")\n" +
|
|
916
|
+
"def index():\n" +
|
|
917
|
+
` return render_template(\"index.html\", title=\"${title}\")\n\n\n` +
|
|
918
|
+
"if __name__ == \"__main__\":\n" +
|
|
919
|
+
" app.run(debug=True)\n"));
|
|
920
|
+
made.push(wf("requirements.txt", "flask\n"));
|
|
921
|
+
made.push(wf("templates/index.html",
|
|
922
|
+
"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n" +
|
|
923
|
+
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" +
|
|
924
|
+
` <title>${title}</title>\n</head>\n<body>\n <h1>${title}</h1>\n` +
|
|
925
|
+
" {% block content %}{% endblock %}\n</body>\n</html>\n"));
|
|
926
|
+
made.push(wf("static/style.css", "/* Styles */\nbody { font-family: system-ui; }\n"));
|
|
927
|
+
} else {
|
|
928
|
+
// web / website / static starter
|
|
929
|
+
made.push(wf("index.html",
|
|
930
|
+
"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n" +
|
|
931
|
+
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" +
|
|
932
|
+
` <title>${title}</title>\n <link rel=\"stylesheet\" href=\"styles.css\">\n` +
|
|
933
|
+
"</head>\n<body>\n <script src=\"script.js\" defer></script>\n</body>\n</html>\n"));
|
|
934
|
+
this.write_file({ path: path.join(p, "styles.css"), content: "" });
|
|
935
|
+
this.write_file({ path: path.join(p, "script.js"), content: "" });
|
|
936
|
+
made.push("styles.css (starter)", "script.js (starter)");
|
|
937
|
+
}
|
|
938
|
+
return new ToolResult(
|
|
939
|
+
`Created ${template} project '${path.basename(p)}' with: ` +
|
|
940
|
+
made.join(", ") + ". Extend these files with write_file/edit_file next.");
|
|
941
|
+
},
|
|
942
|
+
|
|
894
943
|
edit_file(args) {
|
|
895
944
|
const p = path.resolve(anchorPath(String(args.path)).replace(/^~(?=$|\/)/, os.homedir()));
|
|
896
945
|
if (!fs.existsSync(p)) return new ToolResult("", `Not found: ${p}`, false);
|