@layer-ai/core 2.0.41 → 2.0.44
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/routes/v1/chat-completions.d.ts.map +1 -1
- package/dist/routes/v1/chat-completions.js +1 -2
- package/dist/routes/v1/gates.d.ts.map +1 -1
- package/dist/routes/v1/gates.js +0 -3
- package/dist/routes/v1/keys.d.ts.map +1 -1
- package/dist/routes/v1/keys.js +0 -3
- package/dist/routes/v1/logs.d.ts.map +1 -1
- package/dist/routes/v1/logs.js +0 -3
- package/dist/routes/v1/messages.d.ts.map +1 -1
- package/dist/routes/v1/messages.js +1 -2
- package/dist/routes/v1/spending.d.ts.map +1 -1
- package/dist/routes/v1/spending.js +0 -2
- package/dist/routes/v2/complete.d.ts.map +1 -1
- package/dist/routes/v2/complete.js +1 -2
- package/dist/routes/v3/chat.d.ts.map +1 -1
- package/dist/routes/v3/chat.js +1 -2
- package/dist/routes/v3/embeddings.d.ts.map +1 -1
- package/dist/routes/v3/embeddings.js +1 -2
- package/dist/routes/v3/image.d.ts.map +1 -1
- package/dist/routes/v3/image.js +1 -2
- package/dist/routes/v3/ocr.d.ts.map +1 -1
- package/dist/routes/v3/ocr.js +1 -2
- package/dist/routes/v3/tts.d.ts.map +1 -1
- package/dist/routes/v3/tts.js +1 -2
- package/dist/routes/v3/video.d.ts.map +1 -1
- package/dist/routes/v3/video.js +1 -2
- package/dist/services/providers/google-adapter.d.ts +4 -1
- package/dist/services/providers/google-adapter.d.ts.map +1 -1
- package/dist/services/providers/google-adapter.js +13 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-completions.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/chat-completions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"chat-completions.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/chat-completions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAapD,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;AAkTpC,eAAe,MAAM,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import { nanoid } from 'nanoid';
|
|
3
3
|
import { db } from '../../lib/db/postgres.js';
|
|
4
|
-
import { authenticate } from '../../middleware/auth.js';
|
|
5
4
|
import { spendingTracker } from '../../lib/spending-tracker.js';
|
|
6
5
|
import { convertOpenAIRequestToLayer, convertLayerResponseToOpenAI, convertLayerChunkToOpenAI, } from '../../lib/openai-conversion.js';
|
|
7
6
|
import { resolveFinalRequest } from '../v3/chat.js';
|
|
@@ -14,7 +13,7 @@ async function executeWithRouting(gateConfig, request, userId) {
|
|
|
14
13
|
const result = await callAdapter(request, userId);
|
|
15
14
|
return { result, modelUsed: request.model };
|
|
16
15
|
}
|
|
17
|
-
router.post('/',
|
|
16
|
+
router.post('/', async (req, res) => {
|
|
18
17
|
const startTime = Date.now();
|
|
19
18
|
if (!req.userId) {
|
|
20
19
|
const error = {
|
|
@@ -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;
|
|
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;AAylBpC,eAAe,MAAM,CAAC"}
|
package/dist/routes/v1/gates.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import { db } from '../../lib/db/postgres.js';
|
|
3
3
|
import { cache } from '../../lib/db/redis.js';
|
|
4
|
-
import { authenticate } from '../../middleware/auth.js';
|
|
5
4
|
import { callAdapter } from '../../lib/provider-factory.js';
|
|
6
5
|
import { MODEL_REGISTRY } from '@layer-ai/sdk';
|
|
7
6
|
import { detectSignificantChanges } from '../../lib/gate-utils.js';
|
|
8
7
|
const router = Router();
|
|
9
|
-
// All routes require authentication (SDK auth with Bearer token)
|
|
10
|
-
router.use(authenticate);
|
|
11
8
|
// POST / - Create a new gate
|
|
12
9
|
router.post('/', async (req, res) => {
|
|
13
10
|
if (!req.userId) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/keys.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/keys.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAIpD,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;AAyEpC,eAAe,MAAM,CAAC"}
|
package/dist/routes/v1/keys.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import crypto from 'crypto';
|
|
3
3
|
import { db } from '../../lib/db/postgres.js';
|
|
4
|
-
import { authenticate } from '../../middleware/auth.js';
|
|
5
4
|
const router = Router();
|
|
6
|
-
// All routes require sdk authentication
|
|
7
|
-
router.use(authenticate);
|
|
8
5
|
// Generate a random API key
|
|
9
6
|
function generateApiKey() {
|
|
10
7
|
const randomBytes = crypto.randomBytes(32).toString('hex');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logs.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/logs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"logs.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/logs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAGpD,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;AA6LpC,eAAe,MAAM,CAAC"}
|
package/dist/routes/v1/logs.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import { db } from '../../lib/db/postgres.js';
|
|
3
|
-
import { authenticate } from '../../middleware/auth.js';
|
|
4
3
|
const router = Router();
|
|
5
|
-
// All routes require SDK authentication
|
|
6
|
-
router.use(authenticate);
|
|
7
4
|
// GET /v1/logs - List request logs
|
|
8
5
|
router.get('/', async (req, res) => {
|
|
9
6
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/messages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/messages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAapD,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;AAyUpC,eAAe,MAAM,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import { db } from '../../lib/db/postgres.js';
|
|
3
|
-
import { authenticateAnthropicCompatible } from '../../middleware/auth.js';
|
|
4
3
|
import { spendingTracker } from '../../lib/spending-tracker.js';
|
|
5
4
|
import { convertAnthropicRequestToLayer, convertLayerResponseToAnthropic, convertLayerStreamToAnthropicEvents, } from '../../lib/anthropic-conversion.js';
|
|
6
5
|
import { resolveFinalRequest } from '../v3/chat.js';
|
|
@@ -13,7 +12,7 @@ async function executeWithRouting(gateConfig, request, userId) {
|
|
|
13
12
|
const result = await callAdapter(request, userId);
|
|
14
13
|
return { result, modelUsed: request.model };
|
|
15
14
|
}
|
|
16
|
-
router.post('/',
|
|
15
|
+
router.post('/', async (req, res) => {
|
|
17
16
|
const startTime = Date.now();
|
|
18
17
|
if (!req.userId) {
|
|
19
18
|
const error = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spending.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/spending.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,
|
|
1
|
+
{"version":3,"file":"spending.d.ts","sourceRoot":"","sources":["../../../src/routes/v1/spending.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAC,MAAM,SAAS,CAAC;AAInD,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;AAuGpC,eAAe,MAAM,CAAC"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import { db } from '../../lib/db/postgres.js';
|
|
3
3
|
import { cache } from '../../lib/db/redis.js';
|
|
4
|
-
import { authenticate } from '../../middleware/auth.js';
|
|
5
4
|
const router = Router();
|
|
6
|
-
router.use(authenticate);
|
|
7
5
|
// GET /spending - Get current spending information
|
|
8
6
|
router.get('/', async (req, res) => {
|
|
9
7
|
if (!req.userId) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"complete.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/complete.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"complete.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/complete.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AASpD,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;AAsVpC,eAAe,MAAM,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import { db } from '../../lib/db/postgres.js';
|
|
3
|
-
import { authenticate } from '../../middleware/auth.js';
|
|
4
3
|
import { callAdapter, normalizeModelId } from '../../lib/provider-factory.js';
|
|
5
4
|
import { OverrideField } from '@layer-ai/sdk';
|
|
6
5
|
import { spendingTracker } from '../../lib/spending-tracker.js';
|
|
@@ -158,7 +157,7 @@ async function executeWithRouting(gateConfig, request, userId) {
|
|
|
158
157
|
}
|
|
159
158
|
}
|
|
160
159
|
// MARK:- Route Handler
|
|
161
|
-
router.post('/',
|
|
160
|
+
router.post('/', async (req, res) => {
|
|
162
161
|
const startTime = Date.now();
|
|
163
162
|
if (!req.userId) {
|
|
164
163
|
res.status(401).json({ error: 'unauthorized', message: 'Missing user ID' });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../../src/routes/v3/chat.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../../src/routes/v3/chat.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAGpD,OAAO,KAAK,EAAE,YAAY,EAAiB,IAAI,EAA+C,MAAM,eAAe,CAAC;AAIpH,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;AAiBpC,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,IAAI,EAChB,OAAO,EAAE,YAAY,GACpB,YAAY,CAiFd;AAwWD,eAAe,MAAM,CAAC"}
|
package/dist/routes/v3/chat.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import { db } from '../../lib/db/postgres.js';
|
|
3
|
-
import { authenticate } from '../../middleware/auth.js';
|
|
4
3
|
import { callAdapter, callAdapterStream, normalizeModelId, getProviderForModel, PROVIDER } from '../../lib/provider-factory.js';
|
|
5
4
|
import { OverrideField } from '@layer-ai/sdk';
|
|
6
5
|
import { spendingTracker } from '../../lib/spending-tracker.js';
|
|
@@ -184,7 +183,7 @@ async function* executeWithRoutingStream(gateConfig, request, userId) {
|
|
|
184
183
|
}
|
|
185
184
|
}
|
|
186
185
|
// MARK:- Route Handler
|
|
187
|
-
router.post('/',
|
|
186
|
+
router.post('/', async (req, res) => {
|
|
188
187
|
const startTime = Date.now();
|
|
189
188
|
if (!req.userId) {
|
|
190
189
|
res.status(401).json({ error: 'unauthorized', message: 'Missing user ID' });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embeddings.d.ts","sourceRoot":"","sources":["../../../src/routes/v3/embeddings.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"embeddings.d.ts","sourceRoot":"","sources":["../../../src/routes/v3/embeddings.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAMpD,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;AAmQpC,eAAe,MAAM,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import { db } from '../../lib/db/postgres.js';
|
|
3
|
-
import { authenticate } from '../../middleware/auth.js';
|
|
4
3
|
import { callAdapter, normalizeModelId } from '../../lib/provider-factory.js';
|
|
5
4
|
import { OverrideField } from '@layer-ai/sdk';
|
|
6
5
|
const router = Router();
|
|
@@ -84,7 +83,7 @@ async function executeWithRouting(gateConfig, request, userId) {
|
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
85
|
// MARK:- Route Handler
|
|
87
|
-
router.post('/',
|
|
86
|
+
router.post('/', async (req, res) => {
|
|
88
87
|
const startTime = Date.now();
|
|
89
88
|
if (!req.userId) {
|
|
90
89
|
res.status(401).json({ error: 'unauthorized', message: 'Missing user ID' });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../../src/routes/v3/image.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../../src/routes/v3/image.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAMpD,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;AA4PpC,eAAe,MAAM,CAAC"}
|
package/dist/routes/v3/image.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import { db } from '../../lib/db/postgres.js';
|
|
3
|
-
import { authenticate } from '../../middleware/auth.js';
|
|
4
3
|
import { callAdapter, normalizeModelId } from '../../lib/provider-factory.js';
|
|
5
4
|
import { OverrideField } from '@layer-ai/sdk';
|
|
6
5
|
const router = Router();
|
|
@@ -94,7 +93,7 @@ async function executeWithRouting(gateConfig, request, userId) {
|
|
|
94
93
|
}
|
|
95
94
|
}
|
|
96
95
|
// MARK:- Route Handler
|
|
97
|
-
router.post('/',
|
|
96
|
+
router.post('/', async (req, res) => {
|
|
98
97
|
const startTime = Date.now();
|
|
99
98
|
if (!req.userId) {
|
|
100
99
|
res.status(401).json({ error: 'unauthorized', message: 'Missing user ID' });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ocr.d.ts","sourceRoot":"","sources":["../../../src/routes/v3/ocr.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"ocr.d.ts","sourceRoot":"","sources":["../../../src/routes/v3/ocr.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAMpD,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;AAqPpC,eAAe,MAAM,CAAC"}
|
package/dist/routes/v3/ocr.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import { db } from '../../lib/db/postgres.js';
|
|
3
|
-
import { authenticate } from '../../middleware/auth.js';
|
|
4
3
|
import { callAdapter, normalizeModelId } from '../../lib/provider-factory.js';
|
|
5
4
|
import { OverrideField } from '@layer-ai/sdk';
|
|
6
5
|
const router = Router();
|
|
@@ -84,7 +83,7 @@ async function executeWithRouting(gateConfig, request, userId) {
|
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
85
|
// MARK:- Route Handler
|
|
87
|
-
router.post('/',
|
|
86
|
+
router.post('/', async (req, res) => {
|
|
88
87
|
const startTime = Date.now();
|
|
89
88
|
if (!req.userId) {
|
|
90
89
|
res.status(401).json({ error: 'unauthorized', message: 'Missing user ID' });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tts.d.ts","sourceRoot":"","sources":["../../../src/routes/v3/tts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"tts.d.ts","sourceRoot":"","sources":["../../../src/routes/v3/tts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAMpD,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;AAiPpC,eAAe,MAAM,CAAC"}
|
package/dist/routes/v3/tts.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import { db } from '../../lib/db/postgres.js';
|
|
3
|
-
import { authenticate } from '../../middleware/auth.js';
|
|
4
3
|
import { callAdapter, normalizeModelId } from '../../lib/provider-factory.js';
|
|
5
4
|
import { OverrideField } from '@layer-ai/sdk';
|
|
6
5
|
const router = Router();
|
|
@@ -84,7 +83,7 @@ async function executeWithRouting(gateConfig, request, userId) {
|
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
85
|
// MARK:- Route Handler
|
|
87
|
-
router.post('/',
|
|
86
|
+
router.post('/', async (req, res) => {
|
|
88
87
|
const startTime = Date.now();
|
|
89
88
|
if (!req.userId) {
|
|
90
89
|
res.status(401).json({ error: 'unauthorized', message: 'Missing user ID' });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"video.d.ts","sourceRoot":"","sources":["../../../src/routes/v3/video.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"video.d.ts","sourceRoot":"","sources":["../../../src/routes/v3/video.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAMpD,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;AA4PpC,eAAe,MAAM,CAAC"}
|
package/dist/routes/v3/video.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import { db } from '../../lib/db/postgres.js';
|
|
3
|
-
import { authenticate } from '../../middleware/auth.js';
|
|
4
3
|
import { callAdapter, normalizeModelId } from '../../lib/provider-factory.js';
|
|
5
4
|
import { OverrideField } from '@layer-ai/sdk';
|
|
6
5
|
const router = Router();
|
|
@@ -94,7 +93,7 @@ async function executeWithRouting(gateConfig, request, userId) {
|
|
|
94
93
|
}
|
|
95
94
|
}
|
|
96
95
|
// MARK:- Route Handler
|
|
97
|
-
router.post('/',
|
|
96
|
+
router.post('/', async (req, res) => {
|
|
98
97
|
const startTime = Date.now();
|
|
99
98
|
if (!req.userId) {
|
|
100
99
|
res.status(401).json({ error: 'unauthorized', message: 'Missing user ID' });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FunctionCallingConfigMode } from '@google/genai';
|
|
2
|
-
import { LayerRequest, LayerResponse, Role, FinishReason, VideoSize } from '@layer-ai/sdk';
|
|
2
|
+
import { LayerRequest, LayerResponse, Role, FinishReason, ImageSize, VideoSize } from '@layer-ai/sdk';
|
|
3
3
|
import { BaseProviderAdapter } from './base-adapter.js';
|
|
4
4
|
import { type Provider } from "../../lib/provider-constants.js";
|
|
5
5
|
export declare class GoogleAdapter extends BaseProviderAdapter {
|
|
@@ -7,6 +7,9 @@ export declare class GoogleAdapter extends BaseProviderAdapter {
|
|
|
7
7
|
protected roleMappings: Record<Role, string>;
|
|
8
8
|
protected finishReasonMappings: Record<string, FinishReason>;
|
|
9
9
|
protected toolChoiceMappings: Record<string, FunctionCallingConfigMode>;
|
|
10
|
+
protected imageSizeConfig: Record<ImageSize, {
|
|
11
|
+
aspectRatio: string;
|
|
12
|
+
}>;
|
|
10
13
|
protected videoSizeConfig: Record<VideoSize, {
|
|
11
14
|
aspectRatio: string;
|
|
12
15
|
resolution: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-adapter.d.ts","sourceRoot":"","sources":["../../../src/services/providers/google-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,yBAAyB,EAI1B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,IAAI,EACJ,YAAY,EACZ,SAAS,EACV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAgB1E,qBAAa,aAAc,SAAQ,mBAAmB;IACpD,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAmB;IAE/C,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAQ1C;IAEF,SAAS,CAAC,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAO1D;IAEF,SAAS,CAAC,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAIrE;IAEF,SAAS,CAAC,eAAe,EAAE,MAAM,CAC/B,SAAS,EACT;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAC5C,CAKC;IAEI,IAAI,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAmBnE,UAAU,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC,aAAa,CAAC;YAYzE,UAAU;YAwLT,gBAAgB;YAmNjB,qBAAqB;
|
|
1
|
+
{"version":3,"file":"google-adapter.d.ts","sourceRoot":"","sources":["../../../src/services/providers/google-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,yBAAyB,EAI1B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,IAAI,EACJ,YAAY,EACZ,SAAS,EACT,SAAS,EACV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAgB1E,qBAAa,aAAc,SAAQ,mBAAmB;IACpD,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAmB;IAE/C,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAQ1C;IAEF,SAAS,CAAC,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAO1D;IAEF,SAAS,CAAC,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAIrE;IAEF,SAAS,CAAC,eAAe,EAAE,MAAM,CAAC,SAAS,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAQnE;IAEF,SAAS,CAAC,eAAe,EAAE,MAAM,CAC/B,SAAS,EACT;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAC5C,CAKC;IAEI,IAAI,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAmBnE,UAAU,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC,aAAa,CAAC;YAYzE,UAAU;YAwLT,gBAAgB;YAmNjB,qBAAqB;YA6CrB,gBAAgB;YAsChB,qBAAqB;YAsHrB,kBAAkB;IA2ChC,OAAO,CAAC,KAAK;CAGd"}
|
|
@@ -39,6 +39,15 @@ export class GoogleAdapter extends BaseProviderAdapter {
|
|
|
39
39
|
none: FunctionCallingConfigMode.NONE,
|
|
40
40
|
required: FunctionCallingConfigMode.ANY,
|
|
41
41
|
};
|
|
42
|
+
this.imageSizeConfig = {
|
|
43
|
+
'256x256': { aspectRatio: '1:1' },
|
|
44
|
+
'512x512': { aspectRatio: '1:1' },
|
|
45
|
+
'1024x1024': { aspectRatio: '1:1' },
|
|
46
|
+
'1792x1024': { aspectRatio: '16:9' },
|
|
47
|
+
'1024x1792': { aspectRatio: '9:16' },
|
|
48
|
+
'1536x1024': { aspectRatio: '3:2' },
|
|
49
|
+
'1024x1536': { aspectRatio: '2:3' },
|
|
50
|
+
};
|
|
42
51
|
this.videoSizeConfig = {
|
|
43
52
|
'720x1280': { aspectRatio: '9:16', resolution: '720p' },
|
|
44
53
|
'1280x720': { aspectRatio: '16:9', resolution: '720p' },
|
|
@@ -412,6 +421,9 @@ export class GoogleAdapter extends BaseProviderAdapter {
|
|
|
412
421
|
if (!model) {
|
|
413
422
|
throw new Error('Model is required for chat completion');
|
|
414
423
|
}
|
|
424
|
+
// Derive aspect ratio from size if provided
|
|
425
|
+
const sizeConfig = image.size ? this.imageSizeConfig[image.size] : null;
|
|
426
|
+
const aspectRatio = sizeConfig?.aspectRatio;
|
|
415
427
|
// Google's Imagen API via generateImages
|
|
416
428
|
const response = await client.models.generateImages({
|
|
417
429
|
model: model,
|
|
@@ -419,6 +431,7 @@ export class GoogleAdapter extends BaseProviderAdapter {
|
|
|
419
431
|
config: {
|
|
420
432
|
numberOfImages: image.count || 1,
|
|
421
433
|
...(image.seed !== undefined && { seed: image.seed }),
|
|
434
|
+
...(aspectRatio && { aspectRatio }),
|
|
422
435
|
},
|
|
423
436
|
});
|
|
424
437
|
const images = response.generatedImages?.map((img) => ({
|