@terreno/ai 0.3.2
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/.claude/CLAUDE.local.md +208 -0
- package/.cursor/rules/00-root.mdc +342 -0
- package/.cursorrules +221 -0
- package/.github/copilot-instructions.md +337 -0
- package/AGENTS.md +337 -0
- package/biome.jsonc +20 -0
- package/bunfig.toml +3 -0
- package/dist/aiApp.d.ts +59 -0
- package/dist/aiApp.js +67 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +23 -0
- package/dist/models/aiRequest.d.ts +2 -0
- package/dist/models/aiRequest.js +76 -0
- package/dist/models/aiRequest.test.d.ts +1 -0
- package/dist/models/aiRequest.test.js +187 -0
- package/dist/models/fileAttachment.d.ts +2 -0
- package/dist/models/fileAttachment.js +25 -0
- package/dist/models/fileAttachment.test.d.ts +1 -0
- package/dist/models/fileAttachment.test.js +217 -0
- package/dist/models/gptHistory.d.ts +2 -0
- package/dist/models/gptHistory.js +56 -0
- package/dist/models/gptHistory.test.d.ts +1 -0
- package/dist/models/gptHistory.test.js +336 -0
- package/dist/models/index.d.ts +3 -0
- package/dist/models/index.js +9 -0
- package/dist/routes/aiRequestsExplorer.d.ts +2 -0
- package/dist/routes/aiRequestsExplorer.js +153 -0
- package/dist/routes/files.d.ts +5 -0
- package/dist/routes/files.js +168 -0
- package/dist/routes/gpt.d.ts +2 -0
- package/dist/routes/gpt.js +593 -0
- package/dist/routes/gptHistories.d.ts +3 -0
- package/dist/routes/gptHistories.js +29 -0
- package/dist/routes/index.d.ts +5 -0
- package/dist/routes/index.js +13 -0
- package/dist/routes/mcp.d.ts +2 -0
- package/dist/routes/mcp.js +133 -0
- package/dist/routes/routes.test.d.ts +1 -0
- package/dist/routes/routes.test.js +303 -0
- package/dist/service/aiService.d.ts +24 -0
- package/dist/service/aiService.js +453 -0
- package/dist/service/aiService.test.d.ts +1 -0
- package/dist/service/aiService.test.js +367 -0
- package/dist/service/fileStorage.d.ts +24 -0
- package/dist/service/fileStorage.js +143 -0
- package/dist/service/index.d.ts +4 -0
- package/dist/service/index.js +15 -0
- package/dist/service/mcpService.d.ts +14 -0
- package/dist/service/mcpService.js +271 -0
- package/dist/service/prompts.d.ts +4 -0
- package/dist/service/prompts.js +14 -0
- package/dist/tests/bunSetup.d.ts +1 -0
- package/dist/tests/bunSetup.js +227 -0
- package/dist/types/index.d.ts +170 -0
- package/dist/types/index.js +7 -0
- package/package.json +55 -0
- package/src/aiApp.ts +110 -0
- package/src/index.ts +6 -0
- package/src/models/aiRequest.test.ts +101 -0
- package/src/models/aiRequest.ts +45 -0
- package/src/models/fileAttachment.test.ts +119 -0
- package/src/models/fileAttachment.ts +31 -0
- package/src/models/gptHistory.test.ts +209 -0
- package/src/models/gptHistory.ts +71 -0
- package/src/models/index.ts +3 -0
- package/src/routes/aiRequestsExplorer.ts +107 -0
- package/src/routes/files.ts +128 -0
- package/src/routes/gpt.ts +503 -0
- package/src/routes/gptHistories.ts +31 -0
- package/src/routes/index.ts +5 -0
- package/src/routes/mcp.ts +76 -0
- package/src/routes/routes.test.ts +168 -0
- package/src/service/aiService.test.ts +242 -0
- package/src/service/aiService.ts +269 -0
- package/src/service/fileStorage.ts +74 -0
- package/src/service/index.ts +9 -0
- package/src/service/mcpService.ts +120 -0
- package/src/service/prompts.ts +18 -0
- package/src/tests/bunSetup.ts +163 -0
- package/src/types/index.ts +224 -0
- package/tsconfig.json +31 -0
|
@@ -0,0 +1,168 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.addFileRoutes = void 0;
|
|
43
|
+
var api_1 = require("@terreno/api");
|
|
44
|
+
var multer_1 = __importDefault(require("multer"));
|
|
45
|
+
var fileAttachment_1 = require("../models/fileAttachment");
|
|
46
|
+
var ALLOWED_MIME_TYPES = new Set([
|
|
47
|
+
"image/jpeg",
|
|
48
|
+
"image/png",
|
|
49
|
+
"image/gif",
|
|
50
|
+
"image/webp",
|
|
51
|
+
"application/pdf",
|
|
52
|
+
"text/plain",
|
|
53
|
+
"text/csv",
|
|
54
|
+
"application/json",
|
|
55
|
+
]);
|
|
56
|
+
var DEFAULT_MAX_FILE_SIZE = 10 * 1024 * 1024; // 10MB
|
|
57
|
+
var addFileRoutes = function (router, options) {
|
|
58
|
+
var _a, _b, _c;
|
|
59
|
+
var fileStorageService = options.fileStorageService, _d = options.maxFileSize, maxFileSize = _d === void 0 ? DEFAULT_MAX_FILE_SIZE : _d;
|
|
60
|
+
var upload = (0, multer_1.default)({
|
|
61
|
+
fileFilter: function (_req, file, cb) {
|
|
62
|
+
if (ALLOWED_MIME_TYPES.has(file.mimetype)) {
|
|
63
|
+
cb(null, true);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
cb(new Error("File type ".concat(file.mimetype, " is not allowed")));
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
limits: { fileSize: maxFileSize },
|
|
70
|
+
storage: multer_1.default.memoryStorage(),
|
|
71
|
+
});
|
|
72
|
+
router.post("/files/upload", [
|
|
73
|
+
(0, api_1.authenticateMiddleware)(),
|
|
74
|
+
upload.single("file"),
|
|
75
|
+
(0, api_1.createOpenApiBuilder)((_a = options.openApiOptions) !== null && _a !== void 0 ? _a : {})
|
|
76
|
+
.withTags(["files"])
|
|
77
|
+
.withSummary("Upload a file")
|
|
78
|
+
.withResponse(200, {
|
|
79
|
+
filename: { type: "string" },
|
|
80
|
+
gcsKey: { type: "string" },
|
|
81
|
+
mimeType: { type: "string" },
|
|
82
|
+
size: { type: "number" },
|
|
83
|
+
url: { type: "string" },
|
|
84
|
+
})
|
|
85
|
+
.build(),
|
|
86
|
+
], (0, api_1.asyncHandler)(function (req, res) { return __awaiter(void 0, void 0, void 0, function () {
|
|
87
|
+
var file, userId, result;
|
|
88
|
+
var _a;
|
|
89
|
+
return __generator(this, function (_b) {
|
|
90
|
+
switch (_b.label) {
|
|
91
|
+
case 0:
|
|
92
|
+
file = req.file;
|
|
93
|
+
userId = (_a = req.user) === null || _a === void 0 ? void 0 : _a._id;
|
|
94
|
+
if (!file) {
|
|
95
|
+
throw new api_1.APIError({ status: 400, title: "No file provided" });
|
|
96
|
+
}
|
|
97
|
+
return [4 /*yield*/, fileStorageService.upload({
|
|
98
|
+
buffer: file.buffer,
|
|
99
|
+
filename: file.originalname,
|
|
100
|
+
mimeType: file.mimetype,
|
|
101
|
+
userId: userId,
|
|
102
|
+
})];
|
|
103
|
+
case 1:
|
|
104
|
+
result = _b.sent();
|
|
105
|
+
return [2 /*return*/, res.json({ data: result })];
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}); }));
|
|
109
|
+
router.get("/files/:gcsKey(*)", [
|
|
110
|
+
(0, api_1.createOpenApiBuilder)((_b = options.openApiOptions) !== null && _b !== void 0 ? _b : {})
|
|
111
|
+
.withTags(["files"])
|
|
112
|
+
.withSummary("Get file URL")
|
|
113
|
+
.withPathParameter("gcsKey", { type: "string" })
|
|
114
|
+
.withResponse(200, { url: { type: "string" } })
|
|
115
|
+
.build(),
|
|
116
|
+
], (0, api_1.asyncHandler)(function (req, res) { return __awaiter(void 0, void 0, void 0, function () {
|
|
117
|
+
var gcsKey, attachment, url;
|
|
118
|
+
return __generator(this, function (_a) {
|
|
119
|
+
switch (_a.label) {
|
|
120
|
+
case 0:
|
|
121
|
+
gcsKey = req.params.gcsKey;
|
|
122
|
+
return [4 /*yield*/, fileAttachment_1.FileAttachment.findOne({ deleted: false, gcsKey: gcsKey })];
|
|
123
|
+
case 1:
|
|
124
|
+
attachment = _a.sent();
|
|
125
|
+
if (!attachment) {
|
|
126
|
+
throw new api_1.APIError({ status: 404, title: "File not found" });
|
|
127
|
+
}
|
|
128
|
+
return [4 /*yield*/, fileStorageService.getSignedUrl(gcsKey)];
|
|
129
|
+
case 2:
|
|
130
|
+
url = _a.sent();
|
|
131
|
+
return [2 /*return*/, res.json({ data: { url: url } })];
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}); }));
|
|
135
|
+
router.delete("/files/:gcsKey(*)", [
|
|
136
|
+
(0, api_1.authenticateMiddleware)(),
|
|
137
|
+
(0, api_1.createOpenApiBuilder)((_c = options.openApiOptions) !== null && _c !== void 0 ? _c : {})
|
|
138
|
+
.withTags(["files"])
|
|
139
|
+
.withSummary("Delete a file")
|
|
140
|
+
.withPathParameter("gcsKey", { type: "string" })
|
|
141
|
+
.withResponse(200, { success: { type: "boolean" } })
|
|
142
|
+
.build(),
|
|
143
|
+
], (0, api_1.asyncHandler)(function (req, res) { return __awaiter(void 0, void 0, void 0, function () {
|
|
144
|
+
var gcsKey, userId, attachment;
|
|
145
|
+
var _a;
|
|
146
|
+
return __generator(this, function (_b) {
|
|
147
|
+
switch (_b.label) {
|
|
148
|
+
case 0:
|
|
149
|
+
gcsKey = req.params.gcsKey;
|
|
150
|
+
userId = (_a = req.user) === null || _a === void 0 ? void 0 : _a._id;
|
|
151
|
+
return [4 /*yield*/, fileAttachment_1.FileAttachment.findOne({ deleted: false, gcsKey: gcsKey })];
|
|
152
|
+
case 1:
|
|
153
|
+
attachment = _b.sent();
|
|
154
|
+
if (!attachment) {
|
|
155
|
+
throw new api_1.APIError({ status: 404, title: "File not found" });
|
|
156
|
+
}
|
|
157
|
+
if (attachment.userId.toString() !== userId.toString()) {
|
|
158
|
+
throw new api_1.APIError({ status: 403, title: "Not authorized to delete this file" });
|
|
159
|
+
}
|
|
160
|
+
return [4 /*yield*/, fileStorageService.delete(gcsKey)];
|
|
161
|
+
case 2:
|
|
162
|
+
_b.sent();
|
|
163
|
+
return [2 /*return*/, res.json({ data: { success: true } })];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}); }));
|
|
167
|
+
};
|
|
168
|
+
exports.addFileRoutes = addFileRoutes;
|