@myvillage/cli 1.80.1 → 1.81.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myvillage/cli",
3
- "version": "1.80.1",
3
+ "version": "1.81.0",
4
4
  "description": "MyVillageOS CLI for community developers",
5
5
  "type": "module",
6
6
  "bin": {
@@ -79,6 +79,14 @@ export async function agentLoop(agentName, { signal }) {
79
79
  // The model client is built once, but OAuth tokens rotate (~1h). A static
80
80
  // bearer would 401 on every gateway call after expiry for long-lived agents,
81
81
  // so inject the current token per request — refreshing first if it expired.
82
+ // Tell the gateway which agent is spending MVTs, so the server can attribute the
83
+ // MVT transaction (e.g. "AI chat · Vee 1.3 · agent: research-bot"). Header values
84
+ // must be safe ASCII — undici rejects CR/LF and non-latin1 — so strip aggressively.
85
+ const agentHeader = String(config.display_name || agentName || '')
86
+ .replace(/[^\x20-\x7e]+/g, ' ')
87
+ .replace(/\s+/g, ' ')
88
+ .trim()
89
+ .slice(0, 64);
82
90
  const gatewayFetch = async (url, init = {}) => {
83
91
  if (isTokenExpired()) {
84
92
  try { await refreshAccessToken(); } catch { /* fall through with the existing token */ }
@@ -86,6 +94,7 @@ export async function agentLoop(agentName, { signal }) {
86
94
  const current = getAccessToken();
87
95
  const headers = new Headers(init.headers);
88
96
  if (current) headers.set('authorization', `Bearer ${current}`);
97
+ if (agentHeader) headers.set('x-myvillage-agent', agentHeader);
89
98
  return fetch(url, { ...init, headers });
90
99
  };
91
100
  const openai = createOpenAI({ apiKey: token, baseURL: `${apiBaseUrl}/ai`, fetch: gatewayFetch });