@lmnr-ai/lmnr 0.8.48 → 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-Ci0oAv2f.mjs → file-utils-DOEv6ccL.mjs} +47 -18
- package/dist/file-utils-DOEv6ccL.mjs.map +1 -0
- package/dist/{file-utils-BvYQiFYO.cjs → file-utils-RXJzJyiI.cjs} +47 -18
- package/dist/file-utils-RXJzJyiI.cjs.map +1 -0
- package/dist/index.cjs +164 -54
- 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 -54
- 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-BNApHb06.cjs → utils-CNR1tzh5.cjs} +10 -9
- package/dist/utils-CNR1tzh5.cjs.map +1 -0
- package/dist/{utils-OZ7rROM9.mjs → utils-DRrXCfun.mjs} +9 -8
- package/dist/{utils-OZ7rROM9.mjs.map → utils-DRrXCfun.mjs.map} +1 -1
- package/package.json +6 -8
- package/dist/file-utils-BvYQiFYO.cjs.map +0 -1
- package/dist/file-utils-Ci0oAv2f.mjs.map +0 -1
- package/dist/utils-BNApHb06.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_rolldown_runtime = require("./rolldown-runtime-
|
|
3
|
-
const require_utils = require("./utils-
|
|
2
|
+
const require_rolldown_runtime = require("./rolldown-runtime-Ctb5zv51.cjs");
|
|
3
|
+
const require_utils = require("./utils-CNR1tzh5.cjs");
|
|
4
4
|
const require_consts = require("./consts-9rSS0oeR.cjs");
|
|
5
5
|
let path = require("path");
|
|
6
6
|
path = require_rolldown_runtime.__toESM(path);
|
|
@@ -183,7 +183,7 @@ var LaminarDataset = class extends EvaluationDataset {
|
|
|
183
183
|
*/
|
|
184
184
|
async push(paths, recursive = false) {
|
|
185
185
|
if (!this.client) throw new Error("Client not set");
|
|
186
|
-
const { loadFromPaths } = await Promise.resolve().then(() => require("./file-utils-
|
|
186
|
+
const { loadFromPaths } = await Promise.resolve().then(() => require("./file-utils-RXJzJyiI.cjs")).then((n) => n.file_utils_exports);
|
|
187
187
|
const data = await loadFromPaths(Array.isArray(paths) ? paths : [paths], recursive);
|
|
188
188
|
if (data.length === 0) {
|
|
189
189
|
console.warn("No data to push. Skipping");
|
|
@@ -569,7 +569,8 @@ const handleStreamResult = (originalResult, streamInfo, span, ignoreOutput, seri
|
|
|
569
569
|
});
|
|
570
570
|
trackStreamProcessing(async () => {
|
|
571
571
|
try {
|
|
572
|
-
const
|
|
572
|
+
const tempResponse = new Response(stream2);
|
|
573
|
+
const { chunks, error } = await consumeResponse(tempResponse);
|
|
573
574
|
if (shouldSendTraces() && !ignoreOutput) try {
|
|
574
575
|
const output = {
|
|
575
576
|
type: "response",
|
|
@@ -668,7 +669,7 @@ const writeDebugSessionFile = (file, dir = process.cwd()) => {
|
|
|
668
669
|
* logic line-comparable with the Python `config.py`.
|
|
669
670
|
*/
|
|
670
671
|
const logger$24 = require_utils.initializeLogger();
|
|
671
|
-
const TRUTHY = new Set([
|
|
672
|
+
const TRUTHY = /* @__PURE__ */ new Set([
|
|
672
673
|
"true",
|
|
673
674
|
"1",
|
|
674
675
|
"yes",
|
|
@@ -740,10 +741,12 @@ const buildDebugConfig = () => {
|
|
|
740
741
|
const providedSessionId = process.env.LMNR_DEBUG_SESSION_ID || existing?.session_id || void 0;
|
|
741
742
|
const sessionId = providedSessionId || (0, node_crypto.randomUUID)();
|
|
742
743
|
const sessionMinted = providedSessionId === void 0;
|
|
744
|
+
const replayTraceId = process.env.LMNR_DEBUG_REPLAY_TRACE_ID || existing?.replay_trace_id || null;
|
|
745
|
+
const cacheUntilValue = process.env.LMNR_DEBUG_CACHE_UNTIL ?? existing?.cache_until ?? void 0;
|
|
743
746
|
return {
|
|
744
747
|
sessionId,
|
|
745
|
-
replayTraceId
|
|
746
|
-
cacheUntilSpanId: parseCacheUntil(
|
|
748
|
+
replayTraceId,
|
|
749
|
+
cacheUntilSpanId: parseCacheUntil(cacheUntilValue),
|
|
747
750
|
localOrigin: true,
|
|
748
751
|
sessionMinted
|
|
749
752
|
};
|
|
@@ -964,14 +967,15 @@ var DebugRuntime = class {
|
|
|
964
967
|
if (!this._config.localOrigin) return;
|
|
965
968
|
if (this._emitted) return;
|
|
966
969
|
this._emitted = true;
|
|
967
|
-
|
|
970
|
+
const file = buildDebugSessionFile({
|
|
968
971
|
sessionId: this._config.sessionId,
|
|
969
972
|
traceId: this._traceId,
|
|
970
973
|
replayTraceId: this._config.replayTraceId,
|
|
971
974
|
cacheUntil: this._config.cacheUntilSpanId,
|
|
972
975
|
debuggerUrl: this.debuggerSessionUrl(),
|
|
973
976
|
startedAt: this._startedAt
|
|
974
|
-
})
|
|
977
|
+
});
|
|
978
|
+
emitPointer(file);
|
|
975
979
|
}
|
|
976
980
|
};
|
|
977
981
|
let runtime = null;
|
|
@@ -1180,7 +1184,7 @@ var LaminarSpan = class LaminarSpan {
|
|
|
1180
1184
|
}
|
|
1181
1185
|
addTags(tags) {
|
|
1182
1186
|
const currentTags = this.tags;
|
|
1183
|
-
this.setTags(Array.from(new Set([...currentTags, ...tags])));
|
|
1187
|
+
this.setTags(Array.from(/* @__PURE__ */ new Set([...currentTags, ...tags])));
|
|
1184
1188
|
}
|
|
1185
1189
|
getLaminarSpanContext() {
|
|
1186
1190
|
let spanPath = [];
|
|
@@ -1568,7 +1572,8 @@ const flagSettingsEnv = (existing, cwd) => {
|
|
|
1568
1572
|
} catch {}
|
|
1569
1573
|
return {};
|
|
1570
1574
|
}
|
|
1571
|
-
|
|
1575
|
+
const resolved = path.isAbsolute(trimmed) ? trimmed : path.join(cwd ?? process.cwd(), trimmed);
|
|
1576
|
+
return settingsEnvBlock(loadSettingsFile(resolved) ?? {});
|
|
1572
1577
|
};
|
|
1573
1578
|
/**
|
|
1574
1579
|
* Build the `--settings` value that forces the CLI through our proxy.
|
|
@@ -1602,7 +1607,8 @@ const buildProxyFlagSettings = (existing, proxyUrl, cwd, settingSources) => {
|
|
|
1602
1607
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
1603
1608
|
settingsObj = parsed;
|
|
1604
1609
|
} else {
|
|
1605
|
-
const
|
|
1610
|
+
const resolved = path.isAbsolute(trimmed) ? trimmed : path.join(cwd ?? process.cwd(), trimmed);
|
|
1611
|
+
const loaded = loadSettingsFile(resolved);
|
|
1606
1612
|
if (loaded === null) return null;
|
|
1607
1613
|
settingsObj = loaded;
|
|
1608
1614
|
}
|
|
@@ -1693,7 +1699,10 @@ const resolveTargetUrlFromEnv = (envDict, fallback = DEFAULT_ANTHROPIC_BASE_URL,
|
|
|
1693
1699
|
const bedrockBaseUrl = getEnvValue(BEDROCK_BASE_URL_ENV);
|
|
1694
1700
|
if (bedrockBaseUrl) return bedrockBaseUrl.replace(/\/$/, "");
|
|
1695
1701
|
let region = getEnvValue(BEDROCK_AWS_REGION_ENV);
|
|
1696
|
-
if (!region)
|
|
1702
|
+
if (!region) {
|
|
1703
|
+
const awsProfile = getEnvValue("AWS_PROFILE") || "default";
|
|
1704
|
+
region = getRegionFromAwsConfig(awsProfile) ?? void 0;
|
|
1705
|
+
}
|
|
1697
1706
|
if (region) return `https://bedrock-runtime.${region}.amazonaws.com`;
|
|
1698
1707
|
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.`);
|
|
1699
1708
|
return null;
|
|
@@ -2232,10 +2241,13 @@ var Laminar = class Laminar {
|
|
|
2232
2241
|
runtime.recordProjectId(projectId);
|
|
2233
2242
|
const sessionUrl = runtime.debuggerSessionUrl();
|
|
2234
2243
|
logger$20.info(`Laminar debugger session: ${sessionUrl}`);
|
|
2235
|
-
if (runtime.shouldOpenBrowser)
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2244
|
+
if (runtime.shouldOpenBrowser) {
|
|
2245
|
+
const opener = process.platform === "win32" ? "start" : process.platform === "darwin" ? "open" : "xdg-open";
|
|
2246
|
+
(0, node_child_process.spawn)(opener, [sessionUrl], {
|
|
2247
|
+
detached: true,
|
|
2248
|
+
stdio: "ignore"
|
|
2249
|
+
}).unref();
|
|
2250
|
+
}
|
|
2239
2251
|
}
|
|
2240
2252
|
}).catch((e) => {
|
|
2241
2253
|
logger$20.warn("Failed to register debug session: " + require_utils.errorMessage(e));
|
|
@@ -2282,11 +2294,13 @@ var Laminar = class Laminar {
|
|
|
2282
2294
|
if (!debug || debug.enabled !== true || !debug.sessionId) return;
|
|
2283
2295
|
const existing = getRuntime();
|
|
2284
2296
|
if (existing !== null && existing.localOrigin) return;
|
|
2285
|
-
const
|
|
2297
|
+
const rolloutSessions = existing?.rolloutSessions ?? new require_utils.LaminarClient({
|
|
2286
2298
|
baseUrl: this.baseUrlForDebug,
|
|
2287
2299
|
projectApiKey: this.projectApiKey,
|
|
2288
2300
|
port: this.httpPortForDebug
|
|
2289
|
-
}).rolloutSessions
|
|
2301
|
+
}).rolloutSessions;
|
|
2302
|
+
const debuggerUrl = process?.env?.LMNR_FRONTEND_URL ?? require_utils.getFrontendUrl(this.baseUrlForDebug);
|
|
2303
|
+
const { runtime, configChanged } = initDebugRuntimeFromContext(debug, rolloutSessions, debuggerUrl);
|
|
2290
2304
|
if (runtime === null) return;
|
|
2291
2305
|
if (configChanged) {
|
|
2292
2306
|
this.debugRunLive = false;
|
|
@@ -2590,12 +2604,13 @@ var Laminar = class Laminar {
|
|
|
2590
2604
|
const sessionIdProperties = sessionIdValue ? { [require_utils.SESSION_ID]: sessionIdValue } : {};
|
|
2591
2605
|
const traceTypeProperties = traceTypeValue ? { [require_utils.TRACE_TYPE]: traceTypeValue } : {};
|
|
2592
2606
|
const tracingLevelProperties = tracingLevelValue ? { [`${require_utils.ASSOCIATION_PROPERTIES}.tracing_level`]: tracingLevelValue } : {};
|
|
2593
|
-
const
|
|
2607
|
+
const mergedMetadata = {
|
|
2594
2608
|
...this.globalMetadata,
|
|
2595
2609
|
...ctxMetadata,
|
|
2596
2610
|
...parentMetadata,
|
|
2597
2611
|
...metadata
|
|
2598
|
-
}
|
|
2612
|
+
};
|
|
2613
|
+
const metadataProperties = require_utils.metadataToAttributes(mergedMetadata);
|
|
2599
2614
|
const attributes = {
|
|
2600
2615
|
[require_utils.SPAN_TYPE]: spanType ?? "DEFAULT",
|
|
2601
2616
|
...tagProperties,
|
|
@@ -2959,7 +2974,8 @@ const prettyPrintZodSchema = (schema, indent = 2) => {
|
|
|
2959
2974
|
if (typeof description === "string") result += `.describe('${description.replace(/'/g, "\\'")}')`;
|
|
2960
2975
|
return result;
|
|
2961
2976
|
};
|
|
2962
|
-
|
|
2977
|
+
const finalType = applyModifiers(value, getBaseType(value));
|
|
2978
|
+
return `${indentString}${key}: ${finalType},`;
|
|
2963
2979
|
}).join("\n")}\n})`;
|
|
2964
2980
|
};
|
|
2965
2981
|
const modelToProviderMap = {
|
|
@@ -3015,7 +3031,7 @@ const modelToProvider = (model) => {
|
|
|
3015
3031
|
const injectScript = (sessionRecordingOptions, stringifyCallbackArgs) => {
|
|
3016
3032
|
const BATCH_TIMEOUT = 2e3;
|
|
3017
3033
|
const HEARTBEAT_INTERVAL = 1e3;
|
|
3018
|
-
const CHUNK_SIZE =
|
|
3034
|
+
const CHUNK_SIZE = 262144;
|
|
3019
3035
|
window.lmnrRrwebEventsBatch = [];
|
|
3020
3036
|
window.lmnrChunkSequence = 0;
|
|
3021
3037
|
window.lmnrSendInProgress = false;
|
|
@@ -3076,7 +3092,9 @@ const injectScript = (sessionRecordingOptions, stringifyCallbackArgs) => {
|
|
|
3076
3092
|
try {
|
|
3077
3093
|
const compressedEvents = [];
|
|
3078
3094
|
for (const event of events) try {
|
|
3079
|
-
const
|
|
3095
|
+
const dataString = JSON.stringify(event.data);
|
|
3096
|
+
const compressed = await gzipCompress(dataString);
|
|
3097
|
+
const base64Data = await bufferToBase64(compressed);
|
|
3080
3098
|
compressedEvents.push({
|
|
3081
3099
|
...event,
|
|
3082
3100
|
data: base64Data
|
|
@@ -5326,15 +5344,17 @@ const applyGenerationSpanData = (lmnrSpan, spanData) => {
|
|
|
5326
5344
|
setGenAiInputMessages(lmnrSpan, inputData, getCurrentSystemInstructions());
|
|
5327
5345
|
const outputData = spanData?.output;
|
|
5328
5346
|
setGenAiOutputMessages(lmnrSpan, outputData);
|
|
5329
|
-
|
|
5347
|
+
const llmData = {
|
|
5330
5348
|
model: spanData?.model,
|
|
5331
5349
|
usage: spanData?.usage,
|
|
5332
5350
|
response_id: spanData?.response_id ?? spanData?.id
|
|
5333
|
-
}
|
|
5351
|
+
};
|
|
5352
|
+
applyLlmAttributes(lmnrSpan, llmData);
|
|
5334
5353
|
};
|
|
5335
5354
|
const applyResponseSpanData = (lmnrSpan, spanData) => {
|
|
5336
5355
|
const response = spanData?._response ?? spanData?.response;
|
|
5337
|
-
|
|
5356
|
+
const responseInput = spanData?._input ?? spanData?.input;
|
|
5357
|
+
setGenAiInputMessages(lmnrSpan, responseInput, getCurrentSystemInstructions());
|
|
5338
5358
|
if (response != null) {
|
|
5339
5359
|
setGenAiOutputMessagesFromResponse(lmnrSpan, response);
|
|
5340
5360
|
setToolDefinitionsFromResponse(lmnrSpan, response);
|
|
@@ -5375,8 +5395,10 @@ const applySpeechSpanData = (lmnrSpan, spanData) => {
|
|
|
5375
5395
|
const inputText = spanData?.input;
|
|
5376
5396
|
if (inputText) setGenAiInputMessages(lmnrSpan, inputText);
|
|
5377
5397
|
const outputData = spanData?.output;
|
|
5378
|
-
if (outputData)
|
|
5379
|
-
|
|
5398
|
+
if (outputData) {
|
|
5399
|
+
if (typeof outputData === "object" && !Array.isArray(outputData)) setGenAiOutputMessages(lmnrSpan, outputData.data);
|
|
5400
|
+
else setGenAiOutputMessages(lmnrSpan, outputData);
|
|
5401
|
+
}
|
|
5380
5402
|
};
|
|
5381
5403
|
const applyTranscriptionSpanData = (lmnrSpan, spanData) => {
|
|
5382
5404
|
const model = spanData?.model;
|
|
@@ -5386,8 +5408,10 @@ const applyTranscriptionSpanData = (lmnrSpan, spanData) => {
|
|
|
5386
5408
|
lmnrSpan.setAttribute(require_utils.LaminarAttributes.PROVIDER, "openai");
|
|
5387
5409
|
}
|
|
5388
5410
|
const inputData = spanData?.input;
|
|
5389
|
-
if (inputData)
|
|
5390
|
-
|
|
5411
|
+
if (inputData) {
|
|
5412
|
+
if (typeof inputData === "object" && !Array.isArray(inputData)) setGenAiInputMessages(lmnrSpan, inputData.data);
|
|
5413
|
+
else setGenAiInputMessages(lmnrSpan, inputData);
|
|
5414
|
+
}
|
|
5391
5415
|
const outputText = spanData?.output;
|
|
5392
5416
|
if (outputText) setGenAiOutputMessages(lmnrSpan, outputText);
|
|
5393
5417
|
};
|
|
@@ -5610,7 +5634,8 @@ const wrapGetResponse = (original) => function(request, ...rest) {
|
|
|
5610
5634
|
};
|
|
5611
5635
|
const wrapGetStreamedResponse = (original) => function(request, ...rest) {
|
|
5612
5636
|
const systemInstructions = request?.systemInstructions;
|
|
5613
|
-
|
|
5637
|
+
const source = original.call(this, request, ...rest);
|
|
5638
|
+
return wrapStreamWithSystemInstructions(systemInstructions, source);
|
|
5614
5639
|
};
|
|
5615
5640
|
const MODEL_METHODS = ["getResponse", "getStreamedResponse"];
|
|
5616
5641
|
var OpenAIAgentsInstrumentation = class extends _opentelemetry_instrumentation.InstrumentationBase {
|
|
@@ -5755,12 +5780,12 @@ var OpencodeInstrumentation = class extends _opentelemetry_instrumentation.Instr
|
|
|
5755
5780
|
};
|
|
5756
5781
|
//#endregion
|
|
5757
5782
|
//#region src/opentelemetry-lib/instrumentation/openrouter/utils.ts
|
|
5758
|
-
const TERMINAL_RESPONSE_EVENTS = new Set([
|
|
5783
|
+
const TERMINAL_RESPONSE_EVENTS = /* @__PURE__ */ new Set([
|
|
5759
5784
|
"response.completed",
|
|
5760
5785
|
"response.incomplete",
|
|
5761
5786
|
"response.failed"
|
|
5762
5787
|
]);
|
|
5763
|
-
const ERROR_RESPONSE_STATUSES = new Set(["failed", "incomplete"]);
|
|
5788
|
+
const ERROR_RESPONSE_STATUSES = /* @__PURE__ */ new Set(["failed", "incomplete"]);
|
|
5764
5789
|
const safeSetAttribute$1 = (span, key, value) => {
|
|
5765
5790
|
if (value === null || value === void 0) return;
|
|
5766
5791
|
if (typeof value === "string" && value.length === 0) return;
|
|
@@ -5926,7 +5951,8 @@ const wrapStream = (span, kind, stream, traceContent) => {
|
|
|
5926
5951
|
throw error;
|
|
5927
5952
|
} finally {
|
|
5928
5953
|
try {
|
|
5929
|
-
|
|
5954
|
+
const response = kind === "chat" ? aggregateChatChunks(chunks) : responseFromStreamEvents(chunks);
|
|
5955
|
+
setResponseAttributes$1(span, kind, response, traceContent);
|
|
5930
5956
|
} finally {
|
|
5931
5957
|
span.end();
|
|
5932
5958
|
}
|
|
@@ -6492,7 +6518,9 @@ const buildHeaders = (existing) => {
|
|
|
6492
6518
|
const headers = { ...existing };
|
|
6493
6519
|
if (laminarCtx) {
|
|
6494
6520
|
headers[require_consts.LAMINAR_SPAN_CONTEXT_HEADER] = encodePayload(JSON.stringify(laminarCtx));
|
|
6495
|
-
|
|
6521
|
+
const traceHex = laminarCtx.traceId.replace(/-/g, "");
|
|
6522
|
+
const spanHex = laminarCtx.spanId.replace(/-/g, "").slice(16);
|
|
6523
|
+
headers[require_consts.TRACEPARENT_HEADER] = encodePayload(`00-${traceHex}-${spanHex}-01`);
|
|
6496
6524
|
} else {
|
|
6497
6525
|
const ctx = rawSpan.spanContext();
|
|
6498
6526
|
headers[require_consts.TRACEPARENT_HEADER] = encodePayload(`00-${ctx.traceId}-${ctx.spanId}-01`);
|
|
@@ -6956,10 +6984,11 @@ const patchTemporalWorker = (workerModule, options = {}) => {
|
|
|
6956
6984
|
activity: [ActivityInterceptorFactory(options), ...rawOpts?.interceptors?.activity ?? []]
|
|
6957
6985
|
};
|
|
6958
6986
|
if (!usesWorkflowBundle) interceptors.workflowModules = [require.resolve("@lmnr-ai/lmnr/temporal-workflow-interceptors"), ...rawOpts?.interceptors?.workflowModules ?? []];
|
|
6959
|
-
|
|
6987
|
+
const patched = {
|
|
6960
6988
|
...rawOpts,
|
|
6961
6989
|
interceptors
|
|
6962
|
-
}
|
|
6990
|
+
};
|
|
6991
|
+
return originalCreate(patched, ...rest);
|
|
6963
6992
|
};
|
|
6964
6993
|
};
|
|
6965
6994
|
/**
|
|
@@ -7168,8 +7197,9 @@ const initializeLaminarInstrumentations = (options = {}) => {
|
|
|
7168
7197
|
if (apiKey) {
|
|
7169
7198
|
const url = options.baseUrl ?? process?.env?.LMNR_BASE_URL ?? "https://api.lmnr.ai";
|
|
7170
7199
|
const port = options.httpPort ?? (url.match(/:\d{1,5}$/g) ? parseInt(url.match(/:\d{1,5}$/g)[0].slice(1)) : 443);
|
|
7200
|
+
const urlWithoutSlash = url.replace(/\/$/, "").replace(/:\d{1,5}$/g, "");
|
|
7171
7201
|
client = new require_utils.LaminarClient({
|
|
7172
|
-
baseUrl: `${
|
|
7202
|
+
baseUrl: `${urlWithoutSlash}:${port}`,
|
|
7173
7203
|
projectApiKey: apiKey
|
|
7174
7204
|
});
|
|
7175
7205
|
}
|
|
@@ -7449,14 +7479,15 @@ const startTracing = (options) => {
|
|
|
7449
7479
|
});
|
|
7450
7480
|
};
|
|
7451
7481
|
const patchModules = (modules) => {
|
|
7482
|
+
const instrumentations = initializeLaminarInstrumentations({
|
|
7483
|
+
baseUrl: _baseHttpUrl,
|
|
7484
|
+
apiKey: _apiKey,
|
|
7485
|
+
instrumentModules: modules,
|
|
7486
|
+
suppressContentTracing: !shouldSendTraces(),
|
|
7487
|
+
sessionRecordingOptions: _configuration?.sessionRecordingOptions
|
|
7488
|
+
});
|
|
7452
7489
|
(0, _opentelemetry_instrumentation.registerInstrumentations)({
|
|
7453
|
-
instrumentations
|
|
7454
|
-
baseUrl: _baseHttpUrl,
|
|
7455
|
-
apiKey: _apiKey,
|
|
7456
|
-
instrumentModules: modules,
|
|
7457
|
-
suppressContentTracing: !shouldSendTraces(),
|
|
7458
|
-
sessionRecordingOptions: _configuration?.sessionRecordingOptions
|
|
7459
|
-
}),
|
|
7490
|
+
instrumentations,
|
|
7460
7491
|
tracerProvider
|
|
7461
7492
|
});
|
|
7462
7493
|
};
|
|
@@ -8875,8 +8906,10 @@ const stripSystemMessages = (messages) => messages.filter((m) => !(m !== null &&
|
|
|
8875
8906
|
* hex-encoded (64 chars).
|
|
8876
8907
|
*/
|
|
8877
8908
|
const debugInputHash = (messages) => {
|
|
8878
|
-
const
|
|
8879
|
-
|
|
8909
|
+
const stripped = stripSystemMessages(messages);
|
|
8910
|
+
const canonical = canonicalJson(stripped);
|
|
8911
|
+
const digest = (0, _noble_hashes_blake3_js.blake3)(new TextEncoder().encode(canonical));
|
|
8912
|
+
return (0, _noble_hashes_utils_js.bytesToHex)(digest);
|
|
8880
8913
|
};
|
|
8881
8914
|
//#endregion
|
|
8882
8915
|
//#region src/debug/replay.ts
|
|
@@ -8992,6 +9025,28 @@ const applyUsageToSpan = (span, usage) => {
|
|
|
8992
9025
|
applyUsage(attrs, usage);
|
|
8993
9026
|
for (const [k, v] of Object.entries(attrs)) if (v !== void 0) span.setAttribute(k, v);
|
|
8994
9027
|
};
|
|
9028
|
+
const resolveAssociationProperties = (event, parent) => {
|
|
9029
|
+
const { userId, sessionId, tags, ...metadata } = {
|
|
9030
|
+
...event?.toolsContext ?? {},
|
|
9031
|
+
...event?.runtimeContext ?? {}
|
|
9032
|
+
};
|
|
9033
|
+
return {
|
|
9034
|
+
associationProperties: {
|
|
9035
|
+
userId: typeof userId === "string" && userId.length > 0 ? userId : parent.userId,
|
|
9036
|
+
sessionId: typeof sessionId === "string" && sessionId.length > 0 ? sessionId : parent.sessionId,
|
|
9037
|
+
metadata: {
|
|
9038
|
+
...parent.metadata ?? {},
|
|
9039
|
+
...metadata
|
|
9040
|
+
}
|
|
9041
|
+
},
|
|
9042
|
+
tags: Array.isArray(tags) && tags.every((tag) => typeof tag === "string") ? tags : void 0
|
|
9043
|
+
};
|
|
9044
|
+
};
|
|
9045
|
+
const applyAssociationProperties = (span, properties) => {
|
|
9046
|
+
if (properties.userId) span.setAttribute(require_utils.USER_ID, properties.userId);
|
|
9047
|
+
if (properties.sessionId) span.setAttribute(require_utils.SESSION_ID, properties.sessionId);
|
|
9048
|
+
span.setAttributes(require_utils.metadataToAttributes(properties.metadata));
|
|
9049
|
+
};
|
|
8995
9050
|
const applyFinishReason = (span, finishReason) => {
|
|
8996
9051
|
span.setAttribute("gen_ai.response.finish_reason", finishReason);
|
|
8997
9052
|
span.setAttribute("ai.response.finishReason", finishReason);
|
|
@@ -9025,6 +9080,17 @@ const verbatimPromptString = (prompt) => {
|
|
|
9025
9080
|
return null;
|
|
9026
9081
|
}
|
|
9027
9082
|
};
|
|
9083
|
+
const buildDecisionInputMessages = (state) => {
|
|
9084
|
+
if (state === void 0 || state === null) return void 0;
|
|
9085
|
+
if (Array.isArray(state)) return verbatimPromptString([{
|
|
9086
|
+
role: "user",
|
|
9087
|
+
content: state
|
|
9088
|
+
}]) ?? void 0;
|
|
9089
|
+
return serializeJSON$1([{
|
|
9090
|
+
role: "user",
|
|
9091
|
+
content: typeof state === "string" ? state : serializeJSON$1(state)
|
|
9092
|
+
}]);
|
|
9093
|
+
};
|
|
9028
9094
|
const verbatimPromptMessages = (prompt) => {
|
|
9029
9095
|
const serialized = verbatimPromptString(prompt);
|
|
9030
9096
|
if (serialized === null) return null;
|
|
@@ -9680,7 +9746,6 @@ var LaminarAiSdkTelemetry = class {
|
|
|
9680
9746
|
} : {}
|
|
9681
9747
|
}
|
|
9682
9748
|
}, parentCtx);
|
|
9683
|
-
const spanCtx = _opentelemetry_api.trace.setSpan(parentCtx, span);
|
|
9684
9749
|
span.setAttribute(require_utils.SPAN_TYPE, "DEFAULT");
|
|
9685
9750
|
if (typeof event.operationId === "string") span.setAttribute("ai.operation", event.operationId);
|
|
9686
9751
|
if (typeof event.provider === "string") {
|
|
@@ -9693,6 +9758,14 @@ var LaminarAiSdkTelemetry = class {
|
|
|
9693
9758
|
}
|
|
9694
9759
|
if (typeof event.functionId === "string") span.setAttribute("ai.functionId", event.functionId);
|
|
9695
9760
|
if (event.operationId === "ai.embed" || event.operationId === "ai.embedMany" || event.operationId === "ai.rerank") span.setAttribute(require_utils.SPAN_TYPE, "LLM");
|
|
9761
|
+
const parentAssociationProperties = parentCtx.getValue(ASSOCIATION_PROPERTIES_KEY) ?? {};
|
|
9762
|
+
const { associationProperties, tags } = resolveAssociationProperties(event, parentAssociationProperties);
|
|
9763
|
+
applyAssociationProperties(span, associationProperties);
|
|
9764
|
+
if (tags) span.setAttribute(`${require_utils.ASSOCIATION_PROPERTIES}.tags`, tags);
|
|
9765
|
+
const spanCtx = _opentelemetry_api.trace.setSpan(parentCtx.setValue(ASSOCIATION_PROPERTIES_KEY, {
|
|
9766
|
+
...parentAssociationProperties,
|
|
9767
|
+
...Object.fromEntries(Object.entries(associationProperties).filter(([, value]) => value !== void 0))
|
|
9768
|
+
}), span);
|
|
9696
9769
|
if (this.recordInputs) {
|
|
9697
9770
|
if (Array.isArray(event.messages) || event.system !== void 0 || event.instructions !== void 0) {
|
|
9698
9771
|
const msgs = verbatimStandardizedMessages(event);
|
|
@@ -9708,7 +9781,8 @@ var LaminarAiSdkTelemetry = class {
|
|
|
9708
9781
|
ctx: spanCtx,
|
|
9709
9782
|
operationId: event.operationId ?? "unknown",
|
|
9710
9783
|
provider: event.provider,
|
|
9711
|
-
modelId: event.modelId
|
|
9784
|
+
modelId: event.modelId,
|
|
9785
|
+
associationProperties
|
|
9712
9786
|
});
|
|
9713
9787
|
};
|
|
9714
9788
|
this.onStepStart = (event) => {
|
|
@@ -9726,6 +9800,7 @@ var LaminarAiSdkTelemetry = class {
|
|
|
9726
9800
|
const spanCtx = _opentelemetry_api.trace.setSpan(op.ctx, span);
|
|
9727
9801
|
span.setAttribute(require_utils.SPAN_TYPE, "DEFAULT");
|
|
9728
9802
|
span.setAttributes(buildAiSdkInstrumentationAttributes());
|
|
9803
|
+
applyAssociationProperties(span, op.associationProperties);
|
|
9729
9804
|
span.setAttribute("ai.step.number", stepNumber);
|
|
9730
9805
|
if (this.recordInputs) {
|
|
9731
9806
|
const msgs = verbatimStandardizedMessages(event);
|
|
@@ -9742,11 +9817,13 @@ var LaminarAiSdkTelemetry = class {
|
|
|
9742
9817
|
if (!callId) return;
|
|
9743
9818
|
const step = this.findLatestStep(callId);
|
|
9744
9819
|
const stepNumber = step?.stepNumber ?? event?.stepNumber ?? 0;
|
|
9745
|
-
const
|
|
9746
|
-
|
|
9820
|
+
const op = this.operationByCallId.get(callId);
|
|
9821
|
+
const parentCtx = step?.ctx ?? op?.ctx;
|
|
9822
|
+
if (!op || !parentCtx) return;
|
|
9747
9823
|
const span = getTracer().startSpan(`ai.llm ${event.provider ?? ""}:${event.modelId ?? ""}`, { kind: _opentelemetry_api.SpanKind.CLIENT }, parentCtx);
|
|
9748
9824
|
span.setAttribute(require_utils.SPAN_TYPE, "LLM");
|
|
9749
9825
|
span.setAttributes(buildAiSdkInstrumentationAttributes());
|
|
9826
|
+
applyAssociationProperties(span, op.associationProperties);
|
|
9750
9827
|
applyRequestModelAttributes(span, event);
|
|
9751
9828
|
if (this.recordInputs) {
|
|
9752
9829
|
if (event.tools) try {
|
|
@@ -9843,6 +9920,7 @@ var LaminarAiSdkTelemetry = class {
|
|
|
9843
9920
|
const span = getTracer().startSpan(`ai.llm ${event.provider ?? ""}:${event.modelId ?? ""}`, { kind: _opentelemetry_api.SpanKind.CLIENT }, op.ctx);
|
|
9844
9921
|
span.setAttribute(require_utils.SPAN_TYPE, "LLM");
|
|
9845
9922
|
span.setAttributes(buildAiSdkInstrumentationAttributes());
|
|
9923
|
+
applyAssociationProperties(span, op.associationProperties);
|
|
9846
9924
|
applyRequestModelAttributes(span, event);
|
|
9847
9925
|
if (this.recordInputs && Array.isArray(event?.promptMessages)) {
|
|
9848
9926
|
const serialized = verbatimPromptString(event.promptMessages);
|
|
@@ -9881,12 +9959,15 @@ var LaminarAiSdkTelemetry = class {
|
|
|
9881
9959
|
const toolCallId = toolCall?.toolCallId;
|
|
9882
9960
|
const toolName = toolCall?.toolName;
|
|
9883
9961
|
if (!callId || !toolCallId) return;
|
|
9884
|
-
const
|
|
9885
|
-
|
|
9962
|
+
const step = this.findLatestStep(callId);
|
|
9963
|
+
const op = this.operationByCallId.get(callId);
|
|
9964
|
+
const parentCtx = step?.ctx ?? op?.ctx;
|
|
9965
|
+
if (!op || !parentCtx) return;
|
|
9886
9966
|
const span = getTracer().startSpan(`ai.tool ${toolName ?? "unknown"}`, { kind: _opentelemetry_api.SpanKind.CLIENT }, parentCtx);
|
|
9887
9967
|
const spanCtx = _opentelemetry_api.trace.setSpan(parentCtx, span);
|
|
9888
9968
|
span.setAttribute(require_utils.SPAN_TYPE, "TOOL");
|
|
9889
9969
|
span.setAttributes(buildAiSdkInstrumentationAttributes());
|
|
9970
|
+
applyAssociationProperties(span, op.associationProperties);
|
|
9890
9971
|
if (toolName) span.setAttribute("ai.toolCall.name", toolName);
|
|
9891
9972
|
span.setAttribute("ai.toolCall.id", toolCallId);
|
|
9892
9973
|
if (this.recordInputs && toolCall?.input !== void 0) {
|
|
@@ -9956,6 +10037,35 @@ var LaminarAiSdkTelemetry = class {
|
|
|
9956
10037
|
};
|
|
9957
10038
|
this.onRerankStart = () => {};
|
|
9958
10039
|
this.onRerankEnd = () => {};
|
|
10040
|
+
this.experimental_onDecideStart = (event) => {
|
|
10041
|
+
const callId = event?.callId;
|
|
10042
|
+
if (!callId) return;
|
|
10043
|
+
this.onStart(event);
|
|
10044
|
+
const op = this.operationByCallId.get(callId);
|
|
10045
|
+
if (!op) return;
|
|
10046
|
+
op.span.setAttribute(require_utils.SPAN_TYPE, "LLM");
|
|
10047
|
+
applyRequestModelAttributes(op.span, event);
|
|
10048
|
+
if (this.recordInputs) {
|
|
10049
|
+
const input = buildDecisionInputMessages(event.state);
|
|
10050
|
+
if (input !== void 0) op.span.setAttribute("gen_ai.input.messages", input);
|
|
10051
|
+
if (event.questions !== void 0) op.span.setAttribute("gen_ai.request.structured_output_schema", serializeJSON$1(event.questions));
|
|
10052
|
+
}
|
|
10053
|
+
};
|
|
10054
|
+
this.experimental_onDecideEnd = (event) => {
|
|
10055
|
+
const callId = event?.callId;
|
|
10056
|
+
if (!callId) return;
|
|
10057
|
+
const op = this.operationByCallId.get(callId);
|
|
10058
|
+
if (!op) return;
|
|
10059
|
+
if (typeof event.response?.modelId === "string") op.span.setAttribute(require_utils.LaminarAttributes.RESPONSE_MODEL, event.response.modelId);
|
|
10060
|
+
if (typeof event.response?.id === "string") op.span.setAttribute("gen_ai.response.id", event.response.id);
|
|
10061
|
+
applyUsageToSpan(op.span, event.usage);
|
|
10062
|
+
if (this.recordOutputs && event.answers !== void 0) op.span.setAttribute("gen_ai.output.messages", serializeJSON$1([{
|
|
10063
|
+
role: "assistant",
|
|
10064
|
+
content: serializeJSON$1(event.answers)
|
|
10065
|
+
}]));
|
|
10066
|
+
op.span.setStatus({ code: _opentelemetry_api.SpanStatusCode.OK });
|
|
10067
|
+
this.closeOperation(callId, op);
|
|
10068
|
+
};
|
|
9959
10069
|
this.onEnd = (event) => {
|
|
9960
10070
|
const callId = event?.callId;
|
|
9961
10071
|
if (!callId) return;
|