ai-sdk-provider-gemini-cli-agentic 0.1.1 → 0.1.3

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.cjs CHANGED
@@ -12,7 +12,9 @@ var zod = require('zod');
12
12
  function parseStreamJsonLine(line) {
13
13
  try {
14
14
  const event = JSON.parse(line);
15
- if (!event.type || typeof event.type !== "string") return null;
15
+ if (!event || typeof event !== "object" || !("type" in event) || typeof event.type !== "string") {
16
+ return null;
17
+ }
16
18
  return event;
17
19
  } catch {
18
20
  return null;
@@ -259,7 +261,7 @@ var GeminiCliLanguageModel = class {
259
261
  allowedMcpServerNames: providerOptions.allowedMcpServerNames ?? this.settings.allowedMcpServerNames
260
262
  };
261
263
  }
262
- buildArgs(promptText, settings = this.settings) {
264
+ buildArgs(settings = this.settings) {
263
265
  const base = resolveGeminiPath(settings.geminiPath, settings.allowNpx);
264
266
  const cmd = base.cmd;
265
267
  const args = [...base.args];
@@ -294,7 +296,7 @@ var GeminiCliLanguageModel = class {
294
296
  args.push("--resume", "latest");
295
297
  }
296
298
  }
297
- args.push(promptText);
299
+ args.push("-");
298
300
  const env = {
299
301
  ...process.env,
300
302
  ...settings.env || {}
@@ -346,21 +348,45 @@ var GeminiCliLanguageModel = class {
346
348
  schema: geminiCliProviderOptionsSchema
347
349
  });
348
350
  const effectiveSettings = this.mergeSettings(providerOptions);
349
- const { cmd, args, env, cwd, shell } = this.buildArgs(promptText, effectiveSettings);
350
- this.logger.debug(`[gemini-cli] Executing: ${cmd} ${args.slice(0, -1).join(" ")} [prompt]`);
351
+ const { cmd, args, env, cwd, shell } = this.buildArgs(effectiveSettings);
352
+ this.logger.debug(`[gemini-cli] Executing: ${cmd} ${args.join(" ")}`);
351
353
  let text = "";
352
354
  let usage = createEmptyUsage();
353
355
  let finishReason = { unified: "stop", raw: void 0 };
354
356
  const content = [];
355
357
  const toolResults = /* @__PURE__ */ new Map();
356
- const child = child_process.spawn(cmd, args, { env, cwd, shell, stdio: ["ignore", "pipe", "pipe"] });
358
+ const isWin = process.platform === "win32";
359
+ const child = child_process.spawn(cmd, args, {
360
+ env,
361
+ cwd,
362
+ shell,
363
+ stdio: ["pipe", "pipe", "pipe"],
364
+ detached: !isWin
365
+ });
366
+ const killProcessTree = (signal = "SIGTERM") => {
367
+ if (child.pid) {
368
+ if (isWin) {
369
+ child_process.spawn("taskkill", ["/pid", String(child.pid), "/T", "/F"], { stdio: "ignore" });
370
+ } else {
371
+ try {
372
+ process.kill(-child.pid, signal);
373
+ } catch {
374
+ child.kill(signal);
375
+ }
376
+ }
377
+ } else {
378
+ child.kill(signal);
379
+ }
380
+ };
381
+ child.stdin.write(promptText);
382
+ child.stdin.end();
357
383
  let onAbort;
358
384
  if (options.abortSignal) {
359
385
  if (options.abortSignal.aborted) {
360
- child.kill("SIGTERM");
386
+ killProcessTree();
361
387
  throw options.abortSignal.reason ?? new Error("Request aborted");
362
388
  }
363
- onAbort = () => child.kill("SIGTERM");
389
+ onAbort = () => killProcessTree();
364
390
  options.abortSignal.addEventListener("abort", onAbort, { once: true });
365
391
  }
366
392
  const startTime = Date.now();
@@ -478,24 +504,48 @@ var GeminiCliLanguageModel = class {
478
504
  schema: geminiCliProviderOptionsSchema
479
505
  });
480
506
  const effectiveSettings = this.mergeSettings(providerOptions);
481
- const { cmd, args, env, cwd, shell } = this.buildArgs(promptText, effectiveSettings);
482
- this.logger.debug(`[gemini-cli] Streaming: ${cmd} ${args.slice(0, -1).join(" ")} [prompt]`);
507
+ const { cmd, args, env, cwd, shell } = this.buildArgs(effectiveSettings);
508
+ this.logger.debug(`[gemini-cli] Streaming: ${cmd} ${args.join(" ")}`);
483
509
  const model = this;
484
510
  const abortSignal = options.abortSignal;
485
511
  const stream = new ReadableStream({
486
512
  start(controller) {
487
513
  const startTime = Date.now();
488
- const child = child_process.spawn(cmd, args, { env, cwd, shell, stdio: ["ignore", "pipe", "pipe"] });
514
+ const isWin = process.platform === "win32";
515
+ const child = child_process.spawn(cmd, args, {
516
+ env,
517
+ cwd,
518
+ shell,
519
+ stdio: ["pipe", "pipe", "pipe"],
520
+ detached: !isWin
521
+ });
522
+ const killProcessTree = (signal = "SIGTERM") => {
523
+ if (child.pid) {
524
+ if (isWin) {
525
+ child_process.spawn("taskkill", ["/pid", String(child.pid), "/T", "/F"], { stdio: "ignore" });
526
+ } else {
527
+ try {
528
+ process.kill(-child.pid, signal);
529
+ } catch {
530
+ child.kill(signal);
531
+ }
532
+ }
533
+ } else {
534
+ child.kill(signal);
535
+ }
536
+ };
537
+ child.stdin.write(promptText);
538
+ child.stdin.end();
489
539
  controller.enqueue({ type: "stream-start", warnings });
490
540
  let stderr = "";
491
541
  let lastUsage;
492
542
  let textId;
493
543
  let lastStatus;
494
544
  const toolResults = /* @__PURE__ */ new Map();
495
- const onAbort = () => child.kill("SIGTERM");
545
+ const onAbort = () => killProcessTree();
496
546
  if (abortSignal) {
497
547
  if (abortSignal.aborted) {
498
- child.kill("SIGTERM");
548
+ killProcessTree();
499
549
  controller.error(abortSignal.reason ?? new Error("Request aborted"));
500
550
  return;
501
551
  }
package/dist/index.js CHANGED
@@ -10,7 +10,9 @@ import { z } from 'zod';
10
10
  function parseStreamJsonLine(line) {
11
11
  try {
12
12
  const event = JSON.parse(line);
13
- if (!event.type || typeof event.type !== "string") return null;
13
+ if (!event || typeof event !== "object" || !("type" in event) || typeof event.type !== "string") {
14
+ return null;
15
+ }
14
16
  return event;
15
17
  } catch {
16
18
  return null;
@@ -257,7 +259,7 @@ var GeminiCliLanguageModel = class {
257
259
  allowedMcpServerNames: providerOptions.allowedMcpServerNames ?? this.settings.allowedMcpServerNames
258
260
  };
259
261
  }
260
- buildArgs(promptText, settings = this.settings) {
262
+ buildArgs(settings = this.settings) {
261
263
  const base = resolveGeminiPath(settings.geminiPath, settings.allowNpx);
262
264
  const cmd = base.cmd;
263
265
  const args = [...base.args];
@@ -292,7 +294,7 @@ var GeminiCliLanguageModel = class {
292
294
  args.push("--resume", "latest");
293
295
  }
294
296
  }
295
- args.push(promptText);
297
+ args.push("-");
296
298
  const env = {
297
299
  ...process.env,
298
300
  ...settings.env || {}
@@ -344,21 +346,45 @@ var GeminiCliLanguageModel = class {
344
346
  schema: geminiCliProviderOptionsSchema
345
347
  });
346
348
  const effectiveSettings = this.mergeSettings(providerOptions);
347
- const { cmd, args, env, cwd, shell } = this.buildArgs(promptText, effectiveSettings);
348
- this.logger.debug(`[gemini-cli] Executing: ${cmd} ${args.slice(0, -1).join(" ")} [prompt]`);
349
+ const { cmd, args, env, cwd, shell } = this.buildArgs(effectiveSettings);
350
+ this.logger.debug(`[gemini-cli] Executing: ${cmd} ${args.join(" ")}`);
349
351
  let text = "";
350
352
  let usage = createEmptyUsage();
351
353
  let finishReason = { unified: "stop", raw: void 0 };
352
354
  const content = [];
353
355
  const toolResults = /* @__PURE__ */ new Map();
354
- const child = spawn(cmd, args, { env, cwd, shell, stdio: ["ignore", "pipe", "pipe"] });
356
+ const isWin = process.platform === "win32";
357
+ const child = spawn(cmd, args, {
358
+ env,
359
+ cwd,
360
+ shell,
361
+ stdio: ["pipe", "pipe", "pipe"],
362
+ detached: !isWin
363
+ });
364
+ const killProcessTree = (signal = "SIGTERM") => {
365
+ if (child.pid) {
366
+ if (isWin) {
367
+ spawn("taskkill", ["/pid", String(child.pid), "/T", "/F"], { stdio: "ignore" });
368
+ } else {
369
+ try {
370
+ process.kill(-child.pid, signal);
371
+ } catch {
372
+ child.kill(signal);
373
+ }
374
+ }
375
+ } else {
376
+ child.kill(signal);
377
+ }
378
+ };
379
+ child.stdin.write(promptText);
380
+ child.stdin.end();
355
381
  let onAbort;
356
382
  if (options.abortSignal) {
357
383
  if (options.abortSignal.aborted) {
358
- child.kill("SIGTERM");
384
+ killProcessTree();
359
385
  throw options.abortSignal.reason ?? new Error("Request aborted");
360
386
  }
361
- onAbort = () => child.kill("SIGTERM");
387
+ onAbort = () => killProcessTree();
362
388
  options.abortSignal.addEventListener("abort", onAbort, { once: true });
363
389
  }
364
390
  const startTime = Date.now();
@@ -476,24 +502,48 @@ var GeminiCliLanguageModel = class {
476
502
  schema: geminiCliProviderOptionsSchema
477
503
  });
478
504
  const effectiveSettings = this.mergeSettings(providerOptions);
479
- const { cmd, args, env, cwd, shell } = this.buildArgs(promptText, effectiveSettings);
480
- this.logger.debug(`[gemini-cli] Streaming: ${cmd} ${args.slice(0, -1).join(" ")} [prompt]`);
505
+ const { cmd, args, env, cwd, shell } = this.buildArgs(effectiveSettings);
506
+ this.logger.debug(`[gemini-cli] Streaming: ${cmd} ${args.join(" ")}`);
481
507
  const model = this;
482
508
  const abortSignal = options.abortSignal;
483
509
  const stream = new ReadableStream({
484
510
  start(controller) {
485
511
  const startTime = Date.now();
486
- const child = spawn(cmd, args, { env, cwd, shell, stdio: ["ignore", "pipe", "pipe"] });
512
+ const isWin = process.platform === "win32";
513
+ const child = spawn(cmd, args, {
514
+ env,
515
+ cwd,
516
+ shell,
517
+ stdio: ["pipe", "pipe", "pipe"],
518
+ detached: !isWin
519
+ });
520
+ const killProcessTree = (signal = "SIGTERM") => {
521
+ if (child.pid) {
522
+ if (isWin) {
523
+ spawn("taskkill", ["/pid", String(child.pid), "/T", "/F"], { stdio: "ignore" });
524
+ } else {
525
+ try {
526
+ process.kill(-child.pid, signal);
527
+ } catch {
528
+ child.kill(signal);
529
+ }
530
+ }
531
+ } else {
532
+ child.kill(signal);
533
+ }
534
+ };
535
+ child.stdin.write(promptText);
536
+ child.stdin.end();
487
537
  controller.enqueue({ type: "stream-start", warnings });
488
538
  let stderr = "";
489
539
  let lastUsage;
490
540
  let textId;
491
541
  let lastStatus;
492
542
  const toolResults = /* @__PURE__ */ new Map();
493
- const onAbort = () => child.kill("SIGTERM");
543
+ const onAbort = () => killProcessTree();
494
544
  if (abortSignal) {
495
545
  if (abortSignal.aborted) {
496
- child.kill("SIGTERM");
546
+ killProcessTree();
497
547
  controller.error(abortSignal.reason ?? new Error("Request aborted"));
498
548
  return;
499
549
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-sdk-provider-gemini-cli-agentic",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "AI SDK v6 provider for Google Gemini CLI agentic mode",
5
5
  "keywords": [
6
6
  "ai-sdk",