@vtstech/pi-status 1.0.5 → 1.0.6

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/status.js +45 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtstech/pi-status",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "System monitor / status bar extension for Pi Coding Agent",
5
5
  "main": "status.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.0.5"
17
+ "@vtstech/pi-shared": "1.0.6"
18
18
  },
19
19
  "peerDependencies": {
20
20
  "@mariozechner/pi-coding-agent": ">=0.66"
package/status.js CHANGED
@@ -26,6 +26,7 @@ function status_temp_default(pi) {
26
26
  let footerModel = "";
27
27
  let footerThinking = "";
28
28
  let footerCtxPct = "";
29
+ let isLocalProvider = true;
29
30
  let securityFlashTool = "";
30
31
  let securityFlashUntil = 0;
31
32
  let activeTool = "";
@@ -75,6 +76,26 @@ function status_temp_default(pi) {
75
76
  let ollamaLoadedCache = "";
76
77
  let ollamaLoadedLastCheck = 0;
77
78
  const OLLAMA_LOADED_INTERVAL = 15e3;
79
+ function detectLocalProvider(modelsJson) {
80
+ try {
81
+ for (const provider of Object.values(modelsJson.providers || {})) {
82
+ const url = provider.baseUrl || "";
83
+ const hasLocalUrl = url.includes("localhost") || url.includes("127.0.0.1") || url.includes("0.0.0.0");
84
+ const modelId = footerModel || "";
85
+ if (modelId && (provider.models || []).some((m) => m.id === modelId)) {
86
+ return hasLocalUrl;
87
+ }
88
+ }
89
+ for (const [name, provider] of Object.entries(modelsJson.providers || {})) {
90
+ const url = provider.baseUrl || "";
91
+ if (url.includes("localhost") || url.includes("127.0.0.1") || url.includes("0.0.0.0") || name === "ollama") {
92
+ return true;
93
+ }
94
+ }
95
+ } catch {
96
+ }
97
+ return false;
98
+ }
78
99
  function getOllamaLoadedModel() {
79
100
  const now = Date.now();
80
101
  if (now - ollamaLoadedLastCheck < OLLAMA_LOADED_INTERVAL) return ollamaLoadedCache;
@@ -151,34 +172,37 @@ function status_temp_default(pi) {
151
172
  hasSwap = false;
152
173
  }
153
174
  ollamaLoaded = getOllamaLoadedModel();
175
+ let modelsJson = null;
176
+ try {
177
+ const raw = fs.readFileSync(
178
+ path.join(os.homedir(), ".pi", "agent", "models.json"),
179
+ "utf-8"
180
+ );
181
+ modelsJson = JSON.parse(raw);
182
+ } catch {
183
+ }
154
184
  if (currentCtx) {
155
185
  footerModel = currentCtx.model?.id || "";
156
186
  footerThinking = pi.getThinkingLevel?.() ?? "";
157
187
  const usage = currentCtx.getContextUsage?.();
158
188
  if (usage && usage.contextWindow > 0) {
159
- const pct = (usage.tokens / usage.contextWindow * 100).toFixed(1);
160
- footerCtxPct = `${pct}%/${(usage.contextWindow / 1e3).toFixed(0)}k`;
189
+ const pctVal = (usage.tokens / usage.contextWindow * 100).toFixed(1);
190
+ footerCtxPct = `${pctVal}%/${(usage.contextWindow / 1e3).toFixed(0)}k`;
161
191
  } else {
162
192
  footerCtxPct = "";
163
193
  }
164
194
  const modelId = currentCtx.model?.id || "";
165
- if (modelId && !footerCtxPct) {
166
- try {
167
- const modelsJson = JSON.parse(fs.readFileSync(
168
- path.join(os.homedir(), ".pi", "agent", "models.json"),
169
- "utf-8"
170
- ));
171
- for (const prov of Object.values(modelsJson.providers || {})) {
172
- const match = (prov.models || []).find((m) => m.id === modelId);
173
- if (match?.contextLength) {
174
- footerCtxPct = `${(match.contextLength / 1e3).toFixed(0)}k ctx`;
175
- break;
176
- }
195
+ if (modelId && !footerCtxPct && modelsJson) {
196
+ for (const prov of Object.values(modelsJson.providers || {})) {
197
+ const match = (prov.models || []).find((m) => m.id === modelId);
198
+ if (match?.contextLength) {
199
+ footerCtxPct = `${(match.contextLength / 1e3).toFixed(0)}k ctx`;
200
+ break;
177
201
  }
178
- } catch {
179
202
  }
180
203
  }
181
204
  }
205
+ isLocalProvider = modelsJson ? detectLocalProvider(modelsJson) : false;
182
206
  refreshBlockedCount();
183
207
  }
184
208
  pi.on("session_start", async (_event, ctx) => {
@@ -207,10 +231,12 @@ function status_temp_default(pi) {
207
231
  if (footerModel) parts.push(dim(footerModel));
208
232
  if (footerThinking && footerThinking !== "off") parts.push(dim(footerThinking));
209
233
  if (footerCtxPct) parts.push(footerCtxPct);
210
- parts.push(dim(`CPU ${cpuUsage.toFixed(0)}%`));
211
- parts.push(`RAM ${fmtBytes(memUsed)}/${fmtBytes(memTotal)}`);
212
- if (hasSwap && swapUsed > 0) {
213
- parts.push(`Swap ${fmtBytes(swapUsed)}/${fmtBytes(swapTotal)}`);
234
+ if (isLocalProvider) {
235
+ parts.push(dim(`CPU ${cpuUsage.toFixed(0)}%`));
236
+ parts.push(`RAM ${fmtBytes(memUsed)}/${fmtBytes(memTotal)}`);
237
+ if (hasSwap && swapUsed > 0) {
238
+ parts.push(`Swap ${fmtBytes(swapUsed)}/${fmtBytes(swapTotal)}`);
239
+ }
214
240
  }
215
241
  if (ollamaLoaded) parts.push(`${ollamaLoaded}`);
216
242
  if (lastResponseTime !== null) parts.push(`Resp ${fmtDur(lastResponseTime)}`);