@hsuite/smart-engines-sdk 3.13.0 → 3.13.1

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.ts CHANGED
@@ -5423,8 +5423,9 @@ export declare function createAnthropicProvider(opts: {
5423
5423
  model: string;
5424
5424
  }): IModelProvider;
5425
5425
  export declare function createOpenAiProvider(opts: {
5426
- apiKey: string;
5426
+ apiKey?: string;
5427
5427
  model: string;
5428
+ baseURL?: string;
5428
5429
  }): IModelProvider;
5429
5430
  export declare function createGeminiProvider(opts: {
5430
5431
  apiKey: string;
@@ -5432,8 +5433,9 @@ export declare function createGeminiProvider(opts: {
5432
5433
  }): IModelProvider;
5433
5434
  export declare function createModelProvider(opts: {
5434
5435
  provider: ModelProvider;
5435
- apiKey: string;
5436
+ apiKey?: string;
5436
5437
  model: string;
5438
+ baseURL?: string;
5437
5439
  }): IModelProvider;
5438
5440
  export type InferJsonResult<T> = {
5439
5441
  ok: boolean;
@@ -5443,8 +5445,9 @@ export type InferJsonResult<T> = {
5443
5445
  };
5444
5446
  export declare function inferJson<T = unknown>(opts: {
5445
5447
  provider: ModelProvider;
5446
- apiKey: string;
5448
+ apiKey?: string;
5447
5449
  model: string;
5450
+ baseURL?: string;
5448
5451
  system?: string;
5449
5452
  input: unknown;
5450
5453
  maxTokens?: number;
package/dist/index.js CHANGED
@@ -10497,10 +10497,11 @@ function createAnthropicProvider(opts) {
10497
10497
  }
10498
10498
 
10499
10499
  // src/ai/openai.ts
10500
- var OPENAI_URL = "https://api.openai.com/v1/chat/completions";
10500
+ var DEFAULT_OPENAI_BASE_URL = "https://api.openai.com/v1";
10501
10501
  var DEFAULT_MAX_TOKENS2 = 1024;
10502
10502
  function createOpenAiProvider(opts) {
10503
10503
  const { apiKey, model } = opts;
10504
+ const url = `${(opts.baseURL ?? DEFAULT_OPENAI_BASE_URL).replace(/\/+$/, "")}/chat/completions`;
10504
10505
  return {
10505
10506
  provider: "openai",
10506
10507
  async infer(args) {
@@ -10514,11 +10515,13 @@ function createOpenAiProvider(opts) {
10514
10515
  let res;
10515
10516
  try {
10516
10517
  res = await fetchWithTimeout(
10517
- OPENAI_URL,
10518
+ url,
10518
10519
  {
10519
10520
  method: "POST",
10520
10521
  headers: {
10521
- Authorization: `Bearer ${apiKey}`,
10522
+ // Auth only when a key is supplied — a keyless local server (Ollama)
10523
+ // rejects a bogus Bearer header.
10524
+ ...apiKey ? { Authorization: `Bearer ${apiKey}` } : {},
10522
10525
  "content-type": "application/json"
10523
10526
  },
10524
10527
  body: JSON.stringify({
@@ -10603,14 +10606,14 @@ function createGeminiProvider(opts) {
10603
10606
 
10604
10607
  // src/ai/factory.ts
10605
10608
  function createModelProvider(opts) {
10606
- const { provider, apiKey, model } = opts;
10609
+ const { provider, apiKey, model, baseURL } = opts;
10607
10610
  switch (provider) {
10608
10611
  case "anthropic":
10609
- return createAnthropicProvider({ apiKey, model });
10612
+ return createAnthropicProvider({ apiKey: apiKey ?? "", model });
10610
10613
  case "openai":
10611
- return createOpenAiProvider({ apiKey, model });
10614
+ return createOpenAiProvider({ apiKey, model, baseURL });
10612
10615
  case "gemini":
10613
- return createGeminiProvider({ apiKey, model });
10616
+ return createGeminiProvider({ apiKey: apiKey ?? "", model });
10614
10617
  default: {
10615
10618
  const never = provider;
10616
10619
  throw new Error(`Unsupported model provider: ${String(never)}`);
@@ -10675,10 +10678,10 @@ function extractJson(raw) {
10675
10678
  );
10676
10679
  }
10677
10680
  async function inferJson(opts) {
10678
- const { provider, apiKey, model, system, input, maxTokens, timeoutMs, signal, parse } = opts;
10681
+ const { provider, apiKey, model, baseURL, system, input, maxTokens, timeoutMs, signal, parse } = opts;
10679
10682
  let client;
10680
10683
  try {
10681
- client = createModelProvider({ provider, apiKey, model });
10684
+ client = createModelProvider({ provider, apiKey, model, baseURL });
10682
10685
  } catch (err) {
10683
10686
  return { ok: false, error: errMsg(err) };
10684
10687
  }