Skip to content

Commit 01fe97e

Browse files
quanruclaude
andcommitted
refactor(core): rename Insight class to Service
This is a comprehensive refactoring that renames the Insight class and all related types to Service for better semantic clarity. Changes: - Renamed directories: insight/ -> service/ - Renamed test files: insight.test.ts -> service.test.ts - Updated 50+ type definitions - Modified 18+ source files - Synchronized all test files - Updated external package dependencies Core updates: - Class: Insight -> Service - Interface: InsightOptions -> ServiceOptions - All InsightX types -> ServiceX types - String literal 'Insight' -> 'Service' Affected files: - src/index.ts, src/yaml.ts, src/task-runner.ts - src/agent/*.ts (agent, tasks, task-builder, ui-utils) - tests/utils.ts and all test files - External: chrome-extension, evaluation, report Verification: - TypeScript: 0 errors - Lint: 530 files passed - Build: successful (341.1 kB) 🤖 Generated with Claude Code Co-Authored-By: Claude <[email protected]>
1 parent 9894171 commit 01fe97e

File tree

20 files changed

+211
-206
lines changed

20 files changed

+211
-206
lines changed

apps/chrome-extension/src/utils/eventOptimizer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Insight from '@midscene/core';
1+
import Service from '@midscene/core';
22
import type { Rect, UIContext } from '@midscene/core';
33
import type { RecordedEvent } from '@midscene/recorder';
44
import { globalModelConfigManager } from '@midscene/shared/env';
@@ -110,7 +110,7 @@ export const generateAIDescription = async (
110110
size: { width: event.pageInfo.width, height: event.pageInfo.height },
111111
};
112112

113-
const insight = new Insight(mockContext);
113+
const service = new Service(mockContext);
114114
const rect =
115115
event.elementRect?.x && event.elementRect?.y
116116
? ([event.elementRect.x, event.elementRect.y] as [number, number])

apps/report/src/components/store/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import type { PlaywrightTaskAttributes } from '@/types';
33
import type {
44
ExecutionDump,
55
ExecutionTask,
6-
ExecutionTaskInsightLocate,
6+
ExecutionTaskServiceLocate,
77
GroupedActionDump,
8-
InsightDump,
8+
ServiceDump,
99
} from '@midscene/core';
1010
import type { AnimationScript } from '@midscene/visualizer';
1111
import {
@@ -55,7 +55,7 @@ export interface DumpStoreType {
5555
activeExecutionAnimation: AnimationScript[] | null;
5656
activeTask: ExecutionTask | null;
5757
setActiveTask: (task: ExecutionTask) => void;
58-
insightDump: InsightDump | null;
58+
insightDump: ServiceDump | null;
5959
_contextLoadId: number;
6060
hoverTask: ExecutionTask | null;
6161
hoverTimestamp: number | null;
@@ -203,8 +203,8 @@ export const useExecutionDump = create<DumpStoreType>((set, get) => {
203203
: null,
204204
});
205205
console.log('will set task', task);
206-
if (task.type === 'Insight') {
207-
const dump = (task as ExecutionTaskInsightLocate).log;
206+
if (task.type === 'Service') {
207+
const dump = (task as ExecutionTaskServiceLocate).log;
208208
set({
209209
insightDump: dump,
210210
});

packages/core/src/agent/agent.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import {
1010
type ExecutionTask,
1111
type ExecutionTaskLog,
1212
type GroupedActionDump,
13-
Insight,
14-
type InsightAction,
15-
type InsightExtractOption,
16-
type InsightExtractParam,
1713
type LocateOption,
1814
type LocateResultElement,
1915
type LocateValidatorResult,
@@ -23,6 +19,10 @@ import {
2319
type PlanningAction,
2420
type Rect,
2521
type ScrollParam,
22+
Service,
23+
type ServiceAction,
24+
type ServiceExtractOption,
25+
type ServiceExtractParam,
2626
type TUserPrompt,
2727
type TaskRunner,
2828
type UIContext,
@@ -82,7 +82,7 @@ const includedInRect = (point: [number, number], rect: Rect) => {
8282
return x >= left && x <= left + width && y >= top && y <= top + height;
8383
};
8484

85-
const defaultInsightExtractOption: InsightExtractOption = {
85+
const defaultServiceExtractOption: ServiceExtractOption = {
8686
domIncluded: false,
8787
screenshotIncluded: true,
8888
};
@@ -107,7 +107,7 @@ export class Agent<
107107
> {
108108
interface: InterfaceType;
109109

110-
insight: Insight;
110+
service: Service;
111111

112112
dump: GroupedActionDump;
113113

@@ -245,7 +245,7 @@ export class Agent<
245245

246246
this.onTaskStartTip = this.opts.onTaskStartTip;
247247

248-
this.insight = new Insight(async () => {
248+
this.service = new Service(async () => {
249249
return this.getUIContext();
250250
});
251251

@@ -263,7 +263,7 @@ export class Agent<
263263
);
264264
}
265265

266-
this.taskExecutor = new TaskExecutor(this.interface, this.insight, {
266+
this.taskExecutor = new TaskExecutor(this.interface, this.service, {
267267
taskCache: this.taskCache,
268268
onTaskStart: this.callbackOnTaskStartTip.bind(this),
269269
replanningCycleLimit: this.opts.replanningCycleLimit,
@@ -278,7 +278,7 @@ export class Agent<
278278
return this.interface.actionSpace();
279279
}
280280

281-
async getUIContext(action?: InsightAction): Promise<UIContext> {
281+
async getUIContext(action?: ServiceAction): Promise<UIContext> {
282282
// Check VL model configuration when UI context is first needed
283283
this.ensureVLModelWarning();
284284

@@ -765,8 +765,8 @@ export class Agent<
765765
}
766766

767767
async aiQuery<ReturnType = any>(
768-
demand: InsightExtractParam,
769-
opt: InsightExtractOption = defaultInsightExtractOption,
768+
demand: ServiceExtractParam,
769+
opt: ServiceExtractOption = defaultServiceExtractOption,
770770
): Promise<ReturnType> {
771771
const modelConfig = this.modelConfigManager.getModelConfig('VQA');
772772
const { output, runner } = await this.taskExecutor.createTypeQueryExecution(
@@ -781,7 +781,7 @@ export class Agent<
781781

782782
async aiBoolean(
783783
prompt: TUserPrompt,
784-
opt: InsightExtractOption = defaultInsightExtractOption,
784+
opt: ServiceExtractOption = defaultServiceExtractOption,
785785
): Promise<boolean> {
786786
const modelConfig = this.modelConfigManager.getModelConfig('VQA');
787787

@@ -799,7 +799,7 @@ export class Agent<
799799

800800
async aiNumber(
801801
prompt: TUserPrompt,
802-
opt: InsightExtractOption = defaultInsightExtractOption,
802+
opt: ServiceExtractOption = defaultServiceExtractOption,
803803
): Promise<number> {
804804
const modelConfig = this.modelConfigManager.getModelConfig('VQA');
805805

@@ -817,7 +817,7 @@ export class Agent<
817817

818818
async aiString(
819819
prompt: TUserPrompt,
820-
opt: InsightExtractOption = defaultInsightExtractOption,
820+
opt: ServiceExtractOption = defaultServiceExtractOption,
821821
): Promise<string> {
822822
const modelConfig = this.modelConfigManager.getModelConfig('VQA');
823823

@@ -835,7 +835,7 @@ export class Agent<
835835

836836
async aiAsk(
837837
prompt: TUserPrompt,
838-
opt: InsightExtractOption = defaultInsightExtractOption,
838+
opt: ServiceExtractOption = defaultServiceExtractOption,
839839
): Promise<string> {
840840
return this.aiString(prompt, opt);
841841
}
@@ -873,7 +873,7 @@ export class Agent<
873873
// use same intent as aiLocate
874874
const modelConfig = this.modelConfigManager.getModelConfig('grounding');
875875

876-
const text = await this.insight.describe(center, modelConfig, {
876+
const text = await this.service.describe(center, modelConfig, {
877877
deepThink,
878878
});
879879
debug('aiDescribe text', text);
@@ -961,15 +961,15 @@ export class Agent<
961961
async aiAssert(
962962
assertion: TUserPrompt,
963963
msg?: string,
964-
opt?: AgentAssertOpt & InsightExtractOption,
964+
opt?: AgentAssertOpt & ServiceExtractOption,
965965
) {
966966
const modelConfig = this.modelConfigManager.getModelConfig('VQA');
967967

968-
const insightOpt: InsightExtractOption = {
969-
domIncluded: opt?.domIncluded ?? defaultInsightExtractOption.domIncluded,
968+
const serviceOpt: ServiceExtractOption = {
969+
domIncluded: opt?.domIncluded ?? defaultServiceExtractOption.domIncluded,
970970
screenshotIncluded:
971971
opt?.screenshotIncluded ??
972-
defaultInsightExtractOption.screenshotIncluded,
972+
defaultServiceExtractOption.screenshotIncluded,
973973
doNotThrowError: opt?.doNotThrowError,
974974
};
975975

@@ -980,7 +980,7 @@ export class Agent<
980980
'Assert',
981981
textPrompt,
982982
modelConfig,
983-
insightOpt,
983+
serviceOpt,
984984
multimodalPrompt,
985985
);
986986
await this.afterTaskRunning(runner, true);

packages/core/src/agent/task-builder.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import { findAllMidsceneLocatorField, parseActionParam } from '@/ai-model';
22
import type { AbstractInterface } from '@/device';
3-
import type Insight from '@/insight';
3+
import type Service from '@/service';
44
import type {
55
DetailedLocateParam,
66
ElementCacheFeature,
77
ExecutionTaskActionApply,
88
ExecutionTaskApply,
99
ExecutionTaskHitBy,
10-
ExecutionTaskInsightLocateApply,
11-
InsightDump,
10+
ExecutionTaskServiceLocateApply,
1211
LocateResultElement,
1312
LocateResultWithDump,
1413
PlanningAction,
1514
PlanningActionParamSleep,
1615
PlanningLocateParam,
1716
Rect,
17+
ServiceDump,
1818
} from '@/types';
19-
import { InsightError } from '@/types';
19+
import { ServiceError } from '@/types';
2020
import { sleep } from '@/utils';
2121
import type { IModelConfig } from '@midscene/shared/env';
2222
import { generateElementByPosition } from '@midscene/shared/extractor';
@@ -40,7 +40,7 @@ export function locatePlanForLocate(param: string | DetailedLocateParam) {
4040

4141
interface TaskBuilderDeps {
4242
interfaceInstance: AbstractInterface;
43-
insight: Insight;
43+
service: Service;
4444
taskCache?: TaskCache;
4545
}
4646

@@ -59,13 +59,13 @@ interface PlanBuildContext {
5959
export class TaskBuilder {
6060
private readonly interface: AbstractInterface;
6161

62-
private readonly insight: Insight;
62+
private readonly service: Service;
6363

6464
private readonly taskCache?: TaskCache;
6565

66-
constructor({ interfaceInstance, insight, taskCache }: TaskBuilderDeps) {
66+
constructor({ interfaceInstance, service, taskCache }: TaskBuilderDeps) {
6767
this.interface = interfaceInstance;
68-
this.insight = insight;
68+
this.service = service;
6969
this.taskCache = taskCache;
7070
}
7171

@@ -324,7 +324,7 @@ export class TaskBuilder {
324324
detailedLocateParam: DetailedLocateParam | string,
325325
context: PlanBuildContext,
326326
onResult?: (result: LocateResultElement) => void,
327-
): ExecutionTaskInsightLocateApply {
327+
): ExecutionTaskServiceLocateApply {
328328
const { cacheable, modelConfig } = context;
329329
let locateParam = detailedLocateParam;
330330

@@ -341,8 +341,8 @@ export class TaskBuilder {
341341
};
342342
}
343343

344-
const taskFind: ExecutionTaskInsightLocateApply = {
345-
type: 'Insight',
344+
const taskFind: ExecutionTaskServiceLocateApply = {
345+
type: 'Service',
346346
subType: 'Locate',
347347
subTask: context.subTask || undefined,
348348
param: locateParam,
@@ -359,15 +359,15 @@ export class TaskBuilder {
359359
);
360360

361361
if (!uiContext) {
362-
uiContext = await this.insight.contextRetrieverFn();
362+
uiContext = await this.service.contextRetrieverFn();
363363
}
364364

365-
assert(uiContext, 'uiContext is required for Insight task');
365+
assert(uiContext, 'uiContext is required for Service task');
366366

367-
let locateDump: InsightDump | undefined;
367+
let locateDump: ServiceDump | undefined;
368368
let locateResult: LocateResultWithDump | undefined;
369369

370-
const applyDump = (dump?: InsightDump) => {
370+
const applyDump = (dump?: ServiceDump) => {
371371
if (!dump) {
372372
return;
373373
}
@@ -422,7 +422,7 @@ export class TaskBuilder {
422422
let elementFromAiLocate: LocateResultElement | null | undefined;
423423
if (!userExpectedPathHitFlag && !cacheHitFlag && !planHitFlag) {
424424
try {
425-
locateResult = await this.insight.locate(
425+
locateResult = await this.service.locate(
426426
param,
427427
{
428428
context: uiContext,
@@ -432,7 +432,7 @@ export class TaskBuilder {
432432
applyDump(locateResult.dump);
433433
elementFromAiLocate = locateResult.element;
434434
} catch (error) {
435-
if (error instanceof InsightError) {
435+
if (error instanceof ServiceError) {
436436
applyDump(error.dump);
437437
}
438438
throw error;
@@ -491,7 +491,7 @@ export class TaskBuilder {
491491

492492
if (!element) {
493493
if (locateDump) {
494-
throw new InsightError(
494+
throw new ServiceError(
495495
`Element not found : ${param.prompt}`,
496496
locateDump,
497497
);

0 commit comments

Comments
 (0)