@123toto/ai-app-assistant-server 0.2.1 → 0.2.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/README.md CHANGED
@@ -64,6 +64,23 @@ const aiAppAssistant = createManagedAiAppAssistantServer({
64
64
  await aiAppAssistant.initialize();
65
65
  ```
66
66
 
67
+ For deployments exposing one provider at a time, the library maps generic
68
+ runtime values without requiring provider-specific environment variables:
69
+
70
+ ```ts
71
+ const deployment = createAiAppAssistantDeploymentDefaults({
72
+ enabled: env.AI_APP_ASSISTANT_LLM_ENABLED,
73
+ provider: env.AI_APP_ASSISTANT_PROVIDER,
74
+ model: env.AI_APP_ASSISTANT_LLM_MODEL,
75
+ apiKey: env.AI_APP_ASSISTANT_API_KEY,
76
+ baseURL: env.AI_APP_ASSISTANT_LOCAL_LLM_BASE_URL
77
+ });
78
+ ```
79
+
80
+ `baseURL` is required for the local `ollama` provider. API keys and encryption
81
+ keys must come from a runtime secret store; they must never be committed or
82
+ embedded in an application image.
83
+
67
84
  `enabled: false` disables every provider operation while keeping the host
68
85
  application and the read-only administration endpoints available.
69
86
 
@@ -1,4 +1,4 @@
1
- import { M as ManagedAiAppAssistantServer } from './managed-server-CQb-RK-i.cjs';
1
+ import { M as ManagedAiAppAssistantServer } from './managed-server-wXfu_9rp.cjs';
2
2
  import './ai-sdk-qU3KgNu-.cjs';
3
3
  import 'ai';
4
4
  import '@123toto/ai-app-assistant-contracts';
package/dist/express.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { M as ManagedAiAppAssistantServer } from './managed-server-CGmvVYsF.js';
1
+ import { M as ManagedAiAppAssistantServer } from './managed-server-CusQWWBB.js';
2
2
  import './ai-sdk-qU3KgNu-.js';
3
3
  import 'ai';
4
4
  import '@123toto/ai-app-assistant-contracts';
package/dist/index.cjs CHANGED
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ AI_APP_ASSISTANT_PROVIDERS: () => AI_APP_ASSISTANT_PROVIDERS,
23
24
  AiAppAssistantConfigurationConflictError: () => AiAppAssistantConfigurationConflictError,
24
25
  AiAppAssistantConfigurationManager: () => AiAppAssistantConfigurationManager,
25
26
  AiAppAssistantManagementError: () => AiAppAssistantManagementError,
@@ -1464,6 +1465,7 @@ function quotaResult(count, resetAt, maxRequests, now) {
1464
1465
  }
1465
1466
 
1466
1467
  // src/provider-catalog.ts
1468
+ var AI_APP_ASSISTANT_PROVIDERS = ["anthropic", "google", "mistral", "ollama", "openai"];
1467
1469
  var PROVIDERS = Object.freeze([
1468
1470
  { id: "anthropic", label: "Anthropic", requiresApiKey: true, supportsModelDiscovery: true },
1469
1471
  { id: "google", label: "Google Gemini", requiresApiKey: true, supportsModelDiscovery: true },
@@ -2818,21 +2820,38 @@ function createAiAppAssistantDeploymentDefaults(options) {
2818
2820
  const apiKeys = Object.fromEntries(
2819
2821
  Object.entries(options.apiKeys ?? {}).map(([provider2, value]) => [provider2, value?.trim() || void 0])
2820
2822
  );
2821
- const resolveApiKey2 = (provider2) => apiKeys[provider2];
2823
+ const selectedProvider = options.provider;
2824
+ const selectedApiKey = options.apiKey?.trim() || void 0;
2825
+ const resolveApiKey2 = (provider2) => provider2 === selectedProvider ? selectedApiKey ?? apiKeys[provider2] : apiKeys[provider2];
2822
2826
  if (!options.enabled || !options.model?.trim()) return { resolveApiKey: resolveApiKey2 };
2823
- const match = options.model.trim().match(/^([^:/]+)[:/](.+)$/);
2824
- if (!match) throw new TypeError(`Invalid AI App Assistant model identifier: ${options.model}`);
2825
- const provider = match[1] === "gemini" ? "google" : match[1];
2827
+ const rawModel = options.model.trim();
2828
+ const legacyMatch = selectedProvider ? void 0 : rawModel.match(/^([^:/]+)[:/](.+)$/);
2829
+ const explicitMatch = selectedProvider ? rawModel.match(/^([^:]+):(.+)$/) : void 0;
2830
+ if (!selectedProvider && !legacyMatch) {
2831
+ throw new TypeError(`Invalid AI App Assistant model identifier: ${options.model}`);
2832
+ }
2833
+ const parsedProvider = legacyMatch?.[1] ?? explicitMatch?.[1];
2834
+ const modelProvider = parsedProvider === "gemini" ? "google" : parsedProvider ?? selectedProvider;
2835
+ const provider = modelProvider;
2826
2836
  if (!listAiProviders().some((candidate) => candidate.id === provider)) {
2827
- throw new TypeError(`Unsupported AI App Assistant provider: ${match[1]}`);
2837
+ throw new TypeError(`Unsupported AI App Assistant provider: ${modelProvider}`);
2828
2838
  }
2839
+ if (selectedProvider && explicitMatch && provider !== selectedProvider) {
2840
+ throw new TypeError(
2841
+ `AI App Assistant provider '${selectedProvider}' does not match model identifier '${options.model}'`
2842
+ );
2843
+ }
2844
+ const model = legacyMatch?.[2]?.trim() ?? explicitMatch?.[2]?.trim() ?? rawModel;
2829
2845
  const apiKey = resolveApiKey2(provider);
2830
- const baseURL = options.baseURLs?.[provider]?.trim() || void 0;
2846
+ const baseURL = (provider === selectedProvider ? options.baseURL?.trim() : void 0) || options.baseURLs?.[provider]?.trim() || void 0;
2847
+ if (provider === "ollama" && !baseURL) {
2848
+ throw new TypeError("AI App Assistant local provider 'ollama' requires a base URL");
2849
+ }
2831
2850
  return {
2832
2851
  resolveApiKey: resolveApiKey2,
2833
2852
  configuration: {
2834
2853
  provider,
2835
- model: match[2].trim(),
2854
+ model,
2836
2855
  connectionSource: "environment",
2837
2856
  ...apiKey ? { apiKey } : {},
2838
2857
  ...baseURL ? { baseURL } : {},
@@ -3042,6 +3061,7 @@ function clampInteger3(value, minimum, maximum) {
3042
3061
  var import_ai_app_assistant_contracts6 = require("@123toto/ai-app-assistant-contracts");
3043
3062
  // Annotate the CommonJS export names for ESM import in node:
3044
3063
  0 && (module.exports = {
3064
+ AI_APP_ASSISTANT_PROVIDERS,
3045
3065
  AiAppAssistantConfigurationConflictError,
3046
3066
  AiAppAssistantConfigurationManager,
3047
3067
  AiAppAssistantManagementError,