@terreno/ai 57.4.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 +2 -2
- package/dist/aiAdminApp.js +9 -10
- package/dist/aiApp.js +31 -31
- package/dist/langfuseApp.js +27 -76
- package/dist/langfuseCache.js +20 -79
- package/dist/langfuseClient.js +13 -58
- package/dist/langfusePrompts.js +70 -173
- package/dist/langfuseRoutesEvaluations.js +26 -73
- package/dist/langfuseRoutesMiddleware.js +4 -4
- package/dist/langfuseRoutesPlayground.js +29 -99
- package/dist/langfuseRoutesPrompts.js +48 -121
- package/dist/langfuseRoutesTraces.js +24 -76
- package/dist/langfuseTracing.js +15 -60
- package/dist/langfuseVercelAi.js +38 -87
- package/dist/models/aiRequest.js +19 -72
- package/dist/models/fileAttachment.js +3 -3
- package/dist/models/gptHistory.js +5 -5
- package/dist/models/project.js +4 -4
- package/dist/routes/aiRequestsExplorer.js +89 -150
- package/dist/routes/files.js +50 -115
- package/dist/routes/gpt.js +457 -694
- package/dist/routes/gptHistories.js +17 -19
- package/dist/routes/mcp.js +30 -102
- package/dist/routes/projects.js +53 -116
- package/dist/service/aiService.js +393 -706
- package/dist/service/fileStorage.js +42 -134
- package/dist/service/gemini.js +55 -130
- package/dist/service/getMCPTools.js +17 -86
- package/dist/service/mcpService.js +87 -258
- package/dist/service/parseAiJson.js +32 -32
- package/dist/service/vertex.js +129 -283
- package/package.json +7 -7
- package/tsconfig.json +6 -21
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/
|
|
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/
|
|
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.
|
package/dist/aiAdminApp.js
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AIAdminApp = void 0;
|
|
4
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
class AIAdminApp {
|
|
9
|
+
options;
|
|
10
|
+
constructor(options = {}) {
|
|
11
11
|
this.options = options;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
adminContribution() {
|
|
14
14
|
return {
|
|
15
15
|
customScreens: [{ displayName: "AI Requests", icon: "robot", name: "ai-requests" }],
|
|
16
16
|
};
|
|
17
|
-
}
|
|
18
|
-
|
|
17
|
+
}
|
|
18
|
+
register(app) {
|
|
19
19
|
(0, aiRequestsExplorer_1.addAiRequestsExplorerRoutes)(app, { openApiOptions: this.options.openApiOptions });
|
|
20
|
-
}
|
|
21
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
37
|
-
|
|
36
|
+
class AiApp {
|
|
37
|
+
options;
|
|
38
|
+
constructor(options) {
|
|
38
39
|
this.options = options;
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
(0, gptHistories_1.addGptHistoryRoutes)(router, { 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
|
|
46
|
-
createModelFn
|
|
47
|
-
createServerModelFn
|
|
48
|
-
demoMode
|
|
49
|
-
maxSteps
|
|
50
|
-
mcpService
|
|
51
|
-
openApiOptions
|
|
52
|
-
titleModelId
|
|
53
|
-
toolChoice
|
|
54
|
-
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
|
|
57
|
-
(0, projects_1.addProjectRoutes)(router, { 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
|
|
61
|
-
gcsBucket
|
|
62
|
-
openApiOptions
|
|
61
|
+
fileStorageService,
|
|
62
|
+
gcsBucket,
|
|
63
|
+
openApiOptions,
|
|
63
64
|
});
|
|
64
65
|
}
|
|
65
66
|
if (mcpService) {
|
|
66
|
-
(0, mcp_1.addMcpRoutes)(router, { mcpService
|
|
67
|
+
(0, mcp_1.addMcpRoutes)(router, { mcpService, openApiOptions });
|
|
67
68
|
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
}());
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
71
|
exports.AiApp = AiApp;
|
package/dist/langfuseApp.js
CHANGED
|
@@ -1,63 +1,26 @@
|
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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";
|
|
16
|
+
register(app) {
|
|
17
|
+
const organization = this.options.organization ?? "flourish-health";
|
|
18
|
+
const project = this.options.project ?? "terreno";
|
|
56
19
|
try {
|
|
57
20
|
(0, langfuseClient_1.initLangfuseClient)(this.options);
|
|
58
21
|
}
|
|
59
22
|
catch (err) {
|
|
60
|
-
api_1.logger.warn(
|
|
23
|
+
api_1.logger.warn(`Langfuse client initialization failed; continuing without Langfuse: ${err}`);
|
|
61
24
|
return;
|
|
62
25
|
}
|
|
63
26
|
if (this.options.enableTracing !== false) {
|
|
@@ -65,38 +28,26 @@ var LangfuseApp = /** @class */ (function () {
|
|
|
65
28
|
(0, langfuseTracing_1.initTracing)(this.options);
|
|
66
29
|
}
|
|
67
30
|
catch (err) {
|
|
68
|
-
api_1.logger.warn(
|
|
31
|
+
api_1.logger.warn(`Langfuse tracing initialization failed: ${err}`);
|
|
69
32
|
}
|
|
70
33
|
}
|
|
71
34
|
if (this.options.enableAdminUI !== false) {
|
|
72
|
-
|
|
35
|
+
const adminPath = this.options.adminPath ?? "/admin/langfuse";
|
|
73
36
|
(0, langfuseRoutesPrompts_1.addPromptRoutes)(app, adminPath);
|
|
74
37
|
(0, langfuseRoutesTraces_1.addTraceRoutes)(app, adminPath);
|
|
75
38
|
(0, langfuseRoutesPlayground_1.addPlaygroundRoutes)(app, adminPath);
|
|
76
|
-
if (
|
|
77
|
-
(0, langfuseRoutesEvaluations_1.addEvaluationRoutes)(app, adminPath,
|
|
39
|
+
if (this.options.evaluation?.enabled) {
|
|
40
|
+
(0, langfuseRoutesEvaluations_1.addEvaluationRoutes)(app, adminPath, this.options.evaluation.scoringFunctions ?? []);
|
|
78
41
|
}
|
|
79
|
-
api_1.logger.info(
|
|
42
|
+
api_1.logger.info(`Langfuse admin routes mounted at ${adminPath} (org: ${organization}, project: ${project})`);
|
|
80
43
|
}
|
|
81
|
-
process.once("SIGTERM",
|
|
82
|
-
void
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
LangfuseApp.prototype.shutdown = function () {
|
|
86
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
-
return __generator(this, function (_a) {
|
|
88
|
-
switch (_a.label) {
|
|
89
|
-
case 0: return [4 /*yield*/, (0, langfuseClient_1.shutdownLangfuseClient)()];
|
|
90
|
-
case 1:
|
|
91
|
-
_a.sent();
|
|
92
|
-
return [4 /*yield*/, (0, langfuseTracing_1.shutdownTracing)()];
|
|
93
|
-
case 2:
|
|
94
|
-
_a.sent();
|
|
95
|
-
return [2 /*return*/];
|
|
96
|
-
}
|
|
97
|
-
});
|
|
44
|
+
process.once("SIGTERM", () => {
|
|
45
|
+
void this.shutdown();
|
|
98
46
|
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
47
|
+
}
|
|
48
|
+
async shutdown() {
|
|
49
|
+
await (0, langfuseClient_1.shutdownLangfuseClient)();
|
|
50
|
+
await (0, langfuseTracing_1.shutdownTracing)();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
102
53
|
exports.LangfuseApp = LangfuseApp;
|
package/dist/langfuseCache.js
CHANGED
|
@@ -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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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;
|
package/dist/langfuseClient.js
CHANGED
|
@@ -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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
26
|
+
const isLangfuseInitialized = () => langfuseInstance != null;
|
|
64
27
|
exports.isLangfuseInitialized = isLangfuseInitialized;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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;
|