@smythos/sre 1.7.18 → 1.7.20
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 +21 -21
- package/dist/index.js.map +1 -1
- package/dist/types/Components/RAG/DataSourceCleaner.class.d.ts +37 -0
- package/dist/types/Components/RAG/DataSourceComponent.class.d.ts +30 -0
- package/dist/types/Components/RAG/DataSourceIndexer.class.d.ts +14 -0
- package/dist/types/Components/RAG/DataSourceLookup.class.d.ts +36 -0
- package/dist/types/helpers/Conversation.helper.d.ts +3 -0
- package/dist/types/subsystems/LLMManager/LLM.inference.d.ts +10 -3
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/GoogleAI.class.d.ts +4 -2
- package/dist/types/subsystems/Security/ManagedVault.service/connectors/SecretManagerManagedVault.d.ts +10 -0
- package/dist/types/subsystems/Security/Vault.service/connectors/SecretsManager.class.d.ts +5 -0
- package/dist/types/types/LLM.types.d.ts +2 -0
- package/dist/types/utils/array.utils.d.ts +4 -0
- package/package.json +1 -1
- package/src/helpers/AWSLambdaCode.helper.ts +40 -45
- package/src/helpers/Conversation.helper.ts +14 -10
- package/src/subsystems/LLMManager/LLM.inference.ts +63 -47
- package/src/subsystems/LLMManager/LLM.service/connectors/GoogleAI.class.ts +92 -19
- package/src/subsystems/LLMManager/ModelsProvider.service/connectors/JSONModelsProvider.class.ts +34 -27
- package/src/subsystems/ObservabilityManager/Telemetry.service/connectors/OTel/OTel.class.ts +6 -0
- package/src/subsystems/Security/ManagedVault.service/connectors/SecretManagerManagedVault.ts +111 -48
- package/src/subsystems/Security/Vault.service/connectors/SecretsManager.class.ts +92 -62
- package/src/types/LLM.types.ts +5 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { IAgent as Agent } from '@sre/types/Agent.types';
|
|
2
|
+
import Joi from 'joi';
|
|
3
|
+
import { DataSourceComponent } from './DataSourceComponent.class';
|
|
4
|
+
export declare class DataSourceCleaner extends DataSourceComponent {
|
|
5
|
+
protected configSchema: Joi.ObjectSchema<any>;
|
|
6
|
+
constructor();
|
|
7
|
+
init(): void;
|
|
8
|
+
process(input: any, config: any, agent: Agent): Promise<{
|
|
9
|
+
_debug: string;
|
|
10
|
+
Success: boolean;
|
|
11
|
+
_error?: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
_debug: string;
|
|
14
|
+
_error: any;
|
|
15
|
+
Success?: undefined;
|
|
16
|
+
}>;
|
|
17
|
+
processV1(input: any, config: any, agent: Agent): Promise<{
|
|
18
|
+
_debug: string;
|
|
19
|
+
Success: boolean;
|
|
20
|
+
_error?: undefined;
|
|
21
|
+
} | {
|
|
22
|
+
_debug: string;
|
|
23
|
+
_error: any;
|
|
24
|
+
Success?: undefined;
|
|
25
|
+
}>;
|
|
26
|
+
processV2(input: any, config: any, agent: Agent): Promise<{
|
|
27
|
+
_debug: string;
|
|
28
|
+
_error: any;
|
|
29
|
+
Success?: undefined;
|
|
30
|
+
} | {
|
|
31
|
+
_debug: string;
|
|
32
|
+
Success: boolean;
|
|
33
|
+
_error?: undefined;
|
|
34
|
+
}>;
|
|
35
|
+
validateInput(input: any): Joi.ValidationResult<any>;
|
|
36
|
+
validateConfigData(data: any): Joi.ValidationResult<any>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Component } from '../Component.class';
|
|
2
|
+
import { TEmbeddings } from '@sre/IO/VectorDB.service/embed/BaseEmbedding';
|
|
3
|
+
import { VectorDBConnector } from '@sre/IO/VectorDB.service/VectorDBConnector';
|
|
4
|
+
export type NsRecord = {
|
|
5
|
+
credentialId: string;
|
|
6
|
+
embeddings: {
|
|
7
|
+
dimensions: string;
|
|
8
|
+
modelId: string;
|
|
9
|
+
};
|
|
10
|
+
label: string;
|
|
11
|
+
createdAt: string;
|
|
12
|
+
};
|
|
13
|
+
export declare enum TDataSourceCompErrorCodes {
|
|
14
|
+
NAMESPACE_NOT_FOUND = 1,
|
|
15
|
+
CREDENTIAL_NOT_FOUND = 2,
|
|
16
|
+
EMBEDDING_CONFIG_ERROR = 3
|
|
17
|
+
}
|
|
18
|
+
export declare class DataSourceCompError extends Error {
|
|
19
|
+
code: TDataSourceCompErrorCodes;
|
|
20
|
+
constructor(message: string, code: TDataSourceCompErrorCodes);
|
|
21
|
+
}
|
|
22
|
+
export declare class DataSourceComponent extends Component {
|
|
23
|
+
constructor();
|
|
24
|
+
resolveVectorDbConnector(namespace: string | NsRecord, teamId: string): Promise<VectorDBConnector>;
|
|
25
|
+
buildEmbeddingConfig(embedding: {
|
|
26
|
+
dimensions: string;
|
|
27
|
+
modelId: string;
|
|
28
|
+
}, teamId: string): Promise<TEmbeddings>;
|
|
29
|
+
static normalizeDsId(providedId: string, teamId: string, namespaceId: string): string;
|
|
30
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IAgent as Agent } from '@sre/types/Agent.types';
|
|
2
|
+
import { DataSourceComponent } from './DataSourceComponent.class';
|
|
3
|
+
import Joi from 'joi';
|
|
4
|
+
export declare class DataSourceIndexer extends DataSourceComponent {
|
|
5
|
+
private MAX_ALLOWED_URLS_PER_INPUT;
|
|
6
|
+
protected configSchema: Joi.ObjectSchema<any>;
|
|
7
|
+
constructor();
|
|
8
|
+
init(): void;
|
|
9
|
+
process(input: any, config: any, agent: Agent): Promise<any>;
|
|
10
|
+
private processV1;
|
|
11
|
+
private processV2;
|
|
12
|
+
validateInput(input: any): Joi.ValidationResult<any>;
|
|
13
|
+
private addDSFromText;
|
|
14
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import Joi from 'joi';
|
|
2
|
+
import { IAgent as Agent } from '@sre/types/Agent.types';
|
|
3
|
+
import { DataSourceComponent } from './DataSourceComponent.class';
|
|
4
|
+
export declare class DataSourceLookup extends DataSourceComponent {
|
|
5
|
+
protected configSchema: Joi.ObjectSchema<any>;
|
|
6
|
+
constructor();
|
|
7
|
+
init(): void;
|
|
8
|
+
process(input: any, config: any, agent: Agent): Promise<{
|
|
9
|
+
Results: string[] | {
|
|
10
|
+
content: string;
|
|
11
|
+
metadata: any;
|
|
12
|
+
score?: number;
|
|
13
|
+
}[];
|
|
14
|
+
_error: any;
|
|
15
|
+
_debug: string;
|
|
16
|
+
}>;
|
|
17
|
+
processV1(input: any, config: any, agent: Agent): Promise<{
|
|
18
|
+
Results: string[] | {
|
|
19
|
+
content: string;
|
|
20
|
+
metadata: any;
|
|
21
|
+
score?: number;
|
|
22
|
+
}[];
|
|
23
|
+
_error: any;
|
|
24
|
+
_debug: string;
|
|
25
|
+
}>;
|
|
26
|
+
processV2(input: any, config: any, agent: Agent): Promise<{
|
|
27
|
+
Results: string[] | {
|
|
28
|
+
content: string;
|
|
29
|
+
metadata: any;
|
|
30
|
+
score?: number;
|
|
31
|
+
}[];
|
|
32
|
+
_error: any;
|
|
33
|
+
_debug: string;
|
|
34
|
+
}>;
|
|
35
|
+
private parseMetadata;
|
|
36
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LLMInference } from '@sre/LLMManager/LLM.inference';
|
|
1
2
|
import { LLMContext } from '@sre/MemoryManager/LLMContext';
|
|
2
3
|
import { ILLMContextStore, TLLMModel } from '@sre/types/LLM.types';
|
|
3
4
|
import EventEmitter from 'events';
|
|
@@ -38,6 +39,8 @@ export declare class Conversation extends EventEmitter {
|
|
|
38
39
|
set spec(specSource: any);
|
|
39
40
|
set model(model: string | TLLMModel);
|
|
40
41
|
get model(): string | TLLMModel;
|
|
42
|
+
private _llmInference;
|
|
43
|
+
get llmInference(): LLMInference;
|
|
41
44
|
constructor(_model: string | TLLMModel, _specSource?: string | Record<string, any>, _settings?: {
|
|
42
45
|
maxContextSize?: number;
|
|
43
46
|
maxOutputTokens?: number;
|
|
@@ -2,6 +2,7 @@ import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.cla
|
|
|
2
2
|
import { IAgent } from '@sre/types/Agent.types';
|
|
3
3
|
import { TLLMModel, TLLMParams } from '@sre/types/LLM.types';
|
|
4
4
|
import { LLMConnector } from './LLM.service/LLMConnector';
|
|
5
|
+
import { IModelsProviderRequest } from './ModelsProvider.service/ModelsProviderConnector';
|
|
5
6
|
type TPromptParams = {
|
|
6
7
|
query?: string;
|
|
7
8
|
contextWindow?: any[];
|
|
@@ -10,9 +11,15 @@ type TPromptParams = {
|
|
|
10
11
|
onFallback?: (data: any) => void;
|
|
11
12
|
};
|
|
12
13
|
export declare class LLMInference {
|
|
13
|
-
private
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
private _model;
|
|
15
|
+
get model(): string | TLLMModel;
|
|
16
|
+
get modelId(): string;
|
|
17
|
+
private _llmConnector;
|
|
18
|
+
get llmConnector(): LLMConnector;
|
|
19
|
+
private _modelProviderReq;
|
|
20
|
+
get modelProviderReq(): IModelsProviderRequest;
|
|
21
|
+
private _llmProviderName;
|
|
22
|
+
get llmProviderName(): string;
|
|
16
23
|
teamId?: string;
|
|
17
24
|
static getInstance(model: string | TLLMModel, candidate: AccessCandidate): Promise<LLMInference>;
|
|
18
25
|
static user(candidate: AccessCandidate): any;
|
|
@@ -28,12 +28,14 @@ export declare class GoogleAIConnector extends LLMConnector {
|
|
|
28
28
|
output_tokens: number;
|
|
29
29
|
input_tokens_audio: number;
|
|
30
30
|
input_tokens_cache_read: number;
|
|
31
|
+
input_tokens_cache_read_audio: number;
|
|
31
32
|
input_tokens_cache_write: number;
|
|
32
|
-
reasoning_tokens: number;
|
|
33
33
|
keySource: APIKeySource;
|
|
34
34
|
agentId: string;
|
|
35
35
|
teamId: string;
|
|
36
|
-
|
|
36
|
+
inTier: string;
|
|
37
|
+
outTier: string;
|
|
38
|
+
crTier: string;
|
|
37
39
|
};
|
|
38
40
|
/**
|
|
39
41
|
* Extract text and image tokens from Google AI usage metadata
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
|
|
2
2
|
import { ACL } from '@sre/Security/AccessControl/ACL.class';
|
|
3
3
|
import { IAccessCandidate } from '@sre/types/ACL.types';
|
|
4
|
+
import { GetSecretValueCommandOutput } from '@aws-sdk/client-secrets-manager';
|
|
4
5
|
import { ManagedVaultConnector } from '../ManagedVaultConnector';
|
|
5
6
|
import { SecretsManagerConfig } from '../../Vault.service/connectors/SecretsManager.class';
|
|
6
7
|
export declare class SecretManagerManagedVault extends ManagedVaultConnector {
|
|
7
8
|
protected _settings: SecretsManagerConfig & {
|
|
8
9
|
vaultName: string;
|
|
10
|
+
prefix: string;
|
|
9
11
|
};
|
|
10
12
|
name: string;
|
|
11
13
|
scope: string;
|
|
12
14
|
private secretsManager;
|
|
15
|
+
private prefix;
|
|
13
16
|
constructor(_settings: SecretsManagerConfig & {
|
|
14
17
|
vaultName: string;
|
|
18
|
+
prefix: string;
|
|
15
19
|
});
|
|
16
20
|
protected get(acRequest: AccessRequest, secretName: string): Promise<any>;
|
|
17
21
|
protected set(acRequest: AccessRequest, secretName: string, value: string): Promise<void>;
|
|
@@ -19,4 +23,10 @@ export declare class SecretManagerManagedVault extends ManagedVaultConnector {
|
|
|
19
23
|
protected exists(acRequest: AccessRequest, secretName: string): Promise<boolean>;
|
|
20
24
|
getResourceACL(resourceId: string, candidate: IAccessCandidate): Promise<ACL>;
|
|
21
25
|
private getSecretByName;
|
|
26
|
+
getVaultKey(secretName: string, teamId: string): string;
|
|
27
|
+
getFormattedSecret(secret: GetSecretValueCommandOutput): {
|
|
28
|
+
secretId: string;
|
|
29
|
+
key: string;
|
|
30
|
+
value: string;
|
|
31
|
+
};
|
|
22
32
|
}
|
|
@@ -6,15 +6,20 @@ export type SecretsManagerConfig = {
|
|
|
6
6
|
region: string;
|
|
7
7
|
awsAccessKeyId?: string;
|
|
8
8
|
awsSecretAccessKey?: string;
|
|
9
|
+
prefix?: string;
|
|
9
10
|
};
|
|
10
11
|
export declare class SecretsManager extends VaultConnector {
|
|
11
12
|
protected _settings: SecretsManagerConfig;
|
|
12
13
|
name: string;
|
|
13
14
|
private secretsManager;
|
|
15
|
+
private prefix;
|
|
14
16
|
constructor(_settings: SecretsManagerConfig);
|
|
15
17
|
protected get(acRequest: AccessRequest, secretName: string): Promise<any>;
|
|
16
18
|
protected exists(acRequest: AccessRequest, keyId: string): Promise<boolean>;
|
|
17
19
|
protected listKeys(acRequest: AccessRequest): Promise<any[]>;
|
|
18
20
|
getResourceACL(resourceId: string, candidate: IAccessCandidate): Promise<ACL>;
|
|
19
21
|
private getSecretByName;
|
|
22
|
+
private getVaultKey;
|
|
23
|
+
private getSecretById;
|
|
24
|
+
private getSecretValue;
|
|
20
25
|
}
|
|
@@ -300,6 +300,7 @@ export type ToolData = {
|
|
|
300
300
|
function?: any;
|
|
301
301
|
error?: string;
|
|
302
302
|
callId?: string;
|
|
303
|
+
thoughtSignature?: string;
|
|
303
304
|
};
|
|
304
305
|
/**
|
|
305
306
|
* Base tool definition interface - only truly common properties
|
|
@@ -497,6 +498,7 @@ export interface TGoogleAIRequestBody {
|
|
|
497
498
|
topK?: number;
|
|
498
499
|
stopSequences?: string[];
|
|
499
500
|
responseMimeType?: string;
|
|
501
|
+
media_resolution?: 'low' | 'medium' | 'high';
|
|
500
502
|
};
|
|
501
503
|
tools?: any;
|
|
502
504
|
toolConfig?: any;
|
package/package.json
CHANGED
|
@@ -134,13 +134,7 @@ export async function zipCode(directory: string) {
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
export async function createOrUpdateLambdaFunction(functionName, zipFilePath, awsConfigs, envVariables: Record<string, string>) {
|
|
137
|
-
const client =
|
|
138
|
-
region: awsConfigs.region,
|
|
139
|
-
credentials: {
|
|
140
|
-
accessKeyId: awsConfigs.accessKeyId,
|
|
141
|
-
secretAccessKey: awsConfigs.secretAccessKey,
|
|
142
|
-
},
|
|
143
|
-
});
|
|
137
|
+
const client = getAWSLambdaClient(awsConfigs.region, awsConfigs.accessKeyId, awsConfigs.secretAccessKey)
|
|
144
138
|
const functionContent = fs.readFileSync(zipFilePath);
|
|
145
139
|
|
|
146
140
|
try {
|
|
@@ -168,26 +162,19 @@ export async function createOrUpdateLambdaFunction(functionName, zipFilePath, aw
|
|
|
168
162
|
let roleArn = '';
|
|
169
163
|
// check if the role exists
|
|
170
164
|
try {
|
|
171
|
-
const iamClient =
|
|
172
|
-
region: awsConfigs.region,
|
|
173
|
-
credentials: { accessKeyId: awsConfigs.accessKeyId, secretAccessKey: awsConfigs.secretAccessKey },
|
|
174
|
-
});
|
|
165
|
+
const iamClient = getAWSIAMClient(awsConfigs.region, awsConfigs.accessKeyId, awsConfigs.secretAccessKey);
|
|
175
166
|
const getRoleCommand = new GetRoleCommand({ RoleName: `smyth-${functionName}-role` });
|
|
176
167
|
const roleResponse: GetRoleCommandOutput = await iamClient.send(getRoleCommand);
|
|
177
168
|
roleArn = roleResponse.Role.Arn;
|
|
178
169
|
} catch (error) {
|
|
179
170
|
if (error.name === 'NoSuchEntityException') {
|
|
180
171
|
// create role
|
|
181
|
-
const iamClient =
|
|
182
|
-
region: awsConfigs.region,
|
|
183
|
-
credentials: { accessKeyId: awsConfigs.accessKeyId, secretAccessKey: awsConfigs.secretAccessKey },
|
|
184
|
-
});
|
|
172
|
+
const iamClient = getAWSIAMClient(awsConfigs.region, awsConfigs.accessKeyId, awsConfigs.secretAccessKey);
|
|
185
173
|
const createRoleCommand = new CreateRoleCommand({
|
|
186
174
|
RoleName: `smyth-${functionName}-role`,
|
|
187
175
|
AssumeRolePolicyDocument: getLambdaRolePolicy(),
|
|
188
176
|
});
|
|
189
177
|
const roleResponse: CreateRoleCommandOutput = await iamClient.send(createRoleCommand);
|
|
190
|
-
|
|
191
178
|
await waitForRoleDeploymentStatus(`smyth-${functionName}-role`, iamClient);
|
|
192
179
|
roleArn = roleResponse.Role.Arn;
|
|
193
180
|
} else {
|
|
@@ -231,7 +218,7 @@ function updateLambdaFunctionConfiguration(client: LambdaClient, functionName: s
|
|
|
231
218
|
|
|
232
219
|
async function createLambdaFunction(client: LambdaClient, functionParams: any, maxRetries: number = 5): Promise<void> {
|
|
233
220
|
let lastError: Error | null = null;
|
|
234
|
-
|
|
221
|
+
|
|
235
222
|
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
236
223
|
try {
|
|
237
224
|
const functionCreateCommand = new CreateFunctionCommand(functionParams);
|
|
@@ -241,7 +228,6 @@ async function createLambdaFunction(client: LambdaClient, functionParams: any, m
|
|
|
241
228
|
lastError = error;
|
|
242
229
|
// Check if this is a role trust policy error
|
|
243
230
|
if (error?.message?.includes('cannot be assumed by Lambda')) {
|
|
244
|
-
|
|
245
231
|
if (attempt < maxRetries) {
|
|
246
232
|
// Exponential backoff: 2^attempt seconds (2, 4, 8, 16, 32 seconds)
|
|
247
233
|
const waitTime = Math.pow(2, attempt) * 1000;
|
|
@@ -249,12 +235,11 @@ async function createLambdaFunction(client: LambdaClient, functionParams: any, m
|
|
|
249
235
|
continue;
|
|
250
236
|
}
|
|
251
237
|
}
|
|
252
|
-
|
|
253
238
|
// For other errors or if we've exhausted retries, throw immediately
|
|
254
239
|
throw error;
|
|
255
240
|
}
|
|
256
241
|
}
|
|
257
|
-
|
|
242
|
+
|
|
258
243
|
// If we get here, all retries failed
|
|
259
244
|
throw lastError || new Error('Lambda function creation failed after all retry attempts');
|
|
260
245
|
}
|
|
@@ -262,15 +247,15 @@ async function createLambdaFunction(client: LambdaClient, functionParams: any, m
|
|
|
262
247
|
export async function waitForRoleDeploymentStatus(roleName, client): Promise<boolean> {
|
|
263
248
|
return new Promise((resolve, reject) => {
|
|
264
249
|
const interval = setInterval(async () => {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
250
|
+
const getRoleCommand = new GetRoleCommand({ RoleName: roleName });
|
|
251
|
+
const roleResponse = await client.send(getRoleCommand);
|
|
252
|
+
|
|
253
|
+
// Check if role exists and has assume role policy document
|
|
254
|
+
if (roleResponse.Role && roleResponse.Role.AssumeRolePolicyDocument) {
|
|
255
|
+
clearInterval(interval);
|
|
256
|
+
setTimeout(() => resolve(true), 2000);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
274
259
|
}, 2000); // Check every 2 seconds
|
|
275
260
|
});
|
|
276
261
|
}
|
|
@@ -319,15 +304,7 @@ export async function invokeLambdaFunction(
|
|
|
319
304
|
awsCredentials: AWSCredentials & AWSRegionConfig
|
|
320
305
|
): Promise<any> {
|
|
321
306
|
try {
|
|
322
|
-
const client =
|
|
323
|
-
region: awsCredentials.region as string,
|
|
324
|
-
...(awsCredentials.accessKeyId && {
|
|
325
|
-
credentials: {
|
|
326
|
-
accessKeyId: awsCredentials.accessKeyId as string,
|
|
327
|
-
secretAccessKey: awsCredentials.secretAccessKey as string,
|
|
328
|
-
},
|
|
329
|
-
}),
|
|
330
|
-
});
|
|
307
|
+
const client = getAWSLambdaClient(awsCredentials.region, awsCredentials.accessKeyId, awsCredentials.secretAccessKey);
|
|
331
308
|
|
|
332
309
|
const invokeCommand = new InvokeCommand({
|
|
333
310
|
FunctionName: functionName,
|
|
@@ -347,13 +324,7 @@ export async function invokeLambdaFunction(
|
|
|
347
324
|
|
|
348
325
|
export async function getDeployedFunction(functionName: string, awsConfigs: AWSCredentials & AWSRegionConfig) {
|
|
349
326
|
try {
|
|
350
|
-
const client =
|
|
351
|
-
region: awsConfigs.region as string,
|
|
352
|
-
credentials: {
|
|
353
|
-
accessKeyId: awsConfigs.accessKeyId as string,
|
|
354
|
-
secretAccessKey: awsConfigs.secretAccessKey as string,
|
|
355
|
-
},
|
|
356
|
-
});
|
|
327
|
+
const client = getAWSLambdaClient(awsConfigs.region as string, awsConfigs.accessKeyId as string, awsConfigs.secretAccessKey as string);
|
|
357
328
|
const getFunctionCommand = new GetFunctionCommand({ FunctionName: functionName });
|
|
358
329
|
const lambdaResponse: GetFunctionCommandOutput = await client.send(getFunctionCommand);
|
|
359
330
|
return {
|
|
@@ -392,6 +363,30 @@ export async function getLambdaCredentials(agent: IAgent, config: any): Promise<
|
|
|
392
363
|
return awsCredentials;
|
|
393
364
|
}
|
|
394
365
|
|
|
366
|
+
function getAWSLambdaClient(region: string, accessKeyId?: string, secretAccessKey?: string) {
|
|
367
|
+
return new LambdaClient({
|
|
368
|
+
region,
|
|
369
|
+
...(accessKeyId && secretAccessKey && {
|
|
370
|
+
credentials: {
|
|
371
|
+
accessKeyId,
|
|
372
|
+
secretAccessKey,
|
|
373
|
+
},
|
|
374
|
+
}),
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function getAWSIAMClient(region: string, accessKeyId?: string, secretAccessKey?: string) {
|
|
379
|
+
return new IAMClient({
|
|
380
|
+
region,
|
|
381
|
+
...(accessKeyId && secretAccessKey && {
|
|
382
|
+
credentials: {
|
|
383
|
+
accessKeyId,
|
|
384
|
+
secretAccessKey,
|
|
385
|
+
},
|
|
386
|
+
}),
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
|
|
395
390
|
export function calculateExecutionCost(executionTime: number) {
|
|
396
391
|
// executionTime in milliseconds
|
|
397
392
|
const cost = (executionTime / 1000) * Number(PER_SECOND_COST);
|
|
@@ -117,6 +117,11 @@ export class Conversation extends EventEmitter {
|
|
|
117
117
|
return this._model;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
private _llmInference: LLMInference;
|
|
121
|
+
public get llmInference() {
|
|
122
|
+
return this._llmInference;
|
|
123
|
+
}
|
|
124
|
+
|
|
120
125
|
constructor(
|
|
121
126
|
private _model: string | TLLMModel,
|
|
122
127
|
private _specSource?: string | Record<string, any>,
|
|
@@ -308,7 +313,6 @@ export class Conversation extends EventEmitter {
|
|
|
308
313
|
// toolsConfig,
|
|
309
314
|
// });
|
|
310
315
|
/* ==================== STEP ENTRY ==================== */
|
|
311
|
-
const llmInference: LLMInference = await LLMInference.getInstance(this.model, AccessCandidate.team(this._teamId));
|
|
312
316
|
|
|
313
317
|
if (message) this._context.addUserMessage(message, message_id);
|
|
314
318
|
|
|
@@ -329,7 +333,7 @@ export class Conversation extends EventEmitter {
|
|
|
329
333
|
requestId: llmReqUid,
|
|
330
334
|
});
|
|
331
335
|
|
|
332
|
-
const eventEmitter: any = await llmInference
|
|
336
|
+
const eventEmitter: any = await this.llmInference
|
|
333
337
|
.promptStream({
|
|
334
338
|
contextWindow,
|
|
335
339
|
files,
|
|
@@ -818,6 +822,7 @@ export class Conversation extends EventEmitter {
|
|
|
818
822
|
handler: (args: Record<string, any>) => Promise<any>;
|
|
819
823
|
inputs?: any[];
|
|
820
824
|
}) {
|
|
825
|
+
await this.ready;
|
|
821
826
|
if (!tool.arguments) {
|
|
822
827
|
//if no arguments are provided, we need to extract them from the function
|
|
823
828
|
const toolFunction = tool.handler as Function;
|
|
@@ -879,11 +884,10 @@ export class Conversation extends EventEmitter {
|
|
|
879
884
|
|
|
880
885
|
//deduplicate tools
|
|
881
886
|
|
|
882
|
-
const llmInference: LLMInference = await LLMInference.getInstance(this.model, AccessCandidate.team(this._teamId));
|
|
883
887
|
this._customToolsDeclarations = this._customToolsDeclarations.filter(
|
|
884
888
|
(tool, index, self) => self.findIndex((t) => t.name === tool.name) === index
|
|
885
889
|
);
|
|
886
|
-
const toolsConfig: any = llmInference.connector.formatToolsConfig({
|
|
890
|
+
const toolsConfig: any = this.llmInference.connector.formatToolsConfig({
|
|
887
891
|
type: 'function',
|
|
888
892
|
toolDefinitions: this._customToolsDeclarations,
|
|
889
893
|
toolChoice: this.toolChoice,
|
|
@@ -896,11 +900,11 @@ export class Conversation extends EventEmitter {
|
|
|
896
900
|
}
|
|
897
901
|
|
|
898
902
|
async removeTool(toolName: string) {
|
|
903
|
+
await this.ready;
|
|
899
904
|
this._customToolsDeclarations = this._customToolsDeclarations.filter((tool) => tool.name !== toolName);
|
|
900
905
|
delete this._customToolsHandlers[toolName];
|
|
901
|
-
const llmInference: LLMInference = await LLMInference.getInstance(this.model, AccessCandidate.team(this._teamId));
|
|
902
906
|
|
|
903
|
-
const toolsConfig: any = llmInference.connector.formatToolsConfig({
|
|
907
|
+
const toolsConfig: any = this.llmInference.connector.formatToolsConfig({
|
|
904
908
|
type: 'function',
|
|
905
909
|
toolDefinitions: this._customToolsDeclarations,
|
|
906
910
|
toolChoice: this.toolChoice,
|
|
@@ -928,15 +932,15 @@ export class Conversation extends EventEmitter {
|
|
|
928
932
|
const functionDeclarations = this.getFunctionDeclarations(this._spec);
|
|
929
933
|
//functionDeclarations.push(...this._customToolsDeclarations);
|
|
930
934
|
this._customToolsDeclarations.push(...functionDeclarations);
|
|
931
|
-
|
|
932
|
-
if (!
|
|
935
|
+
this._llmInference = await LLMInference.getInstance(this._model, AccessCandidate.team(this._teamId));
|
|
936
|
+
if (!this._llmInference.connector) {
|
|
933
937
|
this.emit('error', 'No connector found for model: ' + this._model);
|
|
934
938
|
return;
|
|
935
939
|
}
|
|
936
940
|
this._customToolsDeclarations = this._customToolsDeclarations.filter(
|
|
937
941
|
(tool, index, self) => self.findIndex((t) => t.name === tool.name) === index
|
|
938
942
|
);
|
|
939
|
-
this._toolsConfig = llmInference.connector.formatToolsConfig({
|
|
943
|
+
this._toolsConfig = this.llmInference.connector.formatToolsConfig({
|
|
940
944
|
type: 'function',
|
|
941
945
|
toolDefinitions: this._customToolsDeclarations,
|
|
942
946
|
toolChoice: this.toolChoice,
|
|
@@ -945,7 +949,7 @@ export class Conversation extends EventEmitter {
|
|
|
945
949
|
let messages = [];
|
|
946
950
|
if (this._context) messages = this._context.messages; // preserve messages
|
|
947
951
|
|
|
948
|
-
this._context = new LLMContext(llmInference, this.systemPrompt, this._llmContextStore);
|
|
952
|
+
this._context = new LLMContext(this.llmInference, this.systemPrompt, this._llmContextStore);
|
|
949
953
|
} else {
|
|
950
954
|
this._toolsConfig = null;
|
|
951
955
|
this._reqMethods = null;
|