@widgetic/workflows 0.2.10 → 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.
Files changed (75) hide show
  1. package/README.md +11 -13
  2. package/dist/api/workflowsApi.d.ts +9 -1
  3. package/dist/api/workflowsApi.js +2 -1
  4. package/dist/assistant/assistantEvents.d.ts +42 -0
  5. package/dist/assistant/assistantEvents.js +61 -0
  6. package/dist/assistant/assistantRemoteChange.d.ts +4 -0
  7. package/dist/assistant/assistantRemoteChange.js +8 -0
  8. package/dist/assistant/assistantSaveMode.d.ts +5 -0
  9. package/dist/assistant/assistantSaveMode.js +8 -0
  10. package/dist/assistant/assistantStream.d.ts +8 -0
  11. package/dist/assistant/assistantStream.js +140 -0
  12. package/dist/assistant/assistantTranscript.d.ts +11 -0
  13. package/dist/assistant/assistantTranscript.js +18 -0
  14. package/dist/assistant/types.d.ts +81 -0
  15. package/dist/assistant/types.js +1 -0
  16. package/dist/assistant/workflowPlanViewModel.d.ts +48 -0
  17. package/dist/assistant/workflowPlanViewModel.js +17 -0
  18. package/dist/components/Workflows.svelte +3 -1
  19. package/dist/components/WorkflowsEmptyState.svelte +15 -3
  20. package/dist/components/WorkflowsEmptyState.svelte.d.ts +2 -0
  21. package/dist/components/WorkflowsWorkspace.svelte +4 -0
  22. package/dist/components/WorkflowsWorkspace.svelte.d.ts +1 -0
  23. package/dist/components/assistant/WorkflowAssistantPanel.svelte +384 -0
  24. package/dist/components/assistant/WorkflowAssistantPanel.svelte.d.ts +8 -0
  25. package/dist/components/canvas/CompositionNodeView.svelte +5 -5
  26. package/dist/components/canvas/ConditionNodeView.svelte +4 -4
  27. package/dist/components/canvas/HandlePoint.svelte +1 -1
  28. package/dist/components/canvas/TriggerNodeView.svelte +5 -4
  29. package/dist/components/canvas/WorkflowCanvas.svelte +16 -6
  30. package/dist/components/canvas/WorkflowCanvas.svelte.d.ts +2 -2
  31. package/dist/components/editor/EditorCanvasArea.svelte +57 -2
  32. package/dist/components/editor/EditorCanvasArea.svelte.d.ts +8 -1
  33. package/dist/components/editor/EditorTabs.svelte +1 -2
  34. package/dist/components/editor/EditorTopBar.svelte +29 -21
  35. package/dist/components/editor/EditorTopBar.svelte.d.ts +3 -0
  36. package/dist/components/editor/RunsFlow.svelte +73 -23
  37. package/dist/components/editor/WorkflowEditor.svelte +31 -3
  38. package/dist/components/editor/WorkflowEditor.svelte.d.ts +5 -0
  39. package/dist/components/editor/WorkflowNameControl.svelte +136 -0
  40. package/dist/components/editor/WorkflowNameControl.svelte.d.ts +13 -0
  41. package/dist/components/list/WorkflowList.svelte +112 -60
  42. package/dist/components/list/WorkflowList.svelte.d.ts +2 -0
  43. package/dist/components/list/WorkflowRow.svelte +2 -0
  44. package/dist/components/panel/ConditionForm.svelte +7 -7
  45. package/dist/components/ui/Menu.svelte +31 -7
  46. package/dist/components/ui/Menu.svelte.d.ts +4 -0
  47. package/dist/components/ui/icons.d.ts +2 -0
  48. package/dist/components/ui/icons.js +3 -1
  49. package/dist/drafts/draftJournal.d.ts +59 -0
  50. package/dist/drafts/draftJournal.js +261 -0
  51. package/dist/drafts/workflowDraft.d.ts +72 -0
  52. package/dist/drafts/workflowDraft.js +151 -0
  53. package/dist/drafts/workflowListViewState.d.ts +30 -0
  54. package/dist/drafts/workflowListViewState.js +92 -0
  55. package/dist/editor/createBlankWorkflow.d.ts +30 -0
  56. package/dist/editor/createBlankWorkflow.js +37 -0
  57. package/dist/editor/editorState.svelte.d.ts +68 -2
  58. package/dist/editor/editorState.svelte.js +273 -0
  59. package/dist/editor/listState.svelte.d.ts +73 -36
  60. package/dist/editor/listState.svelte.js +260 -46
  61. package/dist/editor/presetChoice.d.ts +4 -4
  62. package/dist/editor/presetChoice.js +4 -4
  63. package/dist/editor/runsFlowBandLabel.d.ts +16 -0
  64. package/dist/editor/runsFlowBandLabel.js +34 -0
  65. package/dist/editor/runsFlowLayout.d.ts +24 -9
  66. package/dist/editor/runsFlowLayout.js +73 -28
  67. package/dist/editor/workflowNameCommit.d.ts +12 -0
  68. package/dist/editor/workflowNameCommit.js +11 -0
  69. package/dist/i18n/language.d.ts +3 -3
  70. package/dist/i18n/messages.d.ts +40 -26
  71. package/dist/i18n/messages.js +43 -30
  72. package/dist/types/index.d.ts +4 -0
  73. package/package.json +8 -1
  74. package/dist/components/list/CreateWorkflowDialog.svelte +0 -262
  75. package/dist/components/list/CreateWorkflowDialog.svelte.d.ts +0 -9
