Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions frontend/src/lib/features/actions/ActionFlowEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import Send from '@lucide/svelte/icons/send';
import FileText from '@lucide/svelte/icons/file-text';
import Tag from '@lucide/svelte/icons/tag';
import Code from '@lucide/svelte/icons/code';
import X from '@lucide/svelte/icons/x';
import { toHotkeyString, getShortcutDisplay } from '../../utils/keyboardShortcuts.js';
import { actionCapabilities } from '../../api/ai.js';
Expand Down Expand Up @@ -48,7 +49,9 @@
import NotifyCustomerNode from './nodes/NotifyCustomerNode.svelte';
import InsertCannedResponseNode from './nodes/InsertCannedResponseNode.svelte';
import AdjustLabelsNode from './nodes/AdjustLabelsNode.svelte';
import ExecuteScriptNode from './nodes/ExecuteScriptNode.svelte';
import CreateMilestoneConfigPanel from './CreateMilestoneConfigPanel.svelte';
import ScriptConfigPanel from './ScriptConfigPanel.svelte';
import UpdateAssetConfigPanel from './UpdateAssetConfigPanel.svelte';
import CreateAssetConfigPanel from './CreateAssetConfigPanel.svelte';
import PlaceholderReferenceModal from './PlaceholderReferenceModal.svelte';
Expand Down Expand Up @@ -130,6 +133,7 @@
notify_customer: NotifyCustomerNode,
insert_canned_response: InsertCannedResponseNode,
adjust_labels: AdjustLabelsNode,
execute_script: ExecuteScriptNode,
};

// Mirror each node's accentColor in the minimap so the overview reflects
Expand All @@ -154,6 +158,7 @@
notify_customer: 'magenta',
insert_canned_response: 'orange',
adjust_labels: 'purple',
execute_script: 'cyan',
};

function minimapNodeColor(node) {
Expand Down Expand Up @@ -192,6 +197,7 @@
notify_customer: Send,
insert_canned_response: FileText,
adjust_labels: Tag,
execute_script: Code,
};

// i18n keys for node types. When a type isn't in this map, the palette
Expand All @@ -216,6 +222,7 @@
notify_customer: 'actions.nodes.notifyCustomer',
insert_canned_response: 'actions.nodes.insertCannedResponse',
adjust_labels: 'actions.nodes.adjustLabels',
execute_script: 'actions.nodes.executeScript',
};

// nodePalette is built from the catalog response on mount. Trigger nodes
Expand Down Expand Up @@ -1110,6 +1117,8 @@
<CreateAssetConfigPanel {selectedNode} flowStore={store} bind:showPlaceholderModal />
{:else if selectedNode.type === 'create_milestone'}
<CreateMilestoneConfigPanel {selectedNode} flowStore={store} bind:showPlaceholderModal />
{:else if selectedNode.type === 'execute_script'}
<ScriptConfigPanel {selectedNode} flowStore={store} />
{:else if selectedNode.type === 'notify_customer'}
<div>
<label for="config-notify-customer-subject" class="block text-xs font-medium mb-1">{t('actions.config.notifySubject')}</label>
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/lib/features/actions/ActionLogs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import XCircle from '@lucide/svelte/icons/x-circle';
import Clock from '@lucide/svelte/icons/clock';
import SkipForward from '@lucide/svelte/icons/skip-forward';
import AlertTriangle from '@lucide/svelte/icons/alert-triangle';
import Eye from '@lucide/svelte/icons/eye';
import { formatAuthenticatedDateTime } from '../../utils/authenticatedDateFormatter.js';
import { actionLogElapsedMs, formatElapsedMs } from '../../utils/timeUtils.js';
Expand Down Expand Up @@ -118,6 +119,9 @@
{:else if item.status === 'skipped'}
<SkipForward class="w-4 h-4 text-ds-icon-subtle" />
<span class="text-ds-text-subtle">{t('actions.logs.skipped')}</span>
{:else if item.status === 'reconciliation_required'}
<AlertTriangle class="w-4 h-4 text-ds-icon-warning" />
<span class="text-ds-text-warning">{t('actions.logs.reconciliationRequired')}</span>
{:else}
<span class="capitalize status-text">{item.status}</span>
{/if}
Expand Down
138 changes: 138 additions & 0 deletions frontend/src/lib/features/actions/ScriptConfigPanel.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<script>
import Input from '../../components/Input.svelte';
import Textarea from '../../components/Textarea.svelte';

