@ketd/gemini-cli-sdk 0.3.4 → 0.3.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.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
@@ -578,6 +700,21 @@ interface GeminiStreamOptions {
578
700
  * @example '/path/to/session-2025-01-01T12-00-abc123.json'
579
701
  */
580
702
  resumeSessionFilePath?: string;
703
+ /**
704
+ * Custom logger implementation
705
+ * If not provided, uses console with [GeminiStreamClient] prefix
706
+ * Set to silentLogger to disable all logging
707
+ *
708
+ * @example
709
+ * ```typescript
710
+ * import { silentLogger, GeminiStreamClient } from '@google/gemini-cli-sdk';
711
+ *
712
+ * const client = new GeminiStreamClient({
713
+ * logger: silentLogger, // Disable all logging
714
+ * });
715
+ * ```
716
+ */
717
+ logger?: Logger;
581
718
  }
582
719
 
583
720
  /**
@@ -742,6 +879,7 @@ declare class GeminiStreamClient extends EventEmitter$1 {
742
879
  private initEvent;
743
880
  private initTimeout;
744
881
  private tempSettingsPath;
882
+ private logger;
745
883
  constructor(options: GeminiStreamOptions);
746
884
  /**
747
885
  * Start the Gemini CLI process
@@ -896,4 +1034,4 @@ declare function formatDuration(ms: number): string;
896
1034
  */
897
1035
  declare function formatTokens(tokens: number): string;
898
1036
 
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 };
1037
+ 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, 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 TruncateHistoryControl, type UserInputMessage, createLogger, findGeminiCLI, formatDuration, formatTokens, getApiKey, query, sdkLogger, silentLogger, validateApiKey, validateModel };
package/dist/index.js CHANGED
@@ -53,6 +53,101 @@ var JsonInputMessageType = /* @__PURE__ */ ((JsonInputMessageType2) => {
53
53
  return JsonInputMessageType2;
54
54
  })(JsonInputMessageType || {});
55
55
 
56
+ // src/logger.ts
57
+ var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
58
+ LogLevel2[LogLevel2["DEBUG"] = 0] = "DEBUG";
59
+ LogLevel2[LogLevel2["INFO"] = 1] = "INFO";
60
+ LogLevel2[LogLevel2["WARN"] = 2] = "WARN";
61
+ LogLevel2[LogLevel2["ERROR"] = 3] = "ERROR";
62
+ LogLevel2[LogLevel2["SILENT"] = 4] = "SILENT";
63
+ return LogLevel2;
64
+ })(LogLevel || {});
65
+ var consoleLogger = {
66
+ debug: (message, ...args) => console.log(message, ...args),
67
+ info: (message, ...args) => console.log(message, ...args),
68
+ warn: (message, ...args) => console.warn(message, ...args),
69
+ error: (message, ...args) => console.error(message, ...args)
70
+ };
71
+ var silentLogger = {
72
+ debug: () => {
73
+ },
74
+ info: () => {
75
+ },
76
+ warn: () => {
77
+ },
78
+ error: () => {
79
+ }
80
+ };
81
+ var SDKLogger = class {
82
+ logger;
83
+ level;
84
+ prefix;
85
+ constructor(options = {}) {
86
+ this.logger = options.logger || consoleLogger;
87
+ this.level = options.level ?? 1 /* INFO */;
88
+ this.prefix = options.prefix || "";
89
+ }
90
+ /**
91
+ * Update logger configuration
92
+ */
93
+ configure(options) {
94
+ if (options.logger !== void 0) {
95
+ this.logger = options.logger;
96
+ }
97
+ if (options.level !== void 0) {
98
+ this.level = options.level;
99
+ }
100
+ if (options.prefix !== void 0) {
101
+ this.prefix = options.prefix;
102
+ }
103
+ }
104
+ /**
105
+ * Set log level
106
+ */
107
+ setLevel(level) {
108
+ this.level = level;
109
+ }
110
+ /**
111
+ * Set custom logger implementation
112
+ */
113
+ setLogger(logger) {
114
+ this.logger = logger;
115
+ }
116
+ formatMessage(message) {
117
+ return this.prefix ? `${this.prefix} ${message}` : message;
118
+ }
119
+ debug(message, ...args) {
120
+ if (this.level <= 0 /* DEBUG */) {
121
+ this.logger.debug(this.formatMessage(message), ...args);
122
+ }
123
+ }
124
+ info(message, ...args) {
125
+ if (this.level <= 1 /* INFO */) {
126
+ this.logger.info(this.formatMessage(message), ...args);
127
+ }
128
+ }
129
+ warn(message, ...args) {
130
+ if (this.level <= 2 /* WARN */) {
131
+ this.logger.warn(this.formatMessage(message), ...args);
132
+ }
133
+ }
134
+ error(message, ...args) {
135
+ if (this.level <= 3 /* ERROR */) {
136
+ this.logger.error(this.formatMessage(message), ...args);
137
+ }
138
+ }
139
+ };
140
+ var sdkLogger = new SDKLogger({
141
+ prefix: "[GeminiSDK]",
142
+ level: 1 /* INFO */
143
+ });
144
+ function createLogger(component, options = {}) {
145
+ return new SDKLogger({
146
+ ...options,
147
+ prefix: options.prefix || `[${component}]`
148
+ });
149
+ }
150
+
56
151
  // src/query.ts
