evaliphy 1.0.1-beta.0

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.
@@ -0,0 +1,355 @@
1
+ const require_token_error$1 = require("./token-error-C8wr5ChX.cjs");
2
+ //#region node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/token-io.js
3
+ var require_token_io = /* @__PURE__ */ require_token_error$1.__commonJSMin(((exports, module) => {
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __export = (target, all) => {
11
+ for (var name in all) __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
19
+ get: () => from[key],
20
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
21
+ });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: true
28
+ }) : target, mod));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var token_io_exports = {};
31
+ __export(token_io_exports, {
32
+ findRootDir: () => findRootDir,
33
+ getUserDataDir: () => getUserDataDir
34
+ });
35
+ module.exports = __toCommonJS(token_io_exports);
36
+ var import_path = __toESM(require("path"));
37
+ var import_fs = __toESM(require("fs"));
38
+ var import_os$1 = __toESM(require("os"));
39
+ var import_token_error = require_token_error$1.require_token_error();
40
+ function findRootDir() {
41
+ try {
42
+ let dir = process.cwd();
43
+ while (dir !== import_path.default.dirname(dir)) {
44
+ const pkgPath = import_path.default.join(dir, ".vercel");
45
+ if (import_fs.default.existsSync(pkgPath)) return dir;
46
+ dir = import_path.default.dirname(dir);
47
+ }
48
+ } catch (e) {
49
+ throw new import_token_error.VercelOidcTokenError("Token refresh only supported in node server environments");
50
+ }
51
+ return null;
52
+ }
53
+ function getUserDataDir() {
54
+ if (process.env.XDG_DATA_HOME) return process.env.XDG_DATA_HOME;
55
+ switch (import_os$1.default.platform()) {
56
+ case "darwin": return import_path.default.join(import_os$1.default.homedir(), "Library/Application Support");
57
+ case "linux": return import_path.default.join(import_os$1.default.homedir(), ".local/share");
58
+ case "win32":
59
+ if (process.env.LOCALAPPDATA) return process.env.LOCALAPPDATA;
60
+ return null;
61
+ default: return null;
62
+ }
63
+ }
64
+ }));
65
+ //#endregion
66
+ //#region node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/auth-config.js
67
+ var require_auth_config = /* @__PURE__ */ require_token_error$1.__commonJSMin(((exports, module) => {
68
+ var __create = Object.create;
69
+ var __defProp = Object.defineProperty;
70
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
71
+ var __getOwnPropNames = Object.getOwnPropertyNames;
72
+ var __getProtoOf = Object.getPrototypeOf;
73
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
74
+ var __export = (target, all) => {
75
+ for (var name in all) __defProp(target, name, {
76
+ get: all[name],
77
+ enumerable: true
78
+ });
79
+ };
80
+ var __copyProps = (to, from, except, desc) => {
81
+ if (from && typeof from === "object" || typeof from === "function") {
82
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
83
+ get: () => from[key],
84
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
85
+ });
86
+ }
87
+ return to;
88
+ };
89
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
90
+ value: mod,
91
+ enumerable: true
92
+ }) : target, mod));
93
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
94
+ var auth_config_exports = {};
95
+ __export(auth_config_exports, {
96
+ isValidAccessToken: () => isValidAccessToken,
97
+ readAuthConfig: () => readAuthConfig,
98
+ writeAuthConfig: () => writeAuthConfig
99
+ });
100
+ module.exports = __toCommonJS(auth_config_exports);
101
+ var fs$1 = __toESM(require("fs"));
102
+ var path$1 = __toESM(require("path"));
103
+ var import_token_util = require_token_util();
104
+ function getAuthConfigPath() {
105
+ const dataDir = (0, import_token_util.getVercelDataDir)();
106
+ if (!dataDir) throw new Error(`Unable to find Vercel CLI data directory. Your platform: ${process.platform}. Supported: darwin, linux, win32.`);
107
+ return path$1.join(dataDir, "auth.json");
108
+ }
109
+ function readAuthConfig() {
110
+ try {
111
+ const authPath = getAuthConfigPath();
112
+ if (!fs$1.existsSync(authPath)) return null;
113
+ const content = fs$1.readFileSync(authPath, "utf8");
114
+ if (!content) return null;
115
+ return JSON.parse(content);
116
+ } catch (error) {
117
+ return null;
118
+ }
119
+ }
120
+ function writeAuthConfig(config) {
121
+ const authPath = getAuthConfigPath();
122
+ const authDir = path$1.dirname(authPath);
123
+ if (!fs$1.existsSync(authDir)) fs$1.mkdirSync(authDir, {
124
+ mode: 504,
125
+ recursive: true
126
+ });
127
+ fs$1.writeFileSync(authPath, JSON.stringify(config, null, 2), { mode: 384 });
128
+ }
129
+ function isValidAccessToken(authConfig) {
130
+ if (!authConfig.token) return false;
131
+ if (typeof authConfig.expiresAt !== "number") return true;
132
+ const nowInSeconds = Math.floor(Date.now() / 1e3);
133
+ return authConfig.expiresAt >= nowInSeconds;
134
+ }
135
+ }));
136
+ //#endregion
137
+ //#region node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/oauth.js
138
+ var require_oauth = /* @__PURE__ */ require_token_error$1.__commonJSMin(((exports, module) => {
139
+ var __defProp = Object.defineProperty;
140
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
141
+ var __getOwnPropNames = Object.getOwnPropertyNames;
142
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
143
+ var __export = (target, all) => {
144
+ for (var name in all) __defProp(target, name, {
145
+ get: all[name],
146
+ enumerable: true
147
+ });
148
+ };
149
+ var __copyProps = (to, from, except, desc) => {
150
+ if (from && typeof from === "object" || typeof from === "function") {
151
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
152
+ get: () => from[key],
153
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
154
+ });
155
+ }
156
+ return to;
157
+ };
158
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
159
+ var oauth_exports = {};
160
+ __export(oauth_exports, {
161
+ processTokenResponse: () => processTokenResponse,
162
+ refreshTokenRequest: () => refreshTokenRequest
163
+ });
164
+ module.exports = __toCommonJS(oauth_exports);
165
+ var import_os = require("os");
166
+ const VERCEL_ISSUER = "https://vercel.com";
167
+ const VERCEL_CLI_CLIENT_ID = "cl_HYyOPBNtFMfHhaUn9L4QPfTZz6TP47bp";
168
+ const userAgent = `@vercel/oidc node-${process.version} ${(0, import_os.platform)()} (${(0, import_os.arch)()}) ${(0, import_os.hostname)()}`;
169
+ let _tokenEndpoint = null;
170
+ async function getTokenEndpoint() {
171
+ if (_tokenEndpoint) return _tokenEndpoint;
172
+ const discoveryUrl = `${VERCEL_ISSUER}/.well-known/openid-configuration`;
173
+ const response = await fetch(discoveryUrl, { headers: { "user-agent": userAgent } });
174
+ if (!response.ok) throw new Error("Failed to discover OAuth endpoints");
175
+ const metadata = await response.json();
176
+ if (!metadata || typeof metadata.token_endpoint !== "string") throw new Error("Invalid OAuth discovery response");
177
+ const endpoint = metadata.token_endpoint;
178
+ _tokenEndpoint = endpoint;
179
+ return endpoint;
180
+ }
181
+ async function refreshTokenRequest(options) {
182
+ const tokenEndpoint = await getTokenEndpoint();
183
+ return await fetch(tokenEndpoint, {
184
+ method: "POST",
185
+ headers: {
186
+ "Content-Type": "application/x-www-form-urlencoded",
187
+ "user-agent": userAgent
188
+ },
189
+ body: new URLSearchParams({
190
+ client_id: VERCEL_CLI_CLIENT_ID,
191
+ grant_type: "refresh_token",
192
+ ...options
193
+ })
194
+ });
195
+ }
196
+ async function processTokenResponse(response) {
197
+ const json = await response.json();
198
+ if (!response.ok) {
199
+ const errorMsg = typeof json === "object" && json && "error" in json ? String(json.error) : "Token refresh failed";
200
+ return [new Error(errorMsg)];
201
+ }
202
+ if (typeof json !== "object" || json === null) return [/* @__PURE__ */ new Error("Invalid token response")];
203
+ if (typeof json.access_token !== "string") return [/* @__PURE__ */ new Error("Missing access_token in response")];
204
+ if (json.token_type !== "Bearer") return [/* @__PURE__ */ new Error("Invalid token_type in response")];
205
+ if (typeof json.expires_in !== "number") return [/* @__PURE__ */ new Error("Missing expires_in in response")];
206
+ return [null, json];
207
+ }
208
+ }));
209
+ //#endregion
210
+ //#region node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/token-util.js
211
+ var require_token_util = /* @__PURE__ */ require_token_error$1.__commonJSMin(((exports, module) => {
212
+ var __create = Object.create;
213
+ var __defProp = Object.defineProperty;
214
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
215
+ var __getOwnPropNames = Object.getOwnPropertyNames;
216
+ var __getProtoOf = Object.getPrototypeOf;
217
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
218
+ var __export = (target, all) => {
219
+ for (var name in all) __defProp(target, name, {
220
+ get: all[name],
221
+ enumerable: true
222
+ });
223
+ };
224
+ var __copyProps = (to, from, except, desc) => {
225
+ if (from && typeof from === "object" || typeof from === "function") {
226
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
227
+ get: () => from[key],
228
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
229
+ });
230
+ }
231
+ return to;
232
+ };
233
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
234
+ value: mod,
235
+ enumerable: true
236
+ }) : target, mod));
237
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
238
+ var token_util_exports = {};
239
+ __export(token_util_exports, {
240
+ assertVercelOidcTokenResponse: () => assertVercelOidcTokenResponse,
241
+ findProjectInfo: () => findProjectInfo,
242
+ getTokenPayload: () => getTokenPayload,
243
+ getVercelCliToken: () => getVercelCliToken,
244
+ getVercelDataDir: () => getVercelDataDir,
245
+ getVercelOidcToken: () => getVercelOidcToken,
246
+ isExpired: () => isExpired,
247
+ loadToken: () => loadToken,
248
+ saveToken: () => saveToken
249
+ });
250
+ module.exports = __toCommonJS(token_util_exports);
251
+ var path = __toESM(require("path"));
252
+ var fs = __toESM(require("fs"));
253
+ var import_token_error = require_token_error$1.require_token_error();
254
+ var import_token_io = require_token_io();
255
+ var import_auth_config = require_auth_config();
256
+ var import_oauth = require_oauth();
257
+ function getVercelDataDir() {
258
+ const vercelFolder = "com.vercel.cli";
259
+ const dataDir = (0, import_token_io.getUserDataDir)();
260
+ if (!dataDir) return null;
261
+ return path.join(dataDir, vercelFolder);
262
+ }
263
+ async function getVercelCliToken() {
264
+ const authConfig = (0, import_auth_config.readAuthConfig)();
265
+ if (!authConfig) return null;
266
+ if ((0, import_auth_config.isValidAccessToken)(authConfig)) return authConfig.token || null;
267
+ if (!authConfig.refreshToken) {
268
+ (0, import_auth_config.writeAuthConfig)({});
269
+ return null;
270
+ }
271
+ try {
272
+ const tokenResponse = await (0, import_oauth.refreshTokenRequest)({ refresh_token: authConfig.refreshToken });
273
+ const [tokensError, tokens] = await (0, import_oauth.processTokenResponse)(tokenResponse);
274
+ if (tokensError || !tokens) {
275
+ (0, import_auth_config.writeAuthConfig)({});
276
+ return null;
277
+ }
278
+ const updatedConfig = {
279
+ token: tokens.access_token,
280
+ expiresAt: Math.floor(Date.now() / 1e3) + tokens.expires_in
281
+ };
282
+ if (tokens.refresh_token) updatedConfig.refreshToken = tokens.refresh_token;
283
+ (0, import_auth_config.writeAuthConfig)(updatedConfig);
284
+ return updatedConfig.token ?? null;
285
+ } catch (error) {
286
+ (0, import_auth_config.writeAuthConfig)({});
287
+ return null;
288
+ }
289
+ }
290
+ async function getVercelOidcToken(authToken, projectId, teamId) {
291
+ const url = `https://api.vercel.com/v1/projects/${projectId}/token?source=vercel-oidc-refresh${teamId ? `&teamId=${teamId}` : ""}`;
292
+ const res = await fetch(url, {
293
+ method: "POST",
294
+ headers: { Authorization: `Bearer ${authToken}` }
295
+ });
296
+ if (!res.ok) throw new import_token_error.VercelOidcTokenError(`Failed to refresh OIDC token: ${res.statusText}`);
297
+ const tokenRes = await res.json();
298
+ assertVercelOidcTokenResponse(tokenRes);
299
+ return tokenRes;
300
+ }
301
+ function assertVercelOidcTokenResponse(res) {
302
+ if (!res || typeof res !== "object") throw new TypeError("Vercel OIDC token is malformed. Expected an object. Please run `vc env pull` and try again");
303
+ if (!("token" in res) || typeof res.token !== "string") throw new TypeError("Vercel OIDC token is malformed. Expected a string-valued token property. Please run `vc env pull` and try again");
304
+ }
305
+ function findProjectInfo() {
306
+ const dir = (0, import_token_io.findRootDir)();
307
+ if (!dir) throw new import_token_error.VercelOidcTokenError("Unable to find project root directory. Have you linked your project with `vc link?`");
308
+ const prjPath = path.join(dir, ".vercel", "project.json");
309
+ if (!fs.existsSync(prjPath)) throw new import_token_error.VercelOidcTokenError("project.json not found, have you linked your project with `vc link?`");
310
+ const prj = JSON.parse(fs.readFileSync(prjPath, "utf8"));
311
+ if (typeof prj.projectId !== "string" && typeof prj.orgId !== "string") throw new TypeError("Expected a string-valued projectId property. Try running `vc link` to re-link your project.");
312
+ return {
313
+ projectId: prj.projectId,
314
+ teamId: prj.orgId
315
+ };
316
+ }
317
+ function saveToken(token, projectId) {
318
+ const dir = (0, import_token_io.getUserDataDir)();
319
+ if (!dir) throw new import_token_error.VercelOidcTokenError("Unable to find user data directory. Please reach out to Vercel support.");
320
+ const tokenPath = path.join(dir, "com.vercel.token", `${projectId}.json`);
321
+ const tokenJson = JSON.stringify(token);
322
+ fs.mkdirSync(path.dirname(tokenPath), {
323
+ mode: 504,
324
+ recursive: true
325
+ });
326
+ fs.writeFileSync(tokenPath, tokenJson);
327
+ fs.chmodSync(tokenPath, 432);
328
+ }
329
+ function loadToken(projectId) {
330
+ const dir = (0, import_token_io.getUserDataDir)();
331
+ if (!dir) throw new import_token_error.VercelOidcTokenError("Unable to find user data directory. Please reach out to Vercel support.");
332
+ const tokenPath = path.join(dir, "com.vercel.token", `${projectId}.json`);
333
+ if (!fs.existsSync(tokenPath)) return null;
334
+ const token = JSON.parse(fs.readFileSync(tokenPath, "utf8"));
335
+ assertVercelOidcTokenResponse(token);
336
+ return token;
337
+ }
338
+ function getTokenPayload(token) {
339
+ const tokenParts = token.split(".");
340
+ if (tokenParts.length !== 3) throw new import_token_error.VercelOidcTokenError("Invalid token. Please run `vc env pull` and try again");
341
+ const base64 = tokenParts[1].replace(/-/g, "+").replace(/_/g, "/");
342
+ const padded = base64.padEnd(base64.length + (4 - base64.length % 4) % 4, "=");
343
+ return JSON.parse(Buffer.from(padded, "base64").toString("utf8"));
344
+ }
345
+ function isExpired(token) {
346
+ return token.exp * 1e3 < Date.now();
347
+ }
348
+ }));
349
+ //#endregion
350
+ Object.defineProperty(exports, "default", {
351
+ enumerable: true,
352
+ get: function() {
353
+ return require_token_util();
354
+ }
355
+ });
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "evaliphy",
3
+ "version": "1.0.1-beta.0",
4
+ "type": "module",
5
+ "description": "The first QA-centric SDK for testing Retrieval-Augmented Generation (RAG).",
6
+ "main": "./dist/index.mjs",
7
+ "types": "./dist/index.d.mts",
8
+ "keywords": [
9
+ "evaliphy",
10
+ "evaluate",
11
+ "rag",
12
+ "llm",
13
+ "qa",
14
+ "testing",
15
+ "ai",
16
+ "evaluation"
17
+ ],
18
+ "homepage": "https://github.com/priyanshus/evaliphy#readme",
19
+ "bugs": {
20
+ "url": "https://github.com/priyanshus/evaliphy/issues"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/priyanshus/evaliphy.git"
25
+ },
26
+ "license": "MIT",
27
+ "author": "Evaliphy",
28
+ "engines": {
29
+ "node": ">=18.0.0"
30
+ },
31
+ "exports": {
32
+ ".": {
33
+ "import": "./dist/index.mjs",
34
+ "require": "./dist/index.cjs",
35
+ "types": "./dist/index.d.mts"
36
+ }
37
+ },
38
+ "bin": {
39
+ "evaliphy": "./dist/bin.mjs"
40
+ },
41
+ "files": [
42
+ "dist",
43
+ "README.md"
44
+ ],
45
+ "dependencies": {
46
+ "commander": "^12.1.0",
47
+ "fast-glob": "^3.3.3",
48
+ "tsx": "^4.21.0",
49
+ "zod": "^3.0.7",
50
+ "picocolors": "^1.0.0",
51
+ "pino": "^9.0.0",
52
+ "pino-pretty": "^13.1.3"
53
+ },
54
+ "devDependencies": {
55
+ "tsdown": "^0.21.3",
56
+ "typescript": "^5.9.3",
57
+ "vitest": "^4.1.0",
58
+ "@types/node": "^20.0.0"
59
+ },
60
+ "scripts": {
61
+ "build": "tsdown",
62
+ "dev": "tsdown --watch",
63
+ "test": "vitest",
64
+ "lint": "tsc --noEmit"
65
+ }
66
+ }