Files
windmill/frontend/src/lib/rawAppDeploy.ts
T
ef5fa21603 feat: add a share dialog and a first-deploy dialog (#11950)
* feat: harmonize flow, script and app settings drawers

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* refactor: name the on-behalf-of setting by the access it grants

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: add a permissions tab and confirm who apps run on behalf of

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: sandbox draft-only app deploys and keep app settings out of exports

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: keep drafted run-as users and custom url removals

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: confirm the run-as user on every deploy that uses one

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: let new raw apps take the folder default and follow synced settings

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: add a share dialog next to deploy and a first-deploy dialog

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: start AI-session raw apps without a run-as user

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: mock the deployed app read in chat deploy tests and type the list height

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* chore: point at the ee branch that registers the sharing counters

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: share the deployed path, log first deploys once and report the kept app access

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* refactor: stop drafting an app's access mode and custom url

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: keep a deployed app's access mode on an mcp deploy

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: ask who a first deploy runs as in the first-deploy dialog's second step

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: drop the first-deploy footer rule and test the run-as question

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: let a flow or script deploy turn off run on behalf of

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: apply who can open an app on change, as on main

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: mute the error handler from the editor menu and keep it on deploy

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* refactor: rename the Permissions entries and drawer to Share

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: confirm deploys that move an item to another folder

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: change only the access mode when it applies on click

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: read the mute flag from the deployed row at its own path

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: read a raw app's access mode after bundling it

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: keep group members off the list of who a move takes access from

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: change an app's access mode under the deploy row lock

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: defer a mode change to deploy on an app run as another user

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: hold the access toggle while its change is in flight

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: bind the app policy down to the settings drawer

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: keep app draft labels in the mcp session tools

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* revert: leave the deploy panel's access toggle to the settings drawer PR

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: change only the access mode on click and let deploys keep the deployed one

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: send Share's mode change alone and keep it out of MCP deploys

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: keep the caller's draft on a mode-only app update

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: leave the access mode out of every update deploy

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: explain in Share what an item's runs can reach

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: describe a viewer-mode app as using its viewer's access

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: confirm Share's app access changes with a toast

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: refuse a builder's mode-only change on an unsandboxed app

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: disable Share's access mode for a builder on an unsandboxed app

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test: check the reason for the unsandboxed mode-only refusal

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: defer a builder's access-mode change on an unsandboxed app

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: state the stored access mode in the chat's raw app deploy note

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: state the stored access mode in the MCP raw app deploy note

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: lock the access mode when the server would refuse the change

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: address settings and run-as review findings

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: say to deploy first when Share's access mode is locked

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: hold the run-as confirmation until the folder default has loaded

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: keep the run-as dialog cancelable while the folder default loads

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* refactor: harmonize flow and script settings layout

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: name who can change a locked access mode without taking the app over

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: keep the priority input open while it is edited

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: confirm run-as on flow and script deploy, mute from editor menu

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: keep settings rows open while edited and name the deploying user for non-admins

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: reread the deployed run-as user after a deploy that keeps the editor open

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: say in Share that admins and deployers can change a locked access mode

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: tell a builder who keeps the run-as user to pick themselves before deploying

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: write a setting before its row opens and show its real state while edited

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: slide settings rows open to their full height

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: open Share from the menu of Home's favorite and recent cards

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: send the popover's deployment message when Deploy is clicked

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: remount a settings row's fields when its toggle turns it on

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: send the popover's deployment message from Deploy & Stay here

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: count Share opened from a Home card under its own telemetry key

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: clear the deployment message after a successful deploy

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: show the stored access mode in Share after a refused change

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: keep app access mode display in sync with the stored mode and badge app settings tabs

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: clear the app Deploy popover's message after a successful deploy

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: read the deployed row before muting from the menu, title Deploy only when icon-only

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: give the app settings badges the chip label and row key

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: mark the app labels and access rows so their badges reach them

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: show the app settings as three sections instead of tabs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: drop unused publishAccessMode and app sharing badges

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: update ee-repo-ref to d16494953659e00dd169fb8f73266f22f937b862

This commit updates the EE repository reference after PR #911 was merged in windmill-ee-private.

Previous ee-repo-ref: 07f0090acb4a1f206c37f34411819b8c86690388

New ee-repo-ref: d16494953659e00dd169fb8f73266f22f937b862

Automated by sync-ee-ref workflow.

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
2026-10-29 19:28:41 +01:00

167 lines
6.0 KiB
TypeScript

/**
* Deploy a raw app (code-based app), from its server-side draft or from an
* explicit value. Raw apps can't be deployed through the normal
* AppService.updateApp/createApp path: their source `files` must be bundled to
* js/css and saved via the raw-app endpoints.
*
* This mirrors how the global AI chat deploys raw apps
* (`copilot/chat/global/core.ts` → deployDraft, case 'app'): read the item with
* its draft, normalise to an AppDraftValue, recompute the policy, bundle the
* files, then createAppRaw/updateAppRaw. The source→AppDraftValue projection is
* shared via `rawAppDraftValue` so the two deploy paths can't drift.
*/
import { AppService } from '$lib/gen'
import type { Policy } from '$lib/gen'
import { bundleRawAppDraft } from '$lib/components/copilot/chat/global/rawAppBundlerBridge'
import type { AppDraftValue } from '$lib/components/copilot/chat/global/workspaceItems'
import { updateRawAppPolicy } from '$lib/components/raw_apps/rawAppPolicy'
import { withoutSharedPolicySettings } from '$lib/components/apps/editor/appDraftSettings'
import { DEFAULT_DATA as DEFAULT_RAW_APP_DATA } from '$lib/components/raw_apps/dataTableRefUtils'
import {
appSourceToDraftValue,
normalizeRawAppData
} from '$lib/components/raw_apps/rawAppDraftValue'
import { stateSnapshot } from '$lib/svelte5Utils.svelte'
/**
* Deploy an explicit raw-app value — one the user edited as JSON, or one
* restored from a previous version — onto a deployed app.
*/
export async function deployRawAppValue({
workspace,
path,
value,
summary,
policy: currentPolicy,
deploymentMessage,
allowKindChange
}: {
workspace: string
path: string
value: any
summary?: string
policy?: Policy
deploymentMessage?: string
/** Let this deploy turn a low-code app into a raw one. Off for every ordinary
* deploy — see the backend's `allow_kind_change`. */
allowKindChange?: boolean
}): Promise<void> {
// The value often comes straight out of a `$state` field, and the bundler
// runs in an iframe: postMessage refuses to clone a state proxy.
const plainValue = (stateSnapshot(value) ?? {}) as Record<string, any>
const files = (plainValue.files ?? {}) as Record<string, string>
const runnables = plainValue.runnables ?? {}
// The value carries the runnables, so the policy's triggerables have to be
// recomputed from it or the deployed app can't call what it now contains.
const policy = (await updateRawAppPolicy(runnables, currentPolicy)) as Policy
const bundle = await bundleRawAppDraft({ workspace, files })
await AppService.updateAppRaw({
workspace,
path,
formData: {
app: {
// Through `normalizeRawAppData`, like every other deploy path: an old
// version can still carry the pre-`data` datatable shapes.
value: { files, runnables, data: normalizeRawAppData(plainValue) },
summary: summary ?? '',
// Without the mode, which the Share dialog sets: the server keeps the deployed one,
// read under the row lock a mode change also takes.
policy: withoutSharedPolicySettings(policy),
deployment_message: deploymentMessage,
// Absent keeps the custom URL, which the Share dialog sets.
custom_path: undefined,
preserve_on_behalf_of: policy.on_behalf_of ? true : undefined,
allow_kind_change: allowKindChange || undefined
},
js: bundle.js,
css: bundle.css
}
})
}
/**
* Promote a raw app's draft to deployed. Throws on failure (caller wraps into a
* DeployResult). The matching draft row is deleted server-side by the raw-app
* create/update handler, like the other deploy paths.
*/
export async function deployRawAppDraft(
workspace: string,
path: string,
deploymentMessage?: string
): Promise<void> {
// `rawApp: true` so a never-deployed raw app (no `app` row) resolves to
// the raw_app draft kind server-side instead of 404ing.
const app = await AppService.getAppByPath({ workspace, path, getDraft: true, rawApp: true })
const draft = (app as any).draft
// Deploy at the draft's intended path. A raw-app draft carries the user-typed
// path in `draft_path` (a never-deployed app is parked at a synthetic
// `u/{user}/draft_{uuid}` storage key); the URL `path` below stays that storage
// key. Falls back to `path` for an unrenamed draft on a deployed app.
const targetPath = draft?.draft_path ?? draft?.path ?? path
const value = appSourceToDraftValue(draft ?? app, app)
const policy = (await updateRawAppPolicy(
value.runnables as any,
value.policy as any
)) as NonNullable<AppDraftValue['policy']> & Policy
if (!policy.execution_mode) {
policy.execution_mode = 'publisher'
}
const bundle = await bundleRawAppDraft({ workspace, files: value.files })
const rawAppValue = {
files: value.files,
runnables: value.runnables,
data: value.data ?? { ...DEFAULT_RAW_APP_DATA }
}
const summary = value.summary ?? ''
if (await AppService.existsApp({ workspace, path })) {
// Who can open the app and its custom URL are set from the Share dialog: the update states
// neither, and the server keeps the deployed ones.
await AppService.updateAppRaw({
workspace,
path,
formData: {
app: {
path: targetPath,
value: rawAppValue,
summary,
policy: withoutSharedPolicySettings(policy),
deployment_message: deploymentMessage,
custom_path: undefined,
labels: value.labels,
// Preserve the policy's on_behalf_of: this draft-deploy path has no
// on-behalf-of selector, so without the flag the backend resets it to
// the deploying user (gated server-side by can_preserve_on_behalf_of).
preserve_on_behalf_of: policy.on_behalf_of ? true : undefined
},
js: bundle.js,
css: bundle.css
}
})
} else {
await AppService.createAppRaw({
workspace,
formData: {
app: {
path: targetPath,
value: rawAppValue,
summary,
policy,
deployment_message: deploymentMessage,
custom_path: value.custom_path,
labels: value.labels,
// Preserve the policy's on_behalf_of (see update branch above).
preserve_on_behalf_of: policy.on_behalf_of ? true : undefined
},
js: bundle.js,
css: bundle.css
}
})
}
}