@k2wanko/gemini-cli-sdk 0.2.1 → 0.3.0
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/README.md +2 -0
- package/dist/agent.d.ts +9 -2
- package/dist/agent.js +6 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/logger.d.ts +8 -0
- package/dist/logger.js +21 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,6 +7,8 @@ Built on top of `@google/gemini-cli-core`.
|
|
|
7
7
|
|
|
8
8
|
- **Skill support** — Load skill directories compatible with Gemini CLI's skill format
|
|
9
9
|
- **Non-interactive by default** — All tool calls are auto-approved, designed for headless agent usage
|
|
10
|
+
- **Logging control** — Suppress noisy core logs by default (`"silent"`), or route them to a custom logger (pino, winston, etc.) via `logLevel` and `logger` options
|
|
11
|
+
- **Hooks** — Run shell commands at lifecycle events (BeforeTool, AfterTool, BeforeAgent, etc.) to inject context, block operations, or audit tool calls — compatible with Gemini CLI's hook protocol
|
|
10
12
|
|
|
11
13
|
## Install
|
|
12
14
|
|
package/dist/agent.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { GeminiEventType, type ServerGeminiStreamEvent } from "@google/gemini-cli-core";
|
|
1
|
+
import { GeminiEventType, type HookDefinition, HookEventName, HookType, type ServerGeminiStreamEvent } from "@google/gemini-cli-core";
|
|
2
2
|
import { type SessionContext } from "./context.js";
|
|
3
|
+
import { type Logger, type LogLevel } from "./logger.js";
|
|
3
4
|
import type { SkillRef } from "./skills.js";
|
|
4
5
|
import { type ToolDef } from "./tool.js";
|
|
5
|
-
export { GeminiEventType, type ServerGeminiStreamEvent };
|
|
6
|
+
export { GeminiEventType, HookEventName, HookType, type HookDefinition, type ServerGeminiStreamEvent, };
|
|
6
7
|
export interface GeminiAgentOptions {
|
|
7
8
|
instructions: string | ((ctx: SessionContext) => string | Promise<string>);
|
|
8
9
|
tools?: ToolDef<any>[];
|
|
@@ -14,6 +15,12 @@ export interface GeminiAgentOptions {
|
|
|
14
15
|
sessionId?: string;
|
|
15
16
|
/** Context compression threshold (0-1 fraction) */
|
|
16
17
|
compressionThreshold?: number;
|
|
18
|
+
/** Core logger verbosity — default: "silent" */
|
|
19
|
+
logLevel?: LogLevel;
|
|
20
|
+
/** Custom log destination — defaults to console when logLevel is not "silent" */
|
|
21
|
+
logger?: Logger;
|
|
22
|
+
/** Hook definitions — automatically enables the hook system when provided */
|
|
23
|
+
hooks?: Partial<Record<HookEventName, HookDefinition[]>>;
|
|
17
24
|
}
|
|
18
25
|
export declare class GeminiAgent {
|
|
19
26
|
private readonly config;
|
package/dist/agent.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { ActivateSkillTool, AuthType, Config, GeminiEventType, getAuthTypeFromEnv, loadSkillsFromDir, PolicyDecision, PREVIEW_GEMINI_MODEL_AUTO, scheduleAgentTools, } from "@google/gemini-cli-core";
|
|
1
|
+
import { ActivateSkillTool, AuthType, Config, GeminiEventType, getAuthTypeFromEnv, HookEventName, HookType, loadSkillsFromDir, PolicyDecision, PREVIEW_GEMINI_MODEL_AUTO, scheduleAgentTools, } from "@google/gemini-cli-core";
|
|
2
2
|
import { AgentFsImpl, AgentShellImpl } from "./context.js";
|
|
3
|
+
import { patchCoreLogger } from "./logger.js";
|
|
3
4
|
import { listSessions, loadSession, messageRecordsToHistory, } from "./session.js";
|
|
4
5
|
import { SdkTool } from "./tool.js";
|
|
5
|
-
export { GeminiEventType };
|
|
6
|
+
export { GeminiEventType, HookEventName, HookType, };
|
|
6
7
|
export class GeminiAgent {
|
|
7
8
|
config;
|
|
8
9
|
tools;
|
|
@@ -11,6 +12,7 @@ export class GeminiAgent {
|
|
|
11
12
|
resumeSessionId;
|
|
12
13
|
instructionsLoaded = false;
|
|
13
14
|
constructor(options) {
|
|
15
|
+
patchCoreLogger(options.logLevel ?? "silent", options.logger);
|
|
14
16
|
this.instructions = options.instructions;
|
|
15
17
|
this.tools = options.tools ?? [];
|
|
16
18
|
this.skillRefs = options.skills ?? [];
|
|
@@ -24,7 +26,8 @@ export class GeminiAgent {
|
|
|
24
26
|
debugMode: options.debug ?? false,
|
|
25
27
|
model: options.model ?? PREVIEW_GEMINI_MODEL_AUTO,
|
|
26
28
|
userMemory: initialMemory,
|
|
27
|
-
enableHooks:
|
|
29
|
+
enableHooks: !!options.hooks,
|
|
30
|
+
...(options.hooks && { hooks: options.hooks }),
|
|
28
31
|
mcpEnabled: false,
|
|
29
32
|
extensionsEnabled: false,
|
|
30
33
|
skillsSupport: true,
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type LogLevel = "silent" | "error" | "warn" | "info" | "debug";
|
|
2
|
+
export interface Logger {
|
|
3
|
+
log?: (...args: unknown[]) => void;
|
|
4
|
+
warn?: (...args: unknown[]) => void;
|
|
5
|
+
error?: (...args: unknown[]) => void;
|
|
6
|
+
debug?: (...args: unknown[]) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare function patchCoreLogger(level: LogLevel, logger?: Logger): void;
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { debugLogger } from "@google/gemini-cli-core";
|
|
2
|
+
const LOG_LEVEL_ORDER = {
|
|
3
|
+
silent: 0,
|
|
4
|
+
error: 1,
|
|
5
|
+
warn: 2,
|
|
6
|
+
info: 3,
|
|
7
|
+
debug: 4,
|
|
8
|
+
};
|
|
9
|
+
const noop = () => { };
|
|
10
|
+
export function patchCoreLogger(level, logger) {
|
|
11
|
+
const threshold = LOG_LEVEL_ORDER[level];
|
|
12
|
+
const dest = logger ?? console;
|
|
13
|
+
debugLogger.log =
|
|
14
|
+
threshold >= LOG_LEVEL_ORDER.info ? (dest.log ?? noop).bind(dest) : noop;
|
|
15
|
+
debugLogger.warn =
|
|
16
|
+
threshold >= LOG_LEVEL_ORDER.warn ? (dest.warn ?? noop).bind(dest) : noop;
|
|
17
|
+
debugLogger.error =
|
|
18
|
+
threshold >= LOG_LEVEL_ORDER.error ? (dest.error ?? noop).bind(dest) : noop;
|
|
19
|
+
debugLogger.debug =
|
|
20
|
+
threshold >= LOG_LEVEL_ORDER.debug ? (dest.debug ?? noop).bind(dest) : noop;
|
|
21
|
+
}
|