agentrein 1.0.11 → 1.0.12
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 currentSession;
|
|
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;
|
|
@@ -12,6 +12,7 @@ function createUndoConfig(config) {
|
|
|
12
12
|
class AgentRein {
|
|
13
13
|
constructor(options) {
|
|
14
14
|
this.token = null;
|
|
15
|
+
this.currentSession = null;
|
|
15
16
|
this.serverUrl = options.serverUrl || 'https://api.agentrein.com';
|
|
16
17
|
this.apiKey = options.apiKey;
|
|
17
18
|
this.failureMode = options.failureMode ?? 'open';
|
|
@@ -60,18 +61,41 @@ class AgentRein {
|
|
|
60
61
|
const res = await axios_1.default.post(`${this.serverUrl}/sessions`, { agentId, intent }, { headers });
|
|
61
62
|
return res.data.data;
|
|
62
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Start a new workflow session.
|
|
66
|
+
* All subsequent agentrein.call() will be logged under this session automatically.
|
|
67
|
+
*/
|
|
68
|
+
async startWorkflow(options) {
|
|
69
|
+
this.currentSession = await this.newSession(options);
|
|
70
|
+
return this.currentSession;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* End the current workflow and clear the internal session state.
|
|
74
|
+
*/
|
|
75
|
+
async endWorkflow() {
|
|
76
|
+
this.currentSession = null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get the current active session, or create one automatically if none exists.
|
|
80
|
+
*/
|
|
81
|
+
async getCurrentSession() {
|
|
82
|
+
if (!this.currentSession) {
|
|
83
|
+
this.currentSession = await this.newSession();
|
|
84
|
+
}
|
|
85
|
+
return this.currentSession;
|
|
86
|
+
}
|
|
63
87
|
/**
|
|
64
88
|
* Resume an existing session by ID.
|
|
65
|
-
* Use this when
|
|
66
|
-
*
|
|
67
|
-
* @param sessionId - The ID of the existing session to resume
|
|
89
|
+
* Use this when you need to explicitly attach to a known session.
|
|
68
90
|
*/
|
|
69
91
|
async resumeSession(sessionId) {
|
|
70
92
|
const headers = await this.authHeaders();
|
|
71
93
|
const res = await axios_1.default.get(`${this.serverUrl}/sessions/${sessionId}`, { headers });
|
|
72
|
-
|
|
94
|
+
this.currentSession = res.data.data;
|
|
95
|
+
return this.currentSession;
|
|
73
96
|
}
|
|
74
|
-
async call(fn,
|
|
97
|
+
async call(fn, ...args) {
|
|
98
|
+
const session = await this.getCurrentSession();
|
|
75
99
|
// Detect if first extra arg is an UndoConfig object
|
|
76
100
|
let undoConfig;
|
|
77
101
|
let callArgs = args;
|
|
@@ -9,6 +9,7 @@ export { AgentReinUnavailableError };
|
|
|
9
9
|
export class AgentRein {
|
|
10
10
|
constructor(options) {
|
|
11
11
|
this.token = null;
|
|
12
|
+
this.currentSession = null;
|
|
12
13
|
this.serverUrl = options.serverUrl || 'https://api.agentrein.com';
|
|
13
14
|
this.apiKey = options.apiKey;
|
|
14
15
|
this.failureMode = options.failureMode ?? 'open';
|
|
@@ -57,18 +58,41 @@ export class AgentRein {
|
|
|
57
58
|
const res = await axios.post(`${this.serverUrl}/sessions`, { agentId, intent }, { headers });
|
|
58
59
|
return res.data.data;
|
|
59
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Start a new workflow session.
|
|
63
|
+
* All subsequent agentrein.call() will be logged under this session automatically.
|
|
64
|
+
*/
|
|
65
|
+
async startWorkflow(options) {
|
|
66
|
+
this.currentSession = await this.newSession(options);
|
|
67
|
+
return this.currentSession;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* End the current workflow and clear the internal session state.
|
|
71
|
+
*/
|
|
72
|
+
async endWorkflow() {
|
|
73
|
+
this.currentSession = null;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get the current active session, or create one automatically if none exists.
|
|
77
|
+
*/
|
|
78
|
+
async getCurrentSession() {
|
|
79
|
+
if (!this.currentSession) {
|
|
80
|
+
this.currentSession = await this.newSession();
|
|
81
|
+
}
|
|
82
|
+
return this.currentSession;
|
|
83
|
+
}
|
|
60
84
|
/**
|
|
61
85
|
* Resume an existing session by ID.
|
|
62
|
-
* Use this when
|
|
63
|
-
*
|
|
64
|
-
* @param sessionId - The ID of the existing session to resume
|
|
86
|
+
* Use this when you need to explicitly attach to a known session.
|
|
65
87
|
*/
|
|
66
88
|
async resumeSession(sessionId) {
|
|
67
89
|
const headers = await this.authHeaders();
|
|
68
90
|
const res = await axios.get(`${this.serverUrl}/sessions/${sessionId}`, { headers });
|
|
69
|
-
|
|
91
|
+
this.currentSession = res.data.data;
|
|
92
|
+
return this.currentSession;
|
|
70
93
|
}
|
|
71
|
-
async call(fn,
|
|
94
|
+
async call(fn, ...args) {
|
|
95
|
+
const session = await this.getCurrentSession();
|
|
72
96
|
// Detect if first extra arg is an UndoConfig object
|
|
73
97
|
let undoConfig;
|
|
74
98
|
let callArgs = args;
|