@use-lattice/litmus 0.121.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/dist/src/accounts-Bt1oJb1Z.cjs +219 -0
- package/dist/src/accounts-DjOU8Rm3.js +178 -0
- package/dist/src/agentic-utils-D03IiXQc.js +153 -0
- package/dist/src/agentic-utils-Dh7xaMQM.cjs +180 -0
- package/dist/src/agents-C6BIMlZa.js +231 -0
- package/dist/src/agents-DvIpNX1L.cjs +666 -0
- package/dist/src/agents-ZP0RP9vV.cjs +231 -0
- package/dist/src/agents-maJXdjbR.js +665 -0
- package/dist/src/aimlapi-BTbQjG2E.cjs +30 -0
- package/dist/src/aimlapi-CwMxqfXP.js +30 -0
- package/dist/src/audio-BBUdvsde.cjs +97 -0
- package/dist/src/audio-D5DPZ7I-.js +97 -0
- package/dist/src/base-BEysXrkq.cjs +222 -0
- package/dist/src/base-C451JQfq.js +193 -0
- package/dist/src/blobs-BY8MDmpo.js +230 -0
- package/dist/src/blobs-BgcNn97m.cjs +256 -0
- package/dist/src/cache-BBE_lsTA.cjs +4 -0
- package/dist/src/cache-BkrqU5Ba.js +237 -0
- package/dist/src/cache-DsCxFlsZ.cjs +297 -0
- package/dist/src/chat-CPJWDP6a.cjs +289 -0
- package/dist/src/chat-CXX3xzkk.cjs +811 -0
- package/dist/src/chat-CcDgZFJ4.js +787 -0
- package/dist/src/chat-Dz5ZeGO2.js +289 -0
- package/dist/src/chatkit-Dw0mKkML.cjs +1158 -0
- package/dist/src/chatkit-swAIVuea.js +1157 -0
- package/dist/src/chunk-DEq-mXcV.js +15 -0
- package/dist/src/claude-agent-sdk-BXZJtOg6.js +379 -0
- package/dist/src/claude-agent-sdk-CkfyjDoG.cjs +383 -0
- package/dist/src/cloudflare-ai-BzpJcqUH.js +161 -0
- package/dist/src/cloudflare-ai-Cmy_R1y2.cjs +161 -0
- package/dist/src/cloudflare-gateway-B9tVQKok.cjs +272 -0
- package/dist/src/cloudflare-gateway-DrD3ew3H.js +272 -0
- package/dist/src/codex-sdk-Dezj9Nwm.js +1056 -0
- package/dist/src/codex-sdk-Dl9D4k5B.cjs +1060 -0
- package/dist/src/cometapi-C-9YvCHC.js +54 -0
- package/dist/src/cometapi-DHgDKoO2.cjs +54 -0
- package/dist/src/completion-B8Ctyxpr.js +120 -0
- package/dist/src/completion-Cxrt08sj.cjs +131 -0
- package/dist/src/createHash-BwgE13yv.cjs +27 -0
- package/dist/src/createHash-DmPQkvBh.js +15 -0
- package/dist/src/docker-BiqcTwLv.js +80 -0
- package/dist/src/docker-C7tEJnP-.cjs +80 -0
- package/dist/src/esm-C62Zofr1.cjs +409 -0
- package/dist/src/esm-DMVc93eh.js +379 -0
- package/dist/src/evalResult-C3NJPQOo.cjs +301 -0
- package/dist/src/evalResult-C7JJAPBb.js +295 -0
- package/dist/src/evalResult-DoVTZZWI.cjs +2 -0
- package/dist/src/extractor-DnMD3fwt.cjs +391 -0
- package/dist/src/extractor-DtlL28vL.js +374 -0
- package/dist/src/fetch-BTxakTSg.cjs +1133 -0
- package/dist/src/fetch-DQckpUFz.js +928 -0
- package/dist/src/fileExtensions-DnqA1y9x.js +85 -0
- package/dist/src/fileExtensions-bYh77CN8.cjs +114 -0
- package/dist/src/genaiTracer-CyZrmaK0.cjs +268 -0
- package/dist/src/genaiTracer-D3fD9dNV.js +256 -0
- package/dist/src/graders-BNscxFrU.js +13644 -0
- package/dist/src/graders-D2oE9Msq.js +2 -0
- package/dist/src/graders-c0Ez_w-9.cjs +2 -0
- package/dist/src/graders-d0F2M3e9.cjs +14056 -0
- package/dist/src/image-0ZhE0VlR.cjs +280 -0
- package/dist/src/image-CWE1pdNv.js +257 -0
- package/dist/src/image-D9ZK6hwL.js +163 -0
- package/dist/src/image-DKZgZITg.cjs +163 -0
- package/dist/src/index.cjs +11366 -0
- package/dist/src/index.d.cts +19640 -0
- package/dist/src/index.d.ts +19641 -0
- package/dist/src/index.js +11306 -0
- package/dist/src/invariant-Ddh24eXh.js +25 -0
- package/dist/src/invariant-kfQ8Bu82.cjs +30 -0
- package/dist/src/knowledgeBase-BgPyGFUd.cjs +122 -0
- package/dist/src/knowledgeBase-DyHilYaP.js +122 -0
- package/dist/src/litellm-CyMeneHS.js +135 -0
- package/dist/src/litellm-DWDF73yF.cjs +135 -0
- package/dist/src/logger-C40ZGil9.js +717 -0
- package/dist/src/logger-DyfK9PBt.cjs +917 -0
- package/dist/src/luma-ray-BAU9X_ep.cjs +315 -0
- package/dist/src/luma-ray-nwVseBbv.js +313 -0
- package/dist/src/messages-B5ADWTTv.js +245 -0
- package/dist/src/messages-BCnZfqrS.cjs +257 -0
- package/dist/src/meteor-DLZZ3osF.cjs +134 -0
- package/dist/src/meteor-DUiCJRC-.js +134 -0
- package/dist/src/modelslab-00cveB8L.cjs +163 -0
- package/dist/src/modelslab-D9sCU_L7.js +163 -0
- package/dist/src/nova-reel-CTapvqYH.js +276 -0
- package/dist/src/nova-reel-DlWuuroF.cjs +278 -0
- package/dist/src/nova-sonic-5UPWfeMv.cjs +363 -0
- package/dist/src/nova-sonic-BhSwQNym.js +363 -0
- package/dist/src/openai-BWrJK9d8.cjs +52 -0
- package/dist/src/openai-DumO8WQn.js +47 -0
- package/dist/src/openclaw-B8brrjC_.cjs +577 -0
- package/dist/src/openclaw-Bkayww9q.js +571 -0
- package/dist/src/opencode-sdk-7xjoDNiM.cjs +562 -0
- package/dist/src/opencode-sdk-SGwAPxht.js +558 -0
- package/dist/src/otlpReceiver-CoAHfAN9.cjs +15 -0
- package/dist/src/otlpReceiver-oO3EQwI9.js +14 -0
- package/dist/src/providerRegistry-4yjhaEM8.js +45 -0
- package/dist/src/providerRegistry-DhV4rJIc.cjs +50 -0
- package/dist/src/providers-B5RJVG-7.cjs +33609 -0
- package/dist/src/providers-BdmZCLzV.js +33262 -0
- package/dist/src/providers-CxtRxn8e.js +2 -0
- package/dist/src/providers-DnQLNbx1.cjs +3 -0
- package/dist/src/pythonUtils-BD0druiM.cjs +275 -0
- package/dist/src/pythonUtils-IBhn5YGR.js +249 -0
- package/dist/src/quiverai-BDOwZBsM.cjs +213 -0
- package/dist/src/quiverai-D3JTF5lD.js +213 -0
- package/dist/src/responses-B2LCDCXZ.js +667 -0
- package/dist/src/responses-BvNm4Xv9.cjs +685 -0
- package/dist/src/rubyUtils-B0NwnfpY.cjs +245 -0
- package/dist/src/rubyUtils-BroxzZ7c.cjs +2 -0
- package/dist/src/rubyUtils-hqVw5UvJ.js +222 -0
- package/dist/src/sagemaker-Cno2V-Sx.js +689 -0
- package/dist/src/sagemaker-fV_KUgs5.cjs +691 -0
- package/dist/src/server-BOuAXb06.cjs +238 -0
- package/dist/src/server-CtI-EWzm.cjs +2 -0
- package/dist/src/server-Cy3DZymt.js +189 -0
- package/dist/src/slack-CP8xBePa.js +135 -0
- package/dist/src/slack-DSQ1yXVb.cjs +135 -0
- package/dist/src/store-BwDDaBjb.cjs +246 -0
- package/dist/src/store-DcbLC593.cjs +2 -0
- package/dist/src/store-IGpqMIkv.js +240 -0
- package/dist/src/tables-3Q2cL7So.cjs +373 -0
- package/dist/src/tables-Bi2fjr4W.js +288 -0
- package/dist/src/telemetry-Bg2WqF79.js +161 -0
- package/dist/src/telemetry-D0x6u5kX.cjs +166 -0
- package/dist/src/telemetry-DXNimrI0.cjs +2 -0
- package/dist/src/text-B_UCRPp2.js +22 -0
- package/dist/src/text-CW1cyrwj.cjs +33 -0
- package/dist/src/tokenUsageUtils-NYT-WKS6.js +138 -0
- package/dist/src/tokenUsageUtils-bVa1ga6f.cjs +173 -0
- package/dist/src/transcription-Cl_W16Pr.js +122 -0
- package/dist/src/transcription-yt1EecY8.cjs +124 -0
- package/dist/src/transform-BCtGrl_W.cjs +228 -0
- package/dist/src/transform-Bv6gG2MJ.cjs +1688 -0
- package/dist/src/transform-CY1wbpRy.js +1507 -0
- package/dist/src/transform-DU8rUL9P.cjs +2 -0
- package/dist/src/transform-yWaShiKr.js +216 -0
- package/dist/src/transformersAvailability-BGkzavwb.js +35 -0
- package/dist/src/transformersAvailability-DKoRtQLy.cjs +35 -0
- package/dist/src/types-5aqHpBwE.cjs +3769 -0
- package/dist/src/types-Bn6D9c4U.js +3300 -0
- package/dist/src/util-BkKlTkI2.js +293 -0
- package/dist/src/util-CTh0bfOm.cjs +1119 -0
- package/dist/src/util-D17oBwo7.cjs +328 -0
- package/dist/src/util-DsS_-v4p.js +613 -0
- package/dist/src/util-DuntT1Ga.js +951 -0
- package/dist/src/util-aWjdCYMI.cjs +667 -0
- package/dist/src/utils-CisQwpjA.js +94 -0
- package/dist/src/utils-yWamDvmz.cjs +123 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/drizzle/0000_lush_hellion.sql +36 -0
- package/drizzle/0001_wide_calypso.sql +3 -0
- package/drizzle/0002_tidy_juggernaut.sql +1 -0
- package/drizzle/0003_lively_naoko.sql +8 -0
- package/drizzle/0004_minor_peter_quill.sql +19 -0
- package/drizzle/0005_silky_millenium_guard.sql +2 -0
- package/drizzle/0006_harsh_caretaker.sql +42 -0
- package/drizzle/0007_cloudy_wong.sql +1 -0
- package/drizzle/0008_broad_boomer.sql +2 -0
- package/drizzle/0009_strong_marten_broadcloak.sql +19 -0
- package/drizzle/0010_needy_bishop.sql +11 -0
- package/drizzle/0011_moaning_millenium_guard.sql +1 -0
- package/drizzle/0012_late_marten_broadcloak.sql +2 -0
- package/drizzle/0013_previous_dormammu.sql +9 -0
- package/drizzle/0014_lazy_captain_universe.sql +2 -0
- package/drizzle/0015_zippy_wallop.sql +29 -0
- package/drizzle/0016_jazzy_zemo.sql +2 -0
- package/drizzle/0017_reflective_praxagora.sql +4 -0
- package/drizzle/0018_fat_vanisher.sql +22 -0
- package/drizzle/0019_new_clint_barton.sql +8 -0
- package/drizzle/0020_skinny_maverick.sql +1 -0
- package/drizzle/0021_mysterious_madelyne_pryor.sql +13 -0
- package/drizzle/0022_sleepy_ultimo.sql +25 -0
- package/drizzle/0023_wooden_mandrill.sql +2 -0
- package/drizzle/AGENTS.md +68 -0
- package/drizzle/CLAUDE.md +1 -0
- package/drizzle/meta/0000_snapshot.json +221 -0
- package/drizzle/meta/0001_snapshot.json +214 -0
- package/drizzle/meta/0002_snapshot.json +221 -0
- package/drizzle/meta/0005_snapshot.json +369 -0
- package/drizzle/meta/0006_snapshot.json +638 -0
- package/drizzle/meta/0007_snapshot.json +640 -0
- package/drizzle/meta/0008_snapshot.json +649 -0
- package/drizzle/meta/0009_snapshot.json +554 -0
- package/drizzle/meta/0010_snapshot.json +619 -0
- package/drizzle/meta/0011_snapshot.json +627 -0
- package/drizzle/meta/0012_snapshot.json +639 -0
- package/drizzle/meta/0013_snapshot.json +717 -0
- package/drizzle/meta/0014_snapshot.json +717 -0
- package/drizzle/meta/0015_snapshot.json +897 -0
- package/drizzle/meta/0016_snapshot.json +1031 -0
- package/drizzle/meta/0018_snapshot.json +1210 -0
- package/drizzle/meta/0019_snapshot.json +1165 -0
- package/drizzle/meta/0020_snapshot.json +1232 -0
- package/drizzle/meta/0021_snapshot.json +1311 -0
- package/drizzle/meta/0022_snapshot.json +1481 -0
- package/drizzle/meta/0023_snapshot.json +1496 -0
- package/drizzle/meta/_journal.json +174 -0
- package/package.json +240 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-DEq-mXcV.js";
|
|
2
|
+
import { r as logger, v as getEnvBool, w as isCI, x as getEnvString } from "./logger-C40ZGil9.js";
|
|
3
|
+
import { D as CONSENT_ENDPOINT, M as VERSION, k as R_ENDPOINT, r as fetchWithTimeout, t as fetchWithProxy } from "./fetch-DQckpUFz.js";
|
|
4
|
+
import { a as getUserId, i as getUserEmail, n as getAuthMethod, o as isLoggedIntoCloud } from "./accounts-DjOU8Rm3.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import "posthog-node";
|
|
7
|
+
//#region src/telemetry.ts
|
|
8
|
+
var telemetry_exports = /* @__PURE__ */ __exportAll({
|
|
9
|
+
Telemetry: () => Telemetry,
|
|
10
|
+
default: () => telemetry
|
|
11
|
+
});
|
|
12
|
+
z.object({
|
|
13
|
+
event: z.enum([
|
|
14
|
+
"assertion_used",
|
|
15
|
+
"command_used",
|
|
16
|
+
"eval setup",
|
|
17
|
+
"eval_ran",
|
|
18
|
+
"feature_used",
|
|
19
|
+
"funnel",
|
|
20
|
+
"redteam discover",
|
|
21
|
+
"redteam generate",
|
|
22
|
+
"redteam init",
|
|
23
|
+
"redteam poison",
|
|
24
|
+
"redteam report",
|
|
25
|
+
"redteam run",
|
|
26
|
+
"redteam setup",
|
|
27
|
+
"webui_action",
|
|
28
|
+
"webui_api",
|
|
29
|
+
"webui_page_view"
|
|
30
|
+
]),
|
|
31
|
+
packageVersion: z.string().optional().prefault(VERSION),
|
|
32
|
+
properties: z.record(z.string(), z.union([
|
|
33
|
+
z.string(),
|
|
34
|
+
z.number(),
|
|
35
|
+
z.boolean(),
|
|
36
|
+
z.array(z.string())
|
|
37
|
+
]))
|
|
38
|
+
});
|
|
39
|
+
let posthogClient = null;
|
|
40
|
+
let isShuttingDown = false;
|
|
41
|
+
function getPostHogClient() {
|
|
42
|
+
if (getEnvBool("PROMPTFOO_DISABLE_TELEMETRY") || getEnvBool("IS_TESTING")) return null;
|
|
43
|
+
return posthogClient;
|
|
44
|
+
}
|
|
45
|
+
const TELEMETRY_TIMEOUT_MS = 1e3;
|
|
46
|
+
var Telemetry = class {
|
|
47
|
+
telemetryDisabledRecorded = false;
|
|
48
|
+
id;
|
|
49
|
+
email;
|
|
50
|
+
constructor() {
|
|
51
|
+
this.id = getUserId();
|
|
52
|
+
this.email = getUserEmail();
|
|
53
|
+
this.identify();
|
|
54
|
+
}
|
|
55
|
+
async identify() {
|
|
56
|
+
if (this.disabled || getEnvBool("IS_TESTING")) return;
|
|
57
|
+
const client = getPostHogClient();
|
|
58
|
+
if (client) try {
|
|
59
|
+
client.identify({
|
|
60
|
+
distinctId: this.id,
|
|
61
|
+
properties: {
|
|
62
|
+
email: this.email,
|
|
63
|
+
isLoggedIntoCloud: isLoggedIntoCloud(),
|
|
64
|
+
authMethod: getAuthMethod(),
|
|
65
|
+
isRunningInCi: isCI()
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
client.flush().catch(() => {});
|
|
69
|
+
} catch (error) {
|
|
70
|
+
logger.debug(`PostHog identify error: ${error}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
get disabled() {
|
|
74
|
+
return getEnvBool("PROMPTFOO_DISABLE_TELEMETRY");
|
|
75
|
+
}
|
|
76
|
+
recordTelemetryDisabled() {
|
|
77
|
+
if (!this.telemetryDisabledRecorded) {
|
|
78
|
+
this.sendEvent("feature_used", { feature: "telemetry disabled" });
|
|
79
|
+
this.telemetryDisabledRecorded = true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
record(eventName, properties) {
|
|
83
|
+
if (this.disabled) this.recordTelemetryDisabled();
|
|
84
|
+
else this.sendEvent(eventName, properties);
|
|
85
|
+
}
|
|
86
|
+
sendEvent(eventName, properties) {
|
|
87
|
+
const propertiesWithMetadata = {
|
|
88
|
+
...properties,
|
|
89
|
+
packageVersion: VERSION,
|
|
90
|
+
isRunningInCi: isCI()
|
|
91
|
+
};
|
|
92
|
+
const client = getPostHogClient();
|
|
93
|
+
if (client && !getEnvBool("IS_TESTING")) try {
|
|
94
|
+
client.capture({
|
|
95
|
+
distinctId: this.id,
|
|
96
|
+
event: eventName,
|
|
97
|
+
properties: propertiesWithMetadata
|
|
98
|
+
});
|
|
99
|
+
client.flush().catch(() => {});
|
|
100
|
+
} catch (error) {
|
|
101
|
+
logger.debug(`PostHog capture error: ${error}`);
|
|
102
|
+
}
|
|
103
|
+
fetchWithProxy(R_ENDPOINT, {
|
|
104
|
+
method: "POST",
|
|
105
|
+
headers: { "Content-Type": "application/json" },
|
|
106
|
+
body: JSON.stringify({
|
|
107
|
+
event: eventName,
|
|
108
|
+
environment: getEnvString("NODE_ENV", "development"),
|
|
109
|
+
email: this.email,
|
|
110
|
+
meta: {
|
|
111
|
+
user_id: this.id,
|
|
112
|
+
...propertiesWithMetadata
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
}).catch(() => {});
|
|
116
|
+
}
|
|
117
|
+
async shutdown() {
|
|
118
|
+
if (isShuttingDown) return;
|
|
119
|
+
const client = getPostHogClient();
|
|
120
|
+
if (!client) return;
|
|
121
|
+
isShuttingDown = true;
|
|
122
|
+
try {
|
|
123
|
+
await client.shutdown();
|
|
124
|
+
} catch (error) {
|
|
125
|
+
logger.debug(`PostHog shutdown error: ${error}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* This is a separate endpoint to save consent used only for redteam data synthesis for "harmful" plugins.
|
|
130
|
+
*/
|
|
131
|
+
async saveConsent(email, metadata) {
|
|
132
|
+
try {
|
|
133
|
+
const response = await fetchWithTimeout(CONSENT_ENDPOINT, {
|
|
134
|
+
method: "POST",
|
|
135
|
+
headers: { "Content-Type": "application/json" },
|
|
136
|
+
body: JSON.stringify({
|
|
137
|
+
email,
|
|
138
|
+
metadata
|
|
139
|
+
})
|
|
140
|
+
}, TELEMETRY_TIMEOUT_MS);
|
|
141
|
+
if (!response.ok) throw new Error(`Failed to save consent: ${response.statusText}`);
|
|
142
|
+
} catch (err) {
|
|
143
|
+
logger.debug(`Failed to save consent: ${err.message}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const telemetry = new Telemetry();
|
|
148
|
+
const TELEMETRY_INSTANCE_KEY = Symbol.for("promptfoo.telemetry.instance");
|
|
149
|
+
const SHUTDOWN_HANDLER_KEY = Symbol.for("promptfoo.telemetry.shutdownHandler");
|
|
150
|
+
process[TELEMETRY_INSTANCE_KEY] = telemetry;
|
|
151
|
+
if (!process[SHUTDOWN_HANDLER_KEY]) {
|
|
152
|
+
process[SHUTDOWN_HANDLER_KEY] = true;
|
|
153
|
+
process.once("beforeExit", () => {
|
|
154
|
+
const instance = process[TELEMETRY_INSTANCE_KEY];
|
|
155
|
+
if (instance) instance.shutdown().catch(() => {});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
//#endregion
|
|
159
|
+
export { telemetry_exports as n, telemetry as t };
|
|
160
|
+
|
|
161
|
+
//# sourceMappingURL=telemetry-Bg2WqF79.js.map
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
const require_logger = require("./logger-DyfK9PBt.cjs");
|
|
2
|
+
const require_fetch = require("./fetch-BTxakTSg.cjs");
|
|
3
|
+
const require_accounts = require("./accounts-Bt1oJb1Z.cjs");
|
|
4
|
+
let zod = require("zod");
|
|
5
|
+
require("posthog-node");
|
|
6
|
+
zod.z.object({
|
|
7
|
+
event: zod.z.enum([
|
|
8
|
+
"assertion_used",
|
|
9
|
+
"command_used",
|
|
10
|
+
"eval setup",
|
|
11
|
+
"eval_ran",
|
|
12
|
+
"feature_used",
|
|
13
|
+
"funnel",
|
|
14
|
+
"redteam discover",
|
|
15
|
+
"redteam generate",
|
|
16
|
+
"redteam init",
|
|
17
|
+
"redteam poison",
|
|
18
|
+
"redteam report",
|
|
19
|
+
"redteam run",
|
|
20
|
+
"redteam setup",
|
|
21
|
+
"webui_action",
|
|
22
|
+
"webui_api",
|
|
23
|
+
"webui_page_view"
|
|
24
|
+
]),
|
|
25
|
+
packageVersion: zod.z.string().optional().prefault(require_fetch.VERSION),
|
|
26
|
+
properties: zod.z.record(zod.z.string(), zod.z.union([
|
|
27
|
+
zod.z.string(),
|
|
28
|
+
zod.z.number(),
|
|
29
|
+
zod.z.boolean(),
|
|
30
|
+
zod.z.array(zod.z.string())
|
|
31
|
+
]))
|
|
32
|
+
});
|
|
33
|
+
let posthogClient = null;
|
|
34
|
+
let isShuttingDown = false;
|
|
35
|
+
function getPostHogClient() {
|
|
36
|
+
if (require_logger.getEnvBool("PROMPTFOO_DISABLE_TELEMETRY") || require_logger.getEnvBool("IS_TESTING")) return null;
|
|
37
|
+
return posthogClient;
|
|
38
|
+
}
|
|
39
|
+
const TELEMETRY_TIMEOUT_MS = 1e3;
|
|
40
|
+
var Telemetry = class {
|
|
41
|
+
telemetryDisabledRecorded = false;
|
|
42
|
+
id;
|
|
43
|
+
email;
|
|
44
|
+
constructor() {
|
|
45
|
+
this.id = require_accounts.getUserId();
|
|
46
|
+
this.email = require_accounts.getUserEmail();
|
|
47
|
+
this.identify();
|
|
48
|
+
}
|
|
49
|
+
async identify() {
|
|
50
|
+
if (this.disabled || require_logger.getEnvBool("IS_TESTING")) return;
|
|
51
|
+
const client = getPostHogClient();
|
|
52
|
+
if (client) try {
|
|
53
|
+
client.identify({
|
|
54
|
+
distinctId: this.id,
|
|
55
|
+
properties: {
|
|
56
|
+
email: this.email,
|
|
57
|
+
isLoggedIntoCloud: require_accounts.isLoggedIntoCloud(),
|
|
58
|
+
authMethod: require_accounts.getAuthMethod(),
|
|
59
|
+
isRunningInCi: require_logger.isCI()
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
client.flush().catch(() => {});
|
|
63
|
+
} catch (error) {
|
|
64
|
+
require_logger.logger.debug(`PostHog identify error: ${error}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
get disabled() {
|
|
68
|
+
return require_logger.getEnvBool("PROMPTFOO_DISABLE_TELEMETRY");
|
|
69
|
+
}
|
|
70
|
+
recordTelemetryDisabled() {
|
|
71
|
+
if (!this.telemetryDisabledRecorded) {
|
|
72
|
+
this.sendEvent("feature_used", { feature: "telemetry disabled" });
|
|
73
|
+
this.telemetryDisabledRecorded = true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
record(eventName, properties) {
|
|
77
|
+
if (this.disabled) this.recordTelemetryDisabled();
|
|
78
|
+
else this.sendEvent(eventName, properties);
|
|
79
|
+
}
|
|
80
|
+
sendEvent(eventName, properties) {
|
|
81
|
+
const propertiesWithMetadata = {
|
|
82
|
+
...properties,
|
|
83
|
+
packageVersion: require_fetch.VERSION,
|
|
84
|
+
isRunningInCi: require_logger.isCI()
|
|
85
|
+
};
|
|
86
|
+
const client = getPostHogClient();
|
|
87
|
+
if (client && !require_logger.getEnvBool("IS_TESTING")) try {
|
|
88
|
+
client.capture({
|
|
89
|
+
distinctId: this.id,
|
|
90
|
+
event: eventName,
|
|
91
|
+
properties: propertiesWithMetadata
|
|
92
|
+
});
|
|
93
|
+
client.flush().catch(() => {});
|
|
94
|
+
} catch (error) {
|
|
95
|
+
require_logger.logger.debug(`PostHog capture error: ${error}`);
|
|
96
|
+
}
|
|
97
|
+
require_fetch.fetchWithProxy(require_fetch.R_ENDPOINT, {
|
|
98
|
+
method: "POST",
|
|
99
|
+
headers: { "Content-Type": "application/json" },
|
|
100
|
+
body: JSON.stringify({
|
|
101
|
+
event: eventName,
|
|
102
|
+
environment: require_logger.getEnvString("NODE_ENV", "development"),
|
|
103
|
+
email: this.email,
|
|
104
|
+
meta: {
|
|
105
|
+
user_id: this.id,
|
|
106
|
+
...propertiesWithMetadata
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
}).catch(() => {});
|
|
110
|
+
}
|
|
111
|
+
async shutdown() {
|
|
112
|
+
if (isShuttingDown) return;
|
|
113
|
+
const client = getPostHogClient();
|
|
114
|
+
if (!client) return;
|
|
115
|
+
isShuttingDown = true;
|
|
116
|
+
try {
|
|
117
|
+
await client.shutdown();
|
|
118
|
+
} catch (error) {
|
|
119
|
+
require_logger.logger.debug(`PostHog shutdown error: ${error}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* This is a separate endpoint to save consent used only for redteam data synthesis for "harmful" plugins.
|
|
124
|
+
*/
|
|
125
|
+
async saveConsent(email, metadata) {
|
|
126
|
+
try {
|
|
127
|
+
const response = await require_fetch.fetchWithTimeout(require_fetch.CONSENT_ENDPOINT, {
|
|
128
|
+
method: "POST",
|
|
129
|
+
headers: { "Content-Type": "application/json" },
|
|
130
|
+
body: JSON.stringify({
|
|
131
|
+
email,
|
|
132
|
+
metadata
|
|
133
|
+
})
|
|
134
|
+
}, TELEMETRY_TIMEOUT_MS);
|
|
135
|
+
if (!response.ok) throw new Error(`Failed to save consent: ${response.statusText}`);
|
|
136
|
+
} catch (err) {
|
|
137
|
+
require_logger.logger.debug(`Failed to save consent: ${err.message}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const telemetry = new Telemetry();
|
|
142
|
+
const TELEMETRY_INSTANCE_KEY = Symbol.for("promptfoo.telemetry.instance");
|
|
143
|
+
const SHUTDOWN_HANDLER_KEY = Symbol.for("promptfoo.telemetry.shutdownHandler");
|
|
144
|
+
process[TELEMETRY_INSTANCE_KEY] = telemetry;
|
|
145
|
+
if (!process[SHUTDOWN_HANDLER_KEY]) {
|
|
146
|
+
process[SHUTDOWN_HANDLER_KEY] = true;
|
|
147
|
+
process.once("beforeExit", () => {
|
|
148
|
+
const instance = process[TELEMETRY_INSTANCE_KEY];
|
|
149
|
+
if (instance) instance.shutdown().catch(() => {});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
Object.defineProperty(exports, "Telemetry", {
|
|
154
|
+
enumerable: true,
|
|
155
|
+
get: function() {
|
|
156
|
+
return Telemetry;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
Object.defineProperty(exports, "telemetry", {
|
|
160
|
+
enumerable: true,
|
|
161
|
+
get: function() {
|
|
162
|
+
return telemetry;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
//# sourceMappingURL=telemetry-D0x6u5kX.cjs.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/util/text.ts
|
|
2
|
+
/**
|
|
3
|
+
* Truncates a string to a maximum length, adding an ellipsis (...) if truncated.
|
|
4
|
+
* @param str The string to truncate
|
|
5
|
+
* @param maxLen The maximum length of the resulting string, including the ellipsis
|
|
6
|
+
* @returns The truncated string, with ellipsis if necessary
|
|
7
|
+
*/
|
|
8
|
+
function ellipsize(str, maxLen) {
|
|
9
|
+
if (str.length > maxLen) return str.slice(0, maxLen - 3) + "...";
|
|
10
|
+
return str;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Escapes special regex characters in a string.
|
|
14
|
+
* Use this when building regex patterns from dynamic input to prevent ReDoS attacks.
|
|
15
|
+
*/
|
|
16
|
+
function escapeRegExp(str) {
|
|
17
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { escapeRegExp as n, ellipsize as t };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=text-B_UCRPp2.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/util/text.ts
|
|
2
|
+
/**
|
|
3
|
+
* Truncates a string to a maximum length, adding an ellipsis (...) if truncated.
|
|
4
|
+
* @param str The string to truncate
|
|
5
|
+
* @param maxLen The maximum length of the resulting string, including the ellipsis
|
|
6
|
+
* @returns The truncated string, with ellipsis if necessary
|
|
7
|
+
*/
|
|
8
|
+
function ellipsize(str, maxLen) {
|
|
9
|
+
if (str.length > maxLen) return str.slice(0, maxLen - 3) + "...";
|
|
10
|
+
return str;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Escapes special regex characters in a string.
|
|
14
|
+
* Use this when building regex patterns from dynamic input to prevent ReDoS attacks.
|
|
15
|
+
*/
|
|
16
|
+
function escapeRegExp(str) {
|
|
17
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
Object.defineProperty(exports, "ellipsize", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function() {
|
|
23
|
+
return ellipsize;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(exports, "escapeRegExp", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function() {
|
|
29
|
+
return escapeRegExp;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=text-CW1cyrwj.cjs.map
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
//#region src/util/tokenUsageUtils.ts
|
|
2
|
+
/**
|
|
3
|
+
* Helper to create empty completion details
|
|
4
|
+
*/
|
|
5
|
+
function createEmptyCompletionDetails() {
|
|
6
|
+
return {
|
|
7
|
+
reasoning: 0,
|
|
8
|
+
acceptedPrediction: 0,
|
|
9
|
+
rejectedPrediction: 0
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Create an empty assertions token usage object.
|
|
14
|
+
*/
|
|
15
|
+
function createEmptyAssertions() {
|
|
16
|
+
return {
|
|
17
|
+
total: 0,
|
|
18
|
+
prompt: 0,
|
|
19
|
+
completion: 0,
|
|
20
|
+
cached: 0,
|
|
21
|
+
numRequests: 0,
|
|
22
|
+
completionDetails: createEmptyCompletionDetails()
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create an empty token usage object with all fields initialized to zero.
|
|
27
|
+
*/
|
|
28
|
+
function createEmptyTokenUsage() {
|
|
29
|
+
return {
|
|
30
|
+
prompt: 0,
|
|
31
|
+
completion: 0,
|
|
32
|
+
cached: 0,
|
|
33
|
+
total: 0,
|
|
34
|
+
numRequests: 0,
|
|
35
|
+
completionDetails: createEmptyCompletionDetails(),
|
|
36
|
+
assertions: createEmptyAssertions()
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Helper to accumulate numeric values
|
|
41
|
+
*/
|
|
42
|
+
function addNumbers(a, b) {
|
|
43
|
+
return (a ?? 0) + (b ?? 0);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Helper to accumulate completion details
|
|
47
|
+
*/
|
|
48
|
+
function accumulateCompletionDetails(target, update) {
|
|
49
|
+
if (!update) return target;
|
|
50
|
+
return {
|
|
51
|
+
reasoning: addNumbers(target?.reasoning, update.reasoning),
|
|
52
|
+
acceptedPrediction: addNumbers(target?.acceptedPrediction, update.acceptedPrediction),
|
|
53
|
+
rejectedPrediction: addNumbers(target?.rejectedPrediction, update.rejectedPrediction)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Accumulate token usage into a target object. Mutates {@code target}.
|
|
58
|
+
* @param target Object to update
|
|
59
|
+
* @param update Usage to add
|
|
60
|
+
* @param incrementRequests Whether to increment numRequests when update is provided but doesn't specify numRequests
|
|
61
|
+
*/
|
|
62
|
+
function accumulateTokenUsage(target, update, incrementRequests = false) {
|
|
63
|
+
if (!update) return;
|
|
64
|
+
target.prompt = addNumbers(target.prompt, update.prompt);
|
|
65
|
+
target.completion = addNumbers(target.completion, update.completion);
|
|
66
|
+
target.cached = addNumbers(target.cached, update.cached);
|
|
67
|
+
target.total = addNumbers(target.total, update.total);
|
|
68
|
+
if (update.numRequests !== void 0) target.numRequests = addNumbers(target.numRequests, update.numRequests);
|
|
69
|
+
else if (incrementRequests) target.numRequests = (target.numRequests ?? 0) + 1;
|
|
70
|
+
if (update.completionDetails) target.completionDetails = accumulateCompletionDetails(target.completionDetails, update.completionDetails);
|
|
71
|
+
if (update.assertions) {
|
|
72
|
+
if (!target.assertions) target.assertions = {
|
|
73
|
+
total: 0,
|
|
74
|
+
prompt: 0,
|
|
75
|
+
completion: 0,
|
|
76
|
+
cached: 0,
|
|
77
|
+
numRequests: 0
|
|
78
|
+
};
|
|
79
|
+
target.assertions.total = addNumbers(target.assertions.total, update.assertions.total);
|
|
80
|
+
target.assertions.prompt = addNumbers(target.assertions.prompt, update.assertions.prompt);
|
|
81
|
+
target.assertions.completion = addNumbers(target.assertions.completion, update.assertions.completion);
|
|
82
|
+
target.assertions.cached = addNumbers(target.assertions.cached, update.assertions.cached);
|
|
83
|
+
target.assertions.numRequests = addNumbers(target.assertions.numRequests, update.assertions.numRequests);
|
|
84
|
+
if (update.assertions.completionDetails) target.assertions.completionDetails = accumulateCompletionDetails(target.assertions.completionDetails, update.assertions.completionDetails);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Accumulate token usage specifically for assertions.
|
|
89
|
+
* This function operates directly on an assertions object rather than a full TokenUsage object.
|
|
90
|
+
* @param target Assertions object to update
|
|
91
|
+
* @param update Partial token usage that may contain assertion-related fields
|
|
92
|
+
*/
|
|
93
|
+
function accumulateAssertionTokenUsage(target, update) {
|
|
94
|
+
if (!update) return;
|
|
95
|
+
target.total = addNumbers(target.total, update.total);
|
|
96
|
+
target.prompt = addNumbers(target.prompt, update.prompt);
|
|
97
|
+
target.completion = addNumbers(target.completion, update.completion);
|
|
98
|
+
target.cached = addNumbers(target.cached, update.cached);
|
|
99
|
+
if (update.completionDetails) target.completionDetails = accumulateCompletionDetails(target.completionDetails, update.completionDetails);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Accumulate token usage from a response, handling the common pattern of
|
|
103
|
+
* incrementing numRequests when no token usage is provided.
|
|
104
|
+
* @param target Object to update
|
|
105
|
+
* @param response Response that may contain token usage
|
|
106
|
+
*/
|
|
107
|
+
function accumulateResponseTokenUsage(target, response, options) {
|
|
108
|
+
const countAsRequest = options?.countAsRequest ?? true;
|
|
109
|
+
if (response?.tokenUsage) if (countAsRequest) {
|
|
110
|
+
accumulateTokenUsage(target, response.tokenUsage);
|
|
111
|
+
if (response.tokenUsage.numRequests === void 0) target.numRequests = (target.numRequests ?? 0) + 1;
|
|
112
|
+
} else accumulateTokenUsage(target, {
|
|
113
|
+
...response.tokenUsage,
|
|
114
|
+
numRequests: void 0
|
|
115
|
+
});
|
|
116
|
+
else if (response && countAsRequest) target.numRequests = (target.numRequests ?? 0) + 1;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Normalize token usage from a provider response into a standard TokenUsage object.
|
|
120
|
+
* Provides default values for all fields if not present in the response.
|
|
121
|
+
* @param tokenUsage Token usage from provider response (may be partial or undefined)
|
|
122
|
+
* @returns Fully populated TokenUsage object with defaults
|
|
123
|
+
*/
|
|
124
|
+
function normalizeTokenUsage(tokenUsage) {
|
|
125
|
+
return {
|
|
126
|
+
total: tokenUsage?.total || 0,
|
|
127
|
+
prompt: tokenUsage?.prompt || 0,
|
|
128
|
+
completion: tokenUsage?.completion || 0,
|
|
129
|
+
cached: tokenUsage?.cached || 0,
|
|
130
|
+
numRequests: tokenUsage?.numRequests || 0,
|
|
131
|
+
completionDetails: tokenUsage?.completionDetails || createEmptyCompletionDetails(),
|
|
132
|
+
assertions: tokenUsage?.assertions || createEmptyAssertions()
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
export { createEmptyTokenUsage as a, createEmptyAssertions as i, accumulateResponseTokenUsage as n, normalizeTokenUsage as o, accumulateTokenUsage as r, accumulateAssertionTokenUsage as t };
|
|
137
|
+
|
|
138
|
+
//# sourceMappingURL=tokenUsageUtils-NYT-WKS6.js.map
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
//#region src/util/tokenUsageUtils.ts
|
|
2
|
+
/**
|
|
3
|
+
* Helper to create empty completion details
|
|
4
|
+
*/
|
|
5
|
+
function createEmptyCompletionDetails() {
|
|
6
|
+
return {
|
|
7
|
+
reasoning: 0,
|
|
8
|
+
acceptedPrediction: 0,
|
|
9
|
+
rejectedPrediction: 0
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Create an empty assertions token usage object.
|
|
14
|
+
*/
|
|
15
|
+
function createEmptyAssertions() {
|
|
16
|
+
return {
|
|
17
|
+
total: 0,
|
|
18
|
+
prompt: 0,
|
|
19
|
+
completion: 0,
|
|
20
|
+
cached: 0,
|
|
21
|
+
numRequests: 0,
|
|
22
|
+
completionDetails: createEmptyCompletionDetails()
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create an empty token usage object with all fields initialized to zero.
|
|
27
|
+
*/
|
|
28
|
+
function createEmptyTokenUsage() {
|
|
29
|
+
return {
|
|
30
|
+
prompt: 0,
|
|
31
|
+
completion: 0,
|
|
32
|
+
cached: 0,
|
|
33
|
+
total: 0,
|
|
34
|
+
numRequests: 0,
|
|
35
|
+
completionDetails: createEmptyCompletionDetails(),
|
|
36
|
+
assertions: createEmptyAssertions()
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Helper to accumulate numeric values
|
|
41
|
+
*/
|
|
42
|
+
function addNumbers(a, b) {
|
|
43
|
+
return (a ?? 0) + (b ?? 0);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Helper to accumulate completion details
|
|
47
|
+
*/
|
|
48
|
+
function accumulateCompletionDetails(target, update) {
|
|
49
|
+
if (!update) return target;
|
|
50
|
+
return {
|
|
51
|
+
reasoning: addNumbers(target?.reasoning, update.reasoning),
|
|
52
|
+
acceptedPrediction: addNumbers(target?.acceptedPrediction, update.acceptedPrediction),
|
|
53
|
+
rejectedPrediction: addNumbers(target?.rejectedPrediction, update.rejectedPrediction)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Accumulate token usage into a target object. Mutates {@code target}.
|
|
58
|
+
* @param target Object to update
|
|
59
|
+
* @param update Usage to add
|
|
60
|
+
* @param incrementRequests Whether to increment numRequests when update is provided but doesn't specify numRequests
|
|
61
|
+
*/
|
|
62
|
+
function accumulateTokenUsage(target, update, incrementRequests = false) {
|
|
63
|
+
if (!update) return;
|
|
64
|
+
target.prompt = addNumbers(target.prompt, update.prompt);
|
|
65
|
+
target.completion = addNumbers(target.completion, update.completion);
|
|
66
|
+
target.cached = addNumbers(target.cached, update.cached);
|
|
67
|
+
target.total = addNumbers(target.total, update.total);
|
|
68
|
+
if (update.numRequests !== void 0) target.numRequests = addNumbers(target.numRequests, update.numRequests);
|
|
69
|
+
else if (incrementRequests) target.numRequests = (target.numRequests ?? 0) + 1;
|
|
70
|
+
if (update.completionDetails) target.completionDetails = accumulateCompletionDetails(target.completionDetails, update.completionDetails);
|
|
71
|
+
if (update.assertions) {
|
|
72
|
+
if (!target.assertions) target.assertions = {
|
|
73
|
+
total: 0,
|
|
74
|
+
prompt: 0,
|
|
75
|
+
completion: 0,
|
|
76
|
+
cached: 0,
|
|
77
|
+
numRequests: 0
|
|
78
|
+
};
|
|
79
|
+
target.assertions.total = addNumbers(target.assertions.total, update.assertions.total);
|
|
80
|
+
target.assertions.prompt = addNumbers(target.assertions.prompt, update.assertions.prompt);
|
|
81
|
+
target.assertions.completion = addNumbers(target.assertions.completion, update.assertions.completion);
|
|
82
|
+
target.assertions.cached = addNumbers(target.assertions.cached, update.assertions.cached);
|
|
83
|
+
target.assertions.numRequests = addNumbers(target.assertions.numRequests, update.assertions.numRequests);
|
|
84
|
+
if (update.assertions.completionDetails) target.assertions.completionDetails = accumulateCompletionDetails(target.assertions.completionDetails, update.assertions.completionDetails);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Accumulate token usage specifically for assertions.
|
|
89
|
+
* This function operates directly on an assertions object rather than a full TokenUsage object.
|
|
90
|
+
* @param target Assertions object to update
|
|
91
|
+
* @param update Partial token usage that may contain assertion-related fields
|
|
92
|
+
*/
|
|
93
|
+
function accumulateAssertionTokenUsage(target, update) {
|
|
94
|
+
if (!update) return;
|
|
95
|
+
target.total = addNumbers(target.total, update.total);
|
|
96
|
+
target.prompt = addNumbers(target.prompt, update.prompt);
|
|
97
|
+
target.completion = addNumbers(target.completion, update.completion);
|
|
98
|
+
target.cached = addNumbers(target.cached, update.cached);
|
|
99
|
+
if (update.completionDetails) target.completionDetails = accumulateCompletionDetails(target.completionDetails, update.completionDetails);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Accumulate token usage from a response, handling the common pattern of
|
|
103
|
+
* incrementing numRequests when no token usage is provided.
|
|
104
|
+
* @param target Object to update
|
|
105
|
+
* @param response Response that may contain token usage
|
|
106
|
+
*/
|
|
107
|
+
function accumulateResponseTokenUsage(target, response, options) {
|
|
108
|
+
const countAsRequest = options?.countAsRequest ?? true;
|
|
109
|
+
if (response?.tokenUsage) if (countAsRequest) {
|
|
110
|
+
accumulateTokenUsage(target, response.tokenUsage);
|
|
111
|
+
if (response.tokenUsage.numRequests === void 0) target.numRequests = (target.numRequests ?? 0) + 1;
|
|
112
|
+
} else accumulateTokenUsage(target, {
|
|
113
|
+
...response.tokenUsage,
|
|
114
|
+
numRequests: void 0
|
|
115
|
+
});
|
|
116
|
+
else if (response && countAsRequest) target.numRequests = (target.numRequests ?? 0) + 1;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Normalize token usage from a provider response into a standard TokenUsage object.
|
|
120
|
+
* Provides default values for all fields if not present in the response.
|
|
121
|
+
* @param tokenUsage Token usage from provider response (may be partial or undefined)
|
|
122
|
+
* @returns Fully populated TokenUsage object with defaults
|
|
123
|
+
*/
|
|
124
|
+
function normalizeTokenUsage(tokenUsage) {
|
|
125
|
+
return {
|
|
126
|
+
total: tokenUsage?.total || 0,
|
|
127
|
+
prompt: tokenUsage?.prompt || 0,
|
|
128
|
+
completion: tokenUsage?.completion || 0,
|
|
129
|
+
cached: tokenUsage?.cached || 0,
|
|
130
|
+
numRequests: tokenUsage?.numRequests || 0,
|
|
131
|
+
completionDetails: tokenUsage?.completionDetails || createEmptyCompletionDetails(),
|
|
132
|
+
assertions: tokenUsage?.assertions || createEmptyAssertions()
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
Object.defineProperty(exports, "accumulateAssertionTokenUsage", {
|
|
137
|
+
enumerable: true,
|
|
138
|
+
get: function() {
|
|
139
|
+
return accumulateAssertionTokenUsage;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
Object.defineProperty(exports, "accumulateResponseTokenUsage", {
|
|
143
|
+
enumerable: true,
|
|
144
|
+
get: function() {
|
|
145
|
+
return accumulateResponseTokenUsage;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
Object.defineProperty(exports, "accumulateTokenUsage", {
|
|
149
|
+
enumerable: true,
|
|
150
|
+
get: function() {
|
|
151
|
+
return accumulateTokenUsage;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
Object.defineProperty(exports, "createEmptyAssertions", {
|
|
155
|
+
enumerable: true,
|
|
156
|
+
get: function() {
|
|
157
|
+
return createEmptyAssertions;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
Object.defineProperty(exports, "createEmptyTokenUsage", {
|
|
161
|
+
enumerable: true,
|
|
162
|
+
get: function() {
|
|
163
|
+
return createEmptyTokenUsage;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
Object.defineProperty(exports, "normalizeTokenUsage", {
|
|
167
|
+
enumerable: true,
|
|
168
|
+
get: function() {
|
|
169
|
+
return normalizeTokenUsage;
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
//# sourceMappingURL=tokenUsageUtils-bVa1ga6f.cjs.map
|