@@ -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;
@@ -62,15 +62,15 @@
62
62
  );
63
63
 
64
64
  const rootBorder = $derived.by(() => {
65
- if (status === 'error') return 'border-2 border-destructive';
66
- if (selected) return 'border-2 border-primary';
67
- if (isEmpty) return 'border border-dashed border-input';
68
- return 'border border-border';
65
+ if (status === 'error') return 'border-destructive';
66
+ if (selected) return 'border-primary';
67
+ if (isEmpty) return 'border-dashed border-input';
68
+ return 'border-border';
69
69
  });
70
70
  </script>
71
71
 
72
72
  <div
73
- class="relative flex w-60 flex-col overflow-hidden rounded-xl bg-background text-start text-foreground {rootBorder}"
73
+ class="relative flex w-60 flex-col overflow-hidden rounded-xl border-2 bg-background text-start text-foreground {rootBorder}"
74
74
  dir={$textDirection}
75
75
  data-workflow-block="composition"
76
76
  >
@@ -42,14 +42,14 @@
42
42
  }
43
43
 
44
44
  const rootBorder = $derived.by(() => {
45
- if (status === 'error') return 'border-2 border-destructive';
46
- if (selected) return 'border-2 border-primary';
47
- return 'border border-border';
45
+ if (status === 'error') return 'border-destructive';
46
+ if (selected) return 'border-primary';
47
+ return 'border-border';
48
48
  });
49
49
  </script>
50
50
 
51
51
  <div
52
- class="relative flex w-66 flex-col overflow-hidden rounded-xl bg-background text-start text-foreground {rootBorder}"
52
+ class="relative flex w-66 flex-col overflow-hidden rounded-xl border-2 bg-background text-start text-foreground {rootBorder}"
53
53
  dir={$textDirection}
54
54
  data-workflow-block="condition"
55
55
  >
@@ -31,7 +31,7 @@
31
31
  {port}
32
32
  accept={accept ? [...accept] : undefined}
33
33
  {position}
34
- class="group flex size-2.5 items-center justify-center border-0 bg-transparent p-0 [&_.kaykay-handle-label]:hidden"
34
+ class="group z-10 flex size-2.5 items-center justify-center border-0 bg-transparent p-0 [&_.kaykay-handle-label]:hidden"
35
35
  >
36
36
  <span
37
37
  class="pointer-events-none block size-2.5 rounded-full border border-muted-foreground bg-background transition-colors duration-fast group-[.can-connect]:border-primary group-[.can-connect]:bg-primary group-[.connecting]:border-primary group-[.connecting]:bg-primary group-[.incompatible]:opacity-50"
@@ -51,15 +51,16 @@
51
51
  }
52
52
  });
53
53
 
54
+ /** Two pixels reserved always so selection does not shift the block; handles sit above this ring in z-order. */
54
55
  const rootBorder = $derived.by(() => {
55
- if (status === 'error') return 'border-2 border-destructive';
56
- if (selected) return 'border-2 border-primary';
57
- return 'border border-border';
56
+ if (status === 'error') return 'border-destructive';
57
+ if (selected) return 'border-primary';
58
+ return 'border-border';
58
59
  });
59
60
  </script>
60
61
 
61
62
  <div
62
- class="relative flex w-58 flex-col gap-2 rounded-xl bg-background px-4 py-3 text-start text-foreground {rootBorder}"
63
+ class="relative flex w-58 flex-col gap-2 rounded-xl border-2 bg-background px-4 py-3 text-start text-foreground {rootBorder}"
63
64
  dir={$textDirection}
64
65
  data-workflow-block="trigger"
65
66
  >
@@ -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
- onViewportZoom?: (zoom: number) => void;
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
- onViewportZoom,
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 reportViewportZoom(viewport: Viewport): void {
116
- onViewportZoom?.(viewport.zoom);
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) => reportViewportZoom(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) reportViewportZoom(flow.viewport);
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
- onViewportZoom?: (zoom: number) => void;
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
- onViewportZoom={(z) => (canvasZoom = z)}
78
- onReady={(handle) => (editor.canvas = handle)}
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
- declare const EditorCanvasArea: import("svelte").Component<Record<string, never>, {}, "">;
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;
@@ -30,8 +30,7 @@
30
30
  ];
31
31
 
32
32
  function open(tab: EditorTab): void {
33
- if (tab !== 'editor' && editor.viewing) editor.leaveVersion();
34
- editor.tab = tab;
33
+ editor.selectTab(tab);
35
34
  }
36
35
  </script>
37
36