@lmnr-ai/lmnr 0.8.49 → 0.8.50
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/dist/cli.cjs +19 -14
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +2 -2
- package/dist/cli.d.mts +2 -2
- package/dist/cli.mjs +16 -11
- package/dist/cli.mjs.map +1 -1
- package/dist/{evaluations-4bQ4UuTj.d.mts → evaluations-BVaPPf0j.d.mts} +1679 -1305
- package/dist/{evaluations-CbHnDCAY.d.cts → evaluations-C8cI_XIE.d.cts} +1682 -1307
- package/dist/{file-utils-Ct8PiWkV.mjs → file-utils-DOEv6ccL.mjs} +47 -18
- package/dist/file-utils-DOEv6ccL.mjs.map +1 -0
- package/dist/{file-utils-N65ihgSU.cjs → file-utils-RXJzJyiI.cjs} +47 -18
- package/dist/file-utils-RXJzJyiI.cjs.map +1 -0
- package/dist/index.cjs +164 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1762 -1284
- package/dist/index.d.mts +1762 -1284
- package/dist/index.mjs +164 -62
- package/dist/index.mjs.map +1 -1
- package/dist/opentelemetry-lib/instrumentation/temporal/workflow-interceptors.cjs +114 -102
- package/dist/opentelemetry-lib/instrumentation/temporal/workflow-interceptors.cjs.map +1 -1
- package/dist/opentelemetry-lib/instrumentation/temporal/workflow-interceptors.d.cts +776 -372
- package/dist/opentelemetry-lib/instrumentation/temporal/workflow-interceptors.d.mts +776 -372
- package/dist/opentelemetry-lib/instrumentation/temporal/workflow-interceptors.mjs +114 -102
- package/dist/opentelemetry-lib/instrumentation/temporal/workflow-interceptors.mjs.map +1 -1
- package/dist/{rolldown-runtime-2rV9d50f.mjs → rolldown-runtime-B4iAMlE-.mjs} +2 -2
- package/dist/{rolldown-runtime-CVvi-lCc.cjs → rolldown-runtime-Ctb5zv51.cjs} +1 -1
- package/dist/{utils-D8kgcFxb.cjs → utils-CNR1tzh5.cjs} +10 -9
- package/dist/utils-CNR1tzh5.cjs.map +1 -0
- package/dist/{utils-CbvnF9B9.mjs → utils-DRrXCfun.mjs} +9 -8
- package/dist/{utils-CbvnF9B9.mjs.map → utils-DRrXCfun.mjs.map} +1 -1
- package/package.json +6 -8
- package/dist/file-utils-Ct8PiWkV.mjs.map +0 -1
- package/dist/file-utils-N65ihgSU.cjs.map +0 -1
- package/dist/utils-D8kgcFxb.cjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as __require } from "./rolldown-runtime-
|
|
2
|
-
import { A as SPAN_INSTRUMENTATION_SOURCE, B as LaminarClient, C as PARENT_SPAN_IDS_PATH, D as SPAN_INPUT, E as SPAN_IDS_PATH, F as SPAN_TYPE, H as DEBUG_SESSION_FILE, I as TRACE_HAS_BROWSER_SESSION, L as TRACE_TYPE, M as SPAN_OUTPUT, N as SPAN_PATH, O as SPAN_INSTRUMENTATION_SCOPE_NAME, P as SPAN_SDK_VERSION, R as USER_ID, S as LaminarAttributes, T as SESSION_ID, U as TracingLevel, V as DEBUG_SESSION_DIR, W as errorMessage, _ as tryToOtelSpanContext, a as getFrontendUrl, b as ASSOCIATION_PROPERTIES_OVERRIDES, c as loadEnv, d as normalizeOtelSpanId, f as normalizeOtelTraceId, g as truncateSpanPayload, h as parseOtelHeaders, j as SPAN_LANGUAGE_VERSION, k as SPAN_INSTRUMENTATION_SCOPE_VERSION, l as metadataToAttributes, m as otelTraceIdToUUID, n as Semaphore, o as getOtelEnvVar, p as otelSpanIdToUUID, r as deserializeLaminarSpanContext, s as initializeLogger, t as NIL_UUID, u as newUUID, v as validateTracingConfig, w as PARENT_SPAN_PATH, x as HUMAN_EVALUATOR_OPTIONS, y as ASSOCIATION_PROPERTIES, z as version } from "./utils-
|
|
1
|
+
import { r as __require } from "./rolldown-runtime-B4iAMlE-.mjs";
|
|
2
|
+
import { A as SPAN_INSTRUMENTATION_SOURCE, B as LaminarClient, C as PARENT_SPAN_IDS_PATH, D as SPAN_INPUT, E as SPAN_IDS_PATH, F as SPAN_TYPE, H as DEBUG_SESSION_FILE, I as TRACE_HAS_BROWSER_SESSION, L as TRACE_TYPE, M as SPAN_OUTPUT, N as SPAN_PATH, O as SPAN_INSTRUMENTATION_SCOPE_NAME, P as SPAN_SDK_VERSION, R as USER_ID, S as LaminarAttributes, T as SESSION_ID, U as TracingLevel, V as DEBUG_SESSION_DIR, W as errorMessage, _ as tryToOtelSpanContext, a as getFrontendUrl, b as ASSOCIATION_PROPERTIES_OVERRIDES, c as loadEnv, d as normalizeOtelSpanId, f as normalizeOtelTraceId, g as truncateSpanPayload, h as parseOtelHeaders, j as SPAN_LANGUAGE_VERSION, k as SPAN_INSTRUMENTATION_SCOPE_VERSION, l as metadataToAttributes, m as otelTraceIdToUUID, n as Semaphore, o as getOtelEnvVar, p as otelSpanIdToUUID, r as deserializeLaminarSpanContext, s as initializeLogger, t as NIL_UUID, u as newUUID, v as validateTracingConfig, w as PARENT_SPAN_PATH, x as HUMAN_EVALUATOR_OPTIONS, y as ASSOCIATION_PROPERTIES, z as version } from "./utils-DRrXCfun.mjs";
|
|
3
3
|
import { n as TRACEPARENT_HEADER, t as LAMINAR_SPAN_CONTEXT_HEADER } from "./consts-CTTu3jhI.mjs";
|
|
4
4
|
import * as path from "path";
|
|
5
5
|
import { DiagConsoleLogger, DiagLogLevel, ROOT_CONTEXT, SpanKind, SpanStatusCode, TraceFlags, context, createContextKey, diag, isSpanContextValid, trace } from "@opentelemetry/api";
|
|
@@ -176,7 +176,7 @@ var LaminarDataset = class extends EvaluationDataset {
|
|
|
176
176
|
*/
|
|
177
177
|
async push(paths, recursive = false) {
|
|
178
178
|
if (!this.client) throw new Error("Client not set");
|
|
179
|
-
const { loadFromPaths } = await import("./file-utils-
|
|
179
|
+
const { loadFromPaths } = await import("./file-utils-DOEv6ccL.mjs").then((n) => n.t);
|
|
180
180
|
const data = await loadFromPaths(Array.isArray(paths) ? paths : [paths], recursive);
|
|
181
181
|
if (data.length === 0) {
|
|
182
182
|
console.warn("No data to push. Skipping");
|
|
@@ -562,7 +562,8 @@ const handleStreamResult = (originalResult, streamInfo, span, ignoreOutput, seri
|
|
|
562
562
|
});
|
|
563
563
|
trackStreamProcessing(async () => {
|
|
564
564
|
try {
|
|
565
|
-
const
|
|
565
|
+
const tempResponse = new Response(stream2);
|
|
566
|
+
const { chunks, error } = await consumeResponse(tempResponse);
|
|
566
567
|
if (shouldSendTraces() && !ignoreOutput) try {
|
|
567
568
|
const output = {
|
|
568
569
|
type: "response",
|
|
@@ -661,7 +662,7 @@ const writeDebugSessionFile = (file, dir = process.cwd()) => {
|
|
|
661
662
|
* logic line-comparable with the Python `config.py`.
|
|
662
663
|
*/
|
|
663
664
|
const logger$24 = initializeLogger();
|
|
664
|
-
const TRUTHY = new Set([
|
|
665
|
+
const TRUTHY = /* @__PURE__ */ new Set([
|
|
665
666
|
"true",
|
|
666
667
|
"1",
|
|
667
668
|
"yes",
|
|
@@ -733,10 +734,12 @@ const buildDebugConfig = () => {
|
|
|
733
734
|
const providedSessionId = process.env.LMNR_DEBUG_SESSION_ID || existing?.session_id || void 0;
|
|
734
735
|
const sessionId = providedSessionId || randomUUID();
|
|
735
736
|
const sessionMinted = providedSessionId === void 0;
|
|
737
|
+
const replayTraceId = process.env.LMNR_DEBUG_REPLAY_TRACE_ID || existing?.replay_trace_id || null;
|
|
738
|
+
const cacheUntilValue = process.env.LMNR_DEBUG_CACHE_UNTIL ?? existing?.cache_until ?? void 0;
|
|
736
739
|
return {
|
|
737
740
|
sessionId,
|
|
738
|
-
replayTraceId
|
|
739
|
-
cacheUntilSpanId: parseCacheUntil(
|
|
741
|
+
replayTraceId,
|
|
742
|
+
cacheUntilSpanId: parseCacheUntil(cacheUntilValue),
|
|
740
743
|
localOrigin: true,
|
|
741
744
|
sessionMinted
|
|
742
745
|
};
|
|
@@ -957,14 +960,15 @@ var DebugRuntime = class {
|
|
|
957
960
|
if (!this._config.localOrigin) return;
|
|
958
961
|
if (this._emitted) return;
|
|
959
962
|
this._emitted = true;
|
|
960
|
-
|
|
963
|
+
const file = buildDebugSessionFile({
|
|
961
964
|
sessionId: this._config.sessionId,
|
|
962
965
|
traceId: this._traceId,
|
|
963
966
|
replayTraceId: this._config.replayTraceId,
|
|
964
967
|
cacheUntil: this._config.cacheUntilSpanId,
|
|
965
968
|
debuggerUrl: this.debuggerSessionUrl(),
|
|
966
969
|
startedAt: this._startedAt
|
|
967
|
-
})
|
|
970
|
+
});
|
|
971
|
+
emitPointer(file);
|
|
968
972
|
}
|
|
969
973
|
};
|
|
970
974
|
let runtime = null;
|
|
@@ -1173,7 +1177,7 @@ var LaminarSpan = class LaminarSpan {
|
|
|
1173
1177
|
}
|
|
1174
1178
|
addTags(tags) {
|
|
1175
1179
|
const currentTags = this.tags;
|
|
1176
|
-
this.setTags(Array.from(new Set([...currentTags, ...tags])));
|
|
1180
|
+
this.setTags(Array.from(/* @__PURE__ */ new Set([...currentTags, ...tags])));
|
|
1177
1181
|
}
|
|
1178
1182
|
getLaminarSpanContext() {
|
|
1179
1183
|
let spanPath = [];
|
|
@@ -1561,7 +1565,8 @@ const flagSettingsEnv = (existing, cwd) => {
|
|
|
1561
1565
|
} catch {}
|
|
1562
1566
|
return {};
|
|
1563
1567
|
}
|
|
1564
|
-
|
|
1568
|
+
const resolved = path.isAbsolute(trimmed) ? trimmed : path.join(cwd ?? process.cwd(), trimmed);
|
|
1569
|
+
return settingsEnvBlock(loadSettingsFile(resolved) ?? {});
|
|
1565
1570
|
};
|
|
1566
1571
|
/**
|
|
1567
1572
|
* Build the `--settings` value that forces the CLI through our proxy.
|
|
@@ -1595,7 +1600,8 @@ const buildProxyFlagSettings = (existing, proxyUrl, cwd, settingSources) => {
|
|
|
1595
1600
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
1596
1601
|
settingsObj = parsed;
|
|
1597
1602
|
} else {
|
|
1598
|
-
const
|
|
1603
|
+
const resolved = path.isAbsolute(trimmed) ? trimmed : path.join(cwd ?? process.cwd(), trimmed);
|
|
1604
|
+
const loaded = loadSettingsFile(resolved);
|
|
1599
1605
|
if (loaded === null) return null;
|
|
1600
1606
|
settingsObj = loaded;
|
|
1601
1607
|
}
|
|
@@ -1686,7 +1692,10 @@ const resolveTargetUrlFromEnv = (envDict, fallback = DEFAULT_ANTHROPIC_BASE_URL,
|
|
|
1686
1692
|
const bedrockBaseUrl = getEnvValue(BEDROCK_BASE_URL_ENV);
|
|
1687
1693
|
if (bedrockBaseUrl) return bedrockBaseUrl.replace(/\/$/, "");
|
|
1688
1694
|
let region = getEnvValue(BEDROCK_AWS_REGION_ENV);
|
|
1689
|
-
if (!region)
|
|
1695
|
+
if (!region) {
|
|
1696
|
+
const awsProfile = getEnvValue("AWS_PROFILE") || "default";
|
|
1697
|
+
region = getRegionFromAwsConfig(awsProfile) ?? void 0;
|
|
1698
|
+
}
|
|
1690
1699
|
if (region) return `https://bedrock-runtime.${region}.amazonaws.com`;
|
|
1691
1700
|
logger$22.error(`${BEDROCK_USE_ENV} is set but could not determine AWS region. Set ${BEDROCK_AWS_REGION_ENV} or configure a region in ~/.aws/config for the active profile.`);
|
|
1692
1701
|
return null;
|
|
@@ -2225,10 +2234,13 @@ var Laminar = class Laminar {
|
|
|
2225
2234
|
runtime.recordProjectId(projectId);
|
|
2226
2235
|
const sessionUrl = runtime.debuggerSessionUrl();
|
|
2227
2236
|
logger$20.info(`Laminar debugger session: ${sessionUrl}`);
|
|
2228
|
-
if (runtime.shouldOpenBrowser)
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2237
|
+
if (runtime.shouldOpenBrowser) {
|
|
2238
|
+
const opener = process.platform === "win32" ? "start" : process.platform === "darwin" ? "open" : "xdg-open";
|
|
2239
|
+
spawn(opener, [sessionUrl], {
|
|
2240
|
+
detached: true,
|
|
2241
|
+
stdio: "ignore"
|
|
2242
|
+
}).unref();
|
|
2243
|
+
}
|
|
2232
2244
|
}
|
|
2233
2245
|
}).catch((e) => {
|
|
2234
2246
|
logger$20.warn("Failed to register debug session: " + errorMessage(e));
|
|
@@ -2275,11 +2287,13 @@ var Laminar = class Laminar {
|
|
|
2275
2287
|
if (!debug || debug.enabled !== true || !debug.sessionId) return;
|
|
2276
2288
|
const existing = getRuntime();
|
|
2277
2289
|
if (existing !== null && existing.localOrigin) return;
|
|
2278
|
-
const
|
|
2290
|
+
const rolloutSessions = existing?.rolloutSessions ?? new LaminarClient({
|
|
2279
2291
|
baseUrl: this.baseUrlForDebug,
|
|
2280
2292
|
projectApiKey: this.projectApiKey,
|
|
2281
2293
|
port: this.httpPortForDebug
|
|
2282
|
-
}).rolloutSessions
|
|
2294
|
+
}).rolloutSessions;
|
|
2295
|
+
const debuggerUrl = process?.env?.LMNR_FRONTEND_URL ?? getFrontendUrl(this.baseUrlForDebug);
|
|
2296
|
+
const { runtime, configChanged } = initDebugRuntimeFromContext(debug, rolloutSessions, debuggerUrl);
|
|
2283
2297
|
if (runtime === null) return;
|
|
2284
2298
|
if (configChanged) {
|
|
2285
2299
|
this.debugRunLive = false;
|
|
@@ -2583,12 +2597,13 @@ var Laminar = class Laminar {
|
|
|
2583
2597
|
const sessionIdProperties = sessionIdValue ? { [SESSION_ID]: sessionIdValue } : {};
|
|
2584
2598
|
const traceTypeProperties = traceTypeValue ? { [TRACE_TYPE]: traceTypeValue } : {};
|
|
2585
2599
|
const tracingLevelProperties = tracingLevelValue ? { [`${ASSOCIATION_PROPERTIES}.tracing_level`]: tracingLevelValue } : {};
|
|
2586
|
-
const
|
|
2600
|
+
const mergedMetadata = {
|
|
2587
2601
|
...this.globalMetadata,
|
|
2588
2602
|
...ctxMetadata,
|
|
2589
2603
|
...parentMetadata,
|
|
2590
2604
|
...metadata
|
|
2591
|
-
}
|
|
2605
|
+
};
|
|
2606
|
+
const metadataProperties = metadataToAttributes(mergedMetadata);
|
|
2592
2607
|
const attributes = {
|
|
2593
2608
|
[SPAN_TYPE]: spanType ?? "DEFAULT",
|
|
2594
2609
|
...tagProperties,
|
|
@@ -2952,7 +2967,8 @@ const prettyPrintZodSchema = (schema, indent = 2) => {
|
|
|
2952
2967
|
if (typeof description === "string") result += `.describe('${description.replace(/'/g, "\\'")}')`;
|
|
2953
2968
|
return result;
|
|
2954
2969
|
};
|
|
2955
|
-
|
|
2970
|
+
const finalType = applyModifiers(value, getBaseType(value));
|
|
2971
|
+
return `${indentString}${key}: ${finalType},`;
|
|
2956
2972
|
}).join("\n")}\n})`;
|
|
2957
2973
|
};
|
|
2958
2974
|
const modelToProviderMap = {
|
|
@@ -3008,7 +3024,7 @@ const modelToProvider = (model) => {
|
|
|
3008
3024
|
const injectScript = (sessionRecordingOptions, stringifyCallbackArgs) => {
|
|
3009
3025
|
const BATCH_TIMEOUT = 2e3;
|
|
3010
3026
|
const HEARTBEAT_INTERVAL = 1e3;
|
|
3011
|
-
const CHUNK_SIZE =
|
|
3027
|
+
const CHUNK_SIZE = 262144;
|
|
3012
3028
|
window.lmnrRrwebEventsBatch = [];
|
|
3013
3029
|
window.lmnrChunkSequence = 0;
|
|
3014
3030
|
window.lmnrSendInProgress = false;
|
|
@@ -3069,7 +3085,9 @@ const injectScript = (sessionRecordingOptions, stringifyCallbackArgs) => {
|
|
|
3069
3085
|
try {
|
|
3070
3086
|
const compressedEvents = [];
|
|
3071
3087
|
for (const event of events) try {
|
|
3072
|
-
const
|
|
3088
|
+
const dataString = JSON.stringify(event.data);
|
|
3089
|
+
const compressed = await gzipCompress(dataString);
|
|
3090
|
+
const base64Data = await bufferToBase64(compressed);
|
|
3073
3091
|
compressedEvents.push({
|
|
3074
3092
|
...event,
|
|
3075
3093
|
data: base64Data
|
|
@@ -5319,15 +5337,17 @@ const applyGenerationSpanData = (lmnrSpan, spanData) => {
|
|
|
5319
5337
|
setGenAiInputMessages(lmnrSpan, inputData, getCurrentSystemInstructions());
|
|
5320
5338
|
const outputData = spanData?.output;
|
|
5321
5339
|
setGenAiOutputMessages(lmnrSpan, outputData);
|
|
5322
|
-
|
|
5340
|
+
const llmData = {
|
|
5323
5341
|
model: spanData?.model,
|
|
5324
5342
|
usage: spanData?.usage,
|
|
5325
5343
|
response_id: spanData?.response_id ?? spanData?.id
|
|
5326
|
-
}
|
|
5344
|
+
};
|
|
5345
|
+
applyLlmAttributes(lmnrSpan, llmData);
|
|
5327
5346
|
};
|
|
5328
5347
|
const applyResponseSpanData = (lmnrSpan, spanData) => {
|
|
5329
5348
|
const response = spanData?._response ?? spanData?.response;
|
|
5330
|
-
|
|
5349
|
+
const responseInput = spanData?._input ?? spanData?.input;
|
|
5350
|
+
setGenAiInputMessages(lmnrSpan, responseInput, getCurrentSystemInstructions());
|
|
5331
5351
|
if (response != null) {
|
|
5332
5352
|
setGenAiOutputMessagesFromResponse(lmnrSpan, response);
|
|
5333
5353
|
setToolDefinitionsFromResponse(lmnrSpan, response);
|
|
@@ -5368,8 +5388,10 @@ const applySpeechSpanData = (lmnrSpan, spanData) => {
|
|
|
5368
5388
|
const inputText = spanData?.input;
|
|
5369
5389
|
if (inputText) setGenAiInputMessages(lmnrSpan, inputText);
|
|
5370
5390
|
const outputData = spanData?.output;
|
|
5371
|
-
if (outputData)
|
|
5372
|
-
|
|
5391
|
+
if (outputData) {
|
|
5392
|
+
if (typeof outputData === "object" && !Array.isArray(outputData)) setGenAiOutputMessages(lmnrSpan, outputData.data);
|
|
5393
|
+
else setGenAiOutputMessages(lmnrSpan, outputData);
|
|
5394
|
+
}
|
|
5373
5395
|
};
|
|
5374
5396
|
const applyTranscriptionSpanData = (lmnrSpan, spanData) => {
|
|
5375
5397
|
const model = spanData?.model;
|
|
@@ -5379,8 +5401,10 @@ const applyTranscriptionSpanData = (lmnrSpan, spanData) => {
|
|
|
5379
5401
|
lmnrSpan.setAttribute(LaminarAttributes.PROVIDER, "openai");
|
|
5380
5402
|
}
|
|
5381
5403
|
const inputData = spanData?.input;
|
|
5382
|
-
if (inputData)
|
|
5383
|
-
|
|
5404
|
+
if (inputData) {
|
|
5405
|
+
if (typeof inputData === "object" && !Array.isArray(inputData)) setGenAiInputMessages(lmnrSpan, inputData.data);
|
|
5406
|
+
else setGenAiInputMessages(lmnrSpan, inputData);
|
|
5407
|
+
}
|
|
5384
5408
|
const outputText = spanData?.output;
|
|
5385
5409
|
if (outputText) setGenAiOutputMessages(lmnrSpan, outputText);
|
|
5386
5410
|
};
|
|
@@ -5603,7 +5627,8 @@ const wrapGetResponse = (original) => function(request, ...rest) {
|
|
|
5603
5627
|
};
|
|
5604
5628
|
const wrapGetStreamedResponse = (original) => function(request, ...rest) {
|
|
5605
5629
|
const systemInstructions = request?.systemInstructions;
|
|
5606
|
-
|
|
5630
|
+
const source = original.call(this, request, ...rest);
|
|
5631
|
+
return wrapStreamWithSystemInstructions(systemInstructions, source);
|
|
5607
5632
|
};
|
|
5608
5633
|
const MODEL_METHODS = ["getResponse", "getStreamedResponse"];
|
|
5609
5634
|
var OpenAIAgentsInstrumentation = class extends InstrumentationBase {
|
|
@@ -5748,12 +5773,12 @@ var OpencodeInstrumentation = class extends InstrumentationBase {
|
|
|
5748
5773
|
};
|
|
5749
5774
|
//#endregion
|
|
5750
5775
|
//#region src/opentelemetry-lib/instrumentation/openrouter/utils.ts
|
|
5751
|
-
const TERMINAL_RESPONSE_EVENTS = new Set([
|
|
5776
|
+
const TERMINAL_RESPONSE_EVENTS = /* @__PURE__ */ new Set([
|
|
5752
5777
|
"response.completed",
|
|
5753
5778
|
"response.incomplete",
|
|
5754
5779
|
"response.failed"
|
|
5755
5780
|
]);
|
|
5756
|
-
const ERROR_RESPONSE_STATUSES = new Set(["failed", "incomplete"]);
|
|
5781
|
+
const ERROR_RESPONSE_STATUSES = /* @__PURE__ */ new Set(["failed", "incomplete"]);
|
|
5757
5782
|
const safeSetAttribute$1 = (span, key, value) => {
|
|
5758
5783
|
if (value === null || value === void 0) return;
|
|
5759
5784
|
if (typeof value === "string" && value.length === 0) return;
|
|
@@ -5919,7 +5944,8 @@ const wrapStream = (span, kind, stream, traceContent) => {
|
|
|
5919
5944
|
throw error;
|
|
5920
5945
|
} finally {
|
|
5921
5946
|
try {
|
|
5922
|
-
|
|
5947
|
+
const response = kind === "chat" ? aggregateChatChunks(chunks) : responseFromStreamEvents(chunks);
|
|
5948
|
+
setResponseAttributes$1(span, kind, response, traceContent);
|
|
5923
5949
|
} finally {
|
|
5924
5950
|
span.end();
|
|
5925
5951
|
}
|
|
@@ -6485,7 +6511,9 @@ const buildHeaders = (existing) => {
|
|
|
6485
6511
|
const headers = { ...existing };
|
|
6486
6512
|
if (laminarCtx) {
|
|
6487
6513
|
headers[LAMINAR_SPAN_CONTEXT_HEADER] = encodePayload(JSON.stringify(laminarCtx));
|
|
6488
|
-
|
|
6514
|
+
const traceHex = laminarCtx.traceId.replace(/-/g, "");
|
|
6515
|
+
const spanHex = laminarCtx.spanId.replace(/-/g, "").slice(16);
|
|
6516
|
+
headers[TRACEPARENT_HEADER] = encodePayload(`00-${traceHex}-${spanHex}-01`);
|
|
6489
6517
|
} else {
|
|
6490
6518
|
const ctx = rawSpan.spanContext();
|
|
6491
6519
|
headers[TRACEPARENT_HEADER] = encodePayload(`00-${ctx.traceId}-${ctx.spanId}-01`);
|
|
@@ -6949,10 +6977,11 @@ const patchTemporalWorker = (workerModule, options = {}) => {
|
|
|
6949
6977
|
activity: [ActivityInterceptorFactory(options), ...rawOpts?.interceptors?.activity ?? []]
|
|
6950
6978
|
};
|
|
6951
6979
|
if (!usesWorkflowBundle) interceptors.workflowModules = [__require.resolve("@lmnr-ai/lmnr/temporal-workflow-interceptors"), ...rawOpts?.interceptors?.workflowModules ?? []];
|
|
6952
|
-
|
|
6980
|
+
const patched = {
|
|
6953
6981
|
...rawOpts,
|
|
6954
6982
|
interceptors
|
|
6955
|
-
}
|
|
6983
|
+
};
|
|
6984
|
+
return originalCreate(patched, ...rest);
|
|
6956
6985
|
};
|
|
6957
6986
|
};
|
|
6958
6987
|
/**
|
|
@@ -7161,8 +7190,9 @@ const initializeLaminarInstrumentations = (options = {}) => {
|
|
|
7161
7190
|
if (apiKey) {
|
|
7162
7191
|
const url = options.baseUrl ?? process?.env?.LMNR_BASE_URL ?? "https://api.lmnr.ai";
|
|
7163
7192
|
const port = options.httpPort ?? (url.match(/:\d{1,5}$/g) ? parseInt(url.match(/:\d{1,5}$/g)[0].slice(1)) : 443);
|
|
7193
|
+
const urlWithoutSlash = url.replace(/\/$/, "").replace(/:\d{1,5}$/g, "");
|
|
7164
7194
|
client = new LaminarClient({
|
|
7165
|
-
baseUrl: `${
|
|
7195
|
+
baseUrl: `${urlWithoutSlash}:${port}`,
|
|
7166
7196
|
projectApiKey: apiKey
|
|
7167
7197
|
});
|
|
7168
7198
|
}
|
|
@@ -7442,14 +7472,15 @@ const startTracing = (options) => {
|
|
|
7442
7472
|
});
|
|
7443
7473
|
};
|
|
7444
7474
|
const patchModules = (modules) => {
|
|
7475
|
+
const instrumentations = initializeLaminarInstrumentations({
|
|
7476
|
+
baseUrl: _baseHttpUrl,
|
|
7477
|
+
apiKey: _apiKey,
|
|
7478
|
+
instrumentModules: modules,
|
|
7479
|
+
suppressContentTracing: !shouldSendTraces(),
|
|
7480
|
+
sessionRecordingOptions: _configuration?.sessionRecordingOptions
|
|
7481
|
+
});
|
|
7445
7482
|
registerInstrumentations({
|
|
7446
|
-
instrumentations
|
|
7447
|
-
baseUrl: _baseHttpUrl,
|
|
7448
|
-
apiKey: _apiKey,
|
|
7449
|
-
instrumentModules: modules,
|
|
7450
|
-
suppressContentTracing: !shouldSendTraces(),
|
|
7451
|
-
sessionRecordingOptions: _configuration?.sessionRecordingOptions
|
|
7452
|
-
}),
|
|
7483
|
+
instrumentations,
|
|
7453
7484
|
tracerProvider
|
|
7454
7485
|
});
|
|
7455
7486
|
};
|
|
@@ -8868,8 +8899,10 @@ const stripSystemMessages = (messages) => messages.filter((m) => !(m !== null &&
|
|
|
8868
8899
|
* hex-encoded (64 chars).
|
|
8869
8900
|
*/
|
|
8870
8901
|
const debugInputHash = (messages) => {
|
|
8871
|
-
const
|
|
8872
|
-
|
|
8902
|
+
const stripped = stripSystemMessages(messages);
|
|
8903
|
+
const canonical = canonicalJson(stripped);
|
|
8904
|
+
const digest = blake3(new TextEncoder().encode(canonical));
|
|
8905
|
+
return bytesToHex(digest);
|
|
8873
8906
|
};
|
|
8874
8907
|
//#endregion
|
|
8875
8908
|
//#region src/debug/replay.ts
|
|
@@ -8985,6 +9018,28 @@ const applyUsageToSpan = (span, usage) => {
|
|
|
8985
9018
|
applyUsage(attrs, usage);
|
|
8986
9019
|
for (const [k, v] of Object.entries(attrs)) if (v !== void 0) span.setAttribute(k, v);
|
|
8987
9020
|
};
|
|
9021
|
+
const resolveAssociationProperties = (event, parent) => {
|
|
9022
|
+
const { userId, sessionId, tags, ...metadata } = {
|
|
9023
|
+
...event?.toolsContext ?? {},
|
|
9024
|
+
...event?.runtimeContext ?? {}
|
|
9025
|
+
};
|
|
9026
|
+
return {
|
|
9027
|
+
associationProperties: {
|
|
9028
|
+
userId: typeof userId === "string" && userId.length > 0 ? userId : parent.userId,
|
|
9029
|
+
sessionId: typeof sessionId === "string" && sessionId.length > 0 ? sessionId : parent.sessionId,
|
|
9030
|
+
metadata: {
|
|
9031
|
+
...parent.metadata ?? {},
|
|
9032
|
+
...metadata
|
|
9033
|
+
}
|
|
9034
|
+
},
|
|
9035
|
+
tags: Array.isArray(tags) && tags.every((tag) => typeof tag === "string") ? tags : void 0
|
|
9036
|
+
};
|
|
9037
|
+
};
|
|
9038
|
+
const applyAssociationProperties = (span, properties) => {
|
|
9039
|
+
if (properties.userId) span.setAttribute(USER_ID, properties.userId);
|
|
9040
|
+
if (properties.sessionId) span.setAttribute(SESSION_ID, properties.sessionId);
|
|
9041
|
+
span.setAttributes(metadataToAttributes(properties.metadata));
|
|
9042
|
+
};
|
|
8988
9043
|
const applyFinishReason = (span, finishReason) => {
|
|
8989
9044
|
span.setAttribute("gen_ai.response.finish_reason", finishReason);
|
|
8990
9045
|
span.setAttribute("ai.response.finishReason", finishReason);
|
|
@@ -9018,6 +9073,17 @@ const verbatimPromptString = (prompt) => {
|
|
|
9018
9073
|
return null;
|
|
9019
9074
|
}
|
|
9020
9075
|
};
|
|
9076
|
+
const buildDecisionInputMessages = (state) => {
|
|
9077
|
+
if (state === void 0 || state === null) return void 0;
|
|
9078
|
+
if (Array.isArray(state)) return verbatimPromptString([{
|
|
9079
|
+
role: "user",
|
|
9080
|
+
content: state
|
|
9081
|
+
}]) ?? void 0;
|
|
9082
|
+
return serializeJSON$1([{
|
|
9083
|
+
role: "user",
|
|
9084
|
+
content: typeof state === "string" ? state : serializeJSON$1(state)
|
|
9085
|
+
}]);
|
|
9086
|
+
};
|
|
9021
9087
|
const verbatimPromptMessages = (prompt) => {
|
|
9022
9088
|
const serialized = verbatimPromptString(prompt);
|
|
9023
9089
|
if (serialized === null) return null;
|
|
@@ -9673,7 +9739,6 @@ var LaminarAiSdkTelemetry = class {
|
|
|
9673
9739
|
} : {}
|
|
9674
9740
|
}
|
|
9675
9741
|
}, parentCtx);
|
|
9676
|
-
const spanCtx = trace.setSpan(parentCtx, span);
|
|
9677
9742
|
span.setAttribute(SPAN_TYPE, "DEFAULT");
|
|
9678
9743
|
if (typeof event.operationId === "string") span.setAttribute("ai.operation", event.operationId);
|
|
9679
9744
|
if (typeof event.provider === "string") {
|
|
@@ -9686,14 +9751,14 @@ var LaminarAiSdkTelemetry = class {
|
|
|
9686
9751
|
}
|
|
9687
9752
|
if (typeof event.functionId === "string") span.setAttribute("ai.functionId", event.functionId);
|
|
9688
9753
|
if (event.operationId === "ai.embed" || event.operationId === "ai.embedMany" || event.operationId === "ai.rerank") span.setAttribute(SPAN_TYPE, "LLM");
|
|
9689
|
-
const
|
|
9690
|
-
|
|
9691
|
-
|
|
9692
|
-
};
|
|
9693
|
-
|
|
9694
|
-
|
|
9695
|
-
|
|
9696
|
-
span
|
|
9754
|
+
const parentAssociationProperties = parentCtx.getValue(ASSOCIATION_PROPERTIES_KEY) ?? {};
|
|
9755
|
+
const { associationProperties, tags } = resolveAssociationProperties(event, parentAssociationProperties);
|
|
9756
|
+
applyAssociationProperties(span, associationProperties);
|
|
9757
|
+
if (tags) span.setAttribute(`${ASSOCIATION_PROPERTIES}.tags`, tags);
|
|
9758
|
+
const spanCtx = trace.setSpan(parentCtx.setValue(ASSOCIATION_PROPERTIES_KEY, {
|
|
9759
|
+
...parentAssociationProperties,
|
|
9760
|
+
...Object.fromEntries(Object.entries(associationProperties).filter(([, value]) => value !== void 0))
|
|
9761
|
+
}), span);
|
|
9697
9762
|
if (this.recordInputs) {
|
|
9698
9763
|
if (Array.isArray(event.messages) || event.system !== void 0 || event.instructions !== void 0) {
|
|
9699
9764
|
const msgs = verbatimStandardizedMessages(event);
|
|
@@ -9709,7 +9774,8 @@ var LaminarAiSdkTelemetry = class {
|
|
|
9709
9774
|
ctx: spanCtx,
|
|
9710
9775
|
operationId: event.operationId ?? "unknown",
|
|
9711
9776
|
provider: event.provider,
|
|
9712
|
-
modelId: event.modelId
|
|
9777
|
+
modelId: event.modelId,
|
|
9778
|
+
associationProperties
|
|
9713
9779
|
});
|
|
9714
9780
|
};
|
|
9715
9781
|
this.onStepStart = (event) => {
|
|
@@ -9727,6 +9793,7 @@ var LaminarAiSdkTelemetry = class {
|
|
|
9727
9793
|
const spanCtx = trace.setSpan(op.ctx, span);
|
|
9728
9794
|
span.setAttribute(SPAN_TYPE, "DEFAULT");
|
|
9729
9795
|
span.setAttributes(buildAiSdkInstrumentationAttributes());
|
|
9796
|
+
applyAssociationProperties(span, op.associationProperties);
|
|
9730
9797
|
span.setAttribute("ai.step.number", stepNumber);
|
|
9731
9798
|
if (this.recordInputs) {
|
|
9732
9799
|
const msgs = verbatimStandardizedMessages(event);
|
|
@@ -9743,11 +9810,13 @@ var LaminarAiSdkTelemetry = class {
|
|
|
9743
9810
|
if (!callId) return;
|
|
9744
9811
|
const step = this.findLatestStep(callId);
|
|
9745
9812
|
const stepNumber = step?.stepNumber ?? event?.stepNumber ?? 0;
|
|
9746
|
-
const
|
|
9747
|
-
|
|
9813
|
+
const op = this.operationByCallId.get(callId);
|
|
9814
|
+
const parentCtx = step?.ctx ?? op?.ctx;
|
|
9815
|
+
if (!op || !parentCtx) return;
|
|
9748
9816
|
const span = getTracer().startSpan(`ai.llm ${event.provider ?? ""}:${event.modelId ?? ""}`, { kind: SpanKind.CLIENT }, parentCtx);
|
|
9749
9817
|
span.setAttribute(SPAN_TYPE, "LLM");
|
|
9750
9818
|
span.setAttributes(buildAiSdkInstrumentationAttributes());
|
|
9819
|
+
applyAssociationProperties(span, op.associationProperties);
|
|
9751
9820
|
applyRequestModelAttributes(span, event);
|
|
9752
9821
|
if (this.recordInputs) {
|
|
9753
9822
|
if (event.tools) try {
|
|
@@ -9844,6 +9913,7 @@ var LaminarAiSdkTelemetry = class {
|
|
|
9844
9913
|
const span = getTracer().startSpan(`ai.llm ${event.provider ?? ""}:${event.modelId ?? ""}`, { kind: SpanKind.CLIENT }, op.ctx);
|
|
9845
9914
|
span.setAttribute(SPAN_TYPE, "LLM");
|
|
9846
9915
|
span.setAttributes(buildAiSdkInstrumentationAttributes());
|
|
9916
|
+
applyAssociationProperties(span, op.associationProperties);
|
|
9847
9917
|
applyRequestModelAttributes(span, event);
|
|
9848
9918
|
if (this.recordInputs && Array.isArray(event?.promptMessages)) {
|
|
9849
9919
|
const serialized = verbatimPromptString(event.promptMessages);
|
|
@@ -9882,12 +9952,15 @@ var LaminarAiSdkTelemetry = class {
|
|
|
9882
9952
|
const toolCallId = toolCall?.toolCallId;
|
|
9883
9953
|
const toolName = toolCall?.toolName;
|
|
9884
9954
|
if (!callId || !toolCallId) return;
|
|
9885
|
-
const
|
|
9886
|
-
|
|
9955
|
+
const step = this.findLatestStep(callId);
|
|
9956
|
+
const op = this.operationByCallId.get(callId);
|
|
9957
|
+
const parentCtx = step?.ctx ?? op?.ctx;
|
|
9958
|
+
if (!op || !parentCtx) return;
|
|
9887
9959
|
const span = getTracer().startSpan(`ai.tool ${toolName ?? "unknown"}`, { kind: SpanKind.CLIENT }, parentCtx);
|
|
9888
9960
|
const spanCtx = trace.setSpan(parentCtx, span);
|
|
9889
9961
|
span.setAttribute(SPAN_TYPE, "TOOL");
|
|
9890
9962
|
span.setAttributes(buildAiSdkInstrumentationAttributes());
|
|
9963
|
+
applyAssociationProperties(span, op.associationProperties);
|
|
9891
9964
|
if (toolName) span.setAttribute("ai.toolCall.name", toolName);
|
|
9892
9965
|
span.setAttribute("ai.toolCall.id", toolCallId);
|
|
9893
9966
|
if (this.recordInputs && toolCall?.input !== void 0) {
|
|
@@ -9957,6 +10030,35 @@ var LaminarAiSdkTelemetry = class {
|
|
|
9957
10030
|
};
|
|
9958
10031
|
this.onRerankStart = () => {};
|
|
9959
10032
|
this.onRerankEnd = () => {};
|
|
10033
|
+
this.experimental_onDecideStart = (event) => {
|
|
10034
|
+
const callId = event?.callId;
|
|
10035
|
+
if (!callId) return;
|
|
10036
|
+
this.onStart(event);
|
|
10037
|
+
const op = this.operationByCallId.get(callId);
|
|
10038
|
+
if (!op) return;
|
|
10039
|
+
op.span.setAttribute(SPAN_TYPE, "LLM");
|
|
10040
|
+
applyRequestModelAttributes(op.span, event);
|
|
10041
|
+
if (this.recordInputs) {
|
|
10042
|
+
const input = buildDecisionInputMessages(event.state);
|
|
10043
|
+
if (input !== void 0) op.span.setAttribute("gen_ai.input.messages", input);
|
|
10044
|
+
if (event.questions !== void 0) op.span.setAttribute("gen_ai.request.structured_output_schema", serializeJSON$1(event.questions));
|
|
10045
|
+
}
|
|
10046
|
+
};
|
|
10047
|
+
this.experimental_onDecideEnd = (event) => {
|
|
10048
|
+
const callId = event?.callId;
|
|
10049
|
+
if (!callId) return;
|
|
10050
|
+
const op = this.operationByCallId.get(callId);
|
|
10051
|
+
if (!op) return;
|
|
10052
|
+
if (typeof event.response?.modelId === "string") op.span.setAttribute(LaminarAttributes.RESPONSE_MODEL, event.response.modelId);
|
|
10053
|
+
if (typeof event.response?.id === "string") op.span.setAttribute("gen_ai.response.id", event.response.id);
|
|
10054
|
+
applyUsageToSpan(op.span, event.usage);
|
|
10055
|
+
if (this.recordOutputs && event.answers !== void 0) op.span.setAttribute("gen_ai.output.messages", serializeJSON$1([{
|
|
10056
|
+
role: "assistant",
|
|
10057
|
+
content: serializeJSON$1(event.answers)
|
|
10058
|
+
}]));
|
|
10059
|
+
op.span.setStatus({ code: SpanStatusCode.OK });
|
|
10060
|
+
this.closeOperation(callId, op);
|
|
10061
|
+
};
|
|
9960
10062
|
this.onEnd = (event) => {
|
|
9961
10063
|
const callId = event?.callId;
|
|
9962
10064
|
if (!callId) return;
|