@databricks/appkit-ui 0.91.3 → 0.93.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.
Files changed (81) hide show
  1. package/CLAUDE.md +2 -0
  2. package/NOTICE.md +3 -3
  3. package/dist/cli/commands/doctor/checks-existence.js +15 -0
  4. package/dist/cli/commands/doctor/checks-existence.js.map +1 -1
  5. package/dist/cli/commands/plugin/add/add.js +398 -0
  6. package/dist/cli/commands/plugin/add/add.js.map +1 -0
  7. package/dist/cli/commands/plugin/add/plan.js +216 -0
  8. package/dist/cli/commands/plugin/add/plan.js.map +1 -0
  9. package/dist/cli/commands/plugin/add/resolve.js +45 -0
  10. package/dist/cli/commands/plugin/add/resolve.js.map +1 -0
  11. package/dist/cli/commands/plugin/create/resource-defaults.js +4 -0
  12. package/dist/cli/commands/plugin/create/resource-defaults.js.map +1 -1
  13. package/dist/cli/commands/plugin/index.js +4 -1
  14. package/dist/cli/commands/plugin/index.js.map +1 -1
  15. package/dist/cli/commands/plugin/schema-resources.js +2 -1
  16. package/dist/cli/commands/plugin/schema-resources.js.map +1 -1
  17. package/dist/cli/commands/registry/add.js +3 -2
  18. package/dist/cli/commands/registry/add.js.map +1 -1
  19. package/dist/cli/commands/registry/config-plan.js +1 -1
  20. package/dist/cli/commands/registry/config-plan.js.map +1 -1
  21. package/dist/cli/commands/registry/config-writer.js +77 -9
  22. package/dist/cli/commands/registry/config-writer.js.map +1 -1
  23. package/dist/cli/commands/registry/env-writer.js +15 -2
  24. package/dist/cli/commands/registry/env-writer.js.map +1 -1
  25. package/dist/cli/commands/registry/server-register.js +62 -26
  26. package/dist/cli/commands/registry/server-register.js.map +1 -1
  27. package/dist/cli/commands/registry/workspace-picker.js +47 -2
  28. package/dist/cli/commands/registry/workspace-picker.js.map +1 -1
  29. package/dist/cli/deploy-config.js.map +1 -1
  30. package/dist/cli/index.js +1 -1
  31. package/dist/react/beta.d.ts +3 -1
  32. package/dist/react/beta.js +3 -1
  33. package/dist/react/charts/base.d.ts +1 -1
  34. package/dist/react/charts/base.d.ts.map +1 -1
  35. package/dist/react/charts/base.js +5 -3
  36. package/dist/react/charts/base.js.map +1 -1
  37. package/dist/react/charts/constants.js +13 -1
  38. package/dist/react/charts/constants.js.map +1 -1
  39. package/dist/react/charts/create-chart.js +1 -1
  40. package/dist/react/charts/create-chart.js.map +1 -1
  41. package/dist/react/charts/index.d.ts +1 -1
  42. package/dist/react/charts/types.d.ts +7 -3
  43. package/dist/react/charts/types.d.ts.map +1 -1
  44. package/dist/react/charts/types.js.map +1 -1
  45. package/dist/react/charts/wrapper.d.ts +1 -1
  46. package/dist/react/charts/wrapper.d.ts.map +1 -1
  47. package/dist/react/charts/wrapper.js +12 -5
  48. package/dist/react/charts/wrapper.js.map +1 -1
  49. package/dist/react/design-page.d.ts +33 -0
  50. package/dist/react/design-page.d.ts.map +1 -0
  51. package/dist/react/design-page.js +173 -0
  52. package/dist/react/design-page.js.map +1 -0
  53. package/dist/react/hooks/use-design-ready.d.ts +19 -0
  54. package/dist/react/hooks/use-design-ready.d.ts.map +1 -0
  55. package/dist/react/hooks/use-design-ready.js +33 -0
  56. package/dist/react/hooks/use-design-ready.js.map +1 -0
  57. package/dist/react/index.d.ts +2 -2
  58. package/dist/schemas/manifest.d.ts +79 -0
  59. package/dist/schemas/manifest.d.ts.map +1 -1
  60. package/dist/schemas/manifest.js +10 -1
  61. package/dist/schemas/manifest.js.map +1 -1
  62. package/dist/shared/src/plugin.d.ts.map +1 -1
  63. package/docs/api/appkit/Enumeration.ResourceType.md +9 -0
  64. package/docs/api/appkit/TypeAlias.ResourcePermission.md +1 -0
  65. package/docs/api/appkit/Variable.design.md +6 -0
  66. package/docs/api/appkit-ui/data/AreaChart.md +2 -2
  67. package/docs/api/appkit-ui/data/BarChart.md +2 -2
  68. package/docs/api/appkit-ui/data/DonutChart.md +2 -2
  69. package/docs/api/appkit-ui/data/HeatmapChart.md +2 -2
  70. package/docs/api/appkit-ui/data/LineChart.md +2 -2
  71. package/docs/api/appkit-ui/data/PieChart.md +2 -2
  72. package/docs/api/appkit-ui/data/RadarChart.md +2 -2
  73. package/docs/api/appkit-ui/data/ScatterChart.md +2 -2
  74. package/docs/api/appkit.md +1 -0
  75. package/docs/plugins/agents.md +3 -3
  76. package/docs/plugins/analytics.md +8 -0
  77. package/docs/plugins/design.md +233 -0
  78. package/docs/plugins/manifest.md +1 -0
  79. package/llms.txt +2 -0
  80. package/package.json +1 -1
  81. package/sbom.cdx.json +1 -1
