8 Commits

  • feat: add cache-user-id toggle for Claude cloaking
    Default to generating a fresh random user_id per request instead of
    reusing cached IDs. Add cache-user-id config option to opt in to the
    previous caching behavior.
    
    - Add CacheUserID field to CloakConfig
    - Extract user_id cache logic to dedicated file
    - Generate fresh user_id by default, cache only when enabled
    - Add tests for both paths
  • Merge branch 'pr-1624' into dev
    # Conflicts:
    #	internal/runtime/executor/claude_executor.go
    #	internal/runtime/executor/claude_executor_test.go
  • fix: skip proxy_ prefix for built-in tools in message history
    The proxy_ prefix logic correctly skips built-in tools (those with a
    non-empty "type" field) in tools[] definitions but does not skip them
    in messages[].content[] tool_use blocks or tool_choice. This causes
    web_search in conversation history to become proxy_web_search, which
    Anthropic does not recognize.
    
    Fix: collect built-in tool names from tools[] into a set and also
    maintain a hardcoded fallback set (web_search, code_execution,
    text_editor, computer) for cases where the built-in tool appears in
    history but not in the current request's tools[] array. Skip prefixing
    in messages and tool_choice when name matches a built-in.
  • fix: skip built-in tools in tool_reference prefix + refactor to switch
    - Collect built-in tool names (those with a "type" field like
      web_search, code_execution) and skip prefixing tool_reference
      blocks that reference them, preventing name mismatch.
    - Refactor if-else if chains to switch statements in all three
      prefix functions for idiomatic Go style.
  • fix: handle tool_reference nested inside tool_result.content[]
    tool_reference blocks can appear nested inside tool_result.content[]
    arrays, not just at the top level of messages[].content[]. The prefix
    logic now iterates into tool_result blocks with array content to find
    and prefix/strip nested tool_reference.tool_name fields.
  • fix: add proxy_ prefix handling for tool_reference content blocks (#1)
    applyClaudeToolPrefix, stripClaudeToolPrefixFromResponse, and
    stripClaudeToolPrefixFromStreamLine now handle "tool_reference" blocks
    (field "tool_name") in addition to "tool_use" blocks (field "name").
    
    Without this fix, tool_reference blocks in conversation history retain
    their original unprefixed names while tool definitions carry the proxy_
    prefix, causing Anthropic API 400 errors: "Tool reference 'X' not found
    in available tools."
    
    Co-authored-by: Kirill Turanskiy <kt@novamedia.ru>
  • Fix Claude OAuth tool name mapping
    Prefix tool names with proxy_ for Claude OAuth requests and strip the prefix from streaming and non-streaming responses to restore client-facing names.
    
    Updates the Claude executor to:
    - add prefixing for tools, tool_choice, and tool_use messages when using OAuth tokens
    - strip the prefix from tool_use events in SSE and non-streaming payloads
    - add focused unit tests for prefix/strip helpers