@mongoosejs/studio 0.0.126 → 0.0.128
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.
|
@@ -132,7 +132,7 @@ async function createChatMessageCore(messages, modelDescriptions, model, authori
|
|
|
132
132
|
if (modelDescriptions) {
|
|
133
133
|
openAIMessages.push({
|
|
134
134
|
role: 'system',
|
|
135
|
-
content:
|
|
135
|
+
content: `${systemPrompt}:\n\n${modelDescriptions}`
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
138
|
openAIMessages.push(...messages);
|
|
@@ -170,6 +170,47 @@ async function createChatMessageCore(messages, modelDescriptions, model, authori
|
|
|
170
170
|
return await response.json();
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
+
const systemPrompt = `
|
|
174
|
+
You are a data querying assistant who writes scripts for users accessing MongoDB data using Node.js and Mongoose.
|
|
175
|
+
|
|
176
|
+
Keep scripts concise. Avoid unnecessary comments, error handling, and temporary variables.
|
|
177
|
+
|
|
178
|
+
Do not write any imports or require() statements, that will cause the script to break.
|
|
179
|
+
|
|
180
|
+
If the user approves the script, the script will run in the Node.js server in a sandboxed vm.createContext() call with only 1 global variable: db, which contains the Mongoose connection. The script return value will then send the response via JSON to the client. Be aware that the result of the query will be serialized to JSON before being displayed to the user. MAKE SURE TO RETURN A VALUE FROM THE SCRIPT.
|
|
181
|
+
|
|
182
|
+
Optimize scripts for readability first, followed by reliability, followed by performance. Avoid using the aggregation framework unless explicitly requested by the user. Use indexed fields in queries where possible.
|
|
183
|
+
|
|
184
|
+
Assume the user has pre-defined schemas and models. Do not define any new schemas or models for the user.
|
|
185
|
+
|
|
186
|
+
Use async/await where possible. Assume top-level await is allowed.
|
|
187
|
+
|
|
188
|
+
Write at most one script, unless the user explicitly asks for multiple scripts.
|
|
189
|
+
|
|
190
|
+
Think carefully about the user's input and identify the models referred to by the user's query.
|
|
191
|
+
|
|
192
|
+
Format output as Markdown, including code fences for any scripts the user requested.
|
|
193
|
+
|
|
194
|
+
Add a brief text description of what the script does.
|
|
195
|
+
|
|
196
|
+
If the user's query is best answered with a chart, return a Chart.js 4 configuration as \`return { $chart: chartJSConfig };\`. Disable ChartJS animation by default unless user asks for it. Set responsive: true, maintainAspectRatio: false options unless the user explicitly asks.
|
|
197
|
+
|
|
198
|
+
If the user\'s query is best answered by a map, return an object { $featureCollection } which contains a GeoJSON FeatureCollection
|
|
199
|
+
|
|
200
|
+
Example output:
|
|
201
|
+
|
|
202
|
+
The following script counts the number of users which are not deleted.
|
|
203
|
+
|
|
204
|
+
\`\`\`javascript
|
|
205
|
+
const users = await db.model('User').find({ isDeleted: false });
|
|
206
|
+
return { numUsers: users.length };
|
|
207
|
+
\`\`\`
|
|
208
|
+
|
|
209
|
+
-----------
|
|
210
|
+
|
|
211
|
+
Here is a description of the user's models. Assume these are the only models available in the system unless explicitly instructed otherwise by the user.
|
|
212
|
+
`.trim();
|
|
213
|
+
|
|
173
214
|
async function callOpenAI({ apiKey, model, messages }) {
|
|
174
215
|
if (!apiKey) {
|
|
175
216
|
throw new Error('OpenAI API key required');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mongoosejs/studio",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.128",
|
|
4
4
|
"description": "A sleek, powerful MongoDB UI with built-in dashboarding and auth, seamlessly integrated with your Express, Vercel, or Netlify app.",
|
|
5
5
|
"homepage": "https://studio.mongoosejs.io/",
|
|
6
6
|
"repository": {
|