@layer-ai/core 2.0.46 → 2.0.47
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 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/lib/provider-factory.d.ts.map +1 -1
- package/dist/lib/provider-factory.js +4 -4
- package/dist/lib/registry.d.ts +17 -0
- package/dist/lib/registry.d.ts.map +1 -0
- package/dist/lib/registry.js +50 -0
- package/dist/routes/v1/gates.js +3 -3
- package/dist/services/providers/base-adapter.d.ts.map +1 -1
- package/dist/services/providers/base-adapter.js +18 -9
- package/dist/services/task-analysis.d.ts.map +1 -1
- package/dist/services/task-analysis.js +2 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export type { EncryptedData } from '@layer-ai/sdk';
|
|
|
20
20
|
export declare const createSessionKey: (userId: string) => Promise<string>;
|
|
21
21
|
export declare const deleteSessionKeysForUser: (userId: string) => Promise<void>;
|
|
22
22
|
export * from './services/task-analysis.js';
|
|
23
|
+
export { initializeRegistry, getRegistry, getModel, hasModel, getModelEntries } from './lib/registry.js';
|
|
23
24
|
export { PROVIDER, PROVIDERS, type Provider, callAdapter, normalizeModelId, getProviderForModel } from './lib/provider-factory.js';
|
|
24
25
|
export { spendingTracker } from './lib/spending-tracker.js';
|
|
25
26
|
export { spendingJobs } from './lib/spending-jobs.js';
|
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,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,OAAO,I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C;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,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -33,6 +33,8 @@ export const deleteSessionKeysForUser = async (userId) => {
|
|
|
33
33
|
};
|
|
34
34
|
// Services
|
|
35
35
|
export * from './services/task-analysis.js';
|
|
36
|
+
// Model Registry
|
|
37
|
+
export { initializeRegistry, getRegistry, getModel, hasModel, getModelEntries } from './lib/registry.js';
|
|
36
38
|
// Provider Factory
|
|
37
39
|
export { PROVIDER, PROVIDERS, callAdapter, normalizeModelId, getProviderForModel } from './lib/provider-factory.js';
|
|
38
40
|
// Spending Management
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-factory.d.ts","sourceRoot":"","sources":["../../src/lib/provider-factory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"provider-factory.d.ts","sourceRoot":"","sources":["../../src/lib/provider-factory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAI7E,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,QAAQ,EAAE,CAAC;AAa9C;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,CAmBhE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,cAAc,GAAG,QAAQ,CAMnE;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAWhG;AAED;;;;;GAKG;AACH,wBAAuB,iBAAiB,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC,aAAa,CAAC,CAgB7G"}
|
|
@@ -9,8 +9,8 @@ import { OpenAIAdapter } from '../services/providers/openai-adapter.js';
|
|
|
9
9
|
import { AnthropicAdapter } from '../services/providers/anthropic-adapter.js';
|
|
10
10
|
import { GoogleAdapter } from '../services/providers/google-adapter.js';
|
|
11
11
|
import { MistralAdapter } from '../services/providers/mistral-adapter.js';
|
|
12
|
-
import { MODEL_REGISTRY } from '@layer-ai/sdk';
|
|
13
12
|
import { PROVIDER, PROVIDERS } from './provider-constants.js';
|
|
13
|
+
import { getModel, hasModel } from './registry.js';
|
|
14
14
|
// Re-export for convenience
|
|
15
15
|
export { PROVIDER, PROVIDERS };
|
|
16
16
|
/**
|
|
@@ -28,7 +28,7 @@ const PROVIDER_ADAPTERS = {
|
|
|
28
28
|
* Supports both full IDs (e.g., "openai/gpt-4") and short IDs (e.g., "gpt-4").
|
|
29
29
|
*/
|
|
30
30
|
export function normalizeModelId(modelId) {
|
|
31
|
-
if (
|
|
31
|
+
if (hasModel(modelId)) {
|
|
32
32
|
return modelId;
|
|
33
33
|
}
|
|
34
34
|
const providers = [
|
|
@@ -39,7 +39,7 @@ export function normalizeModelId(modelId) {
|
|
|
39
39
|
];
|
|
40
40
|
for (const provider of providers) {
|
|
41
41
|
const fullId = `${provider}/${modelId}`;
|
|
42
|
-
if (
|
|
42
|
+
if (hasModel(fullId)) {
|
|
43
43
|
return fullId;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -49,7 +49,7 @@ export function normalizeModelId(modelId) {
|
|
|
49
49
|
* Gets the provider type for a given model
|
|
50
50
|
*/
|
|
51
51
|
export function getProviderForModel(model) {
|
|
52
|
-
const modelInfo =
|
|
52
|
+
const modelInfo = getModel(model);
|
|
53
53
|
if (!modelInfo) {
|
|
54
54
|
throw new Error(`Model "${model}" not found in registry`);
|
|
55
55
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime Model Registry
|
|
3
|
+
*
|
|
4
|
+
* Starts with static SDK data, fetches fresh data from the API
|
|
5
|
+
* at startup. Falls back to SDK data if the API is unreachable or
|
|
6
|
+
* API_URL is not set (e.g., local dev).
|
|
7
|
+
*/
|
|
8
|
+
interface InitOptions {
|
|
9
|
+
refreshIntervalMs?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare function initializeRegistry(options?: InitOptions): Promise<void>;
|
|
12
|
+
export declare function getRegistry(): Record<string, any>;
|
|
13
|
+
export declare function getModel(modelId: string): any | undefined;
|
|
14
|
+
export declare function hasModel(modelId: string): boolean;
|
|
15
|
+
export declare function getModelEntries(): [string, any][];
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/lib/registry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,UAAU,WAAW;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,wBAAsB,kBAAkB,CAAC,OAAO,GAAE,WAAgB,iBAcjE;AAgBD,wBAAgB,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAEjD;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,CAEzD;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED,wBAAgB,eAAe,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAEjD"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime Model Registry
|
|
3
|
+
*
|
|
4
|
+
* Starts with static SDK data, fetches fresh data from the API
|
|
5
|
+
* at startup. Falls back to SDK data if the API is unreachable or
|
|
6
|
+
* API_URL is not set (e.g., local dev).
|
|
7
|
+
*/
|
|
8
|
+
import { MODEL_REGISTRY as STATIC_REGISTRY } from '@layer-ai/sdk';
|
|
9
|
+
let registry = { ...STATIC_REGISTRY };
|
|
10
|
+
let refreshTimer = null;
|
|
11
|
+
export async function initializeRegistry(options = {}) {
|
|
12
|
+
const apiUrl = process.env.API_URL;
|
|
13
|
+
if (!apiUrl) {
|
|
14
|
+
console.log('[Registry] No API_URL set, using static SDK data');
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
await fetchRegistry(apiUrl);
|
|
18
|
+
if (options.refreshIntervalMs) {
|
|
19
|
+
refreshTimer = setInterval(() => fetchRegistry(apiUrl), options.refreshIntervalMs);
|
|
20
|
+
// Allow the process to exit even if the timer is active
|
|
21
|
+
refreshTimer.unref();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function fetchRegistry(apiUrl) {
|
|
25
|
+
try {
|
|
26
|
+
const res = await fetch(`${apiUrl}/v1/registry`, {
|
|
27
|
+
signal: AbortSignal.timeout(10000),
|
|
28
|
+
});
|
|
29
|
+
if (!res.ok)
|
|
30
|
+
throw new Error(`HTTP ${res.status}`);
|
|
31
|
+
const data = await res.json();
|
|
32
|
+
registry = data.models;
|
|
33
|
+
console.log(`[Registry] Loaded ${Object.keys(registry).length} models from API`);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
console.warn('[Registry] Fetch failed, using existing data:', err);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function getRegistry() {
|
|
40
|
+
return registry;
|
|
41
|
+
}
|
|
42
|
+
export function getModel(modelId) {
|
|
43
|
+
return registry[modelId];
|
|
44
|
+
}
|
|
45
|
+
export function hasModel(modelId) {
|
|
46
|
+
return modelId in registry;
|
|
47
|
+
}
|
|
48
|
+
export function getModelEntries() {
|
|
49
|
+
return Object.entries(registry);
|
|
50
|
+
}
|
package/dist/routes/v1/gates.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Router } from 'express';
|
|
|
2
2
|
import { db } from '../../lib/db/postgres.js';
|
|
3
3
|
import { cache } from '../../lib/db/redis.js';
|
|
4
4
|
import { callAdapter } from '../../lib/provider-factory.js';
|
|
5
|
-
import {
|
|
5
|
+
import { hasModel } from '../../lib/registry.js';
|
|
6
6
|
import { detectSignificantChanges } from '../../lib/gate-utils.js';
|
|
7
7
|
const router = Router();
|
|
8
8
|
// POST / - Create a new gate
|
|
@@ -17,7 +17,7 @@ router.post('/', async (req, res) => {
|
|
|
17
17
|
res.status(400).json({ error: 'bad_request', message: 'Missing required fields: name and model' });
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
|
-
if (!
|
|
20
|
+
if (!hasModel(model)) {
|
|
21
21
|
res.status(400).json({ error: 'bad_request', message: `Unsupported model: ${model}` });
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
@@ -259,7 +259,7 @@ router.patch('/:id', async (req, res) => {
|
|
|
259
259
|
res.status(404).json({ error: 'not_found', message: 'Gate not found' });
|
|
260
260
|
return;
|
|
261
261
|
}
|
|
262
|
-
if (model && !
|
|
262
|
+
if (model && !hasModel(model)) {
|
|
263
263
|
res.status(400).json({ error: 'bad_request', message: `Unsupported model: ${model}` });
|
|
264
264
|
return;
|
|
265
265
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-adapter.d.ts","sourceRoot":"","sources":["../../../src/services/providers/base-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,aAAa,EACb,IAAI,EACJ,WAAW,EACX,SAAS,EACT,YAAY,EACZ,UAAU,EACV,SAAS,EACT,WAAW,EACX,aAAa,EACb,aAAa,EACb,YAAY,EACZ,UAAU,EACV,cAAc,EACd,eAAe,
|
|
1
|
+
{"version":3,"file":"base-adapter.d.ts","sourceRoot":"","sources":["../../../src/services/providers/base-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,aAAa,EACb,IAAI,EACJ,WAAW,EACX,SAAS,EACT,YAAY,EACZ,UAAU,EACV,SAAS,EACT,WAAW,EACX,aAAa,EACb,aAAa,EACb,YAAY,EACZ,UAAU,EACV,cAAc,EACd,eAAe,EAChB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAGhE,OAAO,EAAE,eAAe,EAAE,CAAC;AAE3B,8BAAsB,mBAAmB;IACvC,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IACtC,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAE1B,SAAS,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC9C,SAAS,CA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'@layer-ai/sdk';
|
|
2
|
+
import { getModel } from '../../lib/registry.js';
|
|
2
3
|
export { ADAPTER_HANDLED };
|
|
3
4
|
export class BaseProviderAdapter {
|
|
4
5
|
mapRole(role) {
|
|
@@ -81,7 +82,7 @@ export class BaseProviderAdapter {
|
|
|
81
82
|
return this.toolChoiceMappings[choice];
|
|
82
83
|
}
|
|
83
84
|
calculateCost(model, promptTokens, completionTokens) {
|
|
84
|
-
const modelInfo =
|
|
85
|
+
const modelInfo = getModel(model);
|
|
85
86
|
if (!modelInfo || !('pricing' in modelInfo) || !modelInfo.pricing?.input) {
|
|
86
87
|
return 0;
|
|
87
88
|
}
|
|
@@ -91,17 +92,25 @@ export class BaseProviderAdapter {
|
|
|
91
92
|
return inputCost + outputCost;
|
|
92
93
|
}
|
|
93
94
|
calculateImageCost(model, quality, size, count = 1) {
|
|
94
|
-
const modelInfo =
|
|
95
|
-
if (!modelInfo
|
|
95
|
+
const modelInfo = getModel(model);
|
|
96
|
+
if (!modelInfo)
|
|
96
97
|
return 0;
|
|
98
|
+
// Support new unitPricing format (per_image key) and legacy imagePricing
|
|
99
|
+
let perImagePricing;
|
|
100
|
+
if ('unitPricing' in modelInfo && modelInfo.unitPricing?.per_image) {
|
|
101
|
+
perImagePricing = modelInfo.unitPricing.per_image;
|
|
97
102
|
}
|
|
98
|
-
|
|
103
|
+
else if ('imagePricing' in modelInfo && modelInfo.imagePricing) {
|
|
104
|
+
perImagePricing = modelInfo.imagePricing;
|
|
105
|
+
}
|
|
106
|
+
if (!perImagePricing)
|
|
107
|
+
return 0;
|
|
99
108
|
// Flat-rate pricing (e.g. Google Imagen models)
|
|
100
|
-
if (typeof
|
|
101
|
-
return
|
|
109
|
+
if (typeof perImagePricing === 'number') {
|
|
110
|
+
return perImagePricing * count;
|
|
102
111
|
}
|
|
103
112
|
// Build pricing key from quality and size (e.g., 'hd-1024x1024' or 'standard-1024x1024')
|
|
104
|
-
const pricingTable =
|
|
113
|
+
const pricingTable = perImagePricing;
|
|
105
114
|
const pricingKey = quality && size ? `${quality}-${size}` : size || 'standard-1024x1024';
|
|
106
115
|
const pricePerImage = pricingTable[pricingKey];
|
|
107
116
|
if (!pricePerImage) {
|
|
@@ -112,7 +121,7 @@ export class BaseProviderAdapter {
|
|
|
112
121
|
return pricePerImage * count;
|
|
113
122
|
}
|
|
114
123
|
calculateVideoCost(model, duration, count = 1) {
|
|
115
|
-
const modelInfo =
|
|
124
|
+
const modelInfo = getModel(model);
|
|
116
125
|
if (!modelInfo || !('videoPricing' in modelInfo) || !modelInfo.videoPricing) {
|
|
117
126
|
return 0;
|
|
118
127
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-analysis.d.ts","sourceRoot":"","sources":["../../src/services/task-analysis.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
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;AA4D9E,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,CA6HvB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Anthropic from '@anthropic-ai/sdk';
|
|
2
|
-
import {
|
|
2
|
+
import { getModelEntries } from '../lib/registry.js';
|
|
3
3
|
async function detectTaskType(description, anthropic) {
|
|
4
4
|
const prompt = `Analyze this task description and determine what TYPE of AI task it is.
|
|
5
5
|
|
|
@@ -66,7 +66,7 @@ export async function analyzeTask(description, userPreferences) {
|
|
|
66
66
|
console.error('Failed to detect task type, defaulting to chat:', error);
|
|
67
67
|
}
|
|
68
68
|
const filteredRegistry = {};
|
|
69
|
-
for (const [key, model] of
|
|
69
|
+
for (const [key, model] of getModelEntries()) {
|
|
70
70
|
// Filter by task type
|
|
71
71
|
if (model.type !== taskType) {
|
|
72
72
|
continue;
|