@@ -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,EAAE;GAC1C,UAAU,OAAO,WAAW,YAAY,EAAE;GAC3C;EACF;;AAGH,SAAS,cAAc,MAAwB;AAC7C,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C;AACtE,OAAI,SACF,SAAQ,KACN,GAAG,OACD,mCAAmC,KAAK,4BACzC,CACF;QAGH,SAAQ,IACN,GAAG,OAAO,0BAA0B,WAAW,IAAI,OAAO,OAAO,GAAG,GAClE,gDACA,GAAG,IACD,cAAc,WAAW,WAAW,WAAW,8BAClB,KAAK,kBACnC,CACJ;GAEH;;;AAIJ,MAAa,+BACX,IAAI,QAAQ,MAAM,CACf,YACC,6HACD,CACA,SAAS,gBAAgB,0CAA0C,CACnE,OACC,sBACA,sFACD,CACA,OACC,0CACA,uFACC,GAAW,QAAkB,CAAC,GAAG,KAAK,EAAE,EACzC,EAAE,CACH,CACA,OACC,sBACA,0NACD,CACA,OAAO,mBAAmB,6BAA6B,CACvD,OAAO,aAAa,gDAAgD,CACpE,OACC,iBACA,qDACD,CACA,OACC,wBACA,2FACD,CACA,YACC,SACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;gEA6BD,CACA,QAAQ,OAAiB,SACxB,aAAa,OAAO,KAAK,CAAC,OAAO,QAAe;AAC9C,SAAQ,MAAM,GAAG,IAAI,IAAI,QAAQ,CAAC;AAClC,SAAQ,KAAK,EAAE;EACf,CACH;AAEL,MAAa,mBAAmB,wBAAwB"}
@@ -0,0 +1,216 @@
1
+ import { DABS_BINDING_BY_TYPE } from "../../../../schemas/manifest.js";
2
+ import { isValidEnvName } from "../../registry/requirements.js";
3
+
4
+ //#region src/cli/commands/plugin/add/plan.ts
5
+ const AUTH_MODE_SP = "sp";
6
+ const AUTH_MODE_OBO = "obo";
7
+ const AUTH_MODE_BOTH = "both";
8
+ /** Reserved --set field that selects a resource's auth mode. */
9
+ const AUTH_MODE_FIELD = "authMode";
10
+ /** The manifest's binding, else the built-in one for the type (as the CLI generator does). */
11
+ function bindingOf(r) {
12
+ return r.binding ?? DABS_BINDING_BY_TYPE[r.type];
13
+ }
14
+ /** Same identity as resource de-duplication: type + key. */
15
+ function authKey(r) {
16
+ return `${r.type}:${r.resourceKey}`;
17
+ }
18
+ /** Keys `resourceKey.field`, as the CLI's resourceValues map. */
19
+ function valueKey(r, field) {
20
+ return `${r.resourceKey}.${field}`;
21
+ }
22
+ function fieldNames(r) {
23
+ return Object.keys(r.fields ?? {}).sort();
24
+ }
25
+ function allResources(p) {
26
+ return [...p.resources.required, ...p.resources.optional];
27
+ }
28
+ /** Manifest fields the resource's databricks.yml binding references. */
29
+ function bindingVarFields(r) {
30
+ return (bindingOf(r)?.varFields ?? []).map(([f]) => f);
31
+ }
32
+ /** The --set keys the manifest declares (authMode only for non-app-only resources). */
33
+ function validSetKeys(plugin) {
34
+ const keys = /* @__PURE__ */ new Set();
35
+ for (const r of allResources(plugin)) {
36
+ const prefix = `${plugin.name}.${r.resourceKey}.`;
37
+ for (const f of [...fieldNames(r), ...bindingVarFields(r)]) keys.add(prefix + f);
38
+ if (!r.appOnly) keys.add(prefix + AUTH_MODE_FIELD);
39
+ }
40
+ return keys;
41
+ }
42
+ /** The error for a --set key the plugin manifest doesn't declare. */
43
+ function undeclaredKey(plugin, sv) {
44
+ const keys = validSetKeys(plugin);
45
+ return /* @__PURE__ */ new Error(`--set "${sv}" does not match a resource declared by plugin "${plugin.name}"; valid keys: ${[...keys].join(", ") || "(none, the plugin declares no resources)"}`);
46
+ }
47
+ function splitSetKey(sv) {
48
+ const eq = sv.indexOf("=");
49
+ const key = eq === -1 ? "" : sv.slice(0, eq);
50
+ if (!key) throw new Error(`invalid --set format "${sv}", expected plugin.resourceKey.field=value`);
51
+ const parts = key.split(".");
52
+ if (parts.length < 3) throw new Error(`invalid --set key "${key}", expected plugin.resourceKey.field`);
53
+ return {
54
+ pluginName: parts[0],
55
+ resourceKey: parts[1],
56
+ field: parts.slice(2).join("."),
57
+ value: sv.slice(eq + 1)
58
+ };
59
+ }
60
+ /** `--set plugin.resourceKey.field=value` → `resourceKey.field` → value; authMode pairs are skipped. */
61
+ function parseSetValues(setValues, plugin) {
62
+ const rv = {};
63
+ for (const sv of setValues) {
64
+ const { pluginName, resourceKey, field, value } = splitSetKey(sv);
65
+ if (field === AUTH_MODE_FIELD) continue;
66
+ if (pluginName !== plugin.name) throw new Error(`unknown plugin "${pluginName}" in --set "${sv}"; this command adds "${plugin.name}"`);
67
+ if (!validSetKeys(plugin).has(`${pluginName}.${resourceKey}.${field}`)) throw undeclaredKey(plugin, sv);
68
+ rv[`${resourceKey}.${field}`] = value;
69
+ }
70
+ for (const r of allResources(plugin)) {
71
+ const checkable = fieldNames(r).filter((f) => !r.fields?.[f].bundleIgnore && !r.fields?.[f].localOnly);
72
+ if (checkable.length <= 1) continue;
73
+ const missing = checkable.filter((f) => !rv[valueKey(r, f)]);
74
+ if (missing.length > 0 && missing.length < checkable.length) throw new Error(`incomplete resource "${r.resourceKey}": missing fields [${missing.map((f) => valueKey(r, f)).join(" ")}] (all fields must be set together)`);
75
+ }
76
+ return rv;
77
+ }
78
+ /** Parses `--set plugin.resourceKey.authMode=obo|sp|both` into authKey → mode. */
79
+ function parseSetAuthModes(setValues, plugin) {
80
+ const modes = {};
81
+ for (const sv of setValues) {
82
+ const { pluginName, resourceKey, field, value } = splitSetKey(sv);
83
+ if (field !== AUTH_MODE_FIELD) continue;
84
+ if (pluginName !== plugin.name) throw new Error(`unknown plugin "${pluginName}" in --set "${sv}"; this command adds "${plugin.name}"`);
85
+ const r = allResources(plugin).find((x) => x.resourceKey === resourceKey);
86
+ if (!r) throw undeclaredKey(plugin, sv);
87
+ if (value !== AUTH_MODE_SP && value !== AUTH_MODE_OBO && value !== AUTH_MODE_BOTH) throw new Error(`invalid auth mode "${value}" in --set "${sv}" (must be obo, sp, or both)`);
88
+ if (r.appOnly) throw new Error(`resource "${resourceKey}" of plugin "${plugin.name}" is always accessed by the app's service principal; remove --set ${sv}`);
89
+ if (value !== AUTH_MODE_SP && !r.scope) throw new Error(`resource "${resourceKey}" of plugin "${plugin.name}" cannot be accessed on behalf of the user; use ${plugin.name}.${resourceKey}.${AUTH_MODE_FIELD}=sp`);
90
+ modes[authKey(r)] = value;
91
+ }
92
+ return modes;
93
+ }
94
+ /** True when the resource can be accessed on behalf of the user. */
95
+ function oboCapable(r) {
96
+ return Boolean(r.scope) && !r.appOnly;
97
+ }
98
+ /** Precedence: --set authMode, prompt, --auth-mode, sp; obo/both only are stored. */
99
+ function resolveAuthModes(resources, setModes, promptedModes, defaultMode) {
100
+ const modes = {};
101
+ const keptSP = [];
102
+ for (const r of resources) {
103
+ let mode = setModes[authKey(r)] ?? promptedModes[authKey(r)];
104
+ if (mode === void 0 && defaultMode === AUTH_MODE_OBO) {
105
+ if (!oboCapable(r)) {
106
+ keptSP.push(r.resourceKey);
107
+ continue;
108
+ }
109
+ mode = AUTH_MODE_OBO;
110
+ }
111
+ if (mode === AUTH_MODE_OBO || mode === AUTH_MODE_BOTH) modes[authKey(r)] = mode;
112
+ }
113
+ return {
114
+ modes,
115
+ keptSP
116
+ };
117
+ }
118
+ /** True when any field value of the resource is set. */
119
+ function resourceConfigured(r, values) {
120
+ return [...fieldNames(r), ...bindingVarFields(r)].some((f) => values[valueKey(r, f)]);
121
+ }
122
+ /** Required resources plus optional ones that have a value. */
123
+ function selectResources(plugin, values) {
124
+ return [...plugin.resources.required, ...plugin.resources.optional.filter((r) => resourceConfigured(r, values))];
125
+ }
126
+ /** Unset values: binding fields (sp/both) or env fields (obo), plus resolver fields local .env needs. */
127
+ function findMissingValues(pluginName, resources, values, modes) {
128
+ const missing = [];
129
+ for (const r of resources) {
130
+ const fields = modes[authKey(r)] === AUTH_MODE_OBO ? fieldNames(r).filter((f) => r.fields?.[f].env && !r.fields[f].localOnly) : variableFields(r);
131
+ const resolved = fieldNames(r).filter((f) => r.fields?.[f].resolve);
132
+ for (const field of new Set([...fields, ...resolved])) {
133
+ if (values[valueKey(r, field)] || r.fields?.[field]?.value) continue;
134
+ missing.push({
135
+ resource: r,
136
+ field,
137
+ setKey: `${pluginName}.${r.resourceKey}.${field}`
138
+ });
139
+ }
140
+ }
141
+ return missing;
142
+ }
143
+ /** Fields that become bundle variables: manifest fields plus binding var fields. */
144
+ function variableFields(r) {
145
+ const out = fieldNames(r).filter((f) => !r.fields?.[f].bundleIgnore && !r.fields?.[f].localOnly);
146
+ const covered = new Set(fieldNames(r));
147
+ for (const f of bindingVarFields(r)) if (!covered.has(f)) out.push(f);
148
+ return out;
149
+ }
150
+ function varName(r, field) {
151
+ return `${r.resourceKey.replaceAll("-", "_")}_${field}`;
152
+ }
153
+ /** The file changes for the resources, as the CLI generator: OBO-only gets a literal value, no binding. */
154
+ function buildAddPlan(plugin, resources, values, modes) {
155
+ const dotEnv = [];
156
+ const appYamlEnv = [];
157
+ const bundleVariables = [];
158
+ const resourceBindings = [];
159
+ const unverifiedTypes = [];
160
+ const scopes = [];
161
+ for (const r of resources) {
162
+ const mode = modes[authKey(r)];
163
+ const oboOnly = mode === AUTH_MODE_OBO;
164
+ if ((mode === AUTH_MODE_OBO || mode === AUTH_MODE_BOTH) && r.scope) scopes.push(r.scope);
165
+ for (const f of fieldNames(r)) {
166
+ const field = r.fields?.[f] ?? {};
167
+ if (!field.env || !isValidEnvName(field.env)) continue;
168
+ const value = (values[valueKey(r, f)] || field.value || "").replace(/[\r\n]/g, "");
169
+ dotEnv.push({
170
+ env: field.env,
171
+ value
172
+ });
173
+ if (field.localOnly) continue;
174
+ appYamlEnv.push(oboOnly ? {
175
+ name: field.env,
176
+ value
177
+ } : {
178
+ name: field.env,
179
+ valueFrom: r.resourceKey
180
+ });
181
+ }
182
+ if (oboOnly) continue;
183
+ const binding = bindingOf(r);
184
+ if (!binding) {
185
+ unverifiedTypes.push(r.type);
186
+ continue;
187
+ }
188
+ for (const f of variableFields(r)) bundleVariables.push({
189
+ name: varName(r, f),
190
+ description: r.fields?.[f]?.description || r.description,
191
+ value: values[valueKey(r, f)] || r.fields?.[f]?.value || void 0
192
+ });
193
+ const fields = {};
194
+ for (const [mf, yf] of binding.varFields) fields[yf] = `\${var.${varName(r, mf)}}`;
195
+ for (const [yf, v] of binding.staticFields ?? []) fields[yf] = v;
196
+ resourceBindings.push({
197
+ name: r.resourceKey,
198
+ type: binding.yamlKey,
199
+ permission: r.permission,
200
+ fields
201
+ });
202
+ }
203
+ scopes.push(...plugin.scopes ?? []);
204
+ return {
205
+ dotEnv,
206
+ appYamlEnv,
207
+ bundleVariables,
208
+ resourceBindings,
209
+ unverifiedTypes,
210
+ userApiScopes: [...new Set(scopes)]
211
+ };
212
+ }
213
+
214
+ //#endregion
215
+ export { AUTH_MODE_BOTH, AUTH_MODE_FIELD, AUTH_MODE_OBO, AUTH_MODE_SP, authKey, buildAddPlan, findMissingValues, oboCapable, parseSetAuthModes, parseSetValues, resolveAuthModes, resourceConfigured, selectResources };
216
+ //# sourceMappingURL=plan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plan.js","names":[],"sources":["../../../../../src/cli/commands/plugin/add/plan.ts"],"sourcesContent":["import { DABS_BINDING_BY_TYPE } from \"../../../../schemas/manifest\";\nimport type { AppYamlEnvEntry, ResourceBinding } from \"../../../deploy-config\";\nimport type { BundleVariable, ConfigPlan } from \"../../registry/config-plan\";\nimport { isValidEnvName } from \"../../registry/requirements\";\n\n// Port of the Databricks CLI's `apps init` resource handling (cmd/apps/init.go, libs/apps/generator).\n\nexport const AUTH_MODE_SP = \"sp\";\nexport const AUTH_MODE_OBO = \"obo\";\nexport const AUTH_MODE_BOTH = \"both\";\nexport type AuthMode =\n | typeof AUTH_MODE_SP\n | typeof AUTH_MODE_OBO\n | typeof AUTH_MODE_BOTH;\n\n/** Reserved --set field that selects a resource's auth mode. */\nexport const AUTH_MODE_FIELD = \"authMode\";\n\nexport interface ManifestField {\n env?: string;\n description?: string;\n value?: string;\n localOnly?: boolean;\n bundleIgnore?: boolean;\n /** Derived-value resolver key, e.g. \"postgres:host\" (see resolve.ts). */\n resolve?: string;\n}\n\nexport interface ManifestResource {\n type: string;\n alias: string;\n resourceKey: string;\n description?: string;\n permission?: string;\n fields?: Record<string, ManifestField>;\n scope?: string;\n appOnly?: boolean;\n binding?: Binding;\n}\n\ntype FieldPair = readonly [string, string];\ninterface Binding {\n yamlKey: string;\n varFields: readonly FieldPair[];\n staticFields?: readonly FieldPair[];\n}\n\n/** The manifest's binding, else the built-in one for the type (as the CLI generator does). */\nfunction bindingOf(r: ManifestResource): Binding | undefined {\n return (\n r.binding ??\n (DABS_BINDING_BY_TYPE as Record<string, Binding | undefined>)[r.type]\n );\n}\n\n/** A plugin entry of the app's appkit.plugins.json (the fields used here). */\nexport interface ManifestPlugin {\n name: string;\n package: string;\n stability?: string;\n scopes?: string[];\n resources: { required: ManifestResource[]; optional: ManifestResource[] };\n}\n\n/** Same identity as resource de-duplication: type + key. */\nexport function authKey(r: ManifestResource): string {\n return `${r.type}:${r.resourceKey}`;\n}\n\n/** Keys `resourceKey.field`, as the CLI's resourceValues map. */\nfunction valueKey(r: ManifestResource, field: string): string {\n return `${r.resourceKey}.${field}`;\n}\n\nfunction fieldNames(r: ManifestResource): string[] {\n return Object.keys(r.fields ?? {}).sort();\n}\n\nfunction allResources(p: ManifestPlugin): ManifestResource[] {\n return [...p.resources.required, ...p.resources.optional];\n}\n\n/** Manifest fields the resource's databricks.yml binding references. */\nfunction bindingVarFields(r: ManifestResource): string[] {\n return (bindingOf(r)?.varFields ?? []).map(([f]) => f);\n}\n\n/** The --set keys the manifest declares (authMode only for non-app-only resources). */\nexport function validSetKeys(plugin: ManifestPlugin): Set<string> {\n const keys = new Set<string>();\n for (const r of allResources(plugin)) {\n const prefix = `${plugin.name}.${r.resourceKey}.`;\n for (const f of [...fieldNames(r), ...bindingVarFields(r)])\n keys.add(prefix + f);\n if (!r.appOnly) keys.add(prefix + AUTH_MODE_FIELD);\n }\n return keys;\n}\n\n/** The error for a --set key the plugin manifest doesn't declare. */\nfunction undeclaredKey(plugin: ManifestPlugin, sv: string): Error {\n const keys = validSetKeys(plugin);\n return new Error(\n `--set \"${sv}\" does not match a resource declared by plugin \"${plugin.name}\"; valid keys: ${[...keys].join(\", \") || \"(none, the plugin declares no resources)\"}`,\n );\n}\n\nfunction splitSetKey(sv: string): {\n pluginName: string;\n resourceKey: string;\n field: string;\n value: string;\n} {\n const eq = sv.indexOf(\"=\");\n const key = eq === -1 ? \"\" : sv.slice(0, eq);\n if (!key) {\n throw new Error(\n `invalid --set format \"${sv}\", expected plugin.resourceKey.field=value`,\n );\n }\n const parts = key.split(\".\");\n if (parts.length < 3) {\n throw new Error(\n `invalid --set key \"${key}\", expected plugin.resourceKey.field`,\n );\n }\n return {\n pluginName: parts[0],\n resourceKey: parts[1],\n field: parts.slice(2).join(\".\"),\n value: sv.slice(eq + 1),\n };\n}\n\n/** `--set plugin.resourceKey.field=value` → `resourceKey.field` → value; authMode pairs are skipped. */\nexport function parseSetValues(\n setValues: string[],\n plugin: ManifestPlugin,\n): Record<string, string> {\n const rv: Record<string, string> = {};\n for (const sv of setValues) {\n const { pluginName, resourceKey, field, value } = splitSetKey(sv);\n if (field === AUTH_MODE_FIELD) continue;\n if (pluginName !== plugin.name) {\n throw new Error(\n `unknown plugin \"${pluginName}\" in --set \"${sv}\"; this command adds \"${plugin.name}\"`,\n );\n }\n if (!validSetKeys(plugin).has(`${pluginName}.${resourceKey}.${field}`)) {\n throw undeclaredKey(plugin, sv);\n }\n rv[`${resourceKey}.${field}`] = value;\n }\n\n for (const r of allResources(plugin)) {\n const checkable = fieldNames(r).filter(\n (f) => !r.fields?.[f].bundleIgnore && !r.fields?.[f].localOnly,\n );\n if (checkable.length <= 1) continue;\n const missing = checkable.filter((f) => !rv[valueKey(r, f)]);\n if (missing.length > 0 && missing.length < checkable.length) {\n throw new Error(\n `incomplete resource \"${r.resourceKey}\": missing fields [${missing.map((f) => valueKey(r, f)).join(\" \")}] (all fields must be set together)`,\n );\n }\n }\n return rv;\n}\n\n/** Parses `--set plugin.resourceKey.authMode=obo|sp|both` into authKey → mode. */\nexport function parseSetAuthModes(\n setValues: string[],\n plugin: ManifestPlugin,\n): Record<string, AuthMode> {\n const modes: Record<string, AuthMode> = {};\n for (const sv of setValues) {\n const { pluginName, resourceKey, field, value } = splitSetKey(sv);\n if (field !== AUTH_MODE_FIELD) continue;\n if (pluginName !== plugin.name) {\n throw new Error(\n `unknown plugin \"${pluginName}\" in --set \"${sv}\"; this command adds \"${plugin.name}\"`,\n );\n }\n const r = allResources(plugin).find((x) => x.resourceKey === resourceKey);\n if (!r) throw undeclaredKey(plugin, sv);\n if (\n value !== AUTH_MODE_SP &&\n value !== AUTH_MODE_OBO &&\n value !== AUTH_MODE_BOTH\n ) {\n throw new Error(\n `invalid auth mode \"${value}\" in --set \"${sv}\" (must be obo, sp, or both)`,\n );\n }\n if (r.appOnly) {\n throw new Error(\n `resource \"${resourceKey}\" of plugin \"${plugin.name}\" is always accessed by the app's service principal; remove --set ${sv}`,\n );\n }\n if (value !== AUTH_MODE_SP && !r.scope) {\n throw new Error(\n `resource \"${resourceKey}\" of plugin \"${plugin.name}\" cannot be accessed on behalf of the user; use ${plugin.name}.${resourceKey}.${AUTH_MODE_FIELD}=sp`,\n );\n }\n modes[authKey(r)] = value;\n }\n return modes;\n}\n\n/** True when the resource can be accessed on behalf of the user. */\nexport function oboCapable(r: ManifestResource): boolean {\n return Boolean(r.scope) && !r.appOnly;\n}\n\n/** Precedence: --set authMode, prompt, --auth-mode, sp; obo/both only are stored. */\nexport function resolveAuthModes(\n resources: ManifestResource[],\n setModes: Record<string, AuthMode>,\n promptedModes: Record<string, AuthMode>,\n defaultMode: string | undefined,\n): { modes: Record<string, AuthMode>; keptSP: string[] } {\n const modes: Record<string, AuthMode> = {};\n const keptSP: string[] = [];\n for (const r of resources) {\n let mode: AuthMode | undefined =\n setModes[authKey(r)] ?? promptedModes[authKey(r)];\n if (mode === undefined && defaultMode === AUTH_MODE_OBO) {\n if (!oboCapable(r)) {\n keptSP.push(r.resourceKey);\n continue;\n }\n mode = AUTH_MODE_OBO;\n }\n if (mode === AUTH_MODE_OBO || mode === AUTH_MODE_BOTH) {\n modes[authKey(r)] = mode;\n }\n }\n return { modes, keptSP };\n}\n\n/** True when any field value of the resource is set. */\nexport function resourceConfigured(\n r: ManifestResource,\n values: Record<string, string>,\n): boolean {\n return [...fieldNames(r), ...bindingVarFields(r)].some(\n (f) => values[valueKey(r, f)],\n );\n}\n\n/** Required resources plus optional ones that have a value. */\nexport function selectResources(\n plugin: ManifestPlugin,\n values: Record<string, string>,\n): ManifestResource[] {\n return [\n ...plugin.resources.required,\n ...plugin.resources.optional.filter((r) => resourceConfigured(r, values)),\n ];\n}\n\nexport interface MissingValue {\n resource: ManifestResource;\n field: string;\n /** The --set key that supplies it. */\n setKey: string;\n}\n\n/** Unset values: binding fields (sp/both) or env fields (obo), plus resolver fields local .env needs. */\nexport function findMissingValues(\n pluginName: string,\n resources: ManifestResource[],\n values: Record<string, string>,\n modes: Record<string, AuthMode>,\n): MissingValue[] {\n const missing: MissingValue[] = [];\n for (const r of resources) {\n const fields =\n modes[authKey(r)] === AUTH_MODE_OBO\n ? fieldNames(r).filter(\n (f) => r.fields?.[f].env && !r.fields[f].localOnly,\n )\n : variableFields(r);\n const resolved = fieldNames(r).filter((f) => r.fields?.[f].resolve);\n for (const field of new Set([...fields, ...resolved])) {\n if (values[valueKey(r, field)] || r.fields?.[field]?.value) continue;\n missing.push({\n resource: r,\n field,\n setKey: `${pluginName}.${r.resourceKey}.${field}`,\n });\n }\n }\n return missing;\n}\n\n/** Fields that become bundle variables: manifest fields plus binding var fields. */\nfunction variableFields(r: ManifestResource): string[] {\n const out = fieldNames(r).filter(\n (f) => !r.fields?.[f].bundleIgnore && !r.fields?.[f].localOnly,\n );\n const covered = new Set(fieldNames(r));\n for (const f of bindingVarFields(r)) {\n if (!covered.has(f)) out.push(f);\n }\n return out;\n}\n\nfunction varName(r: ManifestResource, field: string): string {\n return `${r.resourceKey.replaceAll(\"-\", \"_\")}_${field}`;\n}\n\nexport interface AddPlan extends ConfigPlan {\n /** .env lines to add (skipped later when the name is already present). */\n dotEnv: { env: string; value: string }[];\n}\n\n/** The file changes for the resources, as the CLI generator: OBO-only gets a literal value, no binding. */\nexport function buildAddPlan(\n plugin: ManifestPlugin,\n resources: ManifestResource[],\n values: Record<string, string>,\n modes: Record<string, AuthMode>,\n): AddPlan {\n const dotEnv: AddPlan[\"dotEnv\"] = [];\n const appYamlEnv: AppYamlEnvEntry[] = [];\n const bundleVariables: BundleVariable[] = [];\n const resourceBindings: ResourceBinding[] = [];\n const unverifiedTypes: string[] = [];\n const scopes: string[] = [];\n\n for (const r of resources) {\n const mode = modes[authKey(r)];\n const oboOnly = mode === AUTH_MODE_OBO;\n if ((mode === AUTH_MODE_OBO || mode === AUTH_MODE_BOTH) && r.scope) {\n scopes.push(r.scope);\n }\n\n for (const f of fieldNames(r)) {\n const field = r.fields?.[f] ?? {};\n if (!field.env || !isValidEnvName(field.env)) continue;\n const value = (values[valueKey(r, f)] || field.value || \"\").replace(\n /[\\r\\n]/g,\n \"\",\n );\n dotEnv.push({ env: field.env, value });\n if (field.localOnly) continue;\n appYamlEnv.push(\n oboOnly\n ? { name: field.env, value }\n : { name: field.env, valueFrom: r.resourceKey },\n );\n }\n\n if (oboOnly) continue;\n const binding = bindingOf(r);\n if (!binding) {\n unverifiedTypes.push(r.type);\n continue;\n }\n for (const f of variableFields(r)) {\n bundleVariables.push({\n name: varName(r, f),\n description: r.fields?.[f]?.description || r.description,\n value: values[valueKey(r, f)] || r.fields?.[f]?.value || undefined,\n });\n }\n const fields: Record<string, string> = {};\n for (const [mf, yf] of binding.varFields) {\n fields[yf] = `\\${var.${varName(r, mf)}}`;\n }\n for (const [yf, v] of binding.staticFields ?? []) fields[yf] = v;\n resourceBindings.push({\n name: r.resourceKey,\n type: binding.yamlKey,\n permission: r.permission,\n fields,\n });\n }\n\n // Plugin scopes (e.g. genie) cover always-OBO routes, whatever the resources' mode.\n scopes.push(...(plugin.scopes ?? []));\n return {\n dotEnv,\n appYamlEnv,\n bundleVariables,\n resourceBindings,\n unverifiedTypes,\n userApiScopes: [...new Set(scopes)],\n };\n}\n"],"mappings":";;;;AAOA,MA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AExC,OAAK,MAAM,CAAC,IAAI,MAAM,QAAQ,gBAAgB,EAAE,CAAE,QAAO,MAAM;AAC/D,mBAAiB,KAAK;GACpB,MAAM,EAAE;GACR,MAAM,QAAQ;GACd,YAAY,EAAE;GACd;GACD,CAAC;;AAIJ,QAAO,KAAK,GAAI,OAAO,UAAU,EAAE,CAAE;AACrC,QAAO;EACL;EACA;EACA;EACA;EACA;EACA,eAAe,CAAC,GAAG,IAAI,IAAI,OAAO,CAAC;EACpC"}
@@ -0,0 +1,45 @@
1
+ //#region src/cli/commands/plugin/add/resolve.ts
2
+ /** Values for `postgres:*` resolver fields, as the Databricks CLI's ResolvePostgresValues. */
3
+ async function resolveDerivedValues(r, values, profile) {
4
+ const branch = values[`${r.resourceKey}.branch`];
5
+ const database = values[`${r.resourceKey}.database`];
6
+ const needs = Object.entries(r.fields ?? {}).some(([name, f]) => f.resolve?.startsWith("postgres:") && !values[`${r.resourceKey}.${name}`]);
7
+ if (r.type !== "postgres" || !needs || !branch) return {};
8
+ const { makeWorkspaceClient } = await import("../../registry/workspace-picker.js");
9
+ const pg = makeWorkspaceClient(profile).postgres;
10
+ const resolved = {};
11
+ for await (const ep of pg.listEndpointsIter({ parent: branch })) {
12
+ if (ep.status?.endpointType !== "ENDPOINT_TYPE_READ_WRITE") continue;
13
+ if (ep.name) resolved["postgres:endpointPath"] = ep.name;
14
+ if (ep.status.hosts?.host) resolved["postgres:host"] = ep.status.hosts.host;
15
+ break;
16
+ }
17
+ if (database) for await (const db of pg.listDatabasesIter({ parent: branch })) {
18
+ if (db.name !== database) continue;
19
+ if (db.status?.postgresDatabase) resolved["postgres:databaseName"] = db.status.postgresDatabase;
20
+ break;
21
+ }
22
+ const out = {};
23
+ for (const [name, field] of Object.entries(r.fields ?? {})) {
24
+ const v = field.resolve && resolved[field.resolve];
25
+ if (v) out[`${r.resourceKey}.${name}`] = v;
26
+ }
27
+ return out;
28
+ }
29
+ /** An AI Search index's synced source columns, minus embedding vectors. */
30
+ async function discoverIndexColumns(indexName, profile) {
31
+ const { makeWorkspaceClient } = await import("../../registry/workspace-picker.js");
32
+ const client = makeWorkspaceClient(profile);
33
+ const index = await client.vectorSearch.getVectorIndex({ name: indexName });
34
+ const spec = index.indexSpec?.$case === "deltaSyncIndexSpec" ? index.indexSpec.deltaSyncIndexSpec : void 0;
35
+ if (!spec?.sourceTable) throw new Error(`index ${indexName} has no Delta Sync source table`);
36
+ const excluded = new Set(spec.embeddingVectorColumns?.map((c) => c.name));
37
+ const table = await client.tables.getTable({ fullNameArg: spec.sourceTable });
38
+ const subset = spec.columnsToSync?.length ? spec.columnsToSync : spec.columnsToIndex;
39
+ const synced = subset?.length ? new Set(subset) : void 0;
40
+ return (table.columns ?? []).flatMap((c) => c.name && !excluded.has(c.name) && (!synced || synced.has(c.name)) ? [c.name] : []);
41
+ }
42
+
43
+ //#endregion
44
+ export { discoverIndexColumns, resolveDerivedValues };
45
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.js","names":[],"sources":["../../../../../src/cli/commands/plugin/add/resolve.ts"],"sourcesContent":["import type { ManifestResource } from \"./plan\";\n\n/** Values for `postgres:*` resolver fields, as the Databricks CLI's ResolvePostgresValues. */\nexport async function resolveDerivedValues(\n r: ManifestResource,\n values: Record<string, string>,\n profile: string | undefined,\n): Promise<Record<string, string>> {\n const branch = values[`${r.resourceKey}.branch`];\n const database = values[`${r.resourceKey}.database`];\n const needs = Object.entries(r.fields ?? {}).some(\n ([name, f]) =>\n f.resolve?.startsWith(\"postgres:\") && !values[`${r.resourceKey}.${name}`],\n );\n if (r.type !== \"postgres\" || !needs || !branch) return {};\n\n const { makeWorkspaceClient } =\n await import(\"../../registry/workspace-picker.js\");\n const pg = makeWorkspaceClient(profile).postgres;\n const resolved: Record<string, string> = {};\n for await (const ep of pg.listEndpointsIter({ parent: branch })) {\n if (ep.status?.endpointType !== \"ENDPOINT_TYPE_READ_WRITE\") continue;\n if (ep.name) resolved[\"postgres:endpointPath\"] = ep.name;\n if (ep.status.hosts?.host) resolved[\"postgres:host\"] = ep.status.hosts.host;\n break;\n }\n if (database) {\n for await (const db of pg.listDatabasesIter({ parent: branch })) {\n if (db.name !== database) continue;\n if (db.status?.postgresDatabase) {\n resolved[\"postgres:databaseName\"] = db.status.postgresDatabase;\n }\n break;\n }\n }\n\n const out: Record<string, string> = {};\n for (const [name, field] of Object.entries(r.fields ?? {})) {\n const v = field.resolve && resolved[field.resolve];\n if (v) out[`${r.resourceKey}.${name}`] = v;\n }\n return out;\n}\n\n/** An AI Search index's synced source columns, minus embedding vectors. */\nexport async function discoverIndexColumns(\n indexName: string,\n profile: string | undefined,\n): Promise<string[]> {\n const { makeWorkspaceClient } =\n await import(\"../../registry/workspace-picker.js\");\n const client = makeWorkspaceClient(profile);\n const index = await client.vectorSearch.getVectorIndex({ name: indexName });\n const spec =\n index.indexSpec?.$case === \"deltaSyncIndexSpec\"\n ? index.indexSpec.deltaSyncIndexSpec\n : undefined;\n if (!spec?.sourceTable) {\n throw new Error(`index ${indexName} has no Delta Sync source table`);\n }\n const excluded = new Set(spec.embeddingVectorColumns?.map((c) => c.name));\n const table = await client.tables.getTable({ fullNameArg: spec.sourceTable });\n // columnsToIndex is the response's alias of columnsToSync.\n const subset = spec.columnsToSync?.length\n ? spec.columnsToSync\n : spec.columnsToIndex;\n const synced = subset?.length ? new Set(subset) : undefined;\n return (table.columns ?? []).flatMap((c) =>\n c.name && !excluded.has(c.name) && (!synced || synced.has(c.name))\n ? [c.name]\n : [],\n );\n}\n"],"mappings":";;AAGA,eAAsB,qBACpB,GACA,QACA,SACiC;CACjC,MAAM,SAAS,OAAO,GAAG,EAAE,YAAY;CACvC,MAAM,WAAW,OAAO,GAAG,EAAE,YAAY;CACzC,MAAM,QAAQ,OAAO,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC,MAC1C,CAAC,MAAM,OACN,EAAE,SAAS,WAAW,YAAY,IAAI,CAAC,OAAO,GAAG,EAAE,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AO,SAAS,EAAE,aAAa,KAAK,aAAa,CAAC;CAE7E,MAAM,SAAS,KAAK,eAAe,SAC/B,KAAK,gBACL,KAAK;CACT,MAAM,SAAS,QAAQ,SAAS,IAAI,IAAI,OAAO,GAAG;AAClD,SAAQ,MAAM,WAAW,EAAE,EAAE,SAAS,MACpC,EAAE,QAAQ,CAAC,SAAS,IAAI,EAAE,KAAK,KAAK,CAAC,UAAU,OAAO,IAAI,EAAE,KAAK,IAC7D,CAAC,EAAE,KAAK,GACR,EAAE,CACP"}
@@ -37,6 +37,10 @@ const DEFAULT_FIELDS_BY_TYPE = {
37
37
  env: "DATABRICKS_SERVING_ENDPOINT_ID",
38
38
  description: "Serving endpoint ID"
39
39
  } },
