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:
@@ -155,7 +155,7 @@ export class AIPanelError extends WithDisposable(LitElement) {
|
|||||||
<span>Cancel</span>
|
<span>Cancel</span>
|
||||||
</div>
|
</div>
|
||||||
<div @click=${this.config.login} class="action-button primary">
|
<div @click=${this.config.login} class="action-button primary">
|
||||||
<span>login</span>
|
<span>Login</span>
|
||||||
</div>
|
</div>
|
||||||
</div>`,
|
</div>`,
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ export class TextRenderer extends WithDisposable(ShadowlessElement) {
|
|||||||
|
|
||||||
.ai-answer-text-editor .affine-page-root-block-container {
|
.ai-answer-text-editor .affine-page-root-block-container {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
line-height: var(--affine-line-height);
|
line-height: var(--affine-line-height);
|
||||||
color: var(--affine-text-primary-color);
|
color: var(--affine-text-primary-color);
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ export class CopilotClient {
|
|||||||
async createSession(
|
async createSession(
|
||||||
options: OptionsField<typeof createCopilotSessionMutation>
|
options: OptionsField<typeof createCopilotSessionMutation>
|
||||||
) {
|
) {
|
||||||
|
try {
|
||||||
const res = await this.gql({
|
const res = await this.gql({
|
||||||
query: createCopilotSessionMutation,
|
query: createCopilotSessionMutation,
|
||||||
variables: {
|
variables: {
|
||||||
@@ -79,11 +80,15 @@ export class CopilotClient {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
return res.createCopilotSession;
|
return res.createCopilotSession;
|
||||||
|
} catch (err) {
|
||||||
|
throw resolveError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateSession(
|
async updateSession(
|
||||||
options: OptionsField<typeof updateCopilotSessionMutation>
|
options: OptionsField<typeof updateCopilotSessionMutation>
|
||||||
) {
|
) {
|
||||||
|
try {
|
||||||
const res = await this.gql({
|
const res = await this.gql({
|
||||||
query: updateCopilotSessionMutation,
|
query: updateCopilotSessionMutation,
|
||||||
variables: {
|
variables: {
|
||||||
@@ -91,9 +96,13 @@ export class CopilotClient {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
return res.updateCopilotSession;
|
return res.updateCopilotSession;
|
||||||
|
} catch (err) {
|
||||||
|
throw resolveError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async forkSession(options: OptionsField<typeof forkCopilotSessionMutation>) {
|
async forkSession(options: OptionsField<typeof forkCopilotSessionMutation>) {
|
||||||
|
try {
|
||||||
const res = await this.gql({
|
const res = await this.gql({
|
||||||
query: forkCopilotSessionMutation,
|
query: forkCopilotSessionMutation,
|
||||||
variables: {
|
variables: {
|
||||||
@@ -101,11 +110,15 @@ export class CopilotClient {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
return res.forkCopilotSession;
|
return res.forkCopilotSession;
|
||||||
|
} catch (err) {
|
||||||
|
throw resolveError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async createMessage(
|
async createMessage(
|
||||||
options: OptionsField<typeof createCopilotMessageMutation>
|
options: OptionsField<typeof createCopilotMessageMutation>
|
||||||
) {
|
) {
|
||||||
|
try {
|
||||||
const res = await this.gql({
|
const res = await this.gql({
|
||||||
query: createCopilotMessageMutation,
|
query: createCopilotMessageMutation,
|
||||||
variables: {
|
variables: {
|
||||||
@@ -113,9 +126,13 @@ export class CopilotClient {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
return res.createCopilotMessage;
|
return res.createCopilotMessage;
|
||||||
|
} catch (err) {
|
||||||
|
throw resolveError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSessions(workspaceId: string) {
|
async getSessions(workspaceId: string) {
|
||||||
|
try {
|
||||||
const res = await this.gql({
|
const res = await this.gql({
|
||||||
query: getCopilotSessionsQuery,
|
query: getCopilotSessionsQuery,
|
||||||
variables: {
|
variables: {
|
||||||
@@ -123,6 +140,9 @@ export class CopilotClient {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
return res.currentUser?.copilot;
|
return res.currentUser?.copilot;
|
||||||
|
} catch (err) {
|
||||||
|
throw resolveError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getHistories(
|
async getHistories(
|
||||||
@@ -132,6 +152,7 @@ export class CopilotClient {
|
|||||||
typeof getCopilotHistoriesQuery
|
typeof getCopilotHistoriesQuery
|
||||||
>['variables']['options']
|
>['variables']['options']
|
||||||
) {
|
) {
|
||||||
|
try {
|
||||||
const res = await this.gql({
|
const res = await this.gql({
|
||||||
query: getCopilotHistoriesQuery,
|
query: getCopilotHistoriesQuery,
|
||||||
variables: {
|
variables: {
|
||||||
@@ -142,6 +163,9 @@ export class CopilotClient {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return res.currentUser?.copilot?.histories;
|
return res.currentUser?.copilot?.histories;
|
||||||
|
} catch (err) {
|
||||||
|
throw resolveError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getHistoryIds(
|
async getHistoryIds(
|
||||||
@@ -151,6 +175,7 @@ export class CopilotClient {
|
|||||||
typeof getCopilotHistoriesQuery
|
typeof getCopilotHistoriesQuery
|
||||||
>['variables']['options']
|
>['variables']['options']
|
||||||
) {
|
) {
|
||||||
|
try {
|
||||||
const res = await this.gql({
|
const res = await this.gql({
|
||||||
query: getCopilotHistoryIdsQuery,
|
query: getCopilotHistoryIdsQuery,
|
||||||
variables: {
|
variables: {
|
||||||
@@ -161,6 +186,9 @@ export class CopilotClient {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return res.currentUser?.copilot?.histories;
|
return res.currentUser?.copilot?.histories;
|
||||||
|
} catch (err) {
|
||||||
|
throw resolveError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async cleanupSessions(input: {
|
async cleanupSessions(input: {
|
||||||
@@ -168,6 +196,7 @@ export class CopilotClient {
|
|||||||
docId: string;
|
docId: string;
|
||||||
sessionIds: string[];
|
sessionIds: string[];
|
||||||
}) {
|
}) {
|
||||||
|
try {
|
||||||
const res = await this.gql({
|
const res = await this.gql({
|
||||||
query: cleanupCopilotSessionMutation,
|
query: cleanupCopilotSessionMutation,
|
||||||
variables: {
|
variables: {
|
||||||
@@ -175,6 +204,9 @@ export class CopilotClient {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
return res.cleanupCopilotSession;
|
return res.cleanupCopilotSession;
|
||||||
|
} catch (err) {
|
||||||
|
throw resolveError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async chatText({
|
async chatText({
|
||||||
|
|||||||
Reference in New Issue
Block a user