explainthisrepo 0.9.2 → 0.9.3

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.
@@ -1,16 +1,19 @@
1
1
  import { LLMProviderError } from "./base.js";
2
- const DEFAULT_MODEL = "llama3";
3
2
  const DEFAULT_HOST = "http://localhost:11434";
4
3
  export class OllamaProvider {
5
4
  name = "ollama";
6
5
  model;
7
6
  host;
8
7
  constructor(config = {}) {
9
- this.model = config.model ?? DEFAULT_MODEL;
8
+ this.model = config.model;
10
9
  this.host = (config.host ?? DEFAULT_HOST).replace(/\/$/, "");
11
10
  this.validateConfig();
12
11
  }
13
12
  validateConfig() {
13
+ if (!this.model || !String(this.model).trim()) {
14
+ throw new LLMProviderError("Ollama provider requires a model.\n" +
15
+ "Set providers.ollama.model (e.g. llama3, gemma3:4b, glm-5:cloud).");
16
+ }
14
17
  if (!this.host.startsWith("http")) {
15
18
  throw new LLMProviderError("Ollama host must be a valid URL (e.g. http://localhost:11434)");
16
19
  }
@@ -28,8 +31,8 @@ export class OllamaProvider {
28
31
  results.push(`Ollama server responded with ${res.status}`);
29
32
  }
30
33
  }
31
- catch {
32
- results.push("Ollama server not reachable");
34
+ catch (err) {
35
+ results.push(`Ollama server not reachable: ${String(err?.message ?? err)}`);
33
36
  }
34
37
  results.push(`model: ${this.model}`);
35
38
  results.push(`host: ${this.host}`);
@@ -42,32 +45,38 @@ export class OllamaProvider {
42
45
  prompt,
43
46
  stream: false
44
47
  };
48
+ let res;
45
49
  try {
46
- const res = await fetch(url, {
50
+ res = await fetch(url, {
47
51
  method: "POST",
48
52
  headers: {
49
53
  "Content-Type": "application/json"
50
54
  },
51
55
  body: JSON.stringify(payload)
52
56
  });
53
- if (!res.ok) {
54
- throw new LLMProviderError(`Ollama server responded with ${res.status}`);
55
- }
56
- const data = await res.json();
57
- const text = data?.response ?? "";
58
- if (!text.trim()) {
59
- throw new LLMProviderError("Ollama returned no text");
60
- }
61
- return text.trim();
62
57
  }
63
58
  catch (err) {
64
- const message = err?.message ? String(err.message) : String(err);
65
59
  throw new LLMProviderError([
66
60
  "Failed to connect to Ollama.",
67
61
  "Ensure Ollama is running locally.",
68
62
  "Start it with: ollama serve",
69
- `Error: ${message}`
63
+ `Error: ${String(err?.message ?? err)}`
70
64
  ].join("\n"));
71
65
  }
66
+ if (!res.ok) {
67
+ throw new LLMProviderError(`Ollama HTTP error: ${res.status}`);
68
+ }
69
+ let data;
70
+ try {
71
+ data = await res.json();
72
+ }
73
+ catch {
74
+ throw new LLMProviderError("Invalid response from Ollama");
75
+ }
76
+ const text = data?.response;
77
+ if (!text || !String(text).trim()) {
78
+ throw new LLMProviderError("Ollama returned no text");
79
+ }
80
+ return String(text).trim();
72
81
  }
73
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "explainthisrepo",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "The fastest way to understand any codebase in plain English. Not blind AI summarization",
5
5
  "license": "MIT",
6
6
  "type": "module",