fix(core): copilot client should throw right ai error (#9958)

[BS-2488](https://linear.app/affine-design/issue/BS-2488/copilot-client-需要正确返回错误类型)
This commit is contained in:
donteatfriedrice
2025-02-05 12:46:12 +00:00
parent 4ed03c9f0e
commit 9cae1c3a28
3 changed files with 94 additions and 61 deletions

View File

@@ -155,7 +155,7 @@ export class AIPanelError extends WithDisposable(LitElement) {
<span>Cancel</span>
</div>
<div @click=${this.config.login} class="action-button primary">
<span>login</span>
<span>Login</span>
</div>
</div>`,
],

View File

@@ -100,6 +100,7 @@ export class TextRenderer extends WithDisposable(ShadowlessElement) {
.ai-answer-text-editor .affine-page-root-block-container {
padding: 0;
margin: 0;
line-height: var(--affine-line-height);
color: var(--affine-text-primary-color);
font-weight: 400;

View File

@@ -72,6 +72,7 @@ export class CopilotClient {
async createSession(
options: OptionsField<typeof createCopilotSessionMutation>
) {
try {
const res = await this.gql({
query: createCopilotSessionMutation,
variables: {
@@ -79,11 +80,15 @@ export class CopilotClient {
},
});
return res.createCopilotSession;
} catch (err) {
throw resolveError(err);
}
}
async updateSession(
options: OptionsField<typeof updateCopilotSessionMutation>
) {
try {
const res = await this.gql({
query: updateCopilotSessionMutation,
variables: {
@@ -91,9 +96,13 @@ export class CopilotClient {
},
});
return res.updateCopilotSession;
} catch (err) {
throw resolveError(err);
}
}
async forkSession(options: OptionsField<typeof forkCopilotSessionMutation>) {
try {
const res = await this.gql({
query: forkCopilotSessionMutation,
variables: {
@@ -101,11 +110,15 @@ export class CopilotClient {
},
});
return res.forkCopilotSession;
} catch (err) {
throw resolveError(err);
}
}
async createMessage(
options: OptionsField<typeof createCopilotMessageMutation>
) {
try {
const res = await this.gql({
query: createCopilotMessageMutation,
variables: {
@@ -113,9 +126,13 @@ export class CopilotClient {
},
});
return res.createCopilotMessage;
} catch (err) {
throw resolveError(err);
}
}
async getSessions(workspaceId: string) {
try {
const res = await this.gql({
query: getCopilotSessionsQuery,
variables: {
@@ -123,6 +140,9 @@ export class CopilotClient {
},
});
return res.currentUser?.copilot;
} catch (err) {
throw resolveError(err);
}
}
async getHistories(
@@ -132,6 +152,7 @@ export class CopilotClient {
typeof getCopilotHistoriesQuery
>['variables']['options']
) {
try {
const res = await this.gql({
query: getCopilotHistoriesQuery,
variables: {
@@ -142,6 +163,9 @@ export class CopilotClient {
});
return res.currentUser?.copilot?.histories;
} catch (err) {
throw resolveError(err);
}
}
async getHistoryIds(
@@ -151,6 +175,7 @@ export class CopilotClient {
typeof getCopilotHistoriesQuery
>['variables']['options']
) {
try {
const res = await this.gql({
query: getCopilotHistoryIdsQuery,
variables: {
@@ -161,6 +186,9 @@ export class CopilotClient {
});
return res.currentUser?.copilot?.histories;
} catch (err) {
throw resolveError(err);
}
}
async cleanupSessions(input: {
@@ -168,6 +196,7 @@ export class CopilotClient {
docId: string;
sessionIds: string[];
}) {
try {
const res = await this.gql({
query: cleanupCopilotSessionMutation,
variables: {
@@ -175,6 +204,9 @@ export class CopilotClient {
},
});
return res.cleanupCopilotSession;
} catch (err) {
throw resolveError(err);
}
}
async chatText({