@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,409 @@
|
|
|
1
|
+
const require_logger = require("./logger-DyfK9PBt.cjs");
|
|
2
|
+
let path = require("path");
|
|
3
|
+
path = require_logger.__toESM(path);
|
|
4
|
+
let node_fs = require("node:fs");
|
|
5
|
+
node_fs = require_logger.__toESM(node_fs);
|
|
6
|
+
let node_fs_promises = require("node:fs/promises");
|
|
7
|
+
node_fs_promises = require_logger.__toESM(node_fs_promises);
|
|
8
|
+
let node_module = require("node:module");
|
|
9
|
+
let node_path = require("node:path");
|
|
10
|
+
node_path = require_logger.__toESM(node_path);
|
|
11
|
+
let node_url = require("node:url");
|
|
12
|
+
let node_vm = require("node:vm");
|
|
13
|
+
node_vm = require_logger.__toESM(node_vm);
|
|
14
|
+
let exsolve = require("exsolve");
|
|
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.default.isAbsolute((0, node_url.fileURLToPath)(filePath));
|
|
29
|
+
} catch {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return path.default.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.default.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.default.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 = node_path.default.join(baseDir, WRAPPER_SUBDIRS[type]);
|
|
106
|
+
wrapperDirCache[type] = result;
|
|
107
|
+
require_logger.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 = (0, node_url.pathToFileURL)(node_path.default.join(baseDir, "package.json")).href;
|
|
155
|
+
const resolved = (0, exsolve.resolveModulePath)(packageName, {
|
|
156
|
+
from,
|
|
157
|
+
conditions: [
|
|
158
|
+
"node",
|
|
159
|
+
"import",
|
|
160
|
+
"require",
|
|
161
|
+
"default"
|
|
162
|
+
],
|
|
163
|
+
try: true
|
|
164
|
+
});
|
|
165
|
+
return resolved ? node_path.default.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
|
+
return __dirname;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* ESM-only module loader - simplified without eval() or CommonJS fallback
|
|
187
|
+
* Uses Node.js native ESM import with proper URL resolution
|
|
188
|
+
*/
|
|
189
|
+
async function importModule(modulePath, functionName) {
|
|
190
|
+
require_logger.logger.debug(`Attempting to import module: ${JSON.stringify({
|
|
191
|
+
resolvedPath: safeResolve(modulePath),
|
|
192
|
+
moduleId: modulePath
|
|
193
|
+
})}`);
|
|
194
|
+
try {
|
|
195
|
+
if (modulePath.endsWith(".ts") || modulePath.endsWith(".mjs")) {
|
|
196
|
+
require_logger.logger.debug("TypeScript/ESM module detected, importing tsx/cjs");
|
|
197
|
+
await import("tsx/cjs");
|
|
198
|
+
}
|
|
199
|
+
const resolvedPath = (0, node_url.pathToFileURL)(safeResolve(modulePath));
|
|
200
|
+
const resolvedPathStr = resolvedPath.toString();
|
|
201
|
+
require_logger.logger.debug(`Attempting ESM import from: ${resolvedPathStr}`);
|
|
202
|
+
const importedModule = await import(resolvedPathStr);
|
|
203
|
+
const mod = importedModule?.default?.default || importedModule?.default || importedModule;
|
|
204
|
+
require_logger.logger.debug(`Successfully imported module: ${JSON.stringify({
|
|
205
|
+
resolvedPath,
|
|
206
|
+
moduleId: modulePath
|
|
207
|
+
})}`);
|
|
208
|
+
if (functionName) {
|
|
209
|
+
require_logger.logger.debug(`Returning named export: ${functionName}`);
|
|
210
|
+
return mod[functionName];
|
|
211
|
+
}
|
|
212
|
+
return mod;
|
|
213
|
+
} catch (err) {
|
|
214
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
215
|
+
if (modulePath.endsWith(".js") && isCjsInEsmError(errorMessage)) {
|
|
216
|
+
require_logger.logger.debug(`ESM import failed for ${modulePath}, attempting vm-based CJS fallback: ${errorMessage}`);
|
|
217
|
+
try {
|
|
218
|
+
const resolvedPath = safeResolve(modulePath);
|
|
219
|
+
const mod = loadCjsModule(resolvedPath);
|
|
220
|
+
require_logger.logger.debug(`Successfully loaded module via CJS fallback: ${JSON.stringify({
|
|
221
|
+
resolvedPath,
|
|
222
|
+
moduleId: modulePath
|
|
223
|
+
})}`);
|
|
224
|
+
if (functionName) {
|
|
225
|
+
require_logger.logger.debug(`Returning named export: ${functionName}`);
|
|
226
|
+
return mod[functionName];
|
|
227
|
+
}
|
|
228
|
+
return mod;
|
|
229
|
+
} catch (cjsErr) {
|
|
230
|
+
const cjsErrorMessage = cjsErr instanceof Error ? cjsErr.message : String(cjsErr);
|
|
231
|
+
require_logger.logger.error(`ESM import failed for ${modulePath}: ${errorMessage}`);
|
|
232
|
+
require_logger.logger.error(`CJS fallback also failed: ${cjsErrorMessage}`);
|
|
233
|
+
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`);
|
|
234
|
+
combinedError.cause = {
|
|
235
|
+
esmError: err,
|
|
236
|
+
cjsError: cjsErr
|
|
237
|
+
};
|
|
238
|
+
throw combinedError;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const e = err;
|
|
242
|
+
if (e.stack) require_logger.logger.debug(e.stack);
|
|
243
|
+
if (err.code === "ERR_MODULE_NOT_FOUND") {
|
|
244
|
+
const resolvedModulePath = safeResolve(modulePath);
|
|
245
|
+
try {
|
|
246
|
+
await node_fs_promises.default.access(resolvedModulePath);
|
|
247
|
+
require_logger.logger.error(`ESM import failed: ${err}`);
|
|
248
|
+
} catch {
|
|
249
|
+
const enoentError = /* @__PURE__ */ new Error(`ENOENT: no such file or directory, open '${resolvedModulePath}'`);
|
|
250
|
+
enoentError.code = "ENOENT";
|
|
251
|
+
enoentError.path = resolvedModulePath;
|
|
252
|
+
throw enoentError;
|
|
253
|
+
}
|
|
254
|
+
} else require_logger.logger.error(`ESM import failed: ${err}`);
|
|
255
|
+
throw err;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Detects if an error message indicates a CommonJS module being loaded in ESM context.
|
|
260
|
+
*/
|
|
261
|
+
function isCjsInEsmError(message) {
|
|
262
|
+
return [
|
|
263
|
+
"require is not defined",
|
|
264
|
+
"module is not defined",
|
|
265
|
+
"exports is not defined",
|
|
266
|
+
"__dirname is not defined",
|
|
267
|
+
"__filename is not defined",
|
|
268
|
+
"Cannot use import statement",
|
|
269
|
+
"ERR_REQUIRE_ESM"
|
|
270
|
+
].some((pattern) => message.includes(pattern));
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Loads a CommonJS module by executing it in a vm context with proper CJS globals.
|
|
274
|
+
* This bypasses Node.js's module type detection which is based on package.json "type" field.
|
|
275
|
+
*
|
|
276
|
+
* SECURITY NOTE: This is NOT a security sandbox. The executed code has full access to
|
|
277
|
+
* the file system, network, etc. via the injected require function and process object.
|
|
278
|
+
* This is intentional - it's designed for loading trusted user configuration files
|
|
279
|
+
* (custom providers, assertions, hooks) that need full Node.js capabilities.
|
|
280
|
+
*/
|
|
281
|
+
function loadCjsModule(modulePath) {
|
|
282
|
+
const code = node_fs.default.readFileSync(modulePath, "utf-8");
|
|
283
|
+
const dirname = node_path.default.dirname(modulePath);
|
|
284
|
+
const filename = modulePath;
|
|
285
|
+
const moduleRequire = (0, node_module.createRequire)((0, node_url.pathToFileURL)(modulePath).href);
|
|
286
|
+
const moduleObj = { exports: {} };
|
|
287
|
+
const context = node_vm.default.createContext({
|
|
288
|
+
module: moduleObj,
|
|
289
|
+
exports: moduleObj.exports,
|
|
290
|
+
require: moduleRequire,
|
|
291
|
+
__dirname: dirname,
|
|
292
|
+
__filename: filename,
|
|
293
|
+
global: globalThis,
|
|
294
|
+
globalThis,
|
|
295
|
+
console,
|
|
296
|
+
process,
|
|
297
|
+
Buffer,
|
|
298
|
+
setTimeout,
|
|
299
|
+
setInterval,
|
|
300
|
+
setImmediate,
|
|
301
|
+
clearTimeout,
|
|
302
|
+
clearInterval,
|
|
303
|
+
clearImmediate,
|
|
304
|
+
queueMicrotask,
|
|
305
|
+
URL,
|
|
306
|
+
URLSearchParams,
|
|
307
|
+
TextEncoder,
|
|
308
|
+
TextDecoder,
|
|
309
|
+
atob: globalThis.atob,
|
|
310
|
+
btoa: globalThis.btoa,
|
|
311
|
+
fetch: globalThis.fetch,
|
|
312
|
+
Request: globalThis.Request,
|
|
313
|
+
Response: globalThis.Response,
|
|
314
|
+
Headers: globalThis.Headers,
|
|
315
|
+
AbortController: globalThis.AbortController,
|
|
316
|
+
AbortSignal: globalThis.AbortSignal,
|
|
317
|
+
Event: globalThis.Event,
|
|
318
|
+
EventTarget: globalThis.EventTarget,
|
|
319
|
+
Error,
|
|
320
|
+
TypeError,
|
|
321
|
+
ReferenceError,
|
|
322
|
+
SyntaxError,
|
|
323
|
+
RangeError,
|
|
324
|
+
Array,
|
|
325
|
+
Object,
|
|
326
|
+
String,
|
|
327
|
+
Number,
|
|
328
|
+
Boolean,
|
|
329
|
+
Symbol,
|
|
330
|
+
Map,
|
|
331
|
+
Set,
|
|
332
|
+
WeakMap,
|
|
333
|
+
WeakSet,
|
|
334
|
+
Promise,
|
|
335
|
+
Proxy,
|
|
336
|
+
Reflect,
|
|
337
|
+
JSON,
|
|
338
|
+
Math,
|
|
339
|
+
Date,
|
|
340
|
+
RegExp,
|
|
341
|
+
Int8Array,
|
|
342
|
+
Uint8Array,
|
|
343
|
+
Uint8ClampedArray,
|
|
344
|
+
Int16Array,
|
|
345
|
+
Uint16Array,
|
|
346
|
+
Int32Array,
|
|
347
|
+
Uint32Array,
|
|
348
|
+
Float32Array,
|
|
349
|
+
Float64Array,
|
|
350
|
+
BigInt64Array,
|
|
351
|
+
BigUint64Array,
|
|
352
|
+
DataView,
|
|
353
|
+
ArrayBuffer,
|
|
354
|
+
SharedArrayBuffer: globalThis.SharedArrayBuffer,
|
|
355
|
+
Atomics: globalThis.Atomics,
|
|
356
|
+
BigInt,
|
|
357
|
+
eval: void 0,
|
|
358
|
+
Function,
|
|
359
|
+
isNaN,
|
|
360
|
+
isFinite,
|
|
361
|
+
parseFloat,
|
|
362
|
+
parseInt,
|
|
363
|
+
decodeURI,
|
|
364
|
+
decodeURIComponent,
|
|
365
|
+
encodeURI,
|
|
366
|
+
encodeURIComponent
|
|
367
|
+
});
|
|
368
|
+
node_vm.default.runInContext(code, context, { filename: modulePath });
|
|
369
|
+
return moduleObj.exports;
|
|
370
|
+
}
|
|
371
|
+
//#endregion
|
|
372
|
+
Object.defineProperty(exports, "getDirectory", {
|
|
373
|
+
enumerable: true,
|
|
374
|
+
get: function() {
|
|
375
|
+
return getDirectory;
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
Object.defineProperty(exports, "getWrapperDir", {
|
|
379
|
+
enumerable: true,
|
|
380
|
+
get: function() {
|
|
381
|
+
return getWrapperDir;
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
Object.defineProperty(exports, "importModule", {
|
|
385
|
+
enumerable: true,
|
|
386
|
+
get: function() {
|
|
387
|
+
return importModule;
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
Object.defineProperty(exports, "resolvePackageEntryPoint", {
|
|
391
|
+
enumerable: true,
|
|
392
|
+
get: function() {
|
|
393
|
+
return resolvePackageEntryPoint;
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
Object.defineProperty(exports, "safeJoin", {
|
|
397
|
+
enumerable: true,
|
|
398
|
+
get: function() {
|
|
399
|
+
return safeJoin;
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
Object.defineProperty(exports, "safeResolve", {
|
|
403
|
+
enumerable: true,
|
|
404
|
+
get: function() {
|
|
405
|
+
return safeResolve;
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
//# sourceMappingURL=esm-C62Zofr1.cjs.map
|