agentrein 1.0.9 → 1.0.11

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.
@@ -9,11 +9,15 @@ export interface SessionOptions {
9
9
  intent?: string;
10
10
  }
11
11
  export interface UndoConfig {
12
- type: 'slack-correction' | 'http-delete' | 'none';
12
+ __isUndoConfig: true;
13
+ type?: 'slack-correction' | 'http-delete' | 'none' | string;
13
14
  url?: string;
14
15
  headers?: Record<string, string>;
15
16
  body?: Record<string, unknown>;
17
+ action?: string;
18
+ rollback?: (response: any) => Promise<void>;
16
19
  }
20
+ export declare function createUndoConfig(config: Omit<UndoConfig, '__isUndoConfig'>): UndoConfig;
17
21
  export interface Session {
18
22
  id: string;
19
23
  organizationId: string;
@@ -47,6 +51,13 @@ export declare class AgentRein {
47
51
  * If omitted, a random agentId is generated.
48
52
  */
49
53
  newSession(options?: SessionOptions | string): Promise<Session>;
54
+ /**
55
+ * Resume an existing session by ID.
56
+ * Use this when multiple tools or steps need to share the same session.
57
+ *
58
+ * @param sessionId - The ID of the existing session to resume
59
+ */
60
+ resumeSession(sessionId: string): Promise<Session>;
50
61
  /**
51
62
  * Execute an API call under AgentRein's protection.
52
63
  *
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AgentRein = exports.AgentReinUnavailableError = void 0;
4
+ exports.createUndoConfig = createUndoConfig;
4
5
  const axios_1 = require("axios");
5
6
  const errors_1 = require("./errors");
6
7
  Object.defineProperty(exports, "AgentReinUnavailableError", { enumerable: true, get: function () { return errors_1.AgentReinUnavailableError; } });
8
+ function createUndoConfig(config) {
9
+ return { __isUndoConfig: true, ...config };
10
+ }
7
11
  // ─── AgentRein Client ─────────────────────────────────────
8
12
  class AgentRein {
9
13
  constructor(options) {
@@ -56,6 +60,17 @@ class AgentRein {
56
60
  const res = await axios_1.default.post(`${this.serverUrl}/sessions`, { agentId, intent }, { headers });
57
61
  return res.data.data;
58
62
  }
63
+ /**
64
+ * Resume an existing session by ID.
65
+ * Use this when multiple tools or steps need to share the same session.
66
+ *
67
+ * @param sessionId - The ID of the existing session to resume
68
+ */
69
+ async resumeSession(sessionId) {
70
+ const headers = await this.authHeaders();
71
+ const res = await axios_1.default.get(`${this.serverUrl}/sessions/${sessionId}`, { headers });
72
+ return res.data.data;
73
+ }
59
74
  async call(fn, session, ...args) {
60
75
  // Detect if first extra arg is an UndoConfig object
61
76
  let undoConfig;
@@ -63,8 +78,7 @@ class AgentRein {
63
78
  if (args.length > 0 &&
64
79
  args[0] &&
65
80
  typeof args[0] === 'object' &&
66
- 'type' in args[0] &&
67
- ['slack-correction', 'http-delete', 'none'].includes(args[0].type)) {
81
+ '__isUndoConfig' in args[0]) {
68
82
  undoConfig = args[0];
69
83
  callArgs = args.slice(1);
70
84
  }
@@ -1,5 +1,8 @@
1
1
  import axios from 'axios';
2
2
  import { AgentReinUnavailableError } from './errors';
3
+ export function createUndoConfig(config) {
4
+ return { __isUndoConfig: true, ...config };
5
+ }
3
6
  // Re-export errors for consumer convenience
4
7
  export { AgentReinUnavailableError };
5
8
  // ─── AgentRein Client ─────────────────────────────────────
@@ -54,6 +57,17 @@ export class AgentRein {
54
57
  const res = await axios.post(`${this.serverUrl}/sessions`, { agentId, intent }, { headers });
55
58
  return res.data.data;
56
59
  }
60
+ /**
61
+ * Resume an existing session by ID.
62
+ * Use this when multiple tools or steps need to share the same session.
63
+ *
64
+ * @param sessionId - The ID of the existing session to resume
65
+ */
66
+ async resumeSession(sessionId) {
67
+ const headers = await this.authHeaders();
68
+ const res = await axios.get(`${this.serverUrl}/sessions/${sessionId}`, { headers });
69
+ return res.data.data;
70
+ }
57
71
  async call(fn, session, ...args) {
58
72
  // Detect if first extra arg is an UndoConfig object
59
73
  let undoConfig;
@@ -61,8 +75,7 @@ export class AgentRein {
61
75
  if (args.length > 0 &&
62
76
  args[0] &&
63
77
  typeof args[0] === 'object' &&
64
- 'type' in args[0] &&
65
- ['slack-correction', 'http-delete', 'none'].includes(args[0].type)) {
78
+ '__isUndoConfig' in args[0]) {
66
79
  undoConfig = args[0];
67
80
  callArgs = args.slice(1);
68
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentrein",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "main": "./dist/cjs/agentreinClient.js",
5
5
  "module": "./dist/esm/agentreinClient.js",
6
6
  "types": "./dist/cjs/agentreinClient.d.ts",