mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00: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,
|
||||
} from '../utils/selection-utils';
|
||||
import type { AffineAIPanelWidget } from '../widgets/ai-panel/ai-panel';
|
||||
import type { AINetworkSearchConfig } from '../widgets/ai-panel/type';
|
||||
import { actionToAnswerRenderer } from './answer-renderer';
|
||||
|
||||
export function bindTextStream(
|
||||
@@ -69,7 +70,8 @@ function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
|
||||
Parameters<BlockSuitePresets.AIActions[T]>[0],
|
||||
keyof BlockSuitePresets.AITextActionOptions
|
||||
>,
|
||||
trackerOptions?: BlockSuitePresets.TrackerOptions
|
||||
trackerOptions?: BlockSuitePresets.TrackerOptions,
|
||||
networkConfig?: AINetworkSearchConfig
|
||||
): BlockSuitePresets.TextStream | undefined {
|
||||
const action = AIProvider.actions[id];
|
||||
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 control = trackerOptions?.control ?? 'format-bar';
|
||||
const where = trackerOptions?.where ?? 'ai-panel';
|
||||
const { visible, enabled } = networkConfig ?? {};
|
||||
const options = {
|
||||
...variants,
|
||||
attachments,
|
||||
input: input ? `${markdown}\n${input}` : markdown,
|
||||
input: input ? (markdown ? `${markdown}\n${input}` : input) : markdown,
|
||||
stream: true,
|
||||
host,
|
||||
models,
|
||||
@@ -106,6 +109,7 @@ function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
|
||||
where,
|
||||
docId: host.doc.id,
|
||||
workspaceId: host.doc.workspace.id,
|
||||
networkSearch: visible?.value && enabled?.value,
|
||||
} as Parameters<typeof action>[0];
|
||||
// @ts-expect-error TODO(@Peng): maybe fix this
|
||||
stream = await action(options);
|
||||
@@ -122,7 +126,8 @@ function actionToGenerateAnswer<T extends keyof BlockSuitePresets.AIActions>(
|
||||
Parameters<BlockSuitePresets.AIActions[T]>[0],
|
||||
keyof BlockSuitePresets.AITextActionOptions
|
||||
>,
|
||||
trackerOptions?: BlockSuitePresets.TrackerOptions
|
||||
trackerOptions?: BlockSuitePresets.TrackerOptions,
|
||||
networkConfig?: AINetworkSearchConfig
|
||||
) {
|
||||
return ({
|
||||
input,
|
||||
@@ -143,7 +148,8 @@ function actionToGenerateAnswer<T extends keyof BlockSuitePresets.AIActions>(
|
||||
input,
|
||||
signal,
|
||||
variants,
|
||||
trackerOptions
|
||||
trackerOptions,
|
||||
networkConfig
|
||||
);
|
||||
if (!stream) return;
|
||||
bindTextStream(stream, { update, finish, signal });
|
||||
@@ -171,7 +177,8 @@ function updateAIPanelConfig<T extends keyof BlockSuitePresets.AIActions>(
|
||||
host,
|
||||
id,
|
||||
variants,
|
||||
trackerOptions
|
||||
trackerOptions,
|
||||
config.networkSearchConfig
|
||||
);
|
||||
|
||||
const ctx = new AIContext();
|
||||
|
||||
@@ -36,6 +36,7 @@ import {
|
||||
getSelections,
|
||||
} from '../utils/selection-utils';
|
||||
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 { actionToAnswerRenderer } from './answer-renderer';
|
||||
import { EXCLUDING_COPY_ACTIONS } from './consts';
|
||||
@@ -168,7 +169,8 @@ function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
|
||||
seed?: string;
|
||||
} | void>,
|
||||
trackerOptions?: BlockSuitePresets.TrackerOptions,
|
||||
panelInput?: string
|
||||
panelInput?: string,
|
||||
networkConfig?: AINetworkSearchConfig
|
||||
) {
|
||||
const action = AIProvider.actions[id];
|
||||
|
||||
@@ -182,6 +184,7 @@ function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
|
||||
return {
|
||||
async *[Symbol.asyncIterator]() {
|
||||
const models = getCopilotSelectedElems(host);
|
||||
const { visible, enabled } = networkConfig ?? {};
|
||||
const options = {
|
||||
...variants,
|
||||
signal,
|
||||
@@ -193,6 +196,7 @@ function actionToStream<T extends keyof BlockSuitePresets.AIActions>(
|
||||
host,
|
||||
docId: host.doc.id,
|
||||
workspaceId: host.doc.workspace.id,
|
||||
networkSearch: visible?.value && enabled?.value,
|
||||
} as Parameters<typeof action>[0];
|
||||
|
||||
const content = ctx.get().content;
|
||||
@@ -259,7 +263,8 @@ function actionToGeneration<T extends keyof BlockSuitePresets.AIActions>(
|
||||
attachments?: (string | Blob)[];
|
||||
seed?: string;
|
||||
} | void>,
|
||||
trackerOptions?: BlockSuitePresets.TrackerOptions
|
||||
trackerOptions?: BlockSuitePresets.TrackerOptions,
|
||||
networkConfig?: AINetworkSearchConfig
|
||||
) {
|
||||
return (host: EditorHost, ctx: AIContext) => {
|
||||
return ({
|
||||
@@ -284,7 +289,8 @@ function actionToGeneration<T extends keyof BlockSuitePresets.AIActions>(
|
||||
variants,
|
||||
extract,
|
||||
trackerOptions,
|
||||
input
|
||||
input,
|
||||
networkConfig
|
||||
)?.(host, ctx);
|
||||
|
||||
if (!stream) return;
|
||||
@@ -325,7 +331,8 @@ function updateEdgelessAIPanelConfig<
|
||||
id,
|
||||
variants,
|
||||
customInput,
|
||||
trackerOptions
|
||||
trackerOptions,
|
||||
config.networkSearchConfig
|
||||
)(host, ctx);
|
||||
config.finishStateConfig = actionToResponse(id, host, ctx, variants);
|
||||
config.generatingStateConfig = actionToGenerating(id, generatingIcon);
|
||||
|
||||
Reference in New Issue
Block a user