@lorekit/cli 1.33.2 → 1.33.3
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/package.json +1 -1
- package/src/mcp.mjs +29 -0
package/package.json
CHANGED
package/src/mcp.mjs
CHANGED
|
@@ -138,6 +138,26 @@ export function normalizeCorrelationId(raw) {
|
|
|
138
138
|
return /^[A-Za-z0-9_\-./:#@]+$/.test(t) ? t : null;
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Normalise a deployment-environment marker restFetch attaches as
|
|
143
|
+
* X-LoreKit-Deployment-Environment when DEPLOYMENT_ENVIRONMENT (or
|
|
144
|
+
* OTEL_DEPLOYMENT_ENVIRONMENT) is set. It lets a smoke/test run tell the edge to
|
|
145
|
+
* report `deployment.environment.name` for that request — the edge honours only
|
|
146
|
+
* the synthetic `test` value, so real traffic (no env set) is never tagged and a
|
|
147
|
+
* caller can never relabel itself as another real environment. This is the SAME
|
|
148
|
+
* value `resolveDeploymentEnvironment` (packages/cli/src/telemetry.mjs) puts on
|
|
149
|
+
* the CLI's own resource, so one `DEPLOYMENT_ENVIRONMENT=test` marks both the CLI
|
|
150
|
+
* span and its downstream edge spans. Bounded + charset-restricted (fail-safe: a
|
|
151
|
+
* bad value is not sent). Zero-dep, so the small regex is duplicated
|
|
152
|
+
* intentionally, like `normalizeCorrelationId`.
|
|
153
|
+
*/
|
|
154
|
+
export function normalizeRunEnvironment(raw) {
|
|
155
|
+
if (typeof raw !== 'string') return null;
|
|
156
|
+
const t = raw.trim();
|
|
157
|
+
if (!t || t.length > 64) return null;
|
|
158
|
+
return /^[A-Za-z0-9_.\-:]+$/.test(t) ? t : null;
|
|
159
|
+
}
|
|
160
|
+
|
|
141
161
|
export async function restFetch(baseUrl, token, path, { method = 'GET', body, timeoutMs = 10000, traceparent } = {}) {
|
|
142
162
|
const controller = new AbortController();
|
|
143
163
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
@@ -148,12 +168,21 @@ export async function restFetch(baseUrl, token, path, { method = 'GET', body, ti
|
|
|
148
168
|
// /memories/usage?correlation_id=… can report "usage for this PR". Absent env
|
|
149
169
|
// ⇒ no header ⇒ existing behaviour unchanged.
|
|
150
170
|
const correlationId = normalizeCorrelationId(process.env.LOREKIT_CORRELATION_ID);
|
|
171
|
+
// Opt-in test-run marker: when DEPLOYMENT_ENVIRONMENT is set (a deploy/CI
|
|
172
|
+
// smoke sets it to `test`), tell the edge to report that
|
|
173
|
+
// `deployment.environment.name` for this request so Dash0 can filter synthetic
|
|
174
|
+
// smoke traffic apart from real usage. Absent env ⇒ no header ⇒ existing
|
|
175
|
+
// behaviour unchanged. The edge honours only `test` (see otel.ts).
|
|
176
|
+
const runEnv = normalizeRunEnvironment(
|
|
177
|
+
process.env.DEPLOYMENT_ENVIRONMENT ?? process.env.OTEL_DEPLOYMENT_ENVIRONMENT,
|
|
178
|
+
);
|
|
151
179
|
const headers = {
|
|
152
180
|
accept: 'application/json',
|
|
153
181
|
...(body !== undefined ? { 'content-type': 'application/json' } : {}),
|
|
154
182
|
...(token ? { authorization: `Bearer ${token}` } : {}),
|
|
155
183
|
...(traceparent ? { traceparent } : {}),
|
|
156
184
|
...(correlationId ? { 'x-lorekit-correlation-id': correlationId } : {}),
|
|
185
|
+
...(runEnv ? { 'x-lorekit-deployment-environment': runEnv } : {}),
|
|
157
186
|
// Name the calling surface so usage analytics can tell a CLI read from a
|
|
158
187
|
// dashboard one. Not cosmetic: `GET /memories/read-activity` EXCLUDES the
|
|
159
188
|
// `dashboard` client (a human browsing lore is not consuming it), so a
|