GitLab Duo provider#772
Conversation
Uses @gitlab/gitlab-ai-provider for native tool calling via GitLab's Anthropic proxy. Supports Claude Opus 4.5, Sonnet 4.5, and Haiku 4.5 models with automatic OAuth token management. - Add gitlab-duo API type and provider - Add duo-chat, duo-chat-opus-4-5, duo-chat-sonnet-4-5, duo-chat-haiku-4-5 models - Support GITLAB_TOKEN and GITLAB_DUO_TOKEN env vars - Support self-hosted GitLab via instanceUrl option - Add streaming support for text, reasoning, and tool calls
Track processed tool call IDs to prevent emitting the same tool call twice - once from streaming events and again from the final tool-call event.
- Add loginGitLabDuo and refreshGitLabDuoToken functions - Add gitlab-duo to OAuth provider list - Update CLI to handle gitlab-duo login flow - Support self-hosted GitLab via GITLAB_INSTANCE_URL env var - Update documentation with OAuth instructions
Use the opencode-gitlab-auth client ID which is registered with http://127.0.0.1:8080/callback redirect URI. Implements a lightweight callback server using Node's http module. The bundled VS Code extension client ID only supports vscode:// scheme redirects which don't work for CLI applications.
- Add stream.test.ts tests for GitLab Duo provider - Fix model config: reasoning=false, input=[text] only - GitLab Duo doesn't support thinking/reasoning mode - GitLab Duo proxy doesn't support image input
Add gitlab-duo provider tests to: - abort.test.ts - context-overflow.test.ts - empty.test.ts - tokens.test.ts - tool-call-without-result.test.ts - total-tokens.test.ts - unicode-surrogate.test.ts Note: image-tool-result.test.ts not updated since GitLab Duo doesn't support image input.
- Skip cost assertions for gitlab-duo (subscription-based, no per-token cost) - Skip unpaired surrogate test (GitLab proxy rejects malformed unicode) - Skip context-overflow test (error patterns may differ from direct Anthropic)
Extract the cause from TOKEN_REFRESH_NEEDED errors to show the actual API error (e.g., 'prompt is too long: X tokens > Y maximum') instead of a generic auth failure message.
Sanitize unpaired surrogate characters in system prompts, user messages, assistant text, and tool results to prevent API errors from malformed unicode.
The test requires longer timeout due to GitLab proxy latency.
|
@badlogic In order to get test credits for an integration test you can go through https://contributors.gitlab.com/start. Please link to this comment if you do. GitLab team members reading this: Ping me in Slack for more context if needed. cc @terrorobe |
|
@igorwwwwwwwwwwwwwwwwwwww sorry it took so long ot get to this. I tried to go through the onboarding link, but it's frankly super confusing. E.g. https://gitlab.com/gitlab-community/community-members/onboarding/-/issues/3430 80% of this does not apply to me, I will not be contributing to GitLab itself, so I just checked all the things. It is also unclear to me where I should put the link to your comment. I'm happy to pay for GitLab Duo credits (if such a thing exists, it's unclear from the GitLab Duo site) to get to a token/OAuth faster. Any pointers? |
|
@igorwwwwwwwwwwwwwwwwwwww thanks for the PR. I reimplemented this as a pi extension with full support for:
It can be used via: Then just pick any Ghostty.mp4Internally, this delegates to the excisting implementations of Anthropic's Messages API and OpenAI's Responses API, which makes the implementation trivial: https://github.com/badlogic/pi-gitlab-duo I'm happy to have you maintain that package if you want, e.g. improve model enumeration (maybe you have an endpoint that spits out the currently supported models), and obviously move it to GitLab. |
|
@badlogic Amazing. Thanks for this, looks great! I'd be happy to take ownership of the plugin, let me know what you need for that. |
|
@badlogic I've created a fork on our end. Would you be able to transfer the npm package to me? My NPM user is: |
Follow-up to #759, now with tests.
Uses @gitlab/gitlab-ai-provider for native tool calling via GitLab's Anthropic proxy. Supports Claude Opus 4.5, Sonnet 4.5, and Haiku 4.5 models.
This is based on the opencode implementation: anomalyco/opencode#7333. I tried to use @gitlab/opencode-gitlab-auth directly, but it takes a dep on @opencode-ai/plugin and I didn't want to drag in all of those transitive deps.