@fabric-harness/databricks 3.0.2 → 4.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 CHANGED
@@ -71,10 +71,10 @@ await jobs.runJob({ jobId: 42, idempotencyToken: submission.id });
71
71
 
72
72
  `databricks({ ... }).sdk` exposes the principal-bound generated clients to custom agent runs. Fabric
73
73
  adds governance, approval, lifecycle safety, retries for explicitly idempotent operations, lineage,
74
- and durable state; it does not reimplement stable Databricks service APIs. A small
75
- `DatabricksPreviewClient` remains only for APIs absent from the modular SDK: Agent Services, Genie
76
- Agent Mode streaming, Genie ACLs, Workspace object import/export, MLflow 3 tracing, and AI
77
- Gateway/model-service discovery.
74
+ and durable state; it does not reimplement stable Databricks service APIs. A small private preview
75
+ transport remains only for APIs absent from the modular SDK: Agent Services, Genie Agent Mode
76
+ streaming, Genie ACLs, Workspace object import/export, MLflow 3 tracing, and AI Gateway/model-service
77
+ discovery. Callers use typed bundle capabilities rather than constructing that transport.
78
78
 
79
79
  One compatibility exception is deliberately quarantined: SDK 0.21's generated Genie query-result
80
80
  parser rejects Databricks' real row-array payload. Genie retries that one decoded response through the
