@wix/evalforge-evaluator 0.16.0 → 0.17.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.
package/build/index.mjs CHANGED
@@ -7272,6 +7272,79 @@ async function testNetworkConnectivity(config) {
7272
7272
  durationMs: Date.now() - start
7273
7273
  };
7274
7274
  }
7275
+ async function testAiGatewayApiCall(config) {
7276
+ const start = Date.now();
7277
+ const details = {};
7278
+ const gatewayUrl = config.aiGatewayUrl;
7279
+ const headers = config.aiGatewayHeaders;
7280
+ details.gatewayUrl = gatewayUrl;
7281
+ details.hasHeaders = !!headers;
7282
+ details.headerKeys = headers ? Object.keys(headers) : [];
7283
+ if (!gatewayUrl) {
7284
+ return {
7285
+ name: "ai-gateway-api-call",
7286
+ passed: false,
7287
+ details,
7288
+ error: "No AI_GATEWAY_URL configured",
7289
+ durationMs: Date.now() - start
7290
+ };
7291
+ }
7292
+ if (!headers) {
7293
+ return {
7294
+ name: "ai-gateway-api-call",
7295
+ passed: false,
7296
+ details,
7297
+ error: "No AI_GATEWAY_HEADERS configured",
7298
+ durationMs: Date.now() - start
7299
+ };
7300
+ }
7301
+ const headerFlags = Object.entries(headers).map(([k, v]) => `-H "${k}: ${v}"`).join(" ");
7302
+ const requestBody = JSON.stringify({
7303
+ model: "claude-3-5-sonnet-latest",
7304
+ max_tokens: 10,
7305
+ messages: [{ role: "user", content: "Say hi" }]
7306
+ }).replace(/"/g, '\\"');
7307
+ const messagesUrl = `${gatewayUrl}/v1/messages`;
7308
+ const curlCmd = `curl -s --max-time 15 ${headerFlags} -H "Content-Type: application/json" -H "anthropic-version: 2023-06-01" -d "${requestBody}" "${messagesUrl}" 2>&1`;
7309
+ const redactedCmd = curlCmd.replace(/app-secret:[^"]+/g, "app-secret:[REDACTED]").replace(
7310
+ /-H "x-wix-ai-gateway-app-secret: [^"]+"/g,
7311
+ '-H "x-wix-ai-gateway-app-secret: [REDACTED]"'
7312
+ );
7313
+ details.curlCommand = redactedCmd;
7314
+ console.error("[DIAG] Making actual API call to AI Gateway...");
7315
+ console.error("[DIAG] URL:", messagesUrl);
7316
+ const result = await execCommand(curlCmd, 2e4);
7317
+ details.responseRaw = result.stdout.slice(0, 1500);
7318
+ details.exitCode = result.exitCode;
7319
+ let responseJson = null;
7320
+ try {
7321
+ responseJson = JSON.parse(result.stdout);
7322
+ details.responseParsed = true;
7323
+ } catch {
7324
+ details.responseParsed = false;
7325
+ details.parseError = "Response is not valid JSON";
7326
+ }
7327
+ const isError = result.stdout.includes('"type":"error"') || result.stdout.includes('"error":{') || result.stdout.includes("authentication_error") || result.stdout.includes("permission_error");
7328
+ const isSuccess = result.stdout.includes('"type":"message"') || result.stdout.includes('"content":');
7329
+ details.isError = isError;
7330
+ details.isSuccess = isSuccess;
7331
+ if (isError && responseJson && typeof responseJson === "object") {
7332
+ const errorObj = responseJson;
7333
+ if (errorObj.error && typeof errorObj.error === "object") {
7334
+ const error = errorObj.error;
7335
+ details.errorType = error.type;
7336
+ details.errorMessage = error.message;
7337
+ }
7338
+ }
7339
+ const passed = result.exitCode === 0 && isSuccess && !isError;
7340
+ return {
7341
+ name: "ai-gateway-api-call",
7342
+ passed,
7343
+ details,
7344
+ error: passed ? void 0 : isError ? `API returned error: ${details.errorType || "unknown"} - ${details.errorMessage || result.stdout.slice(0, 200)}` : `API call failed: exit=${result.exitCode}, response=${result.stdout.slice(0, 200)}`,
7345
+ durationMs: Date.now() - start
7346
+ };
7347
+ }
7275
7348
  async function testChildProcessSpawning() {
7276
7349
  const start = Date.now();
7277
7350
  const details = {};
@@ -7477,6 +7550,7 @@ async function runDiagnostics(config, evalRunId2) {
7477
7550
  await runTest("environment-dump", testEnvironmentDump);
7478
7551
  await runTest("file-system-structure", testFileSystemStructure);
7479
7552
  await runTest("network-connectivity", () => testNetworkConnectivity(config));
7553
+ await runTest("ai-gateway-api-call", () => testAiGatewayApiCall(config));
7480
7554
  await runTest("child-process-spawning", testChildProcessSpawning);
7481
7555
  await runTest("sdk-import", testSdkImport);
7482
7556
  await runTest("file-system-write", testFileSystemWrite);