gitlab integration poc
This commit is contained in:
parent
d95fd77861
commit
b3182149c8
7 changed files with 100 additions and 10 deletions
|
|
@ -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:",
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
86
packages/opencode/src/plugin/gitlab.ts
Normal file
86
packages/opencode/src/plugin/gitlab.ts
Normal file
|
|
@ -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
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ 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" })
|
||||
|
|
@ -19,7 +20,7 @@ export namespace 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({
|
||||
|
|
|
|||
|
|
@ -165,6 +165,8 @@ export type ProviderHook = {
|
|||
reconcile?: (input: {
|
||||
provider: Provider
|
||||
models: Record<string, Model>
|
||||
auth?: Auth
|
||||
options?: Record<string, unknown>
|
||||
}) => Promise<Record<string, Model> | undefined>
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue