@kenkaiiii/gg-core 4.4.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.
@@ -0,0 +1,295 @@
1
+ export { ContextWindowOptions, MODELS, ModelInfo, getContextWindow, getDefaultModel, getMaxThinkingLevel, getModel, getModelsForProvider, getSummaryModel, usesOpenAICodexTransport } from './model-registry.js';
2
+ import { Provider, ThinkingLevel } from '@kenkaiiii/gg-ai';
3
+ export { AppPaths, getAppPaths } from './paths.js';
4
+
5
+ declare function getSupportedThinkingLevels(provider: Provider, model: string): readonly ThinkingLevel[];
6
+ declare function isThinkingLevelSupported(provider: Provider, model: string, level: ThinkingLevel): boolean;
7
+ declare function getNextThinkingLevel(provider: Provider, model: string, current: ThinkingLevel | undefined): ThinkingLevel | undefined;
8
+
9
+ type LogLevel = "INFO" | "ERROR" | "WARN" | "DEBUG";
10
+ /**
11
+ * Open the debug log in append mode, tagging this process with a session id and
12
+ * remembering `name` for the shutdown line. Idempotent — re-calling while open
13
+ * is a no-op. Returns true only when it *newly* opened the file (so callers can
14
+ * write a one-time startup line); returns false if already open or if the file
15
+ * could not be opened.
16
+ */
17
+ declare function openLog(filePath: string, name: string): boolean;
18
+ /** Session identifier included on every log line as `sid=<id>`. */
19
+ declare function getSessionId(): string;
20
+ /** True if the logger has an open file descriptor. */
21
+ declare function isLoggerOpen(): boolean;
22
+ /** Write a timestamped log line. No-op if the logger is not open. */
23
+ declare function log(level: LogLevel, category: string, message: string, data?: Record<string, unknown>): void;
24
+ /**
25
+ * Register a cleanup callback (e.g. an EventBus unsubscriber) to run when the
26
+ * logger closes. Lets app-side bridges hook into the shared lifecycle without
27
+ * the core needing to know about app types.
28
+ */
29
+ declare function registerLogCleanup(fn: () => void): void;
30
+ /**
31
+ * Write a shutdown line (unless suppressed), close the file descriptor, and run
32
+ * any registered cleanups.
33
+ */
34
+ declare function closeLogger(opts?: {
35
+ shutdownLine?: boolean;
36
+ }): void;
37
+
38
+ /**
39
+ * Simple file-based lock with PID tracking and stale detection.
40
+ * Uses atomic file creation (wx flag) to prevent races.
41
+ */
42
+ declare function withFileLock<T>(filePath: string, fn: () => Promise<T>): Promise<T>;
43
+
44
+ /**
45
+ * Resolve the current Claude Code release version for spoofing the claude-cli
46
+ * User-Agent on OAuth and inference requests. Cached in-memory for the process
47
+ * lifetime and on disk for 24h. Falls back to a hardcoded constant if the npm
48
+ * registry is unreachable and no cache exists.
49
+ */
50
+ declare function getClaudeCodeVersion(): Promise<string>;
51
+ /** Build the User-Agent string Anthropic's OAuth + inference edges expect. */
52
+ declare function getClaudeCliUserAgent(): Promise<string>;
53
+
54
+ interface OAuthCredentials {
55
+ accessToken: string;
56
+ refreshToken: string;
57
+ expiresAt: number;
58
+ accountId?: string;
59
+ projectId?: string;
60
+ baseUrl?: string;
61
+ }
62
+ interface OAuthLoginCallbacks {
63
+ onOpenUrl: (url: string) => void;
64
+ onPromptCode: (message: string) => Promise<string>;
65
+ onStatus: (message: string) => void;
66
+ }
67
+
68
+ declare class AuthStorage {
69
+ private data;
70
+ private filePath;
71
+ private loaded;
72
+ /** Per-provider lock to serialize concurrent refresh calls. */
73
+ private refreshLocks;
74
+ constructor(filePath?: string);
75
+ /** Path to the on-disk auth file. Useful for status output. */
76
+ get path(): string;
77
+ /** List provider keys with stored credentials. */
78
+ listProviders(): Promise<string[]>;
79
+ /** True if credentials exist for `provider`. */
80
+ hasCredentials(provider: string): Promise<boolean>;
81
+ load(): Promise<void>;
82
+ private ensureLoaded;
83
+ getCredentials(provider: string): Promise<OAuthCredentials | undefined>;
84
+ setCredentials(provider: string, creds: OAuthCredentials): Promise<void>;
85
+ clearCredentials(provider: string): Promise<void>;
86
+ clearAll(): Promise<void>;
87
+ /**
88
+ * Returns valid credentials, auto-refreshing if expired.
89
+ * If `forceRefresh` is true, refreshes even if the token hasn't expired
90
+ * (useful when the provider rejects a token with 401 before its stored expiry).
91
+ * Throws if not logged in.
92
+ */
93
+ resolveCredentials(provider: string, opts?: {
94
+ forceRefresh?: boolean;
95
+ }): Promise<OAuthCredentials>;
96
+ /**
97
+ * Returns a valid access token, auto-refreshing if expired.
98
+ * Throws if not logged in.
99
+ */
100
+ resolveToken(provider: string): Promise<string>;
101
+ private save;
102
+ }
103
+ declare class NotLoggedInError extends Error {
104
+ provider: string;
105
+ constructor(provider: string);
106
+ }
107
+
108
+ declare function generatePKCE(): Promise<{
109
+ verifier: string;
110
+ challenge: string;
111
+ }>;
112
+
113
+ declare function loginAnthropic(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials>;
114
+ declare function refreshAnthropicToken(refreshToken: string): Promise<OAuthCredentials>;
115
+
116
+ declare function loginOpenAI(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials>;
117
+ declare function refreshOpenAIToken(refreshToken: string): Promise<OAuthCredentials>;
118
+
119
+ declare function loginGemini(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials>;
120
+ declare function refreshGeminiToken(refreshToken: string): Promise<OAuthCredentials>;
121
+
122
+ /**
123
+ * Minimal Telegram Bot API client using raw fetch().
124
+ * Supports long polling, markdown messages, inline keyboards, and message splitting.
125
+ */
126
+ interface TelegramConfig {
127
+ botToken: string;
128
+ /** Only accept messages from this Telegram user ID. */
129
+ allowedUserId: number;
130
+ }
131
+ interface TelegramUpdate {
132
+ update_id: number;
133
+ message?: {
134
+ message_id: number;
135
+ from: {
136
+ id: number;
137
+ first_name: string;
138
+ };
139
+ chat: {
140
+ id: number;
141
+ type: string;
142
+ title?: string;
143
+ };
144
+ text?: string;
145
+ voice?: {
146
+ file_id: string;
147
+ duration: number;
148
+ mime_type?: string;
149
+ file_size?: number;
150
+ };
151
+ };
152
+ callback_query?: {
153
+ id: string;
154
+ from: {
155
+ id: number;
156
+ };
157
+ message: {
158
+ chat: {
159
+ id: number;
160
+ };
161
+ };
162
+ data: string;
163
+ };
164
+ my_chat_member?: {
165
+ chat: {
166
+ id: number;
167
+ type: string;
168
+ title?: string;
169
+ };
170
+ from: {
171
+ id: number;
172
+ };
173
+ new_chat_member: {
174
+ status: string;
175
+ };
176
+ };
177
+ }
178
+ interface InlineButton {
179
+ text: string;
180
+ callback_data: string;
181
+ }
182
+ /** Incoming message with chat context. */
183
+ interface TelegramMessage {
184
+ text: string;
185
+ chatId: number;
186
+ chatType: "private" | "group" | "supergroup" | "channel";
187
+ chatTitle?: string;
188
+ }
189
+ /** Incoming voice note with chat context. */
190
+ interface TelegramVoiceMessage {
191
+ fileId: string;
192
+ duration: number;
193
+ chatId: number;
194
+ chatType: "private" | "group" | "supergroup" | "channel";
195
+ chatTitle?: string;
196
+ }
197
+ declare class TelegramBot {
198
+ private token;
199
+ private allowedUserId;
200
+ private offset;
201
+ private running;
202
+ private onMessage;
203
+ private onVoiceMessage;
204
+ private onCallback;
205
+ private onBotAdded;
206
+ private onBotRemoved;
207
+ constructor(config: TelegramConfig);
208
+ /** Register handler for incoming text messages. */
209
+ onText(handler: (msg: TelegramMessage) => void): void;
210
+ /** Register handler for incoming voice notes. */
211
+ onVoice(handler: (msg: TelegramVoiceMessage) => void): void;
212
+ /** Register handler for inline keyboard button presses. */
213
+ onCallbackQuery(handler: (data: string, chatId: number) => void): void;
214
+ /** Register handler for when the bot is added to a group. */
215
+ onAddedToGroup(handler: (chatId: number, chatTitle?: string) => void): void;
216
+ /** Register handler for when the bot is removed from a group. */
217
+ onRemovedFromGroup(handler: (chatId: number) => void): void;
218
+ /** Start long polling. Blocks until stop() is called. */
219
+ start(): Promise<void>;
220
+ /** Stop long polling. */
221
+ stop(): void;
222
+ /** Send a text message to a specific chat. Converts markdown and splits long messages. */
223
+ send(chatId: number, text: string, buttons?: InlineButton[][]): Promise<void>;
224
+ /** Send a plain text message (no markdown parsing) to a specific chat. */
225
+ sendPlain(chatId: number, text: string): Promise<void>;
226
+ /** Send a typing indicator to a specific chat. */
227
+ sendTyping(chatId: number): Promise<void>;
228
+ /** Get a direct download URL for a Telegram file. */
229
+ getFileUrl(fileId: string): Promise<string>;
230
+ private getUpdates;
231
+ private handleUpdate;
232
+ private apiCall;
233
+ }
234
+
235
+ /**
236
+ * Voice note transcription using local Whisper model.
237
+ * Uses @huggingface/transformers (pure JS/WASM) — no native deps, no API keys.
238
+ * Model (~75MB) is downloaded on first use and cached locally.
239
+ */
240
+ /** Optional callback for model download progress. */
241
+ type ProgressCallback = (info: {
242
+ status: string;
243
+ progress?: number;
244
+ file?: string;
245
+ }) => void;
246
+ /** Set a callback to receive model download progress updates. */
247
+ declare function setProgressCallback(cb: ProgressCallback | null): void;
248
+ /**
249
+ * Resample audio from one sample rate to another using linear interpolation.
250
+ */
251
+ declare function resample(audio: Float32Array, fromRate: number, toRate: number): Float32Array;
252
+ /**
253
+ * Downmix multi-channel audio to mono by averaging all channels.
254
+ */
255
+ declare function downmixToMono(channelData: Float32Array[]): Float32Array;
256
+ /**
257
+ * Decode OGG Opus audio buffer to 16kHz mono PCM Float32Array.
258
+ */
259
+ declare function decodeOggOpus(buffer: Uint8Array): Promise<Float32Array>;
260
+ /** Whether the model has been loaded already. */
261
+ declare function isModelLoaded(): boolean;
262
+ /**
263
+ * Transcribe a voice message from its Telegram file URL.
264
+ * Downloads the OGG Opus file, decodes to PCM, and runs Whisper locally.
265
+ */
266
+ declare function transcribeVoice(fileUrl: string): Promise<string>;
267
+
268
+ interface AutoUpdateConfig {
269
+ /** npm package to self-update, e.g. "@kenkaiiii/ggcoder". */
270
+ packageName: string;
271
+ /**
272
+ * Absolute path to this app's update-state.json, or a thunk resolving it.
273
+ * A thunk keeps path resolution lazy so callers can derive it from
274
+ * `os.homedir()` without freezing the value at module-load time (which
275
+ * breaks tests that mock the home directory after import).
276
+ */
277
+ stateFilePath: string | (() => string);
278
+ /** Builds the in-session "update available" notification. */
279
+ periodicMessage?: (args: {
280
+ currentVersion: string;
281
+ latestVersion: string;
282
+ updateCommand: string;
283
+ }) => string;
284
+ }
285
+ interface AutoUpdater {
286
+ checkAndAutoUpdate(currentVersion: string): string | null;
287
+ getPendingUpdate(currentVersion: string): {
288
+ latestVersion: string;
289
+ } | null;
290
+ startPeriodicUpdateCheck(currentVersion: string, onUpdate: (message: string) => void): void;
291
+ stopPeriodicUpdateCheck(): void;
292
+ }
293
+ declare function createAutoUpdater(config: AutoUpdateConfig): AutoUpdater;
294
+
295
+ export { AuthStorage, type AutoUpdateConfig, type AutoUpdater, type InlineButton, type LogLevel, NotLoggedInError, type OAuthCredentials, type OAuthLoginCallbacks, type ProgressCallback, TelegramBot, type TelegramConfig, type TelegramMessage, type TelegramUpdate, type TelegramVoiceMessage, closeLogger, createAutoUpdater, decodeOggOpus, downmixToMono, generatePKCE, getClaudeCliUserAgent, getClaudeCodeVersion, getNextThinkingLevel, getSessionId, getSupportedThinkingLevels, isLoggerOpen, isModelLoaded, isThinkingLevelSupported, log, loginAnthropic, loginGemini, loginOpenAI, openLog, refreshAnthropicToken, refreshGeminiToken, refreshOpenAIToken, registerLogCleanup, resample, setProgressCallback, transcribeVoice, withFileLock };