honeyhive 0.3.11 → 0.3.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.
package/dist/sdk/sdk.js CHANGED
@@ -48,9 +48,9 @@ var SDKConfiguration = /** @class */ (function () {
48
48
  function SDKConfiguration(init) {
49
49
  this.language = "typescript";
50
50
  this.openapiDocVersion = "1.0.1";
51
- this.sdkVersion = "0.3.1";
52
- this.genVersion = "2.279.1";
53
- this.userAgent = "speakeasy-sdk/typescript 0.3.1 2.279.1 1.0.1 HoneyHive";
51
+ this.sdkVersion = "0.3.2";
52
+ this.genVersion = "2.281.2";
53
+ this.userAgent = "speakeasy-sdk/typescript 0.3.2 2.281.2 1.0.1 HoneyHive";
54
54
  Object.assign(this, init);
55
55
  }
56
56
  return SDKConfiguration;
@@ -60,8 +60,11 @@ var HoneyHive = /** @class */ (function () {
60
60
  function HoneyHive(props) {
61
61
  var _a, _b;
62
62
  var serverURL = props === null || props === void 0 ? void 0 : props.serverURL;
63
- var serverIdx = (_a = props === null || props === void 0 ? void 0 : props.serverIdx) !== null && _a !== void 0 ? _a : 0;
64
63
  if (!serverURL) {
64
+ var serverIdx = (_a = props === null || props === void 0 ? void 0 : props.serverIdx) !== null && _a !== void 0 ? _a : 0;
65
+ if (serverIdx < 0 || serverIdx >= exports.ServerList.length) {
66
+ throw new Error("Invalid server index ".concat(serverIdx));
67
+ }
65
68
  serverURL = exports.ServerList[serverIdx];
66
69
  }
67
70
  var defaultClient = (_b = props === null || props === void 0 ? void 0 : props.defaultClient) !== null && _b !== void 0 ? _b : axios_1.default.create();
@@ -119,12 +119,13 @@ 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?: {
126
126
  [key: string]: any;
127
127
  }, source?: string);
128
+ getSessionId(): string;
128
129
  startSession(inputs?: {
129
130
  [key: string]: any;
130
131
  }): Promise<void>;
@@ -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,33 @@ 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
  }
94
+ SessionTracer.prototype.getSessionId = function () {
95
+ return this.session_id;
96
+ };
89
97
  SessionTracer.prototype.startSession = function (inputs) {
90
- var _a;
91
98
  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) {
99
+ var session, _a;
100
+ return __generator(this, function (_b) {
101
+ switch (_b.label) {
95
102
  case 0:
96
- _c.trys.push([0, 2, , 3]);
103
+ _b.trys.push([0, 2, , 3]);
104
+ this.session_id = (0, uuid_1.v4)();
97
105
  session = {
98
106
  project: this.project,
99
107
  source: this.source,
100
- sessionName: this.session_name,
101
- userProperties: this.user_properties,
108
+ session_name: this.session_name,
109
+ user_properties: this.user_properties,
110
+ inputs: inputs || {},
111
+ event_id: this.session_id,
112
+ session_id: this.session_id,
102
113
  };
103
114
  this.parentEvent = {
104
115
  project: this.project,
@@ -114,23 +125,16 @@ var SessionTracer = /** @class */ (function () {
114
125
  metrics: {},
115
126
  feedback: {},
116
127
  event_id: (0, uuid_1.v4)(),
128
+ session_id: this.session_id,
117
129
  };
118
- return [4 /*yield*/, this.sdk.session.startSession({
130
+ return [4 /*yield*/, this.client.post("https://api.honeyhive.ai/session/start", {
119
131
  session: session,
120
132
  })];
121
133
  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;
134
+ _b.sent();
131
135
  return [3 /*break*/, 3];
132
136
  case 2:
133
- _b = _c.sent();
137
+ _a = _b.sent();
134
138
  return [3 /*break*/, 3];
135
139
  case 3: return [2 /*return*/];
136
140
  }
@@ -190,11 +194,11 @@ var SessionTracer = /** @class */ (function () {
190
194
  };
191
195
  SessionTracer.prototype.endSession = function (outputs, error) {
192
196
  return __awaiter(this, void 0, void 0, function () {
193
- var session_trace, res, _a;
197
+ var session_trace, _a;
194
198
  return __generator(this, function (_b) {
195
199
  switch (_b.label) {
196
200
  case 0:
197
- _b.trys.push([0, 3, , 4]);
201
+ _b.trys.push([0, 4, , 5]);
198
202
  while (this.eventStack.length > 0) {
199
203
  this.endEvent();
200
204
  }
@@ -205,23 +209,24 @@ var SessionTracer = /** @class */ (function () {
205
209
  if (error) {
206
210
  session_trace.error = error;
207
211
  }
208
- if (!session_trace) return [3 /*break*/, 2];
209
- return [4 /*yield*/, this.sdk.session.processEventTrace(this.session_id, { logs: [session_trace] })];
212
+ if (!session_trace) return [3 /*break*/, 3];
213
+ return [4 /*yield*/, this.client.post("https://api.honeyhive.ai/session/".concat(this.session_id, "/traces"), {
214
+ logs: [session_trace],
215
+ })];
210
216
  case 1:
211
- 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:
217
+ _b.sent();
218
+ return [4 /*yield*/, this.client.put("https://api.honeyhive.ai/events", {
219
+ event_id: this.session_id,
220
+ outputs: outputs,
221
+ })];
222
+ case 2:
223
+ _b.sent();
224
+ _b.label = 3;
225
+ case 3: return [3 /*break*/, 5];
226
+ case 4:
222
227
  _a = _b.sent();
223
- return [3 /*break*/, 4];
224
- case 4: return [2 /*return*/];
228
+ return [3 /*break*/, 5];
229
+ case 5: return [2 /*return*/];
225
230
  }
226
231
  });
227
232
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "honeyhive",
3
- "version": "0.3.11",
3
+ "version": "0.3.13",
4
4
  "author": "HoneyHive",
5
5
  "scripts": {
6
6
  "prepare": "tsc --build",