pi-ollama-cloud 0.2.0 → 0.2.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.
- package/CHANGELOG.md +4 -0
- package/models.ts +18 -20
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.2.1] - 2026-04-29
|
|
6
|
+
|
|
7
|
+
- Fix API key retrieval by using `AuthStorage` instead of `ctx.modelRegistry.getApiKeyForProvider`. The provider-level API key lookup was failing, causing auth to only work when an environment variable was set. Now reads from `auth.json` directly via the pi `AuthStorage` class.
|
|
8
|
+
|
|
5
9
|
## [0.2.0] - 2026-04-28
|
|
6
10
|
|
|
7
11
|
- Add `PI_OLLAMA_WEB_TOOLS` environment variable to optionally disable `ollama_web_search` and `ollama_web_fetch` tool registrations. Set to `0`, `false`, `no`, `off`, or an empty string to opt-out. The model provider and `/ollama-cloud-refresh` command remain active regardless.
|
package/models.ts
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { type ExtensionCommandContext, getAgentDir, type ProviderModelConfig } from "@mariozechner/pi-coding-agent";
|
|
4
|
+
import { AuthStorage } from "@mariozechner/pi-coding-agent";
|
|
4
5
|
|
|
5
6
|
// --- Constants ---
|
|
6
|
-
|
|
7
7
|
const CACHE_DIR = join(getAgentDir(), "cache");
|
|
8
8
|
const CACHE_FILE = join(CACHE_DIR, "ollama-cloud-models.json");
|
|
9
9
|
const FETCH_TIMEOUT_MS = 10000;
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* Defaults to "https://ollama.com"; override with OLLAMA_API_BASE to point at a proxy or self-hosted instance.
|
|
14
|
-
*/
|
|
15
|
-
export const OLLAMA_BASE = (process.env.OLLAMA_API_BASE || "https://ollama.com").replace(/\/+$/, "");
|
|
11
|
+
// --- API fetch ---
|
|
12
|
+
export let OLLAMA_BASE = (process.env.OLLAMA_API_BASE || "https://ollama.com").replace(/\/+$/, "");
|
|
16
13
|
|
|
17
|
-
//
|
|
14
|
+
// Initialize AuthStorage
|
|
15
|
+
const authStorage = AuthStorage.create();
|
|
18
16
|
|
|
17
|
+
// --- Raw API types ---
|
|
19
18
|
/** Response from POST /api/show */
|
|
20
19
|
export interface OllamaShowResponse {
|
|
21
20
|
details: {
|
|
@@ -38,7 +37,6 @@ interface CachedData {
|
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
// --- Assembly: raw API data -> ProviderModelConfig[] ---
|
|
41
|
-
|
|
42
40
|
function getContextLength(modelInfo: Record<string, unknown>): number {
|
|
43
41
|
for (const [key, value] of Object.entries(modelInfo)) {
|
|
44
42
|
if (key.endsWith(".context_length") && typeof value === "number") {
|
|
@@ -63,7 +61,6 @@ export function assembleModels(raw: Record<string, OllamaShowResponse>): Provide
|
|
|
63
61
|
}
|
|
64
62
|
|
|
65
63
|
// --- Fallback models (cold cache) ---
|
|
66
|
-
|
|
67
64
|
export const FALLBACK_MODELS: ProviderModelConfig[] = [
|
|
68
65
|
{
|
|
69
66
|
id: "glm-5.1:cloud",
|
|
@@ -86,7 +83,6 @@ export const FALLBACK_MODELS: ProviderModelConfig[] = [
|
|
|
86
83
|
];
|
|
87
84
|
|
|
88
85
|
// --- Cache I/O ---
|
|
89
|
-
|
|
90
86
|
export function readCache(): Record<string, OllamaShowResponse> | null {
|
|
91
87
|
try {
|
|
92
88
|
if (!existsSync(CACHE_FILE)) return null;
|
|
@@ -107,17 +103,19 @@ export function writeCache(models: Record<string, OllamaShowResponse>): void {
|
|
|
107
103
|
}
|
|
108
104
|
}
|
|
109
105
|
|
|
110
|
-
// ---
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Fetch the full model catalog from Ollama Cloud.
|
|
114
|
-
* Returns null on fatal errors (missing API key, list fetch failed, no models fetched);
|
|
115
|
-
* the caller can rely on fetchModels having already shown a user-facing error.
|
|
116
|
-
*/
|
|
106
|
+
// --- Fetch Models ---
|
|
117
107
|
export async function fetchModels(ctx: ExtensionCommandContext): Promise<Record<string, OllamaShowResponse> | null> {
|
|
118
|
-
const apiKey = await
|
|
108
|
+
const apiKey = await authStorage.getApiKey("ollama-cloud");
|
|
109
|
+
|
|
119
110
|
if (!apiKey) {
|
|
120
|
-
ctx.ui.notify(
|
|
111
|
+
ctx.ui.notify(
|
|
112
|
+
"No Ollama Cloud API key found. \n" +
|
|
113
|
+
"Please ensure your API key is set in: \n" +
|
|
114
|
+
"- auth.json file (at ~/.pi/agent/auth.json) under 'ollama-cloud' key,\n" +
|
|
115
|
+
"- or via the CLI --api-key flag.\n" +
|
|
116
|
+
"Example auth.json entry: \n" +
|
|
117
|
+
'{ \"ollama-cloud\": { \"type\": \"api_key\", \"key\": \"YOUR_API_KEY\" } }'
|
|
118
|
+
, "error");
|
|
121
119
|
return null;
|
|
122
120
|
}
|
|
123
121
|
|
|
@@ -178,4 +176,4 @@ export async function fetchModels(ctx: ExtensionCommandContext): Promise<Record<
|
|
|
178
176
|
ctx.ui.notify(`Fetched ${succeeded} model details${failed ? ` (${failed} failed)` : ""}`, "info");
|
|
179
177
|
|
|
180
178
|
return results;
|
|
181
|
-
}
|
|
179
|
+
}
|