Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/opencode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"@ai-sdk/xai": "2.0.51",
"@aws-sdk/credential-providers": "3.993.0",
"@clack/prompts": "1.0.0-alpha.1",
"@gitlab/gitlab-ai-provider": "3.6.0",
"gitlab-ai-provider": "5.2.0",
"@gitlab/opencode-gitlab-auth": "1.3.3",
"@hono/standard-validator": "0.1.5",
"@hono/zod-validator": "catalog:",
Expand Down
2 changes: 1 addition & 1 deletion packages/opencode/src/plugin/codex.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Hooks, PluginInput } from "@opencode-ai/plugin"
import { Log } from "../util/log"
import { Installation } from "../installation"
import { Auth, OAUTH_DUMMY_KEY } from "../auth"
import { OAUTH_DUMMY_KEY } from "../auth"
import os from "os"
import { ProviderTransform } from "@/provider/transform"
import { ModelID, ProviderID } from "@/provider/schema"
Expand Down
86 changes: 86 additions & 0 deletions packages/opencode/src/plugin/gitlab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import type { Hooks, PluginInput } from "@opencode-ai/plugin"
import { discoverWorkflowModels } from "gitlab-ai-provider"
import { Log } from "@/util/log"
import { ProviderTransform } from "@/provider/transform"
import { ModelID, ProviderID } from "@/provider/schema"

const log = Log.create({ service: "plugin.gitlab" })

function str(value: unknown, fallback: string) {
if (typeof value === "string" && value) return value
return fallback
}

export async function GitlabPlugin(input: PluginInput): Promise<Hooks> {
return {
provider: {
id: "gitlab",
models: {
async reconcile(args) {
const url = str(args.options?.instanceUrl, "https://gitlab.com")

const token = str(args.options?.apiKey, "")
if (!token) return
const headers = (): Record<string, string> => {
if (args.auth?.type === "api") return { "PRIVATE-TOKEN": token }
return { Authorization: `Bearer ${token}` }
}

try {
log.info("gitlab model discovery starting", { instanceUrl: url })
const res = await discoverWorkflowModels(
{ instanceUrl: url, getHeaders: headers },
{ workingDirectory: input.directory },
)

if (!res.models.length) {
log.info("gitlab model discovery skipped: no models found", {
project: res.project ? { id: res.project.id, path: res.project.pathWithNamespace } : null,
})
return
}
for (const model of res.models) {
if (args.models[model.id]) {
continue
}

const m = {
id: ModelID.make(model.id),
providerID: ProviderID.make("gitlab"),
name: `Agent Platform (${model.name})`,
api: {
id: model.id,
url,
npm: "gitlab-ai-provider",
},
status: "active" as const,
headers: {},
options: { workflowRef: model.ref },
cost: { input: 0, output: 0, cache: { read: 0, write: 0 } },
limit: { context: model.context, output: model.output },
capabilities: {
temperature: false,
reasoning: true,
attachment: true,
toolcall: true,
input: { text: true, audio: false, image: true, video: false, pdf: true },
output: { text: true, audio: false, image: false, video: false, pdf: false },
interleaved: false,
},
release_date: "",
variants: {} as Record<string, Record<string, any>>,
}
m.variants = ProviderTransform.variants(m)
args.models[model.id] = m
}

return args.models
} catch (err) {
log.warn("gitlab model discovery failed", { error: err })
return
}
},
},
},
}
}
9 changes: 5 additions & 4 deletions packages/opencode/src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import { Session } from "../session"
import { NamedError } from "@opencode-ai/util/error"
import { CopilotAuthPlugin } from "./copilot"
import { gitlabAuthPlugin as GitlabAuthPlugin } from "@gitlab/opencode-gitlab-auth"
import { GitlabPlugin } from "./gitlab"

export namespace Plugin {
const log = Log.create({ service: "plugin" })

const BUILTIN = ["opencode-anthropic-auth@0.0.13"]

// Built-in plugins that are directly imported (not installed from npm)
const INTERNAL_PLUGINS: PluginInstance[] = [CodexAuthPlugin, CopilotAuthPlugin, GitlabAuthPlugin]
const INTERNAL_PLUGINS: PluginInstance[] = [CodexAuthPlugin, CopilotAuthPlugin, GitlabAuthPlugin, GitlabPlugin]

const state = Instance.state(async () => {
const client = createOpencodeClient({
Expand Down Expand Up @@ -110,9 +111,9 @@ export namespace Plugin {
})

export async function trigger<
Name extends Exclude<keyof Required<Hooks>, "auth" | "event" | "tool">,
Input = Parameters<Required<Hooks>[Name]>[0],
Output = Parameters<Required<Hooks>[Name]>[1],
Name extends Exclude<keyof Required<Hooks>, "auth" | "event" | "tool" | "provider">,
Input = Parameters<Extract<Required<Hooks>[Name], (...args: any) => any>>[0],
Output = Parameters<Extract<Required<Hooks>[Name], (...args: any) => any>>[1],
>(name: Name, input: Input, output: Output): Promise<Output> {
if (!name) return output
for (const hook of await state().then((x) => x.hooks)) {
Expand Down
13 changes: 13 additions & 0 deletions packages/plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,26 @@ export type AuthOuathResult = { url: string; instructions: string } & (
}
)

export type ProviderHook = {
id: string
models?: {
reconcile?: (input: {
provider: Provider
models: Record<string, Model>
auth?: Auth
options?: Record<string, unknown>
}) => Promise<Record<string, Model> | undefined>
}
}

export interface Hooks {
event?: (input: { event: Event }) => Promise<void>
config?: (input: Config) => Promise<void>
tool?: {
[key: string]: ToolDefinition
}
auth?: AuthHook
provider?: ProviderHook
/**
* Called when a new message is received
*/
Expand Down
Loading