Files
windmill/frontend/src/lib/components/Password.svelte
T
GuilhemandClaude Opus 5.5 9536cfdab1 feat: ask for secrets and connect services in the AI chat through a secure card (#12575)
* feat: ask for secrets in the AI chat through a secure input card

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

* fix: overwrite a secret only once the card shows its path as taken

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

* fix: settle a stopped secret request, keep multiline secrets, link the saving workspace

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

* fix: sanitize the secret card's help link, report a save that lands after stop

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

* refactor: let the chat run the secret save, so it alone settles the card

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

* fix: let a secret save land before opening a past chat

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

* fix: write a late secret save before a chat switch, recheck for a turn after waiting

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

* feat: connect a service from one secret card that saves the secrets and creates the resource

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

* fix: keep a turn sent during new chat, set the type of a replaced resource, honour replace for its variables

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

* feat: connect postgres from a pasted connection string on the secret card

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

* fix: scope replace to the path the AI asked for, save only what the connection string says

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

* feat: test a connection from the secret card through a shared connection-test module, show provider steps

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

* fix: render the secret card's provider steps as markdown

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

* fix: test saved storage resources from their stored value, key retry ownership by kind

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

* docs: say how each saved-resource check reads its secrets, reattach saveSecretRequest's comment

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

* feat: serve request_secret to MCP clients through a signed link to a secure input page

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

* feat: open the secure input page on its own, outside the app's navigation

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

* fix: ask only what shapes the secret card, label its fields per the form guidelines, load the user on the secure input page

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

* feat: save the secure input card's secrets and resource as drafts the AI offers to deploy

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

* feat: name the resource and encrypted variables the secure input card saves, copy the reply to the assistant

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

* fix: confirm before the secret card replaces your drafts, keep a replaced secret's expiry, record and report saves landing after stop

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 22:49:22 +01:00

159 lines
4.5 KiB
Svelte

<script lang="ts">
import { createBubbler } from 'svelte/legacy'
import { tick } from 'svelte'
import Button from './common/button/Button.svelte'
import TextInput from './text_input/TextInput.svelte'
import { Eye, EyeClosed } from 'lucide-svelte'
import type { HTMLInputAttributes } from 'svelte/elements'
const bubble = createBubbler()
interface Props {
password: string | undefined
placeholder?: string
disabled?: boolean
required?: boolean
small?: boolean
minRows?: number
id?: string
autocomplete?: HTMLInputAttributes['autocomplete']
/** Off for login-style fields: keeps Enter free to submit. Overrides `minRows`. */
allowMultiline?: boolean
/** Renders the field in its error state; the message itself is the caller's to display. */
error?: boolean
/** id of the element holding that message, wired up as aria-describedby. */
describedBy?: string
onKeyDown?: (event: KeyboardEvent) => void
onBlur?: (event: FocusEvent) => void
}
let {
password = $bindable(),
placeholder = '******',
disabled = false,
required = false,
small = false,
minRows,
id,
autocomplete = 'new-password',
allowMultiline = true,
error = false,
describedBy = undefined,
onKeyDown,
onBlur
}: Props = $props()
let red = $derived(required && (password == '' || password == undefined))
let hasError = $derived(red || error)
let hideValue = $state(true)
let forceMultiline = $state(false)
let isMultiline = $derived(
allowMultiline &&
(forceMultiline || (minRows != null && minRows > 1) || (password?.includes('\n') ?? false))
)
let textareaRef: TextInput<'textarea'> | undefined = $state()
let inputRef: TextInput<'input'> | undefined = $state()
export function focus() {
;(isMultiline ? textareaRef : inputRef)?.focus()
}
// Revealing swaps the input to type="text". Auth forms conceal again before submitting,
// so the browser sees a password field when it decides whether to save the credential.
export function conceal() {
hideValue = true
}
function insertAndSwitchToMultiline(input: HTMLInputElement, text: string) {
const start = input.selectionStart
const end = input.selectionEnd
if (start != null && end != null) {
password = (password ?? '').substring(0, start) + text + (password ?? '').substring(end)
} else {
// selectionStart/End are null for type="password" inputs
password = (password ?? '') + text
}
forceMultiline = true
tick().then(() => textareaRef?.focus())
}
</script>
<div class="relative w-full {small ? 'max-w-lg' : ''}">
{#if isMultiline}
<TextInput
bind:this={textareaRef}
size="md"
error={hasError}
bind:value={password}
underlyingInputEl="textarea"
inputProps={{
id,
disabled,
placeholder,
rows: minRows ?? 3,
autocomplete,
'aria-invalid': hasError ? 'true' : undefined,
'aria-describedby': describedBy,
onblur: (e) => onBlur?.(e),
onkeydown: (e) => {
onKeyDown?.(e)
bubble('keydown')(e)
},
style: hideValue ? '-webkit-text-security: disc' : ''
}}
class="pr-8"
unifiedHeight={false}
/>
{:else}
<TextInput
bind:this={inputRef}
size="md"
error={hasError}
bind:value={password}
inputProps={{
id,
disabled,
placeholder,
autocomplete,
'aria-invalid': hasError ? 'true' : undefined,
'aria-describedby': describedBy,
onblur: (e) => onBlur?.(e),
onkeydown: (e) => {
// A modified Enter is left to the caller, which may submit on it.
if (allowMultiline && e.key === 'Enter' && !e.metaKey && !e.ctrlKey) {
e.preventDefault()
insertAndSwitchToMultiline(e.currentTarget as HTMLInputElement, '\n')
return
}
onKeyDown?.(e)
bubble('keydown')(e)
},
onpaste: (e) => {
const text = e.clipboardData?.getData('text')
if (allowMultiline && text?.includes('\n')) {
e.preventDefault()
insertAndSwitchToMultiline(e.currentTarget as HTMLInputElement, text)
}
},
type: hideValue ? 'password' : 'text'
}}
class="pr-8"
/>
{/if}
<!-- After the input in DOM order so Tab reaches the field before the toggle -->
<div class="absolute {isMultiline ? 'top-1' : 'inset-y-0'} right-1 flex items-center z-10">
<Button
unifiedSize="sm"
onClick={() => (hideValue = !hideValue)}
iconOnly
startIcon={{ icon: hideValue ? Eye : EyeClosed }}
variant="subtle"
title={hideValue ? 'Show password' : 'Hide password'}
wrapperClasses="bg-surface-input"
/>
</div>
</div>
{#if red}
<div class="text-red-600 text-2xs grow">This field is required</div>
{/if}