u-foo 3.1.7 → 4.0.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.
Files changed (193) hide show
  1. package/README.md +172 -13
  2. package/README.zh-CN.md +108 -13
  3. package/SKILLS/ufoo/SKILL.md +15 -3
  4. package/SKILLS/ufoo-bus/SKILL.md +21 -1
  5. package/bin/uclaude.js +4 -0
  6. package/bin/ucodex.js +4 -0
  7. package/bin/ufoo.js +3 -1
  8. package/dist/tui/darwin-arm64/ufoo-tui +0 -0
  9. package/dist/tui/darwin-x64/ufoo-tui +0 -0
  10. package/dist/tui/linux-arm64/ufoo-tui +0 -0
  11. package/dist/tui/linux-x64/ufoo-tui +0 -0
  12. package/package.json +10 -3
  13. package/scripts/postinstall-skills.js +53 -0
  14. package/scripts/postinstall.js +11 -16
  15. package/scripts/smoke-native-messages.js +214 -0
  16. package/src/agents/activity/activityStateWriter.js +37 -38
  17. package/src/agents/capabilities/agentManagement/index.js +4 -0
  18. package/src/agents/capabilities/agentManagement/service.js +113 -0
  19. package/src/agents/capabilities/agentRouting/index.js +4 -0
  20. package/src/agents/capabilities/coding/index.js +32 -0
  21. package/src/agents/capabilities/coordination/index.js +37 -0
  22. package/src/agents/capabilities/globalRouting/index.js +5 -0
  23. package/src/agents/capabilities/groups/index.js +3 -0
  24. package/src/agents/capabilities/index.js +25 -0
  25. package/src/agents/capabilities/planning/index.js +123 -0
  26. package/src/agents/capabilities/planning/main.js +28 -0
  27. package/src/agents/capabilities/projectDiscovery/index.js +3 -0
  28. package/src/agents/capabilities/scheduling/index.js +3 -0
  29. package/src/agents/capabilities/sharedMemory/index.js +4 -0
  30. package/src/agents/capabilities/skills/index.js +12 -0
  31. package/src/agents/capabilities/taskExecution/index.js +3 -0
  32. package/src/agents/capabilities/taskReports/index.js +6 -0
  33. package/src/agents/controller/controllerToolExecutor.js +6 -4
  34. package/src/agents/controller/loopRuntime.js +85 -221
  35. package/src/agents/controller/ufooAgent.js +1 -0
  36. package/src/agents/internal/internalRunner.js +103 -32
  37. package/src/agents/launch/launcher.js +88 -6
  38. package/src/agents/launch/nativeCapabilities.js +40 -0
  39. package/src/agents/launch/nativeMessages.js +362 -0
  40. package/src/agents/launch/notifier.js +13 -18
  41. package/src/agents/launch/readyDetector.js +26 -12
  42. package/src/agents/profiles/coding.js +6 -0
  43. package/src/agents/profiles/globalRouter.js +2 -0
  44. package/src/agents/profiles/main.js +5 -0
  45. package/src/agents/prompts/groupBootstrap.js +10 -0
  46. package/src/agents/prompts/mainAgent.js +39 -0
  47. package/src/agents/prompts/native/tasks.js +2 -2
  48. package/src/agents/prompts/native/ufoo.js +3 -0
  49. package/src/agents/providers/claudeEventTranslator.js +6 -1
  50. package/src/agents/providers/claudeThreadProvider.js +44 -2
  51. package/src/agents/providers/codexEventTranslator.js +47 -7
  52. package/src/agents/providers/codexThreadProvider.js +3 -2
  53. package/src/agents/providers/controllerJsonTransport.js +28 -0
  54. package/src/agents/providers/credentials/claude.js +10 -3
  55. package/src/agents/providers/nativeTransport.js +1135 -0
  56. package/src/agents/providers/runtimeConfig.js +186 -0
  57. package/src/agents/providers/thinkingLevels.js +132 -0
  58. package/src/agents/providers/transports/anthropicMessagesTransport.js +121 -0
  59. package/src/agents/providers/transports/index.js +10 -0
  60. package/src/agents/providers/transports/openaiChatTransport.js +117 -0
  61. package/src/agents/providers/transports/openaiResponsesTransport.js +120 -0
  62. package/src/agents/providers/transports/responsesProtocol.js +499 -0
  63. package/src/agents/providers/transports/systemBlocks.js +16 -0
  64. package/src/agents/providers/transports/transportContract.js +50 -0
  65. package/src/agents/providers/transports/visionBlocks.js +151 -0
  66. package/src/agents/providers/upstreamTransport.js +13 -4
  67. package/src/agents/runtime/composeCapabilities.js +89 -0
  68. package/src/agents/runtime/context/commandStore.js +43 -0
  69. package/src/agents/runtime/context/contextWindow.js +119 -0
  70. package/src/agents/runtime/context/fileLock.js +36 -0
  71. package/src/agents/runtime/context/runtimeStore.js +126 -0
  72. package/src/agents/runtime/context/sessionJournal.js +360 -0
  73. package/src/agents/runtime/context/sessionStore.js +57 -0
  74. package/src/agents/runtime/core/agentLoop.js +270 -0
  75. package/src/agents/runtime/core/stableJson.js +29 -0
  76. package/src/agents/runtime/core/toolLoopGuard.js +55 -0
  77. package/src/agents/runtime/createAgentRuntime.js +247 -0
  78. package/src/agents/runtime/index.js +14 -0
  79. package/src/agents/runtime/protocol/faultHarness.js +90 -0
  80. package/src/agents/runtime/protocol/materialize.js +107 -0
  81. package/src/agents/runtime/protocol/toolCallLedger.js +221 -0
  82. package/src/agents/runtime/tasks/resourceLease.js +66 -0
  83. package/src/agents/runtime/tasks/scheduler.js +73 -0
  84. package/src/agents/runtime/tools/registry.js +57 -0
  85. package/src/app/chat/ChatController.js +14 -3
  86. package/src/app/chat/agentDirectory.js +8 -2
  87. package/src/app/chat/commandExecutor.js +36 -46
  88. package/src/app/chat/commands.js +14 -7
  89. package/src/app/chat/daemonConnection.js +58 -5
  90. package/src/app/chat/daemonMessageRouter.js +61 -3
  91. package/src/app/chat/inputSubmitHandler.js +14 -2
  92. package/src/app/chat/launchRequestContext.js +42 -0
  93. package/src/app/chat/multiWindow/paneManager.js +85 -165
  94. package/src/app/chat/streamState.js +3 -3
  95. package/src/app/chat/transport.js +1 -1
  96. package/src/app/cli/busCoreCommands.js +9 -0
  97. package/src/app/cli/features/doctor.js +33 -0
  98. package/src/app/cli/features/skills.js +16 -4
  99. package/src/app/cli/reportCoreCommands.js +37 -0
  100. package/src/app/cli/run.js +40 -39
  101. package/src/code/agent.js +16 -4
  102. package/src/code/context/artifacts.js +12 -11
  103. package/src/code/context/assembler.js +2 -1
  104. package/src/code/context/promptLayers.js +1 -13
  105. package/src/code/context/stableJson.js +2 -27
  106. package/src/code/contextWindow.js +2 -117
  107. package/src/code/conversation/sessionJournal.js +3 -349
  108. package/src/code/internalThread.js +100 -0
  109. package/src/code/nativeRunner.js +36 -2667
  110. package/src/code/protocol/faultHarness.js +2 -88
  111. package/src/code/protocol/materialize.js +2 -105
  112. package/src/code/protocol/toolCallLedger.js +5 -215
  113. package/src/code/providers/anthropicMessagesTransport.js +2 -118
  114. package/src/code/providers/openaiChatTransport.js +2 -114
  115. package/src/code/providers/openaiResponsesTransport.js +2 -117
  116. package/src/code/providers/responsesProtocol.js +2 -497
  117. package/src/code/providers/transportContract.js +2 -48
  118. package/src/code/providers/visionBlocks.js +2 -149
  119. package/src/code/sessionStore.js +24 -96
  120. package/src/code/thinkingLevels.js +1 -130
  121. package/src/code/toolLoopGuard.js +3 -49
  122. package/src/code/tools/artifactRead.js +1 -1
  123. package/src/code/tools/executor.js +373 -0
  124. package/src/code/tools/specs.js +312 -0
  125. package/src/config.js +81 -67
  126. package/src/coordination/bus/deliveryQueue.js +16 -2
  127. package/src/coordination/bus/index.js +2 -6
  128. package/src/coordination/bus/inject.js +13 -5
  129. package/src/coordination/bus/nativeReceipts.js +100 -0
  130. package/src/coordination/bus/queue.js +1 -3
  131. package/src/coordination/bus/utils.js +7 -3
  132. package/src/coordination/history/agentSurface.js +142 -0
  133. package/src/coordination/history/controllerSummary.js +23 -0
  134. package/src/coordination/memory/index.js +5 -21
  135. package/src/coordination/report/store.js +103 -83
  136. package/src/coordination/state/agentsStore.js +57 -3
  137. package/src/coordination/state/fileLock.js +2 -0
  138. package/src/coordination/state/workspaceAccess.js +36 -0
  139. package/src/runtime/contracts/agentMode.js +17 -0
  140. package/src/runtime/contracts/eventContract.js +3 -0
  141. package/src/runtime/contracts/uiProtocol.js +4 -0
  142. package/src/runtime/daemon/agentHost.js +375 -0
  143. package/src/runtime/daemon/busBridge.js +396 -0
  144. package/src/runtime/daemon/claudeChannel.js +159 -0
  145. package/src/runtime/daemon/controlPlaneService.js +27 -17
  146. package/src/runtime/daemon/cronOps.js +25 -17
  147. package/src/runtime/daemon/deliveryScheduler.js +32 -5
  148. package/src/runtime/daemon/executionPaths.js +30 -0
  149. package/src/runtime/daemon/globalDaemon.js +28 -1
  150. package/src/runtime/daemon/groupOrchestrator.js +1 -0
  151. package/src/runtime/daemon/index.js +114 -344
  152. package/src/runtime/daemon/ipcServer.js +32 -10
  153. package/src/runtime/daemon/mcpConfigure.js +113 -20
  154. package/src/runtime/daemon/mcpHttpServer.js +27 -5
  155. package/src/runtime/daemon/mcpServer.js +7 -4
  156. package/src/runtime/daemon/mcpStdioProxy.js +127 -10
  157. package/src/runtime/daemon/ops.js +22 -17
  158. package/src/runtime/daemon/promptRequest.js +23 -4
  159. package/src/runtime/daemon/providerSessions.js +67 -33
  160. package/src/runtime/daemon/reportControlBus.js +59 -25
  161. package/src/runtime/daemon/status.js +4 -0
  162. package/src/runtime/privacy/redactor.js +2 -2
  163. package/src/runtime/projects/identity.js +2 -1
  164. package/src/runtime/projects/registry.js +98 -38
  165. package/src/tools/controllerSchemas.js +24 -0
  166. package/src/tools/handlers/dispatchMessage.js +5 -2
  167. package/src/tools/handlers/listAgents.js +3 -1
  168. package/src/tools/handlers/readBusSummary.js +3 -1
  169. package/src/tools/handlers/readProjectRegistry.js +29 -2
  170. package/src/tools/handlers/routeAgent.js +35 -0
  171. package/src/tools/index.js +1 -0
  172. package/src/tools/registry.js +2 -0
  173. package/src/tools/schemaFixtures.js +16 -3
  174. package/src/tools/tier1/routeAgent.js +2 -2
  175. package/src/tools/tier2/runtimeCoordination.js +38 -0
  176. package/src/tools/types.js +2 -0
  177. package/src/ui/agentPresentation.js +109 -0
  178. package/src/ui/agentSurface.js +270 -0
  179. package/src/ui/format/banner.js +8 -11
  180. package/src/ui/format/startupBanner.js +50 -0
  181. package/src/ui/multiPaneBusMirror.js +29 -3
  182. package/src/ui/rustChatHost.js +170 -438
  183. package/src/ui/rustMultiSession.js +225 -51
  184. package/src/ui/rustUcodeHost.js +20 -87
  185. package/src/ui/settingsBridge.js +7 -4
  186. package/src/app/chat/agentEnter.js +0 -70
  187. package/src/app/chat/multiWindow/index.js +0 -310
  188. package/src/app/chat/multiWindow/paneLayout.js +0 -84
  189. package/src/app/chat/multiWindow/renderer.js +0 -420
  190. package/src/app/chat/multiWindow/virtualTerminal.js +0 -327
  191. package/src/app/chat/multiWindow/vtFrame.js +0 -93
  192. package/src/ui/multiWindowHandoff.js +0 -232
  193. package/src/ui/ptyHandoff.js +0 -23
