@layer-ai/core 2.0.28 → 2.0.30
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":"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;AAcpD,QAAA,MAAM,MAAM,EAAE,UAAqB,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;AAcpD,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;AAkTpC,eAAe,MAAM,CAAC"}
|
|
@@ -32,11 +32,22 @@ router.post('/', authenticate, async (req, res) => {
|
|
|
32
32
|
let layerRequest = null;
|
|
33
33
|
try {
|
|
34
34
|
const openaiReq = req.body;
|
|
35
|
-
|
|
35
|
+
// Extract gate ID from multiple possible sources
|
|
36
|
+
let gateId = openaiReq.gateId || req.headers['x-layer-gate-id'];
|
|
37
|
+
// If not found in body or header, try to extract from model field
|
|
38
|
+
if (!gateId && openaiReq.model) {
|
|
39
|
+
const modelStr = openaiReq.model;
|
|
40
|
+
// Try to extract UUID from model field (e.g., "layer/82ab7591-..." or "layer:82ab7591-..." or just "82ab7591-...")
|
|
41
|
+
const uuidPattern = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
|
|
42
|
+
const match = modelStr.match(uuidPattern);
|
|
43
|
+
if (match) {
|
|
44
|
+
gateId = match[0];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
36
47
|
if (!gateId) {
|
|
37
48
|
const error = {
|
|
38
49
|
error: {
|
|
39
|
-
message: 'Missing required field: gateId (provide in request body
|
|
50
|
+
message: 'Missing required field: gateId (provide in request body, X-Layer-Gate-Id header, or as part of model field)',
|
|
40
51
|
type: 'invalid_request_error',
|
|
41
52
|
param: 'gateId',
|
|
42
53
|
code: 'missing_field',
|
|
@@ -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;AASpD,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;AASpD,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;AA4lBpC,eAAe,MAAM,CAAC"}
|
package/dist/routes/v1/gates.js
CHANGED
|
@@ -76,6 +76,59 @@ router.get('/', async (req, res) => {
|
|
|
76
76
|
res.status(500).json({ error: 'internal_error', message: 'Failed to list gates' });
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
|
+
// GET /openclaw - Get gates tagged with "openclaw" with analytics
|
|
80
|
+
router.get('/openclaw', async (req, res) => {
|
|
81
|
+
if (!req.userId) {
|
|
82
|
+
res.status(401).json({ error: 'unauthorized', message: 'Missing user ID' });
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const result = await db.query(`SELECT
|
|
87
|
+
g.id,
|
|
88
|
+
g.user_id,
|
|
89
|
+
g.name,
|
|
90
|
+
g.model,
|
|
91
|
+
g.task_type,
|
|
92
|
+
g.description,
|
|
93
|
+
g.created_at,
|
|
94
|
+
g.updated_at,
|
|
95
|
+
g.spending_limit,
|
|
96
|
+
g.spending_current,
|
|
97
|
+
g.spending_status,
|
|
98
|
+
COALESCE(COUNT(r.id), 0)::integer as request_count,
|
|
99
|
+
COALESCE(SUM(r.cost_usd), 0)::numeric as total_cost,
|
|
100
|
+
COALESCE(AVG(r.latency_ms), 0)::integer as avg_latency,
|
|
101
|
+
MAX(r.created_at) as last_request
|
|
102
|
+
FROM gates g
|
|
103
|
+
LEFT JOIN requests r ON g.id = r.gate_id
|
|
104
|
+
WHERE g.user_id = $1
|
|
105
|
+
AND g.tags @> '["openclaw"]'::jsonb
|
|
106
|
+
GROUP BY g.id
|
|
107
|
+
ORDER BY g.created_at DESC`, [req.userId]);
|
|
108
|
+
const gates = result.rows.map((row) => ({
|
|
109
|
+
id: row.id,
|
|
110
|
+
userId: row.user_id,
|
|
111
|
+
name: row.name,
|
|
112
|
+
model: row.model,
|
|
113
|
+
taskType: row.task_type,
|
|
114
|
+
description: row.description,
|
|
115
|
+
createdAt: row.created_at,
|
|
116
|
+
updatedAt: row.updated_at,
|
|
117
|
+
spendingLimit: row.spending_limit,
|
|
118
|
+
spendingCurrent: row.spending_current ? parseFloat(row.spending_current) : undefined,
|
|
119
|
+
spendingStatus: row.spending_status,
|
|
120
|
+
requestCount: row.request_count,
|
|
121
|
+
totalCost: parseFloat(row.total_cost),
|
|
122
|
+
avgLatency: row.avg_latency,
|
|
123
|
+
lastRequest: row.last_request,
|
|
124
|
+
}));
|
|
125
|
+
res.json(gates);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
console.error('List OpenClaw gates error:', error);
|
|
129
|
+
res.status(500).json({ error: 'internal_error', message: 'Failed to list OpenClaw gates' });
|
|
130
|
+
}
|
|
131
|
+
});
|
|
79
132
|
// GET /name/:name - Get a single gate by name
|
|
80
133
|
router.get('/name/:name', async (req, res) => {
|
|
81
134
|
if (!req.userId) {
|