@aiscene/core 9.0.1 → 9.0.3

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.
Files changed (55) hide show
  1. package/dist/es/agent/agent.mjs +51 -1
  2. package/dist/es/agent/agent.mjs.map +1 -1
  3. package/dist/es/agent/tasks.mjs +8 -6
  4. package/dist/es/agent/tasks.mjs.map +1 -1
  5. package/dist/es/agent/utils.mjs +1 -1
  6. package/dist/es/ai-model/auto-glm/planning.mjs +2 -1
  7. package/dist/es/ai-model/auto-glm/planning.mjs.map +1 -1
  8. package/dist/es/ai-model/conversation-history.mjs +4 -0
  9. package/dist/es/ai-model/conversation-history.mjs.map +1 -1
  10. package/dist/es/ai-model/inspect.mjs +4 -3
  11. package/dist/es/ai-model/inspect.mjs.map +1 -1
  12. package/dist/es/ai-model/prompt/util.mjs +18 -1
  13. package/dist/es/ai-model/prompt/util.mjs.map +1 -1
  14. package/dist/es/ai-model/ui-tars-planning.mjs +6 -2
  15. package/dist/es/ai-model/ui-tars-planning.mjs.map +1 -1
  16. package/dist/es/index.mjs +2 -2
  17. package/dist/es/index.mjs.map +1 -1
  18. package/dist/es/service/index.mjs +21 -1
  19. package/dist/es/service/index.mjs.map +1 -1
  20. package/dist/es/types.mjs +1 -20
  21. package/dist/es/types.mjs.map +1 -1
  22. package/dist/es/utils.mjs +2 -2
  23. package/dist/lib/agent/agent.js +51 -1
  24. package/dist/lib/agent/agent.js.map +1 -1
  25. package/dist/lib/agent/tasks.js +7 -5
  26. package/dist/lib/agent/tasks.js.map +1 -1
  27. package/dist/lib/agent/utils.js +1 -1
  28. package/dist/lib/ai-model/auto-glm/planning.js +2 -1
  29. package/dist/lib/ai-model/auto-glm/planning.js.map +1 -1
  30. package/dist/lib/ai-model/conversation-history.js +4 -0
  31. package/dist/lib/ai-model/conversation-history.js.map +1 -1
  32. package/dist/lib/ai-model/inspect.js +4 -3
  33. package/dist/lib/ai-model/inspect.js.map +1 -1
  34. package/dist/lib/ai-model/prompt/util.js +26 -0
  35. package/dist/lib/ai-model/prompt/util.js.map +1 -1
  36. package/dist/lib/ai-model/ui-tars-planning.js +6 -2
  37. package/dist/lib/ai-model/ui-tars-planning.js.map +1 -1
  38. package/dist/lib/index.js +1 -7
  39. package/dist/lib/index.js.map +1 -1
  40. package/dist/lib/service/index.js +21 -1
  41. package/dist/lib/service/index.js.map +1 -1
  42. package/dist/lib/types.js +8 -35
  43. package/dist/lib/types.js.map +1 -1
  44. package/dist/lib/utils.js +2 -2
  45. package/dist/types/agent/agent.d.ts +12 -1
  46. package/dist/types/agent/index.d.ts +1 -1
  47. package/dist/types/agent/tasks.d.ts +2 -0
  48. package/dist/types/ai-model/conversation-history.d.ts +2 -1
  49. package/dist/types/ai-model/inspect.d.ts +3 -0
  50. package/dist/types/ai-model/prompt/util.d.ts +4 -1
  51. package/dist/types/index.d.ts +1 -1
  52. package/dist/types/service/index.d.ts +3 -0
  53. package/dist/types/types.d.ts +21 -35
  54. package/dist/types/yaml.d.ts +3 -1
  55. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import type { TUserPrompt } from '../ai-model/index';
2
2
  import Service from '../service/index';
3
- import { type ActionParam, type ActionReturn, type AgentAssertOpt, type AgentDescribeElementAtPointResult, type AgentOpt, type AgentWaitForOpt, type DeepThinkOption, type DeviceAction, ExecutionDump, type LocateOption, type LocateResultElement, type LocateValidatorResult, type LocatorValidatorOption, type OnTaskStartTip, ReportActionDump, type ScrollParam, type ServiceAction, type ServiceExtractOption, type ServiceExtractParam, type UIContext } from '../types';
3
+ import { type ActionParam, type ActionReturn, type AIMemory, type AgentAssertOpt, type AgentDescribeElementAtPointResult, type AgentOpt, type AgentWaitForOpt, type DeepThinkOption, type DeviceAction, ExecutionDump, type LocateOption, type LocateResultElement, type LocateValidatorResult, type LocatorValidatorOption, type OnTaskStartTip, ReportActionDump, type ScrollParam, type ServiceAction, type ServiceExtractOption, type ServiceExtractParam, type UIContext } from '../types';
4
4
  import type { AbstractInterface } from '../device';
