@fabric-harness/databricks 5.0.1 → 6.0.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/README.md +15 -3
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +753 -353
- package/dist/agent.js.map +1 -1
- package/dist/ai.d.ts +10 -3
- package/dist/ai.d.ts.map +1 -1
- package/dist/app-user-authorization.d.ts +2 -0
- package/dist/app-user-authorization.d.ts.map +1 -1
- package/dist/app-user-authorization.js +8 -4
- package/dist/app-user-authorization.js.map +1 -1
- package/dist/app.d.ts +8 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/asset-bundles.d.ts +56 -6
- package/dist/asset-bundles.d.ts.map +1 -1
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/certify.js +163 -12
- package/dist/certify.js.map +1 -1
- package/dist/compatibility.d.ts +1 -1
- package/dist/compatibility.d.ts.map +1 -1
- package/dist/index.d.ts +45 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +939 -362
- package/dist/index.js.map +1 -1
- package/dist/jobs.d.ts +46 -2
- package/dist/jobs.d.ts.map +1 -1
- package/dist/lakeflow.d.ts +14 -7
- package/dist/lakeflow.d.ts.map +1 -1
- package/dist/persistence.d.ts +13 -2
- package/dist/persistence.d.ts.map +1 -1
- package/dist/resource-policy.d.ts +9 -0
- package/dist/resource-policy.d.ts.map +1 -0
- package/dist/tools.d.ts +40 -9
- package/dist/tools.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -2267,6 +2267,39 @@ function jitter(ms) {
|
|
|
2267
2267
|
return Math.max(1, Math.round(ms * (0.9 + Math.random() * 0.2)));
|
|
2268
2268
|
}
|
|
2269
2269
|
|
|
2270
|
+
// src/resource-policy.ts
|
|
2271
|
+
var DatabricksResourceNotAllowedError = class extends Error {
|
|
2272
|
+
code = "DATABRICKS_RESOURCE_NOT_ALLOWED";
|
|
2273
|
+
resourceKind;
|
|
2274
|
+
constructor(resourceKind) {
|
|
2275
|
+
super(`Databricks ${resourceKind} is not allowed by the configured policy.`);
|
|
2276
|
+
this.name = "DatabricksResourceNotAllowedError";
|
|
2277
|
+
this.resourceKind = resourceKind;
|
|
2278
|
+
}
|
|
2279
|
+
};
|
|
2280
|
+
function resolveExactResourcePolicy(policy, allowedKey, allowAnyKey, resourceKind) {
|
|
2281
|
+
if (!policy || typeof policy !== "object" || Array.isArray(policy))
|
|
2282
|
+
throw new TypeError(`Databricks ${resourceKind} policy must be an object.`);
|
|
2283
|
+
const value = policy;
|
|
2284
|
+
const allowed = value[allowedKey];
|
|
2285
|
+
const allowAny = value[allowAnyKey];
|
|
2286
|
+
if (allowAny === true && allowed === void 0) return void 0;
|
|
2287
|
+
if (Array.isArray(allowed) && allowed.length > 0 && allowed.every((entry) => typeof entry === "string" && entry.trim().length > 0) && allowAny === void 0)
|
|
2288
|
+
return [...new Set(allowed.map((entry) => entry.trim()))];
|
|
2289
|
+
throw new TypeError(
|
|
2290
|
+
`Databricks ${resourceKind} policy must set either non-empty ${allowedKey} or ${allowAnyKey}: true.`
|
|
2291
|
+
);
|
|
2292
|
+
}
|
|
2293
|
+
function assertExactResourceAllowed(resourceKind, value, allowed) {
|
|
2294
|
+
if (allowed && !allowed.includes(value.trim()))
|
|
2295
|
+
throw new DatabricksResourceNotAllowedError(resourceKind);
|
|
2296
|
+
}
|
|
2297
|
+
function pinnedStringResourceSchema(allowed) {
|
|
2298
|
+
if (!allowed) return { type: "string" };
|
|
2299
|
+
if (allowed.length === 1) return { type: "string", const: allowed[0] };
|
|
2300
|
+
return { type: "string", enum: [...allowed] };
|
|
2301
|
+
}
|
|
2302
|
+
|
|
2270
2303
|
// src/sql-exec.ts
|
|
2271
2304
|
var TERMINAL_STATES = /* @__PURE__ */ new Set(["SUCCEEDED", "FAILED", "CANCELED", "CLOSED"]);
|
|
2272
2305
|
async function runStatement(client, warehouseId, statement, parameters, poll) {
|
|
@@ -2303,25 +2336,53 @@ function parseStatementRows(response) {
|
|
|
2303
2336
|
}
|
|
2304
2337
|
|
|
2305
2338
|
// src/ai.ts
|
|
2306
|
-
function databricksAiQueryTool(client, options) {
|
|
2307
|
-
const poll = {
|
|
2339
|
+
function databricksAiQueryTool(client, endpointPolicy, options) {
|
|
2340
|
+
const poll = {
|
|
2341
|
+
intervalMs: options.pollIntervalMs ?? 2e3,
|
|
2342
|
+
timeoutMs: options.timeoutMs ?? 12e4
|
|
2343
|
+
};
|
|
2344
|
+
const allowedEndpoints = resolveExactResourcePolicy(
|
|
2345
|
+
endpointPolicy,
|
|
2346
|
+
"allowedEndpoints",
|
|
2347
|
+
"allowAnyEndpoint",
|
|
2348
|
+
"AI Functions endpoint"
|
|
2349
|
+
);
|
|
2308
2350
|
return {
|
|
2309
2351
|
name: options.name ?? "databricks_ai_query",
|
|
2310
2352
|
description: options.description ?? "Run model inference inside the SQL warehouse via ai_query() against a Databricks serving endpoint.",
|
|
2311
2353
|
inputSchema: {
|
|
2312
2354
|
type: "object",
|
|
2313
2355
|
additionalProperties: false,
|
|
2314
|
-
properties: {
|
|
2356
|
+
properties: {
|
|
2357
|
+
endpoint: pinnedStringResourceSchema(allowedEndpoints),
|
|
2358
|
+
request: { type: "string" }
|
|
2359
|
+
},
|
|
2315
2360
|
required: ["endpoint", "request"]
|
|
2316
2361
|
},
|
|
2317
|
-
metadata: {
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2362
|
+
metadata: {
|
|
2363
|
+
effect: "execute",
|
|
2364
|
+
provider: "databricks",
|
|
2365
|
+
service: "ai-functions",
|
|
2366
|
+
governance: {
|
|
2367
|
+
resources: [
|
|
2368
|
+
{ kind: "serving-endpoint", path: "/endpoint" },
|
|
2369
|
+
{ kind: "sql-warehouse", value: options.warehouseId }
|
|
2370
|
+
]
|
|
2371
|
+
}
|
|
2372
|
+
},
|
|
2373
|
+
async execute(input) {
|
|
2374
|
+
assertExactResourceAllowed("AI Functions endpoint", input.endpoint, allowedEndpoints);
|
|
2375
|
+
return await runStatement(
|
|
2376
|
+
client,
|
|
2377
|
+
options.warehouseId,
|
|
2378
|
+
"SELECT ai_query(:endpoint, :request) AS result",
|
|
2379
|
+
[
|
|
2380
|
+
{ name: "endpoint", value: input.endpoint },
|
|
2381
|
+
{ name: "request", value: input.request }
|
|
2382
|
+
],
|
|
2383
|
+
poll
|
|
2384
|
+
);
|
|
2385
|
+
}
|
|
2325
2386
|
};
|
|
2326
2387
|
}
|
|
2327
2388
|
|
|
@@ -2653,9 +2714,12 @@ function canonicalJson(value) {
|
|
|
2653
2714
|
// src/asset-bundles.ts
|
|
2654
2715
|
var BUNDLE_RESOURCE_TYPE = "databricks-bundle";
|
|
2655
2716
|
var FINGERPRINT_EXCLUDED_DIRS = /* @__PURE__ */ new Set([".databricks", "node_modules", "dist"]);
|
|
2717
|
+
var BUNDLE_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
2656
2718
|
var DatabricksAssetBundleLifecycle = class {
|
|
2657
2719
|
/** Resolved bundle directory; also the governed resource identity on the tools. */
|
|
2658
2720
|
bundleDir;
|
|
2721
|
+
/** Logical name of this bundle within a named `assetBundles` map; unset in the single-bundle form. */
|
|
2722
|
+
instanceName;
|
|
2659
2723
|
target;
|
|
2660
2724
|
profile;
|
|
2661
2725
|
executable;
|
|
@@ -2675,6 +2739,7 @@ var DatabricksAssetBundleLifecycle = class {
|
|
|
2675
2739
|
this.principalLabel = options.principalLabel ?? "unknown";
|
|
2676
2740
|
if (options.target !== void 0) this.target = options.target;
|
|
2677
2741
|
if (options.profile !== void 0) this.profile = options.profile;
|
|
2742
|
+
if (options.instanceName !== void 0) this.instanceName = options.instanceName;
|
|
2678
2743
|
}
|
|
2679
2744
|
/** Run `databricks bundle validate` without mutating the workspace. */
|
|
2680
2745
|
async validate() {
|
|
@@ -2752,6 +2817,10 @@ var DatabricksAssetBundleLifecycle = class {
|
|
|
2752
2817
|
key,
|
|
2753
2818
|
"--no-wait",
|
|
2754
2819
|
...options.restart === true ? ["--restart"] : [],
|
|
2820
|
+
"--output",
|
|
2821
|
+
"json",
|
|
2822
|
+
"--progress-format",
|
|
2823
|
+
"json",
|
|
2755
2824
|
...this.targetArgs(),
|
|
2756
2825
|
...this.profileArgs()
|
|
2757
2826
|
];
|
|
@@ -2760,7 +2829,7 @@ var DatabricksAssetBundleLifecycle = class {
|
|
|
2760
2829
|
env: this.env
|
|
2761
2830
|
});
|
|
2762
2831
|
requireSuccess2("Databricks bundle run submission", result);
|
|
2763
|
-
return
|
|
2832
|
+
return parseBundleRunResult(key, result);
|
|
2764
2833
|
}
|
|
2765
2834
|
/** Destroy a Harness-recorded bundle deployment and delete its managed record. */
|
|
2766
2835
|
async destroy(options = {}) {
|
|
@@ -2796,14 +2865,20 @@ var DatabricksAssetBundleLifecycle = class {
|
|
|
2796
2865
|
await this.store.delete(BUNDLE_RESOURCE_TYPE, resourceId);
|
|
2797
2866
|
return { destroyed: true, output: lastNonEmptyLine2(result.stdout) };
|
|
2798
2867
|
}
|
|
2799
|
-
/**
|
|
2868
|
+
/**
|
|
2869
|
+
* Bundle `name:` parsed from `databricks.yml`, falling back to the directory basename. Named
|
|
2870
|
+
* bundles append `#instanceName` (and `#target` when set) so two lifecycles over the same manifest
|
|
2871
|
+
* cannot collide in a shared managed-resource store; the single-bundle form keeps the bare name so
|
|
2872
|
+
* existing records stay addressable.
|
|
2873
|
+
*/
|
|
2800
2874
|
async resourceId() {
|
|
2801
2875
|
if (this.bundleName === void 0) {
|
|
2802
2876
|
const manifest = await readFile(path2.join(this.bundleDir, "databricks.yml"), "utf8");
|
|
2803
2877
|
const match = /^\s*name:\s*["']?([^\s"']+)["']?\s*$/m.exec(manifest);
|
|
2804
2878
|
this.bundleName = match?.[1] ?? path2.basename(this.bundleDir);
|
|
2805
2879
|
}
|
|
2806
|
-
return this.bundleName;
|
|
2880
|
+
if (this.instanceName === void 0) return this.bundleName;
|
|
2881
|
+
return `${this.bundleName}#${this.instanceName}${this.target ? `#${this.target}` : ""}`;
|
|
2807
2882
|
}
|
|
2808
2883
|
async requireManifest() {
|
|
2809
2884
|
const manifest = path2.join(this.bundleDir, "databricks.yml");
|
|
@@ -2823,7 +2898,65 @@ var DatabricksAssetBundleLifecycle = class {
|
|
|
2823
2898
|
function databricksAssetBundleLifecycle(options) {
|
|
2824
2899
|
return new DatabricksAssetBundleLifecycle(options);
|
|
2825
2900
|
}
|
|
2901
|
+
function isDatabricksAssetBundleEntry(value) {
|
|
2902
|
+
if (value instanceof DatabricksAssetBundleLifecycle) return true;
|
|
2903
|
+
return isPlainObject(value) && Object.hasOwn(value, "bundleDir") && typeof value.bundleDir === "string";
|
|
2904
|
+
}
|
|
2905
|
+
function requireDatabricksAssetBundleMap(value) {
|
|
2906
|
+
if (!isPlainObject(value))
|
|
2907
|
+
throw new Error(
|
|
2908
|
+
"databricks asset bundles: named bundles must be an object keyed by bundle name."
|
|
2909
|
+
);
|
|
2910
|
+
}
|
|
2911
|
+
function databricksAssetBundleLifecycles(options, defaults = {}) {
|
|
2912
|
+
requireDatabricksAssetBundleMap(options);
|
|
2913
|
+
const lifecycles = /* @__PURE__ */ new Map();
|
|
2914
|
+
for (const name of Object.keys(options).sort()) {
|
|
2915
|
+
requireBundleName(name);
|
|
2916
|
+
const entry = options[name];
|
|
2917
|
+
if (!isPlainObject(entry) || typeof entry.bundleDir !== "string" || !entry.bundleDir.trim())
|
|
2918
|
+
throw new Error(
|
|
2919
|
+
`databricks asset bundles: bundle "${name}" requires a non-empty bundleDir string.`
|
|
2920
|
+
);
|
|
2921
|
+
lifecycles.set(
|
|
2922
|
+
name,
|
|
2923
|
+
new DatabricksAssetBundleLifecycle({ ...defaults, ...entry, instanceName: name })
|
|
2924
|
+
);
|
|
2925
|
+
}
|
|
2926
|
+
requireNamedBundles(lifecycles);
|
|
2927
|
+
return lifecycles;
|
|
2928
|
+
}
|
|
2826
2929
|
function databricksAssetBundleTools(options) {
|
|
2930
|
+
if (isDatabricksAssetBundleEntry(options)) return singleBundleTools(options);
|
|
2931
|
+
return namedBundleTools(
|
|
2932
|
+
options instanceof Map ? checkedLifecycles(options) : databricksAssetBundleLifecycles(options)
|
|
2933
|
+
);
|
|
2934
|
+
}
|
|
2935
|
+
function checkedLifecycles(lifecycles) {
|
|
2936
|
+
const checked = /* @__PURE__ */ new Map();
|
|
2937
|
+
for (const [name, lifecycle] of lifecycles) {
|
|
2938
|
+
requireBundleName(name);
|
|
2939
|
+
if (!(lifecycle instanceof DatabricksAssetBundleLifecycle))
|
|
2940
|
+
throw new Error(
|
|
2941
|
+
`databricks asset bundles: bundle "${name}" must be a DatabricksAssetBundleLifecycle.`
|
|
2942
|
+
);
|
|
2943
|
+
if (lifecycle.instanceName !== name)
|
|
2944
|
+
throw new Error(
|
|
2945
|
+
`databricks asset bundles: bundle "${name}" must be built with instanceName "${name}"${lifecycle.instanceName === void 0 ? "" : `, not "${lifecycle.instanceName}"`}.`
|
|
2946
|
+
);
|
|
2947
|
+
checked.set(name, lifecycle);
|
|
2948
|
+
}
|
|
2949
|
+
return checked;
|
|
2950
|
+
}
|
|
2951
|
+
function requireBundleName(name) {
|
|
2952
|
+
if (typeof name !== "string")
|
|
2953
|
+
throw new Error(`databricks asset bundles: bundle names must be strings, not ${typeof name}.`);
|
|
2954
|
+
if (!BUNDLE_NAME_PATTERN.test(name))
|
|
2955
|
+
throw new Error(
|
|
2956
|
+
`databricks asset bundles: bundle name "${name}" must match ${BUNDLE_NAME_PATTERN.source}.`
|
|
2957
|
+
);
|
|
2958
|
+
}
|
|
2959
|
+
function singleBundleTools(options) {
|
|
2827
2960
|
const lifecycle = options instanceof DatabricksAssetBundleLifecycle ? options : new DatabricksAssetBundleLifecycle(options);
|
|
2828
2961
|
const resources = [{ kind: "bundle", value: lifecycle.bundleDir }];
|
|
2829
2962
|
return [
|
|
@@ -2880,6 +3013,94 @@ function databricksAssetBundleTools(options) {
|
|
|
2880
3013
|
)
|
|
2881
3014
|
];
|
|
2882
3015
|
}
|
|
3016
|
+
function namedBundleTools(lifecycles) {
|
|
3017
|
+
requireNamedBundles(lifecycles);
|
|
3018
|
+
const names = [...lifecycles.keys()].sort();
|
|
3019
|
+
const selector = { bundle: { type: "string", enum: names } };
|
|
3020
|
+
const resources = [{ kind: "bundle", path: "/bundle" }];
|
|
3021
|
+
const select = (input) => selectBundle(lifecycles, names, input);
|
|
3022
|
+
return [
|
|
3023
|
+
bundleTool(
|
|
3024
|
+
"databricks_bundle_validate",
|
|
3025
|
+
"Validate one checked-in Databricks Asset Bundle, selected by name with `bundle`, without deploying it.",
|
|
3026
|
+
"read",
|
|
3027
|
+
{
|
|
3028
|
+
type: "object",
|
|
3029
|
+
additionalProperties: false,
|
|
3030
|
+
properties: { ...selector },
|
|
3031
|
+
required: ["bundle"]
|
|
3032
|
+
},
|
|
3033
|
+
[],
|
|
3034
|
+
async (input) => select(input).validate()
|
|
3035
|
+
),
|
|
3036
|
+
bundleTool(
|
|
3037
|
+
"databricks_bundle_deploy",
|
|
3038
|
+
"Validate and deploy one checked-in Databricks Asset Bundle, selected by name with `bundle`, recording its source fingerprint.",
|
|
3039
|
+
"write",
|
|
3040
|
+
{
|
|
3041
|
+
type: "object",
|
|
3042
|
+
additionalProperties: false,
|
|
3043
|
+
properties: { ...selector, expectedFingerprint: { type: "string" } },
|
|
3044
|
+
required: ["bundle"]
|
|
3045
|
+
},
|
|
3046
|
+
resources,
|
|
3047
|
+
async (input) => {
|
|
3048
|
+
const lifecycle = select(input);
|
|
3049
|
+
const expectedFingerprint = input.expectedFingerprint;
|
|
3050
|
+
return lifecycle.deploy(expectedFingerprint !== void 0 ? { expectedFingerprint } : {});
|
|
3051
|
+
}
|
|
3052
|
+
),
|
|
3053
|
+
bundleTool(
|
|
3054
|
+
"databricks_bundle_run",
|
|
3055
|
+
"Submit (without waiting) a run of a job or pipeline defined by one Databricks Asset Bundle, selected by name with `bundle`, using its databricks.yml resource key.",
|
|
3056
|
+
"execute",
|
|
3057
|
+
{
|
|
3058
|
+
type: "object",
|
|
3059
|
+
additionalProperties: false,
|
|
3060
|
+
properties: { ...selector, key: { type: "string" }, restart: { type: "boolean" } },
|
|
3061
|
+
required: ["bundle", "key"]
|
|
3062
|
+
},
|
|
3063
|
+
resources,
|
|
3064
|
+
async (input) => select(input).run({
|
|
3065
|
+
key: input.key,
|
|
3066
|
+
restart: input.restart === true
|
|
3067
|
+
})
|
|
3068
|
+
),
|
|
3069
|
+
bundleTool(
|
|
3070
|
+
"databricks_bundle_destroy",
|
|
3071
|
+
"Destroy a Harness-recorded deployment of one Databricks Asset Bundle, selected by name with `bundle`.",
|
|
3072
|
+
"write",
|
|
3073
|
+
{
|
|
3074
|
+
type: "object",
|
|
3075
|
+
additionalProperties: false,
|
|
3076
|
+
properties: { ...selector, force: { type: "boolean" } },
|
|
3077
|
+
required: ["bundle"]
|
|
3078
|
+
},
|
|
3079
|
+
resources,
|
|
3080
|
+
async (input) => select(input).destroy({ force: input.force === true })
|
|
3081
|
+
)
|
|
3082
|
+
];
|
|
3083
|
+
}
|
|
3084
|
+
function selectBundle(lifecycles, names, input) {
|
|
3085
|
+
const bundle = input.bundle;
|
|
3086
|
+
if (typeof bundle !== "string" || !bundle)
|
|
3087
|
+
throw new Error(
|
|
3088
|
+
`databricks asset bundles: bundle is required; configured bundles: ${names.join(", ")}.`
|
|
3089
|
+
);
|
|
3090
|
+
const lifecycle = lifecycles.get(bundle);
|
|
3091
|
+
if (!lifecycle)
|
|
3092
|
+
throw new Error(
|
|
3093
|
+
`databricks asset bundles: unknown bundle "${bundle}"; configured bundles: ${names.join(", ")}.`
|
|
3094
|
+
);
|
|
3095
|
+
return lifecycle;
|
|
3096
|
+
}
|
|
3097
|
+
function requireNamedBundles(lifecycles) {
|
|
3098
|
+
if (lifecycles.size === 0)
|
|
3099
|
+
throw new Error("databricks asset bundles: at least one named bundle is required.");
|
|
3100
|
+
}
|
|
3101
|
+
function isPlainObject(value) {
|
|
3102
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3103
|
+
}
|
|
2883
3104
|
function bundleTool(name, description, effect, inputSchema, resources, execute2) {
|
|
2884
3105
|
return {
|
|
2885
3106
|
name,
|
|
@@ -2918,6 +3139,79 @@ function requireSuccess2(label, result) {
|
|
|
2918
3139
|
function lastNonEmptyLine2(value) {
|
|
2919
3140
|
return value.split("\n").map((line) => line.trim()).filter(Boolean).at(-1) ?? "";
|
|
2920
3141
|
}
|
|
3142
|
+
function parseBundleRunResult(resourceKey2, result) {
|
|
3143
|
+
const records = [...jsonRecords(result.stdout), ...jsonRecords(result.stderr)];
|
|
3144
|
+
const jobEvent = records.find((record2) => record2.type === "job_run_url");
|
|
3145
|
+
const pipelineEvent = records.find((record2) => record2.type === "pipeline_update_url");
|
|
3146
|
+
const runUrl = stringField(jobEvent, "url") ?? stringField(pipelineEvent, "url") ?? firstUrl(result.stdout) ?? firstUrl(result.stderr);
|
|
3147
|
+
const explicitRunId = numberField(jobEvent, "run_id") ?? numberField(jobEvent, "runId") ?? records.map((record2) => numberField(record2, "run_id") ?? numberField(record2, "runId")).find(
|
|
3148
|
+
(value) => value !== void 0
|
|
3149
|
+
);
|
|
3150
|
+
const runId = explicitRunId ?? runIdFromUrl(runUrl);
|
|
3151
|
+
const pipelineId = stringField(pipelineEvent, "pipeline_id") ?? stringField(pipelineEvent, "pipelineId") ?? pipelineIdentityFromUrl(runUrl)?.pipelineId;
|
|
3152
|
+
const updateId = stringField(pipelineEvent, "update_id") ?? stringField(pipelineEvent, "updateId") ?? records.map((record2) => stringField(record2, "update_id") ?? stringField(record2, "updateId")).find((value) => value !== void 0) ?? pipelineIdentityFromUrl(runUrl)?.updateId;
|
|
3153
|
+
const output = lastNonEmptyLine2(result.stdout) || lastNonEmptyLine2(result.stderr);
|
|
3154
|
+
return {
|
|
3155
|
+
submitted: true,
|
|
3156
|
+
resourceKey: resourceKey2,
|
|
3157
|
+
...runId !== void 0 ? { runKind: "job", runId } : {},
|
|
3158
|
+
...pipelineId !== void 0 || updateId !== void 0 ? {
|
|
3159
|
+
runKind: "pipeline",
|
|
3160
|
+
...pipelineId !== void 0 ? { pipelineId } : {},
|
|
3161
|
+
...updateId !== void 0 ? { updateId } : {}
|
|
3162
|
+
} : {},
|
|
3163
|
+
...runUrl !== void 0 ? { runUrl } : {},
|
|
3164
|
+
output
|
|
3165
|
+
};
|
|
3166
|
+
}
|
|
3167
|
+
function jsonRecords(value) {
|
|
3168
|
+
const records = [];
|
|
3169
|
+
for (const candidate of [value.trim(), ...value.split("\n").map((line) => line.trim())]) {
|
|
3170
|
+
if (!(candidate.startsWith("{") && candidate.endsWith("}"))) continue;
|
|
3171
|
+
try {
|
|
3172
|
+
const parsed = JSON.parse(candidate);
|
|
3173
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed))
|
|
3174
|
+
records.push(parsed);
|
|
3175
|
+
} catch {
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
3178
|
+
return records;
|
|
3179
|
+
}
|
|
3180
|
+
function stringField(record2, key) {
|
|
3181
|
+
const value = record2?.[key];
|
|
3182
|
+
return typeof value === "string" && value.trim() ? value : void 0;
|
|
3183
|
+
}
|
|
3184
|
+
function numberField(record2, key) {
|
|
3185
|
+
const value = record2?.[key];
|
|
3186
|
+
const parsed = typeof value === "number" ? value : typeof value === "string" && /^\d+$/.test(value) ? Number(value) : void 0;
|
|
3187
|
+
return parsed !== void 0 && Number.isSafeInteger(parsed) && parsed > 0 ? parsed : void 0;
|
|
3188
|
+
}
|
|
3189
|
+
function firstUrl(value) {
|
|
3190
|
+
const match = /https?:\/\/[^\s"']+/u.exec(value);
|
|
3191
|
+
return match?.[0]?.replace(/[),.;]+$/u, "");
|
|
3192
|
+
}
|
|
3193
|
+
function runIdFromUrl(value) {
|
|
3194
|
+
if (!value) return void 0;
|
|
3195
|
+
try {
|
|
3196
|
+
const url2 = new URL(value);
|
|
3197
|
+
const raw = /\/jobs\/\d+\/runs\/(\d+)/u.exec(url2.pathname)?.[1] ?? /(?:^|\/)job\/\d+\/run\/(\d+)(?:\/|$)/u.exec(url2.hash.replace(/^#/, ""))?.[1];
|
|
3198
|
+
return raw ? numberField({ value: raw }, "value") : void 0;
|
|
3199
|
+
} catch {
|
|
3200
|
+
return void 0;
|
|
3201
|
+
}
|
|
3202
|
+
}
|
|
3203
|
+
function pipelineIdentityFromUrl(value) {
|
|
3204
|
+
if (!value) return void 0;
|
|
3205
|
+
try {
|
|
3206
|
+
const url2 = new URL(value);
|
|
3207
|
+
const match = /(?:^|\/)pipelines\/([^/]+)\/updates\/([^/?#]+)/u.exec(
|
|
3208
|
+
`${url2.pathname}/${url2.hash.replace(/^#/, "")}`
|
|
3209
|
+
);
|
|
3210
|
+
return match?.[1] && match[2] ? { pipelineId: match[1], updateId: match[2] } : void 0;
|
|
3211
|
+
} catch {
|
|
3212
|
+
return void 0;
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
2921
3215
|
|
|
2922
3216
|
// src/consumption.ts
|
|
2923
3217
|
var GROUP_COLUMNS = {
|
|
@@ -6464,7 +6758,7 @@ __export(util_exports, {
|
|
|
6464
6758
|
getSizableOrigin: () => getSizableOrigin,
|
|
6465
6759
|
hexToUint8Array: () => hexToUint8Array,
|
|
6466
6760
|
isObject: () => isObject,
|
|
6467
|
-
isPlainObject: () =>
|
|
6761
|
+
isPlainObject: () => isPlainObject2,
|
|
6468
6762
|
issue: () => issue,
|
|
6469
6763
|
joinValues: () => joinValues,
|
|
6470
6764
|
jsonStringifyReplacer: () => jsonStringifyReplacer,
|
|
@@ -6644,7 +6938,7 @@ var allowsEval = /* @__PURE__ */ cached(() => {
|
|
|
6644
6938
|
return false;
|
|
6645
6939
|
}
|
|
6646
6940
|
});
|
|
6647
|
-
function
|
|
6941
|
+
function isPlainObject2(o2) {
|
|
6648
6942
|
if (isObject(o2) === false)
|
|
6649
6943
|
return false;
|
|
6650
6944
|
const ctor = o2.constructor;
|
|
@@ -6661,7 +6955,7 @@ function isPlainObject(o2) {
|
|
|
6661
6955
|
return true;
|
|
6662
6956
|
}
|
|
6663
6957
|
function shallowClone(o2) {
|
|
6664
|
-
if (
|
|
6958
|
+
if (isPlainObject2(o2))
|
|
6665
6959
|
return { ...o2 };
|
|
6666
6960
|
if (Array.isArray(o2))
|
|
6667
6961
|
return [...o2];
|
|
@@ -6865,7 +7159,7 @@ function omit(schema, mask) {
|
|
|
6865
7159
|
return clone(schema, def);
|
|
6866
7160
|
}
|
|
6867
7161
|
function extend(schema, shape) {
|
|
6868
|
-
if (!
|
|
7162
|
+
if (!isPlainObject2(shape)) {
|
|
6869
7163
|
throw new Error("Invalid input to extend: expected a plain object");
|
|
6870
7164
|
}
|
|
6871
7165
|
const checks = schema._zod.def.checks;
|
|
@@ -6888,7 +7182,7 @@ function extend(schema, shape) {
|
|
|
6888
7182
|
return clone(schema, def);
|
|
6889
7183
|
}
|
|
6890
7184
|
function safeExtend(schema, shape) {
|
|
6891
|
-
if (!
|
|
7185
|
+
if (!isPlainObject2(shape)) {
|
|
6892
7186
|
throw new Error("Invalid input to safeExtend: expected a plain object");
|
|
6893
7187
|
}
|
|
6894
7188
|
const def = mergeDefs(schema._zod.def, {
|
|
@@ -9235,7 +9529,7 @@ function mergeValues(a2, b2) {
|
|
|
9235
9529
|
if (a2 instanceof Date && b2 instanceof Date && +a2 === +b2) {
|
|
9236
9530
|
return { valid: true, data: a2 };
|
|
9237
9531
|
}
|
|
9238
|
-
if (
|
|
9532
|
+
if (isPlainObject2(a2) && isPlainObject2(b2)) {
|
|
9239
9533
|
const bKeys = Object.keys(b2);
|
|
9240
9534
|
const sharedKeys = Object.keys(a2).filter((key) => bKeys.indexOf(key) !== -1);
|
|
9241
9535
|
const newObj = { ...a2, ...b2 };
|
|
@@ -9421,7 +9715,7 @@ var $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
|
|
|
9421
9715
|
$ZodType.init(inst, def);
|
|
9422
9716
|
inst._zod.parse = (payload, ctx) => {
|
|
9423
9717
|
const input = payload.value;
|
|
9424
|
-
if (!
|
|
9718
|
+
if (!isPlainObject2(input)) {
|
|
9425
9719
|
payload.issues.push({
|
|
9426
9720
|
expected: "record",
|
|
9427
9721
|
code: "invalid_type",
|
|
@@ -22131,43 +22425,76 @@ function databricksPipelineStatusTool(client, options = {}) {
|
|
|
22131
22425
|
execute: (input) => client.get({ pipelineId: input.pipelineId })
|
|
22132
22426
|
};
|
|
22133
22427
|
}
|
|
22134
|
-
function databricksPipelineStartTool(client, options = {}) {
|
|
22428
|
+
function databricksPipelineStartTool(client, runPolicy, options = {}) {
|
|
22429
|
+
const allowedPipelineIds = resolveExactResourcePolicy(
|
|
22430
|
+
runPolicy,
|
|
22431
|
+
"allowedPipelineIds",
|
|
22432
|
+
"allowAnyPipelineId",
|
|
22433
|
+
"Lakeflow pipeline"
|
|
22434
|
+
);
|
|
22135
22435
|
return {
|
|
22136
22436
|
name: options.name ?? "databricks_pipeline_start",
|
|
22137
22437
|
description: options.description ?? "Trigger a Lakeflow pipeline update (run). Set fullRefresh to reprocess all data.",
|
|
22138
22438
|
inputSchema: {
|
|
22139
22439
|
type: "object",
|
|
22140
22440
|
additionalProperties: false,
|
|
22141
|
-
properties: {
|
|
22441
|
+
properties: {
|
|
22442
|
+
pipelineId: pinnedStringResourceSchema(allowedPipelineIds),
|
|
22443
|
+
fullRefresh: { type: "boolean" }
|
|
22444
|
+
},
|
|
22142
22445
|
required: ["pipelineId"]
|
|
22143
22446
|
},
|
|
22144
|
-
metadata: {
|
|
22145
|
-
|
|
22146
|
-
|
|
22147
|
-
|
|
22148
|
-
|
|
22447
|
+
metadata: {
|
|
22448
|
+
effect: "execute",
|
|
22449
|
+
provider: "databricks",
|
|
22450
|
+
service: "lakeflow",
|
|
22451
|
+
governance: { resources: [{ kind: "pipeline", path: "/pipelineId" }] }
|
|
22452
|
+
},
|
|
22453
|
+
async execute(input) {
|
|
22454
|
+
assertExactResourceAllowed("Lakeflow pipeline", input.pipelineId, allowedPipelineIds);
|
|
22455
|
+
return await client.start({
|
|
22456
|
+
pipelineId: input.pipelineId,
|
|
22457
|
+
...input.fullRefresh !== void 0 ? { fullRefresh: input.fullRefresh } : {}
|
|
22458
|
+
});
|
|
22459
|
+
}
|
|
22149
22460
|
};
|
|
22150
22461
|
}
|
|
22151
|
-
function databricksPipelineStopTool(client, options = {}) {
|
|
22462
|
+
function databricksPipelineStopTool(client, runPolicy, options = {}) {
|
|
22463
|
+
const allowedPipelineIds = resolveExactResourcePolicy(
|
|
22464
|
+
runPolicy,
|
|
22465
|
+
"allowedPipelineIds",
|
|
22466
|
+
"allowAnyPipelineId",
|
|
22467
|
+
"Lakeflow pipeline"
|
|
22468
|
+
);
|
|
22152
22469
|
return {
|
|
22153
22470
|
name: options.name ?? "databricks_pipeline_stop",
|
|
22154
22471
|
description: options.description ?? "Stop the active update of a Lakeflow pipeline.",
|
|
22155
22472
|
inputSchema: {
|
|
22156
22473
|
type: "object",
|
|
22157
22474
|
additionalProperties: false,
|
|
22158
|
-
properties: { pipelineId:
|
|
22475
|
+
properties: { pipelineId: pinnedStringResourceSchema(allowedPipelineIds) },
|
|
22159
22476
|
required: ["pipelineId"]
|
|
22160
22477
|
},
|
|
22161
|
-
metadata: {
|
|
22162
|
-
|
|
22478
|
+
metadata: {
|
|
22479
|
+
effect: "execute",
|
|
22480
|
+
provider: "databricks",
|
|
22481
|
+
service: "lakeflow",
|
|
22482
|
+
governance: { resources: [{ kind: "pipeline", path: "/pipelineId" }] }
|
|
22483
|
+
},
|
|
22484
|
+
async execute(input) {
|
|
22485
|
+
assertExactResourceAllowed("Lakeflow pipeline", input.pipelineId, allowedPipelineIds);
|
|
22486
|
+
return await client.stop({ pipelineId: input.pipelineId });
|
|
22487
|
+
}
|
|
22163
22488
|
};
|
|
22164
22489
|
}
|
|
22165
|
-
function databricksLakeflowTools(client) {
|
|
22490
|
+
function databricksLakeflowTools(client, runPolicy) {
|
|
22166
22491
|
return [
|
|
22167
22492
|
databricksPipelineListTool(client),
|
|
22168
22493
|
databricksPipelineStatusTool(client),
|
|
22169
|
-
|
|
22170
|
-
|
|
22494
|
+
...runPolicy ? [
|
|
22495
|
+
databricksPipelineStartTool(client, runPolicy),
|
|
22496
|
+
databricksPipelineStopTool(client, runPolicy)
|
|
22497
|
+
] : []
|
|
22171
22498
|
];
|
|
22172
22499
|
}
|
|
22173
22500
|
|
|
@@ -58706,12 +59033,71 @@ var DatabricksRunTimeoutError = class extends Error {
|
|
|
58706
59033
|
this.runId = runId;
|
|
58707
59034
|
}
|
|
58708
59035
|
};
|
|
59036
|
+
var DatabricksRunNotAllowedError = class extends Error {
|
|
59037
|
+
constructor(message) {
|
|
59038
|
+
super(message);
|
|
59039
|
+
this.name = "DatabricksRunNotAllowedError";
|
|
59040
|
+
}
|
|
59041
|
+
};
|
|
59042
|
+
function validateDatabricksJobRunPolicy(policy) {
|
|
59043
|
+
if (policy.allowAnyJobId === true) return;
|
|
59044
|
+
const ids = policy.allowedJobIds;
|
|
59045
|
+
if (!Array.isArray(ids) || ids.length === 0)
|
|
59046
|
+
throw new Error("databricks jobs: runPolicy.allowedJobIds must be non-empty when configured.");
|
|
59047
|
+
for (const id of ids)
|
|
59048
|
+
if (!Number.isSafeInteger(id) || id < 0)
|
|
59049
|
+
throw new Error(
|
|
59050
|
+
"databricks jobs: runPolicy.allowedJobIds must contain non-negative integer job ids."
|
|
59051
|
+
);
|
|
59052
|
+
}
|
|
59053
|
+
function validateDatabricksNotebookRunPolicy(policy) {
|
|
59054
|
+
if (policy.allowAnyNotebookPath === true) return;
|
|
59055
|
+
const paths = policy.allowedNotebookPaths ?? [];
|
|
59056
|
+
const prefixes = policy.allowedNotebookPathPrefixes ?? [];
|
|
59057
|
+
if (paths.length === 0 && prefixes.length === 0)
|
|
59058
|
+
throw new Error(
|
|
59059
|
+
"databricks jobs: notebookPolicy must configure a non-empty allowedNotebookPaths or allowedNotebookPathPrefixes."
|
|
59060
|
+
);
|
|
59061
|
+
for (const [name, values] of [
|
|
59062
|
+
["allowedNotebookPaths", paths],
|
|
59063
|
+
["allowedNotebookPathPrefixes", prefixes]
|
|
59064
|
+
]) {
|
|
59065
|
+
for (const value of values) {
|
|
59066
|
+
if (typeof value !== "string" || !value.startsWith("/"))
|
|
59067
|
+
throw new Error(
|
|
59068
|
+
`databricks jobs: notebookPolicy.${name} entries must be absolute workspace paths.`
|
|
59069
|
+
);
|
|
59070
|
+
if (hasParentSegment(value))
|
|
59071
|
+
throw new Error(
|
|
59072
|
+
`databricks jobs: notebookPolicy.${name} entries cannot contain a ".." segment.`
|
|
59073
|
+
);
|
|
59074
|
+
}
|
|
59075
|
+
}
|
|
59076
|
+
}
|
|
59077
|
+
function hasParentSegment(path4) {
|
|
59078
|
+
return path4.split("/").includes("..");
|
|
59079
|
+
}
|
|
59080
|
+
function notebookPathAllowed(policy, path4) {
|
|
59081
|
+
if (policy.allowedNotebookPaths?.includes(path4)) return true;
|
|
59082
|
+
return (policy.allowedNotebookPathPrefixes ?? []).some((prefix) => {
|
|
59083
|
+
const normalized = prefix.length > 1 && prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
|
|
59084
|
+
return normalized === path4 || path4.startsWith(`${normalized}/`);
|
|
59085
|
+
});
|
|
59086
|
+
}
|
|
58709
59087
|
var DatabricksJobs = class {
|
|
58710
|
-
constructor(client) {
|
|
59088
|
+
constructor(client, options = {}) {
|
|
58711
59089
|
this.client = client;
|
|
59090
|
+
if (options.runPolicy !== void 0) validateDatabricksJobRunPolicy(options.runPolicy);
|
|
59091
|
+
if (options.notebookPolicy !== void 0)
|
|
59092
|
+
validateDatabricksNotebookRunPolicy(options.notebookPolicy);
|
|
59093
|
+
this.runPolicy = options.runPolicy;
|
|
59094
|
+
this.notebookPolicy = options.notebookPolicy;
|
|
58712
59095
|
}
|
|
58713
59096
|
client;
|
|
59097
|
+
runPolicy;
|
|
59098
|
+
notebookPolicy;
|
|
58714
59099
|
async runJob(input) {
|
|
59100
|
+
this.assertJobAllowed(input.jobId);
|
|
58715
59101
|
const idempotencyToken = input.idempotencyToken ?? crypto.randomUUID();
|
|
58716
59102
|
const request = {
|
|
58717
59103
|
jobId: BigInt(input.jobId),
|
|
@@ -58724,6 +59110,7 @@ var DatabricksJobs = class {
|
|
|
58724
59110
|
return receipt(waiter.runId, void 0, idempotencyToken, "job");
|
|
58725
59111
|
}
|
|
58726
59112
|
async submitNotebook(input) {
|
|
59113
|
+
this.assertNotebookAllowed(input.notebookPath);
|
|
58727
59114
|
const idempotencyToken = input.idempotencyToken ?? crypto.randomUUID();
|
|
58728
59115
|
const request = {
|
|
58729
59116
|
idempotencyToken,
|
|
@@ -58796,9 +59183,27 @@ var DatabricksJobs = class {
|
|
|
58796
59183
|
await store.put({ scope, ref, bytes });
|
|
58797
59184
|
return ref;
|
|
58798
59185
|
}
|
|
59186
|
+
/** Bound checked before `runNow`, so an out-of-policy id never reaches the workspace. */
|
|
59187
|
+
assertJobAllowed(jobId2) {
|
|
59188
|
+
const policy = this.runPolicy;
|
|
59189
|
+
if (!policy || policy.allowAnyJobId === true) return;
|
|
59190
|
+
if (!(policy.allowedJobIds ?? []).includes(jobId2))
|
|
59191
|
+
throw new DatabricksRunNotAllowedError(
|
|
59192
|
+
`databricks jobs: job ${jobId2} is not in the configured run allowlist.`
|
|
59193
|
+
);
|
|
59194
|
+
}
|
|
59195
|
+
/** Bound checked before `submitRun`, so an out-of-policy notebook is never executed. */
|
|
59196
|
+
assertNotebookAllowed(notebookPath) {
|
|
59197
|
+
const policy = this.notebookPolicy;
|
|
59198
|
+
if (!policy || policy.allowAnyNotebookPath === true) return;
|
|
59199
|
+
if (hasParentSegment(notebookPath) || !notebookPathAllowed(policy, notebookPath))
|
|
59200
|
+
throw new DatabricksRunNotAllowedError(
|
|
59201
|
+
`databricks jobs: notebook path ${JSON.stringify(notebookPath)} is not in the configured run allowlist.`
|
|
59202
|
+
);
|
|
59203
|
+
}
|
|
58799
59204
|
};
|
|
58800
|
-
function databricksJobs(client) {
|
|
58801
|
-
return new DatabricksJobs(client);
|
|
59205
|
+
function databricksJobs(client, options) {
|
|
59206
|
+
return new DatabricksJobs(client, options);
|
|
58802
59207
|
}
|
|
58803
59208
|
function receipt(runIdValue, numberInJobValue, idempotencyToken, kind) {
|
|
58804
59209
|
if (runIdValue === void 0)
|
|
@@ -58994,7 +59399,8 @@ function lexSqlReadStatement(statement) {
|
|
|
58994
59399
|
function assertDatabricksSqlReadStatement(statement) {
|
|
58995
59400
|
if (!statement.trim()) throw new Error("Databricks SQL read denied: statement cannot be empty.");
|
|
58996
59401
|
const { tokens, semicolons } = lexSqlReadStatement(statement);
|
|
58997
|
-
if (tokens.length === 0)
|
|
59402
|
+
if (tokens.length === 0)
|
|
59403
|
+
throw new Error("Databricks SQL read denied: expected a SELECT statement.");
|
|
58998
59404
|
if (semicolons.length > 1)
|
|
58999
59405
|
throw new Error("Databricks SQL read denied: multiple statements are not allowed.");
|
|
59000
59406
|
if (semicolons.length === 1) {
|
|
@@ -59012,7 +59418,8 @@ function assertDatabricksSqlReadStatement(statement) {
|
|
|
59012
59418
|
if (unsafe)
|
|
59013
59419
|
throw new Error(`Databricks SQL read denied: unsafe keyword ${unsafe.value} is not allowed.`);
|
|
59014
59420
|
}
|
|
59015
|
-
function databricksSqlTool(client, options) {
|
|
59421
|
+
function databricksSqlTool(client, policy, options) {
|
|
59422
|
+
const executionPolicy = resolveSqlExecutionPolicy(policy);
|
|
59016
59423
|
return {
|
|
59017
59424
|
name: options.name ?? "databricks_sql",
|
|
59018
59425
|
description: options.description ?? "Run a SQL statement on a Databricks SQL Warehouse.",
|
|
@@ -59020,23 +59427,55 @@ function databricksSqlTool(client, options) {
|
|
|
59020
59427
|
type: "object",
|
|
59021
59428
|
additionalProperties: false,
|
|
59022
59429
|
properties: {
|
|
59023
|
-
statement: { type: "string" },
|
|
59430
|
+
statement: executionPolicy.kind === "allowlist" ? pinnedStringResourceSchema(executionPolicy.statements) : { type: "string" },
|
|
59024
59431
|
catalog: { type: "string" },
|
|
59025
59432
|
schema: { type: "string" }
|
|
59026
59433
|
},
|
|
59027
59434
|
required: ["statement"]
|
|
59028
59435
|
},
|
|
59029
|
-
metadata: {
|
|
59030
|
-
|
|
59031
|
-
|
|
59032
|
-
|
|
59033
|
-
|
|
59034
|
-
|
|
59035
|
-
|
|
59036
|
-
|
|
59037
|
-
|
|
59436
|
+
metadata: {
|
|
59437
|
+
effect: "execute",
|
|
59438
|
+
provider: "databricks",
|
|
59439
|
+
service: "sql",
|
|
59440
|
+
governance: {
|
|
59441
|
+
resources: [{ kind: "sql-warehouse", value: options.warehouseId }]
|
|
59442
|
+
}
|
|
59443
|
+
},
|
|
59444
|
+
async execute(input) {
|
|
59445
|
+
await assertSqlExecutionAllowed(input, executionPolicy);
|
|
59446
|
+
return await client.executeStatement({
|
|
59447
|
+
warehouseId: options.warehouseId,
|
|
59448
|
+
statement: input.statement,
|
|
59449
|
+
waitTimeout: options.waitTimeout ?? "30s",
|
|
59450
|
+
disposition: options.disposition ?? "INLINE",
|
|
59451
|
+
...input.catalog ? { catalog: input.catalog } : {},
|
|
59452
|
+
...input.schema ? { schema: input.schema } : {}
|
|
59453
|
+
});
|
|
59454
|
+
}
|
|
59038
59455
|
};
|
|
59039
59456
|
}
|
|
59457
|
+
function resolveSqlExecutionPolicy(policy) {
|
|
59458
|
+
if (!policy || typeof policy !== "object" || Array.isArray(policy))
|
|
59459
|
+
throw new TypeError("Databricks SQL execution policy must be an object.");
|
|
59460
|
+
if ("validateStatement" in policy && typeof policy.validateStatement === "function")
|
|
59461
|
+
return { kind: "validator", validate: policy.validateStatement };
|
|
59462
|
+
const statements = resolveExactResourcePolicy(
|
|
59463
|
+
policy,
|
|
59464
|
+
"allowedStatements",
|
|
59465
|
+
"allowAnyStatement",
|
|
59466
|
+
"SQL statement"
|
|
59467
|
+
);
|
|
59468
|
+
return statements ? { kind: "allowlist", statements } : { kind: "allow-any" };
|
|
59469
|
+
}
|
|
59470
|
+
async function assertSqlExecutionAllowed(input, policy) {
|
|
59471
|
+
if (policy.kind === "allow-any") return;
|
|
59472
|
+
if (policy.kind === "allowlist") {
|
|
59473
|
+
assertExactResourceAllowed("SQL statement", input.statement, policy.statements);
|
|
59474
|
+
return;
|
|
59475
|
+
}
|
|
59476
|
+
if (await policy.validate(input) !== true)
|
|
59477
|
+
throw new DatabricksResourceNotAllowedError("SQL statement");
|
|
59478
|
+
}
|
|
59040
59479
|
function databricksSqlReadTool(client, options) {
|
|
59041
59480
|
return {
|
|
59042
59481
|
name: options.name ?? "sql_read",
|
|
@@ -59056,9 +59495,7 @@ function databricksSqlReadTool(client, options) {
|
|
|
59056
59495
|
provider: "databricks",
|
|
59057
59496
|
service: "sql",
|
|
59058
59497
|
governance: {
|
|
59059
|
-
resources: [
|
|
59060
|
-
{ kind: "catalog", path: "/catalog", catalogQualified: true, optional: true }
|
|
59061
|
-
]
|
|
59498
|
+
resources: [{ kind: "catalog", path: "/catalog", catalogQualified: true, optional: true }]
|
|
59062
59499
|
}
|
|
59063
59500
|
},
|
|
59064
59501
|
async execute(input) {
|
|
@@ -59074,7 +59511,8 @@ function databricksSqlReadTool(client, options) {
|
|
|
59074
59511
|
}
|
|
59075
59512
|
};
|
|
59076
59513
|
}
|
|
59077
|
-
function databricksRunJobTool(client, options = {}) {
|
|
59514
|
+
function databricksRunJobTool(client, runPolicy, options = {}) {
|
|
59515
|
+
const jobs = databricksJobs(client, { runPolicy });
|
|
59078
59516
|
return {
|
|
59079
59517
|
name: options.name ?? "databricks_run_job",
|
|
59080
59518
|
description: options.description ?? "Trigger an existing Databricks job by job id.",
|
|
@@ -59082,7 +59520,7 @@ function databricksRunJobTool(client, options = {}) {
|
|
|
59082
59520
|
type: "object",
|
|
59083
59521
|
additionalProperties: false,
|
|
59084
59522
|
properties: {
|
|
59085
|
-
jobId:
|
|
59523
|
+
jobId: pinnedJobIdSchema(runPolicy),
|
|
59086
59524
|
idempotencyToken: { type: "string" },
|
|
59087
59525
|
notebookParams: { type: "object", additionalProperties: true },
|
|
59088
59526
|
pythonParams: { type: "array", items: { type: "string" } },
|
|
@@ -59090,11 +59528,26 @@ function databricksRunJobTool(client, options = {}) {
|
|
|
59090
59528
|
},
|
|
59091
59529
|
required: ["jobId"]
|
|
59092
59530
|
},
|
|
59093
|
-
metadata: {
|
|
59094
|
-
|
|
59531
|
+
metadata: {
|
|
59532
|
+
effect: "execute",
|
|
59533
|
+
provider: "databricks",
|
|
59534
|
+
service: "jobs",
|
|
59535
|
+
governance: { resources: [{ kind: "job", path: "/jobId" }] }
|
|
59536
|
+
},
|
|
59537
|
+
execute: (input, context) => jobs.runJob({
|
|
59538
|
+
...input,
|
|
59539
|
+
...input.idempotencyToken ? {} : context?.toolCallId ? { idempotencyToken: context.toolCallId } : {}
|
|
59540
|
+
})
|
|
59095
59541
|
};
|
|
59096
59542
|
}
|
|
59097
|
-
function
|
|
59543
|
+
function pinnedJobIdSchema(policy) {
|
|
59544
|
+
const ids = policy.allowAnyJobId === true ? [] : policy.allowedJobIds ?? [];
|
|
59545
|
+
if (ids.length === 1) return { type: "number", const: ids[0] };
|
|
59546
|
+
if (ids.length > 1) return { type: "number", enum: ids };
|
|
59547
|
+
return { type: "number" };
|
|
59548
|
+
}
|
|
59549
|
+
function databricksNotebookTool(client, notebookPolicy, options = {}) {
|
|
59550
|
+
const jobs = databricksJobs(client, { notebookPolicy });
|
|
59098
59551
|
return {
|
|
59099
59552
|
name: options.name ?? "databricks_run_notebook",
|
|
59100
59553
|
description: options.description ?? "Submit a one-off Databricks notebook run.",
|
|
@@ -59102,21 +59555,40 @@ function databricksNotebookTool(client, options = {}) {
|
|
|
59102
59555
|
type: "object",
|
|
59103
59556
|
additionalProperties: false,
|
|
59104
59557
|
properties: {
|
|
59105
|
-
notebookPath:
|
|
59558
|
+
notebookPath: pinnedNotebookPathSchema(notebookPolicy),
|
|
59106
59559
|
idempotencyToken: { type: "string" },
|
|
59107
59560
|
baseParameters: { type: "object", additionalProperties: true },
|
|
59108
59561
|
runName: { type: "string" }
|
|
59109
59562
|
},
|
|
59110
59563
|
required: ["notebookPath"]
|
|
59111
59564
|
},
|
|
59112
|
-
metadata: {
|
|
59113
|
-
|
|
59565
|
+
metadata: {
|
|
59566
|
+
effect: "execute",
|
|
59567
|
+
provider: "databricks",
|
|
59568
|
+
service: "jobs",
|
|
59569
|
+
governance: { resources: [{ kind: "notebook", path: "/notebookPath" }] }
|
|
59570
|
+
},
|
|
59571
|
+
execute: (input, context) => jobs.submitNotebook({
|
|
59114
59572
|
...input,
|
|
59573
|
+
...input.idempotencyToken ? {} : context?.toolCallId ? { idempotencyToken: context.toolCallId } : {},
|
|
59115
59574
|
...options.existingClusterId ? { existingClusterId: options.existingClusterId } : {}
|
|
59116
59575
|
})
|
|
59117
59576
|
};
|
|
59118
59577
|
}
|
|
59119
|
-
function
|
|
59578
|
+
function pinnedNotebookPathSchema(policy) {
|
|
59579
|
+
if (policy.allowAnyNotebookPath === true) return { type: "string" };
|
|
59580
|
+
const paths = policy.allowedNotebookPaths ?? [];
|
|
59581
|
+
if (paths.length > 0 && (policy.allowedNotebookPathPrefixes ?? []).length === 0)
|
|
59582
|
+
return { type: "string", enum: paths };
|
|
59583
|
+
return { type: "string" };
|
|
59584
|
+
}
|
|
59585
|
+
function databricksMlflowLogMetricTool(client, runPolicy, options = {}) {
|
|
59586
|
+
const allowedRunIds = resolveExactResourcePolicy(
|
|
59587
|
+
runPolicy,
|
|
59588
|
+
"allowedRunIds",
|
|
59589
|
+
"allowAnyRunId",
|
|
59590
|
+
"MLflow run"
|
|
59591
|
+
);
|
|
59120
59592
|
return {
|
|
59121
59593
|
name: options.name ?? "databricks_mlflow_log_metric",
|
|
59122
59594
|
description: options.description ?? "Log a metric to an MLflow run hosted in Databricks.",
|
|
@@ -59124,7 +59596,7 @@ function databricksMlflowLogMetricTool(client, options = {}) {
|
|
|
59124
59596
|
type: "object",
|
|
59125
59597
|
additionalProperties: false,
|
|
59126
59598
|
properties: {
|
|
59127
|
-
runId:
|
|
59599
|
+
runId: pinnedStringResourceSchema(allowedRunIds),
|
|
59128
59600
|
key: { type: "string" },
|
|
59129
59601
|
value: { type: "number" },
|
|
59130
59602
|
step: { type: "number" },
|
|
@@ -59132,32 +59604,58 @@ function databricksMlflowLogMetricTool(client, options = {}) {
|
|
|
59132
59604
|
},
|
|
59133
59605
|
required: ["runId", "key", "value"]
|
|
59134
59606
|
},
|
|
59135
|
-
metadata: {
|
|
59136
|
-
|
|
59137
|
-
|
|
59138
|
-
|
|
59139
|
-
|
|
59140
|
-
|
|
59141
|
-
|
|
59142
|
-
|
|
59143
|
-
|
|
59144
|
-
|
|
59607
|
+
metadata: {
|
|
59608
|
+
effect: "write",
|
|
59609
|
+
provider: "databricks",
|
|
59610
|
+
service: "mlflow",
|
|
59611
|
+
governance: { resources: [{ kind: "mlflow-run", path: "/runId" }] }
|
|
59612
|
+
},
|
|
59613
|
+
async execute(input) {
|
|
59614
|
+
assertExactResourceAllowed("MLflow run", input.runId, allowedRunIds);
|
|
59615
|
+
return await retryIdempotent(
|
|
59616
|
+
() => client.logMetric({
|
|
59617
|
+
runId: input.runId,
|
|
59618
|
+
key: input.key,
|
|
59619
|
+
value: input.value,
|
|
59620
|
+
timestamp: BigInt(input.timestamp ?? Date.now()),
|
|
59621
|
+
...input.step !== void 0 ? { step: BigInt(input.step) } : {}
|
|
59622
|
+
})
|
|
59623
|
+
);
|
|
59624
|
+
}
|
|
59145
59625
|
};
|
|
59146
59626
|
}
|
|
59147
|
-
function databricksMlflowLogParamTool(client, options = {}) {
|
|
59627
|
+
function databricksMlflowLogParamTool(client, runPolicy, options = {}) {
|
|
59628
|
+
const allowedRunIds = resolveExactResourcePolicy(
|
|
59629
|
+
runPolicy,
|
|
59630
|
+
"allowedRunIds",
|
|
59631
|
+
"allowAnyRunId",
|
|
59632
|
+
"MLflow run"
|
|
59633
|
+
);
|
|
59148
59634
|
return {
|
|
59149
59635
|
name: options.name ?? "databricks_mlflow_log_param",
|
|
59150
59636
|
description: options.description ?? "Log a parameter to an MLflow run hosted in Databricks.",
|
|
59151
59637
|
inputSchema: {
|
|
59152
59638
|
type: "object",
|
|
59153
59639
|
additionalProperties: false,
|
|
59154
|
-
properties: {
|
|
59640
|
+
properties: {
|
|
59641
|
+
runId: pinnedStringResourceSchema(allowedRunIds),
|
|
59642
|
+
key: { type: "string" },
|
|
59643
|
+
value: { type: "string" }
|
|
59644
|
+
},
|
|
59155
59645
|
required: ["runId", "key", "value"]
|
|
59156
59646
|
},
|
|
59157
|
-
metadata: {
|
|
59158
|
-
|
|
59159
|
-
|
|
59160
|
-
|
|
59647
|
+
metadata: {
|
|
59648
|
+
effect: "write",
|
|
59649
|
+
provider: "databricks",
|
|
59650
|
+
service: "mlflow",
|
|
59651
|
+
governance: { resources: [{ kind: "mlflow-run", path: "/runId" }] }
|
|
59652
|
+
},
|
|
59653
|
+
async execute(input) {
|
|
59654
|
+
assertExactResourceAllowed("MLflow run", input.runId, allowedRunIds);
|
|
59655
|
+
return await retryIdempotent(
|
|
59656
|
+
() => client.logParam({ runId: input.runId, key: input.key, value: input.value })
|
|
59657
|
+
);
|
|
59658
|
+
}
|
|
59161
59659
|
};
|
|
59162
59660
|
}
|
|
59163
59661
|
async function retryIdempotent(call, attempts = 3) {
|
|
@@ -59818,6 +60316,7 @@ function databricksPersistence(options) {
|
|
|
59818
60316
|
let sessionStore;
|
|
59819
60317
|
let submissionStore;
|
|
59820
60318
|
let conversationStreamStore;
|
|
60319
|
+
let schedulerLeaseStore;
|
|
59821
60320
|
const persistence = {
|
|
59822
60321
|
client,
|
|
59823
60322
|
async connect() {
|
|
@@ -59835,6 +60334,11 @@ function databricksPersistence(options) {
|
|
|
59835
60334
|
conversationStreamStore ??= new module.PostgresConversationStreamStore({ client });
|
|
59836
60335
|
return conversationStreamStore;
|
|
59837
60336
|
},
|
|
60337
|
+
async connectSchedulerLeaseStore() {
|
|
60338
|
+
const module = await stores();
|
|
60339
|
+
schedulerLeaseStore ??= module.postgresSchedulerLeaseStore?.(client);
|
|
60340
|
+
return schedulerLeaseStore;
|
|
60341
|
+
},
|
|
59838
60342
|
async connectAll() {
|
|
59839
60343
|
return {
|
|
59840
60344
|
store: await persistence.connect(),
|
|
@@ -60070,261 +60574,6 @@ async function queryDatabricksLineageEvidence(client, submissionId) {
|
|
|
60070
60574
|
}));
|
|
60071
60575
|
}
|
|
60072
60576
|
|
|
60073
|
-
// src/volumes-attachment-store.ts
|
|
60074
|
-
import {
|
|
60075
|
-
AttachmentStoreError,
|
|
60076
|
-
verifyAttachmentBytes
|
|
60077
|
-
} from "@fabric-harness/sdk";
|
|
60078
|
-
var UcVolumesAttachmentStore = class {
|
|
60079
|
-
client;
|
|
60080
|
-
volumeRoot;
|
|
60081
|
-
rootPrefix;
|
|
60082
|
-
constructor(options) {
|
|
60083
|
-
this.client = options.client;
|
|
60084
|
-
this.rootPrefix = options.rootPrefix ?? "fh-attachments";
|
|
60085
|
-
this.volumeRoot = `/Volumes/${options.catalog}/${options.schema}/${options.volume}/${this.rootPrefix}`;
|
|
60086
|
-
}
|
|
60087
|
-
async put(input) {
|
|
60088
|
-
await verifyAttachmentBytes(input.ref, input.bytes);
|
|
60089
|
-
const refPath = this.refPath(input.scope, input.ref.digest);
|
|
60090
|
-
if (await this.readFile(refPath)) return;
|
|
60091
|
-
await this.writeFile(this.bytesPath(input.scope, input.ref.digest), input.bytes);
|
|
60092
|
-
await this.writeFile(refPath, new TextEncoder().encode(JSON.stringify(input.ref)));
|
|
60093
|
-
}
|
|
60094
|
-
async get(scope, digest) {
|
|
60095
|
-
const refBytes = await this.readFile(this.refPath(scope, digest));
|
|
60096
|
-
if (!refBytes) return null;
|
|
60097
|
-
const ref = parseAttachmentRef(refBytes);
|
|
60098
|
-
const bytes = await this.readFile(this.bytesPath(scope, digest));
|
|
60099
|
-
if (!bytes) return null;
|
|
60100
|
-
return { ref, bytes };
|
|
60101
|
-
}
|
|
60102
|
-
async getByAttachmentId(scope, attachmentId) {
|
|
60103
|
-
for (const ref of await this.list(scope)) {
|
|
60104
|
-
if (ref.id === attachmentId) return this.get(scope, ref.digest);
|
|
60105
|
-
}
|
|
60106
|
-
return null;
|
|
60107
|
-
}
|
|
60108
|
-
async list(scope) {
|
|
60109
|
-
const refs = [];
|
|
60110
|
-
for (const prefixDir of await this.listDirectory(this.scopeDir(scope))) {
|
|
60111
|
-
if (!prefixDir.isDirectory || !prefixDir.path) continue;
|
|
60112
|
-
for (const entry of await this.listDirectory(prefixDir.path)) {
|
|
60113
|
-
if (entry.isDirectory || !entry.path || !entry.path.endsWith(".json")) continue;
|
|
60114
|
-
const refBytes = await this.readFile(entry.path);
|
|
60115
|
-
if (refBytes) refs.push(parseAttachmentRef(refBytes));
|
|
60116
|
-
}
|
|
60117
|
-
}
|
|
60118
|
-
return refs;
|
|
60119
|
-
}
|
|
60120
|
-
async delete(scope, digest) {
|
|
60121
|
-
if (!await this.deleteFile(this.refPath(scope, digest))) {
|
|
60122
|
-
throw new AttachmentStoreError("NOT_FOUND", `Attachment not found: ${scope}/${digest}`);
|
|
60123
|
-
}
|
|
60124
|
-
await this.deleteFile(this.bytesPath(scope, digest));
|
|
60125
|
-
}
|
|
60126
|
-
// ─── Volume paths ─────────────────────────────────────────────────────────
|
|
60127
|
-
scopeDir(scope) {
|
|
60128
|
-
return `${this.volumeRoot}/${encodeURIComponent(scope)}`;
|
|
60129
|
-
}
|
|
60130
|
-
bytesPath(scope, digest) {
|
|
60131
|
-
return `${this.scopeDir(scope)}/${digest.slice(0, 2)}/${digest}`;
|
|
60132
|
-
}
|
|
60133
|
-
refPath(scope, digest) {
|
|
60134
|
-
return `${this.bytesPath(scope, digest)}.json`;
|
|
60135
|
-
}
|
|
60136
|
-
// ─── Files API ────────────────────────────────────────────────────────────
|
|
60137
|
-
async writeFile(path4, bytes) {
|
|
60138
|
-
await this.client.uploadFile({
|
|
60139
|
-
filePath: path4,
|
|
60140
|
-
overwrite: true,
|
|
60141
|
-
contents: new Blob([viewToBuffer(bytes)]).stream()
|
|
60142
|
-
});
|
|
60143
|
-
}
|
|
60144
|
-
/** Raw file bytes, or `null` when the file does not exist (404). */
|
|
60145
|
-
async readFile(path4) {
|
|
60146
|
-
try {
|
|
60147
|
-
const response = await this.client.downloadFile({ filePath: path4 });
|
|
60148
|
-
if (!response.contents) return new Uint8Array();
|
|
60149
|
-
return new Uint8Array(await new Response(response.contents).arrayBuffer());
|
|
60150
|
-
} catch (error51) {
|
|
60151
|
-
if (isNotFound(error51)) return null;
|
|
60152
|
-
throw error51;
|
|
60153
|
-
}
|
|
60154
|
-
}
|
|
60155
|
-
/** True when the file existed and was deleted; false on 404. */
|
|
60156
|
-
async deleteFile(path4) {
|
|
60157
|
-
try {
|
|
60158
|
-
await this.client.deleteFile({ filePath: path4 });
|
|
60159
|
-
return true;
|
|
60160
|
-
} catch (error51) {
|
|
60161
|
-
if (isNotFound(error51)) return false;
|
|
60162
|
-
throw error51;
|
|
60163
|
-
}
|
|
60164
|
-
}
|
|
60165
|
-
/** Immediate children of a directory; empty for a missing directory (404). */
|
|
60166
|
-
async listDirectory(path4) {
|
|
60167
|
-
const entries = [];
|
|
60168
|
-
let pageToken;
|
|
60169
|
-
do {
|
|
60170
|
-
let listing;
|
|
60171
|
-
try {
|
|
60172
|
-
listing = await this.client.listDirectoryContents({
|
|
60173
|
-
directoryPath: path4,
|
|
60174
|
-
...pageToken ? { pageToken } : {}
|
|
60175
|
-
});
|
|
60176
|
-
} catch (error51) {
|
|
60177
|
-
if (isNotFound(error51)) return entries;
|
|
60178
|
-
throw error51;
|
|
60179
|
-
}
|
|
60180
|
-
entries.push(...listing.contents ?? []);
|
|
60181
|
-
pageToken = listing.nextPageToken;
|
|
60182
|
-
} while (pageToken);
|
|
60183
|
-
return entries;
|
|
60184
|
-
}
|
|
60185
|
-
};
|
|
60186
|
-
function isNotFound(error51) {
|
|
60187
|
-
if (error51 && typeof error51 === "object" && "httpStatusCode" in error51)
|
|
60188
|
-
return error51.httpStatusCode === 404;
|
|
60189
|
-
return /RESOURCE_DOES_NOT_EXIST|does not exist|404/iu.test(String(error51));
|
|
60190
|
-
}
|
|
60191
|
-
function parseAttachmentRef(bytes) {
|
|
60192
|
-
const parsed = JSON.parse(new TextDecoder().decode(bytes));
|
|
60193
|
-
if (typeof parsed.id !== "string" || typeof parsed.mimeType !== "string" || typeof parsed.sizeBytes !== "number" || typeof parsed.digest !== "string") {
|
|
60194
|
-
throw new Error("databricks volumes: malformed attachment ref sidecar");
|
|
60195
|
-
}
|
|
60196
|
-
return {
|
|
60197
|
-
id: parsed.id,
|
|
60198
|
-
mimeType: parsed.mimeType,
|
|
60199
|
-
sizeBytes: parsed.sizeBytes,
|
|
60200
|
-
digest: parsed.digest,
|
|
60201
|
-
...typeof parsed.filename === "string" ? { filename: parsed.filename } : {}
|
|
60202
|
-
};
|
|
60203
|
-
}
|
|
60204
|
-
function viewToBuffer(bytes) {
|
|
60205
|
-
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
60206
|
-
}
|
|
60207
|
-
|
|
60208
|
-
// src/app.ts
|
|
60209
|
-
function databricksApp(options = {}) {
|
|
60210
|
-
registerDatabricksModelProvider();
|
|
60211
|
-
const env2 = options.env ?? (typeof process !== "undefined" ? process.env : {});
|
|
60212
|
-
const principal = options.principal ?? appServicePrincipalFromEnv(env2);
|
|
60213
|
-
if (!principal) {
|
|
60214
|
-
throw new Error(
|
|
60215
|
-
"databricksApp() could not resolve an identity: pass `principal` or set DATABRICKS_HOST + DATABRICKS_CLIENT_ID + DATABRICKS_CLIENT_SECRET (the Databricks Apps runtime provides these)."
|
|
60216
|
-
);
|
|
60217
|
-
}
|
|
60218
|
-
const host = options.host ?? (principal.kind === "service-principal" || principal.kind === "cli-profile" ? principal.host : void 0) ?? (env2.DATABRICKS_HOST ? env2.DATABRICKS_HOST.includes("://") ? env2.DATABRICKS_HOST : `https://${env2.DATABRICKS_HOST}` : void 0);
|
|
60219
|
-
if (!host) {
|
|
60220
|
-
throw new Error(
|
|
60221
|
-
"databricksApp() requires a workspace host: pass `host` or set DATABRICKS_HOST."
|
|
60222
|
-
);
|
|
60223
|
-
}
|
|
60224
|
-
const identity = databricksIdentity(principal);
|
|
60225
|
-
const fabricPrincipal = fabricPrincipalFor(principal, {
|
|
60226
|
-
asAppPrincipal: true,
|
|
60227
|
-
...options.ucPrincipal ? { ucPrincipal: options.ucPrincipal } : {}
|
|
60228
|
-
});
|
|
60229
|
-
const actor = { principal: fabricPrincipal };
|
|
60230
|
-
const native = createDatabricksNativeClients({
|
|
60231
|
-
host,
|
|
60232
|
-
credentials: databricksCredentials(principal),
|
|
60233
|
-
tokenProvider: identity,
|
|
60234
|
-
...options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}
|
|
60235
|
-
});
|
|
60236
|
-
const model = options.model ?? env2.DATABRICKS_MODEL;
|
|
60237
|
-
const envMode = parseInferenceMode(env2.DATABRICKS_INFERENCE_MODE);
|
|
60238
|
-
const modelProvider = databricksFoundationModelProvider({
|
|
60239
|
-
host,
|
|
60240
|
-
token: identity,
|
|
60241
|
-
...model ? { defaultModel: model } : {},
|
|
60242
|
-
...env2.DATABRICKS_AI_GATEWAY_BASE_URL ? { baseUrl: env2.DATABRICKS_AI_GATEWAY_BASE_URL } : {},
|
|
60243
|
-
...envMode ? { mode: envMode } : {},
|
|
60244
|
-
...options.inference ?? {},
|
|
60245
|
-
...options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}
|
|
60246
|
-
});
|
|
60247
|
-
let persistence;
|
|
60248
|
-
if (options.lakebase !== false) {
|
|
60249
|
-
const lakebase = options.lakebase === void 0 ? {} : options.lakebase;
|
|
60250
|
-
const lakebaseHost = lakebase.host ?? env2.DATABRICKS_LAKEBASE_HOST ?? env2.PGHOST;
|
|
60251
|
-
const database = lakebase.database ?? env2.DATABRICKS_LAKEBASE_DATABASE ?? env2.PGDATABASE;
|
|
60252
|
-
const endpoint = lakebase.endpoint ?? env2.DATABRICKS_LAKEBASE_ENDPOINT ?? env2.ENDPOINT_NAME;
|
|
60253
|
-
const user = lakebase.user ?? env2.DATABRICKS_LAKEBASE_USER ?? env2.PGUSER ?? (principal.kind === "service-principal" ? principal.clientId : void 0);
|
|
60254
|
-
if (lakebaseHost && database && user && endpoint) {
|
|
60255
|
-
persistence = databricksPersistence({
|
|
60256
|
-
lakebase: {
|
|
60257
|
-
host: lakebaseHost,
|
|
60258
|
-
database,
|
|
60259
|
-
user,
|
|
60260
|
-
endpoint,
|
|
60261
|
-
credentialClient: native.postgres,
|
|
60262
|
-
...lakebase.port !== void 0 ? { port: lakebase.port } : env2.PGPORT ? { port: Number(env2.PGPORT) } : {},
|
|
60263
|
-
...lakebase.ssl !== void 0 ? { ssl: lakebase.ssl } : {},
|
|
60264
|
-
...lakebase.poolFactory ? { poolFactory: lakebase.poolFactory } : {}
|
|
60265
|
-
},
|
|
60266
|
-
...options.loadPersistenceStores ? { loadStores: options.loadPersistenceStores } : {}
|
|
60267
|
-
});
|
|
60268
|
-
} else if (options.lakebase !== void 0) {
|
|
60269
|
-
throw new Error(
|
|
60270
|
-
"databricksApp({ lakebase }) is missing connection details: provide host/database/user/endpoint or the DATABRICKS_LAKEBASE_* (or PG*/ENDPOINT_NAME) environment variables from the app database resource."
|
|
60271
|
-
);
|
|
60272
|
-
}
|
|
60273
|
-
}
|
|
60274
|
-
const telemetry = persistence && options.telemetry !== false ? databricksTelemetry({ client: persistence.client }) : void 0;
|
|
60275
|
-
const attachmentConfig = options.attachments === false ? void 0 : options.attachments ?? {};
|
|
60276
|
-
const attachmentCatalog = attachmentConfig?.catalog ?? env2.DATABRICKS_CATALOG;
|
|
60277
|
-
const attachmentSchema = attachmentConfig?.schema ?? env2.DATABRICKS_SCHEMA;
|
|
60278
|
-
const attachmentVolume = attachmentConfig?.volume ?? env2.DATABRICKS_VOLUME;
|
|
60279
|
-
const attachmentStore = attachmentCatalog && attachmentSchema && attachmentVolume ? new UcVolumesAttachmentStore({
|
|
60280
|
-
client: native.files,
|
|
60281
|
-
catalog: attachmentCatalog,
|
|
60282
|
-
schema: attachmentSchema,
|
|
60283
|
-
volume: attachmentVolume,
|
|
60284
|
-
rootPrefix: attachmentConfig?.rootPrefix ?? env2.DATABRICKS_VOLUME_ROOT ?? "fh-attachments",
|
|
60285
|
-
...options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}
|
|
60286
|
-
}) : void 0;
|
|
60287
|
-
return {
|
|
60288
|
-
identity,
|
|
60289
|
-
principal: fabricPrincipal,
|
|
60290
|
-
actor,
|
|
60291
|
-
modelProvider,
|
|
60292
|
-
...persistence ? { persistence } : {},
|
|
60293
|
-
...telemetry ? { telemetry } : {},
|
|
60294
|
-
...attachmentStore ? { attachmentStore } : {},
|
|
60295
|
-
mlflowTraceExporter: (traceOptions) => mlflowTraceExporter({ client: native.rawProtocol, ...traceOptions }),
|
|
60296
|
-
async serverOptions() {
|
|
60297
|
-
if (!persistence) return attachmentStore ? { attachmentStore } : {};
|
|
60298
|
-
const { store, submissionStore, conversationStreamStore } = await persistence.connectAll();
|
|
60299
|
-
return {
|
|
60300
|
-
sessionStore: store,
|
|
60301
|
-
submissionStore,
|
|
60302
|
-
conversationStreamStore,
|
|
60303
|
-
...telemetry ? { telemetry: telemetry.sink } : {},
|
|
60304
|
-
...attachmentStore ? { attachmentStore } : {}
|
|
60305
|
-
};
|
|
60306
|
-
},
|
|
60307
|
-
onBehalfOf(headers) {
|
|
60308
|
-
const user = onBehalfOfFromHeaders(headers);
|
|
60309
|
-
if (!user) return void 0;
|
|
60310
|
-
return {
|
|
60311
|
-
identity: databricksIdentity(user),
|
|
60312
|
-
actor: { principal: fabricPrincipalFor(user), onBehalfOf: user.label ?? "user" }
|
|
60313
|
-
};
|
|
60314
|
-
},
|
|
60315
|
-
async close() {
|
|
60316
|
-
await persistence?.close();
|
|
60317
|
-
}
|
|
60318
|
-
};
|
|
60319
|
-
}
|
|
60320
|
-
function parseInferenceMode(value) {
|
|
60321
|
-
if (!value) return void 0;
|
|
60322
|
-
if (value === "auto" || value === "ai-gateway" || value === "serving-endpoints") return value;
|
|
60323
|
-
throw new Error(
|
|
60324
|
-
`Invalid DATABRICKS_INFERENCE_MODE "${value}". Use auto, ai-gateway, or serving-endpoints.`
|
|
60325
|
-
);
|
|
60326
|
-
}
|
|
60327
|
-
|
|
60328
60577
|
// src/app-user-authorization.ts
|
|
60329
60578
|
import { createHash as createHash3 } from "crypto";
|
|
60330
60579
|
var DATABRICKS_APP_USER_PERMISSIONS = [
|
|
@@ -60354,7 +60603,7 @@ function createDatabricksAppUserAuthenticator(options) {
|
|
|
60354
60603
|
id: forwardedUser.id,
|
|
60355
60604
|
kind: "user",
|
|
60356
60605
|
provider: "databricks-apps",
|
|
60357
|
-
tenantId:
|
|
60606
|
+
tenantId: databricksPrincipalTenantId("user", forwardedUser.id),
|
|
60358
60607
|
permissions: [...permissions],
|
|
60359
60608
|
...forwardedUser.displayName ? { displayName: forwardedUser.displayName } : {},
|
|
60360
60609
|
...forwardedUser.ucPrincipal ? { ucPrincipal: forwardedUser.ucPrincipal } : {}
|
|
@@ -60376,7 +60625,7 @@ function createDatabricksAppUserAuthenticator(options) {
|
|
|
60376
60625
|
id,
|
|
60377
60626
|
kind: "service-principal",
|
|
60378
60627
|
provider: "databricks-apps",
|
|
60379
|
-
tenantId:
|
|
60628
|
+
tenantId: databricksPrincipalTenantId("service-principal", id),
|
|
60380
60629
|
permissions: [...permissions]
|
|
60381
60630
|
};
|
|
60382
60631
|
}
|
|
@@ -60392,7 +60641,7 @@ function createDatabricksAppUserAuthenticator(options) {
|
|
|
60392
60641
|
...options.now ? { now: options.now } : {}
|
|
60393
60642
|
});
|
|
60394
60643
|
const id = inspection.principal.id;
|
|
60395
|
-
const tenantId = options.tenantId?.(inspection) ??
|
|
60644
|
+
const tenantId = options.tenantId?.(inspection) ?? databricksPrincipalTenantId("user", id);
|
|
60396
60645
|
if (!tenantId) return false;
|
|
60397
60646
|
const principal = {
|
|
60398
60647
|
id,
|
|
@@ -60420,10 +60669,13 @@ function appPrincipalFor(id, permissions) {
|
|
|
60420
60669
|
id,
|
|
60421
60670
|
kind: "app-principal",
|
|
60422
60671
|
provider: "databricks-apps",
|
|
60423
|
-
tenantId:
|
|
60672
|
+
tenantId: databricksPrincipalTenantId("app", id),
|
|
60424
60673
|
permissions: [...permissions]
|
|
60425
60674
|
};
|
|
60426
60675
|
}
|
|
60676
|
+
function databricksPrincipalTenantId(kind, id) {
|
|
60677
|
+
return `databricks-${kind}:${createHash3("sha256").update(id).digest("hex").slice(0, 24)}`;
|
|
60678
|
+
}
|
|
60427
60679
|
async function isAppAuthorizedCaller(headers, delegated, allowed) {
|
|
60428
60680
|
const forwarded = forwardedIdentity(headers);
|
|
60429
60681
|
if (forwarded && allowed.has(forwarded)) return true;
|
|
@@ -60522,6 +60774,275 @@ function jwtLifetimeClaims(token) {
|
|
|
60522
60774
|
}
|
|
60523
60775
|
}
|
|
60524
60776
|
|
|
60777
|
+
// src/volumes-attachment-store.ts
|
|
60778
|
+
import {
|
|
60779
|
+
AttachmentStoreError,
|
|
60780
|
+
verifyAttachmentBytes
|
|
60781
|
+
} from "@fabric-harness/sdk";
|
|
60782
|
+
var UcVolumesAttachmentStore = class {
|
|
60783
|
+
client;
|
|
60784
|
+
volumeRoot;
|
|
60785
|
+
rootPrefix;
|
|
60786
|
+
constructor(options) {
|
|
60787
|
+
this.client = options.client;
|
|
60788
|
+
this.rootPrefix = options.rootPrefix ?? "fh-attachments";
|
|
60789
|
+
this.volumeRoot = `/Volumes/${options.catalog}/${options.schema}/${options.volume}/${this.rootPrefix}`;
|
|
60790
|
+
}
|
|
60791
|
+
async put(input) {
|
|
60792
|
+
await verifyAttachmentBytes(input.ref, input.bytes);
|
|
60793
|
+
const refPath = this.refPath(input.scope, input.ref.digest);
|
|
60794
|
+
if (await this.readFile(refPath)) return;
|
|
60795
|
+
await this.writeFile(this.bytesPath(input.scope, input.ref.digest), input.bytes);
|
|
60796
|
+
await this.writeFile(refPath, new TextEncoder().encode(JSON.stringify(input.ref)));
|
|
60797
|
+
}
|
|
60798
|
+
async get(scope, digest) {
|
|
60799
|
+
const refBytes = await this.readFile(this.refPath(scope, digest));
|
|
60800
|
+
if (!refBytes) return null;
|
|
60801
|
+
const ref = parseAttachmentRef(refBytes);
|
|
60802
|
+
const bytes = await this.readFile(this.bytesPath(scope, digest));
|
|
60803
|
+
if (!bytes) return null;
|
|
60804
|
+
return { ref, bytes };
|
|
60805
|
+
}
|
|
60806
|
+
async getByAttachmentId(scope, attachmentId) {
|
|
60807
|
+
for (const ref of await this.list(scope)) {
|
|
60808
|
+
if (ref.id === attachmentId) return this.get(scope, ref.digest);
|
|
60809
|
+
}
|
|
60810
|
+
return null;
|
|
60811
|
+
}
|
|
60812
|
+
async list(scope) {
|
|
60813
|
+
const refs = [];
|
|
60814
|
+
for (const prefixDir of await this.listDirectory(this.scopeDir(scope))) {
|
|
60815
|
+
if (!prefixDir.isDirectory || !prefixDir.path) continue;
|
|
60816
|
+
for (const entry of await this.listDirectory(prefixDir.path)) {
|
|
60817
|
+
if (entry.isDirectory || !entry.path || !entry.path.endsWith(".json")) continue;
|
|
60818
|
+
const refBytes = await this.readFile(entry.path);
|
|
60819
|
+
if (refBytes) refs.push(parseAttachmentRef(refBytes));
|
|
60820
|
+
}
|
|
60821
|
+
}
|
|
60822
|
+
return refs;
|
|
60823
|
+
}
|
|
60824
|
+
async delete(scope, digest) {
|
|
60825
|
+
if (!await this.deleteFile(this.refPath(scope, digest))) {
|
|
60826
|
+
throw new AttachmentStoreError("NOT_FOUND", `Attachment not found: ${scope}/${digest}`);
|
|
60827
|
+
}
|
|
60828
|
+
await this.deleteFile(this.bytesPath(scope, digest));
|
|
60829
|
+
}
|
|
60830
|
+
// ─── Volume paths ─────────────────────────────────────────────────────────
|
|
60831
|
+
scopeDir(scope) {
|
|
60832
|
+
return `${this.volumeRoot}/${encodeURIComponent(scope)}`;
|
|
60833
|
+
}
|
|
60834
|
+
bytesPath(scope, digest) {
|
|
60835
|
+
return `${this.scopeDir(scope)}/${digest.slice(0, 2)}/${digest}`;
|
|
60836
|
+
}
|
|
60837
|
+
refPath(scope, digest) {
|
|
60838
|
+
return `${this.bytesPath(scope, digest)}.json`;
|
|
60839
|
+
}
|
|
60840
|
+
// ─── Files API ────────────────────────────────────────────────────────────
|
|
60841
|
+
async writeFile(path4, bytes) {
|
|
60842
|
+
await this.client.uploadFile({
|
|
60843
|
+
filePath: path4,
|
|
60844
|
+
overwrite: true,
|
|
60845
|
+
contents: new Blob([viewToBuffer(bytes)]).stream()
|
|
60846
|
+
});
|
|
60847
|
+
}
|
|
60848
|
+
/** Raw file bytes, or `null` when the file does not exist (404). */
|
|
60849
|
+
async readFile(path4) {
|
|
60850
|
+
try {
|
|
60851
|
+
const response = await this.client.downloadFile({ filePath: path4 });
|
|
60852
|
+
if (!response.contents) return new Uint8Array();
|
|
60853
|
+
return new Uint8Array(await new Response(response.contents).arrayBuffer());
|
|
60854
|
+
} catch (error51) {
|
|
60855
|
+
if (isNotFound(error51)) return null;
|
|
60856
|
+
throw error51;
|
|
60857
|
+
}
|
|
60858
|
+
}
|
|
60859
|
+
/** True when the file existed and was deleted; false on 404. */
|
|
60860
|
+
async deleteFile(path4) {
|
|
60861
|
+
try {
|
|
60862
|
+
await this.client.deleteFile({ filePath: path4 });
|
|
60863
|
+
return true;
|
|
60864
|
+
} catch (error51) {
|
|
60865
|
+
if (isNotFound(error51)) return false;
|
|
60866
|
+
throw error51;
|
|
60867
|
+
}
|
|
60868
|
+
}
|
|
60869
|
+
/** Immediate children of a directory; empty for a missing directory (404). */
|
|
60870
|
+
async listDirectory(path4) {
|
|
60871
|
+
const entries = [];
|
|
60872
|
+
let pageToken;
|
|
60873
|
+
do {
|
|
60874
|
+
let listing;
|
|
60875
|
+
try {
|
|
60876
|
+
listing = await this.client.listDirectoryContents({
|
|
60877
|
+
directoryPath: path4,
|
|
60878
|
+
...pageToken ? { pageToken } : {}
|
|
60879
|
+
});
|
|
60880
|
+
} catch (error51) {
|
|
60881
|
+
if (isNotFound(error51)) return entries;
|
|
60882
|
+
throw error51;
|
|
60883
|
+
}
|
|
60884
|
+
entries.push(...listing.contents ?? []);
|
|
60885
|
+
pageToken = listing.nextPageToken;
|
|
60886
|
+
} while (pageToken);
|
|
60887
|
+
return entries;
|
|
60888
|
+
}
|
|
60889
|
+
};
|
|
60890
|
+
function isNotFound(error51) {
|
|
60891
|
+
if (error51 && typeof error51 === "object" && "httpStatusCode" in error51)
|
|
60892
|
+
return error51.httpStatusCode === 404;
|
|
60893
|
+
return /RESOURCE_DOES_NOT_EXIST|does not exist|404/iu.test(String(error51));
|
|
60894
|
+
}
|
|
60895
|
+
function parseAttachmentRef(bytes) {
|
|
60896
|
+
const parsed = JSON.parse(new TextDecoder().decode(bytes));
|
|
60897
|
+
if (typeof parsed.id !== "string" || typeof parsed.mimeType !== "string" || typeof parsed.sizeBytes !== "number" || typeof parsed.digest !== "string") {
|
|
60898
|
+
throw new Error("databricks volumes: malformed attachment ref sidecar");
|
|
60899
|
+
}
|
|
60900
|
+
return {
|
|
60901
|
+
id: parsed.id,
|
|
60902
|
+
mimeType: parsed.mimeType,
|
|
60903
|
+
sizeBytes: parsed.sizeBytes,
|
|
60904
|
+
digest: parsed.digest,
|
|
60905
|
+
...typeof parsed.filename === "string" ? { filename: parsed.filename } : {}
|
|
60906
|
+
};
|
|
60907
|
+
}
|
|
60908
|
+
function viewToBuffer(bytes) {
|
|
60909
|
+
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
60910
|
+
}
|
|
60911
|
+
|
|
60912
|
+
// src/app.ts
|
|
60913
|
+
function databricksApp(options = {}) {
|
|
60914
|
+
registerDatabricksModelProvider();
|
|
60915
|
+
const env2 = options.env ?? (typeof process !== "undefined" ? process.env : {});
|
|
60916
|
+
const principal = options.principal ?? appServicePrincipalFromEnv(env2);
|
|
60917
|
+
if (!principal) {
|
|
60918
|
+
throw new Error(
|
|
60919
|
+
"databricksApp() could not resolve an identity: pass `principal` or set DATABRICKS_HOST + DATABRICKS_CLIENT_ID + DATABRICKS_CLIENT_SECRET (the Databricks Apps runtime provides these)."
|
|
60920
|
+
);
|
|
60921
|
+
}
|
|
60922
|
+
const host = options.host ?? (principal.kind === "service-principal" || principal.kind === "cli-profile" ? principal.host : void 0) ?? (env2.DATABRICKS_HOST ? env2.DATABRICKS_HOST.includes("://") ? env2.DATABRICKS_HOST : `https://${env2.DATABRICKS_HOST}` : void 0);
|
|
60923
|
+
if (!host) {
|
|
60924
|
+
throw new Error(
|
|
60925
|
+
"databricksApp() requires a workspace host: pass `host` or set DATABRICKS_HOST."
|
|
60926
|
+
);
|
|
60927
|
+
}
|
|
60928
|
+
const identity = databricksIdentity(principal);
|
|
60929
|
+
const fabricPrincipal = fabricPrincipalFor(principal, {
|
|
60930
|
+
asAppPrincipal: true,
|
|
60931
|
+
...options.ucPrincipal ? { ucPrincipal: options.ucPrincipal } : {}
|
|
60932
|
+
});
|
|
60933
|
+
const actor = { principal: fabricPrincipal };
|
|
60934
|
+
const schedulerIdentity = {
|
|
60935
|
+
tenantId: databricksPrincipalTenantId("app", fabricPrincipal.id),
|
|
60936
|
+
actor
|
|
60937
|
+
};
|
|
60938
|
+
const native = createDatabricksNativeClients({
|
|
60939
|
+
host,
|
|
60940
|
+
credentials: databricksCredentials(principal),
|
|
60941
|
+
tokenProvider: identity,
|
|
60942
|
+
...options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}
|
|
60943
|
+
});
|
|
60944
|
+
const model = options.model ?? env2.DATABRICKS_MODEL;
|
|
60945
|
+
const envMode = parseInferenceMode(env2.DATABRICKS_INFERENCE_MODE);
|
|
60946
|
+
const modelProvider = databricksFoundationModelProvider({
|
|
60947
|
+
host,
|
|
60948
|
+
token: identity,
|
|
60949
|
+
...model ? { defaultModel: model } : {},
|
|
60950
|
+
...env2.DATABRICKS_AI_GATEWAY_BASE_URL ? { baseUrl: env2.DATABRICKS_AI_GATEWAY_BASE_URL } : {},
|
|
60951
|
+
...envMode ? { mode: envMode } : {},
|
|
60952
|
+
...options.inference ?? {},
|
|
60953
|
+
...options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}
|
|
60954
|
+
});
|
|
60955
|
+
let persistence;
|
|
60956
|
+
if (options.lakebase !== false) {
|
|
60957
|
+
const lakebase = options.lakebase === void 0 ? {} : options.lakebase;
|
|
60958
|
+
const lakebaseHost = lakebase.host ?? env2.DATABRICKS_LAKEBASE_HOST ?? env2.PGHOST;
|
|
60959
|
+
const database = lakebase.database ?? env2.DATABRICKS_LAKEBASE_DATABASE ?? env2.PGDATABASE;
|
|
60960
|
+
const endpoint = lakebase.endpoint ?? env2.DATABRICKS_LAKEBASE_ENDPOINT ?? env2.ENDPOINT_NAME;
|
|
60961
|
+
const user = lakebase.user ?? env2.DATABRICKS_LAKEBASE_USER ?? env2.PGUSER ?? (principal.kind === "service-principal" ? principal.clientId : void 0);
|
|
60962
|
+
if (lakebaseHost && database && user && endpoint) {
|
|
60963
|
+
persistence = databricksPersistence({
|
|
60964
|
+
lakebase: {
|
|
60965
|
+
host: lakebaseHost,
|
|
60966
|
+
database,
|
|
60967
|
+
user,
|
|
60968
|
+
endpoint,
|
|
60969
|
+
credentialClient: native.postgres,
|
|
60970
|
+
...lakebase.port !== void 0 ? { port: lakebase.port } : env2.PGPORT ? { port: Number(env2.PGPORT) } : {},
|
|
60971
|
+
...lakebase.ssl !== void 0 ? { ssl: lakebase.ssl } : {},
|
|
60972
|
+
...lakebase.poolFactory ? { poolFactory: lakebase.poolFactory } : {}
|
|
60973
|
+
},
|
|
60974
|
+
...options.loadPersistenceStores ? { loadStores: options.loadPersistenceStores } : {}
|
|
60975
|
+
});
|
|
60976
|
+
} else if (options.lakebase !== void 0) {
|
|
60977
|
+
throw new Error(
|
|
60978
|
+
"databricksApp({ lakebase }) is missing connection details: provide host/database/user/endpoint or the DATABRICKS_LAKEBASE_* (or PG*/ENDPOINT_NAME) environment variables from the app database resource."
|
|
60979
|
+
);
|
|
60980
|
+
}
|
|
60981
|
+
}
|
|
60982
|
+
const telemetry = persistence && options.telemetry !== false ? databricksTelemetry({ client: persistence.client }) : void 0;
|
|
60983
|
+
const attachmentConfig = options.attachments === false ? void 0 : options.attachments ?? {};
|
|
60984
|
+
const attachmentCatalog = attachmentConfig?.catalog ?? env2.DATABRICKS_CATALOG;
|
|
60985
|
+
const attachmentSchema = attachmentConfig?.schema ?? env2.DATABRICKS_SCHEMA;
|
|
60986
|
+
const attachmentVolume = attachmentConfig?.volume ?? env2.DATABRICKS_VOLUME;
|
|
60987
|
+
const attachmentStore = attachmentCatalog && attachmentSchema && attachmentVolume ? new UcVolumesAttachmentStore({
|
|
60988
|
+
client: native.files,
|
|
60989
|
+
catalog: attachmentCatalog,
|
|
60990
|
+
schema: attachmentSchema,
|
|
60991
|
+
volume: attachmentVolume,
|
|
60992
|
+
rootPrefix: attachmentConfig?.rootPrefix ?? env2.DATABRICKS_VOLUME_ROOT ?? "fh-attachments",
|
|
60993
|
+
...options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}
|
|
60994
|
+
}) : void 0;
|
|
60995
|
+
return {
|
|
60996
|
+
identity,
|
|
60997
|
+
principal: fabricPrincipal,
|
|
60998
|
+
actor,
|
|
60999
|
+
modelProvider,
|
|
61000
|
+
...persistence ? { persistence } : {},
|
|
61001
|
+
...telemetry ? { telemetry } : {},
|
|
61002
|
+
...attachmentStore ? { attachmentStore } : {},
|
|
61003
|
+
mlflowTraceExporter: (traceOptions) => mlflowTraceExporter({ client: native.rawProtocol, ...traceOptions }),
|
|
61004
|
+
async serverOptions() {
|
|
61005
|
+
if (!persistence)
|
|
61006
|
+
return {
|
|
61007
|
+
scheduler: { identity: () => schedulerIdentity, catchUp: "skip" },
|
|
61008
|
+
...attachmentStore ? { attachmentStore } : {}
|
|
61009
|
+
};
|
|
61010
|
+
const { store, submissionStore, conversationStreamStore } = await persistence.connectAll();
|
|
61011
|
+
const schedulerLeaseStore = await persistence.connectSchedulerLeaseStore();
|
|
61012
|
+
return {
|
|
61013
|
+
sessionStore: store,
|
|
61014
|
+
submissionStore,
|
|
61015
|
+
conversationStreamStore,
|
|
61016
|
+
...telemetry ? { telemetry: telemetry.sink } : {},
|
|
61017
|
+
...attachmentStore ? { attachmentStore } : {},
|
|
61018
|
+
scheduler: {
|
|
61019
|
+
identity: () => schedulerIdentity,
|
|
61020
|
+
...schedulerLeaseStore ? { leaseStore: schedulerLeaseStore } : {},
|
|
61021
|
+
catchUp: "run-once"
|
|
61022
|
+
}
|
|
61023
|
+
};
|
|
61024
|
+
},
|
|
61025
|
+
onBehalfOf(headers) {
|
|
61026
|
+
const user = onBehalfOfFromHeaders(headers);
|
|
61027
|
+
if (!user) return void 0;
|
|
61028
|
+
return {
|
|
61029
|
+
identity: databricksIdentity(user),
|
|
61030
|
+
actor: { principal: fabricPrincipalFor(user), onBehalfOf: user.label ?? "user" }
|
|
61031
|
+
};
|
|
61032
|
+
},
|
|
61033
|
+
async close() {
|
|
61034
|
+
await persistence?.close();
|
|
61035
|
+
}
|
|
61036
|
+
};
|
|
61037
|
+
}
|
|
61038
|
+
function parseInferenceMode(value) {
|
|
61039
|
+
if (!value) return void 0;
|
|
61040
|
+
if (value === "auto" || value === "ai-gateway" || value === "serving-endpoints") return value;
|
|
61041
|
+
throw new Error(
|
|
61042
|
+
`Invalid DATABRICKS_INFERENCE_MODE "${value}". Use auto, ai-gateway, or serving-endpoints.`
|
|
61043
|
+
);
|
|
61044
|
+
}
|
|
61045
|
+
|
|
60525
61046
|
// src/serving-usage.ts
|
|
60526
61047
|
import { currentSubmissionContext as currentSubmissionContext3, emitSubmissionTelemetry } from "@fabric-harness/sdk";
|
|
60527
61048
|
function servingUsageCapture(options) {
|
|
@@ -62168,7 +62689,7 @@ var DATABRICKS_API_VERSIONS = {
|
|
|
62168
62689
|
var DATABRICKS_PACKAGE_COMPATIBILITY = {
|
|
62169
62690
|
node: ">=22.0.0",
|
|
62170
62691
|
package: "@fabric-harness/databricks",
|
|
62171
|
-
packageRange: ">=
|
|
62692
|
+
packageRange: ">=6.0.0 <7",
|
|
62172
62693
|
pg: "^8.11.0 (only for Lakebase)"
|
|
62173
62694
|
};
|
|
62174
62695
|
var DATABRICKS_AUTH_MODES = [
|
|
@@ -62658,7 +63179,17 @@ var DATABRICKS_CAPABILITY_DEFINITIONS = [
|
|
|
62658
63179
|
certification: "protected-live",
|
|
62659
63180
|
auth: ["oauth-m2m", "app-service-principal", "pat"],
|
|
62660
63181
|
contractClouds: ALL_CLOUDS,
|
|
62661
|
-
surfaces: [
|
|
63182
|
+
surfaces: [
|
|
63183
|
+
{
|
|
63184
|
+
package: "@fabric-harness/databricks",
|
|
63185
|
+
exports: [
|
|
63186
|
+
"databricks",
|
|
63187
|
+
"scoreRagTurn",
|
|
63188
|
+
"databricksMlflowLogMetricTool",
|
|
63189
|
+
"databricksMlflowLogParamTool"
|
|
63190
|
+
]
|
|
63191
|
+
}
|
|
63192
|
+
],
|
|
62662
63193
|
requiredEvidence: ["mlflow.trace", "mlflow.evaluate"],
|
|
62663
63194
|
evidenceIds: ["dbx-cert-d03df5a0a5b69a98d8acb0ad4c1e9ef9bcffefea7e433cbd2ba0ff3d792fec71"],
|
|
62664
63195
|
docs: "/docs/databricks/rag",
|
|
@@ -62708,7 +63239,7 @@ var DATABRICKS_CAPABILITY_DEFINITIONS = [
|
|
|
62708
63239
|
requiredEvidence: ["lakeflow.read", "lakeflow.execute"],
|
|
62709
63240
|
evidenceIds: [CURRENT_CONSUMPTION_EVIDENCE_ID],
|
|
62710
63241
|
docs: "/docs/databricks/integrations",
|
|
62711
|
-
notes: "
|
|
63242
|
+
notes: "List/status are read-only defaults. Model-callable start/stop require a construction-time pipeline policy; read/execute evidence remains separate from authoring lifecycle evidence."
|
|
62712
63243
|
},
|
|
62713
63244
|
{
|
|
62714
63245
|
id: "automation-bundles",
|
|
@@ -63600,7 +64131,8 @@ function defineDatabricksAgent(options = {}) {
|
|
|
63600
64131
|
...directTools.length > 0 ? { tools: directTools } : {},
|
|
63601
64132
|
run: async (context) => {
|
|
63602
64133
|
const env2 = context.env ?? {};
|
|
63603
|
-
const
|
|
64134
|
+
const baseConfig = explicitConfig ?? databricksConfigFromEnv(env2, { analyticsCopilot });
|
|
64135
|
+
const config2 = baseConfig.warehouseId && !baseConfig.sqlRead && toolRefs.some((ref) => ref === "sql" || ref === "sql-read" || ref === "sql_read") ? { ...baseConfig, sqlRead: true } : baseConfig;
|
|
63604
64136
|
const bundle = config2.mcp?.length ? await databricksWithManagedMcp(config2) : databricks(config2);
|
|
63605
64137
|
try {
|
|
63606
64138
|
const analyticsCostLimit = analyticsCopilot ? databricksAnalyticsCostLimitFromEnv(env2, config2, bundle) : void 0;
|
|
@@ -63701,7 +64233,7 @@ function resolveToolRefs(bundle, refs) {
|
|
|
63701
64233
|
toolMap.set(tool7.name, tool7);
|
|
63702
64234
|
}
|
|
63703
64235
|
const shortNameMap = {
|
|
63704
|
-
sql: "
|
|
64236
|
+
sql: "sql_read",
|
|
63705
64237
|
"sql-read": "sql_read",
|
|
63706
64238
|
tables: "databricks_unity_catalog_tables",
|
|
63707
64239
|
"table-info": "databricks_table_info",
|
|
@@ -64283,6 +64815,7 @@ async function databricksWithManagedMcp(config2, scope) {
|
|
|
64283
64815
|
}
|
|
64284
64816
|
function buildDatabricksBundle(config2, scope) {
|
|
64285
64817
|
registerDatabricksModelProvider();
|
|
64818
|
+
const assetBundles = buildAssetBundleLifecycles(config2);
|
|
64286
64819
|
const genie = normalizeGenieConfig(config2);
|
|
64287
64820
|
validateAuthoringConfig(config2, genie);
|
|
64288
64821
|
const identity = scope?.identity ?? databricksIdentity(config2.principal);
|
|
@@ -64296,12 +64829,8 @@ function buildDatabricksBundle(config2, scope) {
|
|
|
64296
64829
|
const client = native.rawProtocol;
|
|
64297
64830
|
const genieAgentModeClient = genie.agentMode ? databricksGenieAgentMode(client, genie.agentMode) : void 0;
|
|
64298
64831
|
const agentServicesClient = config2.agentServices ? databricksAgentServices(client, config2.agentServices) : void 0;
|
|
64299
|
-
const
|
|
64300
|
-
|
|
64301
|
-
...config2.assetBundles.target ? { target: config2.assetBundles.target } : {},
|
|
64302
|
-
...config2.assetBundles.store ? { store: config2.assetBundles.store } : {},
|
|
64303
|
-
principalLabel: config2.governance?.principalLabel ?? principalLabel(config2.principal)
|
|
64304
|
-
}) : void 0;
|
|
64832
|
+
const namedAssetBundles = assetBundles instanceof Map ? Object.freeze(Object.fromEntries(assetBundles)) : void 0;
|
|
64833
|
+
const assetBundle = assetBundles instanceof Map ? assetBundles.size === 1 ? [...assetBundles.values()][0] : void 0 : assetBundles;
|
|
64305
64834
|
let embeddings;
|
|
64306
64835
|
let retriever;
|
|
64307
64836
|
let searchTool;
|
|
@@ -64336,11 +64865,19 @@ function buildDatabricksBundle(config2, scope) {
|
|
|
64336
64865
|
}
|
|
64337
64866
|
const rawTools = [
|
|
64338
64867
|
...config2.sqlRead && config2.warehouseId ? [databricksSqlReadTool(native.statements, { warehouseId: config2.warehouseId })] : [],
|
|
64339
|
-
...config2.
|
|
64868
|
+
...config2.sqlExecute && config2.warehouseId ? [
|
|
64869
|
+
databricksSqlTool(native.statements, config2.sqlExecute, {
|
|
64870
|
+
warehouseId: config2.warehouseId
|
|
64871
|
+
})
|
|
64872
|
+
] : [],
|
|
64340
64873
|
unityCatalogTablesTool(native.tables),
|
|
64341
64874
|
databricksTableInfoTool(native.tables),
|
|
64342
64875
|
...searchTool ? [searchTool] : [],
|
|
64343
|
-
...config2.aiFunctions && config2.warehouseId ? [
|
|
64876
|
+
...config2.aiFunctions && config2.warehouseId ? [
|
|
64877
|
+
databricksAiQueryTool(native.statements, config2.aiFunctions, {
|
|
64878
|
+
warehouseId: config2.warehouseId
|
|
64879
|
+
})
|
|
64880
|
+
] : [],
|
|
64344
64881
|
...genie.conversations ? [
|
|
64345
64882
|
databricksGenieTool(native.genie, {
|
|
64346
64883
|
...genie.conversations,
|
|
@@ -64366,7 +64903,10 @@ function buildDatabricksBundle(config2, scope) {
|
|
|
64366
64903
|
...genie.manage.sqlPolicy ? { sqlPolicy: genie.manage.sqlPolicy } : {}
|
|
64367
64904
|
}
|
|
64368
64905
|
) : [],
|
|
64369
|
-
...config2.lakeflow ? databricksLakeflowTools(
|
|
64906
|
+
...config2.lakeflow ? databricksLakeflowTools(
|
|
64907
|
+
native.pipelines,
|
|
64908
|
+
typeof config2.lakeflow === "object" ? config2.lakeflow.runPolicy : void 0
|
|
64909
|
+
) : [],
|
|
64370
64910
|
...config2.consumption && config2.warehouseId ? [
|
|
64371
64911
|
databricksConsumptionTool(native.statements, {
|
|
64372
64912
|
warehouseId: config2.warehouseId
|
|
@@ -64383,7 +64923,7 @@ function buildDatabricksBundle(config2, scope) {
|
|
|
64383
64923
|
...config2.lakeflowAuthoring ? databricksLakeflowAuthoringTools(native.pipelines, {
|
|
64384
64924
|
...config2.lakeflowEvents && config2.warehouseId ? { warehouseId: config2.warehouseId, statements: native.statements } : {}
|
|
64385
64925
|
}) : [],
|
|
64386
|
-
...
|
|
64926
|
+
...assetBundles ? databricksAssetBundleTools(assetBundles) : [],
|
|
64387
64927
|
...config2.aiSearchAdmin ? databricksAiSearchAdminTools(native.vectorSearch) : [],
|
|
64388
64928
|
...config2.servingAdmin ? databricksServingAdminTools(native.modelServing) : [],
|
|
64389
64929
|
...config2.ucAdmin ? databricksUnityCatalogAdminTools(
|
|
@@ -64403,16 +64943,19 @@ function buildDatabricksBundle(config2, scope) {
|
|
|
64403
64943
|
...config2.tools ?? []
|
|
64404
64944
|
];
|
|
64405
64945
|
const authoringServices = enabledAuthoringServices(config2);
|
|
64406
|
-
const
|
|
64407
|
-
const
|
|
64946
|
+
const approvalServices = config2.governance?.approvalServices;
|
|
64947
|
+
const approvalRequiredToolNames = new Set(
|
|
64408
64948
|
rawTools.filter((tool7) => {
|
|
64409
64949
|
const effect = tool7.metadata?.effect;
|
|
64410
|
-
|
|
64950
|
+
if (effect !== "write" && effect !== "execute") return false;
|
|
64951
|
+
if (!approvalServices) return true;
|
|
64952
|
+
const service = tool7.metadata?.service;
|
|
64953
|
+
return typeof service === "string" && approvalServices.includes(service);
|
|
64411
64954
|
}).map((tool7) => tool7.name)
|
|
64412
64955
|
);
|
|
64413
64956
|
for (const tool7 of rawTools) {
|
|
64414
64957
|
const effect = tool7.metadata?.effect;
|
|
64415
|
-
if (
|
|
64958
|
+
if (effect === "write" || effect === "execute")
|
|
64416
64959
|
validateDatabricksGovernanceDescriptor(tool7, true);
|
|
64417
64960
|
}
|
|
64418
64961
|
const tools = withGovernanceTools(rawTools, {
|
|
@@ -64420,7 +64963,7 @@ function buildDatabricksBundle(config2, scope) {
|
|
|
64420
64963
|
...config2.governance?.onLineage ? { onLineage: config2.governance.onLineage } : {},
|
|
64421
64964
|
...config2.governance?.catalogs ? { catalogs: config2.governance.catalogs } : {},
|
|
64422
64965
|
executingPrincipal,
|
|
64423
|
-
...config2.governance?.stewardAudience && !config2.allowUnapprovedAuthoring ? { requireApprovalGrantForTools: [...
|
|
64966
|
+
...config2.governance?.stewardAudience && !config2.allowUnapprovedAuthoring ? { requireApprovalGrantForTools: [...approvalRequiredToolNames] } : {}
|
|
64424
64967
|
});
|
|
64425
64968
|
const policy = databricksGovernancePolicy({
|
|
64426
64969
|
tools,
|
|
@@ -64463,6 +65006,7 @@ function buildDatabricksBundle(config2, scope) {
|
|
|
64463
65006
|
...genieAgentModeClient ? { genieAgentMode: genieAgentModeClient } : {},
|
|
64464
65007
|
...agentServicesClient ? { agentServices: agentServicesClient } : {},
|
|
64465
65008
|
...assetBundle ? { assetBundle } : {},
|
|
65009
|
+
...namedAssetBundles ? { assetBundles: namedAssetBundles } : {},
|
|
64466
65010
|
aiGateway: {
|
|
64467
65011
|
ensure: () => ensureDatabricksAiGateway(client),
|
|
64468
65012
|
listModelServices: (options) => listDatabricksModelServices(client, options),
|
|
@@ -64491,6 +65035,36 @@ function buildDatabricksBundle(config2, scope) {
|
|
|
64491
65035
|
}
|
|
64492
65036
|
return bundle;
|
|
64493
65037
|
}
|
|
65038
|
+
function buildAssetBundleLifecycles(config2) {
|
|
65039
|
+
const assetBundles = config2.assetBundles;
|
|
65040
|
+
if (assetBundles === void 0) return void 0;
|
|
65041
|
+
const label = config2.governance?.principalLabel ?? principalLabel(config2.principal);
|
|
65042
|
+
if (isDatabricksAssetBundleEntry(assetBundles))
|
|
65043
|
+
return databricksAssetBundleLifecycle({
|
|
65044
|
+
bundleDir: assetBundles.bundleDir,
|
|
65045
|
+
...assetBundles.target !== void 0 ? { target: assetBundles.target } : {},
|
|
65046
|
+
...assetBundles.store !== void 0 ? { store: assetBundles.store } : {},
|
|
65047
|
+
principalLabel: label
|
|
65048
|
+
});
|
|
65049
|
+
requireDatabricksAssetBundleMap(assetBundles);
|
|
65050
|
+
return databricksAssetBundleLifecycles(
|
|
65051
|
+
// Cast at the boundary into the validating helper: these are unvalidated config candidates, and
|
|
65052
|
+
// each entry's `bundleDir` is enforced there rather than trusted here.
|
|
65053
|
+
Object.fromEntries(
|
|
65054
|
+
Object.entries(assetBundles).map(([name, entry]) => [name, assetBundleEntryOptions(entry)])
|
|
65055
|
+
),
|
|
65056
|
+
{ principalLabel: label }
|
|
65057
|
+
);
|
|
65058
|
+
}
|
|
65059
|
+
function assetBundleEntryOptions(entry) {
|
|
65060
|
+
if (entry === null || typeof entry !== "object") return {};
|
|
65061
|
+
const { bundleDir, target, store } = entry;
|
|
65062
|
+
return {
|
|
65063
|
+
...bundleDir !== void 0 ? { bundleDir } : {},
|
|
65064
|
+
...target !== void 0 ? { target } : {},
|
|
65065
|
+
...store !== void 0 ? { store } : {}
|
|
65066
|
+
};
|
|
65067
|
+
}
|
|
64494
65068
|
function enabledAuthoringServices(config2, genie = normalizeGenieConfig(config2)) {
|
|
64495
65069
|
return [
|
|
64496
65070
|
.../* @__PURE__ */ new Set([
|
|
@@ -64520,11 +65094,9 @@ function validateAuthoringConfig(config2, genie = normalizeGenieConfig(config2))
|
|
|
64520
65094
|
if (config2.jobAuthoring || config2.oneOffCompute)
|
|
64521
65095
|
validateDatabricksComputePolicy(config2.computePolicy ?? {});
|
|
64522
65096
|
const audience = config2.governance?.stewardAudience;
|
|
64523
|
-
|
|
64524
|
-
if (!config2.allowUnapprovedAuthoring && (!audience || excluded.length > 0)) {
|
|
64525
|
-
const ungated = !audience ? services : excluded;
|
|
65097
|
+
if (!config2.allowUnapprovedAuthoring && !audience) {
|
|
64526
65098
|
throw new Error(
|
|
64527
|
-
`databricks: authoring services are not approval-gated: ${
|
|
65099
|
+
`databricks: authoring services are not approval-gated: ${services.join(", ")}. Configure governance.stewardAudience, or explicitly set allowUnapprovedAuthoring: true.`
|
|
64528
65100
|
);
|
|
64529
65101
|
}
|
|
64530
65102
|
}
|
|
@@ -64608,6 +65180,8 @@ export {
|
|
|
64608
65180
|
DatabricksJobsAuthoring,
|
|
64609
65181
|
DatabricksLakeflowAuthoring,
|
|
64610
65182
|
DatabricksManagedResourceConflictError,
|
|
65183
|
+
DatabricksResourceNotAllowedError,
|
|
65184
|
+
DatabricksRunNotAllowedError,
|
|
64611
65185
|
DatabricksRunTimeoutError,
|
|
64612
65186
|
DatabricksSecretsAuthoring,
|
|
64613
65187
|
DatabricksServingAdmin,
|
|
@@ -64635,6 +65209,7 @@ export {
|
|
|
64635
65209
|
databricksApp,
|
|
64636
65210
|
databricksApprovalRules,
|
|
64637
65211
|
databricksAssetBundleLifecycle,
|
|
65212
|
+
databricksAssetBundleLifecycles,
|
|
64638
65213
|
databricksAssetBundleTools,
|
|
64639
65214
|
databricksCertificationTier,
|
|
64640
65215
|
databricksCompatibilityRecord,
|
|
@@ -64734,6 +65309,8 @@ export {
|
|
|
64734
65309
|
validateDatabricksCrossTierEvidence,
|
|
64735
65310
|
validateDatabricksGenieSqlReferences,
|
|
64736
65311
|
validateDatabricksGovernanceDescriptor,
|
|
65312
|
+
validateDatabricksJobRunPolicy,
|
|
65313
|
+
validateDatabricksNotebookRunPolicy,
|
|
64737
65314
|
validateDatabricksReleaseEvidence,
|
|
64738
65315
|
validateDatabricksRollingEvidence,
|
|
64739
65316
|
validateJobSpec,
|