@layer-ai/core 2.0.37 → 2.0.38
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;
|
|
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
|
|
121
|
-
|
|
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({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layer-ai/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.38",
|
|
4
4
|
"description": "Core API routes and services for Layer AI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"nanoid": "^5.0.4",
|
|
37
37
|
"openai": "^4.24.0",
|
|
38
38
|
"pg": "^8.11.3",
|
|
39
|
-
"@layer-ai/sdk": "^2.5.
|
|
39
|
+
"@layer-ai/sdk": "^2.5.11"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/bcryptjs": "^2.4.6",
|