@saltcorn/copilot 0.7.0 → 0.7.1

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.
@@ -88,8 +88,23 @@ class GeneratePageSkill {
88
88
 
89
89
  return {
90
90
  type: "function",
91
- process: async ({ name }) => {
92
- return "Metadata recieved";
91
+ process: async ({ name, existing_page_name }) => {
92
+ if (existing_page_name) {
93
+ const page = Page.findOne({ name: existing_page_name });
94
+
95
+ if (!page)
96
+ return `Existing page ${existing_page_name} not found. Unable to provide HTML for this page`;
97
+ if (!page.layout.html_file)
98
+ return `Existing page ${existing_page_name} is not HTML-based. Unable to provide HTML for this page`;
99
+ const file = await File.findOne(page.layout.html_file);
100
+ const html = await file.get_contents("utf8");
101
+ return (
102
+ `The HTML code for the ${existing_page_name} page is:` +
103
+ "\n```html\n" +
104
+ html +
105
+ "\n```\n"
106
+ );
107
+ } else return "Metadata recieved";
93
108
  },
94
109
  postProcess: async ({ tool_call, generate }) => {
95
110
  const str = await generate(
@@ -114,7 +129,7 @@ class GeneratePageSkill {
114
129
  add_user_action: {
115
130
  name: "build_copilot_page_gen",
116
131
  type: "button",
117
- label: "Save page",
132
+ label: "Save page "+tool_call.input.name,
118
133
  input: { html },
119
134
  },
120
135
  };
@@ -124,6 +139,16 @@ class GeneratePageSkill {
124
139
  return div({ class: "border border-primary p-2 m-2" }, phrase);
125
140
  },*/
126
141
  renderToolResponse: async (response, { req }) => {
142
+ if (
143
+ typeof response === "string" &&
144
+ response.includes("Unable to provide HTML for this page")
145
+ )
146
+ return response;
147
+ if (
148
+ typeof response === "string" &&
149
+ response.includes("The HTML code for the ")
150
+ )
151
+ return `Existing page retrieved...`;
127
152
  return null;
128
153
  },
129
154
  function: {
@@ -133,8 +158,12 @@ class GeneratePageSkill {
133
158
  type: "object",
134
159
  required: ["name", "title", "min_role", "page_type"],
135
160
  properties: {
161
+ existing_page_name: {
162
+ description: `If the user asks to modify or change a page, or create a new page based on an existing page, set this to retrieve the contents of the existing page.`,
163
+ type: "string",
164
+ },
136
165
  name: {
137
- description: `The name of the page, this should be a short name which is part of the url. `,
166
+ description: `The name of the new page to generate, this should be a short name which is part of the url. If an existing page name if given, set this to the same name to modify the existing page, and a different name to create a new page based on the existing page`,
138
167
  type: "string",
139
168
  },
140
169
  title: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/copilot",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "AI assistant for building Saltcorn applications",
5
5
  "main": "index.js",
6
6
  "dependencies": {