Refactor
This commit is contained in:
@@ -40,8 +40,11 @@ export function cloakClaudeTools(body) {
|
||||
const clientToolNames = new Set();
|
||||
const clientDeclarations = [];
|
||||
|
||||
// All client tools get renamed with suffix
|
||||
// All client tools get renamed with suffix.
|
||||
// Built-in server tools (web_search_20250305, etc.) carry a `type` and require
|
||||
// an exact reserved `name` — never suffix those or Claude rejects the request.
|
||||
for (const tool of tools) {
|
||||
if (tool.type) { clientDeclarations.push(tool); continue; }
|
||||
const suffixed = suffix(tool.name);
|
||||
toolNameMap.set(suffixed, tool.name);
|
||||
clientToolNames.add(tool.name);
|
||||
|
||||
@@ -128,7 +128,10 @@ export function createDisconnectAwareStream(transformStream, streamController, o
|
||||
controller.enqueue(value);
|
||||
} catch (error) {
|
||||
const wasConnected = streamController.isConnected();
|
||||
streamController.handleError(error);
|
||||
// Controller already closed = downstream ended; not an upstream error, skip noisy log.
|
||||
const msg0 = error?.message || "";
|
||||
const isControllerClosed = msg0.includes("already closed") || msg0.includes("Invalid state");
|
||||
if (!isControllerClosed) streamController.handleError(error);
|
||||
reader.cancel().catch(() => {});
|
||||
writer.abort().catch(() => {});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user