feat: refactor copilot module (#14537)

This commit is contained in:
DarkSky
2026-03-02 13:57:55 +08:00
committed by GitHub
parent 60acd81d4b
commit c5d622531c
92 changed files with 5759 additions and 2170 deletions
@@ -1,18 +0,0 @@
query getPrompts {
listCopilotPrompts {
name
model
action
config {
frequencyPenalty
presencePenalty
temperature
topP
}
messages {
role
content
params
}
}
}
@@ -1,21 +0,0 @@
mutation updatePrompt(
$name: String!
$messages: [CopilotPromptMessageInput!]!
) {
updateCopilotPrompt(name: $name, messages: $messages) {
name
model
action
config {
frequencyPenalty
presencePenalty
temperature
topP
}
messages {
role
content
params
}
}
}
@@ -1,4 +1,4 @@
#import "./fragments/copilot.gql"
#import "./fragments/paginated-copilot-chats.gql"
query getCopilotDocSessions(
$workspaceId: String!
@@ -1,4 +1,4 @@
#import "./fragments/copilot.gql"
#import "./fragments/paginated-copilot-chats.gql"
query getCopilotPinnedSessions(
$workspaceId: String!
@@ -1,4 +1,4 @@
#import "./fragments/copilot.gql"
#import "./fragments/paginated-copilot-chats.gql"
query getCopilotWorkspaceSessions(
$workspaceId: String!
@@ -1,4 +1,4 @@
#import "./fragments/copilot.gql"
#import "./fragments/paginated-copilot-chats.gql"
query getCopilotHistories(
$workspaceId: String!
@@ -0,0 +1,7 @@
#import "./fragments/copilot-chat-history.gql"
mutation createCopilotSessionWithHistory($options: CreateChatSessionInput!) {
createCopilotSessionWithHistory(options: $options) {
...CopilotChatHistory
}
}
@@ -1,4 +1,4 @@
#import "./fragments/copilot.gql"
#import "./fragments/paginated-copilot-chats.gql"
query getCopilotLatestDocSession(
$workspaceId: String!
@@ -1,4 +1,4 @@
#import "./fragments/copilot.gql"
#import "./fragments/paginated-copilot-chats.gql"
query getCopilotSession(
$workspaceId: String!
@@ -1,4 +1,4 @@
#import "./fragments/copilot.gql"
#import "./fragments/paginated-copilot-chats.gql"
query getCopilotRecentSessions(
$workspaceId: String!
@@ -1,4 +1,4 @@
#import "./fragments/copilot.gql"
#import "./fragments/paginated-copilot-chats.gql"
query getCopilotSessions(
$workspaceId: String!
@@ -0,0 +1,30 @@
fragment CopilotChatHistory on CopilotHistories {
sessionId
workspaceId
docId
parentSessionId
promptName
model
optionalModels
action
pinned
title
tokens
messages {
id
role
content
attachments
streamObjects {
type
textDelta
toolCallId
toolName
args
result
}
createdAt
}
createdAt
updatedAt
}
@@ -1,49 +0,0 @@
fragment CopilotChatMessage on ChatMessage {
id
role
content
attachments
streamObjects {
type
textDelta
toolCallId
toolName
args
result
}
createdAt
}
fragment CopilotChatHistory on CopilotHistories {
sessionId
workspaceId
docId
parentSessionId
promptName
model
optionalModels
action
pinned
title
tokens
messages {
...CopilotChatMessage
}
createdAt
updatedAt
}
fragment PaginatedCopilotChats on PaginatedCopilotHistoriesType {
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
edges {
cursor
node {
...CopilotChatHistory
}
}
}
@@ -0,0 +1,16 @@
#import "./copilot-chat-history.gql"
fragment PaginatedCopilotChats on PaginatedCopilotHistoriesType {
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
edges {
cursor
node {
...CopilotChatHistory
}
}
}
+39 -92
View File
@@ -6,21 +6,6 @@ export interface GraphQLQuery {
file?: boolean;
deprecations?: string[];
}
export const copilotChatMessageFragment = `fragment CopilotChatMessage on ChatMessage {
id
role
content
attachments
streamObjects {
type
textDelta
toolCallId
toolName
args
result
}
createdAt
}`;
export const copilotChatHistoryFragment = `fragment CopilotChatHistory on CopilotHistories {
sessionId
workspaceId
@@ -34,25 +19,23 @@ export const copilotChatHistoryFragment = `fragment CopilotChatHistory on Copilo
title
tokens
messages {
...CopilotChatMessage
id
role
content
attachments
streamObjects {
type
textDelta
toolCallId
toolName
args
result
}
createdAt
}
createdAt
updatedAt
}`;
export const paginatedCopilotChatsFragment = `fragment PaginatedCopilotChats on PaginatedCopilotHistoriesType {
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
edges {
cursor
node {
...CopilotChatHistory
}
}
}`;
export const credentialsRequirementsFragment = `fragment CredentialsRequirements on CredentialsRequirementType {
password {
...PasswordLimits
@@ -94,6 +77,20 @@ export const currentUserProfileFragment = `fragment CurrentUserProfile on UserTy
}
}
}`;
export const paginatedCopilotChatsFragment = `fragment PaginatedCopilotChats on PaginatedCopilotHistoriesType {
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
edges {
cursor
node {
...CopilotChatHistory
}
}
}${copilotChatHistoryFragment}`;
export const passwordLimitsFragment = `fragment PasswordLimits on PasswordLimitsType {
minLength
maxLength
@@ -404,52 +401,6 @@ export const appConfigQuery = {
}`,
};
export const getPromptsQuery = {
id: 'getPromptsQuery' as const,
op: 'getPrompts',
query: `query getPrompts {
listCopilotPrompts {
name
model
action
config {
frequencyPenalty
presencePenalty
temperature
topP
}
messages {
role
content
params
}
}
}`,
};
export const updatePromptMutation = {
id: 'updatePromptMutation' as const,
op: 'updatePrompt',
query: `mutation updatePrompt($name: String!, $messages: [CopilotPromptMessageInput!]!) {
updateCopilotPrompt(name: $name, messages: $messages) {
name
model
action
config {
frequencyPenalty
presencePenalty
temperature
topP
}
messages {
role
content
params
}
}
}`,
};
export const createUserMutation = {
id: 'createUserMutation' as const,
op: 'createUser',
@@ -1411,8 +1362,6 @@ export const getCopilotDocSessionsQuery = {
}
}
}
${copilotChatMessageFragment}
${copilotChatHistoryFragment}
${paginatedCopilotChatsFragment}`,
};
@@ -1432,8 +1381,6 @@ export const getCopilotPinnedSessionsQuery = {
}
}
}
${copilotChatMessageFragment}
${copilotChatHistoryFragment}
${paginatedCopilotChatsFragment}`,
};
@@ -1449,8 +1396,6 @@ export const getCopilotWorkspaceSessionsQuery = {
}
}
}
${copilotChatMessageFragment}
${copilotChatHistoryFragment}
${paginatedCopilotChatsFragment}`,
};
@@ -1466,8 +1411,6 @@ export const getCopilotHistoriesQuery = {
}
}
}
${copilotChatMessageFragment}
${copilotChatHistoryFragment}
${paginatedCopilotChatsFragment}`,
};
@@ -1596,12 +1539,24 @@ export const cleanupCopilotSessionMutation = {
}`,
};
export const createCopilotSessionWithHistoryMutation = {
id: 'createCopilotSessionWithHistoryMutation' as const,
op: 'createCopilotSessionWithHistory',
query: `mutation createCopilotSessionWithHistory($options: CreateChatSessionInput!) {
createCopilotSessionWithHistory(options: $options) {
...CopilotChatHistory
}
}
${copilotChatHistoryFragment}`,
};
export const createCopilotSessionMutation = {
id: 'createCopilotSessionMutation' as const,
op: 'createCopilotSession',
query: `mutation createCopilotSession($options: CreateChatSessionInput!) {
createCopilotSession(options: $options)
}`,
deprecations: ["'createCopilotSession' is deprecated: use `createCopilotSessionWithHistory` instead"],
};
export const forkCopilotSessionMutation = {
@@ -1628,8 +1583,6 @@ export const getCopilotLatestDocSessionQuery = {
}
}
}
${copilotChatMessageFragment}
${copilotChatHistoryFragment}
${paginatedCopilotChatsFragment}`,
};
@@ -1645,8 +1598,6 @@ export const getCopilotSessionQuery = {
}
}
}
${copilotChatMessageFragment}
${copilotChatHistoryFragment}
${paginatedCopilotChatsFragment}`,
};
@@ -1665,8 +1616,6 @@ export const getCopilotRecentSessionsQuery = {
}
}
}
${copilotChatMessageFragment}
${copilotChatHistoryFragment}
${paginatedCopilotChatsFragment}`,
};
@@ -1690,8 +1639,6 @@ export const getCopilotSessionsQuery = {
}
}
}
${copilotChatMessageFragment}
${copilotChatHistoryFragment}
${paginatedCopilotChatsFragment}`,
};
+101 -193
View File
@@ -725,54 +725,11 @@ export interface CopilotModelsType {
proModels: Array<CopilotModelType>;
}
export interface CopilotPromptConfigInput {
frequencyPenalty?: InputMaybe<Scalars['Float']['input']>;
presencePenalty?: InputMaybe<Scalars['Float']['input']>;
temperature?: InputMaybe<Scalars['Float']['input']>;
topP?: InputMaybe<Scalars['Float']['input']>;
}
export interface CopilotPromptConfigType {
__typename?: 'CopilotPromptConfigType';
frequencyPenalty: Maybe<Scalars['Float']['output']>;
presencePenalty: Maybe<Scalars['Float']['output']>;
temperature: Maybe<Scalars['Float']['output']>;
topP: Maybe<Scalars['Float']['output']>;
}
export interface CopilotPromptMessageInput {
content: Scalars['String']['input'];
params?: InputMaybe<Scalars['JSON']['input']>;
role: CopilotPromptMessageRole;
}
export enum CopilotPromptMessageRole {
assistant = 'assistant',
system = 'system',
user = 'user',
}
export interface CopilotPromptMessageType {
__typename?: 'CopilotPromptMessageType';
content: Scalars['String']['output'];
params: Maybe<Scalars['JSON']['output']>;
role: CopilotPromptMessageRole;
}
export interface CopilotPromptNotFoundDataType {
__typename?: 'CopilotPromptNotFoundDataType';
name: Scalars['String']['output'];
}
export interface CopilotPromptType {
__typename?: 'CopilotPromptType';
action: Maybe<Scalars['String']['output']>;
config: Maybe<CopilotPromptConfigType>;
messages: Array<CopilotPromptMessageType>;
model: Scalars['String']['output'];
name: Scalars['String']['output'];
}
export interface CopilotProviderNotSupportedDataType {
__typename?: 'CopilotProviderNotSupportedDataType';
kind: Scalars['String']['output'];
@@ -884,14 +841,6 @@ export interface CreateCheckoutSessionInput {
variant?: InputMaybe<SubscriptionVariant>;
}
export interface CreateCopilotPromptInput {
action?: InputMaybe<Scalars['String']['input']>;
config?: InputMaybe<CopilotPromptConfigInput>;
messages: Array<CopilotPromptMessageInput>;
model: Scalars['String']['input'];
name: Scalars['String']['input'];
}
export interface CreateUserInput {
email: Scalars['String']['input'];
name?: InputMaybe<Scalars['String']['input']>;
@@ -1752,10 +1701,13 @@ export interface Mutation {
createCopilotContext: Scalars['String']['output'];
/** Create a chat message */
createCopilotMessage: Scalars['String']['output'];
/** Create a copilot prompt */
createCopilotPrompt: CopilotPromptType;
/** Create a chat session */
/**
* Create a chat session
* @deprecated use `createCopilotSessionWithHistory` instead
*/
createCopilotSession: Scalars['String']['output'];
/** Create a chat session and return full session payload */
createCopilotSessionWithHistory: CopilotHistories;
/** Create a stripe customer portal to manage payment methods */
createCustomerPortal: Scalars['String']['output'];
createInviteLink: InviteLink;
@@ -1845,8 +1797,6 @@ export interface Mutation {
updateCalendarAccount: Maybe<CalendarAccountObjectType>;
/** Update a comment content */
updateComment: Scalars['Boolean']['output'];
/** Update a copilot prompt */
updateCopilotPrompt: CopilotPromptType;
/** Update a chat session */
updateCopilotSession: Scalars['String']['output'];
updateDocDefaultRole: Scalars['Boolean']['output'];
@@ -1998,11 +1948,11 @@ export interface MutationCreateCopilotMessageArgs {
options: CreateChatMessageInput;
}
export interface MutationCreateCopilotPromptArgs {
input: CreateCopilotPromptInput;
export interface MutationCreateCopilotSessionArgs {
options: CreateChatSessionInput;
}
export interface MutationCreateCopilotSessionArgs {
export interface MutationCreateCopilotSessionWithHistoryArgs {
options: CreateChatSessionInput;
}
@@ -2262,11 +2212,6 @@ export interface MutationUpdateCommentArgs {
input: CommentUpdateInput;
}
export interface MutationUpdateCopilotPromptArgs {
messages: Array<CopilotPromptMessageInput>;
name: Scalars['String']['input'];
}
export interface MutationUpdateCopilotSessionArgs {
options: UpdateChatSessionInput;
}
@@ -2554,8 +2499,6 @@ export interface Query {
error: ErrorDataUnion;
/** get workspace invitation info */
getInviteInfo: InvitationType;
/** List all copilot prompts */
listCopilotPrompts: Array<CopilotPromptType>;
prices: Array<SubscriptionPrice>;
/** Get public user by id */
publicUserById: Maybe<PublicUserType>;
@@ -3886,59 +3829,6 @@ export type AppConfigQueryVariables = Exact<{ [key: string]: never }>;
export type AppConfigQuery = { __typename?: 'Query'; appConfig: any };
export type GetPromptsQueryVariables = Exact<{ [key: string]: never }>;
export type GetPromptsQuery = {
__typename?: 'Query';
listCopilotPrompts: Array<{
__typename?: 'CopilotPromptType';
name: string;
model: string;
action: string | null;
config: {
__typename?: 'CopilotPromptConfigType';
frequencyPenalty: number | null;
presencePenalty: number | null;
temperature: number | null;
topP: number | null;
} | null;
messages: Array<{
__typename?: 'CopilotPromptMessageType';
role: CopilotPromptMessageRole;
content: string;
params: Record<string, string> | null;
}>;
}>;
};
export type UpdatePromptMutationVariables = Exact<{
name: Scalars['String']['input'];
messages: Array<CopilotPromptMessageInput> | CopilotPromptMessageInput;
}>;
export type UpdatePromptMutation = {
__typename?: 'Mutation';
updateCopilotPrompt: {
__typename?: 'CopilotPromptType';
name: string;
model: string;
action: string | null;
config: {
__typename?: 'CopilotPromptConfigType';
frequencyPenalty: number | null;
presencePenalty: number | null;
temperature: number | null;
topP: number | null;
} | null;
messages: Array<{
__typename?: 'CopilotPromptMessageType';
role: CopilotPromptMessageRole;
content: string;
params: Record<string, string> | null;
}>;
};
};
export type CreateUserMutationVariables = Exact<{
input: CreateUserInput;
}>;
@@ -5425,6 +5315,47 @@ export type CleanupCopilotSessionMutation = {
cleanupCopilotSession: Array<string>;
};
export type CreateCopilotSessionWithHistoryMutationVariables = Exact<{
options: CreateChatSessionInput;
}>;
export type CreateCopilotSessionWithHistoryMutation = {
__typename?: 'Mutation';
createCopilotSessionWithHistory: {
__typename?: 'CopilotHistories';
sessionId: string;
workspaceId: string;
docId: string | null;
parentSessionId: string | null;
promptName: string;
model: string;
optionalModels: Array<string>;
action: string | null;
pinned: boolean;
title: string | null;
tokens: number;
createdAt: string;
updatedAt: string;
messages: Array<{
__typename?: 'ChatMessage';
id: string | null;
role: string;
content: string;
attachments: Array<string> | null;
createdAt: string;
streamObjects: Array<{
__typename?: 'StreamObject';
type: string;
textDelta: string | null;
toolCallId: string | null;
toolName: string | null;
args: Record<string, string> | null;
result: Record<string, string> | null;
}> | null;
}>;
};
};
export type CreateCopilotSessionMutationVariables = Exact<{
options: CreateChatSessionInput;
}>;
@@ -5934,24 +5865,6 @@ export type GetDocRolePermissionsQuery = {
};
};
export type CopilotChatMessageFragment = {
__typename?: 'ChatMessage';
id: string | null;
role: string;
content: string;
attachments: Array<string> | null;
createdAt: string;
streamObjects: Array<{
__typename?: 'StreamObject';
type: string;
textDelta: string | null;
toolCallId: string | null;
toolName: string | null;
args: Record<string, string> | null;
result: Record<string, string> | null;
}> | null;
};
export type CopilotChatHistoryFragment = {
__typename?: 'CopilotHistories';
sessionId: string;
@@ -5986,6 +5899,52 @@ export type CopilotChatHistoryFragment = {
}>;
};
export type CredentialsRequirementsFragment = {
__typename?: 'CredentialsRequirementType';
password: {
__typename?: 'PasswordLimitsType';
minLength: number;
maxLength: number;
};
};
export type CurrentUserProfileFragment = {
__typename?: 'UserType';
id: string;
name: string;
email: string;
avatarUrl: string | null;
emailVerified: boolean;
features: Array<FeatureType>;
settings: {
__typename?: 'UserSettingsType';
receiveInvitationEmail: boolean;
receiveMentionEmail: boolean;
receiveCommentEmail: boolean;
};
quota: {
__typename?: 'UserQuotaType';
name: string;
blobLimit: number;
storageQuota: number;
historyPeriod: number;
memberLimit: number;
humanReadable: {
__typename?: 'UserQuotaHumanReadableType';
name: string;
blobLimit: string;
storageQuota: string;
historyPeriod: string;
memberLimit: string;
};
};
quotaUsage: { __typename?: 'UserQuotaUsageType'; storageQuota: number };
copilot: {
__typename?: 'Copilot';
quota: { __typename?: 'CopilotQuota'; limit: number | null; used: number };
};
};
export type PaginatedCopilotChatsFragment = {
__typename?: 'PaginatedCopilotHistoriesType';
pageInfo: {
@@ -6034,52 +5993,6 @@ export type PaginatedCopilotChatsFragment = {
}>;
};
export type CredentialsRequirementsFragment = {
__typename?: 'CredentialsRequirementType';
password: {
__typename?: 'PasswordLimitsType';
minLength: number;
maxLength: number;
};
};
export type CurrentUserProfileFragment = {
__typename?: 'UserType';
id: string;
name: string;
email: string;
avatarUrl: string | null;
emailVerified: boolean;
features: Array<FeatureType>;
settings: {
__typename?: 'UserSettingsType';
receiveInvitationEmail: boolean;
receiveMentionEmail: boolean;
receiveCommentEmail: boolean;
};
quota: {
__typename?: 'UserQuotaType';
name: string;
blobLimit: number;
storageQuota: number;
historyPeriod: number;
memberLimit: number;
humanReadable: {
__typename?: 'UserQuotaHumanReadableType';
name: string;
blobLimit: string;
storageQuota: string;
historyPeriod: string;
memberLimit: string;
};
};
quotaUsage: { __typename?: 'UserQuotaUsageType'; storageQuota: number };
copilot: {
__typename?: 'Copilot';
quota: { __typename?: 'CopilotQuota'; limit: number | null; used: number };
};
};
export type PasswordLimitsFragment = {
__typename?: 'PasswordLimitsType';
minLength: number;
@@ -7623,11 +7536,6 @@ export type Queries =
variables: AppConfigQueryVariables;
response: AppConfigQuery;
}
| {
name: 'getPromptsQuery';
variables: GetPromptsQueryVariables;
response: GetPromptsQuery;
}
| {
name: 'getUserByEmailQuery';
variables: GetUserByEmailQueryVariables;
@@ -8035,11 +7943,6 @@ export type Mutations =
variables: CreateChangePasswordUrlMutationVariables;
response: CreateChangePasswordUrlMutation;
}
| {
name: 'updatePromptMutation';
variables: UpdatePromptMutationVariables;
response: UpdatePromptMutation;
}
| {
name: 'createUserMutation';
variables: CreateUserMutationVariables;
@@ -8275,6 +8178,11 @@ export type Mutations =
variables: CleanupCopilotSessionMutationVariables;
response: CleanupCopilotSessionMutation;
}
| {
name: 'createCopilotSessionWithHistoryMutation';
variables: CreateCopilotSessionWithHistoryMutationVariables;
response: CreateCopilotSessionWithHistoryMutation;
}
| {
name: 'createCopilotSessionMutation';
variables: CreateCopilotSessionMutationVariables;