nsarrazin HF Staff commited on
Commit
6a5e4c9
·
unverified ·
1 Parent(s): 6e16d44

feat(tools): remove feature flag for tools and use env variable instead (#1433)

Browse files
.env CHANGED
@@ -175,4 +175,5 @@ BODY_SIZE_LIMIT=15728640
175
  HF_ORG_ADMIN=
176
  HF_ORG_EARLY_ACCESS=
177
 
178
- PUBLIC_SMOOTH_UPDATES=false
 
 
175
  HF_ORG_ADMIN=
176
  HF_ORG_EARLY_ACCESS=
177
 
178
+ PUBLIC_SMOOTH_UPDATES=false
179
+ COMMUNITY_TOOLS=false
chart/env/prod.yaml CHANGED
@@ -30,6 +30,7 @@ envVars:
30
  ADDRESS_HEADER: 'X-Forwarded-For'
31
  ALTERNATIVE_REDIRECT_URLS: '["huggingchat://login/callback"]'
32
  APP_BASE: "/chat"
 
33
  ENABLE_ASSISTANTS: "true"
34
  ENABLE_ASSISTANTS_RAG: "true"
35
  EXPOSE_API: "true"
 
30
  ADDRESS_HEADER: 'X-Forwarded-For'
31
  ALTERNATIVE_REDIRECT_URLS: '["huggingchat://login/callback"]'
32
  APP_BASE: "/chat"
33
+ COMMUNITY_TOOLS: "true"
34
  ENABLE_ASSISTANTS: "true"
35
  ENABLE_ASSISTANTS_RAG: "true"
36
  EXPOSE_API: "true"
src/lib/components/NavMenu.svelte CHANGED
@@ -136,8 +136,7 @@
136
  Assistants
137
  </a>
138
  {/if}
139
- <!-- XXX: feature_flag_tools -->
140
- {#if $page.data.user?.isEarlyAccess}
141
  <a
142
  href="{base}/tools"
143
  class="flex h-9 flex-none items-center gap-1.5 rounded-lg pl-2.5 pr-2 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"
 
136
  Assistants
137
  </a>
138
  {/if}
139
+ {#if $page.data.enableCommunityTools}
 
140
  <a
141
  href="{base}/tools"
142
  class="flex h-9 flex-none items-center gap-1.5 rounded-lg pl-2.5 pr-2 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"
src/lib/components/ToolsMenu.svelte CHANGED
@@ -84,8 +84,7 @@
84
  {/if}
85
  </button>
86
  </div>
87
- <!-- XXX: feature_flag_tools -->
88
- {#if $page.data.user?.isEarlyAccess}
89
  <a
90
  href="{base}/tools"
91
  class="col-span-2 my-1 h-fit w-fit items-center justify-center rounded-full bg-purple-500/20 px-2.5 py-1.5 text-sm hover:bg-purple-500/30"
 
84
  {/if}
85
  </button>
86
  </div>
87
+ {#if $page.data.enableCommunityTools}
 
88
  <a
89
  href="{base}/tools"
90
  class="col-span-2 my-1 h-fit w-fit items-center justify-center rounded-full bg-purple-500/20 px-2.5 py-1.5 text-sm hover:bg-purple-500/30"
src/routes/+layout.server.ts CHANGED
@@ -240,6 +240,7 @@ export const load: LayoutServerLoad = async ({ locals, depends, request }) => {
240
  assistant,
241
  enableAssistants,
242
  enableAssistantsRAG: env.ENABLE_ASSISTANTS_RAG === "true",
 
243
  loginRequired,
244
  loginEnabled: requiresUser,
245
  guestMode: requiresUser && messagesBeforeLogin > 0,
 
240
  assistant,
241
  enableAssistants,
242
  enableAssistantsRAG: env.ENABLE_ASSISTANTS_RAG === "true",
243
+ enableCommunityTools: env.COMMUNITY_TOOLS === "true",
244
  loginRequired,
245
  loginEnabled: requiresUser,
246
  guestMode: requiresUser && messagesBeforeLogin > 0,
src/routes/api/spaces-config/+server.ts CHANGED
@@ -1,9 +1,9 @@
 
1
  import { Client } from "@gradio/client";
2
 
3
- export async function GET({ url, locals }) {
4
- // XXX: feature_flag_tools
5
- if (!locals.user?.isEarlyAccess) {
6
- return new Response("Not early access", { status: 403 });
7
  }
8
 
9
  const space = url.searchParams.get("space");
 
1
+ import { env } from "$env/dynamic/private";
2
  import { Client } from "@gradio/client";
3
 
4
+ export async function GET({ url }) {
5
+ if (env.COMMUNITY_TOOLS !== "true") {
6
+ return new Response("Community tools are not enabled", { status: 403 });
 
7
  }
8
 
9
  const space = url.searchParams.get("space");
src/routes/api/tools/[toolId]/+server.ts CHANGED
@@ -1,12 +1,12 @@
 
1
  import { collections } from "$lib/server/database.js";
2
  import { toolFromConfigs } from "$lib/server/tools/index.js";
3
  import type { CommunityToolDB } from "$lib/types/Tool.js";
4
  import { ObjectId } from "mongodb";
5
 
6
- export async function GET({ params, locals }) {
7
- // XXX: feature_flag_tools
8
- if (!locals.user?.isEarlyAccess) {
9
- return new Response("Not early access", { status: 403 });
10
  }
11
 
12
  const toolId = params.toolId;
 
1
+ import { env } from "$env/dynamic/private";
2
  import { collections } from "$lib/server/database.js";
3
  import { toolFromConfigs } from "$lib/server/tools/index.js";
4
  import type { CommunityToolDB } from "$lib/types/Tool.js";
5
  import { ObjectId } from "mongodb";
6
 
7
+ export async function GET({ params }) {
8
+ if (env.COMMUNITY_TOOLS !== "true") {
9
+ return new Response("Community tools are not enabled", { status: 403 });
 
10
  }
11
 
12
  const toolId = params.toolId;
src/routes/api/tools/search/+server.ts CHANGED
@@ -1,13 +1,13 @@
 
1
  import { collections } from "$lib/server/database.js";
2
  import { toolFromConfigs } from "$lib/server/tools/index.js";
3
  import type { BaseTool, CommunityToolDB } from "$lib/types/Tool.js";
4
  import { generateQueryTokens, generateSearchTokens } from "$lib/utils/searchTokens.js";
5
  import type { Filter } from "mongodb";
6
 
7
- export async function GET({ url, locals }) {
8
- // XXX: feature_flag_tools
9
- if (!locals.user?.isEarlyAccess) {
10
- return new Response("Not early access", { status: 403 });
11
  }
12
 
13
  const query = url.searchParams.get("q")?.trim() ?? null;
 
1
+ import { env } from "$env/dynamic/private";
2
  import { collections } from "$lib/server/database.js";
3
  import { toolFromConfigs } from "$lib/server/tools/index.js";
4
  import type { BaseTool, CommunityToolDB } from "$lib/types/Tool.js";
5
  import { generateQueryTokens, generateSearchTokens } from "$lib/utils/searchTokens.js";
6
  import type { Filter } from "mongodb";
7
 
8
+ export async function GET({ url }) {
9
+ if (env.COMMUNITY_TOOLS !== "true") {
10
+ return new Response("Community tools are not enabled", { status: 403 });
 
11
  }
12
 
13
  const query = url.searchParams.get("q")?.trim() ?? null;
src/routes/settings/(nav)/+server.ts CHANGED
@@ -22,14 +22,6 @@ export async function POST({ request, locals }) {
22
  })
23
  .parse(body) satisfies SettingsEditable;
24
 
25
- // only allow tools to be set to community tools if user is early access
26
- // XXX: feature_flag_tools
27
- if (!locals.user?.isEarlyAccess) {
28
- settings.tools = settings.tools?.filter((toolId) => {
29
- return toolFromConfigs.some((tool) => tool._id.toString() === toolId);
30
- });
31
- }
32
-
33
  // make sure all tools exist
34
  // either in db or in config
35
  if (settings.tools) {
 
22
  })
23
  .parse(body) satisfies SettingsEditable;
24
 
 
 
 
 
 
 
 
 
25
  // make sure all tools exist
26
  // either in db or in config
27
  if (settings.tools) {
src/routes/settings/(nav)/assistants/[assistantId]/edit/+page.server.ts CHANGED
@@ -171,8 +171,7 @@ export const actions: Actions = {
171
  allowedDomains: parse.data.ragDomainList,
172
  allowAllDomains: parse.data.ragAllowAll,
173
  },
174
- // XXX: feature_flag_tools
175
- tools: locals.user?.isEarlyAccess ? parse.data.tools : undefined,
176
  dynamicPrompt: parse.data.dynamicPrompt,
177
  searchTokens: generateSearchTokens(parse.data.name),
178
  generateSettings: {
 
171
  allowedDomains: parse.data.ragDomainList,
172
  allowAllDomains: parse.data.ragAllowAll,
173
  },
174
+ tools: parse.data.tools,
 
175
  dynamicPrompt: parse.data.dynamicPrompt,
176
  searchTokens: generateSearchTokens(parse.data.name),
177
  generateSettings: {
src/routes/settings/(nav)/assistants/new/+page.server.ts CHANGED
@@ -142,8 +142,7 @@ export const actions: Actions = {
142
  createdById,
143
  createdByName: locals.user?.username ?? locals.user?.name,
144
  ...parse.data,
145
- // XXX: feature_flag_tools
146
- tools: locals.user?.isEarlyAccess ? parse.data.tools : undefined,
147
  exampleInputs,
148
  avatar: hash,
149
  createdAt: new Date(),
 
142
  createdById,
143
  createdByName: locals.user?.username ?? locals.user?.name,
144
  ...parse.data,
145
+ tools: parse.data.tools,
 
146
  exampleInputs,
147
  avatar: hash,
148
  createdAt: new Date(),
src/routes/tools/+layout.ts CHANGED
@@ -1,13 +1,10 @@
1
- // check if user is earlyAccess else redirect to base
2
-
3
  import { base } from "$app/paths";
4
  import { redirect } from "@sveltejs/kit";
5
 
6
- // XXX: feature_flag_tools
7
  export async function load({ parent }) {
8
- const { user } = await parent();
9
 
10
- if (user?.isEarlyAccess) {
11
  return {};
12
  }
13
 
 
 
 
1
  import { base } from "$app/paths";
2
  import { redirect } from "@sveltejs/kit";
3
 
 
4
  export async function load({ parent }) {
5
+ const { enableCommunityTools } = await parent();
6
 
7
+ if (enableCommunityTools) {
8
  return {};
9
  }
10
 
src/routes/tools/+page.server.ts CHANGED
@@ -1,3 +1,4 @@
 
1
  import { authCondition } from "$lib/server/auth.js";
2
  import { Database, collections } from "$lib/server/database.js";
3
  import { toolFromConfigs } from "$lib/server/tools/index.js";
@@ -11,9 +12,8 @@ import { ObjectId, type Filter } from "mongodb";
11
  const NUM_PER_PAGE = 16;
12
 
13
  export const load = async ({ url, locals }) => {
14
- // XXX: feature_flag_tools
15
- if (!locals.user?.isEarlyAccess) {
16
- error(403, "You need to be an early access user to view tools");
17
  }
18
 
19
  const username = url.searchParams.get("user");
 
1
+ import { env } from "$env/dynamic/private";
2
  import { authCondition } from "$lib/server/auth.js";
3
  import { Database, collections } from "$lib/server/database.js";
4
  import { toolFromConfigs } from "$lib/server/tools/index.js";
 
12
  const NUM_PER_PAGE = 16;
13
 
14
  export const load = async ({ url, locals }) => {
15
+ if (env.COMMUNITY_TOOLS !== "true") {
16
+ error(403, "Community tools are not enabled");
 
17
  }
18
 
19
  const username = url.searchParams.get("user");
src/routes/tools/new/+page.server.ts CHANGED
@@ -1,3 +1,4 @@
 
1
  import { authCondition, requiresUser } from "$lib/server/auth.js";
2
  import { collections } from "$lib/server/database.js";
3
  import { editableToolSchema } from "$lib/server/tools/index.js";
@@ -8,9 +9,8 @@ import { ObjectId } from "mongodb";
8
 
9
  export const actions = {
10
  default: async ({ request, locals }) => {
11
- // XXX: feature_flag_tools
12
- if (!locals.user?.isEarlyAccess) {
13
- error(403, "You need to be an early access user to create tools");
14
  }
15
 
16
  const body = await request.formData();
@@ -66,9 +66,7 @@ export const actions = {
66
  updatedAt: new Date(),
67
  last24HoursUseCount: 0,
68
  useCount: 0,
69
- // XXX: feature_flag_tools
70
- // since this is scoped to internal team members only, we can assume that they should all be public
71
- featured: true,
72
  searchTokens: generateSearchTokens(parse.data.displayName),
73
  });
74
 
 
1
+ import { env } from "$env/dynamic/private";
2
  import { authCondition, requiresUser } from "$lib/server/auth.js";
3
  import { collections } from "$lib/server/database.js";
4
  import { editableToolSchema } from "$lib/server/tools/index.js";
 
9
 
10
  export const actions = {
11
  default: async ({ request, locals }) => {
12
+ if (env.COMMUNITY_TOOLS !== "true") {
13
+ error(403, "Community tools are not enabled");
 
14
  }
15
 
16
  const body = await request.formData();
 
66
  updatedAt: new Date(),
67
  last24HoursUseCount: 0,
68
  useCount: 0,
69
+ featured: locals.user?.isAdmin ?? false, // admin tools are featured by default
 
 
70
  searchTokens: generateSearchTokens(parse.data.displayName),
71
  });
72