@layer-ai/core 0.8.11 → 0.8.13
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.
|
@@ -43,8 +43,10 @@ export declare const db: {
|
|
|
43
43
|
createGateHistory(gateId: string, gate: Partial<Gate>, appliedBy: "user" | "auto", changedFields?: string[]): Promise<void>;
|
|
44
44
|
getGateHistory(gateId: string, limit?: number): Promise<any[]>;
|
|
45
45
|
getGateHistoryById(id: string): Promise<any | null>;
|
|
46
|
+
getAllGatesHistory(userId: string, limit?: number): Promise<any[]>;
|
|
46
47
|
createActivityLog(gateId: string, userId: string | null, action: "manual_update" | "auto_update" | "reanalysis" | "rollback", details: any): Promise<void>;
|
|
47
48
|
getActivityLog(gateId: string, limit?: number): Promise<any[]>;
|
|
49
|
+
getAllGatesActivity(userId: string, limit?: number): Promise<any[]>;
|
|
48
50
|
rollbackGate(gateId: string, historyId: string, userId: string): Promise<Gate | null>;
|
|
49
51
|
};
|
|
50
52
|
export default getPool;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../../src/lib/db/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAyB,WAAW,EAAE,MAAM,eAAe,CAAC;AAO5F,iBAAS,OAAO,IAAI,EAAE,CAAC,IAAI,CAqB1B;AA0BD,eAAO,MAAM,EAAE;gBAEK,MAAM,WAAW,GAAG,EAAE;0BASZ,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;oBAQnC,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;sBAQ3B,MAAM,gBAAgB,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;6BASrC,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;yBAQnC,MAAM,WAAW,MAAM,a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OAAO,CAAC,OAAO,CAAC;qCAQzC,MAAM,GAAQ,OAAO,CAAC,WAAW,EAAE,CAAC;8BAahE,MAAM,QACR,OAAO,CAAC,IAAI,CAAC,aACR,MAAM,GAAG,MAAM,kBACV,MAAM,EAAE,GACvB,OAAO,CAAC,IAAI,CAAC;2BA8Ca,MAAM,UAAS,MAAM,GAAQ,OAAO,CAAC,GAAG,EAAE,CAAC;2BAW3C,MAAM,GAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC;+BAQxB,MAAM,UAAS,MAAM,GAAS,OAAO,CAAC,GAAG,EAAE,CAAC;8BAcnE,MAAM,UACN,MAAM,GAAG,IAAI,UACb,eAAe,GAAG,aAAa,GAAG,YAAY,GAAG,UAAU,WAC1D,GAAG,GACX,OAAO,CAAC,IAAI,CAAC;2BAQa,MAAM,UAAS,MAAM,GAAQ,OAAO,CAAC,GAAG,EAAE,CAAC;gCAWtC,MAAM,UAAS,MAAM,GAAS,OAAO,CAAC,GAAG,EAAE,CAAC;yBAYnD,MAAM,aAAa,MAAM,UAAU,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;CA+E5F,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
package/dist/lib/db/postgres.js
CHANGED
|
@@ -98,8 +98,8 @@ export const db = {
|
|
|
98
98
|
return result.rows.map(toCamelCase);
|
|
99
99
|
},
|
|
100
100
|
async createGate(userId, data) {
|
|
101
|
-
const result = await getPool().query(`INSERT INTO gates (user_id, name, description, task_type, model, system_prompt, allow_overrides, temperature, max_tokens, top_p, tags, routing_strategy, fallback_models, cost_weight, latency_weight, quality_weight, analysis_method, reanalysis_period, task_analysis)
|
|
102
|
-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19) RETURNING *`, [
|
|
101
|
+
const result = await getPool().query(`INSERT INTO gates (user_id, name, description, task_type, model, system_prompt, allow_overrides, temperature, max_tokens, top_p, tags, routing_strategy, fallback_models, cost_weight, latency_weight, quality_weight, analysis_method, reanalysis_period, auto_apply_recommendations, task_analysis)
|
|
102
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20) RETURNING *`, [
|
|
103
103
|
userId,
|
|
104
104
|
data.name,
|
|
105
105
|
data.description,
|
|
@@ -118,6 +118,7 @@ export const db = {
|
|
|
118
118
|
data.qualityWeight ?? 0.34,
|
|
119
119
|
data.analysisMethod || 'balanced',
|
|
120
120
|
data.reanalysisPeriod || 'never',
|
|
121
|
+
data.autoApplyRecommendations ?? false,
|
|
121
122
|
data.taskAnalysis ? JSON.stringify(data.taskAnalysis) : null
|
|
122
123
|
]);
|
|
123
124
|
return toCamelCase(result.rows[0]);
|
|
@@ -145,7 +146,8 @@ export const db = {
|
|
|
145
146
|
quality_weight = COALESCE($16, quality_weight),
|
|
146
147
|
analysis_method = COALESCE($17, analysis_method),
|
|
147
148
|
reanalysis_period = COALESCE($18, reanalysis_period),
|
|
148
|
-
|
|
149
|
+
auto_apply_recommendations = COALESCE($19, auto_apply_recommendations),
|
|
150
|
+
task_analysis = COALESCE($20, task_analysis),
|
|
149
151
|
updated_at = NOW()
|
|
150
152
|
WHERE id = $1 RETURNING *`, [
|
|
151
153
|
id,
|
|
@@ -166,6 +168,7 @@ export const db = {
|
|
|
166
168
|
data.qualityWeight,
|
|
167
169
|
data.analysisMethod,
|
|
168
170
|
data.reanalysisPeriod,
|
|
171
|
+
data.autoApplyRecommendations,
|
|
169
172
|
data.taskAnalysis ? JSON.stringify(data.taskAnalysis) : null,
|
|
170
173
|
]);
|
|
171
174
|
return result.rows[0] ? toCamelCase(result.rows[0]) : null;
|
|
@@ -289,6 +292,14 @@ export const db = {
|
|
|
289
292
|
const result = await getPool().query('SELECT * FROM gate_history WHERE id = $1', [id]);
|
|
290
293
|
return result.rows[0] ? toCamelCase(result.rows[0]) : null;
|
|
291
294
|
},
|
|
295
|
+
async getAllGatesHistory(userId, limit = 100) {
|
|
296
|
+
const result = await getPool().query(`SELECT gh.* FROM gate_history gh
|
|
297
|
+
JOIN gates g ON gh.gate_id = g.id
|
|
298
|
+
WHERE g.user_id = $1
|
|
299
|
+
ORDER BY gh.created_at DESC
|
|
300
|
+
LIMIT $2`, [userId, limit]);
|
|
301
|
+
return result.rows.map(toCamelCase);
|
|
302
|
+
},
|
|
292
303
|
// Activity Log
|
|
293
304
|
async createActivityLog(gateId, userId, action, details) {
|
|
294
305
|
await getPool().query(`INSERT INTO gate_activity_log (gate_id, user_id, action, details)
|
|
@@ -301,6 +312,14 @@ export const db = {
|
|
|
301
312
|
LIMIT $2`, [gateId, limit]);
|
|
302
313
|
return result.rows.map(toCamelCase);
|
|
303
314
|
},
|
|
315
|
+
async getAllGatesActivity(userId, limit = 100) {
|
|
316
|
+
const result = await getPool().query(`SELECT gal.* FROM gate_activity_log gal
|
|
317
|
+
JOIN gates g ON gal.gate_id = g.id
|
|
318
|
+
WHERE g.user_id = $1
|
|
319
|
+
ORDER BY gal.timestamp DESC
|
|
320
|
+
LIMIT $2`, [userId, limit]);
|
|
321
|
+
return result.rows.map(toCamelCase);
|
|
322
|
+
},
|
|
304
323
|
async rollbackGate(gateId, historyId, userId) {
|
|
305
324
|
// Get the historical configuration
|
|
306
325
|
const historyEntry = await this.getGateHistoryById(historyId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gate-history.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/gate-history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGjC,QAAA,MAAM,MAAM,EAAE,MAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"gate-history.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/gate-history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGjC,QAAA,MAAM,MAAM,EAAE,MAAiB,CAAC;AA6JhC,eAAe,MAAM,CAAC"}
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import { db } from '../../lib/db/postgres.js';
|
|
3
3
|
const router = Router();
|
|
4
|
+
/**
|
|
5
|
+
* GET /v1/gates/history
|
|
6
|
+
* Get history for all gates belonging to the user
|
|
7
|
+
*/
|
|
8
|
+
router.get('/history', async (req, res) => {
|
|
9
|
+
try {
|
|
10
|
+
const limit = req.query.limit ? parseInt(req.query.limit, 10) : 100;
|
|
11
|
+
const history = await db.getAllGatesHistory(req.userId, limit);
|
|
12
|
+
res.json(history);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
console.error('Error fetching all gates history:', error);
|
|
16
|
+
res.status(500).json({ error: 'Failed to fetch history' });
|
|
17
|
+
}
|
|
18
|
+
});
|
|
4
19
|
/**
|
|
5
20
|
* GET /v1/gates/:gateId/history
|
|
6
21
|
* Get history for a gate
|
|
@@ -24,6 +39,21 @@ router.get('/:gateId/history', async (req, res) => {
|
|
|
24
39
|
res.status(500).json({ error: 'Failed to fetch history' });
|
|
25
40
|
}
|
|
26
41
|
});
|
|
42
|
+
/**
|
|
43
|
+
* GET /v1/gates/activity
|
|
44
|
+
* Get activity log for all gates belonging to the user
|
|
45
|
+
*/
|
|
46
|
+
router.get('/activity', async (req, res) => {
|
|
47
|
+
try {
|
|
48
|
+
const limit = req.query.limit ? parseInt(req.query.limit, 10) : 100;
|
|
49
|
+
const activity = await db.getAllGatesActivity(req.userId, limit);
|
|
50
|
+
res.json(activity);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
console.error('Error fetching all gates activity:', error);
|
|
54
|
+
res.status(500).json({ error: 'Failed to fetch activity' });
|
|
55
|
+
}
|
|
56
|
+
});
|
|
27
57
|
/**
|
|
28
58
|
* GET /v1/gates/:gateId/activity
|
|
29
59
|
* Get activity log for a gate
|