import { SPI } from '@oinone/kunlun-spi'; import { ActionType } from '@oinone/kunlun-meta'; import type { DslDefinition } from '@oinone/kunlun-dsl'; import { type RuntimeServerAction, SubmitValue } from '@oinone/kunlun-engine'; import { Widget, type WidgetSubjection } from '@oinone/kunlun-vue-widget'; import { ActionWidget } from '../../component'; import { ServerActionWidget } from '../ServerActionWidget'; import type { ClickResult } from '../../../typing'; import { REFRESH_FORM_DATA } from '../../../basic/constant/state-stream'; import { executeAiTandemMutation } from './server'; import { findTandemActionHostViewName } from '../../../util'; @SPI.ClassFactory(ActionWidget.Token({ actionType: ActionType.Server, widget: ['AiTandemAction'] })) export class AiTandemActionWidget extends ServerActionWidget { @Widget.SubContext(REFRESH_FORM_DATA) protected reloadFormData$!: WidgetSubjection; @Widget.Reactive() protected get updateData(): boolean { return true; } @Widget.Reactive() protected get refreshData(): boolean { return false; } protected async executeAction(action: RuntimeServerAction, submitValue: SubmitValue): Promise { const activeRecord = this.activeRecords?.[0] ?? {}; const viewName = findTandemActionHostViewName({ rootRuntimeContext: this.rootRuntimeContext, metadataRuntimeContext: this.metadataRuntimeContext, isDialog: this.isDialog, isDrawer: this.isDrawer }); const { connectorCode = '' } = this.getDsl(); const rst = await executeAiTandemMutation( { connectorCode, viewName, actionName: action.name, data: activeRecord }, action.sessionPath ); if (rst.result) { let t = setTimeout(() => { this.reloadFormData$.subject.next(true); clearTimeout(t); t = null as any; }, 100); return rst.result || {}; } return null; } }