@saltcorn/copilot 0.8.2 → 0.8.3

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.
@@ -1,9 +1,9 @@
1
- const { eval_expression } = require("@saltcorn/data/models/expression");
2
1
  const MetaData = require("@saltcorn/data/models/metadata");
3
2
  const { interpolate } = require("@saltcorn/data/utils");
4
3
  const { getState } = require("@saltcorn/data/db/state");
5
4
  const { requirements_tool, task_tool } = require("./tools");
6
5
  const { tool_choice } = require("./common");
6
+ const { PromptGenerator } = require("./prompt-generator");
7
7
 
8
8
  module.exports = {
9
9
  description: "Provide user feedback to the AppConstructor",
@@ -71,6 +71,7 @@ module.exports = {
71
71
  title_field,
72
72
  description_field,
73
73
  url_field,
74
+ research_context,
74
75
  },
75
76
  }) => {
76
77
  const use_title =
@@ -81,85 +82,72 @@ module.exports = {
81
82
  : row[description_field];
82
83
  const use_url =
83
84
  mode === "workflow" ? interpolate(url, row, user) : row[url_field];
84
- await MetaData.create({
85
- type: "CopilotConstructMgr",
86
- name: "feedback",
87
- body: { title: use_title, description: use_description, url: use_url },
88
- user_id: user?.id,
89
- });
90
- const spec = await MetaData.findOne({
91
- type: "CopilotConstructMgr",
92
- name: "spec",
93
- });
94
- if (!spec) return;
95
- const reqAnswer = await getState().functions.llm_generate.run(
96
- `The following application is being built:
97
85
 
98
- Description: ${spec.body.description}
99
- Audience: ${spec.body.audience}
100
- Core features: ${spec.body.core_features}
101
- Out of scope: ${spec.body.out_of_scope}
102
- Visual style: ${spec.body.visual_style}
103
-
104
- A new piece of feedback has come in from a user:
105
-
106
- Title: ${use_title}
107
- Description: ${use_description}
86
+ const generator = await PromptGenerator.createInstance();
87
+ if (!generator.spec) return;
88
+
89
+ const feedbackResearchSection = research_context
90
+ ? `\nThe user also answered clarifying questions about this feedback:\n\n${research_context}\n`
91
+ : "";
92
+
93
+ let urlSection = "";
94
+ if (use_url) {
95
+ const mView = use_url.match(/\/view\/([^/?#]+)/);
96
+ const mPage = use_url.match(/\/page\/([^/?#]+)/);
97
+ if (mView)
98
+ urlSection =
99
+ `\nThe feedback was submitted from the Saltcorn view named "${mView[1]}"` +
100
+ ` (URL: ${use_url}).\n`;
101
+ else if (mPage)
102
+ urlSection =
103
+ `\nThe feedback was submitted from the Saltcorn page named "${mPage[1]}"` +
104
+ ` (URL: ${use_url}).\n`;
105
+ else urlSection = `\nThe feedback was submitted from: ${use_url}\n`;
106
+ }
108
107
 
109
- Now use the make_requirements tool to create a single or several (a single is prefered) new requirements that captures this new piece of feedback.
110
- `,
108
+ // plan requirements for a feedback
109
+ const reqAnswer = await getState().functions.llm_generate.run(
110
+ generator.feedbackReqPrompt({
111
+ title: use_title,
112
+ description: use_description,
113
+ urlSection,
114
+ feedbackResearchSection,
115
+ }),
111
116
  {
112
117
  tools: [requirements_tool],
113
118
  ...tool_choice("make_requirements"),
114
119
  systemPrompt:
115
- "You are a project manager. The user wants to build an application, and you must analyse their application description and any feedback available",
116
- },
120
+ "You are a project manager. The user wants to build an application, and you\n" +
121
+ "must analyse their application description and any feedback available.",
122
+ }
117
123
  );
118
124
  const tc = reqAnswer.getToolCalls()[0];
119
- console.log("gotr new requiremenrts", tc.input.requirements);
125
+ console.log("got new requiremenrts", tc.input.requirements);
120
126
 
121
127
  for (const reqm of tc.input.requirements)
122
128
  await MetaData.create({
123
129
  type: "CopilotConstructMgr",
124
130
  name: "requirement",
125
- body: reqm,
131
+ body: { ...reqm, source: "feedback", feedback_title: use_title },
126
132
  user_id: req.user?.id,
127
133
  });
128
134
 
135
+ // plan tasks for the new requirements
129
136
  const taskAnswer = await getState().functions.llm_generate.run(
130
- `The following application is being built:
131
-
132
- Description: ${spec.body.description}
133
- Audience: ${spec.body.audience}
134
- Core features: ${spec.body.core_features}
135
- Out of scope: ${spec.body.out_of_scope}
136
- Visual style: ${spec.body.visual_style}
137
-
138
- This application will be implemented in Saltcorn, a database application development
139
- environment.
140
-
141
- A new piece of feedback has come in from a user:
142
-
143
- Title: ${use_title}
144
- Description: ${use_description}
145
-
146
- A product manager has determined that the following requirements should be added to the list of application requirements:
147
-
148
- ${tc.input.requirements.map((r) => " * " + r.requirement).join("\n")}
149
-
150
- Your plan for implementing this new fedback and requirements should not include any clarification or questions to the product owner. The
151
- information you have been given so far is all that is available. Every step in the plan
152
- should be immediately implementable in Saltcorn. You are writing the steps in the plan
153
- for a person who is competent in using saltcorn but has no other business knowledge.
154
-
155
- Now use the plan_tasks tool to create the tasks to implement this new feedback
156
- `,
137
+ generator.feedbackPrompt({
138
+ title: use_title,
139
+ description: use_description,
140
+ urlSection,
141
+ feedbackResearchSection,
142
+ newRequirements: tc.input.requirements,
143
+ }),
157
144
  {
158
145
  tools: [task_tool],
159
146
  ...tool_choice("plan_tasks"),
160
147
  systemPrompt:
161
- "You are a project manager. The user wants to build an application, and you must analyse their application description and any feedback available",
162
- },
148
+ "You are a project manager. The user wants to build an application, and you\n" +
149
+ "must analyse their application description and any feedback available.",
150
+ }
163
151
  );
164
152
  const tcTasks = taskAnswer.getToolCalls()[0];
165
153
  console.log("got new tasks", tcTasks.input.tasks);
@@ -168,8 +156,22 @@ Now use the plan_tasks tool to create the tasks to implement this new feedback
168
156
  await MetaData.create({
169
157
  type: "CopilotConstructMgr",
170
158
  name: "task",
171
- body: task,
159
+ body: { ...task, source: "feedback", feedback_title: use_title },
172
160
  user_id: req.user?.id,
173
161
  });
162
+
163
+ await MetaData.create({
164
+ type: "CopilotConstructMgr",
165
+ name: "feedback",
166
+ body: {
167
+ title: use_title,
168
+ description: use_description,
169
+ url: use_url,
170
+ research_context,
171
+ scope: row.scope || "overall",
172
+ phase_idx: row.phase_idx ?? null,
173
+ },
174
+ user_id: user?.id,
175
+ });
174
176
  },
175
177
  };