ConusAI vendor v0.1.0-dev.20261013+85463d22
This commit is contained in:
parent
c3c6526952
commit
0da8a2a81b
+28
-3
@@ -6,9 +6,9 @@ import { createServer } from 'node:http'
|
||||
import { gunzipSync } from 'node:zlib'
|
||||
|
||||
const PORT = 4010
|
||||
const state = { audit: [], usage: [], blobs: [] }
|
||||
const state = { audit: [], usage: [], blobs: [], otel: { logs: [], traces: [] } }
|
||||
const catalog = {
|
||||
redis: { display_name: 'Redis', description: 'Counts uploads per visitor each minute.' },
|
||||
kv: { display_name: 'KV Store', description: 'Counts uploads per visitor each minute.' },
|
||||
nats: { display_name: 'NATS', description: 'Announces new notes live to subscribers.' },
|
||||
qdrant: { display_name: 'Qdrant', description: 'Finds similar notes by vector search.' },
|
||||
git: { display_name: 'Git & Packages', description: 'Installs packages from the platform registry.' },
|
||||
@@ -68,6 +68,16 @@ const server = createServer(async (req, res) => {
|
||||
return send(res, 200, { items, next_cursor: null, has_more: false })
|
||||
}
|
||||
|
||||
// @conusai-sdk/observe-node's BatchExporter (showcase D23): POSTs OTLP/HTTP JSON directly to
|
||||
// these `{CONUSAI_API_URL}/otel/v1/{signal}` routes, bearer-authenticated with CONUSAI_API_TOKEN
|
||||
// -- not the OTEL_EXPORTER_OTLP_* env vars, which the SDK never reads itself.
|
||||
if (method === 'POST' && (path === '/otel/v1/logs' || path === '/otel/v1/traces')) {
|
||||
const body = JSON.parse((await readBody(req)).toString('utf8'))
|
||||
const bucket = path.endsWith('/logs') ? state.otel.logs : state.otel.traces
|
||||
bucket.push({ authorization: req.headers['authorization'] ?? null, body })
|
||||
return send(res, 200, {})
|
||||
}
|
||||
|
||||
if (method === 'POST' && path === '/_conusai/usage/events') {
|
||||
const body = JSON.parse((await readBody(req)).toString('utf8'))
|
||||
state.usage.push(...body.events)
|
||||
@@ -83,9 +93,24 @@ const server = createServer(async (req, res) => {
|
||||
contentType: req.headers['content-type'] ?? 'application/octet-stream',
|
||||
size: bytes.length,
|
||||
uploadedAt: new Date().toISOString(),
|
||||
bytes,
|
||||
}
|
||||
state.blobs.push(info)
|
||||
return send(res, 200, info)
|
||||
return send(res, 200, {
|
||||
url: info.url,
|
||||
pathname: info.pathname,
|
||||
contentType: info.contentType,
|
||||
size: info.size,
|
||||
uploadedAt: info.uploadedAt,
|
||||
})
|
||||
}
|
||||
|
||||
// GET /blob/{pathname}, and the real API's /blob/{project_id}/{pathname} shape.
|
||||
if (method === 'GET' && path.startsWith('/blob/')) {
|
||||
const info = state.blobs.find((blob) => path === `/blob/${blob.pathname}` || path.endsWith(`/${blob.pathname}`))
|
||||
if (!info) return send(res, 404, { title: 'not found', path })
|
||||
res.writeHead(200, { 'content-type': info.contentType })
|
||||
return res.end(info.bytes)
|
||||
}
|
||||
|
||||
return send(res, 404, { title: 'not found', path })
|
||||
|
||||
Reference in New Issue
Block a user