mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-07 20:31:33 +08:00
fix(core): online search button status not updated to the search prompt (#11542)
Close [BS-3079](https://linear.app/affine-design/issue/BS-3079).
This commit is contained in:
@@ -22,6 +22,7 @@ import {
|
|||||||
selectAboveBlocks,
|
selectAboveBlocks,
|
||||||
} from '../utils/selection-utils';
|
} from '../utils/selection-utils';
|
||||||
import type { AffineAIPanelWidget } from '../widgets/ai-panel/ai-panel';
|
import type { AffineAIPanelWidget } from '../widgets/ai-panel/ai-panel';
|
||||||
|
import type { AINetworkSearchConfig } from '../widgets/ai-panel/type';
|
||||||
import { actionToAnswerRenderer } from './answer-renderer';
|
import { actionToAnswerRenderer } from './answer-renderer';
|
||||||
|
|
||||||
export function bindTextStream(
|
export function bindTextStream(
|
||||||
@@ -69,7 +70,8 @@ function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
|
|||||||
Parameters<BlockSuitePresets.AIActions[T]>[0],
|
Parameters<BlockSuitePresets.AIActions[T]>[0],
|
||||||
keyof BlockSuitePresets.AITextActionOptions
|
keyof BlockSuitePresets.AITextActionOptions
|
||||||
>,
|
>,
|
||||||
trackerOptions?: BlockSuitePresets.TrackerOptions
|
trackerOptions?: BlockSuitePresets.TrackerOptions,
|
||||||
|
networkConfig?: AINetworkSearchConfig
|
||||||
): BlockSuitePresets.TextStream | undefined {
|
): BlockSuitePresets.TextStream | undefined {
|
||||||
const action = AIProvider.actions[id];
|
const action = AIProvider.actions[id];
|
||||||
if (!action || typeof action !== 'function') return;
|
if (!action || typeof action !== 'function') return;
|
||||||
@@ -94,10 +96,11 @@ function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
|
|||||||
const models = selectedBlocks?.map(block => block.model);
|
const models = selectedBlocks?.map(block => block.model);
|
||||||
const control = trackerOptions?.control ?? 'format-bar';
|
const control = trackerOptions?.control ?? 'format-bar';
|
||||||
const where = trackerOptions?.where ?? 'ai-panel';
|
const where = trackerOptions?.where ?? 'ai-panel';
|
||||||
|
const { visible, enabled } = networkConfig ?? {};
|
||||||
const options = {
|
const options = {
|
||||||
...variants,
|
...variants,
|
||||||
attachments,
|
attachments,
|
||||||
input: input ? `${markdown}\n${input}` : markdown,
|
input: input ? (markdown ? `${markdown}\n${input}` : input) : markdown,
|
||||||
stream: true,
|
stream: true,
|
||||||
host,
|
host,
|
||||||
models,
|
models,
|
||||||
@@ -106,6 +109,7 @@ function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
|
|||||||
where,
|
where,
|
||||||
docId: host.doc.id,
|
docId: host.doc.id,
|
||||||
workspaceId: host.doc.workspace.id,
|
workspaceId: host.doc.workspace.id,
|
||||||
|
networkSearch: visible?.value && enabled?.value,
|
||||||
} as Parameters<typeof action>[0];
|
} as Parameters<typeof action>[0];
|
||||||
// @ts-expect-error TODO(@Peng): maybe fix this
|
// @ts-expect-error TODO(@Peng): maybe fix this
|
||||||
stream = await action(options);
|
stream = await action(options);
|
||||||
@@ -122,7 +126,8 @@ function actionToGenerateAnswer<T extends keyof BlockSuitePresets.AIActions>(
|
|||||||
Parameters<BlockSuitePresets.AIActions[T]>[0],
|
Parameters<BlockSuitePresets.AIActions[T]>[0],
|
||||||
keyof BlockSuitePresets.AITextActionOptions
|
keyof BlockSuitePresets.AITextActionOptions
|
||||||
>,
|
>,
|
||||||
trackerOptions?: BlockSuitePresets.TrackerOptions
|
trackerOptions?: BlockSuitePresets.TrackerOptions,
|
||||||
|
networkConfig?: AINetworkSearchConfig
|
||||||
) {
|
) {
|
||||||
return ({
|
return ({
|
||||||
input,
|
input,
|
||||||
@@ -143,7 +148,8 @@ function actionToGenerateAnswer<T extends keyof BlockSuitePresets.AIActions>(
|
|||||||
input,
|
input,
|
||||||
signal,
|
signal,
|
||||||
variants,
|
variants,
|
||||||
trackerOptions
|
trackerOptions,
|
||||||
|
networkConfig
|
||||||
);
|
);
|
||||||
if (!stream) return;
|
if (!stream) return;
|
||||||
bindTextStream(stream, { update, finish, signal });
|
bindTextStream(stream, { update, finish, signal });
|
||||||
@@ -171,7 +177,8 @@ function updateAIPanelConfig<T extends keyof BlockSuitePresets.AIActions>(
|
|||||||
host,
|
host,
|
||||||
id,
|
id,
|
||||||
variants,
|
variants,
|
||||||
trackerOptions
|
trackerOptions,
|
||||||
|
config.networkSearchConfig
|
||||||
);
|
);
|
||||||
|
|
||||||
const ctx = new AIContext();
|
const ctx = new AIContext();
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import {
|
|||||||
getSelections,
|
getSelections,
|
||||||
} from '../utils/selection-utils';
|
} from '../utils/selection-utils';
|
||||||
import type { AffineAIPanelWidget } from '../widgets/ai-panel/ai-panel';
|
import type { AffineAIPanelWidget } from '../widgets/ai-panel/ai-panel';
|
||||||
|
import type { AINetworkSearchConfig } from '../widgets/ai-panel/type';
|
||||||
import type { EdgelessCopilotWidget } from '../widgets/edgeless-copilot';
|
import type { EdgelessCopilotWidget } from '../widgets/edgeless-copilot';
|
||||||
import { actionToAnswerRenderer } from './answer-renderer';
|
import { actionToAnswerRenderer } from './answer-renderer';
|
||||||
import { EXCLUDING_COPY_ACTIONS } from './consts';
|
import { EXCLUDING_COPY_ACTIONS } from './consts';
|
||||||
@@ -168,7 +169,8 @@ function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
|
|||||||
seed?: string;
|
seed?: string;
|
||||||
} | void>,
|
} | void>,
|
||||||
trackerOptions?: BlockSuitePresets.TrackerOptions,
|
trackerOptions?: BlockSuitePresets.TrackerOptions,
|
||||||
panelInput?: string
|
panelInput?: string,
|
||||||
|
networkConfig?: AINetworkSearchConfig
|
||||||
) {
|
) {
|
||||||
const action = AIProvider.actions[id];
|
const action = AIProvider.actions[id];
|
||||||
|
|
||||||
@@ -182,6 +184,7 @@ function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
|
|||||||
return {
|
return {
|
||||||
async *[Symbol.asyncIterator]() {
|
async *[Symbol.asyncIterator]() {
|
||||||
const models = getCopilotSelectedElems(host);
|
const models = getCopilotSelectedElems(host);
|
||||||
|
const { visible, enabled } = networkConfig ?? {};
|
||||||
const options = {
|
const options = {
|
||||||
...variants,
|
...variants,
|
||||||
signal,
|
signal,
|
||||||
@@ -193,6 +196,7 @@ function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
|
|||||||
host,
|
host,
|
||||||
docId: host.doc.id,
|
docId: host.doc.id,
|
||||||
workspaceId: host.doc.workspace.id,
|
workspaceId: host.doc.workspace.id,
|
||||||
|
networkSearch: visible?.value && enabled?.value,
|
||||||
} as Parameters<typeof action>[0];
|
} as Parameters<typeof action>[0];
|
||||||
|
|
||||||
const content = ctx.get().content;
|
const content = ctx.get().content;
|
||||||
@@ -259,7 +263,8 @@ function actionToGeneration<T extends keyof BlockSuitePresets.AIActions>(
|
|||||||
attachments?: (string | Blob)[];
|
attachments?: (string | Blob)[];
|
||||||
seed?: string;
|
seed?: string;
|
||||||
} | void>,
|
} | void>,
|
||||||
trackerOptions?: BlockSuitePresets.TrackerOptions
|
trackerOptions?: BlockSuitePresets.TrackerOptions,
|
||||||
|
networkConfig?: AINetworkSearchConfig
|
||||||
) {
|
) {
|
||||||
return (host: EditorHost, ctx: AIContext) => {
|
return (host: EditorHost, ctx: AIContext) => {
|
||||||
return ({
|
return ({
|
||||||
@@ -284,7 +289,8 @@ function actionToGeneration<T extends keyof BlockSuitePresets.AIActions>(
|
|||||||
variants,
|
variants,
|
||||||
extract,
|
extract,
|
||||||
trackerOptions,
|
trackerOptions,
|
||||||
input
|
input,
|
||||||
|
networkConfig
|
||||||
)?.(host, ctx);
|
)?.(host, ctx);
|
||||||
|
|
||||||
if (!stream) return;
|
if (!stream) return;
|
||||||
@@ -325,7 +331,8 @@ function updateEdgelessAIPanelConfig<
|
|||||||
id,
|
id,
|
||||||
variants,
|
variants,
|
||||||
customInput,
|
customInput,
|
||||||
trackerOptions
|
trackerOptions,
|
||||||
|
config.networkSearchConfig
|
||||||
)(host, ctx);
|
)(host, ctx);
|
||||||
config.finishStateConfig = actionToResponse(id, host, ctx, variants);
|
config.finishStateConfig = actionToResponse(id, host, ctx, variants);
|
||||||
config.generatingStateConfig = actionToGenerating(id, generatingIcon);
|
config.generatingStateConfig = actionToGenerating(id, generatingIcon);
|
||||||
|
|||||||
Reference in New Issue
Block a user