feat: introduce AutoProbe module and related interfaces

- Added AutoProbe interfaces to define models for autoprobe functionality, including AutoProbe, AutoProbeTask, and AutoProbeFetchResult.
- Created AutoProbeStore module for managing state, getters, mutations, and actions related to autoprobe.
- Updated existing LLM interfaces to utilize LLMResponseUsage for token tracking.
- Refactored store index to include autoprobe namespace and removed obsolete AiStore module.
This commit is contained in:
Marvin Zhang
2025-05-12 11:25:30 +08:00
parent a10a05ea80
commit ec5bcf9287
7 changed files with 141 additions and 29 deletions

View File

@@ -0,0 +1,74 @@
export declare global {
interface AutoProbe extends BaseModel {
name?: string;
url?: string;
query?: string;
}
type AutoProbeTaskStatus = 'pending' | 'running' | 'completed' | 'failed';
type SelectorType = 'css' | 'xpath' | 'regex';
type ExtractType = 'text' | 'attribute' | 'html';
type PaginationType = 'next' | 'load' | 'scroll';
interface FieldRule {
name: string;
selector_type: SelectorType;
selector: string;
extraction_type: ExtractType;
attribute_name?: string;
default_value?: string;
}
interface ItemPattern {
fields?: FieldRule[];
lists?: ListRule[];
}
interface ListRule {
name: string;
list_selector_type: SelectorType;
list_selector: string;
item_selector_type: SelectorType;
item_selector: string;
item_pattern: ItemPattern;
}
interface Pagination {
type: PaginationType;
selector_type?: SelectorType;
selector?: string;
max_pages?: number;
start_page?: number;
}
interface PagePattern {
name: string;
fields?: FieldRule[];
lists?: ListRule[];
pagination?: Pagination;
}
interface PageData {
data?: Record<string, any>;
list_data?: any[][];
}
interface AutoProbeTask extends BaseModel {
autoprobe_id: string;
url?: string;
query?: string;
status: AutoProbeTaskStatus;
page_pattern?: PagePattern;
page_data?: PageData;
provider_id?: string;
model?: string;
usage?: LLMResponseUsage;
}
interface AutoProbeFetchResult extends BaseModel {
autoprobe_id: string;
url: string;
html?: string;
}
}

View File

@@ -1,4 +1,10 @@
export declare global {
interface LLMResponseUsage {
prompt_tokens?: number;
completion_tokens?: number;
total_tokens?: number;
}
type LLMProviderType =
| 'openai'
| 'azure-openai'
@@ -48,7 +54,7 @@ export declare global {
metadata?: Record<string, any>;
status: ChatMessageStatus;
error?: string;
usage?: ChatMessageUsage;
usage?: LLMResponseUsage;
// Frontend UI-specific properties
timestamp?: Date;
@@ -68,18 +74,12 @@ export declare global {
action_target?: string;
action_status?: ChatMessageActionStatus;
hidden?: boolean;
usage?: ChatMessageUsage;
usage?: LLMResponseUsage;
// Frontend UI-specific properties
isStreaming?: boolean;
}
interface ChatMessageUsage {
prompt_tokens?: number;
completion_tokens?: number;
total_tokens?: number;
}
type ChatConversationStatus = 'active' | 'archived' | 'deleted';
interface ChatConversation extends BaseModel {
@@ -133,6 +133,6 @@ export declare global {
error?: string;
hidden?: boolean;
is_text_done?: boolean;
usage?: ChatMessageUsage;
usage?: LLMResponseUsage;
}
}

View File

@@ -29,15 +29,15 @@ export declare global {
database: DatabaseStoreState;
dependency: DependencyStoreState;
environment: EnvironmentStoreState;
ai: AiStoreState;
system: SystemStoreState;
autoprobe: AutoProbeStoreState;
}
type StoreGetter<S, T, R = RootStoreState> = (
state: S,
getters?: GetterTree<S, R>,
rootState?: R,
rootGetters?: any
rootGetters?: any,
) => T;
type StoreMutation<S, P> = (state: S, payload: P) => void;
@@ -45,7 +45,7 @@ export declare global {
type StoreActionHandler<S, P, T, R = RootStoreState> = (
this: Store<R>,
ctx: ActionContext<S, R>,
payload?: P
payload?: P,
) => T;
interface StoreActionObject<S, P, T> {
@@ -175,7 +175,7 @@ export declare global {
| 'dependency'
| 'environment'
| 'dataCollection'
| 'llmProvider';
| 'autoprobe';
type StoreNamespace = ListStoreNamespace | 'layout' | 'common';
interface StoreContext<T, R = RootStoreState> {

View File

@@ -1,14 +0,0 @@
type AiStoreModule = BaseModule<
AiStoreState,
AiStoreGetters,
AiStoreMutations,
AiStoreActions
>;
interface AiStoreState extends BaseStoreState<LLMProvider> {}
type AiStoreGetters = BaseStoreGetters<LLMProvider>;
interface AiStoreMutations extends BaseStoreMutations<LLMProvider> {}
interface AiStoreActions extends BaseStoreActions<LLMProvider> {}

View File

@@ -0,0 +1,14 @@
type AutoProbeStoreModule = BaseModule<
AutoProbeStoreState,
AutoProbeStoreGetters,
AutoProbeStoreMutations,
AutoProbeStoreActions
>;
interface AutoProbeStoreState extends BaseStoreState<AutoProbe> {}
type AutoProbeStoreGetters = BaseStoreGetters<AutoProbe>;
interface AutoProbeStoreMutations extends BaseStoreMutations<AutoProbe> {}
interface AutoProbeStoreActions extends BaseStoreActions<AutoProbe> {}

View File

@@ -0,0 +1,38 @@
import {
getDefaultStoreActions,
getDefaultStoreGetters,
getDefaultStoreMutations,
getDefaultStoreState,
} from '@/utils/store';
import { TAB_NAME_OVERVIEW } from '@/constants/tab';
import { translate } from '@/utils/i18n';
// i18n
const t = translate;
const state = {
...getDefaultStoreState<AutoProbe>('autoprobe'),
tabs: [
{ id: TAB_NAME_OVERVIEW, title: t('common.tabs.overview') },
],
} as AutoProbeStoreState;
const getters = {
...getDefaultStoreGetters<AutoProbe>(),
} as AutoProbeStoreGetters;
const mutations = {
...getDefaultStoreMutations<AutoProbe>(),
} as AutoProbeStoreMutations;
const actions = {
...getDefaultStoreActions<AutoProbe>('/projects'),
} as AutoProbeStoreActions;
export default {
namespaced: true,
state,
getters,
mutations,
actions,
} as AutoProbeStoreModule;

View File

@@ -2,11 +2,11 @@ import { useStore } from 'vuex';
import { useList } from '@/layouts';
const useAutoProbeList = () => {
const ns: ListStoreNamespace = 'extract';
const ns: ListStoreNamespace = 'autoprobe';
const store = useStore();
return {
...useList<ExtractPattern>(ns),
...useList<AutoProbe>(ns, store),
};
};