@ddwang/magnitude-core 0.3.1-ddwang.2 → 0.3.1-ddwang.4

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
@@ -201,7 +201,39 @@ interface ModelUsage {
201
201
  outputCost?: number;
202
202
  }
203
203
 
204
+ interface OperationOptions {
205
+ signal?: AbortSignal;
206
+ /** Absolute Unix time in milliseconds, shared by every step, retry, and wait. */
207
+ deadline?: number;
208
+ }
209
+ type OperationKind = 'act' | 'query' | 'extract' | 'nav' | 'exec';
210
+ type OperationPhase = 'preparing' | 'context' | 'observations' | 'model' | 'action' | 'screenshot' | 'stability' | 'cooldown' | 'retry' | 'paused' | 'cursor';
211
+ interface OperationTiming {
212
+ count: number;
213
+ totalMs: number;
214
+ }
215
+ interface OperationDiagnostics {
216
+ id: string;
217
+ kind: OperationKind;
218
+ status: 'running' | 'draining' | 'finished';
219
+ outcome?: 'succeeded' | 'failed' | 'cancelled' | 'deadline';
220
+ phase: OperationPhase;
221
+ startedAt: number;
222
+ elapsedMs: number;
223
+ cancellationToDrainMs?: number;
224
+ cancellationToIdleMs?: number;
225
+ lastAction?: {
226
+ index: number;
227
+ name: string;
228
+ state: 'pending' | 'started' | 'completed' | 'failed';
229
+ };
230
+ /** Inclusive totals: nested and concurrent phases overlap and must not be summed. */
231
+ timings: Partial<Record<OperationPhase, OperationTiming>>;
232
+ }
233
+
204
234
  interface AgentEvents {
235
+ /** Payload-free snapshots. Existing action/thought events retain their original payloads. */
236
+ 'operation': (diagnostics: OperationDiagnostics) => void;
205
237
  'start': () => void;
206
238
  'stop': () => void;
207
239
  'thought': (thought: string) => void;
@@ -398,12 +430,6 @@ declare class AgentMemory {
398
430
  loadJSON(data: SerializedAgentMemory): Promise<void>;
399
431
  }
400
432
 
401
- interface OperationOptions {
402
- signal?: AbortSignal;
403
- /** Absolute Unix time in milliseconds, shared by every step, retry, and wait. */
404
- deadline?: number;
405
- }
406
-
407
433
  type ActionContext<T> = {
408
434
  input: T;
409
435
  agent: Agent;
@@ -490,18 +516,30 @@ declare class Agent {
490
516
  private _paused;
491
517
  private _pauseResolve;
492
518
  private activeOperation?;
519
+ private latestOperation?;
493
520
  private idle;
494
- private stopped;
521
+ private resolveIdle?;
522
+ private pendingWork;
523
+ private lifecycleTail;
524
+ private lifecycleRequest?;
525
+ private lifecycleState;
526
+ private telemetryStarted;
495
527
  protected latestTaskMemory: AgentMemory;
496
528
  constructor(baseConfig?: Partial<AgentOptions>);
497
529
  getConnector<C extends AgentConnector>(connectorClass: new (...args: any[]) => C): C | undefined;
498
530
  require<C extends AgentConnector>(connectorClass: new (...args: any[]) => C): C;
499
531
  start(): Promise<void>;
532
+ get lifecycle(): 'new' | 'starting' | 'ready' | 'stopping' | 'stopped';
533
+ private beginWork;
534
+ private endWork;
535
+ private scheduleLifecycle;
500
536
  identifyAction(action: Action): ActionDefinition<any>;
501
537
  /** True until underlying work settles, including after a cancelled caller returns. */
502
538
  get busy(): boolean;
503
539
  whenIdle(): Promise<void>;
504
- protected runOperation<T>(options: OperationOptions, fn: () => Promise<T>): Promise<T>;
540
+ /** A payload-free snapshot of the active or most recent operation. */
541
+ get operation(): OperationDiagnostics | undefined;
542
+ protected runOperation<T>(options: OperationOptions, fn: () => Promise<T>, kind?: OperationKind): Promise<T>;
505
543
  exec(action: Action, memory?: AgentMemory, options?: OperationOptions): Promise<unknown>;
506
544
  private _exec;
507
545
  protected _recordConnectorObservations(memory: AgentMemory): Promise<void>;
@@ -518,10 +556,13 @@ declare class Agent {
518
556
  resume(): void;
519
557
  get paused(): boolean;
520
558
  stop(): Promise<void>;
559
+ private stopConnectors;
521
560
  }
522
561
 
523
562
  interface ActionVisualizerOptions {
524
563
  showCursor?: boolean;
564
+ /** Set false to skip the 300 ms movement animation. Defaults to true. */
565
+ animateCursor?: boolean;
525
566
  showHoverCircle?: boolean;
526
567
  showClickRipple?: boolean;
527
568
  showDragLine?: boolean;
@@ -686,6 +727,7 @@ interface BrowserBlock {
686
727
  }
687
728
  declare class BrowserBlockedError extends Error {
688
729
  readonly block: BrowserBlock;
730
+ readonly operation?: OperationDiagnostics;
689
731
  constructor(block: BrowserBlock);
690
732
  }
691
733
  interface HttpDiagnostic {
@@ -850,6 +892,7 @@ interface AgentErrorOptions {
850
892
  adaptable?: boolean;
851
893
  }
852
894
  declare class AgentError extends Error {
895
+ readonly operation?: OperationDiagnostics;
853
896
  readonly options: Required<AgentErrorOptions>;
854
897
  constructor(message: string, options?: AgentErrorOptions);
855
898
  }
@@ -1007,4 +1050,4 @@ declare function buildDefaultBrowserAgentOptions({ agentOptions, browserOptions
1007
1050
  declare const logger: pino.Logger<never, boolean>;
1008
1051
 
1009
1052
  export { ActionLimitError, Agent, AgentBusyError, AgentError, AgentMemory, BrowserAgent, BrowserBlockedError, BrowserConnector, BrowserProvider, DesktopConnector, Observation, OperationCancelledError, OperationDeadlineError, WebHarness, allBrowserAgentRoles, buildDefaultBrowserAgentOptions, createAction, createId, deepEquals, getCodebaseId, getMachineId, logger, mergeMessages, posthog, retryOnError, retryOnErrorIsSuccess, sendTelemetry, startBrowserAgent };
1010
- export type { ActOptions, Action, ActionContext, ActionDefinition, ActionIntent, ActionPayload, AgentConnector, AgentErrorOptions, AgentEvents, AgentMemoryOptions, AgentOptions, AnthropicClient, ApiKeyFailure, AzureOpenAIClient, Base64Image, BasetenClient, BedrockClient, BlockReason, BrowserAgentRole, BrowserBlock, BrowserConnectorOptions, BrowserConnectorStateData, BrowserFailure, BrowserOptions, BugDetectedFailure, BugSeverity, CancelledFailure, CheckIntent, ClaudeCodeClient, ClickIntent, ClickWebAction, DesktopConnectorOptions, DesktopInterface, FailedTestCaseResult, FailureDescriptor, GoogleAIClient, GoogleVertexClient, HoverIntent, HoverWebAction, HttpDiagnostic, Intent, LLMClient, LLMClientIdentifier, MemoryRenderOptions, MisalignmentFailure, ModelUsage, NavigateWebAction, NetworkFailure, ObservableDataArray, ObservableDataObject, ObservableDataPrimitive, ObservationRetentionOptions, ObservationRole, ObservationSource, OpenAIClient, OpenAIGenericClient, OperationOptions, PixelCoordinate, RateLimitFailure, RecoveryOptions, RenderableContent, RetryMode, RetryOptions, RetryParams, ScrollIntent, ScrollWebAction, SerializedAgentMemory, SuccessfulTestCaseResult, SwitchTabIntent, SwitchTabWebAction, TestCaseDefinition, TestCaseResult, TestData, TestDataEntry, TestStepDefinition, TypeIntent, TypeWebAction, UnknownFailure, WebAction, WebHarnessEvents, WebHarnessOptions };
1053
+ export type { ActOptions, Action, ActionContext, ActionDefinition, ActionIntent, ActionPayload, AgentConnector, AgentErrorOptions, AgentEvents, AgentMemoryOptions, AgentOptions, AnthropicClient, ApiKeyFailure, AzureOpenAIClient, Base64Image, BasetenClient, BedrockClient, BlockReason, BrowserAgentRole, BrowserBlock, BrowserConnectorOptions, BrowserConnectorStateData, BrowserFailure, BrowserOptions, BugDetectedFailure, BugSeverity, CancelledFailure, CheckIntent, ClaudeCodeClient, ClickIntent, ClickWebAction, DesktopConnectorOptions, DesktopInterface, FailedTestCaseResult, FailureDescriptor, GoogleAIClient, GoogleVertexClient, HoverIntent, HoverWebAction, HttpDiagnostic, Intent, LLMClient, LLMClientIdentifier, MemoryRenderOptions, MisalignmentFailure, ModelUsage, NavigateWebAction, NetworkFailure, ObservableDataArray, ObservableDataObject, ObservableDataPrimitive, ObservationRetentionOptions, ObservationRole, ObservationSource, OpenAIClient, OpenAIGenericClient, OperationDiagnostics, OperationKind, OperationOptions, OperationPhase, OperationTiming, PixelCoordinate, RateLimitFailure, RecoveryOptions, RenderableContent, RetryMode, RetryOptions, RetryParams, ScrollIntent, ScrollWebAction, SerializedAgentMemory, SuccessfulTestCaseResult, SwitchTabIntent, SwitchTabWebAction, TestCaseDefinition, TestCaseResult, TestData, TestDataEntry, TestStepDefinition, TypeIntent, TypeWebAction, UnknownFailure, WebAction, WebHarnessEvents, WebHarnessOptions };
package/dist/index.d.ts CHANGED
@@ -17,7 +17,7 @@ export { BrowserBlockedError } from '@/web/recovery';
17
17
  export type { BrowserBlock, BlockReason, RecoveryOptions, HttpDiagnostic } from '@/web/recovery';
18
18
  export * from "@/actions/types";
19
19
  export * from '@/common';
20
- export type { OperationOptions } from '@/common/operation';
20
+ export type { OperationOptions, OperationDiagnostics, OperationKind, OperationPhase, OperationTiming } from '@/common/operation';
21
21
  export * from "@/telemetry";
22
22
  export { buildDefaultBrowserAgentOptions } from "@/ai/util";
23
23
  export { logger } from './logger';