Skip to content

Commit 01e0549

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 a1ea023 commit 01e0549

77 files changed

Lines changed: 877 additions & 208 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;
@@ -203,12 +204,11 @@ interface DeltaToolCall {
203204
*
204205
* @example Using the factory (recommended)
205206
* ```ts
206-
* import { createApp, createAgent, agents } from "@databricks/appkit";
207+
* import { createApp, createAgent, agents, createWorkspaceClient } from "@databricks/appkit";
207208
* import { DatabricksAdapter } from "@databricks/appkit/beta";
208-
* import { WorkspaceClient } from "@databricks/sdk-experimental";
209209
*
210210
* const adapter = DatabricksAdapter.fromServingEndpoint({
211-
* workspaceClient: new WorkspaceClient({}),
211+
* workspaceClient: createWorkspaceClient(),
212212
* endpointName: "my-endpoint",
213213
* });
214214
*
@@ -358,11 +358,9 @@ export class DatabricksAdapter implements AgentAdapter {
358358
let workspaceClient: WorkspaceClientLike | undefined =
359359
options?.workspaceClient;
360360
if (!workspaceClient) {
361-
const sdk = await import("@databricks/sdk-experimental");
362-
workspaceClient = new sdk.WorkspaceClient(
363-
{},
364-
getClientOptions(),
365-
) as unknown as WorkspaceClientLike;
361+
workspaceClient = createWorkspaceClient({
362+
clientOptions: getClientOptions(),
363+
}) as unknown as WorkspaceClientLike;
366364
}
367365

368366
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
@@ -944,11 +944,16 @@ describe("DatabricksAdapter.fromModelServing", () => {
944944
test("reads endpoint from DATABRICKS_SERVING_ENDPOINT_NAME env var", async () => {
945945
process.env.DATABRICKS_SERVING_ENDPOINT_NAME = "my-model";
946946

947-
vi.mock("@databricks/sdk-experimental", () => ({
948-
WorkspaceClient: vi.fn().mockImplementation(() => ({
949-
apiClient: { request: vi.fn() },
950-
})),
951-
}));
947+
vi.mock("../../workspace-client", async (importOriginal) => {
948+
const actual =
949+
await importOriginal<typeof import("../../workspace-client")>();
950+
return {
951+
...actual,
952+
createWorkspaceClient: vi.fn().mockImplementation(() => ({
953+
apiClient: { request: vi.fn() },
954+
})),
955+
};
956+
});
952957

953958
const adapter = await DatabricksAdapter.fromModelServing();
954959
expect(adapter).toBeInstanceOf(DatabricksAdapter);

0 commit comments

Comments
 (0)