Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(workspace): move slug format rules into @lobechat/const (#19087)

YuTengjingf2329c46a0d2
diff --git a/packages/business-server/package.json b/packages/business-server/package.json
index 20eac9594b8..20d659af0b9 100644
--- a/packages/business-server/package.json
+++ b/packages/business-server/package.json
@@ -7,7 +7,7 @@
},
"dependencies": {
"@lobechat/agent-gateway-client": "workspace:*",
- "@lobechat/business-const": "workspace:*",
+ "@lobechat/const": "workspace:*",
"@lobechat/database": "workspace:*",
"@lobechat/model-runtime": "workspace:*",
"@lobechat/trpc": "workspace:*",
diff --git a/packages/business-server/src/lambda-routers/workspace.ts b/packages/business-server/src/lambda-routers/workspace.ts
index 2b1fbf5a048..de2013b8daa 100644
--- a/packages/business-server/src/lambda-routers/workspace.ts
+++ b/packages/business-server/src/lambda-routers/workspace.ts
@@ -2,7 +2,7 @@ import {
isWorkspaceSlugFormatValid,
WORKSPACE_SLUG_MAX,
WORKSPACE_SLUG_MIN,
-} from '@lobechat/business-const';
+} from '@lobechat/const';
import type { WorkspaceItem } from '@lobechat/database/schemas';
import { TRPCError } from '@trpc/server';
import { z } from 'zod';
diff --git a/packages/business/const/src/index.ts b/packages/business/const/src/index.ts
index ccfecdce3a0..2282d422665 100644
--- a/packages/business/const/src/index.ts
+++ b/packages/business/const/src/index.ts
@@ -3,7 +3,6 @@ import { BRANDING_PROVIDER } from './branding';
export * from './branding';
export * from './llm';
export * from './url';
-export * from './workspaceSlug';
export const ENABLE_BUSINESS_FEATURES = false;
diff --git a/packages/business/const/src/workspaceSlug.ts b/packages/business/const/src/workspaceSlug.ts
deleted file mode 100644
index ed591dd4c7c..00000000000
--- a/packages/business/const/src/workspaceSlug.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-/**
- * Format rules for a workspace slug, mirroring the cloud constants of the same
- * names so the open-source router contract rejects what cloud rejects.
- *
- * Cloud additionally refuses slugs that would shadow a real top-level route
- * (`chat`, `settings`, `api`, …) — that reservation list is a deployment
- * concern and lives only in the cloud overlay, so a slug accepted here can
- * still come back as `invalid-slug` from the server.
- */
-export const WORKSPACE_SLUG_MIN = 3;
-export const WORKSPACE_SLUG_MAX = 32;
-
-export const WORKSPACE_SLUG_PATTERN = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
-
-/** Format-only check: lowercase alphanumerics and inner hyphens. */
-export const isWorkspaceSlugFormatValid = (slug: string): boolean =>
- WORKSPACE_SLUG_PATTERN.test(slug);
diff --git a/packages/const/src/workspace.test.ts b/packages/const/src/workspace.test.ts
new file mode 100644
index 00000000000..64369de680c
--- /dev/null
+++ b/packages/const/src/workspace.test.ts
@@ -0,0 +1,29 @@
+import { describe, expect, it } from 'vitest';
+
+import {
+ isWorkspaceSlugFormatValid,
+ WORKSPACE_SLUG_MAX,
+ WORKSPACE_SLUG_MIN,
+ WORKSPACE_SLUG_PATTERN,
+} from './workspace';
+
+describe('workspace slug format', () => {
+ it.each(['foo', 'foo-bar', 'a1', 'admin', '1-2-3'])('accepts %s', (slug) => {
+ expect(isWorkspaceSlugFormatValid(slug)).toBe(true);
+ });
+
+ it.each(['-foo', 'foo-', 'Foo', 'foo_bar', 'foo bar', 'foo.bar', '', '中文', '@foo'])(
+ 'rejects %s',
+ (slug) => {
+ expect(isWorkspaceSlugFormatValid(slug)).toBe(false);
+ },
+ );
+
+ // Length is enforced by the callers' zod schema, not by the pattern.
+ it('does not enforce length', () => {
+ expect(isWorkspaceSlugFormatValid('a')).toBe(true);
+ expect(isWorkspaceSlugFormatValid('a'.repeat(WORKSPACE_SLUG_MAX + 1))).toBe(true);
+ expect(WORKSPACE_SLUG_MIN).toBeLessThan(WORKSPACE_SLUG_MAX);
+ expect(WORKSPACE_SLUG_PATTERN.test('a'.repeat(WORKSPACE_SLUG_MIN))).toBe(true);
+ });
+});
diff --git a/packages/const/src/workspace.ts b/packages/const/src/workspace.ts
index 0abb772b89b..38e1a241d3f 100644
--- a/packages/const/src/workspace.ts
+++ b/packages/const/src/workspace.ts
@@ -16,3 +16,19 @@ export const INVITATION_EXPIRY_DAYS = 7;
* the server is going to refuse wholesale.
*/
export const MAX_RESOURCE_COLLABORATORS_PER_ADD = 100;
+
+/**
+ * Format rules for a workspace slug: length bounds plus lowercase
+ * alphanumerics with inner hyphens. Generic on purpose — they define what a
+ * slug *is*, so the OSS workspace router contract and the CLI validate the
+ * same shape a business deployment does. Deployment-specific refusals (slugs
+ * that would shadow a real top-level route, protected brand names) are a
+ * business concern layered on top of these and do not live here.
+ */
+export const WORKSPACE_SLUG_MIN = 3;
+export const WORKSPACE_SLUG_MAX = 32;
+export const WORKSPACE_SLUG_PATTERN = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
+
+/** Format-only check against {@link WORKSPACE_SLUG_PATTERN}; no length check. */
+export const isWorkspaceSlugFormatValid = (slug: string): boolean =>
+ WORKSPACE_SLUG_PATTERN.test(slug);