@widgetic/workflows 0.2.16 → 0.2.18
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 +22 -0
- package/dist/assistant/assistantEvents.d.ts +7 -1
- package/dist/assistant/assistantStream.js +19 -13
- package/dist/assistant/creditsShortage.d.ts +31 -0
- package/dist/assistant/creditsShortage.js +51 -0
- package/dist/assistant/types.d.ts +50 -0
- package/dist/components/WorkflowsEmptyState.svelte +8 -3
- package/dist/components/assistant/WorkflowAssistantPanel.svelte +294 -20
- package/dist/components/list/WorkflowList.svelte +29 -19
- package/dist/editor/editorState.svelte.d.ts +2 -2
- package/dist/editor/listState.svelte.d.ts +2 -2
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +6 -0
- package/dist/i18n/messages.js +8 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -186,6 +186,28 @@ person approves it. The page gives the wiring; the screen holds no key.
|
|
|
186
186
|
| `suggestUrl` | `string` (optional) | Where the box asks how to go on: grey words after what the person typed (see below). Left out, the box suggests none. |
|
|
187
187
|
| `outcomeUrl` | `string` (optional) | Where the counts of what happened to the suggestions go: shown, taken, sent away. Counts only, never a word typed. |
|
|
188
188
|
| `agentMascot` | `boolean` (default `true`) | `false` draws the chat's plain round avatar instead of the mascot, and never loads the mascot's Three.js (see below). |
|
|
189
|
+
| `credits` | `WorkflowAssistantCredits` (optional) | What the page says about the workspace's credits, for the notice above the box: its name, "Manage credits", looking at the balance (below). |
|
|
190
|
+
| `references` | `WorkflowAssistantReferences` (optional) | What the page says about the widgets and compositions the assistant names in its words: their names now, and what pressing one does (below). |
|
|
191
|
+
|
|
192
|
+
**What the assistant writes, and when the credits run out.** The words of the assistant are markdown (lists, bold, links) in the darkest text of the panel, and a
|
|
193
|
+
long message of the person is folded to its first lines with "Show more". A panel that is scrolled up shows the arrow to the newest message, which glides the
|
|
194
|
+
list back down. After a build, "Worked for 4m 37s" folds the finished work. All of it is `@widgetic/chat`, so the package needs the chat version that ships it.
|
|
195
|
+
|
|
196
|
+
- **References.** The assistant names a widget or a composition with `[Spring sale](widgetic://composition/<id>)` and the panel draws a chip in the line. A
|
|
197
|
+
reference is an identity, not an address, so the page decides: `references.resolve(reference)` returns `{ href?, label?, openable? }` (the name it has now, an
|
|
198
|
+
address, or `openable: false` when it cannot be opened from here), and `references.open(reference)` is what a press does (usually opening the canvas or the
|
|
199
|
+
composition in another tab). Without them a chip shows the name the assistant wrote and does nothing.
|
|
200
|
+
- **Out of credits.** Planning costs no credits; the build of an approved plan does. When the gateway refuses the build for credits (the stream's
|
|
201
|
+
`INSUFFICIENT_CREDITS` error, or a 402 `BILLING_INSUFFICIENT_CREDITS`), a notice goes up above the box ("You're out of AI credits in Design Team. Credits reset
|
|
202
|
+
Nov 26.", with a "Manage credits" button) and the box is shut. **It stays until the credits are back**, even after a reload: `credits.scope` (the workspace's
|
|
203
|
+
id) is the key it is kept under, and `credits.creditsAreBack({ required })` looks at the balance when the person comes back to the tab (resolve `true` when it
|
|
204
|
+
can spend again, `false` when it is still out, `null` when it could not be read: the notice then stays). The reset day comes from the refusal
|
|
205
|
+
(`details.resetsAt`) and the notice goes by itself on that day. `credits.workspaceName()` names the workspace and `credits.onManage()` opens where credits are
|
|
206
|
+
added (the button is not drawn without it). All four are optional: without them the notice still goes up, with less in it. Because planning itself is free, the
|
|
207
|
+
box that is shut while the notice shows follows the request of 21 Nov 2026 (the chats are disabled until there are new credits); it can be loosened for this
|
|
208
|
+
panel if planning should stay open.
|
|
209
|
+
- **Support ID.** The row under the last answer has an "i" ("Copy debug details") that opens a card with the id the gateway echoed for the latest request
|
|
210
|
+
(`X-Correlation-Id`), to send to support. The panel only reads that header; it sends no header of its own for it.
|
|
189
211
|
|
|
190
212
|
**The assistant's face** is the Scribble Mascot (`@widgetic/brand`), the one it has in the chat of the Widgetic creator, and
|
|
191
213
|
it moves the way it does there: it thinks (large) while the person waits for the first word, writes (small) while the
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type WorkflowAssistantSaveMode } from './assistantSaveMode.js';
|
|
2
2
|
import type { CompositionReference } from './compositionMention.js';
|
|
3
3
|
import { type AssistantDataPreview, type PlanBindingStatus } from './liveData.js';
|
|
4
|
+
import type { AssistantCreditsShortage } from './creditsShortage.js';
|
|
4
5
|
import type { McpReference } from './mcpMention.js';
|
|
5
6
|
import type { AssistantPlanCardState, AssistantQuestionCardState, AssistantTranscriptMessage } from './types.js';
|
|
6
7
|
export interface AssistantUiState {
|
|
@@ -29,12 +30,17 @@ export type AssistantUiAction = {
|
|
|
29
30
|
type: 'streaming';
|
|
30
31
|
value: boolean;
|
|
31
32
|
}
|
|
32
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* `failed`: the words are a failure's (the server's error, not a reply), so the assistant's face can look worried.
|
|
35
|
+
* `creditsShortage`: the failure is that the workspace is out of AI credits, and this is what the gateway said about it (the workspace,
|
|
36
|
+
* the day its credits reset). The panel puts the notice above its box from it; like `failed` it is not kept in the transcript.
|
|
37
|
+
*/
|
|
33
38
|
| {
|
|
34
39
|
type: 'assistant_text';
|
|
35
40
|
id: string;
|
|
36
41
|
text: string;
|
|
37
42
|
failed?: boolean;
|
|
43
|
+
creditsShortage?: AssistantCreditsShortage;
|
|
38
44
|
} | {
|
|
39
45
|
type: 'question_card';
|
|
40
46
|
card: AssistantQuestionCardState;
|
|
@@ -3,6 +3,7 @@ import { isPlanBindingStatus, parseDataPreview, parsePlanBindings } from './live
|
|
|
3
3
|
import { mapWorkflowPlanWireToCard } from './workflowPlanViewModel.js';
|
|
4
4
|
import { saveModeFromWire } from './assistantSaveMode.js';
|
|
5
5
|
import { isCanvasId } from './canvasLink.js';
|
|
6
|
+
import { creditsShortageOfErrorEvent } from './creditsShortage.js';
|
|
6
7
|
import { parseTemplateDestinations } from './templateDestinations.js';
|
|
7
8
|
/**
|
|
8
9
|
* The assistant saved a change to the draft a moment ago (on the chat stream while it edits, on the approve stream while the
|
|
@@ -18,6 +19,21 @@ function workflowUpdatedAction(payload) {
|
|
|
18
19
|
revision: typeof payload.revision === 'number' && Number.isFinite(payload.revision) ? payload.revision : null,
|
|
19
20
|
};
|
|
20
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* An `error` event as the transcript shows it: its words, as a failure (the assistant's face looks worried). When the error is that the
|
|
24
|
+
* workspace is out of AI credits it also carries what the gateway said about it (`creditsShortage`: the workspace, the day its credits
|
|
25
|
+
* reset), so the panel can put the notice above its box. The action sequence is the same either way.
|
|
26
|
+
*/
|
|
27
|
+
function errorTextAction(payload) {
|
|
28
|
+
const creditsShortage = creditsShortageOfErrorEvent(payload);
|
|
29
|
+
return {
|
|
30
|
+
type: 'assistant_text',
|
|
31
|
+
id: crypto.randomUUID(),
|
|
32
|
+
text: String(payload.message ?? WORKFLOWS_MESSAGES['workflows.error.generic']),
|
|
33
|
+
failed: true,
|
|
34
|
+
...(creditsShortage ? { creditsShortage } : {}),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
21
37
|
export async function* parseAssistantSseStream(response) {
|
|
22
38
|
const reader = response.body?.getReader();
|
|
23
39
|
if (!reader)
|
|
@@ -115,12 +131,7 @@ function* mapStreamPayloadToAction(payload) {
|
|
|
115
131
|
};
|
|
116
132
|
break;
|
|
117
133
|
case 'error':
|
|
118
|
-
yield
|
|
119
|
-
type: 'assistant_text',
|
|
120
|
-
id: crypto.randomUUID(),
|
|
121
|
-
text: String(payload.message ?? WORKFLOWS_MESSAGES['workflows.error.generic']),
|
|
122
|
-
failed: true,
|
|
123
|
-
};
|
|
134
|
+
yield errorTextAction(payload);
|
|
124
135
|
break;
|
|
125
136
|
case 'done':
|
|
126
137
|
yield { type: 'done' };
|
|
@@ -178,13 +189,8 @@ export async function* parseAssistantApproveStream(response) {
|
|
|
178
189
|
}
|
|
179
190
|
else if (payload.type === 'error') {
|
|
180
191
|
// Credits short, a plan used twice, a build that failed: the person is told in the chat, not left looking at a card
|
|
181
|
-
// that does nothing.
|
|
182
|
-
yield
|
|
183
|
-
type: 'assistant_text',
|
|
184
|
-
id: crypto.randomUUID(),
|
|
185
|
-
text: String(payload.message ?? WORKFLOWS_MESSAGES['workflows.error.generic']),
|
|
186
|
-
failed: true,
|
|
187
|
-
};
|
|
192
|
+
// that does nothing. Credits short also says which workspace and when its credits reset (the notice above the box).
|
|
193
|
+
yield errorTextAction(payload);
|
|
188
194
|
}
|
|
189
195
|
else if (payload.type === 'workflow_updated') {
|
|
190
196
|
// A widget of the plan went into the open workflow while the others are still being built: the editor shows it now.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the gateway tells when a workspace is out of AI credits, read for the notice the panel keeps above its box.
|
|
3
|
+
*
|
|
4
|
+
* The chat of the workflows assistant costs no credits; approving a plan does (the widgets it builds are paid for in the workspace the
|
|
5
|
+
* plan was written for). Two places tell of a shortage:
|
|
6
|
+
* - the stream of the approval sends an `error` event with the code `INSUFFICIENT_CREDITS` and `details`: the credits the plan needs
|
|
7
|
+
* (`required`), the workspace (`workspaceId`) and the day its credits reset (`resetsAt`, left out when the plan ends);
|
|
8
|
+
* - any request can be answered with a `402` `BILLING_INSUFFICIENT_CREDITS` before a stream begins. The panel reads that one with the
|
|
9
|
+
* chat's `creditsShortageOfAnswer`, which gives the same shape.
|
|
10
|
+
*
|
|
11
|
+
* Every part of `details` is optional (an older gateway sends none of it), and a part that is not what it should be is `null`: the notice
|
|
12
|
+
* is made from what is known and says nothing of the rest.
|
|
13
|
+
*
|
|
14
|
+
* Plain TypeScript, with nothing imported from another package, so a test can load it as it is.
|
|
15
|
+
*/
|
|
16
|
+
/** What the gateway said about the shortage. The same shape as the chat's `CreditsShortage`, so the panel can hand it over as it is. */
|
|
17
|
+
export interface AssistantCreditsShortage {
|
|
18
|
+
/** The workspace that is out of credits (its id), when the gateway says which. */
|
|
19
|
+
readonly workspaceId: string | null;
|
|
20
|
+
/** The day the credits reset, as an ISO-8601 date-time. `null` when the plan does not renew, or the gateway did not say. */
|
|
21
|
+
readonly resetsAt: string | null;
|
|
22
|
+
/** The credits the refused request needed. */
|
|
23
|
+
readonly required: number | null;
|
|
24
|
+
/** The credits the workspace had (the ones that can still be spent). */
|
|
25
|
+
readonly available: number | null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The shortage an `error` event of a stream tells of, or `null` when the event is about anything else (a plan used twice, a build that
|
|
29
|
+
* failed). Never throws: a payload that is not an object is no shortage.
|
|
30
|
+
*/
|
|
31
|
+
export declare function creditsShortageOfErrorEvent(payload: unknown): AssistantCreditsShortage | null;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the gateway tells when a workspace is out of AI credits, read for the notice the panel keeps above its box.
|
|
3
|
+
*
|
|
4
|
+
* The chat of the workflows assistant costs no credits; approving a plan does (the widgets it builds are paid for in the workspace the
|
|
5
|
+
* plan was written for). Two places tell of a shortage:
|
|
6
|
+
* - the stream of the approval sends an `error` event with the code `INSUFFICIENT_CREDITS` and `details`: the credits the plan needs
|
|
7
|
+
* (`required`), the workspace (`workspaceId`) and the day its credits reset (`resetsAt`, left out when the plan ends);
|
|
8
|
+
* - any request can be answered with a `402` `BILLING_INSUFFICIENT_CREDITS` before a stream begins. The panel reads that one with the
|
|
9
|
+
* chat's `creditsShortageOfAnswer`, which gives the same shape.
|
|
10
|
+
*
|
|
11
|
+
* Every part of `details` is optional (an older gateway sends none of it), and a part that is not what it should be is `null`: the notice
|
|
12
|
+
* is made from what is known and says nothing of the rest.
|
|
13
|
+
*
|
|
14
|
+
* Plain TypeScript, with nothing imported from another package, so a test can load it as it is.
|
|
15
|
+
*/
|
|
16
|
+
/** The codes that say "the workspace is out of AI credits": the approval's own, and the code of the gateway's error envelope. */
|
|
17
|
+
const CREDITS_SHORTAGE_CODES = new Set(['INSUFFICIENT_CREDITS', 'BILLING_INSUFFICIENT_CREDITS']);
|
|
18
|
+
/** A string that says something, trimmed; `null` for anything else. */
|
|
19
|
+
function nonEmptyString(value) {
|
|
20
|
+
return typeof value === 'string' && value.trim() !== '' ? value.trim() : null;
|
|
21
|
+
}
|
|
22
|
+
/** A number that is a number; `null` for `NaN`, a string and a missing value. */
|
|
23
|
+
function finiteNumber(value) {
|
|
24
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : null;
|
|
25
|
+
}
|
|
26
|
+
/** A date written as text, written again as ISO-8601; `null` when it is not a date. */
|
|
27
|
+
function isoDateOf(value) {
|
|
28
|
+
const text = nonEmptyString(value);
|
|
29
|
+
if (text === null)
|
|
30
|
+
return null;
|
|
31
|
+
const milliseconds = Date.parse(text);
|
|
32
|
+
return Number.isFinite(milliseconds) ? new Date(milliseconds).toISOString() : null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The shortage an `error` event of a stream tells of, or `null` when the event is about anything else (a plan used twice, a build that
|
|
36
|
+
* failed). Never throws: a payload that is not an object is no shortage.
|
|
37
|
+
*/
|
|
38
|
+
export function creditsShortageOfErrorEvent(payload) {
|
|
39
|
+
if (!payload || typeof payload !== 'object')
|
|
40
|
+
return null;
|
|
41
|
+
const event = payload;
|
|
42
|
+
if (typeof event.code !== 'string' || !CREDITS_SHORTAGE_CODES.has(event.code))
|
|
43
|
+
return null;
|
|
44
|
+
const details = event.details && typeof event.details === 'object' ? event.details : {};
|
|
45
|
+
return {
|
|
46
|
+
workspaceId: nonEmptyString(details.workspaceId),
|
|
47
|
+
resetsAt: isoDateOf(details.resetsAt),
|
|
48
|
+
required: finiteNumber(details.required),
|
|
49
|
+
available: finiteNumber(details.available),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -39,7 +39,57 @@ export interface WorkflowAssistantConfig {
|
|
|
39
39
|
* left out, the Widgetic site's own `/canvas/{canvasId}` is used. Return the address for this canvas id.
|
|
40
40
|
*/
|
|
41
41
|
readonly canvasHref?: (canvasId: string) => string;
|
|
42
|
+
/**
|
|
43
|
+
* What the host says about the credits of the workspace, so the panel can keep the notice "You're out of AI credits in Design Team.
|
|
44
|
+
* Credits reset Nov 26." above its box (with the box shut) until the credits are back. Optional: left out, the notice still goes up
|
|
45
|
+
* when the gateway refuses for credits, with nothing to name the workspace and no button.
|
|
46
|
+
*/
|
|
47
|
+
readonly credits?: WorkflowAssistantCredits;
|
|
48
|
+
/**
|
|
49
|
+
* The widgets and compositions the assistant names in its words (`[Spring sale](widgetic://composition/<id>)`) are drawn as small
|
|
50
|
+
* chips in the line. This is what the host says about them: what each is called now, and what pressing one does. Optional: left out,
|
|
51
|
+
* a chip is a label that does nothing.
|
|
52
|
+
*/
|
|
53
|
+
readonly references?: WorkflowAssistantReferences;
|
|
54
|
+
}
|
|
55
|
+
/** What the host tells the panel about the credits of the workspace (see {@link WorkflowAssistantConfig.credits}). */
|
|
56
|
+
export interface WorkflowAssistantCredits {
|
|
57
|
+
/**
|
|
58
|
+
* The name of the workspace, for the notice ("Design Team"). A function, read when the notice is drawn: the list of the person's
|
|
59
|
+
* workspaces can arrive after the panel opened. `null` says the host does not know it.
|
|
60
|
+
*/
|
|
61
|
+
readonly workspaceName?: () => string | null | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* The "Manage credits" button: where the person adds credits (usually the billing page, in another tab, so the plan they are
|
|
64
|
+
* working on stays as it is). The button is not drawn without it.
|
|
65
|
+
*/
|
|
66
|
+
readonly onManage?: () => void;
|
|
67
|
+
/**
|
|
68
|
+
* Looks at the balance of the workspace: `true` when it can spend credits again, `false` when it is still out, and `null` when it
|
|
69
|
+
* could not be read (the notice stays: not knowing is no reason to open the box). It is asked when the person comes back to the
|
|
70
|
+
* page, and when the page is opened again with a notice that was kept. `required` is what the refused request needed, when known.
|
|
71
|
+
*/
|
|
72
|
+
readonly creditsAreBack?: (context: {
|
|
73
|
+
required: number | null;
|
|
74
|
+
}) => Promise<boolean | null>;
|
|
75
|
+
/**
|
|
76
|
+
* Where the notice is kept across a reload: the id of the workspace (a person who is out of credits in one workspace is not locked
|
|
77
|
+
* out of another). Left out, or without `creditsAreBack` to look at the balance, the notice is not kept across a reload: a notice
|
|
78
|
+
* that nothing can take away must not outlive the page.
|
|
79
|
+
*/
|
|
80
|
+
readonly scope?: string;
|
|
81
|
+
}
|
|
82
|
+
/** What the host tells the panel about the widgets and compositions the assistant names (see {@link WorkflowAssistantConfig.references}). */
|
|
83
|
+
export interface WorkflowAssistantReferences {
|
|
84
|
+
/**
|
|
85
|
+
* What the host knows about one: its current name, an address, or that it cannot be opened from here (`openable: false`).
|
|
86
|
+
* `null` or nothing says the host knows nothing, and the chip keeps the name the assistant wrote.
|
|
87
|
+
*/
|
|
88
|
+
readonly resolve?: (reference: ChatReference) => ChatReferenceTarget | null | undefined;
|
|
89
|
+
/** What pressing a chip does (usually: open the widget's canvas or the composition in another tab). Without it a chip is a label. */
|
|
90
|
+
readonly open?: (reference: ChatReference) => void;
|
|
42
91
|
}
|
|
92
|
+
import type { ChatReference, ChatReferenceTarget } from '@widgetic/chat';
|
|
43
93
|
import type { CompositionReference } from './compositionMention.js';
|
|
44
94
|
import type { AssistantPlanBindingCard, PlanBindingWire } from './liveData.js';
|
|
45
95
|
import type { McpReference } from './mcpMention.js';
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
What the list shows while the workspace has no workflow yet: what a workflow is, and the button that makes the first one.
|
|
3
3
|
A list that is empty because a search or a filter matches nothing does not show this; it says so in a line of its own.
|
|
4
|
+
|
|
5
|
+
The look is the one of every empty placeholder of the Widgetic site (the design system's EmptyState, Figma "Components" empty
|
|
6
|
+
state): a grey tile (muted) behind an icon in the foreground colour, a title in Body/Medium and a hint in Body/Default, both in
|
|
7
|
+
muted-foreground. It used to be a green tile with a heading-sized title, which made this list look unlike the others (owner,
|
|
8
|
+
18 Nov 2026).
|
|
4
9
|
-->
|
|
5
10
|
<script lang="ts">
|
|
6
11
|
import { useWorkflowsLanguage } from '../i18n/language.js';
|
|
@@ -22,11 +27,11 @@
|
|
|
22
27
|
|
|
23
28
|
<div class="flex flex-1 flex-col items-center justify-center px-4 py-12">
|
|
24
29
|
<div class="flex w-120 max-w-full flex-col items-center gap-3 px-12 text-center">
|
|
25
|
-
<div class="flex size-12 items-center justify-center rounded-xl bg-
|
|
26
|
-
<Icon name="route" class="size-4 text-
|
|
30
|
+
<div class="flex size-12 items-center justify-center rounded-xl bg-muted">
|
|
31
|
+
<Icon name="route" class="size-4 text-foreground" />
|
|
27
32
|
</div>
|
|
28
33
|
<div class="flex w-full flex-col gap-1">
|
|
29
|
-
<h2 class="text-
|
|
34
|
+
<h2 class="text-body-medium text-muted-foreground">{$t('workflows.empty.title')}</h2>
|
|
30
35
|
<p class="text-body text-muted-foreground">{$t('workflows.empty.hint')}</p>
|
|
31
36
|
</div>
|
|
32
37
|
<Button
|