@arbidocs/blocks 0.4.76 → 0.4.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/index.cjs +346 -258
- package/dist/agents/index.js +5 -5
- package/dist/agents/tasks/TaskActivityTimeline.d.ts +1 -1
- package/dist/agents/tasks/WorkflowThreadStrip.d.ts +15 -4
- package/dist/agents/workflows/SchemaForm.d.ts +6 -1
- package/dist/agents/workflows/StepBarFrame.d.ts +75 -0
- package/dist/agents/workflows/StepParts.d.ts +109 -0
- package/dist/agents/workflows/WorkflowRunner.d.ts +15 -2
- package/dist/agents/workflows/WorkflowStepBar.d.ts +9 -11
- package/dist/agents/workflows/index.d.ts +5 -2
- package/dist/agents/workflows/planSteps.d.ts +8 -1
- package/dist/agents/workflows/run.d.ts +61 -8
- package/dist/agents/workflows/stepWindow.d.ts +59 -0
- package/dist/agents/workflows/types.d.ts +133 -4
- package/dist/agents/workflows/useWorkflowPreview.d.ts +2 -1
- package/dist/agents/workflows/useWorkflowView.d.ts +19 -0
- package/dist/chat/ChatPage.d.ts +1 -1
- package/dist/chat/WorkflowStepChip.d.ts +24 -0
- package/dist/chat/chat-page-types.d.ts +9 -0
- package/dist/chat/index.cjs +130 -122
- package/dist/chat/index.d.ts +1 -0
- package/dist/chat/index.js +2 -2
- package/dist/{chunk-TKB7TVMW.js → chunk-5OC5CGYX.js} +168 -100
- package/dist/chunk-5OC5CGYX.js.map +1 -0
- package/dist/{chunk-ZWA7UUZL.cjs → chunk-7YUFMNFW.cjs} +2 -54
- package/dist/chunk-7YUFMNFW.cjs.map +1 -0
- package/dist/chunk-A24C6BNA.js +92 -0
- package/dist/chunk-A24C6BNA.js.map +1 -0
- package/dist/chunk-AINNADMT.cjs +62 -0
- package/dist/chunk-AINNADMT.cjs.map +1 -0
- package/dist/chunk-CWAZNXC5.js +441 -0
- package/dist/chunk-CWAZNXC5.js.map +1 -0
- package/dist/{chunk-UIWLDSTF.js → chunk-EWSEQEPL.js} +71 -7
- package/dist/chunk-EWSEQEPL.js.map +1 -0
- package/dist/chunk-FE4ULGOR.js +151 -0
- package/dist/chunk-FE4ULGOR.js.map +1 -0
- package/dist/chunk-FT5FFXSJ.js +60 -0
- package/dist/chunk-FT5FFXSJ.js.map +1 -0
- package/dist/{chunk-WJEKRSPH.js → chunk-ICBAFX5B.js} +3 -3
- package/dist/{chunk-WJEKRSPH.js.map → chunk-ICBAFX5B.js.map} +1 -1
- package/dist/{chunk-7CVF3DK2.cjs → chunk-IF6VAYIA.cjs} +5 -5
- package/dist/{chunk-7CVF3DK2.cjs.map → chunk-IF6VAYIA.cjs.map} +1 -1
- package/dist/chunk-MLAHDAN5.cjs +450 -0
- package/dist/chunk-MLAHDAN5.cjs.map +1 -0
- package/dist/{chunk-IPGKTUF7.cjs → chunk-MP6FK43E.cjs} +71 -5
- package/dist/chunk-MP6FK43E.cjs.map +1 -0
- package/dist/{chunk-5EBGRG3X.js → chunk-OPA2Y6YZ.js} +3 -54
- package/dist/chunk-OPA2Y6YZ.js.map +1 -0
- package/dist/{chunk-7FKARMA3.cjs → chunk-SSDISIDW.cjs} +190 -122
- package/dist/chunk-SSDISIDW.cjs.map +1 -0
- package/dist/chunk-TZR36PPP.cjs +95 -0
- package/dist/chunk-TZR36PPP.cjs.map +1 -0
- package/dist/chunk-VFIZYSZB.cjs +2783 -0
- package/dist/chunk-VFIZYSZB.cjs.map +1 -0
- package/dist/chunk-WXRCMIAE.js +2707 -0
- package/dist/chunk-WXRCMIAE.js.map +1 -0
- package/dist/{chunk-HITAN7JF.cjs → chunk-XMBYDLZQ.cjs} +4 -4
- package/dist/{chunk-HITAN7JF.cjs.map → chunk-XMBYDLZQ.cjs.map} +1 -1
- package/dist/{chunk-MK6NJQGF.js → chunk-XQDM6T6C.js} +3 -3
- package/dist/{chunk-MK6NJQGF.js.map → chunk-XQDM6T6C.js.map} +1 -1
- package/dist/chunk-ZVBPRMHJ.cjs +153 -0
- package/dist/chunk-ZVBPRMHJ.cjs.map +1 -0
- package/dist/connect/docx.cjs +10 -88
- package/dist/connect/docx.cjs.map +1 -1
- package/dist/connect/docx.js +6 -86
- package/dist/connect/docx.js.map +1 -1
- package/dist/connect/index.cjs +468 -49
- package/dist/connect/index.cjs.map +1 -1
- package/dist/connect/index.d.ts +2 -0
- package/dist/connect/index.js +454 -37
- package/dist/connect/index.js.map +1 -1
- package/dist/connection/ConnectedTagMatrix.d.ts +20 -0
- package/dist/connection/ConnectedWorkflowRunner.d.ts +28 -2
- package/dist/connection/WorkflowRunThread.d.ts +21 -0
- package/dist/connection/WorkflowRunnerDialogs.d.ts +37 -0
- package/dist/connection/useWorkflowThread.d.ts +12 -0
- package/dist/document-tools/index.cjs +7 -143
- package/dist/document-tools/index.cjs.map +1 -1
- package/dist/document-tools/index.js +5 -144
- package/dist/document-tools/index.js.map +1 -1
- package/dist/docx/index.cjs +18 -17
- package/dist/docx/index.cjs.map +1 -1
- package/dist/docx/index.js +3 -2
- package/dist/docx/index.js.map +1 -1
- package/dist/facts/index.cjs +1 -1
- package/dist/facts/index.js +1 -1
- package/dist/files/index.cjs +1 -1
- package/dist/files/index.js +1 -1
- package/dist/home/index.cjs +1 -1
- package/dist/home/index.js +1 -1
- package/dist/index.cjs +560 -431
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +10 -9
- package/dist/index.js.map +1 -1
- package/dist/shell/index.cjs +1 -1
- package/dist/shell/index.js +1 -1
- package/dist/studio/index.cjs +4 -4
- package/dist/studio/index.js +3 -3
- package/dist/tags/TagMatrix.d.ts +64 -0
- package/dist/tags/index.d.ts +3 -0
- package/dist/tags/tagMatrixModel.d.ts +39 -0
- package/dist/workflow-canvas/StepActionSettings.d.ts +132 -0
- package/dist/workflow-canvas/StepInspector.d.ts +25 -2
- package/dist/workflow-canvas/WorkflowBuilder.d.ts +11 -3
- package/dist/workflow-canvas/WorkflowCanvas.d.ts +27 -2
- package/dist/workflow-canvas/edit.d.ts +9 -1
- package/dist/workflow-canvas/index.cjs +882 -102
- package/dist/workflow-canvas/index.cjs.map +1 -1
- package/dist/workflow-canvas/index.js +849 -69
- package/dist/workflow-canvas/index.js.map +1 -1
- package/package.json +4 -4
- package/src/workflow-canvas/canvas.css +9 -0
- package/dist/chunk-22P5KNIM.js +0 -1422
- package/dist/chunk-22P5KNIM.js.map +0 -1
- package/dist/chunk-5EBGRG3X.js.map +0 -1
- package/dist/chunk-7FKARMA3.cjs.map +0 -1
- package/dist/chunk-IPGKTUF7.cjs.map +0 -1
- package/dist/chunk-TKB7TVMW.js.map +0 -1
- package/dist/chunk-UIWLDSTF.js.map +0 -1
- package/dist/chunk-VYRKO3XU.cjs +0 -1469
- package/dist/chunk-VYRKO3XU.cjs.map +0 -1
- package/dist/chunk-ZWA7UUZL.cjs.map +0 -1
package/dist/chunk-22P5KNIM.js
DELETED
|
@@ -1,1422 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { UploadDropzone } from './chunk-EVUEIBNU.js';
|
|
3
|
-
import { FoldSection } from './chunk-XD2M6LIG.js';
|
|
4
|
-
import { useElementSize } from './chunk-HOXKR26S.js';
|
|
5
|
-
import { testIdOr, prefixedTestId } from './chunk-7F6CBP3Z.js';
|
|
6
|
-
import { useState, useRef, useEffect, useCallback, useMemo, useLayoutEffect } from 'react';
|
|
7
|
-
import { cn, Card, Button, Label, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, Switch, Input, Textarea } from '@arbidocs/react/ui';
|
|
8
|
-
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
9
|
-
import { CheckCircle2, ArrowLeft, Loader2, ArrowRight, RotateCw, GitBranch, FileText, Check, AlertTriangle, MinusCircle } from 'lucide-react';
|
|
10
|
-
|
|
11
|
-
// src/agents/workflows/types.ts
|
|
12
|
-
var EMPTY_WORKFLOW_SCOPE = { folders: [], labels: [] };
|
|
13
|
-
|
|
14
|
-
// src/agents/workflows/workflow.ts
|
|
15
|
-
var isWorkflowScope = (value) => typeof value === "object" && value !== null && Array.isArray(value.folders) && Array.isArray(value.labels);
|
|
16
|
-
var isEmptyWorkflowScope = (scope) => scope.folders.length === 0 && scope.labels.length === 0 && !scope.documents?.length;
|
|
17
|
-
var isFileField = (field) => field.type === "scope" || field.type === "documents";
|
|
18
|
-
function emptyValue(field) {
|
|
19
|
-
switch (field.type) {
|
|
20
|
-
case "boolean":
|
|
21
|
-
return false;
|
|
22
|
-
case "scope":
|
|
23
|
-
return { folders: [], labels: [] };
|
|
24
|
-
case "documents":
|
|
25
|
-
return { folders: [], labels: [], documents: [] };
|
|
26
|
-
default:
|
|
27
|
-
return "";
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function defaultInputs(workflow) {
|
|
31
|
-
const inputs = {};
|
|
32
|
-
for (const field of workflow.inputs) {
|
|
33
|
-
const d = field.default;
|
|
34
|
-
inputs[field.name] = d === void 0 ? emptyValue(field) : isWorkflowScope(d) ? { ...d } : d;
|
|
35
|
-
}
|
|
36
|
-
return inputs;
|
|
37
|
-
}
|
|
38
|
-
function validateInputs(workflow, inputs) {
|
|
39
|
-
const errors = {};
|
|
40
|
-
for (const field of workflow.inputs) {
|
|
41
|
-
const value = inputs[field.name];
|
|
42
|
-
if (field.type === "number") {
|
|
43
|
-
const blank = value === "" || value === void 0;
|
|
44
|
-
if (blank) {
|
|
45
|
-
if (field.required) errors[field.name] = "required";
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
const n = Number(value);
|
|
49
|
-
if (Number.isNaN(n)) errors[field.name] = "number";
|
|
50
|
-
else if (field.min !== void 0 && n < field.min) errors[field.name] = "min";
|
|
51
|
-
else if (field.max !== void 0 && n > field.max) errors[field.name] = "max";
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
if (!field.required) continue;
|
|
55
|
-
if (field.type === "documents") {
|
|
56
|
-
if (!isWorkflowScope(value) || !value.documents?.length) errors[field.name] = "required";
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
if (field.type === "boolean" || field.type === "scope") continue;
|
|
60
|
-
if (typeof value !== "string" || value.trim() === "") errors[field.name] = "required";
|
|
61
|
-
}
|
|
62
|
-
return errors;
|
|
63
|
-
}
|
|
64
|
-
function promptFieldName(workflow) {
|
|
65
|
-
return workflow.inputs.find((f) => !f.advanced && (f.type === "text" || f.type === "longtext"))?.name;
|
|
66
|
-
}
|
|
67
|
-
var quoteList = (names) => {
|
|
68
|
-
const quoted = names.map((n) => `"${n}"`);
|
|
69
|
-
return quoted.length <= 1 ? quoted[0] ?? "" : `${quoted.slice(0, -1).join(", ")} and ${quoted[quoted.length - 1]}`;
|
|
70
|
-
};
|
|
71
|
-
function fragment(field, value, ctx) {
|
|
72
|
-
switch (field.type) {
|
|
73
|
-
case "documents": {
|
|
74
|
-
const ids = isWorkflowScope(value) ? value.documents ?? [] : [];
|
|
75
|
-
const names = ids.flatMap((id) => {
|
|
76
|
-
const title = ctx?.documentTitles?.[id];
|
|
77
|
-
return title ? [title] : [];
|
|
78
|
-
});
|
|
79
|
-
return quoteList(names);
|
|
80
|
-
}
|
|
81
|
-
case "boolean":
|
|
82
|
-
return value ? field.trueText ?? "yes" : field.falseText ?? "no";
|
|
83
|
-
case "select": {
|
|
84
|
-
const option = field.options?.find((o) => o.value === value);
|
|
85
|
-
return option ? option.text ?? option.label : String(value ?? "");
|
|
86
|
-
}
|
|
87
|
-
case "scope":
|
|
88
|
-
return "";
|
|
89
|
-
default:
|
|
90
|
-
return typeof value === "string" ? value.trim() : String(value ?? "");
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function composeWorkflowPrompt(workflow, inputs, ctx) {
|
|
94
|
-
if (workflow.run.kind !== "prompt") return "";
|
|
95
|
-
const byName = new Map(workflow.inputs.map((f) => [f.name, f]));
|
|
96
|
-
const template = workflow.run.promptTemplate;
|
|
97
|
-
let out = "";
|
|
98
|
-
let last = 0;
|
|
99
|
-
const append = (text, isValue) => {
|
|
100
|
-
let t = text;
|
|
101
|
-
if (!isValue) {
|
|
102
|
-
t = t.replace(/[ \t]{2,}/g, " ");
|
|
103
|
-
if (/[ \t]$/.test(out)) t = t.replace(/^[ \t]+/, "");
|
|
104
|
-
}
|
|
105
|
-
out += t;
|
|
106
|
-
};
|
|
107
|
-
for (const m of template.matchAll(/\{\{\s*([a-z][a-z0-9_]*)\s*\}\}/gi)) {
|
|
108
|
-
append(template.slice(last, m.index), false);
|
|
109
|
-
const field = byName.get(m[1]);
|
|
110
|
-
append(field ? fragment(field, inputs[m[1]], ctx) : "", true);
|
|
111
|
-
last = m.index + m[0].length;
|
|
112
|
-
}
|
|
113
|
-
append(template.slice(last), false);
|
|
114
|
-
return out.trim();
|
|
115
|
-
}
|
|
116
|
-
function buildLaunch(workflow, inputs, agentId) {
|
|
117
|
-
const scopeField = workflow.inputs.find(isFileField);
|
|
118
|
-
const raw = scopeField ? inputs[scopeField.name] : void 0;
|
|
119
|
-
const scope = isWorkflowScope(raw) ? raw : { ...EMPTY_WORKFLOW_SCOPE };
|
|
120
|
-
return { workflow, inputs, scope, agentId: agentId || workflow.defaultAgentId || void 0 };
|
|
121
|
-
}
|
|
122
|
-
function workflowAccepts(workflow) {
|
|
123
|
-
const kinds = /* @__PURE__ */ new Set();
|
|
124
|
-
for (const field of workflow.inputs) if (field.context) kinds.add(field.context);
|
|
125
|
-
return [...kinds];
|
|
126
|
-
}
|
|
127
|
-
function workflowsAccepting(workflows, supplied) {
|
|
128
|
-
return workflows.filter((w) => workflowAccepts(w).some((k) => supplied.includes(k)));
|
|
129
|
-
}
|
|
130
|
-
function workflowsForHost(workflows, host) {
|
|
131
|
-
return workflows.filter((w) => !w.host || w.host === host);
|
|
132
|
-
}
|
|
133
|
-
function inputsFromContext(workflow, context) {
|
|
134
|
-
const inputs = {};
|
|
135
|
-
for (const field of workflow.inputs) {
|
|
136
|
-
if (!field.context) continue;
|
|
137
|
-
if (field.context === "selection") {
|
|
138
|
-
if (context.selection) inputs[field.name] = context.selection;
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
const ids = field.context === "image" ? context.image ? [context.image] : [] : context.documents;
|
|
142
|
-
if (ids?.length && isFileField(field)) {
|
|
143
|
-
inputs[field.name] = { folders: [], labels: [], documents: ids.slice(0, field.max ?? 1) };
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return inputs;
|
|
147
|
-
}
|
|
148
|
-
var SKILL_PROMPT_LABEL = "What should it work on?";
|
|
149
|
-
var SKILL_PROMPT_FALLBACK_PLACEHOLDER = "Describe what you want";
|
|
150
|
-
var plainHint = (hint) => hint.replace(/^[<[]\s*|\s*[>\]]$/g, "").trim();
|
|
151
|
-
function skillToWorkflow(skill) {
|
|
152
|
-
const hint = plainHint((skill.arg_hint ?? "").trim());
|
|
153
|
-
const inputs = [
|
|
154
|
-
{
|
|
155
|
-
name: "args",
|
|
156
|
-
type: "longtext",
|
|
157
|
-
label: SKILL_PROMPT_LABEL,
|
|
158
|
-
placeholder: hint || SKILL_PROMPT_FALLBACK_PLACEHOLDER,
|
|
159
|
-
required: true
|
|
160
|
-
}
|
|
161
|
-
];
|
|
162
|
-
return {
|
|
163
|
-
id: skill.slug,
|
|
164
|
-
skill: skill.slug,
|
|
165
|
-
title: skill.name || skill.slug,
|
|
166
|
-
description: skill.description ?? "",
|
|
167
|
-
inputs,
|
|
168
|
-
run: { kind: "prompt", promptTemplate: `/${skill.slug} {{args}}` },
|
|
169
|
-
landing: "chat",
|
|
170
|
-
schedulable: true
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
var FIELD_TYPES = [
|
|
174
|
-
"text",
|
|
175
|
-
"longtext",
|
|
176
|
-
"boolean",
|
|
177
|
-
"select",
|
|
178
|
-
"number",
|
|
179
|
-
"date",
|
|
180
|
-
"scope",
|
|
181
|
-
"documents"
|
|
182
|
-
];
|
|
183
|
-
var str = (v) => typeof v === "string" ? v : void 0;
|
|
184
|
-
var num = (v) => typeof v === "number" ? v : void 0;
|
|
185
|
-
var bool = (v) => typeof v === "boolean" ? v : void 0;
|
|
186
|
-
function fieldFromFrontmatter(raw) {
|
|
187
|
-
if (typeof raw !== "object" || raw === null) return null;
|
|
188
|
-
const r = raw;
|
|
189
|
-
const name = str(r.name);
|
|
190
|
-
const type = FIELD_TYPES.find((t) => t === r.type);
|
|
191
|
-
if (!name || !/^[a-z][a-z0-9_]*$/.test(name) || !type) return null;
|
|
192
|
-
const options = Array.isArray(r.options) ? r.options.flatMap((o) => {
|
|
193
|
-
const ro = o;
|
|
194
|
-
const value = str(ro?.value);
|
|
195
|
-
const label = str(ro?.label);
|
|
196
|
-
return value && label ? [
|
|
197
|
-
{
|
|
198
|
-
value,
|
|
199
|
-
label,
|
|
200
|
-
description: str(ro.description),
|
|
201
|
-
text: str(ro.text),
|
|
202
|
-
icon: str(ro.icon)
|
|
203
|
-
}
|
|
204
|
-
] : [];
|
|
205
|
-
}) : void 0;
|
|
206
|
-
return {
|
|
207
|
-
name,
|
|
208
|
-
type,
|
|
209
|
-
label: str(r.label) ?? name,
|
|
210
|
-
description: str(r.description),
|
|
211
|
-
placeholder: str(r.placeholder),
|
|
212
|
-
required: bool(r.required),
|
|
213
|
-
default: r.default,
|
|
214
|
-
options,
|
|
215
|
-
min: num(r.min),
|
|
216
|
-
max: num(r.max),
|
|
217
|
-
trueText: str(r.true_text),
|
|
218
|
-
falseText: str(r.false_text),
|
|
219
|
-
advanced: bool(r.advanced),
|
|
220
|
-
accept: r.accept === "image" ? "image" : void 0,
|
|
221
|
-
context: r.context === "documents" || r.context === "selection" || r.context === "image" ? r.context : void 0,
|
|
222
|
-
by: Array.isArray(r.by) ? r.by.filter((b) => b === "folders" || b === "labels") : void 0
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
function workflowFromFrontmatter(id, frontmatter, body) {
|
|
226
|
-
const inputs = Array.isArray(frontmatter.inputs) ? frontmatter.inputs.flatMap((f) => {
|
|
227
|
-
const field = fieldFromFrontmatter(f);
|
|
228
|
-
return field ? [field] : [];
|
|
229
|
-
}) : [];
|
|
230
|
-
return {
|
|
231
|
-
id,
|
|
232
|
-
title: str(frontmatter.name) ?? id,
|
|
233
|
-
description: str(frontmatter.description) ?? "",
|
|
234
|
-
icon: str(frontmatter.icon),
|
|
235
|
-
inputs,
|
|
236
|
-
run: { kind: "prompt", promptTemplate: body.trim() },
|
|
237
|
-
landing: frontmatter.landing === "files" ? "files" : "chat",
|
|
238
|
-
requiresFiles: bool(frontmatter.requires_files),
|
|
239
|
-
schedulable: bool(frontmatter.schedulable) ?? true
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
function fieldToFrontmatter(field) {
|
|
243
|
-
return compact({
|
|
244
|
-
name: field.name,
|
|
245
|
-
type: field.type,
|
|
246
|
-
label: field.label,
|
|
247
|
-
description: field.description,
|
|
248
|
-
placeholder: field.placeholder,
|
|
249
|
-
required: field.required,
|
|
250
|
-
default: field.default,
|
|
251
|
-
options: field.options?.map(
|
|
252
|
-
(o) => compact({
|
|
253
|
-
value: o.value,
|
|
254
|
-
label: o.label,
|
|
255
|
-
description: o.description,
|
|
256
|
-
text: o.text,
|
|
257
|
-
icon: o.icon
|
|
258
|
-
})
|
|
259
|
-
),
|
|
260
|
-
min: field.min,
|
|
261
|
-
max: field.max,
|
|
262
|
-
true_text: field.trueText,
|
|
263
|
-
false_text: field.falseText,
|
|
264
|
-
advanced: field.advanced,
|
|
265
|
-
by: field.by,
|
|
266
|
-
accept: field.accept,
|
|
267
|
-
context: field.context
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
var compact = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !== void 0));
|
|
271
|
-
var DEFAULT_SCHEMA_FORM_LABELS = {
|
|
272
|
-
optional: "(optional)",
|
|
273
|
-
advanced: "More options",
|
|
274
|
-
errors: {
|
|
275
|
-
required: "This is needed to continue",
|
|
276
|
-
min: "Too small",
|
|
277
|
-
max: "Too large",
|
|
278
|
-
number: "Enter a number"
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
var TILE_MAX = 4;
|
|
282
|
-
function FieldControl({
|
|
283
|
-
field,
|
|
284
|
-
value,
|
|
285
|
-
error,
|
|
286
|
-
onChange,
|
|
287
|
-
l,
|
|
288
|
-
idFor,
|
|
289
|
-
renderScope,
|
|
290
|
-
renderDocuments,
|
|
291
|
-
renderIcon,
|
|
292
|
-
onEnterSubmit
|
|
293
|
-
}) {
|
|
294
|
-
const id = `${idFor()}-control`;
|
|
295
|
-
const testId = idFor();
|
|
296
|
-
switch (field.type) {
|
|
297
|
-
case "text":
|
|
298
|
-
return /* @__PURE__ */ jsx(
|
|
299
|
-
Input,
|
|
300
|
-
{
|
|
301
|
-
id,
|
|
302
|
-
"data-testid": testId,
|
|
303
|
-
value: String(value ?? ""),
|
|
304
|
-
placeholder: field.placeholder,
|
|
305
|
-
"aria-required": field.required || void 0,
|
|
306
|
-
"aria-invalid": error ? true : void 0,
|
|
307
|
-
"aria-describedby": error ? idFor("error") : void 0,
|
|
308
|
-
onChange: (e) => onChange(e.target.value)
|
|
309
|
-
}
|
|
310
|
-
);
|
|
311
|
-
case "longtext":
|
|
312
|
-
return /* @__PURE__ */ jsx(
|
|
313
|
-
Textarea,
|
|
314
|
-
{
|
|
315
|
-
id,
|
|
316
|
-
"data-testid": testId,
|
|
317
|
-
value: String(value ?? ""),
|
|
318
|
-
placeholder: field.placeholder,
|
|
319
|
-
"aria-required": field.required || void 0,
|
|
320
|
-
"aria-invalid": error ? true : void 0,
|
|
321
|
-
"aria-describedby": error ? idFor("error") : void 0,
|
|
322
|
-
className: "min-h-[96px]",
|
|
323
|
-
onChange: (e) => onChange(e.target.value),
|
|
324
|
-
onKeyDown: (e) => {
|
|
325
|
-
if (onEnterSubmit && e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) {
|
|
326
|
-
e.preventDefault();
|
|
327
|
-
onEnterSubmit();
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
);
|
|
332
|
-
case "number":
|
|
333
|
-
return /* @__PURE__ */ jsx(
|
|
334
|
-
Input,
|
|
335
|
-
{
|
|
336
|
-
id,
|
|
337
|
-
"data-testid": testId,
|
|
338
|
-
type: "number",
|
|
339
|
-
inputMode: "decimal",
|
|
340
|
-
min: field.min,
|
|
341
|
-
max: field.max,
|
|
342
|
-
value: value === void 0 ? "" : String(value),
|
|
343
|
-
placeholder: field.placeholder,
|
|
344
|
-
"aria-invalid": error ? true : void 0,
|
|
345
|
-
"aria-describedby": error ? idFor("error") : void 0,
|
|
346
|
-
onChange: (e) => onChange(e.target.value === "" ? "" : Number(e.target.value))
|
|
347
|
-
}
|
|
348
|
-
);
|
|
349
|
-
case "date":
|
|
350
|
-
return /* @__PURE__ */ jsx(
|
|
351
|
-
Input,
|
|
352
|
-
{
|
|
353
|
-
id,
|
|
354
|
-
"data-testid": testId,
|
|
355
|
-
type: "date",
|
|
356
|
-
value: String(value ?? ""),
|
|
357
|
-
"aria-invalid": error ? true : void 0,
|
|
358
|
-
"aria-describedby": error ? idFor("error") : void 0,
|
|
359
|
-
onChange: (e) => onChange(e.target.value)
|
|
360
|
-
}
|
|
361
|
-
);
|
|
362
|
-
case "boolean":
|
|
363
|
-
return /* @__PURE__ */ jsx(
|
|
364
|
-
Switch,
|
|
365
|
-
{
|
|
366
|
-
id,
|
|
367
|
-
"data-testid": testId,
|
|
368
|
-
checked: Boolean(value),
|
|
369
|
-
onCheckedChange: (checked) => onChange(checked)
|
|
370
|
-
}
|
|
371
|
-
);
|
|
372
|
-
case "select": {
|
|
373
|
-
const options = field.options ?? [];
|
|
374
|
-
if (options.length > 0 && options.length <= TILE_MAX) {
|
|
375
|
-
return /* @__PURE__ */ jsx(
|
|
376
|
-
"div",
|
|
377
|
-
{
|
|
378
|
-
role: "radiogroup",
|
|
379
|
-
"aria-label": field.label,
|
|
380
|
-
className: "grid grid-cols-2 gap-2 sm:grid-cols-4",
|
|
381
|
-
"data-testid": testId,
|
|
382
|
-
children: options.map((option) => {
|
|
383
|
-
const selected = value === option.value;
|
|
384
|
-
return /* @__PURE__ */ jsxs(
|
|
385
|
-
"button",
|
|
386
|
-
{
|
|
387
|
-
type: "button",
|
|
388
|
-
role: "radio",
|
|
389
|
-
"aria-checked": selected,
|
|
390
|
-
"data-testid": prefixedTestId(testId, option.value, {
|
|
391
|
-
testId: `workflow-field-${field.name}-${option.value}`
|
|
392
|
-
}),
|
|
393
|
-
onClick: () => {
|
|
394
|
-
onChange(option.value);
|
|
395
|
-
},
|
|
396
|
-
className: cn(
|
|
397
|
-
"flex min-h-24 flex-col items-center justify-center gap-1.5 rounded-lg border p-3 text-center transition-colors pointer-coarse:min-h-28 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
398
|
-
selected ? "border-primary bg-primary/10" : "border-border bg-card [&:hover]:border-primary [&:hover]:bg-muted"
|
|
399
|
-
),
|
|
400
|
-
children: [
|
|
401
|
-
option.icon && renderIcon && /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: renderIcon(option.icon) }),
|
|
402
|
-
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-foreground", children: option.label }),
|
|
403
|
-
option.description && /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: option.description })
|
|
404
|
-
]
|
|
405
|
-
},
|
|
406
|
-
option.value
|
|
407
|
-
);
|
|
408
|
-
})
|
|
409
|
-
}
|
|
410
|
-
);
|
|
411
|
-
}
|
|
412
|
-
return /* @__PURE__ */ jsxs(Select, { value: String(value ?? ""), onValueChange: (v) => onChange(v), children: [
|
|
413
|
-
/* @__PURE__ */ jsx(SelectTrigger, { id, "data-testid": testId, className: "pointer-coarse:min-h-11", children: /* @__PURE__ */ jsx(SelectValue, { placeholder: field.placeholder }) }),
|
|
414
|
-
/* @__PURE__ */ jsx(SelectContent, { children: options.map((o) => /* @__PURE__ */ jsx(SelectItem, { value: o.value, children: o.label }, o.value)) })
|
|
415
|
-
] });
|
|
416
|
-
}
|
|
417
|
-
case "scope": {
|
|
418
|
-
const scope = isWorkflowScope(value) ? value : { folders: [], labels: [] };
|
|
419
|
-
return /* @__PURE__ */ jsx("div", { "data-testid": testId, children: renderScope?.(field, scope, onChange) });
|
|
420
|
-
}
|
|
421
|
-
case "documents": {
|
|
422
|
-
const picked = isWorkflowScope(value) ? value : { folders: [], labels: [], documents: [] };
|
|
423
|
-
return /* @__PURE__ */ jsx("div", { "data-testid": testId, children: renderDocuments?.(field, picked, onChange) });
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
function FormField(props) {
|
|
428
|
-
const { field, error, l, idFor } = props;
|
|
429
|
-
const isBoolean = field.type === "boolean";
|
|
430
|
-
const showOptional = !field.required && field.type !== "boolean" && field.type !== "scope";
|
|
431
|
-
const label = /* @__PURE__ */ jsxs(
|
|
432
|
-
Label,
|
|
433
|
-
{
|
|
434
|
-
htmlFor: `${idFor()}-control`,
|
|
435
|
-
className: isBoolean ? "cursor-pointer font-normal" : void 0,
|
|
436
|
-
children: [
|
|
437
|
-
field.label,
|
|
438
|
-
showOptional && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
439
|
-
" ",
|
|
440
|
-
/* @__PURE__ */ jsx("span", { className: "font-normal text-muted-foreground", children: l.optional })
|
|
441
|
-
] })
|
|
442
|
-
]
|
|
443
|
-
}
|
|
444
|
-
);
|
|
445
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", "data-slot": "schema-field", "data-field": field.name, children: [
|
|
446
|
-
isBoolean ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2.5 pointer-coarse:min-h-11", children: [
|
|
447
|
-
/* @__PURE__ */ jsx(FieldControl, { ...props }),
|
|
448
|
-
label
|
|
449
|
-
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
450
|
-
field.type !== "scope" && label,
|
|
451
|
-
/* @__PURE__ */ jsx(FieldControl, { ...props })
|
|
452
|
-
] }),
|
|
453
|
-
field.description && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: field.description }),
|
|
454
|
-
error && /* @__PURE__ */ jsx(
|
|
455
|
-
"p",
|
|
456
|
-
{
|
|
457
|
-
id: idFor("error"),
|
|
458
|
-
role: "alert",
|
|
459
|
-
className: "text-xs text-destructive",
|
|
460
|
-
"data-testid": idFor("error"),
|
|
461
|
-
children: l.errors[error]
|
|
462
|
-
}
|
|
463
|
-
)
|
|
464
|
-
] });
|
|
465
|
-
}
|
|
466
|
-
function SchemaForm({
|
|
467
|
-
fields,
|
|
468
|
-
values,
|
|
469
|
-
onChange,
|
|
470
|
-
errors,
|
|
471
|
-
renderScope,
|
|
472
|
-
renderDocuments,
|
|
473
|
-
renderIcon,
|
|
474
|
-
onEnterSubmit,
|
|
475
|
-
testIdPrefix,
|
|
476
|
-
labels,
|
|
477
|
-
className
|
|
478
|
-
}) {
|
|
479
|
-
const l = {
|
|
480
|
-
...DEFAULT_SCHEMA_FORM_LABELS,
|
|
481
|
-
...labels,
|
|
482
|
-
errors: { ...DEFAULT_SCHEMA_FORM_LABELS.errors, ...labels?.errors }
|
|
483
|
-
};
|
|
484
|
-
const [advancedOpen, setAdvancedOpen] = useState(false);
|
|
485
|
-
const common = fields.filter((f) => !f.advanced);
|
|
486
|
-
const advanced = fields.filter((f) => f.advanced);
|
|
487
|
-
const render = (field) => /* @__PURE__ */ jsx(
|
|
488
|
-
FormField,
|
|
489
|
-
{
|
|
490
|
-
field,
|
|
491
|
-
value: values[field.name],
|
|
492
|
-
error: errors?.[field.name],
|
|
493
|
-
onChange: (v) => onChange(field.name, v),
|
|
494
|
-
l,
|
|
495
|
-
idFor: (suffix) => suffix ? `${testIdOr(testIdPrefix, { testId: "workflow-field" })}-${field.name}-${suffix}` : `${testIdOr(testIdPrefix, { testId: "workflow-field" })}-${field.name}`,
|
|
496
|
-
renderScope,
|
|
497
|
-
renderDocuments,
|
|
498
|
-
renderIcon,
|
|
499
|
-
onEnterSubmit
|
|
500
|
-
},
|
|
501
|
-
field.name
|
|
502
|
-
);
|
|
503
|
-
return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col gap-4", className), "data-slot": "schema-form", children: [
|
|
504
|
-
common.map(render),
|
|
505
|
-
advanced.length > 0 && /* @__PURE__ */ jsx(
|
|
506
|
-
FoldSection,
|
|
507
|
-
{
|
|
508
|
-
label: l.advanced,
|
|
509
|
-
open: advancedOpen,
|
|
510
|
-
onOpenChange: setAdvancedOpen,
|
|
511
|
-
testId: `${testIdOr(testIdPrefix, { testId: "workflow-field" })}-advanced-toggle`,
|
|
512
|
-
children: /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-4", children: advanced.map(render) })
|
|
513
|
-
}
|
|
514
|
-
)
|
|
515
|
-
] });
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
// src/agents/workflows/run.ts
|
|
519
|
-
function workflowSteps(workflow) {
|
|
520
|
-
return workflow.run.kind === "steps" ? workflow.run.steps : [];
|
|
521
|
-
}
|
|
522
|
-
var isSteppedWorkflow = (workflow) => workflow.run.kind === "steps";
|
|
523
|
-
function stepDependencies(steps, id) {
|
|
524
|
-
const i = steps.findIndex((s) => s.id === id);
|
|
525
|
-
if (i < 0) return [];
|
|
526
|
-
return steps[i].after ?? (i > 0 ? [steps[i - 1].id] : []);
|
|
527
|
-
}
|
|
528
|
-
function dependsOn(steps, a, b) {
|
|
529
|
-
const seen = /* @__PURE__ */ new Set();
|
|
530
|
-
const stack = [...stepDependencies(steps, a)];
|
|
531
|
-
while (stack.length) {
|
|
532
|
-
const id = stack.pop();
|
|
533
|
-
if (id === b) return true;
|
|
534
|
-
if (seen.has(id)) continue;
|
|
535
|
-
seen.add(id);
|
|
536
|
-
stack.push(...stepDependencies(steps, id));
|
|
537
|
-
}
|
|
538
|
-
return false;
|
|
539
|
-
}
|
|
540
|
-
function orderSteps(steps) {
|
|
541
|
-
const explicit = steps.map((s) => ({ ...s, after: stepDependencies(steps, s.id) }));
|
|
542
|
-
const known = new Set(explicit.map((s) => s.id));
|
|
543
|
-
const placed = /* @__PURE__ */ new Set();
|
|
544
|
-
const out = [];
|
|
545
|
-
let progress = true;
|
|
546
|
-
while (out.length < explicit.length && progress) {
|
|
547
|
-
progress = false;
|
|
548
|
-
for (const s of explicit) {
|
|
549
|
-
if (placed.has(s.id)) continue;
|
|
550
|
-
if (s.after.every((d) => placed.has(d) || !known.has(d))) {
|
|
551
|
-
out.push(s);
|
|
552
|
-
placed.add(s.id);
|
|
553
|
-
progress = true;
|
|
554
|
-
break;
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
return [...out, ...explicit.filter((s) => !placed.has(s.id))];
|
|
559
|
-
}
|
|
560
|
-
function validateWorkflowGraph(steps) {
|
|
561
|
-
const problems = [];
|
|
562
|
-
const ids = /* @__PURE__ */ new Set();
|
|
563
|
-
for (const s of steps) {
|
|
564
|
-
if (ids.has(s.id)) problems.push({ code: "duplicate", step: s.id });
|
|
565
|
-
ids.add(s.id);
|
|
566
|
-
}
|
|
567
|
-
steps.forEach((s, i) => {
|
|
568
|
-
for (const d of stepDependencies(steps, s.id)) {
|
|
569
|
-
if (!ids.has(d)) problems.push({ code: "unknown", step: s.id, dependency: d });
|
|
570
|
-
else if (d === s.id || dependsOn(steps, d, s.id)) problems.push({ code: "cycle", step: s.id });
|
|
571
|
-
else if (steps.findIndex((x) => x.id === d) > i)
|
|
572
|
-
problems.push({ code: "order", step: s.id, dependency: d });
|
|
573
|
-
}
|
|
574
|
-
});
|
|
575
|
-
return problems;
|
|
576
|
-
}
|
|
577
|
-
function stepLevels(steps) {
|
|
578
|
-
const depth = /* @__PURE__ */ new Map();
|
|
579
|
-
for (const s of steps) {
|
|
580
|
-
const deps = stepDependencies(steps, s.id).filter((d) => depth.has(d));
|
|
581
|
-
depth.set(s.id, deps.length ? Math.max(...deps.map((d) => depth.get(d))) + 1 : 0);
|
|
582
|
-
}
|
|
583
|
-
const levels = [];
|
|
584
|
-
for (const s of steps) (levels[depth.get(s.id)] ??= []).push(s);
|
|
585
|
-
return levels.filter(Boolean);
|
|
586
|
-
}
|
|
587
|
-
var STEP_EVENTS = {
|
|
588
|
-
step_started: "running",
|
|
589
|
-
step_done: "done",
|
|
590
|
-
step_skipped: "skipped",
|
|
591
|
-
step_failed: "failed"
|
|
592
|
-
};
|
|
593
|
-
function stepStatesFromActivity(events) {
|
|
594
|
-
const states = {};
|
|
595
|
-
for (const e of events) {
|
|
596
|
-
const status = STEP_EVENTS[e.kind];
|
|
597
|
-
const step = e.detail?.step;
|
|
598
|
-
if (!status || typeof step !== "string") continue;
|
|
599
|
-
const responseId = typeof e.detail?.response_id === "string" ? e.detail.response_id : void 0;
|
|
600
|
-
const error = typeof e.detail?.error === "string" ? e.detail.error : null;
|
|
601
|
-
const startedAt = status === "running" ? e.created_at : states[step]?.startedAt;
|
|
602
|
-
states[step] = {
|
|
603
|
-
status,
|
|
604
|
-
responseId: responseId ?? states[step]?.responseId ?? null,
|
|
605
|
-
error,
|
|
606
|
-
...startedAt ? { startedAt } : {}
|
|
607
|
-
};
|
|
608
|
-
}
|
|
609
|
-
return states;
|
|
610
|
-
}
|
|
611
|
-
function runFields(workflow) {
|
|
612
|
-
return [
|
|
613
|
-
...workflow.inputs,
|
|
614
|
-
...workflowSteps(workflow).flatMap((s) => s.kind === "form" ? s.inputs : [])
|
|
615
|
-
];
|
|
616
|
-
}
|
|
617
|
-
function initialRunInputs(workflow, inputs = {}) {
|
|
618
|
-
return { ...defaultInputs({ ...workflow, inputs: runFields(workflow) }), ...inputs };
|
|
619
|
-
}
|
|
620
|
-
var finished = (s) => s?.status === "done" || s?.status === "skipped";
|
|
621
|
-
function stepPhase(steps, states, id) {
|
|
622
|
-
const s = states[id];
|
|
623
|
-
if (s && s.status !== "pending") return s.status;
|
|
624
|
-
return stepDependencies(steps, id).every((d) => finished(states[d])) ? "ready" : "blocked";
|
|
625
|
-
}
|
|
626
|
-
var isRunFinished = (steps, states) => steps.length > 0 && steps.every((s) => finished(states[s.id]));
|
|
627
|
-
var isPersonStep = (step) => step.kind !== "agent";
|
|
628
|
-
function nextAction(steps, states, current) {
|
|
629
|
-
const i = steps.findIndex((s) => s.id === current);
|
|
630
|
-
const step = steps[i];
|
|
631
|
-
if (!step) return "wait";
|
|
632
|
-
const phase = stepPhase(steps, states, step.id);
|
|
633
|
-
if (phase === "blocked") return "wait";
|
|
634
|
-
const following = steps[i + 1];
|
|
635
|
-
const independentNext = !!following && !dependsOn(steps, following.id, step.id);
|
|
636
|
-
if (phase === "done" || phase === "skipped") {
|
|
637
|
-
if (following) return "move";
|
|
638
|
-
return isRunFinished(steps, states) ? "finish" : "wait";
|
|
639
|
-
}
|
|
640
|
-
if (isPersonStep(step)) return "complete";
|
|
641
|
-
if (phase !== "failed") return independentNext ? "move" : "wait";
|
|
642
|
-
const waitedFor = steps.slice(i + 1).some((s) => dependsOn(steps, s.id, step.id));
|
|
643
|
-
return waitedFor || !following ? "skip" : "move";
|
|
644
|
-
}
|
|
645
|
-
function validateStep(step, inputs) {
|
|
646
|
-
if (step.kind !== "form") return {};
|
|
647
|
-
return validateInputs(
|
|
648
|
-
{
|
|
649
|
-
id: step.id,
|
|
650
|
-
title: step.title,
|
|
651
|
-
inputs: step.inputs},
|
|
652
|
-
inputs
|
|
653
|
-
);
|
|
654
|
-
}
|
|
655
|
-
var asText = (value) => typeof value === "string" ? value.trim() : typeof value === "number" ? String(value) : "";
|
|
656
|
-
function fillStepInputs(templates, inputs) {
|
|
657
|
-
const out = {};
|
|
658
|
-
for (const [name, template] of Object.entries(templates ?? {})) {
|
|
659
|
-
const bare = /^\{\{\s*([a-z][a-z0-9_]*)\s*\}\}$/i.exec(template);
|
|
660
|
-
if (bare) {
|
|
661
|
-
out[name] = inputs[bare[1]] ?? "";
|
|
662
|
-
continue;
|
|
663
|
-
}
|
|
664
|
-
out[name] = fillRunText(template, inputs);
|
|
665
|
-
}
|
|
666
|
-
return out;
|
|
667
|
-
}
|
|
668
|
-
function fillRunText(template, inputs) {
|
|
669
|
-
return template.replace(/\{\{([^}]*)\}\}/g, (_, expr) => {
|
|
670
|
-
for (const ref of expr.split("||")) {
|
|
671
|
-
const text = asText(inputs[ref.trim()]);
|
|
672
|
-
if (text) return text;
|
|
673
|
-
}
|
|
674
|
-
return "";
|
|
675
|
-
}).trim();
|
|
676
|
-
}
|
|
677
|
-
function runThreadTitle(workflow, inputs) {
|
|
678
|
-
const template = workflow.run.kind === "steps" ? workflow.run.threadTitle : void 0;
|
|
679
|
-
return template && fillRunText(template, inputs) || workflow.title;
|
|
680
|
-
}
|
|
681
|
-
function reviewInstructions(step, inputs) {
|
|
682
|
-
return step.instructions && fillRunText(step.instructions, inputs) || step.title;
|
|
683
|
-
}
|
|
684
|
-
function composeStepPrompt(workflow, step, runInputs, { resolveWorkflow, compose } = {}) {
|
|
685
|
-
if (step.workflow) {
|
|
686
|
-
const target = resolveWorkflow?.(step.workflow);
|
|
687
|
-
if (!target) return "";
|
|
688
|
-
const inputs = { ...defaultInputs(target), ...fillStepInputs(step.with, runInputs) };
|
|
689
|
-
return target.run.kind === "prompt" ? composeWorkflowPrompt(target, inputs) : compose?.(target.id, inputs, runInputs) ?? "";
|
|
690
|
-
}
|
|
691
|
-
if (step.run?.kind === "prompt") {
|
|
692
|
-
return composeWorkflowPrompt(
|
|
693
|
-
{ ...workflow, inputs: runFields(workflow), run: step.run },
|
|
694
|
-
runInputs
|
|
695
|
-
);
|
|
696
|
-
}
|
|
697
|
-
return compose?.(step.id, runInputs, runInputs) ?? "";
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
// src/agents/workflows/planSteps.ts
|
|
701
|
-
var compact2 = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !== void 0 && v !== ""));
|
|
702
|
-
function placeholders(workflow) {
|
|
703
|
-
return Object.fromEntries(runFields(workflow).map((f) => [f.name, `{{${f.name}}}`]));
|
|
704
|
-
}
|
|
705
|
-
function agentStep(workflow, step, options) {
|
|
706
|
-
const target = step.workflow ? options.resolveWorkflow?.(step.workflow) : void 0;
|
|
707
|
-
if (target?.skill) return { skill: target.skill, inputs: step.with ?? {}, prompt: null };
|
|
708
|
-
const given = Object.entries(options.inputs ?? {}).filter(
|
|
709
|
-
([, v]) => v !== void 0 && v !== null && v !== ""
|
|
710
|
-
);
|
|
711
|
-
const inputs = { ...placeholders(workflow), ...Object.fromEntries(given) };
|
|
712
|
-
return { skill: null, inputs: null, prompt: composeStepPrompt(workflow, step, inputs, options) };
|
|
713
|
-
}
|
|
714
|
-
function toPlanSteps(workflow, options = {}) {
|
|
715
|
-
const layout = workflow.run.kind === "steps" ? workflow.run.layout : void 0;
|
|
716
|
-
return workflowSteps(workflow).map((step) => {
|
|
717
|
-
const ui = compact2({
|
|
718
|
-
description: step.description,
|
|
719
|
-
icon: step.icon,
|
|
720
|
-
commit: step.commit,
|
|
721
|
-
next_label: step.nextLabel,
|
|
722
|
-
position: layout?.[step.id],
|
|
723
|
-
...step.kind === "form" ? { fields: step.inputs } : {},
|
|
724
|
-
...step.kind === "upload" ? { required: step.required, accept: step.accept, hint: step.hint } : {},
|
|
725
|
-
...step.kind === "review" ? { instructions: step.instructions } : {},
|
|
726
|
-
...step.kind === "agent" ? {
|
|
727
|
-
output: step.output,
|
|
728
|
-
workflow: step.workflow,
|
|
729
|
-
with: step.with,
|
|
730
|
-
prompt_template: step.run?.kind === "prompt" ? step.run.promptTemplate : void 0
|
|
731
|
-
} : {}
|
|
732
|
-
});
|
|
733
|
-
return {
|
|
734
|
-
id: step.id,
|
|
735
|
-
title: step.title,
|
|
736
|
-
kind: step.kind,
|
|
737
|
-
after: step.after ?? null,
|
|
738
|
-
branch: step.kind === "agent" && !!step.branch,
|
|
739
|
-
requires_files: false,
|
|
740
|
-
ui,
|
|
741
|
-
// An unfinished signal (still being typed) is not saved: the server would refuse it.
|
|
742
|
-
...step.signals?.some((s) => !isIncompleteSignal(s)) ? { signals: step.signals.filter((s) => !isIncompleteSignal(s)).map(toPlanSignal) } : {},
|
|
743
|
-
...step.kind === "agent" ? agentStep(workflow, step, options) : { skill: null, inputs: null, prompt: null }
|
|
744
|
-
};
|
|
745
|
-
});
|
|
746
|
-
}
|
|
747
|
-
function toPlanSignal(signal) {
|
|
748
|
-
return signal.when ? { name: signal.name, when: signal.when } : { name: signal.name };
|
|
749
|
-
}
|
|
750
|
-
function isIncompleteSignal(signal) {
|
|
751
|
-
const when = signal.when;
|
|
752
|
-
if (!signal.name.trim()) return true;
|
|
753
|
-
if (!when) return false;
|
|
754
|
-
if ("field" in when) return !when.field || String(when.equals).trim() === "";
|
|
755
|
-
if ("contains" in when) return !when.contains.trim();
|
|
756
|
-
if ("matches" in when) return !when.matches.trim();
|
|
757
|
-
return false;
|
|
758
|
-
}
|
|
759
|
-
function fromPlanSignal(signal) {
|
|
760
|
-
const w = signal.when;
|
|
761
|
-
const when = w?.field != null && w.equals != null ? { field: w.field, equals: w.equals } : w?.contains != null ? { contains: w.contains } : w?.matches != null ? { matches: w.matches } : w?.approved ? { approved: true } : void 0;
|
|
762
|
-
return when ? { name: signal.name, when } : { name: signal.name };
|
|
763
|
-
}
|
|
764
|
-
function fromPlanSteps(steps) {
|
|
765
|
-
return (steps ?? []).map((p) => {
|
|
766
|
-
const ui = p.ui ?? {};
|
|
767
|
-
const base = {
|
|
768
|
-
id: p.id,
|
|
769
|
-
title: p.title,
|
|
770
|
-
description: ui.description,
|
|
771
|
-
icon: ui.icon,
|
|
772
|
-
commit: ui.commit,
|
|
773
|
-
nextLabel: ui.next_label,
|
|
774
|
-
...p.after != null ? { after: p.after } : {},
|
|
775
|
-
...p.signals?.length ? { signals: p.signals.map(fromPlanSignal) } : {}
|
|
776
|
-
};
|
|
777
|
-
switch (p.kind) {
|
|
778
|
-
case "form":
|
|
779
|
-
return { ...base, kind: "form", inputs: ui.fields ?? [] };
|
|
780
|
-
case "upload":
|
|
781
|
-
return { ...base, kind: "upload", required: ui.required, accept: ui.accept, hint: ui.hint };
|
|
782
|
-
case "review":
|
|
783
|
-
return { ...base, kind: "review", instructions: ui.instructions };
|
|
784
|
-
default: {
|
|
785
|
-
const promptTemplate = ui.prompt_template ?? p.prompt ?? void 0;
|
|
786
|
-
return {
|
|
787
|
-
...base,
|
|
788
|
-
kind: "agent",
|
|
789
|
-
workflow: ui.workflow ?? p.skill ?? void 0,
|
|
790
|
-
with: ui.with ?? p.inputs ?? void 0,
|
|
791
|
-
run: !ui.workflow && !p.skill && promptTemplate ? { kind: "prompt", promptTemplate } : void 0,
|
|
792
|
-
output: ui.output,
|
|
793
|
-
branch: p.branch || void 0
|
|
794
|
-
};
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
});
|
|
798
|
-
}
|
|
799
|
-
function layoutFromPlanSteps(steps) {
|
|
800
|
-
const entries = (steps ?? []).flatMap((p) => {
|
|
801
|
-
const position = p.ui?.position;
|
|
802
|
-
return position ? [[p.id, position]] : [];
|
|
803
|
-
});
|
|
804
|
-
return entries.length ? Object.fromEntries(entries) : void 0;
|
|
805
|
-
}
|
|
806
|
-
var errorMessage = (e) => e instanceof Error ? e.message : typeof e === "string" ? e : "Something went wrong.";
|
|
807
|
-
function firstOpen(steps, states) {
|
|
808
|
-
const open = steps.find((s) => !["done", "skipped"].includes(states[s.id]?.status ?? "pending"));
|
|
809
|
-
return open?.id ?? (steps.length && isRunFinished(steps, states) ? null : steps[0]?.id ?? null);
|
|
810
|
-
}
|
|
811
|
-
function useWorkflowView(options) {
|
|
812
|
-
const { steps, states, inputs, setInput } = options;
|
|
813
|
-
const [current, setCurrent] = useState(() => firstOpen(steps, states));
|
|
814
|
-
const [showErrors, setShowErrors] = useState(false);
|
|
815
|
-
const [busy, setBusy] = useState(false);
|
|
816
|
-
const [actionError, setActionError] = useState(null);
|
|
817
|
-
const optionsRef = useRef(options);
|
|
818
|
-
optionsRef.current = options;
|
|
819
|
-
const placed = useRef(steps.length > 0);
|
|
820
|
-
useEffect(() => {
|
|
821
|
-
if (placed.current || steps.length === 0) return;
|
|
822
|
-
placed.current = true;
|
|
823
|
-
setCurrent(firstOpen(steps, states));
|
|
824
|
-
}, [steps, states]);
|
|
825
|
-
const step = steps.find((s) => s.id === current);
|
|
826
|
-
const following = useCallback(
|
|
827
|
-
(id) => {
|
|
828
|
-
const i = steps.findIndex((s) => s.id === id);
|
|
829
|
-
return steps[i + 1]?.id ?? null;
|
|
830
|
-
},
|
|
831
|
-
[steps]
|
|
832
|
-
);
|
|
833
|
-
const onward = useCallback(
|
|
834
|
-
(id) => {
|
|
835
|
-
const { steps: s, states: st } = optionsRef.current;
|
|
836
|
-
const i = s.findIndex((x) => x.id === id);
|
|
837
|
-
const open = s.slice(i + 1).find((x) => !["done", "skipped"].includes(st[x.id]?.status ?? "pending"));
|
|
838
|
-
return open?.id ?? following(id);
|
|
839
|
-
},
|
|
840
|
-
[following]
|
|
841
|
-
);
|
|
842
|
-
const action = busy ? "wait" : nextAction(steps, states, current);
|
|
843
|
-
const next = useCallback(async () => {
|
|
844
|
-
const { steps: s, states: st, inputs: values } = optionsRef.current;
|
|
845
|
-
const at = s.find((x) => x.id === current);
|
|
846
|
-
const act2 = nextAction(s, st, current);
|
|
847
|
-
if (!at || act2 === "wait" || busy) return;
|
|
848
|
-
setActionError(null);
|
|
849
|
-
if (act2 === "finish") return setCurrent(null);
|
|
850
|
-
if (act2 === "move") return setCurrent(following(current));
|
|
851
|
-
setBusy(true);
|
|
852
|
-
try {
|
|
853
|
-
if (act2 === "skip") {
|
|
854
|
-
await optionsRef.current.skip(at.id);
|
|
855
|
-
} else {
|
|
856
|
-
if (Object.keys(validateStep(at, values)).length > 0) {
|
|
857
|
-
setShowErrors(true);
|
|
858
|
-
return;
|
|
859
|
-
}
|
|
860
|
-
await optionsRef.current.complete(at);
|
|
861
|
-
}
|
|
862
|
-
setShowErrors(false);
|
|
863
|
-
setCurrent(onward(at.id) ?? current);
|
|
864
|
-
} catch (e) {
|
|
865
|
-
setActionError(errorMessage(e));
|
|
866
|
-
} finally {
|
|
867
|
-
setBusy(false);
|
|
868
|
-
}
|
|
869
|
-
}, [current, busy, following, onward]);
|
|
870
|
-
const goTo = useCallback((stepId) => {
|
|
871
|
-
setShowErrors(false);
|
|
872
|
-
setActionError(null);
|
|
873
|
-
setCurrent(stepId);
|
|
874
|
-
}, []);
|
|
875
|
-
const index = steps.findIndex((s) => s.id === current);
|
|
876
|
-
const back = useCallback(() => {
|
|
877
|
-
const i = steps.findIndex((s) => s.id === current);
|
|
878
|
-
const to = i < 0 ? steps[steps.length - 1] : steps[i - 1];
|
|
879
|
-
if (to) goTo(to.id);
|
|
880
|
-
}, [steps, current, goTo]);
|
|
881
|
-
const act = useCallback(
|
|
882
|
-
(fn) => fn && (async (stepId) => {
|
|
883
|
-
setBusy(true);
|
|
884
|
-
setActionError(null);
|
|
885
|
-
try {
|
|
886
|
-
await fn(stepId);
|
|
887
|
-
} catch (e) {
|
|
888
|
-
setActionError(errorMessage(e));
|
|
889
|
-
} finally {
|
|
890
|
-
setBusy(false);
|
|
891
|
-
}
|
|
892
|
-
}),
|
|
893
|
-
[]
|
|
894
|
-
);
|
|
895
|
-
const currentRef = useRef(current);
|
|
896
|
-
currentRef.current = current;
|
|
897
|
-
const skip = useMemo(
|
|
898
|
-
() => act(async (id) => {
|
|
899
|
-
await optionsRef.current.skip(id);
|
|
900
|
-
if (currentRef.current !== id) return;
|
|
901
|
-
setShowErrors(false);
|
|
902
|
-
setCurrent(onward(id) ?? id);
|
|
903
|
-
}),
|
|
904
|
-
[act, onward]
|
|
905
|
-
);
|
|
906
|
-
const retry = useMemo(
|
|
907
|
-
() => options.retry ? act((id) => optionsRef.current.retry?.(id) ?? Promise.resolve()) : void 0,
|
|
908
|
-
// Only whether the host offers retry matters here.
|
|
909
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
910
|
-
[act, !!options.retry]
|
|
911
|
-
);
|
|
912
|
-
const isLocked = useCallback(
|
|
913
|
-
(stepId) => optionsRef.current.isLocked?.(stepId) ?? false,
|
|
914
|
-
[]
|
|
915
|
-
);
|
|
916
|
-
return {
|
|
917
|
-
steps,
|
|
918
|
-
step,
|
|
919
|
-
current,
|
|
920
|
-
isComplete: current === null,
|
|
921
|
-
inputs,
|
|
922
|
-
setInput,
|
|
923
|
-
stateOf: (id) => states[id],
|
|
924
|
-
phaseOf: (id) => stepPhase(steps, states, id),
|
|
925
|
-
isLocked,
|
|
926
|
-
errors: showErrors && step && !isLocked(step.id) ? validateStep(step, inputs) : {},
|
|
927
|
-
busy,
|
|
928
|
-
actionError,
|
|
929
|
-
isRunning: Object.values(states).some((s) => s.status === "running"),
|
|
930
|
-
action,
|
|
931
|
-
canBack: (current === null || index > 0) && !busy,
|
|
932
|
-
next,
|
|
933
|
-
back,
|
|
934
|
-
goTo,
|
|
935
|
-
skip,
|
|
936
|
-
retry,
|
|
937
|
-
restart: () => {
|
|
938
|
-
setShowErrors(false);
|
|
939
|
-
setActionError(null);
|
|
940
|
-
setCurrent(steps[0]?.id ?? null);
|
|
941
|
-
}
|
|
942
|
-
};
|
|
943
|
-
}
|
|
944
|
-
function PhaseMark({ phase, icon }) {
|
|
945
|
-
if (phase === "done") return /* @__PURE__ */ jsx(Check, { className: "size-3.5 shrink-0" });
|
|
946
|
-
if (phase === "running") return /* @__PURE__ */ jsx(Loader2, { className: "size-3.5 shrink-0 animate-spin" });
|
|
947
|
-
if (phase === "failed") return /* @__PURE__ */ jsx(AlertTriangle, { className: "size-3.5 shrink-0" });
|
|
948
|
-
if (phase === "skipped") return /* @__PURE__ */ jsx(MinusCircle, { className: "size-3.5 shrink-0" });
|
|
949
|
-
return icon ? /* @__PURE__ */ jsx("span", { className: "flex size-3.5 shrink-0 items-center justify-center [&_svg]:size-3.5", children: icon }) : null;
|
|
950
|
-
}
|
|
951
|
-
var PILL = "flex min-w-0 max-w-full shrink-0 items-center gap-2 whitespace-nowrap rounded-full border px-2.5 py-1.5 text-xs font-medium";
|
|
952
|
-
var LABEL = "min-w-0 max-w-[12rem] truncate";
|
|
953
|
-
function WorkflowStepBar({
|
|
954
|
-
run,
|
|
955
|
-
levels,
|
|
956
|
-
doneTitle,
|
|
957
|
-
doneIcon,
|
|
958
|
-
icon,
|
|
959
|
-
tid
|
|
960
|
-
}) {
|
|
961
|
-
const box = useRef(null);
|
|
962
|
-
const measure = useRef(null);
|
|
963
|
-
const row = useRef(null);
|
|
964
|
-
const { width } = useElementSize(box);
|
|
965
|
-
const [compact3, setCompact] = useState(false);
|
|
966
|
-
const titles = levels.map((l) => l.map((s) => s.title).join("\0")).join("") + doneTitle;
|
|
967
|
-
useLayoutEffect(() => {
|
|
968
|
-
const needed = measure.current?.scrollWidth ?? 0;
|
|
969
|
-
setCompact(width > 0 && needed > width);
|
|
970
|
-
}, [width, titles]);
|
|
971
|
-
useLayoutEffect(() => {
|
|
972
|
-
if (!compact3) return;
|
|
973
|
-
const el = row.current?.querySelector('[aria-current="step"]');
|
|
974
|
-
el?.scrollIntoView?.({ block: "nearest", inline: "nearest" });
|
|
975
|
-
}, [compact3, run.current]);
|
|
976
|
-
const pill = (s) => {
|
|
977
|
-
const phase = run.phaseOf(s.id);
|
|
978
|
-
const current = s.id === run.current;
|
|
979
|
-
return /* @__PURE__ */ jsxs(
|
|
980
|
-
"button",
|
|
981
|
-
{
|
|
982
|
-
type: "button",
|
|
983
|
-
onClick: () => run.goTo(s.id),
|
|
984
|
-
disabled: run.busy,
|
|
985
|
-
className: cn(
|
|
986
|
-
PILL,
|
|
987
|
-
"transition-colors disabled:cursor-default",
|
|
988
|
-
current ? "border-primary bg-primary/10 text-primary" : phase === "failed" ? "border-destructive/40 text-destructive" : phase === "done" || phase === "skipped" || phase === "running" ? "border-primary/30 bg-primary/5 text-primary" : "border-border text-muted-foreground"
|
|
989
|
-
),
|
|
990
|
-
"aria-current": current ? "step" : void 0,
|
|
991
|
-
"aria-label": s.title,
|
|
992
|
-
title: s.title,
|
|
993
|
-
"data-phase": phase,
|
|
994
|
-
"data-testid": tid(`step-${s.id}`),
|
|
995
|
-
children: [
|
|
996
|
-
/* @__PURE__ */ jsx(PhaseMark, { phase, icon: icon(s.icon) }),
|
|
997
|
-
(current || !compact3) && /* @__PURE__ */ jsx("span", { className: LABEL, "data-testid": tid(`step-${s.id}-label`), children: s.title })
|
|
998
|
-
]
|
|
999
|
-
},
|
|
1000
|
-
s.id
|
|
1001
|
-
);
|
|
1002
|
-
};
|
|
1003
|
-
const done = run.isComplete;
|
|
1004
|
-
return /* @__PURE__ */ jsxs("div", { ref: box, className: "relative min-w-0", children: [
|
|
1005
|
-
/* @__PURE__ */ jsx(
|
|
1006
|
-
"div",
|
|
1007
|
-
{
|
|
1008
|
-
ref: measure,
|
|
1009
|
-
"aria-hidden": true,
|
|
1010
|
-
className: "pointer-events-none invisible absolute left-0 top-0 flex w-max items-center gap-1.5",
|
|
1011
|
-
children: [...levels, [{ id: "__done", title: doneTitle }]].map((level, i) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
1012
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-col items-start gap-1", children: level.map((s) => /* @__PURE__ */ jsxs("div", { className: PILL, children: [
|
|
1013
|
-
/* @__PURE__ */ jsx("span", { className: "size-3.5 shrink-0" }),
|
|
1014
|
-
/* @__PURE__ */ jsx(
|
|
1015
|
-
"span",
|
|
1016
|
-
{
|
|
1017
|
-
className: cn(LABEL, "before:content-[attr(data-label)]"),
|
|
1018
|
-
"data-label": s.title
|
|
1019
|
-
}
|
|
1020
|
-
)
|
|
1021
|
-
] }, s.id)) }),
|
|
1022
|
-
i < levels.length && /* @__PURE__ */ jsx("div", { className: "w-2" })
|
|
1023
|
-
] }, i))
|
|
1024
|
-
}
|
|
1025
|
-
),
|
|
1026
|
-
/* @__PURE__ */ jsx(
|
|
1027
|
-
"ol",
|
|
1028
|
-
{
|
|
1029
|
-
ref: row,
|
|
1030
|
-
className: cn("flex w-full items-center gap-1.5", compact3 && "overflow-x-auto pb-1"),
|
|
1031
|
-
"data-compact": compact3 || void 0,
|
|
1032
|
-
"data-testid": tid("steps"),
|
|
1033
|
-
children: [...levels, null].map((level, i) => /* @__PURE__ */ jsxs(
|
|
1034
|
-
"li",
|
|
1035
|
-
{
|
|
1036
|
-
className: cn(
|
|
1037
|
-
"flex min-w-0 items-center gap-1.5",
|
|
1038
|
-
i < levels.length && !compact3 && "flex-1",
|
|
1039
|
-
compact3 && "flex-none"
|
|
1040
|
-
),
|
|
1041
|
-
children: [
|
|
1042
|
-
level ? /* @__PURE__ */ jsx("div", { className: "flex min-w-0 flex-col items-start gap-1", children: level.map(pill) }) : /* @__PURE__ */ jsxs(
|
|
1043
|
-
"div",
|
|
1044
|
-
{
|
|
1045
|
-
className: cn(
|
|
1046
|
-
PILL,
|
|
1047
|
-
done ? "border-primary bg-primary/10 text-primary" : "border-border text-muted-foreground"
|
|
1048
|
-
),
|
|
1049
|
-
"aria-current": done ? "step" : void 0,
|
|
1050
|
-
"aria-label": doneTitle,
|
|
1051
|
-
title: doneTitle,
|
|
1052
|
-
"data-testid": tid("step-done"),
|
|
1053
|
-
children: [
|
|
1054
|
-
/* @__PURE__ */ jsx(PhaseMark, { phase: "ready", icon: doneIcon }),
|
|
1055
|
-
(done || !compact3) && /* @__PURE__ */ jsx("span", { className: LABEL, children: doneTitle })
|
|
1056
|
-
]
|
|
1057
|
-
}
|
|
1058
|
-
),
|
|
1059
|
-
i < levels.length && /* @__PURE__ */ jsx(
|
|
1060
|
-
"div",
|
|
1061
|
-
{
|
|
1062
|
-
className: cn(
|
|
1063
|
-
"h-px",
|
|
1064
|
-
compact3 ? "w-3 flex-none" : "min-w-2 flex-1",
|
|
1065
|
-
level?.every((s) => ["done", "skipped"].includes(run.phaseOf(s.id))) ? "bg-primary/40" : "bg-border"
|
|
1066
|
-
)
|
|
1067
|
-
}
|
|
1068
|
-
)
|
|
1069
|
-
]
|
|
1070
|
-
},
|
|
1071
|
-
level ? level.map((s) => s.id).join("+") : "done"
|
|
1072
|
-
))
|
|
1073
|
-
}
|
|
1074
|
-
)
|
|
1075
|
-
] });
|
|
1076
|
-
}
|
|
1077
|
-
var DEFAULT_WORKFLOW_RUNNER_LABELS = {
|
|
1078
|
-
back: "Back",
|
|
1079
|
-
next: "Continue",
|
|
1080
|
-
skip: "Skip",
|
|
1081
|
-
skipStep: "Skip this step",
|
|
1082
|
-
finish: "Finish",
|
|
1083
|
-
approve: "Approve",
|
|
1084
|
-
working: "Working\u2026",
|
|
1085
|
-
stepWorking: "{step}\u2026 {elapsed}",
|
|
1086
|
-
starting: "Starting\u2026",
|
|
1087
|
-
retry: "Retry",
|
|
1088
|
-
failed: "This step did not finish.",
|
|
1089
|
-
blocked: "Starts after {steps}.",
|
|
1090
|
-
awaitingReview: "Waiting for approval.",
|
|
1091
|
-
approved: "Approved.",
|
|
1092
|
-
skipped: "Skipped.",
|
|
1093
|
-
branch: "Runs alongside; its result joins the thread",
|
|
1094
|
-
complete: "Done",
|
|
1095
|
-
restart: "Start again",
|
|
1096
|
-
filesHeading: "Already in the workspace ({count})",
|
|
1097
|
-
addedHeading: "Added for this step ({count})",
|
|
1098
|
-
noFiles: "No files yet.",
|
|
1099
|
-
fileReading: "Reading\u2026",
|
|
1100
|
-
fileReady: "Ready",
|
|
1101
|
-
fileFailed: "Could not be read",
|
|
1102
|
-
readingFiles: "Reading {current} of {count} files\u2026"
|
|
1103
|
-
};
|
|
1104
|
-
function WorkflowRunner({
|
|
1105
|
-
workflow,
|
|
1106
|
-
run,
|
|
1107
|
-
renderAgentOutput,
|
|
1108
|
-
renderReview,
|
|
1109
|
-
onUpload,
|
|
1110
|
-
uploading = false,
|
|
1111
|
-
files,
|
|
1112
|
-
renderUpload,
|
|
1113
|
-
renderStepNote,
|
|
1114
|
-
renderComplete,
|
|
1115
|
-
renderScope,
|
|
1116
|
-
renderDocuments,
|
|
1117
|
-
renderIcon,
|
|
1118
|
-
labels,
|
|
1119
|
-
testIdPrefix = "workflow-run",
|
|
1120
|
-
className
|
|
1121
|
-
}) {
|
|
1122
|
-
const l = { ...DEFAULT_WORKFLOW_RUNNER_LABELS, ...labels };
|
|
1123
|
-
const { steps, step, isComplete, action } = run;
|
|
1124
|
-
const completion = workflow.run.kind === "steps" ? workflow.run.completion : void 0;
|
|
1125
|
-
const tid = (suffix) => `${testIdPrefix}-${suffix}`;
|
|
1126
|
-
const levels = stepLevels(steps);
|
|
1127
|
-
const icon = (key) => key && renderIcon ? renderIcon(key) : void 0;
|
|
1128
|
-
const added = step?.kind === "upload" ? (files ?? []).filter((f) => f.addedFor === step.id) : [];
|
|
1129
|
-
const unread = added.filter((f) => f.status === "processing").length;
|
|
1130
|
-
const reading = action === "complete" && unread > 0;
|
|
1131
|
-
const nextLabel = reading ? l.readingFiles.replace("{current}", String(Math.min(added.length - unread + 1, added.length))).replace("{count}", String(added.length)) : action === "skip" ? l.skip : action === "finish" ? l.finish : action === "complete" && step?.kind === "review" ? l.approve : action === "wait" && (run.isRunning || run.busy) ? l.working : (step && !run.isLocked(step.id) ? step.nextLabel : void 0) ?? l.next;
|
|
1132
|
-
return /* @__PURE__ */ jsxs("div", { className: cn("space-y-6", className), "data-testid": testIdPrefix, children: [
|
|
1133
|
-
/* @__PURE__ */ jsx(
|
|
1134
|
-
WorkflowStepBar,
|
|
1135
|
-
{
|
|
1136
|
-
run,
|
|
1137
|
-
levels,
|
|
1138
|
-
doneTitle: completion?.title ?? l.complete,
|
|
1139
|
-
doneIcon: icon(completion?.icon),
|
|
1140
|
-
icon,
|
|
1141
|
-
tid
|
|
1142
|
-
}
|
|
1143
|
-
),
|
|
1144
|
-
isComplete ? renderComplete?.(run) ?? /* @__PURE__ */ jsxs(Card, { className: "mx-auto max-w-lg p-8 text-center", "data-testid": tid("done"), children: [
|
|
1145
|
-
/* @__PURE__ */ jsx(CheckCircle2, { className: "mx-auto size-12 text-primary" }),
|
|
1146
|
-
/* @__PURE__ */ jsx("h2", { className: "mt-4 text-xl font-semibold", children: completion?.title ?? l.complete }),
|
|
1147
|
-
completion?.description && /* @__PURE__ */ jsx("p", { className: "mt-1 text-sm text-muted-foreground", children: completion.description }),
|
|
1148
|
-
/* @__PURE__ */ jsx(
|
|
1149
|
-
Button,
|
|
1150
|
-
{
|
|
1151
|
-
variant: "outline",
|
|
1152
|
-
className: "mt-6",
|
|
1153
|
-
onClick: run.restart,
|
|
1154
|
-
"data-testid": tid("restart"),
|
|
1155
|
-
children: l.restart
|
|
1156
|
-
}
|
|
1157
|
-
)
|
|
1158
|
-
] }) : step ? /* @__PURE__ */ jsx("div", { className: "space-y-3", children: run.phaseOf(step.id) === "blocked" ? /* @__PURE__ */ jsx(Card, { className: "max-w-2xl p-6", "data-testid": tid(step.id), children: /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", "data-testid": tid(`${step.id}-blocked`), children: l.blocked.replace(
|
|
1159
|
-
"{steps}",
|
|
1160
|
-
stepDependencies(steps, step.id).map((d) => steps.find((s) => s.id === d)?.title ?? d).join(", ")
|
|
1161
|
-
) }) }) : step.kind === "form" ? /* @__PURE__ */ jsxs(Card, { className: "max-w-2xl space-y-4 p-6", "data-testid": tid(step.id), children: [
|
|
1162
|
-
/* @__PURE__ */ jsx(StepHeading, { step, icon: icon(step.icon), testId: tid(`${step.id}-title`) }),
|
|
1163
|
-
/* @__PURE__ */ jsx("fieldset", { disabled: run.isLocked(step.id), className: "contents", children: /* @__PURE__ */ jsx(
|
|
1164
|
-
SchemaForm,
|
|
1165
|
-
{
|
|
1166
|
-
fields: step.inputs,
|
|
1167
|
-
values: run.inputs,
|
|
1168
|
-
onChange: run.setInput,
|
|
1169
|
-
errors: run.errors,
|
|
1170
|
-
renderScope,
|
|
1171
|
-
renderDocuments,
|
|
1172
|
-
renderIcon,
|
|
1173
|
-
onEnterSubmit: () => void run.next(),
|
|
1174
|
-
testIdPrefix: tid("field")
|
|
1175
|
-
}
|
|
1176
|
-
) }),
|
|
1177
|
-
run.actionError && /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", "data-testid": tid("action-error"), children: run.actionError }),
|
|
1178
|
-
renderStepNote?.(step, run)
|
|
1179
|
-
] }) : step.kind === "upload" ? /* @__PURE__ */ jsxs(Card, { className: "max-w-2xl space-y-4 p-6", "data-testid": tid(step.id), children: [
|
|
1180
|
-
renderUpload?.(step) ?? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1181
|
-
/* @__PURE__ */ jsx(
|
|
1182
|
-
UploadDropzone,
|
|
1183
|
-
{
|
|
1184
|
-
onFiles: (picked) => void onUpload?.(picked, step),
|
|
1185
|
-
uploading,
|
|
1186
|
-
disabled: !onUpload,
|
|
1187
|
-
accept: step.accept,
|
|
1188
|
-
title: step.title,
|
|
1189
|
-
description: step.description,
|
|
1190
|
-
hint: step.hint,
|
|
1191
|
-
testId: tid(`${step.id}-drop`)
|
|
1192
|
-
}
|
|
1193
|
-
),
|
|
1194
|
-
files && /* @__PURE__ */ jsx(
|
|
1195
|
-
UploadFiles,
|
|
1196
|
-
{
|
|
1197
|
-
added,
|
|
1198
|
-
others: files.filter((f) => f.addedFor !== step.id),
|
|
1199
|
-
l,
|
|
1200
|
-
testId: tid(`${step.id}-files`)
|
|
1201
|
-
}
|
|
1202
|
-
)
|
|
1203
|
-
] }),
|
|
1204
|
-
run.actionError && /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: run.actionError }),
|
|
1205
|
-
renderStepNote?.(step, run)
|
|
1206
|
-
] }) : step.kind === "review" ? /* @__PURE__ */ jsxs(Card, { className: "max-w-2xl space-y-4 p-6", "data-testid": tid(step.id), children: [
|
|
1207
|
-
/* @__PURE__ */ jsx(StepHeading, { step, icon: icon(step.icon) }),
|
|
1208
|
-
/* @__PURE__ */ jsx("p", { className: "whitespace-pre-line text-sm text-muted-foreground", children: reviewInstructions(step, run.inputs) }),
|
|
1209
|
-
/* @__PURE__ */ jsx("p", { className: "text-sm", "data-testid": tid(`${step.id}-status`), children: run.phaseOf(step.id) === "done" ? l.approved : run.phaseOf(step.id) === "skipped" ? l.skipped : l.awaitingReview }),
|
|
1210
|
-
run.phaseOf(step.id) === "ready" && renderReview?.(step),
|
|
1211
|
-
run.actionError && /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: run.actionError }),
|
|
1212
|
-
renderStepNote?.(step, run)
|
|
1213
|
-
] }) : /* @__PURE__ */ jsx(
|
|
1214
|
-
AgentStepBody,
|
|
1215
|
-
{
|
|
1216
|
-
step,
|
|
1217
|
-
run,
|
|
1218
|
-
renderAgentOutput,
|
|
1219
|
-
icon: icon(step.icon),
|
|
1220
|
-
renderStepNote,
|
|
1221
|
-
l,
|
|
1222
|
-
tid
|
|
1223
|
-
}
|
|
1224
|
-
) }, step.id) : null,
|
|
1225
|
-
!isComplete && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between border-t border-border pt-4", children: [
|
|
1226
|
-
/* @__PURE__ */ jsxs(
|
|
1227
|
-
Button,
|
|
1228
|
-
{
|
|
1229
|
-
variant: "ghost",
|
|
1230
|
-
onClick: run.back,
|
|
1231
|
-
disabled: !run.canBack,
|
|
1232
|
-
"data-testid": tid("back"),
|
|
1233
|
-
children: [
|
|
1234
|
-
/* @__PURE__ */ jsx(ArrowLeft, { className: "size-4" }),
|
|
1235
|
-
" ",
|
|
1236
|
-
l.back
|
|
1237
|
-
]
|
|
1238
|
-
}
|
|
1239
|
-
),
|
|
1240
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
1241
|
-
step && action !== "skip" && // A step that commits (creates the matter, starts the thread) is what the run stands on.
|
|
1242
|
-
!step.commit && ["ready", "blocked", "failed"].includes(run.phaseOf(step.id)) && /* @__PURE__ */ jsx(
|
|
1243
|
-
Button,
|
|
1244
|
-
{
|
|
1245
|
-
variant: "ghost",
|
|
1246
|
-
onClick: () => void run.skip(step.id),
|
|
1247
|
-
disabled: run.busy,
|
|
1248
|
-
"data-testid": tid("skip-step"),
|
|
1249
|
-
children: l.skipStep
|
|
1250
|
-
}
|
|
1251
|
-
),
|
|
1252
|
-
/* @__PURE__ */ jsxs(
|
|
1253
|
-
Button,
|
|
1254
|
-
{
|
|
1255
|
-
onClick: () => void run.next(),
|
|
1256
|
-
disabled: action === "wait" || reading,
|
|
1257
|
-
"data-testid": tid("next"),
|
|
1258
|
-
children: [
|
|
1259
|
-
nextLabel,
|
|
1260
|
-
reading || action === "wait" && (run.isRunning || run.busy) ? /* @__PURE__ */ jsx(Loader2, { className: "size-4 animate-spin" }) : /* @__PURE__ */ jsx(ArrowRight, { className: "size-4" })
|
|
1261
|
-
]
|
|
1262
|
-
}
|
|
1263
|
-
)
|
|
1264
|
-
] })
|
|
1265
|
-
] })
|
|
1266
|
-
] });
|
|
1267
|
-
}
|
|
1268
|
-
function UploadFiles({
|
|
1269
|
-
added,
|
|
1270
|
-
others,
|
|
1271
|
-
l,
|
|
1272
|
-
testId
|
|
1273
|
-
}) {
|
|
1274
|
-
const heading = "text-xs font-semibold uppercase tracking-wide text-muted-foreground";
|
|
1275
|
-
const row = (f) => /* @__PURE__ */ jsxs(
|
|
1276
|
-
"div",
|
|
1277
|
-
{
|
|
1278
|
-
className: "flex items-center gap-2 text-sm text-muted-foreground",
|
|
1279
|
-
"data-status": f.status,
|
|
1280
|
-
"data-testid": `${testId}-file-${f.id}`,
|
|
1281
|
-
children: [
|
|
1282
|
-
/* @__PURE__ */ jsx(FileText, { className: "size-3.5 shrink-0 text-primary" }),
|
|
1283
|
-
/* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate", title: f.name, children: f.name }),
|
|
1284
|
-
f.status === "processing" && /* @__PURE__ */ jsxs("span", { className: "flex shrink-0 items-center gap-1 text-xs", children: [
|
|
1285
|
-
/* @__PURE__ */ jsx(Loader2, { className: "size-3 animate-spin" }),
|
|
1286
|
-
" ",
|
|
1287
|
-
l.fileReading
|
|
1288
|
-
] }),
|
|
1289
|
-
f.status === "ready" && /* @__PURE__ */ jsxs("span", { className: "flex shrink-0 items-center gap-1 text-xs text-primary", children: [
|
|
1290
|
-
/* @__PURE__ */ jsx(Check, { className: "size-3" }),
|
|
1291
|
-
" ",
|
|
1292
|
-
l.fileReady
|
|
1293
|
-
] }),
|
|
1294
|
-
f.status === "failed" && /* @__PURE__ */ jsxs("span", { className: "flex shrink-0 items-center gap-1 text-xs text-destructive", children: [
|
|
1295
|
-
/* @__PURE__ */ jsx(AlertTriangle, { className: "size-3" }),
|
|
1296
|
-
" ",
|
|
1297
|
-
l.fileFailed
|
|
1298
|
-
] })
|
|
1299
|
-
]
|
|
1300
|
-
},
|
|
1301
|
-
f.id
|
|
1302
|
-
);
|
|
1303
|
-
return /* @__PURE__ */ jsxs("div", { className: "space-y-3", "data-testid": testId, children: [
|
|
1304
|
-
added.length > 0 && /* @__PURE__ */ jsxs("div", { className: "space-y-1", "data-testid": `${testId}-added`, children: [
|
|
1305
|
-
/* @__PURE__ */ jsx("p", { className: heading, children: l.addedHeading.replace("{count}", String(added.length)) }),
|
|
1306
|
-
added.map(row)
|
|
1307
|
-
] }),
|
|
1308
|
-
added.length === 0 && others.length === 0 && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: l.noFiles }),
|
|
1309
|
-
others.length > 0 && /* @__PURE__ */ jsxs("details", { className: "space-y-1", "data-testid": `${testId}-others`, children: [
|
|
1310
|
-
/* @__PURE__ */ jsx("summary", { className: cn(heading, "cursor-pointer select-none"), children: l.filesHeading.replace("{count}", String(others.length)) }),
|
|
1311
|
-
/* @__PURE__ */ jsx("div", { className: "mt-1 max-h-48 space-y-1 overflow-y-auto", children: others.map(row) })
|
|
1312
|
-
] })
|
|
1313
|
-
] });
|
|
1314
|
-
}
|
|
1315
|
-
function StepHeading({
|
|
1316
|
-
step,
|
|
1317
|
-
icon,
|
|
1318
|
-
testId
|
|
1319
|
-
}) {
|
|
1320
|
-
return /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
|
|
1321
|
-
/* @__PURE__ */ jsxs("p", { className: "flex items-center gap-2 text-sm font-medium", "data-testid": testId, children: [
|
|
1322
|
-
icon && /* @__PURE__ */ jsx("span", { className: "flex size-4 items-center justify-center text-primary [&_svg]:size-4", children: icon }),
|
|
1323
|
-
step.title
|
|
1324
|
-
] }),
|
|
1325
|
-
step.description && /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: step.description })
|
|
1326
|
-
] });
|
|
1327
|
-
}
|
|
1328
|
-
function formatElapsed(ms) {
|
|
1329
|
-
const total = Math.max(0, Math.floor(ms / 1e3));
|
|
1330
|
-
const h = Math.floor(total / 3600);
|
|
1331
|
-
const m = Math.floor(total % 3600 / 60);
|
|
1332
|
-
const sec = String(total % 60).padStart(2, "0");
|
|
1333
|
-
return h ? `${h}:${String(m).padStart(2, "0")}:${sec}` : `${m}:${sec}`;
|
|
1334
|
-
}
|
|
1335
|
-
function StepWorking({ title, since, label }) {
|
|
1336
|
-
const seen = useRef(Date.now());
|
|
1337
|
-
const start = since && Date.parse(since) || seen.current;
|
|
1338
|
-
const [now, setNow] = useState(() => Date.now());
|
|
1339
|
-
useEffect(() => {
|
|
1340
|
-
const t = setInterval(() => setNow(Date.now()), 1e3);
|
|
1341
|
-
return () => clearInterval(t);
|
|
1342
|
-
}, []);
|
|
1343
|
-
return /* @__PURE__ */ jsx("span", { children: label.replace("{step}", title).replace("{elapsed}", formatElapsed(now - start)) });
|
|
1344
|
-
}
|
|
1345
|
-
function AgentStepBody({
|
|
1346
|
-
step,
|
|
1347
|
-
run,
|
|
1348
|
-
renderAgentOutput,
|
|
1349
|
-
icon,
|
|
1350
|
-
renderStepNote,
|
|
1351
|
-
l,
|
|
1352
|
-
tid
|
|
1353
|
-
}) {
|
|
1354
|
-
const state = run.stateOf(step.id);
|
|
1355
|
-
const phase = run.phaseOf(step.id);
|
|
1356
|
-
const header = /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-3", children: [
|
|
1357
|
-
/* @__PURE__ */ jsx(StepHeading, { step, icon }),
|
|
1358
|
-
phase === "failed" && /* @__PURE__ */ jsx("div", { className: "flex shrink-0 items-center gap-2", children: run.retry && /* @__PURE__ */ jsxs(
|
|
1359
|
-
Button,
|
|
1360
|
-
{
|
|
1361
|
-
variant: "outline",
|
|
1362
|
-
size: "sm",
|
|
1363
|
-
onClick: () => void run.retry?.(step.id),
|
|
1364
|
-
disabled: run.busy,
|
|
1365
|
-
"data-testid": tid(`${step.id}-retry`),
|
|
1366
|
-
children: [
|
|
1367
|
-
/* @__PURE__ */ jsx(RotateCw, { className: "size-4" }),
|
|
1368
|
-
" ",
|
|
1369
|
-
l.retry
|
|
1370
|
-
]
|
|
1371
|
-
}
|
|
1372
|
-
) })
|
|
1373
|
-
] });
|
|
1374
|
-
const status = /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
|
|
1375
|
-
step.branch && /* @__PURE__ */ jsxs("p", { className: "flex items-center gap-1.5 text-xs text-muted-foreground", children: [
|
|
1376
|
-
/* @__PURE__ */ jsx(GitBranch, { className: "size-3.5" }),
|
|
1377
|
-
" ",
|
|
1378
|
-
l.branch
|
|
1379
|
-
] }),
|
|
1380
|
-
(phase === "ready" || phase === "running") && !state?.text && /* @__PURE__ */ jsxs(
|
|
1381
|
-
"p",
|
|
1382
|
-
{
|
|
1383
|
-
className: "flex items-center gap-2 text-sm text-muted-foreground",
|
|
1384
|
-
"data-testid": tid(`${step.id}-working`),
|
|
1385
|
-
children: [
|
|
1386
|
-
/* @__PURE__ */ jsx(Loader2, { className: "size-4 animate-spin" }),
|
|
1387
|
-
" ",
|
|
1388
|
-
phase === "ready" ? l.starting : /* @__PURE__ */ jsx(StepWorking, { title: step.title, since: state?.startedAt, label: l.stepWorking })
|
|
1389
|
-
]
|
|
1390
|
-
}
|
|
1391
|
-
),
|
|
1392
|
-
phase === "failed" && /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", "data-testid": tid(`${step.id}-failed`), children: state?.error || l.failed }),
|
|
1393
|
-
phase === "skipped" && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: l.skipped })
|
|
1394
|
-
] });
|
|
1395
|
-
if (step.output === "artifact") {
|
|
1396
|
-
return /* @__PURE__ */ jsxs(
|
|
1397
|
-
"div",
|
|
1398
|
-
{
|
|
1399
|
-
className: "grid gap-4 lg:grid-cols-[minmax(0,18rem)_minmax(0,1fr)]",
|
|
1400
|
-
"data-testid": tid(step.id),
|
|
1401
|
-
children: [
|
|
1402
|
-
/* @__PURE__ */ jsxs(Card, { className: "h-fit space-y-3 p-5", children: [
|
|
1403
|
-
header,
|
|
1404
|
-
status,
|
|
1405
|
-
renderStepNote?.(step, run)
|
|
1406
|
-
] }),
|
|
1407
|
-
/* @__PURE__ */ jsx("div", { className: "min-w-0", children: renderAgentOutput(step, state) })
|
|
1408
|
-
]
|
|
1409
|
-
}
|
|
1410
|
-
);
|
|
1411
|
-
}
|
|
1412
|
-
return /* @__PURE__ */ jsxs(Card, { className: "space-y-3 p-6", "data-testid": tid(step.id), children: [
|
|
1413
|
-
header,
|
|
1414
|
-
status,
|
|
1415
|
-
renderAgentOutput(step, state),
|
|
1416
|
-
renderStepNote?.(step, run)
|
|
1417
|
-
] });
|
|
1418
|
-
}
|
|
1419
|
-
|
|
1420
|
-
export { DEFAULT_SCHEMA_FORM_LABELS, DEFAULT_WORKFLOW_RUNNER_LABELS, EMPTY_WORKFLOW_SCOPE, SKILL_PROMPT_FALLBACK_PLACEHOLDER, SKILL_PROMPT_LABEL, SchemaForm, WorkflowRunner, buildLaunch, composeStepPrompt, composeWorkflowPrompt, defaultInputs, dependsOn, fieldToFrontmatter, fillRunText, fillStepInputs, fromPlanSteps, initialRunInputs, inputsFromContext, isEmptyWorkflowScope, isIncompleteSignal, isPersonStep, isRunFinished, isSteppedWorkflow, isWorkflowScope, layoutFromPlanSteps, nextAction, orderSteps, promptFieldName, reviewInstructions, runFields, runThreadTitle, skillToWorkflow, stepDependencies, stepLevels, stepPhase, stepStatesFromActivity, toPlanSteps, useWorkflowView, validateInputs, validateStep, validateWorkflowGraph, workflowAccepts, workflowFromFrontmatter, workflowSteps, workflowsAccepting, workflowsForHost };
|
|
1421
|
-
//# sourceMappingURL=chunk-22P5KNIM.js.map
|
|
1422
|
-
//# sourceMappingURL=chunk-22P5KNIM.js.map
|