@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,379 @@
|
|
|
1
|
+
import { r as logger } from "./logger-C40ZGil9.js";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import path$1 from "node:path";
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import fsPromises from "node:fs/promises";
|
|
8
|
+
import vm from "node:vm";
|
|
9
|
+
import { resolveModulePath } from "exsolve";
|
|
10
|
+
//#region node_modules/tsdown/esm-shims.js
|
|
11
|
+
const getFilename = () => fileURLToPath(import.meta.url);
|
|
12
|
+
const getDirname = () => path$1.dirname(getFilename());
|
|
13
|
+
const __dirname = /* @__PURE__ */ getDirname();
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/util/pathUtils.ts
|
|
16
|
+
/**
|
|
17
|
+
* Path resolution utilities that work with both regular paths and file:// URLs
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Check if a file path is absolute, handling both regular paths and URLs
|
|
21
|
+
* @param filePath - The file path to check
|
|
22
|
+
* @returns True if the path is absolute
|
|
23
|
+
*/
|
|
24
|
+
function isAbsolute(filePath) {
|
|
25
|
+
if (!filePath) return false;
|
|
26
|
+
if (/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(filePath)) {
|
|
27
|
+
if (filePath.startsWith("file://")) try {
|
|
28
|
+
return path.isAbsolute(fileURLToPath(filePath));
|
|
29
|
+
} catch {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return path.isAbsolute(filePath);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Safely resolves a path - only calls resolve() if the last path is relative
|
|
38
|
+
* Leaves absolute paths and absolute URLs unchanged
|
|
39
|
+
*
|
|
40
|
+
* @param paths - The path segments to resolve
|
|
41
|
+
* @returns The resolved path if last path is relative, or the last path if it's absolute
|
|
42
|
+
*/
|
|
43
|
+
function safeResolve(...paths) {
|
|
44
|
+
const lastPath = paths[paths.length - 1] || "";
|
|
45
|
+
if (isAbsolute(lastPath)) return lastPath;
|
|
46
|
+
return path.resolve(...paths);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Safely joins paths - only joins if the last path is relative
|
|
50
|
+
* If the last path is absolute or an absolute URL, returns it directly
|
|
51
|
+
*
|
|
52
|
+
* @param paths - The path segments to join
|
|
53
|
+
* @returns The joined path if last path is relative, or the last path if it's absolute
|
|
54
|
+
*/
|
|
55
|
+
function safeJoin(...paths) {
|
|
56
|
+
const lastPath = paths[paths.length - 1] || "";
|
|
57
|
+
if (isAbsolute(lastPath)) return lastPath;
|
|
58
|
+
return path.join(...paths);
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/esm.ts
|
|
62
|
+
/**
|
|
63
|
+
* Mapping of wrapper types to their subdirectory names.
|
|
64
|
+
* These correspond to the directory structure under src/ and dist/src/.
|
|
65
|
+
*/
|
|
66
|
+
const WRAPPER_SUBDIRS = {
|
|
67
|
+
python: "python",
|
|
68
|
+
ruby: "ruby",
|
|
69
|
+
golang: "golang"
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Cache for wrapper directory paths to avoid repeated path construction.
|
|
73
|
+
*/
|
|
74
|
+
const wrapperDirCache = {};
|
|
75
|
+
/**
|
|
76
|
+
* Returns the directory containing wrapper scripts for the specified language.
|
|
77
|
+
*
|
|
78
|
+
* This function provides a consistent way to locate wrapper scripts (wrapper.py,
|
|
79
|
+
* wrapper.rb, wrapper.go, etc.) that works correctly in both development and
|
|
80
|
+
* production (bundled) environments.
|
|
81
|
+
*
|
|
82
|
+
* Directory resolution:
|
|
83
|
+
* - Development (tsx): src/{python|ruby|golang}/
|
|
84
|
+
* - Production (bundled): dist/src/{python|ruby|golang}/
|
|
85
|
+
*
|
|
86
|
+
* Results are cached for performance.
|
|
87
|
+
*
|
|
88
|
+
* @param type - The wrapper type ('python', 'ruby', or 'golang')
|
|
89
|
+
* @returns The absolute path to the wrapper directory
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* // Get Python wrapper path
|
|
94
|
+
* const pythonDir = getWrapperDir('python');
|
|
95
|
+
* const wrapperPath = path.join(pythonDir, 'wrapper.py');
|
|
96
|
+
*
|
|
97
|
+
* // Get Ruby wrapper path
|
|
98
|
+
* const rubyDir = getWrapperDir('ruby');
|
|
99
|
+
* const wrapperPath = path.join(rubyDir, 'wrapper.rb');
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
function getWrapperDir(type) {
|
|
103
|
+
if (wrapperDirCache[type]) return wrapperDirCache[type];
|
|
104
|
+
const baseDir = getDirectory();
|
|
105
|
+
const result = path$1.join(baseDir, WRAPPER_SUBDIRS[type]);
|
|
106
|
+
wrapperDirCache[type] = result;
|
|
107
|
+
logger.debug(`Resolved ${type} wrapper directory: ${result}`);
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Resolves the entry point path for an npm package, handling ESM-only packages
|
|
112
|
+
* with restrictive `exports` fields.
|
|
113
|
+
*
|
|
114
|
+
* ## Why this function exists
|
|
115
|
+
*
|
|
116
|
+
* Some ESM-only packages (like `@openai/codex-sdk`) have restrictive `exports` fields:
|
|
117
|
+
*
|
|
118
|
+
* ```json
|
|
119
|
+
* {
|
|
120
|
+
* "type": "module",
|
|
121
|
+
* "exports": {
|
|
122
|
+
* ".": { "import": "./dist/index.js" }
|
|
123
|
+
* }
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* This causes problems with Node.js's `require.resolve()`:
|
|
128
|
+
* - `require.resolve('@openai/codex-sdk')` fails with "No exports main defined"
|
|
129
|
+
* because there's no `"require"` or `"default"` condition.
|
|
130
|
+
*
|
|
131
|
+
* ## Solution
|
|
132
|
+
*
|
|
133
|
+
* This function uses `exsolve` which implements Node's ESM resolution algorithm,
|
|
134
|
+
* correctly handling all `exports` field variations:
|
|
135
|
+
* - Direct string exports: `"exports": "./index.js"`
|
|
136
|
+
* - Shorthand object: `"exports": { ".": "./index.js" }`
|
|
137
|
+
* - Conditional exports: `"exports": { ".": { "import": "./index.js" } }`
|
|
138
|
+
* - Nested conditionals, array fallbacks, pattern exports, etc.
|
|
139
|
+
*
|
|
140
|
+
* @param packageName - The npm package name (e.g., '@openai/codex-sdk')
|
|
141
|
+
* @param baseDir - The directory to resolve from (should contain node_modules)
|
|
142
|
+
* @returns The absolute path to the package entry point, or null if not found
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* // Resolve from current directory
|
|
147
|
+
* const codexPath = resolvePackageEntryPoint('@openai/codex-sdk', process.cwd());
|
|
148
|
+
* if (codexPath) {
|
|
149
|
+
* const module = await importModule(codexPath);
|
|
150
|
+
* }
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
function resolvePackageEntryPoint(packageName, baseDir) {
|
|
154
|
+
const from = pathToFileURL(path$1.join(baseDir, "package.json")).href;
|
|
155
|
+
const resolved = resolveModulePath(packageName, {
|
|
156
|
+
from,
|
|
157
|
+
conditions: [
|
|
158
|
+
"node",
|
|
159
|
+
"import",
|
|
160
|
+
"require",
|
|
161
|
+
"default"
|
|
162
|
+
],
|
|
163
|
+
try: true
|
|
164
|
+
});
|
|
165
|
+
return resolved ? path$1.normalize(resolved) : null;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* ESM replacement for __dirname - guarded for dual CJS/ESM builds.
|
|
169
|
+
*
|
|
170
|
+
* This is the canonical way to get the current directory in dual ESM/CJS code.
|
|
171
|
+
* Use this instead of implementing the try-catch pattern in each file.
|
|
172
|
+
*
|
|
173
|
+
* Build contexts:
|
|
174
|
+
* - ESM (production/bundled): BUILD_FORMAT='esm', import.meta.url is valid
|
|
175
|
+
* - CJS (library build): BUILD_FORMAT='cjs', import.meta.url may be empty, __dirname available
|
|
176
|
+
* - Development (tsx): BUILD_FORMAT=undefined, import.meta.url is valid
|
|
177
|
+
* - Vitest tests: BUILD_FORMAT=undefined, import.meta is valid in ESM mode
|
|
178
|
+
*
|
|
179
|
+
* The try-catch is necessary because `import.meta` syntax itself causes a SyntaxError
|
|
180
|
+
* in CJS environments (Node require), not just an undefined value.
|
|
181
|
+
*/
|
|
182
|
+
function getDirectory() {
|
|
183
|
+
try {
|
|
184
|
+
const url = import.meta.url;
|
|
185
|
+
if (url && url !== "") return path$1.dirname(fileURLToPath(url));
|
|
186
|
+
} catch {}
|
|
187
|
+
if (typeof __dirname !== "undefined") return __dirname;
|
|
188
|
+
throw new Error("Unable to determine directory: neither import.meta.url nor __dirname available. This indicates an unsupported module environment.");
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* ESM-only module loader - simplified without eval() or CommonJS fallback
|
|
192
|
+
* Uses Node.js native ESM import with proper URL resolution
|
|
193
|
+
*/
|
|
194
|
+
async function importModule(modulePath, functionName) {
|
|
195
|
+
logger.debug(`Attempting to import module: ${JSON.stringify({
|
|
196
|
+
resolvedPath: safeResolve(modulePath),
|
|
197
|
+
moduleId: modulePath
|
|
198
|
+
})}`);
|
|
199
|
+
try {
|
|
200
|
+
if (modulePath.endsWith(".ts") || modulePath.endsWith(".mjs")) {
|
|
201
|
+
logger.debug("TypeScript/ESM module detected, importing tsx/cjs");
|
|
202
|
+
await import("tsx/cjs");
|
|
203
|
+
}
|
|
204
|
+
const resolvedPath = pathToFileURL(safeResolve(modulePath));
|
|
205
|
+
const resolvedPathStr = resolvedPath.toString();
|
|
206
|
+
logger.debug(`Attempting ESM import from: ${resolvedPathStr}`);
|
|
207
|
+
const importedModule = await import(resolvedPathStr);
|
|
208
|
+
const mod = importedModule?.default?.default || importedModule?.default || importedModule;
|
|
209
|
+
logger.debug(`Successfully imported module: ${JSON.stringify({
|
|
210
|
+
resolvedPath,
|
|
211
|
+
moduleId: modulePath
|
|
212
|
+
})}`);
|
|
213
|
+
if (functionName) {
|
|
214
|
+
logger.debug(`Returning named export: ${functionName}`);
|
|
215
|
+
return mod[functionName];
|
|
216
|
+
}
|
|
217
|
+
return mod;
|
|
218
|
+
} catch (err) {
|
|
219
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
220
|
+
if (modulePath.endsWith(".js") && isCjsInEsmError(errorMessage)) {
|
|
221
|
+
logger.debug(`ESM import failed for ${modulePath}, attempting vm-based CJS fallback: ${errorMessage}`);
|
|
222
|
+
try {
|
|
223
|
+
const resolvedPath = safeResolve(modulePath);
|
|
224
|
+
const mod = loadCjsModule(resolvedPath);
|
|
225
|
+
logger.debug(`Successfully loaded module via CJS fallback: ${JSON.stringify({
|
|
226
|
+
resolvedPath,
|
|
227
|
+
moduleId: modulePath
|
|
228
|
+
})}`);
|
|
229
|
+
if (functionName) {
|
|
230
|
+
logger.debug(`Returning named export: ${functionName}`);
|
|
231
|
+
return mod[functionName];
|
|
232
|
+
}
|
|
233
|
+
return mod;
|
|
234
|
+
} catch (cjsErr) {
|
|
235
|
+
const cjsErrorMessage = cjsErr instanceof Error ? cjsErr.message : String(cjsErr);
|
|
236
|
+
logger.error(`ESM import failed for ${modulePath}: ${errorMessage}`);
|
|
237
|
+
logger.error(`CJS fallback also failed: ${cjsErrorMessage}`);
|
|
238
|
+
const combinedError = /* @__PURE__ */ new Error(`Failed to load module ${modulePath}:\n ESM import error: ${errorMessage}\n CJS fallback error: ${cjsErrorMessage}\nTo fix this, either:\n 1. Rename the file to .cjs (recommended for CommonJS)\n 2. Convert to ESM syntax (import/export)\n 3. Ensure the file has valid JavaScript syntax`);
|
|
239
|
+
combinedError.cause = {
|
|
240
|
+
esmError: err,
|
|
241
|
+
cjsError: cjsErr
|
|
242
|
+
};
|
|
243
|
+
throw combinedError;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const e = err;
|
|
247
|
+
if (e.stack) logger.debug(e.stack);
|
|
248
|
+
if (err.code === "ERR_MODULE_NOT_FOUND") {
|
|
249
|
+
const resolvedModulePath = safeResolve(modulePath);
|
|
250
|
+
try {
|
|
251
|
+
await fsPromises.access(resolvedModulePath);
|
|
252
|
+
logger.error(`ESM import failed: ${err}`);
|
|
253
|
+
} catch {
|
|
254
|
+
const enoentError = /* @__PURE__ */ new Error(`ENOENT: no such file or directory, open '${resolvedModulePath}'`);
|
|
255
|
+
enoentError.code = "ENOENT";
|
|
256
|
+
enoentError.path = resolvedModulePath;
|
|
257
|
+
throw enoentError;
|
|
258
|
+
}
|
|
259
|
+
} else logger.error(`ESM import failed: ${err}`);
|
|
260
|
+
throw err;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Detects if an error message indicates a CommonJS module being loaded in ESM context.
|
|
265
|
+
*/
|
|
266
|
+
function isCjsInEsmError(message) {
|
|
267
|
+
return [
|
|
268
|
+
"require is not defined",
|
|
269
|
+
"module is not defined",
|
|
270
|
+
"exports is not defined",
|
|
271
|
+
"__dirname is not defined",
|
|
272
|
+
"__filename is not defined",
|
|
273
|
+
"Cannot use import statement",
|
|
274
|
+
"ERR_REQUIRE_ESM"
|
|
275
|
+
].some((pattern) => message.includes(pattern));
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Loads a CommonJS module by executing it in a vm context with proper CJS globals.
|
|
279
|
+
* This bypasses Node.js's module type detection which is based on package.json "type" field.
|
|
280
|
+
*
|
|
281
|
+
* SECURITY NOTE: This is NOT a security sandbox. The executed code has full access to
|
|
282
|
+
* the file system, network, etc. via the injected require function and process object.
|
|
283
|
+
* This is intentional - it's designed for loading trusted user configuration files
|
|
284
|
+
* (custom providers, assertions, hooks) that need full Node.js capabilities.
|
|
285
|
+
*/
|
|
286
|
+
function loadCjsModule(modulePath) {
|
|
287
|
+
const code = fs.readFileSync(modulePath, "utf-8");
|
|
288
|
+
const dirname = path$1.dirname(modulePath);
|
|
289
|
+
const filename = modulePath;
|
|
290
|
+
const moduleRequire = createRequire(pathToFileURL(modulePath).href);
|
|
291
|
+
const moduleObj = { exports: {} };
|
|
292
|
+
const context = vm.createContext({
|
|
293
|
+
module: moduleObj,
|
|
294
|
+
exports: moduleObj.exports,
|
|
295
|
+
require: moduleRequire,
|
|
296
|
+
__dirname: dirname,
|
|
297
|
+
__filename: filename,
|
|
298
|
+
global: globalThis,
|
|
299
|
+
globalThis,
|
|
300
|
+
console,
|
|
301
|
+
process,
|
|
302
|
+
Buffer,
|
|
303
|
+
setTimeout,
|
|
304
|
+
setInterval,
|
|
305
|
+
setImmediate,
|
|
306
|
+
clearTimeout,
|
|
307
|
+
clearInterval,
|
|
308
|
+
clearImmediate,
|
|
309
|
+
queueMicrotask,
|
|
310
|
+
URL,
|
|
311
|
+
URLSearchParams,
|
|
312
|
+
TextEncoder,
|
|
313
|
+
TextDecoder,
|
|
314
|
+
atob: globalThis.atob,
|
|
315
|
+
btoa: globalThis.btoa,
|
|
316
|
+
fetch: globalThis.fetch,
|
|
317
|
+
Request: globalThis.Request,
|
|
318
|
+
Response: globalThis.Response,
|
|
319
|
+
Headers: globalThis.Headers,
|
|
320
|
+
AbortController: globalThis.AbortController,
|
|
321
|
+
AbortSignal: globalThis.AbortSignal,
|
|
322
|
+
Event: globalThis.Event,
|
|
323
|
+
EventTarget: globalThis.EventTarget,
|
|
324
|
+
Error,
|
|
325
|
+
TypeError,
|
|
326
|
+
ReferenceError,
|
|
327
|
+
SyntaxError,
|
|
328
|
+
RangeError,
|
|
329
|
+
Array,
|
|
330
|
+
Object,
|
|
331
|
+
String,
|
|
332
|
+
Number,
|
|
333
|
+
Boolean,
|
|
334
|
+
Symbol,
|
|
335
|
+
Map,
|
|
336
|
+
Set,
|
|
337
|
+
WeakMap,
|
|
338
|
+
WeakSet,
|
|
339
|
+
Promise,
|
|
340
|
+
Proxy,
|
|
341
|
+
Reflect,
|
|
342
|
+
JSON,
|
|
343
|
+
Math,
|
|
344
|
+
Date,
|
|
345
|
+
RegExp,
|
|
346
|
+
Int8Array,
|
|
347
|
+
Uint8Array,
|
|
348
|
+
Uint8ClampedArray,
|
|
349
|
+
Int16Array,
|
|
350
|
+
Uint16Array,
|
|
351
|
+
Int32Array,
|
|
352
|
+
Uint32Array,
|
|
353
|
+
Float32Array,
|
|
354
|
+
Float64Array,
|
|
355
|
+
BigInt64Array,
|
|
356
|
+
BigUint64Array,
|
|
357
|
+
DataView,
|
|
358
|
+
ArrayBuffer,
|
|
359
|
+
SharedArrayBuffer: globalThis.SharedArrayBuffer,
|
|
360
|
+
Atomics: globalThis.Atomics,
|
|
361
|
+
BigInt,
|
|
362
|
+
eval: void 0,
|
|
363
|
+
Function,
|
|
364
|
+
isNaN,
|
|
365
|
+
isFinite,
|
|
366
|
+
parseFloat,
|
|
367
|
+
parseInt,
|
|
368
|
+
decodeURI,
|
|
369
|
+
decodeURIComponent,
|
|
370
|
+
encodeURI,
|
|
371
|
+
encodeURIComponent
|
|
372
|
+
});
|
|
373
|
+
vm.runInContext(code, context, { filename: modulePath });
|
|
374
|
+
return moduleObj.exports;
|
|
375
|
+
}
|
|
376
|
+
//#endregion
|
|
377
|
+
export { safeJoin as a, resolvePackageEntryPoint as i, getWrapperDir as n, safeResolve as o, importModule as r, getDirectory as t };
|
|
378
|
+
|
|
379
|
+
//# sourceMappingURL=esm-DMVc93eh.js.map
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
const require_logger = require("./logger-DyfK9PBt.cjs");
|
|
2
|
+
const require_types = require("./types-5aqHpBwE.cjs");
|
|
3
|
+
const require_fetch = require("./fetch-BTxakTSg.cjs");
|
|
4
|
+
const require_utils = require("./utils-yWamDvmz.cjs");
|
|
5
|
+
const require_tables = require("./tables-3Q2cL7So.cjs");
|
|
6
|
+
const require_extractor = require("./extractor-DnMD3fwt.cjs");
|
|
7
|
+
let drizzle_orm = require("drizzle-orm");
|
|
8
|
+
//#region src/models/evalResult.ts
|
|
9
|
+
function sanitizeProvider(provider) {
|
|
10
|
+
try {
|
|
11
|
+
if (require_types.isApiProvider(provider)) return {
|
|
12
|
+
id: provider.id(),
|
|
13
|
+
label: provider.label,
|
|
14
|
+
...provider.config && { config: JSON.parse(require_logger.safeJsonStringify(provider.config)) }
|
|
15
|
+
};
|
|
16
|
+
if (require_types.isProviderOptions(provider)) return {
|
|
17
|
+
id: provider.id,
|
|
18
|
+
label: provider.label,
|
|
19
|
+
...provider.config && { config: JSON.parse(require_logger.safeJsonStringify(provider.config)) }
|
|
20
|
+
};
|
|
21
|
+
if (typeof provider === "object" && provider) {
|
|
22
|
+
const providerObj = provider;
|
|
23
|
+
return {
|
|
24
|
+
id: typeof providerObj.id === "function" ? providerObj.id() : providerObj.id,
|
|
25
|
+
label: providerObj.label,
|
|
26
|
+
...providerObj.config && { config: JSON.parse(require_logger.safeJsonStringify(providerObj.config)) }
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
} catch {}
|
|
30
|
+
return JSON.parse(require_logger.safeJsonStringify(provider));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Sanitize an object for database storage by removing circular references
|
|
34
|
+
* and non-serializable values (functions, Timeout objects, etc.).
|
|
35
|
+
* Uses safeJsonStringify which handles circular references gracefully.
|
|
36
|
+
*
|
|
37
|
+
* This prevents "Converting circular structure to JSON" errors that can occur
|
|
38
|
+
* when Node.js Timeout objects or other non-serializable data leaks into results.
|
|
39
|
+
* See: https://github.com/promptfoo/promptfoo/issues/7266
|
|
40
|
+
*/
|
|
41
|
+
function sanitizeForDb(obj) {
|
|
42
|
+
if (obj === null || obj === void 0) return obj;
|
|
43
|
+
try {
|
|
44
|
+
const serialized = require_logger.safeJsonStringify(obj);
|
|
45
|
+
if (serialized === void 0) {
|
|
46
|
+
require_logger.logger.debug("sanitizeForDb: Failed to serialize object, using fallback", {
|
|
47
|
+
valueType: typeof obj,
|
|
48
|
+
isArray: Array.isArray(obj)
|
|
49
|
+
});
|
|
50
|
+
return Array.isArray(obj) ? [] : null;
|
|
51
|
+
}
|
|
52
|
+
return JSON.parse(serialized);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
require_logger.logger.debug("sanitizeForDb: Parse error, using fallback", { error });
|
|
55
|
+
return Array.isArray(obj) ? [] : null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
var EvalResult = class EvalResult {
|
|
59
|
+
static async createFromEvaluateResult(evalId, result, opts) {
|
|
60
|
+
const persist = opts?.persist == null ? true : opts.persist;
|
|
61
|
+
const { prompt, error, score, latencyMs, success, provider, gradingResult, namedScores, cost, metadata, failureReason, testCase } = result;
|
|
62
|
+
const preSanitizeTestCase = {
|
|
63
|
+
...testCase,
|
|
64
|
+
...testCase.provider && { provider: sanitizeProvider(testCase.provider) }
|
|
65
|
+
};
|
|
66
|
+
const processedResponse = await require_extractor.extractAndStoreBinaryData(result.response, {
|
|
67
|
+
evalId,
|
|
68
|
+
testIdx: result.testIdx,
|
|
69
|
+
promptIdx: result.promptIdx
|
|
70
|
+
});
|
|
71
|
+
const args = {
|
|
72
|
+
id: crypto.randomUUID(),
|
|
73
|
+
evalId,
|
|
74
|
+
testCase: sanitizeForDb(preSanitizeTestCase),
|
|
75
|
+
promptIdx: result.promptIdx,
|
|
76
|
+
testIdx: result.testIdx,
|
|
77
|
+
prompt: sanitizeForDb(prompt),
|
|
78
|
+
promptId: require_utils.hashPrompt(prompt),
|
|
79
|
+
error: error?.toString(),
|
|
80
|
+
success,
|
|
81
|
+
score: score == null ? 0 : score,
|
|
82
|
+
response: sanitizeForDb(processedResponse || null),
|
|
83
|
+
gradingResult: sanitizeForDb(gradingResult || null),
|
|
84
|
+
namedScores: sanitizeForDb(namedScores),
|
|
85
|
+
provider: sanitizeProvider(provider),
|
|
86
|
+
latencyMs,
|
|
87
|
+
cost,
|
|
88
|
+
metadata: sanitizeForDb(metadata),
|
|
89
|
+
failureReason
|
|
90
|
+
};
|
|
91
|
+
if (persist) return new EvalResult({
|
|
92
|
+
...(await require_tables.getDb().insert(require_tables.evalResultsTable).values(args).returning())[0],
|
|
93
|
+
persisted: true
|
|
94
|
+
});
|
|
95
|
+
return new EvalResult(args);
|
|
96
|
+
}
|
|
97
|
+
static async createManyFromEvaluateResult(results, evalId) {
|
|
98
|
+
const db = require_tables.getDb();
|
|
99
|
+
const returnResults = [];
|
|
100
|
+
const processedResults = [];
|
|
101
|
+
for (const result of results) {
|
|
102
|
+
const processedResponse = require_extractor.isBlobStorageEnabled() ? await require_extractor.extractAndStoreBinaryData(result.response, {
|
|
103
|
+
evalId,
|
|
104
|
+
testIdx: result.testIdx,
|
|
105
|
+
promptIdx: result.promptIdx
|
|
106
|
+
}) : result.response;
|
|
107
|
+
processedResults.push({
|
|
108
|
+
...result,
|
|
109
|
+
response: processedResponse ?? void 0
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
db.transaction(() => {
|
|
113
|
+
for (const result of processedResults) {
|
|
114
|
+
const sanitizedResult = {
|
|
115
|
+
...result,
|
|
116
|
+
testCase: sanitizeForDb(result.testCase),
|
|
117
|
+
prompt: sanitizeForDb(result.prompt),
|
|
118
|
+
response: sanitizeForDb(result.response),
|
|
119
|
+
gradingResult: sanitizeForDb(result.gradingResult),
|
|
120
|
+
namedScores: sanitizeForDb(result.namedScores),
|
|
121
|
+
metadata: sanitizeForDb(result.metadata),
|
|
122
|
+
provider: result.provider ? sanitizeProvider(result.provider) : result.provider
|
|
123
|
+
};
|
|
124
|
+
const dbResult = db.insert(require_tables.evalResultsTable).values({
|
|
125
|
+
...sanitizedResult,
|
|
126
|
+
evalId,
|
|
127
|
+
id: crypto.randomUUID()
|
|
128
|
+
}).returning().get();
|
|
129
|
+
returnResults.push(new EvalResult({
|
|
130
|
+
...dbResult,
|
|
131
|
+
persisted: true
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
return returnResults;
|
|
136
|
+
}
|
|
137
|
+
static async findById(id) {
|
|
138
|
+
const result = await require_tables.getDb().select().from(require_tables.evalResultsTable).where((0, drizzle_orm.eq)(require_tables.evalResultsTable.id, id));
|
|
139
|
+
return result.length > 0 ? new EvalResult({
|
|
140
|
+
...result[0],
|
|
141
|
+
persisted: true
|
|
142
|
+
}) : null;
|
|
143
|
+
}
|
|
144
|
+
static async findManyByEvalId(evalId, opts) {
|
|
145
|
+
return (await require_tables.getDb().select().from(require_tables.evalResultsTable).where((0, drizzle_orm.and)((0, drizzle_orm.eq)(require_tables.evalResultsTable.evalId, evalId), opts?.testIdx == null ? void 0 : (0, drizzle_orm.eq)(require_tables.evalResultsTable.testIdx, opts.testIdx)))).map((result) => new EvalResult({
|
|
146
|
+
...result,
|
|
147
|
+
persisted: true
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
static async findManyByEvalIdAndTestIndices(evalId, testIndices) {
|
|
151
|
+
if (!testIndices.length) return [];
|
|
152
|
+
return (await require_tables.getDb().select().from(require_tables.evalResultsTable).where((0, drizzle_orm.and)((0, drizzle_orm.eq)(require_tables.evalResultsTable.evalId, evalId), testIndices.length === 1 ? (0, drizzle_orm.eq)(require_tables.evalResultsTable.testIdx, testIndices[0]) : (0, drizzle_orm.inArray)(require_tables.evalResultsTable.testIdx, testIndices)))).map((result) => new EvalResult({
|
|
153
|
+
...result,
|
|
154
|
+
persisted: true
|
|
155
|
+
}));
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Returns a set of completed (testIdx,promptIdx) pairs for a given eval.
|
|
159
|
+
* Key format: `${testIdx}:${promptIdx}`
|
|
160
|
+
*
|
|
161
|
+
* @param evalId - The evaluation ID to query
|
|
162
|
+
* @param opts.excludeErrors - If true, excludes results with ERROR failureReason (used in retry mode)
|
|
163
|
+
*/
|
|
164
|
+
static async getCompletedIndexPairs(evalId, opts) {
|
|
165
|
+
const db = require_tables.getDb();
|
|
166
|
+
const whereClause = opts?.excludeErrors ? (0, drizzle_orm.and)((0, drizzle_orm.eq)(require_tables.evalResultsTable.evalId, evalId), (0, drizzle_orm.ne)(require_tables.evalResultsTable.failureReason, require_types.ResultFailureReason.ERROR)) : (0, drizzle_orm.eq)(require_tables.evalResultsTable.evalId, evalId);
|
|
167
|
+
const rows = await db.select({
|
|
168
|
+
testIdx: require_tables.evalResultsTable.testIdx,
|
|
169
|
+
promptIdx: require_tables.evalResultsTable.promptIdx
|
|
170
|
+
}).from(require_tables.evalResultsTable).where(whereClause);
|
|
171
|
+
const ret = /* @__PURE__ */ new Set();
|
|
172
|
+
for (const r of rows) ret.add(`${r.testIdx}:${r.promptIdx}`);
|
|
173
|
+
return ret;
|
|
174
|
+
}
|
|
175
|
+
static async *findManyByEvalIdBatched(evalId, opts) {
|
|
176
|
+
const db = require_tables.getDb();
|
|
177
|
+
const batchSize = opts?.batchSize || 100;
|
|
178
|
+
let offset = 0;
|
|
179
|
+
while (true) {
|
|
180
|
+
const results = await db.select().from(require_tables.evalResultsTable).where((0, drizzle_orm.and)((0, drizzle_orm.eq)(require_tables.evalResultsTable.evalId, evalId), (0, drizzle_orm.gte)(require_tables.evalResultsTable.testIdx, offset), (0, drizzle_orm.lt)(require_tables.evalResultsTable.testIdx, offset + batchSize))).all();
|
|
181
|
+
if (results.length === 0) break;
|
|
182
|
+
yield results.map((result) => new EvalResult({
|
|
183
|
+
...result,
|
|
184
|
+
persisted: true
|
|
185
|
+
}));
|
|
186
|
+
offset += batchSize;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
id;
|
|
190
|
+
evalId;
|
|
191
|
+
description;
|
|
192
|
+
promptIdx;
|
|
193
|
+
testIdx;
|
|
194
|
+
testCase;
|
|
195
|
+
prompt;
|
|
196
|
+
promptId;
|
|
197
|
+
error;
|
|
198
|
+
success;
|
|
199
|
+
score;
|
|
200
|
+
response;
|
|
201
|
+
gradingResult;
|
|
202
|
+
namedScores;
|
|
203
|
+
provider;
|
|
204
|
+
latencyMs;
|
|
205
|
+
cost;
|
|
206
|
+
metadata;
|
|
207
|
+
failureReason;
|
|
208
|
+
persisted;
|
|
209
|
+
pluginId;
|
|
210
|
+
constructor(opts) {
|
|
211
|
+
this.id = opts.id;
|
|
212
|
+
this.evalId = opts.evalId;
|
|
213
|
+
this.promptIdx = opts.promptIdx;
|
|
214
|
+
this.testIdx = opts.testIdx;
|
|
215
|
+
this.testCase = opts.testCase;
|
|
216
|
+
this.prompt = opts.prompt;
|
|
217
|
+
this.promptId = opts.promptId || require_utils.hashPrompt(opts.prompt);
|
|
218
|
+
this.error = opts.error;
|
|
219
|
+
this.score = opts.score;
|
|
220
|
+
this.success = opts.success;
|
|
221
|
+
this.response = opts.response || void 0;
|
|
222
|
+
this.gradingResult = opts.gradingResult;
|
|
223
|
+
this.namedScores = opts.namedScores || {};
|
|
224
|
+
this.provider = opts.provider;
|
|
225
|
+
this.latencyMs = opts.latencyMs || 0;
|
|
226
|
+
this.cost = opts.cost || 0;
|
|
227
|
+
this.metadata = opts.metadata || {};
|
|
228
|
+
this.failureReason = require_types.isResultFailureReason(opts.failureReason) ? opts.failureReason : require_types.ResultFailureReason.NONE;
|
|
229
|
+
this.persisted = opts.persisted || false;
|
|
230
|
+
this.pluginId = opts.testCase.metadata?.pluginId;
|
|
231
|
+
}
|
|
232
|
+
async save() {
|
|
233
|
+
const db = require_tables.getDb();
|
|
234
|
+
if (this.persisted) await db.update(require_tables.evalResultsTable).set({
|
|
235
|
+
...this,
|
|
236
|
+
updatedAt: require_fetch.getCurrentTimestamp()
|
|
237
|
+
}).where((0, drizzle_orm.eq)(require_tables.evalResultsTable.id, this.id));
|
|
238
|
+
else {
|
|
239
|
+
this.id = (await db.insert(require_tables.evalResultsTable).values(this).returning())[0].id;
|
|
240
|
+
this.persisted = true;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
toEvaluateResult() {
|
|
244
|
+
const shouldStripPromptText = require_logger.getEnvBool("PROMPTFOO_STRIP_PROMPT_TEXT", false);
|
|
245
|
+
const shouldStripResponseOutput = require_logger.getEnvBool("PROMPTFOO_STRIP_RESPONSE_OUTPUT", false);
|
|
246
|
+
const shouldStripTestVars = require_logger.getEnvBool("PROMPTFOO_STRIP_TEST_VARS", false);
|
|
247
|
+
const shouldStripGradingResult = require_logger.getEnvBool("PROMPTFOO_STRIP_GRADING_RESULT", false);
|
|
248
|
+
const shouldStripMetadata = require_logger.getEnvBool("PROMPTFOO_STRIP_METADATA", false);
|
|
249
|
+
const response = shouldStripResponseOutput && this.response ? {
|
|
250
|
+
...this.response,
|
|
251
|
+
output: "[output stripped]"
|
|
252
|
+
} : this.response;
|
|
253
|
+
const prompt = shouldStripPromptText ? {
|
|
254
|
+
...this.prompt,
|
|
255
|
+
raw: "[prompt stripped]"
|
|
256
|
+
} : this.prompt;
|
|
257
|
+
const testCase = shouldStripTestVars ? {
|
|
258
|
+
...this.testCase,
|
|
259
|
+
vars: void 0
|
|
260
|
+
} : this.testCase;
|
|
261
|
+
return {
|
|
262
|
+
cost: this.cost,
|
|
263
|
+
description: this.description || void 0,
|
|
264
|
+
error: this.error || void 0,
|
|
265
|
+
gradingResult: shouldStripGradingResult ? null : this.gradingResult,
|
|
266
|
+
id: this.id,
|
|
267
|
+
latencyMs: this.latencyMs,
|
|
268
|
+
namedScores: this.namedScores,
|
|
269
|
+
prompt,
|
|
270
|
+
promptId: this.promptId,
|
|
271
|
+
promptIdx: this.promptIdx,
|
|
272
|
+
provider: {
|
|
273
|
+
id: this.provider.id,
|
|
274
|
+
label: this.provider.label
|
|
275
|
+
},
|
|
276
|
+
response,
|
|
277
|
+
score: this.score,
|
|
278
|
+
success: this.success,
|
|
279
|
+
testCase,
|
|
280
|
+
testIdx: this.testIdx,
|
|
281
|
+
vars: shouldStripTestVars ? {} : this.testCase.vars || {},
|
|
282
|
+
metadata: shouldStripMetadata ? {} : this.metadata,
|
|
283
|
+
failureReason: this.failureReason
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
//#endregion
|
|
288
|
+
Object.defineProperty(exports, "EvalResult", {
|
|
289
|
+
enumerable: true,
|
|
290
|
+
get: function() {
|
|
291
|
+
return EvalResult;
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
Object.defineProperty(exports, "sanitizeProvider", {
|
|
295
|
+
enumerable: true,
|
|
296
|
+
get: function() {
|
|
297
|
+
return sanitizeProvider;
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
//# sourceMappingURL=evalResult-C3NJPQOo.cjs.map
|