@k2wanko/gemini-cli-sdk 0.2.0 → 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 +15 -2
- package/dist/agent.js +24 -5
- 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;
|
|
@@ -23,7 +30,13 @@ export declare class GeminiAgent {
|
|
|
23
30
|
private readonly resumeSessionId;
|
|
24
31
|
private instructionsLoaded;
|
|
25
32
|
constructor(options: GeminiAgentOptions);
|
|
33
|
+
/** Return the session ID assigned to this agent instance */
|
|
34
|
+
getSessionId(): string;
|
|
35
|
+
/** List available sessions for the current project */
|
|
36
|
+
listSessions(): Promise<import("./session.js").SessionInfo[]>;
|
|
26
37
|
sendStream(prompt: string, signal?: AbortSignal): AsyncGenerator<ServerGeminiStreamEvent>;
|
|
38
|
+
private initialized;
|
|
39
|
+
private ensureInitialized;
|
|
27
40
|
private initialize;
|
|
28
41
|
private resolveInstructions;
|
|
29
42
|
private buildScopedRegistry;
|
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,
|
|
@@ -36,6 +39,15 @@ export class GeminiAgent {
|
|
|
36
39
|
};
|
|
37
40
|
this.config = new Config(configParams);
|
|
38
41
|
}
|
|
42
|
+
/** Return the session ID assigned to this agent instance */
|
|
43
|
+
getSessionId() {
|
|
44
|
+
return this.config.getSessionId();
|
|
45
|
+
}
|
|
46
|
+
/** List available sessions for the current project */
|
|
47
|
+
async listSessions() {
|
|
48
|
+
await this.ensureInitialized();
|
|
49
|
+
return listSessions(this.config);
|
|
50
|
+
}
|
|
39
51
|
async *sendStream(prompt, signal) {
|
|
40
52
|
await this.initialize();
|
|
41
53
|
const client = this.config.getGeminiClient();
|
|
@@ -91,12 +103,19 @@ export class GeminiAgent {
|
|
|
91
103
|
// -------------------------------------------------------------------------
|
|
92
104
|
// Private helpers
|
|
93
105
|
// -------------------------------------------------------------------------
|
|
94
|
-
|
|
95
|
-
|
|
106
|
+
initialized = false;
|
|
107
|
+
async ensureInitialized() {
|
|
108
|
+
if (this.initialized)
|
|
96
109
|
return;
|
|
97
110
|
const authType = getAuthTypeFromEnv() || AuthType.COMPUTE_ADC;
|
|
98
111
|
await this.config.refreshAuth(authType);
|
|
99
112
|
await this.config.initialize();
|
|
113
|
+
this.initialized = true;
|
|
114
|
+
}
|
|
115
|
+
async initialize() {
|
|
116
|
+
if (this.config.getContentGenerator())
|
|
117
|
+
return;
|
|
118
|
+
await this.ensureInitialized();
|
|
100
119
|
// Resume previous session if requested
|
|
101
120
|
if (this.resumeSessionId) {
|
|
102
121
|
const sessions = await listSessions(this.config);
|
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
|
+
}
|