@loopstack/loopstack-studio 0.35.1 → 0.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/features/documents/DocumentRenderer.js +7 -7
  2. package/dist/features/documents/renderers/DocumentFormRenderer.js +1 -1
  3. package/dist/features/oauth/OAuthCallbackPage.js +2 -0
  4. package/dist/features/run-view/RunView.js +153 -0
  5. package/dist/features/run-view/Transcript.js +127 -0
  6. package/dist/features/run-view/prompts/FormPrompt.js +129 -0
  7. package/dist/features/run-view/prompts/OAuthPrompt.js +94 -0
  8. package/dist/features/run-view/prompts/SandboxRunButton.js +35 -0
  9. package/dist/features/run-view/prompts/SecretPrompt.js +69 -0
  10. package/dist/features/run-view/prompts/SimplePrompts.js +196 -0
  11. package/dist/features/run-view/prompts/cards.js +90 -0
  12. package/dist/features/run-view/prompts/registry.js +16 -0
  13. package/dist/features/run-view/transcript.js +24 -0
  14. package/dist/features/run-view/useRunPrompts.js +111 -0
  15. package/dist/features/run-view/useRunTree.js +59 -0
  16. package/dist/features/run-view/useTreeLlmStreams.js +91 -0
  17. package/dist/features/secrets/components/WorkbenchSecretsPanel.js +1 -1
  18. package/dist/features/secrets/renderers/SecretInputRenderer.js +1 -1
  19. package/dist/features/workbench/WorkflowList.js +111 -52
  20. package/dist/features/workbench/components/NewRunDialog.js +1 -1
  21. package/dist/features/workbench/index.js +1 -1
  22. package/dist/features/workbench/providers/WorkbenchLayoutProvider.js +4 -1
  23. package/dist/features/workspaces/components/WorkspaceHomePage.js +1 -1
  24. package/dist/index.d.ts +2 -0
  25. package/dist/node_modules/dompurify/dist/purify.es.js +351 -228
  26. package/dist/packages/client/dist/resources/workflows.js +2 -1
  27. package/dist/packages/client/dist/stream/invalidations.js +9 -2
  28. package/dist/packages/client/dist/stream/stream.js +73 -28
  29. package/dist/packages/contracts/dist/park-view/index.js +2 -0
  30. package/dist/packages/contracts/dist/park-view/park-view.rules.js +102 -0
  31. package/dist/packages/contracts/dist/park-view/park-view.types.js +15 -0
  32. package/dist/pages/PreviewWorkbenchPage.js +23 -23
  33. package/dist/providers/StudioPreferencesProvider.js +2 -1
  34. package/package.json +4 -4
