@gnar-engine/cli 1.0.3 → 1.0.5

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.
Files changed (259) hide show
  1. package/bootstrap/deploy.localdev.yml +44 -30
  2. package/bootstrap/secrets.localdev.yml +20 -14
  3. package/bootstrap/services/control/src/config.js +4 -0
  4. package/bootstrap/services/{agent → page}/Dockerfile +3 -3
  5. package/bootstrap/services/page/package.json +16 -0
  6. package/bootstrap/services/page/src/app.js +50 -0
  7. package/bootstrap/services/page/src/commands/block.handler.js +94 -0
  8. package/bootstrap/services/page/src/commands/page.handler.js +167 -0
  9. package/bootstrap/services/page/src/config.js +62 -0
  10. package/bootstrap/services/page/src/controllers/block.http.controller.js +87 -0
  11. package/bootstrap/services/page/src/controllers/message.controller.js +51 -0
  12. package/bootstrap/services/page/src/controllers/page.http.controller.js +89 -0
  13. package/bootstrap/services/page/src/policies/block.policy.js +50 -0
  14. package/bootstrap/services/page/src/policies/page.policy.js +49 -0
  15. package/bootstrap/services/page/src/schema/page.schema.js +139 -0
  16. package/bootstrap/services/page/src/services/block.service.js +83 -0
  17. package/bootstrap/services/page/src/services/page.service.js +83 -0
  18. package/bootstrap/services/portal/Dockerfile +7 -10
  19. package/bootstrap/services/portal/README.md +66 -15
  20. package/bootstrap/services/portal/index.html +13 -0
  21. package/bootstrap/services/portal/nginx.conf +5 -12
  22. package/bootstrap/services/portal/package.json +27 -53
  23. package/bootstrap/services/portal/public/vite.svg +1 -0
  24. package/bootstrap/services/portal/react-router.config.js +7 -0
  25. package/bootstrap/services/portal/src/App.jsx +16 -0
  26. package/bootstrap/services/portal/src/assets/gnar-engine-white-logo.svg +9 -0
  27. package/bootstrap/services/portal/src/assets/icon-agent.svg +6 -0
  28. package/bootstrap/services/portal/src/assets/icon-cog.svg +4 -0
  29. package/bootstrap/services/portal/src/assets/icon-delete.svg +3 -0
  30. package/bootstrap/services/portal/src/assets/icon-home.svg +3 -0
  31. package/bootstrap/services/portal/src/assets/icon-padlock.svg +3 -0
  32. package/bootstrap/services/portal/src/assets/icon-page.svg +6 -0
  33. package/bootstrap/services/portal/src/assets/icon-reports.svg +3 -0
  34. package/bootstrap/services/portal/src/assets/icon-user.svg +3 -0
  35. package/bootstrap/services/portal/src/assets/icon-users.svg +3 -0
  36. package/bootstrap/services/portal/src/assets/login-green-rad-back-1.jpg +0 -0
  37. package/bootstrap/services/portal/src/assets/react.svg +1 -0
  38. package/bootstrap/services/portal/src/components/CrudList/CrudList.jsx +85 -0
  39. package/bootstrap/services/portal/src/components/CrudList/CrudList.less +59 -0
  40. package/bootstrap/services/portal/src/{ui/customSelect → components/CustomSelect}/CustomSelect.jsx +21 -3
  41. package/bootstrap/services/portal/src/components/LoginForm/LoginForm.jsx +58 -0
  42. package/bootstrap/services/portal/src/components/PageBlockSwitch/PageBlockSwitch.jsx +129 -0
  43. package/bootstrap/services/portal/src/components/Sidebar/Sidebar.jsx +33 -0
  44. package/bootstrap/services/portal/src/components/Sidebar/Sidebar.less +37 -0
  45. package/bootstrap/services/portal/src/components/Topbar/Topbar.jsx +19 -0
  46. package/bootstrap/services/portal/src/components/Topbar/Topbar.less +22 -0
  47. package/bootstrap/services/portal/src/components/UserInfo/UserInfo.jsx +33 -0
  48. package/bootstrap/services/portal/src/components/UserInfo/UserInfo.less +21 -0
  49. package/bootstrap/services/portal/src/css/style.css +446 -742
  50. package/bootstrap/services/portal/src/data/pages.data.js +10 -0
  51. package/bootstrap/services/portal/src/elements/CustomSelect/CustomSelect.jsx +65 -0
  52. package/bootstrap/services/portal/src/{ui/customSelect/customSelect.less → elements/CustomSelect/CustomSelect.less} +17 -7
  53. package/bootstrap/services/portal/src/elements/ImageInput/ImageInput.jsx +115 -0
  54. package/bootstrap/services/portal/src/elements/ImageInput/ImageInput.less +43 -0
  55. package/bootstrap/services/portal/src/elements/ImageMultiInput/ImageMultiInput.jsx +124 -0
  56. package/bootstrap/services/portal/src/elements/ImageMultiInput/ImageMultiInput.less +0 -0
  57. package/bootstrap/services/portal/src/elements/Repeater/Repeater.jsx +52 -0
  58. package/bootstrap/services/portal/src/elements/Repeater/Repeater.less +70 -0
  59. package/bootstrap/services/portal/src/elements/RichTextInput/RichTextInput.jsx +18 -0
  60. package/bootstrap/services/portal/src/elements/RichTextInput/RichTextInput.less +37 -0
  61. package/bootstrap/services/portal/src/elements/SaveButton/SaveButton.jsx +45 -0
  62. package/bootstrap/services/portal/src/elements/SelectRepeater/SelectRepeater.jsx +63 -0
  63. package/bootstrap/services/portal/src/elements/SelectRepeater/SelectRepeater.less +23 -0
  64. package/bootstrap/services/portal/src/elements/TextInput/TextInput.jsx +17 -0
  65. package/bootstrap/services/portal/src/layouts/Card/Card.jsx +15 -0
  66. package/bootstrap/services/portal/src/layouts/PortalLayout/PortalLayout.jsx +29 -0
  67. package/bootstrap/services/portal/src/layouts/PortalLayout/PortalLayout.less +49 -0
  68. package/bootstrap/services/portal/src/main.jsx +51 -0
  69. package/bootstrap/services/portal/src/pages/BlockSinglePage/BlockSinglePage.jsx +277 -0
  70. package/bootstrap/services/portal/src/pages/BlocksPage/BlocksPage.jsx +23 -0
  71. package/bootstrap/services/portal/src/pages/DashboardPage/DashboardPage.jsx +11 -0
  72. package/bootstrap/services/portal/src/pages/DashboardPage/DashboardPage.less +0 -0
  73. package/bootstrap/services/portal/src/pages/LoginPage/LoginPage.jsx +21 -0
  74. package/bootstrap/services/portal/src/pages/LoginPage/LoginPage.less +51 -0
  75. package/bootstrap/services/portal/src/pages/PageSinglePage/PageSinglePage.jsx +338 -0
  76. package/bootstrap/services/portal/src/pages/PagesPage/PagesPage.jsx +23 -0
  77. package/bootstrap/services/portal/src/pages/UserSinglePage/UserSinglePage.jsx +9 -0
  78. package/bootstrap/services/portal/src/pages/UserSinglePage/UserSinglePage.less +0 -0
  79. package/bootstrap/services/portal/src/pages/UsersPage/UsersPage.jsx +25 -0
  80. package/bootstrap/services/portal/src/pages/UsersPage/UsersPage.less +0 -0
  81. package/bootstrap/services/portal/src/services/block.js +28 -0
  82. package/bootstrap/services/portal/src/services/client.js +67 -0
  83. package/bootstrap/services/portal/src/services/gravatar.js +14 -0
  84. package/bootstrap/services/portal/src/services/page.js +28 -0
  85. package/bootstrap/services/portal/src/services/storage.js +62 -0
  86. package/bootstrap/services/portal/src/services/user.js +41 -0
  87. package/bootstrap/services/portal/src/slices/authSlice.js +44 -14
  88. package/bootstrap/services/portal/src/store/configureStore.js +1 -3
  89. package/bootstrap/services/portal/src/style/cards.less +57 -0
  90. package/bootstrap/services/portal/src/{styles → style}/global.less +90 -45
  91. package/bootstrap/services/portal/src/style/icons.less +21 -0
  92. package/bootstrap/services/portal/src/style/inputs.less +52 -0
  93. package/bootstrap/services/portal/src/style/main.less +28 -0
  94. package/bootstrap/services/portal/src/utils/utils.js +9 -0
  95. package/bootstrap/services/portal/vite.config.js +12 -0
  96. package/bootstrap/services/user/Dockerfile +1 -1
  97. package/bootstrap/services/user/src/app.js +6 -1
  98. package/bootstrap/services/user/src/commands/user.handler.js +0 -3
  99. package/bootstrap/services/user/src/config.js +5 -1
  100. package/bootstrap/services/user/src/policies/user.policy.js +3 -1
  101. package/bootstrap/services/user/src/tests/commands/user.test.js +22 -0
  102. package/install-from-clone.sh +30 -0
  103. package/package.json +1 -1
  104. package/src/cli.js +8 -0
  105. package/src/config.js +2 -1
  106. package/src/dev/commands.js +10 -2
  107. package/src/dev/dev.service.js +167 -52
  108. package/src/provisioner/Dockerfile +27 -0
  109. package/src/provisioner/package.json +19 -0
  110. package/src/provisioner/src/app.js +56 -0
  111. package/src/provisioner/src/services/mongodb.js +58 -0
  112. package/src/provisioner/src/services/mysql.js +51 -0
  113. package/src/provisioner/src/services/secrets.js +84 -0
  114. package/src/scaffolder/commands.js +12 -5
  115. package/src/scaffolder/scaffolder.handler.js +256 -58
  116. package/templates/service/Dockerfile.hbs +4 -1
  117. package/templates/service/package.json.hbs +14 -16
  118. package/templates/service/src/app.js.hbs +53 -0
  119. package/templates/service/{commands → src/commands}/{{serviceName}}.handler.js.hbs +2 -3
  120. package/templates/service/src/mongodb.config.js.hbs +49 -0
  121. package/templates/service/{config.js.hbs → src/mysql.config.js.hbs} +10 -0
  122. package/{bootstrap/services/agent/src/schema/Agent.schema.js → templates/service/src/schema/{{serviceName}}.schema.js.hbs} +3 -3
  123. package/templates/service/src/services/mongodb.{{serviceName}}.service.js.hbs +70 -0
  124. package/bootstrap/services/agent/notes.md +0 -28
  125. package/bootstrap/services/agent/package.json +0 -16
  126. package/bootstrap/services/agent/src/app.js +0 -52
  127. package/bootstrap/services/agent/src/commands/agent.handler.js +0 -104
  128. package/bootstrap/services/agent/src/config.js +0 -52
  129. package/bootstrap/services/agent/src/controllers/http.controller.js +0 -44
  130. package/bootstrap/services/agent/src/controllers/message.controller.js +0 -51
  131. package/bootstrap/services/agent/src/db/migrations/01-init.js +0 -50
  132. package/bootstrap/services/agent/src/db/migrations/02-agent-service-init.js +0 -36
  133. package/bootstrap/services/agent/src/policies/agent.policy.js +0 -13
  134. package/bootstrap/services/agent/src/services/agent.service.js +0 -259
  135. package/bootstrap/services/agent/src/services/chatgpt.service.js +0 -46
  136. package/bootstrap/services/agent/src/services/manifest.service.js +0 -21
  137. package/bootstrap/services/portal/Dockerfile.remote +0 -40
  138. package/bootstrap/services/portal/public/favicon.ico +0 -0
  139. package/bootstrap/services/portal/public/gnar-white.png +0 -0
  140. package/bootstrap/services/portal/public/gnarengine-logo-black.png +0 -0
  141. package/bootstrap/services/portal/public/index.html +0 -43
  142. package/bootstrap/services/portal/public/logo192.png +0 -0
  143. package/bootstrap/services/portal/public/logo512.png +0 -0
  144. package/bootstrap/services/portal/public/manifest.json +0 -25
  145. package/bootstrap/services/portal/public/robots.txt +0 -3
  146. package/bootstrap/services/portal/src/App.js +0 -56
  147. package/bootstrap/services/portal/src/assets/Logo_Anchord_Black.svg +0 -1
  148. package/bootstrap/services/portal/src/assets/Logo_Anchord_Black_Green.svg +0 -1
  149. package/bootstrap/services/portal/src/assets/Logo_Anchord_White_Green.svg +0 -1
  150. package/bootstrap/services/portal/src/assets/activity.svg +0 -3
  151. package/bootstrap/services/portal/src/assets/arrow.svg +0 -3
  152. package/bootstrap/services/portal/src/assets/bin-white.svg +0 -3
  153. package/bootstrap/services/portal/src/assets/bin.svg +0 -3
  154. package/bootstrap/services/portal/src/assets/check.svg +0 -3
  155. package/bootstrap/services/portal/src/assets/chevron.svg +0 -3
  156. package/bootstrap/services/portal/src/assets/contact.svg +0 -3
  157. package/bootstrap/services/portal/src/assets/dots-vertical.svg +0 -5
  158. package/bootstrap/services/portal/src/assets/eye-off.svg +0 -3
  159. package/bootstrap/services/portal/src/assets/eye.svg +0 -4
  160. package/bootstrap/services/portal/src/assets/gnar-engine-black.svg +0 -47
  161. package/bootstrap/services/portal/src/assets/gnar-engine-white.svg +0 -47
  162. package/bootstrap/services/portal/src/assets/gnar_engine.svg +0 -3
  163. package/bootstrap/services/portal/src/assets/gnarengine-logo-black.png +0 -0
  164. package/bootstrap/services/portal/src/assets/home.svg +0 -3
  165. package/bootstrap/services/portal/src/assets/link.svg +0 -3
  166. package/bootstrap/services/portal/src/assets/lock.svg +0 -3
  167. package/bootstrap/services/portal/src/assets/package.svg +0 -4
  168. package/bootstrap/services/portal/src/assets/raffle.svg +0 -3
  169. package/bootstrap/services/portal/src/assets/settings.svg +0 -4
  170. package/bootstrap/services/portal/src/assets/shopping-bag.svg +0 -3
  171. package/bootstrap/services/portal/src/assets/user-black.svg +0 -3
  172. package/bootstrap/services/portal/src/assets/user.svg +0 -3
  173. package/bootstrap/services/portal/src/assets/users.svg +0 -3
  174. package/bootstrap/services/portal/src/assets/wallet.svg +0 -3
  175. package/bootstrap/services/portal/src/data/data.js +0 -70
  176. package/bootstrap/services/portal/src/features/attributeFormRow/AttributeFormRow.jsx +0 -32
  177. package/bootstrap/services/portal/src/features/billingShipping/BillingShipping.jsx +0 -160
  178. package/bootstrap/services/portal/src/features/crud/crudEdit.less +0 -230
  179. package/bootstrap/services/portal/src/features/crud/crudList.less +0 -134
  180. package/bootstrap/services/portal/src/features/crud/crudPage.less +0 -31
  181. package/bootstrap/services/portal/src/features/crudContact/CrudContactList.jsx +0 -108
  182. package/bootstrap/services/portal/src/features/crudContact/CrudContactSingle.jsx +0 -243
  183. package/bootstrap/services/portal/src/features/crudOrder/CrudOrderList.jsx +0 -109
  184. package/bootstrap/services/portal/src/features/crudOrder/CrudOrderSingle.jsx +0 -315
  185. package/bootstrap/services/portal/src/features/crudProducts/CrudProductList.jsx +0 -104
  186. package/bootstrap/services/portal/src/features/crudProducts/CrudProductSingle.jsx +0 -388
  187. package/bootstrap/services/portal/src/features/crudRaffles/CrudRafflesList.jsx +0 -104
  188. package/bootstrap/services/portal/src/features/crudRaffles/CrudRafflesSingle.jsx +0 -208
  189. package/bootstrap/services/portal/src/features/crudSubscription/CrudSubscriptionList.jsx +0 -110
  190. package/bootstrap/services/portal/src/features/crudSubscription/CrudSubscriptionSingle.jsx +0 -261
  191. package/bootstrap/services/portal/src/features/crudUser/CrudUserList.jsx +0 -107
  192. package/bootstrap/services/portal/src/features/crudUser/CrudUserSingle.jsx +0 -402
  193. package/bootstrap/services/portal/src/features/inventoryFormRow/InventoryFormRow.jsx +0 -30
  194. package/bootstrap/services/portal/src/features/lineItems/LineItems.jsx +0 -113
  195. package/bootstrap/services/portal/src/features/loginForm/LoginForm.jsx +0 -56
  196. package/bootstrap/services/portal/src/features/loginForm/loginForm.less +0 -56
  197. package/bootstrap/services/portal/src/features/notes/Notes.jsx +0 -18
  198. package/bootstrap/services/portal/src/features/passwordReset/PasswordResetForm.jsx +0 -96
  199. package/bootstrap/services/portal/src/features/passwordReset/PasswordResetRequestForm.jsx +0 -74
  200. package/bootstrap/services/portal/src/features/priceFormRow/PriceFormRow.jsx +0 -102
  201. package/bootstrap/services/portal/src/features/priceFormRow/priceFormRow.less +0 -24
  202. package/bootstrap/services/portal/src/features/raffleEntriesList/RaffleEntriesList.jsx +0 -99
  203. package/bootstrap/services/portal/src/features/raffleProductFormRow/RaffleProductFormRow.jsx +0 -46
  204. package/bootstrap/services/portal/src/features/sidebar/Sidebar.jsx +0 -64
  205. package/bootstrap/services/portal/src/features/sidebar/sidebar.less +0 -49
  206. package/bootstrap/services/portal/src/features/skus/Skus.jsx +0 -109
  207. package/bootstrap/services/portal/src/features/subscriptionSchedule/SubscriptionSchedule.jsx +0 -44
  208. package/bootstrap/services/portal/src/features/taxonomyFormRow/TaxonomyFormRow.jsx +0 -32
  209. package/bootstrap/services/portal/src/features/user/User.jsx +0 -54
  210. package/bootstrap/services/portal/src/features/user/user.less +0 -57
  211. package/bootstrap/services/portal/src/includes/utilities.js +0 -259
  212. package/bootstrap/services/portal/src/index.js +0 -14
  213. package/bootstrap/services/portal/src/layouts/CrudLayout.jsx +0 -50
  214. package/bootstrap/services/portal/src/layouts/LoginLayout.jsx +0 -17
  215. package/bootstrap/services/portal/src/layouts/PortalLayout.jsx +0 -48
  216. package/bootstrap/services/portal/src/layouts/loginLayout.less +0 -33
  217. package/bootstrap/services/portal/src/layouts/portalLayout.less +0 -67
  218. package/bootstrap/services/portal/src/pages/contacts/Contacts.jsx +0 -199
  219. package/bootstrap/services/portal/src/pages/dashboard/Dashboard.jsx +0 -17
  220. package/bootstrap/services/portal/src/pages/integrations/Integrations.jsx +0 -10
  221. package/bootstrap/services/portal/src/pages/login/Login.jsx +0 -15
  222. package/bootstrap/services/portal/src/pages/login/login.less +0 -10
  223. package/bootstrap/services/portal/src/pages/orders/Orders.jsx +0 -199
  224. package/bootstrap/services/portal/src/pages/passwordReset/PasswordResetPage.jsx +0 -15
  225. package/bootstrap/services/portal/src/pages/passwordResetRequest/PasswordResetRequestPage.jsx +0 -15
  226. package/bootstrap/services/portal/src/pages/payments/Payments.jsx +0 -10
  227. package/bootstrap/services/portal/src/pages/portal/Portal.jsx +0 -43
  228. package/bootstrap/services/portal/src/pages/products/Products.jsx +0 -212
  229. package/bootstrap/services/portal/src/pages/raffleEntries/RaffleEntries.jsx +0 -124
  230. package/bootstrap/services/portal/src/pages/raffles/Raffles.jsx +0 -186
  231. package/bootstrap/services/portal/src/pages/reports/Reports.jsx +0 -10
  232. package/bootstrap/services/portal/src/pages/settings/Settings.jsx +0 -10
  233. package/bootstrap/services/portal/src/pages/subscriptions/Subscriptions.jsx +0 -199
  234. package/bootstrap/services/portal/src/pages/users/Users.jsx +0 -193
  235. package/bootstrap/services/portal/src/pages/users/users.less +0 -25
  236. package/bootstrap/services/portal/src/styles/inputs.less +0 -157
  237. package/bootstrap/services/portal/src/styles/main.less +0 -26
  238. package/bootstrap/services/portal/src/ui/collapsible/Collapsible.jsx +0 -97
  239. package/bootstrap/services/portal/src/ui/collapsible/collapsible.less +0 -23
  240. package/bootstrap/services/portal/src/ui/customCheckbox/CustomCheckbox.jsx +0 -17
  241. package/bootstrap/services/portal/src/ui/customCheckbox/customCheckbox.less +0 -42
  242. package/bootstrap/services/portal/src/ui/customMultiSelect/CustomMultiSelect.jsx +0 -63
  243. package/bootstrap/services/portal/src/ui/customMultiSelect/CustomMultiSelectPeriod.jsx +0 -63
  244. package/bootstrap/services/portal/src/ui/goBack/GoBack.jsx +0 -19
  245. package/bootstrap/services/portal/src/ui/loader/Loader.jsx +0 -12
  246. package/bootstrap/services/portal/src/ui/pagination/Pagination.jsx +0 -23
  247. package/bootstrap/services/portal/src/ui/repeater/Repeater.jsx +0 -29
  248. package/bootstrap/services/portal/src/ui/saveButton/SaveButton.jsx +0 -69
  249. package/bootstrap/services/user/src/db/seeders/development/02-portal-admin-user.js +0 -27
  250. package/bootstrap/services/user/src/tests/user.test.js +0 -126
  251. package/templates/service/app.js.hbs +0 -38
  252. package/templates/service/schema/{{serviceName}}.schema.js.hbs +0 -14
  253. /package/bootstrap/services/portal/src/{ui/saveButton/saveButton.less → components/CustomSelect/CustomSelect.less} +0 -0
  254. /package/templates/service/{controllers → src/controllers}/http.controller.js.hbs +0 -0
  255. /package/templates/service/{controllers → src/controllers}/message.controller.js.hbs +0 -0
  256. /package/templates/service/{db → src/mysql.db}/migrations/01-init.js.hbs +0 -0
  257. /package/templates/service/{db → src/mysql.db}/migrations/02-{{lowerCase serviceName}}-service-init.js.hbs +0 -0
  258. /package/templates/service/{policies → src/policies}/{{serviceName}}.policy.js.hbs +0 -0
  259. /package/templates/service/{services/{{serviceName}}.service.js.hbs → src/services/mysql.{{serviceName}}.service.js.hbs} +0 -0
