@ketd/gemini-cli-sdk 0.3.4 → 0.3.6

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,11 +1,118 @@
1
1
  import { EventEmitter } from 'events';
2
2
  import { EventEmitter as EventEmitter$1 } from 'node:events';
3
3
 
4
+ /**
5
+ * Logger utility for Gemini CLI SDK
6
+ *
7
+ * Provides a configurable logging interface that can be customized by SDK consumers.
8
+ * By default, logs go to console. Users can provide their own logger implementation.
9
+ */
10
+ /**
11
+ * Log level enumeration
12
+ */
13
+ declare enum LogLevel {
14
+ DEBUG = 0,
15
+ INFO = 1,
16
+ WARN = 2,
17
+ ERROR = 3,
18
+ SILENT = 4
19
+ }
20
+ /**
21
+ * Logger interface that SDK consumers can implement
22
+ */
23
+ interface Logger {
24
+ debug(message: string, ...args: unknown[]): void;
25
+ info(message: string, ...args: unknown[]): void;
26
+ warn(message: string, ...args: unknown[]): void;
27
+ error(message: string, ...args: unknown[]): void;
28
+ }
29
+ /**
30
+ * Logger configuration options
31
+ */
32
+ interface LoggerOptions {
33
+ /** Custom logger implementation */
34
+ logger?: Logger;
35
+ /** Minimum log level to output (default: INFO, or DEBUG if debug=true) */
36
+ level?: LogLevel;
37
+ /** Prefix for all log messages (e.g., '[GeminiSDK]') */
38
+ prefix?: string;
39
+ }
40
+ /**
41
+ * Silent logger that outputs nothing
42
+ */
43
+ declare const silentLogger: Logger;
44
+ /**
45
+ * SDK Logger class
46
+ *
47
+ * Wraps a logger implementation with level filtering and prefix support.
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * // Use default console logger
52
+ * const logger = new SDKLogger({ level: LogLevel.DEBUG });
53
+ *
54
+ * // Use custom logger
55
+ * const logger = new SDKLogger({
56
+ * logger: myCustomLogger,
57
+ * prefix: '[MyApp]',
58
+ * });
59
+ *
60
+ * logger.debug('Debug message');
61
+ * logger.error('Error occurred', { details: '...' });
62
+ * ```
63
+ */
64
+ declare class SDKLogger implements Logger {
65
+ private logger;
66
+ private level;
67
+ private prefix;
68
+ constructor(options?: LoggerOptions);
69
+ /**
70
+ * Update logger configuration
71
+ */
72
+ configure(options: Partial<LoggerOptions>): void;
73
+ /**
74
+ * Set log level
75
+ */
76
+ setLevel(level: LogLevel): void;
77
+ /**
78
+ * Set custom logger implementation
79
+ */
80
+ setLogger(logger: Logger): void;
81
+ private formatMessage;
82
+ debug(message: string, ...args: unknown[]): void;
83
+ info(message: string, ...args: unknown[]): void;
84
+ warn(message: string, ...args: unknown[]): void;
85
+ error(message: string, ...args: unknown[]): void;
86
+ }
87
+ /**
88
+ * Global SDK logger instance
89
+ *
90
+ * Used internally by SDK components. Can be configured by SDK consumers.
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * import { sdkLogger, LogLevel } from '@google/gemini-cli-sdk';
95
+ *
96
+ * // Configure global logger
97
+ * sdkLogger.setLevel(LogLevel.DEBUG);
98
+ * sdkLogger.setLogger(myCustomLogger);
99
+ * ```
100
+ */
101
+ declare const sdkLogger: SDKLogger;
102
+ /**
103
+ * Create a component-specific logger
104
+ *
105
+ * @param component - Component name for the prefix (e.g., 'GeminiStreamClient')
106
+ * @param options - Logger options
107
+ */
108
+ declare function createLogger(component: string, options?: LoggerOptions): SDKLogger;
109
+
4
110
  /**
5
111
  * Type definitions for Gemini CLI SDK
6
112
  *
7
113
  * Based on Gemini CLI v0.21.0+ interface specification
8
114
  */