@@ -0,0 +1,196 @@
1
+ import { Button } from "../../../components/ui/button.js";
2
+ import { Input } from "../../../components/ui/input.js";
3
+ import { c } from "react/compiler-runtime";
4
+ import { useState } from "react";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ function question(t) {
7
+ let r = t.content;
8
+ return typeof r?.question == "string" ? r.question : "Input required";
9
+ }
10
+ function TextPrompt(s) {
11
+ let l = c(26), { view: u, submit: d, isSubmitting: f } = s, [p, m] = useState(""), h;
12
+ l[0] !== p || l[1] !== d ? (h = () => {
13
+ p.trim() && d({ answer: p.trim() });
14
+ }, l[0] = p, l[1] = d, l[2] = h) : h = l[2];
15
+ let g = h, _;
16
+ l[3] === u ? _ = l[4] : (_ = question(u), l[3] = u, l[4] = _);
17
+ let v;
18
+ l[5] === _ ? v = l[6] : (v = /* @__PURE__ */ jsx("p", {
19
+ className: "text-sm font-medium",
20
+ children: _
21
+ }), l[5] = _, l[6] = v);
22
+ let y;
23
+ l[7] === Symbol.for("react.memo_cache_sentinel") ? (y = (t) => m(t.target.value), l[7] = y) : y = l[7];
24
+ let b;
25
+ l[8] === g ? b = l[9] : (b = (t) => t.key === "Enter" && g(), l[8] = g, l[9] = b);
26
+ let x;
27
+ l[10] !== p || l[11] !== f || l[12] !== b ? (x = /* @__PURE__ */ jsx(Input, {
28
+ value: p,
29
+ onChange: y,
30
+ onKeyDown: b,
31
+ placeholder: "Your answer…",
32
+ disabled: f,
33
+ autoFocus: !0
34
+ }), l[10] = p, l[11] = f, l[12] = b, l[13] = x) : x = l[13];
35
+ let S;
36
+ l[14] !== p || l[15] !== f ? (S = f || !p.trim(), l[14] = p, l[15] = f, l[16] = S) : S = l[16];
37
+ let C;
38
+ l[17] !== g || l[18] !== S ? (C = /* @__PURE__ */ jsx(Button, {
39
+ onClick: g,
40
+ disabled: S,
41
+ children: "Send"
42
+ }), l[17] = g, l[18] = S, l[19] = C) : C = l[19];
43
+ let w;
44
+ l[20] !== x || l[21] !== C ? (w = /* @__PURE__ */ jsxs("div", {
45
+ className: "flex gap-2",
46
+ children: [x, C]
47
+ }), l[20] = x, l[21] = C, l[22] = w) : w = l[22];
48
+ let T;
49
+ return l[23] !== v || l[24] !== w ? (T = /* @__PURE__ */ jsxs("div", {
50
+ className: "space-y-2",
51
+ children: [v, w]
52
+ }), l[23] = v, l[24] = w, l[25] = T) : T = l[25], T;
53
+ }
54
+ function ConfirmPrompt(r) {
55
+ let i = c(20), { view: s, submit: l, isSubmitting: u } = r, d;
56
+ i[0] === s ? d = i[1] : (d = question(s), i[0] = s, i[1] = d);
57
+ let f;
58
+ i[2] === d ? f = i[3] : (f = /* @__PURE__ */ jsx("p", {
59
+ className: "text-sm font-medium",
60
+ children: d
61
+ }), i[2] = d, i[3] = f);
62
+ let p;
63
+ i[4] === l ? p = i[5] : (p = () => l({ answer: "yes" }), i[4] = l, i[5] = p);
64
+ let m;
65
+ i[6] !== u || i[7] !== p ? (m = /* @__PURE__ */ jsx(Button, {
66
+ className: "flex-1",
67
+ onClick: p,
68
+ disabled: u,
69
+ children: "Yes"
70
+ }), i[6] = u, i[7] = p, i[8] = m) : m = i[8];
71
+ let h;
72
+ i[9] === l ? h = i[10] : (h = () => l({ answer: "no" }), i[9] = l, i[10] = h);
73
+ let g;
74
+ i[11] !== u || i[12] !== h ? (g = /* @__PURE__ */ jsx(Button, {
75
+ variant: "outline",
76
+ className: "flex-1",
77
+ onClick: h,
78
+ disabled: u,
79
+ children: "No"
80
+ }), i[11] = u, i[12] = h, i[13] = g) : g = i[13];
81
+ let _;
82
+ i[14] !== m || i[15] !== g ? (_ = /* @__PURE__ */ jsxs("div", {
83
+ className: "flex gap-2",
84
+ children: [m, g]
85
+ }), i[14] = m, i[15] = g, i[16] = _) : _ = i[16];
86
+ let v;
87
+ return i[17] !== f || i[18] !== _ ? (v = /* @__PURE__ */ jsxs("div", {
88
+ className: "space-y-2",
89
+ children: [f, _]
90
+ }), i[17] = f, i[18] = _, i[19] = v) : v = i[19], v;
91
+ }
92
+ function ChoicesPrompt(s) {
93
+ let l = c(24), { view: u, submit: d, isSubmitting: f } = s, p = u.content, m;
94
+ l[0] === p ? m = l[1] : (m = Array.isArray(p?.options) ? p.options : [], l[0] = p, l[1] = m);
95
+ let h = m, [g, _] = useState(""), v;
96
+ l[2] === u ? v = l[3] : (v = question(u), l[2] = u, l[3] = v);
97
+ let y;
98
+ l[4] === v ? y = l[5] : (y = /* @__PURE__ */ jsx("p", {
99
+ className: "text-sm font-medium",
100
+ children: v
101
+ }), l[4] = v, l[5] = y);
102
+ let b;
103
+ if (l[6] !== f || l[7] !== h || l[8] !== d) {
104
+ let r;
105
+ l[10] !== f || l[11] !== d ? (r = (r) => /* @__PURE__ */ jsx(Button, {
106
+ variant: "outline",
107
+ className: "w-full",
108
+ onClick: () => d({ answer: r }),
109
+ disabled: f,
110
+ children: r
111
+ }, r), l[10] = f, l[11] = d, l[12] = r) : r = l[12], b = h.map(r), l[6] = f, l[7] = h, l[8] = d, l[9] = b;
112
+ } else b = l[9];
113
+ let x;
114
+ l[13] === b ? x = l[14] : (x = /* @__PURE__ */ jsx("div", {
115
+ className: "flex flex-col gap-2",
116
+ children: b
117
+ }), l[13] = b, l[14] = x);
118
+ let S;
119
+ l[15] !== p?.allowCustomAnswer || l[16] !== g || l[17] !== f || l[18] !== d ? (S = p?.allowCustomAnswer === !0 && /* @__PURE__ */ jsxs("div", {
120
+ className: "flex gap-2",
121
+ children: [/* @__PURE__ */ jsx(Input, {
122
+ value: g,
123
+ onChange: (t) => _(t.target.value),
124
+ onKeyDown: (t) => t.key === "Enter" && g.trim() && d({ answer: g.trim() }),
125
+ placeholder: "Custom answer…",
126
+ disabled: f
127
+ }), /* @__PURE__ */ jsx(Button, {
128
+ onClick: () => d({ answer: g.trim() }),
129
+ disabled: f || !g.trim(),
130
+ children: "Send"
131
+ })]
132
+ }), l[15] = p?.allowCustomAnswer, l[16] = g, l[17] = f, l[18] = d, l[19] = S) : S = l[19];
133
+ let C;
134
+ return l[20] !== y || l[21] !== x || l[22] !== S ? (C = /* @__PURE__ */ jsxs("div", {
135
+ className: "space-y-2",
136
+ children: [
137
+ y,
138
+ x,
139
+ S
140
+ ]
141
+ }), l[20] = y, l[21] = x, l[22] = S, l[23] = C) : C = l[23], C;
142
+ }
143
+ function PromptInput(o) {
144
+ let s = c(20), { view: l, submit: u, isSubmitting: d } = o, [f, p] = useState(""), m = typeof l.options?.label == "string" ? l.options.label : "Message", h;
145
+ s[0] !== f || s[1] !== u ? (h = () => {
146
+ f.trim() && (u(f.trim()), p(""));
147
+ }, s[0] = f, s[1] = u, s[2] = h) : h = s[2];
148
+ let g = h, _;
149
+ s[3] === Symbol.for("react.memo_cache_sentinel") ? (_ = (t) => p(t.target.value), s[3] = _) : _ = s[3];
150
+ let v;
151
+ s[4] === g ? v = s[5] : (v = (t) => t.key === "Enter" && g(), s[4] = g, s[5] = v);
152
+ let y = `${m}…`, b;
153
+ s[6] !== d || s[7] !== f || s[8] !== v || s[9] !== y ? (b = /* @__PURE__ */ jsx(Input, {
154
+ value: f,
155
+ onChange: _,
156
+ onKeyDown: v,
157
+ placeholder: y,
158
+ disabled: d,
159
+ autoFocus: !0
160
+ }), s[6] = d, s[7] = f, s[8] = v, s[9] = y, s[10] = b) : b = s[10];
161
+ let x;
162
+ s[11] !== d || s[12] !== f ? (x = d || !f.trim(), s[11] = d, s[12] = f, s[13] = x) : x = s[13];
163
+ let S;
164
+ s[14] !== g || s[15] !== x ? (S = /* @__PURE__ */ jsx(Button, {
165
+ onClick: g,
166
+ disabled: x,
167
+ children: "Send"
168
+ }), s[14] = g, s[15] = x, s[16] = S) : S = s[16];
169
+ let C;
170
+ return s[17] !== b || s[18] !== S ? (C = /* @__PURE__ */ jsxs("div", {
171
+ className: "flex gap-2",
172
+ children: [b, S]
173
+ }), s[17] = b, s[18] = S, s[19] = C) : C = s[19], C;
174
+ }
175
+ function ActionButton(r) {
176
+ let i = c(6), { view: a, submit: o, isSubmitting: s } = r, l = typeof a.options?.label == "string" ? a.options.label : a.defaultTransition ?? "Continue", u;
177
+ i[0] === o ? u = i[1] : (u = () => o({}), i[0] = o, i[1] = u);
178
+ let d;
179
+ return i[2] !== s || i[3] !== l || i[4] !== u ? (d = /* @__PURE__ */ jsx(Button, {
180
+ onClick: u,
181
+ disabled: s,
182
+ children: l
183
+ }), i[2] = s, i[3] = l, i[4] = u, i[5] = d) : d = i[5], d;
184
+ }
185
+ function FullWidthActionButton(r) {
186
+ let i = c(6), { view: a, submit: o, isSubmitting: s } = r, l = typeof a.options?.label == "string" ? a.options.label : a.defaultTransition ?? "Continue", u;
187
+ i[0] === o ? u = i[1] : (u = () => o({}), i[0] = o, i[1] = u);
188
+ let d;
189
+ return i[2] !== s || i[3] !== l || i[4] !== u ? (d = /* @__PURE__ */ jsx(Button, {
190
+ className: "w-full",
191
+ onClick: u,
192
+ disabled: s,
193
+ children: l
194
+ }), i[2] = s, i[3] = l, i[4] = u, i[5] = d) : d = i[5], d;
195
+ }
196
+ export { ActionButton, ChoicesPrompt, ConfirmPrompt, FullWidthActionButton, PromptInput, TextPrompt };
@@ -0,0 +1,90 @@
1
+ import { Button } from "../../../components/ui/button.js";
2
+ import { c } from "react/compiler-runtime";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ import { AlertCircle, RefreshCw } from "lucide-react";
5
+ function NotSupportedCard(e) {
6
+ let i = c(2), { view: a } = e, o;
7
+ return i[0] === a.widget ? o = i[1] : (o = /* @__PURE__ */ jsxs("div", {
8
+ className: "text-muted-foreground rounded-md border border-dashed p-3 text-sm",
9
+ children: [
10
+ "Input of type ",
11
+ /* @__PURE__ */ jsx("code", {
12
+ className: "font-mono",
13
+ children: a.widget
14
+ }),
15
+ " is not yet supported in the run view."
16
+ ]
17
+ }), i[0] = a.widget, i[1] = o), o;
18
+ }
19
+ function BareWaitCard(e) {
20
+ let i = c(4), { view: a } = e, o;
21
+ i[0] === a.transitions ? o = i[1] : (o = a.transitions.join(", ") || "—", i[0] = a.transitions, i[1] = o);
22
+ let s;
23
+ return i[2] === o ? s = i[3] : (s = /* @__PURE__ */ jsxs("div", {
24
+ className: "text-muted-foreground rounded-md border border-dashed p-3 text-sm",
25
+ children: [
26
+ "Waiting on ",
27
+ /* @__PURE__ */ jsx("code", {
28
+ className: "font-mono",
29
+ children: o
30
+ }),
31
+ " — nothing to show."
32
+ ]
33
+ }), i[2] = o, i[3] = s), s;
34
+ }
35
+ function FailedRunCard(o) {
36
+ let s = c(13), { workflowName: l, errorMessage: u, onRetry: d, isRetrying: f } = o, p;
37
+ s[0] === Symbol.for("react.memo_cache_sentinel") ? (p = /* @__PURE__ */ jsx(AlertCircle, { className: "text-destructive h-4 w-4 shrink-0" }), s[0] = p) : p = s[0];
38
+ let m;
39
+ s[1] === l ? m = s[2] : (m = /* @__PURE__ */ jsx("span", {
40
+ className: "font-medium",
41
+ children: l
42
+ }), s[1] = l, s[2] = m);
43
+ let h = u ? `: ${u}` : ".", g;
44
+ s[3] !== m || s[4] !== h ? (g = /* @__PURE__ */ jsxs("p", {
45
+ className: "flex items-center gap-2 text-sm",
46
+ children: [p, /* @__PURE__ */ jsxs("span", { children: [
47
+ m,
48
+ " failed",
49
+ h
50
+ ] })]
51
+ }), s[3] = m, s[4] = h, s[5] = g) : g = s[5];
52
+ let _;
53
+ s[6] === Symbol.for("react.memo_cache_sentinel") ? (_ = /* @__PURE__ */ jsx(RefreshCw, { className: "mr-2 h-3.5 w-3.5" }), s[6] = _) : _ = s[6];
54
+ let v;
55
+ s[7] !== f || s[8] !== d ? (v = /* @__PURE__ */ jsxs(Button, {
56
+ variant: "outline",
57
+ size: "sm",
58
+ onClick: d,
59
+ disabled: f,
60
+ children: [_, "Retry"]
61
+ }), s[7] = f, s[8] = d, s[9] = v) : v = s[9];
62
+ let y;
63
+ return s[10] !== g || s[11] !== v ? (y = /* @__PURE__ */ jsxs("div", {
64
+ className: "border-destructive/40 space-y-2 rounded-md border p-3",
65
+ children: [g, v]
66
+ }), s[10] = g, s[11] = v, s[12] = y) : y = s[12], y;
67
+ }
68
+ function InertPromptEntry(e) {
69
+ let i = c(10), { document: a } = e, o;
70
+ i[0] === a.content ? o = i[1] : (o = a.content ?? {}, i[0] = a.content, i[1] = o);
71
+ let s = o, l = typeof s.question == "string" ? s.question : typeof s.markdown == "string" ? s.markdown : void 0, u = s.answer !== void 0, f;
72
+ i[2] === l ? f = i[3] : (f = l && /* @__PURE__ */ jsx("p", {
73
+ className: "font-medium",
74
+ children: l
75
+ }), i[2] = l, i[3] = f);
76
+ let p;
77
+ i[4] !== u || i[5] !== s.answer ? (p = u && /* @__PURE__ */ jsxs("p", {
78
+ className: "text-muted-foreground mt-1",
79
+ children: ["Answered: ", formatAnswer(s.answer)]
80
+ }), i[4] = u, i[5] = s.answer, i[6] = p) : p = i[6];
81
+ let m;
82
+ return i[7] !== f || i[8] !== p ? (m = /* @__PURE__ */ jsxs("div", {
83
+ className: "rounded-md border p-3 text-sm",
84
+ children: [f, p]
85
+ }), i[7] = f, i[8] = p, i[9] = m) : m = i[9], m;
86
+ }
87
+ function formatAnswer(e) {
88
+ return typeof e == "string" ? e : typeof e == "boolean" ? e ? "yes" : "no" : JSON.stringify(e);
89
+ }
90
+ export { BareWaitCard, FailedRunCard, InertPromptEntry, NotSupportedCard };
@@ -0,0 +1,16 @@
1
+ import { FormPrompt } from "./FormPrompt.js";
2
+ import { OAuthPrompt } from "./OAuthPrompt.js";
3
+ import { SecretPrompt } from "./SecretPrompt.js";
4
+ import { ActionButton, ChoicesPrompt, ConfirmPrompt, FullWidthActionButton, PromptInput, TextPrompt } from "./SimplePrompts.js";
5
+ const promptRegistry = new Map([
6
+ ["text-prompt", TextPrompt],
7
+ ["confirm-prompt", ConfirmPrompt],
8
+ ["choices", ChoicesPrompt],
9
+ ["form", FormPrompt],
10
+ ["secret-input", SecretPrompt],
11
+ ["oauth-prompt", OAuthPrompt],
12
+ ["prompt-input", PromptInput],
13
+ ["button", ActionButton],
14
+ ["button-full-w", FullWidthActionButton]
15
+ ]);
16
+ export { promptRegistry };
@@ -0,0 +1,24 @@
1
+ function composeTranscript(e, t) {
2
+ let n = e.flatMap((e) => e.documents.map((t) => ({
3
+ document: t,
4
+ depth: e.depth
5
+ })));
6
+ n.sort((e, t) => new Date(e.document.createdAt).getTime() - new Date(t.document.createdAt).getTime() || e.document.index - t.document.index);
7
+ let r = new Set(e.filter((e) => e.depth === 0).map((e) => e.workflowId)), i = [];
8
+ for (let { document: e, depth: a } of n) {
9
+ if (a > 0 && !r.has(e.workflowId)) continue;
10
+ let n = t(e.documentName);
11
+ if (n === "link") {
12
+ let t = e.content?.workflowId;
13
+ typeof t == "string" && r.add(t);
14
+ continue;
15
+ }
16
+ i.push({
17
+ document: e,
18
+ depth: a,
19
+ widget: n
20
+ });
21
+ }
22
+ return i;
23
+ }
24
+ export { composeTranscript };
@@ -0,0 +1,111 @@
1
+ import { useLoopstackClient } from "../../packages/react/dist/provider.js";
2
+ import "../../packages/react/dist/index.js";
3
+ import { useDocumentConfigs } from "../../hooks/useConfig.js";
4
+ import { promptRegistry } from "./prompts/registry.js";
5
+ import { evaluateWorkflowPrompts, isAnswered, pickPrompt, toParkView } from "../../packages/contracts/dist/park-view/park-view.rules.js";
6
+ import "../../packages/contracts/dist/park-view/index.js";
7
+ import { useMemo } from "react";
8
+ import { useQueries } from "@tanstack/react-query";
9
+ function toWidgetConfig(e) {
10
+ let o = e.ui?.widgets?.[0];
11
+ if (!o) return;
12
+ let s = e.meta;
13
+ return {
14
+ widget: o.widget,
15
+ options: o.options,
16
+ enabledWhen: o.enabledWhen,
17
+ showWhen: o.showWhen,
18
+ schema: e.schema,
19
+ enableAtPlaces: s?.enableAtPlaces,
20
+ hideAtPlaces: s?.hideAtPlaces,
21
+ internal: e.tags?.includes("internal") || void 0
22
+ };
23
+ }
24
+ function toWorkflowInput(e) {
25
+ return {
26
+ id: e.id,
27
+ workflowName: e.workflowName,
28
+ status: e.status,
29
+ place: e.place ?? null,
30
+ availableTransitions: e.availableTransitions?.map((e) => e.id) ?? []
31
+ };
32
+ }
33
+ function useRunPrompts(d) {
34
+ let f = useLoopstackClient(), p = useDocumentConfigs(), m = useMemo(() => {
35
+ let e = /* @__PURE__ */ new Map();
36
+ for (let [o, s] of p) {
37
+ let c = toWidgetConfig(s);
38
+ c && e.set(o, c);
39
+ }
40
+ return e;
41
+ }, [p]), h = useMemo(() => [...new Set(d.map((e) => e.workflow.workflowName))], [d]), g = useQueries({ queries: h.map((e) => ({
42
+ ...f.queries.workflowConfig(e),
43
+ staleTime: 6e4
44
+ })) }), _ = useMemo(() => {
45
+ let e = /* @__PURE__ */ new Map();
46
+ return h.forEach((o, s) => {
47
+ let c = g[s]?.data?.ui?.widgets ?? [];
48
+ e.set(o, c.map((e) => ({
49
+ widget: e.widget,
50
+ options: e.options,
51
+ enabledWhen: e.enabledWhen,
52
+ showWhen: e.showWhen
53
+ })));
54
+ }), e;
55
+ }, [h, ...g.map((e) => e.data)]);
56
+ return useMemo(() => {
57
+ let e = pickPrompt(d.flatMap((e) => {
58
+ let o = e.documents.filter((e) => !e.isInvalidated).map((e) => ({
59
+ documentName: e.documentName,
60
+ place: e.place ?? null,
61
+ content: e.content ?? null,
62
+ tags: e.tags
63
+ }));
64
+ return evaluateWorkflowPrompts(toWorkflowInput(e.workflow), o, m, _.get(e.workflow.workflowName) ?? []);
65
+ }), (e) => !!e.widget && promptRegistry.has(e.widget.widget)), o = (e) => e ? {
66
+ candidate: e,
67
+ view: toParkView(e)
68
+ } : void 0, l;
69
+ if (!e.prompt && !e.blocked) {
70
+ for (let e of d) if (!(e.workflow.status !== "running" && e.workflow.status !== "pending")) {
71
+ for (let o of _.get(e.workflow.workflowName) ?? []) {
72
+ if (!promptRegistry.has(o.widget) || o.showWhen && !o.showWhen.includes(e.workflow.place ?? "")) continue;
73
+ let c = {
74
+ kind: "workflow",
75
+ workflow: toWorkflowInput(e.workflow),
76
+ widget: o,
77
+ state: "disabled"
78
+ };
79
+ l = {
80
+ candidate: c,
81
+ view: toParkView(c)
82
+ };
83
+ break;
84
+ }
85
+ if (l) break;
86
+ }
87
+ }
88
+ let u = /* @__PURE__ */ new Map();
89
+ for (let e of d) if (e.workflow.status !== "completed") for (let o of _.get(e.workflow.workflowName) ?? []) {
90
+ if (o.widget !== "sandbox-run" || o.showWhen && !o.showWhen.includes(e.workflow.place ?? "")) continue;
91
+ let s = o.options;
92
+ u.set(s?.slotId ?? "", {
93
+ slotId: s?.slotId,
94
+ label: s?.label
95
+ });
96
+ }
97
+ return {
98
+ picked: o(e.prompt),
99
+ blocked: o(e.blocked),
100
+ fallback: o(e.fallback),
101
+ idlePrompt: l,
102
+ answered: (e) => isAnswered(e.content),
103
+ sandboxSlots: [...u.values()]
104
+ };
105
+ }, [
106
+ d,
107
+ m,
108
+ _
109
+ ]);
110
+ }
111
+ export { useRunPrompts };
@@ -0,0 +1,59 @@
1
+ import { useLoopstackClient } from "../../packages/react/dist/provider.js";
2
+ import { SortOrder } from "../../packages/contracts/dist/enums/sort-order.enum.js";
3
+ import "../../packages/contracts/dist/enums/index.js";
4
+ import "../../packages/react/dist/index.js";
5
+ import { useEffect, useMemo, useState } from "react";
6
+ import { useQueries } from "@tanstack/react-query";
7
+ var DOCUMENTS_PAGE_SIZE = 100, DOCUMENTS_MAX_PAGES = 5;
8
+ function allDocumentsQuery(e, r) {
9
+ return {
10
+ queryKey: [...e.queries.documents(r).queryKey, "all"],
11
+ queryFn: async () => {
12
+ let i = [];
13
+ for (let a = 0; a < DOCUMENTS_MAX_PAGES; a++) {
14
+ let o = await e.documents.list({
15
+ filter: { workflowId: r },
16
+ sortBy: [{
17
+ field: "index",
18
+ order: SortOrder.ASC
19
+ }],
20
+ page: a,
21
+ limit: DOCUMENTS_PAGE_SIZE
22
+ });
23
+ if (i.push(...o.data), o.data.length < DOCUMENTS_PAGE_SIZE) break;
24
+ }
25
+ return i;
26
+ }
27
+ };
28
+ }
29
+ function useRunTree(n) {
30
+ let s = useLoopstackClient(), [c, l] = useState(n ? [n] : []), u = useMemo(() => new Map(n ? [[n, 0]] : []), [n]);
31
+ useEffect(() => {
32
+ l(n ? [n] : []);
33
+ }, [n]);
34
+ let d = useQueries({ queries: c.map((e) => ({ ...s.queries.workflow(e) })) }), f = useQueries({ queries: c.map((e) => ({ ...s.queries.childWorkflows(e) })) }), p = useQueries({ queries: c.map((e) => allDocumentsQuery(s, e)) });
35
+ return useEffect(() => {
36
+ let e = new Set(c), n = [];
37
+ c.forEach((r, i) => {
38
+ let a = f[i]?.data?.data ?? [];
39
+ for (let i of a) e.has(i.id) || (e.add(i.id), u.set(i.id, (u.get(r) ?? 0) + 1), n.push(i.id));
40
+ }), n.length > 0 && l((e) => [...e, ...n]);
41
+ }, [c, ...f.map((e) => e.data)]), {
42
+ nodes: useMemo(() => c.map((e, n) => {
43
+ let r = d[n]?.data;
44
+ if (r) return {
45
+ workflowId: e,
46
+ depth: u.get(e) ?? 0,
47
+ workflow: r,
48
+ documents: p[n]?.data ?? []
49
+ };
50
+ }).filter((e) => e !== void 0), [
51
+ c,
52
+ u,
53
+ ...d.map((e) => e.data),
54
+ ...p.map((e) => e.data)
55
+ ]),
56
+ isLoading: d[0]?.isLoading ?? !0
57
+ };
58
+ }
59
+ export { useRunTree };
@@ -0,0 +1,91 @@
1
+ import { useLoopstackClient } from "../../packages/react/dist/provider.js";
2
+ import { isLlmResponseEvent } from "../../packages/contracts/dist/events/client-message.schema.js";
3
+ import "../../packages/contracts/dist/events/index.js";
4
+ import { reduceLlmStream } from "../../packages/client/dist/stream/llm-reducer.js";
5
+ import "../../packages/client/dist/index.js";
6
+ import "../../packages/react/dist/index.js";
7
+ import { c } from "react/compiler-runtime";
8
+ import { useEffect, useMemo, useState } from "react";
9
+ function useTreeLlmStreams(a) {
10
+ let s = c(9), l = useLoopstackClient(), u;
11
+ s[0] === Symbol.for("react.memo_cache_sentinel") ? (u = {}, s[0] = u) : u = s[0];
12
+ let [d, f] = useState(u), p;
13
+ s[1] === a ? p = s[2] : (p = a.join(","), s[1] = a, s[2] = p);
14
+ let m = p, h;
15
+ s[3] !== l.stream || s[4] !== m ? (h = () => {
16
+ let e = new Set(m.split(",").filter(Boolean));
17
+ return l.stream.onAny((r) => {
18
+ "userId" in r && isLlmResponseEvent(r) && e.has(r.workflowId) && f((e) => ({
19
+ ...e,
20
+ [r.workflowId]: reduceLlmStream(e[r.workflowId] ?? {}, r)
21
+ }));
22
+ });
23
+ }, s[3] = l.stream, s[4] = m, s[5] = h) : h = s[5];
24
+ let g;
25
+ return s[6] !== l || s[7] !== m ? (g = [l, m], s[6] = l, s[7] = m, s[8] = g) : g = s[8], useEffect(h, g), d;
26
+ }
27
+ function getLlmMessageId(e) {
28
+ let t = e.content;
29
+ return e.documentName === "llm_message" && typeof t?.id == "string" ? t.id : void 0;
30
+ }
31
+ function toStreamingDocument(e, t, n) {
32
+ let r = n.error ? `Error while streaming response: ${n.error}` : n.text, i = [
33
+ ...n.thinking ? [{
34
+ type: "thinking",
35
+ text: n.thinking
36
+ }] : [],
37
+ {
38
+ type: "text",
39
+ text: r
40
+ },
41
+ ...n.toolCalls.map((e) => ({
42
+ type: "tool_call",
43
+ ...e
44
+ }))
45
+ ], a = (/* @__PURE__ */ new Date()).toISOString();
46
+ return {
47
+ id: `streaming-${n.messageId}`,
48
+ documentName: "llm_message",
49
+ content: {
50
+ id: n.messageId,
51
+ role: "assistant",
52
+ text: r,
53
+ blocks: i
54
+ },
55
+ validationError: null,
56
+ meta: { streaming: !n.completed && !n.error },
57
+ isInvalidated: !1,
58
+ index: 2 ** 53 - 1,
59
+ transition: null,
60
+ place: t,
61
+ labels: [],
62
+ tags: ["message"],
63
+ createdAt: a,
64
+ updatedAt: a,
65
+ workspaceId: "",
66
+ workflowId: e
67
+ };
68
+ }
69
+ function mergeStreamingDocuments(e, t, n, r) {
70
+ let i = Object.values(r ?? {});
71
+ if (i.length === 0) return n;
72
+ let a = new Set(n.map(getLlmMessageId).filter((e) => !!e)), o = i.filter((e) => !a.has(e.messageId)).map((n) => toStreamingDocument(e, t ?? "", n));
73
+ return o.length > 0 ? [...n, ...o] : n;
74
+ }
75
+ function useStreamingNodes(e) {
76
+ let t = c(7), n;
77
+ t[0] === e ? n = t[1] : (n = e.map(_temp), t[0] = e, t[1] = n);
78
+ let i = useTreeLlmStreams(n), a;
79
+ if (t[2] !== e || t[3] !== i) {
80
+ let n;
81
+ t[5] === i ? n = t[6] : (n = (e) => ({
82
+ ...e,
83
+ documents: mergeStreamingDocuments(e.workflowId, e.workflow.place ?? null, e.documents, i[e.workflowId])
84
+ }), t[5] = i, t[6] = n), a = e.map(n), t[2] = e, t[3] = i, t[4] = a;
85
+ } else a = t[4];
86
+ return a;
87
+ }
88
+ function _temp(e) {
89
+ return e.workflowId;
90
+ }
91
+ export { useStreamingNodes };
@@ -1,10 +1,10 @@
1
1
  import { Button } from "../../../components/ui/button.js";
