From b6745e50c633d11333a673687a4b1bef56895090 Mon Sep 17 00:00:00 2001 From: balibabu Date: Tue, 29 Jul 2025 13:15:37 +0800 Subject: [PATCH] Feat: Add Yahoo Finance Operator #3221 (#9088) ### What problem does this PR solve? Feat: Add Yahoo Finance Operator #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- .../node/dropdown/next-step-dropdown.tsx | 1 + web/src/pages/agent/constant.tsx | 8 +- .../pages/agent/form/tool-form/constant.tsx | 2 +- .../tool-form/yahoo-finance-form/index.tsx | 40 +++++ .../agent/form/yahoo-finance-form/index.tsx | 151 ++++++++++++++---- .../hooks/use-agent-tool-initial-values.ts | 2 + 6 files changed, 171 insertions(+), 33 deletions(-) create mode 100644 web/src/pages/agent/form/tool-form/yahoo-finance-form/index.tsx diff --git a/web/src/pages/agent/canvas/node/dropdown/next-step-dropdown.tsx b/web/src/pages/agent/canvas/node/dropdown/next-step-dropdown.tsx index 268a68373..11139417b 100644 --- a/web/src/pages/agent/canvas/node/dropdown/next-step-dropdown.tsx +++ b/web/src/pages/agent/canvas/node/dropdown/next-step-dropdown.tsx @@ -103,6 +103,7 @@ function AccordionOperators() { Operator.TavilyExtract, Operator.ExeSQL, Operator.Google, + Operator.YahooFinance, ]} > diff --git a/web/src/pages/agent/constant.tsx b/web/src/pages/agent/constant.tsx index 5f66f735f..c555bf34d 100644 --- a/web/src/pages/agent/constant.tsx +++ b/web/src/pages/agent/constant.tsx @@ -464,13 +464,19 @@ export const initialWenCaiValues = { export const initialAkShareValues = { top_n: 10, ...initialQueryBaseValues }; export const initialYahooFinanceValues = { + stock_code: '', info: true, history: false, financials: false, balance_sheet: false, cash_flow_statement: false, news: true, - ...initialQueryBaseValues, + outputs: { + report: { + value: '', + type: 'string', + }, + }, }; export const initialJin10Values = { diff --git a/web/src/pages/agent/form/tool-form/constant.tsx b/web/src/pages/agent/form/tool-form/constant.tsx index 419e8abb8..1a6b8de87 100644 --- a/web/src/pages/agent/form/tool-form/constant.tsx +++ b/web/src/pages/agent/form/tool-form/constant.tsx @@ -8,12 +8,12 @@ import GithubForm from '../github-form'; import GoogleScholarForm from '../google-scholar-form'; import PubMedForm from '../pubmed-form'; import WikipediaForm from '../wikipedia-form'; -import YahooFinanceForm from '../yahoo-finance-form'; import BingForm from './bing-form'; import CrawlerForm from './crawler-form'; import ExeSQLForm from './exesql-form'; import RetrievalForm from './retrieval-form'; import TavilyForm from './tavily-form'; +import YahooFinanceForm from './yahoo-finance-form'; export const ToolFormConfigMap = { [Operator.Retrieval]: RetrievalForm, diff --git a/web/src/pages/agent/form/tool-form/yahoo-finance-form/index.tsx b/web/src/pages/agent/form/tool-form/yahoo-finance-form/index.tsx new file mode 100644 index 000000000..af8f21cbd --- /dev/null +++ b/web/src/pages/agent/form/tool-form/yahoo-finance-form/index.tsx @@ -0,0 +1,40 @@ +import { FormContainer } from '@/components/form-container'; +import { Form } from '@/components/ui/form'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { memo } from 'react'; +import { useForm } from 'react-hook-form'; +import { z } from 'zod'; +import { FormWrapper } from '../../components/form-wrapper'; +import { + YahooFinanceFormPartialSchema, + YahooFinanceFormWidgets, +} from '../../yahoo-finance-form'; +import { useValues } from '../use-values'; +import { useWatchFormChange } from '../use-watch-change'; + +const FormSchema = z.object({ + ...YahooFinanceFormPartialSchema, +}); + +function YahooFinanceForm() { + const values = useValues(); + + const form = useForm>({ + defaultValues: values, + resolver: zodResolver(FormSchema), + }); + + useWatchFormChange(form); + + return ( +
+ + + + + +
+ ); +} + +export default memo(YahooFinanceForm); diff --git a/web/src/pages/agent/form/yahoo-finance-form/index.tsx b/web/src/pages/agent/form/yahoo-finance-form/index.tsx index ce7a3e7d2..de8a02a2a 100644 --- a/web/src/pages/agent/form/yahoo-finance-form/index.tsx +++ b/web/src/pages/agent/form/yahoo-finance-form/index.tsx @@ -1,38 +1,127 @@ +import { FormContainer } from '@/components/form-container'; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from '@/components/ui/form'; +import { Input } from '@/components/ui/input'; +import { Switch } from '@/components/ui/switch'; import { useTranslate } from '@/hooks/common-hooks'; -import { Form, Switch } from 'antd'; -import { IOperatorForm } from '../../interface'; -import DynamicInputVariable from '../components/dynamic-input-variable'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { ReactNode } from 'react'; +import { useForm, useFormContext } from 'react-hook-form'; +import { z } from 'zod'; +import { initialYahooFinanceValues } from '../../constant'; +import { useFormValues } from '../../hooks/use-form-values'; +import { INextOperatorForm } from '../../interface'; +import { buildOutputList } from '../../utils/build-output-list'; +import { FormWrapper } from '../components/form-wrapper'; +import { Output } from '../components/output'; -const YahooFinanceForm = ({ onValuesChange, form, node }: IOperatorForm) => { - const { t } = useTranslate('flow'); +export const YahooFinanceFormPartialSchema = { + info: z.boolean(), + history: z.boolean(), + financials: z.boolean(), + balance_sheet: z.boolean(), + cash_flow_statement: z.boolean(), + news: z.boolean(), +}; + +const FormSchema = z.object({ + stock_code: z.string(), + ...YahooFinanceFormPartialSchema, +}); + +interface SwitchFormFieldProps { + name: string; + label: ReactNode; +} +function SwitchFormField({ name, label }: SwitchFormFieldProps) { + const form = useFormContext(); return ( -
- - - - - - - - - - - - - - - - - - - + ( + + {label} + + + + + + )} + /> + ); +} + +export function YahooFinanceFormWidgets() { + const { t } = useTranslate('flow'); + return ( + <> + + + + + + + + + + ); +} + +const outputList = buildOutputList(initialYahooFinanceValues.outputs); + +const YahooFinanceForm = ({ node }: INextOperatorForm) => { + const { t } = useTranslate('flow'); + + const defaultValues = useFormValues(initialYahooFinanceValues, node); + + const form = useForm>({ + defaultValues, + resolver: zodResolver(FormSchema), + }); + + return ( + + + + ( + + {t('stockCode')} + + + + + + )} + /> + + + +
+ +
); }; diff --git a/web/src/pages/agent/hooks/use-agent-tool-initial-values.ts b/web/src/pages/agent/hooks/use-agent-tool-initial-values.ts index fd0de1c42..311c18d16 100644 --- a/web/src/pages/agent/hooks/use-agent-tool-initial-values.ts +++ b/web/src/pages/agent/hooks/use-agent-tool-initial-values.ts @@ -24,6 +24,8 @@ export function useAgentToolInitialValues() { return omit(initialValues, 'sql'); case Operator.Bing: return omit(initialValues, 'query'); + case Operator.YahooFinance: + return omit(initialValues, 'stock_code'); default: return initialValues;