@@ -0,0 +1,70 @@
1
+ import { db, logger } from '@gnar-engine/core';
2
+ import { ObjectId } from 'mongodb';
3
+
4
+ export const {{serviceName}} = {
5
+
6
+ // Get all {{lowerCasePlural serviceName}}
7
+ getAll: async () => {
8
+ try {
9
+ const items = await db.collection('{{lowerCasePlural serviceName}}').find().toArray();
10
+ return items;
11
+ } catch (error) {
12
+ logger.error("Error fetching {{lowerCasePlural serviceName}}:", error);
13
+ throw error;
14
+ }
15
+ },
16
+
17
+ // Create a {{lowerCase serviceName}}
18
+ create: async (data) => {
19
+ try {
20
+ const collection = db.collection('{{lowerCasePlural serviceName}}');
21
+ const result = await collection.insertOne(data);
22
+ return await collection.findOne({ _id: result.insertedId });
23
+ } catch (error) {
24
+ logger.error("Error creating {{lowerCase serviceName}}:", error);
25
+ throw error;
26
+ }
27
+ },
28
+
29
+ // Get a {{lowerCase serviceName}} by ID
30
+ getById: async ({ id }) => {
31
+ try {
32
+ const collection = db.collection('{{lowerCasePlural serviceName}}');
33
+ const objectId = new ObjectId(id);
34
+ const item = await collection.findOne({ _id: objectId });
35
+ return item;
36
+ } catch (error) {
37
+ logger.error("Error fetching {{lowerCase serviceName}}:", error);
38
+ throw error;
39
+ }
40
+ },
41
+
42
+ // Update a {{lowerCase serviceName}}
43
+ update: async ({ id, updatedData }) => {
44
+ try {
45
+ const collection = db.collection('{{lowerCasePlural serviceName}}');
46
+ const objectId = new ObjectId(id);
47
+ const result = await collection.updateOne(
48
+ { _id: objectId },
49
+ { $set: updatedData }
50
+ );
51
+ return result.modifiedCount > 0;
52
+ } catch (error) {
53
+ logger.error("Error updating {{lowerCase serviceName}}:", error);
54
+ throw error;
55
+ }
56
+ },
57
+
58
+ // Delete a {{lowerCase serviceName}}
59
+ delete: async ({ id }) => {
60
+ try {
61
+ const collection = db.collection('{{lowerCasePlural serviceName}}');
62
+ const objectId = new ObjectId(id);
63
+ const result = await collection.deleteOne({ _id: objectId });
64
+ return result.deletedCount > 0;
65
+ } catch (error) {
66
+ logger.error("Error deleting {{lowerCase serviceName}}:", error);
67
+ throw error;
68
+ }
69
+ }
70
+ };
@@ -1,28 +0,0 @@
1
- # Gnar MCP Notes
2
-
3
- ### Aims
4
-
5
- - We don't want to provide all command implementations (with payload information) until we know what commands are required.
6
-
7
- Step 1: Gather Facts
8
-
9
- - All first prompts (no chatId provided) are 'gather facts'.
10
- - This prompt will be augmented with the all service/model schemas and a list of all available commands e.g. userService.create, userService.update.
11
- - From the client input the model should generate an action plan with an ordered list of the commands required, and also request the exact data required from the user to carry out the plan (based on the schemas provided in the augmented prompt).
12
-
13
- Step 2: Confirm plan
14
-
15
- - All further prompts (chatId provided) that do not have a 'confirmed plan' are 'confirm plan'.
16
- - This prompt will be augmented with the all service/model schemas, a list of all available commands, a manifest containing the command implementations (including payload information) for each command in the most recently proposed action plan, the most recently proposed action plan itself, and a list of all previous user inputs and response texts.
17
- - The model should determine from the resources provided if the action plan is accurate and if we have enough information, request conmfirmation from the user to action the request. If not we should request further information from the user until all information is provided. Should reassess the proposed plan based on user input and the command implementations provided in the prompt augmentation. If the plan is suitable, we have all the required information, and the user has confirmed that we can action the request, the model should include - actionPlanGoAhead = true in the response, and also the first command execution payload in the actionPlan.
18
-
19
-
20
- // should we postback before actioning?
21
- Step 3: Action plan loop
22
- - Before returning back to the client - if the agent response has 'actionPlanGoAhead' = true, we should initalise the action plan execution loop
23
- - Action Plan Execution Loop (foreach action plan command):
24
- - The command will be triggered with the included payload.
25
- - The result of the first command will be passed back to the agent with the system prompt, action plan, all messages, schemas, relevant command implementations.
26
- - This prompt should confirm the payload for the next command in the action Plan.
27
-
28
- - Upon the last command being executed, the model will be prompted to provide a text output to confirm the result of the action plan.
@@ -1,16 +0,0 @@
1
- {
2
- "name": "agent-service",
3
- "version": "1.0.0",
4
- "description": "LLM Agent microservice for Gnar Engine",
5
- "type": "module",
6
- "scripts": {
7
- "start": "node ./src/app.js",
8
- "start:dev": "nodemon --watch ./src ./src/app.js"
9
- },
10
- "dependencies": {
11
- "@gnar-engine/core": "^1.0.1",
12
- "openai": "5.13.1"
13
- },
14
- "author": "Gnar Software",
15
- "license": "MIT"
16
- }
@@ -1,52 +0,0 @@
1
- import { message, http, logger, db, registerService } from '@gnar-engine/core';
2
- import { config } from './config.js';
3
- import { messageHandlers } from './controllers/message.controller.js';
4
- import { httpController as AgentPlatformHttpController } from './controllers/http.controller.js';
5
- import { manifestService } from './services/manifest.service.js';
6
- import { Agent } from './services/agent.service.js';
7
-
8
- /**
9
- * Initialise service
10
- */
11
- export const initService = async () => {
12
-
13
- // Run migrations
14
- db.migrations.runMigrations({config});
15
- db.seeders.runSeeders({config});
16
-
17
- // Import command handlers after the command bus is initialised
18
- await import('./commands/agent.handler.js');
19
- // Add more handlers as needed
20
-
21
- // Initialise and register message handlers
22
- await message.init({
23
- config: config.message,
24
- handlers: messageHandlers
25
- });
26
-
27
- // Register http routes
28
- await http.registerRoutes({
29
- controllers: [
30
- AgentPlatformHttpController,
31
- ]
32
- });
33
-
34
- // Initialise agent client
35
- await Agent.init();
36
-
37
- // Start the HTTP server
38
- await http.start();
39
-
40
- // Register service with control service
41
- await registerService();
42
-
43
- // Start manifest generation poll
44
- //setInterval(() => {
45
- manifestService.generateServiceManifests();
46
- //}, 3600);
47
-
48
- logger.info('G n a r E n g i n e | Agent Service initialised successfully.');
49
- }
50
-
51
- initService();
52
-
@@ -1,104 +0,0 @@
1
- import { commands, logger } from '@gnar-engine/core';
2
- import { Agent } from '../services/agent.service.js';
3
- import { config } from '../config.js';
4
-
5
-
6
- /**
7
- * Prompt the LLM agent
8
- */
9
- commands.register('agentService.prompt', async ({input, chatId, authUser}) => {
10
- try {
11
- logger.info('recieved input' + JSON.stringify(input));
12
- let chatContextToStore = {};
13
-
14
- const [manifests, resolvedChatId, chat] = await Promise.all([
15
- // Get the manifests
16
- commands.execute('controlService.getManifests'),
17
-
18
- // Create a new chat if chatId is not provided
19
- (async () => {
20
- if (!chatId) {
21
- return await Agent.createChat({
22
- userId: '',
23
- title: input.substring(0, 50),
24
- sessionKey: input.sessionKey
25
- });
26
- }
27
-
28
- return chatId
29
- })(),
30
-
31
- // Retrieve existing chat if chatId is provided
32
- (async () => {
33
- if (chatId) {
34
- return await Agent.getChat({chatId});
35
- }
36
-
37
- return null;
38
- })()
39
- ]);
40
-
41
- let preparedInput;
42
-
43
- // Gather facts
44
- if (!chatId) {
45
- preparedInput = await Agent.prepareGatherFactsPrompt({inputText: input, manifests: manifests});
46
- }
47
-
48
- // Prepare Plan
49
- else if (chat) {
50
- await logger.info('GOT HERE WITH CHAT: ' + JSON.stringify(chat));
51
- preparedInput = await Agent.preparePlanPrompt({inputText: input, manifests: manifests, chat: chat});
52
- }
53
-
54
- // Infer
55
- let agentResponse = await Agent.infer({preparedInput});
56
- logger.info('Agent response: ' + agentResponse);
57
- agentResponse = JSON.parse(agentResponse);
58
-
59
- // Collect context from response
60
- chatContextToStore.actionPlan = agentResponse.actionPlan || null;
61
- chatContextToStore.input = input;
62
- chatContextToStore.responseText = agentResponse.responseText || null;
63
-
64
- // Collect required command implementations from manifests to store for next time
65
- if (agentResponse.commandsRequired) {
66
- chatContextToStore.commandsManifest = [];
67
-
68
- agentResponse.commandsRequired.forEach((commandRequired) => {
69
- manifests.manifests.forEach((manifest) => {
70
- //logger.info('got here ' + commandRequired + ' ' + JSON.stringify(manifest.manifest) );
71
- if (manifest.manifest?.commandImplementations?.[commandRequired]) {
72
- chatContextToStore.commandsManifest.push(manifest.manifest.commandImplementations[commandRequired]);
73
- }
74
- })
75
- });
76
- }
77
-
78
- logger.info('Chat context to store: ' + JSON.stringify(chatContextToStore));
79
-
80
- // Store chat messages
81
- chatId = resolvedChatId;
82
- Agent.createChatMessage({
83
- chatId: chatId,
84
- userName: authUser.username,
85
- context: chatContextToStore
86
- });
87
-
88
- // Plan execution loop
89
- if (agentResponse.actionPlan) {
90
- logger.info('Executing plan: ' + agentResponse.actionPlan);
91
-
92
- }
93
-
94
- let response = {
95
- structuredResponse: agentResponse,
96
- chatId: chatId
97
- };
98
-
99
- return response;
100
- } catch (err) {
101
- logger.error("Error handling LLM agent prompt: " + err);
102
- throw err;
103
- }
104
- });
@@ -1,52 +0,0 @@
1
- /**
2
- * Gnar Engine Service Config
3
- */
4
- export const config = {
5
- // service name
6
- serviceName: 'agentService',
7
-
8
- // microservice | modular-monolith
9
- architecture: process.env.GLOBAL_ARCHITECTURE || 'microservice',
10
-
11
- // web server
12
- http: {
13
- allowedOrigins: [],
14
- allowedMethods: ['GET', 'POST', 'PUT', 'DELETE'],
15
- allowedHeaders: ['Content-Type', 'Authorization'],
16
- rateLimiting: {
17
- max: 3,
18
- timeWindow: '1 second',
19
- }
20
- },
21
-
22
- // database
23
- db: {
24
- // type: mongodb | mysql
25
- type: 'mysql',
26
-
27
- // MongoDB
28
- connectionUrl: process.env.AGENT_MONGO_URL,
29
- connectionArgs: {},
30
-
31
- // MySQL
32
- host: process.env.AGENT_MYSQL_HOST,
33
- user: process.env.AGENT_MYSQL_USER,
34
- password: process.env.AGENT_MYSQL_PASSWORD,
35
- database: process.env.AGENT_MYSQL_DATABASE,
36
- connectionLimit: 10,
37
- queueLimit: 20,
38
- maxRetries: 5
39
- },
40
-
41
- // message broker
42
- message: {
43
- url: process.env.RABBITMQ_URL,
44
- queueName: 'agentServiceQueue',
45
- prefetch: 20
46
- },
47
-
48
- hashNameSpace: '',
49
-
50
- // Default agent type
51
- agent: 'chatgpt'
52
- }
@@ -1,44 +0,0 @@
1
- import { commands, logger } from '@gnar-engine/core';
2
- import { authorise } from '../policies/agent.policy.js';
3
-
4
- /**
5
- * HTTP controller
6
- */
7
- export const httpController = {
8
-
9
- /**
10
- * Prompt the agent
11
- */
12
- agentPrompt: {
13
- method: 'POST',
14
- url: '/agent/prompt',
15
- preHandler: async (request, reply) => authorise.agentPrompt(request, reply),
16
- handler: async (request, reply) => {
17
- logger.info('Received agent prompt request' + JSON.stringify(request.body));
18
- const params = {
19
- input: request.body.textInput,
20
- chatId: request.body.chatId || '',
21
- authUser: request.user
22
- };
23
-
24
- // Sanitize input (remove all JSON delimiters)
25
- params.input = params.input.replace(/[\{\}\[\]\"\'\:\,]/g, '');
26
-
27
- // execute
28
- let response;
29
- logger.info('params' + JSON.stringify(params));
30
- try {
31
- response = await commands.execute('prompt', params);
32
- } catch (error) {
33
- logger.error(error.message);
34
- return reply.code(500).send({ error: error.message});
35
- }
36
-
37
- logger.info('response is: ' + JSON.stringify(response));
38
-
39
- // handle response
40
- reply.code(200).send(response);
41
- }
42
- },
43
-
44
- }
@@ -1,51 +0,0 @@
1
- import { commands } from '@gnar-engine/core';
2
-
3
- export const messageHandlers = {
4
-
5
- getAgent: async (payload) => {
6
- let result;
7
- if (payload.data?.id) {
8
- result = await commands.execute('getSingleAgent', {
9
- id: payload.data.id
10
- });
11
- } else if (payload.data?.email) {
12
- result = await commands.execute('getSingleAgent', {
13
- email: payload.data.email
14
- });
15
- } else {
16
- throw new Error('No Agent ID or email provided');
17
- }
18
- if (!result) {
19
- throw new Error('Agent not found');
20
- }
21
- return { Agent: result };
22
- },
23
-
24
- getManyAgents: async (payload) => {
25
- const results = await commands.execute('getManyAgents', {});
26
- return { agents: results };
27
- },
28
-
29
- createAgent: async (payload) => {
30
- const results = await commands.execute('createAgents', {
31
- agents: [payload.data.Agent]
32
- });
33
- return { agents: results };
34
- },
35
-
36
- updateAgent: async (payload) => {
37
- const result = await commands.execute('updateAgent', {
38
- id: payload.data.id,
39
- newAgentData: payload.data
40
- });
41
- return { Agent: result };
42
- },
43
-
44
- deleteAgent: async (payload) => {
45
- await commands.execute('deleteAgent', {
46
- id: payload.data.id
47
- });
48
- return { message: 'Agent deleted' };
49
- },
50
-
51
- };
@@ -1,50 +0,0 @@
1
- import { logger, db } from '@gnar-engine/core';
2
-
3
- /**
4
- * Up
5
- */
6
- export const up = async () => {
7
- await initDatabaseTables();
8
- }
9
-
10
- /**
11
- * Down
12
- */
13
- export const down = async () => {
14
- await dropDatabaseTables();
15
- }
16
-
17
- /**
18
- * Create all tables
19
- */
20
- export const initDatabaseTables = async () => {
21
-
22
- // Migrations table
23
- logger.info("Creating migrations table");
24
- const createMigrationsTableQuery = `
25
- CREATE TABLE migrations (
26
- id INT AUTO_INCREMENT PRIMARY KEY,
27
- name VARCHAR(255) NOT NULL UNIQUE,
28
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
29
- )`;
30
- await db.query(createMigrationsTableQuery);
31
-
32
- // Seeders table
33
- logger.info("Creating seeders table");
34
- const createSeedersTableQuery = `
35
- CREATE TABLE seeders (
36
- id INT AUTO_INCREMENT PRIMARY KEY,
37
- name VARCHAR(255) NOT NULL UNIQUE,
38
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
39
- )`;
40
- await db.query(createSeedersTableQuery);
41
- }
42
-
43
- /**
44
- * Drop all tables
45
- */
46
- export const dropDatabaseTables = async () => {
47
- logger.info('Dropping tables');
48
- await db.query('DROP TABLE IF EXISTS migrations');
49
- await db.query('DROP TABLE IF EXISTS seeders');
50
- }
@@ -1,36 +0,0 @@
1
- import { logger, db } from '@gnar-engine/core';
2
-
3
- /**
4
- * Up
5
- */
6
- export const up = async () => {
7
- logger.info('Creating table: agent-chats');
8
- await db.query(`
9
- CREATE TABLE agent_chats (
10
- id CHAR(36) PRIMARY KEY,
11
- user_id CHAR(36) NOT NULL,
12
- title VARCHAR(255) NOT NULL,
13
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
14
- updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
15
- )
16
- `);
17
-
18
- logger.info('Creating table: agent-chat-messages');
19
- await db.query(`
20
- CREATE TABLE agent_chat_messages (
21
- id CHAR(36) PRIMARY KEY,
22
- chat_id CHAR(36) NOT NULL,
23
- user_name VARCHAR(255) NOT NULL,
24
- context MEDIUMTEXT NOT NULL,
25
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
26
- )
27
- `);
28
- }
29
-
30
- /**
31
- * Down
32
- */
33
- export const down = async () => {
34
- logger.info('Dropping table: agents');
35
- await db.query('DROP TABLE IF EXISTS agents');
36
- }
@@ -1,13 +0,0 @@
1
- import { config } from '../config.js';
2
-
3
- export const authorise = {
4
-
5
- /**
6
- * Authorise agent prompt
7
- */
8
- agentPrompt: async (request, reply) => {
9
- if (!request.user || request.user.role !== 'service_admin') {
10
- reply.code(403).send({error: 'not authorised'});
11
- }
12
- }
13
- }