@fabric-harness/databricks 4.3.2 → 4.4.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.
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,eAAe,EAEf,YAAY,EAGZ,UAAU,EACV,aAAa,EACb,cAAc,EACd,OAAO,EACR,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAG3E,MAAM,MAAM,4BAA4B,CAAC,MAAM,GAAG,UAAU,EAAE,OAAO,GAAG,OAAO,IAAI,IAAI,CACrF,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,KAAK,GAAG,OAAO,CAChB,GAAG;IACF,UAAU,CAAC,EAAE,sBAAsB,CAAC;IACpC,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,KAAK,CAAC,EAAE,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,GAAG,CAAC,EAAE,CACJ,OAAO,EAAE,eAAe,CAAC,MAAM,CAAC,GAAG;QAAE,UAAU,EAAE,gBAAgB,CAAA;KAAE,KAChE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;CACjC,CAAC;AAkEF,wBAAgB,qBAAqB,CAAC,MAAM,GAAG,UAAU,EAAE,OAAO,GAAG,OAAO,EAC1E,OAAO,GAAE,4BAA4B,CAAC,MAAM,EAAE,OAAO,CAAM,GAC1D,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CA0C/B;AAuBD,wBAAgB,eAAe,CAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,CAgCnF"}
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EAEf,YAAY,EACZ,eAAe,EACf,YAAY,EAGZ,UAAU,EACV,aAAa,EACb,cAAc,EACd,OAAO,EACR,MAAM,qBAAqB,CAAC;AAO7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAI3E,MAAM,MAAM,4BAA4B,CAAC,MAAM,GAAG,UAAU,EAAE,OAAO,GAAG,OAAO,IAAI,IAAI,CACrF,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,KAAK,GAAG,OAAO,CAChB,GAAG;IACF,UAAU,CAAC,EAAE,sBAAsB,CAAC;IACpC,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,KAAK,CAAC,EAAE,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,GAAG,CAAC,EAAE,CACJ,OAAO,EAAE,eAAe,CAAC,MAAM,CAAC,GAAG;QAAE,UAAU,EAAE,gBAAgB,CAAA;KAAE,KAChE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;CACjC,CAAC;AAkEF,wBAAgB,qBAAqB,CAAC,MAAM,GAAG,UAAU,EAAE,OAAO,GAAG,OAAO,EAC1E,OAAO,GAAE,4BAA4B,CAAC,MAAM,EAAE,OAAO,CAAM,GAC1D,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CA6C/B;AAuBD,wBAAgB,eAAe,CAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,CAgCnF"}
package/dist/agent.js CHANGED
@@ -1793,7 +1793,11 @@ var require_json_bigint = __commonJS({
1793
1793
  });
1794
1794
 
1795
1795
  // src/agent.ts
1796
- import { defineAgent, mergeCapabilityPolicies } from "@fabric-harness/sdk/strict";
1796
+ import {
1797
+ defineAgent,
1798
+ listSandboxBackendFactories,
1799
+ mergeCapabilityPolicies
1800
+ } from "@fabric-harness/sdk/strict";
1797
1801
 
1798
1802
  // ../../node_modules/.pnpm/@databricks+sdk-auth@0.21.0/node_modules/@databricks/sdk-auth/package.json
