@terreno/ai 57.3.0 → 57.6.0

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/README.md CHANGED
@@ -43,8 +43,8 @@ This mounts GPT chat (`POST /gpt/prompt`), history CRUD (`/gpt/histories`), proj
43
43
 
44
44
  ## Documentation
45
45
 
46
- Full API reference: [docs/reference/ai.md](https://github.com/flourishhealth/terreno/blob/master/docs/reference/ai.md)
46
+ Full API reference: [docs/reference/ai.md](https://github.com/TerrenoLabs/terreno/blob/master/docs/reference/ai.md)
47
47
 
48
48
  ## License and Contributing
49
49
 
50
- Licensed under the [MIT License](https://github.com/flourishhealth/terreno/blob/master/LICENSE). See [CONTRIBUTING.md](https://github.com/flourishhealth/terreno/blob/master/CONTRIBUTING.md) for contribution guidelines.
50
+ Licensed under the [MIT License](https://github.com/TerrenoLabs/terreno/blob/master/LICENSE). See [CONTRIBUTING.md](https://github.com/TerrenoLabs/terreno/blob/master/CONTRIBUTING.md) for contribution guidelines.
@@ -1,23 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AIAdminApp = void 0;
4
- var aiRequestsExplorer_1 = require("./routes/aiRequestsExplorer");
4
+ const aiRequestsExplorer_1 = require("./routes/aiRequestsExplorer");
5
5
  /**
6
6
  * Registers the AI request explorer API and contributes its admin screen metadata.
7
7
  */
8
- var AIAdminApp = /** @class */ (function () {
9
- function AIAdminApp(options) {
10
- if (options === void 0) { options = {}; }
8
+ class AIAdminApp {
9
+ options;
10
+ constructor(options = {}) {
11
11
  this.options = options;
12
12
  }
13
- AIAdminApp.prototype.adminContribution = function () {
13
+ adminContribution() {
14
14
  return {
15
15
  customScreens: [{ displayName: "AI Requests", icon: "robot", name: "ai-requests" }],
16
16
  };
17
- };
18
- AIAdminApp.prototype.register = function (app) {
17
+ }
18
+ register(app) {
19
19
  (0, aiRequestsExplorer_1.addAiRequestsExplorerRoutes)(app, { openApiOptions: this.options.openApiOptions });
20
- };
21
- return AIAdminApp;
22
- }());
20
+ }
21
+ }
23
22
  exports.AIAdminApp = AIAdminApp;
package/dist/aiApp.js CHANGED
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AiApp = void 0;
4
- var aiRequestsExplorer_1 = require("./routes/aiRequestsExplorer");
5
- var files_1 = require("./routes/files");
6
- var gpt_1 = require("./routes/gpt");
7
- var gptHistories_1 = require("./routes/gptHistories");
8
- var mcp_1 = require("./routes/mcp");
9
- var projects_1 = require("./routes/projects");
4
+ const aiRequestsExplorer_1 = require("./routes/aiRequestsExplorer");
5
+ const files_1 = require("./routes/files");
6
+ const gpt_1 = require("./routes/gpt");
7
+ const gptHistories_1 = require("./routes/gptHistories");
8
+ const mcp_1 = require("./routes/mcp");
9
+ const projects_1 = require("./routes/projects");
10
10
  /**
11
11
  * TerrenoPlugin that mounts all AI routes (GPT chat, history, file uploads, MCP, admin explorer).
12
12
  *
@@ -33,39 +33,39 @@ var projects_1 = require("./routes/projects");
33
33
  * }).register(app);
34
34
  * ```
35
35
  */
36
- var AiApp = /** @class */ (function () {
37
- function AiApp(options) {
36
+ class AiApp {
37
+ options;
38
+ constructor(options) {
38
39
  this.options = options;
39
40
  }
40
- AiApp.prototype.register = function (app) {
41
- var router = app;
42
- var _a = this.options, aiService = _a.aiService, createModelFn = _a.createModelFn, createServerModelFn = _a.createServerModelFn, demoMode = _a.demoMode, fileStorageService = _a.fileStorageService, gcsBucket = _a.gcsBucket, maxSteps = _a.maxSteps, mcpService = _a.mcpService, openApiOptions = _a.openApiOptions, titleModelId = _a.titleModelId, toolChoice = _a.toolChoice, tools = _a.tools;
43
- (0, gptHistories_1.addGptHistoryRoutes)(router, { openApiOptions: openApiOptions });
41
+ register(app) {
42
+ const router = app;
43
+ const { aiService, createModelFn, createServerModelFn, demoMode, fileStorageService, gcsBucket, maxSteps, mcpService, openApiOptions, titleModelId, toolChoice, tools, } = this.options;
44
+ (0, gptHistories_1.addGptHistoryRoutes)(router, { openApiOptions });
44
45
  (0, gpt_1.addGptRoutes)(router, {
45
- aiService: aiService,
46
- createModelFn: createModelFn,
47
- createServerModelFn: createServerModelFn,
48
- demoMode: demoMode,
49
- maxSteps: maxSteps,
50
- mcpService: mcpService,
51
- openApiOptions: openApiOptions,
52
- titleModelId: titleModelId,
53
- toolChoice: toolChoice,
54
- tools: tools,
46
+ aiService,
47
+ createModelFn,
48
+ createServerModelFn,
49
+ demoMode,
50
+ maxSteps,
51
+ mcpService,
52
+ openApiOptions,
53
+ titleModelId,
54
+ toolChoice,
55
+ tools,
55
56
  });
56
- (0, aiRequestsExplorer_1.addAiRequestsExplorerRoutes)(router, { openApiOptions: openApiOptions });
57
- (0, projects_1.addProjectRoutes)(router, { openApiOptions: openApiOptions });
57
+ (0, aiRequestsExplorer_1.addAiRequestsExplorerRoutes)(router, { openApiOptions });
58
+ (0, projects_1.addProjectRoutes)(router, { openApiOptions });
58
59
  if (fileStorageService && gcsBucket) {
59
60
  (0, files_1.addFileRoutes)(router, {
60
- fileStorageService: fileStorageService,
61
- gcsBucket: gcsBucket,
62
- openApiOptions: openApiOptions,
61
+ fileStorageService,
62
+ gcsBucket,
63
+ openApiOptions,
63
64
  });
64
65
  }
65
66
  if (mcpService) {
66
- (0, mcp_1.addMcpRoutes)(router, { mcpService: mcpService, openApiOptions: openApiOptions });
67
+ (0, mcp_1.addMcpRoutes)(router, { mcpService, openApiOptions });
67
68
  }
68
- };
69
- return AiApp;
70
- }());
69
+ }
70
+ }
71
71
  exports.AiApp = AiApp;
@@ -1,96 +1,53 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.LangfuseApp = void 0;
40
- var api_1 = require("@terreno/api");
41
- var langfuseClient_1 = require("./langfuseClient");
42
- var langfuseRoutesEvaluations_1 = require("./langfuseRoutesEvaluations");
43
- var langfuseRoutesPlayground_1 = require("./langfuseRoutesPlayground");
44
- var langfuseRoutesPrompts_1 = require("./langfuseRoutesPrompts");
45
- var langfuseRoutesTraces_1 = require("./langfuseRoutesTraces");
46
- var langfuseTracing_1 = require("./langfuseTracing");
47
- var LangfuseApp = /** @class */ (function () {
48
- function LangfuseApp(options) {
4
+ const api_1 = require("@terreno/api");
5
+ const langfuseClient_1 = require("./langfuseClient");
6
+ const langfuseRoutesEvaluations_1 = require("./langfuseRoutesEvaluations");
7
+ const langfuseRoutesPlayground_1 = require("./langfuseRoutesPlayground");
8
+ const langfuseRoutesPrompts_1 = require("./langfuseRoutesPrompts");
9
+ const langfuseRoutesTraces_1 = require("./langfuseRoutesTraces");
10
+ const langfuseTracing_1 = require("./langfuseTracing");
11
+ class LangfuseApp {
12
+ options;
13
+ constructor(options) {
49
14
  this.options = options;
50
15
  }
51
- LangfuseApp.prototype.register = function (app) {
52
- var _this = this;
53
- var _a, _b, _c, _d, _e;
54
- var organization = (_a = this.options.organization) !== null && _a !== void 0 ? _a : "flourish-health";
55
- var project = (_b = this.options.project) !== null && _b !== void 0 ? _b : "terreno";
56
- (0, langfuseClient_1.initLangfuseClient)(this.options);
16
+ register(app) {
17
+ const organization = this.options.organization ?? "flourish-health";
18
+ const project = this.options.project ?? "terreno";
19
+ try {
20
+ (0, langfuseClient_1.initLangfuseClient)(this.options);
21
+ }
22
+ catch (err) {
23
+ api_1.logger.warn(`Langfuse client initialization failed; continuing without Langfuse: ${err}`);
24
+ return;
25
+ }
57
26
  if (this.options.enableTracing !== false) {
58
27
  try {
59
28
  (0, langfuseTracing_1.initTracing)(this.options);
60
29
  }
61
30
  catch (err) {
62
- api_1.logger.warn("Langfuse tracing initialization failed: ".concat(err));
31
+ api_1.logger.warn(`Langfuse tracing initialization failed: ${err}`);
63
32
  }
64
33
  }
65
34
  if (this.options.enableAdminUI !== false) {
66
- var adminPath = (_c = this.options.adminPath) !== null && _c !== void 0 ? _c : "/admin/langfuse";
35
+ const adminPath = this.options.adminPath ?? "/admin/langfuse";
67
36
  (0, langfuseRoutesPrompts_1.addPromptRoutes)(app, adminPath);
68
37
  (0, langfuseRoutesTraces_1.addTraceRoutes)(app, adminPath);
69
38
  (0, langfuseRoutesPlayground_1.addPlaygroundRoutes)(app, adminPath);
70
- if ((_d = this.options.evaluation) === null || _d === void 0 ? void 0 : _d.enabled) {
71
- (0, langfuseRoutesEvaluations_1.addEvaluationRoutes)(app, adminPath, (_e = this.options.evaluation.scoringFunctions) !== null && _e !== void 0 ? _e : []);
39
+ if (this.options.evaluation?.enabled) {
40
+ (0, langfuseRoutesEvaluations_1.addEvaluationRoutes)(app, adminPath, this.options.evaluation.scoringFunctions ?? []);
72
41
  }
73
- api_1.logger.info("Langfuse admin routes mounted at ".concat(adminPath, " (org: ").concat(organization, ", project: ").concat(project, ")"));
42
+ api_1.logger.info(`Langfuse admin routes mounted at ${adminPath} (org: ${organization}, project: ${project})`);
74
43
  }
75
- process.once("SIGTERM", function () {
76
- void _this.shutdown();
44
+ process.once("SIGTERM", () => {
45
+ void this.shutdown();
77
46
  });
78
- };
79
- LangfuseApp.prototype.shutdown = function () {
80
- return __awaiter(this, void 0, void 0, function () {
81
- return __generator(this, function (_a) {
82
- switch (_a.label) {
83
- case 0: return [4 /*yield*/, (0, langfuseClient_1.shutdownLangfuseClient)()];
84
- case 1:
85
- _a.sent();
86
- return [4 /*yield*/, (0, langfuseTracing_1.shutdownTracing)()];
87
- case 2:
88
- _a.sent();
89
- return [2 /*return*/];
90
- }
91
- });
92
- });
93
- };
94
- return LangfuseApp;
95
- }());
47
+ }
48
+ async shutdown() {
49
+ await (0, langfuseClient_1.shutdownLangfuseClient)();
50
+ await (0, langfuseTracing_1.shutdownTracing)();
51
+ }
52
+ }
96
53
  exports.LangfuseApp = LangfuseApp;
@@ -1,49 +1,13 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
4
  };
41
5
  Object.defineProperty(exports, "__esModule", { value: true });
42
6
  exports.invalidateCache = exports.setCached = exports.getCached = exports.LangfuseCache = void 0;
43
- var api_1 = require("@terreno/api");
44
- var luxon_1 = require("luxon");
45
- var mongoose_1 = __importDefault(require("mongoose"));
46
- var langfuseCacheSchema = new mongoose_1.default.Schema({
7
+ const api_1 = require("@terreno/api");
8
+ const luxon_1 = require("luxon");
9
+ const mongoose_1 = __importDefault(require("mongoose"));
10
+ const langfuseCacheSchema = new mongoose_1.default.Schema({
47
11
  expiresAt: {
48
12
  description: "When this cache entry expires",
49
13
  required: true,
@@ -68,46 +32,23 @@ langfuseCacheSchema.plugin(api_1.findOneOrNone);
68
32
  langfuseCacheSchema.plugin(api_1.findExactlyOne);
69
33
  exports.LangfuseCache = mongoose_1.default.models.LangfuseCache ||
70
34
  mongoose_1.default.model("LangfuseCache", langfuseCacheSchema);
71
- var getCached = function (key) { return __awaiter(void 0, void 0, void 0, function () {
72
- var entry;
73
- return __generator(this, function (_a) {
74
- switch (_a.label) {
75
- case 0: return [4 /*yield*/, exports.LangfuseCache.findOneOrNone({
76
- expiresAt: { $gt: luxon_1.DateTime.now().toJSDate() },
77
- key: key,
78
- })];
79
- case 1:
80
- entry = _a.sent();
81
- if (!entry) {
82
- return [2 /*return*/, null];
83
- }
84
- return [2 /*return*/, entry.value];
85
- }
35
+ const getCached = async (key) => {
36
+ const entry = await exports.LangfuseCache.findOneOrNone({
37
+ expiresAt: { $gt: luxon_1.DateTime.now().toJSDate() },
38
+ key,
86
39
  });
87
- }); };
40
+ if (!entry) {
41
+ return null;
42
+ }
43
+ return entry.value;
44
+ };
88
45
  exports.getCached = getCached;
89
- var setCached = function (key, value, ttlSeconds) { return __awaiter(void 0, void 0, void 0, function () {
90
- var expiresAt;
91
- return __generator(this, function (_a) {
92
- switch (_a.label) {
93
- case 0:
94
- expiresAt = luxon_1.DateTime.now().plus({ seconds: ttlSeconds }).toJSDate();
95
- return [4 /*yield*/, exports.LangfuseCache.findOneAndUpdate({ key: key }, { expiresAt: expiresAt, key: key, value: value }, { upsert: true })];
96
- case 1:
97
- _a.sent();
98
- return [2 /*return*/];
99
- }
100
- });
101
- }); };
46
+ const setCached = async (key, value, ttlSeconds) => {
47
+ const expiresAt = luxon_1.DateTime.now().plus({ seconds: ttlSeconds }).toJSDate();
48
+ await exports.LangfuseCache.findOneAndUpdate({ key }, { expiresAt, key, value }, { upsert: true });
49
+ };
102
50
  exports.setCached = setCached;
103
- var invalidateCache = function (keyPattern) { return __awaiter(void 0, void 0, void 0, function () {
104
- return __generator(this, function (_a) {
105
- switch (_a.label) {
106
- case 0: return [4 /*yield*/, exports.LangfuseCache.deleteMany({ key: { $regex: keyPattern } })];
107
- case 1:
108
- _a.sent();
109
- return [2 /*return*/];
110
- }
111
- });
112
- }); };
51
+ const invalidateCache = async (keyPattern) => {
52
+ await exports.LangfuseCache.deleteMany({ key: { $regex: keyPattern } });
53
+ };
113
54
  exports.invalidateCache = invalidateCache;
@@ -1,56 +1,19 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.shutdownLangfuseClient = exports.isLangfuseInitialized = exports.getLangfuseClient = exports.initLangfuseClient = void 0;
40
- var client_1 = require("@langfuse/client");
41
- var api_1 = require("@terreno/api");
42
- var langfuseInstance = null;
43
- var initLangfuseClient = function (options) {
44
- var _a;
4
+ const client_1 = require("@langfuse/client");
5
+ const api_1 = require("@terreno/api");
6
+ let langfuseInstance = null;
7
+ const initLangfuseClient = (options) => {
45
8
  langfuseInstance = new client_1.LangfuseClient({
46
- baseUrl: (_a = options.baseUrl) !== null && _a !== void 0 ? _a : "https://cloud.langfuse.com",
9
+ baseUrl: options.baseUrl ?? "https://cloud.langfuse.com",
47
10
  publicKey: options.publicKey,
48
11
  secretKey: options.secretKey,
49
12
  });
50
13
  return langfuseInstance;
51
14
  };
52
15
  exports.initLangfuseClient = initLangfuseClient;
53
- var getLangfuseClient = function () {
16
+ const getLangfuseClient = () => {
54
17
  if (!langfuseInstance) {
55
18
  throw new api_1.APIError({
56
19
  status: 500,
@@ -60,20 +23,12 @@ var getLangfuseClient = function () {
60
23
  return langfuseInstance;
61
24
  };
62
25
  exports.getLangfuseClient = getLangfuseClient;
63
- var isLangfuseInitialized = function () { return langfuseInstance != null; };
26
+ const isLangfuseInitialized = () => langfuseInstance != null;
64
27
  exports.isLangfuseInitialized = isLangfuseInitialized;
65
- var shutdownLangfuseClient = function () { return __awaiter(void 0, void 0, void 0, function () {
66
- return __generator(this, function (_a) {
67
- switch (_a.label) {
68
- case 0:
69
- if (!langfuseInstance) return [3 /*break*/, 2];
70
- return [4 /*yield*/, langfuseInstance.shutdown()];
71
- case 1:
72
- _a.sent();
73
- langfuseInstance = null;
74
- _a.label = 2;
75
- case 2: return [2 /*return*/];
76
- }
77
- });
78
- }); };
28
+ const shutdownLangfuseClient = async () => {
29
+ if (langfuseInstance) {
30
+ await langfuseInstance.shutdown();
31
+ langfuseInstance = null;
32
+ }
33
+ };
79
34
  exports.shutdownLangfuseClient = shutdownLangfuseClient;