feat(server): add doc embedding switch for workspace (#11760)

fix AI-33
This commit is contained in:
darkskygit
2025-04-17 07:13:22 +00:00
parent ebf1d5476d
commit 38e8806787
11 changed files with 71 additions and 11 deletions

View File

@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "workspaces" ADD COLUMN "enable_doc_embedding" BOOLEAN NOT NULL DEFAULT true;

View File

@@ -1,3 +1,3 @@
# Please do not edit this file manually # Please do not edit this file manually
# It should be added in your version-control system (i.e. Git) # It should be added in your version-control system (e.g., Git)
provider = "postgresql" provider = "postgresql"

View File

@@ -104,14 +104,15 @@ model VerificationToken {
} }
model Workspace { model Workspace {
id String @id @default(uuid()) @db.VarChar id String @id @default(uuid()) @db.VarChar
public Boolean public Boolean
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3) createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
// workspace level feature flags // workspace level feature flags
enableAi Boolean @default(true) @map("enable_ai") enableAi Boolean @default(true) @map("enable_ai")
enableUrlPreview Boolean @default(false) @map("enable_url_preview") enableUrlPreview Boolean @default(false) @map("enable_url_preview")
name String? @db.VarChar enableDocEmbedding Boolean @default(true) @map("enable_doc_embedding")
avatarKey String? @map("avatar_key") @db.VarChar name String? @db.VarChar
avatarKey String? @map("avatar_key") @db.VarChar
features WorkspaceFeature[] features WorkspaceFeature[]
docs WorkspaceDoc[] docs WorkspaceDoc[]

View File

@@ -60,6 +60,7 @@ test('should update workspace', async t => {
public: true, public: true,
enableAi: true, enableAi: true,
enableUrlPreview: true, enableUrlPreview: true,
enableDocEmbedding: false,
}; };
await t.context.workspace.update(workspace.id, data); await t.context.workspace.update(workspace.id, data);
const workspace1 = await t.context.workspace.get(workspace.id); const workspace1 = await t.context.workspace.get(workspace.id);

View File

@@ -88,6 +88,9 @@ export class WorkspaceType extends WorkspaceFeatureType {
@Field({ description: 'Enable url previous when sharing' }) @Field({ description: 'Enable url previous when sharing' })
enableUrlPreview!: boolean; enableUrlPreview!: boolean;
@Field({ description: 'Enable doc embedding' })
enableDocEmbedding!: boolean;
@Field(() => [InviteUserType], { @Field(() => [InviteUserType], {
description: 'Members of workspace', description: 'Members of workspace',
}) })
@@ -133,7 +136,7 @@ export class InvitationType {
@InputType() @InputType()
export class UpdateWorkspaceInput extends PickType( export class UpdateWorkspaceInput extends PickType(
PartialType(WorkspaceType), PartialType(WorkspaceType),
['public', 'enableAi', 'enableUrlPreview'], ['public', 'enableAi', 'enableUrlPreview', 'enableDocEmbedding'],
InputType InputType
) { ) {
@Field(() => ID) @Field(() => ID)

View File

@@ -16,7 +16,12 @@ declare global {
export type { Workspace }; export type { Workspace };
export type UpdateWorkspaceInput = Pick< export type UpdateWorkspaceInput = Pick<
Partial<Workspace>, Partial<Workspace>,
'public' | 'enableAi' | 'enableUrlPreview' | 'name' | 'avatarKey' | 'public'
| 'enableAi'
| 'enableUrlPreview'
| 'enableDocEmbedding'
| 'name'
| 'avatarKey'
>; >;
@Injectable() @Injectable()
@@ -88,5 +93,10 @@ export class WorkspaceModel extends BaseModel {
const workspace = await this.get(workspaceId); const workspace = await this.get(workspaceId);
return workspace?.enableUrlPreview ?? false; return workspace?.enableUrlPreview ?? false;
} }
async allowEmbedding(workspaceId: string) {
const workspace = await this.get(workspaceId);
return workspace?.enableDocEmbedding ?? false;
}
// #endregion // #endregion
} }

View File

@@ -1493,6 +1493,9 @@ input UpdateWorkspaceInput {
"""Enable AI""" """Enable AI"""
enableAi: Boolean enableAi: Boolean
"""Enable doc embedding"""
enableDocEmbedding: Boolean
"""Enable url previous when sharing""" """Enable url previous when sharing"""
enableUrlPreview: Boolean enableUrlPreview: Boolean
id: ID! id: ID!
@@ -1702,6 +1705,9 @@ type WorkspaceType {
"""Enable AI""" """Enable AI"""
enableAi: Boolean! enableAi: Boolean!
"""Enable doc embedding"""
enableDocEmbedding: Boolean!
"""Enable url previous when sharing""" """Enable url previous when sharing"""
enableUrlPreview: Boolean! enableUrlPreview: Boolean!
histories(before: DateTime, guid: String!, take: Int): [DocHistoryType!]! histories(before: DateTime, guid: String!, take: Int): [DocHistoryType!]!

View File

@@ -1595,6 +1595,7 @@ export const getWorkspaceConfigQuery = {
workspace(id: $id) { workspace(id: $id) {
enableAi enableAi
enableUrlPreview enableUrlPreview
enableDocEmbedding
inviteLink { inviteLink {
link link
expireTime expireTime
@@ -1613,6 +1614,16 @@ export const setEnableAiMutation = {
}`, }`,
}; };
export const setEnableDocEmbeddingMutation = {
id: 'setEnableDocEmbeddingMutation' as const,
op: 'setEnableDocEmbedding',
query: `mutation setEnableDocEmbedding($id: ID!, $enableDocEmbedding: Boolean!) {
updateWorkspace(input: {id: $id, enableDocEmbedding: $enableDocEmbedding}) {
id
}
}`,
};
export const setEnableUrlPreviewMutation = { export const setEnableUrlPreviewMutation = {
id: 'setEnableUrlPreviewMutation' as const, id: 'setEnableUrlPreviewMutation' as const,
op: 'setEnableUrlPreview', op: 'setEnableUrlPreview',

View File

@@ -2,6 +2,7 @@ query getWorkspaceConfig($id: String!) {
workspace(id: $id) { workspace(id: $id) {
enableAi enableAi
enableUrlPreview enableUrlPreview
enableDocEmbedding
inviteLink { inviteLink {
link link
expireTime expireTime

View File

@@ -0,0 +1,5 @@
mutation setEnableDocEmbedding($id: ID!, $enableDocEmbedding: Boolean!) {
updateWorkspace(input: { id: $id, enableDocEmbedding: $enableDocEmbedding }) {
id
}
}

View File

@@ -2006,6 +2006,8 @@ export interface UpdateUserSettingsInput {
export interface UpdateWorkspaceInput { export interface UpdateWorkspaceInput {
/** Enable AI */ /** Enable AI */
enableAi?: InputMaybe<Scalars['Boolean']['input']>; enableAi?: InputMaybe<Scalars['Boolean']['input']>;
/** Enable doc embedding */
enableDocEmbedding?: InputMaybe<Scalars['Boolean']['input']>;
/** Enable url previous when sharing */ /** Enable url previous when sharing */
enableUrlPreview?: InputMaybe<Scalars['Boolean']['input']>; enableUrlPreview?: InputMaybe<Scalars['Boolean']['input']>;
id: Scalars['ID']['input']; id: Scalars['ID']['input'];
@@ -2230,6 +2232,8 @@ export interface WorkspaceType {
doc: DocType; doc: DocType;
/** Enable AI */ /** Enable AI */
enableAi: Scalars['Boolean']['output']; enableAi: Scalars['Boolean']['output'];
/** Enable doc embedding */
enableDocEmbedding: Scalars['Boolean']['output'];
/** Enable url previous when sharing */ /** Enable url previous when sharing */
enableUrlPreview: Scalars['Boolean']['output']; enableUrlPreview: Scalars['Boolean']['output'];
histories: Array<DocHistoryType>; histories: Array<DocHistoryType>;
@@ -4107,6 +4111,7 @@ export type GetWorkspaceConfigQuery = {
__typename?: 'WorkspaceType'; __typename?: 'WorkspaceType';
enableAi: boolean; enableAi: boolean;
enableUrlPreview: boolean; enableUrlPreview: boolean;
enableDocEmbedding: boolean;
inviteLink: { inviteLink: {
__typename?: 'InviteLink'; __typename?: 'InviteLink';
link: string; link: string;
@@ -4125,6 +4130,16 @@ export type SetEnableAiMutation = {
updateWorkspace: { __typename?: 'WorkspaceType'; id: string }; updateWorkspace: { __typename?: 'WorkspaceType'; id: string };
}; };
export type SetEnableDocEmbeddingMutationVariables = Exact<{
id: Scalars['ID']['input'];
enableDocEmbedding: Scalars['Boolean']['input'];
}>;
export type SetEnableDocEmbeddingMutation = {
__typename?: 'Mutation';
updateWorkspace: { __typename?: 'WorkspaceType'; id: string };
};
export type SetEnableUrlPreviewMutationVariables = Exact<{ export type SetEnableUrlPreviewMutationVariables = Exact<{
id: Scalars['ID']['input']; id: Scalars['ID']['input'];
enableUrlPreview: Scalars['Boolean']['input']; enableUrlPreview: Scalars['Boolean']['input'];
@@ -4931,6 +4946,11 @@ export type Mutations =
variables: SetEnableAiMutationVariables; variables: SetEnableAiMutationVariables;
response: SetEnableAiMutation; response: SetEnableAiMutation;
} }
| {
name: 'setEnableDocEmbeddingMutation';
variables: SetEnableDocEmbeddingMutationVariables;
response: SetEnableDocEmbeddingMutation;
}
| { | {
name: 'setEnableUrlPreviewMutation'; name: 'setEnableUrlPreviewMutation';
variables: SetEnableUrlPreviewMutationVariables; variables: SetEnableUrlPreviewMutationVariables;