Skip to content

Commit

Permalink
fix(presets): ai message should be encoded (#6707)
Browse files Browse the repository at this point in the history
message in url should be encoded
  • Loading branch information
pengx17 committed Apr 9, 2024
1 parent db8b241 commit 4585926
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/presets/src/ai/copilot-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,15 @@ export class CopilotClient {

async textToText(text: string, sessionId: string) {
const res = await fetch(
`${this.backendUrl}/api/copilot/chat/${sessionId}?message=${text}`
`${this.backendUrl}/api/copilot/chat/${sessionId}?message=${encodeURIComponent(text)}`
);
if (!res.ok) return;
return res.text();
}

textToTextStream(text: string, sessionId: string) {
return new EventSource(
`${this.backendUrl}/api/copilot/chat/${sessionId}/stream?message=${text}`
`${this.backendUrl}/api/copilot/chat/${sessionId}/stream?message=${encodeURIComponent(text)}`
);
}
}
3 changes: 2 additions & 1 deletion packages/presets/src/ai/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export interface AIUserInfo {
*/
export class AIProvider {
private readonly actions: Partial<BlockSuitePresets.AIActions> = {};
private userInfoFn: () => AIUserInfo | null = () => null;
private userInfoFn: () => AIUserInfo | Promise<AIUserInfo> | null = () =>
null;
private static readonly instance = new AIProvider();

static provideAction<T extends keyof BlockSuitePresets.AIActions>(
Expand Down

0 comments on commit 4585926

Please sign in to comment.