@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
|
@@ -1,129 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
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);
|
|
24
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
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;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
3
|
exports.addPromptRoutes = void 0;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
router.get(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return [4 /*yield*/, client.api.prompts.list({ limit: limit, page: page })];
|
|
65
|
-
case 1:
|
|
66
|
-
result = _a.sent();
|
|
67
|
-
return [2 /*return*/, res.json({
|
|
68
|
-
data: result.data,
|
|
69
|
-
meta: result.meta,
|
|
70
|
-
})];
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}); }));
|
|
74
|
-
router.get("".concat(basePath, "/prompts/:name"), [(0, api_1.authenticateMiddleware)(), langfuseRoutesMiddleware_1.requireAdmin], (0, api_1.asyncHandler)(function (req, res) { return __awaiter(void 0, void 0, void 0, function () {
|
|
75
|
-
var client, name, version, label, prompt;
|
|
76
|
-
return __generator(this, function (_a) {
|
|
77
|
-
switch (_a.label) {
|
|
78
|
-
case 0:
|
|
79
|
-
client = (0, langfuseClient_1.getLangfuseClient)();
|
|
80
|
-
name = req.params.name;
|
|
81
|
-
version = req.query.version ? Number(req.query.version) : undefined;
|
|
82
|
-
label = req.query.label;
|
|
83
|
-
return [4 /*yield*/, client.prompt.get(name, __assign(__assign({ cacheTtlSeconds: 0 }, (version !== undefined ? { version: version } : {})), (label ? { label: label } : {})))];
|
|
84
|
-
case 1:
|
|
85
|
-
prompt = _a.sent();
|
|
86
|
-
return [2 /*return*/, res.json({
|
|
87
|
-
config: prompt.config,
|
|
88
|
-
labels: prompt.labels,
|
|
89
|
-
name: prompt.name,
|
|
90
|
-
prompt: prompt.prompt,
|
|
91
|
-
tags: prompt.tags,
|
|
92
|
-
type: prompt.type,
|
|
93
|
-
version: prompt.version,
|
|
94
|
-
})];
|
|
95
|
-
}
|
|
4
|
+
const api_1 = require("@terreno/api");
|
|
5
|
+
const langfuseClient_1 = require("./langfuseClient");
|
|
6
|
+
const langfusePrompts_1 = require("./langfusePrompts");
|
|
7
|
+
const langfuseRoutesMiddleware_1 = require("./langfuseRoutesMiddleware");
|
|
8
|
+
const addPromptRoutes = (router, basePath) => {
|
|
9
|
+
router.get(`${basePath}/prompts`, [(0, api_1.authenticateMiddleware)(), langfuseRoutesMiddleware_1.requireAdmin], (0, api_1.asyncHandler)(async (req, res) => {
|
|
10
|
+
const client = (0, langfuseClient_1.getLangfuseClient)();
|
|
11
|
+
const page = Number(req.query.page) || 1;
|
|
12
|
+
const limit = Number(req.query.limit) || 20;
|
|
13
|
+
const result = await client.api.prompts.list({ limit, page });
|
|
14
|
+
return res.json({
|
|
15
|
+
data: result.data,
|
|
16
|
+
meta: result.meta,
|
|
96
17
|
});
|
|
97
|
-
})
|
|
98
|
-
router.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
status: 400,
|
|
108
|
-
title: "Invalid request",
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
return [4 /*yield*/, (0, langfusePrompts_1.createPrompt)({ config: config, labels: labels, name: name, prompt: prompt, tags: tags, type: type })];
|
|
112
|
-
case 1:
|
|
113
|
-
result = _b.sent();
|
|
114
|
-
return [2 /*return*/, res.status(201).json(result)];
|
|
115
|
-
}
|
|
18
|
+
}));
|
|
19
|
+
router.get(`${basePath}/prompts/:name`, [(0, api_1.authenticateMiddleware)(), langfuseRoutesMiddleware_1.requireAdmin], (0, api_1.asyncHandler)(async (req, res) => {
|
|
20
|
+
const client = (0, langfuseClient_1.getLangfuseClient)();
|
|
21
|
+
const { name } = req.params;
|
|
22
|
+
const version = req.query.version ? Number(req.query.version) : undefined;
|
|
23
|
+
const label = req.query.label;
|
|
24
|
+
const prompt = await client.prompt.get(name, {
|
|
25
|
+
cacheTtlSeconds: 0,
|
|
26
|
+
...(version !== undefined ? { version } : {}),
|
|
27
|
+
...(label ? { label } : {}),
|
|
116
28
|
});
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
29
|
+
return res.json({
|
|
30
|
+
config: prompt.config,
|
|
31
|
+
labels: prompt.labels,
|
|
32
|
+
name: prompt.name,
|
|
33
|
+
prompt: prompt.prompt,
|
|
34
|
+
tags: prompt.tags,
|
|
35
|
+
type: prompt.type,
|
|
36
|
+
version: prompt.version,
|
|
126
37
|
});
|
|
127
|
-
})
|
|
38
|
+
}));
|
|
39
|
+
router.post(`${basePath}/prompts`, [(0, api_1.authenticateMiddleware)(), langfuseRoutesMiddleware_1.requireAdmin], (0, api_1.asyncHandler)(async (req, res) => {
|
|
40
|
+
const { name, type, prompt, labels, tags, config } = req.body;
|
|
41
|
+
if (!name || !type || prompt === undefined) {
|
|
42
|
+
throw new api_1.APIError({
|
|
43
|
+
detail: "name, type, and prompt are required",
|
|
44
|
+
status: 400,
|
|
45
|
+
title: "Invalid request",
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const result = await (0, langfusePrompts_1.createPrompt)({ config, labels, name, prompt, tags, type });
|
|
49
|
+
return res.status(201).json(result);
|
|
50
|
+
}));
|
|
51
|
+
router.delete(`${basePath}/prompts/:name/cache`, [(0, api_1.authenticateMiddleware)(), langfuseRoutesMiddleware_1.requireAdmin], (0, api_1.asyncHandler)(async (req, res) => {
|
|
52
|
+
await (0, langfusePrompts_1.invalidatePromptCache)(req.params.name);
|
|
53
|
+
return res.json({ invalidated: true, name: req.params.name });
|
|
54
|
+
}));
|
|
128
55
|
};
|
|
129
56
|
exports.addPromptRoutes = addPromptRoutes;
|
|
@@ -1,82 +1,30 @@
|
|
|
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.addTraceRoutes = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
router.get(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
limit: limit,
|
|
58
|
-
page: page,
|
|
59
|
-
toTimestamp: toTimestamp,
|
|
60
|
-
userId: userId,
|
|
61
|
-
})];
|
|
62
|
-
case 1:
|
|
63
|
-
result = _a.sent();
|
|
64
|
-
return [2 /*return*/, res.json({ data: result.data, meta: result.meta })];
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}); }));
|
|
68
|
-
router.get("".concat(basePath, "/traces/:traceId"), [(0, api_1.authenticateMiddleware)(), langfuseRoutesMiddleware_1.requireAdmin], (0, api_1.asyncHandler)(function (req, res) { return __awaiter(void 0, void 0, void 0, function () {
|
|
69
|
-
var client, result;
|
|
70
|
-
return __generator(this, function (_a) {
|
|
71
|
-
switch (_a.label) {
|
|
72
|
-
case 0:
|
|
73
|
-
client = (0, langfuseClient_1.getLangfuseClient)();
|
|
74
|
-
return [4 /*yield*/, client.api.trace.get(req.params.traceId)];
|
|
75
|
-
case 1:
|
|
76
|
-
result = _a.sent();
|
|
77
|
-
return [2 /*return*/, res.json(result)];
|
|
78
|
-
}
|
|
4
|
+
const api_1 = require("@terreno/api");
|
|
5
|
+
const langfuseClient_1 = require("./langfuseClient");
|
|
6
|
+
const langfuseRoutesMiddleware_1 = require("./langfuseRoutesMiddleware");
|
|
7
|
+
const addTraceRoutes = (router, basePath) => {
|
|
8
|
+
router.get(`${basePath}/traces`, [(0, api_1.authenticateMiddleware)(), langfuseRoutesMiddleware_1.requireAdmin], (0, api_1.asyncHandler)(async (req, res) => {
|
|
9
|
+
const client = (0, langfuseClient_1.getLangfuseClient)();
|
|
10
|
+
const page = Number(req.query.page) || 1;
|
|
11
|
+
const limit = Number(req.query.limit) || 20;
|
|
12
|
+
const userId = req.query.userId;
|
|
13
|
+
const fromTimestamp = req.query.from ? req.query.from : undefined;
|
|
14
|
+
const toTimestamp = req.query.to ? req.query.to : undefined;
|
|
15
|
+
const result = await client.api.trace.list({
|
|
16
|
+
fromTimestamp,
|
|
17
|
+
limit,
|
|
18
|
+
page,
|
|
19
|
+
toTimestamp,
|
|
20
|
+
userId,
|
|
79
21
|
});
|
|
80
|
-
|
|
22
|
+
return res.json({ data: result.data, meta: result.meta });
|
|
23
|
+
}));
|
|
24
|
+
router.get(`${basePath}/traces/:traceId`, [(0, api_1.authenticateMiddleware)(), langfuseRoutesMiddleware_1.requireAdmin], (0, api_1.asyncHandler)(async (req, res) => {
|
|
25
|
+
const client = (0, langfuseClient_1.getLangfuseClient)();
|
|
26
|
+
const result = await client.api.trace.get(req.params.traceId);
|
|
27
|
+
return res.json(result);
|
|
28
|
+
}));
|
|
81
29
|
};
|
|
82
30
|
exports.addTraceRoutes = addTraceRoutes;
|
package/dist/langfuseTracing.js
CHANGED
|
@@ -1,53 +1,16 @@
|
|
|
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.shutdownTracing = exports.initTracing = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
serviceName: (_a = options.serviceName) !== null && _a !== void 0 ? _a : "terreno-app",
|
|
4
|
+
const otel_1 = require("@langfuse/otel");
|
|
5
|
+
const sdk_node_1 = require("@opentelemetry/sdk-node");
|
|
6
|
+
const api_1 = require("@terreno/api");
|
|
7
|
+
let sdkInstance = null;
|
|
8
|
+
const initTracing = (options) => {
|
|
9
|
+
const sdk = new sdk_node_1.NodeSDK({
|
|
10
|
+
serviceName: options.serviceName ?? "terreno-app",
|
|
48
11
|
spanProcessors: [
|
|
49
12
|
new otel_1.LangfuseSpanProcessor({
|
|
50
|
-
baseUrl:
|
|
13
|
+
baseUrl: options.baseUrl ?? "https://cloud.langfuse.com",
|
|
51
14
|
publicKey: options.publicKey,
|
|
52
15
|
secretKey: options.secretKey,
|
|
53
16
|
}),
|
|
@@ -59,19 +22,11 @@ var initTracing = function (options) {
|
|
|
59
22
|
return sdk;
|
|
60
23
|
};
|
|
61
24
|
exports.initTracing = initTracing;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
_a.sent();
|
|
70
|
-
sdkInstance = null;
|
|
71
|
-
api_1.logger.info("Langfuse OpenTelemetry tracing shut down");
|
|
72
|
-
_a.label = 2;
|
|
73
|
-
case 2: return [2 /*return*/];
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}); };
|
|
25
|
+
const shutdownTracing = async () => {
|
|
26
|
+
if (sdkInstance) {
|
|
27
|
+
await sdkInstance.shutdown();
|
|
28
|
+
sdkInstance = null;
|
|
29
|
+
api_1.logger.info("Langfuse OpenTelemetry tracing shut down");
|
|
30
|
+
}
|
|
31
|
+
};
|
|
77
32
|
exports.shutdownTracing = shutdownTracing;
|
package/dist/langfuseVercelAi.js
CHANGED
|
@@ -1,98 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTelemetryConfig = exports.preparePromptForAI = void 0;
|
|
4
|
+
const api_1 = require("@terreno/api");
|
|
5
|
+
const langfusePrompts_1 = require("./langfusePrompts");
|
|
6
|
+
const preparePromptForAI = async (params, appOptions) => {
|
|
7
|
+
const options = {
|
|
8
|
+
label: params.label,
|
|
9
|
+
userId: params.userId,
|
|
10
|
+
variables: params.variables,
|
|
10
11
|
};
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
12
|
+
const cached = await (0, langfusePrompts_1.getPrompt)(params.promptName, options, appOptions);
|
|
13
|
+
const compiled = (0, langfusePrompts_1.compilePrompt)(cached, params.variables ?? {});
|
|
14
|
+
const varKeys = Object.keys(params.variables ?? {});
|
|
15
|
+
api_1.logger.debug(`Langfuse prompt used: "${params.promptName}" v${cached.version}${varKeys.length ? ` (vars: ${varKeys.join(", ")})` : ""}${params.userId ? ` (user: ${params.userId})` : ""}`);
|
|
16
|
+
const telemetry = {
|
|
17
|
+
functionId: `prompt:${params.promptName}`,
|
|
18
|
+
isEnabled: true,
|
|
19
|
+
metadata: {
|
|
20
|
+
langfusePromptName: params.promptName,
|
|
21
|
+
langfusePromptVersion: cached.version,
|
|
22
|
+
...(params.userId ? { userId: params.userId } : {}),
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
if (cached.type === "text") {
|
|
26
|
+
return {
|
|
27
|
+
config: cached.config,
|
|
28
|
+
prompt: compiled,
|
|
29
|
+
telemetry,
|
|
30
|
+
};
|
|
47
31
|
}
|
|
32
|
+
return {
|
|
33
|
+
config: cached.config,
|
|
34
|
+
messages: compiled,
|
|
35
|
+
telemetry,
|
|
36
|
+
};
|
|
48
37
|
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.createTelemetryConfig = exports.preparePromptForAI = void 0;
|
|
51
|
-
var api_1 = require("@terreno/api");
|
|
52
|
-
var langfusePrompts_1 = require("./langfusePrompts");
|
|
53
|
-
var preparePromptForAI = function (params, appOptions) { return __awaiter(void 0, void 0, void 0, function () {
|
|
54
|
-
var options, cached, compiled, varKeys, telemetry;
|
|
55
|
-
var _a, _b;
|
|
56
|
-
return __generator(this, function (_c) {
|
|
57
|
-
switch (_c.label) {
|
|
58
|
-
case 0:
|
|
59
|
-
options = {
|
|
60
|
-
label: params.label,
|
|
61
|
-
userId: params.userId,
|
|
62
|
-
variables: params.variables,
|
|
63
|
-
};
|
|
64
|
-
return [4 /*yield*/, (0, langfusePrompts_1.getPrompt)(params.promptName, options, appOptions)];
|
|
65
|
-
case 1:
|
|
66
|
-
cached = _c.sent();
|
|
67
|
-
compiled = (0, langfusePrompts_1.compilePrompt)(cached, (_a = params.variables) !== null && _a !== void 0 ? _a : {});
|
|
68
|
-
varKeys = Object.keys((_b = params.variables) !== null && _b !== void 0 ? _b : {});
|
|
69
|
-
api_1.logger.debug("Langfuse prompt used: \"".concat(params.promptName, "\" v").concat(cached.version).concat(varKeys.length ? " (vars: ".concat(varKeys.join(", "), ")") : "").concat(params.userId ? " (user: ".concat(params.userId, ")") : ""));
|
|
70
|
-
telemetry = {
|
|
71
|
-
functionId: "prompt:".concat(params.promptName),
|
|
72
|
-
isEnabled: true,
|
|
73
|
-
metadata: __assign({ langfusePromptName: params.promptName, langfusePromptVersion: cached.version }, (params.userId ? { userId: params.userId } : {})),
|
|
74
|
-
};
|
|
75
|
-
if (cached.type === "text") {
|
|
76
|
-
return [2 /*return*/, {
|
|
77
|
-
config: cached.config,
|
|
78
|
-
prompt: compiled,
|
|
79
|
-
telemetry: telemetry,
|
|
80
|
-
}];
|
|
81
|
-
}
|
|
82
|
-
return [2 /*return*/, {
|
|
83
|
-
config: cached.config,
|
|
84
|
-
messages: compiled,
|
|
85
|
-
telemetry: telemetry,
|
|
86
|
-
}];
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}); };
|
|
90
38
|
exports.preparePromptForAI = preparePromptForAI;
|
|
91
|
-
|
|
39
|
+
const createTelemetryConfig = (params) => {
|
|
92
40
|
return {
|
|
93
41
|
functionId: params.functionId,
|
|
94
42
|
isEnabled: true,
|
|
95
|
-
metadata:
|
|
43
|
+
metadata: {
|
|
44
|
+
...params.metadata,
|
|
45
|
+
...(params.userId ? { userId: params.userId } : {}),
|
|
46
|
+
},
|
|
96
47
|
};
|
|
97
48
|
};
|
|
98
49
|
exports.createTelemetryConfig = createTelemetryConfig;
|
package/dist/models/aiRequest.js
CHANGED
|
@@ -1,48 +1,12 @@
|
|
|
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.AIRequest = void 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
7
|
+
const api_1 = require("@terreno/api");
|
|
8
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
9
|
+
const aiRequestSchema = new mongoose_1.default.Schema({
|
|
46
10
|
aiModel: {
|
|
47
11
|
description: "The AI model identifier used for this request",
|
|
48
12
|
required: true,
|
|
@@ -96,40 +60,23 @@ aiRequestSchema.index({ created: -1, userId: 1 });
|
|
|
96
60
|
aiRequestSchema.index({ aiModel: 1, created: -1 });
|
|
97
61
|
aiRequestSchema.index({ created: -1, requestType: 1 });
|
|
98
62
|
aiRequestSchema.index({ parentRequestId: 1 });
|
|
99
|
-
aiRequestSchema.statics.logRequest = function (params) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return __generator(this, function (_a) {
|
|
103
|
-
request = new this(params);
|
|
104
|
-
return [2 /*return*/, request.save()];
|
|
105
|
-
});
|
|
106
|
-
});
|
|
63
|
+
aiRequestSchema.statics.logRequest = async function (params) {
|
|
64
|
+
const request = new this(params);
|
|
65
|
+
return request.save();
|
|
107
66
|
};
|
|
108
|
-
aiRequestSchema.statics.logMultiAgentRequest = function (params) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
response: "",
|
|
120
|
-
subRequestIds: params.subRequestIds,
|
|
121
|
-
totalResponseTime: params.totalResponseTime,
|
|
122
|
-
totalTokensUsed: params.totalTokensUsed,
|
|
123
|
-
userId: params.userId,
|
|
124
|
-
})];
|
|
125
|
-
case 1:
|
|
126
|
-
parent = _b.sent();
|
|
127
|
-
return [4 /*yield*/, this.updateMany({ _id: { $in: params.subRequestIds } }, { $set: { parentRequestId: parent._id } })];
|
|
128
|
-
case 2:
|
|
129
|
-
_b.sent();
|
|
130
|
-
return [2 /*return*/, parent];
|
|
131
|
-
}
|
|
132
|
-
});
|
|
67
|
+
aiRequestSchema.statics.logMultiAgentRequest = async function (params) {
|
|
68
|
+
const parent = await this.create({
|
|
69
|
+
aiModel: params.aiModel,
|
|
70
|
+
metadata: params.metadata ?? {},
|
|
71
|
+
prompt: "[multi-agent parent request]",
|
|
72
|
+
requestType: params.requestType,
|
|
73
|
+
response: "",
|
|
74
|
+
subRequestIds: params.subRequestIds,
|
|
75
|
+
totalResponseTime: params.totalResponseTime,
|
|
76
|
+
totalTokensUsed: params.totalTokensUsed,
|
|
77
|
+
userId: params.userId,
|
|
133
78
|
});
|
|
79
|
+
await this.updateMany({ _id: { $in: params.subRequestIds } }, { $set: { parentRequestId: parent._id } });
|
|
80
|
+
return parent;
|
|
134
81
|
};
|
|
135
82
|
exports.AIRequest = mongoose_1.default.model("AIRequest", aiRequestSchema);
|
|
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.FileAttachment = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const api_1 = require("@terreno/api");
|
|
8
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
9
|
+
const fileAttachmentSchema = new mongoose_1.default.Schema({
|
|
10
10
|
filename: { description: "Original name of the uploaded file", required: true, type: String },
|
|
11
11
|
gcsKey: {
|
|
12
12
|
description: "Google Cloud Storage key identifying this file",
|