@contentgrowth/llm-service 1.3.7 → 1.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.
- package/README.md +66 -1
- package/dist/index.cjs +235 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +117 -28
- package/dist/index.d.ts +117 -28
- package/dist/index.js +235 -39
- package/dist/index.js.map +1 -1
- package/package.json +11 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import OpenAI from 'openai';
|
|
2
2
|
import Anthropic from '@anthropic-ai/sdk';
|
|
3
|
-
import * as _google_genai from '@google/genai';
|
|
4
3
|
import { GoogleGenAI } from '@google/genai';
|
|
5
4
|
export { Modality } from '@google/genai';
|
|
6
5
|
|
|
@@ -567,6 +566,8 @@ declare namespace MODEL_CONFIGS {
|
|
|
567
566
|
* Invalid model IDs that earlier versions of this library shipped as defaults.
|
|
568
567
|
* Consumers persisted some of them (e.g. saved BYOK key configs), so we map them
|
|
569
568
|
* to a valid equivalent instead of letting the provider return 404.
|
|
569
|
+
*
|
|
570
|
+
* NOTE: Imagen models are NOT included here - they should fail with clear error.
|
|
570
571
|
*/
|
|
571
572
|
declare const LEGACY_MODEL_ALIASES: {
|
|
572
573
|
'gpt-5.5-instant': string;
|
|
@@ -575,6 +576,10 @@ declare const LEGACY_MODEL_ALIASES: {
|
|
|
575
576
|
'gemini-3.7-pro': string;
|
|
576
577
|
'gemini-3.5-pro-image-preview': string;
|
|
577
578
|
'gemini-3.7-pro-image-preview': string;
|
|
579
|
+
'gemini-3-pro-image': string;
|
|
580
|
+
'gemini-3.1-flash-image': string;
|
|
581
|
+
'gemini-3.1-flash-lite-image': string;
|
|
582
|
+
'gemini-2.5-flash-image': string;
|
|
578
583
|
'claude-4.5-haiku': string;
|
|
579
584
|
'claude-4.6-sonnet': string;
|
|
580
585
|
'claude-4.8-opus': string;
|
|
@@ -619,13 +624,28 @@ declare class GoogleProvider extends BaseLLMProvider {
|
|
|
619
624
|
models: {};
|
|
620
625
|
defaultModel: any;
|
|
621
626
|
_pendingOperations: Map<any, any>;
|
|
627
|
+
accessToken: any;
|
|
628
|
+
project: any;
|
|
629
|
+
location: any;
|
|
630
|
+
useDirectAPI: boolean;
|
|
622
631
|
client: GoogleGenAI;
|
|
623
632
|
/**
|
|
624
633
|
* Perform the actual API call. Both AI Studio and Vertex AI use the
|
|
625
634
|
* same @google/genai SDK method — the routing is determined by how
|
|
626
635
|
* the client was constructed.
|
|
627
636
|
*/
|
|
628
|
-
_generateContent(requestOptions: any): Promise<
|
|
637
|
+
_generateContent(requestOptions: any): Promise<any>;
|
|
638
|
+
/**
|
|
639
|
+
* Direct Vertex AI API call using pre-generated access token
|
|
640
|
+
* @private
|
|
641
|
+
*/
|
|
642
|
+
private _directVertexAPICall;
|
|
643
|
+
/**
|
|
644
|
+
* Determine authentication mode from config for logging/debugging
|
|
645
|
+
* @private
|
|
646
|
+
* @returns {string} Auth mode description
|
|
647
|
+
*/
|
|
648
|
+
private _getAuthMode;
|
|
629
649
|
chat(userMessage: any, systemPrompt?: string, options?: {}): Promise<{
|
|
630
650
|
text: string;
|
|
631
651
|
}>;
|
|
@@ -637,18 +657,18 @@ declare class GoogleProvider extends BaseLLMProvider {
|
|
|
637
657
|
tool_calls: {
|
|
638
658
|
type: string;
|
|
639
659
|
function: {
|
|
640
|
-
name:
|
|
660
|
+
name: any;
|
|
641
661
|
arguments: string;
|
|
642
662
|
};
|
|
643
663
|
thought_signature: any;
|
|
644
664
|
}[];
|
|
645
665
|
finishReason: string;
|
|
646
|
-
_rawFinishReason:
|
|
666
|
+
_rawFinishReason: any;
|
|
647
667
|
_responseFormat: any;
|
|
648
668
|
usage: {
|
|
649
|
-
prompt_tokens:
|
|
650
|
-
completion_tokens:
|
|
651
|
-
total_tokens:
|
|
669
|
+
prompt_tokens: any;
|
|
670
|
+
completion_tokens: any;
|
|
671
|
+
total_tokens: any;
|
|
652
672
|
};
|
|
653
673
|
}>;
|
|
654
674
|
_chatCompletionWithModel(messages: any, systemPrompt: any, tools: any, modelName: any, maxTokens: any, temperature: any, options?: {}): Promise<{
|
|
@@ -659,18 +679,18 @@ declare class GoogleProvider extends BaseLLMProvider {
|
|
|
659
679
|
tool_calls: {
|
|
660
680
|
type: string;
|
|
661
681
|
function: {
|
|
662
|
-
name:
|
|
682
|
+
name: any;
|
|
663
683
|
arguments: string;
|
|
664
684
|
};
|
|
665
685
|
thought_signature: any;
|
|
666
686
|
}[];
|
|
667
687
|
finishReason: string;
|
|
668
|
-
_rawFinishReason:
|
|
688
|
+
_rawFinishReason: any;
|
|
669
689
|
_responseFormat: any;
|
|
670
690
|
usage: {
|
|
671
|
-
prompt_tokens:
|
|
672
|
-
completion_tokens:
|
|
673
|
-
total_tokens:
|
|
691
|
+
prompt_tokens: any;
|
|
692
|
+
completion_tokens: any;
|
|
693
|
+
total_tokens: any;
|
|
674
694
|
};
|
|
675
695
|
}>;
|
|
676
696
|
_buildGenerationConfig(options: any, maxTokens: any, temperature: any): {
|
|
@@ -684,8 +704,8 @@ declare class GoogleProvider extends BaseLLMProvider {
|
|
|
684
704
|
_safeJsonParse(content: any): any;
|
|
685
705
|
executeTools(tool_calls: any, messages: any, tenantId: any, toolImplementations: any, env: any): Promise<void>;
|
|
686
706
|
imageGeneration(prompt: any, systemPrompt: any, options?: {}): Promise<{
|
|
687
|
-
imageData:
|
|
688
|
-
mimeType:
|
|
707
|
+
imageData: any;
|
|
708
|
+
mimeType: any;
|
|
689
709
|
thought_signature: any;
|
|
690
710
|
}>;
|
|
691
711
|
_getModelForTier(tier: any): any;
|
|
@@ -788,26 +808,95 @@ declare function handleApiError(error: Error, operation?: string, context?: stri
|
|
|
788
808
|
declare function sanitizeError(error: Error, context?: string): Error;
|
|
789
809
|
|
|
790
810
|
/**
|
|
791
|
-
* Google
|
|
792
|
-
*
|
|
811
|
+
* Google OAuth2 Token Manager
|
|
812
|
+
*
|
|
813
|
+
* Handles token generation, caching, and automatic refresh for
|
|
814
|
+
* Google Cloud service accounts. Tokens are cached and automatically
|
|
815
|
+
* refreshed when they expire (with a 5-minute safety buffer).
|
|
816
|
+
*
|
|
817
|
+
* @example
|
|
818
|
+
* const sa = parseGoogleCredentials(credentials);
|
|
819
|
+
* const tokenManager = new GoogleTokenManager(sa);
|
|
820
|
+
*
|
|
821
|
+
* // Get token (cached or fresh)
|
|
822
|
+
* const token = await tokenManager.getToken();
|
|
823
|
+
*
|
|
824
|
+
* // Force refresh
|
|
825
|
+
* tokenManager.invalidate();
|
|
826
|
+
* const newToken = await tokenManager.getToken();
|
|
793
827
|
*/
|
|
794
|
-
declare class
|
|
828
|
+
declare class GoogleTokenManager {
|
|
795
829
|
/**
|
|
796
|
-
* @param {
|
|
830
|
+
* @param {object} serviceAccount - Parsed service account with client_email and private_key
|
|
831
|
+
* @param {object} options - Optional configuration
|
|
832
|
+
* @param {string} options.scope - OAuth2 scope (default: cloud-platform)
|
|
833
|
+
* @param {number} options.tokenLifetime - Token lifetime in seconds (default: 3600)
|
|
797
834
|
*/
|
|
798
|
-
constructor(
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
835
|
+
constructor(serviceAccount: object, options?: {
|
|
836
|
+
scope: string;
|
|
837
|
+
tokenLifetime: number;
|
|
838
|
+
});
|
|
839
|
+
clientEmail: any;
|
|
840
|
+
privateKey: any;
|
|
841
|
+
projectId: any;
|
|
842
|
+
scope: string;
|
|
843
|
+
tokenLifetime: number;
|
|
844
|
+
_tokenCache: string;
|
|
845
|
+
_expiresAt: number;
|
|
846
|
+
/**
|
|
847
|
+
* Get a valid access token (cached or fresh)
|
|
848
|
+
*
|
|
849
|
+
* @returns {Promise<string>} OAuth2 access token
|
|
850
|
+
*/
|
|
851
|
+
getToken(): Promise<string>;
|
|
852
|
+
/**
|
|
853
|
+
* Clear cached token (force refresh on next getToken call)
|
|
854
|
+
*/
|
|
855
|
+
invalidate(): void;
|
|
856
|
+
/**
|
|
857
|
+
* Check if cached token is still valid
|
|
858
|
+
*
|
|
859
|
+
* @returns {boolean} True if token is valid
|
|
860
|
+
*/
|
|
861
|
+
isValid(): boolean;
|
|
862
|
+
/**
|
|
863
|
+
* Get time until token expires (in seconds)
|
|
864
|
+
*
|
|
865
|
+
* @returns {number} Seconds until expiration (0 if no token or expired)
|
|
866
|
+
*/
|
|
867
|
+
getTimeToExpiry(): number;
|
|
802
868
|
/**
|
|
803
|
-
* Generate
|
|
869
|
+
* Generate OAuth2 token via JWT flow
|
|
870
|
+
*
|
|
871
|
+
* @private
|
|
872
|
+
* @returns {Promise<string>} Access token
|
|
873
|
+
*/
|
|
874
|
+
private _generateToken;
|
|
875
|
+
/**
|
|
876
|
+
* Sign JWT using service account private key
|
|
877
|
+
*
|
|
878
|
+
* @private
|
|
879
|
+
* @param {object} header - JWT header
|
|
880
|
+
* @param {object} payload - JWT payload
|
|
881
|
+
* @returns {Promise<string>} Signed JWT
|
|
804
882
|
*/
|
|
805
|
-
|
|
883
|
+
private _signJWT;
|
|
806
884
|
/**
|
|
807
|
-
*
|
|
808
|
-
*
|
|
885
|
+
* Import PEM private key for signing
|
|
886
|
+
*
|
|
887
|
+
* @private
|
|
888
|
+
* @param {string} pemKey - PEM formatted private key
|
|
889
|
+
* @returns {Promise<CryptoKey>} Imported key
|
|
890
|
+
*/
|
|
891
|
+
private _importPrivateKey;
|
|
892
|
+
/**
|
|
893
|
+
* Base64 URL encode (without padding)
|
|
894
|
+
*
|
|
895
|
+
* @private
|
|
896
|
+
* @param {string|ArrayBuffer} input - Data to encode
|
|
897
|
+
* @returns {string} Base64 URL encoded string
|
|
809
898
|
*/
|
|
810
|
-
|
|
899
|
+
private _base64UrlEncode;
|
|
811
900
|
}
|
|
812
901
|
|
|
813
902
|
/**
|
|
@@ -837,7 +926,7 @@ declare class TranscriptionService {
|
|
|
837
926
|
endpoint: string;
|
|
838
927
|
model: string;
|
|
839
928
|
client: OpenAI;
|
|
840
|
-
|
|
929
|
+
googleTokenManager: GoogleTokenManager;
|
|
841
930
|
projectId: any;
|
|
842
931
|
/**
|
|
843
932
|
* Transcribe audio to text
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import OpenAI from 'openai';
|
|
2
2
|
import Anthropic from '@anthropic-ai/sdk';
|
|
3
|
-
import * as _google_genai from '@google/genai';
|
|
4
3
|
import { GoogleGenAI } from '@google/genai';
|
|
5
4
|
export { Modality } from '@google/genai';
|
|
6
5
|
|
|
@@ -567,6 +566,8 @@ declare namespace MODEL_CONFIGS {
|
|
|
567
566
|
* Invalid model IDs that earlier versions of this library shipped as defaults.
|
|
568
567
|
* Consumers persisted some of them (e.g. saved BYOK key configs), so we map them
|
|
569
568
|
* to a valid equivalent instead of letting the provider return 404.
|
|
569
|
+
*
|
|
570
|
+
* NOTE: Imagen models are NOT included here - they should fail with clear error.
|
|
570
571
|
*/
|
|
571
572
|
declare const LEGACY_MODEL_ALIASES: {
|
|
572
573
|
'gpt-5.5-instant': string;
|
|
@@ -575,6 +576,10 @@ declare const LEGACY_MODEL_ALIASES: {
|
|
|
575
576
|
'gemini-3.7-pro': string;
|
|
576
577
|
'gemini-3.5-pro-image-preview': string;
|
|
577
578
|
'gemini-3.7-pro-image-preview': string;
|
|
579
|
+
'gemini-3-pro-image': string;
|
|
580
|
+
'gemini-3.1-flash-image': string;
|
|
581
|
+
'gemini-3.1-flash-lite-image': string;
|
|
582
|
+
'gemini-2.5-flash-image': string;
|
|
578
583
|
'claude-4.5-haiku': string;
|
|
579
584
|
'claude-4.6-sonnet': string;
|
|
580
585
|
'claude-4.8-opus': string;
|
|
@@ -619,13 +624,28 @@ declare class GoogleProvider extends BaseLLMProvider {
|
|
|
619
624
|
models: {};
|
|
620
625
|
defaultModel: any;
|
|
621
626
|
_pendingOperations: Map<any, any>;
|
|
627
|
+
accessToken: any;
|
|
628
|
+
project: any;
|
|
629
|
+
location: any;
|
|
630
|
+
useDirectAPI: boolean;
|
|
622
631
|
client: GoogleGenAI;
|
|
623
632
|
/**
|
|
624
633
|
* Perform the actual API call. Both AI Studio and Vertex AI use the
|
|
625
634
|
* same @google/genai SDK method — the routing is determined by how
|
|
626
635
|
* the client was constructed.
|
|
627
636
|
*/
|
|
628
|
-
_generateContent(requestOptions: any): Promise<
|
|
637
|
+
_generateContent(requestOptions: any): Promise<any>;
|
|
638
|
+
/**
|
|
639
|
+
* Direct Vertex AI API call using pre-generated access token
|
|
640
|
+
* @private
|
|
641
|
+
*/
|
|
642
|
+
private _directVertexAPICall;
|
|
643
|
+
/**
|
|
644
|
+
* Determine authentication mode from config for logging/debugging
|
|
645
|
+
* @private
|
|
646
|
+
* @returns {string} Auth mode description
|
|
647
|
+
*/
|
|
648
|
+
private _getAuthMode;
|
|
629
649
|
chat(userMessage: any, systemPrompt?: string, options?: {}): Promise<{
|
|
630
650
|
text: string;
|
|
631
651
|
}>;
|
|
@@ -637,18 +657,18 @@ declare class GoogleProvider extends BaseLLMProvider {
|
|
|
637
657
|
tool_calls: {
|
|
638
658
|
type: string;
|
|
639
659
|
function: {
|
|
640
|
-
name:
|
|
660
|
+
name: any;
|
|
641
661
|
arguments: string;
|
|
642
662
|
};
|
|
643
663
|
thought_signature: any;
|
|
644
664
|
}[];
|
|
645
665
|
finishReason: string;
|
|
646
|
-
_rawFinishReason:
|
|
666
|
+
_rawFinishReason: any;
|
|
647
667
|
_responseFormat: any;
|
|
648
668
|
usage: {
|
|
649
|
-
prompt_tokens:
|
|
650
|
-
completion_tokens:
|
|
651
|
-
total_tokens:
|
|
669
|
+
prompt_tokens: any;
|
|
670
|
+
completion_tokens: any;
|
|
671
|
+
total_tokens: any;
|
|
652
672
|
};
|
|
653
673
|
}>;
|
|
654
674
|
_chatCompletionWithModel(messages: any, systemPrompt: any, tools: any, modelName: any, maxTokens: any, temperature: any, options?: {}): Promise<{
|
|
@@ -659,18 +679,18 @@ declare class GoogleProvider extends BaseLLMProvider {
|
|
|
659
679
|
tool_calls: {
|
|
660
680
|
type: string;
|
|
661
681
|
function: {
|
|
662
|
-
name:
|
|
682
|
+
name: any;
|
|
663
683
|
arguments: string;
|
|
664
684
|
};
|
|
665
685
|
thought_signature: any;
|
|
666
686
|
}[];
|
|
667
687
|
finishReason: string;
|
|
668
|
-
_rawFinishReason:
|
|
688
|
+
_rawFinishReason: any;
|
|
669
689
|
_responseFormat: any;
|
|
670
690
|
usage: {
|
|
671
|
-
prompt_tokens:
|
|
672
|
-
completion_tokens:
|
|
673
|
-
total_tokens:
|
|
691
|
+
prompt_tokens: any;
|
|
692
|
+
completion_tokens: any;
|
|
693
|
+
total_tokens: any;
|
|
674
694
|
};
|
|
675
695
|
}>;
|
|
676
696
|
_buildGenerationConfig(options: any, maxTokens: any, temperature: any): {
|
|
@@ -684,8 +704,8 @@ declare class GoogleProvider extends BaseLLMProvider {
|
|
|
684
704
|
_safeJsonParse(content: any): any;
|
|
685
705
|
executeTools(tool_calls: any, messages: any, tenantId: any, toolImplementations: any, env: any): Promise<void>;
|
|
686
706
|
imageGeneration(prompt: any, systemPrompt: any, options?: {}): Promise<{
|
|
687
|
-
imageData:
|
|
688
|
-
mimeType:
|
|
707
|
+
imageData: any;
|
|
708
|
+
mimeType: any;
|
|
689
709
|
thought_signature: any;
|
|
690
710
|
}>;
|
|
691
711
|
_getModelForTier(tier: any): any;
|
|
@@ -788,26 +808,95 @@ declare function handleApiError(error: Error, operation?: string, context?: stri
|
|
|
788
808
|
declare function sanitizeError(error: Error, context?: string): Error;
|
|
789
809
|
|
|
790
810
|
/**
|
|
791
|
-
* Google
|
|
792
|
-
*
|
|
811
|
+
* Google OAuth2 Token Manager
|
|
812
|
+
*
|
|
813
|
+
* Handles token generation, caching, and automatic refresh for
|
|
814
|
+
* Google Cloud service accounts. Tokens are cached and automatically
|
|
815
|
+
* refreshed when they expire (with a 5-minute safety buffer).
|
|
816
|
+
*
|
|
817
|
+
* @example
|
|
818
|
+
* const sa = parseGoogleCredentials(credentials);
|
|
819
|
+
* const tokenManager = new GoogleTokenManager(sa);
|
|
820
|
+
*
|
|
821
|
+
* // Get token (cached or fresh)
|
|
822
|
+
* const token = await tokenManager.getToken();
|
|
823
|
+
*
|
|
824
|
+
* // Force refresh
|
|
825
|
+
* tokenManager.invalidate();
|
|
826
|
+
* const newToken = await tokenManager.getToken();
|
|
793
827
|
*/
|
|
794
|
-
declare class
|
|
828
|
+
declare class GoogleTokenManager {
|
|
795
829
|
/**
|
|
796
|
-
* @param {
|
|
830
|
+
* @param {object} serviceAccount - Parsed service account with client_email and private_key
|
|
831
|
+
* @param {object} options - Optional configuration
|
|
832
|
+
* @param {string} options.scope - OAuth2 scope (default: cloud-platform)
|
|
833
|
+
* @param {number} options.tokenLifetime - Token lifetime in seconds (default: 3600)
|
|
797
834
|
*/
|
|
798
|
-
constructor(
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
835
|
+
constructor(serviceAccount: object, options?: {
|
|
836
|
+
scope: string;
|
|
837
|
+
tokenLifetime: number;
|
|
838
|
+
});
|
|
839
|
+
clientEmail: any;
|
|
840
|
+
privateKey: any;
|
|
841
|
+
projectId: any;
|
|
842
|
+
scope: string;
|
|
843
|
+
tokenLifetime: number;
|
|
844
|
+
_tokenCache: string;
|
|
845
|
+
_expiresAt: number;
|
|
846
|
+
/**
|
|
847
|
+
* Get a valid access token (cached or fresh)
|
|
848
|
+
*
|
|
849
|
+
* @returns {Promise<string>} OAuth2 access token
|
|
850
|
+
*/
|
|
851
|
+
getToken(): Promise<string>;
|
|
852
|
+
/**
|
|
853
|
+
* Clear cached token (force refresh on next getToken call)
|
|
854
|
+
*/
|
|
855
|
+
invalidate(): void;
|
|
856
|
+
/**
|
|
857
|
+
* Check if cached token is still valid
|
|
858
|
+
*
|
|
859
|
+
* @returns {boolean} True if token is valid
|
|
860
|
+
*/
|
|
861
|
+
isValid(): boolean;
|
|
862
|
+
/**
|
|
863
|
+
* Get time until token expires (in seconds)
|
|
864
|
+
*
|
|
865
|
+
* @returns {number} Seconds until expiration (0 if no token or expired)
|
|
866
|
+
*/
|
|
867
|
+
getTimeToExpiry(): number;
|
|
802
868
|
/**
|
|
803
|
-
* Generate
|
|
869
|
+
* Generate OAuth2 token via JWT flow
|
|
870
|
+
*
|
|
871
|
+
* @private
|
|
872
|
+
* @returns {Promise<string>} Access token
|
|
873
|
+
*/
|
|
874
|
+
private _generateToken;
|
|
875
|
+
/**
|
|
876
|
+
* Sign JWT using service account private key
|
|
877
|
+
*
|
|
878
|
+
* @private
|
|
879
|
+
* @param {object} header - JWT header
|
|
880
|
+
* @param {object} payload - JWT payload
|
|
881
|
+
* @returns {Promise<string>} Signed JWT
|
|
804
882
|
*/
|
|
805
|
-
|
|
883
|
+
private _signJWT;
|
|
806
884
|
/**
|
|
807
|
-
*
|
|
808
|
-
*
|
|
885
|
+
* Import PEM private key for signing
|
|
886
|
+
*
|
|
887
|
+
* @private
|
|
888
|
+
* @param {string} pemKey - PEM formatted private key
|
|
889
|
+
* @returns {Promise<CryptoKey>} Imported key
|
|
890
|
+
*/
|
|
891
|
+
private _importPrivateKey;
|
|
892
|
+
/**
|
|
893
|
+
* Base64 URL encode (without padding)
|
|
894
|
+
*
|
|
895
|
+
* @private
|
|
896
|
+
* @param {string|ArrayBuffer} input - Data to encode
|
|
897
|
+
* @returns {string} Base64 URL encoded string
|
|
809
898
|
*/
|
|
810
|
-
|
|
899
|
+
private _base64UrlEncode;
|
|
811
900
|
}
|
|
812
901
|
|
|
813
902
|
/**
|
|
@@ -837,7 +926,7 @@ declare class TranscriptionService {
|
|
|
837
926
|
endpoint: string;
|
|
838
927
|
model: string;
|
|
839
928
|
client: OpenAI;
|
|
840
|
-
|
|
929
|
+
googleTokenManager: GoogleTokenManager;
|
|
841
930
|
projectId: any;
|
|
842
931
|
/**
|
|
843
932
|
* Transcribe audio to text
|