@fabric-harness/databricks 4.10.1 → 5.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/dist/index.js CHANGED
@@ -59461,37 +59461,70 @@ function deleteSchema() {
59461
59461
  // src/vector-search.ts
59462
59462
  var SCORE_COLUMN = "score";
59463
59463
  function databricksAiSearch(options) {
59464
- const queryType = options.queryType ?? "text";
59464
+ const configuredInputMode = options.inputMode ?? "text";
59465
+ const configuredStrategy = options.strategy ?? (configuredInputMode === "vector" ? "ann" : "hybrid");
59465
59466
  const columns = options.columns ?? dedupe([options.textColumn, ...options.idColumn ? [options.idColumn] : []]);
59466
- return {
59467
+ const retriever = {
59468
+ kind: "databricks-ai-search",
59467
59469
  name: options.name ?? `databricks-ai-search:${options.index}`,
59470
+ index: options.index,
59471
+ inputMode: configuredInputMode,
59472
+ strategy: configuredStrategy,
59468
59473
  async retrieve(query, opts = {}) {
59474
+ return (await retriever.query(query, opts)).chunks;
59475
+ },
59476
+ async query(query, opts = {}) {
59477
+ if (!query.trim()) throw new Error("databricks AI Search: query must not be empty.");
59478
+ const inputMode = opts.inputMode ?? configuredInputMode;
59479
+ const strategy = opts.strategy ?? configuredStrategy;
59480
+ validateQueryCombination(inputMode, strategy);
59481
+ const scoreThreshold = opts.scoreThreshold ?? options.scoreThreshold;
59482
+ const queryColumns = opts.queryColumns ?? options.queryColumns;
59483
+ const sortColumns = opts.sortColumns ?? options.sortColumns;
59484
+ const facets = opts.facets ?? options.facets;
59485
+ const reranker = opts.reranker ?? options.reranker;
59486
+ const columnsToRerank = opts.columnsToRerank ?? options.columnsToRerank;
59469
59487
  const body = {
59470
59488
  name: options.index,
59471
59489
  columns,
59472
- numResults: opts.k ?? 5
59490
+ numResults: opts.k ?? 5,
59491
+ queryType: nativeStrategy(strategy),
59492
+ ...scoreThreshold !== void 0 ? { scoreThreshold } : {},
59493
+ ...queryColumns ? { queryColumns } : {},
59494
+ ...sortColumns ? { sortColumns } : {},
59495
+ ...facets ? { facets } : {},
59496
+ ...reranker ? { reranker } : {},
59497
+ ...columnsToRerank ? { columnsToRerank } : {}
59473
59498
  };
59474
59499
  if (opts.filter) body.filtersJson = JSON.stringify(opts.filter);
59475
- if (queryType === "vector") {
59476
- if (!options.embeddings)
59477
- throw new Error(
59478
- 'databricks AI Search: queryType "vector" requires an embeddings provider.'
59479
- );
59480
- const [vector] = await options.embeddings.embed([query]);
59481
- if (!vector)
59482
- throw new Error("databricks AI Search: embeddings returned no vector for the query.");
59483
- body.queryVector = vector;
59484
- } else {
59500
+ if (inputMode !== "vector") {
59485
59501
  body.queryText = query;
59486
59502
  }
59487
- const response = await queryVectorIndex(options, body);
59488
- return mapResults(response, options, columns);
59503
+ if (inputMode !== "text") {
59504
+ body.queryVector = await resolveQueryVector(query, opts, options);
59505
+ }
59506
+ const response = await queryVectorIndex(options, body, opts.signal);
59507
+ return queryResult(response, options, columns);
59508
+ },
59509
+ async nextPage(pageToken, opts = {}) {
59510
+ if (!pageToken.trim()) throw new Error("databricks AI Search: page token must not be empty.");
59511
+ if (!options.client.queryVectorIndexNextPage) {
59512
+ throw new Error(
59513
+ "databricks AI Search: the configured client does not support result pagination."
59514
+ );
59515
+ }
59516
+ const response = opts.signal ? await options.client.queryVectorIndexNextPage(
59517
+ { name: options.index, pageToken },
59518
+ { signal: opts.signal }
59519
+ ) : await options.client.queryVectorIndexNextPage({ name: options.index, pageToken });
59520
+ return queryResult(response, options, columns);
59489
59521
  }
59490
59522
  };
59523
+ return retriever;
59491
59524
  }
59492
- async function queryVectorIndex(options, body) {
59525
+ async function queryVectorIndex(options, body, signal) {
59493
59526
  try {
59494
- return await options.client.queryVectorIndex(body);
59527
+ return signal ? await options.client.queryVectorIndex(body, { signal }) : await options.client.queryVectorIndex(body);
59495
59528
  } catch (error51) {
59496
59529
  if (!options.rawProtocolClient || !isGeneratedFloatingPointDecodeError(error51)) throw error51;
59497
59530
  const raw = await options.rawProtocolClient.post(
@@ -59501,10 +59534,17 @@ async function queryVectorIndex(options, body) {
59501
59534
  num_results: body.numResults,
59502
59535
  ...body.filtersJson !== void 0 ? { filters_json: body.filtersJson } : {},
59503
59536
  ...body.queryText !== void 0 ? { query_text: body.queryText } : {},
59504
- ...body.queryVector !== void 0 ? { query_vector: body.queryVector } : {}
59537
+ ...body.queryVector !== void 0 ? { query_vector: body.queryVector } : {},
59538
+ ...body.queryType !== void 0 ? { query_type: body.queryType } : {},
59539
+ ...body.scoreThreshold !== void 0 ? { score_threshold: body.scoreThreshold } : {},
59540
+ ...body.queryColumns !== void 0 ? { query_columns: body.queryColumns } : {},
59541
+ ...body.sortColumns !== void 0 ? { sort_columns: body.sortColumns } : {},
59542
+ ...body.facets !== void 0 ? { facets: body.facets } : {},
59543
+ ...body.reranker !== void 0 ? { reranker: body.reranker } : {},
59544
+ ...body.columnsToRerank !== void 0 ? { columns_to_rerank: body.columnsToRerank } : {}
59505
59545
  },
59506
59546
  void 0,
59507
- { retry: "safe" }
59547
+ { retry: "safe", ...signal ? { signal } : {} }
59508
59548
  );
59509
59549
  return {
59510
59550
  ...raw.manifest ? { manifest: raw.manifest } : {},
@@ -59514,10 +59554,49 @@ async function queryVectorIndex(options, body) {
59514
59554
  ...raw.result.row_count !== void 0 ? { rowCount: raw.result.row_count } : {}
59515
59555
  }
59516
59556
  } : {},
59517
- ...raw.next_page_token ? { nextPageToken: raw.next_page_token } : {}
59557
+ ...raw.next_page_token ? { nextPageToken: raw.next_page_token } : {},
59558
+ ...raw.facet_result ? { facetResult: raw.facet_result } : {}
59518
59559
  };
59519
59560
  }
59520
59561
  }
59562
+ async function resolveQueryVector(query, queryOptions, options) {
59563
+ if (queryOptions.queryVector) {
59564
+ if (queryOptions.queryVector.length === 0)
59565
+ throw new Error("databricks AI Search: queryVector must not be empty.");
59566
+ return queryOptions.queryVector;
59567
+ }
59568
+ if (!options.embeddings) {
59569
+ throw new Error(
59570
+ "databricks AI Search: vector input requires `queryVector` or an embeddings provider."
59571
+ );
59572
+ }
59573
+ const [vector] = queryOptions.signal ? await options.embeddings.embed([query], { signal: queryOptions.signal }) : await options.embeddings.embed([query]);
59574
+ if (!vector?.length)
59575
+ throw new Error("databricks AI Search: embeddings returned no vector for the query.");
59576
+ return vector;
59577
+ }
59578
+ function validateQueryCombination(inputMode, strategy) {
59579
+ if ((strategy === "hybrid" || strategy === "full-text") && inputMode === "vector") {
59580
+ throw new Error(
59581
+ `databricks AI Search: ${strategy} retrieval requires text or text-and-vector input.`
59582
+ );
59583
+ }
59584
+ if (strategy === "full-text" && inputMode === "text-and-vector") {
59585
+ throw new Error("databricks AI Search: full-text retrieval does not accept a query vector.");
59586
+ }
59587
+ }
59588
+ function nativeStrategy(strategy) {
59589
+ if (strategy === "full-text") return "FULL_TEXT";
59590
+ return strategy.toUpperCase();
59591
+ }
59592
+ function queryResult(response, options, requestedColumns) {
59593
+ return {
59594
+ chunks: mapResults(response, options, requestedColumns),
59595
+ ...response.nextPageToken ? { nextPageToken: response.nextPageToken } : {},
59596
+ ...response.facetResult ? { facetResult: response.facetResult } : {},
59597
+ response
59598
+ };
59599
+ }
59521
59600
  function isGeneratedFloatingPointDecodeError(error51) {
59522
59601
  const message = error51 instanceof Error ? `${error51.name}: ${error51.message}` : String(error51);
59523
59602
  return /Cannot convert [-+]?\d+\.\d+(?:e[-+]?\d+)? to a BigInt/iu.test(message);
@@ -60706,13 +60785,18 @@ async function runDatabricksCertification(options) {
60706
60785
  ...explicitlyRequired,
60707
60786
  ...options.checks.filter((check3) => requiredTiers.has(check3.tier ?? databricksCertificationTier(check3.id))).map((check3) => check3.id)
60708
60787
  ]);
60709
- const results = [];
60710
- for (const check3 of options.checks) {
60788
+ const resultsByIndex = new Array(
60789
+ options.checks.length
60790
+ );
60791
+ const executionOrder = options.checks.map((check3, index) => ({ check: check3, index })).sort(
60792
+ (left, right) => Number(required2.has(right.check.id)) - Number(required2.has(left.check.id))
60793
+ );
60794
+ for (const { check: check3, index } of executionOrder) {
60711
60795
  const startedAt2 = Date.now();
60712
60796
  const requiredCheck = required2.has(check3.id);
60713
60797
  const tier = check3.tier ?? databricksCertificationTier(check3.id);
60714
60798
  if (!check3.configured) {
60715
- results.push({
60799
+ resultsByIndex[index] = {
60716
60800
  id: check3.id,
60717
60801
  description: check3.description,
60718
60802
  tier,
@@ -60720,12 +60804,12 @@ async function runDatabricksCertification(options) {
60720
60804
  status: "not-configured",
60721
60805
  durationMs: 0,
60722
60806
  ...requiredCheck ? { error: "Required check is not configured." } : {}
60723
- });
60807
+ };
60724
60808
  continue;
60725
60809
  }
60726
60810
  try {
60727
60811
  const details = await check3.run();
60728
- results.push({
60812
+ resultsByIndex[index] = {
60729
60813
  id: check3.id,
60730
60814
  description: check3.description,
60731
60815
  tier,
@@ -60733,9 +60817,9 @@ async function runDatabricksCertification(options) {
60733
60817
  status: "passed",
60734
60818
  durationMs: Date.now() - startedAt2,
60735
60819
  ...isRecord2(details) ? { details } : {}
60736
- });
60820
+ };
60737
60821
  } catch (error51) {
60738
- results.push({
60822
+ resultsByIndex[index] = {
60739
60823
  id: check3.id,
60740
60824
  description: check3.description,
60741
60825
  tier,
@@ -60745,9 +60829,12 @@ async function runDatabricksCertification(options) {
60745
60829
  error: redactText3(databricksErrorMessage(error51), {
60746
60830
  additionalSecrets: options.secrets ?? []
60747
60831
  })
60748
- });
60832
+ };
60749
60833
  }
60750
60834
  }
60835
+ const results = resultsByIndex.filter(
60836
+ (result) => result !== void 0
60837
+ );
60751
60838
  const summary = {
60752
60839
  passed: results.filter((result) => result.status === "passed").length,
60753
60840
  failed: results.filter((result) => result.status === "failed").length,
@@ -62161,6 +62248,97 @@ function databricksCompatibilityRecord(evidence) {
62161
62248
 
62162
62249
  // src/capabilities.ts
62163
62250
  var ALL_CLOUDS = ["aws", "azure", "gcp"];
62251
+ var DATABRICKS_PLATFORM_DOMAINS = [
62252
+ {
62253
+ id: "agents-and-generative-ai",
62254
+ name: "Agents and generative AI",
62255
+ capabilityIds: [
62256
+ "responses-agent",
62257
+ "unity-ai-gateway",
62258
+ "agent-services",
62259
+ "mcp-multi-agent",
62260
+ "managed-memory",
62261
+ "ai-search",
62262
+ "mlflow-genai"
62263
+ ],
62264
+ knownGaps: ["Managed agent memory is not yet supported."]
62265
+ },
62266
+ {
62267
+ id: "machine-learning",
62268
+ name: "Machine learning and serving",
62269
+ capabilityIds: [
62270
+ "model-lifecycle",
62271
+ "serving-admin",
62272
+ "provisioned-throughput-admin",
62273
+ "feature-serving",
62274
+ "ai-functions"
62275
+ ],
62276
+ knownGaps: [
62277
+ "Training, AutoML, Feature Engineering authoring, batch inference, and full registered-model lifecycle are not yet represented."
62278
+ ]
62279
+ },
62280
+ {
62281
+ id: "data-engineering",
62282
+ name: "Data engineering and orchestration",
62283
+ capabilityIds: [
62284
+ "jobs-run",
62285
+ "jobs-authoring",
62286
+ "lakeflow",
62287
+ "lakeflow-authoring",
62288
+ "automation-bundles"
62289
+ ],
62290
+ knownGaps: [
62291
+ "Spark Connect, streaming tables, materialized views, and ingestion connectors do not yet have first-party Harness APIs."
62292
+ ]
62293
+ },
62294
+ {
62295
+ id: "sql-and-bi",
62296
+ name: "SQL, dashboards, and AI/BI",
62297
+ capabilityIds: ["sql-warehouse", "genie-query", "genie-authoring", "genie-agent-mode"],
62298
+ knownGaps: [
62299
+ "Dashboard, query, alert, warehouse, and metric-view authoring are not yet complete."
62300
+ ]
62301
+ },
62302
+ {
62303
+ id: "apps-and-operational-data",
62304
+ name: "Apps and operational data",
62305
+ capabilityIds: ["apps-deploy", "lakebase", "uc-volumes"],
62306
+ knownGaps: [
62307
+ "All App resource kinds need typed first-party configuration; AI Search and Genie are currently the explicit convenience bindings."
62308
+ ]
62309
+ },
62310
+ {
62311
+ id: "governance-and-security",
62312
+ name: "Governance, identity, and security",
62313
+ capabilityIds: [
62314
+ "unity-catalog-read",
62315
+ "uc-admin",
62316
+ "secrets-write",
62317
+ "governance-approvals",
62318
+ "workspace-write",
62319
+ "workspace-api"
62320
+ ],
62321
+ knownGaps: [
62322
+ "Lineage reads, ABAC policy authoring, row filters, masks, federation, account-level IAM, and system-table administration remain incomplete."
62323
+ ]
62324
+ },
62325
+ {
62326
+ id: "sharing-and-collaboration",
62327
+ name: "Sharing and collaboration",
62328
+ capabilityIds: [],
62329
+ knownGaps: [
62330
+ "Delta Sharing, Clean Rooms, Marketplace, and data-room lifecycle are not yet supported."
62331
+ ]
62332
+ },
62333
+ {
62334
+ id: "operations-and-finops",
62335
+ name: "Operations, observability, and FinOps",
62336
+ capabilityIds: ["consumption-cost", "mlflow-genai", "automation-bundles"],
62337
+ knownGaps: [
62338
+ "Workspace system-table coverage, budgets, billing APIs, audit-log delivery, and fleet-wide administration remain incomplete."
62339
+ ]
62340
+ }
62341
+ ];
62164
62342
  var AUTHORING_EVIDENCE_ID = "dbx-cert-d4b16490526892f3945ba5a53249c600581aaed105829c0b87f00eed508bcb18";
62165
62343
  var CLASSIC_AUTHORING_EVIDENCE_ID = "dbx-cert-d5bdbd276533a8634910e223898337314446561be2a444030fc2d11baa237bec";
62166
62344
  var CURRENT_CONSUMPTION_EVIDENCE_ID = "dbx-cert-69878cfdd583d1f4331487a5af3272ae7380736914203dcba3bbb8b4d87adb34";
@@ -62504,7 +62682,13 @@ var DATABRICKS_CAPABILITY_DEFINITIONS = [
62504
62682
  requiredEvidence: ["ai-search.query", "ai-search.authorization-denied"],
62505
62683
  evidenceIds: [CURRENT_CONSUMPTION_EVIDENCE_ID],
62506
62684
  docs: "/docs/databricks/rag",
62507
- notes: "Query evidence remains separate from the beta ai-search-admin lifecycle."
62685
+ upstreamMaturity: "general-availability",
62686
+ apiFidelity: "native-complete",
62687
+ lifecycle: ["query"],
62688
+ knownGaps: [
62689
+ "Hybrid, full-text, reranking, facets, sorting, thresholds, and pagination have contract evidence but still require exact-candidate live certification."
62690
+ ],
62691
+ notes: "Query evidence remains separate from the AI Search administration lifecycle."
62508
62692
  },
62509
62693
  {
62510
62694
  id: "lakeflow",
@@ -62751,6 +62935,29 @@ var DATABRICKS_CAPABILITY_DEFINITIONS = [
62751
62935
  ],
62752
62936
  evidenceIds: [AUTHORING_EVIDENCE_ID]
62753
62937
  },
62938
+ {
62939
+ id: "workspace-api",
62940
+ name: "Native Databricks workspace REST escape hatch",
62941
+ category: "operations",
62942
+ status: "partial",
62943
+ tier: "escape-hatch",
62944
+ certification: "contract",
62945
+ auth: ["oauth-m2m", "app-service-principal", "on-behalf-of", "pat"],
62946
+ contractClouds: ALL_CLOUDS,
62947
+ surfaces: [
62948
+ {
62949
+ package: "@fabric-harness/databricks",
62950
+ exports: ["databricksWorkspaceApi"]
62951
+ }
62952
+ ],
62953
+ docs: "/docs/databricks/native-access",
62954
+ requiredEvidence: ["workspace-api.contract"],
62955
+ apiFidelity: "native-complete",
62956
+ lifecycle: ["discover", "read", "query", "execute", "create", "update", "delete"],
62957
+ knownGaps: [
62958
+ "The escape hatch preserves HTTP fidelity but intentionally does not add domain schemas, governed ToolDefs, or lifecycle ownership."
62959
+ ]
62960
+ },
62754
62961
  {
62755
62962
  id: "secrets-write",
62756
62963
  name: "Secret-reference administration",
@@ -62772,10 +62979,24 @@ var DATABRICKS_CAPABILITY_DEFINITIONS = [
62772
62979
  notes: "Built-in ToolDefs accept SecretRef values only; raw secret values remain typed-client-only."
62773
62980
  }
62774
62981
  ];
62775
- var DATABRICKS_CAPABILITIES = DATABRICKS_CAPABILITY_DEFINITIONS.map((capability) => ({
62776
- ...capability,
62777
- clouds: certifiedCloudsForEvidence(capability.evidenceIds)
62778
- }));
62982
+ var DATABRICKS_CAPABILITIES = DATABRICKS_CAPABILITY_DEFINITIONS.map((definition) => {
62983
+ const { upstreamMaturity, apiFidelity, lifecycle, knownGaps, ...capability } = definition;
62984
+ const clouds = certifiedCloudsForEvidence(capability.evidenceIds);
62985
+ return {
62986
+ ...capability,
62987
+ clouds,
62988
+ coverage: {
62989
+ upstreamMaturity: upstreamMaturity ?? inferredUpstreamMaturity(capability.status),
62990
+ apiFidelity: apiFidelity ?? inferredApiFidelity(capability.status),
62991
+ lifecycle: lifecycle ?? inferredLifecycle(capability.requiredEvidence),
62992
+ runtimeCertification: capability.certification,
62993
+ identities: capability.auth,
62994
+ contractClouds: capability.contractClouds,
62995
+ certifiedClouds: clouds,
62996
+ knownGaps: knownGaps ?? []
62997
+ }
62998
+ };
62999
+ });
62779
63000
  function stableConsumptionCapabilities() {
62780
63001
  const rows = [
62781
63002
  [
@@ -62871,6 +63092,33 @@ function stableConsumptionCapabilities() {
62871
63092
  evidenceIds: id === "ai-functions" ? ["dbx-cert-d03df5a0a5b69a98d8acb0ad4c1e9ef9bcffefea7e433cbd2ba0ff3d792fec71"] : [CURRENT_CONSUMPTION_EVIDENCE_ID]
62872
63093
  }));
62873
63094
  }
63095
+ function inferredUpstreamMaturity(status) {
63096
+ if (status === "beta") return "beta";
63097
+ if (status === "stable") return "general-availability";
63098
+ return "unknown";
63099
+ }
63100
+ function inferredApiFidelity(status) {
63101
+ if (status === "planned") return "not-supported";
63102
+ if (status === "partial") return "native-subset";
63103
+ return "fabric-abstraction";
63104
+ }
63105
+ function inferredLifecycle(checks) {
63106
+ const operations = /* @__PURE__ */ new Set();
63107
+ for (const check3 of checks) {
63108
+ const operation = check3.slice(check3.lastIndexOf(".") + 1);
63109
+ if (/discover|list|status|verify/u.test(operation)) operations.add("discover");
63110
+ if (/read|output/u.test(operation)) operations.add("read");
63111
+ if (/query/u.test(operation)) operations.add("query");
63112
+ if (/execute|invoke|run|deploy|build|consume|write/u.test(operation)) operations.add("execute");
63113
+ if (/create/u.test(operation)) operations.add("create");
63114
+ if (/mutate|update/u.test(operation)) operations.add("update");
63115
+ if (/delete/u.test(operation)) operations.add("delete");
63116
+ if (/recover|recovery|restart/u.test(operation)) operations.add("recover");
63117
+ }
63118
+ return ["discover", "read", "query", "execute", "create", "update", "delete", "recover"].filter(
63119
+ (operation) => operations.has(operation)
63120
+ );
63121
+ }
62874
63122
  function certifiedCloudsForEvidence(evidenceIds) {
62875
63123
  const clouds = /* @__PURE__ */ new Set();
62876
63124
  for (const id of evidenceIds ?? []) {
@@ -62883,8 +63131,11 @@ function getDatabricksCapability(id) {
62883
63131
  return DATABRICKS_CAPABILITIES.find((capability) => capability.id === id);
62884
63132
  }
62885
63133
  function listDatabricksCapabilities(options = {}) {
63134
+ const domainCapabilityIds = options.domain ? new Set(
63135
+ DATABRICKS_PLATFORM_DOMAINS.find((domain2) => domain2.id === options.domain)?.capabilityIds ?? []
63136
+ ) : void 0;
62886
63137
  return DATABRICKS_CAPABILITIES.filter(
62887
- (capability) => (options.status === void 0 || capability.status === options.status) && (options.tier === void 0 || capability.tier === options.tier)
63138
+ (capability) => (options.status === void 0 || capability.status === options.status) && (options.tier === void 0 || capability.tier === options.tier) && (options.apiFidelity === void 0 || capability.coverage.apiFidelity === options.apiFidelity) && (domainCapabilityIds === void 0 || domainCapabilityIds.has(capability.id))
62888
63139
  );
62889
63140
  }
62890
63141
  function missingDatabricksCapabilityEvidence(capability, evidence = DATABRICKS_CAPABILITY_EVIDENCE) {
@@ -62925,6 +63176,162 @@ function databricksSecretsProvider(options) {
62925
63176
  };
62926
63177
  }
62927
63178
 
63179
+ // src/workspace-api.ts
63180
+ import { redactText as redactText4 } from "@fabric-harness/sdk";
63181
+ function databricksWorkspaceApi(options) {
63182
+ const host = databricksWorkspaceOrigin(options.host);
63183
+ const tokenProvider = databricksIdentity(options.principal);
63184
+ const fetchImpl = options.fetchImpl ?? fetch;
63185
+ const clientMaxRetries = boundedRetries(options.maxRetries ?? 3);
63186
+ const retryBaseDelayMs = options.retryBaseDelayMs ?? 500;
63187
+ if (!Number.isFinite(retryBaseDelayMs) || retryBaseDelayMs < 0)
63188
+ throw new Error("databricks workspace API: retryBaseDelayMs must be non-negative.");
63189
+ async function requestRaw(method, path4, requestOptions = {}) {
63190
+ const normalizedPath = nativePath(path4);
63191
+ const headers = normalizedHeaders(requestOptions.headers);
63192
+ const retry = requestOptions.retry ?? (method === "GET" ? "safe" : "never");
63193
+ if (method !== "GET" && retry === "safe") {
63194
+ throw new Error(
63195
+ 'databricks workspace API: mutations may retry only with `retry: "idempotent"`.'
63196
+ );
63197
+ }
63198
+ if (retry === "idempotent" && !requestOptions.idempotencyKey?.trim()) {
63199
+ throw new Error(
63200
+ "databricks workspace API: idempotent mutation retries require a stable idempotencyKey."
63201
+ );
63202
+ }
63203
+ if (requestOptions.idempotencyKey) {
63204
+ headers.set("x-databricks-idempotency-token", requestOptions.idempotencyKey);
63205
+ }
63206
+ const maxRetries = retry === "never" ? 0 : boundedRetries(requestOptions.maxRetries ?? clientMaxRetries);
63207
+ const signal = combineAbortSignals2(options.signal, requestOptions.signal);
63208
+ const url2 = new URL(`${host}${normalizedPath}`);
63209
+ for (const [key, value] of Object.entries(requestOptions.query ?? {})) {
63210
+ if (Array.isArray(value)) {
63211
+ for (const item of value) url2.searchParams.append(key, item);
63212
+ } else if (value !== void 0) {
63213
+ url2.searchParams.set(key, String(value));
63214
+ }
63215
+ }
63216
+ for (let attempt = 0; ; attempt += 1) {
63217
+ const extraHeaders = typeof options.extraHeaders === "function" ? await options.extraHeaders() : options.extraHeaders;
63218
+ const resolvedHeaders = normalizedHeaders(extraHeaders);
63219
+ for (const [key, value] of headers) resolvedHeaders.set(key, value);
63220
+ const token = await tokenProvider();
63221
+ resolvedHeaders.set("authorization", `Bearer ${token}`);
63222
+ if (requestOptions.body !== void 0 && requestOptions.bodyEncoding !== "raw" && !resolvedHeaders.has("content-type")) {
63223
+ resolvedHeaders.set("content-type", "application/json");
63224
+ }
63225
+ const init = {
63226
+ method,
63227
+ headers: resolvedHeaders,
63228
+ ...requestOptions.body !== void 0 ? {
63229
+ body: requestOptions.bodyEncoding === "raw" ? requestOptions.body : JSON.stringify(requestOptions.body)
63230
+ } : {},
63231
+ ...signal ? { signal } : {}
63232
+ };
63233
+ let response;
63234
+ try {
63235
+ response = await fetchImpl(url2, init);
63236
+ } catch (error51) {
63237
+ if (signal?.aborted || attempt >= maxRetries) throw error51;
63238
+ await abortableSleep4(retryBaseDelayMs * 2 ** attempt, signal);
63239
+ continue;
63240
+ }
63241
+ if (response.ok) return response;
63242
+ if (isRetryableStatus2(response.status) && attempt < maxRetries) {
63243
+ await response.body?.cancel();
63244
+ await abortableSleep4(retryDelayMs2(response, attempt, retryBaseDelayMs), signal);
63245
+ continue;
63246
+ }
63247
+ const detail = redactText4(await response.text(), { additionalSecrets: [token] });
63248
+ throw new Error(
63249
+ `databricks workspace API: ${response.status} ${response.statusText}: ${detail.slice(0, 2e3)}`
63250
+ );
63251
+ }
63252
+ }
63253
+ return {
63254
+ async request(method, path4, requestOptions = {}) {
63255
+ const response = await requestRaw(method, path4, requestOptions);
63256
+ if (response.status === 204) return void 0;
63257
+ return await response.json();
63258
+ },
63259
+ requestRaw
63260
+ };
63261
+ }
63262
+ function nativePath(path4) {
63263
+ if (!path4.startsWith("/") || path4.includes("?") || path4.includes("#") || path4.includes("\\") || path4.startsWith("//")) {
63264
+ throw new Error(
63265
+ "databricks workspace API: path must be an absolute workspace-relative path without query or fragment text."
63266
+ );
63267
+ }
63268
+ if (!(path4.startsWith("/api/") || path4.startsWith("/serving-endpoints/"))) {
63269
+ throw new Error("databricks workspace API: path must target /api/* or /serving-endpoints/*.");
63270
+ }
63271
+ if (/%2f|%5c/iu.test(path4)) {
63272
+ throw new Error("databricks workspace API: encoded path separators are not allowed.");
63273
+ }
63274
+ let segments;
63275
+ try {
63276
+ segments = path4.split("/").map((segment2) => decodeURIComponent(segment2));
63277
+ } catch {
63278
+ throw new Error("databricks workspace API: path contains invalid percent encoding.");
63279
+ }
63280
+ if (segments.some((segment2) => segment2 === "." || segment2 === "..")) {
63281
+ throw new Error("databricks workspace API: relative path segments are not allowed.");
63282
+ }
63283
+ return path4;
63284
+ }
63285
+ function normalizedHeaders(input) {
63286
+ const headers = new Headers(input);
63287
+ if (headers.has("authorization") || headers.has("proxy-authorization")) {
63288
+ throw new Error(
63289
+ "databricks workspace API: authorization headers are managed by the configured principal."
63290
+ );
63291
+ }
63292
+ return headers;
63293
+ }
63294
+ function boundedRetries(value) {
63295
+ if (!Number.isInteger(value) || value < 0 || value > 10)
63296
+ throw new Error("databricks workspace API: maxRetries must be an integer from 0 to 10.");
63297
+ return value;
63298
+ }
63299
+ function isRetryableStatus2(status) {
63300
+ return status === 429 || status === 499 || status >= 500 && status <= 599;
63301
+ }
63302
+ function retryDelayMs2(response, attempt, base2) {
63303
+ const retryAfter = response.headers.get("retry-after");
63304
+ if (retryAfter) {
63305
+ const seconds = Number(retryAfter);
63306
+ if (Number.isFinite(seconds) && seconds >= 0) return seconds * 1e3;
63307
+ }
63308
+ return base2 * 2 ** attempt;
63309
+ }
63310
+ function combineAbortSignals2(clientSignal, requestSignal) {
63311
+ if (!clientSignal) return requestSignal;
63312
+ if (!requestSignal || requestSignal === clientSignal) return clientSignal;
63313
+ return AbortSignal.any([clientSignal, requestSignal]);
63314
+ }
63315
+ function abortableSleep4(ms, signal) {
63316
+ if (signal?.aborted)
63317
+ return Promise.reject(
63318
+ signal.reason ?? new DOMException("The operation was aborted.", "AbortError")
63319
+ );
63320
+ if (!signal) return new Promise((resolve2) => setTimeout(resolve2, ms));
63321
+ return new Promise((resolve2, reject) => {
63322
+ const timer = setTimeout(() => {
63323
+ signal.removeEventListener("abort", abort);
63324
+ resolve2();
63325
+ }, ms);
63326
+ const abort = () => {
63327
+ clearTimeout(timer);
63328
+ signal.removeEventListener("abort", abort);
63329
+ reject(signal.reason ?? new DOMException("The operation was aborted.", "AbortError"));
63330
+ };
63331
+ signal.addEventListener("abort", abort, { once: true });
63332
+ });
63333
+ }
63334
+
62928
63335
  // src/agent.ts
62929
63336
  import {
62930
63337
  defineAgent,
@@ -63434,11 +63841,32 @@ function createDatabricksRagChain(options) {
63434
63841
  const retrievalQuery = preprocess2 === "none" ? input.question : await preprocess2(input.question);
63435
63842
  const preprocessMs = Date.now() - preStarted;
63436
63843
  const retrieveStarted = Date.now();
63437
- const chunks = await retriever.retrieve(retrievalQuery, {
63438
- k: topK,
63439
- ...options.filter ? { filter: options.filter } : {},
63844
+ const retrievalOptions = {
63845
+ ...options.retrieval,
63846
+ ...input.retrieval,
63847
+ k: input.retrieval?.k ?? options.retrieval?.k ?? topK,
63848
+ ...input.retrieval?.filter ? { filter: input.retrieval.filter } : options.retrieval?.filter ? { filter: options.retrieval.filter } : options.filter ? { filter: options.filter } : {},
63440
63849
  ...input.signal ? { signal: input.signal } : {}
63441
- });
63850
+ };
63851
+ let chunks;
63852
+ let retrieval;
63853
+ if (isDatabricksAiSearchRetriever(retriever)) {
63854
+ const result = await retriever.query(retrievalQuery, retrievalOptions);
63855
+ chunks = result.chunks;
63856
+ retrieval = {
63857
+ inputMode: retrievalOptions.inputMode ?? retriever.inputMode,
63858
+ strategy: retrievalOptions.strategy ?? retriever.strategy,
63859
+ ...result.nextPageToken ? { nextPageToken: result.nextPageToken } : {},
63860
+ ...result.facetResult ? { facetResult: result.facetResult } : {}
63861
+ };
63862
+ } else {
63863
+ assertPortableRetrievalOptions(retrievalOptions);
63864
+ chunks = await retriever.retrieve(retrievalQuery, {
63865
+ k: retrievalOptions.k ?? topK,
63866
+ ...retrievalOptions.filter ? { filter: retrievalOptions.filter } : {},
63867
+ ...input.signal ? { signal: input.signal } : {}
63868
+ });
63869
+ }
63442
63870
  const retrieveMs = Date.now() - retrieveStarted;
63443
63871
  const context = formatContext(chunks, { maxContextChars, maxChunkChars });
63444
63872
  const augmentedPrompt = userTemplate.replaceAll("{{question}}", input.question).replaceAll("{{context}}", context);
@@ -63462,7 +63890,8 @@ function createDatabricksRagChain(options) {
63462
63890
  chunks,
63463
63891
  retrieveMs,
63464
63892
  augmentedPrompt,
63465
- sources
63893
+ sources,
63894
+ ...retrieval ? { retrieval } : {}
63466
63895
  };
63467
63896
  }
63468
63897
  function initialRequest(augmentedPrompt, signal) {
@@ -63526,6 +63955,7 @@ Sources: ${citations.map((citation) => citation.id).join(", ")}`;
63526
63955
  citations,
63527
63956
  ...options.model ? { model: options.model } : {},
63528
63957
  ...options.index ? { index: options.index } : {},
63958
+ ...prepared.retrieval ? { retrieval: prepared.retrieval } : {},
63529
63959
  latencyMs: {
63530
63960
  preprocess: prepared.preprocessMs,
63531
63961
  retrieve: prepared.retrieveMs,
@@ -63592,6 +64022,29 @@ Sources: ${citations.map((citation) => citation.id).join(", ")}`;
63592
64022
  }
63593
64023
  };
63594
64024
  }
64025
+ function isDatabricksAiSearchRetriever(retriever) {
64026
+ const candidate = retriever;
64027
+ return candidate.kind === "databricks-ai-search" && typeof candidate.query === "function";
64028
+ }
64029
+ function assertPortableRetrievalOptions(options) {
64030
+ const nativeKeys = [
64031
+ "inputMode",
64032
+ "strategy",
64033
+ "queryVector",
64034
+ "scoreThreshold",
64035
+ "queryColumns",
64036
+ "sortColumns",
64037
+ "facets",
64038
+ "reranker",
64039
+ "columnsToRerank"
64040
+ ];
64041
+ const unsupported = nativeKeys.filter((key) => options[key] !== void 0);
64042
+ if (unsupported.length > 0) {
64043
+ throw new Error(
64044
+ `RAG native retrieval options require a Databricks AI Search retriever: ${unsupported.join(", ")}.`
64045
+ );
64046
+ }
64047
+ }
63595
64048
  function formatContext(chunks, limits) {
63596
64049
  if (chunks.length === 0) return "(no retrieved context)";
63597
64050
  const rows = [];
@@ -63866,8 +64319,15 @@ function buildDatabricksBundle(config2, scope) {
63866
64319
  textColumn: aiSearch.textColumn,
63867
64320
  ...aiSearch.columns ? { columns: aiSearch.columns } : {},
63868
64321
  ...aiSearch.idColumn ? { idColumn: aiSearch.idColumn } : {},
63869
- ...aiSearch.queryType ? { queryType: aiSearch.queryType } : {},
63870
- ...embeddings ? { embeddings } : {}
64322
+ ...aiSearch.inputMode ? { inputMode: aiSearch.inputMode } : {},
64323
+ ...aiSearch.strategy ? { strategy: aiSearch.strategy } : {},
64324
+ ...embeddings ? { embeddings } : {},
64325
+ ...aiSearch.scoreThreshold !== void 0 ? { scoreThreshold: aiSearch.scoreThreshold } : {},
64326
+ ...aiSearch.queryColumns ? { queryColumns: aiSearch.queryColumns } : {},
64327
+ ...aiSearch.sortColumns ? { sortColumns: aiSearch.sortColumns } : {},
64328
+ ...aiSearch.facets ? { facets: aiSearch.facets } : {},
64329
+ ...aiSearch.reranker ? { reranker: aiSearch.reranker } : {},
64330
+ ...aiSearch.columnsToRerank ? { columnsToRerank: aiSearch.columnsToRerank } : {}
63871
64331
  });
63872
64332
  searchTool = createSearchTool2(retriever, {
63873
64333
  ...aiSearch.searchToolName ? { name: aiSearch.searchToolName } : {},
@@ -64111,6 +64571,7 @@ function databricksRagChain(options) {
64111
64571
  ...options.model ? { model: options.model } : {},
64112
64572
  ...options.topK !== void 0 ? { topK: options.topK } : {},
64113
64573
  ...options.filter ? { filter: options.filter } : {},
64574
+ ...options.retrieval ? { retrieval: options.retrieval } : {},
64114
64575
  ...options.preprocess ? { preprocess: options.preprocess } : {},
64115
64576
  ...options.prompt ? { prompt: options.prompt } : {},
64116
64577
  ...options.postProcess ? { postProcess: options.postProcess } : {},
@@ -64129,6 +64590,7 @@ export {
64129
64590
  DATABRICKS_CERTIFICATION_RESOURCE_PREFIX,
64130
64591
  DATABRICKS_OPTIONAL_CERTIFICATION_CHECKS,
64131
64592
  DATABRICKS_PACKAGE_COMPATIBILITY,
64593
+ DATABRICKS_PLATFORM_DOMAINS,
64132
64594
  DATABRICKS_RELEASE_CERTIFICATION_CHECKS,
64133
64595
  DATABRICKS_SDK_VERSION,
64134
64596
  DatabricksAiSearchAdmin,
@@ -64218,6 +64680,7 @@ export {
64218
64680
  databricksTenantCostLimit,
64219
64681
  databricksUnityCatalogAdminTools,
64220
64682
  databricksWithManagedMcp,
64683
+ databricksWorkspaceApi,
64221
64684
  databricksWorkspaceOrigin,
64222
64685
  defaultDatabricksCertificationChecks,
64223
64686
  defineDatabricksAgent,