agentrein 1.0.12 → 1.0.13
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.
|
@@ -33,7 +33,7 @@ export declare class AgentRein {
|
|
|
33
33
|
private readonly apiKey;
|
|
34
34
|
private readonly failureMode;
|
|
35
35
|
private token;
|
|
36
|
-
private
|
|
36
|
+
private static activeSessions;
|
|
37
37
|
constructor(options: AgentReinOptions);
|
|
38
38
|
/**
|
|
39
39
|
* Obtain a JWT token from the AgentRein server using the API key.
|
|
@@ -12,7 +12,6 @@ function createUndoConfig(config) {
|
|
|
12
12
|
class AgentRein {
|
|
13
13
|
constructor(options) {
|
|
14
14
|
this.token = null;
|
|
15
|
-
this.currentSession = null;
|
|
16
15
|
this.serverUrl = options.serverUrl || 'https://api.agentrein.com';
|
|
17
16
|
this.apiKey = options.apiKey;
|
|
18
17
|
this.failureMode = options.failureMode ?? 'open';
|
|
@@ -66,23 +65,26 @@ class AgentRein {
|
|
|
66
65
|
* All subsequent agentrein.call() will be logged under this session automatically.
|
|
67
66
|
*/
|
|
68
67
|
async startWorkflow(options) {
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
const session = await this.newSession(options);
|
|
69
|
+
AgentRein.activeSessions.set(this.apiKey, session);
|
|
70
|
+
return session;
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
73
|
* End the current workflow and clear the internal session state.
|
|
74
74
|
*/
|
|
75
75
|
async endWorkflow() {
|
|
76
|
-
this.
|
|
76
|
+
AgentRein.activeSessions.delete(this.apiKey);
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
79
|
* Get the current active session, or create one automatically if none exists.
|
|
80
80
|
*/
|
|
81
81
|
async getCurrentSession() {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
const cached = AgentRein.activeSessions.get(this.apiKey);
|
|
83
|
+
if (cached)
|
|
84
|
+
return cached;
|
|
85
|
+
const session = await this.newSession();
|
|
86
|
+
AgentRein.activeSessions.set(this.apiKey, session);
|
|
87
|
+
return session;
|
|
86
88
|
}
|
|
87
89
|
/**
|
|
88
90
|
* Resume an existing session by ID.
|
|
@@ -91,8 +93,9 @@ class AgentRein {
|
|
|
91
93
|
async resumeSession(sessionId) {
|
|
92
94
|
const headers = await this.authHeaders();
|
|
93
95
|
const res = await axios_1.default.get(`${this.serverUrl}/sessions/${sessionId}`, { headers });
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
const session = res.data.data;
|
|
97
|
+
AgentRein.activeSessions.set(this.apiKey, session);
|
|
98
|
+
return session;
|
|
96
99
|
}
|
|
97
100
|
async call(fn, ...args) {
|
|
98
101
|
const session = await this.getCurrentSession();
|
|
@@ -128,4 +131,5 @@ class AgentRein {
|
|
|
128
131
|
}
|
|
129
132
|
}
|
|
130
133
|
exports.AgentRein = AgentRein;
|
|
134
|
+
AgentRein.activeSessions = new Map();
|
|
131
135
|
exports.default = AgentRein;
|
|
@@ -9,7 +9,6 @@ export { AgentReinUnavailableError };
|
|
|
9
9
|
export class AgentRein {
|
|
10
10
|
constructor(options) {
|
|
11
11
|
this.token = null;
|
|
12
|
-
this.currentSession = null;
|
|
13
12
|
this.serverUrl = options.serverUrl || 'https://api.agentrein.com';
|
|
14
13
|
this.apiKey = options.apiKey;
|
|
15
14
|
this.failureMode = options.failureMode ?? 'open';
|
|
@@ -63,23 +62,26 @@ export class AgentRein {
|
|
|
63
62
|
* All subsequent agentrein.call() will be logged under this session automatically.
|
|
64
63
|
*/
|
|
65
64
|
async startWorkflow(options) {
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
const session = await this.newSession(options);
|
|
66
|
+
AgentRein.activeSessions.set(this.apiKey, session);
|
|
67
|
+
return session;
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
70
|
* End the current workflow and clear the internal session state.
|
|
71
71
|
*/
|
|
72
72
|
async endWorkflow() {
|
|
73
|
-
this.
|
|
73
|
+
AgentRein.activeSessions.delete(this.apiKey);
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
76
|
* Get the current active session, or create one automatically if none exists.
|
|
77
77
|
*/
|
|
78
78
|
async getCurrentSession() {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
const cached = AgentRein.activeSessions.get(this.apiKey);
|
|
80
|
+
if (cached)
|
|
81
|
+
return cached;
|
|
82
|
+
const session = await this.newSession();
|
|
83
|
+
AgentRein.activeSessions.set(this.apiKey, session);
|
|
84
|
+
return session;
|
|
83
85
|
}
|
|
84
86
|
/**
|
|
85
87
|
* Resume an existing session by ID.
|
|
@@ -88,8 +90,9 @@ export class AgentRein {
|
|
|
88
90
|
async resumeSession(sessionId) {
|
|
89
91
|
const headers = await this.authHeaders();
|
|
90
92
|
const res = await axios.get(`${this.serverUrl}/sessions/${sessionId}`, { headers });
|
|
91
|
-
|
|
92
|
-
|
|
93
|
+
const session = res.data.data;
|
|
94
|
+
AgentRein.activeSessions.set(this.apiKey, session);
|
|
95
|
+
return session;
|
|
93
96
|
}
|
|
94
97
|
async call(fn, ...args) {
|
|
95
98
|
const session = await this.getCurrentSession();
|
|
@@ -124,4 +127,5 @@ export class AgentRein {
|
|
|
124
127
|
}
|
|
125
128
|
}
|
|
126
129
|
}
|
|
130
|
+
AgentRein.activeSessions = new Map();
|
|
127
131
|
export default AgentRein;
|