@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.
- package/README.md +11 -13
- package/dist/api/workflowsApi.d.ts +9 -1
- package/dist/api/workflowsApi.js +2 -1
- package/dist/assistant/assistantEvents.d.ts +42 -0
- package/dist/assistant/assistantEvents.js +61 -0
- package/dist/assistant/assistantRemoteChange.d.ts +4 -0
- package/dist/assistant/assistantRemoteChange.js +8 -0
- package/dist/assistant/assistantSaveMode.d.ts +5 -0
- package/dist/assistant/assistantSaveMode.js +8 -0
- package/dist/assistant/assistantStream.d.ts +8 -0
- package/dist/assistant/assistantStream.js +140 -0
- package/dist/assistant/assistantTranscript.d.ts +11 -0
- package/dist/assistant/assistantTranscript.js +18 -0
- package/dist/assistant/types.d.ts +81 -0
- package/dist/assistant/types.js +1 -0
- package/dist/assistant/workflowPlanViewModel.d.ts +48 -0
- package/dist/assistant/workflowPlanViewModel.js +17 -0
- package/dist/components/Workflows.svelte +3 -1
- package/dist/components/WorkflowsEmptyState.svelte +15 -3
- package/dist/components/WorkflowsEmptyState.svelte.d.ts +2 -0
- package/dist/components/WorkflowsWorkspace.svelte +4 -0
- package/dist/components/WorkflowsWorkspace.svelte.d.ts +1 -0
- package/dist/components/assistant/WorkflowAssistantPanel.svelte +384 -0
- package/dist/components/assistant/WorkflowAssistantPanel.svelte.d.ts +8 -0
- package/dist/components/canvas/CompositionNodeView.svelte +5 -5
- package/dist/components/canvas/ConditionNodeView.svelte +4 -4
- package/dist/components/canvas/HandlePoint.svelte +1 -1
- package/dist/components/canvas/TriggerNodeView.svelte +5 -4
- package/dist/components/canvas/WorkflowCanvas.svelte +16 -6
- package/dist/components/canvas/WorkflowCanvas.svelte.d.ts +2 -2
- package/dist/components/editor/EditorCanvasArea.svelte +57 -2
- package/dist/components/editor/EditorCanvasArea.svelte.d.ts +8 -1
- package/dist/components/editor/EditorTabs.svelte +1 -2
- package/dist/components/editor/EditorTopBar.svelte +29 -21
- package/dist/components/editor/EditorTopBar.svelte.d.ts +3 -0
- package/dist/components/editor/RunsFlow.svelte +73 -23
- package/dist/components/editor/WorkflowEditor.svelte +31 -3
- package/dist/components/editor/WorkflowEditor.svelte.d.ts +5 -0
- package/dist/components/editor/WorkflowNameControl.svelte +136 -0
- package/dist/components/editor/WorkflowNameControl.svelte.d.ts +13 -0
- package/dist/components/list/WorkflowList.svelte +112 -60
- package/dist/components/list/WorkflowList.svelte.d.ts +2 -0
- package/dist/components/list/WorkflowRow.svelte +2 -0
- package/dist/components/panel/ConditionForm.svelte +7 -7
- package/dist/components/ui/Menu.svelte +31 -7
- package/dist/components/ui/Menu.svelte.d.ts +4 -0
- package/dist/components/ui/icons.d.ts +2 -0
- package/dist/components/ui/icons.js +3 -1
- package/dist/drafts/draftJournal.d.ts +59 -0
- package/dist/drafts/draftJournal.js +261 -0
- package/dist/drafts/workflowDraft.d.ts +72 -0
- package/dist/drafts/workflowDraft.js +151 -0
- package/dist/drafts/workflowListViewState.d.ts +30 -0
- package/dist/drafts/workflowListViewState.js +92 -0
- package/dist/editor/createBlankWorkflow.d.ts +30 -0
- package/dist/editor/createBlankWorkflow.js +37 -0
- package/dist/editor/editorState.svelte.d.ts +68 -2
- package/dist/editor/editorState.svelte.js +273 -0
- package/dist/editor/listState.svelte.d.ts +73 -36
- package/dist/editor/listState.svelte.js +260 -46
- package/dist/editor/presetChoice.d.ts +4 -4
- package/dist/editor/presetChoice.js +4 -4
- package/dist/editor/runsFlowBandLabel.d.ts +16 -0
- package/dist/editor/runsFlowBandLabel.js +34 -0
- package/dist/editor/runsFlowLayout.d.ts +24 -9
- package/dist/editor/runsFlowLayout.js +73 -28
- package/dist/editor/workflowNameCommit.d.ts +12 -0
- package/dist/editor/workflowNameCommit.js +11 -0
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +40 -26
- package/dist/i18n/messages.js +43 -30
- package/dist/types/index.d.ts +4 -0
- package/package.json +8 -1
- package/dist/components/list/CreateWorkflowDialog.svelte +0 -262
- package/dist/components/list/CreateWorkflowDialog.svelte.d.ts +0 -9
package/README.md
CHANGED
|
@@ -14,18 +14,16 @@ Workflows are for **Teams and partner accounts** only. On Widgetic the page is
|
|
|
14
14
|
## What it does
|
|
15
15
|
|
|
16
16
|
- **The list.** The workspace's workflows with where each one stands (draft, live, paused, archived), how many visitors
|
|
17
|
-
went through, and when it was last published. Search by name,
|
|
18
|
-
created, last published or visitors, and make a workflow (`New workflow`), duplicate it or delete it. The
|
|
19
|
-
when one is opened (`onOpenWorkflow`) so the address can follow.
|
|
20
|
-
- **
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
so it is given longer than another request, and it is sent with an `Idempotency-Key`: asking again after a timeout does
|
|
28
|
-
not copy twice.
|
|
17
|
+
went through, and when it was last published. Search by name, filter by state (All, Draft, Live, Paused, Archived), order
|
|
18
|
+
by name, date created, last published or visitors, and make a workflow (`New workflow`), duplicate it or delete it. The
|
|
19
|
+
page is told when one is opened (`onOpenWorkflow`) so the address can follow.
|
|
20
|
+
- **New workflow.** `New workflow` makes a blank draft named `Untitled` at once and opens the editor: there is no dialog,
|
|
21
|
+
no name to type and no choice to make (the name is changed in the editor's header, by clicking it).
|
|
22
|
+
- **Start from a preset (model and API only).** A preset is a published workflow that Widgetic (or a partner) offers as a
|
|
23
|
+
place to start; starting from one copies every widget it chains and wires a draft like the preset's live version. The
|
|
24
|
+
list no longer shows a preset choice, but its model (`loadPresets()`, `startFromPreset()`) and the API client
|
|
25
|
+
(`listPresets()`, `startFromPreset()`) still do this, for a host that wants to offer templates itself. The copy is sent
|
|
26
|
+
with an `Idempotency-Key`: asking again after a timeout does not copy twice.
|
|
29
27
|
- **The editor.** A canvas of blocks joined by lines. A **Composition** block shows a composition; a **Trigger** block
|
|
30
28
|
waits for something a visitor does (a value they add to a widget, an action in the widget, an event on the page, or a
|
|
31
29
|
time); a **Condition** block sends the visitor on by the first rule that matches. Blocks go forward only, a workflow
|
|
@@ -222,7 +220,7 @@ The catalog's messages are grouped by the part of the screen that says them:
|
|
|
222
220
|
| Group | What it says |
|
|
223
221
|
| -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
|
|
224
222
|
| `workflows.header.*`, `empty.*` | The title and the empty state. |
|
|
225
|
-
| `workflows.list.*`, `create.*`, `status.*` | The list: search,
|
|
223
|
+
| `workflows.list.*`, `create.*`, `status.*` | The list: search, status tabs, order, rows, blank New workflow, states. |
|
|
226
224
|
| `workflows.top.*`, `save.*`, `tabs.*`, `banner.*`, `leave.*` | The bar above the canvas, the save state, the tabs and the banners. |
|
|
227
225
|
| `workflows.canvas.*`, `toolbar.*`, `addBlock.*`, `block.*` | The canvas, its tools, the Add block menu and what a block is called. |
|
|
228
226
|
| `workflows.panel.*`, `composition.*`, `trigger.*`, `schedule.*`, `event.*`, `reason.*` | The side panel for a composition and for each kind of trigger, and why a trigger is not offered. |
|
|
@@ -59,6 +59,14 @@ export interface WorkflowsApiOptions {
|
|
|
59
59
|
export interface RequestOptions {
|
|
60
60
|
signal?: AbortSignal;
|
|
61
61
|
}
|
|
62
|
+
/** Options for saving a draft (including a best-effort leave save). */
|
|
63
|
+
export interface SaveDraftOptions extends RequestOptions {
|
|
64
|
+
/**
|
|
65
|
+
* Lets the request finish after the page is gone (`fetch` `keepalive`): for a tab close or hide, when the body is
|
|
66
|
+
* below the browser limit (~64 KB).
|
|
67
|
+
*/
|
|
68
|
+
keepalive?: boolean;
|
|
69
|
+
}
|
|
62
70
|
/** Options of the call that gives an edit claim up. */
|
|
63
71
|
export interface ReleaseEditLeaseOptions extends RequestOptions {
|
|
64
72
|
/**
|
|
@@ -89,7 +97,7 @@ export interface WorkflowsApi {
|
|
|
89
97
|
name?: string;
|
|
90
98
|
timezone?: string;
|
|
91
99
|
graph?: WorkflowGraph;
|
|
92
|
-
}, options?:
|
|
100
|
+
}, options?: SaveDraftOptions): Promise<WorkflowListItem>;
|
|
93
101
|
deleteWorkflow(workflowId: string, options?: RequestOptions): Promise<void>;
|
|
94
102
|
duplicateWorkflow(workflowId: string, options?: RetryableRequestOptions): Promise<WorkflowDetail>;
|
|
95
103
|
publishWorkflow(workflowId: string, revision: number, options?: RetryableRequestOptions): Promise<WorkflowPublishResult>;
|
package/dist/api/workflowsApi.js
CHANGED
|
@@ -774,7 +774,8 @@ export function createWorkflowsApi(options) {
|
|
|
774
774
|
return readWorkflowListItem(await request('PUT', pathOfWorkflow(workflowId), {
|
|
775
775
|
body: input,
|
|
776
776
|
signal: requestOptions.signal,
|
|
777
|
-
timeoutMs: writeTimeoutMs
|
|
777
|
+
timeoutMs: writeTimeoutMs,
|
|
778
|
+
keepalive: requestOptions.keepalive
|
|
778
779
|
}));
|
|
779
780
|
},
|
|
780
781
|
async deleteWorkflow(workflowId, requestOptions = {}) {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { AssistantPlanCardState, AssistantQuestionCardState, AssistantTranscriptMessage } from './types.js';
|
|
2
|
+
export interface AssistantUiState {
|
|
3
|
+
readonly messages: readonly AssistantTranscriptMessage[];
|
|
4
|
+
readonly questionCard: AssistantQuestionCardState | null;
|
|
5
|
+
readonly planCard: AssistantPlanCardState | null;
|
|
6
|
+
readonly isStreaming: boolean;
|
|
7
|
+
readonly completionMessage: string | null;
|
|
8
|
+
readonly savedWorkflowId: string | null;
|
|
9
|
+
}
|
|
10
|
+
export declare const emptyAssistantUiState: AssistantUiState;
|
|
11
|
+
export type AssistantUiAction = {
|
|
12
|
+
type: 'clear';
|
|
13
|
+
} | {
|
|
14
|
+
type: 'user_message';
|
|
15
|
+
id: string;
|
|
16
|
+
text: string;
|
|
17
|
+
} | {
|
|
18
|
+
type: 'streaming';
|
|
19
|
+
value: boolean;
|
|
20
|
+
} | {
|
|
21
|
+
type: 'assistant_text';
|
|
22
|
+
id: string;
|
|
23
|
+
text: string;
|
|
24
|
+
} | {
|
|
25
|
+
type: 'question_card';
|
|
26
|
+
card: AssistantQuestionCardState;
|
|
27
|
+
} | {
|
|
28
|
+
type: 'plan_card';
|
|
29
|
+
card: AssistantPlanCardState;
|
|
30
|
+
} | {
|
|
31
|
+
type: 'plan_step';
|
|
32
|
+
stepId: string;
|
|
33
|
+
status: 'waiting' | 'creating' | 'done' | 'failed';
|
|
34
|
+
detail?: string;
|
|
35
|
+
} | {
|
|
36
|
+
type: 'workflow_ready';
|
|
37
|
+
workflowId: string;
|
|
38
|
+
mode: 'filled_empty' | 'created_new';
|
|
39
|
+
} | {
|
|
40
|
+
type: 'done';
|
|
41
|
+
};
|
|
42
|
+
export declare function reduceAssistantUiState(state: AssistantUiState, action: AssistantUiAction): AssistantUiState;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { WORKFLOWS_MESSAGES } from '../i18n/messages.js';
|
|
2
|
+
import { completionMessageKeyForSaveMode } from './assistantSaveMode.js';
|
|
3
|
+
export const emptyAssistantUiState = {
|
|
4
|
+
messages: [],
|
|
5
|
+
questionCard: null,
|
|
6
|
+
planCard: null,
|
|
7
|
+
isStreaming: false,
|
|
8
|
+
completionMessage: null,
|
|
9
|
+
savedWorkflowId: null,
|
|
10
|
+
};
|
|
11
|
+
export function reduceAssistantUiState(state, action) {
|
|
12
|
+
switch (action.type) {
|
|
13
|
+
case 'clear':
|
|
14
|
+
return { ...emptyAssistantUiState };
|
|
15
|
+
case 'user_message':
|
|
16
|
+
return {
|
|
17
|
+
...state,
|
|
18
|
+
messages: [...state.messages, { id: action.id, role: 'user', text: action.text }],
|
|
19
|
+
};
|
|
20
|
+
case 'streaming':
|
|
21
|
+
return { ...state, isStreaming: action.value };
|
|
22
|
+
case 'assistant_text':
|
|
23
|
+
return {
|
|
24
|
+
...state,
|
|
25
|
+
messages: [...state.messages, { id: action.id, role: 'assistant', text: action.text }],
|
|
26
|
+
};
|
|
27
|
+
case 'question_card':
|
|
28
|
+
return { ...state, questionCard: action.card };
|
|
29
|
+
case 'plan_card':
|
|
30
|
+
return {
|
|
31
|
+
...state,
|
|
32
|
+
planCard: {
|
|
33
|
+
...action.card,
|
|
34
|
+
steps: action.card.steps.map((step) => ({ ...step, status: 'waiting' })),
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
case 'plan_step':
|
|
38
|
+
if (!state.planCard)
|
|
39
|
+
return state;
|
|
40
|
+
return {
|
|
41
|
+
...state,
|
|
42
|
+
planCard: {
|
|
43
|
+
...state.planCard,
|
|
44
|
+
steps: state.planCard.steps.map((step) => step.id === action.stepId
|
|
45
|
+
? { ...step, status: action.status, detail: action.status === 'failed' ? action.detail : undefined }
|
|
46
|
+
: step),
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
case 'workflow_ready':
|
|
50
|
+
return {
|
|
51
|
+
...state,
|
|
52
|
+
savedWorkflowId: action.workflowId,
|
|
53
|
+
completionMessage: WORKFLOWS_MESSAGES[completionMessageKeyForSaveMode(action.mode)],
|
|
54
|
+
isStreaming: false,
|
|
55
|
+
};
|
|
56
|
+
case 'done':
|
|
57
|
+
return { ...state, isStreaming: false };
|
|
58
|
+
default:
|
|
59
|
+
return state;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SaveState } from '../editor/autosave.js';
|
|
2
|
+
export type AssistantRemoteChangeAction = 'reload' | 'showConflict' | 'noop';
|
|
3
|
+
/** Whether the editor should reload or show the existing conflict banner after the assistant saves. */
|
|
4
|
+
export declare function decideAssistantRemoteChangeAction(saveState: SaveState): AssistantRemoteChangeAction;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Whether the editor should reload or show the existing conflict banner after the assistant saves. */
|
|
2
|
+
export function decideAssistantRemoteChangeAction(saveState) {
|
|
3
|
+
if (saveState === 'conflict')
|
|
4
|
+
return 'noop';
|
|
5
|
+
if (saveState === 'saved')
|
|
6
|
+
return 'reload';
|
|
7
|
+
return 'showConflict';
|
|
8
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type WorkflowAssistantSaveMode = 'filled_empty' | 'created_new';
|
|
2
|
+
/** Catalog message key for the completion line after approve. */
|
|
3
|
+
export declare function completionMessageKeyForSaveMode(mode: WorkflowAssistantSaveMode): 'workflows.assistant.ready' | 'workflows.assistant.createdNew';
|
|
4
|
+
/** Whether approving should reload the open workflow or navigate to a new one. */
|
|
5
|
+
export declare function editorActionForSaveMode(mode: WorkflowAssistantSaveMode): 'reload_open' | 'open_new';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Catalog message key for the completion line after approve. */
|
|
2
|
+
export function completionMessageKeyForSaveMode(mode) {
|
|
3
|
+
return mode === 'created_new' ? 'workflows.assistant.createdNew' : 'workflows.assistant.ready';
|
|
4
|
+
}
|
|
5
|
+
/** Whether approving should reload the open workflow or navigate to a new one. */
|
|
6
|
+
export function editorActionForSaveMode(mode) {
|
|
7
|
+
return mode === 'created_new' ? 'open_new' : 'reload_open';
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AssistantUiAction } from './assistantEvents.js';
|
|
2
|
+
export declare function parseAssistantSseStream(response: Response): AsyncGenerator<AssistantUiAction>;
|
|
3
|
+
export declare function parseAssistantApproveStream(response: Response): AsyncGenerator<AssistantUiAction>;
|
|
4
|
+
/**
|
|
5
|
+
* What to tell the person when the gateway answered with an error status instead of a stream (the body is JSON then, and a
|
|
6
|
+
* stream reader would find nothing in it and say nothing).
|
|
7
|
+
*/
|
|
8
|
+
export declare function assistantFailureTextForStatus(status: number): string;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { WORKFLOWS_MESSAGES } from '../i18n/messages.js';
|
|
2
|
+
import { mapWorkflowPlanWireToCard } from './workflowPlanViewModel.js';
|
|
3
|
+
export async function* parseAssistantSseStream(response) {
|
|
4
|
+
const reader = response.body?.getReader();
|
|
5
|
+
if (!reader)
|
|
6
|
+
return;
|
|
7
|
+
const decoder = new TextDecoder();
|
|
8
|
+
let buffer = '';
|
|
9
|
+
while (true) {
|
|
10
|
+
const { done, value } = await reader.read();
|
|
11
|
+
if (done)
|
|
12
|
+
break;
|
|
13
|
+
buffer += decoder.decode(value, { stream: true });
|
|
14
|
+
const parts = buffer.split('\n\n');
|
|
15
|
+
buffer = parts.pop() ?? '';
|
|
16
|
+
for (const part of parts) {
|
|
17
|
+
const lines = part.split('\n');
|
|
18
|
+
const dataLine = lines.find((line) => line.startsWith('data: '));
|
|
19
|
+
if (!dataLine)
|
|
20
|
+
continue;
|
|
21
|
+
const payload = JSON.parse(dataLine.slice(6));
|
|
22
|
+
yield* mapStreamPayloadToAction(payload);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function* mapStreamPayloadToAction(payload) {
|
|
27
|
+
switch (payload.type) {
|
|
28
|
+
case 'assistant_message':
|
|
29
|
+
yield {
|
|
30
|
+
type: 'assistant_text',
|
|
31
|
+
id: crypto.randomUUID(),
|
|
32
|
+
text: String(payload.text ?? ''),
|
|
33
|
+
};
|
|
34
|
+
break;
|
|
35
|
+
case 'question_card': {
|
|
36
|
+
const card = payload.card;
|
|
37
|
+
const first = card.questions[0];
|
|
38
|
+
if (!first)
|
|
39
|
+
break;
|
|
40
|
+
yield {
|
|
41
|
+
type: 'question_card',
|
|
42
|
+
card: {
|
|
43
|
+
cardId: card.cardId,
|
|
44
|
+
message: card.message,
|
|
45
|
+
question: first.question,
|
|
46
|
+
options: first.options,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case 'plan_card': {
|
|
52
|
+
const raw = payload.plan;
|
|
53
|
+
const plan = {
|
|
54
|
+
...raw,
|
|
55
|
+
planToken: raw.planToken ?? '',
|
|
56
|
+
flow: raw.flow ?? { nodes: [], edges: [] },
|
|
57
|
+
attachments: raw.attachments ?? [],
|
|
58
|
+
estimate: raw.estimate ?? { credits: 0, widgetsToCreate: 0 },
|
|
59
|
+
};
|
|
60
|
+
yield { type: 'plan_card', card: mapWorkflowPlanWireToCard(plan) };
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case 'refusal':
|
|
64
|
+
yield {
|
|
65
|
+
type: 'assistant_text',
|
|
66
|
+
id: crypto.randomUUID(),
|
|
67
|
+
text: String(payload.message ?? ''),
|
|
68
|
+
};
|
|
69
|
+
break;
|
|
70
|
+
case 'error':
|
|
71
|
+
yield {
|
|
72
|
+
type: 'assistant_text',
|
|
73
|
+
id: crypto.randomUUID(),
|
|
74
|
+
text: String(payload.message ?? WORKFLOWS_MESSAGES['workflows.error.generic']),
|
|
75
|
+
};
|
|
76
|
+
break;
|
|
77
|
+
case 'done':
|
|
78
|
+
yield { type: 'done' };
|
|
79
|
+
break;
|
|
80
|
+
default:
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export async function* parseAssistantApproveStream(response) {
|
|
85
|
+
const reader = response.body?.getReader();
|
|
86
|
+
if (!reader)
|
|
87
|
+
return;
|
|
88
|
+
const decoder = new TextDecoder();
|
|
89
|
+
let buffer = '';
|
|
90
|
+
while (true) {
|
|
91
|
+
const { done, value } = await reader.read();
|
|
92
|
+
if (done)
|
|
93
|
+
break;
|
|
94
|
+
buffer += decoder.decode(value, { stream: true });
|
|
95
|
+
const parts = buffer.split('\n\n');
|
|
96
|
+
buffer = parts.pop() ?? '';
|
|
97
|
+
for (const part of parts) {
|
|
98
|
+
const dataLine = part.split('\n').find((line) => line.startsWith('data: '));
|
|
99
|
+
if (!dataLine)
|
|
100
|
+
continue;
|
|
101
|
+
const payload = JSON.parse(dataLine.slice(6));
|
|
102
|
+
if (payload.type === 'step_status') {
|
|
103
|
+
yield {
|
|
104
|
+
type: 'plan_step',
|
|
105
|
+
stepId: String(payload.stepId),
|
|
106
|
+
status: payload.status,
|
|
107
|
+
// The gateway's sentence for a failed step ("Still building. It will be in your widgets when it finishes.")
|
|
108
|
+
detail: typeof payload.detail === 'string' && payload.detail.length > 0 ? payload.detail : undefined,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
else if (payload.type === 'error') {
|
|
112
|
+
// Credits short, a plan used twice, a build that failed: the person is told in the chat, not left looking at a card
|
|
113
|
+
// that does nothing.
|
|
114
|
+
yield {
|
|
115
|
+
type: 'assistant_text',
|
|
116
|
+
id: crypto.randomUUID(),
|
|
117
|
+
text: String(payload.message ?? WORKFLOWS_MESSAGES['workflows.error.generic']),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
else if (payload.type === 'workflow_saved') {
|
|
121
|
+
const mode = payload.mode === 'created_new' ? 'created_new' : 'filled_empty';
|
|
122
|
+
yield { type: 'workflow_ready', workflowId: String(payload.workflowId), mode };
|
|
123
|
+
}
|
|
124
|
+
else if (payload.type === 'done') {
|
|
125
|
+
yield { type: 'done' };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* What to tell the person when the gateway answered with an error status instead of a stream (the body is JSON then, and a
|
|
132
|
+
* stream reader would find nothing in it and say nothing).
|
|
133
|
+
*/
|
|
134
|
+
export function assistantFailureTextForStatus(status) {
|
|
135
|
+
if (status === 429)
|
|
136
|
+
return WORKFLOWS_MESSAGES['workflows.assistant.errorRateLimited'];
|
|
137
|
+
if (status === 404)
|
|
138
|
+
return WORKFLOWS_MESSAGES['workflows.assistant.errorNotAvailable'];
|
|
139
|
+
return WORKFLOWS_MESSAGES['workflows.error.generic'];
|
|
140
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type DraftJournal } from '../drafts/draftJournal.js';
|
|
2
|
+
import type { AssistantTranscriptMessage } from './types.js';
|
|
3
|
+
export declare const ASSISTANT_DRAFT_NAMESPACE = "assistant";
|
|
4
|
+
export interface AssistantTranscriptPayload {
|
|
5
|
+
readonly messages: readonly AssistantTranscriptMessage[];
|
|
6
|
+
}
|
|
7
|
+
export declare function assistantDraftKey(workflowId: string): string;
|
|
8
|
+
export declare function createAssistantTranscriptJournal(): DraftJournal<AssistantTranscriptPayload>;
|
|
9
|
+
export declare function readAssistantTranscript(journal: DraftJournal<AssistantTranscriptPayload>, workflowId: string): readonly AssistantTranscriptMessage[];
|
|
10
|
+
export declare function writeAssistantTranscript(journal: DraftJournal<AssistantTranscriptPayload>, workflowId: string, messages: readonly AssistantTranscriptMessage[]): void;
|
|
11
|
+
export declare function clearAssistantTranscript(journal: DraftJournal<AssistantTranscriptPayload>, workflowId: string): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createDraftJournal } from '../drafts/draftJournal.js';
|
|
2
|
+
export const ASSISTANT_DRAFT_NAMESPACE = 'assistant';
|
|
3
|
+
export function assistantDraftKey(workflowId) {
|
|
4
|
+
return `${ASSISTANT_DRAFT_NAMESPACE}:${workflowId}`;
|
|
5
|
+
}
|
|
6
|
+
export function createAssistantTranscriptJournal() {
|
|
7
|
+
return createDraftJournal(ASSISTANT_DRAFT_NAMESPACE);
|
|
8
|
+
}
|
|
9
|
+
export function readAssistantTranscript(journal, workflowId) {
|
|
10
|
+
const entry = journal.read(assistantDraftKey(workflowId));
|
|
11
|
+
return entry?.payload.messages ?? [];
|
|
12
|
+
}
|
|
13
|
+
export function writeAssistantTranscript(journal, workflowId, messages) {
|
|
14
|
+
journal.write(assistantDraftKey(workflowId), { messages });
|
|
15
|
+
}
|
|
16
|
+
export function clearAssistantTranscript(journal, workflowId) {
|
|
17
|
+
journal.clear(assistantDraftKey(workflowId));
|
|
18
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export type WorkflowAssistantAuthHeaders = Record<string, string> | (() => Promise<Record<string, string>>);
|
|
2
|
+
/** Host wiring for the workflows assistant panel (optional: omitted = no panel). */
|
|
3
|
+
export interface WorkflowAssistantConfig {
|
|
4
|
+
readonly enabled: boolean;
|
|
5
|
+
readonly streamUrl: string;
|
|
6
|
+
readonly approveUrl: string;
|
|
7
|
+
readonly getAuthHeaders: WorkflowAssistantAuthHeaders;
|
|
8
|
+
readonly uploadFileToLibrary: (file: File) => Promise<{
|
|
9
|
+
mediaId: string;
|
|
10
|
+
fileName: string;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
export type AssistantMessageRole = 'user' | 'assistant';
|
|
14
|
+
export interface AssistantTranscriptMessage {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly role: AssistantMessageRole;
|
|
17
|
+
readonly text: string;
|
|
18
|
+
}
|
|
19
|
+
export interface AssistantQuestionCardState {
|
|
20
|
+
readonly cardId: string;
|
|
21
|
+
readonly message: string;
|
|
22
|
+
readonly question: string;
|
|
23
|
+
readonly options: ReadonlyArray<{
|
|
24
|
+
id: string;
|
|
25
|
+
label: string;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
export interface AssistantPlanApproveWire {
|
|
29
|
+
readonly planId: string;
|
|
30
|
+
readonly planToken: string;
|
|
31
|
+
readonly title: string;
|
|
32
|
+
readonly summary: string;
|
|
33
|
+
readonly steps: ReadonlyArray<{
|
|
34
|
+
id: string;
|
|
35
|
+
kind: 'reuse' | 'create';
|
|
36
|
+
widgetId?: string;
|
|
37
|
+
widgetName: string;
|
|
38
|
+
role: string;
|
|
39
|
+
prompt?: string;
|
|
40
|
+
}>;
|
|
41
|
+
readonly flow: {
|
|
42
|
+
readonly nodes: ReadonlyArray<{
|
|
43
|
+
id: string;
|
|
44
|
+
label: string;
|
|
45
|
+
}>;
|
|
46
|
+
readonly edges: ReadonlyArray<{
|
|
47
|
+
from: string;
|
|
48
|
+
to: string;
|
|
49
|
+
label?: string;
|
|
50
|
+
}>;
|
|
51
|
+
};
|
|
52
|
+
readonly estimate: {
|
|
53
|
+
readonly credits: number;
|
|
54
|
+
readonly widgetsToCreate: number;
|
|
55
|
+
};
|
|
56
|
+
readonly attachments: ReadonlyArray<{
|
|
57
|
+
mediaId: string;
|
|
58
|
+
fileName: string;
|
|
59
|
+
}>;
|
|
60
|
+
}
|
|
61
|
+
export interface AssistantPlanCardState {
|
|
62
|
+
readonly planId: string;
|
|
63
|
+
readonly planToken: string;
|
|
64
|
+
readonly planWire: AssistantPlanApproveWire;
|
|
65
|
+
readonly title: string;
|
|
66
|
+
readonly summary: string;
|
|
67
|
+
readonly steps: ReadonlyArray<{
|
|
68
|
+
id: string;
|
|
69
|
+
label: string;
|
|
70
|
+
status: 'waiting' | 'creating' | 'done' | 'failed';
|
|
71
|
+
/** Why a step failed, in a sentence the gateway wrote for the person; empty for the other states. */
|
|
72
|
+
detail?: string;
|
|
73
|
+
}>;
|
|
74
|
+
readonly credits: number;
|
|
75
|
+
readonly widgetsToCreate: number;
|
|
76
|
+
}
|
|
77
|
+
export interface AssistantAttachmentChip {
|
|
78
|
+
readonly mediaId: string;
|
|
79
|
+
readonly fileName: string;
|
|
80
|
+
readonly state: 'uploading' | 'ready' | 'error';
|
|
81
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface WorkflowPlanWireStep {
|
|
2
|
+
id: string;
|
|
3
|
+
kind: 'reuse' | 'create';
|
|
4
|
+
widgetId?: string;
|
|
5
|
+
widgetName: string;
|
|
6
|
+
role: string;
|
|
7
|
+
prompt?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface WorkflowPlanWire {
|
|
10
|
+
planId: string;
|
|
11
|
+
planToken: string;
|
|
12
|
+
title: string;
|
|
13
|
+
summary: string;
|
|
14
|
+
steps: WorkflowPlanWireStep[];
|
|
15
|
+
flow: {
|
|
16
|
+
nodes: Array<{
|
|
17
|
+
id: string;
|
|
18
|
+
label: string;
|
|
19
|
+
}>;
|
|
20
|
+
edges: Array<{
|
|
21
|
+
from: string;
|
|
22
|
+
to: string;
|
|
23
|
+
label?: string;
|
|
24
|
+
}>;
|
|
25
|
+
};
|
|
26
|
+
estimate: {
|
|
27
|
+
credits: number;
|
|
28
|
+
widgetsToCreate: number;
|
|
29
|
+
};
|
|
30
|
+
attachments: Array<{
|
|
31
|
+
mediaId: string;
|
|
32
|
+
fileName: string;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
export declare function mapWorkflowPlanWireToCard(plan: WorkflowPlanWire): {
|
|
36
|
+
planId: string;
|
|
37
|
+
planToken: string;
|
|
38
|
+
planWire: WorkflowPlanWire;
|
|
39
|
+
title: string;
|
|
40
|
+
summary: string;
|
|
41
|
+
credits: number;
|
|
42
|
+
widgetsToCreate: number;
|
|
43
|
+
steps: {
|
|
44
|
+
id: string;
|
|
45
|
+
label: string;
|
|
46
|
+
status: "waiting";
|
|
47
|
+
}[];
|
|
48
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function mapWorkflowPlanWireToCard(plan) {
|
|
2
|
+
const planWire = { ...plan, planToken: plan.planToken ?? '' };
|
|
3
|
+
return {
|
|
4
|
+
planId: plan.planId,
|
|
5
|
+
planToken: planWire.planToken ?? '',
|
|
6
|
+
planWire,
|
|
7
|
+
title: plan.title,
|
|
8
|
+
summary: plan.summary,
|
|
9
|
+
credits: plan.estimate.credits,
|
|
10
|
+
widgetsToCreate: plan.estimate.widgetsToCreate,
|
|
11
|
+
steps: plan.steps.map((step) => ({
|
|
12
|
+
id: step.id,
|
|
13
|
+
label: `${step.widgetName} — ${step.role}`,
|
|
14
|
+
status: 'waiting',
|
|
15
|
+
})),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -46,7 +46,8 @@
|
|
|
46
46
|
dir = undefined,
|
|
47
47
|
class: className = '',
|
|
48
48
|
onError,
|
|
49
|
-
fetchImplementation
|
|
49
|
+
fetchImplementation,
|
|
50
|
+
assistant = null
|
|
50
51
|
}: WorkflowsProps = $props();
|
|
51
52
|
|
|
52
53
|
// Why stores and effects below instead of `$derived`: the design system's language (`update()`) and direction
|
|
@@ -107,6 +108,7 @@
|
|
|
107
108
|
{onOpenWorkflow}
|
|
108
109
|
{onShowEmbedCode}
|
|
109
110
|
{presence}
|
|
111
|
+
{assistant}
|
|
110
112
|
onError={reportToPage}
|
|
111
113
|
/>
|
|
112
114
|
{/key}
|
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
interface Props {
|
|
12
12
|
/** The person pressed the button that makes the first workflow. */
|
|
13
13
|
oncreate: () => void;
|
|
14
|
+
/** A workflow is already being made (the button is disabled and shows a spinner). */
|
|
15
|
+
busy?: boolean;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
let { oncreate }: Props = $props();
|
|
18
|
+
let { oncreate, busy = false }: Props = $props();
|
|
17
19
|
|
|
18
20
|
const { t } = useWorkflowsLanguage();
|
|
19
21
|
</script>
|
|
@@ -27,8 +29,18 @@
|
|
|
27
29
|
<h2 class="text-heading-section text-foreground">{$t('workflows.empty.title')}</h2>
|
|
28
30
|
<p class="text-body text-muted-foreground">{$t('workflows.empty.hint')}</p>
|
|
29
31
|
</div>
|
|
30
|
-
<Button
|
|
31
|
-
|
|
32
|
+
<Button
|
|
33
|
+
class="mt-3"
|
|
34
|
+
variant={dsButtonVariant('primary')}
|
|
35
|
+
disabled={busy}
|
|
36
|
+
aria-busy={busy}
|
|
37
|
+
onclick={oncreate}
|
|
38
|
+
>
|
|
39
|
+
{#if busy}
|
|
40
|
+
<Icon name="loader" class="size-4 motion-safe:animate-spin" />
|
|
41
|
+
{:else}
|
|
42
|
+
<Icon name="plus" class="size-4" />
|
|
43
|
+
{/if}
|
|
32
44
|
{$t('workflows.list.newWorkflow')}
|
|
33
45
|
</Button>
|
|
34
46
|
</div>
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
interface Props {
|
|
2
2
|
/** The person pressed the button that makes the first workflow. */
|
|
3
3
|
oncreate: () => void;
|
|
4
|
+
/** A workflow is already being made (the button is disabled and shows a spinner). */
|
|
5
|
+
busy?: boolean;
|
|
4
6
|
}
|
|
5
7
|
declare const WorkflowsEmptyState: import("svelte").Component<Props, {}, "">;
|
|
6
8
|
type WorkflowsEmptyState = ReturnType<typeof WorkflowsEmptyState>;
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
onOpenWorkflow?: WorkflowsProps['onOpenWorkflow'];
|
|
27
27
|
onShowEmbedCode?: WorkflowsProps['onShowEmbedCode'];
|
|
28
28
|
presence?: WorkflowsProps['presence'];
|
|
29
|
+
assistant?: WorkflowsProps['assistant'];
|
|
29
30
|
onError: (error: WorkflowsError) => void;
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -38,6 +39,7 @@
|
|
|
38
39
|
onOpenWorkflow,
|
|
39
40
|
onShowEmbedCode,
|
|
40
41
|
presence = false,
|
|
42
|
+
assistant = null,
|
|
41
43
|
onError
|
|
42
44
|
}: Props = $props();
|
|
43
45
|
|
|
@@ -80,6 +82,7 @@
|
|
|
80
82
|
onerror={onError}
|
|
81
83
|
onshowembedcode={onShowEmbedCode}
|
|
82
84
|
{presence}
|
|
85
|
+
{assistant}
|
|
83
86
|
/>
|
|
84
87
|
{/key}
|
|
85
88
|
</div>
|
|
@@ -87,6 +90,7 @@
|
|
|
87
90
|
<!-- The list keeps its own spacing (the page header, the toolbar and the rows each have theirs), as the design has it. -->
|
|
88
91
|
<div class="flex min-h-0 flex-1 flex-col">
|
|
89
92
|
<WorkflowList
|
|
93
|
+
{workspaceId}
|
|
90
94
|
onopen={(id) => open(id)}
|
|
91
95
|
onerror={onError}
|
|
92
96
|
onshowembedcode={onShowEmbedCode}
|
|
@@ -8,6 +8,7 @@ interface Props {
|
|
|
8
8
|
onOpenWorkflow?: WorkflowsProps['onOpenWorkflow'];
|
|
9
9
|
onShowEmbedCode?: WorkflowsProps['onShowEmbedCode'];
|
|
10
10
|
presence?: WorkflowsProps['presence'];
|
|
11
|
+
assistant?: WorkflowsProps['assistant'];
|
|
11
12
|
onError: (error: WorkflowsError) => void;
|
|
12
13
|
}
|
|
13
14
|
declare const WorkflowsWorkspace: import("svelte").Component<Props, {}, "">;
|