ai-sdk-provider-gemini-cli-agentic 0.1.2 → 0.1.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.cjs CHANGED
@@ -2,17 +2,24 @@
2
2
 
3
3
  var provider = require('@ai-sdk/provider');
4
4
  var child_process = require('child_process');
5
+ var treeKill = require('tree-kill');
5
6
  var crypto = require('crypto');
6
7
  var providerUtils = require('@ai-sdk/provider-utils');
7
8
  var zod = require('zod');
8
9
 
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ var treeKill__default = /*#__PURE__*/_interopDefault(treeKill);
13
+
9
14
  // src/gemini-cli-provider.ts
10
15
 
11
16
  // src/stream-parser.ts
12
17
  function parseStreamJsonLine(line) {
13
18
  try {
14
19
  const event = JSON.parse(line);
15
- if (!event.type || typeof event.type !== "string") return null;
20
+ if (!event || typeof event !== "object" || !("type" in event) || typeof event.type !== "string") {
21
+ return null;
22
+ }
16
23
  return event;
17
24
  } catch {
18
25
  return null;
@@ -353,16 +360,26 @@ var GeminiCliLanguageModel = class {
353
360
  let finishReason = { unified: "stop", raw: void 0 };
354
361
  const content = [];
355
362
  const toolResults = /* @__PURE__ */ new Map();
356
- const child = child_process.spawn(cmd, args, { env, cwd, shell, stdio: ["pipe", "pipe", "pipe"] });
363
+ const isWin = process.platform === "win32";
364
+ const child = child_process.spawn(cmd, args, {
365
+ env,
366
+ cwd,
367
+ shell,
368
+ stdio: ["pipe", "pipe", "pipe"],
369
+ detached: !isWin
370
+ });
371
+ const killProcessTree = (pid, signal = "SIGTERM") => {
372
+ treeKill__default.default(pid, signal);
373
+ };
357
374
  child.stdin.write(promptText);
358
375
  child.stdin.end();
359
376
  let onAbort;
360
377
  if (options.abortSignal) {
361
378
  if (options.abortSignal.aborted) {
362
- child.kill("SIGTERM");
379
+ child.pid && killProcessTree(child.pid);
363
380
  throw options.abortSignal.reason ?? new Error("Request aborted");
364
381
  }
365
- onAbort = () => child.kill("SIGTERM");
382
+ onAbort = () => child.pid && killProcessTree(child.pid);
366
383
  options.abortSignal.addEventListener("abort", onAbort, { once: true });
367
384
  }
368
385
  const startTime = Date.now();
@@ -487,7 +504,17 @@ var GeminiCliLanguageModel = class {
487
504
  const stream = new ReadableStream({
488
505
  start(controller) {
489
506
  const startTime = Date.now();
490
- const child = child_process.spawn(cmd, args, { env, cwd, shell, stdio: ["pipe", "pipe", "pipe"] });
507
+ const isWin = process.platform === "win32";
508
+ const child = child_process.spawn(cmd, args, {
509
+ env,
510
+ cwd,
511
+ shell,
512
+ stdio: ["pipe", "pipe", "pipe"],
513
+ detached: !isWin
514
+ });
515
+ const killProcessTree = (pid, signal = "SIGTERM") => {
516
+ treeKill__default.default(pid, signal);
517
+ };
491
518
  child.stdin.write(promptText);
492
519
  child.stdin.end();
493
520
  controller.enqueue({ type: "stream-start", warnings });
@@ -496,10 +523,10 @@ var GeminiCliLanguageModel = class {
496
523
  let textId;
497
524
  let lastStatus;
498
525
  const toolResults = /* @__PURE__ */ new Map();
499
- const onAbort = () => child.kill("SIGTERM");
526
+ const onAbort = () => child.pid && killProcessTree(child.pid);
500
527
  if (abortSignal) {
501
528
  if (abortSignal.aborted) {
502
- child.kill("SIGTERM");
529
+ child.pid && killProcessTree(child.pid);
503
530
  controller.error(abortSignal.reason ?? new Error("Request aborted"));
504
531
  return;
505
532
  }
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { NoSuchModelError, LoadAPIKeyError, APICallError } from '@ai-sdk/provider';
2
2
  import { spawn } from 'child_process';
3
+ import treeKill from 'tree-kill';
3
4
  import { randomUUID } from 'crypto';
4
5
  import { parseProviderOptions, generateId } from '@ai-sdk/provider-utils';
5
6
  import { z } from 'zod';
@@ -10,7 +11,9 @@ import { z } from 'zod';
10
11
  function parseStreamJsonLine(line) {
11
12
  try {
12
13
  const event = JSON.parse(line);
13
- if (!event.type || typeof event.type !== "string") return null;
14
+ if (!event || typeof event !== "object" || !("type" in event) || typeof event.type !== "string") {
15
+ return null;
16
+ }
14
17
  return event;
15
18
  } catch {
16
19
  return null;
@@ -351,16 +354,26 @@ var GeminiCliLanguageModel = class {
351
354
  let finishReason = { unified: "stop", raw: void 0 };
352
355
  const content = [];
353
356
  const toolResults = /* @__PURE__ */ new Map();
354
- const child = spawn(cmd, args, { env, cwd, shell, stdio: ["pipe", "pipe", "pipe"] });
357
+ const isWin = process.platform === "win32";
358
+ const child = spawn(cmd, args, {
359
+ env,
360
+ cwd,
361
+ shell,
362
+ stdio: ["pipe", "pipe", "pipe"],
363
+ detached: !isWin
364
+ });
365
+ const killProcessTree = (pid, signal = "SIGTERM") => {
366
+ treeKill(pid, signal);
367
+ };
355
368
  child.stdin.write(promptText);
356
369
  child.stdin.end();
357
370
  let onAbort;
358
371
  if (options.abortSignal) {
359
372
  if (options.abortSignal.aborted) {
360
- child.kill("SIGTERM");
373
+ child.pid && killProcessTree(child.pid);
361
374
  throw options.abortSignal.reason ?? new Error("Request aborted");
362
375
  }
363
- onAbort = () => child.kill("SIGTERM");
376
+ onAbort = () => child.pid && killProcessTree(child.pid);
364
377
  options.abortSignal.addEventListener("abort", onAbort, { once: true });
365
378
  }
366
379
  const startTime = Date.now();
@@ -485,7 +498,17 @@ var GeminiCliLanguageModel = class {
485
498
  const stream = new ReadableStream({
486
499
  start(controller) {
487
500
  const startTime = Date.now();
488
- const child = spawn(cmd, args, { env, cwd, shell, stdio: ["pipe", "pipe", "pipe"] });
501
+ const isWin = process.platform === "win32";
502
+ const child = spawn(cmd, args, {
503
+ env,
504
+ cwd,
505
+ shell,
506
+ stdio: ["pipe", "pipe", "pipe"],
507
+ detached: !isWin
508
+ });
509
+ const killProcessTree = (pid, signal = "SIGTERM") => {
510
+ treeKill(pid, signal);
511
+ };
489
512
  child.stdin.write(promptText);
490
513
  child.stdin.end();
491
514
  controller.enqueue({ type: "stream-start", warnings });
@@ -494,10 +517,10 @@ var GeminiCliLanguageModel = class {
494
517
  let textId;
495
518
  let lastStatus;
496
519
  const toolResults = /* @__PURE__ */ new Map();
497
- const onAbort = () => child.kill("SIGTERM");
520
+ const onAbort = () => child.pid && killProcessTree(child.pid);
498
521
  if (abortSignal) {
499
522
  if (abortSignal.aborted) {
500
- child.kill("SIGTERM");
523
+ child.pid && killProcessTree(child.pid);
501
524
  controller.error(abortSignal.reason ?? new Error("Request aborted"));
502
525
  return;
503
526
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-sdk-provider-gemini-cli-agentic",
3
- "version": "0.1.2",
3
+ "version": "0.1.5",
4
4
  "description": "AI SDK v6 provider for Google Gemini CLI agentic mode",
5
5
  "keywords": [
6
6
  "ai-sdk",
@@ -49,7 +49,8 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@ai-sdk/provider": "^3.0.0",
52
- "@ai-sdk/provider-utils": "^4.0.1"
52
+ "@ai-sdk/provider-utils": "^4.0.1",
53
+ "tree-kill": "^1.2.2"
53
54
  },
54
55
  "devDependencies": {
55
56
  "@eslint/js": "^9.28.0",