@vtstech/pi-ollama-sync 1.0.3 → 1.0.4-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.
Files changed (3) hide show
  1. package/README.md +40 -0
  2. package/ollama-sync.js +31 -44
  3. package/package.json +3 -2
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # @vtstech/pi-ollama-sync
2
+
3
+ Ollama sync extension for the [Pi Coding Agent](https://github.com/badlogic/pi-mono).
4
+
5
+ Auto-populate `models.json` with all available Ollama models — works with local and remote instances.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pi install "npm:@vtstech/pi-ollama-sync"
11
+ ```
12
+
13
+ ## Commands
14
+
15
+ ```bash
16
+ /ollama-sync Sync from models.json URL (or localhost)
17
+ /ollama-sync https://your-tunnel-url Sync from a specific remote URL
18
+ ```
19
+
20
+ ## Features
21
+
22
+ - Queries Ollama `/api/tags` for available models (local or remote)
23
+ - Writes the actual Ollama URL back into `models.json` so other extensions pick it up
24
+ - URL priority: CLI argument → existing `models.json` baseUrl → `OLLAMA_HOST` env → localhost
25
+ - Preserves existing provider config (apiKey, compat settings)
26
+ - Defaults to `openai-completions` API mode
27
+ - Sorts models by size (smallest first)
28
+ - Auto-detects reasoning-capable models (deepseek-r1, qwq, o1, o3, think, reason)
29
+ - Merges with existing per-model settings
30
+ - Per-model metadata in sync report (parameter size, quantization level, model family)
31
+ - Registered as both `/ollama-sync` slash command and `ollama_sync` tool
32
+
33
+ ## Links
34
+
35
+ - [Full Documentation](https://github.com/VTSTech/pi-coding-agent#ollama-sync-ollama-syncts)
36
+ - [Changelog](https://github.com/VTSTech/pi-coding-agent/blob/main/CHANGELOG.md)
37
+
38
+ ## License
39
+
40
+ MIT — [VTSTech](https://www.vts-tech.org)
package/ollama-sync.js CHANGED
@@ -1,29 +1,13 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
1
  // .build-npm/ollama-sync/ollama-sync.temp.ts
20
- var ollama_sync_temp_exports = {};
21
- __export(ollama_sync_temp_exports, {
22
- default: () => ollama_sync_temp_default
23
- });
24
- module.exports = __toCommonJS(ollama_sync_temp_exports);
25
- var import_ollama = require("@vtstech/pi-shared/ollama");
26
- var import_format = require("@vtstech/pi-shared/format");
2
+ import {
3
+ MODELS_JSON_PATH as MODELS_FILE,
4
+ fetchOllamaModels,
5
+ readModelsJson,
6
+ writeModelsJson,
7
+ isReasoningModel,
8
+ getOllamaBaseUrl
9
+ } from "@vtstech/pi-shared/ollama";
10
+ import { section, ok, warn, info } from "@vtstech/pi-shared/format";
27
11
  var BRANDING = [
28
12
  ` \u26A1 Pi Ollama Sync v1.0.3`,
29
13
  ` Written by VTSTech`,
@@ -31,7 +15,7 @@ var BRANDING = [
31
15
  ` Website: www.vts-tech.org`
32
16
  ].join("\n");
33
17
  function getProviderConfig(existing) {
34
- const defaultUrl = (0, import_ollama.getOllamaBaseUrl)();
18
+ const defaultUrl = getOllamaBaseUrl();
35
19
  const ollama = existing.providers["ollama"];
36
20
  return {
37
21
  baseUrl: ollama?.baseUrl ?? defaultUrl + "/v1",
@@ -46,7 +30,7 @@ function getProviderConfig(existing) {
46
30
  function buildModelEntry(m) {
47
31
  return {
48
32
  id: m.name,
49
- reasoning: (0, import_ollama.isReasoningModel)(m.name),
33
+ reasoning: isReasoningModel(m.name),
50
34
  parameterSize: m.details.parameter_size,
51
35
  quantizationLevel: m.details.quantization_level,
52
36
  modelFamily: m.details.family || m.details.families?.[0] || "unknown"
@@ -70,7 +54,7 @@ function ollama_sync_temp_default(pi) {
70
54
  pi.registerCommand("ollama-sync", {
71
55
  description: "Sync models from Ollama into models.json. Use: /ollama-sync [url]",
72
56
  getArgumentCompletions: async () => {
73
- const url = (0, import_ollama.getOllamaBaseUrl)();
57
+ const url = getOllamaBaseUrl();
74
58
  return [
75
59
  { value: url, label: url, description: "Default Ollama URL..." }
76
60
  ];
@@ -80,10 +64,10 @@ function ollama_sync_temp_default(pi) {
80
64
  const overrideUrl = arg || void 0;
81
65
  ctx.ui.setStatus("ollama-sync", "Fetching models from Ollama...");
82
66
  try {
83
- const existing = (0, import_ollama.readModelsJson)();
67
+ const existing = readModelsJson();
84
68
  const config = getProviderConfig(existing);
85
- const ollamaBaseUrl = overrideUrl ? overrideUrl.replace(/\/v1$/, "").replace(/\/+$/, "") : config.baseUrl?.replace(/\/v1$/, "") ?? (0, import_ollama.getOllamaBaseUrl)();
86
- const models = await (0, import_ollama.fetchOllamaModels)(ollamaBaseUrl);
69
+ const ollamaBaseUrl = overrideUrl ? overrideUrl.replace(/\/v1$/, "").replace(/\/+$/, "") : config.baseUrl?.replace(/\/v1$/, "") ?? getOllamaBaseUrl();
70
+ const models = await fetchOllamaModels(ollamaBaseUrl);
87
71
  if (models.length === 0) {
88
72
  ctx.ui.notify("No models found in Ollama", "info");
89
73
  ctx.ui.setStatus("ollama-sync", void 0);
@@ -105,30 +89,30 @@ function ollama_sync_temp_default(pi) {
105
89
  baseUrl: ollamaBaseUrl + "/v1",
106
90
  models: mergedModels
107
91
  };
108
- (0, import_ollama.writeModelsJson)(existing);
92
+ writeModelsJson(existing);
109
93
  const lines = [""];
110
94
  lines.push(` Ollama: ${ollamaBaseUrl}`);
111
95
  lines.push(` Synced ${newModels.length} models from Ollama`);
112
- lines.push((0, import_format.section)("Synced Models"));
96
+ lines.push(section("Synced Models"));
113
97
  for (const m of newModels) {
114
- lines.push((0, import_format.ok)(m.id));
98
+ lines.push(ok(m.id));
115
99
  lines.push(
116
100
  ` Params: ${m.parameterSize ?? "?"} \xB7 Quant: ${m.quantizationLevel ?? "?"} \xB7 Family: ${m.modelFamily ?? "?"}`
117
101
  );
118
102
  }
119
103
  if (added.length > 0 || removed.length > 0) {
120
- lines.push((0, import_format.section)("Changes"));
104
+ lines.push(section("Changes"));
121
105
  if (added.length > 0) {
122
- lines.push((0, import_format.ok)(`Added ${added.length}: ${added.map((m) => m.id).join(", ")}`));
106
+ lines.push(ok(`Added ${added.length}: ${added.map((m) => m.id).join(", ")}`));
123
107
  }
124
108
  if (removed.length > 0) {
125
- lines.push((0, import_format.warn)(`Removed ${removed.length}: ${removed.join(", ")}`));
109
+ lines.push(warn(`Removed ${removed.length}: ${removed.join(", ")}`));
126
110
  }
127
111
  } else {
128
- lines.push((0, import_format.info)("No changes \u2014 already in sync"));
112
+ lines.push(info("No changes \u2014 already in sync"));
129
113
  }
130
114
  lines.push("");
131
- lines.push(` Written to ${import_ollama.MODELS_JSON_PATH}`);
115
+ lines.push(` Written to ${MODELS_FILE}`);
132
116
  lines.push(` Run /reload to pick up changes`);
133
117
  lines.push(BRANDING);
134
118
  const report = lines.join("\n");
@@ -163,11 +147,11 @@ function ollama_sync_temp_default(pi) {
163
147
  },
164
148
  async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
165
149
  const overrideUrl = params?.url;
166
- const existing = (0, import_ollama.readModelsJson)();
150
+ const existing = readModelsJson();
167
151
  const config = getProviderConfig(existing);
168
- const ollamaBaseUrl = overrideUrl ? overrideUrl.replace(/\/v1$/, "").replace(/\/+$/, "") : config.baseUrl?.replace(/\/v1$/, "") ?? (0, import_ollama.getOllamaBaseUrl)();
152
+ const ollamaBaseUrl = overrideUrl ? overrideUrl.replace(/\/v1$/, "").replace(/\/+$/, "") : config.baseUrl?.replace(/\/v1$/, "") ?? getOllamaBaseUrl();
169
153
  try {
170
- const models = await (0, import_ollama.fetchOllamaModels)(ollamaBaseUrl);
154
+ const models = await fetchOllamaModels(ollamaBaseUrl);
171
155
  const sorted = [...models].sort((a, b) => a.size - b.size);
172
156
  const newModels = sorted.map(buildModelEntry);
173
157
  const mergedModels = mergeModels(
@@ -179,7 +163,7 @@ function ollama_sync_temp_default(pi) {
179
163
  baseUrl: ollamaBaseUrl + "/v1",
180
164
  models: mergedModels
181
165
  };
182
- (0, import_ollama.writeModelsJson)(existing);
166
+ writeModelsJson(existing);
183
167
  const modelDetails = newModels.map(
184
168
  (m) => ` \u2022 ${m.id} (${m.parameterSize}, ${m.quantizationLevel}, family: ${m.modelFamily})`
185
169
  ).join("\n");
@@ -189,7 +173,7 @@ function ollama_sync_temp_default(pi) {
189
173
  type: "text",
190
174
  text: `${BRANDING}
191
175
 
192
- Synced ${newModels.length} models from ${ollamaBaseUrl} to ${import_ollama.MODELS_JSON_PATH}. Run /reload to pick up changes.
176
+ Synced ${newModels.length} models from ${ollamaBaseUrl} to ${MODELS_FILE}. Run /reload to pick up changes.
193
177
 
194
178
  ${modelDetails}`
195
179
  }
@@ -205,3 +189,6 @@ ${modelDetails}`
205
189
  }
206
190
  });
207
191
  }
192
+ export {
193
+ ollama_sync_temp_default as default
194
+ };
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@vtstech/pi-ollama-sync",
3
- "version": "1.0.3",
3
+ "version": "1.0.4-1",
4
4
  "description": "Ollama model sync extension for Pi Coding Agent",
5
5
  "main": "ollama-sync.js",
6
6
  "keywords": ["pi-package", "pi-extensions"],
7
7
  "license": "MIT",
8
8
  "access": "public",
9
+ "type": "module",
9
10
  "author": "VTSTech",
10
11
  "homepage": "https://www.vts-tech.org",
11
12
  "repository": {
@@ -13,7 +14,7 @@
13
14
  "url": "https://github.com/VTSTech/pi-coding-agent"
14
15
  },
15
16
  "dependencies": {
16
- "@vtstech/pi-shared": "1.0.3"
17
+ "@vtstech/pi-shared": "1.0.4-1"
17
18
  },
18
19
  "peerDependencies": {
19
20
  "@mariozechner/pi-coding-agent": ">=0.66"