@smythos/sre 1.5.56 → 1.5.60
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/CHANGELOG +7 -0
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/dist/types/Components/ScrapflyWebScrape.class.d.ts +23 -0
- package/dist/types/Core/SmythRuntime.class.d.ts +1 -0
- package/dist/types/types/LLM.types.d.ts +2 -0
- package/package.json +2 -2
- package/src/Components/ScrapflyWebScrape.class.ts +24 -0
- package/src/Components/TavilyWebSearch.class.ts +6 -1
- package/src/Core/SmythRuntime.class.ts +6 -0
- package/src/helpers/Conversation.helper.ts +5 -0
- package/src/subsystems/LLMManager/LLM.inference.ts +3 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ChatCompletionsApiInterface.ts +2 -2
- package/src/subsystems/LLMManager/ModelsProvider.service/ModelsProviderConnector.ts +3 -0
- package/src/subsystems/MemoryManager/RuntimeContext.ts +28 -23
- package/src/types/LLM.types.ts +2 -0
|
@@ -2,6 +2,29 @@ import { IAgent as Agent } from '@sre/types/Agent.types';
|
|
|
2
2
|
import { Component } from './Component.class';
|
|
3
3
|
import Joi from 'joi';
|
|
4
4
|
export declare class ScrapflyWebScrape extends Component {
|
|
5
|
+
protected schema: {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
inputs: {
|
|
9
|
+
URLs: {
|
|
10
|
+
type: string;
|
|
11
|
+
description: string;
|
|
12
|
+
default: boolean;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
outputs: {
|
|
16
|
+
Results: {
|
|
17
|
+
type: string;
|
|
18
|
+
description: string;
|
|
19
|
+
default: boolean;
|
|
20
|
+
};
|
|
21
|
+
FailedURLs: {
|
|
22
|
+
type: string;
|
|
23
|
+
description: string;
|
|
24
|
+
default: boolean;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
};
|
|
5
28
|
protected configSchema: Joi.ObjectSchema<any>;
|
|
6
29
|
constructor();
|
|
7
30
|
init(): void;
|
|
@@ -384,6 +384,8 @@ export type TLLMModelsList = {
|
|
|
384
384
|
[key: string]: TLLMModel | TCustomLLMModel;
|
|
385
385
|
};
|
|
386
386
|
export declare enum TLLMEvent {
|
|
387
|
+
/** Generated response chunks */
|
|
388
|
+
Data = "data",
|
|
387
389
|
/** Generated response chunks */
|
|
388
390
|
Content = "content",
|
|
389
391
|
/** Thinking blocks/chunks */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smythos/sre",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.60",
|
|
4
4
|
"description": "Smyth Runtime Environment",
|
|
5
5
|
"author": "Alaa-eddine KADDOURI",
|
|
6
6
|
"license": "MIT",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@google/genai": "^1.10.0",
|
|
57
57
|
"@google/generative-ai": "^0.14.1",
|
|
58
58
|
"@huggingface/inference": "^2.8.0",
|
|
59
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
59
|
+
"@modelcontextprotocol/sdk": "^1.17.4",
|
|
60
60
|
"@pinecone-database/pinecone": "^3.0.0",
|
|
61
61
|
"@runware/sdk-js": "^1.1.36",
|
|
62
62
|
"@smithy/smithy-client": "^4.4.3",
|
|
@@ -9,6 +9,30 @@ import { getCredentials } from '../subsystems/Security/Credentials.helper';
|
|
|
9
9
|
// const CREDITS_PER_URL = 0.2;
|
|
10
10
|
|
|
11
11
|
export class ScrapflyWebScrape extends Component {
|
|
12
|
+
protected schema = {
|
|
13
|
+
name: 'ScrapflyWebScrape',
|
|
14
|
+
description: 'Use this component to scrape web pages',
|
|
15
|
+
inputs: {
|
|
16
|
+
URLs: {
|
|
17
|
+
type: 'Array',
|
|
18
|
+
description: 'The URLs to scrape',
|
|
19
|
+
default: true,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
outputs: {
|
|
23
|
+
Results: {
|
|
24
|
+
type: 'Array',
|
|
25
|
+
description: 'The scraped results',
|
|
26
|
+
default: true,
|
|
27
|
+
},
|
|
28
|
+
FailedURLs: {
|
|
29
|
+
type: 'Array',
|
|
30
|
+
description: 'The URLs that failed to scrape',
|
|
31
|
+
default: true,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
12
36
|
protected configSchema = Joi.object({
|
|
13
37
|
// includeImages: Joi.boolean().default(false).label('Include Image Results'),
|
|
14
38
|
antiScrapingProtection: Joi.boolean().default(false).label('Enable Anti-Scraping Protection'),
|
|
@@ -82,7 +82,12 @@ export class TavilyWebSearch extends Component {
|
|
|
82
82
|
return { ...Output, _error, _debug: logger.output };
|
|
83
83
|
} catch (err: any) {
|
|
84
84
|
const _error = err?.message || err?.response?.data || err.toString();
|
|
85
|
-
|
|
85
|
+
|
|
86
|
+
if (err?.status === 401) {
|
|
87
|
+
logger.error(`Tavily Web Search Auth failed, make sure that you have the vault key "tavily" is present and valid`);
|
|
88
|
+
} else {
|
|
89
|
+
logger.error(` Error scraping web \n${JSON.stringify(_error)}\n`);
|
|
90
|
+
}
|
|
86
91
|
return { Output: undefined, _error, _debug: logger.output };
|
|
87
92
|
}
|
|
88
93
|
}
|
|
@@ -5,6 +5,7 @@ import { Logger } from '../helpers/Log.helper';
|
|
|
5
5
|
import { ConnectorService } from './ConnectorsService';
|
|
6
6
|
import { SystemEvents } from './SystemEvents';
|
|
7
7
|
import { findSmythPath } from '../helpers/Sysconfig.helper';
|
|
8
|
+
import pkg from '../../package.json';
|
|
8
9
|
|
|
9
10
|
const logger = Logger('SRE');
|
|
10
11
|
|
|
@@ -18,6 +19,10 @@ export class SmythRuntime {
|
|
|
18
19
|
private _readyPromise: Promise<boolean>;
|
|
19
20
|
private _readyResolve: (value: boolean) => void;
|
|
20
21
|
|
|
22
|
+
public get version() {
|
|
23
|
+
return pkg.version;
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
private defaultConfig: SREConfig = {
|
|
22
27
|
Vault: {
|
|
23
28
|
Connector: 'JSONFileVault',
|
|
@@ -88,6 +93,7 @@ export class SmythRuntime {
|
|
|
88
93
|
private _initialized = false;
|
|
89
94
|
|
|
90
95
|
public init(_config?: SREConfig): SmythRuntime {
|
|
96
|
+
logger.info(`SRE v${this.version} initializing...`);
|
|
91
97
|
if (!_config || JSON.stringify(_config) === '{}') {
|
|
92
98
|
this._smythDir = findSmythPath();
|
|
93
99
|
logger.info('.smyth directory found in:', this._smythDir);
|
|
@@ -342,6 +342,11 @@ export class Conversation extends EventEmitter {
|
|
|
342
342
|
this.emit(TLLMEvent.Thinking, thinking);
|
|
343
343
|
});
|
|
344
344
|
|
|
345
|
+
eventEmitter.on(TLLMEvent.Data, (data) => {
|
|
346
|
+
if (this.stop) return;
|
|
347
|
+
this.emit(TLLMEvent.Data, data);
|
|
348
|
+
});
|
|
349
|
+
|
|
345
350
|
eventEmitter.on(TLLMEvent.Content, (content) => {
|
|
346
351
|
if (this.stop) return;
|
|
347
352
|
// if (toolHeaders['x-passthrough']) {
|
|
@@ -265,6 +265,9 @@ export class LLMInference {
|
|
|
265
265
|
console.warn('Max input context is 0, returning empty context window, This usually indicates a wrong model configuration');
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
console.debug(
|
|
269
|
+
`Context Window Configuration: Max Input Tokens: ${maxInputContext}, Max Output Tokens: ${maxOutputContext}, Max Model Tokens: ${maxModelContext}`
|
|
270
|
+
);
|
|
268
271
|
const systemMessage = { role: 'system', content: systemPrompt };
|
|
269
272
|
|
|
270
273
|
let smythContextWindow = [];
|
|
@@ -188,7 +188,7 @@ export class ChatCompletionsApiInterface extends OpenAIApiInterface {
|
|
|
188
188
|
// Handle OpenAI tool definition format
|
|
189
189
|
if ('parameters' in tool) {
|
|
190
190
|
return {
|
|
191
|
-
type: 'function',
|
|
191
|
+
type: 'function' as const,
|
|
192
192
|
function: {
|
|
193
193
|
name: tool.name,
|
|
194
194
|
description: tool.description,
|
|
@@ -199,7 +199,7 @@ export class ChatCompletionsApiInterface extends OpenAIApiInterface {
|
|
|
199
199
|
|
|
200
200
|
// Handle legacy format for backward compatibility
|
|
201
201
|
return {
|
|
202
|
-
type: 'function',
|
|
202
|
+
type: 'function' as const,
|
|
203
203
|
function: {
|
|
204
204
|
name: tool.name,
|
|
205
205
|
description: tool.description,
|
|
@@ -132,6 +132,9 @@ export abstract class ModelsProviderConnector extends SecureConnector {
|
|
|
132
132
|
hasAPIKey: boolean;
|
|
133
133
|
}) => {
|
|
134
134
|
//const teamModels = typeof model === 'string' ? await loadTeamModels() : {};
|
|
135
|
+
if (Array.isArray(model?.tags) && model?.tags?.includes('sdk')) {
|
|
136
|
+
return; //skip check for SDK
|
|
137
|
+
}
|
|
135
138
|
const modelInfo = await this.getModelInfo(candidate.readRequest, {}, model, hasAPIKey);
|
|
136
139
|
const allowedContextTokens = modelInfo?.tokens;
|
|
137
140
|
const totalTokens = promptTokens + completionTokens;
|
|
@@ -122,11 +122,9 @@ export class RuntimeContext extends EventEmitter {
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
.set(this.ctxFile, JSON.stringify(ctxData), null, null, 1 * 60 * 60); //expires in 1 hour
|
|
129
|
-
}
|
|
125
|
+
await this._cacheConnector
|
|
126
|
+
.requester(AccessCandidate.agent(this.runtime.agent.id))
|
|
127
|
+
.set(this.ctxFile, JSON.stringify(ctxData), null, null, 1 * 60 * 60); //expires in 1 hour
|
|
130
128
|
} else {
|
|
131
129
|
ctxData = JSON.parse(data);
|
|
132
130
|
if (!ctxData.step) ctxData.step = 0;
|
|
@@ -143,12 +141,31 @@ export class RuntimeContext extends EventEmitter {
|
|
|
143
141
|
return this._readyPromise;
|
|
144
142
|
}
|
|
145
143
|
private async sync() {
|
|
146
|
-
if (!this.ctxFile
|
|
144
|
+
if (!this.ctxFile) return;
|
|
147
145
|
|
|
148
146
|
this.emit('syncing');
|
|
149
147
|
|
|
150
148
|
const deleteSession = this.runtime.sessionClosed;
|
|
151
149
|
|
|
150
|
+
//TODO : Do we need to cache the context if not in debug mode ?
|
|
151
|
+
|
|
152
|
+
const data = this.serialize();
|
|
153
|
+
//if (data) fs.writeFileSync(this.ctxFile, JSON.stringify(data, null, 2));
|
|
154
|
+
if (data) {
|
|
155
|
+
let serializedData = JSON.stringify(data);
|
|
156
|
+
console.debug('Agent Context Size', this.ctxFile, serializedData.length, AccessCandidate.agent(this.runtime.agent.id));
|
|
157
|
+
|
|
158
|
+
await this._cacheConnector
|
|
159
|
+
.requester(AccessCandidate.agent(this.runtime.agent.id))
|
|
160
|
+
.set(this.ctxFile, serializedData, null, null, 3 * 60 * 60); //expires in 3 hours max
|
|
161
|
+
|
|
162
|
+
const mb = serializedData.length / 1024 / 1024;
|
|
163
|
+
const cooldown = (mb / 10) * 1000;
|
|
164
|
+
serializedData = null;
|
|
165
|
+
|
|
166
|
+
await delay(cooldown);
|
|
167
|
+
}
|
|
168
|
+
|
|
152
169
|
if (deleteSession) {
|
|
153
170
|
const exists = await this._cacheConnector.requester(AccessCandidate.agent(this.runtime.agent.id)).exists(this.ctxFile);
|
|
154
171
|
|
|
@@ -161,22 +178,6 @@ export class RuntimeContext extends EventEmitter {
|
|
|
161
178
|
//if (fs.existsSync(this.ctxFile)) fs.unlinkSync(this.ctxFile);
|
|
162
179
|
this.ctxFile = null;
|
|
163
180
|
}
|
|
164
|
-
} else {
|
|
165
|
-
const data = this.serialize();
|
|
166
|
-
//if (data) fs.writeFileSync(this.ctxFile, JSON.stringify(data, null, 2));
|
|
167
|
-
if (data) {
|
|
168
|
-
let serializedData = JSON.stringify(data);
|
|
169
|
-
console.debug('Agent Context Size', this.ctxFile, serializedData.length, AccessCandidate.agent(this.runtime.agent.id));
|
|
170
|
-
await this._cacheConnector
|
|
171
|
-
.requester(AccessCandidate.agent(this.runtime.agent.id))
|
|
172
|
-
.set(this.ctxFile, serializedData, null, null, 3 * 60 * 60); //expires in 3 hours max
|
|
173
|
-
|
|
174
|
-
const mb = serializedData.length / 1024 / 1024;
|
|
175
|
-
const cooldown = (mb / 10) * 1000;
|
|
176
|
-
serializedData = null;
|
|
177
|
-
|
|
178
|
-
await delay(cooldown);
|
|
179
|
-
}
|
|
180
181
|
}
|
|
181
182
|
}
|
|
182
183
|
private _syncQueue = Promise.resolve();
|
|
@@ -184,7 +185,11 @@ export class RuntimeContext extends EventEmitter {
|
|
|
184
185
|
public enqueueSync() {
|
|
185
186
|
if (!this.ctxFile) return;
|
|
186
187
|
console.log('ENQUEUE SYNC');
|
|
187
|
-
this._syncQueue = this._syncQueue
|
|
188
|
+
this._syncQueue = this._syncQueue
|
|
189
|
+
.then(() => this.sync())
|
|
190
|
+
.catch((err) => {
|
|
191
|
+
console.error('Error syncing context', err);
|
|
192
|
+
}); // avoid unhandled rejections
|
|
188
193
|
}
|
|
189
194
|
public incStep() {
|
|
190
195
|
this.step++;
|
package/src/types/LLM.types.ts
CHANGED