honeyhive 0.3.11 → 0.3.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.
@@ -119,7 +119,7 @@ export declare class SessionTracer {
119
119
  private user_properties;
120
120
  private source;
121
121
  private eventStack;
122
- private sdk;
122
+ private client;
123
123
  private session_id;
124
124
  private parentEvent;
125
125
  constructor(api_key: string, project: string, session_name: string, user_properties?: {
@@ -60,10 +60,13 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
60
60
  }
61
61
  return to.concat(ar || Array.prototype.slice.call(from));
62
62
  };
63
+ var __importDefault = (this && this.__importDefault) || function (mod) {
64
+ return (mod && mod.__esModule) ? mod : { "default": mod };
65
+ };
63
66
  Object.defineProperty(exports, "__esModule", { value: true });
64
67
  exports.SessionTracer = exports.ChatRole = void 0;
65
68
  var uuid_1 = require("uuid");
66
- var sdk_1 = require("./sdk");
69
+ var axios_1 = __importDefault(require("axios"));
67
70
  var ChatRole;
68
71
  (function (ChatRole) {
69
72
  ChatRole["User"] = "user";
@@ -80,25 +83,30 @@ var SessionTracer = /** @class */ (function () {
80
83
  this.user_properties = user_properties;
81
84
  this.source = source;
82
85
  this.eventStack = [];
83
- this.sdk = new sdk_1.HoneyHive({
84
- bearerAuth: api_key,
86
+ this.client = axios_1.default.create({
87
+ headers: {
88
+ Authorization: "Bearer " + api_key,
89
+ },
85
90
  });
86
91
  this.session_id = "";
87
92
  this.parentEvent = {};
88
93
  }
89
94
  SessionTracer.prototype.startSession = function (inputs) {
90
- var _a;
91
95
  return __awaiter(this, void 0, void 0, function () {
92
- var session, res, session_id, _b;
93
- return __generator(this, function (_c) {
94
- switch (_c.label) {
96
+ var session, res, _a;
97
+ return __generator(this, function (_b) {
98
+ switch (_b.label) {
95
99
  case 0:
96
- _c.trys.push([0, 2, , 3]);
100
+ _b.trys.push([0, 2, , 3]);
101
+ this.session_id = (0, uuid_1.v4)();
97
102
  session = {
98
103
  project: this.project,
99
104
  source: this.source,
100
- sessionName: this.session_name,
101
- userProperties: this.user_properties,
105
+ session_name: this.session_name,
106
+ user_properties: this.user_properties,
107
+ inputs: inputs || {},
108
+ event_id: this.session_id,
109
+ session_id: this.session_id,
102
110
  };
103
111
  this.parentEvent = {
104
112
  project: this.project,
@@ -114,23 +122,16 @@ var SessionTracer = /** @class */ (function () {
114
122
  metrics: {},
115
123
  feedback: {},
116
124
  event_id: (0, uuid_1.v4)(),
125
+ session_id: this.session_id,
117
126
  };
118
- return [4 /*yield*/, this.sdk.session.startSession({
127
+ return [4 /*yield*/, this.client.post("https://api.honeyhive.ai/session/start", {
119
128
  session: session,
120
129
  })];
121
130
  case 1:
122
- res = _c.sent();
123
- session_id = (_a = res.object) === null || _a === void 0 ? void 0 : _a.sessionId;
124
- if (session_id) {
125
- this.session_id = session_id;
126
- }
127
- else {
128
- throw new Error("Session start failed!");
129
- }
130
- this.parentEvent.session_id = this.session_id;
131
+ res = _b.sent();
131
132
  return [3 /*break*/, 3];
132
133
  case 2:
133
- _b = _c.sent();
134
+ _a = _b.sent();
134
135
  return [3 /*break*/, 3];
135
136
  case 3: return [2 /*return*/];
136
137
  }
@@ -194,7 +195,7 @@ var SessionTracer = /** @class */ (function () {
194
195
  return __generator(this, function (_b) {
195
196
  switch (_b.label) {
196
197
  case 0:
197
- _b.trys.push([0, 3, , 4]);
198
+ _b.trys.push([0, 4, , 5]);
198
199
  while (this.eventStack.length > 0) {
199
200
  this.endEvent();
200
201
  }
@@ -205,23 +206,24 @@ var SessionTracer = /** @class */ (function () {
205
206
  if (error) {
206
207
  session_trace.error = error;
207
208
  }
208
- if (!session_trace) return [3 /*break*/, 2];
209
- return [4 /*yield*/, this.sdk.session.processEventTrace(this.session_id, { logs: [session_trace] })];
209
+ if (!session_trace) return [3 /*break*/, 3];
210
+ return [4 /*yield*/, this.client.post("https://api.honeyhive.ai/session/".concat(this.session_id, "/traces"), {
211
+ logs: [session_trace],
212
+ })];
210
213
  case 1:
211
214
  res = _b.sent();
212
- if (res.statusCode == 200) {
213
- // handle response
214
- console.log('Session trace sent successfully.');
215
- }
216
- else {
217
- console.error('Failed to send session trace:', res);
218
- }
219
- _b.label = 2;
220
- case 2: return [3 /*break*/, 4];
221
- case 3:
215
+ return [4 /*yield*/, this.client.put("https://api.honeyhive.ai/events", {
216
+ event_id: this.session_id,
217
+ outputs: outputs,
218
+ })];
219
+ case 2:
220
+ _b.sent();
221
+ _b.label = 3;
222
+ case 3: return [3 /*break*/, 5];
223
+ case 4:
222
224
  _a = _b.sent();
223
- return [3 /*break*/, 4];
224
- case 4: return [2 /*return*/];
225
+ return [3 /*break*/, 5];
226
+ case 5: return [2 /*return*/];
225
227
  }
226
228
  });
227
229
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "honeyhive",
3
- "version": "0.3.11",
3
+ "version": "0.3.12",
4
4
  "author": "HoneyHive",
5
5
  "scripts": {
6
6
  "prepare": "tsc --build",