Skip to content

feat(provider): add codebuddy as a LLM provider - #780

Merged
pancacake merged 15 commits into
HKUDS:devfrom
SeleiXi:feat/codebuddy-provider
Aug 12, 2026
Merged

pancacake merged 15 commits into
HKUDS:devfrom
SeleiXi:feat/codebuddy-provider

Conversation

@SeleiXi

@SeleiXi SeleiXi commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Description

Adds CodeBuddy/WorkBuddy as an LLM provider in DeepTutor, allowing users to use their existing CodeBuddy subscription quota.

The integration reuses the OAuth login already created by the CodeBuddy IDE plugin or CLI and sends normal chat-completion requests directly to CodeBuddy's OpenAI-compatible HTTP endpoint. The Agent SDK is optional and is retained only as a fallback for interactive login and SDK-specific agent behavior.

Screenshot

376347fa9677b9d886aa3e6369d7516e
97df212e62bbd2c15c44387be79eac85

What This PR Does

Direct HTTP provider

  • Adds an OpenAI-compatible CodeBuddy HTTP provider.
  • Sends chat requests directly to the CodeBuddy cloud under its /v2
    endpoint.
  • Supports streaming responses and standard OpenAI-style tool calling.
  • Preserves DeepTutor's existing tool dispatcher and authorization behavior.
  • Refreshes expired OAuth access tokens when a usable refresh token is available.
  • Retries authentication once after reloading updated credentials from disk.

Local credential reuse

  • Detects the OAuth session shared by the CodeBuddy IDE plugin and CLI.
  • Supports the corresponding credential locations on Windows, macOS, and Linux.
  • Validates an existing session through the CodeBuddy account endpoint.
  • Displays the detected account in the Dashboard settings page.
  • Does not copy the external login into a new DeepTutor credential store.

Related Issues

Closes #773

Module(s) Affected

  • agents
  • api
  • config
  • core
  • knowledge
  • logging
  • services
  • tools
  • utils
  • web (Frontend)
  • docs (Documentation)
  • scripts
  • tests
  • Other: ...

Checklist

  • I have read and followed the contribution guidelines.
  • My code follows the project's coding standards.
  • I have run pre-commit run --all-files and fixed any issues.
  • I have added relevant tests for my changes.
  • I have updated the documentation (if necessary).
  • My changes do not introduce any new security vulnerabilities.

SeleiXi and others added 15 commits August 3, 2026 21:01
Chat with CodeBuddy over plain HTTP by reusing the login state that the
IDE plugin / CLI stores on disk, instead of bundling the ~130MB Agent SDK.

- add codebuddy_http_provider (OpenAI-compatible /chat/completions on
  <endpoint>/v2) with codebuddy_credentials for local OAuth session reuse
- provider_factory picks HTTP transport whenever a login state or API key
  is available; Agent SDK stays as fallback for CLI agent features
- demote codebuddy-agent-sdk from core deps to optional codebuddy extra
- default model codebuddy/default -> codebuddy/hy3
- update auth card UX and locales for SDK-less sign-in flow
…ider

# Conflicts:
#	web/components/settings/ServiceConfigEditor.tsx
Merges dev and reworks this branch against what an adversarial pass found.

**The administrator's subscription was grantable.** A CodeBuddy credential
is one person's IDE-plugin login read from this host, exactly the shape
HKUDS#690 ruled must never be lent out — but ``owner_bound`` is stamped on the
*managed* profile Codex publishes, and a CodeBuddy profile is created by
hand in the settings editor with nowhere to acquire it. Binding now decides
too (``OWNER_BOUND_BINDINGS``), so the profile is never offered in the
grant editor.

**The agent sandbox failed open.** ``_build_options`` probed ten candidate
kwarg sets and returned the first the SDK accepted; six of them carry no
``permission_mode`` and no turn limit. An SDK that renamed those kwargs
would silently fall through to an unrestricted agent. Every candidate now
carries them — both spellings — and exhausting the list raises. The extra
is pinned ``<0.2`` so a minor bump cannot reintroduce the fall-through, and
dropped from ``all`` (it vendors a ~130 MB headless CLI that chat does not
need).

**A local file chose where the token was sent.** ``cached_product_endpoint``
accepted any string starting with ``http`` out of another application's
cache blob. Anything able to write under the service account's home could
point the bearer token at a host of its choosing. Restricted to https on
the two known deployments; an operator who needs another still sets
``CODEBUDDY_BASE_URL``, which is honoured first.

**Logout ended a session DeepTutor does not own.** It called the SDK's
logout against the auth file the IDE plugin and CLI share, signing the
operator out of their editor. It now drops our cached clients and reports
where the session actually lives.

**A phone number was a display label.** ``user_label`` fell back to
``phoneNumber``, returned verbatim by the status endpoint to every admin.

Also: keep the usage-extraction change from wiping real token counts when a
gateway echoes a zero-filled usage object on delta chunks (it applies to
every openai_compat provider, not just this one); replace the two
``binding == "codebuddy"`` tests in the chat loop and the explore
capability with a ``threads_session_id`` predicate, so generic code no
longer names a provider; and revert 33 files whose only change was a
Prettier reformat in the opposite direction from the 3.8.3 the repo pins —
they would have made the next contributor's ``pre-commit run --all-files``
touch 33 unrelated files.
@pancacake
pancacake changed the base branch from main to dev August 12, 2026 16:02
@pancacake
pancacake merged commit 8297fc7 into HKUDS:dev Aug 12, 2026
pancacake added a commit that referenced this pull request Aug 12, 2026
An adversarial pass over #818 / #789 / #780 after merging.

**Codex sign-ins from before this week stopped working (#789).**
``validate_runtime_profile`` compared the profile's ``codex_account_binding``
for equality, but that key is written only by ``sync_codex_catalog`` — every
managed profile published by #690/#774 has none, so ``None != <hash>`` made
each of them look like another account's and locked its owner out of Codex
until they re-ran "Refresh models". Absent now reads as legacy; a binding
that is present and different is still an account switch and still refused.

**Overriding reasoning effort for one turn returned 409 (#789).** The same
function also required the request's effort to be byte-equal to the value
stored in the catalog. Effort is a per-request knob, not part of the identity
that ties a config to a token — the check now stops at model membership.
Its test asserted the old behaviour and has been rewritten around what the
function is actually for.

**The reasoning-effort endpoint left the runtime caches stale (#789).** It
writes the catalog the runtime resolves against, like every other catalog
write in this router, but skipped ``_invalidate_runtime_caches()``.

**OrcaRouter claimed Anthropic prompt caching (#818).** ``supports_prompt_caching``
makes ``_build_kwargs`` inject ``cache_control`` blocks into any ``anthropic/*``
or ``claude*`` request — an OpenRouter extension. No other gateway sets it and
nothing established the second one accepts it; a strict gateway would 400 every
Claude turn. Also fixed ``anthropic/claude-sonnet-4.6`` in the fallback list,
which the rest of the repo spells with dashes, so a user picking it from our
own menu would have got "model not found".

**OrcaRouter inserted itself into the curated menus (#818).** The featured
lists are hand-picked and rendered as a positional numbered menu, so adding an
entry shifted Ollama from [10] to [11]. The registry entry alone already makes
a provider reachable via "Show all" and the Settings dropdown; which providers
are featured is a maintainer decision. The README paragraph goes with it — no
other provider has per-provider prose there, and it would have been translated
into ten languages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Add CodeBuddy/WorkBuddy as a provider

2 participants