@vtstech/pi-ollama-sync 1.1.7 → 1.1.9
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.
- package/ollama-sync.js +34 -34
- package/package.json +2 -2
package/ollama-sync.js
CHANGED
|
@@ -4,11 +4,13 @@ import {
|
|
|
4
4
|
fetchOllamaModels,
|
|
5
5
|
fetchContextLengthsBatched,
|
|
6
6
|
readModelsJson,
|
|
7
|
-
|
|
7
|
+
readModifyWriteModelsJson,
|
|
8
8
|
isReasoningModel,
|
|
9
9
|
getOllamaBaseUrl,
|
|
10
10
|
EXTENSION_VERSION
|
|
11
11
|
} from "@vtstech/pi-shared/ollama";
|
|
12
|
+
import { mergeModels } from "@vtstech/pi-shared/provider-sync";
|
|
13
|
+
import { getEffectiveConfig } from "@vtstech/pi-shared/model-test-utils";
|
|
12
14
|
import { section, ok, warn, info, bytesHuman, estimateMemory } from "@vtstech/pi-shared/format";
|
|
13
15
|
var BRANDING = [
|
|
14
16
|
` \u26A1 Pi Ollama Sync v${EXTENSION_VERSION}`,
|
|
@@ -41,24 +43,15 @@ function buildModelEntry(m, contextLength) {
|
|
|
41
43
|
estimatedSize
|
|
42
44
|
};
|
|
43
45
|
}
|
|
44
|
-
function mergeModels(newModels, oldModels) {
|
|
45
|
-
const oldModelMap = new Map(oldModels.map((m) => [m.id, m]));
|
|
46
|
-
return newModels.map((m) => {
|
|
47
|
-
const old = oldModelMap.get(m.id);
|
|
48
|
-
if (old) {
|
|
49
|
-
const merged = { ...m };
|
|
50
|
-
for (const [k, v] of Object.entries(old)) {
|
|
51
|
-
if (!(k in m)) merged[k] = v;
|
|
52
|
-
}
|
|
53
|
-
return merged;
|
|
54
|
-
}
|
|
55
|
-
return m;
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
46
|
async function performSync(overrideUrl) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
47
|
+
let ollamaBaseUrl;
|
|
48
|
+
if (overrideUrl) {
|
|
49
|
+
ollamaBaseUrl = overrideUrl.replace(/\/v1$/, "").replace(/\/+$/, "");
|
|
50
|
+
} else {
|
|
51
|
+
const preview = readModelsJson();
|
|
52
|
+
const config = getProviderConfig(preview);
|
|
53
|
+
ollamaBaseUrl = config.baseUrl?.replace(/\/v1$/, "") ?? getOllamaBaseUrl();
|
|
54
|
+
}
|
|
62
55
|
try {
|
|
63
56
|
const models = await fetchOllamaModels(ollamaBaseUrl);
|
|
64
57
|
if (models.length === 0) {
|
|
@@ -71,28 +64,35 @@ async function performSync(overrideUrl) {
|
|
|
71
64
|
};
|
|
72
65
|
}
|
|
73
66
|
const sorted = [...models].sort((a, b) => a.size - b.size);
|
|
67
|
+
const testConfig = getEffectiveConfig();
|
|
74
68
|
const contextMap = await fetchContextLengthsBatched(
|
|
75
69
|
ollamaBaseUrl,
|
|
76
|
-
sorted.map((m) => m.name)
|
|
70
|
+
sorted.map((m) => m.name),
|
|
71
|
+
testConfig.CONTEXT_BATCH_SIZE
|
|
77
72
|
);
|
|
78
73
|
const newModels = sorted.map(
|
|
79
74
|
(m) => buildModelEntry(m, contextMap.get(m.name))
|
|
80
75
|
);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
76
|
+
let added = [];
|
|
77
|
+
let removed = [];
|
|
78
|
+
await readModifyWriteModelsJson((existing) => {
|
|
79
|
+
const config = getProviderConfig(existing);
|
|
80
|
+
const oldIds = new Set(
|
|
81
|
+
existing.providers["ollama"]?.models?.map((m) => m.id) ?? []
|
|
82
|
+
);
|
|
83
|
+
added = newModels.filter((m) => !oldIds.has(m.id));
|
|
84
|
+
removed = [...oldIds].filter((id) => !newModels.some((m) => m.id === id));
|
|
85
|
+
const mergedModels = mergeModels(
|
|
86
|
+
newModels,
|
|
87
|
+
existing.providers["ollama"]?.models ?? []
|
|
88
|
+
);
|
|
89
|
+
existing.providers["ollama"] = {
|
|
90
|
+
...config,
|
|
91
|
+
baseUrl: ollamaBaseUrl + "/v1",
|
|
92
|
+
models: mergedModels
|
|
93
|
+
};
|
|
94
|
+
return existing;
|
|
95
|
+
});
|
|
96
96
|
return {
|
|
97
97
|
ollamaBaseUrl,
|
|
98
98
|
newModels,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtstech/pi-ollama-sync",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"description": "Ollama model sync extension for Pi Coding Agent",
|
|
5
5
|
"main": "ollama-sync.js",
|
|
6
6
|
"keywords": ["pi-extensions"],
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"url": "https://github.com/VTSTech/pi-coding-agent"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@vtstech/pi-shared": "1.1.
|
|
17
|
+
"@vtstech/pi-shared": "1.1.9"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"@mariozechner/pi-coding-agent": ">=0.66"
|