mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-29 08:06:46 +00:00
feat: give the chat's deploy confirmation a card of its own (#12571)
* feat: give the chat's deploy confirmation a card with editable fields and a diff * fix: refuse a picked deploy path that is already taken * fix: show the folder default user a first deploy will run as * fix: close the run-as picker once a user is chosen * fix: let Escape stop a turn in a drawer and seed the card from the staged path Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: read a raw app's staged path before canonicalizing its unsaved draft Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: drop the deploy card dev page Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a8f7c56c7e
commit
c8d047905e
@@ -230,7 +230,10 @@
|
||||
? 'opacity-50 cursor-not-allowed'
|
||||
: ''}"
|
||||
disabled={!canPreserve}
|
||||
onclick={() => onSelect('target')}
|
||||
onclick={() => {
|
||||
onSelect('target')
|
||||
closePopover()
|
||||
}}
|
||||
>
|
||||
<Check class="w-3 h-3 {selected === 'target' ? 'opacity-100' : 'opacity-0'}" />
|
||||
<span class="truncate max-w-40">{targetDisplayName}</span>
|
||||
@@ -240,7 +243,10 @@
|
||||
<!-- Me option -->
|
||||
<button
|
||||
class="flex items-center gap-2 px-2 py-1.5 rounded text-left text-xs hover:bg-surface-hover"
|
||||
onclick={() => onSelect('me')}
|
||||
onclick={() => {
|
||||
onSelect('me')
|
||||
closePopover()
|
||||
}}
|
||||
>
|
||||
<Check class="w-3 h-3 {selected === 'me' ? 'opacity-100' : 'opacity-0'}" />
|
||||
<span class="truncate max-w-40">{myDisplayName}</span>
|
||||
|
||||
@@ -80,6 +80,7 @@
|
||||
readDroppedEntries
|
||||
} from './files/fsAccess'
|
||||
import { sendUserToast } from '$lib/toast'
|
||||
import { overlayStack } from '$lib/components/common/overlayHost.svelte'
|
||||
import Alert from '$lib/components/common/alert/Alert.svelte'
|
||||
import { copilotInfo } from '$lib/aiStore'
|
||||
import ComposerSuggestions from './starter/ComposerSuggestions.svelte'
|
||||
@@ -250,9 +251,21 @@
|
||||
// Capture phase is required: Monaco and mounted-but-closed Modal2
|
||||
// instances consume window Escapes before they bubble.
|
||||
let panelEl: HTMLDivElement | undefined = $state()
|
||||
// A drawer or modal opened from the chat, such as the deploy card's diff, takes the Escape that
|
||||
// closes it: focus stays on the button that opened it, so it would otherwise cancel the pending
|
||||
// deploy. The ones the chat sits in (the flow editor's Test flow drawer) leave it the Escape.
|
||||
const overlays = overlayStack()
|
||||
function overlaysHoldingChat(): number {
|
||||
let n = 0
|
||||
for (let el = panelEl?.parentElement; el; el = el.parentElement) {
|
||||
if (el.matches('aside.drawer.open, [role="dialog"]')) n++
|
||||
}
|
||||
return n
|
||||
}
|
||||
$effect(() => {
|
||||
function onWindowKeydownCapture(e: KeyboardEvent) {
|
||||
if (e.key !== 'Escape' || !chatHost.loading) return
|
||||
if (overlays.val.length > overlaysHoldingChat()) return
|
||||
const active = document.activeElement
|
||||
// Focus parked on the body answers for the panel on screen only: the flow chat keeps
|
||||
// a panel per conversation mounted, several of which can be loading, and a hidden
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
<script lang="ts" module>
|
||||
import { lazyModule } from '$lib/lazyModule.svelte'
|
||||
|
||||
// It reaches the session tool graph, which the transcript must not load to render a card.
|
||||
const deployDiffModule = lazyModule(() => import('./global/deployDiff'))
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { resource } from 'runed'
|
||||
import { FolderService } from '$lib/gen'
|
||||
import { useActingUser } from '$lib/actingUser.svelte'
|
||||
import { useFolderDefaultPermissionedAs } from '$lib/components/useFolderDefaultPermissionedAs.svelte'
|
||||
import { folderOfPath, inheritedAccess } from '$lib/components/itemSettings/inheritedAccess'
|
||||
import DeployCardView, { type DeployCardReview } from './DeployCardView.svelte'
|
||||
import { deployIdentity, newAppAccessMode } from './deployCardFacts'
|
||||
import { getChatViewHost } from './chatViewHost'
|
||||
import type { ToolDisplayMessage } from './shared'
|
||||
import type { TriggerKind, WorkspaceItemType } from './global/workspaceItems'
|
||||
|
||||
interface Props {
|
||||
/** A `deploy_workspace_item` call waiting on the user. */
|
||||
message: ToolDisplayMessage
|
||||
}
|
||||
|
||||
let { message }: Props = $props()
|
||||
|
||||
const chatHost = getChatViewHost()
|
||||
const workspace = $derived(chatHost.operatingWorkspace)
|
||||
const args = $derived(
|
||||
(message.parameters ?? {}) as {
|
||||
type?: WorkspaceItemType
|
||||
path?: string
|
||||
trigger_kind?: TriggerKind
|
||||
deployment_message?: string
|
||||
force?: boolean
|
||||
}
|
||||
)
|
||||
|
||||
async function readDiff(target: {
|
||||
workspace: string | undefined
|
||||
type?: WorkspaceItemType
|
||||
path?: string
|
||||
trigger_kind?: TriggerKind
|
||||
}) {
|
||||
if (!target.workspace) return undefined
|
||||
const { loadDeployDiff } = await deployDiffModule.load()
|
||||
return loadDeployDiff(target.workspace, target)
|
||||
}
|
||||
|
||||
const review = resource(
|
||||
() => ({ workspace, type: args.type, path: args.path, trigger_kind: args.trigger_kind }),
|
||||
readDiff
|
||||
)
|
||||
const reviewState: DeployCardReview = $derived(
|
||||
review.current
|
||||
? { state: 'ready', ...review.current }
|
||||
: review.error
|
||||
? { state: 'error', message: review.error.message }
|
||||
: { state: 'loading' }
|
||||
)
|
||||
|
||||
// Where the deploy lands: the draft's path unless the user picks another for a first deploy.
|
||||
let deployPath: string | undefined = $state(undefined)
|
||||
const draftPath = $derived(review.current?.path ?? args.path)
|
||||
const targetPath = $derived(deployPath ?? draftPath)
|
||||
const pathKind = $derived(
|
||||
review.current?.kind === 'script' || review.current?.kind === 'flow'
|
||||
? review.current.kind
|
||||
: review.current?.kind === 'raw_app' || review.current?.kind === 'app'
|
||||
? 'app'
|
||||
: undefined
|
||||
)
|
||||
|
||||
const user = useActingUser(() => workspace)
|
||||
const isNew = $derived(review.current?.isNew === true)
|
||||
const folderDefault = useFolderDefaultPermissionedAs(
|
||||
() => (isNew ? targetPath : undefined),
|
||||
() => workspace
|
||||
)
|
||||
const me = $derived(user.current?.username ? `u/${user.current.username}` : undefined)
|
||||
|
||||
const identity = $derived(
|
||||
review.current && !folderDefault.loading
|
||||
? deployIdentity(review.current.kind, {
|
||||
deployed: review.current.deployed,
|
||||
draft: review.current.draft,
|
||||
isNew,
|
||||
folderDefault: folderDefault.value
|
||||
})
|
||||
: undefined
|
||||
)
|
||||
|
||||
// Who reaches a new item through its path. An update keeps whoever already has it.
|
||||
const access = resource(
|
||||
() => ({ workspace, path: isNew ? targetPath : undefined }),
|
||||
async ({ workspace, path }) => {
|
||||
if (!workspace || !path) return undefined
|
||||
const folderName = folderOfPath(path)
|
||||
const folder = folderName
|
||||
? await FolderService.getFolder({ workspace, name: folderName }).catch(() => undefined)
|
||||
: undefined
|
||||
return inheritedAccess(path, folder)
|
||||
}
|
||||
)
|
||||
|
||||
const appAccess = $derived(
|
||||
review.current ? newAppAccessMode(review.current.kind, review.current.draft, isNew) : undefined
|
||||
)
|
||||
|
||||
// Read again on click: the draft may have changed since the card first read it.
|
||||
const loadDiff = $derived.by(() => {
|
||||
const target = { workspace, type: args.type, path: args.path, trigger_kind: args.trigger_kind }
|
||||
if (!target.workspace || !target.path) return undefined
|
||||
return async () => {
|
||||
const diff = await readDiff(target)
|
||||
if (!diff) throw new Error('No workspace')
|
||||
return diff
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<DeployCardView
|
||||
toolCallId={message.tool_call_id}
|
||||
{workspace}
|
||||
type={args.type}
|
||||
path={draftPath}
|
||||
{pathKind}
|
||||
bind:deployPath
|
||||
review={reviewState}
|
||||
{me}
|
||||
access={isNew ? access.current : undefined}
|
||||
{appAccess}
|
||||
{identity}
|
||||
deploymentMessage={args.deployment_message}
|
||||
force={args.force}
|
||||
{loadDiff}
|
||||
/>
|
||||
@@ -0,0 +1,281 @@
|
||||
<script lang="ts" module>
|
||||
import type { OnBehalfOf } from './global/deployEdits'
|
||||
|
||||
export type DeployCardReview =
|
||||
| { state: 'loading' }
|
||||
| { state: 'error'; message: string }
|
||||
| { state: 'ready'; isNew: boolean; added: number; removed: number }
|
||||
|
||||
/** The run-as user of a script, flow or app being deployed. */
|
||||
export type DeployCardIdentity = {
|
||||
kind: 'script' | 'flow' | 'app'
|
||||
/** The draft's user, which the deploy keeps unless the card picks another. */
|
||||
held: OnBehalfOf
|
||||
/** The deployed user; both unset for a new item or one that runs as its caller. */
|
||||
saved: OnBehalfOf
|
||||
/** The folder default a new item with no user takes. The deploy applies it, so the setting
|
||||
* shows as required, as in the editors' deploy dialog. */
|
||||
folderDefault: string | undefined
|
||||
rawApp: boolean
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { ChevronRight, Loader2 } from 'lucide-svelte'
|
||||
import { Alert, Badge, Button } from '$lib/components/common'
|
||||
import Modal from '$lib/components/common/modal/Modal.svelte'
|
||||
import type { ComponentProps } from 'svelte'
|
||||
import Label from '$lib/components/Label.svelte'
|
||||
import Path from '$lib/components/Path.svelte'
|
||||
import TextInput from '$lib/components/text_input/TextInput.svelte'
|
||||
import RunOnBehalfOfSetting from '$lib/components/itemSettings/RunOnBehalfOfSetting.svelte'
|
||||
import { appOnBehalfOfTooltip } from '$lib/components/itemSettings/onBehalfOf'
|
||||
import AppAccessSection from '$lib/components/itemSettings/AppAccessSection.svelte'
|
||||
import type { AppAccessMode } from '$lib/components/itemSettings/appAccess'
|
||||
import { folderOfPath, type InheritedAccess } from '$lib/components/itemSettings/inheritedAccess'
|
||||
import ChatCollapsibleCard from './ChatCollapsibleCard.svelte'
|
||||
import ToolConfirmationFooter from './ToolConfirmationFooter.svelte'
|
||||
import DeployDiffButton, { type DeployDiffSides } from './DeployDiffButton.svelte'
|
||||
import { TOOL_CONFIRM_ACTIONS } from './toolConfirmAction'
|
||||
import { setDeployEdits, type DeployEdits } from './global/deployEdits'
|
||||
|
||||
interface Props {
|
||||
/** Undefined outside a chat: the buttons then answer nothing. */
|
||||
toolCallId: string | undefined
|
||||
workspace: string | undefined
|
||||
type: string | undefined
|
||||
/** The draft's path, where the model asked to deploy. */
|
||||
path: string | undefined
|
||||
/** For a script, flow or app, the path a first deploy may move to; undefined keeps it fixed. */
|
||||
pathKind: ComponentProps<typeof Path>['kind'] | undefined
|
||||
/** The path the user picked; unset deploys at `path`. */
|
||||
deployPath?: string
|
||||
review: DeployCardReview
|
||||
/** `u/name` of the deploying user. */
|
||||
me: string | undefined
|
||||
/** Who reaches a new item through the path it deploys at; undefined for an update. */
|
||||
access: InheritedAccess | undefined
|
||||
/** Who can open a new app as the draft sets it; undefined for anything else. */
|
||||
appAccess: AppAccessMode | undefined
|
||||
/** Undefined for a kind that runs as its caller, or until the draft is read. */
|
||||
identity: DeployCardIdentity | undefined
|
||||
deploymentMessage: string | undefined
|
||||
force: boolean | undefined
|
||||
/** Undefined disables the Diff button. */
|
||||
loadDiff: (() => Promise<DeployDiffSides>) | undefined
|
||||
}
|
||||
|
||||
let {
|
||||
toolCallId,
|
||||
workspace,
|
||||
type,
|
||||
path,
|
||||
pathKind,
|
||||
deployPath = $bindable(),
|
||||
review,
|
||||
me,
|
||||
access,
|
||||
appAccess,
|
||||
identity,
|
||||
deploymentMessage,
|
||||
force,
|
||||
loadDiff
|
||||
}: Props = $props()
|
||||
|
||||
const confirm = TOOL_CONFIRM_ACTIONS.deploy
|
||||
const isNew = $derived(review.state === 'ready' && review.isNew)
|
||||
const kindLabel = $derived(type ?? 'item')
|
||||
const targetPath = $derived(deployPath ?? path)
|
||||
let pathError: string | undefined = $state(undefined)
|
||||
|
||||
// What the user typed or picked; unset keeps what the model asked for or the draft holds.
|
||||
let message: string | undefined = $state(undefined)
|
||||
let picked: OnBehalfOf | undefined = $state(undefined)
|
||||
let pickedAccess: AppAccessMode | undefined = $state(undefined)
|
||||
const runAs: OnBehalfOf | undefined = $derived(picked ?? identity?.held)
|
||||
|
||||
function edits(): DeployEdits {
|
||||
const held = identity?.held
|
||||
const changedUser =
|
||||
picked !== undefined &&
|
||||
(picked.email !== held?.email || picked.permissionedAs !== held?.permissionedAs)
|
||||
return {
|
||||
deploymentMessage: message,
|
||||
deployPath: isNew && deployPath && deployPath !== path ? deployPath : undefined,
|
||||
onBehalfOf: changedUser ? picked : undefined,
|
||||
appAccess: pickedAccess !== undefined && pickedAccess !== appAccess ? pickedAccess : undefined
|
||||
}
|
||||
}
|
||||
|
||||
const accessSummary = $derived.by(() => {
|
||||
if (!access || !targetPath || pathError) return undefined
|
||||
const folderName = folderOfPath(targetPath)
|
||||
if (folderName !== undefined) {
|
||||
if (access.note !== undefined) return `Members of folder ${folderName}`
|
||||
const n = access.rows.length
|
||||
return `Folder ${folderName} · ${n} ${n === 1 ? 'member' : 'members'}`
|
||||
}
|
||||
const owner = access.rows[0]?.name
|
||||
return owner === me ? 'Only you' : owner
|
||||
})
|
||||
let accessOpen = $state(false)
|
||||
</script>
|
||||
|
||||
{#snippet headerRight()}
|
||||
{#if review.state === 'ready'}
|
||||
{#if review.isNew}
|
||||
<Badge small color="blue">New</Badge>
|
||||
{:else if review.added || review.removed}
|
||||
<span class="font-mono text-2xs shrink-0">
|
||||
<span class="text-green-600 dark:text-green-400">+{review.added}</span>
|
||||
<span class="text-red-600 dark:text-red-400">−{review.removed}</span>
|
||||
</span>
|
||||
{/if}
|
||||
{/if}
|
||||
{/snippet}
|
||||
|
||||
<ChatCollapsibleCard
|
||||
label="Deploy {kindLabel}"
|
||||
expanded
|
||||
onToggle={() => {}}
|
||||
toggleable={false}
|
||||
labelClass="truncate"
|
||||
contentClass="space-y-4"
|
||||
{headerRight}
|
||||
>
|
||||
<div class="flex flex-col gap-4 font-main">
|
||||
{#if review.state === 'loading'}
|
||||
<span class="flex items-center gap-2 text-xs text-secondary">
|
||||
<Loader2 size={12} class="animate-spin" /> Reading the draft…
|
||||
</span>
|
||||
{:else if review.state === 'error'}
|
||||
<Alert type="error" size="xs" title="Could not read the draft">{review.message}</Alert>
|
||||
{/if}
|
||||
|
||||
{#if isNew && pathKind && workspace}
|
||||
<Label label="Path">
|
||||
<Path
|
||||
size="sm"
|
||||
kind={pathKind}
|
||||
initialPath={path ?? ''}
|
||||
bind:path={() => targetPath, (v) => (deployPath = v)}
|
||||
bind:error={pathError}
|
||||
workspaceOverride={workspace}
|
||||
autofocus={false}
|
||||
/>
|
||||
</Label>
|
||||
{:else if path}
|
||||
<Label label="Path">
|
||||
<span class="text-xs font-mono text-primary truncate" title={path}>{path}</span>
|
||||
</Label>
|
||||
{/if}
|
||||
|
||||
{#if force}
|
||||
<Alert type="warning" size="xs" title="Overwrites a newer deploy">
|
||||
Someone deployed this {kindLabel} after the draft was started. Deploying replaces their version.
|
||||
</Alert>
|
||||
{/if}
|
||||
|
||||
{#if isNew && accessSummary}
|
||||
<Label label="Who gets access">
|
||||
<div>
|
||||
<Button
|
||||
variant="default"
|
||||
unifiedSize="sm"
|
||||
endIcon={{ icon: ChevronRight }}
|
||||
wrapperClasses="w-fit max-w-full"
|
||||
title="See who reaches this {kindLabel} once it is deployed"
|
||||
onClick={() => (accessOpen = true)}
|
||||
>
|
||||
<span class="truncate">{accessSummary}</span>
|
||||
</Button>
|
||||
</div>
|
||||
</Label>
|
||||
{/if}
|
||||
|
||||
{#if appAccess && workspace && targetPath}
|
||||
<Label label="Who can open it">
|
||||
<AppAccessSection
|
||||
{workspace}
|
||||
appPath={targetPath}
|
||||
rawApp={identity?.rawApp ?? true}
|
||||
mode={pickedAccess ?? appAccess}
|
||||
onModeChange={(m) => {
|
||||
pickedAccess = m
|
||||
}}
|
||||
/>
|
||||
</Label>
|
||||
{/if}
|
||||
|
||||
{#if identity && workspace}
|
||||
<RunOnBehalfOfSetting
|
||||
kind={identity.kind}
|
||||
required={identity.kind === 'app' || !!identity.folderDefault}
|
||||
tooltip={identity.kind === 'app' ? appOnBehalfOfTooltip(identity.rawApp) : undefined}
|
||||
bind:email={
|
||||
() => runAs?.email, (v) => (picked = { email: v, permissionedAs: runAs?.permissionedAs })
|
||||
}
|
||||
bind:permissionedAs={
|
||||
() => runAs?.permissionedAs, (v) => (picked = { email: runAs?.email, permissionedAs: v })
|
||||
}
|
||||
savedEmail={identity.saved.email}
|
||||
savedPermissionedAs={identity.saved.permissionedAs}
|
||||
targetWorkspace={workspace}
|
||||
{isNew}
|
||||
folderDefault={identity.folderDefault}
|
||||
hideDescription
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<Label label="Deployment message">
|
||||
<TextInput
|
||||
size="sm"
|
||||
bind:value={() => message ?? deploymentMessage ?? '', (v) => (message = String(v ?? ''))}
|
||||
inputProps={{ placeholder: 'Optional' }}
|
||||
/>
|
||||
</Label>
|
||||
</div>
|
||||
|
||||
<ToolConfirmationFooter
|
||||
{toolCallId}
|
||||
rejectLabel="Don't deploy"
|
||||
confirmLabel={confirm.label}
|
||||
confirmIcon={confirm.icon}
|
||||
confirmDisabled={!!pathError}
|
||||
onConfirm={() => toolCallId && setDeployEdits(toolCallId, edits())}
|
||||
>
|
||||
{#snippet leading()}
|
||||
<DeployDiffButton load={loadDiff} />
|
||||
{/snippet}
|
||||
</ToolConfirmationFooter>
|
||||
</ChatCollapsibleCard>
|
||||
|
||||
{#if access}
|
||||
<Modal bind:open={accessOpen} title="Who gets access" kind="X" class="sm:max-w-md">
|
||||
<div class="flex flex-col gap-3 text-xs">
|
||||
<p class="text-secondary">
|
||||
Once deployed, {targetPath} is reachable through its path by:
|
||||
</p>
|
||||
{#if access.note !== undefined}
|
||||
<p class="text-primary">{access.note}</p>
|
||||
{:else}
|
||||
<ul
|
||||
class="flex flex-col divide-y divide-border-light border border-border-light rounded-md"
|
||||
>
|
||||
{#each access.rows as accessRow (accessRow.name)}
|
||||
<li class="flex items-center justify-between px-3 py-1.5">
|
||||
<span class="text-primary">
|
||||
{accessRow.name}{accessRow.name === me ? ' (you)' : ''}
|
||||
</span>
|
||||
<span class="text-secondary">{accessRow.write ? 'Can edit' : 'Can view'}</span>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{/if}
|
||||
<p class="text-secondary">
|
||||
Workspace admins reach everything. To share it with more people, use Share once it is
|
||||
deployed.
|
||||
</p>
|
||||
</div>
|
||||
</Modal>
|
||||
{/if}
|
||||
@@ -0,0 +1,67 @@
|
||||
<script lang="ts" module>
|
||||
import { lazyModule } from '$lib/lazyModule.svelte'
|
||||
import type { UserDraftItemKind } from '$lib/gen'
|
||||
|
||||
// It reaches the AI clients, which the transcript must not load to render a card.
|
||||
const diffDrawerModule = lazyModule(() => import('$lib/components/DiffDrawer.svelte'))
|
||||
|
||||
export type DeployDiffSides = { kind: UserDraftItemKind; deployed: unknown; draft: unknown }
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { tick } from 'svelte'
|
||||
import { GitCompareArrows } from 'lucide-svelte'
|
||||
import { Button } from '$lib/components/common'
|
||||
import type DiffDrawer from '$lib/components/DiffDrawer.svelte'
|
||||
import { sendUserToast } from '$lib/toast'
|
||||
import type { Value } from '$lib/utils'
|
||||
|
||||
interface Props {
|
||||
/** Undefined disables the button. */
|
||||
load: (() => Promise<DeployDiffSides>) | undefined
|
||||
}
|
||||
|
||||
let { load }: Props = $props()
|
||||
|
||||
let diffDrawer: DiffDrawer | undefined = $state(undefined)
|
||||
let isFlow = $state(false)
|
||||
let loading = $state(false)
|
||||
|
||||
async function showDiff() {
|
||||
if (!load || loading) return
|
||||
loading = true
|
||||
try {
|
||||
const [diff] = await Promise.all([load(), diffDrawerModule.load()])
|
||||
isFlow = diff.kind === 'flow'
|
||||
await tick()
|
||||
diffDrawer?.openDrawer()
|
||||
diffDrawer?.setDiff({
|
||||
mode: 'simple',
|
||||
title: 'Deployed → Draft',
|
||||
original: diff.deployed as Value,
|
||||
current: diff.draft as Value
|
||||
})
|
||||
} catch (e: any) {
|
||||
sendUserToast(`Could not load the diff: ${e?.body ?? e?.message ?? e}`, true)
|
||||
} finally {
|
||||
loading = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<Button
|
||||
variant="subtle"
|
||||
unifiedSize="sm"
|
||||
startIcon={{ icon: GitCompareArrows }}
|
||||
{loading}
|
||||
disabled={!load}
|
||||
title="Compare the draft with what is deployed"
|
||||
onClick={showDiff}
|
||||
>
|
||||
Diff
|
||||
</Button>
|
||||
|
||||
{#if diffDrawerModule.current}
|
||||
{@const LoadedDiffDrawer = diffDrawerModule.current.default}
|
||||
<LoadedDiffDrawer bind:this={diffDrawer} {isFlow} />
|
||||
{/if}
|
||||
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { Button } from '$lib/components/common'
|
||||
import type { Snippet } from 'svelte'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
import { getChatViewHost } from './chatViewHost'
|
||||
|
||||
@@ -13,7 +14,12 @@
|
||||
/** Omit for a label-only confirm button. */
|
||||
confirmIcon?: any
|
||||
confirmDestructive?: boolean
|
||||
confirmDisabled?: boolean
|
||||
class?: string
|
||||
/** Rendered just before the reject button. */
|
||||
leading?: Snippet
|
||||
/** Runs right before the call is confirmed. */
|
||||
onConfirm?: () => void
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -24,13 +30,17 @@
|
||||
confirmLabel,
|
||||
confirmIcon,
|
||||
confirmDestructive = false,
|
||||
class: className
|
||||
confirmDisabled = false,
|
||||
class: className,
|
||||
leading,
|
||||
onConfirm
|
||||
}: Props = $props()
|
||||
|
||||
const chatHost = getChatViewHost()
|
||||
|
||||
function respond(confirmed: boolean) {
|
||||
if (toolCallId) {
|
||||
if (confirmed) onConfirm?.()
|
||||
chatHost.handleToolConfirmation(toolCallId, confirmed)
|
||||
}
|
||||
}
|
||||
@@ -38,6 +48,7 @@
|
||||
|
||||
<!-- font-main: the tool cards around it are font-mono, which reads as bold on a button label. -->
|
||||
<div class={twMerge('flex flex-row items-center justify-end gap-2 font-main', className)}>
|
||||
{@render leading?.()}
|
||||
<Button
|
||||
variant="default"
|
||||
unifiedSize="sm"
|
||||
@@ -51,6 +62,7 @@
|
||||
variant="accent"
|
||||
unifiedSize="sm"
|
||||
destructive={confirmDestructive}
|
||||
disabled={confirmDisabled}
|
||||
startIcon={confirmIcon ? { icon: confirmIcon } : undefined}
|
||||
on:click={() => respond(true)}
|
||||
>
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
import AskUserQuestionDisplay from './AskUserQuestionDisplay.svelte'
|
||||
import RunScriptCard from './RunScriptCard.svelte'
|
||||
import ToolDiffCard from './ToolDiffCard.svelte'
|
||||
import DeployCard from './DeployCard.svelte'
|
||||
import { hasToolCodeDiff } from './toolCodeDiff'
|
||||
import { TOOL_CONFIRM_ACTIONS } from './toolConfirmAction'
|
||||
import WebSearchSourcesDisplay from './WebSearchSourcesDisplay.svelte'
|
||||
@@ -176,6 +177,11 @@
|
||||
// the job it named — what happened in a run reads the same either way.
|
||||
const isRunCard = $derived(Boolean(message.runForm || message.inspectedRun))
|
||||
const isDiffCard = $derived(hasToolCodeDiff(message))
|
||||
// Only while it waits on the user: once answered, a deploy reads as any other settled call.
|
||||
const isDeployCard = $derived(
|
||||
message.toolName === 'deploy_workspace_item' &&
|
||||
Boolean(message.isLoading && message.needsConfirmation)
|
||||
)
|
||||
|
||||
// The preview chip sits on the header row (to the right of the tool-call text);
|
||||
// shown once the tool settled, never while loading/erroring/awaiting confirmation.
|
||||
@@ -228,6 +234,8 @@
|
||||
<span class="text-2xs text-tertiary truncate">{message.toolName} held until read</span>
|
||||
{/if}
|
||||
</div>
|
||||
{:else if isDeployCard}
|
||||
<DeployCard {message} />
|
||||
{:else if isRunCard}
|
||||
<RunScriptCard {message} />
|
||||
{:else if isDiffCard}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import type { Policy, UserDraftItemKind } from '$lib/gen'
|
||||
import { accessModeOf, type AppAccessMode } from '$lib/components/itemSettings/appAccess'
|
||||
import type { DeployCardIdentity } from './DeployCardView.svelte'
|
||||
import type { OnBehalfOf } from './global/deployEdits'
|
||||
|
||||
/** Where each kind keeps the user it runs on behalf of. */
|
||||
function identityOf(kind: UserDraftItemKind, value: unknown): OnBehalfOf {
|
||||
const v = (value ?? {}) as Record<string, any>
|
||||
const src = kind === 'raw_app' || kind === 'app' ? (v.policy ?? {}) : v
|
||||
return { email: src.on_behalf_of_email, permissionedAs: src.on_behalf_of }
|
||||
}
|
||||
|
||||
/** The run-as setting of a deploy, for the kinds that carry one. Others run as their caller, or
|
||||
* keep an identity the chat does not read. */
|
||||
export function deployIdentity(
|
||||
kind: UserDraftItemKind,
|
||||
deploy: { deployed: unknown; draft: unknown; isNew: boolean; folderDefault: string | undefined }
|
||||
): DeployCardIdentity | undefined {
|
||||
if (kind !== 'script' && kind !== 'flow' && kind !== 'raw_app' && kind !== 'app') return undefined
|
||||
return {
|
||||
kind: kind === 'raw_app' ? 'app' : kind,
|
||||
held: identityOf(kind, deploy.draft),
|
||||
saved: deploy.isNew
|
||||
? { email: undefined, permissionedAs: undefined }
|
||||
: identityOf(kind, deploy.deployed),
|
||||
folderDefault: deploy.isNew ? deploy.folderDefault : undefined,
|
||||
rawApp: kind === 'raw_app'
|
||||
}
|
||||
}
|
||||
|
||||
/** Who can open a new app as its draft sets it. Undefined for an update, which keeps the deployed
|
||||
* access that only the Share dialog changes. */
|
||||
export function newAppAccessMode(
|
||||
kind: UserDraftItemKind,
|
||||
draft: unknown,
|
||||
isNew: boolean
|
||||
): AppAccessMode | undefined {
|
||||
if (!isNew || (kind !== 'raw_app' && kind !== 'app')) return undefined
|
||||
return accessModeOf((draft as { policy?: Policy } | undefined)?.policy)
|
||||
}
|
||||
@@ -229,6 +229,7 @@ import {
|
||||
resolveGlobalDraftStoragePathByKind,
|
||||
type DraftPersistResult
|
||||
} from './userDraftAdapter'
|
||||
import { describeDeployEdits, takeDeployEdits } from './deployEdits'
|
||||
import {
|
||||
applySessionToolEffects,
|
||||
applyStatusEffects,
|
||||
@@ -7131,13 +7132,30 @@ async function deployDraft(
|
||||
ctx: WriteDraftCtx
|
||||
): Promise<string> {
|
||||
const { workspace, toolId, toolCallbacks, sessionId } = ctx
|
||||
const {
|
||||
type,
|
||||
path,
|
||||
trigger_kind: triggerKind,
|
||||
deployment_message: deploymentMessage,
|
||||
force
|
||||
} = args
|
||||
const { type, path, trigger_kind: triggerKind, force } = args
|
||||
const edits = takeDeployEdits(toolId)
|
||||
const deploymentMessage =
|
||||
edits?.deploymentMessage !== undefined
|
||||
? edits.deploymentMessage || undefined
|
||||
: args.deployment_message
|
||||
const onBehalfOf = edits?.onBehalfOf
|
||||
// A picked path creates the item there: one already taken would turn the create into an update
|
||||
// of whatever lives at it, so it is refused rather than overwritten.
|
||||
if (edits?.deployPath && edits.deployPath !== path) {
|
||||
const taken =
|
||||
type === 'script'
|
||||
? await ScriptService.existsScriptByPath({ workspace, path: edits.deployPath })
|
||||
: type === 'flow'
|
||||
? await FlowService.existsFlowByPath({ workspace, path: edits.deployPath })
|
||||
: type === 'app'
|
||||
? await AppService.existsApp({ workspace, path: edits.deployPath })
|
||||
: false
|
||||
if (taken) {
|
||||
throw new Error(
|
||||
`Cannot deploy ${type} "${path}" at "${edits.deployPath}": something is already deployed there.`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (type === 'trigger' && !triggerKind) {
|
||||
throw new Error('trigger_kind is required when deploying a trigger.')
|
||||
@@ -7202,13 +7220,20 @@ async function deployDraft(
|
||||
: undefined
|
||||
assertDraftBasedOnLatest('flow', path, draft.parentVersionId, existing?.version_id, force)
|
||||
}
|
||||
const isNewItem = !(type === 'script'
|
||||
? await ScriptService.existsScriptByPath({ workspace, path })
|
||||
: await FlowService.existsFlowByPath({ workspace, path }))
|
||||
if (edits?.deployPath && isNewItem) deployedPath = edits.deployPath
|
||||
const draftOnly =
|
||||
type === 'flow'
|
||||
? !(await FlowService.existsFlowByPath({ workspace, path: storagePath }))
|
||||
: false
|
||||
const result = await deployDraftToWorkspace(type, storagePath, workspace, {
|
||||
draftOnly,
|
||||
deploymentMessage
|
||||
deploymentMessage,
|
||||
onBehalfOf,
|
||||
// A path change is a rename for an item already deployed, which the card never offers.
|
||||
deployPath: edits?.deployPath && isNewItem ? edits.deployPath : undefined
|
||||
})
|
||||
if (!result.success) {
|
||||
throw new Error(result.error ?? `Failed to deploy ${type} "${path}".`)
|
||||
@@ -7316,6 +7341,10 @@ async function deployDraft(
|
||||
if (!policy) {
|
||||
throw new Error(`Draft app "${path}" has no policy to deploy.`)
|
||||
}
|
||||
if (onBehalfOf) {
|
||||
policy.on_behalf_of = onBehalfOf.permissionedAs
|
||||
policy.on_behalf_of_email = onBehalfOf.email
|
||||
}
|
||||
|
||||
// An app deployed on its own while a path runnable still points at a draft
|
||||
// is deployed and broken — the deploy has to say so, not just report success.
|
||||
@@ -7389,8 +7418,14 @@ async function deployDraft(
|
||||
throw e
|
||||
}
|
||||
}
|
||||
if (edits?.deployPath && !(await AppService.existsApp({ workspace, path: targetPath }))) {
|
||||
targetPath = edits.deployPath
|
||||
}
|
||||
deployedPath = targetPath
|
||||
const isUpdate = await AppService.existsApp({ workspace, path: targetPath })
|
||||
// The access the user picked on the card applies to a new app only: an update keeps the
|
||||
// deployed one, which only the Share dialog changes.
|
||||
if (!isUpdate && edits?.appAccess) policy.execution_mode = edits.appAccess
|
||||
if (isUpdate) {
|
||||
// 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.
|
||||
@@ -7506,17 +7541,25 @@ async function deployDraft(
|
||||
})
|
||||
}
|
||||
|
||||
const userChanges = describeDeployEdits(edits, {
|
||||
requestedMessage: args.deployment_message,
|
||||
path,
|
||||
deployedPath
|
||||
})
|
||||
|
||||
toolCallbacks.setToolStatus(toolId, {
|
||||
content: `Deployed ${noun} "${path}"`,
|
||||
content: `Deployed ${noun} "${deployedPath}"`,
|
||||
result: 'Deployed',
|
||||
actions
|
||||
})
|
||||
return JSON.stringify(
|
||||
{
|
||||
success: true,
|
||||
message: `Deployed draft ${type} "${path}" to the workspace. Draft removed.${
|
||||
deployNote ? ` ${deployNote}` : ''
|
||||
}`,
|
||||
message: `Deployed draft ${type} "${path}" to the workspace${
|
||||
deployedPath !== path ? ` at "${deployedPath}"` : ''
|
||||
}. Draft removed.${
|
||||
userChanges ? ` ${userChanges}` : ''
|
||||
}${deployNote ? ` ${deployNote}` : ''}`,
|
||||
type,
|
||||
path,
|
||||
triggerKind
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
import type { UserDraftItemKind } from '$lib/gen'
|
||||
import { canonicalDraftSideValue, getDraftDiffValues } from '$lib/utils_draft_deploy'
|
||||
import { UserDraftDbSyncer } from '$lib/userDraftDbSyncer.svelte'
|
||||
import { cleanValueProperties, replaceFalseWithUndefined } from '$lib/utils'
|
||||
import {
|
||||
computeDiffParts,
|
||||
expireWorkspaceDiffList,
|
||||
resolveWorkspaceDiffTarget
|
||||
} from './diffSnapshot'
|
||||
import { itemKindFor, readLocalDraftCellByKind } from './userDraftAdapter'
|
||||
import type { TriggerKind, WorkspaceItemType } from './workspaceItems'
|
||||
|
||||
export interface DeployDiff {
|
||||
kind: UserDraftItemKind
|
||||
/** Where the deploy lands: a draft created in an editor is stored at a synthetic
|
||||
* `u/<user>/draft_<uuid>` key, which the model may pass, with its chosen path in the draft. */
|
||||
path: string
|
||||
deployed: unknown
|
||||
draft: unknown
|
||||
/** Never deployed: this deploy creates the item. */
|
||||
isNew: boolean
|
||||
added: number
|
||||
removed: number
|
||||
}
|
||||
|
||||
/** Deployed vs draft for the target of a pending `deploy_workspace_item` call, in the shape
|
||||
* DiffDrawer's simple mode takes. Resolves the draft the way the `diff` tool does: a
|
||||
* friendly path to its storage row, and a parked autosave flushed with the autosave toggle
|
||||
* honored, so a read never persists edits the user kept local. Those are shown instead,
|
||||
* since the deploy flushes them before it deploys. */
|
||||
export async function loadDeployDiff(
|
||||
workspace: string,
|
||||
args: { type?: WorkspaceItemType; path?: string; trigger_kind?: TriggerKind }
|
||||
): Promise<DeployDiff> {
|
||||
const { type, path } = args
|
||||
const itemKind = type && path ? itemKindFor(type, args.trigger_kind) : undefined
|
||||
if (!type || !path || !itemKind) {
|
||||
throw new Error('The deploy call does not name a draft')
|
||||
}
|
||||
const kinds: UserDraftItemKind[] = type === 'app' ? ['raw_app', 'app'] : [itemKind]
|
||||
const target = await resolveWorkspaceDiffTarget(workspace, kinds, path)
|
||||
if (!target) {
|
||||
throw new Error(`You have no draft at ${path}`)
|
||||
}
|
||||
const query = { workspace, itemKind: target.kind, path: target.storagePath }
|
||||
await UserDraftDbSyncer.flush(query, { honorAutosaveToggle: true })
|
||||
expireWorkspaceDiffList(workspace)
|
||||
|
||||
const values = await getDraftDiffValues(
|
||||
target.kind,
|
||||
target.storagePath,
|
||||
workspace,
|
||||
target.draftOnly
|
||||
)
|
||||
const unsaved =
|
||||
UserDraftDbSyncer.hasUnsavedDisabledChanges(query) ||
|
||||
UserDraftDbSyncer.getState(query).state === 'failed' ||
|
||||
UserDraftDbSyncer.getConflict(query).conflict
|
||||
const localCell = unsaved
|
||||
? readLocalDraftCellByKind(workspace, target.kind, target.storagePath)
|
||||
: undefined
|
||||
const draft =
|
||||
localCell !== undefined ? canonicalDraftSideValue(target.kind, localCell) : values.draft
|
||||
const isNew = target.draftOnly || values.noDeployed
|
||||
// Cleaned as DiffDrawer cleans its sides, or row markers such as `is_draft: false` count as
|
||||
// changes the drawer then does not show.
|
||||
const clean = (v: unknown) => cleanValueProperties(replaceFalseWithUndefined(v))
|
||||
const parts = computeDiffParts(
|
||||
isNew ? undefined : clean(values.deployed),
|
||||
clean(draft),
|
||||
'deployed',
|
||||
'draft'
|
||||
)
|
||||
const counts = { added: 0, removed: 0 }
|
||||
for (const patch of [parts.patch, ...Object.values(parts.files ?? {}).map((f) => f.patch)]) {
|
||||
for (const line of patch.split('\n')) {
|
||||
if (line.startsWith('+') && !line.startsWith('+++')) counts.added++
|
||||
else if (line.startsWith('-') && !line.startsWith('---')) counts.removed++
|
||||
}
|
||||
}
|
||||
// Read from the local cell before canonicalizing: the raw-app canonical value drops `draft_path`.
|
||||
type Staged = { draft_path?: string; path?: string } | null | undefined
|
||||
const local = localCell as Staged
|
||||
const saved = draft as Staged
|
||||
const landsAt =
|
||||
(target.draftOnly
|
||||
? (local?.draft_path ?? local?.path ?? saved?.draft_path ?? saved?.path)
|
||||
: undefined) ?? path
|
||||
return { kind: target.kind, path: landsAt, deployed: values.deployed, draft, isNew, ...counts }
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { describeDeployEdits } from './deployEdits'
|
||||
|
||||
const at = { requestedMessage: 'v2', path: 'u/admin/a', deployedPath: 'u/admin/a' }
|
||||
|
||||
describe('describeDeployEdits', () => {
|
||||
it('says nothing when the card changed nothing the model asked for', () => {
|
||||
expect(describeDeployEdits(undefined, at)).toBeUndefined()
|
||||
expect(describeDeployEdits({ deploymentMessage: 'v2' }, at)).toBeUndefined()
|
||||
})
|
||||
|
||||
it('names every change, a cleared message and a run-as user turned off included', () => {
|
||||
expect(
|
||||
describeDeployEdits(
|
||||
{
|
||||
deploymentMessage: '',
|
||||
deployPath: 'f/reports/a',
|
||||
onBehalfOf: { email: undefined, permissionedAs: undefined }
|
||||
},
|
||||
{ ...at, deployedPath: 'f/reports/a' }
|
||||
)
|
||||
).toBe(
|
||||
'Before confirming, the user changed the deployment message to none, the path to f/reports/a, it to run as whoever starts each run.'
|
||||
)
|
||||
})
|
||||
|
||||
it('leaves out a picked path the deploy did not land at', () => {
|
||||
expect(describeDeployEdits({ deployPath: 'f/reports/a' }, at)).toBeUndefined()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,67 @@
|
||||
/** The user an item runs on behalf of; both unset runs it as whoever starts each run. */
|
||||
export type OnBehalfOf = { email: string | undefined; permissionedAs: string | undefined }
|
||||
|
||||
/** What the user changed on a pending deploy's card before confirming it. */
|
||||
export type DeployEdits = {
|
||||
deploymentMessage?: string
|
||||
/** Set only when the user picked a different user than the draft holds. */
|
||||
onBehalfOf?: OnBehalfOf
|
||||
/** A new app's access, set only when the user picked another than the draft's. */
|
||||
appAccess?: 'publisher' | 'guest' | 'anonymous'
|
||||
/** Scripts, flows and apps never deployed: the path to create the item at, when the user
|
||||
* picked another than the draft's. */
|
||||
deployPath?: string
|
||||
}
|
||||
|
||||
// Keyed by tool call id. The card's edits stay out of the tool's arguments: those are the model's
|
||||
// schema, which the MCP server serves too, and the model never chooses who an item runs as.
|
||||
const pending = new Map<string, DeployEdits>()
|
||||
|
||||
/** Called by the deploy card right before it confirms the call. */
|
||||
export function setDeployEdits(toolCallId: string, edits: DeployEdits): void {
|
||||
pending.set(toolCallId, edits)
|
||||
}
|
||||
|
||||
/** Read once by the deploy, so a declined or failed call leaves nothing behind for a retry. */
|
||||
export function takeDeployEdits(toolCallId: string): DeployEdits | undefined {
|
||||
const edits = pending.get(toolCallId)
|
||||
pending.delete(toolCallId)
|
||||
return edits
|
||||
}
|
||||
|
||||
/** Tells the model what the user changed on the card, so its reply matches what was deployed:
|
||||
* it chose none of it. Undefined when nothing changed. */
|
||||
export function describeDeployEdits(
|
||||
edits: DeployEdits | undefined,
|
||||
deploy: {
|
||||
/** The message the model passed. */
|
||||
requestedMessage: string | undefined
|
||||
/** The path the model asked to deploy, and where the item landed. */
|
||||
path: string
|
||||
deployedPath: string
|
||||
}
|
||||
): string | undefined {
|
||||
if (!edits) return undefined
|
||||
const changed: string[] = []
|
||||
const message = edits.deploymentMessage || undefined
|
||||
if (edits.deploymentMessage !== undefined && message !== deploy.requestedMessage) {
|
||||
changed.push(message ? `the deployment message to "${message}"` : 'the deployment message to none')
|
||||
}
|
||||
if (edits.deployPath && deploy.deployedPath === edits.deployPath && edits.deployPath !== deploy.path) {
|
||||
changed.push(`the path to ${edits.deployPath}`)
|
||||
}
|
||||
if (edits.appAccess) {
|
||||
const who =
|
||||
edits.appAccess === 'publisher'
|
||||
? 'members only'
|
||||
: edits.appAccess === 'guest'
|
||||
? 'guests'
|
||||
: 'anyone with the link'
|
||||
changed.push(`who can open the app to ${who}`)
|
||||
}
|
||||
if (edits.onBehalfOf) {
|
||||
const user = edits.onBehalfOf.permissionedAs ?? edits.onBehalfOf.email
|
||||
changed.push(user ? `the user it runs on behalf of to ${user}` : 'it to run as whoever starts each run')
|
||||
}
|
||||
return changed.length ? `Before confirming, the user changed ${changed.join(', ')}.` : undefined
|
||||
}
|
||||
@@ -569,15 +569,18 @@ export async function resolveWorkspaceDiffTarget(
|
||||
workspace: string,
|
||||
kinds: UserDraftItemKind[],
|
||||
path: string
|
||||
): Promise<{ kind: UserDraftItemKind; storagePath: string } | undefined> {
|
||||
): Promise<{ kind: UserDraftItemKind; storagePath: string; draftOnly: boolean } | undefined> {
|
||||
const cache = await reconcile(workspace)
|
||||
for (const kind of kinds) {
|
||||
if (cache.entries.has(entryKey(kind, path))) return { kind, storagePath: path }
|
||||
const exact = cache.entries.get(entryKey(kind, path))
|
||||
if (exact) return { kind, storagePath: path, draftOnly: exact.row.draft_only }
|
||||
}
|
||||
const entry = [...cache.entries.values()].find(
|
||||
(e) => kinds.includes(e.row.kind) && (e.displayPath === path || e.row.path === path)
|
||||
)
|
||||
return entry ? { kind: entry.row.kind, storagePath: entry.row.path } : undefined
|
||||
return entry
|
||||
? { kind: entry.row.kind, storagePath: entry.row.path, draftOnly: entry.row.draft_only }
|
||||
: undefined
|
||||
}
|
||||
|
||||
/** One item's diff entry, addressed by storage path or friendly draft path.
|
||||
|
||||
@@ -497,9 +497,22 @@ export async function deployDraft(
|
||||
kind: DraftKind,
|
||||
path: string,
|
||||
workspace: string,
|
||||
opts: { draftOnly?: boolean; rawApp?: boolean; deploymentMessage?: string } = {}
|
||||
opts: {
|
||||
draftOnly?: boolean
|
||||
rawApp?: boolean
|
||||
deploymentMessage?: string
|
||||
/** Scripts and flows: deploy with this user instead of the draft's; both unset runs the
|
||||
* item as whoever starts each run. */
|
||||
onBehalfOf?: { email: string | undefined; permissionedAs: string | undefined }
|
||||
/** Scripts and flows never deployed: create at this path instead of the draft's. */
|
||||
deployPath?: string
|
||||
} = {}
|
||||
): Promise<DeployResult & { noop?: boolean }> {
|
||||
const { draftOnly = false, rawApp = false, deploymentMessage } = opts
|
||||
const { draftOnly = false, rawApp = false, deploymentMessage, onBehalfOf, deployPath } = opts
|
||||
const identityOf = (d: { on_behalf_of_email?: string; on_behalf_of?: string }) =>
|
||||
onBehalfOf
|
||||
? { on_behalf_of_email: onBehalfOf.email, on_behalf_of: onBehalfOf.permissionedAs }
|
||||
: { on_behalf_of_email: d.on_behalf_of_email, on_behalf_of: d.on_behalf_of }
|
||||
// Set when the branch found nothing to promote and wrote nothing. Success, because the item is
|
||||
// already at the value a deploy would have left it at and its stale draft state still wants
|
||||
// clearing — but a caller deploying one specific draft it showed the user has to be able to tell
|
||||
@@ -526,13 +539,14 @@ export async function deployDraft(
|
||||
lock_error_logs: _lockErrorLogs,
|
||||
...rest
|
||||
} = d
|
||||
const scriptPath = d.path ?? path
|
||||
const scriptPath = deployPath ?? d.path ?? path
|
||||
// Deploy at the draft's path so a rename in the draft is honored (same as
|
||||
// the editor: createScript at the new path with parent_hash links lineage).
|
||||
await ScriptService.createScript({
|
||||
workspace,
|
||||
requestBody: {
|
||||
...rest,
|
||||
...identityOf(rest),
|
||||
path: scriptPath,
|
||||
parent_hash: r.hash,
|
||||
// The deployed script's: muting applies to it at once, so a draft's copy is stale.
|
||||
@@ -542,7 +556,7 @@ export async function deployDraft(
|
||||
deployment_message: deploymentMessage,
|
||||
// Deploy the draft's on-behalf-of as-is; the backend resets it to the
|
||||
// deploying user without this flag, gated by can_preserve_on_behalf_of.
|
||||
preserve_on_behalf_of: rest.on_behalf_of_email ? true : undefined
|
||||
preserve_on_behalf_of: identityOf(rest).on_behalf_of_email ? true : undefined
|
||||
}
|
||||
})
|
||||
// Then deploy any draft trigger edits, so they aren't dropped with the draft.
|
||||
@@ -558,7 +572,7 @@ export async function deployDraft(
|
||||
// user-typed path in `draft_path` (a never-deployed item is parked at a
|
||||
// synthetic `u/{user}/draft_{uuid}` storage key). The URL `path` stays
|
||||
// that storage key.
|
||||
path: d.draft_path ?? d.path ?? path,
|
||||
path: deployPath ?? d.draft_path ?? d.path ?? path,
|
||||
summary: d.summary ?? '',
|
||||
description: d.description ?? '',
|
||||
value,
|
||||
@@ -570,11 +584,10 @@ export async function deployDraft(
|
||||
ws_error_handler_muted:
|
||||
draftOnly || r.no_deployed ? d.ws_error_handler_muted : r.ws_error_handler_muted,
|
||||
visible_to_runner_only: d.visible_to_runner_only,
|
||||
on_behalf_of_email: d.on_behalf_of_email,
|
||||
on_behalf_of: d.on_behalf_of,
|
||||
...identityOf(d),
|
||||
// Same as scripts and apps: the backend resets on_behalf_of_email to the
|
||||
// deploying user without this flag, gated by can_preserve_on_behalf_of.
|
||||
preserve_on_behalf_of: d.on_behalf_of_email ? true : undefined,
|
||||
preserve_on_behalf_of: identityOf(d).on_behalf_of_email ? true : undefined,
|
||||
labels: d.labels,
|
||||
job_token_scopes: d.job_token_scopes,
|
||||
deployment_message: deploymentMessage
|
||||
@@ -591,7 +604,7 @@ export async function deployDraft(
|
||||
await deployDraftTriggers(
|
||||
d.draft_triggers,
|
||||
workspace,
|
||||
d.draft_path ?? d.path ?? path,
|
||||
deployPath ?? d.draft_path ?? d.path ?? path,
|
||||
draftOnly
|
||||
)
|
||||
} else if (kind === 'app') {
|
||||
|
||||
Reference in New Issue
Block a user