@coolkiller007/my-page-agent 0.1.14 → 0.2.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/index.d.ts CHANGED
@@ -42,6 +42,11 @@ declare interface AgentConfig extends LLMConfig {
42
42
  * @default 40
43
43
  */
44
44
  maxSteps?: number;
45
+ /**
46
+ * 拼装 LLM 提示词时,最近保留完整详情的历史步数;更早的步骤会被压缩成一行。
47
+ * @default 15
48
+ */
49
+ historyWindow?: number;
45
50
  /**
46
51
  * 用于扩展 PageAgent 能力的自定义工具
47
52
  * @experimental
@@ -231,6 +236,7 @@ declare class AgentRuntime extends EventTarget {
231
236
  /** 合并后的 Agent 配置(含最大步数上限) */
232
237
  readonly config: AgentRuntimeConfig & {
233
238
  maxSteps: number;
239
+ historyWindow: number;
234
240
  };
235
241
  /** 内部工具集合(按工具名索引) */
236
242
  readonly tools: typeof tools;
@@ -269,7 +275,7 @@ declare class AgentRuntime extends EventTarget {
269
275
  * 外部错误(前置检查/配置/钩子)会直接抛出;
270
276
  * Agent 内部错误会被捕获并加入历史,同时返回失败结果
271
277
  */
272
- execute(task: string): Promise<ExecutionResult>;
278
+ execute(task: string, attachments?: Attachment[]): Promise<ExecutionResult>;
273
279
  /** 销毁 Agent:中止任务、释放浏览器控制器,并触发 dispose 事件(一次性) */
274
280
  dispose(): void;
275
281
  }
@@ -317,6 +323,25 @@ declare interface AgentTool<TParams = any> {
317
323
  execute: (this: AgentRuntime, args: TParams, ctx: ToolContext) => Promise<string>;
318
324
  }
319
325
 
326
+ /**
327
+ * 用户随任务一起上传的附件(图片或文本类文件)
328
+ */
329
+ declare interface Attachment {
330
+ name: string;
331
+ mimeType: string;
332
+ dataUrl: string;
333
+ }
334
+
335
+ /**
336
+ * 用户随任务一起上传的附件(图片或文本类文件)
337
+ * @note 与 agent/types.ts 中的 Attachment 结构一致,但独立声明以保持 UI 与 Agent 解耦
338
+ */
339
+ declare interface Attachment_2 {
340
+ name: string;
341
+ mimeType: string;
342
+ dataUrl: string;
343
+ }
344
+
320
345
  /**
321
346
  * BrowserController 管理 DOM 状态和元素交互。
322
347
  * 它为所有 DOM 操作提供异步方法,并保持状态隔离。
@@ -558,7 +583,7 @@ declare function getSelectorMap(flatTree: FlatDomTree): Map<number, InteractiveE
558
583
  /**
559
584
  * 所有历史事件的联合类型
560
585
  */
561
- export declare type HistoricalEvent = AgentStepEvent | ObservationEvent | UserTakeoverEvent | RetryEvent | AgentErrorEvent;
586
+ export declare type HistoricalEvent = AgentStepEvent | ObservationEvent | UserTakeoverEvent | TaskStartEvent | RetryEvent | AgentErrorEvent;
562
587
 
563
588
  declare interface InteractiveElementDomNode {
564
589
  tagName: string;
@@ -628,6 +653,11 @@ declare const locales: {
628
653
  readonly expand: "Expand history";
629
654
  readonly collapse: "Collapse history";
630
655
  readonly step: "Step {{number}}";
656
+ readonly attachButtonTitle: "Attach files";
657
+ readonly attachTooMany: "You can attach up to {{max}} files";
658
+ readonly attachTooLarge: "\"{{name}}\" exceeds the {{maxMB}}MB size limit";
659
+ readonly attachUnsupportedType: "\"{{name}}\" is not a supported file type";
660
+ readonly attachmentsLabel: "📎 Attachments: {{names}}";
631
661
  readonly tools: {
632
662
  readonly clicking: "Clicking element [{{index}}]...";
633
663
  readonly inputting: "Inputting text to element [{{index}}]...";
@@ -672,6 +702,11 @@ declare const locales: {
672
702
  readonly expand: "展开历史";
673
703
  readonly collapse: "收起历史";
674
704
  readonly step: "步骤 {{number}}";
705
+ readonly attachButtonTitle: "添加附件";
706
+ readonly attachTooMany: "最多可添加 {{max}} 个文件";
707
+ readonly attachTooLarge: "\"{{name}}\" 超过 {{maxMB}}MB 大小限制";
708
+ readonly attachUnsupportedType: "\"{{name}}\" 不是支持的文件类型";
709
+ readonly attachmentsLabel: "📎 附件: {{names}}";
675
710
  readonly tools: {
676
711
  readonly clicking: "正在点击元素 [{{index}}]...";
677
712
  readonly inputting: "正在输入文本到元素 [{{index}}]...";
@@ -741,6 +776,17 @@ declare type SupportedLanguage = 'en-US' | 'zh-CN';
741
776
  /** 受支持的语言代码类型 */
742
777
  declare type SupportedLanguage_2 = keyof typeof locales;
743
778
 
779
+ /**
780
+ * 任务开始事件 - 标记一个新任务的起点
781
+ * @note history 数组跨任务持久保留(不再在每次 execute 时清空),
782
+ * 该事件用于在历史记录中分隔不同任务,UI 据此渲染各自的任务卡片。
783
+ */
784
+ declare interface TaskStartEvent {
785
+ type: 'task_start';
786
+ task: string;
787
+ attachmentNames?: string[];
788
+ }
789
+
744
790
  declare interface TextDomNode {
745
791
  type: 'TEXT_NODE';
746
792
  text: string;
@@ -839,7 +885,7 @@ declare interface UIAdapter extends EventTarget {
839
885
  } | null;
840
886
  /** agent 事件历史 */
841
887
  readonly history: readonly {
842
- type: 'step' | 'observation' | 'user_takeover' | 'retry' | 'error';
888
+ type: 'step' | 'observation' | 'user_takeover' | 'task_start' | 'retry' | 'error';
843
889
  stepIndex?: number;
844
890
  /** 仅用于 'step' 类型 */
845
891
  reflection?: {
@@ -855,6 +901,10 @@ declare interface UIAdapter extends EventTarget {
855
901
  };
856
902
  /** 仅用于 'observation' 类型 */
857
903
  content?: string;
904
+ /** 仅用于 'task_start' 类型 */
905
+ task?: string;
906
+ /** 仅用于 'task_start' 类型 */
907
+ attachmentNames?: string[];
858
908
  /** 仅用于 'retry' 类型 */
859
909
  attempt?: number;
860
910
  maxAttempts?: number;
@@ -872,8 +922,8 @@ declare interface UIAdapter extends EventTarget {
872
922
  onAskUser?: (question: string, options?: {
873
923
  signal: AbortSignal;
874
924
  }) => Promise<string>;
875
- /** 执行一个任务 */
876
- execute(task: string): Promise<unknown>;
925
+ /** 执行一个任务;attachments 为随任务一起上传的图片/文本附件(可选) */
926
+ execute(task: string, attachments?: Attachment_2[]): Promise<unknown>;
877
927
  /** 停止当前任务(agent 仍可复用) */
878
928
  stop(): Promise<void>;
879
929
  /** 销毁 agent(终态,不可复用) */