2
2
  import { Input } from "../../../components/ui/input.js";
3
3
  import { Label } from "../../../components/ui/label.js";
4
+ import { useCreateSecret, useDeleteSecret, useUpdateSecret, useWorkspaceSecrets } from "../../../hooks/useSecrets.js";
4
5
  import { useWorkbenchLayout } from "../../workbench/providers/WorkbenchLayoutProvider.js";
5
6
  import { SidebarPanel } from "../../workbench/components/SidebarPanel.js";
6
7
  import "../../workbench/index.js";
7
- import { useCreateSecret, useDeleteSecret, useUpdateSecret, useWorkspaceSecrets } from "../../../hooks/useSecrets.js";
8
8
  import { c } from "react/compiler-runtime";
9
9
  import { useState } from "react";
10
10
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -5,9 +5,9 @@ import { Input } from "../../../components/ui/input.js";
5
5
  import { Label } from "../../../components/ui/label.js";
6
6
  import CompletionMessagePaper_default from "../../../components/messages/CompletionMessagePaper.js";
7
7
  import "../../../hooks/useProcessor.js";
8
+ import { useUpsertSecret } from "../../../hooks/useSecrets.js";
8
9
  import { useWorkbenchLayout } from "../../workbench/providers/WorkbenchLayoutProvider.js";
9
10
  import "../../workbench/index.js";
10
- import { useUpsertSecret } from "../../../hooks/useSecrets.js";
11
11
  import React, { useState } from "react";
12
12
  import { jsx, jsxs } from "react/jsx-runtime";
13
13
  import { Info, KeyRound, Loader2 } from "lucide-react";