5
5
  import type { TaskRunner } from '../task-runner';
6
6
  import { ModelConfigManager } from '@aiscene/shared/env';
@@ -37,6 +37,8 @@ export declare class Agent<InterfaceType extends AbstractInterface = AbstractInt
37
37
  */
38
38
  private frozenUIContext?;
39
39
  private get aiActContext();
40
+ private aiMemory;
41
+ resolveAIMemory(): Promise<string[]>;
40
42
  /**
41
43
  * Flag to track if VL model warning has been shown
42
44
  */
@@ -67,6 +69,15 @@ export declare class Agent<InterfaceType extends AbstractInterface = AbstractInt
67
69
  */
68
70
  setAIActionContext(prompt: string): Promise<void>;
69
71
  setAIActContext(prompt: string): Promise<void>;
72
+ setAIMemory(memory?: AIMemory): void;
73
+ setMemory(memory?: AIMemory): void;
74
+ appendAIMemory(memory?: AIMemory): void;
75
+ appendMemory(memory?: AIMemory): void;
76
+ addAIMemory(memory?: AIMemory): void;
77
+ getAIMemory(): string[];
78
+ getMemory(): string[];
79
+ clearAIMemory(): void;
80
+ clearMemory(): void;
70
81
  resetDump(): ReportActionDump;
71
82
  appendExecutionDump(execution: ExecutionDump, runner?: TaskRunner): void;
