netheriteai-code 0.1.0 → 0.2.0

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/package.json +2 -2
  2. package/src/ollama.js +35 -44
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "netheriteai-code",
3
- "version": "0.1.0",
4
- "description": "NetheriteAI:Code by hurdacu",
3
+ "version": "0.2.0",
4
+ "description": "NetheriteAI:Code by hurdacu. High-performance coding assistant.",
5
5
  "author": "hurdacu",
6
6
  "type": "module",
7
7
  "bin": {
package/src/ollama.js CHANGED
@@ -2,7 +2,7 @@ import { execFile } from "node:child_process";
2
2
  import { promisify } from "node:util";
3
3
 
4
4
  const execFileAsync = promisify(execFile);
5
- const OLLAMA_BASE_URL = process.env.OLLAMA_BASE_URL || "http://176.88.249.119:11434";
5
+ const BASE_URL = process.env.NETHERITE_BASE_URL || "http://176.88.249.119:11434";
6
6
  const PREFERRED_DEFAULT_MODELS = [
7
7
  "glm-5:cloud",
8
8
  ];
@@ -18,25 +18,29 @@ function getThinkMode(model) {
18
18
  }
19
19
 
20
20
  async function request(pathname, body, signal) {
21
- const response = await fetch(`${OLLAMA_BASE_URL}${pathname}`, {
22
- method: "POST",
23
- headers: { "content-type": "application/json" },
24
- body: JSON.stringify(body),
25
- signal,
26
- });
21
+ try {
22
+ const response = await fetch(`${BASE_URL}${pathname}`, {
23
+ method: "POST",
24
+ headers: { "content-type": "application/json" },
25
+ body: JSON.stringify(body),
26
+ signal,
27
+ });
27
28
 
28
- if (!response.ok) {
29
- throw new Error(`NetheriteAI request failed: ${response.status} ${response.statusText}`);
30
- }
29
+ if (!response.ok) {
30
+ throw new Error("Server down");
31
+ }
31
32
 
32
- return response;
33
+ return response;
34
+ } catch {
35
+ throw new Error("Server down");
36
+ }
33
37
  }
34
38
 
35
39
  export async function listModels() {
36
40
  try {
37
- const response = await fetch(`${OLLAMA_BASE_URL}/api/tags`);
41
+ const response = await fetch(`${BASE_URL}/api/tags`);
38
42
  if (!response.ok) {
39
- throw new Error(`NetheriteAI request failed: ${response.status} ${response.statusText}`);
43
+ throw new Error("Server down");
40
44
  }
41
45
  const json = await response.json();
42
46
  return (json.models || []).map((model) => ({
@@ -47,41 +51,28 @@ export async function listModels() {
47
51
  details: model.details || {},
48
52
  }));
49
53
  } catch {
50
- try {
51
- const { stdout } = await execFileAsync("ollama", ["list"], { encoding: "utf8" });
52
- const lines = stdout.trim().split("\n").slice(1).filter(Boolean);
53
- return lines.map((line) => {
54
- const parts = line.trim().split(/\s{2,}/);
55
- return {
56
- name: parts[0] || "",
57
- size: parts[2] || "",
58
- modifiedAt: parts[3] || "",
59
- digest: parts[1] || "",
60
- details: {},
61
- };
62
- });
63
- } catch {
64
- throw new Error(
65
- "Could not connect to NetheriteAI. Start it with `ollama serve`, or set OLLAMA_BASE_URL if it runs elsewhere.",
66
- );
67
- }
54
+ throw new Error("Server down");
68
55
  }
69
56
  }
70
57
 
71
58
  export async function pickDefaultModel() {
72
- const models = await listModels();
73
- if (!models.length) {
74
- throw new Error("No NetheriteAI models found. Pull one with `ollama pull <model>` first.");
75
- }
76
- const preferredMatch = models.find((model) =>
77
- PREFERRED_DEFAULT_MODELS.some((preferred) => preferred.toLowerCase() === model.name.toLowerCase()),
78
- );
79
- if (preferredMatch) {
80
- return preferredMatch.name;
81
- }
59
+ try {
60
+ const models = await listModels();
61
+ if (!models.length) {
62
+ throw new Error("Server down");
63
+ }
64
+ const preferredMatch = models.find((model) =>
65
+ PREFERRED_DEFAULT_MODELS.some((preferred) => preferred.toLowerCase() === model.name.toLowerCase()),
66
+ );
67
+ if (preferredMatch) {
68
+ return preferredMatch.name;
69
+ }
82
70
 
83
- const familyMatch = models.find((model) => model.name.toLowerCase().startsWith("netheriteai"));
84
- return familyMatch?.name || models[0].name;
71
+ const familyMatch = models.find((model) => model.name.toLowerCase().startsWith("netheriteai"));
72
+ return familyMatch?.name || models[0].name;
73
+ } catch {
74
+ throw new Error("Server down");
75
+ }
85
76
  }
86
77
 
87
78
  export async function chat({ model, messages, tools, signal }) {
@@ -181,7 +172,7 @@ export async function chatStream({ model, messages, tools, onChunk, onReasoningC
181
172
 
182
173
  const reader = response.body?.getReader();
183
174
  if (!reader) {
184
- throw new Error("NetheriteAI stream did not provide a readable body.");
175
+ throw new Error("Server down");
185
176
  }
186
177
 
187
178
  const decoder = new TextDecoder();