57
152
  function buildCliArgs(options, prompt) {
58
153
  const args = [];
@@ -84,7 +179,7 @@ function buildCliArgs(options, prompt) {
84
179
  args.push(prompt);
85
180
  return args;
86
181
  }
87
- function buildEnv(options) {
182
+ function buildEnv(options, logger) {
88
183
  const env = {
89
184
  ...process.env,
90
185
  ...options.env
@@ -95,25 +190,19 @@ function buildEnv(options) {
95
190
  if (useVertexAI) {
96
191
  env.GOOGLE_API_KEY = options.apiKey;
97
192
  env.GOOGLE_GENAI_USE_VERTEXAI = "true";
98
- if (options.debug) {
99
- console.log("[SDK] Vertex AI mode: Setting GOOGLE_API_KEY:", options.apiKey.substring(0, 10) + "...");
100
- }
193
+ logger.debug("Vertex AI mode: Setting GOOGLE_API_KEY:", options.apiKey.substring(0, 10) + "...");
101
194
  } else {
102
195
  env.GEMINI_API_KEY = options.apiKey;
103
- if (options.debug) {
104
- console.log("[SDK] Standard mode: Setting GEMINI_API_KEY:", options.apiKey.substring(0, 10) + "...");
105
- }
196
+ logger.debug("Standard mode: Setting GEMINI_API_KEY:", options.apiKey.substring(0, 10) + "...");
106
197
  }
107
198
  }
108
199
  if (!useVertexAI && env.GOOGLE_API_KEY) {
109
200
  delete env.GOOGLE_API_KEY;
110
- if (options.debug) {
111
- console.log("[SDK] Removed GOOGLE_API_KEY from environment (not using Vertex AI)");
112
- }
201
+ logger.debug("Removed GOOGLE_API_KEY from environment (not using Vertex AI)");
113
202
  }
114
203
  if (options.debug) {
115
204
  env.DEBUG = "1";
116
- console.log("[SDK] Environment variables set:", {
205
+ logger.debug("Environment variables set:", {
117
206
  GEMINI_API_KEY: env.GEMINI_API_KEY ? "***" : void 0,
118
207
  GOOGLE_API_KEY: env.GOOGLE_API_KEY ? "***" : void 0,
119
208
  GOOGLE_GENAI_USE_VERTEXAI: env.GOOGLE_GENAI_USE_VERTEXAI,
@@ -123,6 +212,10 @@ function buildEnv(options) {
123
212
  return env;
124
213
  }
125
214
  async function* query(prompt, options) {
215
+ const logger = createLogger("GeminiSDK", {
216
+ logger: options.logger,
217
+ level: options.debug ? 0 /* DEBUG */ : 1 /* INFO */
218
+ });
126
219
  if (!options.pathToGeminiCLI) {
127
220
  throw new GeminiSDKError("pathToGeminiCLI is required");
128
221
  }
@@ -132,7 +225,7 @@ async function* query(prompt, options) {
132
225
  );
133
226
  }
134
227
  const args = buildCliArgs(options, prompt);
135
- const env = buildEnv(options);
228
+ const env = buildEnv(options, logger);
136
229
  const cwd = options.cwd || process.cwd();
137
230
  const nodeExecutable = options.pathToNode || "node";
138
231
  let geminiProcess;
@@ -148,9 +241,7 @@ async function* query(prompt, options) {
148
241
  const stderrChunks = [];
149
242
  geminiProcess.stderr?.on("data", (data) => {
150
243
  stderrChunks.push(data);
151
- if (options.debug) {
152
- console.error("[Gemini CLI stderr]:", data.toString());
153
- }
244
+ logger.error("stderr:", data.toString());
154
245
  });
155
246
  let timeoutId;
156
247
  if (options.timeout) {
@@ -170,10 +261,8 @@ async function* query(prompt, options) {
170
261
  hasYieldedEvents = true;
171
262
  yield event;
172
263
  } catch (parseError) {
173
- if (options.debug) {
174
- console.error("[Gemini SDK] Failed to parse JSON line:", line);
175
- console.error("[Gemini SDK] Parse error:", parseError);
176
- }
264
+ logger.debug("Failed to parse JSON line:", line);
265
+ logger.debug("Parse error:", parseError);
177
266
  }
178
267
  }
179
268
  } catch (error) {
@@ -376,6 +465,10 @@ var GeminiStreamClient = class extends EventEmitter {
376
465
  constructor(options) {
377
466
  super();
378
467
  this.options = options;
468
+ this.logger = createLogger("GeminiStreamClient", {
469
+ logger: options.logger,
470
+ level: options.debug ? 0 /* DEBUG */ : 1 /* INFO */
471
+ });
379
472
  if (!options.pathToGeminiCLI) {
380
473
  throw new GeminiSDKError("pathToGeminiCLI is required");
381
474
  }
@@ -390,6 +483,7 @@ var GeminiStreamClient = class extends EventEmitter {
390
483
  initEvent = null;
391
484
  initTimeout = null;
392
485
  tempSettingsPath = null;
486
+ logger;
393
487
  /**
394
488
  * Start the Gemini CLI process
395
489
  */
@@ -433,9 +527,11 @@ var GeminiStreamClient = class extends EventEmitter {
433
527
  }
434
528
  if (this.process.stderr) {
435
529
  this.process.stderr.on("data", (chunk) => {
436
- if (this.options.debug) {
437
- console.error("[GeminiStreamClient] stderr:", chunk.toString());
530
+ const message = chunk.toString().trim();
531
+ if (!message || message.includes("Flushing log events")) {
532
+ return;
438
533
  }
534
+ this.logger.error("stderr:", message);
439
535
  });
440
536
  }
441
537
  this.emit("started");
@@ -571,11 +667,9 @@ var GeminiStreamClient = class extends EventEmitter {
571
667
  if (this.tempSettingsPath) {
572
668
  try {
573
669
  fs.unlinkSync(this.tempSettingsPath);
574
- if (this.options.debug) {
575
- console.log("[GeminiStreamClient] Cleaned up temp settings:", this.tempSettingsPath);
576
- }
670
+ this.logger.debug("Cleaned up temp settings:", this.tempSettingsPath);
577
671
  } catch (error) {
578
- console.error("[GeminiStreamClient] Failed to clean up temp settings:", error);
672
+ this.logger.error("Failed to clean up temp settings:", error);
579
673
  }
580
674
  this.tempSettingsPath = null;
581
675
  }
@@ -620,9 +714,7 @@ var GeminiStreamClient = class extends EventEmitter {
620
714
  }
621
715
  if (!fs.existsSync(geminiConfigDir)) {
622
716
  fs.mkdirSync(geminiConfigDir, { recursive: true });
623
- if (this.options.debug) {
624
- console.log("[GeminiStreamClient] Created config directory:", geminiConfigDir);
625
- }
717
+ this.logger.debug("Created config directory:", geminiConfigDir);
626
718
  }
627
719
  this.tempSettingsPath = path2.join(geminiConfigDir, "settings.json");
628
720
  const settings = {};
@@ -637,10 +729,8 @@ var GeminiStreamClient = class extends EventEmitter {
637
729
  }
638
730
  try {
639
731
  fs.writeFileSync(this.tempSettingsPath, JSON.stringify(settings, null, 2), "utf-8");
640
- if (this.options.debug) {
641
- console.log("[GeminiStreamClient] Wrote settings to:", this.tempSettingsPath);
642
- console.log("[GeminiStreamClient] Settings content:", JSON.stringify(settings, null, 2));
643
- }
732
+ this.logger.debug("Wrote settings to:", this.tempSettingsPath);
733
+ this.logger.debug("Settings content:", JSON.stringify(settings, null, 2));
644
734
  } catch (error) {
645
735
  throw new GeminiSDKError(`Failed to write settings file: ${error}`);
646
736
  }
@@ -658,9 +748,7 @@ var GeminiStreamClient = class extends EventEmitter {
658
748
  ];
659
749
  if (this.options.resumeSessionFilePath) {
660
750
  args.push("--resume-from-file", this.options.resumeSessionFilePath);
661
- if (this.options.debug) {
662
- console.log("[GeminiStreamClient] Resuming from session file:", this.options.resumeSessionFilePath);
663
- }
751
+ this.logger.debug("Resuming from session file:", this.options.resumeSessionFilePath);
664
752
  }
665
753
  if (this.options.model) {
666
754
  args.push("--model", this.options.model);
@@ -683,28 +771,20 @@ var GeminiStreamClient = class extends EventEmitter {
683
771
  };
684
772
  if (this.options.apiKey) {
685
773
  const useVertexAI = this.options.env?.GOOGLE_GENAI_USE_VERTEXAI === "true";
686
- if (this.options.debug) {
687
- console.log("[GeminiStreamClient] buildEnv() - API Key prefix:", this.options.apiKey.substring(0, 3));
688
- console.log("[GeminiStreamClient] buildEnv() - GOOGLE_GENAI_USE_VERTEXAI:", this.options.env?.GOOGLE_GENAI_USE_VERTEXAI);
689
- console.log("[GeminiStreamClient] buildEnv() - useVertexAI:", useVertexAI);
690
- }
774
+ this.logger.debug("buildEnv() - API Key prefix:", this.options.apiKey.substring(0, 3));
775
+ this.logger.debug("buildEnv() - GOOGLE_GENAI_USE_VERTEXAI:", this.options.env?.GOOGLE_GENAI_USE_VERTEXAI);
776
+ this.logger.debug("buildEnv() - useVertexAI:", useVertexAI);
691
777
  if (useVertexAI) {
692
778
  env.GOOGLE_API_KEY = this.options.apiKey;
693
- if (this.options.debug) {
694
- console.log("[GeminiStreamClient] buildEnv() - Setting GOOGLE_API_KEY for Vertex AI");
695
- }
779
+ this.logger.debug("buildEnv() - Setting GOOGLE_API_KEY for Vertex AI");
696
780
  } else {
697
781
  env.GEMINI_API_KEY = this.options.apiKey;
698
- if (this.options.debug) {
699
- console.log("[GeminiStreamClient] buildEnv() - Setting GEMINI_API_KEY for AI Studio");
700
- }
782
+ this.logger.debug("buildEnv() - Setting GEMINI_API_KEY for AI Studio");
701
783
  }
702
784
  }
703
- if (this.options.debug) {
704
- console.log("[GeminiStreamClient] buildEnv() - Final env has GOOGLE_API_KEY:", !!env.GOOGLE_API_KEY);
705
- console.log("[GeminiStreamClient] buildEnv() - Final env has GEMINI_API_KEY:", !!env.GEMINI_API_KEY);
706
- console.log("[GeminiStreamClient] buildEnv() - Final env GOOGLE_GENAI_USE_VERTEXAI:", env.GOOGLE_GENAI_USE_VERTEXAI);
707
- }
785
+ this.logger.debug("buildEnv() - Final env has GOOGLE_API_KEY:", !!env.GOOGLE_API_KEY);
786
+ this.logger.debug("buildEnv() - Final env has GEMINI_API_KEY:", !!env.GEMINI_API_KEY);
787
+ this.logger.debug("buildEnv() - Final env GOOGLE_GENAI_USE_VERTEXAI:", env.GOOGLE_GENAI_USE_VERTEXAI);
708
788
  return env;
709
789
  }
710
790
  /**
@@ -715,19 +795,15 @@ var GeminiStreamClient = class extends EventEmitter {
715
795
  throw new GeminiSDKError("stdin stream not available");
716
796
  }
717
797
  const json = JSON.stringify(message);
718
- if (this.options.debug) {
719
- console.log("[GeminiStreamClient] Writing message to stdin:", json.substring(0, 100));
720
- }
798
+ this.logger.debug("Writing message to stdin:", json.substring(0, 100));
721
799
  const success = this.stdinStream.write(json + "\n", (error) => {
722
800
  if (error) {
723
- console.error("[GeminiStreamClient] Write error:", error);
724
- } else if (this.options.debug) {
725
- console.log("[GeminiStreamClient] Write callback: message flushed to stdin");
801
+ this.logger.error("Write error:", error);
802
+ } else {
803
+ this.logger.debug("Write callback: message flushed to stdin");
726
804
  }
727
805
  });
728
- if (this.options.debug) {
729
- console.log("[GeminiStreamClient] Write success:", success, "Stream writable:", this.stdinStream.writable);
730
- }
806
+ this.logger.debug("Write success:", success, "Stream writable:", this.stdinStream.writable);
731
807
  }
732
808
  /**
733
809
  * Start reading JSONL events from stdout
@@ -742,23 +818,17 @@ var GeminiStreamClient = class extends EventEmitter {
742
818
  return;
743
819
  }
744
820
  if (trimmed.startsWith("[")) {
745
- if (this.options.debug) {
746
- console.log("[GeminiStreamClient] Skipping debug output:", trimmed.substring(0, 100));
747
- }
748
821
  return;
749
822
  }
750
823
  try {
751
824
  const event = JSON.parse(trimmed);
752
825
  this.handleEvent(event);
753
826
  } catch (error) {
754
- console.error("[GeminiStreamClient] Failed to parse JSON:", trimmed);
755
- console.error("[GeminiStreamClient] Error:", error);
827
+ this.logger.error("Failed to parse JSON:", trimmed);
828
+ this.logger.error("Error:", error);
756
829
  }
757
830
  });
758
831
  this.readlineInterface.on("close", () => {
759
- if (this.options.debug) {
760
- console.log("[GeminiStreamClient] readline interface closed");
761
- }
762
832
  });
763
833
  }
764
834
  /**
@@ -800,9 +870,7 @@ var GeminiStreamClient = class extends EventEmitter {
800
870
  * Handle process exit
801
871
  */
802
872
  handleProcessExit(code, signal) {
803
- if (this.options.debug) {
804
- console.log("[GeminiStreamClient] Process exited:", { code, signal });
805
- }
873
+ this.logger.debug("Process exited:", { code, signal });
806
874
  if (code !== 0 && code !== null) {
807
875
  this.status = "error" /* ERROR */;
808
876
  this.emit("error", new GeminiSDKError(`Process exited with code ${code}`, code));
@@ -821,7 +889,7 @@ var GeminiStreamClient = class extends EventEmitter {
821
889
  * Handle process error
822
890
  */
823
891
  handleProcessError(error) {
824
- console.error("[GeminiStreamClient] Process error:", error);
892
+ this.logger.error("Process error:", error);
825
893
  this.status = "error" /* ERROR */;
826
894
  this.emit("error", error);
827
895
  }
@@ -880,7 +948,7 @@ function validateModel(model) {
880
948
  return defaultModel;
881
949
  }
882
950
  if (!model.startsWith("gemini-")) {
883
- console.warn(`Warning: Model name "${model}" does not start with "gemini-"`);
951
+ sdkLogger.warn(`Warning: Model name "${model}" does not start with "gemini-"`);
884
952
  }
885
953
  return model;
886
954
  }
@@ -899,6 +967,6 @@ function formatTokens(tokens) {
899
967
  return tokens.toLocaleString();
900
968
  }
901
969
 
902
- export { ExitCode, GeminiClient, GeminiSDKError, GeminiStreamClient, JsonInputMessageType, JsonStreamEventType, ProcessStatus, findGeminiCLI, formatDuration, formatTokens, getApiKey, query, validateApiKey, validateModel };
970
+ export { ExitCode, GeminiClient, GeminiSDKError, GeminiStreamClient, JsonInputMessageType, JsonStreamEventType, LogLevel, ProcessStatus, SDKLogger, createLogger, findGeminiCLI, formatDuration, formatTokens, getApiKey, query, sdkLogger, silentLogger, validateApiKey, validateModel };
903
971
  //# sourceMappingURL=index.js.map
904
972
  //# sourceMappingURL=index.js.map