@contentgrowth/llm-service 1.4.0 → 1.4.2

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/index.d.cts CHANGED
@@ -2,6 +2,7 @@ import OpenAI from 'openai';
2
2
  import Anthropic from '@anthropic-ai/sdk';
3
3
  import { GoogleGenAI } from '@google/genai';
4
4
  export { Modality } from '@google/genai';
5
+ import { GoogleTokenManager } from './utils/google-auth.cjs';
5
6
 
6
7
  declare namespace FINISH_REASONS {
7
8
  let COMPLETED: string;
@@ -359,11 +360,14 @@ declare class LLMService {
359
360
  getVideoGenerationStatus(operationName: any, tenantId: any): Promise<any>;
360
361
  /**
361
362
  * Generate an image
362
- * Falls back to system keys if tenant doesn't have image capability enabled
363
+ *
364
+ * Note: The caller (backend) is responsible for capability checks and routing.
365
+ * This method simply delegates to the configured provider.
366
+ *
363
367
  * @param {string} prompt - Text description of the image
364
368
  * @param {string} tenantId - Tenant identifier
365
369
  * @param {string} systemPrompt - System instructions for generation
366
- * @param {Object} options - Generation options (aspectRatio, images, etc.)
370
+ * @param {Object} options - Generation options (aspectRatio, images, model, etc.)
367
371
  */
368
372
  imageGeneration(prompt: string, tenantId: string, systemPrompt: string, options?: any): Promise<any>;
369
373
  /**
@@ -807,98 +811,6 @@ declare function handleApiError(error: Error, operation?: string, context?: stri
807
811
  */
808
812
  declare function sanitizeError(error: Error, context?: string): Error;
809
813
 
810
- /**
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();
827
- */
828
- declare class GoogleTokenManager {
829
- /**
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)
834
- */
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;
868
- /**
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
882
- */
883
- private _signJWT;
884
- /**
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
898
- */
899
- private _base64UrlEncode;
900
- }
901
-
902
814
  /**
903
815
  * Transcription Service - Separate from LLM Service
904
816
  * Handles audio-to-text transcription using various providers.
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import OpenAI from 'openai';
2
2
  import Anthropic from '@anthropic-ai/sdk';
3
3
  import { GoogleGenAI } from '@google/genai';
4
4
  export { Modality } from '@google/genai';
5
+ import { GoogleTokenManager } from './utils/google-auth.js';
5
6
 
6
7
  declare namespace FINISH_REASONS {
7
8
  let COMPLETED: string;
@@ -359,11 +360,14 @@ declare class LLMService {
359
360
  getVideoGenerationStatus(operationName: any, tenantId: any): Promise<any>;
360
361
  /**
361
362
  * Generate an image
362
- * Falls back to system keys if tenant doesn't have image capability enabled
363
+ *
364
+ * Note: The caller (backend) is responsible for capability checks and routing.
365
+ * This method simply delegates to the configured provider.
366
+ *
363
367
  * @param {string} prompt - Text description of the image
364
368
  * @param {string} tenantId - Tenant identifier
365
369
  * @param {string} systemPrompt - System instructions for generation
366
- * @param {Object} options - Generation options (aspectRatio, images, etc.)
370
+ * @param {Object} options - Generation options (aspectRatio, images, model, etc.)
367
371
  */
368
372
  imageGeneration(prompt: string, tenantId: string, systemPrompt: string, options?: any): Promise<any>;
369
373
  /**
@@ -807,98 +811,6 @@ declare function handleApiError(error: Error, operation?: string, context?: stri
807
811
  */
808
812
  declare function sanitizeError(error: Error, context?: string): Error;
809
813
 
810
- /**
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();
827
- */
828
- declare class GoogleTokenManager {
829
- /**
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)
834
- */
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;
868
- /**
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
882
- */
883
- private _signJWT;
884
- /**
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
898
- */
899
- private _base64UrlEncode;
900
- }
901
-
902
814
  /**
903
815
  * Transcription Service - Separate from LLM Service
904
816
  * Handles audio-to-text transcription using various providers.
package/dist/index.js CHANGED
@@ -1877,21 +1877,16 @@ var LLMService = class {
1877
1877
  }
1878
1878
  /**
1879
1879
  * Generate an image
1880
- * Falls back to system keys if tenant doesn't have image capability enabled
1880
+ *
1881
+ * Note: The caller (backend) is responsible for capability checks and routing.
1882
+ * This method simply delegates to the configured provider.
1883
+ *
1881
1884
  * @param {string} prompt - Text description of the image
1882
1885
  * @param {string} tenantId - Tenant identifier
1883
1886
  * @param {string} systemPrompt - System instructions for generation
1884
- * @param {Object} options - Generation options (aspectRatio, images, etc.)
1887
+ * @param {Object} options - Generation options (aspectRatio, images, model, etc.)
1885
1888
  */
1886
1889
  async imageGeneration(prompt, tenantId, systemPrompt, options = {}) {
1887
- var _a;
1888
- if (tenantId) {
1889
- const config = await ConfigManager.getConfig(tenantId, this.env);
1890
- if (config.isTenantOwned && !((_a = config.capabilities) == null ? void 0 : _a.image)) {
1891
- console.log(`[LLMService] Tenant ${tenantId} BYOK doesn't have image capability. Using system keys.`);
1892
- tenantId = null;
1893
- }
1894
- }
1895
1890
  const provider = await this._getProvider(tenantId);
1896
1891
  return provider.imageGeneration(prompt, systemPrompt, options);
1897
1892
  }