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