@oagi/oagi 0.1.3 → 0.1.5

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.cts CHANGED
@@ -1,5 +1,5 @@
1
+ import { CompletionUsage, ChatCompletionMessageParam } from 'openai/resources.js';
1
2
  import * as z from 'zod';
2
- import { ChatCompletionMessageParam, CompletionUsage } from 'openai/resources.js';
3
3
 
4
4
  /**
5
5
  * -----------------------------------------------------------------------------
@@ -44,6 +44,7 @@ interface Step {
44
44
  reason?: string;
45
45
  actions: Action[];
46
46
  stop: boolean;
47
+ usage?: CompletionUsage;
47
48
  }
48
49
 
49
50
  /**
@@ -356,7 +357,7 @@ declare class Actor {
356
357
  */
357
358
  private currentStep;
358
359
  private client;
359
- constructor(apiKey?: string, baseUrl?: string, model?: string, temperature?: number | undefined);
360
+ constructor(apiKey?: string, baseURL?: string, model?: string, temperature?: number | undefined);
360
361
  private validateAndIncrementStep;
361
362
  /**
362
363
  * Get screenshot URL, uploading to S3 if needed (async version).
@@ -425,32 +426,21 @@ declare class DefaultAgent implements Agent {
425
426
  * -----------------------------------------------------------------------------
426
427
  */
427
428
 
