Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(sql-editor): text-to-sql demo (#5003)

Liu Jied0e8689edd9
diff --git a/backend/api/v1/setting_service.go b/backend/api/v1/setting_service.go
index 84826d7373..333d757aec 100644
--- a/backend/api/v1/setting_service.go
+++ b/backend/api/v1/setting_service.go
@@ -35,6 +35,7 @@ var whitelistSettings = []api.SettingName{
api.SettingBrandingLogo,
api.SettingAppIM,
api.SettingWatermark,
+ api.SettingPluginOpenAIKey,
}
// GetSetting gets the setting by name.
diff --git a/backend/legacyapi/setting.go b/backend/legacyapi/setting.go
index 3406e4b8b6..7519c5093c 100644
--- a/backend/legacyapi/setting.go
+++ b/backend/legacyapi/setting.go
@@ -27,6 +27,9 @@ const (
// SettingAgentToken is the setting name for the agent token to call the internal API.
// For now we will call the hub to fetch the subscription license.
SettingAgentToken SettingName = "bb.agent.token"
+ // SettingPluginOpenAIKey is used for OpenAI's API key.
+ // For AI-related features.
+ SettingPluginOpenAIKey SettingName = "bb.plugin.openai-key"
)
// IMType is the type of IM.
diff --git a/backend/server/server.go b/backend/server/server.go
index 4d9bc553cf..552c5cf649 100644
--- a/backend/server/server.go
+++ b/backend/server/server.go
@@ -670,6 +670,15 @@ func (s *Server) getInitSetting(ctx context.Context, datastore *store.Store) (*w
return nil, err
}
+ // initial OpenAI key setting
+ if _, _, err := datastore.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
+ Name: api.SettingPluginOpenAIKey,
+ Value: "",
+ Description: "API key to request OpenAI (ChatGPT)",
+ }, api.SystemBotID); err != nil {
+ return nil, err
+ }
+
// initial workspace profile setting
bytes, err := protojson.Marshal(&storepb.WorkspaceProfileSetting{
ExternalUrl: s.profile.ExternalURL,
diff --git a/backend/server/setting.go b/backend/server/setting.go
index 307e084a43..84d36959bf 100644
--- a/backend/server/setting.go
+++ b/backend/server/setting.go
@@ -21,6 +21,7 @@ var whitelistSettings = []api.SettingName{
api.SettingAppIM,
api.SettingWatermark,
api.SettingWorkspaceProfile,
+ api.SettingPluginOpenAIKey,
}
func (s *Server) registerSettingRoutes(g *echo.Group) {
diff --git a/frontend/package.json b/frontend/package.json
index 3a1dc231ff..fe9f7249c6 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -48,6 +48,8 @@
"papaparse": "5.3.2",
"pev2": "1.5.0",
"pinia": "2.0.23",
+ "pouchdb": "^8.0.1",
+ "pouchdb-find": "^8.0.1",
"qs": "6.11.0",
"rollup": "3.2.5",
"scroll-into-view-if-needed": "^2.2.29",
@@ -85,6 +87,8 @@
"@types/node": "18.11.18",
"@types/normalize-wheel": "^1.0.1",
"@types/papaparse": "5.3.7",
+ "@types/pouchdb": "^6.4.0",
+ "@types/pouchdb-find": "^7.3.0",
"@types/prettier": "2.7.1",
"@types/qs": "6.9.7",
"@types/scrollparent": "^2.0.1",
@@ -103,6 +107,7 @@
"eslint-config-prettier": "8.5.0",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-vue": "9.7.0",
+ "events": "^3.3.0",
"jquery": "3.6.1",
"long": "^5.2.1",
"popper.js": "1.16.1",
@@ -122,6 +127,7 @@
},
"peerDependencies": {
"@popperjs/core": "^2.11.6",
+ "events": "^3.3.0",
"jquery": "1.9.1 - 3",
"popper.js": "^1.16.1",
"vscode-oniguruma": "^1.6.2",
diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml
index 19a8f684e1..e662282933 100644
--- a/frontend/pnpm-lock.yaml
+++ b/frontend/pnpm-lock.yaml
@@ -25,6 +25,8 @@ specifiers:
'@types/node': 18.11.18
'@types/normalize-wheel': ^1.0.1
'@types/papaparse': 5.3.7
+ '@types/pouchdb': ^6.4.0
+ '@types/pouchdb-find': ^7.3.0
'@types/prettier': 2.7.1
'@types/qs': 6.9.7
'@types/scrollparent': ^2.0.1
@@ -54,6 +56,7 @@ specifiers:
eslint-config-prettier: 8.5.0
eslint-plugin-prettier: 4.2.1
eslint-plugin-vue: 9.7.0
+ events: ^3.3.0
google-protobuf: ^3.21.2
highlight.js: 11.6.0
html-to-image: ^1.11.4
@@ -74,6 +77,8 @@ specifiers:
pinia: 2.0.23
popper.js: 1.16.1
postcss: 8.4.18
+ pouchdb: ^8.0.1
+ pouchdb-find: ^8.0.1
prettier: 2.7.1
protobufjs: ^7.1.2
qs: 6.11.0
@@ -142,6 +147,8 @@ dependencies:
papaparse: 5.3.2
pev2: 1.5.0_47tpum6wtjtozdoo6t4hr5iro4
pinia: 2.0.23_l7r24p6nevbtlimqmqcwa3ouhu
+ pouchdb: 8.0.1
+ pouchdb-find: 8.0.1
qs: 6.11.0
rollup: 3.2.5
scroll-into-view-if-needed: 2.2.29
@@ -179,6 +186,8 @@ devDependencies:
'@types/node': 18.11.18
'@types/normalize-wheel': 1.0.1
'@types/papaparse': 5.3.7
+ '@types/pouchdb': 6.4.0
+ '@types/pouchdb-find': 7.3.0
'@types/prettier': 2.7.1
'@types/qs': 6.9.7
'@types/scrollparent': 2.0.1
@@ -197,6 +206,7 @@ devDependencies:
eslint-config-prettier: [email protected]
eslint-plugin-prettier: 4.2.1_aniwkeyvlpmwkidetuytnokvcm
eslint-plugin-vue: [email protected]
+ events: 3.3.0
jquery: 3.6.1
long: 5.2.1
popper.js: 1.16.1
@@ -904,6 +914,12 @@ packages:
'@types/d3-zoom': 3.0.1
dev: false
+ /@types/debug/4.1.7:
+ resolution: {integrity: sha512-9AonUzyTjXXhEOa0DnqpzZi6VHlqKMswga9EXjpXnnqxwLtdvPPtlO8evrI5D9S6asFRCQ6v+wpiUKbw+vKqyg==}
+ dependencies:
+ '@types/ms': 0.7.31
+ dev: true
+
/@types/dompurify/2.3.4:
resolution: {integrity: sha512-EXzDatIb5EspL2eb/xPGmaC8pePcTHrkDCONjeisusLFrVfl38Pjea/R0YJGu3k9ZQadSvMqW0WXPI2hEo2Ajg==}
dependencies:
@@ -961,6 +977,10 @@ packages:
dev: false
optional: true
+ /@types/ms/0.7.31:
+ resolution: {integrity: sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==}
+ dev: true
+
/@types/node/17.0.45:
resolution: {integrity: sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw==}
dev: false
@@ -983,6 +1003,135 @@ packages:
'@types/node': 18.11.18
dev: true
+ /@types/pouchdb-adapter-cordova-sqlite/1.0.1:
+ resolution: {integrity: sha512-nqlXpW1ho3KBg1mUQvZgH2755y3z/rw4UA7ZJCPMRTHofxGMY8izRVw5rHBL4/7P615or0J2udpRYxgkT3D02g==}
+ dependencies:
+ '@types/pouchdb-core': 7.0.10
+ dev: true
+
+ /@types/pouchdb-adapter-fruitdown/6.1.3:
+ resolution: {integrity: sha512-Wz1Z1JLOW1hgmFQjqnSkmyyfH7by/iWb4abKn684WMvQfmxx6BxKJpJ4+eulkVPQzzgMMSgU1MpnQOm9FgRkbw==}
+ dependencies:
+ '@types/pouchdb-core': 7.0.10
+ dev: true
+
+ /@types/pouchdb-adapter-http/6.1.3:
+ resolution: {integrity: sha512-9Z4TLbF/KJWy/D2sWRPBA+RNU0odQimfdvlDX+EY7rGcd3aVoH8qjD/X0Xcd/0dfBH5pKrNIMFFQgW/TylRCmA==}
+ dependencies:
+ '@types/pouchdb-core': 7.0.10
+ dev: true
+
+ /@types/pouchdb-adapter-idb/6.1.4:
+ resolution: {integrity: sha512-KIAXbkF4uYUz0ZwfNEFLtEkK44mEWopAsD76UhucH92XnJloBysav+TjI4FFfYQyTjoW3S1s6V+Z14CUJZ0F6w==}
+ dependencies:
+ '@types/pouchdb-core': 7.0.10
+ dev: true
+
+ /@types/pouchdb-adapter-leveldb/6.1.3:
+ resolution: {integrity: sha512-ex8NFqQGFwEpFi7AaZ5YofmuemfZNsL3nTFZBUCAKYMBkazQij1pe2ILLStSvJr0XS0qxgXjCEW19T5Wqiiskg==}
+ dependencies:
+ '@types/pouchdb-core': 7.0.10
+ dev: true
+
+ /@types/pouchdb-adapter-localstorage/6.1.3:
+ resolution: {integrity: sha512-oor040tye1KKiGLWYtIy7rRT7C2yoyX3Tf6elEJRpjOA7Ja/H8lKc4LaSh9ATbptIcES6MRqZDxtp7ly9hsW3Q==}
+ dependencies:
+ '@types/pouchdb-core': 7.0.10
+ dev: true
+
+ /@types/pouchdb-adapter-memory/6.1.3:
+ resolution: {integrity: sha512-gVbsIMzDzgZYThFVT4eVNsmuZwVm/4jDxP1sjlgc3qtDIxbtBhGgyNfcskwwz9Zu5Lv1avkDsIWvcxQhnvRlHg==}
+ dependencies:
+ '@types/pouchdb-core': 7.0.10
+ dev: true
+
+ /@types/pouchdb-adapter-node-websql/6.1.3:
+ resolution: {integrity: sha512-F/P+os6Jsa7CgHtH64+Z0HfwIcj0hIRB5z8gNhF7L7dxPWoAfkopK5H2gydrP3sQrlGyN4WInF+UJW/Zu1+FKg==}
+ dependencies:
+ '@types/pouchdb-adapter-websql': 6.1.4
+ '@types/pouchdb-core': 7.0.10
+ dev: true
+
+ /@types/pouchdb-adapter-websql/6.1.4:
+ resolution: {integrity: sha512-zMJQCtXC40hBsIDRn0GhmpeGMK0f9l/OGWfLguvczROzxxcOD7REI+e6SEmX7gJKw5JuMvlfuHzkQwjmvSJbtg==}
+ dependencies:
+ '@types/pouchdb-core': 7.0.10
+ dev: true
+
+ /@types/pouchdb-browser/6.1.3:
+ resolution: {integrity: sha512-EdYowrWxW9SWBMX/rux2eq7dbHi5Zeyzz+FF/IAsgQKnUxgeCO5VO2j4zTzos0SDyJvAQU+EYRc11r7xGn5tvA==}
+ dependencies:
+ '@types/pouchdb-adapter-http': 6.1.3
+ '@types/pouchdb-adapter-idb': 6.1.4
+ '@types/pouchdb-adapter-websql': 6.1.4
+ '@types/pouchdb-core': 7.0.10
+ '@types/pouchdb-mapreduce': 6.1.7
+ '@types/pouchdb-replication': 6.4.4
+ dev: true
+
+ /@types/pouchdb-core/7.0.10:
+ resolution: {integrity: sha512-mKhjLlWWXyV3PTTjDhzDV1kc2dolO7VYFa75IoKM/hr8Er9eo8RIbS7mJLfC8r/C3p6ihZu9yZs1PWC1LQ0SOA==}
+ dependencies:
+ '@types/debug': 4.1.7
+ '@types/pouchdb-find': 7.3.0
+ dev: true
+
+ /@types/pouchdb-find/7.3.0:
+ resolution: {integrity: sha512-sFPli5tBjGX9UfXioik1jUzPdcN84eV82n0lmEFuoPepWqkLjQcyri0eOa++HYOaNPyMDhKFBqEALEZivK2dRg==}
+ dependencies:
+ '@types/pouchdb-core': 7.0.10
+ dev: true
+
+ /@types/pouchdb-http/6.1.3:
+ resolution: {integrity: sha512-0e9E5SqNOyPl/3FnEIbENssB4FlJsNYuOy131nxrZk36S+y1R/6qO7ZVRypWpGTqBWSuVd7gCsq2UDwO/285+w==}
+ dependencies:
+ '@types/pouchdb-adapter-http': 6.1.3
+ '@types/pouchdb-core': 7.0.10
+ dev: true
+
+ /@types/pouchdb-mapreduce/6.1.7:
+ resolution: {integrity: sha512-WzBwm7tmO9QhfRzVaWT4v6JQSS/fG2OoUDrWrhX87rPe2Pn6laPvdK5li6myNRxCoI/l5e8Jd+oYBAFnaiFucA==}
+ dependencies:
+ '@types/pouchdb-core': 7.0.10
+ dev: true
+
+ /@types/pouchdb-node/6.1.4:
+ resolution: {integrity: sha512-wnTCH8X1JOPpNOfVhz8HW0AvmdHh6pt40MuRj0jQnK7QEHsHS79WujsKTKSOF8QXtPwpvCNSsI7ut7H7tfxxJQ==}
+ dependencies:
+ '@types/pouchdb-adapter-http': 6.1.3
+ '@types/pouchdb-adapter-leveldb': 6.1.3
+ '@types/pouchdb-core': 7.0.10
+ '@types/pouchdb-mapreduce': 6.1.7
+ '@types/pouchdb-replication': 6.4.4
+ dev: true
+
+ /@types/pouchdb-replication/6.4.4:
+ resolution: {integrity: sha512-BsE5LKpjJK4iAf6Fx5kyrMw+33V+Ip7uWldUnU2BYrrvtR+MLD22dcImm7DZN1st2wPPb91i0XEnQzvP0w1C/Q==}
+ dependencies:
+ '@types/pouchdb-core': 7.0.10
+ '@types/pouchdb-find': 7.3.0
+ dev: true
+
+ /@types/pouchdb/6.4.0:
+ resolution: {integrity: sha512-eGCpX+NXhd5VLJuJMzwe3L79fa9+IDTrAG3CPaf4s/31PD56hOrhDJTSmRELSXuiqXr6+OHzzP0PldSaWsFt7w==}
+ dependencies:
+ '@types/pouchdb-adapter-cordova-sqlite': 1.0.1
+ '@types/pouchdb-adapter-fruitdown': 6.1.3
+ '@types/pouchdb-adapter-http': 6.1.3
+ '@types/pouchdb-adapter-idb': 6.1.4
+ '@types/pouchdb-adapter-leveldb': 6.1.3
+ '@types/pouchdb-adapter-localstorage': 6.1.3
+ '@types/pouchdb-adapter-memory': 6.1.3
+ '@types/pouchdb-adapter-node-websql': 6.1.3
+ '@types/pouchdb-adapter-websql': 6.1.4
+ '@types/pouchdb-browser': 6.1.3
+ '@types/pouchdb-core': 7.0.10
+ '@types/pouchdb-http': 6.1.3
+ '@types/pouchdb-mapreduce': 6.1.7
+ '@types/pouchdb-node': 6.1.4
+ '@types/pouchdb-replication': 6.4.4
+ dev: true
+
/@types/prettier/2.7.1:
resolution: {integrity: sha512-ri0UmynRRvZiiUJdiz38MmIblKK+oH30MztdBVR95dv/Ubw6neWSb8u1XpRb72L4qsZOhz+L+z9JD40SJmfWow==}
dev: true
@@ -1374,6 +1523,35 @@ packages:
resolution: {integrity: sha512-lJ2ssrl3FoTK3cX/g15lRCkXFWKiwRTRtBjfwounO2EM/Q65rI/MEZsfsch1juWU2pH2aLSaq0HGowlDP/imrw==}
dev: false
+ /abort-controller/3.0.0:
+ resolution: {integrity: sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==}
+ engines: {node: '>=6.5'}
+ dependencies:
+ event-target-shim: 5.0.1
+ dev: false
+
+ /abstract-leveldown/6.2.3:
+ resolution: {integrity: sha512-BsLm5vFMRUrrLeCcRc+G0t2qOaTzpoJQLOubq2XM72eNpjF5UdU5o/5NvlNhx95XHcAvcl8OMXr4mlg/fRgUXQ==}
+ engines: {node: '>=6'}
+ dependencies:
+ buffer: 5.7.1
+ immediate: 3.3.0
+ level-concat-iterator: 2.0.1
+ level-supports: 1.0.1
+ xtend: 4.0.2
+ dev: false
+
+ /abstract-leveldown/6.3.0:
+ resolution: {integrity: sha512-TU5nlYgta8YrBMNpc9FwQzRbiXsj49gsALsXadbGHt9CROPzX5fB0rWDR5mtdpOOKa5XqRFpbj1QroPAoPzVjQ==}
+ engines: {node: '>=6'}
+ dependencies:
+ buffer: 5.7.1
+ immediate: 3.3.0
+ level-concat-iterator: 2.0.1
+ level-supports: 1.0.1
+ xtend: 4.0.2
+ dev: false
+
/acorn-jsx/[email protected]:
resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==}
peerDependencies:
@@ -1496,6 +1674,10 @@ packages:
/balanced-match/1.0.2:
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
+ /base64-js/1.5.1:
+ resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
+ dev: false
+
/big-integer/1.6.51:
resolution: {integrity: sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg==}
engines: {node: '>=0.6'}
@@ -1560,6 +1742,17 @@ packages:
update-browserslist-db: [email protected]
dev: true
+ /buffer-from/1.1.2:
+ resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==}
+ dev: false
+
+ /buffer/5.7.1:
+ resolution: {integrity: sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==}
+ dependencies:
+ base64-js: 1.5.1
+ ieee754: 1.2.1
+ dev: false
+
/call-bind/1.0.2:
resolution: {integrity: sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==}
dependencies:
@@ -1642,6 +1835,11 @@ packages:
tiny-emitter: 2.1.0
dev: false
+ /clone-buffer/1.0.0:
+ resolution: {integrity: sha512-KLLTJWrvwIP+OPfMn0x2PheDEP20RPUcGXj/ERegTgdmPEZylALQldygiqrPPu8P45uNuPs7ckmReLY6v/iA5g==}
+ engines: {node: '>= 0.10'}
+ dev: false
+
/color-convert/2.0.1:
resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==}
engines: {node: '>=7.0.0'}
@@ -1676,6 +1874,10 @@ packages:
/concat-map/0.0.1:
resolution: {integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=}
+ /core-util-is/1.0.3:
+ resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==}
+ dev: false
+
/cross-spawn/7.0.3:
resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==}
engines: {node: '>= 8'}
@@ -2021,6 +2223,14 @@ packages:
resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==}
dev: true
+ /deferred-leveldown/5.3.0:
+ resolution: {integrity: sha512-a59VOT+oDy7vtAbLRCZwWgxu2BaCfd5Hk7wxJd48ei7I+nsg8Orlb9CLG0PMZienk9BSUKgeAqkO2+Lw+1+Ukw==}
+ engines: {node: '>=6'}
+ dependencies:
+ abstract-leveldown: 6.2.3
+ inherits: 2.0.4
+ dev: false
+
/defined/1.0.1:
resolution: {integrity: sha512-hsBd2qSVCRE+5PmNdHt1uzyrFu5d3RwmFDKzyNZMFq/EwDNJF7Ee5+D5oEKF0hU6LhtoUF1macFvOe4AskQC1Q==}
dev: true
@@ -2101,6 +2311,10 @@ packages:
resolution: {integrity: sha512-Be9tbQMZds4a3C6xTmz68NlMfeONA//4dOavl/1rNw50E+/QO0KVpbcU0PcaW0nsQxurXls9ZocqFxk8R2mWEA==}
dev: false
+ /double-ended-queue/2.1.0-0:
+ resolution: {integrity: sha512-+BNfZ+deCo8hMNpDqDnvT+c0XpJ5cUa6mqYq89bho2Ifze4URTqRkcwR399hWoTrTkbZ/XJYDgP6rc7pRgffEQ==}
+ dev: false
+
/downloadjs/1.4.7:
resolution: {integrity: sha512-LN1gO7+u9xjU5oEScGFKvXhYf7Y/empUIIEAGBs1LzUq/rg5duiDrkuH5A2lQGd5jfMOb9X9usDa2oVXwJ0U/Q==}
dev: false
@@ -2124,6 +2338,29 @@ packages:
engines: {node: '>=14.16'}
dev: false
+ /encoding-down/6.3.0:
+ resolution: {integrity: sha512-QKrV0iKR6MZVJV08QY0wp1e7vF6QbhnbQhb07bwpEyuz4uZiZgPlEGdkCROuFkUwdxlFaiPIhjyarH1ee/3vhw==}
+ engines: {node: '>=6'}
+ dependencies:
+ abstract-leveldown: 6.3.0
+ inherits: 2.0.4
+ level-codec: 9.0.2
+ level-errors: 2.0.1
+ dev: false
+
+ /end-stream/0.1.0:
+ resolution: {integrity: sha512-Brl10T8kYnc75IepKizW6Y9liyW8ikz1B7n/xoHrJxoVSSjoqPn30sb7XVFfQERK4QfUMYRGs9dhWwtt2eu6uA==}
+ dependencies:
+ write-stream: 0.4.3
+ dev: false
+
+ /errno/0.1.8:
+ resolution: {integrity: sha512-dJ6oBr5SQ1VSd9qkk7ByRgb/1SH4JZjCHSW/mr63/QcXO9zLVxvJ6Oy13nio03rxpSnVDDjFor75SjVeZWPW/A==}
+ hasBin: true
+ dependencies:
+ prr: 1.0.1
+ dev: false
+
/esbuild-android-64/0.15.13:
resolution: {integrity: sha512-yRorukXBlokwTip+Sy4MYskLhJsO0Kn0/Fj43s1krVblfwP+hMD37a4Wmg139GEsMLl+vh8WXp2mq/cTA9J97g==}
engines: {node: '>=12'}
@@ -2539,6 +2776,16 @@ packages:
engines: {node: '>=0.10.0'}
dev: true
+ /event-target-shim/5.0.1:
+ resolution: {integrity: sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==}
+ engines: {node: '>=6'}
+ dev: false
+
+ /events/3.3.0:
+ resolution: {integrity: sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==}
+ engines: {node: '>=0.8.x'}
+ dev: true
+
/evtd/0.2.4:
resolution: {integrity: sha512-qaeGN5bx63s/AXgQo8gj6fBkxge+OoLddLniox5qtLAEY5HSnuSlISXVPxnSae1dWblvTh4/HoMIB+mbMsvZzw==}
dev: false
@@ -2591,6 +2838,13 @@ packages:
reusify: 1.0.4
dev: true
+ /fetch-cookie/0.11.0:
+ resolution: {integrity: sha512-BQm7iZLFhMWFy5CZ/162sAGjBfdNWb7a8LEqqnzsHFhxT/X/SVj/z2t2nu3aJvjlbQkrAlTUApplPRjWyH4mhA==}
+ engines: {node: '>=8'}
+ dependencies:
+ tough-cookie: 4.1.2
+ dev: false
+
/file-entry-cache/6.0.1:
resolution: {integrity: sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==}
engines: {node: ^10.12.0 || >=12.0.0}
@@ -2793,11 +3047,19 @@ packages:
safer-buffer: 2.1.2
dev: false
+ /ieee754/1.2.1:
+ resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==}
+ dev: false
+
/ignore/5.2.0:
resolution: {integrity: sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==}
engines: {node: '>= 4'}
dev: true
+ /immediate/3.3.0:
+ resolution: {integrity: sha512-HR7EVodfFUdQCTIeySw+WDRFJlPcLOJbXfwwZ7Oom6tjsvZ3bOkCDJHehQC3nxJrv7+f9XecwazynjU8e4Vw3Q==}
+ dev: false
+
/immutable/4.1.0:
resolution: {integrity: sha512-oNkuqVTA8jqG1Q6c+UglTOD1xhC1BtjKI7XkCXRkZHrN5m18/XsnUp8Q89GkQO/z+0WjonSvl0FLhDYftp46nQ==}
dev: false
@@ -2824,7 +3086,6 @@ packages:
/inherits/2.0.4:
resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==}
- dev: true
/inter-ui/3.19.3:
resolution: {integrity: sha512-5FG9fjuYOXocIfjzcCBhICL5cpvwEetseL3FU6tP3d6Bn7g8wODhB+I9RNGRTizCT7CUG4GOK54OPxqq3msQgg==}
@@ -2871,6 +3132,10 @@ packages:
engines: {node: '>=8'}
dev: true
+ /isarray/0.0.1:
+ resolution: {integrity: sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==}
+ dev: false
+
/isexe/2.0.0:
resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==}
dev: true
@@ -2915,6 +3180,94 @@ packages:
resolution: {integrity: sha512-dLkz37Ab97HWMx9KTes3Tbi3D1ln9fCAy2zr2YVExJasDRPGRaKcoE4fycWNtnCAJfjFqe0cnY+f8KT2JePEXQ==}
dev: true
+ /level-codec/9.0.2:
+ resolution: {integrity: sha512-UyIwNb1lJBChJnGfjmO0OR+ezh2iVu1Kas3nvBS/BzGnx79dv6g7unpKIDNPMhfdTEGoc7mC8uAu51XEtX+FHQ==}
+ engines: {node: '>=6'}
+ dependencies:
+ buffer: 5.7.1
+ dev: false
+
+ /level-concat-iterator/2.0.1:
+ resolution: {integrity: sha512-OTKKOqeav2QWcERMJR7IS9CUo1sHnke2C0gkSmcR7QuEtFNLLzHQAvnMw8ykvEcv0Qtkg0p7FOwP1v9e5Smdcw==}
+ engines: {node: '>=6'}
+ dev: false
+
+ /level-errors/2.0.1:
+ resolution: {integrity: sha512-UVprBJXite4gPS+3VznfgDSU8PTRuVX0NXwoWW50KLxd2yw4Y1t2JUR5In1itQnudZqRMT9DlAM3Q//9NCjCFw==}
+ engines: {node: '>=6'}
+ dependencies:
+ errno: 0.1.8
+ dev: false
+
+ /level-iterator-stream/4.0.2:
+ resolution: {integrity: sha512-ZSthfEqzGSOMWoUGhTXdX9jv26d32XJuHz/5YnuHZzH6wldfWMOVwI9TBtKcya4BKTyTt3XVA0A3cF3q5CY30Q==}
+ engines: {node: '>=6'}
+ dependencies:
+ inherits: 2.0.4
+ readable-stream: 3.6.1
+ xtend: 4.0.2
+ dev: false
+
+ /level-js/5.0.2:
+ resolution: {integrity: sha512-SnBIDo2pdO5VXh02ZmtAyPP6/+6YTJg2ibLtl9C34pWvmtMEmRTWpra+qO/hifkUtBTOtfx6S9vLDjBsBK4gRg==}
+ dependencies:
+ abstract-leveldown: 6.2.3
+ buffer: 5.7.1
+ inherits: 2.0.4
+ ltgt: 2.2.1
+ dev: false
+
+ /level-packager/5.1.1:
+ resolution: {integrity: sha512-HMwMaQPlTC1IlcwT3+swhqf/NUO+ZhXVz6TY1zZIIZlIR0YSn8GtAAWmIvKjNY16ZkEg/JcpAuQskxsXqC0yOQ==}
+ engines: {node: '>=6'}
+ dependencies:
+ encoding-down: 6.3.0
+ levelup: 4.4.0
+ dev: false
+
+ /level-supports/1.0.1:
+ resolution: {integrity: sha512-rXM7GYnW8gsl1vedTJIbzOrRv85c/2uCMpiiCzO2fndd06U/kUXEEU9evYn4zFggBOg36IsBW8LzqIpETwwQzg==}
+ engines: {node: '>=6'}
+ dependencies:
+ xtend: 4.0.2
+ dev: false
+
+ /level-write-stream/1.0.0:
+ resolution: {integrity: sha512-bBNKOEOMl8msO+uIM9YX/gUO6ckokZ/4pCwTm/lwvs46x6Xs8Zy0sn3Vh37eDqse4mhy4fOMIb/JsSM2nyQFtw==}
+ dependencies:
+ end-stream: 0.1.0
+ dev: false
+
+ /level/6.0.1:
+ resolution: {integrity: sha512-psRSqJZCsC/irNhfHzrVZbmPYXDcEYhA5TVNwr+V92jF44rbf86hqGp8fiT702FyiArScYIlPSBTDUASCVNSpw==}
+ engines: {node: '>=8.6.0'}
+ dependencies:
+ level-js: 5.0.2
+ level-packager: 5.1.1
+ leveldown: 5.6.0
+ dev: false
+
+ /leveldown/5.6.0:
+ resolution: {integrity: sha512-iB8O/7Db9lPaITU1aA2txU/cBEXAt4vWwKQRrrWuS6XDgbP4QZGj9BL2aNbwb002atoQ/lIotJkfyzz+ygQnUQ==}
+ engines: {node: '>=8.6.0'}
+ requiresBuild: true
+ dependencies:
+ abstract-leveldown: 6.2.3
+ napi-macros: 2.0.0
+ node-gyp-build: 4.1.1
+ dev: false
+
+ /levelup/4.4.0:
+ resolution: {integrity: sha512-94++VFO3qN95cM/d6eBXvd894oJE0w3cInq9USsyQzzoJxmiYzPAocNcuGCPGGjoXqDVJcr3C1jzt1TSjyaiLQ==}
+ engines: {node: '>=6'}
+ dependencies:
+ deferred-leveldown: 5.3.0
+ level-errors: 2.0.1
+ level-iterator-stream: 4.0.2
+ level-supports: 1.0.1
+ xtend: 4.0.2
+ dev: false
+
/levn/0.4.1:
resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==}
engines: {node: '>= 0.8.0'}
@@ -2979,6 +3332,10 @@ packages:
dependencies:
yallist: 4.0.0
+ /ltgt/2.2.1:
+ resolution: {integrity: sha512-AI2r85+4MquTw9ZYqabu4nMwy9Oftlfa/e/52t9IjtfG+mGBbTNdAoZ3RQKLHR6r0wQnwZnPIEh/Ya6XTWAKNA==}
+ dev: false
+
/magic-string/0.25.9:
resolution: {integrity: sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ==}
dependencies:
@@ -3116,6 +3473,10 @@ packages:
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
hasBin: true
+ /napi-macros/2.0.0:
+ resolution: {integrity: sha512-A0xLykHtARfueITVDernsAWdtIMbOJgKgcluwENp3AlsKN/PloyO10HtmoqnFAQAcxPkgZN7wdfPfEd0zNGxbg==}
+ dev: false
+
/natural-compare-lite/1.4.0:
resolution: {integrity: sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==}
dev: true
@@ -3151,6 +3512,23 @@ packages:
- google-protobuf
dev: false
+ /node-fetch/2.6.7:
+ resolution: {integrity: sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==}
+ engines: {node: 4.x || >=6.0.0}
+ peerDependencies:
+ encoding: ^0.1.0
+ peerDependenciesMeta:
+ encoding:
+ optional: true
+ dependencies:
+ whatwg-url: 5.0.0
+ dev: false
+
+ /node-gyp-build/4.1.1:
+ resolution: {integrity: sha512-dSq1xmcPDKPZ2EED2S6zw/b9NKsqzXRE6dVr8TVQnI3FJOTteUMuqF3Qqs6LZg+mLGYJWqQzMbIjMtJqTv87nQ==}
+ hasBin: true
+ dev: false
+
/node-releases/2.0.6:
resolution: {integrity: sha512-PiVXnNuFm5+iYkLBNeq5211hvO38y63T0i2KKh2KnUs3RpzJ+JtODFjkD8yjLwnDkTYF1eKXheUwdssR+NRZdg==}
dev: true
@@ -3421,6 +3799,120 @@ packages:
picocolors: 1.0.0
source-map-js: 1.0.2
+ /pouchdb-abstract-mapreduce/8.0.1:
+ resolution: {integrity: sha512-BxJRHdfiC8gID8h4DPS0Xy6wsa2VBHRHMv9hsm0BhGTWTqS4k8ivItVSeU2dMoXiTBYp+7SerYmovUQNGSX1GA==}
+ dependencies:
+ pouchdb-binary-utils: 8.0.1
+ pouchdb-collate: 8.0.1
+ pouchdb-collections: 8.0.1
+ pouchdb-errors: 8.0.1
+ pouchdb-fetch: 8.0.1
+ pouchdb-mapreduce-utils: 8.0.1
+ pouchdb-md5: 8.0.1
+ pouchdb-utils: 8.0.1
+ transitivePeerDependencies:
+ - encoding
+ dev: false
+
+ /pouchdb-binary-utils/8.0.1:
+ resolution: {integrity: sha512-WsuR/S0aoUlcA0Alt99czkXsfuXWcrYXAcvGiTW02zawVXOafCnb/qHjA09TUaV0oy5HeHmYaNnDckoOUqspeA==}
+ dependencies:
+ buffer-from: 1.1.2
+ dev: false
+
+ /pouchdb-collate/8.0.1:
+ resolution: {integrity: sha512-DTuNz1UJjBTGZMUlWS1klSE1rPsmHy8IIDie3MFH1ZTz/C+SwGgGwkiAyUDv/n00D18EMLgXq5mu+r7L6K1BwQ==}
+ dev: false
+
+ /pouchdb-collections/8.0.1:
+ resolution: {integrity: sha512-TlkQ2GGHJApJgL0b7bJMQcwX6eMfVenLeoK9mqHfC2fJssui+HWJJ5LYKHOWan11SeB90BQVFbO6rHN6CJQeDg==}
+ dev: false
+
+ /pouchdb-errors/8.0.1:
+ resolution: {integrity: sha512-H+ZsQxcG/JV3Tn29gnM6c9+lRPCN91ZYOkoIICsLjVRYgOTzN1AvNUD/G5JCB+81aI/u3fxZec0LEaZh6g6NHA==}
+ dev: false
+
+ /pouchdb-fetch/8.0.1:
+ resolution: {integrity: sha512-Px5HLT8MxqTujc8bpPRKoouznDTJa9XBGqCbhl95q6rhjWRfwZEvXjV92z0B5BALAM6D6avMyG0DjuNfUWnMuA==}
+ dependencies:
+ abort-controller: 3.0.0
+ fetch-cookie: 0.11.0
+ node-fetch: 2.6.7
+ transitivePeerDependencies:
+ - encoding
+ dev: false
+
+ /pouchdb-find/8.0.1:
+ resolution: {integrity: sha512-i5criYXMOXlbeRrCrXonqaOY+xiMiOyTLybqvtX/NkUsiD4BxJxkq5AxdSlHdJ9703nWJ0k6S+5C8VrpEj8tsQ==}
+ dependencies:
+ pouchdb-abstract-mapreduce: 8.0.1
+ pouchdb-collate: 8.0.1
+ pouchdb-errors: 8.0.1
+ pouchdb-fetch: 8.0.1
+ pouchdb-md5: 8.0.1
+ pouchdb-selector-core: 8.0.1
+ pouchdb-utils: 8.0.1
+ transitivePeerDependencies:
+ - encoding
+ dev: false
+
+ /pouchdb-mapreduce-utils/8.0.1:
+ resolution: {integrity: sha512-asZcFLy1DA3oe5CeXIRCpfVrBHaHRvSb3Tc/LPD1dZDDtpEkeCuXGtJm+praN0jl41jTBEm0uMdD/YI0J5ZFXw==}
+ dependencies:
+ pouchdb-collections: 8.0.1
+ pouchdb-utils: 8.0.1
+ dev: false
+
+ /pouchdb-md5/8.0.1:
+ resolution: {integrity: sha512-shVcs/K/iilrcAhDEERpLIrGm/cnDVsXiocOzs7kycJEuBqYnLD9nj58VwWDcum26wfa8T9cznvEGE1jlYVNPQ==}
+ dependencies:
+ pouchdb-binary-utils: 8.0.1
+ spark-md5: 3.0.2
+ dev: false
+
+ /pouchdb-selector-core/8.0.1:
+ resolution: {integrity: sha512-dHWsnR+mLGyfVld1vSHJI1xKTwS1xk1G2dggjfXfUrLehI+wysjTUOwiSNytyPzG6DpT+o86wyUpwzPwsDCLBw==}
+ dependencies:
+ pouchdb-collate: 8.0.1
+ pouchdb-utils: 8.0.1
+ dev: false
+
+ /pouchdb-utils/8.0.1:
+ resolution: {integrity: sha512-pWgxdk9EHVWJmjQoEvTe+ZlPXyjcuQ/vgLITN+RjGwcYhoQYUE1M0PksQd2dUP3V8lGS4+wrg9lEM/qSJPYcpw==}
+ dependencies:
+ clone-buffer: 1.0.0
+ immediate: 3.3.0
+ pouchdb-collections: 8.0.1
+ pouchdb-errors: 8.0.1
+ pouchdb-md5: 8.0.1
+ uuid: 8.3.2
+ dev: false
+
+ /pouchdb/8.0.1:
+ resolution: {integrity: sha512-xp5S83JOQn2NAL0ZQ5CU+DI26V9/YrYuVtkXnbGEIDrYiFfj5A8gAcfbxefXb/9O+Qn4n5RaT/19+8UBSZ42sw==}
+ dependencies:
+ abort-controller: 3.0.0
+ buffer-from: 1.1.2
+ clone-buffer: 1.0.0
+ double-ended-queue: 2.1.0-0
+ fetch-cookie: 0.11.0
+ immediate: 3.3.0
+ level: 6.0.1
+ level-codec: 9.0.2
+ level-write-stream: 1.0.0
+ leveldown: 5.6.0
+ levelup: 4.4.0
+ ltgt: 2.2.1
+ node-fetch: 2.6.7
+ readable-stream: 1.1.14
+ spark-md5: 3.0.2
+ through2: 3.0.2
+ uuid: 8.3.2
+ vuvuzela: 1.0.3
+ transitivePeerDependencies:
+ - encoding
+ dev: false
+
/prelude-ls/1.2.1:
resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==}
engines: {node: '>= 0.8.0'}
@@ -3482,10 +3974,17 @@ packages:
resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==}
dev: false
+ /prr/1.0.1:
+ resolution: {integrity: sha512-yPw4Sng1gWghHQWj0B3ZggWUm4qVbPwPFcRG8KyxiU7J2OHFSoEHKS+EZ3fv5l1t9CyCiop6l/ZYeWbrgoQejw==}
+ dev: false
+
+ /psl/1.9.0:
+ resolution: {integrity: sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==}
+ dev: false
+
/punycode/2.1.1:
resolution: {integrity: sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==}
engines: {node: '>=6'}
- dev: true
/qs/6.11.0:
resolution: {integrity: sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==}
@@ -3494,6 +3993,10 @@ packages:
side-channel: 1.0.4
dev: false
+ /querystringify/2.2.0:
+ resolution: {integrity: sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==}
+ dev: false
+
/queue-microtask/1.2.3:
resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==}
dev: true
@@ -3521,6 +4024,28 @@ packages:
pify: 2.3.0
dev: true
+ /readable-stream/0.0.4:
+ resolution: {integrity: sha512-azrivNydKRYt7zwLV5wWUK7YzKTWs3q87xSmY6DlHapPrCvaT6ZrukvM5erV+yCSSPmZT8zkSdttOHQpWWm9zw==}
+ dev: false
+
+ /readable-stream/1.1.14:
+ resolution: {integrity: sha512-+MeVjFf4L44XUkhM1eYbD8fyEsxcV81pqMSR5gblfcLCHfZvbrqy4/qYHE+/R5HoBUT11WV5O08Cr1n3YXkWVQ==}
+ dependencies:
+ core-util-is: 1.0.3
+ inherits: 2.0.4
+ isarray: 0.0.1
+ string_decoder: 0.10.31
+ dev: false
+
+ /readable-stream/3.6.1:
+ resolution: {integrity: sha512-+rQmrWMYGA90yenhTYsLWAsLsqVC8osOw6PKE1HDYiO0gdPeKe/xDHNzIAIn4C91YQ6oenEhfYqqc1883qHbjQ==}
+ engines: {node: '>= 6'}
+ dependencies:
+ inherits: 2.0.4
+ string_decoder: 1.3.0
+ util-deprecate: 1.0.2
+ dev: false
+
/readdirp/3.6.0:
resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==}
engines: {node: '>=8.10.0'}
@@ -3540,6 +4065,10 @@ packages:
resolution: {integrity: sha1-CkPTqq4egNuRngeuJUsoXZ4ce7U=}
dev: false
+ /requires-port/1.0.0:
+ resolution: {integrity: sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==}
+ dev: false
+
/resolve-from/4.0.0:
resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==}
engines: {node: '>=4'}
@@ -3600,6 +4129,10 @@ packages:
resolution: {integrity: sha512-PdhdWy89SiZogBLaw42zdeqtRJ//zFd2PgQavcICDUgJT5oW10QCRKbJ6bg4r0/UY2M6BWd5tkxuGFRvCkgfHQ==}
dev: false
+ /safe-buffer/5.2.1:
+ resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==}
+ dev: false
+
/safer-buffer/2.1.2:
resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==}
dev: false
@@ -3693,6 +4226,10 @@ packages:
/sourcemap-codec/1.4.8:
resolution: {integrity: sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==}
+ /spark-md5/3.0.2:
+ resolution: {integrity: sha512-wcFzz9cDfbuqe0FZzfi2or1sgyIrsDwmPwfZC4hiNidPdPINjeUwNfv5kldczoEAcjl9Y1L3SM7Uz2PUEQzxQw==}
+ dev: false
+
/splitpanes/3.1.5:
resolution: {integrity: sha512-r3Mq2ITFQ5a2VXLOy4/Sb2Ptp7OfEO8YIbhVJqJXoFc9hc5nTXXkCvtVDjIGbvC0vdE7tse+xTM9BMjsszP6bw==}
dev: false
@@ -3705,6 +4242,16 @@ packages:
nearley: 2.20.1
dev: false
+ /string_decoder/0.10.31:
+ resolution: {integrity: sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ==}
+ dev: false
+
+ /string_decoder/1.3.0:
+ resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==}
+ dependencies:
+ safe-buffer: 5.2.1
+ dev: false
+
/strip-ansi/6.0.1:
resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==}
engines: {node: '>=8'}
@@ -3778,6 +4325,13 @@ packages:
resolution: {integrity: sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==}
dev: true
+ /through2/3.0.2:
+ resolution: {integrity: sha512-enaDQ4MUyP2W6ZyT6EsMzqBPZaM/avg8iuo+l2d3QCs0J+6RaqkHV/2/lOwDTueBHeJ/2LG9lrLW3d5rWPucuQ==}
+ dependencies:
+ inherits: 2.0.4
+ readable-stream: 3.6.1
+ dev: false
+
/tiny-emitter/2.1.0:
resolution: {integrity: sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==}
dev: false
@@ -3821,6 +4375,20 @@ packages:
engines: {node: '>=10'}
dev: true
+ /tough-cookie/4.1.2:
+ resolution: {integrity: sha512-G9fqXWoYFZgTc2z8Q5zaHy/vJMjm+WV0AkAeHxVCQiEB1b+dGvWzFW6QV07cY5jQ5gRkeid2qIkzkxUnmoQZUQ==}
+ engines: {node: '>=6'}
+ dependencies:
+ psl: 1.9.0
+ punycode: 2.1.1
+ universalify: 0.2.0
+ url-parse: 1.5.10
+ dev: false
+
+ /tr46/0.0.3:
+ resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==}
+ dev: false
+
/treemate/0.3.11:
resolution: {integrity: sha512-M8RGFoKtZ8dF+iwJfAJTOH/SM4KluKOKRJpjCMhI8bG3qB74zrFoArKZ62ll0Fr3mqkMJiQOmWYkdYgDeITYQg==}
dev: false
@@ -3891,6 +4459,11 @@ packages:
engines: {node: '>=4.2.0'}
hasBin: true
+ /universalify/0.2.0:
+ resolution: {integrity: sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==}
+ engines: {node: '>= 4.0.0'}
+ dev: false
+
/unplugin-icons/0.15.2_@[email protected]:
resolution: {integrity: sha512-oWTTdLMuqfEYfZcko+KZHDEOIsqT4OeyJB1e4U7luCOo9gto/JLyHkqfbqjmjkjdQqA3DNHS18WOKh5esqQM5g==}
peerDependencies:
@@ -3981,9 +4554,20 @@ packages:
punycode: 2.1.1
dev: true
+ /url-parse/1.5.10:
+ resolution: {integrity: sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==}
+ dependencies:
+ querystringify: 2.2.0
+ requires-port: 1.0.0
+ dev: false
+
/util-deprecate/1.0.2:
resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==}
- dev: true
+
+ /uuid/8.3.2:
+ resolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==}
+ hasBin: true
+ dev: false
/uuid/9.0.0:
resolution: {integrity: sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==}
@@ -4265,6 +4849,14 @@ packages:
vue: 3.2.41
dev: false
+ /vuvuzela/1.0.3:
+ resolution: {integrity: sha512-Tm7jR1xTzBbPW+6y1tknKiEhz04Wf/1iZkcTJjSFcpNko43+dFW6+OOeQe9taJIug3NdfUAjFKgUSyQrIKaDvQ==}
+ dev: false
+
+ /webidl-conversions/3.0.1:
+ resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}
+ dev: false
+
/webpack-sources/3.2.3:
resolution: {integrity: sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==}
engines: {node: '>=10.13.0'}
@@ -4278,6 +4870,13 @@ packages:
resolution: {integrity: sha512-kyDivFZ7ZM0BVOUteVbDFhlRt7Ah/CSPwJdi8hBpkK7QLumUqdLtVfm/PX/hkcnrvr0i77fO5+TjZ94Pe+C9iw==}
dev: true
+ /whatwg-url/5.0.0:
+ resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==}
+ dependencies:
+ tr46: 0.0.3
+ webidl-conversions: 3.0.1
+ dev: false
+
/which/2.0.2:
resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==}
engines: {node: '>= 8'}
@@ -4295,6 +4894,12 @@ packages:
resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==}
dev: true
+ /write-stream/0.4.3:
+ resolution: {integrity: sha512-IJrvkhbAnj89W/GAVdVgbnPiVw5Ntg/B4tc/MUCIEwj/g6JIww1DWJyB/yBMT3yw2/TkT6IUZ0+IYef3flEw8A==}
+ dependencies:
+ readable-stream: 0.0.4
+ dev: false
+
/xml-name-validator/4.0.0:
resolution: {integrity: sha512-ICP2e+jsHvAj2E2lIHxa5tjXRlKDJo4IdvPvCXbXQGdzSfmSpNVyIKMvoZHjDY9DP0zV17iI85o90vRFXNccRw==}
engines: {node: '>=12'}
@@ -4303,7 +4908,6 @@ packages:
/xtend/4.0.2:
resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==}
engines: {node: '>=0.4'}
- dev: true
/yallist/4.0.0:
resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==}
diff --git a/frontend/src/bbkit/BBSpin.vue b/frontend/src/bbkit/BBSpin.vue
index 3b0da29add..a58fb1626d 100644
--- a/frontend/src/bbkit/BBSpin.vue
+++ b/frontend/src/bbkit/BBSpin.vue
@@ -1,7 +1,8 @@
<template>
<div class="flex flex-row items-center text-control text-sm">
<svg
- class="animate-spin h-5 w-5 mr-1 text-blue-600"
+ class="animate-spin h-5 w-5 text-blue-600"
+ :class="[title && 'mr-1']"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index ece56b79ae..a23add6d26 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1934,5 +1934,25 @@
"setup-auth-app": "Setup authenticator app",
"download-recovery-codes": "Download your recovery codes"
}
+ },
+ "plugin": {
+ "ai": {
+ "examples": "Examples",
+ "text-to-sql-placeholder": "Use natural language and Bytebase will convert it into SQL",
+ "run-automatically": "Run automatically",
+ "conversation": {
+ "conversations": "Conversations",
+ "untitled": "Untitled conversation",
+ "delete": "Delete conversation",
+ "rename": "Rename conversation",
+ "select-or-create": "Select or {create} a conversation to start."
+ },
+ "preset-suggestion": {
+ "1": "Which department has most employees?",
+ "2": "Which manager has most direct reports in each department?",
+ "3": "What's the gender ratio in each department?"
+ },
+ "statement-copied": "Statement copied to clipboard"
+ }
}
}
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index a71a6e737b..df4a10ffc7 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1933,5 +1933,25 @@
"setup-auth-app": "设置认证器应用程序",
"download-recovery-codes": "下载恢复码"
}
+ },
+ "plugin": {
+ "ai": {
+ "examples": "例子",
+ "text-to-sql-placeholder": "在此输入自然语言后,Bytebase 会马上转换成 SQL 语句",
+ "run-automatically": "自动运行",
+ "conversation": {
+ "conversations": "会话",
+ "untitled": "未命名会话",
+ "delete": "删除会话",
+ "rename": "修改会话名称",
+ "select-or-create": "选择或{create}一个会话以开始。"
+ },
+ "preset-suggestion": {
+ "1": "哪个部门的员工最多?",
+ "2": "哪个部门经理的下属最多?",
+ "3": "各个部门的性别比例如何?"
+ },
+ "statement-copied": "语句已复制到剪贴板"
+ }
}
}
diff --git a/frontend/src/plugins/ai/components/AIDialog.vue b/frontend/src/plugins/ai/components/AIDialog.vue
new file mode 100644
index 0000000000..e7b2321d26
--- /dev/null
+++ b/frontend/src/plugins/ai/components/AIDialog.vue
@@ -0,0 +1,200 @@
+<template>
+ <BBModal class="!pb-0" container-class="!p-0" @close="$emit('close')">
+ <div
+ class="h-[calc(100vh-10rem)] w-[calc(100vw-8rem)] max-w-[72rem] px-8 pb-4 flex"
+ >
+ <aside class="hidden lg:flex lg:flex-col w-[14em] border-l border-b">
+ <ConversationList />
+ </aside>
+
+ <div class="flex-1 flex flex-col bg-gray-100">
+ <ChatView @enter="requestAI" />
+
+ <div class="px-2 py-2">
+ <div>
+ <label class="inline-flex items-center gap-x-1">
+ <BBCheckbox :value="autoRun" @toggle="autoRun = $event" />
+ <span class="textinfolabel">
+ {{ $t("plugin.ai.run-automatically") }}
+ </span>
+ </label>
+ </div>
+ <PromptInput :disabled="state.loading" @enter="requestAI" />
+ </div>
+ </div>
+ </div>
+ </BBModal>
+</template>
+
+<script lang="ts" setup>
+import { reactive, toRef } from "vue";
+import { Axios, AxiosResponse } from "axios";
+import { head } from "lodash-es";
+
+import { BBCheckbox, BBModal } from "@/bbkit";
+import { useAIContext } from "../logic";
+import type { OpenAIMessage, OpenAIResponse } from "../types";
+import ConversationList from "./ConversationList.vue";
+import ChatView from "./ChatView";
+import PromptInput from "./PromptInput.vue";
+import { useConversationStore } from "../store";
+
+type LocalState = {
+ loading: boolean;
+};
+
+defineEmits<{
+ (event: "close"): void;
+}>();
+
+const state = reactive<LocalState>({
+ loading: false,
+});
+
+const context = useAIContext();
+
+const { showDialog, openAIKey, autoRun } = context;
+
+const store = useConversationStore();
+const conversation = toRef(store, "selectedConversation");
+
+const requestAI = async (query: string) => {
+ const c = conversation.value;
+ if (!c) return;
+
+ const { messageList } = c;
+ if (messageList.length === 0) {
+ // For the first message of a conversation,
+ // add extra database schema metadata info if possible
+ const engineType = context.engineType.value;
+ const databaseMetadata = context.databaseMetadata.value;
+ const prompts: string[] = [];
+ if (engineType) {
+ if (databaseMetadata) {
+ prompts.push(`### ${engineType} tables, with their properties:`);
+ } else {
+ prompts.push(`### ${engineType} database`);
+ }
+ } else {
+ if (databaseMetadata) {
+ prompts.push(`### Giving a database`);
+ }
+ }
+ if (databaseMetadata) {
+ databaseMetadata.schemas.forEach((schema) => {
+ schema.tables.forEach((table) => {
+ const name = schema.name
+ ? `${schema.name}.${table.name}`
+ : table.name;
+ const columns = table.columns.map((column) => column.name).join(", ");
+ prompts.push(`# ${name}(${columns})`);
+ });
+ });
+ }
+ prompts.push(`### Write a SQL statement to solve the question below`);
+ prompts.push(`### ${query}`);
+ const prompt = prompts.join("\n");
+ await store.createMessage({
+ conversation_id: c.id,
+ content: query,
+ prompt,
+ author: "USER",
+ error: "",
+ status: "DONE",
+ });
+ } else {
+ await store.createMessage({
+ conversation_id: c.id,
+ content: query,
+ prompt: query,
+ author: "USER",
+ error: "",
+ status: "DONE",
+ });
+ }
+
+ const answer = await store.createMessage({
+ author: "AI",
+ prompt: "SELECT",
+ content: "",
+ error: "",
+ conversation_id: c.id,
+ status: "LOADING",
+ });
+ const url = "https://api.openai.com/v1/chat/completions";
+ const FINAL_PROMPT = "SELECT";
+ const messages: OpenAIMessage[] = [];
+
+ c.messageList.forEach((message) => {
+ const { author, prompt } = message;
+ messages.push({
+ role: author === "USER" ? "user" : "assistant",
+ content: prompt,
+ });
+ });
+ const body = {
+ model: "gpt-3.5-turbo",
+ messages,
+ temperature: 0,
+ stop: ["#", ";"],
+ top_p: 1.0,
+ frequency_penalty: 0.0,
+ presence_penalty: 0.0,
+ };
+ state.loading = true;
+ const axios = new Axios({
+ timeout: 20 * 1000,
+ responseType: "json",
+ });
+ const headers = {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${openAIKey.value}`,
+ };
+ try {
+ const response: AxiosResponse<string> = await axios.post(
+ url,
+ JSON.stringify(body),
+ {
+ headers,
+ }
+ );
+
+ const data = JSON.parse(response.data) as OpenAIResponse;
+ if (data?.error) {
+ throw new Error(data.error.message);
+ }
+
+ const text = head(data?.choices)?.message.content?.trim();
+ if (text) {
+ const parts = [text];
+ if (!text.startsWith(FINAL_PROMPT)) {
+ parts.unshift(FINAL_PROMPT);
+ }
+ const statement = parts.join(" ").trim();
+
+ answer.content = statement;
+ answer.prompt = statement;
+ }
+
+ answer.status = "DONE";
+ } catch (err) {
+ answer.error = String(err);
+ answer.status = "FAILED";
+ } finally {
+ state.loading = false;
+ await store.updateMessage(answer);
+ if (c.id === conversation.value?.id) {
+ if (answer.status === "FAILED") {
+ context.events.emit("error", answer.error);
+ } else {
+ if (showDialog.value && autoRun.value) {
+ context.events.emit("apply-statement", {
+ statement: answer.content,
+ run: autoRun.value,
+ });
+ }
+ }
+ }
+ }
+};
+</script>
diff --git a/frontend/src/plugins/ai/components/AIPromptButton.vue b/frontend/src/plugins/ai/components/AIPromptButton.vue
new file mode 100644
index 0000000000..d7e0c555e4
--- /dev/null
+++ b/frontend/src/plugins/ai/components/AIPromptButton.vue
@@ -0,0 +1,76 @@
+<template>
+ <button
+ v-if="openAIKey"
+ class="w-full flex items-center gap-x-1 rounded-[3px] border border-control-border bg-white hover:bg-gray-100 pl-2 pr-1 py-1.5 outline-none"
+ @click="state.showDialog = true"
+ >
+ <heroicons-outline:sparkles class="w-4 h-4 text-accent" />
+ <span class="text-control-placeholder flex-1 text-left text-sm">
+ {{ $t("plugin.ai.text-to-sql-placeholder") }}
+ </span>
+
+ <AIDialog v-if="state.showDialog" @close="state.showDialog = false" />
+ </button>
+</template>
+
+<script lang="ts" setup>
+import { computed, reactive, toRef } from "vue";
+
+import AIDialog from "./AIDialog.vue";
+import type { AIContextEvents } from "../types";
+import { DatabaseMetadata } from "@/types/proto/store/database";
+import type { EngineType } from "@/types";
+import Emittery from "emittery";
+import { provideAIContext } from "../logic";
+import { useLocalStorage } from "@vueuse/core";
+import { useSettingByName } from "@/store";
+
+type LocalState = {
+ showDialog: boolean;
+};
+
+const props = withDefaults(
+ defineProps<{
+ engineType?: EngineType;
+ databaseMetadata?: DatabaseMetadata;
+ }>(),
+ {
+ engineType: undefined,
+ databaseMetadata: undefined,
+ }
+);
+
+const emit = defineEmits<{
+ (event: "apply-statement", statement: string, run: boolean): void;
+ (event: "error", error: string): void;
+ (event: "update:loading", loading: boolean): void;
+}>();
+
+const state = reactive<LocalState>({
+ showDialog: false,
+});
+
+const openAIKeySetting = useSettingByName("bb.plugin.openai-key");
+const openAIKey = computed(() => openAIKeySetting.value?.value ?? "");
+
+const events: AIContextEvents = new Emittery();
+
+events.on("apply-statement", ({ statement, run }) => {
+ emit("apply-statement", statement, run);
+ state.showDialog = false;
+});
+events.on("error", (error) => {
+ emit("error", error);
+});
+
+const autoRun = useLocalStorage("bb.plugin.ai.auto-run", true);
+
+provideAIContext({
+ showDialog: toRef(state, "showDialog"),
+ openAIKey,
+ engineType: toRef(props, "engineType"),
+ databaseMetadata: toRef(props, "databaseMetadata"),
+ autoRun,
+ events,
+});
+</script>
diff --git a/frontend/src/plugins/ai/components/ChatView/AIMessageView.vue b/frontend/src/plugins/ai/components/ChatView/AIMessageView.vue
new file mode 100644
index 0000000000..b44f3f3c44
--- /dev/null
+++ b/frontend/src/plugins/ai/components/ChatView/AIMessageView.vue
@@ -0,0 +1,36 @@
+<template>
+ <div
+ class="border rounded shadow py-1 px-1 bg-gray-100 border-gray-400"
+ :class="[
+ message.status === 'DONE'
+ ? 'w-[60%]'
+ : message.status === 'FAILED'
+ ? 'max-w-[60%]'
+ : 'w-auto',
+ ]"
+ >
+ <CodeView v-if="message.status === 'DONE'" :message="message" />
+ <template v-else-if="message.status === 'LOADING'">
+ <BBSpin class="mx-1" />
+ </template>
+ <template v-else>
+ <div class="text-warning flex items-center gap-x-1">
+ <heroicons-outline:exclaimation-triangle
+ class="inline-block w-4 h-4 shrink-0"
+ />
+ <span class="text-sm">
+ {{ message.error }}
+ </span>
+ </div>
+ </template>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import type { Message } from "../../types";
+import CodeView from "./CodeView.vue";
+
+defineProps<{
+ message: Message;
+}>();
+</script>
diff --git a/frontend/src/plugins/ai/components/ChatView/ChatView.vue b/frontend/src/plugins/ai/components/ChatView/ChatView.vue
new file mode 100644
index 0000000000..633d5d9b27
--- /dev/null
+++ b/frontend/src/plugins/ai/components/ChatView/ChatView.vue
@@ -0,0 +1,83 @@
+<template>
+ <div ref="scrollerRef" class="flex-1 py-4 overflow-y-auto">
+ <template v-if="conversation">
+ <PresetSuggestions
+ v-if="conversation.messageList.length === 0"
+ @select="$emit('enter', $event)"
+ />
+ <div
+ v-else
+ ref="containerRef"
+ class="flex flex-col justify-end px-2 gap-y-8"
+ >
+ <div
+ v-for="message in conversation?.messageList"
+ :key="message.id"
+ class="flex"
+ :class="[message.author === 'AI' ? 'justify-start' : 'justify-end']"
+ >
+ <UserMessageView
+ v-if="message.author === 'USER'"
+ :message="message"
+ />
+ <AIMessageView v-if="message.author === 'AI'" :message="message" />
+ </div>
+ </div>
+ </template>
+ <template v-else>
+ <div
+ class="w-full h-full flex flex-col justify-end items-center pb-[2rem]"
+ >
+ <i18n-t
+ keypath="plugin.ai.conversation.select-or-create"
+ tag="p"
+ class="textinfolabel"
+ >
+ <template #create>
+ <button class="normal-link" @click="handleCreate">
+ {{ $t("common.create") }}
+ </button>
+ </template>
+ </i18n-t>
+ </div>
+ </template>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { ref, toRef, watch } from "vue";
+import { useElementSize } from "@vueuse/core";
+
+import UserMessageView from "./UserMessageView.vue";
+import AIMessageView from "./AIMessageView.vue";
+import PresetSuggestions from "./PresetSuggestions.vue";
+import { useConversationStore } from "../../store";
+
+defineEmits<{
+ (event: "enter", value: string): void;
+}>();
+
+const scrollerRef = ref<HTMLDivElement>();
+const containerRef = ref<HTMLDivElement>();
+
+const store = useConversationStore();
+const conversation = toRef(store, "selectedConversation");
+
+const { height: containerHeight } = useElementSize(containerRef);
+
+const scrollToLast = () => {
+ const scroller = scrollerRef.value;
+ const container = containerRef.value;
+ if (!scroller) return;
+ if (!container) return;
+ scroller.scrollTo(0, container.scrollHeight);
+};
+watch(containerHeight, scrollToLast, { immediate: true });
+
+const handleCreate = async () => {
+ const c = await store.createConversation({
+ name: "", // Will display as "Untitled conversation"
+ });
+ store.selectConversation(c);
+};
+</script>
diff --git a/frontend/src/plugins/ai/components/ChatView/CodeView.vue b/frontend/src/plugins/ai/components/ChatView/CodeView.vue
new file mode 100644
index 0000000000..584ed29af0
--- /dev/null
+++ b/frontend/src/plugins/ai/components/ChatView/CodeView.vue
@@ -0,0 +1,86 @@
+<template>
+ <div class="flex items-start w-full">
+ <MonacoEditor
+ ref="editorRef"
+ class="flex-1 border h-auto max-h-[240px]"
+ language="sql"
+ :value="message.content"
+ :readonly="true"
+ :auto-focus="false"
+ :options="{
+ fontSize: 12,
+ lineHeight: 14,
+ lineNumbers: 'off',
+ wordWrap: 'off',
+ scrollbar: {
+ vertical: 'hidden',
+ horizontal: 'hidden',
+ useShadows: false,
+ verticalScrollbarSize: 0,
+ horizontalScrollbarSize: 0,
+ },
+ }"
+ @ready="handleMonacoEditorReady"
+ />
+ <div class="flex flex-col gap-y-2 ml-0.5 mt-1">
+ <button
+ class="inline-flex items-center justify-center hover:text-accent cursor-pointer"
+ @click="handleExecute"
+ >
+ <heroicons-outline:play class="w-4 h-4" />
+ </button>
+ <button
+ class="inline-flex items-center justify-center hover:text-accent cursor-pointer"
+ @click="handleCopy"
+ >
+ <heroicons-outline:clipboard-copy class="w-4 h-4" />
+ </button>
+ </div>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { ref } from "vue";
+import { toClipboard } from "@soerenmartius/vue3-clipboard";
+
+import type { Message } from "../../types";
+import MonacoEditor from "@/components/MonacoEditor";
+import { useAIContext } from "../../logic";
+import { pushNotification } from "@/store";
+import { useI18n } from "vue-i18n";
+
+const props = defineProps<{
+ message: Message;
+}>();
+
+const { t } = useI18n();
+const context = useAIContext();
+const editorRef = ref<InstanceType<typeof MonacoEditor>>();
+
+const updateEditorHeight = () => {
+ const contentHeight =
+ editorRef.value?.editorInstance?.getContentHeight() as number;
+ editorRef.value?.setEditorContentHeight(contentHeight);
+};
+
+const handleMonacoEditorReady = () => {
+ updateEditorHeight();
+};
+
+const handleExecute = () => {
+ context.events.emit("apply-statement", {
+ statement: props.message.content,
+ run: true,
+ });
+};
+
+const handleCopy = () => {
+ toClipboard(props.message.content).then(() => {
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("plugin.ai.statement-copied"),
+ });
+ });
+};
+</script>
diff --git a/frontend/src/plugins/ai/components/ChatView/PresetSuggestions.vue b/frontend/src/plugins/ai/components/ChatView/PresetSuggestions.vue
new file mode 100644
index 0000000000..61c72a8547
--- /dev/null
+++ b/frontend/src/plugins/ai/components/ChatView/PresetSuggestions.vue
@@ -0,0 +1,43 @@
+<template>
+ <div class="w-full h-full flex flex-col justify-end items-center pb-[2rem]">
+ <div
+ class="w-[30rem] mx-auto bg-white border border-control-border rounded shadow-md py-1"
+ >
+ <div class="mt-1 mb-2 px-2 text-md font-normal text-control-light">
+ {{ $t("plugin.ai.examples") }}
+ </div>
+
+ <ul class="px-1 text-sm">
+ <li
+ v-for="(sug, i) in presetSuggestions"
+ :key="i"
+ class="py-2 px-1 flex items-center justify-between gap-x-1 rounded-sm hover:bg-indigo-600/10 cursor-default"
+ @click="$emit('select', sug)"
+ >
+ <heroicons-outline:magnifying-glass class="w-4 h-4" />
+ <span class="flex-1">{{ sug }}</span>
+ <heroicons-outline:chevron-right class="w-4 h-4 text-gray-400" />
+ </li>
+ </ul>
+ </div>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { computed } from "vue";
+import { useI18n } from "vue-i18n";
+
+defineEmits<{
+ (event: "select", preset: string): void;
+}>();
+
+const { t } = useI18n();
+
+const presetSuggestions = computed(() => {
+ return [
+ t("plugin.ai.preset-suggestion.1"),
+ t("plugin.ai.preset-suggestion.2"),
+ t("plugin.ai.preset-suggestion.3"),
+ ];
+});
+</script>
diff --git a/frontend/src/plugins/ai/components/ChatView/UserMessageView.vue b/frontend/src/plugins/ai/components/ChatView/UserMessageView.vue
new file mode 100644
index 0000000000..426955362c
--- /dev/null
+++ b/frontend/src/plugins/ai/components/ChatView/UserMessageView.vue
@@ -0,0 +1,15 @@
+<template>
+ <div
+ class="max-w-[60%] border rounded shadow py-1 px-2 bg-indigo-100 border-indigo-400"
+ >
+ {{ message.content }}
+ </div>
+</template>
+
+<script lang="ts" setup>
+import type { Message } from "../../types";
+
+defineProps<{
+ message: Message;
+}>();
+</script>
diff --git a/frontend/src/plugins/ai/components/ChatView/index.ts b/frontend/src/plugins/ai/components/ChatView/index.ts
new file mode 100644
index 0000000000..dd4fe6f11e
--- /dev/null
+++ b/frontend/src/plugins/ai/components/ChatView/index.ts
@@ -0,0 +1,3 @@
+import ChatView from "./ChatView.vue";
+
+export default ChatView;
diff --git a/frontend/src/plugins/ai/components/ConversationList.vue b/frontend/src/plugins/ai/components/ConversationList.vue
new file mode 100644
index 0000000000..82b75bf313
--- /dev/null
+++ b/frontend/src/plugins/ai/components/ConversationList.vue
@@ -0,0 +1,127 @@
+<template>
+ <div class="h-full overflow-hidden flex flex-col">
+ <div class="py-2 px-2">
+ <h3 class="font-bold">
+ {{ $t("plugin.ai.conversation.conversations") }}
+ </h3>
+ </div>
+ <div class="flex-1 overflow-y-auto p-1 flex flex-col gap-y-2">
+ <template v-if="ready">
+ <div
+ v-for="conversation in conversationList"
+ :key="conversation.id"
+ :data-conversation-id="conversation.id"
+ class="flex items-start gap-x-0.5 border rounded-md py-2 pl-2 pr-0.5 hover:bg-indigo-50 hover:border-indigo-400 cursor-pointer"
+ :class="[
+ selectedConversation?.id === conversation.id &&
+ 'bg-indigo-100 border-indigo-400',
+ ]"
+ @click="store.selectConversation(conversation)"
+ >
+ <div
+ v-if="conversation.name"
+ class="text-sm flex-1 whitespace-pre-wrap break-words break-all"
+ >
+ {{ conversation.name }}
+ </div>
+ <div v-else class="text-sm flex-1 truncate text-gray-500 italic">
+ {{
+ head(conversation.messageList)?.content ||
+ $t("plugin.ai.conversation.untitled")
+ }}
+ </div>
+ <div class="flex items-center gap-x-px">
+ <button
+ class="flex items-center p-0.5 border border-transparent rounded text-gray-500 hover:text-accent hover:bg-indigo-50 hover:border-accent cursor-pointer"
+ @click.stop="state.rename = conversation"
+ >
+ <heroicons-outline:pencil class="w-3 h-3" />
+ </button>
+ <NPopconfirm
+ @positive-click="handleDeleteConversation(conversation)"
+ >
+ <template #trigger>
+ <button
+ class="flex items-center p-0.5 border border-transparent rounded text-gray-500 hover:text-accent hover:bg-indigo-50 hover:border-accent cursor-pointer"
+ @click.stop=""
+ >
+ <heroicons-outline:trash class="w-3 h-3" />
+ </button>
+ </template>
+ <span>{{ $t("plugin.ai.conversation.delete") }}</span>
+ </NPopconfirm>
+ </div>
+ </div>
+
+ <div
+ class="sticky bottom-0 btn-normal items-center justify-center gap-x-1"
+ @click="addConversation"
+ >
+ <heroicons-outline:plus class="w-4 h-4" />
+ <span class="pr-3">{{ $t("common.new") }}</span>
+ </div>
+ </template>
+ <template v-else>
+ <BBSpin class="self-center mt-8" />
+ </template>
+ </div>
+
+ <ConversationRenameDialog
+ v-if="state.rename"
+ :conversation="state.rename"
+ @cancel="state.rename = undefined"
+ @updated="state.rename = undefined"
+ />
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { reactive, toRef, watch } from "vue";
+import { NPopconfirm } from "naive-ui";
+import scrollIntoView from "scroll-into-view-if-needed";
+import { head } from "lodash-es";
+
+import ConversationRenameDialog from "./ConversationRenameDialog.vue";
+import type { Conversation } from "../types";
+import { useConversationList, useConversationStore } from "../store";
+
+type LocalState = {
+ rename: Conversation | undefined;
+};
+
+const state = reactive<LocalState>({
+ rename: undefined,
+});
+const store = useConversationStore();
+const { conversationList, ready } = useConversationList();
+const selectedConversation = toRef(store, "selectedConversation");
+
+const addConversation = async () => {
+ const c = await store.createConversation({
+ name: "", // Will display as "Untitled conversation"
+ });
+ store.selectConversation(c);
+};
+
+const handleDeleteConversation = async (conversation: Conversation) => {
+ const index = conversationList.value.findIndex(
+ (c) => c.id === selectedConversation.value?.id
+ );
+ await store.deleteConversation(conversation.id);
+ store.selectConversation(conversationList.value[index]);
+};
+
+watch(
+ [() => selectedConversation.value?.id, conversationList],
+ ([id, list]) => {
+ if (!id) return;
+ if (list.length === 0) return;
+ requestAnimationFrame(() => {
+ const elem = document.querySelector(`[data-conversation-id="${id}"]`);
+ if (!elem) return;
+ scrollIntoView(elem, { scrollMode: "if-needed" });
+ });
+ },
+ { immediate: true }
+);
+</script>
diff --git a/frontend/src/plugins/ai/components/ConversationRenameDialog.vue b/frontend/src/plugins/ai/components/ConversationRenameDialog.vue
new file mode 100644
index 0000000000..89c7fb39eb
--- /dev/null
+++ b/frontend/src/plugins/ai/components/ConversationRenameDialog.vue
@@ -0,0 +1,78 @@
+<template>
+ <BBModal
+ :title="$t('plugin.ai.conversation.rename')"
+ @close="$emit('cancel')"
+ >
+ <div class="w-[18rem] flex flex-col items-start gap-y-2">
+ <div class="textlabel">{{ $t("common.name") }}</div>
+ <div class="w-full">
+ <NInput
+ v-model:value="state.name"
+ class="w-full"
+ @keypress.enter="handleRename"
+ />
+ </div>
+ <div
+ class="w-full flex items-center justify-end gap-x-2 mt-4 pt-2 border-t"
+ >
+ <NButton @click="$emit('cancel')">
+ {{ $t("common.cancel") }}
+ </NButton>
+ <NButton type="primary" @click="handleRename">
+ {{ $t("common.update") }}
+ </NButton>
+ </div>
+ <div
+ v-if="state.loading"
+ class="absolute inset-0 bg-white/50 flex flex-col items-center justify-center rounded-lg"
+ >
+ <BBSpin />
+ </div>
+ </div>
+ </BBModal>
+</template>
+
+<script lang="ts" setup>
+import { reactive } from "vue";
+import { useI18n } from "vue-i18n";
+import { NButton, NInput } from "naive-ui";
+import { head } from "lodash-es";
+
+import type { Conversation } from "../types";
+import { BBModal } from "@/bbkit";
+import { useConversationStore } from "../store";
+
+type LocalState = {
+ name: string;
+ loading: boolean;
+};
+
+const props = defineProps<{
+ conversation: Conversation;
+}>();
+
+const emit = defineEmits<{
+ (event: "cancel"): void;
+ (event: "updated"): void;
+}>();
+
+const { t } = useI18n();
+
+const state = reactive<LocalState>({
+ name:
+ props.conversation.name ||
+ head(props.conversation.messageList)?.content ||
+ t("plugin.ai.conversation.untitled"),
+ loading: false,
+});
+const store = useConversationStore();
+
+const handleRename = async () => {
+ const { conversation } = props;
+ const { name } = state;
+ conversation.name = name;
+ state.loading = true;
+ await store.updateConversation(conversation);
+ emit("updated");
+};
+</script>
diff --git a/frontend/src/plugins/ai/components/PromptInput.vue b/frontend/src/plugins/ai/components/PromptInput.vue
new file mode 100644
index 0000000000..a95b261253
--- /dev/null
+++ b/frontend/src/plugins/ai/components/PromptInput.vue
@@ -0,0 +1,76 @@
+<template>
+ <NInput
+ v-model:value="state.value"
+ :disabled="disabled"
+ :placeholder="$t('plugin.ai.text-to-sql-placeholder')"
+ class="bb-ai-prompt-input"
+ @keypress.enter="handlePressEnter"
+ >
+ <template #prefix>
+ <heroicons-outline:sparkles class="w-4 h-4 text-accent" />
+ </template>
+ <template #suffix>
+ <NButton
+ :quaternary="true"
+ :disabled="!state.value"
+ type="primary"
+ size="small"
+ @click="handlePressEnter"
+ >
+ ⏎
+ </NButton>
+ </template>
+ </NInput>
+</template>
+
+<script lang="ts" setup>
+import { onMounted, reactive } from "vue";
+import { NInput } from "naive-ui";
+
+type LocalState = {
+ value: string;
+};
+
+withDefaults(
+ defineProps<{
+ disabled?: boolean;
+ }>(),
+ {
+ disabled: false,
+ }
+);
+
+const emit = defineEmits<{
+ (event: "enter", value: string): void;
+}>();
+
+const state = reactive<LocalState>({
+ value: "",
+});
+
+const applyValue = (value: string) => {
+ state.value = "";
+ emit("enter", value);
+};
+
+const handlePressEnter = () => {
+ applyValue(state.value);
+};
+
+onMounted(() => {
+ requestAnimationFrame(() => {
+ const input = document.querySelector(
+ ".bb-ai-prompt-input input[type=text]"
+ ) as HTMLInputElement;
+ if (input) {
+ input.focus();
+ }
+ });
+});
+</script>
+
+<style lang="postcss">
+.bb-ai-prompt-input .n-input__input-el {
+ @apply !ring-0;
+}
+</style>
diff --git a/frontend/src/plugins/ai/index.ts b/frontend/src/plugins/ai/index.ts
new file mode 100644
index 0000000000..dfae7e918a
--- /dev/null
+++ b/frontend/src/plugins/ai/index.ts
@@ -0,0 +1,5 @@
+import AIDialog from "./components/AIDialog.vue";
+import AIPromptButton from "./components/AIPromptButton.vue";
+
+export * from "./types";
+export { AIDialog, AIPromptButton };
diff --git a/frontend/src/plugins/ai/logic/context.ts b/frontend/src/plugins/ai/logic/context.ts
new file mode 100644
index 0000000000..629d1ed1e3
--- /dev/null
+++ b/frontend/src/plugins/ai/logic/context.ts
@@ -0,0 +1,12 @@
+import { inject, provide, type InjectionKey } from "vue";
+import { AIContext } from "../types";
+
+export const KEY = Symbol("bb.plugin.ai") as InjectionKey<AIContext>;
+
+export const useAIContext = () => {
+ return inject(KEY)!;
+};
+
+export const provideAIContext = (context: AIContext) => {
+ provide(KEY, context);
+};
diff --git a/frontend/src/plugins/ai/logic/index.ts b/frontend/src/plugins/ai/logic/index.ts
new file mode 100644
index 0000000000..2edd280c79
--- /dev/null
+++ b/frontend/src/plugins/ai/logic/index.ts
@@ -0,0 +1 @@
+export * from "./context";
diff --git a/frontend/src/plugins/ai/store/conversation.ts b/frontend/src/plugins/ai/store/conversation.ts
new file mode 100644
index 0000000000..0177d127d9
--- /dev/null
+++ b/frontend/src/plugins/ai/store/conversation.ts
@@ -0,0 +1,292 @@
+import { computed, onMounted, reactive, ref, toRef, watchEffect } from "vue";
+import { groupBy, last, omit } from "lodash-es";
+import { defineStore } from "pinia";
+import PouchDB from "pouchdb";
+import PouchDBFind from "pouchdb-find";
+import { v1 as uuidv1 } from "uuid";
+
+import { Conversation, Message } from "../types";
+
+type RowStatus = "NORMAL" | "ARCHIVED";
+
+type Entity<T, O extends keyof T, E = unknown> = Omit<T, "id" | O> & {
+ _id: string;
+ _rev?: string;
+ row_status: RowStatus;
+} & E;
+
+type ConversationEntity = Entity<Conversation, "messageList">;
+type MessageEntity = Entity<
+ Message,
+ "conversation",
+ {
+ conversation_id: string;
+ }
+>;
+
+type EntityCreate<T> = Omit<T, "_id" | "created_ts" | "row_status">;
+
+PouchDB.plugin(PouchDBFind);
+
+const convertConversationToEntity = (conversation: Conversation) => {
+ const c: ConversationEntity = {
+ ...omit(conversation, "id", "messageList"),
+ _id: conversation.id,
+ row_status: "NORMAL",
+ };
+ return c;
+};
+
+const convertMessageToEntity = (message: Message) => {
+ const m: MessageEntity = {
+ ...omit(message, "id", "conversation"),
+ _id: message.id,
+ row_status: "NORMAL",
+ conversation_id: message.conversation.id,
+ };
+ return m;
+};
+
+const useLocalCache = () => {
+ const conversationById = reactive(new Map<string, Conversation>());
+ const messageById = reactive(new Map<string, Message>());
+
+ const convertConversation = (
+ c: ConversationEntity,
+ messageList: Message[] = []
+ ): Conversation => {
+ const existed = conversationById.get(c._id);
+ if (existed) {
+ Object.assign(existed, {
+ ...c,
+ messageList,
+ });
+ return existed;
+ }
+ const conversation = reactive({
+ ...c,
+ id: c._id,
+ messageList,
+ });
+ conversationById.set(conversation.id, conversation);
+ return conversation;
+ };
+
+ const convertMessage = (
+ m: MessageEntity,
+ conversation: Conversation
+ ): Message => {
+ const existed = messageById.get(m._id);
+ if (existed) {
+ Object.assign(existed, {
+ ...m,
+ conversation,
+ });
+ }
+ const message = reactive({
+ ...m,
+ id: m._id,
+ conversation,
+ });
+ messageById.set(message.id, message);
+ return message;
+ };
+
+ const getConversationById = (id: string) => {
+ return conversationById.get(id)!;
+ };
+ const getMessageById = (id: string) => {
+ return messageById.get(id)!;
+ };
+
+ return {
+ conversationById,
+ convertConversation,
+ convertMessage,
+ getConversationById,
+ getMessageById,
+ };
+};
+
+export const useConversationStore = defineStore("ai-conversation", () => {
+ const conversations = new PouchDB<ConversationEntity>(
+ "bb.plugin.ai.conversations"
+ );
+ const messages = new PouchDB<MessageEntity>("bb.plugin.ai.messages");
+ messages.createIndex({
+ index: { name: "idx_conversation_id", fields: ["conversation_id"] },
+ });
+
+ const {
+ conversationById,
+ convertConversation,
+ convertMessage,
+ getConversationById,
+ } = useLocalCache();
+
+ const selectedConversationId = ref<string>();
+ const conversationList = computed(() => {
+ return [...conversationById.values()];
+ });
+ const selectedConversation = computed(() => {
+ const id = selectedConversationId.value;
+ if (!id) return undefined;
+ return getConversationById(id);
+ });
+
+ const fetchConversationList = async () => {
+ const conversationEntityList = (
+ await conversations.find({
+ selector: { row_status: { $eq: "NORMAL" } },
+ })
+ ).docs;
+ const flattenMessageMessageList = (
+ await messages.find({
+ selector: {
+ row_status: { $eq: "NORMAL" },
+ conversation_id: {
+ $in: conversationEntityList.map((c) => c._id),
+ },
+ },
+ })
+ ).docs;
+
+ const groupByConversationId = groupBy(
+ flattenMessageMessageList,
+ (m) => m.conversation_id
+ );
+ conversationEntityList.sort((a, b) => a.created_ts - b.created_ts);
+ const conversationList = conversationEntityList.map<Conversation>((c) => {
+ const conversation = convertConversation(c);
+ const messageEntityList = groupByConversationId[c._id] ?? [];
+ conversation.messageList = messageEntityList.map((m) =>
+ convertMessage(m, conversation)
+ );
+ conversation.messageList.sort((a, b) => a.created_ts - b.created_ts);
+ return conversation;
+ });
+ if (conversationList.length === 0) {
+ const initialConversation = await createConversation({
+ name: "",
+ });
+ conversationList.push(initialConversation);
+ }
+ await fixAbnormalMessages(conversationList.flatMap((c) => c.messageList));
+ return conversationList;
+ };
+
+ const createConversation = async (
+ conversationCreate: EntityCreate<ConversationEntity>
+ ): Promise<Conversation> => {
+ const c: ConversationEntity = {
+ _id: uuidv1(),
+ created_ts: Date.now(),
+ row_status: "NORMAL",
+ ...conversationCreate,
+ };
+ const response = await conversations.put(c);
+ c._rev = response.rev;
+ return convertConversation(c);
+ };
+
+ const updateConversation = async (conversation: Conversation) => {
+ const c = convertConversationToEntity(conversation);
+ await conversations.put(c, { force: true });
+ return convertConversation(c, conversation.messageList);
+ };
+
+ const deleteConversation = async (id: string) => {
+ const conversation = getConversationById(id);
+ if (conversation.messageList.length > 0) {
+ await messages.bulkDocs(
+ conversation.messageList.map((message) => ({
+ ...convertMessageToEntity(message),
+ row_status: "ARCHIVED",
+ }))
+ );
+ }
+ await conversations.put(
+ {
+ ...convertConversationToEntity(conversation),
+ row_status: "ARCHIVED",
+ },
+ {
+ force: true,
+ }
+ );
+ conversationById.delete(conversation.id);
+ };
+
+ const createMessage = async (messageCreate: EntityCreate<MessageEntity>) => {
+ const m: MessageEntity = {
+ _id: uuidv1(),
+ created_ts: Date.now(),
+ row_status: "NORMAL",
+ ...messageCreate,
+ };
+ const response = await messages.put(m);
+ m._rev = response.rev;
+ const conversation = getConversationById(m.conversation_id);
+ const message = convertMessage(m, conversation);
+ conversation.messageList.push(message);
+ return message;
+ };
+
+ const updateMessage = async (message: Message) => {
+ const m = convertMessageToEntity(message);
+ await messages.put(m, {
+ force: true,
+ });
+ return convertMessage(m, message.conversation);
+ };
+
+ const selectConversation = (c: Conversation | undefined) => {
+ selectedConversationId.value = c?.id;
+ };
+
+ const fixAbnormalMessages = async (messageList: Message[]) => {
+ const requests = messageList
+ .filter((message) => message.status === "LOADING")
+ .map((message) => {
+ message.status = "FAILED";
+ message.error = "Request timeout";
+ return updateMessage(message);
+ });
+ await Promise.all(requests);
+ };
+
+ const reset = () => {
+ console.log("reset conversation storage");
+ return Promise.all([conversations.destroy(), messages.destroy()]);
+ };
+
+ watchEffect(() => {
+ if (!selectedConversationId.value) {
+ selectConversation(last(conversationList.value));
+ }
+ });
+
+ return {
+ conversationById,
+ conversationList,
+ selectedConversation,
+ fetchConversationList,
+ createConversation,
+ updateConversation,
+ deleteConversation,
+ createMessage,
+ updateMessage,
+ selectConversation,
+ reset,
+ };
+});
+
+export const useConversationList = () => {
+ const store = useConversationStore();
+ const ready = ref(false);
+ onMounted(async () => {
+ await store.fetchConversationList();
+ ready.value = true;
+ });
+ return { conversationList: toRef(store, "conversationList"), ready };
+};
diff --git a/frontend/src/plugins/ai/store/index.ts b/frontend/src/plugins/ai/store/index.ts
new file mode 100644
index 0000000000..a4409abfcf
--- /dev/null
+++ b/frontend/src/plugins/ai/store/index.ts
@@ -0,0 +1,5 @@
+import { createPinia } from "pinia";
+
+export const pinia = createPinia();
+
+export * from "./conversation";
diff --git a/frontend/src/plugins/ai/types/context.ts b/frontend/src/plugins/ai/types/context.ts
new file mode 100644
index 0000000000..f9eb7b9964
--- /dev/null
+++ b/frontend/src/plugins/ai/types/context.ts
@@ -0,0 +1,20 @@
+import type { Ref } from "vue";
+import type Emittery from "emittery";
+import type { EngineType } from "@/types";
+import type { DatabaseMetadata } from "@/types/proto/store/database";
+
+export type AIContextEvents = Emittery<{
+ "apply-statement": { statement: string; run: boolean };
+ error: string;
+}>;
+
+export type AIContext = {
+ showDialog: Ref<boolean>;
+ openAIKey: Ref<string>;
+ engineType: Ref<EngineType | undefined>;
+ databaseMetadata: Ref<DatabaseMetadata | undefined>;
+ autoRun: Ref<boolean>;
+
+ // Events
+ events: AIContextEvents;
+};
diff --git a/frontend/src/plugins/ai/types/conversation.ts b/frontend/src/plugins/ai/types/conversation.ts
new file mode 100644
index 0000000000..f5dea75985
--- /dev/null
+++ b/frontend/src/plugins/ai/types/conversation.ts
@@ -0,0 +1,21 @@
+export type MessageAuthor = "USER" | "AI";
+
+export type MessageStatus = "LOADING" | "DONE" | "FAILED";
+
+export type Message = {
+ id: string; // uuid
+ created_ts: number; // ms
+ author: MessageAuthor;
+ content: string; // Content to display
+ prompt: string; // Prompt to send to AI
+ status: MessageStatus; // Always "DONE" when `author`="USER"
+ error: string;
+ conversation: Conversation;
+};
+
+export type Conversation = {
+ id: string; // uuid
+ created_ts: number; // ms
+ name: string;
+ messageList: Message[];
+};
diff --git a/frontend/src/plugins/ai/types/index.ts b/frontend/src/plugins/ai/types/index.ts
new file mode 100644
index 0000000000..c0b5159840
--- /dev/null
+++ b/frontend/src/plugins/ai/types/index.ts
@@ -0,0 +1,3 @@
+export * from "./context";
+export * from "./conversation";
+export * from "./openai";
diff --git a/frontend/src/plugins/ai/types/openai.ts b/frontend/src/plugins/ai/types/openai.ts
new file mode 100644
index 0000000000..bd7eefa34a
--- /dev/null
+++ b/frontend/src/plugins/ai/types/openai.ts
@@ -0,0 +1,35 @@
+export type OpenAIMessage = {
+ role: "system" | "user" | "assistant";
+ content: string;
+};
+
+export type OpenAIChoice = {
+ // text: string;
+ index: number;
+ logprobs: unknown;
+ finish_reason: "stop" | "length" | null;
+ message: OpenAIMessage;
+};
+
+export type OpenAIUsage = {
+ prompt_tokens: number;
+ completion_tokens: number;
+ total_tokens: number;
+};
+
+export type OpenAIError = {
+ message: string;
+ type: string;
+ param: unknown;
+ code: unknown;
+};
+
+export type OpenAIResponse = {
+ id: string;
+ object: "text_completion";
+ created: number;
+ model: "code-davinci-002";
+ choices: OpenAIChoice[];
+ usage: OpenAIUsage;
+ error: OpenAIError | undefined;
+};
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index f1bbf25a8b..4e444655bf 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -52,6 +52,7 @@ import {
useIdentityProviderStore,
useCurrentUser,
} from "@/store";
+import { useConversationStore } from "@/plugins/ai/store";
const HOME_MODULE = "workspace.home";
const AUTH_MODULE = "auth";
@@ -1018,6 +1019,7 @@ router.beforeEach((to, from, next) => {
to.name === PASSWORD_FORGOT_MODULE
) {
useTabStore().reset();
+ useConversationStore().reset();
if (isLoggedIn) {
if (typeof to.query.redirect === "string") {
location.replace(to.query.redirect);
diff --git a/frontend/src/store/modules/dbSchema.ts b/frontend/src/store/modules/dbSchema.ts
index 99f71d3800..9f076c0454 100644
--- a/frontend/src/store/modules/dbSchema.ts
+++ b/frontend/src/store/modules/dbSchema.ts
@@ -1,6 +1,7 @@
+import { computed, unref, watchEffect } from "vue";
import axios from "axios";
import { defineStore } from "pinia";
-import { DatabaseId, DBSchemaState } from "@/types";
+import { DatabaseId, DBSchemaState, MaybeRef, UNKNOWN_ID } from "@/types";
import {
DatabaseMetadata,
ExtensionMetadata,
@@ -144,3 +145,17 @@ export const useDBSchemaStore = defineStore("dbSchema", {
},
},
});
+
+export const useMetadataByDatabaseId = (
+ databaseId: MaybeRef<DatabaseId>,
+ skipCache: MaybeRef<boolean>
+) => {
+ const store = useDBSchemaStore();
+ watchEffect(() => {
+ const id = unref(databaseId);
+ if (id !== UNKNOWN_ID) {
+ store.getOrFetchDatabaseMetadataById(id, unref(skipCache));
+ }
+ });
+ return computed(() => store.databaseMetadataById.get(unref(databaseId)));
+};
diff --git a/frontend/src/types/setting.ts b/frontend/src/types/setting.ts
index 9d6b15eea8..6b83eb9a35 100644
--- a/frontend/src/types/setting.ts
+++ b/frontend/src/types/setting.ts
@@ -4,7 +4,8 @@ export type SettingName =
| "bb.branding.logo"
| "bb.app.im"
| "bb.workspace.watermark"
- | "bb.workspace.profile";
+ | "bb.workspace.profile"
+ | "bb.plugin.openai-key";
export type Setting = {
id: SettingId;
diff --git a/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue b/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue
index c9aa51af7b..138caee5ed 100644
--- a/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue
@@ -78,6 +78,20 @@
</NPopover>
</template>
</div>
+
+ <div
+ v-if="
+ tabStore.currentTab.mode === TabMode.ReadOnly &&
+ !tabStore.isDisconnected
+ "
+ class="w-full -mb-1"
+ >
+ <AIPromptButton
+ :engine-type="instance.engine"
+ :database-metadata="databaseMetadata"
+ @apply-statement="handleApplySQL"
+ />
+ </div>
</div>
</template>
@@ -89,9 +103,11 @@ import {
useSQLEditorStore,
useInstanceById,
useWebTerminalStore,
+ useMetadataByDatabaseId,
} from "@/store";
import type { ExecuteConfig, ExecuteOption } from "@/types";
import { TabMode, UNKNOWN_ID } from "@/types";
+import { AIPromptButton } from "@/plugins/ai";
import SharePopover from "./SharePopover.vue";
import AdminModeButton from "./AdminModeButton.vue";
@@ -190,4 +206,17 @@ const handleFormatSQL = () => {
const handleClearScreen = () => {
emit("clear-screen");
};
+
+const databaseId = computed(() => tabStore.currentTab.connection.databaseId);
+const databaseMetadata = useMetadataByDatabaseId(databaseId, false);
+const instance = useInstanceById(
+ computed(() => tabStore.currentTab.connection.instanceId)
+);
+
+const handleApplySQL = (sql: string, run: boolean) => {
+ tabStore.currentTab.statement = sql;
+ if (run) {
+ emit("execute", sql, { databaseType: selectedInstanceEngine.value });
+ }
+};
</script>