osborn 0.9.268 → 0.9.269

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.
@@ -177,7 +177,33 @@ export function applyAuthFallback() {
177
177
  if (process.env.ANTHROPIC_API_KEY && process.env.ANTHROPIC_API_KEY.trim() !== '') {
178
178
  return;
179
179
  }
180
- // Tier 3: central OpenRouter key.
180
+ // Tier 3: HOUSE DEMO PASS - z.ai GLM coding subscription (flat/shared, not
181
+ // pay-per-use). Cline/opencode-style: unauthenticated demo users ride the
182
+ // house pass instead of raw API billing. The z.ai Anthropic-compatible
183
+ // endpoint (api.z.ai/api/anthropic) speaks native Messages - verified live
184
+ // 2026-10-24 (glm-4.7 returned a real response). Precedence: Z_AI_PERSONAL_API_KEY
185
+ // (verified working; ZAI_STANDARD_API_KEY in .env is expired).
186
+ const zaiKey = process.env.Z_AI_PERSONAL_API_KEY || process.env.ZAI_API_KEY;
187
+ if (zaiKey && zaiKey.trim() !== '') {
188
+ // Native Anthropic-Messages endpoint - no local translation proxy needed.
189
+ process.env.ANTHROPIC_BASE_URL = process.env.OSBORN_DEMO_BASE_URL || 'https://api.z.ai/api/anthropic';
190
+ process.env.ANTHROPIC_AUTH_TOKEN = zaiKey;
191
+ process.env.ANTHROPIC_API_KEY = ''; // required - a set key bypasses AUTH_TOKEN
192
+ const demoModel = process.env.OSBORN_DEMO_MODEL || 'glm-4.7';
193
+ process.env.ANTHROPIC_MODEL = demoModel;
194
+ process.env.ANTHROPIC_SMALL_FAST_MODEL = demoModel;
195
+ process.env.CLAUDE_CODE_SUBAGENT_MODEL = demoModel;
196
+ process.env.CLAUDE_CODE_SUBAGENT_MODEL_FORCE = demoModel;
197
+ // GLM-4.7 exposes a 200K window; pins the CLI's context-cap handling.
198
+ process.env.CLAUDE_CODE_MAX_CONTEXT_TOKENS = process.env.OSBORN_DEMO_MAX_CONTEXT || '200000';
199
+ // Signal for the fast brain (pipeline-fastbrain reads this per call) so the
200
+ // WHOLE model layer - main agent AND fast brain - rides the same pass.
201
+ process.env.OSBORN_DEMO_PASS = 'zai';
202
+ fallbackTierActive = true;
203
+ console.log(`[auth-fallback] using house demo pass (z.ai), model=${demoModel}`);
204
+ return;
205
+ }
206
+ // Tier 4: central OpenRouter key (pay-per-use fallback of the fallback).
181
207
  const openRouterKey = process.env.OPENROUTER_API_KEY;
182
208
  if (openRouterKey && openRouterKey.trim() !== '') {
183
209
  // Native Anthropic-Messages endpoint — no local translation proxy needed.
@@ -207,8 +233,8 @@ export function applyAuthFallback() {
207
233
  console.log(`[auth-fallback] using central OpenRouter tier, model=${FALLBACK_MODEL}`);
208
234
  return;
209
235
  }
210
- // Tier 3 fail: no OpenRouter key — do NOT throw.
211
- console.warn('[auth-fallback] no Claude login, no ANTHROPIC_API_KEY, and no OPENROUTER_API_KEY — agent may be unauthenticated');
236
+ // Tier 4 fail: no fallback key at all — do NOT throw.
237
+ console.warn('[auth-fallback] no Claude login, no ANTHROPIC_API_KEY, no Z_AI key, and no OPENROUTER_API_KEY — agent may be unauthenticated');
212
238
  }
213
239
  /**
214
240
  * Clear the OpenRouter fallback redirect — but ONLY if applyAuthFallback() set
@@ -229,8 +255,11 @@ function clearAuthFallbackIfActive() {
229
255
  // must be unset so the per-agent sonnet/opus fields take effect again.
230
256
  delete process.env.CLAUDE_CODE_SUBAGENT_MODEL;
231
257
  delete process.env.CLAUDE_CODE_SUBAGENT_MODEL_FORCE;
258
+ // Demo-pass signal - without this a post-login fast brain would keep routing
259
+ // to the house z.ai pass instead of the user's own pay-per-use providers.
260
+ delete process.env.OSBORN_DEMO_PASS;
232
261
  fallbackTierActive = false;
233
- console.log('[auth-fallback] real Claude login completed — cleared OpenRouter redirect');
262
+ console.log('[auth-fallback] real Claude login completed — cleared fallback redirect');
234
263
  }
235
264
  /**
236
265
  * Check auth via `claude auth status` (most reliable).
@@ -32,6 +32,27 @@ const OPENROUTER_URL = FIREWORKS
32
32
  : 'https://openrouter.ai/api/v1/chat/completions';
33
33
  const TIMEOUT_MS = 20_000;
34
34
  const MAX_TOOL_ROUNDS = 4;
35
+ /**
36
+ * Per-call provider resolution for the HOUSE DEMO PASS. When the user has no
37
+ * Claude auth, applyAuthFallback() sets OSBORN_DEMO_PASS='zai' - the whole
38
+ * model layer (main agent AND this fast brain) then rides the shared z.ai GLM
39
+ * subscription instead of pay-per-use Fireworks/OpenRouter. Checked per call
40
+ * (not module-load) because applyAuthFallback runs after this module loads, and
41
+ * because a mid-session real-Claude login clears the flag via clearAuthFallback.
42
+ * Returns null on the normal (user pays their own providers) path.
43
+ */
44
+ function resolveFastBrainProvider() {
45
+ if (process.env.OSBORN_DEMO_PASS !== 'zai')
46
+ return null;
47
+ const zaiKey = process.env.Z_AI_PERSONAL_API_KEY || process.env.ZAI_API_KEY;
48
+ if (!zaiKey)
49
+ return null;
50
+ return {
51
+ url: 'https://api.z.ai/api/paas/v4/chat/completions',
52
+ model: process.env.OSBORN_DEMO_FAST_MODEL || 'glm-4.5-air', // fast/cheap tier of the pass
53
+ name: 'z.ai (demo pass)',
54
+ };
55
+ }
35
56
  // ============================================================
36
57
  // PERSISTENT STATE (OpenAI message format)
37
58
  // ============================================================
@@ -314,7 +335,12 @@ function buildSystemPrompt(chatHistory, researchContext) {
314
335
  // OPENROUTER CALL
315
336
  // ============================================================
316
337
  async function callOpenRouter(messages, tools, apiKey) {
317
- const resp = await fetch(OPENROUTER_URL, {
338
+ // Demo pass first — same OpenAI-compatible tool-loop contract, house z.ai key.
339
+ const demo = resolveFastBrainProvider();
340
+ const url = demo?.url || OPENROUTER_URL;
341
+ const model = demo?.model || OPENROUTER_MODEL;
342
+ const providerName = demo?.name || PROVIDER_NAME;
343
+ const resp = await fetch(url, {
318
344
  method: 'POST',
319
345
  headers: {
320
346
  'Authorization': `Bearer ${apiKey}`,
@@ -322,7 +348,7 @@ async function callOpenRouter(messages, tools, apiKey) {
322
348
  'X-OpenRouter-Title': 'Osborn Fast Brain',
323
349
  },
324
350
  body: JSON.stringify({
325
- model: OPENROUTER_MODEL,
351
+ model,
326
352
  messages,
327
353
  tools,
328
354
  tool_choice: 'auto',
@@ -331,7 +357,7 @@ async function callOpenRouter(messages, tools, apiKey) {
331
357
  });
332
358
  if (!resp.ok) {
333
359
  const body = await resp.text().catch(() => '');
334
- throw new Error(`${PROVIDER_NAME} ${resp.status}: ${body.substring(0, 200)}`);
360
+ throw new Error(`${providerName} ${resp.status}: ${body.substring(0, 200)}`);
335
361
  }
336
362
  return resp.json();
337
363
  }
@@ -369,7 +395,11 @@ export async function askPipelineFastBrain(workingDir, sessionId, question, opts
369
395
  if (!sessionId || sessionId === 'pending') {
370
396
  return { script: 'Session is still initializing.', type: 'acknowledgment', toolsUsed: [] };
371
397
  }
372
- const apiKey = process.env.FIREWORKS_API_KEY || process.env.OPENROUTER_API_KEY;
398
+ // Demo pass (house z.ai key) takes precedence when active; else the user's own
399
+ // pay-per-use providers (Fireworks preferred, OpenRouter fallback).
400
+ const apiKey = resolveFastBrainProvider()
401
+ ? (process.env.Z_AI_PERSONAL_API_KEY || process.env.ZAI_API_KEY)
402
+ : (process.env.FIREWORKS_API_KEY || process.env.OPENROUTER_API_KEY);
373
403
  if (!apiKey) {
374
404
  return { script: 'Search system not available right now.', type: 'acknowledgment', toolsUsed: [] };
375
405
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "osborn",
3
- "version": "0.9.268",
3
+ "version": "0.9.269",
4
4
  "description": "Voice AI coding assistant - local agent that connects to Osborn frontend",
5
5
  "type": "module",
6
6
  "bin": {