@mongoosejs/studio 0.0.125 → 0.0.127

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: `Here are the Mongoose model descriptions you can refer to:\n\n${modelDescriptions}`
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');
@@ -94,7 +94,7 @@ if (window.MONGOOSE_STUDIO_CONFIG.isLambda) {
94
94
  exportQueryResults(params) {
95
95
  const accessToken = window.localStorage.getItem('_mongooseStudioAccessToken') || null;
96
96
 
97
- return fetch(window.MONGOOSE_STUDIO_CONFIG.baseURL + new URLSearchParams({ ...params, action: 'Model.exportQueryResults' }).toString(), {
97
+ return fetch(window.MONGOOSE_STUDIO_CONFIG.baseURL + '?' + new URLSearchParams({ ...params, action: 'Model.exportQueryResults' }).toString(), {
98
98
  method: 'GET',
99
99
  headers: {
100
100
  Authorization: `${accessToken}`, // Set your authorization token here
@@ -15267,7 +15267,7 @@ var bson = /*#__PURE__*/Object.freeze({
15267
15267
  /***/ ((module) => {
15268
15268
 
15269
15269
  "use strict";
15270
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@mongoosejs/studio","version":"0.0.125","description":"A sleek, powerful MongoDB UI with built-in dashboarding and auth, seamlessly integrated with your Express, Vercel, or Netlify app.","homepage":"https://studio.mongoosejs.io/","repository":{"type":"git","url":"https://github.com/mongoosejs/studio"},"dependencies":{"archetype":"0.13.1","csv-stringify":"6.3.0","ejson":"^2.2.3","extrovert":"^0.1.0","marked":"15.0.12","node-inspect-extracted":"3.x","tailwindcss":"3.4.0","vanillatoasts":"^1.6.0","vue":"3.x","webpack":"5.x"},"peerDependencies":{"bson":"^5.5.1 || 6.x","express":"4.x","mongoose":"7.x || 8.x"},"devDependencies":{"@masteringjs/eslint-config":"0.1.1","axios":"1.2.2","dedent":"^1.6.0","eslint":"9.30.0","express":"4.x","mocha":"10.2.0","mongoose":"8.x"},"scripts":{"lint":"eslint .","tailwind":"tailwindcss -o ./frontend/public/tw.css","tailwind:watch":"tailwindcss -o ./frontend/public/tw.css --watch","test":"mocha test/*.test.js"}}');
15270
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@mongoosejs/studio","version":"0.0.126","description":"A sleek, powerful MongoDB UI with built-in dashboarding and auth, seamlessly integrated with your Express, Vercel, or Netlify app.","homepage":"https://studio.mongoosejs.io/","repository":{"type":"git","url":"https://github.com/mongoosejs/studio"},"dependencies":{"archetype":"0.13.1","csv-stringify":"6.3.0","ejson":"^2.2.3","extrovert":"^0.1.0","marked":"15.0.12","node-inspect-extracted":"3.x","tailwindcss":"3.4.0","vanillatoasts":"^1.6.0","vue":"3.x","webpack":"5.x"},"peerDependencies":{"bson":"^5.5.1 || 6.x","express":"4.x","mongoose":"7.x || 8.x"},"devDependencies":{"@masteringjs/eslint-config":"0.1.1","axios":"1.2.2","dedent":"^1.6.0","eslint":"9.30.0","express":"4.x","mocha":"10.2.0","mongoose":"8.x"},"scripts":{"lint":"eslint .","tailwind":"tailwindcss -o ./frontend/public/tw.css","tailwind:watch":"tailwindcss -o ./frontend/public/tw.css --watch","test":"mocha test/*.test.js"}}');
15271
15271
 
15272
15272
  /***/ })
15273
15273
 
@@ -84,7 +84,7 @@ if (window.MONGOOSE_STUDIO_CONFIG.isLambda) {
84
84
  exportQueryResults(params) {
85
85
  const accessToken = window.localStorage.getItem('_mongooseStudioAccessToken') || null;
86
86
 
87
- return fetch(window.MONGOOSE_STUDIO_CONFIG.baseURL + new URLSearchParams({ ...params, action: 'Model.exportQueryResults' }).toString(), {
87
+ return fetch(window.MONGOOSE_STUDIO_CONFIG.baseURL + '?' + new URLSearchParams({ ...params, action: 'Model.exportQueryResults' }).toString(), {
88
88
  method: 'GET',
89
89
  headers: {
90
90
  Authorization: `${accessToken}`, // Set your authorization token here
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mongoosejs/studio",
3
- "version": "0.0.125",
3
+ "version": "0.0.127",
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": {