115
+
9
116
  /**
10
117
  * Gemini CLI configuration options
11
118
  */
@@ -95,6 +202,21 @@ interface GeminiOptions {
95
202
  * If not provided, falls back to Gemini CLI's built-in approval mechanism
96
203
  */
97
204
  onPermissionRequest?: (request: ToolPermissionRequest) => Promise<ToolPermissionDecision>;
205
+ /**
206
+ * Custom logger implementation
207
+ * If not provided, uses console with [GeminiSDK] prefix
208
+ * Set to silentLogger to disable all logging
209
+ *
210
+ * @example
211
+ * ```typescript
212
+ * import { silentLogger } from '@google/gemini-cli-sdk';
213
+ *
214
+ * const stream = query('Hello', {
215
+ * logger: silentLogger, // Disable all logging
216
+ * });
217
+ * ```
218
+ */
219
+ logger?: Logger;
98
220
  }
99
221
  /**
100
222
  * Tool permission request
@@ -461,9 +583,16 @@ interface MCPServerConfig {
461
583
  cwd?: string;
462
584
  /** Environment variables */
463
585
  env?: Record<string, string>;
464
- /** URL for SSE transport */
586
+ /**
587
+ * Transport type for URL-based connections
588
+ * - 'http': Streamable HTTP transport (recommended for mcp-chrome)
589
+ * - 'sse': Server-Sent Events transport
590
+ * When not specified with url, defaults to 'http'
591
+ */
592
+ type?: 'http' | 'sse';
593
+ /** URL for the MCP server (used with type field) */
465
594
  url?: string;
466
- /** URL for HTTP streaming transport */
595
+ /** URL for HTTP streaming transport (deprecated, use url with type: 'http') */
467
596
  httpUrl?: string;
468
597
  /** Custom headers for HTTP transports */
469
598
  headers?: Record<string, string>;