@@ -79,6 +79,8 @@ function normalizeClaudeContentBlock(block = {}) {
79
79
  }];
80
80
  }
81
81
 
82
+ if (type === "thinking") return [{ type: "thinking_delta", delta: String(item.thinking || "") }];
83
+
82
84
  if (type === "tool_use") {
83
85
  return [{
84
86
  type: "tool_call",
@@ -170,8 +172,10 @@ function normalizeClaudeEvent(event = {}, state = createClaudeEventState()) {
170
172
  if (blockState.type === "tool_use") {
171
173
  blockState.toolCallId = String(block.id || block.tool_use_id || "");
172
174
  blockState.name = String(block.name || "");
173
- blockState.jsonText = safeStringify(block.input || "");
175
+ blockState.jsonText = block.input && Object.keys(block.input).length ? safeStringify(block.input) : "";
174
176
  }
177
+ if (blockState.type === "text" && blockState.text) return [{ type: "text_delta", delta: blockState.text, itemType: "text" }];
178
+ if (blockState.type === "thinking" && block.thinking) return [{ type: "thinking_delta", delta: String(block.thinking) }];
175
179
  return [];
176
180
  }
177
181
 
@@ -199,6 +203,7 @@ function normalizeClaudeEvent(event = {}, state = createClaudeEventState()) {
199
203
  itemType: "text",
200
204
  }];
201
205
  }
206
+ if (deltaType === "thinking_delta") return [{ type: "thinking_delta", delta: String(delta.thinking || "") }];
202
207
  if (deltaType === "input_json_delta") {
203
208
  blockState.jsonText += String(delta.partial_json || "");
204
209
  }
@@ -356,13 +356,44 @@ class ClaudeApiThread {
356
356
  const sessionId = String(message.session_id || message.sessionId || "").trim();
357
357
  for (const event of emitThreadStarted(this, sessionId)) yield event;
358
358
 
359
+ if (message.type === "system" && message.subtype === "status") {
360
+ yield redactUfooEvent({ type: "phase", phase: { type: message.status || "request_start" } });
361
+ continue;
362
+ }
363
+ if (message.type === "system" && message.subtype === "api_retry") {
364
+ yield redactUfooEvent({ type: "phase", phase: { type: "retry", attempt: message.attempt,
365
+ max_retries: message.max_retries, retry_delay_ms: message.retry_delay_ms } });
366
+ continue;
367
+ }
368
+ if (message.type === "system" && message.subtype === "compact_boundary") {
369
+ yield { type: "phase", phase: { type: "request_start" } };
370
+ continue;
371
+ }
372
+ if (message.type === "tool_progress") {
373
+ yield redactUfooEvent({ type: "phase", phase: { type: "tool_request", name: message.tool_name } });
374
+ continue;
375
+ }
376
+ if (message.type === "auth_status") {
377
+ yield redactUfooEvent({ type: "status", state: message.error ? "blocked" : "working",
378
+ text: message.error || (message.isAuthenticating ? "Authenticating…" : "Waiting for model…"), busy: !message.error });
379
+ continue;
380
+ }
381
+ if (message.type === "system" && ["task_started", "task_updated", "task_progress", "task_notification"].includes(message.subtype)) {
382
+ yield redactUfooEvent({ type: "background_task", task_id: message.task_id,
383
+ status: message.status || message.patch?.status || (message.subtype === "task_started" ? "running" : undefined),
384
+ description: message.description || message.patch?.description || message.summary || "" });
385
+ continue;
386
+ }
387
+
359
388
  if (message.type === "stream_event") {
360
389
  sawStreamEvents = true;
361
390
  const events = normalizeClaudeEvent(message.event || {}, state);
362
391
  for (const event of events) {
363
392
  if (!event || typeof event !== "object") continue;
364
393
  if (event.type === "text_delta" && event.delta) sawText = true;
365
- if (event.type === "turn_completed") sawTurnCompleted = true;
394
+ // A message ends before Claude executes its tools and continues.
395
+ // Only the SDK result ends the complete agent turn.
396
+ if (event.type === "turn_completed") continue;
366
397
  yield redactUfooEvent(event);
367
398
  }
368
399
  continue;
@@ -374,12 +405,23 @@ class ClaudeApiThread {
374
405
  for (const event of events) {
375
406
  if (!event || typeof event !== "object") continue;
376
407
  if (event.type === "text_delta" && event.delta) sawText = true;
377
- if (event.type === "turn_completed") sawTurnCompleted = true;
408
+ if (event.type === "turn_completed") continue;
378
409
  yield redactUfooEvent(event);
379
410
  }
380
411
  continue;
381
412
  }
382
413
 
414
+ if (message.type === "user") {
415
+ const blocks = message.message && Array.isArray(message.message.content) ? message.message.content : [];
416
+ for (const block of blocks) {
417
+ if (block.type !== "tool_result") continue;
418
+ for (const event of normalizeClaudeMessage({ content: [block] })) {
419
+ if (event.type === "tool_result") yield redactUfooEvent(event);
420
+ }
421
+ }
422
+ continue;
423
+ }
424
+
383
425
  if (message.type === "result") {
384
426
  if (message.is_error) {
385
427
  yield redactUfooEvent({
@@ -10,7 +10,11 @@ function getTextFromItem(item) {
10
10
  return "";
11
11
  }
12
12
 
13
- function normalizeCodexEvent(event = {}) {
13
+ function createCodexEventState() {
14
+ return { items: new Map() };
15
+ }
16
+
17
+ function normalizeCodexEvent(event = {}, state = createCodexEventState()) {
14
18
  const type = String(event.type || "").trim();
15
19
  if (!type) return null;
16
20
 
@@ -39,25 +43,60 @@ function normalizeCodexEvent(event = {}) {
39
43
  };
40
44
  }
41
45
 
42
- if (type === "item.completed") {
46
+ if (type === "error") return { type: "turn_failed", error: String(event.message || "Codex stream failed") };
47
+
48
+ if (["item.started", "item.updated", "item.completed"].includes(type)) {
43
49
  const item = event.item || {};
44
50
  const itemType = String(item.type || "").trim();
45
51
  const text = getTextFromItem(item);
52
+ const key = String(item.id || "");
53
+ const previous = key ? state.items.get(key) || {} : {};
54
+ const remember = (next) => { if (key) state.items.set(key, { ...previous, ...next }); };
55
+
56
+ if (itemType === "todo_list") return { type: "plan", items: item.items || [] };
46
57
 
47
- if (itemType === "message" || itemType === "assistant_message" || text) {
58
+ if (["message", "assistant_message", "agent_message"].includes(itemType)) {
59
+ const delta = text.startsWith(previous.text || "") ? text.slice((previous.text || "").length) : text;
60
+ remember({ text });
61
+ if (!delta) return type === "item.started" ? { type: "phase", phase: { type: "text_delta" } } : null;
48
62
  return {
49
63
  type: "text_delta",
50
- delta: text,
64
+ delta,
51
65
  itemType,
52
66
  };
53
67
  }
54
68
 
55
- if (itemType === "tool_call") {
69
+ if (itemType === "reasoning") {
70
+ const delta = text.startsWith(previous.text || "") ? text.slice((previous.text || "").length) : text;
71
+ remember({ text });
72
+ return delta ? { type: "thinking_delta", delta }
73
+ : type === "item.started" ? { type: "phase", phase: { type: "thinking" } } : null;
74
+ }
75
+
76
+ if (["tool_call", "command_execution", "mcp_tool_call", "file_change", "web_search", "todo_list"].includes(itemType)) {
77
+ if (previous.started && ["command_execution", "mcp_tool_call"].includes(itemType)) {
78
+ const output = itemType === "command_execution" ? String(item.aggregated_output || "") : item.result || item.error || "";
79
+ const delta = typeof output === "string" && output.startsWith(previous.output || "")
80
+ ? output.slice((previous.output || "").length) : output;
81
+ remember({ output });
82
+ if (!delta && type !== "item.completed") return null;
83
+ return { type: "tool_result", toolCallId: key, output: delta,
84
+ ...(item.exit_code !== undefined ? { exitCode: item.exit_code } : {}), status: item.status || "" };
85
+ }
86
+ remember({ started: true, output: "" });
87
+ const nativeTools = {
88
+ command_execution: { name: "bash", args: { command: item.command || "" } },
89
+ file_change: { name: "apply_patch", args: { path: (item.changes || []).map((change) => change.path).join(", ") } },
90
+ mcp_tool_call: { name: `${item.server || "mcp"}.${item.tool || "tool"}`, args: item.arguments || {} },
91
+ web_search: { name: "web_search", args: { query: item.query || "" } },
92
+ todo_list: { name: "plan", args: { items: item.items || [] } },
93
+ };
94
+ const tool = nativeTools[itemType] || { name: item.name || "", args: item.arguments || item.args || {} };
56
95
  return {
57
96
  type: "tool_call",
58
- name: item.name || "",
97
+ name: tool.name,
59
98
  toolCallId: item.id || item.tool_call_id || "",
60
- args: item.arguments || item.args || {},
99
+ args: tool.args,
61
100
  };
62
101
  }
63
102
 
@@ -74,5 +113,6 @@ function normalizeCodexEvent(event = {}) {
74
113
  }
75
114
 
76
115
  module.exports = {
116
+ createCodexEventState,
77
117
  normalizeCodexEvent,
78
118
  };
@@ -1,4 +1,4 @@
1
- const { normalizeCodexEvent } = require("./codexEventTranslator");
1
+ const { createCodexEventState, normalizeCodexEvent } = require("./codexEventTranslator");
2
2
  const { redactUfooEvent } = require("../../runtime/privacy/redactor");
3
3
 
4
4
  async function resolveCodexSdk() {
@@ -152,8 +152,9 @@ class CodexSdkThread {
152
152
  opts: mergedOpts,
153
153
  });
154
154
  let outputText = "";
155
+ const eventState = createCodexEventState();
155
156
  for await (const rawEvent of stream) {
156
- const normalized = normalizeCodexEvent(rawEvent);
157
+ const normalized = normalizeCodexEvent(rawEvent, eventState);
157
158
  if (!normalized) continue;
158
159
  if (normalized.type === "thread_started" && normalized.threadId) {
159
160
  this.id = normalized.threadId;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ const { createOpenAiChatTransport } = require("./transports/openaiChatTransport");
4
+
5
+ /** Adapt the legacy controller JSON envelope to the shared tool protocol. */
6
+ function createControllerJsonTransport({ invoke } = {}) {
7
+ return { ...createOpenAiChatTransport({
8
+ resolveUrl: () => "controller://local",
9
+ normalizeToolName: (name) => String(name || "").trim().toLowerCase(),
10
+ normalizeToolCallArgs: (args) => typeof args === "string" ? JSON.parse(args || "{}") : args || {},
11
+ toJsonString: JSON.stringify,
12
+ clipText: (text) => text,
13
+ async runTurn() {
14
+ const result = await invoke();
15
+ if (!result || result.ok !== true) throw Object.assign(new Error(result && result.error || "ufoo-agent loop failed"), { code: "provider_error" });
16
+ const payload = result.payload || {};
17
+ const call = payload.tool_call;
18
+ return {
19
+ text: call ? "" : JSON.stringify(payload),
20
+ toolCalls: call ? [{ id: call.tool_call_id || call.toolCallId || call.id,
21
+ function: { name: call.name, arguments: call.arguments || call.args || {} } }] : [],
22
+ usage: { input: result.meta && result.meta.input_tokens, output: result.meta && result.meta.output_tokens },
23
+ };
24
+ },
25
+ }), features: Object.freeze(["tool_calls"]) };
26
+ }
27
+
28
+ module.exports = { createControllerJsonTransport };
@@ -22,7 +22,7 @@ function defaultClaudeConfigDir() {
22
22
  }
23
23
 
24
24
  function resolveClaudeOauthPaths(options = {}) {
25
- const configDir = String(options.configDir || defaultClaudeConfigDir()).trim() || defaultClaudeConfigDir();
25
+ const configDir = String(options.configDir || (options.env || process.env).CLAUDE_CONFIG_DIR || defaultClaudeConfigDir()).trim() || defaultClaudeConfigDir();
26
26
  const profile = String(options.profile || "").trim();
27
27
  const explicitTokenPath = String(options.tokenPath || "").trim();
28
28
  const explicitSettingsPath = String(options.settingsPath || "").trim();
@@ -234,6 +234,7 @@ class ClaudeUpstreamCredentialResolver {
234
234
  apiKey: firstString(env.ANTHROPIC_API_KEY, env.CLAUDE_API_KEY),
235
235
  apiKeySource,
236
236
  authToken: firstString(env.ANTHROPIC_AUTH_TOKEN),
237
+ baseUrl: firstString(env.ANTHROPIC_BASE_URL),
237
238
  };
238
239
  }
239
240
 
@@ -332,7 +333,7 @@ class ClaudeUpstreamCredentialResolver {
332
333
  });
333
334
  }
334
335
 
335
- async resolveCredentials() {
336
+ async resolveAuthCredential(settingsEnv) {
336
337
  const anthropicApiKey = firstString(this.env.ANTHROPIC_API_KEY);
337
338
  const claudeApiKey = firstString(this.env.CLAUDE_API_KEY);
338
339
  if (anthropicApiKey || claudeApiKey) {
@@ -347,7 +348,6 @@ class ClaudeUpstreamCredentialResolver {
347
348
  return this.buildAuthTokenCredential(authToken, "env:ANTHROPIC_AUTH_TOKEN");
348
349
  }
349
350
 
350
- const settingsEnv = this.readSettingsEnv();
351
351
  if (settingsEnv.apiKey) {
352
352
  return this.buildApiKeyCredential(settingsEnv.apiKey, settingsEnv.apiKeySource || "settings:ANTHROPIC_API_KEY", this.paths.settingsPath);
353
353
  }
@@ -373,6 +373,13 @@ class ClaudeUpstreamCredentialResolver {
373
373
 
374
374
  return this.refreshIfNeeded(tokenRecord);
375
375
  }
376
+
377
+ async resolveCredentials() {
378
+ const settings = this.readSettingsEnv();
379
+ const credential = await this.resolveAuthCredential(settings);
380
+ return { ...credential, metadata: { ...credential.metadata,
381
+ baseUrl: firstString(this.env.ANTHROPIC_BASE_URL, settings.baseUrl) } };
382
+ }
376
383
  }
377
384
 
378
385
  async function resolveClaudeUpstreamCredentials(options = {}) {