40
+ model_service: { name: {
41
+ env: "DATABRICKS_MODEL_SERVICE_NAME",
42
+ description: "Model service full name (catalog.schema.name)"
43
+ } },
40
44
  volume: { name: {
41
45
  env: "VOLUME_NAME",
42
46
  description: "Volume name"
@@ -1 +1 @@
1
- {"version":3,"file":"resource-defaults.js","names":[],"sources":["../../../../../src/cli/commands/plugin/create/resource-defaults.ts"],"sourcesContent":["/**\n * Resource type and permission defaults for plugin scaffolding.\n * Values are sourced from the canonical Zod schemas in `schemas/manifest`,\n * surfaced through the `schema-resources` module.\n */\n\nimport {\n getResourceTypeOptions,\n getResourceTypePermissions,\n type ResourceTypeOption,\n} from \"../schema-resources\";\n\nexport const MANIFEST_SCHEMA_ID =\n \"https://databricks.github.io/appkit/schemas/plugin-manifest.schema.json\";\n\nexport type { ResourceTypeOption };\n\n/** Resource types from schema resourceType enum (value, human label). */\nexport const RESOURCE_TYPE_OPTIONS: ResourceTypeOption[] =\n getResourceTypeOptions();\n\n/** All valid permissions per resource type, from schema allOf/if-then rules. */\nexport const PERMISSIONS_BY_TYPE: Record<string, string[]> =\n getResourceTypePermissions();\n\n/** Default (first) permission per resource type for scaffolding. */\nexport const DEFAULT_PERMISSION_BY_TYPE: Record<string, string> =\n Object.fromEntries(\n Object.entries(PERMISSIONS_BY_TYPE).map(([type, perms]) => [\n type,\n perms[0],\n ]),\n );\n\n/** Default fields per resource type: field key -> { env, description }. */\nexport const DEFAULT_FIELDS_BY_TYPE: Record<\n string,\n Record<string, { env: string; description?: string }>\n> = {\n sql_warehouse: {\n id: { env: \"DATABRICKS_WAREHOUSE_ID\", description: \"SQL Warehouse ID\" },\n },\n secret: {\n scope: { env: \"SECRET_SCOPE\", description: \"Secret scope name\" },\n key: { env: \"SECRET_KEY\", description: \"Secret key\" },\n },\n job: {\n id: { env: \"DATABRICKS_JOB_ID\", description: \"Job ID\" },\n },\n serving_endpoint: {\n id: {\n env: \"DATABRICKS_SERVING_ENDPOINT_ID\",\n description: \"Serving endpoint ID\",\n },\n },\n volume: {\n name: { env: \"VOLUME_NAME\", description: \"Volume name\" },\n },\n vector_search_index: {\n endpoint_name: {\n env: \"VECTOR_SEARCH_ENDPOINT_NAME\",\n description: \"Vector search endpoint name\",\n },\n index_name: {\n env: \"VECTOR_SEARCH_INDEX_NAME\",\n description: \"Vector search index name\",\n },\n },\n uc_function: {\n name: {\n env: \"UC_FUNCTION_NAME\",\n description: \"Unity Catalog function name\",\n },\n },\n uc_connection: {\n name: {\n env: \"UC_CONNECTION_NAME\",\n description: \"Unity Catalog connection name\",\n },\n },\n database: {\n instance_name: {\n env: \"DATABRICKS_INSTANCE_NAME\",\n description: \"Databricks instance name\",\n },\n database_name: {\n env: \"DATABASE_NAME\",\n description: \"Database name\",\n },\n },\n genie_space: {\n id: { env: \"GENIE_SPACE_ID\", description: \"Genie Space ID\" },\n },\n experiment: {\n id: { env: \"MLFLOW_EXPERIMENT_ID\", description: \"MLflow experiment ID\" },\n },\n app: {\n id: { env: \"DATABRICKS_APP_ID\", description: \"Databricks App ID\" },\n },\n};\n\n/** Valid resource type values from the schema. */\nexport function getValidResourceTypes(): string[] {\n return RESOURCE_TYPE_OPTIONS.map((o) => o.value);\n}\n\n/** Humanized alias from resource type (e.g. sql_warehouse -> \"SQL Warehouse\"). */\nexport function humanizeResourceType(type: string): string {\n const option = RESOURCE_TYPE_OPTIONS.find((o) => o.value === type);\n return option ? option.label : type.replace(/_/g, \" \");\n}\n\n/** Kebab-case resource key from type (e.g. sql_warehouse -> \"sql-warehouse\"). */\nexport function resourceKeyFromType(type: string): string {\n return type.replace(/_/g, \"-\");\n}\n\n/** Get default fields for a resource type; fallback to single id field. */\nexport function getDefaultFieldsForType(\n type: string,\n): Record<string, { env: string; description?: string }> {\n const known = DEFAULT_FIELDS_BY_TYPE[type];\n if (known) return known;\n const key = resourceKeyFromType(type);\n const envName = `DATABRICKS_${key.toUpperCase().replace(/-/g, \"_\")}_ID`;\n return {\n id: { env: envName, description: `${humanizeResourceType(type)} ID` },\n };\n}\n"],"mappings":";;;;;;;;AAYA,MAAa,qBACX;;AAKF,MAAa,wBACX,wBAAwB;;AAG1B,MAAa,sBACX,4BAA4B;;AAG9B,MAAa,6BACX,OAAO,YACL,OAAO,QAAQ,oBAAoB,CAAC,KAAK,CAAC,MAAM,WAAW,CACzD,MACA,MAAM,GACP,CAAC,CACH;;AAGH,MAAa,yBAGT;CACF,eAAe,EACb,IAAI;EAAE,KAAK;EAA2B,aAAa;EAAoB,EACxE;CACD,QAAQ;EACN,OAAO;GAAE,KAAK;GAAgB,aAAa;GAAqB;EAChE,KAAK;GAAE,KAAK;GAAc,aAAa;GAAc;EACtD;CACD,KAAK,EACH,IAAI;EAAE,KAAK;EAAqB,aAAa;EAAU,EACxD;CACD,kBAAkB,EAChB,IAAI;EACF,KAAK;EACL,aAAa;EACd,EACF;CACD,QAAQ,EACN,MAAM;EAAE,KAAK;EAAe,aAAa;EAAe,EACzD;CACD,qBAAqB;EACnB,eAAe;GACb,KAAK;GACL,aAAa;GACd;EACD,YAAY;GACV,KAAK;GACL,aAAa;GACd;EACF;CACD,aAAa,EACX,MAAM;EACJ,KAAK;EACL,aAAa;EACd,EACF;CACD,eAAe,EACb,MAAM;EACJ,KAAK;EACL,aAAa;EACd,EACF;CACD,UAAU;EACR,eAAe;GACb,KAAK;GACL,aAAa;GACd;EACD,eAAe;GACb,KAAK;GACL,aAAa;GACd;EACF;CACD,aAAa,EACX,IAAI;EAAE,KAAK;EAAkB,aAAa;EAAkB,EAC7D;CACD,YAAY,EACV,IAAI;EAAE,KAAK;EAAwB,aAAa;EAAwB,EACzE;CACD,KAAK,EACH,IAAI;EAAE,KAAK;EAAqB,aAAa;EAAqB,EACnE;CACF;;AAGD,SAAgB,wBAAkC;AAChD,QAAO,sBAAsB,KAAK,MAAM,EAAE,MAAM;;;AAIlD,SAAgB,qBAAqB,MAAsB;CACzD,MAAM,SAAS,sBAAsB,MAAM,MAAM,EAAE,UAAU,KAAK;AAClE,QAAO,SAAS,OAAO,QAAQ,KAAK,QAAQ,MAAM,IAAI;;;AAIxD,SAAgB,oBAAoB,MAAsB;AACxD,QAAO,KAAK,QAAQ,MAAM,IAAI;;;AAIhC,SAAgB,wBACd,MACuD;CACvD,MAAM,QAAQ,uBAAuB;AACrC,KAAI,MAAO,QAAO;AAGlB,QAAO,EACL,IAAI;EAAE,KAFQ,cADJ,oBAAoB,KAAK,CACH,aAAa,CAAC,QAAQ,MAAM,IAAI,CAAC;EAE7C,aAAa,GAAG,qBAAqB,KAAK,CAAC;EAAM,EACtE"}
1
+ {"version":3,"file":"resource-defaults.js","names":[],"sources":["../../../../../src/cli/commands/plugin/create/resource-defaults.ts"],"sourcesContent":["/**\n * Resource type and permission defaults for plugin scaffolding.\n * Values are sourced from the canonical Zod schemas in `schemas/manifest`,\n * surfaced through the `schema-resources` module.\n */\n\nimport {\n getResourceTypeOptions,\n getResourceTypePermissions,\n type ResourceTypeOption,\n} from \"../schema-resources\";\n\nexport const MANIFEST_SCHEMA_ID =\n \"https://databricks.github.io/appkit/schemas/plugin-manifest.schema.json\";\n\nexport type { ResourceTypeOption };\n\n/** Resource types from schema resourceType enum (value, human label). */\nexport const RESOURCE_TYPE_OPTIONS: ResourceTypeOption[] =\n getResourceTypeOptions();\n\n/** All valid permissions per resource type, from schema allOf/if-then rules. */\nexport const PERMISSIONS_BY_TYPE: Record<string, string[]> =\n getResourceTypePermissions();\n\n/** Default (first) permission per resource type for scaffolding. */\nexport const DEFAULT_PERMISSION_BY_TYPE: Record<string, string> =\n Object.fromEntries(\n Object.entries(PERMISSIONS_BY_TYPE).map(([type, perms]) => [\n type,\n perms[0],\n ]),\n );\n\n/** Default fields per resource type: field key -> { env, description }. */\nexport const DEFAULT_FIELDS_BY_TYPE: Record<\n string,\n Record<string, { env: string; description?: string }>\n> = {\n sql_warehouse: {\n id: { env: \"DATABRICKS_WAREHOUSE_ID\", description: \"SQL Warehouse ID\" },\n },\n secret: {\n scope: { env: \"SECRET_SCOPE\", description: \"Secret scope name\" },\n key: { env: \"SECRET_KEY\", description: \"Secret key\" },\n },\n job: {\n id: { env: \"DATABRICKS_JOB_ID\", description: \"Job ID\" },\n },\n serving_endpoint: {\n id: {\n env: \"DATABRICKS_SERVING_ENDPOINT_ID\",\n description: \"Serving endpoint ID\",\n },\n },\n model_service: {\n name: {\n env: \"DATABRICKS_MODEL_SERVICE_NAME\",\n description: \"Model service full name (catalog.schema.name)\",\n },\n },\n volume: {\n name: { env: \"VOLUME_NAME\", description: \"Volume name\" },\n },\n vector_search_index: {\n endpoint_name: {\n env: \"VECTOR_SEARCH_ENDPOINT_NAME\",\n description: \"Vector search endpoint name\",\n },\n index_name: {\n env: \"VECTOR_SEARCH_INDEX_NAME\",\n description: \"Vector search index name\",\n },\n },\n uc_function: {\n name: {\n env: \"UC_FUNCTION_NAME\",\n description: \"Unity Catalog function name\",\n },\n },\n uc_connection: {\n name: {\n env: \"UC_CONNECTION_NAME\",\n description: \"Unity Catalog connection name\",\n },\n },\n database: {\n instance_name: {\n env: \"DATABRICKS_INSTANCE_NAME\",\n description: \"Databricks instance name\",\n },\n database_name: {\n env: \"DATABASE_NAME\",\n description: \"Database name\",\n },\n },\n genie_space: {\n id: { env: \"GENIE_SPACE_ID\", description: \"Genie Space ID\" },\n },\n experiment: {\n id: { env: \"MLFLOW_EXPERIMENT_ID\", description: \"MLflow experiment ID\" },\n },\n app: {\n id: { env: \"DATABRICKS_APP_ID\", description: \"Databricks App ID\" },\n },\n};\n\n/** Valid resource type values from the schema. */\nexport function getValidResourceTypes(): string[] {\n return RESOURCE_TYPE_OPTIONS.map((o) => o.value);\n}\n\n/** Humanized alias from resource type (e.g. sql_warehouse -> \"SQL Warehouse\"). */\nexport function humanizeResourceType(type: string): string {\n const option = RESOURCE_TYPE_OPTIONS.find((o) => o.value === type);\n return option ? option.label : type.replace(/_/g, \" \");\n}\n\n/** Kebab-case resource key from type (e.g. sql_warehouse -> \"sql-warehouse\"). */\nexport function resourceKeyFromType(type: string): string {\n return type.replace(/_/g, \"-\");\n}\n\n/** Get default fields for a resource type; fallback to single id field. */\nexport function getDefaultFieldsForType(\n type: string,\n): Record<string, { env: string; description?: string }> {\n const known = DEFAULT_FIELDS_BY_TYPE[type];\n if (known) return known;\n const key = resourceKeyFromType(type);\n const envName = `DATABRICKS_${key.toUpperCase().replace(/-/g, \"_\")}_ID`;\n return {\n id: { env: envName, description: `${humanizeResourceType(type)} ID` },\n };\n}\n"],"mappings":";;;;;;;;AAYA,MAAa,qBACX;;AAKF,MAAa,wBACX,wBAAwB;;AAG1B,MAAa,sBACX,4BAA4B;;AAG9B,MAAa,6BACX,OAAO,YACL,OAAO,QAAQ,oBAAoB,CAAC,KAAK,CAAC,MAAM,WAAW,CACzD,MACA,MAAM,GACP,CAAC,CACH;;AAGH,MAAa,yBAGT;CACF,eAAe,EACb,IAAI;EAAE,KAAK;EAA2B,aAAa;EAAoB,EACxE;CACD,QAAQ;EACN,OAAO;GAAE,KAAK;GAAgB,aAAa;GAAqB;EAChE,KAAK;GAAE,KAAK;GAAc,aAAa;GAAc;EACtD;CACD,KAAK,EACH,IAAI;EAAE,KAAK;EAAqB,aAAa;EAAU,EACxD;CACD,kBAAkB,EAChB,IAAI;EACF,KAAK;EACL,aAAa;EACd,EACF;CACD,eAAe,EACb,MAAM;EACJ,KAAK;EACL,aAAa;EACd,EACF;CACD,QAAQ,EACN,MAAM;EAAE,KAAK;EAAe,aAAa;EAAe,EACzD;CACD,qBAAqB;EACnB,eAAe;GACb,KAAK;GACL,aAAa;GACd;EACD,YAAY;GACV,KAAK;GACL,aAAa;GACd;EACF;CACD,aAAa,EACX,MAAM;EACJ,KAAK;EACL,aAAa;EACd,EACF;CACD,eAAe,EACb,MAAM;EACJ,KAAK;EACL,aAAa;EACd,EACF;CACD,UAAU;EACR,eAAe;GACb,KAAK;GACL,aAAa;GACd;EACD,eAAe;GACb,KAAK;GACL,aAAa;GACd;EACF;CACD,aAAa,EACX,IAAI;EAAE,KAAK;EAAkB,aAAa;EAAkB,EAC7D;CACD,YAAY,EACV,IAAI;EAAE,KAAK;EAAwB,aAAa;EAAwB,EACzE;CACD,KAAK,EACH,IAAI;EAAE,KAAK;EAAqB,aAAa;EAAqB,EACnE;CACF;;AAGD,SAAgB,wBAAkC;AAChD,QAAO,sBAAsB,KAAK,MAAM,EAAE,MAAM;;;AAIlD,SAAgB,qBAAqB,MAAsB;CACzD,MAAM,SAAS,sBAAsB,MAAM,MAAM,EAAE,UAAU,KAAK;AAClE,QAAO,SAAS,OAAO,QAAQ,KAAK,QAAQ,MAAM,IAAI;;;AAIxD,SAAgB,oBAAoB,MAAsB;AACxD,QAAO,KAAK,QAAQ,MAAM,IAAI;;;AAIhC,SAAgB,wBACd,MACuD;CACvD,MAAM,QAAQ,uBAAuB;AACrC,KAAI,MAAO,QAAO;AAGlB,QAAO,EACL,IAAI;EAAE,KAFQ,cADJ,oBAAoB,KAAK,CACH,aAAa,CAAC,QAAQ,MAAM,IAAI,CAAC;EAE7C,aAAa,GAAG,qBAAqB,KAAK,CAAC;EAAM,EACtE"}
@@ -1,4 +1,5 @@
1
1
  import { pluginAddResourceCommand } from "./add-resource/add-resource.js";
2
+ import { pluginAddCommand } from "./add/add.js";
2
3
  import { pluginCreateCommand } from "./create/create.js";
3
4
  import { pluginListCommand } from "./list/list.js";
4
5
  import { pluginsSyncCommand } from "./sync/sync.js";
@@ -14,15 +15,17 @@ import { Command } from "commander";
14
15
  * - create: Scaffold a new plugin (interactive)
15
16
  * - validate: Validate manifest(s) against the JSON schema
16
17
  * - list: List plugins from appkit.plugins.json or a directory
18
+ * - add: Add a plugin to the app (server, .env, app.yaml, databricks.yml)
17
19
  * - add-resource: Add a resource requirement to a plugin manifest (interactive)
18
20
  * - promote: Promote a plugin to a higher stability tier
19
21
  */
20
- const pluginCommand = new Command("plugin").description("Plugin management commands").addCommand(pluginsSyncCommand).addCommand(pluginCreateCommand).addCommand(pluginValidateCommand).addCommand(pluginListCommand).addCommand(pluginAddResourceCommand).addCommand(pluginPromoteCommand).addHelpText("after", `
22
+ const pluginCommand = new Command("plugin").description("Plugin management commands").addCommand(pluginsSyncCommand).addCommand(pluginCreateCommand).addCommand(pluginValidateCommand).addCommand(pluginListCommand).addCommand(pluginAddCommand).addCommand(pluginAddResourceCommand).addCommand(pluginPromoteCommand).addHelpText("after", `
21
23
  Examples:
22
24
  $ appkit plugin sync --write
23
25
  $ appkit plugin create --placement in-repo --path plugins/my-plugin --name my-plugin --description "Does X"
24
26
  $ appkit plugin validate .
25
27
  $ appkit plugin list --json
28
+ $ appkit plugin add analytics --auth-mode obo --set analytics.sql-warehouse.id=abc123
26
29
  $ appkit plugin add-resource --path plugins/my-plugin --type sql_warehouse
27
30
  $ appkit plugin promote my-plugin --to ga`);
28
31
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../src/cli/commands/plugin/index.ts"],"sourcesContent":["import { Command } from \"commander\";\n\nimport { pluginAddResourceCommand } from \"./add-resource/add-resource\";\nimport { pluginCreateCommand } from \"./create/create\";\nimport { pluginListCommand } from \"./list/list\";\nimport { pluginPromoteCommand } from \"./promote/promote\";\nimport { pluginsSyncCommand } from \"./sync/sync\";\nimport { pluginValidateCommand } from \"./validate/validate\";\n\n/**\n * Parent command for plugin management operations.\n * Subcommands:\n * - sync: Aggregate plugin manifests into appkit.plugins.json\n * - create: Scaffold a new plugin (interactive)\n * - validate: Validate manifest(s) against the JSON schema\n * - list: List plugins from appkit.plugins.json or a directory\n * - add-resource: Add a resource requirement to a plugin manifest (interactive)\n * - promote: Promote a plugin to a higher stability tier\n */\nexport const pluginCommand = new Command(\"plugin\")\n .description(\"Plugin management commands\")\n .addCommand(pluginsSyncCommand)\n .addCommand(pluginCreateCommand)\n .addCommand(pluginValidateCommand)\n .addCommand(pluginListCommand)\n .addCommand(pluginAddResourceCommand)\n .addCommand(pluginPromoteCommand)\n .addHelpText(\n \"after\",\n `\nExamples:\n $ appkit plugin sync --write\n $ appkit plugin create --placement in-repo --path plugins/my-plugin --name my-plugin --description \"Does X\"\n $ appkit plugin validate .\n $ appkit plugin list --json\n $ appkit plugin add-resource --path plugins/my-plugin --type sql_warehouse\n $ appkit plugin promote my-plugin --to ga`,\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,MAAa,gBAAgB,IAAI,QAAQ,SAAS,CAC/C,YAAY,6BAA6B,CACzC,WAAW,mBAAmB,CAC9B,WAAW,oBAAoB,CAC/B,WAAW,sBAAsB,CACjC,WAAW,kBAAkB,CAC7B,WAAW,yBAAyB,CACpC,WAAW,qBAAqB,CAChC,YACC,SACA;;;;;;;6CAQD"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../src/cli/commands/plugin/index.ts"],"sourcesContent":["import { Command } from \"commander\";\n\nimport { pluginAddResourceCommand } from \"./add-resource/add-resource\";\nimport { pluginAddCommand } from \"./add/add\";\nimport { pluginCreateCommand } from \"./create/create\";\nimport { pluginListCommand } from \"./list/list\";\nimport { pluginPromoteCommand } from \"./promote/promote\";\nimport { pluginsSyncCommand } from \"./sync/sync\";\nimport { pluginValidateCommand } from \"./validate/validate\";\n\n/**\n * Parent command for plugin management operations.\n * Subcommands:\n * - sync: Aggregate plugin manifests into appkit.plugins.json\n * - create: Scaffold a new plugin (interactive)\n * - validate: Validate manifest(s) against the JSON schema\n * - list: List plugins from appkit.plugins.json or a directory\n * - add: Add a plugin to the app (server, .env, app.yaml, databricks.yml)\n * - add-resource: Add a resource requirement to a plugin manifest (interactive)\n * - promote: Promote a plugin to a higher stability tier\n */\nexport const pluginCommand = new Command(\"plugin\")\n .description(\"Plugin management commands\")\n .addCommand(pluginsSyncCommand)\n .addCommand(pluginCreateCommand)\n .addCommand(pluginValidateCommand)\n .addCommand(pluginListCommand)\n .addCommand(pluginAddCommand)\n .addCommand(pluginAddResourceCommand)\n .addCommand(pluginPromoteCommand)\n .addHelpText(\n \"after\",\n `\nExamples:\n $ appkit plugin sync --write\n $ appkit plugin create --placement in-repo --path plugins/my-plugin --name my-plugin --description \"Does X\"\n $ appkit plugin validate .\n $ appkit plugin list --json\n $ appkit plugin add analytics --auth-mode obo --set analytics.sql-warehouse.id=abc123\n $ appkit plugin add-resource --path plugins/my-plugin --type sql_warehouse\n $ appkit plugin promote my-plugin --to ga`,\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,gBAAgB,IAAI,QAAQ,SAAS,CAC/C,YAAY,6BAA6B,CACzC,WAAW,mBAAmB,CAC9B,WAAW,oBAAoB,CAC/B,WAAW,sBAAsB,CACjC,WAAW,kBAAkB,CAC7B,WAAW,iBAAiB,CAC5B,WAAW,yBAAyB,CACpC,WAAW,qBAAqB,CAChC,YACC,SACA;;;;;;;;6CASD"}
@@ -1,4 +1,4 @@
1
- import { appPermissionSchema, databasePermissionSchema, experimentPermissionSchema, genieSpacePermissionSchema, jobPermissionSchema, postgresPermissionSchema, resourceTypeSchema, secretPermissionSchema, servingEndpointPermissionSchema, sqlWarehousePermissionSchema, ucConnectionPermissionSchema, ucFunctionPermissionSchema, vectorSearchIndexPermissionSchema, volumePermissionSchema } from "../../../schemas/manifest.js";
1
+ import { appPermissionSchema, databasePermissionSchema, experimentPermissionSchema, genieSpacePermissionSchema, jobPermissionSchema, modelServicePermissionSchema, postgresPermissionSchema, resourceTypeSchema, secretPermissionSchema, servingEndpointPermissionSchema, sqlWarehousePermissionSchema, ucConnectionPermissionSchema, ucFunctionPermissionSchema, vectorSearchIndexPermissionSchema, volumePermissionSchema } from "../../../schemas/manifest.js";
2
2
 
3
3
  //#region src/cli/commands/plugin/schema-resources.ts
4
4
  /**
@@ -30,6 +30,7 @@ const PERMISSION_SCHEMAS_BY_TYPE = {
30
30
  job: jobPermissionSchema,
31
31
  sql_warehouse: sqlWarehousePermissionSchema,
32
32
  serving_endpoint: servingEndpointPermissionSchema,
33
+ model_service: modelServicePermissionSchema,
33
34
  volume: volumePermissionSchema,
34
35
  vector_search_index: vectorSearchIndexPermissionSchema,
35
36
  uc_function: ucFunctionPermissionSchema,
@@ -1 +1 @@
1
- {"version":3,"file":"schema-resources.js","names":[],"sources":["../../../../src/cli/commands/plugin/schema-resources.ts"],"sourcesContent":["/**\n * Resource types and permissions sourced from the canonical Zod schemas in\n * `schemas/manifest.ts`. Single source of truth so create, add-resource, and\n * validate stay in sync with the schema.\n *\n * Values are constant at module load (direct Zod imports, no runtime JSON-schema\n * read), so no caching is needed.\n */\nimport {\n appPermissionSchema,\n databasePermissionSchema,\n experimentPermissionSchema,\n genieSpacePermissionSchema,\n jobPermissionSchema,\n postgresPermissionSchema,\n resourceTypeSchema,\n secretPermissionSchema,\n servingEndpointPermissionSchema,\n sqlWarehousePermissionSchema,\n ucConnectionPermissionSchema,\n ucFunctionPermissionSchema,\n vectorSearchIndexPermissionSchema,\n volumePermissionSchema,\n} from \"../../../schemas/manifest\";\n\nexport interface ResourceTypeOption {\n value: string;\n label: string;\n}\n\n/** Optional display overrides for acronyms (e.g. SQL, UC). Omitted entries use title-case of value. */\nconst LABEL_OVERRIDES: Record<string, string> = {\n sql_warehouse: \"SQL Warehouse\",\n uc_function: \"UC Function\",\n uc_connection: \"UC Connection\",\n};\n\nfunction humanize(value: string): string {\n if (LABEL_OVERRIDES[value]) return LABEL_OVERRIDES[value];\n return value.replace(/_/g, \" \").replace(/\\b\\w/g, (c) => c.toUpperCase());\n}\n\n/**\n * Map from resource type literal to its permission enum schema. Mirrors the\n * `allOf + if/then` block in the previous hand-written JSON Schema, but driven\n * directly from the Zod source. Add an entry here when extending\n * `resourceTypeSchema`.\n */\nconst PERMISSION_SCHEMAS_BY_TYPE = {\n secret: secretPermissionSchema,\n job: jobPermissionSchema,\n sql_warehouse: sqlWarehousePermissionSchema,\n serving_endpoint: servingEndpointPermissionSchema,\n volume: volumePermissionSchema,\n vector_search_index: vectorSearchIndexPermissionSchema,\n uc_function: ucFunctionPermissionSchema,\n uc_connection: ucConnectionPermissionSchema,\n database: databasePermissionSchema,\n postgres: postgresPermissionSchema,\n genie_space: genieSpacePermissionSchema,\n experiment: experimentPermissionSchema,\n app: appPermissionSchema,\n} as const;\n\n/**\n * Resource type options (value + label) from `resourceTypeSchema.options`.\n */\nexport function getResourceTypeOptions(): ResourceTypeOption[] {\n return resourceTypeSchema.options.map((value) => ({\n value,\n label: humanize(value),\n }));\n}\n\n/**\n * Permissions per resource type, derived from each type's per-type permission\n * schema's `.options` array. Order is weakest-to-strongest (matches Zod enum\n * declaration order, which the original JSON Schema also preserved).\n */\nexport function getResourceTypePermissions(): Record<string, string[]> {\n const out: Record<string, string[]> = {};\n for (const [type, schema] of Object.entries(PERMISSION_SCHEMAS_BY_TYPE)) {\n out[type] = [...schema.options];\n }\n return out;\n}\n"],"mappings":";;;;;;;;;;;;AA+BA,MAAM,kBAA0C;CAC9C,eAAe;CACf,aAAa;CACb,eAAe;CAChB;AAED,SAAS,SAAS,OAAuB;AACvC,KAAI,gBAAgB,OAAQ,QAAO,gBAAgB;AACnD,QAAO,MAAM,QAAQ,MAAM,IAAI,CAAC,QAAQ,UAAU,MAAM,EAAE,aAAa,CAAC;;;;;;;;AAS1E,MAAM,6BAA6B;CACjC,QAAQ;CACR,KAAK;CACL,eAAe;CACf,kBAAkB;CAClB,QAAQ;CACR,qBAAqB;CACrB,aAAa;CACb,eAAe;CACf,UAAU;CACV,UAAU;CACV,aAAa;CACb,YAAY;CACZ,KAAK;CACN;;;;AAKD,SAAgB,yBAA+C;AAC7D,QAAO,mBAAmB,QAAQ,KAAK,WAAW;EAChD;EACA,OAAO,SAAS,MAAM;EACvB,EAAE;;;;;;;AAQL,SAAgB,6BAAuD;CACrE,MAAM,MAAgC,EAAE;AACxC,MAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,2BAA2B,CACrE,KAAI,QAAQ,CAAC,GAAG,OAAO,QAAQ;AAEjC,QAAO"}
1
+ {"version":3,"file":"schema-resources.js","names":[],"sources":["../../../../src/cli/commands/plugin/schema-resources.ts"],"sourcesContent":["/**\n * Resource types and permissions sourced from the canonical Zod schemas in\n * `schemas/manifest.ts`. Single source of truth so create, add-resource, and\n * validate stay in sync with the schema.\n *\n * Values are constant at module load (direct Zod imports, no runtime JSON-schema\n * read), so no caching is needed.\n */\nimport {\n appPermissionSchema,\n databasePermissionSchema,\n experimentPermissionSchema,\n genieSpacePermissionSchema,\n jobPermissionSchema,\n modelServicePermissionSchema,\n postgresPermissionSchema,\n resourceTypeSchema,\n secretPermissionSchema,\n servingEndpointPermissionSchema,\n sqlWarehousePermissionSchema,\n ucConnectionPermissionSchema,\n ucFunctionPermissionSchema,\n vectorSearchIndexPermissionSchema,\n volumePermissionSchema,\n} from \"../../../schemas/manifest\";\n\nexport interface ResourceTypeOption {\n value: string;\n label: string;\n}\n\n/** Optional display overrides for acronyms (e.g. SQL, UC). Omitted entries use title-case of value. */\nconst LABEL_OVERRIDES: Record<string, string> = {\n sql_warehouse: \"SQL Warehouse\",\n uc_function: \"UC Function\",\n uc_connection: \"UC Connection\",\n};\n\nfunction humanize(value: string): string {\n if (LABEL_OVERRIDES[value]) return LABEL_OVERRIDES[value];\n return value.replace(/_/g, \" \").replace(/\\b\\w/g, (c) => c.toUpperCase());\n}\n\n/**\n * Map from resource type literal to its permission enum schema. Mirrors the\n * `allOf + if/then` block in the previous hand-written JSON Schema, but driven\n * directly from the Zod source. Add an entry here when extending\n * `resourceTypeSchema`.\n */\nconst PERMISSION_SCHEMAS_BY_TYPE = {\n secret: secretPermissionSchema,\n job: jobPermissionSchema,\n sql_warehouse: sqlWarehousePermissionSchema,\n serving_endpoint: servingEndpointPermissionSchema,\n model_service: modelServicePermissionSchema,\n volume: volumePermissionSchema,\n vector_search_index: vectorSearchIndexPermissionSchema,\n uc_function: ucFunctionPermissionSchema,\n uc_connection: ucConnectionPermissionSchema,\n database: databasePermissionSchema,\n postgres: postgresPermissionSchema,\n genie_space: genieSpacePermissionSchema,\n experiment: experimentPermissionSchema,\n app: appPermissionSchema,\n} as const;\n\n/**\n * Resource type options (value + label) from `resourceTypeSchema.options`.\n */\nexport function getResourceTypeOptions(): ResourceTypeOption[] {\n return resourceTypeSchema.options.map((value) => ({\n value,\n label: humanize(value),\n }));\n}\n\n/**\n * Permissions per resource type, derived from each type's per-type permission\n * schema's `.options` array. Order is weakest-to-strongest (matches Zod enum\n * declaration order, which the original JSON Schema also preserved).\n */\nexport function getResourceTypePermissions(): Record<string, string[]> {\n const out: Record<string, string[]> = {};\n for (const [type, schema] of Object.entries(PERMISSION_SCHEMAS_BY_TYPE)) {\n out[type] = [...schema.options];\n }\n return out;\n}\n"],"mappings":";;;;;;;;;;;;AAgCA,MAAM,kBAA0C;CAC9C,eAAe;CACf,aAAa;CACb,eAAe;CAChB;AAED,SAAS,SAAS,OAAuB;AACvC,KAAI,gBAAgB,OAAQ,QAAO,gBAAgB;AACnD,QAAO,MAAM,QAAQ,MAAM,IAAI,CAAC,QAAQ,UAAU,MAAM,EAAE,aAAa,CAAC;;;;;;;;AAS1E,MAAM,6BAA6B;CACjC,QAAQ;CACR,KAAK;CACL,eAAe;CACf,kBAAkB;CAClB,eAAe;CACf,QAAQ;CACR,qBAAqB;CACrB,aAAa;CACb,eAAe;CACf,UAAU;CACV,UAAU;CACV,aAAa;CACb,YAAY;CACZ,KAAK;CACN;;;;AAKD,SAAgB,yBAA+C;AAC7D,QAAO,mBAAmB,QAAQ,KAAK,WAAW;EAChD;EACA,OAAO,SAAS,MAAM;EACvB,EAAE;;;;;;;AAQL,SAAgB,6BAAuD;CACrE,MAAM,MAAgC,EAAE;AACxC,MAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,2BAA2B,CACrE,KAAI,QAAQ,CAAC,GAAG,OAAO,QAAQ;AAEjC,QAAO"}
@@ -4,7 +4,7 @@ import { JS_IDENTIFIER, REGISTRY_REPO } from "./constants.js";
4
4
  import { fetchRegistryItem, fetchVerifiedNames, isValidItemName, stripNamespace } from "./client.js";