72
83
  dumpDataString(opt?: {
@@ -5,5 +5,5 @@ export { extractInsightParam, locateParamStr, paramStr, taskTitleStr, typeStr, }
5
5
  export { type LocateCache, type PlanningCache, TaskCache } from './task-cache';
6
6
  export { cacheFileExt } from './task-cache';
7
7
  export { TaskExecutor } from './tasks';
8
- export type { AgentOpt } from '../types';
8
+ export type { AIMemory, AIMemoryRetriever, AgentOpt } from '../types';
9
9
  export type { AiActOptions } from './agent';
@@ -27,6 +27,7 @@ export declare class TaskExecutor {
27
27
  replanningCycleLimit?: number;
28
28
  waitAfterAction?: number;
29
29
  useDeviceTime?: boolean;
30
+ private readonly memoryRetrieverFn?;
30
31
  get page(): AbstractInterface;
31
32
  constructor(interfaceInstance: AbstractInterface, service: Service, opts: {
32
33
  taskCache?: TaskCache;
@@ -34,6 +35,7 @@ export declare class TaskExecutor {
34
35
  replanningCycleLimit?: number;
35
36
  waitAfterAction?: number;
36
37
  useDeviceTime?: boolean;
38
+ memoryRetrieverFn?: () => readonly string[] | Promise<readonly string[]>;
37
39
  hooks?: TaskExecutorHooks;
38
40
  actionSpace: DeviceAction[];
39
41
  });
@@ -1,7 +1,8 @@
1
- import type { SubGoal } from '../types';
1
+ import type { AIMemory, SubGoal } from '../types';
2
2
  import type { ChatCompletionMessageParam } from 'openai/resources/index';
3
3
  export interface ConversationHistoryOptions {
4
4
  initialMessages?: ChatCompletionMessageParam[];
5
+ initialMemories?: AIMemory;
5
6
  }
6
7
  export declare class ConversationHistory {
7
8
  private readonly messages;
@@ -22,6 +22,7 @@ export declare function AiLocateElement(options: {
22
22
  targetElementDescription: TUserPrompt;
23
23
  searchConfig?: Awaited<ReturnType<typeof AiLocateSection>>;
24
24
  modelConfig: IModelConfig;
25
+ memories?: readonly string[];
25
26
  abortSignal?: AbortSignal;
26
27
  }): Promise<{
27
28
  parseResult: {
@@ -37,6 +38,7 @@ export declare function AiLocateSection(options: {
37
38
  context: UIContext;
38
39
  sectionDescription: TUserPrompt;
39
40
  modelConfig: IModelConfig;
41
+ memories?: readonly string[];
40
42
  abortSignal?: AbortSignal;
41
43
  }): Promise<{
42
44
  rect?: Rect;
@@ -53,6 +55,7 @@ export declare function AiExtractElementInfo<T>(options: {
53
55
  pageDescription?: string;
54
56
  extractOption?: ServiceExtractOption;
55
57
  modelConfig: IModelConfig;
58
+ memories?: readonly string[];
56
59
  }): Promise<{
57
60
  parseResult: AIDataExtractionResponse<T>;
58
61
  rawResponse: string;
@@ -1,4 +1,4 @@
1
- import type { SubGoal } from '../../types';
1
+ import type { AIMemory, SubGoal } from '../../types';
2
2
  /**
3
3
  * Extract content from an XML tag in a string, searching from the end.
4
4
  * This approach handles cases where models prepend thinking content (like <think>...</think>)
@@ -23,6 +23,9 @@ export declare function parseSubGoalsFromXML(xmlContent: string): SubGoal[];
23
23
  * Extract indexes of sub-goals marked as finished from <mark-sub-goal-done> content
24
24
  */
25
25
  export declare function parseMarkFinishedIndexes(xmlContent: string): number[];
26
+ export declare function normalizeAIMemory(memory?: AIMemory): string[];
27
+ export declare function formatAIMemories(memories?: readonly string[]): string;
28
+ export declare function appendAIMemoryToText(text: string, memories?: readonly string[]): string;
26
29
  export declare const distanceThreshold = 16;
27
30
  export declare function distance(point1: {
28
31
  x: number;
@@ -5,7 +5,7 @@ import { getVersion } from './utils';
5
5
  export { plan, AiLocateElement, runConnectivityTest, getMidsceneLocationSchema, PointSchema, SizeSchema, RectSchema, TMultimodalPromptSchema, TUserPromptSchema, type TMultimodalPrompt, type TUserPrompt, type ConnectivityCheckResultItem, type ConnectivityTestConfig, type ConnectivityTestResult, } from './ai-model/index';
6
6
  export { MIDSCENE_MODEL_NAME, type CreateOpenAIClientFn, } from '@aiscene/shared/env';
7
7
  export type * from './types';
8
- export { ServiceError, ActionAssertionError, isActionAssertionError, ExecutionDump, ReportActionDump, GroupedActionDump, type IExecutionDump, type IReportActionDump, type IGroupedActionDump, type ReportMeta, type GroupMeta, } from './types';
8
+ export { ServiceError, ExecutionDump, ReportActionDump, GroupedActionDump, type IExecutionDump, type IReportActionDump, type IGroupedActionDump, type ReportMeta, type GroupMeta, } from './types';
9
9
  export { z };
10
10
  export default Service;
11
11
  export { TaskRunner, Service, getVersion };
@@ -10,11 +10,14 @@ export type AnyValue<T> = {
10
10
  };
11
11
  interface ServiceOptions {
12
12
  taskInfo?: Omit<ServiceTaskInfo, 'durationMs'>;
13
+ memoryRetrieverFn?: () => readonly string[] | Promise<readonly string[]>;
13
14
  }
14
15
  export default class Service {
15
16
  contextRetrieverFn: () => Promise<UIContext> | UIContext;
16
17
  taskInfo?: Omit<ServiceTaskInfo, 'durationMs'>;
18
+ private memoryRetrieverFn?;
17
19
  constructor(context: UIContext | (() => Promise<UIContext> | UIContext), opt?: ServiceOptions);
20
+ private getAIMemory;
18
21
  locate(query: PlanningLocateParam, opt: LocateOpts, modelConfig: IModelConfig, abortSignal?: AbortSignal): Promise<LocateResultWithDump>;
19
22
  extract<T>(dataDemand: ServiceExtractParam, modelConfig: IModelConfig, opt?: ServiceExtractOption, pageDescription?: string, multimodalPrompt?: TMultimodalPrompt, context?: UIContext): Promise<ServiceExtractResult<T>>;
20
23
  describe(target: Rect | [number, number], modelConfig: IModelConfig, opt?: {
@@ -163,41 +163,6 @@ export declare class ServiceError extends Error {
163
163
  dump: ServiceDump;
164
164
  constructor(message: string, dump: ServiceDump);
165
165
  }
166
- /**
167
- * Thrown by a DeviceAction whose semantics are "assert / verify".
168
- *
169
- * The task executor in [`tasks.ts`](packages/core/src/agent/tasks.ts) treats
170
- * regular action errors as soft failures and asks the planner to retry — that
171
- * is the right behavior for transient issues like a missed tap, but it is the
172
- * wrong behavior for actions like `ExpectToast` whose entire purpose is to
173
- * guarantee a postcondition. When an `ActionAssertionError` bubbles out of
174
- * `action.call()`, the executor MUST stop the current `aiAct` run and surface
175
- * the error to the caller without re-planning.
176
- *
177
- * Use this class (or a subclass) instead of a plain `Error` from any action
178
- * whose contract is verification rather than mutation.
179
- */
180
- export declare class ActionAssertionError extends Error {
181
- /** Name of the action that raised the assertion (e.g. "ExpectToast"). */
182
- readonly actionName?: string;
183
- /**
184
- * Optional structured detail — surfaced to the test report so users can see
185
- * what was expected vs. observed without parsing the message string.
186
- */
187
- readonly detail?: Record<string, unknown>;
188
- constructor(message: string, options?: {
189
- actionName?: string;
190
- detail?: Record<string, unknown>;
191
- });
192
- }
193
- /**
194
- * Type guard usable across packages without instanceof issues.
195
- *
196
- * Walks the `.cause` chain (depth-limited) so that wrappers like
197
- * `TaskExecutionError` — which the task runner uses to re-throw the failure of
198
- * an individual action — still report as assertion errors.
199
- */
200
- export declare function isActionAssertionError(err: unknown): err is ActionAssertionError;
201
166
  export interface LiteUISection {
202
167
  name: string;
203
168
  description: string;
@@ -212,6 +177,8 @@ export type ServiceAssertionResponse = AIAssertionResponse & {
212
177
  * agent
213
178
  */
214
179
  export type OnTaskStartTip = (tip: string) => Promise<void> | void;
180
+ export type AIMemory = string | readonly string[];
181
+ export type AIMemoryRetriever = () => AIMemory | Promise<AIMemory>;
215
182
  export interface AgentWaitForOpt extends ServiceExtractOption {
216
183
  checkIntervalMs?: number;
217
184
  timeoutMs?: number;
@@ -636,6 +603,25 @@ export interface AgentOpt {
636
603
  */
637
604
  outputFormat?: 'single-html' | 'html-and-external-assets';
638
605
  onTaskStartTip?: OnTaskStartTip;
606
+ /**
607
+ * User-provided memories that will be included in model calls.
608
+ * Use this for stable task knowledge such as account hints, domain rules,
609
+ * app-specific labels, or previous facts the model should consider.
610
+ */
611
+ aiMemory?: AIMemory;
612
+ /**
613
+ * Alias for aiMemory.
614
+ */
615
+ memory?: AIMemory;
616
+ /**
617
+ * Dynamically resolves memories before each model call. Useful for services
618
+ * that maintain memory outside the Agent, for example in a database or cache.
619
+ */
620
+ aiMemoryRetriever?: AIMemoryRetriever;
621
+ /**
622
+ * Alias for aiMemoryRetriever.
623
+ */
624
+ memoryRetriever?: AIMemoryRetriever;
639
625
  aiActContext?: string;
640
626
  aiActionContext?: string;
641
627
  reportFileName?: string;
@@ -62,12 +62,14 @@ export interface MidsceneYamlTask {
62
62
  * groupName: "E2E Test Suite"
63
63
  * generateReport: true
64
64
  * replanningCycleLimit: 30
65
+ * aiMemory:
66
+ * - "The Settings tab is represented by a gear icon."
65
67
  * cache:
66
68
  * id: "checkout-cache"
67
69
  * strategy: "read-write"
68
70
  * ```
69
71
  */
70
- export type MidsceneYamlScriptAgentOpt = Pick<AgentOpt, 'testId' | 'groupName' | 'groupDescription' | 'generateReport' | 'persistExecutionDump' | 'autoPrintReportMsg' | 'reportFileName' | 'replanningCycleLimit' | 'aiActContext' | 'aiActionContext' | 'cache' | 'screenshotShrinkFactor'>;
72
+ export type MidsceneYamlScriptAgentOpt = Pick<AgentOpt, 'testId' | 'groupName' | 'groupDescription' | 'generateReport' | 'persistExecutionDump' | 'autoPrintReportMsg' | 'reportFileName' | 'replanningCycleLimit' | 'aiMemory' | 'memory' | 'aiActContext' | 'aiActionContext' | 'cache' | 'screenshotShrinkFactor'>;
71
73
  export interface MidsceneYamlScriptConfig {
72
74
  output?: string;
73
75
  unstableLogContent?: boolean | string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aiscene/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": "9.0.1",
4
+ "version": "9.0.3",
5
5
  "repository": "https://github.com/web-infra-dev/midscene",
6
6
  "homepage": "https://midscenejs.com/",
7
7
  "main": "./dist/lib/index.js",