refactor(core): use the websearch parameters passed in by the front-end (#11989)

Support [AI-60](https://linear.app/affine-design/issue/AI-60).

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **Refactor**
  - Updated naming conventions for the web search tool to ensure consistency across AI chat features.
  - Simplified internal handling of web search tool options for a more streamlined experience.
  - Unified parameter naming from "mustSearch" to "webSearch" across AI chat inputs and actions.
- **Chores**
  - Removed unused configuration options related to web search from prompt settings.
  - Added support for enabling or disabling web search via new parameters in chat requests.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
akumatus
2025-04-28 07:49:54 +00:00
committed by Yue Wu
parent e366f69707
commit cf5574caf6
12 changed files with 51 additions and 32 deletions

View File

@@ -109,7 +109,7 @@ function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
where,
docId: host.doc.id,
workspaceId: host.doc.workspace.id,
mustSearch: visible?.value && enabled?.value,
webSearch: visible?.value && enabled?.value,
} as Parameters<typeof action>[0];
// @ts-expect-error TODO(@Peng): maybe fix this
stream = await action(options);

View File

@@ -199,7 +199,7 @@ function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
host,
docId: host.doc.id,
workspaceId: host.doc.workspace.id,
mustSearch: visible?.value && enabled?.value,
webSearch: visible?.value && enabled?.value,
} as Parameters<typeof action>[0];
const content = ctx.get().content;

View File

@@ -133,7 +133,7 @@ declare global {
interface ChatOptions extends AITextActionOptions {
sessionId?: string;
isRootSession?: boolean;
mustSearch?: boolean;
webSearch?: boolean;
reasoning?: boolean;
contexts?: {
docs: AIDocContextOption[];

View File

@@ -560,7 +560,7 @@ export class AIChatInput extends SignalWatcher(WithDisposable(LitElement)) {
isRootSession: this.isRootSession,
where: this.trackOptions.where,
control: this.trackOptions.control,
mustSearch: this._isNetworkActive,
webSearch: this._isNetworkActive,
reasoning: this._isReasoningActive,
});

View File

@@ -351,17 +351,20 @@ export class CopilotClient {
sessionId,
messageId,
reasoning,
webSearch,
signal,
}: {
sessionId: string;
messageId?: string;
reasoning?: boolean;
webSearch?: boolean;
signal?: AbortSignal;
}) {
let url = `/api/copilot/chat/${sessionId}`;
const queryString = this.paramsToQueryString({
messageId,
reasoning,
webSearch,
});
if (queryString) {
url += `?${queryString}`;
@@ -376,10 +379,12 @@ export class CopilotClient {
sessionId,
messageId,
reasoning,
webSearch,
}: {
sessionId: string;
messageId?: string;
reasoning?: boolean;
webSearch?: boolean;
},
endpoint = 'stream'
) {
@@ -387,6 +392,7 @@ export class CopilotClient {
const queryString = this.paramsToQueryString({
messageId,
reasoning,
webSearch,
});
if (queryString) {
url += `?${queryString}`;

View File

@@ -20,6 +20,7 @@ export type TextToTextOptions = {
isRootSession?: boolean;
postfix?: (text: string) => string;
reasoning?: boolean;
webSearch?: boolean;
};
export type ToImageOptions = TextToTextOptions & {
@@ -115,6 +116,7 @@ export function textToText({
workflow = false,
postfix,
reasoning,
webSearch,
}: TextToTextOptions) {
let messageId: string | undefined;
@@ -135,6 +137,7 @@ export function textToText({
sessionId,
messageId,
reasoning,
webSearch,
},
workflow ? 'workflow' : undefined
);
@@ -195,6 +198,7 @@ export function textToText({
sessionId,
messageId,
reasoning,
webSearch,
});
})(),
]);

View File

@@ -82,7 +82,7 @@ export function setupAIProvider(
//#region actions
AIProvider.provide('chat', async options => {
const { input, contexts, mustSearch } = options;
const { input, contexts, webSearch } = options;
const sessionId = await createSession({
promptName: 'Chat With AFFiNE AI',
@@ -96,7 +96,7 @@ export function setupAIProvider(
params: {
docs: contexts?.docs,
files: contexts?.files,
searchMode: mustSearch ? 'MUST' : 'CAN',
searchMode: webSearch ? 'MUST' : 'CAN',
},
});
});