@astermind/cybernetic-chatbot-client 1.0.6 → 1.0.9
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 +81 -1
- package/dist/config.d.ts +38 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/cybernetic-chatbot-client-full.esm.js +145 -13
- package/dist/cybernetic-chatbot-client-full.esm.js.map +1 -1
- package/dist/cybernetic-chatbot-client-full.min.js +1 -1
- package/dist/cybernetic-chatbot-client-full.min.js.map +1 -1
- package/dist/cybernetic-chatbot-client-full.umd.js +145 -13
- package/dist/cybernetic-chatbot-client-full.umd.js.map +1 -1
- package/dist/cybernetic-chatbot-client.esm.js +155 -14
- package/dist/cybernetic-chatbot-client.esm.js.map +1 -1
- package/dist/cybernetic-chatbot-client.min.js +1 -1
- package/dist/cybernetic-chatbot-client.min.js.map +1 -1
- package/dist/cybernetic-chatbot-client.umd.js +155 -13
- package/dist/cybernetic-chatbot-client.umd.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -2010,6 +2010,8 @@ class CyberneticClient {
|
|
|
2010
2010
|
|
|
2011
2011
|
// src/config.ts
|
|
2012
2012
|
// Configuration loading and validation
|
|
2013
|
+
/** Default API URL when not specified */
|
|
2014
|
+
const DEFAULT_API_URL = 'https://api.astermind.ai';
|
|
2013
2015
|
/**
|
|
2014
2016
|
* Validate configuration
|
|
2015
2017
|
*/
|
|
@@ -2030,30 +2032,169 @@ function validateConfig(config) {
|
|
|
2030
2032
|
return true;
|
|
2031
2033
|
}
|
|
2032
2034
|
/**
|
|
2033
|
-
* Load config from
|
|
2035
|
+
* Load config from Node.js process.env (for bundlers that replace process.env)
|
|
2034
2036
|
*/
|
|
2035
|
-
function
|
|
2037
|
+
function loadFromProcessEnv() {
|
|
2038
|
+
// Check if process.env exists (Node.js or bundler-injected)
|
|
2039
|
+
if (typeof process === 'undefined' || !process.env) {
|
|
2040
|
+
return null;
|
|
2041
|
+
}
|
|
2042
|
+
// Check for ASTERMIND_RAG_* env vars (non-prefixed, for Node.js/server environments)
|
|
2043
|
+
const apiKey = process.env.ASTERMIND_RAG_API_KEY;
|
|
2044
|
+
const apiUrl = process.env.ASTERMIND_RAG_API_SERVER_URL;
|
|
2045
|
+
if (apiKey) {
|
|
2046
|
+
return {
|
|
2047
|
+
apiKey,
|
|
2048
|
+
apiUrl: apiUrl || DEFAULT_API_URL,
|
|
2049
|
+
_source: 'env'
|
|
2050
|
+
};
|
|
2051
|
+
}
|
|
2052
|
+
// Check for CRA-style REACT_APP_* env vars
|
|
2053
|
+
const craApiKey = process.env.REACT_APP_ASTERMIND_RAG_API_KEY;
|
|
2054
|
+
const craApiUrl = process.env.REACT_APP_ASTERMIND_RAG_API_SERVER_URL;
|
|
2055
|
+
if (craApiKey) {
|
|
2056
|
+
return {
|
|
2057
|
+
apiKey: craApiKey,
|
|
2058
|
+
apiUrl: craApiUrl || DEFAULT_API_URL,
|
|
2059
|
+
_source: 'env'
|
|
2060
|
+
};
|
|
2061
|
+
}
|
|
2062
|
+
return null;
|
|
2063
|
+
}
|
|
2064
|
+
/**
|
|
2065
|
+
* Load config from Vite's import.meta.env (browser environment)
|
|
2066
|
+
* Note: This only works at build time when Vite replaces the variables
|
|
2067
|
+
*/
|
|
2068
|
+
function loadFromViteEnv() {
|
|
2069
|
+
// Check for window.__ASTERMIND_CONFIG__ (SSR-injected config)
|
|
2070
|
+
if (typeof window !== 'undefined') {
|
|
2071
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2072
|
+
const injected = window.__ASTERMIND_CONFIG__;
|
|
2073
|
+
if (injected && typeof injected === 'object' && injected.apiKey) {
|
|
2074
|
+
return {
|
|
2075
|
+
...injected,
|
|
2076
|
+
apiUrl: injected.apiUrl || DEFAULT_API_URL,
|
|
2077
|
+
_source: 'vite'
|
|
2078
|
+
};
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
// Check for Vite's import.meta.env (replaced at build time)
|
|
2082
|
+
// Note: TypeScript doesn't know about import.meta.env, so we use a try-catch
|
|
2083
|
+
try {
|
|
2084
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2085
|
+
const importMeta = globalThis.import?.meta?.env;
|
|
2086
|
+
if (importMeta) {
|
|
2087
|
+
const apiKey = importMeta.VITE_ASTERMIND_RAG_API_KEY;
|
|
2088
|
+
const apiUrl = importMeta.VITE_ASTERMIND_RAG_API_SERVER_URL;
|
|
2089
|
+
if (apiKey) {
|
|
2090
|
+
return {
|
|
2091
|
+
apiKey,
|
|
2092
|
+
apiUrl: apiUrl || DEFAULT_API_URL,
|
|
2093
|
+
_source: 'vite'
|
|
2094
|
+
};
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
catch {
|
|
2099
|
+
// import.meta not available in this environment
|
|
2100
|
+
}
|
|
2101
|
+
return null;
|
|
2102
|
+
}
|
|
2103
|
+
/**
|
|
2104
|
+
* Load config from window.astermindConfig global object
|
|
2105
|
+
*/
|
|
2106
|
+
function loadFromGlobalObject() {
|
|
2036
2107
|
if (typeof window === 'undefined') {
|
|
2037
2108
|
return null;
|
|
2038
2109
|
}
|
|
2039
|
-
// Check for global config object
|
|
2040
2110
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2111
|
+
const globalConfig = window.astermindConfig;
|
|
2112
|
+
if (globalConfig && typeof globalConfig === 'object' && globalConfig.apiKey) {
|
|
2113
|
+
return {
|
|
2114
|
+
...globalConfig,
|
|
2115
|
+
apiUrl: globalConfig.apiUrl || DEFAULT_API_URL,
|
|
2116
|
+
_source: 'window'
|
|
2117
|
+
};
|
|
2118
|
+
}
|
|
2119
|
+
return null;
|
|
2120
|
+
}
|
|
2121
|
+
/**
|
|
2122
|
+
* Load config from script tag data attributes
|
|
2123
|
+
*/
|
|
2124
|
+
function loadFromScriptAttributes() {
|
|
2125
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
2126
|
+
return null;
|
|
2046
2127
|
}
|
|
2047
|
-
// Check for script tag with data attributes
|
|
2048
2128
|
const script = document.querySelector('script[data-astermind-key]');
|
|
2049
2129
|
if (script) {
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2130
|
+
const apiKey = script.getAttribute('data-astermind-key');
|
|
2131
|
+
if (apiKey) {
|
|
2132
|
+
return {
|
|
2133
|
+
apiKey,
|
|
2134
|
+
apiUrl: script.getAttribute('data-astermind-url') || DEFAULT_API_URL,
|
|
2135
|
+
_source: 'data-attr'
|
|
2136
|
+
};
|
|
2137
|
+
}
|
|
2054
2138
|
}
|
|
2055
2139
|
return null;
|
|
2056
2140
|
}
|
|
2141
|
+
/**
|
|
2142
|
+
* Load config using priority-based fallback chain:
|
|
2143
|
+
* 1. Environment variables (process.env - for bundlers/Node.js)
|
|
2144
|
+
* 2. Vite environment variables (import.meta.env or window.__ASTERMIND_CONFIG__)
|
|
2145
|
+
* 3. Global object (window.astermindConfig)
|
|
2146
|
+
* 4. Script data attributes (data-astermind-key, data-astermind-url)
|
|
2147
|
+
*
|
|
2148
|
+
* @param options - Configuration options
|
|
2149
|
+
* @param options.throwOnMissingKey - If true (default), throws when no API key found. If false, returns null and logs a warning.
|
|
2150
|
+
* @returns Configuration object or null if not found and throwOnMissingKey is false
|
|
2151
|
+
*/
|
|
2152
|
+
function loadConfig(options = {}) {
|
|
2153
|
+
const { throwOnMissingKey = true } = options;
|
|
2154
|
+
// Priority 1: Environment variables (Node.js/bundler)
|
|
2155
|
+
const envConfig = loadFromProcessEnv();
|
|
2156
|
+
if (envConfig) {
|
|
2157
|
+
return envConfig;
|
|
2158
|
+
}
|
|
2159
|
+
// Priority 2: Vite environment variables / SSR-injected config
|
|
2160
|
+
const viteConfig = loadFromViteEnv();
|
|
2161
|
+
if (viteConfig) {
|
|
2162
|
+
return viteConfig;
|
|
2163
|
+
}
|
|
2164
|
+
// Priority 3: Global object (window.astermindConfig)
|
|
2165
|
+
const globalConfig = loadFromGlobalObject();
|
|
2166
|
+
if (globalConfig) {
|
|
2167
|
+
validateConfig(globalConfig);
|
|
2168
|
+
return globalConfig;
|
|
2169
|
+
}
|
|
2170
|
+
// Priority 4: Script data attributes
|
|
2171
|
+
const scriptConfig = loadFromScriptAttributes();
|
|
2172
|
+
if (scriptConfig) {
|
|
2173
|
+
return scriptConfig;
|
|
2174
|
+
}
|
|
2175
|
+
// No config found
|
|
2176
|
+
if (throwOnMissingKey) {
|
|
2177
|
+
throw new Error('AsterMind API key is required. Configure using one of these methods:\n' +
|
|
2178
|
+
' 1. Set VITE_ASTERMIND_RAG_API_KEY environment variable (Vite)\n' +
|
|
2179
|
+
' 2. Set REACT_APP_ASTERMIND_RAG_API_KEY environment variable (CRA)\n' +
|
|
2180
|
+
' 3. Set window.astermindConfig = { apiKey: "am_...", apiUrl: "..." }\n' +
|
|
2181
|
+
' 4. Add data-astermind-key attribute to your script tag\n' +
|
|
2182
|
+
' 5. Pass apiKey directly to createClient() or CyberneticClient constructor');
|
|
2183
|
+
}
|
|
2184
|
+
else {
|
|
2185
|
+
console.warn('[AsterMind] No API key found. Chatbot will not function until configured.');
|
|
2186
|
+
return null;
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
/**
|
|
2190
|
+
* Export individual loaders for testing and advanced use cases
|
|
2191
|
+
*/
|
|
2192
|
+
const configLoaders = {
|
|
2193
|
+
loadFromProcessEnv,
|
|
2194
|
+
loadFromViteEnv,
|
|
2195
|
+
loadFromGlobalObject,
|
|
2196
|
+
loadFromScriptAttributes
|
|
2197
|
+
};
|
|
2057
2198
|
|
|
2058
2199
|
// src/agentic/CyberneticIntentClassifier.ts
|
|
2059
2200
|
// Hybrid intent classification for agentic capabilities
|
|
@@ -3261,5 +3402,5 @@ function createClient(config) {
|
|
|
3261
3402
|
return new CyberneticClient(config);
|
|
3262
3403
|
}
|
|
3263
3404
|
|
|
3264
|
-
export { ApiClient, CyberneticAgent, CyberneticCache, CyberneticClient, CyberneticIntentClassifier, CyberneticLocalRAG, LicenseManager, REQUIRED_FEATURES, createClient, createLicenseManager, detectEnvironment, getEnforcementMode, getTokenExpiration, isValidJWTFormat, loadConfig, registerAgenticCapabilities, validateConfig, verifyLicenseToken };
|
|
3405
|
+
export { ApiClient, CyberneticAgent, CyberneticCache, CyberneticClient, CyberneticIntentClassifier, CyberneticLocalRAG, LicenseManager, REQUIRED_FEATURES, configLoaders, createClient, createLicenseManager, detectEnvironment, getEnforcementMode, getTokenExpiration, isValidJWTFormat, loadConfig, registerAgenticCapabilities, validateConfig, verifyLicenseToken };
|
|
3265
3406
|
//# sourceMappingURL=cybernetic-chatbot-client.esm.js.map
|