// Copyright (C) 2026 Rob Colbert <rob.colbert@openplatform.us>
// Licensed under the Apache License, Version 2.0

export { IAiEnvironment } from "./config/env.ts";

export {
  type AiSdkType,
  type IAiProvider,
  type IAiModelConfig,
  type IAiInferenceStats,
  type IAiGenerateOptions,
  type IAiGenerateResponse,
  type IContextChatMessage,
  type IAiChatOptions,
  type IAiChatResponse,
  type IToolCall,
  type IAiStreamChunk,
  type IAiResponseStreamFn,
  type IAiLogger,
  defaultLogger,
  AiApi,
  type IAiModelListResult,
  type IAiModelProbeResult,
} from "./api.js";

export type {
  IAiTool,
  IToolArguments,
  IToolDefinition,
} from "./tools/tool.js";
export { formatError, type IToolError, type ToolErrorCode } from "./tools/tool-error.ts";

export { OllamaAiApi } from "./ollama.js";
export { OpenAiApi } from "./openai.js";

import { OllamaAiApi } from "./ollama.js";
import { OpenAiApi } from "./openai.js";
import type { IAiProvider } from "./api.js";
import type { IAiLogger } from "./api.js";
import type { AiApi } from "./api.js";
import { IAiEnvironment } from "./config/env.ts";

export function createAiApi(
  env: IAiEnvironment,
  provider: IAiProvider,
  logger?: IAiLogger,
): AiApi {
  switch (provider.sdk) {
    case "ollama":
      return new OllamaAiApi(env, provider, logger);
    case "openai":
      return new OpenAiApi(env, provider, logger);
    default:
      throw new Error(`Unknown AI SDK: ${(provider as IAiProvider).sdk}`);
  }
}