428
- interface Agent {
429
- /**
430
- * Protocol for synchronous task execution agents.
431
- */
432
- execute(instruction: string, action_handler: ActionHandler, image_provider: ImageProvider): Promise<boolean>;
429
+ interface ClientOptions {
430
+ baseURL?: string;
431
+ apiKey?: string;
432
+ maxRetries?: number;
433
433
  }
434
-
435
- /**
436
- * -----------------------------------------------------------------------------
437
- * Copyright (c) OpenAGI Foundation
438
- * All rights reserved.
439
- *
440
- * This file is part of the official API project.
441
- * Licensed under the MIT License.
442
- * -----------------------------------------------------------------------------
443
- */
444
-
445
434
  /**
446
435
  * HTTP client for the OAGI API.
447
436
  */
448
437
  declare class Client {
449
- private baseUrl;
450
- private apiKey;
438
+ private baseURL;
439
+ private apiKey?;
451
440
  private timeout;
452
441
  private client;
453
- constructor(baseUrl?: string, apiKey?: string | null, maxRetries?: number);
442
+ constructor(options: ClientOptions);
443
+ constructor(baseURL?: string, apiKey?: string, maxRetries?: number);
454
444
  private fetch;
455
445
  private buildHeaders;
456
446
  private handleResponseError;
@@ -508,6 +498,170 @@ declare class Client {
508
498
  callWorker({ workerId, overallTodo, taskDescription, todos, history, currentTodoIndex, taskExecutionSummary, currentScreenshot, currentSubtaskInstruction, windowSteps, windowScreenshots, resultScreenshot, priorNotes, latestTodoSummary, apiVersion, }: GenerateOption): Promise<GenerateResponse>;
509
499
  }
510
500
 
501
+ /**
502
+ * -----------------------------------------------------------------------------
503
+ * Copyright (c) OpenAGI Foundation
504
+ * All rights reserved.
505
+ *
506
+ * This file is part of the official API project.
507
+ * Licensed under the MIT License.
508
+ * -----------------------------------------------------------------------------
509
+ */
510
+
511
+ type ImageLike = ArrayBuffer | string;
512
+ type TodoStatus = Todo['status'] | 'skipped';
513
+ interface TodoItem {
514
+ description: string;
515
+ status: TodoStatus;
516
+ }
517
+ interface TaskerAction {
518
+ timestamp: string;
519
+ action_type: string;
520
+ target?: string | null;
521
+ details?: Record<string, unknown>;
522
+ reasoning?: string | null;
523
+ result?: string | null;
524
+ screenshot_uuid?: string | null;
525
+ }
526
+ interface TodoHistory {
527
+ todo_index: number;
528
+ todo: string;
529
+ actions: TaskerAction[];
530
+ summary?: string;
531
+ completed: boolean;
532
+ }
533
+ interface PlannerOutput {
534
+ instruction: string;
535
+ reasoning: string;
536
+ subtodos: string[];
537
+ }
538
+ interface ReflectionOutput {
539
+ continue_current: boolean;
540
+ new_instruction?: string | null;
541
+ reasoning: string;
542
+ success_assessment: boolean;
543
+ }
544
+ type PlannerContext = Record<string, unknown>;
545
+ declare class PlannerMemory {
546
+ taskDescription: string;
547
+ todos: TodoItem[];
548
+ history: TodoHistory[];
549
+ taskExecutionSummary: string;
550
+ todoExecutionSummaries: Record<number, string>;
551
+ setTask(taskDescription: string, todos: string[] | TodoItem[]): void;
552
+ getCurrentTodo(): {
553
+ todo: TodoItem;
554
+ index: number;
555
+ } | null;
556
+ updateTodo(index: number, status: TodoStatus, summary?: string): void;
557
+ addHistory(todoIndex: number, actions: TaskerAction[], summary?: string, completed?: boolean): void;
558
+ getContext(): PlannerContext;
559
+ getTodoStatusSummary(): Record<string, number>;
560
+ appendTodo(description: string): void;
561
+ }
562
+ declare class Planner {
563
+ private apiKey?;
564
+ private baseUrl?;
565
+ private client?;
566
+ private ownsClient;
567
+ constructor(client?: Client, apiKey?: string | undefined, baseUrl?: string | undefined);
568
+ private ensureClient;
569
+ getClient(): Client;
570
+ close(): Promise<void>;
571
+ private extractMemoryData;
572
+ private extractJsonString;
573
+ private parsePlannerOutput;
574
+ private parseReflectionOutput;
575
+ private formatExecutionNotes;
576
+ private ensureScreenshotUuid;
577
+ initialPlan(todo: string, context: PlannerContext, screenshot?: ImageLike, memory?: PlannerMemory, todoIndex?: number): Promise<{
578
+ output: PlannerOutput;
579
+ requestId?: string | null;
580
+ }>;
581
+ reflect(actions: TaskerAction[], context: PlannerContext, screenshot?: ImageLike, memory?: PlannerMemory, todoIndex?: number, currentInstruction?: string, reflectionInterval?: number): Promise<{
582
+ output: ReflectionOutput;
583
+ requestId?: string | null;
584
+ }>;
585
+ summarize(_executionHistory: TaskerAction[], context: PlannerContext, memory?: PlannerMemory, todoIndex?: number): Promise<{
586
+ summary: string;
587
+ requestId?: string | null;
588
+ }>;
589
+ }
590
+ declare class TaskerAgent implements Agent {
591
+ /** Hierarchical agent that manages multi-todo workflows. */
592
+ private apiKey?;
593
+ private baseUrl?;
594
+ private model;
595
+ private maxSteps;
596
+ private temperature?;
597
+ private reflectionInterval;
598
+ private planner;
599
+ private stepObserver?;
600
+ private stepDelay;
601
+ private memory;
602
+ private currentTaskeeAgent?;
603
+ constructor(apiKey?: string, baseUrl?: string, model?: string, maxSteps?: number, temperature?: number | undefined, reflectionInterval?: number, planner?: Planner, stepObserver?: StepObserver, stepDelay?: number);
604
+ setTask(task: string, todos: string[]): void;
605
+ set_task(task: string, todos: string[]): void;
606
+ execute(_instruction: string, actionHandler: ActionHandler, imageProvider: ImageProvider): Promise<boolean>;
607
+ private prepare;
608
+ private executeTodo;
609
+ private updateMemoryFromExecution;
610
+ private updateTaskSummary;
611
+ getMemory(): PlannerMemory;
612
+ appendTodo(description: string): void;
613
+ }
614
+
615
+ /**
616
+ * -----------------------------------------------------------------------------
617
+ * Copyright (c) OpenAGI Foundation
618
+ * All rights reserved.
619
+ *
620
+ * This file is part of the official API project.
621
+ * Licensed under the MIT License.
622
+ * -----------------------------------------------------------------------------
623
+ */
624
+
625
+ declare enum ExportFormat {
626
+ /** Supported export formats. */
627
+ MARKDOWN = "markdown",
628
+ HTML = "html",
629
+ JSON = "json"
630
+ }
631
+ declare class AsyncAgentObserver extends StepObserver {
632
+ /**
633
+ * Records agent execution events and exports to various formats.
634
+ *
635
+ * This class implements the AsyncObserver protocol and provides
636
+ * functionality for recording events during agent execution and
637
+ * exporting them to Markdown or HTML formats.
638
+ */
639
+ events: ObserverEvent[];
640
+ onEvent(event: ObserverEvent): Promise<void>;
641
+ addLog(message: string): void;
642
+ addSplit(label?: string): void;
643
+ clear(): void;
644
+ getEventsByStep(step_num: number): ObserverEvent[];
645
+ export(format: ExportFormat | string, path: string, images_dir?: string | null): void;
646
+ }
647
+
648
+ /**
649
+ * -----------------------------------------------------------------------------
650
+ * Copyright (c) OpenAGI Foundation
651
+ * All rights reserved.
652
+ *
653
+ * This file is part of the official API project.
654
+ * Licensed under the MIT License.
655
+ * -----------------------------------------------------------------------------
656
+ */
657
+
658
+ interface Agent {
659
+ /**
660
+ * Protocol for synchronous task execution agents.
661
+ */
662
+ execute(instruction: string, action_handler: ActionHandler, image_provider: ImageProvider): Promise<boolean>;
663
+ }
664
+
511
665
  /**
512
666
  * -----------------------------------------------------------------------------
513
667
  * Copyright (c) OpenAGI Foundation
@@ -564,4 +718,4 @@ declare class DefaultActionHandler implements ActionHandler {
564
718
  handle(actions: Action[]): Promise<void>;
565
719
  }
566
720
 
567
- export { APIError, Actor, type Agent, AuthenticationError, Client, ConfigurationError, DefaultActionHandler, DefaultAgent, type ErrorDetail, type ErrorResponse, type GenerateResponse, NetworkError, NotFoundError, OAGIError, RateLimitError, RequestTimeoutError, ScreenshotMaker, ServerError, type UploadFileResponse, ValidationError };
721
+ export { APIError, type Action, Actor, type Agent, AsyncAgentObserver, AuthenticationError, Client, type ClientOptions, ConfigurationError, DefaultActionHandler, DefaultAgent, type ErrorDetail, type ErrorResponse, ExportFormat, type GenerateResponse, NetworkError, NotFoundError, OAGIError, RateLimitError, RequestTimeoutError, ScreenshotMaker, ServerError, type Step, TaskerAgent, type UploadFileResponse, ValidationError };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
+ import { CompletionUsage, ChatCompletionMessageParam } from 'openai/resources.js';
1
2
  import * as z from 'zod';
2
- import { ChatCompletionMessageParam, CompletionUsage } from 'openai/resources.js';
3
3
 
4
4
  /**
5
5
  * -----------------------------------------------------------------------------
@@ -44,6 +44,7 @@ interface Step {
44
44
  reason?: string;
45
45
  actions: Action[];
46
46
  stop: boolean;
47
+ usage?: CompletionUsage;
47
48
  }
48
49
 
49
50
  /**
@@ -356,7 +357,7 @@ declare class Actor {
356
357
  */
357
358
  private currentStep;
358
359
  private client;
359
- constructor(apiKey?: string, baseUrl?: string, model?: string, temperature?: number | undefined);
360
+ constructor(apiKey?: string, baseURL?: string, model?: string, temperature?: number | undefined);
360
361
  private validateAndIncrementStep;
361
362
  /**
362
363
  * Get screenshot URL, uploading to S3 if needed (async version).
@@ -425,32 +426,21 @@ declare class DefaultAgent implements Agent {
425
426
  * -----------------------------------------------------------------------------
426
427
  */
427
428
 
428
- interface Agent {
429
- /**
430
- * Protocol for synchronous task execution agents.
431
- */
432
- execute(instruction: string, action_handler: ActionHandler, image_provider: ImageProvider): Promise<boolean>;
429
+ interface ClientOptions {
430
+ baseURL?: string;
431
+ apiKey?: string;
432
+ maxRetries?: number;
433
433
  }
434
-
435
- /**
436
- * -----------------------------------------------------------------------------
437
- * Copyright (c) OpenAGI Foundation
438
- * All rights reserved.
439
- *
440
- * This file is part of the official API project.
441
- * Licensed under the MIT License.
442
- * -----------------------------------------------------------------------------
443
- */
444
-
445
434
  /**
446
435
  * HTTP client for the OAGI API.
447
436
  */
448
437
  declare class Client {
449
- private baseUrl;
450
- private apiKey;
438
+ private baseURL;
439
+ private apiKey?;
451
440
  private timeout;
452
441
  private client;
453
- constructor(baseUrl?: string, apiKey?: string | null, maxRetries?: number);
442
+ constructor(options: ClientOptions);
443
+ constructor(baseURL?: string, apiKey?: string, maxRetries?: number);
454
444
  private fetch;
455
445
  private buildHeaders;
456
446
  private handleResponseError;
@@ -508,6 +498,170 @@ declare class Client {
508
498
  callWorker({ workerId, overallTodo, taskDescription, todos, history, currentTodoIndex, taskExecutionSummary, currentScreenshot, currentSubtaskInstruction, windowSteps, windowScreenshots, resultScreenshot, priorNotes, latestTodoSummary, apiVersion, }: GenerateOption): Promise<GenerateResponse>;
509
499
  }
510
500
 
501
+ /**
502
+ * -----------------------------------------------------------------------------
503
+ * Copyright (c) OpenAGI Foundation
504
+ * All rights reserved.
505
+ *
506
+ * This file is part of the official API project.
507
+ * Licensed under the MIT License.
508
+ * -----------------------------------------------------------------------------
509
+ */
510
+
511
+ type ImageLike = ArrayBuffer | string;
512
+ type TodoStatus = Todo['status'] | 'skipped';
513
+ interface TodoItem {
514
+ description: string;
515
+ status: TodoStatus;
516
+ }
517
+ interface TaskerAction {
518
+ timestamp: string;
519
+ action_type: string;
520
+ target?: string | null;
521
+ details?: Record<string, unknown>;
522
+ reasoning?: string | null;
523
+ result?: string | null;
524
+ screenshot_uuid?: string | null;
525
+ }
526
+ interface TodoHistory {
527
+ todo_index: number;
528
+ todo: string;
529
+ actions: TaskerAction[];
530
+ summary?: string;
531
+ completed: boolean;
532
+ }
533
+ interface PlannerOutput {
534
+ instruction: string;
535
+ reasoning: string;
536
+ subtodos: string[];
537
+ }
538
+ interface ReflectionOutput {
539
+ continue_current: boolean;
540
+ new_instruction?: string | null;
541
+ reasoning: string;
542
+ success_assessment: boolean;
543
+ }
544
+ type PlannerContext = Record<string, unknown>;
545
+ declare class PlannerMemory {
546
+ taskDescription: string;
547
+ todos: TodoItem[];
548
+ history: TodoHistory[];
549
+ taskExecutionSummary: string;
550
+ todoExecutionSummaries: Record<number, string>;
551
+ setTask(taskDescription: string, todos: string[] | TodoItem[]): void;
552
+ getCurrentTodo(): {
553
+ todo: TodoItem;
554
+ index: number;
555
+ } | null;
556
+ updateTodo(index: number, status: TodoStatus, summary?: string): void;
557
+ addHistory(todoIndex: number, actions: TaskerAction[], summary?: string, completed?: boolean): void;
558
+ getContext(): PlannerContext;
559
+ getTodoStatusSummary(): Record<string, number>;
560
+ appendTodo(description: string): void;
561
+ }
562
+ declare class Planner {
563
+ private apiKey?;
564
+ private baseUrl?;
565
+ private client?;
566
+ private ownsClient;
567
+ constructor(client?: Client, apiKey?: string | undefined, baseUrl?: string | undefined);
568
+ private ensureClient;
569
+ getClient(): Client;
570
+ close(): Promise<void>;
571
+ private extractMemoryData;
572
+ private extractJsonString;
573
+ private parsePlannerOutput;
574
+ private parseReflectionOutput;
575
+ private formatExecutionNotes;
576
+ private ensureScreenshotUuid;
577
+ initialPlan(todo: string, context: PlannerContext, screenshot?: ImageLike, memory?: PlannerMemory, todoIndex?: number): Promise<{
578
+ output: PlannerOutput;
579
+ requestId?: string | null;
580
+ }>;
581
+ reflect(actions: TaskerAction[], context: PlannerContext, screenshot?: ImageLike, memory?: PlannerMemory, todoIndex?: number, currentInstruction?: string, reflectionInterval?: number): Promise<{
582
+ output: ReflectionOutput;
583
+ requestId?: string | null;
584
+ }>;
585
+ summarize(_executionHistory: TaskerAction[], context: PlannerContext, memory?: PlannerMemory, todoIndex?: number): Promise<{
586
+ summary: string;
587
+ requestId?: string | null;
588
+ }>;
589
+ }
590
+ declare class TaskerAgent implements Agent {
591
+ /** Hierarchical agent that manages multi-todo workflows. */
592
+ private apiKey?;
593
+ private baseUrl?;
594
+ private model;
595
+ private maxSteps;
596
+ private temperature?;
597
+ private reflectionInterval;
598
+ private planner;
599
+ private stepObserver?;
600
+ private stepDelay;
601
+ private memory;
602
+ private currentTaskeeAgent?;
603
+ constructor(apiKey?: string, baseUrl?: string, model?: string, maxSteps?: number, temperature?: number | undefined, reflectionInterval?: number, planner?: Planner, stepObserver?: StepObserver, stepDelay?: number);
604
+ setTask(task: string, todos: string[]): void;
605
+ set_task(task: string, todos: string[]): void;
606
+ execute(_instruction: string, actionHandler: ActionHandler, imageProvider: ImageProvider): Promise<boolean>;
607
+ private prepare;
608
+ private executeTodo;
609
+ private updateMemoryFromExecution;
610
+ private updateTaskSummary;
611
+ getMemory(): PlannerMemory;
612
+ appendTodo(description: string): void;
613
+ }
614
+
615
+ /**
616
+ * -----------------------------------------------------------------------------
617
+ * Copyright (c) OpenAGI Foundation
618
+ * All rights reserved.
619
+ *
620
+ * This file is part of the official API project.
621
+ * Licensed under the MIT License.
622
+ * -----------------------------------------------------------------------------
623
+ */
624
+
625
+ declare enum ExportFormat {
626
+ /** Supported export formats. */
627
+ MARKDOWN = "markdown",
628
+ HTML = "html",
629
+ JSON = "json"
630
+ }
631
+ declare class AsyncAgentObserver extends StepObserver {
632
+ /**
633
+ * Records agent execution events and exports to various formats.
634
+ *
635
+ * This class implements the AsyncObserver protocol and provides
636
+ * functionality for recording events during agent execution and
637
+ * exporting them to Markdown or HTML formats.
638
+ */
639
+ events: ObserverEvent[];
640
+ onEvent(event: ObserverEvent): Promise<void>;
641
+ addLog(message: string): void;
642
+ addSplit(label?: string): void;
643
+ clear(): void;
644
+ getEventsByStep(step_num: number): ObserverEvent[];
645
+ export(format: ExportFormat | string, path: string, images_dir?: string | null): void;
646
+ }
647
+
648
+ /**
649
+ * -----------------------------------------------------------------------------
650
+ * Copyright (c) OpenAGI Foundation
651
+ * All rights reserved.
652
+ *
653
+ * This file is part of the official API project.
654
+ * Licensed under the MIT License.
655
+ * -----------------------------------------------------------------------------
656
+ */
657
+
658
+ interface Agent {
659
+ /**
660
+ * Protocol for synchronous task execution agents.
661
+ */
662
+ execute(instruction: string, action_handler: ActionHandler, image_provider: ImageProvider): Promise<boolean>;
663
+ }
664
+
511
665
  /**
512
666
  * -----------------------------------------------------------------------------
513
667
  * Copyright (c) OpenAGI Foundation
@@ -564,4 +718,4 @@ declare class DefaultActionHandler implements ActionHandler {
564
718
  handle(actions: Action[]): Promise<void>;
565
719
  }
566
720
 
567
- export { APIError, Actor, type Agent, AuthenticationError, Client, ConfigurationError, DefaultActionHandler, DefaultAgent, type ErrorDetail, type ErrorResponse, type GenerateResponse, NetworkError, NotFoundError, OAGIError, RateLimitError, RequestTimeoutError, ScreenshotMaker, ServerError, type UploadFileResponse, ValidationError };
721
+ export { APIError, type Action, Actor, type Agent, AsyncAgentObserver, AuthenticationError, Client, type ClientOptions, ConfigurationError, DefaultActionHandler, DefaultAgent, type ErrorDetail, type ErrorResponse, ExportFormat, type GenerateResponse, NetworkError, NotFoundError, OAGIError, RateLimitError, RequestTimeoutError, ScreenshotMaker, ServerError, type Step, TaskerAgent, type UploadFileResponse, ValidationError };
package/dist/index.js CHANGED
@@ -2,11 +2,13 @@
2
2
  import {
3
3
  APIError,
4
4
  Actor,
5
+ AsyncAgentObserver,
5
6
  AuthenticationError,
6
7
  Client,
7
8
  ConfigurationError,
8
9
  DefaultActionHandler,
9
10
  DefaultAgent,
11
+ ExportFormat,
10
12
  NetworkError,
11
13
  NotFoundError,
12
14
  OAGIError,
@@ -14,16 +16,19 @@ import {
14
16
  RequestTimeoutError,
15
17
  ScreenshotMaker,
16
18
  ServerError,
19
+ TaskerAgent,
17
20
  ValidationError
18
- } from "./chunk-SDBYP57G.js";
21
+ } from "./chunk-SRTB44IH.js";
19
22
  export {
20
23
  APIError,
21
24
  Actor,
25
+ AsyncAgentObserver,
22
26
  AuthenticationError,
23
27
  Client,
24
28
  ConfigurationError,
25
29
  DefaultActionHandler,
26
30
  DefaultAgent,
31
+ ExportFormat,
27
32
  NetworkError,
28
33
  NotFoundError,
29
34
  OAGIError,
@@ -31,6 +36,7 @@ export {
31
36
  RequestTimeoutError,
32
37
  ScreenshotMaker,
33
38
  ServerError,
39
+ TaskerAgent,
34
40
  ValidationError
35
41
  };
36
42
  //# sourceMappingURL=index.js.map
package/dist/index.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * -----------------------------------------------------------------------------
3
+ * Copyright (c) OpenAGI Foundation
4
+ * All rights reserved.
5
+ *
6
+ * This file is part of the official API project.
7
+ * Licensed under the MIT License.
8
+ * -----------------------------------------------------------------------------
9
+ */
10
+
11
+ export type {
12
+ ActionEvent,
13
+ BaseEvent,
14
+ ImageEvent,
15
+ LogEvent,
16
+ ObserverEvent,
17
+ PlanEvent,
18
+ SplitEvent,
19
+ StepEvent,
20
+ } from '../../types/index.js';
21
+
22
+ export { AsyncAgentObserver, ExportFormat } from './agent_observer.js';
23
+ export { exportToHtml, exportToJson, exportToMarkdown } from './exporters.js';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * -----------------------------------------------------------------------------
3
+ * Copyright (c) OpenAGI Foundation
4
+ * All rights reserved.
5
+ *
6
+ * This file is part of the official API project.
7
+ * Licensed under the MIT License.
8
+ * -----------------------------------------------------------------------------
9
+ */
10
+
11
+ // Re-export from types for convenience
12
+ import type { AsyncObserver } from '../../types/index.js';
13
+
14
+ export type { AsyncObserver };