@openclaw/ai 2026.11.3 → 2026.11.5-beta.2
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/README.md +11 -8
- package/dist/.source-module-urls/fe058cc430242ce2ab0dfbcbe153e240a52cf9c3072c3dc0a73e5f956b6ba49b.json +1 -0
- package/dist/anthropic-DEKgalVg.mjs +182 -0
- package/dist/{anthropic-payload-policy-C0ki72BT.d.mts → anthropic-payload-policy-CXCJ5Pmj.d.mts} +21 -4
- package/dist/{anthropic-stream-reducer-yWDb5Cct.mjs → anthropic-stream-lifecycle-DF2qVvg1.mjs} +845 -649
- package/dist/{anthropic-tool-projection-C2-d1eZ3.d.mts → anthropic-tool-projection-D5DyrL6C.d.mts} +6 -7
- package/dist/{anthropic-tool-projection-DZOKfAmL.mjs → anthropic-tool-projection-dGRfr4iT.mjs} +22 -32
- package/dist/{api-registry-gDt0faai.d.mts → api-registry-DY2MLUyg.d.mts} +2 -2
- package/dist/assistant-output-CD4kY9gu.mjs +16 -0
- package/dist/{azure-openai-responses-BvvXzZbi.mjs → azure-openai-responses-DbQV5RTx.mjs} +47 -53
- package/dist/{cloudflare-Dttf8jKq.mjs → cloudflare-BJ2_Xabx.mjs} +1 -1
- package/dist/{credential-redaction-XvsPf7Yi.d.mts → credential-redaction-DrgndwTJ.d.mts} +5 -3
- package/dist/{deferred-event-buffer-DAvyP7qA.mjs → deferred-event-buffer-tIGkTkTm.mjs} +1 -2
- package/dist/{diagnostics-v7oVEW59.mjs → diagnostics-CloVGQiK.mjs} +27 -20
- package/dist/{diagnostics-DzrF1h4J.mjs → diagnostics-o1PrVNQb.mjs} +11 -4
- package/dist/diagnostics.d.mts +6 -7
- package/dist/diagnostics.mjs +4 -4
- package/dist/{env-api-keys-Xd8dm_aV.mjs → env-api-keys-BuHc86ya.mjs} +1 -26
- package/dist/event-stream-B4ZcSvsu.d.mts +1 -0
- package/dist/{event-stream-CzpE1g_o.d.mts → event-stream-BYmtRe8-.d.mts} +1 -1
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -2
- package/dist/expect-lbe3Hgrh.mjs +8 -0
- package/dist/{github-copilot-request-facts-F-EmvkpW.mjs → github-copilot-request-facts-BZ_EMo7X.mjs} +1 -1
- package/dist/{google-Cpi_cLKZ.mjs → google-B1g82bn4.mjs} +7 -8
- package/dist/{google-interactions-CGINbsjO.mjs → google-interactions-Ckr0Z99Z.mjs} +243 -269
- package/dist/{google-messages-DQMgG5yG.mjs → google-messages-A-9d3y5V.mjs} +52 -18
- package/dist/{google-provider-stream-BHd0cST9.mjs → google-provider-stream-CNVh4gpm.mjs} +19 -11
- package/dist/{google-shared-vtag8bj5.mjs → google-shared-WNM86ZcW.mjs} +72 -42
- package/dist/{google-vertex-eKoUnW7N.mjs → google-vertex-CXjleC6g.mjs} +3 -3
- package/dist/{google-video-slots-D8tPH8wX.mjs → google-video-slots-Bxt-OXO8.mjs} +1 -1
- package/dist/{host-CWt55nnF.mjs → host-DX7ORpeH.mjs} +46 -39
- package/dist/{host-jJOffdlW.d.mts → host-ccbwPC3A.d.mts} +17 -9
- package/dist/{host-policy-Dm7PM6AD.mjs → host-policy-jCZebuXx.mjs} +2 -2
- package/dist/index-Bczt0MnO.d.mts +17 -0
- package/dist/index.d.mts +8 -7
- package/dist/index.mjs +9 -7
- package/dist/internal/anthropic.d.mts +21 -26
- package/dist/internal/anthropic.mjs +6 -6
- package/dist/internal/google-model-family.mjs +1 -1
- package/dist/internal/google.d.mts +15 -0
- package/dist/internal/google.mjs +1 -0
- package/dist/internal/model-request-body.d.mts +37 -0
- package/dist/internal/model-request-body.mjs +106 -0
- package/dist/internal/openai-completions-compat.d.mts +1 -1
- package/dist/internal/openai-completions-compat.mjs +1 -1
- package/dist/internal/openai-responses-payload-policy.d.mts +2 -2
- package/dist/internal/openai-responses-payload-policy.mjs +2 -2
- package/dist/internal/openai.d.mts +14 -12
- package/dist/internal/openai.mjs +11 -10
- package/dist/internal/reasoning-tag-text-partitioner.d.mts +26 -0
- package/dist/{reasoning-tag-text-partitioner-CU9A4Lg8.mjs → internal/reasoning-tag-text-partitioner.mjs} +313 -111
- package/dist/internal/retry-after.d.mts +2 -2
- package/dist/internal/retry-after.mjs +96 -32
- package/dist/internal/runtime.d.mts +15 -41
- package/dist/internal/runtime.mjs +9 -10
- package/dist/internal/shared.d.mts +21 -25
- package/dist/internal/shared.mjs +9 -98
- package/dist/internal/tool-schema.d.mts +10 -10
- package/dist/internal/tool-schema.mjs +4 -4
- package/dist/{llm-request-activity-CfMuh5cC.mjs → llm-request-activity-DzaHoRAU.mjs} +2 -2
- package/dist/mistral-CjHkvsqR.mjs +3741 -0
- package/dist/{openai.LICENSE → mistral.LICENSE} +1 -1
- package/dist/{model-transport-url-BrsjjdjR.d.mts → model-transport-url-BdksnBqu.d.mts} +6 -8
- package/dist/{number-coercion-37gmNkuA.mjs → number-coercion-C7HsBgUL.mjs} +7 -2
- package/dist/observe-async-iterator-AlARO5wS.d.mts +178 -0
- package/dist/observe-async-iterator-DgmegcZR.mjs +181 -0
- package/dist/{openai-chatgpt-responses-BZa3SySh.mjs → openai-chatgpt-responses-CwS5JP7A.mjs} +61 -80
- package/dist/{openai-completions-compat-CBvb2eld.d.mts → openai-completions-compat-CJ-NsDzg.d.mts} +12 -6
- package/dist/{openai-completions-compat-bNQXF1y9.mjs → openai-completions-compat-CstlTQuF.mjs} +74 -50
- package/dist/{openai-completions-CCZ_UHCk.mjs → openai-completions-sj4S-RXQ.mjs} +5 -5
- package/dist/openai-completions-transport-BDAIA0_P.mjs +3406 -0
- package/dist/{openai-prompt-cache-DgjD-UL5.d.mts → openai-prompt-cache-BZGaIWYh.d.mts} +4 -4
- package/dist/{openai-prompt-cache-B9AvdoEo.mjs → openai-prompt-cache-CgDoFhO0.mjs} +5 -4
- package/dist/{openai-responses-compaction-replay-_sUXtcwU.d.mts → openai-responses-compaction-replay-CNHk6k53.d.mts} +4 -4
- package/dist/{openai-responses-contracts-B1nkeLL6.d.mts → openai-responses-contracts-BXMcvO7F.d.mts} +4 -10
- package/dist/{openai-responses-contracts-B5mGAbR6.mjs → openai-responses-contracts-xU-n9AJJ.mjs} +36 -37
- package/dist/{openai-responses-endpoint-CfKR6N5f.mjs → openai-responses-endpoint-DCkURKS0.mjs} +55 -8
- package/dist/openai-responses-ev_c6oTy.mjs +89 -0
- package/dist/{openai-responses-payload-policy-BzM52TTH.d.mts → openai-responses-payload-policy-DyE30gdD.d.mts} +7 -7
- package/dist/{openai-responses-request-lifecycle-CTqHc02t.mjs → openai-responses-request-lifecycle-BuOs0mwI.mjs} +12 -26
- package/dist/{openai-responses-shared-wx9v1MCn.mjs → openai-responses-shared-BmRQnUPP.mjs} +633 -1493
- package/dist/{openai-responses-terminal-usage-CpVjkqn-.d.mts → openai-responses-terminal-usage-D7IhRA6i.d.mts} +9 -3
- package/dist/{openai-tool-schema-BTEU2xmN.mjs → openai-tool-schema-CsoYgnWy.mjs} +97 -122
- package/dist/otel-Buswj0Mf.mjs +766 -0
- package/dist/{overflow-OF3PgPbw.mjs → overflow-CpApyjG2.mjs} +1 -1
- package/dist/{positive-integer-Bb4Evc7L.mjs → positive-integer-DiqE5vNi.mjs} +2 -3
- package/dist/{prompt-cache-stability-D_MeCQFI.mjs → prompt-cache-stability-w-ICeyOI.mjs} +1 -1
- package/dist/{provider-error-qtZD2inE.mjs → provider-error-DD-fo4Rz.mjs} +71 -234
- package/dist/{provider-options-DAzsyi49.d.mts → provider-options-Mo8NM5d1.d.mts} +16 -5
- package/dist/{provider-replay-context-4vxI7p4V.mjs → provider-replay-context-xyU7-CiT.mjs} +2 -2
- package/dist/provider-transcript-transform-DtaxNcC1.mjs +32 -0
- package/dist/{provider-transport-turn-state-D_GjPJHe.mjs → provider-transport-turn-state-BIS8maBK.mjs} +4 -4
- package/dist/{provider-types-CWl4VXvE.d.mts → provider-types-B1e98js5.d.mts} +3 -3
- package/dist/provider-types.d.mts +7 -6
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +26 -29
- package/dist/{record-coerce-CNDovvft.mjs → record-coerce-BQaoiN3r.mjs} +4 -1
- package/dist/request-headers-DO4Mqhw1.mjs +10 -0
- package/dist/{required-api-key-D088S4Cd.mjs → required-api-key-2zZTkmsi.mjs} +1 -1
- package/dist/{retry-after-BrmTv0jL.d.mts → retry-after-DnHBlFS2.d.mts} +21 -1
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/{sanitize-unicode-ZqVLLEKC.d.mts → sanitize-unicode-BISmUlUv.d.mts} +2 -2
- package/dist/{simple-options-xJkqrG_E.mjs → simple-options-tLSeECry.mjs} +108 -82
- package/dist/src-BUsVkrNt.mjs +105 -0
- package/dist/{src-CyA0zJnt.mjs → src-CQ7nH2mL.mjs} +4 -7
- package/dist/stable-stringify-CchQEmeA.mjs +84 -0
- package/dist/{stream-C4YDqhFj.mjs → stream-DrtAWu7c.mjs} +2 -6
- package/dist/{stream-first-event-timeout-D_TfJHRJ.mjs → stream-first-event-timeout-B7RcufAV.mjs} +16 -13
- package/dist/{string-coerce-Cj8sqWHx.mjs → string-coerce-BCuWMIrk.mjs} +1 -1
- package/dist/string-normalization-B8TDDBX_.mjs +32 -0
- package/dist/telemetry-CvK1yQg7.mjs +582 -0
- package/dist/{tool-schema-json-projection-B1sTYwfH.mjs → tool-schema-json-projection-BQpiJlXJ.mjs} +53 -69
- package/dist/{transport-stream-shared-lhgkTOz3.mjs → transport-stream-shared-D2uFMhMc.mjs} +177 -93
- package/dist/{transport-stream-shared-8ru8eX4s.d.mts → transport-stream-shared-D3IAU4jn.d.mts} +29 -15
- package/dist/{transport-utils-DwOpuTjL.mjs → transport-utils-Da_39MYi.mjs} +23 -38
- package/dist/transports.d.mts +42 -39
- package/dist/transports.mjs +215 -296
- package/dist/{types-CVYzKrMl.d.mts → types-BVdTf0YV.d.mts} +38 -3
- package/dist/types-Cb3-5WM9.d.mts +1 -0
- package/dist/{types-BXd0kI8-.mjs → types-OVEWUaDh.mjs} +3 -1
- package/dist/types.d.mts +7 -6
- package/dist/types.mjs +7 -5
- package/dist/{validation-9FSkE8T-.mjs → validation-DGXqfvkj.mjs} +45 -27
- package/dist/{validation-BQ5u20Ru.d.mts → validation-QmyD0E5A.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -2
- package/package.json +40 -6
- package/dist/anthropic-lueA8LUg.mjs +0 -221
- package/dist/assistant-output-BnQm3fov.mjs +0 -47
- package/dist/event-stream-CDpFza-M.d.mts +0 -1
- package/dist/index-DSprYWaz.d.mts +0 -185
- package/dist/mistral-CQ7aoWg2.mjs +0 -512
- package/dist/model-request-body-BD5vy4rP.d.mts +0 -17
- package/dist/openai-CiRi-nVE.mjs +0 -20077
- package/dist/openai-completions-transport-DFvSBbUT.mjs +0 -10881
- package/dist/openai-responses-DQsZKUoI.mjs +0 -87
- package/dist/rolldown-runtime-B4iAMlE-.mjs +0 -35
- package/dist/types-CBJthzJX.d.mts +0 -1
- package/dist/ws.LICENSE +0 -20
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
import { OTEL_SERVICE_NAME } from "./otel-Buswj0Mf.mjs";
|
|
2
|
+
import { i as getRegisteredTracerProvider } from "./mistral-CjHkvsqR.mjs";
|
|
3
|
+
import { trace } from "@opentelemetry/api";
|
|
4
|
+
//#region node_modules/.pnpm/@mistralai+mistralai@2.7.0_@opentelemetry+api@1.9.1_@opentelemetry+exporter-trace-otlp-_ef8dce160c897b96339bfd78f5c612fa/node_modules/@mistralai/mistralai/esm/extra/observability/redaction-policies.js
|
|
5
|
+
/**
|
|
6
|
+
* Redaction policies for client-side redaction of telemetry spans.
|
|
7
|
+
*
|
|
8
|
+
* Can be customized through the CallbackRedactionPolicy, or extended by
|
|
9
|
+
* subclassing RedactionPolicy.
|
|
10
|
+
*/
|
|
11
|
+
const DEFAULT_REDACTED_VALUE = "[REDACTED]";
|
|
12
|
+
function defaultRedactionPolicy() {
|
|
13
|
+
return new RegexRedactionPolicy();
|
|
14
|
+
}
|
|
15
|
+
/** Base class for redaction policies. */
|
|
16
|
+
var RedactionPolicy = class {
|
|
17
|
+
/** Return the span name to export. Defaults to unchanged. */
|
|
18
|
+
redactSpanName(name) {
|
|
19
|
+
return name;
|
|
20
|
+
}
|
|
21
|
+
/** Return the status description to export. Defaults to unchanged. */
|
|
22
|
+
redactStatusDescription(description) {
|
|
23
|
+
return description;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const DEFAULT_PII_SECRET_PATTERNS = [
|
|
27
|
+
...[
|
|
28
|
+
/bearer\s+[a-z0-9._-]+/gi,
|
|
29
|
+
/\bgh[pousr]_[A-Za-z0-9_]{20,}\b/g,
|
|
30
|
+
/\bxox[baprs]-[A-Za-z0-9-]{10,}\b/g,
|
|
31
|
+
/\bsk-[A-Za-z0-9]{20,}\b/g,
|
|
32
|
+
/\bAKIA[0-9A-Z]{16}\b/g,
|
|
33
|
+
/\bAIza[0-9A-Za-z_-]{35}\b/g,
|
|
34
|
+
/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/g,
|
|
35
|
+
/-----BEGIN [A-Z ]*PRIVATE KEY-----/g,
|
|
36
|
+
/\b[sr]k_(?:live|test)_[0-9A-Za-z]{10,}\b/g,
|
|
37
|
+
/\bsk-ant-[A-Za-z0-9\-_]{20,}\b/g,
|
|
38
|
+
/\bsk-proj-[A-Za-z0-9\-_]{20,}\b/g,
|
|
39
|
+
/\bhf_[A-Za-z0-9]{30,}\b/g,
|
|
40
|
+
/\bgithub_pat_[A-Za-z0-9_]{22,}\b/g,
|
|
41
|
+
/\bglpat-[A-Za-z0-9\-=_]{20,22}\b/g,
|
|
42
|
+
/\bshp(?:at|ca|pa|ss)_[a-fA-F0-9]{32}\b/g,
|
|
43
|
+
/\bsq0(?:atp|csp|idp)-[0-9A-Za-z\-_]{22,43}\b/g,
|
|
44
|
+
/\bPMAK-[a-zA-Z0-9]{24,59}\b/g,
|
|
45
|
+
/\bphc_[a-zA-Z0-9_]{43}\b/g,
|
|
46
|
+
/\brubygems_[a-f0-9]{48}\b/g,
|
|
47
|
+
/\blin_api_[0-9A-Za-z]{40}\b/g,
|
|
48
|
+
/pypi-AgEIcHlwaS5vcmc[A-Za-z0-9\-_]{50,}/g,
|
|
49
|
+
/\bsecret_[A-Za-z0-9]{43}\b/g,
|
|
50
|
+
/[A-Za-z0-9]{14}\.atlasv1\.[A-Za-z0-9]{60,}/g,
|
|
51
|
+
/\bSG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43}\b/g,
|
|
52
|
+
/\bpk_(?:live|test)_[0-9a-zA-Z]{24}\b/g,
|
|
53
|
+
/https:\/\/hooks\.slack\.com\/services\/[A-Za-z0-9/+]{40,}/g,
|
|
54
|
+
/https:\/\/discord(?:app)?\.com\/api\/webhooks\/[0-9]{17,}\/[A-Za-z0-9\-_]{60,}/g,
|
|
55
|
+
/https:\/\/hooks\.zapier\.com\/hooks\/catch\/[A-Za-z0-9/]{16,}/g
|
|
56
|
+
],
|
|
57
|
+
/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g,
|
|
58
|
+
/\b(?:\d[ -]?){13,16}\b/g,
|
|
59
|
+
/\b(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)\b/g
|
|
60
|
+
];
|
|
61
|
+
/**
|
|
62
|
+
* Content-oriented policy based on regexes.
|
|
63
|
+
*
|
|
64
|
+
* This is the default policy. Leaves keys and structure intact, scans string
|
|
65
|
+
* values and redacts matched substrings. Fewer false positives than
|
|
66
|
+
* AttributeRedactionPolicy and aims to preserve observability value; may miss
|
|
67
|
+
* free-form PII or secrets not in the default patterns.
|
|
68
|
+
*/
|
|
69
|
+
var RegexRedactionPolicy = class extends RedactionPolicy {
|
|
70
|
+
patterns;
|
|
71
|
+
redactedValue;
|
|
72
|
+
constructor(patterns = DEFAULT_PII_SECRET_PATTERNS, options = {}) {
|
|
73
|
+
super();
|
|
74
|
+
this.patterns = patterns;
|
|
75
|
+
this.redactedValue = options.redactedValue ?? "[REDACTED]";
|
|
76
|
+
}
|
|
77
|
+
redactAttributes(attributes) {
|
|
78
|
+
const redacted = {};
|
|
79
|
+
if (attributes == null) return redacted;
|
|
80
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
81
|
+
if (value === void 0) continue;
|
|
82
|
+
redacted[key] = redactValue(value, this.patterns, this.redactedValue);
|
|
83
|
+
}
|
|
84
|
+
return redacted;
|
|
85
|
+
}
|
|
86
|
+
redactSpanName(name) {
|
|
87
|
+
return redactText(name, this.patterns, this.redactedValue);
|
|
88
|
+
}
|
|
89
|
+
redactStatusDescription(description) {
|
|
90
|
+
if (description == null) return description;
|
|
91
|
+
return redactText(description, this.patterns, this.redactedValue);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Callback-based policy for users to provide custom redaction capabilities.
|
|
96
|
+
*
|
|
97
|
+
* The callback is invoked per attribute and should return the value to keep or
|
|
98
|
+
* `undefined` to drop the attribute. Span name and status description are left
|
|
99
|
+
* unchanged (the callback operates on attributes only).
|
|
100
|
+
*/
|
|
101
|
+
var CallbackRedactionPolicy = class extends RedactionPolicy {
|
|
102
|
+
maskFunction;
|
|
103
|
+
constructor(maskFunction) {
|
|
104
|
+
super();
|
|
105
|
+
this.maskFunction = maskFunction;
|
|
106
|
+
}
|
|
107
|
+
redactAttributes(attributes) {
|
|
108
|
+
const redacted = {};
|
|
109
|
+
if (attributes == null) return redacted;
|
|
110
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
111
|
+
if (value === void 0) continue;
|
|
112
|
+
const masked = this.maskFunction(key, value);
|
|
113
|
+
if (masked === void 0) continue;
|
|
114
|
+
redacted[key] = masked;
|
|
115
|
+
}
|
|
116
|
+
return redacted;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
function redactValue(value, patterns, redactedValue = DEFAULT_REDACTED_VALUE) {
|
|
120
|
+
return redactValueCounting(value, patterns, redactedValue)[0];
|
|
121
|
+
}
|
|
122
|
+
function redactValueCounting(value, patterns, redactedValue = DEFAULT_REDACTED_VALUE) {
|
|
123
|
+
if (typeof value === "string") return redactTextCounting(value, patterns, redactedValue);
|
|
124
|
+
if (Array.isArray(value)) {
|
|
125
|
+
let total = 0;
|
|
126
|
+
return [value.map((item) => {
|
|
127
|
+
if (typeof item === "string") {
|
|
128
|
+
const [redactedItem, count] = redactTextCounting(item, patterns, redactedValue);
|
|
129
|
+
total += count;
|
|
130
|
+
return redactedItem;
|
|
131
|
+
}
|
|
132
|
+
return item;
|
|
133
|
+
}), total];
|
|
134
|
+
}
|
|
135
|
+
return [value, 0];
|
|
136
|
+
}
|
|
137
|
+
function redactText(text, patterns, redactedValue = DEFAULT_REDACTED_VALUE) {
|
|
138
|
+
return redactTextCounting(text, patterns, redactedValue)[0];
|
|
139
|
+
}
|
|
140
|
+
function redactTextCounting(text, patterns, redactedValue = DEFAULT_REDACTED_VALUE) {
|
|
141
|
+
let redacted = text;
|
|
142
|
+
let total = 0;
|
|
143
|
+
for (const pattern of patterns) redacted = redacted.replace(pattern, () => {
|
|
144
|
+
total += 1;
|
|
145
|
+
return redactedValue;
|
|
146
|
+
});
|
|
147
|
+
return [redacted, total];
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region node_modules/.pnpm/@mistralai+mistralai@2.7.0_@opentelemetry+api@1.9.1_@opentelemetry+exporter-trace-otlp-_ef8dce160c897b96339bfd78f5c612fa/node_modules/@mistralai/mistralai/esm/extra/observability/redaction.js
|
|
151
|
+
/**
|
|
152
|
+
* Client-side redaction of telemetry spans before they are exported.
|
|
153
|
+
*
|
|
154
|
+
* This module provides a configurable, export-time masking layer for
|
|
155
|
+
* OpenTelemetry spans so PII/secrets never leave the client. It is the primary,
|
|
156
|
+
* reusable primitive: any OTEL application can wrap the exporter it owns with
|
|
157
|
+
* `RedactingSpanExporter`, and the Mistral SDK installs it automatically in
|
|
158
|
+
* dedicated telemetry mode (see `configureTelemetry`). Several redaction
|
|
159
|
+
* policies are implemented in `redaction-policies.ts`.
|
|
160
|
+
*
|
|
161
|
+
* The module stays importable without the optional OpenTelemetry SDK: it only
|
|
162
|
+
* manipulates plain objects and delegates the actual export to the wrapped
|
|
163
|
+
* exporter. Structural types are used instead of importing
|
|
164
|
+
* `@opentelemetry/sdk-trace-base` so no extra dependency is required to import.
|
|
165
|
+
*/
|
|
166
|
+
/**
|
|
167
|
+
* Resolve a redaction setting into a policy, or `undefined` to disable
|
|
168
|
+
* redaction. `true` yields the default policy, `false` disables redaction
|
|
169
|
+
* entirely, and a policy or `(key, value) => value | undefined` callback is used
|
|
170
|
+
* as-is.
|
|
171
|
+
*/
|
|
172
|
+
function resolveRedaction(redaction) {
|
|
173
|
+
if (redaction === false) return;
|
|
174
|
+
if (redaction === true) return defaultRedactionPolicy();
|
|
175
|
+
return resolvePolicy(redaction);
|
|
176
|
+
}
|
|
177
|
+
function resolvePolicy(policy) {
|
|
178
|
+
if (policy == null) return defaultRedactionPolicy();
|
|
179
|
+
if (policy instanceof RedactionPolicy) return policy;
|
|
180
|
+
if (typeof policy === "function") return new CallbackRedactionPolicy(policy);
|
|
181
|
+
throw new TypeError(`redaction policy must be a RedactionPolicy, a callable, or undefined; got ${typeof policy}.`);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Wrap any `SpanExporter` to redact spans before delegating export.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* const exporter = new RedactingSpanExporter(new OTLPTraceExporter());
|
|
189
|
+
* provider.addSpanProcessor(new BatchSpanProcessor(exporter));
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
var RedactingSpanExporter = class {
|
|
193
|
+
exporter;
|
|
194
|
+
policy;
|
|
195
|
+
constructor(exporter, policy) {
|
|
196
|
+
this.exporter = exporter;
|
|
197
|
+
this.policy = resolvePolicy(policy);
|
|
198
|
+
}
|
|
199
|
+
export(spans, resultCallback) {
|
|
200
|
+
const redacted = spans.map((span) => redactSpan(span, this.policy));
|
|
201
|
+
this.exporter.export(redacted, resultCallback);
|
|
202
|
+
}
|
|
203
|
+
shutdown() {
|
|
204
|
+
return this.exporter.shutdown();
|
|
205
|
+
}
|
|
206
|
+
forceFlush() {
|
|
207
|
+
return this.exporter.forceFlush?.() ?? Promise.resolve();
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* Define an own data property on `target`, shadowing the prototype. Plain
|
|
212
|
+
* assignment (`target.key = value`) fails when the prototype exposes `key` as a
|
|
213
|
+
* getter-only accessor (e.g. OpenTelemetry's `Resource.attributes`), so we
|
|
214
|
+
* always define the override explicitly.
|
|
215
|
+
*/
|
|
216
|
+
function overrideProperty(target, key, value) {
|
|
217
|
+
Object.defineProperty(target, key, {
|
|
218
|
+
value,
|
|
219
|
+
enumerable: true,
|
|
220
|
+
configurable: true,
|
|
221
|
+
writable: true
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Shallow-clone an object, keeping its prototype and copying every own field as
|
|
226
|
+
* an own property.
|
|
227
|
+
*/
|
|
228
|
+
function shallowClone(source) {
|
|
229
|
+
return Object.create(Object.getPrototypeOf(source), Object.getOwnPropertyDescriptors(source));
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Return a redacted clone of a span: same prototype, every own field copied, so
|
|
233
|
+
* untouched fields survive exporters that spread or enumerate it ({...span},
|
|
234
|
+
* Object.keys). Only the sensitive surface is overridden.
|
|
235
|
+
*/
|
|
236
|
+
function redactSpan(span, policy) {
|
|
237
|
+
const redacted = shallowClone(span);
|
|
238
|
+
overrideProperty(redacted, "name", policy.redactSpanName(span.name));
|
|
239
|
+
overrideProperty(redacted, "attributes", policy.redactAttributes(span.attributes));
|
|
240
|
+
overrideProperty(redacted, "events", redactEvents(span.events, policy));
|
|
241
|
+
overrideProperty(redacted, "links", redactLinks(span.links, policy));
|
|
242
|
+
overrideProperty(redacted, "resource", redactResource(span.resource, policy));
|
|
243
|
+
overrideProperty(redacted, "status", redactStatus(span.status, policy));
|
|
244
|
+
return redacted;
|
|
245
|
+
}
|
|
246
|
+
function redactEvents(events, policy) {
|
|
247
|
+
if (events == null) return [];
|
|
248
|
+
return events.map((event) => {
|
|
249
|
+
const redacted = shallowClone(event);
|
|
250
|
+
overrideProperty(redacted, "attributes", policy.redactAttributes(event.attributes));
|
|
251
|
+
return redacted;
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
function redactLinks(links, policy) {
|
|
255
|
+
if (links == null) return [];
|
|
256
|
+
return links.map((link) => {
|
|
257
|
+
const redacted = shallowClone(link);
|
|
258
|
+
overrideProperty(redacted, "attributes", policy.redactAttributes(link.attributes));
|
|
259
|
+
return redacted;
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
function redactResource(resource, policy) {
|
|
263
|
+
if (resource == null) return resource;
|
|
264
|
+
const redacted = shallowClone(resource);
|
|
265
|
+
overrideProperty(redacted, "attributes", policy.redactAttributes(resource.attributes));
|
|
266
|
+
return redacted;
|
|
267
|
+
}
|
|
268
|
+
function redactStatus(status, policy) {
|
|
269
|
+
if (status == null) return status;
|
|
270
|
+
const message = policy.redactStatusDescription(status.message);
|
|
271
|
+
const redacted = { code: status.code };
|
|
272
|
+
if (message !== void 0) redacted.message = message;
|
|
273
|
+
return redacted;
|
|
274
|
+
}
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region node_modules/.pnpm/@mistralai+mistralai@2.7.0_@opentelemetry+api@1.9.1_@opentelemetry+exporter-trace-otlp-_ef8dce160c897b96339bfd78f5c612fa/node_modules/@mistralai/mistralai/esm/extra/observability/telemetry.js
|
|
277
|
+
const MISTRAL_SDK_TELEMETRY_ENV = "MISTRAL_SDK_TELEMETRY";
|
|
278
|
+
const MISTRAL_TELEMETRY_BASE_URL = "https://api.mistral.ai";
|
|
279
|
+
const MISTRAL_TELEMETRY_TRACES_PATH = "/telemetry/v1/traces";
|
|
280
|
+
const MISTRAL_TELEMETRY_ENDPOINT = createTelemetryEndpoint(MISTRAL_TELEMETRY_BASE_URL);
|
|
281
|
+
const MISTRAL_OTLP_TRACES_ENDPOINT_ENV = "MISTRAL_OTLP_TRACES_ENDPOINT";
|
|
282
|
+
const TELEMETRY_PROVIDER_DEDICATED = "dedicated";
|
|
283
|
+
const TELEMETRY_PROVIDER_GLOBAL = "global";
|
|
284
|
+
const DISABLED_VALUE = "false";
|
|
285
|
+
var TelemetryConfigurationError = class extends Error {
|
|
286
|
+
constructor(message) {
|
|
287
|
+
super(message);
|
|
288
|
+
this.name = "TelemetryConfigurationError";
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
async function configureTelemetry(client, provider = TELEMETRY_PROVIDER_DEDICATED, options = {}) {
|
|
292
|
+
const hook = getTracingHook(client);
|
|
293
|
+
const redaction = options.redaction;
|
|
294
|
+
if (typeof provider === "string") {
|
|
295
|
+
const providerMode = resolveProviderMode(provider);
|
|
296
|
+
if (providerMode === "global") {
|
|
297
|
+
warnRedactionIgnored(redaction, TELEMETRY_PROVIDER_GLOBAL);
|
|
298
|
+
return useGlobalTracerProvider(hook, { replaceExisting: true });
|
|
299
|
+
}
|
|
300
|
+
return configureTelemetryForHook(hook, {
|
|
301
|
+
baseURL: client._baseURL,
|
|
302
|
+
options: client._options
|
|
303
|
+
}, {
|
|
304
|
+
telemetry: providerMode,
|
|
305
|
+
replaceExisting: true,
|
|
306
|
+
redaction
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
warnRedactionIgnored(redaction, "custom");
|
|
310
|
+
markTelemetryConfigurationChanged(hook);
|
|
311
|
+
await attachCustomTracerProvider(hook, provider);
|
|
312
|
+
return true;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Redaction is applied only in dedicated provider mode, where the SDK owns the
|
|
316
|
+
* exporter. In global/custom modes the application owns the export pipeline, so
|
|
317
|
+
* the argument is ignored. Because redaction is on by default, warn (unless it
|
|
318
|
+
* was explicitly disabled) so callers know their spans are not redacted here and
|
|
319
|
+
* that they must wrap their own exporter with `RedactingSpanExporter`.
|
|
320
|
+
*/
|
|
321
|
+
function warnRedactionIgnored(redaction, mode) {
|
|
322
|
+
if (redaction === false) return;
|
|
323
|
+
warnLog(`Telemetry redaction is only applied in 'dedicated' provider mode, where the Mistral SDK owns the exporter. In '${mode}' mode the application owns the export pipeline; wrap your exporter with RedactingSpanExporter to redact spans. Ignoring the redaction argument.`);
|
|
324
|
+
}
|
|
325
|
+
async function setTracerProvider(client, provider) {
|
|
326
|
+
return configureTelemetry(client, provider);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Flush the SDK-owned telemetry provider attached to `client` without shutting
|
|
330
|
+
* it down or detaching it.
|
|
331
|
+
*
|
|
332
|
+
* This is a no-op when dedicated telemetry is not configured. In global/custom
|
|
333
|
+
* provider modes the application owns the provider lifecycle. Rejections from
|
|
334
|
+
* the SDK-owned provider's `forceFlush()` are propagated to the caller.
|
|
335
|
+
*/
|
|
336
|
+
async function flushTelemetry(client) {
|
|
337
|
+
await getTracingHook(client)._autoTelemetryProvider?.forceFlush?.();
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Flush and shut down the SDK-owned telemetry provider attached to `client`.
|
|
341
|
+
*
|
|
342
|
+
* In dedicated mode the SDK owns a BatchSpanProcessor that buffers spans and
|
|
343
|
+
* only exports them on a timer or on shutdown. Node has no reliable async exit
|
|
344
|
+
* hook to flush automatically (unlike Python's finalizer), so short-lived
|
|
345
|
+
* programs must call this before exiting or their buffered spans are dropped.
|
|
346
|
+
* In global/custom provider modes the application owns the export pipeline, so
|
|
347
|
+
* this is a no-op.
|
|
348
|
+
*/
|
|
349
|
+
async function shutdownTelemetry(client) {
|
|
350
|
+
await shutdownTelemetryProvider(getTracingHook(client));
|
|
351
|
+
}
|
|
352
|
+
function getTelemetryTracer(client, name, version, options) {
|
|
353
|
+
return getClientTracerProvider(getTracingHook(client), resolveMistralTelemetryEnv() === TELEMETRY_PROVIDER_GLOBAL).getTracer(name, version, options);
|
|
354
|
+
}
|
|
355
|
+
async function configureTelemetryForHook(hook, context, options = {}) {
|
|
356
|
+
const telemetryOverride = options.telemetry;
|
|
357
|
+
const hasTelemetryOverride = telemetryOverride != null;
|
|
358
|
+
const replaceExisting = options.replaceExisting === true;
|
|
359
|
+
if (!hasTelemetryOverride && hasConfiguredAutoTelemetry(hook)) return true;
|
|
360
|
+
if (!hasTelemetryOverride && hook._telemetryAutoDisabled) return false;
|
|
361
|
+
const providerMode = hasTelemetryOverride ? resolveTelemetryMode(telemetryOverride) : resolveMistralTelemetryEnv();
|
|
362
|
+
if (hook._telemetryInitialization !== void 0) {
|
|
363
|
+
if (!replaceExisting && providerMode === "dedicated") return hook._telemetryInitialization;
|
|
364
|
+
try {
|
|
365
|
+
await hook._telemetryInitialization;
|
|
366
|
+
} catch {}
|
|
367
|
+
}
|
|
368
|
+
if (providerMode == null) {
|
|
369
|
+
markTelemetryConfigurationChanged(hook);
|
|
370
|
+
await shutdownTelemetryProvider(hook);
|
|
371
|
+
markAutoTelemetryDisabled(hook);
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
if (providerMode === "global") return useGlobalTracerProvider(hook, { replaceExisting: replaceExisting || hasTelemetryOverride });
|
|
375
|
+
if (hook._autoTelemetryProvider !== void 0) return true;
|
|
376
|
+
if (hook.tracerProvider !== void 0) {
|
|
377
|
+
if (!replaceExisting) return false;
|
|
378
|
+
hook.tracerProvider = void 0;
|
|
379
|
+
}
|
|
380
|
+
if (getRegisteredTracerProvider() !== void 0 && !replaceExisting) return false;
|
|
381
|
+
const initialization = initializeTelemetryProvider(hook, context, options, markTelemetryConfigurationChanged(hook));
|
|
382
|
+
hook._telemetryInitialization = initialization;
|
|
383
|
+
try {
|
|
384
|
+
return await initialization;
|
|
385
|
+
} finally {
|
|
386
|
+
if (hook._telemetryInitialization === initialization) hook._telemetryInitialization = void 0;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
async function initializeTelemetryProvider(hook, context, options, configurationVersion) {
|
|
390
|
+
const provider = await (options.createTelemetryTracerProvider ?? _createTelemetryTracerProvider)({
|
|
391
|
+
apiKey: await resolveApiKey(context),
|
|
392
|
+
baseURL: context.baseURL ?? context.options?.serverURL,
|
|
393
|
+
redaction: options.redaction
|
|
394
|
+
});
|
|
395
|
+
if (hook._telemetryConfigurationVersion !== configurationVersion) {
|
|
396
|
+
await provider.shutdown?.();
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
await attachTelemetryProvider(hook, provider);
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
async function _createTelemetryTracerProvider(options) {
|
|
403
|
+
if (options.apiKey == null || options.apiKey === "") throw new TelemetryConfigurationError("Mistral telemetry requires an API key. Pass apiKey to the client or set MISTRAL_API_KEY.");
|
|
404
|
+
const moduleLoader = options.moduleLoader ?? loadModule;
|
|
405
|
+
let sdkTraceBase;
|
|
406
|
+
let otlpExporterModule;
|
|
407
|
+
let resourcesModule;
|
|
408
|
+
try {
|
|
409
|
+
[sdkTraceBase, otlpExporterModule, resourcesModule] = await Promise.all([
|
|
410
|
+
moduleLoader("@opentelemetry/sdk-trace-base"),
|
|
411
|
+
moduleLoader("@opentelemetry/exporter-trace-otlp-http"),
|
|
412
|
+
moduleLoader("@opentelemetry/resources")
|
|
413
|
+
]);
|
|
414
|
+
} catch {
|
|
415
|
+
throw new TelemetryConfigurationError("Mistral telemetry requires optional OpenTelemetry SDK/exporter dependencies. Install @opentelemetry/sdk-trace-base, @opentelemetry/exporter-trace-otlp-http, and @opentelemetry/resources with your package manager.");
|
|
416
|
+
}
|
|
417
|
+
const BasicTracerProvider = requireExportConstructor(sdkTraceBase, "BasicTracerProvider", "@opentelemetry/sdk-trace-base");
|
|
418
|
+
const BatchSpanProcessor = requireExportConstructor(sdkTraceBase, "BatchSpanProcessor", "@opentelemetry/sdk-trace-base");
|
|
419
|
+
const exporter = new (requireExportConstructor(otlpExporterModule, "OTLPTraceExporter", "@opentelemetry/exporter-trace-otlp-http"))({
|
|
420
|
+
url: resolveMistralTelemetryEndpoint(options.baseURL),
|
|
421
|
+
headers: { Authorization: asBearerToken(options.apiKey) }
|
|
422
|
+
});
|
|
423
|
+
const policy = resolveRedaction(options.redaction ?? true);
|
|
424
|
+
const spanProcessor = new BatchSpanProcessor(policy ? new RedactingSpanExporter(exporter, policy) : exporter);
|
|
425
|
+
const resource = createResource(resourcesModule, { "service.name": OTEL_SERVICE_NAME });
|
|
426
|
+
const provider = new BasicTracerProvider({ resource });
|
|
427
|
+
if (typeof provider.addSpanProcessor === "function") {
|
|
428
|
+
provider.addSpanProcessor(spanProcessor);
|
|
429
|
+
return provider;
|
|
430
|
+
}
|
|
431
|
+
return new BasicTracerProvider({
|
|
432
|
+
resource,
|
|
433
|
+
spanProcessors: [spanProcessor]
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
function getTracingHook(client) {
|
|
437
|
+
const beforeRequestHooks = (client._options?.hooks)?.beforeRequestHooks;
|
|
438
|
+
if (!Array.isArray(beforeRequestHooks)) throw new Error("Cannot configure telemetry: SDK hooks not initialised.");
|
|
439
|
+
const hook = beforeRequestHooks.find(isTelemetryCapableTracingHook);
|
|
440
|
+
if (hook === void 0) throw new Error("Cannot configure telemetry: TracingHook not found in the client's hooks.");
|
|
441
|
+
return hook;
|
|
442
|
+
}
|
|
443
|
+
function isTelemetryCapableTracingHook(hook) {
|
|
444
|
+
return Boolean(hook && typeof hook === "object" && hook._mistralTracingHook === true);
|
|
445
|
+
}
|
|
446
|
+
function getClientTracerProvider(hook, usesGlobalProvider) {
|
|
447
|
+
if (hook.tracerProvider !== void 0) return hook.tracerProvider;
|
|
448
|
+
if (!usesGlobalProvider && !hook._telemetryUseGlobalProvider) {
|
|
449
|
+
const registeredProvider = getRegisteredTracerProvider();
|
|
450
|
+
if (registeredProvider !== void 0) return registeredProvider;
|
|
451
|
+
}
|
|
452
|
+
return trace.getTracerProvider();
|
|
453
|
+
}
|
|
454
|
+
function resolveTelemetryMode(value) {
|
|
455
|
+
if (typeof value === "boolean") return value ? TELEMETRY_PROVIDER_DEDICATED : null;
|
|
456
|
+
switch (value.trim().toLowerCase()) {
|
|
457
|
+
case TELEMETRY_PROVIDER_DEDICATED: return TELEMETRY_PROVIDER_DEDICATED;
|
|
458
|
+
case TELEMETRY_PROVIDER_GLOBAL: return TELEMETRY_PROVIDER_GLOBAL;
|
|
459
|
+
case DISABLED_VALUE: return null;
|
|
460
|
+
}
|
|
461
|
+
throw new TelemetryConfigurationError(`Invalid telemetry setting ${JSON.stringify(value)}. Expected one of: dedicated, false, global.`);
|
|
462
|
+
}
|
|
463
|
+
function resolveProviderMode(value) {
|
|
464
|
+
switch (value.trim().toLowerCase()) {
|
|
465
|
+
case TELEMETRY_PROVIDER_DEDICATED: return TELEMETRY_PROVIDER_DEDICATED;
|
|
466
|
+
case TELEMETRY_PROVIDER_GLOBAL: return TELEMETRY_PROVIDER_GLOBAL;
|
|
467
|
+
}
|
|
468
|
+
throw new TelemetryConfigurationError(`Invalid telemetry provider ${JSON.stringify(value)}. Expected one of: dedicated, global.`);
|
|
469
|
+
}
|
|
470
|
+
function resolveMistralTelemetryEnv() {
|
|
471
|
+
const envValue = readEnv(MISTRAL_SDK_TELEMETRY_ENV);
|
|
472
|
+
if (envValue == null || envValue === "") return null;
|
|
473
|
+
try {
|
|
474
|
+
return resolveTelemetryMode(envValue);
|
|
475
|
+
} catch {
|
|
476
|
+
throw new TelemetryConfigurationError(`Invalid ${MISTRAL_SDK_TELEMETRY_ENV}=${JSON.stringify(envValue)}. Expected one of: dedicated, false, global.`);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
async function resolveApiKey(context) {
|
|
480
|
+
const authHeader = context.resolvedSecurity?.headers?.["Authorization"];
|
|
481
|
+
if (authHeader) return authHeader;
|
|
482
|
+
const apiKey = await resolveApiKeySource(context.options?.apiKey);
|
|
483
|
+
if (apiKey) return apiKey;
|
|
484
|
+
const envApiKey = readEnv("MISTRAL_API_KEY");
|
|
485
|
+
if (envApiKey) return envApiKey;
|
|
486
|
+
throw new TelemetryConfigurationError("Mistral telemetry requires an API key. Pass apiKey to the client or set MISTRAL_API_KEY.");
|
|
487
|
+
}
|
|
488
|
+
async function resolveApiKeySource(source) {
|
|
489
|
+
if (source == null) return;
|
|
490
|
+
return typeof source === "function" ? source() : source;
|
|
491
|
+
}
|
|
492
|
+
function resolveMistralTelemetryEndpoint(baseURL) {
|
|
493
|
+
const endpoint = readEnv(MISTRAL_OTLP_TRACES_ENDPOINT_ENV)?.trim();
|
|
494
|
+
if (endpoint) return endpoint;
|
|
495
|
+
if (baseURL != null && `${baseURL}`.trim() !== "") return createTelemetryEndpoint(baseURL);
|
|
496
|
+
return MISTRAL_TELEMETRY_ENDPOINT;
|
|
497
|
+
}
|
|
498
|
+
function createTelemetryEndpoint(baseURL) {
|
|
499
|
+
return new URL(MISTRAL_TELEMETRY_TRACES_PATH, baseURL).toString();
|
|
500
|
+
}
|
|
501
|
+
async function attachTelemetryProvider(hook, provider) {
|
|
502
|
+
await shutdownTelemetryProvider(hook);
|
|
503
|
+
hook.tracerProvider = provider;
|
|
504
|
+
hook._autoTelemetryProvider = provider;
|
|
505
|
+
hook._telemetryUseGlobalProvider = false;
|
|
506
|
+
hook._telemetryAutoDisabled = false;
|
|
507
|
+
}
|
|
508
|
+
function hasConfiguredAutoTelemetry(hook) {
|
|
509
|
+
return hook._autoTelemetryProvider !== void 0 || hook._telemetryUseGlobalProvider;
|
|
510
|
+
}
|
|
511
|
+
function markAutoTelemetryDisabled(hook) {
|
|
512
|
+
hook._telemetryUseGlobalProvider = false;
|
|
513
|
+
hook._telemetryAutoDisabled = true;
|
|
514
|
+
}
|
|
515
|
+
function markTelemetryConfigurationChanged(hook) {
|
|
516
|
+
hook._telemetryConfigurationVersion += 1;
|
|
517
|
+
return hook._telemetryConfigurationVersion;
|
|
518
|
+
}
|
|
519
|
+
async function attachCustomTracerProvider(hook, provider) {
|
|
520
|
+
await shutdownTelemetryProvider(hook);
|
|
521
|
+
hook.tracerProvider = provider;
|
|
522
|
+
hook._telemetryUseGlobalProvider = false;
|
|
523
|
+
hook._telemetryAutoDisabled = false;
|
|
524
|
+
}
|
|
525
|
+
async function useGlobalTracerProvider(hook, options) {
|
|
526
|
+
if (hook.tracerProvider !== void 0 && hook._autoTelemetryProvider === void 0 && !options.replaceExisting) return false;
|
|
527
|
+
markTelemetryConfigurationChanged(hook);
|
|
528
|
+
await shutdownTelemetryProvider(hook);
|
|
529
|
+
hook.tracerProvider = void 0;
|
|
530
|
+
hook._telemetryUseGlobalProvider = true;
|
|
531
|
+
hook._telemetryAutoDisabled = true;
|
|
532
|
+
return true;
|
|
533
|
+
}
|
|
534
|
+
async function shutdownTelemetryProvider(hook) {
|
|
535
|
+
const provider = hook._autoTelemetryProvider;
|
|
536
|
+
if (provider === void 0) return;
|
|
537
|
+
hook._autoTelemetryProvider = void 0;
|
|
538
|
+
if (hook.tracerProvider === provider) hook.tracerProvider = void 0;
|
|
539
|
+
await provider.shutdown?.();
|
|
540
|
+
}
|
|
541
|
+
function asBearerToken(apiKey) {
|
|
542
|
+
return apiKey.toLowerCase().startsWith("bearer ") ? apiKey : `Bearer ${apiKey}`;
|
|
543
|
+
}
|
|
544
|
+
function readEnv(name) {
|
|
545
|
+
try {
|
|
546
|
+
const denoValue = (globalThis.Deno?.env)?.get?.(name);
|
|
547
|
+
if (denoValue !== void 0) return denoValue;
|
|
548
|
+
} catch {}
|
|
549
|
+
try {
|
|
550
|
+
return globalThis.process?.env?.[name];
|
|
551
|
+
} catch {
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
function warnLog(message) {
|
|
556
|
+
try {
|
|
557
|
+
globalThis.console?.warn?.(message);
|
|
558
|
+
} catch {}
|
|
559
|
+
}
|
|
560
|
+
async function loadModule(specifier) {
|
|
561
|
+
return await import(
|
|
562
|
+
/* webpackIgnore: true */
|
|
563
|
+
/* turbopackIgnore: true */
|
|
564
|
+
/* @vite-ignore */
|
|
565
|
+
specifier
|
|
566
|
+
);
|
|
567
|
+
}
|
|
568
|
+
function requireExportConstructor(moduleExports, exportName, moduleName) {
|
|
569
|
+
const value = moduleExports[exportName];
|
|
570
|
+
if (typeof value !== "function") throw new TelemetryConfigurationError(`Mistral telemetry expected ${moduleName} to export ${exportName}.`);
|
|
571
|
+
return value;
|
|
572
|
+
}
|
|
573
|
+
function createResource(moduleExports, attributes) {
|
|
574
|
+
const resourceFromAttributes = moduleExports["resourceFromAttributes"];
|
|
575
|
+
if (typeof resourceFromAttributes === "function") return resourceFromAttributes(attributes);
|
|
576
|
+
const Resource = moduleExports["Resource"];
|
|
577
|
+
if (typeof Resource !== "function") return { attributes };
|
|
578
|
+
const resource = new Resource(attributes);
|
|
579
|
+
return (Resource.default?.())?.merge?.(resource) ?? resource;
|
|
580
|
+
}
|
|
581
|
+
//#endregion
|
|
582
|
+
export { MISTRAL_OTLP_TRACES_ENDPOINT_ENV, MISTRAL_SDK_TELEMETRY_ENV, MISTRAL_TELEMETRY_BASE_URL, MISTRAL_TELEMETRY_ENDPOINT, MISTRAL_TELEMETRY_TRACES_PATH, TELEMETRY_PROVIDER_DEDICATED, TELEMETRY_PROVIDER_GLOBAL, TelemetryConfigurationError, _createTelemetryTracerProvider, configureTelemetry, configureTelemetryForHook, flushTelemetry, getTelemetryTracer, setTracerProvider, shutdownTelemetry };
|