open-agents-ai 0.16.4 → 0.16.5

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.
Files changed (2) hide show
  1. package/dist/index.js +52 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -9835,6 +9835,53 @@ async function fetchOllamaModels(baseUrl) {
9835
9835
  parameterSize: m.details?.parameter_size
9836
9836
  })).sort((a, b) => b.sizeBytes - a.sizeBytes);
9837
9837
  }
9838
+ async function fetchOpenAIModels(baseUrl, apiKey) {
9839
+ const normalized = normalizeBaseUrl(baseUrl);
9840
+ const url = `${normalized}/v1/models`;
9841
+ const headers = {};
9842
+ if (apiKey) {
9843
+ headers["Authorization"] = `Bearer ${apiKey}`;
9844
+ }
9845
+ const resp = await fetch(url, {
9846
+ headers,
9847
+ signal: AbortSignal.timeout(1e4)
9848
+ });
9849
+ if (!resp.ok) {
9850
+ throw new Error(`Failed to fetch models: HTTP ${resp.status}`);
9851
+ }
9852
+ const data = await resp.json();
9853
+ const models = data.data ?? [];
9854
+ return models.map((m) => ({
9855
+ name: m.id,
9856
+ size: m.context_length ? `${Math.round(m.context_length / 1024)}K ctx` : m.max_model_len ? `${Math.round(m.max_model_len / 1024)}K ctx` : "",
9857
+ sizeBytes: 0,
9858
+ modified: m.created ? formatRelativeTime(new Date(m.created * 1e3).toISOString()) : "",
9859
+ parameterSize: m.owned_by ?? void 0
9860
+ })).sort((a, b) => a.name.localeCompare(b.name));
9861
+ }
9862
+ async function fetchModels(baseUrl, apiKey) {
9863
+ const provider = detectProvider(baseUrl);
9864
+ if (provider.id === "ollama") {
9865
+ try {
9866
+ return await fetchOllamaModels(baseUrl);
9867
+ } catch {
9868
+ try {
9869
+ return await fetchOpenAIModels(baseUrl, apiKey);
9870
+ } catch {
9871
+ throw new Error("Cannot reach Ollama at " + baseUrl);
9872
+ }
9873
+ }
9874
+ }
9875
+ try {
9876
+ return await fetchOpenAIModels(baseUrl, apiKey);
9877
+ } catch {
9878
+ try {
9879
+ return await fetchOllamaModels(baseUrl);
9880
+ } catch {
9881
+ throw new Error(`Cannot fetch models from ${provider.label} at ${baseUrl}`);
9882
+ }
9883
+ }
9884
+ }
9838
9885
  function findModel(models, query) {
9839
9886
  const exact = models.find((m) => m.name === query);
9840
9887
  if (exact)
@@ -11535,7 +11582,7 @@ async function doSetup(config, rl) {
11535
11582
  }
11536
11583
  async function isModelAvailable(config) {
11537
11584
  try {
11538
- const models = await fetchOllamaModels(config.backendUrl);
11585
+ const models = await fetchModels(config.backendUrl, config.apiKey);
11539
11586
  return !!findModel(models, config.model);
11540
11587
  } catch {
11541
11588
  return false;
@@ -11910,7 +11957,7 @@ async function handleSlashCommand(input, ctx) {
11910
11957
  }
11911
11958
  async function listModels(ctx) {
11912
11959
  try {
11913
- const models = await fetchOllamaModels(ctx.config.backendUrl);
11960
+ const models = await fetchModels(ctx.config.backendUrl, ctx.config.apiKey);
11914
11961
  renderModelList(models.map((m) => ({ name: m.name, size: m.size, modified: m.modified })), ctx.config.model);
11915
11962
  } catch (err) {
11916
11963
  renderError(`Failed to fetch models: ${err instanceof Error ? err.message : String(err)}`);
@@ -11918,9 +11965,9 @@ async function listModels(ctx) {
11918
11965
  }
11919
11966
  async function showModelPicker(ctx) {
11920
11967
  try {
11921
- const models = await fetchOllamaModels(ctx.config.backendUrl);
11968
+ const models = await fetchModels(ctx.config.backendUrl, ctx.config.apiKey);
11922
11969
  if (models.length === 0) {
11923
- renderWarning("No models found. Pull a model with: ollama pull <model>");
11970
+ renderWarning("No models found.");
11924
11971
  return;
11925
11972
  }
11926
11973
  renderModelList(models.map((m) => ({ name: m.name, size: m.size, modified: m.modified })), ctx.config.model);
@@ -12114,7 +12161,7 @@ async function handleUpdate(subcommand, ctx) {
12114
12161
  }
12115
12162
  async function switchModel(query, ctx, local = false) {
12116
12163
  try {
12117
- const models = await fetchOllamaModels(ctx.config.backendUrl);
12164
+ const models = await fetchModels(ctx.config.backendUrl, ctx.config.apiKey);
12118
12165
  const match = findModel(models, query);
12119
12166
  if (!match) {
12120
12167
  renderError(`Model not found: "${query}"`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "open-agents-ai",
3
- "version": "0.16.4",
3
+ "version": "0.16.5",
4
4
  "description": "AI coding agent powered by open-source models (Ollama/vLLM) — interactive TUI with agentic tool-calling loop",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",