@vtstech/pi-status 1.0.5 → 1.0.7

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 +43 -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.7",
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.7"
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,24 @@ 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
+ const isLocalUrl = (url) => url.includes("localhost") || url.includes("127.0.0.1") || url.includes("0.0.0.0");
81
+ try {
82
+ const ctxUrl = currentCtx?.provider?.baseUrl || currentCtx?.provider?.url || "";
83
+ if (ctxUrl) return isLocalUrl(ctxUrl);
84
+ const modelId = footerModel || "";
85
+ if (modelsJson && modelId) {
86
+ for (const provider of Object.values(modelsJson.providers || {})) {
87
+ const url = provider.baseUrl || "";
88
+ if ((provider.models || []).some((m) => m.id === modelId)) {
89
+ return isLocalUrl(url);
90
+ }
91
+ }
92
+ }
93
+ } catch {
94
+ }
95
+ return false;
96
+ }
78
97
  function getOllamaLoadedModel() {
79
98
  const now = Date.now();
80
99
  if (now - ollamaLoadedLastCheck < OLLAMA_LOADED_INTERVAL) return ollamaLoadedCache;
@@ -151,34 +170,37 @@ function status_temp_default(pi) {
151
170
  hasSwap = false;
152
171
  }
153
172
  ollamaLoaded = getOllamaLoadedModel();
173
+ let modelsJson = null;
174
+ try {
175
+ const raw = fs.readFileSync(
176
+ path.join(os.homedir(), ".pi", "agent", "models.json"),
177
+ "utf-8"
178
+ );
179
+ modelsJson = JSON.parse(raw);
180
+ } catch {
181
+ }
154
182
  if (currentCtx) {
155
183
  footerModel = currentCtx.model?.id || "";
156
184
  footerThinking = pi.getThinkingLevel?.() ?? "";
157
185
  const usage = currentCtx.getContextUsage?.();
158
186
  if (usage && usage.contextWindow > 0) {
159
- const pct = (usage.tokens / usage.contextWindow * 100).toFixed(1);
160
- footerCtxPct = `${pct}%/${(usage.contextWindow / 1e3).toFixed(0)}k`;
187
+ const pctVal = (usage.tokens / usage.contextWindow * 100).toFixed(1);
188
+ footerCtxPct = `${pctVal}%/${(usage.contextWindow / 1e3).toFixed(0)}k`;
161
189
  } else {
162
190
  footerCtxPct = "";
163
191
  }
164
192
  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
- }
193
+ if (modelId && !footerCtxPct && modelsJson) {
194
+ for (const prov of Object.values(modelsJson.providers || {})) {
195
+ const match = (prov.models || []).find((m) => m.id === modelId);
196
+ if (match?.contextLength) {
197
+ footerCtxPct = `${(match.contextLength / 1e3).toFixed(0)}k ctx`;
198
+ break;
177
199
  }
178
- } catch {
179
200
  }
180
201
  }
181
202
  }
203
+ isLocalProvider = modelsJson ? detectLocalProvider(modelsJson) : false;
182
204
  refreshBlockedCount();
183
205
  }
184
206
  pi.on("session_start", async (_event, ctx) => {
@@ -207,10 +229,12 @@ function status_temp_default(pi) {
207
229
  if (footerModel) parts.push(dim(footerModel));
208
230
  if (footerThinking && footerThinking !== "off") parts.push(dim(footerThinking));
209
231
  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)}`);
232
+ if (isLocalProvider) {
233
+ parts.push(dim(`CPU ${cpuUsage.toFixed(0)}%`));
234
+ parts.push(`RAM ${fmtBytes(memUsed)}/${fmtBytes(memTotal)}`);
235
+ if (hasSwap && swapUsed > 0) {
236
+ parts.push(`Swap ${fmtBytes(swapUsed)}/${fmtBytes(swapTotal)}`);
237
+ }
214
238
  }
215
239
  if (ollamaLoaded) parts.push(`${ollamaLoaded}`);
216
240
  if (lastResponseTime !== null) parts.push(`Resp ${fmtDur(lastResponseTime)}`);