@fabric-harness/databricks 5.0.0 → 5.2.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/dist/agent.js CHANGED
@@ -18543,9 +18543,12 @@ function canonicalJson(value) {
18543
18543
  // src/asset-bundles.ts
18544
18544
  var BUNDLE_RESOURCE_TYPE = "databricks-bundle";
18545
18545
  var FINGERPRINT_EXCLUDED_DIRS = /* @__PURE__ */ new Set([".databricks", "node_modules", "dist"]);
18546
+ var BUNDLE_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
18546
18547
  var DatabricksAssetBundleLifecycle = class {
18547
18548
  /** Resolved bundle directory; also the governed resource identity on the tools. */
18548
18549
  bundleDir;
18550
+ /** Logical name of this bundle within a named `assetBundles` map; unset in the single-bundle form. */
18551
+ instanceName;
18549
18552
  target;
18550
18553
  profile;
18551
18554
  executable;
@@ -18565,6 +18568,7 @@ var DatabricksAssetBundleLifecycle = class {
18565
18568
  this.principalLabel = options.principalLabel ?? "unknown";
18566
18569
  if (options.target !== void 0) this.target = options.target;
18567
18570
  if (options.profile !== void 0) this.profile = options.profile;
18571
+ if (options.instanceName !== void 0) this.instanceName = options.instanceName;
18568
18572
  }
18569
18573
  /** Run `databricks bundle validate` without mutating the workspace. */
18570
18574
  async validate() {
@@ -18642,6 +18646,10 @@ var DatabricksAssetBundleLifecycle = class {
18642
18646
  key,
18643
18647
  "--no-wait",
18644
18648
  ...options.restart === true ? ["--restart"] : [],
18649
+ "--output",
18650
+ "json",
18651
+ "--progress-format",
18652
+ "json",
18645
18653
  ...this.targetArgs(),
18646
18654
  ...this.profileArgs()
18647
18655
  ];
@@ -18650,7 +18658,7 @@ var DatabricksAssetBundleLifecycle = class {
18650
18658
  env: this.env
18651
18659
  });
18652
18660
  requireSuccess("Databricks bundle run submission", result);
18653
- return { submitted: true, output: lastNonEmptyLine(result.stdout) };
18661
+ return parseBundleRunResult(key, result);
18654
18662
  }
18655
18663
  /** Destroy a Harness-recorded bundle deployment and delete its managed record. */
18656
18664
  async destroy(options = {}) {
@@ -18686,14 +18694,20 @@ var DatabricksAssetBundleLifecycle = class {
18686
18694
  await this.store.delete(BUNDLE_RESOURCE_TYPE, resourceId);
18687
18695
  return { destroyed: true, output: lastNonEmptyLine(result.stdout) };
18688
18696
  }
18689
- /** Bundle `name:` parsed from `databricks.yml`, falling back to the directory basename. */
18697
+ /**
18698
+ * Bundle `name:` parsed from `databricks.yml`, falling back to the directory basename. Named
18699
+ * bundles append `#instanceName` (and `#target` when set) so two lifecycles over the same manifest
18700
+ * cannot collide in a shared managed-resource store; the single-bundle form keeps the bare name so
18701
+ * existing records stay addressable.
18702
+ */
18690
18703
  async resourceId() {
18691
18704
  if (this.bundleName === void 0) {
18692
18705
  const manifest = await readFile2(path2.join(this.bundleDir, "databricks.yml"), "utf8");
18693
18706
  const match = /^\s*name:\s*["']?([^\s"']+)["']?\s*$/m.exec(manifest);
18694
18707
  this.bundleName = match?.[1] ?? path2.basename(this.bundleDir);
18695
18708
  }
18696
- return this.bundleName;
18709
+ if (this.instanceName === void 0) return this.bundleName;
18710
+ return `${this.bundleName}#${this.instanceName}${this.target ? `#${this.target}` : ""}`;
18697
18711
  }
18698
18712
  async requireManifest() {
18699
18713
  const manifest = path2.join(this.bundleDir, "databricks.yml");
@@ -18713,7 +18727,65 @@ var DatabricksAssetBundleLifecycle = class {
18713
18727
  function databricksAssetBundleLifecycle(options) {
18714
18728
  return new DatabricksAssetBundleLifecycle(options);
18715
18729
  }
18730
+ function isDatabricksAssetBundleEntry(value) {
18731
+ if (value instanceof DatabricksAssetBundleLifecycle) return true;
18732
+ return isPlainObject2(value) && Object.hasOwn(value, "bundleDir") && typeof value.bundleDir === "string";
18733
+ }
18734
+ function requireDatabricksAssetBundleMap(value) {
18735
+ if (!isPlainObject2(value))
18736
+ throw new Error(
18737
+ "databricks asset bundles: named bundles must be an object keyed by bundle name."
18738
+ );
18739
+ }
18740
+ function databricksAssetBundleLifecycles(options, defaults = {}) {
18741
+ requireDatabricksAssetBundleMap(options);
18742
+ const lifecycles = /* @__PURE__ */ new Map();
18743
+ for (const name of Object.keys(options).sort()) {
18744
+ requireBundleName(name);
18745
+ const entry = options[name];
18746
+ if (!isPlainObject2(entry) || typeof entry.bundleDir !== "string" || !entry.bundleDir.trim())
18747
+ throw new Error(
18748
+ `databricks asset bundles: bundle "${name}" requires a non-empty bundleDir string.`
18749
+ );
18750
+ lifecycles.set(
18751
+ name,
18752
+ new DatabricksAssetBundleLifecycle({ ...defaults, ...entry, instanceName: name })
18753
+ );
18754
+ }
18755
+ requireNamedBundles(lifecycles);
18756
+ return lifecycles;
18757
+ }
18716
18758
  function databricksAssetBundleTools(options) {
18759
+ if (isDatabricksAssetBundleEntry(options)) return singleBundleTools(options);
18760
+ return namedBundleTools(
18761
+ options instanceof Map ? checkedLifecycles(options) : databricksAssetBundleLifecycles(options)
18762
+ );
18763
+ }
18764
+ function checkedLifecycles(lifecycles) {
18765
+ const checked = /* @__PURE__ */ new Map();
18766
+ for (const [name, lifecycle] of lifecycles) {
18767
+ requireBundleName(name);
18768
+ if (!(lifecycle instanceof DatabricksAssetBundleLifecycle))
18769
+ throw new Error(
18770
+ `databricks asset bundles: bundle "${name}" must be a DatabricksAssetBundleLifecycle.`
18771
+ );
18772
+ if (lifecycle.instanceName !== name)
18773
+ throw new Error(
18774
+ `databricks asset bundles: bundle "${name}" must be built with instanceName "${name}"${lifecycle.instanceName === void 0 ? "" : `, not "${lifecycle.instanceName}"`}.`
18775
+ );
18776
+ checked.set(name, lifecycle);
18777
+ }
18778
+ return checked;
18779
+ }
18780
+ function requireBundleName(name) {
18781
+ if (typeof name !== "string")
18782
+ throw new Error(`databricks asset bundles: bundle names must be strings, not ${typeof name}.`);
18783
+ if (!BUNDLE_NAME_PATTERN.test(name))
18784
+ throw new Error(
18785
+ `databricks asset bundles: bundle name "${name}" must match ${BUNDLE_NAME_PATTERN.source}.`
18786
+ );
18787
+ }
18788
+ function singleBundleTools(options) {
18717
18789
  const lifecycle = options instanceof DatabricksAssetBundleLifecycle ? options : new DatabricksAssetBundleLifecycle(options);
18718
18790
  const resources = [{ kind: "bundle", value: lifecycle.bundleDir }];
18719
18791
  return [
@@ -18770,6 +18842,94 @@ function databricksAssetBundleTools(options) {
18770
18842
  )
18771
18843
  ];
18772
18844
  }
18845
+ function namedBundleTools(lifecycles) {
18846
+ requireNamedBundles(lifecycles);
18847
+ const names = [...lifecycles.keys()].sort();
18848
+ const selector = { bundle: { type: "string", enum: names } };
18849
+ const resources = [{ kind: "bundle", path: "/bundle" }];
18850
+ const select = (input) => selectBundle(lifecycles, names, input);
18851
+ return [
18852
+ bundleTool(
18853
+ "databricks_bundle_validate",
18854
+ "Validate one checked-in Databricks Asset Bundle, selected by name with `bundle`, without deploying it.",
18855
+ "read",
18856
+ {
18857
+ type: "object",
18858
+ additionalProperties: false,
18859
+ properties: { ...selector },
18860
+ required: ["bundle"]
18861
+ },
18862
+ [],
18863
+ async (input) => select(input).validate()
18864
+ ),
18865
+ bundleTool(
18866
+ "databricks_bundle_deploy",
18867
+ "Validate and deploy one checked-in Databricks Asset Bundle, selected by name with `bundle`, recording its source fingerprint.",
18868
+ "write",
18869
+ {
18870
+ type: "object",
18871
+ additionalProperties: false,
18872
+ properties: { ...selector, expectedFingerprint: { type: "string" } },
18873
+ required: ["bundle"]
18874
+ },
18875
+ resources,
18876
+ async (input) => {
18877
+ const lifecycle = select(input);
18878
+ const expectedFingerprint = input.expectedFingerprint;
18879
+ return lifecycle.deploy(expectedFingerprint !== void 0 ? { expectedFingerprint } : {});
18880
+ }
18881
+ ),
18882
+ bundleTool(
18883
+ "databricks_bundle_run",
18884
+ "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.",
18885
+ "execute",
18886
+ {
18887
+ type: "object",
18888
+ additionalProperties: false,
18889
+ properties: { ...selector, key: { type: "string" }, restart: { type: "boolean" } },
18890
+ required: ["bundle", "key"]
18891
+ },
18892
+ resources,
18893
+ async (input) => select(input).run({
18894
+ key: input.key,
18895
+ restart: input.restart === true
18896
+ })
18897
+ ),
18898
+ bundleTool(
18899
+ "databricks_bundle_destroy",
18900
+ "Destroy a Harness-recorded deployment of one Databricks Asset Bundle, selected by name with `bundle`.",
18901
+ "write",
18902
+ {
18903
+ type: "object",
18904
+ additionalProperties: false,
18905
+ properties: { ...selector, force: { type: "boolean" } },
18906
+ required: ["bundle"]
18907
+ },
18908
+ resources,
18909
+ async (input) => select(input).destroy({ force: input.force === true })
18910
+ )
18911
+ ];
18912
+ }
18913
+ function selectBundle(lifecycles, names, input) {
18914
+ const bundle = input.bundle;
18915
+ if (typeof bundle !== "string" || !bundle)
18916
+ throw new Error(
18917
+ `databricks asset bundles: bundle is required; configured bundles: ${names.join(", ")}.`
18918
+ );
18919
+ const lifecycle = lifecycles.get(bundle);
18920
+ if (!lifecycle)
18921
+ throw new Error(
18922
+ `databricks asset bundles: unknown bundle "${bundle}"; configured bundles: ${names.join(", ")}.`
18923
+ );
18924
+ return lifecycle;
18925
+ }
18926
+ function requireNamedBundles(lifecycles) {
18927
+ if (lifecycles.size === 0)
18928
+ throw new Error("databricks asset bundles: at least one named bundle is required.");
18929
+ }
18930
+ function isPlainObject2(value) {
18931
+ return typeof value === "object" && value !== null && !Array.isArray(value);
18932
+ }
18773
18933
  function bundleTool(name, description, effect, inputSchema, resources, execute2) {
18774
18934
  return {
18775
18935
  name,
@@ -18808,6 +18968,79 @@ function requireSuccess(label, result) {
18808
18968
  function lastNonEmptyLine(value) {
18809
18969
  return value.split("\n").map((line) => line.trim()).filter(Boolean).at(-1) ?? "";
18810
18970
  }
18971
+ function parseBundleRunResult(resourceKey2, result) {
18972
+ const records = [...jsonRecords(result.stdout), ...jsonRecords(result.stderr)];
18973
+ const jobEvent = records.find((record2) => record2.type === "job_run_url");
18974
+ const pipelineEvent = records.find((record2) => record2.type === "pipeline_update_url");
18975
+ const runUrl = stringField(jobEvent, "url") ?? stringField(pipelineEvent, "url") ?? firstUrl(result.stdout) ?? firstUrl(result.stderr);
18976
+ const explicitRunId = numberField(jobEvent, "run_id") ?? numberField(jobEvent, "runId") ?? records.map((record2) => numberField(record2, "run_id") ?? numberField(record2, "runId")).find(
18977
+ (value) => value !== void 0
18978
+ );
18979
+ const runId = explicitRunId ?? runIdFromUrl(runUrl);
18980
+ const pipelineId = stringField(pipelineEvent, "pipeline_id") ?? stringField(pipelineEvent, "pipelineId") ?? pipelineIdentityFromUrl(runUrl)?.pipelineId;
18981
+ 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;
18982
+ const output = lastNonEmptyLine(result.stdout) || lastNonEmptyLine(result.stderr);
18983
+ return {
18984
+ submitted: true,
18985
+ resourceKey: resourceKey2,
18986
+ ...runId !== void 0 ? { runKind: "job", runId } : {},
18987
+ ...pipelineId !== void 0 || updateId !== void 0 ? {
18988
+ runKind: "pipeline",
18989
+ ...pipelineId !== void 0 ? { pipelineId } : {},
18990
+ ...updateId !== void 0 ? { updateId } : {}
18991
+ } : {},
18992
+ ...runUrl !== void 0 ? { runUrl } : {},
18993
+ output
18994
+ };
18995
+ }
18996
+ function jsonRecords(value) {
18997
+ const records = [];
18998
+ for (const candidate of [value.trim(), ...value.split("\n").map((line) => line.trim())]) {
18999
+ if (!(candidate.startsWith("{") && candidate.endsWith("}"))) continue;
19000
+ try {
19001
+ const parsed = JSON.parse(candidate);
19002
+ if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed))
19003
+ records.push(parsed);
19004
+ } catch {
19005
+ }
19006
+ }
19007
+ return records;
19008
+ }
19009
+ function stringField(record2, key) {
19010
+ const value = record2?.[key];
19011
+ return typeof value === "string" && value.trim() ? value : void 0;
19012
+ }
19013
+ function numberField(record2, key) {
19014
+ const value = record2?.[key];
19015
+ const parsed = typeof value === "number" ? value : typeof value === "string" && /^\d+$/.test(value) ? Number(value) : void 0;
19016
+ return parsed !== void 0 && Number.isSafeInteger(parsed) && parsed > 0 ? parsed : void 0;
19017
+ }
19018
+ function firstUrl(value) {
19019
+ const match = /https?:\/\/[^\s"']+/u.exec(value);
19020
+ return match?.[0]?.replace(/[),.;]+$/u, "");
19021
+ }
19022
+ function runIdFromUrl(value) {
19023
+ if (!value) return void 0;
19024
+ try {
19025
+ const url2 = new URL(value);
19026
+ const raw = /\/jobs\/\d+\/runs\/(\d+)/u.exec(url2.pathname)?.[1] ?? /(?:^|\/)job\/\d+\/run\/(\d+)(?:\/|$)/u.exec(url2.hash.replace(/^#/, ""))?.[1];
19027
+ return raw ? numberField({ value: raw }, "value") : void 0;
19028
+ } catch {
19029
+ return void 0;
19030
+ }
19031
+ }
19032
+ function pipelineIdentityFromUrl(value) {
19033
+ if (!value) return void 0;
19034
+ try {
19035
+ const url2 = new URL(value);
19036
+ const match = /(?:^|\/)pipelines\/([^/]+)\/updates\/([^/?#]+)/u.exec(
19037
+ `${url2.pathname}/${url2.hash.replace(/^#/, "")}`
19038
+ );
19039
+ return match?.[1] && match[2] ? { pipelineId: match[1], updateId: match[2] } : void 0;
19040
+ } catch {
19041
+ return void 0;
19042
+ }
19043
+ }
18811
19044
 
18812
19045
  // src/consumption.ts
18813
19046
  var GROUP_COLUMNS = {
@@ -59404,6 +59637,7 @@ async function databricksWithManagedMcp(config2, scope) {
59404
59637
  }
59405
59638
  function buildDatabricksBundle(config2, scope) {
59406
59639
  registerDatabricksModelProvider();
59640
+ const assetBundles = buildAssetBundleLifecycles(config2);
59407
59641
  const genie = normalizeGenieConfig(config2);
59408
59642
  validateAuthoringConfig(config2, genie);
59409
59643
  const identity = scope?.identity ?? databricksIdentity(config2.principal);
@@ -59417,12 +59651,8 @@ function buildDatabricksBundle(config2, scope) {
59417
59651
  const client = native.rawProtocol;
59418
59652
  const genieAgentModeClient = genie.agentMode ? databricksGenieAgentMode(client, genie.agentMode) : void 0;
59419
59653
  const agentServicesClient = config2.agentServices ? databricksAgentServices(client, config2.agentServices) : void 0;
59420
- const assetBundle = config2.assetBundles ? databricksAssetBundleLifecycle({
59421
- bundleDir: config2.assetBundles.bundleDir,
59422
- ...config2.assetBundles.target ? { target: config2.assetBundles.target } : {},
59423
- ...config2.assetBundles.store ? { store: config2.assetBundles.store } : {},
59424
- principalLabel: config2.governance?.principalLabel ?? principalLabel(config2.principal)
59425
- }) : void 0;
59654
+ const namedAssetBundles = assetBundles instanceof Map ? Object.freeze(Object.fromEntries(assetBundles)) : void 0;
59655
+ const assetBundle = assetBundles instanceof Map ? assetBundles.size === 1 ? [...assetBundles.values()][0] : void 0 : assetBundles;
59426
59656
  let embeddings;
59427
59657
  let retriever;
59428
59658
  let searchTool;
@@ -59504,7 +59734,7 @@ function buildDatabricksBundle(config2, scope) {
59504
59734
  ...config2.lakeflowAuthoring ? databricksLakeflowAuthoringTools(native.pipelines, {
59505
59735
  ...config2.lakeflowEvents && config2.warehouseId ? { warehouseId: config2.warehouseId, statements: native.statements } : {}
59506
59736
  }) : [],
59507
- ...assetBundle ? databricksAssetBundleTools(assetBundle) : [],
59737
+ ...assetBundles ? databricksAssetBundleTools(assetBundles) : [],
59508
59738
  ...config2.aiSearchAdmin ? databricksAiSearchAdminTools(native.vectorSearch) : [],
59509
59739
  ...config2.servingAdmin ? databricksServingAdminTools(native.modelServing) : [],
59510
59740
  ...config2.ucAdmin ? databricksUnityCatalogAdminTools(
@@ -59584,6 +59814,7 @@ function buildDatabricksBundle(config2, scope) {
59584
59814
  ...genieAgentModeClient ? { genieAgentMode: genieAgentModeClient } : {},
59585
59815
  ...agentServicesClient ? { agentServices: agentServicesClient } : {},
59586
59816
  ...assetBundle ? { assetBundle } : {},
59817
+ ...namedAssetBundles ? { assetBundles: namedAssetBundles } : {},
59587
59818
  aiGateway: {
59588
59819
  ensure: () => ensureDatabricksAiGateway(client),
59589
59820
  listModelServices: (options) => listDatabricksModelServices(client, options),
@@ -59612,6 +59843,36 @@ function buildDatabricksBundle(config2, scope) {
59612
59843
  }
59613
59844
  return bundle;
59614
59845
  }
59846
+ function buildAssetBundleLifecycles(config2) {
59847
+ const assetBundles = config2.assetBundles;
59848
+ if (assetBundles === void 0) return void 0;
59849
+ const label = config2.governance?.principalLabel ?? principalLabel(config2.principal);
59850
+ if (isDatabricksAssetBundleEntry(assetBundles))
59851
+ return databricksAssetBundleLifecycle({
59852
+ bundleDir: assetBundles.bundleDir,
59853
+ ...assetBundles.target !== void 0 ? { target: assetBundles.target } : {},
59854
+ ...assetBundles.store !== void 0 ? { store: assetBundles.store } : {},
59855
+ principalLabel: label
59856
+ });
59857
+ requireDatabricksAssetBundleMap(assetBundles);
59858
+ return databricksAssetBundleLifecycles(
59859
+ // Cast at the boundary into the validating helper: these are unvalidated config candidates, and
59860
+ // each entry's `bundleDir` is enforced there rather than trusted here.
59861
+ Object.fromEntries(
59862
+ Object.entries(assetBundles).map(([name, entry]) => [name, assetBundleEntryOptions(entry)])
59863
+ ),
59864
+ { principalLabel: label }
59865
+ );
59866
+ }
59867
+ function assetBundleEntryOptions(entry) {
59868
+ if (entry === null || typeof entry !== "object") return {};
59869
+ const { bundleDir, target, store } = entry;
59870
+ return {
59871
+ ...bundleDir !== void 0 ? { bundleDir } : {},
59872
+ ...target !== void 0 ? { target } : {},
59873
+ ...store !== void 0 ? { store } : {}
59874
+ };
59875
+ }
59615
59876
  function enabledAuthoringServices(config2, genie = normalizeGenieConfig(config2)) {
59616
59877
  return [
59617
59878
  .../* @__PURE__ */ new Set([