@smythos/sre 1.5.4 → 1.5.6
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/dist/index.js +122 -22317
- package/dist/index.js.map +1 -1
- package/dist/types/helpers/Sysconfig.helper.d.ts +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/subsystems/IO/Log.service/connectors/ConsoleLog.class.d.ts +1 -1
- package/dist/types/subsystems/IO/NKV.service/NKVConnector.d.ts +2 -0
- package/dist/types/subsystems/IO/NKV.service/connectors/NKVLocalStorage.class.d.ts +34 -0
- package/dist/types/subsystems/IO/Storage.service/connectors/LocalStorage.class.d.ts +1 -0
- package/package.json +1 -1
- package/src/Components/DataSourceLookup.class.ts +1 -1
- package/src/Core/SmythRuntime.class.ts +3 -66
- package/src/helpers/Sysconfig.helper.ts +67 -0
- package/src/index.ts +2 -0
- package/src/index.ts.bak +178 -176
- package/src/subsystems/AgentManager/AgentLogger.class.ts +1 -1
- package/src/subsystems/IO/Log.service/connectors/ConsoleLog.class.ts +1 -1
- package/src/subsystems/IO/NKV.service/NKVConnector.ts +2 -0
- package/src/subsystems/IO/NKV.service/connectors/NKVLocalStorage.class.ts +211 -0
- package/src/subsystems/IO/NKV.service/connectors/NKVRAM.class.ts +1 -1
- package/src/subsystems/IO/NKV.service/index.ts +2 -0
- package/src/subsystems/IO/Storage.service/connectors/LocalStorage.class.ts +21 -1
- package/src/subsystems/Security/Vault.service/connectors/JSONFileVault.class.ts +11 -11
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function findSmythPath(_path?: string, callback?: (smythDir: string, success?: boolean, nextDir?: string) => void): any;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -51,6 +51,7 @@ export * from './helpers/Log.helper';
|
|
|
51
51
|
export * from './helpers/OpenApiParser.helper';
|
|
52
52
|
export * from './helpers/S3Cache.helper';
|
|
53
53
|
export * from './helpers/SmythURI.helper';
|
|
54
|
+
export * from './helpers/Sysconfig.helper';
|
|
54
55
|
export * from './helpers/TemplateString.helper';
|
|
55
56
|
export * from './helpers/TypeChecker.helper';
|
|
56
57
|
export * from './types/ACL.types';
|
|
@@ -137,6 +138,7 @@ export * from './subsystems/AgentManager/AgentData.service/connectors/NullAgentD
|
|
|
137
138
|
export * from './subsystems/AgentManager/Component.service/connectors/LocalComponentConnector.class';
|
|
138
139
|
export * from './subsystems/ComputeManager/Code.service/connectors/AWSLambdaCode.class';
|
|
139
140
|
export * from './subsystems/IO/Log.service/connectors/ConsoleLog.class';
|
|
141
|
+
export * from './subsystems/IO/NKV.service/connectors/NKVLocalStorage.class';
|
|
140
142
|
export * from './subsystems/IO/NKV.service/connectors/NKVRAM.class';
|
|
141
143
|
export * from './subsystems/IO/NKV.service/connectors/NKVRedis.class';
|
|
142
144
|
export * from './subsystems/IO/Router.service/connectors/ExpressRouter.class';
|
|
@@ -4,9 +4,9 @@ import { IAccessCandidate } from '@sre/types/ACL.types';
|
|
|
4
4
|
import { LogConnector } from '../LogConnector';
|
|
5
5
|
import { AgentCallLog } from '@sre/types/AgentLogger.types';
|
|
6
6
|
export declare class ConsoleLog extends LogConnector {
|
|
7
|
+
name: string;
|
|
7
8
|
id: string;
|
|
8
9
|
getResourceACL(resourceId: string, candidate: IAccessCandidate): Promise<ACL>;
|
|
9
10
|
protected log(acRequest: AccessRequest, logData: AgentCallLog, callId?: string): Promise<any>;
|
|
10
11
|
protected logTask(acRequest: AccessRequest, tasks: number, isUsingTestDomain: boolean): Promise<void>;
|
|
11
|
-
name: string;
|
|
12
12
|
}
|
|
@@ -17,6 +17,8 @@ export interface INKVRequest {
|
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* NKV = Namespace-Key-Value Connector
|
|
20
|
+
* The NKV Connectors are used to store and retrieve data in a namespace-key-value format.
|
|
21
|
+
* It is generally used by internal connectors to index data : for example, some vectorDB providers may use it to keep track of inserted vectors.
|
|
20
22
|
*/
|
|
21
23
|
export declare abstract class NKVConnector extends SecureConnector {
|
|
22
24
|
requester(candidate: AccessCandidate): INKVRequest;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
|
|
2
|
+
import { NKVConnector } from '../NKVConnector';
|
|
3
|
+
import { IAccessCandidate } from '@sre/types/ACL.types';
|
|
4
|
+
import { ACL } from '@sre/Security/AccessControl/ACL.class';
|
|
5
|
+
import { StorageData } from '@sre/types/Storage.types';
|
|
6
|
+
export type NKVLocalStorageConfig = {
|
|
7
|
+
folder?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare class NKVLocalStorage extends NKVConnector {
|
|
10
|
+
protected _settings?: NKVLocalStorageConfig;
|
|
11
|
+
name: string;
|
|
12
|
+
private folder;
|
|
13
|
+
private accountConnector;
|
|
14
|
+
private cacheConnector;
|
|
15
|
+
private isInitialized;
|
|
16
|
+
constructor(_settings?: NKVLocalStorageConfig);
|
|
17
|
+
private findStorageFolder;
|
|
18
|
+
private initialize;
|
|
19
|
+
private getStoragePath;
|
|
20
|
+
key(...parts: string[]): string;
|
|
21
|
+
protected get(acRequest: AccessRequest, namespace: string, key: string): Promise<StorageData>;
|
|
22
|
+
protected set(acRequest: AccessRequest, namespace: string, key: string, value: any): Promise<void>;
|
|
23
|
+
protected delete(acRequest: AccessRequest, namespace: string, key: string): Promise<void>;
|
|
24
|
+
protected exists(acRequest: AccessRequest, namespace: string, key: string): Promise<boolean>;
|
|
25
|
+
list(acRequest: AccessRequest, namespace: string): Promise<{
|
|
26
|
+
key: string;
|
|
27
|
+
data: StorageData;
|
|
28
|
+
}[]>;
|
|
29
|
+
deleteAll(acRequest: AccessRequest, namespace: string): Promise<void>;
|
|
30
|
+
getResourceACL(resourceId: string, candidate: IAccessCandidate): Promise<ACL>;
|
|
31
|
+
clearAll(): void;
|
|
32
|
+
static NamespaceAccessControl(target: any, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor;
|
|
33
|
+
static Validate(target: any, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor;
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -70,7 +70,7 @@ export class DataSourceLookup extends Component {
|
|
|
70
70
|
.requester(AccessCandidate.team(teamId))
|
|
71
71
|
.search(namespace, _input, { topK, includeMetadata: true });
|
|
72
72
|
results = response.slice(0, config.data.topK).map((result) => ({
|
|
73
|
-
content: result.
|
|
73
|
+
content: result.text,
|
|
74
74
|
metadata: result.metadata,
|
|
75
75
|
}));
|
|
76
76
|
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { boot } from './boot';
|
|
2
2
|
|
|
3
3
|
import { SREConfig, TConnectorService } from '@sre/types/SRE.types';
|
|
4
|
+
import { Logger } from '../helpers/Log.helper';
|
|
4
5
|
import { ConnectorService } from './ConnectorsService';
|
|
5
6
|
import { SystemEvents } from './SystemEvents';
|
|
6
|
-
import {
|
|
7
|
-
import path from 'path';
|
|
8
|
-
import fs from 'fs';
|
|
9
|
-
import os from 'os';
|
|
10
|
-
import { fileURLToPath } from 'url';
|
|
11
|
-
import { dirname } from 'path';
|
|
7
|
+
import { findSmythPath } from '../helpers/Sysconfig.helper';
|
|
12
8
|
|
|
13
9
|
const logger = Logger('SRE');
|
|
14
10
|
|
|
@@ -90,7 +86,7 @@ export class SmythRuntime {
|
|
|
90
86
|
|
|
91
87
|
public init(_config?: SREConfig): SmythRuntime {
|
|
92
88
|
if (!_config || JSON.stringify(_config) === '{}') {
|
|
93
|
-
this._smythDir =
|
|
89
|
+
this._smythDir = findSmythPath();
|
|
94
90
|
logger.info('.smyth directory found in:', this._smythDir);
|
|
95
91
|
}
|
|
96
92
|
|
|
@@ -198,65 +194,6 @@ export class SmythRuntime {
|
|
|
198
194
|
export const SRE = SmythRuntime.Instance;
|
|
199
195
|
let shuttingDown = false;
|
|
200
196
|
|
|
201
|
-
function findSmythDir() {
|
|
202
|
-
// 1. Try to find in local directory (the directory from which the program was run)
|
|
203
|
-
const localDir = path.resolve(process.cwd(), '.smyth');
|
|
204
|
-
if (fs.existsSync(localDir)) {
|
|
205
|
-
return localDir;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// 2. Try to find from main script's directory (entry point)
|
|
209
|
-
const mainScriptPath = process.argv[1];
|
|
210
|
-
const mainScriptDir = path.dirname(path.resolve(mainScriptPath));
|
|
211
|
-
if (mainScriptPath) {
|
|
212
|
-
const mainScriptSmythDir = path.resolve(mainScriptDir, '.smyth');
|
|
213
|
-
if (fs.existsSync(mainScriptSmythDir)) {
|
|
214
|
-
return mainScriptSmythDir;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// 3. Try to find it in current package root directory (where package.json is)
|
|
219
|
-
let packageRootDir = findPackageRoot();
|
|
220
|
-
if (packageRootDir) {
|
|
221
|
-
const packageSmythDir = path.resolve(packageRootDir, '.smyth');
|
|
222
|
-
if (fs.existsSync(packageSmythDir)) {
|
|
223
|
-
return packageSmythDir;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// 4. Try to find it in current package root directory from main script's directory
|
|
228
|
-
packageRootDir = findPackageRoot(mainScriptDir);
|
|
229
|
-
if (packageRootDir) {
|
|
230
|
-
const packageSmythDir = path.resolve(packageRootDir, '.smyth');
|
|
231
|
-
if (fs.existsSync(packageSmythDir)) {
|
|
232
|
-
return packageSmythDir;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// 5. Try to find it in user home directory
|
|
237
|
-
const homeDir = path.resolve(os.homedir(), '.smyth');
|
|
238
|
-
if (fs.existsSync(homeDir)) {
|
|
239
|
-
return homeDir;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// Default: return path in current working directory (will be created if needed)
|
|
243
|
-
return localDir;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function findPackageRoot(startDir = process.cwd()) {
|
|
247
|
-
let currentDir = startDir;
|
|
248
|
-
|
|
249
|
-
while (currentDir !== path.dirname(currentDir)) {
|
|
250
|
-
const packageJsonPath = path.resolve(currentDir, 'package.json');
|
|
251
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
252
|
-
return currentDir;
|
|
253
|
-
}
|
|
254
|
-
currentDir = path.dirname(currentDir);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
return null;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
197
|
async function shutdown(reason) {
|
|
261
198
|
if (!SmythRuntime.Instance.started) return;
|
|
262
199
|
if (shuttingDown) return;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import os from 'os';
|
|
4
|
+
|
|
5
|
+
export function findSmythPath(_path: string = '', callback?: (smythDir: string, success?: boolean, nextDir?: string) => void) {
|
|
6
|
+
//TODO : also search for a local sre configuration file indicating .smyth folder explicitly
|
|
7
|
+
|
|
8
|
+
const searchDirectories = [];
|
|
9
|
+
|
|
10
|
+
// 1. Try to find in local directory (the directory from which the program was run)
|
|
11
|
+
const localDir = path.resolve(process.cwd(), '.smyth', _path);
|
|
12
|
+
searchDirectories.push(localDir);
|
|
13
|
+
|
|
14
|
+
// 2. Try to find from main script's directory (entry point)
|
|
15
|
+
const mainScriptPath = process.argv[1];
|
|
16
|
+
const mainScriptDir = mainScriptPath ? path.dirname(path.resolve(mainScriptPath)) : null;
|
|
17
|
+
if (mainScriptDir) {
|
|
18
|
+
const mainScriptSmythDir = path.resolve(mainScriptDir, '.smyth', _path);
|
|
19
|
+
searchDirectories.push(mainScriptSmythDir);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 3. Try to find it in current package root directory (where package.json is)
|
|
23
|
+
const packageRootDir = findPackageRoot();
|
|
24
|
+
if (packageRootDir) {
|
|
25
|
+
const packageSmythDir = path.resolve(packageRootDir, '.smyth', _path);
|
|
26
|
+
searchDirectories.push(packageSmythDir);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 4. Try to find it in current package root directory from main script's directory
|
|
30
|
+
const packageMainRootDir = findPackageRoot(mainScriptDir);
|
|
31
|
+
if (packageMainRootDir) {
|
|
32
|
+
const packageSmythDir = path.resolve(packageMainRootDir, '.smyth', _path);
|
|
33
|
+
searchDirectories.push(packageSmythDir);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 5. Try to find it in user home directory
|
|
37
|
+
const homeDir = path.resolve(os.homedir(), '.smyth', _path);
|
|
38
|
+
searchDirectories.push(homeDir);
|
|
39
|
+
|
|
40
|
+
//check if any of the directories exist
|
|
41
|
+
for (let i = 0; i < searchDirectories.length; i++) {
|
|
42
|
+
const dir = searchDirectories[i];
|
|
43
|
+
const nextDir = searchDirectories[i + 1];
|
|
44
|
+
if (!fs.existsSync(dir)) {
|
|
45
|
+
callback?.(dir, false, nextDir);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
callback?.(dir, true, null);
|
|
49
|
+
return dir;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return localDir;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function findPackageRoot(startDir = process.cwd()) {
|
|
56
|
+
let currentDir = startDir;
|
|
57
|
+
|
|
58
|
+
while (currentDir !== path.dirname(currentDir)) {
|
|
59
|
+
const packageJsonPath = path.resolve(currentDir, 'package.json');
|
|
60
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
61
|
+
return currentDir;
|
|
62
|
+
}
|
|
63
|
+
currentDir = path.dirname(currentDir);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return null;
|
|
67
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -57,6 +57,7 @@ export * from './helpers/Log.helper';
|
|
|
57
57
|
export * from './helpers/OpenApiParser.helper';
|
|
58
58
|
export * from './helpers/S3Cache.helper';
|
|
59
59
|
export * from './helpers/SmythURI.helper';
|
|
60
|
+
export * from './helpers/Sysconfig.helper';
|
|
60
61
|
export * from './helpers/TemplateString.helper';
|
|
61
62
|
export * from './helpers/TypeChecker.helper';
|
|
62
63
|
export * from './types/ACL.types';
|
|
@@ -143,6 +144,7 @@ export * from './subsystems/AgentManager/AgentData.service/connectors/NullAgentD
|
|
|
143
144
|
export * from './subsystems/AgentManager/Component.service/connectors/LocalComponentConnector.class';
|
|
144
145
|
export * from './subsystems/ComputeManager/Code.service/connectors/AWSLambdaCode.class';
|
|
145
146
|
export * from './subsystems/IO/Log.service/connectors/ConsoleLog.class';
|
|
147
|
+
export * from './subsystems/IO/NKV.service/connectors/NKVLocalStorage.class';
|
|
146
148
|
export * from './subsystems/IO/NKV.service/connectors/NKVRAM.class';
|
|
147
149
|
export * from './subsystems/IO/NKV.service/connectors/NKVRedis.class';
|
|
148
150
|
export * from './subsystems/IO/Router.service/connectors/ExpressRouter.class';
|