@gnar-engine/cli 1.0.0 → 1.0.1
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.
- package/assets/gnar-engine-logo-white.svg +9 -0
- package/bootstrap/deploy.localdev.yml +51 -0
- package/bootstrap/secrets.localdev.yml +27 -0
- package/bootstrap/services/agent/Dockerfile +23 -0
- package/bootstrap/services/agent/notes.md +28 -0
- package/bootstrap/services/agent/package.json +16 -0
- package/bootstrap/services/agent/src/app.js +52 -0
- package/bootstrap/services/agent/src/commands/agent.handler.js +104 -0
- package/bootstrap/services/agent/src/config.js +52 -0
- package/bootstrap/services/agent/src/controllers/http.controller.js +44 -0
- package/bootstrap/services/agent/src/controllers/message.controller.js +51 -0
- package/bootstrap/services/agent/src/db/migrations/01-init.js +50 -0
- package/bootstrap/services/agent/src/db/migrations/02-agent-service-init.js +36 -0
- package/bootstrap/services/agent/src/policies/agent.policy.js +13 -0
- package/bootstrap/services/agent/src/schema/Agent.schema.js +17 -0
- package/bootstrap/services/agent/src/services/agent.service.js +259 -0
- package/bootstrap/services/agent/src/services/chatgpt.service.js +46 -0
- package/bootstrap/services/agent/src/services/manifest.service.js +21 -0
- package/bootstrap/services/control/Dockerfile +23 -0
- package/bootstrap/services/control/Dockerfile.prod +37 -0
- package/bootstrap/services/control/README.md +25 -0
- package/bootstrap/services/control/package.json +16 -0
- package/bootstrap/services/control/src/app.js +45 -0
- package/bootstrap/services/control/src/commands/control.handler.js +231 -0
- package/bootstrap/services/control/src/commands/service.handler.js +81 -0
- package/bootstrap/services/control/src/commands/task.handler.js +247 -0
- package/bootstrap/services/control/src/config.js +55 -0
- package/bootstrap/services/control/src/controllers/http.controller.js +228 -0
- package/bootstrap/services/control/src/controllers/message.controller.js +40 -0
- package/bootstrap/services/control/src/db/migrations/01-init.js +50 -0
- package/bootstrap/services/control/src/db/migrations/02-control-service-init.js +60 -0
- package/bootstrap/services/control/src/db/migrations/03-alter-tasks.js +29 -0
- package/bootstrap/services/control/src/policies/task.policy.js +53 -0
- package/bootstrap/services/control/src/schema/control.schema.js +42 -0
- package/bootstrap/services/control/src/services/registry.service.js +83 -0
- package/bootstrap/services/control/src/services/reset.service.js +28 -0
- package/bootstrap/services/control/src/services/task.service.js +153 -0
- package/bootstrap/services/control/src/tests/control.test.js +50 -0
- package/bootstrap/services/notification/Dockerfile +23 -0
- package/bootstrap/services/notification/Dockerfile.prod +37 -0
- package/bootstrap/services/notification/README.md +3 -0
- package/bootstrap/services/notification/package.json +34 -0
- package/bootstrap/services/notification/src/app.js +51 -0
- package/bootstrap/services/notification/src/commands/command-bus.js +20 -0
- package/bootstrap/services/notification/src/commands/handlers/control.handler.js +18 -0
- package/bootstrap/services/notification/src/commands/handlers/notification.handler.js +157 -0
- package/bootstrap/services/notification/src/config.js +15 -0
- package/bootstrap/services/notification/src/controllers/message.controller.js +82 -0
- package/bootstrap/services/notification/src/services/logger.service.js +16 -0
- package/bootstrap/services/notification/src/services/ses.service.js +23 -0
- package/bootstrap/services/notification/src/templates/admin-order-recieved.hbs +136 -0
- package/bootstrap/services/notification/src/templates/admin-subscription-failed.hbs +87 -0
- package/bootstrap/services/notification/src/templates/customer-order-recieved.hbs +132 -0
- package/bootstrap/services/notification/src/templates/customer-subscription-failed.hbs +77 -0
- package/bootstrap/services/notification/src/tests/notification.test.js +0 -0
- package/bootstrap/services/portal/Dockerfile +23 -0
- package/bootstrap/services/portal/Dockerfile.remote +40 -0
- package/bootstrap/services/portal/README.md +22 -0
- package/bootstrap/services/portal/nginx.conf +12 -0
- package/bootstrap/services/portal/package.json +59 -0
- package/bootstrap/services/portal/public/favicon.ico +0 -0
- package/bootstrap/services/portal/public/gnar-white.png +0 -0
- package/bootstrap/services/portal/public/gnarengine-logo-black.png +0 -0
- package/bootstrap/services/portal/public/index.html +43 -0
- package/bootstrap/services/portal/public/logo192.png +0 -0
- package/bootstrap/services/portal/public/logo512.png +0 -0
- package/bootstrap/services/portal/public/manifest.json +25 -0
- package/bootstrap/services/portal/public/robots.txt +3 -0
- package/bootstrap/services/portal/src/App.js +56 -0
- package/bootstrap/services/portal/src/assets/Logo_Anchord_Black.svg +1 -0
- package/bootstrap/services/portal/src/assets/Logo_Anchord_Black_Green.svg +1 -0
- package/bootstrap/services/portal/src/assets/Logo_Anchord_White_Green.svg +1 -0
- package/bootstrap/services/portal/src/assets/activity.svg +3 -0
- package/bootstrap/services/portal/src/assets/arrow.svg +3 -0
- package/bootstrap/services/portal/src/assets/bin-white.svg +3 -0
- package/bootstrap/services/portal/src/assets/bin.svg +3 -0
- package/bootstrap/services/portal/src/assets/check.svg +3 -0
- package/bootstrap/services/portal/src/assets/chevron.svg +3 -0
- package/bootstrap/services/portal/src/assets/contact.svg +3 -0
- package/bootstrap/services/portal/src/assets/dots-vertical.svg +5 -0
- package/bootstrap/services/portal/src/assets/eye-off.svg +3 -0
- package/bootstrap/services/portal/src/assets/eye.svg +4 -0
- package/bootstrap/services/portal/src/assets/gnar-engine-black.svg +47 -0
- package/bootstrap/services/portal/src/assets/gnar-engine-white.svg +47 -0
- package/bootstrap/services/portal/src/assets/gnar_engine.svg +3 -0
- package/bootstrap/services/portal/src/assets/gnarengine-logo-black.png +0 -0
- package/bootstrap/services/portal/src/assets/home.svg +3 -0
- package/bootstrap/services/portal/src/assets/link.svg +3 -0
- package/bootstrap/services/portal/src/assets/lock.svg +3 -0
- package/bootstrap/services/portal/src/assets/package.svg +4 -0
- package/bootstrap/services/portal/src/assets/raffle.svg +3 -0
- package/bootstrap/services/portal/src/assets/settings.svg +4 -0
- package/bootstrap/services/portal/src/assets/shopping-bag.svg +3 -0
- package/bootstrap/services/portal/src/assets/user-black.svg +3 -0
- package/bootstrap/services/portal/src/assets/user.svg +3 -0
- package/bootstrap/services/portal/src/assets/users.svg +3 -0
- package/bootstrap/services/portal/src/assets/wallet.svg +3 -0
- package/bootstrap/services/portal/src/css/style.css +1007 -0
- package/bootstrap/services/portal/src/data/data.js +70 -0
- package/bootstrap/services/portal/src/features/attributeFormRow/AttributeFormRow.jsx +32 -0
- package/bootstrap/services/portal/src/features/billingShipping/BillingShipping.jsx +160 -0
- package/bootstrap/services/portal/src/features/crud/crudEdit.less +230 -0
- package/bootstrap/services/portal/src/features/crud/crudList.less +134 -0
- package/bootstrap/services/portal/src/features/crud/crudPage.less +31 -0
- package/bootstrap/services/portal/src/features/crudContact/CrudContactList.jsx +108 -0
- package/bootstrap/services/portal/src/features/crudContact/CrudContactSingle.jsx +243 -0
- package/bootstrap/services/portal/src/features/crudOrder/CrudOrderList.jsx +109 -0
- package/bootstrap/services/portal/src/features/crudOrder/CrudOrderSingle.jsx +315 -0
- package/bootstrap/services/portal/src/features/crudProducts/CrudProductList.jsx +104 -0
- package/bootstrap/services/portal/src/features/crudProducts/CrudProductSingle.jsx +388 -0
- package/bootstrap/services/portal/src/features/crudRaffles/CrudRafflesList.jsx +104 -0
- package/bootstrap/services/portal/src/features/crudRaffles/CrudRafflesSingle.jsx +208 -0
- package/bootstrap/services/portal/src/features/crudSubscription/CrudSubscriptionList.jsx +110 -0
- package/bootstrap/services/portal/src/features/crudSubscription/CrudSubscriptionSingle.jsx +261 -0
- package/bootstrap/services/portal/src/features/crudUser/CrudUserList.jsx +107 -0
- package/bootstrap/services/portal/src/features/crudUser/CrudUserSingle.jsx +402 -0
- package/bootstrap/services/portal/src/features/inventoryFormRow/InventoryFormRow.jsx +30 -0
- package/bootstrap/services/portal/src/features/lineItems/LineItems.jsx +113 -0
- package/bootstrap/services/portal/src/features/loginForm/LoginForm.jsx +56 -0
- package/bootstrap/services/portal/src/features/loginForm/loginForm.less +56 -0
- package/bootstrap/services/portal/src/features/notes/Notes.jsx +18 -0
- package/bootstrap/services/portal/src/features/passwordReset/PasswordResetForm.jsx +96 -0
- package/bootstrap/services/portal/src/features/passwordReset/PasswordResetRequestForm.jsx +74 -0
- package/bootstrap/services/portal/src/features/priceFormRow/PriceFormRow.jsx +102 -0
- package/bootstrap/services/portal/src/features/priceFormRow/priceFormRow.less +24 -0
- package/bootstrap/services/portal/src/features/raffleEntriesList/RaffleEntriesList.jsx +99 -0
- package/bootstrap/services/portal/src/features/raffleProductFormRow/RaffleProductFormRow.jsx +46 -0
- package/bootstrap/services/portal/src/features/sidebar/Sidebar.jsx +64 -0
- package/bootstrap/services/portal/src/features/sidebar/sidebar.less +49 -0
- package/bootstrap/services/portal/src/features/skus/Skus.jsx +109 -0
- package/bootstrap/services/portal/src/features/subscriptionSchedule/SubscriptionSchedule.jsx +44 -0
- package/bootstrap/services/portal/src/features/taxonomyFormRow/TaxonomyFormRow.jsx +32 -0
- package/bootstrap/services/portal/src/features/user/User.jsx +54 -0
- package/bootstrap/services/portal/src/features/user/user.less +57 -0
- package/bootstrap/services/portal/src/includes/utilities.js +259 -0
- package/bootstrap/services/portal/src/index.js +14 -0
- package/bootstrap/services/portal/src/layouts/CrudLayout.jsx +50 -0
- package/bootstrap/services/portal/src/layouts/LoginLayout.jsx +17 -0
- package/bootstrap/services/portal/src/layouts/PortalLayout.jsx +48 -0
- package/bootstrap/services/portal/src/layouts/loginLayout.less +33 -0
- package/bootstrap/services/portal/src/layouts/portalLayout.less +67 -0
- package/bootstrap/services/portal/src/pages/contacts/Contacts.jsx +199 -0
- package/bootstrap/services/portal/src/pages/dashboard/Dashboard.jsx +17 -0
- package/bootstrap/services/portal/src/pages/integrations/Integrations.jsx +10 -0
- package/bootstrap/services/portal/src/pages/login/Login.jsx +15 -0
- package/bootstrap/services/portal/src/pages/login/login.less +10 -0
- package/bootstrap/services/portal/src/pages/orders/Orders.jsx +199 -0
- package/bootstrap/services/portal/src/pages/passwordReset/PasswordResetPage.jsx +15 -0
- package/bootstrap/services/portal/src/pages/passwordResetRequest/PasswordResetRequestPage.jsx +15 -0
- package/bootstrap/services/portal/src/pages/payments/Payments.jsx +10 -0
- package/bootstrap/services/portal/src/pages/portal/Portal.jsx +43 -0
- package/bootstrap/services/portal/src/pages/products/Products.jsx +212 -0
- package/bootstrap/services/portal/src/pages/raffleEntries/RaffleEntries.jsx +124 -0
- package/bootstrap/services/portal/src/pages/raffles/Raffles.jsx +186 -0
- package/bootstrap/services/portal/src/pages/reports/Reports.jsx +10 -0
- package/bootstrap/services/portal/src/pages/settings/Settings.jsx +10 -0
- package/bootstrap/services/portal/src/pages/subscriptions/Subscriptions.jsx +199 -0
- package/bootstrap/services/portal/src/pages/users/Users.jsx +193 -0
- package/bootstrap/services/portal/src/pages/users/users.less +25 -0
- package/bootstrap/services/portal/src/slices/authSlice.js +71 -0
- package/bootstrap/services/portal/src/store/configureStore.js +12 -0
- package/bootstrap/services/portal/src/styles/global.less +159 -0
- package/bootstrap/services/portal/src/styles/inputs.less +157 -0
- package/bootstrap/services/portal/src/styles/main.less +26 -0
- package/bootstrap/services/portal/src/ui/collapsible/Collapsible.jsx +97 -0
- package/bootstrap/services/portal/src/ui/collapsible/collapsible.less +23 -0
- package/bootstrap/services/portal/src/ui/customCheckbox/CustomCheckbox.jsx +17 -0
- package/bootstrap/services/portal/src/ui/customCheckbox/customCheckbox.less +42 -0
- package/bootstrap/services/portal/src/ui/customMultiSelect/CustomMultiSelect.jsx +63 -0
- package/bootstrap/services/portal/src/ui/customMultiSelect/CustomMultiSelectPeriod.jsx +63 -0
- package/bootstrap/services/portal/src/ui/customSelect/CustomSelect.jsx +63 -0
- package/bootstrap/services/portal/src/ui/customSelect/customSelect.less +92 -0
- package/bootstrap/services/portal/src/ui/goBack/GoBack.jsx +19 -0
- package/bootstrap/services/portal/src/ui/loader/Loader.jsx +12 -0
- package/bootstrap/services/portal/src/ui/pagination/Pagination.jsx +23 -0
- package/bootstrap/services/portal/src/ui/repeater/Repeater.jsx +29 -0
- package/bootstrap/services/portal/src/ui/saveButton/SaveButton.jsx +69 -0
- package/bootstrap/services/portal/src/ui/saveButton/saveButton.less +0 -0
- package/bootstrap/services/rabbit-mq/Dockerfile.prod +9 -0
- package/bootstrap/services/user/Dockerfile +23 -0
- package/bootstrap/services/user/Dockerfile.prod +37 -0
- package/bootstrap/services/user/README.md +8 -0
- package/bootstrap/services/user/package.json +16 -0
- package/bootstrap/services/user/src/app.js +45 -0
- package/bootstrap/services/user/src/commands/session.handler.js +23 -0
- package/bootstrap/services/user/src/commands/user.handler.js +286 -0
- package/bootstrap/services/user/src/config.js +73 -0
- package/bootstrap/services/user/src/controllers/http.controller.js +156 -0
- package/bootstrap/services/user/src/controllers/message.controller.js +51 -0
- package/bootstrap/services/user/src/db/migrations/01-init.js +50 -0
- package/bootstrap/services/user/src/db/migrations/02-user-service-init.js +63 -0
- package/bootstrap/services/user/src/db/migrations/03-unauth-sessions.js +43 -0
- package/bootstrap/services/user/src/db/seeders/development/01-root-user.js +29 -0
- package/bootstrap/services/user/src/db/seeders/development/02-portal-admin-user.js +27 -0
- package/bootstrap/services/user/src/db/seeders/production/01-root-user.js +29 -0
- package/bootstrap/services/user/src/policies/user.policy.js +81 -0
- package/bootstrap/services/user/src/schema/user.schema.js +69 -0
- package/bootstrap/services/user/src/services/authentication.service.js +127 -0
- package/bootstrap/services/user/src/services/session.service.js +58 -0
- package/bootstrap/services/user/src/services/user.service.js +130 -0
- package/bootstrap/services/user/src/tests/user.test.js +126 -0
- package/package.json +3 -7
- package/src/agent/agent.client.js +28 -0
- package/src/agent/commands.js +48 -0
- package/src/cli.js +30 -0
- package/src/config.js +8 -0
- package/src/control/commands.js +156 -0
- package/src/control/control.client.js +127 -0
- package/src/dev/commands.js +71 -0
- package/src/dev/dev.service.js +320 -0
- package/src/engine/infra.js +142 -0
- package/src/helpers/helpers.js +63 -0
- package/src/profiles/command.js +170 -0
- package/src/profiles/profiles.client.js +101 -0
- package/src/scaffolder/commands.js +123 -0
- package/src/scaffolder/scaffolder.handler.js +252 -0
- package/src/services/client.js +174 -0
- package/templates/service/Dockerfile.hbs +20 -0
- package/templates/service/app.js.hbs +38 -0
- package/templates/service/commands/{{serviceName}}.handler.js.hbs +97 -0
- package/templates/service/config.js.hbs +48 -0
- package/templates/service/controllers/http.controller.js.hbs +87 -0
- package/templates/service/controllers/message.controller.js.hbs +51 -0
- package/templates/service/db/migrations/01-init.js.hbs +50 -0
- package/templates/service/db/migrations/02-{{lowerCase serviceName}}-service-init.js.hbs +23 -0
- package/templates/service/package.json.hbs +18 -0
- package/templates/service/policies/{{serviceName}}.policy.js.hbs +49 -0
- package/templates/service/schema/{{serviceName}}.schema.js.hbs +14 -0
- package/templates/service/services/{{serviceName}}.service.js.hbs +32 -0
- package/dist/cli.js +0 -18
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { db, logger, utils } from '@gnar-engine/core';
|
|
2
|
+
import { config } from '../config.js';
|
|
3
|
+
import { chatGptAgent } from '../services/chatgpt.service.js';
|
|
4
|
+
|
|
5
|
+
export const Agent = {
|
|
6
|
+
|
|
7
|
+
client: {},
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Initialise LLM agent
|
|
11
|
+
*
|
|
12
|
+
* @returns {string} response
|
|
13
|
+
*/
|
|
14
|
+
init: async function () {
|
|
15
|
+
switch (config.agent) {
|
|
16
|
+
case 'chatgpt':
|
|
17
|
+
this.client = await chatGptAgent.init()
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Plan prompt preparation
|
|
24
|
+
*
|
|
25
|
+
* @param {*} inputText
|
|
26
|
+
* @returns {string} preparedPlanInput
|
|
27
|
+
*/
|
|
28
|
+
prepareGatherFactsPrompt: function ({inputText, manifests}) {
|
|
29
|
+
const commandLists = [];
|
|
30
|
+
const schemaLists = [];
|
|
31
|
+
|
|
32
|
+
manifests.manifests.forEach((manifest) => {
|
|
33
|
+
if (manifest.manifest.commandList?.[0] && manifest.manifest.commandList[0].includes('agentService')) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
commandLists.push(manifest.manifest.commandList);
|
|
38
|
+
schemaLists.push(manifest.manifest.schemas);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const preparedPlanInput = JSON.stringify({
|
|
42
|
+
clientPrompt: inputText,
|
|
43
|
+
systemInstructions: "Respond to the clientPrompt in the format of the responseStructure JSON. Your sole aim is to confirm (using the commandsRequired response property) which commands described in the manifest you will need more information on (command signature), in order to be able to invoke the commands to fulfill the request provided in the clientPrompt. Simillarly, please ensure that you request all required information as per the schema manifest from the user in the responseText. If there aren't suitable commands, explain that you can't with no further options. If it is not yet clear, please request clarification. The responseText will be shown to the customer so ensure that responses are non-technical and don't go into detail about the rest of the response.",
|
|
44
|
+
responseStructure: {
|
|
45
|
+
responseText: "Customer facing message reply here",
|
|
46
|
+
commandsRequired: [
|
|
47
|
+
'e.g. userService.create',
|
|
48
|
+
'userService.update'
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
commandManifest: commandLists,
|
|
52
|
+
schemaManifest: schemaLists
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
logger.info(preparedPlanInput);
|
|
56
|
+
|
|
57
|
+
return preparedPlanInput;
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Plan prompt preparation
|
|
62
|
+
*
|
|
63
|
+
* @param {*} inputText
|
|
64
|
+
* @returns {string} preparedPlanInput
|
|
65
|
+
*/
|
|
66
|
+
preparePlanPrompt: function ({inputText, manifests}) {
|
|
67
|
+
const commandLists = [];
|
|
68
|
+
const schemaLists = [];
|
|
69
|
+
|
|
70
|
+
manifests.manifests.forEach((manifest) => {
|
|
71
|
+
if (manifest.manifest.commandList?.[0] && manifest.manifest.commandList[0].includes('agentService')) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
commandLists.push(manifest.manifest.commandList);
|
|
76
|
+
schemaLists.push(manifest.manifest.schema);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const preparedPlanInput = JSON.stringify({
|
|
80
|
+
clientPrompt: inputText,
|
|
81
|
+
systemInstructions: "Respond to the clientPrompt in the format of the responseStructure JSON. Your sole aim is to confirm using the commandsRequired response property, which commands described in the manifest you will need more information, in order to be able to invoke the commands to fulfill the request provided in the clientPrompt. If there aren't suitable commands, explain that you can't with no further options. If it is not yet clear, please request clarification. The responseText will be shown to the customer so ensure that responses are non-technical and don't go into detail about the rest of the response.",
|
|
82
|
+
responseStructure: {
|
|
83
|
+
responseText: "Customer facing message reply here",
|
|
84
|
+
actionPlan: [
|
|
85
|
+
{
|
|
86
|
+
planDesc: "Fetch the user ID using the email address provided",
|
|
87
|
+
commandName: "userService.getSingle"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
planDesc: "update the users first name as requested",
|
|
91
|
+
commandName: "userService.update"
|
|
92
|
+
}
|
|
93
|
+
],
|
|
94
|
+
commandsRequired: [
|
|
95
|
+
'e.g. userService.create',
|
|
96
|
+
'userService.update'
|
|
97
|
+
]
|
|
98
|
+
},
|
|
99
|
+
commandManifest: commandLists,
|
|
100
|
+
schemaManifest: schemaLists
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
logger.info(preparedPlanInput);
|
|
104
|
+
|
|
105
|
+
return preparedPlanInput;
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Action plan step prompt preparation
|
|
111
|
+
*
|
|
112
|
+
* @param {*} inputText
|
|
113
|
+
* @returns {string} preparedActionPlanStepPrompt
|
|
114
|
+
*/
|
|
115
|
+
preparedActionPlanStepPrompt: function ({actionPlanStepDesc, manifest}) {
|
|
116
|
+
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Prompt augmentation for the agent
|
|
121
|
+
*
|
|
122
|
+
* @param {*} inputText
|
|
123
|
+
* @returns {string} preparedInput
|
|
124
|
+
*/
|
|
125
|
+
preparePrompt: function ({inputText}) {
|
|
126
|
+
const preparedInput = JSON.stringify({
|
|
127
|
+
clientPrompt: inputText,
|
|
128
|
+
systemInstructions: "Respond to the clientPrompt in the the format of the responseStructure JSON. If there is an appropriate flow of actions to take based on the actions described in the registeredServices you should respond with a command otherwise don't. You should always include a customer facing message requesting clarifications or the action taken.",
|
|
129
|
+
responseStructure: {
|
|
130
|
+
responseText: "Your message here",
|
|
131
|
+
action: {
|
|
132
|
+
commandName: "e.g. userService.update",
|
|
133
|
+
payload: {
|
|
134
|
+
userId: "12345",
|
|
135
|
+
data: {}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
registeredServices: [
|
|
140
|
+
{
|
|
141
|
+
serviceName: "userService",
|
|
142
|
+
actions: [
|
|
143
|
+
{
|
|
144
|
+
name: "update",
|
|
145
|
+
description: "Update user information",
|
|
146
|
+
parameters: {
|
|
147
|
+
userId: "string",
|
|
148
|
+
data: "object"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
]
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
return preparedInput;
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Create a new chat session
|
|
161
|
+
*
|
|
162
|
+
* @param {string} userId
|
|
163
|
+
* @param {string} title
|
|
164
|
+
* @param {string} sessionKey
|
|
165
|
+
* @returns {string} chatId
|
|
166
|
+
*/
|
|
167
|
+
createChat: async function ({userId, title, sessionKey}) {
|
|
168
|
+
const chatId = utils.uuid();
|
|
169
|
+
|
|
170
|
+
await db.query(
|
|
171
|
+
'INSERT INTO agent_chats (id, user_id, title) VALUES (?, ?, ?)',
|
|
172
|
+
[chatId, userId, title]
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
return chatId;
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Get a chat (with all messages)
|
|
180
|
+
*
|
|
181
|
+
* @param {string} chatId
|
|
182
|
+
* @returns {object} chat
|
|
183
|
+
*/
|
|
184
|
+
getChat: async function ({chatId}) {
|
|
185
|
+
try {
|
|
186
|
+
// Fetch the chat
|
|
187
|
+
const chatResult = await db.query(
|
|
188
|
+
'SELECT * FROM agent_chats WHERE id = ?',
|
|
189
|
+
[chatId]
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
if (!chatResult || chatResult.length === 0) {
|
|
193
|
+
throw new Error(`Chat with ID ${chatId} not found`);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const chat = chatResult[0][0];
|
|
197
|
+
|
|
198
|
+
// Fetch messages for the chat
|
|
199
|
+
const chatMessageResult = await db.query(
|
|
200
|
+
'SELECT id, chat_id, user_name, context, created_at FROM agent_chat_messages WHERE chat_id = ? ORDER BY created_at ASC',
|
|
201
|
+
[chatId]
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
if (!chatMessageResult || chatMessageResult.length === 0) {
|
|
205
|
+
throw new Error('No chat messages found');
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
chat.messages = chatMessageResult[0];
|
|
209
|
+
|
|
210
|
+
return chat;
|
|
211
|
+
} catch (err) {
|
|
212
|
+
logger.error(`Error fetching chat ${chatId}: ${err.message}`);
|
|
213
|
+
throw err;
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Create a new chat message
|
|
219
|
+
*
|
|
220
|
+
* @param {string} chatId
|
|
221
|
+
* @param {string} userName
|
|
222
|
+
* @param {object} context
|
|
223
|
+
*/
|
|
224
|
+
createChatMessage: async function ({chatId, userName, context}) {
|
|
225
|
+
try {
|
|
226
|
+
const messageId = utils.uuid();
|
|
227
|
+
context = JSON.stringify(context);
|
|
228
|
+
|
|
229
|
+
logger.info('storing context: ' + context);
|
|
230
|
+
|
|
231
|
+
await db.query(
|
|
232
|
+
'INSERT INTO agent_chat_messages (id, chat_id, user_name, context) VALUES (?, ?, ?, ?)',
|
|
233
|
+
[messageId, chatId, userName, context]
|
|
234
|
+
);
|
|
235
|
+
} catch (err) {
|
|
236
|
+
logger.error('Error creating chat message: ' + err.message);
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Infer LLM agent
|
|
242
|
+
*
|
|
243
|
+
* @param {string} preparedInput
|
|
244
|
+
* @returns {string} response
|
|
245
|
+
*/
|
|
246
|
+
infer: async function ({preparedInput}) {
|
|
247
|
+
|
|
248
|
+
let response;
|
|
249
|
+
|
|
250
|
+
switch (config.agent) {
|
|
251
|
+
case 'chatgpt':
|
|
252
|
+
response = await chatGptAgent.getResponse(preparedInput)
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return response;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
import { logger } from "@gnar-engine/core";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export const chatGptAgent = {
|
|
6
|
+
|
|
7
|
+
client: null,
|
|
8
|
+
|
|
9
|
+
init: function () {
|
|
10
|
+
if (this.client) {
|
|
11
|
+
return this.client;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return this.client = new OpenAI({
|
|
15
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
16
|
+
baseURL: process.env.OPENAI_API_BASE_URL || 'https://api.openai.com/v1',
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
getResponse: async function (preparedInput) {
|
|
21
|
+
try {
|
|
22
|
+
logger.info('LLM request sending...');
|
|
23
|
+
const response = await this.client.chat.completions.create({
|
|
24
|
+
model: "gpt-5-mini",
|
|
25
|
+
messages: [
|
|
26
|
+
{
|
|
27
|
+
role: "user",
|
|
28
|
+
content: [
|
|
29
|
+
{
|
|
30
|
+
type: "text",
|
|
31
|
+
text: preparedInput
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
logger.info('LLM response returned');
|
|
39
|
+
|
|
40
|
+
return response.choices[0].message.content;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
logger.error("ChatGPT agent error:" + error);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { commands, logger } from '@gnar-engine/core';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const manifestService = {
|
|
5
|
+
|
|
6
|
+
commandList: {},
|
|
7
|
+
schemaList: {},
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Generate service manifests
|
|
11
|
+
*/
|
|
12
|
+
generateServiceManifests: async () => {
|
|
13
|
+
logger.info('Generating command manifest...');
|
|
14
|
+
|
|
15
|
+
// Get services from control service
|
|
16
|
+
const manifests = await commands.execute('controlService.getManifests');
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Dockerfile for Control Service
|
|
2
|
+
FROM node:20-alpine
|
|
3
|
+
|
|
4
|
+
# Set the working directory
|
|
5
|
+
WORKDIR /usr/gnar_engine/app
|
|
6
|
+
|
|
7
|
+
# Define a global env var
|
|
8
|
+
ENV GLOBAL_SERVICE_BASE_DIR=/usr/gnar_engine/app/src/
|
|
9
|
+
|
|
10
|
+
# Copy package.json and package-lock.json
|
|
11
|
+
COPY ./services/control/package*.json ./
|
|
12
|
+
|
|
13
|
+
# Install nodemon
|
|
14
|
+
RUN npm install -g nodemon
|
|
15
|
+
|
|
16
|
+
# Install app dependencies
|
|
17
|
+
RUN npm install
|
|
18
|
+
|
|
19
|
+
# Expose the port the service will run on
|
|
20
|
+
EXPOSE 3000
|
|
21
|
+
|
|
22
|
+
# Start the application
|
|
23
|
+
CMD ["nodemon", "--watch", "./gnar_engine", "./gnar_engine/app.js"]
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Stage 1: Builder
|
|
2
|
+
FROM node:20-alpine AS builder
|
|
3
|
+
|
|
4
|
+
WORKDIR /app
|
|
5
|
+
|
|
6
|
+
# Copy app source
|
|
7
|
+
COPY ./services/control/src ./src
|
|
8
|
+
COPY ./Lib ./Lib
|
|
9
|
+
|
|
10
|
+
# Copy environment variables (do this later in build only if needed)
|
|
11
|
+
COPY ./.env.production .env
|
|
12
|
+
|
|
13
|
+
# Copy package files and install deps
|
|
14
|
+
COPY ./services/control/package*.json ./
|
|
15
|
+
RUN npm install --omit=dev
|
|
16
|
+
|
|
17
|
+
# Stage 2: Runtime
|
|
18
|
+
FROM node:20-alpine
|
|
19
|
+
|
|
20
|
+
WORKDIR /app
|
|
21
|
+
|
|
22
|
+
# Copy built app from builder stage
|
|
23
|
+
COPY --from=builder /app /app
|
|
24
|
+
|
|
25
|
+
# Install system deps
|
|
26
|
+
RUN apk add --no-cache ca-certificates wget
|
|
27
|
+
|
|
28
|
+
# Install AWS DocumentDB CA certificates
|
|
29
|
+
RUN mkdir -p /usr/local/share/ca-certificates && \
|
|
30
|
+
wget https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem -O /usr/local/share/ca-certificates/aws-docdb.pem && \
|
|
31
|
+
update-ca-certificates
|
|
32
|
+
|
|
33
|
+
# Expose port
|
|
34
|
+
EXPOSE 4000
|
|
35
|
+
|
|
36
|
+
# Start app
|
|
37
|
+
CMD ["npm", "run", "start"]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Gnar Engine Control Service
|
|
2
|
+
|
|
3
|
+
- Used for scheduling and running tasks
|
|
4
|
+
- Used for service registry
|
|
5
|
+
- Used by the CLI
|
|
6
|
+
|
|
7
|
+
### Commands
|
|
8
|
+
|
|
9
|
+
Start dev server npm start:dev
|
|
10
|
+
Start production server npm start
|
|
11
|
+
Run tests npm test
|
|
12
|
+
|
|
13
|
+
### notes
|
|
14
|
+
|
|
15
|
+
Cron job runs:
|
|
16
|
+
|
|
17
|
+
Fetch due tasks from SQL (status = pending).
|
|
18
|
+
Push them to RabbitMQ.
|
|
19
|
+
Update the database status to queued.
|
|
20
|
+
Worker service processes tasks:
|
|
21
|
+
|
|
22
|
+
Listens for tasks in RabbitMQ.
|
|
23
|
+
Executes the task (e.g., calling another microservice).
|
|
24
|
+
On success, updates SQL status to completed.
|
|
25
|
+
On failure, updates SQL status to failed and may retry.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gnar_engine_control",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Gnar Engine - Control Service",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "node ./src/app.js",
|
|
8
|
+
"start:dev": "nodemon --watch ./src ./src/app.js",
|
|
9
|
+
"test": "jest --watchAll --verbose"
|
|
10
|
+
},
|
|
11
|
+
"author": "Gnar Software Ltd",
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@gnar-engine/core": "^1.0.1"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { message, http, logger, db, registerService, webSockets } from '@gnar-engine/core';
|
|
2
|
+
import { config } from './config.js';
|
|
3
|
+
import { messageHandlers } from './controllers/message.controller.js';
|
|
4
|
+
import { httpController as controlPlatformHttpController } from './controllers/http.controller.js';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Initialise service
|
|
9
|
+
*/
|
|
10
|
+
export const initService = async () => {
|
|
11
|
+
|
|
12
|
+
// Run migrations
|
|
13
|
+
db.migrations.runMigrations({config});
|
|
14
|
+
|
|
15
|
+
// Import command handlers after the command bus is initialised
|
|
16
|
+
await import('./commands/control.handler.js');
|
|
17
|
+
await import('./commands/service.handler.js');
|
|
18
|
+
await import('./commands/task.handler.js');
|
|
19
|
+
|
|
20
|
+
// Initialise and register message handlers
|
|
21
|
+
await message.init({
|
|
22
|
+
config: config.message,
|
|
23
|
+
handlers: messageHandlers
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Initialise websocket client & server
|
|
27
|
+
await webSockets.init(config.webSockets, config.serviceName);
|
|
28
|
+
|
|
29
|
+
// Register http routes
|
|
30
|
+
await http.registerRoutes({
|
|
31
|
+
controllers: [
|
|
32
|
+
controlPlatformHttpController,
|
|
33
|
+
]
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Start the HTTP server
|
|
37
|
+
await http.start();
|
|
38
|
+
|
|
39
|
+
// Register service with control service
|
|
40
|
+
await registerService();
|
|
41
|
+
|
|
42
|
+
logger.info('G n a r E n g i n e | Control Service initialised successfully.');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
initService();
|