1799
1803
  var package_default = {
@@ -57103,7 +57107,11 @@ function fabricHttpClient(fetchImpl, extraHeaders) {
57103
57107
  if (request.body instanceof ReadableStream) {
57104
57108
  init.duplex = "half";
57105
57109
  }
57106
- const response = await fetchImpl(request.url, init);
57110
+ const url2 = new URL(request.url);
57111
+ if (/^\/api\/serving-endpoints\/[^/]+\/invocations$/u.test(url2.pathname)) {
57112
+ url2.pathname = url2.pathname.slice("/api".length);
57113
+ }
57114
+ const response = await fetchImpl(url2, init);
57107
57115
  return {
57108
57116
  statusCode: response.status,
57109
57117
  headers: response.headers,
@@ -58044,6 +58052,190 @@ function base643(value) {
58044
58052
  return btoa(String.fromCharCode(...bytes));
58045
58053
  }
58046
58054
 
58055
+ // src/sql-sandbox.ts
58056
+ import { createRemoteSandboxEnv, registerSandboxBackendFactory, registerSandboxRefDecoder, unregisterSandboxBackendFactory, unregisterSandboxRefDecoder } from "@fabric-harness/sdk";
58057
+ var DATABRICKS_SQL_SANDBOX_REF_PROVIDER = "databricks-sql";
58058
+ function databricksSqlSandbox(options) {
58059
+ const identity = databricksIdentity(options.principal);
58060
+ const client = options.client ?? createDatabricksNativeClients({
58061
+ host: options.host,
58062
+ credentials: databricksCredentials(options.principal),
58063
+ tokenProvider: identity,
58064
+ ...options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}
58065
+ }).statements;
58066
+ const waitTimeoutSeconds = options.waitTimeoutSeconds ?? 30;
58067
+ const resultFormat = options.resultFormat ?? "jsonl";
58068
+ const memFs = /* @__PURE__ */ new Map();
58069
+ const api = {
58070
+ async exec(command) {
58071
+ const startedAt = Date.now();
58072
+ try {
58073
+ const response = await client.executeStatement({
58074
+ warehouseId: options.warehouseId,
58075
+ statement: command,
58076
+ waitTimeout: `${waitTimeoutSeconds}s`,
58077
+ onWaitTimeout: "CANCEL",
58078
+ ...options.catalog ? { catalog: options.catalog } : {},
58079
+ ...options.schema ? { schema: options.schema } : {}
58080
+ });
58081
+ if (response.status?.state === "FAILED" || response.status?.state === "CANCELED") {
58082
+ return {
58083
+ command,
58084
+ exitCode: 1,
58085
+ stdout: "",
58086
+ stderr: response.status.error?.message ?? `Statement ${response.status.state}`,
58087
+ durationMs: Date.now() - startedAt
58088
+ };
58089
+ }
58090
+ const stdout = serializeResult(response, resultFormat);
58091
+ return { command, exitCode: 0, stdout, stderr: "", durationMs: Date.now() - startedAt };
58092
+ } catch (error51) {
58093
+ return {
58094
+ command,
58095
+ exitCode: 1,
58096
+ stdout: "",
58097
+ stderr: error51 instanceof Error ? error51.message : String(error51),
58098
+ durationMs: Date.now() - startedAt
58099
+ };
58100
+ }
58101
+ },
58102
+ async readFile(path) {
58103
+ const bytes = memFs.get(path);
58104
+ if (!bytes) throw new Error(`No such file: ${path}`);
58105
+ return new TextDecoder().decode(bytes);
58106
+ },
58107
+ async readFileBuffer(path) {
58108
+ const bytes = memFs.get(path);
58109
+ if (!bytes) throw new Error(`No such file: ${path}`);
58110
+ return bytes;
58111
+ },
58112
+ async writeFile(path, content) {
58113
+ memFs.set(path, typeof content === "string" ? new TextEncoder().encode(content) : content);
58114
+ },
58115
+ async stat(path) {
58116
+ const bytes = memFs.get(path);
58117
+ if (!bytes) throw new Error(`No such file: ${path}`);
58118
+ return { type: "file", size: bytes.byteLength };
58119
+ },
58120
+ async readdir(path) {
58121
+ const prefix = path.replace(/\/$/, "");
58122
+ const direct = /* @__PURE__ */ new Set();
58123
+ for (const key of memFs.keys()) {
58124
+ if (!key.startsWith(`${prefix}/`)) continue;
58125
+ const tail = key.slice(prefix.length + 1);
58126
+ const slash = tail.indexOf("/");
58127
+ direct.add(slash > 0 ? tail.slice(0, slash) : tail);
58128
+ }
58129
+ return [...direct];
58130
+ },
58131
+ async exists(path) {
58132
+ return memFs.has(path);
58133
+ },
58134
+ async mkdir() {
58135
+ },
58136
+ async rm(path) {
58137
+ for (const key of [...memFs.keys()]) {
58138
+ if (key === path || key.startsWith(`${path}/`)) memFs.delete(key);
58139
+ }
58140
+ }
58141
+ };
58142
+ return createRemoteSandboxEnv(api, {
58143
+ cwd: "/workspace",
58144
+ capabilities: { exec: true, filesystem: true, binaryFiles: true, snapshots: false, restore: false, reconnect: true, network: "provider-managed", persistence: "session", isolation: "provider" },
58145
+ encodeRef: () => ({
58146
+ provider: DATABRICKS_SQL_SANDBOX_REF_PROVIDER,
58147
+ providerData: databricksSqlSandboxRefData(options)
58148
+ })
58149
+ });
58150
+ }
58151
+ function registerDatabricksSqlSandboxBackend(registration = {}) {
58152
+ registerSandboxBackendFactory("databricks", (factoryOptions) => createRegisteredDatabricksSqlSandbox(factoryOptions, registration));
58153
+ registerSandboxRefDecoder(DATABRICKS_SQL_SANDBOX_REF_PROVIDER, (providerData) => {
58154
+ const target = assertDatabricksSqlSandboxRefData(providerData);
58155
+ return (factoryOptions) => databricksSqlSandbox({
58156
+ ...target,
58157
+ principal: resolveRegisteredPrincipal(factoryOptions, target, registration),
58158
+ ...registration.client ? { client: registration.client } : {}
58159
+ });
58160
+ });
58161
+ }
58162
+ function createRegisteredDatabricksSqlSandbox(options, registration) {
58163
+ const env2 = options.env ?? process.env;
58164
+ const metadata = options.metadata ?? {};
58165
+ const catalog = metadataString(metadata, "databricksCatalog") ?? env2.DATABRICKS_CATALOG;
58166
+ const schema = metadataString(metadata, "databricksSchema") ?? env2.DATABRICKS_SCHEMA;
58167
+ const resultFormat = metadataString(metadata, "databricksResultFormat");
58168
+ const target = {
58169
+ host: metadataString(metadata, "databricksHost") ?? env2.DATABRICKS_HOST ?? "",
58170
+ warehouseId: metadataString(metadata, "databricksWarehouseId") ?? env2.DATABRICKS_WAREHOUSE_ID ?? "",
58171
+ ...catalog ? { catalog } : {},
58172
+ ...schema ? { schema } : {},
58173
+ ...resultFormat ? { resultFormat: assertResultFormat(resultFormat) } : {}
58174
+ };
58175
+ assertDatabricksSqlSandboxRefData(target);
58176
+ return databricksSqlSandbox({
58177
+ ...target,
58178
+ principal: resolveRegisteredPrincipal(options, target, registration),
58179
+ ...registration.client ? { client: registration.client } : {}
58180
+ });
58181
+ }
58182
+ function resolveRegisteredPrincipal(options, target, registration) {
58183
+ const env2 = options.env ?? process.env;
58184
+ return registration.resolvePrincipal?.(env2, target) ?? databricksPrincipalFromEnv(env2);
58185
+ }
58186
+ function databricksSqlSandboxRefData(options) {
58187
+ return {
58188
+ host: options.host,
58189
+ warehouseId: options.warehouseId,
58190
+ ...options.catalog ? { catalog: options.catalog } : {},
58191
+ ...options.schema ? { schema: options.schema } : {},
58192
+ ...options.resultFormat ? { resultFormat: options.resultFormat } : {},
58193
+ ...options.waitTimeoutSeconds !== void 0 ? { waitTimeoutSeconds: options.waitTimeoutSeconds } : {}
58194
+ };
58195
+ }
58196
+ function assertDatabricksSqlSandboxRefData(value) {
58197
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Invalid Databricks SQL sandbox reference.");
58198
+ const data = value;
58199
+ if (typeof data.host !== "string" || data.host.trim().length === 0) throw new Error("Databricks SQL sandbox reference is missing host.");
58200
+ if (typeof data.warehouseId !== "string" || data.warehouseId.trim().length === 0) throw new Error("Databricks SQL sandbox reference is missing warehouseId.");
58201
+ const result = { host: data.host, warehouseId: data.warehouseId };
58202
+ if (typeof data.catalog === "string") result.catalog = data.catalog;
58203
+ if (typeof data.schema === "string") result.schema = data.schema;
58204
+ if (data.resultFormat !== void 0) result.resultFormat = assertResultFormat(data.resultFormat);
58205
+ if (data.waitTimeoutSeconds !== void 0) {
58206
+ if (typeof data.waitTimeoutSeconds !== "number" || !Number.isFinite(data.waitTimeoutSeconds)) throw new Error("Databricks SQL sandbox reference has an invalid waitTimeoutSeconds.");
58207
+ result.waitTimeoutSeconds = data.waitTimeoutSeconds;
58208
+ }
58209
+ return result;
58210
+ }
58211
+ function metadataString(metadata, key) {
58212
+ const value = metadata[key];
58213
+ return typeof value === "string" && value.trim().length > 0 ? value : void 0;
58214
+ }
58215
+ function assertResultFormat(value) {
58216
+ if (value === "jsonl" || value === "csv") return value;
58217
+ throw new Error("Databricks SQL sandbox result format must be jsonl or csv.");
58218
+ }
58219
+ function serializeResult(response, format) {
58220
+ const columns = response.manifest?.schema?.columns?.map((c2) => c2.name ?? "") ?? [];
58221
+ const rows = response.result?.dataArray ?? [];
58222
+ if (format === "csv") {
58223
+ const header = columns.join(",");
58224
+ const body = rows.map((row) => row.map(formatCsvCell).join(",")).join("\n");
58225
+ return [header, body].filter(Boolean).join("\n");
58226
+ }
58227
+ return rows.map((row) => {
58228
+ const obj = {};
58229
+ for (let i2 = 0; i2 < columns.length; i2 += 1) obj[columns[i2] ?? `_${i2}`] = row[i2];
58230
+ return JSON.stringify(obj);
58231
+ }).join("\n");
58232
+ }
58233
+ function formatCsvCell(value) {
58234
+ if (value === null || value === void 0) return "";
58235
+ const str = String(value);
58236
+ return /[",\n]/.test(str) ? `"${str.replace(/"/g, '""')}"` : str;
58237
+ }
58238
+
58047
58239
  // src/index.ts
58048
58240
  function databricks(config2) {
58049
58241
  return buildDatabricksBundle(config2);
@@ -58356,6 +58548,9 @@ function defineDatabricksAgent(options = {}) {
58356
58548
  } = merged;
58357
58549
  const directTools = tools.filter((tool7) => typeof tool7 !== "string");
58358
58550
  const toolRefs = tools.filter((tool7) => typeof tool7 === "string");
58551
+ if (sandbox === "databricks" && !listSandboxBackendFactories().includes("databricks")) {
58552
+ registerDatabricksSqlSandboxBackend();
58553
+ }
58359
58554
  const def = {
58360
58555
  ...definition,
58361
58556
  ...directTools.length > 0 ? { tools: directTools } : {},