@@ -139,12 +139,14 @@ See [Databricks resource management](https://harness.fabric.pro/docs/databricks/
139
139
  ## Unity Catalog Agent Services
140
140
 
141
141
  ```ts
142
- import { DatabricksPreviewClient, databricksAgentServices } from '@fabric-harness/databricks';
142
+ import { databricks, databricksPrincipalFromEnv } from '@fabric-harness/databricks';
143
143
 
144
- const services = databricksAgentServices(
145
- new DatabricksPreviewClient({ host: process.env.DATABRICKS_HOST!, token: process.env.DATABRICKS_TOKEN! }),
146
- { acknowledgeBeta: true },
147
- );
144
+ const workspace = databricks({
145
+ host: process.env.DATABRICKS_HOST!,
146
+ principal: databricksPrincipalFromEnv(process.env),
147
+ agentServices: { acknowledgeBeta: true },
148
+ });
149
+ const services = workspace.agentServices!;
148
150
 
149
151
  await services.create({
150
152
  catalog: 'main',
package/dist/agent.js CHANGED
@@ -17385,6 +17385,172 @@ function fabricPrincipalFor(principal, overrides = {}) {
17385
17385
  // src/index.ts
17386
17386
  import { createSearchTool } from "@fabric-harness/sdk";
17387
17387
 
17388
+ // src/agent-services.ts
17389
+ var DATABRICKS_AGENT_SERVICES_API = "/api/2.1/unity-catalog/agent-services";
17390
+ var DATABRICKS_AGENT_SERVICE_SECURABLE = "AGENT_SERVICE";
17391
+ var DatabricksAgentServices = class {
17392
+ constructor(client, options) {
17393
+ this.client = client;
17394
+ if (options.acknowledgeBeta !== true) {
17395
+ throw new Error("databricks agent services: acknowledgeBeta must be true.");
17396
+ }
17397
+ }
17398
+ create(options) {
17399
+ const catalog = ucIdentifier(options.catalog, "catalog");
17400
+ const schema = ucIdentifier(options.schema, "schema");
17401
+ const id = ucIdentifier(options.id, "agent service id");
17402
+ const basePath = externalBasePath(options.basePath ?? "/responses");
17403
+ return this.client.post(
17404
+ DATABRICKS_AGENT_SERVICES_API,
17405
+ {
17406
+ agent_service_type: "AGENT_SERVICE_TYPE_EXTERNAL",
17407
+ ...options.comment !== void 0 ? { comment: options.comment } : {},
17408
+ config: {
17409
+ connection: { name: connectionResourceName(options.connection) },
17410
+ base_path: basePath,
17411
+ ...options.systemPrompt !== void 0 ? { system_prompt: options.systemPrompt } : {}
17412
+ }
17413
+ },
17414
+ { parent: `schemas/${catalog}.${schema}`, agent_service_id: id },
17415
+ { retry: "never" }
17416
+ );
17417
+ }
17418
+ get(fullName) {
17419
+ return this.client.get(agentServicePath(fullName));
17420
+ }
17421
+ list(options = {}) {
17422
+ if (options.catalog === void 0 !== (options.schema === void 0)) {
17423
+ throw new Error("databricks agent services: catalog and schema must be provided together.");
17424
+ }
17425
+ const parent = options.catalog && options.schema ? `schemas/${ucIdentifier(options.catalog, "catalog")}.${ucIdentifier(options.schema, "schema")}` : void 0;
17426
+ return this.client.get(DATABRICKS_AGENT_SERVICES_API, {
17427
+ parent,
17428
+ page_token: options.pageToken
17429
+ });
17430
+ }
17431
+ update(fullName, options) {
17432
+ const mask = [];
17433
+ const config2 = {};
17434
+ const body = {};
17435
+ if (options.comment !== void 0) {
17436
+ mask.push("comment");
17437
+ body.comment = options.comment;
17438
+ }
17439
+ if (options.basePath !== void 0) {
17440
+ mask.push("config.base_path");
17441
+ config2.base_path = externalBasePath(options.basePath);
17442
+ }
17443
+ if (options.systemPrompt !== void 0) {
17444
+ mask.push("config.system_prompt");
17445
+ config2.system_prompt = options.systemPrompt;
17446
+ }
17447
+ if (mask.length === 0) {
17448
+ throw new Error(
17449
+ "databricks agent services: update requires comment, basePath or systemPrompt."
17450
+ );
17451
+ }
17452
+ if (Object.keys(config2).length > 0) body.config = config2;
17453
+ return this.client.request(
17454
+ "PATCH",
17455
+ agentServicePath(fullName),
17456
+ body,
17457
+ { update_mask: mask.join(",") },
17458
+ { retry: "safe" }
17459
+ );
17460
+ }
17461
+ delete(fullName) {
17462
+ return this.client.request(
17463
+ "DELETE",
17464
+ agentServicePath(fullName),
17465
+ void 0,
17466
+ {},
17467
+ { retry: "never" }
17468
+ );
17469
+ }
17470
+ permissions(fullName) {
17471
+ return this.client.get(permissionsPath(fullName));
17472
+ }
17473
+ updatePermissions(fullName, changes) {
17474
+ if (changes.length === 0) {
17475
+ throw new Error("databricks agent services: at least one permission change is required.");
17476
+ }
17477
+ for (const change of changes) {
17478
+ if (!change.principal.trim())
17479
+ throw new Error("databricks agent services: principal cannot be empty.");
17480
+ if ((change.add?.length ?? 0) === 0 && (change.remove?.length ?? 0) === 0) {
17481
+ throw new Error(
17482
+ `databricks agent services: ${change.principal} has no privileges to add or remove.`
17483
+ );
17484
+ }
17485
+ }
17486
+ return this.client.request(
17487
+ "PATCH",
17488
+ permissionsPath(fullName),
17489
+ { changes },
17490
+ {},
17491
+ { retry: "safe" }
17492
+ );
17493
+ }
17494
+ grant(fullName, principal, privileges = ["EXECUTE"]) {
17495
+ return this.updatePermissions(fullName, [{ principal, add: privileges }]);
17496
+ }
17497
+ revoke(fullName, principal, privileges = ["EXECUTE"]) {
17498
+ return this.updatePermissions(fullName, [{ principal, remove: privileges }]);
17499
+ }
17500
+ };
17501
+ function databricksAgentServices(client, options) {
17502
+ return new DatabricksAgentServices(client, options);
17503
+ }
17504
+ function agentServicePath(fullName) {
17505
+ return `${DATABRICKS_AGENT_SERVICES_API}/${encodeURIComponent(fullUcName(fullName))}`;
17506
+ }
17507
+ function permissionsPath(fullName) {
17508
+ return `/api/2.1/unity-catalog/permissions/${DATABRICKS_AGENT_SERVICE_SECURABLE}/${encodeURIComponent(fullUcName(fullName))}`;
17509
+ }
17510
+ function fullUcName(value) {
17511
+ const parts = value.split(".");
17512
+ if (parts.length !== 3) {
17513
+ throw new Error(
17514
+ `databricks agent services: expected catalog.schema.service, received ${value}.`
17515
+ );
17516
+ }
17517
+ return parts.map(
17518
+ (part, index) => ucIdentifier(part, ["catalog", "schema", "service"][index] ?? "identifier")
17519
+ ).join(".");
17520
+ }
17521
+ function connectionResourceName(value) {
17522
+ const trimmed = value.trim();
17523
+ const name = trimmed.startsWith("connections/") ? trimmed.slice("connections/".length) : trimmed;
17524
+ const parts = name.split(".");
17525
+ if (parts.length !== 1 && parts.length !== 3) {
17526
+ throw new Error(
17527
+ `databricks agent services: expected connection name or catalog.schema.connection, received ${value}.`
17528
+ );
17529
+ }
17530
+ return `connections/${parts.map(
17531
+ (part, index) => ucIdentifier(
17532
+ part,
17533
+ parts.length === 1 ? "connection" : ["catalog", "schema", "connection"][index] ?? "identifier"
17534
+ )
17535
+ ).join(".")}`;
17536
+ }
17537
+ function externalBasePath(value) {
17538
+ const path = value.trim();
17539
+ if (!path.startsWith("/") || path.startsWith("//") || path.includes("?") || path.includes("#")) {
17540
+ throw new Error(
17541
+ "databricks agent services: basePath must be an absolute URL path without a query or fragment."
17542
+ );
17543
+ }
17544
+ return path;
17545
+ }
17546
+ function ucIdentifier(value, label) {
17547
+ const normalized = value.trim();
17548
+ if (!/^[A-Za-z0-9_][A-Za-z0-9_$-]*$/.test(normalized)) {
17549
+ throw new Error(`databricks agent services: invalid ${label} ${JSON.stringify(value)}.`);
17550
+ }
17551
+ return normalized;
17552
+ }
17553
+
17388
17554
  // src/ai-search-admin.ts
17389
17555
  var DatabricksAiSearchAdmin = class {
17390
17556
  constructor(client) {
@@ -17625,6 +17791,55 @@ function jitter(ms) {
17625
17791
  return Math.max(1, Math.round(ms * (0.9 + Math.random() * 0.2)));
17626
17792
  }
17627
17793
 
17794
+ // src/ai-gateway.ts
17795
+ async function ensureDatabricksAiGateway(client) {
17796
+ await client.get("/api/ai-gateway/v2/endpoints", { page_size: 1 });
17797
+ }
17798
+ async function listDatabricksModelServices(client, options = {}) {
17799
+ const pageSize = positiveInteger(options.pageSize ?? 100, "pageSize");
17800
+ const maxPages = positiveInteger(options.maxPages ?? 100, "maxPages");
17801
+ const requiredPrefix = options.requiredPrefix ?? "system.ai.";
17802
+ const services = /* @__PURE__ */ new Map();
17803
+ const seenTokens = /* @__PURE__ */ new Set();
17804
+ let pageToken;
17805
+ for (let page = 0; page < maxPages; page += 1) {
17806
+ const response = await client.get(
17807
+ "/api/2.1/unity-catalog/model-services",
17808
+ { page_size: pageSize, ...pageToken ? { page_token: pageToken } : {} }
17809
+ );
17810
+ for (const raw of response.model_services ?? []) {
17811
+ const service = normalizeModelService(raw, requiredPrefix);
17812
+ if (service) services.set(service.name, service);
17813
+ }
17814
+ const next = response.next_page_token?.trim();
17815
+ if (!next) return [...services.values()].sort((a2, b2) => a2.name.localeCompare(b2.name));
17816
+ if (seenTokens.has(next))
17817
+ throw new Error(
17818
+ `databricks model-services pagination repeated token after page ${page + 1}.`
17819
+ );
17820
+ seenTokens.add(next);
17821
+ pageToken = next;
17822
+ }
17823
+ throw new Error(`databricks model-services pagination exceeded ${maxPages} pages.`);
17824
+ }
17825
+ function normalizeModelService(raw, requiredPrefix) {
17826
+ const rawName = typeof raw.name === "string" ? raw.name.trim() : "";
17827
+ const name = rawName.replace(/^model-services\//, "");
17828
+ if (!name.startsWith(requiredPrefix)) return void 0;
17829
+ return {
17830
+ name,
17831
+ ...typeof raw.comment === "string" ? { comment: raw.comment } : {},
17832
+ ...typeof raw.creator === "string" ? { creator: raw.creator } : {},
17833
+ ...typeof raw.created_at === "number" ? { createdAt: raw.created_at } : {},
17834
+ ...typeof raw.updated_at === "number" ? { updatedAt: raw.updated_at } : {}
17835
+ };
17836
+ }
17837
+ function positiveInteger(value, name) {
17838
+ if (!Number.isSafeInteger(value) || value <= 0)
17839
+ throw new Error(`${name} must be a positive integer.`);
17840
+ return value;
17841
+ }
17842
+
17628
17843
  // src/sql-exec.ts
17629
17844
  var TERMINAL_STATES = /* @__PURE__ */ new Set(["SUCCEEDED", "FAILED", "CANCELED", "CLOSED"]);
17630
17845
  async function runStatement(client, warehouseId, statement, parameters, poll) {
@@ -17857,10 +18072,10 @@ var DatabricksGenieAgentModeClient = class {
17857
18072
  if (options.acknowledgeBeta !== true)
17858
18073
  throw new Error("Databricks Genie Agent Mode requires acknowledgeBeta: true.");
17859
18074
  this.agentId = validateAgentId(options.agentId);
17860
- this.maxEventBytes = positiveInteger(options.maxEventBytes ?? 2 * 1024 * 1024, "maxEventBytes");
17861
- this.maxEvents = positiveInteger(options.maxEvents ?? 1e4, "maxEvents");
17862
- this.timeoutMs = positiveInteger(options.timeoutMs ?? 90 * 6e4, "timeoutMs");
17863
- this.idleTimeoutMs = positiveInteger(options.idleTimeoutMs ?? 2 * 6e4, "idleTimeoutMs");
18075
+ this.maxEventBytes = positiveInteger2(options.maxEventBytes ?? 2 * 1024 * 1024, "maxEventBytes");
18076
+ this.maxEvents = positiveInteger2(options.maxEvents ?? 1e4, "maxEvents");
18077
+ this.timeoutMs = positiveInteger2(options.timeoutMs ?? 90 * 6e4, "timeoutMs");
18078
+ this.idleTimeoutMs = positiveInteger2(options.idleTimeoutMs ?? 2 * 6e4, "idleTimeoutMs");
17864
18079
  this.onEvent = options.onEvent;
17865
18080
  }
17866
18081
  agentId;
@@ -17975,7 +18190,7 @@ var DatabricksGenieAgentModeClient = class {
17975
18190
  `/api/2.0/genie/agents/${encodeURIComponent(this.agentId)}/conversations/${encodeURIComponent(nonEmpty(conversationId, "conversationId"))}/items`,
17976
18191
  {
17977
18192
  after: optionalNonEmpty(options.after, "after"),
17978
- limit: options.limit === void 0 ? void 0 : positiveInteger(options.limit, "limit")
18193
+ limit: options.limit === void 0 ? void 0 : positiveInteger2(options.limit, "limit")
17979
18194
  },
17980
18195
  signalOption(options.signal)
17981
18196
  );
@@ -17994,7 +18209,7 @@ function databricksGenieAgentMode(client, options) {
17994
18209
  }
17995
18210
  function databricksGenieAgentModeTool(client, agentId, options = {}) {
17996
18211
  const configuredAgentId = validateAgentId(agentId);
17997
- const maxOutputBytes = positiveInteger(options.maxOutputBytes ?? 1024 * 1024, "maxOutputBytes");
18212
+ const maxOutputBytes = positiveInteger2(options.maxOutputBytes ?? 1024 * 1024, "maxOutputBytes");
17998
18213
  return {
17999
18214
  name: "databricks_genie_agent_mode",
18000
18215
  description: "Ask a Databricks Genie Agent through the Beta Agent Mode streaming API and return its terminal response.",
@@ -18194,7 +18409,7 @@ function nonEmpty(value, name) {
18194
18409
  function optionalNonEmpty(value, name) {
18195
18410
  return value === void 0 ? void 0 : nonEmpty(value, name);
18196
18411
  }
18197
- function positiveInteger(value, name) {
18412
+ function positiveInteger2(value, name) {
18198
18413
  if (!Number.isSafeInteger(value) || value <= 0)
18199
18414
  throw new Error(`Databricks Genie Agent Mode ${name} must be a positive integer.`);
18200
18415
  return value;
@@ -18629,10 +18844,17 @@ function databricksGenieAuthoringTools(client, options) {
18629
18844
  }
18630
18845
  throw error51;
18631
18846
  }
18632
- const current = await admin.get(agentId, {
18633
- includeConfiguration: true,
18634
- ...contextSignal(context)
18635
- });
18847
+ let current;
18848
+ try {
18849
+ current = await admin.get(agentId, {
18850
+ includeConfiguration: true,
18851
+ ...contextSignal(context)
18852
+ });
18853
+ } catch (lookupError) {
18854
+ if (!isGenieAbsentError(lookupError)) throw lookupError;
18855
+ await options.managedResourceStore.delete(GENIE_RESOURCE_TYPE, agentId);
18856
+ return { deleted: true, agentId, alreadyAbsent: true };
18857
+ }
18636
18858
  if (current.fingerprint !== expectedFingerprint) {
18637
18859
  throw new DatabricksManagedResourceConflictError({
18638
18860
  resourceType: GENIE_RESOURCE_TYPE,
@@ -19347,19 +19569,19 @@ var DatabricksGenieClient = class {
19347
19569
  this.agentId = resolveAgentId(options);
19348
19570
  this.previewClient = options.previewClient;
19349
19571
  this.basePath = `/api/2.0/genie/spaces/${enc2(this.agentId)}`;
19350
- this.pollIntervalMs = positiveInteger2(options.pollIntervalMs ?? 2e3, "pollIntervalMs");
19351
- this.timeoutMs = positiveInteger2(options.timeoutMs ?? 12e4, "timeoutMs");
19572
+ this.pollIntervalMs = positiveInteger3(options.pollIntervalMs ?? 2e3, "pollIntervalMs");
19573
+ this.timeoutMs = positiveInteger3(options.timeoutMs ?? 12e4, "timeoutMs");
19352
19574
  this.pollJitterRatio = boundedRatio(options.pollJitterRatio ?? 0.2, "pollJitterRatio");
19353
- this.maxAttachments = positiveInteger2(options.maxAttachments ?? 32, "maxAttachments");
19575
+ this.maxAttachments = positiveInteger3(options.maxAttachments ?? 32, "maxAttachments");
19354
19576
  this.maxUnknownAttachments = nonNegativeInteger(
19355
19577
  options.maxUnknownAttachments ?? 8,
19356
19578
  "maxUnknownAttachments"
19357
19579
  );
19358
- this.maxResultBytes = positiveInteger2(
19580
+ this.maxResultBytes = positiveInteger3(
19359
19581
  options.maxResultBytes ?? 2 * 1024 * 1024,
19360
19582
  "maxResultBytes"
19361
19583
  );
19362
- this.maxTextChars = positiveInteger2(options.maxTextChars ?? 1e5, "maxTextChars");
19584
+ this.maxTextChars = positiveInteger3(options.maxTextChars ?? 1e5, "maxTextChars");
19363
19585
  }
19364
19586
  agentId;
19365
19587
  basePath;
@@ -19694,7 +19916,7 @@ function nonEmpty3(value, name) {
19694
19916
  if (!normalized) throw new Error(`Databricks Genie ${name} cannot be empty.`);
19695
19917
  return normalized;
19696
19918
  }
19697
- function positiveInteger2(value, name) {
19919
+ function positiveInteger3(value, name) {
19698
19920
  if (!Number.isInteger(value) || value <= 0)
19699
19921
  throw new Error(`Databricks Genie ${name} must be a positive integer.`);
19700
19922
  return value;
@@ -20439,7 +20661,10 @@ function serializeTask(task) {
20439
20661
  policyId: task.newCluster.policyId,
20440
20662
  sparkVersion: task.newCluster.sparkVersion,
20441
20663
  nodeTypeId: task.newCluster.nodeTypeId,
20442
- numWorkers: task.newCluster.numWorkers,
20664
+ size: {
20665
+ $case: "numWorkers",
20666
+ numWorkers: task.newCluster.numWorkers
20667
+ },
20443
20668
  ...task.newCluster.customTags ? { customTags: task.newCluster.customTags } : {}
20444
20669
  } }
20445
20670
  } : {}
@@ -55601,6 +55826,151 @@ function databricksLakeflowTools(client) {
55601
55826
  ];
55602
55827
  }
55603
55828
 
55829
+ // src/mlflow-tracing.ts
55830
+ import { createHash } from "crypto";
55831
+ import { eventToTelemetrySpan } from "@fabric-harness/sdk";
55832
+ function mlflowTraceExporter(options) {
55833
+ const onError = options.onError ?? ((context, error51) => {
55834
+ console.error(`[fabric-harness:mlflow-tracing] ${context}:`, error51);
55835
+ });
55836
+ const buffers = /* @__PURE__ */ new Map();
55837
+ return {
55838
+ sink: {
55839
+ record(event) {
55840
+ try {
55841
+ const key = `agent:${event.agent}:${event.instanceId}:${event.session}`;
55842
+ if (event.type === "submission_started") {
55843
+ buffers.set(key, {
55844
+ submissionId: event.submissionId,
55845
+ agent: event.agent,
55846
+ instanceId: event.instanceId,
55847
+ session: event.session,
55848
+ startedAtMs: event.at,
55849
+ attemptCount: event.attemptCount,
55850
+ ...event.tenantId !== void 0 ? { tenantId: event.tenantId } : {},
55851
+ spans: []
55852
+ });
55853
+ return;
55854
+ }
55855
+ if (event.type !== "submission_settled") return;
55856
+ const buffer = buffers.get(key);
55857
+ buffers.delete(key);
55858
+ const startedAtMs = buffer?.startedAtMs ?? event.at - (event.durationMs ?? 0);
55859
+ const attemptCount = event.attemptCount ?? buffer?.attemptCount;
55860
+ const trace = buildMlflowTrace({
55861
+ submissionId: event.submissionId,
55862
+ agent: event.agent,
55863
+ instanceId: event.instanceId,
55864
+ session: event.session,
55865
+ experimentId: options.experimentId,
55866
+ startedAtMs,
55867
+ settledAtMs: event.at,
55868
+ state: event.outcome === "completed" ? "OK" : "ERROR",
55869
+ spans: buffer?.spans ?? [],
55870
+ ...attemptCount !== void 0 ? { attemptCount } : {},
55871
+ ...event.tenantId !== void 0 ? { tenantId: event.tenantId } : {},
55872
+ ...event.error !== void 0 ? { error: event.error } : {}
55873
+ });
55874
+ void options.client.post("/api/3.0/mlflow/traces", trace).catch((error51) => onError(`trace export failed for ${event.submissionId}`, error51));
55875
+ } catch (error51) {
55876
+ onError("telemetry event handling failed", error51);
55877
+ }
55878
+ }
55879
+ },
55880
+ onEvent(event) {
55881
+ try {
55882
+ if (!event.sessionId) return;
55883
+ const buffer = buffers.get(event.sessionId);
55884
+ if (!buffer) return;
55885
+ const span = eventToTelemetrySpan(event);
55886
+ if (span) buffer.spans.push(span);
55887
+ } catch (error51) {
55888
+ onError("event buffering failed", error51);
55889
+ }
55890
+ }
55891
+ };
55892
+ }
55893
+ function buildMlflowTrace(input) {
55894
+ const traceBytes = sha256(input.submissionId).subarray(0, 16);
55895
+ const traceIdBase64 = traceBytes.toString("base64");
55896
+ const rootSpanId = spanIdFor(input.submissionId, 0);
55897
+ const durationSeconds = Math.max(0, input.settledAtMs - input.startedAtMs) / 1e3;
55898
+ const rootSpan = {
55899
+ trace_id: traceIdBase64,
55900
+ span_id: rootSpanId,
55901
+ name: `fabric.submission ${input.agent}`,
55902
+ start_time_unix_nano: toUnixNano(input.startedAtMs),
55903
+ end_time_unix_nano: toUnixNano(input.settledAtMs),
55904
+ attributes: toOtlpAttributes({
55905
+ "fabric.submission_id": input.submissionId,
55906
+ "fabric.agent": input.agent,
55907
+ "fabric.instance_id": input.instanceId,
55908
+ "fabric.session": input.session,
55909
+ ...input.attemptCount !== void 0 ? { "fabric.attempt_count": input.attemptCount } : {},
55910
+ ...input.error !== void 0 ? { "fabric.error": input.error } : {}
55911
+ }),
55912
+ status: {
55913
+ code: input.state === "OK" ? "STATUS_CODE_OK" : "STATUS_CODE_ERROR",
55914
+ ...input.error !== void 0 ? { message: input.error } : {}
55915
+ }
55916
+ };
55917
+ const childSpans = input.spans.map(
55918
+ (span, index) => ({
55919
+ trace_id: traceIdBase64,
55920
+ span_id: spanIdFor(input.submissionId, index + 1),
55921
+ parent_span_id: rootSpanId,
55922
+ name: span.name,
55923
+ start_time_unix_nano: toUnixNano(Date.parse(span.startedAt)),
55924
+ end_time_unix_nano: toUnixNano(Date.parse(span.endedAt)),
55925
+ attributes: toOtlpAttributes(span.attributes),
55926
+ status: { code: "STATUS_CODE_OK" }
55927
+ })
55928
+ );
55929
+ return {
55930
+ trace: {
55931
+ trace_info: {
55932
+ trace_id: `tr-${traceBytes.toString("hex")}`,
55933
+ trace_location: {
55934
+ type: "MLFLOW_EXPERIMENT",
55935
+ mlflow_experiment: { experiment_id: input.experimentId }
55936
+ },
55937
+ request_time: new Date(input.startedAtMs).toISOString(),
55938
+ execution_duration: `${durationSeconds.toFixed(3)}s`,
55939
+ state: input.state,
55940
+ trace_metadata: {
55941
+ "fabric.submission_id": input.submissionId,
55942
+ "fabric.agent": input.agent,
55943
+ "fabric.instance_id": input.instanceId,
55944
+ "fabric.session": input.session,
55945
+ ...input.attemptCount !== void 0 ? { "fabric.attempt_count": String(input.attemptCount) } : {}
55946
+ },
55947
+ tags: {
55948
+ "fabric.agent": input.agent,
55949
+ ...input.tenantId !== void 0 ? { "fabric.tenant_id": input.tenantId } : {}
55950
+ }
55951
+ },
55952
+ trace_data: { spans: [rootSpan, ...childSpans] }
55953
+ }
55954
+ };
55955
+ }
55956
+ function sha256(seed) {
55957
+ return createHash("sha256").update(seed).digest();
55958
+ }
55959
+ function spanIdFor(submissionId, index) {
55960
+ return sha256(`${submissionId}:span:${index}`).subarray(0, 8).toString("base64");
55961
+ }
55962
+ function toUnixNano(epochMs) {
55963
+ return `${Math.round(epochMs)}000000`;
55964
+ }
55965
+ function toOtlpAttributes(attributes) {
55966
+ return Object.entries(attributes).map(([key, value]) => {
55967
+ if (typeof value === "number") {
55968
+ return Number.isInteger(value) ? { key, value: { int_value: String(value) } } : { key, value: { double_value: value } };
55969
+ }
55970
+ return { key, value: { string_value: String(value) } };
55971
+ });
55972
+ }
55973
+
55604
55974
  // src/model.ts
55605
55975
  import {
55606
55976
  OpenAICompatibleModelProvider,
@@ -55887,11 +56257,19 @@ var DatabricksServingAdmin = class {
55887
56257
  });
55888
56258
  }
55889
56259
  updateAiGateway(name, update) {
56260
+ const rateLimits = update.rateLimits?.map((limit) => ({
56261
+ ...limit.calls !== void 0 ? { calls: positiveBigInt(limit.calls, "rateLimits.calls") } : {},
56262
+ ...limit.tokens !== void 0 ? { tokens: positiveBigInt(limit.tokens, "rateLimits.tokens") } : {},
56263
+ ...limit.key !== void 0 ? { key: limit.key } : {},
56264
+ ...limit.renewalPeriod !== void 0 ? { renewalPeriod: limit.renewalPeriod } : {},
56265
+ ...limit.principal !== void 0 ? { principal: limit.principal } : {}
56266
+ }));
55890
56267
  return this.client.putInferenceEndpointAiGateway({
55891
56268
  name,
55892
- ...update.rateLimits ? { rateLimits: update.rateLimits } : {},
56269
+ ...rateLimits ? { rateLimits } : {},
55893
56270
  ...update.guardrails ? { guardrails: update.guardrails } : {},
55894
- ...update.usageTracking ? { inferenceTableConfig: update.usageTracking } : {},
56271
+ ...update.inferenceTableConfig ? { inferenceTableConfig: update.inferenceTableConfig } : {},
56272
+ ...update.usageTrackingConfig ? { usageTrackingConfig: update.usageTrackingConfig } : {},
55895
56273
  ...update.fallbackEnabled !== void 0 ? { fallbackConfig: { enabled: update.fallbackEnabled } } : {}
55896
56274
  });
55897
56275
  }
@@ -55978,6 +56356,11 @@ function validate(spec) {
55978
56356
  throw new Error("databricks serving: provisionedModelUnits must be a positive integer.");
55979
56357
  }
55980
56358
  }
56359
+ function positiveBigInt(value, name) {
56360
+ if (!Number.isSafeInteger(value) || value <= 0)
56361
+ throw new Error(`databricks serving: ${name} must be a positive safe integer.`);
56362
+ return BigInt(value);
56363
+ }
55981
56364
  function serialize2(spec) {
55982
56365
  return {
55983
56366
  name: spec.name,
@@ -56125,9 +56508,23 @@ function gatewaySchema() {
56125
56508
  additionalProperties: false,
56126
56509
  properties: {
56127
56510
  name: { type: "string" },
56128
- rateLimits: { type: "array", items: { type: "object", additionalProperties: true } },
56511
+ rateLimits: {
56512
+ type: "array",
56513
+ items: {
56514
+ type: "object",
56515
+ additionalProperties: false,
56516
+ properties: {
56517
+ calls: { type: "integer", minimum: 1 },
56518
+ tokens: { type: "integer", minimum: 1 },
56519
+ key: { type: "string" },
56520
+ renewalPeriod: { type: "string" },
56521
+ principal: { type: "string" }
56522
+ }
56523
+ }
56524
+ },
56129
56525
  guardrails: { type: "object", additionalProperties: true },
56130
- usageTracking: { type: "object", additionalProperties: true },
56526
+ inferenceTableConfig: { type: "object", additionalProperties: true },
56527
+ usageTrackingConfig: { type: "object", additionalProperties: true },
56131
56528
  fallbackEnabled: { type: "boolean" }
56132
56529
  },
56133
56530
  required: ["name"]
@@ -56624,6 +57021,7 @@ function buildDatabricksBundle(config2, scope) {
56624
57021
  });
56625
57022
  const client = native.preview;
56626
57023
  const genieAgentModeClient = genie.agentMode ? databricksGenieAgentMode(client, genie.agentMode) : void 0;
57024
+ const agentServicesClient = config2.agentServices ? databricksAgentServices(client, config2.agentServices) : void 0;
56627
57025
  let embeddings;
56628
57026
  let retriever;
56629
57027
  let searchTool;
@@ -56744,6 +57142,12 @@ function buildDatabricksBundle(config2, scope) {
56744
57142
  })
56745
57143
  } : {},
56746
57144
  ...genieAgentModeClient ? { genieAgentMode: genieAgentModeClient } : {},
57145
+ ...agentServicesClient ? { agentServices: agentServicesClient } : {},
57146
+ aiGateway: {
57147
+ ensure: () => ensureDatabricksAiGateway(client),
57148
+ listModelServices: (options) => listDatabricksModelServices(client, options)
57149
+ },
57150
+ mlflowTraceExporter: (options) => mlflowTraceExporter({ client, ...options }),
56747
57151
  forPrincipal(input) {
56748
57152
  const scoped = buildDatabricksBundle(config2, {
56749
57153
  identity: input.tokenProvider,