geminisdk 0.1.1
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 +129 -0
- package/dist/chunk-Y4MC6YDW.mjs +135 -0
- package/dist/index.d.mts +511 -0
- package/dist/index.d.ts +511 -0
- package/dist/index.js +1696 -0
- package/dist/index.mjs +1480 -0
- package/dist/types-ADTG4FSI.mjs +46 -0
- package/package.json +60 -0
- package/src/auth.ts +293 -0
- package/src/backend.ts +615 -0
- package/src/client.ts +230 -0
- package/src/exceptions.ts +289 -0
- package/src/index.ts +148 -0
- package/src/session.ts +380 -0
- package/src/tools.ts +127 -0
- package/src/types.ts +352 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for GeminiSDK TypeScript
|
|
3
|
+
*
|
|
4
|
+
* Based on:
|
|
5
|
+
* - GitHub Copilot SDK types
|
|
6
|
+
* - Google Gemini CLI implementation
|
|
7
|
+
*/
|
|
8
|
+
type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'error';
|
|
9
|
+
type LogLevel = 'none' | 'error' | 'warning' | 'info' | 'debug' | 'all';
|
|
10
|
+
declare enum Role {
|
|
11
|
+
USER = "user",
|
|
12
|
+
ASSISTANT = "assistant",
|
|
13
|
+
SYSTEM = "system"
|
|
14
|
+
}
|
|
15
|
+
interface GeminiOAuthCredentials {
|
|
16
|
+
accessToken: string;
|
|
17
|
+
refreshToken: string;
|
|
18
|
+
tokenType: string;
|
|
19
|
+
expiryDate: number;
|
|
20
|
+
}
|
|
21
|
+
interface GeminiModelInfo {
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
contextWindow: number;
|
|
25
|
+
maxOutput: number;
|
|
26
|
+
inputPrice: number;
|
|
27
|
+
outputPrice: number;
|
|
28
|
+
supportsNativeTools: boolean;
|
|
29
|
+
supportsThinking: boolean;
|
|
30
|
+
}
|
|
31
|
+
interface ModelVisionLimits {
|
|
32
|
+
supportedMediaTypes?: string[];
|
|
33
|
+
maxPromptImages?: number;
|
|
34
|
+
maxPromptImageSize?: number;
|
|
35
|
+
}
|
|
36
|
+
interface ModelLimits {
|
|
37
|
+
maxPromptTokens?: number;
|
|
38
|
+
maxContextWindowTokens?: number;
|
|
39
|
+
vision?: ModelVisionLimits;
|
|
40
|
+
}
|
|
41
|
+
interface ModelSupports {
|
|
42
|
+
vision: boolean;
|
|
43
|
+
tools: boolean;
|
|
44
|
+
thinking: boolean;
|
|
45
|
+
}
|
|
46
|
+
interface ModelCapabilities {
|
|
47
|
+
supports: ModelSupports;
|
|
48
|
+
limits: ModelLimits;
|
|
49
|
+
}
|
|
50
|
+
interface ModelInfo {
|
|
51
|
+
id: string;
|
|
52
|
+
name: string;
|
|
53
|
+
capabilities: ModelCapabilities;
|
|
54
|
+
}
|
|
55
|
+
interface ContentPart {
|
|
56
|
+
text?: string;
|
|
57
|
+
imageUrl?: string;
|
|
58
|
+
imageData?: Uint8Array;
|
|
59
|
+
imageMimeType?: string;
|
|
60
|
+
}
|
|
61
|
+
interface Message {
|
|
62
|
+
role: Role;
|
|
63
|
+
content: string | ContentPart[];
|
|
64
|
+
name?: string;
|
|
65
|
+
toolCalls?: ToolCall[];
|
|
66
|
+
toolCallId?: string;
|
|
67
|
+
}
|
|
68
|
+
interface Attachment {
|
|
69
|
+
type: 'file' | 'image';
|
|
70
|
+
path?: string;
|
|
71
|
+
url?: string;
|
|
72
|
+
data?: string;
|
|
73
|
+
mimeType?: string;
|
|
74
|
+
}
|
|
75
|
+
interface FunctionCall {
|
|
76
|
+
name: string;
|
|
77
|
+
arguments: Record<string, unknown> | string;
|
|
78
|
+
}
|
|
79
|
+
interface ToolCall {
|
|
80
|
+
id: string;
|
|
81
|
+
type: 'function';
|
|
82
|
+
function: FunctionCall;
|
|
83
|
+
}
|
|
84
|
+
interface ToolInvocation {
|
|
85
|
+
name: string;
|
|
86
|
+
arguments: Record<string, unknown>;
|
|
87
|
+
callId: string;
|
|
88
|
+
}
|
|
89
|
+
type ToolResultType = 'success' | 'failure' | 'rejected' | 'denied';
|
|
90
|
+
interface ToolResult {
|
|
91
|
+
resultType?: ToolResultType;
|
|
92
|
+
textResultForLlm?: string;
|
|
93
|
+
binaryResult?: Uint8Array;
|
|
94
|
+
sessionLog?: string;
|
|
95
|
+
}
|
|
96
|
+
type ToolHandler = (invocation: ToolInvocation) => ToolResult | Promise<ToolResult>;
|
|
97
|
+
interface Tool {
|
|
98
|
+
name: string;
|
|
99
|
+
description: string;
|
|
100
|
+
parameters?: Record<string, unknown>;
|
|
101
|
+
handler?: ToolHandler;
|
|
102
|
+
}
|
|
103
|
+
interface GenerationConfig {
|
|
104
|
+
temperature?: number;
|
|
105
|
+
maxOutputTokens?: number;
|
|
106
|
+
topP?: number;
|
|
107
|
+
topK?: number;
|
|
108
|
+
stopSequences?: string[];
|
|
109
|
+
}
|
|
110
|
+
interface ThinkingConfig {
|
|
111
|
+
includeThoughts?: boolean;
|
|
112
|
+
thinkingBudget?: number;
|
|
113
|
+
}
|
|
114
|
+
interface MessageOptions {
|
|
115
|
+
prompt: string;
|
|
116
|
+
attachments?: Attachment[];
|
|
117
|
+
context?: string;
|
|
118
|
+
}
|
|
119
|
+
interface LLMUsage {
|
|
120
|
+
promptTokens: number;
|
|
121
|
+
completionTokens: number;
|
|
122
|
+
totalTokens: number;
|
|
123
|
+
}
|
|
124
|
+
interface LLMChunk {
|
|
125
|
+
content: string;
|
|
126
|
+
reasoningContent?: string;
|
|
127
|
+
toolCalls?: ToolCall[];
|
|
128
|
+
usage?: LLMUsage;
|
|
129
|
+
finishReason?: string;
|
|
130
|
+
}
|
|
131
|
+
interface SessionConfig {
|
|
132
|
+
sessionId?: string;
|
|
133
|
+
model?: string;
|
|
134
|
+
tools?: Tool[];
|
|
135
|
+
systemMessage?: string;
|
|
136
|
+
generationConfig?: GenerationConfig;
|
|
137
|
+
thinkingConfig?: ThinkingConfig;
|
|
138
|
+
streaming?: boolean;
|
|
139
|
+
}
|
|
140
|
+
interface SessionMetadata {
|
|
141
|
+
sessionId: string;
|
|
142
|
+
startTime: string;
|
|
143
|
+
modifiedTime: string;
|
|
144
|
+
summary?: string;
|
|
145
|
+
model: string;
|
|
146
|
+
}
|
|
147
|
+
interface GeminiClientOptions {
|
|
148
|
+
oauthPath?: string;
|
|
149
|
+
clientId?: string;
|
|
150
|
+
clientSecret?: string;
|
|
151
|
+
baseUrl?: string;
|
|
152
|
+
timeout?: number;
|
|
153
|
+
logLevel?: LogLevel;
|
|
154
|
+
autoRefresh?: boolean;
|
|
155
|
+
}
|
|
156
|
+
declare enum EventType {
|
|
157
|
+
SESSION_CREATED = "session.created",
|
|
158
|
+
SESSION_IDLE = "session.idle",
|
|
159
|
+
SESSION_ERROR = "session.error",
|
|
160
|
+
ASSISTANT_MESSAGE = "assistant.message",
|
|
161
|
+
ASSISTANT_MESSAGE_DELTA = "assistant.message_delta",
|
|
162
|
+
ASSISTANT_REASONING = "assistant.reasoning",
|
|
163
|
+
ASSISTANT_REASONING_DELTA = "assistant.reasoning_delta",
|
|
164
|
+
TOOL_CALL = "tool.call",
|
|
165
|
+
TOOL_RESULT = "tool.result"
|
|
166
|
+
}
|
|
167
|
+
interface SessionEvent {
|
|
168
|
+
type: EventType;
|
|
169
|
+
data: unknown;
|
|
170
|
+
sessionId: string;
|
|
171
|
+
}
|
|
172
|
+
type SessionEventHandler = (event: SessionEvent) => void;
|
|
173
|
+
declare const GEMINI_OAUTH_REDIRECT_URI = "http://localhost:45289";
|
|
174
|
+
declare const GEMINI_OAUTH_BASE_URL = "https://accounts.google.com";
|
|
175
|
+
declare const GEMINI_OAUTH_TOKEN_ENDPOINT = "https://accounts.google.com/o/oauth2/token";
|
|
176
|
+
declare const GEMINI_OAUTH_AUTH_ENDPOINT = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
177
|
+
declare const GEMINI_OAUTH_CLIENT_ID = "681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com";
|
|
178
|
+
declare const GEMINI_OAUTH_CLIENT_SECRET = "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";
|
|
179
|
+
declare const GEMINI_OAUTH_SCOPES: string[];
|
|
180
|
+
declare const GEMINI_CODE_ASSIST_ENDPOINT = "https://cloudcode-pa.googleapis.com";
|
|
181
|
+
declare const GEMINI_CODE_ASSIST_API_VERSION = "v1internal";
|
|
182
|
+
declare const GEMINI_DIR = ".gemini";
|
|
183
|
+
declare const GEMINI_CREDENTIAL_FILENAME = "oauth_creds.json";
|
|
184
|
+
declare const GEMINI_ENV_FILENAME = ".env";
|
|
185
|
+
declare const TOKEN_REFRESH_BUFFER_MS: number;
|
|
186
|
+
declare const HTTP_OK = 200;
|
|
187
|
+
declare const HTTP_UNAUTHORIZED = 401;
|
|
188
|
+
declare const HTTP_FORBIDDEN = 403;
|
|
189
|
+
declare const GEMINI_CLI_MODELS: Record<string, GeminiModelInfo>;
|
|
190
|
+
declare function getGeminiCliCredentialPath(customPath?: string): string;
|
|
191
|
+
declare function getGeminiCliEnvPath(customPath?: string): string;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Backend for Gemini CLI / Google Code Assist API.
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
interface BackendOptions {
|
|
198
|
+
timeout?: number;
|
|
199
|
+
oauthPath?: string;
|
|
200
|
+
clientId?: string;
|
|
201
|
+
clientSecret?: string;
|
|
202
|
+
}
|
|
203
|
+
declare class GeminiBackend {
|
|
204
|
+
private timeout;
|
|
205
|
+
private oauthManager;
|
|
206
|
+
private projectId;
|
|
207
|
+
constructor(options?: BackendOptions);
|
|
208
|
+
private getAuthHeaders;
|
|
209
|
+
private prepareMessages;
|
|
210
|
+
private prepareTools;
|
|
211
|
+
private ensureProjectId;
|
|
212
|
+
private onboardForProject;
|
|
213
|
+
private buildRequestPayload;
|
|
214
|
+
private parseCompletionResponse;
|
|
215
|
+
complete(options: {
|
|
216
|
+
model: string;
|
|
217
|
+
messages: Message[];
|
|
218
|
+
generationConfig?: GenerationConfig;
|
|
219
|
+
thinkingConfig?: ThinkingConfig;
|
|
220
|
+
tools?: Tool[];
|
|
221
|
+
extraHeaders?: Record<string, string>;
|
|
222
|
+
}): Promise<LLMChunk>;
|
|
223
|
+
private completeWithRetry;
|
|
224
|
+
completeStreaming(options: {
|
|
225
|
+
model: string;
|
|
226
|
+
messages: Message[];
|
|
227
|
+
generationConfig?: GenerationConfig;
|
|
228
|
+
thinkingConfig?: ThinkingConfig;
|
|
229
|
+
tools?: Tool[];
|
|
230
|
+
extraHeaders?: Record<string, string>;
|
|
231
|
+
}): AsyncGenerator<LLMChunk, void, unknown>;
|
|
232
|
+
private completeStreamingWithRetry;
|
|
233
|
+
private handleHttpError;
|
|
234
|
+
listModels(): Promise<string[]>;
|
|
235
|
+
close(): Promise<void>;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* GeminiSDK Session - Manages individual conversation sessions.
|
|
240
|
+
*/
|
|
241
|
+
|
|
242
|
+
declare class GeminiSession {
|
|
243
|
+
private readonly _sessionId;
|
|
244
|
+
private readonly _model;
|
|
245
|
+
private readonly _backend;
|
|
246
|
+
private _tools;
|
|
247
|
+
private readonly _toolHandlers;
|
|
248
|
+
private readonly _systemMessage?;
|
|
249
|
+
private readonly _generationConfig?;
|
|
250
|
+
private readonly _thinkingConfig?;
|
|
251
|
+
private readonly _streaming;
|
|
252
|
+
private _messages;
|
|
253
|
+
private readonly _eventHandlers;
|
|
254
|
+
private _closed;
|
|
255
|
+
private readonly _startTime;
|
|
256
|
+
private _modifiedTime;
|
|
257
|
+
constructor(options: {
|
|
258
|
+
sessionId: string;
|
|
259
|
+
model: string;
|
|
260
|
+
backend: GeminiBackend;
|
|
261
|
+
tools?: Tool[];
|
|
262
|
+
systemMessage?: string;
|
|
263
|
+
generationConfig?: GenerationConfig;
|
|
264
|
+
thinkingConfig?: ThinkingConfig;
|
|
265
|
+
streaming?: boolean;
|
|
266
|
+
});
|
|
267
|
+
get sessionId(): string;
|
|
268
|
+
get model(): string;
|
|
269
|
+
get startTime(): Date;
|
|
270
|
+
get modifiedTime(): Date;
|
|
271
|
+
get messages(): Message[];
|
|
272
|
+
on(handler: SessionEventHandler): () => void;
|
|
273
|
+
private emit;
|
|
274
|
+
send(options: MessageOptions): Promise<void>;
|
|
275
|
+
sendAndWait(options: MessageOptions): Promise<SessionEvent>;
|
|
276
|
+
private streamResponse;
|
|
277
|
+
private getResponse;
|
|
278
|
+
private handleToolCalls;
|
|
279
|
+
getMessages(): Message[];
|
|
280
|
+
addTool(tool: Tool): void;
|
|
281
|
+
removeTool(toolName: string): void;
|
|
282
|
+
clearHistory(): Promise<void>;
|
|
283
|
+
destroy(): Promise<void>;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* GeminiSDK Client - Main entry point for the Gemini SDK.
|
|
288
|
+
*/
|
|
289
|
+
|
|
290
|
+
declare class GeminiClient {
|
|
291
|
+
private _options;
|
|
292
|
+
private _state;
|
|
293
|
+
private _backend;
|
|
294
|
+
private _oauthManager;
|
|
295
|
+
private _sessions;
|
|
296
|
+
private _started;
|
|
297
|
+
private _autoRefreshInterval;
|
|
298
|
+
constructor(options?: GeminiClientOptions);
|
|
299
|
+
get options(): GeminiClientOptions;
|
|
300
|
+
get state(): ConnectionState;
|
|
301
|
+
start(): Promise<void>;
|
|
302
|
+
private startAutoRefresh;
|
|
303
|
+
stop(): Promise<void>;
|
|
304
|
+
close(): Promise<void>;
|
|
305
|
+
createSession(config?: SessionConfig): Promise<GeminiSession>;
|
|
306
|
+
getSession(sessionId: string): Promise<GeminiSession>;
|
|
307
|
+
listSessions(): Promise<SessionMetadata[]>;
|
|
308
|
+
deleteSession(sessionId: string): Promise<void>;
|
|
309
|
+
getState(): ConnectionState;
|
|
310
|
+
getAuthStatus(): Promise<{
|
|
311
|
+
authenticated: boolean;
|
|
312
|
+
tokenType?: string;
|
|
313
|
+
expiresAt?: number;
|
|
314
|
+
}>;
|
|
315
|
+
listModels(): Promise<ModelInfo[]>;
|
|
316
|
+
refreshAuth(): Promise<void>;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* OAuth authentication for Gemini CLI / Code Assist API.
|
|
321
|
+
*/
|
|
322
|
+
|
|
323
|
+
declare class GeminiOAuthManager {
|
|
324
|
+
private oauthPath?;
|
|
325
|
+
private clientId;
|
|
326
|
+
private clientSecret;
|
|
327
|
+
private credentials;
|
|
328
|
+
private refreshLock;
|
|
329
|
+
private projectId;
|
|
330
|
+
constructor(oauthPath?: string, clientId?: string, clientSecret?: string);
|
|
331
|
+
private getCredentialPath;
|
|
332
|
+
private loadCachedCredentials;
|
|
333
|
+
private saveCredentials;
|
|
334
|
+
private refreshAccessToken;
|
|
335
|
+
private doRefresh;
|
|
336
|
+
private isTokenValid;
|
|
337
|
+
invalidateCredentials(): void;
|
|
338
|
+
ensureAuthenticated(forceRefresh?: boolean): Promise<string>;
|
|
339
|
+
getCredentials(): Promise<GeminiOAuthCredentials>;
|
|
340
|
+
getApiEndpoint(): string;
|
|
341
|
+
getProjectId(): string | null;
|
|
342
|
+
setProjectId(projectId: string): void;
|
|
343
|
+
generateAuthUrl(state: string, codeVerifier?: string): string;
|
|
344
|
+
exchangeCode(code: string, codeVerifier?: string): Promise<GeminiOAuthCredentials>;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* GeminiSDK Tools - Tool definition utilities.
|
|
349
|
+
*/
|
|
350
|
+
|
|
351
|
+
interface ToolDefinitionOptions {
|
|
352
|
+
name?: string;
|
|
353
|
+
description?: string;
|
|
354
|
+
parameters?: Record<string, unknown>;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Define a tool for use with Gemini models.
|
|
358
|
+
*/
|
|
359
|
+
declare function defineTool<T extends Record<string, unknown>>(options: ToolDefinitionOptions, handler: (args: T) => unknown | Promise<unknown>): Tool;
|
|
360
|
+
/**
|
|
361
|
+
* Create a tool programmatically.
|
|
362
|
+
*/
|
|
363
|
+
declare function createTool(name: string, description: string, parameters?: Record<string, unknown>, handler?: ToolHandler): Tool;
|
|
364
|
+
/**
|
|
365
|
+
* Registry for managing tools.
|
|
366
|
+
*/
|
|
367
|
+
declare class ToolRegistry {
|
|
368
|
+
private tools;
|
|
369
|
+
private categories;
|
|
370
|
+
register(tool: Tool, category?: string): void;
|
|
371
|
+
unregister(name: string): void;
|
|
372
|
+
get(name: string): Tool | undefined;
|
|
373
|
+
getAll(): Tool[];
|
|
374
|
+
getByCategory(category: string): Tool[];
|
|
375
|
+
listCategories(): string[];
|
|
376
|
+
}
|
|
377
|
+
declare function getDefaultRegistry(): ToolRegistry;
|
|
378
|
+
declare function registerTool(tool: Tool, category?: string): void;
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Custom exceptions for GeminiSDK TypeScript
|
|
382
|
+
*/
|
|
383
|
+
interface ErrorDetails {
|
|
384
|
+
[key: string]: unknown;
|
|
385
|
+
}
|
|
386
|
+
declare class GeminiSDKError extends Error {
|
|
387
|
+
readonly details: ErrorDetails;
|
|
388
|
+
constructor(message: string, details?: ErrorDetails);
|
|
389
|
+
}
|
|
390
|
+
declare class AuthenticationError extends GeminiSDKError {
|
|
391
|
+
constructor(message?: string, details?: ErrorDetails);
|
|
392
|
+
}
|
|
393
|
+
declare class CredentialsNotFoundError extends AuthenticationError {
|
|
394
|
+
readonly credentialPath: string;
|
|
395
|
+
constructor(credentialPath: string, message?: string);
|
|
396
|
+
}
|
|
397
|
+
declare class TokenRefreshError extends AuthenticationError {
|
|
398
|
+
readonly statusCode?: number;
|
|
399
|
+
readonly responseBody?: string;
|
|
400
|
+
constructor(message?: string, statusCode?: number, responseBody?: string);
|
|
401
|
+
}
|
|
402
|
+
declare class TokenExpiredError extends AuthenticationError {
|
|
403
|
+
constructor(message?: string);
|
|
404
|
+
}
|
|
405
|
+
declare class ConnectionError extends GeminiSDKError {
|
|
406
|
+
readonly endpoint?: string;
|
|
407
|
+
constructor(message?: string, endpoint?: string, details?: ErrorDetails);
|
|
408
|
+
}
|
|
409
|
+
declare class APIError extends GeminiSDKError {
|
|
410
|
+
readonly statusCode: number;
|
|
411
|
+
readonly responseBody?: string;
|
|
412
|
+
readonly endpoint?: string;
|
|
413
|
+
constructor(message: string, statusCode: number, responseBody?: string, endpoint?: string);
|
|
414
|
+
}
|
|
415
|
+
declare class RateLimitError extends APIError {
|
|
416
|
+
readonly retryAfter?: number;
|
|
417
|
+
constructor(message?: string, statusCode?: number, retryAfter?: number, responseBody?: string);
|
|
418
|
+
}
|
|
419
|
+
declare class QuotaExceededError extends APIError {
|
|
420
|
+
readonly resetTime?: string;
|
|
421
|
+
constructor(message?: string, statusCode?: number, resetTime?: string, responseBody?: string);
|
|
422
|
+
}
|
|
423
|
+
declare class PermissionDeniedError extends APIError {
|
|
424
|
+
constructor(message?: string, statusCode?: number, responseBody?: string);
|
|
425
|
+
}
|
|
426
|
+
declare class NotFoundError extends APIError {
|
|
427
|
+
readonly resource?: string;
|
|
428
|
+
constructor(message?: string, statusCode?: number, resource?: string, responseBody?: string);
|
|
429
|
+
}
|
|
430
|
+
declare class SessionError extends GeminiSDKError {
|
|
431
|
+
readonly sessionId?: string;
|
|
432
|
+
constructor(message: string, sessionId?: string, details?: ErrorDetails);
|
|
433
|
+
}
|
|
434
|
+
declare class SessionNotFoundError extends SessionError {
|
|
435
|
+
constructor(sessionId: string);
|
|
436
|
+
}
|
|
437
|
+
declare class SessionClosedError extends SessionError {
|
|
438
|
+
constructor(sessionId?: string);
|
|
439
|
+
}
|
|
440
|
+
declare class ToolError extends GeminiSDKError {
|
|
441
|
+
readonly toolName?: string;
|
|
442
|
+
constructor(message: string, toolName?: string, details?: ErrorDetails);
|
|
443
|
+
}
|
|
444
|
+
declare class ToolNotFoundError extends ToolError {
|
|
445
|
+
constructor(toolName: string);
|
|
446
|
+
}
|
|
447
|
+
declare class ToolExecutionError extends ToolError {
|
|
448
|
+
readonly originalError?: Error;
|
|
449
|
+
constructor(message: string, toolName: string, originalError?: Error);
|
|
450
|
+
}
|
|
451
|
+
declare class ValidationError extends GeminiSDKError {
|
|
452
|
+
readonly field?: string;
|
|
453
|
+
readonly value?: unknown;
|
|
454
|
+
constructor(message: string, field?: string, value?: unknown);
|
|
455
|
+
}
|
|
456
|
+
declare class ConfigurationError extends GeminiSDKError {
|
|
457
|
+
readonly configKey?: string;
|
|
458
|
+
constructor(message: string, configKey?: string);
|
|
459
|
+
}
|
|
460
|
+
declare class StreamError extends GeminiSDKError {
|
|
461
|
+
readonly partialContent?: string;
|
|
462
|
+
constructor(message: string, partialContent?: string);
|
|
463
|
+
}
|
|
464
|
+
declare class CancellationError extends GeminiSDKError {
|
|
465
|
+
constructor(message?: string);
|
|
466
|
+
}
|
|
467
|
+
declare class TimeoutError extends GeminiSDKError {
|
|
468
|
+
readonly timeout?: number;
|
|
469
|
+
constructor(message?: string, timeout?: number);
|
|
470
|
+
}
|
|
471
|
+
declare class OnboardingError extends GeminiSDKError {
|
|
472
|
+
readonly tierId?: string;
|
|
473
|
+
constructor(message?: string, tierId?: string);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* GeminiSDK TypeScript - A TypeScript SDK for Google Gemini Code Assist API.
|
|
478
|
+
*
|
|
479
|
+
* This SDK provides a high-level interface for interacting with the Gemini
|
|
480
|
+
* Code Assist API, supporting OAuth authentication, streaming responses,
|
|
481
|
+
* tool calling, and session management.
|
|
482
|
+
*
|
|
483
|
+
* @example
|
|
484
|
+
* ```typescript
|
|
485
|
+
* import { GeminiClient, EventType } from 'geminisdk';
|
|
486
|
+
*
|
|
487
|
+
* async function main() {
|
|
488
|
+
* const client = new GeminiClient();
|
|
489
|
+
* await client.start();
|
|
490
|
+
*
|
|
491
|
+
* const session = await client.createSession({
|
|
492
|
+
* model: 'gemini-2.5-pro',
|
|
493
|
+
* streaming: true,
|
|
494
|
+
* });
|
|
495
|
+
*
|
|
496
|
+
* session.on((event) => {
|
|
497
|
+
* if (event.type === EventType.ASSISTANT_MESSAGE_DELTA) {
|
|
498
|
+
* process.stdout.write((event.data as any).deltaContent);
|
|
499
|
+
* }
|
|
500
|
+
* });
|
|
501
|
+
*
|
|
502
|
+
* await session.send({ prompt: 'What is TypeScript?' });
|
|
503
|
+
* await client.close();
|
|
504
|
+
* }
|
|
505
|
+
*
|
|
506
|
+
* main();
|
|
507
|
+
* ```
|
|
508
|
+
*/
|
|
509
|
+
declare const VERSION = "0.1.1";
|
|
510
|
+
|
|
511
|
+
export { APIError, type Attachment, AuthenticationError, CancellationError, ConfigurationError, ConnectionError, type ConnectionState, type ContentPart, CredentialsNotFoundError, EventType, type FunctionCall, GEMINI_CLI_MODELS, GEMINI_CODE_ASSIST_API_VERSION, GEMINI_CODE_ASSIST_ENDPOINT, GEMINI_CREDENTIAL_FILENAME, GEMINI_DIR, GEMINI_ENV_FILENAME, GEMINI_OAUTH_AUTH_ENDPOINT, GEMINI_OAUTH_BASE_URL, GEMINI_OAUTH_CLIENT_ID, GEMINI_OAUTH_CLIENT_SECRET, GEMINI_OAUTH_REDIRECT_URI, GEMINI_OAUTH_SCOPES, GEMINI_OAUTH_TOKEN_ENDPOINT, GeminiBackend, GeminiClient, type GeminiClientOptions, type GeminiModelInfo, type GeminiOAuthCredentials, GeminiOAuthManager, GeminiSDKError, GeminiSession, type GenerationConfig, HTTP_FORBIDDEN, HTTP_OK, HTTP_UNAUTHORIZED, type LLMChunk, type LLMUsage, type LogLevel, type Message, type MessageOptions, type ModelCapabilities, type ModelInfo, type ModelLimits, type ModelSupports, type ModelVisionLimits, NotFoundError, OnboardingError, PermissionDeniedError, QuotaExceededError, RateLimitError, Role, SessionClosedError, type SessionConfig, SessionError, type SessionEvent, type SessionEventHandler, type SessionMetadata, SessionNotFoundError, StreamError, TOKEN_REFRESH_BUFFER_MS, type ThinkingConfig, TimeoutError, TokenExpiredError, TokenRefreshError, type Tool, type ToolCall, ToolError, ToolExecutionError, type ToolHandler, type ToolInvocation, ToolNotFoundError, ToolRegistry, type ToolResult, type ToolResultType, VERSION, ValidationError, createTool, defineTool, getDefaultRegistry, getGeminiCliCredentialPath, getGeminiCliEnvPath, registerTool };
|