@widgetic/workflows 0.2.11 → 0.2.12
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.
- package/dist/api/workflowsApi.d.ts +9 -1
- package/dist/api/workflowsApi.js +2 -1
- package/dist/assistant/assistantEvents.d.ts +42 -0
- package/dist/assistant/assistantEvents.js +61 -0
- package/dist/assistant/assistantRemoteChange.d.ts +4 -0
- package/dist/assistant/assistantRemoteChange.js +8 -0
- package/dist/assistant/assistantSaveMode.d.ts +5 -0
- package/dist/assistant/assistantSaveMode.js +8 -0
- package/dist/assistant/assistantStream.d.ts +8 -0
- package/dist/assistant/assistantStream.js +140 -0
- package/dist/assistant/assistantTranscript.d.ts +11 -0
- package/dist/assistant/assistantTranscript.js +18 -0
- package/dist/assistant/types.d.ts +81 -0
- package/dist/assistant/types.js +1 -0
- package/dist/assistant/workflowPlanViewModel.d.ts +48 -0
- package/dist/assistant/workflowPlanViewModel.js +17 -0
- package/dist/components/Workflows.svelte +3 -1
- package/dist/components/WorkflowsWorkspace.svelte +4 -0
- package/dist/components/WorkflowsWorkspace.svelte.d.ts +1 -0
- package/dist/components/assistant/WorkflowAssistantPanel.svelte +384 -0
- package/dist/components/assistant/WorkflowAssistantPanel.svelte.d.ts +8 -0
- package/dist/components/canvas/WorkflowCanvas.svelte +16 -6
- package/dist/components/canvas/WorkflowCanvas.svelte.d.ts +2 -2
- package/dist/components/editor/EditorCanvasArea.svelte +57 -2
- package/dist/components/editor/EditorCanvasArea.svelte.d.ts +8 -1
- package/dist/components/editor/EditorTabs.svelte +1 -2
- package/dist/components/editor/EditorTopBar.svelte +23 -1
- package/dist/components/editor/EditorTopBar.svelte.d.ts +3 -0
- package/dist/components/editor/WorkflowEditor.svelte +31 -3
- package/dist/components/editor/WorkflowEditor.svelte.d.ts +5 -0
- package/dist/components/editor/WorkflowNameControl.svelte +10 -0
- package/dist/components/list/WorkflowList.svelte +25 -1
- package/dist/components/list/WorkflowList.svelte.d.ts +2 -0
- package/dist/components/list/WorkflowRow.svelte +2 -0
- package/dist/components/panel/ConditionForm.svelte +7 -7
- package/dist/components/ui/Menu.svelte +31 -7
- package/dist/components/ui/Menu.svelte.d.ts +4 -0
- package/dist/drafts/draftJournal.d.ts +59 -0
- package/dist/drafts/draftJournal.js +261 -0
- package/dist/drafts/workflowDraft.d.ts +72 -0
- package/dist/drafts/workflowDraft.js +151 -0
- package/dist/drafts/workflowListViewState.d.ts +30 -0
- package/dist/drafts/workflowListViewState.js +92 -0
- package/dist/editor/editorState.svelte.d.ts +68 -2
- package/dist/editor/editorState.svelte.js +273 -0
- package/dist/editor/listState.svelte.d.ts +51 -2
- package/dist/editor/listState.svelte.js +210 -1
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +32 -0
- package/dist/i18n/messages.js +34 -1
- package/dist/types/index.d.ts +4 -0
- package/package.json +8 -1
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Collapsible workflows assistant: plans journeys, asks questions, and approves widget creation.
|
|
3
|
+
-->
|
|
4
|
+
<script lang="ts">
|
|
5
|
+
import { onMount } from 'svelte';
|
|
6
|
+
import { Button } from '@widgetic/design-system/components';
|
|
7
|
+
import { useEditorState } from '../../editor/editorState.svelte.js';
|
|
8
|
+
import {
|
|
9
|
+
emptyAssistantUiState,
|
|
10
|
+
reduceAssistantUiState,
|
|
11
|
+
type AssistantUiState,
|
|
12
|
+
} from '../../assistant/assistantEvents.js';
|
|
13
|
+
import {
|
|
14
|
+
clearAssistantTranscript,
|
|
15
|
+
createAssistantTranscriptJournal,
|
|
16
|
+
readAssistantTranscript,
|
|
17
|
+
writeAssistantTranscript,
|
|
18
|
+
} from '../../assistant/assistantTranscript.js';
|
|
19
|
+
import {
|
|
20
|
+
assistantFailureTextForStatus,
|
|
21
|
+
parseAssistantApproveStream,
|
|
22
|
+
parseAssistantSseStream,
|
|
23
|
+
} from '../../assistant/assistantStream.js';
|
|
24
|
+
import { editorActionForSaveMode } from '../../assistant/assistantSaveMode.js';
|
|
25
|
+
import type { AssistantAttachmentChip, WorkflowAssistantConfig } from '../../assistant/types.js';
|
|
26
|
+
import { dsButtonVariant } from '../ui/dsButtonProps.js';
|
|
27
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
28
|
+
import type { WorkflowsMessageKey } from '../../i18n/messages.js';
|
|
29
|
+
|
|
30
|
+
interface Props {
|
|
31
|
+
workflowId: string;
|
|
32
|
+
config: WorkflowAssistantConfig;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let { workflowId, config }: Props = $props();
|
|
36
|
+
|
|
37
|
+
const editor = useEditorState();
|
|
38
|
+
const { t } = useWorkflowsLanguage();
|
|
39
|
+
const journal = createAssistantTranscriptJournal();
|
|
40
|
+
|
|
41
|
+
let collapsed = $state(false);
|
|
42
|
+
let draft = $state('');
|
|
43
|
+
let ui = $state<AssistantUiState>({ ...emptyAssistantUiState });
|
|
44
|
+
let attachments = $state<AssistantAttachmentChip[]>([]);
|
|
45
|
+
let isApproving = $state(false);
|
|
46
|
+
let selectedOptionId = $state<string | null>(null);
|
|
47
|
+
|
|
48
|
+
const hasFailedPlanStep = $derived(ui.planCard?.steps.some((step) => step.status === 'failed') ?? false);
|
|
49
|
+
|
|
50
|
+
const welcomeChips: Array<{ key: WorkflowsMessageKey; send: WorkflowsMessageKey }> = [
|
|
51
|
+
{ key: 'workflows.assistant.chipIdeas', send: 'workflows.assistant.chipIdeas' },
|
|
52
|
+
{ key: 'workflows.assistant.chipLeads', send: 'workflows.assistant.chipLeads' },
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
function planStepStatusLabel(status: 'waiting' | 'creating' | 'done' | 'failed'): string {
|
|
56
|
+
switch (status) {
|
|
57
|
+
case 'waiting':
|
|
58
|
+
return $t('workflows.assistant.stepWaiting');
|
|
59
|
+
case 'creating':
|
|
60
|
+
return $t('workflows.assistant.stepCreating');
|
|
61
|
+
case 'done':
|
|
62
|
+
return $t('workflows.assistant.stepDone');
|
|
63
|
+
case 'failed':
|
|
64
|
+
return $t('workflows.assistant.stepFailed');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
onMount(() => {
|
|
69
|
+
ui = { ...ui, messages: [...readAssistantTranscript(journal, workflowId)] };
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
function persistTranscript(): void {
|
|
73
|
+
writeAssistantTranscript(journal, workflowId, ui.messages);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function authHeaders(): Promise<Record<string, string>> {
|
|
77
|
+
const headers = config.getAuthHeaders;
|
|
78
|
+
return typeof headers === 'function' ? headers() : headers;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function streamHistory() {
|
|
82
|
+
return ui.messages.map((message) => ({
|
|
83
|
+
role: message.role,
|
|
84
|
+
text: message.text,
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function sendMessage(
|
|
89
|
+
text: string,
|
|
90
|
+
answer?: { cardId: string; selectedOptionIds: string[]; selectedOptionLabels?: string[] },
|
|
91
|
+
): Promise<void> {
|
|
92
|
+
if (!text.trim() || ui.isStreaming) return;
|
|
93
|
+
const history = streamHistory();
|
|
94
|
+
ui = reduceAssistantUiState(ui, { type: 'user_message', id: crypto.randomUUID(), text });
|
|
95
|
+
ui = reduceAssistantUiState(ui, { type: 'streaming', value: true });
|
|
96
|
+
persistTranscript();
|
|
97
|
+
const body = {
|
|
98
|
+
message: text,
|
|
99
|
+
workflowId,
|
|
100
|
+
history,
|
|
101
|
+
attachmentMediaIds: attachments.filter((a) => a.state === 'ready').map((a) => a.mediaId),
|
|
102
|
+
...(answer ? { answerToQuestion: answer } : {}),
|
|
103
|
+
};
|
|
104
|
+
try {
|
|
105
|
+
const response = await fetch(config.streamUrl, {
|
|
106
|
+
method: 'POST',
|
|
107
|
+
headers: { 'Content-Type': 'application/json', ...(await authHeaders()) },
|
|
108
|
+
body: JSON.stringify(body),
|
|
109
|
+
});
|
|
110
|
+
if (!response.ok) {
|
|
111
|
+
console.debug('[workflows-assistant] the stream answered with an error status', response.status);
|
|
112
|
+
ui = reduceAssistantUiState(ui, {
|
|
113
|
+
type: 'assistant_text',
|
|
114
|
+
id: crypto.randomUUID(),
|
|
115
|
+
text: assistantFailureTextForStatus(response.status),
|
|
116
|
+
});
|
|
117
|
+
} else {
|
|
118
|
+
for await (const action of parseAssistantSseStream(response)) {
|
|
119
|
+
ui = reduceAssistantUiState(ui, action);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
} catch (error) {
|
|
123
|
+
console.debug('[workflows-assistant] the stream could not be read', error);
|
|
124
|
+
ui = reduceAssistantUiState(ui, {
|
|
125
|
+
type: 'assistant_text',
|
|
126
|
+
id: crypto.randomUUID(),
|
|
127
|
+
text: $t('workflows.error.generic'),
|
|
128
|
+
});
|
|
129
|
+
} finally {
|
|
130
|
+
// Whatever happened, the composer is usable again.
|
|
131
|
+
ui = reduceAssistantUiState(ui, { type: 'streaming', value: false });
|
|
132
|
+
persistTranscript();
|
|
133
|
+
draft = '';
|
|
134
|
+
selectedOptionId = null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async function onAttachFiles(event: Event): Promise<void> {
|
|
139
|
+
const input = event.target as HTMLInputElement;
|
|
140
|
+
const files = input.files ? [...input.files] : [];
|
|
141
|
+
for (const file of files) {
|
|
142
|
+
const chip: AssistantAttachmentChip = {
|
|
143
|
+
mediaId: '',
|
|
144
|
+
fileName: file.name,
|
|
145
|
+
state: 'uploading',
|
|
146
|
+
};
|
|
147
|
+
attachments = [...attachments, chip];
|
|
148
|
+
try {
|
|
149
|
+
const saved = await config.uploadFileToLibrary(file);
|
|
150
|
+
attachments = attachments.map((entry) =>
|
|
151
|
+
entry.fileName === file.name && entry.state === 'uploading'
|
|
152
|
+
? { ...entry, mediaId: saved.mediaId, state: 'ready' as const }
|
|
153
|
+
: entry,
|
|
154
|
+
);
|
|
155
|
+
} catch {
|
|
156
|
+
attachments = attachments.map((entry) =>
|
|
157
|
+
entry.fileName === file.name ? { ...entry, state: 'error' as const } : entry,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
input.value = '';
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function approvePlan(): Promise<void> {
|
|
165
|
+
const planCard = ui.planCard;
|
|
166
|
+
if (!planCard || isApproving) return;
|
|
167
|
+
isApproving = true;
|
|
168
|
+
ui = reduceAssistantUiState(ui, { type: 'streaming', value: true });
|
|
169
|
+
try {
|
|
170
|
+
const response = await fetch(config.approveUrl, {
|
|
171
|
+
method: 'POST',
|
|
172
|
+
headers: { 'Content-Type': 'application/json', ...(await authHeaders()) },
|
|
173
|
+
body: JSON.stringify({
|
|
174
|
+
planId: planCard.planId,
|
|
175
|
+
planToken: planCard.planToken,
|
|
176
|
+
workflowId,
|
|
177
|
+
plan: planCard.planWire,
|
|
178
|
+
}),
|
|
179
|
+
});
|
|
180
|
+
if (!response.ok) {
|
|
181
|
+
console.debug('[workflows-assistant] the approval answered with an error status', response.status);
|
|
182
|
+
ui = reduceAssistantUiState(ui, {
|
|
183
|
+
type: 'assistant_text',
|
|
184
|
+
id: crypto.randomUUID(),
|
|
185
|
+
text: assistantFailureTextForStatus(response.status),
|
|
186
|
+
});
|
|
187
|
+
} else {
|
|
188
|
+
for await (const action of parseAssistantApproveStream(response)) {
|
|
189
|
+
ui = reduceAssistantUiState(ui, action);
|
|
190
|
+
if (action.type === 'workflow_ready') {
|
|
191
|
+
if (editorActionForSaveMode(action.mode) === 'open_new') {
|
|
192
|
+
editor.goToWorkflow(action.workflowId);
|
|
193
|
+
} else {
|
|
194
|
+
await editor.respondToAssistantWorkflowUpdate();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
} catch (error) {
|
|
200
|
+
// A dropped connection: the builds may still be running on the server, so say so rather than leave the card spinning.
|
|
201
|
+
console.debug('[workflows-assistant] the approval stream ended early', error);
|
|
202
|
+
ui = reduceAssistantUiState(ui, {
|
|
203
|
+
type: 'assistant_text',
|
|
204
|
+
id: crypto.randomUUID(),
|
|
205
|
+
text: $t('workflows.error.generic'),
|
|
206
|
+
});
|
|
207
|
+
} finally {
|
|
208
|
+
isApproving = false;
|
|
209
|
+
ui = reduceAssistantUiState(ui, { type: 'streaming', value: false });
|
|
210
|
+
persistTranscript();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* "Retry" after a step failed. The plan is used once its builds have started (pressing it again would build the same widgets
|
|
216
|
+
* twice), so Retry asks the assistant for a new plan, which reuses the widgets that did get built.
|
|
217
|
+
*/
|
|
218
|
+
async function retryWithAssistant(): Promise<void> {
|
|
219
|
+
ui = { ...ui, planCard: null };
|
|
220
|
+
await sendMessage($t('workflows.assistant.retryMessage'));
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function newChat(): void {
|
|
224
|
+
clearAssistantTranscript(journal, workflowId);
|
|
225
|
+
ui = { ...emptyAssistantUiState };
|
|
226
|
+
attachments = [];
|
|
227
|
+
draft = '';
|
|
228
|
+
}
|
|
229
|
+
</script>
|
|
230
|
+
|
|
231
|
+
<aside class="flex h-full min-h-0 w-full flex-col rounded-xl border border-border bg-background">
|
|
232
|
+
<header class="flex items-center justify-between border-b border-border px-3 py-2">
|
|
233
|
+
<h2 class="text-body font-medium text-foreground">{$t('workflows.assistant.title')}</h2>
|
|
234
|
+
<div class="flex gap-1">
|
|
235
|
+
<Button variant={dsButtonVariant('ghost')} size="sm" onclick={newChat}>{$t('workflows.assistant.newChat')}</Button>
|
|
236
|
+
<Button variant={dsButtonVariant('ghost')} size="sm" onclick={() => (collapsed = !collapsed)}>
|
|
237
|
+
{collapsed ? $t('workflows.assistant.open') : $t('workflows.assistant.collapse')}
|
|
238
|
+
</Button>
|
|
239
|
+
</div>
|
|
240
|
+
</header>
|
|
241
|
+
{#if !collapsed}
|
|
242
|
+
<div class="flex min-h-0 flex-1 flex-col gap-3 overflow-auto p-3">
|
|
243
|
+
<p class="text-caption text-muted-foreground">
|
|
244
|
+
{$t('workflows.assistant.welcome')}
|
|
245
|
+
</p>
|
|
246
|
+
<div class="flex flex-wrap gap-2">
|
|
247
|
+
{#each welcomeChips as chip (chip.key)}
|
|
248
|
+
<Button
|
|
249
|
+
variant={dsButtonVariant('secondary')}
|
|
250
|
+
size="sm"
|
|
251
|
+
onclick={() => void sendMessage($t(chip.send))}
|
|
252
|
+
>
|
|
253
|
+
{$t(chip.key)}
|
|
254
|
+
</Button>
|
|
255
|
+
{/each}
|
|
256
|
+
</div>
|
|
257
|
+
<ul class="space-y-2">
|
|
258
|
+
{#each ui.messages as message (message.id)}
|
|
259
|
+
<li class="rounded-lg px-2 py-1 text-body {message.role === 'user' ? 'bg-muted' : 'bg-transparent'}">
|
|
260
|
+
{message.text}
|
|
261
|
+
</li>
|
|
262
|
+
{/each}
|
|
263
|
+
</ul>
|
|
264
|
+
{#if ui.questionCard}
|
|
265
|
+
<section class="rounded-lg border border-border p-3">
|
|
266
|
+
<p class="mb-2 text-body text-foreground">{ui.questionCard.message}</p>
|
|
267
|
+
<p class="mb-2 text-caption text-muted-foreground">{ui.questionCard.question}</p>
|
|
268
|
+
<div class="flex flex-col gap-1">
|
|
269
|
+
{#each ui.questionCard.options as option (option.id)}
|
|
270
|
+
<Button
|
|
271
|
+
variant={dsButtonVariant(selectedOptionId === option.id ? 'primary' : 'outline')}
|
|
272
|
+
size="sm"
|
|
273
|
+
onclick={() => (selectedOptionId = option.id)}
|
|
274
|
+
>
|
|
275
|
+
{option.label}
|
|
276
|
+
</Button>
|
|
277
|
+
{/each}
|
|
278
|
+
</div>
|
|
279
|
+
<Button
|
|
280
|
+
class="mt-2"
|
|
281
|
+
variant={dsButtonVariant('primary')}
|
|
282
|
+
size="sm"
|
|
283
|
+
disabled={!selectedOptionId}
|
|
284
|
+
onclick={() =>
|
|
285
|
+
selectedOptionId &&
|
|
286
|
+
void sendMessage($t('workflows.assistant.answerSent'), {
|
|
287
|
+
cardId: ui.questionCard?.cardId ?? '',
|
|
288
|
+
selectedOptionIds: [selectedOptionId],
|
|
289
|
+
selectedOptionLabels: ui.questionCard
|
|
290
|
+
? [
|
|
291
|
+
ui.questionCard.options.find((option) => option.id === selectedOptionId)?.label ??
|
|
292
|
+
selectedOptionId,
|
|
293
|
+
]
|
|
294
|
+
: [],
|
|
295
|
+
})}
|
|
296
|
+
>
|
|
297
|
+
{$t('workflows.assistant.submit')}
|
|
298
|
+
</Button>
|
|
299
|
+
</section>
|
|
300
|
+
{/if}
|
|
301
|
+
{#if ui.planCard}
|
|
302
|
+
<section class="rounded-lg border border-border p-3">
|
|
303
|
+
<h3 class="text-body font-medium text-foreground">{ui.planCard.title}</h3>
|
|
304
|
+
<p class="mt-1 text-caption text-muted-foreground">{ui.planCard.summary}</p>
|
|
305
|
+
<ul class="my-2 space-y-1">
|
|
306
|
+
{#each ui.planCard.steps as step (step.id)}
|
|
307
|
+
<li class="flex flex-col gap-0.5 text-caption text-muted-foreground">
|
|
308
|
+
<span>{step.label} — {planStepStatusLabel(step.status)}</span>
|
|
309
|
+
{#if step.status === 'failed' && step.detail}
|
|
310
|
+
<span class="text-destructive">{step.detail}</span>
|
|
311
|
+
{/if}
|
|
312
|
+
</li>
|
|
313
|
+
{/each}
|
|
314
|
+
</ul>
|
|
315
|
+
<p class="text-caption text-muted-foreground">
|
|
316
|
+
{$t('workflows.assistant.estimate', { number: ui.planCard.credits })}
|
|
317
|
+
</p>
|
|
318
|
+
<p class="mt-1 text-caption text-muted-foreground">{$t('workflows.assistant.planNote')}</p>
|
|
319
|
+
{#if ui.planCard.widgetsToCreate > 0}
|
|
320
|
+
<p class="mt-1 text-caption text-muted-foreground">{$t('workflows.assistant.buildNote')}</p>
|
|
321
|
+
{/if}
|
|
322
|
+
<div class="mt-2 flex flex-wrap gap-2">
|
|
323
|
+
<Button
|
|
324
|
+
variant={dsButtonVariant('primary')}
|
|
325
|
+
size="sm"
|
|
326
|
+
disabled={isApproving}
|
|
327
|
+
onclick={() => void approvePlan()}
|
|
328
|
+
>
|
|
329
|
+
{$t('workflows.assistant.createWorkflow')}
|
|
330
|
+
</Button>
|
|
331
|
+
<Button variant={dsButtonVariant('outline')} size="sm" onclick={() => (ui = { ...ui, planCard: null })}>
|
|
332
|
+
{$t('workflows.assistant.notNow')}
|
|
333
|
+
</Button>
|
|
334
|
+
{#if hasFailedPlanStep}
|
|
335
|
+
<Button variant={dsButtonVariant('outline')} size="sm" onclick={() => void retryWithAssistant()}>
|
|
336
|
+
{$t('workflows.assistant.retry')}
|
|
337
|
+
</Button>
|
|
338
|
+
{/if}
|
|
339
|
+
</div>
|
|
340
|
+
</section>
|
|
341
|
+
{/if}
|
|
342
|
+
{#if ui.completionMessage}
|
|
343
|
+
<p class="text-body text-foreground">{ui.completionMessage}</p>
|
|
344
|
+
{#if ui.savedWorkflowId}
|
|
345
|
+
<Button
|
|
346
|
+
variant={dsButtonVariant('primary')}
|
|
347
|
+
size="sm"
|
|
348
|
+
onclick={() => {
|
|
349
|
+
editor.goToWorkflow(ui.savedWorkflowId ?? workflowId);
|
|
350
|
+
editor.tab = 'editor';
|
|
351
|
+
}}
|
|
352
|
+
>
|
|
353
|
+
{$t('workflows.assistant.openInEditor')}
|
|
354
|
+
</Button>
|
|
355
|
+
{/if}
|
|
356
|
+
{/if}
|
|
357
|
+
</div>
|
|
358
|
+
<footer class="border-t border-border p-3">
|
|
359
|
+
<div class="mb-2 flex flex-wrap gap-2">
|
|
360
|
+
{#each attachments as file (file.fileName + file.mediaId)}
|
|
361
|
+
<span class="rounded-full bg-muted px-2 py-0.5 text-caption">{file.fileName} — {file.state}</span>
|
|
362
|
+
{/each}
|
|
363
|
+
</div>
|
|
364
|
+
<label class="mb-2 inline-block cursor-pointer text-caption text-primary">
|
|
365
|
+
{$t('workflows.assistant.attachFiles')}
|
|
366
|
+
<input type="file" class="hidden" multiple onchange={onAttachFiles} />
|
|
367
|
+
</label>
|
|
368
|
+
<p class="mb-2 text-caption text-muted-foreground">{$t('workflows.assistant.libraryHint')}</p>
|
|
369
|
+
<textarea
|
|
370
|
+
class="min-h-16 w-full rounded-lg border border-border bg-background p-2 text-body"
|
|
371
|
+
bind:value={draft}
|
|
372
|
+
placeholder={$t('workflows.assistant.composerPlaceholder')}
|
|
373
|
+
></textarea>
|
|
374
|
+
<Button
|
|
375
|
+
class="mt-2 w-full"
|
|
376
|
+
variant={dsButtonVariant('primary')}
|
|
377
|
+
disabled={ui.isStreaming}
|
|
378
|
+
onclick={() => void sendMessage(draft)}
|
|
379
|
+
>
|
|
380
|
+
{$t('workflows.assistant.send')}
|
|
381
|
+
</Button>
|
|
382
|
+
</footer>
|
|
383
|
+
{/if}
|
|
384
|
+
</aside>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { WorkflowAssistantConfig } from '../../assistant/types.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
workflowId: string;
|
|
4
|
+
config: WorkflowAssistantConfig;
|
|
5
|
+
}
|
|
6
|
+
declare const WorkflowAssistantPanel: import("svelte").Component<Props, {}, "">;
|
|
7
|
+
type WorkflowAssistantPanel = ReturnType<typeof WorkflowAssistantPanel>;
|
|
8
|
+
export default WorkflowAssistantPanel;
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
/** The `B` key was pressed on the canvas: the owner opens its Add block menu. */
|
|
65
65
|
onAddBlockShortcut?: () => void;
|
|
66
66
|
/** Pan/zoom updates (toolbar zoom label); not every `on_change` includes the viewport. */
|
|
67
|
-
|
|
67
|
+
onViewportChange?: (viewport: Viewport) => void;
|
|
68
68
|
/** Gives the owner the handle once the canvas is on the screen, and `null` when it leaves. */
|
|
69
69
|
onReady?: (handle: CanvasHandle | null) => void;
|
|
70
70
|
class?: string;
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
onGraphChange,
|
|
79
79
|
onSelectionChange,
|
|
80
80
|
onAddBlockShortcut,
|
|
81
|
-
|
|
81
|
+
onViewportChange,
|
|
82
82
|
onReady,
|
|
83
83
|
class: className = ''
|
|
84
84
|
}: Props = $props();
|
|
@@ -112,8 +112,8 @@
|
|
|
112
112
|
return canvas?.getFlow();
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
function
|
|
116
|
-
|
|
115
|
+
function reportViewportChange(viewport: Viewport): void {
|
|
116
|
+
onViewportChange?.(viewport);
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
const flowConfig: FlowConfig = {
|
|
@@ -137,7 +137,7 @@
|
|
|
137
137
|
|
|
138
138
|
const flowCallbacks: FlowCallbacks = {
|
|
139
139
|
on_change: () => scheduleRead(),
|
|
140
|
-
on_viewport_change: (viewport) =>
|
|
140
|
+
on_viewport_change: (viewport) => reportViewportChange(viewport),
|
|
141
141
|
on_selection_change: (nodeIds, edgeIds) => onSelectionChange?.(nodeIds, edgeIds)
|
|
142
142
|
};
|
|
143
143
|
|
|
@@ -269,6 +269,16 @@
|
|
|
269
269
|
},
|
|
270
270
|
get zoom() {
|
|
271
271
|
return getFlow()?.viewport.zoom ?? 1;
|
|
272
|
+
},
|
|
273
|
+
get viewport() {
|
|
274
|
+
const flow = getFlow();
|
|
275
|
+
return flow
|
|
276
|
+
? { x: flow.viewport.x, y: flow.viewport.y, zoom: flow.viewport.zoom }
|
|
277
|
+
: { x: 0, y: 0, zoom: 1 };
|
|
278
|
+
},
|
|
279
|
+
setViewport(viewport) {
|
|
280
|
+
getFlow()?.setViewport(viewport);
|
|
281
|
+
reportViewportChange(viewport);
|
|
272
282
|
}
|
|
273
283
|
};
|
|
274
284
|
|
|
@@ -348,7 +358,7 @@
|
|
|
348
358
|
}
|
|
349
359
|
fitSoon();
|
|
350
360
|
const flow = getFlow();
|
|
351
|
-
if (flow)
|
|
361
|
+
if (flow) reportViewportChange(flow.viewport);
|
|
352
362
|
onReady?.(handle);
|
|
353
363
|
});
|
|
354
364
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { NodeStatus } from 'kaykay';
|
|
1
|
+
import type { NodeStatus, Viewport } from 'kaykay';
|
|
2
2
|
import type { WorkflowGraph } from '@widgetic/workflows-engine';
|
|
3
3
|
import { type CanvasContext } from '../../editor/canvasContext.js';
|
|
4
4
|
import type { CanvasHandle } from '../../editor/editorState.svelte.js';
|
|
@@ -17,7 +17,7 @@ interface Props {
|
|
|
17
17
|
/** The `B` key was pressed on the canvas: the owner opens its Add block menu. */
|
|
18
18
|
onAddBlockShortcut?: () => void;
|
|
19
19
|
/** Pan/zoom updates (toolbar zoom label); not every `on_change` includes the viewport. */
|
|
20
|
-
|
|
20
|
+
onViewportChange?: (viewport: Viewport) => void;
|
|
21
21
|
/** Gives the owner the handle once the canvas is on the screen, and `null` when it leaves. */
|
|
22
22
|
onReady?: (handle: CanvasHandle | null) => void;
|
|
23
23
|
class?: string;
|
|
@@ -11,11 +11,32 @@
|
|
|
11
11
|
import { makeCanvasWords } from '../../editor/canvasWords.js';
|
|
12
12
|
import { useEditorState } from '../../editor/editorState.svelte.js';
|
|
13
13
|
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
14
|
+
import { Button } from '@widgetic/design-system/components';
|
|
15
|
+
import { dsButtonVariant } from '../ui/dsButtonProps.js';
|
|
14
16
|
import CanvasToolbar from '../canvas/CanvasToolbar.svelte';
|
|
15
17
|
import WorkflowCanvas from '../canvas/WorkflowCanvas.svelte';
|
|
16
18
|
import SidePanel from '../panel/SidePanel.svelte';
|
|
19
|
+
import WorkflowAssistantPanel from '../assistant/WorkflowAssistantPanel.svelte';
|
|
20
|
+
import type { WorkflowAssistantConfig } from '../../assistant/types.js';
|
|
21
|
+
|
|
22
|
+
interface Props {
|
|
23
|
+
workflowId: string;
|
|
24
|
+
assistant?: WorkflowAssistantConfig | null;
|
|
25
|
+
assistantOpen?: boolean;
|
|
26
|
+
onOpenAssistant?: () => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let { workflowId, assistant = null, assistantOpen = false, onOpenAssistant }: Props = $props();
|
|
17
30
|
|
|
18
31
|
const editor = useEditorState();
|
|
32
|
+
|
|
33
|
+
const showAssistant = $derived(Boolean(assistant?.enabled) && assistantOpen);
|
|
34
|
+
const showEmptyAssistantEntry = $derived(
|
|
35
|
+
Boolean(assistant?.enabled) &&
|
|
36
|
+
editor.canEditCanvas &&
|
|
37
|
+
editor.loadState === 'ready' &&
|
|
38
|
+
editor.graph.nodes.length === 0,
|
|
39
|
+
);
|
|
19
40
|
const { t, locale } = useWorkflowsLanguage();
|
|
20
41
|
|
|
21
42
|
/** Updated from the canvas viewport so the toolbar percentage stays live while zooming. */
|
|
@@ -74,10 +95,39 @@
|
|
|
74
95
|
onGraphChange={(graph) => editor.acceptCanvasGraph(graph)}
|
|
75
96
|
onSelectionChange={(nodeIds, edgeIds) => editor.followSelection(nodeIds, edgeIds)}
|
|
76
97
|
onAddBlockShortcut={() => toolbar?.openAddBlock()}
|
|
77
|
-
|
|
78
|
-
|
|
98
|
+
onViewportChange={(viewport) => {
|
|
99
|
+
canvasZoom = viewport.zoom;
|
|
100
|
+
editor.followViewport({
|
|
101
|
+
x: viewport.x,
|
|
102
|
+
y: viewport.y,
|
|
103
|
+
zoom: viewport.zoom
|
|
104
|
+
});
|
|
105
|
+
}}
|
|
106
|
+
onReady={(handle) => {
|
|
107
|
+
editor.canvas = handle;
|
|
108
|
+
const viewport = editor.canvasViewport;
|
|
109
|
+
if (handle && viewport) handle.setViewport(viewport);
|
|
110
|
+
}}
|
|
79
111
|
/>
|
|
80
112
|
<CanvasToolbar bind:this={toolbar} canEdit={!editor.isReadOnly} zoomLevel={canvasZoom} />
|
|
113
|
+
{#if showEmptyAssistantEntry}
|
|
114
|
+
<div
|
|
115
|
+
class="pointer-events-none absolute inset-0 flex flex-col items-center justify-center gap-3 px-6 text-center"
|
|
116
|
+
aria-live="polite"
|
|
117
|
+
>
|
|
118
|
+
<p class="text-body text-muted-foreground">{$t('workflows.assistant.emptyCanvas')}</p>
|
|
119
|
+
{#if onOpenAssistant}
|
|
120
|
+
<Button
|
|
121
|
+
class="pointer-events-auto"
|
|
122
|
+
variant={dsButtonVariant('primary')}
|
|
123
|
+
size="sm"
|
|
124
|
+
onclick={onOpenAssistant}
|
|
125
|
+
>
|
|
126
|
+
{$t('workflows.assistant.openAssistant')}
|
|
127
|
+
</Button>
|
|
128
|
+
{/if}
|
|
129
|
+
</div>
|
|
130
|
+
{/if}
|
|
81
131
|
</div>
|
|
82
132
|
</div>
|
|
83
133
|
<!-- The panel only when there is something to show; without it the canvas has the whole width (Figma "Editor"). -->
|
|
@@ -86,4 +136,9 @@
|
|
|
86
136
|
<SidePanel />
|
|
87
137
|
</div>
|
|
88
138
|
{/if}
|
|
139
|
+
{#if showAssistant && assistant}
|
|
140
|
+
<div class="min-h-0 w-full shrink-0 @3xl:w-80 @3xl:shrink-0">
|
|
141
|
+
<WorkflowAssistantPanel {workflowId} config={assistant} />
|
|
142
|
+
</div>
|
|
143
|
+
{/if}
|
|
89
144
|
</div>
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import type { WorkflowAssistantConfig } from '../../assistant/types.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
workflowId: string;
|
|
4
|
+
assistant?: WorkflowAssistantConfig | null;
|
|
5
|
+
assistantOpen?: boolean;
|
|
6
|
+
onOpenAssistant?: () => void;
|
|
7
|
+
}
|
|
8
|
+
declare const EditorCanvasArea: import("svelte").Component<Props, {}, "">;
|
|
2
9
|
type EditorCanvasArea = ReturnType<typeof EditorCanvasArea>;
|
|
3
10
|
export default EditorCanvasArea;
|
|
@@ -25,9 +25,19 @@
|
|
|
25
25
|
onpublish: () => void;
|
|
26
26
|
/** Opens the embed code of this workflow; absent when the page that hosts the screen has no such dialog. */
|
|
27
27
|
onshowembedcode?: () => void;
|
|
28
|
+
assistantEnabled?: boolean;
|
|
29
|
+
assistantOpen?: boolean;
|
|
30
|
+
onToggleAssistant?: () => void;
|
|
28
31
|
}
|
|
29
32
|
|
|
30
|
-
let {
|
|
33
|
+
let {
|
|
34
|
+
onback,
|
|
35
|
+
onpublish,
|
|
36
|
+
onshowembedcode,
|
|
37
|
+
assistantEnabled = false,
|
|
38
|
+
assistantOpen = false,
|
|
39
|
+
onToggleAssistant
|
|
40
|
+
}: Props = $props();
|
|
31
41
|
|
|
32
42
|
const editor = useEditorState();
|
|
33
43
|
const { t } = useWorkflowsLanguage();
|
|
@@ -176,6 +186,18 @@
|
|
|
176
186
|
<div class="hidden min-w-0 flex-1 @3xl:block"></div>
|
|
177
187
|
|
|
178
188
|
<div class="hidden w-full flex-wrap items-center justify-end gap-2 @3xl:flex @3xl:w-auto">
|
|
189
|
+
{#if assistantEnabled && onToggleAssistant}
|
|
190
|
+
<Button
|
|
191
|
+
variant="outline"
|
|
192
|
+
size={dsButtonSize('small')}
|
|
193
|
+
aria-pressed={assistantOpen}
|
|
194
|
+
class={assistantOpen ? 'bg-accent' : ''}
|
|
195
|
+
disabled={editor.tab !== 'editor'}
|
|
196
|
+
onclick={onToggleAssistant}
|
|
197
|
+
>
|
|
198
|
+
{$t('workflows.assistant.toolbarButton')}
|
|
199
|
+
</Button>
|
|
200
|
+
{/if}
|
|
179
201
|
<Button
|
|
180
202
|
variant="outline"
|
|
181
203
|
size={dsButtonSize('small')}
|
|
@@ -3,6 +3,9 @@ interface Props {
|
|
|
3
3
|
onpublish: () => void;
|
|
4
4
|
/** Opens the embed code of this workflow; absent when the page that hosts the screen has no such dialog. */
|
|
5
5
|
onshowembedcode?: () => void;
|
|
6
|
+
assistantEnabled?: boolean;
|
|
7
|
+
assistantOpen?: boolean;
|
|
8
|
+
onToggleAssistant?: () => void;
|
|
6
9
|
}
|
|
7
10
|
declare const EditorTopBar: import("svelte").Component<Props, {}, "">;
|
|
8
11
|
type EditorTopBar = ReturnType<typeof EditorTopBar>;
|