@databricks/appkit-ui 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +10 -0
- package/NOTICE.md +1 -0
- package/dist/cli/commands/generate-types.js +15 -13
- package/dist/cli/commands/generate-types.js.map +1 -1
- package/dist/react/hooks/index.d.ts +4 -2
- package/dist/react/hooks/index.js +2 -0
- package/dist/react/hooks/types.d.ts +30 -1
- package/dist/react/hooks/types.d.ts.map +1 -1
- package/dist/react/hooks/use-serving-invoke.d.ts +30 -0
- package/dist/react/hooks/use-serving-invoke.d.ts.map +1 -0
- package/dist/react/hooks/use-serving-invoke.js +82 -0
- package/dist/react/hooks/use-serving-invoke.js.map +1 -0
- package/dist/react/hooks/use-serving-stream.d.ts +35 -0
- package/dist/react/hooks/use-serving-stream.d.ts.map +1 -0
- package/dist/react/hooks/use-serving-stream.js +101 -0
- package/dist/react/hooks/use-serving-stream.js.map +1 -0
- package/dist/react/index.d.ts +4 -2
- package/dist/react/index.js +3 -1
- package/docs/api/appkit/Class.Plugin.md +8 -3
- package/docs/api/appkit/Function.appKitServingTypesPlugin.md +24 -0
- package/docs/api/appkit/Function.extractServingEndpoints.md +22 -0
- package/docs/api/appkit/Function.findServerFile.md +20 -0
- package/docs/api/appkit/Interface.EndpointConfig.md +23 -0
- package/docs/api/appkit/Interface.ServingEndpointEntry.md +30 -0
- package/docs/api/appkit/Interface.ServingEndpointRegistry.md +3 -0
- package/docs/api/appkit/TypeAlias.ExecutionResult.md +36 -0
- package/docs/api/appkit/TypeAlias.ServingFactory.md +15 -0
- package/docs/api/appkit.md +39 -31
- package/docs/faq.md +66 -0
- package/docs/plugins/serving.md +223 -0
- package/llms.txt +10 -0
- package/package.json +1 -1
- package/sbom.cdx.json +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Function: appKitServingTypesPlugin()
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
function appKitServingTypesPlugin(options?: AppKitServingTypesPluginOptions): Plugin$1;
|
|
5
|
+
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
Vite plugin to generate TypeScript types for AppKit serving endpoints. Fetches OpenAPI schemas from Databricks and generates a .d.ts with ServingEndpointRegistry module augmentation.
|
|
9
|
+
|
|
10
|
+
Endpoint discovery order:
|
|
11
|
+
|
|
12
|
+
1. Explicit `endpoints` option (override)
|
|
13
|
+
2. AST extraction from server file (server/index.ts or server/server.ts)
|
|
14
|
+
3. DATABRICKS\_SERVING\_ENDPOINT\_NAME env var (single default endpoint)
|
|
15
|
+
|
|
16
|
+
## Parameters[](#parameters "Direct link to Parameters")
|
|
17
|
+
|
|
18
|
+
| Parameter | Type |
|
|
19
|
+
| ---------- | --------------------------------- |
|
|
20
|
+
| `options?` | `AppKitServingTypesPluginOptions` |
|
|
21
|
+
|
|
22
|
+
## Returns[](#returns "Direct link to Returns")
|
|
23
|
+
|
|
24
|
+
`Plugin$1`
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Function: extractServingEndpoints()
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
function extractServingEndpoints(serverFilePath: string):
|
|
5
|
+
| Record<string, EndpointConfig>
|
|
6
|
+
| null;
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Extract serving endpoint config from a server file by AST-parsing it. Looks for `serving({ endpoints: { alias: { env: "..." }, ... } })` calls and extracts the endpoint alias names and their environment variable mappings.
|
|
11
|
+
|
|
12
|
+
## Parameters[](#parameters "Direct link to Parameters")
|
|
13
|
+
|
|
14
|
+
| Parameter | Type | Description |
|
|
15
|
+
| ---------------- | -------- | -------------------------------------- |
|
|
16
|
+
| `serverFilePath` | `string` | Absolute path to the server entry file |
|
|
17
|
+
|
|
18
|
+
## Returns[](#returns "Direct link to Returns")
|
|
19
|
+
|
|
20
|
+
\| `Record`<`string`, [`EndpointConfig`](./docs/api/appkit/Interface.EndpointConfig.md)> | `null`
|
|
21
|
+
|
|
22
|
+
Extracted endpoint config, or null if not found or not extractable
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Function: findServerFile()
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
function findServerFile(basePath: string): string | null;
|
|
5
|
+
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
Find the server entry file by checking candidate paths in order.
|
|
9
|
+
|
|
10
|
+
## Parameters[](#parameters "Direct link to Parameters")
|
|
11
|
+
|
|
12
|
+
| Parameter | Type | Description |
|
|
13
|
+
| ---------- | -------- | ------------------------------------- |
|
|
14
|
+
| `basePath` | `string` | Project root directory to search from |
|
|
15
|
+
|
|
16
|
+
## Returns[](#returns "Direct link to Returns")
|
|
17
|
+
|
|
18
|
+
`string` | `null`
|
|
19
|
+
|
|
20
|
+
Absolute path to the server file, or null if none found
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Interface: EndpointConfig
|
|
2
|
+
|
|
3
|
+
## Properties[](#properties "Direct link to Properties")
|
|
4
|
+
|
|
5
|
+
### env[](#env "Direct link to env")
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
env: string;
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Environment variable holding the endpoint name.
|
|
13
|
+
|
|
14
|
+
***
|
|
15
|
+
|
|
16
|
+
### servedModel?[](#servedmodel "Direct link to servedModel?")
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
optional servedModel: string;
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Target a specific served model (bypasses traffic routing).
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Interface: ServingEndpointEntry
|
|
2
|
+
|
|
3
|
+
Shape of a single registry entry.
|
|
4
|
+
|
|
5
|
+
## Properties[](#properties "Direct link to Properties")
|
|
6
|
+
|
|
7
|
+
### chunk[](#chunk "Direct link to chunk")
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
chunk: unknown;
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
***
|
|
15
|
+
|
|
16
|
+
### request[](#request "Direct link to request")
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
request: Record<string, unknown>;
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
***
|
|
24
|
+
|
|
25
|
+
### response[](#response "Direct link to response")
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
response: unknown;
|
|
29
|
+
|
|
30
|
+
```
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# Interface: ServingEndpointRegistry
|
|
2
|
+
|
|
3
|
+
Registry interface for serving endpoint type generation. Empty by default — augmented by the Vite type generator's `.d.ts` output via module augmentation. When populated, provides autocomplete for alias names and typed request/response/chunk per endpoint.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Type Alias: ExecutionResult\<T>
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
type ExecutionResult<T> =
|
|
5
|
+
| {
|
|
6
|
+
data: T;
|
|
7
|
+
ok: true;
|
|
8
|
+
}
|
|
9
|
+
| {
|
|
10
|
+
message: string;
|
|
11
|
+
ok: false;
|
|
12
|
+
status: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Discriminated union for plugin execution results.
|
|
18
|
+
|
|
19
|
+
Replaces the previous `T | undefined` return type on `execute()`.
|
|
20
|
+
|
|
21
|
+
On failure, the HTTP status code is preserved from:
|
|
22
|
+
|
|
23
|
+
* `AppKitError` subclasses (via `statusCode`)
|
|
24
|
+
* Any `Error` with a numeric `statusCode` property (e.g. `ApiError`)
|
|
25
|
+
* All other errors default to status 500
|
|
26
|
+
|
|
27
|
+
In production, error messages from non-AppKitError sources are handled as:
|
|
28
|
+
|
|
29
|
+
* 4xx errors: original message is preserved (client-facing by design)
|
|
30
|
+
* 5xx errors: replaced with "Server error" to prevent information leakage
|
|
31
|
+
|
|
32
|
+
## Type Parameters[](#type-parameters "Direct link to Type Parameters")
|
|
33
|
+
|
|
34
|
+
| Type Parameter |
|
|
35
|
+
| -------------- |
|
|
36
|
+
| `T` |
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Type Alias: ServingFactory
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
type ServingFactory = keyof ServingEndpointRegistry extends never ? (alias?: string) => ServingEndpointHandle : <K>(alias: K) => ServingEndpointHandle<ServingEndpointRegistry[K]["request"], ServingEndpointRegistry[K]["response"]>;
|
|
5
|
+
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
Factory function returned by `AppKit.serving`.
|
|
9
|
+
|
|
10
|
+
This is a conditional type that adapts based on whether `ServingEndpointRegistry` has been populated via module augmentation (generated by `appKitServingTypesPlugin()`):
|
|
11
|
+
|
|
12
|
+
* **Registry empty (default):** `(alias?: string) => ServingEndpointHandle` — accepts any alias string with untyped request/response.
|
|
13
|
+
* **Registry populated:** `<K>(alias: K) => ServingEndpointHandle<...>` — restricts `alias` to known endpoint keys and infers typed request/response from the registry entry.
|
|
14
|
+
|
|
15
|
+
Run `appKitServingTypesPlugin()` in your Vite config to generate the registry augmentation and enable full type safety.
|
package/docs/api/appkit.md
CHANGED
|
@@ -27,32 +27,37 @@ Core library for building Databricks applications with type-safe SQL queries, pl
|
|
|
27
27
|
|
|
28
28
|
## Interfaces[](#interfaces "Direct link to Interfaces")
|
|
29
29
|
|
|
30
|
-
| Interface | Description
|
|
31
|
-
| ----------------------------------------------------------------------------------------------------------- |
|
|
32
|
-
| [BasePluginConfig](./docs/api/appkit/Interface.BasePluginConfig.md) | Base configuration interface for AppKit plugins
|
|
33
|
-
| [CacheConfig](./docs/api/appkit/Interface.CacheConfig.md) | Configuration for the CacheInterceptor. Controls TTL, size limits, storage backend, and probabilistic cleanup.
|
|
34
|
-
| [DatabaseCredential](./docs/api/appkit/Interface.DatabaseCredential.md) | Database credentials with OAuth token for Postgres connection
|
|
35
|
-
| [
|
|
36
|
-
| [
|
|
37
|
-
| [
|
|
38
|
-
| [
|
|
39
|
-
| [
|
|
40
|
-
| [
|
|
41
|
-
| [
|
|
42
|
-
| [
|
|
43
|
-
| [
|
|
44
|
-
| [
|
|
45
|
-
| [
|
|
46
|
-
| [
|
|
30
|
+
| Interface | Description |
|
|
31
|
+
| ----------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
32
|
+
| [BasePluginConfig](./docs/api/appkit/Interface.BasePluginConfig.md) | Base configuration interface for AppKit plugins |
|
|
33
|
+
| [CacheConfig](./docs/api/appkit/Interface.CacheConfig.md) | Configuration for the CacheInterceptor. Controls TTL, size limits, storage backend, and probabilistic cleanup. |
|
|
34
|
+
| [DatabaseCredential](./docs/api/appkit/Interface.DatabaseCredential.md) | Database credentials with OAuth token for Postgres connection |
|
|
35
|
+
| [EndpointConfig](./docs/api/appkit/Interface.EndpointConfig.md) | - |
|
|
36
|
+
| [GenerateDatabaseCredentialRequest](./docs/api/appkit/Interface.GenerateDatabaseCredentialRequest.md) | Request parameters for generating database OAuth credentials |
|
|
37
|
+
| [ITelemetry](./docs/api/appkit/Interface.ITelemetry.md) | Plugin-facing interface for OpenTelemetry instrumentation. Provides a thin abstraction over OpenTelemetry APIs for plugins. |
|
|
38
|
+
| [LakebasePoolConfig](./docs/api/appkit/Interface.LakebasePoolConfig.md) | Configuration for creating a Lakebase connection pool |
|
|
39
|
+
| [PluginManifest](./docs/api/appkit/Interface.PluginManifest.md) | Plugin manifest that declares metadata and resource requirements. Attached to plugin classes as a static property. Extends the shared PluginManifest with strict resource types. |
|
|
40
|
+
| [RequestedClaims](./docs/api/appkit/Interface.RequestedClaims.md) | Optional claims for fine-grained Unity Catalog table permissions When specified, the returned token will be scoped to only the requested tables |
|
|
41
|
+
| [RequestedResource](./docs/api/appkit/Interface.RequestedResource.md) | Resource to request permissions for in Unity Catalog |
|
|
42
|
+
| [ResourceEntry](./docs/api/appkit/Interface.ResourceEntry.md) | Internal representation of a resource in the registry. Extends ResourceRequirement with resolution state and plugin ownership. |
|
|
43
|
+
| [ResourceFieldEntry](./docs/api/appkit/Interface.ResourceFieldEntry.md) | Defines a single field for a resource. Each field has its own environment variable and optional description. Single-value types use one key (e.g. id); multi-value types (database, secret) use multiple (e.g. instance\_name, database\_name or scope, key). |
|
|
44
|
+
| [ResourceRequirement](./docs/api/appkit/Interface.ResourceRequirement.md) | Declares a resource requirement for a plugin. Can be defined statically in a manifest or dynamically via getResourceRequirements(). Narrows the generated base: type → ResourceType enum, permission → ResourcePermission union. |
|
|
45
|
+
| [ServingEndpointEntry](./docs/api/appkit/Interface.ServingEndpointEntry.md) | Shape of a single registry entry. |
|
|
46
|
+
| [ServingEndpointRegistry](./docs/api/appkit/Interface.ServingEndpointRegistry.md) | Registry interface for serving endpoint type generation. Empty by default — augmented by the Vite type generator's `.d.ts` output via module augmentation. When populated, provides autocomplete for alias names and typed request/response/chunk per endpoint. |
|
|
47
|
+
| [StreamExecutionSettings](./docs/api/appkit/Interface.StreamExecutionSettings.md) | Execution settings for streaming endpoints. Extends PluginExecutionSettings with SSE stream configuration. |
|
|
48
|
+
| [TelemetryConfig](./docs/api/appkit/Interface.TelemetryConfig.md) | OpenTelemetry configuration for AppKit applications |
|
|
49
|
+
| [ValidationResult](./docs/api/appkit/Interface.ValidationResult.md) | Result of validating all registered resources against the environment. |
|
|
47
50
|
|
|
48
51
|
## Type Aliases[](#type-aliases "Direct link to Type Aliases")
|
|
49
52
|
|
|
50
53
|
| Type Alias | Description |
|
|
51
54
|
| ----------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
|
|
52
55
|
| [ConfigSchema](./docs/api/appkit/TypeAlias.ConfigSchema.md) | Configuration schema definition for plugin config. Re-exported from the standard JSON Schema Draft 7 types. |
|
|
56
|
+
| [ExecutionResult](./docs/api/appkit/TypeAlias.ExecutionResult.md) | Discriminated union for plugin execution results. |
|
|
53
57
|
| [IAppRouter](./docs/api/appkit/TypeAlias.IAppRouter.md) | Express router type for plugin route registration |
|
|
54
58
|
| [PluginData](./docs/api/appkit/TypeAlias.PluginData.md) | Tuple of plugin class, config, and name. Created by `toPlugin()` and passed to `createApp()`. |
|
|
55
59
|
| [ResourcePermission](./docs/api/appkit/TypeAlias.ResourcePermission.md) | Union of all possible permission levels across all resource types. |
|
|
60
|
+
| [ServingFactory](./docs/api/appkit/TypeAlias.ServingFactory.md) | Factory function returned by `AppKit.serving`. |
|
|
56
61
|
| [ToPlugin](./docs/api/appkit/TypeAlias.ToPlugin.md) | Factory function type returned by `toPlugin()`. Accepts optional config and returns a PluginData tuple. |
|
|
57
62
|
|
|
58
63
|
## Variables[](#variables "Direct link to Variables")
|
|
@@ -63,17 +68,20 @@ Core library for building Databricks applications with type-safe SQL queries, pl
|
|
|
63
68
|
|
|
64
69
|
## Functions[](#functions "Direct link to Functions")
|
|
65
70
|
|
|
66
|
-
| Function | Description
|
|
67
|
-
| -------------------------------------------------------------------------------------------- |
|
|
68
|
-
| [
|
|
69
|
-
| [
|
|
70
|
-
| [
|
|
71
|
-
| [
|
|
72
|
-
| [
|
|
73
|
-
| [
|
|
74
|
-
| [
|
|
75
|
-
| [
|
|
76
|
-
| [
|
|
77
|
-
| [
|
|
78
|
-
| [
|
|
79
|
-
| [
|
|
71
|
+
| Function | Description |
|
|
72
|
+
| -------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
73
|
+
| [appKitServingTypesPlugin](./docs/api/appkit/Function.appKitServingTypesPlugin.md) | Vite plugin to generate TypeScript types for AppKit serving endpoints. Fetches OpenAPI schemas from Databricks and generates a .d.ts with ServingEndpointRegistry module augmentation. |
|
|
74
|
+
| [appKitTypesPlugin](./docs/api/appkit/Function.appKitTypesPlugin.md) | Vite plugin to generate types for AppKit queries. Calls generateFromEntryPoint under the hood. |
|
|
75
|
+
| [createApp](./docs/api/appkit/Function.createApp.md) | Bootstraps AppKit with the provided configuration. |
|
|
76
|
+
| [createLakebasePool](./docs/api/appkit/Function.createLakebasePool.md) | Create a Lakebase pool with appkit's logger integration. Telemetry automatically uses appkit's OpenTelemetry configuration via global registry. |
|
|
77
|
+
| [extractServingEndpoints](./docs/api/appkit/Function.extractServingEndpoints.md) | Extract serving endpoint config from a server file by AST-parsing it. Looks for `serving({ endpoints: { alias: { env: "..." }, ... } })` calls and extracts the endpoint alias names and their environment variable mappings. |
|
|
78
|
+
| [findServerFile](./docs/api/appkit/Function.findServerFile.md) | Find the server entry file by checking candidate paths in order. |
|
|
79
|
+
| [generateDatabaseCredential](./docs/api/appkit/Function.generateDatabaseCredential.md) | Generate OAuth credentials for Postgres database connection using the proper Postgres API. |
|
|
80
|
+
| [getExecutionContext](./docs/api/appkit/Function.getExecutionContext.md) | Get the current execution context. |
|
|
81
|
+
| [getLakebaseOrmConfig](./docs/api/appkit/Function.getLakebaseOrmConfig.md) | Get Lakebase connection configuration for ORMs that don't accept pg.Pool directly. |
|
|
82
|
+
| [getLakebasePgConfig](./docs/api/appkit/Function.getLakebasePgConfig.md) | Get Lakebase connection configuration for PostgreSQL clients. |
|
|
83
|
+
| [getPluginManifest](./docs/api/appkit/Function.getPluginManifest.md) | Loads and validates the manifest from a plugin constructor. Normalizes string type/permission to strict ResourceType/ResourcePermission. |
|
|
84
|
+
| [getResourceRequirements](./docs/api/appkit/Function.getResourceRequirements.md) | Gets the resource requirements from a plugin's manifest. |
|
|
85
|
+
| [getUsernameWithApiLookup](./docs/api/appkit/Function.getUsernameWithApiLookup.md) | Resolves the PostgreSQL username for a Lakebase connection. |
|
|
86
|
+
| [getWorkspaceClient](./docs/api/appkit/Function.getWorkspaceClient.md) | Get workspace client from config or SDK default auth chain |
|
|
87
|
+
| [isSQLTypeMarker](./docs/api/appkit/Function.isSQLTypeMarker.md) | Type guard to check if a value is a SQL type marker |
|
package/docs/faq.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# FAQ
|
|
2
|
+
|
|
3
|
+
## Integrations[](#integrations "Direct link to Integrations")
|
|
4
|
+
|
|
5
|
+
### What Databricks services are available through AppKit?[](#what-databricks-services-are-available-through-appkit "Direct link to What Databricks services are available through AppKit?")
|
|
6
|
+
|
|
7
|
+
AppKit provides built-in integrations with the following Databricks services via its [plugin system](./docs/plugins.md):
|
|
8
|
+
|
|
9
|
+
| Plugin | Databricks Service | What It Does |
|
|
10
|
+
| ---------------------------------------------- | --------------------------------- | --------------------------------------------------------------------------------------- |
|
|
11
|
+
| [Analytics](./docs/plugins/analytics.md) | SQL Warehouses | Execute parameterized SQL queries with built-in caching, retry, and Arrow support |
|
|
12
|
+
| [Lakebase](./docs/plugins/lakebase.md) | Lakebase Autoscaling (PostgreSQL) | Relational database access via standard pg.Pool with automatic OAuth token refresh |
|
|
13
|
+
| [Genie](./docs/plugins/genie.md) | AI/BI Genie Spaces | Natural language data queries with conversation management and streaming |
|
|
14
|
+
| [Files](./docs/plugins/files.md) | Unity Catalog Volumes | Multi-volume file operations (list, read, upload, download, delete, preview) |
|
|
15
|
+
| [Serving](./docs/plugins/serving.md) | Model Serving | Authenticated proxy to Model Serving endpoints with invoke and streaming support |
|
|
16
|
+
| [Server](./docs/plugins/server.md) | N/A | Express HTTP server with static file serving, Vite dev mode, and plugin route injection |
|
|
17
|
+
|
|
18
|
+
Stay tuned for new plugins as we constantly expand integrations!
|
|
19
|
+
|
|
20
|
+
### Can I add custom integrations?[](#can-i-add-custom-integrations "Direct link to Can I add custom integrations?")
|
|
21
|
+
|
|
22
|
+
Yes. AppKit's plugin architecture is extensible - you can create custom plugins using the CLI (`npx appkit plugin create`) or manually. See the [creating custom plugins guide](./docs/plugins/custom-plugins.md).
|
|
23
|
+
|
|
24
|
+
## Authentication[](#authentication "Direct link to Authentication")
|
|
25
|
+
|
|
26
|
+
### How does authentication work in AppKit apps?[](#how-does-authentication-work-in-appkit-apps "Direct link to How does authentication work in AppKit apps?")
|
|
27
|
+
|
|
28
|
+
AppKit apps are designed to run on [Databricks Apps](https://docs.databricks.com/aws/en/dev-tools/databricks-apps/), which handles user authentication and authorization. Databricks Apps forwards user identity to the app via request headers, and AppKit integrates with this through the `.asUser(req)` pattern for on-behalf-of (OBO) execution — allowing plugins to act on behalf of the authenticated user.
|
|
29
|
+
|
|
30
|
+
For details on how authentication and authorization work in Databricks Apps, see the [official auth documentation](https://docs.databricks.com/aws/en/dev-tools/databricks-apps/auth).
|
|
31
|
+
|
|
32
|
+
## Databases[](#databases "Direct link to Databases")
|
|
33
|
+
|
|
34
|
+
*Also: Lakebase, PostgreSQL, OLTP*
|
|
35
|
+
|
|
36
|
+
### How does AppKit handle databases?[](#how-does-appkit-handle-databases "Direct link to How does AppKit handle databases?")
|
|
37
|
+
|
|
38
|
+
AppKit is a TypeScript SDK (Express + React) and does not manage databases directly.
|
|
39
|
+
|
|
40
|
+
To add database support, use the [Lakebase plugin](./docs/plugins/lakebase.md), which integrates with Lakebase Autoscaling.
|
|
41
|
+
|
|
42
|
+
AppKit also uses Lakebase for caching when it is available (see the [caching](#does-appkit-support-caching) section below).
|
|
43
|
+
|
|
44
|
+
You can manage Lakebase Autoscaling projects and branches using the dedicated agent skill from [Databricks Agent Skills](./docs/development/ai-assisted-development.md), installed with the Databricks CLI.
|
|
45
|
+
|
|
46
|
+
### How does database setup and permission management work in AppKit?[](#how-does-database-setup-and-permission-management-work-in-appkit "Direct link to How does database setup and permission management work in AppKit?")
|
|
47
|
+
|
|
48
|
+
AppKit apps can have an attached Lakebase Autoscaling instance. No database is bundled by default - you add one by configuring the [Lakebase plugin](./docs/plugins/lakebase.md). When running `databricks apps init` and selecting the Lakebase plugin, the selected database is automatically attached as an app resource after deployment.
|
|
49
|
+
|
|
50
|
+
With [AI-assisted development](./docs/development/ai-assisted-development.md), you can also ask the Agent to create a Lakebase project and branch for you.
|
|
51
|
+
|
|
52
|
+
When deployed, a Databricks app uses its Service Principal for schema and table creation. If you configure the Lakebase Autoscaling project as an [app resource](https://docs.databricks.com/aws/en/dev-tools/databricks-apps/resources), the necessary connect and create permissions are granted automatically to the app's Service Principal.
|
|
53
|
+
|
|
54
|
+
### Does AppKit support Lakebase Provisioned?[](#does-appkit-support-lakebase-provisioned "Direct link to Does AppKit support Lakebase Provisioned?")
|
|
55
|
+
|
|
56
|
+
No. AppKit only supports Lakebase Autoscaling. Lakebase Provisioned databases are not supported by the [Lakebase plugin](./docs/plugins/lakebase.md) or Lakebase agent skill from [Databricks Agent Skills](./docs/development/ai-assisted-development.md).
|
|
57
|
+
|
|
58
|
+
## Caching[](#caching "Direct link to Caching")
|
|
59
|
+
|
|
60
|
+
### Does AppKit support caching?[](#does-appkit-support-caching "Direct link to Does AppKit support caching?")
|
|
61
|
+
|
|
62
|
+
Yes. The [Analytics plugin](./docs/plugins/analytics.md) - used for executing SQL queries against Databricks SQL Warehouses - supports an optional cache layer.
|
|
63
|
+
|
|
64
|
+
Caching is configured per plugin and can use either [Lakebase Autoscaling](https://docs.databricks.com/aws/en/oltp/) or an in-memory store, depending on the configuration.
|
|
65
|
+
|
|
66
|
+
If the Lakebase Autoscaling connection is configured, the AppKit-based app creates an `appkit` schema in the configured database with internal tables required for caching.
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
# Serving plugin
|
|
2
|
+
|
|
3
|
+
Provides an authenticated proxy to [Databricks Model Serving](https://docs.databricks.com/aws/en/machine-learning/model-serving) endpoints, with invoke and streaming support.
|
|
4
|
+
|
|
5
|
+
**Key features:**
|
|
6
|
+
|
|
7
|
+
* Named endpoint aliases for multiple serving endpoints
|
|
8
|
+
* Non-streaming (`invoke`) and SSE streaming (`stream`) invocation
|
|
9
|
+
* Automatic OpenAPI type generation for request/response schemas
|
|
10
|
+
* Request body filtering based on endpoint schema
|
|
11
|
+
* On-behalf-of (OBO) user execution
|
|
12
|
+
|
|
13
|
+
## Basic usage[](#basic-usage "Direct link to Basic usage")
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createApp, server, serving } from "@databricks/appkit";
|
|
17
|
+
|
|
18
|
+
await createApp({
|
|
19
|
+
plugins: [
|
|
20
|
+
server(),
|
|
21
|
+
serving(),
|
|
22
|
+
],
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
With no configuration, the plugin reads `DATABRICKS_SERVING_ENDPOINT_NAME` from the environment and registers it under the `default` alias.
|
|
28
|
+
|
|
29
|
+
## Configuration options[](#configuration-options "Direct link to Configuration options")
|
|
30
|
+
|
|
31
|
+
| Option | Type | Default | Description |
|
|
32
|
+
| ----------- | -------------------------------- | ---------------------------------------------------------- | -------------------------------------- |
|
|
33
|
+
| `endpoints` | `Record<string, EndpointConfig>` | `{ default: { env: "DATABRICKS_SERVING_ENDPOINT_NAME" } }` | Map of alias names to endpoint configs |
|
|
34
|
+
| `timeout` | `number` | `120000` | Request timeout in ms |
|
|
35
|
+
|
|
36
|
+
### Endpoint aliases[](#endpoint-aliases "Direct link to Endpoint aliases")
|
|
37
|
+
|
|
38
|
+
Endpoint aliases let you reference multiple serving endpoints by name:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
serving({
|
|
42
|
+
endpoints: {
|
|
43
|
+
llm: { env: "DATABRICKS_SERVING_ENDPOINT_NAME" },
|
|
44
|
+
classifier: { env: "DATABRICKS_SERVING_ENDPOINT_CLASSIFIER" },
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Each alias maps to an environment variable holding the actual endpoint name. If an endpoint serves multiple models, you can use `servedModel` to bypass traffic routing and target a specific model directly:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
serving({
|
|
54
|
+
endpoints: {
|
|
55
|
+
llm: { env: "DATABRICKS_SERVING_ENDPOINT_NAME", servedModel: "llama-v2" },
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Type generation[](#type-generation "Direct link to Type generation")
|
|
62
|
+
|
|
63
|
+
The `appKitServingTypesPlugin()` Vite plugin generates TypeScript types from your serving endpoints' OpenAPI schemas. **No manual setup needed** — the AppKit dev server includes this plugin automatically.
|
|
64
|
+
|
|
65
|
+
The plugin auto-discovers endpoint configuration from your server file (`server/index.ts` or `server/server.ts`).
|
|
66
|
+
|
|
67
|
+
Generated types provide:
|
|
68
|
+
|
|
69
|
+
* **Alias autocomplete** in both backend (`AppKit.serving("alias")`) and frontend hooks (`useServingStream`, `useServingInvoke`)
|
|
70
|
+
* **Typed request/response/chunk** per endpoint based on OpenAPI schemas
|
|
71
|
+
|
|
72
|
+
If an endpoint's OpenAPI schema is unavailable (not deployed, env var not set), the plugin generates generic fallback types. The endpoint is still usable — just without typed request/response.
|
|
73
|
+
|
|
74
|
+
note
|
|
75
|
+
|
|
76
|
+
Endpoints that don't define a streaming response schema in their OpenAPI spec will have `chunk: unknown`. For these endpoints, use `useServingInvoke` instead of `useServingStream` — the `response` type will still be properly typed.
|
|
77
|
+
|
|
78
|
+
## Environment variables[](#environment-variables "Direct link to Environment variables")
|
|
79
|
+
|
|
80
|
+
| Variable | Description |
|
|
81
|
+
| ---------------------------------- | --------------------------------------------------------------- |
|
|
82
|
+
| `DATABRICKS_SERVING_ENDPOINT_NAME` | Default endpoint name (used when `endpoints` config is omitted) |
|
|
83
|
+
|
|
84
|
+
When using named endpoints, define a custom environment variable per alias (e.g. `DATABRICKS_SERVING_ENDPOINT_CLASSIFIER`).
|
|
85
|
+
|
|
86
|
+
## Execution context[](#execution-context "Direct link to Execution context")
|
|
87
|
+
|
|
88
|
+
All serving routes execute on behalf of the authenticated user (OBO) by default, consistent with the Genie and Files plugins. This ensures per-user `CAN_QUERY` permissions are enforced on the serving endpoint.
|
|
89
|
+
|
|
90
|
+
For programmatic access via `exports()`, use `.asUser(req)` to run in user context:
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
// Service principal context (default)
|
|
94
|
+
const result = await AppKit.serving("llm").invoke({ messages });
|
|
95
|
+
|
|
96
|
+
// User context (recommended in route handlers)
|
|
97
|
+
const result = await AppKit.serving("llm").asUser(req).invoke({ messages });
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## HTTP endpoints[](#http-endpoints "Direct link to HTTP endpoints")
|
|
102
|
+
|
|
103
|
+
### Named mode (with `endpoints` config)[](#named-mode-with-endpoints-config "Direct link to named-mode-with-endpoints-config")
|
|
104
|
+
|
|
105
|
+
* `POST /api/serving/:alias/invoke` — Non-streaming invocation
|
|
106
|
+
* `POST /api/serving/:alias/stream` — SSE streaming invocation
|
|
107
|
+
|
|
108
|
+
### Default mode (no `endpoints` config)[](#default-mode-no-endpoints-config "Direct link to default-mode-no-endpoints-config")
|
|
109
|
+
|
|
110
|
+
* `POST /api/serving/invoke` — Non-streaming invocation
|
|
111
|
+
* `POST /api/serving/stream` — SSE streaming invocation
|
|
112
|
+
|
|
113
|
+
### Request format[](#request-format "Direct link to Request format")
|
|
114
|
+
|
|
115
|
+
```text
|
|
116
|
+
POST /api/serving/:alias/invoke
|
|
117
|
+
Content-Type: application/json
|
|
118
|
+
|
|
119
|
+
{
|
|
120
|
+
"messages": [
|
|
121
|
+
{ "role": "user", "content": "Hello" }
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Programmatic access[](#programmatic-access "Direct link to Programmatic access")
|
|
128
|
+
|
|
129
|
+
The plugin exports `invoke` and `stream` methods for server-side use:
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
const AppKit = await createApp({
|
|
133
|
+
plugins: [
|
|
134
|
+
server(),
|
|
135
|
+
serving({
|
|
136
|
+
endpoints: {
|
|
137
|
+
llm: { env: "DATABRICKS_SERVING_ENDPOINT_NAME" },
|
|
138
|
+
},
|
|
139
|
+
}),
|
|
140
|
+
],
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Non-streaming
|
|
144
|
+
const result = await AppKit.serving("llm").invoke({
|
|
145
|
+
messages: [{ role: "user", content: "Hello" }],
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Streaming
|
|
149
|
+
for await (const chunk of AppKit.serving("llm").stream({
|
|
150
|
+
messages: [{ role: "user", content: "Hello" }],
|
|
151
|
+
})) {
|
|
152
|
+
console.log(chunk);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Frontend hooks[](#frontend-hooks "Direct link to Frontend hooks")
|
|
158
|
+
|
|
159
|
+
The `@databricks/appkit-ui` package provides React hooks for serving endpoints:
|
|
160
|
+
|
|
161
|
+
### useServingStream[](#useservingstream "Direct link to useServingStream")
|
|
162
|
+
|
|
163
|
+
Streaming invocation via SSE:
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
import { useServingStream } from "@databricks/appkit-ui/react";
|
|
167
|
+
|
|
168
|
+
function ChatStream() {
|
|
169
|
+
const { stream, chunks, streaming, error, reset } = useServingStream(
|
|
170
|
+
{ messages: [{ role: "user", content: "Hello" }] },
|
|
171
|
+
{
|
|
172
|
+
alias: "llm",
|
|
173
|
+
onComplete: (finalChunks) => {
|
|
174
|
+
// Called with all accumulated chunks when the stream finishes
|
|
175
|
+
console.log("Stream done, got", finalChunks.length, "chunks");
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
return (
|
|
181
|
+
<>
|
|
182
|
+
<button onClick={stream} disabled={streaming}>Send</button>
|
|
183
|
+
<button onClick={reset}>Reset</button>
|
|
184
|
+
{chunks.map((chunk, i) => <pre key={i}>{JSON.stringify(chunk)}</pre>)}
|
|
185
|
+
{error && <p>{error}</p>}
|
|
186
|
+
</>
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### useServingInvoke[](#useservinginvoke "Direct link to useServingInvoke")
|
|
193
|
+
|
|
194
|
+
Non-streaming invocation. `invoke()` returns a promise with the response data (or `null` on error):
|
|
195
|
+
|
|
196
|
+
```tsx
|
|
197
|
+
import { useServingInvoke } from "@databricks/appkit-ui/react";
|
|
198
|
+
|
|
199
|
+
function Classify() {
|
|
200
|
+
const { invoke, data, loading, error } = useServingInvoke(
|
|
201
|
+
{ inputs: ["sample text"] },
|
|
202
|
+
{ alias: "classifier" },
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
async function handleClick() {
|
|
206
|
+
const result = await invoke();
|
|
207
|
+
if (result) {
|
|
208
|
+
console.log("Classification result:", result);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return (
|
|
213
|
+
<>
|
|
214
|
+
<button onClick={handleClick} disabled={loading}>Classify</button>
|
|
215
|
+
{data && <pre>{JSON.stringify(data)}</pre>}
|
|
216
|
+
{error && <p>{error}</p>}
|
|
217
|
+
</>
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Both hooks accept `autoStart: true` to invoke automatically on mount.
|