5
5
  import { extractRequirements, renderRequirements } from "./requirements.js";
6
6
  import { buildConfigPlan, collectBindingValueNeeds, planHasContent } from "./config-plan.js";
7
- import { reportConfigWrite, validateBundle, writeConfig } from "./config-writer.js";
7
+ import { preflightConfig, reportConfigWrite, validateBundle, writeConfig } from "./config-writer.js";
8
8
  import { parseEnv } from "./env-reconcile.js";
9
9
  import { spawnSync } from "node:child_process";
10
10
  import fs from "node:fs";
@@ -313,6 +313,7 @@ async function runAdd(refs, opts) {
313
313
  process.exit(1);
314
314
  }
315
315
  }
316
+ if (opts.resources !== false && items.some((i) => extractRequirements(i).length > 0)) preflightConfig(cwd);
316
317
  const hasUi = items.some((i) => !isPluginItem(i));
317
318
  const hasPlugin = items.some(isPluginItem);
318
319
  const frontendRoot = hasUi ? findFrontendRoot(cwd) : cwd;
@@ -461,5 +462,5 @@ Examples:
461
462
  }));
462
463
 
463
464
  //#endregion
464
- export { addCommand };
465
+ export { addCommand, findServerRoot, profileFromEnv };
465
466
  //# sourceMappingURL=add.js.map