@prestyj/core 5.28.1 → 5.29.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/dist/{chunk-CK6UIITE.js → chunk-N73LFQ3N.js} +39 -25
- package/dist/chunk-N73LFQ3N.js.map +1 -0
- package/dist/index.cjs +70 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +35 -12
- package/dist/index.js.map +1 -1
- package/dist/model-registry.cjs +11 -17
- package/dist/model-registry.cjs.map +1 -1
- package/dist/model-registry.d.cts +11 -19
- package/dist/model-registry.d.ts +11 -19
- package/dist/model-registry.js +1 -3
- package/package.json +2 -2
- package/dist/chunk-CK6UIITE.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { ModelInfo } from './model-registry.cjs';
|
|
2
|
-
export { ContextWindowOptions, DEFAULT_MAX_VIDEO_BYTES, MODELS, clearRuntimeModels, getAllModels, getAuthStorageKey, getAuthStorageKeys, getContextWindow, getDefaultModel, getDefaultThinkingLevel,
|
|
2
|
+
export { ContextWindowOptions, DEFAULT_MAX_VIDEO_BYTES, MODELS, clearRuntimeModels, getAllModels, getAuthStorageKey, getAuthStorageKeys, getContextWindow, getDefaultModel, getDefaultThinkingLevel, getMaxThinkingLevel, getModel, getModelsForProvider, getSummaryModel, getToolResultCharLimit, getVideoByteLimit, registerRuntimeModels, usesOpenAICodexTransport } from './model-registry.cjs';
|
|
3
3
|
import { ThinkingLevel, Provider } from '@prestyj/ai';
|
|
4
4
|
export { AppPaths, getAppPaths } from './paths.cjs';
|
|
5
5
|
|
|
6
6
|
declare function getSupportedThinkingLevels(provider: Provider, model: string): readonly ThinkingLevel[];
|
|
7
|
+
/**
|
|
8
|
+
* The lowest effort `model` accepts — the first rung of its ladder, never
|
|
9
|
+
* "off". Used for background work (compaction summaries, `model: fast`
|
|
10
|
+
* agents) that runs on the active model but doesn't need deep reasoning.
|
|
11
|
+
* Undefined only when the model cannot reason at all, since sending it any
|
|
12
|
+
* effort would be rejected.
|
|
13
|
+
*/
|
|
14
|
+
declare function getLowestThinkingLevel(provider: Provider, model: string): ThinkingLevel | undefined;
|
|
7
15
|
declare function isThinkingLevelSupported(provider: Provider, model: string, level: ThinkingLevel): boolean;
|
|
8
16
|
declare function getNextThinkingLevel(provider: Provider, model: string, current: ThinkingLevel | undefined): ThinkingLevel | undefined;
|
|
9
17
|
/**
|
|
@@ -685,6 +693,8 @@ declare class TelegramBot {
|
|
|
685
693
|
private allowedUserId;
|
|
686
694
|
private offset;
|
|
687
695
|
private running;
|
|
696
|
+
/** Aborts the in-flight long poll so stop() takes effect immediately. */
|
|
697
|
+
private pollAbort;
|
|
688
698
|
private onMessage;
|
|
689
699
|
private onVoiceMessage;
|
|
690
700
|
private onCallback;
|
|
@@ -778,4 +788,4 @@ interface AutoUpdater {
|
|
|
778
788
|
}
|
|
779
789
|
declare function createAutoUpdater(config: AutoUpdateConfig): AutoUpdater;
|
|
780
790
|
|
|
781
|
-
export { AuthStorage, type AutoUpdateConfig, type AutoUpdater, DEFAULT_LOCAL_ENDPOINTS, type DiscoverOptions, type DiscoveryResult, type DualAuthProvider, FALLBACK_CONTEXT_WINDOW, type InlineButton, LOCAL_API_KEY_PLACEHOLDER, LOCAL_AUTH_KEY_PREFIX, type LocalEndpoint, type LocalEndpointKind, type LocalEndpointProbe, type LocalModel, type LogLevel, MOONSHOT_OAUTH_KEY, ModelInfo, NotLoggedInError, type OAuthCredentials, type OAuthLoginCallbacks, PLAN_MODE_THINKING_CAP, type ProbeOptions, type ProgressCallback, SubscriptionUsageError, type SubscriptionUsageProvider, type SubscriptionUsageSnapshot, type SubscriptionUsageWindow, TelegramBot, type TelegramConfig, type TelegramMessage, type TelegramUpdate, type TelegramVoiceMessage, XAI_OAUTH_KEY, XIAOMI_CREDITS_KEY, clampThinkingForPlanMode, clearLocalDiscoveryCache, closeLogger, compareClaudeCodeVersions, createAutoUpdater, decodeOggOpus, discoverLocalModels, downmixToMono, dualAuthProvider, dualAuthProviderByOAuthKey, endpointRoot, fetchSubscriptionUsage, findProbedModel, formatLocalModelId, generatePKCE, getClaudeCliUserAgent, getClaudeCodeVersion, getNextThinkingLevel, getSessionId, getSupportedThinkingLevels, grokCliBaseUrl, grokCliHeaders, isGrokCliEndpoint, isKimiCodingEndpoint, isLocalModelId, isLoggerOpen, isModelLoaded, isThinkingLevelSupported, kimiCodeBaseUrl, kimiCodingHeaders, localAuthStorageKey, log, loginAnthropic, loginGemini, loginKimi, loginOpenAI, loginXai, oauthStorageKey, openLog, parseLocalModelId, probeEndpoint, providerStorageKeys, readStoredBaseUrlSync, recordRequiredClaudeCodeVersion, refreshAnthropicToken, refreshGeminiToken, refreshKimiToken, refreshOpenAIToken, refreshXaiToken, registerLogCleanup, resample, setProgressCallback, toModelInfo, transcribeVoice, withFileLock };
|
|
791
|
+
export { AuthStorage, type AutoUpdateConfig, type AutoUpdater, DEFAULT_LOCAL_ENDPOINTS, type DiscoverOptions, type DiscoveryResult, type DualAuthProvider, FALLBACK_CONTEXT_WINDOW, type InlineButton, LOCAL_API_KEY_PLACEHOLDER, LOCAL_AUTH_KEY_PREFIX, type LocalEndpoint, type LocalEndpointKind, type LocalEndpointProbe, type LocalModel, type LogLevel, MOONSHOT_OAUTH_KEY, ModelInfo, NotLoggedInError, type OAuthCredentials, type OAuthLoginCallbacks, PLAN_MODE_THINKING_CAP, type ProbeOptions, type ProgressCallback, SubscriptionUsageError, type SubscriptionUsageProvider, type SubscriptionUsageSnapshot, type SubscriptionUsageWindow, TelegramBot, type TelegramConfig, type TelegramMessage, type TelegramUpdate, type TelegramVoiceMessage, XAI_OAUTH_KEY, XIAOMI_CREDITS_KEY, clampThinkingForPlanMode, clearLocalDiscoveryCache, closeLogger, compareClaudeCodeVersions, createAutoUpdater, decodeOggOpus, discoverLocalModels, downmixToMono, dualAuthProvider, dualAuthProviderByOAuthKey, endpointRoot, fetchSubscriptionUsage, findProbedModel, formatLocalModelId, generatePKCE, getClaudeCliUserAgent, getClaudeCodeVersion, getLowestThinkingLevel, getNextThinkingLevel, getSessionId, getSupportedThinkingLevels, grokCliBaseUrl, grokCliHeaders, isGrokCliEndpoint, isKimiCodingEndpoint, isLocalModelId, isLoggerOpen, isModelLoaded, isThinkingLevelSupported, kimiCodeBaseUrl, kimiCodingHeaders, localAuthStorageKey, log, loginAnthropic, loginGemini, loginKimi, loginOpenAI, loginXai, oauthStorageKey, openLog, parseLocalModelId, probeEndpoint, providerStorageKeys, readStoredBaseUrlSync, recordRequiredClaudeCodeVersion, refreshAnthropicToken, refreshGeminiToken, refreshKimiToken, refreshOpenAIToken, refreshXaiToken, registerLogCleanup, resample, setProgressCallback, toModelInfo, transcribeVoice, withFileLock };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { ModelInfo } from './model-registry.js';
|
|
2
|
-
export { ContextWindowOptions, DEFAULT_MAX_VIDEO_BYTES, MODELS, clearRuntimeModels, getAllModels, getAuthStorageKey, getAuthStorageKeys, getContextWindow, getDefaultModel, getDefaultThinkingLevel,
|
|
2
|
+
export { ContextWindowOptions, DEFAULT_MAX_VIDEO_BYTES, MODELS, clearRuntimeModels, getAllModels, getAuthStorageKey, getAuthStorageKeys, getContextWindow, getDefaultModel, getDefaultThinkingLevel, getMaxThinkingLevel, getModel, getModelsForProvider, getSummaryModel, getToolResultCharLimit, getVideoByteLimit, registerRuntimeModels, usesOpenAICodexTransport } from './model-registry.js';
|
|
3
3
|
import { ThinkingLevel, Provider } from '@prestyj/ai';
|
|
4
4
|
export { AppPaths, getAppPaths } from './paths.js';
|
|
5
5
|
|
|
6
6
|
declare function getSupportedThinkingLevels(provider: Provider, model: string): readonly ThinkingLevel[];
|
|
7
|
+
/**
|
|
8
|
+
* The lowest effort `model` accepts — the first rung of its ladder, never
|
|
9
|
+
* "off". Used for background work (compaction summaries, `model: fast`
|
|
10
|
+
* agents) that runs on the active model but doesn't need deep reasoning.
|
|
11
|
+
* Undefined only when the model cannot reason at all, since sending it any
|
|
12
|
+
* effort would be rejected.
|
|
13
|
+
*/
|
|
14
|
+
declare function getLowestThinkingLevel(provider: Provider, model: string): ThinkingLevel | undefined;
|
|
7
15
|
declare function isThinkingLevelSupported(provider: Provider, model: string, level: ThinkingLevel): boolean;
|
|
8
16
|
declare function getNextThinkingLevel(provider: Provider, model: string, current: ThinkingLevel | undefined): ThinkingLevel | undefined;
|
|
9
17
|
/**
|
|
@@ -685,6 +693,8 @@ declare class TelegramBot {
|
|
|
685
693
|
private allowedUserId;
|
|
686
694
|
private offset;
|
|
687
695
|
private running;
|
|
696
|
+
/** Aborts the in-flight long poll so stop() takes effect immediately. */
|
|
697
|
+
private pollAbort;
|
|
688
698
|
private onMessage;
|
|
689
699
|
private onVoiceMessage;
|
|
690
700
|
private onCallback;
|
|
@@ -778,4 +788,4 @@ interface AutoUpdater {
|
|
|
778
788
|
}
|
|
779
789
|
declare function createAutoUpdater(config: AutoUpdateConfig): AutoUpdater;
|
|
780
790
|
|
|
781
|
-
export { AuthStorage, type AutoUpdateConfig, type AutoUpdater, DEFAULT_LOCAL_ENDPOINTS, type DiscoverOptions, type DiscoveryResult, type DualAuthProvider, FALLBACK_CONTEXT_WINDOW, type InlineButton, LOCAL_API_KEY_PLACEHOLDER, LOCAL_AUTH_KEY_PREFIX, type LocalEndpoint, type LocalEndpointKind, type LocalEndpointProbe, type LocalModel, type LogLevel, MOONSHOT_OAUTH_KEY, ModelInfo, NotLoggedInError, type OAuthCredentials, type OAuthLoginCallbacks, PLAN_MODE_THINKING_CAP, type ProbeOptions, type ProgressCallback, SubscriptionUsageError, type SubscriptionUsageProvider, type SubscriptionUsageSnapshot, type SubscriptionUsageWindow, TelegramBot, type TelegramConfig, type TelegramMessage, type TelegramUpdate, type TelegramVoiceMessage, XAI_OAUTH_KEY, XIAOMI_CREDITS_KEY, clampThinkingForPlanMode, clearLocalDiscoveryCache, closeLogger, compareClaudeCodeVersions, createAutoUpdater, decodeOggOpus, discoverLocalModels, downmixToMono, dualAuthProvider, dualAuthProviderByOAuthKey, endpointRoot, fetchSubscriptionUsage, findProbedModel, formatLocalModelId, generatePKCE, getClaudeCliUserAgent, getClaudeCodeVersion, getNextThinkingLevel, getSessionId, getSupportedThinkingLevels, grokCliBaseUrl, grokCliHeaders, isGrokCliEndpoint, isKimiCodingEndpoint, isLocalModelId, isLoggerOpen, isModelLoaded, isThinkingLevelSupported, kimiCodeBaseUrl, kimiCodingHeaders, localAuthStorageKey, log, loginAnthropic, loginGemini, loginKimi, loginOpenAI, loginXai, oauthStorageKey, openLog, parseLocalModelId, probeEndpoint, providerStorageKeys, readStoredBaseUrlSync, recordRequiredClaudeCodeVersion, refreshAnthropicToken, refreshGeminiToken, refreshKimiToken, refreshOpenAIToken, refreshXaiToken, registerLogCleanup, resample, setProgressCallback, toModelInfo, transcribeVoice, withFileLock };
|
|
791
|
+
export { AuthStorage, type AutoUpdateConfig, type AutoUpdater, DEFAULT_LOCAL_ENDPOINTS, type DiscoverOptions, type DiscoveryResult, type DualAuthProvider, FALLBACK_CONTEXT_WINDOW, type InlineButton, LOCAL_API_KEY_PLACEHOLDER, LOCAL_AUTH_KEY_PREFIX, type LocalEndpoint, type LocalEndpointKind, type LocalEndpointProbe, type LocalModel, type LogLevel, MOONSHOT_OAUTH_KEY, ModelInfo, NotLoggedInError, type OAuthCredentials, type OAuthLoginCallbacks, PLAN_MODE_THINKING_CAP, type ProbeOptions, type ProgressCallback, SubscriptionUsageError, type SubscriptionUsageProvider, type SubscriptionUsageSnapshot, type SubscriptionUsageWindow, TelegramBot, type TelegramConfig, type TelegramMessage, type TelegramUpdate, type TelegramVoiceMessage, XAI_OAUTH_KEY, XIAOMI_CREDITS_KEY, clampThinkingForPlanMode, clearLocalDiscoveryCache, closeLogger, compareClaudeCodeVersions, createAutoUpdater, decodeOggOpus, discoverLocalModels, downmixToMono, dualAuthProvider, dualAuthProviderByOAuthKey, endpointRoot, fetchSubscriptionUsage, findProbedModel, formatLocalModelId, generatePKCE, getClaudeCliUserAgent, getClaudeCodeVersion, getLowestThinkingLevel, getNextThinkingLevel, getSessionId, getSupportedThinkingLevels, grokCliBaseUrl, grokCliHeaders, isGrokCliEndpoint, isKimiCodingEndpoint, isLocalModelId, isLoggerOpen, isModelLoaded, isThinkingLevelSupported, kimiCodeBaseUrl, kimiCodingHeaders, localAuthStorageKey, log, loginAnthropic, loginGemini, loginKimi, loginOpenAI, loginXai, oauthStorageKey, openLog, parseLocalModelId, probeEndpoint, providerStorageKeys, readStoredBaseUrlSync, recordRequiredClaudeCodeVersion, refreshAnthropicToken, refreshGeminiToken, refreshKimiToken, refreshOpenAIToken, refreshXaiToken, registerLogCleanup, resample, setProgressCallback, toModelInfo, transcribeVoice, withFileLock };
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,6 @@ import {
|
|
|
21
21
|
getContextWindow,
|
|
22
22
|
getDefaultModel,
|
|
23
23
|
getDefaultThinkingLevel,
|
|
24
|
-
getFastModel,
|
|
25
24
|
getMaxThinkingLevel,
|
|
26
25
|
getModel,
|
|
27
26
|
getModelsForProvider,
|
|
@@ -56,7 +55,7 @@ import {
|
|
|
56
55
|
registerRuntimeModels,
|
|
57
56
|
usesOpenAICodexTransport,
|
|
58
57
|
withFileLock
|
|
59
|
-
} from "./chunk-
|
|
58
|
+
} from "./chunk-N73LFQ3N.js";
|
|
60
59
|
import {
|
|
61
60
|
getAppPaths
|
|
62
61
|
} from "./chunk-CRU3SSNX.js";
|
|
@@ -148,6 +147,10 @@ function getSupportedThinkingLevels(provider, model) {
|
|
|
148
147
|
if (maxIndex === -1) return ["medium"];
|
|
149
148
|
return levels.slice(0, maxIndex + 1);
|
|
150
149
|
}
|
|
150
|
+
function getLowestThinkingLevel(provider, model) {
|
|
151
|
+
if (getModel(model)?.supportsThinking === false) return void 0;
|
|
152
|
+
return getSupportedThinkingLevels(provider, model)[0];
|
|
153
|
+
}
|
|
151
154
|
function isThinkingLevelSupported(provider, model, level) {
|
|
152
155
|
return getSupportedThinkingLevels(provider, model).includes(level);
|
|
153
156
|
}
|
|
@@ -695,12 +698,16 @@ async function fetchSubscriptionUsage(provider, credentials, options = {}) {
|
|
|
695
698
|
|
|
696
699
|
// src/telegram.ts
|
|
697
700
|
var TELEGRAM_API = "https://api.telegram.org";
|
|
701
|
+
var LONG_POLL_SECONDS = 30;
|
|
702
|
+
var API_TIMEOUT_MS = 3e4;
|
|
698
703
|
var MAX_MESSAGE_LENGTH = 4096;
|
|
699
704
|
var TelegramBot = class {
|
|
700
705
|
token;
|
|
701
706
|
allowedUserId;
|
|
702
707
|
offset = 0;
|
|
703
708
|
running = false;
|
|
709
|
+
/** Aborts the in-flight long poll so stop() takes effect immediately. */
|
|
710
|
+
pollAbort = null;
|
|
704
711
|
onMessage = null;
|
|
705
712
|
onVoiceMessage = null;
|
|
706
713
|
onCallback = null;
|
|
@@ -753,6 +760,7 @@ var TelegramBot = class {
|
|
|
753
760
|
/** Stop long polling. */
|
|
754
761
|
stop() {
|
|
755
762
|
this.running = false;
|
|
763
|
+
this.pollAbort?.abort();
|
|
756
764
|
}
|
|
757
765
|
/** Send a text message to a specific chat. Converts markdown and splits long messages. */
|
|
758
766
|
async send(chatId, text, buttons) {
|
|
@@ -799,12 +807,26 @@ var TelegramBot = class {
|
|
|
799
807
|
}
|
|
800
808
|
// ── Private ───────────────────────────────────────────
|
|
801
809
|
async getUpdates() {
|
|
802
|
-
const
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
810
|
+
const poll = new AbortController();
|
|
811
|
+
this.pollAbort = poll;
|
|
812
|
+
let result;
|
|
813
|
+
try {
|
|
814
|
+
result = await this.apiCall(
|
|
815
|
+
"getUpdates",
|
|
816
|
+
{
|
|
817
|
+
offset: this.offset,
|
|
818
|
+
timeout: LONG_POLL_SECONDS,
|
|
819
|
+
allowed_updates: ["message", "callback_query", "my_chat_member"]
|
|
820
|
+
},
|
|
821
|
+
// A half-open socket would otherwise hang the poll forever.
|
|
822
|
+
AbortSignal.any([poll.signal, AbortSignal.timeout((LONG_POLL_SECONDS + 15) * 1e3)])
|
|
823
|
+
);
|
|
824
|
+
} finally {
|
|
825
|
+
if (this.pollAbort === poll) this.pollAbort = null;
|
|
826
|
+
}
|
|
827
|
+
if (!result.ok || !Array.isArray(result.result)) {
|
|
828
|
+
throw new Error(`getUpdates failed: ${JSON.stringify(result)}`);
|
|
829
|
+
}
|
|
808
830
|
const updates = result.result;
|
|
809
831
|
if (updates.length > 0) {
|
|
810
832
|
this.offset = updates[updates.length - 1].update_id + 1;
|
|
@@ -852,12 +874,13 @@ var TelegramBot = class {
|
|
|
852
874
|
}
|
|
853
875
|
}
|
|
854
876
|
}
|
|
855
|
-
async apiCall(method, body) {
|
|
877
|
+
async apiCall(method, body, signal = AbortSignal.timeout(API_TIMEOUT_MS)) {
|
|
856
878
|
const url = `${TELEGRAM_API}/bot${this.token}/${method}`;
|
|
857
879
|
const response = await fetch(url, {
|
|
858
880
|
method: "POST",
|
|
859
881
|
headers: { "Content-Type": "application/json" },
|
|
860
|
-
body: body ? JSON.stringify(body) : void 0
|
|
882
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
883
|
+
signal
|
|
861
884
|
});
|
|
862
885
|
if (!response.ok) {
|
|
863
886
|
return { ok: false };
|
|
@@ -990,7 +1013,7 @@ function isModelLoaded() {
|
|
|
990
1013
|
return transcriber !== null;
|
|
991
1014
|
}
|
|
992
1015
|
async function transcribeVoice(fileUrl) {
|
|
993
|
-
const response = await fetch(fileUrl);
|
|
1016
|
+
const response = await fetch(fileUrl, { signal: AbortSignal.timeout(6e4) });
|
|
994
1017
|
if (!response.ok) throw new Error(`Failed to download voice file: ${response.status}`);
|
|
995
1018
|
const buffer = new Uint8Array(await response.arrayBuffer());
|
|
996
1019
|
const pcm = await decodeOggOpus(buffer);
|
|
@@ -1208,7 +1231,7 @@ export {
|
|
|
1208
1231
|
getContextWindow,
|
|
1209
1232
|
getDefaultModel,
|
|
1210
1233
|
getDefaultThinkingLevel,
|
|
1211
|
-
|
|
1234
|
+
getLowestThinkingLevel,
|
|
1212
1235
|
getMaxThinkingLevel,
|
|
1213
1236
|
getModel,
|
|
1214
1237
|
getModelsForProvider,
|