@layer-ai/core 2.0.48 → 2.0.50
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/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/db/migrations/010_add_task_subtype_to_gates.sql +1 -0
- package/dist/lib/db/postgres.d.ts.map +1 -1
- package/dist/lib/db/postgres.js +27 -24
- package/dist/lib/spending-jobs.d.ts +13 -7
- package/dist/lib/spending-jobs.d.ts.map +1 -1
- package/dist/lib/spending-jobs.js +61 -57
- package/dist/routes/v1/gates.d.ts.map +1 -1
- package/dist/routes/v1/gates.js +5 -2
- package/dist/services/providers/anthropic-adapter.js +3 -3
- package/dist/services/providers/google-adapter.js +3 -3
- package/dist/services/providers/mistral-adapter.js +3 -3
- package/dist/services/providers/openai-adapter.js +3 -3
- package/dist/services/task-analysis.d.ts.map +1 -1
- package/dist/services/task-analysis.js +2 -1
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -23,6 +23,6 @@ export * from './services/task-analysis.js';
|
|
|
23
23
|
export { initializeRegistry, getRegistry, getModel, hasModel, getModelEntries } from './lib/registry.js';
|
|
24
24
|
export { PROVIDER, PROVIDERS, type Provider, callAdapter, normalizeModelId, getProviderForModel } from './lib/provider-factory.js';
|
|
25
25
|
export { spendingTracker } from './lib/spending-tracker.js';
|
|
26
|
-
export {
|
|
26
|
+
export { spendingWorker } from './lib/spending-jobs.js';
|
|
27
27
|
export { gateSpendingTracker } from './lib/gate-spending-tracker.js';
|
|
28
28
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,OAAO,IAAI,WAAW,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MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG3C,OAAO,EAAE,EAAE,EAAE,MAAM,sBAAsB,CAAC;AAC1C,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAGrD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAGnD,eAAO,MAAM,gBAAgB,GAAU,QAAQ,MAAM,KAAG,OAAO,CAAC,MAAM,CAGrE,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAU,QAAQ,MAAM,KAAG,OAAO,CAAC,IAAI,CAG3E,CAAC;AAGF,cAAc,6BAA6B,CAAC;AAG5C,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGzG,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,QAAQ,EAAE,WAAW,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAGnI,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -39,5 +39,5 @@ export { initializeRegistry, getRegistry, getModel, hasModel, getModelEntries }
|
|
|
39
39
|
export { PROVIDER, PROVIDERS, callAdapter, normalizeModelId, getProviderForModel } from './lib/provider-factory.js';
|
|
40
40
|
// Spending Management
|
|
41
41
|
export { spendingTracker } from './lib/spending-tracker.js';
|
|
42
|
-
export {
|
|
42
|
+
export { spendingWorker } from './lib/spending-jobs.js';
|
|
43
43
|
export { gateSpendingTracker } from './lib/gate-spending-tracker.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE gates ADD COLUMN task_subtype VARCHAR(20);
|
|
@@ -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;0BAQxC,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;4BAU7B,MAAM,GAAG,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,WAAW,EAAE,IAAI,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,oBAAoB,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;+BAexI,MAAM,eAAe,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;kCAOxC,MAAM,QAAQ,MAAM,GAAG,OAAO,CAAC;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAC;0BAexG,MAAM,UAAU,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;iCAO/B,MAAM,SAAS,MAAM,GAAG,I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AS,GAAG,OAAO,CAAC;QACzC,eAAe,EAAE,MAAM,CAAC;QACxB,mBAAmB,EAAE,MAAM,CAAC;QAC5B,mBAAmB,EAAE,YAAY,GAAG,OAAO,CAAC;QAC5C,cAAc,EAAE,QAAQ,GAAG,WAAW,CAAC;QACvC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;KAC5B,GAAG,IAAI,CAAC;iCAkC0B,MAAM,SAAS,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;uCAStC,MAAM,eAAe,YAAY,GAAG,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;kCAShE,MAAM,UAAU,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;8BASvD,MAAM,QAAQ,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;8BASpC,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;+BASrB,OAAO,CAAC,MAAM,EAAE,CAAC;mCAab,MAAM,GAAG,OAAO,CAAC;QACpD,OAAO,EAAE,OAAO,CAAC;QACjB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,eAAe,EAAE,MAAM,CAAC;QACxB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,WAAW,EAAE,YAAY,GAAG,OAAO,CAAC;KACrC,CAAC;CAgDH,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
package/dist/lib/db/postgres.js
CHANGED
|
@@ -202,12 +202,13 @@ export const db = {
|
|
|
202
202
|
return result.rows.map(toCamelCase);
|
|
203
203
|
},
|
|
204
204
|
async createGate(userId, data) {
|
|
205
|
-
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, response_format_enabled, response_format_type, response_format_schema, spending_limit, spending_limit_period, spending_enforcement)
|
|
206
|
-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26) RETURNING *`, [
|
|
205
|
+
const result = await getPool().query(`INSERT INTO gates (user_id, name, description, task_type, task_subtype, 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, response_format_enabled, response_format_type, response_format_schema, spending_limit, spending_limit_period, spending_enforcement)
|
|
206
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27) RETURNING *`, [
|
|
207
207
|
userId,
|
|
208
208
|
data.name,
|
|
209
209
|
data.description,
|
|
210
210
|
data.taskType,
|
|
211
|
+
data.taskSubtype || null,
|
|
211
212
|
data.model,
|
|
212
213
|
data.systemPrompt,
|
|
213
214
|
data.allowOverrides ? JSON.stringify(data.allowOverrides) : null,
|
|
@@ -242,34 +243,36 @@ export const db = {
|
|
|
242
243
|
name = COALESCE($2, name),
|
|
243
244
|
description = COALESCE($3, description),
|
|
244
245
|
task_type = COALESCE($4, task_type),
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
246
|
+
task_subtype = COALESCE($5, task_subtype),
|
|
247
|
+
model = COALESCE($6, model),
|
|
248
|
+
system_prompt = COALESCE($7, system_prompt),
|
|
249
|
+
allow_overrides = COALESCE($8, allow_overrides),
|
|
250
|
+
temperature = COALESCE($9, temperature),
|
|
251
|
+
max_tokens = COALESCE($10, max_tokens),
|
|
252
|
+
top_p = COALESCE($11, top_p),
|
|
253
|
+
tags = COALESCE($12, tags),
|
|
254
|
+
routing_strategy = COALESCE($13, routing_strategy),
|
|
255
|
+
fallback_models = COALESCE($14, fallback_models),
|
|
256
|
+
cost_weight = COALESCE($15, cost_weight),
|
|
257
|
+
latency_weight = COALESCE($16, latency_weight),
|
|
258
|
+
quality_weight = COALESCE($17, quality_weight),
|
|
259
|
+
analysis_method = COALESCE($18, analysis_method),
|
|
260
|
+
reanalysis_period = COALESCE($19, reanalysis_period),
|
|
261
|
+
auto_apply_recommendations = COALESCE($20, auto_apply_recommendations),
|
|
262
|
+
task_analysis = COALESCE($21, task_analysis),
|
|
263
|
+
response_format_enabled = COALESCE($22, response_format_enabled),
|
|
264
|
+
response_format_type = COALESCE($23, response_format_type),
|
|
265
|
+
response_format_schema = COALESCE($24, response_format_schema),
|
|
266
|
+
spending_limit = COALESCE($25, spending_limit),
|
|
267
|
+
spending_limit_period = COALESCE($26, spending_limit_period),
|
|
268
|
+
spending_enforcement = COALESCE($27, spending_enforcement),
|
|
267
269
|
updated_at = NOW()
|
|
268
270
|
WHERE id = $1 RETURNING *`, [
|
|
269
271
|
id,
|
|
270
272
|
data.name,
|
|
271
273
|
data.description,
|
|
272
274
|
data.taskType,
|
|
275
|
+
data.taskSubtype || null,
|
|
273
276
|
data.model,
|
|
274
277
|
data.systemPrompt,
|
|
275
278
|
data.allowOverrides ? JSON.stringify(data.allowOverrides) : null,
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
declare class SpendingWorker {
|
|
2
|
+
private isRunning;
|
|
3
|
+
private syncTask;
|
|
4
|
+
private resetTask;
|
|
5
|
+
start(): void;
|
|
6
|
+
stop(): void;
|
|
7
|
+
private syncSpendingJob;
|
|
8
|
+
private resetSpendingPeriodsJob;
|
|
9
|
+
private resetGateSpendingPeriodsJob;
|
|
10
|
+
private resetUsageCountersJob;
|
|
11
|
+
}
|
|
12
|
+
export declare const spendingWorker: SpendingWorker;
|
|
13
|
+
export {};
|
|
8
14
|
//# sourceMappingURL=spending-jobs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spending-jobs.d.ts","sourceRoot":"","sources":["../../src/lib/spending-jobs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"spending-jobs.d.ts","sourceRoot":"","sources":["../../src/lib/spending-jobs.ts"],"names":[],"mappings":"AAKA,cAAM,cAAc;IAClB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAmC;IACnD,OAAO,CAAC,SAAS,CAAmC;IAEpD,KAAK;IAkBL,IAAI;YAUU,eAAe;YAiBf,uBAAuB;YAwBvB,2BAA2B;YAuB3B,qBAAqB;CAUpC;AAED,eAAO,MAAM,cAAc,gBAAuB,CAAC"}
|
|
@@ -1,98 +1,102 @@
|
|
|
1
|
+
import * as cron from 'node-cron';
|
|
1
2
|
import { db } from './db/postgres.js';
|
|
2
3
|
import { cache } from './db/redis.js';
|
|
3
4
|
import { spendingTracker } from './spending-tracker.js';
|
|
4
|
-
|
|
5
|
+
class SpendingWorker {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.isRunning = false;
|
|
8
|
+
this.syncTask = null;
|
|
9
|
+
this.resetTask = null;
|
|
10
|
+
}
|
|
11
|
+
start() {
|
|
12
|
+
console.log('[Spending Worker] Starting scheduled jobs');
|
|
13
|
+
// Sync Redis to DB every 5 minutes
|
|
14
|
+
this.syncTask = cron.schedule('*/5 * * * *', async () => {
|
|
15
|
+
await this.syncSpendingJob();
|
|
16
|
+
});
|
|
17
|
+
// Check for billing period resets every hour at :15
|
|
18
|
+
this.resetTask = cron.schedule('15 * * * *', async () => {
|
|
19
|
+
await this.resetSpendingPeriodsJob();
|
|
20
|
+
await this.resetGateSpendingPeriodsJob();
|
|
21
|
+
await this.resetUsageCountersJob();
|
|
22
|
+
});
|
|
23
|
+
console.log('[Spending Worker] Cron schedules activated');
|
|
24
|
+
}
|
|
25
|
+
stop() {
|
|
26
|
+
if (this.syncTask) {
|
|
27
|
+
this.syncTask.stop();
|
|
28
|
+
}
|
|
29
|
+
if (this.resetTask) {
|
|
30
|
+
this.resetTask.stop();
|
|
31
|
+
}
|
|
32
|
+
console.log('[Spending Worker] Stopped');
|
|
33
|
+
}
|
|
5
34
|
async syncSpendingJob() {
|
|
6
|
-
|
|
35
|
+
if (this.isRunning) {
|
|
36
|
+
console.log('[Spending Worker] Sync already in progress, skipping');
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this.isRunning = true;
|
|
7
40
|
try {
|
|
41
|
+
console.log('[Spending Worker] Starting periodic sync...');
|
|
8
42
|
await spendingTracker.syncAllSpending();
|
|
9
43
|
}
|
|
10
44
|
catch (error) {
|
|
11
|
-
console.error('[Spending
|
|
45
|
+
console.error('[Spending Worker] Sync failed:', error);
|
|
12
46
|
}
|
|
13
|
-
|
|
47
|
+
finally {
|
|
48
|
+
this.isRunning = false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
14
51
|
async resetSpendingPeriodsJob() {
|
|
15
|
-
console.log('[Spending
|
|
52
|
+
console.log('[Spending Worker] Checking for billing periods to reset...');
|
|
16
53
|
try {
|
|
17
54
|
const usersToReset = await db.getUsersToResetSpending();
|
|
18
55
|
if (usersToReset.length === 0) {
|
|
19
|
-
console.log('[Spending
|
|
56
|
+
console.log('[Spending Worker] No users need reset');
|
|
20
57
|
return;
|
|
21
58
|
}
|
|
22
|
-
console.log(`[Spending
|
|
59
|
+
console.log(`[Spending Worker] Resetting ${usersToReset.length} users`);
|
|
23
60
|
for (const userId of usersToReset) {
|
|
24
61
|
await db.resetUserSpending(userId);
|
|
25
62
|
await cache.invalidateUserSpending(userId);
|
|
26
|
-
console.log(`[Spending
|
|
63
|
+
console.log(`[Spending Worker] Reset user ${userId}`);
|
|
27
64
|
}
|
|
28
|
-
console.log('[Spending
|
|
65
|
+
console.log('[Spending Worker] Reset complete');
|
|
29
66
|
}
|
|
30
67
|
catch (error) {
|
|
31
|
-
console.error('[Spending
|
|
68
|
+
console.error('[Spending Worker] Reset failed:', error);
|
|
32
69
|
}
|
|
33
|
-
}
|
|
70
|
+
}
|
|
34
71
|
async resetGateSpendingPeriodsJob() {
|
|
35
|
-
console.log('[Spending
|
|
72
|
+
console.log('[Spending Worker] Checking for gate spending periods to reset...');
|
|
36
73
|
try {
|
|
37
74
|
const gatesToReset = await db.getGatesToResetSpending();
|
|
38
75
|
if (gatesToReset.length === 0) {
|
|
39
|
-
console.log('[Spending
|
|
76
|
+
console.log('[Spending Worker] No gates need reset');
|
|
40
77
|
return;
|
|
41
78
|
}
|
|
42
|
-
console.log(`[Spending
|
|
79
|
+
console.log(`[Spending Worker] Resetting ${gatesToReset.length} gates`);
|
|
43
80
|
for (const gateId of gatesToReset) {
|
|
44
81
|
await db.resetGateSpending(gateId);
|
|
45
|
-
console.log(`[Spending
|
|
82
|
+
console.log(`[Spending Worker] Reset gate ${gateId}`);
|
|
46
83
|
}
|
|
47
|
-
console.log('[Spending
|
|
84
|
+
console.log('[Spending Worker] Gate reset complete');
|
|
48
85
|
}
|
|
49
86
|
catch (error) {
|
|
50
|
-
console.error('[Spending
|
|
87
|
+
console.error('[Spending Worker] Gate reset failed:', error);
|
|
51
88
|
}
|
|
52
|
-
}
|
|
89
|
+
}
|
|
53
90
|
async resetUsageCountersJob() {
|
|
54
|
-
console.log('[Spending
|
|
91
|
+
console.log('[Spending Worker] Checking for usage counters to reset...');
|
|
55
92
|
try {
|
|
56
93
|
await db.resetDailyUsage();
|
|
57
94
|
await db.resetMonthlyUsage();
|
|
58
|
-
console.log('[Spending
|
|
95
|
+
console.log('[Spending Worker] Usage counters reset complete');
|
|
59
96
|
}
|
|
60
97
|
catch (error) {
|
|
61
|
-
console.error('[Spending
|
|
98
|
+
console.error('[Spending Worker] Usage counter reset failed:', error);
|
|
62
99
|
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
setInterval(() => {
|
|
67
|
-
this.syncSpendingJob().catch(err => {
|
|
68
|
-
console.error('[Spending Job] Sync interval error:', err);
|
|
69
|
-
});
|
|
70
|
-
}, 5 * 60 * 1000);
|
|
71
|
-
// Check for billing period resets every hour
|
|
72
|
-
setInterval(() => {
|
|
73
|
-
this.resetSpendingPeriodsJob().catch(err => {
|
|
74
|
-
console.error('[Spending Job] Reset interval error:', err);
|
|
75
|
-
});
|
|
76
|
-
this.resetGateSpendingPeriodsJob().catch(err => {
|
|
77
|
-
console.error('[Spending Job] Gate reset interval error:', err);
|
|
78
|
-
});
|
|
79
|
-
this.resetUsageCountersJob().catch(err => {
|
|
80
|
-
console.error('[Spending Job] Usage counter reset interval error:', err);
|
|
81
|
-
});
|
|
82
|
-
}, 60 * 60 * 1000);
|
|
83
|
-
// Run once on startup
|
|
84
|
-
this.syncSpendingJob().catch(err => {
|
|
85
|
-
console.error('[Spending Job] Initial sync error:', err);
|
|
86
|
-
});
|
|
87
|
-
this.resetSpendingPeriodsJob().catch(err => {
|
|
88
|
-
console.error('[Spending Job] Initial reset error:', err);
|
|
89
|
-
});
|
|
90
|
-
this.resetGateSpendingPeriodsJob().catch(err => {
|
|
91
|
-
console.error('[Spending Job] Initial gate reset error:', err);
|
|
92
|
-
});
|
|
93
|
-
this.resetUsageCountersJob().catch(err => {
|
|
94
|
-
console.error('[Spending Job] Initial usage counter reset error:', err);
|
|
95
|
-
});
|
|
96
|
-
console.log('[Spending Job] Scheduled jobs started');
|
|
97
|
-
},
|
|
98
|
-
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export const spendingWorker = new SpendingWorker();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gates.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/gates.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAQpD,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"gates.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/gates.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAQpD,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;AA4lBpC,eAAe,MAAM,CAAC"}
|
package/dist/routes/v1/gates.js
CHANGED
|
@@ -12,7 +12,7 @@ router.post('/', async (req, res) => {
|
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
14
|
try {
|
|
15
|
-
const { name, description, taskType, model, systemPrompt, allowOverrides, temperature, maxTokens, topP, tags, routingStrategy, fallbackModels, costWeight, latencyWeight, qualityWeight, reanalysisPeriod, taskAnalysis, responseFormatEnabled, responseFormatType, responseFormatSchema, spendingLimit, spendingLimitPeriod, spendingEnforcement } = req.body;
|
|
15
|
+
const { name, description, taskType, taskSubtype, model, systemPrompt, allowOverrides, temperature, maxTokens, topP, tags, routingStrategy, fallbackModels, costWeight, latencyWeight, qualityWeight, reanalysisPeriod, taskAnalysis, responseFormatEnabled, responseFormatType, responseFormatSchema, spendingLimit, spendingLimitPeriod, spendingEnforcement } = req.body;
|
|
16
16
|
if (!name || !model) {
|
|
17
17
|
res.status(400).json({ error: 'bad_request', message: 'Missing required fields: name and model' });
|
|
18
18
|
return;
|
|
@@ -30,6 +30,7 @@ router.post('/', async (req, res) => {
|
|
|
30
30
|
name,
|
|
31
31
|
description,
|
|
32
32
|
taskType,
|
|
33
|
+
taskSubtype,
|
|
33
34
|
model,
|
|
34
35
|
systemPrompt,
|
|
35
36
|
allowOverrides,
|
|
@@ -249,7 +250,7 @@ router.patch('/:id', async (req, res) => {
|
|
|
249
250
|
return;
|
|
250
251
|
}
|
|
251
252
|
try {
|
|
252
|
-
const { name, description, taskType, model, systemPrompt, allowOverrides, temperature, maxTokens, topP, tags, routingStrategy, fallbackModels, costWeight, latencyWeight, qualityWeight, analysisMethod, reanalysisPeriod, taskAnalysis, autoApplyRecommendations, responseFormatEnabled, responseFormatType, responseFormatSchema, spendingLimit, spendingLimitPeriod, spendingEnforcement } = req.body;
|
|
253
|
+
const { name, description, taskType, taskSubtype, model, systemPrompt, allowOverrides, temperature, maxTokens, topP, tags, routingStrategy, fallbackModels, costWeight, latencyWeight, qualityWeight, analysisMethod, reanalysisPeriod, taskAnalysis, autoApplyRecommendations, responseFormatEnabled, responseFormatType, responseFormatSchema, spendingLimit, spendingLimitPeriod, spendingEnforcement } = req.body;
|
|
253
254
|
const existing = await db.getGateById(req.params.id);
|
|
254
255
|
if (!existing) {
|
|
255
256
|
res.status(404).json({ error: 'not_found', message: 'Gate not found' });
|
|
@@ -268,6 +269,7 @@ router.patch('/:id', async (req, res) => {
|
|
|
268
269
|
name,
|
|
269
270
|
description,
|
|
270
271
|
taskType,
|
|
272
|
+
taskSubtype,
|
|
271
273
|
model,
|
|
272
274
|
systemPrompt,
|
|
273
275
|
temperature,
|
|
@@ -292,6 +294,7 @@ router.patch('/:id', async (req, res) => {
|
|
|
292
294
|
name,
|
|
293
295
|
description,
|
|
294
296
|
taskType,
|
|
297
|
+
taskSubtype,
|
|
295
298
|
model,
|
|
296
299
|
systemPrompt,
|
|
297
300
|
allowOverrides,
|
|
@@ -9,7 +9,7 @@ function getAnthropicClient(apiKey) {
|
|
|
9
9
|
}
|
|
10
10
|
if (!anthropic) {
|
|
11
11
|
anthropic = new Anthropic({
|
|
12
|
-
apiKey: process.env.
|
|
12
|
+
apiKey: process.env.LAYER_PLATFORM_ANTHROPIC_API_KEY,
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
return anthropic;
|
|
@@ -52,7 +52,7 @@ export class AnthropicAdapter extends BaseProviderAdapter {
|
|
|
52
52
|
return super.mapToolChoice(choice);
|
|
53
53
|
}
|
|
54
54
|
async call(request, userId) {
|
|
55
|
-
const resolved = await resolveApiKey(this.provider, userId, process.env.
|
|
55
|
+
const resolved = await resolveApiKey(this.provider, userId, process.env.LAYER_PLATFORM_ANTHROPIC_API_KEY);
|
|
56
56
|
switch (request.type) {
|
|
57
57
|
case 'chat':
|
|
58
58
|
return this.handleChat(request, resolved.key, resolved.usedPlatformKey);
|
|
@@ -69,7 +69,7 @@ export class AnthropicAdapter extends BaseProviderAdapter {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
async *callStream(request, userId) {
|
|
72
|
-
const resolved = await resolveApiKey(this.provider, userId, process.env.
|
|
72
|
+
const resolved = await resolveApiKey(this.provider, userId, process.env.LAYER_PLATFORM_ANTHROPIC_API_KEY);
|
|
73
73
|
switch (request.type) {
|
|
74
74
|
case 'chat':
|
|
75
75
|
yield* this.handleChatStream(request, resolved.key, resolved.usedPlatformKey);
|
|
@@ -9,7 +9,7 @@ function getGoogleClient(apiKey) {
|
|
|
9
9
|
return new GoogleGenAI({ apiKey });
|
|
10
10
|
}
|
|
11
11
|
if (!client) {
|
|
12
|
-
client = new GoogleGenAI({ apiKey: process.env.
|
|
12
|
+
client = new GoogleGenAI({ apiKey: process.env.LAYER_PLATFORM_GOOGLE_API_KEY || '' });
|
|
13
13
|
}
|
|
14
14
|
return client;
|
|
15
15
|
}
|
|
@@ -56,7 +56,7 @@ export class GoogleAdapter extends BaseProviderAdapter {
|
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
async call(request, userId) {
|
|
59
|
-
const resolved = await resolveApiKey(this.provider, userId, process.env.
|
|
59
|
+
const resolved = await resolveApiKey(this.provider, userId, process.env.LAYER_PLATFORM_GOOGLE_API_KEY);
|
|
60
60
|
switch (request.type) {
|
|
61
61
|
case 'chat':
|
|
62
62
|
return this.handleChat(request, resolved.key, resolved.usedPlatformKey);
|
|
@@ -73,7 +73,7 @@ export class GoogleAdapter extends BaseProviderAdapter {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
async *callStream(request, userId) {
|
|
76
|
-
const resolved = await resolveApiKey(this.provider, userId, process.env.
|
|
76
|
+
const resolved = await resolveApiKey(this.provider, userId, process.env.LAYER_PLATFORM_GOOGLE_API_KEY);
|
|
77
77
|
switch (request.type) {
|
|
78
78
|
case 'chat':
|
|
79
79
|
yield* this.handleChatStream(request, resolved.key, resolved.usedPlatformKey);
|
|
@@ -12,7 +12,7 @@ function getMistralClient(apiKey) {
|
|
|
12
12
|
// Otherwise use singleton with platform key
|
|
13
13
|
if (!client) {
|
|
14
14
|
client = new Mistral({
|
|
15
|
-
apiKey: process.env.
|
|
15
|
+
apiKey: process.env.LAYER_PLATFORM_MISTRAL_API_KEY || '',
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
return client;
|
|
@@ -46,7 +46,7 @@ export class MistralAdapter extends BaseProviderAdapter {
|
|
|
46
46
|
}
|
|
47
47
|
async call(request, userId) {
|
|
48
48
|
// Resolve API key (BYOK → Platform key)
|
|
49
|
-
const resolved = await resolveApiKey(this.provider, userId, process.env.
|
|
49
|
+
const resolved = await resolveApiKey(this.provider, userId, process.env.LAYER_PLATFORM_MISTRAL_API_KEY);
|
|
50
50
|
switch (request.type) {
|
|
51
51
|
case 'chat':
|
|
52
52
|
return this.handleChat(request, resolved.key, resolved.usedPlatformKey);
|
|
@@ -65,7 +65,7 @@ export class MistralAdapter extends BaseProviderAdapter {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
async *callStream(request, userId) {
|
|
68
|
-
const resolved = await resolveApiKey(this.provider, userId, process.env.
|
|
68
|
+
const resolved = await resolveApiKey(this.provider, userId, process.env.LAYER_PLATFORM_MISTRAL_API_KEY);
|
|
69
69
|
switch (request.type) {
|
|
70
70
|
case 'chat':
|
|
71
71
|
yield* this.handleChatStream(request, resolved.key, resolved.usedPlatformKey);
|
|
@@ -9,7 +9,7 @@ function getOpenAIClient(apiKey) {
|
|
|
9
9
|
}
|
|
10
10
|
if (!openai) {
|
|
11
11
|
openai = new OpenAI({
|
|
12
|
-
apiKey: process.env.
|
|
12
|
+
apiKey: process.env.LAYER_PLATFORM_OPENAI_API_KEY,
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
return openai;
|
|
@@ -71,7 +71,7 @@ export class OpenAIAdapter extends BaseProviderAdapter {
|
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
73
|
async call(request, userId) {
|
|
74
|
-
const resolved = await resolveApiKey(this.provider, userId, process.env.
|
|
74
|
+
const resolved = await resolveApiKey(this.provider, userId, process.env.LAYER_PLATFORM_OPENAI_API_KEY);
|
|
75
75
|
switch (request.type) {
|
|
76
76
|
case 'chat':
|
|
77
77
|
return this.handleChat(request, resolved.key, resolved.usedPlatformKey);
|
|
@@ -88,7 +88,7 @@ export class OpenAIAdapter extends BaseProviderAdapter {
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
async *callStream(request, userId) {
|
|
91
|
-
const resolved = await resolveApiKey(this.provider, userId, process.env.
|
|
91
|
+
const resolved = await resolveApiKey(this.provider, userId, process.env.LAYER_PLATFORM_OPENAI_API_KEY);
|
|
92
92
|
switch (request.type) {
|
|
93
93
|
case 'chat':
|
|
94
94
|
yield* this.handleChatStream(request, resolved.key, resolved.usedPlatformKey);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-analysis.d.ts","sourceRoot":"","sources":["../../src/services/task-analysis.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAmC,MAAM,eAAe,CAAC;AA6D9E,wBAAsB,WAAW,CAC/B,WAAW,EAAE,MAAM,EACnB,eAAe,CAAC,EAAE;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC/B,GACA,OAAO,CAAC,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"task-analysis.d.ts","sourceRoot":"","sources":["../../src/services/task-analysis.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAmC,MAAM,eAAe,CAAC;AA6D9E,wBAAsB,WAAW,CAC/B,WAAW,EAAE,MAAM,EACnB,eAAe,CAAC,EAAE;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC/B,GACA,OAAO,CAAC,YAAY,CAAC,CA8HvB"}
|
|
@@ -53,7 +53,7 @@ Return ONLY the task type as a single word, nothing else.`;
|
|
|
53
53
|
}
|
|
54
54
|
export async function analyzeTask(description, userPreferences) {
|
|
55
55
|
const anthropic = new Anthropic({
|
|
56
|
-
apiKey: process.env.
|
|
56
|
+
apiKey: process.env.LAYER_PLATFORM_ANTHROPIC_API_KEY
|
|
57
57
|
});
|
|
58
58
|
const costWeight = userPreferences?.costWeight ?? 0.33;
|
|
59
59
|
const latencyWeight = userPreferences?.latencyWeight ?? 0.33;
|
|
@@ -100,6 +100,7 @@ USER PREFERENCES (0.0 = doesn't care, 1.0 = very important):
|
|
|
100
100
|
Analyze this task and recommend the BEST models from our registry that match BOTH the task requirements AND user preferences.
|
|
101
101
|
|
|
102
102
|
Consider:
|
|
103
|
+
- Model subtype (prefer "reasoning" subtype for complex multi-step reasoning, "code" subtype for programming, "realtime" subtype for low-latency streaming)
|
|
103
104
|
- Math benchmarks (for quantitative tasks)
|
|
104
105
|
- Coding benchmarks (for programming tasks)
|
|
105
106
|
- Intelligence scores (for reasoning)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layer-ai/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.50",
|
|
4
4
|
"description": "Core API routes and services for Layer AI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -34,15 +34,17 @@
|
|
|
34
34
|
"ioredis": "^5.3.2",
|
|
35
35
|
"jsonwebtoken": "^9.0.2",
|
|
36
36
|
"nanoid": "^5.0.4",
|
|
37
|
+
"node-cron": "^4.2.1",
|
|
37
38
|
"openai": "^4.24.0",
|
|
38
39
|
"pg": "^8.11.3",
|
|
39
|
-
"@layer-ai/sdk": "^2.5.
|
|
40
|
+
"@layer-ai/sdk": "^2.5.14"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"@types/bcryptjs": "^2.4.6",
|
|
43
44
|
"@types/express": "^4.17.21",
|
|
44
45
|
"@types/jsonwebtoken": "^9.0.5",
|
|
45
46
|
"@types/node": "^20.10.4",
|
|
47
|
+
"@types/node-cron": "^3.0.11",
|
|
46
48
|
"@types/pg": "^8.10.9",
|
|
47
49
|
"typescript": "^5.3.3"
|
|
48
50
|
},
|