@terreno/ai 0.11.8 → 0.11.9
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/types/index.d.ts +14 -10
- package/package.json +3 -3
- package/src/routes/files.test.ts +50 -0
- package/src/types/index.ts +12 -10
package/dist/types/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type mongoose from "mongoose";
|
|
|
4
4
|
export declare const DEFAULT_AI_REQUEST_TYPES: readonly ["general", "remix", "summarization", "translation"];
|
|
5
5
|
export type DefaultAIRequestType = (typeof DEFAULT_AI_REQUEST_TYPES)[number];
|
|
6
6
|
export type AIRequestType = DefaultAIRequestType | (string & {});
|
|
7
|
-
export
|
|
7
|
+
export interface AIRequestDocument extends mongoose.Document<mongoose.Types.ObjectId> {
|
|
8
8
|
created: Date;
|
|
9
9
|
deleted: boolean;
|
|
10
10
|
error?: string;
|
|
@@ -21,12 +21,13 @@ export type AIRequestDocument = mongoose.Document<mongoose.Types.ObjectId> & {
|
|
|
21
21
|
totalTokensUsed?: number;
|
|
22
22
|
updated: Date;
|
|
23
23
|
userId?: mongoose.Types.ObjectId;
|
|
24
|
-
}
|
|
24
|
+
}
|
|
25
25
|
export interface AIRequestStatics extends FindExactlyOnePlugin<AIRequestDocument>, FindOneOrNonePlugin<AIRequestDocument> {
|
|
26
26
|
logMultiAgentRequest(params: LogMultiAgentRequestParams): Promise<AIRequestDocument>;
|
|
27
27
|
logRequest(params: LogRequestParams): Promise<AIRequestDocument>;
|
|
28
28
|
}
|
|
29
|
-
export
|
|
29
|
+
export interface AIRequestModel extends mongoose.Model<AIRequestDocument>, AIRequestStatics {
|
|
30
|
+
}
|
|
30
31
|
export interface LogRequestParams {
|
|
31
32
|
error?: string;
|
|
32
33
|
metadata?: Record<string, unknown>;
|
|
@@ -74,7 +75,7 @@ export interface GptHistoryPrompt {
|
|
|
74
75
|
args?: Record<string, unknown>;
|
|
75
76
|
result?: unknown;
|
|
76
77
|
}
|
|
77
|
-
export
|
|
78
|
+
export interface GptHistoryDocument extends mongoose.Document<mongoose.Types.ObjectId> {
|
|
78
79
|
created: Date;
|
|
79
80
|
deleted: boolean;
|
|
80
81
|
projectId?: mongoose.Types.ObjectId;
|
|
@@ -82,10 +83,11 @@ export type GptHistoryDocument = mongoose.Document<mongoose.Types.ObjectId> & {
|
|
|
82
83
|
title?: string;
|
|
83
84
|
updated: Date;
|
|
84
85
|
userId: mongoose.Types.ObjectId;
|
|
85
|
-
}
|
|
86
|
+
}
|
|
86
87
|
export interface GptHistoryStatics extends FindExactlyOnePlugin<GptHistoryDocument>, FindOneOrNonePlugin<GptHistoryDocument> {
|
|
87
88
|
}
|
|
88
|
-
export
|
|
89
|
+
export interface GptHistoryModel extends mongoose.Model<GptHistoryDocument>, GptHistoryStatics {
|
|
90
|
+
}
|
|
89
91
|
export interface ProjectMemory {
|
|
90
92
|
_id?: mongoose.Types.ObjectId;
|
|
91
93
|
category?: string;
|
|
@@ -93,7 +95,7 @@ export interface ProjectMemory {
|
|
|
93
95
|
source: "user" | "auto";
|
|
94
96
|
text: string;
|
|
95
97
|
}
|
|
96
|
-
export
|
|
98
|
+
export interface ProjectDocument extends mongoose.Document<mongoose.Types.ObjectId> {
|
|
97
99
|
created: Date;
|
|
98
100
|
deleted: boolean;
|
|
99
101
|
memories: ProjectMemory[];
|
|
@@ -101,10 +103,11 @@ export type ProjectDocument = mongoose.Document<mongoose.Types.ObjectId> & {
|
|
|
101
103
|
systemContext: string;
|
|
102
104
|
updated: Date;
|
|
103
105
|
userId: mongoose.Types.ObjectId;
|
|
104
|
-
}
|
|
106
|
+
}
|
|
105
107
|
export interface ProjectStatics extends FindExactlyOnePlugin<ProjectDocument>, FindOneOrNonePlugin<ProjectDocument> {
|
|
106
108
|
}
|
|
107
|
-
export
|
|
109
|
+
export interface ProjectModel extends mongoose.Model<ProjectDocument>, ProjectStatics {
|
|
110
|
+
}
|
|
108
111
|
export interface AIServiceOptions {
|
|
109
112
|
defaultTemperature?: number;
|
|
110
113
|
model: LanguageModel;
|
|
@@ -201,7 +204,8 @@ export interface FileAttachmentDocument extends mongoose.Document<mongoose.Types
|
|
|
201
204
|
}
|
|
202
205
|
export interface FileAttachmentStatics extends FindExactlyOnePlugin<FileAttachmentDocument>, FindOneOrNonePlugin<FileAttachmentDocument> {
|
|
203
206
|
}
|
|
204
|
-
export
|
|
207
|
+
export interface FileAttachmentModel extends mongoose.Model<FileAttachmentDocument>, FileAttachmentStatics {
|
|
208
|
+
}
|
|
205
209
|
export interface MCPServerConfig {
|
|
206
210
|
name: string;
|
|
207
211
|
transport: {
|
package/package.json
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@types/multer": "^1.4.12",
|
|
23
23
|
"@types/passport-local-mongoose": "^6.1.5",
|
|
24
24
|
"@types/supertest": "^6.0.2",
|
|
25
|
-
"@terreno/api": "0.11.
|
|
25
|
+
"@terreno/api": "0.11.9",
|
|
26
26
|
"mongoose": "8.23.0",
|
|
27
27
|
"passport-local-mongoose": "^9.0.1",
|
|
28
28
|
"supertest": "^7.0.0",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"access": "public"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
|
-
"@terreno/api": "0.11.
|
|
66
|
+
"@terreno/api": "0.11.9",
|
|
67
67
|
"mongoose": "^8.0.0"
|
|
68
68
|
},
|
|
69
69
|
"repository": {
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"test:coverage": "bun run ../scripts/check-coverage.ts"
|
|
83
83
|
},
|
|
84
84
|
"types": "dist/index.d.ts",
|
|
85
|
-
"version": "0.11.
|
|
85
|
+
"version": "0.11.9"
|
|
86
86
|
}
|
package/src/routes/files.test.ts
CHANGED
|
@@ -39,15 +39,19 @@ const authAsUser = async (appInstance: express.Application, type: "admin" | "not
|
|
|
39
39
|
describe("File Routes", () => {
|
|
40
40
|
let app: express.Application;
|
|
41
41
|
let fileStorageService: MockFileStorageService;
|
|
42
|
+
let adminId: mongoose.Types.ObjectId;
|
|
43
|
+
let userId: mongoose.Types.ObjectId;
|
|
42
44
|
|
|
43
45
|
beforeAll(async () => {
|
|
44
46
|
await UserModel.deleteMany({});
|
|
45
47
|
const admin = await UserModel.create({admin: true, email: "admin@example.com", name: "Admin"});
|
|
46
48
|
await (admin as unknown as PasswordedUser).setPassword("securePassword");
|
|
47
49
|
await admin.save();
|
|
50
|
+
adminId = admin._id;
|
|
48
51
|
const user = await UserModel.create({email: "notAdmin@example.com", name: "User"});
|
|
49
52
|
await (user as unknown as PasswordedUser).setPassword("password");
|
|
50
53
|
await user.save();
|
|
54
|
+
userId = user._id;
|
|
51
55
|
});
|
|
52
56
|
|
|
53
57
|
beforeEach(async () => {
|
|
@@ -109,6 +113,21 @@ describe("File Routes", () => {
|
|
|
109
113
|
const res = await supertest(app).get("/files/missing/key.txt");
|
|
110
114
|
expect(res.status).toBe(404);
|
|
111
115
|
});
|
|
116
|
+
|
|
117
|
+
it("returns the signed URL when the file exists", async () => {
|
|
118
|
+
const attachment = await FileAttachment.create({
|
|
119
|
+
filename: "hi.txt",
|
|
120
|
+
gcsKey: "hi-single.txt",
|
|
121
|
+
mimeType: "text/plain",
|
|
122
|
+
size: 5,
|
|
123
|
+
url: "https://example.com/hi.txt",
|
|
124
|
+
userId,
|
|
125
|
+
});
|
|
126
|
+
const res = await supertest(app).get(`/files/${attachment.gcsKey}`);
|
|
127
|
+
expect(res.status).toBe(200);
|
|
128
|
+
expect(res.body.data.url).toBe("https://example.com/signed");
|
|
129
|
+
expect(fileStorageService.getSignedUrl as ReturnType<typeof mock>).toHaveBeenCalledTimes(1);
|
|
130
|
+
});
|
|
112
131
|
});
|
|
113
132
|
|
|
114
133
|
describe("DELETE /files/*gcsKey", () => {
|
|
@@ -122,5 +141,36 @@ describe("File Routes", () => {
|
|
|
122
141
|
const res = await supertest(app).delete("/files/any/thing.txt");
|
|
123
142
|
expect(res.status).toBe(401);
|
|
124
143
|
});
|
|
144
|
+
|
|
145
|
+
it("deletes the file when the requester owns it", async () => {
|
|
146
|
+
const attachment = await FileAttachment.create({
|
|
147
|
+
filename: "mine.txt",
|
|
148
|
+
gcsKey: "mine-single.txt",
|
|
149
|
+
mimeType: "text/plain",
|
|
150
|
+
size: 4,
|
|
151
|
+
url: "https://example.com/mine.txt",
|
|
152
|
+
userId,
|
|
153
|
+
});
|
|
154
|
+
const agent = await authAsUser(app, "notAdmin");
|
|
155
|
+
const res = await agent.delete(`/files/${attachment.gcsKey}`);
|
|
156
|
+
expect(res.status).toBe(200);
|
|
157
|
+
expect(res.body.data.success).toBe(true);
|
|
158
|
+
expect(fileStorageService.delete as ReturnType<typeof mock>).toHaveBeenCalledTimes(1);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("returns 403 when the requester does not own the file", async () => {
|
|
162
|
+
const attachment = await FileAttachment.create({
|
|
163
|
+
filename: "theirs.txt",
|
|
164
|
+
gcsKey: "theirs-single.txt",
|
|
165
|
+
mimeType: "text/plain",
|
|
166
|
+
size: 6,
|
|
167
|
+
url: "https://example.com/theirs.txt",
|
|
168
|
+
userId: adminId,
|
|
169
|
+
});
|
|
170
|
+
const agent = await authAsUser(app, "notAdmin");
|
|
171
|
+
const res = await agent.delete(`/files/${attachment.gcsKey}`);
|
|
172
|
+
expect(res.status).toBe(403);
|
|
173
|
+
expect(fileStorageService.delete as ReturnType<typeof mock>).not.toHaveBeenCalled();
|
|
174
|
+
});
|
|
125
175
|
});
|
|
126
176
|
});
|
package/src/types/index.ts
CHANGED
|
@@ -15,7 +15,7 @@ export const DEFAULT_AI_REQUEST_TYPES = [
|
|
|
15
15
|
export type DefaultAIRequestType = (typeof DEFAULT_AI_REQUEST_TYPES)[number];
|
|
16
16
|
export type AIRequestType = DefaultAIRequestType | (string & {});
|
|
17
17
|
|
|
18
|
-
export
|
|
18
|
+
export interface AIRequestDocument extends mongoose.Document<mongoose.Types.ObjectId> {
|
|
19
19
|
created: Date;
|
|
20
20
|
deleted: boolean;
|
|
21
21
|
error?: string;
|
|
@@ -32,7 +32,7 @@ export type AIRequestDocument = mongoose.Document<mongoose.Types.ObjectId> & {
|
|
|
32
32
|
totalTokensUsed?: number;
|
|
33
33
|
updated: Date;
|
|
34
34
|
userId?: mongoose.Types.ObjectId;
|
|
35
|
-
}
|
|
35
|
+
}
|
|
36
36
|
|
|
37
37
|
export interface AIRequestStatics
|
|
38
38
|
extends FindExactlyOnePlugin<AIRequestDocument>,
|
|
@@ -41,7 +41,7 @@ export interface AIRequestStatics
|
|
|
41
41
|
logRequest(params: LogRequestParams): Promise<AIRequestDocument>;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
export
|
|
44
|
+
export interface AIRequestModel extends mongoose.Model<AIRequestDocument>, AIRequestStatics {}
|
|
45
45
|
|
|
46
46
|
export interface LogRequestParams {
|
|
47
47
|
error?: string;
|
|
@@ -105,7 +105,7 @@ export interface GptHistoryPrompt {
|
|
|
105
105
|
result?: unknown;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
export
|
|
108
|
+
export interface GptHistoryDocument extends mongoose.Document<mongoose.Types.ObjectId> {
|
|
109
109
|
created: Date;
|
|
110
110
|
deleted: boolean;
|
|
111
111
|
projectId?: mongoose.Types.ObjectId;
|
|
@@ -113,13 +113,13 @@ export type GptHistoryDocument = mongoose.Document<mongoose.Types.ObjectId> & {
|
|
|
113
113
|
title?: string;
|
|
114
114
|
updated: Date;
|
|
115
115
|
userId: mongoose.Types.ObjectId;
|
|
116
|
-
}
|
|
116
|
+
}
|
|
117
117
|
|
|
118
118
|
export interface GptHistoryStatics
|
|
119
119
|
extends FindExactlyOnePlugin<GptHistoryDocument>,
|
|
120
120
|
FindOneOrNonePlugin<GptHistoryDocument> {}
|
|
121
121
|
|
|
122
|
-
export
|
|
122
|
+
export interface GptHistoryModel extends mongoose.Model<GptHistoryDocument>, GptHistoryStatics {}
|
|
123
123
|
|
|
124
124
|
// ============================================================
|
|
125
125
|
// Project Types
|
|
@@ -133,7 +133,7 @@ export interface ProjectMemory {
|
|
|
133
133
|
text: string;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
export
|
|
136
|
+
export interface ProjectDocument extends mongoose.Document<mongoose.Types.ObjectId> {
|
|
137
137
|
created: Date;
|
|
138
138
|
deleted: boolean;
|
|
139
139
|
memories: ProjectMemory[];
|
|
@@ -141,13 +141,13 @@ export type ProjectDocument = mongoose.Document<mongoose.Types.ObjectId> & {
|
|
|
141
141
|
systemContext: string;
|
|
142
142
|
updated: Date;
|
|
143
143
|
userId: mongoose.Types.ObjectId;
|
|
144
|
-
}
|
|
144
|
+
}
|
|
145
145
|
|
|
146
146
|
export interface ProjectStatics
|
|
147
147
|
extends FindExactlyOnePlugin<ProjectDocument>,
|
|
148
148
|
FindOneOrNonePlugin<ProjectDocument> {}
|
|
149
149
|
|
|
150
|
-
export
|
|
150
|
+
export interface ProjectModel extends mongoose.Model<ProjectDocument>, ProjectStatics {}
|
|
151
151
|
|
|
152
152
|
// ============================================================
|
|
153
153
|
// AI Service Types
|
|
@@ -269,7 +269,9 @@ export interface FileAttachmentStatics
|
|
|
269
269
|
extends FindExactlyOnePlugin<FileAttachmentDocument>,
|
|
270
270
|
FindOneOrNonePlugin<FileAttachmentDocument> {}
|
|
271
271
|
|
|
272
|
-
export
|
|
272
|
+
export interface FileAttachmentModel
|
|
273
|
+
extends mongoose.Model<FileAttachmentDocument>,
|
|
274
|
+
FileAttachmentStatics {}
|
|
273
275
|
|
|
274
276
|
// ============================================================
|
|
275
277
|
// MCP Types
|