agentrein 1.0.13 → 1.0.15

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,6 @@ export declare class AgentRein {
33
33
  private readonly apiKey;
34
34
  private readonly failureMode;
35
35
  private token;
36
- private static activeSessions;
37
36
  constructor(options: AgentReinOptions);
38
37
  /**
39
38
  * Obtain a JWT token from the AgentRein server using the API key.
@@ -52,24 +51,14 @@ export declare class AgentRein {
52
51
  * If omitted, a random agentId is generated.
53
52
  */
54
53
  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>;
68
54
  /**
69
55
  * Resume an existing session by ID.
70
- * Use this when you need to explicitly attach to a known session.
71
56
  */
72
57
  resumeSession(sessionId: string): Promise<Session>;
58
+ /**
59
+ * Get a session by ID — alias for resumeSession.
60
+ */
61
+ getSession(sessionId: string): Promise<Session>;
73
62
  /**
74
63
  * Execute an API call under AgentRein's protection.
75
64
  *
@@ -78,9 +67,10 @@ export declare class AgentRein {
78
67
  * 3. On failure, triggers server-side rollback
79
68
  *
80
69
  * @param fn - The function to execute
70
+ * @param session - The active AgentRein session
81
71
  * @param args - Arguments forwarded to fn
82
72
  */
83
- call<T>(fn: Function, ...args: any[]): Promise<T>;
84
- call<T>(fn: Function, undoConfig: UndoConfig, ...args: any[]): Promise<T>;
73
+ call<T>(fn: Function, session: Session, ...args: any[]): Promise<T>;
74
+ call<T>(fn: Function, session: Session, undoConfig: UndoConfig, ...args: any[]): Promise<T>;
85
75
  }
86
76
  export default AgentRein;
@@ -60,45 +60,22 @@ 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
+ // ── resumeSession & getSession ────────────────────────
89
64
  /**
90
65
  * Resume an existing session by ID.
91
- * Use this when you need to explicitly attach to a known session.
92
66
  */
93
67
  async resumeSession(sessionId) {
94
68
  const headers = await this.authHeaders();
95
69
  const res = await axios_1.default.get(`${this.serverUrl}/sessions/${sessionId}`, { headers });
96
- const session = res.data.data;
97
- AgentRein.activeSessions.set(this.apiKey, session);
98
- return session;
70
+ return res.data.data;
71
+ }
72
+ /**
73
+ * Get a session by ID — alias for resumeSession.
74
+ */
75
+ async getSession(sessionId) {
76
+ return this.resumeSession(sessionId);
99
77
  }
100
- async call(fn, ...args) {
101
- const session = await this.getCurrentSession();
78
+ async call(fn, session, ...args) {
102
79
  // Detect if first extra arg is an UndoConfig object
103
80
  let undoConfig;
104
81
  let callArgs = args;
@@ -131,5 +108,4 @@ class AgentRein {
131
108
  }
132
109
  }
133
110
  exports.AgentRein = AgentRein;
134
- AgentRein.activeSessions = new Map();
135
111
  exports.default = AgentRein;
@@ -57,45 +57,22 @@ 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
+ // ── resumeSession & getSession ────────────────────────
86
61
  /**
87
62
  * Resume an existing session by ID.
88
- * Use this when you need to explicitly attach to a known session.
89
63
  */
90
64
  async resumeSession(sessionId) {
91
65
  const headers = await this.authHeaders();
92
66
  const res = await axios.get(`${this.serverUrl}/sessions/${sessionId}`, { headers });
93
- const session = res.data.data;
94
- AgentRein.activeSessions.set(this.apiKey, session);
95
- return session;
67
+ return res.data.data;
68
+ }
69
+ /**
70
+ * Get a session by ID — alias for resumeSession.
71
+ */
72
+ async getSession(sessionId) {
73
+ return this.resumeSession(sessionId);
96
74
  }
97
- async call(fn, ...args) {
98
- const session = await this.getCurrentSession();
75
+ async call(fn, session, ...args) {
99
76
  // Detect if first extra arg is an UndoConfig object
100
77
  let undoConfig;
101
78
  let callArgs = args;
@@ -127,5 +104,4 @@ export class AgentRein {
127
104
  }
128
105
  }
129
106
  }
130
- AgentRein.activeSessions = new Map();
131
107
  export default AgentRein;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentrein",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "main": "./dist/cjs/agentreinClient.js",
5
5
  "module": "./dist/esm/agentreinClient.js",
6
6
  "types": "./dist/cjs/agentreinClient.d.ts",