@midscene/core 0.30.6-beta-20251022093704.0 → 1.0.1-beta-20251022061922.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/agent/agent.mjs +41 -33
- package/dist/es/agent/agent.mjs.map +1 -1
- package/dist/es/agent/execution-session.mjs +41 -0
- package/dist/es/agent/execution-session.mjs.map +1 -0
- package/dist/es/agent/task-builder.mjs +315 -0
- package/dist/es/agent/task-builder.mjs.map +1 -0
- package/dist/es/agent/tasks.mjs +80 -405
- package/dist/es/agent/tasks.mjs.map +1 -1
- package/dist/es/agent/ui-utils.mjs.map +1 -1
- package/dist/es/agent/utils.mjs +6 -6
- package/dist/es/agent/utils.mjs.map +1 -1
- package/dist/es/ai-model/common.mjs +1 -15
- package/dist/es/ai-model/common.mjs.map +1 -1
- package/dist/es/ai-model/inspect.mjs +2 -3
- package/dist/es/ai-model/inspect.mjs.map +1 -1
- package/dist/es/ai-model/llm-planning.mjs +11 -30
- package/dist/es/ai-model/llm-planning.mjs.map +1 -1
- package/dist/es/ai-model/prompt/llm-locator.mjs +3 -204
- package/dist/es/ai-model/prompt/llm-locator.mjs.map +1 -1
- package/dist/es/ai-model/service-caller/index.mjs +101 -231
- package/dist/es/ai-model/service-caller/index.mjs.map +1 -1
- package/dist/es/index.mjs +3 -2
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/insight/index.mjs +18 -19
- package/dist/es/insight/index.mjs.map +1 -1
- package/dist/es/insight/utils.mjs +3 -3
- package/dist/es/insight/utils.mjs.map +1 -1
- package/dist/es/report.mjs.map +1 -1
- package/dist/es/{ai-model/action-executor.mjs → task-runner.mjs} +81 -10
- package/dist/es/task-runner.mjs.map +1 -0
- package/dist/es/types.mjs +18 -1
- package/dist/es/types.mjs.map +1 -1
- package/dist/es/utils.mjs +2 -2
- package/dist/es/yaml/player.mjs +18 -14
- package/dist/es/yaml/player.mjs.map +1 -1
- package/dist/lib/agent/agent.js +41 -33
- package/dist/lib/agent/agent.js.map +1 -1
- package/dist/lib/agent/execution-session.js +75 -0
- package/dist/lib/agent/execution-session.js.map +1 -0
- package/dist/lib/agent/task-builder.js +352 -0
- package/dist/lib/agent/task-builder.js.map +1 -0
- package/dist/lib/agent/tasks.js +80 -405
- package/dist/lib/agent/tasks.js.map +1 -1
- package/dist/lib/agent/ui-utils.js.map +1 -1
- package/dist/lib/agent/utils.js +6 -6
- package/dist/lib/agent/utils.js.map +1 -1
- package/dist/lib/ai-model/common.js +2 -19
- package/dist/lib/ai-model/common.js.map +1 -1
- package/dist/lib/ai-model/inspect.js +1 -2
- package/dist/lib/ai-model/inspect.js.map +1 -1
- package/dist/lib/ai-model/llm-planning.js +10 -29
- package/dist/lib/ai-model/llm-planning.js.map +1 -1
- package/dist/lib/ai-model/prompt/llm-locator.js +2 -206
- package/dist/lib/ai-model/prompt/llm-locator.js.map +1 -1
- package/dist/lib/ai-model/service-caller/index.js +236 -384
- package/dist/lib/ai-model/service-caller/index.js.map +1 -1
- package/dist/lib/index.js +9 -5
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/insight/index.js +17 -18
- package/dist/lib/insight/index.js.map +1 -1
- package/dist/lib/insight/utils.js +5 -5
- package/dist/lib/insight/utils.js.map +1 -1
- package/dist/lib/report.js.map +1 -1
- package/dist/lib/{ai-model/action-executor.js → task-runner.js} +83 -12
- package/dist/lib/task-runner.js.map +1 -0
- package/dist/lib/types.js +22 -1
- package/dist/lib/types.js.map +1 -1
- package/dist/lib/utils.js +2 -2
- package/dist/lib/yaml/player.js +18 -14
- package/dist/lib/yaml/player.js.map +1 -1
- package/dist/types/agent/agent.d.ts +16 -0
- package/dist/types/agent/execution-session.d.ts +27 -0
- package/dist/types/agent/task-builder.d.ts +34 -0
- package/dist/types/agent/tasks.d.ts +14 -13
- package/dist/types/agent/ui-utils.d.ts +2 -2
- package/dist/types/agent/utils.d.ts +6 -2
- package/dist/types/ai-model/common.d.ts +0 -1
- package/dist/types/ai-model/prompt/llm-locator.d.ts +0 -2
- package/dist/types/device/index.d.ts +20 -20
- package/dist/types/index.d.ts +4 -3
- package/dist/types/insight/index.d.ts +5 -10
- package/dist/types/insight/utils.d.ts +2 -2
- package/dist/types/task-runner.d.ts +31 -0
- package/dist/types/types.d.ts +53 -14
- package/dist/types/yaml.d.ts +3 -1
- package/package.json +4 -7
- package/dist/es/ai-model/action-executor.mjs.map +0 -1
- package/dist/lib/ai-model/action-executor.js.map +0 -1
- package/dist/types/ai-model/action-executor.d.ts +0 -19
|
@@ -145,8 +145,8 @@ export declare const actionTapParamSchema: z.ZodObject<{
|
|
|
145
145
|
}[] | undefined;
|
|
146
146
|
convertHttpImage2Base64?: boolean | undefined;
|
|
147
147
|
});
|
|
148
|
-
cacheable?: boolean | undefined;
|
|
149
148
|
deepThink?: boolean | undefined;
|
|
149
|
+
cacheable?: boolean | undefined;
|
|
150
150
|
xpath?: string | boolean | undefined;
|
|
151
151
|
} & {
|
|
152
152
|
[k: string]: unknown;
|
|
@@ -162,8 +162,8 @@ export declare const actionTapParamSchema: z.ZodObject<{
|
|
|
162
162
|
}[] | undefined;
|
|
163
163
|
convertHttpImage2Base64?: boolean | undefined;
|
|
164
164
|
});
|
|
165
|
-
cacheable?: boolean | undefined;
|
|
166
165
|
deepThink?: boolean | undefined;
|
|
166
|
+
cacheable?: boolean | undefined;
|
|
167
167
|
xpath?: string | boolean | undefined;
|
|
168
168
|
} & {
|
|
169
169
|
[k: string]: unknown;
|
|
@@ -291,8 +291,8 @@ export declare const actionRightClickParamSchema: z.ZodObject<{
|
|
|
291
291
|
}[] | undefined;
|
|
292
292
|
convertHttpImage2Base64?: boolean | undefined;
|
|
293
293
|
});
|
|
294
|
-
cacheable?: boolean | undefined;
|
|
295
294
|
deepThink?: boolean | undefined;
|
|
295
|
+
cacheable?: boolean | undefined;
|
|
296
296
|
xpath?: string | boolean | undefined;
|
|
297
297
|
} & {
|
|
298
298
|
[k: string]: unknown;
|
|
@@ -308,8 +308,8 @@ export declare const actionRightClickParamSchema: z.ZodObject<{
|
|
|
308
308
|
}[] | undefined;
|
|
309
309
|
convertHttpImage2Base64?: boolean | undefined;
|
|
310
310
|
});
|
|
311
|
-
cacheable?: boolean | undefined;
|
|
312
311
|
deepThink?: boolean | undefined;
|
|
312
|
+
cacheable?: boolean | undefined;
|
|
313
313
|
xpath?: string | boolean | undefined;
|
|
314
314
|
} & {
|
|
315
315
|
[k: string]: unknown;
|
|
@@ -437,8 +437,8 @@ export declare const actionDoubleClickParamSchema: z.ZodObject<{
|
|
|
437
437
|
}[] | undefined;
|
|
438
438
|
convertHttpImage2Base64?: boolean | undefined;
|
|
439
439
|
});
|
|
440
|
-
cacheable?: boolean | undefined;
|
|
441
440
|
deepThink?: boolean | undefined;
|
|
441
|
+
cacheable?: boolean | undefined;
|
|
442
442
|
xpath?: string | boolean | undefined;
|
|
443
443
|
} & {
|
|
444
444
|
[k: string]: unknown;
|
|
@@ -454,8 +454,8 @@ export declare const actionDoubleClickParamSchema: z.ZodObject<{
|
|
|
454
454
|
}[] | undefined;
|
|
455
455
|
convertHttpImage2Base64?: boolean | undefined;
|
|
456
456
|
});
|
|
457
|
-
cacheable?: boolean | undefined;
|
|
458
457
|
deepThink?: boolean | undefined;
|
|
458
|
+
cacheable?: boolean | undefined;
|
|
459
459
|
xpath?: string | boolean | undefined;
|
|
460
460
|
} & {
|
|
461
461
|
[k: string]: unknown;
|
|
@@ -583,8 +583,8 @@ export declare const actionHoverParamSchema: z.ZodObject<{
|
|
|
583
583
|
}[] | undefined;
|
|
584
584
|
convertHttpImage2Base64?: boolean | undefined;
|
|
585
585
|
});
|
|
586
|
-
cacheable?: boolean | undefined;
|
|
587
586
|
deepThink?: boolean | undefined;
|
|
587
|
+
cacheable?: boolean | undefined;
|
|
588
588
|
xpath?: string | boolean | undefined;
|
|
589
589
|
} & {
|
|
590
590
|
[k: string]: unknown;
|
|
@@ -600,8 +600,8 @@ export declare const actionHoverParamSchema: z.ZodObject<{
|
|
|
600
600
|
}[] | undefined;
|
|
601
601
|
convertHttpImage2Base64?: boolean | undefined;
|
|
602
602
|
});
|
|
603
|
-
cacheable?: boolean | undefined;
|
|
604
603
|
deepThink?: boolean | undefined;
|
|
604
|
+
cacheable?: boolean | undefined;
|
|
605
605
|
xpath?: string | boolean | undefined;
|
|
606
606
|
} & {
|
|
607
607
|
[k: string]: unknown;
|
|
@@ -1106,7 +1106,7 @@ export declare const actionScrollParamSchema: z.ZodObject<{
|
|
|
1106
1106
|
xpath: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodBoolean]>>;
|
|
1107
1107
|
}, z.ZodTypeAny, "passthrough">>>;
|
|
1108
1108
|
}, "strip", z.ZodTypeAny, {
|
|
1109
|
-
direction: "
|
|
1109
|
+
direction: "down" | "up" | "right" | "left";
|
|
1110
1110
|
scrollType: "once" | "untilBottom" | "untilTop" | "untilRight" | "untilLeft";
|
|
1111
1111
|
locate?: z.objectOutputType<{
|
|
1112
1112
|
prompt: z.ZodUnion<[z.ZodString, z.ZodIntersection<z.ZodObject<{
|
|
@@ -1182,7 +1182,7 @@ export declare const actionScrollParamSchema: z.ZodObject<{
|
|
|
1182
1182
|
cacheable: z.ZodOptional<z.ZodBoolean>;
|
|
1183
1183
|
xpath: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodBoolean]>>;
|
|
1184
1184
|
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
1185
|
-
direction?: "
|
|
1185
|
+
direction?: "down" | "up" | "right" | "left" | undefined;
|
|
1186
1186
|
scrollType?: "once" | "untilBottom" | "untilTop" | "untilRight" | "untilLeft" | undefined;
|
|
1187
1187
|
distance?: number | null | undefined;
|
|
1188
1188
|
}>;
|
|
@@ -1417,8 +1417,8 @@ export declare const actionDragAndDropParamSchema: z.ZodObject<{
|
|
|
1417
1417
|
}[] | undefined;
|
|
1418
1418
|
convertHttpImage2Base64?: boolean | undefined;
|
|
1419
1419
|
});
|
|
1420
|
-
cacheable?: boolean | undefined;
|
|
1421
1420
|
deepThink?: boolean | undefined;
|
|
1421
|
+
cacheable?: boolean | undefined;
|
|
1422
1422
|
xpath?: string | boolean | undefined;
|
|
1423
1423
|
} & {
|
|
1424
1424
|
[k: string]: unknown;
|
|
@@ -1433,8 +1433,8 @@ export declare const actionDragAndDropParamSchema: z.ZodObject<{
|
|
|
1433
1433
|
}[] | undefined;
|
|
1434
1434
|
convertHttpImage2Base64?: boolean | undefined;
|
|
1435
1435
|
});
|
|
1436
|
-
cacheable?: boolean | undefined;
|
|
1437
1436
|
deepThink?: boolean | undefined;
|
|
1437
|
+
cacheable?: boolean | undefined;
|
|
1438
1438
|
xpath?: string | boolean | undefined;
|
|
1439
1439
|
} & {
|
|
1440
1440
|
[k: string]: unknown;
|
|
@@ -1450,8 +1450,8 @@ export declare const actionDragAndDropParamSchema: z.ZodObject<{
|
|
|
1450
1450
|
}[] | undefined;
|
|
1451
1451
|
convertHttpImage2Base64?: boolean | undefined;
|
|
1452
1452
|
});
|
|
1453
|
-
cacheable?: boolean | undefined;
|
|
1454
1453
|
deepThink?: boolean | undefined;
|
|
1454
|
+
cacheable?: boolean | undefined;
|
|
1455
1455
|
xpath?: string | boolean | undefined;
|
|
1456
1456
|
} & {
|
|
1457
1457
|
[k: string]: unknown;
|
|
@@ -1466,8 +1466,8 @@ export declare const actionDragAndDropParamSchema: z.ZodObject<{
|
|
|
1466
1466
|
}[] | undefined;
|
|
1467
1467
|
convertHttpImage2Base64?: boolean | undefined;
|
|
1468
1468
|
});
|
|
1469
|
-
cacheable?: boolean | undefined;
|
|
1470
1469
|
deepThink?: boolean | undefined;
|
|
1470
|
+
cacheable?: boolean | undefined;
|
|
1471
1471
|
xpath?: string | boolean | undefined;
|
|
1472
1472
|
} & {
|
|
1473
1473
|
[k: string]: unknown;
|
|
@@ -1597,8 +1597,8 @@ export declare const ActionLongPressParamSchema: z.ZodObject<{
|
|
|
1597
1597
|
}[] | undefined;
|
|
1598
1598
|
convertHttpImage2Base64?: boolean | undefined;
|
|
1599
1599
|
});
|
|
1600
|
-
cacheable?: boolean | undefined;
|
|
1601
1600
|
deepThink?: boolean | undefined;
|
|
1601
|
+
cacheable?: boolean | undefined;
|
|
1602
1602
|
xpath?: string | boolean | undefined;
|
|
1603
1603
|
} & {
|
|
1604
1604
|
[k: string]: unknown;
|
|
@@ -1615,8 +1615,8 @@ export declare const ActionLongPressParamSchema: z.ZodObject<{
|
|
|
1615
1615
|
}[] | undefined;
|
|
1616
1616
|
convertHttpImage2Base64?: boolean | undefined;
|
|
1617
1617
|
});
|
|
1618
|
-
cacheable?: boolean | undefined;
|
|
1619
1618
|
deepThink?: boolean | undefined;
|
|
1619
|
+
cacheable?: boolean | undefined;
|
|
1620
1620
|
xpath?: string | boolean | undefined;
|
|
1621
1621
|
} & {
|
|
1622
1622
|
[k: string]: unknown;
|
|
@@ -1848,7 +1848,7 @@ export declare const ActionSwipeParamSchema: z.ZodObject<{
|
|
|
1848
1848
|
}, "strip", z.ZodTypeAny, {
|
|
1849
1849
|
duration: number;
|
|
1850
1850
|
repeat?: number | undefined;
|
|
1851
|
-
direction?: "
|
|
1851
|
+
direction?: "down" | "up" | "right" | "left" | undefined;
|
|
1852
1852
|
distance?: number | undefined;
|
|
1853
1853
|
start?: z.objectOutputType<{
|
|
1854
1854
|
prompt: z.ZodUnion<[z.ZodString, z.ZodIntersection<z.ZodObject<{
|
|
@@ -1924,7 +1924,7 @@ export declare const ActionSwipeParamSchema: z.ZodObject<{
|
|
|
1924
1924
|
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
1925
1925
|
}, {
|
|
1926
1926
|
repeat?: number | undefined;
|
|
1927
|
-
direction?: "
|
|
1927
|
+
direction?: "down" | "up" | "right" | "left" | undefined;
|
|
1928
1928
|
distance?: number | undefined;
|
|
1929
1929
|
duration?: number | undefined;
|
|
1930
1930
|
start?: z.objectInputType<{
|
|
@@ -2127,8 +2127,8 @@ export declare const actionClearInputParamSchema: z.ZodObject<{
|
|
|
2127
2127
|
}[] | undefined;
|
|
2128
2128
|
convertHttpImage2Base64?: boolean | undefined;
|
|
2129
2129
|
});
|
|
2130
|
-
cacheable?: boolean | undefined;
|
|
2131
2130
|
deepThink?: boolean | undefined;
|
|
2131
|
+
cacheable?: boolean | undefined;
|
|
2132
2132
|
xpath?: string | boolean | undefined;
|
|
2133
2133
|
} & {
|
|
2134
2134
|
[k: string]: unknown;
|
|
@@ -2144,8 +2144,8 @@ export declare const actionClearInputParamSchema: z.ZodObject<{
|
|
|
2144
2144
|
}[] | undefined;
|
|
2145
2145
|
convertHttpImage2Base64?: boolean | undefined;
|
|
2146
2146
|
});
|
|
2147
|
-
cacheable?: boolean | undefined;
|
|
2148
2147
|
deepThink?: boolean | undefined;
|
|
2148
|
+
cacheable?: boolean | undefined;
|
|
2149
2149
|
xpath?: string | boolean | undefined;
|
|
2150
2150
|
} & {
|
|
2151
2151
|
[k: string]: unknown;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { Executor } from './ai-model/action-executor';
|
|
3
2
|
import Insight from './insight/index';
|
|
3
|
+
import { TaskRunner } from './task-runner';
|
|
4
4
|
import { getVersion } from './utils';
|
|
5
5
|
export { plan, describeUserPage, AiLocateElement, getMidsceneLocationSchema, type MidsceneLocationResultType, PointSchema, SizeSchema, RectSchema, TMultimodalPromptSchema, TUserPromptSchema, type TMultimodalPrompt, type TUserPrompt, } from './ai-model/index';
|
|
6
|
-
export { MIDSCENE_MODEL_NAME } from '@midscene/shared/env';
|
|
6
|
+
export { MIDSCENE_MODEL_NAME, type CreateOpenAIClientFn, } from '@midscene/shared/env';
|
|
7
7
|
export type * from './types';
|
|
8
|
+
export { InsightError } from './types';
|
|
8
9
|
export { z };
|
|
9
10
|
export default Insight;
|
|
10
|
-
export {
|
|
11
|
+
export { TaskRunner, Insight, getVersion };
|
|
11
12
|
export type { MidsceneYamlScript, MidsceneYamlTask, MidsceneYamlFlowItem, MidsceneYamlConfigResult, MidsceneYamlConfig, MidsceneYamlScriptWebEnv, MidsceneYamlScriptAndroidEnv, MidsceneYamlScriptIOSEnv, MidsceneYamlScriptEnv, LocateOption, DetailedLocateParam, } from './yaml';
|
|
12
13
|
export { Agent, type AgentOpt, createAgent } from './agent';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { callAIWithObjectResponse } from '../ai-model/index';
|
|
2
|
-
import type { AIDescribeElementResponse,
|
|
2
|
+
import type { AIDescribeElementResponse, BaseElement, DetailedLocateParam, InsightExtractOption, InsightExtractParam, InsightExtractResult, InsightTaskInfo, LocateResultWithDump, Rect, UIContext } from '../types';
|
|
3
3
|
import { type IModelConfig } from '@midscene/shared/env';
|
|
4
4
|
import type { TMultimodalPrompt } from '../ai-model/common';
|
|
5
5
|
export interface LocateOpts {
|
|
@@ -13,17 +13,12 @@ interface InsightOptions {
|
|
|
13
13
|
aiVendorFn?: typeof callAIWithObjectResponse;
|
|
14
14
|
}
|
|
15
15
|
export default class Insight<ElementType extends BaseElement = BaseElement, ContextType extends UIContext<ElementType> = UIContext<ElementType>> {
|
|
16
|
-
contextRetrieverFn: (
|
|
16
|
+
contextRetrieverFn: () => Promise<ContextType> | ContextType;
|
|
17
17
|
aiVendorFn: Exclude<InsightOptions['aiVendorFn'], undefined>;
|
|
18
|
-
onceDumpUpdatedFn?: DumpSubscriber;
|
|
19
18
|
taskInfo?: Omit<InsightTaskInfo, 'durationMs'>;
|
|
20
|
-
constructor(context: ContextType | ((
|
|
21
|
-
locate(query: DetailedLocateParam, opt: LocateOpts, modelConfig: IModelConfig): Promise<
|
|
22
|
-
extract<T>(dataDemand: InsightExtractParam, modelConfig: IModelConfig, opt?: InsightExtractOption, multimodalPrompt?: TMultimodalPrompt): Promise<
|
|
23
|
-
data: T;
|
|
24
|
-
thought?: string;
|
|
25
|
-
usage?: AIUsageInfo;
|
|
26
|
-
}>;
|
|
19
|
+
constructor(context: ContextType | (() => Promise<ContextType> | ContextType), opt?: InsightOptions);
|
|
20
|
+
locate(query: DetailedLocateParam, opt: LocateOpts, modelConfig: IModelConfig): Promise<LocateResultWithDump>;
|
|
21
|
+
extract<T>(dataDemand: InsightExtractParam, modelConfig: IModelConfig, opt?: InsightExtractOption, multimodalPrompt?: TMultimodalPrompt): Promise<InsightExtractResult<T>>;
|
|
27
22
|
describe(target: Rect | [number, number], modelConfig: IModelConfig, opt?: {
|
|
28
23
|
deepThink?: boolean;
|
|
29
24
|
}): Promise<Pick<AIDescribeElementResponse, 'description'>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function
|
|
1
|
+
import type { InsightDump, PartialInsightDumpFromSDK } from '../types';
|
|
2
|
+
export declare function createInsightDump(data: PartialInsightDumpFromSDK): InsightDump;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ExecutionDump, ExecutionTask, ExecutionTaskApply, ExecutionTaskProgressOptions, UIContext } from './types';
|
|
2
|
+
export declare class TaskRunner {
|
|
3
|
+
name: string;
|
|
4
|
+
tasks: ExecutionTask[];
|
|
5
|
+
status: 'init' | 'pending' | 'running' | 'completed' | 'error';
|
|
6
|
+
onTaskStart?: ExecutionTaskProgressOptions['onTaskStart'];
|
|
7
|
+
private readonly uiContextBuilder;
|
|
8
|
+
constructor(name: string, uiContextBuilder: () => Promise<UIContext>, options?: ExecutionTaskProgressOptions & {
|
|
9
|
+
tasks?: ExecutionTaskApply[];
|
|
10
|
+
});
|
|
11
|
+
private captureScreenshot;
|
|
12
|
+
private attachRecorderItem;
|
|
13
|
+
private markTaskAsPending;
|
|
14
|
+
private findPreviousNonSubTaskUIContext;
|
|
15
|
+
append(task: ExecutionTaskApply[] | ExecutionTaskApply): Promise<void>;
|
|
16
|
+
appendAndFlush(task: ExecutionTaskApply[] | ExecutionTaskApply): Promise<{
|
|
17
|
+
output: any;
|
|
18
|
+
thought?: string;
|
|
19
|
+
} | undefined>;
|
|
20
|
+
flush(): Promise<{
|
|
21
|
+
output: any;
|
|
22
|
+
thought?: string;
|
|
23
|
+
} | undefined>;
|
|
24
|
+
isInErrorState(): boolean;
|
|
25
|
+
latestErrorTask(): ExecutionTask | null;
|
|
26
|
+
dump(): ExecutionDump;
|
|
27
|
+
appendErrorPlan(errorMsg: string): Promise<{
|
|
28
|
+
output: undefined;
|
|
29
|
+
runner: TaskRunner;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NodeType } from '@midscene/shared/constants';
|
|
2
|
-
import type { TModelConfigFn } from '@midscene/shared/env';
|
|
2
|
+
import type { CreateOpenAIClientFn, TModelConfigFn } from '@midscene/shared/env';
|
|
3
3
|
import type { BaseElement, ElementTreeNode, Rect, Size } from '@midscene/shared/types';
|
|
4
4
|
import type { z } from 'zod';
|
|
5
5
|
import type { TUserPrompt } from './ai-model/common';
|
|
@@ -154,7 +154,19 @@ export interface InsightDump extends DumpMeta {
|
|
|
154
154
|
output?: any;
|
|
155
155
|
}
|
|
156
156
|
export type PartialInsightDumpFromSDK = Omit<InsightDump, 'logTime' | 'logId' | 'model_name'>;
|
|
157
|
-
export
|
|
157
|
+
export interface InsightResultBase {
|
|
158
|
+
dump: InsightDump;
|
|
159
|
+
}
|
|
160
|
+
export type LocateResultWithDump = LocateResult & InsightResultBase;
|
|
161
|
+
export interface InsightExtractResult<T> extends InsightResultBase {
|
|
162
|
+
data: T;
|
|
163
|
+
thought?: string;
|
|
164
|
+
usage?: AIUsageInfo;
|
|
165
|
+
}
|
|
166
|
+
export declare class InsightError extends Error {
|
|
167
|
+
dump: InsightDump;
|
|
168
|
+
constructor(message: string, dump: InsightDump);
|
|
169
|
+
}
|
|
158
170
|
export interface LiteUISection {
|
|
159
171
|
name: string;
|
|
160
172
|
description: string;
|
|
@@ -190,25 +202,20 @@ export interface PlanningAction<ParamType = any> {
|
|
|
190
202
|
param: ParamType;
|
|
191
203
|
locate?: PlanningLocateParam | null;
|
|
192
204
|
}
|
|
193
|
-
export interface
|
|
194
|
-
action
|
|
195
|
-
actions?: PlanningAction[];
|
|
205
|
+
export interface RawResponsePlanningAIResponse {
|
|
206
|
+
action: PlanningAction;
|
|
196
207
|
more_actions_needed_by_instruction: boolean;
|
|
197
208
|
log: string;
|
|
198
209
|
sleep?: number;
|
|
199
210
|
error?: string;
|
|
211
|
+
}
|
|
212
|
+
export interface PlanningAIResponse extends Omit<RawResponsePlanningAIResponse, 'action'> {
|
|
213
|
+
actions?: PlanningAction[];
|
|
200
214
|
usage?: AIUsageInfo;
|
|
201
215
|
rawResponse?: string;
|
|
202
216
|
yamlFlow?: MidsceneYamlFlowItem[];
|
|
203
217
|
yamlString?: string;
|
|
204
218
|
}
|
|
205
|
-
export type PlanningActionParamTap = null;
|
|
206
|
-
export type PlanningActionParamHover = null;
|
|
207
|
-
export type PlanningActionParamRightClick = null;
|
|
208
|
-
export interface PlanningActionParamInputOrKeyPress {
|
|
209
|
-
value: string;
|
|
210
|
-
autoDismissKeyboard?: boolean;
|
|
211
|
-
}
|
|
212
219
|
export interface PlanningActionParamSleep {
|
|
213
220
|
timeMs: number;
|
|
214
221
|
}
|
|
@@ -216,10 +223,10 @@ export interface PlanningActionParamError {
|
|
|
216
223
|
thought: string;
|
|
217
224
|
}
|
|
218
225
|
export type PlanningActionParamWaitFor = AgentWaitForOpt & {};
|
|
219
|
-
export interface
|
|
226
|
+
export interface LongPressParam {
|
|
220
227
|
duration?: number;
|
|
221
228
|
}
|
|
222
|
-
export interface
|
|
229
|
+
export interface PullParam {
|
|
223
230
|
direction: 'up' | 'down';
|
|
224
231
|
distance?: number;
|
|
225
232
|
duration?: number;
|
|
@@ -251,10 +258,12 @@ export type ExecutionTaskType = 'Planning' | 'Insight' | 'Action' | 'Assertion'
|
|
|
251
258
|
export interface ExecutorContext {
|
|
252
259
|
task: ExecutionTask;
|
|
253
260
|
element?: LocateResultElement | null;
|
|
261
|
+
uiContext?: UIContext;
|
|
254
262
|
}
|
|
255
263
|
export interface ExecutionTaskApply<Type extends ExecutionTaskType = any, TaskParam = any, TaskOutput = any, TaskLog = any> {
|
|
256
264
|
type: Type;
|
|
257
265
|
subType?: string;
|
|
266
|
+
subTask?: boolean;
|
|
258
267
|
param?: TaskParam;
|
|
259
268
|
thought?: string;
|
|
260
269
|
locate?: PlanningLocateParam | null;
|
|
@@ -398,6 +407,36 @@ export interface AgentOpt {
|
|
|
398
407
|
modelConfig?: TModelConfigFn;
|
|
399
408
|
cache?: Cache;
|
|
400
409
|
replanningCycleLimit?: number;
|
|
410
|
+
/**
|
|
411
|
+
* Custom OpenAI client factory function
|
|
412
|
+
*
|
|
413
|
+
* If provided, this function will be called to create OpenAI client instances
|
|
414
|
+
* for each AI call, allowing you to:
|
|
415
|
+
* - Wrap clients with observability tools (langsmith, langfuse)
|
|
416
|
+
* - Use custom OpenAI-compatible clients
|
|
417
|
+
* - Apply different configurations based on intent
|
|
418
|
+
*
|
|
419
|
+
* @param config - Resolved model configuration
|
|
420
|
+
* @returns OpenAI client instance (original or wrapped)
|
|
421
|
+
*
|
|
422
|
+
* @example
|
|
423
|
+
* ```typescript
|
|
424
|
+
* createOpenAIClient: (config) => {
|
|
425
|
+
* const openai = new OpenAI({
|
|
426
|
+
* apiKey: config.openaiApiKey,
|
|
427
|
+
* baseURL: config.openaiBaseURL,
|
|
428
|
+
* });
|
|
429
|
+
*
|
|
430
|
+
* // Wrap with langsmith for planning tasks
|
|
431
|
+
* if (config.intent === 'planning') {
|
|
432
|
+
* return wrapOpenAI(openai, { metadata: { task: 'planning' } });
|
|
433
|
+
* }
|
|
434
|
+
*
|
|
435
|
+
* return openai;
|
|
436
|
+
* }
|
|
437
|
+
* ```
|
|
438
|
+
*/
|
|
439
|
+
createOpenAIClient?: CreateOpenAIClientFn;
|
|
401
440
|
}
|
|
402
441
|
export type TestStatus = 'passed' | 'failed' | 'timedOut' | 'skipped' | 'interrupted';
|
|
403
442
|
export interface ReportFileWithAttributes {
|
package/dist/types/yaml.d.ts
CHANGED
|
@@ -80,8 +80,9 @@ export interface MidsceneYamlScriptIOSEnv extends MidsceneYamlScriptConfig {
|
|
|
80
80
|
}
|
|
81
81
|
export type MidsceneYamlScriptEnv = MidsceneYamlScriptWebEnv | MidsceneYamlScriptAndroidEnv | MidsceneYamlScriptIOSEnv;
|
|
82
82
|
export interface MidsceneYamlFlowItemAIAction {
|
|
83
|
-
ai?: string;
|
|
84
83
|
aiAction?: string;
|
|
84
|
+
ai?: string;
|
|
85
|
+
aiAct?: string;
|
|
85
86
|
aiActionProgressTips?: string[];
|
|
86
87
|
cacheable?: boolean;
|
|
87
88
|
}
|
|
@@ -127,6 +128,7 @@ export interface MidsceneYamlFlowItemSleep {
|
|
|
127
128
|
}
|
|
128
129
|
export interface MidsceneYamlFlowItemLogScreenshot {
|
|
129
130
|
logScreenshot?: string;
|
|
131
|
+
recordToReport?: string;
|
|
130
132
|
content?: string;
|
|
131
133
|
}
|
|
132
134
|
export type MidsceneYamlFlowItem = MidsceneYamlFlowItemAIAction | MidsceneYamlFlowItemAIAssert | MidsceneYamlFlowItemAIQuery | MidsceneYamlFlowItemAIWaitFor | MidsceneYamlFlowItemSleep | MidsceneYamlFlowItemLogScreenshot;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/core",
|
|
3
3
|
"description": "Automate browser actions, extract data, and perform assertions using AI. It offers JavaScript SDK, Chrome extension, and support for scripting in YAML. See https://midscenejs.com/ for details.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "1.0.1-beta-20251022061922.0",
|
|
5
5
|
"repository": "https://github.com/web-infra-dev/midscene",
|
|
6
6
|
"homepage": "https://midscenejs.com/",
|
|
7
7
|
"main": "./dist/lib/index.js",
|
|
@@ -79,21 +79,18 @@
|
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@anthropic-ai/sdk": "0.33.1",
|
|
83
|
-
"@azure/identity": "4.5.0",
|
|
84
82
|
"@langchain/core": "0.3.26",
|
|
85
83
|
"@ui-tars/action-parser": "1.2.3",
|
|
86
84
|
"dotenv": "^16.4.5",
|
|
87
85
|
"https-proxy-agent": "7.0.2",
|
|
88
86
|
"jsonrepair": "3.12.0",
|
|
89
|
-
"
|
|
90
|
-
"openai": "4.81.0",
|
|
87
|
+
"openai": "6.3.0",
|
|
91
88
|
"socks-proxy-agent": "8.0.4",
|
|
92
89
|
"zod": "3.24.3",
|
|
93
90
|
"semver": "7.5.2",
|
|
94
91
|
"js-yaml": "4.1.0",
|
|
95
|
-
"@midscene/recorder": "0.
|
|
96
|
-
"@midscene/shared": "0.
|
|
92
|
+
"@midscene/recorder": "1.0.1-beta-20251022061922.0",
|
|
93
|
+
"@midscene/shared": "1.0.1-beta-20251022061922.0"
|
|
97
94
|
},
|
|
98
95
|
"devDependencies": {
|
|
99
96
|
"@rslib/core": "^0.11.2",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ai-model/action-executor.mjs","sources":["webpack://@midscene/core/./src/ai-model/action-executor.ts"],"sourcesContent":["import type {\n ExecutionDump,\n ExecutionTask,\n ExecutionTaskApply,\n ExecutionTaskInsightLocateOutput,\n ExecutionTaskProgressOptions,\n ExecutionTaskReturn,\n ExecutorContext,\n} from '@/types';\nimport { assert } from '@midscene/shared/utils';\n\nexport class Executor {\n name: string;\n\n tasks: ExecutionTask[];\n\n // status of executor\n status: 'init' | 'pending' | 'running' | 'completed' | 'error';\n\n onTaskStart?: ExecutionTaskProgressOptions['onTaskStart'];\n\n constructor(\n name: string,\n options?: ExecutionTaskProgressOptions & {\n tasks?: ExecutionTaskApply[];\n },\n ) {\n this.status =\n options?.tasks && options.tasks.length > 0 ? 'pending' : 'init';\n this.name = name;\n this.tasks = (options?.tasks || []).map((item) =>\n this.markTaskAsPending(item),\n );\n this.onTaskStart = options?.onTaskStart;\n }\n\n private markTaskAsPending(task: ExecutionTaskApply): ExecutionTask {\n return {\n status: 'pending',\n ...task,\n };\n }\n\n async append(task: ExecutionTaskApply[] | ExecutionTaskApply): Promise<void> {\n assert(\n this.status !== 'error',\n `executor is in error state, cannot append task\\nerror=${this.latestErrorTask()?.error}\\n${this.latestErrorTask()?.errorStack}`,\n );\n if (Array.isArray(task)) {\n this.tasks.push(...task.map((item) => this.markTaskAsPending(item)));\n } else {\n this.tasks.push(this.markTaskAsPending(task));\n }\n if (this.status !== 'running') {\n this.status = 'pending';\n }\n }\n\n async flush(): Promise<{ output: any; thought?: string } | undefined> {\n if (this.status === 'init' && this.tasks.length > 0) {\n console.warn(\n 'illegal state for executor, status is init but tasks are not empty',\n );\n }\n\n assert(this.status !== 'running', 'executor is already running');\n assert(this.status !== 'completed', 'executor is already completed');\n assert(this.status !== 'error', 'executor is in error state');\n\n const nextPendingIndex = this.tasks.findIndex(\n (task) => task.status === 'pending',\n );\n if (nextPendingIndex < 0) {\n // all tasks are completed\n return;\n }\n\n this.status = 'running';\n let taskIndex = nextPendingIndex;\n let successfullyCompleted = true;\n\n let previousFindOutput: ExecutionTaskInsightLocateOutput | undefined;\n\n while (taskIndex < this.tasks.length) {\n const task = this.tasks[taskIndex];\n assert(\n task.status === 'pending',\n `task status should be pending, but got: ${task.status}`,\n );\n task.timing = {\n start: Date.now(),\n };\n try {\n task.status = 'running';\n try {\n if (this.onTaskStart) {\n await this.onTaskStart(task);\n }\n } catch (e) {\n console.error('error in onTaskStart', e);\n }\n assert(\n ['Insight', 'Action', 'Planning'].indexOf(task.type) >= 0,\n `unsupported task type: ${task.type}`,\n );\n\n const { executor, param } = task;\n assert(executor, `executor is required for task type: ${task.type}`);\n\n let returnValue;\n const executorContext: ExecutorContext = {\n task,\n element: previousFindOutput?.element,\n };\n\n if (task.type === 'Insight') {\n assert(\n task.subType === 'Locate' ||\n task.subType === 'Query' ||\n task.subType === 'Assert' ||\n task.subType === 'WaitFor' ||\n task.subType === 'Boolean' ||\n task.subType === 'Number' ||\n task.subType === 'String',\n `unsupported insight subType: ${task.subType}`,\n );\n returnValue = await task.executor(param, executorContext);\n if (task.subType === 'Locate') {\n previousFindOutput = (\n returnValue as ExecutionTaskReturn<ExecutionTaskInsightLocateOutput>\n )?.output;\n }\n } else if (task.type === 'Action' || task.type === 'Planning') {\n returnValue = await task.executor(param, executorContext);\n } else {\n console.warn(\n `unsupported task type: ${task.type}, will try to execute it directly`,\n );\n returnValue = await task.executor(param, executorContext);\n }\n\n Object.assign(task, returnValue);\n task.status = 'finished';\n task.timing.end = Date.now();\n task.timing.cost = task.timing.end - task.timing.start;\n taskIndex++;\n } catch (e: any) {\n successfullyCompleted = false;\n task.error = e;\n task.errorMessage =\n e?.message || (typeof e === 'string' ? e : 'error-without-message');\n task.errorStack = e.stack;\n\n task.status = 'failed';\n task.timing.end = Date.now();\n task.timing.cost = task.timing.end - task.timing.start;\n break;\n }\n }\n\n // set all remaining tasks as cancelled\n for (let i = taskIndex + 1; i < this.tasks.length; i++) {\n this.tasks[i].status = 'cancelled';\n }\n\n if (successfullyCompleted) {\n this.status = 'completed';\n } else {\n this.status = 'error';\n }\n\n if (this.tasks.length) {\n // return the last output\n const outputIndex = Math.min(taskIndex, this.tasks.length - 1);\n const { thought, output } = this.tasks[outputIndex];\n return {\n thought,\n output,\n };\n }\n }\n\n isInErrorState(): boolean {\n return this.status === 'error';\n }\n\n latestErrorTask(): ExecutionTask | null {\n if (this.status !== 'error') {\n return null;\n }\n const errorTaskIndex = this.tasks.findIndex(\n (task) => task.status === 'failed',\n );\n if (errorTaskIndex >= 0) {\n return this.tasks[errorTaskIndex];\n }\n return null;\n }\n\n dump(): ExecutionDump {\n const dumpData: ExecutionDump = {\n logTime: Date.now(),\n name: this.name,\n tasks: this.tasks,\n };\n return dumpData;\n }\n}\n"],"names":["Executor","task","_this_latestErrorTask","_this_latestErrorTask1","assert","Array","item","console","nextPendingIndex","taskIndex","successfullyCompleted","previousFindOutput","Date","e","executor","param","returnValue","executorContext","Object","i","outputIndex","Math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":["webpack://@midscene/core/webpack/runtime/define_property_getters","webpack://@midscene/core/webpack/runtime/has_own_property","webpack://@midscene/core/webpack/runtime/make_namespace_object","webpack://@midscene/core/./src/ai-model/action-executor.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import type {\n ExecutionDump,\n ExecutionTask,\n ExecutionTaskApply,\n ExecutionTaskInsightLocateOutput,\n ExecutionTaskProgressOptions,\n ExecutionTaskReturn,\n ExecutorContext,\n} from '@/types';\nimport { assert } from '@midscene/shared/utils';\n\nexport class Executor {\n name: string;\n\n tasks: ExecutionTask[];\n\n // status of executor\n status: 'init' | 'pending' | 'running' | 'completed' | 'error';\n\n onTaskStart?: ExecutionTaskProgressOptions['onTaskStart'];\n\n constructor(\n name: string,\n options?: ExecutionTaskProgressOptions & {\n tasks?: ExecutionTaskApply[];\n },\n ) {\n this.status =\n options?.tasks && options.tasks.length > 0 ? 'pending' : 'init';\n this.name = name;\n this.tasks = (options?.tasks || []).map((item) =>\n this.markTaskAsPending(item),\n );\n this.onTaskStart = options?.onTaskStart;\n }\n\n private markTaskAsPending(task: ExecutionTaskApply): ExecutionTask {\n return {\n status: 'pending',\n ...task,\n };\n }\n\n async append(task: ExecutionTaskApply[] | ExecutionTaskApply): Promise<void> {\n assert(\n this.status !== 'error',\n `executor is in error state, cannot append task\\nerror=${this.latestErrorTask()?.error}\\n${this.latestErrorTask()?.errorStack}`,\n );\n if (Array.isArray(task)) {\n this.tasks.push(...task.map((item) => this.markTaskAsPending(item)));\n } else {\n this.tasks.push(this.markTaskAsPending(task));\n }\n if (this.status !== 'running') {\n this.status = 'pending';\n }\n }\n\n async flush(): Promise<{ output: any; thought?: string } | undefined> {\n if (this.status === 'init' && this.tasks.length > 0) {\n console.warn(\n 'illegal state for executor, status is init but tasks are not empty',\n );\n }\n\n assert(this.status !== 'running', 'executor is already running');\n assert(this.status !== 'completed', 'executor is already completed');\n assert(this.status !== 'error', 'executor is in error state');\n\n const nextPendingIndex = this.tasks.findIndex(\n (task) => task.status === 'pending',\n );\n if (nextPendingIndex < 0) {\n // all tasks are completed\n return;\n }\n\n this.status = 'running';\n let taskIndex = nextPendingIndex;\n let successfullyCompleted = true;\n\n let previousFindOutput: ExecutionTaskInsightLocateOutput | undefined;\n\n while (taskIndex < this.tasks.length) {\n const task = this.tasks[taskIndex];\n assert(\n task.status === 'pending',\n `task status should be pending, but got: ${task.status}`,\n );\n task.timing = {\n start: Date.now(),\n };\n try {\n task.status = 'running';\n try {\n if (this.onTaskStart) {\n await this.onTaskStart(task);\n }\n } catch (e) {\n console.error('error in onTaskStart', e);\n }\n assert(\n ['Insight', 'Action', 'Planning'].indexOf(task.type) >= 0,\n `unsupported task type: ${task.type}`,\n );\n\n const { executor, param } = task;\n assert(executor, `executor is required for task type: ${task.type}`);\n\n let returnValue;\n const executorContext: ExecutorContext = {\n task,\n element: previousFindOutput?.element,\n };\n\n if (task.type === 'Insight') {\n assert(\n task.subType === 'Locate' ||\n task.subType === 'Query' ||\n task.subType === 'Assert' ||\n task.subType === 'WaitFor' ||\n task.subType === 'Boolean' ||\n task.subType === 'Number' ||\n task.subType === 'String',\n `unsupported insight subType: ${task.subType}`,\n );\n returnValue = await task.executor(param, executorContext);\n if (task.subType === 'Locate') {\n previousFindOutput = (\n returnValue as ExecutionTaskReturn<ExecutionTaskInsightLocateOutput>\n )?.output;\n }\n } else if (task.type === 'Action' || task.type === 'Planning') {\n returnValue = await task.executor(param, executorContext);\n } else {\n console.warn(\n `unsupported task type: ${task.type}, will try to execute it directly`,\n );\n returnValue = await task.executor(param, executorContext);\n }\n\n Object.assign(task, returnValue);\n task.status = 'finished';\n task.timing.end = Date.now();\n task.timing.cost = task.timing.end - task.timing.start;\n taskIndex++;\n } catch (e: any) {\n successfullyCompleted = false;\n task.error = e;\n task.errorMessage =\n e?.message || (typeof e === 'string' ? e : 'error-without-message');\n task.errorStack = e.stack;\n\n task.status = 'failed';\n task.timing.end = Date.now();\n task.timing.cost = task.timing.end - task.timing.start;\n break;\n }\n }\n\n // set all remaining tasks as cancelled\n for (let i = taskIndex + 1; i < this.tasks.length; i++) {\n this.tasks[i].status = 'cancelled';\n }\n\n if (successfullyCompleted) {\n this.status = 'completed';\n } else {\n this.status = 'error';\n }\n\n if (this.tasks.length) {\n // return the last output\n const outputIndex = Math.min(taskIndex, this.tasks.length - 1);\n const { thought, output } = this.tasks[outputIndex];\n return {\n thought,\n output,\n };\n }\n }\n\n isInErrorState(): boolean {\n return this.status === 'error';\n }\n\n latestErrorTask(): ExecutionTask | null {\n if (this.status !== 'error') {\n return null;\n }\n const errorTaskIndex = this.tasks.findIndex(\n (task) => task.status === 'failed',\n );\n if (errorTaskIndex >= 0) {\n return this.tasks[errorTaskIndex];\n }\n return null;\n }\n\n dump(): ExecutionDump {\n const dumpData: ExecutionDump = {\n logTime: Date.now(),\n name: this.name,\n tasks: this.tasks,\n };\n return dumpData;\n }\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","Executor","task","_this_latestErrorTask","_this_latestErrorTask1","assert","Array","item","console","nextPendingIndex","taskIndex","successfullyCompleted","previousFindOutput","Date","e","executor","param","returnValue","executorContext","i","outputIndex","Math","thought","output","errorTaskIndex","dumpData","name","options"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,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I,CAAC,IAAI;YACf,OAAO,IAAI,CAAC,KAAK;QACnB;QACA,OAAOY;IACT;IAzLA,YACEC,IAAY,EACZC,OAEC,CACD;QAdF;QAEA;QAGA;QAEA;QAQE,IAAI,CAAC,MAAM,GACTA,AAAAA,CAAAA,QAAAA,UAAAA,KAAAA,IAAAA,QAAS,KAAK,AAAD,KAAKA,QAAQ,KAAK,CAAC,MAAM,GAAG,IAAI,YAAY;QAC3D,IAAI,CAAC,IAAI,GAAGD;QACZ,IAAI,CAAC,KAAK,GAAIC,AAAAA,CAAAA,CAAAA,QAAAA,UAAAA,KAAAA,IAAAA,QAAS,KAAK,AAAD,KAAK,EAAC,EAAG,GAAG,CAAC,CAACpB,OACvC,IAAI,CAAC,iBAAiB,CAACA;QAEzB,IAAI,CAAC,WAAW,GAAGoB,QAAAA,UAAAA,KAAAA,IAAAA,QAAS,WAAW;IACzC;AA6KF"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { ExecutionDump, ExecutionTask, ExecutionTaskApply, ExecutionTaskProgressOptions } from '../types';
|
|
2
|
-
export declare class Executor {
|
|
3
|
-
name: string;
|
|
4
|
-
tasks: ExecutionTask[];
|
|
5
|
-
status: 'init' | 'pending' | 'running' | 'completed' | 'error';
|
|
6
|
-
onTaskStart?: ExecutionTaskProgressOptions['onTaskStart'];
|
|
7
|
-
constructor(name: string, options?: ExecutionTaskProgressOptions & {
|
|
8
|
-
tasks?: ExecutionTaskApply[];
|
|
9
|
-
});
|
|
10
|
-
private markTaskAsPending;
|
|
11
|
-
append(task: ExecutionTaskApply[] | ExecutionTaskApply): Promise<void>;
|
|
12
|
-
flush(): Promise<{
|
|
13
|
-
output: any;
|
|
14
|
-
thought?: string;
|
|
15
|
-
} | undefined>;
|
|
16
|
-
isInErrorState(): boolean;
|
|
17
|
-
latestErrorTask(): ExecutionTask | null;
|
|
18
|
-
dump(): ExecutionDump;
|
|
19
|
-
}
|