@databricks/appkit-ui 0.92.0 → 0.94.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/CLAUDE.md +3 -0
- package/dist/cli/commands/docs.js +231 -10
- package/dist/cli/commands/docs.js.map +1 -1
- package/dist/cli/commands/plugin/add/add.js +398 -0
- package/dist/cli/commands/plugin/add/add.js.map +1 -0
- package/dist/cli/commands/plugin/add/plan.js +216 -0
- package/dist/cli/commands/plugin/add/plan.js.map +1 -0
- package/dist/cli/commands/plugin/add/resolve.js +45 -0
- package/dist/cli/commands/plugin/add/resolve.js.map +1 -0
- package/dist/cli/commands/plugin/index.js +4 -1
- package/dist/cli/commands/plugin/index.js.map +1 -1
- package/dist/cli/commands/registry/add.js +3 -2
- package/dist/cli/commands/registry/add.js.map +1 -1
- package/dist/cli/commands/registry/config-plan.js +1 -1
- package/dist/cli/commands/registry/config-plan.js.map +1 -1
- package/dist/cli/commands/registry/config-writer.js +77 -9
- package/dist/cli/commands/registry/config-writer.js.map +1 -1
- package/dist/cli/commands/registry/env-writer.js +1 -1
- package/dist/cli/commands/registry/env-writer.js.map +1 -1
- package/dist/cli/commands/registry/server-register.js +62 -26
- package/dist/cli/commands/registry/server-register.js.map +1 -1
- package/dist/cli/commands/registry/workspace-picker.js +1 -1
- package/dist/cli/deploy-config.js.map +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/react/beta.d.ts +3 -1
- package/dist/react/beta.js +3 -1
- package/dist/react/charts/base.d.ts +1 -1
- package/dist/react/charts/base.d.ts.map +1 -1
- package/dist/react/charts/base.js +5 -3
- package/dist/react/charts/base.js.map +1 -1
- package/dist/react/charts/constants.js +13 -1
- package/dist/react/charts/constants.js.map +1 -1
- package/dist/react/charts/create-chart.js +1 -1
- package/dist/react/charts/create-chart.js.map +1 -1
- package/dist/react/charts/index.d.ts +1 -1
- package/dist/react/charts/types.d.ts +17 -8
- package/dist/react/charts/types.d.ts.map +1 -1
- package/dist/react/charts/types.js.map +1 -1
- package/dist/react/charts/wrapper.d.ts +1 -1
- package/dist/react/charts/wrapper.d.ts.map +1 -1
- package/dist/react/charts/wrapper.js +12 -5
- package/dist/react/charts/wrapper.js.map +1 -1
- package/dist/react/design-page.d.ts +33 -0
- package/dist/react/design-page.d.ts.map +1 -0
- package/dist/react/design-page.js +173 -0
- package/dist/react/design-page.js.map +1 -0
- package/dist/react/hooks/use-design-ready.d.ts +19 -0
- package/dist/react/hooks/use-design-ready.d.ts.map +1 -0
- package/dist/react/hooks/use-design-ready.js +33 -0
- package/dist/react/hooks/use-design-ready.js.map +1 -0
- package/dist/react/index.d.ts +2 -2
- package/dist/react/table/data-table.d.ts +6 -0
- package/dist/react/table/data-table.d.ts.map +1 -1
- package/dist/react/table/data-table.js +6 -0
- package/dist/react/table/data-table.js.map +1 -1
- package/dist/shared/src/plugin.d.ts.map +1 -1
- package/docs/api/appkit/Variable.design.md +6 -0
- package/docs/api/appkit-ui/data/AreaChart.md +25 -25
- package/docs/api/appkit-ui/data/BarChart.md +23 -23
- package/docs/api/appkit-ui/data/DataTable.md +2 -0
- package/docs/api/appkit-ui/data/DonutChart.md +24 -24
- package/docs/api/appkit-ui/data/HeatmapChart.md +25 -25
- package/docs/api/appkit-ui/data/LineChart.md +24 -24
- package/docs/api/appkit-ui/data/PieChart.md +24 -24
- package/docs/api/appkit-ui/data/RadarChart.md +22 -22
- package/docs/api/appkit-ui/data/ScatterChart.md +22 -22
- package/docs/api/appkit.md +1 -0
- package/docs/plugins/analytics.md +9 -1
- package/docs/plugins/design.md +233 -0
- package/llms.txt +3 -0
- package/package.json +1 -1
- package/sbom.cdx.json +1 -1
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import { APP_YAML_FILE } from "../../../deploy-config.js";
|
|
2
|
+
import { planHasContent } from "../../registry/config-plan.js";
|
|
3
|
+
import { bundleConflicts, preflightConfig, reportConfigWrite, validateBundle, writeConfig } from "../../registry/config-writer.js";
|
|
4
|
+
import { parseEnv, serializeEnvAppend } from "../../registry/env-reconcile.js";
|
|
5
|
+
import { findServerRoot, profileFromEnv } from "../../registry/add.js";
|
|
6
|
+
import { AUTH_MODE_BOTH, AUTH_MODE_FIELD, AUTH_MODE_OBO, AUTH_MODE_SP, authKey, buildAddPlan, findMissingValues, oboCapable, parseSetAuthModes, parseSetValues, resolveAuthModes, resourceConfigured, selectResources } from "./plan.js";
|
|
7
|
+
import { discoverIndexColumns, resolveDerivedValues } from "./resolve.js";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import fs from "node:fs";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { Command } from "commander";
|
|
12
|
+
import process from "node:process";
|
|
13
|
+
import pc from "picocolors";
|
|
14
|
+
import { parseDocument } from "yaml";
|
|
15
|
+
|
|
16
|
+
//#region src/cli/commands/plugin/add/add.ts
|
|
17
|
+
const MANIFEST_FILE = "appkit.plugins.json";
|
|
18
|
+
function loadPlugin(cwd, name) {
|
|
19
|
+
const file = path.join(cwd, MANIFEST_FILE);
|
|
20
|
+
if (!fs.existsSync(file)) throw new Error(`${MANIFEST_FILE} not found in ${cwd}; run \`appkit plugin sync --write\` first`);
|
|
21
|
+
const plugins = JSON.parse(fs.readFileSync(file, "utf-8")).plugins ?? {};
|
|
22
|
+
const plugin = plugins[name];
|
|
23
|
+
if (!plugin) throw new Error(`unknown plugin "${name}"; available: ${Object.keys(plugins).sort().join(", ")}`);
|
|
24
|
+
return {
|
|
25
|
+
...plugin,
|
|
26
|
+
name,
|
|
27
|
+
resources: {
|
|
28
|
+
required: plugin.resources?.required ?? [],
|
|
29
|
+
optional: plugin.resources?.optional ?? []
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function authModeLabel(mode) {
|
|
34
|
+
if (mode === AUTH_MODE_OBO) return "on behalf of user";
|
|
35
|
+
if (mode === AUTH_MODE_BOTH) return "service principal and on behalf of user";
|
|
36
|
+
return "service principal";
|
|
37
|
+
}
|
|
38
|
+
/** Bails out of the command on Ctrl+C in a prompt. */
|
|
39
|
+
async function answered(value) {
|
|
40
|
+
const { cancel, isCancel } = await import("@clack/prompts");
|
|
41
|
+
if (isCancel(value)) {
|
|
42
|
+
cancel("Cancelled.");
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
/** Asks which optional resources to configure (they're only added with values). */
|
|
48
|
+
async function promptOptional(plugin, values) {
|
|
49
|
+
const { confirm } = await import("@clack/prompts");
|
|
50
|
+
const picked = [];
|
|
51
|
+
for (const r of plugin.resources.optional) {
|
|
52
|
+
if (resourceConfigured(r, values)) continue;
|
|
53
|
+
if (await answered(await confirm({
|
|
54
|
+
message: `Configure ${r.alias}? ${pc.dim(`${r.description ?? ""} (optional)`)}`,
|
|
55
|
+
initialValue: false
|
|
56
|
+
}))) picked.push(r);
|
|
57
|
+
}
|
|
58
|
+
return picked;
|
|
59
|
+
}
|
|
60
|
+
/** As `apps init`: one question, then one per resource for "Mixed". */
|
|
61
|
+
async function promptAuthModes(resources) {
|
|
62
|
+
const capable = resources.filter(oboCapable);
|
|
63
|
+
if (capable.length === 0) return {};
|
|
64
|
+
const { log, select } = await import("@clack/prompts");
|
|
65
|
+
const appMode = await answered(await select({
|
|
66
|
+
message: "How should the app access resources?",
|
|
67
|
+
options: [
|
|
68
|
+
{
|
|
69
|
+
value: AUTH_MODE_SP,
|
|
70
|
+
label: "Service principal"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
value: AUTH_MODE_OBO,
|
|
74
|
+
label: "On behalf of user"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
value: "mixed",
|
|
78
|
+
label: "Mixed (choose per resource)"
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
}));
|
|
82
|
+
const modes = {};
|
|
83
|
+
for (const r of capable) {
|
|
84
|
+
modes[authKey(r)] = appMode === "mixed" ? await answered(await select({
|
|
85
|
+
message: `How should the app access ${r.alias}?`,
|
|
86
|
+
options: [
|
|
87
|
+
{
|
|
88
|
+
value: AUTH_MODE_OBO,
|
|
89
|
+
label: "On behalf of user"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
value: AUTH_MODE_SP,
|
|
93
|
+
label: "Service principal"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
value: AUTH_MODE_BOTH,
|
|
97
|
+
label: "Both"
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
})) : appMode;
|
|
101
|
+
log.info(`${r.alias}: ${authModeLabel(modes[authKey(r)])}`);
|
|
102
|
+
}
|
|
103
|
+
for (const r of resources) if (!oboCapable(r)) log.info(`${r.alias}: ${authModeLabel(AUTH_MODE_SP)} (only option)`);
|
|
104
|
+
return modes;
|
|
105
|
+
}
|
|
106
|
+
/** Prompts for each missing value, or fails on the first one when not interactive. */
|
|
107
|
+
async function fillMissing(missing, values, interactive) {
|
|
108
|
+
if (missing.length > 0 && !interactive) {
|
|
109
|
+
const m = missing[0];
|
|
110
|
+
throw new Error(`missing value for ${m.setKey}; use --set ${m.setKey}=value`);
|
|
111
|
+
}
|
|
112
|
+
if (missing.length === 0) return;
|
|
113
|
+
const { text } = await import("@clack/prompts");
|
|
114
|
+
for (const m of missing) {
|
|
115
|
+
const field = m.resource.fields?.[m.field];
|
|
116
|
+
const value = await answered(await text({
|
|
117
|
+
message: `${m.resource.alias}: ${m.field}`,
|
|
118
|
+
placeholder: field?.description,
|
|
119
|
+
validate: (v) => !v?.trim() || /[\r\n]/.test(v) ? "Enter a value" : void 0
|
|
120
|
+
}));
|
|
121
|
+
values[`${m.resource.resourceKey}.${m.field}`] = value.trim();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/** aiSearch's default index columns (production won't start without them): discovered, else prompted. */
|
|
125
|
+
async function aiSearchColumns(values, profile, interactive) {
|
|
126
|
+
const indexName = values["vector-search-index.id"];
|
|
127
|
+
try {
|
|
128
|
+
const columns = await discoverIndexColumns(indexName, profile);
|
|
129
|
+
if (columns.length > 0) {
|
|
130
|
+
console.log(pc.dim(`Index columns: ${columns.join(", ")}`));
|
|
131
|
+
return columns;
|
|
132
|
+
}
|
|
133
|
+
} catch (err) {
|
|
134
|
+
console.warn(pc.yellow(`Could not discover the columns of ${indexName}: ${err.message}`));
|
|
135
|
+
}
|
|
136
|
+
if (!interactive) throw new Error(`aiSearch needs the columns of ${indexName} to start in production; run with workspace access (--profile) or interactively to enter them`);
|
|
137
|
+
const { text } = await import("@clack/prompts");
|
|
138
|
+
return (await answered(await text({
|
|
139
|
+
message: `Columns to return from ${indexName} (comma-separated)`,
|
|
140
|
+
validate: (v) => v?.split(",").some((c) => c.trim()) ? void 0 : "Enter at least one column"
|
|
141
|
+
}))).split(",").map((c) => c.trim()).filter(Boolean);
|
|
142
|
+
}
|
|
143
|
+
/** What an app.yaml env entry points at, for comparing two entries. */
|
|
144
|
+
function entryKey(e) {
|
|
145
|
+
return JSON.stringify([e.valueFrom, e.value]);
|
|
146
|
+
}
|
|
147
|
+
/** The first item per key, in order. */
|
|
148
|
+
function firstBy(xs, key) {
|
|
149
|
+
return xs.filter((x, i) => xs.findIndex((y) => key(y) === key(x)) === i);
|
|
150
|
+
}
|
|
151
|
+
/** Env names the plan would set differently from .env, app.yaml or earlier plugins. */
|
|
152
|
+
function envConflicts(cwd, plan, pending = []) {
|
|
153
|
+
const dotEnv = fs.existsSync(path.join(cwd, ".env")) ? parseEnv(fs.readFileSync(path.join(cwd, ".env"), "utf-8")) : {};
|
|
154
|
+
const appYamlFile = path.join(cwd, APP_YAML_FILE);
|
|
155
|
+
const appEnv = /* @__PURE__ */ new Map();
|
|
156
|
+
if (fs.existsSync(appYamlFile)) {
|
|
157
|
+
const env = parseDocument(fs.readFileSync(appYamlFile, "utf-8")).toJSON()?.env;
|
|
158
|
+
for (const e of env ?? []) if (e?.name) appEnv.set(e.name, entryKey(e));
|
|
159
|
+
}
|
|
160
|
+
for (const p of pending) {
|
|
161
|
+
for (const e of p.dotEnv) if (!dotEnv[e.env]) dotEnv[e.env] = e.value;
|
|
162
|
+
for (const e of p.appYamlEnv) if (!appEnv.has(e.name)) appEnv.set(e.name, entryKey(e));
|
|
163
|
+
}
|
|
164
|
+
const out = /* @__PURE__ */ new Set();
|
|
165
|
+
for (const e of plan.dotEnv) if (dotEnv[e.env] && e.value && dotEnv[e.env] !== e.value) out.add(e.env);
|
|
166
|
+
for (const e of plan.appYamlEnv) {
|
|
167
|
+
const have = appEnv.get(e.name);
|
|
168
|
+
if (have !== void 0 && have !== entryKey(e)) out.add(e.name);
|
|
169
|
+
}
|
|
170
|
+
return [...out];
|
|
171
|
+
}
|
|
172
|
+
/** Plans one plugin without writing: prompts, derived values, file plan, registration config. */
|
|
173
|
+
async function preparePlugin(cwd, req, opts, pending) {
|
|
174
|
+
if (req.authMode !== void 0 && req.authMode !== AUTH_MODE_SP && req.authMode !== AUTH_MODE_OBO) throw new Error(`invalid --auth-mode value: "${req.authMode}" (must be obo or sp; use --set <plugin>.<resourceKey>.${AUTH_MODE_FIELD}=both for a single resource)`);
|
|
175
|
+
const plugin = loadPlugin(cwd, req.name);
|
|
176
|
+
const values = parseSetValues(req.set, plugin);
|
|
177
|
+
const setModes = parseSetAuthModes(req.set, plugin);
|
|
178
|
+
const interactive = !opts.yes && Boolean(process.stdin.isTTY);
|
|
179
|
+
let resources = selectResources(plugin, values);
|
|
180
|
+
if (interactive) resources.push(...await promptOptional(plugin, values));
|
|
181
|
+
const promptedModes = interactive && req.authMode === void 0 ? await promptAuthModes(resources.filter((r) => !(authKey(r) in setModes))) : {};
|
|
182
|
+
const { modes, keptSP } = resolveAuthModes(resources, setModes, promptedModes, req.authMode);
|
|
183
|
+
if (keptSP.length > 0) console.log(`Note: these resources cannot be accessed on behalf of the user and use the service principal: ${keptSP.join(", ")}`);
|
|
184
|
+
const missingNow = () => findMissingValues(plugin.name, resources, values, modes);
|
|
185
|
+
await fillMissing(missingNow().filter((m) => !m.resource.fields?.[m.field]?.resolve), values, interactive);
|
|
186
|
+
const profile = opts.profile ?? profileFromEnv(cwd);
|
|
187
|
+
for (const r of resources) try {
|
|
188
|
+
for (const [k, v] of Object.entries(await resolveDerivedValues(r, values, profile))) values[k] ||= v;
|
|
189
|
+
} catch (err) {
|
|
190
|
+
console.warn(pc.yellow(`Could not resolve derived values for ${r.alias}: ${err.message}`));
|
|
191
|
+
}
|
|
192
|
+
await fillMissing(missingNow(), values, interactive);
|
|
193
|
+
resources = selectResources(plugin, values);
|
|
194
|
+
const config = pluginConfig(plugin, resources, modes, plugin.name === "aiSearch" && opts.register !== false ? await aiSearchColumns(values, profile, interactive) : void 0);
|
|
195
|
+
const plan = buildAddPlan(plugin, resources, values, modes);
|
|
196
|
+
const conflicts = [...envConflicts(cwd, plan, pending), ...bundleConflicts(cwd, plan, pending)];
|
|
197
|
+
if (conflicts.length > 0) throw new Error(`${conflicts.join(", ")} already set to a different resource or value in .env, app.yaml or databricks.yml; nothing was written. Edit those entries by hand, then rerun.`);
|
|
198
|
+
return {
|
|
199
|
+
plugin,
|
|
200
|
+
plan,
|
|
201
|
+
config
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/** Requests from `plugin add a b --set ...`: each plugin gets its own --set pairs. */
|
|
205
|
+
function requestsFromArgs(names, set, authMode) {
|
|
206
|
+
for (const sv of set) {
|
|
207
|
+
const prefix = sv.split(".")[0];
|
|
208
|
+
if (!names.includes(prefix)) throw new Error(`--set "${sv}" is for "${prefix}", which this run doesn't add (${names.join(", ")})`);
|
|
209
|
+
}
|
|
210
|
+
return names.map((name) => ({
|
|
211
|
+
name,
|
|
212
|
+
set: set.filter((sv) => sv.split(".")[0] === name),
|
|
213
|
+
authMode
|
|
214
|
+
}));
|
|
215
|
+
}
|
|
216
|
+
const dataPlanSchema = z.object({
|
|
217
|
+
version: z.literal(1),
|
|
218
|
+
plugins: z.array(z.object({
|
|
219
|
+
name: z.string().min(1),
|
|
220
|
+
authMode: z.enum([AUTH_MODE_OBO, AUTH_MODE_SP]).optional(),
|
|
221
|
+
set: z.record(z.string(), z.string()).optional()
|
|
222
|
+
})).min(1)
|
|
223
|
+
});
|
|
224
|
+
/** Requests from a data plan file (`.appkit/data-plan.json`, version 1). */
|
|
225
|
+
function requestsFromPlan(file) {
|
|
226
|
+
const parsed = dataPlanSchema.safeParse(JSON.parse(fs.readFileSync(file, "utf-8")));
|
|
227
|
+
if (!parsed.success) throw new Error(`invalid data plan ${file}: ${parsed.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ")}`);
|
|
228
|
+
return parsed.data.plugins.map((p) => ({
|
|
229
|
+
name: p.name,
|
|
230
|
+
authMode: p.authMode,
|
|
231
|
+
set: Object.entries(p.set ?? {}).map(([k, v]) => {
|
|
232
|
+
const parts = k.split(".");
|
|
233
|
+
return `${parts.length >= 3 && parts[0] === p.name ? k : `${p.name}.${k}`}=${v}`;
|
|
234
|
+
})
|
|
235
|
+
}));
|
|
236
|
+
}
|
|
237
|
+
/** Plans every plugin, then writes each file once (one dev-server restart). */
|
|
238
|
+
async function runPluginAdd(names, opts) {
|
|
239
|
+
const cwd = opts.cwd ? path.resolve(opts.cwd) : process.cwd();
|
|
240
|
+
if (opts.fromPlan && (names.length > 0 || opts.set.length > 0 || opts.authMode)) throw new Error("--from-plan can't be combined with plugin names, --set or --auth-mode");
|
|
241
|
+
if (!opts.fromPlan && names.length === 0) throw new Error("name at least one plugin, or pass --from-plan <file>");
|
|
242
|
+
const requests = opts.fromPlan ? requestsFromPlan(path.resolve(cwd, opts.fromPlan)) : requestsFromArgs(names, opts.set, opts.authMode);
|
|
243
|
+
const seen = /* @__PURE__ */ new Set();
|
|
244
|
+
for (const r of requests) {
|
|
245
|
+
if (seen.has(r.name)) throw new Error(`plugin "${r.name}" is listed twice`);
|
|
246
|
+
seen.add(r.name);
|
|
247
|
+
}
|
|
248
|
+
preflightConfig(cwd);
|
|
249
|
+
const prepared = [];
|
|
250
|
+
for (const req of requests) prepared.push(await preparePlugin(cwd, req, opts, prepared.map((p) => p.plan)));
|
|
251
|
+
if (opts.register === false) for (const { plugin, config } of prepared) {
|
|
252
|
+
if (!config) continue;
|
|
253
|
+
console.log(`${pc.bold("Register it with this config in your createApp call:")}\n` + pc.dim(` ${plugin.name}(${toSource(config)})`));
|
|
254
|
+
}
|
|
255
|
+
else await registerInServer(cwd, prepared);
|
|
256
|
+
const plans = prepared.map((p) => p.plan);
|
|
257
|
+
await writeDotEnv(cwd, plans.flatMap((p) => p.dotEnv));
|
|
258
|
+
const merged = {
|
|
259
|
+
appYamlEnv: firstBy(plans.flatMap((p) => p.appYamlEnv), (x) => x.name),
|
|
260
|
+
bundleVariables: firstBy(plans.flatMap((p) => p.bundleVariables), (x) => x.name),
|
|
261
|
+
resourceBindings: firstBy(plans.flatMap((p) => p.resourceBindings), (x) => x.name),
|
|
262
|
+
userApiScopes: [...new Set(plans.flatMap((p) => p.userApiScopes ?? []))],
|
|
263
|
+
unverifiedTypes: [...new Set(plans.flatMap((p) => p.unverifiedTypes))]
|
|
264
|
+
};
|
|
265
|
+
if (planHasContent(merged)) {
|
|
266
|
+
const result = writeConfig(cwd, merged);
|
|
267
|
+
reportConfigWrite(result);
|
|
268
|
+
if (result.databricksYmlChanged) validateBundle(cwd, opts.profile ?? profileFromEnv(cwd));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/** One .env write: fills empty `KEY=` placeholders, appends new names, keeps set values. */
|
|
272
|
+
async function writeDotEnv(cwd, entries) {
|
|
273
|
+
const { readEnvFile } = await import("../../registry/env-writer.js");
|
|
274
|
+
const envPath = path.join(cwd, ".env");
|
|
275
|
+
const existing = readEnvFile(envPath);
|
|
276
|
+
const dotEnv = firstBy(entries, (e) => e.env);
|
|
277
|
+
const filled = dotEnv.filter((e) => existing[e.env] === "" && e.value);
|
|
278
|
+
const newEnv = dotEnv.filter((e) => !(e.env in existing));
|
|
279
|
+
if (filled.length === 0 && newEnv.length === 0) return;
|
|
280
|
+
let content = fs.existsSync(envPath) ? fs.readFileSync(envPath, "utf-8") : "";
|
|
281
|
+
for (const e of filled) content = content.replace(new RegExp(`^(\\s*(?:export\\s+)?${e.env}\\s*=).*$`, "m"), (_, key) => key + e.value);
|
|
282
|
+
const append = serializeEnvAppend(newEnv);
|
|
283
|
+
if (append) {
|
|
284
|
+
if (content.length > 0 && !content.endsWith("\n")) content += "\n";
|
|
285
|
+
content += append;
|
|
286
|
+
}
|
|
287
|
+
fs.writeFileSync(envPath, content);
|
|
288
|
+
console.log(`${pc.green("Updated .env:")} ${[...filled, ...newEnv].map((e) => e.env).join(", ")}`);
|
|
289
|
+
}
|
|
290
|
+
/** Plugins that default to the service principal unless told otherwise. */
|
|
291
|
+
const AUTH_OPTION_PLUGINS = new Set([
|
|
292
|
+
"files",
|
|
293
|
+
"aiSearch",
|
|
294
|
+
"agents"
|
|
295
|
+
]);
|
|
296
|
+
const OBO = "on-behalf-of-user";
|
|
297
|
+
/** The `createApp` config an OBO plan needs (the SP is unbound), plus aiSearch columns. */
|
|
298
|
+
function pluginConfig(plugin, resources, modes, columns) {
|
|
299
|
+
let obo = false;
|
|
300
|
+
if (AUTH_OPTION_PLUGINS.has(plugin.name)) {
|
|
301
|
+
const governed = resources.filter((r) => oboCapable(r) && (plugin.name !== "agents" || r.type === "model_service"));
|
|
302
|
+
const oboRes = governed.filter((r) => modes[authKey(r)] === AUTH_MODE_OBO);
|
|
303
|
+
obo = oboRes.length > 0 && oboRes.length === governed.length;
|
|
304
|
+
if (plugin.name === "agents") {
|
|
305
|
+
for (const r of resources) if (r.type === "volume" && modes[authKey(r)] === AUTH_MODE_OBO) console.warn(pc.yellow(`agents loads skills from ${r.resourceKey} as the service principal at boot, which gets no access in obo mode; use --set agents.${r.resourceKey}.authMode=sp (or both).`));
|
|
306
|
+
}
|
|
307
|
+
if (plugin.name === "files" && oboRes.length > 0 && !obo) {
|
|
308
|
+
const keys = oboRes.map((r) => filesVolumeKey(r));
|
|
309
|
+
if (keys.every(Boolean)) return { volumes: Object.fromEntries(keys.map((k) => [k, { auth: OBO }])) };
|
|
310
|
+
}
|
|
311
|
+
if (oboRes.length > 0 && !obo) console.warn(pc.yellow(`${plugin.name} is registered with one auth setting for all its resources; set auth per volume or index in its config to mix on-behalf-of-user (${oboRes.map((r) => r.resourceKey).join(", ")}) with service principal access.`));
|
|
312
|
+
}
|
|
313
|
+
if (plugin.name === "aiSearch") {
|
|
314
|
+
const index = {
|
|
315
|
+
...columns && { columns },
|
|
316
|
+
...obo && { auth: OBO }
|
|
317
|
+
};
|
|
318
|
+
return Object.keys(index).length > 0 ? { indexes: { default: index } } : void 0;
|
|
319
|
+
}
|
|
320
|
+
return obo ? { auth: OBO } : void 0;
|
|
321
|
+
}
|
|
322
|
+
/** Volume key as FilesPlugin.discoverVolumes derives it from DATABRICKS_VOLUME_<KEY>. */
|
|
323
|
+
function filesVolumeKey(r) {
|
|
324
|
+
const prefix = "DATABRICKS_VOLUME_";
|
|
325
|
+
return Object.values(r.fields ?? {}).map((f) => f.env).find((e) => e?.startsWith(prefix) && e.length > 18)?.slice(18).toLowerCase();
|
|
326
|
+
}
|
|
327
|
+
/** Source text for a config literal: `{ auth: "x", columns: ["a"] }`. */
|
|
328
|
+
function toSource(v) {
|
|
329
|
+
if (Array.isArray(v)) return `[${v.map(toSource).join(", ")}]`;
|
|
330
|
+
if (v && typeof v === "object") return `{ ${Object.entries(v).map(([k, x]) => `${/^[A-Za-z_$][\w$]*$/.test(k) ? k : JSON.stringify(k)}: ${toSource(x)}`).join(", ")} }`;
|
|
331
|
+
return JSON.stringify(v);
|
|
332
|
+
}
|
|
333
|
+
async function registerInServer(cwd, prepared) {
|
|
334
|
+
const serverRoot = findServerRoot(cwd);
|
|
335
|
+
const { findServerFile, registerPluginsInServer } = await import("../../registry/server-register.js");
|
|
336
|
+
const serverFile = findServerFile(serverRoot);
|
|
337
|
+
const entries = prepared.map(({ plugin, config }) => {
|
|
338
|
+
let importPath = plugin.stability === "beta" && plugin.package === "@databricks/appkit" ? `${plugin.package}/beta` : plugin.package;
|
|
339
|
+
if (plugin.package.startsWith(".")) {
|
|
340
|
+
const from = path.dirname(serverFile ?? serverRoot);
|
|
341
|
+
const rel = path.relative(from, path.resolve(cwd, plugin.package)).split(path.sep).join("/");
|
|
342
|
+
importPath = rel.startsWith(".") ? rel : `./${rel}`;
|
|
343
|
+
}
|
|
344
|
+
return {
|
|
345
|
+
importPath,
|
|
346
|
+
exportName: plugin.name,
|
|
347
|
+
callArgs: config ? toSource(config) : ""
|
|
348
|
+
};
|
|
349
|
+
});
|
|
350
|
+
registerPluginsInServer(serverRoot, entries).forEach((result, i) => {
|
|
351
|
+
const { importPath, exportName, callArgs } = entries[i];
|
|
352
|
+
const call = `${exportName}(${callArgs})`;
|
|
353
|
+
const shown = result.file && path.relative(cwd, path.join(serverRoot, result.file));
|
|
354
|
+
if (result.status === "wired") console.log(`${pc.green("Registered")} ${call} in ${shown}`);
|
|
355
|
+
else if (result.status === "already") {
|
|
356
|
+
console.log(pc.dim(`${exportName} is already registered in ${shown}`));
|
|
357
|
+
if (callArgs) console.warn(pc.yellow(` Make sure it is configured as ${call} for the chosen auth mode.`));
|
|
358
|
+
} else console.log(pc.yellow(`Couldn't auto-register ${exportName}: ${result.reason}.`) + "\nAdd it to your server's createApp call:\n" + pc.dim(` import { ${exportName} } from "${importPath}";\n createApp({ plugins: [${call}, /* ... */] });`));
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
/** A fresh `plugin add` command (commander keeps parsed values per instance). */
|
|
362
|
+
const createPluginAddCommand = () => new Command("add").description("Add plugins from appkit.plugins.json to the app: server registration, .env, app.yaml and databricks.yml, each written once").argument("[plugins...]", "Plugin names, as in appkit.plugins.json").option("--from-plan <file>", "Add the plugins listed in a data plan file (e.g. .appkit/data-plan.json, version 1)").option("--set <plugin.resourceKey.field=value>", "Set resource values (format: plugin.resourceKey.field=value, can specify multiple)", (v, acc) => [...acc, v], []).option("--auth-mode <mode>", "Default resource auth mode: obo (on behalf of the user) or sp (service principal). With obo, resources that cannot be accessed on behalf of the user use sp. Prompts if not provided in interactive mode, otherwise sp.").option("-C, --cwd <dir>", "Run as if started in <dir>").option("-y, --yes", "Don't prompt; fail on missing required values").option("--no-register", "Don't edit the server entry to register the plugin").option("-p, --profile <name>", "Databricks profile for bundle validate (defaults to the app's DATABRICKS_CONFIG_PROFILE)").addHelpText("after", `
|
|
363
|
+
Resource configuration (--set), as in \`databricks apps init\`:
|
|
364
|
+
Set resource values using --set plugin.resourceKey.field=value
|
|
365
|
+
Keys are defined in the app's appkit.plugins.json manifest.
|
|
366
|
+
Multi-field resources (e.g., database, secret) require all fields to be set together.
|
|
367
|
+
Use --set plugin.resourceKey.authMode=obo|sp|both to choose how the app accesses a resource:
|
|
368
|
+
on behalf of the user (obo), as the app's service principal (sp), or both.
|
|
369
|
+
obo/both add the resource's user_api_scopes; sp/both bind it with its permission.
|
|
370
|
+
|
|
371
|
+
Several plugins can be added in one run; each file is written once, so a dev
|
|
372
|
+
server watching them restarts once. Rerunning with the same input changes nothing.
|
|
373
|
+
Existing entries in .env, app.yaml and databricks.yml are never overwritten.
|
|
374
|
+
|
|
375
|
+
Data plan file (--from-plan), version 1:
|
|
376
|
+
{ "version": 1,
|
|
377
|
+
"plugins": [
|
|
378
|
+
{ "name": "analytics", "authMode": "obo",
|
|
379
|
+
"set": { "sql-warehouse.id": "abc123" } },
|
|
380
|
+
{ "name": "genie", "set": { "genie-space.id": "s1", "genie-space.name": "Sales" } } ] }
|
|
381
|
+
"set" keys are the --set keys, with or without the plugin prefix ("authMode" works per
|
|
382
|
+
resource, e.g. "sql-warehouse.authMode": "both"); "authMode" is the plugin's default.
|
|
383
|
+
|
|
384
|
+
Examples:
|
|
385
|
+
$ appkit plugin add analytics --set analytics.sql-warehouse.id=abc123
|
|
386
|
+
$ appkit plugin add analytics --auth-mode obo --set analytics.sql-warehouse.id=abc123
|
|
387
|
+
$ appkit plugin add jobs --auth-mode obo --set jobs.job.authMode=sp --set jobs.job.id=42
|
|
388
|
+
$ appkit plugin add analytics genie --set analytics.sql-warehouse.id=abc123 \\
|
|
389
|
+
--set genie.genie-space.id=s1 --set genie.genie-space.name=Sales
|
|
390
|
+
$ appkit plugin add --from-plan .appkit/data-plan.json --yes`).action((names, opts) => runPluginAdd(names, opts).catch((err) => {
|
|
391
|
+
console.error(pc.red(err.message));
|
|
392
|
+
process.exit(1);
|
|
393
|
+
}));
|
|
394
|
+
const pluginAddCommand = createPluginAddCommand();
|
|
395
|
+
|
|
396
|
+
//#endregion
|
|
397
|
+
export { pluginAddCommand };
|
|
398
|
+
//# sourceMappingURL=add.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add.js","names":[],"sources":["../../../../../src/cli/commands/plugin/add/add.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport process from \"node:process\";\n\nimport { Command } from \"commander\";\nimport pc from \"picocolors\";\nimport { parseDocument } from \"yaml\";\nimport { z } from \"zod\";\n\nimport { APP_YAML_FILE } from \"../../../deploy-config\";\nimport { findServerRoot, profileFromEnv } from \"../../registry/add\";\nimport type { ConfigPlan } from \"../../registry/config-plan\";\nimport {\n bundleConflicts,\n preflightConfig,\n planHasContent,\n reportConfigWrite,\n validateBundle,\n writeConfig,\n} from \"../../registry/config-writer\";\nimport { parseEnv, serializeEnvAppend } from \"../../registry/env-reconcile\";\nimport {\n AUTH_MODE_BOTH,\n AUTH_MODE_FIELD,\n AUTH_MODE_OBO,\n AUTH_MODE_SP,\n type AddPlan,\n type AuthMode,\n authKey,\n buildAddPlan,\n findMissingValues,\n type ManifestPlugin,\n type ManifestResource,\n type MissingValue,\n oboCapable,\n parseSetAuthModes,\n parseSetValues,\n resolveAuthModes,\n resourceConfigured,\n selectResources,\n} from \"./plan\";\nimport { discoverIndexColumns, resolveDerivedValues } from \"./resolve\";\n\nconst MANIFEST_FILE = \"appkit.plugins.json\";\n\ninterface AddOptions {\n set: string[];\n fromPlan?: string;\n authMode?: string;\n cwd?: string;\n yes?: boolean;\n register?: boolean;\n profile?: string;\n}\n\nfunction loadPlugin(cwd: string, name: string): ManifestPlugin {\n const file = path.join(cwd, MANIFEST_FILE);\n if (!fs.existsSync(file)) {\n throw new Error(\n `${MANIFEST_FILE} not found in ${cwd}; run \\`appkit plugin sync --write\\` first`,\n );\n }\n const manifest = JSON.parse(fs.readFileSync(file, \"utf-8\")) as {\n plugins?: Record<string, ManifestPlugin>;\n };\n const plugins = manifest.plugins ?? {};\n const plugin = plugins[name];\n if (!plugin) {\n throw new Error(\n `unknown plugin \"${name}\"; available: ${Object.keys(plugins).sort().join(\", \")}`,\n );\n }\n return {\n ...plugin,\n name,\n resources: {\n required: plugin.resources?.required ?? [],\n optional: plugin.resources?.optional ?? [],\n },\n };\n}\n\nfunction authModeLabel(mode: AuthMode): string {\n if (mode === AUTH_MODE_OBO) return \"on behalf of user\";\n if (mode === AUTH_MODE_BOTH) return \"service principal and on behalf of user\";\n return \"service principal\";\n}\n\n/** Bails out of the command on Ctrl+C in a prompt. */\nasync function answered<T>(value: T | symbol): Promise<T> {\n const { cancel, isCancel } = await import(\"@clack/prompts\");\n if (isCancel(value)) {\n cancel(\"Cancelled.\");\n process.exit(1);\n }\n return value as T;\n}\n\n/** Asks which optional resources to configure (they're only added with values). */\nasync function promptOptional(\n plugin: ManifestPlugin,\n values: Record<string, string>,\n): Promise<ManifestResource[]> {\n const { confirm } = await import(\"@clack/prompts\");\n const picked: ManifestResource[] = [];\n for (const r of plugin.resources.optional) {\n if (resourceConfigured(r, values)) continue;\n const yes = await answered(\n await confirm({\n message: `Configure ${r.alias}? ${pc.dim(`${r.description ?? \"\"} (optional)`)}`,\n initialValue: false,\n }),\n );\n if (yes) picked.push(r);\n }\n return picked;\n}\n\n/** As `apps init`: one question, then one per resource for \"Mixed\". */\nasync function promptAuthModes(\n resources: ManifestResource[],\n): Promise<Record<string, AuthMode>> {\n const capable = resources.filter(oboCapable);\n if (capable.length === 0) return {};\n const { log, select } = await import(\"@clack/prompts\");\n const appMode = await answered(\n await select({\n message: \"How should the app access resources?\",\n options: [\n { value: AUTH_MODE_SP, label: \"Service principal\" },\n { value: AUTH_MODE_OBO, label: \"On behalf of user\" },\n { value: \"mixed\", label: \"Mixed (choose per resource)\" },\n ],\n }),\n );\n const modes: Record<string, AuthMode> = {};\n for (const r of capable) {\n modes[authKey(r)] =\n appMode === \"mixed\"\n ? await answered(\n await select<AuthMode>({\n message: `How should the app access ${r.alias}?`,\n options: [\n { value: AUTH_MODE_OBO, label: \"On behalf of user\" },\n { value: AUTH_MODE_SP, label: \"Service principal\" },\n { value: AUTH_MODE_BOTH, label: \"Both\" },\n ],\n }),\n )\n : (appMode as AuthMode);\n log.info(`${r.alias}: ${authModeLabel(modes[authKey(r)])}`);\n }\n for (const r of resources) {\n if (!oboCapable(r)) {\n log.info(`${r.alias}: ${authModeLabel(AUTH_MODE_SP)} (only option)`);\n }\n }\n return modes;\n}\n\n/** Prompts for each missing value, or fails on the first one when not interactive. */\nasync function fillMissing(\n missing: MissingValue[],\n values: Record<string, string>,\n interactive: boolean,\n): Promise<void> {\n if (missing.length > 0 && !interactive) {\n const m = missing[0];\n throw new Error(\n `missing value for ${m.setKey}; use --set ${m.setKey}=value`,\n );\n }\n if (missing.length === 0) return;\n const { text } = await import(\"@clack/prompts\");\n for (const m of missing) {\n const field = m.resource.fields?.[m.field];\n const value = await answered(\n await text({\n message: `${m.resource.alias}: ${m.field}`,\n placeholder: field?.description,\n validate: (v) =>\n !v?.trim() || /[\\r\\n]/.test(v) ? \"Enter a value\" : undefined,\n }),\n );\n values[`${m.resource.resourceKey}.${m.field}`] = value.trim();\n }\n}\n\n/** aiSearch's default index columns (production won't start without them): discovered, else prompted. */\nasync function aiSearchColumns(\n values: Record<string, string>,\n profile: string | undefined,\n interactive: boolean,\n): Promise<string[]> {\n const indexName = values[\"vector-search-index.id\"];\n try {\n const columns = await discoverIndexColumns(indexName, profile);\n if (columns.length > 0) {\n console.log(pc.dim(`Index columns: ${columns.join(\", \")}`));\n return columns;\n }\n } catch (err) {\n console.warn(\n pc.yellow(\n `Could not discover the columns of ${indexName}: ${(err as Error).message}`,\n ),\n );\n }\n if (!interactive) {\n throw new Error(\n `aiSearch needs the columns of ${indexName} to start in production; run with workspace access (--profile) or interactively to enter them`,\n );\n }\n const { text } = await import(\"@clack/prompts\");\n const answer = await answered(\n await text({\n message: `Columns to return from ${indexName} (comma-separated)`,\n validate: (v) =>\n v?.split(\",\").some((c) => c.trim())\n ? undefined\n : \"Enter at least one column\",\n }),\n );\n return answer\n .split(\",\")\n .map((c) => c.trim())\n .filter(Boolean);\n}\n\n/** What an app.yaml env entry points at, for comparing two entries. */\nfunction entryKey(e: { valueFrom?: string; value?: string }): string {\n return JSON.stringify([e.valueFrom, e.value]);\n}\n\n/** The first item per key, in order. */\nfunction firstBy<T>(xs: T[], key: (x: T) => string): T[] {\n return xs.filter((x, i) => xs.findIndex((y) => key(y) === key(x)) === i);\n}\n\n/** Env names the plan would set differently from .env, app.yaml or earlier plugins. */\nexport function envConflicts(\n cwd: string,\n plan: AddPlan,\n /** Plans of earlier plugins in the same run, not yet written. */\n pending: AddPlan[] = [],\n): string[] {\n const dotEnv = fs.existsSync(path.join(cwd, \".env\"))\n ? parseEnv(fs.readFileSync(path.join(cwd, \".env\"), \"utf-8\"))\n : {};\n const appYamlFile = path.join(cwd, APP_YAML_FILE);\n const appEnv = new Map<string, string>();\n if (fs.existsSync(appYamlFile)) {\n const env = parseDocument(fs.readFileSync(appYamlFile, \"utf-8\")).toJSON()\n ?.env as\n | { name?: string; valueFrom?: string; value?: string }[]\n | undefined;\n for (const e of env ?? []) {\n if (e?.name) appEnv.set(e.name, entryKey(e));\n }\n }\n for (const p of pending) {\n for (const e of p.dotEnv) if (!dotEnv[e.env]) dotEnv[e.env] = e.value;\n for (const e of p.appYamlEnv) {\n if (!appEnv.has(e.name)) appEnv.set(e.name, entryKey(e));\n }\n }\n const out = new Set<string>();\n for (const e of plan.dotEnv) {\n if (dotEnv[e.env] && e.value && dotEnv[e.env] !== e.value) out.add(e.env);\n }\n for (const e of plan.appYamlEnv) {\n const have = appEnv.get(e.name);\n if (have !== undefined && have !== entryKey(e)) out.add(e.name);\n }\n return [...out];\n}\n\n/** One plugin of a run: its name, its --set pairs and its default auth mode. */\nexport interface PluginRequest {\n name: string;\n set: string[];\n authMode?: string;\n}\n\ninterface PreparedPlugin {\n plugin: ManifestPlugin;\n plan: AddPlan;\n config?: Record<string, unknown>;\n}\n\n/** Plans one plugin without writing: prompts, derived values, file plan, registration config. */\nasync function preparePlugin(\n cwd: string,\n req: PluginRequest,\n opts: AddOptions,\n pending: AddPlan[],\n): Promise<PreparedPlugin> {\n if (\n req.authMode !== undefined &&\n req.authMode !== AUTH_MODE_SP &&\n req.authMode !== AUTH_MODE_OBO\n ) {\n throw new Error(\n `invalid --auth-mode value: \"${req.authMode}\" (must be obo or sp; use --set <plugin>.<resourceKey>.${AUTH_MODE_FIELD}=both for a single resource)`,\n );\n }\n const plugin = loadPlugin(cwd, req.name);\n const values = parseSetValues(req.set, plugin);\n const setModes = parseSetAuthModes(req.set, plugin);\n const interactive = !opts.yes && Boolean(process.stdin.isTTY);\n\n let resources = selectResources(plugin, values);\n if (interactive) resources.push(...(await promptOptional(plugin, values)));\n\n const promptedModes =\n interactive && req.authMode === undefined\n ? await promptAuthModes(\n resources.filter((r) => !(authKey(r) in setModes)),\n )\n : {};\n const { modes, keptSP } = resolveAuthModes(\n resources,\n setModes,\n promptedModes,\n req.authMode,\n );\n if (keptSP.length > 0) {\n console.log(\n `Note: these resources cannot be accessed on behalf of the user and use the service principal: ${keptSP.join(\", \")}`,\n );\n }\n\n const missingNow = () =>\n findMissingValues(plugin.name, resources, values, modes);\n // Values the user supplies come first: the derived ones need them.\n await fillMissing(\n missingNow().filter((m) => !m.resource.fields?.[m.field]?.resolve),\n values,\n interactive,\n );\n const profile = opts.profile ?? profileFromEnv(cwd);\n for (const r of resources) {\n try {\n for (const [k, v] of Object.entries(\n await resolveDerivedValues(r, values, profile),\n )) {\n values[k] ||= v;\n }\n } catch (err) {\n console.warn(\n pc.yellow(\n `Could not resolve derived values for ${r.alias}: ${(err as Error).message}`,\n ),\n );\n }\n }\n await fillMissing(missingNow(), values, interactive);\n resources = selectResources(plugin, values);\n\n const config = pluginConfig(\n plugin,\n resources,\n modes,\n plugin.name === \"aiSearch\" && opts.register !== false\n ? await aiSearchColumns(values, profile, interactive)\n : undefined,\n );\n\n const plan = buildAddPlan(plugin, resources, values, modes);\n\n const conflicts = [\n ...envConflicts(cwd, plan, pending),\n ...bundleConflicts(cwd, plan, pending),\n ];\n if (conflicts.length > 0) {\n throw new Error(\n `${conflicts.join(\", \")} already set to a different resource or value in .env, app.yaml or databricks.yml; nothing was written. Edit those entries by hand, then rerun.`,\n );\n }\n\n return { plugin, plan, config };\n}\n\n/** Requests from `plugin add a b --set ...`: each plugin gets its own --set pairs. */\nexport function requestsFromArgs(\n names: string[],\n set: string[],\n authMode: string | undefined,\n): PluginRequest[] {\n for (const sv of set) {\n const prefix = sv.split(\".\")[0];\n if (!names.includes(prefix)) {\n throw new Error(\n `--set \"${sv}\" is for \"${prefix}\", which this run doesn't add (${names.join(\", \")})`,\n );\n }\n }\n return names.map((name) => ({\n name,\n set: set.filter((sv) => sv.split(\".\")[0] === name),\n authMode,\n }));\n}\n\nconst dataPlanSchema = z.object({\n version: z.literal(1),\n plugins: z\n .array(\n z.object({\n name: z.string().min(1),\n authMode: z.enum([AUTH_MODE_OBO, AUTH_MODE_SP]).optional(),\n /** --set keys, with or without the plugin prefix. */\n set: z.record(z.string(), z.string()).optional(),\n }),\n )\n .min(1),\n});\n\n/** Requests from a data plan file (`.appkit/data-plan.json`, version 1). */\nexport function requestsFromPlan(file: string): PluginRequest[] {\n const parsed = dataPlanSchema.safeParse(\n JSON.parse(fs.readFileSync(file, \"utf-8\")),\n );\n if (!parsed.success) {\n throw new Error(\n `invalid data plan ${file}: ${parsed.error.issues.map((i) => `${i.path.join(\".\")}: ${i.message}`).join(\"; \")}`,\n );\n }\n return parsed.data.plugins.map((p) => ({\n name: p.name,\n authMode: p.authMode,\n set: Object.entries(p.set ?? {}).map(([k, v]) => {\n // Count parts: \"files.path\" (resourceKey \"files\") is unprefixed.\n const parts = k.split(\".\");\n const prefixed = parts.length >= 3 && parts[0] === p.name;\n return `${prefixed ? k : `${p.name}.${k}`}=${v}`;\n }),\n }));\n}\n\n/** Plans every plugin, then writes each file once (one dev-server restart). */\nasync function runPluginAdd(names: string[], opts: AddOptions): Promise<void> {\n const cwd = opts.cwd ? path.resolve(opts.cwd) : process.cwd();\n if (\n opts.fromPlan &&\n (names.length > 0 || opts.set.length > 0 || opts.authMode)\n ) {\n throw new Error(\n \"--from-plan can't be combined with plugin names, --set or --auth-mode\",\n );\n }\n if (!opts.fromPlan && names.length === 0) {\n throw new Error(\"name at least one plugin, or pass --from-plan <file>\");\n }\n const requests = opts.fromPlan\n ? requestsFromPlan(path.resolve(cwd, opts.fromPlan))\n : requestsFromArgs(names, opts.set, opts.authMode);\n const seen = new Set<string>();\n for (const r of requests) {\n if (seen.has(r.name)) throw new Error(`plugin \"${r.name}\" is listed twice`);\n seen.add(r.name);\n }\n\n // Fail before any prompt or write rather than leave a partial install.\n preflightConfig(cwd);\n\n const prepared: PreparedPlugin[] = [];\n for (const req of requests) {\n prepared.push(\n await preparePlugin(\n cwd,\n req,\n opts,\n prepared.map((p) => p.plan),\n ),\n );\n }\n\n if (opts.register === false) {\n for (const { plugin, config } of prepared) {\n if (!config) continue;\n // The config carries required settings (auth mode, columns, model).\n console.log(\n `${pc.bold(\"Register it with this config in your createApp call:\")}\\n` +\n pc.dim(` ${plugin.name}(${toSource(config)})`),\n );\n }\n } else {\n await registerInServer(cwd, prepared);\n }\n\n const plans = prepared.map((p) => p.plan);\n await writeDotEnv(\n cwd,\n plans.flatMap((p) => p.dotEnv),\n );\n\n // Shared resources: envConflicts already rejected differing ones.\n const merged: ConfigPlan = {\n appYamlEnv: firstBy(\n plans.flatMap((p) => p.appYamlEnv),\n (x) => x.name,\n ),\n bundleVariables: firstBy(\n plans.flatMap((p) => p.bundleVariables),\n (x) => x.name,\n ),\n resourceBindings: firstBy(\n plans.flatMap((p) => p.resourceBindings),\n (x) => x.name,\n ),\n userApiScopes: [...new Set(plans.flatMap((p) => p.userApiScopes ?? []))],\n unverifiedTypes: [...new Set(plans.flatMap((p) => p.unverifiedTypes))],\n };\n if (planHasContent(merged)) {\n const result = writeConfig(cwd, merged);\n reportConfigWrite(result);\n if (result.databricksYmlChanged) {\n validateBundle(cwd, opts.profile ?? profileFromEnv(cwd));\n }\n }\n}\n\n/** One .env write: fills empty `KEY=` placeholders, appends new names, keeps set values. */\nasync function writeDotEnv(\n cwd: string,\n entries: { env: string; value: string }[],\n): Promise<void> {\n const { readEnvFile } = await import(\"../../registry/env-writer.js\");\n const envPath = path.join(cwd, \".env\");\n const existing = readEnvFile(envPath);\n const dotEnv = firstBy(entries, (e) => e.env);\n const filled = dotEnv.filter((e) => existing[e.env] === \"\" && e.value);\n const newEnv = dotEnv.filter((e) => !(e.env in existing));\n if (filled.length === 0 && newEnv.length === 0) return;\n let content = fs.existsSync(envPath) ? fs.readFileSync(envPath, \"utf-8\") : \"\";\n for (const e of filled) {\n // e.env is a validated identifier, so it is safe in the pattern.\n content = content.replace(\n new RegExp(`^(\\\\s*(?:export\\\\s+)?${e.env}\\\\s*=).*$`, \"m\"),\n (_, key: string) => key + e.value,\n );\n }\n const append = serializeEnvAppend(newEnv);\n if (append) {\n if (content.length > 0 && !content.endsWith(\"\\n\")) content += \"\\n\";\n content += append;\n }\n fs.writeFileSync(envPath, content);\n console.log(\n `${pc.green(\"Updated .env:\")} ${[...filled, ...newEnv].map((e) => e.env).join(\", \")}`,\n );\n}\n\n/** Plugins that default to the service principal unless told otherwise. */\nconst AUTH_OPTION_PLUGINS = new Set([\"files\", \"aiSearch\", \"agents\"]);\nconst OBO = \"on-behalf-of-user\";\n\n/** The `createApp` config an OBO plan needs (the SP is unbound), plus aiSearch columns. */\nexport function pluginConfig(\n plugin: ManifestPlugin,\n resources: ManifestResource[],\n modes: Record<string, AuthMode>,\n columns?: string[],\n): Record<string, unknown> | undefined {\n let obo = false;\n if (AUTH_OPTION_PLUGINS.has(plugin.name)) {\n // For agents only the model counts: skills load as the SP at boot.\n const governed = resources.filter(\n (r) =>\n oboCapable(r) &&\n (plugin.name !== \"agents\" || r.type === \"model_service\"),\n );\n const oboRes = governed.filter((r) => modes[authKey(r)] === AUTH_MODE_OBO);\n obo = oboRes.length > 0 && oboRes.length === governed.length;\n if (plugin.name === \"agents\") {\n for (const r of resources) {\n if (r.type === \"volume\" && modes[authKey(r)] === AUTH_MODE_OBO) {\n console.warn(\n pc.yellow(\n `agents loads skills from ${r.resourceKey} as the service principal at boot, which gets no access in obo mode; use --set agents.${r.resourceKey}.authMode=sp (or both).`,\n ),\n );\n }\n }\n }\n // files also takes auth per volume.\n if (plugin.name === \"files\" && oboRes.length > 0 && !obo) {\n const keys = oboRes.map((r) => filesVolumeKey(r));\n if (keys.every(Boolean)) {\n return {\n volumes: Object.fromEntries(keys.map((k) => [k, { auth: OBO }])),\n };\n }\n }\n if (oboRes.length > 0 && !obo) {\n console.warn(\n pc.yellow(\n `${plugin.name} is registered with one auth setting for all its resources; set auth per volume or index in its config to mix on-behalf-of-user (${oboRes.map((r) => r.resourceKey).join(\", \")}) with service principal access.`,\n ),\n );\n }\n }\n if (plugin.name === \"aiSearch\") {\n const index = { ...(columns && { columns }), ...(obo && { auth: OBO }) };\n return Object.keys(index).length > 0\n ? { indexes: { default: index } }\n : undefined;\n }\n return obo ? { auth: OBO } : undefined;\n}\n\n/** Volume key as FilesPlugin.discoverVolumes derives it from DATABRICKS_VOLUME_<KEY>. */\nfunction filesVolumeKey(r: ManifestResource): string | undefined {\n const prefix = \"DATABRICKS_VOLUME_\";\n const env = Object.values(r.fields ?? {})\n .map((f) => f.env)\n .find((e) => e?.startsWith(prefix) && e.length > prefix.length);\n return env?.slice(prefix.length).toLowerCase();\n}\n\n/** Source text for a config literal: `{ auth: \"x\", columns: [\"a\"] }`. */\nexport function toSource(v: unknown): string {\n if (Array.isArray(v)) return `[${v.map(toSource).join(\", \")}]`;\n if (v && typeof v === \"object\") {\n const props = Object.entries(v).map(\n ([k, x]) =>\n `${/^[A-Za-z_$][\\w$]*$/.test(k) ? k : JSON.stringify(k)}: ${toSource(x)}`,\n );\n return `{ ${props.join(\", \")} }`;\n }\n return JSON.stringify(v);\n}\n\nasync function registerInServer(\n cwd: string,\n prepared: PreparedPlugin[],\n): Promise<void> {\n const serverRoot = findServerRoot(cwd);\n // Lazy: server-register pulls in the @ast-grep/napi native addon.\n const { findServerFile, registerPluginsInServer } =\n await import(\"../../registry/server-register.js\");\n const serverFile = findServerFile(serverRoot);\n const entries = prepared.map(({ plugin, config }) => {\n // The /beta subpath is AppKit's; other packages export their plugins as is.\n let importPath =\n plugin.stability === \"beta\" && plugin.package === \"@databricks/appkit\"\n ? `${plugin.package}/beta`\n : plugin.package;\n // Local packages are app-root relative; imports are server-file relative.\n if (plugin.package.startsWith(\".\")) {\n const from = path.dirname(serverFile ?? serverRoot);\n const rel = path\n .relative(from, path.resolve(cwd, plugin.package))\n .split(path.sep)\n .join(\"/\");\n importPath = rel.startsWith(\".\") ? rel : `./${rel}`;\n }\n return {\n importPath,\n exportName: plugin.name,\n callArgs: config ? toSource(config) : \"\",\n };\n });\n const results = registerPluginsInServer(serverRoot, entries);\n results.forEach((result, i) => {\n const { importPath, exportName, callArgs } = entries[i];\n const call = `${exportName}(${callArgs})`;\n const shown =\n result.file && path.relative(cwd, path.join(serverRoot, result.file));\n if (result.status === \"wired\") {\n console.log(`${pc.green(\"Registered\")} ${call} in ${shown}`);\n } else if (result.status === \"already\") {\n console.log(pc.dim(`${exportName} is already registered in ${shown}`));\n if (callArgs) {\n console.warn(\n pc.yellow(\n ` Make sure it is configured as ${call} for the chosen auth mode.`,\n ),\n );\n }\n } else {\n console.log(\n pc.yellow(`Couldn't auto-register ${exportName}: ${result.reason}.`) +\n \"\\nAdd it to your server's createApp call:\\n\" +\n pc.dim(\n ` import { ${exportName} } from \"${importPath}\";\\n` +\n ` createApp({ plugins: [${call}, /* ... */] });`,\n ),\n );\n }\n });\n}\n\n/** A fresh `plugin add` command (commander keeps parsed values per instance). */\nexport const createPluginAddCommand = () =>\n new Command(\"add\")\n .description(\n \"Add plugins from appkit.plugins.json to the app: server registration, .env, app.yaml and databricks.yml, each written once\",\n )\n .argument(\"[plugins...]\", \"Plugin names, as in appkit.plugins.json\")\n .option(\n \"--from-plan <file>\",\n \"Add the plugins listed in a data plan file (e.g. .appkit/data-plan.json, version 1)\",\n )\n .option(\n \"--set <plugin.resourceKey.field=value>\",\n \"Set resource values (format: plugin.resourceKey.field=value, can specify multiple)\",\n (v: string, acc: string[]) => [...acc, v],\n [] as string[],\n )\n .option(\n \"--auth-mode <mode>\",\n \"Default resource auth mode: obo (on behalf of the user) or sp (service principal). With obo, resources that cannot be accessed on behalf of the user use sp. Prompts if not provided in interactive mode, otherwise sp.\",\n )\n .option(\"-C, --cwd <dir>\", \"Run as if started in <dir>\")\n .option(\"-y, --yes\", \"Don't prompt; fail on missing required values\")\n .option(\n \"--no-register\",\n \"Don't edit the server entry to register the plugin\",\n )\n .option(\n \"-p, --profile <name>\",\n \"Databricks profile for bundle validate (defaults to the app's DATABRICKS_CONFIG_PROFILE)\",\n )\n .addHelpText(\n \"after\",\n `\nResource configuration (--set), as in \\`databricks apps init\\`:\n Set resource values using --set plugin.resourceKey.field=value\n Keys are defined in the app's appkit.plugins.json manifest.\n Multi-field resources (e.g., database, secret) require all fields to be set together.\n Use --set plugin.resourceKey.authMode=obo|sp|both to choose how the app accesses a resource:\n on behalf of the user (obo), as the app's service principal (sp), or both.\n obo/both add the resource's user_api_scopes; sp/both bind it with its permission.\n\nSeveral plugins can be added in one run; each file is written once, so a dev\nserver watching them restarts once. Rerunning with the same input changes nothing.\nExisting entries in .env, app.yaml and databricks.yml are never overwritten.\n\nData plan file (--from-plan), version 1:\n { \"version\": 1,\n \"plugins\": [\n { \"name\": \"analytics\", \"authMode\": \"obo\",\n \"set\": { \"sql-warehouse.id\": \"abc123\" } },\n { \"name\": \"genie\", \"set\": { \"genie-space.id\": \"s1\", \"genie-space.name\": \"Sales\" } } ] }\n \"set\" keys are the --set keys, with or without the plugin prefix (\"authMode\" works per\n resource, e.g. \"sql-warehouse.authMode\": \"both\"); \"authMode\" is the plugin's default.\n\nExamples:\n $ appkit plugin add analytics --set analytics.sql-warehouse.id=abc123\n $ appkit plugin add analytics --auth-mode obo --set analytics.sql-warehouse.id=abc123\n $ appkit plugin add jobs --auth-mode obo --set jobs.job.authMode=sp --set jobs.job.id=42\n $ appkit plugin add analytics genie --set analytics.sql-warehouse.id=abc123 \\\\\n --set genie.genie-space.id=s1 --set genie.genie-space.name=Sales\n $ appkit plugin add --from-plan .appkit/data-plan.json --yes`,\n )\n .action((names: string[], opts: AddOptions) =>\n runPluginAdd(names, opts).catch((err: Error) => {\n console.error(pc.red(err.message));\n process.exit(1);\n }),\n );\n\nexport const pluginAddCommand = createPluginAddCommand();\n"],"mappings":";;;;;;;;;;;;;;;;AA2CA,MAAM,gBAAgB;AAYtB,SAAS,WAAW,KAAa,MAA8B;CAC7D,MAAM,OAAO,KAAK,KAAK,KAAK,cAAc;AAC1C,KAAI,CAAC,GAAG,WAAW,KAAK,CACtB,OAAM,IAAI,MACR,GAAG,cAAc,gBAAgB,IAAI,4CACtC;CAKH,MAAM,UAHW,KAAK,MAAM,GAAG,aAAa,MAAM,QAAQ,CAAC,CAGlC,WAAW,EAAE;CACtC,MAAM,SAAS,QAAQ;AACvB,KAAI,CAAC,OACH,OAAM,IAAI,MACR,mBAAmB,KAAK,gBAAgB,OAAO,KAAK,QAAQ,CAAC,MAAM,CAAC,KAAK,KAAK,GAC/E;AAEH,QAAO;EACL,GAAG;EACH;EACA,WAAW;GACT,UAAU,OAAO,WAAW,YAAY,EA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