let {
selectedNode,
flowStore,
} = $props();

const cfg = $derived(selectedNode?.data?.config || {});

const sourceExample = `// The effective executor's identity and permissions apply.
// Call the v2 REST API synchronously:
const res = windshift.api.request({
method: 'POST',
path: '/items/' + context.item_id + '/comments',
body: { content: 'Handled by automation', is_private: true }
});
console.log('comment status', res.status);
return { comment_id: res.body?.id ?? null };`;
</script>

<div class="script-panel">
<div>
<label for="execute-script-source" class="block text-xs font-medium mb-1">JavaScript (function body)</label>
<Textarea
id="execute-script-source"
data-testid="execute-script-source"
rows={14}
class="script-source"
value={cfg.source || ''}
placeholder={sourceExample}
oninput={(e) => flowStore.updateNodeConfig(selectedNode.id, { source: e.currentTarget.value })}
/>
<p class="hint">
Saving validates syntax only; the script never runs while editing. The
return value becomes JSON output. There is no network, filesystem, shell,
module, or async access — only <code>windshift.api.request</code> and
<code>console</code>.
</p>
</div>

<div>
<label for="execute-script-output-variable" class="block text-xs font-medium mb-1">Output variable</label>
<Input
id="execute-script-output-variable"
dataTestid="execute-script-output-variable"
type="text"
size="small"
value={cfg.output_variable || ''}
placeholder="script_result"
oninput={(e) => flowStore.updateNodeConfig(selectedNode.id, { output_variable: e.currentTarget.value })}
/>
<p class="hint">Downstream nodes read this variable. Reserved names such as
<code>actor_user_id</code> are rejected.</p>
</div>

<div class="script-grid">
<div>
<label for="execute-script-timeout" class="block text-xs font-medium mb-1">Timeout (ms)</label>
<Input
id="execute-script-timeout"
dataTestid="execute-script-timeout"
type="number"
size="small"
value={cfg.timeout_ms ? String(cfg.timeout_ms) : ''}
placeholder="5000"
oninput={(e) => flowStore.updateNodeConfig(selectedNode.id, { timeout_ms: e.currentTarget.value ? parseInt(e.currentTarget.value, 10) : 0 })}
/>
</div>
<div>
<label for="execute-script-max-calls" class="block text-xs font-medium mb-1">Max API calls</label>
<Input
id="execute-script-max-calls"
dataTestid="execute-script-max-calls"
type="number"
size="small"
value={cfg.max_api_calls ? String(cfg.max_api_calls) : ''}
placeholder="50"
oninput={(e) => flowStore.updateNodeConfig(selectedNode.id, { max_api_calls: e.currentTarget.value ? parseInt(e.currentTarget.value, 10) : 0 })}
/>
</div>
</div>

