shellx-ai 1.0.12 → 1.1.1

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 (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +666 -0
  3. package/dist/automation/element-finder.d.ts +189 -0
  4. package/dist/automation/element-finder.js +322 -0
  5. package/dist/automation/element-finder.js.map +1 -0
  6. package/dist/automation/ui-action-handler.d.ts +330 -0
  7. package/dist/automation/ui-action-handler.js +873 -0
  8. package/dist/automation/ui-action-handler.js.map +1 -0
  9. package/dist/cbor-compat.d.ts +27 -0
  10. package/dist/cbor-compat.js +111 -0
  11. package/dist/cbor-compat.js.map +1 -0
  12. package/dist/domain-manager.d.ts +80 -0
  13. package/dist/domain-manager.js +161 -0
  14. package/dist/domain-manager.js.map +1 -0
  15. package/dist/error-handler.d.ts +87 -0
  16. package/dist/error-handler.js +151 -0
  17. package/dist/error-handler.js.map +1 -0
  18. package/dist/errors.d.ts +114 -0
  19. package/dist/errors.js +139 -0
  20. package/dist/errors.js.map +1 -0
  21. package/dist/index.d.ts +163 -54
  22. package/dist/index.js +678 -481
  23. package/dist/index.js.map +1 -0
  24. package/dist/logger.d.ts +81 -0
  25. package/dist/logger.js +128 -0
  26. package/dist/logger.js.map +1 -0
  27. package/dist/protocol.d.ts +147 -31
  28. package/dist/protocol.js +2 -2
  29. package/dist/protocol.js.map +1 -0
  30. package/dist/shell/output-buffer.d.ts +152 -0
  31. package/dist/shell/output-buffer.js +176 -0
  32. package/dist/shell/output-buffer.js.map +1 -0
  33. package/dist/shell/shell-command-executor.d.ts +182 -0
  34. package/dist/shell/shell-command-executor.js +404 -0
  35. package/dist/shell/shell-command-executor.js.map +1 -0
  36. package/dist/shellx.d.ts +681 -178
  37. package/dist/shellx.js +762 -1159
  38. package/dist/shellx.js.map +1 -0
  39. package/dist/types.d.ts +132 -57
  40. package/dist/types.js +4 -4
  41. package/dist/types.js.map +1 -0
  42. package/dist/utils/retry-helper.d.ts +73 -0
  43. package/dist/utils/retry-helper.js +95 -0
  44. package/dist/utils/retry-helper.js.map +1 -0
  45. package/dist/utils.d.ts +3 -3
  46. package/dist/utils.js +20 -23
  47. package/dist/utils.js.map +1 -0
  48. package/package.json +95 -62
@@ -0,0 +1,151 @@
1
+ /**
2
+ * ErrorHandler - Unified error handling utilities for ShellX
3
+ *
4
+ * This module provides consistent error handling patterns across the codebase,
5
+ * ensuring all errors are properly formatted, logged, and returned.
6
+ */
7
+ import { createLogger } from "./logger.js";
8
+ import { OperationError, ValidationError } from "./errors.js";
9
+ // Create logger for ErrorHandler
10
+ const logger = createLogger("ErrorHandler");
11
+ /**
12
+ * Safely extracts error message from unknown error
13
+ * @param error - Unknown error object
14
+ * @param defaultMessage - Default message if extraction fails
15
+ * @returns Error message string
16
+ */
17
+ export function extractErrorMessage(error, defaultMessage = "Unknown error occurred") {
18
+ if (error instanceof Error) {
19
+ return error.message;
20
+ }
21
+ if (typeof error === "string") {
22
+ return error;
23
+ }
24
+ if (error && typeof error === "object" && "message" in error) {
25
+ return String(error.message);
26
+ }
27
+ return defaultMessage;
28
+ }
29
+ /**
30
+ * Creates a standardized error result
31
+ * @param error - Error object or message
32
+ * @param startTime - Operation start time for duration calculation
33
+ * @param options - Error handler options
34
+ * @returns Standardized error result
35
+ */
36
+ export function createErrorResult(error, startTime, options = {}) {
37
+ const errorMessage = extractErrorMessage(error, options.defaultErrorMessage);
38
+ if (options.logError !== false && options.logPrefix) {
39
+ logger.error(`${options.logPrefix}`, error);
40
+ }
41
+ return {
42
+ success: false,
43
+ error: errorMessage,
44
+ duration: Date.now() - startTime,
45
+ timestamp: startTime,
46
+ ...options.context,
47
+ };
48
+ }
49
+ /**
50
+ * Creates a standardized success result
51
+ * @param data - Success data
52
+ * @param startTime - Operation start time
53
+ * @returns Standardized success result
54
+ */
55
+ export function createSuccessResult(data, startTime) {
56
+ return {
57
+ success: true,
58
+ duration: Date.now() - startTime,
59
+ timestamp: startTime,
60
+ ...data,
61
+ };
62
+ }
63
+ /**
64
+ * Wraps an async operation with standardized error handling
65
+ * @param operation - Async operation to execute
66
+ * @param startTime - Operation start time
67
+ * @param options - Error handler options
68
+ * @returns Promise resolving to result or error
69
+ */
70
+ export async function handleOperation(operation, startTime, options = {}) {
71
+ try {
72
+ const data = await operation();
73
+ return createSuccessResult(data, startTime);
74
+ }
75
+ catch (error) {
76
+ throw new OperationError(extractErrorMessage(error, options.defaultErrorMessage), options.context);
77
+ }
78
+ }
79
+ /**
80
+ * Validates required parameters and throws ValidationError if missing
81
+ * @param params - Parameters to validate
82
+ * @param paramName - Name of the parameter for error message
83
+ * @throws ValidationError if parameter is missing/invalid
84
+ */
85
+ export function validateRequired(param, paramName) {
86
+ if (param === undefined || param === null) {
87
+ throw new ValidationError(`Required parameter '${paramName}' is missing`);
88
+ }
89
+ }
90
+ /**
91
+ * Validates one of multiple required parameters is present
92
+ * @param params - Object with parameters to validate
93
+ * @param requiredNames - Array of parameter names (at least one must be present)
94
+ * @throws ValidationError if none of the parameters are present
95
+ */
96
+ export function validateOneOfRequired(params, requiredNames) {
97
+ const hasOne = requiredNames.some((name) => params[name] !== undefined && params[name] !== null);
98
+ if (!hasOne) {
99
+ throw new ValidationError(`At least one of the following parameters is required: ${requiredNames.join(", ")}`);
100
+ }
101
+ }
102
+ /**
103
+ * Executes operation with retry and standardized error handling
104
+ * @param operation - Async operation to execute
105
+ * @param startTime - Operation start time
106
+ * @param options - Error handler options
107
+ * @returns Promise resolving to result or null if all retries fail
108
+ */
109
+ export async function handleOperationWithRetry(operation, startTime, options = {}) {
110
+ const { maxRetries = 3, retryDelay = 500, ...errorOptions } = options;
111
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
112
+ try {
113
+ const data = await operation();
114
+ return createSuccessResult(data, startTime);
115
+ }
116
+ catch (error) {
117
+ const isLastAttempt = attempt === maxRetries;
118
+ if (errorOptions.logError !== false) {
119
+ logger.warn(`${errorOptions.logPrefix || "Operation"} attempt ${attempt}/${maxRetries} failed:`, error);
120
+ }
121
+ if (isLastAttempt) {
122
+ return createErrorResult(error, startTime, {
123
+ ...errorOptions,
124
+ defaultErrorMessage: errorOptions.defaultErrorMessage || "Operation failed after retries",
125
+ });
126
+ }
127
+ // Wait before retry
128
+ await new Promise((resolve) => setTimeout(resolve, retryDelay));
129
+ }
130
+ }
131
+ // This should never be reached, but TypeScript needs it
132
+ return null;
133
+ }
134
+ /**
135
+ * Wraps an error with additional context for better debugging
136
+ * @param error - Original error
137
+ * @param context - Additional context information
138
+ * @param operationName - Name of the operation that failed
139
+ * @returns Wrapped error with context
140
+ */
141
+ export function wrapErrorWithContext(error, context, operationName) {
142
+ const baseMessage = extractErrorMessage(error);
143
+ const contextStr = Object.entries(context)
144
+ .map(([key, value]) => `${key}=${JSON.stringify(value)}`)
145
+ .join(", ");
146
+ const message = `${operationName} failed: ${baseMessage}${contextStr ? ` (${contextStr})` : ""}`;
147
+ const wrappedError = new Error(message);
148
+ wrappedError.stack = error instanceof Error ? error.stack : undefined;
149
+ return wrappedError;
150
+ }
151
+ //# sourceMappingURL=error-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../src/error-handler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9D,iCAAiC;AACjC,MAAM,MAAM,GAAG,YAAY,CAAC,cAAc,CAAC,CAAC;AAqB5C;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAc,EACd,iBAAyB,wBAAwB;IAEjD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,OAAO,CAAC;IACvB,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,K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AC,SAAS,CAAC;IAEtE,OAAO,YAAY,CAAC;AACtB,CAAC"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Unified Error Handling Types for ShellX
3
+ *
4
+ * This module defines consistent error response structures used across
5
+ * the entire ShellX codebase to ensure error handling is uniform.
6
+ */
7
+ /**
8
+ * Standard error response structure
9
+ * All error responses should follow this format
10
+ */
11
+ export interface ErrorResponse {
12
+ /** Error message describing what went wrong */
13
+ error: string;
14
+ /** Optional error code for categorization */
15
+ code?: string;
16
+ /** Additional error details */
17
+ details?: Record<string, unknown>;
18
+ }
19
+ /**
20
+ * Standard operation result with error information
21
+ * This is the base interface for all operation results
22
+ */
23
+ export interface BaseOperationResult {
24
+ /** Whether the operation completed successfully */
25
+ success: boolean;
26
+ /** Error information if operation failed */
27
+ error?: string;
28
+ /** Time taken for the operation in milliseconds */
29
+ duration: number;
30
+ }
31
+ /**
32
+ * Create a standardized error response
33
+ * @param message - Error message
34
+ * @param code - Optional error code
35
+ * @param details - Optional additional details
36
+ * @returns Standardized error response
37
+ */
38
+ export declare function createErrorResponse(message: string, code?: string, details?: Record<string, unknown>): ErrorResponse;
39
+ /**
40
+ * Create a standardized operation result
41
+ * @param success - Whether operation succeeded
42
+ * @param duration - Operation duration in milliseconds
43
+ * @param error - Optional error message
44
+ * @returns Standardized operation result
45
+ */
46
+ export declare function createOperationResult(success: boolean, duration: number, error?: string): BaseOperationResult;
47
+ /**
48
+ * Standard error codes
49
+ */
50
+ export declare enum ErrorCode {
51
+ CONNECTION_FAILED = "CONNECTION_FAILED",
52
+ CONNECTION_TIMEOUT = "CONNECTION_TIMEOUT",
53
+ AUTHENTICATION_FAILED = "AUTHENTICATION_FAILED",
54
+ DEVICE_NOT_FOUND = "DEVICE_NOT_FOUND",
55
+ DEVICE_NOT_REGISTERED = "DEVICE_NOT_REGISTERED",
56
+ OPERATION_FAILED = "OPERATION_FAILED",
57
+ OPERATION_TIMEOUT = "OPERATION_TIMEOUT",
58
+ OPERATION_CANCELLED = "OPERATION_CANCELLED",
59
+ ELEMENT_NOT_FOUND = "ELEMENT_NOT_FOUND",
60
+ ELEMENT_NOT_VISIBLE = "ELEMENT_NOT_VISIBLE",
61
+ ELEMENT_NOT_CLICKABLE = "ELEMENT_NOT_CLICKABLE",
62
+ INVALID_SELECTOR = "INVALID_SELECTOR",
63
+ INVALID_INPUT = "INVALID_INPUT",
64
+ MISSING_PARAMETER = "MISSING_PARAMETER",
65
+ INVALID_FORMAT = "INVALID_FORMAT",
66
+ INTERNAL_ERROR = "INTERNAL_ERROR",
67
+ NOT_INITIALIZED = "NOT_INITIALIZED",
68
+ NOT_SUPPORTED = "NOT_SUPPORTED",
69
+ COMMAND_FAILED = "COMMAND_FAILED",
70
+ COMMAND_TIMEOUT = "COMMAND_TIMEOUT",
71
+ COMMAND_EXIT_CODE = "COMMAND_EXIT_CODE"
72
+ }
73
+ /**
74
+ * ShellX specific error class
75
+ */
76
+ export declare class ShellXError extends Error {
77
+ /** Error code for categorization */
78
+ readonly code: string;
79
+ /** Additional error details */
80
+ readonly details?: Record<string, unknown>;
81
+ constructor(message: string, code: string, details?: Record<string, unknown>);
82
+ /**
83
+ * Convert error to standardized response format
84
+ */
85
+ toResponse(): ErrorResponse;
86
+ /**
87
+ * Create ShellXError from unknown error
88
+ */
89
+ static fromUnknown(error: unknown, defaultCode?: ErrorCode): ShellXError;
90
+ }
91
+ /**
92
+ * Connection error class
93
+ */
94
+ export declare class ConnectionError extends ShellXError {
95
+ constructor(message: string, details?: Record<string, unknown>);
96
+ }
97
+ /**
98
+ * Operation error class
99
+ */
100
+ export declare class OperationError extends ShellXError {
101
+ constructor(message: string, details?: Record<string, unknown>);
102
+ }
103
+ /**
104
+ * Element error class
105
+ */
106
+ export declare class ElementError extends ShellXError {
107
+ constructor(message: string, details?: Record<string, unknown>);
108
+ }
109
+ /**
110
+ * Validation error class
111
+ */
112
+ export declare class ValidationError extends ShellXError {
113
+ constructor(message: string, details?: Record<string, unknown>);
114
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Unified Error Handling Types for ShellX
3
+ *
4
+ * This module defines consistent error response structures used across
5
+ * the entire ShellX codebase to ensure error handling is uniform.
6
+ */
7
+ /**
8
+ * Create a standardized error response
9
+ * @param message - Error message
10
+ * @param code - Optional error code
11
+ * @param details - Optional additional details
12
+ * @returns Standardized error response
13
+ */
14
+ export function createErrorResponse(message, code, details) {
15
+ const response = { error: message };
16
+ if (code)
17
+ response.code = code;
18
+ if (details)
19
+ response.details = details;
20
+ return response;
21
+ }
22
+ /**
23
+ * Create a standardized operation result
24
+ * @param success - Whether operation succeeded
25
+ * @param duration - Operation duration in milliseconds
26
+ * @param error - Optional error message
27
+ * @returns Standardized operation result
28
+ */
29
+ export function createOperationResult(success, duration, error) {
30
+ const result = { success, duration };
31
+ if (error)
32
+ result.error = error;
33
+ return result;
34
+ }
35
+ /**
36
+ * Standard error codes
37
+ */
38
+ export var ErrorCode;
39
+ (function (ErrorCode) {
40
+ // Connection errors (1xxx)
41
+ ErrorCode["CONNECTION_FAILED"] = "CONNECTION_FAILED";
42
+ ErrorCode["CONNECTION_TIMEOUT"] = "CONNECTION_TIMEOUT";
43
+ ErrorCode["AUTHENTICATION_FAILED"] = "AUTHENTICATION_FAILED";
44
+ ErrorCode["DEVICE_NOT_FOUND"] = "DEVICE_NOT_FOUND";
45
+ ErrorCode["DEVICE_NOT_REGISTERED"] = "DEVICE_NOT_REGISTERED";
46
+ // Operation errors (2xxx)
47
+ ErrorCode["OPERATION_FAILED"] = "OPERATION_FAILED";
48
+ ErrorCode["OPERATION_TIMEOUT"] = "OPERATION_TIMEOUT";
49
+ ErrorCode["OPERATION_CANCELLED"] = "OPERATION_CANCELLED";
50
+ // Element errors (3xxx)
51
+ ErrorCode["ELEMENT_NOT_FOUND"] = "ELEMENT_NOT_FOUND";
52
+ ErrorCode["ELEMENT_NOT_VISIBLE"] = "ELEMENT_NOT_VISIBLE";
53
+ ErrorCode["ELEMENT_NOT_CLICKABLE"] = "ELEMENT_NOT_CLICKABLE";
54
+ ErrorCode["INVALID_SELECTOR"] = "INVALID_SELECTOR";
55
+ // Input errors (4xxx)
56
+ ErrorCode["INVALID_INPUT"] = "INVALID_INPUT";
57
+ ErrorCode["MISSING_PARAMETER"] = "MISSING_PARAMETER";
58
+ ErrorCode["INVALID_FORMAT"] = "INVALID_FORMAT";
59
+ // System errors (5xxx)
60
+ ErrorCode["INTERNAL_ERROR"] = "INTERNAL_ERROR";
61
+ ErrorCode["NOT_INITIALIZED"] = "NOT_INITIALIZED";
62
+ ErrorCode["NOT_SUPPORTED"] = "NOT_SUPPORTED";
63
+ // Command errors (6xxx)
64
+ ErrorCode["COMMAND_FAILED"] = "COMMAND_FAILED";
65
+ ErrorCode["COMMAND_TIMEOUT"] = "COMMAND_TIMEOUT";
66
+ ErrorCode["COMMAND_EXIT_CODE"] = "COMMAND_EXIT_CODE";
67
+ })(ErrorCode || (ErrorCode = {}));
68
+ /**
69
+ * ShellX specific error class
70
+ */
71
+ export class ShellXError extends Error {
72
+ /** Error code for categorization */
73
+ code;
74
+ /** Additional error details */
75
+ details;
76
+ constructor(message, code, details) {
77
+ super(message);
78
+ this.name = "ShellXError";
79
+ this.code = code;
80
+ this.details = details;
81
+ // Maintains proper stack trace for where our error was thrown
82
+ if (Error.captureStackTrace) {
83
+ Error.captureStackTrace(this, ShellXError);
84
+ }
85
+ }
86
+ /**
87
+ * Convert error to standardized response format
88
+ */
89
+ toResponse() {
90
+ return createErrorResponse(this.message, this.code, this.details);
91
+ }
92
+ /**
93
+ * Create ShellXError from unknown error
94
+ */
95
+ static fromUnknown(error, defaultCode = ErrorCode.INTERNAL_ERROR) {
96
+ if (error instanceof ShellXError) {
97
+ return error;
98
+ }
99
+ const message = error instanceof Error ? error.message : String(error);
100
+ return new ShellXError(message, defaultCode);
101
+ }
102
+ }
103
+ /**
104
+ * Connection error class
105
+ */
106
+ export class ConnectionError extends ShellXError {
107
+ constructor(message, details) {
108
+ super(message, ErrorCode.CONNECTION_FAILED, details);
109
+ this.name = "ConnectionError";
110
+ }
111
+ }
112
+ /**
113
+ * Operation error class
114
+ */
115
+ export class OperationError extends ShellXError {
116
+ constructor(message, details) {
117
+ super(message, ErrorCode.OPERATION_FAILED, details);
118
+ this.name = "OperationError";
119
+ }
120
+ }
121
+ /**
122
+ * Element error class
123
+ */
124
+ export class ElementError extends ShellXError {
125
+ constructor(message, details) {
126
+ super(message, ErrorCode.ELEMENT_NOT_FOUND, details);
127
+ this.name = "ElementError";
128
+ }
129
+ }
130
+ /**
131
+ * Validation error class
132
+ */
133
+ export class ValidationError extends ShellXError {
134
+ constructor(message, details) {
135
+ super(message, ErrorCode.INVALID_INPUT, details);
136
+ this.name = "ValidationError";
137
+ }
138
+ }
139
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA4BH;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,OAAe,EACf,IAAa,EACb,OAAiC;IAEjC,MAAM,QAAQ,GAAkB,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IACnD,IAAI,IAAI;QAAE,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC;IAC/B,IAAI,OAAO;QAAE,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC;IACxC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAAgB,EAChB,QAAgB,EAChB,KAAc;IAEd,MAAM,MAAM,GAAwB,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;IAC1D,IAAI,KAAK;QAAE,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;IAChC,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,SAiCX;AAjCD,WAAY,SAAS;IACnB,2BAA2B;IAC3B,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