@kumologica/sdk 4.0.0-beta1 → 4.0.0-beta10
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/LICENSE +170 -0
- package/cli/commands/export-commands/cloudformation.js +1 -1
- package/cli/commands/license-commands/request.js +37 -0
- package/cli/commands/license-commands/save.js +19 -18
- package/cli/commands/open.js +12 -0
- package/cli/commands/run.js +68 -29
- package/cli/commands/test.js +1 -1
- package/cli/utils/license.js +111 -0
- package/package.json +12 -9
- package/src/app/lib/ai/chatai.js +179 -0
- package/src/app/lib/aws/index.js +9 -3
- package/src/app/lib/serverless/index.js +1 -1
- package/src/app/lib/stores/settings-ai-store.js +266 -0
- package/src/app/lib/utils/tools.min.js +1 -1
- package/src/app/preload.js +12 -4
- package/src/app/ui/editor-client/public/red/red.js +850 -216
- package/src/app/ui/editor-client/public/red/red.min.js +2 -2
- package/src/app/ui/editor-client/public/red/style.min.css +1 -1
- package/src/app/ui/editor-client/src/js/red.js +1 -0
- package/src/app/ui/editor-client/src/js/ui/aitab.js +90 -0
- package/src/app/ui/editor-client/src/js/ui/editor.js +115 -1
- package/src/app/ui/editor-client/src/js/ui/palette-aiassistant.js +553 -0
- package/src/app/ui/editor-client/src/js/ui/palette.js +120 -0
- package/src/app/ui/editor-client/src/js/ui/tray.js +10 -0
- package/src/app/ui/editor-client/src/js/ui/ui-settings.js +50 -5
- package/src/app/ui/editor-client/src/sass/palette.scss +89 -4
- package/src/app/ui/editor-client/src/sass/ui-settings.scss +11 -0
- package/src/app/ui/editor-client/templates/index.mst +107 -60
- package/src/server/DesignerServer.js +30 -3
- package/src/server/TaskServer.js +68 -0
- package/cli/commands/license-commands/license.js +0 -115
- package/cli/utils/fs/create-zip-file.js +0 -39
- package/src/app/ui/editor-client/src/js/ui/tab-ai.js +0 -210
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
const got = require('got');
|
|
2
|
+
const { fromIni } = require('@aws-sdk/credential-providers');
|
|
3
|
+
const { SignatureV4 } = require('@aws-sdk/signature-v4');
|
|
4
|
+
const { Sha256 } = require('@aws-crypto/sha256-js');
|
|
5
|
+
const { defaultProvider } = require('@aws-sdk/credential-providers');
|
|
6
|
+
|
|
7
|
+
const PROVIDER_CONFIG = {
|
|
8
|
+
openai: { baseUrl: 'https://api.openai.com/v1', headers: {} },
|
|
9
|
+
deepseek: { baseUrl: 'https://api.deepseek.com/v1', headers: {} },
|
|
10
|
+
xai: { baseUrl: 'https://api.x.ai/v1', headers: {} },
|
|
11
|
+
anthropic: { baseUrl: 'https://api.anthropic.com/v1', headers: { 'anthropic-version': '2023-06-01' } },
|
|
12
|
+
gemini: { baseUrl: 'https://generativelanguage.googleapis.com/v1beta', headers: {} },
|
|
13
|
+
bedrock: { type: 'bedrock-http' },
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
let signerCache = null; // Cache signer per region/profile to avoid recreating
|
|
17
|
+
|
|
18
|
+
async function getSigner({ region, profile }) {
|
|
19
|
+
const cacheKey = `${region || 'default'}:${profile || 'default'}`;
|
|
20
|
+
if (signerCache && signerCache.key === cacheKey) return signerCache.signer;
|
|
21
|
+
|
|
22
|
+
const credentials = profile ? fromIni({ profile }) : defaultProvider();
|
|
23
|
+
|
|
24
|
+
const signer = new SignatureV4({
|
|
25
|
+
credentials,
|
|
26
|
+
region: region || 'us-east-1',
|
|
27
|
+
service: 'bedrock',
|
|
28
|
+
sha256: Sha256,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
signerCache = { key: cacheKey, signer };
|
|
32
|
+
return signer;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Unified chat — Bedrock now uses 100% public AWS SDK v3 SigV4
|
|
37
|
+
*/
|
|
38
|
+
async function chatAi({
|
|
39
|
+
provider,
|
|
40
|
+
model,
|
|
41
|
+
apiKey,
|
|
42
|
+
region = process.env.AWS_REGION || 'us-east-1',
|
|
43
|
+
profile, // ← optional AWS profile name
|
|
44
|
+
messages,
|
|
45
|
+
systemPrompt,
|
|
46
|
+
params = {}
|
|
47
|
+
}) {
|
|
48
|
+
const { temperature = 0.7, maxTokens = 4096, timeout = 60000 } = params;
|
|
49
|
+
provider = provider.toLowerCase();
|
|
50
|
+
|
|
51
|
+
let url, headers = { 'Content-Type': 'application/json' }, body;
|
|
52
|
+
|
|
53
|
+
// ========================================
|
|
54
|
+
// BEDROCK — pure HTTP + official SigV4
|
|
55
|
+
// ========================================
|
|
56
|
+
if (provider === 'bedrock') {
|
|
57
|
+
const signer = await getSigner({ region, profile });
|
|
58
|
+
|
|
59
|
+
url = `https://bedrock-runtime.${region}.amazonaws.com/model/${model}/converse`;
|
|
60
|
+
|
|
61
|
+
const messagesNoSystem = messages.filter(m => m.role !== 'system');
|
|
62
|
+
const converseMessages = messagesNoSystem.map(m => ({
|
|
63
|
+
role: m.role === 'assistant' ? 'assistant' : 'user',
|
|
64
|
+
content: [{ text: m.content }]
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
body = {
|
|
68
|
+
messages: converseMessages,
|
|
69
|
+
system: systemPrompt ? [{'text': systemPrompt}] : undefined,
|
|
70
|
+
inferenceConfig: { maxTokens, temperature },
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const request = {
|
|
74
|
+
method: 'POST',
|
|
75
|
+
protocol: 'https:',
|
|
76
|
+
hostname: `bedrock-runtime.${region}.amazonaws.com`,
|
|
77
|
+
path: `/model/${model}/converse`,
|
|
78
|
+
headers: {
|
|
79
|
+
'Host': `bedrock-runtime.${region}.amazonaws.com`,
|
|
80
|
+
'Accept': 'application/json',
|
|
81
|
+
'Content-Type': 'application/json',
|
|
82
|
+
},
|
|
83
|
+
body: JSON.stringify(body),
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// Sign the request
|
|
87
|
+
const signed = await signer.sign(request);
|
|
88
|
+
|
|
89
|
+
headers = signed.headers;
|
|
90
|
+
url = `https://${signed.hostname}${signed.path}`;
|
|
91
|
+
}
|
|
92
|
+
// ========================================
|
|
93
|
+
// ALL OTHER PROVIDERS (unchanged)
|
|
94
|
+
// ========================================
|
|
95
|
+
else {
|
|
96
|
+
const config = PROVIDER_CONFIG[provider];
|
|
97
|
+
if (!config) throw new Error(`Unsupported provider: ${provider}`);
|
|
98
|
+
|
|
99
|
+
headers = { 'Content-Type': 'application/json', ...config.headers };
|
|
100
|
+
|
|
101
|
+
if (provider === 'gemini') {
|
|
102
|
+
// key in URL
|
|
103
|
+
} else if (provider === 'anthropic') {
|
|
104
|
+
headers['x-api-key'] = apiKey;
|
|
105
|
+
} else {
|
|
106
|
+
headers.Authorization = `Bearer ${apiKey}`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
let finalMessages = messages;
|
|
110
|
+
if (systemPrompt) {
|
|
111
|
+
finalMessages = provider === 'gemini'
|
|
112
|
+
? [{ role: 'user', content: systemPrompt }, ...messages]
|
|
113
|
+
: [{ role: 'system', content: systemPrompt }, ...messages];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (provider === 'anthropic') {
|
|
117
|
+
url = `${config.baseUrl}/messages`;
|
|
118
|
+
body = {
|
|
119
|
+
model,
|
|
120
|
+
messages: finalMessages.filter(m => m.role !== 'system'),
|
|
121
|
+
system: systemPrompt || undefined,
|
|
122
|
+
max_tokens: maxTokens,
|
|
123
|
+
temperature,
|
|
124
|
+
};
|
|
125
|
+
} else if (provider === 'gemini') {
|
|
126
|
+
url = `${config.baseUrl}/models/${model}:generateContent?key=${apiKey}`;
|
|
127
|
+
body = {
|
|
128
|
+
contents: finalMessages.map(m => ({
|
|
129
|
+
role: m.role === 'assistant' ? 'model' : 'user',
|
|
130
|
+
parts: [{ text: m.content }]
|
|
131
|
+
})),
|
|
132
|
+
generationConfig: { temperature, maxOutputTokens: maxTokens },
|
|
133
|
+
};
|
|
134
|
+
} else {
|
|
135
|
+
url = `${config.baseUrl}/chat/completions`;
|
|
136
|
+
body = { model, messages: finalMessages, temperature, max_tokens: maxTokens };
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ========================================
|
|
141
|
+
// SEND WITH GOT
|
|
142
|
+
// ========================================
|
|
143
|
+
const response = await got.post(url, {
|
|
144
|
+
headers,
|
|
145
|
+
json: provider === 'bedrock' ? undefined : body,
|
|
146
|
+
body: provider === 'bedrock' ? JSON.stringify(body) : undefined,
|
|
147
|
+
timeout: { request: timeout },
|
|
148
|
+
responseType: 'json',
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// ========================================
|
|
152
|
+
// PARSE RESPONSE
|
|
153
|
+
// ========================================
|
|
154
|
+
if (provider === 'bedrock') {
|
|
155
|
+
const data = response.body;
|
|
156
|
+
const text = data.output?.message?.content?.[0]?.text || '';
|
|
157
|
+
return {
|
|
158
|
+
content: text,
|
|
159
|
+
usage: data.usage,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (provider === 'anthropic') {
|
|
164
|
+
return { content: response.body.content?.[0]?.text || '', usage: response.body.usage };
|
|
165
|
+
}
|
|
166
|
+
if (provider === 'gemini') {
|
|
167
|
+
const c = response.body.candidates?.[0];
|
|
168
|
+
if (!c?.content?.parts?.[0]?.text) throw new Error('Empty response from Gemini');
|
|
169
|
+
return { content: c.content.parts[0].text };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const choice = response.body.choices?.[0];
|
|
173
|
+
return {
|
|
174
|
+
content: choice?.message?.content || '',
|
|
175
|
+
usage: response.body.usage,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
module.exports = { chatAi };
|
package/src/app/lib/aws/index.js
CHANGED
|
@@ -511,7 +511,10 @@ if (s.cwevents && s.cwevents.length > 0) {
|
|
|
511
511
|
settings.flowName
|
|
512
512
|
);
|
|
513
513
|
|
|
514
|
-
|
|
514
|
+
if (!params.environment.some(e => e.key === "KUMOLOGICA_LICENSE")) {
|
|
515
|
+
params.environment.push({ key: "KUMOLOGICA_LICENSE", value: process.env.KUMOLOGICA_LICENSE });
|
|
516
|
+
}
|
|
517
|
+
|
|
515
518
|
const args = this.mapParams(params);
|
|
516
519
|
args.region = this.region;
|
|
517
520
|
args["bucket-name"] = settings.deploymentBucketName;
|
|
@@ -519,7 +522,6 @@ if (s.cwevents && s.cwevents.length > 0) {
|
|
|
519
522
|
args["flow-file-name"] = projectInfo.projectFlowName;
|
|
520
523
|
args["zip-file-name"] = settings.zipFileName;
|
|
521
524
|
|
|
522
|
-
console.log(`args: ${JSON.stringify(args)}`);
|
|
523
525
|
const scriptFileName = exp("cloudformation", "aws", args);
|
|
524
526
|
|
|
525
527
|
this.log(`Cloudformation script has been created: ${scriptFileName}`);
|
|
@@ -562,6 +564,10 @@ if (s.cwevents && s.cwevents.length > 0) {
|
|
|
562
564
|
Body: body
|
|
563
565
|
});
|
|
564
566
|
|
|
567
|
+
if (!params.environment.some(e => e.key === "KUMOLOGICA_LICENSE")) {
|
|
568
|
+
params.environment.push({ key: "KUMOLOGICA_LICENSE", value: process.env.KUMOLOGICA_LICENSE });
|
|
569
|
+
}
|
|
570
|
+
|
|
565
571
|
const args = this.mapParams(params);
|
|
566
572
|
args.region = this.region;
|
|
567
573
|
args["bucket-name"] = settings.deploymentBucketName;
|
|
@@ -569,7 +575,7 @@ if (s.cwevents && s.cwevents.length > 0) {
|
|
|
569
575
|
args["flow-file-name"] = projectInfo.projectFlowName;
|
|
570
576
|
args["zip-file-name"] = settings.zipFileName;
|
|
571
577
|
args.skipPrepare = "true"; // no need for cloudformation prepare
|
|
572
|
-
|
|
578
|
+
|
|
573
579
|
const scriptFileName = exp("cloudformation", "aws", args);
|
|
574
580
|
|
|
575
581
|
const lambdaCfTemplate = this.loadJsonFile(scriptFileName);
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
// properties: ~/.kumologica/credentials
|
|
2
|
+
|
|
3
|
+
const defaultContent = `; This file contains all your sensitive credential information
|
|
4
|
+
; about your ai configuration used by Kumologica Designer.
|
|
5
|
+
; For more information visit https://docs.kumologica.com/settings
|
|
6
|
+
;
|
|
7
|
+
; supported providers: openai, anthropic, deepseek, xai, gemini, aws bedrock
|
|
8
|
+
;
|
|
9
|
+
; Examples:
|
|
10
|
+
;
|
|
11
|
+
; =============== Anthropic =======================
|
|
12
|
+
; [anthropic-haiku]
|
|
13
|
+
; provider = anthropic
|
|
14
|
+
; model = claude-haiku-4-5
|
|
15
|
+
; api_key = your-anthropic-api-key
|
|
16
|
+
; max_tokens = 4096
|
|
17
|
+
; temperature = 0.7
|
|
18
|
+
|
|
19
|
+
; ============= OpenAI =======================
|
|
20
|
+
; [openai-gpt4o]
|
|
21
|
+
; provider = openai
|
|
22
|
+
; model = gpt-4o
|
|
23
|
+
; api_key = your-openai-api-key
|
|
24
|
+
; max_tokens = 8192
|
|
25
|
+
; temperature = 0.7
|
|
26
|
+
|
|
27
|
+
; ============= AWS Bedrock =======================
|
|
28
|
+
; [aws bedrock claude 3.5 sonnet]
|
|
29
|
+
; provider = bedrock
|
|
30
|
+
; model=anthropic.claude-3-5-sonnet-20241022-v2:0
|
|
31
|
+
; region=ap-southeast-2
|
|
32
|
+
; ; your local AWS profile name, if not provided the default profile will be used
|
|
33
|
+
; profile=bedrock
|
|
34
|
+
; max_tokens = 8192
|
|
35
|
+
; temperature = 0.7
|
|
36
|
+
`
|
|
37
|
+
|
|
38
|
+
const os = require('os');
|
|
39
|
+
const fs = require('fs');
|
|
40
|
+
const fsx = require('fs-extra')
|
|
41
|
+
const ini = require('ini');
|
|
42
|
+
const path = require('path');
|
|
43
|
+
const got = require('got');
|
|
44
|
+
|
|
45
|
+
const PROMPT_URL = 'https://kumologica.com/ai/kumologica-prompt.md';
|
|
46
|
+
const FILENAME_PREFIX = 'kumologica-prompt';
|
|
47
|
+
const CHAT_HISTORY_FILENAME = 'kumologica-chat-history.json';
|
|
48
|
+
const FILE_EXTENSION = '.md';
|
|
49
|
+
const MAX_AGE_DAYS = 7;
|
|
50
|
+
|
|
51
|
+
const emptyHistory =
|
|
52
|
+
[
|
|
53
|
+
{
|
|
54
|
+
timestamp: 'latest',
|
|
55
|
+
title: 'Latest Chat',
|
|
56
|
+
messages: []
|
|
57
|
+
}
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
class AiConfigStore {
|
|
61
|
+
// aiConfigFileFullPath: a string representing the full path of the ai config file
|
|
62
|
+
|
|
63
|
+
constructor() {
|
|
64
|
+
let homedir = os.homedir();
|
|
65
|
+
const credsDir = '.kumologica';
|
|
66
|
+
const credsFile = `ai`;
|
|
67
|
+
|
|
68
|
+
this.aiConfigFileFullPath = path.join(homedir, credsDir, credsFile);
|
|
69
|
+
this.chatHistoryFileFullPath = path.join(homedir, credsDir, CHAT_HISTORY_FILENAME);
|
|
70
|
+
|
|
71
|
+
this.promptDirectory = path.join(homedir, credsDir);
|
|
72
|
+
|
|
73
|
+
// check whether the config file exist or not: ~/.kumologica/ai
|
|
74
|
+
if (!fs.existsSync(this.aiConfigFileFullPath)){
|
|
75
|
+
// create file and write default content on it
|
|
76
|
+
console.log(`Creating AI config file on: ${this.aiConfigFileFullPath}...`)
|
|
77
|
+
fsx.ensureDirSync(path.join(homedir, credsDir));
|
|
78
|
+
fs.writeFileSync(this.aiConfigFileFullPath, defaultContent);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// check whether the chat history file exist or not: ~/.kumologica/ai
|
|
82
|
+
if (!fs.existsSync(this.chatHistoryFileFullPath)){
|
|
83
|
+
// create file and write default content on it
|
|
84
|
+
console.log(`Creating AI chat history file on: ${this.chatHistoryFileFullPath}...`)
|
|
85
|
+
fsx.ensureDirSync(path.join(homedir, credsDir));
|
|
86
|
+
fs.writeFileSync(this.chatHistoryFileFullPath, JSON.stringify(emptyHistory));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
this.initFile = this.parseAiConfigFile();
|
|
90
|
+
this.syncPrompt();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
deleteOldFiles(files) {
|
|
94
|
+
for (const f of files) {
|
|
95
|
+
try {
|
|
96
|
+
fs.unlinkSync(f.fullPath);
|
|
97
|
+
console.debug(`Deleted old: ${f.name}`);
|
|
98
|
+
} catch {}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
getPromptFiles() {
|
|
103
|
+
try {
|
|
104
|
+
return fs.readdirSync(this.promptDirectory)
|
|
105
|
+
.filter(f => f.startsWith(FILENAME_PREFIX) && f.endsWith(FILE_EXTENSION))
|
|
106
|
+
.map(f => {
|
|
107
|
+
const fullPath = path.join(this.promptDirectory, f);
|
|
108
|
+
try {
|
|
109
|
+
const stat = fs.statSync(fullPath);
|
|
110
|
+
return { name: f, fullPath, mtime: stat.mtime.getTime() };
|
|
111
|
+
} catch {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
.filter(Boolean)
|
|
116
|
+
.sort((a, b) => b.mtime - a.mtime); // newest first
|
|
117
|
+
} catch {
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
getPrompt() {
|
|
123
|
+
if (this.prompt) {
|
|
124
|
+
return this.prompt;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const newest = this.getPromptFiles()[0];
|
|
128
|
+
if (!newest) return null;
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
this.prompt = fs.readFileSync(newest.fullPath, 'utf-8').trim();
|
|
132
|
+
return this.prompt;
|
|
133
|
+
} catch (err) {
|
|
134
|
+
console.error('Failed to read prompt file:', err.message);
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async syncPrompt() {
|
|
140
|
+
const files = this.getPromptFiles();
|
|
141
|
+
const newest = files[0] || null;
|
|
142
|
+
|
|
143
|
+
const isRecent = newest && (Date.now() - newest.mtime) <= MAX_AGE_DAYS * 24 * 60 * 60 * 1000;
|
|
144
|
+
|
|
145
|
+
if (isRecent) {
|
|
146
|
+
// Still fresh → just clean up any old junk and exit
|
|
147
|
+
this.deleteOldFiles(files.slice(1));
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Need fresh copy
|
|
152
|
+
const filename = `${FILENAME_PREFIX}-${new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19)}${FILE_EXTENSION}`;
|
|
153
|
+
const filepath = path.join(this.promptDirectory, filename);
|
|
154
|
+
|
|
155
|
+
try {
|
|
156
|
+
console.log('Downloading latest prompt...');
|
|
157
|
+
const { body } = await got(PROMPT_URL);
|
|
158
|
+
fs.writeFileSync(filepath, body, 'utf-8');
|
|
159
|
+
console.log(`Saved: ${filename}`);
|
|
160
|
+
|
|
161
|
+
// Delete everything except the new file
|
|
162
|
+
this.deleteOldFiles(files);
|
|
163
|
+
} catch (err) {
|
|
164
|
+
try { fs.unlinkSync(filepath); } catch {}
|
|
165
|
+
throw new Error(`Download failed: ${err.message}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
getSections() {
|
|
170
|
+
return Object.keys(this.initFile).filter(key => key !== '');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
parseAiConfigFile() {
|
|
174
|
+
this.initFile = ini.parse(this.readAiConfigFile());
|
|
175
|
+
return this.initFile;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
getAliases(section){
|
|
179
|
+
if (this.initFile && this.initFile[section]){
|
|
180
|
+
return Object.keys(this.initFile[section]);
|
|
181
|
+
}else{
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
getAliasInfo(section, alias) {
|
|
187
|
+
if (this.initFile && this.initFile[section]){
|
|
188
|
+
return this.initFile[section][alias];
|
|
189
|
+
}else{
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
getAiConfigFileFullPath() {
|
|
195
|
+
return this.aiConfigFileFullPath;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
writeAiConfigFile(content) {
|
|
199
|
+
this.initFile = ini.parse(content);
|
|
200
|
+
fs.writeFileSync(this.aiConfigFileFullPath, content);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
readAiConfigFile() {
|
|
204
|
+
const data = fs.readFileSync(this.aiConfigFileFullPath, "utf-8");
|
|
205
|
+
const lines = data.split(/\r\n|\n/);
|
|
206
|
+
|
|
207
|
+
return lines.map(l => l.trim()).join('\n');
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// history management methods
|
|
211
|
+
//
|
|
212
|
+
// the structure of chatHistory is an array of histories
|
|
213
|
+
// each history is an object of timestamp, title and array of messages
|
|
214
|
+
// the latest chat history is not timestamped but has a value of latest
|
|
215
|
+
//
|
|
216
|
+
readChatHistory() {
|
|
217
|
+
try {
|
|
218
|
+
const data = fs.readFileSync(this.chatHistoryFileFullPath, "utf-8");
|
|
219
|
+
const chatHistory = JSON.parse(data);
|
|
220
|
+
return chatHistory;
|
|
221
|
+
} catch (err) {
|
|
222
|
+
console.error('Failed to read chat history file:', err.message);
|
|
223
|
+
return emptyHistory;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
getChat(timestamp) {
|
|
228
|
+
const chatHistory = this.readChatHistory();
|
|
229
|
+
return chatHistory.find(h => h.timestamp === timestamp);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
writeChatHistoryFile(content) {
|
|
233
|
+
fs.writeFileSync(this.chatHistoryFileFullPath, content);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
updateChatHistory(timestamp, messages) {
|
|
237
|
+
let chatHistory = this.readChatHistory();
|
|
238
|
+
|
|
239
|
+
let chat = chatHistory.find(h => h.timestamp === timestamp);
|
|
240
|
+
if (chat) {
|
|
241
|
+
chat.messages = messages;
|
|
242
|
+
this.writeChatHistoryFile(JSON.stringify(chatHistory));
|
|
243
|
+
} else {
|
|
244
|
+
console.error(`Chat history with timestamp ${timestamp} not found.`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
newLatestChat() {
|
|
249
|
+
let chatHistory = this.readChatHistory() || [];
|
|
250
|
+
|
|
251
|
+
let chat = chatHistory.find(h => h.timestamp === "latest");
|
|
252
|
+
if (chat) {
|
|
253
|
+
chat.timestamp = new Date().toISOString();
|
|
254
|
+
}
|
|
255
|
+
chatHistory.push({
|
|
256
|
+
timestamp: 'latest',
|
|
257
|
+
title: 'Latest Chat',
|
|
258
|
+
messages: []
|
|
259
|
+
});
|
|
260
|
+
this.writeChatHistoryFile(JSON.stringify(chatHistory));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
module.exports = {
|
|
265
|
+
AiConfigStore
|
|
266
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
var e,o,n,t,r=require("crypto"),s=require("fs"),i=require("path");function l(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function c(){if(!o){o=1;let l="base64";e={subscribe:async function(e){console.log("Requesting license for email: "+e);var r=await fetch("https://api.infra.kumologica.com/p/signup?x-api-key=RjibYF3qZb2AzmTrPOnV35LfRV798e3Z87vp4izo",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e})});if(r.ok)return!0;{let e=await r.text();return console.error(`License request failed: ${r.status} `+e),!1}},display:function(e){e?(console.log("-------- License Details ----------"),console.log("Subscriber: "+e.sub),console.log("Email: "+e.email),console.log("License Type: "+e.licenseType),console.log("Issued For: "+(e.name||e.email)),console.log("Issued By: "+e.iss),console.log("Issued At: "+new Date(e.iat).toLocaleString()),console.log("Expiry: "+("perpetual"===e.exp?"Perpetual":new Date(e.exp).toLocaleString())),console.log("-----------------------------------")):console.error("Invalid license data.")},verify:function(e){publicKeyPem=(()=>{var o=Buffer.from("XkI1bxBWOXhHBztkdXIuEXlKLBcSIWstZlEzOEADPyFCCVkUeQNIIxwWDU4QEiEyLHpfOjwHCVNlL3tTFiIvMGkcZCkOBnNgIjtybUckA3x7BRARDElXRxECPlB4OgF4aWIRDQAGLBI2Jns3eTINDkx+XSN9bAAFDHllInIdCEg8SzICC2JJJyl4CGk5JAB/EBQcLW4+dzcuMGxhLglhbHUZF2ZwFQMJEl08cAVfWGd5ADtje34SDUJCHxUlWh83aghXDnJXXwxxCFsUNANhCzJ0MHoiVyEvLlh2OC5gf2UwdGZhDxAvMllUcCgSWl1w",l).toString().split("").reverse().join("");let t="";for(let r=0;r<o.length;r++){let e="34jfd#d-cDFG23@W096ml".charCodeAt(r%21);t+=String.fromCharCode(o.charCodeAt(r)^e)}return Buffer.from(t,l).toString()})();var o=r,[e,t]=e.split(".");if(!e||!t)throw new Error("Invalid license format. License may have been tampered.");var e=Buffer.from(e,"base64url").toString("utf-8"),n=JSON.parse(e),e=Buffer.from(e,"utf-8"),t=Buffer.from(t,l),o=o.createVerify("SHA256");if(o.update(e),o.end(),!o.verify(publicKeyPem,t))throw new Error("Invalid license signature. License may have been tampered.");if(!(n&&n.sub&&n.email&&n.iss&&n.iat))throw new Error("Invalid license data. License may have been tampered.");if(n.exp&&("Perpetual"===n.exp||Date.now()>n.exp))throw new Error("License has expired. Please renew your license, contact Kumologica support at contact@kumologica.com.");return n},save:function(e,r){var o=s,t=i,t=(console.log("saving key to: "+e),t.join(e,"kumologica.license"));try{o.writeFileSync(t,r,"utf-8"),console.log("License saved successfully at: "+t)}catch(e){console.error("Failed to save license: "+e.message)}},read:function(e){var r=s,o=i.join(e,"kumologica.license");try{let e=r.readFileSync(o,"utf-8");return console.log("License read successfully from: "+o),e}catch(e){return null}}}}return e}var a=(()=>{if(t)return n;t=1;var e=c();return n={license:e}})(),u=l(a);module.exports=u;
|
package/src/app/preload.js
CHANGED
|
@@ -35,8 +35,9 @@ const KumohubConfig = require("./lib/stores/kumohub-config-store");
|
|
|
35
35
|
const AzureConfig = require("./lib/stores/azure-config-store");
|
|
36
36
|
const ProjectInfoConfig = require("./lib/stores/project-info-config-store");
|
|
37
37
|
const { CloudConfigStore } = require("./lib/stores/settings-cloud-store");
|
|
38
|
+
const { AiConfigStore } = require("./lib/stores/settings-ai-store");
|
|
38
39
|
const { NetworkConfigStore } = require("./lib/stores/settings-network-store");
|
|
39
|
-
const {
|
|
40
|
+
const { chatAi } = require("./lib/ai/chatai");
|
|
40
41
|
|
|
41
42
|
const AWSProfile = require("./lib/aws/aws-profile");
|
|
42
43
|
const AWSDeployer = require("./lib/aws");
|
|
@@ -69,10 +70,9 @@ const KUMOLOGICA_NODE_LIB_BASEURL = "https://library.kumohub.io";
|
|
|
69
70
|
const KUMOLOGICA_NODE_LIB_URL = `${KUMOLOGICA_NODE_LIB_BASEURL}/library.json`;
|
|
70
71
|
|
|
71
72
|
const cloudConfigStore = new CloudConfigStore();
|
|
73
|
+
const aiConfigStore = new AiConfigStore();
|
|
72
74
|
const networkConfigStore = new NetworkConfigStore();
|
|
73
75
|
|
|
74
|
-
const openAIClient = new OpenAIClient({ version: "gpt-3.5-turbo" }); //'gpt-4'
|
|
75
|
-
|
|
76
76
|
// function to be called each time
|
|
77
77
|
// project changes - either new project created or old project opened.
|
|
78
78
|
// header.js is the component handling project changes.
|
|
@@ -82,6 +82,7 @@ function loadConfigs() {
|
|
|
82
82
|
window.__kumologica.settings.cloudConfig = new CloudConfig.CloudConfigStore({
|
|
83
83
|
dataPath: window.__kumologica.settings.projectDir,
|
|
84
84
|
});
|
|
85
|
+
window.__kumologica.settings.aiConfig = new AiConfigStore();
|
|
85
86
|
|
|
86
87
|
window.__kumologica.settings.kumohubConfig =
|
|
87
88
|
new KumohubConfig.KumohubConfigStore({
|
|
@@ -580,6 +581,11 @@ function includeNodePathIntoPath() {
|
|
|
580
581
|
}
|
|
581
582
|
}
|
|
582
583
|
|
|
584
|
+
|
|
585
|
+
async function chatWithAi(params) {
|
|
586
|
+
return await chatAi(params );
|
|
587
|
+
}
|
|
588
|
+
|
|
583
589
|
async function npmInstall(dependency) {
|
|
584
590
|
return new Promise((resolve, reject) => {
|
|
585
591
|
window.__kumologica.editor.terminal.eventEmitter.emit(
|
|
@@ -679,6 +685,7 @@ window.__kumologica.settings = {};
|
|
|
679
685
|
window.__kumologica.settings.loadConfigs = loadConfigs;
|
|
680
686
|
|
|
681
687
|
window.__kumologica.settings.cloudConfigStore = cloudConfigStore;
|
|
688
|
+
window.__kumologica.settings.aiConfigStore = aiConfigStore;
|
|
682
689
|
window.__kumologica.settings.networkConfigStore = networkConfigStore;
|
|
683
690
|
window.__kumologica.settings.workspacePreferenceStore =
|
|
684
691
|
new WorkspacePreferenceStore();
|
|
@@ -737,7 +744,8 @@ window.__kumologica.libs.dagre = dagre;
|
|
|
737
744
|
window.__kumologica.libs.simpleGit = simpleGit;
|
|
738
745
|
|
|
739
746
|
// AI utilities
|
|
740
|
-
window.__kumologica.libs.
|
|
747
|
+
window.__kumologica.libs.chatAi = chatWithAi;
|
|
748
|
+
|
|
741
749
|
|
|
742
750
|
/**
|
|
743
751
|
* Return the name of the valid kumologica flow or undefined otherwise.
|