Skip to content

Commit 395c4a2

Browse files
committed
feat(appkit): introduce workspace-client wrapper over the Databricks SDK
Add packages/appkit/src/workspace-client/ — a facade over the legacy @databricks/sdk-experimental client that mirrors the modular Databricks SDK's multi-client shape. This prepares the library for an incremental, per-service migration to the modular SDK without migrating anything yet. - legacy.ts is the ONLY module importing @databricks/sdk-experimental; it constructs the client and re-exports the SDK symbols AppKit uses. - The WorkspaceClient facade exposes per-service accessors (files, warehouses, genie, jobs, statementExecution, servingEndpoints, currentUser, config, apiClient), each legacy-typed and delegating to the underlying client. Migrating a service later is a localized swap: one getter + its accessor type + one connector. - createWorkspaceClient() replaces every `new WorkspaceClient(...)` site (runtime + build-time type-generator); toLegacyWorkspaceClient() is the escape hatch for @databricks/lakebase. - createApp({ client }) and the public index now expose the wrapper type instead of the raw SDK client. - A Biome noRestrictedImports boundary rule forbids importing @databricks/sdk-experimental outside workspace-client/, keeping the seam enforceable. Tests mock the wrapper rather than the SDK. Time is sourced off the SDK namespace (SDK.Time ?? SDK.default.Time) because the SDK's CommonJS `Time` export is a getter that defeats Node's static ESM named-export detection — a direct `export { Time }` throws at link time. Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
1 parent affe5d2 commit 395c4a2

77 files changed

Lines changed: 877 additions & 206 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

biome.json

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@
4141
},
4242
"security": {
4343
"noDangerouslySetInnerHtml": "off"
44+
},
45+
"style": {
46+
"noRestrictedImports": {
47+
"level": "error",
48+
"options": {
49+
"patterns": [
50+
{
51+
"group": [
52+
"@databricks/sdk-experimental",
53+
"@databricks/sdk-experimental/**"
54+
],
55+
"message": "Import the Databricks SDK only through the wrapper in packages/appkit/src/workspace-client. Add a re-export there if you need a new symbol."
56+
}
57+
]
58+
}
59+
}
4460
}
4561
}
4662
},
@@ -56,5 +72,17 @@
5672
"organizeImports": "on"
5773
}
5874
}
59-
}
75+
},
76+
"overrides": [
77+
{
78+
"includes": ["packages/appkit/src/workspace-client/**"],
79+
"linter": {
80+
"rules": {
81+
"style": {
82+
"noRestrictedImports": "off"
83+
}
84+
}
85+
}
86+
}
87+
]
6088
}

docs/docs/api/appkit/Class.DatabricksAdapter.md

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/docs/api/appkit/Function.createApp.md

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/docs/api/appkit/Function.createWorkspaceClient.md

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/docs/api/appkit/Interface.WorkspaceClient.md

Lines changed: 118 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/docs/api/appkit/Interface.WorkspaceClientOptions.md

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/docs/api/appkit/index.md

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/docs/api/appkit/typedoc-sidebar.ts

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/appkit/src/agents/databricks.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
} from "shared";
88
import { stream as servingStream } from "../connectors/serving/client";
99
import { APPKIT_USER_AGENT, getClientOptions } from "../context/client-options";
10+
import { createWorkspaceClient } from "../workspace-client";
1011

1112
/** Default cap for a single incomplete SSE line tail (DoS guard). */
1213
const DEFAULT_MAX_SSE_LINE_CHARS = 1024 * 1024;
@@ -246,12 +247,11 @@ interface DeltaToolCall {
246247
*
247248
* @example Using the factory (recommended)
248249
* ```ts
249-
* import { createApp, createAgent, agents } from "@databricks/appkit";
250+
* import { createApp, createAgent, agents, createWorkspaceClient } from "@databricks/appkit";
250251
* import { DatabricksAdapter } from "@databricks/appkit/beta";
251-
* import { WorkspaceClient } from "@databricks/sdk-experimental";
252252
*
253253
* const adapter = DatabricksAdapter.fromServingEndpoint({
254-
* workspaceClient: new WorkspaceClient({}),
254+
* workspaceClient: createWorkspaceClient(),
255255
* endpointName: "my-endpoint",
256256
* });
257257
*
@@ -405,11 +405,9 @@ export class DatabricksAdapter implements AgentAdapter {
405405
let workspaceClient: WorkspaceClientLike | undefined =
406406
options?.workspaceClient;
407407
if (!workspaceClient) {
408-
const sdk = await import("@databricks/sdk-experimental");
409-
workspaceClient = new sdk.WorkspaceClient(
410-
{},
411-
getClientOptions(),
412-
) as unknown as WorkspaceClientLike;
408+
workspaceClient = createWorkspaceClient({
409+
clientOptions: getClientOptions(),
410+
}) as unknown as WorkspaceClientLike;
413411
}
414412

415413
return DatabricksAdapter.fromServingEndpoint({

packages/appkit/src/agents/tests/databricks.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -999,11 +999,16 @@ describe("DatabricksAdapter.fromModelServing", () => {
999999
test("reads endpoint from DATABRICKS_SERVING_ENDPOINT_NAME env var", async () => {
10001000
process.env.DATABRICKS_SERVING_ENDPOINT_NAME = "my-model";
10011001

1002-
vi.mock("@databricks/sdk-experimental", () => ({
1003-
WorkspaceClient: vi.fn().mockImplementation(() => ({
1004-
apiClient: { request: vi.fn() },
1005-
})),
1006-
}));
1002+
vi.mock("../../workspace-client", async (importOriginal) => {
1003+
const actual =
1004+
await importOriginal<typeof import("../../workspace-client")>();
1005+
return {
1006+
...actual,
1007+
createWorkspaceClient: vi.fn().mockImplementation(() => ({
1008+
apiClient: { request: vi.fn() },
1009+
})),
1010+
};
1011+
});
10071012

10081013
const adapter = await DatabricksAdapter.fromModelServing();
10091014
expect(adapter).toBeInstanceOf(DatabricksAdapter);

0 commit comments

Comments
 (0)