@stacksjs/ai 0.70.254 → 0.70.256
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/client.d.ts +7 -1
- package/dist/client.js +24 -2
- package/dist/types.d.ts +12 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import type { AIProvider, ConfiguredAIClient, ConfiguredAIOptions } from './types';
|
|
1
|
+
import type { AIProvider, AIProviderConfiguration, ConfiguredAIClient, ConfiguredAIOptions } from './types';
|
|
2
|
+
export declare function resolveAIProvider(config: ConfiguredAIOptions, override?: AIProvider): AIProvider;
|
|
3
|
+
/**
|
|
4
|
+
* Inspect the selected provider without creating a request or exposing secrets.
|
|
5
|
+
* Applications can use this for health checks, settings screens, and fallbacks.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getAIProviderConfiguration(config: ConfiguredAIOptions, override?: AIProvider, environment?: Record<string, string | undefined>): AIProviderConfiguration;
|
|
2
8
|
declare function parseObject(content: string): unknown;
|
|
3
9
|
declare function validateSchema(value: unknown, schema: Record<string, any>, path?: string): string[];
|
|
4
10
|
/**
|
package/dist/client.js
CHANGED
|
@@ -7,7 +7,7 @@ function textContent(content) {
|
|
|
7
7
|
return content.filter((block) => block.type === "text").map((block) => block.text ?? "").join(`
|
|
8
8
|
`);
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
export function resolveAIProvider(config, override) {
|
|
11
11
|
if (override)
|
|
12
12
|
return override;
|
|
13
13
|
const configured = String(config.default || "").toLowerCase();
|
|
@@ -19,6 +19,27 @@ function providerFromConfig(config, override) {
|
|
|
19
19
|
return "ollama";
|
|
20
20
|
throw Error(`Unsupported configured AI driver: ${config.default || "(empty)"}. Expected anthropic, openai, or ollama.`);
|
|
21
21
|
}
|
|
22
|
+
function configuredModel(config, provider) {
|
|
23
|
+
const driverModel = config.drivers?.[provider]?.model?.trim();
|
|
24
|
+
if (driverModel)
|
|
25
|
+
return driverModel;
|
|
26
|
+
const configuredDefault = String(config.default || "").trim();
|
|
27
|
+
if (!configuredDefault || configuredDefault.toLowerCase() === provider)
|
|
28
|
+
return;
|
|
29
|
+
return configuredDefault;
|
|
30
|
+
}
|
|
31
|
+
export function getAIProviderConfiguration(config, override, environment = process.env) {
|
|
32
|
+
const provider = resolveAIProvider(config, override), driver = config.drivers?.[provider] ?? {}, model = configuredModel(config, provider);
|
|
33
|
+
if (provider === "ollama")
|
|
34
|
+
return { provider, model, configured: !0, source: "local" };
|
|
35
|
+
if (driver.apiKey?.trim())
|
|
36
|
+
return { provider, model, configured: !0, source: "config" };
|
|
37
|
+
if (environment[provider === "openai" ? "OPENAI_API_KEY" : "ANTHROPIC_API_KEY"]?.trim())
|
|
38
|
+
return { provider, model, configured: !0, source: "environment" };
|
|
39
|
+
if (driver.baseUrl?.trim())
|
|
40
|
+
return { provider, model, configured: !0, source: "base-url" };
|
|
41
|
+
return { provider, model, configured: !1, source: "none" };
|
|
42
|
+
}
|
|
22
43
|
function parseObject(content) {
|
|
23
44
|
const unfenced = content.trim().replace(/^```(?:json)?\s*/i, "").replace(/\s*```$/, "");
|
|
24
45
|
try {
|
|
@@ -132,9 +153,10 @@ function createGenerate(config, provider) {
|
|
|
132
153
|
};
|
|
133
154
|
}
|
|
134
155
|
export function createAIClient(config, override) {
|
|
135
|
-
const provider =
|
|
156
|
+
const provider = resolveAIProvider(config, override), configuration = getAIProviderConfiguration(config, provider), generate = createGenerate(config, provider);
|
|
136
157
|
return {
|
|
137
158
|
provider,
|
|
159
|
+
configuration,
|
|
138
160
|
generate,
|
|
139
161
|
async generateObject(messages, schema, options = {}) {
|
|
140
162
|
const { attempts = 2, system, ...completionOptions } = options, history = [...messages];
|
package/dist/types.d.ts
CHANGED
|
@@ -168,6 +168,16 @@ export declare interface AIConfig {
|
|
|
168
168
|
search?: SearchConfig
|
|
169
169
|
mcp?: MCPConfig
|
|
170
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Safe, provider-neutral configuration metadata for diagnostics and UI.
|
|
173
|
+
* Never includes credentials.
|
|
174
|
+
*/
|
|
175
|
+
export declare interface AIProviderConfiguration {
|
|
176
|
+
provider: AIProvider
|
|
177
|
+
model?: string
|
|
178
|
+
configured: boolean
|
|
179
|
+
source: AIConfigurationSource
|
|
180
|
+
}
|
|
171
181
|
export declare interface ConfiguredAIOptions extends AIConfig {
|
|
172
182
|
drivers?: {
|
|
173
183
|
anthropic?: AIDriverConfig & { anthropicVersion?: string }
|
|
@@ -181,6 +191,7 @@ export declare interface GenerateObjectOptions extends ChatCompletionOptions {
|
|
|
181
191
|
}
|
|
182
192
|
export declare interface ConfiguredAIClient {
|
|
183
193
|
provider: AIProvider
|
|
194
|
+
configuration: AIProviderConfiguration
|
|
184
195
|
generate: (messages: AIMessage[], options?: ChatCompletionOptions & { system?: string }) => Promise<AIResult>
|
|
185
196
|
generateObject: <T>(
|
|
186
197
|
messages: AIMessage[],
|
|
@@ -204,3 +215,4 @@ export type AIResponseFormat = | { type: 'text' }
|
|
|
204
215
|
}
|
|
205
216
|
}
|
|
206
217
|
export type AIProvider = 'anthropic' | 'openai' | 'ollama';
|
|
218
|
+
export type AIConfigurationSource = 'config' | 'environment' | 'base-url' | 'local' | 'none';
|