@widgetic/workflows 0.2.14 → 0.2.16
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/README.md +117 -3
- package/dist/api/types.d.ts +17 -0
- package/dist/api/workflowsApi.d.ts +12 -1
- package/dist/api/workflowsApi.js +37 -0
- package/dist/assistant/assistantEvents.d.ts +44 -2
- package/dist/assistant/assistantEvents.js +58 -2
- package/dist/assistant/assistantReferences.d.ts +66 -0
- package/dist/assistant/assistantReferences.js +109 -0
- package/dist/assistant/assistantSaveMode.d.ts +15 -3
- package/dist/assistant/assistantSaveMode.js +16 -2
- package/dist/assistant/assistantSeed.d.ts +55 -0
- package/dist/assistant/assistantSeed.js +90 -0
- package/dist/assistant/assistantStream.js +81 -3
- package/dist/assistant/assistantSuggest.d.ts +18 -0
- package/dist/assistant/assistantSuggest.js +21 -0
- package/dist/assistant/assistantTurns.d.ts +75 -0
- package/dist/assistant/assistantTurns.js +56 -0
- package/dist/assistant/attachmentUploads.d.ts +42 -0
- package/dist/assistant/attachmentUploads.js +69 -0
- package/dist/assistant/canvasLink.d.ts +30 -0
- package/dist/assistant/canvasLink.js +51 -0
- package/dist/assistant/compositionMention.d.ts +18 -0
- package/dist/assistant/compositionMention.js +47 -0
- package/dist/assistant/liveData.d.ts +150 -0
- package/dist/assistant/liveData.js +286 -0
- package/dist/assistant/mcpMention.d.ts +20 -0
- package/dist/assistant/mcpMention.js +30 -0
- package/dist/assistant/mentionEntries.d.ts +39 -0
- package/dist/assistant/mentionEntries.js +69 -0
- package/dist/assistant/planFlow.d.ts +26 -0
- package/dist/assistant/planFlow.js +57 -0
- package/dist/assistant/templateDestinations.d.ts +37 -0
- package/dist/assistant/templateDestinations.js +64 -0
- package/dist/assistant/types.d.ts +99 -2
- package/dist/assistant/workflowPlanViewModel.d.ts +13 -2
- package/dist/assistant/workflowPlanViewModel.js +9 -1
- package/dist/components/Workflows.svelte +7 -1
- package/dist/components/WorkflowsWorkspace.svelte +29 -1
- package/dist/components/WorkflowsWorkspace.svelte.d.ts +3 -0
- package/dist/components/assistant/AssistantPlanStepRow.svelte +56 -0
- package/dist/components/assistant/AssistantPlanStepRow.svelte.d.ts +9 -0
- package/dist/components/assistant/CompositionMentionMenu.svelte +135 -0
- package/dist/components/assistant/CompositionMentionMenu.svelte.d.ts +9 -0
- package/dist/components/assistant/DataPreviewCard.svelte +108 -0
- package/dist/components/assistant/DataPreviewCard.svelte.d.ts +7 -0
- package/dist/components/assistant/PlanBindingsBlock.svelte +200 -0
- package/dist/components/assistant/PlanBindingsBlock.svelte.d.ts +14 -0
- package/dist/components/assistant/TemplateProjectCard.svelte +81 -0
- package/dist/components/assistant/TemplateProjectCard.svelte.d.ts +14 -0
- package/dist/components/assistant/WorkflowAssistantPanel.svelte +1045 -147
- package/dist/components/assistant/WorkflowAssistantPanel.svelte.d.ts +5 -0
- package/dist/components/canvas/CanvasContextMenu.svelte +199 -0
- package/dist/components/canvas/CanvasContextMenu.svelte.d.ts +16 -0
- package/dist/components/canvas/CompositionNodeView.svelte +7 -2
- package/dist/components/canvas/ConditionNodeView.svelte +5 -1
- package/dist/components/canvas/HandlePoint.svelte +25 -3
- package/dist/components/canvas/WorkflowCanvas.svelte +351 -12
- package/dist/components/canvas/WorkflowCanvas.svelte.d.ts +12 -1
- package/dist/components/canvas/altDragDuplicateController.d.ts +29 -0
- package/dist/components/canvas/altDragDuplicateController.js +92 -0
- package/dist/components/canvas/connectionSnapController.d.ts +29 -0
- package/dist/components/canvas/connectionSnapController.js +182 -0
- package/dist/components/canvas/spacePanController.d.ts +16 -0
- package/dist/components/canvas/spacePanController.js +103 -0
- package/dist/components/editor/EditorCanvasArea.svelte +98 -4
- package/dist/components/editor/EditorCanvasArea.svelte.d.ts +5 -0
- package/dist/components/editor/EditorLoadFailure.svelte +53 -0
- package/dist/components/editor/EditorLoadFailure.svelte.d.ts +7 -0
- package/dist/components/editor/EditorTopBar.svelte +53 -42
- package/dist/components/editor/WorkflowEditor.svelte +74 -50
- package/dist/components/editor/WorkflowEditor.svelte.d.ts +5 -0
- package/dist/components/editor/WorkflowNameControl.svelte +9 -8
- package/dist/components/editor/WorkflowNameControl.svelte.d.ts +3 -1
- package/dist/components/list/WorkflowList.svelte +43 -41
- package/dist/components/list/WorkflowList.svelte.d.ts +5 -0
- package/dist/components/panel/CompositionForm.svelte +3 -2
- package/dist/components/panel/CompositionPicker.svelte +25 -23
- package/dist/components/panel/CompositionPicker.svelte.d.ts +2 -2
- package/dist/components/panel/CompositionSelect.svelte +4 -4
- package/dist/components/panel/CompositionSelect.svelte.d.ts +2 -2
- package/dist/components/ui/ErrorState.svelte +43 -0
- package/dist/components/ui/ErrorState.svelte.d.ts +13 -0
- package/dist/components/ui/icons.d.ts +8 -0
- package/dist/components/ui/icons.js +24 -1
- package/dist/editor/apiErrorText.d.ts +2 -0
- package/dist/editor/apiErrorText.js +15 -0
- package/dist/editor/autoLayout.d.ts +38 -0
- package/dist/editor/autoLayout.js +403 -0
- package/dist/editor/blockClipboard.svelte.d.ts +9 -0
- package/dist/editor/blockClipboard.svelte.js +24 -0
- package/dist/editor/blockCopy.d.ts +39 -0
- package/dist/editor/blockCopy.js +137 -0
- package/dist/editor/canvasMenu.d.ts +45 -0
- package/dist/editor/canvasMenu.js +68 -0
- package/dist/editor/connectionSnap.d.ts +90 -0
- package/dist/editor/connectionSnap.js +98 -0
- package/dist/editor/editorState.svelte.d.ts +122 -13
- package/dist/editor/editorState.svelte.js +262 -22
- package/dist/editor/graphIssues.d.ts +5 -0
- package/dist/editor/graphIssues.js +18 -0
- package/dist/editor/graphModel.d.ts +6 -1
- package/dist/editor/graphModel.js +8 -1
- package/dist/editor/keyHints.d.ts +21 -0
- package/dist/editor/keyHints.js +30 -0
- package/dist/editor/listState.svelte.d.ts +4 -4
- package/dist/editor/listState.svelte.js +3 -1
- package/dist/editor/staleGuard.d.ts +111 -0
- package/dist/editor/staleGuard.js +279 -0
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +85 -1
- package/dist/i18n/messages.js +99 -4
- package/dist/index.d.ts +1 -0
- package/dist/types/index.d.ts +19 -2
- package/package.json +10 -10
|
@@ -2,12 +2,43 @@
|
|
|
2
2
|
Collapsible workflows assistant: plans journeys, asks questions, and approves widget creation.
|
|
3
3
|
-->
|
|
4
4
|
<script lang="ts">
|
|
5
|
-
import { onMount } from 'svelte';
|
|
6
|
-
import { Button } from '@widgetic/design-system/components';
|
|
5
|
+
import { onMount, tick } from 'svelte';
|
|
6
|
+
import { Button, Chip } from '@widgetic/design-system/components';
|
|
7
|
+
import { useWorkflowsApi } from '../../api/apiContext.js';
|
|
8
|
+
import type { CompositionOption, OpenMcpOption } from '../../api/types.js';
|
|
9
|
+
// The grey words after what the person has typed, which Tab takes: the engine is the design system's, one box's part is below
|
|
10
|
+
import {
|
|
11
|
+
completionHintMemory,
|
|
12
|
+
createGatewayCompletion,
|
|
13
|
+
inlineCompletion,
|
|
14
|
+
type GatewayCompletion,
|
|
15
|
+
type GhostView,
|
|
16
|
+
} from '@widgetic/design-system/inline-completion';
|
|
17
|
+
// A `#` in the box names a file attached to the draft ("use #hero_banner as the header"): the menu with thumbnails, the badge in the
|
|
18
|
+
// text and the label of each file are the design system's, and so is the guard that keeps a label out of the suggestions.
|
|
19
|
+
import {
|
|
20
|
+
assignReferenceLabel,
|
|
21
|
+
collectReferences,
|
|
22
|
+
genericLabelNumber,
|
|
23
|
+
neutralizingSource,
|
|
24
|
+
normalizeForSend,
|
|
25
|
+
promptReferences,
|
|
26
|
+
unbadgeTokensWithoutFiles,
|
|
27
|
+
type NeutralizingSettings,
|
|
28
|
+
type PromptReferencesParams,
|
|
29
|
+
type ReferenceHoverEvent,
|
|
30
|
+
type ReferenceMenuStatus
|
|
31
|
+
} from '@widgetic/design-system/prompt-references';
|
|
32
|
+
// The assistant's face: the chat's turn (the avatar with its content beside it) and its rules for the avatar's look, with the
|
|
33
|
+
// brand's mascot as the drawing. The chat itself is not used: this panel keeps its own transcript, cards and composer.
|
|
34
|
+
import { AgentTurn, liveAgentLook, settledAgentLook } from '@widgetic/chat';
|
|
35
|
+
import type { AgentAvatarRenderProps, AgentLook } from '@widgetic/chat';
|
|
36
|
+
import { Mascot, warmUpMascot } from '@widgetic/brand/mascot';
|
|
7
37
|
import { useEditorState } from '../../editor/editorState.svelte.js';
|
|
8
38
|
import {
|
|
9
39
|
emptyAssistantUiState,
|
|
10
40
|
reduceAssistantUiState,
|
|
41
|
+
type AssistantUiAction,
|
|
11
42
|
type AssistantUiState,
|
|
12
43
|
} from '../../assistant/assistantEvents.js';
|
|
13
44
|
import {
|
|
@@ -22,62 +53,581 @@
|
|
|
22
53
|
parseAssistantSseStream,
|
|
23
54
|
} from '../../assistant/assistantStream.js';
|
|
24
55
|
import { editorActionForSaveMode } from '../../assistant/assistantSaveMode.js';
|
|
56
|
+
import { composerAfterSeed, type ReadyAssistantSeed } from '../../assistant/assistantSeed.js';
|
|
57
|
+
import {
|
|
58
|
+
assistantMoment,
|
|
59
|
+
groupAssistantTurns,
|
|
60
|
+
momentKeepsAvatarSmall,
|
|
61
|
+
type AssistantMoment,
|
|
62
|
+
} from '../../assistant/assistantTurns.js';
|
|
63
|
+
import {
|
|
64
|
+
addCompositionReference,
|
|
65
|
+
caretAfterMentionInsert,
|
|
66
|
+
compositionReferencesForPayload,
|
|
67
|
+
findActiveMentionTrigger,
|
|
68
|
+
insertMentionText,
|
|
69
|
+
removeCompositionReference,
|
|
70
|
+
type CompositionReference,
|
|
71
|
+
} from '../../assistant/compositionMention.js';
|
|
72
|
+
import {
|
|
73
|
+
buildMentionEntries,
|
|
74
|
+
firstSelectableIndex,
|
|
75
|
+
mentionEntryIsSelectable,
|
|
76
|
+
nextSelectableIndex,
|
|
77
|
+
type MentionEntry,
|
|
78
|
+
} from '../../assistant/mentionEntries.js';
|
|
79
|
+
import {
|
|
80
|
+
addMcpReference,
|
|
81
|
+
mcpReferencesForPayload,
|
|
82
|
+
removeMcpReference,
|
|
83
|
+
type McpReference,
|
|
84
|
+
} from '../../assistant/mcpMention.js';
|
|
85
|
+
import { liveDataIsReady, previewsOutsideCard } from '../../assistant/liveData.js';
|
|
86
|
+
import {
|
|
87
|
+
attachmentChipProgress,
|
|
88
|
+
createUploadRegistry,
|
|
89
|
+
failAttachment,
|
|
90
|
+
finishAttachment,
|
|
91
|
+
removeAttachment,
|
|
92
|
+
setAttachmentProgress,
|
|
93
|
+
startAttachment,
|
|
94
|
+
} from '../../assistant/attachmentUploads.js';
|
|
95
|
+
import { orderPlanFlowNodes, planFlowTransitionLabels } from '../../assistant/planFlow.js';
|
|
96
|
+
import {
|
|
97
|
+
effectiveTemplateProjectId,
|
|
98
|
+
templateProjectIdForApproval,
|
|
99
|
+
} from '../../assistant/templateDestinations.js';
|
|
100
|
+
import {
|
|
101
|
+
WORKFLOW_ASSISTANT_SUGGEST_SURFACE,
|
|
102
|
+
workflowSuggestContext,
|
|
103
|
+
} from '../../assistant/assistantSuggest.js';
|
|
104
|
+
import {
|
|
105
|
+
ASSISTANT_MAX_REFERENCES,
|
|
106
|
+
attachmentReferenceFields,
|
|
107
|
+
isPictureFile,
|
|
108
|
+
readyMediaIdsOfChips,
|
|
109
|
+
referenceItemsOfChips,
|
|
110
|
+
referenceLabelsOfChips,
|
|
111
|
+
referenceTargetsOfChips,
|
|
112
|
+
} from '../../assistant/assistantReferences.js';
|
|
25
113
|
import type { AssistantAttachmentChip, WorkflowAssistantConfig } from '../../assistant/types.js';
|
|
26
114
|
import { dsButtonVariant } from '../ui/dsButtonProps.js';
|
|
115
|
+
import Icon from '../ui/Icon.svelte';
|
|
116
|
+
import { hasBuildToWatch } from '../../assistant/canvasLink.js';
|
|
117
|
+
import AssistantPlanStepRow from './AssistantPlanStepRow.svelte';
|
|
27
118
|
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
28
119
|
import type { WorkflowsMessageKey } from '../../i18n/messages.js';
|
|
120
|
+
import CompositionMentionMenu from './CompositionMentionMenu.svelte';
|
|
121
|
+
import DataPreviewCard from './DataPreviewCard.svelte';
|
|
122
|
+
import PlanBindingsBlock from './PlanBindingsBlock.svelte';
|
|
123
|
+
import TemplateProjectCard from './TemplateProjectCard.svelte';
|
|
29
124
|
|
|
30
125
|
interface Props {
|
|
31
126
|
workflowId: string;
|
|
32
127
|
config: WorkflowAssistantConfig;
|
|
128
|
+
/** The first message the page left waiting for the assistant of this workflow. Read once, when the panel is first drawn. */
|
|
129
|
+
seed?: ReadyAssistantSeed | null;
|
|
130
|
+
/** The seed was written to the composer, or left alone because the person had already begun. Called once, with no arguments. */
|
|
131
|
+
onseedapplied?: () => void;
|
|
33
132
|
}
|
|
34
133
|
|
|
35
|
-
let { workflowId, config }: Props = $props();
|
|
134
|
+
let { workflowId, config, seed = null, onseedapplied }: Props = $props();
|
|
135
|
+
// One id for this panel, so the ids of the elements the box points at are never the ones of another panel on the page
|
|
136
|
+
const panelId = $props.id();
|
|
36
137
|
|
|
37
138
|
const editor = useEditorState();
|
|
38
|
-
const
|
|
139
|
+
const api = useWorkflowsApi();
|
|
140
|
+
const { t, locale } = useWorkflowsLanguage();
|
|
39
141
|
const journal = createAssistantTranscriptJournal();
|
|
40
142
|
|
|
41
143
|
let collapsed = $state(false);
|
|
42
144
|
let draft = $state('');
|
|
43
145
|
let ui = $state<AssistantUiState>({ ...emptyAssistantUiState });
|
|
44
146
|
let attachments = $state<AssistantAttachmentChip[]>([]);
|
|
147
|
+
// The upload of each file that is still going up, so that removing its chip can stop it.
|
|
148
|
+
const uploads = createUploadRegistry();
|
|
149
|
+
let compositionReferences = $state<CompositionReference[]>([]);
|
|
150
|
+
let compositionCatalog = $state.raw<readonly CompositionOption[]>([]);
|
|
151
|
+
// The Open MCPs the person picked with @. Unlike the compositions they stay for the rest of the conversation (see `sendMessage`).
|
|
152
|
+
let mcpReferences = $state<McpReference[]>([]);
|
|
153
|
+
// The person's Open MCPs, as the menu lists them; asked for each time the menu opens (see `refreshMcpCatalog`).
|
|
154
|
+
let mcpCatalog = $state.raw<readonly OpenMcpOption[]>([]);
|
|
155
|
+
let isLoadingMcpCatalog = false;
|
|
156
|
+
// The plan the person said yes to ("anyone who opens these embeds sees this data"). A new plan has another id, so it asks
|
|
157
|
+
// again by itself, with nothing to reset.
|
|
158
|
+
let acknowledgedPlanId = $state<string | null>(null);
|
|
45
159
|
let isApproving = $state(false);
|
|
160
|
+
// The project the person picked for the template copies, and the plan it was picked on: a new plan starts from its default.
|
|
161
|
+
let pickedTemplateProject = $state<{ planId: string; projectId: string } | null>(null);
|
|
46
162
|
let selectedOptionId = $state<string | null>(null);
|
|
163
|
+
let composerElement = $state<HTMLTextAreaElement | null>(null);
|
|
164
|
+
let mentionOpen = $state(false);
|
|
165
|
+
let mentionHighlight = $state(0);
|
|
166
|
+
let mentionTriggerStart = $state(0);
|
|
167
|
+
let mentionCaret = $state(0);
|
|
168
|
+
let mentionQuery = $state('');
|
|
169
|
+
|
|
170
|
+
// The rows of the menu: the person's Open MCPs first, then their compositions, both filtered by what follows the @.
|
|
171
|
+
const mentionItems = $derived.by((): readonly MentionEntry[] => {
|
|
172
|
+
if (!mentionOpen) return [];
|
|
173
|
+
const trigger = findActiveMentionTrigger(draft, mentionCaret);
|
|
174
|
+
if (!trigger) return [];
|
|
175
|
+
return buildMentionEntries(trigger.query, compositionCatalog, mcpCatalog);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// The row that is highlighted: the one the person moved to, or the first one that can be picked (the rows change as the lists load).
|
|
179
|
+
const mentionActiveIndex = $derived.by(() => {
|
|
180
|
+
const highlighted = mentionItems[mentionHighlight];
|
|
181
|
+
return highlighted && mentionEntryIsSelectable(highlighted)
|
|
182
|
+
? mentionHighlight
|
|
183
|
+
: firstSelectableIndex(mentionItems);
|
|
184
|
+
});
|
|
47
185
|
|
|
48
186
|
const hasFailedPlanStep = $derived(ui.planCard?.steps.some((step) => step.status === 'failed') ?? false);
|
|
187
|
+
/** True while a widget of the plan is being built and has a canvas to open: the card then says what the links are for. */
|
|
188
|
+
const isBuildWatchable = $derived(
|
|
189
|
+
ui.planCard ? hasBuildToWatch(ui.planCard.steps, config.canvasHref) : false,
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
// "Desired Run Facts": what the LATEST run of the assistant (a message sent, or a plan approved) came to, which is what its
|
|
193
|
+
// face shows. Cards, replies and conclusions of earlier runs stay on screen until the person starts again, so the screen alone
|
|
194
|
+
// cannot tell a card that waits for an answer from one that was answered long ago.
|
|
195
|
+
let hasRunFailed = $state(false);
|
|
196
|
+
let hasRunSucceeded = $state(false);
|
|
197
|
+
let hasRunBroughtCard = $state(false);
|
|
198
|
+
|
|
199
|
+
/** How long the mascot's WebGL context is kept ready for the next one, in milliseconds: two minutes, as the creator keeps it. */
|
|
200
|
+
const MASCOT_KEEP_WARM_MILLISECONDS = 120_000;
|
|
201
|
+
/** A turn that is not the newest: a small still picture, so a long conversation keeps one mascot moving and not one per turn. */
|
|
202
|
+
const stillAvatarLook: AgentLook = { state: 'idle', size: 'small', live: false };
|
|
203
|
+
|
|
204
|
+
// "Desired Mascot": the assistant is drawn as the Scribble Mascot unless the host says false (a partner can turn it off)
|
|
205
|
+
const isMascotEnabled = $derived(config.agentMascot !== false);
|
|
206
|
+
|
|
207
|
+
// Work with no words of its own: the widgets of an approved plan are being built
|
|
208
|
+
const isBuildingPlan = $derived(
|
|
209
|
+
isApproving || (ui.planCard?.steps.some((step) => step.status === 'creating') ?? false),
|
|
210
|
+
);
|
|
211
|
+
// A question, or a plan nobody has approved yet, that the latest run brought and the person has not answered or dismissed
|
|
212
|
+
const hasCardToAnswer = $derived(
|
|
213
|
+
hasRunBroughtCard &&
|
|
214
|
+
(ui.questionCard !== null ||
|
|
215
|
+
(ui.planCard !== null && ui.planCard.steps.every((step) => step.status === 'waiting'))),
|
|
216
|
+
);
|
|
217
|
+
// "Desired Assistant Moment": what the assistant is doing right now, as far as its avatar cares
|
|
218
|
+
const currentAssistantMoment: AssistantMoment = $derived(
|
|
219
|
+
assistantMoment({
|
|
220
|
+
isStreaming: ui.isStreaming,
|
|
221
|
+
hasReplyStarted: ui.messages[ui.messages.length - 1]?.role === 'assistant',
|
|
222
|
+
isBuilding: isBuildingPlan,
|
|
223
|
+
hasCardToAnswer,
|
|
224
|
+
hasFailed: hasRunFailed,
|
|
225
|
+
hasSucceeded: hasRunSucceeded,
|
|
226
|
+
}),
|
|
227
|
+
);
|
|
228
|
+
// The newest turn's avatar follows the chat's own rules for the moment (the panel is narrow, so a card waiting keeps the
|
|
229
|
+
// small avatar: see `momentKeepsAvatarSmall`); the turns before it rest
|
|
230
|
+
const newestAvatarLook: AgentLook = $derived.by(() => {
|
|
231
|
+
const chatLook =
|
|
232
|
+
currentAssistantMoment.kind === 'live'
|
|
233
|
+
? liveAgentLook(currentAssistantMoment.phase)
|
|
234
|
+
: settledAgentLook(currentAssistantMoment.outcome, true);
|
|
235
|
+
return momentKeepsAvatarSmall(currentAssistantMoment) ? { ...chatLook, size: 'small' } : chatLook;
|
|
236
|
+
});
|
|
237
|
+
// Something of the assistant's is on screen after the transcript, so the last turn is its own even when the person spoke last
|
|
238
|
+
const hasLiveContent = $derived(
|
|
239
|
+
ui.isStreaming ||
|
|
240
|
+
isBuildingPlan ||
|
|
241
|
+
ui.questionCard !== null ||
|
|
242
|
+
ui.planCard !== null ||
|
|
243
|
+
ui.completionMessage !== null ||
|
|
244
|
+
hasRunFailed,
|
|
245
|
+
);
|
|
246
|
+
// "Desired Turns": the transcript as rows, the assistant's messages in a row being one turn with one face
|
|
247
|
+
const transcriptTurns = $derived(groupAssistantTurns(ui.messages, hasLiveContent));
|
|
248
|
+
|
|
249
|
+
// Said once for each change of what the assistant is doing, never on every redraw
|
|
250
|
+
let lastReportedMoment = '';
|
|
251
|
+
$effect(() => {
|
|
252
|
+
const momentSignature = [
|
|
253
|
+
currentAssistantMoment.kind,
|
|
254
|
+
currentAssistantMoment.kind === 'live' ? currentAssistantMoment.phase : currentAssistantMoment.outcome,
|
|
255
|
+
].join('/');
|
|
256
|
+
if (momentSignature === lastReportedMoment) return;
|
|
257
|
+
lastReportedMoment = momentSignature;
|
|
258
|
+
console.debug('[workflows-assistant] the assistant is now', momentSignature);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
// The first mascot of a page waits for Three.js, the WebGL context and the shader (a still picture until then). They are got
|
|
262
|
+
// ready once the panel is open, so the first thing the assistant does starts moving at once. With the mascot off, nothing is fetched.
|
|
263
|
+
$effect(() => {
|
|
264
|
+
if (collapsed || !isMascotEnabled) return;
|
|
265
|
+
try {
|
|
266
|
+
// The brand never throws and never rejects: a page without WebGL gets the poster, as every mascot does
|
|
267
|
+
void warmUpMascot({ keepWarmForMilliseconds: MASCOT_KEEP_WARM_MILLISECONDS });
|
|
268
|
+
} catch (error) {
|
|
269
|
+
console.debug(
|
|
270
|
+
'[workflows-assistant] the mascot could not be warmed up; the first one starts as it always did',
|
|
271
|
+
error,
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
// The live data of the plan on the card (none for an ordinary plan), and what follows from it.
|
|
277
|
+
const planBindings = $derived(ui.planCard?.bindings ?? []);
|
|
278
|
+
// A plan that only turns live data on has no widget to build and no workflow to save: the card leaves out what is about building.
|
|
279
|
+
const isLiveDataOnlyPlan = $derived(planBindings.length > 0 && (ui.planCard?.steps.length ?? 0) === 0);
|
|
280
|
+
// Live data is on for every composition of the plan (the approval is over, and pressing it again would only be refused).
|
|
281
|
+
const liveDataIsOn = $derived(ui.planCard ? liveDataIsReady(ui.planCard) : false);
|
|
282
|
+
// The previews no plan block shows: the ones a block shows are drawn inside it.
|
|
283
|
+
const previewsOutsidePlan = $derived(previewsOutsideCard(ui.dataPreviews, planBindings));
|
|
284
|
+
// Only a plan with live data asks for the yes, and it asks for each new plan.
|
|
285
|
+
const currentPlanId = $derived(ui.planCard?.planId ?? null);
|
|
286
|
+
const exposureAcknowledged = $derived(currentPlanId !== null && acknowledgedPlanId === currentPlanId);
|
|
287
|
+
const needsExposureConsent = $derived(planBindings.length > 0 && !exposureAcknowledged);
|
|
288
|
+
|
|
289
|
+
// Where the copies of the plan's template widgets go: asked only when the gateway sent a choice (two projects or more).
|
|
290
|
+
const templateDestinations = $derived(ui.planCard?.templateDestinations ?? null);
|
|
291
|
+
const pickedTemplateProjectId = $derived(
|
|
292
|
+
ui.planCard && pickedTemplateProject?.planId === ui.planCard.planId ? pickedTemplateProject.projectId : null,
|
|
293
|
+
);
|
|
294
|
+
const chosenTemplateProjectId = $derived(
|
|
295
|
+
templateDestinations ? effectiveTemplateProjectId(templateDestinations, pickedTemplateProjectId) : null,
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
// The widgets of the plan in the order a visitor meets them (shown as chips), and what moves a visitor on from one to the next.
|
|
299
|
+
const planFlowNodes = $derived(ui.planCard ? orderPlanFlowNodes(ui.planCard.planWire.flow) : []);
|
|
300
|
+
const planFlowTransitions = $derived(ui.planCard ? planFlowTransitionLabels(ui.planCard.planWire.flow) : []);
|
|
301
|
+
|
|
302
|
+
// "Desired Suggestions": the grey words after what the person has typed (Tab takes them, typing on or Esc sends them away). The
|
|
303
|
+
// host gives a suggest route or it does not: without one the box has no suggestions and the panel is what it always was.
|
|
304
|
+
// A suggestion is on the screen now: the hint beside the box says what Tab does with it
|
|
305
|
+
let suggestionShows = $state(false);
|
|
306
|
+
// The line of the hint stays once it has been needed, so the panel does not move each time a suggestion comes and goes
|
|
307
|
+
let isHintLineKept = $state(false);
|
|
308
|
+
// The routes are read as plain text, so a host that hands in a new config object with the same routes does not start the box over
|
|
309
|
+
const suggestRoute = $derived(config.suggestUrl || undefined);
|
|
310
|
+
const outcomeRoute = $derived(config.outcomeUrl || undefined);
|
|
311
|
+
|
|
312
|
+
// What the engine says it did, quietly and once per kind of thing (a gateway that is down is one line, not one per keystroke)
|
|
313
|
+
function logCompletion(message: string, detail?: Record<string, unknown>): void {
|
|
314
|
+
console.debug('[workflows-assistant] suggestions:', message, detail ?? '');
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// The box of suggestions for the routes the host gave, or null without a suggest route. It is made again only when a route changes.
|
|
318
|
+
const completion = $derived.by<GatewayCompletion | null>(() => {
|
|
319
|
+
const suggestUrl = suggestRoute;
|
|
320
|
+
if (!suggestUrl) return null;
|
|
321
|
+
try {
|
|
322
|
+
return createGatewayCompletion({
|
|
323
|
+
surface: WORKFLOW_ASSISTANT_SUGGEST_SURFACE,
|
|
324
|
+
suggestUrl,
|
|
325
|
+
outcomeUrl: outcomeRoute,
|
|
326
|
+
headers: authHeaders,
|
|
327
|
+
// The calls carry the person's token and not a cookie, as the stream's do
|
|
328
|
+
credentials: 'omit',
|
|
329
|
+
locale: () => $locale,
|
|
330
|
+
// What the box says about itself: how many steps the open workflow holds
|
|
331
|
+
context: () => workflowSuggestContext(editor.graph.nodes.length),
|
|
332
|
+
log: logCompletion,
|
|
333
|
+
});
|
|
334
|
+
} catch (error) {
|
|
335
|
+
console.debug(
|
|
336
|
+
'[workflows-assistant] the suggestions could not be set up; the box shows none',
|
|
337
|
+
error,
|
|
338
|
+
);
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
// What a box counted goes out when another one replaces it (the host gave other routes) and when the panel goes away
|
|
344
|
+
$effect(() => {
|
|
345
|
+
const countingCompletion = completion;
|
|
346
|
+
return () => countingCompletion?.destroy();
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
// The suggestion on the screen comes and goes: the hint beside the box follows it. The hint is for the first suggestion only: the
|
|
350
|
+
// design system's action notes the first one taken (before it tells the box the grey words are gone), and from then on the box has no
|
|
351
|
+
// hint and no line for one, so the panel is as it is without suggestions.
|
|
352
|
+
function handleSuggestionChange(suggestion: GhostView | null): void {
|
|
353
|
+
suggestionShows = suggestion !== null;
|
|
354
|
+
if (completionHintMemory.learned) {
|
|
355
|
+
isHintLineKept = false;
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
if (suggestionShows) isHintLineKept = true;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// What a screen reader hears when a suggestion shows: the words typed with the suggestion in them (a badge is read as its `#label`:
|
|
362
|
+
// the room it takes in the box is not part of the words)
|
|
363
|
+
function describeSuggestion(suggestionText: string): string {
|
|
364
|
+
return $t('workflows.assistant.suggestionAnnouncement', {
|
|
365
|
+
text: `${normalizeForSend(draft)}${suggestionText}`.trim(),
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// "Desired References": the files attached to the draft can be named in the text with a `#` (`#hero_banner`). The menu lists them
|
|
370
|
+
// with their thumbnails, a badge with the picture stands in the text, and the request says which file each word means. A file's
|
|
371
|
+
// label is made when it is attached and lives in the draft only: a chat started over starts its numbers over.
|
|
372
|
+
/** The highest `Image_N` handed out in this draft, so a number is never given twice, not even when its file has left. */
|
|
373
|
+
let referenceGenericFloor = 0;
|
|
374
|
+
/** The label of the file a badge or a menu row is on now: the chip of the same file in the tray above the box gets a ring. */
|
|
375
|
+
let hoveredReferenceLabel = $state<string | null>(null);
|
|
376
|
+
/** The `#` menu is open: the grey suggestion of the same box goes while it is (one popup at a time, the menu owns the keys). */
|
|
377
|
+
let referenceMenuOpen = $state(false);
|
|
378
|
+
/** The addresses the browser made for the pictures of the draft: given back when the chat starts over and when the panel goes. */
|
|
379
|
+
const previewUrlsMade: string[] = [];
|
|
380
|
+
/** The line under the box that says how to name a file: the box points at it while there is a file to name. */
|
|
381
|
+
const referenceHintId = `${panelId}-reference-hint`;
|
|
382
|
+
|
|
383
|
+
// The files the menu offers, in the order they were attached
|
|
384
|
+
const referenceItems = $derived(referenceItemsOfChips(attachments));
|
|
385
|
+
|
|
386
|
+
// What a suggestion service may see of the files attached now, read at each request: the wrapper below is made once for a source,
|
|
387
|
+
// so files coming and going do not start the box's suggestions over
|
|
388
|
+
function readNeutralizingSettings(): NeutralizingSettings {
|
|
389
|
+
return { labels: referenceLabelsOfChips(attachments) };
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// Where the suggestions come from: a file's name never reaches the service, because each reference in the text is the neutral
|
|
393
|
+
// word `#file` by then (a label is made from a file's name, and the text of the box is what the service completes)
|
|
394
|
+
const suggestionSource = $derived(neutralizingSource(completion?.source, readNeutralizingSettings));
|
|
395
|
+
|
|
396
|
+
function showReferenceHover(event: ReferenceHoverEvent): void {
|
|
397
|
+
hoveredReferenceLabel = event.label;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function showReferenceMenuStatus(status: ReferenceMenuStatus): void {
|
|
401
|
+
referenceMenuOpen = status.open;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// What the `#` action says about itself: one line per thing that happened, never one per key
|
|
405
|
+
function logReferences(message: string, detail?: unknown): void {
|
|
406
|
+
console.debug('[workflows-assistant] references:', message, detail ?? '');
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// What the `#` action is told. `value` is there so a text the panel changes by itself (the box clears after a send) repaints the badges.
|
|
410
|
+
const referenceParams = $derived<PromptReferencesParams>({
|
|
411
|
+
items: referenceItems,
|
|
412
|
+
messages: {
|
|
413
|
+
menuLabel: $t('workflows.assistant.referenceMenuLabel'),
|
|
414
|
+
// The action fills `{name}` with the file's name
|
|
415
|
+
remove: $t('workflows.assistant.referenceRemove', { name: '{name}' }),
|
|
416
|
+
},
|
|
417
|
+
value: draft,
|
|
418
|
+
onHover: showReferenceHover,
|
|
419
|
+
onMenuChange: showReferenceMenuStatus,
|
|
420
|
+
logger: logReferences,
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
// Whether the chip of a file is the one a badge or a menu row is on (a label is the same word in any case)
|
|
424
|
+
function isReferenceHovered(chip: AssistantAttachmentChip): boolean {
|
|
425
|
+
return (
|
|
426
|
+
hoveredReferenceLabel !== null &&
|
|
427
|
+
chip.label !== undefined &&
|
|
428
|
+
chip.label.toLowerCase() === hoveredReferenceLabel.toLowerCase()
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// A thumbnail of a picture the person attached, from the file in their hands (nothing is fetched). Other kinds of file have none.
|
|
433
|
+
function makePreviewUrl(file: File): string | undefined {
|
|
434
|
+
if (!isPictureFile(file)) return undefined;
|
|
435
|
+
try {
|
|
436
|
+
const previewUrl = URL.createObjectURL(file);
|
|
437
|
+
previewUrlsMade.push(previewUrl);
|
|
438
|
+
return previewUrl;
|
|
439
|
+
} catch (error) {
|
|
440
|
+
console.debug('[workflows-assistant] no thumbnail could be made for a file; its chip has none', error);
|
|
441
|
+
return undefined;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// The addresses made for the pictures go back to the browser
|
|
446
|
+
function releasePreviewUrls(): void {
|
|
447
|
+
for (const previewUrl of previewUrlsMade.splice(0)) {
|
|
448
|
+
try {
|
|
449
|
+
URL.revokeObjectURL(previewUrl);
|
|
450
|
+
} catch (error) {
|
|
451
|
+
console.debug('[workflows-assistant] a thumbnail could not be given back', error);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
49
455
|
|
|
50
456
|
const welcomeChips: Array<{ key: WorkflowsMessageKey; send: WorkflowsMessageKey }> = [
|
|
51
457
|
{ key: 'workflows.assistant.chipIdeas', send: 'workflows.assistant.chipIdeas' },
|
|
52
458
|
{ key: 'workflows.assistant.chipLeads', send: 'workflows.assistant.chipLeads' },
|
|
53
459
|
];
|
|
54
460
|
|
|
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
461
|
onMount(() => {
|
|
69
462
|
ui = { ...ui, messages: [...readAssistantTranscript(journal, workflowId)] };
|
|
463
|
+
takeInSeed();
|
|
464
|
+
// The pictures of the draft are given back to the browser as the panel goes away
|
|
465
|
+
return releasePreviewUrls;
|
|
70
466
|
});
|
|
71
467
|
|
|
468
|
+
/**
|
|
469
|
+
* The first message the page left for the assistant goes into the composer, not sent: the person reads it, changes it if they
|
|
470
|
+
* want to, and presses Send. It is read once, when the panel is first drawn (the seed is not watched afterwards), and only into an
|
|
471
|
+
* empty composer of a workflow with no conversation yet, so a person who has begun keeps what they have. The page is told either
|
|
472
|
+
* way, so it can stop holding the seed.
|
|
473
|
+
*/
|
|
474
|
+
function takeInSeed(): void {
|
|
475
|
+
if (!seed) return;
|
|
476
|
+
try {
|
|
477
|
+
const outcome = composerAfterSeed({ draft, messageCount: ui.messages.length }, seed);
|
|
478
|
+
if (outcome.applied) {
|
|
479
|
+
draft = outcome.draft;
|
|
480
|
+
// The compositions the page named go in as the chips the `@` menu makes (the seed holds at most 10, each once)
|
|
481
|
+
compositionReferences = outcome.compositionReferences.map((reference) => ({
|
|
482
|
+
id: reference.id,
|
|
483
|
+
name: reference.name,
|
|
484
|
+
}));
|
|
485
|
+
}
|
|
486
|
+
console.debug(
|
|
487
|
+
outcome.applied
|
|
488
|
+
? '[workflows-assistant] the first message the page left is in the composer'
|
|
489
|
+
: '[workflows-assistant] the first message the page left was not used: the person had already begun',
|
|
490
|
+
{ compositions: outcome.compositionReferences.length },
|
|
491
|
+
);
|
|
492
|
+
} catch (error) {
|
|
493
|
+
console.debug('[workflows-assistant] the first message the page left could not be put in the composer', error);
|
|
494
|
+
}
|
|
495
|
+
onseedapplied?.();
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/** A new run begins (the person sent a message or approved the plan), or the chat starts over: the face forgets the last run. */
|
|
499
|
+
function forgetLastRun(): void {
|
|
500
|
+
hasRunFailed = false;
|
|
501
|
+
hasRunSucceeded = false;
|
|
502
|
+
hasRunBroughtCard = false;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/** What one event of a stream says about how the run is going, for the face. The screen itself is the reducer's business. */
|
|
506
|
+
function noteRunEvent(action: AssistantUiAction): void {
|
|
507
|
+
if (action.type === 'assistant_text' && action.failed) hasRunFailed = true;
|
|
508
|
+
if (action.type === 'plan_step' && action.status === 'failed') hasRunFailed = true;
|
|
509
|
+
if (action.type === 'question_card' || action.type === 'plan_card') hasRunBroughtCard = true;
|
|
510
|
+
if (action.type === 'workflow_ready') hasRunSucceeded = true;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
async function ensureCompositionCatalog(): Promise<void> {
|
|
514
|
+
if (compositionCatalog.length > 0) return;
|
|
515
|
+
try {
|
|
516
|
+
const page = await api.listCompositionOptions({ limit: 50, offset: 0 });
|
|
517
|
+
compositionCatalog = page.items;
|
|
518
|
+
} catch (error) {
|
|
519
|
+
console.debug('[workflows-assistant] composition list for mentions failed', error);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* The person's Open MCPs for the menu. They are asked for each time the menu opens, not once: a server the person just connected
|
|
525
|
+
* in the workspace settings has to be in it. The menu keeps the list it had while the new one comes, and a list that cannot be
|
|
526
|
+
* read leaves it as it was: the menu is a convenience, and compositions can be mentioned without it.
|
|
527
|
+
*/
|
|
528
|
+
async function refreshMcpCatalog(): Promise<void> {
|
|
529
|
+
if (isLoadingMcpCatalog) return;
|
|
530
|
+
isLoadingMcpCatalog = true;
|
|
531
|
+
try {
|
|
532
|
+
mcpCatalog = await api.listMcpOptions();
|
|
533
|
+
} catch (error) {
|
|
534
|
+
console.debug('[workflows-assistant] the Open MCPs for mentions could not be listed', error);
|
|
535
|
+
} finally {
|
|
536
|
+
isLoadingMcpCatalog = false;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function syncMentionFromComposer(): void {
|
|
541
|
+
const caret = composerElement?.selectionStart ?? draft.length;
|
|
542
|
+
mentionCaret = caret;
|
|
543
|
+
const trigger = findActiveMentionTrigger(draft, caret);
|
|
544
|
+
if (trigger) {
|
|
545
|
+
const menuWasOpen = mentionOpen;
|
|
546
|
+
mentionOpen = true;
|
|
547
|
+
mentionTriggerStart = trigger.start;
|
|
548
|
+
// The highlight goes back to the top only when the menu opens or what follows the @ changes: this runs on every key, and
|
|
549
|
+
// an arrow key must not undo its own move when it is released.
|
|
550
|
+
if (!menuWasOpen || trigger.query !== mentionQuery) mentionHighlight = 0;
|
|
551
|
+
mentionQuery = trigger.query;
|
|
552
|
+
void ensureCompositionCatalog();
|
|
553
|
+
if (!menuWasOpen) void refreshMcpCatalog();
|
|
554
|
+
} else {
|
|
555
|
+
mentionOpen = false;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
async function chooseMention(entry: MentionEntry): Promise<void> {
|
|
560
|
+
// A server that cannot be used yet is shown in the menu with its reason and is not taken.
|
|
561
|
+
if (!mentionEntryIsSelectable(entry)) return;
|
|
562
|
+
const caret = composerElement?.selectionStart ?? draft.length;
|
|
563
|
+
const { name } = entry.option;
|
|
564
|
+
draft = insertMentionText(draft, mentionTriggerStart, caret, name);
|
|
565
|
+
if (entry.kind === 'mcp') {
|
|
566
|
+
mcpReferences = [...addMcpReference(mcpReferences, entry.option)];
|
|
567
|
+
} else {
|
|
568
|
+
compositionReferences = [...addCompositionReference(compositionReferences, entry.option)];
|
|
569
|
+
}
|
|
570
|
+
mentionOpen = false;
|
|
571
|
+
const nextCaret = caretAfterMentionInsert(mentionTriggerStart, name);
|
|
572
|
+
await tick();
|
|
573
|
+
composerElement?.focus();
|
|
574
|
+
composerElement?.setSelectionRange(nextCaret, nextCaret);
|
|
575
|
+
mentionCaret = nextCaret;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function handleComposerKeydown(event: KeyboardEvent): void {
|
|
579
|
+
if (mentionOpen && mentionItems.length > 0) {
|
|
580
|
+
if (event.key === 'ArrowDown') {
|
|
581
|
+
event.preventDefault();
|
|
582
|
+
mentionHighlight = nextSelectableIndex(mentionItems, mentionActiveIndex, 1);
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
if (event.key === 'ArrowUp') {
|
|
586
|
+
event.preventDefault();
|
|
587
|
+
mentionHighlight = nextSelectableIndex(mentionItems, mentionActiveIndex, -1);
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
if (event.key === 'Enter' && !event.shiftKey) {
|
|
591
|
+
const highlighted = mentionItems[mentionActiveIndex];
|
|
592
|
+
// A row that cannot be picked takes no Enter: the key then does what it always does in the composer.
|
|
593
|
+
if (highlighted && mentionEntryIsSelectable(highlighted)) {
|
|
594
|
+
event.preventDefault();
|
|
595
|
+
void chooseMention(highlighted);
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
if (mentionOpen && event.key === 'Escape') {
|
|
601
|
+
event.preventDefault();
|
|
602
|
+
mentionOpen = false;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
72
606
|
function persistTranscript(): void {
|
|
73
607
|
writeAssistantTranscript(journal, workflowId, ui.messages);
|
|
74
608
|
}
|
|
75
609
|
|
|
76
|
-
|
|
610
|
+
// The headers of a call to the gateway, as the host gives them: at once, or when it has them (a token refreshed on demand)
|
|
611
|
+
function authHeaders(): Promise<Record<string, string>> | Record<string, string> {
|
|
77
612
|
const headers = config.getAuthHeaders;
|
|
78
613
|
return typeof headers === 'function' ? headers() : headers;
|
|
79
614
|
}
|
|
80
615
|
|
|
616
|
+
/**
|
|
617
|
+
* The assistant changed the draft of the workflow that is open (the chat's own tools saved it, or a widget of an approved plan
|
|
618
|
+
* went into it as its build ended): the editor shows it now, while the chat is still working. It is not awaited, so the rest
|
|
619
|
+
* of the stream is not held up by the look at the server. A change to another workflow is not this editor's to show.
|
|
620
|
+
*/
|
|
621
|
+
function showAssistantChangeOnCanvas(update: { workflowId: string; revision: number | null }): void {
|
|
622
|
+
if (update.workflowId !== workflowId) return;
|
|
623
|
+
console.debug('[workflows-assistant] the assistant saved a change to the draft', {
|
|
624
|
+
revision: update.revision,
|
|
625
|
+
});
|
|
626
|
+
void editor.respondToAssistantWorkflowUpdate(update.revision).catch((error: unknown) => {
|
|
627
|
+
console.debug('[workflows-assistant] the change could not be shown on the canvas', error);
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
|
|
81
631
|
function streamHistory() {
|
|
82
632
|
return ui.messages.map((message) => ({
|
|
83
633
|
role: message.role,
|
|
@@ -89,18 +639,43 @@
|
|
|
89
639
|
text: string,
|
|
90
640
|
answer?: { cardId: string; selectedOptionIds: string[]; selectedOptionLabels?: string[] },
|
|
91
641
|
): Promise<void> {
|
|
92
|
-
|
|
642
|
+
// The words a person wrote ("use #hero_banner as the header"): the room each badge takes in the box is not part of the message
|
|
643
|
+
const messageText = normalizeForSend(text);
|
|
644
|
+
if (!messageText.trim() || ui.isStreaming) return;
|
|
93
645
|
const history = streamHistory();
|
|
94
|
-
|
|
646
|
+
// The files this message carries, and which of them its words name: read from the box's own text, badges and words typed by hand alike
|
|
647
|
+
const sentMediaIds = readyMediaIdsOfChips(attachments);
|
|
648
|
+
const namedFiles = collectReferences(text, referenceTargetsOfChips(attachments), {
|
|
649
|
+
max: ASSISTANT_MAX_REFERENCES,
|
|
650
|
+
});
|
|
651
|
+
forgetLastRun();
|
|
652
|
+
const refs = compositionReferencesForPayload(compositionReferences);
|
|
653
|
+
const mcpRefs = mcpReferencesForPayload(mcpReferences);
|
|
654
|
+
const messageId = crypto.randomUUID();
|
|
655
|
+
ui = reduceAssistantUiState(ui, {
|
|
656
|
+
type: 'user_message',
|
|
657
|
+
id: messageId,
|
|
658
|
+
text: messageText,
|
|
659
|
+
...(refs.length > 0 ? { compositionReferences: refs } : {}),
|
|
660
|
+
...(mcpRefs.length > 0 ? { mcpReferences: mcpRefs } : {}),
|
|
661
|
+
});
|
|
95
662
|
ui = reduceAssistantUiState(ui, { type: 'streaming', value: true });
|
|
96
663
|
persistTranscript();
|
|
97
664
|
const body = {
|
|
98
|
-
message:
|
|
665
|
+
message: messageText,
|
|
99
666
|
workflowId,
|
|
100
667
|
history,
|
|
101
|
-
attachmentMediaIds:
|
|
668
|
+
attachmentMediaIds: sentMediaIds,
|
|
669
|
+
// The files the words name, only when the message names any (the gateway reads them beside `attachmentMediaIds`)
|
|
670
|
+
...attachmentReferenceFields(namedFiles, sentMediaIds),
|
|
671
|
+
...(refs.length > 0 ? { compositionReferences: refs } : {}),
|
|
672
|
+
// The servers the person picked: the assistant may use an Open MCP only when the message names it.
|
|
673
|
+
...(mcpRefs.length > 0 ? { mcpReferences: mcpRefs } : {}),
|
|
102
674
|
...(answer ? { answerToQuestion: answer } : {}),
|
|
103
675
|
};
|
|
676
|
+
if (namedFiles.length > 0) {
|
|
677
|
+
console.debug('[workflows-assistant] the message names files with a #:', namedFiles.length);
|
|
678
|
+
}
|
|
104
679
|
try {
|
|
105
680
|
const response = await fetch(config.streamUrl, {
|
|
106
681
|
method: 'POST',
|
|
@@ -109,6 +684,7 @@
|
|
|
109
684
|
});
|
|
110
685
|
if (!response.ok) {
|
|
111
686
|
console.debug('[workflows-assistant] the stream answered with an error status', response.status);
|
|
687
|
+
hasRunFailed = true;
|
|
112
688
|
ui = reduceAssistantUiState(ui, {
|
|
113
689
|
type: 'assistant_text',
|
|
114
690
|
id: crypto.randomUUID(),
|
|
@@ -117,10 +693,13 @@
|
|
|
117
693
|
} else {
|
|
118
694
|
for await (const action of parseAssistantSseStream(response)) {
|
|
119
695
|
ui = reduceAssistantUiState(ui, action);
|
|
696
|
+
noteRunEvent(action);
|
|
697
|
+
if (action.type === 'workflow_updated') showAssistantChangeOnCanvas(action);
|
|
120
698
|
}
|
|
121
699
|
}
|
|
122
700
|
} catch (error) {
|
|
123
701
|
console.debug('[workflows-assistant] the stream could not be read', error);
|
|
702
|
+
hasRunFailed = true;
|
|
124
703
|
ui = reduceAssistantUiState(ui, {
|
|
125
704
|
type: 'assistant_text',
|
|
126
705
|
id: crypto.randomUUID(),
|
|
@@ -130,7 +709,17 @@
|
|
|
130
709
|
// Whatever happened, the composer is usable again.
|
|
131
710
|
ui = reduceAssistantUiState(ui, { type: 'streaming', value: false });
|
|
132
711
|
persistTranscript();
|
|
133
|
-
|
|
712
|
+
// The composer is emptied when it still holds what was just sent. A message that came from somewhere else (a welcome chip,
|
|
713
|
+
// the answer to a question) leaves what the person is writing, and the compositions it names, where they are: a message
|
|
714
|
+
// the page left in the composer is not lost to a click on a chip.
|
|
715
|
+
if (draft === text) {
|
|
716
|
+
draft = '';
|
|
717
|
+
// A conversation that has an Open MCP in it keeps what the person picked until they remove it or start a new chat: every
|
|
718
|
+
// message has to name the servers (and the compositions the data is for) again, and the answer to a question card would
|
|
719
|
+
// otherwise be sent without them. Other conversations clear the compositions after each message, as they always did.
|
|
720
|
+
if (mcpRefs.length === 0) compositionReferences = [];
|
|
721
|
+
}
|
|
722
|
+
mentionOpen = false;
|
|
134
723
|
selectedOptionId = null;
|
|
135
724
|
}
|
|
136
725
|
}
|
|
@@ -138,34 +727,92 @@
|
|
|
138
727
|
async function onAttachFiles(event: Event): Promise<void> {
|
|
139
728
|
const input = event.target as HTMLInputElement;
|
|
140
729
|
const files = input.files ? [...input.files] : [];
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
entry.fileName === file.name ? { ...entry, state: 'error' as const } : entry,
|
|
158
|
-
);
|
|
159
|
-
}
|
|
730
|
+
// Every chosen file gets its chip at once (at 0%); the files then go up one after the other.
|
|
731
|
+
const queued = files.map((file) => ({ file, id: crypto.randomUUID() }));
|
|
732
|
+
for (const { file, id } of queued) {
|
|
733
|
+
// The word that names this file after a `#`: made from its name, and never one that another file of the draft has
|
|
734
|
+
const referenceLabel = assignReferenceLabel(file.name, {
|
|
735
|
+
takenLabels: referenceLabelsOfChips(attachments),
|
|
736
|
+
genericNumberFloor: referenceGenericFloor,
|
|
737
|
+
});
|
|
738
|
+
referenceGenericFloor = Math.max(referenceGenericFloor, genericLabelNumber(referenceLabel) ?? 0);
|
|
739
|
+
const previewUrl = makePreviewUrl(file);
|
|
740
|
+
attachments = startAttachment(attachments, id, file.name).map((entry) =>
|
|
741
|
+
entry.id === id ? { ...entry, label: referenceLabel, previewUrl } : entry,
|
|
742
|
+
);
|
|
743
|
+
}
|
|
744
|
+
for (const { file, id } of queued) {
|
|
745
|
+
await uploadAttachment(file, id);
|
|
160
746
|
}
|
|
161
747
|
input.value = '';
|
|
162
748
|
}
|
|
163
749
|
|
|
750
|
+
/** Sends one file to the library; its chip fills as the host reports progress and is ready when the library has it. */
|
|
751
|
+
async function uploadAttachment(file: File, id: string): Promise<void> {
|
|
752
|
+
// The person removed the chip while the file waited for its turn: there is nothing to send.
|
|
753
|
+
if (!attachments.some((entry) => entry.id === id)) return;
|
|
754
|
+
const controller = uploads.start(id);
|
|
755
|
+
try {
|
|
756
|
+
const saved = await config.uploadFileToLibrary(file, {
|
|
757
|
+
onProgress: (percentage) => {
|
|
758
|
+
attachments = setAttachmentProgress(attachments, id, percentage);
|
|
759
|
+
},
|
|
760
|
+
signal: controller.signal,
|
|
761
|
+
});
|
|
762
|
+
attachments = finishAttachment(attachments, id, saved.mediaId);
|
|
763
|
+
} catch (error) {
|
|
764
|
+
// Aborting is the person's own choice (the chip is gone); anything else is worth a line in the console.
|
|
765
|
+
if (!controller.signal.aborted) {
|
|
766
|
+
console.debug('[workflows-assistant] a file could not be uploaded', file.name, error);
|
|
767
|
+
}
|
|
768
|
+
attachments = failAttachment(attachments, id);
|
|
769
|
+
unbadgeReferencesOfMissingFiles();
|
|
770
|
+
} finally {
|
|
771
|
+
uploads.finish(id);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
/** The x of an attachment chip: the chip goes, and a file that is still going up stops. */
|
|
776
|
+
function removeAttachmentChip(id: string): void {
|
|
777
|
+
uploads.abort(id);
|
|
778
|
+
attachments = removeAttachment(attachments, id);
|
|
779
|
+
unbadgeReferencesOfMissingFiles();
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/** A file that did not go up (or was taken away) cannot be named: the badge that stands for it becomes the plain word again. */
|
|
783
|
+
function unbadgeReferencesOfMissingFiles(): void {
|
|
784
|
+
const textWithoutBadgeOfMissingFiles = unbadgeTokensWithoutFiles(
|
|
785
|
+
draft,
|
|
786
|
+
referenceItemsOfChips(attachments).map((item) => item.label),
|
|
787
|
+
);
|
|
788
|
+
if (textWithoutBadgeOfMissingFiles !== draft) draft = textWithoutBadgeOfMissingFiles;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* The props that give the chip of a file its progress background. The design-system release that adds them is newer
|
|
793
|
+
* than the one this package builds against, so they go in as one spread: an older release ignores them and the chip
|
|
794
|
+
* simply stays empty while the file goes up.
|
|
795
|
+
*/
|
|
796
|
+
function attachmentChipProgressProps(file: AssistantAttachmentChip): Record<string, unknown> {
|
|
797
|
+
const progress = attachmentChipProgress(file);
|
|
798
|
+
if (progress === undefined) return {};
|
|
799
|
+
return {
|
|
800
|
+
progress,
|
|
801
|
+
progressLabel: $t('workflows.assistant.uploadProgress', { percent: Math.round(progress) }),
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
|
|
164
805
|
async function approvePlan(): Promise<void> {
|
|
165
806
|
const planCard = ui.planCard;
|
|
166
807
|
if (!planCard || isApproving) return;
|
|
808
|
+
// A plan with live data is approved only with the person's yes (the gateway refuses it without): the button is off until then.
|
|
809
|
+
const hasLiveData = (planCard.bindings?.length ?? 0) > 0;
|
|
810
|
+
if (hasLiveData && !exposureAcknowledged) return;
|
|
167
811
|
isApproving = true;
|
|
812
|
+
forgetLastRun();
|
|
168
813
|
ui = reduceAssistantUiState(ui, { type: 'streaming', value: true });
|
|
814
|
+
// The project chosen for the template copies goes beside the plan, not in it: the plan is signed and goes back as it came.
|
|
815
|
+
const templateProjectId = templateProjectIdForApproval(planCard.templateDestinations, pickedTemplateProjectId);
|
|
169
816
|
try {
|
|
170
817
|
const response = await fetch(config.approveUrl, {
|
|
171
818
|
method: 'POST',
|
|
@@ -175,10 +822,13 @@
|
|
|
175
822
|
planToken: planCard.planToken,
|
|
176
823
|
workflowId,
|
|
177
824
|
plan: planCard.planWire,
|
|
825
|
+
...(templateProjectId ? { templateProjectId } : {}),
|
|
826
|
+
...(hasLiveData ? { exposureAcknowledged: true } : {}),
|
|
178
827
|
}),
|
|
179
828
|
});
|
|
180
829
|
if (!response.ok) {
|
|
181
830
|
console.debug('[workflows-assistant] the approval answered with an error status', response.status);
|
|
831
|
+
hasRunFailed = true;
|
|
182
832
|
ui = reduceAssistantUiState(ui, {
|
|
183
833
|
type: 'assistant_text',
|
|
184
834
|
id: crypto.randomUUID(),
|
|
@@ -187,6 +837,9 @@
|
|
|
187
837
|
} else {
|
|
188
838
|
for await (const action of parseAssistantApproveStream(response)) {
|
|
189
839
|
ui = reduceAssistantUiState(ui, action);
|
|
840
|
+
noteRunEvent(action);
|
|
841
|
+
// The widgets of the plan go into the open workflow as their builds end: the canvas fills while the others build
|
|
842
|
+
if (action.type === 'workflow_updated') showAssistantChangeOnCanvas(action);
|
|
190
843
|
if (action.type === 'workflow_ready') {
|
|
191
844
|
if (editorActionForSaveMode(action.mode) === 'open_new') {
|
|
192
845
|
editor.goToWorkflow(action.workflowId);
|
|
@@ -199,6 +852,7 @@
|
|
|
199
852
|
} catch (error) {
|
|
200
853
|
// A dropped connection: the builds may still be running on the server, so say so rather than leave the card spinning.
|
|
201
854
|
console.debug('[workflows-assistant] the approval stream ended early', error);
|
|
855
|
+
hasRunFailed = true;
|
|
202
856
|
ui = reduceAssistantUiState(ui, {
|
|
203
857
|
type: 'assistant_text',
|
|
204
858
|
id: crypto.randomUUID(),
|
|
@@ -223,11 +877,181 @@
|
|
|
223
877
|
function newChat(): void {
|
|
224
878
|
clearAssistantTranscript(journal, workflowId);
|
|
225
879
|
ui = { ...emptyAssistantUiState };
|
|
880
|
+
forgetLastRun();
|
|
226
881
|
attachments = [];
|
|
882
|
+
compositionReferences = [];
|
|
883
|
+
mcpReferences = [];
|
|
884
|
+
acknowledgedPlanId = null;
|
|
227
885
|
draft = '';
|
|
886
|
+
mentionOpen = false;
|
|
887
|
+
pickedTemplateProject = null;
|
|
888
|
+
// The draft starts over: its numbers, its pictures and what it was pointing at
|
|
889
|
+
referenceGenericFloor = 0;
|
|
890
|
+
hoveredReferenceLabel = null;
|
|
891
|
+
releasePreviewUrls();
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
function removeReference(id: string): void {
|
|
895
|
+
compositionReferences = [...removeCompositionReference(compositionReferences, id)];
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
function removeMcpChip(id: string): void {
|
|
899
|
+
mcpReferences = [...removeMcpReference(mcpReferences, id)];
|
|
228
900
|
}
|
|
229
901
|
</script>
|
|
230
902
|
|
|
903
|
+
{#snippet assistantAvatar(avatar: AgentAvatarRenderProps)}
|
|
904
|
+
<!-- The assistant's face: the brand's mascot, drawn as the chat's avatar asks (its state, its size, a still picture for a turn that is not the newest). -->
|
|
905
|
+
<Mascot
|
|
906
|
+
state={avatar.state}
|
|
907
|
+
size={avatar.size}
|
|
908
|
+
label={avatar.label}
|
|
909
|
+
decorative={!avatar.label}
|
|
910
|
+
frozenAt={avatar.live ? undefined : 0.5}
|
|
911
|
+
settleTo="idle"
|
|
912
|
+
/>
|
|
913
|
+
{/snippet}
|
|
914
|
+
|
|
915
|
+
<!-- What the newest turn of the assistant still has to show: a question, the plan, the conclusion. -->
|
|
916
|
+
{#snippet liveAssistantContent()}
|
|
917
|
+
{#each previewsOutsidePlan as preview (preview.previewId)}
|
|
918
|
+
<!-- What a call of one of the person's Open MCPs would show: their own values, for them to check. -->
|
|
919
|
+
<DataPreviewCard {preview} />
|
|
920
|
+
{/each}
|
|
921
|
+
{#if ui.questionCard}
|
|
922
|
+
<section class="rounded-lg border border-border p-3">
|
|
923
|
+
<p class="mb-2 text-body text-foreground">{ui.questionCard.message}</p>
|
|
924
|
+
<p class="mb-2 text-caption text-muted-foreground">{ui.questionCard.question}</p>
|
|
925
|
+
<div class="flex flex-col gap-1">
|
|
926
|
+
{#each ui.questionCard.options as option (option.id)}
|
|
927
|
+
<!-- The chosen answer is filled, the others are outlined: no card button is the page's main (primary) one. -->
|
|
928
|
+
<Button
|
|
929
|
+
variant={dsButtonVariant(selectedOptionId === option.id ? 'secondary' : 'outline')}
|
|
930
|
+
size="sm"
|
|
931
|
+
onclick={() => (selectedOptionId = option.id)}
|
|
932
|
+
>
|
|
933
|
+
{option.label}
|
|
934
|
+
</Button>
|
|
935
|
+
{/each}
|
|
936
|
+
</div>
|
|
937
|
+
<!-- Secondary, like every button of a card: the Publish button is the one main button of the screen. -->
|
|
938
|
+
<Button
|
|
939
|
+
class="mt-2"
|
|
940
|
+
variant={dsButtonVariant('secondary')}
|
|
941
|
+
size="sm"
|
|
942
|
+
disabled={!selectedOptionId}
|
|
943
|
+
onclick={() =>
|
|
944
|
+
selectedOptionId &&
|
|
945
|
+
void sendMessage($t('workflows.assistant.answerSent'), {
|
|
946
|
+
cardId: ui.questionCard?.cardId ?? '',
|
|
947
|
+
selectedOptionIds: [selectedOptionId],
|
|
948
|
+
selectedOptionLabels: ui.questionCard
|
|
949
|
+
? [
|
|
950
|
+
ui.questionCard.options.find((option) => option.id === selectedOptionId)?.label ??
|
|
951
|
+
selectedOptionId,
|
|
952
|
+
]
|
|
953
|
+
: [],
|
|
954
|
+
})}
|
|
955
|
+
>
|
|
956
|
+
{$t('workflows.assistant.submit')}
|
|
957
|
+
</Button>
|
|
958
|
+
</section>
|
|
959
|
+
{/if}
|
|
960
|
+
{#if ui.planCard}
|
|
961
|
+
<section class="rounded-lg border border-border p-3">
|
|
962
|
+
<h3 class="text-body font-medium text-foreground">{ui.planCard.title}</h3>
|
|
963
|
+
<p class="mt-1 text-caption text-muted-foreground">{ui.planCard.summary}</p>
|
|
964
|
+
<ul class="my-2 space-y-1">
|
|
965
|
+
{#each ui.planCard.steps as step (step.id)}
|
|
966
|
+
<AssistantPlanStepRow {step} canvasHref={config.canvasHref} />
|
|
967
|
+
{/each}
|
|
968
|
+
</ul>
|
|
969
|
+
{#if isBuildWatchable}
|
|
970
|
+
<p class="mb-1 text-caption text-muted-foreground">{$t('workflows.assistant.watchNote')}</p>
|
|
971
|
+
{/if}
|
|
972
|
+
{#if planFlowNodes.length > 1}
|
|
973
|
+
<!-- The widgets of the plan in the order a visitor meets them: the DS chip of the composer, an arrow between. -->
|
|
974
|
+
<ol class="my-2 flex flex-wrap items-center gap-1.5" aria-label={$t('workflows.assistant.planFlow')}>
|
|
975
|
+
{#each planFlowNodes as flowNode, flowIndex (flowNode.id)}
|
|
976
|
+
<li class="flex min-w-0 items-center gap-1.5">
|
|
977
|
+
<Chip label={flowNode.label}>
|
|
978
|
+
{#snippet leading()}
|
|
979
|
+
<Icon name="composition" class="size-4" />
|
|
980
|
+
{/snippet}
|
|
981
|
+
</Chip>
|
|
982
|
+
{#if flowIndex < planFlowNodes.length - 1}
|
|
983
|
+
<Icon name="arrowRight" class="size-4 text-muted-foreground" />
|
|
984
|
+
{/if}
|
|
985
|
+
</li>
|
|
986
|
+
{/each}
|
|
987
|
+
</ol>
|
|
988
|
+
{#if planFlowTransitions.length > 0}
|
|
989
|
+
<p class="mb-2 text-caption text-muted-foreground">{planFlowTransitions.join(' · ')}</p>
|
|
990
|
+
{/if}
|
|
991
|
+
{/if}
|
|
992
|
+
{#if !isLiveDataOnlyPlan}
|
|
993
|
+
<p class="text-caption text-muted-foreground">
|
|
994
|
+
{$t('workflows.assistant.estimate', { number: ui.planCard.credits })}
|
|
995
|
+
</p>
|
|
996
|
+
<p class="mt-1 text-caption text-muted-foreground">{$t('workflows.assistant.planNote')}</p>
|
|
997
|
+
{/if}
|
|
998
|
+
{#if ui.planCard.widgetsToCreate > 0}
|
|
999
|
+
<p class="mt-1 text-caption text-muted-foreground">{$t('workflows.assistant.buildNote')}</p>
|
|
1000
|
+
{/if}
|
|
1001
|
+
{#if planBindings.length > 0}
|
|
1002
|
+
<!-- The live data of the plan: the exact calls, where each value goes, what they would show, and the person's yes. -->
|
|
1003
|
+
<PlanBindingsBlock
|
|
1004
|
+
bindings={planBindings}
|
|
1005
|
+
previews={ui.dataPreviews}
|
|
1006
|
+
consent={exposureAcknowledged}
|
|
1007
|
+
onConsentChange={(consent) => (acknowledgedPlanId = consent ? currentPlanId : null)}
|
|
1008
|
+
disabled={isApproving || liveDataIsOn}
|
|
1009
|
+
/>
|
|
1010
|
+
{/if}
|
|
1011
|
+
{#if templateDestinations && chosenTemplateProjectId}
|
|
1012
|
+
<!-- The plan uses template widgets and the person has more than one project: they choose where the copies go.
|
|
1013
|
+
The choice is applied when they press Create workflow. -->
|
|
1014
|
+
<div class="mt-2">
|
|
1015
|
+
<TemplateProjectCard
|
|
1016
|
+
projects={templateDestinations.projects}
|
|
1017
|
+
selectedProjectId={chosenTemplateProjectId}
|
|
1018
|
+
onSelect={(projectId) => {
|
|
1019
|
+
if (ui.planCard) pickedTemplateProject = { planId: ui.planCard.planId, projectId };
|
|
1020
|
+
}}
|
|
1021
|
+
disabled={isApproving || ui.savedWorkflowId !== null}
|
|
1022
|
+
/>
|
|
1023
|
+
</div>
|
|
1024
|
+
{/if}
|
|
1025
|
+
<div class="mt-2 flex flex-wrap gap-2">
|
|
1026
|
+
<Button
|
|
1027
|
+
variant={dsButtonVariant('secondary')}
|
|
1028
|
+
size="sm"
|
|
1029
|
+
disabled={isApproving || liveDataIsOn || needsExposureConsent}
|
|
1030
|
+
onclick={() => void approvePlan()}
|
|
1031
|
+
>
|
|
1032
|
+
{isLiveDataOnlyPlan ? $t('workflows.assistant.turnOnLiveData') : $t('workflows.assistant.createWorkflow')}
|
|
1033
|
+
</Button>
|
|
1034
|
+
<Button variant={dsButtonVariant('outline')} size="sm" onclick={() => (ui = { ...ui, planCard: null })}>
|
|
1035
|
+
{$t('workflows.assistant.notNow')}
|
|
1036
|
+
</Button>
|
|
1037
|
+
{#if hasFailedPlanStep}
|
|
1038
|
+
<Button variant={dsButtonVariant('outline')} size="sm" onclick={() => void retryWithAssistant()}>
|
|
1039
|
+
{$t('workflows.assistant.retry')}
|
|
1040
|
+
</Button>
|
|
1041
|
+
{/if}
|
|
1042
|
+
</div>
|
|
1043
|
+
{#if needsExposureConsent}
|
|
1044
|
+
<!-- Why the button is off: the person has not said yes to the data being public. -->
|
|
1045
|
+
<p class="mt-1 text-caption text-muted-foreground">{$t('workflows.assistant.exposureNeeded')}</p>
|
|
1046
|
+
{/if}
|
|
1047
|
+
</section>
|
|
1048
|
+
{/if}
|
|
1049
|
+
{#if ui.completionMessage}
|
|
1050
|
+
<p class="text-body text-foreground">{ui.completionMessage}</p>
|
|
1051
|
+
<!-- No "Open in editor" button: the editor already shows the workflow the chat changed (or opens the new one). -->
|
|
1052
|
+
{/if}
|
|
1053
|
+
{/snippet}
|
|
1054
|
+
|
|
231
1055
|
<aside class="flex h-full min-h-0 w-full flex-col rounded-xl border border-border bg-background">
|
|
232
1056
|
<header class="flex items-center justify-between border-b border-border px-3 py-2">
|
|
233
1057
|
<h2 class="text-body font-medium text-foreground">{$t('workflows.assistant.title')}</h2>
|
|
@@ -254,111 +1078,97 @@
|
|
|
254
1078
|
</Button>
|
|
255
1079
|
{/each}
|
|
256
1080
|
</div>
|
|
257
|
-
<ul class="
|
|
258
|
-
{#each
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
1081
|
+
<ul class="flex flex-col gap-3">
|
|
1082
|
+
{#each transcriptTurns as turn (turn.key)}
|
|
1083
|
+
{#if turn.kind === 'user'}
|
|
1084
|
+
<li class="flex flex-col gap-1.5">
|
|
1085
|
+
<div class="rounded-lg bg-muted px-2 py-1 text-body">
|
|
1086
|
+
<span dir="auto">{turn.message.text}</span>
|
|
1087
|
+
</div>
|
|
1088
|
+
{#if turn.message.compositionReferences?.length}
|
|
1089
|
+
<!-- The compositions the person picked with @, as chips under their message (the design's "Mention sent" frame). -->
|
|
1090
|
+
<ul class="flex flex-wrap justify-end gap-1.5" aria-label={$t('workflows.assistant.compositionReferencesLabel')}>
|
|
1091
|
+
{#each turn.message.compositionReferences as reference (reference.id)}
|
|
1092
|
+
<li class="flex min-w-0 max-w-full">
|
|
1093
|
+
<Chip label={reference.name}>
|
|
1094
|
+
{#snippet leading()}
|
|
1095
|
+
<Icon name="composition" class="size-4" />
|
|
1096
|
+
{/snippet}
|
|
1097
|
+
</Chip>
|
|
1098
|
+
</li>
|
|
1099
|
+
{/each}
|
|
1100
|
+
</ul>
|
|
1101
|
+
{/if}
|
|
1102
|
+
{#if turn.message.mcpReferences?.length}
|
|
1103
|
+
<!-- The Open MCPs the person picked with @, as chips under their message, beside the compositions. -->
|
|
1104
|
+
<ul class="flex flex-wrap justify-end gap-1.5" aria-label={$t('workflows.assistant.mcpReferencesLabel')}>
|
|
1105
|
+
{#each turn.message.mcpReferences as reference (reference.id)}
|
|
1106
|
+
<li class="flex min-w-0 max-w-full">
|
|
1107
|
+
<Chip label={reference.name}>
|
|
1108
|
+
{#snippet leading()}
|
|
1109
|
+
<Icon name="plugConnected" class="size-4" />
|
|
1110
|
+
{/snippet}
|
|
1111
|
+
</Chip>
|
|
1112
|
+
</li>
|
|
1113
|
+
{/each}
|
|
1114
|
+
</ul>
|
|
1115
|
+
{/if}
|
|
1116
|
+
</li>
|
|
1117
|
+
{:else}
|
|
1118
|
+
<li>
|
|
1119
|
+
<!-- The newest turn is the one that moves; the others are still pictures. -->
|
|
1120
|
+
<AgentTurn
|
|
1121
|
+
look={turn.isNewest ? newestAvatarLook : stillAvatarLook}
|
|
1122
|
+
renderAgentAvatar={isMascotEnabled ? assistantAvatar : undefined}
|
|
274
1123
|
>
|
|
275
|
-
{
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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>
|
|
1124
|
+
{#each turn.messages as message, messageIndex (message.id)}
|
|
1125
|
+
<p class="text-body text-foreground {messageIndex === 0 ? 'flex min-h-7 items-center' : ''}">
|
|
1126
|
+
<span dir="auto">{message.text}</span>
|
|
1127
|
+
</p>
|
|
1128
|
+
{/each}
|
|
1129
|
+
{#if turn.isNewest}
|
|
1130
|
+
{#if ui.isStreaming}
|
|
1131
|
+
<p class="flex min-h-7 items-center text-caption text-muted-foreground" aria-live="polite">
|
|
1132
|
+
{$t('workflows.assistant.working')}
|
|
1133
|
+
</p>
|
|
1134
|
+
{/if}
|
|
1135
|
+
{@render liveAssistantContent()}
|
|
311
1136
|
{/if}
|
|
312
|
-
</
|
|
313
|
-
|
|
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>
|
|
1137
|
+
</AgentTurn>
|
|
1138
|
+
</li>
|
|
321
1139
|
{/if}
|
|
322
|
-
|
|
323
|
-
|
|
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}
|
|
1140
|
+
{/each}
|
|
1141
|
+
</ul>
|
|
357
1142
|
</div>
|
|
358
1143
|
<footer class="border-t border-border p-3">
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
1144
|
+
<!-- The files attached: the design's chip (the "Attachment" frame). While a file goes up, the chip's own background fills
|
|
1145
|
+
with the share done; there is no separate bar. A file named with a `#` in the box (or hovered in its menu) has a ring. -->
|
|
1146
|
+
<div class="mb-2 flex flex-wrap gap-1.5" data-workflows-assistant-attachments>
|
|
1147
|
+
{#each attachments as file (file.id)}
|
|
1148
|
+
<span
|
|
1149
|
+
class="inline-flex rounded-full {isReferenceHovered(file) ? 'ring-2 ring-primary' : ''}"
|
|
1150
|
+
data-testid="workflow-assistant-attachment"
|
|
1151
|
+
data-reference-label={file.label}
|
|
1152
|
+
>
|
|
1153
|
+
<Chip
|
|
1154
|
+
label={file.label ? `${file.fileName} · #${file.label}` : file.fileName}
|
|
1155
|
+
showRemove
|
|
1156
|
+
removeLabel={$t('workflows.assistant.removeAttachment', { name: file.fileName })}
|
|
1157
|
+
onRemove={() => removeAttachmentChip(file.id)}
|
|
1158
|
+
{...attachmentChipProgressProps(file)}
|
|
1159
|
+
>
|
|
1160
|
+
{#snippet leading()}
|
|
1161
|
+
{#if file.state === 'error'}
|
|
1162
|
+
<Icon name="warning" class="size-4 text-destructive" />
|
|
1163
|
+
<span class="sr-only">{$t('workflows.assistant.attachmentFailed')}</span>
|
|
1164
|
+
{:else if file.previewUrl}
|
|
1165
|
+
<img src={file.previewUrl} alt="" class="size-4 rounded-sm object-cover" />
|
|
1166
|
+
{:else}
|
|
1167
|
+
<Icon name="file" class="size-4" />
|
|
1168
|
+
{/if}
|
|
1169
|
+
{/snippet}
|
|
1170
|
+
</Chip>
|
|
1171
|
+
</span>
|
|
362
1172
|
{/each}
|
|
363
1173
|
</div>
|
|
364
1174
|
<label class="mb-2 inline-block cursor-pointer text-caption text-primary">
|
|
@@ -366,11 +1176,99 @@
|
|
|
366
1176
|
<input type="file" class="hidden" multiple onchange={onAttachFiles} />
|
|
367
1177
|
</label>
|
|
368
1178
|
<p class="mb-2 text-caption text-muted-foreground">{$t('workflows.assistant.libraryHint')}</p>
|
|
369
|
-
<
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
1179
|
+
<p class="mb-2 text-caption text-muted-foreground">{$t('workflows.assistant.mentionHint')}</p>
|
|
1180
|
+
{#if compositionReferences.length > 0 || mcpReferences.length > 0}
|
|
1181
|
+
<!-- The compositions and the Open MCPs picked with @: the design's chip, with its remove button (the "Mention chosen" frame). -->
|
|
1182
|
+
<div class="mb-2 flex flex-wrap gap-1.5" data-workflows-assistant-references>
|
|
1183
|
+
<span class="sr-only">{$t('workflows.assistant.compositionReferencesLabel')}</span>
|
|
1184
|
+
{#each compositionReferences as reference (reference.id)}
|
|
1185
|
+
<Chip
|
|
1186
|
+
label={reference.name}
|
|
1187
|
+
showRemove
|
|
1188
|
+
removeLabel={$t('workflows.assistant.removeCompositionReference', { name: reference.name })}
|
|
1189
|
+
onRemove={() => removeReference(reference.id)}
|
|
1190
|
+
>
|
|
1191
|
+
{#snippet leading()}
|
|
1192
|
+
<Icon name="composition" class="size-4" />
|
|
1193
|
+
{/snippet}
|
|
1194
|
+
</Chip>
|
|
1195
|
+
{/each}
|
|
1196
|
+
{#if mcpReferences.length > 0}
|
|
1197
|
+
<span class="sr-only">{$t('workflows.assistant.mcpReferencesLabel')}</span>
|
|
1198
|
+
{/if}
|
|
1199
|
+
{#each mcpReferences as reference (reference.id)}
|
|
1200
|
+
<Chip
|
|
1201
|
+
label={reference.name}
|
|
1202
|
+
showRemove
|
|
1203
|
+
removeLabel={$t('workflows.assistant.removeMcpReference', { name: reference.name })}
|
|
1204
|
+
onRemove={() => removeMcpChip(reference.id)}
|
|
1205
|
+
>
|
|
1206
|
+
{#snippet leading()}
|
|
1207
|
+
<Icon name="plugConnected" class="size-4" />
|
|
1208
|
+
{/snippet}
|
|
1209
|
+
</Chip>
|
|
1210
|
+
{/each}
|
|
1211
|
+
</div>
|
|
1212
|
+
{/if}
|
|
1213
|
+
<!-- `relative`: the @ menu and the grey words are drawn against the nearest positioned parent of the box -->
|
|
1214
|
+
<div class="relative">
|
|
1215
|
+
{#if mentionOpen}
|
|
1216
|
+
<CompositionMentionMenu
|
|
1217
|
+
items={mentionItems}
|
|
1218
|
+
highlightIndex={mentionActiveIndex}
|
|
1219
|
+
onselect={(entry) => void chooseMention(entry)}
|
|
1220
|
+
/>
|
|
1221
|
+
{/if}
|
|
1222
|
+
<!-- A message the page left in the composer can be long: where the browser allows, the box grows to show it (up to a limit). -->
|
|
1223
|
+
<textarea
|
|
1224
|
+
bind:this={composerElement}
|
|
1225
|
+
class="max-h-48 min-h-16 w-full field-sizing-content rounded-lg border border-border bg-background p-2 text-body"
|
|
1226
|
+
bind:value={draft}
|
|
1227
|
+
placeholder={$t('workflows.assistant.composerPlaceholder')}
|
|
1228
|
+
aria-describedby={referenceItems.length > 0 ? referenceHintId : undefined}
|
|
1229
|
+
data-workflows-assistant-composer
|
|
1230
|
+
oninput={syncMentionFromComposer}
|
|
1231
|
+
onclick={syncMentionFromComposer}
|
|
1232
|
+
onkeyup={syncMentionFromComposer}
|
|
1233
|
+
onkeydown={handleComposerKeydown}
|
|
1234
|
+
use:inlineCompletion={{
|
|
1235
|
+
source: suggestionSource,
|
|
1236
|
+
value: draft,
|
|
1237
|
+
// The grey words go while the `#` menu or the `@` menu is open: one popup at a time, and the menu owns the keys
|
|
1238
|
+
disabled: referenceMenuOpen || mentionOpen,
|
|
1239
|
+
onEvent: completion?.onEvent,
|
|
1240
|
+
onChange: handleSuggestionChange,
|
|
1241
|
+
announce: describeSuggestion,
|
|
1242
|
+
log: logCompletion,
|
|
1243
|
+
}}
|
|
1244
|
+
use:promptReferences={referenceParams}
|
|
1245
|
+
></textarea>
|
|
1246
|
+
</div>
|
|
1247
|
+
{#if referenceItems.length > 0}
|
|
1248
|
+
<!-- How to name an attached file: shown while there is one, so the way in is not a secret -->
|
|
1249
|
+
<p
|
|
1250
|
+
id={referenceHintId}
|
|
1251
|
+
class="mt-1 text-caption text-muted-foreground"
|
|
1252
|
+
data-testid="workflow-assistant-reference-hint"
|
|
1253
|
+
>
|
|
1254
|
+
{$t('workflows.assistant.referenceHint')}
|
|
1255
|
+
</p>
|
|
1256
|
+
{/if}
|
|
1257
|
+
{#if isHintLineKept}
|
|
1258
|
+
<!-- A line of its own once it has been needed, so the panel does not move as suggestions come and go. A screen reader is told by the box itself. -->
|
|
1259
|
+
<p
|
|
1260
|
+
class="mt-1 flex h-5 items-center gap-1.5 text-caption text-muted-foreground"
|
|
1261
|
+
data-testid="workflow-assistant-suggestion-hint"
|
|
1262
|
+
aria-hidden="true"
|
|
1263
|
+
>
|
|
1264
|
+
{#if suggestionShows}
|
|
1265
|
+
<kbd class="rounded-sm border border-border bg-muted px-1.5 font-sans text-caption"
|
|
1266
|
+
>{$t('workflows.assistant.suggestionTabKey')}</kbd
|
|
1267
|
+
>
|
|
1268
|
+
<span>{$t('workflows.assistant.suggestionTabHint')}</span>
|
|
1269
|
+
{/if}
|
|
1270
|
+
</p>
|
|
1271
|
+
{/if}
|
|
374
1272
|
<Button
|
|
375
1273
|
class="mt-2 w-full"
|
|
376
1274
|
variant={dsButtonVariant('primary')}
|