@@ -480,6 +609,38 @@ interface MCPServerConfig {
480
609
  * MCP Servers configuration map
481
610
  */
482
611
  type MCPServersConfig = Record<string, MCPServerConfig>;
612
+ /**
613
+ * Tools configuration for Gemini CLI settings.json
614
+ * Used to configure custom tool discovery and execution commands
615
+ */
616
+ interface ToolsConfig {
617
+ /**
618
+ * Command to discover available tools
619
+ * @example '"node" "/path/to/discover-tools.cjs"'
620
+ */
621
+ discoveryCommand?: string;
622
+ /**
623
+ * Command to call/execute a tool
624
+ * @example '"node" "/path/to/call-tool.cjs"'
625
+ */
626
+ callCommand?: string;
627
+ /**
628
+ * Enable hooks for tool execution
629
+ * Set to true when using hooks configuration
630
+ */
631
+ enableHooks?: boolean;
632
+ }
633
+ /**
634
+ * Context configuration for Gemini CLI settings.json
635
+ * Used to configure context file settings
636
+ */
637
+ interface ContextConfig {
638
+ /**
639
+ * Name of the context file (e.g., 'AOE.md')
640
+ * Gemini CLI will look for this file in the working directory
641
+ */
642
+ fileName?: string;
643
+ }
483
644
  /**
484
645
  * Options for GeminiStreamClient
485
646
  */
@@ -578,6 +739,49 @@ interface GeminiStreamOptions {
578
739
  * @example '/path/to/session-2025-01-01T12-00-abc123.json'
579
740
  */
580
741
  resumeSessionFilePath?: string;
742
+ /**
743
+ * Custom logger implementation
744
+ * If not provided, uses console with [GeminiStreamClient] prefix
745
+ * Set to silentLogger to disable all logging
746
+ *
747
+ * @example
748
+ * ```typescript
749
+ * import { silentLogger, GeminiStreamClient } from '@google/gemini-cli-sdk';
750
+ *
751
+ * const client = new GeminiStreamClient({
752
+ * logger: silentLogger, // Disable all logging
753
+ * });
754
+ * ```
755
+ */
756
+ logger?: Logger;
757
+ /**
758
+ * Tools configuration for Gemini CLI
759
+ * Configures custom tool discovery and execution commands
760
+ * Written to settings.json tools field
761
+ *
762
+ * @example
763
+ * ```typescript
764
+ * tools: {
765
+ * discoveryCommand: '"node" "/path/to/discover-tools.cjs"',
766
+ * callCommand: '"node" "/path/to/call-tool.cjs"',
767
+ * enableHooks: true,
768
+ * }
769
+ * ```
770
+ */
771
+ tools?: ToolsConfig;
772
+ /**
773
+ * Context configuration for Gemini CLI
774
+ * Configures context file settings
775
+ * Written to settings.json context field
776
+ *
777
+ * @example
778
+ * ```typescript
779
+ * context: {
780
+ * fileName: 'AOE.md',
781
+ * }
782
+ * ```
783
+ */
784
+ context?: ContextConfig;
581
785
  }
582
786
 
583
787
  /**
@@ -742,6 +946,7 @@ declare class GeminiStreamClient extends EventEmitter$1 {
742
946
  private initEvent;
743
947
  private initTimeout;
744
948
  private tempSettingsPath;
949
+ private logger;
745
950
  constructor(options: GeminiStreamOptions);
746
951
  /**
747
952
  * Start the Gemini CLI process
@@ -807,6 +1012,9 @@ declare class GeminiStreamClient extends EventEmitter$1 {
807
1012
  * Note: Gemini CLI does not support --settings-file parameter.
808
1013
  * Instead, it loads settings from GEMINI_CONFIG_DIR/settings.json
809
1014
  * where GEMINI_CONFIG_DIR is set via environment variable.
1015
+ *
1016
+ * This method merges with existing settings.json if present, preserving
1017
+ * any configuration written by the host application (e.g., tools.discoveryCommand).
810
1018
  */
811
1019
  private createTempSettings;
812
1020
  /**
@@ -896,4 +1104,4 @@ declare function formatDuration(ms: number): string;
896
1104
  */
897
1105
  declare function formatTokens(tokens: number): string;
898
1106
 
899
- export { type ControlInputMessage, type ControlSubtype, type ErrorEvent, ExitCode, GeminiClient, type GeminiOptions, GeminiSDKError, GeminiStreamClient, type GeminiStreamOptions, type HooksConfiguration, type InitEvent, type InterruptControl, type JsonInputMessage, JsonInputMessageType, type JsonStreamEvent, JsonStreamEventType, type MCPServerConfig, type MCPServersConfig, type MessageEvent, ProcessStatus, type QueryResult, type ResultEvent, type ResumeSessionControl, type StreamStats, type ThoughtEvent, type ToolPermissionDecision, type ToolPermissionRequest, type ToolResultEvent, type ToolUseEvent, type TruncateHistoryControl, type UserInputMessage, findGeminiCLI, formatDuration, formatTokens, getApiKey, query, validateApiKey, validateModel };
1107
+ export { type ContextConfig, type ControlInputMessage, type ControlSubtype, type ErrorEvent, ExitCode, GeminiClient, type GeminiOptions, GeminiSDKError, GeminiStreamClient, type GeminiStreamOptions, type HooksConfiguration, type InitEvent, type InterruptControl, type JsonInputMessage, JsonInputMessageType, type JsonStreamEvent, JsonStreamEventType, LogLevel, type Logger, type LoggerOptions, type MCPServerConfig, type MCPServersConfig, type MessageEvent, ProcessStatus, type QueryResult, type ResultEvent, type ResumeSessionControl, SDKLogger, type StreamStats, type ThoughtEvent, type ToolPermissionDecision, type ToolPermissionRequest, type ToolResultEvent, type ToolUseEvent, type ToolsConfig, type TruncateHistoryControl, type UserInputMessage, createLogger, findGeminiCLI, formatDuration, formatTokens, getApiKey, query, sdkLogger, silentLogger, validateApiKey, validateModel };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,118 @@
1
1
  import { EventEmitter } from 'events';
2
2
  import { EventEmitter as EventEmitter$1 } from 'node:events';
3
3
 
4
+ /**
5
+ * Logger utility for Gemini CLI SDK
6
+ *
7
+ * Provides a configurable logging interface that can be customized by SDK consumers.
8
+ * By default, logs go to console. Users can provide their own logger implementation.
9
+ */
10
+ /**
11
+ * Log level enumeration
12
+ */
13
+ declare enum LogLevel {
14
+ DEBUG = 0,
15
+ INFO = 1,
16
+ WARN = 2,
17
+ ERROR = 3,
18
+ SILENT = 4
19
+ }
20
+ /**
21
+ * Logger interface that SDK consumers can implement
22
+ */
23
+ interface Logger {
24
+ debug(message: string, ...args: unknown[]): void;
25
+ info(message: string, ...args: unknown[]): void;
26
+ warn(message: string, ...args: unknown[]): void;
27
+ error(message: string, ...args: unknown[]): void;
28
+ }
29
+ /**
30
+ * Logger configuration options
31
+ */
32
+ interface LoggerOptions {
33
+ /** Custom logger implementation */
34
+ logger?: Logger;
35
+ /** Minimum log level to output (default: INFO, or DEBUG if debug=true) */
36
+ level?: LogLevel;
37
+ /** Prefix for all log messages (e.g., '[GeminiSDK]') */
38
+ prefix?: string;
39
+ }
40
+ /**
41
+ * Silent logger that outputs nothing
42
+ */
43
+ declare const silentLogger: Logger;
44
+ /**
45
+ * SDK Logger class
46
+ *
47
+ * Wraps a logger implementation with level filtering and prefix support.
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * // Use default console logger
52
+ * const logger = new SDKLogger({ level: LogLevel.DEBUG });
53
+ *
54
+ * // Use custom logger
55
+ * const logger = new SDKLogger({
56
+ * logger: myCustomLogger,
57
+ * prefix: '[MyApp]',
58
+ * });
59
+ *
60
+ * logger.debug('Debug message');
61
+ * logger.error('Error occurred', { details: '...' });
62
+ * ```
63
+ */
64
+ declare class SDKLogger implements Logger {
65
+ private logger;
66
+ private level;
67
+ private prefix;
68
+ constructor(options?: LoggerOptions);
69
+ /**
70
+ * Update logger configuration
71
+ */
72
+ configure(options: Partial<LoggerOptions>): void;
73
+ /**
74
+ * Set log level
75
+ */
76
+ setLevel(level: LogLevel): void;
77
+ /**
78
+ * Set custom logger implementation
79
+ */
80
+ setLogger(logger: Logger): void;
81
+ private formatMessage;
82
+ debug(message: string, ...args: unknown[]): void;
83
+ info(message: string, ...args: unknown[]): void;
84
+ warn(message: string, ...args: unknown[]): void;
85
+ error(message: string, ...args: unknown[]): void;
86
+ }
87
+ /**
88
+ * Global SDK logger instance
89
+ *
90
+ * Used internally by SDK components. Can be configured by SDK consumers.
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * import { sdkLogger, LogLevel } from '@google/gemini-cli-sdk';
95
+ *
96
+ * // Configure global logger
97
+ * sdkLogger.setLevel(LogLevel.DEBUG);
98
+ * sdkLogger.setLogger(myCustomLogger);
99
+ * ```
100
+ */
101
+ declare const sdkLogger: SDKLogger;
102
+ /**
103
+ * Create a component-specific logger
104
+ *
105
+ * @param component - Component name for the prefix (e.g., 'GeminiStreamClient')
106
+ * @param options - Logger options
107
+ */
108
+ declare function createLogger(component: string, options?: LoggerOptions): SDKLogger;
109
+
4
110
  /**
5
111
  * Type definitions for Gemini CLI SDK
6
112
  *
7
113
  * Based on Gemini CLI v0.21.0+ interface specification
8
114
  */
115
+
9
116
  /**
10
117
  * Gemini CLI configuration options
11
118
  */
@@ -95,6 +202,21 @@ interface GeminiOptions {
95
202
  * If not provided, falls back to Gemini CLI's built-in approval mechanism
96
203
  */
97
204
  onPermissionRequest?: (request: ToolPermissionRequest) => Promise<ToolPermissionDecision>;
205
+ /**
206
+ * Custom logger implementation
207
+ * If not provided, uses console with [GeminiSDK] prefix
208
+ * Set to silentLogger to disable all logging
209
+ *
210
+ * @example
211
+ * ```typescript
212
+ * import { silentLogger } from '@google/gemini-cli-sdk';
213
+ *
214
+ * const stream = query('Hello', {
215
+ * logger: silentLogger, // Disable all logging
216
+ * });
217
+ * ```
218
+ */
219
+ logger?: Logger;
98
220
  }
99
221
  /**
100
222
  * Tool permission request
@@ -461,9 +583,16 @@ interface MCPServerConfig {
461
583
  cwd?: string;
462
584
  /** Environment variables */
463
585
  env?: Record<string, string>;
464
- /** URL for SSE transport */
586
+ /**
587
+ * Transport type for URL-based connections
588
+ * - 'http': Streamable HTTP transport (recommended for mcp-chrome)
589
+ * - 'sse': Server-Sent Events transport
590
+ * When not specified with url, defaults to 'http'
591
+ */
592
+ type?: 'http' | 'sse';
593
+ /** URL for the MCP server (used with type field) */
465
594
  url?: string;
466
- /** URL for HTTP streaming transport */
595
+ /** URL for HTTP streaming transport (deprecated, use url with type: 'http') */
467
596
  httpUrl?: string;
468
597
  /** Custom headers for HTTP transports */
469
598
  headers?: Record<string, string>;
@@ -480,6 +609,38 @@ interface MCPServerConfig {
480
609
  * MCP Servers configuration map
481
610
  */
482
611
  type MCPServersConfig = Record<string, MCPServerConfig>;
612
+ /**
613
+ * Tools configuration for Gemini CLI settings.json
614
+ * Used to configure custom tool discovery and execution commands
615
+ */
616
+ interface ToolsConfig {
617
+ /**
618
+ * Command to discover available tools
619
+ * @example '"node" "/path/to/discover-tools.cjs"'
620
+ */
621
+ discoveryCommand?: string;
622
+ /**
623
+ * Command to call/execute a tool
624
+ * @example '"node" "/path/to/call-tool.cjs"'
625
+ */
626
+ callCommand?: string;
627
+ /**
628
+ * Enable hooks for tool execution
629
+ * Set to true when using hooks configuration
630
+ */
631
+ enableHooks?: boolean;
632
+ }
633
+ /**
634
+ * Context configuration for Gemini CLI settings.json
635
+ * Used to configure context file settings
636
+ */
637
+ interface ContextConfig {
638
+ /**
639
+ * Name of the context file (e.g., 'AOE.md')
640
+ * Gemini CLI will look for this file in the working directory
641
+ */
642
+ fileName?: string;
643
+ }
483
644
  /**
484
645
  * Options for GeminiStreamClient
485
646
  */
@@ -578,6 +739,49 @@ interface GeminiStreamOptions {
578
739
  * @example '/path/to/session-2025-01-01T12-00-abc123.json'
579
740
  */
580
741
  resumeSessionFilePath?: string;
742
+ /**
743
+ * Custom logger implementation
744
+ * If not provided, uses console with [GeminiStreamClient] prefix
745
+ * Set to silentLogger to disable all logging
746
+ *
747
+ * @example
748
+ * ```typescript
749
+ * import { silentLogger, GeminiStreamClient } from '@google/gemini-cli-sdk';
750
+ *
751
+ * const client = new GeminiStreamClient({
752
+ * logger: silentLogger, // Disable all logging
753
+ * });
754
+ * ```
755
+ */
756
+ logger?: Logger;
757
+ /**
758
+ * Tools configuration for Gemini CLI
759
+ * Configures custom tool discovery and execution commands
760
+ * Written to settings.json tools field
761
+ *
762
+ * @example
763
+ * ```typescript
764
+ * tools: {
765
+ * discoveryCommand: '"node" "/path/to/discover-tools.cjs"',
766
+ * callCommand: '"node" "/path/to/call-tool.cjs"',
767
+ * enableHooks: true,
768
+ * }
769
+ * ```
770
+ */
771
+ tools?: ToolsConfig;
772
+ /**
773
+ * Context configuration for Gemini CLI
774
+ * Configures context file settings
775
+ * Written to settings.json context field
776
+ *
777
+ * @example
778
+ * ```typescript
779
+ * context: {
780
+ * fileName: 'AOE.md',
781
+ * }
782
+ * ```
783
+ */
784
+ context?: ContextConfig;
581
785
  }
582
786
 
583
787
  /**
@@ -742,6 +946,7 @@ declare class GeminiStreamClient extends EventEmitter$1 {
742
946
  private initEvent;
743
947
  private initTimeout;
744
948
  private tempSettingsPath;
949
+ private logger;
745
950
  constructor(options: GeminiStreamOptions);
746
951
  /**
747
952
  * Start the Gemini CLI process
@@ -807,6 +1012,9 @@ declare class GeminiStreamClient extends EventEmitter$1 {
807
1012
  * Note: Gemini CLI does not support --settings-file parameter.
808
1013
  * Instead, it loads settings from GEMINI_CONFIG_DIR/settings.json
809
1014
  * where GEMINI_CONFIG_DIR is set via environment variable.
1015
+ *
1016
+ * This method merges with existing settings.json if present, preserving
1017
+ * any configuration written by the host application (e.g., tools.discoveryCommand).
810
1018
  */
811
1019
  private createTempSettings;
812
1020
  /**
@@ -896,4 +1104,4 @@ declare function formatDuration(ms: number): string;
896
1104
  */
897
1105
  declare function formatTokens(tokens: number): string;
898
1106
 
899
- export { type ControlInputMessage, type ControlSubtype, type ErrorEvent, ExitCode, GeminiClient, type GeminiOptions, GeminiSDKError, GeminiStreamClient, type GeminiStreamOptions, type HooksConfiguration, type InitEvent, type InterruptControl, type JsonInputMessage, JsonInputMessageType, type JsonStreamEvent, JsonStreamEventType, type MCPServerConfig, type MCPServersConfig, type MessageEvent, ProcessStatus, type QueryResult, type ResultEvent, type ResumeSessionControl, type StreamStats, type ThoughtEvent, type ToolPermissionDecision, type ToolPermissionRequest, type ToolResultEvent, type ToolUseEvent, type TruncateHistoryControl, type UserInputMessage, findGeminiCLI, formatDuration, formatTokens, getApiKey, query, validateApiKey, validateModel };
1107
+ export { type ContextConfig, type ControlInputMessage, type ControlSubtype, type ErrorEvent, ExitCode, GeminiClient, type GeminiOptions, GeminiSDKError, GeminiStreamClient, type GeminiStreamOptions, type HooksConfiguration, type InitEvent, type InterruptControl, type JsonInputMessage, JsonInputMessageType, type JsonStreamEvent, JsonStreamEventType, LogLevel, type Logger, type LoggerOptions, type MCPServerConfig, type MCPServersConfig, type MessageEvent, ProcessStatus, type QueryResult, type ResultEvent, type ResumeSessionControl, SDKLogger, type StreamStats, type ThoughtEvent, type ToolPermissionDecision, type ToolPermissionRequest, type ToolResultEvent, type ToolUseEvent, type ToolsConfig, type TruncateHistoryControl, type UserInputMessage, createLogger, findGeminiCLI, formatDuration, formatTokens, getApiKey, query, sdkLogger, silentLogger, validateApiKey, validateModel };