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,57 +72,77 @@ export class CopilotClient {
|
|||||||
async createSession(
|
async createSession(
|
||||||
options: OptionsField<typeof createCopilotSessionMutation>
|
options: OptionsField<typeof createCopilotSessionMutation>
|
||||||
) {
|
) {
|
||||||
const res = await this.gql({
|
try {
|
||||||
query: createCopilotSessionMutation,
|
const res = await this.gql({
|
||||||
variables: {
|
query: createCopilotSessionMutation,
|
||||||
options,
|
variables: {
|
||||||
},
|
options,
|
||||||
});
|
},
|
||||||
return res.createCopilotSession;
|
});
|
||||||
|
return res.createCopilotSession;
|
||||||
|
} catch (err) {
|
||||||
|
throw resolveError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateSession(
|
async updateSession(
|
||||||
options: OptionsField<typeof updateCopilotSessionMutation>
|
options: OptionsField<typeof updateCopilotSessionMutation>
|
||||||
) {
|
) {
|
||||||
const res = await this.gql({
|
try {
|
||||||
query: updateCopilotSessionMutation,
|
const res = await this.gql({
|
||||||
variables: {
|
query: updateCopilotSessionMutation,
|
||||||
options,
|
variables: {
|
||||||
},
|
options,
|
||||||
});
|
},
|
||||||
return res.updateCopilotSession;
|
});
|
||||||
|
return res.updateCopilotSession;
|
||||||
|
} catch (err) {
|
||||||
|
throw resolveError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async forkSession(options: OptionsField<typeof forkCopilotSessionMutation>) {
|
async forkSession(options: OptionsField<typeof forkCopilotSessionMutation>) {
|
||||||
const res = await this.gql({
|
try {
|
||||||
query: forkCopilotSessionMutation,
|
const res = await this.gql({
|
||||||
variables: {
|
query: forkCopilotSessionMutation,
|
||||||
options,
|
variables: {
|
||||||
},
|
options,
|
||||||
});
|
},
|
||||||
return res.forkCopilotSession;
|
});
|
||||||
|
return res.forkCopilotSession;
|
||||||
|
} catch (err) {
|
||||||
|
throw resolveError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async createMessage(
|
async createMessage(
|
||||||
options: OptionsField<typeof createCopilotMessageMutation>
|
options: OptionsField<typeof createCopilotMessageMutation>
|
||||||
) {
|
) {
|
||||||
const res = await this.gql({
|
try {
|
||||||
query: createCopilotMessageMutation,
|
const res = await this.gql({
|
||||||
variables: {
|
query: createCopilotMessageMutation,
|
||||||
options,
|
variables: {
|
||||||
},
|
options,
|
||||||
});
|
},
|
||||||
return res.createCopilotMessage;
|
});
|
||||||
|
return res.createCopilotMessage;
|
||||||
|
} catch (err) {
|
||||||
|
throw resolveError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSessions(workspaceId: string) {
|
async getSessions(workspaceId: string) {
|
||||||
const res = await this.gql({
|
try {
|
||||||
query: getCopilotSessionsQuery,
|
const res = await this.gql({
|
||||||
variables: {
|
query: getCopilotSessionsQuery,
|
||||||
workspaceId,
|
variables: {
|
||||||
},
|
workspaceId,
|
||||||
});
|
},
|
||||||
return res.currentUser?.copilot;
|
});
|
||||||
|
return res.currentUser?.copilot;
|
||||||
|
} catch (err) {
|
||||||
|
throw resolveError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getHistories(
|
async getHistories(
|
||||||
@@ -132,16 +152,20 @@ export class CopilotClient {
|
|||||||
typeof getCopilotHistoriesQuery
|
typeof getCopilotHistoriesQuery
|
||||||
>['variables']['options']
|
>['variables']['options']
|
||||||
) {
|
) {
|
||||||
const res = await this.gql({
|
try {
|
||||||
query: getCopilotHistoriesQuery,
|
const res = await this.gql({
|
||||||
variables: {
|
query: getCopilotHistoriesQuery,
|
||||||
workspaceId,
|
variables: {
|
||||||
docId,
|
workspaceId,
|
||||||
options,
|
docId,
|
||||||
},
|
options,
|
||||||
});
|
},
|
||||||
|
});
|
||||||
|
|
||||||
return res.currentUser?.copilot?.histories;
|
return res.currentUser?.copilot?.histories;
|
||||||
|
} catch (err) {
|
||||||
|
throw resolveError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getHistoryIds(
|
async getHistoryIds(
|
||||||
@@ -151,16 +175,20 @@ export class CopilotClient {
|
|||||||
typeof getCopilotHistoriesQuery
|
typeof getCopilotHistoriesQuery
|
||||||
>['variables']['options']
|
>['variables']['options']
|
||||||
) {
|
) {
|
||||||
const res = await this.gql({
|
try {
|
||||||
query: getCopilotHistoryIdsQuery,
|
const res = await this.gql({
|
||||||
variables: {
|
query: getCopilotHistoryIdsQuery,
|
||||||
workspaceId,
|
variables: {
|
||||||
docId,
|
workspaceId,
|
||||||
options,
|
docId,
|
||||||
},
|
options,
|
||||||
});
|
},
|
||||||
|
});
|
||||||
|
|
||||||
return res.currentUser?.copilot?.histories;
|
return res.currentUser?.copilot?.histories;
|
||||||
|
} catch (err) {
|
||||||
|
throw resolveError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async cleanupSessions(input: {
|
async cleanupSessions(input: {
|
||||||
@@ -168,13 +196,17 @@ export class CopilotClient {
|
|||||||
docId: string;
|
docId: string;
|
||||||
sessionIds: string[];
|
sessionIds: string[];
|
||||||
}) {
|
}) {
|
||||||
const res = await this.gql({
|
try {
|
||||||
query: cleanupCopilotSessionMutation,
|
const res = await this.gql({
|
||||||
variables: {
|
query: cleanupCopilotSessionMutation,
|
||||||
input,
|
variables: {
|
||||||
},
|
input,
|
||||||
});
|
},
|
||||||
return res.cleanupCopilotSession;
|
});
|
||||||
|
return res.cleanupCopilotSession;
|
||||||
|
} catch (err) {
|
||||||
|
throw resolveError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async chatText({
|
async chatText({
|
||||||
|
|||||||
Reference in New Issue
Block a user