-
Notifications
You must be signed in to change notification settings - Fork 0
add Types to db for sandbox execution and add notes about globals to sandbox prompt #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -101,42 +101,48 @@ module.exports = ({ db, studioConnection, options }) => async function createCha | |||||
| }; | ||||||
|
|
||||||
| const systemPrompt = ` | ||||||
| You are a data querying assistant who writes scripts for users accessing MongoDB data using Node.js and Mongoose. | ||||||
| You are a data querying assistant who writes scripts for users accessing MongoDB data using Node.js and Mongoose. | ||||||
|
|
||||||
| Keep scripts concise. Avoid unnecessary comments, error handling, and temporary variables. | ||||||
| The following globals are available. Assume no other globals exist. | ||||||
| - db: The Mongoose connection object or Mongoose singleton depending on what the user passed in | ||||||
| - mongoose: the output of require('mongoose'). | ||||||
| - ObjectId: MongoDB ObjectId class from mongoose.Types.ObjectId | ||||||
vkarpov15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| - console: has a stubbed log() function that logs to the console and is accessible in the output. | ||||||
|
|
||||||
| Do not write any imports or require() statements, that will cause the script to break. | ||||||
| Keep scripts concise. Avoid unnecessary comments, error handling, and temporary variables. | ||||||
|
|
||||||
| 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. | ||||||
| Do not write any imports or require() statements, that will cause the script to break. | ||||||
|
|
||||||
| 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. | ||||||
| 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. | ||||||
|
||||||
| 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. | |
| If the user approves the script, the script will run in the Node.js server in a sandboxed vm.createContext() call with only the following global variables available: db, mongoose, ObjectId, and console. 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mutating the
dbobject by addingTypesto it could have unintended side effects if the samedbobject is reused across multiple script executions or in other parts of the application. Consider addingTypesdirectly to the sandbox object instead, or document that this is intentional behavior. For example:sandbox.db = Object.assign({}, db, { Types: mongoose.Types })or add a separateTypesproperty to the sandbox.