mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
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:
74
frontend/crawlab-ui/src/interfaces/models/autoprobe.d.ts
vendored
Normal file
74
frontend/crawlab-ui/src/interfaces/models/autoprobe.d.ts
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -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> {}
|
||||
14
frontend/crawlab-ui/src/interfaces/store/modules/autoprobe.d.ts
vendored
Normal file
14
frontend/crawlab-ui/src/interfaces/store/modules/autoprobe.d.ts
vendored
Normal 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> {}
|
||||
38
frontend/crawlab-ui/src/store/modules/autoprobe.ts
Normal file
38
frontend/crawlab-ui/src/store/modules/autoprobe.ts
Normal 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;
|
||||
@@ -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),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user