agentrein 1.0.11 → 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,6 +33,7 @@ export declare class AgentRein {
|
|
|
33
33
|
private readonly apiKey;
|
|
34
34
|
private readonly failureMode;
|
|
35
35
|
private token;
|
|
36
|
+
private static activeSessions;
|
|
36
37
|
constructor(options: AgentReinOptions);
|
|
37
38
|
/**
|
|
38
39
|
* Obtain a JWT token from the AgentRein server using the API key.
|
|
@@ -51,11 +52,22 @@ export declare class AgentRein {
|
|
|
51
52
|
* If omitted, a random agentId is generated.
|
|
52
53
|
*/
|
|
53
54
|
newSession(options?: SessionOptions | string): Promise<Session>;
|
|
55
|
+
/**
|
|
56
|
+
* Start a new workflow session.
|
|
57
|
+
* All subsequent agentrein.call() will be logged under this session automatically.
|
|
58
|
+
*/
|
|
59
|
+
startWorkflow(options?: SessionOptions | string): Promise<Session>;
|
|
60
|
+
/**
|
|
61
|
+
* End the current workflow and clear the internal session state.
|
|
62
|
+
*/
|
|
63
|
+
endWorkflow(): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Get the current active session, or create one automatically if none exists.
|
|
66
|
+
*/
|
|
67
|
+
getCurrentSession(): Promise<Session>;
|
|
54
68
|
/**
|
|
55
69
|
* Resume an existing session by ID.
|
|
56
|
-
* Use this when
|
|
57
|
-
*
|
|
58
|
-
* @param sessionId - The ID of the existing session to resume
|
|
70
|
+
* Use this when you need to explicitly attach to a known session.
|
|
59
71
|
*/
|
|
60
72
|
resumeSession(sessionId: string): Promise<Session>;
|
|
61
73
|
/**
|
|
@@ -66,10 +78,9 @@ export declare class AgentRein {
|
|
|
66
78
|
* 3. On failure, triggers server-side rollback
|
|
67
79
|
*
|
|
68
80
|
* @param fn - The function to execute
|
|
69
|
-
* @param session - The active AgentRein session
|
|
70
81
|
* @param args - Arguments forwarded to fn
|
|
71
82
|
*/
|
|
72
|
-
call<T>(fn: Function,
|
|
73
|
-
call<T>(fn: Function,
|
|
83
|
+
call<T>(fn: Function, ...args: any[]): Promise<T>;
|
|
84
|
+
call<T>(fn: Function, undoConfig: UndoConfig, ...args: any[]): Promise<T>;
|
|
74
85
|
}
|
|
75
86
|
export default AgentRein;
|
|
@@ -60,18 +60,45 @@ class AgentRein {
|
|
|
60
60
|
const res = await axios_1.default.post(`${this.serverUrl}/sessions`, { agentId, intent }, { headers });
|
|
61
61
|
return res.data.data;
|
|
62
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Start a new workflow session.
|
|
65
|
+
* All subsequent agentrein.call() will be logged under this session automatically.
|
|
66
|
+
*/
|
|
67
|
+
async startWorkflow(options) {
|
|
68
|
+
const session = await this.newSession(options);
|
|
69
|
+
AgentRein.activeSessions.set(this.apiKey, session);
|
|
70
|
+
return session;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* End the current workflow and clear the internal session state.
|
|
74
|
+
*/
|
|
75
|
+
async endWorkflow() {
|
|
76
|
+
AgentRein.activeSessions.delete(this.apiKey);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get the current active session, or create one automatically if none exists.
|
|
80
|
+
*/
|
|
81
|
+
async getCurrentSession() {
|
|
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;
|
|
88
|
+
}
|
|
63
89
|
/**
|
|
64
90
|
* Resume an existing session by ID.
|
|
65
|
-
* Use this when
|
|
66
|
-
*
|
|
67
|
-
* @param sessionId - The ID of the existing session to resume
|
|
91
|
+
* Use this when you need to explicitly attach to a known session.
|
|
68
92
|
*/
|
|
69
93
|
async resumeSession(sessionId) {
|
|
70
94
|
const headers = await this.authHeaders();
|
|
71
95
|
const res = await axios_1.default.get(`${this.serverUrl}/sessions/${sessionId}`, { headers });
|
|
72
|
-
|
|
96
|
+
const session = res.data.data;
|
|
97
|
+
AgentRein.activeSessions.set(this.apiKey, session);
|
|
98
|
+
return session;
|
|
73
99
|
}
|
|
74
|
-
async call(fn,
|
|
100
|
+
async call(fn, ...args) {
|
|
101
|
+
const session = await this.getCurrentSession();
|
|
75
102
|
// Detect if first extra arg is an UndoConfig object
|
|
76
103
|
let undoConfig;
|
|
77
104
|
let callArgs = args;
|
|
@@ -104,4 +131,5 @@ class AgentRein {
|
|
|
104
131
|
}
|
|
105
132
|
}
|
|
106
133
|
exports.AgentRein = AgentRein;
|
|
134
|
+
AgentRein.activeSessions = new Map();
|
|
107
135
|
exports.default = AgentRein;
|
|
@@ -57,18 +57,45 @@ export class AgentRein {
|
|
|
57
57
|
const res = await axios.post(`${this.serverUrl}/sessions`, { agentId, intent }, { headers });
|
|
58
58
|
return res.data.data;
|
|
59
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Start a new workflow session.
|
|
62
|
+
* All subsequent agentrein.call() will be logged under this session automatically.
|
|
63
|
+
*/
|
|
64
|
+
async startWorkflow(options) {
|
|
65
|
+
const session = await this.newSession(options);
|
|
66
|
+
AgentRein.activeSessions.set(this.apiKey, session);
|
|
67
|
+
return session;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* End the current workflow and clear the internal session state.
|
|
71
|
+
*/
|
|
72
|
+
async endWorkflow() {
|
|
73
|
+
AgentRein.activeSessions.delete(this.apiKey);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get the current active session, or create one automatically if none exists.
|
|
77
|
+
*/
|
|
78
|
+
async getCurrentSession() {
|
|
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;
|
|
85
|
+
}
|
|
60
86
|
/**
|
|
61
87
|
* Resume an existing session by ID.
|
|
62
|
-
* Use this when
|
|
63
|
-
*
|
|
64
|
-
* @param sessionId - The ID of the existing session to resume
|
|
88
|
+
* Use this when you need to explicitly attach to a known session.
|
|
65
89
|
*/
|
|
66
90
|
async resumeSession(sessionId) {
|
|
67
91
|
const headers = await this.authHeaders();
|
|
68
92
|
const res = await axios.get(`${this.serverUrl}/sessions/${sessionId}`, { headers });
|
|
69
|
-
|
|
93
|
+
const session = res.data.data;
|
|
94
|
+
AgentRein.activeSessions.set(this.apiKey, session);
|
|
95
|
+
return session;
|
|
70
96
|
}
|
|
71
|
-
async call(fn,
|
|
97
|
+
async call(fn, ...args) {
|
|
98
|
+
const session = await this.getCurrentSession();
|
|
72
99
|
// Detect if first extra arg is an UndoConfig object
|
|
73
100
|
let undoConfig;
|
|
74
101
|
let callArgs = args;
|
|
@@ -100,4 +127,5 @@ export class AgentRein {
|
|
|
100
127
|
}
|
|
101
128
|
}
|
|
102
129
|
}
|
|
130
|
+
AgentRein.activeSessions = new Map();
|
|
103
131
|
export default AgentRein;
|