@fabric-harness/databricks 4.3.0 → 4.3.2
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/app-user-authorization.d.ts +6 -0
- package/dist/app-user-authorization.d.ts.map +1 -1
- package/dist/app-user-authorization.js +33 -0
- package/dist/app-user-authorization.js.map +1 -1
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/agent-services.js +0 -142
- package/dist/agent-services.js.map +0 -1
- package/dist/ai-gateway.js +0 -51
- package/dist/ai-gateway.js.map +0 -1
- package/dist/ai-search-admin.js +0 -194
- package/dist/ai-search-admin.js.map +0 -1
- package/dist/ai.js +0 -22
- package/dist/ai.js.map +0 -1
- package/dist/app.js +0 -143
- package/dist/app.js.map +0 -1
- package/dist/authoring-certification.js +0 -476
- package/dist/authoring-certification.js.map +0 -1
- package/dist/capabilities.js +0 -633
- package/dist/capabilities.js.map +0 -1
- package/dist/certification-resource.js +0 -17
- package/dist/certification-resource.js.map +0 -1
- package/dist/certification-sweeper.js +0 -128
- package/dist/certification-sweeper.js.map +0 -1
- package/dist/certification.js +0 -236
- package/dist/certification.js.map +0 -1
- package/dist/client.d.ts +0 -58
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -184
- package/dist/client.js.map +0 -1
- package/dist/compatibility.js +0 -88
- package/dist/compatibility.js.map +0 -1
- package/dist/consumption.js +0 -85
- package/dist/consumption.js.map +0 -1
- package/dist/cost-budget-actuals.js +0 -316
- package/dist/cost-budget-actuals.js.map +0 -1
- package/dist/embeddings.js +0 -24
- package/dist/embeddings.js.map +0 -1
- package/dist/feature-serving.js +0 -29
- package/dist/feature-serving.js.map +0 -1
- package/dist/genie-agent-mode.js +0 -374
- package/dist/genie-agent-mode.js.map +0 -1
- package/dist/genie-authoring.js +0 -898
- package/dist/genie-authoring.js.map +0 -1
- package/dist/genie.js +0 -405
- package/dist/genie.js.map +0 -1
- package/dist/governance.js +0 -353
- package/dist/governance.js.map +0 -1
- package/dist/identity.js +0 -229
- package/dist/identity.js.map +0 -1
- package/dist/jobs-authoring.js +0 -570
- package/dist/jobs-authoring.js.map +0 -1
- package/dist/jobs.js +0 -173
- package/dist/jobs.js.map +0 -1
- package/dist/lakebase.js +0 -110
- package/dist/lakebase.js.map +0 -1
- package/dist/lakeflow-authoring.js +0 -115
- package/dist/lakeflow-authoring.js.map +0 -1
- package/dist/lakeflow.js +0 -75
- package/dist/lakeflow.js.map +0 -1
- package/dist/managed-resource.js +0 -197
- package/dist/managed-resource.js.map +0 -1
- package/dist/mlflow-tracing.js +0 -167
- package/dist/mlflow-tracing.js.map +0 -1
- package/dist/mock-provider.js +0 -66
- package/dist/mock-provider.js.map +0 -1
- package/dist/model.js +0 -173
- package/dist/model.js.map +0 -1
- package/dist/persistence.js +0 -82
- package/dist/persistence.js.map +0 -1
- package/dist/rag-chain.js +0 -212
- package/dist/rag-chain.js.map +0 -1
- package/dist/rag-eval.js +0 -151
- package/dist/rag-eval.js.map +0 -1
- package/dist/secrets-authoring.js +0 -78
- package/dist/secrets-authoring.js.map +0 -1
- package/dist/secrets.js +0 -25
- package/dist/secrets.js.map +0 -1
- package/dist/serving-admin.js +0 -255
- package/dist/serving-admin.js.map +0 -1
- package/dist/serving-usage.js +0 -100
- package/dist/serving-usage.js.map +0 -1
- package/dist/sql-exec.js +0 -36
- package/dist/sql-exec.js.map +0 -1
- package/dist/telemetry-sink.js +0 -180
- package/dist/telemetry-sink.js.map +0 -1
- package/dist/tools.js +0 -167
- package/dist/tools.js.map +0 -1
- package/dist/unity-catalog-admin.js +0 -166
- package/dist/unity-catalog-admin.js.map +0 -1
- package/dist/vector-search.js +0 -65
- package/dist/vector-search.js.map +0 -1
- package/dist/volumes-attachment-store.js +0 -172
- package/dist/volumes-attachment-store.js.map +0 -1
- package/dist/workspace-authoring.js +0 -78
- package/dist/workspace-authoring.js.map +0 -1
package/dist/genie-authoring.js
DELETED
|
@@ -1,898 +0,0 @@
|
|
|
1
|
-
import { DatabricksManagedResourceConflictError, DatabricksUnmanagedResourceError, databricksResourceFingerprint, requireDatabricksManagedResource, } from "./managed-resource.js";
|
|
2
|
-
const GENIE_RESOURCE_TYPE = "genie-agent";
|
|
3
|
-
const SERIALIZED_VERSION = 2;
|
|
4
|
-
const ID_PATTERN = /^[0-9a-f]{32}$/;
|
|
5
|
-
const MAX_STRING_LENGTH = 25_000;
|
|
6
|
-
export class DatabricksGenieAdmin {
|
|
7
|
-
client;
|
|
8
|
-
options;
|
|
9
|
-
constructor(client, options = {}) {
|
|
10
|
-
this.client = client;
|
|
11
|
-
this.options = options;
|
|
12
|
-
}
|
|
13
|
-
async list(options = {}) {
|
|
14
|
-
const response = await this.client.get("/api/2.0/genie/spaces", { page_size: options.pageSize, page_token: options.pageToken }, signalOption(options.signal));
|
|
15
|
-
const rawAgents = Array.isArray(response.spaces) ? response.spaces : [];
|
|
16
|
-
const agents = await Promise.all(rawAgents.map((raw) => parseAgent(requireRecord(raw, "space"))));
|
|
17
|
-
return {
|
|
18
|
-
agents,
|
|
19
|
-
...optional("nextPageToken", asString(response.next_page_token)),
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
async get(agentId, options = {}) {
|
|
23
|
-
const raw = await this.client.get(`/api/2.0/genie/spaces/${enc(nonEmpty(agentId, "agentId"))}`, { include_serialized_space: options.includeConfiguration }, signalOption(options.signal));
|
|
24
|
-
return parseAgent(raw);
|
|
25
|
-
}
|
|
26
|
-
async create(spec, options = {}) {
|
|
27
|
-
const normalized = await normalizeDatabricksGenieAgentSpec(spec);
|
|
28
|
-
const serializedSpace = JSON.stringify(serializedSpec(normalized));
|
|
29
|
-
const raw = await this.client.post("/api/2.0/genie/spaces", {
|
|
30
|
-
title: normalized.title,
|
|
31
|
-
...optional("description", normalized.description),
|
|
32
|
-
parent_path: normalized.parentPath,
|
|
33
|
-
warehouse_id: normalized.warehouseId,
|
|
34
|
-
serialized_space: serializedSpace,
|
|
35
|
-
}, {}, { retry: "never", ...signalOption(options.signal) });
|
|
36
|
-
const created = await parseAgent({
|
|
37
|
-
...raw,
|
|
38
|
-
title: raw.title ?? normalized.title,
|
|
39
|
-
description: raw.description ?? normalized.description,
|
|
40
|
-
parent_path: raw.parent_path ?? normalized.parentPath,
|
|
41
|
-
warehouse_id: raw.warehouse_id ?? normalized.warehouseId,
|
|
42
|
-
serialized_space: raw.serialized_space ?? serializedSpace,
|
|
43
|
-
});
|
|
44
|
-
await this.recordOwnership(created, options.ownership);
|
|
45
|
-
return created;
|
|
46
|
-
}
|
|
47
|
-
async update(agentId, update, options = {}) {
|
|
48
|
-
nonEmpty(update.expectedFingerprint, "expectedFingerprint");
|
|
49
|
-
if (Object.keys(update.set).length === 0 && !update.remove?.length)
|
|
50
|
-
throw new Error("Databricks Genie update requires at least one set or remove operation.");
|
|
51
|
-
const current = await this.get(agentId, {
|
|
52
|
-
includeConfiguration: true,
|
|
53
|
-
...signalOption(options.signal),
|
|
54
|
-
});
|
|
55
|
-
if (current.fingerprint !== update.expectedFingerprint) {
|
|
56
|
-
throw new DatabricksManagedResourceConflictError({
|
|
57
|
-
resourceType: GENIE_RESOURCE_TYPE,
|
|
58
|
-
resourceId: current.agentId,
|
|
59
|
-
expectedFingerprint: update.expectedFingerprint,
|
|
60
|
-
actualFingerprint: current.fingerprint,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
let normalized;
|
|
64
|
-
if (update.set.spec)
|
|
65
|
-
normalized = await normalizeDatabricksGenieAgentSpec(update.set.spec);
|
|
66
|
-
const body = {
|
|
67
|
-
...optional("etag", current.etag),
|
|
68
|
-
...optional("title", normalized?.title ?? update.set.title),
|
|
69
|
-
...optional("description", normalized?.description ?? update.set.description),
|
|
70
|
-
...optional("parent_path", normalized?.parentPath ?? update.set.parentPath),
|
|
71
|
-
...optional("warehouse_id", normalized?.warehouseId ?? update.set.warehouseId),
|
|
72
|
-
...(normalized ? { serialized_space: JSON.stringify(serializedSpec(normalized)) } : {}),
|
|
73
|
-
...(update.remove?.includes("description") ? { description: "" } : {}),
|
|
74
|
-
};
|
|
75
|
-
await this.client.patch(`/api/2.0/genie/spaces/${enc(current.agentId)}`, body, {}, { retry: "never", ...signalOption(options.signal) });
|
|
76
|
-
const updated = await this.get(current.agentId, {
|
|
77
|
-
includeConfiguration: true,
|
|
78
|
-
...signalOption(options.signal),
|
|
79
|
-
});
|
|
80
|
-
await this.recordOwnership(updated, options.ownership, current);
|
|
81
|
-
return updated;
|
|
82
|
-
}
|
|
83
|
-
async delete(agentId, options = {}) {
|
|
84
|
-
const normalizedId = nonEmpty(agentId, "agentId");
|
|
85
|
-
try {
|
|
86
|
-
await this.client.delete(`/api/2.0/genie/spaces/${enc(normalizedId)}`, undefined, {}, { retry: "never", ...signalOption(options.signal) });
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
if (!isGenieAbsentError(error))
|
|
90
|
-
throw error;
|
|
91
|
-
}
|
|
92
|
-
await this.waitUntilTrashed(normalizedId, options.signal);
|
|
93
|
-
await this.options.managedResourceStore?.delete(GENIE_RESOURCE_TYPE, normalizedId);
|
|
94
|
-
}
|
|
95
|
-
async waitUntilTrashed(agentId, signal) {
|
|
96
|
-
const deadline = Date.now() + 30_000;
|
|
97
|
-
for (;;) {
|
|
98
|
-
try {
|
|
99
|
-
await this.get(agentId, { ...signalOption(signal) });
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
if (isGenieAbsentError(error))
|
|
103
|
-
return;
|
|
104
|
-
throw error;
|
|
105
|
-
}
|
|
106
|
-
if (Date.now() >= deadline)
|
|
107
|
-
throw new Error(`Databricks Genie Agent ${agentId} remained active after trash request.`);
|
|
108
|
-
await abortableDelay(250, signal);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
async permissions(agentId, options = {}) {
|
|
112
|
-
const raw = await this.client.get(`/api/2.0/permissions/genie/${enc(nonEmpty(agentId, "agentId"))}`, {}, signalOption(options.signal));
|
|
113
|
-
return parsePermissions(raw);
|
|
114
|
-
}
|
|
115
|
-
async updatePermissions(agentId, changes, options = {}) {
|
|
116
|
-
if (changes.length === 0)
|
|
117
|
-
throw new Error("Databricks Genie permission changes cannot be empty.");
|
|
118
|
-
const accessControlList = changes.map(permissionChangeToWire);
|
|
119
|
-
const raw = await this.client.patch(`/api/2.0/permissions/genie/${enc(nonEmpty(agentId, "agentId"))}`, { access_control_list: accessControlList }, {}, { retry: "never", ...signalOption(options.signal) });
|
|
120
|
-
return parsePermissions(raw);
|
|
121
|
-
}
|
|
122
|
-
async export(agentId, options = {}) {
|
|
123
|
-
const agent = await this.get(agentId, {
|
|
124
|
-
includeConfiguration: true,
|
|
125
|
-
...signalOption(options.signal),
|
|
126
|
-
});
|
|
127
|
-
if (!agent.serializedSpace)
|
|
128
|
-
throw new Error(`Databricks Genie Agent ${agent.agentId} did not return serialized_space.`);
|
|
129
|
-
return { exportedAt: new Date().toISOString(), agent, serializedSpace: agent.serializedSpace };
|
|
130
|
-
}
|
|
131
|
-
/** Raw export import is intentionally typed-client-only; no model ToolDef accepts serialized space. */
|
|
132
|
-
async import(exported, options = {}) {
|
|
133
|
-
validateSerializedSpace(exported.serializedSpace);
|
|
134
|
-
const raw = await this.client.post("/api/2.0/genie/spaces", {
|
|
135
|
-
title: options.title ?? exported.agent.title,
|
|
136
|
-
...optional("description", options.description ?? exported.agent.description),
|
|
137
|
-
...optional("parent_path", options.parentPath ?? exported.agent.parentPath),
|
|
138
|
-
...optional("warehouse_id", options.warehouseId ?? exported.agent.warehouseId),
|
|
139
|
-
serialized_space: exported.serializedSpace,
|
|
140
|
-
}, {}, { retry: "never", ...signalOption(options.signal) });
|
|
141
|
-
const created = await parseAgent({
|
|
142
|
-
...raw,
|
|
143
|
-
title: raw.title ?? options.title ?? exported.agent.title,
|
|
144
|
-
description: raw.description ?? options.description ?? exported.agent.description,
|
|
145
|
-
parent_path: raw.parent_path ?? options.parentPath ?? exported.agent.parentPath,
|
|
146
|
-
warehouse_id: raw.warehouse_id ?? options.warehouseId ?? exported.agent.warehouseId,
|
|
147
|
-
serialized_space: raw.serialized_space ?? exported.serializedSpace,
|
|
148
|
-
});
|
|
149
|
-
await this.recordOwnership(created, options.ownership);
|
|
150
|
-
return created;
|
|
151
|
-
}
|
|
152
|
-
async recordOwnership(agent, ownership, previous) {
|
|
153
|
-
if (!this.options.managedResourceStore || !ownership)
|
|
154
|
-
return;
|
|
155
|
-
const now = new Date().toISOString();
|
|
156
|
-
const existing = await this.options.managedResourceStore.get(GENIE_RESOURCE_TYPE, agent.agentId);
|
|
157
|
-
await this.options.managedResourceStore.put({
|
|
158
|
-
resourceType: GENIE_RESOURCE_TYPE,
|
|
159
|
-
resourceId: agent.agentId,
|
|
160
|
-
fingerprint: agent.fingerprint,
|
|
161
|
-
createdBy: existing?.createdBy ?? ownership.principal,
|
|
162
|
-
toolCallId: ownership.toolCallId,
|
|
163
|
-
createdAt: existing?.createdAt ?? now,
|
|
164
|
-
updatedAt: now,
|
|
165
|
-
metadata: {
|
|
166
|
-
title: agent.title,
|
|
167
|
-
...optional("previousFingerprint", previous?.fingerprint),
|
|
168
|
-
},
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
export function databricksGenieAdmin(client, options = {}) {
|
|
173
|
-
return new DatabricksGenieAdmin(client, options);
|
|
174
|
-
}
|
|
175
|
-
export function databricksGenieAuthoringTools(client, options) {
|
|
176
|
-
const admin = databricksGenieAdmin(client, {
|
|
177
|
-
managedResourceStore: options.managedResourceStore,
|
|
178
|
-
});
|
|
179
|
-
const tools = [
|
|
180
|
-
genieTool("databricks_create_genie_agent", "Create a governed Genie Agent from a normalized configuration without arbitrary SQL.", {
|
|
181
|
-
type: "object",
|
|
182
|
-
additionalProperties: false,
|
|
183
|
-
properties: { spec: genieSpecSchema(Boolean(options.sqlPolicy)) },
|
|
184
|
-
required: ["spec"],
|
|
185
|
-
}, [
|
|
186
|
-
{ kind: "workspace-path", path: "/spec/parentPath" },
|
|
187
|
-
{ kind: "warehouse", path: "/spec/warehouseId" },
|
|
188
|
-
{ kind: "table", path: "/spec/dataSources/*/table", catalogQualified: true },
|
|
189
|
-
], "write", async (input, context) => {
|
|
190
|
-
const spec = input.spec;
|
|
191
|
-
if (options.sqlPolicy)
|
|
192
|
-
await validateDatabricksGenieSqlReferences(spec, options.sqlPolicy);
|
|
193
|
-
const created = await admin.create(spec, {
|
|
194
|
-
ownership: ownership(options.principal, context),
|
|
195
|
-
...contextSignal(context),
|
|
196
|
-
});
|
|
197
|
-
return publicAgent(created);
|
|
198
|
-
}),
|
|
199
|
-
genieTool("databricks_get_genie_agent", "Inspect one Genie Agent and return its conflict-safe fingerprint.", idSchema(false), [{ kind: "genie-agent", path: "/agentId" }], "read", async (input, context) => publicAgent(await admin.get(String(input.agentId), {
|
|
200
|
-
includeConfiguration: true,
|
|
201
|
-
...contextSignal(context),
|
|
202
|
-
}))),
|
|
203
|
-
genieTool("databricks_update_genie_agent", "Update a Harness-managed Genie Agent using its expected fingerprint.", updateToolSchema(Boolean(options.sqlPolicy)), [
|
|
204
|
-
{ kind: "genie-agent", path: "/agentId" },
|
|
205
|
-
{ kind: "workspace-path", path: "/set/spec/parentPath", optional: true },
|
|
206
|
-
{ kind: "warehouse", path: "/set/spec/warehouseId", optional: true },
|
|
207
|
-
{
|
|
208
|
-
kind: "table",
|
|
209
|
-
path: "/set/spec/dataSources/*/table",
|
|
210
|
-
catalogQualified: true,
|
|
211
|
-
optional: true,
|
|
212
|
-
},
|
|
213
|
-
], "write", async (input, context) => {
|
|
214
|
-
const agentId = String(input.agentId);
|
|
215
|
-
const expectedFingerprint = String(input.expectedFingerprint);
|
|
216
|
-
const nextSpec = input.set.spec;
|
|
217
|
-
if (nextSpec && options.sqlPolicy)
|
|
218
|
-
await validateDatabricksGenieSqlReferences(nextSpec, options.sqlPolicy);
|
|
219
|
-
await requireDatabricksManagedResource({
|
|
220
|
-
store: options.managedResourceStore,
|
|
221
|
-
resourceType: GENIE_RESOURCE_TYPE,
|
|
222
|
-
resourceId: agentId,
|
|
223
|
-
expectedFingerprint,
|
|
224
|
-
});
|
|
225
|
-
const updated = await admin.update(agentId, {
|
|
226
|
-
expectedFingerprint,
|
|
227
|
-
set: input.set,
|
|
228
|
-
...(Array.isArray(input.remove)
|
|
229
|
-
? { remove: input.remove }
|
|
230
|
-
: {}),
|
|
231
|
-
}, {
|
|
232
|
-
ownership: ownership(options.principal, context),
|
|
233
|
-
...contextSignal(context),
|
|
234
|
-
});
|
|
235
|
-
return publicAgent(updated);
|
|
236
|
-
}),
|
|
237
|
-
];
|
|
238
|
-
if (options.destructive) {
|
|
239
|
-
tools.push(genieTool("databricks_delete_genie_agent", "Delete one Harness-managed Genie Agent by exact id and expected fingerprint.", idSchema(true), [{ kind: "genie-agent", path: "/agentId" }], "write", async (input, context) => {
|
|
240
|
-
const agentId = String(input.agentId);
|
|
241
|
-
const expectedFingerprint = String(input.expectedFingerprint);
|
|
242
|
-
try {
|
|
243
|
-
await requireDatabricksManagedResource({
|
|
244
|
-
store: options.managedResourceStore,
|
|
245
|
-
resourceType: GENIE_RESOURCE_TYPE,
|
|
246
|
-
resourceId: agentId,
|
|
247
|
-
expectedFingerprint,
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
catch (error) {
|
|
251
|
-
if (error instanceof DatabricksUnmanagedResourceError) {
|
|
252
|
-
try {
|
|
253
|
-
await admin.get(agentId, contextSignal(context));
|
|
254
|
-
}
|
|
255
|
-
catch (lookupError) {
|
|
256
|
-
if (isGenieAbsentError(lookupError))
|
|
257
|
-
return { deleted: true, agentId, alreadyAbsent: true };
|
|
258
|
-
throw error;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
throw error;
|
|
262
|
-
}
|
|
263
|
-
const current = await admin.get(agentId, {
|
|
264
|
-
includeConfiguration: true,
|
|
265
|
-
...contextSignal(context),
|
|
266
|
-
});
|
|
267
|
-
if (current.fingerprint !== expectedFingerprint) {
|
|
268
|
-
throw new DatabricksManagedResourceConflictError({
|
|
269
|
-
resourceType: GENIE_RESOURCE_TYPE,
|
|
270
|
-
resourceId: agentId,
|
|
271
|
-
expectedFingerprint,
|
|
272
|
-
actualFingerprint: current.fingerprint,
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
await admin.delete(agentId, contextSignal(context));
|
|
276
|
-
return { deleted: true, agentId };
|
|
277
|
-
}));
|
|
278
|
-
}
|
|
279
|
-
return tools;
|
|
280
|
-
}
|
|
281
|
-
export async function normalizeDatabricksGenieAgentSpec(spec) {
|
|
282
|
-
if (spec.version !== SERIALIZED_VERSION)
|
|
283
|
-
throw new Error(`Databricks Genie serialized_space version must be ${SERIALIZED_VERSION}.`);
|
|
284
|
-
const title = boundedString(spec.title, "title");
|
|
285
|
-
const parentPath = boundedString(spec.parentPath, "parentPath");
|
|
286
|
-
if (!parentPath.startsWith("/"))
|
|
287
|
-
throw new Error("Databricks Genie parentPath must start with '/'.");
|
|
288
|
-
const warehouseId = boundedString(spec.warehouseId, "warehouseId");
|
|
289
|
-
if (spec.dataSources.length === 0)
|
|
290
|
-
throw new Error("Databricks Genie requires at least one data source.");
|
|
291
|
-
if (spec.dataSources.length > 30)
|
|
292
|
-
throw new Error("Databricks Genie supports at most 30 data sources.");
|
|
293
|
-
if ((spec.instructions?.length ?? 0) > 1)
|
|
294
|
-
throw new Error("Databricks Genie supports at most one text instruction.");
|
|
295
|
-
const dataSources = spec.dataSources
|
|
296
|
-
.map(normalizeDataSource)
|
|
297
|
-
.sort((a, b) => a.table.localeCompare(b.table));
|
|
298
|
-
assertUnique(dataSources.map((source) => `${source.kind ?? "table"}:${source.table}`), "data source");
|
|
299
|
-
const sampleQuestions = await Promise.all((spec.sampleQuestions ?? []).map(async (sample) => ({
|
|
300
|
-
id: sample.id
|
|
301
|
-
? validateId(sample.id, "sample question")
|
|
302
|
-
: await stableId("sample-question", sample.question),
|
|
303
|
-
question: boundedString(sample.question, "sample question"),
|
|
304
|
-
})));
|
|
305
|
-
sampleQuestions.sort((a, b) => a.id.localeCompare(b.id));
|
|
306
|
-
assertUnique(sampleQuestions.map((sample) => sample.id), "sample question id");
|
|
307
|
-
const examples = await Promise.all((spec.examples ?? []).map(async (item) => ({
|
|
308
|
-
id: item.id
|
|
309
|
-
? validateId(item.id, "SQL example")
|
|
310
|
-
: await stableId("sql-example", `${item.question}\n${item.sql}`),
|
|
311
|
-
question: boundedString(item.question, "SQL example question"),
|
|
312
|
-
sql: boundedString(item.sql, "SQL example"),
|
|
313
|
-
})));
|
|
314
|
-
const sqlFunctions = await Promise.all((spec.sqlFunctions ?? []).map(async (item) => ({
|
|
315
|
-
id: item.id
|
|
316
|
-
? validateId(item.id, "SQL function")
|
|
317
|
-
: await stableId("sql-function", item.identifier),
|
|
318
|
-
identifier: qualifiedIdentifier(item.identifier, "SQL function"),
|
|
319
|
-
})));
|
|
320
|
-
const joins = await Promise.all((spec.joins ?? []).map(async (item) => {
|
|
321
|
-
const left = normalizeJoinSide(item.left, "left join side");
|
|
322
|
-
const right = normalizeJoinSide(item.right, "right join side");
|
|
323
|
-
const sql = boundedString(item.sql, "join SQL");
|
|
324
|
-
return {
|
|
325
|
-
id: item.id
|
|
326
|
-
? validateId(item.id, "join")
|
|
327
|
-
: await stableId("join", `${left.identifier}\n${right.identifier}\n${sql}`),
|
|
328
|
-
left,
|
|
329
|
-
right,
|
|
330
|
-
sql,
|
|
331
|
-
};
|
|
332
|
-
}));
|
|
333
|
-
const sqlSnippets = await normalizeSqlSnippets(spec.sqlSnippets);
|
|
334
|
-
const benchmarks = await Promise.all((spec.benchmarks ?? []).map(async (item) => ({
|
|
335
|
-
id: item.id
|
|
336
|
-
? validateId(item.id, "benchmark")
|
|
337
|
-
: await stableId("benchmark", `${item.question}\n${item.sql}`),
|
|
338
|
-
question: boundedString(item.question, "benchmark question"),
|
|
339
|
-
sql: boundedString(item.sql, "benchmark SQL"),
|
|
340
|
-
})));
|
|
341
|
-
for (const [name, values] of [
|
|
342
|
-
["SQL example id", examples],
|
|
343
|
-
["SQL function id", sqlFunctions],
|
|
344
|
-
["join id", joins],
|
|
345
|
-
["benchmark id", benchmarks],
|
|
346
|
-
])
|
|
347
|
-
assertUnique(values.map((item) => item.id), name);
|
|
348
|
-
return {
|
|
349
|
-
version: 2,
|
|
350
|
-
title,
|
|
351
|
-
...optional("description", optionalBoundedString(spec.description, "description")),
|
|
352
|
-
parentPath,
|
|
353
|
-
warehouseId,
|
|
354
|
-
...(sampleQuestions.length ? { sampleQuestions } : {}),
|
|
355
|
-
dataSources,
|
|
356
|
-
...(spec.instructions?.length
|
|
357
|
-
? {
|
|
358
|
-
instructions: spec.instructions.map((instruction) => boundedString(instruction, "instruction")),
|
|
359
|
-
}
|
|
360
|
-
: {}),
|
|
361
|
-
...(examples.length ? { examples } : {}),
|
|
362
|
-
...(sqlFunctions.length ? { sqlFunctions } : {}),
|
|
363
|
-
...(joins.length ? { joins } : {}),
|
|
364
|
-
...(sqlSnippets ? { sqlSnippets } : {}),
|
|
365
|
-
...(benchmarks.length ? { benchmarks } : {}),
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
export async function validateDatabricksGenieSqlReferences(spec, policy) {
|
|
369
|
-
const declaredDataSources = spec.dataSources.map((source) => qualifiedIdentifier(source.table, "data source"));
|
|
370
|
-
const allowed = new Set(declaredDataSources);
|
|
371
|
-
const statements = [
|
|
372
|
-
...(spec.examples ?? []).map((item) => ({ sql: item.sql, purpose: "example" })),
|
|
373
|
-
...(spec.joins ?? []).map((item) => ({ sql: item.sql, purpose: "join" })),
|
|
374
|
-
...(spec.sqlSnippets?.filters ?? []).map((item) => ({
|
|
375
|
-
sql: item.sql,
|
|
376
|
-
purpose: "filter",
|
|
377
|
-
})),
|
|
378
|
-
...(spec.sqlSnippets?.expressions ?? []).map((item) => ({
|
|
379
|
-
sql: item.sql,
|
|
380
|
-
purpose: "expression",
|
|
381
|
-
})),
|
|
382
|
-
...(spec.sqlSnippets?.measures ?? []).map((item) => ({
|
|
383
|
-
sql: item.sql,
|
|
384
|
-
purpose: "measure",
|
|
385
|
-
})),
|
|
386
|
-
...(spec.benchmarks ?? []).map((item) => ({ sql: item.sql, purpose: "benchmark" })),
|
|
387
|
-
];
|
|
388
|
-
for (const statement of statements) {
|
|
389
|
-
const result = await policy({
|
|
390
|
-
sql: boundedString(statement.sql, `${statement.purpose} SQL`),
|
|
391
|
-
purpose: statement.purpose,
|
|
392
|
-
declaredDataSources: [...declaredDataSources],
|
|
393
|
-
});
|
|
394
|
-
if (!result || !Array.isArray(result.resources))
|
|
395
|
-
throw new Error("Databricks Genie SQL policy must return a complete resources array.");
|
|
396
|
-
for (const resource of result.resources) {
|
|
397
|
-
const qualified = qualifiedIdentifier(resource, "SQL policy resource");
|
|
398
|
-
if (!allowed.has(qualified))
|
|
399
|
-
throw new Error(`Databricks Genie SQL policy denied undeclared resource '${qualified}'.`);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
export async function serializeDatabricksGenieAgentSpec(spec) {
|
|
404
|
-
return JSON.stringify(serializedSpec(await normalizeDatabricksGenieAgentSpec(spec)));
|
|
405
|
-
}
|
|
406
|
-
function serializedSpec(spec) {
|
|
407
|
-
const tables = spec.dataSources.filter((source) => (source.kind ?? "table") === "table");
|
|
408
|
-
const metricViews = spec.dataSources.filter((source) => source.kind === "metric-view");
|
|
409
|
-
return {
|
|
410
|
-
version: 2,
|
|
411
|
-
config: {
|
|
412
|
-
sample_questions: (spec.sampleQuestions ?? []).map((sample) => ({
|
|
413
|
-
id: sample.id,
|
|
414
|
-
question: [sample.question],
|
|
415
|
-
})),
|
|
416
|
-
},
|
|
417
|
-
data_sources: {
|
|
418
|
-
tables: tables.map(dataSourceToWire),
|
|
419
|
-
...(metricViews.length ? { metric_views: metricViews.map(dataSourceToWire) } : {}),
|
|
420
|
-
},
|
|
421
|
-
...((spec.instructions?.length ?? 0) ||
|
|
422
|
-
(spec.examples?.length ?? 0) ||
|
|
423
|
-
(spec.sqlFunctions?.length ?? 0) ||
|
|
424
|
-
(spec.joins?.length ?? 0) ||
|
|
425
|
-
spec.sqlSnippets
|
|
426
|
-
? {
|
|
427
|
-
instructions: {
|
|
428
|
-
...(spec.instructions?.length
|
|
429
|
-
? {
|
|
430
|
-
text_instructions: spec.instructions.map((content, index) => ({
|
|
431
|
-
id: instructionId(spec, content, index),
|
|
432
|
-
content: [content],
|
|
433
|
-
})),
|
|
434
|
-
}
|
|
435
|
-
: {}),
|
|
436
|
-
...(spec.examples?.length
|
|
437
|
-
? {
|
|
438
|
-
example_question_sqls: spec.examples.map((item) => ({
|
|
439
|
-
id: item.id,
|
|
440
|
-
question: [item.question],
|
|
441
|
-
sql: [item.sql],
|
|
442
|
-
})),
|
|
443
|
-
}
|
|
444
|
-
: {}),
|
|
445
|
-
...(spec.sqlFunctions?.length
|
|
446
|
-
? {
|
|
447
|
-
sql_functions: spec.sqlFunctions.map((item) => ({
|
|
448
|
-
id: item.id,
|
|
449
|
-
identifier: item.identifier,
|
|
450
|
-
})),
|
|
451
|
-
}
|
|
452
|
-
: {}),
|
|
453
|
-
...(spec.joins?.length
|
|
454
|
-
? {
|
|
455
|
-
join_specs: spec.joins.map((item) => ({
|
|
456
|
-
id: item.id,
|
|
457
|
-
left: item.left,
|
|
458
|
-
right: item.right,
|
|
459
|
-
sql: [item.sql],
|
|
460
|
-
})),
|
|
461
|
-
}
|
|
462
|
-
: {}),
|
|
463
|
-
...(spec.sqlSnippets ? { sql_snippets: serializeSqlSnippets(spec.sqlSnippets) } : {}),
|
|
464
|
-
},
|
|
465
|
-
}
|
|
466
|
-
: {}),
|
|
467
|
-
...(spec.benchmarks?.length
|
|
468
|
-
? {
|
|
469
|
-
benchmarks: {
|
|
470
|
-
questions: spec.benchmarks.map((item) => ({
|
|
471
|
-
id: item.id,
|
|
472
|
-
question: [item.question],
|
|
473
|
-
answer: [{ format: "SQL", content: [item.sql] }],
|
|
474
|
-
})),
|
|
475
|
-
},
|
|
476
|
-
}
|
|
477
|
-
: {}),
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
function normalizeJoinSide(side, name) {
|
|
481
|
-
return {
|
|
482
|
-
identifier: qualifiedIdentifier(side.identifier, name),
|
|
483
|
-
...optional("alias", optionalBoundedString(side.alias, `${name} alias`)),
|
|
484
|
-
};
|
|
485
|
-
}
|
|
486
|
-
async function normalizeSqlSnippets(snippets) {
|
|
487
|
-
if (!snippets)
|
|
488
|
-
return undefined;
|
|
489
|
-
const normalize = async (values, kind) => {
|
|
490
|
-
const normalized = await Promise.all((values ?? []).map(async (item) => ({
|
|
491
|
-
id: item.id
|
|
492
|
-
? validateId(item.id, `${kind} snippet`)
|
|
493
|
-
: await stableId(`${kind}-snippet`, `${item.alias ?? item.displayName ?? ""}\n${item.sql}`),
|
|
494
|
-
sql: boundedString(item.sql, `${kind} SQL`),
|
|
495
|
-
...optional("displayName", optionalBoundedString(item.displayName, `${kind} display name`)),
|
|
496
|
-
...optional("alias", optionalBoundedString(item.alias, `${kind} alias`)),
|
|
497
|
-
...(item.synonyms
|
|
498
|
-
? { synonyms: item.synonyms.map((value) => boundedString(value, `${kind} synonym`)) }
|
|
499
|
-
: {}),
|
|
500
|
-
})));
|
|
501
|
-
if ((kind === "expression" || kind === "measure") && normalized.some((item) => !item.alias))
|
|
502
|
-
throw new Error(`Databricks Genie ${kind} snippets require alias.`);
|
|
503
|
-
assertUnique(normalized.map((item) => item.id ?? ""), `${kind} snippet id`);
|
|
504
|
-
return normalized;
|
|
505
|
-
};
|
|
506
|
-
const filters = await normalize(snippets.filters, "filter");
|
|
507
|
-
const expressions = await normalize(snippets.expressions, "expression");
|
|
508
|
-
const measures = await normalize(snippets.measures, "measure");
|
|
509
|
-
if (!(filters.length || expressions.length || measures.length))
|
|
510
|
-
return undefined;
|
|
511
|
-
return {
|
|
512
|
-
...(filters.length ? { filters } : {}),
|
|
513
|
-
...(expressions.length ? { expressions } : {}),
|
|
514
|
-
...(measures.length ? { measures } : {}),
|
|
515
|
-
};
|
|
516
|
-
}
|
|
517
|
-
function serializeSqlSnippets(snippets) {
|
|
518
|
-
const serialize = (items) => (items ?? []).map((item) => ({
|
|
519
|
-
id: item.id,
|
|
520
|
-
sql: [item.sql],
|
|
521
|
-
...optional("display_name", item.displayName),
|
|
522
|
-
...optional("alias", item.alias),
|
|
523
|
-
...optional("synonyms", item.synonyms),
|
|
524
|
-
}));
|
|
525
|
-
return {
|
|
526
|
-
...(snippets.filters?.length ? { filters: serialize(snippets.filters) } : {}),
|
|
527
|
-
...(snippets.expressions?.length ? { expressions: serialize(snippets.expressions) } : {}),
|
|
528
|
-
...(snippets.measures?.length ? { measures: serialize(snippets.measures) } : {}),
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
function qualifiedIdentifier(value, name) {
|
|
532
|
-
const normalized = boundedString(value, name);
|
|
533
|
-
if (normalized.split(".").length !== 3 || normalized.split(".").some((part) => !part.trim()))
|
|
534
|
-
throw new Error(`Databricks Genie ${name} '${normalized}' must be catalog.schema.object.`);
|
|
535
|
-
return normalized;
|
|
536
|
-
}
|
|
537
|
-
function isGenieAbsentError(error) {
|
|
538
|
-
return /\b404\b|not[ _-]?found|does not exist|RESOURCE_DOES_NOT_EXIST|has been trashed/i.test(error instanceof Error ? error.message : String(error));
|
|
539
|
-
}
|
|
540
|
-
function abortableDelay(milliseconds, signal) {
|
|
541
|
-
if (signal?.aborted)
|
|
542
|
-
return Promise.reject(signal.reason);
|
|
543
|
-
return new Promise((resolve, reject) => {
|
|
544
|
-
const onAbort = () => {
|
|
545
|
-
clearTimeout(timer);
|
|
546
|
-
reject(signal?.reason);
|
|
547
|
-
};
|
|
548
|
-
const timer = setTimeout(() => {
|
|
549
|
-
signal?.removeEventListener("abort", onAbort);
|
|
550
|
-
resolve();
|
|
551
|
-
}, milliseconds);
|
|
552
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
553
|
-
});
|
|
554
|
-
}
|
|
555
|
-
function dataSourceToWire(source) {
|
|
556
|
-
return {
|
|
557
|
-
identifier: source.table,
|
|
558
|
-
...(source.description ? { description: [source.description] } : {}),
|
|
559
|
-
...(source.columns?.length
|
|
560
|
-
? {
|
|
561
|
-
column_configs: source.columns.map((column) => ({
|
|
562
|
-
column_name: column.name,
|
|
563
|
-
...(column.description ? { description: [column.description] } : {}),
|
|
564
|
-
...optional("synonyms", column.synonyms),
|
|
565
|
-
...optional("exclude", column.exclude),
|
|
566
|
-
...optional("get_example_values", column.getExampleValues),
|
|
567
|
-
...optional("enable_format_assistance", column.enableFormatAssistance),
|
|
568
|
-
...optional("enable_entity_matching", column.enableEntityMatching),
|
|
569
|
-
})),
|
|
570
|
-
}
|
|
571
|
-
: {}),
|
|
572
|
-
};
|
|
573
|
-
}
|
|
574
|
-
function normalizeDataSource(source) {
|
|
575
|
-
const table = qualifiedIdentifier(source.table, "data source");
|
|
576
|
-
const columns = (source.columns ?? [])
|
|
577
|
-
.map((column) => ({
|
|
578
|
-
name: boundedString(column.name, "column name"),
|
|
579
|
-
...optional("description", optionalBoundedString(column.description, "column description")),
|
|
580
|
-
...(column.synonyms
|
|
581
|
-
? { synonyms: column.synonyms.map((synonym) => boundedString(synonym, "column synonym")) }
|
|
582
|
-
: {}),
|
|
583
|
-
...optional("exclude", column.exclude),
|
|
584
|
-
...optional("getExampleValues", column.getExampleValues),
|
|
585
|
-
...optional("enableFormatAssistance", column.enableFormatAssistance),
|
|
586
|
-
...optional("enableEntityMatching", column.enableEntityMatching),
|
|
587
|
-
}))
|
|
588
|
-
.sort((a, b) => a.name.localeCompare(b.name));
|
|
589
|
-
assertUnique(columns.map((column) => column.name), `column in ${table}`);
|
|
590
|
-
return {
|
|
591
|
-
kind: source.kind ?? "table",
|
|
592
|
-
table,
|
|
593
|
-
...optional("description", optionalBoundedString(source.description, "data source description")),
|
|
594
|
-
...(columns.length ? { columns } : {}),
|
|
595
|
-
};
|
|
596
|
-
}
|
|
597
|
-
async function parseAgent(raw) {
|
|
598
|
-
const agentId = nonEmpty(asString(raw.space_id ?? raw.id) ?? "", "response space_id");
|
|
599
|
-
const title = nonEmpty(asString(raw.title) ?? "", "response title");
|
|
600
|
-
const envelope = {
|
|
601
|
-
agentId,
|
|
602
|
-
title,
|
|
603
|
-
description: asString(raw.description),
|
|
604
|
-
parentPath: asString(raw.parent_path),
|
|
605
|
-
warehouseId: asString(raw.warehouse_id),
|
|
606
|
-
etag: asString(raw.etag),
|
|
607
|
-
serializedSpace: asString(raw.serialized_space),
|
|
608
|
-
};
|
|
609
|
-
return {
|
|
610
|
-
agentId,
|
|
611
|
-
title,
|
|
612
|
-
...optional("description", envelope.description),
|
|
613
|
-
...optional("parentPath", envelope.parentPath),
|
|
614
|
-
...optional("warehouseId", envelope.warehouseId),
|
|
615
|
-
...optional("etag", envelope.etag),
|
|
616
|
-
...optional("serializedSpace", envelope.serializedSpace),
|
|
617
|
-
fingerprint: await databricksResourceFingerprint(envelope),
|
|
618
|
-
};
|
|
619
|
-
}
|
|
620
|
-
function parsePermissions(raw) {
|
|
621
|
-
return {
|
|
622
|
-
...optional("objectId", asString(raw.object_id)),
|
|
623
|
-
...optional("objectType", asString(raw.object_type)),
|
|
624
|
-
accessControlList: Array.isArray(raw.access_control_list)
|
|
625
|
-
? raw.access_control_list.filter((entry) => typeof entry === "object" && entry !== null && !Array.isArray(entry))
|
|
626
|
-
: [],
|
|
627
|
-
};
|
|
628
|
-
}
|
|
629
|
-
function permissionChangeToWire(change) {
|
|
630
|
-
const principals = [change.userName, change.groupName, change.servicePrincipalName].filter(Boolean);
|
|
631
|
-
if (principals.length !== 1)
|
|
632
|
-
throw new Error("Databricks Genie permission change requires exactly one principal.");
|
|
633
|
-
return {
|
|
634
|
-
permission_level: change.permissionLevel,
|
|
635
|
-
...optional("user_name", change.userName),
|
|
636
|
-
...optional("group_name", change.groupName),
|
|
637
|
-
...optional("service_principal_name", change.servicePrincipalName),
|
|
638
|
-
};
|
|
639
|
-
}
|
|
640
|
-
function validateSerializedSpace(serializedSpace) {
|
|
641
|
-
let value;
|
|
642
|
-
try {
|
|
643
|
-
value = JSON.parse(serializedSpace);
|
|
644
|
-
}
|
|
645
|
-
catch {
|
|
646
|
-
throw new Error("Databricks Genie serializedSpace must be valid JSON.");
|
|
647
|
-
}
|
|
648
|
-
const record = requireRecord(value, "serializedSpace");
|
|
649
|
-
if (record.version !== SERIALIZED_VERSION)
|
|
650
|
-
throw new Error(`Databricks Genie serializedSpace version must be ${SERIALIZED_VERSION}.`);
|
|
651
|
-
}
|
|
652
|
-
function requireRecord(value, name) {
|
|
653
|
-
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
654
|
-
throw new Error(`Databricks Genie ${name} must be an object.`);
|
|
655
|
-
return value;
|
|
656
|
-
}
|
|
657
|
-
function nonEmpty(value, name) {
|
|
658
|
-
const normalized = value.trim();
|
|
659
|
-
if (!normalized)
|
|
660
|
-
throw new Error(`Databricks Genie ${name} cannot be empty.`);
|
|
661
|
-
return normalized;
|
|
662
|
-
}
|
|
663
|
-
function boundedString(value, name) {
|
|
664
|
-
const normalized = nonEmpty(value, name);
|
|
665
|
-
if (normalized.length > MAX_STRING_LENGTH)
|
|
666
|
-
throw new Error(`Databricks Genie ${name} exceeds ${MAX_STRING_LENGTH} characters.`);
|
|
667
|
-
return normalized;
|
|
668
|
-
}
|
|
669
|
-
function optionalBoundedString(value, name) {
|
|
670
|
-
return value === undefined ? undefined : boundedString(value, name);
|
|
671
|
-
}
|
|
672
|
-
function validateId(id, name) {
|
|
673
|
-
if (!ID_PATTERN.test(id))
|
|
674
|
-
throw new Error(`Databricks Genie ${name} id must be 32 lowercase hexadecimal characters.`);
|
|
675
|
-
return id;
|
|
676
|
-
}
|
|
677
|
-
async function stableId(namespace, value) {
|
|
678
|
-
return (await databricksResourceFingerprint({ namespace, value })).slice(0, 32);
|
|
679
|
-
}
|
|
680
|
-
function instructionId(spec, content, index) {
|
|
681
|
-
// The normalized spec permits one instruction; derive a deterministic 32-hex identifier without
|
|
682
|
-
// introducing another asynchronous serialization pass.
|
|
683
|
-
const seed = `${spec.title}\u0000${content}\u0000${index}`;
|
|
684
|
-
let output = "";
|
|
685
|
-
for (let block = 0; block < 4; block += 1) {
|
|
686
|
-
let hash = 2166136261 ^ block;
|
|
687
|
-
for (let offset = 0; offset < seed.length; offset += 1) {
|
|
688
|
-
hash ^= seed.charCodeAt(offset);
|
|
689
|
-
hash = Math.imul(hash, 16777619);
|
|
690
|
-
}
|
|
691
|
-
output += (hash >>> 0).toString(16).padStart(8, "0");
|
|
692
|
-
}
|
|
693
|
-
return output;
|
|
694
|
-
}
|
|
695
|
-
function assertUnique(values, name) {
|
|
696
|
-
if (new Set(values).size !== values.length)
|
|
697
|
-
throw new Error(`Databricks Genie ${name} values must be unique.`);
|
|
698
|
-
}
|
|
699
|
-
function asString(value) {
|
|
700
|
-
return typeof value === "string" ? value : undefined;
|
|
701
|
-
}
|
|
702
|
-
function signalOption(signal) {
|
|
703
|
-
return signal ? { signal } : {};
|
|
704
|
-
}
|
|
705
|
-
function optional(key, value) {
|
|
706
|
-
return value === undefined ? {} : { [key]: value };
|
|
707
|
-
}
|
|
708
|
-
const enc = encodeURIComponent;
|
|
709
|
-
function genieTool(name, description, inputSchema, resources, effect, execute) {
|
|
710
|
-
return {
|
|
711
|
-
name,
|
|
712
|
-
description,
|
|
713
|
-
inputSchema,
|
|
714
|
-
metadata: {
|
|
715
|
-
effect,
|
|
716
|
-
provider: "databricks",
|
|
717
|
-
service: "genie",
|
|
718
|
-
governance: { resources },
|
|
719
|
-
},
|
|
720
|
-
execute,
|
|
721
|
-
};
|
|
722
|
-
}
|
|
723
|
-
function genieSpecSchema(includeSql = false) {
|
|
724
|
-
return {
|
|
725
|
-
type: "object",
|
|
726
|
-
additionalProperties: false,
|
|
727
|
-
properties: {
|
|
728
|
-
version: { type: "number", const: 2 },
|
|
729
|
-
title: { type: "string" },
|
|
730
|
-
description: { type: "string" },
|
|
731
|
-
parentPath: { type: "string" },
|
|
732
|
-
warehouseId: { type: "string" },
|
|
733
|
-
sampleQuestions: {
|
|
734
|
-
type: "array",
|
|
735
|
-
items: {
|
|
736
|
-
type: "object",
|
|
737
|
-
additionalProperties: false,
|
|
738
|
-
properties: { id: { type: "string" }, question: { type: "string" } },
|
|
739
|
-
required: ["question"],
|
|
740
|
-
},
|
|
741
|
-
},
|
|
742
|
-
dataSources: {
|
|
743
|
-
type: "array",
|
|
744
|
-
minItems: 1,
|
|
745
|
-
maxItems: 30,
|
|
746
|
-
items: {
|
|
747
|
-
type: "object",
|
|
748
|
-
additionalProperties: false,
|
|
749
|
-
properties: {
|
|
750
|
-
kind: { type: "string", enum: ["table", "metric-view"] },
|
|
751
|
-
table: { type: "string" },
|
|
752
|
-
description: { type: "string" },
|
|
753
|
-
columns: {
|
|
754
|
-
type: "array",
|
|
755
|
-
items: {
|
|
756
|
-
type: "object",
|
|
757
|
-
additionalProperties: false,
|
|
758
|
-
properties: {
|
|
759
|
-
name: { type: "string" },
|
|
760
|
-
description: { type: "string" },
|
|
761
|
-
synonyms: { type: "array", items: { type: "string" } },
|
|
762
|
-
exclude: { type: "boolean" },
|
|
763
|
-
getExampleValues: { type: "boolean" },
|
|
764
|
-
enableFormatAssistance: { type: "boolean" },
|
|
765
|
-
enableEntityMatching: { type: "boolean" },
|
|
766
|
-
},
|
|
767
|
-
required: ["name"],
|
|
768
|
-
},
|
|
769
|
-
},
|
|
770
|
-
},
|
|
771
|
-
required: ["table"],
|
|
772
|
-
},
|
|
773
|
-
},
|
|
774
|
-
instructions: { type: "array", maxItems: 1, items: { type: "string" } },
|
|
775
|
-
...(includeSql
|
|
776
|
-
? {
|
|
777
|
-
examples: { type: "array", items: sqlQuestionSchema() },
|
|
778
|
-
sqlFunctions: {
|
|
779
|
-
type: "array",
|
|
780
|
-
items: {
|
|
781
|
-
type: "object",
|
|
782
|
-
additionalProperties: false,
|
|
783
|
-
properties: { id: { type: "string" }, identifier: { type: "string" } },
|
|
784
|
-
required: ["identifier"],
|
|
785
|
-
},
|
|
786
|
-
},
|
|
787
|
-
joins: {
|
|
788
|
-
type: "array",
|
|
789
|
-
items: {
|
|
790
|
-
type: "object",
|
|
791
|
-
additionalProperties: false,
|
|
792
|
-
properties: {
|
|
793
|
-
id: { type: "string" },
|
|
794
|
-
left: joinSideSchema(),
|
|
795
|
-
right: joinSideSchema(),
|
|
796
|
-
sql: { type: "string" },
|
|
797
|
-
},
|
|
798
|
-
required: ["left", "right", "sql"],
|
|
799
|
-
},
|
|
800
|
-
},
|
|
801
|
-
sqlSnippets: {
|
|
802
|
-
type: "object",
|
|
803
|
-
additionalProperties: false,
|
|
804
|
-
properties: {
|
|
805
|
-
filters: { type: "array", items: sqlSnippetSchema(false) },
|
|
806
|
-
expressions: { type: "array", items: sqlSnippetSchema(true) },
|
|
807
|
-
measures: { type: "array", items: sqlSnippetSchema(true) },
|
|
808
|
-
},
|
|
809
|
-
},
|
|
810
|
-
benchmarks: { type: "array", items: sqlQuestionSchema() },
|
|
811
|
-
}
|
|
812
|
-
: {}),
|
|
813
|
-
},
|
|
814
|
-
required: ["version", "title", "parentPath", "warehouseId", "dataSources"],
|
|
815
|
-
};
|
|
816
|
-
}
|
|
817
|
-
function updateToolSchema(includeSql = false) {
|
|
818
|
-
return {
|
|
819
|
-
type: "object",
|
|
820
|
-
additionalProperties: false,
|
|
821
|
-
properties: {
|
|
822
|
-
agentId: { type: "string" },
|
|
823
|
-
expectedFingerprint: { type: "string" },
|
|
824
|
-
set: {
|
|
825
|
-
type: "object",
|
|
826
|
-
additionalProperties: false,
|
|
827
|
-
properties: {
|
|
828
|
-
spec: genieSpecSchema(includeSql),
|
|
829
|
-
title: { type: "string" },
|
|
830
|
-
description: { type: "string" },
|
|
831
|
-
parentPath: { type: "string" },
|
|
832
|
-
warehouseId: { type: "string" },
|
|
833
|
-
},
|
|
834
|
-
},
|
|
835
|
-
remove: { type: "array", items: { type: "string", enum: ["description"] } },
|
|
836
|
-
},
|
|
837
|
-
required: ["agentId", "expectedFingerprint", "set"],
|
|
838
|
-
};
|
|
839
|
-
}
|
|
840
|
-
function sqlQuestionSchema() {
|
|
841
|
-
return {
|
|
842
|
-
type: "object",
|
|
843
|
-
additionalProperties: false,
|
|
844
|
-
properties: {
|
|
845
|
-
id: { type: "string" },
|
|
846
|
-
question: { type: "string" },
|
|
847
|
-
sql: { type: "string" },
|
|
848
|
-
},
|
|
849
|
-
required: ["question", "sql"],
|
|
850
|
-
};
|
|
851
|
-
}
|
|
852
|
-
function joinSideSchema() {
|
|
853
|
-
return {
|
|
854
|
-
type: "object",
|
|
855
|
-
additionalProperties: false,
|
|
856
|
-
properties: { identifier: { type: "string" }, alias: { type: "string" } },
|
|
857
|
-
required: ["identifier"],
|
|
858
|
-
};
|
|
859
|
-
}
|
|
860
|
-
function sqlSnippetSchema(requireAlias) {
|
|
861
|
-
return {
|
|
862
|
-
type: "object",
|
|
863
|
-
additionalProperties: false,
|
|
864
|
-
properties: {
|
|
865
|
-
id: { type: "string" },
|
|
866
|
-
sql: { type: "string" },
|
|
867
|
-
displayName: { type: "string" },
|
|
868
|
-
alias: { type: "string" },
|
|
869
|
-
synonyms: { type: "array", items: { type: "string" } },
|
|
870
|
-
},
|
|
871
|
-
required: requireAlias ? ["sql", "alias"] : ["sql"],
|
|
872
|
-
};
|
|
873
|
-
}
|
|
874
|
-
function idSchema(withFingerprint) {
|
|
875
|
-
return {
|
|
876
|
-
type: "object",
|
|
877
|
-
additionalProperties: false,
|
|
878
|
-
properties: {
|
|
879
|
-
agentId: { type: "string" },
|
|
880
|
-
...(withFingerprint ? { expectedFingerprint: { type: "string" } } : {}),
|
|
881
|
-
},
|
|
882
|
-
required: withFingerprint ? ["agentId", "expectedFingerprint"] : ["agentId"],
|
|
883
|
-
};
|
|
884
|
-
}
|
|
885
|
-
function ownership(principal, context) {
|
|
886
|
-
const toolCallId = context?.toolCallId?.trim();
|
|
887
|
-
if (!toolCallId)
|
|
888
|
-
throw new Error("Databricks Genie authoring requires a stable toolCallId for provenance.");
|
|
889
|
-
return { principal, toolCallId };
|
|
890
|
-
}
|
|
891
|
-
function contextSignal(context) {
|
|
892
|
-
return signalOption(context?.signal);
|
|
893
|
-
}
|
|
894
|
-
function publicAgent(agent) {
|
|
895
|
-
const { serializedSpace: _serializedSpace, ...publicFields } = agent;
|
|
896
|
-
return publicFields;
|
|
897
|
-
}
|
|
898
|
-
//# sourceMappingURL=genie-authoring.js.map
|