mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-09 22:25:02 +03:00
fix(core): accept a Databricks host that includes the scheme (#59334)
This commit is contained in:
committed by
GitHub
Unverified
parent
7405f93721
commit
be600a2eee
@@ -8,6 +8,16 @@ export const DatabricksPlugin = define({
|
||||
// models.dev also lists DATABRICKS_HOST, which only fills the base URL template.
|
||||
editor.method.update({ integrationID: "databricks", method: { type: "env", names: ["DATABRICKS_TOKEN"] } })
|
||||
})
|
||||
yield* ctx.provider.transform((evt) => {
|
||||
// The template adds its own scheme, but Databricks tooling documents DATABRICKS_HOST with one.
|
||||
const host = process.env.DATABRICKS_HOST?.replace(/^https?:\/\//i, "").replace(/\/+$/, "")
|
||||
if (!host) return
|
||||
const baseURL = evt.get("databricks")?.provider.settings?.baseURL
|
||||
if (typeof baseURL !== "string" || !baseURL.includes("${DATABRICKS_HOST}")) return
|
||||
evt.update("databricks", (provider) => {
|
||||
provider.settings = { ...provider.settings, baseURL: baseURL.replaceAll("${DATABRICKS_HOST}", host) }
|
||||
})
|
||||
})
|
||||
yield* ctx.model.transform((models) => {
|
||||
for (const item of models.list("databricks")) {
|
||||
// Databricks caches Claude only through explicit `cache_control` breakpoints.
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import { describe, expect } from "bun:test"
|
||||
import { Effect } from "effect"
|
||||
import { Plugin } from "@opencode/core/plugin"
|
||||
import { PluginHost } from "@opencode/core/plugin/host"
|
||||
import { DatabricksPlugin } from "@opencode/core/plugin/provider/databricks"
|
||||
import { Provider } from "@opencode/core/provider"
|
||||
import { testEffect } from "../lib/effect"
|
||||
import { PluginTestLayer } from "./fixture"
|
||||
|
||||
const it = testEffect(PluginTestLayer)
|
||||
const providerID = Provider.ID.make("databricks")
|
||||
|
||||
const baseURLFor = Effect.fn(function* (host: string) {
|
||||
const previous = process.env.DATABRICKS_HOST
|
||||
yield* Effect.addFinalizer(() =>
|
||||
Effect.sync(() => {
|
||||
if (previous === undefined) delete process.env.DATABRICKS_HOST
|
||||
if (previous !== undefined) process.env.DATABRICKS_HOST = previous
|
||||
}),
|
||||
)
|
||||
process.env.DATABRICKS_HOST = host
|
||||
const catalog = yield* Provider.Service
|
||||
yield* catalog.transform((catalog) => {
|
||||
catalog.update(providerID, (item) => {
|
||||
item.settings = { baseURL: "https://${DATABRICKS_HOST}/ai-gateway/mlflow/v1" }
|
||||
})
|
||||
})
|
||||
const plugin = yield* Plugin.Service
|
||||
yield* DatabricksPlugin.effect(yield* PluginHost.make(plugin))
|
||||
return (yield* catalog.get(providerID))?.settings?.baseURL
|
||||
})
|
||||
|
||||
describe("DatabricksPlugin", () => {
|
||||
it.effect("fills the base URL from a bare host", () =>
|
||||
Effect.gen(function* () {
|
||||
expect(yield* baseURLFor("adb-123.azuredatabricks.net")).toBe(
|
||||
"https://adb-123.azuredatabricks.net/ai-gateway/mlflow/v1",
|
||||
)
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("fills the base URL from a host that includes the scheme", () =>
|
||||
Effect.gen(function* () {
|
||||
expect(yield* baseURLFor("https://adb-123.azuredatabricks.net/")).toBe(
|
||||
"https://adb-123.azuredatabricks.net/ai-gateway/mlflow/v1",
|
||||
)
|
||||
}),
|
||||
)
|
||||
})
|
||||
Reference in New Issue
Block a user