abhijitramesh commited on
Commit
5993e41
·
verified ·
1 Parent(s): 92eab7d

fix OAuth + drop isPullRequest

Browse files
Files changed (1) hide show
  1. bench-hub.js +16 -9
bench-hub.js CHANGED
@@ -75,12 +75,22 @@ export async function beginHFSignIn() {
75
  if (!isHubConfigured()) {
76
  throw new Error('HF hub is not configured. Set HF_DATASET_REPO in bench-config.js.');
77
  }
78
- // When served from an HF Space with `hf_oauth: true`, the Space injects
79
- // OAuth client config via meta tags; @huggingface/hub picks it up when
80
- // clientId is omitted. For local dev, running the sign-in flow requires a
81
- // Space URL so OAuth is effectively hosted-only.
 
 
 
 
 
 
 
 
 
82
  const url = await oauthLoginUrl({
83
- scopes: HF_OAUTH_SCOPES,
 
84
  redirectUrl: location.origin + location.pathname,
85
  });
86
  location.assign(url);
@@ -129,14 +139,11 @@ export async function submitResultsToDataset(results, {
129
  credentials: { accessToken: token },
130
  file: { path, content: blob },
131
  commitTitle: `bench: ${machineSlug} / ${browser} / ${results.length} variants`,
132
- isPullRequest: true,
133
  });
134
 
135
- const prUrl = res?.pullRequestUrl
136
- || (res?.hfHubUrl ? `https://huggingface.co${res.hfHubUrl}` : null);
137
  return {
138
  path,
139
  commit: res?.commit?.oid || null,
140
- prUrl,
141
  };
142
  }
 
75
  if (!isHubConfigured()) {
76
  throw new Error('HF hub is not configured. Set HF_DATASET_REPO in bench-config.js.');
77
  }
78
+ // When served from an HF Space with `hf_oauth: true`, HF injects
79
+ // `window.huggingface.variables` with OAUTH_CLIENT_ID + OAUTH_SCOPES.
80
+ // @huggingface/hub needs the clientId passed explicitly.
81
+ const injected = (globalThis.window?.huggingface?.variables) || {};
82
+ const clientId = injected.OAUTH_CLIENT_ID;
83
+ if (!clientId) {
84
+ throw new Error(
85
+ 'No OAUTH_CLIENT_ID injected — is this page served from an HF Space with `hf_oauth: true`?',
86
+ );
87
+ }
88
+ const scopes = injected.OAUTH_SCOPES
89
+ ? injected.OAUTH_SCOPES.split(/\s+/).filter(Boolean)
90
+ : HF_OAUTH_SCOPES;
91
  const url = await oauthLoginUrl({
92
+ clientId,
93
+ scopes,
94
  redirectUrl: location.origin + location.pathname,
95
  });
96
  location.assign(url);
 
139
  credentials: { accessToken: token },
140
  file: { path, content: blob },
141
  commitTitle: `bench: ${machineSlug} / ${browser} / ${results.length} variants`,
 
142
  });
143
 
 
 
144
  return {
145
  path,
146
  commit: res?.commit?.oid || null,
147
+ commitUrl: `https://huggingface.co/datasets/${datasetRepo}/blob/main/${path}`,
148
  };
149
  }