<div class="reference">
<p class="reference-title">windshift.api.request(&#123; method, path, body &#125;)</p>
<p class="hint">
<code>path</code> is relative to the v2 REST root (for example
<code>/items/123</code>). Alternate hosts, redirects, path escapes, and
unsupported routes are rejected. Requests run with a short-lived token
scoped to this executor and are audited with the action, execution, and
node that produced them.
</p>
<p class="hint">
<code>console.log/info/warn/error/debug</code> write bounded lines to the
execution trace.
</p>
</div>
</div>

<style>
.script-panel {
display: flex;
flex-direction: column;
gap: 12px;
}
.script-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
}
:global(textarea.script-source) {
font-family: var(--ds-font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
font-size: 12px;
line-height: 1.5;
}
.hint {
margin-top: 4px;
color: var(--ds-text-subtle);
font-size: 11px;
line-height: 1.4;
}
.hint code,
.reference code {
font-family: var(--ds-font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
}
.reference {
border: 1px solid var(--ds-border);
border-radius: 6px;
padding: 8px;
background: var(--ds-surface-sunken, transparent);
}
.reference-title {
font-size: 11px;
font-weight: 600;
margin-bottom: 4px;
}
</style>
10 changes: 10 additions & 0 deletions frontend/src/lib/features/actions/nodes/ExecuteScriptNode.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script>
import Code from '@lucide/svelte/icons/code';
import { t } from '../../../stores/i18n.svelte.js';
import { actionFlowStore } from '../../../stores/actionFlowStore.svelte.js';
import BaseActionNode from '../shared/BaseActionNode.svelte';

let { data = {}, selected = false } = $props();
</script>

<BaseActionNode {data} {selected} flowStore={data.flowStore || actionFlowStore} icon={Code} title={t('actions.nodes.executeScript')} accentColor="cyan" />
2 changes: 2 additions & 0 deletions frontend/src/lib/locales/ar/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default {
transitionItem: 'نقل العنصر',
roundRobinAssign: 'تعيين بالتناوب',
createMilestone: 'إنشاء معلم',
executeScript: 'تشغيل البرنامج النصي',
},

aiUpdated: 'تم تحديث الإجراء بواسطة الذكاء الاصطناعي',
Expand Down Expand Up @@ -165,6 +166,7 @@ export default {
completed: 'مكتمل',
failed: 'فشل',
skipped: 'تم تخطيه',
reconciliationRequired: 'مطلوب تسوية',
startedAt: 'بدأ في',
completedAt: 'اكتمل في',
error: 'خطأ',
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/locales/de/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default {
transitionItem: 'Vorgang überführen',
roundRobinAssign: 'Round-Robin zuweisen',
createMilestone: 'Meilenstein erstellen',
executeScript: 'Skript ausführen',
},

aiUpdated: 'Aktion durch KI aktualisiert',
Expand Down Expand Up @@ -168,6 +169,7 @@ export default {
completed: 'Abgeschlossen',
failed: 'Fehlgeschlagen',
skipped: 'Übersprungen',
reconciliationRequired: 'Abgleich erforderlich',
startedAt: 'Gestartet um',
completedAt: 'Abgeschlossen um',
error: 'Fehler',
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/locales/en/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export default {
notifyCustomer: 'Notify customer',
insertCannedResponse: 'Insert canned response',
adjustLabels: 'Adjust labels',
executeScript: 'Run script',
},

// Toast shown when the AI chat updates the open action via update_action.
Expand Down Expand Up @@ -266,6 +267,7 @@ export default {
completed: 'Completed',
failed: 'Failed',
skipped: 'Skipped',
reconciliationRequired: 'Reconciliation required',
startedAt: 'Started At',
completedAt: 'Completed At',
error: 'Error',
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/locales/es/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default {
transitionItem: 'Transicionar elemento',
roundRobinAssign: 'Asignar por turno rotativo',
createMilestone: 'Crear hito',
executeScript: 'Ejecutar script',
},

aiUpdated: 'Acción actualizada por IA',
Expand Down Expand Up @@ -167,6 +168,7 @@ export default {
completed: 'Completado',
failed: 'Fallido',
skipped: 'Omitido',
reconciliationRequired: 'Se requiere reconciliación',
startedAt: 'Iniciado a las',
completedAt: 'Completado a las',
error: 'Error',
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/locales/fa/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default {
"transitionItem": "مورد انتقال",
"roundRobinAssign": "تخصیص نوبتی",
"createMilestone": "نقطه عطف ایجاد کنید",
"executeScript": "اجرای اسکریپت",
"notifyCustomer": "به مشتری اطلاع دهید",
"insertCannedResponse": "درج پاسخ آماده",
"adjustLabels": "برچسب ها را تنظیم کنید"
Expand Down Expand Up @@ -225,6 +226,7 @@ export default {
"completed": "تکمیل شد",
"failed": "شکست خورد",
"skipped": "رد شد",
"reconciliationRequired": "نیاز به تطبیق",
"startedAt": "شروع شده در",
"completedAt": "تکمیل شده در",
"error": "خطا",
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/locales/fr/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default {
transitionItem: 'Faire évoluer l’élément',
roundRobinAssign: 'Attribution à tour de rôle',
createMilestone: 'Créer un jalon',
executeScript: 'Exécuter le script',
},

// Toast shown when the AI chat updates the open action via update_action.
Expand Down Expand Up @@ -235,6 +236,7 @@ export default {
completed: 'Terminé',
failed: 'Échoué',
skipped: 'Ignoré',
reconciliationRequired: 'Réconciliation requise',
startedAt: 'Démarré le',
completedAt: 'Terminé le',
error: 'Erreur',
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/locales/it/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default {
transitionItem: 'Transizione elemento',
roundRobinAssign: 'Assegnazione a rotazione',
createMilestone: 'Crea milestone',
executeScript: 'Esegui script',
notifyCustomer: 'Notifica cliente',
insertCannedResponse: 'Inserisci risposta predefinita',
adjustLabels: 'Modifica etichette',
Expand Down Expand Up @@ -257,6 +258,7 @@ export default {
completed: 'Completata',
failed: 'Non riuscita',
skipped: 'Saltata',
reconciliationRequired: 'Riconciliazione richiesta',
startedAt: 'Avviata il',
completedAt: 'Completata il',
error: 'Errore',
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/lib/locales/ko/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export default {
"relatedItems": "각 관련 작업에 대해 실행",
"transitionItem": "작업 상태 전환",
"roundRobinAssign": "순환 배정",
"createMilestone": "마일스톤 만들기"
"createMilestone": "마일스톤 만들기",
"executeScript": "스크립트 실행"
},
"aiUpdated": "AI가 자동화를 수정했습니다",
"runAs": "실행 사용자",
Expand Down Expand Up @@ -191,6 +192,7 @@ export default {
"completed": "완료",
"failed": "실패",
"skipped": "건너뜀",
"reconciliationRequired": "조정 필요",
"startedAt": "시작 시각",
"completedAt": "완료 시각",
"error": "오류",
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/locales/pl/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default {
transitionItem: 'Przejście elementu',
roundRobinAssign: 'Przypisanie rotacyjne',
createMilestone: 'Utwórz kamień milowy',
executeScript: 'Uruchom skrypt',
notifyCustomer: 'Powiadom klienta',
insertCannedResponse: 'Wstaw gotową odpowiedź',
adjustLabels: 'Dostosuj etykiety',
Expand Down Expand Up @@ -266,6 +267,7 @@ export default {
completed: 'Zakończone',
failed: 'Niepowodzenie',
skipped: 'Pominięte',
reconciliationRequired: 'Wymagane uzgodnienie',
startedAt: 'Rozpoczęto',
completedAt: 'Zakończono',
error: 'Błąd',
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/locales/pt-BR/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default {
transitionItem: 'Transicionar item',
roundRobinAssign: 'Atribuir em rodízio',
createMilestone: 'Criar marco',
executeScript: 'Executar script',
},

aiUpdated: 'Ação atualizada pela IA',
Expand Down Expand Up @@ -167,6 +168,7 @@ export default {
completed: 'Concluído',
failed: 'Falhou',
skipped: 'Ignorado',
reconciliationRequired: 'Reconciliação necessária',
startedAt: 'Iniciado em',
completedAt: 'Concluído em',
error: 'Erro',
Expand Down
Loading
Loading