@umituz/react-native-ai-gemini-provider 3.0.41 → 3.0.42
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/package.json +1 -1
- package/src/application/builders/config-builder.ts +102 -0
- package/src/application/builders/index.ts +8 -0
- package/src/application/dtos/generation-request.dto.ts +89 -0
- package/src/application/dtos/index.ts +8 -0
- package/src/application/index.ts +16 -0
- package/src/application/providers/gemini-provider.ts +135 -0
- package/src/application/providers/index.ts +6 -0
- package/src/application/use-cases/generate-json.use-case.ts +73 -0
- package/src/application/use-cases/generate-text.use-case.ts +81 -0
- package/src/application/use-cases/index.ts +20 -0
- package/src/application/use-cases/stream-content.use-case.ts +46 -0
- package/src/domain/entities/error.types.ts +0 -5
- package/src/domain/entities/gemini.types.ts +3 -1
- package/src/domain/index.ts +16 -0
- package/src/domain/repositories/index.ts +19 -0
- package/src/domain/repositories/streaming.repository.ts +41 -0
- package/src/domain/repositories/structured-text.repository.ts +41 -0
- package/src/domain/repositories/text-generation.repository.ts +38 -0
- package/src/domain/services/validation.service.ts +157 -0
- package/src/domain/value-objects/api-key.vo.ts +55 -0
- package/src/domain/value-objects/index.ts +8 -0
- package/src/domain/value-objects/model-name.vo.ts +66 -0
- package/src/domain/value-objects/timeout.vo.ts +69 -0
- package/src/index.ts +110 -25
- package/src/infrastructure/external/gemini-client.singleton.ts +49 -0
- package/src/infrastructure/external/gemini-sdk.adapter.ts +143 -0
- package/src/infrastructure/external/index.ts +7 -0
- package/src/infrastructure/index.ts +16 -0
- package/src/infrastructure/mappers/content.mapper.ts +80 -0
- package/src/infrastructure/mappers/error.mapper.ts +152 -0
- package/src/infrastructure/mappers/index.ts +7 -0
- package/src/infrastructure/mappers/response.mapper.ts +165 -0
- package/src/infrastructure/repositories/base-gemini.repository.ts +94 -0
- package/src/infrastructure/repositories/gemini-streaming.repository.impl.ts +119 -0
- package/src/infrastructure/repositories/gemini-structured-text.repository.impl.ts +108 -0
- package/src/infrastructure/repositories/gemini-text.repository.impl.ts +76 -0
- package/src/infrastructure/repositories/index.ts +10 -0
- package/src/infrastructure/utils/index.ts +6 -0
- package/src/presentation/hooks/index.ts +8 -0
- package/src/presentation/hooks/use-gemini.hook.ts +181 -0
- package/src/presentation/hooks/use-operation-manager.hook.ts +67 -0
- package/src/presentation/index.ts +10 -0
- package/src/presentation/providers/gemini-provider.tsx +93 -0
- package/src/presentation/providers/index.ts +10 -0
- package/dist/domain/entities/error.types.d.ts +0 -96
- package/dist/domain/entities/gemini.types.d.ts +0 -128
- package/dist/domain/entities/index.d.ts +0 -6
- package/dist/domain/entities/models.d.ts +0 -23
- package/dist/index.d.ts +0 -15
- package/dist/infrastructure/services/BaseService.d.ts +0 -29
- package/dist/infrastructure/services/ChatSession.d.ts +0 -63
- package/dist/infrastructure/services/GeminiClient.d.ts +0 -16
- package/dist/infrastructure/services/GeminiProvider.d.ts +0 -10
- package/dist/infrastructure/services/Streaming.d.ts +0 -7
- package/dist/infrastructure/services/StructuredText.d.ts +0 -6
- package/dist/infrastructure/services/TextGeneration.d.ts +0 -8
- package/dist/infrastructure/services/index.d.ts +0 -6
- package/dist/infrastructure/telemetry/TelemetryHooks.d.ts +0 -41
- package/dist/infrastructure/telemetry/index.d.ts +0 -4
- package/dist/infrastructure/utils/async/execute-state.util.d.ts +0 -49
- package/dist/infrastructure/utils/async/index.d.ts +0 -4
- package/dist/infrastructure/utils/content-mapper.util.d.ts +0 -45
- package/dist/infrastructure/utils/error-mapper.util.d.ts +0 -2
- package/dist/infrastructure/utils/gemini-data-transformer.util.d.ts +0 -2
- package/dist/infrastructure/utils/json-parser.util.d.ts +0 -9
- package/dist/infrastructure/utils/stream-processor.util.d.ts +0 -14
- package/dist/presentation/hooks/index.d.ts +0 -1
- package/dist/presentation/hooks/useGemini.d.ts +0 -17
- package/dist/presentation/hooks/useOperationManager.d.ts +0 -23
- package/dist/providers/ConfigBuilder.d.ts +0 -46
- package/dist/providers/ProviderFactory.d.ts +0 -25
- package/dist/providers/index.d.ts +0 -7
- package/src/infrastructure/services/BaseService.ts +0 -53
- package/src/infrastructure/services/ChatSession.ts +0 -199
- package/src/infrastructure/services/GeminiClient.ts +0 -112
- package/src/infrastructure/services/Streaming.ts +0 -56
- package/src/infrastructure/services/StructuredText.ts +0 -57
- package/src/infrastructure/services/TextGeneration.ts +0 -57
- package/src/infrastructure/telemetry/TelemetryHooks.ts +0 -110
- package/src/infrastructure/utils/async/execute-state.util.ts +0 -93
- package/src/infrastructure/utils/content-mapper.util.ts +0 -175
- package/src/infrastructure/utils/error-mapper.util.ts +0 -145
- package/src/infrastructure/utils/gemini-data-transformer.util.ts +0 -40
- package/src/infrastructure/utils/text-calculations.util.ts +0 -51
- package/src/presentation/hooks/useGemini.ts +0 -125
- package/src/presentation/hooks/useOperationManager.ts +0 -88
- package/src/providers/ConfigBuilder.ts +0 -112
- package/src/providers/ProviderFactory.ts +0 -65
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Categories of errors that can occur with Gemini API
|
|
3
|
-
*/
|
|
4
|
-
export declare enum GeminiErrorType {
|
|
5
|
-
/** Network connectivity issues */
|
|
6
|
-
NETWORK = "NETWORK",
|
|
7
|
-
/** API rate limit exceeded */
|
|
8
|
-
RATE_LIMIT = "RATE_LIMIT",
|
|
9
|
-
/** Authentication/authorization failures */
|
|
10
|
-
AUTHENTICATION = "AUTHENTICATION",
|
|
11
|
-
/** Invalid input data or parameters */
|
|
12
|
-
VALIDATION = "VALIDATION",
|
|
13
|
-
/** Content blocked by safety filters */
|
|
14
|
-
SAFETY = "SAFETY",
|
|
15
|
-
/** Server-side errors */
|
|
16
|
-
SERVER = "SERVER",
|
|
17
|
-
/** Request timeout */
|
|
18
|
-
TIMEOUT = "TIMEOUT",
|
|
19
|
-
/** API quota exceeded */
|
|
20
|
-
QUOTA_EXCEEDED = "QUOTA_EXCEEDED",
|
|
21
|
-
/** Requested model not found */
|
|
22
|
-
MODEL_NOT_FOUND = "MODEL_NOT_FOUND",
|
|
23
|
-
/** Unknown/unclassified error */
|
|
24
|
-
UNKNOWN = "UNKNOWN"
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Detailed error information for Gemini API errors
|
|
28
|
-
*/
|
|
29
|
-
export interface GeminiErrorInfo {
|
|
30
|
-
/** Category of the error */
|
|
31
|
-
type: GeminiErrorType;
|
|
32
|
-
/** Message key for i18n translation */
|
|
33
|
-
messageKey: string;
|
|
34
|
-
/** Whether the request can be retried */
|
|
35
|
-
retryable: boolean;
|
|
36
|
-
/** Original error that caused this error */
|
|
37
|
-
originalError?: unknown;
|
|
38
|
-
/** HTTP status code if applicable */
|
|
39
|
-
statusCode?: number;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Structure of Gemini API error responses
|
|
43
|
-
*/
|
|
44
|
-
export interface GeminiApiError {
|
|
45
|
-
error?: {
|
|
46
|
-
/** Error code */
|
|
47
|
-
code?: number;
|
|
48
|
-
/** Error message */
|
|
49
|
-
message?: string;
|
|
50
|
-
/** Error status */
|
|
51
|
-
status?: string;
|
|
52
|
-
/** Additional error details */
|
|
53
|
-
details?: Array<{
|
|
54
|
-
"@type"?: string;
|
|
55
|
-
reason?: string;
|
|
56
|
-
domain?: string;
|
|
57
|
-
metadata?: Record<string, string>;
|
|
58
|
-
}>;
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Custom error class for Gemini API errors
|
|
63
|
-
* Provides structured error information and retry capability
|
|
64
|
-
*/
|
|
65
|
-
export declare class GeminiError extends Error {
|
|
66
|
-
/** Error category */
|
|
67
|
-
readonly type: GeminiErrorType;
|
|
68
|
-
/** Whether the operation can be retried */
|
|
69
|
-
readonly retryable: boolean;
|
|
70
|
-
/** HTTP status code if applicable */
|
|
71
|
-
readonly statusCode?: number;
|
|
72
|
-
/** Original error that caused this error */
|
|
73
|
-
readonly originalError?: unknown;
|
|
74
|
-
/**
|
|
75
|
-
* Create a new GeminiError
|
|
76
|
-
* @param info - Error information
|
|
77
|
-
*/
|
|
78
|
-
constructor(info: GeminiErrorInfo);
|
|
79
|
-
/**
|
|
80
|
-
* Check if this error is retryable
|
|
81
|
-
* @returns true if the operation can be retried
|
|
82
|
-
*/
|
|
83
|
-
isRetryable(): boolean;
|
|
84
|
-
/**
|
|
85
|
-
* Get the error type
|
|
86
|
-
* @returns The error category
|
|
87
|
-
*/
|
|
88
|
-
getErrorType(): GeminiErrorType;
|
|
89
|
-
/**
|
|
90
|
-
* Create a GeminiError from an unknown error
|
|
91
|
-
* @param error - The original error
|
|
92
|
-
* @param info - Error information
|
|
93
|
-
* @returns A new GeminiError instance
|
|
94
|
-
*/
|
|
95
|
-
static fromError(error: unknown, info: GeminiErrorInfo): GeminiError;
|
|
96
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import type { GenerationConfig } from "@google/generative-ai";
|
|
2
|
-
/**
|
|
3
|
-
* Configuration for Gemini AI client initialization
|
|
4
|
-
*/
|
|
5
|
-
export interface GeminiConfig {
|
|
6
|
-
/** API key for authentication */
|
|
7
|
-
apiKey: string;
|
|
8
|
-
/** Default timeout in milliseconds (used by external consumers for timeout logic) */
|
|
9
|
-
defaultTimeoutMs?: number;
|
|
10
|
-
/** Default model to use for text generation */
|
|
11
|
-
textModel?: string;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Generation configuration for AI requests
|
|
15
|
-
*/
|
|
16
|
-
export type GeminiGenerationConfig = GenerationConfig;
|
|
17
|
-
/**
|
|
18
|
-
* Harm categories for content safety filtering
|
|
19
|
-
*/
|
|
20
|
-
export type GeminiHarmCategory = "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_DANGEROUS_CONTENT";
|
|
21
|
-
/**
|
|
22
|
-
* Threshold levels for blocking harmful content
|
|
23
|
-
*/
|
|
24
|
-
export type GeminiHarmBlockThreshold = "BLOCK_NONE" | "BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_ONLY_HIGH";
|
|
25
|
-
/**
|
|
26
|
-
* Content structure for Gemini API requests
|
|
27
|
-
*/
|
|
28
|
-
export interface GeminiContent {
|
|
29
|
-
/** Array of content parts (text, images, etc.) */
|
|
30
|
-
parts: GeminiPart[];
|
|
31
|
-
/** Role of the content creator (user or model) */
|
|
32
|
-
role?: "user" | "model";
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Individual content part
|
|
36
|
-
*/
|
|
37
|
-
export type GeminiPart = {
|
|
38
|
-
text: string;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Response structure from Gemini API
|
|
42
|
-
*/
|
|
43
|
-
export interface GeminiResponse {
|
|
44
|
-
/** Array of response candidates */
|
|
45
|
-
candidates?: GeminiCandidate[];
|
|
46
|
-
/** Token usage information */
|
|
47
|
-
usageMetadata?: GeminiUsageMetadata;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Individual response candidate
|
|
51
|
-
*/
|
|
52
|
-
export interface GeminiCandidate {
|
|
53
|
-
/** Generated content */
|
|
54
|
-
content: GeminiContent;
|
|
55
|
-
/** Reason for generation completion */
|
|
56
|
-
finishReason?: GeminiFinishReason;
|
|
57
|
-
/** Safety ratings for the content */
|
|
58
|
-
safetyRatings?: GeminiSafetyRating[];
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Reasons why generation finished
|
|
62
|
-
*/
|
|
63
|
-
export type GeminiFinishReason = "FINISH_REASON_UNSPECIFIED" | "STOP" | "MAX_TOKENS" | "SAFETY" | "RECITATION" | "OTHER";
|
|
64
|
-
/**
|
|
65
|
-
* Safety rating for generated content
|
|
66
|
-
*/
|
|
67
|
-
export interface GeminiSafetyRating {
|
|
68
|
-
/** Category of safety check */
|
|
69
|
-
category: GeminiHarmCategory;
|
|
70
|
-
/** Probability of content being unsafe */
|
|
71
|
-
probability: "NEGLIGIBLE" | "LOW" | "MEDIUM" | "HIGH";
|
|
72
|
-
/** Whether the content was blocked */
|
|
73
|
-
blocked?: boolean;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Token usage metadata for the request
|
|
77
|
-
*/
|
|
78
|
-
export interface GeminiUsageMetadata {
|
|
79
|
-
/** Number of tokens in the prompt */
|
|
80
|
-
promptTokenCount?: number;
|
|
81
|
-
/** Number of tokens in the response candidates */
|
|
82
|
-
candidatesTokenCount?: number;
|
|
83
|
-
/** Total number of tokens used */
|
|
84
|
-
totalTokenCount?: number;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Safety setting for a single harm category
|
|
88
|
-
*/
|
|
89
|
-
export interface GeminiSafetySetting {
|
|
90
|
-
category: GeminiHarmCategory;
|
|
91
|
-
threshold: GeminiHarmBlockThreshold;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Inline data part for binary content (images, audio)
|
|
95
|
-
*/
|
|
96
|
-
export interface GeminiInlineDataPart {
|
|
97
|
-
inlineData: {
|
|
98
|
-
mimeType: string;
|
|
99
|
-
data: string;
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* A message part that can be text or inline data
|
|
104
|
-
*/
|
|
105
|
-
export type GeminiMessagePart = GeminiPart | GeminiInlineDataPart;
|
|
106
|
-
/**
|
|
107
|
-
* Options for creating a generative model instance
|
|
108
|
-
*/
|
|
109
|
-
export interface GeminiModelOptions {
|
|
110
|
-
model?: string;
|
|
111
|
-
systemInstruction?: string;
|
|
112
|
-
safetySettings?: GeminiSafetySetting[];
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Configuration for a chat session
|
|
116
|
-
*/
|
|
117
|
-
export interface GeminiChatConfig {
|
|
118
|
-
/** Model name override */
|
|
119
|
-
model?: string;
|
|
120
|
-
/** System instruction for the model */
|
|
121
|
-
systemInstruction?: string;
|
|
122
|
-
/** Safety settings (defaults to BLOCK_NONE for all categories) */
|
|
123
|
-
safetySettings?: GeminiSafetySetting[];
|
|
124
|
-
/** Generation config (temperature, maxOutputTokens, etc.) */
|
|
125
|
-
generationConfig?: GeminiGenerationConfig;
|
|
126
|
-
/** Initial conversation history */
|
|
127
|
-
history?: GeminiContent[];
|
|
128
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Available Gemini AI models
|
|
3
|
-
*/
|
|
4
|
-
export declare const GEMINI_MODELS: {
|
|
5
|
-
/** Text generation models */
|
|
6
|
-
readonly TEXT: {
|
|
7
|
-
/** Lightweight flash model for fast text generation */
|
|
8
|
-
readonly FLASH_LITE: "gemini-2.5-flash-lite";
|
|
9
|
-
/** Balanced flash model for general use */
|
|
10
|
-
readonly FLASH: "gemini-2.5-flash";
|
|
11
|
-
/** Premium model for complex tasks */
|
|
12
|
-
readonly PRO: "gemini-2.5-pro";
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Default models to use for each category
|
|
17
|
-
*/
|
|
18
|
-
export declare const DEFAULT_MODELS: {
|
|
19
|
-
/** Default model for text generation */
|
|
20
|
-
readonly TEXT: "gemini-2.5-flash-lite";
|
|
21
|
-
/** Default model for chat sessions */
|
|
22
|
-
readonly CHAT: "gemini-2.5-flash";
|
|
23
|
-
};
|
package/dist/index.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @umituz/react-native-ai-gemini-provider
|
|
3
|
-
* Google Gemini AI provider for React Native applications
|
|
4
|
-
*/
|
|
5
|
-
export type { GeminiConfig, GeminiGenerationConfig, GeminiHarmCategory, GeminiHarmBlockThreshold, GeminiContent, GeminiPart, GeminiInlineDataPart, GeminiMessagePart, GeminiSafetySetting, GeminiModelOptions, GeminiChatConfig, GeminiResponse, GeminiCandidate, GeminiFinishReason, GeminiSafetyRating, GeminiUsageMetadata, GeminiErrorInfo, GeminiApiError, } from "./domain/entities";
|
|
6
|
-
export { GeminiErrorType, GeminiError, GEMINI_MODELS, DEFAULT_MODELS } from "./domain/entities";
|
|
7
|
-
export { geminiClient } from "./infrastructure/services/GeminiClient";
|
|
8
|
-
export { createChatSession, sendChatMessage, buildChatHistory, trimChatHistory, type ChatSendResult, type ChatHistoryMessage, type SendChatMessageOptions, } from "./infrastructure/services/ChatSession";
|
|
9
|
-
export { textGeneration } from "./infrastructure/services/TextGeneration";
|
|
10
|
-
export { structuredText } from "./infrastructure/services/StructuredText";
|
|
11
|
-
export { streaming } from "./infrastructure/services/Streaming";
|
|
12
|
-
export { useGemini } from "./presentation/hooks/useGemini";
|
|
13
|
-
export type { UseGeminiOptions, UseGeminiReturn } from "./presentation/hooks/useGemini";
|
|
14
|
-
export { ConfigBuilder, providerFactory } from "./providers/ProviderFactory";
|
|
15
|
-
export type { ProviderConfig, ProviderFactoryOptions, } from "./providers/ProviderFactory";
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { GeminiContent, GeminiGenerationConfig } from "../../domain/entities";
|
|
2
|
-
import type { GenerativeModel } from "@google/generative-ai";
|
|
3
|
-
import type { Part } from "@google/generative-ai";
|
|
4
|
-
export interface BaseRequestOptions {
|
|
5
|
-
model: string;
|
|
6
|
-
contents: GeminiContent[];
|
|
7
|
-
generationConfig?: GeminiGenerationConfig;
|
|
8
|
-
signal?: AbortSignal;
|
|
9
|
-
}
|
|
10
|
-
export declare abstract class BaseGeminiService {
|
|
11
|
-
protected validateAndPrepare(options: BaseRequestOptions): {
|
|
12
|
-
genModel: GenerativeModel;
|
|
13
|
-
sdkContents: Array<{
|
|
14
|
-
role: string;
|
|
15
|
-
parts: Part[];
|
|
16
|
-
}>;
|
|
17
|
-
};
|
|
18
|
-
protected handleError(error: unknown, abortMessage: string): never;
|
|
19
|
-
protected createRequestOptions(sdkContents: Array<{
|
|
20
|
-
role: string;
|
|
21
|
-
parts: Part[];
|
|
22
|
-
}>, generationConfig?: GeminiGenerationConfig): {
|
|
23
|
-
contents: {
|
|
24
|
-
role: string;
|
|
25
|
-
parts: Part[];
|
|
26
|
-
}[];
|
|
27
|
-
generationConfig: import("@google/generative-ai").GenerationConfig | undefined;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { GeminiChatConfig, GeminiGenerationConfig, GeminiContent, GeminiInlineDataPart, GeminiMessagePart, GeminiSafetySetting } from "../../domain/entities";
|
|
2
|
-
export interface ChatSendResult {
|
|
3
|
-
text: string;
|
|
4
|
-
finishReason?: string;
|
|
5
|
-
}
|
|
6
|
-
/** A simple chat message (user/assistant/system) */
|
|
7
|
-
export interface ChatHistoryMessage {
|
|
8
|
-
readonly role: "user" | "assistant" | "system";
|
|
9
|
-
readonly content: string;
|
|
10
|
-
}
|
|
11
|
-
/** Options for the high-level sendChatMessage() */
|
|
12
|
-
export interface SendChatMessageOptions {
|
|
13
|
-
/** Conversation history */
|
|
14
|
-
history: ChatHistoryMessage[];
|
|
15
|
-
/** Current user message text */
|
|
16
|
-
message: string;
|
|
17
|
-
/** System instruction for the model */
|
|
18
|
-
systemPrompt?: string;
|
|
19
|
-
/** Model name (defaults to gemini-2.5-flash) */
|
|
20
|
-
model?: string;
|
|
21
|
-
/** Generation config (temperature, maxOutputTokens, etc.) */
|
|
22
|
-
generationConfig?: GeminiGenerationConfig;
|
|
23
|
-
/** Safety settings (defaults to BLOCK_NONE for all) */
|
|
24
|
-
safetySettings?: GeminiSafetySetting[];
|
|
25
|
-
/** Pre-built attachments (base64 inline data parts for images/audio) */
|
|
26
|
-
attachments?: GeminiInlineDataPart[];
|
|
27
|
-
/** Max character budget for history trimming (default 12000) */
|
|
28
|
-
historyMaxChars?: number;
|
|
29
|
-
/** Min messages to always keep regardless of budget (default 4) */
|
|
30
|
-
historyMinMessages?: number;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Converts chat messages (user/assistant/system) to Gemini SDK content format.
|
|
34
|
-
* Skips system messages, merges consecutive same-role messages.
|
|
35
|
-
*/
|
|
36
|
-
export declare function buildChatHistory(history: readonly ChatHistoryMessage[]): GeminiContent[];
|
|
37
|
-
/**
|
|
38
|
-
* Trims conversation history to fit within a character budget.
|
|
39
|
-
* Keeps at least `minMessages` entries regardless of budget.
|
|
40
|
-
*/
|
|
41
|
-
export declare function trimChatHistory(history: ChatHistoryMessage[], maxChars?: number, minMessages?: number): ChatHistoryMessage[];
|
|
42
|
-
/**
|
|
43
|
-
* Creates a Gemini chat session with full support for system instructions,
|
|
44
|
-
* safety settings, generation config, and multi-turn conversation history.
|
|
45
|
-
*/
|
|
46
|
-
export declare function createChatSession(config?: GeminiChatConfig): {
|
|
47
|
-
send(parts: GeminiMessagePart[]): Promise<ChatSendResult>;
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* All-in-one: trims history, builds session, sends message, handles safety.
|
|
51
|
-
* Returns the AI response text.
|
|
52
|
-
*
|
|
53
|
-
* ```ts
|
|
54
|
-
* const text = await sendChatMessage({
|
|
55
|
-
* history: messages,
|
|
56
|
-
* message: "hello",
|
|
57
|
-
* systemPrompt: "You are Aria...",
|
|
58
|
-
* model: GEMINI_MODELS.TEXT.FLASH,
|
|
59
|
-
* generationConfig: { temperature: 0.7, maxOutputTokens: 512 },
|
|
60
|
-
* });
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
export declare function sendChatMessage(opts: SendChatMessageOptions): Promise<string>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type GenerativeModel } from "@google/generative-ai";
|
|
2
|
-
import type { GeminiConfig, GeminiModelOptions } from "../../domain/entities";
|
|
3
|
-
declare class GeminiClient {
|
|
4
|
-
private client;
|
|
5
|
-
private config;
|
|
6
|
-
private initialized;
|
|
7
|
-
initialize(config: GeminiConfig): void;
|
|
8
|
-
/**
|
|
9
|
-
* Returns a GenerativeModel configured with optional safety settings and system instruction.
|
|
10
|
-
* When no safety settings are provided, defaults to BLOCK_NONE for all categories.
|
|
11
|
-
*/
|
|
12
|
-
getModel(modelNameOrOptions?: string | GeminiModelOptions): GenerativeModel;
|
|
13
|
-
reset(): void;
|
|
14
|
-
}
|
|
15
|
-
export declare const geminiClient: GeminiClient;
|
|
16
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { GeminiConfig } from "../../domain/entities";
|
|
2
|
-
export declare class GeminiProvider {
|
|
3
|
-
readonly providerId = "gemini";
|
|
4
|
-
readonly providerName = "Google Gemini";
|
|
5
|
-
initialize(config: GeminiConfig): void;
|
|
6
|
-
isInitialized(): boolean;
|
|
7
|
-
reset(): void;
|
|
8
|
-
generateStructuredText<T>(prompt: string, schema: Record<string, unknown>, model: string): Promise<T>;
|
|
9
|
-
}
|
|
10
|
-
export declare const geminiProvider: GeminiProvider;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { BaseGeminiService } from "./BaseService";
|
|
2
|
-
import type { GeminiContent, GeminiGenerationConfig } from "../../domain/entities";
|
|
3
|
-
declare class StreamingService extends BaseGeminiService {
|
|
4
|
-
streamContent(model: string, contents: GeminiContent[], onChunk: (text: string) => void, generationConfig?: GeminiGenerationConfig, signal?: AbortSignal): Promise<string>;
|
|
5
|
-
}
|
|
6
|
-
export declare const streaming: StreamingService;
|
|
7
|
-
export {};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { GeminiGenerationConfig } from "../../domain/entities";
|
|
2
|
-
declare class StructuredTextService {
|
|
3
|
-
generateStructuredText<T>(model: string, prompt: string, schema: Record<string, unknown>, config?: Omit<GeminiGenerationConfig, "responseMimeType" | "responseSchema">, signal?: AbortSignal): Promise<T>;
|
|
4
|
-
}
|
|
5
|
-
export declare const structuredText: StructuredTextService;
|
|
6
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { BaseGeminiService } from "./BaseService";
|
|
2
|
-
import type { GeminiContent, GeminiGenerationConfig, GeminiResponse } from "../../domain/entities";
|
|
3
|
-
declare class TextGenerationService extends BaseGeminiService {
|
|
4
|
-
generateContent(model: string, contents: GeminiContent[], generationConfig?: GeminiGenerationConfig, signal?: AbortSignal): Promise<GeminiResponse>;
|
|
5
|
-
generateText(model: string, prompt: string, config?: GeminiGenerationConfig, signal?: AbortSignal): Promise<string>;
|
|
6
|
-
}
|
|
7
|
-
export declare const textGeneration: TextGenerationService;
|
|
8
|
-
export {};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { geminiClient } from "./GeminiClient";
|
|
2
|
-
export { textGeneration } from "./TextGeneration";
|
|
3
|
-
export { structuredText } from "./StructuredText";
|
|
4
|
-
export { streaming } from "./Streaming";
|
|
5
|
-
export { geminiProvider, GeminiProvider } from "./GeminiProvider";
|
|
6
|
-
export { createChatSession, sendChatMessage, buildChatHistory, trimChatHistory, resolveAudioMimeType, resolveImageMimeType, type ChatSendResult, type ChatHistoryMessage, type SendChatMessageOptions, } from "./ChatSession";
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
export interface TelemetryEvent {
|
|
2
|
-
type: "error";
|
|
3
|
-
timestamp: number;
|
|
4
|
-
model?: string;
|
|
5
|
-
feature?: string;
|
|
6
|
-
metadata?: Record<string, unknown>;
|
|
7
|
-
}
|
|
8
|
-
export type TelemetryListener = (event: TelemetryEvent) => void;
|
|
9
|
-
declare class TelemetryHooks {
|
|
10
|
-
private listeners;
|
|
11
|
-
private failedListeners;
|
|
12
|
-
private readonly MAX_FAILURES;
|
|
13
|
-
private listenerFailureCounts;
|
|
14
|
-
/**
|
|
15
|
-
* Register a telemetry listener
|
|
16
|
-
*
|
|
17
|
-
* @returns Unsubscribe function - IMPORTANT: Call this when done listening to prevent memory leaks
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* const unsubscribe = telemetryHooks.subscribe((event) => console.log(event));
|
|
22
|
-
* // ... later when done
|
|
23
|
-
* unsubscribe(); // Prevents memory leak
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
subscribe(listener: TelemetryListener): () => void;
|
|
27
|
-
/**
|
|
28
|
-
* Emit a telemetry event to all listeners
|
|
29
|
-
*/
|
|
30
|
-
emit(event: TelemetryEvent): void;
|
|
31
|
-
/**
|
|
32
|
-
* Log error
|
|
33
|
-
*/
|
|
34
|
-
logError(model: string, error: Error, feature?: string): void;
|
|
35
|
-
/**
|
|
36
|
-
* Remove a specific listener
|
|
37
|
-
*/
|
|
38
|
-
unsubscribe(listener: TelemetryListener): void;
|
|
39
|
-
}
|
|
40
|
-
export declare const telemetryHooks: TelemetryHooks;
|
|
41
|
-
export {};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Async State Execution Utilities
|
|
3
|
-
* Utilities for managing asynchronous operation state
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Callbacks for async operation outcomes
|
|
7
|
-
*/
|
|
8
|
-
export interface AsyncStateCallbacks<T = string> {
|
|
9
|
-
onSuccess?: (result: T) => void;
|
|
10
|
-
onError?: (error: string) => void;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Setter functions for updating state
|
|
14
|
-
*/
|
|
15
|
-
export interface AsyncStateSetters<T = string, U = unknown> {
|
|
16
|
-
setIsLoading: (value: boolean) => void;
|
|
17
|
-
setError: (value: string | null) => void;
|
|
18
|
-
setResult: (value: T | null) => void;
|
|
19
|
-
setSecondaryResult?: (value: U | null) => void;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Configuration for executeWithState
|
|
23
|
-
*/
|
|
24
|
-
export interface AsyncStateConfig<T = string> {
|
|
25
|
-
resetState?: boolean;
|
|
26
|
-
transformResult?: (result: T) => T;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Execute an async operation with automatic state management
|
|
30
|
-
*
|
|
31
|
-
* @param setters - State setter functions
|
|
32
|
-
* @param callbacks - Optional callbacks for success/error
|
|
33
|
-
* @param execute - The async operation to execute
|
|
34
|
-
* @param onResult - Function to handle successful result
|
|
35
|
-
* @param config - Optional configuration
|
|
36
|
-
*
|
|
37
|
-
* @returns The result or null if failed/aborted
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```ts
|
|
41
|
-
* const result = await executeWithState(
|
|
42
|
-
* { setIsLoading, setError, setResult },
|
|
43
|
-
* { onSuccess: console.log },
|
|
44
|
-
* () => apiCall(),
|
|
45
|
-
* (data) => setResult(data)
|
|
46
|
-
* );
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
export declare function executeWithState<T, U = unknown>(setters: AsyncStateSetters<T, U>, callbacks: AsyncStateCallbacks<T>, execute: () => Promise<T>, onResult: (result: T) => void, config?: AsyncStateConfig<T>): Promise<T | null>;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Content Mapper Utilities
|
|
3
|
-
* Handles transformation between domain content and SDK format
|
|
4
|
-
*/
|
|
5
|
-
import type { Part } from "@google/generative-ai";
|
|
6
|
-
import type { GeminiContent, GeminiPart, GeminiResponse } from "../../domain/entities";
|
|
7
|
-
/**
|
|
8
|
-
* Convert domain content to SDK format
|
|
9
|
-
* Preserves both text and inlineData parts
|
|
10
|
-
*/
|
|
11
|
-
export declare function toSdkContent(contents: GeminiContent[]): Array<{
|
|
12
|
-
role: string;
|
|
13
|
-
parts: Part[];
|
|
14
|
-
}>;
|
|
15
|
-
/**
|
|
16
|
-
* Create a simple text content
|
|
17
|
-
*/
|
|
18
|
-
export declare function createTextContent(text: string, role?: "user" | "model"): GeminiContent;
|
|
19
|
-
/**
|
|
20
|
-
* Transform SDK response to domain format
|
|
21
|
-
*/
|
|
22
|
-
export declare function transformResponse(response: {
|
|
23
|
-
candidates?: Array<{
|
|
24
|
-
content: {
|
|
25
|
-
parts: Array<{
|
|
26
|
-
text?: string;
|
|
27
|
-
}>;
|
|
28
|
-
role?: string;
|
|
29
|
-
};
|
|
30
|
-
finishReason?: string;
|
|
31
|
-
safetyRatings?: Array<{
|
|
32
|
-
category: string;
|
|
33
|
-
probability: string;
|
|
34
|
-
}>;
|
|
35
|
-
}>;
|
|
36
|
-
usageMetadata?: {
|
|
37
|
-
promptTokenCount?: number;
|
|
38
|
-
candidatesTokenCount?: number;
|
|
39
|
-
totalTokenCount?: number;
|
|
40
|
-
};
|
|
41
|
-
}): GeminiResponse;
|
|
42
|
-
/**
|
|
43
|
-
* Extract text from content parts
|
|
44
|
-
*/
|
|
45
|
-
export declare function extractTextFromParts(parts: GeminiPart[] | undefined): string;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JSON Parser Utilities
|
|
3
|
-
* Handles cleaning and parsing JSON responses from AI models
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Parse JSON response with error handling
|
|
7
|
-
* @throws Error if parsing fails with detailed error message
|
|
8
|
-
*/
|
|
9
|
-
export declare function parseJsonResponse<T>(text: string): T;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stream Processing Utilities
|
|
3
|
-
* Reusable stream handling logic
|
|
4
|
-
*/
|
|
5
|
-
interface StreamChunk {
|
|
6
|
-
text: () => string;
|
|
7
|
-
}
|
|
8
|
-
type ChunkCallback = (text: string) => void;
|
|
9
|
-
type ErrorLogger = (error: unknown, context?: string) => void;
|
|
10
|
-
/**
|
|
11
|
-
* Process async stream with chunk callback
|
|
12
|
-
*/
|
|
13
|
-
export declare function processStream(stream: AsyncIterable<StreamChunk>, onChunk: ChunkCallback, onError?: ErrorLogger): Promise<string>;
|
|
14
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useGemini, type UseGeminiOptions, type UseGeminiReturn } from "./useGemini";
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { GeminiGenerationConfig } from "../../domain/entities";
|
|
2
|
-
export interface UseGeminiOptions {
|
|
3
|
-
model?: string;
|
|
4
|
-
generationConfig?: GeminiGenerationConfig;
|
|
5
|
-
onSuccess?: (result: string) => void;
|
|
6
|
-
onError?: (error: string) => void;
|
|
7
|
-
}
|
|
8
|
-
export interface UseGeminiReturn {
|
|
9
|
-
generate: (prompt: string) => Promise<void>;
|
|
10
|
-
generateJSON: <T>(prompt: string, schema: Record<string, unknown>) => Promise<T | null>;
|
|
11
|
-
result: string | null;
|
|
12
|
-
jsonResult: unknown;
|
|
13
|
-
isGenerating: boolean;
|
|
14
|
-
error: string | null;
|
|
15
|
-
reset: () => void;
|
|
16
|
-
}
|
|
17
|
-
export declare function useGemini(options?: UseGeminiOptions): UseGeminiReturn;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Operation Manager Hook
|
|
3
|
-
* Reusable abort controller and operation ID management
|
|
4
|
-
* Eliminates code duplication in hooks
|
|
5
|
-
*/
|
|
6
|
-
export interface OperationManager {
|
|
7
|
-
/**
|
|
8
|
-
* Execute an operation with abort support and operation ID tracking
|
|
9
|
-
*/
|
|
10
|
-
executeOperation: <T>(operation: (signal: AbortSignal, operationId: number) => Promise<T>) => Promise<T>;
|
|
11
|
-
/**
|
|
12
|
-
* Abort current operation
|
|
13
|
-
*/
|
|
14
|
-
abort: () => void;
|
|
15
|
-
/**
|
|
16
|
-
* Check if current operation is active
|
|
17
|
-
*/
|
|
18
|
-
isOperationActive: (operationId: number) => boolean;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Hook for managing operations with abort control
|
|
22
|
-
*/
|
|
23
|
-
export declare function useOperationManager(): OperationManager;
|