@layer-ai/core 2.0.37 → 2.0.39

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.
@@ -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;AAcpD,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;AA0TpC,eAAe,MAAM,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;AAcpD,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;AAyUpC,eAAe,MAAM,CAAC"}
@@ -117,8 +117,18 @@ router.post('/', authenticateAnthropicCompatible, async (req, res) => {
117
117
  let totalCost = 0;
118
118
  let modelUsed = finalRequest.model;
119
119
  try {
120
- const streamGenerator = executeWithRoutingStream(gateConfig, finalRequest, userId);
121
- for await (const event of convertLayerStreamToAnthropicEvents(streamGenerator)) {
120
+ const rawStream = executeWithRoutingStream(gateConfig, finalRequest, userId);
121
+ // Wrap the raw stream to capture usedPlatformKey before Anthropic conversion
122
+ let usedPlatformKey = false;
123
+ async function* captureMetadata(stream) {
124
+ for await (const chunk of stream) {
125
+ if (chunk.usedPlatformKey !== undefined) {
126
+ usedPlatformKey = chunk.usedPlatformKey;
127
+ }
128
+ yield chunk;
129
+ }
130
+ }
131
+ for await (const event of convertLayerStreamToAnthropicEvents(captureMetadata(rawStream))) {
122
132
  // Track usage from message_start and message_delta events
123
133
  if (event.type === 'message_start' && event.message.usage) {
124
134
  promptTokens = event.message.usage.input_tokens;
@@ -133,6 +143,9 @@ router.post('/', authenticateAnthropicCompatible, async (req, res) => {
133
143
  res.write(`event: ${event.type}\n`);
134
144
  res.write(`data: ${JSON.stringify(event)}\n\n`);
135
145
  }
146
+ // Send Layer-specific metadata as a custom event so internal middleware can track it
147
+ res.write(`event: layer_metadata\n`);
148
+ res.write(`data: ${JSON.stringify({ usedPlatformKey })}\n\n`);
136
149
  res.end();
137
150
  const latencyMs = Date.now() - startTime;
138
151
  db.logRequest({
@@ -243,7 +256,7 @@ router.post('/', authenticateAnthropicCompatible, async (req, res) => {
243
256
  console.error('Failed to track spending:', err);
244
257
  });
245
258
  const anthropicResponse = convertLayerResponseToAnthropic(result);
246
- res.json(anthropicResponse);
259
+ res.json({ ...anthropicResponse, usedPlatformKey: result.usedPlatformKey ?? false });
247
260
  }
248
261
  catch (error) {
249
262
  const latencyMs = Date.now() - startTime;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layer-ai/core",
3
- "version": "2.0.37",
3
+ "version": "2.0.39",
4
4
  "description": "Core API routes and services for Layer AI",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -14,6 +14,12 @@
14
14
  "files": [
15
15
  "dist"
16
16
  ],
17
+ "scripts": {
18
+ "build": "tsc && cp -r src/lib/db/migrations dist/lib/db/",
19
+ "dev": "tsc --watch",
20
+ "clean": "rm -rf dist",
21
+ "migrate": "node dist/lib/db/migrate.js"
22
+ },
17
23
  "author": "Micah Nettey",
18
24
  "license": "MIT",
19
25
  "repository": {
@@ -28,6 +34,7 @@
28
34
  "dependencies": {
29
35
  "@anthropic-ai/sdk": "^0.39.0",
30
36
  "@google/genai": "^1.30.0",
37
+ "@layer-ai/sdk": "workspace:^",
31
38
  "@mistralai/mistralai": "^1.11.0",
32
39
  "bcryptjs": "^2.4.3",
33
40
  "express": "^4.18.2",
@@ -35,8 +42,7 @@
35
42
  "jsonwebtoken": "^9.0.2",
36
43
  "nanoid": "^5.0.4",
37
44
  "openai": "^4.24.0",
38
- "pg": "^8.11.3",
39
- "@layer-ai/sdk": "^2.5.10"
45
+ "pg": "^8.11.3"
40
46
  },
41
47
  "devDependencies": {
42
48
  "@types/bcryptjs": "^2.4.6",
@@ -45,11 +51,5 @@
45
51
  "@types/node": "^20.10.4",
46
52
  "@types/pg": "^8.10.9",
47
53
  "typescript": "^5.3.3"
48
- },
49
- "scripts": {
50
- "build": "tsc && cp -r src/lib/db/migrations dist/lib/db/",
51
- "dev": "tsc --watch",
52
- "clean": "rm -rf dist",
53
- "migrate": "node dist/lib/db/migrate.js"
54
54
  }
55
- }
55
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Layer AI
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.